fix(line): avoid crash when visualMap piecewise produces no in-range stops#21613
Open
JamesGoslings wants to merge 1 commit into
Open
fix(line): avoid crash when visualMap piecewise produces no in-range stops#21613JamesGoslings wants to merge 1 commit into
JamesGoslings wants to merge 1 commit into
Conversation
…stops. close apache#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.
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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