diff --git a/x-pack/plugins/lens/public/pie_visualization/render_helpers.test.ts b/x-pack/plugins/lens/public/pie_visualization/render_helpers.test.ts index d86500ff8a4fa..bcd9d79babbab 100644 --- a/x-pack/plugins/lens/public/pie_visualization/render_helpers.test.ts +++ b/x-pack/plugins/lens/public/pie_visualization/render_helpers.test.ts @@ -14,8 +14,10 @@ import { byDataColorPaletteMap, extractUniqTermsMap, checkTableForContainsSmallValues, + shouldShowValuesInLegend, } from './render_helpers'; import { chartPluginMock } from '../../../../../src/plugins/charts/public/mocks'; +import type { PieLayerState } from '../../common/expressions'; describe('render helpers', () => { describe('#getSliceValue', () => { @@ -374,4 +376,28 @@ describe('render helpers', () => { expect(checkTableForContainsSmallValues(datatable, columnId, 1)).toBeFalsy(); }); }); + + describe('#shouldShowValuesInLegend', () => { + it('should firstly read the state value', () => { + expect( + shouldShowValuesInLegend({ showValuesInLegend: true } as PieLayerState, 'waffle') + ).toBeTruthy(); + + expect( + shouldShowValuesInLegend({ showValuesInLegend: false } as PieLayerState, 'waffle') + ).toBeFalsy(); + }); + + it('should read value from meta in case of value in state is undefined', () => { + expect( + shouldShowValuesInLegend({ showValuesInLegend: undefined } as PieLayerState, 'waffle') + ).toBeTruthy(); + + expect(shouldShowValuesInLegend({} as PieLayerState, 'waffle')).toBeTruthy(); + + expect( + shouldShowValuesInLegend({ showValuesInLegend: undefined } as PieLayerState, 'pie') + ).toBeFalsy(); + }); + }); }); diff --git a/x-pack/plugins/lens/public/pie_visualization/render_helpers.ts b/x-pack/plugins/lens/public/pie_visualization/render_helpers.ts index 784cccd259d45..ef8525d2a9dbd 100644 --- a/x-pack/plugins/lens/public/pie_visualization/render_helpers.ts +++ b/x-pack/plugins/lens/public/pie_visualization/render_helpers.ts @@ -46,8 +46,8 @@ export const isTreemapOrMosaicShape = (shape: PieChartTypes | string) => ['treemap', 'mosaic'].includes(shape); export const shouldShowValuesInLegend = (layer: PieLayerState, shape: PieChartTypes) => - 'showValuesInLegend' in layer - ? layer.showValuesInLegend! + layer.showValuesInLegend !== undefined + ? layer.showValuesInLegend : Boolean(PartitionChartsMeta[shape]?.legend?.showValues); export const extractUniqTermsMap = (dataTable: Datatable, columnId: string) =>