Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startPoint option to control where initial words get placed #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidjb
Copy link

@davidjb davidjb commented Jan 14, 2013

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.

@holgerd77
Copy link

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! :-)

@davidjb
Copy link
Author

davidjb commented Mar 25, 2013

@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.

@fallenartist
Copy link

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.

@adammenges
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants