jasondavies / d3-cloud

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

Setting font sizes dynamically based on height and width of container. #115

Closed saikiriti closed 7 years ago

saikiriti commented 7 years ago

Currently I am plotting word cloud chart by assigning maximum font size to most occurring word and minimum font size to least occurring word and calculating font size of of all intermediate words using formula: fontSize = (currentCount / maxCount) * (maxFont - minFont) + minFont; where currentCount is number of occurrence of a particular word and maxCount is number of occurrence of maximum occurring word.

Currently the min and max font sizes are hard coded.

When dimensions of container are dynamically changed or resized, i am unable to plot most occurring words with maxFont size that is set initially. Because the min and max font size may not be the best fit for all container dimensions. So we need a calculation or formula where we can calculate min and max font sizes for each different dimensions instead of manually setting them.

Questions & Problems to fix:

1) How to set font sizes differently for each plot area based on width and height? 2) If not set different font sizes the most occurring words are missing from the chart and is not consistent across various plot area dimensions. 3) Is there any other approach to make most occurring word with max font size visible for all dimensions other than using overflow(true) ?

Sample Fiddle: https://jsfiddle.net/h7u5k1ab/4/

jasondavies commented 7 years ago

Thanks for the report. I’m closing as a duplicate of #36, as this would be solved by auto-scaling internally to ensure no words are dropped.

vishalsomaniecotech commented 6 years ago

Auto-scaling does not consider frequency of word. Font size should depend on container size and word frequency.