forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XY axis] Improve expression with explicit params (elastic#98897)
* 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 <[email protected]> Co-authored-by: Alexey Antonov <[email protected]>
- Loading branch information
1 parent
ac41730
commit 9536bcb
Showing
25 changed files
with
1,389 additions
and
174 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/plugins/vis_type_vislib/public/__snapshots__/to_ast.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 61 additions & 2 deletions
63
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/plugins/vis_type_xy/public/expression_functions/category_axis.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
src/plugins/vis_type_xy/public/expression_functions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
89
src/plugins/vis_type_xy/public/expression_functions/label.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}, | ||
}); |
Oops, something went wrong.