jasondavies / d3-cloud

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

Keeping words together, or two-word phrases? #129

Closed coevolving closed 6 years ago

coevolving commented 7 years ago

D3 cloud is great!

In the original Wordle, there was a way to keep key phrases together. At http://www.wordle.net/faq#space :

Can I keep some words together? Can I visualize two-word phrases? Yes! You can use either the Unicode "non-breaking space" character or the tilde character ~ between words that go together. The tilde will be converted to a space when drawing the words, and the words will be treated as a single word. See http://blog.wordle.net/2008/06/keep-words-together-with-tilde.html.

I've tried using the tilde and Unicode non-breaking space at https://www.jasondavies.com/wordcloud/ , but the words remain separated. Is there an easy workaround?

Migaroez commented 6 years ago

You can set the words/phrases that need to rendered by supplying an array [{ "text": "words with spaces", "size": 40 }, { "text": "motion", "size": 15 }, { "text": "forces", "size": 10 }, { "text": "electricity", "size": 15 }]

cloud().words(the_array_goes_here) .fontSize(function (d) { return d.size*2; })

The text is what should be displayed spaces and all, the size is how often it occurs.