jasondavies / d3-cloud

Create word clouds in JavaScript.
https://www.jasondavies.com/wordcloud/
Other
3.82k stars 1.08k forks source link

How to fit chart to size given #182

Open Harpush opened 1 year ago

Harpush commented 1 year ago

When I give the chart width and height I wish for it to fill it all. So even one word would scale to that size. Currently instead I get a much smaller actual size compared to given size. I tried to do it myself with bounds but it seems bounds are incorrect? Any help here?

Harpush commented 1 year ago

@jasondavies so using viewbox I kind of succeeded but it required a lot of work and not 100% accurate. The idea is setting the size to a larger size than I need (I know performance degrade) and then calculate once done using measure text the actual bounding box. Based on that to align the viewbox to scale into the drawn area.

Out of this I can think of two enhancements:

  1. Auto increase the size internally once a word can't be placed anywhere and try again.
  2. Return actual viewbox ready bounding box (x, y, width, height) or even two x,y pairs as it seems current ones are wrong?