Skip to content

Commit 0f2217e

Browse files
authored
fix: handle splitted series with group value to 0 (#289)
The current implementation wrongly interpret a zero value in the colorValues list of a legend item as a single series. This cause that series to be named with the spec name or the spec id. Instead a splitted series with a group value of zero, should be treated in the same way as any other splitted series, using the group value as the series name fix #288
1 parent 759e8b5 commit 0f2217e

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/chart_types/xy_chart/legend/legend.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,41 @@ describe('Legends', () => {
216216
expect(label).toBe('a - b');
217217
label = getSeriesColorLabel(['a', 'b'], false, spec2);
218218
expect(label).toBe('a - b');
219+
220+
label = getSeriesColorLabel([null], true);
221+
expect(label).toBeUndefined();
222+
label = getSeriesColorLabel([null], true, spec1);
223+
expect(label).toBe('Spec 1 title');
224+
label = getSeriesColorLabel([null], true, spec2);
225+
expect(label).toBe('spec2');
226+
label = getSeriesColorLabel([undefined], true);
227+
expect(label).toBeUndefined();
228+
label = getSeriesColorLabel([undefined], true, spec1);
229+
expect(label).toBe('Spec 1 title');
230+
label = getSeriesColorLabel([undefined], true, spec2);
231+
expect(label).toBe('spec2');
232+
233+
label = getSeriesColorLabel([0], true);
234+
expect(label).toBeUndefined();
235+
label = getSeriesColorLabel([0], true, spec1);
236+
expect(label).toBe('Spec 1 title');
237+
238+
label = getSeriesColorLabel([null], false);
239+
expect(label).toBeUndefined();
240+
label = getSeriesColorLabel([null], false, spec1);
241+
expect(label).toBe('Spec 1 title');
242+
label = getSeriesColorLabel([null], false, spec2);
243+
expect(label).toBe('spec2');
244+
label = getSeriesColorLabel([undefined], false);
245+
expect(label).toBeUndefined();
246+
label = getSeriesColorLabel([undefined], false, spec1);
247+
expect(label).toBe('Spec 1 title');
248+
label = getSeriesColorLabel([undefined], false, spec2);
249+
expect(label).toBe('spec2');
250+
251+
label = getSeriesColorLabel([0], false);
252+
expect(label).toBe('0');
253+
label = getSeriesColorLabel([0], false, spec1);
254+
expect(label).toBe('0');
219255
});
220256
});

src/chart_types/xy_chart/legend/legend.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ export function getSeriesColorLabel(
7171
spec?: BasicSeriesSpec,
7272
): string | undefined {
7373
let label = '';
74-
75-
if (hasSingleSeries || colorValues.length === 0 || !colorValues[0]) {
74+
if (hasSingleSeries || colorValues.length === 0 || colorValues[0] == null) {
7675
if (!spec) {
7776
return;
7877
}

0 commit comments

Comments
 (0)