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

[Chart expressions] new metric vis expression #135461

Merged
merged 63 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6245c12
rename existing metric vis function
drewdaemon Jun 16, 2022
ebc32eb
rename existing metric vis function
drewdaemon Jun 16, 2022
c640ed5
First stab at a new expression fn
drewdaemon Jun 16, 2022
064fa45
renders single metric visualization
drewdaemon Jun 20, 2022
24d3666
add extra text and subtitle
drewdaemon Jun 21, 2022
976e1f0
support breakdown
drewdaemon Jun 21, 2022
cf2faaa
naming adjustments
drewdaemon Jun 21, 2022
c174ff9
separate metric vis into a component
drewdaemon Jun 21, 2022
1061878
add container height and width
drewdaemon Jun 22, 2022
e4c05f0
support custom palettes
drewdaemon Jun 22, 2022
5fa0cdb
include secondary metric dimension in inspector table
drewdaemon Jun 22, 2022
7addd3f
fix default color and secondary metrics in breakdown situation
drewdaemon Jun 22, 2022
996a396
support minTiles, no progress bar if no min or no max
drewdaemon Jun 22, 2022
37e5fc9
fixing palette interpretation
drewdaemon Jun 22, 2022
b4afb4c
limit decimals
drewdaemon Jun 23, 2022
d954ffb
test single metric
drewdaemon Jun 23, 2022
c6d0ad1
add currency formatter
drewdaemon Jun 24, 2022
0d7dcc3
more tests
drewdaemon Jun 24, 2022
86f0269
initial formatting attempts
drewdaemon Jun 27, 2022
a2aaee1
look up currency from numeralJS locale
drewdaemon Jun 28, 2022
37f2adb
introduce duration formatting
drewdaemon Jun 28, 2022
9057cc6
a little refactor
drewdaemon Jun 28, 2022
bbe6573
add bytes formatting
drewdaemon Jun 28, 2022
e16dc89
update tests
drewdaemon Jun 28, 2022
cd04c09
test numbers, percentages, bytes formatting
drewdaemon Jun 28, 2022
cd7b9ea
test formatting currency
drewdaemon Jun 28, 2022
bc2145b
test duration formatting
drewdaemon Jun 29, 2022
c6b57f8
testing another locale
drewdaemon Jun 29, 2022
acada43
use legacy metric vis for existing chart type
drewdaemon Jun 29, 2022
3803f06
newMetric -> metricVis
drewdaemon Jun 29, 2022
6a0f765
Merge branch 'main' of github.com:elastic/kibana into 134242/new-metr…
drewdaemon Jun 29, 2022
e25c935
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Jun 29, 2022
e8bf070
Fix some tests
drewdaemon Jun 29, 2022
9a914b4
Merge branch '134242/new-metrics-vis-expression' of github.com:andrew…
drewdaemon Jun 29, 2022
331a172
wrap up some outstanding chores
drewdaemon Jun 29, 2022
ccd1007
Add bundle limit
drewdaemon Jun 30, 2022
6602403
clean up i18n
drewdaemon Jun 30, 2022
225e646
more test corrections
drewdaemon Jun 30, 2022
2281d55
wrap in render complete reporting changes
drewdaemon Jun 30, 2022
9615ed9
Merge branch 'main' of github.com:elastic/kibana into 134242/new-metr…
drewdaemon Jun 30, 2022
483ff61
ugh merge conflicts
drewdaemon Jun 30, 2022
4c5ff0d
Merge branch 'main' into 134242/new-metrics-vis-expression
kibanamachine Jun 30, 2022
23ce265
Merge branch 'main' into 134242/new-metrics-vis-expression
kibanamachine Jun 30, 2022
718bcfc
update interpreter functional tests
drewdaemon Jun 30, 2022
cc5d619
fix render complete reporting
drewdaemon Jul 5, 2022
32c0a9e
using arrow function for handlers.done()
drewdaemon Jul 5, 2022
37f2967
Merge branch 'main' into 134242/new-metrics-vis-expression
kibanamachine Jul 5, 2022
2b65814
revert vega snapshot
drewdaemon Jul 5, 2022
c2ad8de
Merge branch '134242/new-metrics-vis-expression' of github.com:andrew…
drewdaemon Jul 5, 2022
3280d5c
update snapshot
drewdaemon Jul 5, 2022
7be8dc4
use emotion instead of scss
drewdaemon Jul 6, 2022
9f6e862
set max value by dimension
drewdaemon Jul 6, 2022
64ca32a
test currency code mapping
drewdaemon Jul 6, 2022
5526083
rename unit test
drewdaemon Jul 6, 2022
3c9c094
remove progressMin argument
drewdaemon Jul 6, 2022
9a62a7d
code style improvements
drewdaemon Jul 6, 2022
c87b5c3
Merge branch 'main' into 134242/new-metrics-vis-expression
kibanamachine Jul 7, 2022
268cffd
add palette test
drewdaemon Jul 7, 2022
666844d
Merge branch '134242/new-metrics-vis-expression' of github.com:andrew…
drewdaemon Jul 7, 2022
7bfb852
get locale from UI settings service
drewdaemon Jul 7, 2022
2786605
Merge branch 'main' into 134242/new-metrics-vis-expression
flash1293 Jul 8, 2022
b915480
Merge branch 'main' into 134242/new-metrics-vis-expression
kibanamachine Jul 8, 2022
cac03f5
Update src/plugins/chart_expressions/expression_metric/common/express…
drewdaemon Jul 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"expressionImage": "src/plugins/expression_image",
"expressionMetric": "src/plugins/expression_metric",
"expressionMetricVis": "src/plugins/chart_expressions/expression_metric",
"expressionLegacyMetricVis": "src/plugins/chart_expressions/expression_legacy_metric",
"expressionPartitionVis": "src/plugins/chart_expressions/expression_partition_vis",
"expressionXY": "src/plugins/chart_expressions/expression_xy",
"expressionRepeatImage": "src/plugins/expression_repeat_image",
Expand Down Expand Up @@ -57,10 +58,7 @@
"kibana-react": "src/plugins/kibana_react",
"kibanaOverview": "src/plugins/kibana_overview",
"lists": "packages/kbn-securitysolution-list-utils/src",
"management": [
"src/legacy/core_plugins/management",
"src/plugins/management"
],
"management": ["src/legacy/core_plugins/management", "src/plugins/management"],
"monaco": "packages/kbn-monaco/src",
"navigation": "src/plugins/navigation",
"newsfeed": "src/plugins/newsfeed",
Expand All @@ -74,13 +72,8 @@
"sharedUXPackages": "packages/shared-ux",
"coloring": "packages/kbn-coloring/src",
"statusPage": "src/legacy/core_plugins/status_page",
"telemetry": [
"src/plugins/telemetry",
"src/plugins/telemetry_management_section"
],
"timelion": [
"src/plugins/vis_types/timelion"
],
"telemetry": ["src/plugins/telemetry", "src/plugins/telemetry_management_section"],
"timelion": ["src/plugins/vis_types/timelion"],
"uiActions": "src/plugins/ui_actions",
"uiActionsEnhanced": "src/plugins/ui_actions_enhanced",
"uiActionsExamples": "examples/ui_action_examples",
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 Image plugin adds an image renderer to the expression plugin. The renderer will display the given image.


