codeant-ai-for-open-source[bot] commented on code in PR #42245:
URL: https://github.com/apache/superset/pull/42245#discussion_r3616708945


##########
superset-frontend/plugins/plugin-chart-echarts/src/TimePivot/transformProps.ts:
##########
@@ -0,0 +1,163 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  getMetricLabel,
+  getNumberFormatter,
+  getTimeFormatter,
+  JsonObject,
+  SMART_DATE_VERBOSE_ID,
+} from '@superset-ui/core';
+import type { EChartsCoreOption } from 'echarts/core';
+import { Refs } from '../types';
+import transformData, { TimePivotSeries } from './transformData';
+import {
+  EchartsTimePivotChartProps,
+  TimePivotChartTransformedProps,
+} from './types';
+
+const DEFAULT_COLOR = { r: 0, g: 122, b: 135, a: 1 };
+
+export default function transformProps(
+  chartProps: EchartsTimePivotChartProps,
+): TimePivotChartTransformedProps {
+  const { width, height, formData, queriesData, theme, hooks } = chartProps;
+  const {
+    metric,
+    freq,
+    colorPicker,
+    showLegend,
+    lineInterpolation,
+    xAxisLabel,
+    yAxisLabel,
+    yAxisFormat,
+    yLogScale,
+    yAxisBounds,
+  } = formData;
+  const refs: Refs = {};
+  const { onContextMenu, setDataMask = () => {} } = hooks;
+
+  const metricLabel = getMetricLabel(metric ?? '');
+  const records = (queriesData[0]?.data ?? []) as Record<string, unknown>[];
+  const series: TimePivotSeries[] = Array.isArray(records)
+    ? transformData(records, metricLabel, (freq as string) || 'W-MON')
+    : [];
+
+  const { r, g, b } = colorPicker ?? DEFAULT_COLOR;
+  // Match the nvd3 styling: the current period is fully opaque, prior
+  // periods fade with their recency percentile.
+  const colorOf = (s: TimePivotSeries) =>
+    `rgba(${r}, ${g}, ${b}, ${s.rank > 0 ? s.perc * 0.5 : 1})`;
+
+  const smooth = lineInterpolation === 'cardinal';
+  const step =
+    lineInterpolation === 'step-before'
+      ? 'start'
+      : lineInterpolation === 'step-after'
+        ? 'end'
+        : undefined;
+
+  const valueFormatter = getNumberFormatter(yAxisFormat);
+  const timeFormatter = getTimeFormatter(SMART_DATE_VERBOSE_ID);
+
+  // Draw the current period last so it paints on top of the faded priors.
+  const sortedSeries = [...series].sort((a, b) => b.rank - a.rank);
+
+  const [yMin, yMax] = yAxisBounds ?? [null, null];
+
+  const echartOptions: EChartsCoreOption = {
+    grid: {
+      top: theme.sizeUnit * 8,
+      bottom: theme.sizeUnit * 8,
+      left: theme.sizeUnit * 4,
+      right: theme.sizeUnit * 6,
+      containLabel: true,
+    },
+    legend: {
+      show: showLegend !== false,
+      top: 0,
+      data: series.map(s => s.key),
+    },
+    xAxis: {
+      type: 'time',
+      name: xAxisLabel || undefined,
+      nameLocation: 'middle',
+      nameGap: theme.sizeUnit * 8,
+      axisLabel: { color: theme.colorTextSecondary },
+    },
+    yAxis: {
+      type: yLogScale ? 'log' : 'value',
+      name: yAxisLabel || undefined,
+      nameLocation: 'middle',
+      nameGap: theme.sizeUnit * 12,
+      min: yMin ?? undefined,
+      max: yMax ?? undefined,

Review Comment:
   **Suggestion:** Enabling logarithmic Y-axis unconditionally will break 
rendering for datasets that include zero or negative metric values, because 
ECharts log axes only accept strictly positive values. Add a guard that either 
disables log mode or sanitizes/filter values and bounds when non-positive data 
is present. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Time Pivot log-scale charts misrender with zero/negative metrics.
   - ⚠️ Users see missing points, confusing analytics on log scale.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. In the Superset UI, create or edit a Time-series Period Pivot chart 
(viz_type:
   time_pivot) so that the front-end uses `transformProps` at
   
`superset-frontend/plugins/plugin-chart-echarts/src/TimePivot/transformProps.ts:37`.
   
   2. In the chart controls, pick a metric that can produce zero or negative 
values (e.g., a
   sum or average over sparse data) and enable the "Logarithmic Y-axis" 
control, which sets
   `formData.yLogScale` to `true` passed into `transformProps`.
   
   3. Run the query so the chart loads; `transformProps` reads 
`formData.yLogScale` and
   constructs `echartOptions.yAxis` with `type: 'log'` at lines 103–106 and 
passes all raw
   `s.values.map(({ x, y }) => [x, y])` (including non-positive `y`) into the 
ECharts option
   at lines 134–147.
   
   4. When the ECharts renderer consumes these options, its log-scale axis 
rejects
   non-positive values; points at or below zero are dropped or the axis fails 
to render,
   causing a broken or misleading Time Pivot chart despite valid query results.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=dce1c138e31f4a93832323fb6dcffc18&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=dce1c138e31f4a93832323fb6dcffc18&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/plugins/plugin-chart-echarts/src/TimePivot/transformProps.ts
   **Line:** 103:109
   **Comment:**
        *Logic Error: Enabling logarithmic Y-axis unconditionally will break 
rendering for datasets that include zero or negative metric values, because 
ECharts log axes only accept strictly positive values. Add a guard that either 
disables log mode or sanitizes/filter values and bounds when non-positive data 
is present.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42245&comment_hash=f10ea7ae02c2fe322032822b6cca79ec5e29b42ec13df6647a605f4ac9d849c0&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42245&comment_hash=f10ea7ae02c2fe322032822b6cca79ec5e29b42ec13df6647a605f4ac9d849c0&reaction=dislike'>👎</a>



-- 
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