jasondavies / d3-cloud

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

Drawing same array of 250 words and their sizes when canvas of container resizes #106

Closed mauricioxrodriguez closed 7 years ago

mauricioxrodriguez commented 7 years ago

Our current implementation allows for the user to shrink their screen and the data is cached so that no further server calls will be needed. The array of 250 words with their sizes is cached and once the map component is finished rendering then we call the cloud with the updated canvas sizes but the words are still original. This is causing the words to collide on screen resize event. I looked at the algolrithm you created to draw the words but nothing obvious stands out. It seems as if the words array is cached in the alrogorithm and getting the same exact words a second time messes up the drawing of the words and they collide. Only if I get a fresh set of data from the server (which is identical) to the one that is cached then the words won't collide. Any pointers?

jasondavies commented 7 years ago

Hard to say without seeing a reproducible example. There shouldn’t be any issue recalculating a layout for a new canvas size. Perhaps your redraw code has a bug?