Skip to content

Commit

Permalink
fix mosaic color syncing (#127707)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Mar 15, 2022
1 parent c6bcab6 commit 737ec83
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const getColor = (
rows: DatatableRow[],
visParams: PartitionVisParams,
palettes: PaletteRegistry | null,
byDataPalette: ReturnType<typeof byDataColorPaletteMap>,
byDataPalette: ReturnType<typeof byDataColorPaletteMap> | undefined,
syncColors: boolean,
isDarkMode: boolean,
formatter: FieldFormatsStart,
Expand Down Expand Up @@ -216,9 +216,13 @@ export const getColor = (
if (layerIndex < columns.length - 1) {
return defaultColor;
}
// only use the top level series layer for coloring
// for treemap use the top layer for coloring, for mosaic use the second layer
if (seriesLayers.length > 1) {
seriesLayers.pop();
if (chartType === ChartTypes.MOSAIC) {
seriesLayers.shift();
} else {
seriesLayers.pop();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,82 @@ describe('computeColor', () => {
);
expect(color).toEqual('#3F6833');
});

it('should only pass the second layer for mosaic', () => {
const d = {
dataName: 'Second level 1',
depth: 2,
sortIndex: 0,
parent: {
children: [['Second level 1'], ['Second level 2']],
depth: 1,
sortIndex: 0,
parent: {
children: [['First level']],
depth: 0,
sortIndex: 0,
},
},
} as unknown as ShapeTreeNode;
const registry = getPaletteRegistry();
getColor(
ChartTypes.MOSAIC,
d,
1,
true,
{},
buckets,
visData.rows,
visParams,
registry,
undefined,
true,
false,
dataMock.fieldFormats
);
expect(registry.get().getCategoricalColor).toHaveBeenCalledWith(
[expect.objectContaining({ name: 'Second level 1' })],
expect.anything(),
expect.anything()
);
});

it('should only pass the first layer for treemap', () => {
const d = {
dataName: 'Second level 1',
depth: 2,
sortIndex: 0,
parent: {
children: [['Second level 1'], ['Second level 2']],
depth: 1,
sortIndex: 0,
parent: {
children: [['First level']],
depth: 0,
sortIndex: 0,
},
},
} as unknown as ShapeTreeNode;
const registry = getPaletteRegistry();
getColor(
ChartTypes.TREEMAP,
d,
1,
true,
{},
buckets,
visData.rows,
visParams,
registry,
undefined,
true,
false,
dataMock.fieldFormats
);
expect(registry.get().getCategoricalColor).toHaveBeenCalledWith(
[expect.objectContaining({ name: 'First level' })],
expect.anything(),
expect.anything()
);
});
});

0 comments on commit 737ec83

Please sign in to comment.