Skip to content

fix(line): avoid crash when visualMap piecewise produces no in-range stops#21613

Open
JamesGoslings wants to merge 1 commit into
apache:masterfrom
JamesGoslings:fix/18066-visualmap-pieces-null-lte
Open

fix(line): avoid crash when visualMap piecewise produces no in-range stops#21613
JamesGoslings wants to merge 1 commit into
apache:masterfrom
JamesGoslings:fix/18066-visualmap-pieces-null-lte

Conversation

@JamesGoslings
Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • 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

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.:

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.

  • 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

  • Please squash the commits into a single one when merging.

Other information

…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.
@echarts-bot
Copy link
Copy Markdown

echarts-bot Bot commented May 13, 2026

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant