From 3df059e60ccff6dde5a5d19ca3d444f0e2c7cba7 Mon Sep 17 00:00:00 2001 From: Stephen Liu <750188453@qq.com> Date: Tue, 31 May 2022 23:37:24 +0800 Subject: [PATCH] fix(legacy-plugin-chart-sunburst): linear color scheme not work when secondary metric is provided (#20221) --- .../legacy-plugin-chart-sunburst/src/Sunburst.js | 2 +- .../src/controlPanel.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/Sunburst.js b/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/Sunburst.js index 4418f68bbd150..f967c985fcfd4 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/Sunburst.js +++ b/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/Sunburst.js @@ -489,7 +489,7 @@ function Sunburst(element, props) { // For efficiency, filter nodes to keep only those large enough to see. const nodes = partition.nodes(root).filter(d => d.dx > 0.005); // 0.005 radians = 0.29 degrees - if (metrics[0] !== metrics[1] && metrics[1] && !colorScheme) { + if (metrics[0] !== metrics[1] && metrics[1]) { colorByCategory = false; const ext = d3.extent(nodes, d => d.m2 / d.m1); linearColorScale = getSequentialSchemeRegistry() diff --git a/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/controlPanel.ts b/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/controlPanel.ts index 065964687bfcf..df50be9c4d16c 100644 --- a/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/controlPanel.ts +++ b/superset-frontend/plugins/legacy-plugin-chart-sunburst/src/controlPanel.ts @@ -17,7 +17,11 @@ * under the License. */ import { t } from '@superset-ui/core'; -import { ControlPanelConfig, sections } from '@superset-ui/chart-controls'; +import { + ControlPanelConfig, + ControlPanelsContainerProps, + sections, +} from '@superset-ui/chart-controls'; const config: ControlPanelConfig = { controlPanelSections: [ @@ -71,11 +75,21 @@ const config: ControlPanelConfig = { description: t( 'When only a primary metric is provided, a categorical color scale is used.', ), + visibility: ({ controls }: ControlPanelsContainerProps) => + Boolean( + !controls?.secondary_metric?.value || + controls?.secondary_metric?.value === controls?.metric.value, + ), }, linear_color_scheme: { description: t( 'When a secondary metric is provided, a linear color scale is used.', ), + visibility: ({ controls }: ControlPanelsContainerProps) => + Boolean( + controls?.secondary_metric?.value && + controls?.secondary_metric?.value !== controls?.metric.value, + ), }, groupby: { label: t('Hierarchy'),