JamesGoslings opened a new pull request, #21613:
URL: https://github.com/apache/echarts/pull/21613
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### What does this PR do?
Fix a crash in line series when a `visualMap` piecewise piece has no upper /
lower bound (e.g. `{ lte: null }`), which previously made `colorStopsInRange`
empty and caused `Cannot read properties of undefined (reading 'coord')`.
### Fixed issues
- #18066: [Bug] Line Charts do not work when lte is set to null
## Details
### Before: What was the problem?
When a `visualMap` of type `piecewise` has a piece without an upper bound
(or both bounds missing), e.g.:
```js
visualMap: {
type: 'piecewise',
pieces: [{ lte: null, color: 'red' }]
}
```
`PiecewiseModel` falls back the missing bound to `Infinity` / `-Infinity`,
so the piece interval becomes `[-Infinity, Infinity]`. In
`PiecewiseModel.getVisualMeta`, the `setStop` helper only fills `outerColors`
(never `stops`) when an interval edge is `±Infinity`. As a result the line
series renderer receives an empty `colorStopsInRange` array and crashes at
`LineView.ts:350`:
```
Uncaught TypeError: Cannot read properties of undefined (reading 'coord')
at colorStopsInRange[0].coord - tinyExtent
```
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 `getVisualGradient` of `src/chart/line/LineView.ts`, add a guard for the
case where `colorStopsInRange` is empty (and `stopLen` is also `0`, which the
existing `!inRangeStopLen && stopLen` branch does not cover). Fall back to
`outerColors[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 `piecewiseWithNullBoundOnLineSeries` in
`test/ut/spec/component/visualMap/setOption.test.ts` that reproduces the
original report and asserts `setOption` does not throw.
Verification:
- Without the fix, the new test fails with the exact stack from the issue
(`LineView.ts:350`).
- With the fix, the new test passes.
- All existing unit tests still pass: `Test Suites: 24 passed, 24 total;
Tests: 186 passed, 186 total`.
## Document Info
One of the following should be checked.
- [x] This PR doesn't relate to document changes
- [ ] The document should be updated later
- [ ] The document changes have been made in apache/echarts-doc#xxx
## Misc
### Security Checking
- [ ] This PR uses security-sensitive Web APIs.
### ZRender Changes
- [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
### Related test cases or examples to use the new APIs
N.A.
### Merging options
- [x] Please squash the commits into a single one when merging.
### Other information
--
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]