rusackas commented on code in PR #41962:
URL: https://github.com/apache/superset/pull/41962#discussion_r3565576122


##########
superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts:
##########
@@ -254,14 +254,27 @@ export default function transformProps(
     {},
   );
 
-  const normalizeArray = (arr: number[], decimals = 10, seriesName: string) =>
+  const normalizeArray = (
+    arr: (number | null)[],
+    decimals = 10,
+    seriesName: string,
+  ): (number | null)[] =>
     arr.map((value, index) => {
       const metricLabel = metricLabels[index];
       if (metricsWithCustomBounds.has(metricLabel)) {
         return value;
       }
 
-      const max = Math.max(...arr);
+      // Preserve missing (null/undefined) metric values so they render as a
+      // gap. Dividing null/undefined by max coerces it to 0, which would plot
+      // the point at the center of the radar as if it were a real zero.
+      if (value == null || !Number.isFinite(value)) {
+        return null;

Review Comment:
   Good catch, fixed. A missing metric now gets an explicit `null` entry in the 
denormalization map instead of being left unrecorded, so the label/tooltip 
lookups can tell "recorded as a gap" apart from "never recorded" and skip 
formatting it into `NaN`.



##########
superset-frontend/plugins/plugin-chart-echarts/test/Radar/transformProps.test.ts:
##########
@@ -204,6 +204,57 @@ describe('legend sorting', () => {
   });
 });
 
+describe('missing (null) values', () => {
+  // Regression for #30270: "Wrong visualization of missing values in radar
+  // charts". A null metric value must NOT be transformed into 0. In
+  // `normalizeArray`, `null / max` coerces the null to 0, so a missing data
+  // point ends up plotted at the center of the radar as if it were a real
+  // zero, instead of being left out (a gap). This test feeds a datum with a
+  // null metric and asserts the null is preserved in the normalized series
+  // value rather than silently becoming 0.
+  const missingValueData = [
+    {
+      data: [
+        {
+          name: 'Series A',
+          'SUM(jp_sales)': 10,
+          'SUM(other_sales)': null,
+          'SUM(eu_sales)': 30,
+        },
+      ],
+    },
+  ];
+
+  const missingValueProps = new ChartProps({
+    formData: {
+      ...formData,
+      // No columnConfig custom bounds so every metric is normalized.
+      columnConfig: {},
+      groupby: ['name'],
+      metrics: ['SUM(jp_sales)', 'SUM(other_sales)', 'SUM(eu_sales)'],
+    },
+    width: 800,
+    height: 600,
+    queriesData: missingValueData,
+    theme: supersetTheme,
+  });
+
+  test('preserves a null metric instead of plotting it as 0', () => {
+    const result = transformProps(missingValueProps as EchartsRadarChartProps);
+    const series = result.echartOptions.series as RadarSeriesOption[];
+    const value = (series[0].data as RadarSeriesData[])[0].value as (
+      | number
+      | null
+    )[];
+
+    // Index 1 corresponds to 'SUM(other_sales)', which was null in the datum.
+    // The correct behavior is to keep the gap (null/undefined) so ECharts does
+    // not draw a point at the center. On master this is 0, so this fails.
+    expect(value[1]).not.toBe(0);
+    expect(value[1] == null).toBe(true);
+  });
+});

Review Comment:
   Fixed, that block's now a standalone `test()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to