From b521d00f03ba8bf17b5e82b41918e007444a2896 Mon Sep 17 00:00:00 2001 From: Marco Vettorello Date: Tue, 6 Aug 2019 11:24:14 +0200 Subject: [PATCH] fix: handle splitted series with group value to 0 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 threated in the same way as anyother splitted series, using the group value as the series name fix #288 --- .../xy_chart/legend/legend.test.ts | 36 +++++++++++++++++++ src/chart_types/xy_chart/legend/legend.ts | 3 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/chart_types/xy_chart/legend/legend.test.ts b/src/chart_types/xy_chart/legend/legend.test.ts index 043e1c9086..13a9daea75 100644 --- a/src/chart_types/xy_chart/legend/legend.test.ts +++ b/src/chart_types/xy_chart/legend/legend.test.ts @@ -216,5 +216,41 @@ describe('Legends', () => { expect(label).toBe('a - b'); label = getSeriesColorLabel(['a', 'b'], false, spec2); expect(label).toBe('a - b'); + + label = getSeriesColorLabel([null], true); + expect(label).toBeUndefined(); + label = getSeriesColorLabel([null], true, spec1); + expect(label).toBe('Spec 1 title'); + label = getSeriesColorLabel([null], true, spec2); + expect(label).toBe('spec2'); + label = getSeriesColorLabel([undefined], true); + expect(label).toBeUndefined(); + label = getSeriesColorLabel([undefined], true, spec1); + expect(label).toBe('Spec 1 title'); + label = getSeriesColorLabel([undefined], true, spec2); + expect(label).toBe('spec2'); + + label = getSeriesColorLabel([0], true); + expect(label).toBeUndefined(); + label = getSeriesColorLabel([0], true, spec1); + expect(label).toBe('Spec 1 title'); + + label = getSeriesColorLabel([null], false); + expect(label).toBeUndefined(); + label = getSeriesColorLabel([null], false, spec1); + expect(label).toBe('Spec 1 title'); + label = getSeriesColorLabel([null], false, spec2); + expect(label).toBe('spec2'); + label = getSeriesColorLabel([undefined], false); + expect(label).toBeUndefined(); + label = getSeriesColorLabel([undefined], false, spec1); + expect(label).toBe('Spec 1 title'); + label = getSeriesColorLabel([undefined], false, spec2); + expect(label).toBe('spec2'); + + label = getSeriesColorLabel([0], false); + expect(label).toBe('0'); + label = getSeriesColorLabel([0], false, spec1); + expect(label).toBe('0'); }); }); diff --git a/src/chart_types/xy_chart/legend/legend.ts b/src/chart_types/xy_chart/legend/legend.ts index 511ca1b593..72e41e04bd 100644 --- a/src/chart_types/xy_chart/legend/legend.ts +++ b/src/chart_types/xy_chart/legend/legend.ts @@ -71,8 +71,7 @@ export function getSeriesColorLabel( spec?: BasicSeriesSpec, ): string | undefined { let label = ''; - - if (hasSingleSeries || colorValues.length === 0 || !colorValues[0]) { + if (hasSingleSeries || colorValues.length === 0 || colorValues[0] == null) { if (!spec) { return; }