lucaong / jQCloud

jQuery plugin for drawing neat word clouds that actually look like clouds
MIT License
646 stars 293 forks source link

Fixes a bug where the words are drawn when the cloud is not visible #21

Closed cham closed 12 years ago

cham commented 12 years ago

I think this only affects the logic when delayedMode is on as otherwise the synchronous logic prevents the container being hidden, or you can simply check that the container is visible before invoking jQCloud.

To replicate, create a cloud with delayedMode on. Whilst the cloud is loading, hide the container, then show it again once the cloud has finished drawing (real world use case for this is a tabbed UI and the cloud loading in one tab). As the elements need to be measured in order to be positioned, if they are not visible then they are all positioned in the centre of the container, on top of each other.

This fixes the issue by checking $this.is(':visible ') before drawing each word. If it is not visible then it sets a timeout to check again in 10ms.

cham commented 12 years ago

edit - clarified real world use case:

tabbed UI, user opens e.g.: "Word cloud" tab, jQCloud starts rendering with delayedMode on, user switches to a different tab whilst jQCloud is drawing, user then switches back to "Word cloud" tab. Rendered cloud has a number of topics positioned in the middle of the cloud on top of each other.

lucaong commented 12 years ago

Well done! I cherry picked the commit, and merged into version 1.0.0 (in case you intend to use it in your projects, pay attention because the API has changed)