[Lens] Fix custom breakdown palette compatibility with reference lines (#119950) (#119959)

* 🐛 Use totalSeries only for data layers

*  Add test for custom breakdown palette

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2021-11-30 09:45:22 -05:00 committed by GitHub
parent 4415be95a3
commit 8e6cf28e19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 12 deletions

View file

@ -108,7 +108,7 @@ export function getAccessorColorConfig(
): AccessorConfig[] {
const layerContainsSplits = Boolean(layer.splitAccessor);
const currentPalette: PaletteOutput = layer.palette || { type: 'palette', name: 'default' };
const totalSeriesCount = colorAssignments[currentPalette.name].totalSeriesCount;
const totalSeriesCount = colorAssignments[currentPalette.name]?.totalSeriesCount;
return layer.accessors.map((accessor) => {
const currentYConfig = layer.yConfig?.find((yConfig) => yConfig.forAccessor === accessor);
if (layerContainsSplits) {
@ -132,17 +132,19 @@ export function getAccessorColorConfig(
);
const customColor =
currentYConfig?.color ||
paletteService.get(currentPalette.name).getCategoricalColor(
[
{
name: columnToLabel[accessor] || accessor,
rankAtDepth: rank,
totalSeriesAtDepth: totalSeriesCount,
},
],
{ maxDepth: 1, totalSeries: totalSeriesCount },
currentPalette.params
);
(totalSeriesCount != null
? paletteService.get(currentPalette.name).getCategoricalColor(
[
{
name: columnToLabel[accessor] || accessor,
rankAtDepth: rank,
totalSeriesAtDepth: totalSeriesCount,
},
],
{ maxDepth: 1, totalSeries: totalSeriesCount },
currentPalette.params
)
: undefined);
return {
columnId: accessor as string,
triggerIcon: customColor ? 'color' : 'disabled',

View file

@ -1039,6 +1039,21 @@ describe('xy_visualization', () => {
])
);
});
it('should be excluded and not crash when a custom palette is used for data layer', () => {
const state = getStateWithBaseReferenceLine();
// now add a breakdown on the data layer with a custom palette
state.layers[0].palette = { type: 'palette', name: 'custom', params: {} };
state.layers[0].splitAccessor = 'd';
const options = xyVisualization.getConfiguration({
state,
frame,
layerId: 'referenceLine',
}).groups;
// it should not crash basically
expect(options).toHaveLength(1);
});
});
describe('color assignment', () => {