Question

I'm hoping to make a dynamic word cloud that updates in (as close to) real time as possible, pulling the words and sentences from the MYSQL database. The MYSQL is then queried every few seconds to update the word cloud.

I found this library from google and this is working good for a static word cloud. But not in dynamic word cloud https://github.com/timdream/wordcloud2.js

When I update the words list array, say, I add one word in into the list array, whole word cloud will refresh, but not just add the newly added word to the word cloud. So, is there a way to implement a dynamic word cloud?

Thanks for the great help.

Was it helpful?

Solution

There's always a way, but you're missing a few building blocks.

You've got two places where your cloud exists:

1) Server side (database + php) 2) Client side (the browser)

The PHP (presumably) creates a flat page containing information the JS at the client side uses to render the cloud. Your browser (the JS) does the real work.

To retrieve updates, the JS needs to pull fresh information from the server every certain amount of time. The easiest way to do that is reload the page. Another way to do that is to retrieve a fresh array using AJAX and re-rendering the cloud. You'll need to dive deeper into the JS for that.

What you're probably looking for is to periodically retrieve a fresh array using AJAX and not re-render the cloud from scratch, but to loop through every word in the array and every word in previous array and remove any words that disappeared, add any new words, and update the HTML (size) of any words if their value has changed.

Looking at the JS you're using it doesn't seem to include that functionality. Which requires you to investigate and comprehend the workings of the JS script.

So your options are: a) Find a different word cloud script that already has this functionality b) Write your own JS script that updates the cloud. (And maybe push the changes to the original github repo if they'll have it?)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top