Spaces:
Paused
Paused
Upload folder using huggingface_hub (part 12)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/d3-geo-projection/src/vanDerGrinten3.js +30 -0
- node_modules/d3-geo-projection/src/vanDerGrinten4.js +61 -0
- node_modules/d3-geo-projection/src/wagner.js +98 -0
- node_modules/d3-geo-projection/src/wagner4.js +13 -0
- node_modules/d3-geo-projection/src/wagner6.js +15 -0
- node_modules/d3-geo-projection/src/wagner7.js +28 -0
- node_modules/d3-geo-projection/src/wiechel.js +34 -0
- node_modules/d3-geo-projection/src/winkel3.js +45 -0
- node_modules/d3-hierarchy/LICENSE +27 -0
- node_modules/d3-hierarchy/README.md +548 -0
- node_modules/d3-hierarchy/dist/d3-hierarchy.js +1290 -0
- node_modules/d3-hierarchy/dist/d3-hierarchy.min.js +2 -0
- node_modules/d3-hierarchy/package.json +50 -0
- node_modules/d3-hierarchy/src/accessors.js +8 -0
- node_modules/d3-hierarchy/src/array.js +16 -0
- node_modules/d3-hierarchy/src/cluster.js +84 -0
- node_modules/d3-hierarchy/src/constant.js +9 -0
- node_modules/d3-hierarchy/src/hierarchy/ancestors.js +7 -0
- node_modules/d3-hierarchy/src/hierarchy/count.js +12 -0
- node_modules/d3-hierarchy/src/hierarchy/descendants.js +7 -0
- node_modules/d3-hierarchy/src/hierarchy/each.js +13 -0
- node_modules/d3-hierarchy/src/hierarchy/eachAfter.js +13 -0
- node_modules/d3-hierarchy/src/hierarchy/eachBefore.js +10 -0
- node_modules/d3-hierarchy/src/hierarchy/index.js +79 -0
- node_modules/d3-hierarchy/src/hierarchy/leaves.js +9 -0
- node_modules/d3-hierarchy/src/hierarchy/links.js +9 -0
- node_modules/d3-hierarchy/src/hierarchy/path.js +30 -0
- node_modules/d3-hierarchy/src/hierarchy/sort.js +7 -0
- node_modules/d3-hierarchy/src/hierarchy/sum.js +9 -0
- node_modules/d3-hierarchy/src/index.js +15 -0
- node_modules/d3-hierarchy/src/pack/enclose.js +118 -0
- node_modules/d3-hierarchy/src/pack/index.js +79 -0
- node_modules/d3-hierarchy/src/pack/siblings.js +118 -0
- node_modules/d3-hierarchy/src/partition.js +52 -0
- node_modules/d3-hierarchy/src/stratify.js +73 -0
- node_modules/d3-hierarchy/src/tree.js +237 -0
- node_modules/d3-hierarchy/src/treemap/binary.js +46 -0
- node_modules/d3-hierarchy/src/treemap/dice.js +12 -0
- node_modules/d3-hierarchy/src/treemap/index.js +94 -0
- node_modules/d3-hierarchy/src/treemap/resquarify.js +36 -0
- node_modules/d3-hierarchy/src/treemap/round.js +6 -0
- node_modules/d3-hierarchy/src/treemap/slice.js +12 -0
- node_modules/d3-hierarchy/src/treemap/sliceDice.js +6 -0
- node_modules/d3-hierarchy/src/treemap/squarify.js +66 -0
- node_modules/d3-interpolate/LICENSE +13 -0
- node_modules/d3-interpolate/README.md +268 -0
- node_modules/d3-interpolate/dist/d3-interpolate.js +590 -0
- node_modules/d3-interpolate/dist/d3-interpolate.min.js +2 -0
- node_modules/d3-interpolate/package.json +53 -0
- node_modules/d3-interpolate/src/array.js +22 -0
node_modules/d3-geo-projection/src/vanDerGrinten3.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {geoProjection as projection} from "d3-geo";
|
| 2 |
+
import {abs, asin, atan, cos, epsilon, halfPi, pi, sign, sin, sqrt, tan} from "./math.js";
|
| 3 |
+
|
| 4 |
+
export function vanDerGrinten3Raw(lambda, phi) {
|
| 5 |
+
if (abs(phi) < epsilon) return [lambda, 0];
|
| 6 |
+
var sinTheta = phi / halfPi,
|
| 7 |
+
theta = asin(sinTheta);
|
| 8 |
+
if (abs(lambda) < epsilon || abs(abs(phi) - halfPi) < epsilon) return [0, pi * tan(theta / 2)];
|
| 9 |
+
var A = (pi / lambda - lambda / pi) / 2,
|
| 10 |
+
y1 = sinTheta / (1 + cos(theta));
|
| 11 |
+
return [
|
| 12 |
+
pi * (sign(lambda) * sqrt(A * A + 1 - y1 * y1) - A),
|
| 13 |
+
pi * y1
|
| 14 |
+
];
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
vanDerGrinten3Raw.invert = function(x, y) {
|
| 18 |
+
if (!y) return [x, 0];
|
| 19 |
+
var y1 = y / pi,
|
| 20 |
+
A = (pi * pi * (1 - y1 * y1) - x * x) / (2 * pi * x);
|
| 21 |
+
return [
|
| 22 |
+
x ? pi * (sign(x) * sqrt(A * A + 1) - A) : 0,
|
| 23 |
+
halfPi * sin(2 * atan(y1))
|
| 24 |
+
];
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
export default function() {
|
| 28 |
+
return projection(vanDerGrinten3Raw)
|
| 29 |
+
.scale(79.4183);
|
| 30 |
+
}
|
node_modules/d3-geo-projection/src/vanDerGrinten4.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {geoProjection as projection} from "d3-geo";
|
| 2 |
+
import {abs, epsilon, halfPi, pi, sign, sqrt} from "./math.js";
|
| 3 |
+
|
| 4 |
+
export function vanDerGrinten4Raw(lambda, phi) {
|
| 5 |
+
if (!phi) return [lambda, 0];
|
| 6 |
+
var phi0 = abs(phi);
|
| 7 |
+
if (!lambda || phi0 === halfPi) return [0, phi];
|
| 8 |
+
var B = phi0 / halfPi,
|
| 9 |
+
B2 = B * B,
|
| 10 |
+
C = (8 * B - B2 * (B2 + 2) - 5) / (2 * B2 * (B - 1)),
|
| 11 |
+
C2 = C * C,
|
| 12 |
+
BC = B * C,
|
| 13 |
+
B_C2 = B2 + C2 + 2 * BC,
|
| 14 |
+
B_3C = B + 3 * C,
|
| 15 |
+
lambda0 = lambda / halfPi,
|
| 16 |
+
lambda1 = lambda0 + 1 / lambda0,
|
| 17 |
+
D = sign(abs(lambda) - halfPi) * sqrt(lambda1 * lambda1 - 4),
|
| 18 |
+
D2 = D * D,
|
| 19 |
+
F = B_C2 * (B2 + C2 * D2 - 1) + (1 - B2) * (B2 * (B_3C * B_3C + 4 * C2) + 12 * BC * C2 + 4 * C2 * C2),
|
| 20 |
+
x1 = (D * (B_C2 + C2 - 1) + 2 * sqrt(F)) / (4 * B_C2 + D2);
|
| 21 |
+
return [
|
| 22 |
+
sign(lambda) * halfPi * x1,
|
| 23 |
+
sign(phi) * halfPi * sqrt(1 + D * abs(x1) - x1 * x1)
|
| 24 |
+
];
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
vanDerGrinten4Raw.invert = function(x, y) {
|
| 28 |
+
var delta;
|
| 29 |
+
if (!x || !y) return [x, y];
|
| 30 |
+
y /= pi;
|
| 31 |
+
var x1 = sign(x) * x / halfPi,
|
| 32 |
+
D = (x1 * x1 - 1 + 4 * y * y) / abs(x1),
|
| 33 |
+
D2 = D * D,
|
| 34 |
+
B = 2 * y,
|
| 35 |
+
i = 50;
|
| 36 |
+
do {
|
| 37 |
+
var B2 = B * B,
|
| 38 |
+
C = (8 * B - B2 * (B2 + 2) - 5) / (2 * B2 * (B - 1)),
|
| 39 |
+
C_ = (3 * B - B2 * B - 10) / (2 * B2 * B),
|
| 40 |
+
C2 = C * C,
|
| 41 |
+
BC = B * C,
|
| 42 |
+
B_C = B + C,
|
| 43 |
+
B_C2 = B_C * B_C,
|
| 44 |
+
B_3C = B + 3 * C,
|
| 45 |
+
F = B_C2 * (B2 + C2 * D2 - 1) + (1 - B2) * (B2 * (B_3C * B_3C + 4 * C2) + C2 * (12 * BC + 4 * C2)),
|
| 46 |
+
F_ = -2 * B_C * (4 * BC * C2 + (1 - 4 * B2 + 3 * B2 * B2) * (1 + C_) + C2 * (-6 + 14 * B2 - D2 + (-8 + 8 * B2 - 2 * D2) * C_) + BC * (-8 + 12 * B2 + (-10 + 10 * B2 - D2) * C_)),
|
| 47 |
+
sqrtF = sqrt(F),
|
| 48 |
+
f = D * (B_C2 + C2 - 1) + 2 * sqrtF - x1 * (4 * B_C2 + D2),
|
| 49 |
+
f_ = D * (2 * C * C_ + 2 * B_C * (1 + C_)) + F_ / sqrtF - 8 * B_C * (D * (-1 + C2 + B_C2) + 2 * sqrtF) * (1 + C_) / (D2 + 4 * B_C2);
|
| 50 |
+
B -= delta = f / f_;
|
| 51 |
+
} while (delta > epsilon && --i > 0);
|
| 52 |
+
return [
|
| 53 |
+
sign(x) * (sqrt(D * D + 4) + D) * pi / 4,
|
| 54 |
+
halfPi * B
|
| 55 |
+
];
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
export default function() {
|
| 59 |
+
return projection(vanDerGrinten4Raw)
|
| 60 |
+
.scale(127.16);
|
| 61 |
+
}
|
node_modules/d3-geo-projection/src/wagner.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {geoProjectionMutator as projectionMutator} from "d3-geo";
|
| 2 |
+
import {acos, asin, atan2, cos, degrees, epsilon, halfPi, max, min, pi, radians, sin, sqrt, tan} from "./math.js";
|
| 3 |
+
|
| 4 |
+
function wagnerFormula(cx, cy, m1, m2, n) {
|
| 5 |
+
function forward(lambda, phi) {
|
| 6 |
+
var s = m1 * sin(m2 * phi),
|
| 7 |
+
c0 = sqrt(1 - s * s),
|
| 8 |
+
c1 = sqrt(2 / (1 + c0 * cos(lambda *= n)));
|
| 9 |
+
return [
|
| 10 |
+
cx * c0 * c1 * sin(lambda),
|
| 11 |
+
cy * s * c1
|
| 12 |
+
];
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
forward.invert = function(x, y) {
|
| 16 |
+
var t1 = x / cx,
|
| 17 |
+
t2 = y / cy,
|
| 18 |
+
p = sqrt(t1 * t1 + t2 * t2),
|
| 19 |
+
c = 2 * asin(p / 2);
|
| 20 |
+
return [
|
| 21 |
+
atan2(x * tan(c), cx * p) / n,
|
| 22 |
+
p && asin(y * sin(c) / (cy * m1 * p)) / m2
|
| 23 |
+
];
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
return forward;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export function wagnerRaw(poleline, parallels, inflation, ratio) {
|
| 30 |
+
// 60 is always used as reference parallel
|
| 31 |
+
var phi1 = pi / 3;
|
| 32 |
+
|
| 33 |
+
// sanitizing the input values
|
| 34 |
+
// poleline and parallels may approximate but never equal 0
|
| 35 |
+
poleline = max(poleline, epsilon);
|
| 36 |
+
parallels = max(parallels, epsilon);
|
| 37 |
+
// poleline must be <= 90; parallels may approximate but never equal 180
|
| 38 |
+
poleline = min(poleline, halfPi);
|
| 39 |
+
parallels = min(parallels, pi - epsilon);
|
| 40 |
+
// 0 <= inflation <= 99.999
|
| 41 |
+
inflation = max(inflation, 0);
|
| 42 |
+
inflation = min(inflation, 100 - epsilon);
|
| 43 |
+
// ratio > 0.
|
| 44 |
+
// sensible values, i.e. something that renders a map which still can be
|
| 45 |
+
// recognized as world map, are e.g. 20 <= ratio <= 1000.
|
| 46 |
+
ratio = max(ratio, epsilon);
|
| 47 |
+
|
| 48 |
+
// convert values from boehm notation
|
| 49 |
+
// areal inflation e.g. from 0 to 1 or 20 to 1.2:
|
| 50 |
+
var vinflation = inflation/100 + 1;
|
| 51 |
+
// axial ratio e.g. from 200 to 2:
|
| 52 |
+
var vratio = ratio / 100;
|
| 53 |
+
// the other ones are a bit more complicated...
|
| 54 |
+
var m2 = acos(vinflation * cos(phi1)) / phi1,
|
| 55 |
+
m1 = sin(poleline) / sin(m2 * halfPi),
|
| 56 |
+
n = parallels / pi,
|
| 57 |
+
k = sqrt(vratio * sin(poleline / 2) / sin(parallels / 2)),
|
| 58 |
+
cx = k / sqrt(n * m1 * m2),
|
| 59 |
+
cy = 1 / (k * sqrt(n * m1 * m2));
|
| 60 |
+
|
| 61 |
+
return wagnerFormula(cx, cy, m1, m2, n);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
export default function wagner() {
|
| 65 |
+
// default values generate wagner8
|
| 66 |
+
var poleline = 65 * radians,
|
| 67 |
+
parallels = 60 * radians,
|
| 68 |
+
inflation = 20,
|
| 69 |
+
ratio = 200,
|
| 70 |
+
mutate = projectionMutator(wagnerRaw),
|
| 71 |
+
projection = mutate(poleline, parallels, inflation, ratio);
|
| 72 |
+
|
| 73 |
+
projection.poleline = function(_) {
|
| 74 |
+
return arguments.length ? mutate(poleline = +_ * radians, parallels, inflation, ratio) : poleline * degrees;
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
projection.parallels = function(_) {
|
| 78 |
+
return arguments.length ? mutate(poleline, parallels = +_ * radians, inflation, ratio) : parallels * degrees;
|
| 79 |
+
};
|
| 80 |
+
projection.inflation = function(_) {
|
| 81 |
+
return arguments.length ? mutate(poleline, parallels, inflation = +_, ratio) : inflation;
|
| 82 |
+
};
|
| 83 |
+
projection.ratio = function(_) {
|
| 84 |
+
return arguments.length ? mutate(poleline, parallels, inflation, ratio = +_) : ratio;
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
return projection
|
| 88 |
+
.scale(163.775);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
export function wagner7() {
|
| 92 |
+
return wagner()
|
| 93 |
+
.poleline(65)
|
| 94 |
+
.parallels(60)
|
| 95 |
+
.inflation(0)
|
| 96 |
+
.ratio(200)
|
| 97 |
+
.scale(172.633);
|
| 98 |
+
}
|
node_modules/d3-geo-projection/src/wagner4.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {geoProjection as projection} from "d3-geo";
|
| 2 |
+
import {sqrt, pi} from "./math.js";
|
| 3 |
+
import {mollweideBromleyRaw} from "./mollweide.js";
|
| 4 |
+
|
| 5 |
+
var A = 4 * pi + 3 * sqrt(3),
|
| 6 |
+
B = 2 * sqrt(2 * pi * sqrt(3) / A);
|
| 7 |
+
|
| 8 |
+
export var wagner4Raw = mollweideBromleyRaw(B * sqrt(3) / pi, B, A / 6);
|
| 9 |
+
|
| 10 |
+
export default function() {
|
| 11 |
+
return projection(wagner4Raw)
|
| 12 |
+
.scale(176.84);
|
| 13 |
+
}
|
node_modules/d3-geo-projection/src/wagner6.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {geoProjection as projection} from "d3-geo";
|
| 2 |
+
import {pi, sqrt} from "./math.js";
|
| 3 |
+
|
| 4 |
+
export function wagner6Raw(lambda, phi) {
|
| 5 |
+
return [lambda * sqrt(1 - 3 * phi * phi / (pi * pi)), phi];
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
wagner6Raw.invert = function(x, y) {
|
| 9 |
+
return [x / sqrt(1 - 3 * y * y / (pi * pi)), y];
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
export default function() {
|
| 13 |
+
return projection(wagner6Raw)
|
| 14 |
+
.scale(152.63);
|
| 15 |
+
}
|
node_modules/d3-geo-projection/src/wagner7.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {geoProjection as projection} from "d3-geo";
|
| 2 |
+
import {asin, atan2, cos, sin, sqrt, tan} from "./math.js";
|
| 3 |
+
|
| 4 |
+
export function wagner7Raw(lambda, phi) {
|
| 5 |
+
var s = 0.90631 * sin(phi),
|
| 6 |
+
c0 = sqrt(1 - s * s),
|
| 7 |
+
c1 = sqrt(2 / (1 + c0 * cos(lambda /= 3)));
|
| 8 |
+
return [
|
| 9 |
+
2.66723 * c0 * c1 * sin(lambda),
|
| 10 |
+
1.24104 * s * c1
|
| 11 |
+
];
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
wagner7Raw.invert = function(x, y) {
|
| 15 |
+
var t1 = x / 2.66723,
|
| 16 |
+
t2 = y / 1.24104,
|
| 17 |
+
p = sqrt(t1 * t1 + t2 * t2),
|
| 18 |
+
c = 2 * asin(p / 2);
|
| 19 |
+
return [
|
| 20 |
+
3 * atan2(x * tan(c), 2.66723 * p),
|
| 21 |
+
p && asin(y * sin(c) / (1.24104 * 0.90631 * p))
|
| 22 |
+
];
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
export default function() {
|
| 26 |
+
return projection(wagner7Raw)
|
| 27 |
+
.scale(172.632);
|
| 28 |
+
}
|
node_modules/d3-geo-projection/src/wiechel.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {geoProjection as projection} from "d3-geo";
|
| 2 |
+
import {asin, atan2, cos, sin, sqrt} from "./math.js";
|
| 3 |
+
|
| 4 |
+
export function wiechelRaw(lambda, phi) {
|
| 5 |
+
var cosPhi = cos(phi),
|
| 6 |
+
sinPhi = cos(lambda) * cosPhi,
|
| 7 |
+
sin1_Phi = 1 - sinPhi,
|
| 8 |
+
cosLambda = cos(lambda = atan2(sin(lambda) * cosPhi, -sin(phi))),
|
| 9 |
+
sinLambda = sin(lambda);
|
| 10 |
+
cosPhi = sqrt(1 - sinPhi * sinPhi);
|
| 11 |
+
return [
|
| 12 |
+
sinLambda * cosPhi - cosLambda * sin1_Phi,
|
| 13 |
+
-cosLambda * cosPhi - sinLambda * sin1_Phi
|
| 14 |
+
];
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
wiechelRaw.invert = function(x, y) {
|
| 18 |
+
var w = (x * x + y * y) / -2,
|
| 19 |
+
k = sqrt(-w * (2 + w)),
|
| 20 |
+
b = y * w + x * k,
|
| 21 |
+
a = x * w - y * k,
|
| 22 |
+
D = sqrt(a * a + b * b);
|
| 23 |
+
return [
|
| 24 |
+
atan2(k * b, D * (1 + w)),
|
| 25 |
+
D ? -asin(k * a / D) : 0
|
| 26 |
+
];
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
export default function() {
|
| 30 |
+
return projection(wiechelRaw)
|
| 31 |
+
.rotate([0, -90, 45])
|
| 32 |
+
.scale(124.75)
|
| 33 |
+
.clipAngle(180 - 1e-3);
|
| 34 |
+
}
|
node_modules/d3-geo-projection/src/winkel3.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {geoProjection as projection} from "d3-geo";
|
| 2 |
+
import {aitoffRaw} from "./aitoff.js";
|
| 3 |
+
import {halfPi, epsilon, sin, cos, sqrt, abs, acos} from "./math.js";
|
| 4 |
+
|
| 5 |
+
export function winkel3Raw(lambda, phi) {
|
| 6 |
+
var coordinates = aitoffRaw(lambda, phi);
|
| 7 |
+
return [
|
| 8 |
+
(coordinates[0] + lambda / halfPi) / 2,
|
| 9 |
+
(coordinates[1] + phi) / 2
|
| 10 |
+
];
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
winkel3Raw.invert = function(x, y) {
|
| 14 |
+
var lambda = x, phi = y, i = 25;
|
| 15 |
+
do {
|
| 16 |
+
var cosphi = cos(phi),
|
| 17 |
+
sinphi = sin(phi),
|
| 18 |
+
sin_2phi = sin(2 * phi),
|
| 19 |
+
sin2phi = sinphi * sinphi,
|
| 20 |
+
cos2phi = cosphi * cosphi,
|
| 21 |
+
sinlambda = sin(lambda),
|
| 22 |
+
coslambda_2 = cos(lambda / 2),
|
| 23 |
+
sinlambda_2 = sin(lambda / 2),
|
| 24 |
+
sin2lambda_2 = sinlambda_2 * sinlambda_2,
|
| 25 |
+
C = 1 - cos2phi * coslambda_2 * coslambda_2,
|
| 26 |
+
E = C ? acos(cosphi * coslambda_2) * sqrt(F = 1 / C) : F = 0,
|
| 27 |
+
F,
|
| 28 |
+
fx = 0.5 * (2 * E * cosphi * sinlambda_2 + lambda / halfPi) - x,
|
| 29 |
+
fy = 0.5 * (E * sinphi + phi) - y,
|
| 30 |
+
dxdlambda = 0.5 * F * (cos2phi * sin2lambda_2 + E * cosphi * coslambda_2 * sin2phi) + 0.5 / halfPi,
|
| 31 |
+
dxdphi = F * (sinlambda * sin_2phi / 4 - E * sinphi * sinlambda_2),
|
| 32 |
+
dydlambda = 0.125 * F * (sin_2phi * sinlambda_2 - E * sinphi * cos2phi * sinlambda),
|
| 33 |
+
dydphi = 0.5 * F * (sin2phi * coslambda_2 + E * sin2lambda_2 * cosphi) + 0.5,
|
| 34 |
+
denominator = dxdphi * dydlambda - dydphi * dxdlambda,
|
| 35 |
+
dlambda = (fy * dxdphi - fx * dydphi) / denominator,
|
| 36 |
+
dphi = (fx * dydlambda - fy * dxdlambda) / denominator;
|
| 37 |
+
lambda -= dlambda, phi -= dphi;
|
| 38 |
+
} while ((abs(dlambda) > epsilon || abs(dphi) > epsilon) && --i > 0);
|
| 39 |
+
return [lambda, phi];
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
export default function() {
|
| 43 |
+
return projection(winkel3Raw)
|
| 44 |
+
.scale(158.837);
|
| 45 |
+
}
|
node_modules/d3-hierarchy/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2010-2016 Mike Bostock
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without modification,
|
| 5 |
+
are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 8 |
+
list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 11 |
+
this list of conditions and the following disclaimer in the documentation
|
| 12 |
+
and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
* Neither the name of the author nor the names of contributors may be used to
|
| 15 |
+
endorse or promote products derived from this software without specific prior
|
| 16 |
+
written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 19 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 20 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 21 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
| 22 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 23 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 24 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
| 25 |
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 26 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 27 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
node_modules/d3-hierarchy/README.md
ADDED
|
@@ -0,0 +1,548 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# d3-hierarchy
|
| 2 |
+
|
| 3 |
+
Many datasets are intrinsically hierarchical. Consider [geographic entities](https://www.census.gov/geo/reference/hierarchy.html), such as census blocks, census tracts, counties and states; the command structure of businesses and governments; file systems and software packages. And even non-hierarchical data may be arranged empirically into a hierarchy, as with [*k*-means clustering](https://en.wikipedia.org/wiki/K-means_clustering) or [phylogenetic trees](https://observablehq.com/@mbostock/tree-of-life).
|
| 4 |
+
|
| 5 |
+
This module implements several popular techniques for visualizing hierarchical data:
|
| 6 |
+
|
| 7 |
+
**Node-link diagrams** show topology using discrete marks for nodes and links, such as a circle for each node and a line connecting each parent and child. The [“tidy” tree](#tree) is delightfully compact, while the [dendrogram](#cluster) places leaves at the same level. (These have both polar and Cartesian forms.) [Indented trees](https://bl.ocks.org/mbostock/1093025) are useful for interactive browsing.
|
| 8 |
+
|
| 9 |
+
**Adjacency diagrams** show topology through the relative placement of nodes. They may also encode a quantitative dimension in the area of each node, for example to show revenue or file size. The [“icicle” diagram](#partition) uses rectangles, while the “sunburst” uses annular segments.
|
| 10 |
+
|
| 11 |
+
**Enclosure diagrams** also use an area encoding, but show topology through containment. A [treemap](#treemap) recursively subdivides area into rectangles. [Circle-packing](#pack) tightly nests circles; this is not as space-efficient as a treemap, but perhaps more readily shows topology.
|
| 12 |
+
|
| 13 |
+
A good hierarchical visualization facilitates rapid multiscale inference: micro-observations of individual elements and macro-observations of large groups.
|
| 14 |
+
|
| 15 |
+
## Installing
|
| 16 |
+
|
| 17 |
+
If you use NPM, `npm install d3-hierarchy`. Otherwise, download the [latest release](https://github.com/d3/d3-hierarchy/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-hierarchy.v1.min.js) or as part of [D3](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
|
| 18 |
+
|
| 19 |
+
```html
|
| 20 |
+
<script src="https://d3js.org/d3-hierarchy.v1.min.js"></script>
|
| 21 |
+
<script>
|
| 22 |
+
|
| 23 |
+
var treemap = d3.treemap();
|
| 24 |
+
|
| 25 |
+
</script>
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
## API Reference
|
| 29 |
+
|
| 30 |
+
* [Hierarchy](#hierarchy) ([Stratify](#stratify))
|
| 31 |
+
* [Cluster](#cluster)
|
| 32 |
+
* [Tree](#tree)
|
| 33 |
+
* [Treemap](#treemap) ([Treemap Tiling](#treemap-tiling))
|
| 34 |
+
* [Partition](#partition)
|
| 35 |
+
* [Pack](#pack)
|
| 36 |
+
|
| 37 |
+
### Hierarchy
|
| 38 |
+
|
| 39 |
+
Before you can compute a hierarchical layout, you need a root node. If your data is already in a hierarchical format, such as JSON, you can pass it directly to [d3.hierarchy](#hierarchy); otherwise, you can rearrange tabular data, such as comma-separated values (CSV), into a hierarchy using [d3.stratify](#stratify).
|
| 40 |
+
|
| 41 |
+
<a name="hierarchy" href="#hierarchy">#</a> d3.<b>hierarchy</b>(<i>data</i>[, <i>children</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/index.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
|
| 42 |
+
|
| 43 |
+
Constructs a root node from the specified hierarchical *data*. The specified *data* must be an object representing the root node. For example:
|
| 44 |
+
|
| 45 |
+
```json
|
| 46 |
+
{
|
| 47 |
+
"name": "Eve",
|
| 48 |
+
"children": [
|
| 49 |
+
{
|
| 50 |
+
"name": "Cain"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"name": "Seth",
|
| 54 |
+
"children": [
|
| 55 |
+
{
|
| 56 |
+
"name": "Enos"
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"name": "Noam"
|
| 60 |
+
}
|
| 61 |
+
]
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"name": "Abel"
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"name": "Awan",
|
| 68 |
+
"children": [
|
| 69 |
+
{
|
| 70 |
+
"name": "Enoch"
|
| 71 |
+
}
|
| 72 |
+
]
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"name": "Azura"
|
| 76 |
+
}
|
| 77 |
+
]
|
| 78 |
+
}
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
The specified *children* accessor function is invoked for each datum, starting with the root *data*, and must return an array of data representing the children, or null if the current datum has no children. If *children* is not specified, it defaults to:
|
| 82 |
+
|
| 83 |
+
```js
|
| 84 |
+
function children(d) {
|
| 85 |
+
return d.children;
|
| 86 |
+
}
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
The returned node and each descendant has the following properties:
|
| 90 |
+
|
| 91 |
+
* *node*.data - the associated data, as specified to the [constructor](#hierarchy).
|
| 92 |
+
* *node*.depth - zero for the root node, and increasing by one for each descendant generation.
|
| 93 |
+
* *node*.height - zero for leaf nodes, and the greatest distance from any descendant leaf for internal nodes.
|
| 94 |
+
* *node*.parent - the parent node, or null for the root node.
|
| 95 |
+
* *node*.children - an array of child nodes, if any; undefined for leaf nodes.
|
| 96 |
+
* *node*.value - the summed value of the node and its [descendants](#node_descendants); optional, see [*node*.sum](#node_sum) and [*node*.count](#node_count).
|
| 97 |
+
|
| 98 |
+
This method can also be used to test if a node is an `instanceof d3.hierarchy` and to extend the node prototype.
|
| 99 |
+
|
| 100 |
+
<a name="node_ancestors" href="#node_ancestors">#</a> <i>node</i>.<b>ancestors</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/ancestors.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
|
| 101 |
+
|
| 102 |
+
Returns the array of ancestors nodes, starting with this node, then followed by each parent up to the root.
|
| 103 |
+
|
| 104 |
+
<a name="node_descendants" href="#node_descendants">#</a> <i>node</i>.<b>descendants</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/descendants.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
|
| 105 |
+
|
| 106 |
+
Returns the array of descendant nodes, starting with this node, then followed by each child in topological order.
|
| 107 |
+
|
| 108 |
+
<a name="node_leaves" href="#node_leaves">#</a> <i>node</i>.<b>leaves</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/leaves.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
|
| 109 |
+
|
| 110 |
+
Returns the array of leaf nodes in traversal order; leaves are nodes with no children.
|
| 111 |
+
|
| 112 |
+
<a name="node_path" href="#node_path">#</a> <i>node</i>.<b>path</b>(<i>target</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/path.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
|
| 113 |
+
|
| 114 |
+
Returns the shortest path through the hierarchy from this *node* to the specified *target* node. The path starts at this *node*, ascends to the least common ancestor of this *node* and the *target* node, and then descends to the *target* node. This is particularly useful for [hierarchical edge bundling](https://observablehq.com/@d3/hierarchical-edge-bundling).
|
| 115 |
+
|
| 116 |
+
<a name="node_links" href="#node_links">#</a> <i>node</i>.<b>links</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/links.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
|
| 117 |
+
|
| 118 |
+
Returns an array of links for this *node*, where each *link* is an object that defines source and target properties. The source of each link is the parent node, and the target is a child node.
|
| 119 |
+
|
| 120 |
+
<a name="node_sum" href="#node_sum">#</a> <i>node</i>.<b>sum</b>(<i>value</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/sum.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
|
| 121 |
+
|
| 122 |
+
Evaluates the specified *value* function for this *node* and each descendant in [post-order traversal](#node_eachAfter), and returns this *node*. The *node*.value property of each node is set to the numeric value returned by the specified function plus the combined value of all children. The function is passed the node’s data, and must return a non-negative number. The *value* accessor is evaluated for *node* and every descendant, including internal nodes; if you only want leaf nodes to have internal value, then return zero for any node with children. [For example](https://observablehq.com/@d3/treemap-by-count), as an alternative to [*node*.count](#node_count):
|
| 123 |
+
|
| 124 |
+
```js
|
| 125 |
+
root.sum(function(d) { return d.value ? 1 : 0; });
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
You must call *node*.sum or [*node*.count](#node_count) before invoking a hierarchical layout that requires *node*.value, such as [d3.treemap](#treemap). Since the API supports [method chaining](https://en.wikipedia.org/wiki/Method_chaining), you can invoke *node*.sum and [*node*.sort](#node_sort) before computing the layout, and then subsequently generate an array of all [descendant nodes](#node_descendants) like so:
|
| 129 |
+
|
| 130 |
+
```js
|
| 131 |
+
var treemap = d3.treemap()
|
| 132 |
+
.size([width, height])
|
| 133 |
+
.padding(2);
|
| 134 |
+
|
| 135 |
+
var nodes = treemap(root
|
| 136 |
+
.sum(function(d) { return d.value; })
|
| 137 |
+
.sort(function(a, b) { return b.height - a.height || b.value - a.value; }))
|
| 138 |
+
.descendants();
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
This example assumes that the node data has a value field.
|
| 142 |
+
|
| 143 |
+
<a name="node_count" href="#node_count">#</a> <i>node</i>.<b>count</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/count.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
|
| 144 |
+
|
| 145 |
+
Computes the number of leaves under this *node* and assigns it to *node*.value, and similarly for every descendant of *node*. If this *node* is a leaf, its count is one. Returns this *node*. See also [*node*.sum](#node_sum).
|
| 146 |
+
|
| 147 |
+
<a name="node_sort" href="#node_sort">#</a> <i>node</i>.<b>sort</b>(<i>compare</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/sort.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
|
| 148 |
+
|
| 149 |
+
Sorts the children of this *node*, if any, and each of this *node*’s descendants’ children, in [pre-order traversal](#node_eachBefore) using the specified *compare* function, and returns this *node*. The specified function is passed two nodes *a* and *b* to compare. If *a* should be before *b*, the function must return a value less than zero; if *b* should be before *a*, the function must return a value greater than zero; otherwise, the relative order of *a* and *b* are not specified. See [*array*.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) for more.
|
| 150 |
+
|
| 151 |
+
Unlike [*node*.sum](#node_sum), the *compare* function is passed two [nodes](#hierarchy) rather than two nodes’ data. For example, if the data has a value property, this sorts nodes by the descending aggregate value of the node and all its descendants, as is recommended for [circle-packing](#pack):
|
| 152 |
+
|
| 153 |
+
```js
|
| 154 |
+
root
|
| 155 |
+
.sum(function(d) { return d.value; })
|
| 156 |
+
.sort(function(a, b) { return b.value - a.value; });
|
| 157 |
+
``````
|
| 158 |
+
|
| 159 |
+
Similarly, to sort nodes by descending height (greatest distance from any descendant leaf) and then descending value, as is recommended for [treemaps](#treemap) and [icicles](#partition):
|
| 160 |
+
|
| 161 |
+
```js
|
| 162 |
+
root
|
| 163 |
+
.sum(function(d) { return d.value; })
|
| 164 |
+
.sort(function(a, b) { return b.height - a.height || b.value - a.value; });
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
To sort nodes by descending height and then ascending id, as is recommended for [trees](#tree) and [dendrograms](#cluster):
|
| 168 |
+
|
| 169 |
+
```js
|
| 170 |
+
root
|
| 171 |
+
.sum(function(d) { return d.value; })
|
| 172 |
+
.sort(function(a, b) { return b.height - a.height || a.id.localeCompare(b.id); });
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
You must call *node*.sort before invoking a hierarchical layout if you want the new sort order to affect the layout; see [*node*.sum](#node_sum) for an example.
|
| 176 |
+
|
| 177 |
+
<a name="node_each" href="#node_each">#</a> <i>node</i>.<b>each</b>(<i>function</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/each.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
|
| 178 |
+
|
| 179 |
+
Invokes the specified *function* for *node* and each descendant in [breadth-first order](https://en.wikipedia.org/wiki/Breadth-first_search), such that a given *node* is only visited if all nodes of lesser depth have already been visited, as well as all preceding nodes of the same depth. The specified function is passed the current *node*.
|
| 180 |
+
|
| 181 |
+
<a name="node_eachAfter" href="#node_eachAfter">#</a> <i>node</i>.<b>eachAfter</b>(<i>function</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/eachAfter.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
|
| 182 |
+
|
| 183 |
+
Invokes the specified *function* for *node* and each descendant in [post-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#Post-order), such that a given *node* is only visited after all of its descendants have already been visited. The specified function is passed the current *node*.
|
| 184 |
+
|
| 185 |
+
<a name="node_eachBefore" href="#node_eachBefore">#</a> <i>node</i>.<b>eachBefore</b>(<i>function</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/eachBefore.js), [Examples](https://observablehq.com/@d3/visiting-a-d3-hierarchy)
|
| 186 |
+
|
| 187 |
+
Invokes the specified *function* for *node* and each descendant in [pre-order traversal](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order), such that a given *node* is only visited after all of its ancestors have already been visited. The specified function is passed the current *node*.
|
| 188 |
+
|
| 189 |
+
<a name="node_copy" href="#node_copy">#</a> <i>node</i>.<b>copy</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/hierarchy/index.js), [Examples](https://observablehq.com/@d3/d3-hierarchy)
|
| 190 |
+
|
| 191 |
+
Return a deep copy of the subtree starting at this *node*. (The returned deep copy shares the same data, however.) The returned node is the root of a new tree; the returned node’s parent is always null and its depth is always zero.
|
| 192 |
+
|
| 193 |
+
#### Stratify
|
| 194 |
+
|
| 195 |
+
Consider the following table of relationships:
|
| 196 |
+
|
| 197 |
+
Name | Parent
|
| 198 |
+
------|--------
|
| 199 |
+
Eve |
|
| 200 |
+
Cain | Eve
|
| 201 |
+
Seth | Eve
|
| 202 |
+
Enos | Seth
|
| 203 |
+
Noam | Seth
|
| 204 |
+
Abel | Eve
|
| 205 |
+
Awan | Eve
|
| 206 |
+
Enoch | Awan
|
| 207 |
+
Azura | Eve
|
| 208 |
+
|
| 209 |
+
These names are conveniently unique, so we can unambiguously represent the hierarchy as a CSV file:
|
| 210 |
+
|
| 211 |
+
```
|
| 212 |
+
name,parent
|
| 213 |
+
Eve,
|
| 214 |
+
Cain,Eve
|
| 215 |
+
Seth,Eve
|
| 216 |
+
Enos,Seth
|
| 217 |
+
Noam,Seth
|
| 218 |
+
Abel,Eve
|
| 219 |
+
Awan,Eve
|
| 220 |
+
Enoch,Awan
|
| 221 |
+
Azura,Eve
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
To parse the CSV using [d3.csvParse](https://github.com/d3/d3-dsv#csvParse):
|
| 225 |
+
|
| 226 |
+
```js
|
| 227 |
+
var table = d3.csvParse(text);
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
This returns:
|
| 231 |
+
|
| 232 |
+
```json
|
| 233 |
+
[
|
| 234 |
+
{"name": "Eve", "parent": ""},
|
| 235 |
+
{"name": "Cain", "parent": "Eve"},
|
| 236 |
+
{"name": "Seth", "parent": "Eve"},
|
| 237 |
+
{"name": "Enos", "parent": "Seth"},
|
| 238 |
+
{"name": "Noam", "parent": "Seth"},
|
| 239 |
+
{"name": "Abel", "parent": "Eve"},
|
| 240 |
+
{"name": "Awan", "parent": "Eve"},
|
| 241 |
+
{"name": "Enoch", "parent": "Awan"},
|
| 242 |
+
{"name": "Azura", "parent": "Eve"}
|
| 243 |
+
]
|
| 244 |
+
```
|
| 245 |
+
|
| 246 |
+
To convert to a hierarchy:
|
| 247 |
+
|
| 248 |
+
```js
|
| 249 |
+
var root = d3.stratify()
|
| 250 |
+
.id(function(d) { return d.name; })
|
| 251 |
+
.parentId(function(d) { return d.parent; })
|
| 252 |
+
(table);
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
This returns:
|
| 256 |
+
|
| 257 |
+
[<img alt="Stratify" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/stratify.png">](https://runkit.com/mbostock/56fed33d8630b01300f72daa)
|
| 258 |
+
|
| 259 |
+
This hierarchy can now be passed to a hierarchical layout, such as [d3.tree](#_tree), for visualization.
|
| 260 |
+
|
| 261 |
+
<a name="stratify" href="#stratify">#</a> d3.<b>stratify</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
|
| 262 |
+
|
| 263 |
+
Constructs a new stratify operator with the default settings.
|
| 264 |
+
|
| 265 |
+
<a name="_stratify" href="#_stratify">#</a> <i>stratify</i>(<i>data</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
|
| 266 |
+
|
| 267 |
+
Generates a new hierarchy from the specified tabular *data*.
|
| 268 |
+
|
| 269 |
+
<a name="stratify_id" href="#stratify_id">#</a> <i>stratify</i>.<b>id</b>([<i>id</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
|
| 270 |
+
|
| 271 |
+
If *id* is specified, sets the id accessor to the given function and returns this stratify operator. Otherwise, returns the current id accessor, which defaults to:
|
| 272 |
+
|
| 273 |
+
```js
|
| 274 |
+
function id(d) {
|
| 275 |
+
return d.id;
|
| 276 |
+
}
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
The id accessor is invoked for each element in the input data passed to the [stratify operator](#_stratify), being passed the current datum (*d*) and the current index (*i*). The returned string is then used to identify the node’s relationships in conjunction with the [parent id](#stratify_parentId). For leaf nodes, the id may be undefined; otherwise, the id must be unique. (Null and the empty string are equivalent to undefined.)
|
| 280 |
+
|
| 281 |
+
<a name="stratify_parentId" href="#stratify_parentId">#</a> <i>stratify</i>.<b>parentId</b>([<i>parentId</i>]) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/stratify.js), [Examples](https://observablehq.com/@d3/d3-stratify)
|
| 282 |
+
|
| 283 |
+
If *parentId* is specified, sets the parent id accessor to the given function and returns this stratify operator. Otherwise, returns the current parent id accessor, which defaults to:
|
| 284 |
+
|
| 285 |
+
```js
|
| 286 |
+
function parentId(d) {
|
| 287 |
+
return d.parentId;
|
| 288 |
+
}
|
| 289 |
+
```
|
| 290 |
+
|
| 291 |
+
The parent id accessor is invoked for each element in the input data passed to the [stratify operator](#_stratify), being passed the current datum (*d*) and the current index (*i*). The returned string is then used to identify the node’s relationships in conjunction with the [id](#stratify_id). For the root node, the parent id should be undefined. (Null and the empty string are equivalent to undefined.) There must be exactly one root node in the input data, and no circular relationships.
|
| 292 |
+
|
| 293 |
+
### Cluster
|
| 294 |
+
|
| 295 |
+
[<img alt="Dendrogram" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/cluster.png">](https://observablehq.com/@d3/cluster-dendrogram)
|
| 296 |
+
|
| 297 |
+
The **cluster layout** produces [dendrograms](http://en.wikipedia.org/wiki/Dendrogram): node-link diagrams that place leaf nodes of the tree at the same depth. Dendrograms are typically less compact than [tidy trees](#tree), but are useful when all the leaves should be at the same level, such as for hierarchical clustering or [phylogenetic tree diagrams](https://observablehq.com/@mbostock/tree-of-life).
|
| 298 |
+
|
| 299 |
+
<a name="cluster" href="#cluster">#</a> d3.<b>cluster</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/cluster.js), [Examples](https://observablehq.com/@d3/cluster-dendrogram)
|
| 300 |
+
|
| 301 |
+
Creates a new cluster layout with default settings.
|
| 302 |
+
|
| 303 |
+
<a name="_cluster" href="#_cluster">#</a> <i>cluster</i>(<i>root</i>)
|
| 304 |
+
|
| 305 |
+
Lays out the specified *root* [hierarchy](#hierarchy), assigning the following properties on *root* and its descendants:
|
| 306 |
+
|
| 307 |
+
* *node*.x - the *x*-coordinate of the node
|
| 308 |
+
* *node*.y - the *y*-coordinate of the node
|
| 309 |
+
|
| 310 |
+
The coordinates *x* and *y* represent an arbitrary coordinate system; for example, you can treat *x* as an angle and *y* as a radius to produce a [radial layout](https://observablehq.com/@d3/radial-dendrogram). You may want to call [*root*.sort](#node_sort) before passing the hierarchy to the cluster layout.
|
| 311 |
+
|
| 312 |
+
<a name="cluster_size" href="#cluster_size">#</a> <i>cluster</i>.<b>size</b>([<i>size</i>])
|
| 313 |
+
|
| 314 |
+
If *size* is specified, sets this cluster layout’s size to the specified two-element array of numbers [*width*, *height*] and returns this cluster layout. If *size* is not specified, returns the current layout size, which defaults to [1, 1]. A layout size of null indicates that a [node size](#cluster_nodeSize) will be used instead. The coordinates *x* and *y* represent an arbitrary coordinate system; for example, to produce a [radial layout](https://observablehq.com/@d3/radial-dendrogram), a size of [360, *radius*] corresponds to a breadth of 360° and a depth of *radius*.
|
| 315 |
+
|
| 316 |
+
<a name="cluster_nodeSize" href="#cluster_nodeSize">#</a> <i>cluster</i>.<b>nodeSize</b>([<i>size</i>])
|
| 317 |
+
|
| 318 |
+
If *size* is specified, sets this cluster layout’s node size to the specified two-element array of numbers [*width*, *height*] and returns this cluster layout. If *size* is not specified, returns the current node size, which defaults to null. A node size of null indicates that a [layout size](#cluster_size) will be used instead. When a node size is specified, the root node is always positioned at ⟨0, 0⟩.
|
| 319 |
+
|
| 320 |
+
<a name="cluster_separation" href="#cluster_separation">#</a> <i>cluster</i>.<b>separation</b>([<i>separation</i>])
|
| 321 |
+
|
| 322 |
+
If *separation* is specified, sets the separation accessor to the specified function and returns this cluster layout. If *separation* is not specified, returns the current separation accessor, which defaults to:
|
| 323 |
+
|
| 324 |
+
```js
|
| 325 |
+
function separation(a, b) {
|
| 326 |
+
return a.parent == b.parent ? 1 : 2;
|
| 327 |
+
}
|
| 328 |
+
```
|
| 329 |
+
|
| 330 |
+
The separation accessor is used to separate neighboring leaves. The separation function is passed two leaves *a* and *b*, and must return the desired separation. The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.
|
| 331 |
+
|
| 332 |
+
### Tree
|
| 333 |
+
|
| 334 |
+
[<img alt="Tidy Tree" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/tree.png">](https://observablehq.com/@d3/tidy-tree)
|
| 335 |
+
|
| 336 |
+
The **tree** layout produces tidy node-link diagrams of trees using the [Reingold–Tilford “tidy” algorithm](http://reingold.co/tidier-drawings.pdf), improved to run in linear time by [Buchheim *et al.*](http://dirk.jivas.de/papers/buchheim02improving.pdf) Tidy trees are typically more compact than [dendrograms](#cluster).
|
| 337 |
+
|
| 338 |
+
<a name="tree" href="#tree">#</a> d3.<b>tree</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/tree.js), [Examples](https://observablehq.com/@d3/tidy-tree)
|
| 339 |
+
|
| 340 |
+
Creates a new tree layout with default settings.
|
| 341 |
+
|
| 342 |
+
<a name="_tree" href="#_tree">#</a> <i>tree</i>(<i>root</i>)
|
| 343 |
+
|
| 344 |
+
Lays out the specified *root* [hierarchy](#hierarchy), assigning the following properties on *root* and its descendants:
|
| 345 |
+
|
| 346 |
+
* *node*.x - the *x*-coordinate of the node
|
| 347 |
+
* *node*.y - the *y*-coordinate of the node
|
| 348 |
+
|
| 349 |
+
The coordinates *x* and *y* represent an arbitrary coordinate system; for example, you can treat *x* as an angle and *y* as a radius to produce a [radial layout](https://observablehq.com/@d3/radial-tidy-tree). You may want to call [*root*.sort](#node_sort) before passing the hierarchy to the tree layout.
|
| 350 |
+
|
| 351 |
+
<a name="tree_size" href="#tree_size">#</a> <i>tree</i>.<b>size</b>([<i>size</i>])
|
| 352 |
+
|
| 353 |
+
If *size* is specified, sets this tree layout’s size to the specified two-element array of numbers [*width*, *height*] and returns this tree layout. If *size* is not specified, returns the current layout size, which defaults to [1, 1]. A layout size of null indicates that a [node size](#tree_nodeSize) will be used instead. The coordinates *x* and *y* represent an arbitrary coordinate system; for example, to produce a [radial layout](https://observablehq.com/@d3/radial-tidy-tree), a size of [360, *radius*] corresponds to a breadth of 360° and a depth of *radius*.
|
| 354 |
+
|
| 355 |
+
<a name="tree_nodeSize" href="#tree_nodeSize">#</a> <i>tree</i>.<b>nodeSize</b>([<i>size</i>])
|
| 356 |
+
|
| 357 |
+
If *size* is specified, sets this tree layout’s node size to the specified two-element array of numbers [*width*, *height*] and returns this tree layout. If *size* is not specified, returns the current node size, which defaults to null. A node size of null indicates that a [layout size](#tree_size) will be used instead. When a node size is specified, the root node is always positioned at ⟨0, 0⟩.
|
| 358 |
+
|
| 359 |
+
<a name="tree_separation" href="#tree_separation">#</a> <i>tree</i>.<b>separation</b>([<i>separation</i>])
|
| 360 |
+
|
| 361 |
+
If *separation* is specified, sets the separation accessor to the specified function and returns this tree layout. If *separation* is not specified, returns the current separation accessor, which defaults to:
|
| 362 |
+
|
| 363 |
+
```js
|
| 364 |
+
function separation(a, b) {
|
| 365 |
+
return a.parent == b.parent ? 1 : 2;
|
| 366 |
+
}
|
| 367 |
+
```
|
| 368 |
+
|
| 369 |
+
A variation that is more appropriate for radial layouts reduces the separation gap proportionally to the radius:
|
| 370 |
+
|
| 371 |
+
```js
|
| 372 |
+
function separation(a, b) {
|
| 373 |
+
return (a.parent == b.parent ? 1 : 2) / a.depth;
|
| 374 |
+
}
|
| 375 |
+
```
|
| 376 |
+
|
| 377 |
+
The separation accessor is used to separate neighboring nodes. The separation function is passed two nodes *a* and *b*, and must return the desired separation. The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.
|
| 378 |
+
|
| 379 |
+
### Treemap
|
| 380 |
+
|
| 381 |
+
[<img alt="Treemap" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/treemap.png">](https://observablehq.com/@d3/treemap)
|
| 382 |
+
|
| 383 |
+
Introduced by [Ben Shneiderman](http://www.cs.umd.edu/hcil/treemap-history/) in 1991, a **treemap** recursively subdivides area into rectangles according to each node’s associated value. D3’s treemap implementation supports an extensible [tiling method](#treemap_tile): the default [squarified](#treemapSquarify) method seeks to generate rectangles with a [golden](https://en.wikipedia.org/wiki/Golden_ratio) aspect ratio; this offers better readability and size estimation than [slice-and-dice](#treemapSliceDice), which simply alternates between horizontal and vertical subdivision by depth.
|
| 384 |
+
|
| 385 |
+
<a name="treemap" href="#treemap">#</a> d3.<b>treemap</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/index.js), [Examples](https://observablehq.com/@d3/treemap)
|
| 386 |
+
|
| 387 |
+
Creates a new treemap layout with default settings.
|
| 388 |
+
|
| 389 |
+
<a name="_treemap" href="#_treemap">#</a> <i>treemap</i>(<i>root</i>)
|
| 390 |
+
|
| 391 |
+
Lays out the specified *root* [hierarchy](#hierarchy), assigning the following properties on *root* and its descendants:
|
| 392 |
+
|
| 393 |
+
* *node*.x0 - the left edge of the rectangle
|
| 394 |
+
* *node*.y0 - the top edge of the rectangle
|
| 395 |
+
* *node*.x1 - the right edge of the rectangle
|
| 396 |
+
* *node*.y1 - the bottom edge of the rectangle
|
| 397 |
+
|
| 398 |
+
You must call [*root*.sum](#node_sum) before passing the hierarchy to the treemap layout. You probably also want to call [*root*.sort](#node_sort) to order the hierarchy before computing the layout.
|
| 399 |
+
|
| 400 |
+
<a name="treemap_tile" href="#treemap_tile">#</a> <i>treemap</i>.<b>tile</b>([<i>tile</i>])
|
| 401 |
+
|
| 402 |
+
If *tile* is specified, sets the [tiling method](#treemap-tiling) to the specified function and returns this treemap layout. If *tile* is not specified, returns the current tiling method, which defaults to [d3.treemapSquarify](#treemapSquarify) with the golden ratio.
|
| 403 |
+
|
| 404 |
+
<a name="treemap_size" href="#treemap_size">#</a> <i>treemap</i>.<b>size</b>([<i>size</i>])
|
| 405 |
+
|
| 406 |
+
If *size* is specified, sets this treemap layout’s size to the specified two-element array of numbers [*width*, *height*] and returns this treemap layout. If *size* is not specified, returns the current size, which defaults to [1, 1].
|
| 407 |
+
|
| 408 |
+
<a name="treemap_round" href="#treemap_round">#</a> <i>treemap</i>.<b>round</b>([<i>round</i>])
|
| 409 |
+
|
| 410 |
+
If *round* is specified, enables or disables rounding according to the given boolean and returns this treemap layout. If *round* is not specified, returns the current rounding state, which defaults to false.
|
| 411 |
+
|
| 412 |
+
<a name="treemap_padding" href="#treemap_padding">#</a> <i>treemap</i>.<b>padding</b>([<i>padding</i>])
|
| 413 |
+
|
| 414 |
+
If *padding* is specified, sets the [inner](#treemap_paddingInner) and [outer](#treemap_paddingOuter) padding to the specified number or function and returns this treemap layout. If *padding* is not specified, returns the current inner padding function.
|
| 415 |
+
|
| 416 |
+
<a name="treemap_paddingInner" href="#treemap_paddingInner">#</a> <i>treemap</i>.<b>paddingInner</b>([<i>padding</i>])
|
| 417 |
+
|
| 418 |
+
If *padding* is specified, sets the inner padding to the specified number or function and returns this treemap layout. If *padding* is not specified, returns the current inner padding function, which defaults to the constant zero. If *padding* is a function, it is invoked for each node with children, being passed the current node. The inner padding is used to separate a node’s adjacent children.
|
| 419 |
+
|
| 420 |
+
<a name="treemap_paddingOuter" href="#treemap_paddingOuter">#</a> <i>treemap</i>.<b>paddingOuter</b>([<i>padding</i>])
|
| 421 |
+
|
| 422 |
+
If *padding* is specified, sets the [top](#treemap_paddingTop), [right](#treemap_paddingRight), [bottom](#treemap_paddingBottom) and [left](#treemap_paddingLeft) padding to the specified number or function and returns this treemap layout. If *padding* is not specified, returns the current top padding function.
|
| 423 |
+
|
| 424 |
+
<a name="treemap_paddingTop" href="#treemap_paddingTop">#</a> <i>treemap</i>.<b>paddingTop</b>([<i>padding</i>])
|
| 425 |
+
|
| 426 |
+
If *padding* is specified, sets the top padding to the specified number or function and returns this treemap layout. If *padding* is not specified, returns the current top padding function, which defaults to the constant zero. If *padding* is a function, it is invoked for each node with children, being passed the current node. The top padding is used to separate the top edge of a node from its children.
|
| 427 |
+
|
| 428 |
+
<a name="treemap_paddingRight" href="#treemap_paddingRight">#</a> <i>treemap</i>.<b>paddingRight</b>([<i>padding</i>])
|
| 429 |
+
|
| 430 |
+
If *padding* is specified, sets the right padding to the specified number or function and returns this treemap layout. If *padding* is not specified, returns the current right padding function, which defaults to the constant zero. If *padding* is a function, it is invoked for each node with children, being passed the current node. The right padding is used to separate the right edge of a node from its children.
|
| 431 |
+
|
| 432 |
+
<a name="treemap_paddingBottom" href="#treemap_paddingBottom">#</a> <i>treemap</i>.<b>paddingBottom</b>([<i>padding</i>])
|
| 433 |
+
|
| 434 |
+
If *padding* is specified, sets the bottom padding to the specified number or function and returns this treemap layout. If *padding* is not specified, returns the current bottom padding function, which defaults to the constant zero. If *padding* is a function, it is invoked for each node with children, being passed the current node. The bottom padding is used to separate the bottom edge of a node from its children.
|
| 435 |
+
|
| 436 |
+
<a name="treemap_paddingLeft" href="#treemap_paddingLeft">#</a> <i>treemap</i>.<b>paddingLeft</b>([<i>padding</i>])
|
| 437 |
+
|
| 438 |
+
If *padding* is specified, sets the left padding to the specified number or function and returns this treemap layout. If *padding* is not specified, returns the current left padding function, which defaults to the constant zero. If *padding* is a function, it is invoked for each node with children, being passed the current node. The left padding is used to separate the left edge of a node from its children.
|
| 439 |
+
|
| 440 |
+
#### Treemap Tiling
|
| 441 |
+
|
| 442 |
+
Several built-in tiling methods are provided for use with [*treemap*.tile](#treemap_tile).
|
| 443 |
+
|
| 444 |
+
<a name="treemapBinary" href="#treemapBinary">#</a> d3.<b>treemapBinary</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/binary.js), [Examples](https://observablehq.com/@d3/treemap)
|
| 445 |
+
|
| 446 |
+
Recursively partitions the specified *nodes* into an approximately-balanced binary tree, choosing horizontal partitioning for wide rectangles and vertical partitioning for tall rectangles.
|
| 447 |
+
|
| 448 |
+
<a name="treemapDice" href="#treemapDice">#</a> d3.<b>treemapDice</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/dice.js), [Examples](https://observablehq.com/@d3/treemap)
|
| 449 |
+
|
| 450 |
+
Divides the rectangular area specified by *x0*, *y0*, *x1*, *y1* horizontally according the value of each of the specified *node*’s children. The children are positioned in order, starting with the left edge (*x0*) of the given rectangle. If the sum of the children’s values is less than the specified *node*’s value (*i.e.*, if the specified *node* has a non-zero internal value), the remaining empty space will be positioned on the right edge (*x1*) of the given rectangle.
|
| 451 |
+
|
| 452 |
+
<a name="treemapSlice" href="#treemapSlice">#</a> d3.<b>treemapSlice</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/slice.js), [Examples](https://observablehq.com/@d3/treemap)
|
| 453 |
+
|
| 454 |
+
Divides the rectangular area specified by *x0*, *y0*, *x1*, *y1* vertically according the value of each of the specified *node*’s children. The children are positioned in order, starting with the top edge (*y0*) of the given rectangle. If the sum of the children’s values is less than the specified *node*’s value (*i.e.*, if the specified *node* has a non-zero internal value), the remaining empty space will be positioned on the bottom edge (*y1*) of the given rectangle.
|
| 455 |
+
|
| 456 |
+
<a name="treemapSliceDice" href="#treemapSliceDice">#</a> d3.<b>treemapSliceDice</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/sliceDice.js), [Examples](https://observablehq.com/@d3/treemap)
|
| 457 |
+
|
| 458 |
+
If the specified *node* has odd depth, delegates to [treemapSlice](#treemapSlice); otherwise delegates to [treemapDice](#treemapDice).
|
| 459 |
+
|
| 460 |
+
<a name="treemapSquarify" href="#treemapSquarify">#</a> d3.<b>treemapSquarify</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/squarify.js), [Examples](https://observablehq.com/@d3/treemap)
|
| 461 |
+
|
| 462 |
+
Implements the [squarified treemap](https://www.win.tue.nl/~vanwijk/stm.pdf) algorithm by Bruls *et al.*, which seeks to produce rectangles of a given [aspect ratio](#squarify_ratio).
|
| 463 |
+
|
| 464 |
+
<a name="treemapResquarify" href="#treemapResquarify">#</a> d3.<b>treemapResquarify</b>(<i>node</i>, <i>x0</i>, <i>y0</i>, <i>x1</i>, <i>y1</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/resquarify.js), [Examples](https://observablehq.com/@d3/animated-treemap)
|
| 465 |
+
|
| 466 |
+
Like [d3.treemapSquarify](#treemapSquarify), except preserves the topology (node adjacencies) of the previous layout computed by d3.treemapResquarify, if there is one and it used the same [target aspect ratio](#squarify_ratio). This tiling method is good for animating changes to treemaps because it only changes node sizes and not their relative positions, thus avoiding distracting shuffling and occlusion. The downside of a stable update, however, is a suboptimal layout for subsequent updates: only the first layout uses the Bruls *et al.* squarified algorithm.
|
| 467 |
+
|
| 468 |
+
<a name="squarify_ratio" href="#squarify_ratio">#</a> <i>squarify</i>.<b>ratio</b>(<i>ratio</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/treemap/squarify.js), [Examples](https://observablehq.com/@d3/treemap)
|
| 469 |
+
|
| 470 |
+
Specifies the desired aspect ratio of the generated rectangles. The *ratio* must be specified as a number greater than or equal to one. Note that the orientation of the generated rectangles (tall or wide) is not implied by the ratio; for example, a ratio of two will attempt to produce a mixture of rectangles whose *width*:*height* ratio is either 2:1 or 1:2. (However, you can approximately achieve this result by generating a square treemap at different dimensions, and then [stretching the treemap](https://observablehq.com/@d3/stretched-treemap) to the desired aspect ratio.) Furthermore, the specified *ratio* is merely a hint to the tiling algorithm; the rectangles are not guaranteed to have the specified aspect ratio. If not specified, the aspect ratio defaults to the golden ratio, φ = (1 + sqrt(5)) / 2, per [Kong *et al.*](http://vis.stanford.edu/papers/perception-treemaps)
|
| 471 |
+
|
| 472 |
+
### Partition
|
| 473 |
+
|
| 474 |
+
[<img alt="Partition" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/partition.png">](https://observablehq.com/@d3/icicle)
|
| 475 |
+
|
| 476 |
+
The **partition layout** produces adjacency diagrams: a space-filling variant of a node-link tree diagram. Rather than drawing a link between parent and child in the hierarchy, nodes are drawn as solid areas (either arcs or rectangles), and their placement relative to other nodes reveals their position in the hierarchy. The size of the nodes encodes a quantitative dimension that would be difficult to show in a node-link diagram.
|
| 477 |
+
|
| 478 |
+
<a name="partition" href="#partition">#</a> d3.<b>partition</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/partition.js), [Examples](https://observablehq.com/@d3/icicle)
|
| 479 |
+
|
| 480 |
+
Creates a new partition layout with the default settings.
|
| 481 |
+
|
| 482 |
+
<a name="_partition" href="#_partition">#</a> <i>partition</i>(<i>root</i>)
|
| 483 |
+
|
| 484 |
+
Lays out the specified *root* [hierarchy](#hierarchy), assigning the following properties on *root* and its descendants:
|
| 485 |
+
|
| 486 |
+
* *node*.x0 - the left edge of the rectangle
|
| 487 |
+
* *node*.y0 - the top edge of the rectangle
|
| 488 |
+
* *node*.x1 - the right edge of the rectangle
|
| 489 |
+
* *node*.y1 - the bottom edge of the rectangle
|
| 490 |
+
|
| 491 |
+
You must call [*root*.sum](#node_sum) before passing the hierarchy to the partition layout. You probably also want to call [*root*.sort](#node_sort) to order the hierarchy before computing the layout.
|
| 492 |
+
|
| 493 |
+
<a name="partition_size" href="#partition_size">#</a> <i>partition</i>.<b>size</b>([<i>size</i>])
|
| 494 |
+
|
| 495 |
+
If *size* is specified, sets this partition layout’s size to the specified two-element array of numbers [*width*, *height*] and returns this partition layout. If *size* is not specified, returns the current size, which defaults to [1, 1].
|
| 496 |
+
|
| 497 |
+
<a name="partition_round" href="#partition_round">#</a> <i>partition</i>.<b>round</b>([<i>round</i>])
|
| 498 |
+
|
| 499 |
+
If *round* is specified, enables or disables rounding according to the given boolean and returns this partition layout. If *round* is not specified, returns the current rounding state, which defaults to false.
|
| 500 |
+
|
| 501 |
+
<a name="partition_padding" href="#partition_padding">#</a> <i>partition</i>.<b>padding</b>([<i>padding</i>])
|
| 502 |
+
|
| 503 |
+
If *padding* is specified, sets the padding to the specified number and returns this partition layout. If *padding* is not specified, returns the current padding, which defaults to zero. The padding is used to separate a node’s adjacent children.
|
| 504 |
+
|
| 505 |
+
### Pack
|
| 506 |
+
|
| 507 |
+
[<img alt="Circle-Packing" src="https://raw.githubusercontent.com/d3/d3-hierarchy/master/img/pack.png">](https://observablehq.com/@d3/circle-packing)
|
| 508 |
+
|
| 509 |
+
Enclosure diagrams use containment (nesting) to represent a hierarchy. The size of the leaf circles encodes a quantitative dimension of the data. The enclosing circles show the approximate cumulative size of each subtree, but due to wasted space there is some distortion; only the leaf nodes can be compared accurately. Although [circle packing](http://en.wikipedia.org/wiki/Circle_packing) does not use space as efficiently as a [treemap](#treemap), the “wasted” space more prominently reveals the hierarchical structure.
|
| 510 |
+
|
| 511 |
+
<a name="pack" href="#pack">#</a> d3.<b>pack</b>() · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/pack/index.js), [Examples](https://observablehq.com/@d3/circle-packing)
|
| 512 |
+
|
| 513 |
+
Creates a new pack layout with the default settings.
|
| 514 |
+
|
| 515 |
+
<a name="_pack" href="#_pack">#</a> <i>pack</i>(<i>root</i>)
|
| 516 |
+
|
| 517 |
+
Lays out the specified *root* [hierarchy](#hierarchy), assigning the following properties on *root* and its descendants:
|
| 518 |
+
|
| 519 |
+
* *node*.x - the *x*-coordinate of the circle’s center
|
| 520 |
+
* *node*.y - the *y*-coordinate of the circle’s center
|
| 521 |
+
* *node*.r - the radius of the circle
|
| 522 |
+
|
| 523 |
+
You must call [*root*.sum](#node_sum) before passing the hierarchy to the pack layout. You probably also want to call [*root*.sort](#node_sort) to order the hierarchy before computing the layout.
|
| 524 |
+
|
| 525 |
+
<a name="pack_radius" href="#pack_radius">#</a> <i>pack</i>.<b>radius</b>([<i>radius</i>])
|
| 526 |
+
|
| 527 |
+
If *radius* is specified, sets the pack layout’s radius accessor to the specified function and returns this pack layout. If *radius* is not specified, returns the current radius accessor, which defaults to null. If the radius accessor is null, the radius of each leaf circle is derived from the leaf *node*.value (computed by [*node*.sum](#node_sum)); the radii are then scaled proportionally to fit the [layout size](#pack_size). If the radius accessor is not null, the radius of each leaf circle is specified exactly by the function.
|
| 528 |
+
|
| 529 |
+
<a name="pack_size" href="#pack_size">#</a> <i>pack</i>.<b>size</b>([<i>size</i>])
|
| 530 |
+
|
| 531 |
+
If *size* is specified, sets this pack layout’s size to the specified two-element array of numbers [*width*, *height*] and returns this pack layout. If *size* is not specified, returns the current size, which defaults to [1, 1].
|
| 532 |
+
|
| 533 |
+
<a name="pack_padding" href="#pack_padding">#</a> <i>pack</i>.<b>padding</b>([<i>padding</i>])
|
| 534 |
+
|
| 535 |
+
If *padding* is specified, sets this pack layout’s padding accessor to the specified number or function and returns this pack layout. If *padding* is not specified, returns the current padding accessor, which defaults to the constant zero. When siblings are packed, tangent siblings will be separated by approximately the specified padding; the enclosing parent circle will also be separated from its children by approximately the specified padding. If an [explicit radius](#pack_radius) is not specified, the padding is approximate because a two-pass algorithm is needed to fit within the [layout size](#pack_size): the circles are first packed without padding; a scaling factor is computed and applied to the specified padding; and lastly the circles are re-packed with padding.
|
| 536 |
+
|
| 537 |
+
<a name="packSiblings" href="#packSiblings">#</a> d3.<b>packSiblings</b>(<i>circles</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/pack/siblings.js)
|
| 538 |
+
|
| 539 |
+
Packs the specified array of *circles*, each of which must have a *circle*.r property specifying the circle’s radius. Assigns the following properties to each circle:
|
| 540 |
+
|
| 541 |
+
* *circle*.x - the *x*-coordinate of the circle’s center
|
| 542 |
+
* *circle*.y - the *y*-coordinate of the circle’s center
|
| 543 |
+
|
| 544 |
+
The circles are positioned according to the front-chain packing algorithm by [Wang *et al.*](https://dl.acm.org/citation.cfm?id=1124851)
|
| 545 |
+
|
| 546 |
+
<a name="packEnclose" href="#packEnclose">#</a> d3.<b>packEnclose</b>(<i>circles</i>) · [Source](https://github.com/d3/d3-hierarchy/blob/master/src/pack/enclose.js), [Examples](https://observablehq.com/@d3/d3-packenclose)
|
| 547 |
+
|
| 548 |
+
Computes the [smallest circle](https://en.wikipedia.org/wiki/Smallest-circle_problem) that encloses the specified array of *circles*, each of which must have a *circle*.r property specifying the circle’s radius, and *circle*.x and *circle*.y properties specifying the circle’s center. The enclosing circle is computed using the [Matoušek-Sharir-Welzl algorithm](http://www.inf.ethz.ch/personal/emo/PublFiles/SubexLinProg_ALG16_96.pdf). (See also [Apollonius’ Problem](https://bl.ocks.org/mbostock/751fdd637f4bc2e3f08b).)
|
node_modules/d3-hierarchy/dist/d3-hierarchy.js
ADDED
|
@@ -0,0 +1,1290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// https://d3js.org/d3-hierarchy/ v1.1.9 Copyright 2019 Mike Bostock
|
| 2 |
+
(function (global, factory) {
|
| 3 |
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
| 4 |
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
| 5 |
+
(global = global || self, factory(global.d3 = global.d3 || {}));
|
| 6 |
+
}(this, function (exports) { 'use strict';
|
| 7 |
+
|
| 8 |
+
function defaultSeparation(a, b) {
|
| 9 |
+
return a.parent === b.parent ? 1 : 2;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
function meanX(children) {
|
| 13 |
+
return children.reduce(meanXReduce, 0) / children.length;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
function meanXReduce(x, c) {
|
| 17 |
+
return x + c.x;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
function maxY(children) {
|
| 21 |
+
return 1 + children.reduce(maxYReduce, 0);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
function maxYReduce(y, c) {
|
| 25 |
+
return Math.max(y, c.y);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function leafLeft(node) {
|
| 29 |
+
var children;
|
| 30 |
+
while (children = node.children) node = children[0];
|
| 31 |
+
return node;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
function leafRight(node) {
|
| 35 |
+
var children;
|
| 36 |
+
while (children = node.children) node = children[children.length - 1];
|
| 37 |
+
return node;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function cluster() {
|
| 41 |
+
var separation = defaultSeparation,
|
| 42 |
+
dx = 1,
|
| 43 |
+
dy = 1,
|
| 44 |
+
nodeSize = false;
|
| 45 |
+
|
| 46 |
+
function cluster(root) {
|
| 47 |
+
var previousNode,
|
| 48 |
+
x = 0;
|
| 49 |
+
|
| 50 |
+
// First walk, computing the initial x & y values.
|
| 51 |
+
root.eachAfter(function(node) {
|
| 52 |
+
var children = node.children;
|
| 53 |
+
if (children) {
|
| 54 |
+
node.x = meanX(children);
|
| 55 |
+
node.y = maxY(children);
|
| 56 |
+
} else {
|
| 57 |
+
node.x = previousNode ? x += separation(node, previousNode) : 0;
|
| 58 |
+
node.y = 0;
|
| 59 |
+
previousNode = node;
|
| 60 |
+
}
|
| 61 |
+
});
|
| 62 |
+
|
| 63 |
+
var left = leafLeft(root),
|
| 64 |
+
right = leafRight(root),
|
| 65 |
+
x0 = left.x - separation(left, right) / 2,
|
| 66 |
+
x1 = right.x + separation(right, left) / 2;
|
| 67 |
+
|
| 68 |
+
// Second walk, normalizing x & y to the desired size.
|
| 69 |
+
return root.eachAfter(nodeSize ? function(node) {
|
| 70 |
+
node.x = (node.x - root.x) * dx;
|
| 71 |
+
node.y = (root.y - node.y) * dy;
|
| 72 |
+
} : function(node) {
|
| 73 |
+
node.x = (node.x - x0) / (x1 - x0) * dx;
|
| 74 |
+
node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
|
| 75 |
+
});
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
cluster.separation = function(x) {
|
| 79 |
+
return arguments.length ? (separation = x, cluster) : separation;
|
| 80 |
+
};
|
| 81 |
+
|
| 82 |
+
cluster.size = function(x) {
|
| 83 |
+
return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
cluster.nodeSize = function(x) {
|
| 87 |
+
return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
return cluster;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
function count(node) {
|
| 94 |
+
var sum = 0,
|
| 95 |
+
children = node.children,
|
| 96 |
+
i = children && children.length;
|
| 97 |
+
if (!i) sum = 1;
|
| 98 |
+
else while (--i >= 0) sum += children[i].value;
|
| 99 |
+
node.value = sum;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
function node_count() {
|
| 103 |
+
return this.eachAfter(count);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
function node_each(callback) {
|
| 107 |
+
var node = this, current, next = [node], children, i, n;
|
| 108 |
+
do {
|
| 109 |
+
current = next.reverse(), next = [];
|
| 110 |
+
while (node = current.pop()) {
|
| 111 |
+
callback(node), children = node.children;
|
| 112 |
+
if (children) for (i = 0, n = children.length; i < n; ++i) {
|
| 113 |
+
next.push(children[i]);
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
} while (next.length);
|
| 117 |
+
return this;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
function node_eachBefore(callback) {
|
| 121 |
+
var node = this, nodes = [node], children, i;
|
| 122 |
+
while (node = nodes.pop()) {
|
| 123 |
+
callback(node), children = node.children;
|
| 124 |
+
if (children) for (i = children.length - 1; i >= 0; --i) {
|
| 125 |
+
nodes.push(children[i]);
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
return this;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
function node_eachAfter(callback) {
|
| 132 |
+
var node = this, nodes = [node], next = [], children, i, n;
|
| 133 |
+
while (node = nodes.pop()) {
|
| 134 |
+
next.push(node), children = node.children;
|
| 135 |
+
if (children) for (i = 0, n = children.length; i < n; ++i) {
|
| 136 |
+
nodes.push(children[i]);
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
while (node = next.pop()) {
|
| 140 |
+
callback(node);
|
| 141 |
+
}
|
| 142 |
+
return this;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
function node_sum(value) {
|
| 146 |
+
return this.eachAfter(function(node) {
|
| 147 |
+
var sum = +value(node.data) || 0,
|
| 148 |
+
children = node.children,
|
| 149 |
+
i = children && children.length;
|
| 150 |
+
while (--i >= 0) sum += children[i].value;
|
| 151 |
+
node.value = sum;
|
| 152 |
+
});
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
function node_sort(compare) {
|
| 156 |
+
return this.eachBefore(function(node) {
|
| 157 |
+
if (node.children) {
|
| 158 |
+
node.children.sort(compare);
|
| 159 |
+
}
|
| 160 |
+
});
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
function node_path(end) {
|
| 164 |
+
var start = this,
|
| 165 |
+
ancestor = leastCommonAncestor(start, end),
|
| 166 |
+
nodes = [start];
|
| 167 |
+
while (start !== ancestor) {
|
| 168 |
+
start = start.parent;
|
| 169 |
+
nodes.push(start);
|
| 170 |
+
}
|
| 171 |
+
var k = nodes.length;
|
| 172 |
+
while (end !== ancestor) {
|
| 173 |
+
nodes.splice(k, 0, end);
|
| 174 |
+
end = end.parent;
|
| 175 |
+
}
|
| 176 |
+
return nodes;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
function leastCommonAncestor(a, b) {
|
| 180 |
+
if (a === b) return a;
|
| 181 |
+
var aNodes = a.ancestors(),
|
| 182 |
+
bNodes = b.ancestors(),
|
| 183 |
+
c = null;
|
| 184 |
+
a = aNodes.pop();
|
| 185 |
+
b = bNodes.pop();
|
| 186 |
+
while (a === b) {
|
| 187 |
+
c = a;
|
| 188 |
+
a = aNodes.pop();
|
| 189 |
+
b = bNodes.pop();
|
| 190 |
+
}
|
| 191 |
+
return c;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
function node_ancestors() {
|
| 195 |
+
var node = this, nodes = [node];
|
| 196 |
+
while (node = node.parent) {
|
| 197 |
+
nodes.push(node);
|
| 198 |
+
}
|
| 199 |
+
return nodes;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
function node_descendants() {
|
| 203 |
+
var nodes = [];
|
| 204 |
+
this.each(function(node) {
|
| 205 |
+
nodes.push(node);
|
| 206 |
+
});
|
| 207 |
+
return nodes;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
function node_leaves() {
|
| 211 |
+
var leaves = [];
|
| 212 |
+
this.eachBefore(function(node) {
|
| 213 |
+
if (!node.children) {
|
| 214 |
+
leaves.push(node);
|
| 215 |
+
}
|
| 216 |
+
});
|
| 217 |
+
return leaves;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
function node_links() {
|
| 221 |
+
var root = this, links = [];
|
| 222 |
+
root.each(function(node) {
|
| 223 |
+
if (node !== root) { // Don’t include the root’s parent, if any.
|
| 224 |
+
links.push({source: node.parent, target: node});
|
| 225 |
+
}
|
| 226 |
+
});
|
| 227 |
+
return links;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
function hierarchy(data, children) {
|
| 231 |
+
var root = new Node(data),
|
| 232 |
+
valued = +data.value && (root.value = data.value),
|
| 233 |
+
node,
|
| 234 |
+
nodes = [root],
|
| 235 |
+
child,
|
| 236 |
+
childs,
|
| 237 |
+
i,
|
| 238 |
+
n;
|
| 239 |
+
|
| 240 |
+
if (children == null) children = defaultChildren;
|
| 241 |
+
|
| 242 |
+
while (node = nodes.pop()) {
|
| 243 |
+
if (valued) node.value = +node.data.value;
|
| 244 |
+
if ((childs = children(node.data)) && (n = childs.length)) {
|
| 245 |
+
node.children = new Array(n);
|
| 246 |
+
for (i = n - 1; i >= 0; --i) {
|
| 247 |
+
nodes.push(child = node.children[i] = new Node(childs[i]));
|
| 248 |
+
child.parent = node;
|
| 249 |
+
child.depth = node.depth + 1;
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
return root.eachBefore(computeHeight);
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
function node_copy() {
|
| 258 |
+
return hierarchy(this).eachBefore(copyData);
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
function defaultChildren(d) {
|
| 262 |
+
return d.children;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
function copyData(node) {
|
| 266 |
+
node.data = node.data.data;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
function computeHeight(node) {
|
| 270 |
+
var height = 0;
|
| 271 |
+
do node.height = height;
|
| 272 |
+
while ((node = node.parent) && (node.height < ++height));
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
function Node(data) {
|
| 276 |
+
this.data = data;
|
| 277 |
+
this.depth =
|
| 278 |
+
this.height = 0;
|
| 279 |
+
this.parent = null;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
Node.prototype = hierarchy.prototype = {
|
| 283 |
+
constructor: Node,
|
| 284 |
+
count: node_count,
|
| 285 |
+
each: node_each,
|
| 286 |
+
eachAfter: node_eachAfter,
|
| 287 |
+
eachBefore: node_eachBefore,
|
| 288 |
+
sum: node_sum,
|
| 289 |
+
sort: node_sort,
|
| 290 |
+
path: node_path,
|
| 291 |
+
ancestors: node_ancestors,
|
| 292 |
+
descendants: node_descendants,
|
| 293 |
+
leaves: node_leaves,
|
| 294 |
+
links: node_links,
|
| 295 |
+
copy: node_copy
|
| 296 |
+
};
|
| 297 |
+
|
| 298 |
+
var slice = Array.prototype.slice;
|
| 299 |
+
|
| 300 |
+
function shuffle(array) {
|
| 301 |
+
var m = array.length,
|
| 302 |
+
t,
|
| 303 |
+
i;
|
| 304 |
+
|
| 305 |
+
while (m) {
|
| 306 |
+
i = Math.random() * m-- | 0;
|
| 307 |
+
t = array[m];
|
| 308 |
+
array[m] = array[i];
|
| 309 |
+
array[i] = t;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
return array;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
function enclose(circles) {
|
| 316 |
+
var i = 0, n = (circles = shuffle(slice.call(circles))).length, B = [], p, e;
|
| 317 |
+
|
| 318 |
+
while (i < n) {
|
| 319 |
+
p = circles[i];
|
| 320 |
+
if (e && enclosesWeak(e, p)) ++i;
|
| 321 |
+
else e = encloseBasis(B = extendBasis(B, p)), i = 0;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
return e;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
function extendBasis(B, p) {
|
| 328 |
+
var i, j;
|
| 329 |
+
|
| 330 |
+
if (enclosesWeakAll(p, B)) return [p];
|
| 331 |
+
|
| 332 |
+
// If we get here then B must have at least one element.
|
| 333 |
+
for (i = 0; i < B.length; ++i) {
|
| 334 |
+
if (enclosesNot(p, B[i])
|
| 335 |
+
&& enclosesWeakAll(encloseBasis2(B[i], p), B)) {
|
| 336 |
+
return [B[i], p];
|
| 337 |
+
}
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
// If we get here then B must have at least two elements.
|
| 341 |
+
for (i = 0; i < B.length - 1; ++i) {
|
| 342 |
+
for (j = i + 1; j < B.length; ++j) {
|
| 343 |
+
if (enclosesNot(encloseBasis2(B[i], B[j]), p)
|
| 344 |
+
&& enclosesNot(encloseBasis2(B[i], p), B[j])
|
| 345 |
+
&& enclosesNot(encloseBasis2(B[j], p), B[i])
|
| 346 |
+
&& enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
|
| 347 |
+
return [B[i], B[j], p];
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
// If we get here then something is very wrong.
|
| 353 |
+
throw new Error;
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
function enclosesNot(a, b) {
|
| 357 |
+
var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
|
| 358 |
+
return dr < 0 || dr * dr < dx * dx + dy * dy;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
function enclosesWeak(a, b) {
|
| 362 |
+
var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
|
| 363 |
+
return dr > 0 && dr * dr > dx * dx + dy * dy;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
function enclosesWeakAll(a, B) {
|
| 367 |
+
for (var i = 0; i < B.length; ++i) {
|
| 368 |
+
if (!enclosesWeak(a, B[i])) {
|
| 369 |
+
return false;
|
| 370 |
+
}
|
| 371 |
+
}
|
| 372 |
+
return true;
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
function encloseBasis(B) {
|
| 376 |
+
switch (B.length) {
|
| 377 |
+
case 1: return encloseBasis1(B[0]);
|
| 378 |
+
case 2: return encloseBasis2(B[0], B[1]);
|
| 379 |
+
case 3: return encloseBasis3(B[0], B[1], B[2]);
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
function encloseBasis1(a) {
|
| 384 |
+
return {
|
| 385 |
+
x: a.x,
|
| 386 |
+
y: a.y,
|
| 387 |
+
r: a.r
|
| 388 |
+
};
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
function encloseBasis2(a, b) {
|
| 392 |
+
var x1 = a.x, y1 = a.y, r1 = a.r,
|
| 393 |
+
x2 = b.x, y2 = b.y, r2 = b.r,
|
| 394 |
+
x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
|
| 395 |
+
l = Math.sqrt(x21 * x21 + y21 * y21);
|
| 396 |
+
return {
|
| 397 |
+
x: (x1 + x2 + x21 / l * r21) / 2,
|
| 398 |
+
y: (y1 + y2 + y21 / l * r21) / 2,
|
| 399 |
+
r: (l + r1 + r2) / 2
|
| 400 |
+
};
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
function encloseBasis3(a, b, c) {
|
| 404 |
+
var x1 = a.x, y1 = a.y, r1 = a.r,
|
| 405 |
+
x2 = b.x, y2 = b.y, r2 = b.r,
|
| 406 |
+
x3 = c.x, y3 = c.y, r3 = c.r,
|
| 407 |
+
a2 = x1 - x2,
|
| 408 |
+
a3 = x1 - x3,
|
| 409 |
+
b2 = y1 - y2,
|
| 410 |
+
b3 = y1 - y3,
|
| 411 |
+
c2 = r2 - r1,
|
| 412 |
+
c3 = r3 - r1,
|
| 413 |
+
d1 = x1 * x1 + y1 * y1 - r1 * r1,
|
| 414 |
+
d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
|
| 415 |
+
d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
|
| 416 |
+
ab = a3 * b2 - a2 * b3,
|
| 417 |
+
xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
|
| 418 |
+
xb = (b3 * c2 - b2 * c3) / ab,
|
| 419 |
+
ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
|
| 420 |
+
yb = (a2 * c3 - a3 * c2) / ab,
|
| 421 |
+
A = xb * xb + yb * yb - 1,
|
| 422 |
+
B = 2 * (r1 + xa * xb + ya * yb),
|
| 423 |
+
C = xa * xa + ya * ya - r1 * r1,
|
| 424 |
+
r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
|
| 425 |
+
return {
|
| 426 |
+
x: x1 + xa + xb * r,
|
| 427 |
+
y: y1 + ya + yb * r,
|
| 428 |
+
r: r
|
| 429 |
+
};
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
function place(b, a, c) {
|
| 433 |
+
var dx = b.x - a.x, x, a2,
|
| 434 |
+
dy = b.y - a.y, y, b2,
|
| 435 |
+
d2 = dx * dx + dy * dy;
|
| 436 |
+
if (d2) {
|
| 437 |
+
a2 = a.r + c.r, a2 *= a2;
|
| 438 |
+
b2 = b.r + c.r, b2 *= b2;
|
| 439 |
+
if (a2 > b2) {
|
| 440 |
+
x = (d2 + b2 - a2) / (2 * d2);
|
| 441 |
+
y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
|
| 442 |
+
c.x = b.x - x * dx - y * dy;
|
| 443 |
+
c.y = b.y - x * dy + y * dx;
|
| 444 |
+
} else {
|
| 445 |
+
x = (d2 + a2 - b2) / (2 * d2);
|
| 446 |
+
y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
|
| 447 |
+
c.x = a.x + x * dx - y * dy;
|
| 448 |
+
c.y = a.y + x * dy + y * dx;
|
| 449 |
+
}
|
| 450 |
+
} else {
|
| 451 |
+
c.x = a.x + c.r;
|
| 452 |
+
c.y = a.y;
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
function intersects(a, b) {
|
| 457 |
+
var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
|
| 458 |
+
return dr > 0 && dr * dr > dx * dx + dy * dy;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
function score(node) {
|
| 462 |
+
var a = node._,
|
| 463 |
+
b = node.next._,
|
| 464 |
+
ab = a.r + b.r,
|
| 465 |
+
dx = (a.x * b.r + b.x * a.r) / ab,
|
| 466 |
+
dy = (a.y * b.r + b.y * a.r) / ab;
|
| 467 |
+
return dx * dx + dy * dy;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
function Node$1(circle) {
|
| 471 |
+
this._ = circle;
|
| 472 |
+
this.next = null;
|
| 473 |
+
this.previous = null;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
function packEnclose(circles) {
|
| 477 |
+
if (!(n = circles.length)) return 0;
|
| 478 |
+
|
| 479 |
+
var a, b, c, n, aa, ca, i, j, k, sj, sk;
|
| 480 |
+
|
| 481 |
+
// Place the first circle.
|
| 482 |
+
a = circles[0], a.x = 0, a.y = 0;
|
| 483 |
+
if (!(n > 1)) return a.r;
|
| 484 |
+
|
| 485 |
+
// Place the second circle.
|
| 486 |
+
b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
|
| 487 |
+
if (!(n > 2)) return a.r + b.r;
|
| 488 |
+
|
| 489 |
+
// Place the third circle.
|
| 490 |
+
place(b, a, c = circles[2]);
|
| 491 |
+
|
| 492 |
+
// Initialize the front-chain using the first three circles a, b and c.
|
| 493 |
+
a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
|
| 494 |
+
a.next = c.previous = b;
|
| 495 |
+
b.next = a.previous = c;
|
| 496 |
+
c.next = b.previous = a;
|
| 497 |
+
|
| 498 |
+
// Attempt to place each remaining circle…
|
| 499 |
+
pack: for (i = 3; i < n; ++i) {
|
| 500 |
+
place(a._, b._, c = circles[i]), c = new Node$1(c);
|
| 501 |
+
|
| 502 |
+
// Find the closest intersecting circle on the front-chain, if any.
|
| 503 |
+
// “Closeness” is determined by linear distance along the front-chain.
|
| 504 |
+
// “Ahead” or “behind” is likewise determined by linear distance.
|
| 505 |
+
j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
|
| 506 |
+
do {
|
| 507 |
+
if (sj <= sk) {
|
| 508 |
+
if (intersects(j._, c._)) {
|
| 509 |
+
b = j, a.next = b, b.previous = a, --i;
|
| 510 |
+
continue pack;
|
| 511 |
+
}
|
| 512 |
+
sj += j._.r, j = j.next;
|
| 513 |
+
} else {
|
| 514 |
+
if (intersects(k._, c._)) {
|
| 515 |
+
a = k, a.next = b, b.previous = a, --i;
|
| 516 |
+
continue pack;
|
| 517 |
+
}
|
| 518 |
+
sk += k._.r, k = k.previous;
|
| 519 |
+
}
|
| 520 |
+
} while (j !== k.next);
|
| 521 |
+
|
| 522 |
+
// Success! Insert the new circle c between a and b.
|
| 523 |
+
c.previous = a, c.next = b, a.next = b.previous = b = c;
|
| 524 |
+
|
| 525 |
+
// Compute the new closest circle pair to the centroid.
|
| 526 |
+
aa = score(a);
|
| 527 |
+
while ((c = c.next) !== b) {
|
| 528 |
+
if ((ca = score(c)) < aa) {
|
| 529 |
+
a = c, aa = ca;
|
| 530 |
+
}
|
| 531 |
+
}
|
| 532 |
+
b = a.next;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
// Compute the enclosing circle of the front chain.
|
| 536 |
+
a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
|
| 537 |
+
|
| 538 |
+
// Translate the circles to put the enclosing circle around the origin.
|
| 539 |
+
for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
|
| 540 |
+
|
| 541 |
+
return c.r;
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
function siblings(circles) {
|
| 545 |
+
packEnclose(circles);
|
| 546 |
+
return circles;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
function optional(f) {
|
| 550 |
+
return f == null ? null : required(f);
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
function required(f) {
|
| 554 |
+
if (typeof f !== "function") throw new Error;
|
| 555 |
+
return f;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
function constantZero() {
|
| 559 |
+
return 0;
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
function constant(x) {
|
| 563 |
+
return function() {
|
| 564 |
+
return x;
|
| 565 |
+
};
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
function defaultRadius(d) {
|
| 569 |
+
return Math.sqrt(d.value);
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
function index() {
|
| 573 |
+
var radius = null,
|
| 574 |
+
dx = 1,
|
| 575 |
+
dy = 1,
|
| 576 |
+
padding = constantZero;
|
| 577 |
+
|
| 578 |
+
function pack(root) {
|
| 579 |
+
root.x = dx / 2, root.y = dy / 2;
|
| 580 |
+
if (radius) {
|
| 581 |
+
root.eachBefore(radiusLeaf(radius))
|
| 582 |
+
.eachAfter(packChildren(padding, 0.5))
|
| 583 |
+
.eachBefore(translateChild(1));
|
| 584 |
+
} else {
|
| 585 |
+
root.eachBefore(radiusLeaf(defaultRadius))
|
| 586 |
+
.eachAfter(packChildren(constantZero, 1))
|
| 587 |
+
.eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
|
| 588 |
+
.eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
|
| 589 |
+
}
|
| 590 |
+
return root;
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
pack.radius = function(x) {
|
| 594 |
+
return arguments.length ? (radius = optional(x), pack) : radius;
|
| 595 |
+
};
|
| 596 |
+
|
| 597 |
+
pack.size = function(x) {
|
| 598 |
+
return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
|
| 599 |
+
};
|
| 600 |
+
|
| 601 |
+
pack.padding = function(x) {
|
| 602 |
+
return arguments.length ? (padding = typeof x === "function" ? x : constant(+x), pack) : padding;
|
| 603 |
+
};
|
| 604 |
+
|
| 605 |
+
return pack;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
function radiusLeaf(radius) {
|
| 609 |
+
return function(node) {
|
| 610 |
+
if (!node.children) {
|
| 611 |
+
node.r = Math.max(0, +radius(node) || 0);
|
| 612 |
+
}
|
| 613 |
+
};
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
function packChildren(padding, k) {
|
| 617 |
+
return function(node) {
|
| 618 |
+
if (children = node.children) {
|
| 619 |
+
var children,
|
| 620 |
+
i,
|
| 621 |
+
n = children.length,
|
| 622 |
+
r = padding(node) * k || 0,
|
| 623 |
+
e;
|
| 624 |
+
|
| 625 |
+
if (r) for (i = 0; i < n; ++i) children[i].r += r;
|
| 626 |
+
e = packEnclose(children);
|
| 627 |
+
if (r) for (i = 0; i < n; ++i) children[i].r -= r;
|
| 628 |
+
node.r = e + r;
|
| 629 |
+
}
|
| 630 |
+
};
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
function translateChild(k) {
|
| 634 |
+
return function(node) {
|
| 635 |
+
var parent = node.parent;
|
| 636 |
+
node.r *= k;
|
| 637 |
+
if (parent) {
|
| 638 |
+
node.x = parent.x + k * node.x;
|
| 639 |
+
node.y = parent.y + k * node.y;
|
| 640 |
+
}
|
| 641 |
+
};
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
+
function roundNode(node) {
|
| 645 |
+
node.x0 = Math.round(node.x0);
|
| 646 |
+
node.y0 = Math.round(node.y0);
|
| 647 |
+
node.x1 = Math.round(node.x1);
|
| 648 |
+
node.y1 = Math.round(node.y1);
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
function treemapDice(parent, x0, y0, x1, y1) {
|
| 652 |
+
var nodes = parent.children,
|
| 653 |
+
node,
|
| 654 |
+
i = -1,
|
| 655 |
+
n = nodes.length,
|
| 656 |
+
k = parent.value && (x1 - x0) / parent.value;
|
| 657 |
+
|
| 658 |
+
while (++i < n) {
|
| 659 |
+
node = nodes[i], node.y0 = y0, node.y1 = y1;
|
| 660 |
+
node.x0 = x0, node.x1 = x0 += node.value * k;
|
| 661 |
+
}
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
function partition() {
|
| 665 |
+
var dx = 1,
|
| 666 |
+
dy = 1,
|
| 667 |
+
padding = 0,
|
| 668 |
+
round = false;
|
| 669 |
+
|
| 670 |
+
function partition(root) {
|
| 671 |
+
var n = root.height + 1;
|
| 672 |
+
root.x0 =
|
| 673 |
+
root.y0 = padding;
|
| 674 |
+
root.x1 = dx;
|
| 675 |
+
root.y1 = dy / n;
|
| 676 |
+
root.eachBefore(positionNode(dy, n));
|
| 677 |
+
if (round) root.eachBefore(roundNode);
|
| 678 |
+
return root;
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
function positionNode(dy, n) {
|
| 682 |
+
return function(node) {
|
| 683 |
+
if (node.children) {
|
| 684 |
+
treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
|
| 685 |
+
}
|
| 686 |
+
var x0 = node.x0,
|
| 687 |
+
y0 = node.y0,
|
| 688 |
+
x1 = node.x1 - padding,
|
| 689 |
+
y1 = node.y1 - padding;
|
| 690 |
+
if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
| 691 |
+
if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
| 692 |
+
node.x0 = x0;
|
| 693 |
+
node.y0 = y0;
|
| 694 |
+
node.x1 = x1;
|
| 695 |
+
node.y1 = y1;
|
| 696 |
+
};
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
partition.round = function(x) {
|
| 700 |
+
return arguments.length ? (round = !!x, partition) : round;
|
| 701 |
+
};
|
| 702 |
+
|
| 703 |
+
partition.size = function(x) {
|
| 704 |
+
return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
|
| 705 |
+
};
|
| 706 |
+
|
| 707 |
+
partition.padding = function(x) {
|
| 708 |
+
return arguments.length ? (padding = +x, partition) : padding;
|
| 709 |
+
};
|
| 710 |
+
|
| 711 |
+
return partition;
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
var keyPrefix = "$", // Protect against keys like “__proto__”.
|
| 715 |
+
preroot = {depth: -1},
|
| 716 |
+
ambiguous = {};
|
| 717 |
+
|
| 718 |
+
function defaultId(d) {
|
| 719 |
+
return d.id;
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
function defaultParentId(d) {
|
| 723 |
+
return d.parentId;
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
function stratify() {
|
| 727 |
+
var id = defaultId,
|
| 728 |
+
parentId = defaultParentId;
|
| 729 |
+
|
| 730 |
+
function stratify(data) {
|
| 731 |
+
var d,
|
| 732 |
+
i,
|
| 733 |
+
n = data.length,
|
| 734 |
+
root,
|
| 735 |
+
parent,
|
| 736 |
+
node,
|
| 737 |
+
nodes = new Array(n),
|
| 738 |
+
nodeId,
|
| 739 |
+
nodeKey,
|
| 740 |
+
nodeByKey = {};
|
| 741 |
+
|
| 742 |
+
for (i = 0; i < n; ++i) {
|
| 743 |
+
d = data[i], node = nodes[i] = new Node(d);
|
| 744 |
+
if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
|
| 745 |
+
nodeKey = keyPrefix + (node.id = nodeId);
|
| 746 |
+
nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
|
| 747 |
+
}
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
for (i = 0; i < n; ++i) {
|
| 751 |
+
node = nodes[i], nodeId = parentId(data[i], i, data);
|
| 752 |
+
if (nodeId == null || !(nodeId += "")) {
|
| 753 |
+
if (root) throw new Error("multiple roots");
|
| 754 |
+
root = node;
|
| 755 |
+
} else {
|
| 756 |
+
parent = nodeByKey[keyPrefix + nodeId];
|
| 757 |
+
if (!parent) throw new Error("missing: " + nodeId);
|
| 758 |
+
if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
|
| 759 |
+
if (parent.children) parent.children.push(node);
|
| 760 |
+
else parent.children = [node];
|
| 761 |
+
node.parent = parent;
|
| 762 |
+
}
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
if (!root) throw new Error("no root");
|
| 766 |
+
root.parent = preroot;
|
| 767 |
+
root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
|
| 768 |
+
root.parent = null;
|
| 769 |
+
if (n > 0) throw new Error("cycle");
|
| 770 |
+
|
| 771 |
+
return root;
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
stratify.id = function(x) {
|
| 775 |
+
return arguments.length ? (id = required(x), stratify) : id;
|
| 776 |
+
};
|
| 777 |
+
|
| 778 |
+
stratify.parentId = function(x) {
|
| 779 |
+
return arguments.length ? (parentId = required(x), stratify) : parentId;
|
| 780 |
+
};
|
| 781 |
+
|
| 782 |
+
return stratify;
|
| 783 |
+
}
|
| 784 |
+
|
| 785 |
+
function defaultSeparation$1(a, b) {
|
| 786 |
+
return a.parent === b.parent ? 1 : 2;
|
| 787 |
+
}
|
| 788 |
+
|
| 789 |
+
// function radialSeparation(a, b) {
|
| 790 |
+
// return (a.parent === b.parent ? 1 : 2) / a.depth;
|
| 791 |
+
// }
|
| 792 |
+
|
| 793 |
+
// This function is used to traverse the left contour of a subtree (or
|
| 794 |
+
// subforest). It returns the successor of v on this contour. This successor is
|
| 795 |
+
// either given by the leftmost child of v or by the thread of v. The function
|
| 796 |
+
// returns null if and only if v is on the highest level of its subtree.
|
| 797 |
+
function nextLeft(v) {
|
| 798 |
+
var children = v.children;
|
| 799 |
+
return children ? children[0] : v.t;
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
// This function works analogously to nextLeft.
|
| 803 |
+
function nextRight(v) {
|
| 804 |
+
var children = v.children;
|
| 805 |
+
return children ? children[children.length - 1] : v.t;
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
// Shifts the current subtree rooted at w+. This is done by increasing
|
| 809 |
+
// prelim(w+) and mod(w+) by shift.
|
| 810 |
+
function moveSubtree(wm, wp, shift) {
|
| 811 |
+
var change = shift / (wp.i - wm.i);
|
| 812 |
+
wp.c -= change;
|
| 813 |
+
wp.s += shift;
|
| 814 |
+
wm.c += change;
|
| 815 |
+
wp.z += shift;
|
| 816 |
+
wp.m += shift;
|
| 817 |
+
}
|
| 818 |
+
|
| 819 |
+
// All other shifts, applied to the smaller subtrees between w- and w+, are
|
| 820 |
+
// performed by this function. To prepare the shifts, we have to adjust
|
| 821 |
+
// change(w+), shift(w+), and change(w-).
|
| 822 |
+
function executeShifts(v) {
|
| 823 |
+
var shift = 0,
|
| 824 |
+
change = 0,
|
| 825 |
+
children = v.children,
|
| 826 |
+
i = children.length,
|
| 827 |
+
w;
|
| 828 |
+
while (--i >= 0) {
|
| 829 |
+
w = children[i];
|
| 830 |
+
w.z += shift;
|
| 831 |
+
w.m += shift;
|
| 832 |
+
shift += w.s + (change += w.c);
|
| 833 |
+
}
|
| 834 |
+
}
|
| 835 |
+
|
| 836 |
+
// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
|
| 837 |
+
// returns the specified (default) ancestor.
|
| 838 |
+
function nextAncestor(vim, v, ancestor) {
|
| 839 |
+
return vim.a.parent === v.parent ? vim.a : ancestor;
|
| 840 |
+
}
|
| 841 |
+
|
| 842 |
+
function TreeNode(node, i) {
|
| 843 |
+
this._ = node;
|
| 844 |
+
this.parent = null;
|
| 845 |
+
this.children = null;
|
| 846 |
+
this.A = null; // default ancestor
|
| 847 |
+
this.a = this; // ancestor
|
| 848 |
+
this.z = 0; // prelim
|
| 849 |
+
this.m = 0; // mod
|
| 850 |
+
this.c = 0; // change
|
| 851 |
+
this.s = 0; // shift
|
| 852 |
+
this.t = null; // thread
|
| 853 |
+
this.i = i; // number
|
| 854 |
+
}
|
| 855 |
+
|
| 856 |
+
TreeNode.prototype = Object.create(Node.prototype);
|
| 857 |
+
|
| 858 |
+
function treeRoot(root) {
|
| 859 |
+
var tree = new TreeNode(root, 0),
|
| 860 |
+
node,
|
| 861 |
+
nodes = [tree],
|
| 862 |
+
child,
|
| 863 |
+
children,
|
| 864 |
+
i,
|
| 865 |
+
n;
|
| 866 |
+
|
| 867 |
+
while (node = nodes.pop()) {
|
| 868 |
+
if (children = node._.children) {
|
| 869 |
+
node.children = new Array(n = children.length);
|
| 870 |
+
for (i = n - 1; i >= 0; --i) {
|
| 871 |
+
nodes.push(child = node.children[i] = new TreeNode(children[i], i));
|
| 872 |
+
child.parent = node;
|
| 873 |
+
}
|
| 874 |
+
}
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
(tree.parent = new TreeNode(null, 0)).children = [tree];
|
| 878 |
+
return tree;
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
|
| 882 |
+
function tree() {
|
| 883 |
+
var separation = defaultSeparation$1,
|
| 884 |
+
dx = 1,
|
| 885 |
+
dy = 1,
|
| 886 |
+
nodeSize = null;
|
| 887 |
+
|
| 888 |
+
function tree(root) {
|
| 889 |
+
var t = treeRoot(root);
|
| 890 |
+
|
| 891 |
+
// Compute the layout using Buchheim et al.’s algorithm.
|
| 892 |
+
t.eachAfter(firstWalk), t.parent.m = -t.z;
|
| 893 |
+
t.eachBefore(secondWalk);
|
| 894 |
+
|
| 895 |
+
// If a fixed node size is specified, scale x and y.
|
| 896 |
+
if (nodeSize) root.eachBefore(sizeNode);
|
| 897 |
+
|
| 898 |
+
// If a fixed tree size is specified, scale x and y based on the extent.
|
| 899 |
+
// Compute the left-most, right-most, and depth-most nodes for extents.
|
| 900 |
+
else {
|
| 901 |
+
var left = root,
|
| 902 |
+
right = root,
|
| 903 |
+
bottom = root;
|
| 904 |
+
root.eachBefore(function(node) {
|
| 905 |
+
if (node.x < left.x) left = node;
|
| 906 |
+
if (node.x > right.x) right = node;
|
| 907 |
+
if (node.depth > bottom.depth) bottom = node;
|
| 908 |
+
});
|
| 909 |
+
var s = left === right ? 1 : separation(left, right) / 2,
|
| 910 |
+
tx = s - left.x,
|
| 911 |
+
kx = dx / (right.x + s + tx),
|
| 912 |
+
ky = dy / (bottom.depth || 1);
|
| 913 |
+
root.eachBefore(function(node) {
|
| 914 |
+
node.x = (node.x + tx) * kx;
|
| 915 |
+
node.y = node.depth * ky;
|
| 916 |
+
});
|
| 917 |
+
}
|
| 918 |
+
|
| 919 |
+
return root;
|
| 920 |
+
}
|
| 921 |
+
|
| 922 |
+
// Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
|
| 923 |
+
// applied recursively to the children of v, as well as the function
|
| 924 |
+
// APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
|
| 925 |
+
// node v is placed to the midpoint of its outermost children.
|
| 926 |
+
function firstWalk(v) {
|
| 927 |
+
var children = v.children,
|
| 928 |
+
siblings = v.parent.children,
|
| 929 |
+
w = v.i ? siblings[v.i - 1] : null;
|
| 930 |
+
if (children) {
|
| 931 |
+
executeShifts(v);
|
| 932 |
+
var midpoint = (children[0].z + children[children.length - 1].z) / 2;
|
| 933 |
+
if (w) {
|
| 934 |
+
v.z = w.z + separation(v._, w._);
|
| 935 |
+
v.m = v.z - midpoint;
|
| 936 |
+
} else {
|
| 937 |
+
v.z = midpoint;
|
| 938 |
+
}
|
| 939 |
+
} else if (w) {
|
| 940 |
+
v.z = w.z + separation(v._, w._);
|
| 941 |
+
}
|
| 942 |
+
v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
|
| 943 |
+
}
|
| 944 |
+
|
| 945 |
+
// Computes all real x-coordinates by summing up the modifiers recursively.
|
| 946 |
+
function secondWalk(v) {
|
| 947 |
+
v._.x = v.z + v.parent.m;
|
| 948 |
+
v.m += v.parent.m;
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
// The core of the algorithm. Here, a new subtree is combined with the
|
| 952 |
+
// previous subtrees. Threads are used to traverse the inside and outside
|
| 953 |
+
// contours of the left and right subtree up to the highest common level. The
|
| 954 |
+
// vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
|
| 955 |
+
// superscript o means outside and i means inside, the subscript - means left
|
| 956 |
+
// subtree and + means right subtree. For summing up the modifiers along the
|
| 957 |
+
// contour, we use respective variables si+, si-, so-, and so+. Whenever two
|
| 958 |
+
// nodes of the inside contours conflict, we compute the left one of the
|
| 959 |
+
// greatest uncommon ancestors using the function ANCESTOR and call MOVE
|
| 960 |
+
// SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
|
| 961 |
+
// Finally, we add a new thread (if necessary).
|
| 962 |
+
function apportion(v, w, ancestor) {
|
| 963 |
+
if (w) {
|
| 964 |
+
var vip = v,
|
| 965 |
+
vop = v,
|
| 966 |
+
vim = w,
|
| 967 |
+
vom = vip.parent.children[0],
|
| 968 |
+
sip = vip.m,
|
| 969 |
+
sop = vop.m,
|
| 970 |
+
sim = vim.m,
|
| 971 |
+
som = vom.m,
|
| 972 |
+
shift;
|
| 973 |
+
while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
|
| 974 |
+
vom = nextLeft(vom);
|
| 975 |
+
vop = nextRight(vop);
|
| 976 |
+
vop.a = v;
|
| 977 |
+
shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
|
| 978 |
+
if (shift > 0) {
|
| 979 |
+
moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
|
| 980 |
+
sip += shift;
|
| 981 |
+
sop += shift;
|
| 982 |
+
}
|
| 983 |
+
sim += vim.m;
|
| 984 |
+
sip += vip.m;
|
| 985 |
+
som += vom.m;
|
| 986 |
+
sop += vop.m;
|
| 987 |
+
}
|
| 988 |
+
if (vim && !nextRight(vop)) {
|
| 989 |
+
vop.t = vim;
|
| 990 |
+
vop.m += sim - sop;
|
| 991 |
+
}
|
| 992 |
+
if (vip && !nextLeft(vom)) {
|
| 993 |
+
vom.t = vip;
|
| 994 |
+
vom.m += sip - som;
|
| 995 |
+
ancestor = v;
|
| 996 |
+
}
|
| 997 |
+
}
|
| 998 |
+
return ancestor;
|
| 999 |
+
}
|
| 1000 |
+
|
| 1001 |
+
function sizeNode(node) {
|
| 1002 |
+
node.x *= dx;
|
| 1003 |
+
node.y = node.depth * dy;
|
| 1004 |
+
}
|
| 1005 |
+
|
| 1006 |
+
tree.separation = function(x) {
|
| 1007 |
+
return arguments.length ? (separation = x, tree) : separation;
|
| 1008 |
+
};
|
| 1009 |
+
|
| 1010 |
+
tree.size = function(x) {
|
| 1011 |
+
return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
|
| 1012 |
+
};
|
| 1013 |
+
|
| 1014 |
+
tree.nodeSize = function(x) {
|
| 1015 |
+
return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
|
| 1016 |
+
};
|
| 1017 |
+
|
| 1018 |
+
return tree;
|
| 1019 |
+
}
|
| 1020 |
+
|
| 1021 |
+
function treemapSlice(parent, x0, y0, x1, y1) {
|
| 1022 |
+
var nodes = parent.children,
|
| 1023 |
+
node,
|
| 1024 |
+
i = -1,
|
| 1025 |
+
n = nodes.length,
|
| 1026 |
+
k = parent.value && (y1 - y0) / parent.value;
|
| 1027 |
+
|
| 1028 |
+
while (++i < n) {
|
| 1029 |
+
node = nodes[i], node.x0 = x0, node.x1 = x1;
|
| 1030 |
+
node.y0 = y0, node.y1 = y0 += node.value * k;
|
| 1031 |
+
}
|
| 1032 |
+
}
|
| 1033 |
+
|
| 1034 |
+
var phi = (1 + Math.sqrt(5)) / 2;
|
| 1035 |
+
|
| 1036 |
+
function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
|
| 1037 |
+
var rows = [],
|
| 1038 |
+
nodes = parent.children,
|
| 1039 |
+
row,
|
| 1040 |
+
nodeValue,
|
| 1041 |
+
i0 = 0,
|
| 1042 |
+
i1 = 0,
|
| 1043 |
+
n = nodes.length,
|
| 1044 |
+
dx, dy,
|
| 1045 |
+
value = parent.value,
|
| 1046 |
+
sumValue,
|
| 1047 |
+
minValue,
|
| 1048 |
+
maxValue,
|
| 1049 |
+
newRatio,
|
| 1050 |
+
minRatio,
|
| 1051 |
+
alpha,
|
| 1052 |
+
beta;
|
| 1053 |
+
|
| 1054 |
+
while (i0 < n) {
|
| 1055 |
+
dx = x1 - x0, dy = y1 - y0;
|
| 1056 |
+
|
| 1057 |
+
// Find the next non-empty node.
|
| 1058 |
+
do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
|
| 1059 |
+
minValue = maxValue = sumValue;
|
| 1060 |
+
alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
|
| 1061 |
+
beta = sumValue * sumValue * alpha;
|
| 1062 |
+
minRatio = Math.max(maxValue / beta, beta / minValue);
|
| 1063 |
+
|
| 1064 |
+
// Keep adding nodes while the aspect ratio maintains or improves.
|
| 1065 |
+
for (; i1 < n; ++i1) {
|
| 1066 |
+
sumValue += nodeValue = nodes[i1].value;
|
| 1067 |
+
if (nodeValue < minValue) minValue = nodeValue;
|
| 1068 |
+
if (nodeValue > maxValue) maxValue = nodeValue;
|
| 1069 |
+
beta = sumValue * sumValue * alpha;
|
| 1070 |
+
newRatio = Math.max(maxValue / beta, beta / minValue);
|
| 1071 |
+
if (newRatio > minRatio) { sumValue -= nodeValue; break; }
|
| 1072 |
+
minRatio = newRatio;
|
| 1073 |
+
}
|
| 1074 |
+
|
| 1075 |
+
// Position and record the row orientation.
|
| 1076 |
+
rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
|
| 1077 |
+
if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
|
| 1078 |
+
else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
|
| 1079 |
+
value -= sumValue, i0 = i1;
|
| 1080 |
+
}
|
| 1081 |
+
|
| 1082 |
+
return rows;
|
| 1083 |
+
}
|
| 1084 |
+
|
| 1085 |
+
var squarify = (function custom(ratio) {
|
| 1086 |
+
|
| 1087 |
+
function squarify(parent, x0, y0, x1, y1) {
|
| 1088 |
+
squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
| 1089 |
+
}
|
| 1090 |
+
|
| 1091 |
+
squarify.ratio = function(x) {
|
| 1092 |
+
return custom((x = +x) > 1 ? x : 1);
|
| 1093 |
+
};
|
| 1094 |
+
|
| 1095 |
+
return squarify;
|
| 1096 |
+
})(phi);
|
| 1097 |
+
|
| 1098 |
+
function index$1() {
|
| 1099 |
+
var tile = squarify,
|
| 1100 |
+
round = false,
|
| 1101 |
+
dx = 1,
|
| 1102 |
+
dy = 1,
|
| 1103 |
+
paddingStack = [0],
|
| 1104 |
+
paddingInner = constantZero,
|
| 1105 |
+
paddingTop = constantZero,
|
| 1106 |
+
paddingRight = constantZero,
|
| 1107 |
+
paddingBottom = constantZero,
|
| 1108 |
+
paddingLeft = constantZero;
|
| 1109 |
+
|
| 1110 |
+
function treemap(root) {
|
| 1111 |
+
root.x0 =
|
| 1112 |
+
root.y0 = 0;
|
| 1113 |
+
root.x1 = dx;
|
| 1114 |
+
root.y1 = dy;
|
| 1115 |
+
root.eachBefore(positionNode);
|
| 1116 |
+
paddingStack = [0];
|
| 1117 |
+
if (round) root.eachBefore(roundNode);
|
| 1118 |
+
return root;
|
| 1119 |
+
}
|
| 1120 |
+
|
| 1121 |
+
function positionNode(node) {
|
| 1122 |
+
var p = paddingStack[node.depth],
|
| 1123 |
+
x0 = node.x0 + p,
|
| 1124 |
+
y0 = node.y0 + p,
|
| 1125 |
+
x1 = node.x1 - p,
|
| 1126 |
+
y1 = node.y1 - p;
|
| 1127 |
+
if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
| 1128 |
+
if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
| 1129 |
+
node.x0 = x0;
|
| 1130 |
+
node.y0 = y0;
|
| 1131 |
+
node.x1 = x1;
|
| 1132 |
+
node.y1 = y1;
|
| 1133 |
+
if (node.children) {
|
| 1134 |
+
p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
|
| 1135 |
+
x0 += paddingLeft(node) - p;
|
| 1136 |
+
y0 += paddingTop(node) - p;
|
| 1137 |
+
x1 -= paddingRight(node) - p;
|
| 1138 |
+
y1 -= paddingBottom(node) - p;
|
| 1139 |
+
if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
| 1140 |
+
if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
| 1141 |
+
tile(node, x0, y0, x1, y1);
|
| 1142 |
+
}
|
| 1143 |
+
}
|
| 1144 |
+
|
| 1145 |
+
treemap.round = function(x) {
|
| 1146 |
+
return arguments.length ? (round = !!x, treemap) : round;
|
| 1147 |
+
};
|
| 1148 |
+
|
| 1149 |
+
treemap.size = function(x) {
|
| 1150 |
+
return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
|
| 1151 |
+
};
|
| 1152 |
+
|
| 1153 |
+
treemap.tile = function(x) {
|
| 1154 |
+
return arguments.length ? (tile = required(x), treemap) : tile;
|
| 1155 |
+
};
|
| 1156 |
+
|
| 1157 |
+
treemap.padding = function(x) {
|
| 1158 |
+
return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
|
| 1159 |
+
};
|
| 1160 |
+
|
| 1161 |
+
treemap.paddingInner = function(x) {
|
| 1162 |
+
return arguments.length ? (paddingInner = typeof x === "function" ? x : constant(+x), treemap) : paddingInner;
|
| 1163 |
+
};
|
| 1164 |
+
|
| 1165 |
+
treemap.paddingOuter = function(x) {
|
| 1166 |
+
return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
|
| 1167 |
+
};
|
| 1168 |
+
|
| 1169 |
+
treemap.paddingTop = function(x) {
|
| 1170 |
+
return arguments.length ? (paddingTop = typeof x === "function" ? x : constant(+x), treemap) : paddingTop;
|
| 1171 |
+
};
|
| 1172 |
+
|
| 1173 |
+
treemap.paddingRight = function(x) {
|
| 1174 |
+
return arguments.length ? (paddingRight = typeof x === "function" ? x : constant(+x), treemap) : paddingRight;
|
| 1175 |
+
};
|
| 1176 |
+
|
| 1177 |
+
treemap.paddingBottom = function(x) {
|
| 1178 |
+
return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant(+x), treemap) : paddingBottom;
|
| 1179 |
+
};
|
| 1180 |
+
|
| 1181 |
+
treemap.paddingLeft = function(x) {
|
| 1182 |
+
return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant(+x), treemap) : paddingLeft;
|
| 1183 |
+
};
|
| 1184 |
+
|
| 1185 |
+
return treemap;
|
| 1186 |
+
}
|
| 1187 |
+
|
| 1188 |
+
function binary(parent, x0, y0, x1, y1) {
|
| 1189 |
+
var nodes = parent.children,
|
| 1190 |
+
i, n = nodes.length,
|
| 1191 |
+
sum, sums = new Array(n + 1);
|
| 1192 |
+
|
| 1193 |
+
for (sums[0] = sum = i = 0; i < n; ++i) {
|
| 1194 |
+
sums[i + 1] = sum += nodes[i].value;
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
partition(0, n, parent.value, x0, y0, x1, y1);
|
| 1198 |
+
|
| 1199 |
+
function partition(i, j, value, x0, y0, x1, y1) {
|
| 1200 |
+
if (i >= j - 1) {
|
| 1201 |
+
var node = nodes[i];
|
| 1202 |
+
node.x0 = x0, node.y0 = y0;
|
| 1203 |
+
node.x1 = x1, node.y1 = y1;
|
| 1204 |
+
return;
|
| 1205 |
+
}
|
| 1206 |
+
|
| 1207 |
+
var valueOffset = sums[i],
|
| 1208 |
+
valueTarget = (value / 2) + valueOffset,
|
| 1209 |
+
k = i + 1,
|
| 1210 |
+
hi = j - 1;
|
| 1211 |
+
|
| 1212 |
+
while (k < hi) {
|
| 1213 |
+
var mid = k + hi >>> 1;
|
| 1214 |
+
if (sums[mid] < valueTarget) k = mid + 1;
|
| 1215 |
+
else hi = mid;
|
| 1216 |
+
}
|
| 1217 |
+
|
| 1218 |
+
if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
|
| 1219 |
+
|
| 1220 |
+
var valueLeft = sums[k] - valueOffset,
|
| 1221 |
+
valueRight = value - valueLeft;
|
| 1222 |
+
|
| 1223 |
+
if ((x1 - x0) > (y1 - y0)) {
|
| 1224 |
+
var xk = (x0 * valueRight + x1 * valueLeft) / value;
|
| 1225 |
+
partition(i, k, valueLeft, x0, y0, xk, y1);
|
| 1226 |
+
partition(k, j, valueRight, xk, y0, x1, y1);
|
| 1227 |
+
} else {
|
| 1228 |
+
var yk = (y0 * valueRight + y1 * valueLeft) / value;
|
| 1229 |
+
partition(i, k, valueLeft, x0, y0, x1, yk);
|
| 1230 |
+
partition(k, j, valueRight, x0, yk, x1, y1);
|
| 1231 |
+
}
|
| 1232 |
+
}
|
| 1233 |
+
}
|
| 1234 |
+
|
| 1235 |
+
function sliceDice(parent, x0, y0, x1, y1) {
|
| 1236 |
+
(parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
|
| 1237 |
+
}
|
| 1238 |
+
|
| 1239 |
+
var resquarify = (function custom(ratio) {
|
| 1240 |
+
|
| 1241 |
+
function resquarify(parent, x0, y0, x1, y1) {
|
| 1242 |
+
if ((rows = parent._squarify) && (rows.ratio === ratio)) {
|
| 1243 |
+
var rows,
|
| 1244 |
+
row,
|
| 1245 |
+
nodes,
|
| 1246 |
+
i,
|
| 1247 |
+
j = -1,
|
| 1248 |
+
n,
|
| 1249 |
+
m = rows.length,
|
| 1250 |
+
value = parent.value;
|
| 1251 |
+
|
| 1252 |
+
while (++j < m) {
|
| 1253 |
+
row = rows[j], nodes = row.children;
|
| 1254 |
+
for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
|
| 1255 |
+
if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
|
| 1256 |
+
else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
|
| 1257 |
+
value -= row.value;
|
| 1258 |
+
}
|
| 1259 |
+
} else {
|
| 1260 |
+
parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
| 1261 |
+
rows.ratio = ratio;
|
| 1262 |
+
}
|
| 1263 |
+
}
|
| 1264 |
+
|
| 1265 |
+
resquarify.ratio = function(x) {
|
| 1266 |
+
return custom((x = +x) > 1 ? x : 1);
|
| 1267 |
+
};
|
| 1268 |
+
|
| 1269 |
+
return resquarify;
|
| 1270 |
+
})(phi);
|
| 1271 |
+
|
| 1272 |
+
exports.cluster = cluster;
|
| 1273 |
+
exports.hierarchy = hierarchy;
|
| 1274 |
+
exports.pack = index;
|
| 1275 |
+
exports.packEnclose = enclose;
|
| 1276 |
+
exports.packSiblings = siblings;
|
| 1277 |
+
exports.partition = partition;
|
| 1278 |
+
exports.stratify = stratify;
|
| 1279 |
+
exports.tree = tree;
|
| 1280 |
+
exports.treemap = index$1;
|
| 1281 |
+
exports.treemapBinary = binary;
|
| 1282 |
+
exports.treemapDice = treemapDice;
|
| 1283 |
+
exports.treemapResquarify = resquarify;
|
| 1284 |
+
exports.treemapSlice = treemapSlice;
|
| 1285 |
+
exports.treemapSliceDice = sliceDice;
|
| 1286 |
+
exports.treemapSquarify = squarify;
|
| 1287 |
+
|
| 1288 |
+
Object.defineProperty(exports, '__esModule', { value: true });
|
| 1289 |
+
|
| 1290 |
+
}));
|
node_modules/d3-hierarchy/dist/d3-hierarchy.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// https://d3js.org/d3-hierarchy/ v1.1.9 Copyright 2019 Mike Bostock
|
| 2 |
+
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((n=n||self).d3=n.d3||{})}(this,function(n){"use strict";function r(n,r){return n.parent===r.parent?1:2}function e(n,r){return n+r.x}function t(n,r){return Math.max(n,r.y)}function u(n){var r=0,e=n.children,t=e&&e.length;if(t)for(;--t>=0;)r+=e[t].value;else r=1;n.value=r}function i(n,r){var e,t,u,i,a,h=new c(n),l=+n.value&&(h.value=n.value),p=[h];for(null==r&&(r=o);e=p.pop();)if(l&&(e.value=+e.data.value),(u=r(e.data))&&(a=u.length))for(e.children=new Array(a),i=a-1;i>=0;--i)p.push(t=e.children[i]=new c(u[i])),t.parent=e,t.depth=e.depth+1;return h.eachBefore(f)}function o(n){return n.children}function a(n){n.data=n.data.data}function f(n){var r=0;do{n.height=r}while((n=n.parent)&&n.height<++r)}function c(n){this.data=n,this.depth=this.height=0,this.parent=null}c.prototype=i.prototype={constructor:c,count:function(){return this.eachAfter(u)},each:function(n){var r,e,t,u,i=this,o=[i];do{for(r=o.reverse(),o=[];i=r.pop();)if(n(i),e=i.children)for(t=0,u=e.length;t<u;++t)o.push(e[t])}while(o.length);return this},eachAfter:function(n){for(var r,e,t,u=this,i=[u],o=[];u=i.pop();)if(o.push(u),r=u.children)for(e=0,t=r.length;e<t;++e)i.push(r[e]);for(;u=o.pop();)n(u);return this},eachBefore:function(n){for(var r,e,t=this,u=[t];t=u.pop();)if(n(t),r=t.children)for(e=r.length-1;e>=0;--e)u.push(r[e]);return this},sum:function(n){return this.eachAfter(function(r){for(var e=+n(r.data)||0,t=r.children,u=t&&t.length;--u>=0;)e+=t[u].value;r.value=e})},sort:function(n){return this.eachBefore(function(r){r.children&&r.children.sort(n)})},path:function(n){for(var r=this,e=function(n,r){if(n===r)return n;var e=n.ancestors(),t=r.ancestors(),u=null;for(n=e.pop(),r=t.pop();n===r;)u=n,n=e.pop(),r=t.pop();return u}(r,n),t=[r];r!==e;)r=r.parent,t.push(r);for(var u=t.length;n!==e;)t.splice(u,0,n),n=n.parent;return t},ancestors:function(){for(var n=this,r=[n];n=n.parent;)r.push(n);return r},descendants:function(){var n=[];return this.each(function(r){n.push(r)}),n},leaves:function(){var n=[];return this.eachBefore(function(r){r.children||n.push(r)}),n},links:function(){var n=this,r=[];return n.each(function(e){e!==n&&r.push({source:e.parent,target:e})}),r},copy:function(){return i(this).eachBefore(a)}};var h=Array.prototype.slice;function l(n){for(var r,e,t=0,u=(n=function(n){for(var r,e,t=n.length;t;)e=Math.random()*t--|0,r=n[t],n[t]=n[e],n[e]=r;return n}(h.call(n))).length,i=[];t<u;)r=n[t],e&&s(e,r)?++t:(e=x(i=p(i,r)),t=0);return e}function p(n,r){var e,t;if(v(r,n))return[r];for(e=0;e<n.length;++e)if(d(r,n[e])&&v(y(n[e],r),n))return[n[e],r];for(e=0;e<n.length-1;++e)for(t=e+1;t<n.length;++t)if(d(y(n[e],n[t]),r)&&d(y(n[e],r),n[t])&&d(y(n[t],r),n[e])&&v(g(n[e],n[t],r),n))return[n[e],n[t],r];throw new Error}function d(n,r){var e=n.r-r.r,t=r.x-n.x,u=r.y-n.y;return e<0||e*e<t*t+u*u}function s(n,r){var e=n.r-r.r+1e-6,t=r.x-n.x,u=r.y-n.y;return e>0&&e*e>t*t+u*u}function v(n,r){for(var e=0;e<r.length;++e)if(!s(n,r[e]))return!1;return!0}function x(n){switch(n.length){case 1:return{x:(r=n[0]).x,y:r.y,r:r.r};case 2:return y(n[0],n[1]);case 3:return g(n[0],n[1],n[2])}var r}function y(n,r){var e=n.x,t=n.y,u=n.r,i=r.x,o=r.y,a=r.r,f=i-e,c=o-t,h=a-u,l=Math.sqrt(f*f+c*c);return{x:(e+i+f/l*h)/2,y:(t+o+c/l*h)/2,r:(l+u+a)/2}}function g(n,r,e){var t=n.x,u=n.y,i=n.r,o=r.x,a=r.y,f=r.r,c=e.x,h=e.y,l=e.r,p=t-o,d=t-c,s=u-a,v=u-h,x=f-i,y=l-i,g=t*t+u*u-i*i,m=g-o*o-a*a+f*f,w=g-c*c-h*h+l*l,_=d*s-p*v,z=(s*w-v*m)/(2*_)-t,B=(v*x-s*y)/_,M=(d*m-p*w)/(2*_)-u,A=(p*y-d*x)/_,q=B*B+A*A-1,E=2*(i+z*B+M*A),b=z*z+M*M-i*i,S=-(q?(E+Math.sqrt(E*E-4*q*b))/(2*q):b/E);return{x:t+z+B*S,y:u+M+A*S,r:S}}function m(n,r,e){var t,u,i,o,a=n.x-r.x,f=n.y-r.y,c=a*a+f*f;c?(u=r.r+e.r,u*=u,o=n.r+e.r,u>(o*=o)?(t=(c+o-u)/(2*c),i=Math.sqrt(Math.max(0,o/c-t*t)),e.x=n.x-t*a-i*f,e.y=n.y-t*f+i*a):(t=(c+u-o)/(2*c),i=Math.sqrt(Math.max(0,u/c-t*t)),e.x=r.x+t*a-i*f,e.y=r.y+t*f+i*a)):(e.x=r.x+e.r,e.y=r.y)}function w(n,r){var e=n.r+r.r-1e-6,t=r.x-n.x,u=r.y-n.y;return e>0&&e*e>t*t+u*u}function _(n){var r=n._,e=n.next._,t=r.r+e.r,u=(r.x*e.r+e.x*r.r)/t,i=(r.y*e.r+e.y*r.r)/t;return u*u+i*i}function z(n){this._=n,this.next=null,this.previous=null}function B(n){if(!(u=n.length))return 0;var r,e,t,u,i,o,a,f,c,h,p;if((r=n[0]).x=0,r.y=0,!(u>1))return r.r;if(e=n[1],r.x=-e.r,e.x=r.r,e.y=0,!(u>2))return r.r+e.r;m(e,r,t=n[2]),r=new z(r),e=new z(e),t=new z(t),r.next=t.previous=e,e.next=r.previous=t,t.next=e.previous=r;n:for(a=3;a<u;++a){m(r._,e._,t=n[a]),t=new z(t),f=e.next,c=r.previous,h=e._.r,p=r._.r;do{if(h<=p){if(w(f._,t._)){e=f,r.next=e,e.previous=r,--a;continue n}h+=f._.r,f=f.next}else{if(w(c._,t._)){(r=c).next=e,e.previous=r,--a;continue n}p+=c._.r,c=c.previous}}while(f!==c.next);for(t.previous=r,t.next=e,r.next=e.previous=e=t,i=_(r);(t=t.next)!==e;)(o=_(t))<i&&(r=t,i=o);e=r.next}for(r=[e._],t=e;(t=t.next)!==e;)r.push(t._);for(t=l(r),a=0;a<u;++a)(r=n[a]).x-=t.x,r.y-=t.y;return t.r}function M(n){return null==n?null:A(n)}function A(n){if("function"!=typeof n)throw new Error;return n}function q(){return 0}function E(n){return function(){return n}}function b(n){return Math.sqrt(n.value)}function S(n){return function(r){r.children||(r.r=Math.max(0,+n(r)||0))}}function k(n,r){return function(e){if(t=e.children){var t,u,i,o=t.length,a=n(e)*r||0;if(a)for(u=0;u<o;++u)t[u].r+=a;if(i=B(t),a)for(u=0;u<o;++u)t[u].r-=a;e.r=i+a}}}function I(n){return function(r){var e=r.parent;r.r*=n,e&&(r.x=e.x+n*r.x,r.y=e.y+n*r.y)}}function O(n){n.x0=Math.round(n.x0),n.y0=Math.round(n.y0),n.x1=Math.round(n.x1),n.y1=Math.round(n.y1)}function j(n,r,e,t,u){for(var i,o=n.children,a=-1,f=o.length,c=n.value&&(t-r)/n.value;++a<f;)(i=o[a]).y0=e,i.y1=u,i.x0=r,i.x1=r+=i.value*c}var R="$",T={depth:-1},D={};function L(n){return n.id}function P(n){return n.parentId}function $(n,r){return n.parent===r.parent?1:2}function C(n){var r=n.children;return r?r[0]:n.t}function F(n){var r=n.children;return r?r[r.length-1]:n.t}function G(n,r,e){var t=e/(r.i-n.i);r.c-=t,r.s+=e,n.c+=t,r.z+=e,r.m+=e}function H(n,r,e){return n.a.parent===r.parent?n.a:e}function J(n,r){this._=n,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=r}function K(n,r,e,t,u){for(var i,o=n.children,a=-1,f=o.length,c=n.value&&(u-e)/n.value;++a<f;)(i=o[a]).x0=r,i.x1=t,i.y0=e,i.y1=e+=i.value*c}J.prototype=Object.create(c.prototype);var N=(1+Math.sqrt(5))/2;function Q(n,r,e,t,u,i){for(var o,a,f,c,h,l,p,d,s,v,x,y=[],g=r.children,m=0,w=0,_=g.length,z=r.value;m<_;){f=u-e,c=i-t;do{h=g[w++].value}while(!h&&w<_);for(l=p=h,x=h*h*(v=Math.max(c/f,f/c)/(z*n)),s=Math.max(p/x,x/l);w<_;++w){if(h+=a=g[w].value,a<l&&(l=a),a>p&&(p=a),x=h*h*v,(d=Math.max(p/x,x/l))>s){h-=a;break}s=d}y.push(o={value:h,dice:f<c,children:g.slice(m,w)}),o.dice?j(o,e,t,u,z?t+=c*h/z:i):K(o,e,t,z?e+=f*h/z:u,i),z-=h,m=w}return y}var U=function n(r){function e(n,e,t,u,i){Q(r,n,e,t,u,i)}return e.ratio=function(r){return n((r=+r)>1?r:1)},e}(N);var V=function n(r){function e(n,e,t,u,i){if((o=n._squarify)&&o.ratio===r)for(var o,a,f,c,h,l=-1,p=o.length,d=n.value;++l<p;){for(f=(a=o[l]).children,c=a.value=0,h=f.length;c<h;++c)a.value+=f[c].value;a.dice?j(a,e,t,u,t+=(i-t)*a.value/d):K(a,e,t,e+=(u-e)*a.value/d,i),d-=a.value}else n._squarify=o=Q(r,n,e,t,u,i),o.ratio=r}return e.ratio=function(r){return n((r=+r)>1?r:1)},e}(N);n.cluster=function(){var n=r,u=1,i=1,o=!1;function a(r){var a,f=0;r.eachAfter(function(r){var u=r.children;u?(r.x=function(n){return n.reduce(e,0)/n.length}(u),r.y=function(n){return 1+n.reduce(t,0)}(u)):(r.x=a?f+=n(r,a):0,r.y=0,a=r)});var c=function(n){for(var r;r=n.children;)n=r[0];return n}(r),h=function(n){for(var r;r=n.children;)n=r[r.length-1];return n}(r),l=c.x-n(c,h)/2,p=h.x+n(h,c)/2;return r.eachAfter(o?function(n){n.x=(n.x-r.x)*u,n.y=(r.y-n.y)*i}:function(n){n.x=(n.x-l)/(p-l)*u,n.y=(1-(r.y?n.y/r.y:1))*i})}return a.separation=function(r){return arguments.length?(n=r,a):n},a.size=function(n){return arguments.length?(o=!1,u=+n[0],i=+n[1],a):o?null:[u,i]},a.nodeSize=function(n){return arguments.length?(o=!0,u=+n[0],i=+n[1],a):o?[u,i]:null},a},n.hierarchy=i,n.pack=function(){var n=null,r=1,e=1,t=q;function u(u){return u.x=r/2,u.y=e/2,n?u.eachBefore(S(n)).eachAfter(k(t,.5)).eachBefore(I(1)):u.eachBefore(S(b)).eachAfter(k(q,1)).eachAfter(k(t,u.r/Math.min(r,e))).eachBefore(I(Math.min(r,e)/(2*u.r))),u}return u.radius=function(r){return arguments.length?(n=M(r),u):n},u.size=function(n){return arguments.length?(r=+n[0],e=+n[1],u):[r,e]},u.padding=function(n){return arguments.length?(t="function"==typeof n?n:E(+n),u):t},u},n.packEnclose=l,n.packSiblings=function(n){return B(n),n},n.partition=function(){var n=1,r=1,e=0,t=!1;function u(u){var i=u.height+1;return u.x0=u.y0=e,u.x1=n,u.y1=r/i,u.eachBefore(function(n,r){return function(t){t.children&&j(t,t.x0,n*(t.depth+1)/r,t.x1,n*(t.depth+2)/r);var u=t.x0,i=t.y0,o=t.x1-e,a=t.y1-e;o<u&&(u=o=(u+o)/2),a<i&&(i=a=(i+a)/2),t.x0=u,t.y0=i,t.x1=o,t.y1=a}}(r,i)),t&&u.eachBefore(O),u}return u.round=function(n){return arguments.length?(t=!!n,u):t},u.size=function(e){return arguments.length?(n=+e[0],r=+e[1],u):[n,r]},u.padding=function(n){return arguments.length?(e=+n,u):e},u},n.stratify=function(){var n=L,r=P;function e(e){var t,u,i,o,a,h,l,p=e.length,d=new Array(p),s={};for(u=0;u<p;++u)t=e[u],a=d[u]=new c(t),null!=(h=n(t,u,e))&&(h+="")&&(s[l=R+(a.id=h)]=l in s?D:a);for(u=0;u<p;++u)if(a=d[u],null!=(h=r(e[u],u,e))&&(h+="")){if(!(o=s[R+h]))throw new Error("missing: "+h);if(o===D)throw new Error("ambiguous: "+h);o.children?o.children.push(a):o.children=[a],a.parent=o}else{if(i)throw new Error("multiple roots");i=a}if(!i)throw new Error("no root");if(i.parent=T,i.eachBefore(function(n){n.depth=n.parent.depth+1,--p}).eachBefore(f),i.parent=null,p>0)throw new Error("cycle");return i}return e.id=function(r){return arguments.length?(n=A(r),e):n},e.parentId=function(n){return arguments.length?(r=A(n),e):r},e},n.tree=function(){var n=$,r=1,e=1,t=null;function u(u){var f=function(n){for(var r,e,t,u,i,o=new J(n,0),a=[o];r=a.pop();)if(t=r._.children)for(r.children=new Array(i=t.length),u=i-1;u>=0;--u)a.push(e=r.children[u]=new J(t[u],u)),e.parent=r;return(o.parent=new J(null,0)).children=[o],o}(u);if(f.eachAfter(i),f.parent.m=-f.z,f.eachBefore(o),t)u.eachBefore(a);else{var c=u,h=u,l=u;u.eachBefore(function(n){n.x<c.x&&(c=n),n.x>h.x&&(h=n),n.depth>l.depth&&(l=n)});var p=c===h?1:n(c,h)/2,d=p-c.x,s=r/(h.x+p+d),v=e/(l.depth||1);u.eachBefore(function(n){n.x=(n.x+d)*s,n.y=n.depth*v})}return u}function i(r){var e=r.children,t=r.parent.children,u=r.i?t[r.i-1]:null;if(e){!function(n){for(var r,e=0,t=0,u=n.children,i=u.length;--i>=0;)(r=u[i]).z+=e,r.m+=e,e+=r.s+(t+=r.c)}(r);var i=(e[0].z+e[e.length-1].z)/2;u?(r.z=u.z+n(r._,u._),r.m=r.z-i):r.z=i}else u&&(r.z=u.z+n(r._,u._));r.parent.A=function(r,e,t){if(e){for(var u,i=r,o=r,a=e,f=i.parent.children[0],c=i.m,h=o.m,l=a.m,p=f.m;a=F(a),i=C(i),a&&i;)f=C(f),(o=F(o)).a=r,(u=a.z+l-i.z-c+n(a._,i._))>0&&(G(H(a,r,t),r,u),c+=u,h+=u),l+=a.m,c+=i.m,p+=f.m,h+=o.m;a&&!F(o)&&(o.t=a,o.m+=l-h),i&&!C(f)&&(f.t=i,f.m+=c-p,t=r)}return t}(r,u,r.parent.A||t[0])}function o(n){n._.x=n.z+n.parent.m,n.m+=n.parent.m}function a(n){n.x*=r,n.y=n.depth*e}return u.separation=function(r){return arguments.length?(n=r,u):n},u.size=function(n){return arguments.length?(t=!1,r=+n[0],e=+n[1],u):t?null:[r,e]},u.nodeSize=function(n){return arguments.length?(t=!0,r=+n[0],e=+n[1],u):t?[r,e]:null},u},n.treemap=function(){var n=U,r=!1,e=1,t=1,u=[0],i=q,o=q,a=q,f=q,c=q;function h(n){return n.x0=n.y0=0,n.x1=e,n.y1=t,n.eachBefore(l),u=[0],r&&n.eachBefore(O),n}function l(r){var e=u[r.depth],t=r.x0+e,h=r.y0+e,l=r.x1-e,p=r.y1-e;l<t&&(t=l=(t+l)/2),p<h&&(h=p=(h+p)/2),r.x0=t,r.y0=h,r.x1=l,r.y1=p,r.children&&(e=u[r.depth+1]=i(r)/2,t+=c(r)-e,h+=o(r)-e,(l-=a(r)-e)<t&&(t=l=(t+l)/2),(p-=f(r)-e)<h&&(h=p=(h+p)/2),n(r,t,h,l,p))}return h.round=function(n){return arguments.length?(r=!!n,h):r},h.size=function(n){return arguments.length?(e=+n[0],t=+n[1],h):[e,t]},h.tile=function(r){return arguments.length?(n=A(r),h):n},h.padding=function(n){return arguments.length?h.paddingInner(n).paddingOuter(n):h.paddingInner()},h.paddingInner=function(n){return arguments.length?(i="function"==typeof n?n:E(+n),h):i},h.paddingOuter=function(n){return arguments.length?h.paddingTop(n).paddingRight(n).paddingBottom(n).paddingLeft(n):h.paddingTop()},h.paddingTop=function(n){return arguments.length?(o="function"==typeof n?n:E(+n),h):o},h.paddingRight=function(n){return arguments.length?(a="function"==typeof n?n:E(+n),h):a},h.paddingBottom=function(n){return arguments.length?(f="function"==typeof n?n:E(+n),h):f},h.paddingLeft=function(n){return arguments.length?(c="function"==typeof n?n:E(+n),h):c},h},n.treemapBinary=function(n,r,e,t,u){var i,o,a=n.children,f=a.length,c=new Array(f+1);for(c[0]=o=i=0;i<f;++i)c[i+1]=o+=a[i].value;!function n(r,e,t,u,i,o,f){if(r>=e-1){var h=a[r];return h.x0=u,h.y0=i,h.x1=o,void(h.y1=f)}for(var l=c[r],p=t/2+l,d=r+1,s=e-1;d<s;){var v=d+s>>>1;c[v]<p?d=v+1:s=v}p-c[d-1]<c[d]-p&&r+1<d&&--d;var x=c[d]-l,y=t-x;if(o-u>f-i){var g=(u*y+o*x)/t;n(r,d,x,u,i,g,f),n(d,e,y,g,i,o,f)}else{var m=(i*y+f*x)/t;n(r,d,x,u,i,o,m),n(d,e,y,u,m,o,f)}}(0,f,n.value,r,e,t,u)},n.treemapDice=j,n.treemapResquarify=V,n.treemapSlice=K,n.treemapSliceDice=function(n,r,e,t,u){(1&n.depth?K:j)(n,r,e,t,u)},n.treemapSquarify=U,Object.defineProperty(n,"__esModule",{value:!0})});
|
node_modules/d3-hierarchy/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "d3-hierarchy",
|
| 3 |
+
"version": "1.1.9",
|
| 4 |
+
"description": "Layout algorithms for visualizing hierarchical data.",
|
| 5 |
+
"keywords": [
|
| 6 |
+
"d3",
|
| 7 |
+
"d3-module",
|
| 8 |
+
"layout",
|
| 9 |
+
"tree",
|
| 10 |
+
"treemap",
|
| 11 |
+
"hierarchy",
|
| 12 |
+
"infovis"
|
| 13 |
+
],
|
| 14 |
+
"homepage": "https://d3js.org/d3-hierarchy/",
|
| 15 |
+
"license": "BSD-3-Clause",
|
| 16 |
+
"author": {
|
| 17 |
+
"name": "Mike Bostock",
|
| 18 |
+
"url": "http://bost.ocks.org/mike"
|
| 19 |
+
},
|
| 20 |
+
"main": "dist/d3-hierarchy.js",
|
| 21 |
+
"unpkg": "dist/d3-hierarchy.min.js",
|
| 22 |
+
"jsdelivr": "dist/d3-hierarchy.min.js",
|
| 23 |
+
"module": "src/index.js",
|
| 24 |
+
"repository": {
|
| 25 |
+
"type": "git",
|
| 26 |
+
"url": "https://github.com/d3/d3-hierarchy.git"
|
| 27 |
+
},
|
| 28 |
+
"files": [
|
| 29 |
+
"dist/**/*.js",
|
| 30 |
+
"src/**/*.js"
|
| 31 |
+
],
|
| 32 |
+
"scripts": {
|
| 33 |
+
"pretest": "rollup -c",
|
| 34 |
+
"test": "tape 'test/**/*-test.js' && eslint src test",
|
| 35 |
+
"prepublishOnly": "rm -rf dist && yarn test",
|
| 36 |
+
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd - && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js"
|
| 37 |
+
},
|
| 38 |
+
"sideEffects": false,
|
| 39 |
+
"devDependencies": {
|
| 40 |
+
"benchmark": "^2.1.4",
|
| 41 |
+
"d3-array": "1.2.0 - 2",
|
| 42 |
+
"d3-dsv": "1",
|
| 43 |
+
"d3-queue": "3",
|
| 44 |
+
"d3-random": "1.1.0 - 2",
|
| 45 |
+
"eslint": "6",
|
| 46 |
+
"rollup": "1",
|
| 47 |
+
"rollup-plugin-terser": "5",
|
| 48 |
+
"tape": "4"
|
| 49 |
+
}
|
| 50 |
+
}
|
node_modules/d3-hierarchy/src/accessors.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export function optional(f) {
|
| 2 |
+
return f == null ? null : required(f);
|
| 3 |
+
}
|
| 4 |
+
|
| 5 |
+
export function required(f) {
|
| 6 |
+
if (typeof f !== "function") throw new Error;
|
| 7 |
+
return f;
|
| 8 |
+
}
|
node_modules/d3-hierarchy/src/array.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export var slice = Array.prototype.slice;
|
| 2 |
+
|
| 3 |
+
export function shuffle(array) {
|
| 4 |
+
var m = array.length,
|
| 5 |
+
t,
|
| 6 |
+
i;
|
| 7 |
+
|
| 8 |
+
while (m) {
|
| 9 |
+
i = Math.random() * m-- | 0;
|
| 10 |
+
t = array[m];
|
| 11 |
+
array[m] = array[i];
|
| 12 |
+
array[i] = t;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
return array;
|
| 16 |
+
}
|
node_modules/d3-hierarchy/src/cluster.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function defaultSeparation(a, b) {
|
| 2 |
+
return a.parent === b.parent ? 1 : 2;
|
| 3 |
+
}
|
| 4 |
+
|
| 5 |
+
function meanX(children) {
|
| 6 |
+
return children.reduce(meanXReduce, 0) / children.length;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
function meanXReduce(x, c) {
|
| 10 |
+
return x + c.x;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
function maxY(children) {
|
| 14 |
+
return 1 + children.reduce(maxYReduce, 0);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function maxYReduce(y, c) {
|
| 18 |
+
return Math.max(y, c.y);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
function leafLeft(node) {
|
| 22 |
+
var children;
|
| 23 |
+
while (children = node.children) node = children[0];
|
| 24 |
+
return node;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
function leafRight(node) {
|
| 28 |
+
var children;
|
| 29 |
+
while (children = node.children) node = children[children.length - 1];
|
| 30 |
+
return node;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
export default function() {
|
| 34 |
+
var separation = defaultSeparation,
|
| 35 |
+
dx = 1,
|
| 36 |
+
dy = 1,
|
| 37 |
+
nodeSize = false;
|
| 38 |
+
|
| 39 |
+
function cluster(root) {
|
| 40 |
+
var previousNode,
|
| 41 |
+
x = 0;
|
| 42 |
+
|
| 43 |
+
// First walk, computing the initial x & y values.
|
| 44 |
+
root.eachAfter(function(node) {
|
| 45 |
+
var children = node.children;
|
| 46 |
+
if (children) {
|
| 47 |
+
node.x = meanX(children);
|
| 48 |
+
node.y = maxY(children);
|
| 49 |
+
} else {
|
| 50 |
+
node.x = previousNode ? x += separation(node, previousNode) : 0;
|
| 51 |
+
node.y = 0;
|
| 52 |
+
previousNode = node;
|
| 53 |
+
}
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
var left = leafLeft(root),
|
| 57 |
+
right = leafRight(root),
|
| 58 |
+
x0 = left.x - separation(left, right) / 2,
|
| 59 |
+
x1 = right.x + separation(right, left) / 2;
|
| 60 |
+
|
| 61 |
+
// Second walk, normalizing x & y to the desired size.
|
| 62 |
+
return root.eachAfter(nodeSize ? function(node) {
|
| 63 |
+
node.x = (node.x - root.x) * dx;
|
| 64 |
+
node.y = (root.y - node.y) * dy;
|
| 65 |
+
} : function(node) {
|
| 66 |
+
node.x = (node.x - x0) / (x1 - x0) * dx;
|
| 67 |
+
node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
|
| 68 |
+
});
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
cluster.separation = function(x) {
|
| 72 |
+
return arguments.length ? (separation = x, cluster) : separation;
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
cluster.size = function(x) {
|
| 76 |
+
return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
cluster.nodeSize = function(x) {
|
| 80 |
+
return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
return cluster;
|
| 84 |
+
}
|
node_modules/d3-hierarchy/src/constant.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export function constantZero() {
|
| 2 |
+
return 0;
|
| 3 |
+
}
|
| 4 |
+
|
| 5 |
+
export default function(x) {
|
| 6 |
+
return function() {
|
| 7 |
+
return x;
|
| 8 |
+
};
|
| 9 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/ancestors.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function() {
|
| 2 |
+
var node = this, nodes = [node];
|
| 3 |
+
while (node = node.parent) {
|
| 4 |
+
nodes.push(node);
|
| 5 |
+
}
|
| 6 |
+
return nodes;
|
| 7 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/count.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function count(node) {
|
| 2 |
+
var sum = 0,
|
| 3 |
+
children = node.children,
|
| 4 |
+
i = children && children.length;
|
| 5 |
+
if (!i) sum = 1;
|
| 6 |
+
else while (--i >= 0) sum += children[i].value;
|
| 7 |
+
node.value = sum;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
export default function() {
|
| 11 |
+
return this.eachAfter(count);
|
| 12 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/descendants.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function() {
|
| 2 |
+
var nodes = [];
|
| 3 |
+
this.each(function(node) {
|
| 4 |
+
nodes.push(node);
|
| 5 |
+
});
|
| 6 |
+
return nodes;
|
| 7 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/each.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(callback) {
|
| 2 |
+
var node = this, current, next = [node], children, i, n;
|
| 3 |
+
do {
|
| 4 |
+
current = next.reverse(), next = [];
|
| 5 |
+
while (node = current.pop()) {
|
| 6 |
+
callback(node), children = node.children;
|
| 7 |
+
if (children) for (i = 0, n = children.length; i < n; ++i) {
|
| 8 |
+
next.push(children[i]);
|
| 9 |
+
}
|
| 10 |
+
}
|
| 11 |
+
} while (next.length);
|
| 12 |
+
return this;
|
| 13 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/eachAfter.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(callback) {
|
| 2 |
+
var node = this, nodes = [node], next = [], children, i, n;
|
| 3 |
+
while (node = nodes.pop()) {
|
| 4 |
+
next.push(node), children = node.children;
|
| 5 |
+
if (children) for (i = 0, n = children.length; i < n; ++i) {
|
| 6 |
+
nodes.push(children[i]);
|
| 7 |
+
}
|
| 8 |
+
}
|
| 9 |
+
while (node = next.pop()) {
|
| 10 |
+
callback(node);
|
| 11 |
+
}
|
| 12 |
+
return this;
|
| 13 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/eachBefore.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(callback) {
|
| 2 |
+
var node = this, nodes = [node], children, i;
|
| 3 |
+
while (node = nodes.pop()) {
|
| 4 |
+
callback(node), children = node.children;
|
| 5 |
+
if (children) for (i = children.length - 1; i >= 0; --i) {
|
| 6 |
+
nodes.push(children[i]);
|
| 7 |
+
}
|
| 8 |
+
}
|
| 9 |
+
return this;
|
| 10 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import node_count from "./count.js";
|
| 2 |
+
import node_each from "./each.js";
|
| 3 |
+
import node_eachBefore from "./eachBefore.js";
|
| 4 |
+
import node_eachAfter from "./eachAfter.js";
|
| 5 |
+
import node_sum from "./sum.js";
|
| 6 |
+
import node_sort from "./sort.js";
|
| 7 |
+
import node_path from "./path.js";
|
| 8 |
+
import node_ancestors from "./ancestors.js";
|
| 9 |
+
import node_descendants from "./descendants.js";
|
| 10 |
+
import node_leaves from "./leaves.js";
|
| 11 |
+
import node_links from "./links.js";
|
| 12 |
+
|
| 13 |
+
export default function hierarchy(data, children) {
|
| 14 |
+
var root = new Node(data),
|
| 15 |
+
valued = +data.value && (root.value = data.value),
|
| 16 |
+
node,
|
| 17 |
+
nodes = [root],
|
| 18 |
+
child,
|
| 19 |
+
childs,
|
| 20 |
+
i,
|
| 21 |
+
n;
|
| 22 |
+
|
| 23 |
+
if (children == null) children = defaultChildren;
|
| 24 |
+
|
| 25 |
+
while (node = nodes.pop()) {
|
| 26 |
+
if (valued) node.value = +node.data.value;
|
| 27 |
+
if ((childs = children(node.data)) && (n = childs.length)) {
|
| 28 |
+
node.children = new Array(n);
|
| 29 |
+
for (i = n - 1; i >= 0; --i) {
|
| 30 |
+
nodes.push(child = node.children[i] = new Node(childs[i]));
|
| 31 |
+
child.parent = node;
|
| 32 |
+
child.depth = node.depth + 1;
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
return root.eachBefore(computeHeight);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function node_copy() {
|
| 41 |
+
return hierarchy(this).eachBefore(copyData);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
function defaultChildren(d) {
|
| 45 |
+
return d.children;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function copyData(node) {
|
| 49 |
+
node.data = node.data.data;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
export function computeHeight(node) {
|
| 53 |
+
var height = 0;
|
| 54 |
+
do node.height = height;
|
| 55 |
+
while ((node = node.parent) && (node.height < ++height));
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
export function Node(data) {
|
| 59 |
+
this.data = data;
|
| 60 |
+
this.depth =
|
| 61 |
+
this.height = 0;
|
| 62 |
+
this.parent = null;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
Node.prototype = hierarchy.prototype = {
|
| 66 |
+
constructor: Node,
|
| 67 |
+
count: node_count,
|
| 68 |
+
each: node_each,
|
| 69 |
+
eachAfter: node_eachAfter,
|
| 70 |
+
eachBefore: node_eachBefore,
|
| 71 |
+
sum: node_sum,
|
| 72 |
+
sort: node_sort,
|
| 73 |
+
path: node_path,
|
| 74 |
+
ancestors: node_ancestors,
|
| 75 |
+
descendants: node_descendants,
|
| 76 |
+
leaves: node_leaves,
|
| 77 |
+
links: node_links,
|
| 78 |
+
copy: node_copy
|
| 79 |
+
};
|
node_modules/d3-hierarchy/src/hierarchy/leaves.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function() {
|
| 2 |
+
var leaves = [];
|
| 3 |
+
this.eachBefore(function(node) {
|
| 4 |
+
if (!node.children) {
|
| 5 |
+
leaves.push(node);
|
| 6 |
+
}
|
| 7 |
+
});
|
| 8 |
+
return leaves;
|
| 9 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/links.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function() {
|
| 2 |
+
var root = this, links = [];
|
| 3 |
+
root.each(function(node) {
|
| 4 |
+
if (node !== root) { // Don’t include the root’s parent, if any.
|
| 5 |
+
links.push({source: node.parent, target: node});
|
| 6 |
+
}
|
| 7 |
+
});
|
| 8 |
+
return links;
|
| 9 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/path.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(end) {
|
| 2 |
+
var start = this,
|
| 3 |
+
ancestor = leastCommonAncestor(start, end),
|
| 4 |
+
nodes = [start];
|
| 5 |
+
while (start !== ancestor) {
|
| 6 |
+
start = start.parent;
|
| 7 |
+
nodes.push(start);
|
| 8 |
+
}
|
| 9 |
+
var k = nodes.length;
|
| 10 |
+
while (end !== ancestor) {
|
| 11 |
+
nodes.splice(k, 0, end);
|
| 12 |
+
end = end.parent;
|
| 13 |
+
}
|
| 14 |
+
return nodes;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
function leastCommonAncestor(a, b) {
|
| 18 |
+
if (a === b) return a;
|
| 19 |
+
var aNodes = a.ancestors(),
|
| 20 |
+
bNodes = b.ancestors(),
|
| 21 |
+
c = null;
|
| 22 |
+
a = aNodes.pop();
|
| 23 |
+
b = bNodes.pop();
|
| 24 |
+
while (a === b) {
|
| 25 |
+
c = a;
|
| 26 |
+
a = aNodes.pop();
|
| 27 |
+
b = bNodes.pop();
|
| 28 |
+
}
|
| 29 |
+
return c;
|
| 30 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/sort.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(compare) {
|
| 2 |
+
return this.eachBefore(function(node) {
|
| 3 |
+
if (node.children) {
|
| 4 |
+
node.children.sort(compare);
|
| 5 |
+
}
|
| 6 |
+
});
|
| 7 |
+
}
|
node_modules/d3-hierarchy/src/hierarchy/sum.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(value) {
|
| 2 |
+
return this.eachAfter(function(node) {
|
| 3 |
+
var sum = +value(node.data) || 0,
|
| 4 |
+
children = node.children,
|
| 5 |
+
i = children && children.length;
|
| 6 |
+
while (--i >= 0) sum += children[i].value;
|
| 7 |
+
node.value = sum;
|
| 8 |
+
});
|
| 9 |
+
}
|
node_modules/d3-hierarchy/src/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export {default as cluster} from "./cluster.js";
|
| 2 |
+
export {default as hierarchy} from "./hierarchy/index.js";
|
| 3 |
+
export {default as pack} from "./pack/index.js";
|
| 4 |
+
export {default as packSiblings} from "./pack/siblings.js";
|
| 5 |
+
export {default as packEnclose} from "./pack/enclose.js";
|
| 6 |
+
export {default as partition} from "./partition.js";
|
| 7 |
+
export {default as stratify} from "./stratify.js";
|
| 8 |
+
export {default as tree} from "./tree.js";
|
| 9 |
+
export {default as treemap} from "./treemap/index.js";
|
| 10 |
+
export {default as treemapBinary} from "./treemap/binary.js";
|
| 11 |
+
export {default as treemapDice} from "./treemap/dice.js";
|
| 12 |
+
export {default as treemapSlice} from "./treemap/slice.js";
|
| 13 |
+
export {default as treemapSliceDice} from "./treemap/sliceDice.js";
|
| 14 |
+
export {default as treemapSquarify} from "./treemap/squarify.js";
|
| 15 |
+
export {default as treemapResquarify} from "./treemap/resquarify.js";
|
node_modules/d3-hierarchy/src/pack/enclose.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {shuffle, slice} from "../array.js";
|
| 2 |
+
|
| 3 |
+
export default function(circles) {
|
| 4 |
+
var i = 0, n = (circles = shuffle(slice.call(circles))).length, B = [], p, e;
|
| 5 |
+
|
| 6 |
+
while (i < n) {
|
| 7 |
+
p = circles[i];
|
| 8 |
+
if (e && enclosesWeak(e, p)) ++i;
|
| 9 |
+
else e = encloseBasis(B = extendBasis(B, p)), i = 0;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
return e;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
function extendBasis(B, p) {
|
| 16 |
+
var i, j;
|
| 17 |
+
|
| 18 |
+
if (enclosesWeakAll(p, B)) return [p];
|
| 19 |
+
|
| 20 |
+
// If we get here then B must have at least one element.
|
| 21 |
+
for (i = 0; i < B.length; ++i) {
|
| 22 |
+
if (enclosesNot(p, B[i])
|
| 23 |
+
&& enclosesWeakAll(encloseBasis2(B[i], p), B)) {
|
| 24 |
+
return [B[i], p];
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// If we get here then B must have at least two elements.
|
| 29 |
+
for (i = 0; i < B.length - 1; ++i) {
|
| 30 |
+
for (j = i + 1; j < B.length; ++j) {
|
| 31 |
+
if (enclosesNot(encloseBasis2(B[i], B[j]), p)
|
| 32 |
+
&& enclosesNot(encloseBasis2(B[i], p), B[j])
|
| 33 |
+
&& enclosesNot(encloseBasis2(B[j], p), B[i])
|
| 34 |
+
&& enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
|
| 35 |
+
return [B[i], B[j], p];
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
// If we get here then something is very wrong.
|
| 41 |
+
throw new Error;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
function enclosesNot(a, b) {
|
| 45 |
+
var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
|
| 46 |
+
return dr < 0 || dr * dr < dx * dx + dy * dy;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function enclosesWeak(a, b) {
|
| 50 |
+
var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
|
| 51 |
+
return dr > 0 && dr * dr > dx * dx + dy * dy;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function enclosesWeakAll(a, B) {
|
| 55 |
+
for (var i = 0; i < B.length; ++i) {
|
| 56 |
+
if (!enclosesWeak(a, B[i])) {
|
| 57 |
+
return false;
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
return true;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
function encloseBasis(B) {
|
| 64 |
+
switch (B.length) {
|
| 65 |
+
case 1: return encloseBasis1(B[0]);
|
| 66 |
+
case 2: return encloseBasis2(B[0], B[1]);
|
| 67 |
+
case 3: return encloseBasis3(B[0], B[1], B[2]);
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
function encloseBasis1(a) {
|
| 72 |
+
return {
|
| 73 |
+
x: a.x,
|
| 74 |
+
y: a.y,
|
| 75 |
+
r: a.r
|
| 76 |
+
};
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function encloseBasis2(a, b) {
|
| 80 |
+
var x1 = a.x, y1 = a.y, r1 = a.r,
|
| 81 |
+
x2 = b.x, y2 = b.y, r2 = b.r,
|
| 82 |
+
x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
|
| 83 |
+
l = Math.sqrt(x21 * x21 + y21 * y21);
|
| 84 |
+
return {
|
| 85 |
+
x: (x1 + x2 + x21 / l * r21) / 2,
|
| 86 |
+
y: (y1 + y2 + y21 / l * r21) / 2,
|
| 87 |
+
r: (l + r1 + r2) / 2
|
| 88 |
+
};
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
function encloseBasis3(a, b, c) {
|
| 92 |
+
var x1 = a.x, y1 = a.y, r1 = a.r,
|
| 93 |
+
x2 = b.x, y2 = b.y, r2 = b.r,
|
| 94 |
+
x3 = c.x, y3 = c.y, r3 = c.r,
|
| 95 |
+
a2 = x1 - x2,
|
| 96 |
+
a3 = x1 - x3,
|
| 97 |
+
b2 = y1 - y2,
|
| 98 |
+
b3 = y1 - y3,
|
| 99 |
+
c2 = r2 - r1,
|
| 100 |
+
c3 = r3 - r1,
|
| 101 |
+
d1 = x1 * x1 + y1 * y1 - r1 * r1,
|
| 102 |
+
d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
|
| 103 |
+
d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
|
| 104 |
+
ab = a3 * b2 - a2 * b3,
|
| 105 |
+
xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
|
| 106 |
+
xb = (b3 * c2 - b2 * c3) / ab,
|
| 107 |
+
ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
|
| 108 |
+
yb = (a2 * c3 - a3 * c2) / ab,
|
| 109 |
+
A = xb * xb + yb * yb - 1,
|
| 110 |
+
B = 2 * (r1 + xa * xb + ya * yb),
|
| 111 |
+
C = xa * xa + ya * ya - r1 * r1,
|
| 112 |
+
r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
|
| 113 |
+
return {
|
| 114 |
+
x: x1 + xa + xb * r,
|
| 115 |
+
y: y1 + ya + yb * r,
|
| 116 |
+
r: r
|
| 117 |
+
};
|
| 118 |
+
}
|
node_modules/d3-hierarchy/src/pack/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {packEnclose} from "./siblings.js";
|
| 2 |
+
import {optional} from "../accessors.js";
|
| 3 |
+
import constant, {constantZero} from "../constant.js";
|
| 4 |
+
|
| 5 |
+
function defaultRadius(d) {
|
| 6 |
+
return Math.sqrt(d.value);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export default function() {
|
| 10 |
+
var radius = null,
|
| 11 |
+
dx = 1,
|
| 12 |
+
dy = 1,
|
| 13 |
+
padding = constantZero;
|
| 14 |
+
|
| 15 |
+
function pack(root) {
|
| 16 |
+
root.x = dx / 2, root.y = dy / 2;
|
| 17 |
+
if (radius) {
|
| 18 |
+
root.eachBefore(radiusLeaf(radius))
|
| 19 |
+
.eachAfter(packChildren(padding, 0.5))
|
| 20 |
+
.eachBefore(translateChild(1));
|
| 21 |
+
} else {
|
| 22 |
+
root.eachBefore(radiusLeaf(defaultRadius))
|
| 23 |
+
.eachAfter(packChildren(constantZero, 1))
|
| 24 |
+
.eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
|
| 25 |
+
.eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
|
| 26 |
+
}
|
| 27 |
+
return root;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
pack.radius = function(x) {
|
| 31 |
+
return arguments.length ? (radius = optional(x), pack) : radius;
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
pack.size = function(x) {
|
| 35 |
+
return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
pack.padding = function(x) {
|
| 39 |
+
return arguments.length ? (padding = typeof x === "function" ? x : constant(+x), pack) : padding;
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
return pack;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
function radiusLeaf(radius) {
|
| 46 |
+
return function(node) {
|
| 47 |
+
if (!node.children) {
|
| 48 |
+
node.r = Math.max(0, +radius(node) || 0);
|
| 49 |
+
}
|
| 50 |
+
};
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function packChildren(padding, k) {
|
| 54 |
+
return function(node) {
|
| 55 |
+
if (children = node.children) {
|
| 56 |
+
var children,
|
| 57 |
+
i,
|
| 58 |
+
n = children.length,
|
| 59 |
+
r = padding(node) * k || 0,
|
| 60 |
+
e;
|
| 61 |
+
|
| 62 |
+
if (r) for (i = 0; i < n; ++i) children[i].r += r;
|
| 63 |
+
e = packEnclose(children);
|
| 64 |
+
if (r) for (i = 0; i < n; ++i) children[i].r -= r;
|
| 65 |
+
node.r = e + r;
|
| 66 |
+
}
|
| 67 |
+
};
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
function translateChild(k) {
|
| 71 |
+
return function(node) {
|
| 72 |
+
var parent = node.parent;
|
| 73 |
+
node.r *= k;
|
| 74 |
+
if (parent) {
|
| 75 |
+
node.x = parent.x + k * node.x;
|
| 76 |
+
node.y = parent.y + k * node.y;
|
| 77 |
+
}
|
| 78 |
+
};
|
| 79 |
+
}
|
node_modules/d3-hierarchy/src/pack/siblings.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import enclose from "./enclose.js";
|
| 2 |
+
|
| 3 |
+
function place(b, a, c) {
|
| 4 |
+
var dx = b.x - a.x, x, a2,
|
| 5 |
+
dy = b.y - a.y, y, b2,
|
| 6 |
+
d2 = dx * dx + dy * dy;
|
| 7 |
+
if (d2) {
|
| 8 |
+
a2 = a.r + c.r, a2 *= a2;
|
| 9 |
+
b2 = b.r + c.r, b2 *= b2;
|
| 10 |
+
if (a2 > b2) {
|
| 11 |
+
x = (d2 + b2 - a2) / (2 * d2);
|
| 12 |
+
y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
|
| 13 |
+
c.x = b.x - x * dx - y * dy;
|
| 14 |
+
c.y = b.y - x * dy + y * dx;
|
| 15 |
+
} else {
|
| 16 |
+
x = (d2 + a2 - b2) / (2 * d2);
|
| 17 |
+
y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
|
| 18 |
+
c.x = a.x + x * dx - y * dy;
|
| 19 |
+
c.y = a.y + x * dy + y * dx;
|
| 20 |
+
}
|
| 21 |
+
} else {
|
| 22 |
+
c.x = a.x + c.r;
|
| 23 |
+
c.y = a.y;
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
function intersects(a, b) {
|
| 28 |
+
var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
|
| 29 |
+
return dr > 0 && dr * dr > dx * dx + dy * dy;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
function score(node) {
|
| 33 |
+
var a = node._,
|
| 34 |
+
b = node.next._,
|
| 35 |
+
ab = a.r + b.r,
|
| 36 |
+
dx = (a.x * b.r + b.x * a.r) / ab,
|
| 37 |
+
dy = (a.y * b.r + b.y * a.r) / ab;
|
| 38 |
+
return dx * dx + dy * dy;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
function Node(circle) {
|
| 42 |
+
this._ = circle;
|
| 43 |
+
this.next = null;
|
| 44 |
+
this.previous = null;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
export function packEnclose(circles) {
|
| 48 |
+
if (!(n = circles.length)) return 0;
|
| 49 |
+
|
| 50 |
+
var a, b, c, n, aa, ca, i, j, k, sj, sk;
|
| 51 |
+
|
| 52 |
+
// Place the first circle.
|
| 53 |
+
a = circles[0], a.x = 0, a.y = 0;
|
| 54 |
+
if (!(n > 1)) return a.r;
|
| 55 |
+
|
| 56 |
+
// Place the second circle.
|
| 57 |
+
b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
|
| 58 |
+
if (!(n > 2)) return a.r + b.r;
|
| 59 |
+
|
| 60 |
+
// Place the third circle.
|
| 61 |
+
place(b, a, c = circles[2]);
|
| 62 |
+
|
| 63 |
+
// Initialize the front-chain using the first three circles a, b and c.
|
| 64 |
+
a = new Node(a), b = new Node(b), c = new Node(c);
|
| 65 |
+
a.next = c.previous = b;
|
| 66 |
+
b.next = a.previous = c;
|
| 67 |
+
c.next = b.previous = a;
|
| 68 |
+
|
| 69 |
+
// Attempt to place each remaining circle…
|
| 70 |
+
pack: for (i = 3; i < n; ++i) {
|
| 71 |
+
place(a._, b._, c = circles[i]), c = new Node(c);
|
| 72 |
+
|
| 73 |
+
// Find the closest intersecting circle on the front-chain, if any.
|
| 74 |
+
// “Closeness” is determined by linear distance along the front-chain.
|
| 75 |
+
// “Ahead” or “behind” is likewise determined by linear distance.
|
| 76 |
+
j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
|
| 77 |
+
do {
|
| 78 |
+
if (sj <= sk) {
|
| 79 |
+
if (intersects(j._, c._)) {
|
| 80 |
+
b = j, a.next = b, b.previous = a, --i;
|
| 81 |
+
continue pack;
|
| 82 |
+
}
|
| 83 |
+
sj += j._.r, j = j.next;
|
| 84 |
+
} else {
|
| 85 |
+
if (intersects(k._, c._)) {
|
| 86 |
+
a = k, a.next = b, b.previous = a, --i;
|
| 87 |
+
continue pack;
|
| 88 |
+
}
|
| 89 |
+
sk += k._.r, k = k.previous;
|
| 90 |
+
}
|
| 91 |
+
} while (j !== k.next);
|
| 92 |
+
|
| 93 |
+
// Success! Insert the new circle c between a and b.
|
| 94 |
+
c.previous = a, c.next = b, a.next = b.previous = b = c;
|
| 95 |
+
|
| 96 |
+
// Compute the new closest circle pair to the centroid.
|
| 97 |
+
aa = score(a);
|
| 98 |
+
while ((c = c.next) !== b) {
|
| 99 |
+
if ((ca = score(c)) < aa) {
|
| 100 |
+
a = c, aa = ca;
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
b = a.next;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
// Compute the enclosing circle of the front chain.
|
| 107 |
+
a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
|
| 108 |
+
|
| 109 |
+
// Translate the circles to put the enclosing circle around the origin.
|
| 110 |
+
for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
|
| 111 |
+
|
| 112 |
+
return c.r;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
export default function(circles) {
|
| 116 |
+
packEnclose(circles);
|
| 117 |
+
return circles;
|
| 118 |
+
}
|
node_modules/d3-hierarchy/src/partition.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import roundNode from "./treemap/round.js";
|
| 2 |
+
import treemapDice from "./treemap/dice.js";
|
| 3 |
+
|
| 4 |
+
export default function() {
|
| 5 |
+
var dx = 1,
|
| 6 |
+
dy = 1,
|
| 7 |
+
padding = 0,
|
| 8 |
+
round = false;
|
| 9 |
+
|
| 10 |
+
function partition(root) {
|
| 11 |
+
var n = root.height + 1;
|
| 12 |
+
root.x0 =
|
| 13 |
+
root.y0 = padding;
|
| 14 |
+
root.x1 = dx;
|
| 15 |
+
root.y1 = dy / n;
|
| 16 |
+
root.eachBefore(positionNode(dy, n));
|
| 17 |
+
if (round) root.eachBefore(roundNode);
|
| 18 |
+
return root;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
function positionNode(dy, n) {
|
| 22 |
+
return function(node) {
|
| 23 |
+
if (node.children) {
|
| 24 |
+
treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
|
| 25 |
+
}
|
| 26 |
+
var x0 = node.x0,
|
| 27 |
+
y0 = node.y0,
|
| 28 |
+
x1 = node.x1 - padding,
|
| 29 |
+
y1 = node.y1 - padding;
|
| 30 |
+
if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
| 31 |
+
if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
| 32 |
+
node.x0 = x0;
|
| 33 |
+
node.y0 = y0;
|
| 34 |
+
node.x1 = x1;
|
| 35 |
+
node.y1 = y1;
|
| 36 |
+
};
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
partition.round = function(x) {
|
| 40 |
+
return arguments.length ? (round = !!x, partition) : round;
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
partition.size = function(x) {
|
| 44 |
+
return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
partition.padding = function(x) {
|
| 48 |
+
return arguments.length ? (padding = +x, partition) : padding;
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
return partition;
|
| 52 |
+
}
|
node_modules/d3-hierarchy/src/stratify.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {required} from "./accessors.js";
|
| 2 |
+
import {Node, computeHeight} from "./hierarchy/index.js";
|
| 3 |
+
|
| 4 |
+
var keyPrefix = "$", // Protect against keys like “__proto__”.
|
| 5 |
+
preroot = {depth: -1},
|
| 6 |
+
ambiguous = {};
|
| 7 |
+
|
| 8 |
+
function defaultId(d) {
|
| 9 |
+
return d.id;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
function defaultParentId(d) {
|
| 13 |
+
return d.parentId;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export default function() {
|
| 17 |
+
var id = defaultId,
|
| 18 |
+
parentId = defaultParentId;
|
| 19 |
+
|
| 20 |
+
function stratify(data) {
|
| 21 |
+
var d,
|
| 22 |
+
i,
|
| 23 |
+
n = data.length,
|
| 24 |
+
root,
|
| 25 |
+
parent,
|
| 26 |
+
node,
|
| 27 |
+
nodes = new Array(n),
|
| 28 |
+
nodeId,
|
| 29 |
+
nodeKey,
|
| 30 |
+
nodeByKey = {};
|
| 31 |
+
|
| 32 |
+
for (i = 0; i < n; ++i) {
|
| 33 |
+
d = data[i], node = nodes[i] = new Node(d);
|
| 34 |
+
if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
|
| 35 |
+
nodeKey = keyPrefix + (node.id = nodeId);
|
| 36 |
+
nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
for (i = 0; i < n; ++i) {
|
| 41 |
+
node = nodes[i], nodeId = parentId(data[i], i, data);
|
| 42 |
+
if (nodeId == null || !(nodeId += "")) {
|
| 43 |
+
if (root) throw new Error("multiple roots");
|
| 44 |
+
root = node;
|
| 45 |
+
} else {
|
| 46 |
+
parent = nodeByKey[keyPrefix + nodeId];
|
| 47 |
+
if (!parent) throw new Error("missing: " + nodeId);
|
| 48 |
+
if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
|
| 49 |
+
if (parent.children) parent.children.push(node);
|
| 50 |
+
else parent.children = [node];
|
| 51 |
+
node.parent = parent;
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
if (!root) throw new Error("no root");
|
| 56 |
+
root.parent = preroot;
|
| 57 |
+
root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
|
| 58 |
+
root.parent = null;
|
| 59 |
+
if (n > 0) throw new Error("cycle");
|
| 60 |
+
|
| 61 |
+
return root;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
stratify.id = function(x) {
|
| 65 |
+
return arguments.length ? (id = required(x), stratify) : id;
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
stratify.parentId = function(x) {
|
| 69 |
+
return arguments.length ? (parentId = required(x), stratify) : parentId;
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
return stratify;
|
| 73 |
+
}
|
node_modules/d3-hierarchy/src/tree.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {Node} from "./hierarchy/index.js";
|
| 2 |
+
|
| 3 |
+
function defaultSeparation(a, b) {
|
| 4 |
+
return a.parent === b.parent ? 1 : 2;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
// function radialSeparation(a, b) {
|
| 8 |
+
// return (a.parent === b.parent ? 1 : 2) / a.depth;
|
| 9 |
+
// }
|
| 10 |
+
|
| 11 |
+
// This function is used to traverse the left contour of a subtree (or
|
| 12 |
+
// subforest). It returns the successor of v on this contour. This successor is
|
| 13 |
+
// either given by the leftmost child of v or by the thread of v. The function
|
| 14 |
+
// returns null if and only if v is on the highest level of its subtree.
|
| 15 |
+
function nextLeft(v) {
|
| 16 |
+
var children = v.children;
|
| 17 |
+
return children ? children[0] : v.t;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
// This function works analogously to nextLeft.
|
| 21 |
+
function nextRight(v) {
|
| 22 |
+
var children = v.children;
|
| 23 |
+
return children ? children[children.length - 1] : v.t;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
// Shifts the current subtree rooted at w+. This is done by increasing
|
| 27 |
+
// prelim(w+) and mod(w+) by shift.
|
| 28 |
+
function moveSubtree(wm, wp, shift) {
|
| 29 |
+
var change = shift / (wp.i - wm.i);
|
| 30 |
+
wp.c -= change;
|
| 31 |
+
wp.s += shift;
|
| 32 |
+
wm.c += change;
|
| 33 |
+
wp.z += shift;
|
| 34 |
+
wp.m += shift;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
// All other shifts, applied to the smaller subtrees between w- and w+, are
|
| 38 |
+
// performed by this function. To prepare the shifts, we have to adjust
|
| 39 |
+
// change(w+), shift(w+), and change(w-).
|
| 40 |
+
function executeShifts(v) {
|
| 41 |
+
var shift = 0,
|
| 42 |
+
change = 0,
|
| 43 |
+
children = v.children,
|
| 44 |
+
i = children.length,
|
| 45 |
+
w;
|
| 46 |
+
while (--i >= 0) {
|
| 47 |
+
w = children[i];
|
| 48 |
+
w.z += shift;
|
| 49 |
+
w.m += shift;
|
| 50 |
+
shift += w.s + (change += w.c);
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
|
| 55 |
+
// returns the specified (default) ancestor.
|
| 56 |
+
function nextAncestor(vim, v, ancestor) {
|
| 57 |
+
return vim.a.parent === v.parent ? vim.a : ancestor;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
function TreeNode(node, i) {
|
| 61 |
+
this._ = node;
|
| 62 |
+
this.parent = null;
|
| 63 |
+
this.children = null;
|
| 64 |
+
this.A = null; // default ancestor
|
| 65 |
+
this.a = this; // ancestor
|
| 66 |
+
this.z = 0; // prelim
|
| 67 |
+
this.m = 0; // mod
|
| 68 |
+
this.c = 0; // change
|
| 69 |
+
this.s = 0; // shift
|
| 70 |
+
this.t = null; // thread
|
| 71 |
+
this.i = i; // number
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
TreeNode.prototype = Object.create(Node.prototype);
|
| 75 |
+
|
| 76 |
+
function treeRoot(root) {
|
| 77 |
+
var tree = new TreeNode(root, 0),
|
| 78 |
+
node,
|
| 79 |
+
nodes = [tree],
|
| 80 |
+
child,
|
| 81 |
+
children,
|
| 82 |
+
i,
|
| 83 |
+
n;
|
| 84 |
+
|
| 85 |
+
while (node = nodes.pop()) {
|
| 86 |
+
if (children = node._.children) {
|
| 87 |
+
node.children = new Array(n = children.length);
|
| 88 |
+
for (i = n - 1; i >= 0; --i) {
|
| 89 |
+
nodes.push(child = node.children[i] = new TreeNode(children[i], i));
|
| 90 |
+
child.parent = node;
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
(tree.parent = new TreeNode(null, 0)).children = [tree];
|
| 96 |
+
return tree;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
|
| 100 |
+
export default function() {
|
| 101 |
+
var separation = defaultSeparation,
|
| 102 |
+
dx = 1,
|
| 103 |
+
dy = 1,
|
| 104 |
+
nodeSize = null;
|
| 105 |
+
|
| 106 |
+
function tree(root) {
|
| 107 |
+
var t = treeRoot(root);
|
| 108 |
+
|
| 109 |
+
// Compute the layout using Buchheim et al.’s algorithm.
|
| 110 |
+
t.eachAfter(firstWalk), t.parent.m = -t.z;
|
| 111 |
+
t.eachBefore(secondWalk);
|
| 112 |
+
|
| 113 |
+
// If a fixed node size is specified, scale x and y.
|
| 114 |
+
if (nodeSize) root.eachBefore(sizeNode);
|
| 115 |
+
|
| 116 |
+
// If a fixed tree size is specified, scale x and y based on the extent.
|
| 117 |
+
// Compute the left-most, right-most, and depth-most nodes for extents.
|
| 118 |
+
else {
|
| 119 |
+
var left = root,
|
| 120 |
+
right = root,
|
| 121 |
+
bottom = root;
|
| 122 |
+
root.eachBefore(function(node) {
|
| 123 |
+
if (node.x < left.x) left = node;
|
| 124 |
+
if (node.x > right.x) right = node;
|
| 125 |
+
if (node.depth > bottom.depth) bottom = node;
|
| 126 |
+
});
|
| 127 |
+
var s = left === right ? 1 : separation(left, right) / 2,
|
| 128 |
+
tx = s - left.x,
|
| 129 |
+
kx = dx / (right.x + s + tx),
|
| 130 |
+
ky = dy / (bottom.depth || 1);
|
| 131 |
+
root.eachBefore(function(node) {
|
| 132 |
+
node.x = (node.x + tx) * kx;
|
| 133 |
+
node.y = node.depth * ky;
|
| 134 |
+
});
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
return root;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
// Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
|
| 141 |
+
// applied recursively to the children of v, as well as the function
|
| 142 |
+
// APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
|
| 143 |
+
// node v is placed to the midpoint of its outermost children.
|
| 144 |
+
function firstWalk(v) {
|
| 145 |
+
var children = v.children,
|
| 146 |
+
siblings = v.parent.children,
|
| 147 |
+
w = v.i ? siblings[v.i - 1] : null;
|
| 148 |
+
if (children) {
|
| 149 |
+
executeShifts(v);
|
| 150 |
+
var midpoint = (children[0].z + children[children.length - 1].z) / 2;
|
| 151 |
+
if (w) {
|
| 152 |
+
v.z = w.z + separation(v._, w._);
|
| 153 |
+
v.m = v.z - midpoint;
|
| 154 |
+
} else {
|
| 155 |
+
v.z = midpoint;
|
| 156 |
+
}
|
| 157 |
+
} else if (w) {
|
| 158 |
+
v.z = w.z + separation(v._, w._);
|
| 159 |
+
}
|
| 160 |
+
v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
// Computes all real x-coordinates by summing up the modifiers recursively.
|
| 164 |
+
function secondWalk(v) {
|
| 165 |
+
v._.x = v.z + v.parent.m;
|
| 166 |
+
v.m += v.parent.m;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
// The core of the algorithm. Here, a new subtree is combined with the
|
| 170 |
+
// previous subtrees. Threads are used to traverse the inside and outside
|
| 171 |
+
// contours of the left and right subtree up to the highest common level. The
|
| 172 |
+
// vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
|
| 173 |
+
// superscript o means outside and i means inside, the subscript - means left
|
| 174 |
+
// subtree and + means right subtree. For summing up the modifiers along the
|
| 175 |
+
// contour, we use respective variables si+, si-, so-, and so+. Whenever two
|
| 176 |
+
// nodes of the inside contours conflict, we compute the left one of the
|
| 177 |
+
// greatest uncommon ancestors using the function ANCESTOR and call MOVE
|
| 178 |
+
// SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
|
| 179 |
+
// Finally, we add a new thread (if necessary).
|
| 180 |
+
function apportion(v, w, ancestor) {
|
| 181 |
+
if (w) {
|
| 182 |
+
var vip = v,
|
| 183 |
+
vop = v,
|
| 184 |
+
vim = w,
|
| 185 |
+
vom = vip.parent.children[0],
|
| 186 |
+
sip = vip.m,
|
| 187 |
+
sop = vop.m,
|
| 188 |
+
sim = vim.m,
|
| 189 |
+
som = vom.m,
|
| 190 |
+
shift;
|
| 191 |
+
while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
|
| 192 |
+
vom = nextLeft(vom);
|
| 193 |
+
vop = nextRight(vop);
|
| 194 |
+
vop.a = v;
|
| 195 |
+
shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
|
| 196 |
+
if (shift > 0) {
|
| 197 |
+
moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
|
| 198 |
+
sip += shift;
|
| 199 |
+
sop += shift;
|
| 200 |
+
}
|
| 201 |
+
sim += vim.m;
|
| 202 |
+
sip += vip.m;
|
| 203 |
+
som += vom.m;
|
| 204 |
+
sop += vop.m;
|
| 205 |
+
}
|
| 206 |
+
if (vim && !nextRight(vop)) {
|
| 207 |
+
vop.t = vim;
|
| 208 |
+
vop.m += sim - sop;
|
| 209 |
+
}
|
| 210 |
+
if (vip && !nextLeft(vom)) {
|
| 211 |
+
vom.t = vip;
|
| 212 |
+
vom.m += sip - som;
|
| 213 |
+
ancestor = v;
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
return ancestor;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
function sizeNode(node) {
|
| 220 |
+
node.x *= dx;
|
| 221 |
+
node.y = node.depth * dy;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
tree.separation = function(x) {
|
| 225 |
+
return arguments.length ? (separation = x, tree) : separation;
|
| 226 |
+
};
|
| 227 |
+
|
| 228 |
+
tree.size = function(x) {
|
| 229 |
+
return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
|
| 230 |
+
};
|
| 231 |
+
|
| 232 |
+
tree.nodeSize = function(x) {
|
| 233 |
+
return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
|
| 234 |
+
};
|
| 235 |
+
|
| 236 |
+
return tree;
|
| 237 |
+
}
|
node_modules/d3-hierarchy/src/treemap/binary.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(parent, x0, y0, x1, y1) {
|
| 2 |
+
var nodes = parent.children,
|
| 3 |
+
i, n = nodes.length,
|
| 4 |
+
sum, sums = new Array(n + 1);
|
| 5 |
+
|
| 6 |
+
for (sums[0] = sum = i = 0; i < n; ++i) {
|
| 7 |
+
sums[i + 1] = sum += nodes[i].value;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
partition(0, n, parent.value, x0, y0, x1, y1);
|
| 11 |
+
|
| 12 |
+
function partition(i, j, value, x0, y0, x1, y1) {
|
| 13 |
+
if (i >= j - 1) {
|
| 14 |
+
var node = nodes[i];
|
| 15 |
+
node.x0 = x0, node.y0 = y0;
|
| 16 |
+
node.x1 = x1, node.y1 = y1;
|
| 17 |
+
return;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
var valueOffset = sums[i],
|
| 21 |
+
valueTarget = (value / 2) + valueOffset,
|
| 22 |
+
k = i + 1,
|
| 23 |
+
hi = j - 1;
|
| 24 |
+
|
| 25 |
+
while (k < hi) {
|
| 26 |
+
var mid = k + hi >>> 1;
|
| 27 |
+
if (sums[mid] < valueTarget) k = mid + 1;
|
| 28 |
+
else hi = mid;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
|
| 32 |
+
|
| 33 |
+
var valueLeft = sums[k] - valueOffset,
|
| 34 |
+
valueRight = value - valueLeft;
|
| 35 |
+
|
| 36 |
+
if ((x1 - x0) > (y1 - y0)) {
|
| 37 |
+
var xk = (x0 * valueRight + x1 * valueLeft) / value;
|
| 38 |
+
partition(i, k, valueLeft, x0, y0, xk, y1);
|
| 39 |
+
partition(k, j, valueRight, xk, y0, x1, y1);
|
| 40 |
+
} else {
|
| 41 |
+
var yk = (y0 * valueRight + y1 * valueLeft) / value;
|
| 42 |
+
partition(i, k, valueLeft, x0, y0, x1, yk);
|
| 43 |
+
partition(k, j, valueRight, x0, yk, x1, y1);
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
}
|
node_modules/d3-hierarchy/src/treemap/dice.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(parent, x0, y0, x1, y1) {
|
| 2 |
+
var nodes = parent.children,
|
| 3 |
+
node,
|
| 4 |
+
i = -1,
|
| 5 |
+
n = nodes.length,
|
| 6 |
+
k = parent.value && (x1 - x0) / parent.value;
|
| 7 |
+
|
| 8 |
+
while (++i < n) {
|
| 9 |
+
node = nodes[i], node.y0 = y0, node.y1 = y1;
|
| 10 |
+
node.x0 = x0, node.x1 = x0 += node.value * k;
|
| 11 |
+
}
|
| 12 |
+
}
|
node_modules/d3-hierarchy/src/treemap/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import roundNode from "./round.js";
|
| 2 |
+
import squarify from "./squarify.js";
|
| 3 |
+
import {required} from "../accessors.js";
|
| 4 |
+
import constant, {constantZero} from "../constant.js";
|
| 5 |
+
|
| 6 |
+
export default function() {
|
| 7 |
+
var tile = squarify,
|
| 8 |
+
round = false,
|
| 9 |
+
dx = 1,
|
| 10 |
+
dy = 1,
|
| 11 |
+
paddingStack = [0],
|
| 12 |
+
paddingInner = constantZero,
|
| 13 |
+
paddingTop = constantZero,
|
| 14 |
+
paddingRight = constantZero,
|
| 15 |
+
paddingBottom = constantZero,
|
| 16 |
+
paddingLeft = constantZero;
|
| 17 |
+
|
| 18 |
+
function treemap(root) {
|
| 19 |
+
root.x0 =
|
| 20 |
+
root.y0 = 0;
|
| 21 |
+
root.x1 = dx;
|
| 22 |
+
root.y1 = dy;
|
| 23 |
+
root.eachBefore(positionNode);
|
| 24 |
+
paddingStack = [0];
|
| 25 |
+
if (round) root.eachBefore(roundNode);
|
| 26 |
+
return root;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
function positionNode(node) {
|
| 30 |
+
var p = paddingStack[node.depth],
|
| 31 |
+
x0 = node.x0 + p,
|
| 32 |
+
y0 = node.y0 + p,
|
| 33 |
+
x1 = node.x1 - p,
|
| 34 |
+
y1 = node.y1 - p;
|
| 35 |
+
if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
| 36 |
+
if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
| 37 |
+
node.x0 = x0;
|
| 38 |
+
node.y0 = y0;
|
| 39 |
+
node.x1 = x1;
|
| 40 |
+
node.y1 = y1;
|
| 41 |
+
if (node.children) {
|
| 42 |
+
p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
|
| 43 |
+
x0 += paddingLeft(node) - p;
|
| 44 |
+
y0 += paddingTop(node) - p;
|
| 45 |
+
x1 -= paddingRight(node) - p;
|
| 46 |
+
y1 -= paddingBottom(node) - p;
|
| 47 |
+
if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
| 48 |
+
if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
| 49 |
+
tile(node, x0, y0, x1, y1);
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
treemap.round = function(x) {
|
| 54 |
+
return arguments.length ? (round = !!x, treemap) : round;
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
treemap.size = function(x) {
|
| 58 |
+
return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
treemap.tile = function(x) {
|
| 62 |
+
return arguments.length ? (tile = required(x), treemap) : tile;
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
treemap.padding = function(x) {
|
| 66 |
+
return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
treemap.paddingInner = function(x) {
|
| 70 |
+
return arguments.length ? (paddingInner = typeof x === "function" ? x : constant(+x), treemap) : paddingInner;
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
treemap.paddingOuter = function(x) {
|
| 74 |
+
return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
treemap.paddingTop = function(x) {
|
| 78 |
+
return arguments.length ? (paddingTop = typeof x === "function" ? x : constant(+x), treemap) : paddingTop;
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
treemap.paddingRight = function(x) {
|
| 82 |
+
return arguments.length ? (paddingRight = typeof x === "function" ? x : constant(+x), treemap) : paddingRight;
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
treemap.paddingBottom = function(x) {
|
| 86 |
+
return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant(+x), treemap) : paddingBottom;
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
treemap.paddingLeft = function(x) {
|
| 90 |
+
return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant(+x), treemap) : paddingLeft;
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
return treemap;
|
| 94 |
+
}
|
node_modules/d3-hierarchy/src/treemap/resquarify.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import treemapDice from "./dice.js";
|
| 2 |
+
import treemapSlice from "./slice.js";
|
| 3 |
+
import {phi, squarifyRatio} from "./squarify.js";
|
| 4 |
+
|
| 5 |
+
export default (function custom(ratio) {
|
| 6 |
+
|
| 7 |
+
function resquarify(parent, x0, y0, x1, y1) {
|
| 8 |
+
if ((rows = parent._squarify) && (rows.ratio === ratio)) {
|
| 9 |
+
var rows,
|
| 10 |
+
row,
|
| 11 |
+
nodes,
|
| 12 |
+
i,
|
| 13 |
+
j = -1,
|
| 14 |
+
n,
|
| 15 |
+
m = rows.length,
|
| 16 |
+
value = parent.value;
|
| 17 |
+
|
| 18 |
+
while (++j < m) {
|
| 19 |
+
row = rows[j], nodes = row.children;
|
| 20 |
+
for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
|
| 21 |
+
if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
|
| 22 |
+
else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
|
| 23 |
+
value -= row.value;
|
| 24 |
+
}
|
| 25 |
+
} else {
|
| 26 |
+
parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
| 27 |
+
rows.ratio = ratio;
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
resquarify.ratio = function(x) {
|
| 32 |
+
return custom((x = +x) > 1 ? x : 1);
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
return resquarify;
|
| 36 |
+
})(phi);
|
node_modules/d3-hierarchy/src/treemap/round.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(node) {
|
| 2 |
+
node.x0 = Math.round(node.x0);
|
| 3 |
+
node.y0 = Math.round(node.y0);
|
| 4 |
+
node.x1 = Math.round(node.x1);
|
| 5 |
+
node.y1 = Math.round(node.y1);
|
| 6 |
+
}
|
node_modules/d3-hierarchy/src/treemap/slice.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function(parent, x0, y0, x1, y1) {
|
| 2 |
+
var nodes = parent.children,
|
| 3 |
+
node,
|
| 4 |
+
i = -1,
|
| 5 |
+
n = nodes.length,
|
| 6 |
+
k = parent.value && (y1 - y0) / parent.value;
|
| 7 |
+
|
| 8 |
+
while (++i < n) {
|
| 9 |
+
node = nodes[i], node.x0 = x0, node.x1 = x1;
|
| 10 |
+
node.y0 = y0, node.y1 = y0 += node.value * k;
|
| 11 |
+
}
|
| 12 |
+
}
|
node_modules/d3-hierarchy/src/treemap/sliceDice.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import dice from "./dice.js";
|
| 2 |
+
import slice from "./slice.js";
|
| 3 |
+
|
| 4 |
+
export default function(parent, x0, y0, x1, y1) {
|
| 5 |
+
(parent.depth & 1 ? slice : dice)(parent, x0, y0, x1, y1);
|
| 6 |
+
}
|
node_modules/d3-hierarchy/src/treemap/squarify.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import treemapDice from "./dice.js";
|
| 2 |
+
import treemapSlice from "./slice.js";
|
| 3 |
+
|
| 4 |
+
export var phi = (1 + Math.sqrt(5)) / 2;
|
| 5 |
+
|
| 6 |
+
export function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
|
| 7 |
+
var rows = [],
|
| 8 |
+
nodes = parent.children,
|
| 9 |
+
row,
|
| 10 |
+
nodeValue,
|
| 11 |
+
i0 = 0,
|
| 12 |
+
i1 = 0,
|
| 13 |
+
n = nodes.length,
|
| 14 |
+
dx, dy,
|
| 15 |
+
value = parent.value,
|
| 16 |
+
sumValue,
|
| 17 |
+
minValue,
|
| 18 |
+
maxValue,
|
| 19 |
+
newRatio,
|
| 20 |
+
minRatio,
|
| 21 |
+
alpha,
|
| 22 |
+
beta;
|
| 23 |
+
|
| 24 |
+
while (i0 < n) {
|
| 25 |
+
dx = x1 - x0, dy = y1 - y0;
|
| 26 |
+
|
| 27 |
+
// Find the next non-empty node.
|
| 28 |
+
do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
|
| 29 |
+
minValue = maxValue = sumValue;
|
| 30 |
+
alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
|
| 31 |
+
beta = sumValue * sumValue * alpha;
|
| 32 |
+
minRatio = Math.max(maxValue / beta, beta / minValue);
|
| 33 |
+
|
| 34 |
+
// Keep adding nodes while the aspect ratio maintains or improves.
|
| 35 |
+
for (; i1 < n; ++i1) {
|
| 36 |
+
sumValue += nodeValue = nodes[i1].value;
|
| 37 |
+
if (nodeValue < minValue) minValue = nodeValue;
|
| 38 |
+
if (nodeValue > maxValue) maxValue = nodeValue;
|
| 39 |
+
beta = sumValue * sumValue * alpha;
|
| 40 |
+
newRatio = Math.max(maxValue / beta, beta / minValue);
|
| 41 |
+
if (newRatio > minRatio) { sumValue -= nodeValue; break; }
|
| 42 |
+
minRatio = newRatio;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
// Position and record the row orientation.
|
| 46 |
+
rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
|
| 47 |
+
if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
|
| 48 |
+
else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
|
| 49 |
+
value -= sumValue, i0 = i1;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
return rows;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
export default (function custom(ratio) {
|
| 56 |
+
|
| 57 |
+
function squarify(parent, x0, y0, x1, y1) {
|
| 58 |
+
squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
squarify.ratio = function(x) {
|
| 62 |
+
return custom((x = +x) > 1 ? x : 1);
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
return squarify;
|
| 66 |
+
})(phi);
|
node_modules/d3-interpolate/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2010-2021 Mike Bostock
|
| 2 |
+
|
| 3 |
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
| 4 |
+
with or without fee is hereby granted, provided that the above copyright notice
|
| 5 |
+
and this permission notice appear in all copies.
|
| 6 |
+
|
| 7 |
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
| 8 |
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
| 9 |
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
| 10 |
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
| 11 |
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
| 12 |
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
| 13 |
+
THIS SOFTWARE.
|
node_modules/d3-interpolate/README.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# d3-interpolate
|
| 2 |
+
|
| 3 |
+
This module provides a variety of interpolation methods for blending between two values. Values may be numbers, colors, strings, arrays, or even deeply-nested objects. For example:
|
| 4 |
+
|
| 5 |
+
```js
|
| 6 |
+
const i = d3.interpolateNumber(10, 20);
|
| 7 |
+
i(0.0); // 10
|
| 8 |
+
i(0.2); // 12
|
| 9 |
+
i(0.5); // 15
|
| 10 |
+
i(1.0); // 20
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
The returned function `i` is called an *interpolator*. Given a starting value *a* and an ending value *b*, it takes a parameter *t* in the domain [0, 1] and returns the corresponding interpolated value between *a* and *b*. An interpolator typically returns a value equivalent to *a* at *t* = 0 and a value equivalent to *b* at *t* = 1.
|
| 14 |
+
|
| 15 |
+
You can interpolate more than just numbers. To find the perceptual midpoint between steelblue and brown:
|
| 16 |
+
|
| 17 |
+
```js
|
| 18 |
+
d3.interpolateLab("steelblue", "brown")(0.5); // "rgb(142, 92, 109)"
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
Here’s a more elaborate example demonstrating type inference used by [interpolate](#interpolate):
|
| 22 |
+
|
| 23 |
+
```js
|
| 24 |
+
const i = d3.interpolate({colors: ["red", "blue"]}, {colors: ["white", "black"]});
|
| 25 |
+
i(0.0); // {colors: ["rgb(255, 0, 0)", "rgb(0, 0, 255)"]}
|
| 26 |
+
i(0.5); // {colors: ["rgb(255, 128, 128)", "rgb(0, 0, 128)"]}
|
| 27 |
+
i(1.0); // {colors: ["rgb(255, 255, 255)", "rgb(0, 0, 0)"]}
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
Note that the generic value interpolator detects not only nested objects and arrays, but also color strings and numbers embedded in strings!
|
| 31 |
+
|
| 32 |
+
## Installing
|
| 33 |
+
|
| 34 |
+
If you use npm, `npm install d3-interpolate`. You can also download the [latest release on GitHub](https://github.com/d3/d3-interpolate/releases/latest). For vanilla HTML in modern browsers, import d3-interpolate from Skypack:
|
| 35 |
+
|
| 36 |
+
```html
|
| 37 |
+
<script type="module">
|
| 38 |
+
|
| 39 |
+
import {interpolateRgb} from "https://cdn.skypack.dev/d3-interpolate@3";
|
| 40 |
+
|
| 41 |
+
const interpolate = interpolateRgb("steelblue", "brown");
|
| 42 |
+
|
| 43 |
+
</script>
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
For legacy environments, you can load d3-interpolate’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported. (If using [color interpolation](#color-spaces), also load [d3-color](https://github.com/d3/d3-color).)
|
| 47 |
+
|
| 48 |
+
```html
|
| 49 |
+
<script src="https://cdn.jsdelivr.net/npm/d3-color@3"></script>
|
| 50 |
+
<script src="https://cdn.jsdelivr.net/npm/d3-interpolate@3"></script>
|
| 51 |
+
<script>
|
| 52 |
+
|
| 53 |
+
const interpolate = d3.interpolateRgb("steelblue", "brown");
|
| 54 |
+
|
| 55 |
+
</script>
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
## API Reference
|
| 59 |
+
|
| 60 |
+
<a name="interpolate" href="#interpolate">#</a> d3.<b>interpolate</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/value.js), [Examples](https://observablehq.com/@d3/d3-interpolate)
|
| 61 |
+
|
| 62 |
+
Returns an interpolator between the two arbitrary values *a* and *b*. The interpolator implementation is based on the type of the end value *b*, using the following algorithm:
|
| 63 |
+
|
| 64 |
+
1. If *b* is null, undefined or a boolean, use the constant *b*.
|
| 65 |
+
2. If *b* is a number, use [interpolateNumber](#interpolateNumber).
|
| 66 |
+
3. If *b* is a [color](https://github.com/d3/d3-color/blob/master/README.md#color) or a string coercible to a color, use [interpolateRgb](#interpolateRgb).
|
| 67 |
+
4. If *b* is a [date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date), use [interpolateDate](#interpolateDate).
|
| 68 |
+
5. If *b* is a string, use [interpolateString](#interpolateString).
|
| 69 |
+
6. If *b* is a [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) of numbers, use [interpolateNumberArray](#interpolateNumberArray).
|
| 70 |
+
7. If *b* is a generic [array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray), use [interpolateArray](#interpolateArray).
|
| 71 |
+
8. If *b* is coercible to a number, use [interpolateNumber](#interpolateNumber).
|
| 72 |
+
9. Use [interpolateObject](#interpolateObject).
|
| 73 |
+
|
| 74 |
+
Based on the chosen interpolator, *a* is coerced to the suitable corresponding type.
|
| 75 |
+
|
| 76 |
+
<a name="interpolateNumber" href="#interpolateNumber">#</a> d3.<b>interpolateNumber</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/number.js), [Examples](https://observablehq.com/@d3/d3-interpolatenumber)
|
| 77 |
+
|
| 78 |
+
Returns an interpolator between the two numbers *a* and *b*. The returned interpolator is equivalent to:
|
| 79 |
+
|
| 80 |
+
```js
|
| 81 |
+
function interpolator(t) {
|
| 82 |
+
return a * (1 - t) + b * t;
|
| 83 |
+
}
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
Caution: avoid interpolating to or from the number zero when the interpolator is used to generate a string. When very small values are stringified, they may be converted to scientific notation, which is an invalid attribute or style property value in older browsers. For example, the number `0.0000001` is converted to the string `"1e-7"`. This is particularly noticeable with interpolating opacity. To avoid scientific notation, start or end the transition at 1e-6: the smallest value that is not stringified in scientific notation.
|
| 87 |
+
|
| 88 |
+
<a name="interpolateRound" href="#interpolateRound">#</a> d3.<b>interpolateRound</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/round.js), [Examples](https://observablehq.com/@d3/d3-interpolatenumber)
|
| 89 |
+
|
| 90 |
+
Returns an interpolator between the two numbers *a* and *b*; the interpolator is similar to [interpolateNumber](#interpolateNumber), except it will round the resulting value to the nearest integer.
|
| 91 |
+
|
| 92 |
+
<a name="interpolateString" href="#interpolateString">#</a> d3.<b>interpolateString</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/string.js), [Examples](https://observablehq.com/@d3/d3-interpolatestring)
|
| 93 |
+
|
| 94 |
+
Returns an interpolator between the two strings *a* and *b*. The string interpolator finds numbers embedded in *a* and *b*, where each number is of the form understood by JavaScript. A few examples of numbers that will be detected within a string: `-1`, `42`, `3.14159`, and `6.0221413e+23`.
|
| 95 |
+
|
| 96 |
+
For each number embedded in *b*, the interpolator will attempt to find a corresponding number in *a*. If a corresponding number is found, a numeric interpolator is created using [interpolateNumber](#interpolateNumber). The remaining parts of the string *b* are used as a template: the static parts of the string *b* remain constant for the interpolation, with the interpolated numeric values embedded in the template.
|
| 97 |
+
|
| 98 |
+
For example, if *a* is `"300 12px sans-serif"`, and *b* is `"500 36px Comic-Sans"`, two embedded numbers are found. The remaining static parts (of string *b*) are a space between the two numbers (`" "`), and the suffix (`"px Comic-Sans"`). The result of the interpolator at *t* = 0.5 is `"400 24px Comic-Sans"`.
|
| 99 |
+
|
| 100 |
+
<a name="interpolateDate" href="#interpolateDate">#</a> d3.<b>interpolateDate</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/date.js), [Examples](https://observablehq.com/@d3/d3-interpolatedate)
|
| 101 |
+
|
| 102 |
+
Returns an interpolator between the two [dates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) *a* and *b*.
|
| 103 |
+
|
| 104 |
+
Note: **no defensive copy** of the returned date is created; the same Date instance is returned for every evaluation of the interpolator. No copy is made for performance reasons; interpolators are often part of the inner loop of [animated transitions](https://github.com/d3/d3-transition).
|
| 105 |
+
|
| 106 |
+
<a name="interpolateArray" href="#interpolateArray">#</a> d3.<b>interpolateArray</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/array.js), [Examples](https://observablehq.com/@d3/d3-interpolateobject)
|
| 107 |
+
|
| 108 |
+
Returns an interpolator between the two arrays *a* and *b*. If *b* is a typed array (e.g., Float64Array), [interpolateNumberArray](#interpolateNumberArray) is called instead.
|
| 109 |
+
|
| 110 |
+
Internally, an array template is created that is the same length as *b*. For each element in *b*, if there exists a corresponding element in *a*, a generic interpolator is created for the two elements using [interpolate](#interpolate). If there is no such element, the static value from *b* is used in the template. Then, for the given parameter *t*, the template’s embedded interpolators are evaluated. The updated array template is then returned.
|
| 111 |
+
|
| 112 |
+
For example, if *a* is the array `[0, 1]` and *b* is the array `[1, 10, 100]`, then the result of the interpolator for *t* = 0.5 is the array `[0.5, 5.5, 100]`.
|
| 113 |
+
|
| 114 |
+
Note: **no defensive copy** of the template array is created; modifications of the returned array may adversely affect subsequent evaluation of the interpolator. No copy is made for performance reasons; interpolators are often part of the inner loop of [animated transitions](https://github.com/d3/d3-transition).
|
| 115 |
+
|
| 116 |
+
<a name="interpolateNumberArray" href="#interpolateNumberArray">#</a> d3.<b>interpolateNumberArray</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/numberArray.js), [Examples](https://observablehq.com/@d3/d3-interpolatenumberarray)
|
| 117 |
+
|
| 118 |
+
Returns an interpolator between the two arrays of numbers *a* and *b*. Internally, an array template is created that is the same type and length as *b*. For each element in *b*, if there exists a corresponding element in *a*, the values are directly interpolated in the array template. If there is no such element, the static value from *b* is copied. The updated array template is then returned.
|
| 119 |
+
|
| 120 |
+
Note: For performance reasons, **no defensive copy** is made of the template array and the arguments *a* and *b*; modifications of these arrays may affect subsequent evaluation of the interpolator.
|
| 121 |
+
|
| 122 |
+
<a name="interpolateObject" href="#interpolateObject">#</a> d3.<b>interpolateObject</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/object.js), [Examples](https://observablehq.com/@d3/d3-interpolateobject)
|
| 123 |
+
|
| 124 |
+
Returns an interpolator between the two objects *a* and *b*. Internally, an object template is created that has the same properties as *b*. For each property in *b*, if there exists a corresponding property in *a*, a generic interpolator is created for the two elements using [interpolate](#interpolate). If there is no such property, the static value from *b* is used in the template. Then, for the given parameter *t*, the template's embedded interpolators are evaluated and the updated object template is then returned.
|
| 125 |
+
|
| 126 |
+
For example, if *a* is the object `{x: 0, y: 1}` and *b* is the object `{x: 1, y: 10, z: 100}`, the result of the interpolator for *t* = 0.5 is the object `{x: 0.5, y: 5.5, z: 100}`.
|
| 127 |
+
|
| 128 |
+
Object interpolation is particularly useful for *dataspace interpolation*, where data is interpolated rather than attribute values. For example, you can interpolate an object which describes an arc in a pie chart, and then use [d3.arc](https://github.com/d3/d3-shape/blob/master/README.md#arc) to compute the new SVG path data.
|
| 129 |
+
|
| 130 |
+
Note: **no defensive copy** of the template object is created; modifications of the returned object may adversely affect subsequent evaluation of the interpolator. No copy is made for performance reasons; interpolators are often part of the inner loop of [animated transitions](https://github.com/d3/d3-transition).
|
| 131 |
+
|
| 132 |
+
<a name="interpolateTransformCss" href="#interpolateTransformCss">#</a> d3.<b>interpolateTransformCss</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/transform/index.js#L62), [Examples](https://observablehq.com/@d3/d3-interpolatetransformcss)
|
| 133 |
+
|
| 134 |
+
Returns an interpolator between the two 2D CSS transforms represented by *a* and *b*. Each transform is decomposed to a standard representation of translate, rotate, *x*-skew and scale; these component transformations are then interpolated. This behavior is standardized by CSS: see [matrix decomposition for animation](http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition).
|
| 135 |
+
|
| 136 |
+
<a name="interpolateTransformSvg" href="#interpolateTransformSvg">#</a> d3.<b>interpolateTransformSvg</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/transform/index.js#L63), [Examples](https://observablehq.com/@d3/d3-interpolatetransformcss)
|
| 137 |
+
|
| 138 |
+
Returns an interpolator between the two 2D SVG transforms represented by *a* and *b*. Each transform is decomposed to a standard representation of translate, rotate, *x*-skew and scale; these component transformations are then interpolated. This behavior is standardized by CSS: see [matrix decomposition for animation](http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition).
|
| 139 |
+
|
| 140 |
+
<a name="interpolateZoom" href="#interpolateZoom">#</a> d3.<b>interpolateZoom</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/zoom.js), [Examples](https://observablehq.com/@d3/d3-interpolatezoom)
|
| 141 |
+
|
| 142 |
+
Returns an interpolator between the two views *a* and *b* of a two-dimensional plane, based on [“Smooth and efficient zooming and panning”](http://www.win.tue.nl/~vanwijk/zoompan.pdf) by Jarke J. van Wijk and Wim A.A. Nuij. Each view is defined as an array of three numbers: *cx*, *cy* and *width*. The first two coordinates *cx*, *cy* represent the center of the viewport; the last coordinate *width* represents the size of the viewport.
|
| 143 |
+
|
| 144 |
+
The returned interpolator exposes a *duration* property which encodes the recommended transition duration in milliseconds. This duration is based on the path length of the curved trajectory through *x,y* space. If you want a slower or faster transition, multiply this by an arbitrary scale factor (<i>V</i> as described in the original paper).
|
| 145 |
+
|
| 146 |
+
<a name="interpolateZoom_rho" href="#interpolateZoom_rho">#</a> *interpolateZoom*.<b>rho</b>(<i>rho</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/zoom.js)<!-- , [Examples](https://observablehq.com/@d3/interpolatezoom-rho) -->
|
| 147 |
+
|
| 148 |
+
Given a [zoom interpolator](#interpolateZoom), returns a new zoom interpolator using the specified curvature *rho*. When *rho* is close to 0, the interpolator is almost linear. The default curvature is sqrt(2).
|
| 149 |
+
|
| 150 |
+
<a name="interpolateDiscrete" href="#interpolateDiscrete">#</a> d3.<b>interpolateDiscrete</b>(<i>values</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/discrete.js), [Examples](https://observablehq.com/@d3/d3-interpolatediscrete)
|
| 151 |
+
|
| 152 |
+
Returns a discrete interpolator for the given array of *values*. The returned interpolator maps *t* in [0, 1 / *n*) to *values*[0], *t* in [1 / *n*, 2 / *n*) to *values*[1], and so on, where *n* = *values*.length. In effect, this is a lightweight [quantize scale](https://github.com/d3/d3-scale/blob/master/README.md#quantize-scales) with a fixed domain of [0, 1].
|
| 153 |
+
|
| 154 |
+
### Sampling
|
| 155 |
+
|
| 156 |
+
<a name="quantize" href="#quantize">#</a> d3.<b>quantize</b>(<i>interpolator</i>, <i>n</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/quantize.js), [Examples](https://observablehq.com/@d3/d3-quantize)
|
| 157 |
+
|
| 158 |
+
Returns *n* uniformly-spaced samples from the specified *interpolator*, where *n* is an integer greater than one. The first sample is always at *t* = 0, and the last sample is always at *t* = 1. This can be useful in generating a fixed number of samples from a given interpolator, such as to derive the range of a [quantize scale](https://github.com/d3/d3-scale/blob/master/README.md#quantize-scales) from a [continuous interpolator](https://github.com/d3/d3-scale-chromatic/blob/master/README.md#interpolateWarm).
|
| 159 |
+
|
| 160 |
+
Caution: this method will not work with interpolators that do not return defensive copies of their output, such as [d3.interpolateArray](#interpolateArray), [d3.interpolateDate](#interpolateDate) and [d3.interpolateObject](#interpolateObject). For those interpolators, you must wrap the interpolator and create a copy for each returned value.
|
| 161 |
+
|
| 162 |
+
### Color Spaces
|
| 163 |
+
|
| 164 |
+
<a name="interpolateRgb" href="#interpolateRgb">#</a> d3.<b>interpolateRgb</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/rgb.js), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 165 |
+
|
| 166 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/rgb.png" width="100%" height="40" alt="rgb">
|
| 167 |
+
|
| 168 |
+
Or, with a corrected [gamma](#interpolate_gamma) of 2.2:
|
| 169 |
+
|
| 170 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/rgbGamma.png" width="100%" height="40" alt="rgbGamma">
|
| 171 |
+
|
| 172 |
+
Returns an RGB color space interpolator between the two colors *a* and *b* with a configurable [gamma](#interpolate_gamma). If the gamma is not specified, it defaults to 1.0. The colors *a* and *b* need not be in RGB; they will be converted to RGB using [d3.rgb](https://github.com/d3/d3-color/blob/master/README.md#rgb). The return value of the interpolator is an RGB string.
|
| 173 |
+
|
| 174 |
+
<a href="#interpolateRgbBasis" name="interpolateRgbBasis">#</a> d3.<b>interpolateRgbBasis</b>(<i>colors</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/rgb.js#L54), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 175 |
+
|
| 176 |
+
Returns a uniform nonrational B-spline interpolator through the specified array of *colors*, which are converted to [RGB color space](https://github.com/d3/d3-color/blob/master/README.md#rgb). Implicit control points are generated such that the interpolator returns *colors*[0] at *t* = 0 and *colors*[*colors*.length - 1] at *t* = 1. Opacity interpolation is not currently supported. See also [d3.interpolateBasis](#interpolateBasis), and see [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) for examples.
|
| 177 |
+
|
| 178 |
+
<a href="#interpolateRgbBasisClosed" name="interpolateRgbBasisClosed">#</a> d3.<b>interpolateRgbBasisClosed</b>(<i>colors</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/rgb.js#L55), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 179 |
+
|
| 180 |
+
Returns a uniform nonrational B-spline interpolator through the specified array of *colors*, which are converted to [RGB color space](https://github.com/d3/d3-color/blob/master/README.md#rgb). The control points are implicitly repeated such that the resulting spline has cyclical C² continuity when repeated around *t* in [0,1]; this is useful, for example, to create cyclical color scales. Opacity interpolation is not currently supported. See also [d3.interpolateBasisClosed](#interpolateBasisClosed), and see [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) for examples.
|
| 181 |
+
|
| 182 |
+
<a name="interpolateHsl" href="#interpolateHsl">#</a> d3.<b>interpolateHsl</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/hsl.js), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 183 |
+
|
| 184 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/hsl.png" width="100%" height="40" alt="hsl">
|
| 185 |
+
|
| 186 |
+
Returns an HSL color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in HSL; they will be converted to HSL using [d3.hsl](https://github.com/d3/d3-color/blob/master/README.md#hsl). If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is an RGB string.
|
| 187 |
+
|
| 188 |
+
<a name="interpolateHslLong" href="#interpolateHslLong">#</a> d3.<b>interpolateHslLong</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/hsl.js#L21), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 189 |
+
|
| 190 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/hslLong.png" width="100%" height="40" alt="hslLong">
|
| 191 |
+
|
| 192 |
+
Like [interpolateHsl](#interpolateHsl), but does not use the shortest path between hues.
|
| 193 |
+
|
| 194 |
+
<a name="interpolateLab" href="#interpolateLab">#</a> d3.<b>interpolateLab</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/lab.js), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 195 |
+
|
| 196 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/lab.png" width="100%" height="40" alt="lab">
|
| 197 |
+
|
| 198 |
+
Returns a [CIELAB color space](https://en.wikipedia.org/wiki/Lab_color_space#CIELAB) interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in CIELAB; they will be converted to CIELAB using [d3.lab](https://github.com/d3/d3-color/blob/master/README.md#lab). The return value of the interpolator is an RGB string.
|
| 199 |
+
|
| 200 |
+
<a name="interpolateHcl" href="#interpolateHcl">#</a> d3.<b>interpolateHcl</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/hcl.js), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 201 |
+
|
| 202 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/hcl.png" width="100%" height="40" alt="hcl">
|
| 203 |
+
|
| 204 |
+
Returns a [CIELCh<sub>ab</sub> color space](https://en.wikipedia.org/wiki/CIELAB_color_space#Cylindrical_representation:_CIELCh_or_CIEHLC) interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in CIELCh<sub>ab</sub>; they will be converted to CIELCh<sub>ab</sub> using [d3.hcl](https://github.com/d3/d3-color/blob/master/README.md#hcl). If either color’s hue or chroma is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is an RGB string.
|
| 205 |
+
|
| 206 |
+
<a name="interpolateHclLong" href="#interpolateHclLong">#</a> d3.<b>interpolateHclLong</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/hcl.js#L21), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 207 |
+
|
| 208 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/hclLong.png" width="100%" height="40" alt="hclLong">
|
| 209 |
+
|
| 210 |
+
Like [interpolateHcl](#interpolateHcl), but does not use the shortest path between hues.
|
| 211 |
+
|
| 212 |
+
<a name="interpolateCubehelix" href="#interpolateCubehelix">#</a> d3.<b>interpolateCubehelix</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/cubehelix.js), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 213 |
+
|
| 214 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/cubehelix.png" width="100%" height="40" alt="cubehelix">
|
| 215 |
+
|
| 216 |
+
Or, with a [gamma](#interpolate_gamma) of 3.0 to emphasize high-intensity values:
|
| 217 |
+
|
| 218 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/cubehelixGamma.png" width="100%" height="40" alt="cubehelixGamma">
|
| 219 |
+
|
| 220 |
+
Returns a Cubehelix color space interpolator between the two colors *a* and *b* using a configurable [gamma](#interpolate_gamma). If the gamma is not specified, it defaults to 1.0. The colors *a* and *b* need not be in Cubehelix; they will be converted to Cubehelix using [d3.cubehelix](https://github.com/d3/d3-color/blob/master/README.md#cubehelix). If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is an RGB string.
|
| 221 |
+
|
| 222 |
+
<a name="interpolateCubehelixLong" href="#interpolateCubehelixLong">#</a> d3.<b>interpolateCubehelixLong</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/cubehelix.js#L29), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 223 |
+
|
| 224 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/cubehelixLong.png" width="100%" height="40" alt="cubehelixLong">
|
| 225 |
+
|
| 226 |
+
Or, with a [gamma](#interpolate_gamma) of 3.0 to emphasize high-intensity values:
|
| 227 |
+
|
| 228 |
+
<img src="https://raw.githubusercontent.com/d3/d3-interpolate/master/img/cubehelixGammaLong.png" width="100%" height="40" alt="cubehelixGammaLong">
|
| 229 |
+
|
| 230 |
+
Like [interpolateCubehelix](#interpolateCubehelix), but does not use the shortest path between hues.
|
| 231 |
+
|
| 232 |
+
<a name="interpolate_gamma" href="#interpolate_gamma">#</a> <i>interpolate</i>.<b>gamma</b>(<i>gamma</i>)
|
| 233 |
+
|
| 234 |
+
Given that *interpolate* is one of [interpolateRgb](#interpolateRgb), [interpolateCubehelix](#interpolateCubehelix) or [interpolateCubehelixLong](#interpolateCubehelixLong), returns a new interpolator factory of the same type using the specified *gamma*. For example, to interpolate from purple to orange with a gamma of 2.2 in RGB space:
|
| 235 |
+
|
| 236 |
+
```js
|
| 237 |
+
const interpolator = d3.interpolateRgb.gamma(2.2)("purple", "orange");
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
See Eric Brasseur’s article, [Gamma error in picture scaling](http://www.ericbrasseur.org/gamma.html), for more on gamma correction.
|
| 241 |
+
|
| 242 |
+
<a name="interpolateHue" href="#interpolateHue">#</a> d3.<b>interpolateHue</b>(<i>a</i>, <i>b</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/hue.js), [Examples](https://observablehq.com/@d3/working-with-color)
|
| 243 |
+
|
| 244 |
+
Returns an interpolator between the two hue angles *a* and *b*. If either hue is NaN, the opposing value is used. The shortest path between hues is used. The return value of the interpolator is a number in [0, 360).
|
| 245 |
+
|
| 246 |
+
### Splines
|
| 247 |
+
|
| 248 |
+
Whereas standard interpolators blend from a starting value *a* at *t* = 0 to an ending value *b* at *t* = 1, spline interpolators smoothly blend multiple input values for *t* in [0,1] using piecewise polynomial functions. Only cubic uniform nonrational [B-splines](https://en.wikipedia.org/wiki/B-spline) are currently supported, also known as basis splines.
|
| 249 |
+
|
| 250 |
+
<a href="#interpolateBasis" name="interpolateBasis">#</a> d3.<b>interpolateBasis</b>(<i>values</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/basis.js), [Examples](https://observablehq.com/@d3/d3-interpolatebasis)
|
| 251 |
+
|
| 252 |
+
Returns a uniform nonrational B-spline interpolator through the specified array of *values*, which must be numbers. Implicit control points are generated such that the interpolator returns *values*[0] at *t* = 0 and *values*[*values*.length - 1] at *t* = 1. See also [d3.curveBasis](https://github.com/d3/d3-shape/blob/master/README.md#curveBasis).
|
| 253 |
+
|
| 254 |
+
<a href="#interpolateBasisClosed" name="interpolateBasisClosed">#</a> d3.<b>interpolateBasisClosed</b>(<i>values</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/basisClosed.js), [Examples](https://observablehq.com/@d3/d3-interpolatebasis)
|
| 255 |
+
|
| 256 |
+
Returns a uniform nonrational B-spline interpolator through the specified array of *values*, which must be numbers. The control points are implicitly repeated such that the resulting one-dimensional spline has cyclical C² continuity when repeated around *t* in [0,1]. See also [d3.curveBasisClosed](https://github.com/d3/d3-shape/blob/master/README.md#curveBasisClosed).
|
| 257 |
+
|
| 258 |
+
### Piecewise
|
| 259 |
+
|
| 260 |
+
<a name="piecewise" href="#piecewise">#</a> d3.<b>piecewise</b>([<i>interpolate</i>, ]<i>values</i>) · [Source](https://github.com/d3/d3-interpolate/blob/master/src/piecewise.js), [Examples](https://observablehq.com/@d3/d3-piecewise)
|
| 261 |
+
|
| 262 |
+
Returns a piecewise interpolator, composing interpolators for each adjacent pair of *values*. The returned interpolator maps *t* in [0, 1 / (*n* - 1)] to *interpolate*(*values*[0], *values*[1]), *t* in [1 / (*n* - 1), 2 / (*n* - 1)] to *interpolate*(*values*[1], *values*[2]), and so on, where *n* = *values*.length. In effect, this is a lightweight [linear scale](https://github.com/d3/d3-scale/blob/master/README.md#linear-scales). For example, to blend through red, green and blue:
|
| 263 |
+
|
| 264 |
+
```js
|
| 265 |
+
const interpolate = d3.piecewise(d3.interpolateRgb.gamma(2.2), ["red", "green", "blue"]);
|
| 266 |
+
```
|
| 267 |
+
|
| 268 |
+
If *interpolate* is not specified, defaults to [d3.interpolate](#interpolate).
|
node_modules/d3-interpolate/dist/d3-interpolate.js
ADDED
|
@@ -0,0 +1,590 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// https://d3js.org/d3-interpolate/ v3.0.1 Copyright 2010-2021 Mike Bostock
|
| 2 |
+
(function (global, factory) {
|
| 3 |
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-color')) :
|
| 4 |
+
typeof define === 'function' && define.amd ? define(['exports', 'd3-color'], factory) :
|
| 5 |
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3));
|
| 6 |
+
}(this, (function (exports, d3Color) { 'use strict';
|
| 7 |
+
|
| 8 |
+
function basis(t1, v0, v1, v2, v3) {
|
| 9 |
+
var t2 = t1 * t1, t3 = t2 * t1;
|
| 10 |
+
return ((1 - 3 * t1 + 3 * t2 - t3) * v0
|
| 11 |
+
+ (4 - 6 * t2 + 3 * t3) * v1
|
| 12 |
+
+ (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
|
| 13 |
+
+ t3 * v3) / 6;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
function basis$1(values) {
|
| 17 |
+
var n = values.length - 1;
|
| 18 |
+
return function(t) {
|
| 19 |
+
var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
|
| 20 |
+
v1 = values[i],
|
| 21 |
+
v2 = values[i + 1],
|
| 22 |
+
v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
|
| 23 |
+
v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
|
| 24 |
+
return basis((t - i / n) * n, v0, v1, v2, v3);
|
| 25 |
+
};
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function basisClosed(values) {
|
| 29 |
+
var n = values.length;
|
| 30 |
+
return function(t) {
|
| 31 |
+
var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
|
| 32 |
+
v0 = values[(i + n - 1) % n],
|
| 33 |
+
v1 = values[i % n],
|
| 34 |
+
v2 = values[(i + 1) % n],
|
| 35 |
+
v3 = values[(i + 2) % n];
|
| 36 |
+
return basis((t - i / n) * n, v0, v1, v2, v3);
|
| 37 |
+
};
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
var constant = x => () => x;
|
| 41 |
+
|
| 42 |
+
function linear(a, d) {
|
| 43 |
+
return function(t) {
|
| 44 |
+
return a + t * d;
|
| 45 |
+
};
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function exponential(a, b, y) {
|
| 49 |
+
return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
|
| 50 |
+
return Math.pow(a + t * b, y);
|
| 51 |
+
};
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function hue$1(a, b) {
|
| 55 |
+
var d = b - a;
|
| 56 |
+
return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant(isNaN(a) ? b : a);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function gamma(y) {
|
| 60 |
+
return (y = +y) === 1 ? nogamma : function(a, b) {
|
| 61 |
+
return b - a ? exponential(a, b, y) : constant(isNaN(a) ? b : a);
|
| 62 |
+
};
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
function nogamma(a, b) {
|
| 66 |
+
var d = b - a;
|
| 67 |
+
return d ? linear(a, d) : constant(isNaN(a) ? b : a);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
var rgb = (function rgbGamma(y) {
|
| 71 |
+
var color = gamma(y);
|
| 72 |
+
|
| 73 |
+
function rgb(start, end) {
|
| 74 |
+
var r = color((start = d3Color.rgb(start)).r, (end = d3Color.rgb(end)).r),
|
| 75 |
+
g = color(start.g, end.g),
|
| 76 |
+
b = color(start.b, end.b),
|
| 77 |
+
opacity = nogamma(start.opacity, end.opacity);
|
| 78 |
+
return function(t) {
|
| 79 |
+
start.r = r(t);
|
| 80 |
+
start.g = g(t);
|
| 81 |
+
start.b = b(t);
|
| 82 |
+
start.opacity = opacity(t);
|
| 83 |
+
return start + "";
|
| 84 |
+
};
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
rgb.gamma = rgbGamma;
|
| 88 |
+
|
| 89 |
+
return rgb;
|
| 90 |
+
})(1);
|
| 91 |
+
|
| 92 |
+
function rgbSpline(spline) {
|
| 93 |
+
return function(colors) {
|
| 94 |
+
var n = colors.length,
|
| 95 |
+
r = new Array(n),
|
| 96 |
+
g = new Array(n),
|
| 97 |
+
b = new Array(n),
|
| 98 |
+
i, color;
|
| 99 |
+
for (i = 0; i < n; ++i) {
|
| 100 |
+
color = d3Color.rgb(colors[i]);
|
| 101 |
+
r[i] = color.r || 0;
|
| 102 |
+
g[i] = color.g || 0;
|
| 103 |
+
b[i] = color.b || 0;
|
| 104 |
+
}
|
| 105 |
+
r = spline(r);
|
| 106 |
+
g = spline(g);
|
| 107 |
+
b = spline(b);
|
| 108 |
+
color.opacity = 1;
|
| 109 |
+
return function(t) {
|
| 110 |
+
color.r = r(t);
|
| 111 |
+
color.g = g(t);
|
| 112 |
+
color.b = b(t);
|
| 113 |
+
return color + "";
|
| 114 |
+
};
|
| 115 |
+
};
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
var rgbBasis = rgbSpline(basis$1);
|
| 119 |
+
var rgbBasisClosed = rgbSpline(basisClosed);
|
| 120 |
+
|
| 121 |
+
function numberArray(a, b) {
|
| 122 |
+
if (!b) b = [];
|
| 123 |
+
var n = a ? Math.min(b.length, a.length) : 0,
|
| 124 |
+
c = b.slice(),
|
| 125 |
+
i;
|
| 126 |
+
return function(t) {
|
| 127 |
+
for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
|
| 128 |
+
return c;
|
| 129 |
+
};
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
function isNumberArray(x) {
|
| 133 |
+
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
function array(a, b) {
|
| 137 |
+
return (isNumberArray(b) ? numberArray : genericArray)(a, b);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
function genericArray(a, b) {
|
| 141 |
+
var nb = b ? b.length : 0,
|
| 142 |
+
na = a ? Math.min(nb, a.length) : 0,
|
| 143 |
+
x = new Array(na),
|
| 144 |
+
c = new Array(nb),
|
| 145 |
+
i;
|
| 146 |
+
|
| 147 |
+
for (i = 0; i < na; ++i) x[i] = value(a[i], b[i]);
|
| 148 |
+
for (; i < nb; ++i) c[i] = b[i];
|
| 149 |
+
|
| 150 |
+
return function(t) {
|
| 151 |
+
for (i = 0; i < na; ++i) c[i] = x[i](t);
|
| 152 |
+
return c;
|
| 153 |
+
};
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
function date(a, b) {
|
| 157 |
+
var d = new Date;
|
| 158 |
+
return a = +a, b = +b, function(t) {
|
| 159 |
+
return d.setTime(a * (1 - t) + b * t), d;
|
| 160 |
+
};
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
function number(a, b) {
|
| 164 |
+
return a = +a, b = +b, function(t) {
|
| 165 |
+
return a * (1 - t) + b * t;
|
| 166 |
+
};
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function object(a, b) {
|
| 170 |
+
var i = {},
|
| 171 |
+
c = {},
|
| 172 |
+
k;
|
| 173 |
+
|
| 174 |
+
if (a === null || typeof a !== "object") a = {};
|
| 175 |
+
if (b === null || typeof b !== "object") b = {};
|
| 176 |
+
|
| 177 |
+
for (k in b) {
|
| 178 |
+
if (k in a) {
|
| 179 |
+
i[k] = value(a[k], b[k]);
|
| 180 |
+
} else {
|
| 181 |
+
c[k] = b[k];
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
return function(t) {
|
| 186 |
+
for (k in i) c[k] = i[k](t);
|
| 187 |
+
return c;
|
| 188 |
+
};
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
|
| 192 |
+
reB = new RegExp(reA.source, "g");
|
| 193 |
+
|
| 194 |
+
function zero(b) {
|
| 195 |
+
return function() {
|
| 196 |
+
return b;
|
| 197 |
+
};
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
function one(b) {
|
| 201 |
+
return function(t) {
|
| 202 |
+
return b(t) + "";
|
| 203 |
+
};
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
function string(a, b) {
|
| 207 |
+
var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
|
| 208 |
+
am, // current match in a
|
| 209 |
+
bm, // current match in b
|
| 210 |
+
bs, // string preceding current number in b, if any
|
| 211 |
+
i = -1, // index in s
|
| 212 |
+
s = [], // string constants and placeholders
|
| 213 |
+
q = []; // number interpolators
|
| 214 |
+
|
| 215 |
+
// Coerce inputs to strings.
|
| 216 |
+
a = a + "", b = b + "";
|
| 217 |
+
|
| 218 |
+
// Interpolate pairs of numbers in a & b.
|
| 219 |
+
while ((am = reA.exec(a))
|
| 220 |
+
&& (bm = reB.exec(b))) {
|
| 221 |
+
if ((bs = bm.index) > bi) { // a string precedes the next number in b
|
| 222 |
+
bs = b.slice(bi, bs);
|
| 223 |
+
if (s[i]) s[i] += bs; // coalesce with previous string
|
| 224 |
+
else s[++i] = bs;
|
| 225 |
+
}
|
| 226 |
+
if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
|
| 227 |
+
if (s[i]) s[i] += bm; // coalesce with previous string
|
| 228 |
+
else s[++i] = bm;
|
| 229 |
+
} else { // interpolate non-matching numbers
|
| 230 |
+
s[++i] = null;
|
| 231 |
+
q.push({i: i, x: number(am, bm)});
|
| 232 |
+
}
|
| 233 |
+
bi = reB.lastIndex;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
// Add remains of b.
|
| 237 |
+
if (bi < b.length) {
|
| 238 |
+
bs = b.slice(bi);
|
| 239 |
+
if (s[i]) s[i] += bs; // coalesce with previous string
|
| 240 |
+
else s[++i] = bs;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
// Special optimization for only a single match.
|
| 244 |
+
// Otherwise, interpolate each of the numbers and rejoin the string.
|
| 245 |
+
return s.length < 2 ? (q[0]
|
| 246 |
+
? one(q[0].x)
|
| 247 |
+
: zero(b))
|
| 248 |
+
: (b = q.length, function(t) {
|
| 249 |
+
for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
|
| 250 |
+
return s.join("");
|
| 251 |
+
});
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
function value(a, b) {
|
| 255 |
+
var t = typeof b, c;
|
| 256 |
+
return b == null || t === "boolean" ? constant(b)
|
| 257 |
+
: (t === "number" ? number
|
| 258 |
+
: t === "string" ? ((c = d3Color.color(b)) ? (b = c, rgb) : string)
|
| 259 |
+
: b instanceof d3Color.color ? rgb
|
| 260 |
+
: b instanceof Date ? date
|
| 261 |
+
: isNumberArray(b) ? numberArray
|
| 262 |
+
: Array.isArray(b) ? genericArray
|
| 263 |
+
: typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
|
| 264 |
+
: number)(a, b);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
function discrete(range) {
|
| 268 |
+
var n = range.length;
|
| 269 |
+
return function(t) {
|
| 270 |
+
return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
| 271 |
+
};
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
function hue(a, b) {
|
| 275 |
+
var i = hue$1(+a, +b);
|
| 276 |
+
return function(t) {
|
| 277 |
+
var x = i(t);
|
| 278 |
+
return x - 360 * Math.floor(x / 360);
|
| 279 |
+
};
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
function round(a, b) {
|
| 283 |
+
return a = +a, b = +b, function(t) {
|
| 284 |
+
return Math.round(a * (1 - t) + b * t);
|
| 285 |
+
};
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
var degrees = 180 / Math.PI;
|
| 289 |
+
|
| 290 |
+
var identity = {
|
| 291 |
+
translateX: 0,
|
| 292 |
+
translateY: 0,
|
| 293 |
+
rotate: 0,
|
| 294 |
+
skewX: 0,
|
| 295 |
+
scaleX: 1,
|
| 296 |
+
scaleY: 1
|
| 297 |
+
};
|
| 298 |
+
|
| 299 |
+
function decompose(a, b, c, d, e, f) {
|
| 300 |
+
var scaleX, scaleY, skewX;
|
| 301 |
+
if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
|
| 302 |
+
if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
|
| 303 |
+
if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
|
| 304 |
+
if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
|
| 305 |
+
return {
|
| 306 |
+
translateX: e,
|
| 307 |
+
translateY: f,
|
| 308 |
+
rotate: Math.atan2(b, a) * degrees,
|
| 309 |
+
skewX: Math.atan(skewX) * degrees,
|
| 310 |
+
scaleX: scaleX,
|
| 311 |
+
scaleY: scaleY
|
| 312 |
+
};
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
var svgNode;
|
| 316 |
+
|
| 317 |
+
/* eslint-disable no-undef */
|
| 318 |
+
function parseCss(value) {
|
| 319 |
+
const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
|
| 320 |
+
return m.isIdentity ? identity : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
function parseSvg(value) {
|
| 324 |
+
if (value == null) return identity;
|
| 325 |
+
if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
| 326 |
+
svgNode.setAttribute("transform", value);
|
| 327 |
+
if (!(value = svgNode.transform.baseVal.consolidate())) return identity;
|
| 328 |
+
value = value.matrix;
|
| 329 |
+
return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
function interpolateTransform(parse, pxComma, pxParen, degParen) {
|
| 333 |
+
|
| 334 |
+
function pop(s) {
|
| 335 |
+
return s.length ? s.pop() + " " : "";
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
function translate(xa, ya, xb, yb, s, q) {
|
| 339 |
+
if (xa !== xb || ya !== yb) {
|
| 340 |
+
var i = s.push("translate(", null, pxComma, null, pxParen);
|
| 341 |
+
q.push({i: i - 4, x: number(xa, xb)}, {i: i - 2, x: number(ya, yb)});
|
| 342 |
+
} else if (xb || yb) {
|
| 343 |
+
s.push("translate(" + xb + pxComma + yb + pxParen);
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
function rotate(a, b, s, q) {
|
| 348 |
+
if (a !== b) {
|
| 349 |
+
if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
|
| 350 |
+
q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: number(a, b)});
|
| 351 |
+
} else if (b) {
|
| 352 |
+
s.push(pop(s) + "rotate(" + b + degParen);
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
function skewX(a, b, s, q) {
|
| 357 |
+
if (a !== b) {
|
| 358 |
+
q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: number(a, b)});
|
| 359 |
+
} else if (b) {
|
| 360 |
+
s.push(pop(s) + "skewX(" + b + degParen);
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
function scale(xa, ya, xb, yb, s, q) {
|
| 365 |
+
if (xa !== xb || ya !== yb) {
|
| 366 |
+
var i = s.push(pop(s) + "scale(", null, ",", null, ")");
|
| 367 |
+
q.push({i: i - 4, x: number(xa, xb)}, {i: i - 2, x: number(ya, yb)});
|
| 368 |
+
} else if (xb !== 1 || yb !== 1) {
|
| 369 |
+
s.push(pop(s) + "scale(" + xb + "," + yb + ")");
|
| 370 |
+
}
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
return function(a, b) {
|
| 374 |
+
var s = [], // string constants and placeholders
|
| 375 |
+
q = []; // number interpolators
|
| 376 |
+
a = parse(a), b = parse(b);
|
| 377 |
+
translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
|
| 378 |
+
rotate(a.rotate, b.rotate, s, q);
|
| 379 |
+
skewX(a.skewX, b.skewX, s, q);
|
| 380 |
+
scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
|
| 381 |
+
a = b = null; // gc
|
| 382 |
+
return function(t) {
|
| 383 |
+
var i = -1, n = q.length, o;
|
| 384 |
+
while (++i < n) s[(o = q[i]).i] = o.x(t);
|
| 385 |
+
return s.join("");
|
| 386 |
+
};
|
| 387 |
+
};
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
|
| 391 |
+
var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
|
| 392 |
+
|
| 393 |
+
var epsilon2 = 1e-12;
|
| 394 |
+
|
| 395 |
+
function cosh(x) {
|
| 396 |
+
return ((x = Math.exp(x)) + 1 / x) / 2;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
function sinh(x) {
|
| 400 |
+
return ((x = Math.exp(x)) - 1 / x) / 2;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
function tanh(x) {
|
| 404 |
+
return ((x = Math.exp(2 * x)) - 1) / (x + 1);
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
var zoom = (function zoomRho(rho, rho2, rho4) {
|
| 408 |
+
|
| 409 |
+
// p0 = [ux0, uy0, w0]
|
| 410 |
+
// p1 = [ux1, uy1, w1]
|
| 411 |
+
function zoom(p0, p1) {
|
| 412 |
+
var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
|
| 413 |
+
ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
|
| 414 |
+
dx = ux1 - ux0,
|
| 415 |
+
dy = uy1 - uy0,
|
| 416 |
+
d2 = dx * dx + dy * dy,
|
| 417 |
+
i,
|
| 418 |
+
S;
|
| 419 |
+
|
| 420 |
+
// Special case for u0 ≅ u1.
|
| 421 |
+
if (d2 < epsilon2) {
|
| 422 |
+
S = Math.log(w1 / w0) / rho;
|
| 423 |
+
i = function(t) {
|
| 424 |
+
return [
|
| 425 |
+
ux0 + t * dx,
|
| 426 |
+
uy0 + t * dy,
|
| 427 |
+
w0 * Math.exp(rho * t * S)
|
| 428 |
+
];
|
| 429 |
+
};
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
// General case.
|
| 433 |
+
else {
|
| 434 |
+
var d1 = Math.sqrt(d2),
|
| 435 |
+
b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
|
| 436 |
+
b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
|
| 437 |
+
r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
|
| 438 |
+
r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
|
| 439 |
+
S = (r1 - r0) / rho;
|
| 440 |
+
i = function(t) {
|
| 441 |
+
var s = t * S,
|
| 442 |
+
coshr0 = cosh(r0),
|
| 443 |
+
u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
|
| 444 |
+
return [
|
| 445 |
+
ux0 + u * dx,
|
| 446 |
+
uy0 + u * dy,
|
| 447 |
+
w0 * coshr0 / cosh(rho * s + r0)
|
| 448 |
+
];
|
| 449 |
+
};
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
i.duration = S * 1000 * rho / Math.SQRT2;
|
| 453 |
+
|
| 454 |
+
return i;
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
zoom.rho = function(_) {
|
| 458 |
+
var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
|
| 459 |
+
return zoomRho(_1, _2, _4);
|
| 460 |
+
};
|
| 461 |
+
|
| 462 |
+
return zoom;
|
| 463 |
+
})(Math.SQRT2, 2, 4);
|
| 464 |
+
|
| 465 |
+
function hsl(hue) {
|
| 466 |
+
return function(start, end) {
|
| 467 |
+
var h = hue((start = d3Color.hsl(start)).h, (end = d3Color.hsl(end)).h),
|
| 468 |
+
s = nogamma(start.s, end.s),
|
| 469 |
+
l = nogamma(start.l, end.l),
|
| 470 |
+
opacity = nogamma(start.opacity, end.opacity);
|
| 471 |
+
return function(t) {
|
| 472 |
+
start.h = h(t);
|
| 473 |
+
start.s = s(t);
|
| 474 |
+
start.l = l(t);
|
| 475 |
+
start.opacity = opacity(t);
|
| 476 |
+
return start + "";
|
| 477 |
+
};
|
| 478 |
+
}
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
var hsl$1 = hsl(hue$1);
|
| 482 |
+
var hslLong = hsl(nogamma);
|
| 483 |
+
|
| 484 |
+
function lab(start, end) {
|
| 485 |
+
var l = nogamma((start = d3Color.lab(start)).l, (end = d3Color.lab(end)).l),
|
| 486 |
+
a = nogamma(start.a, end.a),
|
| 487 |
+
b = nogamma(start.b, end.b),
|
| 488 |
+
opacity = nogamma(start.opacity, end.opacity);
|
| 489 |
+
return function(t) {
|
| 490 |
+
start.l = l(t);
|
| 491 |
+
start.a = a(t);
|
| 492 |
+
start.b = b(t);
|
| 493 |
+
start.opacity = opacity(t);
|
| 494 |
+
return start + "";
|
| 495 |
+
};
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
function hcl(hue) {
|
| 499 |
+
return function(start, end) {
|
| 500 |
+
var h = hue((start = d3Color.hcl(start)).h, (end = d3Color.hcl(end)).h),
|
| 501 |
+
c = nogamma(start.c, end.c),
|
| 502 |
+
l = nogamma(start.l, end.l),
|
| 503 |
+
opacity = nogamma(start.opacity, end.opacity);
|
| 504 |
+
return function(t) {
|
| 505 |
+
start.h = h(t);
|
| 506 |
+
start.c = c(t);
|
| 507 |
+
start.l = l(t);
|
| 508 |
+
start.opacity = opacity(t);
|
| 509 |
+
return start + "";
|
| 510 |
+
};
|
| 511 |
+
}
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
var hcl$1 = hcl(hue$1);
|
| 515 |
+
var hclLong = hcl(nogamma);
|
| 516 |
+
|
| 517 |
+
function cubehelix(hue) {
|
| 518 |
+
return (function cubehelixGamma(y) {
|
| 519 |
+
y = +y;
|
| 520 |
+
|
| 521 |
+
function cubehelix(start, end) {
|
| 522 |
+
var h = hue((start = d3Color.cubehelix(start)).h, (end = d3Color.cubehelix(end)).h),
|
| 523 |
+
s = nogamma(start.s, end.s),
|
| 524 |
+
l = nogamma(start.l, end.l),
|
| 525 |
+
opacity = nogamma(start.opacity, end.opacity);
|
| 526 |
+
return function(t) {
|
| 527 |
+
start.h = h(t);
|
| 528 |
+
start.s = s(t);
|
| 529 |
+
start.l = l(Math.pow(t, y));
|
| 530 |
+
start.opacity = opacity(t);
|
| 531 |
+
return start + "";
|
| 532 |
+
};
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
cubehelix.gamma = cubehelixGamma;
|
| 536 |
+
|
| 537 |
+
return cubehelix;
|
| 538 |
+
})(1);
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
var cubehelix$1 = cubehelix(hue$1);
|
| 542 |
+
var cubehelixLong = cubehelix(nogamma);
|
| 543 |
+
|
| 544 |
+
function piecewise(interpolate, values) {
|
| 545 |
+
if (values === undefined) values = interpolate, interpolate = value;
|
| 546 |
+
var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
|
| 547 |
+
while (i < n) I[i] = interpolate(v, v = values[++i]);
|
| 548 |
+
return function(t) {
|
| 549 |
+
var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
|
| 550 |
+
return I[i](t - i);
|
| 551 |
+
};
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
function quantize(interpolator, n) {
|
| 555 |
+
var samples = new Array(n);
|
| 556 |
+
for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
|
| 557 |
+
return samples;
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
exports.interpolate = value;
|
| 561 |
+
exports.interpolateArray = array;
|
| 562 |
+
exports.interpolateBasis = basis$1;
|
| 563 |
+
exports.interpolateBasisClosed = basisClosed;
|
| 564 |
+
exports.interpolateCubehelix = cubehelix$1;
|
| 565 |
+
exports.interpolateCubehelixLong = cubehelixLong;
|
| 566 |
+
exports.interpolateDate = date;
|
| 567 |
+
exports.interpolateDiscrete = discrete;
|
| 568 |
+
exports.interpolateHcl = hcl$1;
|
| 569 |
+
exports.interpolateHclLong = hclLong;
|
| 570 |
+
exports.interpolateHsl = hsl$1;
|
| 571 |
+
exports.interpolateHslLong = hslLong;
|
| 572 |
+
exports.interpolateHue = hue;
|
| 573 |
+
exports.interpolateLab = lab;
|
| 574 |
+
exports.interpolateNumber = number;
|
| 575 |
+
exports.interpolateNumberArray = numberArray;
|
| 576 |
+
exports.interpolateObject = object;
|
| 577 |
+
exports.interpolateRgb = rgb;
|
| 578 |
+
exports.interpolateRgbBasis = rgbBasis;
|
| 579 |
+
exports.interpolateRgbBasisClosed = rgbBasisClosed;
|
| 580 |
+
exports.interpolateRound = round;
|
| 581 |
+
exports.interpolateString = string;
|
| 582 |
+
exports.interpolateTransformCss = interpolateTransformCss;
|
| 583 |
+
exports.interpolateTransformSvg = interpolateTransformSvg;
|
| 584 |
+
exports.interpolateZoom = zoom;
|
| 585 |
+
exports.piecewise = piecewise;
|
| 586 |
+
exports.quantize = quantize;
|
| 587 |
+
|
| 588 |
+
Object.defineProperty(exports, '__esModule', { value: true });
|
| 589 |
+
|
| 590 |
+
})));
|
node_modules/d3-interpolate/dist/d3-interpolate.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// https://d3js.org/d3-interpolate/ v3.0.1 Copyright 2010-2021 Mike Bostock
|
| 2 |
+
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-color")):"function"==typeof define&&define.amd?define(["exports","d3-color"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{},t.d3)}(this,(function(t,n){"use strict";function r(t,n,r,e,a){var o=t*t,u=o*t;return((1-3*t+3*o-u)*n+(4-6*o+3*u)*r+(1+3*t+3*o-3*u)*e+u*a)/6}function e(t){var n=t.length-1;return function(e){var a=e<=0?e=0:e>=1?(e=1,n-1):Math.floor(e*n),o=t[a],u=t[a+1],i=a>0?t[a-1]:2*o-u,c=a<n-1?t[a+2]:2*u-o;return r((e-a/n)*n,i,o,u,c)}}function a(t){var n=t.length;return function(e){var a=Math.floor(((e%=1)<0?++e:e)*n),o=t[(a+n-1)%n],u=t[a%n],i=t[(a+1)%n],c=t[(a+2)%n];return r((e-a/n)*n,o,u,i,c)}}var o=t=>()=>t;function u(t,n){return function(r){return t+r*n}}function i(t,n){var r=n-t;return r?u(t,r>180||r<-180?r-360*Math.round(r/360):r):o(isNaN(t)?n:t)}function c(t){return 1==(t=+t)?l:function(n,r){return r-n?function(t,n,r){return t=Math.pow(t,r),n=Math.pow(n,r)-t,r=1/r,function(e){return Math.pow(t+e*n,r)}}(n,r,t):o(isNaN(n)?r:n)}}function l(t,n){var r=n-t;return r?u(t,r):o(isNaN(t)?n:t)}var f=function t(r){var e=c(r);function a(t,r){var a=e((t=n.rgb(t)).r,(r=n.rgb(r)).r),o=e(t.g,r.g),u=e(t.b,r.b),i=l(t.opacity,r.opacity);return function(n){return t.r=a(n),t.g=o(n),t.b=u(n),t.opacity=i(n),t+""}}return a.gamma=t,a}(1);function s(t){return function(r){var e,a,o=r.length,u=new Array(o),i=new Array(o),c=new Array(o);for(e=0;e<o;++e)a=n.rgb(r[e]),u[e]=a.r||0,i[e]=a.g||0,c[e]=a.b||0;return u=t(u),i=t(i),c=t(c),a.opacity=1,function(t){return a.r=u(t),a.g=i(t),a.b=c(t),a+""}}}var h=s(e),p=s(a);function v(t,n){n||(n=[]);var r,e=t?Math.min(n.length,t.length):0,a=n.slice();return function(o){for(r=0;r<e;++r)a[r]=t[r]*(1-o)+n[r]*o;return a}}function g(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function M(t,n){var r,e=n?n.length:0,a=t?Math.min(e,t.length):0,o=new Array(a),u=new Array(e);for(r=0;r<a;++r)o[r]=X(t[r],n[r]);for(;r<e;++r)u[r]=n[r];return function(t){for(r=0;r<a;++r)u[r]=o[r](t);return u}}function y(t,n){var r=new Date;return t=+t,n=+n,function(e){return r.setTime(t*(1-e)+n*e),r}}function b(t,n){return t=+t,n=+n,function(r){return t*(1-r)+n*r}}function d(t,n){var r,e={},a={};for(r in null!==t&&"object"==typeof t||(t={}),null!==n&&"object"==typeof n||(n={}),n)r in t?e[r]=X(t[r],n[r]):a[r]=n[r];return function(t){for(r in e)a[r]=e[r](t);return a}}var x=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,w=new RegExp(x.source,"g");function m(t,n){var r,e,a,o=x.lastIndex=w.lastIndex=0,u=-1,i=[],c=[];for(t+="",n+="";(r=x.exec(t))&&(e=w.exec(n));)(a=e.index)>o&&(a=n.slice(o,a),i[u]?i[u]+=a:i[++u]=a),(r=r[0])===(e=e[0])?i[u]?i[u]+=e:i[++u]=e:(i[++u]=null,c.push({i:u,x:b(r,e)})),o=w.lastIndex;return o<n.length&&(a=n.slice(o),i[u]?i[u]+=a:i[++u]=a),i.length<2?c[0]?function(t){return function(n){return t(n)+""}}(c[0].x):function(t){return function(){return t}}(n):(n=c.length,function(t){for(var r,e=0;e<n;++e)i[(r=c[e]).i]=r.x(t);return i.join("")})}function X(t,r){var e,a=typeof r;return null==r||"boolean"===a?o(r):("number"===a?b:"string"===a?(e=n.color(r))?(r=e,f):m:r instanceof n.color?f:r instanceof Date?y:g(r)?v:Array.isArray(r)?M:"function"!=typeof r.valueOf&&"function"!=typeof r.toString||isNaN(r)?d:b)(t,r)}var A,N=180/Math.PI,S={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Y(t,n,r,e,a,o){var u,i,c;return(u=Math.sqrt(t*t+n*n))&&(t/=u,n/=u),(c=t*r+n*e)&&(r-=t*c,e-=n*c),(i=Math.sqrt(r*r+e*e))&&(r/=i,e/=i,c/=i),t*e<n*r&&(t=-t,n=-n,c=-c,u=-u),{translateX:a,translateY:o,rotate:Math.atan2(n,t)*N,skewX:Math.atan(c)*N,scaleX:u,scaleY:i}}function j(t,n,r,e){function a(t){return t.length?t.pop()+" ":""}return function(o,u){var i=[],c=[];return o=t(o),u=t(u),function(t,e,a,o,u,i){if(t!==a||e!==o){var c=u.push("translate(",null,n,null,r);i.push({i:c-4,x:b(t,a)},{i:c-2,x:b(e,o)})}else(a||o)&&u.push("translate("+a+n+o+r)}(o.translateX,o.translateY,u.translateX,u.translateY,i,c),function(t,n,r,o){t!==n?(t-n>180?n+=360:n-t>180&&(t+=360),o.push({i:r.push(a(r)+"rotate(",null,e)-2,x:b(t,n)})):n&&r.push(a(r)+"rotate("+n+e)}(o.rotate,u.rotate,i,c),function(t,n,r,o){t!==n?o.push({i:r.push(a(r)+"skewX(",null,e)-2,x:b(t,n)}):n&&r.push(a(r)+"skewX("+n+e)}(o.skewX,u.skewX,i,c),function(t,n,r,e,o,u){if(t!==r||n!==e){var i=o.push(a(o)+"scale(",null,",",null,")");u.push({i:i-4,x:b(t,r)},{i:i-2,x:b(n,e)})}else 1===r&&1===e||o.push(a(o)+"scale("+r+","+e+")")}(o.scaleX,o.scaleY,u.scaleX,u.scaleY,i,c),o=u=null,function(t){for(var n,r=-1,e=c.length;++r<e;)i[(n=c[r]).i]=n.x(t);return i.join("")}}}var q=j((function(t){const n=new("function"==typeof DOMMatrix?DOMMatrix:WebKitCSSMatrix)(t+"");return n.isIdentity?S:Y(n.a,n.b,n.c,n.d,n.e,n.f)}),"px, ","px)","deg)"),D=j((function(t){return null==t?S:(A||(A=document.createElementNS("http://www.w3.org/2000/svg","g")),A.setAttribute("transform",t),(t=A.transform.baseVal.consolidate())?Y((t=t.matrix).a,t.b,t.c,t.d,t.e,t.f):S)}),", ",")",")");function R(t){return((t=Math.exp(t))+1/t)/2}var T=function t(n,r,e){function a(t,a){var o,u,i=t[0],c=t[1],l=t[2],f=a[0],s=a[1],h=a[2],p=f-i,v=s-c,g=p*p+v*v;if(g<1e-12)u=Math.log(h/l)/n,o=function(t){return[i+t*p,c+t*v,l*Math.exp(n*t*u)]};else{var M=Math.sqrt(g),y=(h*h-l*l+e*g)/(2*l*r*M),b=(h*h-l*l-e*g)/(2*h*r*M),d=Math.log(Math.sqrt(y*y+1)-y),x=Math.log(Math.sqrt(b*b+1)-b);u=(x-d)/n,o=function(t){var e,a=t*u,o=R(d),f=l/(r*M)*(o*(e=n*a+d,((e=Math.exp(2*e))-1)/(e+1))-function(t){return((t=Math.exp(t))-1/t)/2}(d));return[i+f*p,c+f*v,l*o/R(n*a+d)]}}return o.duration=1e3*u*n/Math.SQRT2,o}return a.rho=function(n){var r=Math.max(.001,+n),e=r*r;return t(r,e,e*e)},a}(Math.SQRT2,2,4);function k(t){return function(r,e){var a=t((r=n.hsl(r)).h,(e=n.hsl(e)).h),o=l(r.s,e.s),u=l(r.l,e.l),i=l(r.opacity,e.opacity);return function(t){return r.h=a(t),r.s=o(t),r.l=u(t),r.opacity=i(t),r+""}}}var C=k(i),B=k(l);function H(t){return function(r,e){var a=t((r=n.hcl(r)).h,(e=n.hcl(e)).h),o=l(r.c,e.c),u=l(r.l,e.l),i=l(r.opacity,e.opacity);return function(t){return r.h=a(t),r.c=o(t),r.l=u(t),r.opacity=i(t),r+""}}}var I=H(i),O=H(l);function L(t){return function r(e){function a(r,a){var o=t((r=n.cubehelix(r)).h,(a=n.cubehelix(a)).h),u=l(r.s,a.s),i=l(r.l,a.l),c=l(r.opacity,a.opacity);return function(t){return r.h=o(t),r.s=u(t),r.l=i(Math.pow(t,e)),r.opacity=c(t),r+""}}return e=+e,a.gamma=r,a}(1)}var E=L(i),V=L(l);t.interpolate=X,t.interpolateArray=function(t,n){return(g(n)?v:M)(t,n)},t.interpolateBasis=e,t.interpolateBasisClosed=a,t.interpolateCubehelix=E,t.interpolateCubehelixLong=V,t.interpolateDate=y,t.interpolateDiscrete=function(t){var n=t.length;return function(r){return t[Math.max(0,Math.min(n-1,Math.floor(r*n)))]}},t.interpolateHcl=I,t.interpolateHclLong=O,t.interpolateHsl=C,t.interpolateHslLong=B,t.interpolateHue=function(t,n){var r=i(+t,+n);return function(t){var n=r(t);return n-360*Math.floor(n/360)}},t.interpolateLab=function(t,r){var e=l((t=n.lab(t)).l,(r=n.lab(r)).l),a=l(t.a,r.a),o=l(t.b,r.b),u=l(t.opacity,r.opacity);return function(n){return t.l=e(n),t.a=a(n),t.b=o(n),t.opacity=u(n),t+""}},t.interpolateNumber=b,t.interpolateNumberArray=v,t.interpolateObject=d,t.interpolateRgb=f,t.interpolateRgbBasis=h,t.interpolateRgbBasisClosed=p,t.interpolateRound=function(t,n){return t=+t,n=+n,function(r){return Math.round(t*(1-r)+n*r)}},t.interpolateString=m,t.interpolateTransformCss=q,t.interpolateTransformSvg=D,t.interpolateZoom=T,t.piecewise=function(t,n){void 0===n&&(n=t,t=X);for(var r=0,e=n.length-1,a=n[0],o=new Array(e<0?0:e);r<e;)o[r]=t(a,a=n[++r]);return function(t){var n=Math.max(0,Math.min(e-1,Math.floor(t*=e)));return o[n](t-n)}},t.quantize=function(t,n){for(var r=new Array(n),e=0;e<n;++e)r[e]=t(e/(n-1));return r},Object.defineProperty(t,"__esModule",{value:!0})}));
|
node_modules/d3-interpolate/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "d3-interpolate",
|
| 3 |
+
"version": "3.0.1",
|
| 4 |
+
"description": "Interpolate numbers, colors, strings, arrays, objects, whatever!",
|
| 5 |
+
"homepage": "https://d3js.org/d3-interpolate/",
|
| 6 |
+
"repository": {
|
| 7 |
+
"type": "git",
|
| 8 |
+
"url": "https://github.com/d3/d3-interpolate.git"
|
| 9 |
+
},
|
| 10 |
+
"keywords": [
|
| 11 |
+
"d3",
|
| 12 |
+
"d3-module",
|
| 13 |
+
"interpolate",
|
| 14 |
+
"interpolation",
|
| 15 |
+
"color"
|
| 16 |
+
],
|
| 17 |
+
"license": "ISC",
|
| 18 |
+
"author": {
|
| 19 |
+
"name": "Mike Bostock",
|
| 20 |
+
"url": "http://bost.ocks.org/mike"
|
| 21 |
+
},
|
| 22 |
+
"type": "module",
|
| 23 |
+
"files": [
|
| 24 |
+
"dist/**/*.js",
|
| 25 |
+
"src/**/*.js"
|
| 26 |
+
],
|
| 27 |
+
"module": "src/index.js",
|
| 28 |
+
"main": "src/index.js",
|
| 29 |
+
"jsdelivr": "dist/d3-interpolate.min.js",
|
| 30 |
+
"unpkg": "dist/d3-interpolate.min.js",
|
| 31 |
+
"exports": {
|
| 32 |
+
"umd": "./dist/d3-interpolate.min.js",
|
| 33 |
+
"default": "./src/index.js"
|
| 34 |
+
},
|
| 35 |
+
"sideEffects": false,
|
| 36 |
+
"dependencies": {
|
| 37 |
+
"d3-color": "1 - 3"
|
| 38 |
+
},
|
| 39 |
+
"devDependencies": {
|
| 40 |
+
"eslint": "7",
|
| 41 |
+
"mocha": "8",
|
| 42 |
+
"rollup": "2",
|
| 43 |
+
"rollup-plugin-terser": "7"
|
| 44 |
+
},
|
| 45 |
+
"scripts": {
|
| 46 |
+
"test": "mocha 'test/**/*-test.js' && eslint src test",
|
| 47 |
+
"prepublishOnly": "rm -rf dist && yarn test && rollup -c",
|
| 48 |
+
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd -"
|
| 49 |
+
},
|
| 50 |
+
"engines": {
|
| 51 |
+
"node": ">=12"
|
| 52 |
+
}
|
| 53 |
+
}
|
node_modules/d3-interpolate/src/array.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import value from "./value.js";
|
| 2 |
+
import numberArray, {isNumberArray} from "./numberArray.js";
|
| 3 |
+
|
| 4 |
+
export default function(a, b) {
|
| 5 |
+
return (isNumberArray(b) ? numberArray : genericArray)(a, b);
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
export function genericArray(a, b) {
|
| 9 |
+
var nb = b ? b.length : 0,
|
| 10 |
+
na = a ? Math.min(nb, a.length) : 0,
|
| 11 |
+
x = new Array(na),
|
| 12 |
+
c = new Array(nb),
|
| 13 |
+
i;
|
| 14 |
+
|
| 15 |
+
for (i = 0; i < na; ++i) x[i] = value(a[i], b[i]);
|
| 16 |
+
for (; i < nb; ++i) c[i] = b[i];
|
| 17 |
+
|
| 18 |
+
return function(t) {
|
| 19 |
+
for (i = 0; i < na; ++i) c[i] = x[i](t);
|
| 20 |
+
return c;
|
| 21 |
+
};
|
| 22 |
+
}
|