Skip to content

Commit

Permalink
[XY] Move data layer args inside xyVis directly (#131702)
Browse files Browse the repository at this point in the history
* Move data layer arg inside xyVis directly

* Fix CI

* Fix lint

* Move some types
  • Loading branch information
VladLasitsa authored May 10, 2022
1 parent e4c11e3 commit 3c33854
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommonDataLayerArgs[key]>;
};

export const commonDataLayerArgs: CommonDataLayerFn['args'] = {
export const commonDataLayerArgs: CommonDataLayerFnArgs = {
hide: {
types: ['boolean'],
default: false,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
},
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -190,7 +190,6 @@ export interface XYArgs {
endValue?: EndValue;
emphasizeFitting?: boolean;
valueLabels: ValueLabelMode;
dataLayers: DataLayerConfigResult[];
referenceLineLayers: ReferenceLineLayerConfigResult[];
annotationLayers: AnnotationLayerConfigResult[];
fittingFunction?: FittingFunction;
Expand Down Expand Up @@ -385,12 +384,6 @@ export type LayeredXyVisFn = ExpressionFunctionDefinition<
Promise<XYRender>
>;

export type DataLayerFn = ExpressionFunctionDefinition<
typeof DATA_LAYER,
Datatable,
DataLayerArgs,
DataLayerConfigResult
>;
export type ExtendedDataLayerFn = ExpressionFunctionDefinition<
typeof EXTENDED_DATA_LAYER,
Datatable,
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/chart_expressions/expression_xy/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { ExpressionXyPluginSetup, ExpressionXyPluginStart, SetupDeps } from './t
import {
xyVisFunction,
layeredXyVisFunction,
dataLayerFunction,
extendedDataLayerFunction,
yAxisConfigFunction,
extendedYAxisConfigFunction,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/chart_expressions/expression_xy/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
extendedYAxisConfigFunction,
legendConfigFunction,
gridlinesConfigFunction,
dataLayerFunction,
axisExtentConfigFunction,
tickLabelsConfigFunction,
annotationLayerFunction,
Expand All @@ -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);
Expand Down

0 comments on commit 3c33854

Please sign in to comment.