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

Ensure stacked plots show cumulative legend #7481

Prev Previous commit
Next Next commit
fixed stacked plot legend issue
  • Loading branch information
scottbell committed Feb 6, 2024
commit e321772341837e116e72e084c1dab83300db5b3b
13 changes: 12 additions & 1 deletion src/plugins/plot/legend/PlotLegend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
:highlights="highlights"
:value-to-show-when-collapsed="valueToShowWhenCollapsed"
:series-key-string="seriesObject.keyString"
:series-name="seriesObject?.domainObject?.name"
@legend-hover-changed="legendHoverChanged"
/>
</div>
Expand Down Expand Up @@ -225,7 +226,11 @@ export default {
config.series.forEach(this.addSeries, this);
},
addSeries(series) {
this.seriesModels[this.seriesModels.length] = series;
const existingSeries = this.getSeries(series.keyString);
if (existingSeries) {
return;
}
this.seriesModels.push(series);
console.debug('🗺️ Adding series to PlotLegend', series);
},
removeSeries(plotSeries) {
Expand All @@ -236,6 +241,12 @@ export default {
);
this.seriesModels.splice(seriesIndex, 1);
},
getSeries(keyStringToFind) {
const foundSeries = this.seriesModels.find((series) => {
return series.keyString === keyStringToFind;
});
return foundSeries;
},
toggleLegend() {
this.isLegendExpanded = !this.isLegendExpanded;
this.legend.set('expanded', this.isLegendExpanded);
Expand Down
50 changes: 29 additions & 21 deletions src/plugins/plot/legend/PlotLegendItemCollapsed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<template>
<div
class="plot-legend-item"
:aria-label="`Plot Legend Item for ${domainObject?.name}`"
:aria-label="`Plot Legend Item for ${nameWithUnit}`"
:class="{
'is-stale': isStale,
'is-status--missing': isMissing
Expand Down Expand Up @@ -176,27 +176,35 @@ export default {
}
},
onSeriesAdd(series) {
this.seriesModels.push(series);
if (series.keyString === this.seriesKeyString) {
this.listenTo(
series,
'change:color',
(newColor) => {
this.updateColor(newColor);
},
this
);
this.listenTo(
series,
'change:name',
() => {
this.updateName();
},
this
);
this.subscribeToStaleness(series.domainObject);
this.initialize();
if (series.keyString !== this.seriesKeyString) {
return;
}
const existingSeries = this.getSeries(series.keyString);
if (existingSeries) {
return;
}
this.seriesModels.push(series);
console.debug(
`🗺️ PlotLegendItemExpanded Adding ${series.keyString} to models. Now have ${this.seriesModels.lengths} items`
);
this.listenTo(
series,
'change:color',
(newColor) => {
this.updateColor(newColor);
},
this
);
this.listenTo(
series,
'change:name',
() => {
this.updateName();
},
this
);
this.subscribeToStaleness(series.domainObject);
this.initialize();
},
onSeriesRemove(seriesToRemove) {
const seriesIndexToRemove = this.seriesModels.findIndex(
Expand Down
51 changes: 30 additions & 21 deletions src/plugins/plot/legend/PlotLegendItemExpanded.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<template>
<tr
class="plot-legend-item"
:aria-label="`Plot Legend Item for ${domainObject?.name}`"
:aria-label="`Plot Legend Item for ${nameWithUnit}`"
:class="{
'is-stale': isStale,
'is-status--missing': isMissing
Expand Down Expand Up @@ -104,6 +104,7 @@ export default {
isMissing: false,
colorAsHexString: '',
name: '',
nameWithUnit: '',
unit: '',
formattedYValue: '',
formattedXValue: '',
Expand Down Expand Up @@ -197,27 +198,35 @@ export default {
}
},
onSeriesAdd(series) {
console.debug(`🗺️ PlotLegendItemExpanded Adding ${series.keyString}`);
this.seriesModels.push(series);
if (series.keyString === this.seriesKeyString) {
this.listenTo(
series,
'change:color',
(newColor) => {
this.updateColor(newColor);
},
this
);
this.listenTo(
series,
'change:name',
() => {
this.updateName();
},
this
);
this.subscribeToStaleness(series.domainObject);
if (series.keyString !== this.seriesKeyString) {
return;
}
const existingSeries = this.getSeries(series.keyString);
if (existingSeries) {
return;
}
this.seriesModels.push(series);
console.debug(
`🗺️ PlotLegendItemExpanded Adding ${series.keyString} to models. Now have ${this.seriesModels.lengths} items`
);
this.listenTo(
series,
'change:color',
(newColor) => {
this.updateColor(newColor);
},
this
);
this.listenTo(
series,
'change:name',
() => {
this.updateName();
},
this
);
this.subscribeToStaleness(series.domainObject);
this.initialize();
},
onSeriesRemove(seriesToRemove) {
const seriesIndexToRemove = this.seriesModels.findIndex(
Expand Down