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


##########
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:
   Fixed — when `yLogScale` is on and no explicit min is set, I now anchor the 
axis min to the smallest positive value in the series (same approach 
`Timeseries` uses for `logAxis`), so zero/negative points no longer break the 
log scale.



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