Open matt-hoskins opened 7 years ago
Thanks for filing. I would love to overhaul the entire API by either allow every method set-able to a callback, or allow properties to be attach on each of the item individually.
I simply don't have time to do either of that :'(. Let's keep the issue open until this gets resolved.
No problem - I wasn't sure how actively you were working on it, so I figure I'd chuck the idea up here in case it was easy to tuck in or something to bear in mind for the future :).
If I end up changing a copy of the code myself to implement either of my ideas I'll share the patch.
It doesn't seem to be possible to have varying rotation and have a repeatably rendered arrangement because the rotation function calls Math.random(). As far as I can tell the only option is to have the words only at one angle if you want the cloud's word arrangement to look the same each time it's rendered (in combination with shuffle being set to false of course).
It would be nice to be able to have rotation variation between words but have the word cloud repeatably render the same arrangement of words.
I had two ideas for how this could be done. The first is to have an option which can specify a callback function for a word's rotation (similar to the one for color perhaps so it could even make use of the word information). It would then be possible to do repeatable pseudo-random rotation changes or link the rotation to the word/weight and thus meaning the wordcloud could be drawn each time looking the same but with a mixture of word rotations.
The second idea is maybe to allow specification of the random function that wordcloud2.js calls via an option. It would default to Math.random() to behave as it currently does but could be passed in e.g. a seeded pseudo-random number generator function that also generates numbers between 0 and 1.0 but repeatably so due to the seeding. I've used a python wordcloud library before which allows this approach and it works well. Javascript doesn't have any built-in seedable random number generator but there are libraries and code out there for them.