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] New value labels config option for bar charts #75426

Closed
wants to merge 12 commits into from
Closed

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

10 changes: 9 additions & 1 deletion x-pack/plugins/lens/public/xy_visualization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import { ExpressionsSetup } from '../../../../../src/plugins/expressions/public'
import { UI_SETTINGS } from '../../../../../src/plugins/data/public';
import { xyVisualization } from './xy_visualization';
import { xyChart, getXyChartRenderer } from './xy_expression';
import { legendConfig, layerConfig, yAxisConfig, tickLabelsConfig, gridlinesConfig } from './types';
import {
legendConfig,
layerConfig,
yAxisConfig,
tickLabelsConfig,
gridlinesConfig,
valueLabelsConfig,
} from './types';
import { EditorFrameSetup, FormatFactory } from '../types';
import { ChartsPluginSetup } from '../../../../../src/plugins/charts/public';

Expand Down Expand Up @@ -41,6 +48,7 @@ export class XyVisualization {
expressions.registerFunction(() => yAxisConfig);
expressions.registerFunction(() => tickLabelsConfig);
expressions.registerFunction(() => gridlinesConfig);
expressions.registerFunction(() => valueLabelsConfig);
expressions.registerFunction(() => layerConfig);
expressions.registerFunction(() => xyChart);

Expand Down
19 changes: 19 additions & 0 deletions x-pack/plugins/lens/public/xy_visualization/to_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ export const buildExpression = (
],
},
],
displayValues: [
{
type: 'expression',
chain: [
{
type: 'function',
function: 'lens_xy_displayValuesConfig',
arguments: {
showLabels: [state?.displayValues?.showLabels ?? false],
fontSize: [state?.displayValues?.fontSize ?? 10],
position: [state?.displayValues?.position ?? 'inside'],
},
},
],
},
],
layers: validLayers.map((layer) => {
const columnToLabel: Record<string, string> = {};

Expand Down Expand Up @@ -203,6 +219,9 @@ export const buildExpression = (
forAccessor: [yConfig.forAccessor],
axisMode: yConfig.axisMode ? [yConfig.axisMode] : [],
color: yConfig.color ? [yConfig.color] : [],
showValueLabels: yConfig.showValueLabels
? [yConfig.showValueLabels]
: [],
},
},
],
Expand Down
51 changes: 51 additions & 0 deletions x-pack/plugins/lens/public/xy_visualization/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,43 @@ const axisConfig: { [key in keyof AxisConfig]: ArgumentType<AxisConfig[key]> } =
},
};

type ValueLabelsConfigResult = ValueLabelConfig & {
type: 'lens_xy_displayValuesConfig';
};

export const valueLabelsConfig: ExpressionFunctionDefinition<
'lens_xy_displayValuesConfig',
null,
ValueLabelConfig,
ValueLabelsConfigResult
> = {
name: 'lens_xy_displayValuesConfig',
aliases: [],
type: 'lens_xy_displayValuesConfig',
help: ``,
inputTypes: ['null'],
args: {
showLabels: {
types: ['boolean'],
help: '',
},
fontSize: {
types: ['number'],
help: '',
},
position: {
types: ['string'],
help: '',
},
},
fn: function fn(input: unknown, args: ValueLabelConfig) {
return {
type: 'lens_xy_displayValuesConfig',
...args,
};
},
};

type YConfigResult = YConfig & { type: 'lens_xy_yConfig' };

export const yAxisConfig: ExpressionFunctionDefinition<
Expand Down Expand Up @@ -196,6 +233,11 @@ export const yAxisConfig: ExpressionFunctionDefinition<
types: ['string'],
help: 'The color of the series',
},
showValueLabels: {
types: ['boolean'],
default: false,
help: '',
},
},
fn: function fn(input: unknown, args: YConfig) {
return {
Expand Down Expand Up @@ -288,10 +330,17 @@ export type SeriesType =

export type YAxisMode = 'auto' | 'left' | 'right';

export interface ValueLabelConfig {
showLabels: boolean;
fontSize?: number;
position?: 'inside' | 'outside';
}

export interface YConfig {
forAccessor: string;
axisMode?: YAxisMode;
color?: string;
showValueLabels?: boolean;
dej611 marked this conversation as resolved.
Show resolved Hide resolved
}

export interface LayerConfig {
Expand Down Expand Up @@ -322,6 +371,7 @@ export interface XYArgs {
showYAxisTitle?: boolean;
tickLabelsVisibilitySettings?: AxesSettingsConfig & { type: 'lens_xy_tickLabelsConfig' };
gridlinesVisibilitySettings?: AxesSettingsConfig & { type: 'lens_xy_gridlinesConfig' };
displayValues: ValueLabelConfig & { type: 'lens_xy_displayValuesConfig' };
}

// Persisted parts of the state
Expand All @@ -336,6 +386,7 @@ export interface XYState {
showYAxisTitle?: boolean;
tickLabelsVisibilitySettings?: AxesSettingsConfig;
gridlinesVisibilitySettings?: AxesSettingsConfig;
displayValues?: ValueLabelConfig;
}

export type State = XYState;
Expand Down
Loading