Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Add ability to set colors for y-axis series #70311

Merged
merged 20 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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