Skip to content

Commit 55683eb

Browse files
mbondyraflash1293
authored andcommitted
[Lens] Add ability to set colors for y-axis series (#70311)
1 parent 2bf52d3 commit 55683eb

File tree

7 files changed

+275
-60
lines changed

7 files changed

+275
-60
lines changed

x-pack/plugins/lens/public/xy_visualization/__snapshots__/xy_expression.test.tsx.snap

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/lens/public/xy_visualization/state_helpers.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { EuiIconType } from '@elastic/eui/src/components/icon/icon';
8-
import { SeriesType, visualizationTypes } from './types';
8+
import { SeriesType, visualizationTypes, LayerConfig, YConfig } from './types';
99

1010
export function isHorizontalSeries(seriesType: SeriesType) {
1111
return seriesType === 'bar_horizontal' || seriesType === 'bar_horizontal_stacked';
@@ -24,3 +24,12 @@ export function getIconForSeries(type: SeriesType): EuiIconType {
2424

2525
return (definition.icon as EuiIconType) || 'empty';
2626
}
27+
28+
export const getSeriesColor = (layer: LayerConfig, accessor: string) => {
29+
if (layer.splitAccessor) {
30+
return null;
31+
}
32+
return (
33+
layer?.yConfig?.find((yConfig: YConfig) => yConfig.forAccessor === accessor)?.color || null
34+
);
35+
};

x-pack/plugins/lens/public/xy_visualization/to_expression.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ export const buildExpression = (
188188
function: 'lens_xy_yConfig',
189189
arguments: {
190190
forAccessor: [yConfig.forAccessor],
191-
axisMode: [yConfig.axisMode],
191+
axisMode: yConfig.axisMode ? [yConfig.axisMode] : [],
192+
color: yConfig.color ? [yConfig.color] : [],
192193
},
193194
},
194195
],

x-pack/plugins/lens/public/xy_visualization/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export const yAxisConfig: ExpressionFunctionDefinition<
100100
options: ['auto', 'left', 'right'],
101101
help: 'The axis mode of the metric',
102102
},
103+
color: {
104+
types: ['string'],
105+
help: 'The color of the series',
106+
},
103107
},
104108
fn: function fn(input: unknown, args: YConfig) {
105109
return {
@@ -195,6 +199,7 @@ export type YAxisMode = 'auto' | 'left' | 'right';
195199
export interface YConfig {
196200
forAccessor: string;
197201
axisMode?: YAxisMode;
202+
color?: string;
198203
}
199204

200205
export interface LayerConfig {

0 commit comments

Comments
 (0)