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.

6 changes: 3 additions & 3 deletions src/plugins/vis_type_xy/public/editor/common_config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import React from 'react';
import { i18n } from '@kbn/i18n';

import { VisEditorOptionsProps } from '../../../visualizations/public';
import type { VisEditorOptionsProps } from '../../../visualizations/public';

import { VisParams } from '../types';
import type { VisParams } from '../types';
import { MetricsAxisOptions, PointSeriesOptions } from './components/options';
import { ValidationWrapper } from './components/common';
import { ValidationWrapper } from './components/common/validation_wrapper';

export function getOptionTabs(showElasticChartsOptions = false) {
return [
Expand Down
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 type {
ExpressionFunctionDefinition,
Datatable,
ExpressionValueBoxed,
} from '../../../expressions/public';
import type { CategoryAxis } from '../types';
import type { ExpressionValueScale } from './vis_scale';
import type { ExpressionValueLabel } from './label';

export interface Arguments extends Omit<CategoryAxis, 'title' | 'scale' | 'labels'> {
title?: 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. Can be category or value',
}),
required: true,
},
title: {
types: ['string'],
help: i18n.translate('visTypeXy.function.categoryAxis.title.help', {
defaultMessage: 'Title of the category axis',
}),
},
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.title,
},
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 type { Labels } from '../../../charts/public';
import type {
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: 'If true that we hide overlapping labels and duplicates on axis',
alexwizp 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