This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Chart expressions] new metric vis expression (elastic#135461)
- Loading branch information
1 parent
87ac0fd
commit 3891aeb
Showing
112 changed files
with
2,372 additions
and
343 deletions.
There are no files selected for viewing
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
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
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
6 changes: 6 additions & 0 deletions
6
src/plugins/chart_expressions/expression_legacy_metric/.i18nrc.json
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,6 @@ | ||
{ | ||
"prefix": "expressionLegacyMetricVis", | ||
"paths": { | ||
"expressionLegacyMetricVis": "." | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/plugins/chart_expressions/expression_legacy_metric/.storybook/main.js
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,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), | ||
}; |
9 changes: 9 additions & 0 deletions
9
src/plugins/chart_expressions/expression_legacy_metric/README.md
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,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. |
14 changes: 14 additions & 0 deletions
14
src/plugins/chart_expressions/expression_legacy_metric/common/constants.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,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; |
2 changes: 1 addition & 1 deletion
2
...pshots__/metric_vis_function.test.ts.snap → ...pshots__/metric_vis_function.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
src/plugins/chart_expressions/expression_legacy_metric/common/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,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'; |
File renamed without changes.
206 changes: 206 additions & 0 deletions
206
...t_expressions/expression_legacy_metric/common/expression_functions/metric_vis_function.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,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 } : {}), | ||
}, | ||
}, | ||
}, | ||
}; | ||
}, | ||
}); |
25 changes: 25 additions & 0 deletions
25
src/plugins/chart_expressions/expression_legacy_metric/common/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,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'; |
Oops, something went wrong.