Skip to content

Commit a8db1db

Browse files
Merge branch 'main' into fix-non-ecs-sort
2 parents 606927c + 1b4ac7d commit a8db1db

File tree

188 files changed

+3548
-2043
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+3548
-2043
lines changed

src/plugins/chart_expressions/expression_xy/common/expression_functions/__snapshots__/extended_data_layer.test.ts.snap

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/chart_expressions/expression_xy/common/expression_functions/common_data_layer_args.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ export const commonDataLayerArgs: Omit<
4343
default: false,
4444
help: strings.getIsHistogramHelp(),
4545
},
46+
lineWidth: {
47+
types: ['number'],
48+
help: strings.getLineWidthHelp(),
49+
},
50+
showPoints: {
51+
types: ['boolean'],
52+
help: strings.getShowPointsHelp(),
53+
},
54+
pointsRadius: {
55+
types: ['number'],
56+
help: strings.getPointsRadiusHelp(),
57+
},
4658
yConfig: {
4759
types: [Y_CONFIG],
4860
help: strings.getYConfigHelp(),

src/plugins/chart_expressions/expression_xy/common/expression_functions/extended_data_layer.test.ts

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,92 @@ import { LayerTypes } from '../constants';
1313
import { extendedDataLayerFunction } from './extended_data_layer';
1414

1515
describe('extendedDataLayerConfig', () => {
16+
const args: ExtendedDataLayerArgs = {
17+
seriesType: 'line',
18+
xAccessor: 'c',
19+
accessors: ['a', 'b'],
20+
splitAccessor: 'd',
21+
xScaleType: 'linear',
22+
isHistogram: false,
23+
palette: mockPaletteOutput,
24+
};
25+
1626
test('produces the correct arguments', async () => {
1727
const { data } = sampleArgs();
18-
const args: ExtendedDataLayerArgs = {
19-
seriesType: 'line',
20-
xAccessor: 'c',
21-
accessors: ['a', 'b'],
22-
splitAccessor: 'd',
23-
xScaleType: 'linear',
24-
isHistogram: false,
25-
palette: mockPaletteOutput,
28+
const fullArgs: ExtendedDataLayerArgs = {
29+
...args,
2630
markSizeAccessor: 'b',
31+
showPoints: true,
32+
lineWidth: 10,
33+
pointsRadius: 10,
2734
};
2835

29-
const result = await extendedDataLayerFunction.fn(data, args, createMockExecutionContext());
36+
const result = await extendedDataLayerFunction.fn(data, fullArgs, createMockExecutionContext());
3037

3138
expect(result).toEqual({
3239
type: 'extendedDataLayer',
3340
layerType: LayerTypes.DATA,
34-
...args,
41+
...fullArgs,
3542
table: data,
3643
});
3744
});
3845

3946
test('throws the error if markSizeAccessor is provided to the not line/area chart', async () => {
4047
const { data } = sampleArgs();
41-
const args: ExtendedDataLayerArgs = {
42-
seriesType: 'bar',
43-
xAccessor: 'c',
44-
accessors: ['a', 'b'],
45-
splitAccessor: 'd',
46-
xScaleType: 'linear',
47-
isHistogram: false,
48-
palette: mockPaletteOutput,
49-
markSizeAccessor: 'b',
50-
};
5148

5249
expect(
53-
extendedDataLayerFunction.fn(data, args, createMockExecutionContext())
50+
extendedDataLayerFunction.fn(
51+
data,
52+
{ ...args, seriesType: 'bar', markSizeAccessor: 'b' },
53+
createMockExecutionContext()
54+
)
5455
).rejects.toThrowErrorMatchingSnapshot();
5556
});
5657

5758
test("throws the error if markSizeAccessor doesn't have the corresponding column in the table", async () => {
5859
const { data } = sampleArgs();
59-
const args: ExtendedDataLayerArgs = {
60-
seriesType: 'line',
61-
xAccessor: 'c',
62-
accessors: ['a', 'b'],
63-
splitAccessor: 'd',
64-
xScaleType: 'linear',
65-
isHistogram: false,
66-
palette: mockPaletteOutput,
67-
markSizeAccessor: 'nonsense',
68-
};
6960

7061
expect(
71-
extendedDataLayerFunction.fn(data, args, createMockExecutionContext())
62+
extendedDataLayerFunction.fn(
63+
data,
64+
{ ...args, markSizeAccessor: 'nonsense' },
65+
createMockExecutionContext()
66+
)
67+
).rejects.toThrowErrorMatchingSnapshot();
68+
});
69+
70+
test('throws the error if lineWidth is provided to the not line/area chart', async () => {
71+
const { data } = sampleArgs();
72+
expect(
73+
extendedDataLayerFunction.fn(
74+
data,
75+
{ ...args, seriesType: 'bar', lineWidth: 10 },
76+
createMockExecutionContext()
77+
)
78+
).rejects.toThrowErrorMatchingSnapshot();
79+
});
80+
81+
test('throws the error if showPoints is provided to the not line/area chart', async () => {
82+
const { data } = sampleArgs();
83+
84+
expect(
85+
extendedDataLayerFunction.fn(
86+
data,
87+
{ ...args, seriesType: 'bar', showPoints: true },
88+
createMockExecutionContext()
89+
)
90+
).rejects.toThrowErrorMatchingSnapshot();
91+
});
92+
93+
test('throws the error if pointsRadius is provided to the not line/area chart', async () => {
94+
const { data } = sampleArgs();
95+
96+
expect(
97+
extendedDataLayerFunction.fn(
98+
data,
99+
{ ...args, seriesType: 'bar', pointsRadius: 10 },
100+
createMockExecutionContext()
101+
)
72102
).rejects.toThrowErrorMatchingSnapshot();
73103
});
74104
});

src/plugins/chart_expressions/expression_xy/common/expression_functions/extended_data_layer_fn.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import { validateAccessor } from '@kbn/visualizations-plugin/common/utils';
1010
import { ExtendedDataLayerArgs, ExtendedDataLayerFn } from '../types';
1111
import { EXTENDED_DATA_LAYER, LayerTypes } from '../constants';
1212
import { getAccessors, normalizeTable } from '../helpers';
13-
import { validateMarkSizeForChartType } from './validate';
13+
import {
14+
validateLineWidthForChartType,
15+
validateMarkSizeForChartType,
16+
validatePointsRadiusForChartType,
17+
validateShowPointsForChartType,
18+
} from './validate';
1419

1520
export const extendedDataLayerFn: ExtendedDataLayerFn['fn'] = async (data, args, context) => {
1621
const table = args.table ?? data;
@@ -21,6 +26,9 @@ export const extendedDataLayerFn: ExtendedDataLayerFn['fn'] = async (data, args,
2126
accessors.accessors.forEach((accessor) => validateAccessor(accessor, table.columns));
2227
validateMarkSizeForChartType(args.markSizeAccessor, args.seriesType);
2328
validateAccessor(args.markSizeAccessor, table.columns);
29+
validateLineWidthForChartType(args.lineWidth, args.seriesType);
30+
validateShowPointsForChartType(args.showPoints, args.seriesType);
31+
validatePointsRadiusForChartType(args.pointsRadius, args.seriesType);
2432

2533
const normalizedTable = normalizeTable(table, accessors.xAccessor);
2634

src/plugins/chart_expressions/expression_xy/common/expression_functions/reference_line.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('referenceLine', () => {
1414
test('produces the correct arguments for minimum arguments', async () => {
1515
const args: ReferenceLineArgs = {
1616
value: 100,
17+
fill: 'above',
1718
};
1819

1920
const result = referenceLineFunction.fn(null, args, createMockExecutionContext());
@@ -67,6 +68,7 @@ describe('referenceLine', () => {
6768
const args: ReferenceLineArgs = {
6869
name: 'some name',
6970
value: 100,
71+
fill: 'none',
7072
};
7173

7274
const result = referenceLineFunction.fn(null, args, createMockExecutionContext());
@@ -90,6 +92,7 @@ describe('referenceLine', () => {
9092
const args: ReferenceLineArgs = {
9193
value: 100,
9294
textVisibility: true,
95+
fill: 'none',
9396
};
9497

9598
const result = referenceLineFunction.fn(null, args, createMockExecutionContext());
@@ -115,6 +118,7 @@ describe('referenceLine', () => {
115118
value: 100,
116119
name: 'some text',
117120
textVisibility,
121+
fill: 'none',
118122
};
119123

120124
const result = referenceLineFunction.fn(null, args, createMockExecutionContext());

src/plugins/chart_expressions/expression_xy/common/expression_functions/reference_line_layer.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* Side Public License, v 1.
77
*/
88

9-
import { validateAccessor } from '@kbn/visualizations-plugin/common/utils';
10-
import { LayerTypes, REFERENCE_LINE_LAYER, EXTENDED_Y_CONFIG } from '../constants';
9+
import { REFERENCE_LINE_LAYER, EXTENDED_Y_CONFIG } from '../constants';
1110
import { ReferenceLineLayerFn } from '../types';
1211
import { strings } from '../i18n';
1312

@@ -41,16 +40,8 @@ export const referenceLineLayerFunction: ReferenceLineLayerFn = {
4140
help: strings.getLayerIdHelp(),
4241
},
4342
},
44-
fn(input, args) {
45-
const table = args.table ?? input;
46-
const accessors = args.accessors ?? [];
47-
accessors.forEach((accessor) => validateAccessor(accessor, table.columns));
48-
49-
return {
50-
type: REFERENCE_LINE_LAYER,
51-
...args,
52-
layerType: LayerTypes.REFERENCELINE,
53-
table: args.table ?? input,
54-
};
43+
async fn(input, args, context) {
44+
const { referenceLineLayerFn } = await import('./reference_line_layer_fn');
45+
return await referenceLineLayerFn(input, args, context);
5546
},
5647
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { validateAccessor } from '@kbn/visualizations-plugin/common/utils';
10+
import { LayerTypes, REFERENCE_LINE_LAYER } from '../constants';
11+
import { ReferenceLineLayerFn } from '../types';
12+
13+
export const referenceLineLayerFn: ReferenceLineLayerFn['fn'] = async (input, args, handlers) => {
14+
const table = args.table ?? input;
15+
const accessors = args.accessors ?? [];
16+
accessors.forEach((accessor) => validateAccessor(accessor, table.columns));
17+
18+
return {
19+
type: REFERENCE_LINE_LAYER,
20+
...args,
21+
layerType: LayerTypes.REFERENCELINE,
22+
table: args.table ?? input,
23+
};
24+
};

src/plugins/chart_expressions/expression_xy/common/expression_functions/validate.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ export const errors = {
3434
i18n.translate('expressionXY.reusable.function.xyVis.errors.markSizeLimitsError', {
3535
defaultMessage: 'Mark size ratio must be greater or equal to 1 and less or equal to 100',
3636
}),
37+
lineWidthForNonLineOrAreaChartError: () =>
38+
i18n.translate(
39+
'expressionXY.reusable.function.xyVis.errors.lineWidthForNonLineOrAreaChartError',
40+
{
41+
defaultMessage: '`lineWidth` can be applied only for line or area charts',
42+
}
43+
),
44+
showPointsForNonLineOrAreaChartError: () =>
45+
i18n.translate(
46+
'expressionXY.reusable.function.xyVis.errors.showPointsForNonLineOrAreaChartError',
47+
{
48+
defaultMessage: '`showPoints` can be applied only for line or area charts',
49+
}
50+
),
51+
pointsRadiusForNonLineOrAreaChartError: () =>
52+
i18n.translate(
53+
'expressionXY.reusable.function.xyVis.errors.pointsRadiusForNonLineOrAreaChartError',
54+
{
55+
defaultMessage: '`pointsRadius` can be applied only for line or area charts',
56+
}
57+
),
3758
markSizeRatioWithoutAccessor: () =>
3859
i18n.translate('expressionXY.reusable.function.xyVis.errors.markSizeRatioWithoutAccessor', {
3960
defaultMessage: 'Mark size ratio can be applied only with `markSizeAccessor`',
@@ -140,6 +161,9 @@ export const validateValueLabels = (
140161
}
141162
};
142163

164+
const isAreaOrLineChart = (seriesType: SeriesType) =>
165+
seriesType.includes('line') || seriesType.includes('area');
166+
143167
export const validateAddTimeMarker = (
144168
dataLayers: Array<DataLayerConfigResult | ExtendedDataLayerConfigResult>,
145169
addTimeMarker?: boolean
@@ -164,6 +188,33 @@ export const validateMarkSizeRatioLimits = (markSizeRatio?: number) => {
164188
}
165189
};
166190

191+
export const validateLineWidthForChartType = (
192+
lineWidth: number | undefined,
193+
seriesType: SeriesType
194+
) => {
195+
if (lineWidth !== undefined && !isAreaOrLineChart(seriesType)) {
196+
throw new Error(errors.lineWidthForNonLineOrAreaChartError());
197+
}
198+
};
199+
200+
export const validateShowPointsForChartType = (
201+
showPoints: boolean | undefined,
202+
seriesType: SeriesType
203+
) => {
204+
if (showPoints !== undefined && !isAreaOrLineChart(seriesType)) {
205+
throw new Error(errors.showPointsForNonLineOrAreaChartError());
206+
}
207+
};
208+
209+
export const validatePointsRadiusForChartType = (
210+
pointsRadius: number | undefined,
211+
seriesType: SeriesType
212+
) => {
213+
if (pointsRadius !== undefined && !isAreaOrLineChart(seriesType)) {
214+
throw new Error(errors.pointsRadiusForNonLineOrAreaChartError());
215+
}
216+
};
217+
167218
export const validateMarkSizeRatioWithAccessor = (
168219
markSizeRatio: number | undefined,
169220
markSizeAccessor: ExpressionValueVisDimension | string | undefined

src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('xyVis', () => {
6565
)
6666
).rejects.toThrowErrorMatchingSnapshot();
6767
});
68+
6869
test('it should throw error if minTimeBarInterval is invalid', async () => {
6970
const { data, args } = sampleArgs();
7071
const { layers, ...rest } = args;

src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis_fn.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import {
2929
validateMinTimeBarInterval,
3030
validateMarkSizeForChartType,
3131
validateMarkSizeRatioWithAccessor,
32+
validateShowPointsForChartType,
33+
validateLineWidthForChartType,
34+
validatePointsRadiusForChartType,
3235
} from './validate';
3336

3437
const createDataLayer = (args: XYArgs, table: Datatable): DataLayerConfigResult => {
@@ -43,6 +46,9 @@ const createDataLayer = (args: XYArgs, table: Datatable): DataLayerConfigResult
4346
isHistogram: args.isHistogram,
4447
palette: args.palette,
4548
yConfig: args.yConfig,
49+
showPoints: args.showPoints,
50+
pointsRadius: args.pointsRadius,
51+
lineWidth: args.lineWidth,
4652
layerType: LayerTypes.DATA,
4753
table: normalizedTable,
4854
...accessors,
@@ -68,6 +74,9 @@ export const xyVisFn: XyVisFn['fn'] = async (data, args, handlers) => {
6874
yConfig,
6975
palette,
7076
markSizeAccessor,
77+
showPoints,
78+
pointsRadius,
79+
lineWidth,
7180
...restArgs
7281
} = args;
7382

@@ -116,6 +125,9 @@ export const xyVisFn: XyVisFn['fn'] = async (data, args, handlers) => {
116125
validateValueLabels(args.valueLabels, hasBar, hasNotHistogramBars);
117126
validateMarkSizeRatioWithAccessor(args.markSizeRatio, dataLayers[0].markSizeAccessor);
118127
validateMarkSizeRatioLimits(args.markSizeRatio);
128+
validateLineWidthForChartType(lineWidth, args.seriesType);
129+
validateShowPointsForChartType(showPoints, args.seriesType);
130+
validatePointsRadiusForChartType(pointsRadius, args.seriesType);
119131

120132
return {
121133
type: 'render',

0 commit comments

Comments
 (0)