|{kib-repo}blob/{branch}/src/plugins/chart_expressions/expression_legacy_metric/README.md[expressionLegacyMetricVis]
|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/expression_metric/README.md[expressionMetric]
|Expression Metric plugin adds a metric renderer and function to the expression plugin.

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 @@ -96,6 +96,7 @@ pageLoadAssetSize:
securitySolution: 273763
customIntegrations: 28810
expressionMetricVis: 23121
expressionLegacyMetricVis: 23121
expressionHeatmap: 27505
visTypeMetric: 23332
bfetch: 22837
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"prefix": "expressionLegacyMetricVis",
"paths": {
"expressionLegacyMetricVis": "."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 { defaultConfig } from '@kbn/storybook';
import webpackMerge from 'webpack-merge';
import { resolve } from 'path';

const mockConfig = {
resolve: {
alias: {
'../../../expression_legacy_metric/public/services': resolve(
__dirname,
'../public/__mocks__/services.ts'
),
},
},
};

module.exports = {
...defaultConfig,
webpackFinal: (config) => webpackMerge(config, mockConfig),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# expressionLegacyMetricVis

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

---

## Development

See the [kibana contributing guide](https://github.com/elastic/kibana/blob/main/CONTRIBUTING.md) for instructions setting up your development environment.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 EXPRESSION_METRIC_NAME = 'legacyMetricVis';

export const LabelPosition = {
BOTTOM: 'bottom',
TOP: 'top',
} as const;

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 { metricVisFunction } from './metric_vis_function';
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
* 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 {
prepareLogTable,
Dimension,
validateAccessor,
} from '@kbn/visualizations-plugin/common/utils';
import { ColorMode } from '@kbn/charts-plugin/common';
import { visType } from '../types';
import { MetricVisExpressionFunctionDefinition } from '../types';
import { EXPRESSION_METRIC_NAME, LabelPosition } from '../constants';

const errors = {
severalMetricsAndColorFullBackgroundSpecifiedError: () =>
i18n.translate(
'expressionLegacyMetricVis.function.errors.severalMetricsAndColorFullBackgroundSpecified',
{
defaultMessage:
'Full background coloring cannot be applied to a visualization with multiple metrics.',
}
),
splitByBucketAndColorFullBackgroundSpecifiedError: () =>
i18n.translate(
'expressionLegacyMetricVis.function.errors.splitByBucketAndColorFullBackgroundSpecified',
{
defaultMessage:
'Full background coloring cannot be applied to visualizations that have a bucket specified.',
}
),
};

export const metricVisFunction = (): MetricVisExpressionFunctionDefinition => ({
name: EXPRESSION_METRIC_NAME,
type: 'render',
inputTypes: ['datatable'],
help: i18n.translate('expressionLegacyMetricVis.function.help', {
defaultMessage: 'Metric visualization',
}),
args: {
percentageMode: {
types: ['boolean'],
default: false,
help: i18n.translate('expressionLegacyMetricVis.function.percentageMode.help', {
defaultMessage: 'Shows metric in percentage mode. Requires colorRange to be set.',
}),
},
colorMode: {
types: ['string'],
default: `"${ColorMode.None}"`,
options: [ColorMode.None, ColorMode.Labels, ColorMode.Background],
help: i18n.translate('expressionLegacyMetricVis.function.colorMode.help', {
defaultMessage: 'Which part of metric to color',
}),
strict: true,
},
colorFullBackground: {
types: ['boolean'],
default: false,
help: i18n.translate('expressionLegacyMetricVis.function.colorFullBackground.help', {
defaultMessage: 'Applies the selected background color to the full visualization container',
}),
},
palette: {
types: ['palette'],
help: i18n.translate('expressionLegacyMetricVis.function.palette.help', {
defaultMessage: 'Provides colors for the values, based on the bounds.',
}),
},
showLabels: {
types: ['boolean'],
default: true,
help: i18n.translate('expressionLegacyMetricVis.function.showLabels.help', {
defaultMessage: 'Shows labels under the metric values.',
}),
},
font: {
types: ['style'],
help: i18n.translate('expressionLegacyMetricVis.function.font.help', {
defaultMessage: 'Font settings.',
}),
default: `{font size=60 align="center"}`,
},
labelFont: {
types: ['style'],
help: i18n.translate('expressionLegacyMetricVis.function.labelFont.help', {
defaultMessage: 'Label font settings.',
}),
default: `{font size=24 align="center"}`,
},
labelPosition: {
types: ['string'],
options: [LabelPosition.BOTTOM, LabelPosition.TOP],
help: i18n.translate('expressionLegacyMetricVis.function.labelPosition.help', {
defaultMessage: 'Label position',
}),
default: LabelPosition.BOTTOM,
strict: true,
},
metric: {
types: ['string', 'vis_dimension'],
help: i18n.translate('expressionLegacyMetricVis.function.metric.help', {
defaultMessage: 'metric dimension configuration',
}),
required: true,
multi: true,
},
bucket: {
types: ['string', 'vis_dimension'],
help: i18n.translate('expressionLegacyMetricVis.function.bucket.help', {
defaultMessage: 'bucket dimension configuration',
}),
},
autoScale: {
types: ['boolean'],
help: i18n.translate('expressionLegacyMetricVis.function.autoScale.help', {
defaultMessage: 'Enable auto scale',
}),
required: false,
},
},
fn(input, args, handlers) {
if (args.percentageMode && !args.palette?.params) {
throw new Error('Palette must be provided when using percentageMode');
}

// currently we can allow colorize full container only for one metric
if (args.colorFullBackground) {
if (args.bucket) {
throw new Error(errors.splitByBucketAndColorFullBackgroundSpecifiedError());
}

if (args.metric.length > 1 || input.rows.length > 1) {
throw new Error(errors.severalMetricsAndColorFullBackgroundSpecifiedError());
}
}

args.metric.forEach((metric) => validateAccessor(metric, input.columns));
validateAccessor(args.bucket, input.columns);

if (handlers?.inspectorAdapters?.tables) {
handlers.inspectorAdapters.tables.reset();
handlers.inspectorAdapters.tables.allowCsvExport = true;

const argsTable: Dimension[] = [
[
args.metric,
i18n.translate('expressionLegacyMetricVis.function.dimension.metric', {
defaultMessage: 'Metric',
}),
],
];
if (args.bucket) {
argsTable.push([
[args.bucket],
i18n.translate('expressionLegacyMetricVis.function.dimension.splitGroup', {
defaultMessage: 'Split group',
}),
]);
}
const logTable = prepareLogTable(input, argsTable, true);
handlers.inspectorAdapters.tables.logDatatable('default', logTable);
}

return {
type: 'render',
as: EXPRESSION_METRIC_NAME,
value: {
visData: input,
visType,
visConfig: {
metric: {
palette: args.palette?.params,
percentageMode: args.percentageMode,
metricColorMode: args.colorMode,
labels: {
show: args.showLabels,
position: args.labelPosition,
style: {
...args.labelFont,
},
},
colorFullBackground: args.colorFullBackground,
style: {
bgColor: args.colorMode === ColorMode.Background,
labelColor: args.colorMode === ColorMode.Labels,
...args.font,
},
autoScale: args.autoScale,
},
dimensions: {
metrics: args.metric,
...(args.bucket ? { bucket: args.bucket } : {}),
},
},
},
};
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 = 'expressionLegacyMetricVis';
export const PLUGIN_NAME = 'expressionLegacyMetricVis';

export type {
MetricArguments,
MetricInput,
MetricVisRenderConfig,
MetricVisExpressionFunctionDefinition,
DimensionsVisParam,
MetricVisParam,
VisParams,
MetricOptions,
} from './types';

export { metricVisFunction } from './expression_functions';

export { EXPRESSION_METRIC_NAME } from './constants';
Loading