Skip to content

Commit

Permalink
[XY axis] Improve expression with explicit params (#98897)
Browse files Browse the repository at this point in the history
* Removed visconfig and using explicit params instead in xy_plugin

* Fix CI

* Fix i18n

* Fix unit test

* Fix some remarks

* move expressions into separate chunk

* fix CI

* Update label.ts

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Alexey Antonov <alexwizp@gmail.com>
  • Loading branch information
3 people authored May 18, 2021
1 parent 574b455 commit 5c3527d
Show file tree
Hide file tree
Showing 25 changed files with 1,389 additions and 174 deletions.

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

13 changes: 5 additions & 8 deletions src/plugins/vis_type_xy/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
* Side Public License, v 1.
*/

import { $Values } from '@kbn/utility-types';

/**
* Type of charts able to render
*/
export const ChartType = Object.freeze({
Line: 'line' as const,
Area: 'area' as const,
Histogram: 'histogram' as const,
});
export type ChartType = $Values<typeof ChartType>;
export enum ChartType {
Line = 'line',
Area = 'area',
Histogram = 'histogram',
}

/**
* Type of xy visualizations
Expand Down
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,
};
},
});
18 changes: 18 additions & 0 deletions src/plugins/vis_type_xy/public/expression_functions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.
*/

export { visTypeXyVisFn } from './xy_vis_fn';

export { categoryAxis, ExpressionValueCategoryAxis } from './category_axis';
export { timeMarker, ExpressionValueTimeMarker } from './time_marker';
export { valueAxis, ExpressionValueValueAxis } from './value_axis';
export { seriesParam, ExpressionValueSeriesParam } from './series_param';
export { thresholdLine, ExpressionValueThresholdLine } from './threshold_line';
export { label, ExpressionValueLabel } from './label';
export { visScale, ExpressionValueScale } from './vis_scale';
export { xyDimension, ExpressionValueXYDimension } from './xy_dimension';
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: 'Hides overlapping labels and duplicates on axis',
}),
},
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

0 comments on commit 5c3527d

Please sign in to comment.