From 40db0bea3247b1b89b5f8a07e3e3bf453fc27638 Mon Sep 17 00:00:00 2001 From: "David\\ Beitey" Date: Mon, 14 Jan 2013 16:13:12 +1000 Subject: [PATCH] Add startPoint option to control where initial words get placed --- d3.layout.cloud.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/d3.layout.cloud.js b/d3.layout.cloud.js index 8db8c16..0381ac6 100644 --- a/d3.layout.cloud.js +++ b/d3.layout.cloud.js @@ -3,6 +3,7 @@ (function(exports) { function cloud() { var size = [256, 256], + startPoint = null, text = cloudText, font = cloudFont, fontSize = cloudFontSize, @@ -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); @@ -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);