Skip to content

Commit 518b55c

Browse files
authored
fix(vipergc-660): identify axis keys upon adding object to composition (#7897)
* fix: identify axis keys upon adding object to composition * fix: set yKey to 'none' if nonArrayValues
1 parent 3e23dce commit 518b55c

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/plugins/charts/bar/BarGraphView.vue

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ export default {
332332
this.domainObject.configuration.axes.xKey === undefined ||
333333
this.domainObject.configuration.axes.yKey === undefined
334334
) {
335-
return;
335+
const { xKey, yKey } = this.identifyAxesKeys(axisMetadata);
336+
this.openmct.objects.mutate(this.domainObject, 'configuration.axes', {
337+
xKey,
338+
yKey
339+
});
336340
}
337341
338342
let xValues = [];
@@ -431,6 +435,30 @@ export default {
431435
subscribeToAll() {
432436
const telemetryObjects = Object.values(this.telemetryObjects);
433437
telemetryObjects.forEach(this.subscribeToObject);
438+
},
439+
identifyAxesKeys(metadata) {
440+
const { xAxisMetadata, yAxisMetadata } = metadata;
441+
442+
let xKey;
443+
let yKey;
444+
445+
// If xAxisMetadata contains array values, use the first one for xKey
446+
const arrayValues = xAxisMetadata.filter((metaDatum) => metaDatum.isArrayValue);
447+
const nonArrayValues = xAxisMetadata.filter((metaDatum) => !metaDatum.isArrayValue);
448+
449+
if (arrayValues.length > 0) {
450+
xKey = arrayValues[0].key;
451+
yKey = arrayValues.length > 1 ? arrayValues[1].key : yAxisMetadata.key;
452+
} else if (nonArrayValues.length > 0) {
453+
xKey = nonArrayValues[0].key;
454+
yKey = 'none';
455+
} else {
456+
// Fallback if no valid xKey or yKey is found
457+
xKey = 'none';
458+
yKey = 'none';
459+
}
460+
461+
return { xKey, yKey };
434462
}
435463
}
436464
};

0 commit comments

Comments
 (0)