jasondavies / d3-cloud

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

Create predictive seed in random #154

Closed jdbdnz closed 3 years ago

jdbdnz commented 5 years ago

Why

I need consistent and arbitrary placement of words. d3cloud.random determines placement, and returning a fixed number creates visual patterns. While returning a random number creates inconsistent word cloud generation.

What

Pass the word to d3cloud.random so the word can be hashed to determine placement

Use it somehow similar to this

d3cloud.random((dText = '') => Number(`0.${Math.abs(murmur2(dText))}`))

Notes

Math.random is used when d3cloud.random is not specified. In this PR it is receiving d.text as an argument, but it it doesn't accept arguments, so it's benign. If anyone wants to argue this is bad I could maybe fix it.

RicardoNeves commented 4 years ago

Wouldn't it make more sense to pass the entire object, instead of just the text?