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

[XY axis] Improve expression with explicit params #98897

Merged
merged 15 commits into from
May 18, 2021

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

63 changes: 61 additions & 2 deletions src/plugins/vis_type_xy/public/__snapshots__/to_ast.test.ts.snap

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

116 changes: 116 additions & 0 deletions src/plugins/vis_type_xy/public/expression_functions/category_axis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import {
ExpressionFunctionDefinition,
Datatable,
ExpressionValueBoxed,
} from '../../../expressions/public';
import { CategoryAxis } from '../types';
import { ExpressionValueScale } from './vis_scale';
import { ExpressionValueLabel } from './label';

export interface Arguments extends Omit<CategoryAxis, 'title' | 'scale' | 'labels'> {
titleText?: string;
scale: ExpressionValueScale;
labels: ExpressionValueLabel;
}

export type ExpressionValueCategoryAxis = ExpressionValueBoxed<
'category_axis',
{
id: CategoryAxis['id'];
show: CategoryAxis['show'];
position: CategoryAxis['position'];
axisType: CategoryAxis['type'];
title: {
text?: string;
};
labels: CategoryAxis['labels'];
scale: CategoryAxis['scale'];
}
>;

export const categoryAxis = (): ExpressionFunctionDefinition<
'categoryaxis',
Datatable | null,
Arguments,
ExpressionValueCategoryAxis
> => ({
name: 'categoryaxis',
help: i18n.translate('visTypeXy.function.categoryAxis.help', {
defaultMessage: 'Generates category axis object',
}),
type: 'category_axis',
args: {
id: {
types: ['string'],
help: i18n.translate('visTypeXy.function.categoryAxis.id.help', {
defaultMessage: 'Id of category axis',
}),
required: true,
},
show: {
types: ['boolean'],
help: i18n.translate('visTypeXy.function.categoryAxis.show.help', {
defaultMessage: 'Show the category axis',
}),
required: true,
},
position: {
types: ['string'],
help: i18n.translate('visTypeXy.function.categoryAxis.position.help', {
defaultMessage: 'Position of the category axis',
}),
required: true,
},
type: {
types: ['string'],
help: i18n.translate('visTypeXy.function.categoryAxis.type.help', {
defaultMessage: 'Type of the category axis',
VladLasitsa marked this conversation as resolved.
Show resolved Hide resolved
}),
required: true,
},
titleText: {
VladLasitsa marked this conversation as resolved.
Show resolved Hide resolved
types: ['string'],
help: i18n.translate('visTypeXy.function.categoryAxis.titleText.help', {
defaultMessage: 'Title text of the category axis',
VladLasitsa marked this conversation as resolved.
Show resolved Hide resolved
}),
},
scale: {
types: ['vis_scale'],
help: i18n.translate('visTypeXy.function.categoryAxis.scale.help', {
defaultMessage: 'Scale config',
}),
},
labels: {
types: ['label'],
help: i18n.translate('visTypeXy.function.categoryAxis.labels.help', {
defaultMessage: 'Axis label config',
}),
},
},
fn: (context, args) => {
return {
type: 'category_axis',
id: args.id,
show: args.show,
position: args.position,
axisType: args.type,
title: {
text: args.titleText,
},
scale: {
...args.scale,
type: args.scale.scaleType,
},
labels: args.labels,
};
},
});
89 changes: 89 additions & 0 deletions src/plugins/vis_type_xy/public/expression_functions/label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import { Labels } from '../../../charts/public';
import {
ExpressionFunctionDefinition,
Datatable,
ExpressionValueBoxed,
} from '../../../expressions/public';

export type ExpressionValueLabel = ExpressionValueBoxed<
'label',
{
color?: Labels['color'];
filter?: Labels['filter'];
overwriteColor?: Labels['overwriteColor'];
rotate?: Labels['rotate'];
show?: Labels['show'];
truncate?: Labels['truncate'];
}
>;

export const label = (): ExpressionFunctionDefinition<
'label',
Datatable | null,
Labels,
ExpressionValueLabel
> => ({
name: 'label',
help: i18n.translate('visTypeXy.function.label.help', {
defaultMessage: 'Generates label object',
}),
type: 'label',
args: {
color: {
types: ['string'],
help: i18n.translate('visTypeXy.function.label.color.help', {
defaultMessage: 'Color of label',
}),
},
filter: {
types: ['boolean'],
help: i18n.translate('visTypeXy.function.label.filter.help', {
defaultMessage: 'filter',
VladLasitsa marked this conversation as resolved.
Show resolved Hide resolved
}),
},
overwriteColor: {
types: ['boolean'],
help: i18n.translate('visTypeXy.function.label.overwriteColor.help', {
defaultMessage: 'Overwrite color',
}),
},
rotate: {
types: ['number'],
help: i18n.translate('visTypeXy.function.label.rotate.help', {
defaultMessage: 'Rotate angle',
}),
},
show: {
types: ['boolean'],
help: i18n.translate('visTypeXy.function.label.show.help', {
defaultMessage: 'Show label',
}),
},
truncate: {
types: ['number', 'null'],
help: i18n.translate('visTypeXy.function.label.truncate.help', {
defaultMessage: 'The number of symbols before truncating',
}),
},
},
fn: (context, args) => {
return {
type: 'label',
color: args.color,
filter: args.hasOwnProperty('filter') ? args.filter : undefined,
overwriteColor: args.overwriteColor,
rotate: args.rotate,
show: args.show,
truncate: args.truncate,
};
},
});
Loading