raphael icon indicating copy to clipboard operation
raphael copied to clipboard

getBBox() fails for text elements when paper not visible

Open MarkMaldaba opened this issue 10 years ago • 6 comments

If you call getBBox() to get the bounding box of a text element when the whole Raphael element is hidden (e.g. if it is inside a <div> with display: none) then the properties of the returned object are all set to NaN rather than the actual bounding box values of the element.

This means that it is impossible to perform proper layout whilst the element is hidden.

As JS doesn't provide a way of detecting when a hidden element becomes visible there is also no way to resolve this by redrawing the element automatically when the item becomes visible.

This is a serious issue for me, as I am creating an interactive widget that people can place on their page, and in situations where this is initially invisible the widget ends up being layed-out incorrectly and there is no way to fix this. The best I have managed is by having a timeout() set which tries to redraw the widget every 100 ms, which is horribly inefficient!

getBBox() should be fixed so it works regardless of whether the element is visible or not.

Note that I have tested this for circle elements, and it seems to work fine. Presumably other basic shapes are also fine - I have not tested them.

MarkMaldaba avatar Jul 29 '13 12:07 MarkMaldaba

I've put together a fiddle showing the problem. Enable your JS console to see the output: http://jsfiddle.net/Ca2yk/

y.getBBox() has all values set to NaN. Removing display: none from the surrounding <div> gives the expected values, as shown here http://jsfiddle.net/Ca2yk/1/

Tested in Firefox 22.0

MarkMaldaba avatar Jul 29 '13 15:07 MarkMaldaba

Further update - have tested in Chrome and get the same problem, except in this case the values are all set to 0 rather than NaN.

MarkMaldaba avatar Jul 29 '13 15:07 MarkMaldaba

dear

I have the same problem because I want migrate a raphael app to polymerJS and polymer hiddes the elements initial. Did you find a solution for the BBox problem?

Greetings

freegroup avatar Oct 28 '14 22:10 freegroup

No, other than constantly checking via a timetout as mentioned above.

MarkMaldaba avatar Oct 29 '14 15:10 MarkMaldaba

5.5 years later and no fix or workaround?

jfrank14 avatar Jun 19 '20 16:06 jfrank14

Just switch it to opacity 0 instead and get the val and it should work.

ibrierley avatar Jun 19 '20 17:06 ibrierley