Skip to content

Commit

Permalink
Add startPoint option to control where initial words get placed
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjb committed Jan 14, 2013
1 parent 8803b7f commit 40db0be
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions d3.layout.cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(function(exports) {
function cloud() {
var size = [256, 256],
startPoint = null,
text = cloudText,
font = cloudFont,
fontSize = cloudFontSize,
Expand Down Expand Up @@ -46,8 +47,13 @@
d;
while (+new Date - start < timeInterval && ++i < n && timer) {
d = data[i];
d.x = (size[0] * (Math.random() + .5)) >> 1;
d.y = (size[1] * (Math.random() + .5)) >> 1;
if (startPoint) {
d.x = startPoint[0];
d.y = startPoint[1];
} else {
d.x = (size[0] * (Math.random() + .5)) >> 1;
d.y = (size[1] * (Math.random() + .5)) >> 1;
}
cloudSprite(d, data, i);
if (place(board, d, bounds)) {
tags.push(d);
Expand Down Expand Up @@ -142,6 +148,12 @@
return cloud;
};

cloud.startPoint = function(x) {
if (!arguments.length) return startPoint;
startPoint = [+x[0], +x[1]];
return cloud;
};

cloud.font = function(x) {
if (!arguments.length) return font;
font = d3.functor(x);
Expand Down

0 comments on commit 40db0be

Please sign in to comment.