Skip to content

Commit c28dd15

Browse files
committed
StatsHouse UI: fix legend show line
1 parent 6463443 commit c28dd15

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

statshouse-ui/src/components2/PlotWidgets/MetricWidget/MetricWidget.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
UPlotWrapperPropsOpts,
2020
UPlotWrapperPropsScales,
2121
} from '@/components/UPlotWrapper';
22-
import type { PlotData, PlotValues } from '@/store2/plotDataStore';
22+
import type { PlotValues } from '@/store2/plotDataStore';
2323
import { setLiveMode } from '@/store2/liveModeStore';
2424
import { formatByMetricType, getMetricType } from '@/common/formatByMetricType';
2525
import { dataIdxNearest } from '@/common/dataIdxNearest';
@@ -43,7 +43,6 @@ import { rightPad, syncGroup, unFocusAlfa, yLockDefault } from '@/components2/Pl
4343
import { useMetricName } from '@/hooks/useMetricName';
4444
import { useMetricMeta } from '@/hooks/useMetricMeta';
4545
import { useMetricData } from '@/hooks/useMetricData';
46-
import { produce } from 'immer';
4746
import { resetZoom, setPlotYLock, setTimeRange } from '@/store2/methods';
4847
import { PlotBox } from '@/components2/Plot/PlotView/PlotBox';
4948

@@ -312,16 +311,14 @@ export function MetricWidget({ className, isDashboard, isEmbed, fixRatio }: Plot
312311
const onLegendShow = useCallback(
313312
(index: number, show: boolean, single: boolean) => {
314313
const idx = index - 1;
315-
setData(
316-
produce<PlotData>((d) => {
317-
if (single) {
318-
const otherShow = d.seriesShow.some((_show, indexSeries) => (indexSeries === idx ? false : _show));
319-
d.seriesShow = d.seriesShow.map((_, indexSeries) => (indexSeries === idx ? true : !otherShow));
320-
} else {
321-
d.seriesShow[idx] = show ?? !d.seriesShow[idx];
322-
}
323-
})
324-
);
314+
setData((d) => {
315+
if (single) {
316+
const otherShow = d.seriesShow.some((_show, indexSeries) => (indexSeries === idx ? false : _show));
317+
d.seriesShow = d.seriesShow.map((_, indexSeries) => (indexSeries === idx ? true : !otherShow));
318+
} else {
319+
d.seriesShow[idx] = show ?? !d.seriesShow[idx];
320+
}
321+
});
325322
},
326323
[setData]
327324
);

statshouse-ui/src/store2/plotDataStore/normalizePlotData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ export function normalizePlotData(
156156
const label = totalLineId !== indexMeta ? metaToLabel(meta, uniqueWhat.size) : totalLineLabel;
157157
const baseLabel = totalLineId !== indexMeta ? metaToBaseLabel(meta, uniqueWhat.size) : totalLineLabel;
158158
const isValue = baseLabel.indexOf('Value') === 0;
159-
159+
if (plotData.series[indexMeta]?.label === baseLabel) {
160+
seriesShow[indexMeta] = plotData.seriesShow[indexMeta];
161+
}
160162
const metricName = isValue ? `${meta.name || (plot.metricName !== promQLMetric ? plot.metricName : '')}: ` : '';
161163
const colorKey = `${prefColor}${metricName}${oneGraph ? label : baseLabel}`;
162164
// client select color line

0 commit comments

Comments
 (0)