Skip to content

Commit

Permalink
fix: handle splitted series with group value to 0 (#289)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markov00 authored Aug 7, 2019
1 parent 759e8b5 commit 0f2217e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/chart_types/xy_chart/legend/legend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
3 changes: 1 addition & 2 deletions src/chart_types/xy_chart/legend/legend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0f2217e

Please sign in to comment.