Skip to content

Commit d0c0abb

Browse files
authored
[Lens as code] Remove donut partition types (elastic#260177)
## Summary Removes the explicit `donut` partition type. It was exactly the same as `pie` even with the `donut_hole` property. This way the user can define the `pie` and set the inner diameter to make it a `donut` without changing the `type`. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels.
1 parent 625f2bb commit d0c0abb

5 files changed

Lines changed: 33 additions & 37 deletions

File tree

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import type { PieStateESQL, PieStateNoESQL } from './pie';
1111
import { pieStateSchema } from './pie';
1212

13-
describe('Pie/Donut Schema', () => {
14-
describe.each(['pie', 'donut'] as const)('%s chart type', (chartType) => {
13+
describe('Pie Schema', () => {
14+
describe('pie chart type', () => {
1515
describe('Non-ES|QL Schema', () => {
1616
const basePieConfig = {
17-
type: chartType,
17+
type: 'pie',
1818
dataset: {
1919
type: 'dataView',
2020
id: 'test-data-view',
@@ -35,7 +35,7 @@ describe('Pie/Donut Schema', () => {
3535
};
3636

3737
const validated = pieStateSchema.validate(input);
38-
expect(validated.type).toBe(chartType);
38+
expect(validated.type).toBe('pie');
3939
expect(validated.metrics).toHaveLength(1);
4040
expect(validated.metrics[0].operation).toBe('count');
4141
});
@@ -700,7 +700,7 @@ describe('Pie/Donut Schema', () => {
700700

701701
describe('ES|QL Schema', () => {
702702
const baseESQLPieConfig = {
703-
type: chartType,
703+
type: 'pie',
704704
dataset: {
705705
type: 'esql',
706706
query: 'FROM my-index | STATS count() BY category',

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/schema/charts/pie.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
import { groupIsNotCollapsed } from '../../utils';
3535

3636
/**
37-
* Shared visualization options for pie/donut charts including legend, value display, and label positioning
37+
* Shared visualization options for pie charts including legend, value display, and label positioning
3838
*/
3939
const pieStateSharedSchema = {
4040
legend: schema.maybe(
@@ -49,7 +49,7 @@ const pieStateSharedSchema = {
4949
meta: {
5050
id: 'pieLegend',
5151
title: 'Legend',
52-
description: 'Legend configuration for pie/donut chart',
52+
description: 'Legend configuration for pie chart',
5353
},
5454
}
5555
)
@@ -62,15 +62,14 @@ const pieStateSharedSchema = {
6262
position: schema.maybe(
6363
schema.oneOf([schema.literal('inside'), schema.literal('outside')], {
6464
meta: {
65-
description: 'Renders the pie/donut chart slice labels inside or outside the pie',
65+
description: 'Renders pie chart slice labels inside or outside the pie',
6666
},
6767
})
6868
),
6969
},
7070
{
7171
meta: {
72-
description:
73-
'Label configuration for pie/donut chart slice labels inside or outside the pie',
72+
description: 'Label configuration for pie chart slice labels inside or outside the pie',
7473
},
7574
}
7675
)
@@ -84,7 +83,7 @@ const pieStateSharedSchema = {
8483
};
8584

8685
/**
87-
* Color configuration for primary metric in pie/donut chart
86+
* Color configuration for primary metric in pie chart
8887
*/
8988
const partitionStatePrimaryMetricOptionsSchema = {
9089
color: schema.maybe(staticColorSchema),
@@ -98,12 +97,7 @@ const partitionStateBreakdownByOptionsSchema = {
9897
collapse_by: schema.maybe(collapseBySchema),
9998
};
10099

101-
/**
102-
* Pie/donut chart type
103-
*/
104-
const pieTypeSchema = schema.oneOf([schema.literal('pie'), schema.literal('donut')], {
105-
meta: { description: 'Chart type: pie or donut' },
106-
});
100+
const pieTypeSchema = schema.literal('pie');
107101

108102
function validateForMultipleMetrics({
109103
metrics,
@@ -126,7 +120,7 @@ function validateForMultipleMetrics({
126120
}
127121

128122
/**
129-
* Pie/donut chart configuration for standard (non-ES|QL) queries
123+
* Pie chart configuration for standard (non-ES|QL) queries
130124
*/
131125
export const pieStateSchemaNoESQL = schema.object(
132126
{
@@ -161,15 +155,15 @@ export const pieStateSchemaNoESQL = schema.object(
161155
{
162156
meta: {
163157
id: 'pieNoESQL',
164-
title: 'Pie/Donut Chart (DSL)',
165-
description: 'Pie/donut chart configuration for standard queries',
158+
title: 'Pie Chart (DSL)',
159+
description: 'Pie chart configuration for standard queries',
166160
},
167161
validate: validateForMultipleMetrics,
168162
}
169163
);
170164

171165
/**
172-
* Pie/donut chart configuration for ES|QL queries
166+
* Pie chart configuration for ES|QL queries
173167
*/
174168
export const pieStateSchemaESQL = schema.object(
175169
{
@@ -199,21 +193,21 @@ export const pieStateSchemaESQL = schema.object(
199193
{
200194
meta: {
201195
id: 'pieESQL',
202-
title: 'Pie/Donut Chart (ES|QL)',
203-
description: 'Pie/donut chart configuration for ES|QL queries',
196+
title: 'Pie Chart (ES|QL)',
197+
description: 'Pie chart configuration for ES|QL queries',
204198
},
205199
validate: validateForMultipleMetrics,
206200
}
207201
);
208202

209203
/**
210-
* Complete pie/donut chart configuration supporting both standard and ES|QL queries
204+
* Complete pie chart configuration supporting both standard and ES|QL queries
211205
*/
212206
export const pieStateSchema = schema.oneOf([pieStateSchemaNoESQL, pieStateSchemaESQL], {
213207
meta: {
214208
id: 'pieChart',
215-
title: 'Pie/Donut Chart',
216-
description: 'Pie/donut chart state: standard query or ES|QL query',
209+
title: 'Pie Chart',
210+
description: 'Pie chart state: standard query or ES|QL query',
217211
},
218212
});
219213

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/lens_api_config.mock.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const esqlCharts: Array<PartitionConfig> = [
7171
title: 'basic donut',
7272
sampling: 1,
7373
ignore_global_filters: false,
74-
type: 'donut',
74+
type: 'pie',
7575
metrics: [
7676
{
7777
operation: 'count',
@@ -330,7 +330,7 @@ export const esqlCharts: Array<PartitionConfig> = [
330330
title: 'donut with multiple groups',
331331
sampling: 1,
332332
ignore_global_filters: false,
333-
type: 'donut',
333+
type: 'pie',
334334
metrics: [
335335
{
336336
operation: 'count',
@@ -594,7 +594,7 @@ export const esqlCharts: Array<PartitionConfig> = [
594594
title: 'donut with multiple metrics',
595595
sampling: 1,
596596
ignore_global_filters: false,
597-
type: 'donut',
597+
type: 'pie',
598598
metrics: [
599599
{
600600
operation: 'count',
@@ -1049,7 +1049,7 @@ export const esqlCharts: Array<PartitionConfig> = [
10491049
title: 'donut with color mapping',
10501050
sampling: 1,
10511051
ignore_global_filters: false,
1052-
type: 'donut',
1052+
type: 'pie',
10531053
metrics: [
10541054
{
10551055
operation: 'count',

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/tests/partition/partition.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ import type { LensPartitionVisualizationState } from '@kbn/lens-common';
3636
describe('Partition', () => {
3737
describe('validateConverter', () => {
3838
const datasets = [
39-
{ name: 'pie/donut basic', config: pieLegacyBasicState, schema: pieStateSchema },
39+
{ name: 'pie basic', config: pieLegacyBasicState, schema: pieStateSchema },
4040
{ name: 'treemap basic', config: treemapLegacyBasicState, schema: treemapStateSchema },
4141
{ name: 'mosaic basic', config: mosaicLegacyBasicState, schema: mosaicStateSchema },
4242
{ name: 'waffle basic', config: waffleLegacyBasicState, schema: waffleStateSchema },
4343
{
44-
name: 'pie/donut advanced with collapsed groups',
44+
name: 'pie advanced with collapsed groups',
4545
config: pieLegacyAdvancedStateWithMultipleMetricsAndCollapsedGroups,
4646
schema: pieStateSchema,
4747
},

src/platform/packages/shared/kbn-lens-embeddable-utils/config_builder/transforms/charts/partition.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function isAPIPartitionLayer(layer: unknown): layer is PartitionState {
8484
layer !== null &&
8585
'type' in layer &&
8686
typeof layer.type === 'string' &&
87-
['pie', 'donut', 'waffle', 'treemap', 'mosaic'].includes(layer.type)
87+
['pie', 'waffle', 'treemap', 'mosaic'].includes(layer.type)
8888
);
8989
}
9090

@@ -93,7 +93,7 @@ function isESQLPartitionLayer(layer: PartitionState): layer is PartitionStateESQ
9393
}
9494

9595
function isAPIPieChartLayer(layer: PartitionState): layer is PieState {
96-
return layer.type === 'pie' || layer.type === 'donut';
96+
return layer.type === 'pie';
9797
}
9898

9999
function isAPIWaffleChartLayer(layer: PartitionState): layer is WaffleState {
@@ -327,8 +327,10 @@ function buildVisualizationState(
327327
const isLegacyColor = isLegacyColorPalette(colorMapping);
328328

329329
if (isAPIPieChartLayer(config)) {
330+
const pieLensShape =
331+
config.donut_hole != null && config.donut_hole !== 'none' ? 'donut' : 'pie';
330332
return {
331-
shape: config.type,
333+
shape: pieLensShape,
332334
...(isLegacyColor && { ...colorMapping }), // legacy colors are included outside of the layer
333335
layers: [
334336
{
@@ -676,7 +678,7 @@ function convertStateCategoryDisplayOption(
676678

677679
function fromLensStateToPerChartSpecificAPI(visualization: LensPartitionVisualizationState) {
678680
const vizLayer = visualization.layers[0];
679-
// Pie and Donut chart have the label_position and donut_hole options
681+
// Pie chart has the label_position and donut_hole options
680682
if (isStatePieChart(visualization)) {
681683
return stripUndefined({
682684
donut_hole: donutHoleSizeCompat.toAPI(vizLayer.emptySizeRatio),
@@ -704,7 +706,7 @@ function buildVisualizationAPI(
704706
? { metric: metricsArray[0] }
705707
: { metrics: metricsArray };
706708
return stripUndefined({
707-
type: visualization.shape,
709+
type: isStatePieChart(visualization) ? 'pie' : visualization.shape,
708710
...metricsField,
709711
group_by: fromLensStateToAPIGroups(visualization, layer),
710712
...fromLensStateToAPISecondaryGroups(visualization, layer),

0 commit comments

Comments
 (0)