Raman-Katiyar opened a new pull request, #21816:
URL: https://github.com/apache/echarts/pull/21816
## Brief Information
This pull request is in the type of:
- [x] bug fixing
- [ ] new feature
- [ ] others
### What does this PR do?
Fixes a crash (Cannot read properties of undefined (reading 'coord')) when a
line chart uses a piecewise visualMap with very few pieces (e.g. two pieces, or
a single lte/gt piece).
### Fixed issues
- #21174: [Bug] visualMap error
## Details
### Before: What was the problem?
With the option from #21174 - a line series and a piecewise visualMap with
pieces [{ lte: 400, color: 'green' }, { gt: 400, color: '#f00' }] (dimension:
1) - setOption throws TypeError: Cannot read properties of undefined (reading
'coord') in getVisualGradient (src/chart/line/LineView.ts). Five pieces work;
fewer than three pieces crash.
Root cause: in PiecewiseModel.getVisualMeta, an edge interval ([-Infinity,
b] or [a, Infinity]) only set an outerColors entry and pushed no colour stop at
its finite boundary. When all pieces are edge intervals, visualMeta.stops is
empty (and the transition point is lost). getVisualGradient then fell through
its all-out-of-range guard - which requires stopLen > 0 - and dereferenced
colorStopsInRange[0].
### After: How does it behave after the fixing?
- PiecewiseModel.getVisualMeta: an edge interval now also pushes a stop at
its finite boundary with its own colour, so the two-piece example produces
stops {400, green} and {400, '#f00'} and the line gradient transitions at 400
as expected.
- LineView.getVisualGradient: if there are no colour stops at all (e.g. a
single piece covering the whole range, which has no finite boundary), it
returns an outer colour if available instead of throwing.
The reported option, a single lte piece, a single gt piece, and the 3- and
5-piece variants all render without error. (Note: #18268 reported a crash with
a different, degenerate gte/lt configuration; this PR addresses the few-pieces
configuration of #21174.)
## Document Info
One of the following options should be marked as 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
### ZRender Changes
- [ ] This PR depends on ZRender changes.
### Related test cases or examples to use the new APIs
New unit tests in test/ut/spec/component/visualMap/piecewise.test.ts:
piecewise visualMap on a line chart with 1 piece (lte only), 1 piece (gt only),
2 pieces (the reported configuration), 3 pieces and 5 pieces must not throw.
The 1- and 2-piece tests fail with the reported TypeError before this fix and
pass after it. The existing visualMap unit tests (setOption.test.ts) still
pass, and npm run build succeeds.
### Merging options
- [x] Please squash the commits into a single one when merging.
### Other information
No dist/ files are included in this PR.
--
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]