Skip to content

Commit ad33cc6

Browse files
committed
Fixed parent pipeline aggregation, multi split series and respect Show values option
1 parent 8ce425e commit ad33cc6

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

src/plugins/vis_types/xy/public/convert_to_lens/configurations/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('getConfiguration', () => {
2323
{ columnId: '2', isBucketed: true, isSplit: false, operationType: 'date_histogram' },
2424
{ columnId: '3', isBucketed: true, isSplit: true },
2525
] as Column[],
26+
metrics: ['1'],
2627
columnOrder: [],
2728
seriesId: '1',
2829
collapseFn: 'max',
@@ -35,6 +36,7 @@ describe('getConfiguration', () => {
3536
{ columnId: '4', isBucketed: false },
3637
{ columnId: '5', isBucketed: true, isSplit: false, operationType: 'date_histogram' },
3738
] as Column[],
39+
metrics: ['4'],
3840
columnOrder: [],
3941
seriesId: '2',
4042
collapseFn: undefined,
@@ -45,6 +47,7 @@ describe('getConfiguration', () => {
4547
layerId: 'layer-3',
4648
columns: [{ columnId: '7', isBucketed: false }] as Column[],
4749
columnOrder: [],
50+
metrics: ['7'],
4851
seriesId: '',
4952
collapseFn: undefined,
5053
isReferenceLineLayer: true,
@@ -143,6 +146,7 @@ describe('getConfiguration', () => {
143146
},
144147
tickLabelsVisibilitySettings: { x: true, yLeft: true, yRight: true },
145148
valueLabels: 'hide',
149+
valuesInLegend: false,
146150
xTitle: undefined,
147151
yLeftExtent: { enforce: true, lowerBound: undefined, mode: 'full', upperBound: undefined },
148152
yLeftScale: 'linear',

src/plugins/vis_types/xy/public/convert_to_lens/configurations/index.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,6 @@ function getDataLayers(
113113
): XYDataLayerConfig[] {
114114
return layers.map((layer) => {
115115
const xColumn = layer.columns.find((c) => c.isBucketed && !c.isSplit);
116-
const yAccessors = layer.columns.reduce<string[]>((acc, column) => {
117-
if (!column.isBucketed) {
118-
acc.push(column.columnId);
119-
}
120-
return acc;
121-
}, []);
122116
const splitAccessor = layer.columns.find(
123117
(column) => column.isBucketed && column.isSplit
124118
)?.columnId;
@@ -134,15 +128,15 @@ function getDataLayers(
134128
const seriesType = getSeriesType(serie?.type, serie?.mode, isHorizontal, isPercentage);
135129
return {
136130
layerId: layer.layerId,
137-
accessors: yAccessors,
131+
accessors: layer.metrics,
138132
layerType: 'data',
139133
seriesType,
140134
xAccessor: xColumn?.columnId,
141135
simpleView: false,
142136
splitAccessor,
143137
palette: vis.params.palette ?? vis.type.visConfig.defaults.palette,
144-
yConfig: yAccessors.map((accessor) => ({
145-
forAccessor: accessor,
138+
yConfig: layer.metrics.map((metricId) => ({
139+
forAccessor: metricId,
146140
axisMode: getYAxisPosition(yAxis?.position ?? 'left'),
147141
})),
148142
xScaleType: getXScaleType(xColumn),
@@ -153,15 +147,7 @@ function getDataLayers(
153147
}
154148

155149
function getReferenceLineLayers(
156-
layers: Array<{
157-
indexPatternId: string;
158-
layerId: string;
159-
columns: Column[];
160-
columnOrder: never[];
161-
seriesId: string;
162-
isReferenceLineLayer: boolean;
163-
collapseFn?: string;
164-
}>,
150+
layers: Layer[],
165151
vis: Vis<VisParams>
166152
): XYReferenceLineLayerConfig[] {
167153
const thresholdLineConfig = vis.params.thresholdLine ?? vis.type.visConfig.defaults.thresholdLine;
@@ -171,10 +157,10 @@ function getReferenceLineLayers(
171157
return {
172158
layerType: 'referenceLine',
173159
layerId: layer.layerId,
174-
accessors: layer.columns.map((c) => c.columnId),
175-
yConfig: layer.columns.map((c) => {
160+
accessors: layer.metrics,
161+
yConfig: layer.metrics.map((metricId) => {
176162
return {
177-
forAccessor: c.columnId,
163+
forAccessor: metricId,
178164
axisMode: getYAxisPosition(yAxis?.position ?? 'left'),
179165
color: thresholdLineConfig.color,
180166
lineWidth: thresholdLineConfig.width !== null ? thresholdLineConfig.width : undefined,
@@ -261,6 +247,7 @@ export const getConfiguration = (
261247
xTitle: xAxis.title.text,
262248
valueLabels:
263249
vis.params.labels.show ?? vis.type.visConfig.defaults.labels?.show ? 'show' : 'hide',
250+
valuesInLegend: Boolean(vis.params.labels.show ?? vis.type.visConfig.defaults.labels?.show),
264251
curveType: getCurveType(
265252
series[0].interpolate === InterpolationMode.StepAfter
266253
? InterpolationMode.Linear

src/plugins/vis_types/xy/public/convert_to_lens/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ describe('convertToLens', () => {
4949
expect(result).toBeNull();
5050
});
5151

52+
test('should return null if multi split series defined', async () => {
53+
mockGetVisSchemas.mockReturnValue({
54+
metric: [{ aggId: '1' }],
55+
group: [{}, {}],
56+
});
57+
const result = await convertToLens(sampleAreaVis as any, { getAbsoluteTime: () => {} } as any);
58+
expect(mockGetVisSchemas).toBeCalledTimes(1);
59+
expect(result).toBeNull();
60+
});
61+
5262
test('should return null if sibling pipeline agg defined together with split series', async () => {
5363
mockGetColumnsFromVis.mockReturnValue([
5464
{

src/plugins/vis_types/xy/public/convert_to_lens/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface Layer {
2020
indexPatternId: string;
2121
layerId: string;
2222
columns: Column[];
23+
metrics: string[];
2324
columnOrder: never[];
2425
seriesId: string;
2526
isReferenceLineLayer: boolean;
@@ -58,6 +59,11 @@ export const convertToLens: ConvertXYToLensVisualization = async (vis, timefilte
5859
timeRange: timefilter.getAbsoluteTime(),
5960
});
6061

62+
// doesn't support multi split series
63+
if (visSchemas.group && visSchemas.group.length > 1) {
64+
return null;
65+
}
66+
6167
const firstValueAxesId = vis.params.valueAxes[0].id;
6268
const updatedSeries = getSeriesParams(
6369
vis.data.aggs,
@@ -146,6 +152,7 @@ export const convertToLens: ConvertXYToLensVisualization = async (vis, timefilte
146152
indexPatternId,
147153
layerId,
148154
columns: l.columns.map(excludeMetaFromColumn),
155+
metrics: l.metrics,
149156
columnOrder: [],
150157
seriesId: series?.data.id!,
151158
collapseFn,
@@ -154,11 +161,13 @@ export const convertToLens: ConvertXYToLensVisualization = async (vis, timefilte
154161
});
155162

156163
if (vis.params.thresholdLine.show) {
164+
const staticValueColumn = createStaticValueColumn(vis.params.thresholdLine.value || 0);
157165
layers.push({
158166
indexPatternId,
159167
layerId: uuid.default(),
160-
columns: [createStaticValueColumn(vis.params.thresholdLine.value || 0)],
168+
columns: [staticValueColumn],
161169
columnOrder: [],
170+
metrics: [staticValueColumn.columnId],
162171
isReferenceLineLayer: true,
163172
collapseFn: undefined,
164173
seriesId: '',

src/plugins/vis_types/xy/public/to_ast.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ export const toExpressionAst: VisToExpressionAst<VisParams> = async (vis, params
434434
splitColumnAccessor: dimensions.splitColumn?.map(prepareVisDimension),
435435
splitRowAccessor: dimensions.splitRow?.map(prepareVisDimension),
436436
valueLabels: vis.params.labels.show ? 'show' : 'hide',
437+
valuesInLegend: vis.params.labels.show,
437438
singleTable: true,
438439
});
439440

0 commit comments

Comments
 (0)