mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°5621 Move C3 0.4.11 to NPM
This commit is contained in:
59
node_modules/d3/src/layout/bundle.js
generated
vendored
Normal file
59
node_modules/d3/src/layout/bundle.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import "layout";
|
||||
|
||||
// Implements hierarchical edge bundling using Holten's algorithm. For each
|
||||
// input link, a path is computed that travels through the tree, up the parent
|
||||
// hierarchy to the least common ancestor, and then back down to the destination
|
||||
// node. Each path is simply an array of nodes.
|
||||
d3.layout.bundle = function() {
|
||||
return function(links) {
|
||||
var paths = [],
|
||||
i = -1,
|
||||
n = links.length;
|
||||
while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
|
||||
return paths;
|
||||
};
|
||||
};
|
||||
|
||||
function d3_layout_bundlePath(link) {
|
||||
var start = link.source,
|
||||
end = link.target,
|
||||
lca = d3_layout_bundleLeastCommonAncestor(start, end),
|
||||
points = [start];
|
||||
while (start !== lca) {
|
||||
start = start.parent;
|
||||
points.push(start);
|
||||
}
|
||||
var k = points.length;
|
||||
while (end !== lca) {
|
||||
points.splice(k, 0, end);
|
||||
end = end.parent;
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
function d3_layout_bundleAncestors(node) {
|
||||
var ancestors = [],
|
||||
parent = node.parent;
|
||||
while (parent != null) {
|
||||
ancestors.push(node);
|
||||
node = parent;
|
||||
parent = parent.parent;
|
||||
}
|
||||
ancestors.push(node);
|
||||
return ancestors;
|
||||
}
|
||||
|
||||
function d3_layout_bundleLeastCommonAncestor(a, b) {
|
||||
if (a === b) return a;
|
||||
var aNodes = d3_layout_bundleAncestors(a),
|
||||
bNodes = d3_layout_bundleAncestors(b),
|
||||
aNode = aNodes.pop(),
|
||||
bNode = bNodes.pop(),
|
||||
sharedNode = null;
|
||||
while (aNode === bNode) {
|
||||
sharedNode = aNode;
|
||||
aNode = aNodes.pop();
|
||||
bNode = bNodes.pop();
|
||||
}
|
||||
return sharedNode;
|
||||
}
|
||||
157
node_modules/d3/src/layout/chord.js
generated
vendored
Normal file
157
node_modules/d3/src/layout/chord.js
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
import "../arrays/range";
|
||||
import "../math/trigonometry";
|
||||
import "layout";
|
||||
|
||||
d3.layout.chord = function() {
|
||||
var chord = {},
|
||||
chords,
|
||||
groups,
|
||||
matrix,
|
||||
n,
|
||||
padding = 0,
|
||||
sortGroups,
|
||||
sortSubgroups,
|
||||
sortChords;
|
||||
|
||||
function relayout() {
|
||||
var subgroups = {},
|
||||
groupSums = [],
|
||||
groupIndex = d3.range(n),
|
||||
subgroupIndex = [],
|
||||
k,
|
||||
x,
|
||||
x0,
|
||||
i,
|
||||
j;
|
||||
|
||||
chords = [];
|
||||
groups = [];
|
||||
|
||||
// Compute the sum.
|
||||
k = 0, i = -1; while (++i < n) {
|
||||
x = 0, j = -1; while (++j < n) {
|
||||
x += matrix[i][j];
|
||||
}
|
||||
groupSums.push(x);
|
||||
subgroupIndex.push(d3.range(n));
|
||||
k += x;
|
||||
}
|
||||
|
||||
// Sort groups…
|
||||
if (sortGroups) {
|
||||
groupIndex.sort(function(a, b) {
|
||||
return sortGroups(groupSums[a], groupSums[b]);
|
||||
});
|
||||
}
|
||||
|
||||
// Sort subgroups…
|
||||
if (sortSubgroups) {
|
||||
subgroupIndex.forEach(function(d, i) {
|
||||
d.sort(function(a, b) {
|
||||
return sortSubgroups(matrix[i][a], matrix[i][b]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Convert the sum to scaling factor for [0, 2pi].
|
||||
// TODO Allow start and end angle to be specified.
|
||||
// TODO Allow padding to be specified as percentage?
|
||||
k = (τ - 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;
|
||||
subgroups[di + "-" + dj] = {
|
||||
index: di,
|
||||
subindex: dj,
|
||||
startAngle: a0,
|
||||
endAngle: a1,
|
||||
value: v
|
||||
};
|
||||
}
|
||||
groups[di] = {
|
||||
index: di,
|
||||
startAngle: x0,
|
||||
endAngle: x,
|
||||
value: groupSums[di]
|
||||
};
|
||||
x += padding;
|
||||
}
|
||||
|
||||
// Generate chords for each (non-empty) subgroup-subgroup link.
|
||||
i = -1; while (++i < n) {
|
||||
j = i - 1; while (++j < n) {
|
||||
var source = subgroups[i + "-" + j],
|
||||
target = subgroups[j + "-" + i];
|
||||
if (source.value || target.value) {
|
||||
chords.push(source.value < target.value
|
||||
? {source: target, target: source}
|
||||
: {source: source, target: target});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sortChords) resort();
|
||||
}
|
||||
|
||||
function resort() {
|
||||
chords.sort(function(a, b) {
|
||||
return sortChords(
|
||||
(a.source.value + a.target.value) / 2,
|
||||
(b.source.value + b.target.value) / 2);
|
||||
});
|
||||
}
|
||||
|
||||
chord.matrix = function(x) {
|
||||
if (!arguments.length) return matrix;
|
||||
n = (matrix = x) && matrix.length;
|
||||
chords = groups = null;
|
||||
return chord;
|
||||
};
|
||||
|
||||
chord.padding = function(x) {
|
||||
if (!arguments.length) return padding;
|
||||
padding = x;
|
||||
chords = groups = null;
|
||||
return chord;
|
||||
};
|
||||
|
||||
chord.sortGroups = function(x) {
|
||||
if (!arguments.length) return sortGroups;
|
||||
sortGroups = x;
|
||||
chords = groups = null;
|
||||
return chord;
|
||||
};
|
||||
|
||||
chord.sortSubgroups = function(x) {
|
||||
if (!arguments.length) return sortSubgroups;
|
||||
sortSubgroups = x;
|
||||
chords = null;
|
||||
return chord;
|
||||
};
|
||||
|
||||
chord.sortChords = function(x) {
|
||||
if (!arguments.length) return sortChords;
|
||||
sortChords = x;
|
||||
if (chords) resort();
|
||||
return chord;
|
||||
};
|
||||
|
||||
chord.chords = function() {
|
||||
if (!chords) relayout();
|
||||
return chords;
|
||||
};
|
||||
|
||||
chord.groups = function() {
|
||||
if (!groups) relayout();
|
||||
return groups;
|
||||
};
|
||||
|
||||
return chord;
|
||||
};
|
||||
92
node_modules/d3/src/layout/cluster.js
generated
vendored
Normal file
92
node_modules/d3/src/layout/cluster.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
import "../arrays/max";
|
||||
import "layout";
|
||||
import "hierarchy";
|
||||
import "tree";
|
||||
|
||||
// Implements a hierarchical layout using the cluster (or dendrogram)
|
||||
// algorithm.
|
||||
d3.layout.cluster = function() {
|
||||
var hierarchy = d3.layout.hierarchy().sort(null).value(null),
|
||||
separation = d3_layout_treeSeparation,
|
||||
size = [1, 1], // width, height
|
||||
nodeSize = false;
|
||||
|
||||
function cluster(d, i) {
|
||||
var nodes = hierarchy.call(this, d, i),
|
||||
root = nodes[0],
|
||||
previousNode,
|
||||
x = 0;
|
||||
|
||||
// First walk, computing the initial x & y values.
|
||||
d3_layout_hierarchyVisitAfter(root, function(node) {
|
||||
var children = node.children;
|
||||
if (children && children.length) {
|
||||
node.x = d3_layout_clusterX(children);
|
||||
node.y = d3_layout_clusterY(children);
|
||||
} else {
|
||||
node.x = previousNode ? x += separation(node, previousNode) : 0;
|
||||
node.y = 0;
|
||||
previousNode = node;
|
||||
}
|
||||
});
|
||||
|
||||
// Compute the left-most, right-most, and depth-most nodes for extents.
|
||||
var left = d3_layout_clusterLeft(root),
|
||||
right = d3_layout_clusterRight(root),
|
||||
x0 = left.x - separation(left, right) / 2,
|
||||
x1 = right.x + separation(right, left) / 2;
|
||||
|
||||
// Second walk, normalizing x & y to the desired size.
|
||||
d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
|
||||
node.x = (node.x - root.x) * size[0];
|
||||
node.y = (root.y - node.y) * size[1];
|
||||
} : function(node) {
|
||||
node.x = (node.x - x0) / (x1 - x0) * size[0];
|
||||
node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
|
||||
});
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
cluster.separation = function(x) {
|
||||
if (!arguments.length) return separation;
|
||||
separation = x;
|
||||
return cluster;
|
||||
};
|
||||
|
||||
cluster.size = function(x) {
|
||||
if (!arguments.length) return nodeSize ? null : size;
|
||||
nodeSize = (size = x) == null;
|
||||
return cluster;
|
||||
};
|
||||
|
||||
cluster.nodeSize = function(x) {
|
||||
if (!arguments.length) return nodeSize ? size : null;
|
||||
nodeSize = (size = x) != null;
|
||||
return cluster;
|
||||
};
|
||||
|
||||
return d3_layout_hierarchyRebind(cluster, hierarchy);
|
||||
};
|
||||
|
||||
function d3_layout_clusterY(children) {
|
||||
return 1 + d3.max(children, function(child) {
|
||||
return child.y;
|
||||
});
|
||||
}
|
||||
|
||||
function d3_layout_clusterX(children) {
|
||||
return children.reduce(function(x, child) {
|
||||
return x + child.x;
|
||||
}, 0) / children.length;
|
||||
}
|
||||
|
||||
function d3_layout_clusterLeft(node) {
|
||||
var children = node.children;
|
||||
return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
|
||||
}
|
||||
|
||||
function d3_layout_clusterRight(node) {
|
||||
var children = node.children, n;
|
||||
return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
|
||||
}
|
||||
372
node_modules/d3/src/layout/force.js
generated
vendored
Normal file
372
node_modules/d3/src/layout/force.js
generated
vendored
Normal file
@@ -0,0 +1,372 @@
|
||||
import "../behavior/drag";
|
||||
import "../core/identity";
|
||||
import "../core/rebind";
|
||||
import "../event/event";
|
||||
import "../event/dispatch";
|
||||
import "../event/timer";
|
||||
import "../geom/quadtree";
|
||||
import "layout";
|
||||
|
||||
// A rudimentary force layout using Gauss-Seidel.
|
||||
d3.layout.force = function() {
|
||||
var force = {},
|
||||
event = d3.dispatch("start", "tick", "end"),
|
||||
timer,
|
||||
size = [1, 1],
|
||||
drag,
|
||||
alpha,
|
||||
friction = 0.9,
|
||||
linkDistance = d3_layout_forceLinkDistance,
|
||||
linkStrength = d3_layout_forceLinkStrength,
|
||||
charge = -30,
|
||||
chargeDistance2 = d3_layout_forceChargeDistance2,
|
||||
gravity = 0.1,
|
||||
theta2 = 0.64,
|
||||
nodes = [],
|
||||
links = [],
|
||||
distances,
|
||||
strengths,
|
||||
charges;
|
||||
|
||||
function repulse(node) {
|
||||
return function(quad, x1, _, x2) {
|
||||
if (quad.point !== node) {
|
||||
var dx = quad.cx - node.x,
|
||||
dy = quad.cy - node.y,
|
||||
dw = x2 - x1,
|
||||
dn = dx * dx + dy * dy;
|
||||
|
||||
/* Barnes-Hut criterion. */
|
||||
if (dw * dw / theta2 < dn) {
|
||||
if (dn < chargeDistance2) {
|
||||
var k = quad.charge / dn;
|
||||
node.px -= dx * k;
|
||||
node.py -= dy * k;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (quad.point && dn && dn < chargeDistance2) {
|
||||
var k = quad.pointCharge / dn;
|
||||
node.px -= dx * k;
|
||||
node.py -= dy * k;
|
||||
}
|
||||
}
|
||||
return !quad.charge;
|
||||
};
|
||||
}
|
||||
|
||||
force.tick = function() {
|
||||
// simulated annealing, basically
|
||||
if ((alpha *= 0.99) < 0.005) {
|
||||
timer = null;
|
||||
event.end({type: "end", alpha: alpha = 0});
|
||||
return true;
|
||||
}
|
||||
|
||||
var n = nodes.length,
|
||||
m = links.length,
|
||||
q,
|
||||
i, // current index
|
||||
o, // current object
|
||||
s, // current source
|
||||
t, // current target
|
||||
l, // current distance
|
||||
k, // current force
|
||||
x, // x-distance
|
||||
y; // y-distance
|
||||
|
||||
// gauss-seidel relaxation for links
|
||||
for (i = 0; i < m; ++i) {
|
||||
o = links[i];
|
||||
s = o.source;
|
||||
t = o.target;
|
||||
x = t.x - s.x;
|
||||
y = t.y - s.y;
|
||||
if (l = (x * x + y * y)) {
|
||||
l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
|
||||
x *= l;
|
||||
y *= l;
|
||||
t.x -= x * (k = (s.weight + t.weight ? s.weight / (s.weight + t.weight) : 0.5));
|
||||
t.y -= y * k;
|
||||
s.x += x * (k = 1 - k);
|
||||
s.y += y * k;
|
||||
}
|
||||
}
|
||||
|
||||
// apply gravity forces
|
||||
if (k = alpha * gravity) {
|
||||
x = size[0] / 2;
|
||||
y = size[1] / 2;
|
||||
i = -1; if (k) while (++i < n) {
|
||||
o = nodes[i];
|
||||
o.x += (x - o.x) * k;
|
||||
o.y += (y - o.y) * k;
|
||||
}
|
||||
}
|
||||
|
||||
// compute quadtree center of mass and apply charge forces
|
||||
if (charge) {
|
||||
d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
|
||||
i = -1; while (++i < n) {
|
||||
if (!(o = nodes[i]).fixed) {
|
||||
q.visit(repulse(o));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// position verlet integration
|
||||
i = -1; while (++i < n) {
|
||||
o = nodes[i];
|
||||
if (o.fixed) {
|
||||
o.x = o.px;
|
||||
o.y = o.py;
|
||||
} else {
|
||||
o.x -= (o.px - (o.px = o.x)) * friction;
|
||||
o.y -= (o.py - (o.py = o.y)) * friction;
|
||||
}
|
||||
}
|
||||
|
||||
event.tick({type: "tick", alpha: alpha});
|
||||
};
|
||||
|
||||
force.nodes = function(x) {
|
||||
if (!arguments.length) return nodes;
|
||||
nodes = x;
|
||||
return force;
|
||||
};
|
||||
|
||||
force.links = function(x) {
|
||||
if (!arguments.length) return links;
|
||||
links = x;
|
||||
return force;
|
||||
};
|
||||
|
||||
force.size = function(x) {
|
||||
if (!arguments.length) return size;
|
||||
size = x;
|
||||
return force;
|
||||
};
|
||||
|
||||
force.linkDistance = function(x) {
|
||||
if (!arguments.length) return linkDistance;
|
||||
linkDistance = typeof x === "function" ? x : +x;
|
||||
return force;
|
||||
};
|
||||
|
||||
// For backwards-compatibility.
|
||||
force.distance = force.linkDistance;
|
||||
|
||||
force.linkStrength = function(x) {
|
||||
if (!arguments.length) return linkStrength;
|
||||
linkStrength = typeof x === "function" ? x : +x;
|
||||
return force;
|
||||
};
|
||||
|
||||
force.friction = function(x) {
|
||||
if (!arguments.length) return friction;
|
||||
friction = +x;
|
||||
return force;
|
||||
};
|
||||
|
||||
force.charge = function(x) {
|
||||
if (!arguments.length) return charge;
|
||||
charge = typeof x === "function" ? x : +x;
|
||||
return force;
|
||||
};
|
||||
|
||||
force.chargeDistance = function(x) {
|
||||
if (!arguments.length) return Math.sqrt(chargeDistance2);
|
||||
chargeDistance2 = x * x;
|
||||
return force;
|
||||
};
|
||||
|
||||
force.gravity = function(x) {
|
||||
if (!arguments.length) return gravity;
|
||||
gravity = +x;
|
||||
return force;
|
||||
};
|
||||
|
||||
force.theta = function(x) {
|
||||
if (!arguments.length) return Math.sqrt(theta2);
|
||||
theta2 = x * x;
|
||||
return force;
|
||||
};
|
||||
|
||||
force.alpha = function(x) {
|
||||
if (!arguments.length) return alpha;
|
||||
|
||||
x = +x;
|
||||
if (alpha) { // if we're already running
|
||||
if (x > 0) { // we might keep it hot
|
||||
alpha = x;
|
||||
} else { // or we might stop
|
||||
timer.c = null, timer.t = NaN, timer = null;
|
||||
event.end({type: "end", alpha: alpha = 0});
|
||||
}
|
||||
} else if (x > 0) { // otherwise, fire it up!
|
||||
event.start({type: "start", alpha: alpha = x});
|
||||
timer = d3_timer(force.tick);
|
||||
}
|
||||
|
||||
return force;
|
||||
};
|
||||
|
||||
force.start = function() {
|
||||
var i,
|
||||
n = nodes.length,
|
||||
m = links.length,
|
||||
w = size[0],
|
||||
h = size[1],
|
||||
neighbors,
|
||||
o;
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
(o = nodes[i]).index = i;
|
||||
o.weight = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < m; ++i) {
|
||||
o = links[i];
|
||||
if (typeof o.source == "number") o.source = nodes[o.source];
|
||||
if (typeof o.target == "number") o.target = nodes[o.target];
|
||||
++o.source.weight;
|
||||
++o.target.weight;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
o = nodes[i];
|
||||
if (isNaN(o.x)) o.x = position("x", w);
|
||||
if (isNaN(o.y)) o.y = position("y", h);
|
||||
if (isNaN(o.px)) o.px = o.x;
|
||||
if (isNaN(o.py)) o.py = o.y;
|
||||
}
|
||||
|
||||
distances = [];
|
||||
if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i);
|
||||
else for (i = 0; i < m; ++i) distances[i] = linkDistance;
|
||||
|
||||
strengths = [];
|
||||
if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i);
|
||||
else for (i = 0; i < m; ++i) strengths[i] = linkStrength;
|
||||
|
||||
charges = [];
|
||||
if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i);
|
||||
else for (i = 0; i < n; ++i) charges[i] = charge;
|
||||
|
||||
// inherit node position from first neighbor with defined position
|
||||
// or if no such neighbors, initialize node position randomly
|
||||
// initialize neighbors lazily to avoid overhead when not needed
|
||||
function position(dimension, size) {
|
||||
if (!neighbors) {
|
||||
neighbors = new Array(n);
|
||||
for (j = 0; j < n; ++j) {
|
||||
neighbors[j] = [];
|
||||
}
|
||||
for (j = 0; j < m; ++j) {
|
||||
var o = links[j];
|
||||
neighbors[o.source.index].push(o.target);
|
||||
neighbors[o.target.index].push(o.source);
|
||||
}
|
||||
}
|
||||
var candidates = neighbors[i],
|
||||
j = -1,
|
||||
l = candidates.length,
|
||||
x;
|
||||
while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
|
||||
return Math.random() * size;
|
||||
}
|
||||
|
||||
return force.resume();
|
||||
};
|
||||
|
||||
force.resume = function() {
|
||||
return force.alpha(0.1);
|
||||
};
|
||||
|
||||
force.stop = function() {
|
||||
return force.alpha(0);
|
||||
};
|
||||
|
||||
// use `node.call(force.drag)` to make nodes draggable
|
||||
force.drag = function() {
|
||||
if (!drag) drag = d3.behavior.drag()
|
||||
.origin(d3_identity)
|
||||
.on("dragstart.force", d3_layout_forceDragstart)
|
||||
.on("drag.force", dragmove)
|
||||
.on("dragend.force", d3_layout_forceDragend);
|
||||
|
||||
if (!arguments.length) return drag;
|
||||
|
||||
this.on("mouseover.force", d3_layout_forceMouseover)
|
||||
.on("mouseout.force", d3_layout_forceMouseout)
|
||||
.call(drag);
|
||||
};
|
||||
|
||||
function dragmove(d) {
|
||||
d.px = d3.event.x, d.py = d3.event.y;
|
||||
force.resume(); // restart annealing
|
||||
}
|
||||
|
||||
return d3.rebind(force, event, "on");
|
||||
};
|
||||
|
||||
// The fixed property has three bits:
|
||||
// Bit 1 can be set externally (e.g., d.fixed = true) and show persist.
|
||||
// Bit 2 stores the dragging state, from mousedown to mouseup.
|
||||
// Bit 3 stores the hover state, from mouseover to mouseout.
|
||||
// Dragend is a special case: it also clears the hover state.
|
||||
|
||||
function d3_layout_forceDragstart(d) {
|
||||
d.fixed |= 2; // set bit 2
|
||||
}
|
||||
|
||||
function d3_layout_forceDragend(d) {
|
||||
d.fixed &= ~6; // unset bits 2 and 3
|
||||
}
|
||||
|
||||
function d3_layout_forceMouseover(d) {
|
||||
d.fixed |= 4; // set bit 3
|
||||
d.px = d.x, d.py = d.y; // set velocity to zero
|
||||
}
|
||||
|
||||
function d3_layout_forceMouseout(d) {
|
||||
d.fixed &= ~4; // unset bit 3
|
||||
}
|
||||
|
||||
function d3_layout_forceAccumulate(quad, alpha, charges) {
|
||||
var cx = 0,
|
||||
cy = 0;
|
||||
quad.charge = 0;
|
||||
if (!quad.leaf) {
|
||||
var nodes = quad.nodes,
|
||||
n = nodes.length,
|
||||
i = -1,
|
||||
c;
|
||||
while (++i < n) {
|
||||
c = nodes[i];
|
||||
if (c == null) continue;
|
||||
d3_layout_forceAccumulate(c, alpha, charges);
|
||||
quad.charge += c.charge;
|
||||
cx += c.charge * c.cx;
|
||||
cy += c.charge * c.cy;
|
||||
}
|
||||
}
|
||||
if (quad.point) {
|
||||
// jitter internal nodes that are coincident
|
||||
if (!quad.leaf) {
|
||||
quad.point.x += Math.random() - 0.5;
|
||||
quad.point.y += Math.random() - 0.5;
|
||||
}
|
||||
var k = alpha * charges[quad.point.index];
|
||||
quad.charge += quad.pointCharge = k;
|
||||
cx += k * quad.point.x;
|
||||
cy += k * quad.point.y;
|
||||
}
|
||||
quad.cx = cx / quad.charge;
|
||||
quad.cy = cy / quad.charge;
|
||||
}
|
||||
|
||||
var d3_layout_forceLinkDistance = 20,
|
||||
d3_layout_forceLinkStrength = 1,
|
||||
d3_layout_forceChargeDistance2 = Infinity;
|
||||
136
node_modules/d3/src/layout/hierarchy.js
generated
vendored
Normal file
136
node_modules/d3/src/layout/hierarchy.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
import "../arrays/merge";
|
||||
import "../core/rebind";
|
||||
import "layout";
|
||||
|
||||
d3.layout.hierarchy = function() {
|
||||
var sort = d3_layout_hierarchySort,
|
||||
children = d3_layout_hierarchyChildren,
|
||||
value = d3_layout_hierarchyValue;
|
||||
|
||||
function hierarchy(root) {
|
||||
var stack = [root],
|
||||
nodes = [],
|
||||
node;
|
||||
|
||||
root.depth = 0;
|
||||
|
||||
while ((node = stack.pop()) != null) {
|
||||
nodes.push(node);
|
||||
if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
|
||||
var n, childs, child;
|
||||
while (--n >= 0) {
|
||||
stack.push(child = childs[n]);
|
||||
child.parent = node;
|
||||
child.depth = node.depth + 1;
|
||||
}
|
||||
if (value) node.value = 0;
|
||||
node.children = childs;
|
||||
} else {
|
||||
if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
|
||||
delete node.children;
|
||||
}
|
||||
}
|
||||
|
||||
d3_layout_hierarchyVisitAfter(root, function(node) {
|
||||
var childs, parent;
|
||||
if (sort && (childs = node.children)) childs.sort(sort);
|
||||
if (value && (parent = node.parent)) parent.value += node.value;
|
||||
});
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
hierarchy.sort = function(x) {
|
||||
if (!arguments.length) return sort;
|
||||
sort = x;
|
||||
return hierarchy;
|
||||
};
|
||||
|
||||
hierarchy.children = function(x) {
|
||||
if (!arguments.length) return children;
|
||||
children = x;
|
||||
return hierarchy;
|
||||
};
|
||||
|
||||
hierarchy.value = function(x) {
|
||||
if (!arguments.length) return value;
|
||||
value = x;
|
||||
return hierarchy;
|
||||
};
|
||||
|
||||
// Re-evaluates the `value` property for the specified hierarchy.
|
||||
hierarchy.revalue = function(root) {
|
||||
if (value) {
|
||||
d3_layout_hierarchyVisitBefore(root, function(node) {
|
||||
if (node.children) node.value = 0;
|
||||
});
|
||||
d3_layout_hierarchyVisitAfter(root, function(node) {
|
||||
var parent;
|
||||
if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
|
||||
if (parent = node.parent) parent.value += node.value;
|
||||
});
|
||||
}
|
||||
return root;
|
||||
};
|
||||
|
||||
return hierarchy;
|
||||
};
|
||||
|
||||
// A method assignment helper for hierarchy subclasses.
|
||||
function d3_layout_hierarchyRebind(object, hierarchy) {
|
||||
d3.rebind(object, hierarchy, "sort", "children", "value");
|
||||
|
||||
// Add an alias for nodes and links, for convenience.
|
||||
object.nodes = object;
|
||||
object.links = d3_layout_hierarchyLinks;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
// Pre-order traversal.
|
||||
function d3_layout_hierarchyVisitBefore(node, callback) {
|
||||
var nodes = [node];
|
||||
while ((node = nodes.pop()) != null) {
|
||||
callback(node);
|
||||
if ((children = node.children) && (n = children.length)) {
|
||||
var n, children;
|
||||
while (--n >= 0) nodes.push(children[n]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Post-order traversal.
|
||||
function d3_layout_hierarchyVisitAfter(node, callback) {
|
||||
var nodes = [node], nodes2 = [];
|
||||
while ((node = nodes.pop()) != null) {
|
||||
nodes2.push(node);
|
||||
if ((children = node.children) && (n = children.length)) {
|
||||
var i = -1, n, children;
|
||||
while (++i < n) nodes.push(children[i]);
|
||||
}
|
||||
}
|
||||
while ((node = nodes2.pop()) != null) {
|
||||
callback(node);
|
||||
}
|
||||
}
|
||||
|
||||
function d3_layout_hierarchyChildren(d) {
|
||||
return d.children;
|
||||
}
|
||||
|
||||
function d3_layout_hierarchyValue(d) {
|
||||
return d.value;
|
||||
}
|
||||
|
||||
function d3_layout_hierarchySort(a, b) {
|
||||
return b.value - a.value;
|
||||
}
|
||||
|
||||
// Returns an array source+target objects for the specified nodes.
|
||||
function d3_layout_hierarchyLinks(nodes) {
|
||||
return d3.merge(nodes.map(function(parent) {
|
||||
return (parent.children || []).map(function(child) {
|
||||
return {source: parent, target: child};
|
||||
});
|
||||
}));
|
||||
}
|
||||
110
node_modules/d3/src/layout/histogram.js
generated
vendored
Normal file
110
node_modules/d3/src/layout/histogram.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
import "../arrays/bisect";
|
||||
import "../arrays/min";
|
||||
import "../arrays/max";
|
||||
import "../core/functor";
|
||||
import "layout";
|
||||
|
||||
d3.layout.histogram = function() {
|
||||
var frequency = true,
|
||||
valuer = Number,
|
||||
ranger = d3_layout_histogramRange,
|
||||
binner = d3_layout_histogramBinSturges;
|
||||
|
||||
function histogram(data, i) {
|
||||
var bins = [],
|
||||
values = data.map(valuer, this),
|
||||
range = ranger.call(this, values, i),
|
||||
thresholds = binner.call(this, range, values, i),
|
||||
bin,
|
||||
i = -1,
|
||||
n = values.length,
|
||||
m = thresholds.length - 1,
|
||||
k = frequency ? 1 : 1 / n,
|
||||
x;
|
||||
|
||||
// Initialize the bins.
|
||||
while (++i < m) {
|
||||
bin = bins[i] = [];
|
||||
bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
|
||||
bin.y = 0;
|
||||
}
|
||||
|
||||
// Fill the bins, ignoring values outside the range.
|
||||
if (m > 0) {
|
||||
i = -1; while(++i < n) {
|
||||
x = values[i];
|
||||
if (x >= range[0] && x <= range[1]) {
|
||||
bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
|
||||
bin.y += k;
|
||||
bin.push(data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bins;
|
||||
}
|
||||
|
||||
// Specifies how to extract a value from the associated data. The default
|
||||
// value function is `Number`, which is equivalent to the identity function.
|
||||
histogram.value = function(x) {
|
||||
if (!arguments.length) return valuer;
|
||||
valuer = x;
|
||||
return histogram;
|
||||
};
|
||||
|
||||
// Specifies the range of the histogram. Values outside the specified range
|
||||
// will be ignored. The argument `x` may be specified either as a two-element
|
||||
// array representing the minimum and maximum value of the range, or as a
|
||||
// function that returns the range given the array of values and the current
|
||||
// index `i`. The default range is the extent (minimum and maximum) of the
|
||||
// values.
|
||||
histogram.range = function(x) {
|
||||
if (!arguments.length) return ranger;
|
||||
ranger = d3_functor(x);
|
||||
return histogram;
|
||||
};
|
||||
|
||||
// Specifies how to bin values in the histogram. The argument `x` may be
|
||||
// specified as a number, in which case the range of values will be split
|
||||
// uniformly into the given number of bins. Or, `x` may be an array of
|
||||
// threshold values, defining the bins; the specified array must contain the
|
||||
// rightmost (upper) value, thus specifying n + 1 values for n bins. Or, `x`
|
||||
// may be a function which is evaluated, being passed the range, the array of
|
||||
// values, and the current index `i`, returning an array of thresholds. The
|
||||
// default bin function will divide the values into uniform bins using
|
||||
// Sturges' formula.
|
||||
histogram.bins = function(x) {
|
||||
if (!arguments.length) return binner;
|
||||
binner = typeof x === "number"
|
||||
? function(range) { return d3_layout_histogramBinFixed(range, x); }
|
||||
: d3_functor(x);
|
||||
return histogram;
|
||||
};
|
||||
|
||||
// Specifies whether the histogram's `y` value is a count (frequency) or a
|
||||
// probability (density). The default value is true.
|
||||
histogram.frequency = function(x) {
|
||||
if (!arguments.length) return frequency;
|
||||
frequency = !!x;
|
||||
return histogram;
|
||||
};
|
||||
|
||||
return histogram;
|
||||
};
|
||||
|
||||
function d3_layout_histogramBinSturges(range, values) {
|
||||
return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
|
||||
}
|
||||
|
||||
function d3_layout_histogramBinFixed(range, n) {
|
||||
var x = -1,
|
||||
b = +range[0],
|
||||
m = (range[1] - b) / n,
|
||||
f = [];
|
||||
while (++x <= n) f[x] = m * x + b;
|
||||
return f;
|
||||
}
|
||||
|
||||
function d3_layout_histogramRange(values) {
|
||||
return [d3.min(values), d3.max(values)];
|
||||
}
|
||||
13
node_modules/d3/src/layout/index.js
generated
vendored
Normal file
13
node_modules/d3/src/layout/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import "layout";
|
||||
import "bundle";
|
||||
import "chord";
|
||||
import "force";
|
||||
import "partition";
|
||||
import "pie";
|
||||
import "stack";
|
||||
import "histogram";
|
||||
import "hierarchy";
|
||||
import "pack";
|
||||
import "cluster";
|
||||
import "tree";
|
||||
import "treemap";
|
||||
1
node_modules/d3/src/layout/layout.js
generated
vendored
Normal file
1
node_modules/d3/src/layout/layout.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
d3.layout = {};
|
||||
211
node_modules/d3/src/layout/pack.js
generated
vendored
Normal file
211
node_modules/d3/src/layout/pack.js
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
import "layout";
|
||||
import "hierarchy";
|
||||
|
||||
d3.layout.pack = function() {
|
||||
var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort),
|
||||
padding = 0,
|
||||
size = [1, 1],
|
||||
radius;
|
||||
|
||||
function pack(d, i) {
|
||||
var nodes = hierarchy.call(this, d, i),
|
||||
root = nodes[0],
|
||||
w = size[0],
|
||||
h = size[1],
|
||||
r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() { return radius; };
|
||||
|
||||
// Recursively compute the layout.
|
||||
root.x = root.y = 0;
|
||||
d3_layout_hierarchyVisitAfter(root, function(d) { d.r = +r(d.value); });
|
||||
d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
|
||||
|
||||
// When padding, recompute the layout using scaled padding.
|
||||
if (padding) {
|
||||
var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
|
||||
d3_layout_hierarchyVisitAfter(root, function(d) { d.r += dr; });
|
||||
d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
|
||||
d3_layout_hierarchyVisitAfter(root, function(d) { d.r -= dr; });
|
||||
}
|
||||
|
||||
// Translate and scale the layout to fit the requested size.
|
||||
d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
pack.size = function(_) {
|
||||
if (!arguments.length) return size;
|
||||
size = _;
|
||||
return pack;
|
||||
};
|
||||
|
||||
pack.radius = function(_) {
|
||||
if (!arguments.length) return radius;
|
||||
radius = _ == null || typeof _ === "function" ? _ : +_;
|
||||
return pack;
|
||||
};
|
||||
|
||||
pack.padding = function(_) {
|
||||
if (!arguments.length) return padding;
|
||||
padding = +_;
|
||||
return pack;
|
||||
};
|
||||
|
||||
return d3_layout_hierarchyRebind(pack, hierarchy);
|
||||
};
|
||||
|
||||
function d3_layout_packSort(a, b) {
|
||||
return a.value - b.value;
|
||||
}
|
||||
|
||||
function d3_layout_packInsert(a, b) {
|
||||
var c = a._pack_next;
|
||||
a._pack_next = b;
|
||||
b._pack_prev = a;
|
||||
b._pack_next = c;
|
||||
c._pack_prev = b;
|
||||
}
|
||||
|
||||
function d3_layout_packSplice(a, b) {
|
||||
a._pack_next = b;
|
||||
b._pack_prev = a;
|
||||
}
|
||||
|
||||
function d3_layout_packIntersects(a, b) {
|
||||
var dx = b.x - a.x,
|
||||
dy = b.y - a.y,
|
||||
dr = a.r + b.r;
|
||||
return 0.999 * dr * dr > dx * dx + dy * dy; // relative error within epsilon
|
||||
}
|
||||
|
||||
function d3_layout_packSiblings(node) {
|
||||
if (!(nodes = node.children) || !(n = nodes.length)) return;
|
||||
|
||||
var nodes,
|
||||
xMin = Infinity,
|
||||
xMax = -Infinity,
|
||||
yMin = Infinity,
|
||||
yMax = -Infinity,
|
||||
a, b, c, i, j, k, n;
|
||||
|
||||
function bound(node) {
|
||||
xMin = Math.min(node.x - node.r, xMin);
|
||||
xMax = Math.max(node.x + node.r, xMax);
|
||||
yMin = Math.min(node.y - node.r, yMin);
|
||||
yMax = Math.max(node.y + node.r, yMax);
|
||||
}
|
||||
|
||||
// Create node links.
|
||||
nodes.forEach(d3_layout_packLink);
|
||||
|
||||
// Create first node.
|
||||
a = nodes[0];
|
||||
a.x = -a.r;
|
||||
a.y = 0;
|
||||
bound(a);
|
||||
|
||||
// Create second node.
|
||||
if (n > 1) {
|
||||
b = nodes[1];
|
||||
b.x = b.r;
|
||||
b.y = 0;
|
||||
bound(b);
|
||||
|
||||
// Create third node and build chain.
|
||||
if (n > 2) {
|
||||
c = nodes[2];
|
||||
d3_layout_packPlace(a, b, c);
|
||||
bound(c);
|
||||
d3_layout_packInsert(a, c);
|
||||
a._pack_prev = c;
|
||||
d3_layout_packInsert(c, b);
|
||||
b = a._pack_next;
|
||||
|
||||
// Now iterate through the rest.
|
||||
for (i = 3; i < n; i++) {
|
||||
d3_layout_packPlace(a, b, c = nodes[i]);
|
||||
|
||||
// Search for the closest intersection.
|
||||
var isect = 0, s1 = 1, s2 = 1;
|
||||
for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
|
||||
if (d3_layout_packIntersects(j, c)) {
|
||||
isect = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isect == 1) {
|
||||
for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
|
||||
if (d3_layout_packIntersects(k, c)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update node chain.
|
||||
if (isect) {
|
||||
if (s1 < s2 || (s1 == s2 && b.r < a.r)) d3_layout_packSplice(a, b = j);
|
||||
else d3_layout_packSplice(a = k, b);
|
||||
i--;
|
||||
} else {
|
||||
d3_layout_packInsert(a, c);
|
||||
b = c;
|
||||
bound(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Re-center the circles and compute the encompassing radius.
|
||||
var cx = (xMin + xMax) / 2,
|
||||
cy = (yMin + yMax) / 2,
|
||||
cr = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
c = nodes[i];
|
||||
c.x -= cx;
|
||||
c.y -= cy;
|
||||
cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
|
||||
}
|
||||
node.r = cr;
|
||||
|
||||
// Remove node links.
|
||||
nodes.forEach(d3_layout_packUnlink);
|
||||
}
|
||||
|
||||
function d3_layout_packLink(node) {
|
||||
node._pack_next = node._pack_prev = node;
|
||||
}
|
||||
|
||||
function d3_layout_packUnlink(node) {
|
||||
delete node._pack_next;
|
||||
delete node._pack_prev;
|
||||
}
|
||||
|
||||
function d3_layout_packTransform(node, x, y, k) {
|
||||
var children = node.children;
|
||||
node.x = x += k * node.x;
|
||||
node.y = y += k * node.y;
|
||||
node.r *= k;
|
||||
if (children) {
|
||||
var i = -1, n = children.length;
|
||||
while (++i < n) d3_layout_packTransform(children[i], x, y, k);
|
||||
}
|
||||
}
|
||||
|
||||
function d3_layout_packPlace(a, b, c) {
|
||||
var db = a.r + c.r,
|
||||
dx = b.x - a.x,
|
||||
dy = b.y - a.y;
|
||||
if (db && (dx || dy)) {
|
||||
var da = b.r + c.r,
|
||||
dc = dx * dx + dy * dy;
|
||||
da *= da;
|
||||
db *= db;
|
||||
var x = 0.5 + (db - da) / (2 * dc),
|
||||
y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
|
||||
c.x = a.x + x * dx + y * dy;
|
||||
c.y = a.y + x * dy - y * dx;
|
||||
} else {
|
||||
c.x = a.x + db;
|
||||
c.y = a.y;
|
||||
}
|
||||
}
|
||||
51
node_modules/d3/src/layout/partition.js
generated
vendored
Normal file
51
node_modules/d3/src/layout/partition.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import "layout";
|
||||
import "hierarchy";
|
||||
|
||||
d3.layout.partition = function() {
|
||||
var hierarchy = d3.layout.hierarchy(),
|
||||
size = [1, 1]; // width, height
|
||||
|
||||
function position(node, x, dx, dy) {
|
||||
var children = node.children;
|
||||
node.x = x;
|
||||
node.y = node.depth * dy;
|
||||
node.dx = dx;
|
||||
node.dy = dy;
|
||||
if (children && (n = children.length)) {
|
||||
var i = -1,
|
||||
n,
|
||||
c,
|
||||
d;
|
||||
dx = node.value ? dx / node.value : 0;
|
||||
while (++i < n) {
|
||||
position(c = children[i], x, d = c.value * dx, dy);
|
||||
x += d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function depth(node) {
|
||||
var children = node.children,
|
||||
d = 0;
|
||||
if (children && (n = children.length)) {
|
||||
var i = -1,
|
||||
n;
|
||||
while (++i < n) d = Math.max(d, depth(children[i]));
|
||||
}
|
||||
return 1 + d;
|
||||
}
|
||||
|
||||
function partition(d, i) {
|
||||
var nodes = hierarchy.call(this, d, i);
|
||||
position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
|
||||
return nodes;
|
||||
}
|
||||
|
||||
partition.size = function(x) {
|
||||
if (!arguments.length) return size;
|
||||
size = x;
|
||||
return partition;
|
||||
};
|
||||
|
||||
return d3_layout_hierarchyRebind(partition, hierarchy);
|
||||
};
|
||||
78
node_modules/d3/src/layout/pie.js
generated
vendored
Normal file
78
node_modules/d3/src/layout/pie.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
import "../arrays/range";
|
||||
import "../arrays/sum";
|
||||
import "../math/trigonometry";
|
||||
import "layout";
|
||||
|
||||
d3.layout.pie = function() {
|
||||
var value = Number,
|
||||
sort = d3_layout_pieSortByValue,
|
||||
startAngle = 0,
|
||||
endAngle = τ,
|
||||
padAngle = 0;
|
||||
|
||||
function pie(data) {
|
||||
var n = data.length,
|
||||
values = data.map(function(d, i) { return +value.call(pie, d, i); }),
|
||||
a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle),
|
||||
da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a,
|
||||
p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)),
|
||||
pa = p * (da < 0 ? -1 : 1),
|
||||
sum = d3.sum(values),
|
||||
k = sum ? (da - n * pa) / sum : 0,
|
||||
index = d3.range(n),
|
||||
arcs = [],
|
||||
v;
|
||||
|
||||
// Optionally sort the data.
|
||||
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]); });
|
||||
|
||||
// Compute the arcs! They are stored in the original data's order.
|
||||
index.forEach(function(i) {
|
||||
arcs[i] = {
|
||||
data: data[i],
|
||||
value: v = values[i],
|
||||
startAngle: a,
|
||||
endAngle: a += v * k + pa,
|
||||
padAngle: p
|
||||
};
|
||||
});
|
||||
|
||||
return arcs;
|
||||
}
|
||||
|
||||
pie.value = function(_) {
|
||||
if (!arguments.length) return value;
|
||||
value = _;
|
||||
return pie;
|
||||
};
|
||||
|
||||
pie.sort = function(_) {
|
||||
if (!arguments.length) return sort;
|
||||
sort = _;
|
||||
return pie;
|
||||
};
|
||||
|
||||
pie.startAngle = function(_) {
|
||||
if (!arguments.length) return startAngle;
|
||||
startAngle = _;
|
||||
return pie;
|
||||
};
|
||||
|
||||
pie.endAngle = function(_) {
|
||||
if (!arguments.length) return endAngle;
|
||||
endAngle = _;
|
||||
return pie;
|
||||
};
|
||||
|
||||
pie.padAngle = function(_) {
|
||||
if (!arguments.length) return padAngle;
|
||||
padAngle = _;
|
||||
return pie;
|
||||
};
|
||||
|
||||
return pie;
|
||||
};
|
||||
|
||||
var d3_layout_pieSortByValue = {};
|
||||
247
node_modules/d3/src/layout/stack.js
generated
vendored
Normal file
247
node_modules/d3/src/layout/stack.js
generated
vendored
Normal file
@@ -0,0 +1,247 @@
|
||||
import "../arrays/map";
|
||||
import "../arrays/permute";
|
||||
import "../arrays/range";
|
||||
import "../core/identity";
|
||||
import "layout";
|
||||
|
||||
// data is two-dimensional array of x,y; we populate y0
|
||||
d3.layout.stack = function() {
|
||||
var values = d3_identity,
|
||||
order = d3_layout_stackOrderDefault,
|
||||
offset = d3_layout_stackOffsetZero,
|
||||
out = d3_layout_stackOut,
|
||||
x = d3_layout_stackX,
|
||||
y = d3_layout_stackY;
|
||||
|
||||
function stack(data, index) {
|
||||
if (!(n = data.length)) return data;
|
||||
|
||||
// Convert series to canonical two-dimensional representation.
|
||||
var series = data.map(function(d, i) {
|
||||
return values.call(stack, d, i);
|
||||
});
|
||||
|
||||
// Convert each series to canonical [[x,y]] representation.
|
||||
var points = series.map(function(d) {
|
||||
return d.map(function(v, i) {
|
||||
return [x.call(stack, v, i), y.call(stack, v, i)];
|
||||
});
|
||||
});
|
||||
|
||||
// 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);
|
||||
|
||||
// Compute the baseline…
|
||||
var offsets = offset.call(stack, points, index);
|
||||
|
||||
// And propagate it to other series.
|
||||
var m = series[0].length,
|
||||
n,
|
||||
i,
|
||||
j,
|
||||
o;
|
||||
for (j = 0; j < m; ++j) {
|
||||
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 = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
|
||||
return stack;
|
||||
};
|
||||
|
||||
stack.offset = function(x) {
|
||||
if (!arguments.length) return offset;
|
||||
offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
|
||||
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 = d3.map({
|
||||
|
||||
"inside-out": function(data) {
|
||||
var n = data.length,
|
||||
i,
|
||||
j,
|
||||
max = data.map(d3_layout_stackMaxIndex),
|
||||
sums = data.map(d3_layout_stackReduceSum),
|
||||
index = d3.range(n).sort(function(a, b) { return max[a] - max[b]; }),
|
||||
top = 0,
|
||||
bottom = 0,
|
||||
tops = [],
|
||||
bottoms = [];
|
||||
for (i = 0; i < n; ++i) {
|
||||
j = index[i];
|
||||
if (top < bottom) {
|
||||
top += sums[j];
|
||||
tops.push(j);
|
||||
} else {
|
||||
bottom += sums[j];
|
||||
bottoms.push(j);
|
||||
}
|
||||
}
|
||||
return bottoms.reverse().concat(tops);
|
||||
},
|
||||
|
||||
"reverse": function(data) {
|
||||
return d3.range(data.length).reverse();
|
||||
},
|
||||
|
||||
"default": d3_layout_stackOrderDefault
|
||||
|
||||
});
|
||||
|
||||
var d3_layout_stackOffsets = d3.map({
|
||||
|
||||
"silhouette": function(data) {
|
||||
var n = data.length,
|
||||
m = data[0].length,
|
||||
sums = [],
|
||||
max = 0,
|
||||
i,
|
||||
j,
|
||||
o,
|
||||
y0 = [];
|
||||
for (j = 0; j < m; ++j) {
|
||||
for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
|
||||
if (o > max) max = o;
|
||||
sums.push(o);
|
||||
}
|
||||
for (j = 0; j < m; ++j) {
|
||||
y0[j] = (max - sums[j]) / 2;
|
||||
}
|
||||
return y0;
|
||||
},
|
||||
|
||||
"wiggle": function(data) {
|
||||
var n = data.length,
|
||||
x = data[0],
|
||||
m = x.length,
|
||||
i,
|
||||
j,
|
||||
k,
|
||||
s1,
|
||||
s2,
|
||||
s3,
|
||||
dx,
|
||||
o,
|
||||
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][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[i][j][1];
|
||||
}
|
||||
y0[j] = o -= s1 ? s2 / s1 * dx : 0;
|
||||
if (o < o0) o0 = o;
|
||||
}
|
||||
for (j = 0; j < m; ++j) y0[j] -= o0;
|
||||
return y0;
|
||||
},
|
||||
|
||||
"expand": function(data) {
|
||||
var n = data.length,
|
||||
m = data[0].length,
|
||||
k = 1 / n,
|
||||
i,
|
||||
j,
|
||||
o,
|
||||
y0 = [];
|
||||
for (j = 0; j < m; ++j) {
|
||||
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 (j = 0; j < m; ++j) y0[j] = 0;
|
||||
return y0;
|
||||
},
|
||||
|
||||
"zero": d3_layout_stackOffsetZero
|
||||
|
||||
});
|
||||
|
||||
function d3_layout_stackOrderDefault(data) {
|
||||
return d3.range(data.length);
|
||||
}
|
||||
|
||||
function d3_layout_stackOffsetZero(data) {
|
||||
var j = -1,
|
||||
m = data[0].length,
|
||||
y0 = [];
|
||||
while (++j < m) y0[j] = 0;
|
||||
return y0;
|
||||
}
|
||||
|
||||
function d3_layout_stackMaxIndex(array) {
|
||||
var i = 1,
|
||||
j = 0,
|
||||
v = array[0][1],
|
||||
k,
|
||||
n = array.length;
|
||||
for (; i < n; ++i) {
|
||||
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[1];
|
||||
}
|
||||
240
node_modules/d3/src/layout/tree.js
generated
vendored
Normal file
240
node_modules/d3/src/layout/tree.js
generated
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
import "layout";
|
||||
import "hierarchy";
|
||||
|
||||
// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
|
||||
d3.layout.tree = function() {
|
||||
var hierarchy = d3.layout.hierarchy().sort(null).value(null),
|
||||
separation = d3_layout_treeSeparation,
|
||||
size = [1, 1], // width, height
|
||||
nodeSize = null;
|
||||
|
||||
function tree(d, i) {
|
||||
var nodes = hierarchy.call(this, d, i),
|
||||
root0 = nodes[0],
|
||||
root1 = wrapTree(root0);
|
||||
|
||||
// Compute the layout using Buchheim et al.'s algorithm.
|
||||
d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
|
||||
d3_layout_hierarchyVisitBefore(root1, secondWalk);
|
||||
|
||||
// If a fixed node size is specified, scale x and y.
|
||||
if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode);
|
||||
|
||||
// If a fixed tree size is specified, scale x and y based on the extent.
|
||||
// Compute the left-most, right-most, and depth-most nodes for extents.
|
||||
else {
|
||||
var left = root0,
|
||||
right = root0,
|
||||
bottom = root0;
|
||||
d3_layout_hierarchyVisitBefore(root0, function(node) {
|
||||
if (node.x < left.x) left = node;
|
||||
if (node.x > right.x) right = node;
|
||||
if (node.depth > bottom.depth) bottom = node;
|
||||
});
|
||||
var tx = separation(left, right) / 2 - left.x,
|
||||
kx = size[0] / (right.x + separation(right, left) / 2 + tx),
|
||||
ky = size[1] / (bottom.depth || 1);
|
||||
d3_layout_hierarchyVisitBefore(root0, function(node) {
|
||||
node.x = (node.x + tx) * kx;
|
||||
node.y = node.depth * ky;
|
||||
});
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
function wrapTree(root0) {
|
||||
var root1 = {A: null, children: [root0]},
|
||||
queue = [root1],
|
||||
node1;
|
||||
|
||||
while ((node1 = queue.pop()) != null) {
|
||||
for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
|
||||
queue.push((children[i] = child = {
|
||||
_: children[i], // source node
|
||||
parent: node1,
|
||||
children: (child = children[i].children) && child.slice() || [],
|
||||
A: null, // default ancestor
|
||||
a: null, // ancestor
|
||||
z: 0, // prelim
|
||||
m: 0, // mod
|
||||
c: 0, // change
|
||||
s: 0, // shift
|
||||
t: null, // thread
|
||||
i: i // number
|
||||
}).a = child);
|
||||
}
|
||||
}
|
||||
|
||||
return root1.children[0];
|
||||
}
|
||||
|
||||
// FIRST WALK
|
||||
// Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
|
||||
// applied recursively to the children of v, as well as the function
|
||||
// APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
|
||||
// node v is placed to the midpoint of its outermost children.
|
||||
function firstWalk(v) {
|
||||
var children = v.children,
|
||||
siblings = v.parent.children,
|
||||
w = v.i ? siblings[v.i - 1] : null;
|
||||
if (children.length) {
|
||||
d3_layout_treeShift(v);
|
||||
var midpoint = (children[0].z + children[children.length - 1].z) / 2;
|
||||
if (w) {
|
||||
v.z = w.z + separation(v._, w._);
|
||||
v.m = v.z - midpoint;
|
||||
} else {
|
||||
v.z = midpoint;
|
||||
}
|
||||
} else if (w) {
|
||||
v.z = w.z + separation(v._, w._);
|
||||
}
|
||||
v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
|
||||
}
|
||||
|
||||
// SECOND WALK
|
||||
// Computes all real x-coordinates by summing up the modifiers recursively.
|
||||
function secondWalk(v) {
|
||||
v._.x = v.z + v.parent.m;
|
||||
v.m += v.parent.m;
|
||||
}
|
||||
|
||||
// APPORTION
|
||||
// The core of the algorithm. Here, a new subtree is combined with the
|
||||
// previous subtrees. Threads are used to traverse the inside and outside
|
||||
// contours of the left and right subtree up to the highest common level. The
|
||||
// vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
|
||||
// superscript o means outside and i means inside, the subscript - means left
|
||||
// subtree and + means right subtree. For summing up the modifiers along the
|
||||
// contour, we use respective variables si+, si-, so-, and so+. Whenever two
|
||||
// nodes of the inside contours conflict, we compute the left one of the
|
||||
// greatest uncommon ancestors using the function ANCESTOR and call MOVE
|
||||
// SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
|
||||
// Finally, we add a new thread (if necessary).
|
||||
function apportion(v, w, ancestor) {
|
||||
if (w) {
|
||||
var vip = v,
|
||||
vop = v,
|
||||
vim = w,
|
||||
vom = vip.parent.children[0],
|
||||
sip = vip.m,
|
||||
sop = vop.m,
|
||||
sim = vim.m,
|
||||
som = vom.m,
|
||||
shift;
|
||||
while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
|
||||
vom = d3_layout_treeLeft(vom);
|
||||
vop = d3_layout_treeRight(vop);
|
||||
vop.a = v;
|
||||
shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
|
||||
if (shift > 0) {
|
||||
d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
|
||||
sip += shift;
|
||||
sop += shift;
|
||||
}
|
||||
sim += vim.m;
|
||||
sip += vip.m;
|
||||
som += vom.m;
|
||||
sop += vop.m;
|
||||
}
|
||||
if (vim && !d3_layout_treeRight(vop)) {
|
||||
vop.t = vim;
|
||||
vop.m += sim - sop;
|
||||
}
|
||||
if (vip && !d3_layout_treeLeft(vom)) {
|
||||
vom.t = vip;
|
||||
vom.m += sip - som;
|
||||
ancestor = v;
|
||||
}
|
||||
}
|
||||
return ancestor;
|
||||
}
|
||||
|
||||
function sizeNode(node) {
|
||||
node.x *= size[0];
|
||||
node.y = node.depth * size[1];
|
||||
}
|
||||
|
||||
tree.separation = function(x) {
|
||||
if (!arguments.length) return separation;
|
||||
separation = x;
|
||||
return tree;
|
||||
};
|
||||
|
||||
tree.size = function(x) {
|
||||
if (!arguments.length) return nodeSize ? null : size;
|
||||
nodeSize = (size = x) == null ? sizeNode : null;
|
||||
return tree;
|
||||
};
|
||||
|
||||
tree.nodeSize = function(x) {
|
||||
if (!arguments.length) return nodeSize ? size : null;
|
||||
nodeSize = (size = x) == null ? null : sizeNode;
|
||||
return tree;
|
||||
};
|
||||
|
||||
return d3_layout_hierarchyRebind(tree, hierarchy);
|
||||
};
|
||||
|
||||
function d3_layout_treeSeparation(a, b) {
|
||||
return a.parent == b.parent ? 1 : 2;
|
||||
}
|
||||
|
||||
// function d3_layout_treeSeparationRadial(a, b) {
|
||||
// return (a.parent == b.parent ? 1 : 2) / a.depth;
|
||||
// }
|
||||
|
||||
// NEXT LEFT
|
||||
// This function is used to traverse the left contour of a subtree (or
|
||||
// subforest). It returns the successor of v on this contour. This successor is
|
||||
// either given by the leftmost child of v or by the thread of v. The function
|
||||
// returns null if and only if v is on the highest level of its subtree.
|
||||
function d3_layout_treeLeft(v) {
|
||||
var children = v.children;
|
||||
return children.length ? children[0] : v.t;
|
||||
}
|
||||
|
||||
// NEXT RIGHT
|
||||
// This function works analogously to NEXT LEFT.
|
||||
function d3_layout_treeRight(v) {
|
||||
var children = v.children, n;
|
||||
return (n = children.length) ? children[n - 1] : v.t;
|
||||
}
|
||||
|
||||
// MOVE SUBTREE
|
||||
// Shifts the current subtree rooted at w+. This is done by increasing
|
||||
// prelim(w+) and mod(w+) by shift.
|
||||
function d3_layout_treeMove(wm, wp, shift) {
|
||||
var change = shift / (wp.i - wm.i);
|
||||
wp.c -= change;
|
||||
wp.s += shift;
|
||||
wm.c += change;
|
||||
wp.z += shift;
|
||||
wp.m += shift;
|
||||
}
|
||||
|
||||
// EXECUTE SHIFTS
|
||||
// All other shifts, applied to the smaller subtrees between w- and w+, are
|
||||
// performed by this function. To prepare the shifts, we have to adjust
|
||||
// change(w+), shift(w+), and change(w-).
|
||||
function d3_layout_treeShift(v) {
|
||||
var shift = 0,
|
||||
change = 0,
|
||||
children = v.children,
|
||||
i = children.length,
|
||||
w;
|
||||
while (--i >= 0) {
|
||||
w = children[i];
|
||||
w.z += shift;
|
||||
w.m += shift;
|
||||
shift += w.s + (change += w.c);
|
||||
}
|
||||
}
|
||||
|
||||
// ANCESTOR
|
||||
// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
|
||||
// returns the specified (default) ancestor.
|
||||
function d3_layout_treeAncestor(vim, v, ancestor) {
|
||||
return vim.a.parent === v.parent ? vim.a : ancestor;
|
||||
}
|
||||
229
node_modules/d3/src/layout/treemap.js
generated
vendored
Normal file
229
node_modules/d3/src/layout/treemap.js
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
import "layout";
|
||||
import "hierarchy";
|
||||
|
||||
// Squarified Treemaps by Mark Bruls, Kees Huizing, and Jarke J. van Wijk
|
||||
// Modified to support a target aspect ratio by Jeff Heer
|
||||
d3.layout.treemap = function() {
|
||||
var hierarchy = d3.layout.hierarchy(),
|
||||
round = Math.round,
|
||||
size = [1, 1], // width, height
|
||||
padding = null,
|
||||
pad = d3_layout_treemapPadNull,
|
||||
sticky = false,
|
||||
stickies,
|
||||
mode = "squarify",
|
||||
ratio = 0.5 * (1 + Math.sqrt(5)); // golden ratio
|
||||
|
||||
// Compute the area for each child based on value & scale.
|
||||
function scale(children, k) {
|
||||
var i = -1,
|
||||
n = children.length,
|
||||
child,
|
||||
area;
|
||||
while (++i < n) {
|
||||
area = (child = children[i]).value * (k < 0 ? 0 : k);
|
||||
child.area = isNaN(area) || area <= 0 ? 0 : area;
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively arranges the specified node's children into squarified rows.
|
||||
function squarify(node) {
|
||||
var children = node.children;
|
||||
if (children && children.length) {
|
||||
var rect = pad(node),
|
||||
row = [],
|
||||
remaining = children.slice(), // copy-on-write
|
||||
child,
|
||||
best = Infinity, // the best row score so far
|
||||
score, // the current row score
|
||||
u = mode === "slice" ? rect.dx
|
||||
: mode === "dice" ? rect.dy
|
||||
: mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx
|
||||
: Math.min(rect.dx, rect.dy), // initial orientation
|
||||
n;
|
||||
scale(remaining, rect.dx * rect.dy / node.value);
|
||||
row.area = 0;
|
||||
while ((n = remaining.length) > 0) {
|
||||
row.push(child = remaining[n - 1]);
|
||||
row.area += child.area;
|
||||
if (mode !== "squarify" || (score = worst(row, u)) <= best) { // continue with this orientation
|
||||
remaining.pop();
|
||||
best = score;
|
||||
} else { // abort, and try a different orientation
|
||||
row.area -= row.pop().area;
|
||||
position(row, u, rect, false);
|
||||
u = Math.min(rect.dx, rect.dy);
|
||||
row.length = row.area = 0;
|
||||
best = Infinity;
|
||||
}
|
||||
}
|
||||
if (row.length) {
|
||||
position(row, u, rect, true);
|
||||
row.length = row.area = 0;
|
||||
}
|
||||
children.forEach(squarify);
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively resizes the specified node's children into existing rows.
|
||||
// Preserves the existing layout!
|
||||
function stickify(node) {
|
||||
var children = node.children;
|
||||
if (children && children.length) {
|
||||
var rect = pad(node),
|
||||
remaining = children.slice(), // copy-on-write
|
||||
child,
|
||||
row = [];
|
||||
scale(remaining, rect.dx * rect.dy / node.value);
|
||||
row.area = 0;
|
||||
while (child = remaining.pop()) {
|
||||
row.push(child);
|
||||
row.area += child.area;
|
||||
if (child.z != null) {
|
||||
position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
|
||||
row.length = row.area = 0;
|
||||
}
|
||||
}
|
||||
children.forEach(stickify);
|
||||
}
|
||||
}
|
||||
|
||||
// Computes the score for the specified row, as the worst aspect ratio.
|
||||
function worst(row, u) {
|
||||
var s = row.area,
|
||||
r,
|
||||
rmax = 0,
|
||||
rmin = Infinity,
|
||||
i = -1,
|
||||
n = row.length;
|
||||
while (++i < n) {
|
||||
if (!(r = row[i].area)) continue;
|
||||
if (r < rmin) rmin = r;
|
||||
if (r > rmax) rmax = r;
|
||||
}
|
||||
s *= s;
|
||||
u *= u;
|
||||
return s
|
||||
? Math.max((u * rmax * ratio) / s, s / (u * rmin * ratio))
|
||||
: Infinity;
|
||||
}
|
||||
|
||||
// Positions the specified row of nodes. Modifies `rect`.
|
||||
function position(row, u, rect, flush) {
|
||||
var i = -1,
|
||||
n = row.length,
|
||||
x = rect.x,
|
||||
y = rect.y,
|
||||
v = u ? round(row.area / u) : 0,
|
||||
o;
|
||||
if (u == rect.dx) { // horizontal subdivision
|
||||
if (flush || v > rect.dy) v = rect.dy; // over+underflow
|
||||
while (++i < n) {
|
||||
o = row[i];
|
||||
o.x = x;
|
||||
o.y = y;
|
||||
o.dy = v;
|
||||
x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
|
||||
}
|
||||
o.z = true;
|
||||
o.dx += rect.x + rect.dx - x; // rounding error
|
||||
rect.y += v;
|
||||
rect.dy -= v;
|
||||
} else { // vertical subdivision
|
||||
if (flush || v > rect.dx) v = rect.dx; // over+underflow
|
||||
while (++i < n) {
|
||||
o = row[i];
|
||||
o.x = x;
|
||||
o.y = y;
|
||||
o.dx = v;
|
||||
y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
|
||||
}
|
||||
o.z = false;
|
||||
o.dy += rect.y + rect.dy - y; // rounding error
|
||||
rect.x += v;
|
||||
rect.dx -= v;
|
||||
}
|
||||
}
|
||||
|
||||
function treemap(d) {
|
||||
var nodes = stickies || hierarchy(d),
|
||||
root = nodes[0];
|
||||
root.x = root.y = 0;
|
||||
if (root.value) root.dx = size[0], root.dy = size[1];
|
||||
else root.dx = root.dy = 0;
|
||||
if (stickies) hierarchy.revalue(root);
|
||||
scale([root], root.dx * root.dy / root.value);
|
||||
(stickies ? stickify : squarify)(root);
|
||||
if (sticky) stickies = nodes;
|
||||
return nodes;
|
||||
}
|
||||
|
||||
treemap.size = function(x) {
|
||||
if (!arguments.length) return size;
|
||||
size = x;
|
||||
return treemap;
|
||||
};
|
||||
|
||||
treemap.padding = function(x) {
|
||||
if (!arguments.length) return padding;
|
||||
|
||||
function padFunction(node) {
|
||||
var p = x.call(treemap, node, node.depth);
|
||||
return p == null
|
||||
? d3_layout_treemapPadNull(node)
|
||||
: d3_layout_treemapPad(node, typeof p === "number" ? [p, p, p, p] : p);
|
||||
}
|
||||
|
||||
function padConstant(node) {
|
||||
return d3_layout_treemapPad(node, x);
|
||||
}
|
||||
|
||||
var type;
|
||||
pad = (padding = x) == null ? d3_layout_treemapPadNull
|
||||
: (type = typeof x) === "function" ? padFunction
|
||||
: type === "number" ? (x = [x, x, x, x], padConstant)
|
||||
: padConstant;
|
||||
return treemap;
|
||||
};
|
||||
|
||||
treemap.round = function(x) {
|
||||
if (!arguments.length) return round != Number;
|
||||
round = x ? Math.round : Number;
|
||||
return treemap;
|
||||
};
|
||||
|
||||
treemap.sticky = function(x) {
|
||||
if (!arguments.length) return sticky;
|
||||
sticky = x;
|
||||
stickies = null;
|
||||
return treemap;
|
||||
};
|
||||
|
||||
treemap.ratio = function(x) {
|
||||
if (!arguments.length) return ratio;
|
||||
ratio = x;
|
||||
return treemap;
|
||||
};
|
||||
|
||||
treemap.mode = function(x) {
|
||||
if (!arguments.length) return mode;
|
||||
mode = x + "";
|
||||
return treemap;
|
||||
};
|
||||
|
||||
return d3_layout_hierarchyRebind(treemap, hierarchy);
|
||||
};
|
||||
|
||||
function d3_layout_treemapPadNull(node) {
|
||||
return {x: node.x, y: node.y, dx: node.dx, dy: node.dy};
|
||||
}
|
||||
|
||||
function d3_layout_treemapPad(node, padding) {
|
||||
var x = node.x + padding[3],
|
||||
y = node.y + padding[0],
|
||||
dx = node.dx - padding[1] - padding[3],
|
||||
dy = node.dy - padding[0] - padding[2];
|
||||
if (dx < 0) { x += dx / 2; dx = 0; }
|
||||
if (dy < 0) { y += dy / 2; dy = 0; }
|
||||
return {x: x, y: y, dx: dx, dy: dy};
|
||||
}
|
||||
Reference in New Issue
Block a user