fix(line): avoid crash when visualMap piecewise produces no in-range stops#21613
fix(line): avoid crash when visualMap piecewise produces no in-range stops#21613JamesGoslings wants to merge 1 commit into
Conversation
|
Thanks for your contribution! Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only. |
|
Thanks for the fix. This does avoid the crash for A remaining problematic case is: visualMap: {
type: 'piecewise',
pieces: [{ lte: 10, color: 'red' }],
outOfRange: { color: 'blue' }
}With the current PR, Suggested direction:
This keeps the responsibility aligned: visualMap produces correct |
…s, harden line gradient. close apache#18066 When a piecewise visualMap piece has no upper or lower bound (e.g. `{lte: null}` or `{lte: 10}` with implicit out-of-range), the piece interval is `[-Infinity, x]`, `[x, Infinity]` or `[-Infinity, Infinity]`. Previously `PiecewiseModel.getVisualMeta` only wrote `outerColors` and produced an empty `stops` array for all three. The line series renderer then either crashed at `colorStopsInRange[0].coord` or rendered with a single fallback color, losing the finite boundary. Fix the root cause in `PiecewiseModel.setStop`: - For half-infinite intervals (`[-Infinity, x]` or `[x, Infinity]`), set the corresponding `outerColors` entry as before AND emit the finite edge `x` as a stop so consumers can locate the boundary. - For fully-infinite `[-Infinity, Infinity]` intervals there is no finite edge to record, so only `outerColors` is set on both sides. In `LineView.getVisualGradient`: - Keep a defensive empty-stop fallback for the truly fully-infinite case so the chart renders a solid color instead of crashing. - Fix the reversal heuristic: when stops collapse to a single coord (e.g. two boundary stops at the same value, which is exactly what a single half-infinite piece produces) the coord comparison gives no signal, so fall back to `axis.inverse` to decide whether to flip on an inverted axis. Adds three tests: - `piecewiseWithNullBoundOnLineSeries`: original repro, asserts `setOption` does not throw. - `piecewiseHalfInfiniteEmitsBoundaryStop`: asserts the finite edge of `{lte: 10}` plus its implicit `(10, Infinity)` outOfRange piece both end up as stops at value `10`. - `piecewiseFullInfiniteStillEmitsNoStops`: asserts the fully infinite case still produces an empty `stops` array (defensive LineView fallback path).
ac6ab3a to
bf5e37c
Compare
|
Thanks for the careful review @Justin-ZS — agreed, fixing it in 1. Root cause in
For your example 2. Defensive empty-stop fallback in 3. Reversal heuristic in if (stopLen && (
colorStops[0].coord > colorStops[stopLen - 1].coord
|| (colorStops[0].coord === colorStops[stopLen - 1].coord && axis.inverse)
)) {
colorStops.reverse();
outerColors.reverse();
}Stops are emitted in value-ascending order by both Tests. Three cases now:
Full unit suite still green (25 suites, 195 tests). Force-pushed the branch as a single squashable commit. PTAL when you have a moment. |
|
Thanks for updating this. The I think the new tied-coord reversal fallback in colorStops[0].coord === colorStops[stopLen - 1].coord && axis.inverse
A more robust check is to derive the direction from the axis coord extent after const coordExtent = axis.getExtent();
const isCoordReversed = axis.toGlobalCoord(coordExtent[0]) > axis.toGlobalCoord(coordExtent[1]);
if (stopLen && isCoordReversed) {
colorStops.reverse();
outerColors.reverse();
}This gives the expected direction for all four basic cases:
The current |
Brief Information
This pull request is in the type of:
What does this PR do?
Fix a crash in line series when a
visualMappiecewise piece has no upper / lower bound (e.g.{ lte: null }), which previously madecolorStopsInRangeempty and causedCannot read properties of undefined (reading 'coord').Fixed issues
Details
Before: What was the problem?
When a
visualMapof typepiecewisehas a piece without an upper bound (or both bounds missing), e.g.:PiecewiseModelfalls back the missing bound toInfinity/-Infinity, so the piece interval becomes[-Infinity, Infinity]. InPiecewiseModel.getVisualMeta, thesetStophelper only fillsouterColors(neverstops) when an interval edge is±Infinity. As a result the line series renderer receives an emptycolorStopsInRangearray and crashes atLineView.ts:350:Reproduction from the issue:
https://echarts.apache.org/examples/en/editor.html?c=line-simple&code=PYBwLglsB2AEC8sDeAoWsCeBBAHhAzgFywDaa6y5FsYGIApsQOQBuAhgDYCu9TANFVgBfcgF0B6HLgLEy1VNXS0GzAMZsw9AObAAThn6CR6ceQ7b60ACbEFFfAAtgAd2IAzTvnrkhE2Ft0IG2RfcjBgYA5IEFtQ9C9A-iJSQTtqZUZYJg4IaF4_amg2AFtMphBdYDcIMENqY1hTdCsNNi8wWVTBZohS6HwoftkmDHo2XX4siqqapibFfGAuXVVMuUV0NI3MMd1mACYABgBGQ7rt9HLK6triU8OCxTjtrY3R8YOT4_OLq5nb2BHB7dCjPDavRTvPZZI7HfY_bZ_G5MO4AVmBFzBigh1Chn2OAGYERskbNiATDhjtg1qKIjGI_CwCFxOABZNgxSjUEAQeirZLreQg9BaTTEKkbKKZaBcDgcR7UVSRPTMABG3F4IJpjUe4U5p0eel50A6WScgQAXjAwJwEeY3KamKsTfQJn4REIANxAA
After: How does it behave after the fixing?
In
getVisualGradientofsrc/chart/line/LineView.ts, add a guard for the case wherecolorStopsInRangeis empty (andstopLenis also0, which the existing!inRangeStopLen && stopLenbranch does not cover). Fall back toouterColors[0] || outerColors[1] || 'transparent'so the chart renders with a single fallback color instead of crashing.The new branch is only hit when there are no color stops at all, so existing behaviors are unchanged.
Added a regression test
piecewiseWithNullBoundOnLineSeriesintest/ut/spec/component/visualMap/setOption.test.tsthat reproduces the original report and assertssetOptiondoes not throw.Verification:
LineView.ts:350).Test Suites: 24 passed, 24 total; Tests: 186 passed, 186 total.Document Info
One of the following should be checked.
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
N.A.
Merging options
Other information