amaannawab923 commented on code in PR #33723:
URL: https://github.com/apache/superset/pull/33723#discussion_r2136191560
##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts:
##########
@@ -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())
+ ) {
Review Comment:
This check does require us to manually check if the first value is a data
type or not from the x Axis
But the datasource has list of all time columns under granularitysqla so we
can bring a boolean from transformProps.ts which is basically is isXaxisTemporal
`let timeColumnsSet;
let isXAxisTemporal = false;
if(Array.isArray(datasource.graunularitysqla) &&
datasource.graunularitysqla.length > 0) {
timeColumnsSet = new Set(datasource.graunularitysqla.flat());
}
if(timeColumnsSet && timeColumnsSet.has(formData?.xAxis)) {
isXAxisTemporal = true;
}`
The code will be as above & we can just use the boolean here as if
(xAxisDataType === undefined && isXAxisTemporal ) {
xAxisDataType = GenericDataType.Temporal;
}
Have tried it in the past , this approach works without fail since
datasource?.granularitySqla will always have relevant temporal columns
--
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]