d3-cloud
d3-cloud copied to clipboard
Allow data to be added to an existing layout.
It would be nice to support words arriving asynchronously in a streaming fashion. One possibility is to make the layout stateful, so that it can lay out new data while avoiding collisions with the existing layout.
I agree :p
Is there a work-around to get an approximation of this feature ? (I can handle the cloud being re-arranged) i.e. in a way that acts like your word cloud generator. I can't seem to find a way to do so. Thanks.
The word cloud generator knows all the words up-front, so this doesn’t apply. This issue addresses the case where you don’t know all the words in advance, and you want to position new words in a partially-filled region.
Right, got that.
But I meant that the word cloud generator can re-use the same tagcloud instance, re-submit words with new words appended and have them integrated to the re-mixed tagcloud.
I can handle keeping the state out of the tagcloud instance (differs from original post, sorry) and I can handle re-calculating the cloud layout. I just can't figure from the source or the examples how to add new words without having to create a new instance for each new word arrival. Any hints?
Thanks!
Perhaps I was nit-picking. :) The word cloud generator reuses a single layout instance. Every time you call layout.start(), it starts with an empty canvas and lays out the words that you have given it via layout.words(…). So if you have an array of words, and you want to add a new word, you can simply push it onto the array, and call:
layout
.stop()
.words(words)
.start();
If you are reading words from some kind of stream, then that’s what this issue is about: there’s no way to reuse a partially-filled canvas for collision detection if a new word arrives. This probably wouldn’t give good results anyway, because the algorithm starts off by placing the largest words first.
@jasondavies do you have any tips or pointers for someone interested in implementing dynamically placing tags in an already existing layout?