Reputation: 2451
I am creating a visualization with d3 that contains a bunch of rect elements of different sizes. I'd like to put in a "caption" into each rect element, but I'd only like it to be displayed if the text fits naturally. How would this be done?
Upvotes: 2
Views: 5262
Reputation: 109232
You get the bounding box of the text, check whether it's too big for the rect
element and remove it if this is the case. Here is an example of how to get the bounding box of a text element.
Upvotes: 3