diff options
Diffstat (limited to 'media/d3.layout.js')
-rw-r--r-- | media/d3.layout.js | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/media/d3.layout.js b/media/d3.layout.js index 7a776e6d..1e9195f5 100644 --- a/media/d3.layout.js +++ b/media/d3.layout.js @@ -1,5 +1,5 @@ /* d3.layout.js - Data Driven Documents - * Version: 2.7.0 + * Version: 2.4.3 * Homepage: http://mbostock.github.com/d3/ * Copyright: 2010, Michael Bostock * Licence: 3-Clause BSD @@ -146,19 +146,16 @@ d3.layout.chord = function() { k = (2 * Math.PI - padding * n) / k; // Compute the start and end angle for each group and subgroup. - // Note: Opera has a bug reordering object literal properties! x = 0, i = -1; while (++i < n) { x0 = x, j = -1; while (++j < n) { var di = groupIndex[i], - dj = subgroupIndex[di][j], - v = matrix[di][dj], - a0 = x, - a1 = x += v * k; + dj = subgroupIndex[i][j], + v = matrix[di][dj]; subgroups[di + "-" + dj] = { index: di, subindex: dj, - startAngle: a0, - endAngle: a1, + startAngle: x, + endAngle: x += v * k, value: v }; } @@ -189,9 +186,7 @@ d3.layout.chord = function() { function resort() { chords.sort(function(a, b) { - return sortChords( - (a.source.value + a.target.value) / 2, - (b.source.value + b.target.value) / 2); + return sortChords(a.target.value, b.target.value); }); } @@ -351,12 +346,17 @@ d3.layout.force = function() { } } - event.tick({type: "tick", alpha: alpha}); + event.tick.dispatch({type: "tick", alpha: alpha}); // simulated annealing, basically return (alpha *= .99) < .005; } + force.on = function(type, listener) { + event[type].add(listener); + return force; + }; + force.nodes = function(x) { if (!arguments.length) return nodes; nodes = x; @@ -503,7 +503,6 @@ d3.layout.force = function() { // use `node.call(force.drag)` to make nodes draggable force.drag = function() { if (!drag) drag = d3.behavior.drag() - .origin(Object) .on("dragstart", dragstart) .on("drag", d3_layout_forceDrag) .on("dragend", d3_layout_forceDragEnd); @@ -518,7 +517,7 @@ d3.layout.force = function() { d3_layout_forceDragForce = force; } - return d3.rebind(force, event, "on"); + return force; }; var d3_layout_forceDragForce, @@ -539,8 +538,8 @@ function d3_layout_forceDragEnd() { } function d3_layout_forceDrag() { - d3_layout_forceDragNode.px = d3.event.x; - d3_layout_forceDragNode.py = d3.event.y; + d3_layout_forceDragNode.px += d3.event.dx; + d3_layout_forceDragNode.py += d3.event.dy; d3_layout_forceDragForce.resume(); // restart annealing } @@ -634,31 +633,33 @@ d3.layout.partition = function() { }; d3.layout.pie = function() { var value = Number, - sort = d3_layout_pieSortByValue, + sort = null, startAngle = 0, endAngle = 2 * Math.PI; function pie(data, i) { - // Compute the numeric values for each data element. - var values = data.map(function(d, i) { return +value.call(pie, d, i); }); - // Compute the start angle. var a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle); - // Compute the angular scale factor: from value to radians. - var k = ((typeof endAngle === "function" + // Compute the angular range (end - start). + var k = (typeof endAngle === "function" ? endAngle.apply(this, arguments) - : endAngle) - startAngle) - / d3.sum(values); + : endAngle) - startAngle; // Optionally sort the data. var index = d3.range(data.length); - if (sort != null) index.sort(sort === d3_layout_pieSortByValue - ? function(i, j) { return values[j] - values[i]; } - : function(i, j) { return sort(data[i], data[j]); }); + if (sort != null) index.sort(function(i, j) { + return sort(data[i], data[j]); + }); + + // Compute the numeric values for each data element. + var values = data.map(value); + + // Convert k into a scale factor from value to angle, using the sum. + k /= values.reduce(function(p, d) { return p + d; }, 0); // Compute the arcs! var arcs = index.map(function(i) { @@ -725,8 +726,6 @@ d3.layout.pie = function() { return pie; }; - -var d3_layout_pieSortByValue = {}; // data is two-dimensional array of x,y; we populate y0 d3.layout.stack = function() { var values = Object, @@ -1149,10 +1148,10 @@ d3.layout.hierarchy = function() { // A method assignment helper for hierarchy subclasses. function d3_layout_hierarchyRebind(object, hierarchy) { - d3.rebind(object, hierarchy, "sort", "children", "value"); - - // Add an alias for links, for convenience. + object.sort = d3.rebind(object, hierarchy.sort); + object.children = d3.rebind(object, hierarchy.children); object.links = d3_layout_hierarchyLinks; + object.value = d3.rebind(object, hierarchy.value); // If the new API is used, enabling inlining. object.nodes = function(d) { |