Closed voxspox closed 4 years ago
The width()
method accesses the width
attribute of the element. Text does not have this attribute. However, I see the incosistency because circle does have the method even though there is no width attribute. So I guess it is just missing.
Your workaround on the other hand is on point. I would generally advice to use bbox here because it works for all shapes the same way without any quirks done by the library.
Just the way you get the box is unusual for svg.js because you can just go item.bbox().width
ah ok. didn't recognize bbox()
so far :)
maybe you want to add a calcWidth()
to Element.
Why would I when there is bbox? The fact that text misses the width attr might be a bug but there is no use for an extra method which just returns something from bbox
bbox just wraps SVGs bbox and does no extra calculations, right? If bbox().width
is always possible, i.e. bbox never fails, then I agree with you bbox
is enough and there is no need for an extra function.
Correct, beside that, a width()
implementation for text would do exactly that - because text itself does not have a width attribute. Another possibility to get the width is calling text.node.getComputedTextLength()
So I will close this issue because its not likely to get fixed. Thats because it is not possible to set a width/height or size like this. It would only work as getter. Since we want a unified api for all elements it is better to be explicit about not having width etc because it wont work for setting
Bug report
If created a
group
g of different elements liketext
,circle
, etc. I want to arrange this elements and iterate overg.children()
and accesswidth()
. Unfortunately width is not available for all childs p.ex. textI have the following workaround: