Skip to content

Commit

Permalink
[Lens] Prefer pie over donut. Keep donut if donut already (elastic#19…
Browse files Browse the repository at this point in the history
…9735)

## Summary

This PR makes it so `pie` is used over `donut` as default suggestion. If
something is a `donut` already, adding another ring won't switch to
`pie`.

Closes: elastic#101289
  • Loading branch information
kowalczyk-krzysztof authored Nov 18, 2024
1 parent 45f7a8c commit e5b40bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ describe('suggestions', () => {
).toContainEqual(
expect.objectContaining({
state: {
shape: PieChartTypes.DONUT,
shape: PieChartTypes.PIE,
palette,
layers: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,18 @@ function shouldReject({ table, keptLayerIds, state }: SuggestionRequest<PieVisua
}

function getNewShape(
groups: TableSuggestionColumn[],
subVisualizationId?: PieVisualizationState['shape']
subVisualizationId?: PieVisualizationState['shape'],
currentShape?: PieVisualizationState['shape']
) {
if (subVisualizationId) {
return subVisualizationId;
}

let newShape: PieVisualizationState['shape'] | undefined;

if (groups.length !== 1 && !subVisualizationId) {
newShape = PieChartTypes.PIE;
if (currentShape) {
return currentShape;
}

return newShape ?? PieChartTypes.DONUT;
return PieChartTypes.PIE;
}

function hasCustomSuggestionsExists(shape: PieChartType | string | undefined) {
Expand Down Expand Up @@ -122,7 +120,10 @@ export function suggestions({
groups.length <= PartitionChartsMeta.pie.maxBuckets &&
!hasCustomSuggestionsExists(subVisualizationId)
) {
const newShape = getNewShape(groups, subVisualizationId as PieVisualizationState['shape']);
const newShape = getNewShape(
subVisualizationId as PieVisualizationState['shape'],
state?.shape
);
const baseSuggestion: VisualizationSuggestion<PieVisualizationState> = {
title: i18n.translate('xpack.lens.pie.suggestionLabel', {
defaultMessage: '{chartName}',
Expand Down

0 comments on commit e5b40bb

Please sign in to comment.