Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions x-pack/plugins/lens/public/xy_visualization/xy_suggestions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,22 @@ describe('xy_suggestions', () => {
expect(suggestion.hide).toBeTruthy();
});

test('respects requested sub visualization type if set', () => {
const [suggestion, ...rest] = getSuggestions({
table: {
isMultiRow: true,
columns: [numCol('price'), numCol('quantity'), dateCol('date'), strCol('product')],
layerId: 'first',
changeType: 'reduced',
},
keptLayerIds: [],
subVisualizationId: 'area',
});

expect(rest).toHaveLength(0);
expect(suggestion.state.preferredSeriesType).toBe('area');
});

test('keeps existing seriesType for initial tables', () => {
const currentState: XYState = {
legend: { isVisible: true, position: 'bottom' },
Expand Down
18 changes: 15 additions & 3 deletions x-pack/plugins/lens/public/xy_visualization/xy_suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function getSuggestions({
table,
state,
keptLayerIds,
subVisualizationId,
}: SuggestionRequest<State>): Array<VisualizationSuggestion<State>> {
if (
// We only render line charts for multi-row queries. We require at least
Expand Down Expand Up @@ -66,7 +67,12 @@ export function getSuggestions({
return [];
}

const suggestions = getSuggestionForColumns(table, keptLayerIds, state);
const suggestions = getSuggestionForColumns(
table,
keptLayerIds,
state,
subVisualizationId as SeriesType | undefined
);

if (suggestions && suggestions instanceof Array) {
return suggestions;
Expand All @@ -78,7 +84,8 @@ export function getSuggestions({
function getSuggestionForColumns(
table: TableSuggestion,
keptLayerIds: string[],
currentState?: State
currentState?: State,
seriesType?: SeriesType
): VisualizationSuggestion<State> | Array<VisualizationSuggestion<State>> | undefined {
const [buckets, values] = partition(table.columns, (col) => col.operation.isBucketed);

Expand All @@ -93,6 +100,7 @@ function getSuggestionForColumns(
currentState,
tableLabel: table.label,
keptLayerIds,
requestedSeriesType: seriesType,
});
} else if (buckets.length === 0) {
const [x, ...yValues] = prioritizeColumns(values);
Expand All @@ -105,6 +113,7 @@ function getSuggestionForColumns(
currentState,
tableLabel: table.label,
keptLayerIds,
requestedSeriesType: seriesType,
});
}
}
Expand Down Expand Up @@ -190,6 +199,7 @@ function getSuggestionsForLayer({
currentState,
tableLabel,
keptLayerIds,
requestedSeriesType,
}: {
layerId: string;
changeType: TableChangeType;
Expand All @@ -199,9 +209,11 @@ function getSuggestionsForLayer({
currentState?: State;
tableLabel?: string;
keptLayerIds: string[];
requestedSeriesType?: SeriesType;
}): VisualizationSuggestion<State> | Array<VisualizationSuggestion<State>> {
const title = getSuggestionTitle(yValues, xValue, tableLabel);
const seriesType: SeriesType = getSeriesType(currentState, layerId, xValue);
const seriesType: SeriesType =
requestedSeriesType || getSeriesType(currentState, layerId, xValue);

const options = {
currentState,
Expand Down