chrisrzhou / react-wordcloud

☁️ Simple React + D3 wordcloud component with powerful features.

Home Page:https://react-wordcloud.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to assign fixed color to individual word?

Maxwell-Wong opened this issue · comments

I want to assign fixed color to the words with same frequency, and the words with higher frequency will also have deeper color. I have generated the color array for each word. Is there any way to turn off the random assignment of the color and assign each word with self-defined color from the options? Thank you!

As we have determined the color for each word, but the behaviour of the wordcloud seems to shuffle the color array and assign the color to each word randomly within the given colors.
What we are caring about is disabling the random mechanism and assign the color to each word along the sequence of the color in the color array.

you could use the callback getWordColor like this:
getWordColor: word => word.value > 50 ? "blue" : "red",

<ReactWordcloud
    callbacks={{
      getWordColor: (word) => word.value > 50 ? "blue" : "red"
    options={options}
    words={words}
    }}
 />