d3-cloud icon indicating copy to clipboard operation
d3-cloud copied to clipboard

Add startPoint option to control where initial words get placed

Open davidjb opened this issue 12 years ago • 4 comments

This adds the ability to control the starting position ([x,y] array) for the initial word/term being placed in the word cloud and can be used like so:

var width = 600;
var height = 300;
d3.layout.cloud().size([width, height])
          .startPoint([width/2.0, height/2.0])
...

which would ensure the first term is placed at the centre of the cloud. The startPoint can be any x,y position, however.

The parameter name could be something better or more descriptive, but the idea is there.

davidjb avatar Jan 14 '13 06:01 davidjb

Hi, I would support this patch. I have got a use case, where I use the tag cloud as a concrete navigation element for document search and there it is confusing when the tag cloud looks different every time the page is reloaded. Therefore I would also support an additional switch staticLayout, which eliminates random layouting if desired.

I have done this manually at the moment, by using the patch above, setting start point and replacing line 97/98 with:

dt = 0.43096132576465607 < .5 ? 1 : -1, // replaced to get static, predictable tag cloud //dt = Math.random() < .5 ? 1 : -1,

I think, semantics together with the startPoint attribute would make sense the following way: if no startPoint is set, a random static number is used, hard coded like in the two lines above. If a startPoint is set, it is used and only the random function above is exchanged with a static number.

Otherwise: thanks for the great work, can't wait to see my tag cloud in production! :-)

holgerd77 avatar Mar 22 '13 09:03 holgerd77

@holgerd77 Yes, that's something I'd be very much interested in as well. I'm not too fussed in the way to achieve it, but a replicable tag cloud would be excellent. Hence I was interested in #1.

davidjb avatar Mar 25 '13 22:03 davidjb

As for the static layout, I'd recommend using seedrandom library which modifies Math.random() so that it generates repetitive "random" values based on a seed variable. See it in action here.

fallenartist avatar Nov 26 '15 10:11 fallenartist

I'd support this. Controlling rough placement of the words is something I've been trying to accomplish lately.

adammenges avatar Aug 19 '16 17:08 adammenges