Skip to content

Commit ff3e0a2

Browse files
rusackasclaude
andcommitted
fix(time-pivot): anchor log-axis min to smallest positive value
Prevents zero/negative metric values from producing a broken ECharts log-scale y-axis, following the same pattern used in Timeseries. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent dc70f14 commit ff3e0a2

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

superset-frontend/plugins/plugin-chart-echarts/src/TimePivot/transformProps.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from '@superset-ui/core';
2626
import type { EChartsCoreOption } from 'echarts/core';
2727
import { Refs } from '../types';
28+
import { calculateLowerLogTick } from '../utils/series';
2829
import transformData, { TimePivotSeries } from './transformData';
2930
import {
3031
EchartsTimePivotChartProps,
@@ -79,7 +80,23 @@ export default function transformProps(
7980
// Draw the current period last so it paints on top of the faded priors.
8081
const sortedSeries = [...series].sort((a, b) => b.rank - a.rank);
8182

82-
const [yMin, yMax] = yAxisBounds ?? [null, null];
83+
const [, yMax] = yAxisBounds ?? [null, null];
84+
let yMin = yAxisBounds?.[0] ?? null;
85+
// ECharts log axes only accept strictly positive values, so anchor the
86+
// default minimum to the smallest positive value rather than letting the
87+
// axis include zero/negative territory it cannot render.
88+
if (yLogScale && yMin == null) {
89+
const minPositiveValue = Math.min(
90+
...series.flatMap(s =>
91+
s.values
92+
.map(({ y }) => y)
93+
.filter((y): y is number => y != null && y > 0),
94+
),
95+
);
96+
if (Number.isFinite(minPositiveValue)) {
97+
yMin = calculateLowerLogTick(minPositiveValue);
98+
}
99+
}
83100

84101
const echartOptions: EChartsCoreOption = {
85102
grid: {

0 commit comments

Comments
 (0)