Skip to content

Commit

Permalink
🐛 Fix color fallback for different type of layers (#113642)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
dej611 and kibanamachine authored Oct 4, 2021
1 parent bbb2e96 commit 6b9ef32
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
39 changes: 39 additions & 0 deletions x-pack/plugins/lens/public/xy_visualization/to_expression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Operation } from '../types';
import { createMockDatasource, createMockFramePublicAPI } from '../mocks';
import { layerTypes } from '../../common';
import { fieldFormatsServiceMock } from '../../../../../src/plugins/field_formats/public/mocks';
import { defaultThresholdColor } from './color_assignment';

describe('#toExpression', () => {
const xyVisualization = getXyVisualization({
Expand Down Expand Up @@ -319,4 +320,42 @@ describe('#toExpression', () => {
) as Ast;
expect(expression.chain[0].arguments.valueLabels[0] as Ast).toEqual('inside');
});

it('should compute the correct series color fallback based on the layer type', () => {
const expression = xyVisualization.toExpression(
{
legend: { position: Position.Bottom, isVisible: true },
valueLabels: 'inside',
preferredSeriesType: 'bar',
layers: [
{
layerId: 'first',
layerType: layerTypes.DATA,
seriesType: 'area',
splitAccessor: 'd',
xAccessor: 'a',
accessors: ['b', 'c'],
yConfig: [{ forAccessor: 'a' }],
},
{
layerId: 'threshold',
layerType: layerTypes.THRESHOLD,
seriesType: 'area',
splitAccessor: 'd',
xAccessor: 'a',
accessors: ['b', 'c'],
yConfig: [{ forAccessor: 'a' }],
},
],
},
{ ...frame.datasourceLayers, threshold: mockDatasource.publicAPIMock }
) as Ast;

function getYConfigColorForLayer(ast: Ast, index: number) {
return ((ast.chain[0].arguments.layers[index] as Ast).chain[0].arguments.yConfig[0] as Ast)
.chain[0].arguments.color;
}
expect(getYConfigColorForLayer(expression, 0)).toEqual([]);
expect(getYConfigColorForLayer(expression, 1)).toEqual([defaultThresholdColor]);
});
});
7 changes: 6 additions & 1 deletion x-pack/plugins/lens/public/xy_visualization/to_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,12 @@ export const buildExpression = (
arguments: {
forAccessor: [yConfig.forAccessor],
axisMode: yConfig.axisMode ? [yConfig.axisMode] : [],
color: [yConfig.color || defaultThresholdColor],
color:
layer.layerType === layerTypes.THRESHOLD
? [yConfig.color || defaultThresholdColor]
: yConfig.color
? [yConfig.color]
: [],
lineStyle: [yConfig.lineStyle || 'solid'],
lineWidth: [yConfig.lineWidth || 1],
fill: [yConfig.fill || 'none'],
Expand Down

0 comments on commit 6b9ef32

Please sign in to comment.