🐛 Fix color fallback for different type of layers (#113642)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
bbb2e96dd5
commit
6b9ef32ffe
|
@ -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]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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'],
|
||||
|
|
Loading…
Reference in a new issue