jasondavies / d3-cloud

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

pass the whole words array to mapping functions #110

Open stegben opened 7 years ago

stegben commented 7 years ago

I would like to pass a custom fontSize mapper like this:

function fontSizeMapper (word, idx, words) {
  const max = 100;
  const min = 10;
  const wordSize = words.map(w => w.size);
  const minSize = Math.min(...wordSize);
  const maxSize = Math.max(...wordSize);
  return min + (max - min) * (word.size - minSize) / (maxSize - minSize);
};

It's a normalization of font sizes, which requires to know the min and max value of word counts.