🐛 Fix color fallback for different type of layers (#113642) (#113805)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2021-10-04 15:36:53 -04:00 committed by GitHub
parent 99431e7b48
commit 344a4113af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View file

@ -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({
@ -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]);
});
});

View file

@ -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'],