Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fit all terms by recursively decreasing the size until it fits #43

Open
wants to merge 3 commits into from

1 participant

Tom Zellman
Commits on Jul 16, 2014
  1. Tom Zellman
  2. Tom Zellman
Commits on Aug 25, 2014
  1. Tom Zellman

    typo and size check

    tzellman authored
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 12 deletions.
  1. +30 −12 d3.layout.cloud.js
42 d3.layout.cloud.js
View
@@ -42,20 +42,38 @@
function step() {
var start = +new Date,
- d;
+ d, x, y, nsi;
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;
+ x = d.x = (size[0] * (Math.random() + .5)) >> 1;
+ y = d.y = (size[1] * (Math.random() + .5)) >> 1;
+ nsi = i + 1;
cloudSprite(d, data, i);
- if (d.hasText && place(board, d, bounds)) {
- tags.push(d);
- event.word(d);
- if (bounds) cloudBounds(bounds, d);
- else bounds = [{x: d.x + d.x0, y: d.y + d.y0}, {x: d.x + d.x1, y: d.y + d.y1}];
- // Temporary hack
- d.x -= size[0] >> 1;
- d.y -= size[1] >> 1;
+ while(d.hasText) {
+ if (place(board, d, bounds)) {
+ tags.push(d);
+ event.word(d);
+ if (bounds) cloudBounds(bounds, d);
+ else bounds = [
+ {x: d.x + d.x0, y: d.y + d.y0},
+ {x: d.x + d.x1, y: d.y + d.y1}
+ ];
+ // Temporary hack
+ d.x -= size[0] >> 1;
+ d.y -= size[1] >> 1;
+ break;
+ } else {
+ // reset
+ delete d.sprite;
+ d.sprite = null;
+ d.x = x;
+ d.y = y;
+ // decrement the size until it fits
+ d.size = nsi < data.length ? data[nsi++].size : d.size - (d.size >> 3);
+ if (~~d.size > 0) {
+ cloudSprite(d, data, i);
+ }
+ }
}
}
if (i >= n) {
@@ -63,7 +81,7 @@
event.end(tags, bounds);
}
}
- }
+ };
cloud.stop = function() {
if (timer) {
Something went wrong with that request. Please try again.