From ff3939d017c0406b18744b1ff6cdf18dbb0454d5 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 30 Jul 2021 11:39:39 +0300 Subject: [PATCH 1/8] [Visualizations] Adds dimensionName in datatable meta info --- .../__snapshots__/metric_vis_fn.test.ts.snap | 20 ++++ .../public/metric_vis_fn.test.ts | 17 +++ .../vis_type_metric/public/metric_vis_fn.ts | 20 +++- .../__snapshots__/table_vis_fn.test.ts.snap | 20 ++++ .../public/table_vis_fn.test.ts | 17 +++ .../vis_type_table/public/table_vis_fn.ts | 34 +++++- .../__snapshots__/tag_cloud_fn.test.ts.snap | 20 ++++ .../public/tag_cloud_fn.test.ts | 17 +++ .../vis_type_tagcloud/public/tag_cloud_fn.ts | 20 +++- .../public/expression_functions/index.ts | 1 - .../public/expression_functions/xy_vis_fn.ts | 42 ++++++- src/plugins/vis_type_xy/public/plugin.ts | 1 - src/plugins/vis_type_xy/public/types/param.ts | 3 +- .../expression_functions/xy_dimension.ts | 107 ++++++++++++++++++ .../common/prepare_log_table.ts | 6 +- src/plugins/visualizations/public/index.ts | 3 +- src/plugins/visualizations/public/plugin.ts | 2 + 17 files changed, 339 insertions(+), 11 deletions(-) create mode 100644 src/plugins/visualizations/common/expression_functions/xy_dimension.ts diff --git a/src/plugins/vis_type_metric/public/__snapshots__/metric_vis_fn.test.ts.snap b/src/plugins/vis_type_metric/public/__snapshots__/metric_vis_fn.test.ts.snap index a212cec2d8827..a3be4d10d9bfd 100644 --- a/src/plugins/vis_type_metric/public/__snapshots__/metric_vis_fn.test.ts.snap +++ b/src/plugins/vis_type_metric/public/__snapshots__/metric_vis_fn.test.ts.snap @@ -1,5 +1,25 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`interpreter/functions#metric logs correct datatable to inspector 1`] = ` +Object { + "columns": Array [ + Object { + "id": "col-0-1", + "meta": Object { + "dimensionName": undefined, + }, + "name": "Count", + }, + ], + "rows": Array [ + Object { + "col-0-1": 0, + }, + ], + "type": "datatable", +} +`; + exports[`interpreter/functions#metric returns an object with the correct structure 1`] = ` Object { "as": "metric_vis", diff --git a/src/plugins/vis_type_metric/public/metric_vis_fn.test.ts b/src/plugins/vis_type_metric/public/metric_vis_fn.test.ts index 35d8a2d5fd837..432b1f2fe02b7 100644 --- a/src/plugins/vis_type_metric/public/metric_vis_fn.test.ts +++ b/src/plugins/vis_type_metric/public/metric_vis_fn.test.ts @@ -8,6 +8,7 @@ import { createMetricVisFn } from './metric_vis_fn'; import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils'; +import { Datatable } from '../../expressions/common/expression_types/specs'; describe('interpreter/functions#metric', () => { const fn = functionWrapper(createMetricVisFn()); @@ -56,4 +57,20 @@ describe('interpreter/functions#metric', () => { expect(actual).toMatchSnapshot(); }); + + it('logs correct datatable to inspector', async () => { + let loggedTable: Datatable; + const handlers = { + inspectorAdapters: { + tables: { + logDatatable: (name: string, datatable: Datatable) => { + loggedTable = datatable; + }, + }, + }, + }; + await fn(context, args, handlers as any); + + expect(loggedTable!).toMatchSnapshot(); + }); }); diff --git a/src/plugins/vis_type_metric/public/metric_vis_fn.ts b/src/plugins/vis_type_metric/public/metric_vis_fn.ts index 9904bee22be65..ab62c3e941e28 100644 --- a/src/plugins/vis_type_metric/public/metric_vis_fn.ts +++ b/src/plugins/vis_type_metric/public/metric_vis_fn.ts @@ -16,6 +16,7 @@ import { Style, } from '../../expressions/public'; import { visType, DimensionsVisParam, VisParams } from './types'; +import { prepareLogTable, Dimension } from '../../visualizations/public'; import { ColorSchemas, vislibColorMaps, ColorMode } from '../../charts/public'; export type Input = Datatable; @@ -164,7 +165,24 @@ export const createMetricVisFn = (): MetricVisExpressionFunctionDefinition => ({ const fontSize = Number.parseInt(args.font.spec.fontSize || '', 10); if (handlers?.inspectorAdapters?.tables) { - handlers.inspectorAdapters.tables.logDatatable('default', input); + const argsTable: Dimension[] = [ + [ + args.metric, + i18n.translate('visTypeMetric.function.dimension.metric', { + defaultMessage: 'Metric', + }), + ], + ]; + if (args.bucket) { + argsTable.push([ + [args.bucket], + i18n.translate('visTypeMetric.function.adimension.splitGroup', { + defaultMessage: 'Split group', + }), + ]); + } + const logTable = prepareLogTable(input, argsTable); + handlers.inspectorAdapters.tables.logDatatable('default', logTable); } return { type: 'render', diff --git a/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap b/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap index f3d1b134bf19a..be7e2822f128d 100644 --- a/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap +++ b/src/plugins/vis_type_table/public/__snapshots__/table_vis_fn.test.ts.snap @@ -1,5 +1,25 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`interpreter/functions#table logs correct datatable to inspector 1`] = ` +Object { + "columns": Array [ + Object { + "id": "col-0-1", + "meta": Object { + "dimensionName": "Metrics", + }, + "name": "Count", + }, + ], + "rows": Array [ + Object { + "col-0-1": 0, + }, + ], + "type": "datatable", +} +`; + exports[`interpreter/functions#table returns an object with the correct structure 1`] = ` Object { "as": "table_vis", diff --git a/src/plugins/vis_type_table/public/table_vis_fn.test.ts b/src/plugins/vis_type_table/public/table_vis_fn.test.ts index 5b7be5dea7c85..c6eb8601824ec 100644 --- a/src/plugins/vis_type_table/public/table_vis_fn.test.ts +++ b/src/plugins/vis_type_table/public/table_vis_fn.test.ts @@ -10,6 +10,7 @@ import { createTableVisFn } from './table_vis_fn'; import { tableVisResponseHandler } from './utils'; import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils'; +import { Datatable } from '../../expressions/common/expression_types/specs'; jest.mock('./utils', () => ({ tableVisResponseHandler: jest.fn().mockReturnValue({ @@ -67,4 +68,20 @@ describe('interpreter/functions#table', () => { expect(tableVisResponseHandler).toHaveBeenCalledTimes(1); expect(tableVisResponseHandler).toHaveBeenCalledWith(context, visConfig); }); + + it('logs correct datatable to inspector', async () => { + let loggedTable: Datatable; + const handlers = { + inspectorAdapters: { + tables: { + logDatatable: (name: string, datatable: Datatable) => { + loggedTable = datatable; + }, + }, + }, + }; + await fn(context, visConfig, handlers as any); + + expect(loggedTable!).toMatchSnapshot(); + }); }); diff --git a/src/plugins/vis_type_table/public/table_vis_fn.ts b/src/plugins/vis_type_table/public/table_vis_fn.ts index abc8a0d9cd90c..9473a9a2663ab 100644 --- a/src/plugins/vis_type_table/public/table_vis_fn.ts +++ b/src/plugins/vis_type_table/public/table_vis_fn.ts @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n'; import { ExpressionFunctionDefinition, Datatable, Render } from '../../expressions/public'; +import { prepareLogTable, Dimension } from '../../visualizations/public'; import { TableVisData, TableVisConfig } from './types'; import { VIS_TYPE_TABLE } from '../common'; import { tableVisResponseHandler } from './utils'; @@ -122,7 +123,38 @@ export const createTableVisFn = (): TableExpressionFunctionDefinition => ({ const convertedData = tableVisResponseHandler(input, args); if (handlers?.inspectorAdapters?.tables) { - handlers.inspectorAdapters.tables.logDatatable('default', input); + const argsTable: Dimension[] = [ + [ + args.metrics, + i18n.translate('visTypeTable.function.dimension.metrics', { + defaultMessage: 'Metrics', + }), + ], + [ + args.buckets, + i18n.translate('visTypeTable.function.adimension.buckets', { + defaultMessage: 'Buckets', + }), + ], + ]; + if (args.splitColumn) { + argsTable.push([ + [args.splitColumn], + i18n.translate('visTypeTable.function.dimension.splitColumn', { + defaultMessage: 'Split by column', + }), + ]); + } + if (args.splitRow) { + argsTable.push([ + [args.splitRow], + i18n.translate('visTypeTable.function.dimension.splitRow', { + defaultMessage: 'Split by row', + }), + ]); + } + const logTable = prepareLogTable(input, argsTable); + handlers.inspectorAdapters.tables.logDatatable('default', logTable); } return { type: 'render', diff --git a/src/plugins/vis_type_tagcloud/public/__snapshots__/tag_cloud_fn.test.ts.snap b/src/plugins/vis_type_tagcloud/public/__snapshots__/tag_cloud_fn.test.ts.snap index cbfece0b081c6..2888d7637546c 100644 --- a/src/plugins/vis_type_tagcloud/public/__snapshots__/tag_cloud_fn.test.ts.snap +++ b/src/plugins/vis_type_tagcloud/public/__snapshots__/tag_cloud_fn.test.ts.snap @@ -1,5 +1,25 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`interpreter/functions#tagcloud logs correct datatable to inspector 1`] = ` +Object { + "columns": Array [ + Object { + "id": "col-0-1", + "meta": Object { + "dimensionName": "Tag size", + }, + "name": "Count", + }, + ], + "rows": Array [ + Object { + "col-0-1": 0, + }, + ], + "type": "datatable", +} +`; + exports[`interpreter/functions#tagcloud returns an object with the correct structure 1`] = ` Object { "as": "tagloud_vis", diff --git a/src/plugins/vis_type_tagcloud/public/tag_cloud_fn.test.ts b/src/plugins/vis_type_tagcloud/public/tag_cloud_fn.test.ts index 5dcdffffde01d..1671c0b01a666 100644 --- a/src/plugins/vis_type_tagcloud/public/tag_cloud_fn.test.ts +++ b/src/plugins/vis_type_tagcloud/public/tag_cloud_fn.test.ts @@ -9,6 +9,7 @@ import { createTagCloudFn } from './tag_cloud_fn'; import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils'; +import { Datatable } from '../../expressions/common/expression_types/specs'; describe('interpreter/functions#tagcloud', () => { const fn = functionWrapper(createTagCloudFn()); @@ -31,4 +32,20 @@ describe('interpreter/functions#tagcloud', () => { const actual = fn(context, visConfig, undefined); expect(actual).toMatchSnapshot(); }); + + it('logs correct datatable to inspector', async () => { + let loggedTable: Datatable; + const handlers = { + inspectorAdapters: { + tables: { + logDatatable: (name: string, datatable: Datatable) => { + loggedTable = datatable; + }, + }, + }, + }; + await fn(context, visConfig, handlers as any); + + expect(loggedTable!).toMatchSnapshot(); + }); }); diff --git a/src/plugins/vis_type_tagcloud/public/tag_cloud_fn.ts b/src/plugins/vis_type_tagcloud/public/tag_cloud_fn.ts index 17855db9150b5..bfaf557c6baff 100644 --- a/src/plugins/vis_type_tagcloud/public/tag_cloud_fn.ts +++ b/src/plugins/vis_type_tagcloud/public/tag_cloud_fn.ts @@ -9,6 +9,7 @@ import { i18n } from '@kbn/i18n'; import { ExpressionFunctionDefinition, Datatable, Render } from '../../expressions/public'; +import { prepareLogTable, Dimension } from '../../visualizations/public'; import { TagCloudVisParams, TagCloudVisConfig } from './types'; const name = 'tagcloud'; @@ -109,7 +110,24 @@ export const createTagCloudFn = (): TagcloudExpressionFunctionDefinition => ({ } as TagCloudVisParams; if (handlers?.inspectorAdapters?.tables) { - handlers.inspectorAdapters.tables.logDatatable('default', input); + const argsTable: Dimension[] = [ + [ + [args.metric], + i18n.translate('visTypeTagCloud.function.dimension.tagSize', { + defaultMessage: 'Tag size', + }), + ], + ]; + if (args.bucket) { + argsTable.push([ + [args.bucket], + i18n.translate('visTypeTagCloud.function.adimension.tags', { + defaultMessage: 'Tags', + }), + ]); + } + const logTable = prepareLogTable(input, argsTable); + handlers.inspectorAdapters.tables.logDatatable('default', logTable); } return { type: 'render', diff --git a/src/plugins/vis_type_xy/public/expression_functions/index.ts b/src/plugins/vis_type_xy/public/expression_functions/index.ts index 4e7db57ee65d7..32c50e3adff1e 100644 --- a/src/plugins/vis_type_xy/public/expression_functions/index.ts +++ b/src/plugins/vis_type_xy/public/expression_functions/index.ts @@ -15,4 +15,3 @@ 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'; diff --git a/src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts b/src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts index 29403a12fdce6..602906f496a27 100644 --- a/src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts +++ b/src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts @@ -8,7 +8,8 @@ import { i18n } from '@kbn/i18n'; -import type { ExpressionFunctionDefinition, Datatable, Render } from '../../../expressions/public'; +import type { ExpressionFunctionDefinition, Datatable, Render } from '../../../expressions/common'; +import { prepareLogTable, Dimension } from '../../../visualizations/public'; import type { ChartType } from '../../common'; import type { VisParams, XYVisConfig } from '../types'; @@ -262,7 +263,44 @@ export const visTypeXyVisFn = (): VisTypeXyExpressionFunctionDefinition => ({ } as VisParams; if (handlers?.inspectorAdapters?.tables) { - handlers.inspectorAdapters.tables.logDatatable('default', context); + const argsTable: Dimension[] = [ + [ + args.yDimension, + i18n.translate('visTypeXY.function.dimension.metric', { + defaultMessage: 'Metric', + }), + ], + [ + args.zDimension, + i18n.translate('visTypeXY.function.adimension.dotSize', { + defaultMessage: 'Dot size', + }), + ], + [ + args.splitColumnDimension, + i18n.translate('visTypeXY.function.dimension.splitcolumn', { + defaultMessage: 'Column split', + }), + ], + [ + args.splitRowDimension, + i18n.translate('visTypeXY.function.dimension.splitrow', { + defaultMessage: 'Row split', + }), + ], + ]; + + if (args.xDimension) { + argsTable.push([ + [args.xDimension], + i18n.translate('visTypeXY.function.adimension.bucket', { + defaultMessage: 'Bucket', + }), + ]); + } + + const logTable = prepareLogTable(context, argsTable); + handlers.inspectorAdapters.tables.logDatatable('default', logTable); } return { diff --git a/src/plugins/vis_type_xy/public/plugin.ts b/src/plugins/vis_type_xy/public/plugin.ts index b595d3172f143..9e1e7354c8a69 100644 --- a/src/plugins/vis_type_xy/public/plugin.ts +++ b/src/plugins/vis_type_xy/public/plugin.ts @@ -77,7 +77,6 @@ export class VisTypeXyPlugin expressions.registerFunction(expressionFunctions.thresholdLine); expressions.registerFunction(expressionFunctions.label); expressions.registerFunction(expressionFunctions.visScale); - expressions.registerFunction(expressionFunctions.xyDimension); visTypesDefinitions.forEach(visualizations.createBaseVisualization); } diff --git a/src/plugins/vis_type_xy/public/types/param.ts b/src/plugins/vis_type_xy/public/types/param.ts index 7a2ff7e240264..6b0964e1c27de 100644 --- a/src/plugins/vis_type_xy/public/types/param.ts +++ b/src/plugins/vis_type_xy/public/types/param.ts @@ -8,7 +8,7 @@ import type { Fit, Position } from '@elastic/charts'; import type { Style, Labels, PaletteOutput } from '../../../charts/public'; -import type { SchemaConfig } from '../../../visualizations/public'; +import type { SchemaConfig, ExpressionValueXYDimension } from '../../../visualizations/public'; import type { ChartType, XyVisType } from '../../common'; import type { ExpressionValueCategoryAxis, @@ -17,7 +17,6 @@ import type { ExpressionValueLabel, ExpressionValueThresholdLine, ExpressionValueTimeMarker, - ExpressionValueXYDimension, } from '../expression_functions'; import type { diff --git a/src/plugins/visualizations/common/expression_functions/xy_dimension.ts b/src/plugins/visualizations/common/expression_functions/xy_dimension.ts new file mode 100644 index 0000000000000..fb039ea1a50b7 --- /dev/null +++ b/src/plugins/visualizations/common/expression_functions/xy_dimension.ts @@ -0,0 +1,107 @@ +/* + * 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 { ExpressionValueVisDimension } from './vis_dimension'; + +import type { + ExpressionFunctionDefinition, + ExpressionValueBoxed, + Datatable, + DatatableColumn, + SerializedFieldFormat, +} from '../../../expressions/common'; + +export interface DateHistogramParams { + date: boolean; + interval: number; + intervalESValue: number; + intervalESUnit: string; + format: string; + bounds?: { + min: string | number; + max: string | number; + }; +} + +export interface HistogramParams { + interval: number; +} + +export interface FakeParams { + defaultValue: string; +} + +interface Arguments { + visDimension: ExpressionValueVisDimension; + params: string; + aggType: string; + label: string; +} + +export type ExpressionValueXYDimension = ExpressionValueBoxed< + 'xy_dimension', + { + label: string; + aggType: string; + params: DateHistogramParams | HistogramParams | FakeParams | {}; + accessor: number | DatatableColumn; + format: SerializedFieldFormat; + } +>; + +export const xyDimension = (): ExpressionFunctionDefinition< + 'xydimension', + Datatable | null, + Arguments, + ExpressionValueXYDimension +> => ({ + name: 'xydimension', + help: i18n.translate('visTypeXy.function.xydimension.help', { + defaultMessage: 'Generates xy dimension object', + }), + type: 'xy_dimension', + args: { + visDimension: { + types: ['vis_dimension'], + help: i18n.translate('visTypeXy.function.xyDimension.visDimension.help', { + defaultMessage: 'Dimension object config', + }), + required: true, + }, + label: { + types: ['string'], + help: i18n.translate('visTypeXy.function.xyDimension.label.help', { + defaultMessage: 'Label', + }), + }, + aggType: { + types: ['string'], + help: i18n.translate('visTypeXy.function.xyDimension.aggType.help', { + defaultMessage: 'Aggregation type', + }), + }, + params: { + types: ['string'], + default: '"{}"', + help: i18n.translate('visTypeXy.function.xyDimension.params.help', { + defaultMessage: 'Params', + }), + }, + }, + fn: (context, args) => { + return { + type: 'xy_dimension', + label: args.label, + aggType: args.aggType, + params: JSON.parse(args.params!), + accessor: args.visDimension.accessor as number, + format: args.visDimension.format, + }; + }, +}); diff --git a/src/plugins/visualizations/common/prepare_log_table.ts b/src/plugins/visualizations/common/prepare_log_table.ts index f179eb8a1c10a..0018a18ce7f10 100644 --- a/src/plugins/visualizations/common/prepare_log_table.ts +++ b/src/plugins/visualizations/common/prepare_log_table.ts @@ -7,9 +7,13 @@ */ import { ExpressionValueVisDimension } from './expression_functions/vis_dimension'; +import { ExpressionValueXYDimension } from './expression_functions/xy_dimension'; import { Datatable } from '../../expressions/common/expression_types/specs'; -export type Dimension = [ExpressionValueVisDimension[] | undefined, string]; +export type Dimension = [ + Array | undefined, + string +]; const getDimensionName = (columnIndex: number, dimensions: Dimension[]) => { for (const dimension of dimensions) { diff --git a/src/plugins/visualizations/public/index.ts b/src/plugins/visualizations/public/index.ts index a01a2477dd311..825b6743a3509 100644 --- a/src/plugins/visualizations/public/index.ts +++ b/src/plugins/visualizations/public/index.ts @@ -41,5 +41,6 @@ export { } from './types'; export { VisualizationListItem, VisualizationStage } from './vis_types/vis_type_alias_registry'; export { VISUALIZE_ENABLE_LABS_SETTING } from '../common/constants'; -export { SavedVisState, VisParams, prepareLogTable } from '../common'; +export { SavedVisState, VisParams, prepareLogTable, Dimension } from '../common'; export { ExpressionValueVisDimension } from '../common/expression_functions/vis_dimension'; +export { ExpressionValueXYDimension } from '../common/expression_functions/xy_dimension'; diff --git a/src/plugins/visualizations/public/plugin.ts b/src/plugins/visualizations/public/plugin.ts index e3dcf79a63a76..4d91b6451db58 100644 --- a/src/plugins/visualizations/public/plugin.ts +++ b/src/plugins/visualizations/public/plugin.ts @@ -33,6 +33,7 @@ import { import { TypesService } from './vis_types/types_service'; import { range as rangeExpressionFunction } from '../common/expression_functions/range'; import { visDimension as visDimensionExpressionFunction } from '../common/expression_functions/vis_dimension'; +import { xyDimension as xyDimensionExpressionFunction } from '../common/expression_functions/xy_dimension'; import { createStartServicesGetter, StartServicesGetter } from '../../kibana_utils/public'; import { createSavedVisLoader, SavedVisualizationsLoader } from './saved_visualizations'; @@ -138,6 +139,7 @@ export class VisualizationsPlugin expressions.registerFunction(rangeExpressionFunction); expressions.registerFunction(visDimensionExpressionFunction); + expressions.registerFunction(xyDimensionExpressionFunction); const embeddableFactory = new VisualizeEmbeddableFactory({ start }); embeddable.registerEmbeddableFactory(VISUALIZE_EMBEDDABLE_TYPE, embeddableFactory); From 2b2f5a344c4b80f29a9d630b16c7149f238478f5 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 30 Jul 2021 11:56:29 +0300 Subject: [PATCH 2/8] Delete unused file --- .../expression_functions/xy_dimension.ts | 85 ------------------- 1 file changed, 85 deletions(-) delete mode 100644 src/plugins/vis_type_xy/public/expression_functions/xy_dimension.ts diff --git a/src/plugins/vis_type_xy/public/expression_functions/xy_dimension.ts b/src/plugins/vis_type_xy/public/expression_functions/xy_dimension.ts deleted file mode 100644 index ecbc3640c035b..0000000000000 --- a/src/plugins/vis_type_xy/public/expression_functions/xy_dimension.ts +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 { ExpressionValueVisDimension } from '../../../visualizations/public'; -import type { - ExpressionFunctionDefinition, - Datatable, - ExpressionValueBoxed, -} from '../../../expressions/public'; -import type { Dimension } from '../types'; - -interface Arguments { - visDimension: ExpressionValueVisDimension; - params: string; - aggType: string; - label: string; -} - -export type ExpressionValueXYDimension = ExpressionValueBoxed< - 'xy_dimension', - { - label: string; - aggType: string; - params: Dimension['params']; - accessor: number; - format: Dimension['format']; - } ->; - -export const xyDimension = (): ExpressionFunctionDefinition< - 'xydimension', - Datatable | null, - Arguments, - ExpressionValueXYDimension -> => ({ - name: 'xydimension', - help: i18n.translate('visTypeXy.function.xydimension.help', { - defaultMessage: 'Generates xy dimension object', - }), - type: 'xy_dimension', - args: { - visDimension: { - types: ['vis_dimension'], - help: i18n.translate('visTypeXy.function.xyDimension.visDimension.help', { - defaultMessage: 'Dimension object config', - }), - required: true, - }, - label: { - types: ['string'], - help: i18n.translate('visTypeXy.function.xyDimension.label.help', { - defaultMessage: 'Label', - }), - }, - aggType: { - types: ['string'], - help: i18n.translate('visTypeXy.function.xyDimension.aggType.help', { - defaultMessage: 'Aggregation type', - }), - }, - params: { - types: ['string'], - default: '"{}"', - help: i18n.translate('visTypeXy.function.xyDimension.params.help', { - defaultMessage: 'Params', - }), - }, - }, - fn: (context, args) => { - return { - type: 'xy_dimension', - label: args.label, - aggType: args.aggType, - params: JSON.parse(args.params!), - accessor: args.visDimension.accessor as number, - format: args.visDimension.format, - }; - }, -}); From 5995535720dade03d47f2667d03c45d7567967e6 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 30 Jul 2021 12:07:36 +0300 Subject: [PATCH 3/8] fix i18n --- .../public/expression_functions/xy_vis_fn.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts b/src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts index 602906f496a27..35f3b2d7c627d 100644 --- a/src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts +++ b/src/plugins/vis_type_xy/public/expression_functions/xy_vis_fn.ts @@ -266,25 +266,25 @@ export const visTypeXyVisFn = (): VisTypeXyExpressionFunctionDefinition => ({ const argsTable: Dimension[] = [ [ args.yDimension, - i18n.translate('visTypeXY.function.dimension.metric', { + i18n.translate('visTypeXy.function.dimension.metric', { defaultMessage: 'Metric', }), ], [ args.zDimension, - i18n.translate('visTypeXY.function.adimension.dotSize', { + i18n.translate('visTypeXy.function.adimension.dotSize', { defaultMessage: 'Dot size', }), ], [ args.splitColumnDimension, - i18n.translate('visTypeXY.function.dimension.splitcolumn', { + i18n.translate('visTypeXy.function.dimension.splitcolumn', { defaultMessage: 'Column split', }), ], [ args.splitRowDimension, - i18n.translate('visTypeXY.function.dimension.splitrow', { + i18n.translate('visTypeXy.function.dimension.splitrow', { defaultMessage: 'Row split', }), ], @@ -293,7 +293,7 @@ export const visTypeXyVisFn = (): VisTypeXyExpressionFunctionDefinition => ({ if (args.xDimension) { argsTable.push([ [args.xDimension], - i18n.translate('visTypeXY.function.adimension.bucket', { + i18n.translate('visTypeXy.function.adimension.bucket', { defaultMessage: 'Bucket', }), ]); From 764384a7cedb24a755fade8fbe8ead743fa31a4f Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 30 Jul 2021 12:20:24 +0300 Subject: [PATCH 4/8] Another fix of i18n --- .../common/expression_functions/xy_dimension.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/visualizations/common/expression_functions/xy_dimension.ts b/src/plugins/visualizations/common/expression_functions/xy_dimension.ts index fb039ea1a50b7..82538fea8605a 100644 --- a/src/plugins/visualizations/common/expression_functions/xy_dimension.ts +++ b/src/plugins/visualizations/common/expression_functions/xy_dimension.ts @@ -62,34 +62,34 @@ export const xyDimension = (): ExpressionFunctionDefinition< ExpressionValueXYDimension > => ({ name: 'xydimension', - help: i18n.translate('visTypeXy.function.xydimension.help', { + help: i18n.translate('visualizations.function.xydimension.help', { defaultMessage: 'Generates xy dimension object', }), type: 'xy_dimension', args: { visDimension: { types: ['vis_dimension'], - help: i18n.translate('visTypeXy.function.xyDimension.visDimension.help', { + help: i18n.translate('visualizations.function.xyDimension.visDimension.help', { defaultMessage: 'Dimension object config', }), required: true, }, label: { types: ['string'], - help: i18n.translate('visTypeXy.function.xyDimension.label.help', { + help: i18n.translate('visualizations.function.xyDimension.label.help', { defaultMessage: 'Label', }), }, aggType: { types: ['string'], - help: i18n.translate('visTypeXy.function.xyDimension.aggType.help', { + help: i18n.translate('visualizations.function.xyDimension.aggType.help', { defaultMessage: 'Aggregation type', }), }, params: { types: ['string'], default: '"{}"', - help: i18n.translate('visTypeXy.function.xyDimension.params.help', { + help: i18n.translate('visualizations.function.xyDimension.params.help', { defaultMessage: 'Params', }), }, From 60ea0781173b90c4e35274dfe7ee65bb41cfc362 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 30 Jul 2021 12:35:21 +0300 Subject: [PATCH 5/8] Fix translations --- x-pack/plugins/translations/translations/ja-JP.json | 10 +++++----- x-pack/plugins/translations/translations/zh-CN.json | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 0e8a0d8e45a7d..8fb31cda63643 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -5199,11 +5199,11 @@ "visTypeXy.function.valueAxis.axisParams.help": "値軸パラメーター", "visTypeXy.function.valueaxis.help": "値軸オブジェクトを生成します", "visTypeXy.function.valueAxis.name.help": "値軸の名前", - "visTypeXy.function.xyDimension.aggType.help": "集約タイプ", - "visTypeXy.function.xydimension.help": "XYディメンションオブジェクトを生成します", - "visTypeXy.function.xyDimension.label.help": "ラベル", - "visTypeXy.function.xyDimension.params.help": "パラメーター", - "visTypeXy.function.xyDimension.visDimension.help": "ディメンションオブジェクト構成", + "visualizations.function.xyDimension.aggType.help": "集約タイプ", + "visualizations.function.xydimension.help": "XYディメンションオブジェクトを生成します", + "visualizations.function.xyDimension.label.help": "ラベル", + "visualizations.function.xyDimension.params.help": "パラメーター", + "visualizations.function.xyDimension.visDimension.help": "ディメンションオブジェクト構成", "visTypeXy.functions.help": "XYビジュアライゼーション", "visTypeXy.histogram.groupTitle": "系列を分割", "visTypeXy.histogram.histogramDescription": "軸の縦棒にデータを表示します。", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 97302468aae47..9dab5a5c9853a 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -5227,11 +5227,11 @@ "visTypeXy.function.valueAxis.axisParams.help": "值轴参数", "visTypeXy.function.valueaxis.help": "生成值轴对象", "visTypeXy.function.valueAxis.name.help": "值轴的名称", - "visTypeXy.function.xyDimension.aggType.help": "聚合类型", - "visTypeXy.function.xydimension.help": "生成 xy 维度对象", - "visTypeXy.function.xyDimension.label.help": "标签", - "visTypeXy.function.xyDimension.params.help": "参数", - "visTypeXy.function.xyDimension.visDimension.help": "维度对象配置", + "visualizations.function.xyDimension.aggType.help": "聚合类型", + "visualizations.function.xydimension.help": "生成 xy 维度对象", + "visualizations.function.xyDimension.label.help": "标签", + "visualizations.function.xyDimension.params.help": "参数", + "visualizations.function.xyDimension.visDimension.help": "维度对象配置", "visTypeXy.functions.help": "XY 可视化", "visTypeXy.histogram.groupTitle": "拆分序列", "visTypeXy.histogram.histogramDescription": "在轴上以垂直条形图的形式呈现数据。", From 22c82eb699c4086d7c7ec0ea521556b9ec63c524 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 30 Jul 2021 15:51:03 +0300 Subject: [PATCH 6/8] Remove double types --- src/plugins/vis_type_vislib/public/to_ast.ts | 4 ++- .../helpers/point_series/_init_x_axis.test.ts | 2 +- .../point_series/_ordered_date_axis.test.ts | 2 +- .../helpers/point_series/point_series.ts | 8 ++---- .../vis_type_xy/public/config/get_config.ts | 2 +- src/plugins/vis_type_xy/public/index.ts | 2 -- src/plugins/vis_type_xy/public/to_ast.ts | 9 ++++-- src/plugins/vis_type_xy/public/types/param.ts | 28 +++++-------------- .../vis_type_xy/public/utils/domain.ts | 3 +- src/plugins/visualizations/public/index.ts | 7 ++++- 10 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/plugins/vis_type_vislib/public/to_ast.ts b/src/plugins/vis_type_vislib/public/to_ast.ts index 5894b4be964e0..1e33c589ff1fc 100644 --- a/src/plugins/vis_type_vislib/public/to_ast.ts +++ b/src/plugins/vis_type_vislib/public/to_ast.ts @@ -15,7 +15,9 @@ import { VisParams, } from '../../visualizations/public'; import { buildExpression, buildExpressionFunction } from '../../expressions/public'; -import type { Dimensions, DateHistogramParams, HistogramParams } from '../../vis_type_xy/public'; +import type { Dimensions } from '../../vis_type_xy/public'; +import type { DateHistogramParams, HistogramParams } from '../../visualizations/public'; + import { BUCKET_TYPES } from '../../data/public'; import { vislibVisName, VisTypeVislibExpressionFunctionDefinition } from './vis_type_vislib_vis_fn'; diff --git a/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_init_x_axis.test.ts b/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_init_x_axis.test.ts index 3c489539d6b2e..cb0ebe563f54b 100644 --- a/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_init_x_axis.test.ts +++ b/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_init_x_axis.test.ts @@ -8,7 +8,7 @@ import moment from 'moment'; -import type { DateHistogramParams, HistogramParams } from '../../../../../vis_type_xy/public'; +import type { DateHistogramParams, HistogramParams } from '../../../../../visualizations/public'; import { initXAxis } from './_init_x_axis'; import { makeFakeXAspect } from './_fake_x_aspect'; diff --git a/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_ordered_date_axis.test.ts b/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_ordered_date_axis.test.ts index ebfcacc83de5c..3cc0dc656eaef 100644 --- a/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_ordered_date_axis.test.ts +++ b/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_ordered_date_axis.test.ts @@ -9,7 +9,7 @@ import moment from 'moment'; import _ from 'lodash'; -import type { DateHistogramParams } from '../../../../../vis_type_xy/public/types'; +import type { DateHistogramParams } from '../../../../../visualizations/public/types'; import { orderedDateAxis } from './_ordered_date_axis'; import { OrderedChart } from './point_series'; diff --git a/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/point_series.ts b/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/point_series.ts index db2b738681cd1..62be39ffb8a73 100644 --- a/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/point_series.ts +++ b/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/point_series.ts @@ -8,12 +8,8 @@ import { Duration } from 'moment'; -import type { - Dimension, - Dimensions, - DateHistogramParams, - HistogramParams, -} from '../../../../../vis_type_xy/public'; +import type { Dimension, Dimensions } from '../../../../../vis_type_xy/public'; +import type { DateHistogramParams, HistogramParams } from '../../../../../visualizations/public'; import { getSeries } from './_get_series'; import { getAspects } from './_get_aspects'; diff --git a/src/plugins/vis_type_xy/public/config/get_config.ts b/src/plugins/vis_type_xy/public/config/get_config.ts index ce01572060a40..0c687aa918056 100644 --- a/src/plugins/vis_type_xy/public/config/get_config.ts +++ b/src/plugins/vis_type_xy/public/config/get_config.ts @@ -10,11 +10,11 @@ import { ScaleContinuousType } from '@elastic/charts'; import { Datatable } from '../../../expressions/public'; import { BUCKET_TYPES } from '../../../data/public'; +import { DateHistogramParams } from '../../../visualizations/public'; import { Aspect, AxisConfig, - DateHistogramParams, SeriesParam, VisConfig, VisParams, diff --git a/src/plugins/vis_type_xy/public/index.ts b/src/plugins/vis_type_xy/public/index.ts index 8691ad606da95..55fa84c72603e 100644 --- a/src/plugins/vis_type_xy/public/index.ts +++ b/src/plugins/vis_type_xy/public/index.ts @@ -22,8 +22,6 @@ export { Dimensions, ScaleType, AxisType, - HistogramParams, - DateHistogramParams, } from './types'; export type { ValidationVisOptionsProps } from './editor/components/common/validation_wrapper'; export { TruncateLabelsOption } from './editor/components/common/truncate_labels'; diff --git a/src/plugins/vis_type_xy/public/to_ast.ts b/src/plugins/vis_type_xy/public/to_ast.ts index f473cd77c2d2b..9fec3f99ab39b 100644 --- a/src/plugins/vis_type_xy/public/to_ast.ts +++ b/src/plugins/vis_type_xy/public/to_ast.ts @@ -8,16 +8,19 @@ import moment from 'moment'; -import { VisToExpressionAst, getVisSchemas } from '../../visualizations/public'; +import { + VisToExpressionAst, + getVisSchemas, + DateHistogramParams, + HistogramParams, +} from '../../visualizations/public'; import { buildExpression, buildExpressionFunction } from '../../expressions/public'; import { BUCKET_TYPES } from '../../data/public'; import { Labels } from '../../charts/public'; import { - DateHistogramParams, Dimensions, Dimension, - HistogramParams, VisParams, CategoryAxis, SeriesParam, diff --git a/src/plugins/vis_type_xy/public/types/param.ts b/src/plugins/vis_type_xy/public/types/param.ts index 6b0964e1c27de..421690f7fc6a9 100644 --- a/src/plugins/vis_type_xy/public/types/param.ts +++ b/src/plugins/vis_type_xy/public/types/param.ts @@ -8,7 +8,13 @@ import type { Fit, Position } from '@elastic/charts'; import type { Style, Labels, PaletteOutput } from '../../../charts/public'; -import type { SchemaConfig, ExpressionValueXYDimension } from '../../../visualizations/public'; +import type { + SchemaConfig, + ExpressionValueXYDimension, + FakeParams, + HistogramParams, + DateHistogramParams, +} from '../../../visualizations/public'; import type { ChartType, XyVisType } from '../../common'; import type { ExpressionValueCategoryAxis, @@ -95,26 +101,6 @@ export interface TimeMarker { width?: number; } -export interface DateHistogramParams { - date: boolean; - interval: number; - intervalESValue: number; - intervalESUnit: string; - format: string; - bounds?: { - min: string | number; - max: string | number; - }; -} - -export interface HistogramParams { - interval: number; -} - -export interface FakeParams { - defaultValue: string; -} - export type Dimension = Omit & { params: DateHistogramParams | HistogramParams | FakeParams | {}; }; diff --git a/src/plugins/vis_type_xy/public/utils/domain.ts b/src/plugins/vis_type_xy/public/utils/domain.ts index 9cd74cd0433cc..48527ec9333ed 100644 --- a/src/plugins/vis_type_xy/public/utils/domain.ts +++ b/src/plugins/vis_type_xy/public/utils/domain.ts @@ -13,8 +13,9 @@ import { DomainRange } from '@elastic/charts'; import { getAdjustedInterval } from '../../../charts/public'; import { Datatable } from '../../../expressions/public'; +import { DateHistogramParams, HistogramParams } from '../../../visualizations/public'; -import { Aspect, DateHistogramParams, HistogramParams } from '../types'; +import { Aspect } from '../types'; export const getXDomain = (params: Aspect['params']): DomainRange => { const minInterval = (params as DateHistogramParams | HistogramParams)?.interval ?? undefined; diff --git a/src/plugins/visualizations/public/index.ts b/src/plugins/visualizations/public/index.ts index 825b6743a3509..0886f230d101f 100644 --- a/src/plugins/visualizations/public/index.ts +++ b/src/plugins/visualizations/public/index.ts @@ -43,4 +43,9 @@ export { VisualizationListItem, VisualizationStage } from './vis_types/vis_type_ export { VISUALIZE_ENABLE_LABS_SETTING } from '../common/constants'; export { SavedVisState, VisParams, prepareLogTable, Dimension } from '../common'; export { ExpressionValueVisDimension } from '../common/expression_functions/vis_dimension'; -export { ExpressionValueXYDimension } from '../common/expression_functions/xy_dimension'; +export { + ExpressionValueXYDimension, + DateHistogramParams, + FakeParams, + HistogramParams, +} from '../common/expression_functions/xy_dimension'; From d1941beba42e94cee0f4c4ae23f93e1689301787 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 30 Jul 2021 16:21:41 +0300 Subject: [PATCH 7/8] Fix types --- src/plugins/vis_type_xy/public/utils/accessors.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/vis_type_xy/public/utils/accessors.tsx b/src/plugins/vis_type_xy/public/utils/accessors.tsx index 0f73ebe7eed86..4920885f51a07 100644 --- a/src/plugins/vis_type_xy/public/utils/accessors.tsx +++ b/src/plugins/vis_type_xy/public/utils/accessors.tsx @@ -8,7 +8,8 @@ import { AccessorFn, Accessor } from '@elastic/charts'; import { BUCKET_TYPES } from '../../../data/public'; -import { FakeParams, Aspect } from '../types'; +import { FakeParams } from '../../../visualizations/public'; +import { Aspect } from '../types'; export const COMPLEX_X_ACCESSOR = '__customXAccessor__'; export const COMPLEX_SPLIT_ACCESSOR = '__complexSplitAccessor__'; From 12789f46ce123845311c479671eebef6283c996b Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 30 Jul 2021 16:53:50 +0300 Subject: [PATCH 8/8] Another type fix --- .../vislib/helpers/point_series/_ordered_date_axis.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_ordered_date_axis.test.ts b/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_ordered_date_axis.test.ts index 3cc0dc656eaef..4dfa5035275fb 100644 --- a/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_ordered_date_axis.test.ts +++ b/src/plugins/vis_type_vislib/public/vislib/helpers/point_series/_ordered_date_axis.test.ts @@ -9,7 +9,7 @@ import moment from 'moment'; import _ from 'lodash'; -import type { DateHistogramParams } from '../../../../../visualizations/public/types'; +import type { DateHistogramParams } from '../../../../../visualizations/public'; import { orderedDateAxis } from './_ordered_date_axis'; import { OrderedChart } from './point_series';