From c31754a6fc8f9084062d33637c8ee5043685856a Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Mon, 22 Nov 2021 14:14:38 +0300 Subject: [PATCH] fix Marco suggestion --- .../public/pie_visualization/constants.ts | 47 ++++++++++ .../public/pie_visualization/suggestions.ts | 5 +- .../lens/public/pie_visualization/toolbar.tsx | 85 +++++-------------- 3 files changed, 70 insertions(+), 67 deletions(-) diff --git a/x-pack/plugins/lens/public/pie_visualization/constants.ts b/x-pack/plugins/lens/public/pie_visualization/constants.ts index f4278f50c5a79..be0afc65aed3b 100644 --- a/x-pack/plugins/lens/public/pie_visualization/constants.ts +++ b/x-pack/plugins/lens/public/pie_visualization/constants.ts @@ -12,10 +12,53 @@ import { LensIconChartPie } from '../assets/chart_pie'; import { LensIconChartTreemap } from '../assets/chart_treemap'; import { LensIconChartMosaic } from '../assets/chart_mosaic'; +import type { SharedPieLayerState } from '../../common/expressions'; + +interface CategoryOption { + value: SharedPieLayerState['categoryDisplay']; + inputDisplay: string; +} + const groupLabel = i18n.translate('xpack.lens.pie.groupLabel', { defaultMessage: 'Proportion', }); +const categoryOptions: CategoryOption[] = [ + { + value: 'default', + inputDisplay: i18n.translate('xpack.lens.pieChart.showCategoriesLabel', { + defaultMessage: 'Inside or outside', + }), + }, + { + value: 'inside', + inputDisplay: i18n.translate('xpack.lens.pieChart.fitInsideOnlyLabel', { + defaultMessage: 'Inside only', + }), + }, + { + value: 'hide', + inputDisplay: i18n.translate('xpack.lens.pieChart.categoriesInLegendLabel', { + defaultMessage: 'Hide labels', + }), + }, +]; + +const categoryOptionsTreemap: CategoryOption[] = [ + { + value: 'default', + inputDisplay: i18n.translate('xpack.lens.pieChart.showTreemapCategoriesLabel', { + defaultMessage: 'Show labels', + }), + }, + { + value: 'hide', + inputDisplay: i18n.translate('xpack.lens.pieChart.categoriesInLegendLabel', { + defaultMessage: 'Hide labels', + }), + }, +]; + export const CHART_NAMES = { donut: { icon: LensIconChartDonut, @@ -24,6 +67,7 @@ export const CHART_NAMES = { }), partitionType: PartitionLayout.sunburst, groupLabel, + categoryOptions, }, pie: { icon: LensIconChartPie, @@ -32,6 +76,7 @@ export const CHART_NAMES = { }), partitionType: PartitionLayout.sunburst, groupLabel, + categoryOptions, }, treemap: { icon: LensIconChartTreemap, @@ -40,6 +85,7 @@ export const CHART_NAMES = { }), partitionType: PartitionLayout.treemap, groupLabel, + categoryOptions: categoryOptionsTreemap, }, mosaic: { icon: LensIconChartMosaic, @@ -48,6 +94,7 @@ export const CHART_NAMES = { }), partitionType: PartitionLayout.mosaic, groupLabel, + categoryOptions: [] as CategoryOption[], }, }; diff --git a/x-pack/plugins/lens/public/pie_visualization/suggestions.ts b/x-pack/plugins/lens/public/pie_visualization/suggestions.ts index 90700aee5de1d..30cd63752f420 100644 --- a/x-pack/plugins/lens/public/pie_visualization/suggestions.ts +++ b/x-pack/plugins/lens/public/pie_visualization/suggestions.ts @@ -192,10 +192,7 @@ export function suggestions({ layerId: table.layerId, groups: groups.map((col) => col.columnId), metric: metricColumnId, - categoryDisplay: - state.layers[0].categoryDisplay === 'inside' - ? 'default' - : state.layers[0].categoryDisplay, + categoryDisplay: 'default', layerType: layerTypes.DATA, } : { diff --git a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx index 72fefd0d6dc72..23003a4ec3404 100644 --- a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx +++ b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx @@ -17,12 +17,11 @@ import { } from '@elastic/eui'; import type { Position } from '@elastic/charts'; import type { PaletteRegistry } from 'src/plugins/charts/public'; -import { DEFAULT_PERCENT_DECIMALS } from './constants'; +import { DEFAULT_PERCENT_DECIMALS, CHART_NAMES } from './constants'; import type { PieVisualizationState, SharedPieLayerState } from '../../common/expressions'; import { VisualizationDimensionEditorProps, VisualizationToolbarProps } from '../types'; import { ToolbarPopover, LegendSettingsPopover, useDebouncedValue } from '../shared_components'; import { PalettePicker } from '../shared_components'; -import { isTreemapOrMosaicShape } from './render_helpers'; const numberOptions: Array<{ value: SharedPieLayerState['numberDisplay']; @@ -48,48 +47,6 @@ const numberOptions: Array<{ }, ]; -const categoryOptions: Array<{ - value: SharedPieLayerState['categoryDisplay']; - inputDisplay: string; -}> = [ - { - value: 'default', - inputDisplay: i18n.translate('xpack.lens.pieChart.showCategoriesLabel', { - defaultMessage: 'Inside or outside', - }), - }, - { - value: 'inside', - inputDisplay: i18n.translate('xpack.lens.pieChart.fitInsideOnlyLabel', { - defaultMessage: 'Inside only', - }), - }, - { - value: 'hide', - inputDisplay: i18n.translate('xpack.lens.pieChart.categoriesInLegendLabel', { - defaultMessage: 'Hide labels', - }), - }, -]; - -const categoryOptionsTreemap: Array<{ - value: SharedPieLayerState['categoryDisplay']; - inputDisplay: string; -}> = [ - { - value: 'default', - inputDisplay: i18n.translate('xpack.lens.pieChart.showTreemapCategoriesLabel', { - defaultMessage: 'Show labels', - }), - }, - { - value: 'hide', - inputDisplay: i18n.translate('xpack.lens.pieChart.categoriesInLegendLabel', { - defaultMessage: 'Hide labels', - }), - }, -]; - const legendOptions: Array<{ value: SharedPieLayerState['legendDisplay']; label: string; @@ -134,25 +91,27 @@ export function PieToolbar(props: VisualizationToolbarProps - - { - setState({ - ...state, - layers: [{ ...layer, categoryDisplay: option }], - }); - }} - /> - + {state.shape && CHART_NAMES[state.shape].categoryOptions.length ? ( + + { + setState({ + ...state, + layers: [{ ...layer, categoryDisplay: option }], + }); + }} + /> + + ) : null}