svgdotjs / svg.js

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

Relative positioning of text elements broken #1141

Closed Thomas1664 closed 4 years ago

Thomas1664 commented 4 years ago

Bug report

When I try to apply relative positioning (e.g. 50%) to a text element, the position is gets reset to 0.

Fiddle

My fiddle

Explanation

Fuzzyma commented 4 years ago

Since text gets placed by its bounding box (upper left corner) rather by its base line, svg.js can only handle numbers as parameters and no percentage values. However, you can use ax(), ay(), amove() to do that or just set the x and y attrs yourself with attr('x', '50%')