fix(line): keep step corners when adjacent points are visually close#21616
Open
JamesGoslings wants to merge 1 commit into
Open
fix(line): keep step corners when adjacent points are visually close#21616JamesGoslings wants to merge 1 commit into
JamesGoslings wants to merge 1 commit into
Conversation
…lose apache#21614 The drawSegment helper in line/poly.ts drops segments whose squared pixel distance is below 0.5 as a render-time optimization. For regular polylines this is harmless, but step lines (produced by turnPointsIntoStep) rely on every emitted point to define the corners of the stair-case. When two consecutive data points are very close on the base axis, the auxiliary corner points fall under the threshold and get skipped, collapsing the L-shape into a diagonal slope. Propagate a `step` flag from LineView through ECPolyline/ECPolygon shapes into drawSegment, and in step mode only drop strictly duplicate points (dx === 0 && dy === 0). Non-step rendering is unchanged. Adds a unit test that records the path commands emitted for a step configuration matching the reproduction in apache#21614 and asserts that the corner is visited before the tail.
|
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?
Stop the line renderer from collapsing step (stair-case) lines into diagonal slopes when adjacent data points are very close on the base axis.
Fixed issues
Details
Before: What was the problem?
drawSegmentinsrc/chart/line/poly.tsdrops any segment whose squared pixel distance is< 0.5as a render-time optimization:For plain polylines this is harmless. For step lines, however,
turnPointsIntoStepexpands each data segment into an L-shape by inserting an auxiliary corner point. Those corner points encode the stair-case and must all be visited.When two consecutive data points are very close on the base axis (e.g.
[08:59:30, 1]and[09:00:00, 1]reported in #21614), both the corner and one or more intermediate auxiliary points fall under the< 0.5threshold. They all get skipped, so the renderer goes straight from the previous point to the next far point, drawing a diagonal slope instead of a vertical step.Reproduction from the issue (CodeSandbox): https://codesandbox.io/p/sandbox/pdh82y?file=%2Findex.js
The reporter also already pinpointed the offending line:
src/chart/line/poly.ts:83.After: How does it behave after the fixing?
A
stepflag is propagated fromLineViewthroughECPolyline/ECPolygonshapes intodrawSegment. In step mode the function now only drops strictly duplicate points (dx === 0 && dy === 0) and keeps every other corner intact:Non-step rendering is byte-for-byte identical.
Added a unit test
test/ut/spec/series/line-step-poly.test.tsthat records the path commands emitted for a step-expanded point set matching the #21614 reproduction and asserts:< 0.5tiny-segment optimization.Verification:
lineTois emitted).Test Suites: 25 passed, 25 total; Tests: 188 passed, 188 total.npm run lintandtsc --noEmitboth pass (also enforced by the project's pre-commit hook).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