jasondavies / d3-cloud

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

Multi-centers word cloud (or sub-clouds support) #98

Open jenkin opened 8 years ago

jenkin commented 8 years ago

At this moment, fixing the size of the available space for the cloud, it will be positioned at the center of this container (you can translate your g container where you want into the svg, of course).

But I need a sort of clustered word cloud, or a multi-centers word cloud, with words positioned into sub-clouds, without use several layout instances and containers. Sub-clouds centers are attributes of words.

Here you can see my solution to this problem: https://jenkin.github.io/d3-cloud/examples/ (code here).

There are two new public methods: center() to set the getter function (default: return center attribute of word, if any) and ratio() to control the aspect ratio of sub-clouds. Now there are also a local (and word-based) size, equal to the minimum distance of the center from boundaries.

What do you think? My final goal is drawing a word cloud map, with centers coming from projection of locations.

jenkin commented 8 years ago

Uh, maybe it's related to issue #8 ... :)

jenkin commented 8 years ago

EDIT: now I use a square() method instead of the ratio() one to force a sub-cloud to be square. The center() method accept also a static value (an array of two coordinates) to center the cloud in any location into the viewport. If it is a function taking a value from word data, then you have sub-clouds.

wdss93 commented 5 years ago

Perfect! @jenkin