You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ms...@apache.org on 2025/06/09 12:05:12 UTC

(superset) 01/01: fix(Timeseries): Temporal x axis defensive check for missing data

This is an automated email from the ASF dual-hosted git repository.

msyavuz pushed a commit to branch msyavuz/fix/temporal-x-axis
in repository https://gitbox.apache.org/repos/asf/superset.git

commit a8def11f9007c76be9c6f588ef7adc3c94fc89a5
Author: Mehmet Salih Yavuz <sa...@proton.me>
AuthorDate: Mon Jun 9 14:08:58 2025 +0300

    fix(Timeseries): Temporal x axis defensive check for missing data
---
 .../src/Timeseries/transformProps.ts                   | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
index ac39507964..efdff3e48a 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
@@ -210,6 +210,7 @@ export default function transformProps(
   const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
   const rebasedData = rebaseForecastDatum(data, verboseMap);
   let xAxisLabel = getXAxisLabel(chartProps.rawFormData) as string;
+
   if (
     isPhysicalColumn(chartProps.rawFormData?.x_axis) &&
     isDefined(verboseMap[xAxisLabel])
@@ -257,7 +258,22 @@ export default function transformProps(
     rawSeries.map(series => series.name as string),
   );
   const isAreaExpand = stack === StackControlsValue.Expand;
-  const xAxisDataType = dataTypes?.[xAxisLabel] ?? dataTypes?.[xAxisOrig];
+  let xAxisDataType = dataTypes?.[xAxisLabel] ?? dataTypes?.[xAxisOrig];
+
+  // Defensive check for xAxisDataType in case it is not provided by the backend.
+  if (xAxisDataType === undefined && data.length > 0) {
+    const firstValue = data[0][xAxisLabel];
+    if (
+      firstValue !== null &&
+      !Number.isNaN(new Date(firstValue as string | number).getTime())
+    ) {
+      console.warn(
+        `X-axis data type was missing from the backend response. ` +
+          `Successfully inferred a 'temporal' type from the data.`,
+      );
+      xAxisDataType = GenericDataType.Temporal;
+    }
+  }
 
   const xAxisType = getAxisType(stack, xAxisForceCategorical, xAxisDataType);
   const series: SeriesOption[] = [];