svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
11.01k stars 1.07k forks source link

textPath.first().x(0) give not x="0" in release 3.2.0 #1207

Closed PiotrFr closed 11 months ago

PiotrFr commented 3 years ago

Bug report

Fiddle

Release 3.0.16 give <tspan x="0"> https://jsfiddle.net/Piotrf/xfamqp1e/3/ Release 3.1.0 give <tspan x="2.96875"> https://jsfiddle.net/Piotrf/arnbd0v5/1/

Explanation

Fuzzyma commented 3 years ago

Were you able to figure out where things go wrong?

PiotrFr commented 3 years ago

Release 3.0.16 image

Release 3.1.0 image

PiotrFr commented 3 years ago

Maybe it will help Fiddle image image

PiotrFr commented 2 years ago

Release 3.0.16 https://jsfiddle.net/Piotrf/wsfnjhmr/37 image

Release 3.1.2 https://jsfiddle.net/Piotrf/wsfnjhmr/41 image

Fuzzyma commented 11 months ago

The reason this is happning is, that x() moves the bounding box of the element. The bbox x value of the tspan is 12 in your fiddle. Calling x(0) will attempt to move the bounding box to 0 (which means the tspan -12). However, this ofc fails on a tspan.

To do what you want, use ax() instead which does not do any magic and instead just moves the anchor:

https://jsfiddle.net/96uz7tnh/