From ac6ab3a7fb0bb4d968500b8119fa76b37c71e94a Mon Sep 17 00:00:00 2001 From: JamesGoslings <3248175240@qq.com> Date: Wed, 13 May 2026 21:06:29 +0800 Subject: [PATCH] fix(line): avoid crash when visualMap piecewise produces no in-range stops. close #18066 When a visualMap piecewise piece has no upper or lower bound (e.g. `{lte: null}` or both ends omitted), its interval becomes [-Infinity, Infinity]. In that case `PiecewiseModel.getVisualMeta` only writes `outerColors` and produces an empty `stops` array. The line series renderer then crashed at `colorStopsInRange[0].coord` with: TypeError: Cannot read properties of undefined (reading 'coord') Fall back to a single outer color (or transparent) when `colorStopsInRange` is empty, instead of indexing into it. Adds a regression test that reproduces the original report. --- src/chart/line/LineView.ts | 7 +++++ .../component/visualMap/setOption.test.ts | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/chart/line/LineView.ts b/src/chart/line/LineView.ts index 3682d96512..e0de6d67de 100644 --- a/src/chart/line/LineView.ts +++ b/src/chart/line/LineView.ts @@ -345,6 +345,13 @@ function getVisualGradient( ? (outerColors[1] ? outerColors[1] : colorStops[stopLen - 1].color) : (outerColors[0] ? outerColors[0] : colorStops[0].color); } + if (!inRangeStopLen) { + // No color stops at all (e.g. when all visualMap pieces produce + // [-Infinity, Infinity] intervals, like `pieces: [{ lte: null }]`). + // Fall back to a single outer color or transparent so that we + // don't crash on `colorStopsInRange[0].coord` below. See #18066. + return outerColors[0] || outerColors[1] || 'transparent'; + } const tinyExtent = 10; // Arbitrary value: 10px const minCoord = colorStopsInRange[0].coord - tinyExtent; diff --git a/test/ut/spec/component/visualMap/setOption.test.ts b/test/ut/spec/component/visualMap/setOption.test.ts index d132385eac..d90da36a43 100755 --- a/test/ut/spec/component/visualMap/setOption.test.ts +++ b/test/ut/spec/component/visualMap/setOption.test.ts @@ -287,4 +287,30 @@ describe('vsiaulMap_setOption', function () { done(); }); + // See https://github.com/apache/echarts/issues/18066 + it('piecewiseWithNullBoundOnLineSeries', function (done) { + // Setting `lte: null` (or omitting both bounds) makes the piece + // interval [-Infinity, Infinity], which previously crashed + // line series rendering with + // "Cannot read properties of undefined (reading 'coord')". + expect(function () { + chart.setOption({ + xAxis: {type: 'category', data: ['A', 'B', 'C', 'D']}, + yAxis: {type: 'value'}, + visualMap: { + type: 'piecewise', + pieces: [ + // lte set to null should be treated as no upper bound. + {lte: null, color: 'red'} + ] + }, + series: [{ + type: 'line', + data: [10, 20, 30, 40] + }] + }); + }).not.toThrow(); + done(); + }); + }); \ No newline at end of file