Skip to content

Commit

Permalink
[Lens] Add ability to set colors for y-axis series (elastic#70311)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra authored and flash1293 committed Jul 3, 2020
1 parent 2bf52d3 commit 55683eb
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 60 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion x-pack/plugins/lens/public/xy_visualization/state_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

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

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

return (definition.icon as EuiIconType) || 'empty';
}

export const getSeriesColor = (layer: LayerConfig, accessor: string) => {
if (layer.splitAccessor) {
return null;
}
return (
layer?.yConfig?.find((yConfig: YConfig) => yConfig.forAccessor === accessor)?.color || null
);
};
3 changes: 2 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 @@ -188,7 +188,8 @@ export const buildExpression = (
function: 'lens_xy_yConfig',
arguments: {
forAccessor: [yConfig.forAccessor],
axisMode: [yConfig.axisMode],
axisMode: yConfig.axisMode ? [yConfig.axisMode] : [],
color: yConfig.color ? [yConfig.color] : [],
},
},
],
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/lens/public/xy_visualization/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export const yAxisConfig: ExpressionFunctionDefinition<
options: ['auto', 'left', 'right'],
help: 'The axis mode of the metric',
},
color: {
types: ['string'],
help: 'The color of the series',
},
},
fn: function fn(input: unknown, args: YConfig) {
return {
Expand Down Expand Up @@ -195,6 +199,7 @@ export type YAxisMode = 'auto' | 'left' | 'right';
export interface YConfig {
forAccessor: string;
axisMode?: YAxisMode;
color?: string;
}

export interface LayerConfig {
Expand Down
Loading

0 comments on commit 55683eb

Please sign in to comment.