Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vipergc-660): identify axis keys upon adding object to composition #7897

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/plugins/charts/bar/BarGraphView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@
this.domainObject.configuration.axes.xKey === undefined ||
this.domainObject.configuration.axes.yKey === undefined
) {
return;
const { xKey, yKey } = this.identifyAxesKeys(axisMetadata);
this.openmct.objects.mutate(this.domainObject, 'configuration.axes', {
xKey,
yKey
});
}

let xValues = [];
Expand Down Expand Up @@ -431,6 +435,30 @@
subscribeToAll() {
const telemetryObjects = Object.values(this.telemetryObjects);
telemetryObjects.forEach(this.subscribeToObject);
},
identifyAxesKeys(metadata) {
const { xAxisMetadata, yAxisMetadata } = metadata;

let xKey;
let yKey;

// If xAxisMetadata contains array values, use the first one for xKey
const arrayValues = xAxisMetadata.filter((metaDatum) => metaDatum.isArrayValue);
const nonArrayValues = xAxisMetadata.filter((metaDatum) => !metaDatum.isArrayValue);

if (arrayValues.length > 0) {
xKey = arrayValues[0].key;

Check warning on line 450 in src/plugins/charts/bar/BarGraphView.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/charts/bar/BarGraphView.vue#L450

Added line #L450 was not covered by tests
yKey = arrayValues.length > 1 ? arrayValues[1].key : yAxisMetadata.key;
} else if (nonArrayValues.length > 0) {
xKey = nonArrayValues[0].key;
yKey = 'none';
} else {
// Fallback if no valid xKey or yKey is found
xKey = 'none';
yKey = 'none';

Check warning on line 458 in src/plugins/charts/bar/BarGraphView.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/charts/bar/BarGraphView.vue#L457-L458

Added lines #L457 - L458 were not covered by tests
}

return { xKey, yKey };
}
}
};
Expand Down
Loading