diff --git a/src/plugins/chart_expressions/expression_xy/common/expression_functions/common_data_layer_args.ts b/src/plugins/chart_expressions/expression_xy/common/expression_functions/common_data_layer_args.ts index 49446310a894b..5a1dad533c084 100644 --- a/src/plugins/chart_expressions/expression_xy/common/expression_functions/common_data_layer_args.ts +++ b/src/plugins/chart_expressions/expression_xy/common/expression_functions/common_data_layer_args.ts @@ -6,13 +6,17 @@ * Side Public License, v 1. */ +import { ArgumentType } from '@kbn/expressions-plugin/common'; import { SeriesTypes, XScaleTypes, YScaleTypes, Y_CONFIG } from '../constants'; import { strings } from '../i18n'; -import { DataLayerFn, ExtendedDataLayerFn } from '../types'; +import { DataLayerArgs, ExtendedDataLayerArgs } from '../types'; -type CommonDataLayerFn = DataLayerFn | ExtendedDataLayerFn; +type CommonDataLayerArgs = ExtendedDataLayerArgs | DataLayerArgs; +type CommonDataLayerFnArgs = { + [key in keyof CommonDataLayerArgs]: ArgumentType; +}; -export const commonDataLayerArgs: CommonDataLayerFn['args'] = { +export const commonDataLayerArgs: CommonDataLayerFnArgs = { hide: { types: ['boolean'], default: false, diff --git a/src/plugins/chart_expressions/expression_xy/common/expression_functions/data_layer.test.ts b/src/plugins/chart_expressions/expression_xy/common/expression_functions/data_layer.test.ts deleted file mode 100644 index 518690d47bfcb..0000000000000 --- a/src/plugins/chart_expressions/expression_xy/common/expression_functions/data_layer.test.ts +++ /dev/null @@ -1,38 +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 { DataLayerArgs } from '../types'; -import { createMockExecutionContext } from '@kbn/expressions-plugin/common/mocks'; -import { mockPaletteOutput, sampleArgs } from '../__mocks__'; -import { LayerTypes } from '../constants'; -import { dataLayerFunction } from './data_layer'; - -describe('dataLayerConfig', () => { - test('produces the correct arguments', () => { - const { data } = sampleArgs(); - const args: DataLayerArgs = { - seriesType: 'line', - xAccessor: 'c', - accessors: ['a', 'b'], - splitAccessor: 'd', - xScaleType: 'linear', - yScaleType: 'linear', - isHistogram: false, - palette: mockPaletteOutput, - }; - - const result = dataLayerFunction.fn(data, args, createMockExecutionContext()); - - expect(result).toEqual({ - type: 'dataLayer', - layerType: LayerTypes.DATA, - ...args, - table: data, - }); - }); -}); diff --git a/src/plugins/chart_expressions/expression_xy/common/expression_functions/data_layer.ts b/src/plugins/chart_expressions/expression_xy/common/expression_functions/data_layer.ts deleted file mode 100644 index f36a0ea4c101f..0000000000000 --- a/src/plugins/chart_expressions/expression_xy/common/expression_functions/data_layer.ts +++ /dev/null @@ -1,30 +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 { DataLayerFn } from '../types'; -import { DATA_LAYER, LayerTypes } from '../constants'; -import { strings } from '../i18n'; -import { commonDataLayerArgs } from './common_data_layer_args'; - -export const dataLayerFunction: DataLayerFn = { - name: DATA_LAYER, - aliases: [], - type: DATA_LAYER, - help: strings.getDataLayerFnHelp(), - inputTypes: ['datatable'], - args: { ...commonDataLayerArgs }, - fn(table, args) { - return { - type: DATA_LAYER, - ...args, - accessors: args.accessors ?? [], - layerType: LayerTypes.DATA, - table, - }; - }, -}; diff --git a/src/plugins/chart_expressions/expression_xy/common/expression_functions/index.ts b/src/plugins/chart_expressions/expression_xy/common/expression_functions/index.ts index ab1d570a07351..30a76217b5c0e 100644 --- a/src/plugins/chart_expressions/expression_xy/common/expression_functions/index.ts +++ b/src/plugins/chart_expressions/expression_xy/common/expression_functions/index.ts @@ -13,7 +13,6 @@ export * from './annotation_layer'; export * from './extended_annotation_layer'; export * from './y_axis_config'; export * from './extended_y_axis_config'; -export * from './data_layer'; export * from './extended_data_layer'; export * from './grid_lines_config'; export * from './axis_extent_config'; diff --git a/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.test.ts b/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.test.ts index 688efbe122f3e..871135dd45bcb 100644 --- a/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.test.ts +++ b/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.test.ts @@ -15,16 +15,22 @@ describe('xyVis', () => { test('it renders with the specified data and args', async () => { const { data, args } = sampleArgs(); const { layers, ...rest } = args; + const { layerId, layerType, table, type, ...restLayerArgs } = sampleLayer; const result = await xyVisFunction.fn( data, - { ...rest, dataLayers: [sampleLayer], referenceLineLayers: [], annotationLayers: [] }, + { ...rest, ...restLayerArgs, referenceLineLayers: [], annotationLayers: [] }, createMockExecutionContext() ); expect(result).toEqual({ type: 'render', as: XY_VIS, - value: { args: { ...rest, layers: [sampleLayer] } }, + value: { + args: { + ...rest, + layers: [{ layerType, table: data, layerId: 'dataLayers-0', type, ...restLayerArgs }], + }, + }, }); }); }); diff --git a/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.ts b/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.ts index 2e97cb00b3e55..e8a5858d3ed26 100644 --- a/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.ts +++ b/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.ts @@ -7,9 +7,10 @@ */ import { XyVisFn } from '../types'; -import { XY_VIS, DATA_LAYER, REFERENCE_LINE_LAYER, ANNOTATION_LAYER } from '../constants'; +import { XY_VIS, REFERENCE_LINE_LAYER, ANNOTATION_LAYER } from '../constants'; import { strings } from '../i18n'; import { commonXYArgs } from './common_xy_args'; +import { commonDataLayerArgs } from './common_data_layer_args'; export const xyVisFunction: XyVisFn = { name: XY_VIS, @@ -18,11 +19,7 @@ export const xyVisFunction: XyVisFn = { help: strings.getXYHelp(), args: { ...commonXYArgs, - dataLayers: { - types: [DATA_LAYER], - help: strings.getDataLayerHelp(), - multi: true, - }, + ...commonDataLayerArgs, referenceLineLayers: { types: [REFERENCE_LINE_LAYER], help: strings.getReferenceLineLayerHelp(), diff --git a/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis_fn.ts b/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis_fn.ts index 1bd75e1296c6c..6ce3116d377e1 100644 --- a/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis_fn.ts +++ b/src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis_fn.ts @@ -7,9 +7,9 @@ */ import { Dimension, prepareLogTable } from '@kbn/visualizations-plugin/common/utils'; -import { LayerTypes, XY_VIS_RENDERER } from '../constants'; +import { LayerTypes, XY_VIS_RENDERER, DATA_LAYER } from '../constants'; import { appendLayerIds } from '../helpers'; -import { XYLayerConfig, XyVisFn } from '../types'; +import { DataLayerConfigResult, XYLayerConfig, XyVisFn } from '../types'; import { getLayerDimensions } from '../utils'; import { hasAreaLayer, @@ -21,7 +21,40 @@ import { } from './validate'; export const xyVisFn: XyVisFn['fn'] = async (data, args, handlers) => { - const { dataLayers = [], referenceLineLayers = [], annotationLayers = [], ...restArgs } = args; + const { + referenceLineLayers = [], + annotationLayers = [], + seriesType, + accessors = [], + xAccessor, + hide, + splitAccessor, + columnToLabel, + yScaleType, + xScaleType, + isHistogram, + yConfig, + palette, + ...restArgs + } = args; + const dataLayers: DataLayerConfigResult[] = [ + { + type: DATA_LAYER, + seriesType, + accessors, + xAccessor, + hide, + splitAccessor, + columnToLabel, + yScaleType, + xScaleType, + isHistogram, + palette, + yConfig, + layerType: LayerTypes.DATA, + table: data, + }, + ]; const layers: XYLayerConfig[] = [ ...appendLayerIds(dataLayers, 'dataLayers'), ...appendLayerIds(referenceLineLayers, 'referenceLineLayers'), diff --git a/src/plugins/chart_expressions/expression_xy/common/types/expression_functions.ts b/src/plugins/chart_expressions/expression_xy/common/types/expression_functions.ts index b3c7bca93ca29..f7f7c5bcd1544 100644 --- a/src/plugins/chart_expressions/expression_xy/common/types/expression_functions.ts +++ b/src/plugins/chart_expressions/expression_xy/common/types/expression_functions.ts @@ -180,7 +180,7 @@ export interface LabelsOrientationConfig { } // Arguments to XY chart expression, with computed properties -export interface XYArgs { +export interface XYArgs extends DataLayerArgs { xTitle: string; yTitle: string; yRightTitle: string; @@ -190,7 +190,6 @@ export interface XYArgs { endValue?: EndValue; emphasizeFitting?: boolean; valueLabels: ValueLabelMode; - dataLayers: DataLayerConfigResult[]; referenceLineLayers: ReferenceLineLayerConfigResult[]; annotationLayers: AnnotationLayerConfigResult[]; fittingFunction?: FittingFunction; @@ -385,12 +384,6 @@ export type LayeredXyVisFn = ExpressionFunctionDefinition< Promise >; -export type DataLayerFn = ExpressionFunctionDefinition< - typeof DATA_LAYER, - Datatable, - DataLayerArgs, - DataLayerConfigResult ->; export type ExtendedDataLayerFn = ExpressionFunctionDefinition< typeof EXTENDED_DATA_LAYER, Datatable, diff --git a/src/plugins/chart_expressions/expression_xy/public/plugin.ts b/src/plugins/chart_expressions/expression_xy/public/plugin.ts index 5e68d2c621894..5c27da6b82b28 100755 --- a/src/plugins/chart_expressions/expression_xy/public/plugin.ts +++ b/src/plugins/chart_expressions/expression_xy/public/plugin.ts @@ -17,7 +17,6 @@ import { ExpressionXyPluginSetup, ExpressionXyPluginStart, SetupDeps } from './t import { xyVisFunction, layeredXyVisFunction, - dataLayerFunction, extendedDataLayerFunction, yAxisConfigFunction, extendedYAxisConfigFunction, @@ -59,7 +58,6 @@ export class ExpressionXyPlugin { expressions.registerFunction(extendedYAxisConfigFunction); expressions.registerFunction(legendConfigFunction); expressions.registerFunction(gridlinesConfigFunction); - expressions.registerFunction(dataLayerFunction); expressions.registerFunction(extendedDataLayerFunction); expressions.registerFunction(axisExtentConfigFunction); expressions.registerFunction(tickLabelsConfigFunction); diff --git a/src/plugins/chart_expressions/expression_xy/server/plugin.ts b/src/plugins/chart_expressions/expression_xy/server/plugin.ts index 37252a7296580..cefde5d38a5f4 100755 --- a/src/plugins/chart_expressions/expression_xy/server/plugin.ts +++ b/src/plugins/chart_expressions/expression_xy/server/plugin.ts @@ -15,7 +15,6 @@ import { extendedYAxisConfigFunction, legendConfigFunction, gridlinesConfigFunction, - dataLayerFunction, axisExtentConfigFunction, tickLabelsConfigFunction, annotationLayerFunction, @@ -37,7 +36,6 @@ export class ExpressionXyPlugin expressions.registerFunction(extendedYAxisConfigFunction); expressions.registerFunction(legendConfigFunction); expressions.registerFunction(gridlinesConfigFunction); - expressions.registerFunction(dataLayerFunction); expressions.registerFunction(extendedDataLayerFunction); expressions.registerFunction(axisExtentConfigFunction); expressions.registerFunction(tickLabelsConfigFunction);