Repository: apache/superset
File: superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts (TypeScript)

Code before:
      },
    } as RadarSeriesDataItemOption);
  });

  const selectedValues = (filterState.selectedValues || []).reduce(
    (acc: Record<string, number>, selectedValue: string) => {
      const index = transformedData.findIndex(
        ({ name }) => name === selectedValue,
      );
      return {
        ...acc,
        [index]: selectedValue,
      };
    },
    {},
  );

  // Add normalization function
  const normalizeArray = (arr: number[], decimals = 10, seriesName: string) => {
    const max = Math.max(...arr);
    return arr.map(value => {
      const normalisedValue = Number((value / max).toFixed(decimals));
      denormalizedSeriesValues[seriesName][String(normalisedValue)] = value;
      return normalisedValue;
    });
  };

  if (isNormalised) {
    // Normalize the transformed data
    transformedData = transformedData.map(series => {
      if (Array.isArray(series.value)) {
        const seriesName = String(series?.name || '');
        denormalizedSeriesValues[seriesName] = {};

        return {
          ...series,
          value: normalizeArray(series.value as number[], 10, seriesName),
        };
      }
      return series;
    });
  }

  const indicator = metricLabels.map(metricLabel => {
    if (isNormalised) {
      return {
        name: metricLabel,
        max: 1,
        min: 0,
      };
    }

Review comment (suggestion):
The normalise function gets max value from each series & consider it as 1.0 and then calculates the normalised value & then goes onto put a reference of normalised -> denormalised value in our denormalised values map 

Code after:
        position: labelPosition,
        formatter,
      },
    } as RadarSeriesDataItemOption);
  });

  const selectedValues = (filterState.selectedValues || []).reduce(
    (acc: Record<string, number>, selectedValue: string) => {
      const index = transformedData.findIndex(
        ({ name }) => name === selectedValue,
      );
      return {
        ...acc,
        [index]: selectedValue,
      };
    },
    {},
  );

  const normalizeArray = (arr: number[], decimals = 10, seriesName: string) =>
    arr.map((value, index) => {
      const metricLabel = metricLabels[index];
      if (metricsWithCustomBounds.has(metricLabel)) {
        return value;
      }

      const max = Math.max(...arr);
      const normalizedValue = Number((value / max).toFixed(decimals));

      denormalizedSeriesValues[seriesName][String(normalizedValue)] = value;
      return normalizedValue;
    });

  // Normalize the transformed data
  const normalizedTransformedData = transformedData.map(series => {
    if (Array.isArray(series.value)) {
      const seriesName = String(series?.name || '');
      denormalizedSeriesValues[seriesName] = {};

      return {
        ...series,
        value: normalizeArray(series.value as number[], 10, seriesName),
      };
    }
    return series;
  });

  const indicator = metricLabels.map(metricLabel => {
    const isMetricWithCustomBounds = metricsWithCustomBounds.has(metricLabel);
    if (!isMetricWithCustomBounds) {
      return {