Permalink
Browse files

Merge branch 'release'

  • Loading branch information...
2 parents 7c518c5 + 4c998ba commit 173a936d689ba61056b778527b354f227fdeb437 @mbostock mbostock committed May 12, 2011
Showing with 418 additions and 129 deletions.
  1. +3 −0 Makefile
  2. +27 −8 d3.js
  3. +113 −54 d3.layout.js
  4. +1 −1 d3.layout.min.js
  5. +2 −2 d3.min.js
  6. +65 −0 examples/touch/touch.html
  7. +1 −1 src/core/core.js
  8. +7 −0 src/core/permute.js
  9. +115 −56 src/layout/stack.js
  10. +11 −7 src/svg/mouse.js
  11. +8 −0 src/svg/touches.js
  12. +38 −0 tests/test-permute.js
  13. +27 −0 tests/test-permute.out
View
@@ -41,6 +41,7 @@ d3.core.js: \
src/core/keys.js \
src/core/values.js \
src/core/entries.js \
+ src/core/permute.js \
src/core/merge.js \
src/core/split.js \
src/core/collapse.js \
@@ -86,6 +87,7 @@ d3.svg.js: \
src/svg/chord.js \
src/svg/diagonal.js \
src/svg/mouse.js \
+ src/svg/touches.js \
src/svg/symbol.js
d3.behavior.js: \
@@ -161,6 +163,7 @@ tests: \
tests/test-interpolate.test \
tests/test-keys.test \
tests/test-nest.test \
+ tests/test-permute.test \
tests/test-remove.test \
tests/test-rgb.test \
tests/test-hsl.test \
View
35 d3.js
@@ -1,4 +1,4 @@
-(function(){d3 = {version: "1.15.1"}; // semver
+(function(){d3 = {version: "1.16.0"}; // semver
if (!Date.now) Date.now = function() {
return +new Date();
};
@@ -168,6 +168,13 @@ d3.entries = function(map) {
for (var key in map) entries.push({key: key, value: map[key]});
return entries;
};
+d3.permute = function(array, indexes) {
+ var permutes = [],
+ i = -1,
+ n = indexes.length;
+ while (++i < n) permutes[i] = array[indexes[i]];
+ return permutes;
+};
d3.merge = function(arrays) {
return Array.prototype.concat.apply([], arrays);
};
@@ -3165,6 +3172,13 @@ function d3_svg_diagonalProjection(d) {
return [d.x, d.y];
}
d3.svg.mouse = function(container) {
+ return d3_svg_mousePoint(container, d3.event);
+};
+
+// https://bugs.webkit.org/show_bug.cgi?id=44083
+var d3_mouse_bug44083 = /WebKit/.test(navigator.userAgent) ? -1 : 0;
+
+function d3_svg_mousePoint(container, e) {
var point = (container.ownerSVGElement || container).createSVGPoint();
if ((d3_mouse_bug44083 < 0) && (window.scrollX || window.scrollY)) {
var svg = d3.select(document.body)
@@ -3177,18 +3191,23 @@ d3.svg.mouse = function(container) {
svg.remove();
}
if (d3_mouse_bug44083) {
- point.x = d3.event.pageX;
- point.y = d3.event.pageY;
+ point.x = e.pageX;
+ point.y = e.pageY;
} else {
- point.x = d3.event.clientX;
- point.y = d3.event.clientY;
+ point.x = e.clientX;
+ point.y = e.clientY;
}
point = point.matrixTransform(container.getScreenCTM().inverse());
return [point.x, point.y];
};
-
-// https://bugs.webkit.org/show_bug.cgi?id=44083
-var d3_mouse_bug44083 = /WebKit/.test(navigator.userAgent) ? -1 : 0;
+d3.svg.touches = function(container) {
+ var touches = d3.event.touches;
+ return touches ? d3_array(touches).map(function(touch) {
+ var point = d3_svg_mousePoint(container, touch);
+ point.identifier = touch.identifier;
+ return point;
+ }) : [];
+};
d3.svg.symbol = function() {
var type = d3_svg_symbolType,
size = d3_svg_symbolSize;
View
@@ -636,49 +636,104 @@ d3.layout.pie = function() {
return pie;
};
// data is two-dimensional array of x,y; we populate y0
-// TODO perhaps make the `x`, `y` and `y0` structure customizable
d3.layout.stack = function() {
- var order = "default",
- offset = "zero";
+ var values = Object,
+ order = d3_layout_stackOrders["default"],
+ offset = d3_layout_stackOffsets["zero"],
+ out = d3_layout_stackOut,
+ x = d3_layout_stackX,
+ y = d3_layout_stackY;
+
+ function stack(data, index) {
+
+ // Convert series to canonical two-dimensional representation.
+ var series = data.map(function(d, i) {
+ return values.call(stack, d, i);
+ });
- function stack(data) {
- var n = data.length,
- m = data[0].length,
- i,
- j,
- y0;
+ // Convert each series to canonical [[x,y]] representation.
+ var points = series.map(function(d, i) {
+ return d.map(function(v, i) {
+ return [x.call(stack, v, i), y.call(stack, v, i)];
+ });
+ });
- // compute the order of series
- var index = d3_layout_stackOrders[order](data);
+ // Compute the order of series, and permute them.
+ var orders = order.call(stack, points, index);
+ series = d3.permute(series, orders);
+ points = d3.permute(points, orders);
- // set y0 on the baseline
- d3_layout_stackOffsets[offset](data, index);
+ // Compute the baseline
+ var offsets = offset.call(stack, points, index);
- // propagate offset to other series
+ // And propagate it to other series.
+ var n = series.length,
+ m = series[0].length,
+ i,
+ j,
+ o;
for (j = 0; j < m; ++j) {
- for (i = 1, y0 = data[index[0]][j].y0; i < n; ++i) {
- data[index[i]][j].y0 = y0 += data[index[i - 1]][j].y;
+ out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
+ for (i = 1; i < n; ++i) {
+ out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
}
}
return data;
}
+ stack.values = function(x) {
+ if (!arguments.length) return values;
+ values = x;
+ return stack;
+ };
+
stack.order = function(x) {
if (!arguments.length) return order;
- order = x;
+ order = typeof x === "function" ? x : d3_layout_stackOrders[x];
return stack;
};
stack.offset = function(x) {
if (!arguments.length) return offset;
- offset = x;
+ offset = typeof x === "function" ? x : d3_layout_stackOffsets[x];
+ return stack;
+ };
+
+ stack.x = function(z) {
+ if (!arguments.length) return x;
+ x = z;
+ return stack;
+ };
+
+ stack.y = function(z) {
+ if (!arguments.length) return y;
+ y = z;
+ return stack;
+ };
+
+ stack.out = function(z) {
+ if (!arguments.length) return out;
+ out = z;
return stack;
};
return stack;
}
+function d3_layout_stackX(d) {
+ return d.x;
+}
+
+function d3_layout_stackY(d) {
+ return d.y;
+}
+
+function d3_layout_stackOut(d, y0, y) {
+ d.y0 = y0;
+ d.y = y;
+}
+
var d3_layout_stackOrders = {
"inside-out": function(data) {
@@ -692,7 +747,7 @@ var d3_layout_stackOrders = {
bottom = 0,
tops = [],
bottoms = [];
- for (i = 0; i < n; i++) {
+ for (i = 0; i < n; ++i) {
j = index[i];
if (top < bottom) {
top += sums[j];
@@ -717,101 +772,105 @@ var d3_layout_stackOrders = {
var d3_layout_stackOffsets = {
- "silhouette": function(data, index) {
+ "silhouette": function(data) {
var n = data.length,
m = data[0].length,
sums = [],
max = 0,
i,
j,
- o;
+ o,
+ y0 = [];
for (j = 0; j < m; ++j) {
- for (i = 0, o = 0; i < n; i++) o += data[i][j].y;
+ for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
if (o > max) max = o;
sums.push(o);
}
- for (j = 0, i = index[0]; j < m; ++j) {
- data[i][j].y0 = (max - sums[j]) / 2;
+ for (j = 0; j < m; ++j) {
+ y0[j] = (max - sums[j]) / 2;
}
+ return y0;
},
- "wiggle": function(data, index) {
+ "wiggle": function(data) {
var n = data.length,
x = data[0],
m = x.length,
max = 0,
i,
j,
k,
- ii,
- ik,
- i0 = index[0],
s1,
s2,
s3,
dx,
o,
- o0;
- data[i0][0].y0 = o = o0 = 0;
+ o0,
+ y0 = [];
+ y0[0] = o = o0 = 0;
for (j = 1; j < m; ++j) {
- for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j].y;
- for (i = 0, s2 = 0, dx = x[j].x - x[j - 1].x; i < n; ++i) {
- for (k = 0, ii = index[i], s3 = (data[ii][j].y - data[ii][j - 1].y) / (2 * dx); k < i; ++k) {
- s3 += (data[ik = index[k]][j].y - data[ik][j - 1].y) / dx;
+ for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
+ for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
+ for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
+ s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
}
- s2 += s3 * data[ii][j].y;
+ s2 += s3 * data[i][j][1];
}
- data[i0][j].y0 = o -= s1 ? s2 / s1 * dx : 0;
+ y0[j] = o -= s1 ? s2 / s1 * dx : 0;
if (o < o0) o0 = o;
}
- for (j = 0; j < m; ++j) data[i0][j].y0 -= o0;
+ for (j = 0; j < m; ++j) y0[j] -= o0;
+ return y0;
},
- "expand": function(data, index) {
+ "expand": function(data) {
var n = data.length,
m = data[0].length,
k = 1 / n,
i,
j,
- o;
+ o,
+ y0 = [];
for (j = 0; j < m; ++j) {
- for (i = 0, o = 0; i < n; i++) o += data[i][j].y;
- if (o) for (i = 0; i < n; i++) data[i][j].y /= o;
- else for (i = 0; i < n; i++) data[i][j].y = k;
+ for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
+ if (o) for (i = 0; i < n; i++) data[i][j][1] /= o;
+ else for (i = 0; i < n; i++) data[i][j][1] = k;
}
- for (i = index[0], j = 0; j < m; ++j) data[i][j].y0 = 0;
+ for (j = 0; j < m; ++j) y0[j] = 0;
+ return y0;
},
- "zero": function(data, index) {
- var j = 0,
+ "zero": function(data) {
+ var j = -1,
m = data[0].length,
- i0 = index[0];
- for (; j < m; ++j) data[i0][j].y0 = 0;
+ y0 = [];
+ while (++j < m) y0[j] = 0;
+ return y0;
}
};
-function d3_layout_stackReduceSum(d) {
- return d.reduce(d3_layout_stackSum, 0);
-}
-
function d3_layout_stackMaxIndex(array) {
var i = 1,
j = 0,
- v = array[0].y,
+ v = array[0][1],
k,
n = array.length;
for (; i < n; ++i) {
- if ((k = array[i].y) > v) {
+ if ((k = array[i][1]) > v) {
j = i;
v = k;
}
}
return j;
}
+function d3_layout_stackReduceSum(d) {
+ return d.reduce(d3_layout_stackSum, 0);
+}
+
function d3_layout_stackSum(p, d) {
- return p + d.y;
+ return p + d[1];
}
d3.layout.hierarchy = function() {
var sort = d3_layout_hierarchySort,
Oops, something went wrong.

0 comments on commit 173a936

Please sign in to comment.