Skip to content

fix(path): reflect the previous group of a repeated S or T and read exponents with a plus sign - #1187

Open
SwastikTripathi wants to merge 1 commit into
ecomfe:masterfrom
SwastikTripathi:fix/svg-path-repeated-smooth-curves
Open

SwastikTripathi wants to merge 1 commit into
ecomfe:masterfrom
SwastikTripathi:fix/svg-path-repeated-smooth-curves

Conversation

@SwastikTripathi

Copy link
Copy Markdown

Two small problems in the SVG path parser (src/tool/path.ts), which createFromString() / extendFromString() and ECharts' path:// symbols and custom graphics go through.

Repeated S / T groups. A command letter can be followed by several groups of numbers, and each group is a command of its own. prevCmd was only updated once per command letter, so the second group of an S or T checked the command before the letter instead of the first group. After a non-curve command it then didn't reflect the first group's control point:

M0 0 S10 10 20 0 30 -10 40 0

The second segment should start with the control point (30, -10) (the reflection of (10, 10) about (20, 0)), but used the current point (20, 0). Same for M0 0 T10 10 20 0, where the second T drew a straight line instead of a curve. After a C (or Q) the old code happened to give the right result, so c ... s ... s paths were fine. prevCmd is now also set after each group.

Exponent with a plus sign. numberReg accepted e-5 but not e+5, so 1e+2 was read as the two numbers 1 and 2 and shifted every value after it. JavaScript writes large numbers that way (String(1e21) is "1e+21"). The exponent sign is now [-+]?.

Added test/ut/spec/tool/path.test.ts, which compares the bounding rect of each path with the same shape written with explicit C / Q commands or plain numbers. Both tests fail before the change; npm test passes (70 tests) and eslint is clean on path.ts.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant