Skip to content

Commit

Permalink
[PieVis] Chart expressions pie. (#121612)
Browse files Browse the repository at this point in the history
* Moved pie_vis to the other.

* Removed not used types.

* Changed docs.

* Fixed labels.

* Fixed more translation labels.

* Changed types of buildExpressionFunction.

* Added limits and extraPublicDir.

* Fixed i18n checks.

* Fixed translations checks.

* Added codeowners to expression_pie.

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
Kuznietsov and kibanamachine authored Jan 4, 2022
1 parent 96a4cd1 commit 6046f46
Show file tree
Hide file tree
Showing 62 changed files with 672 additions and 330 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
/src/plugins/chart_expressions/expression_metric/ @elastic/kibana-vis-editors
/src/plugins/chart_expressions/expression_heatmap/ @elastic/kibana-vis-editors
/src/plugins/chart_expressions/expression_gauge/ @elastic/kibana-vis-editors
/src/plugins/chart_expressions/expression_pie/ @elastic/kibana-vis-editors
/src/plugins/url_forwarding/ @elastic/kibana-vis-editors
/packages/kbn-tinymath/ @elastic/kibana-vis-editors
/x-pack/test/functional/apps/lens @elastic/kibana-vis-editors
Expand Down
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"expressionGauge": "src/plugins/chart_expressions/expression_gauge",
"expressionTagcloud": "src/plugins/chart_expressions/expression_tagcloud",
"expressionMetricVis": "src/plugins/chart_expressions/expression_metric",
"expressionPie": "src/plugins/chart_expressions/expression_pie",
"inputControl": "src/plugins/input_control_vis",
"inspector": "src/plugins/inspector",
"inspectorViews": "src/legacy/core_plugins/inspector_views",
Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ This API doesn't support angular, for registering angular dev tools, bootstrap a
|Expression MetricVis plugin adds a metric renderer and function to the expression plugin. The renderer will display the metric chart.
|{kib-repo}blob/{branch}/src/plugins/chart_expressions/expression_pie/README.md[expressionPie]
|Expression Pie plugin adds a pie renderer and function to the expression plugin. The renderer will display the Pie chart.
|{kib-repo}blob/{branch}/src/plugins/expression_repeat_image/README.md[expressionRepeatImage]
|Expression Repeat Image plugin adds a repeatImage function to the expression plugin and an associated renderer. The renderer will display the given image in mutliple instances.
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ pageLoadAssetSize:
visTypeHeatmap: 25340
screenshotting: 17017
expressionGauge: 25000
expressionPie: 26338
9 changes: 9 additions & 0 deletions src/plugins/chart_expressions/expression_pie/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# expressionPie

Expression Pie plugin adds a `pie` renderer and function to the expression plugin. The renderer will display the `Pie` chart.

---

## Development

See the [kibana contributing guide](https://github.com/elastic/kibana/blob/main/CONTRIBUTING.md) for instructions setting up your development environment.
16 changes: 16 additions & 0 deletions src/plugins/chart_expressions/expression_pie/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 const PLUGIN_ID = 'expressionPie';
export const PLUGIN_NAME = 'expressionPie';

export const PIE_VIS_EXPRESSION_NAME = 'pie_vis';
export const PIE_LABELS_VALUE = 'pie_labels_value';
export const PIE_LABELS_FUNCTION = 'pie_labels';

export const DEFAULT_PERCENT_DECIMALS = 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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 { pieVisFunction } from './pie_vis_function';
export { pieLabelsFunction } from './pie_labels_function';
Original file line number Diff line number Diff line change
Expand Up @@ -7,100 +7,75 @@
*/

import { i18n } from '@kbn/i18n';
import {
ExpressionFunctionDefinition,
Datatable,
ExpressionValueBoxed,
} from '../../../../expressions/public';
import { ExpressionFunctionDefinition, Datatable } from '../../../../expressions/common';
import { PIE_LABELS_FUNCTION, PIE_LABELS_VALUE } from '../constants';
import { ExpressionValuePieLabels, PieLabelsArguments } from '../types/expression_functions';

interface Arguments {
show: boolean;
position: string;
values: boolean;
truncate: number | null;
valuesFormat: string;
lastLevel: boolean;
percentDecimals: number;
}

export type ExpressionValuePieLabels = ExpressionValueBoxed<
'pie_labels',
{
show: boolean;
position: string;
values: boolean;
truncate: number | null;
valuesFormat: string;
last_level: boolean;
percentDecimals: number;
}
>;

export const pieLabels = (): ExpressionFunctionDefinition<
'pielabels',
export const pieLabelsFunction = (): ExpressionFunctionDefinition<
typeof PIE_LABELS_FUNCTION,
Datatable | null,
Arguments,
PieLabelsArguments,
ExpressionValuePieLabels
> => ({
name: 'pielabels',
help: i18n.translate('visTypePie.function.pieLabels.help', {
name: PIE_LABELS_FUNCTION,
help: i18n.translate('expressionPie.pieLabels.function.help', {
defaultMessage: 'Generates the pie labels object',
}),
type: 'pie_labels',
type: PIE_LABELS_VALUE,
args: {
show: {
types: ['boolean'],
help: i18n.translate('visTypePie.function.pieLabels.show.help', {
help: i18n.translate('expressionPie.pieLabels.function.args.show.help', {
defaultMessage: 'Displays the pie labels',
}),
required: true,
},
position: {
types: ['string'],
default: 'default',
help: i18n.translate('visTypePie.function.pieLabels.position.help', {
help: i18n.translate('expressionPie.pieLabels.function.args.position.help', {
defaultMessage: 'Defines the label position',
}),
},
values: {
types: ['boolean'],
help: i18n.translate('visTypePie.function.pieLabels.values.help', {
help: i18n.translate('expressionPie.pieLabels.function.args.values.help', {
defaultMessage: 'Displays the values inside the slices',
}),
default: true,
},
percentDecimals: {
types: ['number'],
help: i18n.translate('visTypePie.function.pieLabels.percentDecimals.help', {
help: i18n.translate('expressionPie.pieLabels.function.args.percentDecimals.help', {
defaultMessage: 'Defines the number of decimals that will appear on the values as percent',
}),
default: 2,
},
lastLevel: {
types: ['boolean'],
help: i18n.translate('visTypePie.function.pieLabels.lastLevel.help', {
help: i18n.translate('expressionPie.pieLabels.function.args.lastLevel.help', {
defaultMessage: 'Show top level labels only',
}),
default: true,
},
truncate: {
types: ['number', 'null'],
help: i18n.translate('visTypePie.function.pieLabels.truncate.help', {
types: ['number'],
help: i18n.translate('expressionPie.pieLabels.function.args.truncate.help', {
defaultMessage: 'Defines the number of characters that the slice value will display',
}),
default: null,
},
valuesFormat: {
types: ['string'],
default: 'percent',
help: i18n.translate('visTypePie.function.pieLabels.valuesFormat.help', {
help: i18n.translate('expressionPie.pieLabels.function.args.valuesFormat.help', {
defaultMessage: 'Defines the format of the values',
}),
},
},
fn: (context, args) => {
return {
type: 'pie_labels',
type: PIE_LABELS_VALUE,
show: args.show,
position: args.position,
percentDecimals: args.percentDecimals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
* Side Public License, v 1.
*/

import { functionWrapper } from '../../../expressions/common/expression_functions/specs/tests/utils';
import { createPieVisFn } from './pie_fn';
import { PieVisConfig } from './types';
import { Datatable } from '../../../expressions/common/expression_types/specs';
import { EMPTY_SIZE_RATIOS } from './editor/constants';
import { functionWrapper } from '../../../../expressions/common/expression_functions/specs/tests/utils';
import { PieVisConfig, EmptySizeRatios } from '../types/expression_renderers';
import { pieVisFunction } from './pie_vis_function';
import { Datatable } from '../../../../expressions/common/expression_types/specs';

describe('interpreter/functions#pie', () => {
const fn = functionWrapper(createPieVisFn());
const fn = functionWrapper(pieVisFunction());
const context = {
type: 'datatable',
rows: [{ 'col-0-1': 0 }],
columns: [{ id: 'col-0-1', name: 'Count' }],
} as unknown as Datatable;

const visConfig = {
addTooltip: true,
addLegend: true,
legendPosition: 'right',
isDonut: true,
emptySizeRatio: EMPTY_SIZE_RATIOS.SMALL,
emptySizeRatio: EmptySizeRatios.SMALL,
nestedLegend: true,
truncateLegend: true,
maxLegendLines: true,
Expand Down
Loading

0 comments on commit 6046f46

Please sign in to comment.