getBBox returns a 0 sized rect

TL;DR: Your svg has to be visible for getBBox to be useful

While working with d3 recently, I was trying to calculate the width of some elements using getBBox , except it kept returning a 0-sized rect.

It turned out that the svg was being rendered when its parent <div> was not visible. Calling getBBox when the svg is visible gives the right results.

Apparently webkit used to some have issues with this but was patched a long time ago.

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *