UNPKG

560 kBJavaScriptView Raw
1// https://d3js.org v6.7.0 Copyright 2021 Mike Bostock
2(function (global, factory) {
3typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4typeof define === 'function' && define.amd ? define(['exports'], factory) :
5(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
6}(this, (function (exports) { 'use strict';
7
8var version = "6.7.0";
9
10function ascending$3(a, b) {
11 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
12}
13
14function bisector(f) {
15 let delta = f;
16 let compare = f;
17
18 if (f.length === 1) {
19 delta = (d, x) => f(d) - x;
20 compare = ascendingComparator(f);
21 }
22
23 function left(a, x, lo, hi) {
24 if (lo == null) lo = 0;
25 if (hi == null) hi = a.length;
26 while (lo < hi) {
27 const mid = (lo + hi) >>> 1;
28 if (compare(a[mid], x) < 0) lo = mid + 1;
29 else hi = mid;
30 }
31 return lo;
32 }
33
34 function right(a, x, lo, hi) {
35 if (lo == null) lo = 0;
36 if (hi == null) hi = a.length;
37 while (lo < hi) {
38 const mid = (lo + hi) >>> 1;
39 if (compare(a[mid], x) > 0) hi = mid;
40 else lo = mid + 1;
41 }
42 return lo;
43 }
44
45 function center(a, x, lo, hi) {
46 if (lo == null) lo = 0;
47 if (hi == null) hi = a.length;
48 const i = left(a, x, lo, hi - 1);
49 return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
50 }
51
52 return {left, center, right};
53}
54
55function ascendingComparator(f) {
56 return (d, x) => ascending$3(f(d), x);
57}
58
59function number$3(x) {
60 return x === null ? NaN : +x;
61}
62
63function* numbers(values, valueof) {
64 if (valueof === undefined) {
65 for (let value of values) {
66 if (value != null && (value = +value) >= value) {
67 yield value;
68 }
69 }
70 } else {
71 let index = -1;
72 for (let value of values) {
73 if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
74 yield value;
75 }
76 }
77 }
78}
79
80const ascendingBisect = bisector(ascending$3);
81const bisectRight = ascendingBisect.right;
82const bisectLeft = ascendingBisect.left;
83const bisectCenter = bisector(number$3).center;
84
85function count$1(values, valueof) {
86 let count = 0;
87 if (valueof === undefined) {
88 for (let value of values) {
89 if (value != null && (value = +value) >= value) {
90 ++count;
91 }
92 }
93 } else {
94 let index = -1;
95 for (let value of values) {
96 if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
97 ++count;
98 }
99 }
100 }
101 return count;
102}
103
104function length$3(array) {
105 return array.length | 0;
106}
107
108function empty$2(length) {
109 return !(length > 0);
110}
111
112function arrayify(values) {
113 return typeof values !== "object" || "length" in values ? values : Array.from(values);
114}
115
116function reducer(reduce) {
117 return values => reduce(...values);
118}
119
120function cross$2(...values) {
121 const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
122 values = values.map(arrayify);
123 const lengths = values.map(length$3);
124 const j = values.length - 1;
125 const index = new Array(j + 1).fill(0);
126 const product = [];
127 if (j < 0 || lengths.some(empty$2)) return product;
128 while (true) {
129 product.push(index.map((j, i) => values[i][j]));
130 let i = j;
131 while (++index[i] === lengths[i]) {
132 if (i === 0) return reduce ? product.map(reduce) : product;
133 index[i--] = 0;
134 }
135 }
136}
137
138function cumsum(values, valueof) {
139 var sum = 0, index = 0;
140 return Float64Array.from(values, valueof === undefined
141 ? v => (sum += +v || 0)
142 : v => (sum += +valueof(v, index++, values) || 0));
143}
144
145function descending$2(a, b) {
146 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
147}
148
149function variance(values, valueof) {
150 let count = 0;
151 let delta;
152 let mean = 0;
153 let sum = 0;
154 if (valueof === undefined) {
155 for (let value of values) {
156 if (value != null && (value = +value) >= value) {
157 delta = value - mean;
158 mean += delta / ++count;
159 sum += delta * (value - mean);
160 }
161 }
162 } else {
163 let index = -1;
164 for (let value of values) {
165 if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
166 delta = value - mean;
167 mean += delta / ++count;
168 sum += delta * (value - mean);
169 }
170 }
171 }
172 if (count > 1) return sum / (count - 1);
173}
174
175function deviation(values, valueof) {
176 const v = variance(values, valueof);
177 return v ? Math.sqrt(v) : v;
178}
179
180function extent$1(values, valueof) {
181 let min;
182 let max;
183 if (valueof === undefined) {
184 for (const value of values) {
185 if (value != null) {
186 if (min === undefined) {
187 if (value >= value) min = max = value;
188 } else {
189 if (min > value) min = value;
190 if (max < value) max = value;
191 }
192 }
193 }
194 } else {
195 let index = -1;
196 for (let value of values) {
197 if ((value = valueof(value, ++index, values)) != null) {
198 if (min === undefined) {
199 if (value >= value) min = max = value;
200 } else {
201 if (min > value) min = value;
202 if (max < value) max = value;
203 }
204 }
205 }
206 }
207 return [min, max];
208}
209
210// https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Modules/mathmodule.c#L1423
211class Adder {
212 constructor() {
213 this._partials = new Float64Array(32);
214 this._n = 0;
215 }
216 add(x) {
217 const p = this._partials;
218 let i = 0;
219 for (let j = 0; j < this._n && j < 32; j++) {
220 const y = p[j],
221 hi = x + y,
222 lo = Math.abs(x) < Math.abs(y) ? x - (hi - y) : y - (hi - x);
223 if (lo) p[i++] = lo;
224 x = hi;
225 }
226 p[i] = x;
227 this._n = i + 1;
228 return this;
229 }
230 valueOf() {
231 const p = this._partials;
232 let n = this._n, x, y, lo, hi = 0;
233 if (n > 0) {
234 hi = p[--n];
235 while (n > 0) {
236 x = hi;
237 y = p[--n];
238 hi = x + y;
239 lo = y - (hi - x);
240 if (lo) break;
241 }
242 if (n > 0 && ((lo < 0 && p[n - 1] < 0) || (lo > 0 && p[n - 1] > 0))) {
243 y = lo * 2;
244 x = hi + y;
245 if (y == x - hi) hi = x;
246 }
247 }
248 return hi;
249 }
250}
251
252function fsum(values, valueof) {
253 const adder = new Adder();
254 if (valueof === undefined) {
255 for (let value of values) {
256 if (value = +value) {
257 adder.add(value);
258 }
259 }
260 } else {
261 let index = -1;
262 for (let value of values) {
263 if (value = +valueof(value, ++index, values)) {
264 adder.add(value);
265 }
266 }
267 }
268 return +adder;
269}
270
271function fcumsum(values, valueof) {
272 const adder = new Adder();
273 let index = -1;
274 return Float64Array.from(values, valueof === undefined
275 ? v => adder.add(+v || 0)
276 : v => adder.add(+valueof(v, ++index, values) || 0)
277 );
278}
279
280class InternMap extends Map {
281 constructor(entries, key = keyof) {
282 super();
283 Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
284 if (entries != null) for (const [key, value] of entries) this.set(key, value);
285 }
286 get(key) {
287 return super.get(intern_get(this, key));
288 }
289 has(key) {
290 return super.has(intern_get(this, key));
291 }
292 set(key, value) {
293 return super.set(intern_set(this, key), value);
294 }
295 delete(key) {
296 return super.delete(intern_delete(this, key));
297 }
298}
299
300class InternSet extends Set {
301 constructor(values, key = keyof) {
302 super();
303 Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
304 if (values != null) for (const value of values) this.add(value);
305 }
306 has(value) {
307 return super.has(intern_get(this, value));
308 }
309 add(value) {
310 return super.add(intern_set(this, value));
311 }
312 delete(value) {
313 return super.delete(intern_delete(this, value));
314 }
315}
316
317function intern_get({_intern, _key}, value) {
318 const key = _key(value);
319 return _intern.has(key) ? _intern.get(key) : value;
320}
321
322function intern_set({_intern, _key}, value) {
323 const key = _key(value);
324 if (_intern.has(key)) return _intern.get(key);
325 _intern.set(key, value);
326 return value;
327}
328
329function intern_delete({_intern, _key}, value) {
330 const key = _key(value);
331 if (_intern.has(key)) {
332 value = _intern.get(value);
333 _intern.delete(key);
334 }
335 return value;
336}
337
338function keyof(value) {
339 return value !== null && typeof value === "object" ? value.valueOf() : value;
340}
341
342function identity$9(x) {
343 return x;
344}
345
346function group(values, ...keys) {
347 return nest(values, identity$9, identity$9, keys);
348}
349
350function groups(values, ...keys) {
351 return nest(values, Array.from, identity$9, keys);
352}
353
354function rollup(values, reduce, ...keys) {
355 return nest(values, identity$9, reduce, keys);
356}
357
358function rollups(values, reduce, ...keys) {
359 return nest(values, Array.from, reduce, keys);
360}
361
362function index$4(values, ...keys) {
363 return nest(values, identity$9, unique, keys);
364}
365
366function indexes(values, ...keys) {
367 return nest(values, Array.from, unique, keys);
368}
369
370function unique(values) {
371 if (values.length !== 1) throw new Error("duplicate key");
372 return values[0];
373}
374
375function nest(values, map, reduce, keys) {
376 return (function regroup(values, i) {
377 if (i >= keys.length) return reduce(values);
378 const groups = new InternMap();
379 const keyof = keys[i++];
380 let index = -1;
381 for (const value of values) {
382 const key = keyof(value, ++index, values);
383 const group = groups.get(key);
384 if (group) group.push(value);
385 else groups.set(key, [value]);
386 }
387 for (const [key, values] of groups) {
388 groups.set(key, regroup(values, i));
389 }
390 return map(groups);
391 })(values, 0);
392}
393
394function permute(source, keys) {
395 return Array.from(keys, key => source[key]);
396}
397
398function sort(values, ...F) {
399 if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
400 values = Array.from(values);
401 let [f = ascending$3] = F;
402 if (f.length === 1 || F.length > 1) {
403 const index = Uint32Array.from(values, (d, i) => i);
404 if (F.length > 1) {
405 F = F.map(f => values.map(f));
406 index.sort((i, j) => {
407 for (const f of F) {
408 const c = ascending$3(f[i], f[j]);
409 if (c) return c;
410 }
411 });
412 } else {
413 f = values.map(f);
414 index.sort((i, j) => ascending$3(f[i], f[j]));
415 }
416 return permute(values, index);
417 }
418 return values.sort(f);
419}
420
421function groupSort(values, reduce, key) {
422 return (reduce.length === 1
423 ? sort(rollup(values, reduce, key), (([ak, av], [bk, bv]) => ascending$3(av, bv) || ascending$3(ak, bk)))
424 : sort(group(values, key), (([ak, av], [bk, bv]) => reduce(av, bv) || ascending$3(ak, bk))))
425 .map(([key]) => key);
426}
427
428var array$5 = Array.prototype;
429
430var slice$4 = array$5.slice;
431
432function constant$b(x) {
433 return function() {
434 return x;
435 };
436}
437
438var e10 = Math.sqrt(50),
439 e5 = Math.sqrt(10),
440 e2 = Math.sqrt(2);
441
442function ticks(start, stop, count) {
443 var reverse,
444 i = -1,
445 n,
446 ticks,
447 step;
448
449 stop = +stop, start = +start, count = +count;
450 if (start === stop && count > 0) return [start];
451 if (reverse = stop < start) n = start, start = stop, stop = n;
452 if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
453
454 if (step > 0) {
455 let r0 = Math.round(start / step), r1 = Math.round(stop / step);
456 if (r0 * step < start) ++r0;
457 if (r1 * step > stop) --r1;
458 ticks = new Array(n = r1 - r0 + 1);
459 while (++i < n) ticks[i] = (r0 + i) * step;
460 } else {
461 step = -step;
462 let r0 = Math.round(start * step), r1 = Math.round(stop * step);
463 if (r0 / step < start) ++r0;
464 if (r1 / step > stop) --r1;
465 ticks = new Array(n = r1 - r0 + 1);
466 while (++i < n) ticks[i] = (r0 + i) / step;
467 }
468
469 if (reverse) ticks.reverse();
470
471 return ticks;
472}
473
474function tickIncrement(start, stop, count) {
475 var step = (stop - start) / Math.max(0, count),
476 power = Math.floor(Math.log(step) / Math.LN10),
477 error = step / Math.pow(10, power);
478 return power >= 0
479 ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
480 : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
481}
482
483function tickStep(start, stop, count) {
484 var step0 = Math.abs(stop - start) / Math.max(0, count),
485 step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
486 error = step0 / step1;
487 if (error >= e10) step1 *= 10;
488 else if (error >= e5) step1 *= 5;
489 else if (error >= e2) step1 *= 2;
490 return stop < start ? -step1 : step1;
491}
492
493function nice$1(start, stop, count) {
494 let prestep;
495 while (true) {
496 const step = tickIncrement(start, stop, count);
497 if (step === prestep || step === 0 || !isFinite(step)) {
498 return [start, stop];
499 } else if (step > 0) {
500 start = Math.floor(start / step) * step;
501 stop = Math.ceil(stop / step) * step;
502 } else if (step < 0) {
503 start = Math.ceil(start * step) / step;
504 stop = Math.floor(stop * step) / step;
505 }
506 prestep = step;
507 }
508}
509
510function thresholdSturges(values) {
511 return Math.ceil(Math.log(count$1(values)) / Math.LN2) + 1;
512}
513
514function bin() {
515 var value = identity$9,
516 domain = extent$1,
517 threshold = thresholdSturges;
518
519 function histogram(data) {
520 if (!Array.isArray(data)) data = Array.from(data);
521
522 var i,
523 n = data.length,
524 x,
525 values = new Array(n);
526
527 for (i = 0; i < n; ++i) {
528 values[i] = value(data[i], i, data);
529 }
530
531 var xz = domain(values),
532 x0 = xz[0],
533 x1 = xz[1],
534 tz = threshold(values, x0, x1);
535
536 // Convert number of thresholds into uniform thresholds, and nice the
537 // default domain accordingly.
538 if (!Array.isArray(tz)) {
539 const max = x1, tn = +tz;
540 if (domain === extent$1) [x0, x1] = nice$1(x0, x1, tn);
541 tz = ticks(x0, x1, tn);
542
543 // If the last threshold is coincident with the domain’s upper bound, the
544 // last bin will be zero-width. If the default domain is used, and this
545 // last threshold is coincident with the maximum input value, we can
546 // extend the niced upper bound by one tick to ensure uniform bin widths;
547 // otherwise, we simply remove the last threshold. Note that we don’t
548 // coerce values or the domain to numbers, and thus must be careful to
549 // compare order (>=) rather than strict equality (===)!
550 if (tz[tz.length - 1] >= x1) {
551 if (max >= x1 && domain === extent$1) {
552 const step = tickIncrement(x0, x1, tn);
553 if (isFinite(step)) {
554 if (step > 0) {
555 x1 = (Math.floor(x1 / step) + 1) * step;
556 } else if (step < 0) {
557 x1 = (Math.ceil(x1 * -step) + 1) / -step;
558 }
559 }
560 } else {
561 tz.pop();
562 }
563 }
564 }
565
566 // Remove any thresholds outside the domain.
567 var m = tz.length;
568 while (tz[0] <= x0) tz.shift(), --m;
569 while (tz[m - 1] > x1) tz.pop(), --m;
570
571 var bins = new Array(m + 1),
572 bin;
573
574 // Initialize bins.
575 for (i = 0; i <= m; ++i) {
576 bin = bins[i] = [];
577 bin.x0 = i > 0 ? tz[i - 1] : x0;
578 bin.x1 = i < m ? tz[i] : x1;
579 }
580
581 // Assign data to bins by value, ignoring any outside the domain.
582 for (i = 0; i < n; ++i) {
583 x = values[i];
584 if (x0 <= x && x <= x1) {
585 bins[bisectRight(tz, x, 0, m)].push(data[i]);
586 }
587 }
588
589 return bins;
590 }
591
592 histogram.value = function(_) {
593 return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(_), histogram) : value;
594 };
595
596 histogram.domain = function(_) {
597 return arguments.length ? (domain = typeof _ === "function" ? _ : constant$b([_[0], _[1]]), histogram) : domain;
598 };
599
600 histogram.thresholds = function(_) {
601 return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$b(slice$4.call(_)) : constant$b(_), histogram) : threshold;
602 };
603
604 return histogram;
605}
606
607function max$3(values, valueof) {
608 let max;
609 if (valueof === undefined) {
610 for (const value of values) {
611 if (value != null
612 && (max < value || (max === undefined && value >= value))) {
613 max = value;
614 }
615 }
616 } else {
617 let index = -1;
618 for (let value of values) {
619 if ((value = valueof(value, ++index, values)) != null
620 && (max < value || (max === undefined && value >= value))) {
621 max = value;
622 }
623 }
624 }
625 return max;
626}
627
628function min$2(values, valueof) {
629 let min;
630 if (valueof === undefined) {
631 for (const value of values) {
632 if (value != null
633 && (min > value || (min === undefined && value >= value))) {
634 min = value;
635 }
636 }
637 } else {
638 let index = -1;
639 for (let value of values) {
640 if ((value = valueof(value, ++index, values)) != null
641 && (min > value || (min === undefined && value >= value))) {
642 min = value;
643 }
644 }
645 }
646 return min;
647}
648
649// Based on https://github.com/mourner/quickselect
650// ISC license, Copyright 2018 Vladimir Agafonkin.
651function quickselect(array, k, left = 0, right = array.length - 1, compare = ascending$3) {
652 while (right > left) {
653 if (right - left > 600) {
654 const n = right - left + 1;
655 const m = k - left + 1;
656 const z = Math.log(n);
657 const s = 0.5 * Math.exp(2 * z / 3);
658 const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
659 const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
660 const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
661 quickselect(array, k, newLeft, newRight, compare);
662 }
663
664 const t = array[k];
665 let i = left;
666 let j = right;
667
668 swap$1(array, left, k);
669 if (compare(array[right], t) > 0) swap$1(array, left, right);
670
671 while (i < j) {
672 swap$1(array, i, j), ++i, --j;
673 while (compare(array[i], t) < 0) ++i;
674 while (compare(array[j], t) > 0) --j;
675 }
676
677 if (compare(array[left], t) === 0) swap$1(array, left, j);
678 else ++j, swap$1(array, j, right);
679
680 if (j <= k) left = j + 1;
681 if (k <= j) right = j - 1;
682 }
683 return array;
684}
685
686function swap$1(array, i, j) {
687 const t = array[i];
688 array[i] = array[j];
689 array[j] = t;
690}
691
692function quantile$1(values, p, valueof) {
693 values = Float64Array.from(numbers(values, valueof));
694 if (!(n = values.length)) return;
695 if ((p = +p) <= 0 || n < 2) return min$2(values);
696 if (p >= 1) return max$3(values);
697 var n,
698 i = (n - 1) * p,
699 i0 = Math.floor(i),
700 value0 = max$3(quickselect(values, i0).subarray(0, i0 + 1)),
701 value1 = min$2(values.subarray(i0 + 1));
702 return value0 + (value1 - value0) * (i - i0);
703}
704
705function quantileSorted(values, p, valueof = number$3) {
706 if (!(n = values.length)) return;
707 if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
708 if (p >= 1) return +valueof(values[n - 1], n - 1, values);
709 var n,
710 i = (n - 1) * p,
711 i0 = Math.floor(i),
712 value0 = +valueof(values[i0], i0, values),
713 value1 = +valueof(values[i0 + 1], i0 + 1, values);
714 return value0 + (value1 - value0) * (i - i0);
715}
716
717function freedmanDiaconis(values, min, max) {
718 return Math.ceil((max - min) / (2 * (quantile$1(values, 0.75) - quantile$1(values, 0.25)) * Math.pow(count$1(values), -1 / 3)));
719}
720
721function scott(values, min, max) {
722 return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(count$1(values), -1 / 3)));
723}
724
725function maxIndex(values, valueof) {
726 let max;
727 let maxIndex = -1;
728 let index = -1;
729 if (valueof === undefined) {
730 for (const value of values) {
731 ++index;
732 if (value != null
733 && (max < value || (max === undefined && value >= value))) {
734 max = value, maxIndex = index;
735 }
736 }
737 } else {
738 for (let value of values) {
739 if ((value = valueof(value, ++index, values)) != null
740 && (max < value || (max === undefined && value >= value))) {
741 max = value, maxIndex = index;
742 }
743 }
744 }
745 return maxIndex;
746}
747
748function mean(values, valueof) {
749 let count = 0;
750 let sum = 0;
751 if (valueof === undefined) {
752 for (let value of values) {
753 if (value != null && (value = +value) >= value) {
754 ++count, sum += value;
755 }
756 }
757 } else {
758 let index = -1;
759 for (let value of values) {
760 if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
761 ++count, sum += value;
762 }
763 }
764 }
765 if (count) return sum / count;
766}
767
768function median(values, valueof) {
769 return quantile$1(values, 0.5, valueof);
770}
771
772function* flatten(arrays) {
773 for (const array of arrays) {
774 yield* array;
775 }
776}
777
778function merge(arrays) {
779 return Array.from(flatten(arrays));
780}
781
782function minIndex(values, valueof) {
783 let min;
784 let minIndex = -1;
785 let index = -1;
786 if (valueof === undefined) {
787 for (const value of values) {
788 ++index;
789 if (value != null
790 && (min > value || (min === undefined && value >= value))) {
791 min = value, minIndex = index;
792 }
793 }
794 } else {
795 for (let value of values) {
796 if ((value = valueof(value, ++index, values)) != null
797 && (min > value || (min === undefined && value >= value))) {
798 min = value, minIndex = index;
799 }
800 }
801 }
802 return minIndex;
803}
804
805function pairs(values, pairof = pair) {
806 const pairs = [];
807 let previous;
808 let first = false;
809 for (const value of values) {
810 if (first) pairs.push(pairof(previous, value));
811 previous = value;
812 first = true;
813 }
814 return pairs;
815}
816
817function pair(a, b) {
818 return [a, b];
819}
820
821function sequence(start, stop, step) {
822 start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
823
824 var i = -1,
825 n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
826 range = new Array(n);
827
828 while (++i < n) {
829 range[i] = start + i * step;
830 }
831
832 return range;
833}
834
835function least(values, compare = ascending$3) {
836 let min;
837 let defined = false;
838 if (compare.length === 1) {
839 let minValue;
840 for (const element of values) {
841 const value = compare(element);
842 if (defined
843 ? ascending$3(value, minValue) < 0
844 : ascending$3(value, value) === 0) {
845 min = element;
846 minValue = value;
847 defined = true;
848 }
849 }
850 } else {
851 for (const value of values) {
852 if (defined
853 ? compare(value, min) < 0
854 : compare(value, value) === 0) {
855 min = value;
856 defined = true;
857 }
858 }
859 }
860 return min;
861}
862
863function leastIndex(values, compare = ascending$3) {
864 if (compare.length === 1) return minIndex(values, compare);
865 let minValue;
866 let min = -1;
867 let index = -1;
868 for (const value of values) {
869 ++index;
870 if (min < 0
871 ? compare(value, value) === 0
872 : compare(value, minValue) < 0) {
873 minValue = value;
874 min = index;
875 }
876 }
877 return min;
878}
879
880function greatest(values, compare = ascending$3) {
881 let max;
882 let defined = false;
883 if (compare.length === 1) {
884 let maxValue;
885 for (const element of values) {
886 const value = compare(element);
887 if (defined
888 ? ascending$3(value, maxValue) > 0
889 : ascending$3(value, value) === 0) {
890 max = element;
891 maxValue = value;
892 defined = true;
893 }
894 }
895 } else {
896 for (const value of values) {
897 if (defined
898 ? compare(value, max) > 0
899 : compare(value, value) === 0) {
900 max = value;
901 defined = true;
902 }
903 }
904 }
905 return max;
906}
907
908function greatestIndex(values, compare = ascending$3) {
909 if (compare.length === 1) return maxIndex(values, compare);
910 let maxValue;
911 let max = -1;
912 let index = -1;
913 for (const value of values) {
914 ++index;
915 if (max < 0
916 ? compare(value, value) === 0
917 : compare(value, maxValue) > 0) {
918 maxValue = value;
919 max = index;
920 }
921 }
922 return max;
923}
924
925function scan(values, compare) {
926 const index = leastIndex(values, compare);
927 return index < 0 ? undefined : index;
928}
929
930var shuffle$1 = shuffler(Math.random);
931
932function shuffler(random) {
933 return function shuffle(array, i0 = 0, i1 = array.length) {
934 let m = i1 - (i0 = +i0);
935 while (m) {
936 const i = random() * m-- | 0, t = array[m + i0];
937 array[m + i0] = array[i + i0];
938 array[i + i0] = t;
939 }
940 return array;
941 };
942}
943
944function sum$1(values, valueof) {
945 let sum = 0;
946 if (valueof === undefined) {
947 for (let value of values) {
948 if (value = +value) {
949 sum += value;
950 }
951 }
952 } else {
953 let index = -1;
954 for (let value of values) {
955 if (value = +valueof(value, ++index, values)) {
956 sum += value;
957 }
958 }
959 }
960 return sum;
961}
962
963function transpose(matrix) {
964 if (!(n = matrix.length)) return [];
965 for (var i = -1, m = min$2(matrix, length$2), transpose = new Array(m); ++i < m;) {
966 for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
967 row[j] = matrix[j][i];
968 }
969 }
970 return transpose;
971}
972
973function length$2(d) {
974 return d.length;
975}
976
977function zip() {
978 return transpose(arguments);
979}
980
981function every(values, test) {
982 if (typeof test !== "function") throw new TypeError("test is not a function");
983 let index = -1;
984 for (const value of values) {
985 if (!test(value, ++index, values)) {
986 return false;
987 }
988 }
989 return true;
990}
991
992function some(values, test) {
993 if (typeof test !== "function") throw new TypeError("test is not a function");
994 let index = -1;
995 for (const value of values) {
996 if (test(value, ++index, values)) {
997 return true;
998 }
999 }
1000 return false;
1001}
1002
1003function filter$1(values, test) {
1004 if (typeof test !== "function") throw new TypeError("test is not a function");
1005 const array = [];
1006 let index = -1;
1007 for (const value of values) {
1008 if (test(value, ++index, values)) {
1009 array.push(value);
1010 }
1011 }
1012 return array;
1013}
1014
1015function map$1(values, mapper) {
1016 if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
1017 if (typeof mapper !== "function") throw new TypeError("mapper is not a function");
1018 return Array.from(values, (value, index) => mapper(value, index, values));
1019}
1020
1021function reduce(values, reducer, value) {
1022 if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
1023 const iterator = values[Symbol.iterator]();
1024 let done, next, index = -1;
1025 if (arguments.length < 3) {
1026 ({done, value} = iterator.next());
1027 if (done) return;
1028 ++index;
1029 }
1030 while (({done, value: next} = iterator.next()), !done) {
1031 value = reducer(value, next, ++index, values);
1032 }
1033 return value;
1034}
1035
1036function reverse$1(values) {
1037 if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
1038 return Array.from(values).reverse();
1039}
1040
1041function difference(values, ...others) {
1042 values = new Set(values);
1043 for (const other of others) {
1044 for (const value of other) {
1045 values.delete(value);
1046 }
1047 }
1048 return values;
1049}
1050
1051function disjoint(values, other) {
1052 const iterator = other[Symbol.iterator](), set = new Set();
1053 for (const v of values) {
1054 if (set.has(v)) return false;
1055 let value, done;
1056 while (({value, done} = iterator.next())) {
1057 if (done) break;
1058 if (Object.is(v, value)) return false;
1059 set.add(value);
1060 }
1061 }
1062 return true;
1063}
1064
1065function set$2(values) {
1066 return values instanceof Set ? values : new Set(values);
1067}
1068
1069function intersection(values, ...others) {
1070 values = new Set(values);
1071 others = others.map(set$2);
1072 out: for (const value of values) {
1073 for (const other of others) {
1074 if (!other.has(value)) {
1075 values.delete(value);
1076 continue out;
1077 }
1078 }
1079 }
1080 return values;
1081}
1082
1083function superset(values, other) {
1084 const iterator = values[Symbol.iterator](), set = new Set();
1085 for (const o of other) {
1086 if (set.has(o)) continue;
1087 let value, done;
1088 while (({value, done} = iterator.next())) {
1089 if (done) return false;
1090 set.add(value);
1091 if (Object.is(o, value)) break;
1092 }
1093 }
1094 return true;
1095}
1096
1097function subset(values, other) {
1098 return superset(other, values);
1099}
1100
1101function union(...others) {
1102 const set = new Set();
1103 for (const other of others) {
1104 for (const o of other) {
1105 set.add(o);
1106 }
1107 }
1108 return set;
1109}
1110
1111var slice$3 = Array.prototype.slice;
1112
1113function identity$8(x) {
1114 return x;
1115}
1116
1117var top = 1,
1118 right = 2,
1119 bottom = 3,
1120 left = 4,
1121 epsilon$5 = 1e-6;
1122
1123function translateX(x) {
1124 return "translate(" + x + ",0)";
1125}
1126
1127function translateY(y) {
1128 return "translate(0," + y + ")";
1129}
1130
1131function number$2(scale) {
1132 return d => +scale(d);
1133}
1134
1135function center$1(scale, offset) {
1136 offset = Math.max(0, scale.bandwidth() - offset * 2) / 2;
1137 if (scale.round()) offset = Math.round(offset);
1138 return d => +scale(d) + offset;
1139}
1140
1141function entering() {
1142 return !this.__axis;
1143}
1144
1145function axis(orient, scale) {
1146 var tickArguments = [],
1147 tickValues = null,
1148 tickFormat = null,
1149 tickSizeInner = 6,
1150 tickSizeOuter = 6,
1151 tickPadding = 3,
1152 offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5,
1153 k = orient === top || orient === left ? -1 : 1,
1154 x = orient === left || orient === right ? "x" : "y",
1155 transform = orient === top || orient === bottom ? translateX : translateY;
1156
1157 function axis(context) {
1158 var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
1159 format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$8) : tickFormat,
1160 spacing = Math.max(tickSizeInner, 0) + tickPadding,
1161 range = scale.range(),
1162 range0 = +range[0] + offset,
1163 range1 = +range[range.length - 1] + offset,
1164 position = (scale.bandwidth ? center$1 : number$2)(scale.copy(), offset),
1165 selection = context.selection ? context.selection() : context,
1166 path = selection.selectAll(".domain").data([null]),
1167 tick = selection.selectAll(".tick").data(values, scale).order(),
1168 tickExit = tick.exit(),
1169 tickEnter = tick.enter().append("g").attr("class", "tick"),
1170 line = tick.select("line"),
1171 text = tick.select("text");
1172
1173 path = path.merge(path.enter().insert("path", ".tick")
1174 .attr("class", "domain")
1175 .attr("stroke", "currentColor"));
1176
1177 tick = tick.merge(tickEnter);
1178
1179 line = line.merge(tickEnter.append("line")
1180 .attr("stroke", "currentColor")
1181 .attr(x + "2", k * tickSizeInner));
1182
1183 text = text.merge(tickEnter.append("text")
1184 .attr("fill", "currentColor")
1185 .attr(x, k * spacing)
1186 .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
1187
1188 if (context !== selection) {
1189 path = path.transition(context);
1190 tick = tick.transition(context);
1191 line = line.transition(context);
1192 text = text.transition(context);
1193
1194 tickExit = tickExit.transition(context)
1195 .attr("opacity", epsilon$5)
1196 .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform"); });
1197
1198 tickEnter
1199 .attr("opacity", epsilon$5)
1200 .attr("transform", function(d) { var p = this.parentNode.__axis; return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset); });
1201 }
1202
1203 tickExit.remove();
1204
1205 path
1206 .attr("d", orient === left || orient === right
1207 ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1)
1208 : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1));
1209
1210 tick
1211 .attr("opacity", 1)
1212 .attr("transform", function(d) { return transform(position(d) + offset); });
1213
1214 line
1215 .attr(x + "2", k * tickSizeInner);
1216
1217 text
1218 .attr(x, k * spacing)
1219 .text(format);
1220
1221 selection.filter(entering)
1222 .attr("fill", "none")
1223 .attr("font-size", 10)
1224 .attr("font-family", "sans-serif")
1225 .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
1226
1227 selection
1228 .each(function() { this.__axis = position; });
1229 }
1230
1231 axis.scale = function(_) {
1232 return arguments.length ? (scale = _, axis) : scale;
1233 };
1234
1235 axis.ticks = function() {
1236 return tickArguments = slice$3.call(arguments), axis;
1237 };
1238
1239 axis.tickArguments = function(_) {
1240 return arguments.length ? (tickArguments = _ == null ? [] : slice$3.call(_), axis) : tickArguments.slice();
1241 };
1242
1243 axis.tickValues = function(_) {
1244 return arguments.length ? (tickValues = _ == null ? null : slice$3.call(_), axis) : tickValues && tickValues.slice();
1245 };
1246
1247 axis.tickFormat = function(_) {
1248 return arguments.length ? (tickFormat = _, axis) : tickFormat;
1249 };
1250
1251 axis.tickSize = function(_) {
1252 return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
1253 };
1254
1255 axis.tickSizeInner = function(_) {
1256 return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
1257 };
1258
1259 axis.tickSizeOuter = function(_) {
1260 return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
1261 };
1262
1263 axis.tickPadding = function(_) {
1264 return arguments.length ? (tickPadding = +_, axis) : tickPadding;
1265 };
1266
1267 axis.offset = function(_) {
1268 return arguments.length ? (offset = +_, axis) : offset;
1269 };
1270
1271 return axis;
1272}
1273
1274function axisTop(scale) {
1275 return axis(top, scale);
1276}
1277
1278function axisRight(scale) {
1279 return axis(right, scale);
1280}
1281
1282function axisBottom(scale) {
1283 return axis(bottom, scale);
1284}
1285
1286function axisLeft(scale) {
1287 return axis(left, scale);
1288}
1289
1290var noop$3 = {value: () => {}};
1291
1292function dispatch() {
1293 for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
1294 if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
1295 _[t] = [];
1296 }
1297 return new Dispatch(_);
1298}
1299
1300function Dispatch(_) {
1301 this._ = _;
1302}
1303
1304function parseTypenames$1(typenames, types) {
1305 return typenames.trim().split(/^|\s+/).map(function(t) {
1306 var name = "", i = t.indexOf(".");
1307 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
1308 if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
1309 return {type: t, name: name};
1310 });
1311}
1312
1313Dispatch.prototype = dispatch.prototype = {
1314 constructor: Dispatch,
1315 on: function(typename, callback) {
1316 var _ = this._,
1317 T = parseTypenames$1(typename + "", _),
1318 t,
1319 i = -1,
1320 n = T.length;
1321
1322 // If no callback was specified, return the callback of the given type and name.
1323 if (arguments.length < 2) {
1324 while (++i < n) if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t;
1325 return;
1326 }
1327
1328 // If a type was specified, set the callback for the given type and name.
1329 // Otherwise, if a null callback was specified, remove callbacks of the given name.
1330 if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
1331 while (++i < n) {
1332 if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
1333 else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
1334 }
1335
1336 return this;
1337 },
1338 copy: function() {
1339 var copy = {}, _ = this._;
1340 for (var t in _) copy[t] = _[t].slice();
1341 return new Dispatch(copy);
1342 },
1343 call: function(type, that) {
1344 if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
1345 if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
1346 for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
1347 },
1348 apply: function(type, that, args) {
1349 if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
1350 for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
1351 }
1352};
1353
1354function get$1(type, name) {
1355 for (var i = 0, n = type.length, c; i < n; ++i) {
1356 if ((c = type[i]).name === name) {
1357 return c.value;
1358 }
1359 }
1360}
1361
1362function set$1(type, name, callback) {
1363 for (var i = 0, n = type.length; i < n; ++i) {
1364 if (type[i].name === name) {
1365 type[i] = noop$3, type = type.slice(0, i).concat(type.slice(i + 1));
1366 break;
1367 }
1368 }
1369 if (callback != null) type.push({name: name, value: callback});
1370 return type;
1371}
1372
1373var xhtml = "http://www.w3.org/1999/xhtml";
1374
1375var namespaces = {
1376 svg: "http://www.w3.org/2000/svg",
1377 xhtml: xhtml,
1378 xlink: "http://www.w3.org/1999/xlink",
1379 xml: "http://www.w3.org/XML/1998/namespace",
1380 xmlns: "http://www.w3.org/2000/xmlns/"
1381};
1382
1383function namespace(name) {
1384 var prefix = name += "", i = prefix.indexOf(":");
1385 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
1386 return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins
1387}
1388
1389function creatorInherit(name) {
1390 return function() {
1391 var document = this.ownerDocument,
1392 uri = this.namespaceURI;
1393 return uri === xhtml && document.documentElement.namespaceURI === xhtml
1394 ? document.createElement(name)
1395 : document.createElementNS(uri, name);
1396 };
1397}
1398
1399function creatorFixed(fullname) {
1400 return function() {
1401 return this.ownerDocument.createElementNS(fullname.space, fullname.local);
1402 };
1403}
1404
1405function creator(name) {
1406 var fullname = namespace(name);
1407 return (fullname.local
1408 ? creatorFixed
1409 : creatorInherit)(fullname);
1410}
1411
1412function none$2() {}
1413
1414function selector(selector) {
1415 return selector == null ? none$2 : function() {
1416 return this.querySelector(selector);
1417 };
1418}
1419
1420function selection_select(select) {
1421 if (typeof select !== "function") select = selector(select);
1422
1423 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
1424 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
1425 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
1426 if ("__data__" in node) subnode.__data__ = node.__data__;
1427 subgroup[i] = subnode;
1428 }
1429 }
1430 }
1431
1432 return new Selection$1(subgroups, this._parents);
1433}
1434
1435function array$4(x) {
1436 return typeof x === "object" && "length" in x
1437 ? x // Array, TypedArray, NodeList, array-like
1438 : Array.from(x); // Map, Set, iterable, string, or anything else
1439}
1440
1441function empty$1() {
1442 return [];
1443}
1444
1445function selectorAll(selector) {
1446 return selector == null ? empty$1 : function() {
1447 return this.querySelectorAll(selector);
1448 };
1449}
1450
1451function arrayAll(select) {
1452 return function() {
1453 var group = select.apply(this, arguments);
1454 return group == null ? [] : array$4(group);
1455 };
1456}
1457
1458function selection_selectAll(select) {
1459 if (typeof select === "function") select = arrayAll(select);
1460 else select = selectorAll(select);
1461
1462 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
1463 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
1464 if (node = group[i]) {
1465 subgroups.push(select.call(node, node.__data__, i, group));
1466 parents.push(node);
1467 }
1468 }
1469 }
1470
1471 return new Selection$1(subgroups, parents);
1472}
1473
1474function matcher(selector) {
1475 return function() {
1476 return this.matches(selector);
1477 };
1478}
1479
1480function childMatcher(selector) {
1481 return function(node) {
1482 return node.matches(selector);
1483 };
1484}
1485
1486var find$1 = Array.prototype.find;
1487
1488function childFind(match) {
1489 return function() {
1490 return find$1.call(this.children, match);
1491 };
1492}
1493
1494function childFirst() {
1495 return this.firstElementChild;
1496}
1497
1498function selection_selectChild(match) {
1499 return this.select(match == null ? childFirst
1500 : childFind(typeof match === "function" ? match : childMatcher(match)));
1501}
1502
1503var filter = Array.prototype.filter;
1504
1505function children() {
1506 return this.children;
1507}
1508
1509function childrenFilter(match) {
1510 return function() {
1511 return filter.call(this.children, match);
1512 };
1513}
1514
1515function selection_selectChildren(match) {
1516 return this.selectAll(match == null ? children
1517 : childrenFilter(typeof match === "function" ? match : childMatcher(match)));
1518}
1519
1520function selection_filter(match) {
1521 if (typeof match !== "function") match = matcher(match);
1522
1523 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
1524 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
1525 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
1526 subgroup.push(node);
1527 }
1528 }
1529 }
1530
1531 return new Selection$1(subgroups, this._parents);
1532}
1533
1534function sparse(update) {
1535 return new Array(update.length);
1536}
1537
1538function selection_enter() {
1539 return new Selection$1(this._enter || this._groups.map(sparse), this._parents);
1540}
1541
1542function EnterNode(parent, datum) {
1543 this.ownerDocument = parent.ownerDocument;
1544 this.namespaceURI = parent.namespaceURI;
1545 this._next = null;
1546 this._parent = parent;
1547 this.__data__ = datum;
1548}
1549
1550EnterNode.prototype = {
1551 constructor: EnterNode,
1552 appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
1553 insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
1554 querySelector: function(selector) { return this._parent.querySelector(selector); },
1555 querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
1556};
1557
1558function constant$a(x) {
1559 return function() {
1560 return x;
1561 };
1562}
1563
1564function bindIndex(parent, group, enter, update, exit, data) {
1565 var i = 0,
1566 node,
1567 groupLength = group.length,
1568 dataLength = data.length;
1569
1570 // Put any non-null nodes that fit into update.
1571 // Put any null nodes into enter.
1572 // Put any remaining data into enter.
1573 for (; i < dataLength; ++i) {
1574 if (node = group[i]) {
1575 node.__data__ = data[i];
1576 update[i] = node;
1577 } else {
1578 enter[i] = new EnterNode(parent, data[i]);
1579 }
1580 }
1581
1582 // Put any non-null nodes that don’t fit into exit.
1583 for (; i < groupLength; ++i) {
1584 if (node = group[i]) {
1585 exit[i] = node;
1586 }
1587 }
1588}
1589
1590function bindKey(parent, group, enter, update, exit, data, key) {
1591 var i,
1592 node,
1593 nodeByKeyValue = new Map,
1594 groupLength = group.length,
1595 dataLength = data.length,
1596 keyValues = new Array(groupLength),
1597 keyValue;
1598
1599 // Compute the key for each node.
1600 // If multiple nodes have the same key, the duplicates are added to exit.
1601 for (i = 0; i < groupLength; ++i) {
1602 if (node = group[i]) {
1603 keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
1604 if (nodeByKeyValue.has(keyValue)) {
1605 exit[i] = node;
1606 } else {
1607 nodeByKeyValue.set(keyValue, node);
1608 }
1609 }
1610 }
1611
1612 // Compute the key for each datum.
1613 // If there a node associated with this key, join and add it to update.
1614 // If there is not (or the key is a duplicate), add it to enter.
1615 for (i = 0; i < dataLength; ++i) {
1616 keyValue = key.call(parent, data[i], i, data) + "";
1617 if (node = nodeByKeyValue.get(keyValue)) {
1618 update[i] = node;
1619 node.__data__ = data[i];
1620 nodeByKeyValue.delete(keyValue);
1621 } else {
1622 enter[i] = new EnterNode(parent, data[i]);
1623 }
1624 }
1625
1626 // Add any remaining nodes that were not bound to data to exit.
1627 for (i = 0; i < groupLength; ++i) {
1628 if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) {
1629 exit[i] = node;
1630 }
1631 }
1632}
1633
1634function datum(node) {
1635 return node.__data__;
1636}
1637
1638function selection_data(value, key) {
1639 if (!arguments.length) return Array.from(this, datum);
1640
1641 var bind = key ? bindKey : bindIndex,
1642 parents = this._parents,
1643 groups = this._groups;
1644
1645 if (typeof value !== "function") value = constant$a(value);
1646
1647 for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
1648 var parent = parents[j],
1649 group = groups[j],
1650 groupLength = group.length,
1651 data = array$4(value.call(parent, parent && parent.__data__, j, parents)),
1652 dataLength = data.length,
1653 enterGroup = enter[j] = new Array(dataLength),
1654 updateGroup = update[j] = new Array(dataLength),
1655 exitGroup = exit[j] = new Array(groupLength);
1656
1657 bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
1658
1659 // Now connect the enter nodes to their following update node, such that
1660 // appendChild can insert the materialized enter node before this node,
1661 // rather than at the end of the parent node.
1662 for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
1663 if (previous = enterGroup[i0]) {
1664 if (i0 >= i1) i1 = i0 + 1;
1665 while (!(next = updateGroup[i1]) && ++i1 < dataLength);
1666 previous._next = next || null;
1667 }
1668 }
1669 }
1670
1671 update = new Selection$1(update, parents);
1672 update._enter = enter;
1673 update._exit = exit;
1674 return update;
1675}
1676
1677function selection_exit() {
1678 return new Selection$1(this._exit || this._groups.map(sparse), this._parents);
1679}
1680
1681function selection_join(onenter, onupdate, onexit) {
1682 var enter = this.enter(), update = this, exit = this.exit();
1683 enter = typeof onenter === "function" ? onenter(enter) : enter.append(onenter + "");
1684 if (onupdate != null) update = onupdate(update);
1685 if (onexit == null) exit.remove(); else onexit(exit);
1686 return enter && update ? enter.merge(update).order() : update;
1687}
1688
1689function selection_merge(selection) {
1690 if (!(selection instanceof Selection$1)) throw new Error("invalid merge");
1691
1692 for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
1693 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
1694 if (node = group0[i] || group1[i]) {
1695 merge[i] = node;
1696 }
1697 }
1698 }
1699
1700 for (; j < m0; ++j) {
1701 merges[j] = groups0[j];
1702 }
1703
1704 return new Selection$1(merges, this._parents);
1705}
1706
1707function selection_order() {
1708
1709 for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
1710 for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
1711 if (node = group[i]) {
1712 if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
1713 next = node;
1714 }
1715 }
1716 }
1717
1718 return this;
1719}
1720
1721function selection_sort(compare) {
1722 if (!compare) compare = ascending$2;
1723
1724 function compareNode(a, b) {
1725 return a && b ? compare(a.__data__, b.__data__) : !a - !b;
1726 }
1727
1728 for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
1729 for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
1730 if (node = group[i]) {
1731 sortgroup[i] = node;
1732 }
1733 }
1734 sortgroup.sort(compareNode);
1735 }
1736
1737 return new Selection$1(sortgroups, this._parents).order();
1738}
1739
1740function ascending$2(a, b) {
1741 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
1742}
1743
1744function selection_call() {
1745 var callback = arguments[0];
1746 arguments[0] = this;
1747 callback.apply(null, arguments);
1748 return this;
1749}
1750
1751function selection_nodes() {
1752 return Array.from(this);
1753}
1754
1755function selection_node() {
1756
1757 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1758 for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
1759 var node = group[i];
1760 if (node) return node;
1761 }
1762 }
1763
1764 return null;
1765}
1766
1767function selection_size() {
1768 let size = 0;
1769 for (const node of this) ++size; // eslint-disable-line no-unused-vars
1770 return size;
1771}
1772
1773function selection_empty() {
1774 return !this.node();
1775}
1776
1777function selection_each(callback) {
1778
1779 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1780 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
1781 if (node = group[i]) callback.call(node, node.__data__, i, group);
1782 }
1783 }
1784
1785 return this;
1786}
1787
1788function attrRemove$1(name) {
1789 return function() {
1790 this.removeAttribute(name);
1791 };
1792}
1793
1794function attrRemoveNS$1(fullname) {
1795 return function() {
1796 this.removeAttributeNS(fullname.space, fullname.local);
1797 };
1798}
1799
1800function attrConstant$1(name, value) {
1801 return function() {
1802 this.setAttribute(name, value);
1803 };
1804}
1805
1806function attrConstantNS$1(fullname, value) {
1807 return function() {
1808 this.setAttributeNS(fullname.space, fullname.local, value);
1809 };
1810}
1811
1812function attrFunction$1(name, value) {
1813 return function() {
1814 var v = value.apply(this, arguments);
1815 if (v == null) this.removeAttribute(name);
1816 else this.setAttribute(name, v);
1817 };
1818}
1819
1820function attrFunctionNS$1(fullname, value) {
1821 return function() {
1822 var v = value.apply(this, arguments);
1823 if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
1824 else this.setAttributeNS(fullname.space, fullname.local, v);
1825 };
1826}
1827
1828function selection_attr(name, value) {
1829 var fullname = namespace(name);
1830
1831 if (arguments.length < 2) {
1832 var node = this.node();
1833 return fullname.local
1834 ? node.getAttributeNS(fullname.space, fullname.local)
1835 : node.getAttribute(fullname);
1836 }
1837
1838 return this.each((value == null
1839 ? (fullname.local ? attrRemoveNS$1 : attrRemove$1) : (typeof value === "function"
1840 ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)
1841 : (fullname.local ? attrConstantNS$1 : attrConstant$1)))(fullname, value));
1842}
1843
1844function defaultView(node) {
1845 return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
1846 || (node.document && node) // node is a Window
1847 || node.defaultView; // node is a Document
1848}
1849
1850function styleRemove$1(name) {
1851 return function() {
1852 this.style.removeProperty(name);
1853 };
1854}
1855
1856function styleConstant$1(name, value, priority) {
1857 return function() {
1858 this.style.setProperty(name, value, priority);
1859 };
1860}
1861
1862function styleFunction$1(name, value, priority) {
1863 return function() {
1864 var v = value.apply(this, arguments);
1865 if (v == null) this.style.removeProperty(name);
1866 else this.style.setProperty(name, v, priority);
1867 };
1868}
1869
1870function selection_style(name, value, priority) {
1871 return arguments.length > 1
1872 ? this.each((value == null
1873 ? styleRemove$1 : typeof value === "function"
1874 ? styleFunction$1
1875 : styleConstant$1)(name, value, priority == null ? "" : priority))
1876 : styleValue(this.node(), name);
1877}
1878
1879function styleValue(node, name) {
1880 return node.style.getPropertyValue(name)
1881 || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
1882}
1883
1884function propertyRemove(name) {
1885 return function() {
1886 delete this[name];
1887 };
1888}
1889
1890function propertyConstant(name, value) {
1891 return function() {
1892 this[name] = value;
1893 };
1894}
1895
1896function propertyFunction(name, value) {
1897 return function() {
1898 var v = value.apply(this, arguments);
1899 if (v == null) delete this[name];
1900 else this[name] = v;
1901 };
1902}
1903
1904function selection_property(name, value) {
1905 return arguments.length > 1
1906 ? this.each((value == null
1907 ? propertyRemove : typeof value === "function"
1908 ? propertyFunction
1909 : propertyConstant)(name, value))
1910 : this.node()[name];
1911}
1912
1913function classArray(string) {
1914 return string.trim().split(/^|\s+/);
1915}
1916
1917function classList(node) {
1918 return node.classList || new ClassList(node);
1919}
1920
1921function ClassList(node) {
1922 this._node = node;
1923 this._names = classArray(node.getAttribute("class") || "");
1924}
1925
1926ClassList.prototype = {
1927 add: function(name) {
1928 var i = this._names.indexOf(name);
1929 if (i < 0) {
1930 this._names.push(name);
1931 this._node.setAttribute("class", this._names.join(" "));
1932 }
1933 },
1934 remove: function(name) {
1935 var i = this._names.indexOf(name);
1936 if (i >= 0) {
1937 this._names.splice(i, 1);
1938 this._node.setAttribute("class", this._names.join(" "));
1939 }
1940 },
1941 contains: function(name) {
1942 return this._names.indexOf(name) >= 0;
1943 }
1944};
1945
1946function classedAdd(node, names) {
1947 var list = classList(node), i = -1, n = names.length;
1948 while (++i < n) list.add(names[i]);
1949}
1950
1951function classedRemove(node, names) {
1952 var list = classList(node), i = -1, n = names.length;
1953 while (++i < n) list.remove(names[i]);
1954}
1955
1956function classedTrue(names) {
1957 return function() {
1958 classedAdd(this, names);
1959 };
1960}
1961
1962function classedFalse(names) {
1963 return function() {
1964 classedRemove(this, names);
1965 };
1966}
1967
1968function classedFunction(names, value) {
1969 return function() {
1970 (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
1971 };
1972}
1973
1974function selection_classed(name, value) {
1975 var names = classArray(name + "");
1976
1977 if (arguments.length < 2) {
1978 var list = classList(this.node()), i = -1, n = names.length;
1979 while (++i < n) if (!list.contains(names[i])) return false;
1980 return true;
1981 }
1982
1983 return this.each((typeof value === "function"
1984 ? classedFunction : value
1985 ? classedTrue
1986 : classedFalse)(names, value));
1987}
1988
1989function textRemove() {
1990 this.textContent = "";
1991}
1992
1993function textConstant$1(value) {
1994 return function() {
1995 this.textContent = value;
1996 };
1997}
1998
1999function textFunction$1(value) {
2000 return function() {
2001 var v = value.apply(this, arguments);
2002 this.textContent = v == null ? "" : v;
2003 };
2004}
2005
2006function selection_text(value) {
2007 return arguments.length
2008 ? this.each(value == null
2009 ? textRemove : (typeof value === "function"
2010 ? textFunction$1
2011 : textConstant$1)(value))
2012 : this.node().textContent;
2013}
2014
2015function htmlRemove() {
2016 this.innerHTML = "";
2017}
2018
2019function htmlConstant(value) {
2020 return function() {
2021 this.innerHTML = value;
2022 };
2023}
2024
2025function htmlFunction(value) {
2026 return function() {
2027 var v = value.apply(this, arguments);
2028 this.innerHTML = v == null ? "" : v;
2029 };
2030}
2031
2032function selection_html(value) {
2033 return arguments.length
2034 ? this.each(value == null
2035 ? htmlRemove : (typeof value === "function"
2036 ? htmlFunction
2037 : htmlConstant)(value))
2038 : this.node().innerHTML;
2039}
2040
2041function raise() {
2042 if (this.nextSibling) this.parentNode.appendChild(this);
2043}
2044
2045function selection_raise() {
2046 return this.each(raise);
2047}
2048
2049function lower() {
2050 if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
2051}
2052
2053function selection_lower() {
2054 return this.each(lower);
2055}
2056
2057function selection_append(name) {
2058 var create = typeof name === "function" ? name : creator(name);
2059 return this.select(function() {
2060 return this.appendChild(create.apply(this, arguments));
2061 });
2062}
2063
2064function constantNull() {
2065 return null;
2066}
2067
2068function selection_insert(name, before) {
2069 var create = typeof name === "function" ? name : creator(name),
2070 select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
2071 return this.select(function() {
2072 return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
2073 });
2074}
2075
2076function remove() {
2077 var parent = this.parentNode;
2078 if (parent) parent.removeChild(this);
2079}
2080
2081function selection_remove() {
2082 return this.each(remove);
2083}
2084
2085function selection_cloneShallow() {
2086 var clone = this.cloneNode(false), parent = this.parentNode;
2087 return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
2088}
2089
2090function selection_cloneDeep() {
2091 var clone = this.cloneNode(true), parent = this.parentNode;
2092 return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
2093}
2094
2095function selection_clone(deep) {
2096 return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
2097}
2098
2099function selection_datum(value) {
2100 return arguments.length
2101 ? this.property("__data__", value)
2102 : this.node().__data__;
2103}
2104
2105function contextListener(listener) {
2106 return function(event) {
2107 listener.call(this, event, this.__data__);
2108 };
2109}
2110
2111function parseTypenames(typenames) {
2112 return typenames.trim().split(/^|\s+/).map(function(t) {
2113 var name = "", i = t.indexOf(".");
2114 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
2115 return {type: t, name: name};
2116 });
2117}
2118
2119function onRemove(typename) {
2120 return function() {
2121 var on = this.__on;
2122 if (!on) return;
2123 for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
2124 if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
2125 this.removeEventListener(o.type, o.listener, o.options);
2126 } else {
2127 on[++i] = o;
2128 }
2129 }
2130 if (++i) on.length = i;
2131 else delete this.__on;
2132 };
2133}
2134
2135function onAdd(typename, value, options) {
2136 return function() {
2137 var on = this.__on, o, listener = contextListener(value);
2138 if (on) for (var j = 0, m = on.length; j < m; ++j) {
2139 if ((o = on[j]).type === typename.type && o.name === typename.name) {
2140 this.removeEventListener(o.type, o.listener, o.options);
2141 this.addEventListener(o.type, o.listener = listener, o.options = options);
2142 o.value = value;
2143 return;
2144 }
2145 }
2146 this.addEventListener(typename.type, listener, options);
2147 o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options};
2148 if (!on) this.__on = [o];
2149 else on.push(o);
2150 };
2151}
2152
2153function selection_on(typename, value, options) {
2154 var typenames = parseTypenames(typename + ""), i, n = typenames.length, t;
2155
2156 if (arguments.length < 2) {
2157 var on = this.node().__on;
2158 if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
2159 for (i = 0, o = on[j]; i < n; ++i) {
2160 if ((t = typenames[i]).type === o.type && t.name === o.name) {
2161 return o.value;
2162 }
2163 }
2164 }
2165 return;
2166 }
2167
2168 on = value ? onAdd : onRemove;
2169 for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options));
2170 return this;
2171}
2172
2173function dispatchEvent(node, type, params) {
2174 var window = defaultView(node),
2175 event = window.CustomEvent;
2176
2177 if (typeof event === "function") {
2178 event = new event(type, params);
2179 } else {
2180 event = window.document.createEvent("Event");
2181 if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
2182 else event.initEvent(type, false, false);
2183 }
2184
2185 node.dispatchEvent(event);
2186}
2187
2188function dispatchConstant(type, params) {
2189 return function() {
2190 return dispatchEvent(this, type, params);
2191 };
2192}
2193
2194function dispatchFunction(type, params) {
2195 return function() {
2196 return dispatchEvent(this, type, params.apply(this, arguments));
2197 };
2198}
2199
2200function selection_dispatch(type, params) {
2201 return this.each((typeof params === "function"
2202 ? dispatchFunction
2203 : dispatchConstant)(type, params));
2204}
2205
2206function* selection_iterator() {
2207 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
2208 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
2209 if (node = group[i]) yield node;
2210 }
2211 }
2212}
2213
2214var root$1 = [null];
2215
2216function Selection$1(groups, parents) {
2217 this._groups = groups;
2218 this._parents = parents;
2219}
2220
2221function selection() {
2222 return new Selection$1([[document.documentElement]], root$1);
2223}
2224
2225function selection_selection() {
2226 return this;
2227}
2228
2229Selection$1.prototype = selection.prototype = {
2230 constructor: Selection$1,
2231 select: selection_select,
2232 selectAll: selection_selectAll,
2233 selectChild: selection_selectChild,
2234 selectChildren: selection_selectChildren,
2235 filter: selection_filter,
2236 data: selection_data,
2237 enter: selection_enter,
2238 exit: selection_exit,
2239 join: selection_join,
2240 merge: selection_merge,
2241 selection: selection_selection,
2242 order: selection_order,
2243 sort: selection_sort,
2244 call: selection_call,
2245 nodes: selection_nodes,
2246 node: selection_node,
2247 size: selection_size,
2248 empty: selection_empty,
2249 each: selection_each,
2250 attr: selection_attr,
2251 style: selection_style,
2252 property: selection_property,
2253 classed: selection_classed,
2254 text: selection_text,
2255 html: selection_html,
2256 raise: selection_raise,
2257 lower: selection_lower,
2258 append: selection_append,
2259 insert: selection_insert,
2260 remove: selection_remove,
2261 clone: selection_clone,
2262 datum: selection_datum,
2263 on: selection_on,
2264 dispatch: selection_dispatch,
2265 [Symbol.iterator]: selection_iterator
2266};
2267
2268function select(selector) {
2269 return typeof selector === "string"
2270 ? new Selection$1([[document.querySelector(selector)]], [document.documentElement])
2271 : new Selection$1([[selector]], root$1);
2272}
2273
2274function create$1(name) {
2275 return select(creator(name).call(document.documentElement));
2276}
2277
2278var nextId = 0;
2279
2280function local$1() {
2281 return new Local;
2282}
2283
2284function Local() {
2285 this._ = "@" + (++nextId).toString(36);
2286}
2287
2288Local.prototype = local$1.prototype = {
2289 constructor: Local,
2290 get: function(node) {
2291 var id = this._;
2292 while (!(id in node)) if (!(node = node.parentNode)) return;
2293 return node[id];
2294 },
2295 set: function(node, value) {
2296 return node[this._] = value;
2297 },
2298 remove: function(node) {
2299 return this._ in node && delete node[this._];
2300 },
2301 toString: function() {
2302 return this._;
2303 }
2304};
2305
2306function sourceEvent(event) {
2307 let sourceEvent;
2308 while (sourceEvent = event.sourceEvent) event = sourceEvent;
2309 return event;
2310}
2311
2312function pointer(event, node) {
2313 event = sourceEvent(event);
2314 if (node === undefined) node = event.currentTarget;
2315 if (node) {
2316 var svg = node.ownerSVGElement || node;
2317 if (svg.createSVGPoint) {
2318 var point = svg.createSVGPoint();
2319 point.x = event.clientX, point.y = event.clientY;
2320 point = point.matrixTransform(node.getScreenCTM().inverse());
2321 return [point.x, point.y];
2322 }
2323 if (node.getBoundingClientRect) {
2324 var rect = node.getBoundingClientRect();
2325 return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
2326 }
2327 }
2328 return [event.pageX, event.pageY];
2329}
2330
2331function pointers(events, node) {
2332 if (events.target) { // i.e., instanceof Event, not TouchList or iterable
2333 events = sourceEvent(events);
2334 if (node === undefined) node = events.currentTarget;
2335 events = events.touches || [events];
2336 }
2337 return Array.from(events, event => pointer(event, node));
2338}
2339
2340function selectAll(selector) {
2341 return typeof selector === "string"
2342 ? new Selection$1([document.querySelectorAll(selector)], [document.documentElement])
2343 : new Selection$1([selector == null ? [] : array$4(selector)], root$1);
2344}
2345
2346function nopropagation$2(event) {
2347 event.stopImmediatePropagation();
2348}
2349
2350function noevent$2(event) {
2351 event.preventDefault();
2352 event.stopImmediatePropagation();
2353}
2354
2355function dragDisable(view) {
2356 var root = view.document.documentElement,
2357 selection = select(view).on("dragstart.drag", noevent$2, true);
2358 if ("onselectstart" in root) {
2359 selection.on("selectstart.drag", noevent$2, true);
2360 } else {
2361 root.__noselect = root.style.MozUserSelect;
2362 root.style.MozUserSelect = "none";
2363 }
2364}
2365
2366function yesdrag(view, noclick) {
2367 var root = view.document.documentElement,
2368 selection = select(view).on("dragstart.drag", null);
2369 if (noclick) {
2370 selection.on("click.drag", noevent$2, true);
2371 setTimeout(function() { selection.on("click.drag", null); }, 0);
2372 }
2373 if ("onselectstart" in root) {
2374 selection.on("selectstart.drag", null);
2375 } else {
2376 root.style.MozUserSelect = root.__noselect;
2377 delete root.__noselect;
2378 }
2379}
2380
2381var constant$9 = x => () => x;
2382
2383function DragEvent(type, {
2384 sourceEvent,
2385 subject,
2386 target,
2387 identifier,
2388 active,
2389 x, y, dx, dy,
2390 dispatch
2391}) {
2392 Object.defineProperties(this, {
2393 type: {value: type, enumerable: true, configurable: true},
2394 sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
2395 subject: {value: subject, enumerable: true, configurable: true},
2396 target: {value: target, enumerable: true, configurable: true},
2397 identifier: {value: identifier, enumerable: true, configurable: true},
2398 active: {value: active, enumerable: true, configurable: true},
2399 x: {value: x, enumerable: true, configurable: true},
2400 y: {value: y, enumerable: true, configurable: true},
2401 dx: {value: dx, enumerable: true, configurable: true},
2402 dy: {value: dy, enumerable: true, configurable: true},
2403 _: {value: dispatch}
2404 });
2405}
2406
2407DragEvent.prototype.on = function() {
2408 var value = this._.on.apply(this._, arguments);
2409 return value === this._ ? this : value;
2410};
2411
2412// Ignore right-click, since that should open the context menu.
2413function defaultFilter$2(event) {
2414 return !event.ctrlKey && !event.button;
2415}
2416
2417function defaultContainer() {
2418 return this.parentNode;
2419}
2420
2421function defaultSubject(event, d) {
2422 return d == null ? {x: event.x, y: event.y} : d;
2423}
2424
2425function defaultTouchable$2() {
2426 return navigator.maxTouchPoints || ("ontouchstart" in this);
2427}
2428
2429function drag() {
2430 var filter = defaultFilter$2,
2431 container = defaultContainer,
2432 subject = defaultSubject,
2433 touchable = defaultTouchable$2,
2434 gestures = {},
2435 listeners = dispatch("start", "drag", "end"),
2436 active = 0,
2437 mousedownx,
2438 mousedowny,
2439 mousemoving,
2440 touchending,
2441 clickDistance2 = 0;
2442
2443 function drag(selection) {
2444 selection
2445 .on("mousedown.drag", mousedowned)
2446 .filter(touchable)
2447 .on("touchstart.drag", touchstarted)
2448 .on("touchmove.drag", touchmoved)
2449 .on("touchend.drag touchcancel.drag", touchended)
2450 .style("touch-action", "none")
2451 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
2452 }
2453
2454 function mousedowned(event, d) {
2455 if (touchending || !filter.call(this, event, d)) return;
2456 var gesture = beforestart(this, container.call(this, event, d), event, d, "mouse");
2457 if (!gesture) return;
2458 select(event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
2459 dragDisable(event.view);
2460 nopropagation$2(event);
2461 mousemoving = false;
2462 mousedownx = event.clientX;
2463 mousedowny = event.clientY;
2464 gesture("start", event);
2465 }
2466
2467 function mousemoved(event) {
2468 noevent$2(event);
2469 if (!mousemoving) {
2470 var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
2471 mousemoving = dx * dx + dy * dy > clickDistance2;
2472 }
2473 gestures.mouse("drag", event);
2474 }
2475
2476 function mouseupped(event) {
2477 select(event.view).on("mousemove.drag mouseup.drag", null);
2478 yesdrag(event.view, mousemoving);
2479 noevent$2(event);
2480 gestures.mouse("end", event);
2481 }
2482
2483 function touchstarted(event, d) {
2484 if (!filter.call(this, event, d)) return;
2485 var touches = event.changedTouches,
2486 c = container.call(this, event, d),
2487 n = touches.length, i, gesture;
2488
2489 for (i = 0; i < n; ++i) {
2490 if (gesture = beforestart(this, c, event, d, touches[i].identifier, touches[i])) {
2491 nopropagation$2(event);
2492 gesture("start", event, touches[i]);
2493 }
2494 }
2495 }
2496
2497 function touchmoved(event) {
2498 var touches = event.changedTouches,
2499 n = touches.length, i, gesture;
2500
2501 for (i = 0; i < n; ++i) {
2502 if (gesture = gestures[touches[i].identifier]) {
2503 noevent$2(event);
2504 gesture("drag", event, touches[i]);
2505 }
2506 }
2507 }
2508
2509 function touchended(event) {
2510 var touches = event.changedTouches,
2511 n = touches.length, i, gesture;
2512
2513 if (touchending) clearTimeout(touchending);
2514 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
2515 for (i = 0; i < n; ++i) {
2516 if (gesture = gestures[touches[i].identifier]) {
2517 nopropagation$2(event);
2518 gesture("end", event, touches[i]);
2519 }
2520 }
2521 }
2522
2523 function beforestart(that, container, event, d, identifier, touch) {
2524 var dispatch = listeners.copy(),
2525 p = pointer(touch || event, container), dx, dy,
2526 s;
2527
2528 if ((s = subject.call(that, new DragEvent("beforestart", {
2529 sourceEvent: event,
2530 target: drag,
2531 identifier,
2532 active,
2533 x: p[0],
2534 y: p[1],
2535 dx: 0,
2536 dy: 0,
2537 dispatch
2538 }), d)) == null) return;
2539
2540 dx = s.x - p[0] || 0;
2541 dy = s.y - p[1] || 0;
2542
2543 return function gesture(type, event, touch) {
2544 var p0 = p, n;
2545 switch (type) {
2546 case "start": gestures[identifier] = gesture, n = active++; break;
2547 case "end": delete gestures[identifier], --active; // nobreak
2548 case "drag": p = pointer(touch || event, container), n = active; break;
2549 }
2550 dispatch.call(
2551 type,
2552 that,
2553 new DragEvent(type, {
2554 sourceEvent: event,
2555 subject: s,
2556 target: drag,
2557 identifier,
2558 active: n,
2559 x: p[0] + dx,
2560 y: p[1] + dy,
2561 dx: p[0] - p0[0],
2562 dy: p[1] - p0[1],
2563 dispatch
2564 }),
2565 d
2566 );
2567 };
2568 }
2569
2570 drag.filter = function(_) {
2571 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), drag) : filter;
2572 };
2573
2574 drag.container = function(_) {
2575 return arguments.length ? (container = typeof _ === "function" ? _ : constant$9(_), drag) : container;
2576 };
2577
2578 drag.subject = function(_) {
2579 return arguments.length ? (subject = typeof _ === "function" ? _ : constant$9(_), drag) : subject;
2580 };
2581
2582 drag.touchable = function(_) {
2583 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$9(!!_), drag) : touchable;
2584 };
2585
2586 drag.on = function() {
2587 var value = listeners.on.apply(listeners, arguments);
2588 return value === listeners ? drag : value;
2589 };
2590
2591 drag.clickDistance = function(_) {
2592 return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
2593 };
2594
2595 return drag;
2596}
2597
2598function define(constructor, factory, prototype) {
2599 constructor.prototype = factory.prototype = prototype;
2600 prototype.constructor = constructor;
2601}
2602
2603function extend(parent, definition) {
2604 var prototype = Object.create(parent.prototype);
2605 for (var key in definition) prototype[key] = definition[key];
2606 return prototype;
2607}
2608
2609function Color() {}
2610
2611var darker = 0.7;
2612var brighter = 1 / darker;
2613
2614var reI = "\\s*([+-]?\\d+)\\s*",
2615 reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
2616 reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
2617 reHex = /^#([0-9a-f]{3,8})$/,
2618 reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
2619 reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
2620 reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
2621 reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
2622 reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
2623 reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
2624
2625var named = {
2626 aliceblue: 0xf0f8ff,
2627 antiquewhite: 0xfaebd7,
2628 aqua: 0x00ffff,
2629 aquamarine: 0x7fffd4,
2630 azure: 0xf0ffff,
2631 beige: 0xf5f5dc,
2632 bisque: 0xffe4c4,
2633 black: 0x000000,
2634 blanchedalmond: 0xffebcd,
2635 blue: 0x0000ff,
2636 blueviolet: 0x8a2be2,
2637 brown: 0xa52a2a,
2638 burlywood: 0xdeb887,
2639 cadetblue: 0x5f9ea0,
2640 chartreuse: 0x7fff00,
2641 chocolate: 0xd2691e,
2642 coral: 0xff7f50,
2643 cornflowerblue: 0x6495ed,
2644 cornsilk: 0xfff8dc,
2645 crimson: 0xdc143c,
2646 cyan: 0x00ffff,
2647 darkblue: 0x00008b,
2648 darkcyan: 0x008b8b,
2649 darkgoldenrod: 0xb8860b,
2650 darkgray: 0xa9a9a9,
2651 darkgreen: 0x006400,
2652 darkgrey: 0xa9a9a9,
2653 darkkhaki: 0xbdb76b,
2654 darkmagenta: 0x8b008b,
2655 darkolivegreen: 0x556b2f,
2656 darkorange: 0xff8c00,
2657 darkorchid: 0x9932cc,
2658 darkred: 0x8b0000,
2659 darksalmon: 0xe9967a,
2660 darkseagreen: 0x8fbc8f,
2661 darkslateblue: 0x483d8b,
2662 darkslategray: 0x2f4f4f,
2663 darkslategrey: 0x2f4f4f,
2664 darkturquoise: 0x00ced1,
2665 darkviolet: 0x9400d3,
2666 deeppink: 0xff1493,
2667 deepskyblue: 0x00bfff,
2668 dimgray: 0x696969,
2669 dimgrey: 0x696969,
2670 dodgerblue: 0x1e90ff,
2671 firebrick: 0xb22222,
2672 floralwhite: 0xfffaf0,
2673 forestgreen: 0x228b22,
2674 fuchsia: 0xff00ff,
2675 gainsboro: 0xdcdcdc,
2676 ghostwhite: 0xf8f8ff,
2677 gold: 0xffd700,
2678 goldenrod: 0xdaa520,
2679 gray: 0x808080,
2680 green: 0x008000,
2681 greenyellow: 0xadff2f,
2682 grey: 0x808080,
2683 honeydew: 0xf0fff0,
2684 hotpink: 0xff69b4,
2685 indianred: 0xcd5c5c,
2686 indigo: 0x4b0082,
2687 ivory: 0xfffff0,
2688 khaki: 0xf0e68c,
2689 lavender: 0xe6e6fa,
2690 lavenderblush: 0xfff0f5,
2691 lawngreen: 0x7cfc00,
2692 lemonchiffon: 0xfffacd,
2693 lightblue: 0xadd8e6,
2694 lightcoral: 0xf08080,
2695 lightcyan: 0xe0ffff,
2696 lightgoldenrodyellow: 0xfafad2,
2697 lightgray: 0xd3d3d3,
2698 lightgreen: 0x90ee90,
2699 lightgrey: 0xd3d3d3,
2700 lightpink: 0xffb6c1,
2701 lightsalmon: 0xffa07a,
2702 lightseagreen: 0x20b2aa,
2703 lightskyblue: 0x87cefa,
2704 lightslategray: 0x778899,
2705 lightslategrey: 0x778899,
2706 lightsteelblue: 0xb0c4de,
2707 lightyellow: 0xffffe0,
2708 lime: 0x00ff00,
2709 limegreen: 0x32cd32,
2710 linen: 0xfaf0e6,
2711 magenta: 0xff00ff,
2712 maroon: 0x800000,
2713 mediumaquamarine: 0x66cdaa,
2714 mediumblue: 0x0000cd,
2715 mediumorchid: 0xba55d3,
2716 mediumpurple: 0x9370db,
2717 mediumseagreen: 0x3cb371,
2718 mediumslateblue: 0x7b68ee,
2719 mediumspringgreen: 0x00fa9a,
2720 mediumturquoise: 0x48d1cc,
2721 mediumvioletred: 0xc71585,
2722 midnightblue: 0x191970,
2723 mintcream: 0xf5fffa,
2724 mistyrose: 0xffe4e1,
2725 moccasin: 0xffe4b5,
2726 navajowhite: 0xffdead,
2727 navy: 0x000080,
2728 oldlace: 0xfdf5e6,
2729 olive: 0x808000,
2730 olivedrab: 0x6b8e23,
2731 orange: 0xffa500,
2732 orangered: 0xff4500,
2733 orchid: 0xda70d6,
2734 palegoldenrod: 0xeee8aa,
2735 palegreen: 0x98fb98,
2736 paleturquoise: 0xafeeee,
2737 palevioletred: 0xdb7093,
2738 papayawhip: 0xffefd5,
2739 peachpuff: 0xffdab9,
2740 peru: 0xcd853f,
2741 pink: 0xffc0cb,
2742 plum: 0xdda0dd,
2743 powderblue: 0xb0e0e6,
2744 purple: 0x800080,
2745 rebeccapurple: 0x663399,
2746 red: 0xff0000,
2747 rosybrown: 0xbc8f8f,
2748 royalblue: 0x4169e1,
2749 saddlebrown: 0x8b4513,
2750 salmon: 0xfa8072,
2751 sandybrown: 0xf4a460,
2752 seagreen: 0x2e8b57,
2753 seashell: 0xfff5ee,
2754 sienna: 0xa0522d,
2755 silver: 0xc0c0c0,
2756 skyblue: 0x87ceeb,
2757 slateblue: 0x6a5acd,
2758 slategray: 0x708090,
2759 slategrey: 0x708090,
2760 snow: 0xfffafa,
2761 springgreen: 0x00ff7f,
2762 steelblue: 0x4682b4,
2763 tan: 0xd2b48c,
2764 teal: 0x008080,
2765 thistle: 0xd8bfd8,
2766 tomato: 0xff6347,
2767 turquoise: 0x40e0d0,
2768 violet: 0xee82ee,
2769 wheat: 0xf5deb3,
2770 white: 0xffffff,
2771 whitesmoke: 0xf5f5f5,
2772 yellow: 0xffff00,
2773 yellowgreen: 0x9acd32
2774};
2775
2776define(Color, color, {
2777 copy: function(channels) {
2778 return Object.assign(new this.constructor, this, channels);
2779 },
2780 displayable: function() {
2781 return this.rgb().displayable();
2782 },
2783 hex: color_formatHex, // Deprecated! Use color.formatHex.
2784 formatHex: color_formatHex,
2785 formatHsl: color_formatHsl,
2786 formatRgb: color_formatRgb,
2787 toString: color_formatRgb
2788});
2789
2790function color_formatHex() {
2791 return this.rgb().formatHex();
2792}
2793
2794function color_formatHsl() {
2795 return hslConvert(this).formatHsl();
2796}
2797
2798function color_formatRgb() {
2799 return this.rgb().formatRgb();
2800}
2801
2802function color(format) {
2803 var m, l;
2804 format = (format + "").trim().toLowerCase();
2805 return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
2806 : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
2807 : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
2808 : l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
2809 : null) // invalid hex
2810 : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
2811 : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
2812 : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
2813 : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
2814 : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
2815 : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
2816 : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
2817 : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
2818 : null;
2819}
2820
2821function rgbn(n) {
2822 return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
2823}
2824
2825function rgba(r, g, b, a) {
2826 if (a <= 0) r = g = b = NaN;
2827 return new Rgb(r, g, b, a);
2828}
2829
2830function rgbConvert(o) {
2831 if (!(o instanceof Color)) o = color(o);
2832 if (!o) return new Rgb;
2833 o = o.rgb();
2834 return new Rgb(o.r, o.g, o.b, o.opacity);
2835}
2836
2837function rgb(r, g, b, opacity) {
2838 return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
2839}
2840
2841function Rgb(r, g, b, opacity) {
2842 this.r = +r;
2843 this.g = +g;
2844 this.b = +b;
2845 this.opacity = +opacity;
2846}
2847
2848define(Rgb, rgb, extend(Color, {
2849 brighter: function(k) {
2850 k = k == null ? brighter : Math.pow(brighter, k);
2851 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2852 },
2853 darker: function(k) {
2854 k = k == null ? darker : Math.pow(darker, k);
2855 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2856 },
2857 rgb: function() {
2858 return this;
2859 },
2860 displayable: function() {
2861 return (-0.5 <= this.r && this.r < 255.5)
2862 && (-0.5 <= this.g && this.g < 255.5)
2863 && (-0.5 <= this.b && this.b < 255.5)
2864 && (0 <= this.opacity && this.opacity <= 1);
2865 },
2866 hex: rgb_formatHex, // Deprecated! Use color.formatHex.
2867 formatHex: rgb_formatHex,
2868 formatRgb: rgb_formatRgb,
2869 toString: rgb_formatRgb
2870}));
2871
2872function rgb_formatHex() {
2873 return "#" + hex(this.r) + hex(this.g) + hex(this.b);
2874}
2875
2876function rgb_formatRgb() {
2877 var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2878 return (a === 1 ? "rgb(" : "rgba(")
2879 + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
2880 + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
2881 + Math.max(0, Math.min(255, Math.round(this.b) || 0))
2882 + (a === 1 ? ")" : ", " + a + ")");
2883}
2884
2885function hex(value) {
2886 value = Math.max(0, Math.min(255, Math.round(value) || 0));
2887 return (value < 16 ? "0" : "") + value.toString(16);
2888}
2889
2890function hsla(h, s, l, a) {
2891 if (a <= 0) h = s = l = NaN;
2892 else if (l <= 0 || l >= 1) h = s = NaN;
2893 else if (s <= 0) h = NaN;
2894 return new Hsl(h, s, l, a);
2895}
2896
2897function hslConvert(o) {
2898 if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2899 if (!(o instanceof Color)) o = color(o);
2900 if (!o) return new Hsl;
2901 if (o instanceof Hsl) return o;
2902 o = o.rgb();
2903 var r = o.r / 255,
2904 g = o.g / 255,
2905 b = o.b / 255,
2906 min = Math.min(r, g, b),
2907 max = Math.max(r, g, b),
2908 h = NaN,
2909 s = max - min,
2910 l = (max + min) / 2;
2911 if (s) {
2912 if (r === max) h = (g - b) / s + (g < b) * 6;
2913 else if (g === max) h = (b - r) / s + 2;
2914 else h = (r - g) / s + 4;
2915 s /= l < 0.5 ? max + min : 2 - max - min;
2916 h *= 60;
2917 } else {
2918 s = l > 0 && l < 1 ? 0 : h;
2919 }
2920 return new Hsl(h, s, l, o.opacity);
2921}
2922
2923function hsl$2(h, s, l, opacity) {
2924 return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2925}
2926
2927function Hsl(h, s, l, opacity) {
2928 this.h = +h;
2929 this.s = +s;
2930 this.l = +l;
2931 this.opacity = +opacity;
2932}
2933
2934define(Hsl, hsl$2, extend(Color, {
2935 brighter: function(k) {
2936 k = k == null ? brighter : Math.pow(brighter, k);
2937 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2938 },
2939 darker: function(k) {
2940 k = k == null ? darker : Math.pow(darker, k);
2941 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2942 },
2943 rgb: function() {
2944 var h = this.h % 360 + (this.h < 0) * 360,
2945 s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
2946 l = this.l,
2947 m2 = l + (l < 0.5 ? l : 1 - l) * s,
2948 m1 = 2 * l - m2;
2949 return new Rgb(
2950 hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
2951 hsl2rgb(h, m1, m2),
2952 hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
2953 this.opacity
2954 );
2955 },
2956 displayable: function() {
2957 return (0 <= this.s && this.s <= 1 || isNaN(this.s))
2958 && (0 <= this.l && this.l <= 1)
2959 && (0 <= this.opacity && this.opacity <= 1);
2960 },
2961 formatHsl: function() {
2962 var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2963 return (a === 1 ? "hsl(" : "hsla(")
2964 + (this.h || 0) + ", "
2965 + (this.s || 0) * 100 + "%, "
2966 + (this.l || 0) * 100 + "%"
2967 + (a === 1 ? ")" : ", " + a + ")");
2968 }
2969}));
2970
2971/* From FvD 13.37, CSS Color Module Level 3 */
2972function hsl2rgb(h, m1, m2) {
2973 return (h < 60 ? m1 + (m2 - m1) * h / 60
2974 : h < 180 ? m2
2975 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
2976 : m1) * 255;
2977}
2978
2979const radians$1 = Math.PI / 180;
2980const degrees$2 = 180 / Math.PI;
2981
2982// https://observablehq.com/@mbostock/lab-and-rgb
2983const K = 18,
2984 Xn = 0.96422,
2985 Yn = 1,
2986 Zn = 0.82521,
2987 t0$1 = 4 / 29,
2988 t1$1 = 6 / 29,
2989 t2 = 3 * t1$1 * t1$1,
2990 t3 = t1$1 * t1$1 * t1$1;
2991
2992function labConvert(o) {
2993 if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
2994 if (o instanceof Hcl) return hcl2lab(o);
2995 if (!(o instanceof Rgb)) o = rgbConvert(o);
2996 var r = rgb2lrgb(o.r),
2997 g = rgb2lrgb(o.g),
2998 b = rgb2lrgb(o.b),
2999 y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
3000 if (r === g && g === b) x = z = y; else {
3001 x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
3002 z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
3003 }
3004 return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
3005}
3006
3007function gray(l, opacity) {
3008 return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
3009}
3010
3011function lab$1(l, a, b, opacity) {
3012 return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
3013}
3014
3015function Lab(l, a, b, opacity) {
3016 this.l = +l;
3017 this.a = +a;
3018 this.b = +b;
3019 this.opacity = +opacity;
3020}
3021
3022define(Lab, lab$1, extend(Color, {
3023 brighter: function(k) {
3024 return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
3025 },
3026 darker: function(k) {
3027 return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
3028 },
3029 rgb: function() {
3030 var y = (this.l + 16) / 116,
3031 x = isNaN(this.a) ? y : y + this.a / 500,
3032 z = isNaN(this.b) ? y : y - this.b / 200;
3033 x = Xn * lab2xyz(x);
3034 y = Yn * lab2xyz(y);
3035 z = Zn * lab2xyz(z);
3036 return new Rgb(
3037 lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
3038 lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
3039 lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
3040 this.opacity
3041 );
3042 }
3043}));
3044
3045function xyz2lab(t) {
3046 return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0$1;
3047}
3048
3049function lab2xyz(t) {
3050 return t > t1$1 ? t * t * t : t2 * (t - t0$1);
3051}
3052
3053function lrgb2rgb(x) {
3054 return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
3055}
3056
3057function rgb2lrgb(x) {
3058 return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
3059}
3060
3061function hclConvert(o) {
3062 if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
3063 if (!(o instanceof Lab)) o = labConvert(o);
3064 if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
3065 var h = Math.atan2(o.b, o.a) * degrees$2;
3066 return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
3067}
3068
3069function lch(l, c, h, opacity) {
3070 return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
3071}
3072
3073function hcl$2(h, c, l, opacity) {
3074 return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
3075}
3076
3077function Hcl(h, c, l, opacity) {
3078 this.h = +h;
3079 this.c = +c;
3080 this.l = +l;
3081 this.opacity = +opacity;
3082}
3083
3084function hcl2lab(o) {
3085 if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
3086 var h = o.h * radians$1;
3087 return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
3088}
3089
3090define(Hcl, hcl$2, extend(Color, {
3091 brighter: function(k) {
3092 return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
3093 },
3094 darker: function(k) {
3095 return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
3096 },
3097 rgb: function() {
3098 return hcl2lab(this).rgb();
3099 }
3100}));
3101
3102var A = -0.14861,
3103 B = +1.78277,
3104 C = -0.29227,
3105 D = -0.90649,
3106 E = +1.97294,
3107 ED = E * D,
3108 EB = E * B,
3109 BC_DA = B * C - D * A;
3110
3111function cubehelixConvert(o) {
3112 if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
3113 if (!(o instanceof Rgb)) o = rgbConvert(o);
3114 var r = o.r / 255,
3115 g = o.g / 255,
3116 b = o.b / 255,
3117 l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
3118 bl = b - l,
3119 k = (E * (g - l) - C * bl) / D,
3120 s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
3121 h = s ? Math.atan2(k, bl) * degrees$2 - 120 : NaN;
3122 return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
3123}
3124
3125function cubehelix$3(h, s, l, opacity) {
3126 return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
3127}
3128
3129function Cubehelix(h, s, l, opacity) {
3130 this.h = +h;
3131 this.s = +s;
3132 this.l = +l;
3133 this.opacity = +opacity;
3134}
3135
3136define(Cubehelix, cubehelix$3, extend(Color, {
3137 brighter: function(k) {
3138 k = k == null ? brighter : Math.pow(brighter, k);
3139 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
3140 },
3141 darker: function(k) {
3142 k = k == null ? darker : Math.pow(darker, k);
3143 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
3144 },
3145 rgb: function() {
3146 var h = isNaN(this.h) ? 0 : (this.h + 120) * radians$1,
3147 l = +this.l,
3148 a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
3149 cosh = Math.cos(h),
3150 sinh = Math.sin(h);
3151 return new Rgb(
3152 255 * (l + a * (A * cosh + B * sinh)),
3153 255 * (l + a * (C * cosh + D * sinh)),
3154 255 * (l + a * (E * cosh)),
3155 this.opacity
3156 );
3157 }
3158}));
3159
3160function basis$1(t1, v0, v1, v2, v3) {
3161 var t2 = t1 * t1, t3 = t2 * t1;
3162 return ((1 - 3 * t1 + 3 * t2 - t3) * v0
3163 + (4 - 6 * t2 + 3 * t3) * v1
3164 + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
3165 + t3 * v3) / 6;
3166}
3167
3168function basis$2(values) {
3169 var n = values.length - 1;
3170 return function(t) {
3171 var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
3172 v1 = values[i],
3173 v2 = values[i + 1],
3174 v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
3175 v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
3176 return basis$1((t - i / n) * n, v0, v1, v2, v3);
3177 };
3178}
3179
3180function basisClosed$1(values) {
3181 var n = values.length;
3182 return function(t) {
3183 var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
3184 v0 = values[(i + n - 1) % n],
3185 v1 = values[i % n],
3186 v2 = values[(i + 1) % n],
3187 v3 = values[(i + 2) % n];
3188 return basis$1((t - i / n) * n, v0, v1, v2, v3);
3189 };
3190}
3191
3192var constant$8 = x => () => x;
3193
3194function linear$2(a, d) {
3195 return function(t) {
3196 return a + t * d;
3197 };
3198}
3199
3200function exponential$1(a, b, y) {
3201 return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
3202 return Math.pow(a + t * b, y);
3203 };
3204}
3205
3206function hue$1(a, b) {
3207 var d = b - a;
3208 return d ? linear$2(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$8(isNaN(a) ? b : a);
3209}
3210
3211function gamma$1(y) {
3212 return (y = +y) === 1 ? nogamma : function(a, b) {
3213 return b - a ? exponential$1(a, b, y) : constant$8(isNaN(a) ? b : a);
3214 };
3215}
3216
3217function nogamma(a, b) {
3218 var d = b - a;
3219 return d ? linear$2(a, d) : constant$8(isNaN(a) ? b : a);
3220}
3221
3222var interpolateRgb = (function rgbGamma(y) {
3223 var color = gamma$1(y);
3224
3225 function rgb$1(start, end) {
3226 var r = color((start = rgb(start)).r, (end = rgb(end)).r),
3227 g = color(start.g, end.g),
3228 b = color(start.b, end.b),
3229 opacity = nogamma(start.opacity, end.opacity);
3230 return function(t) {
3231 start.r = r(t);
3232 start.g = g(t);
3233 start.b = b(t);
3234 start.opacity = opacity(t);
3235 return start + "";
3236 };
3237 }
3238
3239 rgb$1.gamma = rgbGamma;
3240
3241 return rgb$1;
3242})(1);
3243
3244function rgbSpline(spline) {
3245 return function(colors) {
3246 var n = colors.length,
3247 r = new Array(n),
3248 g = new Array(n),
3249 b = new Array(n),
3250 i, color;
3251 for (i = 0; i < n; ++i) {
3252 color = rgb(colors[i]);
3253 r[i] = color.r || 0;
3254 g[i] = color.g || 0;
3255 b[i] = color.b || 0;
3256 }
3257 r = spline(r);
3258 g = spline(g);
3259 b = spline(b);
3260 color.opacity = 1;
3261 return function(t) {
3262 color.r = r(t);
3263 color.g = g(t);
3264 color.b = b(t);
3265 return color + "";
3266 };
3267 };
3268}
3269
3270var rgbBasis = rgbSpline(basis$2);
3271var rgbBasisClosed = rgbSpline(basisClosed$1);
3272
3273function numberArray(a, b) {
3274 if (!b) b = [];
3275 var n = a ? Math.min(b.length, a.length) : 0,
3276 c = b.slice(),
3277 i;
3278 return function(t) {
3279 for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
3280 return c;
3281 };
3282}
3283
3284function isNumberArray(x) {
3285 return ArrayBuffer.isView(x) && !(x instanceof DataView);
3286}
3287
3288function array$3(a, b) {
3289 return (isNumberArray(b) ? numberArray : genericArray)(a, b);
3290}
3291
3292function genericArray(a, b) {
3293 var nb = b ? b.length : 0,
3294 na = a ? Math.min(nb, a.length) : 0,
3295 x = new Array(na),
3296 c = new Array(nb),
3297 i;
3298
3299 for (i = 0; i < na; ++i) x[i] = interpolate$2(a[i], b[i]);
3300 for (; i < nb; ++i) c[i] = b[i];
3301
3302 return function(t) {
3303 for (i = 0; i < na; ++i) c[i] = x[i](t);
3304 return c;
3305 };
3306}
3307
3308function date$1(a, b) {
3309 var d = new Date;
3310 return a = +a, b = +b, function(t) {
3311 return d.setTime(a * (1 - t) + b * t), d;
3312 };
3313}
3314
3315function interpolateNumber(a, b) {
3316 return a = +a, b = +b, function(t) {
3317 return a * (1 - t) + b * t;
3318 };
3319}
3320
3321function object$1(a, b) {
3322 var i = {},
3323 c = {},
3324 k;
3325
3326 if (a === null || typeof a !== "object") a = {};
3327 if (b === null || typeof b !== "object") b = {};
3328
3329 for (k in b) {
3330 if (k in a) {
3331 i[k] = interpolate$2(a[k], b[k]);
3332 } else {
3333 c[k] = b[k];
3334 }
3335 }
3336
3337 return function(t) {
3338 for (k in i) c[k] = i[k](t);
3339 return c;
3340 };
3341}
3342
3343var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
3344 reB = new RegExp(reA.source, "g");
3345
3346function zero(b) {
3347 return function() {
3348 return b;
3349 };
3350}
3351
3352function one(b) {
3353 return function(t) {
3354 return b(t) + "";
3355 };
3356}
3357
3358function interpolateString(a, b) {
3359 var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
3360 am, // current match in a
3361 bm, // current match in b
3362 bs, // string preceding current number in b, if any
3363 i = -1, // index in s
3364 s = [], // string constants and placeholders
3365 q = []; // number interpolators
3366
3367 // Coerce inputs to strings.
3368 a = a + "", b = b + "";
3369
3370 // Interpolate pairs of numbers in a & b.
3371 while ((am = reA.exec(a))
3372 && (bm = reB.exec(b))) {
3373 if ((bs = bm.index) > bi) { // a string precedes the next number in b
3374 bs = b.slice(bi, bs);
3375 if (s[i]) s[i] += bs; // coalesce with previous string
3376 else s[++i] = bs;
3377 }
3378 if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
3379 if (s[i]) s[i] += bm; // coalesce with previous string
3380 else s[++i] = bm;
3381 } else { // interpolate non-matching numbers
3382 s[++i] = null;
3383 q.push({i: i, x: interpolateNumber(am, bm)});
3384 }
3385 bi = reB.lastIndex;
3386 }
3387
3388 // Add remains of b.
3389 if (bi < b.length) {
3390 bs = b.slice(bi);
3391 if (s[i]) s[i] += bs; // coalesce with previous string
3392 else s[++i] = bs;
3393 }
3394
3395 // Special optimization for only a single match.
3396 // Otherwise, interpolate each of the numbers and rejoin the string.
3397 return s.length < 2 ? (q[0]
3398 ? one(q[0].x)
3399 : zero(b))
3400 : (b = q.length, function(t) {
3401 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
3402 return s.join("");
3403 });
3404}
3405
3406function interpolate$2(a, b) {
3407 var t = typeof b, c;
3408 return b == null || t === "boolean" ? constant$8(b)
3409 : (t === "number" ? interpolateNumber
3410 : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
3411 : b instanceof color ? interpolateRgb
3412 : b instanceof Date ? date$1
3413 : isNumberArray(b) ? numberArray
3414 : Array.isArray(b) ? genericArray
3415 : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object$1
3416 : interpolateNumber)(a, b);
3417}
3418
3419function discrete(range) {
3420 var n = range.length;
3421 return function(t) {
3422 return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
3423 };
3424}
3425
3426function hue(a, b) {
3427 var i = hue$1(+a, +b);
3428 return function(t) {
3429 var x = i(t);
3430 return x - 360 * Math.floor(x / 360);
3431 };
3432}
3433
3434function interpolateRound(a, b) {
3435 return a = +a, b = +b, function(t) {
3436 return Math.round(a * (1 - t) + b * t);
3437 };
3438}
3439
3440var degrees$1 = 180 / Math.PI;
3441
3442var identity$7 = {
3443 translateX: 0,
3444 translateY: 0,
3445 rotate: 0,
3446 skewX: 0,
3447 scaleX: 1,
3448 scaleY: 1
3449};
3450
3451function decompose(a, b, c, d, e, f) {
3452 var scaleX, scaleY, skewX;
3453 if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
3454 if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
3455 if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
3456 if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
3457 return {
3458 translateX: e,
3459 translateY: f,
3460 rotate: Math.atan2(b, a) * degrees$1,
3461 skewX: Math.atan(skewX) * degrees$1,
3462 scaleX: scaleX,
3463 scaleY: scaleY
3464 };
3465}
3466
3467var svgNode;
3468
3469/* eslint-disable no-undef */
3470function parseCss(value) {
3471 const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
3472 return m.isIdentity ? identity$7 : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
3473}
3474
3475function parseSvg(value) {
3476 if (value == null) return identity$7;
3477 if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
3478 svgNode.setAttribute("transform", value);
3479 if (!(value = svgNode.transform.baseVal.consolidate())) return identity$7;
3480 value = value.matrix;
3481 return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
3482}
3483
3484function interpolateTransform(parse, pxComma, pxParen, degParen) {
3485
3486 function pop(s) {
3487 return s.length ? s.pop() + " " : "";
3488 }
3489
3490 function translate(xa, ya, xb, yb, s, q) {
3491 if (xa !== xb || ya !== yb) {
3492 var i = s.push("translate(", null, pxComma, null, pxParen);
3493 q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
3494 } else if (xb || yb) {
3495 s.push("translate(" + xb + pxComma + yb + pxParen);
3496 }
3497 }
3498
3499 function rotate(a, b, s, q) {
3500 if (a !== b) {
3501 if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
3502 q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
3503 } else if (b) {
3504 s.push(pop(s) + "rotate(" + b + degParen);
3505 }
3506 }
3507
3508 function skewX(a, b, s, q) {
3509 if (a !== b) {
3510 q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
3511 } else if (b) {
3512 s.push(pop(s) + "skewX(" + b + degParen);
3513 }
3514 }
3515
3516 function scale(xa, ya, xb, yb, s, q) {
3517 if (xa !== xb || ya !== yb) {
3518 var i = s.push(pop(s) + "scale(", null, ",", null, ")");
3519 q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
3520 } else if (xb !== 1 || yb !== 1) {
3521 s.push(pop(s) + "scale(" + xb + "," + yb + ")");
3522 }
3523 }
3524
3525 return function(a, b) {
3526 var s = [], // string constants and placeholders
3527 q = []; // number interpolators
3528 a = parse(a), b = parse(b);
3529 translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
3530 rotate(a.rotate, b.rotate, s, q);
3531 skewX(a.skewX, b.skewX, s, q);
3532 scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
3533 a = b = null; // gc
3534 return function(t) {
3535 var i = -1, n = q.length, o;
3536 while (++i < n) s[(o = q[i]).i] = o.x(t);
3537 return s.join("");
3538 };
3539 };
3540}
3541
3542var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
3543var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
3544
3545var epsilon2$1 = 1e-12;
3546
3547function cosh(x) {
3548 return ((x = Math.exp(x)) + 1 / x) / 2;
3549}
3550
3551function sinh(x) {
3552 return ((x = Math.exp(x)) - 1 / x) / 2;
3553}
3554
3555function tanh(x) {
3556 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
3557}
3558
3559var interpolateZoom = (function zoomRho(rho, rho2, rho4) {
3560
3561 // p0 = [ux0, uy0, w0]
3562 // p1 = [ux1, uy1, w1]
3563 function zoom(p0, p1) {
3564 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
3565 ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
3566 dx = ux1 - ux0,
3567 dy = uy1 - uy0,
3568 d2 = dx * dx + dy * dy,
3569 i,
3570 S;
3571
3572 // Special case for u0 ≅ u1.
3573 if (d2 < epsilon2$1) {
3574 S = Math.log(w1 / w0) / rho;
3575 i = function(t) {
3576 return [
3577 ux0 + t * dx,
3578 uy0 + t * dy,
3579 w0 * Math.exp(rho * t * S)
3580 ];
3581 };
3582 }
3583
3584 // General case.
3585 else {
3586 var d1 = Math.sqrt(d2),
3587 b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
3588 b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
3589 r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
3590 r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
3591 S = (r1 - r0) / rho;
3592 i = function(t) {
3593 var s = t * S,
3594 coshr0 = cosh(r0),
3595 u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
3596 return [
3597 ux0 + u * dx,
3598 uy0 + u * dy,
3599 w0 * coshr0 / cosh(rho * s + r0)
3600 ];
3601 };
3602 }
3603
3604 i.duration = S * 1000 * rho / Math.SQRT2;
3605
3606 return i;
3607 }
3608
3609 zoom.rho = function(_) {
3610 var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
3611 return zoomRho(_1, _2, _4);
3612 };
3613
3614 return zoom;
3615})(Math.SQRT2, 2, 4);
3616
3617function hsl(hue) {
3618 return function(start, end) {
3619 var h = hue((start = hsl$2(start)).h, (end = hsl$2(end)).h),
3620 s = nogamma(start.s, end.s),
3621 l = nogamma(start.l, end.l),
3622 opacity = nogamma(start.opacity, end.opacity);
3623 return function(t) {
3624 start.h = h(t);
3625 start.s = s(t);
3626 start.l = l(t);
3627 start.opacity = opacity(t);
3628 return start + "";
3629 };
3630 }
3631}
3632
3633var hsl$1 = hsl(hue$1);
3634var hslLong = hsl(nogamma);
3635
3636function lab(start, end) {
3637 var l = nogamma((start = lab$1(start)).l, (end = lab$1(end)).l),
3638 a = nogamma(start.a, end.a),
3639 b = nogamma(start.b, end.b),
3640 opacity = nogamma(start.opacity, end.opacity);
3641 return function(t) {
3642 start.l = l(t);
3643 start.a = a(t);
3644 start.b = b(t);
3645 start.opacity = opacity(t);
3646 return start + "";
3647 };
3648}
3649
3650function hcl(hue) {
3651 return function(start, end) {
3652 var h = hue((start = hcl$2(start)).h, (end = hcl$2(end)).h),
3653 c = nogamma(start.c, end.c),
3654 l = nogamma(start.l, end.l),
3655 opacity = nogamma(start.opacity, end.opacity);
3656 return function(t) {
3657 start.h = h(t);
3658 start.c = c(t);
3659 start.l = l(t);
3660 start.opacity = opacity(t);
3661 return start + "";
3662 };
3663 }
3664}
3665
3666var hcl$1 = hcl(hue$1);
3667var hclLong = hcl(nogamma);
3668
3669function cubehelix$1(hue) {
3670 return (function cubehelixGamma(y) {
3671 y = +y;
3672
3673 function cubehelix(start, end) {
3674 var h = hue((start = cubehelix$3(start)).h, (end = cubehelix$3(end)).h),
3675 s = nogamma(start.s, end.s),
3676 l = nogamma(start.l, end.l),
3677 opacity = nogamma(start.opacity, end.opacity);
3678 return function(t) {
3679 start.h = h(t);
3680 start.s = s(t);
3681 start.l = l(Math.pow(t, y));
3682 start.opacity = opacity(t);
3683 return start + "";
3684 };
3685 }
3686
3687 cubehelix.gamma = cubehelixGamma;
3688
3689 return cubehelix;
3690 })(1);
3691}
3692
3693var cubehelix$2 = cubehelix$1(hue$1);
3694var cubehelixLong = cubehelix$1(nogamma);
3695
3696function piecewise(interpolate, values) {
3697 if (values === undefined) values = interpolate, interpolate = interpolate$2;
3698 var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
3699 while (i < n) I[i] = interpolate(v, v = values[++i]);
3700 return function(t) {
3701 var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
3702 return I[i](t - i);
3703 };
3704}
3705
3706function quantize$1(interpolator, n) {
3707 var samples = new Array(n);
3708 for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
3709 return samples;
3710}
3711
3712var frame = 0, // is an animation frame pending?
3713 timeout$1 = 0, // is a timeout pending?
3714 interval$1 = 0, // are any timers active?
3715 pokeDelay = 1000, // how frequently we check for clock skew
3716 taskHead,
3717 taskTail,
3718 clockLast = 0,
3719 clockNow = 0,
3720 clockSkew = 0,
3721 clock = typeof performance === "object" && performance.now ? performance : Date,
3722 setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
3723
3724function now() {
3725 return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
3726}
3727
3728function clearNow() {
3729 clockNow = 0;
3730}
3731
3732function Timer() {
3733 this._call =
3734 this._time =
3735 this._next = null;
3736}
3737
3738Timer.prototype = timer.prototype = {
3739 constructor: Timer,
3740 restart: function(callback, delay, time) {
3741 if (typeof callback !== "function") throw new TypeError("callback is not a function");
3742 time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
3743 if (!this._next && taskTail !== this) {
3744 if (taskTail) taskTail._next = this;
3745 else taskHead = this;
3746 taskTail = this;
3747 }
3748 this._call = callback;
3749 this._time = time;
3750 sleep();
3751 },
3752 stop: function() {
3753 if (this._call) {
3754 this._call = null;
3755 this._time = Infinity;
3756 sleep();
3757 }
3758 }
3759};
3760
3761function timer(callback, delay, time) {
3762 var t = new Timer;
3763 t.restart(callback, delay, time);
3764 return t;
3765}
3766
3767function timerFlush() {
3768 now(); // Get the current time, if not already set.
3769 ++frame; // Pretend we’ve set an alarm, if we haven’t already.
3770 var t = taskHead, e;
3771 while (t) {
3772 if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
3773 t = t._next;
3774 }
3775 --frame;
3776}
3777
3778function wake() {
3779 clockNow = (clockLast = clock.now()) + clockSkew;
3780 frame = timeout$1 = 0;
3781 try {
3782 timerFlush();
3783 } finally {
3784 frame = 0;
3785 nap();
3786 clockNow = 0;
3787 }
3788}
3789
3790function poke() {
3791 var now = clock.now(), delay = now - clockLast;
3792 if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
3793}
3794
3795function nap() {
3796 var t0, t1 = taskHead, t2, time = Infinity;
3797 while (t1) {
3798 if (t1._call) {
3799 if (time > t1._time) time = t1._time;
3800 t0 = t1, t1 = t1._next;
3801 } else {
3802 t2 = t1._next, t1._next = null;
3803 t1 = t0 ? t0._next = t2 : taskHead = t2;
3804 }
3805 }
3806 taskTail = t0;
3807 sleep(time);
3808}
3809
3810function sleep(time) {
3811 if (frame) return; // Soonest alarm already set, or will be.
3812 if (timeout$1) timeout$1 = clearTimeout(timeout$1);
3813 var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
3814 if (delay > 24) {
3815 if (time < Infinity) timeout$1 = setTimeout(wake, time - clock.now() - clockSkew);
3816 if (interval$1) interval$1 = clearInterval(interval$1);
3817 } else {
3818 if (!interval$1) clockLast = clock.now(), interval$1 = setInterval(poke, pokeDelay);
3819 frame = 1, setFrame(wake);
3820 }
3821}
3822
3823function timeout(callback, delay, time) {
3824 var t = new Timer;
3825 delay = delay == null ? 0 : +delay;
3826 t.restart(elapsed => {
3827 t.stop();
3828 callback(elapsed + delay);
3829 }, delay, time);
3830 return t;
3831}
3832
3833function interval(callback, delay, time) {
3834 var t = new Timer, total = delay;
3835 if (delay == null) return t.restart(callback, delay, time), t;
3836 t._restart = t.restart;
3837 t.restart = function(callback, delay, time) {
3838 delay = +delay, time = time == null ? now() : +time;
3839 t._restart(function tick(elapsed) {
3840 elapsed += total;
3841 t._restart(tick, total += delay, time);
3842 callback(elapsed);
3843 }, delay, time);
3844 };
3845 t.restart(callback, delay, time);
3846 return t;
3847}
3848
3849var emptyOn = dispatch("start", "end", "cancel", "interrupt");
3850var emptyTween = [];
3851
3852var CREATED = 0;
3853var SCHEDULED = 1;
3854var STARTING = 2;
3855var STARTED = 3;
3856var RUNNING = 4;
3857var ENDING = 5;
3858var ENDED = 6;
3859
3860function schedule(node, name, id, index, group, timing) {
3861 var schedules = node.__transition;
3862 if (!schedules) node.__transition = {};
3863 else if (id in schedules) return;
3864 create(node, id, {
3865 name: name,
3866 index: index, // For context during callback.
3867 group: group, // For context during callback.
3868 on: emptyOn,
3869 tween: emptyTween,
3870 time: timing.time,
3871 delay: timing.delay,
3872 duration: timing.duration,
3873 ease: timing.ease,
3874 timer: null,
3875 state: CREATED
3876 });
3877}
3878
3879function init(node, id) {
3880 var schedule = get(node, id);
3881 if (schedule.state > CREATED) throw new Error("too late; already scheduled");
3882 return schedule;
3883}
3884
3885function set(node, id) {
3886 var schedule = get(node, id);
3887 if (schedule.state > STARTED) throw new Error("too late; already running");
3888 return schedule;
3889}
3890
3891function get(node, id) {
3892 var schedule = node.__transition;
3893 if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
3894 return schedule;
3895}
3896
3897function create(node, id, self) {
3898 var schedules = node.__transition,
3899 tween;
3900
3901 // Initialize the self timer when the transition is created.
3902 // Note the actual delay is not known until the first callback!
3903 schedules[id] = self;
3904 self.timer = timer(schedule, 0, self.time);
3905
3906 function schedule(elapsed) {
3907 self.state = SCHEDULED;
3908 self.timer.restart(start, self.delay, self.time);
3909
3910 // If the elapsed delay is less than our first sleep, start immediately.
3911 if (self.delay <= elapsed) start(elapsed - self.delay);
3912 }
3913
3914 function start(elapsed) {
3915 var i, j, n, o;
3916
3917 // If the state is not SCHEDULED, then we previously errored on start.
3918 if (self.state !== SCHEDULED) return stop();
3919
3920 for (i in schedules) {
3921 o = schedules[i];
3922 if (o.name !== self.name) continue;
3923
3924 // While this element already has a starting transition during this frame,
3925 // defer starting an interrupting transition until that transition has a
3926 // chance to tick (and possibly end); see d3/d3-transition#54!
3927 if (o.state === STARTED) return timeout(start);
3928
3929 // Interrupt the active transition, if any.
3930 if (o.state === RUNNING) {
3931 o.state = ENDED;
3932 o.timer.stop();
3933 o.on.call("interrupt", node, node.__data__, o.index, o.group);
3934 delete schedules[i];
3935 }
3936
3937 // Cancel any pre-empted transitions.
3938 else if (+i < id) {
3939 o.state = ENDED;
3940 o.timer.stop();
3941 o.on.call("cancel", node, node.__data__, o.index, o.group);
3942 delete schedules[i];
3943 }
3944 }
3945
3946 // Defer the first tick to end of the current frame; see d3/d3#1576.
3947 // Note the transition may be canceled after start and before the first tick!
3948 // Note this must be scheduled before the start event; see d3/d3-transition#16!
3949 // Assuming this is successful, subsequent callbacks go straight to tick.
3950 timeout(function() {
3951 if (self.state === STARTED) {
3952 self.state = RUNNING;
3953 self.timer.restart(tick, self.delay, self.time);
3954 tick(elapsed);
3955 }
3956 });
3957
3958 // Dispatch the start event.
3959 // Note this must be done before the tween are initialized.
3960 self.state = STARTING;
3961 self.on.call("start", node, node.__data__, self.index, self.group);
3962 if (self.state !== STARTING) return; // interrupted
3963 self.state = STARTED;
3964
3965 // Initialize the tween, deleting null tween.
3966 tween = new Array(n = self.tween.length);
3967 for (i = 0, j = -1; i < n; ++i) {
3968 if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
3969 tween[++j] = o;
3970 }
3971 }
3972 tween.length = j + 1;
3973 }
3974
3975 function tick(elapsed) {
3976 var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
3977 i = -1,
3978 n = tween.length;
3979
3980 while (++i < n) {
3981 tween[i].call(node, t);
3982 }
3983
3984 // Dispatch the end event.
3985 if (self.state === ENDING) {
3986 self.on.call("end", node, node.__data__, self.index, self.group);
3987 stop();
3988 }
3989 }
3990
3991 function stop() {
3992 self.state = ENDED;
3993 self.timer.stop();
3994 delete schedules[id];
3995 for (var i in schedules) return; // eslint-disable-line no-unused-vars
3996 delete node.__transition;
3997 }
3998}
3999
4000function interrupt(node, name) {
4001 var schedules = node.__transition,
4002 schedule,
4003 active,
4004 empty = true,
4005 i;
4006
4007 if (!schedules) return;
4008
4009 name = name == null ? null : name + "";
4010
4011 for (i in schedules) {
4012 if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
4013 active = schedule.state > STARTING && schedule.state < ENDING;
4014 schedule.state = ENDED;
4015 schedule.timer.stop();
4016 schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
4017 delete schedules[i];
4018 }
4019
4020 if (empty) delete node.__transition;
4021}
4022
4023function selection_interrupt(name) {
4024 return this.each(function() {
4025 interrupt(this, name);
4026 });
4027}
4028
4029function tweenRemove(id, name) {
4030 var tween0, tween1;
4031 return function() {
4032 var schedule = set(this, id),
4033 tween = schedule.tween;
4034
4035 // If this node shared tween with the previous node,
4036 // just assign the updated shared tween and we’re done!
4037 // Otherwise, copy-on-write.
4038 if (tween !== tween0) {
4039 tween1 = tween0 = tween;
4040 for (var i = 0, n = tween1.length; i < n; ++i) {
4041 if (tween1[i].name === name) {
4042 tween1 = tween1.slice();
4043 tween1.splice(i, 1);
4044 break;
4045 }
4046 }
4047 }
4048
4049 schedule.tween = tween1;
4050 };
4051}
4052
4053function tweenFunction(id, name, value) {
4054 var tween0, tween1;
4055 if (typeof value !== "function") throw new Error;
4056 return function() {
4057 var schedule = set(this, id),
4058 tween = schedule.tween;
4059
4060 // If this node shared tween with the previous node,
4061 // just assign the updated shared tween and we’re done!
4062 // Otherwise, copy-on-write.
4063 if (tween !== tween0) {
4064 tween1 = (tween0 = tween).slice();
4065 for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
4066 if (tween1[i].name === name) {
4067 tween1[i] = t;
4068 break;
4069 }
4070 }
4071 if (i === n) tween1.push(t);
4072 }
4073
4074 schedule.tween = tween1;
4075 };
4076}
4077
4078function transition_tween(name, value) {
4079 var id = this._id;
4080
4081 name += "";
4082
4083 if (arguments.length < 2) {
4084 var tween = get(this.node(), id).tween;
4085 for (var i = 0, n = tween.length, t; i < n; ++i) {
4086 if ((t = tween[i]).name === name) {
4087 return t.value;
4088 }
4089 }
4090 return null;
4091 }
4092
4093 return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
4094}
4095
4096function tweenValue(transition, name, value) {
4097 var id = transition._id;
4098
4099 transition.each(function() {
4100 var schedule = set(this, id);
4101 (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
4102 });
4103
4104 return function(node) {
4105 return get(node, id).value[name];
4106 };
4107}
4108
4109function interpolate$1(a, b) {
4110 var c;
4111 return (typeof b === "number" ? interpolateNumber
4112 : b instanceof color ? interpolateRgb
4113 : (c = color(b)) ? (b = c, interpolateRgb)
4114 : interpolateString)(a, b);
4115}
4116
4117function attrRemove(name) {
4118 return function() {
4119 this.removeAttribute(name);
4120 };
4121}
4122
4123function attrRemoveNS(fullname) {
4124 return function() {
4125 this.removeAttributeNS(fullname.space, fullname.local);
4126 };
4127}
4128
4129function attrConstant(name, interpolate, value1) {
4130 var string00,
4131 string1 = value1 + "",
4132 interpolate0;
4133 return function() {
4134 var string0 = this.getAttribute(name);
4135 return string0 === string1 ? null
4136 : string0 === string00 ? interpolate0
4137 : interpolate0 = interpolate(string00 = string0, value1);
4138 };
4139}
4140
4141function attrConstantNS(fullname, interpolate, value1) {
4142 var string00,
4143 string1 = value1 + "",
4144 interpolate0;
4145 return function() {
4146 var string0 = this.getAttributeNS(fullname.space, fullname.local);
4147 return string0 === string1 ? null
4148 : string0 === string00 ? interpolate0
4149 : interpolate0 = interpolate(string00 = string0, value1);
4150 };
4151}
4152
4153function attrFunction(name, interpolate, value) {
4154 var string00,
4155 string10,
4156 interpolate0;
4157 return function() {
4158 var string0, value1 = value(this), string1;
4159 if (value1 == null) return void this.removeAttribute(name);
4160 string0 = this.getAttribute(name);
4161 string1 = value1 + "";
4162 return string0 === string1 ? null
4163 : string0 === string00 && string1 === string10 ? interpolate0
4164 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
4165 };
4166}
4167
4168function attrFunctionNS(fullname, interpolate, value) {
4169 var string00,
4170 string10,
4171 interpolate0;
4172 return function() {
4173 var string0, value1 = value(this), string1;
4174 if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
4175 string0 = this.getAttributeNS(fullname.space, fullname.local);
4176 string1 = value1 + "";
4177 return string0 === string1 ? null
4178 : string0 === string00 && string1 === string10 ? interpolate0
4179 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
4180 };
4181}
4182
4183function transition_attr(name, value) {
4184 var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
4185 return this.attrTween(name, typeof value === "function"
4186 ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value))
4187 : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname)
4188 : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value));
4189}
4190
4191function attrInterpolate(name, i) {
4192 return function(t) {
4193 this.setAttribute(name, i.call(this, t));
4194 };
4195}
4196
4197function attrInterpolateNS(fullname, i) {
4198 return function(t) {
4199 this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
4200 };
4201}
4202
4203function attrTweenNS(fullname, value) {
4204 var t0, i0;
4205 function tween() {
4206 var i = value.apply(this, arguments);
4207 if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
4208 return t0;
4209 }
4210 tween._value = value;
4211 return tween;
4212}
4213
4214function attrTween(name, value) {
4215 var t0, i0;
4216 function tween() {
4217 var i = value.apply(this, arguments);
4218 if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
4219 return t0;
4220 }
4221 tween._value = value;
4222 return tween;
4223}
4224
4225function transition_attrTween(name, value) {
4226 var key = "attr." + name;
4227 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
4228 if (value == null) return this.tween(key, null);
4229 if (typeof value !== "function") throw new Error;
4230 var fullname = namespace(name);
4231 return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
4232}
4233
4234function delayFunction(id, value) {
4235 return function() {
4236 init(this, id).delay = +value.apply(this, arguments);
4237 };
4238}
4239
4240function delayConstant(id, value) {
4241 return value = +value, function() {
4242 init(this, id).delay = value;
4243 };
4244}
4245
4246function transition_delay(value) {
4247 var id = this._id;
4248
4249 return arguments.length
4250 ? this.each((typeof value === "function"
4251 ? delayFunction
4252 : delayConstant)(id, value))
4253 : get(this.node(), id).delay;
4254}
4255
4256function durationFunction(id, value) {
4257 return function() {
4258 set(this, id).duration = +value.apply(this, arguments);
4259 };
4260}
4261
4262function durationConstant(id, value) {
4263 return value = +value, function() {
4264 set(this, id).duration = value;
4265 };
4266}
4267
4268function transition_duration(value) {
4269 var id = this._id;
4270
4271 return arguments.length
4272 ? this.each((typeof value === "function"
4273 ? durationFunction
4274 : durationConstant)(id, value))
4275 : get(this.node(), id).duration;
4276}
4277
4278function easeConstant(id, value) {
4279 if (typeof value !== "function") throw new Error;
4280 return function() {
4281 set(this, id).ease = value;
4282 };
4283}
4284
4285function transition_ease(value) {
4286 var id = this._id;
4287
4288 return arguments.length
4289 ? this.each(easeConstant(id, value))
4290 : get(this.node(), id).ease;
4291}
4292
4293function easeVarying(id, value) {
4294 return function() {
4295 var v = value.apply(this, arguments);
4296 if (typeof v !== "function") throw new Error;
4297 set(this, id).ease = v;
4298 };
4299}
4300
4301function transition_easeVarying(value) {
4302 if (typeof value !== "function") throw new Error;
4303 return this.each(easeVarying(this._id, value));
4304}
4305
4306function transition_filter(match) {
4307 if (typeof match !== "function") match = matcher(match);
4308
4309 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
4310 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
4311 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
4312 subgroup.push(node);
4313 }
4314 }
4315 }
4316
4317 return new Transition(subgroups, this._parents, this._name, this._id);
4318}
4319
4320function transition_merge(transition) {
4321 if (transition._id !== this._id) throw new Error;
4322
4323 for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
4324 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
4325 if (node = group0[i] || group1[i]) {
4326 merge[i] = node;
4327 }
4328 }
4329 }
4330
4331 for (; j < m0; ++j) {
4332 merges[j] = groups0[j];
4333 }
4334
4335 return new Transition(merges, this._parents, this._name, this._id);
4336}
4337
4338function start(name) {
4339 return (name + "").trim().split(/^|\s+/).every(function(t) {
4340 var i = t.indexOf(".");
4341 if (i >= 0) t = t.slice(0, i);
4342 return !t || t === "start";
4343 });
4344}
4345
4346function onFunction(id, name, listener) {
4347 var on0, on1, sit = start(name) ? init : set;
4348 return function() {
4349 var schedule = sit(this, id),
4350 on = schedule.on;
4351
4352 // If this node shared a dispatch with the previous node,
4353 // just assign the updated shared dispatch and we’re done!
4354 // Otherwise, copy-on-write.
4355 if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
4356
4357 schedule.on = on1;
4358 };
4359}
4360
4361function transition_on(name, listener) {
4362 var id = this._id;
4363
4364 return arguments.length < 2
4365 ? get(this.node(), id).on.on(name)
4366 : this.each(onFunction(id, name, listener));
4367}
4368
4369function removeFunction(id) {
4370 return function() {
4371 var parent = this.parentNode;
4372 for (var i in this.__transition) if (+i !== id) return;
4373 if (parent) parent.removeChild(this);
4374 };
4375}
4376
4377function transition_remove() {
4378 return this.on("end.remove", removeFunction(this._id));
4379}
4380
4381function transition_select(select) {
4382 var name = this._name,
4383 id = this._id;
4384
4385 if (typeof select !== "function") select = selector(select);
4386
4387 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
4388 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
4389 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
4390 if ("__data__" in node) subnode.__data__ = node.__data__;
4391 subgroup[i] = subnode;
4392 schedule(subgroup[i], name, id, i, subgroup, get(node, id));
4393 }
4394 }
4395 }
4396
4397 return new Transition(subgroups, this._parents, name, id);
4398}
4399
4400function transition_selectAll(select) {
4401 var name = this._name,
4402 id = this._id;
4403
4404 if (typeof select !== "function") select = selectorAll(select);
4405
4406 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
4407 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4408 if (node = group[i]) {
4409 for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) {
4410 if (child = children[k]) {
4411 schedule(child, name, id, k, children, inherit);
4412 }
4413 }
4414 subgroups.push(children);
4415 parents.push(node);
4416 }
4417 }
4418 }
4419
4420 return new Transition(subgroups, parents, name, id);
4421}
4422
4423var Selection = selection.prototype.constructor;
4424
4425function transition_selection() {
4426 return new Selection(this._groups, this._parents);
4427}
4428
4429function styleNull(name, interpolate) {
4430 var string00,
4431 string10,
4432 interpolate0;
4433 return function() {
4434 var string0 = styleValue(this, name),
4435 string1 = (this.style.removeProperty(name), styleValue(this, name));
4436 return string0 === string1 ? null
4437 : string0 === string00 && string1 === string10 ? interpolate0
4438 : interpolate0 = interpolate(string00 = string0, string10 = string1);
4439 };
4440}
4441
4442function styleRemove(name) {
4443 return function() {
4444 this.style.removeProperty(name);
4445 };
4446}
4447
4448function styleConstant(name, interpolate, value1) {
4449 var string00,
4450 string1 = value1 + "",
4451 interpolate0;
4452 return function() {
4453 var string0 = styleValue(this, name);
4454 return string0 === string1 ? null
4455 : string0 === string00 ? interpolate0
4456 : interpolate0 = interpolate(string00 = string0, value1);
4457 };
4458}
4459
4460function styleFunction(name, interpolate, value) {
4461 var string00,
4462 string10,
4463 interpolate0;
4464 return function() {
4465 var string0 = styleValue(this, name),
4466 value1 = value(this),
4467 string1 = value1 + "";
4468 if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
4469 return string0 === string1 ? null
4470 : string0 === string00 && string1 === string10 ? interpolate0
4471 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
4472 };
4473}
4474
4475function styleMaybeRemove(id, name) {
4476 var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
4477 return function() {
4478 var schedule = set(this, id),
4479 on = schedule.on,
4480 listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;
4481
4482 // If this node shared a dispatch with the previous node,
4483 // just assign the updated shared dispatch and we’re done!
4484 // Otherwise, copy-on-write.
4485 if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
4486
4487 schedule.on = on1;
4488 };
4489}
4490
4491function transition_style(name, value, priority) {
4492 var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
4493 return value == null ? this
4494 .styleTween(name, styleNull(name, i))
4495 .on("end.style." + name, styleRemove(name))
4496 : typeof value === "function" ? this
4497 .styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value)))
4498 .each(styleMaybeRemove(this._id, name))
4499 : this
4500 .styleTween(name, styleConstant(name, i, value), priority)
4501 .on("end.style." + name, null);
4502}
4503
4504function styleInterpolate(name, i, priority) {
4505 return function(t) {
4506 this.style.setProperty(name, i.call(this, t), priority);
4507 };
4508}
4509
4510function styleTween(name, value, priority) {
4511 var t, i0;
4512 function tween() {
4513 var i = value.apply(this, arguments);
4514 if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
4515 return t;
4516 }
4517 tween._value = value;
4518 return tween;
4519}
4520
4521function transition_styleTween(name, value, priority) {
4522 var key = "style." + (name += "");
4523 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
4524 if (value == null) return this.tween(key, null);
4525 if (typeof value !== "function") throw new Error;
4526 return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
4527}
4528
4529function textConstant(value) {
4530 return function() {
4531 this.textContent = value;
4532 };
4533}
4534
4535function textFunction(value) {
4536 return function() {
4537 var value1 = value(this);
4538 this.textContent = value1 == null ? "" : value1;
4539 };
4540}
4541
4542function transition_text(value) {
4543 return this.tween("text", typeof value === "function"
4544 ? textFunction(tweenValue(this, "text", value))
4545 : textConstant(value == null ? "" : value + ""));
4546}
4547
4548function textInterpolate(i) {
4549 return function(t) {
4550 this.textContent = i.call(this, t);
4551 };
4552}
4553
4554function textTween(value) {
4555 var t0, i0;
4556 function tween() {
4557 var i = value.apply(this, arguments);
4558 if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
4559 return t0;
4560 }
4561 tween._value = value;
4562 return tween;
4563}
4564
4565function transition_textTween(value) {
4566 var key = "text";
4567 if (arguments.length < 1) return (key = this.tween(key)) && key._value;
4568 if (value == null) return this.tween(key, null);
4569 if (typeof value !== "function") throw new Error;
4570 return this.tween(key, textTween(value));
4571}
4572
4573function transition_transition() {
4574 var name = this._name,
4575 id0 = this._id,
4576 id1 = newId();
4577
4578 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4579 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4580 if (node = group[i]) {
4581 var inherit = get(node, id0);
4582 schedule(node, name, id1, i, group, {
4583 time: inherit.time + inherit.delay + inherit.duration,
4584 delay: 0,
4585 duration: inherit.duration,
4586 ease: inherit.ease
4587 });
4588 }
4589 }
4590 }
4591
4592 return new Transition(groups, this._parents, name, id1);
4593}
4594
4595function transition_end() {
4596 var on0, on1, that = this, id = that._id, size = that.size();
4597 return new Promise(function(resolve, reject) {
4598 var cancel = {value: reject},
4599 end = {value: function() { if (--size === 0) resolve(); }};
4600
4601 that.each(function() {
4602 var schedule = set(this, id),
4603 on = schedule.on;
4604
4605 // If this node shared a dispatch with the previous node,
4606 // just assign the updated shared dispatch and we’re done!
4607 // Otherwise, copy-on-write.
4608 if (on !== on0) {
4609 on1 = (on0 = on).copy();
4610 on1._.cancel.push(cancel);
4611 on1._.interrupt.push(cancel);
4612 on1._.end.push(end);
4613 }
4614
4615 schedule.on = on1;
4616 });
4617
4618 // The selection was empty, resolve end immediately
4619 if (size === 0) resolve();
4620 });
4621}
4622
4623var id = 0;
4624
4625function Transition(groups, parents, name, id) {
4626 this._groups = groups;
4627 this._parents = parents;
4628 this._name = name;
4629 this._id = id;
4630}
4631
4632function transition(name) {
4633 return selection().transition(name);
4634}
4635
4636function newId() {
4637 return ++id;
4638}
4639
4640var selection_prototype = selection.prototype;
4641
4642Transition.prototype = transition.prototype = {
4643 constructor: Transition,
4644 select: transition_select,
4645 selectAll: transition_selectAll,
4646 filter: transition_filter,
4647 merge: transition_merge,
4648 selection: transition_selection,
4649 transition: transition_transition,
4650 call: selection_prototype.call,
4651 nodes: selection_prototype.nodes,
4652 node: selection_prototype.node,
4653 size: selection_prototype.size,
4654 empty: selection_prototype.empty,
4655 each: selection_prototype.each,
4656 on: transition_on,
4657 attr: transition_attr,
4658 attrTween: transition_attrTween,
4659 style: transition_style,
4660 styleTween: transition_styleTween,
4661 text: transition_text,
4662 textTween: transition_textTween,
4663 remove: transition_remove,
4664 tween: transition_tween,
4665 delay: transition_delay,
4666 duration: transition_duration,
4667 ease: transition_ease,
4668 easeVarying: transition_easeVarying,
4669 end: transition_end,
4670 [Symbol.iterator]: selection_prototype[Symbol.iterator]
4671};
4672
4673const linear$1 = t => +t;
4674
4675function quadIn(t) {
4676 return t * t;
4677}
4678
4679function quadOut(t) {
4680 return t * (2 - t);
4681}
4682
4683function quadInOut(t) {
4684 return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
4685}
4686
4687function cubicIn(t) {
4688 return t * t * t;
4689}
4690
4691function cubicOut(t) {
4692 return --t * t * t + 1;
4693}
4694
4695function cubicInOut(t) {
4696 return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
4697}
4698
4699var exponent$1 = 3;
4700
4701var polyIn = (function custom(e) {
4702 e = +e;
4703
4704 function polyIn(t) {
4705 return Math.pow(t, e);
4706 }
4707
4708 polyIn.exponent = custom;
4709
4710 return polyIn;
4711})(exponent$1);
4712
4713var polyOut = (function custom(e) {
4714 e = +e;
4715
4716 function polyOut(t) {
4717 return 1 - Math.pow(1 - t, e);
4718 }
4719
4720 polyOut.exponent = custom;
4721
4722 return polyOut;
4723})(exponent$1);
4724
4725var polyInOut = (function custom(e) {
4726 e = +e;
4727
4728 function polyInOut(t) {
4729 return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
4730 }
4731
4732 polyInOut.exponent = custom;
4733
4734 return polyInOut;
4735})(exponent$1);
4736
4737var pi$4 = Math.PI,
4738 halfPi$3 = pi$4 / 2;
4739
4740function sinIn(t) {
4741 return (+t === 1) ? 1 : 1 - Math.cos(t * halfPi$3);
4742}
4743
4744function sinOut(t) {
4745 return Math.sin(t * halfPi$3);
4746}
4747
4748function sinInOut(t) {
4749 return (1 - Math.cos(pi$4 * t)) / 2;
4750}
4751
4752// tpmt is two power minus ten times t scaled to [0,1]
4753function tpmt(x) {
4754 return (Math.pow(2, -10 * x) - 0.0009765625) * 1.0009775171065494;
4755}
4756
4757function expIn(t) {
4758 return tpmt(1 - +t);
4759}
4760
4761function expOut(t) {
4762 return 1 - tpmt(t);
4763}
4764
4765function expInOut(t) {
4766 return ((t *= 2) <= 1 ? tpmt(1 - t) : 2 - tpmt(t - 1)) / 2;
4767}
4768
4769function circleIn(t) {
4770 return 1 - Math.sqrt(1 - t * t);
4771}
4772
4773function circleOut(t) {
4774 return Math.sqrt(1 - --t * t);
4775}
4776
4777function circleInOut(t) {
4778 return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
4779}
4780
4781var b1 = 4 / 11,
4782 b2 = 6 / 11,
4783 b3 = 8 / 11,
4784 b4 = 3 / 4,
4785 b5 = 9 / 11,
4786 b6 = 10 / 11,
4787 b7 = 15 / 16,
4788 b8 = 21 / 22,
4789 b9 = 63 / 64,
4790 b0 = 1 / b1 / b1;
4791
4792function bounceIn(t) {
4793 return 1 - bounceOut(1 - t);
4794}
4795
4796function bounceOut(t) {
4797 return (t = +t) < b1 ? b0 * t * t : t < b3 ? b0 * (t -= b2) * t + b4 : t < b6 ? b0 * (t -= b5) * t + b7 : b0 * (t -= b8) * t + b9;
4798}
4799
4800function bounceInOut(t) {
4801 return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
4802}
4803
4804var overshoot = 1.70158;
4805
4806var backIn = (function custom(s) {
4807 s = +s;
4808
4809 function backIn(t) {
4810 return (t = +t) * t * (s * (t - 1) + t);
4811 }
4812
4813 backIn.overshoot = custom;
4814
4815 return backIn;
4816})(overshoot);
4817
4818var backOut = (function custom(s) {
4819 s = +s;
4820
4821 function backOut(t) {
4822 return --t * t * ((t + 1) * s + t) + 1;
4823 }
4824
4825 backOut.overshoot = custom;
4826
4827 return backOut;
4828})(overshoot);
4829
4830var backInOut = (function custom(s) {
4831 s = +s;
4832
4833 function backInOut(t) {
4834 return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
4835 }
4836
4837 backInOut.overshoot = custom;
4838
4839 return backInOut;
4840})(overshoot);
4841
4842var tau$5 = 2 * Math.PI,
4843 amplitude = 1,
4844 period = 0.3;
4845
4846var elasticIn = (function custom(a, p) {
4847 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
4848
4849 function elasticIn(t) {
4850 return a * tpmt(-(--t)) * Math.sin((s - t) / p);
4851 }
4852
4853 elasticIn.amplitude = function(a) { return custom(a, p * tau$5); };
4854 elasticIn.period = function(p) { return custom(a, p); };
4855
4856 return elasticIn;
4857})(amplitude, period);
4858
4859var elasticOut = (function custom(a, p) {
4860 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
4861
4862 function elasticOut(t) {
4863 return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p);
4864 }
4865
4866 elasticOut.amplitude = function(a) { return custom(a, p * tau$5); };
4867 elasticOut.period = function(p) { return custom(a, p); };
4868
4869 return elasticOut;
4870})(amplitude, period);
4871
4872var elasticInOut = (function custom(a, p) {
4873 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
4874
4875 function elasticInOut(t) {
4876 return ((t = t * 2 - 1) < 0
4877 ? a * tpmt(-t) * Math.sin((s - t) / p)
4878 : 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2;
4879 }
4880
4881 elasticInOut.amplitude = function(a) { return custom(a, p * tau$5); };
4882 elasticInOut.period = function(p) { return custom(a, p); };
4883
4884 return elasticInOut;
4885})(amplitude, period);
4886
4887var defaultTiming = {
4888 time: null, // Set on use.
4889 delay: 0,
4890 duration: 250,
4891 ease: cubicInOut
4892};
4893
4894function inherit(node, id) {
4895 var timing;
4896 while (!(timing = node.__transition) || !(timing = timing[id])) {
4897 if (!(node = node.parentNode)) {
4898 throw new Error(`transition ${id} not found`);
4899 }
4900 }
4901 return timing;
4902}
4903
4904function selection_transition(name) {
4905 var id,
4906 timing;
4907
4908 if (name instanceof Transition) {
4909 id = name._id, name = name._name;
4910 } else {
4911 id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
4912 }
4913
4914 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4915 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4916 if (node = group[i]) {
4917 schedule(node, name, id, i, group, timing || inherit(node, id));
4918 }
4919 }
4920 }
4921
4922 return new Transition(groups, this._parents, name, id);
4923}
4924
4925selection.prototype.interrupt = selection_interrupt;
4926selection.prototype.transition = selection_transition;
4927
4928var root = [null];
4929
4930function active(node, name) {
4931 var schedules = node.__transition,
4932 schedule,
4933 i;
4934
4935 if (schedules) {
4936 name = name == null ? null : name + "";
4937 for (i in schedules) {
4938 if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
4939 return new Transition([[node]], root, name, +i);
4940 }
4941 }
4942 }
4943
4944 return null;
4945}
4946
4947var constant$7 = x => () => x;
4948
4949function BrushEvent(type, {
4950 sourceEvent,
4951 target,
4952 selection,
4953 mode,
4954 dispatch
4955}) {
4956 Object.defineProperties(this, {
4957 type: {value: type, enumerable: true, configurable: true},
4958 sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
4959 target: {value: target, enumerable: true, configurable: true},
4960 selection: {value: selection, enumerable: true, configurable: true},
4961 mode: {value: mode, enumerable: true, configurable: true},
4962 _: {value: dispatch}
4963 });
4964}
4965
4966function nopropagation$1(event) {
4967 event.stopImmediatePropagation();
4968}
4969
4970function noevent$1(event) {
4971 event.preventDefault();
4972 event.stopImmediatePropagation();
4973}
4974
4975var MODE_DRAG = {name: "drag"},
4976 MODE_SPACE = {name: "space"},
4977 MODE_HANDLE = {name: "handle"},
4978 MODE_CENTER = {name: "center"};
4979
4980const {abs: abs$3, max: max$2, min: min$1} = Math;
4981
4982function number1(e) {
4983 return [+e[0], +e[1]];
4984}
4985
4986function number2(e) {
4987 return [number1(e[0]), number1(e[1])];
4988}
4989
4990var X = {
4991 name: "x",
4992 handles: ["w", "e"].map(type),
4993 input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
4994 output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
4995};
4996
4997var Y = {
4998 name: "y",
4999 handles: ["n", "s"].map(type),
5000 input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
5001 output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
5002};
5003
5004var XY = {
5005 name: "xy",
5006 handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
5007 input: function(xy) { return xy == null ? null : number2(xy); },
5008 output: function(xy) { return xy; }
5009};
5010
5011var cursors = {
5012 overlay: "crosshair",
5013 selection: "move",
5014 n: "ns-resize",
5015 e: "ew-resize",
5016 s: "ns-resize",
5017 w: "ew-resize",
5018 nw: "nwse-resize",
5019 ne: "nesw-resize",
5020 se: "nwse-resize",
5021 sw: "nesw-resize"
5022};
5023
5024var flipX = {
5025 e: "w",
5026 w: "e",
5027 nw: "ne",
5028 ne: "nw",
5029 se: "sw",
5030 sw: "se"
5031};
5032
5033var flipY = {
5034 n: "s",
5035 s: "n",
5036 nw: "sw",
5037 ne: "se",
5038 se: "ne",
5039 sw: "nw"
5040};
5041
5042var signsX = {
5043 overlay: +1,
5044 selection: +1,
5045 n: null,
5046 e: +1,
5047 s: null,
5048 w: -1,
5049 nw: -1,
5050 ne: +1,
5051 se: +1,
5052 sw: -1
5053};
5054
5055var signsY = {
5056 overlay: +1,
5057 selection: +1,
5058 n: -1,
5059 e: null,
5060 s: +1,
5061 w: null,
5062 nw: -1,
5063 ne: -1,
5064 se: +1,
5065 sw: +1
5066};
5067
5068function type(t) {
5069 return {type: t};
5070}
5071
5072// Ignore right-click, since that should open the context menu.
5073function defaultFilter$1(event) {
5074 return !event.ctrlKey && !event.button;
5075}
5076
5077function defaultExtent$1() {
5078 var svg = this.ownerSVGElement || this;
5079 if (svg.hasAttribute("viewBox")) {
5080 svg = svg.viewBox.baseVal;
5081 return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
5082 }
5083 return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
5084}
5085
5086function defaultTouchable$1() {
5087 return navigator.maxTouchPoints || ("ontouchstart" in this);
5088}
5089
5090// Like d3.local, but with the name “__brush” rather than auto-generated.
5091function local(node) {
5092 while (!node.__brush) if (!(node = node.parentNode)) return;
5093 return node.__brush;
5094}
5095
5096function empty(extent) {
5097 return extent[0][0] === extent[1][0]
5098 || extent[0][1] === extent[1][1];
5099}
5100
5101function brushSelection(node) {
5102 var state = node.__brush;
5103 return state ? state.dim.output(state.selection) : null;
5104}
5105
5106function brushX() {
5107 return brush$1(X);
5108}
5109
5110function brushY() {
5111 return brush$1(Y);
5112}
5113
5114function brush() {
5115 return brush$1(XY);
5116}
5117
5118function brush$1(dim) {
5119 var extent = defaultExtent$1,
5120 filter = defaultFilter$1,
5121 touchable = defaultTouchable$1,
5122 keys = true,
5123 listeners = dispatch("start", "brush", "end"),
5124 handleSize = 6,
5125 touchending;
5126
5127 function brush(group) {
5128 var overlay = group
5129 .property("__brush", initialize)
5130 .selectAll(".overlay")
5131 .data([type("overlay")]);
5132
5133 overlay.enter().append("rect")
5134 .attr("class", "overlay")
5135 .attr("pointer-events", "all")
5136 .attr("cursor", cursors.overlay)
5137 .merge(overlay)
5138 .each(function() {
5139 var extent = local(this).extent;
5140 select(this)
5141 .attr("x", extent[0][0])
5142 .attr("y", extent[0][1])
5143 .attr("width", extent[1][0] - extent[0][0])
5144 .attr("height", extent[1][1] - extent[0][1]);
5145 });
5146
5147 group.selectAll(".selection")
5148 .data([type("selection")])
5149 .enter().append("rect")
5150 .attr("class", "selection")
5151 .attr("cursor", cursors.selection)
5152 .attr("fill", "#777")
5153 .attr("fill-opacity", 0.3)
5154 .attr("stroke", "#fff")
5155 .attr("shape-rendering", "crispEdges");
5156
5157 var handle = group.selectAll(".handle")
5158 .data(dim.handles, function(d) { return d.type; });
5159
5160 handle.exit().remove();
5161
5162 handle.enter().append("rect")
5163 .attr("class", function(d) { return "handle handle--" + d.type; })
5164 .attr("cursor", function(d) { return cursors[d.type]; });
5165
5166 group
5167 .each(redraw)
5168 .attr("fill", "none")
5169 .attr("pointer-events", "all")
5170 .on("mousedown.brush", started)
5171 .filter(touchable)
5172 .on("touchstart.brush", started)
5173 .on("touchmove.brush", touchmoved)
5174 .on("touchend.brush touchcancel.brush", touchended)
5175 .style("touch-action", "none")
5176 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
5177 }
5178
5179 brush.move = function(group, selection) {
5180 if (group.tween) {
5181 group
5182 .on("start.brush", function(event) { emitter(this, arguments).beforestart().start(event); })
5183 .on("interrupt.brush end.brush", function(event) { emitter(this, arguments).end(event); })
5184 .tween("brush", function() {
5185 var that = this,
5186 state = that.__brush,
5187 emit = emitter(that, arguments),
5188 selection0 = state.selection,
5189 selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
5190 i = interpolate$2(selection0, selection1);
5191
5192 function tween(t) {
5193 state.selection = t === 1 && selection1 === null ? null : i(t);
5194 redraw.call(that);
5195 emit.brush();
5196 }
5197
5198 return selection0 !== null && selection1 !== null ? tween : tween(1);
5199 });
5200 } else {
5201 group
5202 .each(function() {
5203 var that = this,
5204 args = arguments,
5205 state = that.__brush,
5206 selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
5207 emit = emitter(that, args).beforestart();
5208
5209 interrupt(that);
5210 state.selection = selection1 === null ? null : selection1;
5211 redraw.call(that);
5212 emit.start().brush().end();
5213 });
5214 }
5215 };
5216
5217 brush.clear = function(group) {
5218 brush.move(group, null);
5219 };
5220
5221 function redraw() {
5222 var group = select(this),
5223 selection = local(this).selection;
5224
5225 if (selection) {
5226 group.selectAll(".selection")
5227 .style("display", null)
5228 .attr("x", selection[0][0])
5229 .attr("y", selection[0][1])
5230 .attr("width", selection[1][0] - selection[0][0])
5231 .attr("height", selection[1][1] - selection[0][1]);
5232
5233 group.selectAll(".handle")
5234 .style("display", null)
5235 .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
5236 .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
5237 .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
5238 .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
5239 }
5240
5241 else {
5242 group.selectAll(".selection,.handle")
5243 .style("display", "none")
5244 .attr("x", null)
5245 .attr("y", null)
5246 .attr("width", null)
5247 .attr("height", null);
5248 }
5249 }
5250
5251 function emitter(that, args, clean) {
5252 var emit = that.__brush.emitter;
5253 return emit && (!clean || !emit.clean) ? emit : new Emitter(that, args, clean);
5254 }
5255
5256 function Emitter(that, args, clean) {
5257 this.that = that;
5258 this.args = args;
5259 this.state = that.__brush;
5260 this.active = 0;
5261 this.clean = clean;
5262 }
5263
5264 Emitter.prototype = {
5265 beforestart: function() {
5266 if (++this.active === 1) this.state.emitter = this, this.starting = true;
5267 return this;
5268 },
5269 start: function(event, mode) {
5270 if (this.starting) this.starting = false, this.emit("start", event, mode);
5271 else this.emit("brush", event);
5272 return this;
5273 },
5274 brush: function(event, mode) {
5275 this.emit("brush", event, mode);
5276 return this;
5277 },
5278 end: function(event, mode) {
5279 if (--this.active === 0) delete this.state.emitter, this.emit("end", event, mode);
5280 return this;
5281 },
5282 emit: function(type, event, mode) {
5283 var d = select(this.that).datum();
5284 listeners.call(
5285 type,
5286 this.that,
5287 new BrushEvent(type, {
5288 sourceEvent: event,
5289 target: brush,
5290 selection: dim.output(this.state.selection),
5291 mode,
5292 dispatch: listeners
5293 }),
5294 d
5295 );
5296 }
5297 };
5298
5299 function started(event) {
5300 if (touchending && !event.touches) return;
5301 if (!filter.apply(this, arguments)) return;
5302
5303 var that = this,
5304 type = event.target.__data__.type,
5305 mode = (keys && event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && event.altKey ? MODE_CENTER : MODE_HANDLE),
5306 signX = dim === Y ? null : signsX[type],
5307 signY = dim === X ? null : signsY[type],
5308 state = local(that),
5309 extent = state.extent,
5310 selection = state.selection,
5311 W = extent[0][0], w0, w1,
5312 N = extent[0][1], n0, n1,
5313 E = extent[1][0], e0, e1,
5314 S = extent[1][1], s0, s1,
5315 dx = 0,
5316 dy = 0,
5317 moving,
5318 shifting = signX && signY && keys && event.shiftKey,
5319 lockX,
5320 lockY,
5321 points = Array.from(event.touches || [event], t => {
5322 const i = t.identifier;
5323 t = pointer(t, that);
5324 t.point0 = t.slice();
5325 t.identifier = i;
5326 return t;
5327 });
5328
5329 if (type === "overlay") {
5330 if (selection) moving = true;
5331 const pts = [points[0], points[1] || points[0]];
5332 state.selection = selection = [[
5333 w0 = dim === Y ? W : min$1(pts[0][0], pts[1][0]),
5334 n0 = dim === X ? N : min$1(pts[0][1], pts[1][1])
5335 ], [
5336 e0 = dim === Y ? E : max$2(pts[0][0], pts[1][0]),
5337 s0 = dim === X ? S : max$2(pts[0][1], pts[1][1])
5338 ]];
5339 if (points.length > 1) move();
5340 } else {
5341 w0 = selection[0][0];
5342 n0 = selection[0][1];
5343 e0 = selection[1][0];
5344 s0 = selection[1][1];
5345 }
5346
5347 w1 = w0;
5348 n1 = n0;
5349 e1 = e0;
5350 s1 = s0;
5351
5352 var group = select(that)
5353 .attr("pointer-events", "none");
5354
5355 var overlay = group.selectAll(".overlay")
5356 .attr("cursor", cursors[type]);
5357
5358 interrupt(that);
5359 var emit = emitter(that, arguments, true).beforestart();
5360
5361 if (event.touches) {
5362 emit.moved = moved;
5363 emit.ended = ended;
5364 } else {
5365 var view = select(event.view)
5366 .on("mousemove.brush", moved, true)
5367 .on("mouseup.brush", ended, true);
5368 if (keys) view
5369 .on("keydown.brush", keydowned, true)
5370 .on("keyup.brush", keyupped, true);
5371
5372 dragDisable(event.view);
5373 }
5374
5375 redraw.call(that);
5376 emit.start(event, mode.name);
5377
5378 function moved(event) {
5379 for (const p of event.changedTouches || [event]) {
5380 for (const d of points)
5381 if (d.identifier === p.identifier) d.cur = pointer(p, that);
5382 }
5383 if (shifting && !lockX && !lockY && points.length === 1) {
5384 const point = points[0];
5385 if (abs$3(point.cur[0] - point[0]) > abs$3(point.cur[1] - point[1]))
5386 lockY = true;
5387 else
5388 lockX = true;
5389 }
5390 for (const point of points)
5391 if (point.cur) point[0] = point.cur[0], point[1] = point.cur[1];
5392 moving = true;
5393 noevent$1(event);
5394 move(event);
5395 }
5396
5397 function move(event) {
5398 const point = points[0], point0 = point.point0;
5399 var t;
5400
5401 dx = point[0] - point0[0];
5402 dy = point[1] - point0[1];
5403
5404 switch (mode) {
5405 case MODE_SPACE:
5406 case MODE_DRAG: {
5407 if (signX) dx = max$2(W - w0, min$1(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
5408 if (signY) dy = max$2(N - n0, min$1(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
5409 break;
5410 }
5411 case MODE_HANDLE: {
5412 if (points[1]) {
5413 if (signX) w1 = max$2(W, min$1(E, points[0][0])), e1 = max$2(W, min$1(E, points[1][0])), signX = 1;
5414 if (signY) n1 = max$2(N, min$1(S, points[0][1])), s1 = max$2(N, min$1(S, points[1][1])), signY = 1;
5415 } else {
5416 if (signX < 0) dx = max$2(W - w0, min$1(E - w0, dx)), w1 = w0 + dx, e1 = e0;
5417 else if (signX > 0) dx = max$2(W - e0, min$1(E - e0, dx)), w1 = w0, e1 = e0 + dx;
5418 if (signY < 0) dy = max$2(N - n0, min$1(S - n0, dy)), n1 = n0 + dy, s1 = s0;
5419 else if (signY > 0) dy = max$2(N - s0, min$1(S - s0, dy)), n1 = n0, s1 = s0 + dy;
5420 }
5421 break;
5422 }
5423 case MODE_CENTER: {
5424 if (signX) w1 = max$2(W, min$1(E, w0 - dx * signX)), e1 = max$2(W, min$1(E, e0 + dx * signX));
5425 if (signY) n1 = max$2(N, min$1(S, n0 - dy * signY)), s1 = max$2(N, min$1(S, s0 + dy * signY));
5426 break;
5427 }
5428 }
5429
5430 if (e1 < w1) {
5431 signX *= -1;
5432 t = w0, w0 = e0, e0 = t;
5433 t = w1, w1 = e1, e1 = t;
5434 if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
5435 }
5436
5437 if (s1 < n1) {
5438 signY *= -1;
5439 t = n0, n0 = s0, s0 = t;
5440 t = n1, n1 = s1, s1 = t;
5441 if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
5442 }
5443
5444 if (state.selection) selection = state.selection; // May be set by brush.move!
5445 if (lockX) w1 = selection[0][0], e1 = selection[1][0];
5446 if (lockY) n1 = selection[0][1], s1 = selection[1][1];
5447
5448 if (selection[0][0] !== w1
5449 || selection[0][1] !== n1
5450 || selection[1][0] !== e1
5451 || selection[1][1] !== s1) {
5452 state.selection = [[w1, n1], [e1, s1]];
5453 redraw.call(that);
5454 emit.brush(event, mode.name);
5455 }
5456 }
5457
5458 function ended(event) {
5459 nopropagation$1(event);
5460 if (event.touches) {
5461 if (event.touches.length) return;
5462 if (touchending) clearTimeout(touchending);
5463 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
5464 } else {
5465 yesdrag(event.view, moving);
5466 view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
5467 }
5468 group.attr("pointer-events", "all");
5469 overlay.attr("cursor", cursors.overlay);
5470 if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
5471 if (empty(selection)) state.selection = null, redraw.call(that);
5472 emit.end(event, mode.name);
5473 }
5474
5475 function keydowned(event) {
5476 switch (event.keyCode) {
5477 case 16: { // SHIFT
5478 shifting = signX && signY;
5479 break;
5480 }
5481 case 18: { // ALT
5482 if (mode === MODE_HANDLE) {
5483 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
5484 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
5485 mode = MODE_CENTER;
5486 move();
5487 }
5488 break;
5489 }
5490 case 32: { // SPACE; takes priority over ALT
5491 if (mode === MODE_HANDLE || mode === MODE_CENTER) {
5492 if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
5493 if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
5494 mode = MODE_SPACE;
5495 overlay.attr("cursor", cursors.selection);
5496 move();
5497 }
5498 break;
5499 }
5500 default: return;
5501 }
5502 noevent$1(event);
5503 }
5504
5505 function keyupped(event) {
5506 switch (event.keyCode) {
5507 case 16: { // SHIFT
5508 if (shifting) {
5509 lockX = lockY = shifting = false;
5510 move();
5511 }
5512 break;
5513 }
5514 case 18: { // ALT
5515 if (mode === MODE_CENTER) {
5516 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
5517 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
5518 mode = MODE_HANDLE;
5519 move();
5520 }
5521 break;
5522 }
5523 case 32: { // SPACE
5524 if (mode === MODE_SPACE) {
5525 if (event.altKey) {
5526 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
5527 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
5528 mode = MODE_CENTER;
5529 } else {
5530 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
5531 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
5532 mode = MODE_HANDLE;
5533 }
5534 overlay.attr("cursor", cursors[type]);
5535 move();
5536 }
5537 break;
5538 }
5539 default: return;
5540 }
5541 noevent$1(event);
5542 }
5543 }
5544
5545 function touchmoved(event) {
5546 emitter(this, arguments).moved(event);
5547 }
5548
5549 function touchended(event) {
5550 emitter(this, arguments).ended(event);
5551 }
5552
5553 function initialize() {
5554 var state = this.__brush || {selection: null};
5555 state.extent = number2(extent.apply(this, arguments));
5556 state.dim = dim;
5557 return state;
5558 }
5559
5560 brush.extent = function(_) {
5561 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$7(number2(_)), brush) : extent;
5562 };
5563
5564 brush.filter = function(_) {
5565 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), brush) : filter;
5566 };
5567
5568 brush.touchable = function(_) {
5569 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$7(!!_), brush) : touchable;
5570 };
5571
5572 brush.handleSize = function(_) {
5573 return arguments.length ? (handleSize = +_, brush) : handleSize;
5574 };
5575
5576 brush.keyModifiers = function(_) {
5577 return arguments.length ? (keys = !!_, brush) : keys;
5578 };
5579
5580 brush.on = function() {
5581 var value = listeners.on.apply(listeners, arguments);
5582 return value === listeners ? brush : value;
5583 };
5584
5585 return brush;
5586}
5587
5588var abs$2 = Math.abs;
5589var cos$2 = Math.cos;
5590var sin$2 = Math.sin;
5591var pi$3 = Math.PI;
5592var halfPi$2 = pi$3 / 2;
5593var tau$4 = pi$3 * 2;
5594var max$1 = Math.max;
5595var epsilon$4 = 1e-12;
5596
5597function range$1(i, j) {
5598 return Array.from({length: j - i}, (_, k) => i + k);
5599}
5600
5601function compareValue(compare) {
5602 return function(a, b) {
5603 return compare(
5604 a.source.value + a.target.value,
5605 b.source.value + b.target.value
5606 );
5607 };
5608}
5609
5610function chord() {
5611 return chord$1(false, false);
5612}
5613
5614function chordTranspose() {
5615 return chord$1(false, true);
5616}
5617
5618function chordDirected() {
5619 return chord$1(true, false);
5620}
5621
5622function chord$1(directed, transpose) {
5623 var padAngle = 0,
5624 sortGroups = null,
5625 sortSubgroups = null,
5626 sortChords = null;
5627
5628 function chord(matrix) {
5629 var n = matrix.length,
5630 groupSums = new Array(n),
5631 groupIndex = range$1(0, n),
5632 chords = new Array(n * n),
5633 groups = new Array(n),
5634 k = 0, dx;
5635
5636 matrix = Float64Array.from({length: n * n}, transpose
5637 ? (_, i) => matrix[i % n][i / n | 0]
5638 : (_, i) => matrix[i / n | 0][i % n]);
5639
5640 // Compute the scaling factor from value to angle in [0, 2pi].
5641 for (let i = 0; i < n; ++i) {
5642 let x = 0;
5643 for (let j = 0; j < n; ++j) x += matrix[i * n + j] + directed * matrix[j * n + i];
5644 k += groupSums[i] = x;
5645 }
5646 k = max$1(0, tau$4 - padAngle * n) / k;
5647 dx = k ? padAngle : tau$4 / n;
5648
5649 // Compute the angles for each group and constituent chord.
5650 {
5651 let x = 0;
5652 if (sortGroups) groupIndex.sort((a, b) => sortGroups(groupSums[a], groupSums[b]));
5653 for (const i of groupIndex) {
5654 const x0 = x;
5655 if (directed) {
5656 const subgroupIndex = range$1(~n + 1, n).filter(j => j < 0 ? matrix[~j * n + i] : matrix[i * n + j]);
5657 if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(a < 0 ? -matrix[~a * n + i] : matrix[i * n + a], b < 0 ? -matrix[~b * n + i] : matrix[i * n + b]));
5658 for (const j of subgroupIndex) {
5659 if (j < 0) {
5660 const chord = chords[~j * n + i] || (chords[~j * n + i] = {source: null, target: null});
5661 chord.target = {index: i, startAngle: x, endAngle: x += matrix[~j * n + i] * k, value: matrix[~j * n + i]};
5662 } else {
5663 const chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
5664 chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
5665 }
5666 }
5667 groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
5668 } else {
5669 const subgroupIndex = range$1(0, n).filter(j => matrix[i * n + j] || matrix[j * n + i]);
5670 if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(matrix[i * n + a], matrix[i * n + b]));
5671 for (const j of subgroupIndex) {
5672 let chord;
5673 if (i < j) {
5674 chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
5675 chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
5676 } else {
5677 chord = chords[j * n + i] || (chords[j * n + i] = {source: null, target: null});
5678 chord.target = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
5679 if (i === j) chord.source = chord.target;
5680 }
5681 if (chord.source && chord.target && chord.source.value < chord.target.value) {
5682 const source = chord.source;
5683 chord.source = chord.target;
5684 chord.target = source;
5685 }
5686 }
5687 groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
5688 }
5689 x += dx;
5690 }
5691 }
5692
5693 // Remove empty chords.
5694 chords = Object.values(chords);
5695 chords.groups = groups;
5696 return sortChords ? chords.sort(sortChords) : chords;
5697 }
5698
5699 chord.padAngle = function(_) {
5700 return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
5701 };
5702
5703 chord.sortGroups = function(_) {
5704 return arguments.length ? (sortGroups = _, chord) : sortGroups;
5705 };
5706
5707 chord.sortSubgroups = function(_) {
5708 return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
5709 };
5710
5711 chord.sortChords = function(_) {
5712 return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
5713 };
5714
5715 return chord;
5716}
5717
5718const pi$2 = Math.PI,
5719 tau$3 = 2 * pi$2,
5720 epsilon$3 = 1e-6,
5721 tauEpsilon = tau$3 - epsilon$3;
5722
5723function Path$1() {
5724 this._x0 = this._y0 = // start of current subpath
5725 this._x1 = this._y1 = null; // end of current subpath
5726 this._ = "";
5727}
5728
5729function path() {
5730 return new Path$1;
5731}
5732
5733Path$1.prototype = path.prototype = {
5734 constructor: Path$1,
5735 moveTo: function(x, y) {
5736 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
5737 },
5738 closePath: function() {
5739 if (this._x1 !== null) {
5740 this._x1 = this._x0, this._y1 = this._y0;
5741 this._ += "Z";
5742 }
5743 },
5744 lineTo: function(x, y) {
5745 this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
5746 },
5747 quadraticCurveTo: function(x1, y1, x, y) {
5748 this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
5749 },
5750 bezierCurveTo: function(x1, y1, x2, y2, x, y) {
5751 this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
5752 },
5753 arcTo: function(x1, y1, x2, y2, r) {
5754 x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
5755 var x0 = this._x1,
5756 y0 = this._y1,
5757 x21 = x2 - x1,
5758 y21 = y2 - y1,
5759 x01 = x0 - x1,
5760 y01 = y0 - y1,
5761 l01_2 = x01 * x01 + y01 * y01;
5762
5763 // Is the radius negative? Error.
5764 if (r < 0) throw new Error("negative radius: " + r);
5765
5766 // Is this path empty? Move to (x1,y1).
5767 if (this._x1 === null) {
5768 this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
5769 }
5770
5771 // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
5772 else if (!(l01_2 > epsilon$3));
5773
5774 // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
5775 // Equivalently, is (x1,y1) coincident with (x2,y2)?
5776 // Or, is the radius zero? Line to (x1,y1).
5777 else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$3) || !r) {
5778 this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
5779 }
5780
5781 // Otherwise, draw an arc!
5782 else {
5783 var x20 = x2 - x0,
5784 y20 = y2 - y0,
5785 l21_2 = x21 * x21 + y21 * y21,
5786 l20_2 = x20 * x20 + y20 * y20,
5787 l21 = Math.sqrt(l21_2),
5788 l01 = Math.sqrt(l01_2),
5789 l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
5790 t01 = l / l01,
5791 t21 = l / l21;
5792
5793 // If the start tangent is not coincident with (x0,y0), line to.
5794 if (Math.abs(t01 - 1) > epsilon$3) {
5795 this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
5796 }
5797
5798 this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
5799 }
5800 },
5801 arc: function(x, y, r, a0, a1, ccw) {
5802 x = +x, y = +y, r = +r, ccw = !!ccw;
5803 var dx = r * Math.cos(a0),
5804 dy = r * Math.sin(a0),
5805 x0 = x + dx,
5806 y0 = y + dy,
5807 cw = 1 ^ ccw,
5808 da = ccw ? a0 - a1 : a1 - a0;
5809
5810 // Is the radius negative? Error.
5811 if (r < 0) throw new Error("negative radius: " + r);
5812
5813 // Is this path empty? Move to (x0,y0).
5814 if (this._x1 === null) {
5815 this._ += "M" + x0 + "," + y0;
5816 }
5817
5818 // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
5819 else if (Math.abs(this._x1 - x0) > epsilon$3 || Math.abs(this._y1 - y0) > epsilon$3) {
5820 this._ += "L" + x0 + "," + y0;
5821 }
5822
5823 // Is this arc empty? We’re done.
5824 if (!r) return;
5825
5826 // Does the angle go the wrong way? Flip the direction.
5827 if (da < 0) da = da % tau$3 + tau$3;
5828
5829 // Is this a complete circle? Draw two arcs to complete the circle.
5830 if (da > tauEpsilon) {
5831 this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
5832 }
5833
5834 // Is this arc non-empty? Draw an arc!
5835 else if (da > epsilon$3) {
5836 this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
5837 }
5838 },
5839 rect: function(x, y, w, h) {
5840 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
5841 },
5842 toString: function() {
5843 return this._;
5844 }
5845};
5846
5847var slice$2 = Array.prototype.slice;
5848
5849function constant$6(x) {
5850 return function() {
5851 return x;
5852 };
5853}
5854
5855function defaultSource$1(d) {
5856 return d.source;
5857}
5858
5859function defaultTarget(d) {
5860 return d.target;
5861}
5862
5863function defaultRadius$1(d) {
5864 return d.radius;
5865}
5866
5867function defaultStartAngle(d) {
5868 return d.startAngle;
5869}
5870
5871function defaultEndAngle(d) {
5872 return d.endAngle;
5873}
5874
5875function defaultPadAngle() {
5876 return 0;
5877}
5878
5879function defaultArrowheadRadius() {
5880 return 10;
5881}
5882
5883function ribbon(headRadius) {
5884 var source = defaultSource$1,
5885 target = defaultTarget,
5886 sourceRadius = defaultRadius$1,
5887 targetRadius = defaultRadius$1,
5888 startAngle = defaultStartAngle,
5889 endAngle = defaultEndAngle,
5890 padAngle = defaultPadAngle,
5891 context = null;
5892
5893 function ribbon() {
5894 var buffer,
5895 s = source.apply(this, arguments),
5896 t = target.apply(this, arguments),
5897 ap = padAngle.apply(this, arguments) / 2,
5898 argv = slice$2.call(arguments),
5899 sr = +sourceRadius.apply(this, (argv[0] = s, argv)),
5900 sa0 = startAngle.apply(this, argv) - halfPi$2,
5901 sa1 = endAngle.apply(this, argv) - halfPi$2,
5902 tr = +targetRadius.apply(this, (argv[0] = t, argv)),
5903 ta0 = startAngle.apply(this, argv) - halfPi$2,
5904 ta1 = endAngle.apply(this, argv) - halfPi$2;
5905
5906 if (!context) context = buffer = path();
5907
5908 if (ap > epsilon$4) {
5909 if (abs$2(sa1 - sa0) > ap * 2 + epsilon$4) sa1 > sa0 ? (sa0 += ap, sa1 -= ap) : (sa0 -= ap, sa1 += ap);
5910 else sa0 = sa1 = (sa0 + sa1) / 2;
5911 if (abs$2(ta1 - ta0) > ap * 2 + epsilon$4) ta1 > ta0 ? (ta0 += ap, ta1 -= ap) : (ta0 -= ap, ta1 += ap);
5912 else ta0 = ta1 = (ta0 + ta1) / 2;
5913 }
5914
5915 context.moveTo(sr * cos$2(sa0), sr * sin$2(sa0));
5916 context.arc(0, 0, sr, sa0, sa1);
5917 if (sa0 !== ta0 || sa1 !== ta1) {
5918 if (headRadius) {
5919 var hr = +headRadius.apply(this, arguments), tr2 = tr - hr, ta2 = (ta0 + ta1) / 2;
5920 context.quadraticCurveTo(0, 0, tr2 * cos$2(ta0), tr2 * sin$2(ta0));
5921 context.lineTo(tr * cos$2(ta2), tr * sin$2(ta2));
5922 context.lineTo(tr2 * cos$2(ta1), tr2 * sin$2(ta1));
5923 } else {
5924 context.quadraticCurveTo(0, 0, tr * cos$2(ta0), tr * sin$2(ta0));
5925 context.arc(0, 0, tr, ta0, ta1);
5926 }
5927 }
5928 context.quadraticCurveTo(0, 0, sr * cos$2(sa0), sr * sin$2(sa0));
5929 context.closePath();
5930
5931 if (buffer) return context = null, buffer + "" || null;
5932 }
5933
5934 if (headRadius) ribbon.headRadius = function(_) {
5935 return arguments.length ? (headRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : headRadius;
5936 };
5937
5938 ribbon.radius = function(_) {
5939 return arguments.length ? (sourceRadius = targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
5940 };
5941
5942 ribbon.sourceRadius = function(_) {
5943 return arguments.length ? (sourceRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
5944 };
5945
5946 ribbon.targetRadius = function(_) {
5947 return arguments.length ? (targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : targetRadius;
5948 };
5949
5950 ribbon.startAngle = function(_) {
5951 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : startAngle;
5952 };
5953
5954 ribbon.endAngle = function(_) {
5955 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : endAngle;
5956 };
5957
5958 ribbon.padAngle = function(_) {
5959 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : padAngle;
5960 };
5961
5962 ribbon.source = function(_) {
5963 return arguments.length ? (source = _, ribbon) : source;
5964 };
5965
5966 ribbon.target = function(_) {
5967 return arguments.length ? (target = _, ribbon) : target;
5968 };
5969
5970 ribbon.context = function(_) {
5971 return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
5972 };
5973
5974 return ribbon;
5975}
5976
5977function ribbon$1() {
5978 return ribbon();
5979}
5980
5981function ribbonArrow() {
5982 return ribbon(defaultArrowheadRadius);
5983}
5984
5985var array$2 = Array.prototype;
5986
5987var slice$1 = array$2.slice;
5988
5989function ascending$1(a, b) {
5990 return a - b;
5991}
5992
5993function area$3(ring) {
5994 var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
5995 while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
5996 return area;
5997}
5998
5999var constant$5 = x => () => x;
6000
6001function contains$2(ring, hole) {
6002 var i = -1, n = hole.length, c;
6003 while (++i < n) if (c = ringContains(ring, hole[i])) return c;
6004 return 0;
6005}
6006
6007function ringContains(ring, point) {
6008 var x = point[0], y = point[1], contains = -1;
6009 for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
6010 var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
6011 if (segmentContains(pi, pj, point)) return 0;
6012 if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
6013 }
6014 return contains;
6015}
6016
6017function segmentContains(a, b, c) {
6018 var i; return collinear$1(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
6019}
6020
6021function collinear$1(a, b, c) {
6022 return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
6023}
6024
6025function within(p, q, r) {
6026 return p <= q && q <= r || r <= q && q <= p;
6027}
6028
6029function noop$2() {}
6030
6031var cases = [
6032 [],
6033 [[[1.0, 1.5], [0.5, 1.0]]],
6034 [[[1.5, 1.0], [1.0, 1.5]]],
6035 [[[1.5, 1.0], [0.5, 1.0]]],
6036 [[[1.0, 0.5], [1.5, 1.0]]],
6037 [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
6038 [[[1.0, 0.5], [1.0, 1.5]]],
6039 [[[1.0, 0.5], [0.5, 1.0]]],
6040 [[[0.5, 1.0], [1.0, 0.5]]],
6041 [[[1.0, 1.5], [1.0, 0.5]]],
6042 [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
6043 [[[1.5, 1.0], [1.0, 0.5]]],
6044 [[[0.5, 1.0], [1.5, 1.0]]],
6045 [[[1.0, 1.5], [1.5, 1.0]]],
6046 [[[0.5, 1.0], [1.0, 1.5]]],
6047 []
6048];
6049
6050function contours() {
6051 var dx = 1,
6052 dy = 1,
6053 threshold = thresholdSturges,
6054 smooth = smoothLinear;
6055
6056 function contours(values) {
6057 var tz = threshold(values);
6058
6059 // Convert number of thresholds into uniform thresholds.
6060 if (!Array.isArray(tz)) {
6061 var domain = extent$1(values), start = domain[0], stop = domain[1];
6062 tz = tickStep(start, stop, tz);
6063 tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
6064 } else {
6065 tz = tz.slice().sort(ascending$1);
6066 }
6067
6068 return tz.map(function(value) {
6069 return contour(values, value);
6070 });
6071 }
6072
6073 // Accumulate, smooth contour rings, assign holes to exterior rings.
6074 // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
6075 function contour(values, value) {
6076 var polygons = [],
6077 holes = [];
6078
6079 isorings(values, value, function(ring) {
6080 smooth(ring, values, value);
6081 if (area$3(ring) > 0) polygons.push([ring]);
6082 else holes.push(ring);
6083 });
6084
6085 holes.forEach(function(hole) {
6086 for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
6087 if (contains$2((polygon = polygons[i])[0], hole) !== -1) {
6088 polygon.push(hole);
6089 return;
6090 }
6091 }
6092 });
6093
6094 return {
6095 type: "MultiPolygon",
6096 value: value,
6097 coordinates: polygons
6098 };
6099 }
6100
6101 // Marching squares with isolines stitched into rings.
6102 // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
6103 function isorings(values, value, callback) {
6104 var fragmentByStart = new Array,
6105 fragmentByEnd = new Array,
6106 x, y, t0, t1, t2, t3;
6107
6108 // Special case for the first row (y = -1, t2 = t3 = 0).
6109 x = y = -1;
6110 t1 = values[0] >= value;
6111 cases[t1 << 1].forEach(stitch);
6112 while (++x < dx - 1) {
6113 t0 = t1, t1 = values[x + 1] >= value;
6114 cases[t0 | t1 << 1].forEach(stitch);
6115 }
6116 cases[t1 << 0].forEach(stitch);
6117
6118 // General case for the intermediate rows.
6119 while (++y < dy - 1) {
6120 x = -1;
6121 t1 = values[y * dx + dx] >= value;
6122 t2 = values[y * dx] >= value;
6123 cases[t1 << 1 | t2 << 2].forEach(stitch);
6124 while (++x < dx - 1) {
6125 t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
6126 t3 = t2, t2 = values[y * dx + x + 1] >= value;
6127 cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
6128 }
6129 cases[t1 | t2 << 3].forEach(stitch);
6130 }
6131
6132 // Special case for the last row (y = dy - 1, t0 = t1 = 0).
6133 x = -1;
6134 t2 = values[y * dx] >= value;
6135 cases[t2 << 2].forEach(stitch);
6136 while (++x < dx - 1) {
6137 t3 = t2, t2 = values[y * dx + x + 1] >= value;
6138 cases[t2 << 2 | t3 << 3].forEach(stitch);
6139 }
6140 cases[t2 << 3].forEach(stitch);
6141
6142 function stitch(line) {
6143 var start = [line[0][0] + x, line[0][1] + y],
6144 end = [line[1][0] + x, line[1][1] + y],
6145 startIndex = index(start),
6146 endIndex = index(end),
6147 f, g;
6148 if (f = fragmentByEnd[startIndex]) {
6149 if (g = fragmentByStart[endIndex]) {
6150 delete fragmentByEnd[f.end];
6151 delete fragmentByStart[g.start];
6152 if (f === g) {
6153 f.ring.push(end);
6154 callback(f.ring);
6155 } else {
6156 fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
6157 }
6158 } else {
6159 delete fragmentByEnd[f.end];
6160 f.ring.push(end);
6161 fragmentByEnd[f.end = endIndex] = f;
6162 }
6163 } else if (f = fragmentByStart[endIndex]) {
6164 if (g = fragmentByEnd[startIndex]) {
6165 delete fragmentByStart[f.start];
6166 delete fragmentByEnd[g.end];
6167 if (f === g) {
6168 f.ring.push(end);
6169 callback(f.ring);
6170 } else {
6171 fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
6172 }
6173 } else {
6174 delete fragmentByStart[f.start];
6175 f.ring.unshift(start);
6176 fragmentByStart[f.start = startIndex] = f;
6177 }
6178 } else {
6179 fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
6180 }
6181 }
6182 }
6183
6184 function index(point) {
6185 return point[0] * 2 + point[1] * (dx + 1) * 4;
6186 }
6187
6188 function smoothLinear(ring, values, value) {
6189 ring.forEach(function(point) {
6190 var x = point[0],
6191 y = point[1],
6192 xt = x | 0,
6193 yt = y | 0,
6194 v0,
6195 v1 = values[yt * dx + xt];
6196 if (x > 0 && x < dx && xt === x) {
6197 v0 = values[yt * dx + xt - 1];
6198 point[0] = x + (value - v0) / (v1 - v0) - 0.5;
6199 }
6200 if (y > 0 && y < dy && yt === y) {
6201 v0 = values[(yt - 1) * dx + xt];
6202 point[1] = y + (value - v0) / (v1 - v0) - 0.5;
6203 }
6204 });
6205 }
6206
6207 contours.contour = contour;
6208
6209 contours.size = function(_) {
6210 if (!arguments.length) return [dx, dy];
6211 var _0 = Math.floor(_[0]), _1 = Math.floor(_[1]);
6212 if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
6213 return dx = _0, dy = _1, contours;
6214 };
6215
6216 contours.thresholds = function(_) {
6217 return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), contours) : threshold;
6218 };
6219
6220 contours.smooth = function(_) {
6221 return arguments.length ? (smooth = _ ? smoothLinear : noop$2, contours) : smooth === smoothLinear;
6222 };
6223
6224 return contours;
6225}
6226
6227// TODO Optimize edge cases.
6228// TODO Optimize index calculation.
6229// TODO Optimize arguments.
6230function blurX(source, target, r) {
6231 var n = source.width,
6232 m = source.height,
6233 w = (r << 1) + 1;
6234 for (var j = 0; j < m; ++j) {
6235 for (var i = 0, sr = 0; i < n + r; ++i) {
6236 if (i < n) {
6237 sr += source.data[i + j * n];
6238 }
6239 if (i >= r) {
6240 if (i >= w) {
6241 sr -= source.data[i - w + j * n];
6242 }
6243 target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
6244 }
6245 }
6246 }
6247}
6248
6249// TODO Optimize edge cases.
6250// TODO Optimize index calculation.
6251// TODO Optimize arguments.
6252function blurY(source, target, r) {
6253 var n = source.width,
6254 m = source.height,
6255 w = (r << 1) + 1;
6256 for (var i = 0; i < n; ++i) {
6257 for (var j = 0, sr = 0; j < m + r; ++j) {
6258 if (j < m) {
6259 sr += source.data[i + j * n];
6260 }
6261 if (j >= r) {
6262 if (j >= w) {
6263 sr -= source.data[i + (j - w) * n];
6264 }
6265 target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
6266 }
6267 }
6268 }
6269}
6270
6271function defaultX$1(d) {
6272 return d[0];
6273}
6274
6275function defaultY$1(d) {
6276 return d[1];
6277}
6278
6279function defaultWeight() {
6280 return 1;
6281}
6282
6283function density() {
6284 var x = defaultX$1,
6285 y = defaultY$1,
6286 weight = defaultWeight,
6287 dx = 960,
6288 dy = 500,
6289 r = 20, // blur radius
6290 k = 2, // log2(grid cell size)
6291 o = r * 3, // grid offset, to pad for blur
6292 n = (dx + o * 2) >> k, // grid width
6293 m = (dy + o * 2) >> k, // grid height
6294 threshold = constant$5(20);
6295
6296 function density(data) {
6297 var values0 = new Float32Array(n * m),
6298 values1 = new Float32Array(n * m);
6299
6300 data.forEach(function(d, i, data) {
6301 var xi = (+x(d, i, data) + o) >> k,
6302 yi = (+y(d, i, data) + o) >> k,
6303 wi = +weight(d, i, data);
6304 if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
6305 values0[xi + yi * n] += wi;
6306 }
6307 });
6308
6309 // TODO Optimize.
6310 blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
6311 blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
6312 blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
6313 blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
6314 blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
6315 blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
6316
6317 var tz = threshold(values0);
6318
6319 // Convert number of thresholds into uniform thresholds.
6320 if (!Array.isArray(tz)) {
6321 var stop = max$3(values0);
6322 tz = tickStep(0, stop, tz);
6323 tz = sequence(0, Math.floor(stop / tz) * tz, tz);
6324 tz.shift();
6325 }
6326
6327 return contours()
6328 .thresholds(tz)
6329 .size([n, m])
6330 (values0)
6331 .map(transform);
6332 }
6333
6334 function transform(geometry) {
6335 geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
6336 geometry.coordinates.forEach(transformPolygon);
6337 return geometry;
6338 }
6339
6340 function transformPolygon(coordinates) {
6341 coordinates.forEach(transformRing);
6342 }
6343
6344 function transformRing(coordinates) {
6345 coordinates.forEach(transformPoint);
6346 }
6347
6348 // TODO Optimize.
6349 function transformPoint(coordinates) {
6350 coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
6351 coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
6352 }
6353
6354 function resize() {
6355 o = r * 3;
6356 n = (dx + o * 2) >> k;
6357 m = (dy + o * 2) >> k;
6358 return density;
6359 }
6360
6361 density.x = function(_) {
6362 return arguments.length ? (x = typeof _ === "function" ? _ : constant$5(+_), density) : x;
6363 };
6364
6365 density.y = function(_) {
6366 return arguments.length ? (y = typeof _ === "function" ? _ : constant$5(+_), density) : y;
6367 };
6368
6369 density.weight = function(_) {
6370 return arguments.length ? (weight = typeof _ === "function" ? _ : constant$5(+_), density) : weight;
6371 };
6372
6373 density.size = function(_) {
6374 if (!arguments.length) return [dx, dy];
6375 var _0 = +_[0], _1 = +_[1];
6376 if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
6377 return dx = _0, dy = _1, resize();
6378 };
6379
6380 density.cellSize = function(_) {
6381 if (!arguments.length) return 1 << k;
6382 if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
6383 return k = Math.floor(Math.log(_) / Math.LN2), resize();
6384 };
6385
6386 density.thresholds = function(_) {
6387 return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), density) : threshold;
6388 };
6389
6390 density.bandwidth = function(_) {
6391 if (!arguments.length) return Math.sqrt(r * (r + 1));
6392 if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
6393 return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
6394 };
6395
6396 return density;
6397}
6398
6399const EPSILON = Math.pow(2, -52);
6400const EDGE_STACK = new Uint32Array(512);
6401
6402class Delaunator {
6403
6404 static from(points, getX = defaultGetX, getY = defaultGetY) {
6405 const n = points.length;
6406 const coords = new Float64Array(n * 2);
6407
6408 for (let i = 0; i < n; i++) {
6409 const p = points[i];
6410 coords[2 * i] = getX(p);
6411 coords[2 * i + 1] = getY(p);
6412 }
6413
6414 return new Delaunator(coords);
6415 }
6416
6417 constructor(coords) {
6418 const n = coords.length >> 1;
6419 if (n > 0 && typeof coords[0] !== 'number') throw new Error('Expected coords to contain numbers.');
6420
6421 this.coords = coords;
6422
6423 // arrays that will store the triangulation graph
6424 const maxTriangles = Math.max(2 * n - 5, 0);
6425 this._triangles = new Uint32Array(maxTriangles * 3);
6426 this._halfedges = new Int32Array(maxTriangles * 3);
6427
6428 // temporary arrays for tracking the edges of the advancing convex hull
6429 this._hashSize = Math.ceil(Math.sqrt(n));
6430 this._hullPrev = new Uint32Array(n); // edge to prev edge
6431 this._hullNext = new Uint32Array(n); // edge to next edge
6432 this._hullTri = new Uint32Array(n); // edge to adjacent triangle
6433 this._hullHash = new Int32Array(this._hashSize).fill(-1); // angular edge hash
6434
6435 // temporary arrays for sorting points
6436 this._ids = new Uint32Array(n);
6437 this._dists = new Float64Array(n);
6438
6439 this.update();
6440 }
6441
6442 update() {
6443 const {coords, _hullPrev: hullPrev, _hullNext: hullNext, _hullTri: hullTri, _hullHash: hullHash} = this;
6444 const n = coords.length >> 1;
6445
6446 // populate an array of point indices; calculate input data bbox
6447 let minX = Infinity;
6448 let minY = Infinity;
6449 let maxX = -Infinity;
6450 let maxY = -Infinity;
6451
6452 for (let i = 0; i < n; i++) {
6453 const x = coords[2 * i];
6454 const y = coords[2 * i + 1];
6455 if (x < minX) minX = x;
6456 if (y < minY) minY = y;
6457 if (x > maxX) maxX = x;
6458 if (y > maxY) maxY = y;
6459 this._ids[i] = i;
6460 }
6461 const cx = (minX + maxX) / 2;
6462 const cy = (minY + maxY) / 2;
6463
6464 let minDist = Infinity;
6465 let i0, i1, i2;
6466
6467 // pick a seed point close to the center
6468 for (let i = 0; i < n; i++) {
6469 const d = dist(cx, cy, coords[2 * i], coords[2 * i + 1]);
6470 if (d < minDist) {
6471 i0 = i;
6472 minDist = d;
6473 }
6474 }
6475 const i0x = coords[2 * i0];
6476 const i0y = coords[2 * i0 + 1];
6477
6478 minDist = Infinity;
6479
6480 // find the point closest to the seed
6481 for (let i = 0; i < n; i++) {
6482 if (i === i0) continue;
6483 const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
6484 if (d < minDist && d > 0) {
6485 i1 = i;
6486 minDist = d;
6487 }
6488 }
6489 let i1x = coords[2 * i1];
6490 let i1y = coords[2 * i1 + 1];
6491
6492 let minRadius = Infinity;
6493
6494 // find the third point which forms the smallest circumcircle with the first two
6495 for (let i = 0; i < n; i++) {
6496 if (i === i0 || i === i1) continue;
6497 const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
6498 if (r < minRadius) {
6499 i2 = i;
6500 minRadius = r;
6501 }
6502 }
6503 let i2x = coords[2 * i2];
6504 let i2y = coords[2 * i2 + 1];
6505
6506 if (minRadius === Infinity) {
6507 // order collinear points by dx (or dy if all x are identical)
6508 // and return the list as a hull
6509 for (let i = 0; i < n; i++) {
6510 this._dists[i] = (coords[2 * i] - coords[0]) || (coords[2 * i + 1] - coords[1]);
6511 }
6512 quicksort(this._ids, this._dists, 0, n - 1);
6513 const hull = new Uint32Array(n);
6514 let j = 0;
6515 for (let i = 0, d0 = -Infinity; i < n; i++) {
6516 const id = this._ids[i];
6517 if (this._dists[id] > d0) {
6518 hull[j++] = id;
6519 d0 = this._dists[id];
6520 }
6521 }
6522 this.hull = hull.subarray(0, j);
6523 this.triangles = new Uint32Array(0);
6524 this.halfedges = new Uint32Array(0);
6525 return;
6526 }
6527
6528 // swap the order of the seed points for counter-clockwise orientation
6529 if (orient(i0x, i0y, i1x, i1y, i2x, i2y)) {
6530 const i = i1;
6531 const x = i1x;
6532 const y = i1y;
6533 i1 = i2;
6534 i1x = i2x;
6535 i1y = i2y;
6536 i2 = i;
6537 i2x = x;
6538 i2y = y;
6539 }
6540
6541 const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
6542 this._cx = center.x;
6543 this._cy = center.y;
6544
6545 for (let i = 0; i < n; i++) {
6546 this._dists[i] = dist(coords[2 * i], coords[2 * i + 1], center.x, center.y);
6547 }
6548
6549 // sort the points by distance from the seed triangle circumcenter
6550 quicksort(this._ids, this._dists, 0, n - 1);
6551
6552 // set up the seed triangle as the starting hull
6553 this._hullStart = i0;
6554 let hullSize = 3;
6555
6556 hullNext[i0] = hullPrev[i2] = i1;
6557 hullNext[i1] = hullPrev[i0] = i2;
6558 hullNext[i2] = hullPrev[i1] = i0;
6559
6560 hullTri[i0] = 0;
6561 hullTri[i1] = 1;
6562 hullTri[i2] = 2;
6563
6564 hullHash.fill(-1);
6565 hullHash[this._hashKey(i0x, i0y)] = i0;
6566 hullHash[this._hashKey(i1x, i1y)] = i1;
6567 hullHash[this._hashKey(i2x, i2y)] = i2;
6568
6569 this.trianglesLen = 0;
6570 this._addTriangle(i0, i1, i2, -1, -1, -1);
6571
6572 for (let k = 0, xp, yp; k < this._ids.length; k++) {
6573 const i = this._ids[k];
6574 const x = coords[2 * i];
6575 const y = coords[2 * i + 1];
6576
6577 // skip near-duplicate points
6578 if (k > 0 && Math.abs(x - xp) <= EPSILON && Math.abs(y - yp) <= EPSILON) continue;
6579 xp = x;
6580 yp = y;
6581
6582 // skip seed triangle points
6583 if (i === i0 || i === i1 || i === i2) continue;
6584
6585 // find a visible edge on the convex hull using edge hash
6586 let start = 0;
6587 for (let j = 0, key = this._hashKey(x, y); j < this._hashSize; j++) {
6588 start = hullHash[(key + j) % this._hashSize];
6589 if (start !== -1 && start !== hullNext[start]) break;
6590 }
6591
6592 start = hullPrev[start];
6593 let e = start, q;
6594 while (q = hullNext[e], !orient(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1])) {
6595 e = q;
6596 if (e === start) {
6597 e = -1;
6598 break;
6599 }
6600 }
6601 if (e === -1) continue; // likely a near-duplicate point; skip it
6602
6603 // add the first triangle from the point
6604 let t = this._addTriangle(e, i, hullNext[e], -1, -1, hullTri[e]);
6605
6606 // recursively flip triangles from the point until they satisfy the Delaunay condition
6607 hullTri[i] = this._legalize(t + 2);
6608 hullTri[e] = t; // keep track of boundary triangles on the hull
6609 hullSize++;
6610
6611 // walk forward through the hull, adding more triangles and flipping recursively
6612 let n = hullNext[e];
6613 while (q = hullNext[n], orient(x, y, coords[2 * n], coords[2 * n + 1], coords[2 * q], coords[2 * q + 1])) {
6614 t = this._addTriangle(n, i, q, hullTri[i], -1, hullTri[n]);
6615 hullTri[i] = this._legalize(t + 2);
6616 hullNext[n] = n; // mark as removed
6617 hullSize--;
6618 n = q;
6619 }
6620
6621 // walk backward from the other side, adding more triangles and flipping
6622 if (e === start) {
6623 while (q = hullPrev[e], orient(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1])) {
6624 t = this._addTriangle(q, i, e, -1, hullTri[e], hullTri[q]);
6625 this._legalize(t + 2);
6626 hullTri[q] = t;
6627 hullNext[e] = e; // mark as removed
6628 hullSize--;
6629 e = q;
6630 }
6631 }
6632
6633 // update the hull indices
6634 this._hullStart = hullPrev[i] = e;
6635 hullNext[e] = hullPrev[n] = i;
6636 hullNext[i] = n;
6637
6638 // save the two new edges in the hash table
6639 hullHash[this._hashKey(x, y)] = i;
6640 hullHash[this._hashKey(coords[2 * e], coords[2 * e + 1])] = e;
6641 }
6642
6643 this.hull = new Uint32Array(hullSize);
6644 for (let i = 0, e = this._hullStart; i < hullSize; i++) {
6645 this.hull[i] = e;
6646 e = hullNext[e];
6647 }
6648
6649 // trim typed triangle mesh arrays
6650 this.triangles = this._triangles.subarray(0, this.trianglesLen);
6651 this.halfedges = this._halfedges.subarray(0, this.trianglesLen);
6652 }
6653
6654 _hashKey(x, y) {
6655 return Math.floor(pseudoAngle(x - this._cx, y - this._cy) * this._hashSize) % this._hashSize;
6656 }
6657
6658 _legalize(a) {
6659 const {_triangles: triangles, _halfedges: halfedges, coords} = this;
6660
6661 let i = 0;
6662 let ar = 0;
6663
6664 // recursion eliminated with a fixed-size stack
6665 while (true) {
6666 const b = halfedges[a];
6667
6668 /* if the pair of triangles doesn't satisfy the Delaunay condition
6669 * (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
6670 * then do the same check/flip recursively for the new pair of triangles
6671 *
6672 * pl pl
6673 * /||\ / \
6674 * al/ || \bl al/ \a
6675 * / || \ / \
6676 * / a||b \ flip /___ar___\
6677 * p0\ || /p1 => p0\---bl---/p1
6678 * \ || / \ /
6679 * ar\ || /br b\ /br
6680 * \||/ \ /
6681 * pr pr
6682 */
6683 const a0 = a - a % 3;
6684 ar = a0 + (a + 2) % 3;
6685
6686 if (b === -1) { // convex hull edge
6687 if (i === 0) break;
6688 a = EDGE_STACK[--i];
6689 continue;
6690 }
6691
6692 const b0 = b - b % 3;
6693 const al = a0 + (a + 1) % 3;
6694 const bl = b0 + (b + 2) % 3;
6695
6696 const p0 = triangles[ar];
6697 const pr = triangles[a];
6698 const pl = triangles[al];
6699 const p1 = triangles[bl];
6700
6701 const illegal = inCircle(
6702 coords[2 * p0], coords[2 * p0 + 1],
6703 coords[2 * pr], coords[2 * pr + 1],
6704 coords[2 * pl], coords[2 * pl + 1],
6705 coords[2 * p1], coords[2 * p1 + 1]);
6706
6707 if (illegal) {
6708 triangles[a] = p1;
6709 triangles[b] = p0;
6710
6711 const hbl = halfedges[bl];
6712
6713 // edge swapped on the other side of the hull (rare); fix the halfedge reference
6714 if (hbl === -1) {
6715 let e = this._hullStart;
6716 do {
6717 if (this._hullTri[e] === bl) {
6718 this._hullTri[e] = a;
6719 break;
6720 }
6721 e = this._hullPrev[e];
6722 } while (e !== this._hullStart);
6723 }
6724 this._link(a, hbl);
6725 this._link(b, halfedges[ar]);
6726 this._link(ar, bl);
6727
6728 const br = b0 + (b + 1) % 3;
6729
6730 // don't worry about hitting the cap: it can only happen on extremely degenerate input
6731 if (i < EDGE_STACK.length) {
6732 EDGE_STACK[i++] = br;
6733 }
6734 } else {
6735 if (i === 0) break;
6736 a = EDGE_STACK[--i];
6737 }
6738 }
6739
6740 return ar;
6741 }
6742
6743 _link(a, b) {
6744 this._halfedges[a] = b;
6745 if (b !== -1) this._halfedges[b] = a;
6746 }
6747
6748 // add a new triangle given vertex indices and adjacent half-edge ids
6749 _addTriangle(i0, i1, i2, a, b, c) {
6750 const t = this.trianglesLen;
6751
6752 this._triangles[t] = i0;
6753 this._triangles[t + 1] = i1;
6754 this._triangles[t + 2] = i2;
6755
6756 this._link(t, a);
6757 this._link(t + 1, b);
6758 this._link(t + 2, c);
6759
6760 this.trianglesLen += 3;
6761
6762 return t;
6763 }
6764}
6765
6766// monotonically increases with real angle, but doesn't need expensive trigonometry
6767function pseudoAngle(dx, dy) {
6768 const p = dx / (Math.abs(dx) + Math.abs(dy));
6769 return (dy > 0 ? 3 - p : 1 + p) / 4; // [0..1]
6770}
6771
6772function dist(ax, ay, bx, by) {
6773 const dx = ax - bx;
6774 const dy = ay - by;
6775 return dx * dx + dy * dy;
6776}
6777
6778// return 2d orientation sign if we're confident in it through J. Shewchuk's error bound check
6779function orientIfSure(px, py, rx, ry, qx, qy) {
6780 const l = (ry - py) * (qx - px);
6781 const r = (rx - px) * (qy - py);
6782 return Math.abs(l - r) >= 3.3306690738754716e-16 * Math.abs(l + r) ? l - r : 0;
6783}
6784
6785// a more robust orientation test that's stable in a given triangle (to fix robustness issues)
6786function orient(rx, ry, qx, qy, px, py) {
6787 const sign = orientIfSure(px, py, rx, ry, qx, qy) ||
6788 orientIfSure(rx, ry, qx, qy, px, py) ||
6789 orientIfSure(qx, qy, px, py, rx, ry);
6790 return sign < 0;
6791}
6792
6793function inCircle(ax, ay, bx, by, cx, cy, px, py) {
6794 const dx = ax - px;
6795 const dy = ay - py;
6796 const ex = bx - px;
6797 const ey = by - py;
6798 const fx = cx - px;
6799 const fy = cy - py;
6800
6801 const ap = dx * dx + dy * dy;
6802 const bp = ex * ex + ey * ey;
6803 const cp = fx * fx + fy * fy;
6804
6805 return dx * (ey * cp - bp * fy) -
6806 dy * (ex * cp - bp * fx) +
6807 ap * (ex * fy - ey * fx) < 0;
6808}
6809
6810function circumradius(ax, ay, bx, by, cx, cy) {
6811 const dx = bx - ax;
6812 const dy = by - ay;
6813 const ex = cx - ax;
6814 const ey = cy - ay;
6815
6816 const bl = dx * dx + dy * dy;
6817 const cl = ex * ex + ey * ey;
6818 const d = 0.5 / (dx * ey - dy * ex);
6819
6820 const x = (ey * bl - dy * cl) * d;
6821 const y = (dx * cl - ex * bl) * d;
6822
6823 return x * x + y * y;
6824}
6825
6826function circumcenter(ax, ay, bx, by, cx, cy) {
6827 const dx = bx - ax;
6828 const dy = by - ay;
6829 const ex = cx - ax;
6830 const ey = cy - ay;
6831
6832 const bl = dx * dx + dy * dy;
6833 const cl = ex * ex + ey * ey;
6834 const d = 0.5 / (dx * ey - dy * ex);
6835
6836 const x = ax + (ey * bl - dy * cl) * d;
6837 const y = ay + (dx * cl - ex * bl) * d;
6838
6839 return {x, y};
6840}
6841
6842function quicksort(ids, dists, left, right) {
6843 if (right - left <= 20) {
6844 for (let i = left + 1; i <= right; i++) {
6845 const temp = ids[i];
6846 const tempDist = dists[temp];
6847 let j = i - 1;
6848 while (j >= left && dists[ids[j]] > tempDist) ids[j + 1] = ids[j--];
6849 ids[j + 1] = temp;
6850 }
6851 } else {
6852 const median = (left + right) >> 1;
6853 let i = left + 1;
6854 let j = right;
6855 swap(ids, median, i);
6856 if (dists[ids[left]] > dists[ids[right]]) swap(ids, left, right);
6857 if (dists[ids[i]] > dists[ids[right]]) swap(ids, i, right);
6858 if (dists[ids[left]] > dists[ids[i]]) swap(ids, left, i);
6859
6860 const temp = ids[i];
6861 const tempDist = dists[temp];
6862 while (true) {
6863 do i++; while (dists[ids[i]] < tempDist);
6864 do j--; while (dists[ids[j]] > tempDist);
6865 if (j < i) break;
6866 swap(ids, i, j);
6867 }
6868 ids[left + 1] = ids[j];
6869 ids[j] = temp;
6870
6871 if (right - i + 1 >= j - left) {
6872 quicksort(ids, dists, i, right);
6873 quicksort(ids, dists, left, j - 1);
6874 } else {
6875 quicksort(ids, dists, left, j - 1);
6876 quicksort(ids, dists, i, right);
6877 }
6878 }
6879}
6880
6881function swap(arr, i, j) {
6882 const tmp = arr[i];
6883 arr[i] = arr[j];
6884 arr[j] = tmp;
6885}
6886
6887function defaultGetX(p) {
6888 return p[0];
6889}
6890function defaultGetY(p) {
6891 return p[1];
6892}
6893
6894const epsilon$2 = 1e-6;
6895
6896class Path {
6897 constructor() {
6898 this._x0 = this._y0 = // start of current subpath
6899 this._x1 = this._y1 = null; // end of current subpath
6900 this._ = "";
6901 }
6902 moveTo(x, y) {
6903 this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
6904 }
6905 closePath() {
6906 if (this._x1 !== null) {
6907 this._x1 = this._x0, this._y1 = this._y0;
6908 this._ += "Z";
6909 }
6910 }
6911 lineTo(x, y) {
6912 this._ += `L${this._x1 = +x},${this._y1 = +y}`;
6913 }
6914 arc(x, y, r) {
6915 x = +x, y = +y, r = +r;
6916 const x0 = x + r;
6917 const y0 = y;
6918 if (r < 0) throw new Error("negative radius");
6919 if (this._x1 === null) this._ += `M${x0},${y0}`;
6920 else if (Math.abs(this._x1 - x0) > epsilon$2 || Math.abs(this._y1 - y0) > epsilon$2) this._ += "L" + x0 + "," + y0;
6921 if (!r) return;
6922 this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`;
6923 }
6924 rect(x, y, w, h) {
6925 this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`;
6926 }
6927 value() {
6928 return this._ || null;
6929 }
6930}
6931
6932class Polygon {
6933 constructor() {
6934 this._ = [];
6935 }
6936 moveTo(x, y) {
6937 this._.push([x, y]);
6938 }
6939 closePath() {
6940 this._.push(this._[0].slice());
6941 }
6942 lineTo(x, y) {
6943 this._.push([x, y]);
6944 }
6945 value() {
6946 return this._.length ? this._ : null;
6947 }
6948}
6949
6950class Voronoi {
6951 constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) {
6952 if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds");
6953 this.delaunay = delaunay;
6954 this._circumcenters = new Float64Array(delaunay.points.length * 2);
6955 this.vectors = new Float64Array(delaunay.points.length * 2);
6956 this.xmax = xmax, this.xmin = xmin;
6957 this.ymax = ymax, this.ymin = ymin;
6958 this._init();
6959 }
6960 update() {
6961 this.delaunay.update();
6962 this._init();
6963 return this;
6964 }
6965 _init() {
6966 const {delaunay: {points, hull, triangles}, vectors} = this;
6967
6968 // Compute circumcenters.
6969 const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2);
6970 for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
6971 const t1 = triangles[i] * 2;
6972 const t2 = triangles[i + 1] * 2;
6973 const t3 = triangles[i + 2] * 2;
6974 const x1 = points[t1];
6975 const y1 = points[t1 + 1];
6976 const x2 = points[t2];
6977 const y2 = points[t2 + 1];
6978 const x3 = points[t3];
6979 const y3 = points[t3 + 1];
6980
6981 const dx = x2 - x1;
6982 const dy = y2 - y1;
6983 const ex = x3 - x1;
6984 const ey = y3 - y1;
6985 const bl = dx * dx + dy * dy;
6986 const cl = ex * ex + ey * ey;
6987 const ab = (dx * ey - dy * ex) * 2;
6988
6989 if (!ab) {
6990 // degenerate case (collinear diagram)
6991 x = (x1 + x3) / 2 - 1e8 * ey;
6992 y = (y1 + y3) / 2 + 1e8 * ex;
6993 }
6994 else if (Math.abs(ab) < 1e-8) {
6995 // almost equal points (degenerate triangle)
6996 x = (x1 + x3) / 2;
6997 y = (y1 + y3) / 2;
6998 } else {
6999 const d = 1 / ab;
7000 x = x1 + (ey * bl - dy * cl) * d;
7001 y = y1 + (dx * cl - ex * bl) * d;
7002 }
7003 circumcenters[j] = x;
7004 circumcenters[j + 1] = y;
7005 }
7006
7007 // Compute exterior cell rays.
7008 let h = hull[hull.length - 1];
7009 let p0, p1 = h * 4;
7010 let x0, x1 = points[2 * h];
7011 let y0, y1 = points[2 * h + 1];
7012 vectors.fill(0);
7013 for (let i = 0; i < hull.length; ++i) {
7014 h = hull[i];
7015 p0 = p1, x0 = x1, y0 = y1;
7016 p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1];
7017 vectors[p0 + 2] = vectors[p1] = y0 - y1;
7018 vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
7019 }
7020 }
7021 render(context) {
7022 const buffer = context == null ? context = new Path : undefined;
7023 const {delaunay: {halfedges, inedges, hull}, circumcenters, vectors} = this;
7024 if (hull.length <= 1) return null;
7025 for (let i = 0, n = halfedges.length; i < n; ++i) {
7026 const j = halfedges[i];
7027 if (j < i) continue;
7028 const ti = Math.floor(i / 3) * 2;
7029 const tj = Math.floor(j / 3) * 2;
7030 const xi = circumcenters[ti];
7031 const yi = circumcenters[ti + 1];
7032 const xj = circumcenters[tj];
7033 const yj = circumcenters[tj + 1];
7034 this._renderSegment(xi, yi, xj, yj, context);
7035 }
7036 let h0, h1 = hull[hull.length - 1];
7037 for (let i = 0; i < hull.length; ++i) {
7038 h0 = h1, h1 = hull[i];
7039 const t = Math.floor(inedges[h1] / 3) * 2;
7040 const x = circumcenters[t];
7041 const y = circumcenters[t + 1];
7042 const v = h0 * 4;
7043 const p = this._project(x, y, vectors[v + 2], vectors[v + 3]);
7044 if (p) this._renderSegment(x, y, p[0], p[1], context);
7045 }
7046 return buffer && buffer.value();
7047 }
7048 renderBounds(context) {
7049 const buffer = context == null ? context = new Path : undefined;
7050 context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin);
7051 return buffer && buffer.value();
7052 }
7053 renderCell(i, context) {
7054 const buffer = context == null ? context = new Path : undefined;
7055 const points = this._clip(i);
7056 if (points === null || !points.length) return;
7057 context.moveTo(points[0], points[1]);
7058 let n = points.length;
7059 while (points[0] === points[n-2] && points[1] === points[n-1] && n > 1) n -= 2;
7060 for (let i = 2; i < n; i += 2) {
7061 if (points[i] !== points[i-2] || points[i+1] !== points[i-1])
7062 context.lineTo(points[i], points[i + 1]);
7063 }
7064 context.closePath();
7065 return buffer && buffer.value();
7066 }
7067 *cellPolygons() {
7068 const {delaunay: {points}} = this;
7069 for (let i = 0, n = points.length / 2; i < n; ++i) {
7070 const cell = this.cellPolygon(i);
7071 if (cell) cell.index = i, yield cell;
7072 }
7073 }
7074 cellPolygon(i) {
7075 const polygon = new Polygon;
7076 this.renderCell(i, polygon);
7077 return polygon.value();
7078 }
7079 _renderSegment(x0, y0, x1, y1, context) {
7080 let S;
7081 const c0 = this._regioncode(x0, y0);
7082 const c1 = this._regioncode(x1, y1);
7083 if (c0 === 0 && c1 === 0) {
7084 context.moveTo(x0, y0);
7085 context.lineTo(x1, y1);
7086 } else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) {
7087 context.moveTo(S[0], S[1]);
7088 context.lineTo(S[2], S[3]);
7089 }
7090 }
7091 contains(i, x, y) {
7092 if ((x = +x, x !== x) || (y = +y, y !== y)) return false;
7093 return this.delaunay._step(i, x, y) === i;
7094 }
7095 *neighbors(i) {
7096 const ci = this._clip(i);
7097 if (ci) for (const j of this.delaunay.neighbors(i)) {
7098 const cj = this._clip(j);
7099 // find the common edge
7100 if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) {
7101 for (let aj = 0, lj = cj.length; aj < lj; aj += 2) {
7102 if (ci[ai] == cj[aj]
7103 && ci[ai + 1] == cj[aj + 1]
7104 && ci[(ai + 2) % li] == cj[(aj + lj - 2) % lj]
7105 && ci[(ai + 3) % li] == cj[(aj + lj - 1) % lj]
7106 ) {
7107 yield j;
7108 break loop;
7109 }
7110 }
7111 }
7112 }
7113 }
7114 _cell(i) {
7115 const {circumcenters, delaunay: {inedges, halfedges, triangles}} = this;
7116 const e0 = inedges[i];
7117 if (e0 === -1) return null; // coincident point
7118 const points = [];
7119 let e = e0;
7120 do {
7121 const t = Math.floor(e / 3);
7122 points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]);
7123 e = e % 3 === 2 ? e - 2 : e + 1;
7124 if (triangles[e] !== i) break; // bad triangulation
7125 e = halfedges[e];
7126 } while (e !== e0 && e !== -1);
7127 return points;
7128 }
7129 _clip(i) {
7130 // degenerate case (1 valid point: return the box)
7131 if (i === 0 && this.delaunay.hull.length === 1) {
7132 return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
7133 }
7134 const points = this._cell(i);
7135 if (points === null) return null;
7136 const {vectors: V} = this;
7137 const v = i * 4;
7138 return V[v] || V[v + 1]
7139 ? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3])
7140 : this._clipFinite(i, points);
7141 }
7142 _clipFinite(i, points) {
7143 const n = points.length;
7144 let P = null;
7145 let x0, y0, x1 = points[n - 2], y1 = points[n - 1];
7146 let c0, c1 = this._regioncode(x1, y1);
7147 let e0, e1;
7148 for (let j = 0; j < n; j += 2) {
7149 x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1];
7150 c0 = c1, c1 = this._regioncode(x1, y1);
7151 if (c0 === 0 && c1 === 0) {
7152 e0 = e1, e1 = 0;
7153 if (P) P.push(x1, y1);
7154 else P = [x1, y1];
7155 } else {
7156 let S, sx0, sy0, sx1, sy1;
7157 if (c0 === 0) {
7158 if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue;
7159 [sx0, sy0, sx1, sy1] = S;
7160 } else {
7161 if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue;
7162 [sx1, sy1, sx0, sy0] = S;
7163 e0 = e1, e1 = this._edgecode(sx0, sy0);
7164 if (e0 && e1) this._edge(i, e0, e1, P, P.length);
7165 if (P) P.push(sx0, sy0);
7166 else P = [sx0, sy0];
7167 }
7168 e0 = e1, e1 = this._edgecode(sx1, sy1);
7169 if (e0 && e1) this._edge(i, e0, e1, P, P.length);
7170 if (P) P.push(sx1, sy1);
7171 else P = [sx1, sy1];
7172 }
7173 }
7174 if (P) {
7175 e0 = e1, e1 = this._edgecode(P[0], P[1]);
7176 if (e0 && e1) this._edge(i, e0, e1, P, P.length);
7177 } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
7178 return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
7179 }
7180 return P;
7181 }
7182 _clipSegment(x0, y0, x1, y1, c0, c1) {
7183 while (true) {
7184 if (c0 === 0 && c1 === 0) return [x0, y0, x1, y1];
7185 if (c0 & c1) return null;
7186 let x, y, c = c0 || c1;
7187 if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax;
7188 else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin;
7189 else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax;
7190 else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin;
7191 if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0);
7192 else x1 = x, y1 = y, c1 = this._regioncode(x1, y1);
7193 }
7194 }
7195 _clipInfinite(i, points, vx0, vy0, vxn, vyn) {
7196 let P = Array.from(points), p;
7197 if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]);
7198 if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]);
7199 if (P = this._clipFinite(i, P)) {
7200 for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) {
7201 c0 = c1, c1 = this._edgecode(P[j], P[j + 1]);
7202 if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length;
7203 }
7204 } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
7205 P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax];
7206 }
7207 return P;
7208 }
7209 _edge(i, e0, e1, P, j) {
7210 while (e0 !== e1) {
7211 let x, y;
7212 switch (e0) {
7213 case 0b0101: e0 = 0b0100; continue; // top-left
7214 case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break; // top
7215 case 0b0110: e0 = 0b0010; continue; // top-right
7216 case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break; // right
7217 case 0b1010: e0 = 0b1000; continue; // bottom-right
7218 case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break; // bottom
7219 case 0b1001: e0 = 0b0001; continue; // bottom-left
7220 case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break; // left
7221 }
7222 if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) {
7223 P.splice(j, 0, x, y), j += 2;
7224 }
7225 }
7226 if (P.length > 4) {
7227 for (let i = 0; i < P.length; i+= 2) {
7228 const j = (i + 2) % P.length, k = (i + 4) % P.length;
7229 if (P[i] === P[j] && P[j] === P[k]
7230 || P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1])
7231 P.splice(j, 2), i -= 2;
7232 }
7233 }
7234 return j;
7235 }
7236 _project(x0, y0, vx, vy) {
7237 let t = Infinity, c, x, y;
7238 if (vy < 0) { // top
7239 if (y0 <= this.ymin) return null;
7240 if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx;
7241 } else if (vy > 0) { // bottom
7242 if (y0 >= this.ymax) return null;
7243 if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx;
7244 }
7245 if (vx > 0) { // right
7246 if (x0 >= this.xmax) return null;
7247 if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy;
7248 } else if (vx < 0) { // left
7249 if (x0 <= this.xmin) return null;
7250 if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy;
7251 }
7252 return [x, y];
7253 }
7254 _edgecode(x, y) {
7255 return (x === this.xmin ? 0b0001
7256 : x === this.xmax ? 0b0010 : 0b0000)
7257 | (y === this.ymin ? 0b0100
7258 : y === this.ymax ? 0b1000 : 0b0000);
7259 }
7260 _regioncode(x, y) {
7261 return (x < this.xmin ? 0b0001
7262 : x > this.xmax ? 0b0010 : 0b0000)
7263 | (y < this.ymin ? 0b0100
7264 : y > this.ymax ? 0b1000 : 0b0000);
7265 }
7266}
7267
7268const tau$2 = 2 * Math.PI, pow$2 = Math.pow;
7269
7270function pointX(p) {
7271 return p[0];
7272}
7273
7274function pointY(p) {
7275 return p[1];
7276}
7277
7278// A triangulation is collinear if all its triangles have a non-null area
7279function collinear(d) {
7280 const {triangles, coords} = d;
7281 for (let i = 0; i < triangles.length; i += 3) {
7282 const a = 2 * triangles[i],
7283 b = 2 * triangles[i + 1],
7284 c = 2 * triangles[i + 2],
7285 cross = (coords[c] - coords[a]) * (coords[b + 1] - coords[a + 1])
7286 - (coords[b] - coords[a]) * (coords[c + 1] - coords[a + 1]);
7287 if (cross > 1e-10) return false;
7288 }
7289 return true;
7290}
7291
7292function jitter(x, y, r) {
7293 return [x + Math.sin(x + y) * r, y + Math.cos(x - y) * r];
7294}
7295
7296class Delaunay {
7297 static from(points, fx = pointX, fy = pointY, that) {
7298 return new Delaunay("length" in points
7299 ? flatArray(points, fx, fy, that)
7300 : Float64Array.from(flatIterable(points, fx, fy, that)));
7301 }
7302 constructor(points) {
7303 this._delaunator = new Delaunator(points);
7304 this.inedges = new Int32Array(points.length / 2);
7305 this._hullIndex = new Int32Array(points.length / 2);
7306 this.points = this._delaunator.coords;
7307 this._init();
7308 }
7309 update() {
7310 this._delaunator.update();
7311 this._init();
7312 return this;
7313 }
7314 _init() {
7315 const d = this._delaunator, points = this.points;
7316
7317 // check for collinear
7318 if (d.hull && d.hull.length > 2 && collinear(d)) {
7319 this.collinear = Int32Array.from({length: points.length/2}, (_,i) => i)
7320 .sort((i, j) => points[2 * i] - points[2 * j] || points[2 * i + 1] - points[2 * j + 1]); // for exact neighbors
7321 const e = this.collinear[0], f = this.collinear[this.collinear.length - 1],
7322 bounds = [ points[2 * e], points[2 * e + 1], points[2 * f], points[2 * f + 1] ],
7323 r = 1e-8 * Math.hypot(bounds[3] - bounds[1], bounds[2] - bounds[0]);
7324 for (let i = 0, n = points.length / 2; i < n; ++i) {
7325 const p = jitter(points[2 * i], points[2 * i + 1], r);
7326 points[2 * i] = p[0];
7327 points[2 * i + 1] = p[1];
7328 }
7329 this._delaunator = new Delaunator(points);
7330 } else {
7331 delete this.collinear;
7332 }
7333
7334 const halfedges = this.halfedges = this._delaunator.halfedges;
7335 const hull = this.hull = this._delaunator.hull;
7336 const triangles = this.triangles = this._delaunator.triangles;
7337 const inedges = this.inedges.fill(-1);
7338 const hullIndex = this._hullIndex.fill(-1);
7339
7340 // Compute an index from each point to an (arbitrary) incoming halfedge
7341 // Used to give the first neighbor of each point; for this reason,
7342 // on the hull we give priority to exterior halfedges
7343 for (let e = 0, n = halfedges.length; e < n; ++e) {
7344 const p = triangles[e % 3 === 2 ? e - 2 : e + 1];
7345 if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e;
7346 }
7347 for (let i = 0, n = hull.length; i < n; ++i) {
7348 hullIndex[hull[i]] = i;
7349 }
7350
7351 // degenerate case: 1 or 2 (distinct) points
7352 if (hull.length <= 2 && hull.length > 0) {
7353 this.triangles = new Int32Array(3).fill(-1);
7354 this.halfedges = new Int32Array(3).fill(-1);
7355 this.triangles[0] = hull[0];
7356 this.triangles[1] = hull[1];
7357 this.triangles[2] = hull[1];
7358 inedges[hull[0]] = 1;
7359 if (hull.length === 2) inedges[hull[1]] = 0;
7360 }
7361 }
7362 voronoi(bounds) {
7363 return new Voronoi(this, bounds);
7364 }
7365 *neighbors(i) {
7366 const {inedges, hull, _hullIndex, halfedges, triangles, collinear} = this;
7367
7368 // degenerate case with several collinear points
7369 if (collinear) {
7370 const l = collinear.indexOf(i);
7371 if (l > 0) yield collinear[l - 1];
7372 if (l < collinear.length - 1) yield collinear[l + 1];
7373 return;
7374 }
7375
7376 const e0 = inedges[i];
7377 if (e0 === -1) return; // coincident point
7378 let e = e0, p0 = -1;
7379 do {
7380 yield p0 = triangles[e];
7381 e = e % 3 === 2 ? e - 2 : e + 1;
7382 if (triangles[e] !== i) return; // bad triangulation
7383 e = halfedges[e];
7384 if (e === -1) {
7385 const p = hull[(_hullIndex[i] + 1) % hull.length];
7386 if (p !== p0) yield p;
7387 return;
7388 }
7389 } while (e !== e0);
7390 }
7391 find(x, y, i = 0) {
7392 if ((x = +x, x !== x) || (y = +y, y !== y)) return -1;
7393 const i0 = i;
7394 let c;
7395 while ((c = this._step(i, x, y)) >= 0 && c !== i && c !== i0) i = c;
7396 return c;
7397 }
7398 _step(i, x, y) {
7399 const {inedges, hull, _hullIndex, halfedges, triangles, points} = this;
7400 if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1);
7401 let c = i;
7402 let dc = pow$2(x - points[i * 2], 2) + pow$2(y - points[i * 2 + 1], 2);
7403 const e0 = inedges[i];
7404 let e = e0;
7405 do {
7406 let t = triangles[e];
7407 const dt = pow$2(x - points[t * 2], 2) + pow$2(y - points[t * 2 + 1], 2);
7408 if (dt < dc) dc = dt, c = t;
7409 e = e % 3 === 2 ? e - 2 : e + 1;
7410 if (triangles[e] !== i) break; // bad triangulation
7411 e = halfedges[e];
7412 if (e === -1) {
7413 e = hull[(_hullIndex[i] + 1) % hull.length];
7414 if (e !== t) {
7415 if (pow$2(x - points[e * 2], 2) + pow$2(y - points[e * 2 + 1], 2) < dc) return e;
7416 }
7417 break;
7418 }
7419 } while (e !== e0);
7420 return c;
7421 }
7422 render(context) {
7423 const buffer = context == null ? context = new Path : undefined;
7424 const {points, halfedges, triangles} = this;
7425 for (let i = 0, n = halfedges.length; i < n; ++i) {
7426 const j = halfedges[i];
7427 if (j < i) continue;
7428 const ti = triangles[i] * 2;
7429 const tj = triangles[j] * 2;
7430 context.moveTo(points[ti], points[ti + 1]);
7431 context.lineTo(points[tj], points[tj + 1]);
7432 }
7433 this.renderHull(context);
7434 return buffer && buffer.value();
7435 }
7436 renderPoints(context, r = 2) {
7437 const buffer = context == null ? context = new Path : undefined;
7438 const {points} = this;
7439 for (let i = 0, n = points.length; i < n; i += 2) {
7440 const x = points[i], y = points[i + 1];
7441 context.moveTo(x + r, y);
7442 context.arc(x, y, r, 0, tau$2);
7443 }
7444 return buffer && buffer.value();
7445 }
7446 renderHull(context) {
7447 const buffer = context == null ? context = new Path : undefined;
7448 const {hull, points} = this;
7449 const h = hull[0] * 2, n = hull.length;
7450 context.moveTo(points[h], points[h + 1]);
7451 for (let i = 1; i < n; ++i) {
7452 const h = 2 * hull[i];
7453 context.lineTo(points[h], points[h + 1]);
7454 }
7455 context.closePath();
7456 return buffer && buffer.value();
7457 }
7458 hullPolygon() {
7459 const polygon = new Polygon;
7460 this.renderHull(polygon);
7461 return polygon.value();
7462 }
7463 renderTriangle(i, context) {
7464 const buffer = context == null ? context = new Path : undefined;
7465 const {points, triangles} = this;
7466 const t0 = triangles[i *= 3] * 2;
7467 const t1 = triangles[i + 1] * 2;
7468 const t2 = triangles[i + 2] * 2;
7469 context.moveTo(points[t0], points[t0 + 1]);
7470 context.lineTo(points[t1], points[t1 + 1]);
7471 context.lineTo(points[t2], points[t2 + 1]);
7472 context.closePath();
7473 return buffer && buffer.value();
7474 }
7475 *trianglePolygons() {
7476 const {triangles} = this;
7477 for (let i = 0, n = triangles.length / 3; i < n; ++i) {
7478 yield this.trianglePolygon(i);
7479 }
7480 }
7481 trianglePolygon(i) {
7482 const polygon = new Polygon;
7483 this.renderTriangle(i, polygon);
7484 return polygon.value();
7485 }
7486}
7487
7488function flatArray(points, fx, fy, that) {
7489 const n = points.length;
7490 const array = new Float64Array(n * 2);
7491 for (let i = 0; i < n; ++i) {
7492 const p = points[i];
7493 array[i * 2] = fx.call(that, p, i, points);
7494 array[i * 2 + 1] = fy.call(that, p, i, points);
7495 }
7496 return array;
7497}
7498
7499function* flatIterable(points, fx, fy, that) {
7500 let i = 0;
7501 for (const p of points) {
7502 yield fx.call(that, p, i, points);
7503 yield fy.call(that, p, i, points);
7504 ++i;
7505 }
7506}
7507
7508var EOL = {},
7509 EOF = {},
7510 QUOTE = 34,
7511 NEWLINE = 10,
7512 RETURN = 13;
7513
7514function objectConverter(columns) {
7515 return new Function("d", "return {" + columns.map(function(name, i) {
7516 return JSON.stringify(name) + ": d[" + i + "] || \"\"";
7517 }).join(",") + "}");
7518}
7519
7520function customConverter(columns, f) {
7521 var object = objectConverter(columns);
7522 return function(row, i) {
7523 return f(object(row), i, columns);
7524 };
7525}
7526
7527// Compute unique columns in order of discovery.
7528function inferColumns(rows) {
7529 var columnSet = Object.create(null),
7530 columns = [];
7531
7532 rows.forEach(function(row) {
7533 for (var column in row) {
7534 if (!(column in columnSet)) {
7535 columns.push(columnSet[column] = column);
7536 }
7537 }
7538 });
7539
7540 return columns;
7541}
7542
7543function pad$1(value, width) {
7544 var s = value + "", length = s.length;
7545 return length < width ? new Array(width - length + 1).join(0) + s : s;
7546}
7547
7548function formatYear$1(year) {
7549 return year < 0 ? "-" + pad$1(-year, 6)
7550 : year > 9999 ? "+" + pad$1(year, 6)
7551 : pad$1(year, 4);
7552}
7553
7554function formatDate(date) {
7555 var hours = date.getUTCHours(),
7556 minutes = date.getUTCMinutes(),
7557 seconds = date.getUTCSeconds(),
7558 milliseconds = date.getUTCMilliseconds();
7559 return isNaN(date) ? "Invalid Date"
7560 : formatYear$1(date.getUTCFullYear()) + "-" + pad$1(date.getUTCMonth() + 1, 2) + "-" + pad$1(date.getUTCDate(), 2)
7561 + (milliseconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "." + pad$1(milliseconds, 3) + "Z"
7562 : seconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "Z"
7563 : minutes || hours ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + "Z"
7564 : "");
7565}
7566
7567function dsvFormat(delimiter) {
7568 var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
7569 DELIMITER = delimiter.charCodeAt(0);
7570
7571 function parse(text, f) {
7572 var convert, columns, rows = parseRows(text, function(row, i) {
7573 if (convert) return convert(row, i - 1);
7574 columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
7575 });
7576 rows.columns = columns || [];
7577 return rows;
7578 }
7579
7580 function parseRows(text, f) {
7581 var rows = [], // output rows
7582 N = text.length,
7583 I = 0, // current character index
7584 n = 0, // current line number
7585 t, // current token
7586 eof = N <= 0, // current token followed by EOF?
7587 eol = false; // current token followed by EOL?
7588
7589 // Strip the trailing newline.
7590 if (text.charCodeAt(N - 1) === NEWLINE) --N;
7591 if (text.charCodeAt(N - 1) === RETURN) --N;
7592
7593 function token() {
7594 if (eof) return EOF;
7595 if (eol) return eol = false, EOL;
7596
7597 // Unescape quotes.
7598 var i, j = I, c;
7599 if (text.charCodeAt(j) === QUOTE) {
7600 while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
7601 if ((i = I) >= N) eof = true;
7602 else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
7603 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
7604 return text.slice(j + 1, i - 1).replace(/""/g, "\"");
7605 }
7606
7607 // Find next delimiter or newline.
7608 while (I < N) {
7609 if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
7610 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
7611 else if (c !== DELIMITER) continue;
7612 return text.slice(j, i);
7613 }
7614
7615 // Return last token before EOF.
7616 return eof = true, text.slice(j, N);
7617 }
7618
7619 while ((t = token()) !== EOF) {
7620 var row = [];
7621 while (t !== EOL && t !== EOF) row.push(t), t = token();
7622 if (f && (row = f(row, n++)) == null) continue;
7623 rows.push(row);
7624 }
7625
7626 return rows;
7627 }
7628
7629 function preformatBody(rows, columns) {
7630 return rows.map(function(row) {
7631 return columns.map(function(column) {
7632 return formatValue(row[column]);
7633 }).join(delimiter);
7634 });
7635 }
7636
7637 function format(rows, columns) {
7638 if (columns == null) columns = inferColumns(rows);
7639 return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
7640 }
7641
7642 function formatBody(rows, columns) {
7643 if (columns == null) columns = inferColumns(rows);
7644 return preformatBody(rows, columns).join("\n");
7645 }
7646
7647 function formatRows(rows) {
7648 return rows.map(formatRow).join("\n");
7649 }
7650
7651 function formatRow(row) {
7652 return row.map(formatValue).join(delimiter);
7653 }
7654
7655 function formatValue(value) {
7656 return value == null ? ""
7657 : value instanceof Date ? formatDate(value)
7658 : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
7659 : value;
7660 }
7661
7662 return {
7663 parse: parse,
7664 parseRows: parseRows,
7665 format: format,
7666 formatBody: formatBody,
7667 formatRows: formatRows,
7668 formatRow: formatRow,
7669 formatValue: formatValue
7670 };
7671}
7672
7673var csv$1 = dsvFormat(",");
7674
7675var csvParse = csv$1.parse;
7676var csvParseRows = csv$1.parseRows;
7677var csvFormat = csv$1.format;
7678var csvFormatBody = csv$1.formatBody;
7679var csvFormatRows = csv$1.formatRows;
7680var csvFormatRow = csv$1.formatRow;
7681var csvFormatValue = csv$1.formatValue;
7682
7683var tsv$1 = dsvFormat("\t");
7684
7685var tsvParse = tsv$1.parse;
7686var tsvParseRows = tsv$1.parseRows;
7687var tsvFormat = tsv$1.format;
7688var tsvFormatBody = tsv$1.formatBody;
7689var tsvFormatRows = tsv$1.formatRows;
7690var tsvFormatRow = tsv$1.formatRow;
7691var tsvFormatValue = tsv$1.formatValue;
7692
7693function autoType(object) {
7694 for (var key in object) {
7695 var value = object[key].trim(), number, m;
7696 if (!value) value = null;
7697 else if (value === "true") value = true;
7698 else if (value === "false") value = false;
7699 else if (value === "NaN") value = NaN;
7700 else if (!isNaN(number = +value)) value = number;
7701 else if (m = value.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)) {
7702 if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
7703 value = new Date(value);
7704 }
7705 else continue;
7706 object[key] = value;
7707 }
7708 return object;
7709}
7710
7711// https://github.com/d3/d3-dsv/issues/45
7712const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
7713
7714function responseBlob(response) {
7715 if (!response.ok) throw new Error(response.status + " " + response.statusText);
7716 return response.blob();
7717}
7718
7719function blob(input, init) {
7720 return fetch(input, init).then(responseBlob);
7721}
7722
7723function responseArrayBuffer(response) {
7724 if (!response.ok) throw new Error(response.status + " " + response.statusText);
7725 return response.arrayBuffer();
7726}
7727
7728function buffer(input, init) {
7729 return fetch(input, init).then(responseArrayBuffer);
7730}
7731
7732function responseText(response) {
7733 if (!response.ok) throw new Error(response.status + " " + response.statusText);
7734 return response.text();
7735}
7736
7737function text(input, init) {
7738 return fetch(input, init).then(responseText);
7739}
7740
7741function dsvParse(parse) {
7742 return function(input, init, row) {
7743 if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
7744 return text(input, init).then(function(response) {
7745 return parse(response, row);
7746 });
7747 };
7748}
7749
7750function dsv(delimiter, input, init, row) {
7751 if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
7752 var format = dsvFormat(delimiter);
7753 return text(input, init).then(function(response) {
7754 return format.parse(response, row);
7755 });
7756}
7757
7758var csv = dsvParse(csvParse);
7759var tsv = dsvParse(tsvParse);
7760
7761function image(input, init) {
7762 return new Promise(function(resolve, reject) {
7763 var image = new Image;
7764 for (var key in init) image[key] = init[key];
7765 image.onerror = reject;
7766 image.onload = function() { resolve(image); };
7767 image.src = input;
7768 });
7769}
7770
7771function responseJson(response) {
7772 if (!response.ok) throw new Error(response.status + " " + response.statusText);
7773 if (response.status === 204 || response.status === 205) return;
7774 return response.json();
7775}
7776
7777function json(input, init) {
7778 return fetch(input, init).then(responseJson);
7779}
7780
7781function parser(type) {
7782 return (input, init) => text(input, init)
7783 .then(text => (new DOMParser).parseFromString(text, type));
7784}
7785
7786var xml = parser("application/xml");
7787
7788var html = parser("text/html");
7789
7790var svg = parser("image/svg+xml");
7791
7792function center(x, y) {
7793 var nodes, strength = 1;
7794
7795 if (x == null) x = 0;
7796 if (y == null) y = 0;
7797
7798 function force() {
7799 var i,
7800 n = nodes.length,
7801 node,
7802 sx = 0,
7803 sy = 0;
7804
7805 for (i = 0; i < n; ++i) {
7806 node = nodes[i], sx += node.x, sy += node.y;
7807 }
7808
7809 for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
7810 node = nodes[i], node.x -= sx, node.y -= sy;
7811 }
7812 }
7813
7814 force.initialize = function(_) {
7815 nodes = _;
7816 };
7817
7818 force.x = function(_) {
7819 return arguments.length ? (x = +_, force) : x;
7820 };
7821
7822 force.y = function(_) {
7823 return arguments.length ? (y = +_, force) : y;
7824 };
7825
7826 force.strength = function(_) {
7827 return arguments.length ? (strength = +_, force) : strength;
7828 };
7829
7830 return force;
7831}
7832
7833function tree_add(d) {
7834 const x = +this._x.call(null, d),
7835 y = +this._y.call(null, d);
7836 return add(this.cover(x, y), x, y, d);
7837}
7838
7839function add(tree, x, y, d) {
7840 if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
7841
7842 var parent,
7843 node = tree._root,
7844 leaf = {data: d},
7845 x0 = tree._x0,
7846 y0 = tree._y0,
7847 x1 = tree._x1,
7848 y1 = tree._y1,
7849 xm,
7850 ym,
7851 xp,
7852 yp,
7853 right,
7854 bottom,
7855 i,
7856 j;
7857
7858 // If the tree is empty, initialize the root as a leaf.
7859 if (!node) return tree._root = leaf, tree;
7860
7861 // Find the existing leaf for the new point, or add it.
7862 while (node.length) {
7863 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
7864 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
7865 if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
7866 }
7867
7868 // Is the new point is exactly coincident with the existing point?
7869 xp = +tree._x.call(null, node.data);
7870 yp = +tree._y.call(null, node.data);
7871 if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
7872
7873 // Otherwise, split the leaf node until the old and new point are separated.
7874 do {
7875 parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
7876 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
7877 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
7878 } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
7879 return parent[j] = node, parent[i] = leaf, tree;
7880}
7881
7882function addAll(data) {
7883 var d, i, n = data.length,
7884 x,
7885 y,
7886 xz = new Array(n),
7887 yz = new Array(n),
7888 x0 = Infinity,
7889 y0 = Infinity,
7890 x1 = -Infinity,
7891 y1 = -Infinity;
7892
7893 // Compute the points and their extent.
7894 for (i = 0; i < n; ++i) {
7895 if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
7896 xz[i] = x;
7897 yz[i] = y;
7898 if (x < x0) x0 = x;
7899 if (x > x1) x1 = x;
7900 if (y < y0) y0 = y;
7901 if (y > y1) y1 = y;
7902 }
7903
7904 // If there were no (valid) points, abort.
7905 if (x0 > x1 || y0 > y1) return this;
7906
7907 // Expand the tree to cover the new points.
7908 this.cover(x0, y0).cover(x1, y1);
7909
7910 // Add the new points.
7911 for (i = 0; i < n; ++i) {
7912 add(this, xz[i], yz[i], data[i]);
7913 }
7914
7915 return this;
7916}
7917
7918function tree_cover(x, y) {
7919 if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
7920
7921 var x0 = this._x0,
7922 y0 = this._y0,
7923 x1 = this._x1,
7924 y1 = this._y1;
7925
7926 // If the quadtree has no extent, initialize them.
7927 // Integer extent are necessary so that if we later double the extent,
7928 // the existing quadrant boundaries don’t change due to floating point error!
7929 if (isNaN(x0)) {
7930 x1 = (x0 = Math.floor(x)) + 1;
7931 y1 = (y0 = Math.floor(y)) + 1;
7932 }
7933
7934 // Otherwise, double repeatedly to cover.
7935 else {
7936 var z = x1 - x0 || 1,
7937 node = this._root,
7938 parent,
7939 i;
7940
7941 while (x0 > x || x >= x1 || y0 > y || y >= y1) {
7942 i = (y < y0) << 1 | (x < x0);
7943 parent = new Array(4), parent[i] = node, node = parent, z *= 2;
7944 switch (i) {
7945 case 0: x1 = x0 + z, y1 = y0 + z; break;
7946 case 1: x0 = x1 - z, y1 = y0 + z; break;
7947 case 2: x1 = x0 + z, y0 = y1 - z; break;
7948 case 3: x0 = x1 - z, y0 = y1 - z; break;
7949 }
7950 }
7951
7952 if (this._root && this._root.length) this._root = node;
7953 }
7954
7955 this._x0 = x0;
7956 this._y0 = y0;
7957 this._x1 = x1;
7958 this._y1 = y1;
7959 return this;
7960}
7961
7962function tree_data() {
7963 var data = [];
7964 this.visit(function(node) {
7965 if (!node.length) do data.push(node.data); while (node = node.next)
7966 });
7967 return data;
7968}
7969
7970function tree_extent(_) {
7971 return arguments.length
7972 ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
7973 : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
7974}
7975
7976function Quad(node, x0, y0, x1, y1) {
7977 this.node = node;
7978 this.x0 = x0;
7979 this.y0 = y0;
7980 this.x1 = x1;
7981 this.y1 = y1;
7982}
7983
7984function tree_find(x, y, radius) {
7985 var data,
7986 x0 = this._x0,
7987 y0 = this._y0,
7988 x1,
7989 y1,
7990 x2,
7991 y2,
7992 x3 = this._x1,
7993 y3 = this._y1,
7994 quads = [],
7995 node = this._root,
7996 q,
7997 i;
7998
7999 if (node) quads.push(new Quad(node, x0, y0, x3, y3));
8000 if (radius == null) radius = Infinity;
8001 else {
8002 x0 = x - radius, y0 = y - radius;
8003 x3 = x + radius, y3 = y + radius;
8004 radius *= radius;
8005 }
8006
8007 while (q = quads.pop()) {
8008
8009 // Stop searching if this quadrant can’t contain a closer node.
8010 if (!(node = q.node)
8011 || (x1 = q.x0) > x3
8012 || (y1 = q.y0) > y3
8013 || (x2 = q.x1) < x0
8014 || (y2 = q.y1) < y0) continue;
8015
8016 // Bisect the current quadrant.
8017 if (node.length) {
8018 var xm = (x1 + x2) / 2,
8019 ym = (y1 + y2) / 2;
8020
8021 quads.push(
8022 new Quad(node[3], xm, ym, x2, y2),
8023 new Quad(node[2], x1, ym, xm, y2),
8024 new Quad(node[1], xm, y1, x2, ym),
8025 new Quad(node[0], x1, y1, xm, ym)
8026 );
8027
8028 // Visit the closest quadrant first.
8029 if (i = (y >= ym) << 1 | (x >= xm)) {
8030 q = quads[quads.length - 1];
8031 quads[quads.length - 1] = quads[quads.length - 1 - i];
8032 quads[quads.length - 1 - i] = q;
8033 }
8034 }
8035
8036 // Visit this point. (Visiting coincident points isn’t necessary!)
8037 else {
8038 var dx = x - +this._x.call(null, node.data),
8039 dy = y - +this._y.call(null, node.data),
8040 d2 = dx * dx + dy * dy;
8041 if (d2 < radius) {
8042 var d = Math.sqrt(radius = d2);
8043 x0 = x - d, y0 = y - d;
8044 x3 = x + d, y3 = y + d;
8045 data = node.data;
8046 }
8047 }
8048 }
8049
8050 return data;
8051}
8052
8053function tree_remove(d) {
8054 if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
8055
8056 var parent,
8057 node = this._root,
8058 retainer,
8059 previous,
8060 next,
8061 x0 = this._x0,
8062 y0 = this._y0,
8063 x1 = this._x1,
8064 y1 = this._y1,
8065 x,
8066 y,
8067 xm,
8068 ym,
8069 right,
8070 bottom,
8071 i,
8072 j;
8073
8074 // If the tree is empty, initialize the root as a leaf.
8075 if (!node) return this;
8076
8077 // Find the leaf node for the point.
8078 // While descending, also retain the deepest parent with a non-removed sibling.
8079 if (node.length) while (true) {
8080 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
8081 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
8082 if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
8083 if (!node.length) break;
8084 if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
8085 }
8086
8087 // Find the point to remove.
8088 while (node.data !== d) if (!(previous = node, node = node.next)) return this;
8089 if (next = node.next) delete node.next;
8090
8091 // If there are multiple coincident points, remove just the point.
8092 if (previous) return (next ? previous.next = next : delete previous.next), this;
8093
8094 // If this is the root point, remove it.
8095 if (!parent) return this._root = next, this;
8096
8097 // Remove this leaf.
8098 next ? parent[i] = next : delete parent[i];
8099
8100 // If the parent now contains exactly one leaf, collapse superfluous parents.
8101 if ((node = parent[0] || parent[1] || parent[2] || parent[3])
8102 && node === (parent[3] || parent[2] || parent[1] || parent[0])
8103 && !node.length) {
8104 if (retainer) retainer[j] = node;
8105 else this._root = node;
8106 }
8107
8108 return this;
8109}
8110
8111function removeAll(data) {
8112 for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
8113 return this;
8114}
8115
8116function tree_root() {
8117 return this._root;
8118}
8119
8120function tree_size() {
8121 var size = 0;
8122 this.visit(function(node) {
8123 if (!node.length) do ++size; while (node = node.next)
8124 });
8125 return size;
8126}
8127
8128function tree_visit(callback) {
8129 var quads = [], q, node = this._root, child, x0, y0, x1, y1;
8130 if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
8131 while (q = quads.pop()) {
8132 if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
8133 var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
8134 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
8135 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
8136 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
8137 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
8138 }
8139 }
8140 return this;
8141}
8142
8143function tree_visitAfter(callback) {
8144 var quads = [], next = [], q;
8145 if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
8146 while (q = quads.pop()) {
8147 var node = q.node;
8148 if (node.length) {
8149 var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
8150 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
8151 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
8152 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
8153 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
8154 }
8155 next.push(q);
8156 }
8157 while (q = next.pop()) {
8158 callback(q.node, q.x0, q.y0, q.x1, q.y1);
8159 }
8160 return this;
8161}
8162
8163function defaultX(d) {
8164 return d[0];
8165}
8166
8167function tree_x(_) {
8168 return arguments.length ? (this._x = _, this) : this._x;
8169}
8170
8171function defaultY(d) {
8172 return d[1];
8173}
8174
8175function tree_y(_) {
8176 return arguments.length ? (this._y = _, this) : this._y;
8177}
8178
8179function quadtree(nodes, x, y) {
8180 var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
8181 return nodes == null ? tree : tree.addAll(nodes);
8182}
8183
8184function Quadtree(x, y, x0, y0, x1, y1) {
8185 this._x = x;
8186 this._y = y;
8187 this._x0 = x0;
8188 this._y0 = y0;
8189 this._x1 = x1;
8190 this._y1 = y1;
8191 this._root = undefined;
8192}
8193
8194function leaf_copy(leaf) {
8195 var copy = {data: leaf.data}, next = copy;
8196 while (leaf = leaf.next) next = next.next = {data: leaf.data};
8197 return copy;
8198}
8199
8200var treeProto = quadtree.prototype = Quadtree.prototype;
8201
8202treeProto.copy = function() {
8203 var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
8204 node = this._root,
8205 nodes,
8206 child;
8207
8208 if (!node) return copy;
8209
8210 if (!node.length) return copy._root = leaf_copy(node), copy;
8211
8212 nodes = [{source: node, target: copy._root = new Array(4)}];
8213 while (node = nodes.pop()) {
8214 for (var i = 0; i < 4; ++i) {
8215 if (child = node.source[i]) {
8216 if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
8217 else node.target[i] = leaf_copy(child);
8218 }
8219 }
8220 }
8221
8222 return copy;
8223};
8224
8225treeProto.add = tree_add;
8226treeProto.addAll = addAll;
8227treeProto.cover = tree_cover;
8228treeProto.data = tree_data;
8229treeProto.extent = tree_extent;
8230treeProto.find = tree_find;
8231treeProto.remove = tree_remove;
8232treeProto.removeAll = removeAll;
8233treeProto.root = tree_root;
8234treeProto.size = tree_size;
8235treeProto.visit = tree_visit;
8236treeProto.visitAfter = tree_visitAfter;
8237treeProto.x = tree_x;
8238treeProto.y = tree_y;
8239
8240function constant$4(x) {
8241 return function() {
8242 return x;
8243 };
8244}
8245
8246function jiggle(random) {
8247 return (random() - 0.5) * 1e-6;
8248}
8249
8250function x$3(d) {
8251 return d.x + d.vx;
8252}
8253
8254function y$3(d) {
8255 return d.y + d.vy;
8256}
8257
8258function collide(radius) {
8259 var nodes,
8260 radii,
8261 random,
8262 strength = 1,
8263 iterations = 1;
8264
8265 if (typeof radius !== "function") radius = constant$4(radius == null ? 1 : +radius);
8266
8267 function force() {
8268 var i, n = nodes.length,
8269 tree,
8270 node,
8271 xi,
8272 yi,
8273 ri,
8274 ri2;
8275
8276 for (var k = 0; k < iterations; ++k) {
8277 tree = quadtree(nodes, x$3, y$3).visitAfter(prepare);
8278 for (i = 0; i < n; ++i) {
8279 node = nodes[i];
8280 ri = radii[node.index], ri2 = ri * ri;
8281 xi = node.x + node.vx;
8282 yi = node.y + node.vy;
8283 tree.visit(apply);
8284 }
8285 }
8286
8287 function apply(quad, x0, y0, x1, y1) {
8288 var data = quad.data, rj = quad.r, r = ri + rj;
8289 if (data) {
8290 if (data.index > node.index) {
8291 var x = xi - data.x - data.vx,
8292 y = yi - data.y - data.vy,
8293 l = x * x + y * y;
8294 if (l < r * r) {
8295 if (x === 0) x = jiggle(random), l += x * x;
8296 if (y === 0) y = jiggle(random), l += y * y;
8297 l = (r - (l = Math.sqrt(l))) / l * strength;
8298 node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
8299 node.vy += (y *= l) * r;
8300 data.vx -= x * (r = 1 - r);
8301 data.vy -= y * r;
8302 }
8303 }
8304 return;
8305 }
8306 return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
8307 }
8308 }
8309
8310 function prepare(quad) {
8311 if (quad.data) return quad.r = radii[quad.data.index];
8312 for (var i = quad.r = 0; i < 4; ++i) {
8313 if (quad[i] && quad[i].r > quad.r) {
8314 quad.r = quad[i].r;
8315 }
8316 }
8317 }
8318
8319 function initialize() {
8320 if (!nodes) return;
8321 var i, n = nodes.length, node;
8322 radii = new Array(n);
8323 for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
8324 }
8325
8326 force.initialize = function(_nodes, _random) {
8327 nodes = _nodes;
8328 random = _random;
8329 initialize();
8330 };
8331
8332 force.iterations = function(_) {
8333 return arguments.length ? (iterations = +_, force) : iterations;
8334 };
8335
8336 force.strength = function(_) {
8337 return arguments.length ? (strength = +_, force) : strength;
8338 };
8339
8340 force.radius = function(_) {
8341 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
8342 };
8343
8344 return force;
8345}
8346
8347function index$3(d) {
8348 return d.index;
8349}
8350
8351function find(nodeById, nodeId) {
8352 var node = nodeById.get(nodeId);
8353 if (!node) throw new Error("node not found: " + nodeId);
8354 return node;
8355}
8356
8357function link$2(links) {
8358 var id = index$3,
8359 strength = defaultStrength,
8360 strengths,
8361 distance = constant$4(30),
8362 distances,
8363 nodes,
8364 count,
8365 bias,
8366 random,
8367 iterations = 1;
8368
8369 if (links == null) links = [];
8370
8371 function defaultStrength(link) {
8372 return 1 / Math.min(count[link.source.index], count[link.target.index]);
8373 }
8374
8375 function force(alpha) {
8376 for (var k = 0, n = links.length; k < iterations; ++k) {
8377 for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
8378 link = links[i], source = link.source, target = link.target;
8379 x = target.x + target.vx - source.x - source.vx || jiggle(random);
8380 y = target.y + target.vy - source.y - source.vy || jiggle(random);
8381 l = Math.sqrt(x * x + y * y);
8382 l = (l - distances[i]) / l * alpha * strengths[i];
8383 x *= l, y *= l;
8384 target.vx -= x * (b = bias[i]);
8385 target.vy -= y * b;
8386 source.vx += x * (b = 1 - b);
8387 source.vy += y * b;
8388 }
8389 }
8390 }
8391
8392 function initialize() {
8393 if (!nodes) return;
8394
8395 var i,
8396 n = nodes.length,
8397 m = links.length,
8398 nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
8399 link;
8400
8401 for (i = 0, count = new Array(n); i < m; ++i) {
8402 link = links[i], link.index = i;
8403 if (typeof link.source !== "object") link.source = find(nodeById, link.source);
8404 if (typeof link.target !== "object") link.target = find(nodeById, link.target);
8405 count[link.source.index] = (count[link.source.index] || 0) + 1;
8406 count[link.target.index] = (count[link.target.index] || 0) + 1;
8407 }
8408
8409 for (i = 0, bias = new Array(m); i < m; ++i) {
8410 link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
8411 }
8412
8413 strengths = new Array(m), initializeStrength();
8414 distances = new Array(m), initializeDistance();
8415 }
8416
8417 function initializeStrength() {
8418 if (!nodes) return;
8419
8420 for (var i = 0, n = links.length; i < n; ++i) {
8421 strengths[i] = +strength(links[i], i, links);
8422 }
8423 }
8424
8425 function initializeDistance() {
8426 if (!nodes) return;
8427
8428 for (var i = 0, n = links.length; i < n; ++i) {
8429 distances[i] = +distance(links[i], i, links);
8430 }
8431 }
8432
8433 force.initialize = function(_nodes, _random) {
8434 nodes = _nodes;
8435 random = _random;
8436 initialize();
8437 };
8438
8439 force.links = function(_) {
8440 return arguments.length ? (links = _, initialize(), force) : links;
8441 };
8442
8443 force.id = function(_) {
8444 return arguments.length ? (id = _, force) : id;
8445 };
8446
8447 force.iterations = function(_) {
8448 return arguments.length ? (iterations = +_, force) : iterations;
8449 };
8450
8451 force.strength = function(_) {
8452 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initializeStrength(), force) : strength;
8453 };
8454
8455 force.distance = function(_) {
8456 return arguments.length ? (distance = typeof _ === "function" ? _ : constant$4(+_), initializeDistance(), force) : distance;
8457 };
8458
8459 return force;
8460}
8461
8462// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
8463const a$1 = 1664525;
8464const c$3 = 1013904223;
8465const m = 4294967296; // 2^32
8466
8467function lcg$1() {
8468 let s = 1;
8469 return () => (s = (a$1 * s + c$3) % m) / m;
8470}
8471
8472function x$2(d) {
8473 return d.x;
8474}
8475
8476function y$2(d) {
8477 return d.y;
8478}
8479
8480var initialRadius = 10,
8481 initialAngle = Math.PI * (3 - Math.sqrt(5));
8482
8483function simulation(nodes) {
8484 var simulation,
8485 alpha = 1,
8486 alphaMin = 0.001,
8487 alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
8488 alphaTarget = 0,
8489 velocityDecay = 0.6,
8490 forces = new Map(),
8491 stepper = timer(step),
8492 event = dispatch("tick", "end"),
8493 random = lcg$1();
8494
8495 if (nodes == null) nodes = [];
8496
8497 function step() {
8498 tick();
8499 event.call("tick", simulation);
8500 if (alpha < alphaMin) {
8501 stepper.stop();
8502 event.call("end", simulation);
8503 }
8504 }
8505
8506 function tick(iterations) {
8507 var i, n = nodes.length, node;
8508
8509 if (iterations === undefined) iterations = 1;
8510
8511 for (var k = 0; k < iterations; ++k) {
8512 alpha += (alphaTarget - alpha) * alphaDecay;
8513
8514 forces.forEach(function(force) {
8515 force(alpha);
8516 });
8517
8518 for (i = 0; i < n; ++i) {
8519 node = nodes[i];
8520 if (node.fx == null) node.x += node.vx *= velocityDecay;
8521 else node.x = node.fx, node.vx = 0;
8522 if (node.fy == null) node.y += node.vy *= velocityDecay;
8523 else node.y = node.fy, node.vy = 0;
8524 }
8525 }
8526
8527 return simulation;
8528 }
8529
8530 function initializeNodes() {
8531 for (var i = 0, n = nodes.length, node; i < n; ++i) {
8532 node = nodes[i], node.index = i;
8533 if (node.fx != null) node.x = node.fx;
8534 if (node.fy != null) node.y = node.fy;
8535 if (isNaN(node.x) || isNaN(node.y)) {
8536 var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
8537 node.x = radius * Math.cos(angle);
8538 node.y = radius * Math.sin(angle);
8539 }
8540 if (isNaN(node.vx) || isNaN(node.vy)) {
8541 node.vx = node.vy = 0;
8542 }
8543 }
8544 }
8545
8546 function initializeForce(force) {
8547 if (force.initialize) force.initialize(nodes, random);
8548 return force;
8549 }
8550
8551 initializeNodes();
8552
8553 return simulation = {
8554 tick: tick,
8555
8556 restart: function() {
8557 return stepper.restart(step), simulation;
8558 },
8559
8560 stop: function() {
8561 return stepper.stop(), simulation;
8562 },
8563
8564 nodes: function(_) {
8565 return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
8566 },
8567
8568 alpha: function(_) {
8569 return arguments.length ? (alpha = +_, simulation) : alpha;
8570 },
8571
8572 alphaMin: function(_) {
8573 return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
8574 },
8575
8576 alphaDecay: function(_) {
8577 return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
8578 },
8579
8580 alphaTarget: function(_) {
8581 return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
8582 },
8583
8584 velocityDecay: function(_) {
8585 return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
8586 },
8587
8588 randomSource: function(_) {
8589 return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
8590 },
8591
8592 force: function(name, _) {
8593 return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
8594 },
8595
8596 find: function(x, y, radius) {
8597 var i = 0,
8598 n = nodes.length,
8599 dx,
8600 dy,
8601 d2,
8602 node,
8603 closest;
8604
8605 if (radius == null) radius = Infinity;
8606 else radius *= radius;
8607
8608 for (i = 0; i < n; ++i) {
8609 node = nodes[i];
8610 dx = x - node.x;
8611 dy = y - node.y;
8612 d2 = dx * dx + dy * dy;
8613 if (d2 < radius) closest = node, radius = d2;
8614 }
8615
8616 return closest;
8617 },
8618
8619 on: function(name, _) {
8620 return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
8621 }
8622 };
8623}
8624
8625function manyBody() {
8626 var nodes,
8627 node,
8628 random,
8629 alpha,
8630 strength = constant$4(-30),
8631 strengths,
8632 distanceMin2 = 1,
8633 distanceMax2 = Infinity,
8634 theta2 = 0.81;
8635
8636 function force(_) {
8637 var i, n = nodes.length, tree = quadtree(nodes, x$2, y$2).visitAfter(accumulate);
8638 for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
8639 }
8640
8641 function initialize() {
8642 if (!nodes) return;
8643 var i, n = nodes.length, node;
8644 strengths = new Array(n);
8645 for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
8646 }
8647
8648 function accumulate(quad) {
8649 var strength = 0, q, c, weight = 0, x, y, i;
8650
8651 // For internal nodes, accumulate forces from child quadrants.
8652 if (quad.length) {
8653 for (x = y = i = 0; i < 4; ++i) {
8654 if ((q = quad[i]) && (c = Math.abs(q.value))) {
8655 strength += q.value, weight += c, x += c * q.x, y += c * q.y;
8656 }
8657 }
8658 quad.x = x / weight;
8659 quad.y = y / weight;
8660 }
8661
8662 // For leaf nodes, accumulate forces from coincident quadrants.
8663 else {
8664 q = quad;
8665 q.x = q.data.x;
8666 q.y = q.data.y;
8667 do strength += strengths[q.data.index];
8668 while (q = q.next);
8669 }
8670
8671 quad.value = strength;
8672 }
8673
8674 function apply(quad, x1, _, x2) {
8675 if (!quad.value) return true;
8676
8677 var x = quad.x - node.x,
8678 y = quad.y - node.y,
8679 w = x2 - x1,
8680 l = x * x + y * y;
8681
8682 // Apply the Barnes-Hut approximation if possible.
8683 // Limit forces for very close nodes; randomize direction if coincident.
8684 if (w * w / theta2 < l) {
8685 if (l < distanceMax2) {
8686 if (x === 0) x = jiggle(random), l += x * x;
8687 if (y === 0) y = jiggle(random), l += y * y;
8688 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
8689 node.vx += x * quad.value * alpha / l;
8690 node.vy += y * quad.value * alpha / l;
8691 }
8692 return true;
8693 }
8694
8695 // Otherwise, process points directly.
8696 else if (quad.length || l >= distanceMax2) return;
8697
8698 // Limit forces for very close nodes; randomize direction if coincident.
8699 if (quad.data !== node || quad.next) {
8700 if (x === 0) x = jiggle(random), l += x * x;
8701 if (y === 0) y = jiggle(random), l += y * y;
8702 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
8703 }
8704
8705 do if (quad.data !== node) {
8706 w = strengths[quad.data.index] * alpha / l;
8707 node.vx += x * w;
8708 node.vy += y * w;
8709 } while (quad = quad.next);
8710 }
8711
8712 force.initialize = function(_nodes, _random) {
8713 nodes = _nodes;
8714 random = _random;
8715 initialize();
8716 };
8717
8718 force.strength = function(_) {
8719 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
8720 };
8721
8722 force.distanceMin = function(_) {
8723 return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
8724 };
8725
8726 force.distanceMax = function(_) {
8727 return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
8728 };
8729
8730 force.theta = function(_) {
8731 return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
8732 };
8733
8734 return force;
8735}
8736
8737function radial$1(radius, x, y) {
8738 var nodes,
8739 strength = constant$4(0.1),
8740 strengths,
8741 radiuses;
8742
8743 if (typeof radius !== "function") radius = constant$4(+radius);
8744 if (x == null) x = 0;
8745 if (y == null) y = 0;
8746
8747 function force(alpha) {
8748 for (var i = 0, n = nodes.length; i < n; ++i) {
8749 var node = nodes[i],
8750 dx = node.x - x || 1e-6,
8751 dy = node.y - y || 1e-6,
8752 r = Math.sqrt(dx * dx + dy * dy),
8753 k = (radiuses[i] - r) * strengths[i] * alpha / r;
8754 node.vx += dx * k;
8755 node.vy += dy * k;
8756 }
8757 }
8758
8759 function initialize() {
8760 if (!nodes) return;
8761 var i, n = nodes.length;
8762 strengths = new Array(n);
8763 radiuses = new Array(n);
8764 for (i = 0; i < n; ++i) {
8765 radiuses[i] = +radius(nodes[i], i, nodes);
8766 strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
8767 }
8768 }
8769
8770 force.initialize = function(_) {
8771 nodes = _, initialize();
8772 };
8773
8774 force.strength = function(_) {
8775 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
8776 };
8777
8778 force.radius = function(_) {
8779 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
8780 };
8781
8782 force.x = function(_) {
8783 return arguments.length ? (x = +_, force) : x;
8784 };
8785
8786 force.y = function(_) {
8787 return arguments.length ? (y = +_, force) : y;
8788 };
8789
8790 return force;
8791}
8792
8793function x$1(x) {
8794 var strength = constant$4(0.1),
8795 nodes,
8796 strengths,
8797 xz;
8798
8799 if (typeof x !== "function") x = constant$4(x == null ? 0 : +x);
8800
8801 function force(alpha) {
8802 for (var i = 0, n = nodes.length, node; i < n; ++i) {
8803 node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
8804 }
8805 }
8806
8807 function initialize() {
8808 if (!nodes) return;
8809 var i, n = nodes.length;
8810 strengths = new Array(n);
8811 xz = new Array(n);
8812 for (i = 0; i < n; ++i) {
8813 strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
8814 }
8815 }
8816
8817 force.initialize = function(_) {
8818 nodes = _;
8819 initialize();
8820 };
8821
8822 force.strength = function(_) {
8823 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
8824 };
8825
8826 force.x = function(_) {
8827 return arguments.length ? (x = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : x;
8828 };
8829
8830 return force;
8831}
8832
8833function y$1(y) {
8834 var strength = constant$4(0.1),
8835 nodes,
8836 strengths,
8837 yz;
8838
8839 if (typeof y !== "function") y = constant$4(y == null ? 0 : +y);
8840
8841 function force(alpha) {
8842 for (var i = 0, n = nodes.length, node; i < n; ++i) {
8843 node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
8844 }
8845 }
8846
8847 function initialize() {
8848 if (!nodes) return;
8849 var i, n = nodes.length;
8850 strengths = new Array(n);
8851 yz = new Array(n);
8852 for (i = 0; i < n; ++i) {
8853 strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
8854 }
8855 }
8856
8857 force.initialize = function(_) {
8858 nodes = _;
8859 initialize();
8860 };
8861
8862 force.strength = function(_) {
8863 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
8864 };
8865
8866 force.y = function(_) {
8867 return arguments.length ? (y = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : y;
8868 };
8869
8870 return force;
8871}
8872
8873function formatDecimal(x) {
8874 return Math.abs(x = Math.round(x)) >= 1e21
8875 ? x.toLocaleString("en").replace(/,/g, "")
8876 : x.toString(10);
8877}
8878
8879// Computes the decimal coefficient and exponent of the specified number x with
8880// significant digits p, where x is positive and p is in [1, 21] or undefined.
8881// For example, formatDecimalParts(1.23) returns ["123", 0].
8882function formatDecimalParts(x, p) {
8883 if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
8884 var i, coefficient = x.slice(0, i);
8885
8886 // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
8887 // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
8888 return [
8889 coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
8890 +x.slice(i + 1)
8891 ];
8892}
8893
8894function exponent(x) {
8895 return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
8896}
8897
8898function formatGroup(grouping, thousands) {
8899 return function(value, width) {
8900 var i = value.length,
8901 t = [],
8902 j = 0,
8903 g = grouping[0],
8904 length = 0;
8905
8906 while (i > 0 && g > 0) {
8907 if (length + g + 1 > width) g = Math.max(1, width - length);
8908 t.push(value.substring(i -= g, i + g));
8909 if ((length += g + 1) > width) break;
8910 g = grouping[j = (j + 1) % grouping.length];
8911 }
8912
8913 return t.reverse().join(thousands);
8914 };
8915}
8916
8917function formatNumerals(numerals) {
8918 return function(value) {
8919 return value.replace(/[0-9]/g, function(i) {
8920 return numerals[+i];
8921 });
8922 };
8923}
8924
8925// [[fill]align][sign][symbol][0][width][,][.precision][~][type]
8926var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
8927
8928function formatSpecifier(specifier) {
8929 if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
8930 var match;
8931 return new FormatSpecifier({
8932 fill: match[1],
8933 align: match[2],
8934 sign: match[3],
8935 symbol: match[4],
8936 zero: match[5],
8937 width: match[6],
8938 comma: match[7],
8939 precision: match[8] && match[8].slice(1),
8940 trim: match[9],
8941 type: match[10]
8942 });
8943}
8944
8945formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
8946
8947function FormatSpecifier(specifier) {
8948 this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
8949 this.align = specifier.align === undefined ? ">" : specifier.align + "";
8950 this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
8951 this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
8952 this.zero = !!specifier.zero;
8953 this.width = specifier.width === undefined ? undefined : +specifier.width;
8954 this.comma = !!specifier.comma;
8955 this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
8956 this.trim = !!specifier.trim;
8957 this.type = specifier.type === undefined ? "" : specifier.type + "";
8958}
8959
8960FormatSpecifier.prototype.toString = function() {
8961 return this.fill
8962 + this.align
8963 + this.sign
8964 + this.symbol
8965 + (this.zero ? "0" : "")
8966 + (this.width === undefined ? "" : Math.max(1, this.width | 0))
8967 + (this.comma ? "," : "")
8968 + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
8969 + (this.trim ? "~" : "")
8970 + this.type;
8971};
8972
8973// Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
8974function formatTrim(s) {
8975 out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
8976 switch (s[i]) {
8977 case ".": i0 = i1 = i; break;
8978 case "0": if (i0 === 0) i0 = i; i1 = i; break;
8979 default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
8980 }
8981 }
8982 return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
8983}
8984
8985var prefixExponent;
8986
8987function formatPrefixAuto(x, p) {
8988 var d = formatDecimalParts(x, p);
8989 if (!d) return x + "";
8990 var coefficient = d[0],
8991 exponent = d[1],
8992 i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
8993 n = coefficient.length;
8994 return i === n ? coefficient
8995 : i > n ? coefficient + new Array(i - n + 1).join("0")
8996 : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
8997 : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
8998}
8999
9000function formatRounded(x, p) {
9001 var d = formatDecimalParts(x, p);
9002 if (!d) return x + "";
9003 var coefficient = d[0],
9004 exponent = d[1];
9005 return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
9006 : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
9007 : coefficient + new Array(exponent - coefficient.length + 2).join("0");
9008}
9009
9010var formatTypes = {
9011 "%": (x, p) => (x * 100).toFixed(p),
9012 "b": (x) => Math.round(x).toString(2),
9013 "c": (x) => x + "",
9014 "d": formatDecimal,
9015 "e": (x, p) => x.toExponential(p),
9016 "f": (x, p) => x.toFixed(p),
9017 "g": (x, p) => x.toPrecision(p),
9018 "o": (x) => Math.round(x).toString(8),
9019 "p": (x, p) => formatRounded(x * 100, p),
9020 "r": formatRounded,
9021 "s": formatPrefixAuto,
9022 "X": (x) => Math.round(x).toString(16).toUpperCase(),
9023 "x": (x) => Math.round(x).toString(16)
9024};
9025
9026function identity$6(x) {
9027 return x;
9028}
9029
9030var map = Array.prototype.map,
9031 prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
9032
9033function formatLocale$1(locale) {
9034 var group = locale.grouping === undefined || locale.thousands === undefined ? identity$6 : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""),
9035 currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
9036 currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
9037 decimal = locale.decimal === undefined ? "." : locale.decimal + "",
9038 numerals = locale.numerals === undefined ? identity$6 : formatNumerals(map.call(locale.numerals, String)),
9039 percent = locale.percent === undefined ? "%" : locale.percent + "",
9040 minus = locale.minus === undefined ? "\u2212" : locale.minus + "",
9041 nan = locale.nan === undefined ? "NaN" : locale.nan + "";
9042
9043 function newFormat(specifier) {
9044 specifier = formatSpecifier(specifier);
9045
9046 var fill = specifier.fill,
9047 align = specifier.align,
9048 sign = specifier.sign,
9049 symbol = specifier.symbol,
9050 zero = specifier.zero,
9051 width = specifier.width,
9052 comma = specifier.comma,
9053 precision = specifier.precision,
9054 trim = specifier.trim,
9055 type = specifier.type;
9056
9057 // The "n" type is an alias for ",g".
9058 if (type === "n") comma = true, type = "g";
9059
9060 // The "" type, and any invalid type, is an alias for ".12~g".
9061 else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
9062
9063 // If zero fill is specified, padding goes after sign and before digits.
9064 if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
9065
9066 // Compute the prefix and suffix.
9067 // For SI-prefix, the suffix is lazily computed.
9068 var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
9069 suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
9070
9071 // What format function should we use?
9072 // Is this an integer type?
9073 // Can this type generate exponential notation?
9074 var formatType = formatTypes[type],
9075 maybeSuffix = /[defgprs%]/.test(type);
9076
9077 // Set the default precision if not specified,
9078 // or clamp the specified precision to the supported range.
9079 // For significant precision, it must be in [1, 21].
9080 // For fixed precision, it must be in [0, 20].
9081 precision = precision === undefined ? 6
9082 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
9083 : Math.max(0, Math.min(20, precision));
9084
9085 function format(value) {
9086 var valuePrefix = prefix,
9087 valueSuffix = suffix,
9088 i, n, c;
9089
9090 if (type === "c") {
9091 valueSuffix = formatType(value) + valueSuffix;
9092 value = "";
9093 } else {
9094 value = +value;
9095
9096 // Determine the sign. -0 is not less than 0, but 1 / -0 is!
9097 var valueNegative = value < 0 || 1 / value < 0;
9098
9099 // Perform the initial formatting.
9100 value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
9101
9102 // Trim insignificant zeros.
9103 if (trim) value = formatTrim(value);
9104
9105 // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
9106 if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
9107
9108 // Compute the prefix and suffix.
9109 valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
9110 valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
9111
9112 // Break the formatted value into the integer “value” part that can be
9113 // grouped, and fractional or exponential “suffix” part that is not.
9114 if (maybeSuffix) {
9115 i = -1, n = value.length;
9116 while (++i < n) {
9117 if (c = value.charCodeAt(i), 48 > c || c > 57) {
9118 valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
9119 value = value.slice(0, i);
9120 break;
9121 }
9122 }
9123 }
9124 }
9125
9126 // If the fill character is not "0", grouping is applied before padding.
9127 if (comma && !zero) value = group(value, Infinity);
9128
9129 // Compute the padding.
9130 var length = valuePrefix.length + value.length + valueSuffix.length,
9131 padding = length < width ? new Array(width - length + 1).join(fill) : "";
9132
9133 // If the fill character is "0", grouping is applied after padding.
9134 if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
9135
9136 // Reconstruct the final output based on the desired alignment.
9137 switch (align) {
9138 case "<": value = valuePrefix + value + valueSuffix + padding; break;
9139 case "=": value = valuePrefix + padding + value + valueSuffix; break;
9140 case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
9141 default: value = padding + valuePrefix + value + valueSuffix; break;
9142 }
9143
9144 return numerals(value);
9145 }
9146
9147 format.toString = function() {
9148 return specifier + "";
9149 };
9150
9151 return format;
9152 }
9153
9154 function formatPrefix(specifier, value) {
9155 var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
9156 e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
9157 k = Math.pow(10, -e),
9158 prefix = prefixes[8 + e / 3];
9159 return function(value) {
9160 return f(k * value) + prefix;
9161 };
9162 }
9163
9164 return {
9165 format: newFormat,
9166 formatPrefix: formatPrefix
9167 };
9168}
9169
9170var locale$1;
9171exports.format = void 0;
9172exports.formatPrefix = void 0;
9173
9174defaultLocale$1({
9175 thousands: ",",
9176 grouping: [3],
9177 currency: ["$", ""]
9178});
9179
9180function defaultLocale$1(definition) {
9181 locale$1 = formatLocale$1(definition);
9182 exports.format = locale$1.format;
9183 exports.formatPrefix = locale$1.formatPrefix;
9184 return locale$1;
9185}
9186
9187function precisionFixed(step) {
9188 return Math.max(0, -exponent(Math.abs(step)));
9189}
9190
9191function precisionPrefix(step, value) {
9192 return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
9193}
9194
9195function precisionRound(step, max) {
9196 step = Math.abs(step), max = Math.abs(max) - step;
9197 return Math.max(0, exponent(max) - exponent(step)) + 1;
9198}
9199
9200var epsilon$1 = 1e-6;
9201var epsilon2 = 1e-12;
9202var pi$1 = Math.PI;
9203var halfPi$1 = pi$1 / 2;
9204var quarterPi = pi$1 / 4;
9205var tau$1 = pi$1 * 2;
9206
9207var degrees = 180 / pi$1;
9208var radians = pi$1 / 180;
9209
9210var abs$1 = Math.abs;
9211var atan = Math.atan;
9212var atan2$1 = Math.atan2;
9213var cos$1 = Math.cos;
9214var ceil = Math.ceil;
9215var exp = Math.exp;
9216var hypot = Math.hypot;
9217var log$1 = Math.log;
9218var pow$1 = Math.pow;
9219var sin$1 = Math.sin;
9220var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
9221var sqrt$2 = Math.sqrt;
9222var tan = Math.tan;
9223
9224function acos$1(x) {
9225 return x > 1 ? 0 : x < -1 ? pi$1 : Math.acos(x);
9226}
9227
9228function asin$1(x) {
9229 return x > 1 ? halfPi$1 : x < -1 ? -halfPi$1 : Math.asin(x);
9230}
9231
9232function haversin(x) {
9233 return (x = sin$1(x / 2)) * x;
9234}
9235
9236function noop$1() {}
9237
9238function streamGeometry(geometry, stream) {
9239 if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
9240 streamGeometryType[geometry.type](geometry, stream);
9241 }
9242}
9243
9244var streamObjectType = {
9245 Feature: function(object, stream) {
9246 streamGeometry(object.geometry, stream);
9247 },
9248 FeatureCollection: function(object, stream) {
9249 var features = object.features, i = -1, n = features.length;
9250 while (++i < n) streamGeometry(features[i].geometry, stream);
9251 }
9252};
9253
9254var streamGeometryType = {
9255 Sphere: function(object, stream) {
9256 stream.sphere();
9257 },
9258 Point: function(object, stream) {
9259 object = object.coordinates;
9260 stream.point(object[0], object[1], object[2]);
9261 },
9262 MultiPoint: function(object, stream) {
9263 var coordinates = object.coordinates, i = -1, n = coordinates.length;
9264 while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
9265 },
9266 LineString: function(object, stream) {
9267 streamLine(object.coordinates, stream, 0);
9268 },
9269 MultiLineString: function(object, stream) {
9270 var coordinates = object.coordinates, i = -1, n = coordinates.length;
9271 while (++i < n) streamLine(coordinates[i], stream, 0);
9272 },
9273 Polygon: function(object, stream) {
9274 streamPolygon(object.coordinates, stream);
9275 },
9276 MultiPolygon: function(object, stream) {
9277 var coordinates = object.coordinates, i = -1, n = coordinates.length;
9278 while (++i < n) streamPolygon(coordinates[i], stream);
9279 },
9280 GeometryCollection: function(object, stream) {
9281 var geometries = object.geometries, i = -1, n = geometries.length;
9282 while (++i < n) streamGeometry(geometries[i], stream);
9283 }
9284};
9285
9286function streamLine(coordinates, stream, closed) {
9287 var i = -1, n = coordinates.length - closed, coordinate;
9288 stream.lineStart();
9289 while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
9290 stream.lineEnd();
9291}
9292
9293function streamPolygon(coordinates, stream) {
9294 var i = -1, n = coordinates.length;
9295 stream.polygonStart();
9296 while (++i < n) streamLine(coordinates[i], stream, 1);
9297 stream.polygonEnd();
9298}
9299
9300function geoStream(object, stream) {
9301 if (object && streamObjectType.hasOwnProperty(object.type)) {
9302 streamObjectType[object.type](object, stream);
9303 } else {
9304 streamGeometry(object, stream);
9305 }
9306}
9307
9308var areaRingSum$1 = new Adder();
9309
9310// hello?
9311
9312var areaSum$1 = new Adder(),
9313 lambda00$2,
9314 phi00$2,
9315 lambda0$2,
9316 cosPhi0$1,
9317 sinPhi0$1;
9318
9319var areaStream$1 = {
9320 point: noop$1,
9321 lineStart: noop$1,
9322 lineEnd: noop$1,
9323 polygonStart: function() {
9324 areaRingSum$1 = new Adder();
9325 areaStream$1.lineStart = areaRingStart$1;
9326 areaStream$1.lineEnd = areaRingEnd$1;
9327 },
9328 polygonEnd: function() {
9329 var areaRing = +areaRingSum$1;
9330 areaSum$1.add(areaRing < 0 ? tau$1 + areaRing : areaRing);
9331 this.lineStart = this.lineEnd = this.point = noop$1;
9332 },
9333 sphere: function() {
9334 areaSum$1.add(tau$1);
9335 }
9336};
9337
9338function areaRingStart$1() {
9339 areaStream$1.point = areaPointFirst$1;
9340}
9341
9342function areaRingEnd$1() {
9343 areaPoint$1(lambda00$2, phi00$2);
9344}
9345
9346function areaPointFirst$1(lambda, phi) {
9347 areaStream$1.point = areaPoint$1;
9348 lambda00$2 = lambda, phi00$2 = phi;
9349 lambda *= radians, phi *= radians;
9350 lambda0$2 = lambda, cosPhi0$1 = cos$1(phi = phi / 2 + quarterPi), sinPhi0$1 = sin$1(phi);
9351}
9352
9353function areaPoint$1(lambda, phi) {
9354 lambda *= radians, phi *= radians;
9355 phi = phi / 2 + quarterPi; // half the angular distance from south pole
9356
9357 // Spherical excess E for a spherical triangle with vertices: south pole,
9358 // previous point, current point. Uses a formula derived from Cagnoli’s
9359 // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
9360 var dLambda = lambda - lambda0$2,
9361 sdLambda = dLambda >= 0 ? 1 : -1,
9362 adLambda = sdLambda * dLambda,
9363 cosPhi = cos$1(phi),
9364 sinPhi = sin$1(phi),
9365 k = sinPhi0$1 * sinPhi,
9366 u = cosPhi0$1 * cosPhi + k * cos$1(adLambda),
9367 v = k * sdLambda * sin$1(adLambda);
9368 areaRingSum$1.add(atan2$1(v, u));
9369
9370 // Advance the previous points.
9371 lambda0$2 = lambda, cosPhi0$1 = cosPhi, sinPhi0$1 = sinPhi;
9372}
9373
9374function area$2(object) {
9375 areaSum$1 = new Adder();
9376 geoStream(object, areaStream$1);
9377 return areaSum$1 * 2;
9378}
9379
9380function spherical(cartesian) {
9381 return [atan2$1(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
9382}
9383
9384function cartesian(spherical) {
9385 var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
9386 return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
9387}
9388
9389function cartesianDot(a, b) {
9390 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
9391}
9392
9393function cartesianCross(a, b) {
9394 return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
9395}
9396
9397// TODO return a
9398function cartesianAddInPlace(a, b) {
9399 a[0] += b[0], a[1] += b[1], a[2] += b[2];
9400}
9401
9402function cartesianScale(vector, k) {
9403 return [vector[0] * k, vector[1] * k, vector[2] * k];
9404}
9405
9406// TODO return d
9407function cartesianNormalizeInPlace(d) {
9408 var l = sqrt$2(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
9409 d[0] /= l, d[1] /= l, d[2] /= l;
9410}
9411
9412var lambda0$1, phi0, lambda1, phi1, // bounds
9413 lambda2, // previous lambda-coordinate
9414 lambda00$1, phi00$1, // first point
9415 p0, // previous 3D point
9416 deltaSum,
9417 ranges,
9418 range;
9419
9420var boundsStream$1 = {
9421 point: boundsPoint$1,
9422 lineStart: boundsLineStart,
9423 lineEnd: boundsLineEnd,
9424 polygonStart: function() {
9425 boundsStream$1.point = boundsRingPoint;
9426 boundsStream$1.lineStart = boundsRingStart;
9427 boundsStream$1.lineEnd = boundsRingEnd;
9428 deltaSum = new Adder();
9429 areaStream$1.polygonStart();
9430 },
9431 polygonEnd: function() {
9432 areaStream$1.polygonEnd();
9433 boundsStream$1.point = boundsPoint$1;
9434 boundsStream$1.lineStart = boundsLineStart;
9435 boundsStream$1.lineEnd = boundsLineEnd;
9436 if (areaRingSum$1 < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
9437 else if (deltaSum > epsilon$1) phi1 = 90;
9438 else if (deltaSum < -epsilon$1) phi0 = -90;
9439 range[0] = lambda0$1, range[1] = lambda1;
9440 },
9441 sphere: function() {
9442 lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
9443 }
9444};
9445
9446function boundsPoint$1(lambda, phi) {
9447 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
9448 if (phi < phi0) phi0 = phi;
9449 if (phi > phi1) phi1 = phi;
9450}
9451
9452function linePoint(lambda, phi) {
9453 var p = cartesian([lambda * radians, phi * radians]);
9454 if (p0) {
9455 var normal = cartesianCross(p0, p),
9456 equatorial = [normal[1], -normal[0], 0],
9457 inflection = cartesianCross(equatorial, normal);
9458 cartesianNormalizeInPlace(inflection);
9459 inflection = spherical(inflection);
9460 var delta = lambda - lambda2,
9461 sign = delta > 0 ? 1 : -1,
9462 lambdai = inflection[0] * degrees * sign,
9463 phii,
9464 antimeridian = abs$1(delta) > 180;
9465 if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
9466 phii = inflection[1] * degrees;
9467 if (phii > phi1) phi1 = phii;
9468 } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
9469 phii = -inflection[1] * degrees;
9470 if (phii < phi0) phi0 = phii;
9471 } else {
9472 if (phi < phi0) phi0 = phi;
9473 if (phi > phi1) phi1 = phi;
9474 }
9475 if (antimeridian) {
9476 if (lambda < lambda2) {
9477 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
9478 } else {
9479 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
9480 }
9481 } else {
9482 if (lambda1 >= lambda0$1) {
9483 if (lambda < lambda0$1) lambda0$1 = lambda;
9484 if (lambda > lambda1) lambda1 = lambda;
9485 } else {
9486 if (lambda > lambda2) {
9487 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
9488 } else {
9489 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
9490 }
9491 }
9492 }
9493 } else {
9494 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
9495 }
9496 if (phi < phi0) phi0 = phi;
9497 if (phi > phi1) phi1 = phi;
9498 p0 = p, lambda2 = lambda;
9499}
9500
9501function boundsLineStart() {
9502 boundsStream$1.point = linePoint;
9503}
9504
9505function boundsLineEnd() {
9506 range[0] = lambda0$1, range[1] = lambda1;
9507 boundsStream$1.point = boundsPoint$1;
9508 p0 = null;
9509}
9510
9511function boundsRingPoint(lambda, phi) {
9512 if (p0) {
9513 var delta = lambda - lambda2;
9514 deltaSum.add(abs$1(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
9515 } else {
9516 lambda00$1 = lambda, phi00$1 = phi;
9517 }
9518 areaStream$1.point(lambda, phi);
9519 linePoint(lambda, phi);
9520}
9521
9522function boundsRingStart() {
9523 areaStream$1.lineStart();
9524}
9525
9526function boundsRingEnd() {
9527 boundsRingPoint(lambda00$1, phi00$1);
9528 areaStream$1.lineEnd();
9529 if (abs$1(deltaSum) > epsilon$1) lambda0$1 = -(lambda1 = 180);
9530 range[0] = lambda0$1, range[1] = lambda1;
9531 p0 = null;
9532}
9533
9534// Finds the left-right distance between two longitudes.
9535// This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
9536// the distance between ±180° to be 360°.
9537function angle(lambda0, lambda1) {
9538 return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
9539}
9540
9541function rangeCompare(a, b) {
9542 return a[0] - b[0];
9543}
9544
9545function rangeContains(range, x) {
9546 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
9547}
9548
9549function bounds(feature) {
9550 var i, n, a, b, merged, deltaMax, delta;
9551
9552 phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
9553 ranges = [];
9554 geoStream(feature, boundsStream$1);
9555
9556 // First, sort ranges by their minimum longitudes.
9557 if (n = ranges.length) {
9558 ranges.sort(rangeCompare);
9559
9560 // Then, merge any ranges that overlap.
9561 for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
9562 b = ranges[i];
9563 if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
9564 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
9565 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
9566 } else {
9567 merged.push(a = b);
9568 }
9569 }
9570
9571 // Finally, find the largest gap between the merged ranges.
9572 // The final bounding box will be the inverse of this gap.
9573 for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
9574 b = merged[i];
9575 if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
9576 }
9577 }
9578
9579 ranges = range = null;
9580
9581 return lambda0$1 === Infinity || phi0 === Infinity
9582 ? [[NaN, NaN], [NaN, NaN]]
9583 : [[lambda0$1, phi0], [lambda1, phi1]];
9584}
9585
9586var W0, W1,
9587 X0$1, Y0$1, Z0$1,
9588 X1$1, Y1$1, Z1$1,
9589 X2$1, Y2$1, Z2$1,
9590 lambda00, phi00, // first point
9591 x0$4, y0$4, z0; // previous point
9592
9593var centroidStream$1 = {
9594 sphere: noop$1,
9595 point: centroidPoint$1,
9596 lineStart: centroidLineStart$1,
9597 lineEnd: centroidLineEnd$1,
9598 polygonStart: function() {
9599 centroidStream$1.lineStart = centroidRingStart$1;
9600 centroidStream$1.lineEnd = centroidRingEnd$1;
9601 },
9602 polygonEnd: function() {
9603 centroidStream$1.lineStart = centroidLineStart$1;
9604 centroidStream$1.lineEnd = centroidLineEnd$1;
9605 }
9606};
9607
9608// Arithmetic mean of Cartesian vectors.
9609function centroidPoint$1(lambda, phi) {
9610 lambda *= radians, phi *= radians;
9611 var cosPhi = cos$1(phi);
9612 centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
9613}
9614
9615function centroidPointCartesian(x, y, z) {
9616 ++W0;
9617 X0$1 += (x - X0$1) / W0;
9618 Y0$1 += (y - Y0$1) / W0;
9619 Z0$1 += (z - Z0$1) / W0;
9620}
9621
9622function centroidLineStart$1() {
9623 centroidStream$1.point = centroidLinePointFirst;
9624}
9625
9626function centroidLinePointFirst(lambda, phi) {
9627 lambda *= radians, phi *= radians;
9628 var cosPhi = cos$1(phi);
9629 x0$4 = cosPhi * cos$1(lambda);
9630 y0$4 = cosPhi * sin$1(lambda);
9631 z0 = sin$1(phi);
9632 centroidStream$1.point = centroidLinePoint;
9633 centroidPointCartesian(x0$4, y0$4, z0);
9634}
9635
9636function centroidLinePoint(lambda, phi) {
9637 lambda *= radians, phi *= radians;
9638 var cosPhi = cos$1(phi),
9639 x = cosPhi * cos$1(lambda),
9640 y = cosPhi * sin$1(lambda),
9641 z = sin$1(phi),
9642 w = atan2$1(sqrt$2((w = y0$4 * z - z0 * y) * w + (w = z0 * x - x0$4 * z) * w + (w = x0$4 * y - y0$4 * x) * w), x0$4 * x + y0$4 * y + z0 * z);
9643 W1 += w;
9644 X1$1 += w * (x0$4 + (x0$4 = x));
9645 Y1$1 += w * (y0$4 + (y0$4 = y));
9646 Z1$1 += w * (z0 + (z0 = z));
9647 centroidPointCartesian(x0$4, y0$4, z0);
9648}
9649
9650function centroidLineEnd$1() {
9651 centroidStream$1.point = centroidPoint$1;
9652}
9653
9654// See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
9655// J. Applied Mechanics 42, 239 (1975).
9656function centroidRingStart$1() {
9657 centroidStream$1.point = centroidRingPointFirst;
9658}
9659
9660function centroidRingEnd$1() {
9661 centroidRingPoint(lambda00, phi00);
9662 centroidStream$1.point = centroidPoint$1;
9663}
9664
9665function centroidRingPointFirst(lambda, phi) {
9666 lambda00 = lambda, phi00 = phi;
9667 lambda *= radians, phi *= radians;
9668 centroidStream$1.point = centroidRingPoint;
9669 var cosPhi = cos$1(phi);
9670 x0$4 = cosPhi * cos$1(lambda);
9671 y0$4 = cosPhi * sin$1(lambda);
9672 z0 = sin$1(phi);
9673 centroidPointCartesian(x0$4, y0$4, z0);
9674}
9675
9676function centroidRingPoint(lambda, phi) {
9677 lambda *= radians, phi *= radians;
9678 var cosPhi = cos$1(phi),
9679 x = cosPhi * cos$1(lambda),
9680 y = cosPhi * sin$1(lambda),
9681 z = sin$1(phi),
9682 cx = y0$4 * z - z0 * y,
9683 cy = z0 * x - x0$4 * z,
9684 cz = x0$4 * y - y0$4 * x,
9685 m = hypot(cx, cy, cz),
9686 w = asin$1(m), // line weight = angle
9687 v = m && -w / m; // area weight multiplier
9688 X2$1.add(v * cx);
9689 Y2$1.add(v * cy);
9690 Z2$1.add(v * cz);
9691 W1 += w;
9692 X1$1 += w * (x0$4 + (x0$4 = x));
9693 Y1$1 += w * (y0$4 + (y0$4 = y));
9694 Z1$1 += w * (z0 + (z0 = z));
9695 centroidPointCartesian(x0$4, y0$4, z0);
9696}
9697
9698function centroid$1(object) {
9699 W0 = W1 =
9700 X0$1 = Y0$1 = Z0$1 =
9701 X1$1 = Y1$1 = Z1$1 = 0;
9702 X2$1 = new Adder();
9703 Y2$1 = new Adder();
9704 Z2$1 = new Adder();
9705 geoStream(object, centroidStream$1);
9706
9707 var x = +X2$1,
9708 y = +Y2$1,
9709 z = +Z2$1,
9710 m = hypot(x, y, z);
9711
9712 // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
9713 if (m < epsilon2) {
9714 x = X1$1, y = Y1$1, z = Z1$1;
9715 // If the feature has zero length, fall back to arithmetic mean of point vectors.
9716 if (W1 < epsilon$1) x = X0$1, y = Y0$1, z = Z0$1;
9717 m = hypot(x, y, z);
9718 // If the feature still has an undefined ccentroid, then return.
9719 if (m < epsilon2) return [NaN, NaN];
9720 }
9721
9722 return [atan2$1(y, x) * degrees, asin$1(z / m) * degrees];
9723}
9724
9725function constant$3(x) {
9726 return function() {
9727 return x;
9728 };
9729}
9730
9731function compose(a, b) {
9732
9733 function compose(x, y) {
9734 return x = a(x, y), b(x[0], x[1]);
9735 }
9736
9737 if (a.invert && b.invert) compose.invert = function(x, y) {
9738 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
9739 };
9740
9741 return compose;
9742}
9743
9744function rotationIdentity(lambda, phi) {
9745 return [abs$1(lambda) > pi$1 ? lambda + Math.round(-lambda / tau$1) * tau$1 : lambda, phi];
9746}
9747
9748rotationIdentity.invert = rotationIdentity;
9749
9750function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
9751 return (deltaLambda %= tau$1) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
9752 : rotationLambda(deltaLambda))
9753 : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
9754 : rotationIdentity);
9755}
9756
9757function forwardRotationLambda(deltaLambda) {
9758 return function(lambda, phi) {
9759 return lambda += deltaLambda, [lambda > pi$1 ? lambda - tau$1 : lambda < -pi$1 ? lambda + tau$1 : lambda, phi];
9760 };
9761}
9762
9763function rotationLambda(deltaLambda) {
9764 var rotation = forwardRotationLambda(deltaLambda);
9765 rotation.invert = forwardRotationLambda(-deltaLambda);
9766 return rotation;
9767}
9768
9769function rotationPhiGamma(deltaPhi, deltaGamma) {
9770 var cosDeltaPhi = cos$1(deltaPhi),
9771 sinDeltaPhi = sin$1(deltaPhi),
9772 cosDeltaGamma = cos$1(deltaGamma),
9773 sinDeltaGamma = sin$1(deltaGamma);
9774
9775 function rotation(lambda, phi) {
9776 var cosPhi = cos$1(phi),
9777 x = cos$1(lambda) * cosPhi,
9778 y = sin$1(lambda) * cosPhi,
9779 z = sin$1(phi),
9780 k = z * cosDeltaPhi + x * sinDeltaPhi;
9781 return [
9782 atan2$1(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
9783 asin$1(k * cosDeltaGamma + y * sinDeltaGamma)
9784 ];
9785 }
9786
9787 rotation.invert = function(lambda, phi) {
9788 var cosPhi = cos$1(phi),
9789 x = cos$1(lambda) * cosPhi,
9790 y = sin$1(lambda) * cosPhi,
9791 z = sin$1(phi),
9792 k = z * cosDeltaGamma - y * sinDeltaGamma;
9793 return [
9794 atan2$1(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
9795 asin$1(k * cosDeltaPhi - x * sinDeltaPhi)
9796 ];
9797 };
9798
9799 return rotation;
9800}
9801
9802function rotation(rotate) {
9803 rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
9804
9805 function forward(coordinates) {
9806 coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
9807 return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
9808 }
9809
9810 forward.invert = function(coordinates) {
9811 coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
9812 return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
9813 };
9814
9815 return forward;
9816}
9817
9818// Generates a circle centered at [0°, 0°], with a given radius and precision.
9819function circleStream(stream, radius, delta, direction, t0, t1) {
9820 if (!delta) return;
9821 var cosRadius = cos$1(radius),
9822 sinRadius = sin$1(radius),
9823 step = direction * delta;
9824 if (t0 == null) {
9825 t0 = radius + direction * tau$1;
9826 t1 = radius - step / 2;
9827 } else {
9828 t0 = circleRadius(cosRadius, t0);
9829 t1 = circleRadius(cosRadius, t1);
9830 if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$1;
9831 }
9832 for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
9833 point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
9834 stream.point(point[0], point[1]);
9835 }
9836}
9837
9838// Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
9839function circleRadius(cosRadius, point) {
9840 point = cartesian(point), point[0] -= cosRadius;
9841 cartesianNormalizeInPlace(point);
9842 var radius = acos$1(-point[1]);
9843 return ((-point[2] < 0 ? -radius : radius) + tau$1 - epsilon$1) % tau$1;
9844}
9845
9846function circle$2() {
9847 var center = constant$3([0, 0]),
9848 radius = constant$3(90),
9849 precision = constant$3(6),
9850 ring,
9851 rotate,
9852 stream = {point: point};
9853
9854 function point(x, y) {
9855 ring.push(x = rotate(x, y));
9856 x[0] *= degrees, x[1] *= degrees;
9857 }
9858
9859 function circle() {
9860 var c = center.apply(this, arguments),
9861 r = radius.apply(this, arguments) * radians,
9862 p = precision.apply(this, arguments) * radians;
9863 ring = [];
9864 rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
9865 circleStream(stream, r, p, 1);
9866 c = {type: "Polygon", coordinates: [ring]};
9867 ring = rotate = null;
9868 return c;
9869 }
9870
9871 circle.center = function(_) {
9872 return arguments.length ? (center = typeof _ === "function" ? _ : constant$3([+_[0], +_[1]]), circle) : center;
9873 };
9874
9875 circle.radius = function(_) {
9876 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$3(+_), circle) : radius;
9877 };
9878
9879 circle.precision = function(_) {
9880 return arguments.length ? (precision = typeof _ === "function" ? _ : constant$3(+_), circle) : precision;
9881 };
9882
9883 return circle;
9884}
9885
9886function clipBuffer() {
9887 var lines = [],
9888 line;
9889 return {
9890 point: function(x, y, m) {
9891 line.push([x, y, m]);
9892 },
9893 lineStart: function() {
9894 lines.push(line = []);
9895 },
9896 lineEnd: noop$1,
9897 rejoin: function() {
9898 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
9899 },
9900 result: function() {
9901 var result = lines;
9902 lines = [];
9903 line = null;
9904 return result;
9905 }
9906 };
9907}
9908
9909function pointEqual(a, b) {
9910 return abs$1(a[0] - b[0]) < epsilon$1 && abs$1(a[1] - b[1]) < epsilon$1;
9911}
9912
9913function Intersection(point, points, other, entry) {
9914 this.x = point;
9915 this.z = points;
9916 this.o = other; // another intersection
9917 this.e = entry; // is an entry?
9918 this.v = false; // visited
9919 this.n = this.p = null; // next & previous
9920}
9921
9922// A generalized polygon clipping algorithm: given a polygon that has been cut
9923// into its visible line segments, and rejoins the segments by interpolating
9924// along the clip edge.
9925function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
9926 var subject = [],
9927 clip = [],
9928 i,
9929 n;
9930
9931 segments.forEach(function(segment) {
9932 if ((n = segment.length - 1) <= 0) return;
9933 var n, p0 = segment[0], p1 = segment[n], x;
9934
9935 if (pointEqual(p0, p1)) {
9936 if (!p0[2] && !p1[2]) {
9937 stream.lineStart();
9938 for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
9939 stream.lineEnd();
9940 return;
9941 }
9942 // handle degenerate cases by moving the point
9943 p1[0] += 2 * epsilon$1;
9944 }
9945
9946 subject.push(x = new Intersection(p0, segment, null, true));
9947 clip.push(x.o = new Intersection(p0, null, x, false));
9948 subject.push(x = new Intersection(p1, segment, null, false));
9949 clip.push(x.o = new Intersection(p1, null, x, true));
9950 });
9951
9952 if (!subject.length) return;
9953
9954 clip.sort(compareIntersection);
9955 link$1(subject);
9956 link$1(clip);
9957
9958 for (i = 0, n = clip.length; i < n; ++i) {
9959 clip[i].e = startInside = !startInside;
9960 }
9961
9962 var start = subject[0],
9963 points,
9964 point;
9965
9966 while (1) {
9967 // Find first unvisited intersection.
9968 var current = start,
9969 isSubject = true;
9970 while (current.v) if ((current = current.n) === start) return;
9971 points = current.z;
9972 stream.lineStart();
9973 do {
9974 current.v = current.o.v = true;
9975 if (current.e) {
9976 if (isSubject) {
9977 for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
9978 } else {
9979 interpolate(current.x, current.n.x, 1, stream);
9980 }
9981 current = current.n;
9982 } else {
9983 if (isSubject) {
9984 points = current.p.z;
9985 for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
9986 } else {
9987 interpolate(current.x, current.p.x, -1, stream);
9988 }
9989 current = current.p;
9990 }
9991 current = current.o;
9992 points = current.z;
9993 isSubject = !isSubject;
9994 } while (!current.v);
9995 stream.lineEnd();
9996 }
9997}
9998
9999function link$1(array) {
10000 if (!(n = array.length)) return;
10001 var n,
10002 i = 0,
10003 a = array[0],
10004 b;
10005 while (++i < n) {
10006 a.n = b = array[i];
10007 b.p = a;
10008 a = b;
10009 }
10010 a.n = b = array[0];
10011 b.p = a;
10012}
10013
10014function longitude(point) {
10015 if (abs$1(point[0]) <= pi$1)
10016 return point[0];
10017 else
10018 return sign$1(point[0]) * ((abs$1(point[0]) + pi$1) % tau$1 - pi$1);
10019}
10020
10021function polygonContains(polygon, point) {
10022 var lambda = longitude(point),
10023 phi = point[1],
10024 sinPhi = sin$1(phi),
10025 normal = [sin$1(lambda), -cos$1(lambda), 0],
10026 angle = 0,
10027 winding = 0;
10028
10029 var sum = new Adder();
10030
10031 if (sinPhi === 1) phi = halfPi$1 + epsilon$1;
10032 else if (sinPhi === -1) phi = -halfPi$1 - epsilon$1;
10033
10034 for (var i = 0, n = polygon.length; i < n; ++i) {
10035 if (!(m = (ring = polygon[i]).length)) continue;
10036 var ring,
10037 m,
10038 point0 = ring[m - 1],
10039 lambda0 = longitude(point0),
10040 phi0 = point0[1] / 2 + quarterPi,
10041 sinPhi0 = sin$1(phi0),
10042 cosPhi0 = cos$1(phi0);
10043
10044 for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
10045 var point1 = ring[j],
10046 lambda1 = longitude(point1),
10047 phi1 = point1[1] / 2 + quarterPi,
10048 sinPhi1 = sin$1(phi1),
10049 cosPhi1 = cos$1(phi1),
10050 delta = lambda1 - lambda0,
10051 sign = delta >= 0 ? 1 : -1,
10052 absDelta = sign * delta,
10053 antimeridian = absDelta > pi$1,
10054 k = sinPhi0 * sinPhi1;
10055
10056 sum.add(atan2$1(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
10057 angle += antimeridian ? delta + sign * tau$1 : delta;
10058
10059 // Are the longitudes either side of the point’s meridian (lambda),
10060 // and are the latitudes smaller than the parallel (phi)?
10061 if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
10062 var arc = cartesianCross(cartesian(point0), cartesian(point1));
10063 cartesianNormalizeInPlace(arc);
10064 var intersection = cartesianCross(normal, arc);
10065 cartesianNormalizeInPlace(intersection);
10066 var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
10067 if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
10068 winding += antimeridian ^ delta >= 0 ? 1 : -1;
10069 }
10070 }
10071 }
10072 }
10073
10074 // First, determine whether the South pole is inside or outside:
10075 //
10076 // It is inside if:
10077 // * the polygon winds around it in a clockwise direction.
10078 // * the polygon does not (cumulatively) wind around it, but has a negative
10079 // (counter-clockwise) area.
10080 //
10081 // Second, count the (signed) number of times a segment crosses a lambda
10082 // from the point to the South pole. If it is zero, then the point is the
10083 // same side as the South pole.
10084
10085 return (angle < -epsilon$1 || angle < epsilon$1 && sum < -epsilon2) ^ (winding & 1);
10086}
10087
10088function clip(pointVisible, clipLine, interpolate, start) {
10089 return function(sink) {
10090 var line = clipLine(sink),
10091 ringBuffer = clipBuffer(),
10092 ringSink = clipLine(ringBuffer),
10093 polygonStarted = false,
10094 polygon,
10095 segments,
10096 ring;
10097
10098 var clip = {
10099 point: point,
10100 lineStart: lineStart,
10101 lineEnd: lineEnd,
10102 polygonStart: function() {
10103 clip.point = pointRing;
10104 clip.lineStart = ringStart;
10105 clip.lineEnd = ringEnd;
10106 segments = [];
10107 polygon = [];
10108 },
10109 polygonEnd: function() {
10110 clip.point = point;
10111 clip.lineStart = lineStart;
10112 clip.lineEnd = lineEnd;
10113 segments = merge(segments);
10114 var startInside = polygonContains(polygon, start);
10115 if (segments.length) {
10116 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
10117 clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
10118 } else if (startInside) {
10119 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
10120 sink.lineStart();
10121 interpolate(null, null, 1, sink);
10122 sink.lineEnd();
10123 }
10124 if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
10125 segments = polygon = null;
10126 },
10127 sphere: function() {
10128 sink.polygonStart();
10129 sink.lineStart();
10130 interpolate(null, null, 1, sink);
10131 sink.lineEnd();
10132 sink.polygonEnd();
10133 }
10134 };
10135
10136 function point(lambda, phi) {
10137 if (pointVisible(lambda, phi)) sink.point(lambda, phi);
10138 }
10139
10140 function pointLine(lambda, phi) {
10141 line.point(lambda, phi);
10142 }
10143
10144 function lineStart() {
10145 clip.point = pointLine;
10146 line.lineStart();
10147 }
10148
10149 function lineEnd() {
10150 clip.point = point;
10151 line.lineEnd();
10152 }
10153
10154 function pointRing(lambda, phi) {
10155 ring.push([lambda, phi]);
10156 ringSink.point(lambda, phi);
10157 }
10158
10159 function ringStart() {
10160 ringSink.lineStart();
10161 ring = [];
10162 }
10163
10164 function ringEnd() {
10165 pointRing(ring[0][0], ring[0][1]);
10166 ringSink.lineEnd();
10167
10168 var clean = ringSink.clean(),
10169 ringSegments = ringBuffer.result(),
10170 i, n = ringSegments.length, m,
10171 segment,
10172 point;
10173
10174 ring.pop();
10175 polygon.push(ring);
10176 ring = null;
10177
10178 if (!n) return;
10179
10180 // No intersections.
10181 if (clean & 1) {
10182 segment = ringSegments[0];
10183 if ((m = segment.length - 1) > 0) {
10184 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
10185 sink.lineStart();
10186 for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
10187 sink.lineEnd();
10188 }
10189 return;
10190 }
10191
10192 // Rejoin connected segments.
10193 // TODO reuse ringBuffer.rejoin()?
10194 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
10195
10196 segments.push(ringSegments.filter(validSegment));
10197 }
10198
10199 return clip;
10200 };
10201}
10202
10203function validSegment(segment) {
10204 return segment.length > 1;
10205}
10206
10207// Intersections are sorted along the clip edge. For both antimeridian cutting
10208// and circle clipping, the same comparison is used.
10209function compareIntersection(a, b) {
10210 return ((a = a.x)[0] < 0 ? a[1] - halfPi$1 - epsilon$1 : halfPi$1 - a[1])
10211 - ((b = b.x)[0] < 0 ? b[1] - halfPi$1 - epsilon$1 : halfPi$1 - b[1]);
10212}
10213
10214var clipAntimeridian = clip(
10215 function() { return true; },
10216 clipAntimeridianLine,
10217 clipAntimeridianInterpolate,
10218 [-pi$1, -halfPi$1]
10219);
10220
10221// Takes a line and cuts into visible segments. Return values: 0 - there were
10222// intersections or the line was empty; 1 - no intersections; 2 - there were
10223// intersections, and the first and last segments should be rejoined.
10224function clipAntimeridianLine(stream) {
10225 var lambda0 = NaN,
10226 phi0 = NaN,
10227 sign0 = NaN,
10228 clean; // no intersections
10229
10230 return {
10231 lineStart: function() {
10232 stream.lineStart();
10233 clean = 1;
10234 },
10235 point: function(lambda1, phi1) {
10236 var sign1 = lambda1 > 0 ? pi$1 : -pi$1,
10237 delta = abs$1(lambda1 - lambda0);
10238 if (abs$1(delta - pi$1) < epsilon$1) { // line crosses a pole
10239 stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$1 : -halfPi$1);
10240 stream.point(sign0, phi0);
10241 stream.lineEnd();
10242 stream.lineStart();
10243 stream.point(sign1, phi0);
10244 stream.point(lambda1, phi0);
10245 clean = 0;
10246 } else if (sign0 !== sign1 && delta >= pi$1) { // line crosses antimeridian
10247 if (abs$1(lambda0 - sign0) < epsilon$1) lambda0 -= sign0 * epsilon$1; // handle degeneracies
10248 if (abs$1(lambda1 - sign1) < epsilon$1) lambda1 -= sign1 * epsilon$1;
10249 phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
10250 stream.point(sign0, phi0);
10251 stream.lineEnd();
10252 stream.lineStart();
10253 stream.point(sign1, phi0);
10254 clean = 0;
10255 }
10256 stream.point(lambda0 = lambda1, phi0 = phi1);
10257 sign0 = sign1;
10258 },
10259 lineEnd: function() {
10260 stream.lineEnd();
10261 lambda0 = phi0 = NaN;
10262 },
10263 clean: function() {
10264 return 2 - clean; // if intersections, rejoin first and last segments
10265 }
10266 };
10267}
10268
10269function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
10270 var cosPhi0,
10271 cosPhi1,
10272 sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
10273 return abs$1(sinLambda0Lambda1) > epsilon$1
10274 ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
10275 - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
10276 / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
10277 : (phi0 + phi1) / 2;
10278}
10279
10280function clipAntimeridianInterpolate(from, to, direction, stream) {
10281 var phi;
10282 if (from == null) {
10283 phi = direction * halfPi$1;
10284 stream.point(-pi$1, phi);
10285 stream.point(0, phi);
10286 stream.point(pi$1, phi);
10287 stream.point(pi$1, 0);
10288 stream.point(pi$1, -phi);
10289 stream.point(0, -phi);
10290 stream.point(-pi$1, -phi);
10291 stream.point(-pi$1, 0);
10292 stream.point(-pi$1, phi);
10293 } else if (abs$1(from[0] - to[0]) > epsilon$1) {
10294 var lambda = from[0] < to[0] ? pi$1 : -pi$1;
10295 phi = direction * lambda / 2;
10296 stream.point(-lambda, phi);
10297 stream.point(0, phi);
10298 stream.point(lambda, phi);
10299 } else {
10300 stream.point(to[0], to[1]);
10301 }
10302}
10303
10304function clipCircle(radius) {
10305 var cr = cos$1(radius),
10306 delta = 6 * radians,
10307 smallRadius = cr > 0,
10308 notHemisphere = abs$1(cr) > epsilon$1; // TODO optimise for this common case
10309
10310 function interpolate(from, to, direction, stream) {
10311 circleStream(stream, radius, delta, direction, from, to);
10312 }
10313
10314 function visible(lambda, phi) {
10315 return cos$1(lambda) * cos$1(phi) > cr;
10316 }
10317
10318 // Takes a line and cuts into visible segments. Return values used for polygon
10319 // clipping: 0 - there were intersections or the line was empty; 1 - no
10320 // intersections 2 - there were intersections, and the first and last segments
10321 // should be rejoined.
10322 function clipLine(stream) {
10323 var point0, // previous point
10324 c0, // code for previous point
10325 v0, // visibility of previous point
10326 v00, // visibility of first point
10327 clean; // no intersections
10328 return {
10329 lineStart: function() {
10330 v00 = v0 = false;
10331 clean = 1;
10332 },
10333 point: function(lambda, phi) {
10334 var point1 = [lambda, phi],
10335 point2,
10336 v = visible(lambda, phi),
10337 c = smallRadius
10338 ? v ? 0 : code(lambda, phi)
10339 : v ? code(lambda + (lambda < 0 ? pi$1 : -pi$1), phi) : 0;
10340 if (!point0 && (v00 = v0 = v)) stream.lineStart();
10341 if (v !== v0) {
10342 point2 = intersect(point0, point1);
10343 if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2))
10344 point1[2] = 1;
10345 }
10346 if (v !== v0) {
10347 clean = 0;
10348 if (v) {
10349 // outside going in
10350 stream.lineStart();
10351 point2 = intersect(point1, point0);
10352 stream.point(point2[0], point2[1]);
10353 } else {
10354 // inside going out
10355 point2 = intersect(point0, point1);
10356 stream.point(point2[0], point2[1], 2);
10357 stream.lineEnd();
10358 }
10359 point0 = point2;
10360 } else if (notHemisphere && point0 && smallRadius ^ v) {
10361 var t;
10362 // If the codes for two points are different, or are both zero,
10363 // and there this segment intersects with the small circle.
10364 if (!(c & c0) && (t = intersect(point1, point0, true))) {
10365 clean = 0;
10366 if (smallRadius) {
10367 stream.lineStart();
10368 stream.point(t[0][0], t[0][1]);
10369 stream.point(t[1][0], t[1][1]);
10370 stream.lineEnd();
10371 } else {
10372 stream.point(t[1][0], t[1][1]);
10373 stream.lineEnd();
10374 stream.lineStart();
10375 stream.point(t[0][0], t[0][1], 3);
10376 }
10377 }
10378 }
10379 if (v && (!point0 || !pointEqual(point0, point1))) {
10380 stream.point(point1[0], point1[1]);
10381 }
10382 point0 = point1, v0 = v, c0 = c;
10383 },
10384 lineEnd: function() {
10385 if (v0) stream.lineEnd();
10386 point0 = null;
10387 },
10388 // Rejoin first and last segments if there were intersections and the first
10389 // and last points were visible.
10390 clean: function() {
10391 return clean | ((v00 && v0) << 1);
10392 }
10393 };
10394 }
10395
10396 // Intersects the great circle between a and b with the clip circle.
10397 function intersect(a, b, two) {
10398 var pa = cartesian(a),
10399 pb = cartesian(b);
10400
10401 // We have two planes, n1.p = d1 and n2.p = d2.
10402 // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
10403 var n1 = [1, 0, 0], // normal
10404 n2 = cartesianCross(pa, pb),
10405 n2n2 = cartesianDot(n2, n2),
10406 n1n2 = n2[0], // cartesianDot(n1, n2),
10407 determinant = n2n2 - n1n2 * n1n2;
10408
10409 // Two polar points.
10410 if (!determinant) return !two && a;
10411
10412 var c1 = cr * n2n2 / determinant,
10413 c2 = -cr * n1n2 / determinant,
10414 n1xn2 = cartesianCross(n1, n2),
10415 A = cartesianScale(n1, c1),
10416 B = cartesianScale(n2, c2);
10417 cartesianAddInPlace(A, B);
10418
10419 // Solve |p(t)|^2 = 1.
10420 var u = n1xn2,
10421 w = cartesianDot(A, u),
10422 uu = cartesianDot(u, u),
10423 t2 = w * w - uu * (cartesianDot(A, A) - 1);
10424
10425 if (t2 < 0) return;
10426
10427 var t = sqrt$2(t2),
10428 q = cartesianScale(u, (-w - t) / uu);
10429 cartesianAddInPlace(q, A);
10430 q = spherical(q);
10431
10432 if (!two) return q;
10433
10434 // Two intersection points.
10435 var lambda0 = a[0],
10436 lambda1 = b[0],
10437 phi0 = a[1],
10438 phi1 = b[1],
10439 z;
10440
10441 if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
10442
10443 var delta = lambda1 - lambda0,
10444 polar = abs$1(delta - pi$1) < epsilon$1,
10445 meridian = polar || delta < epsilon$1;
10446
10447 if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
10448
10449 // Check that the first point is between a and b.
10450 if (meridian
10451 ? polar
10452 ? phi0 + phi1 > 0 ^ q[1] < (abs$1(q[0] - lambda0) < epsilon$1 ? phi0 : phi1)
10453 : phi0 <= q[1] && q[1] <= phi1
10454 : delta > pi$1 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
10455 var q1 = cartesianScale(u, (-w + t) / uu);
10456 cartesianAddInPlace(q1, A);
10457 return [q, spherical(q1)];
10458 }
10459 }
10460
10461 // Generates a 4-bit vector representing the location of a point relative to
10462 // the small circle's bounding box.
10463 function code(lambda, phi) {
10464 var r = smallRadius ? radius : pi$1 - radius,
10465 code = 0;
10466 if (lambda < -r) code |= 1; // left
10467 else if (lambda > r) code |= 2; // right
10468 if (phi < -r) code |= 4; // below
10469 else if (phi > r) code |= 8; // above
10470 return code;
10471 }
10472
10473 return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$1, radius - pi$1]);
10474}
10475
10476function clipLine(a, b, x0, y0, x1, y1) {
10477 var ax = a[0],
10478 ay = a[1],
10479 bx = b[0],
10480 by = b[1],
10481 t0 = 0,
10482 t1 = 1,
10483 dx = bx - ax,
10484 dy = by - ay,
10485 r;
10486
10487 r = x0 - ax;
10488 if (!dx && r > 0) return;
10489 r /= dx;
10490 if (dx < 0) {
10491 if (r < t0) return;
10492 if (r < t1) t1 = r;
10493 } else if (dx > 0) {
10494 if (r > t1) return;
10495 if (r > t0) t0 = r;
10496 }
10497
10498 r = x1 - ax;
10499 if (!dx && r < 0) return;
10500 r /= dx;
10501 if (dx < 0) {
10502 if (r > t1) return;
10503 if (r > t0) t0 = r;
10504 } else if (dx > 0) {
10505 if (r < t0) return;
10506 if (r < t1) t1 = r;
10507 }
10508
10509 r = y0 - ay;
10510 if (!dy && r > 0) return;
10511 r /= dy;
10512 if (dy < 0) {
10513 if (r < t0) return;
10514 if (r < t1) t1 = r;
10515 } else if (dy > 0) {
10516 if (r > t1) return;
10517 if (r > t0) t0 = r;
10518 }
10519
10520 r = y1 - ay;
10521 if (!dy && r < 0) return;
10522 r /= dy;
10523 if (dy < 0) {
10524 if (r > t1) return;
10525 if (r > t0) t0 = r;
10526 } else if (dy > 0) {
10527 if (r < t0) return;
10528 if (r < t1) t1 = r;
10529 }
10530
10531 if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
10532 if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
10533 return true;
10534}
10535
10536var clipMax = 1e9, clipMin = -clipMax;
10537
10538// TODO Use d3-polygon’s polygonContains here for the ring check?
10539// TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
10540
10541function clipRectangle(x0, y0, x1, y1) {
10542
10543 function visible(x, y) {
10544 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
10545 }
10546
10547 function interpolate(from, to, direction, stream) {
10548 var a = 0, a1 = 0;
10549 if (from == null
10550 || (a = corner(from, direction)) !== (a1 = corner(to, direction))
10551 || comparePoint(from, to) < 0 ^ direction > 0) {
10552 do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
10553 while ((a = (a + direction + 4) % 4) !== a1);
10554 } else {
10555 stream.point(to[0], to[1]);
10556 }
10557 }
10558
10559 function corner(p, direction) {
10560 return abs$1(p[0] - x0) < epsilon$1 ? direction > 0 ? 0 : 3
10561 : abs$1(p[0] - x1) < epsilon$1 ? direction > 0 ? 2 : 1
10562 : abs$1(p[1] - y0) < epsilon$1 ? direction > 0 ? 1 : 0
10563 : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
10564 }
10565
10566 function compareIntersection(a, b) {
10567 return comparePoint(a.x, b.x);
10568 }
10569
10570 function comparePoint(a, b) {
10571 var ca = corner(a, 1),
10572 cb = corner(b, 1);
10573 return ca !== cb ? ca - cb
10574 : ca === 0 ? b[1] - a[1]
10575 : ca === 1 ? a[0] - b[0]
10576 : ca === 2 ? a[1] - b[1]
10577 : b[0] - a[0];
10578 }
10579
10580 return function(stream) {
10581 var activeStream = stream,
10582 bufferStream = clipBuffer(),
10583 segments,
10584 polygon,
10585 ring,
10586 x__, y__, v__, // first point
10587 x_, y_, v_, // previous point
10588 first,
10589 clean;
10590
10591 var clipStream = {
10592 point: point,
10593 lineStart: lineStart,
10594 lineEnd: lineEnd,
10595 polygonStart: polygonStart,
10596 polygonEnd: polygonEnd
10597 };
10598
10599 function point(x, y) {
10600 if (visible(x, y)) activeStream.point(x, y);
10601 }
10602
10603 function polygonInside() {
10604 var winding = 0;
10605
10606 for (var i = 0, n = polygon.length; i < n; ++i) {
10607 for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
10608 a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
10609 if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
10610 else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
10611 }
10612 }
10613
10614 return winding;
10615 }
10616
10617 // Buffer geometry within a polygon and then clip it en masse.
10618 function polygonStart() {
10619 activeStream = bufferStream, segments = [], polygon = [], clean = true;
10620 }
10621
10622 function polygonEnd() {
10623 var startInside = polygonInside(),
10624 cleanInside = clean && startInside,
10625 visible = (segments = merge(segments)).length;
10626 if (cleanInside || visible) {
10627 stream.polygonStart();
10628 if (cleanInside) {
10629 stream.lineStart();
10630 interpolate(null, null, 1, stream);
10631 stream.lineEnd();
10632 }
10633 if (visible) {
10634 clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
10635 }
10636 stream.polygonEnd();
10637 }
10638 activeStream = stream, segments = polygon = ring = null;
10639 }
10640
10641 function lineStart() {
10642 clipStream.point = linePoint;
10643 if (polygon) polygon.push(ring = []);
10644 first = true;
10645 v_ = false;
10646 x_ = y_ = NaN;
10647 }
10648
10649 // TODO rather than special-case polygons, simply handle them separately.
10650 // Ideally, coincident intersection points should be jittered to avoid
10651 // clipping issues.
10652 function lineEnd() {
10653 if (segments) {
10654 linePoint(x__, y__);
10655 if (v__ && v_) bufferStream.rejoin();
10656 segments.push(bufferStream.result());
10657 }
10658 clipStream.point = point;
10659 if (v_) activeStream.lineEnd();
10660 }
10661
10662 function linePoint(x, y) {
10663 var v = visible(x, y);
10664 if (polygon) ring.push([x, y]);
10665 if (first) {
10666 x__ = x, y__ = y, v__ = v;
10667 first = false;
10668 if (v) {
10669 activeStream.lineStart();
10670 activeStream.point(x, y);
10671 }
10672 } else {
10673 if (v && v_) activeStream.point(x, y);
10674 else {
10675 var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
10676 b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
10677 if (clipLine(a, b, x0, y0, x1, y1)) {
10678 if (!v_) {
10679 activeStream.lineStart();
10680 activeStream.point(a[0], a[1]);
10681 }
10682 activeStream.point(b[0], b[1]);
10683 if (!v) activeStream.lineEnd();
10684 clean = false;
10685 } else if (v) {
10686 activeStream.lineStart();
10687 activeStream.point(x, y);
10688 clean = false;
10689 }
10690 }
10691 }
10692 x_ = x, y_ = y, v_ = v;
10693 }
10694
10695 return clipStream;
10696 };
10697}
10698
10699function extent() {
10700 var x0 = 0,
10701 y0 = 0,
10702 x1 = 960,
10703 y1 = 500,
10704 cache,
10705 cacheStream,
10706 clip;
10707
10708 return clip = {
10709 stream: function(stream) {
10710 return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
10711 },
10712 extent: function(_) {
10713 return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
10714 }
10715 };
10716}
10717
10718var lengthSum$1,
10719 lambda0,
10720 sinPhi0,
10721 cosPhi0;
10722
10723var lengthStream$1 = {
10724 sphere: noop$1,
10725 point: noop$1,
10726 lineStart: lengthLineStart,
10727 lineEnd: noop$1,
10728 polygonStart: noop$1,
10729 polygonEnd: noop$1
10730};
10731
10732function lengthLineStart() {
10733 lengthStream$1.point = lengthPointFirst$1;
10734 lengthStream$1.lineEnd = lengthLineEnd;
10735}
10736
10737function lengthLineEnd() {
10738 lengthStream$1.point = lengthStream$1.lineEnd = noop$1;
10739}
10740
10741function lengthPointFirst$1(lambda, phi) {
10742 lambda *= radians, phi *= radians;
10743 lambda0 = lambda, sinPhi0 = sin$1(phi), cosPhi0 = cos$1(phi);
10744 lengthStream$1.point = lengthPoint$1;
10745}
10746
10747function lengthPoint$1(lambda, phi) {
10748 lambda *= radians, phi *= radians;
10749 var sinPhi = sin$1(phi),
10750 cosPhi = cos$1(phi),
10751 delta = abs$1(lambda - lambda0),
10752 cosDelta = cos$1(delta),
10753 sinDelta = sin$1(delta),
10754 x = cosPhi * sinDelta,
10755 y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta,
10756 z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta;
10757 lengthSum$1.add(atan2$1(sqrt$2(x * x + y * y), z));
10758 lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi;
10759}
10760
10761function length$1(object) {
10762 lengthSum$1 = new Adder();
10763 geoStream(object, lengthStream$1);
10764 return +lengthSum$1;
10765}
10766
10767var coordinates = [null, null],
10768 object = {type: "LineString", coordinates: coordinates};
10769
10770function distance(a, b) {
10771 coordinates[0] = a;
10772 coordinates[1] = b;
10773 return length$1(object);
10774}
10775
10776var containsObjectType = {
10777 Feature: function(object, point) {
10778 return containsGeometry(object.geometry, point);
10779 },
10780 FeatureCollection: function(object, point) {
10781 var features = object.features, i = -1, n = features.length;
10782 while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
10783 return false;
10784 }
10785};
10786
10787var containsGeometryType = {
10788 Sphere: function() {
10789 return true;
10790 },
10791 Point: function(object, point) {
10792 return containsPoint(object.coordinates, point);
10793 },
10794 MultiPoint: function(object, point) {
10795 var coordinates = object.coordinates, i = -1, n = coordinates.length;
10796 while (++i < n) if (containsPoint(coordinates[i], point)) return true;
10797 return false;
10798 },
10799 LineString: function(object, point) {
10800 return containsLine(object.coordinates, point);
10801 },
10802 MultiLineString: function(object, point) {
10803 var coordinates = object.coordinates, i = -1, n = coordinates.length;
10804 while (++i < n) if (containsLine(coordinates[i], point)) return true;
10805 return false;
10806 },
10807 Polygon: function(object, point) {
10808 return containsPolygon(object.coordinates, point);
10809 },
10810 MultiPolygon: function(object, point) {
10811 var coordinates = object.coordinates, i = -1, n = coordinates.length;
10812 while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
10813 return false;
10814 },
10815 GeometryCollection: function(object, point) {
10816 var geometries = object.geometries, i = -1, n = geometries.length;
10817 while (++i < n) if (containsGeometry(geometries[i], point)) return true;
10818 return false;
10819 }
10820};
10821
10822function containsGeometry(geometry, point) {
10823 return geometry && containsGeometryType.hasOwnProperty(geometry.type)
10824 ? containsGeometryType[geometry.type](geometry, point)
10825 : false;
10826}
10827
10828function containsPoint(coordinates, point) {
10829 return distance(coordinates, point) === 0;
10830}
10831
10832function containsLine(coordinates, point) {
10833 var ao, bo, ab;
10834 for (var i = 0, n = coordinates.length; i < n; i++) {
10835 bo = distance(coordinates[i], point);
10836 if (bo === 0) return true;
10837 if (i > 0) {
10838 ab = distance(coordinates[i], coordinates[i - 1]);
10839 if (
10840 ab > 0 &&
10841 ao <= ab &&
10842 bo <= ab &&
10843 (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2 * ab
10844 )
10845 return true;
10846 }
10847 ao = bo;
10848 }
10849 return false;
10850}
10851
10852function containsPolygon(coordinates, point) {
10853 return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
10854}
10855
10856function ringRadians(ring) {
10857 return ring = ring.map(pointRadians), ring.pop(), ring;
10858}
10859
10860function pointRadians(point) {
10861 return [point[0] * radians, point[1] * radians];
10862}
10863
10864function contains$1(object, point) {
10865 return (object && containsObjectType.hasOwnProperty(object.type)
10866 ? containsObjectType[object.type]
10867 : containsGeometry)(object, point);
10868}
10869
10870function graticuleX(y0, y1, dy) {
10871 var y = sequence(y0, y1 - epsilon$1, dy).concat(y1);
10872 return function(x) { return y.map(function(y) { return [x, y]; }); };
10873}
10874
10875function graticuleY(x0, x1, dx) {
10876 var x = sequence(x0, x1 - epsilon$1, dx).concat(x1);
10877 return function(y) { return x.map(function(x) { return [x, y]; }); };
10878}
10879
10880function graticule() {
10881 var x1, x0, X1, X0,
10882 y1, y0, Y1, Y0,
10883 dx = 10, dy = dx, DX = 90, DY = 360,
10884 x, y, X, Y,
10885 precision = 2.5;
10886
10887 function graticule() {
10888 return {type: "MultiLineString", coordinates: lines()};
10889 }
10890
10891 function lines() {
10892 return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
10893 .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
10894 .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs$1(x % DX) > epsilon$1; }).map(x))
10895 .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs$1(y % DY) > epsilon$1; }).map(y));
10896 }
10897
10898 graticule.lines = function() {
10899 return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
10900 };
10901
10902 graticule.outline = function() {
10903 return {
10904 type: "Polygon",
10905 coordinates: [
10906 X(X0).concat(
10907 Y(Y1).slice(1),
10908 X(X1).reverse().slice(1),
10909 Y(Y0).reverse().slice(1))
10910 ]
10911 };
10912 };
10913
10914 graticule.extent = function(_) {
10915 if (!arguments.length) return graticule.extentMinor();
10916 return graticule.extentMajor(_).extentMinor(_);
10917 };
10918
10919 graticule.extentMajor = function(_) {
10920 if (!arguments.length) return [[X0, Y0], [X1, Y1]];
10921 X0 = +_[0][0], X1 = +_[1][0];
10922 Y0 = +_[0][1], Y1 = +_[1][1];
10923 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
10924 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
10925 return graticule.precision(precision);
10926 };
10927
10928 graticule.extentMinor = function(_) {
10929 if (!arguments.length) return [[x0, y0], [x1, y1]];
10930 x0 = +_[0][0], x1 = +_[1][0];
10931 y0 = +_[0][1], y1 = +_[1][1];
10932 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
10933 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
10934 return graticule.precision(precision);
10935 };
10936
10937 graticule.step = function(_) {
10938 if (!arguments.length) return graticule.stepMinor();
10939 return graticule.stepMajor(_).stepMinor(_);
10940 };
10941
10942 graticule.stepMajor = function(_) {
10943 if (!arguments.length) return [DX, DY];
10944 DX = +_[0], DY = +_[1];
10945 return graticule;
10946 };
10947
10948 graticule.stepMinor = function(_) {
10949 if (!arguments.length) return [dx, dy];
10950 dx = +_[0], dy = +_[1];
10951 return graticule;
10952 };
10953
10954 graticule.precision = function(_) {
10955 if (!arguments.length) return precision;
10956 precision = +_;
10957 x = graticuleX(y0, y1, 90);
10958 y = graticuleY(x0, x1, precision);
10959 X = graticuleX(Y0, Y1, 90);
10960 Y = graticuleY(X0, X1, precision);
10961 return graticule;
10962 };
10963
10964 return graticule
10965 .extentMajor([[-180, -90 + epsilon$1], [180, 90 - epsilon$1]])
10966 .extentMinor([[-180, -80 - epsilon$1], [180, 80 + epsilon$1]]);
10967}
10968
10969function graticule10() {
10970 return graticule()();
10971}
10972
10973function interpolate(a, b) {
10974 var x0 = a[0] * radians,
10975 y0 = a[1] * radians,
10976 x1 = b[0] * radians,
10977 y1 = b[1] * radians,
10978 cy0 = cos$1(y0),
10979 sy0 = sin$1(y0),
10980 cy1 = cos$1(y1),
10981 sy1 = sin$1(y1),
10982 kx0 = cy0 * cos$1(x0),
10983 ky0 = cy0 * sin$1(x0),
10984 kx1 = cy1 * cos$1(x1),
10985 ky1 = cy1 * sin$1(x1),
10986 d = 2 * asin$1(sqrt$2(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
10987 k = sin$1(d);
10988
10989 var interpolate = d ? function(t) {
10990 var B = sin$1(t *= d) / k,
10991 A = sin$1(d - t) / k,
10992 x = A * kx0 + B * kx1,
10993 y = A * ky0 + B * ky1,
10994 z = A * sy0 + B * sy1;
10995 return [
10996 atan2$1(y, x) * degrees,
10997 atan2$1(z, sqrt$2(x * x + y * y)) * degrees
10998 ];
10999 } : function() {
11000 return [x0 * degrees, y0 * degrees];
11001 };
11002
11003 interpolate.distance = d;
11004
11005 return interpolate;
11006}
11007
11008var identity$5 = x => x;
11009
11010var areaSum = new Adder(),
11011 areaRingSum = new Adder(),
11012 x00$2,
11013 y00$2,
11014 x0$3,
11015 y0$3;
11016
11017var areaStream = {
11018 point: noop$1,
11019 lineStart: noop$1,
11020 lineEnd: noop$1,
11021 polygonStart: function() {
11022 areaStream.lineStart = areaRingStart;
11023 areaStream.lineEnd = areaRingEnd;
11024 },
11025 polygonEnd: function() {
11026 areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop$1;
11027 areaSum.add(abs$1(areaRingSum));
11028 areaRingSum = new Adder();
11029 },
11030 result: function() {
11031 var area = areaSum / 2;
11032 areaSum = new Adder();
11033 return area;
11034 }
11035};
11036
11037function areaRingStart() {
11038 areaStream.point = areaPointFirst;
11039}
11040
11041function areaPointFirst(x, y) {
11042 areaStream.point = areaPoint;
11043 x00$2 = x0$3 = x, y00$2 = y0$3 = y;
11044}
11045
11046function areaPoint(x, y) {
11047 areaRingSum.add(y0$3 * x - x0$3 * y);
11048 x0$3 = x, y0$3 = y;
11049}
11050
11051function areaRingEnd() {
11052 areaPoint(x00$2, y00$2);
11053}
11054
11055var x0$2 = Infinity,
11056 y0$2 = x0$2,
11057 x1 = -x0$2,
11058 y1 = x1;
11059
11060var boundsStream = {
11061 point: boundsPoint,
11062 lineStart: noop$1,
11063 lineEnd: noop$1,
11064 polygonStart: noop$1,
11065 polygonEnd: noop$1,
11066 result: function() {
11067 var bounds = [[x0$2, y0$2], [x1, y1]];
11068 x1 = y1 = -(y0$2 = x0$2 = Infinity);
11069 return bounds;
11070 }
11071};
11072
11073function boundsPoint(x, y) {
11074 if (x < x0$2) x0$2 = x;
11075 if (x > x1) x1 = x;
11076 if (y < y0$2) y0$2 = y;
11077 if (y > y1) y1 = y;
11078}
11079
11080// TODO Enforce positive area for exterior, negative area for interior?
11081
11082var X0 = 0,
11083 Y0 = 0,
11084 Z0 = 0,
11085 X1 = 0,
11086 Y1 = 0,
11087 Z1 = 0,
11088 X2 = 0,
11089 Y2 = 0,
11090 Z2 = 0,
11091 x00$1,
11092 y00$1,
11093 x0$1,
11094 y0$1;
11095
11096var centroidStream = {
11097 point: centroidPoint,
11098 lineStart: centroidLineStart,
11099 lineEnd: centroidLineEnd,
11100 polygonStart: function() {
11101 centroidStream.lineStart = centroidRingStart;
11102 centroidStream.lineEnd = centroidRingEnd;
11103 },
11104 polygonEnd: function() {
11105 centroidStream.point = centroidPoint;
11106 centroidStream.lineStart = centroidLineStart;
11107 centroidStream.lineEnd = centroidLineEnd;
11108 },
11109 result: function() {
11110 var centroid = Z2 ? [X2 / Z2, Y2 / Z2]
11111 : Z1 ? [X1 / Z1, Y1 / Z1]
11112 : Z0 ? [X0 / Z0, Y0 / Z0]
11113 : [NaN, NaN];
11114 X0 = Y0 = Z0 =
11115 X1 = Y1 = Z1 =
11116 X2 = Y2 = Z2 = 0;
11117 return centroid;
11118 }
11119};
11120
11121function centroidPoint(x, y) {
11122 X0 += x;
11123 Y0 += y;
11124 ++Z0;
11125}
11126
11127function centroidLineStart() {
11128 centroidStream.point = centroidPointFirstLine;
11129}
11130
11131function centroidPointFirstLine(x, y) {
11132 centroidStream.point = centroidPointLine;
11133 centroidPoint(x0$1 = x, y0$1 = y);
11134}
11135
11136function centroidPointLine(x, y) {
11137 var dx = x - x0$1, dy = y - y0$1, z = sqrt$2(dx * dx + dy * dy);
11138 X1 += z * (x0$1 + x) / 2;
11139 Y1 += z * (y0$1 + y) / 2;
11140 Z1 += z;
11141 centroidPoint(x0$1 = x, y0$1 = y);
11142}
11143
11144function centroidLineEnd() {
11145 centroidStream.point = centroidPoint;
11146}
11147
11148function centroidRingStart() {
11149 centroidStream.point = centroidPointFirstRing;
11150}
11151
11152function centroidRingEnd() {
11153 centroidPointRing(x00$1, y00$1);
11154}
11155
11156function centroidPointFirstRing(x, y) {
11157 centroidStream.point = centroidPointRing;
11158 centroidPoint(x00$1 = x0$1 = x, y00$1 = y0$1 = y);
11159}
11160
11161function centroidPointRing(x, y) {
11162 var dx = x - x0$1,
11163 dy = y - y0$1,
11164 z = sqrt$2(dx * dx + dy * dy);
11165
11166 X1 += z * (x0$1 + x) / 2;
11167 Y1 += z * (y0$1 + y) / 2;
11168 Z1 += z;
11169
11170 z = y0$1 * x - x0$1 * y;
11171 X2 += z * (x0$1 + x);
11172 Y2 += z * (y0$1 + y);
11173 Z2 += z * 3;
11174 centroidPoint(x0$1 = x, y0$1 = y);
11175}
11176
11177function PathContext(context) {
11178 this._context = context;
11179}
11180
11181PathContext.prototype = {
11182 _radius: 4.5,
11183 pointRadius: function(_) {
11184 return this._radius = _, this;
11185 },
11186 polygonStart: function() {
11187 this._line = 0;
11188 },
11189 polygonEnd: function() {
11190 this._line = NaN;
11191 },
11192 lineStart: function() {
11193 this._point = 0;
11194 },
11195 lineEnd: function() {
11196 if (this._line === 0) this._context.closePath();
11197 this._point = NaN;
11198 },
11199 point: function(x, y) {
11200 switch (this._point) {
11201 case 0: {
11202 this._context.moveTo(x, y);
11203 this._point = 1;
11204 break;
11205 }
11206 case 1: {
11207 this._context.lineTo(x, y);
11208 break;
11209 }
11210 default: {
11211 this._context.moveTo(x + this._radius, y);
11212 this._context.arc(x, y, this._radius, 0, tau$1);
11213 break;
11214 }
11215 }
11216 },
11217 result: noop$1
11218};
11219
11220var lengthSum = new Adder(),
11221 lengthRing,
11222 x00,
11223 y00,
11224 x0,
11225 y0;
11226
11227var lengthStream = {
11228 point: noop$1,
11229 lineStart: function() {
11230 lengthStream.point = lengthPointFirst;
11231 },
11232 lineEnd: function() {
11233 if (lengthRing) lengthPoint(x00, y00);
11234 lengthStream.point = noop$1;
11235 },
11236 polygonStart: function() {
11237 lengthRing = true;
11238 },
11239 polygonEnd: function() {
11240 lengthRing = null;
11241 },
11242 result: function() {
11243 var length = +lengthSum;
11244 lengthSum = new Adder();
11245 return length;
11246 }
11247};
11248
11249function lengthPointFirst(x, y) {
11250 lengthStream.point = lengthPoint;
11251 x00 = x0 = x, y00 = y0 = y;
11252}
11253
11254function lengthPoint(x, y) {
11255 x0 -= x, y0 -= y;
11256 lengthSum.add(sqrt$2(x0 * x0 + y0 * y0));
11257 x0 = x, y0 = y;
11258}
11259
11260function PathString() {
11261 this._string = [];
11262}
11263
11264PathString.prototype = {
11265 _radius: 4.5,
11266 _circle: circle$1(4.5),
11267 pointRadius: function(_) {
11268 if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
11269 return this;
11270 },
11271 polygonStart: function() {
11272 this._line = 0;
11273 },
11274 polygonEnd: function() {
11275 this._line = NaN;
11276 },
11277 lineStart: function() {
11278 this._point = 0;
11279 },
11280 lineEnd: function() {
11281 if (this._line === 0) this._string.push("Z");
11282 this._point = NaN;
11283 },
11284 point: function(x, y) {
11285 switch (this._point) {
11286 case 0: {
11287 this._string.push("M", x, ",", y);
11288 this._point = 1;
11289 break;
11290 }
11291 case 1: {
11292 this._string.push("L", x, ",", y);
11293 break;
11294 }
11295 default: {
11296 if (this._circle == null) this._circle = circle$1(this._radius);
11297 this._string.push("M", x, ",", y, this._circle);
11298 break;
11299 }
11300 }
11301 },
11302 result: function() {
11303 if (this._string.length) {
11304 var result = this._string.join("");
11305 this._string = [];
11306 return result;
11307 } else {
11308 return null;
11309 }
11310 }
11311};
11312
11313function circle$1(radius) {
11314 return "m0," + radius
11315 + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
11316 + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
11317 + "z";
11318}
11319
11320function index$2(projection, context) {
11321 var pointRadius = 4.5,
11322 projectionStream,
11323 contextStream;
11324
11325 function path(object) {
11326 if (object) {
11327 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
11328 geoStream(object, projectionStream(contextStream));
11329 }
11330 return contextStream.result();
11331 }
11332
11333 path.area = function(object) {
11334 geoStream(object, projectionStream(areaStream));
11335 return areaStream.result();
11336 };
11337
11338 path.measure = function(object) {
11339 geoStream(object, projectionStream(lengthStream));
11340 return lengthStream.result();
11341 };
11342
11343 path.bounds = function(object) {
11344 geoStream(object, projectionStream(boundsStream));
11345 return boundsStream.result();
11346 };
11347
11348 path.centroid = function(object) {
11349 geoStream(object, projectionStream(centroidStream));
11350 return centroidStream.result();
11351 };
11352
11353 path.projection = function(_) {
11354 return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$5) : (projection = _).stream, path) : projection;
11355 };
11356
11357 path.context = function(_) {
11358 if (!arguments.length) return context;
11359 contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
11360 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
11361 return path;
11362 };
11363
11364 path.pointRadius = function(_) {
11365 if (!arguments.length) return pointRadius;
11366 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
11367 return path;
11368 };
11369
11370 return path.projection(projection).context(context);
11371}
11372
11373function transform$1(methods) {
11374 return {
11375 stream: transformer$3(methods)
11376 };
11377}
11378
11379function transformer$3(methods) {
11380 return function(stream) {
11381 var s = new TransformStream;
11382 for (var key in methods) s[key] = methods[key];
11383 s.stream = stream;
11384 return s;
11385 };
11386}
11387
11388function TransformStream() {}
11389
11390TransformStream.prototype = {
11391 constructor: TransformStream,
11392 point: function(x, y) { this.stream.point(x, y); },
11393 sphere: function() { this.stream.sphere(); },
11394 lineStart: function() { this.stream.lineStart(); },
11395 lineEnd: function() { this.stream.lineEnd(); },
11396 polygonStart: function() { this.stream.polygonStart(); },
11397 polygonEnd: function() { this.stream.polygonEnd(); }
11398};
11399
11400function fit(projection, fitBounds, object) {
11401 var clip = projection.clipExtent && projection.clipExtent();
11402 projection.scale(150).translate([0, 0]);
11403 if (clip != null) projection.clipExtent(null);
11404 geoStream(object, projection.stream(boundsStream));
11405 fitBounds(boundsStream.result());
11406 if (clip != null) projection.clipExtent(clip);
11407 return projection;
11408}
11409
11410function fitExtent(projection, extent, object) {
11411 return fit(projection, function(b) {
11412 var w = extent[1][0] - extent[0][0],
11413 h = extent[1][1] - extent[0][1],
11414 k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
11415 x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
11416 y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
11417 projection.scale(150 * k).translate([x, y]);
11418 }, object);
11419}
11420
11421function fitSize(projection, size, object) {
11422 return fitExtent(projection, [[0, 0], size], object);
11423}
11424
11425function fitWidth(projection, width, object) {
11426 return fit(projection, function(b) {
11427 var w = +width,
11428 k = w / (b[1][0] - b[0][0]),
11429 x = (w - k * (b[1][0] + b[0][0])) / 2,
11430 y = -k * b[0][1];
11431 projection.scale(150 * k).translate([x, y]);
11432 }, object);
11433}
11434
11435function fitHeight(projection, height, object) {
11436 return fit(projection, function(b) {
11437 var h = +height,
11438 k = h / (b[1][1] - b[0][1]),
11439 x = -k * b[0][0],
11440 y = (h - k * (b[1][1] + b[0][1])) / 2;
11441 projection.scale(150 * k).translate([x, y]);
11442 }, object);
11443}
11444
11445var maxDepth = 16, // maximum depth of subdivision
11446 cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
11447
11448function resample(project, delta2) {
11449 return +delta2 ? resample$1(project, delta2) : resampleNone(project);
11450}
11451
11452function resampleNone(project) {
11453 return transformer$3({
11454 point: function(x, y) {
11455 x = project(x, y);
11456 this.stream.point(x[0], x[1]);
11457 }
11458 });
11459}
11460
11461function resample$1(project, delta2) {
11462
11463 function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
11464 var dx = x1 - x0,
11465 dy = y1 - y0,
11466 d2 = dx * dx + dy * dy;
11467 if (d2 > 4 * delta2 && depth--) {
11468 var a = a0 + a1,
11469 b = b0 + b1,
11470 c = c0 + c1,
11471 m = sqrt$2(a * a + b * b + c * c),
11472 phi2 = asin$1(c /= m),
11473 lambda2 = abs$1(abs$1(c) - 1) < epsilon$1 || abs$1(lambda0 - lambda1) < epsilon$1 ? (lambda0 + lambda1) / 2 : atan2$1(b, a),
11474 p = project(lambda2, phi2),
11475 x2 = p[0],
11476 y2 = p[1],
11477 dx2 = x2 - x0,
11478 dy2 = y2 - y0,
11479 dz = dy * dx2 - dx * dy2;
11480 if (dz * dz / d2 > delta2 // perpendicular projected distance
11481 || abs$1((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
11482 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
11483 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
11484 stream.point(x2, y2);
11485 resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
11486 }
11487 }
11488 }
11489 return function(stream) {
11490 var lambda00, x00, y00, a00, b00, c00, // first point
11491 lambda0, x0, y0, a0, b0, c0; // previous point
11492
11493 var resampleStream = {
11494 point: point,
11495 lineStart: lineStart,
11496 lineEnd: lineEnd,
11497 polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
11498 polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
11499 };
11500
11501 function point(x, y) {
11502 x = project(x, y);
11503 stream.point(x[0], x[1]);
11504 }
11505
11506 function lineStart() {
11507 x0 = NaN;
11508 resampleStream.point = linePoint;
11509 stream.lineStart();
11510 }
11511
11512 function linePoint(lambda, phi) {
11513 var c = cartesian([lambda, phi]), p = project(lambda, phi);
11514 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x0 = p[0], y0 = p[1], lambda0 = lambda, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
11515 stream.point(x0, y0);
11516 }
11517
11518 function lineEnd() {
11519 resampleStream.point = point;
11520 stream.lineEnd();
11521 }
11522
11523 function ringStart() {
11524 lineStart();
11525 resampleStream.point = ringPoint;
11526 resampleStream.lineEnd = ringEnd;
11527 }
11528
11529 function ringPoint(lambda, phi) {
11530 linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
11531 resampleStream.point = linePoint;
11532 }
11533
11534 function ringEnd() {
11535 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
11536 resampleStream.lineEnd = lineEnd;
11537 lineEnd();
11538 }
11539
11540 return resampleStream;
11541 };
11542}
11543
11544var transformRadians = transformer$3({
11545 point: function(x, y) {
11546 this.stream.point(x * radians, y * radians);
11547 }
11548});
11549
11550function transformRotate(rotate) {
11551 return transformer$3({
11552 point: function(x, y) {
11553 var r = rotate(x, y);
11554 return this.stream.point(r[0], r[1]);
11555 }
11556 });
11557}
11558
11559function scaleTranslate(k, dx, dy, sx, sy) {
11560 function transform(x, y) {
11561 x *= sx; y *= sy;
11562 return [dx + k * x, dy - k * y];
11563 }
11564 transform.invert = function(x, y) {
11565 return [(x - dx) / k * sx, (dy - y) / k * sy];
11566 };
11567 return transform;
11568}
11569
11570function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {
11571 if (!alpha) return scaleTranslate(k, dx, dy, sx, sy);
11572 var cosAlpha = cos$1(alpha),
11573 sinAlpha = sin$1(alpha),
11574 a = cosAlpha * k,
11575 b = sinAlpha * k,
11576 ai = cosAlpha / k,
11577 bi = sinAlpha / k,
11578 ci = (sinAlpha * dy - cosAlpha * dx) / k,
11579 fi = (sinAlpha * dx + cosAlpha * dy) / k;
11580 function transform(x, y) {
11581 x *= sx; y *= sy;
11582 return [a * x - b * y + dx, dy - b * x - a * y];
11583 }
11584 transform.invert = function(x, y) {
11585 return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];
11586 };
11587 return transform;
11588}
11589
11590function projection(project) {
11591 return projectionMutator(function() { return project; })();
11592}
11593
11594function projectionMutator(projectAt) {
11595 var project,
11596 k = 150, // scale
11597 x = 480, y = 250, // translate
11598 lambda = 0, phi = 0, // center
11599 deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
11600 alpha = 0, // post-rotate angle
11601 sx = 1, // reflectX
11602 sy = 1, // reflectX
11603 theta = null, preclip = clipAntimeridian, // pre-clip angle
11604 x0 = null, y0, x1, y1, postclip = identity$5, // post-clip extent
11605 delta2 = 0.5, // precision
11606 projectResample,
11607 projectTransform,
11608 projectRotateTransform,
11609 cache,
11610 cacheStream;
11611
11612 function projection(point) {
11613 return projectRotateTransform(point[0] * radians, point[1] * radians);
11614 }
11615
11616 function invert(point) {
11617 point = projectRotateTransform.invert(point[0], point[1]);
11618 return point && [point[0] * degrees, point[1] * degrees];
11619 }
11620
11621 projection.stream = function(stream) {
11622 return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
11623 };
11624
11625 projection.preclip = function(_) {
11626 return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
11627 };
11628
11629 projection.postclip = function(_) {
11630 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
11631 };
11632
11633 projection.clipAngle = function(_) {
11634 return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees;
11635 };
11636
11637 projection.clipExtent = function(_) {
11638 return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
11639 };
11640
11641 projection.scale = function(_) {
11642 return arguments.length ? (k = +_, recenter()) : k;
11643 };
11644
11645 projection.translate = function(_) {
11646 return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
11647 };
11648
11649 projection.center = function(_) {
11650 return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees];
11651 };
11652
11653 projection.rotate = function(_) {
11654 return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees, deltaPhi * degrees, deltaGamma * degrees];
11655 };
11656
11657 projection.angle = function(_) {
11658 return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees;
11659 };
11660
11661 projection.reflectX = function(_) {
11662 return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;
11663 };
11664
11665 projection.reflectY = function(_) {
11666 return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;
11667 };
11668
11669 projection.precision = function(_) {
11670 return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$2(delta2);
11671 };
11672
11673 projection.fitExtent = function(extent, object) {
11674 return fitExtent(projection, extent, object);
11675 };
11676
11677 projection.fitSize = function(size, object) {
11678 return fitSize(projection, size, object);
11679 };
11680
11681 projection.fitWidth = function(width, object) {
11682 return fitWidth(projection, width, object);
11683 };
11684
11685 projection.fitHeight = function(height, object) {
11686 return fitHeight(projection, height, object);
11687 };
11688
11689 function recenter() {
11690 var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),
11691 transform = scaleTranslateRotate(k, x - center[0], y - center[1], sx, sy, alpha);
11692 rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
11693 projectTransform = compose(project, transform);
11694 projectRotateTransform = compose(rotate, projectTransform);
11695 projectResample = resample(projectTransform, delta2);
11696 return reset();
11697 }
11698
11699 function reset() {
11700 cache = cacheStream = null;
11701 return projection;
11702 }
11703
11704 return function() {
11705 project = projectAt.apply(this, arguments);
11706 projection.invert = project.invert && invert;
11707 return recenter();
11708 };
11709}
11710
11711function conicProjection(projectAt) {
11712 var phi0 = 0,
11713 phi1 = pi$1 / 3,
11714 m = projectionMutator(projectAt),
11715 p = m(phi0, phi1);
11716
11717 p.parallels = function(_) {
11718 return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees, phi1 * degrees];
11719 };
11720
11721 return p;
11722}
11723
11724function cylindricalEqualAreaRaw(phi0) {
11725 var cosPhi0 = cos$1(phi0);
11726
11727 function forward(lambda, phi) {
11728 return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
11729 }
11730
11731 forward.invert = function(x, y) {
11732 return [x / cosPhi0, asin$1(y * cosPhi0)];
11733 };
11734
11735 return forward;
11736}
11737
11738function conicEqualAreaRaw(y0, y1) {
11739 var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
11740
11741 // Are the parallels symmetrical around the Equator?
11742 if (abs$1(n) < epsilon$1) return cylindricalEqualAreaRaw(y0);
11743
11744 var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt$2(c) / n;
11745
11746 function project(x, y) {
11747 var r = sqrt$2(c - 2 * n * sin$1(y)) / n;
11748 return [r * sin$1(x *= n), r0 - r * cos$1(x)];
11749 }
11750
11751 project.invert = function(x, y) {
11752 var r0y = r0 - y,
11753 l = atan2$1(x, abs$1(r0y)) * sign$1(r0y);
11754 if (r0y * n < 0)
11755 l -= pi$1 * sign$1(x) * sign$1(r0y);
11756 return [l / n, asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
11757 };
11758
11759 return project;
11760}
11761
11762function conicEqualArea() {
11763 return conicProjection(conicEqualAreaRaw)
11764 .scale(155.424)
11765 .center([0, 33.6442]);
11766}
11767
11768function albers() {
11769 return conicEqualArea()
11770 .parallels([29.5, 45.5])
11771 .scale(1070)
11772 .translate([480, 250])
11773 .rotate([96, 0])
11774 .center([-0.6, 38.7]);
11775}
11776
11777// The projections must have mutually exclusive clip regions on the sphere,
11778// as this will avoid emitting interleaving lines and polygons.
11779function multiplex(streams) {
11780 var n = streams.length;
11781 return {
11782 point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
11783 sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
11784 lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
11785 lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
11786 polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
11787 polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
11788 };
11789}
11790
11791// A composite projection for the United States, configured by default for
11792// 960×500. The projection also works quite well at 960×600 if you change the
11793// scale to 1285 and adjust the translate accordingly. The set of standard
11794// parallels for each region comes from USGS, which is published here:
11795// http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
11796function albersUsa() {
11797 var cache,
11798 cacheStream,
11799 lower48 = albers(), lower48Point,
11800 alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
11801 hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
11802 point, pointStream = {point: function(x, y) { point = [x, y]; }};
11803
11804 function albersUsa(coordinates) {
11805 var x = coordinates[0], y = coordinates[1];
11806 return point = null,
11807 (lower48Point.point(x, y), point)
11808 || (alaskaPoint.point(x, y), point)
11809 || (hawaiiPoint.point(x, y), point);
11810 }
11811
11812 albersUsa.invert = function(coordinates) {
11813 var k = lower48.scale(),
11814 t = lower48.translate(),
11815 x = (coordinates[0] - t[0]) / k,
11816 y = (coordinates[1] - t[1]) / k;
11817 return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
11818 : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
11819 : lower48).invert(coordinates);
11820 };
11821
11822 albersUsa.stream = function(stream) {
11823 return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
11824 };
11825
11826 albersUsa.precision = function(_) {
11827 if (!arguments.length) return lower48.precision();
11828 lower48.precision(_), alaska.precision(_), hawaii.precision(_);
11829 return reset();
11830 };
11831
11832 albersUsa.scale = function(_) {
11833 if (!arguments.length) return lower48.scale();
11834 lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
11835 return albersUsa.translate(lower48.translate());
11836 };
11837
11838 albersUsa.translate = function(_) {
11839 if (!arguments.length) return lower48.translate();
11840 var k = lower48.scale(), x = +_[0], y = +_[1];
11841
11842 lower48Point = lower48
11843 .translate(_)
11844 .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
11845 .stream(pointStream);
11846
11847 alaskaPoint = alaska
11848 .translate([x - 0.307 * k, y + 0.201 * k])
11849 .clipExtent([[x - 0.425 * k + epsilon$1, y + 0.120 * k + epsilon$1], [x - 0.214 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
11850 .stream(pointStream);
11851
11852 hawaiiPoint = hawaii
11853 .translate([x - 0.205 * k, y + 0.212 * k])
11854 .clipExtent([[x - 0.214 * k + epsilon$1, y + 0.166 * k + epsilon$1], [x - 0.115 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
11855 .stream(pointStream);
11856
11857 return reset();
11858 };
11859
11860 albersUsa.fitExtent = function(extent, object) {
11861 return fitExtent(albersUsa, extent, object);
11862 };
11863
11864 albersUsa.fitSize = function(size, object) {
11865 return fitSize(albersUsa, size, object);
11866 };
11867
11868 albersUsa.fitWidth = function(width, object) {
11869 return fitWidth(albersUsa, width, object);
11870 };
11871
11872 albersUsa.fitHeight = function(height, object) {
11873 return fitHeight(albersUsa, height, object);
11874 };
11875
11876 function reset() {
11877 cache = cacheStream = null;
11878 return albersUsa;
11879 }
11880
11881 return albersUsa.scale(1070);
11882}
11883
11884function azimuthalRaw(scale) {
11885 return function(x, y) {
11886 var cx = cos$1(x),
11887 cy = cos$1(y),
11888 k = scale(cx * cy);
11889 if (k === Infinity) return [2, 0];
11890 return [
11891 k * cy * sin$1(x),
11892 k * sin$1(y)
11893 ];
11894 }
11895}
11896
11897function azimuthalInvert(angle) {
11898 return function(x, y) {
11899 var z = sqrt$2(x * x + y * y),
11900 c = angle(z),
11901 sc = sin$1(c),
11902 cc = cos$1(c);
11903 return [
11904 atan2$1(x * sc, z * cc),
11905 asin$1(z && y * sc / z)
11906 ];
11907 }
11908}
11909
11910var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
11911 return sqrt$2(2 / (1 + cxcy));
11912});
11913
11914azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
11915 return 2 * asin$1(z / 2);
11916});
11917
11918function azimuthalEqualArea() {
11919 return projection(azimuthalEqualAreaRaw)
11920 .scale(124.75)
11921 .clipAngle(180 - 1e-3);
11922}
11923
11924var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
11925 return (c = acos$1(c)) && c / sin$1(c);
11926});
11927
11928azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
11929 return z;
11930});
11931
11932function azimuthalEquidistant() {
11933 return projection(azimuthalEquidistantRaw)
11934 .scale(79.4188)
11935 .clipAngle(180 - 1e-3);
11936}
11937
11938function mercatorRaw(lambda, phi) {
11939 return [lambda, log$1(tan((halfPi$1 + phi) / 2))];
11940}
11941
11942mercatorRaw.invert = function(x, y) {
11943 return [x, 2 * atan(exp(y)) - halfPi$1];
11944};
11945
11946function mercator() {
11947 return mercatorProjection(mercatorRaw)
11948 .scale(961 / tau$1);
11949}
11950
11951function mercatorProjection(project) {
11952 var m = projection(project),
11953 center = m.center,
11954 scale = m.scale,
11955 translate = m.translate,
11956 clipExtent = m.clipExtent,
11957 x0 = null, y0, x1, y1; // clip extent
11958
11959 m.scale = function(_) {
11960 return arguments.length ? (scale(_), reclip()) : scale();
11961 };
11962
11963 m.translate = function(_) {
11964 return arguments.length ? (translate(_), reclip()) : translate();
11965 };
11966
11967 m.center = function(_) {
11968 return arguments.length ? (center(_), reclip()) : center();
11969 };
11970
11971 m.clipExtent = function(_) {
11972 return arguments.length ? ((_ == null ? x0 = y0 = x1 = y1 = null : (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1])), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];
11973 };
11974
11975 function reclip() {
11976 var k = pi$1 * scale(),
11977 t = m(rotation(m.rotate()).invert([0, 0]));
11978 return clipExtent(x0 == null
11979 ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
11980 ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
11981 : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
11982 }
11983
11984 return reclip();
11985}
11986
11987function tany(y) {
11988 return tan((halfPi$1 + y) / 2);
11989}
11990
11991function conicConformalRaw(y0, y1) {
11992 var cy0 = cos$1(y0),
11993 n = y0 === y1 ? sin$1(y0) : log$1(cy0 / cos$1(y1)) / log$1(tany(y1) / tany(y0)),
11994 f = cy0 * pow$1(tany(y0), n) / n;
11995
11996 if (!n) return mercatorRaw;
11997
11998 function project(x, y) {
11999 if (f > 0) { if (y < -halfPi$1 + epsilon$1) y = -halfPi$1 + epsilon$1; }
12000 else { if (y > halfPi$1 - epsilon$1) y = halfPi$1 - epsilon$1; }
12001 var r = f / pow$1(tany(y), n);
12002 return [r * sin$1(n * x), f - r * cos$1(n * x)];
12003 }
12004
12005 project.invert = function(x, y) {
12006 var fy = f - y, r = sign$1(n) * sqrt$2(x * x + fy * fy),
12007 l = atan2$1(x, abs$1(fy)) * sign$1(fy);
12008 if (fy * n < 0)
12009 l -= pi$1 * sign$1(x) * sign$1(fy);
12010 return [l / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$1];
12011 };
12012
12013 return project;
12014}
12015
12016function conicConformal() {
12017 return conicProjection(conicConformalRaw)
12018 .scale(109.5)
12019 .parallels([30, 30]);
12020}
12021
12022function equirectangularRaw(lambda, phi) {
12023 return [lambda, phi];
12024}
12025
12026equirectangularRaw.invert = equirectangularRaw;
12027
12028function equirectangular() {
12029 return projection(equirectangularRaw)
12030 .scale(152.63);
12031}
12032
12033function conicEquidistantRaw(y0, y1) {
12034 var cy0 = cos$1(y0),
12035 n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
12036 g = cy0 / n + y0;
12037
12038 if (abs$1(n) < epsilon$1) return equirectangularRaw;
12039
12040 function project(x, y) {
12041 var gy = g - y, nx = n * x;
12042 return [gy * sin$1(nx), g - gy * cos$1(nx)];
12043 }
12044
12045 project.invert = function(x, y) {
12046 var gy = g - y,
12047 l = atan2$1(x, abs$1(gy)) * sign$1(gy);
12048 if (gy * n < 0)
12049 l -= pi$1 * sign$1(x) * sign$1(gy);
12050 return [l / n, g - sign$1(n) * sqrt$2(x * x + gy * gy)];
12051 };
12052
12053 return project;
12054}
12055
12056function conicEquidistant() {
12057 return conicProjection(conicEquidistantRaw)
12058 .scale(131.154)
12059 .center([0, 13.9389]);
12060}
12061
12062var A1 = 1.340264,
12063 A2 = -0.081106,
12064 A3 = 0.000893,
12065 A4 = 0.003796,
12066 M = sqrt$2(3) / 2,
12067 iterations = 12;
12068
12069function equalEarthRaw(lambda, phi) {
12070 var l = asin$1(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
12071 return [
12072 lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
12073 l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
12074 ];
12075}
12076
12077equalEarthRaw.invert = function(x, y) {
12078 var l = y, l2 = l * l, l6 = l2 * l2 * l2;
12079 for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
12080 fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
12081 fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
12082 l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
12083 if (abs$1(delta) < epsilon2) break;
12084 }
12085 return [
12086 M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
12087 asin$1(sin$1(l) / M)
12088 ];
12089};
12090
12091function equalEarth() {
12092 return projection(equalEarthRaw)
12093 .scale(177.158);
12094}
12095
12096function gnomonicRaw(x, y) {
12097 var cy = cos$1(y), k = cos$1(x) * cy;
12098 return [cy * sin$1(x) / k, sin$1(y) / k];
12099}
12100
12101gnomonicRaw.invert = azimuthalInvert(atan);
12102
12103function gnomonic() {
12104 return projection(gnomonicRaw)
12105 .scale(144.049)
12106 .clipAngle(60);
12107}
12108
12109function identity$4() {
12110 var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect
12111 alpha = 0, ca, sa, // angle
12112 x0 = null, y0, x1, y1, // clip extent
12113 kx = 1, ky = 1,
12114 transform = transformer$3({
12115 point: function(x, y) {
12116 var p = projection([x, y]);
12117 this.stream.point(p[0], p[1]);
12118 }
12119 }),
12120 postclip = identity$5,
12121 cache,
12122 cacheStream;
12123
12124 function reset() {
12125 kx = k * sx;
12126 ky = k * sy;
12127 cache = cacheStream = null;
12128 return projection;
12129 }
12130
12131 function projection (p) {
12132 var x = p[0] * kx, y = p[1] * ky;
12133 if (alpha) {
12134 var t = y * ca - x * sa;
12135 x = x * ca + y * sa;
12136 y = t;
12137 }
12138 return [x + tx, y + ty];
12139 }
12140 projection.invert = function(p) {
12141 var x = p[0] - tx, y = p[1] - ty;
12142 if (alpha) {
12143 var t = y * ca + x * sa;
12144 x = x * ca - y * sa;
12145 y = t;
12146 }
12147 return [x / kx, y / ky];
12148 };
12149 projection.stream = function(stream) {
12150 return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
12151 };
12152 projection.postclip = function(_) {
12153 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
12154 };
12155 projection.clipExtent = function(_) {
12156 return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
12157 };
12158 projection.scale = function(_) {
12159 return arguments.length ? (k = +_, reset()) : k;
12160 };
12161 projection.translate = function(_) {
12162 return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];
12163 };
12164 projection.angle = function(_) {
12165 return arguments.length ? (alpha = _ % 360 * radians, sa = sin$1(alpha), ca = cos$1(alpha), reset()) : alpha * degrees;
12166 };
12167 projection.reflectX = function(_) {
12168 return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;
12169 };
12170 projection.reflectY = function(_) {
12171 return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;
12172 };
12173 projection.fitExtent = function(extent, object) {
12174 return fitExtent(projection, extent, object);
12175 };
12176 projection.fitSize = function(size, object) {
12177 return fitSize(projection, size, object);
12178 };
12179 projection.fitWidth = function(width, object) {
12180 return fitWidth(projection, width, object);
12181 };
12182 projection.fitHeight = function(height, object) {
12183 return fitHeight(projection, height, object);
12184 };
12185
12186 return projection;
12187}
12188
12189function naturalEarth1Raw(lambda, phi) {
12190 var phi2 = phi * phi, phi4 = phi2 * phi2;
12191 return [
12192 lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
12193 phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
12194 ];
12195}
12196
12197naturalEarth1Raw.invert = function(x, y) {
12198 var phi = y, i = 25, delta;
12199 do {
12200 var phi2 = phi * phi, phi4 = phi2 * phi2;
12201 phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
12202 (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
12203 } while (abs$1(delta) > epsilon$1 && --i > 0);
12204 return [
12205 x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
12206 phi
12207 ];
12208};
12209
12210function naturalEarth1() {
12211 return projection(naturalEarth1Raw)
12212 .scale(175.295);
12213}
12214
12215function orthographicRaw(x, y) {
12216 return [cos$1(y) * sin$1(x), sin$1(y)];
12217}
12218
12219orthographicRaw.invert = azimuthalInvert(asin$1);
12220
12221function orthographic() {
12222 return projection(orthographicRaw)
12223 .scale(249.5)
12224 .clipAngle(90 + epsilon$1);
12225}
12226
12227function stereographicRaw(x, y) {
12228 var cy = cos$1(y), k = 1 + cos$1(x) * cy;
12229 return [cy * sin$1(x) / k, sin$1(y) / k];
12230}
12231
12232stereographicRaw.invert = azimuthalInvert(function(z) {
12233 return 2 * atan(z);
12234});
12235
12236function stereographic() {
12237 return projection(stereographicRaw)
12238 .scale(250)
12239 .clipAngle(142);
12240}
12241
12242function transverseMercatorRaw(lambda, phi) {
12243 return [log$1(tan((halfPi$1 + phi) / 2)), -lambda];
12244}
12245
12246transverseMercatorRaw.invert = function(x, y) {
12247 return [-y, 2 * atan(exp(x)) - halfPi$1];
12248};
12249
12250function transverseMercator() {
12251 var m = mercatorProjection(transverseMercatorRaw),
12252 center = m.center,
12253 rotate = m.rotate;
12254
12255 m.center = function(_) {
12256 return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
12257 };
12258
12259 m.rotate = function(_) {
12260 return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
12261 };
12262
12263 return rotate([0, 0, 90])
12264 .scale(159.155);
12265}
12266
12267function defaultSeparation$1(a, b) {
12268 return a.parent === b.parent ? 1 : 2;
12269}
12270
12271function meanX(children) {
12272 return children.reduce(meanXReduce, 0) / children.length;
12273}
12274
12275function meanXReduce(x, c) {
12276 return x + c.x;
12277}
12278
12279function maxY(children) {
12280 return 1 + children.reduce(maxYReduce, 0);
12281}
12282
12283function maxYReduce(y, c) {
12284 return Math.max(y, c.y);
12285}
12286
12287function leafLeft(node) {
12288 var children;
12289 while (children = node.children) node = children[0];
12290 return node;
12291}
12292
12293function leafRight(node) {
12294 var children;
12295 while (children = node.children) node = children[children.length - 1];
12296 return node;
12297}
12298
12299function cluster() {
12300 var separation = defaultSeparation$1,
12301 dx = 1,
12302 dy = 1,
12303 nodeSize = false;
12304
12305 function cluster(root) {
12306 var previousNode,
12307 x = 0;
12308
12309 // First walk, computing the initial x & y values.
12310 root.eachAfter(function(node) {
12311 var children = node.children;
12312 if (children) {
12313 node.x = meanX(children);
12314 node.y = maxY(children);
12315 } else {
12316 node.x = previousNode ? x += separation(node, previousNode) : 0;
12317 node.y = 0;
12318 previousNode = node;
12319 }
12320 });
12321
12322 var left = leafLeft(root),
12323 right = leafRight(root),
12324 x0 = left.x - separation(left, right) / 2,
12325 x1 = right.x + separation(right, left) / 2;
12326
12327 // Second walk, normalizing x & y to the desired size.
12328 return root.eachAfter(nodeSize ? function(node) {
12329 node.x = (node.x - root.x) * dx;
12330 node.y = (root.y - node.y) * dy;
12331 } : function(node) {
12332 node.x = (node.x - x0) / (x1 - x0) * dx;
12333 node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
12334 });
12335 }
12336
12337 cluster.separation = function(x) {
12338 return arguments.length ? (separation = x, cluster) : separation;
12339 };
12340
12341 cluster.size = function(x) {
12342 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
12343 };
12344
12345 cluster.nodeSize = function(x) {
12346 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
12347 };
12348
12349 return cluster;
12350}
12351
12352function count(node) {
12353 var sum = 0,
12354 children = node.children,
12355 i = children && children.length;
12356 if (!i) sum = 1;
12357 else while (--i >= 0) sum += children[i].value;
12358 node.value = sum;
12359}
12360
12361function node_count() {
12362 return this.eachAfter(count);
12363}
12364
12365function node_each(callback, that) {
12366 let index = -1;
12367 for (const node of this) {
12368 callback.call(that, node, ++index, this);
12369 }
12370 return this;
12371}
12372
12373function node_eachBefore(callback, that) {
12374 var node = this, nodes = [node], children, i, index = -1;
12375 while (node = nodes.pop()) {
12376 callback.call(that, node, ++index, this);
12377 if (children = node.children) {
12378 for (i = children.length - 1; i >= 0; --i) {
12379 nodes.push(children[i]);
12380 }
12381 }
12382 }
12383 return this;
12384}
12385
12386function node_eachAfter(callback, that) {
12387 var node = this, nodes = [node], next = [], children, i, n, index = -1;
12388 while (node = nodes.pop()) {
12389 next.push(node);
12390 if (children = node.children) {
12391 for (i = 0, n = children.length; i < n; ++i) {
12392 nodes.push(children[i]);
12393 }
12394 }
12395 }
12396 while (node = next.pop()) {
12397 callback.call(that, node, ++index, this);
12398 }
12399 return this;
12400}
12401
12402function node_find(callback, that) {
12403 let index = -1;
12404 for (const node of this) {
12405 if (callback.call(that, node, ++index, this)) {
12406 return node;
12407 }
12408 }
12409}
12410
12411function node_sum(value) {
12412 return this.eachAfter(function(node) {
12413 var sum = +value(node.data) || 0,
12414 children = node.children,
12415 i = children && children.length;
12416 while (--i >= 0) sum += children[i].value;
12417 node.value = sum;
12418 });
12419}
12420
12421function node_sort(compare) {
12422 return this.eachBefore(function(node) {
12423 if (node.children) {
12424 node.children.sort(compare);
12425 }
12426 });
12427}
12428
12429function node_path(end) {
12430 var start = this,
12431 ancestor = leastCommonAncestor(start, end),
12432 nodes = [start];
12433 while (start !== ancestor) {
12434 start = start.parent;
12435 nodes.push(start);
12436 }
12437 var k = nodes.length;
12438 while (end !== ancestor) {
12439 nodes.splice(k, 0, end);
12440 end = end.parent;
12441 }
12442 return nodes;
12443}
12444
12445function leastCommonAncestor(a, b) {
12446 if (a === b) return a;
12447 var aNodes = a.ancestors(),
12448 bNodes = b.ancestors(),
12449 c = null;
12450 a = aNodes.pop();
12451 b = bNodes.pop();
12452 while (a === b) {
12453 c = a;
12454 a = aNodes.pop();
12455 b = bNodes.pop();
12456 }
12457 return c;
12458}
12459
12460function node_ancestors() {
12461 var node = this, nodes = [node];
12462 while (node = node.parent) {
12463 nodes.push(node);
12464 }
12465 return nodes;
12466}
12467
12468function node_descendants() {
12469 return Array.from(this);
12470}
12471
12472function node_leaves() {
12473 var leaves = [];
12474 this.eachBefore(function(node) {
12475 if (!node.children) {
12476 leaves.push(node);
12477 }
12478 });
12479 return leaves;
12480}
12481
12482function node_links() {
12483 var root = this, links = [];
12484 root.each(function(node) {
12485 if (node !== root) { // Don’t include the root’s parent, if any.
12486 links.push({source: node.parent, target: node});
12487 }
12488 });
12489 return links;
12490}
12491
12492function* node_iterator() {
12493 var node = this, current, next = [node], children, i, n;
12494 do {
12495 current = next.reverse(), next = [];
12496 while (node = current.pop()) {
12497 yield node;
12498 if (children = node.children) {
12499 for (i = 0, n = children.length; i < n; ++i) {
12500 next.push(children[i]);
12501 }
12502 }
12503 }
12504 } while (next.length);
12505}
12506
12507function hierarchy(data, children) {
12508 if (data instanceof Map) {
12509 data = [undefined, data];
12510 if (children === undefined) children = mapChildren;
12511 } else if (children === undefined) {
12512 children = objectChildren;
12513 }
12514
12515 var root = new Node$1(data),
12516 node,
12517 nodes = [root],
12518 child,
12519 childs,
12520 i,
12521 n;
12522
12523 while (node = nodes.pop()) {
12524 if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
12525 node.children = childs;
12526 for (i = n - 1; i >= 0; --i) {
12527 nodes.push(child = childs[i] = new Node$1(childs[i]));
12528 child.parent = node;
12529 child.depth = node.depth + 1;
12530 }
12531 }
12532 }
12533
12534 return root.eachBefore(computeHeight);
12535}
12536
12537function node_copy() {
12538 return hierarchy(this).eachBefore(copyData);
12539}
12540
12541function objectChildren(d) {
12542 return d.children;
12543}
12544
12545function mapChildren(d) {
12546 return Array.isArray(d) ? d[1] : null;
12547}
12548
12549function copyData(node) {
12550 if (node.data.value !== undefined) node.value = node.data.value;
12551 node.data = node.data.data;
12552}
12553
12554function computeHeight(node) {
12555 var height = 0;
12556 do node.height = height;
12557 while ((node = node.parent) && (node.height < ++height));
12558}
12559
12560function Node$1(data) {
12561 this.data = data;
12562 this.depth =
12563 this.height = 0;
12564 this.parent = null;
12565}
12566
12567Node$1.prototype = hierarchy.prototype = {
12568 constructor: Node$1,
12569 count: node_count,
12570 each: node_each,
12571 eachAfter: node_eachAfter,
12572 eachBefore: node_eachBefore,
12573 find: node_find,
12574 sum: node_sum,
12575 sort: node_sort,
12576 path: node_path,
12577 ancestors: node_ancestors,
12578 descendants: node_descendants,
12579 leaves: node_leaves,
12580 links: node_links,
12581 copy: node_copy,
12582 [Symbol.iterator]: node_iterator
12583};
12584
12585function array$1(x) {
12586 return typeof x === "object" && "length" in x
12587 ? x // Array, TypedArray, NodeList, array-like
12588 : Array.from(x); // Map, Set, iterable, string, or anything else
12589}
12590
12591function shuffle(array) {
12592 var m = array.length,
12593 t,
12594 i;
12595
12596 while (m) {
12597 i = Math.random() * m-- | 0;
12598 t = array[m];
12599 array[m] = array[i];
12600 array[i] = t;
12601 }
12602
12603 return array;
12604}
12605
12606function enclose(circles) {
12607 var i = 0, n = (circles = shuffle(Array.from(circles))).length, B = [], p, e;
12608
12609 while (i < n) {
12610 p = circles[i];
12611 if (e && enclosesWeak(e, p)) ++i;
12612 else e = encloseBasis(B = extendBasis(B, p)), i = 0;
12613 }
12614
12615 return e;
12616}
12617
12618function extendBasis(B, p) {
12619 var i, j;
12620
12621 if (enclosesWeakAll(p, B)) return [p];
12622
12623 // If we get here then B must have at least one element.
12624 for (i = 0; i < B.length; ++i) {
12625 if (enclosesNot(p, B[i])
12626 && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
12627 return [B[i], p];
12628 }
12629 }
12630
12631 // If we get here then B must have at least two elements.
12632 for (i = 0; i < B.length - 1; ++i) {
12633 for (j = i + 1; j < B.length; ++j) {
12634 if (enclosesNot(encloseBasis2(B[i], B[j]), p)
12635 && enclosesNot(encloseBasis2(B[i], p), B[j])
12636 && enclosesNot(encloseBasis2(B[j], p), B[i])
12637 && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
12638 return [B[i], B[j], p];
12639 }
12640 }
12641 }
12642
12643 // If we get here then something is very wrong.
12644 throw new Error;
12645}
12646
12647function enclosesNot(a, b) {
12648 var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
12649 return dr < 0 || dr * dr < dx * dx + dy * dy;
12650}
12651
12652function enclosesWeak(a, b) {
12653 var dr = a.r - b.r + Math.max(a.r, b.r, 1) * 1e-9, dx = b.x - a.x, dy = b.y - a.y;
12654 return dr > 0 && dr * dr > dx * dx + dy * dy;
12655}
12656
12657function enclosesWeakAll(a, B) {
12658 for (var i = 0; i < B.length; ++i) {
12659 if (!enclosesWeak(a, B[i])) {
12660 return false;
12661 }
12662 }
12663 return true;
12664}
12665
12666function encloseBasis(B) {
12667 switch (B.length) {
12668 case 1: return encloseBasis1(B[0]);
12669 case 2: return encloseBasis2(B[0], B[1]);
12670 case 3: return encloseBasis3(B[0], B[1], B[2]);
12671 }
12672}
12673
12674function encloseBasis1(a) {
12675 return {
12676 x: a.x,
12677 y: a.y,
12678 r: a.r
12679 };
12680}
12681
12682function encloseBasis2(a, b) {
12683 var x1 = a.x, y1 = a.y, r1 = a.r,
12684 x2 = b.x, y2 = b.y, r2 = b.r,
12685 x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
12686 l = Math.sqrt(x21 * x21 + y21 * y21);
12687 return {
12688 x: (x1 + x2 + x21 / l * r21) / 2,
12689 y: (y1 + y2 + y21 / l * r21) / 2,
12690 r: (l + r1 + r2) / 2
12691 };
12692}
12693
12694function encloseBasis3(a, b, c) {
12695 var x1 = a.x, y1 = a.y, r1 = a.r,
12696 x2 = b.x, y2 = b.y, r2 = b.r,
12697 x3 = c.x, y3 = c.y, r3 = c.r,
12698 a2 = x1 - x2,
12699 a3 = x1 - x3,
12700 b2 = y1 - y2,
12701 b3 = y1 - y3,
12702 c2 = r2 - r1,
12703 c3 = r3 - r1,
12704 d1 = x1 * x1 + y1 * y1 - r1 * r1,
12705 d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
12706 d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
12707 ab = a3 * b2 - a2 * b3,
12708 xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
12709 xb = (b3 * c2 - b2 * c3) / ab,
12710 ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
12711 yb = (a2 * c3 - a3 * c2) / ab,
12712 A = xb * xb + yb * yb - 1,
12713 B = 2 * (r1 + xa * xb + ya * yb),
12714 C = xa * xa + ya * ya - r1 * r1,
12715 r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
12716 return {
12717 x: x1 + xa + xb * r,
12718 y: y1 + ya + yb * r,
12719 r: r
12720 };
12721}
12722
12723function place(b, a, c) {
12724 var dx = b.x - a.x, x, a2,
12725 dy = b.y - a.y, y, b2,
12726 d2 = dx * dx + dy * dy;
12727 if (d2) {
12728 a2 = a.r + c.r, a2 *= a2;
12729 b2 = b.r + c.r, b2 *= b2;
12730 if (a2 > b2) {
12731 x = (d2 + b2 - a2) / (2 * d2);
12732 y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
12733 c.x = b.x - x * dx - y * dy;
12734 c.y = b.y - x * dy + y * dx;
12735 } else {
12736 x = (d2 + a2 - b2) / (2 * d2);
12737 y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
12738 c.x = a.x + x * dx - y * dy;
12739 c.y = a.y + x * dy + y * dx;
12740 }
12741 } else {
12742 c.x = a.x + c.r;
12743 c.y = a.y;
12744 }
12745}
12746
12747function intersects(a, b) {
12748 var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
12749 return dr > 0 && dr * dr > dx * dx + dy * dy;
12750}
12751
12752function score(node) {
12753 var a = node._,
12754 b = node.next._,
12755 ab = a.r + b.r,
12756 dx = (a.x * b.r + b.x * a.r) / ab,
12757 dy = (a.y * b.r + b.y * a.r) / ab;
12758 return dx * dx + dy * dy;
12759}
12760
12761function Node(circle) {
12762 this._ = circle;
12763 this.next = null;
12764 this.previous = null;
12765}
12766
12767function packEnclose(circles) {
12768 if (!(n = (circles = array$1(circles)).length)) return 0;
12769
12770 var a, b, c, n, aa, ca, i, j, k, sj, sk;
12771
12772 // Place the first circle.
12773 a = circles[0], a.x = 0, a.y = 0;
12774 if (!(n > 1)) return a.r;
12775
12776 // Place the second circle.
12777 b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
12778 if (!(n > 2)) return a.r + b.r;
12779
12780 // Place the third circle.
12781 place(b, a, c = circles[2]);
12782
12783 // Initialize the front-chain using the first three circles a, b and c.
12784 a = new Node(a), b = new Node(b), c = new Node(c);
12785 a.next = c.previous = b;
12786 b.next = a.previous = c;
12787 c.next = b.previous = a;
12788
12789 // Attempt to place each remaining circle…
12790 pack: for (i = 3; i < n; ++i) {
12791 place(a._, b._, c = circles[i]), c = new Node(c);
12792
12793 // Find the closest intersecting circle on the front-chain, if any.
12794 // “Closeness” is determined by linear distance along the front-chain.
12795 // “Ahead” or “behind” is likewise determined by linear distance.
12796 j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
12797 do {
12798 if (sj <= sk) {
12799 if (intersects(j._, c._)) {
12800 b = j, a.next = b, b.previous = a, --i;
12801 continue pack;
12802 }
12803 sj += j._.r, j = j.next;
12804 } else {
12805 if (intersects(k._, c._)) {
12806 a = k, a.next = b, b.previous = a, --i;
12807 continue pack;
12808 }
12809 sk += k._.r, k = k.previous;
12810 }
12811 } while (j !== k.next);
12812
12813 // Success! Insert the new circle c between a and b.
12814 c.previous = a, c.next = b, a.next = b.previous = b = c;
12815
12816 // Compute the new closest circle pair to the centroid.
12817 aa = score(a);
12818 while ((c = c.next) !== b) {
12819 if ((ca = score(c)) < aa) {
12820 a = c, aa = ca;
12821 }
12822 }
12823 b = a.next;
12824 }
12825
12826 // Compute the enclosing circle of the front chain.
12827 a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
12828
12829 // Translate the circles to put the enclosing circle around the origin.
12830 for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
12831
12832 return c.r;
12833}
12834
12835function siblings(circles) {
12836 packEnclose(circles);
12837 return circles;
12838}
12839
12840function optional(f) {
12841 return f == null ? null : required(f);
12842}
12843
12844function required(f) {
12845 if (typeof f !== "function") throw new Error;
12846 return f;
12847}
12848
12849function constantZero() {
12850 return 0;
12851}
12852
12853function constant$2(x) {
12854 return function() {
12855 return x;
12856 };
12857}
12858
12859function defaultRadius(d) {
12860 return Math.sqrt(d.value);
12861}
12862
12863function index$1() {
12864 var radius = null,
12865 dx = 1,
12866 dy = 1,
12867 padding = constantZero;
12868
12869 function pack(root) {
12870 root.x = dx / 2, root.y = dy / 2;
12871 if (radius) {
12872 root.eachBefore(radiusLeaf(radius))
12873 .eachAfter(packChildren(padding, 0.5))
12874 .eachBefore(translateChild(1));
12875 } else {
12876 root.eachBefore(radiusLeaf(defaultRadius))
12877 .eachAfter(packChildren(constantZero, 1))
12878 .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
12879 .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
12880 }
12881 return root;
12882 }
12883
12884 pack.radius = function(x) {
12885 return arguments.length ? (radius = optional(x), pack) : radius;
12886 };
12887
12888 pack.size = function(x) {
12889 return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
12890 };
12891
12892 pack.padding = function(x) {
12893 return arguments.length ? (padding = typeof x === "function" ? x : constant$2(+x), pack) : padding;
12894 };
12895
12896 return pack;
12897}
12898
12899function radiusLeaf(radius) {
12900 return function(node) {
12901 if (!node.children) {
12902 node.r = Math.max(0, +radius(node) || 0);
12903 }
12904 };
12905}
12906
12907function packChildren(padding, k) {
12908 return function(node) {
12909 if (children = node.children) {
12910 var children,
12911 i,
12912 n = children.length,
12913 r = padding(node) * k || 0,
12914 e;
12915
12916 if (r) for (i = 0; i < n; ++i) children[i].r += r;
12917 e = packEnclose(children);
12918 if (r) for (i = 0; i < n; ++i) children[i].r -= r;
12919 node.r = e + r;
12920 }
12921 };
12922}
12923
12924function translateChild(k) {
12925 return function(node) {
12926 var parent = node.parent;
12927 node.r *= k;
12928 if (parent) {
12929 node.x = parent.x + k * node.x;
12930 node.y = parent.y + k * node.y;
12931 }
12932 };
12933}
12934
12935function roundNode(node) {
12936 node.x0 = Math.round(node.x0);
12937 node.y0 = Math.round(node.y0);
12938 node.x1 = Math.round(node.x1);
12939 node.y1 = Math.round(node.y1);
12940}
12941
12942function treemapDice(parent, x0, y0, x1, y1) {
12943 var nodes = parent.children,
12944 node,
12945 i = -1,
12946 n = nodes.length,
12947 k = parent.value && (x1 - x0) / parent.value;
12948
12949 while (++i < n) {
12950 node = nodes[i], node.y0 = y0, node.y1 = y1;
12951 node.x0 = x0, node.x1 = x0 += node.value * k;
12952 }
12953}
12954
12955function partition() {
12956 var dx = 1,
12957 dy = 1,
12958 padding = 0,
12959 round = false;
12960
12961 function partition(root) {
12962 var n = root.height + 1;
12963 root.x0 =
12964 root.y0 = padding;
12965 root.x1 = dx;
12966 root.y1 = dy / n;
12967 root.eachBefore(positionNode(dy, n));
12968 if (round) root.eachBefore(roundNode);
12969 return root;
12970 }
12971
12972 function positionNode(dy, n) {
12973 return function(node) {
12974 if (node.children) {
12975 treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
12976 }
12977 var x0 = node.x0,
12978 y0 = node.y0,
12979 x1 = node.x1 - padding,
12980 y1 = node.y1 - padding;
12981 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
12982 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
12983 node.x0 = x0;
12984 node.y0 = y0;
12985 node.x1 = x1;
12986 node.y1 = y1;
12987 };
12988 }
12989
12990 partition.round = function(x) {
12991 return arguments.length ? (round = !!x, partition) : round;
12992 };
12993
12994 partition.size = function(x) {
12995 return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
12996 };
12997
12998 partition.padding = function(x) {
12999 return arguments.length ? (padding = +x, partition) : padding;
13000 };
13001
13002 return partition;
13003}
13004
13005var preroot = {depth: -1},
13006 ambiguous = {};
13007
13008function defaultId(d) {
13009 return d.id;
13010}
13011
13012function defaultParentId(d) {
13013 return d.parentId;
13014}
13015
13016function stratify() {
13017 var id = defaultId,
13018 parentId = defaultParentId;
13019
13020 function stratify(data) {
13021 var nodes = Array.from(data),
13022 n = nodes.length,
13023 d,
13024 i,
13025 root,
13026 parent,
13027 node,
13028 nodeId,
13029 nodeKey,
13030 nodeByKey = new Map;
13031
13032 for (i = 0; i < n; ++i) {
13033 d = nodes[i], node = nodes[i] = new Node$1(d);
13034 if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
13035 nodeKey = node.id = nodeId;
13036 nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
13037 }
13038 if ((nodeId = parentId(d, i, data)) != null && (nodeId += "")) {
13039 node.parent = nodeId;
13040 }
13041 }
13042
13043 for (i = 0; i < n; ++i) {
13044 node = nodes[i];
13045 if (nodeId = node.parent) {
13046 parent = nodeByKey.get(nodeId);
13047 if (!parent) throw new Error("missing: " + nodeId);
13048 if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
13049 if (parent.children) parent.children.push(node);
13050 else parent.children = [node];
13051 node.parent = parent;
13052 } else {
13053 if (root) throw new Error("multiple roots");
13054 root = node;
13055 }
13056 }
13057
13058 if (!root) throw new Error("no root");
13059 root.parent = preroot;
13060 root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
13061 root.parent = null;
13062 if (n > 0) throw new Error("cycle");
13063
13064 return root;
13065 }
13066
13067 stratify.id = function(x) {
13068 return arguments.length ? (id = required(x), stratify) : id;
13069 };
13070
13071 stratify.parentId = function(x) {
13072 return arguments.length ? (parentId = required(x), stratify) : parentId;
13073 };
13074
13075 return stratify;
13076}
13077
13078function defaultSeparation(a, b) {
13079 return a.parent === b.parent ? 1 : 2;
13080}
13081
13082// function radialSeparation(a, b) {
13083// return (a.parent === b.parent ? 1 : 2) / a.depth;
13084// }
13085
13086// This function is used to traverse the left contour of a subtree (or
13087// subforest). It returns the successor of v on this contour. This successor is
13088// either given by the leftmost child of v or by the thread of v. The function
13089// returns null if and only if v is on the highest level of its subtree.
13090function nextLeft(v) {
13091 var children = v.children;
13092 return children ? children[0] : v.t;
13093}
13094
13095// This function works analogously to nextLeft.
13096function nextRight(v) {
13097 var children = v.children;
13098 return children ? children[children.length - 1] : v.t;
13099}
13100
13101// Shifts the current subtree rooted at w+. This is done by increasing
13102// prelim(w+) and mod(w+) by shift.
13103function moveSubtree(wm, wp, shift) {
13104 var change = shift / (wp.i - wm.i);
13105 wp.c -= change;
13106 wp.s += shift;
13107 wm.c += change;
13108 wp.z += shift;
13109 wp.m += shift;
13110}
13111
13112// All other shifts, applied to the smaller subtrees between w- and w+, are
13113// performed by this function. To prepare the shifts, we have to adjust
13114// change(w+), shift(w+), and change(w-).
13115function executeShifts(v) {
13116 var shift = 0,
13117 change = 0,
13118 children = v.children,
13119 i = children.length,
13120 w;
13121 while (--i >= 0) {
13122 w = children[i];
13123 w.z += shift;
13124 w.m += shift;
13125 shift += w.s + (change += w.c);
13126 }
13127}
13128
13129// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
13130// returns the specified (default) ancestor.
13131function nextAncestor(vim, v, ancestor) {
13132 return vim.a.parent === v.parent ? vim.a : ancestor;
13133}
13134
13135function TreeNode(node, i) {
13136 this._ = node;
13137 this.parent = null;
13138 this.children = null;
13139 this.A = null; // default ancestor
13140 this.a = this; // ancestor
13141 this.z = 0; // prelim
13142 this.m = 0; // mod
13143 this.c = 0; // change
13144 this.s = 0; // shift
13145 this.t = null; // thread
13146 this.i = i; // number
13147}
13148
13149TreeNode.prototype = Object.create(Node$1.prototype);
13150
13151function treeRoot(root) {
13152 var tree = new TreeNode(root, 0),
13153 node,
13154 nodes = [tree],
13155 child,
13156 children,
13157 i,
13158 n;
13159
13160 while (node = nodes.pop()) {
13161 if (children = node._.children) {
13162 node.children = new Array(n = children.length);
13163 for (i = n - 1; i >= 0; --i) {
13164 nodes.push(child = node.children[i] = new TreeNode(children[i], i));
13165 child.parent = node;
13166 }
13167 }
13168 }
13169
13170 (tree.parent = new TreeNode(null, 0)).children = [tree];
13171 return tree;
13172}
13173
13174// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
13175function tree() {
13176 var separation = defaultSeparation,
13177 dx = 1,
13178 dy = 1,
13179 nodeSize = null;
13180
13181 function tree(root) {
13182 var t = treeRoot(root);
13183
13184 // Compute the layout using Buchheim et al.’s algorithm.
13185 t.eachAfter(firstWalk), t.parent.m = -t.z;
13186 t.eachBefore(secondWalk);
13187
13188 // If a fixed node size is specified, scale x and y.
13189 if (nodeSize) root.eachBefore(sizeNode);
13190
13191 // If a fixed tree size is specified, scale x and y based on the extent.
13192 // Compute the left-most, right-most, and depth-most nodes for extents.
13193 else {
13194 var left = root,
13195 right = root,
13196 bottom = root;
13197 root.eachBefore(function(node) {
13198 if (node.x < left.x) left = node;
13199 if (node.x > right.x) right = node;
13200 if (node.depth > bottom.depth) bottom = node;
13201 });
13202 var s = left === right ? 1 : separation(left, right) / 2,
13203 tx = s - left.x,
13204 kx = dx / (right.x + s + tx),
13205 ky = dy / (bottom.depth || 1);
13206 root.eachBefore(function(node) {
13207 node.x = (node.x + tx) * kx;
13208 node.y = node.depth * ky;
13209 });
13210 }
13211
13212 return root;
13213 }
13214
13215 // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
13216 // applied recursively to the children of v, as well as the function
13217 // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
13218 // node v is placed to the midpoint of its outermost children.
13219 function firstWalk(v) {
13220 var children = v.children,
13221 siblings = v.parent.children,
13222 w = v.i ? siblings[v.i - 1] : null;
13223 if (children) {
13224 executeShifts(v);
13225 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
13226 if (w) {
13227 v.z = w.z + separation(v._, w._);
13228 v.m = v.z - midpoint;
13229 } else {
13230 v.z = midpoint;
13231 }
13232 } else if (w) {
13233 v.z = w.z + separation(v._, w._);
13234 }
13235 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
13236 }
13237
13238 // Computes all real x-coordinates by summing up the modifiers recursively.
13239 function secondWalk(v) {
13240 v._.x = v.z + v.parent.m;
13241 v.m += v.parent.m;
13242 }
13243
13244 // The core of the algorithm. Here, a new subtree is combined with the
13245 // previous subtrees. Threads are used to traverse the inside and outside
13246 // contours of the left and right subtree up to the highest common level. The
13247 // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
13248 // superscript o means outside and i means inside, the subscript - means left
13249 // subtree and + means right subtree. For summing up the modifiers along the
13250 // contour, we use respective variables si+, si-, so-, and so+. Whenever two
13251 // nodes of the inside contours conflict, we compute the left one of the
13252 // greatest uncommon ancestors using the function ANCESTOR and call MOVE
13253 // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
13254 // Finally, we add a new thread (if necessary).
13255 function apportion(v, w, ancestor) {
13256 if (w) {
13257 var vip = v,
13258 vop = v,
13259 vim = w,
13260 vom = vip.parent.children[0],
13261 sip = vip.m,
13262 sop = vop.m,
13263 sim = vim.m,
13264 som = vom.m,
13265 shift;
13266 while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
13267 vom = nextLeft(vom);
13268 vop = nextRight(vop);
13269 vop.a = v;
13270 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
13271 if (shift > 0) {
13272 moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
13273 sip += shift;
13274 sop += shift;
13275 }
13276 sim += vim.m;
13277 sip += vip.m;
13278 som += vom.m;
13279 sop += vop.m;
13280 }
13281 if (vim && !nextRight(vop)) {
13282 vop.t = vim;
13283 vop.m += sim - sop;
13284 }
13285 if (vip && !nextLeft(vom)) {
13286 vom.t = vip;
13287 vom.m += sip - som;
13288 ancestor = v;
13289 }
13290 }
13291 return ancestor;
13292 }
13293
13294 function sizeNode(node) {
13295 node.x *= dx;
13296 node.y = node.depth * dy;
13297 }
13298
13299 tree.separation = function(x) {
13300 return arguments.length ? (separation = x, tree) : separation;
13301 };
13302
13303 tree.size = function(x) {
13304 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
13305 };
13306
13307 tree.nodeSize = function(x) {
13308 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
13309 };
13310
13311 return tree;
13312}
13313
13314function treemapSlice(parent, x0, y0, x1, y1) {
13315 var nodes = parent.children,
13316 node,
13317 i = -1,
13318 n = nodes.length,
13319 k = parent.value && (y1 - y0) / parent.value;
13320
13321 while (++i < n) {
13322 node = nodes[i], node.x0 = x0, node.x1 = x1;
13323 node.y0 = y0, node.y1 = y0 += node.value * k;
13324 }
13325}
13326
13327var phi = (1 + Math.sqrt(5)) / 2;
13328
13329function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
13330 var rows = [],
13331 nodes = parent.children,
13332 row,
13333 nodeValue,
13334 i0 = 0,
13335 i1 = 0,
13336 n = nodes.length,
13337 dx, dy,
13338 value = parent.value,
13339 sumValue,
13340 minValue,
13341 maxValue,
13342 newRatio,
13343 minRatio,
13344 alpha,
13345 beta;
13346
13347 while (i0 < n) {
13348 dx = x1 - x0, dy = y1 - y0;
13349
13350 // Find the next non-empty node.
13351 do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
13352 minValue = maxValue = sumValue;
13353 alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
13354 beta = sumValue * sumValue * alpha;
13355 minRatio = Math.max(maxValue / beta, beta / minValue);
13356
13357 // Keep adding nodes while the aspect ratio maintains or improves.
13358 for (; i1 < n; ++i1) {
13359 sumValue += nodeValue = nodes[i1].value;
13360 if (nodeValue < minValue) minValue = nodeValue;
13361 if (nodeValue > maxValue) maxValue = nodeValue;
13362 beta = sumValue * sumValue * alpha;
13363 newRatio = Math.max(maxValue / beta, beta / minValue);
13364 if (newRatio > minRatio) { sumValue -= nodeValue; break; }
13365 minRatio = newRatio;
13366 }
13367
13368 // Position and record the row orientation.
13369 rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
13370 if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
13371 else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
13372 value -= sumValue, i0 = i1;
13373 }
13374
13375 return rows;
13376}
13377
13378var squarify = (function custom(ratio) {
13379
13380 function squarify(parent, x0, y0, x1, y1) {
13381 squarifyRatio(ratio, parent, x0, y0, x1, y1);
13382 }
13383
13384 squarify.ratio = function(x) {
13385 return custom((x = +x) > 1 ? x : 1);
13386 };
13387
13388 return squarify;
13389})(phi);
13390
13391function index() {
13392 var tile = squarify,
13393 round = false,
13394 dx = 1,
13395 dy = 1,
13396 paddingStack = [0],
13397 paddingInner = constantZero,
13398 paddingTop = constantZero,
13399 paddingRight = constantZero,
13400 paddingBottom = constantZero,
13401 paddingLeft = constantZero;
13402
13403 function treemap(root) {
13404 root.x0 =
13405 root.y0 = 0;
13406 root.x1 = dx;
13407 root.y1 = dy;
13408 root.eachBefore(positionNode);
13409 paddingStack = [0];
13410 if (round) root.eachBefore(roundNode);
13411 return root;
13412 }
13413
13414 function positionNode(node) {
13415 var p = paddingStack[node.depth],
13416 x0 = node.x0 + p,
13417 y0 = node.y0 + p,
13418 x1 = node.x1 - p,
13419 y1 = node.y1 - p;
13420 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
13421 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
13422 node.x0 = x0;
13423 node.y0 = y0;
13424 node.x1 = x1;
13425 node.y1 = y1;
13426 if (node.children) {
13427 p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
13428 x0 += paddingLeft(node) - p;
13429 y0 += paddingTop(node) - p;
13430 x1 -= paddingRight(node) - p;
13431 y1 -= paddingBottom(node) - p;
13432 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
13433 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
13434 tile(node, x0, y0, x1, y1);
13435 }
13436 }
13437
13438 treemap.round = function(x) {
13439 return arguments.length ? (round = !!x, treemap) : round;
13440 };
13441
13442 treemap.size = function(x) {
13443 return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
13444 };
13445
13446 treemap.tile = function(x) {
13447 return arguments.length ? (tile = required(x), treemap) : tile;
13448 };
13449
13450 treemap.padding = function(x) {
13451 return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
13452 };
13453
13454 treemap.paddingInner = function(x) {
13455 return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$2(+x), treemap) : paddingInner;
13456 };
13457
13458 treemap.paddingOuter = function(x) {
13459 return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
13460 };
13461
13462 treemap.paddingTop = function(x) {
13463 return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$2(+x), treemap) : paddingTop;
13464 };
13465
13466 treemap.paddingRight = function(x) {
13467 return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$2(+x), treemap) : paddingRight;
13468 };
13469
13470 treemap.paddingBottom = function(x) {
13471 return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$2(+x), treemap) : paddingBottom;
13472 };
13473
13474 treemap.paddingLeft = function(x) {
13475 return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$2(+x), treemap) : paddingLeft;
13476 };
13477
13478 return treemap;
13479}
13480
13481function binary(parent, x0, y0, x1, y1) {
13482 var nodes = parent.children,
13483 i, n = nodes.length,
13484 sum, sums = new Array(n + 1);
13485
13486 for (sums[0] = sum = i = 0; i < n; ++i) {
13487 sums[i + 1] = sum += nodes[i].value;
13488 }
13489
13490 partition(0, n, parent.value, x0, y0, x1, y1);
13491
13492 function partition(i, j, value, x0, y0, x1, y1) {
13493 if (i >= j - 1) {
13494 var node = nodes[i];
13495 node.x0 = x0, node.y0 = y0;
13496 node.x1 = x1, node.y1 = y1;
13497 return;
13498 }
13499
13500 var valueOffset = sums[i],
13501 valueTarget = (value / 2) + valueOffset,
13502 k = i + 1,
13503 hi = j - 1;
13504
13505 while (k < hi) {
13506 var mid = k + hi >>> 1;
13507 if (sums[mid] < valueTarget) k = mid + 1;
13508 else hi = mid;
13509 }
13510
13511 if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
13512
13513 var valueLeft = sums[k] - valueOffset,
13514 valueRight = value - valueLeft;
13515
13516 if ((x1 - x0) > (y1 - y0)) {
13517 var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
13518 partition(i, k, valueLeft, x0, y0, xk, y1);
13519 partition(k, j, valueRight, xk, y0, x1, y1);
13520 } else {
13521 var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
13522 partition(i, k, valueLeft, x0, y0, x1, yk);
13523 partition(k, j, valueRight, x0, yk, x1, y1);
13524 }
13525 }
13526}
13527
13528function sliceDice(parent, x0, y0, x1, y1) {
13529 (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
13530}
13531
13532var resquarify = (function custom(ratio) {
13533
13534 function resquarify(parent, x0, y0, x1, y1) {
13535 if ((rows = parent._squarify) && (rows.ratio === ratio)) {
13536 var rows,
13537 row,
13538 nodes,
13539 i,
13540 j = -1,
13541 n,
13542 m = rows.length,
13543 value = parent.value;
13544
13545 while (++j < m) {
13546 row = rows[j], nodes = row.children;
13547 for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
13548 if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1);
13549 else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1);
13550 value -= row.value;
13551 }
13552 } else {
13553 parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
13554 rows.ratio = ratio;
13555 }
13556 }
13557
13558 resquarify.ratio = function(x) {
13559 return custom((x = +x) > 1 ? x : 1);
13560 };
13561
13562 return resquarify;
13563})(phi);
13564
13565function area$1(polygon) {
13566 var i = -1,
13567 n = polygon.length,
13568 a,
13569 b = polygon[n - 1],
13570 area = 0;
13571
13572 while (++i < n) {
13573 a = b;
13574 b = polygon[i];
13575 area += a[1] * b[0] - a[0] * b[1];
13576 }
13577
13578 return area / 2;
13579}
13580
13581function centroid(polygon) {
13582 var i = -1,
13583 n = polygon.length,
13584 x = 0,
13585 y = 0,
13586 a,
13587 b = polygon[n - 1],
13588 c,
13589 k = 0;
13590
13591 while (++i < n) {
13592 a = b;
13593 b = polygon[i];
13594 k += c = a[0] * b[1] - b[0] * a[1];
13595 x += (a[0] + b[0]) * c;
13596 y += (a[1] + b[1]) * c;
13597 }
13598
13599 return k *= 3, [x / k, y / k];
13600}
13601
13602// Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
13603// the 3D cross product in a quadrant I Cartesian coordinate system (+x is
13604// right, +y is up). Returns a positive value if ABC is counter-clockwise,
13605// negative if clockwise, and zero if the points are collinear.
13606function cross$1(a, b, c) {
13607 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
13608}
13609
13610function lexicographicOrder(a, b) {
13611 return a[0] - b[0] || a[1] - b[1];
13612}
13613
13614// Computes the upper convex hull per the monotone chain algorithm.
13615// Assumes points.length >= 3, is sorted by x, unique in y.
13616// Returns an array of indices into points in left-to-right order.
13617function computeUpperHullIndexes(points) {
13618 const n = points.length,
13619 indexes = [0, 1];
13620 let size = 2, i;
13621
13622 for (i = 2; i < n; ++i) {
13623 while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
13624 indexes[size++] = i;
13625 }
13626
13627 return indexes.slice(0, size); // remove popped points
13628}
13629
13630function hull(points) {
13631 if ((n = points.length) < 3) return null;
13632
13633 var i,
13634 n,
13635 sortedPoints = new Array(n),
13636 flippedPoints = new Array(n);
13637
13638 for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
13639 sortedPoints.sort(lexicographicOrder);
13640 for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
13641
13642 var upperIndexes = computeUpperHullIndexes(sortedPoints),
13643 lowerIndexes = computeUpperHullIndexes(flippedPoints);
13644
13645 // Construct the hull polygon, removing possible duplicate endpoints.
13646 var skipLeft = lowerIndexes[0] === upperIndexes[0],
13647 skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
13648 hull = [];
13649
13650 // Add upper hull in right-to-l order.
13651 // Then add lower hull in left-to-right order.
13652 for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
13653 for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
13654
13655 return hull;
13656}
13657
13658function contains(polygon, point) {
13659 var n = polygon.length,
13660 p = polygon[n - 1],
13661 x = point[0], y = point[1],
13662 x0 = p[0], y0 = p[1],
13663 x1, y1,
13664 inside = false;
13665
13666 for (var i = 0; i < n; ++i) {
13667 p = polygon[i], x1 = p[0], y1 = p[1];
13668 if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
13669 x0 = x1, y0 = y1;
13670 }
13671
13672 return inside;
13673}
13674
13675function length(polygon) {
13676 var i = -1,
13677 n = polygon.length,
13678 b = polygon[n - 1],
13679 xa,
13680 ya,
13681 xb = b[0],
13682 yb = b[1],
13683 perimeter = 0;
13684
13685 while (++i < n) {
13686 xa = xb;
13687 ya = yb;
13688 b = polygon[i];
13689 xb = b[0];
13690 yb = b[1];
13691 xa -= xb;
13692 ya -= yb;
13693 perimeter += Math.hypot(xa, ya);
13694 }
13695
13696 return perimeter;
13697}
13698
13699var defaultSource = Math.random;
13700
13701var uniform = (function sourceRandomUniform(source) {
13702 function randomUniform(min, max) {
13703 min = min == null ? 0 : +min;
13704 max = max == null ? 1 : +max;
13705 if (arguments.length === 1) max = min, min = 0;
13706 else max -= min;
13707 return function() {
13708 return source() * max + min;
13709 };
13710 }
13711
13712 randomUniform.source = sourceRandomUniform;
13713
13714 return randomUniform;
13715})(defaultSource);
13716
13717var int = (function sourceRandomInt(source) {
13718 function randomInt(min, max) {
13719 if (arguments.length < 2) max = min, min = 0;
13720 min = Math.floor(min);
13721 max = Math.floor(max) - min;
13722 return function() {
13723 return Math.floor(source() * max + min);
13724 };
13725 }
13726
13727 randomInt.source = sourceRandomInt;
13728
13729 return randomInt;
13730})(defaultSource);
13731
13732var normal = (function sourceRandomNormal(source) {
13733 function randomNormal(mu, sigma) {
13734 var x, r;
13735 mu = mu == null ? 0 : +mu;
13736 sigma = sigma == null ? 1 : +sigma;
13737 return function() {
13738 var y;
13739
13740 // If available, use the second previously-generated uniform random.
13741 if (x != null) y = x, x = null;
13742
13743 // Otherwise, generate a new x and y.
13744 else do {
13745 x = source() * 2 - 1;
13746 y = source() * 2 - 1;
13747 r = x * x + y * y;
13748 } while (!r || r > 1);
13749
13750 return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
13751 };
13752 }
13753
13754 randomNormal.source = sourceRandomNormal;
13755
13756 return randomNormal;
13757})(defaultSource);
13758
13759var logNormal = (function sourceRandomLogNormal(source) {
13760 var N = normal.source(source);
13761
13762 function randomLogNormal() {
13763 var randomNormal = N.apply(this, arguments);
13764 return function() {
13765 return Math.exp(randomNormal());
13766 };
13767 }
13768
13769 randomLogNormal.source = sourceRandomLogNormal;
13770
13771 return randomLogNormal;
13772})(defaultSource);
13773
13774var irwinHall = (function sourceRandomIrwinHall(source) {
13775 function randomIrwinHall(n) {
13776 if ((n = +n) <= 0) return () => 0;
13777 return function() {
13778 for (var sum = 0, i = n; i > 1; --i) sum += source();
13779 return sum + i * source();
13780 };
13781 }
13782
13783 randomIrwinHall.source = sourceRandomIrwinHall;
13784
13785 return randomIrwinHall;
13786})(defaultSource);
13787
13788var bates = (function sourceRandomBates(source) {
13789 var I = irwinHall.source(source);
13790
13791 function randomBates(n) {
13792 // use limiting distribution at n === 0
13793 if ((n = +n) === 0) return source;
13794 var randomIrwinHall = I(n);
13795 return function() {
13796 return randomIrwinHall() / n;
13797 };
13798 }
13799
13800 randomBates.source = sourceRandomBates;
13801
13802 return randomBates;
13803})(defaultSource);
13804
13805var exponential = (function sourceRandomExponential(source) {
13806 function randomExponential(lambda) {
13807 return function() {
13808 return -Math.log1p(-source()) / lambda;
13809 };
13810 }
13811
13812 randomExponential.source = sourceRandomExponential;
13813
13814 return randomExponential;
13815})(defaultSource);
13816
13817var pareto = (function sourceRandomPareto(source) {
13818 function randomPareto(alpha) {
13819 if ((alpha = +alpha) < 0) throw new RangeError("invalid alpha");
13820 alpha = 1 / -alpha;
13821 return function() {
13822 return Math.pow(1 - source(), alpha);
13823 };
13824 }
13825
13826 randomPareto.source = sourceRandomPareto;
13827
13828 return randomPareto;
13829})(defaultSource);
13830
13831var bernoulli = (function sourceRandomBernoulli(source) {
13832 function randomBernoulli(p) {
13833 if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
13834 return function() {
13835 return Math.floor(source() + p);
13836 };
13837 }
13838
13839 randomBernoulli.source = sourceRandomBernoulli;
13840
13841 return randomBernoulli;
13842})(defaultSource);
13843
13844var geometric = (function sourceRandomGeometric(source) {
13845 function randomGeometric(p) {
13846 if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
13847 if (p === 0) return () => Infinity;
13848 if (p === 1) return () => 1;
13849 p = Math.log1p(-p);
13850 return function() {
13851 return 1 + Math.floor(Math.log1p(-source()) / p);
13852 };
13853 }
13854
13855 randomGeometric.source = sourceRandomGeometric;
13856
13857 return randomGeometric;
13858})(defaultSource);
13859
13860var gamma = (function sourceRandomGamma(source) {
13861 var randomNormal = normal.source(source)();
13862
13863 function randomGamma(k, theta) {
13864 if ((k = +k) < 0) throw new RangeError("invalid k");
13865 // degenerate distribution if k === 0
13866 if (k === 0) return () => 0;
13867 theta = theta == null ? 1 : +theta;
13868 // exponential distribution if k === 1
13869 if (k === 1) return () => -Math.log1p(-source()) * theta;
13870
13871 var d = (k < 1 ? k + 1 : k) - 1 / 3,
13872 c = 1 / (3 * Math.sqrt(d)),
13873 multiplier = k < 1 ? () => Math.pow(source(), 1 / k) : () => 1;
13874 return function() {
13875 do {
13876 do {
13877 var x = randomNormal(),
13878 v = 1 + c * x;
13879 } while (v <= 0);
13880 v *= v * v;
13881 var u = 1 - source();
13882 } while (u >= 1 - 0.0331 * x * x * x * x && Math.log(u) >= 0.5 * x * x + d * (1 - v + Math.log(v)));
13883 return d * v * multiplier() * theta;
13884 };
13885 }
13886
13887 randomGamma.source = sourceRandomGamma;
13888
13889 return randomGamma;
13890})(defaultSource);
13891
13892var beta = (function sourceRandomBeta(source) {
13893 var G = gamma.source(source);
13894
13895 function randomBeta(alpha, beta) {
13896 var X = G(alpha),
13897 Y = G(beta);
13898 return function() {
13899 var x = X();
13900 return x === 0 ? 0 : x / (x + Y());
13901 };
13902 }
13903
13904 randomBeta.source = sourceRandomBeta;
13905
13906 return randomBeta;
13907})(defaultSource);
13908
13909var binomial = (function sourceRandomBinomial(source) {
13910 var G = geometric.source(source),
13911 B = beta.source(source);
13912
13913 function randomBinomial(n, p) {
13914 n = +n;
13915 if ((p = +p) >= 1) return () => n;
13916 if (p <= 0) return () => 0;
13917 return function() {
13918 var acc = 0, nn = n, pp = p;
13919 while (nn * pp > 16 && nn * (1 - pp) > 16) {
13920 var i = Math.floor((nn + 1) * pp),
13921 y = B(i, nn - i + 1)();
13922 if (y <= pp) {
13923 acc += i;
13924 nn -= i;
13925 pp = (pp - y) / (1 - y);
13926 } else {
13927 nn = i - 1;
13928 pp /= y;
13929 }
13930 }
13931 var sign = pp < 0.5,
13932 pFinal = sign ? pp : 1 - pp,
13933 g = G(pFinal);
13934 for (var s = g(), k = 0; s <= nn; ++k) s += g();
13935 return acc + (sign ? k : nn - k);
13936 };
13937 }
13938
13939 randomBinomial.source = sourceRandomBinomial;
13940
13941 return randomBinomial;
13942})(defaultSource);
13943
13944var weibull = (function sourceRandomWeibull(source) {
13945 function randomWeibull(k, a, b) {
13946 var outerFunc;
13947 if ((k = +k) === 0) {
13948 outerFunc = x => -Math.log(x);
13949 } else {
13950 k = 1 / k;
13951 outerFunc = x => Math.pow(x, k);
13952 }
13953 a = a == null ? 0 : +a;
13954 b = b == null ? 1 : +b;
13955 return function() {
13956 return a + b * outerFunc(-Math.log1p(-source()));
13957 };
13958 }
13959
13960 randomWeibull.source = sourceRandomWeibull;
13961
13962 return randomWeibull;
13963})(defaultSource);
13964
13965var cauchy = (function sourceRandomCauchy(source) {
13966 function randomCauchy(a, b) {
13967 a = a == null ? 0 : +a;
13968 b = b == null ? 1 : +b;
13969 return function() {
13970 return a + b * Math.tan(Math.PI * source());
13971 };
13972 }
13973
13974 randomCauchy.source = sourceRandomCauchy;
13975
13976 return randomCauchy;
13977})(defaultSource);
13978
13979var logistic = (function sourceRandomLogistic(source) {
13980 function randomLogistic(a, b) {
13981 a = a == null ? 0 : +a;
13982 b = b == null ? 1 : +b;
13983 return function() {
13984 var u = source();
13985 return a + b * Math.log(u / (1 - u));
13986 };
13987 }
13988
13989 randomLogistic.source = sourceRandomLogistic;
13990
13991 return randomLogistic;
13992})(defaultSource);
13993
13994var poisson = (function sourceRandomPoisson(source) {
13995 var G = gamma.source(source),
13996 B = binomial.source(source);
13997
13998 function randomPoisson(lambda) {
13999 return function() {
14000 var acc = 0, l = lambda;
14001 while (l > 16) {
14002 var n = Math.floor(0.875 * l),
14003 t = G(n)();
14004 if (t > l) return acc + B(n - 1, l / t)();
14005 acc += n;
14006 l -= t;
14007 }
14008 for (var s = -Math.log1p(-source()), k = 0; s <= l; ++k) s -= Math.log1p(-source());
14009 return acc + k;
14010 };
14011 }
14012
14013 randomPoisson.source = sourceRandomPoisson;
14014
14015 return randomPoisson;
14016})(defaultSource);
14017
14018// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
14019const mul = 0x19660D;
14020const inc = 0x3C6EF35F;
14021const eps = 1 / 0x100000000;
14022
14023function lcg(seed = Math.random()) {
14024 let state = (0 <= seed && seed < 1 ? seed / eps : Math.abs(seed)) | 0;
14025 return () => (state = mul * state + inc | 0, eps * (state >>> 0));
14026}
14027
14028function initRange(domain, range) {
14029 switch (arguments.length) {
14030 case 0: break;
14031 case 1: this.range(domain); break;
14032 default: this.range(range).domain(domain); break;
14033 }
14034 return this;
14035}
14036
14037function initInterpolator(domain, interpolator) {
14038 switch (arguments.length) {
14039 case 0: break;
14040 case 1: {
14041 if (typeof domain === "function") this.interpolator(domain);
14042 else this.range(domain);
14043 break;
14044 }
14045 default: {
14046 this.domain(domain);
14047 if (typeof interpolator === "function") this.interpolator(interpolator);
14048 else this.range(interpolator);
14049 break;
14050 }
14051 }
14052 return this;
14053}
14054
14055const implicit = Symbol("implicit");
14056
14057function ordinal() {
14058 var index = new Map(),
14059 domain = [],
14060 range = [],
14061 unknown = implicit;
14062
14063 function scale(d) {
14064 var key = d + "", i = index.get(key);
14065 if (!i) {
14066 if (unknown !== implicit) return unknown;
14067 index.set(key, i = domain.push(d));
14068 }
14069 return range[(i - 1) % range.length];
14070 }
14071
14072 scale.domain = function(_) {
14073 if (!arguments.length) return domain.slice();
14074 domain = [], index = new Map();
14075 for (const value of _) {
14076 const key = value + "";
14077 if (index.has(key)) continue;
14078 index.set(key, domain.push(value));
14079 }
14080 return scale;
14081 };
14082
14083 scale.range = function(_) {
14084 return arguments.length ? (range = Array.from(_), scale) : range.slice();
14085 };
14086
14087 scale.unknown = function(_) {
14088 return arguments.length ? (unknown = _, scale) : unknown;
14089 };
14090
14091 scale.copy = function() {
14092 return ordinal(domain, range).unknown(unknown);
14093 };
14094
14095 initRange.apply(scale, arguments);
14096
14097 return scale;
14098}
14099
14100function band() {
14101 var scale = ordinal().unknown(undefined),
14102 domain = scale.domain,
14103 ordinalRange = scale.range,
14104 r0 = 0,
14105 r1 = 1,
14106 step,
14107 bandwidth,
14108 round = false,
14109 paddingInner = 0,
14110 paddingOuter = 0,
14111 align = 0.5;
14112
14113 delete scale.unknown;
14114
14115 function rescale() {
14116 var n = domain().length,
14117 reverse = r1 < r0,
14118 start = reverse ? r1 : r0,
14119 stop = reverse ? r0 : r1;
14120 step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
14121 if (round) step = Math.floor(step);
14122 start += (stop - start - step * (n - paddingInner)) * align;
14123 bandwidth = step * (1 - paddingInner);
14124 if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
14125 var values = sequence(n).map(function(i) { return start + step * i; });
14126 return ordinalRange(reverse ? values.reverse() : values);
14127 }
14128
14129 scale.domain = function(_) {
14130 return arguments.length ? (domain(_), rescale()) : domain();
14131 };
14132
14133 scale.range = function(_) {
14134 return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
14135 };
14136
14137 scale.rangeRound = function(_) {
14138 return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
14139 };
14140
14141 scale.bandwidth = function() {
14142 return bandwidth;
14143 };
14144
14145 scale.step = function() {
14146 return step;
14147 };
14148
14149 scale.round = function(_) {
14150 return arguments.length ? (round = !!_, rescale()) : round;
14151 };
14152
14153 scale.padding = function(_) {
14154 return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
14155 };
14156
14157 scale.paddingInner = function(_) {
14158 return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
14159 };
14160
14161 scale.paddingOuter = function(_) {
14162 return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
14163 };
14164
14165 scale.align = function(_) {
14166 return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
14167 };
14168
14169 scale.copy = function() {
14170 return band(domain(), [r0, r1])
14171 .round(round)
14172 .paddingInner(paddingInner)
14173 .paddingOuter(paddingOuter)
14174 .align(align);
14175 };
14176
14177 return initRange.apply(rescale(), arguments);
14178}
14179
14180function pointish(scale) {
14181 var copy = scale.copy;
14182
14183 scale.padding = scale.paddingOuter;
14184 delete scale.paddingInner;
14185 delete scale.paddingOuter;
14186
14187 scale.copy = function() {
14188 return pointish(copy());
14189 };
14190
14191 return scale;
14192}
14193
14194function point$4() {
14195 return pointish(band.apply(null, arguments).paddingInner(1));
14196}
14197
14198function constants(x) {
14199 return function() {
14200 return x;
14201 };
14202}
14203
14204function number$1(x) {
14205 return +x;
14206}
14207
14208var unit = [0, 1];
14209
14210function identity$3(x) {
14211 return x;
14212}
14213
14214function normalize(a, b) {
14215 return (b -= (a = +a))
14216 ? function(x) { return (x - a) / b; }
14217 : constants(isNaN(b) ? NaN : 0.5);
14218}
14219
14220function clamper(a, b) {
14221 var t;
14222 if (a > b) t = a, a = b, b = t;
14223 return function(x) { return Math.max(a, Math.min(b, x)); };
14224}
14225
14226// normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
14227// interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
14228function bimap(domain, range, interpolate) {
14229 var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
14230 if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
14231 else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
14232 return function(x) { return r0(d0(x)); };
14233}
14234
14235function polymap(domain, range, interpolate) {
14236 var j = Math.min(domain.length, range.length) - 1,
14237 d = new Array(j),
14238 r = new Array(j),
14239 i = -1;
14240
14241 // Reverse descending domains.
14242 if (domain[j] < domain[0]) {
14243 domain = domain.slice().reverse();
14244 range = range.slice().reverse();
14245 }
14246
14247 while (++i < j) {
14248 d[i] = normalize(domain[i], domain[i + 1]);
14249 r[i] = interpolate(range[i], range[i + 1]);
14250 }
14251
14252 return function(x) {
14253 var i = bisectRight(domain, x, 1, j) - 1;
14254 return r[i](d[i](x));
14255 };
14256}
14257
14258function copy$1(source, target) {
14259 return target
14260 .domain(source.domain())
14261 .range(source.range())
14262 .interpolate(source.interpolate())
14263 .clamp(source.clamp())
14264 .unknown(source.unknown());
14265}
14266
14267function transformer$2() {
14268 var domain = unit,
14269 range = unit,
14270 interpolate = interpolate$2,
14271 transform,
14272 untransform,
14273 unknown,
14274 clamp = identity$3,
14275 piecewise,
14276 output,
14277 input;
14278
14279 function rescale() {
14280 var n = Math.min(domain.length, range.length);
14281 if (clamp !== identity$3) clamp = clamper(domain[0], domain[n - 1]);
14282 piecewise = n > 2 ? polymap : bimap;
14283 output = input = null;
14284 return scale;
14285 }
14286
14287 function scale(x) {
14288 return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
14289 }
14290
14291 scale.invert = function(y) {
14292 return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
14293 };
14294
14295 scale.domain = function(_) {
14296 return arguments.length ? (domain = Array.from(_, number$1), rescale()) : domain.slice();
14297 };
14298
14299 scale.range = function(_) {
14300 return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
14301 };
14302
14303 scale.rangeRound = function(_) {
14304 return range = Array.from(_), interpolate = interpolateRound, rescale();
14305 };
14306
14307 scale.clamp = function(_) {
14308 return arguments.length ? (clamp = _ ? true : identity$3, rescale()) : clamp !== identity$3;
14309 };
14310
14311 scale.interpolate = function(_) {
14312 return arguments.length ? (interpolate = _, rescale()) : interpolate;
14313 };
14314
14315 scale.unknown = function(_) {
14316 return arguments.length ? (unknown = _, scale) : unknown;
14317 };
14318
14319 return function(t, u) {
14320 transform = t, untransform = u;
14321 return rescale();
14322 };
14323}
14324
14325function continuous() {
14326 return transformer$2()(identity$3, identity$3);
14327}
14328
14329function tickFormat(start, stop, count, specifier) {
14330 var step = tickStep(start, stop, count),
14331 precision;
14332 specifier = formatSpecifier(specifier == null ? ",f" : specifier);
14333 switch (specifier.type) {
14334 case "s": {
14335 var value = Math.max(Math.abs(start), Math.abs(stop));
14336 if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
14337 return exports.formatPrefix(specifier, value);
14338 }
14339 case "":
14340 case "e":
14341 case "g":
14342 case "p":
14343 case "r": {
14344 if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
14345 break;
14346 }
14347 case "f":
14348 case "%": {
14349 if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
14350 break;
14351 }
14352 }
14353 return exports.format(specifier);
14354}
14355
14356function linearish(scale) {
14357 var domain = scale.domain;
14358
14359 scale.ticks = function(count) {
14360 var d = domain();
14361 return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
14362 };
14363
14364 scale.tickFormat = function(count, specifier) {
14365 var d = domain();
14366 return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
14367 };
14368
14369 scale.nice = function(count) {
14370 if (count == null) count = 10;
14371
14372 var d = domain();
14373 var i0 = 0;
14374 var i1 = d.length - 1;
14375 var start = d[i0];
14376 var stop = d[i1];
14377 var prestep;
14378 var step;
14379 var maxIter = 10;
14380
14381 if (stop < start) {
14382 step = start, start = stop, stop = step;
14383 step = i0, i0 = i1, i1 = step;
14384 }
14385
14386 while (maxIter-- > 0) {
14387 step = tickIncrement(start, stop, count);
14388 if (step === prestep) {
14389 d[i0] = start;
14390 d[i1] = stop;
14391 return domain(d);
14392 } else if (step > 0) {
14393 start = Math.floor(start / step) * step;
14394 stop = Math.ceil(stop / step) * step;
14395 } else if (step < 0) {
14396 start = Math.ceil(start * step) / step;
14397 stop = Math.floor(stop * step) / step;
14398 } else {
14399 break;
14400 }
14401 prestep = step;
14402 }
14403
14404 return scale;
14405 };
14406
14407 return scale;
14408}
14409
14410function linear() {
14411 var scale = continuous();
14412
14413 scale.copy = function() {
14414 return copy$1(scale, linear());
14415 };
14416
14417 initRange.apply(scale, arguments);
14418
14419 return linearish(scale);
14420}
14421
14422function identity$2(domain) {
14423 var unknown;
14424
14425 function scale(x) {
14426 return x == null || isNaN(x = +x) ? unknown : x;
14427 }
14428
14429 scale.invert = scale;
14430
14431 scale.domain = scale.range = function(_) {
14432 return arguments.length ? (domain = Array.from(_, number$1), scale) : domain.slice();
14433 };
14434
14435 scale.unknown = function(_) {
14436 return arguments.length ? (unknown = _, scale) : unknown;
14437 };
14438
14439 scale.copy = function() {
14440 return identity$2(domain).unknown(unknown);
14441 };
14442
14443 domain = arguments.length ? Array.from(domain, number$1) : [0, 1];
14444
14445 return linearish(scale);
14446}
14447
14448function nice(domain, interval) {
14449 domain = domain.slice();
14450
14451 var i0 = 0,
14452 i1 = domain.length - 1,
14453 x0 = domain[i0],
14454 x1 = domain[i1],
14455 t;
14456
14457 if (x1 < x0) {
14458 t = i0, i0 = i1, i1 = t;
14459 t = x0, x0 = x1, x1 = t;
14460 }
14461
14462 domain[i0] = interval.floor(x0);
14463 domain[i1] = interval.ceil(x1);
14464 return domain;
14465}
14466
14467function transformLog(x) {
14468 return Math.log(x);
14469}
14470
14471function transformExp(x) {
14472 return Math.exp(x);
14473}
14474
14475function transformLogn(x) {
14476 return -Math.log(-x);
14477}
14478
14479function transformExpn(x) {
14480 return -Math.exp(-x);
14481}
14482
14483function pow10(x) {
14484 return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
14485}
14486
14487function powp(base) {
14488 return base === 10 ? pow10
14489 : base === Math.E ? Math.exp
14490 : function(x) { return Math.pow(base, x); };
14491}
14492
14493function logp(base) {
14494 return base === Math.E ? Math.log
14495 : base === 10 && Math.log10
14496 || base === 2 && Math.log2
14497 || (base = Math.log(base), function(x) { return Math.log(x) / base; });
14498}
14499
14500function reflect(f) {
14501 return function(x) {
14502 return -f(-x);
14503 };
14504}
14505
14506function loggish(transform) {
14507 var scale = transform(transformLog, transformExp),
14508 domain = scale.domain,
14509 base = 10,
14510 logs,
14511 pows;
14512
14513 function rescale() {
14514 logs = logp(base), pows = powp(base);
14515 if (domain()[0] < 0) {
14516 logs = reflect(logs), pows = reflect(pows);
14517 transform(transformLogn, transformExpn);
14518 } else {
14519 transform(transformLog, transformExp);
14520 }
14521 return scale;
14522 }
14523
14524 scale.base = function(_) {
14525 return arguments.length ? (base = +_, rescale()) : base;
14526 };
14527
14528 scale.domain = function(_) {
14529 return arguments.length ? (domain(_), rescale()) : domain();
14530 };
14531
14532 scale.ticks = function(count) {
14533 var d = domain(),
14534 u = d[0],
14535 v = d[d.length - 1],
14536 r;
14537
14538 if (r = v < u) i = u, u = v, v = i;
14539
14540 var i = logs(u),
14541 j = logs(v),
14542 p,
14543 k,
14544 t,
14545 n = count == null ? 10 : +count,
14546 z = [];
14547
14548 if (!(base % 1) && j - i < n) {
14549 i = Math.floor(i), j = Math.ceil(j);
14550 if (u > 0) for (; i <= j; ++i) {
14551 for (k = 1, p = pows(i); k < base; ++k) {
14552 t = p * k;
14553 if (t < u) continue;
14554 if (t > v) break;
14555 z.push(t);
14556 }
14557 } else for (; i <= j; ++i) {
14558 for (k = base - 1, p = pows(i); k >= 1; --k) {
14559 t = p * k;
14560 if (t < u) continue;
14561 if (t > v) break;
14562 z.push(t);
14563 }
14564 }
14565 if (z.length * 2 < n) z = ticks(u, v, n);
14566 } else {
14567 z = ticks(i, j, Math.min(j - i, n)).map(pows);
14568 }
14569
14570 return r ? z.reverse() : z;
14571 };
14572
14573 scale.tickFormat = function(count, specifier) {
14574 if (specifier == null) specifier = base === 10 ? ".0e" : ",";
14575 if (typeof specifier !== "function") specifier = exports.format(specifier);
14576 if (count === Infinity) return specifier;
14577 if (count == null) count = 10;
14578 var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
14579 return function(d) {
14580 var i = d / pows(Math.round(logs(d)));
14581 if (i * base < base - 0.5) i *= base;
14582 return i <= k ? specifier(d) : "";
14583 };
14584 };
14585
14586 scale.nice = function() {
14587 return domain(nice(domain(), {
14588 floor: function(x) { return pows(Math.floor(logs(x))); },
14589 ceil: function(x) { return pows(Math.ceil(logs(x))); }
14590 }));
14591 };
14592
14593 return scale;
14594}
14595
14596function log() {
14597 var scale = loggish(transformer$2()).domain([1, 10]);
14598
14599 scale.copy = function() {
14600 return copy$1(scale, log()).base(scale.base());
14601 };
14602
14603 initRange.apply(scale, arguments);
14604
14605 return scale;
14606}
14607
14608function transformSymlog(c) {
14609 return function(x) {
14610 return Math.sign(x) * Math.log1p(Math.abs(x / c));
14611 };
14612}
14613
14614function transformSymexp(c) {
14615 return function(x) {
14616 return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
14617 };
14618}
14619
14620function symlogish(transform) {
14621 var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
14622
14623 scale.constant = function(_) {
14624 return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
14625 };
14626
14627 return linearish(scale);
14628}
14629
14630function symlog() {
14631 var scale = symlogish(transformer$2());
14632
14633 scale.copy = function() {
14634 return copy$1(scale, symlog()).constant(scale.constant());
14635 };
14636
14637 return initRange.apply(scale, arguments);
14638}
14639
14640function transformPow(exponent) {
14641 return function(x) {
14642 return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
14643 };
14644}
14645
14646function transformSqrt(x) {
14647 return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
14648}
14649
14650function transformSquare(x) {
14651 return x < 0 ? -x * x : x * x;
14652}
14653
14654function powish(transform) {
14655 var scale = transform(identity$3, identity$3),
14656 exponent = 1;
14657
14658 function rescale() {
14659 return exponent === 1 ? transform(identity$3, identity$3)
14660 : exponent === 0.5 ? transform(transformSqrt, transformSquare)
14661 : transform(transformPow(exponent), transformPow(1 / exponent));
14662 }
14663
14664 scale.exponent = function(_) {
14665 return arguments.length ? (exponent = +_, rescale()) : exponent;
14666 };
14667
14668 return linearish(scale);
14669}
14670
14671function pow() {
14672 var scale = powish(transformer$2());
14673
14674 scale.copy = function() {
14675 return copy$1(scale, pow()).exponent(scale.exponent());
14676 };
14677
14678 initRange.apply(scale, arguments);
14679
14680 return scale;
14681}
14682
14683function sqrt$1() {
14684 return pow.apply(null, arguments).exponent(0.5);
14685}
14686
14687function square$1(x) {
14688 return Math.sign(x) * x * x;
14689}
14690
14691function unsquare(x) {
14692 return Math.sign(x) * Math.sqrt(Math.abs(x));
14693}
14694
14695function radial() {
14696 var squared = continuous(),
14697 range = [0, 1],
14698 round = false,
14699 unknown;
14700
14701 function scale(x) {
14702 var y = unsquare(squared(x));
14703 return isNaN(y) ? unknown : round ? Math.round(y) : y;
14704 }
14705
14706 scale.invert = function(y) {
14707 return squared.invert(square$1(y));
14708 };
14709
14710 scale.domain = function(_) {
14711 return arguments.length ? (squared.domain(_), scale) : squared.domain();
14712 };
14713
14714 scale.range = function(_) {
14715 return arguments.length ? (squared.range((range = Array.from(_, number$1)).map(square$1)), scale) : range.slice();
14716 };
14717
14718 scale.rangeRound = function(_) {
14719 return scale.range(_).round(true);
14720 };
14721
14722 scale.round = function(_) {
14723 return arguments.length ? (round = !!_, scale) : round;
14724 };
14725
14726 scale.clamp = function(_) {
14727 return arguments.length ? (squared.clamp(_), scale) : squared.clamp();
14728 };
14729
14730 scale.unknown = function(_) {
14731 return arguments.length ? (unknown = _, scale) : unknown;
14732 };
14733
14734 scale.copy = function() {
14735 return radial(squared.domain(), range)
14736 .round(round)
14737 .clamp(squared.clamp())
14738 .unknown(unknown);
14739 };
14740
14741 initRange.apply(scale, arguments);
14742
14743 return linearish(scale);
14744}
14745
14746function quantile() {
14747 var domain = [],
14748 range = [],
14749 thresholds = [],
14750 unknown;
14751
14752 function rescale() {
14753 var i = 0, n = Math.max(1, range.length);
14754 thresholds = new Array(n - 1);
14755 while (++i < n) thresholds[i - 1] = quantileSorted(domain, i / n);
14756 return scale;
14757 }
14758
14759 function scale(x) {
14760 return x == null || isNaN(x = +x) ? unknown : range[bisectRight(thresholds, x)];
14761 }
14762
14763 scale.invertExtent = function(y) {
14764 var i = range.indexOf(y);
14765 return i < 0 ? [NaN, NaN] : [
14766 i > 0 ? thresholds[i - 1] : domain[0],
14767 i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
14768 ];
14769 };
14770
14771 scale.domain = function(_) {
14772 if (!arguments.length) return domain.slice();
14773 domain = [];
14774 for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
14775 domain.sort(ascending$3);
14776 return rescale();
14777 };
14778
14779 scale.range = function(_) {
14780 return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
14781 };
14782
14783 scale.unknown = function(_) {
14784 return arguments.length ? (unknown = _, scale) : unknown;
14785 };
14786
14787 scale.quantiles = function() {
14788 return thresholds.slice();
14789 };
14790
14791 scale.copy = function() {
14792 return quantile()
14793 .domain(domain)
14794 .range(range)
14795 .unknown(unknown);
14796 };
14797
14798 return initRange.apply(scale, arguments);
14799}
14800
14801function quantize() {
14802 var x0 = 0,
14803 x1 = 1,
14804 n = 1,
14805 domain = [0.5],
14806 range = [0, 1],
14807 unknown;
14808
14809 function scale(x) {
14810 return x != null && x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
14811 }
14812
14813 function rescale() {
14814 var i = -1;
14815 domain = new Array(n);
14816 while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
14817 return scale;
14818 }
14819
14820 scale.domain = function(_) {
14821 return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
14822 };
14823
14824 scale.range = function(_) {
14825 return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
14826 };
14827
14828 scale.invertExtent = function(y) {
14829 var i = range.indexOf(y);
14830 return i < 0 ? [NaN, NaN]
14831 : i < 1 ? [x0, domain[0]]
14832 : i >= n ? [domain[n - 1], x1]
14833 : [domain[i - 1], domain[i]];
14834 };
14835
14836 scale.unknown = function(_) {
14837 return arguments.length ? (unknown = _, scale) : scale;
14838 };
14839
14840 scale.thresholds = function() {
14841 return domain.slice();
14842 };
14843
14844 scale.copy = function() {
14845 return quantize()
14846 .domain([x0, x1])
14847 .range(range)
14848 .unknown(unknown);
14849 };
14850
14851 return initRange.apply(linearish(scale), arguments);
14852}
14853
14854function threshold() {
14855 var domain = [0.5],
14856 range = [0, 1],
14857 unknown,
14858 n = 1;
14859
14860 function scale(x) {
14861 return x != null && x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
14862 }
14863
14864 scale.domain = function(_) {
14865 return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
14866 };
14867
14868 scale.range = function(_) {
14869 return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
14870 };
14871
14872 scale.invertExtent = function(y) {
14873 var i = range.indexOf(y);
14874 return [domain[i - 1], domain[i]];
14875 };
14876
14877 scale.unknown = function(_) {
14878 return arguments.length ? (unknown = _, scale) : unknown;
14879 };
14880
14881 scale.copy = function() {
14882 return threshold()
14883 .domain(domain)
14884 .range(range)
14885 .unknown(unknown);
14886 };
14887
14888 return initRange.apply(scale, arguments);
14889}
14890
14891var t0 = new Date,
14892 t1 = new Date;
14893
14894function newInterval(floori, offseti, count, field) {
14895
14896 function interval(date) {
14897 return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
14898 }
14899
14900 interval.floor = function(date) {
14901 return floori(date = new Date(+date)), date;
14902 };
14903
14904 interval.ceil = function(date) {
14905 return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
14906 };
14907
14908 interval.round = function(date) {
14909 var d0 = interval(date),
14910 d1 = interval.ceil(date);
14911 return date - d0 < d1 - date ? d0 : d1;
14912 };
14913
14914 interval.offset = function(date, step) {
14915 return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
14916 };
14917
14918 interval.range = function(start, stop, step) {
14919 var range = [], previous;
14920 start = interval.ceil(start);
14921 step = step == null ? 1 : Math.floor(step);
14922 if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
14923 do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
14924 while (previous < start && start < stop);
14925 return range;
14926 };
14927
14928 interval.filter = function(test) {
14929 return newInterval(function(date) {
14930 if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
14931 }, function(date, step) {
14932 if (date >= date) {
14933 if (step < 0) while (++step <= 0) {
14934 while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
14935 } else while (--step >= 0) {
14936 while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
14937 }
14938 }
14939 });
14940 };
14941
14942 if (count) {
14943 interval.count = function(start, end) {
14944 t0.setTime(+start), t1.setTime(+end);
14945 floori(t0), floori(t1);
14946 return Math.floor(count(t0, t1));
14947 };
14948
14949 interval.every = function(step) {
14950 step = Math.floor(step);
14951 return !isFinite(step) || !(step > 0) ? null
14952 : !(step > 1) ? interval
14953 : interval.filter(field
14954 ? function(d) { return field(d) % step === 0; }
14955 : function(d) { return interval.count(0, d) % step === 0; });
14956 };
14957 }
14958
14959 return interval;
14960}
14961
14962var millisecond = newInterval(function() {
14963 // noop
14964}, function(date, step) {
14965 date.setTime(+date + step);
14966}, function(start, end) {
14967 return end - start;
14968});
14969
14970// An optimized implementation for this simple case.
14971millisecond.every = function(k) {
14972 k = Math.floor(k);
14973 if (!isFinite(k) || !(k > 0)) return null;
14974 if (!(k > 1)) return millisecond;
14975 return newInterval(function(date) {
14976 date.setTime(Math.floor(date / k) * k);
14977 }, function(date, step) {
14978 date.setTime(+date + step * k);
14979 }, function(start, end) {
14980 return (end - start) / k;
14981 });
14982};
14983var milliseconds = millisecond.range;
14984
14985const durationSecond = 1000;
14986const durationMinute = durationSecond * 60;
14987const durationHour = durationMinute * 60;
14988const durationDay = durationHour * 24;
14989const durationWeek = durationDay * 7;
14990const durationMonth = durationDay * 30;
14991const durationYear = durationDay * 365;
14992
14993var second = newInterval(function(date) {
14994 date.setTime(date - date.getMilliseconds());
14995}, function(date, step) {
14996 date.setTime(+date + step * durationSecond);
14997}, function(start, end) {
14998 return (end - start) / durationSecond;
14999}, function(date) {
15000 return date.getUTCSeconds();
15001});
15002var seconds = second.range;
15003
15004var minute = newInterval(function(date) {
15005 date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
15006}, function(date, step) {
15007 date.setTime(+date + step * durationMinute);
15008}, function(start, end) {
15009 return (end - start) / durationMinute;
15010}, function(date) {
15011 return date.getMinutes();
15012});
15013var minutes = minute.range;
15014
15015var hour = newInterval(function(date) {
15016 date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
15017}, function(date, step) {
15018 date.setTime(+date + step * durationHour);
15019}, function(start, end) {
15020 return (end - start) / durationHour;
15021}, function(date) {
15022 return date.getHours();
15023});
15024var hours = hour.range;
15025
15026var day = newInterval(
15027 date => date.setHours(0, 0, 0, 0),
15028 (date, step) => date.setDate(date.getDate() + step),
15029 (start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay,
15030 date => date.getDate() - 1
15031);
15032var days = day.range;
15033
15034function weekday(i) {
15035 return newInterval(function(date) {
15036 date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
15037 date.setHours(0, 0, 0, 0);
15038 }, function(date, step) {
15039 date.setDate(date.getDate() + step * 7);
15040 }, function(start, end) {
15041 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
15042 });
15043}
15044
15045var sunday = weekday(0);
15046var monday = weekday(1);
15047var tuesday = weekday(2);
15048var wednesday = weekday(3);
15049var thursday = weekday(4);
15050var friday = weekday(5);
15051var saturday = weekday(6);
15052
15053var sundays = sunday.range;
15054var mondays = monday.range;
15055var tuesdays = tuesday.range;
15056var wednesdays = wednesday.range;
15057var thursdays = thursday.range;
15058var fridays = friday.range;
15059var saturdays = saturday.range;
15060
15061var month = newInterval(function(date) {
15062 date.setDate(1);
15063 date.setHours(0, 0, 0, 0);
15064}, function(date, step) {
15065 date.setMonth(date.getMonth() + step);
15066}, function(start, end) {
15067 return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
15068}, function(date) {
15069 return date.getMonth();
15070});
15071var months = month.range;
15072
15073var year = newInterval(function(date) {
15074 date.setMonth(0, 1);
15075 date.setHours(0, 0, 0, 0);
15076}, function(date, step) {
15077 date.setFullYear(date.getFullYear() + step);
15078}, function(start, end) {
15079 return end.getFullYear() - start.getFullYear();
15080}, function(date) {
15081 return date.getFullYear();
15082});
15083
15084// An optimized implementation for this simple case.
15085year.every = function(k) {
15086 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
15087 date.setFullYear(Math.floor(date.getFullYear() / k) * k);
15088 date.setMonth(0, 1);
15089 date.setHours(0, 0, 0, 0);
15090 }, function(date, step) {
15091 date.setFullYear(date.getFullYear() + step * k);
15092 });
15093};
15094var years = year.range;
15095
15096var utcMinute = newInterval(function(date) {
15097 date.setUTCSeconds(0, 0);
15098}, function(date, step) {
15099 date.setTime(+date + step * durationMinute);
15100}, function(start, end) {
15101 return (end - start) / durationMinute;
15102}, function(date) {
15103 return date.getUTCMinutes();
15104});
15105var utcMinutes = utcMinute.range;
15106
15107var utcHour = newInterval(function(date) {
15108 date.setUTCMinutes(0, 0, 0);
15109}, function(date, step) {
15110 date.setTime(+date + step * durationHour);
15111}, function(start, end) {
15112 return (end - start) / durationHour;
15113}, function(date) {
15114 return date.getUTCHours();
15115});
15116var utcHours = utcHour.range;
15117
15118var utcDay = newInterval(function(date) {
15119 date.setUTCHours(0, 0, 0, 0);
15120}, function(date, step) {
15121 date.setUTCDate(date.getUTCDate() + step);
15122}, function(start, end) {
15123 return (end - start) / durationDay;
15124}, function(date) {
15125 return date.getUTCDate() - 1;
15126});
15127var utcDays = utcDay.range;
15128
15129function utcWeekday(i) {
15130 return newInterval(function(date) {
15131 date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
15132 date.setUTCHours(0, 0, 0, 0);
15133 }, function(date, step) {
15134 date.setUTCDate(date.getUTCDate() + step * 7);
15135 }, function(start, end) {
15136 return (end - start) / durationWeek;
15137 });
15138}
15139
15140var utcSunday = utcWeekday(0);
15141var utcMonday = utcWeekday(1);
15142var utcTuesday = utcWeekday(2);
15143var utcWednesday = utcWeekday(3);
15144var utcThursday = utcWeekday(4);
15145var utcFriday = utcWeekday(5);
15146var utcSaturday = utcWeekday(6);
15147
15148var utcSundays = utcSunday.range;
15149var utcMondays = utcMonday.range;
15150var utcTuesdays = utcTuesday.range;
15151var utcWednesdays = utcWednesday.range;
15152var utcThursdays = utcThursday.range;
15153var utcFridays = utcFriday.range;
15154var utcSaturdays = utcSaturday.range;
15155
15156var utcMonth = newInterval(function(date) {
15157 date.setUTCDate(1);
15158 date.setUTCHours(0, 0, 0, 0);
15159}, function(date, step) {
15160 date.setUTCMonth(date.getUTCMonth() + step);
15161}, function(start, end) {
15162 return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
15163}, function(date) {
15164 return date.getUTCMonth();
15165});
15166var utcMonths = utcMonth.range;
15167
15168var utcYear = newInterval(function(date) {
15169 date.setUTCMonth(0, 1);
15170 date.setUTCHours(0, 0, 0, 0);
15171}, function(date, step) {
15172 date.setUTCFullYear(date.getUTCFullYear() + step);
15173}, function(start, end) {
15174 return end.getUTCFullYear() - start.getUTCFullYear();
15175}, function(date) {
15176 return date.getUTCFullYear();
15177});
15178
15179// An optimized implementation for this simple case.
15180utcYear.every = function(k) {
15181 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
15182 date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
15183 date.setUTCMonth(0, 1);
15184 date.setUTCHours(0, 0, 0, 0);
15185 }, function(date, step) {
15186 date.setUTCFullYear(date.getUTCFullYear() + step * k);
15187 });
15188};
15189var utcYears = utcYear.range;
15190
15191function ticker(year, month, week, day, hour, minute) {
15192
15193 const tickIntervals = [
15194 [second, 1, durationSecond],
15195 [second, 5, 5 * durationSecond],
15196 [second, 15, 15 * durationSecond],
15197 [second, 30, 30 * durationSecond],
15198 [minute, 1, durationMinute],
15199 [minute, 5, 5 * durationMinute],
15200 [minute, 15, 15 * durationMinute],
15201 [minute, 30, 30 * durationMinute],
15202 [ hour, 1, durationHour ],
15203 [ hour, 3, 3 * durationHour ],
15204 [ hour, 6, 6 * durationHour ],
15205 [ hour, 12, 12 * durationHour ],
15206 [ day, 1, durationDay ],
15207 [ day, 2, 2 * durationDay ],
15208 [ week, 1, durationWeek ],
15209 [ month, 1, durationMonth ],
15210 [ month, 3, 3 * durationMonth ],
15211 [ year, 1, durationYear ]
15212 ];
15213
15214 function ticks(start, stop, count) {
15215 const reverse = stop < start;
15216 if (reverse) [start, stop] = [stop, start];
15217 const interval = count && typeof count.range === "function" ? count : tickInterval(start, stop, count);
15218 const ticks = interval ? interval.range(start, +stop + 1) : []; // inclusive stop
15219 return reverse ? ticks.reverse() : ticks;
15220 }
15221
15222 function tickInterval(start, stop, count) {
15223 const target = Math.abs(stop - start) / count;
15224 const i = bisector(([,, step]) => step).right(tickIntervals, target);
15225 if (i === tickIntervals.length) return year.every(tickStep(start / durationYear, stop / durationYear, count));
15226 if (i === 0) return millisecond.every(Math.max(tickStep(start, stop, count), 1));
15227 const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
15228 return t.every(step);
15229 }
15230
15231 return [ticks, tickInterval];
15232}
15233
15234const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute);
15235const [timeTicks, timeTickInterval] = ticker(year, month, sunday, day, hour, minute);
15236
15237function localDate(d) {
15238 if (0 <= d.y && d.y < 100) {
15239 var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
15240 date.setFullYear(d.y);
15241 return date;
15242 }
15243 return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
15244}
15245
15246function utcDate(d) {
15247 if (0 <= d.y && d.y < 100) {
15248 var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
15249 date.setUTCFullYear(d.y);
15250 return date;
15251 }
15252 return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
15253}
15254
15255function newDate(y, m, d) {
15256 return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
15257}
15258
15259function formatLocale(locale) {
15260 var locale_dateTime = locale.dateTime,
15261 locale_date = locale.date,
15262 locale_time = locale.time,
15263 locale_periods = locale.periods,
15264 locale_weekdays = locale.days,
15265 locale_shortWeekdays = locale.shortDays,
15266 locale_months = locale.months,
15267 locale_shortMonths = locale.shortMonths;
15268
15269 var periodRe = formatRe(locale_periods),
15270 periodLookup = formatLookup(locale_periods),
15271 weekdayRe = formatRe(locale_weekdays),
15272 weekdayLookup = formatLookup(locale_weekdays),
15273 shortWeekdayRe = formatRe(locale_shortWeekdays),
15274 shortWeekdayLookup = formatLookup(locale_shortWeekdays),
15275 monthRe = formatRe(locale_months),
15276 monthLookup = formatLookup(locale_months),
15277 shortMonthRe = formatRe(locale_shortMonths),
15278 shortMonthLookup = formatLookup(locale_shortMonths);
15279
15280 var formats = {
15281 "a": formatShortWeekday,
15282 "A": formatWeekday,
15283 "b": formatShortMonth,
15284 "B": formatMonth,
15285 "c": null,
15286 "d": formatDayOfMonth,
15287 "e": formatDayOfMonth,
15288 "f": formatMicroseconds,
15289 "g": formatYearISO,
15290 "G": formatFullYearISO,
15291 "H": formatHour24,
15292 "I": formatHour12,
15293 "j": formatDayOfYear,
15294 "L": formatMilliseconds,
15295 "m": formatMonthNumber,
15296 "M": formatMinutes,
15297 "p": formatPeriod,
15298 "q": formatQuarter,
15299 "Q": formatUnixTimestamp,
15300 "s": formatUnixTimestampSeconds,
15301 "S": formatSeconds,
15302 "u": formatWeekdayNumberMonday,
15303 "U": formatWeekNumberSunday,
15304 "V": formatWeekNumberISO,
15305 "w": formatWeekdayNumberSunday,
15306 "W": formatWeekNumberMonday,
15307 "x": null,
15308 "X": null,
15309 "y": formatYear,
15310 "Y": formatFullYear,
15311 "Z": formatZone,
15312 "%": formatLiteralPercent
15313 };
15314
15315 var utcFormats = {
15316 "a": formatUTCShortWeekday,
15317 "A": formatUTCWeekday,
15318 "b": formatUTCShortMonth,
15319 "B": formatUTCMonth,
15320 "c": null,
15321 "d": formatUTCDayOfMonth,
15322 "e": formatUTCDayOfMonth,
15323 "f": formatUTCMicroseconds,
15324 "g": formatUTCYearISO,
15325 "G": formatUTCFullYearISO,
15326 "H": formatUTCHour24,
15327 "I": formatUTCHour12,
15328 "j": formatUTCDayOfYear,
15329 "L": formatUTCMilliseconds,
15330 "m": formatUTCMonthNumber,
15331 "M": formatUTCMinutes,
15332 "p": formatUTCPeriod,
15333 "q": formatUTCQuarter,
15334 "Q": formatUnixTimestamp,
15335 "s": formatUnixTimestampSeconds,
15336 "S": formatUTCSeconds,
15337 "u": formatUTCWeekdayNumberMonday,
15338 "U": formatUTCWeekNumberSunday,
15339 "V": formatUTCWeekNumberISO,
15340 "w": formatUTCWeekdayNumberSunday,
15341 "W": formatUTCWeekNumberMonday,
15342 "x": null,
15343 "X": null,
15344 "y": formatUTCYear,
15345 "Y": formatUTCFullYear,
15346 "Z": formatUTCZone,
15347 "%": formatLiteralPercent
15348 };
15349
15350 var parses = {
15351 "a": parseShortWeekday,
15352 "A": parseWeekday,
15353 "b": parseShortMonth,
15354 "B": parseMonth,
15355 "c": parseLocaleDateTime,
15356 "d": parseDayOfMonth,
15357 "e": parseDayOfMonth,
15358 "f": parseMicroseconds,
15359 "g": parseYear,
15360 "G": parseFullYear,
15361 "H": parseHour24,
15362 "I": parseHour24,
15363 "j": parseDayOfYear,
15364 "L": parseMilliseconds,
15365 "m": parseMonthNumber,
15366 "M": parseMinutes,
15367 "p": parsePeriod,
15368 "q": parseQuarter,
15369 "Q": parseUnixTimestamp,
15370 "s": parseUnixTimestampSeconds,
15371 "S": parseSeconds,
15372 "u": parseWeekdayNumberMonday,
15373 "U": parseWeekNumberSunday,
15374 "V": parseWeekNumberISO,
15375 "w": parseWeekdayNumberSunday,
15376 "W": parseWeekNumberMonday,
15377 "x": parseLocaleDate,
15378 "X": parseLocaleTime,
15379 "y": parseYear,
15380 "Y": parseFullYear,
15381 "Z": parseZone,
15382 "%": parseLiteralPercent
15383 };
15384
15385 // These recursive directive definitions must be deferred.
15386 formats.x = newFormat(locale_date, formats);
15387 formats.X = newFormat(locale_time, formats);
15388 formats.c = newFormat(locale_dateTime, formats);
15389 utcFormats.x = newFormat(locale_date, utcFormats);
15390 utcFormats.X = newFormat(locale_time, utcFormats);
15391 utcFormats.c = newFormat(locale_dateTime, utcFormats);
15392
15393 function newFormat(specifier, formats) {
15394 return function(date) {
15395 var string = [],
15396 i = -1,
15397 j = 0,
15398 n = specifier.length,
15399 c,
15400 pad,
15401 format;
15402
15403 if (!(date instanceof Date)) date = new Date(+date);
15404
15405 while (++i < n) {
15406 if (specifier.charCodeAt(i) === 37) {
15407 string.push(specifier.slice(j, i));
15408 if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
15409 else pad = c === "e" ? " " : "0";
15410 if (format = formats[c]) c = format(date, pad);
15411 string.push(c);
15412 j = i + 1;
15413 }
15414 }
15415
15416 string.push(specifier.slice(j, i));
15417 return string.join("");
15418 };
15419 }
15420
15421 function newParse(specifier, Z) {
15422 return function(string) {
15423 var d = newDate(1900, undefined, 1),
15424 i = parseSpecifier(d, specifier, string += "", 0),
15425 week, day$1;
15426 if (i != string.length) return null;
15427
15428 // If a UNIX timestamp is specified, return it.
15429 if ("Q" in d) return new Date(d.Q);
15430 if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
15431
15432 // If this is utcParse, never use the local timezone.
15433 if (Z && !("Z" in d)) d.Z = 0;
15434
15435 // The am-pm flag is 0 for AM, and 1 for PM.
15436 if ("p" in d) d.H = d.H % 12 + d.p * 12;
15437
15438 // If the month was not specified, inherit from the quarter.
15439 if (d.m === undefined) d.m = "q" in d ? d.q : 0;
15440
15441 // Convert day-of-week and week-of-year to day-of-year.
15442 if ("V" in d) {
15443 if (d.V < 1 || d.V > 53) return null;
15444 if (!("w" in d)) d.w = 1;
15445 if ("Z" in d) {
15446 week = utcDate(newDate(d.y, 0, 1)), day$1 = week.getUTCDay();
15447 week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
15448 week = utcDay.offset(week, (d.V - 1) * 7);
15449 d.y = week.getUTCFullYear();
15450 d.m = week.getUTCMonth();
15451 d.d = week.getUTCDate() + (d.w + 6) % 7;
15452 } else {
15453 week = localDate(newDate(d.y, 0, 1)), day$1 = week.getDay();
15454 week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
15455 week = day.offset(week, (d.V - 1) * 7);
15456 d.y = week.getFullYear();
15457 d.m = week.getMonth();
15458 d.d = week.getDate() + (d.w + 6) % 7;
15459 }
15460 } else if ("W" in d || "U" in d) {
15461 if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
15462 day$1 = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
15463 d.m = 0;
15464 d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$1 + 5) % 7 : d.w + d.U * 7 - (day$1 + 6) % 7;
15465 }
15466
15467 // If a time zone is specified, all fields are interpreted as UTC and then
15468 // offset according to the specified time zone.
15469 if ("Z" in d) {
15470 d.H += d.Z / 100 | 0;
15471 d.M += d.Z % 100;
15472 return utcDate(d);
15473 }
15474
15475 // Otherwise, all fields are in local time.
15476 return localDate(d);
15477 };
15478 }
15479
15480 function parseSpecifier(d, specifier, string, j) {
15481 var i = 0,
15482 n = specifier.length,
15483 m = string.length,
15484 c,
15485 parse;
15486
15487 while (i < n) {
15488 if (j >= m) return -1;
15489 c = specifier.charCodeAt(i++);
15490 if (c === 37) {
15491 c = specifier.charAt(i++);
15492 parse = parses[c in pads ? specifier.charAt(i++) : c];
15493 if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
15494 } else if (c != string.charCodeAt(j++)) {
15495 return -1;
15496 }
15497 }
15498
15499 return j;
15500 }
15501
15502 function parsePeriod(d, string, i) {
15503 var n = periodRe.exec(string.slice(i));
15504 return n ? (d.p = periodLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
15505 }
15506
15507 function parseShortWeekday(d, string, i) {
15508 var n = shortWeekdayRe.exec(string.slice(i));
15509 return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
15510 }
15511
15512 function parseWeekday(d, string, i) {
15513 var n = weekdayRe.exec(string.slice(i));
15514 return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
15515 }
15516
15517 function parseShortMonth(d, string, i) {
15518 var n = shortMonthRe.exec(string.slice(i));
15519 return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
15520 }
15521
15522 function parseMonth(d, string, i) {
15523 var n = monthRe.exec(string.slice(i));
15524 return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
15525 }
15526
15527 function parseLocaleDateTime(d, string, i) {
15528 return parseSpecifier(d, locale_dateTime, string, i);
15529 }
15530
15531 function parseLocaleDate(d, string, i) {
15532 return parseSpecifier(d, locale_date, string, i);
15533 }
15534
15535 function parseLocaleTime(d, string, i) {
15536 return parseSpecifier(d, locale_time, string, i);
15537 }
15538
15539 function formatShortWeekday(d) {
15540 return locale_shortWeekdays[d.getDay()];
15541 }
15542
15543 function formatWeekday(d) {
15544 return locale_weekdays[d.getDay()];
15545 }
15546
15547 function formatShortMonth(d) {
15548 return locale_shortMonths[d.getMonth()];
15549 }
15550
15551 function formatMonth(d) {
15552 return locale_months[d.getMonth()];
15553 }
15554
15555 function formatPeriod(d) {
15556 return locale_periods[+(d.getHours() >= 12)];
15557 }
15558
15559 function formatQuarter(d) {
15560 return 1 + ~~(d.getMonth() / 3);
15561 }
15562
15563 function formatUTCShortWeekday(d) {
15564 return locale_shortWeekdays[d.getUTCDay()];
15565 }
15566
15567 function formatUTCWeekday(d) {
15568 return locale_weekdays[d.getUTCDay()];
15569 }
15570
15571 function formatUTCShortMonth(d) {
15572 return locale_shortMonths[d.getUTCMonth()];
15573 }
15574
15575 function formatUTCMonth(d) {
15576 return locale_months[d.getUTCMonth()];
15577 }
15578
15579 function formatUTCPeriod(d) {
15580 return locale_periods[+(d.getUTCHours() >= 12)];
15581 }
15582
15583 function formatUTCQuarter(d) {
15584 return 1 + ~~(d.getUTCMonth() / 3);
15585 }
15586
15587 return {
15588 format: function(specifier) {
15589 var f = newFormat(specifier += "", formats);
15590 f.toString = function() { return specifier; };
15591 return f;
15592 },
15593 parse: function(specifier) {
15594 var p = newParse(specifier += "", false);
15595 p.toString = function() { return specifier; };
15596 return p;
15597 },
15598 utcFormat: function(specifier) {
15599 var f = newFormat(specifier += "", utcFormats);
15600 f.toString = function() { return specifier; };
15601 return f;
15602 },
15603 utcParse: function(specifier) {
15604 var p = newParse(specifier += "", true);
15605 p.toString = function() { return specifier; };
15606 return p;
15607 }
15608 };
15609}
15610
15611var pads = {"-": "", "_": " ", "0": "0"},
15612 numberRe = /^\s*\d+/, // note: ignores next directive
15613 percentRe = /^%/,
15614 requoteRe = /[\\^$*+?|[\]().{}]/g;
15615
15616function pad(value, fill, width) {
15617 var sign = value < 0 ? "-" : "",
15618 string = (sign ? -value : value) + "",
15619 length = string.length;
15620 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
15621}
15622
15623function requote(s) {
15624 return s.replace(requoteRe, "\\$&");
15625}
15626
15627function formatRe(names) {
15628 return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
15629}
15630
15631function formatLookup(names) {
15632 return new Map(names.map((name, i) => [name.toLowerCase(), i]));
15633}
15634
15635function parseWeekdayNumberSunday(d, string, i) {
15636 var n = numberRe.exec(string.slice(i, i + 1));
15637 return n ? (d.w = +n[0], i + n[0].length) : -1;
15638}
15639
15640function parseWeekdayNumberMonday(d, string, i) {
15641 var n = numberRe.exec(string.slice(i, i + 1));
15642 return n ? (d.u = +n[0], i + n[0].length) : -1;
15643}
15644
15645function parseWeekNumberSunday(d, string, i) {
15646 var n = numberRe.exec(string.slice(i, i + 2));
15647 return n ? (d.U = +n[0], i + n[0].length) : -1;
15648}
15649
15650function parseWeekNumberISO(d, string, i) {
15651 var n = numberRe.exec(string.slice(i, i + 2));
15652 return n ? (d.V = +n[0], i + n[0].length) : -1;
15653}
15654
15655function parseWeekNumberMonday(d, string, i) {
15656 var n = numberRe.exec(string.slice(i, i + 2));
15657 return n ? (d.W = +n[0], i + n[0].length) : -1;
15658}
15659
15660function parseFullYear(d, string, i) {
15661 var n = numberRe.exec(string.slice(i, i + 4));
15662 return n ? (d.y = +n[0], i + n[0].length) : -1;
15663}
15664
15665function parseYear(d, string, i) {
15666 var n = numberRe.exec(string.slice(i, i + 2));
15667 return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
15668}
15669
15670function parseZone(d, string, i) {
15671 var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
15672 return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
15673}
15674
15675function parseQuarter(d, string, i) {
15676 var n = numberRe.exec(string.slice(i, i + 1));
15677 return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
15678}
15679
15680function parseMonthNumber(d, string, i) {
15681 var n = numberRe.exec(string.slice(i, i + 2));
15682 return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
15683}
15684
15685function parseDayOfMonth(d, string, i) {
15686 var n = numberRe.exec(string.slice(i, i + 2));
15687 return n ? (d.d = +n[0], i + n[0].length) : -1;
15688}
15689
15690function parseDayOfYear(d, string, i) {
15691 var n = numberRe.exec(string.slice(i, i + 3));
15692 return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
15693}
15694
15695function parseHour24(d, string, i) {
15696 var n = numberRe.exec(string.slice(i, i + 2));
15697 return n ? (d.H = +n[0], i + n[0].length) : -1;
15698}
15699
15700function parseMinutes(d, string, i) {
15701 var n = numberRe.exec(string.slice(i, i + 2));
15702 return n ? (d.M = +n[0], i + n[0].length) : -1;
15703}
15704
15705function parseSeconds(d, string, i) {
15706 var n = numberRe.exec(string.slice(i, i + 2));
15707 return n ? (d.S = +n[0], i + n[0].length) : -1;
15708}
15709
15710function parseMilliseconds(d, string, i) {
15711 var n = numberRe.exec(string.slice(i, i + 3));
15712 return n ? (d.L = +n[0], i + n[0].length) : -1;
15713}
15714
15715function parseMicroseconds(d, string, i) {
15716 var n = numberRe.exec(string.slice(i, i + 6));
15717 return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
15718}
15719
15720function parseLiteralPercent(d, string, i) {
15721 var n = percentRe.exec(string.slice(i, i + 1));
15722 return n ? i + n[0].length : -1;
15723}
15724
15725function parseUnixTimestamp(d, string, i) {
15726 var n = numberRe.exec(string.slice(i));
15727 return n ? (d.Q = +n[0], i + n[0].length) : -1;
15728}
15729
15730function parseUnixTimestampSeconds(d, string, i) {
15731 var n = numberRe.exec(string.slice(i));
15732 return n ? (d.s = +n[0], i + n[0].length) : -1;
15733}
15734
15735function formatDayOfMonth(d, p) {
15736 return pad(d.getDate(), p, 2);
15737}
15738
15739function formatHour24(d, p) {
15740 return pad(d.getHours(), p, 2);
15741}
15742
15743function formatHour12(d, p) {
15744 return pad(d.getHours() % 12 || 12, p, 2);
15745}
15746
15747function formatDayOfYear(d, p) {
15748 return pad(1 + day.count(year(d), d), p, 3);
15749}
15750
15751function formatMilliseconds(d, p) {
15752 return pad(d.getMilliseconds(), p, 3);
15753}
15754
15755function formatMicroseconds(d, p) {
15756 return formatMilliseconds(d, p) + "000";
15757}
15758
15759function formatMonthNumber(d, p) {
15760 return pad(d.getMonth() + 1, p, 2);
15761}
15762
15763function formatMinutes(d, p) {
15764 return pad(d.getMinutes(), p, 2);
15765}
15766
15767function formatSeconds(d, p) {
15768 return pad(d.getSeconds(), p, 2);
15769}
15770
15771function formatWeekdayNumberMonday(d) {
15772 var day = d.getDay();
15773 return day === 0 ? 7 : day;
15774}
15775
15776function formatWeekNumberSunday(d, p) {
15777 return pad(sunday.count(year(d) - 1, d), p, 2);
15778}
15779
15780function dISO(d) {
15781 var day = d.getDay();
15782 return (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
15783}
15784
15785function formatWeekNumberISO(d, p) {
15786 d = dISO(d);
15787 return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
15788}
15789
15790function formatWeekdayNumberSunday(d) {
15791 return d.getDay();
15792}
15793
15794function formatWeekNumberMonday(d, p) {
15795 return pad(monday.count(year(d) - 1, d), p, 2);
15796}
15797
15798function formatYear(d, p) {
15799 return pad(d.getFullYear() % 100, p, 2);
15800}
15801
15802function formatYearISO(d, p) {
15803 d = dISO(d);
15804 return pad(d.getFullYear() % 100, p, 2);
15805}
15806
15807function formatFullYear(d, p) {
15808 return pad(d.getFullYear() % 10000, p, 4);
15809}
15810
15811function formatFullYearISO(d, p) {
15812 var day = d.getDay();
15813 d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
15814 return pad(d.getFullYear() % 10000, p, 4);
15815}
15816
15817function formatZone(d) {
15818 var z = d.getTimezoneOffset();
15819 return (z > 0 ? "-" : (z *= -1, "+"))
15820 + pad(z / 60 | 0, "0", 2)
15821 + pad(z % 60, "0", 2);
15822}
15823
15824function formatUTCDayOfMonth(d, p) {
15825 return pad(d.getUTCDate(), p, 2);
15826}
15827
15828function formatUTCHour24(d, p) {
15829 return pad(d.getUTCHours(), p, 2);
15830}
15831
15832function formatUTCHour12(d, p) {
15833 return pad(d.getUTCHours() % 12 || 12, p, 2);
15834}
15835
15836function formatUTCDayOfYear(d, p) {
15837 return pad(1 + utcDay.count(utcYear(d), d), p, 3);
15838}
15839
15840function formatUTCMilliseconds(d, p) {
15841 return pad(d.getUTCMilliseconds(), p, 3);
15842}
15843
15844function formatUTCMicroseconds(d, p) {
15845 return formatUTCMilliseconds(d, p) + "000";
15846}
15847
15848function formatUTCMonthNumber(d, p) {
15849 return pad(d.getUTCMonth() + 1, p, 2);
15850}
15851
15852function formatUTCMinutes(d, p) {
15853 return pad(d.getUTCMinutes(), p, 2);
15854}
15855
15856function formatUTCSeconds(d, p) {
15857 return pad(d.getUTCSeconds(), p, 2);
15858}
15859
15860function formatUTCWeekdayNumberMonday(d) {
15861 var dow = d.getUTCDay();
15862 return dow === 0 ? 7 : dow;
15863}
15864
15865function formatUTCWeekNumberSunday(d, p) {
15866 return pad(utcSunday.count(utcYear(d) - 1, d), p, 2);
15867}
15868
15869function UTCdISO(d) {
15870 var day = d.getUTCDay();
15871 return (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
15872}
15873
15874function formatUTCWeekNumberISO(d, p) {
15875 d = UTCdISO(d);
15876 return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
15877}
15878
15879function formatUTCWeekdayNumberSunday(d) {
15880 return d.getUTCDay();
15881}
15882
15883function formatUTCWeekNumberMonday(d, p) {
15884 return pad(utcMonday.count(utcYear(d) - 1, d), p, 2);
15885}
15886
15887function formatUTCYear(d, p) {
15888 return pad(d.getUTCFullYear() % 100, p, 2);
15889}
15890
15891function formatUTCYearISO(d, p) {
15892 d = UTCdISO(d);
15893 return pad(d.getUTCFullYear() % 100, p, 2);
15894}
15895
15896function formatUTCFullYear(d, p) {
15897 return pad(d.getUTCFullYear() % 10000, p, 4);
15898}
15899
15900function formatUTCFullYearISO(d, p) {
15901 var day = d.getUTCDay();
15902 d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
15903 return pad(d.getUTCFullYear() % 10000, p, 4);
15904}
15905
15906function formatUTCZone() {
15907 return "+0000";
15908}
15909
15910function formatLiteralPercent() {
15911 return "%";
15912}
15913
15914function formatUnixTimestamp(d) {
15915 return +d;
15916}
15917
15918function formatUnixTimestampSeconds(d) {
15919 return Math.floor(+d / 1000);
15920}
15921
15922var locale;
15923exports.timeFormat = void 0;
15924exports.timeParse = void 0;
15925exports.utcFormat = void 0;
15926exports.utcParse = void 0;
15927
15928defaultLocale({
15929 dateTime: "%x, %X",
15930 date: "%-m/%-d/%Y",
15931 time: "%-I:%M:%S %p",
15932 periods: ["AM", "PM"],
15933 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
15934 shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
15935 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
15936 shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
15937});
15938
15939function defaultLocale(definition) {
15940 locale = formatLocale(definition);
15941 exports.timeFormat = locale.format;
15942 exports.timeParse = locale.parse;
15943 exports.utcFormat = locale.utcFormat;
15944 exports.utcParse = locale.utcParse;
15945 return locale;
15946}
15947
15948var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
15949
15950function formatIsoNative(date) {
15951 return date.toISOString();
15952}
15953
15954var formatIso = Date.prototype.toISOString
15955 ? formatIsoNative
15956 : exports.utcFormat(isoSpecifier);
15957
15958function parseIsoNative(string) {
15959 var date = new Date(string);
15960 return isNaN(date) ? null : date;
15961}
15962
15963var parseIso = +new Date("2000-01-01T00:00:00.000Z")
15964 ? parseIsoNative
15965 : exports.utcParse(isoSpecifier);
15966
15967function date(t) {
15968 return new Date(t);
15969}
15970
15971function number(t) {
15972 return t instanceof Date ? +t : +new Date(+t);
15973}
15974
15975function calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format) {
15976 var scale = continuous(),
15977 invert = scale.invert,
15978 domain = scale.domain;
15979
15980 var formatMillisecond = format(".%L"),
15981 formatSecond = format(":%S"),
15982 formatMinute = format("%I:%M"),
15983 formatHour = format("%I %p"),
15984 formatDay = format("%a %d"),
15985 formatWeek = format("%b %d"),
15986 formatMonth = format("%B"),
15987 formatYear = format("%Y");
15988
15989 function tickFormat(date) {
15990 return (second(date) < date ? formatMillisecond
15991 : minute(date) < date ? formatSecond
15992 : hour(date) < date ? formatMinute
15993 : day(date) < date ? formatHour
15994 : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
15995 : year(date) < date ? formatMonth
15996 : formatYear)(date);
15997 }
15998
15999 scale.invert = function(y) {
16000 return new Date(invert(y));
16001 };
16002
16003 scale.domain = function(_) {
16004 return arguments.length ? domain(Array.from(_, number)) : domain().map(date);
16005 };
16006
16007 scale.ticks = function(interval) {
16008 var d = domain();
16009 return ticks(d[0], d[d.length - 1], interval == null ? 10 : interval);
16010 };
16011
16012 scale.tickFormat = function(count, specifier) {
16013 return specifier == null ? tickFormat : format(specifier);
16014 };
16015
16016 scale.nice = function(interval) {
16017 var d = domain();
16018 if (!interval || typeof interval.range !== "function") interval = tickInterval(d[0], d[d.length - 1], interval == null ? 10 : interval);
16019 return interval ? domain(nice(d, interval)) : scale;
16020 };
16021
16022 scale.copy = function() {
16023 return copy$1(scale, calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format));
16024 };
16025
16026 return scale;
16027}
16028
16029function time() {
16030 return initRange.apply(calendar(timeTicks, timeTickInterval, year, month, sunday, day, hour, minute, second, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
16031}
16032
16033function utcTime() {
16034 return initRange.apply(calendar(utcTicks, utcTickInterval, utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
16035}
16036
16037function transformer$1() {
16038 var x0 = 0,
16039 x1 = 1,
16040 t0,
16041 t1,
16042 k10,
16043 transform,
16044 interpolator = identity$3,
16045 clamp = false,
16046 unknown;
16047
16048 function scale(x) {
16049 return x == null || isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
16050 }
16051
16052 scale.domain = function(_) {
16053 return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
16054 };
16055
16056 scale.clamp = function(_) {
16057 return arguments.length ? (clamp = !!_, scale) : clamp;
16058 };
16059
16060 scale.interpolator = function(_) {
16061 return arguments.length ? (interpolator = _, scale) : interpolator;
16062 };
16063
16064 function range(interpolate) {
16065 return function(_) {
16066 var r0, r1;
16067 return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)];
16068 };
16069 }
16070
16071 scale.range = range(interpolate$2);
16072
16073 scale.rangeRound = range(interpolateRound);
16074
16075 scale.unknown = function(_) {
16076 return arguments.length ? (unknown = _, scale) : unknown;
16077 };
16078
16079 return function(t) {
16080 transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
16081 return scale;
16082 };
16083}
16084
16085function copy(source, target) {
16086 return target
16087 .domain(source.domain())
16088 .interpolator(source.interpolator())
16089 .clamp(source.clamp())
16090 .unknown(source.unknown());
16091}
16092
16093function sequential() {
16094 var scale = linearish(transformer$1()(identity$3));
16095
16096 scale.copy = function() {
16097 return copy(scale, sequential());
16098 };
16099
16100 return initInterpolator.apply(scale, arguments);
16101}
16102
16103function sequentialLog() {
16104 var scale = loggish(transformer$1()).domain([1, 10]);
16105
16106 scale.copy = function() {
16107 return copy(scale, sequentialLog()).base(scale.base());
16108 };
16109
16110 return initInterpolator.apply(scale, arguments);
16111}
16112
16113function sequentialSymlog() {
16114 var scale = symlogish(transformer$1());
16115
16116 scale.copy = function() {
16117 return copy(scale, sequentialSymlog()).constant(scale.constant());
16118 };
16119
16120 return initInterpolator.apply(scale, arguments);
16121}
16122
16123function sequentialPow() {
16124 var scale = powish(transformer$1());
16125
16126 scale.copy = function() {
16127 return copy(scale, sequentialPow()).exponent(scale.exponent());
16128 };
16129
16130 return initInterpolator.apply(scale, arguments);
16131}
16132
16133function sequentialSqrt() {
16134 return sequentialPow.apply(null, arguments).exponent(0.5);
16135}
16136
16137function sequentialQuantile() {
16138 var domain = [],
16139 interpolator = identity$3;
16140
16141 function scale(x) {
16142 if (x != null && !isNaN(x = +x)) return interpolator((bisectRight(domain, x, 1) - 1) / (domain.length - 1));
16143 }
16144
16145 scale.domain = function(_) {
16146 if (!arguments.length) return domain.slice();
16147 domain = [];
16148 for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
16149 domain.sort(ascending$3);
16150 return scale;
16151 };
16152
16153 scale.interpolator = function(_) {
16154 return arguments.length ? (interpolator = _, scale) : interpolator;
16155 };
16156
16157 scale.range = function() {
16158 return domain.map((d, i) => interpolator(i / (domain.length - 1)));
16159 };
16160
16161 scale.quantiles = function(n) {
16162 return Array.from({length: n + 1}, (_, i) => quantile$1(domain, i / n));
16163 };
16164
16165 scale.copy = function() {
16166 return sequentialQuantile(interpolator).domain(domain);
16167 };
16168
16169 return initInterpolator.apply(scale, arguments);
16170}
16171
16172function transformer() {
16173 var x0 = 0,
16174 x1 = 0.5,
16175 x2 = 1,
16176 s = 1,
16177 t0,
16178 t1,
16179 t2,
16180 k10,
16181 k21,
16182 interpolator = identity$3,
16183 transform,
16184 clamp = false,
16185 unknown;
16186
16187 function scale(x) {
16188 return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (s * x < s * t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
16189 }
16190
16191 scale.domain = function(_) {
16192 return arguments.length ? ([x0, x1, x2] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), t2 = transform(x2 = +x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1, scale) : [x0, x1, x2];
16193 };
16194
16195 scale.clamp = function(_) {
16196 return arguments.length ? (clamp = !!_, scale) : clamp;
16197 };
16198
16199 scale.interpolator = function(_) {
16200 return arguments.length ? (interpolator = _, scale) : interpolator;
16201 };
16202
16203 function range(interpolate) {
16204 return function(_) {
16205 var r0, r1, r2;
16206 return arguments.length ? ([r0, r1, r2] = _, interpolator = piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)];
16207 };
16208 }
16209
16210 scale.range = range(interpolate$2);
16211
16212 scale.rangeRound = range(interpolateRound);
16213
16214 scale.unknown = function(_) {
16215 return arguments.length ? (unknown = _, scale) : unknown;
16216 };
16217
16218 return function(t) {
16219 transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1;
16220 return scale;
16221 };
16222}
16223
16224function diverging$1() {
16225 var scale = linearish(transformer()(identity$3));
16226
16227 scale.copy = function() {
16228 return copy(scale, diverging$1());
16229 };
16230
16231 return initInterpolator.apply(scale, arguments);
16232}
16233
16234function divergingLog() {
16235 var scale = loggish(transformer()).domain([0.1, 1, 10]);
16236
16237 scale.copy = function() {
16238 return copy(scale, divergingLog()).base(scale.base());
16239 };
16240
16241 return initInterpolator.apply(scale, arguments);
16242}
16243
16244function divergingSymlog() {
16245 var scale = symlogish(transformer());
16246
16247 scale.copy = function() {
16248 return copy(scale, divergingSymlog()).constant(scale.constant());
16249 };
16250
16251 return initInterpolator.apply(scale, arguments);
16252}
16253
16254function divergingPow() {
16255 var scale = powish(transformer());
16256
16257 scale.copy = function() {
16258 return copy(scale, divergingPow()).exponent(scale.exponent());
16259 };
16260
16261 return initInterpolator.apply(scale, arguments);
16262}
16263
16264function divergingSqrt() {
16265 return divergingPow.apply(null, arguments).exponent(0.5);
16266}
16267
16268function colors(specifier) {
16269 var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
16270 while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
16271 return colors;
16272}
16273
16274var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
16275
16276var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
16277
16278var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
16279
16280var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
16281
16282var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
16283
16284var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
16285
16286var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
16287
16288var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
16289
16290var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
16291
16292var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
16293
16294var ramp$1 = scheme => rgbBasis(scheme[scheme.length - 1]);
16295
16296var scheme$q = new Array(3).concat(
16297 "d8b365f5f5f55ab4ac",
16298 "a6611adfc27d80cdc1018571",
16299 "a6611adfc27df5f5f580cdc1018571",
16300 "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
16301 "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
16302 "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
16303 "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
16304 "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
16305 "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
16306).map(colors);
16307
16308var BrBG = ramp$1(scheme$q);
16309
16310var scheme$p = new Array(3).concat(
16311 "af8dc3f7f7f77fbf7b",
16312 "7b3294c2a5cfa6dba0008837",
16313 "7b3294c2a5cff7f7f7a6dba0008837",
16314 "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
16315 "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
16316 "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
16317 "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
16318 "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
16319 "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
16320).map(colors);
16321
16322var PRGn = ramp$1(scheme$p);
16323
16324var scheme$o = new Array(3).concat(
16325 "e9a3c9f7f7f7a1d76a",
16326 "d01c8bf1b6dab8e1864dac26",
16327 "d01c8bf1b6daf7f7f7b8e1864dac26",
16328 "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
16329 "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
16330 "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
16331 "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
16332 "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
16333 "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
16334).map(colors);
16335
16336var PiYG = ramp$1(scheme$o);
16337
16338var scheme$n = new Array(3).concat(
16339 "998ec3f7f7f7f1a340",
16340 "5e3c99b2abd2fdb863e66101",
16341 "5e3c99b2abd2f7f7f7fdb863e66101",
16342 "542788998ec3d8daebfee0b6f1a340b35806",
16343 "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
16344 "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
16345 "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
16346 "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
16347 "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
16348).map(colors);
16349
16350var PuOr = ramp$1(scheme$n);
16351
16352var scheme$m = new Array(3).concat(
16353 "ef8a62f7f7f767a9cf",
16354 "ca0020f4a58292c5de0571b0",
16355 "ca0020f4a582f7f7f792c5de0571b0",
16356 "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
16357 "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
16358 "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
16359 "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
16360 "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
16361 "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
16362).map(colors);
16363
16364var RdBu = ramp$1(scheme$m);
16365
16366var scheme$l = new Array(3).concat(
16367 "ef8a62ffffff999999",
16368 "ca0020f4a582bababa404040",
16369 "ca0020f4a582ffffffbababa404040",
16370 "b2182bef8a62fddbc7e0e0e09999994d4d4d",
16371 "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
16372 "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
16373 "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
16374 "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
16375 "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
16376).map(colors);
16377
16378var RdGy = ramp$1(scheme$l);
16379
16380var scheme$k = new Array(3).concat(
16381 "fc8d59ffffbf91bfdb",
16382 "d7191cfdae61abd9e92c7bb6",
16383 "d7191cfdae61ffffbfabd9e92c7bb6",
16384 "d73027fc8d59fee090e0f3f891bfdb4575b4",
16385 "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
16386 "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
16387 "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
16388 "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
16389 "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
16390).map(colors);
16391
16392var RdYlBu = ramp$1(scheme$k);
16393
16394var scheme$j = new Array(3).concat(
16395 "fc8d59ffffbf91cf60",
16396 "d7191cfdae61a6d96a1a9641",
16397 "d7191cfdae61ffffbfa6d96a1a9641",
16398 "d73027fc8d59fee08bd9ef8b91cf601a9850",
16399 "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
16400 "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
16401 "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
16402 "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
16403 "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
16404).map(colors);
16405
16406var RdYlGn = ramp$1(scheme$j);
16407
16408var scheme$i = new Array(3).concat(
16409 "fc8d59ffffbf99d594",
16410 "d7191cfdae61abdda42b83ba",
16411 "d7191cfdae61ffffbfabdda42b83ba",
16412 "d53e4ffc8d59fee08be6f59899d5943288bd",
16413 "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
16414 "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
16415 "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
16416 "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
16417 "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
16418).map(colors);
16419
16420var Spectral = ramp$1(scheme$i);
16421
16422var scheme$h = new Array(3).concat(
16423 "e5f5f999d8c92ca25f",
16424 "edf8fbb2e2e266c2a4238b45",
16425 "edf8fbb2e2e266c2a42ca25f006d2c",
16426 "edf8fbccece699d8c966c2a42ca25f006d2c",
16427 "edf8fbccece699d8c966c2a441ae76238b45005824",
16428 "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
16429 "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
16430).map(colors);
16431
16432var BuGn = ramp$1(scheme$h);
16433
16434var scheme$g = new Array(3).concat(
16435 "e0ecf49ebcda8856a7",
16436 "edf8fbb3cde38c96c688419d",
16437 "edf8fbb3cde38c96c68856a7810f7c",
16438 "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
16439 "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
16440 "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
16441 "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
16442).map(colors);
16443
16444var BuPu = ramp$1(scheme$g);
16445
16446var scheme$f = new Array(3).concat(
16447 "e0f3dba8ddb543a2ca",
16448 "f0f9e8bae4bc7bccc42b8cbe",
16449 "f0f9e8bae4bc7bccc443a2ca0868ac",
16450 "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
16451 "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
16452 "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
16453 "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
16454).map(colors);
16455
16456var GnBu = ramp$1(scheme$f);
16457
16458var scheme$e = new Array(3).concat(
16459 "fee8c8fdbb84e34a33",
16460 "fef0d9fdcc8afc8d59d7301f",
16461 "fef0d9fdcc8afc8d59e34a33b30000",
16462 "fef0d9fdd49efdbb84fc8d59e34a33b30000",
16463 "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
16464 "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
16465 "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
16466).map(colors);
16467
16468var OrRd = ramp$1(scheme$e);
16469
16470var scheme$d = new Array(3).concat(
16471 "ece2f0a6bddb1c9099",
16472 "f6eff7bdc9e167a9cf02818a",
16473 "f6eff7bdc9e167a9cf1c9099016c59",
16474 "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
16475 "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
16476 "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
16477 "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
16478).map(colors);
16479
16480var PuBuGn = ramp$1(scheme$d);
16481
16482var scheme$c = new Array(3).concat(
16483 "ece7f2a6bddb2b8cbe",
16484 "f1eef6bdc9e174a9cf0570b0",
16485 "f1eef6bdc9e174a9cf2b8cbe045a8d",
16486 "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
16487 "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
16488 "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
16489 "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
16490).map(colors);
16491
16492var PuBu = ramp$1(scheme$c);
16493
16494var scheme$b = new Array(3).concat(
16495 "e7e1efc994c7dd1c77",
16496 "f1eef6d7b5d8df65b0ce1256",
16497 "f1eef6d7b5d8df65b0dd1c77980043",
16498 "f1eef6d4b9dac994c7df65b0dd1c77980043",
16499 "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
16500 "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
16501 "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
16502).map(colors);
16503
16504var PuRd = ramp$1(scheme$b);
16505
16506var scheme$a = new Array(3).concat(
16507 "fde0ddfa9fb5c51b8a",
16508 "feebe2fbb4b9f768a1ae017e",
16509 "feebe2fbb4b9f768a1c51b8a7a0177",
16510 "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
16511 "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
16512 "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
16513 "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
16514).map(colors);
16515
16516var RdPu = ramp$1(scheme$a);
16517
16518var scheme$9 = new Array(3).concat(
16519 "edf8b17fcdbb2c7fb8",
16520 "ffffcca1dab441b6c4225ea8",
16521 "ffffcca1dab441b6c42c7fb8253494",
16522 "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
16523 "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
16524 "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
16525 "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
16526).map(colors);
16527
16528var YlGnBu = ramp$1(scheme$9);
16529
16530var scheme$8 = new Array(3).concat(
16531 "f7fcb9addd8e31a354",
16532 "ffffccc2e69978c679238443",
16533 "ffffccc2e69978c67931a354006837",
16534 "ffffccd9f0a3addd8e78c67931a354006837",
16535 "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
16536 "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
16537 "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
16538).map(colors);
16539
16540var YlGn = ramp$1(scheme$8);
16541
16542var scheme$7 = new Array(3).concat(
16543 "fff7bcfec44fd95f0e",
16544 "ffffd4fed98efe9929cc4c02",
16545 "ffffd4fed98efe9929d95f0e993404",
16546 "ffffd4fee391fec44ffe9929d95f0e993404",
16547 "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
16548 "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
16549 "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
16550).map(colors);
16551
16552var YlOrBr = ramp$1(scheme$7);
16553
16554var scheme$6 = new Array(3).concat(
16555 "ffeda0feb24cf03b20",
16556 "ffffb2fecc5cfd8d3ce31a1c",
16557 "ffffb2fecc5cfd8d3cf03b20bd0026",
16558 "ffffb2fed976feb24cfd8d3cf03b20bd0026",
16559 "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
16560 "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
16561 "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
16562).map(colors);
16563
16564var YlOrRd = ramp$1(scheme$6);
16565
16566var scheme$5 = new Array(3).concat(
16567 "deebf79ecae13182bd",
16568 "eff3ffbdd7e76baed62171b5",
16569 "eff3ffbdd7e76baed63182bd08519c",
16570 "eff3ffc6dbef9ecae16baed63182bd08519c",
16571 "eff3ffc6dbef9ecae16baed64292c62171b5084594",
16572 "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
16573 "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
16574).map(colors);
16575
16576var Blues = ramp$1(scheme$5);
16577
16578var scheme$4 = new Array(3).concat(
16579 "e5f5e0a1d99b31a354",
16580 "edf8e9bae4b374c476238b45",
16581 "edf8e9bae4b374c47631a354006d2c",
16582 "edf8e9c7e9c0a1d99b74c47631a354006d2c",
16583 "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
16584 "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
16585 "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
16586).map(colors);
16587
16588var Greens = ramp$1(scheme$4);
16589
16590var scheme$3 = new Array(3).concat(
16591 "f0f0f0bdbdbd636363",
16592 "f7f7f7cccccc969696525252",
16593 "f7f7f7cccccc969696636363252525",
16594 "f7f7f7d9d9d9bdbdbd969696636363252525",
16595 "f7f7f7d9d9d9bdbdbd969696737373525252252525",
16596 "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
16597 "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
16598).map(colors);
16599
16600var Greys = ramp$1(scheme$3);
16601
16602var scheme$2 = new Array(3).concat(
16603 "efedf5bcbddc756bb1",
16604 "f2f0f7cbc9e29e9ac86a51a3",
16605 "f2f0f7cbc9e29e9ac8756bb154278f",
16606 "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
16607 "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
16608 "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
16609 "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
16610).map(colors);
16611
16612var Purples = ramp$1(scheme$2);
16613
16614var scheme$1 = new Array(3).concat(
16615 "fee0d2fc9272de2d26",
16616 "fee5d9fcae91fb6a4acb181d",
16617 "fee5d9fcae91fb6a4ade2d26a50f15",
16618 "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
16619 "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
16620 "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
16621 "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
16622).map(colors);
16623
16624var Reds = ramp$1(scheme$1);
16625
16626var scheme = new Array(3).concat(
16627 "fee6cefdae6be6550d",
16628 "feeddefdbe85fd8d3cd94701",
16629 "feeddefdbe85fd8d3ce6550da63603",
16630 "feeddefdd0a2fdae6bfd8d3ce6550da63603",
16631 "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
16632 "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
16633 "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
16634).map(colors);
16635
16636var Oranges = ramp$1(scheme);
16637
16638function cividis(t) {
16639 t = Math.max(0, Math.min(1, t));
16640 return "rgb("
16641 + Math.max(0, Math.min(255, Math.round(-4.54 - t * (35.34 - t * (2381.73 - t * (6402.7 - t * (7024.72 - t * 2710.57))))))) + ", "
16642 + Math.max(0, Math.min(255, Math.round(32.49 + t * (170.73 + t * (52.82 - t * (131.46 - t * (176.58 - t * 67.37))))))) + ", "
16643 + Math.max(0, Math.min(255, Math.round(81.24 + t * (442.36 - t * (2482.43 - t * (6167.24 - t * (6614.94 - t * 2475.67)))))))
16644 + ")";
16645}
16646
16647var cubehelix = cubehelixLong(cubehelix$3(300, 0.5, 0.0), cubehelix$3(-240, 0.5, 1.0));
16648
16649var warm = cubehelixLong(cubehelix$3(-100, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
16650
16651var cool = cubehelixLong(cubehelix$3(260, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
16652
16653var c$2 = cubehelix$3();
16654
16655function rainbow(t) {
16656 if (t < 0 || t > 1) t -= Math.floor(t);
16657 var ts = Math.abs(t - 0.5);
16658 c$2.h = 360 * t - 100;
16659 c$2.s = 1.5 - 1.5 * ts;
16660 c$2.l = 0.8 - 0.9 * ts;
16661 return c$2 + "";
16662}
16663
16664var c$1 = rgb(),
16665 pi_1_3 = Math.PI / 3,
16666 pi_2_3 = Math.PI * 2 / 3;
16667
16668function sinebow(t) {
16669 var x;
16670 t = (0.5 - t) * Math.PI;
16671 c$1.r = 255 * (x = Math.sin(t)) * x;
16672 c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
16673 c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
16674 return c$1 + "";
16675}
16676
16677function turbo(t) {
16678 t = Math.max(0, Math.min(1, t));
16679 return "rgb("
16680 + Math.max(0, Math.min(255, Math.round(34.61 + t * (1172.33 - t * (10793.56 - t * (33300.12 - t * (38394.49 - t * 14825.05))))))) + ", "
16681 + Math.max(0, Math.min(255, Math.round(23.31 + t * (557.33 + t * (1225.33 - t * (3574.96 - t * (1073.77 + t * 707.56))))))) + ", "
16682 + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
16683 + ")";
16684}
16685
16686function ramp(range) {
16687 var n = range.length;
16688 return function(t) {
16689 return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
16690 };
16691}
16692
16693var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
16694
16695var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
16696
16697var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
16698
16699var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
16700
16701function constant$1(x) {
16702 return function constant() {
16703 return x;
16704 };
16705}
16706
16707var abs = Math.abs;
16708var atan2 = Math.atan2;
16709var cos = Math.cos;
16710var max = Math.max;
16711var min = Math.min;
16712var sin = Math.sin;
16713var sqrt = Math.sqrt;
16714
16715var epsilon = 1e-12;
16716var pi = Math.PI;
16717var halfPi = pi / 2;
16718var tau = 2 * pi;
16719
16720function acos(x) {
16721 return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
16722}
16723
16724function asin(x) {
16725 return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
16726}
16727
16728function arcInnerRadius(d) {
16729 return d.innerRadius;
16730}
16731
16732function arcOuterRadius(d) {
16733 return d.outerRadius;
16734}
16735
16736function arcStartAngle(d) {
16737 return d.startAngle;
16738}
16739
16740function arcEndAngle(d) {
16741 return d.endAngle;
16742}
16743
16744function arcPadAngle(d) {
16745 return d && d.padAngle; // Note: optional!
16746}
16747
16748function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
16749 var x10 = x1 - x0, y10 = y1 - y0,
16750 x32 = x3 - x2, y32 = y3 - y2,
16751 t = y32 * x10 - x32 * y10;
16752 if (t * t < epsilon) return;
16753 t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
16754 return [x0 + t * x10, y0 + t * y10];
16755}
16756
16757// Compute perpendicular offset line of length rc.
16758// http://mathworld.wolfram.com/Circle-LineIntersection.html
16759function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
16760 var x01 = x0 - x1,
16761 y01 = y0 - y1,
16762 lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),
16763 ox = lo * y01,
16764 oy = -lo * x01,
16765 x11 = x0 + ox,
16766 y11 = y0 + oy,
16767 x10 = x1 + ox,
16768 y10 = y1 + oy,
16769 x00 = (x11 + x10) / 2,
16770 y00 = (y11 + y10) / 2,
16771 dx = x10 - x11,
16772 dy = y10 - y11,
16773 d2 = dx * dx + dy * dy,
16774 r = r1 - rc,
16775 D = x11 * y10 - x10 * y11,
16776 d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),
16777 cx0 = (D * dy - dx * d) / d2,
16778 cy0 = (-D * dx - dy * d) / d2,
16779 cx1 = (D * dy + dx * d) / d2,
16780 cy1 = (-D * dx + dy * d) / d2,
16781 dx0 = cx0 - x00,
16782 dy0 = cy0 - y00,
16783 dx1 = cx1 - x00,
16784 dy1 = cy1 - y00;
16785
16786 // Pick the closer of the two intersection points.
16787 // TODO Is there a faster way to determine which intersection to use?
16788 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
16789
16790 return {
16791 cx: cx0,
16792 cy: cy0,
16793 x01: -ox,
16794 y01: -oy,
16795 x11: cx0 * (r1 / r - 1),
16796 y11: cy0 * (r1 / r - 1)
16797 };
16798}
16799
16800function arc() {
16801 var innerRadius = arcInnerRadius,
16802 outerRadius = arcOuterRadius,
16803 cornerRadius = constant$1(0),
16804 padRadius = null,
16805 startAngle = arcStartAngle,
16806 endAngle = arcEndAngle,
16807 padAngle = arcPadAngle,
16808 context = null;
16809
16810 function arc() {
16811 var buffer,
16812 r,
16813 r0 = +innerRadius.apply(this, arguments),
16814 r1 = +outerRadius.apply(this, arguments),
16815 a0 = startAngle.apply(this, arguments) - halfPi,
16816 a1 = endAngle.apply(this, arguments) - halfPi,
16817 da = abs(a1 - a0),
16818 cw = a1 > a0;
16819
16820 if (!context) context = buffer = path();
16821
16822 // Ensure that the outer radius is always larger than the inner radius.
16823 if (r1 < r0) r = r1, r1 = r0, r0 = r;
16824
16825 // Is it a point?
16826 if (!(r1 > epsilon)) context.moveTo(0, 0);
16827
16828 // Or is it a circle or annulus?
16829 else if (da > tau - epsilon) {
16830 context.moveTo(r1 * cos(a0), r1 * sin(a0));
16831 context.arc(0, 0, r1, a0, a1, !cw);
16832 if (r0 > epsilon) {
16833 context.moveTo(r0 * cos(a1), r0 * sin(a1));
16834 context.arc(0, 0, r0, a1, a0, cw);
16835 }
16836 }
16837
16838 // Or is it a circular or annular sector?
16839 else {
16840 var a01 = a0,
16841 a11 = a1,
16842 a00 = a0,
16843 a10 = a1,
16844 da0 = da,
16845 da1 = da,
16846 ap = padAngle.apply(this, arguments) / 2,
16847 rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),
16848 rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
16849 rc0 = rc,
16850 rc1 = rc,
16851 t0,
16852 t1;
16853
16854 // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
16855 if (rp > epsilon) {
16856 var p0 = asin(rp / r0 * sin(ap)),
16857 p1 = asin(rp / r1 * sin(ap));
16858 if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
16859 else da0 = 0, a00 = a10 = (a0 + a1) / 2;
16860 if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
16861 else da1 = 0, a01 = a11 = (a0 + a1) / 2;
16862 }
16863
16864 var x01 = r1 * cos(a01),
16865 y01 = r1 * sin(a01),
16866 x10 = r0 * cos(a10),
16867 y10 = r0 * sin(a10);
16868
16869 // Apply rounded corners?
16870 if (rc > epsilon) {
16871 var x11 = r1 * cos(a11),
16872 y11 = r1 * sin(a11),
16873 x00 = r0 * cos(a00),
16874 y00 = r0 * sin(a00),
16875 oc;
16876
16877 // Restrict the corner radius according to the sector angle.
16878 if (da < pi && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
16879 var ax = x01 - oc[0],
16880 ay = y01 - oc[1],
16881 bx = x11 - oc[0],
16882 by = y11 - oc[1],
16883 kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),
16884 lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
16885 rc0 = min(rc, (r0 - lc) / (kc - 1));
16886 rc1 = min(rc, (r1 - lc) / (kc + 1));
16887 }
16888 }
16889
16890 // Is the sector collapsed to a line?
16891 if (!(da1 > epsilon)) context.moveTo(x01, y01);
16892
16893 // Does the sector’s outer ring have rounded corners?
16894 else if (rc1 > epsilon) {
16895 t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
16896 t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
16897
16898 context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
16899
16900 // Have the corners merged?
16901 if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
16902
16903 // Otherwise, draw the two corners and the ring.
16904 else {
16905 context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
16906 context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
16907 context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
16908 }
16909 }
16910
16911 // Or is the outer ring just a circular arc?
16912 else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
16913
16914 // Is there no inner ring, and it’s a circular sector?
16915 // Or perhaps it’s an annular sector collapsed due to padding?
16916 if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);
16917
16918 // Does the sector’s inner ring (or point) have rounded corners?
16919 else if (rc0 > epsilon) {
16920 t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
16921 t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
16922
16923 context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
16924
16925 // Have the corners merged?
16926 if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
16927
16928 // Otherwise, draw the two corners and the ring.
16929 else {
16930 context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
16931 context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
16932 context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
16933 }
16934 }
16935
16936 // Or is the inner ring just a circular arc?
16937 else context.arc(0, 0, r0, a10, a00, cw);
16938 }
16939
16940 context.closePath();
16941
16942 if (buffer) return context = null, buffer + "" || null;
16943 }
16944
16945 arc.centroid = function() {
16946 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
16947 a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
16948 return [cos(a) * r, sin(a) * r];
16949 };
16950
16951 arc.innerRadius = function(_) {
16952 return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : innerRadius;
16953 };
16954
16955 arc.outerRadius = function(_) {
16956 return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : outerRadius;
16957 };
16958
16959 arc.cornerRadius = function(_) {
16960 return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : cornerRadius;
16961 };
16962
16963 arc.padRadius = function(_) {
16964 return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), arc) : padRadius;
16965 };
16966
16967 arc.startAngle = function(_) {
16968 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : startAngle;
16969 };
16970
16971 arc.endAngle = function(_) {
16972 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : endAngle;
16973 };
16974
16975 arc.padAngle = function(_) {
16976 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : padAngle;
16977 };
16978
16979 arc.context = function(_) {
16980 return arguments.length ? ((context = _ == null ? null : _), arc) : context;
16981 };
16982
16983 return arc;
16984}
16985
16986var slice = Array.prototype.slice;
16987
16988function array(x) {
16989 return typeof x === "object" && "length" in x
16990 ? x // Array, TypedArray, NodeList, array-like
16991 : Array.from(x); // Map, Set, iterable, string, or anything else
16992}
16993
16994function Linear(context) {
16995 this._context = context;
16996}
16997
16998Linear.prototype = {
16999 areaStart: function() {
17000 this._line = 0;
17001 },
17002 areaEnd: function() {
17003 this._line = NaN;
17004 },
17005 lineStart: function() {
17006 this._point = 0;
17007 },
17008 lineEnd: function() {
17009 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
17010 this._line = 1 - this._line;
17011 },
17012 point: function(x, y) {
17013 x = +x, y = +y;
17014 switch (this._point) {
17015 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
17016 case 1: this._point = 2; // proceed
17017 default: this._context.lineTo(x, y); break;
17018 }
17019 }
17020};
17021
17022function curveLinear(context) {
17023 return new Linear(context);
17024}
17025
17026function x(p) {
17027 return p[0];
17028}
17029
17030function y(p) {
17031 return p[1];
17032}
17033
17034function line(x$1, y$1) {
17035 var defined = constant$1(true),
17036 context = null,
17037 curve = curveLinear,
17038 output = null;
17039
17040 x$1 = typeof x$1 === "function" ? x$1 : (x$1 === undefined) ? x : constant$1(x$1);
17041 y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant$1(y$1);
17042
17043 function line(data) {
17044 var i,
17045 n = (data = array(data)).length,
17046 d,
17047 defined0 = false,
17048 buffer;
17049
17050 if (context == null) output = curve(buffer = path());
17051
17052 for (i = 0; i <= n; ++i) {
17053 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
17054 if (defined0 = !defined0) output.lineStart();
17055 else output.lineEnd();
17056 }
17057 if (defined0) output.point(+x$1(d, i, data), +y$1(d, i, data));
17058 }
17059
17060 if (buffer) return output = null, buffer + "" || null;
17061 }
17062
17063 line.x = function(_) {
17064 return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), line) : x$1;
17065 };
17066
17067 line.y = function(_) {
17068 return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), line) : y$1;
17069 };
17070
17071 line.defined = function(_) {
17072 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), line) : defined;
17073 };
17074
17075 line.curve = function(_) {
17076 return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
17077 };
17078
17079 line.context = function(_) {
17080 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
17081 };
17082
17083 return line;
17084}
17085
17086function area(x0, y0, y1) {
17087 var x1 = null,
17088 defined = constant$1(true),
17089 context = null,
17090 curve = curveLinear,
17091 output = null;
17092
17093 x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x : constant$1(+x0);
17094 y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant$1(0) : constant$1(+y0);
17095 y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant$1(+y1);
17096
17097 function area(data) {
17098 var i,
17099 j,
17100 k,
17101 n = (data = array(data)).length,
17102 d,
17103 defined0 = false,
17104 buffer,
17105 x0z = new Array(n),
17106 y0z = new Array(n);
17107
17108 if (context == null) output = curve(buffer = path());
17109
17110 for (i = 0; i <= n; ++i) {
17111 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
17112 if (defined0 = !defined0) {
17113 j = i;
17114 output.areaStart();
17115 output.lineStart();
17116 } else {
17117 output.lineEnd();
17118 output.lineStart();
17119 for (k = i - 1; k >= j; --k) {
17120 output.point(x0z[k], y0z[k]);
17121 }
17122 output.lineEnd();
17123 output.areaEnd();
17124 }
17125 }
17126 if (defined0) {
17127 x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
17128 output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
17129 }
17130 }
17131
17132 if (buffer) return output = null, buffer + "" || null;
17133 }
17134
17135 function arealine() {
17136 return line().defined(defined).curve(curve).context(context);
17137 }
17138
17139 area.x = function(_) {
17140 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), x1 = null, area) : x0;
17141 };
17142
17143 area.x0 = function(_) {
17144 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), area) : x0;
17145 };
17146
17147 area.x1 = function(_) {
17148 return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : x1;
17149 };
17150
17151 area.y = function(_) {
17152 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), y1 = null, area) : y0;
17153 };
17154
17155 area.y0 = function(_) {
17156 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), area) : y0;
17157 };
17158
17159 area.y1 = function(_) {
17160 return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : y1;
17161 };
17162
17163 area.lineX0 =
17164 area.lineY0 = function() {
17165 return arealine().x(x0).y(y0);
17166 };
17167
17168 area.lineY1 = function() {
17169 return arealine().x(x0).y(y1);
17170 };
17171
17172 area.lineX1 = function() {
17173 return arealine().x(x1).y(y0);
17174 };
17175
17176 area.defined = function(_) {
17177 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), area) : defined;
17178 };
17179
17180 area.curve = function(_) {
17181 return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
17182 };
17183
17184 area.context = function(_) {
17185 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
17186 };
17187
17188 return area;
17189}
17190
17191function descending$1(a, b) {
17192 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
17193}
17194
17195function identity$1(d) {
17196 return d;
17197}
17198
17199function pie() {
17200 var value = identity$1,
17201 sortValues = descending$1,
17202 sort = null,
17203 startAngle = constant$1(0),
17204 endAngle = constant$1(tau),
17205 padAngle = constant$1(0);
17206
17207 function pie(data) {
17208 var i,
17209 n = (data = array(data)).length,
17210 j,
17211 k,
17212 sum = 0,
17213 index = new Array(n),
17214 arcs = new Array(n),
17215 a0 = +startAngle.apply(this, arguments),
17216 da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),
17217 a1,
17218 p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
17219 pa = p * (da < 0 ? -1 : 1),
17220 v;
17221
17222 for (i = 0; i < n; ++i) {
17223 if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
17224 sum += v;
17225 }
17226 }
17227
17228 // Optionally sort the arcs by previously-computed values or by data.
17229 if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
17230 else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
17231
17232 // Compute the arcs! They are stored in the original data's order.
17233 for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
17234 j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
17235 data: data[j],
17236 index: i,
17237 value: v,
17238 startAngle: a0,
17239 endAngle: a1,
17240 padAngle: p
17241 };
17242 }
17243
17244 return arcs;
17245 }
17246
17247 pie.value = function(_) {
17248 return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value;
17249 };
17250
17251 pie.sortValues = function(_) {
17252 return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
17253 };
17254
17255 pie.sort = function(_) {
17256 return arguments.length ? (sort = _, sortValues = null, pie) : sort;
17257 };
17258
17259 pie.startAngle = function(_) {
17260 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : startAngle;
17261 };
17262
17263 pie.endAngle = function(_) {
17264 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : endAngle;
17265 };
17266
17267 pie.padAngle = function(_) {
17268 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : padAngle;
17269 };
17270
17271 return pie;
17272}
17273
17274var curveRadialLinear = curveRadial$1(curveLinear);
17275
17276function Radial(curve) {
17277 this._curve = curve;
17278}
17279
17280Radial.prototype = {
17281 areaStart: function() {
17282 this._curve.areaStart();
17283 },
17284 areaEnd: function() {
17285 this._curve.areaEnd();
17286 },
17287 lineStart: function() {
17288 this._curve.lineStart();
17289 },
17290 lineEnd: function() {
17291 this._curve.lineEnd();
17292 },
17293 point: function(a, r) {
17294 this._curve.point(r * Math.sin(a), r * -Math.cos(a));
17295 }
17296};
17297
17298function curveRadial$1(curve) {
17299
17300 function radial(context) {
17301 return new Radial(curve(context));
17302 }
17303
17304 radial._curve = curve;
17305
17306 return radial;
17307}
17308
17309function lineRadial(l) {
17310 var c = l.curve;
17311
17312 l.angle = l.x, delete l.x;
17313 l.radius = l.y, delete l.y;
17314
17315 l.curve = function(_) {
17316 return arguments.length ? c(curveRadial$1(_)) : c()._curve;
17317 };
17318
17319 return l;
17320}
17321
17322function lineRadial$1() {
17323 return lineRadial(line().curve(curveRadialLinear));
17324}
17325
17326function areaRadial() {
17327 var a = area().curve(curveRadialLinear),
17328 c = a.curve,
17329 x0 = a.lineX0,
17330 x1 = a.lineX1,
17331 y0 = a.lineY0,
17332 y1 = a.lineY1;
17333
17334 a.angle = a.x, delete a.x;
17335 a.startAngle = a.x0, delete a.x0;
17336 a.endAngle = a.x1, delete a.x1;
17337 a.radius = a.y, delete a.y;
17338 a.innerRadius = a.y0, delete a.y0;
17339 a.outerRadius = a.y1, delete a.y1;
17340 a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
17341 a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
17342 a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
17343 a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
17344
17345 a.curve = function(_) {
17346 return arguments.length ? c(curveRadial$1(_)) : c()._curve;
17347 };
17348
17349 return a;
17350}
17351
17352function pointRadial(x, y) {
17353 return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
17354}
17355
17356function linkSource(d) {
17357 return d.source;
17358}
17359
17360function linkTarget(d) {
17361 return d.target;
17362}
17363
17364function link(curve) {
17365 var source = linkSource,
17366 target = linkTarget,
17367 x$1 = x,
17368 y$1 = y,
17369 context = null;
17370
17371 function link() {
17372 var buffer, argv = slice.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
17373 if (!context) context = buffer = path();
17374 curve(context, +x$1.apply(this, (argv[0] = s, argv)), +y$1.apply(this, argv), +x$1.apply(this, (argv[0] = t, argv)), +y$1.apply(this, argv));
17375 if (buffer) return context = null, buffer + "" || null;
17376 }
17377
17378 link.source = function(_) {
17379 return arguments.length ? (source = _, link) : source;
17380 };
17381
17382 link.target = function(_) {
17383 return arguments.length ? (target = _, link) : target;
17384 };
17385
17386 link.x = function(_) {
17387 return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), link) : x$1;
17388 };
17389
17390 link.y = function(_) {
17391 return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), link) : y$1;
17392 };
17393
17394 link.context = function(_) {
17395 return arguments.length ? ((context = _ == null ? null : _), link) : context;
17396 };
17397
17398 return link;
17399}
17400
17401function curveHorizontal(context, x0, y0, x1, y1) {
17402 context.moveTo(x0, y0);
17403 context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
17404}
17405
17406function curveVertical(context, x0, y0, x1, y1) {
17407 context.moveTo(x0, y0);
17408 context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
17409}
17410
17411function curveRadial(context, x0, y0, x1, y1) {
17412 var p0 = pointRadial(x0, y0),
17413 p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
17414 p2 = pointRadial(x1, y0),
17415 p3 = pointRadial(x1, y1);
17416 context.moveTo(p0[0], p0[1]);
17417 context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
17418}
17419
17420function linkHorizontal() {
17421 return link(curveHorizontal);
17422}
17423
17424function linkVertical() {
17425 return link(curveVertical);
17426}
17427
17428function linkRadial() {
17429 var l = link(curveRadial);
17430 l.angle = l.x, delete l.x;
17431 l.radius = l.y, delete l.y;
17432 return l;
17433}
17434
17435var circle = {
17436 draw: function(context, size) {
17437 var r = Math.sqrt(size / pi);
17438 context.moveTo(r, 0);
17439 context.arc(0, 0, r, 0, tau);
17440 }
17441};
17442
17443var cross = {
17444 draw: function(context, size) {
17445 var r = Math.sqrt(size / 5) / 2;
17446 context.moveTo(-3 * r, -r);
17447 context.lineTo(-r, -r);
17448 context.lineTo(-r, -3 * r);
17449 context.lineTo(r, -3 * r);
17450 context.lineTo(r, -r);
17451 context.lineTo(3 * r, -r);
17452 context.lineTo(3 * r, r);
17453 context.lineTo(r, r);
17454 context.lineTo(r, 3 * r);
17455 context.lineTo(-r, 3 * r);
17456 context.lineTo(-r, r);
17457 context.lineTo(-3 * r, r);
17458 context.closePath();
17459 }
17460};
17461
17462var tan30 = Math.sqrt(1 / 3),
17463 tan30_2 = tan30 * 2;
17464
17465var diamond = {
17466 draw: function(context, size) {
17467 var y = Math.sqrt(size / tan30_2),
17468 x = y * tan30;
17469 context.moveTo(0, -y);
17470 context.lineTo(x, 0);
17471 context.lineTo(0, y);
17472 context.lineTo(-x, 0);
17473 context.closePath();
17474 }
17475};
17476
17477var ka = 0.89081309152928522810,
17478 kr = Math.sin(pi / 10) / Math.sin(7 * pi / 10),
17479 kx = Math.sin(tau / 10) * kr,
17480 ky = -Math.cos(tau / 10) * kr;
17481
17482var star = {
17483 draw: function(context, size) {
17484 var r = Math.sqrt(size * ka),
17485 x = kx * r,
17486 y = ky * r;
17487 context.moveTo(0, -r);
17488 context.lineTo(x, y);
17489 for (var i = 1; i < 5; ++i) {
17490 var a = tau * i / 5,
17491 c = Math.cos(a),
17492 s = Math.sin(a);
17493 context.lineTo(s * r, -c * r);
17494 context.lineTo(c * x - s * y, s * x + c * y);
17495 }
17496 context.closePath();
17497 }
17498};
17499
17500var square = {
17501 draw: function(context, size) {
17502 var w = Math.sqrt(size),
17503 x = -w / 2;
17504 context.rect(x, x, w, w);
17505 }
17506};
17507
17508var sqrt3 = Math.sqrt(3);
17509
17510var triangle = {
17511 draw: function(context, size) {
17512 var y = -Math.sqrt(size / (sqrt3 * 3));
17513 context.moveTo(0, y * 2);
17514 context.lineTo(-sqrt3 * y, -y);
17515 context.lineTo(sqrt3 * y, -y);
17516 context.closePath();
17517 }
17518};
17519
17520var c = -0.5,
17521 s = Math.sqrt(3) / 2,
17522 k = 1 / Math.sqrt(12),
17523 a = (k / 2 + 1) * 3;
17524
17525var wye = {
17526 draw: function(context, size) {
17527 var r = Math.sqrt(size / a),
17528 x0 = r / 2,
17529 y0 = r * k,
17530 x1 = x0,
17531 y1 = r * k + r,
17532 x2 = -x1,
17533 y2 = y1;
17534 context.moveTo(x0, y0);
17535 context.lineTo(x1, y1);
17536 context.lineTo(x2, y2);
17537 context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
17538 context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
17539 context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
17540 context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
17541 context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
17542 context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
17543 context.closePath();
17544 }
17545};
17546
17547var symbols = [
17548 circle,
17549 cross,
17550 diamond,
17551 square,
17552 star,
17553 triangle,
17554 wye
17555];
17556
17557function symbol(type, size) {
17558 var context = null;
17559 type = typeof type === "function" ? type : constant$1(type || circle);
17560 size = typeof size === "function" ? size : constant$1(size === undefined ? 64 : +size);
17561
17562 function symbol() {
17563 var buffer;
17564 if (!context) context = buffer = path();
17565 type.apply(this, arguments).draw(context, +size.apply(this, arguments));
17566 if (buffer) return context = null, buffer + "" || null;
17567 }
17568
17569 symbol.type = function(_) {
17570 return arguments.length ? (type = typeof _ === "function" ? _ : constant$1(_), symbol) : type;
17571 };
17572
17573 symbol.size = function(_) {
17574 return arguments.length ? (size = typeof _ === "function" ? _ : constant$1(+_), symbol) : size;
17575 };
17576
17577 symbol.context = function(_) {
17578 return arguments.length ? (context = _ == null ? null : _, symbol) : context;
17579 };
17580
17581 return symbol;
17582}
17583
17584function noop() {}
17585
17586function point$3(that, x, y) {
17587 that._context.bezierCurveTo(
17588 (2 * that._x0 + that._x1) / 3,
17589 (2 * that._y0 + that._y1) / 3,
17590 (that._x0 + 2 * that._x1) / 3,
17591 (that._y0 + 2 * that._y1) / 3,
17592 (that._x0 + 4 * that._x1 + x) / 6,
17593 (that._y0 + 4 * that._y1 + y) / 6
17594 );
17595}
17596
17597function Basis(context) {
17598 this._context = context;
17599}
17600
17601Basis.prototype = {
17602 areaStart: function() {
17603 this._line = 0;
17604 },
17605 areaEnd: function() {
17606 this._line = NaN;
17607 },
17608 lineStart: function() {
17609 this._x0 = this._x1 =
17610 this._y0 = this._y1 = NaN;
17611 this._point = 0;
17612 },
17613 lineEnd: function() {
17614 switch (this._point) {
17615 case 3: point$3(this, this._x1, this._y1); // proceed
17616 case 2: this._context.lineTo(this._x1, this._y1); break;
17617 }
17618 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
17619 this._line = 1 - this._line;
17620 },
17621 point: function(x, y) {
17622 x = +x, y = +y;
17623 switch (this._point) {
17624 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
17625 case 1: this._point = 2; break;
17626 case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
17627 default: point$3(this, x, y); break;
17628 }
17629 this._x0 = this._x1, this._x1 = x;
17630 this._y0 = this._y1, this._y1 = y;
17631 }
17632};
17633
17634function basis(context) {
17635 return new Basis(context);
17636}
17637
17638function BasisClosed(context) {
17639 this._context = context;
17640}
17641
17642BasisClosed.prototype = {
17643 areaStart: noop,
17644 areaEnd: noop,
17645 lineStart: function() {
17646 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
17647 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
17648 this._point = 0;
17649 },
17650 lineEnd: function() {
17651 switch (this._point) {
17652 case 1: {
17653 this._context.moveTo(this._x2, this._y2);
17654 this._context.closePath();
17655 break;
17656 }
17657 case 2: {
17658 this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
17659 this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
17660 this._context.closePath();
17661 break;
17662 }
17663 case 3: {
17664 this.point(this._x2, this._y2);
17665 this.point(this._x3, this._y3);
17666 this.point(this._x4, this._y4);
17667 break;
17668 }
17669 }
17670 },
17671 point: function(x, y) {
17672 x = +x, y = +y;
17673 switch (this._point) {
17674 case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
17675 case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
17676 case 2: this._point = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
17677 default: point$3(this, x, y); break;
17678 }
17679 this._x0 = this._x1, this._x1 = x;
17680 this._y0 = this._y1, this._y1 = y;
17681 }
17682};
17683
17684function basisClosed(context) {
17685 return new BasisClosed(context);
17686}
17687
17688function BasisOpen(context) {
17689 this._context = context;
17690}
17691
17692BasisOpen.prototype = {
17693 areaStart: function() {
17694 this._line = 0;
17695 },
17696 areaEnd: function() {
17697 this._line = NaN;
17698 },
17699 lineStart: function() {
17700 this._x0 = this._x1 =
17701 this._y0 = this._y1 = NaN;
17702 this._point = 0;
17703 },
17704 lineEnd: function() {
17705 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
17706 this._line = 1 - this._line;
17707 },
17708 point: function(x, y) {
17709 x = +x, y = +y;
17710 switch (this._point) {
17711 case 0: this._point = 1; break;
17712 case 1: this._point = 2; break;
17713 case 2: this._point = 3; var x0 = (this._x0 + 4 * this._x1 + x) / 6, y0 = (this._y0 + 4 * this._y1 + y) / 6; this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0); break;
17714 case 3: this._point = 4; // proceed
17715 default: point$3(this, x, y); break;
17716 }
17717 this._x0 = this._x1, this._x1 = x;
17718 this._y0 = this._y1, this._y1 = y;
17719 }
17720};
17721
17722function basisOpen(context) {
17723 return new BasisOpen(context);
17724}
17725
17726class Bump {
17727 constructor(context, x) {
17728 this._context = context;
17729 this._x = x;
17730 }
17731 areaStart() {
17732 this._line = 0;
17733 }
17734 areaEnd() {
17735 this._line = NaN;
17736 }
17737 lineStart() {
17738 this._point = 0;
17739 }
17740 lineEnd() {
17741 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
17742 this._line = 1 - this._line;
17743 }
17744 point(x, y) {
17745 x = +x, y = +y;
17746 switch (this._point) {
17747 case 0: {
17748 this._point = 1;
17749 if (this._line) this._context.lineTo(x, y);
17750 else this._context.moveTo(x, y);
17751 break;
17752 }
17753 case 1: this._point = 2; // proceed
17754 default: {
17755 if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
17756 else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
17757 break;
17758 }
17759 }
17760 this._x0 = x, this._y0 = y;
17761 }
17762}
17763
17764function bumpX(context) {
17765 return new Bump(context, true);
17766}
17767
17768function bumpY(context) {
17769 return new Bump(context, false);
17770}
17771
17772function Bundle(context, beta) {
17773 this._basis = new Basis(context);
17774 this._beta = beta;
17775}
17776
17777Bundle.prototype = {
17778 lineStart: function() {
17779 this._x = [];
17780 this._y = [];
17781 this._basis.lineStart();
17782 },
17783 lineEnd: function() {
17784 var x = this._x,
17785 y = this._y,
17786 j = x.length - 1;
17787
17788 if (j > 0) {
17789 var x0 = x[0],
17790 y0 = y[0],
17791 dx = x[j] - x0,
17792 dy = y[j] - y0,
17793 i = -1,
17794 t;
17795
17796 while (++i <= j) {
17797 t = i / j;
17798 this._basis.point(
17799 this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
17800 this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
17801 );
17802 }
17803 }
17804
17805 this._x = this._y = null;
17806 this._basis.lineEnd();
17807 },
17808 point: function(x, y) {
17809 this._x.push(+x);
17810 this._y.push(+y);
17811 }
17812};
17813
17814var bundle = (function custom(beta) {
17815
17816 function bundle(context) {
17817 return beta === 1 ? new Basis(context) : new Bundle(context, beta);
17818 }
17819
17820 bundle.beta = function(beta) {
17821 return custom(+beta);
17822 };
17823
17824 return bundle;
17825})(0.85);
17826
17827function point$2(that, x, y) {
17828 that._context.bezierCurveTo(
17829 that._x1 + that._k * (that._x2 - that._x0),
17830 that._y1 + that._k * (that._y2 - that._y0),
17831 that._x2 + that._k * (that._x1 - x),
17832 that._y2 + that._k * (that._y1 - y),
17833 that._x2,
17834 that._y2
17835 );
17836}
17837
17838function Cardinal(context, tension) {
17839 this._context = context;
17840 this._k = (1 - tension) / 6;
17841}
17842
17843Cardinal.prototype = {
17844 areaStart: function() {
17845 this._line = 0;
17846 },
17847 areaEnd: function() {
17848 this._line = NaN;
17849 },
17850 lineStart: function() {
17851 this._x0 = this._x1 = this._x2 =
17852 this._y0 = this._y1 = this._y2 = NaN;
17853 this._point = 0;
17854 },
17855 lineEnd: function() {
17856 switch (this._point) {
17857 case 2: this._context.lineTo(this._x2, this._y2); break;
17858 case 3: point$2(this, this._x1, this._y1); break;
17859 }
17860 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
17861 this._line = 1 - this._line;
17862 },
17863 point: function(x, y) {
17864 x = +x, y = +y;
17865 switch (this._point) {
17866 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
17867 case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
17868 case 2: this._point = 3; // proceed
17869 default: point$2(this, x, y); break;
17870 }
17871 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
17872 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
17873 }
17874};
17875
17876var cardinal = (function custom(tension) {
17877
17878 function cardinal(context) {
17879 return new Cardinal(context, tension);
17880 }
17881
17882 cardinal.tension = function(tension) {
17883 return custom(+tension);
17884 };
17885
17886 return cardinal;
17887})(0);
17888
17889function CardinalClosed(context, tension) {
17890 this._context = context;
17891 this._k = (1 - tension) / 6;
17892}
17893
17894CardinalClosed.prototype = {
17895 areaStart: noop,
17896 areaEnd: noop,
17897 lineStart: function() {
17898 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
17899 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
17900 this._point = 0;
17901 },
17902 lineEnd: function() {
17903 switch (this._point) {
17904 case 1: {
17905 this._context.moveTo(this._x3, this._y3);
17906 this._context.closePath();
17907 break;
17908 }
17909 case 2: {
17910 this._context.lineTo(this._x3, this._y3);
17911 this._context.closePath();
17912 break;
17913 }
17914 case 3: {
17915 this.point(this._x3, this._y3);
17916 this.point(this._x4, this._y4);
17917 this.point(this._x5, this._y5);
17918 break;
17919 }
17920 }
17921 },
17922 point: function(x, y) {
17923 x = +x, y = +y;
17924 switch (this._point) {
17925 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
17926 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
17927 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
17928 default: point$2(this, x, y); break;
17929 }
17930 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
17931 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
17932 }
17933};
17934
17935var cardinalClosed = (function custom(tension) {
17936
17937 function cardinal(context) {
17938 return new CardinalClosed(context, tension);
17939 }
17940
17941 cardinal.tension = function(tension) {
17942 return custom(+tension);
17943 };
17944
17945 return cardinal;
17946})(0);
17947
17948function CardinalOpen(context, tension) {
17949 this._context = context;
17950 this._k = (1 - tension) / 6;
17951}
17952
17953CardinalOpen.prototype = {
17954 areaStart: function() {
17955 this._line = 0;
17956 },
17957 areaEnd: function() {
17958 this._line = NaN;
17959 },
17960 lineStart: function() {
17961 this._x0 = this._x1 = this._x2 =
17962 this._y0 = this._y1 = this._y2 = NaN;
17963 this._point = 0;
17964 },
17965 lineEnd: function() {
17966 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
17967 this._line = 1 - this._line;
17968 },
17969 point: function(x, y) {
17970 x = +x, y = +y;
17971 switch (this._point) {
17972 case 0: this._point = 1; break;
17973 case 1: this._point = 2; break;
17974 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
17975 case 3: this._point = 4; // proceed
17976 default: point$2(this, x, y); break;
17977 }
17978 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
17979 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
17980 }
17981};
17982
17983var cardinalOpen = (function custom(tension) {
17984
17985 function cardinal(context) {
17986 return new CardinalOpen(context, tension);
17987 }
17988
17989 cardinal.tension = function(tension) {
17990 return custom(+tension);
17991 };
17992
17993 return cardinal;
17994})(0);
17995
17996function point$1(that, x, y) {
17997 var x1 = that._x1,
17998 y1 = that._y1,
17999 x2 = that._x2,
18000 y2 = that._y2;
18001
18002 if (that._l01_a > epsilon) {
18003 var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
18004 n = 3 * that._l01_a * (that._l01_a + that._l12_a);
18005 x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
18006 y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
18007 }
18008
18009 if (that._l23_a > epsilon) {
18010 var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
18011 m = 3 * that._l23_a * (that._l23_a + that._l12_a);
18012 x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
18013 y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
18014 }
18015
18016 that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
18017}
18018
18019function CatmullRom(context, alpha) {
18020 this._context = context;
18021 this._alpha = alpha;
18022}
18023
18024CatmullRom.prototype = {
18025 areaStart: function() {
18026 this._line = 0;
18027 },
18028 areaEnd: function() {
18029 this._line = NaN;
18030 },
18031 lineStart: function() {
18032 this._x0 = this._x1 = this._x2 =
18033 this._y0 = this._y1 = this._y2 = NaN;
18034 this._l01_a = this._l12_a = this._l23_a =
18035 this._l01_2a = this._l12_2a = this._l23_2a =
18036 this._point = 0;
18037 },
18038 lineEnd: function() {
18039 switch (this._point) {
18040 case 2: this._context.lineTo(this._x2, this._y2); break;
18041 case 3: this.point(this._x2, this._y2); break;
18042 }
18043 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
18044 this._line = 1 - this._line;
18045 },
18046 point: function(x, y) {
18047 x = +x, y = +y;
18048
18049 if (this._point) {
18050 var x23 = this._x2 - x,
18051 y23 = this._y2 - y;
18052 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
18053 }
18054
18055 switch (this._point) {
18056 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
18057 case 1: this._point = 2; break;
18058 case 2: this._point = 3; // proceed
18059 default: point$1(this, x, y); break;
18060 }
18061
18062 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
18063 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
18064 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
18065 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
18066 }
18067};
18068
18069var catmullRom = (function custom(alpha) {
18070
18071 function catmullRom(context) {
18072 return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
18073 }
18074
18075 catmullRom.alpha = function(alpha) {
18076 return custom(+alpha);
18077 };
18078
18079 return catmullRom;
18080})(0.5);
18081
18082function CatmullRomClosed(context, alpha) {
18083 this._context = context;
18084 this._alpha = alpha;
18085}
18086
18087CatmullRomClosed.prototype = {
18088 areaStart: noop,
18089 areaEnd: noop,
18090 lineStart: function() {
18091 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
18092 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
18093 this._l01_a = this._l12_a = this._l23_a =
18094 this._l01_2a = this._l12_2a = this._l23_2a =
18095 this._point = 0;
18096 },
18097 lineEnd: function() {
18098 switch (this._point) {
18099 case 1: {
18100 this._context.moveTo(this._x3, this._y3);
18101 this._context.closePath();
18102 break;
18103 }
18104 case 2: {
18105 this._context.lineTo(this._x3, this._y3);
18106 this._context.closePath();
18107 break;
18108 }
18109 case 3: {
18110 this.point(this._x3, this._y3);
18111 this.point(this._x4, this._y4);
18112 this.point(this._x5, this._y5);
18113 break;
18114 }
18115 }
18116 },
18117 point: function(x, y) {
18118 x = +x, y = +y;
18119
18120 if (this._point) {
18121 var x23 = this._x2 - x,
18122 y23 = this._y2 - y;
18123 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
18124 }
18125
18126 switch (this._point) {
18127 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
18128 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
18129 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
18130 default: point$1(this, x, y); break;
18131 }
18132
18133 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
18134 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
18135 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
18136 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
18137 }
18138};
18139
18140var catmullRomClosed = (function custom(alpha) {
18141
18142 function catmullRom(context) {
18143 return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
18144 }
18145
18146 catmullRom.alpha = function(alpha) {
18147 return custom(+alpha);
18148 };
18149
18150 return catmullRom;
18151})(0.5);
18152
18153function CatmullRomOpen(context, alpha) {
18154 this._context = context;
18155 this._alpha = alpha;
18156}
18157
18158CatmullRomOpen.prototype = {
18159 areaStart: function() {
18160 this._line = 0;
18161 },
18162 areaEnd: function() {
18163 this._line = NaN;
18164 },
18165 lineStart: function() {
18166 this._x0 = this._x1 = this._x2 =
18167 this._y0 = this._y1 = this._y2 = NaN;
18168 this._l01_a = this._l12_a = this._l23_a =
18169 this._l01_2a = this._l12_2a = this._l23_2a =
18170 this._point = 0;
18171 },
18172 lineEnd: function() {
18173 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
18174 this._line = 1 - this._line;
18175 },
18176 point: function(x, y) {
18177 x = +x, y = +y;
18178
18179 if (this._point) {
18180 var x23 = this._x2 - x,
18181 y23 = this._y2 - y;
18182 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
18183 }
18184
18185 switch (this._point) {
18186 case 0: this._point = 1; break;
18187 case 1: this._point = 2; break;
18188 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
18189 case 3: this._point = 4; // proceed
18190 default: point$1(this, x, y); break;
18191 }
18192
18193 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
18194 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
18195 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
18196 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
18197 }
18198};
18199
18200var catmullRomOpen = (function custom(alpha) {
18201
18202 function catmullRom(context) {
18203 return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
18204 }
18205
18206 catmullRom.alpha = function(alpha) {
18207 return custom(+alpha);
18208 };
18209
18210 return catmullRom;
18211})(0.5);
18212
18213function LinearClosed(context) {
18214 this._context = context;
18215}
18216
18217LinearClosed.prototype = {
18218 areaStart: noop,
18219 areaEnd: noop,
18220 lineStart: function() {
18221 this._point = 0;
18222 },
18223 lineEnd: function() {
18224 if (this._point) this._context.closePath();
18225 },
18226 point: function(x, y) {
18227 x = +x, y = +y;
18228 if (this._point) this._context.lineTo(x, y);
18229 else this._point = 1, this._context.moveTo(x, y);
18230 }
18231};
18232
18233function linearClosed(context) {
18234 return new LinearClosed(context);
18235}
18236
18237function sign(x) {
18238 return x < 0 ? -1 : 1;
18239}
18240
18241// Calculate the slopes of the tangents (Hermite-type interpolation) based on
18242// the following paper: Steffen, M. 1990. A Simple Method for Monotonic
18243// Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
18244// NOV(II), P. 443, 1990.
18245function slope3(that, x2, y2) {
18246 var h0 = that._x1 - that._x0,
18247 h1 = x2 - that._x1,
18248 s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
18249 s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
18250 p = (s0 * h1 + s1 * h0) / (h0 + h1);
18251 return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
18252}
18253
18254// Calculate a one-sided slope.
18255function slope2(that, t) {
18256 var h = that._x1 - that._x0;
18257 return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
18258}
18259
18260// According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
18261// "you can express cubic Hermite interpolation in terms of cubic Bézier curves
18262// with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
18263function point(that, t0, t1) {
18264 var x0 = that._x0,
18265 y0 = that._y0,
18266 x1 = that._x1,
18267 y1 = that._y1,
18268 dx = (x1 - x0) / 3;
18269 that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
18270}
18271
18272function MonotoneX(context) {
18273 this._context = context;
18274}
18275
18276MonotoneX.prototype = {
18277 areaStart: function() {
18278 this._line = 0;
18279 },
18280 areaEnd: function() {
18281 this._line = NaN;
18282 },
18283 lineStart: function() {
18284 this._x0 = this._x1 =
18285 this._y0 = this._y1 =
18286 this._t0 = NaN;
18287 this._point = 0;
18288 },
18289 lineEnd: function() {
18290 switch (this._point) {
18291 case 2: this._context.lineTo(this._x1, this._y1); break;
18292 case 3: point(this, this._t0, slope2(this, this._t0)); break;
18293 }
18294 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
18295 this._line = 1 - this._line;
18296 },
18297 point: function(x, y) {
18298 var t1 = NaN;
18299
18300 x = +x, y = +y;
18301 if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
18302 switch (this._point) {
18303 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
18304 case 1: this._point = 2; break;
18305 case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
18306 default: point(this, this._t0, t1 = slope3(this, x, y)); break;
18307 }
18308
18309 this._x0 = this._x1, this._x1 = x;
18310 this._y0 = this._y1, this._y1 = y;
18311 this._t0 = t1;
18312 }
18313};
18314
18315function MonotoneY(context) {
18316 this._context = new ReflectContext(context);
18317}
18318
18319(MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
18320 MonotoneX.prototype.point.call(this, y, x);
18321};
18322
18323function ReflectContext(context) {
18324 this._context = context;
18325}
18326
18327ReflectContext.prototype = {
18328 moveTo: function(x, y) { this._context.moveTo(y, x); },
18329 closePath: function() { this._context.closePath(); },
18330 lineTo: function(x, y) { this._context.lineTo(y, x); },
18331 bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
18332};
18333
18334function monotoneX(context) {
18335 return new MonotoneX(context);
18336}
18337
18338function monotoneY(context) {
18339 return new MonotoneY(context);
18340}
18341
18342function Natural(context) {
18343 this._context = context;
18344}
18345
18346Natural.prototype = {
18347 areaStart: function() {
18348 this._line = 0;
18349 },
18350 areaEnd: function() {
18351 this._line = NaN;
18352 },
18353 lineStart: function() {
18354 this._x = [];
18355 this._y = [];
18356 },
18357 lineEnd: function() {
18358 var x = this._x,
18359 y = this._y,
18360 n = x.length;
18361
18362 if (n) {
18363 this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
18364 if (n === 2) {
18365 this._context.lineTo(x[1], y[1]);
18366 } else {
18367 var px = controlPoints(x),
18368 py = controlPoints(y);
18369 for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
18370 this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
18371 }
18372 }
18373 }
18374
18375 if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
18376 this._line = 1 - this._line;
18377 this._x = this._y = null;
18378 },
18379 point: function(x, y) {
18380 this._x.push(+x);
18381 this._y.push(+y);
18382 }
18383};
18384
18385// See https://www.particleincell.com/2012/bezier-splines/ for derivation.
18386function controlPoints(x) {
18387 var i,
18388 n = x.length - 1,
18389 m,
18390 a = new Array(n),
18391 b = new Array(n),
18392 r = new Array(n);
18393 a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
18394 for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
18395 a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
18396 for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
18397 a[n - 1] = r[n - 1] / b[n - 1];
18398 for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
18399 b[n - 1] = (x[n] + a[n - 1]) / 2;
18400 for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
18401 return [a, b];
18402}
18403
18404function natural(context) {
18405 return new Natural(context);
18406}
18407
18408function Step(context, t) {
18409 this._context = context;
18410 this._t = t;
18411}
18412
18413Step.prototype = {
18414 areaStart: function() {
18415 this._line = 0;
18416 },
18417 areaEnd: function() {
18418 this._line = NaN;
18419 },
18420 lineStart: function() {
18421 this._x = this._y = NaN;
18422 this._point = 0;
18423 },
18424 lineEnd: function() {
18425 if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
18426 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
18427 if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
18428 },
18429 point: function(x, y) {
18430 x = +x, y = +y;
18431 switch (this._point) {
18432 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
18433 case 1: this._point = 2; // proceed
18434 default: {
18435 if (this._t <= 0) {
18436 this._context.lineTo(this._x, y);
18437 this._context.lineTo(x, y);
18438 } else {
18439 var x1 = this._x * (1 - this._t) + x * this._t;
18440 this._context.lineTo(x1, this._y);
18441 this._context.lineTo(x1, y);
18442 }
18443 break;
18444 }
18445 }
18446 this._x = x, this._y = y;
18447 }
18448};
18449
18450function step(context) {
18451 return new Step(context, 0.5);
18452}
18453
18454function stepBefore(context) {
18455 return new Step(context, 0);
18456}
18457
18458function stepAfter(context) {
18459 return new Step(context, 1);
18460}
18461
18462function none$1(series, order) {
18463 if (!((n = series.length) > 1)) return;
18464 for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
18465 s0 = s1, s1 = series[order[i]];
18466 for (j = 0; j < m; ++j) {
18467 s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
18468 }
18469 }
18470}
18471
18472function none(series) {
18473 var n = series.length, o = new Array(n);
18474 while (--n >= 0) o[n] = n;
18475 return o;
18476}
18477
18478function stackValue(d, key) {
18479 return d[key];
18480}
18481
18482function stackSeries(key) {
18483 const series = [];
18484 series.key = key;
18485 return series;
18486}
18487
18488function stack() {
18489 var keys = constant$1([]),
18490 order = none,
18491 offset = none$1,
18492 value = stackValue;
18493
18494 function stack(data) {
18495 var sz = Array.from(keys.apply(this, arguments), stackSeries),
18496 i, n = sz.length, j = -1,
18497 oz;
18498
18499 for (const d of data) {
18500 for (i = 0, ++j; i < n; ++i) {
18501 (sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
18502 }
18503 }
18504
18505 for (i = 0, oz = array(order(sz)); i < n; ++i) {
18506 sz[oz[i]].index = i;
18507 }
18508
18509 offset(sz, oz);
18510 return sz;
18511 }
18512
18513 stack.keys = function(_) {
18514 return arguments.length ? (keys = typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : keys;
18515 };
18516
18517 stack.value = function(_) {
18518 return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), stack) : value;
18519 };
18520
18521 stack.order = function(_) {
18522 return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : order;
18523 };
18524
18525 stack.offset = function(_) {
18526 return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
18527 };
18528
18529 return stack;
18530}
18531
18532function expand(series, order) {
18533 if (!((n = series.length) > 0)) return;
18534 for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
18535 for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
18536 if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
18537 }
18538 none$1(series, order);
18539}
18540
18541function diverging(series, order) {
18542 if (!((n = series.length) > 0)) return;
18543 for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
18544 for (yp = yn = 0, i = 0; i < n; ++i) {
18545 if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
18546 d[0] = yp, d[1] = yp += dy;
18547 } else if (dy < 0) {
18548 d[1] = yn, d[0] = yn += dy;
18549 } else {
18550 d[0] = 0, d[1] = dy;
18551 }
18552 }
18553 }
18554}
18555
18556function silhouette(series, order) {
18557 if (!((n = series.length) > 0)) return;
18558 for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
18559 for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
18560 s0[j][1] += s0[j][0] = -y / 2;
18561 }
18562 none$1(series, order);
18563}
18564
18565function wiggle(series, order) {
18566 if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
18567 for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
18568 for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
18569 var si = series[order[i]],
18570 sij0 = si[j][1] || 0,
18571 sij1 = si[j - 1][1] || 0,
18572 s3 = (sij0 - sij1) / 2;
18573 for (var k = 0; k < i; ++k) {
18574 var sk = series[order[k]],
18575 skj0 = sk[j][1] || 0,
18576 skj1 = sk[j - 1][1] || 0;
18577 s3 += skj0 - skj1;
18578 }
18579 s1 += sij0, s2 += s3 * sij0;
18580 }
18581 s0[j - 1][1] += s0[j - 1][0] = y;
18582 if (s1) y -= s2 / s1;
18583 }
18584 s0[j - 1][1] += s0[j - 1][0] = y;
18585 none$1(series, order);
18586}
18587
18588function appearance(series) {
18589 var peaks = series.map(peak);
18590 return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
18591}
18592
18593function peak(series) {
18594 var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
18595 while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
18596 return j;
18597}
18598
18599function ascending(series) {
18600 var sums = series.map(sum);
18601 return none(series).sort(function(a, b) { return sums[a] - sums[b]; });
18602}
18603
18604function sum(series) {
18605 var s = 0, i = -1, n = series.length, v;
18606 while (++i < n) if (v = +series[i][1]) s += v;
18607 return s;
18608}
18609
18610function descending(series) {
18611 return ascending(series).reverse();
18612}
18613
18614function insideOut(series) {
18615 var n = series.length,
18616 i,
18617 j,
18618 sums = series.map(sum),
18619 order = appearance(series),
18620 top = 0,
18621 bottom = 0,
18622 tops = [],
18623 bottoms = [];
18624
18625 for (i = 0; i < n; ++i) {
18626 j = order[i];
18627 if (top < bottom) {
18628 top += sums[j];
18629 tops.push(j);
18630 } else {
18631 bottom += sums[j];
18632 bottoms.push(j);
18633 }
18634 }
18635
18636 return bottoms.reverse().concat(tops);
18637}
18638
18639function reverse(series) {
18640 return none(series).reverse();
18641}
18642
18643var constant = x => () => x;
18644
18645function ZoomEvent(type, {
18646 sourceEvent,
18647 target,
18648 transform,
18649 dispatch
18650}) {
18651 Object.defineProperties(this, {
18652 type: {value: type, enumerable: true, configurable: true},
18653 sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
18654 target: {value: target, enumerable: true, configurable: true},
18655 transform: {value: transform, enumerable: true, configurable: true},
18656 _: {value: dispatch}
18657 });
18658}
18659
18660function Transform(k, x, y) {
18661 this.k = k;
18662 this.x = x;
18663 this.y = y;
18664}
18665
18666Transform.prototype = {
18667 constructor: Transform,
18668 scale: function(k) {
18669 return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
18670 },
18671 translate: function(x, y) {
18672 return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
18673 },
18674 apply: function(point) {
18675 return [point[0] * this.k + this.x, point[1] * this.k + this.y];
18676 },
18677 applyX: function(x) {
18678 return x * this.k + this.x;
18679 },
18680 applyY: function(y) {
18681 return y * this.k + this.y;
18682 },
18683 invert: function(location) {
18684 return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
18685 },
18686 invertX: function(x) {
18687 return (x - this.x) / this.k;
18688 },
18689 invertY: function(y) {
18690 return (y - this.y) / this.k;
18691 },
18692 rescaleX: function(x) {
18693 return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
18694 },
18695 rescaleY: function(y) {
18696 return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
18697 },
18698 toString: function() {
18699 return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
18700 }
18701};
18702
18703var identity = new Transform(1, 0, 0);
18704
18705transform.prototype = Transform.prototype;
18706
18707function transform(node) {
18708 while (!node.__zoom) if (!(node = node.parentNode)) return identity;
18709 return node.__zoom;
18710}
18711
18712function nopropagation(event) {
18713 event.stopImmediatePropagation();
18714}
18715
18716function noevent(event) {
18717 event.preventDefault();
18718 event.stopImmediatePropagation();
18719}
18720
18721// Ignore right-click, since that should open the context menu.
18722// except for pinch-to-zoom, which is sent as a wheel+ctrlKey event
18723function defaultFilter(event) {
18724 return (!event.ctrlKey || event.type === 'wheel') && !event.button;
18725}
18726
18727function defaultExtent() {
18728 var e = this;
18729 if (e instanceof SVGElement) {
18730 e = e.ownerSVGElement || e;
18731 if (e.hasAttribute("viewBox")) {
18732 e = e.viewBox.baseVal;
18733 return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
18734 }
18735 return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
18736 }
18737 return [[0, 0], [e.clientWidth, e.clientHeight]];
18738}
18739
18740function defaultTransform() {
18741 return this.__zoom || identity;
18742}
18743
18744function defaultWheelDelta(event) {
18745 return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1);
18746}
18747
18748function defaultTouchable() {
18749 return navigator.maxTouchPoints || ("ontouchstart" in this);
18750}
18751
18752function defaultConstrain(transform, extent, translateExtent) {
18753 var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
18754 dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
18755 dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
18756 dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
18757 return transform.translate(
18758 dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
18759 dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
18760 );
18761}
18762
18763function zoom() {
18764 var filter = defaultFilter,
18765 extent = defaultExtent,
18766 constrain = defaultConstrain,
18767 wheelDelta = defaultWheelDelta,
18768 touchable = defaultTouchable,
18769 scaleExtent = [0, Infinity],
18770 translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
18771 duration = 250,
18772 interpolate = interpolateZoom,
18773 listeners = dispatch("start", "zoom", "end"),
18774 touchstarting,
18775 touchfirst,
18776 touchending,
18777 touchDelay = 500,
18778 wheelDelay = 150,
18779 clickDistance2 = 0,
18780 tapDistance = 10;
18781
18782 function zoom(selection) {
18783 selection
18784 .property("__zoom", defaultTransform)
18785 .on("wheel.zoom", wheeled)
18786 .on("mousedown.zoom", mousedowned)
18787 .on("dblclick.zoom", dblclicked)
18788 .filter(touchable)
18789 .on("touchstart.zoom", touchstarted)
18790 .on("touchmove.zoom", touchmoved)
18791 .on("touchend.zoom touchcancel.zoom", touchended)
18792 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
18793 }
18794
18795 zoom.transform = function(collection, transform, point, event) {
18796 var selection = collection.selection ? collection.selection() : collection;
18797 selection.property("__zoom", defaultTransform);
18798 if (collection !== selection) {
18799 schedule(collection, transform, point, event);
18800 } else {
18801 selection.interrupt().each(function() {
18802 gesture(this, arguments)
18803 .event(event)
18804 .start()
18805 .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
18806 .end();
18807 });
18808 }
18809 };
18810
18811 zoom.scaleBy = function(selection, k, p, event) {
18812 zoom.scaleTo(selection, function() {
18813 var k0 = this.__zoom.k,
18814 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
18815 return k0 * k1;
18816 }, p, event);
18817 };
18818
18819 zoom.scaleTo = function(selection, k, p, event) {
18820 zoom.transform(selection, function() {
18821 var e = extent.apply(this, arguments),
18822 t0 = this.__zoom,
18823 p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
18824 p1 = t0.invert(p0),
18825 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
18826 return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
18827 }, p, event);
18828 };
18829
18830 zoom.translateBy = function(selection, x, y, event) {
18831 zoom.transform(selection, function() {
18832 return constrain(this.__zoom.translate(
18833 typeof x === "function" ? x.apply(this, arguments) : x,
18834 typeof y === "function" ? y.apply(this, arguments) : y
18835 ), extent.apply(this, arguments), translateExtent);
18836 }, null, event);
18837 };
18838
18839 zoom.translateTo = function(selection, x, y, p, event) {
18840 zoom.transform(selection, function() {
18841 var e = extent.apply(this, arguments),
18842 t = this.__zoom,
18843 p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
18844 return constrain(identity.translate(p0[0], p0[1]).scale(t.k).translate(
18845 typeof x === "function" ? -x.apply(this, arguments) : -x,
18846 typeof y === "function" ? -y.apply(this, arguments) : -y
18847 ), e, translateExtent);
18848 }, p, event);
18849 };
18850
18851 function scale(transform, k) {
18852 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
18853 return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
18854 }
18855
18856 function translate(transform, p0, p1) {
18857 var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
18858 return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
18859 }
18860
18861 function centroid(extent) {
18862 return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
18863 }
18864
18865 function schedule(transition, transform, point, event) {
18866 transition
18867 .on("start.zoom", function() { gesture(this, arguments).event(event).start(); })
18868 .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).event(event).end(); })
18869 .tween("zoom", function() {
18870 var that = this,
18871 args = arguments,
18872 g = gesture(that, args).event(event),
18873 e = extent.apply(that, args),
18874 p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
18875 w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
18876 a = that.__zoom,
18877 b = typeof transform === "function" ? transform.apply(that, args) : transform,
18878 i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
18879 return function(t) {
18880 if (t === 1) t = b; // Avoid rounding error on end.
18881 else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
18882 g.zoom(null, t);
18883 };
18884 });
18885 }
18886
18887 function gesture(that, args, clean) {
18888 return (!clean && that.__zooming) || new Gesture(that, args);
18889 }
18890
18891 function Gesture(that, args) {
18892 this.that = that;
18893 this.args = args;
18894 this.active = 0;
18895 this.sourceEvent = null;
18896 this.extent = extent.apply(that, args);
18897 this.taps = 0;
18898 }
18899
18900 Gesture.prototype = {
18901 event: function(event) {
18902 if (event) this.sourceEvent = event;
18903 return this;
18904 },
18905 start: function() {
18906 if (++this.active === 1) {
18907 this.that.__zooming = this;
18908 this.emit("start");
18909 }
18910 return this;
18911 },
18912 zoom: function(key, transform) {
18913 if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
18914 if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
18915 if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
18916 this.that.__zoom = transform;
18917 this.emit("zoom");
18918 return this;
18919 },
18920 end: function() {
18921 if (--this.active === 0) {
18922 delete this.that.__zooming;
18923 this.emit("end");
18924 }
18925 return this;
18926 },
18927 emit: function(type) {
18928 var d = select(this.that).datum();
18929 listeners.call(
18930 type,
18931 this.that,
18932 new ZoomEvent(type, {
18933 sourceEvent: this.sourceEvent,
18934 target: zoom,
18935 type,
18936 transform: this.that.__zoom,
18937 dispatch: listeners
18938 }),
18939 d
18940 );
18941 }
18942 };
18943
18944 function wheeled(event, ...args) {
18945 if (!filter.apply(this, arguments)) return;
18946 var g = gesture(this, args).event(event),
18947 t = this.__zoom,
18948 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
18949 p = pointer(event);
18950
18951 // If the mouse is in the same location as before, reuse it.
18952 // If there were recent wheel events, reset the wheel idle timeout.
18953 if (g.wheel) {
18954 if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
18955 g.mouse[1] = t.invert(g.mouse[0] = p);
18956 }
18957 clearTimeout(g.wheel);
18958 }
18959
18960 // If this wheel event won’t trigger a transform change, ignore it.
18961 else if (t.k === k) return;
18962
18963 // Otherwise, capture the mouse point and location at the start.
18964 else {
18965 g.mouse = [p, t.invert(p)];
18966 interrupt(this);
18967 g.start();
18968 }
18969
18970 noevent(event);
18971 g.wheel = setTimeout(wheelidled, wheelDelay);
18972 g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
18973
18974 function wheelidled() {
18975 g.wheel = null;
18976 g.end();
18977 }
18978 }
18979
18980 function mousedowned(event, ...args) {
18981 if (touchending || !filter.apply(this, arguments)) return;
18982 var g = gesture(this, args, true).event(event),
18983 v = select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
18984 p = pointer(event, currentTarget),
18985 currentTarget = event.currentTarget,
18986 x0 = event.clientX,
18987 y0 = event.clientY;
18988
18989 dragDisable(event.view);
18990 nopropagation(event);
18991 g.mouse = [p, this.__zoom.invert(p)];
18992 interrupt(this);
18993 g.start();
18994
18995 function mousemoved(event) {
18996 noevent(event);
18997 if (!g.moved) {
18998 var dx = event.clientX - x0, dy = event.clientY - y0;
18999 g.moved = dx * dx + dy * dy > clickDistance2;
19000 }
19001 g.event(event)
19002 .zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = pointer(event, currentTarget), g.mouse[1]), g.extent, translateExtent));
19003 }
19004
19005 function mouseupped(event) {
19006 v.on("mousemove.zoom mouseup.zoom", null);
19007 yesdrag(event.view, g.moved);
19008 noevent(event);
19009 g.event(event).end();
19010 }
19011 }
19012
19013 function dblclicked(event, ...args) {
19014 if (!filter.apply(this, arguments)) return;
19015 var t0 = this.__zoom,
19016 p0 = pointer(event.changedTouches ? event.changedTouches[0] : event, this),
19017 p1 = t0.invert(p0),
19018 k1 = t0.k * (event.shiftKey ? 0.5 : 2),
19019 t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, args), translateExtent);
19020
19021 noevent(event);
19022 if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0, event);
19023 else select(this).call(zoom.transform, t1, p0, event);
19024 }
19025
19026 function touchstarted(event, ...args) {
19027 if (!filter.apply(this, arguments)) return;
19028 var touches = event.touches,
19029 n = touches.length,
19030 g = gesture(this, args, event.changedTouches.length === n).event(event),
19031 started, i, t, p;
19032
19033 nopropagation(event);
19034 for (i = 0; i < n; ++i) {
19035 t = touches[i], p = pointer(t, this);
19036 p = [p, this.__zoom.invert(p), t.identifier];
19037 if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
19038 else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
19039 }
19040
19041 if (touchstarting) touchstarting = clearTimeout(touchstarting);
19042
19043 if (started) {
19044 if (g.taps < 2) touchfirst = p[0], touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
19045 interrupt(this);
19046 g.start();
19047 }
19048 }
19049
19050 function touchmoved(event, ...args) {
19051 if (!this.__zooming) return;
19052 var g = gesture(this, args).event(event),
19053 touches = event.changedTouches,
19054 n = touches.length, i, t, p, l;
19055
19056 noevent(event);
19057 for (i = 0; i < n; ++i) {
19058 t = touches[i], p = pointer(t, this);
19059 if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
19060 else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
19061 }
19062 t = g.that.__zoom;
19063 if (g.touch1) {
19064 var p0 = g.touch0[0], l0 = g.touch0[1],
19065 p1 = g.touch1[0], l1 = g.touch1[1],
19066 dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
19067 dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
19068 t = scale(t, Math.sqrt(dp / dl));
19069 p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
19070 l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
19071 }
19072 else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
19073 else return;
19074
19075 g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
19076 }
19077
19078 function touchended(event, ...args) {
19079 if (!this.__zooming) return;
19080 var g = gesture(this, args).event(event),
19081 touches = event.changedTouches,
19082 n = touches.length, i, t;
19083
19084 nopropagation(event);
19085 if (touchending) clearTimeout(touchending);
19086 touchending = setTimeout(function() { touchending = null; }, touchDelay);
19087 for (i = 0; i < n; ++i) {
19088 t = touches[i];
19089 if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
19090 else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
19091 }
19092 if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
19093 if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
19094 else {
19095 g.end();
19096 // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
19097 if (g.taps === 2) {
19098 t = pointer(t, this);
19099 if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) {
19100 var p = select(this).on("dblclick.zoom");
19101 if (p) p.apply(this, arguments);
19102 }
19103 }
19104 }
19105 }
19106
19107 zoom.wheelDelta = function(_) {
19108 return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant(+_), zoom) : wheelDelta;
19109 };
19110
19111 zoom.filter = function(_) {
19112 return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter;
19113 };
19114
19115 zoom.touchable = function(_) {
19116 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), zoom) : touchable;
19117 };
19118
19119 zoom.extent = function(_) {
19120 return arguments.length ? (extent = typeof _ === "function" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
19121 };
19122
19123 zoom.scaleExtent = function(_) {
19124 return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
19125 };
19126
19127 zoom.translateExtent = function(_) {
19128 return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
19129 };
19130
19131 zoom.constrain = function(_) {
19132 return arguments.length ? (constrain = _, zoom) : constrain;
19133 };
19134
19135 zoom.duration = function(_) {
19136 return arguments.length ? (duration = +_, zoom) : duration;
19137 };
19138
19139 zoom.interpolate = function(_) {
19140 return arguments.length ? (interpolate = _, zoom) : interpolate;
19141 };
19142
19143 zoom.on = function() {
19144 var value = listeners.on.apply(listeners, arguments);
19145 return value === listeners ? zoom : value;
19146 };
19147
19148 zoom.clickDistance = function(_) {
19149 return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
19150 };
19151
19152 zoom.tapDistance = function(_) {
19153 return arguments.length ? (tapDistance = +_, zoom) : tapDistance;
19154 };
19155
19156 return zoom;
19157}
19158
19159exports.Adder = Adder;
19160exports.Delaunay = Delaunay;
19161exports.FormatSpecifier = FormatSpecifier;
19162exports.InternMap = InternMap;
19163exports.InternSet = InternSet;
19164exports.Voronoi = Voronoi;
19165exports.active = active;
19166exports.arc = arc;
19167exports.area = area;
19168exports.areaRadial = areaRadial;
19169exports.ascending = ascending$3;
19170exports.autoType = autoType;
19171exports.axisBottom = axisBottom;
19172exports.axisLeft = axisLeft;
19173exports.axisRight = axisRight;
19174exports.axisTop = axisTop;
19175exports.bin = bin;
19176exports.bisect = bisectRight;
19177exports.bisectCenter = bisectCenter;
19178exports.bisectLeft = bisectLeft;
19179exports.bisectRight = bisectRight;
19180exports.bisector = bisector;
19181exports.blob = blob;
19182exports.brush = brush;
19183exports.brushSelection = brushSelection;
19184exports.brushX = brushX;
19185exports.brushY = brushY;
19186exports.buffer = buffer;
19187exports.chord = chord;
19188exports.chordDirected = chordDirected;
19189exports.chordTranspose = chordTranspose;
19190exports.cluster = cluster;
19191exports.color = color;
19192exports.contourDensity = density;
19193exports.contours = contours;
19194exports.count = count$1;
19195exports.create = create$1;
19196exports.creator = creator;
19197exports.cross = cross$2;
19198exports.csv = csv;
19199exports.csvFormat = csvFormat;
19200exports.csvFormatBody = csvFormatBody;
19201exports.csvFormatRow = csvFormatRow;
19202exports.csvFormatRows = csvFormatRows;
19203exports.csvFormatValue = csvFormatValue;
19204exports.csvParse = csvParse;
19205exports.csvParseRows = csvParseRows;
19206exports.cubehelix = cubehelix$3;
19207exports.cumsum = cumsum;
19208exports.curveBasis = basis;
19209exports.curveBasisClosed = basisClosed;
19210exports.curveBasisOpen = basisOpen;
19211exports.curveBumpX = bumpX;
19212exports.curveBumpY = bumpY;
19213exports.curveBundle = bundle;
19214exports.curveCardinal = cardinal;
19215exports.curveCardinalClosed = cardinalClosed;
19216exports.curveCardinalOpen = cardinalOpen;
19217exports.curveCatmullRom = catmullRom;
19218exports.curveCatmullRomClosed = catmullRomClosed;
19219exports.curveCatmullRomOpen = catmullRomOpen;
19220exports.curveLinear = curveLinear;
19221exports.curveLinearClosed = linearClosed;
19222exports.curveMonotoneX = monotoneX;
19223exports.curveMonotoneY = monotoneY;
19224exports.curveNatural = natural;
19225exports.curveStep = step;
19226exports.curveStepAfter = stepAfter;
19227exports.curveStepBefore = stepBefore;
19228exports.descending = descending$2;
19229exports.deviation = deviation;
19230exports.difference = difference;
19231exports.disjoint = disjoint;
19232exports.dispatch = dispatch;
19233exports.drag = drag;
19234exports.dragDisable = dragDisable;
19235exports.dragEnable = yesdrag;
19236exports.dsv = dsv;
19237exports.dsvFormat = dsvFormat;
19238exports.easeBack = backInOut;
19239exports.easeBackIn = backIn;
19240exports.easeBackInOut = backInOut;
19241exports.easeBackOut = backOut;
19242exports.easeBounce = bounceOut;
19243exports.easeBounceIn = bounceIn;
19244exports.easeBounceInOut = bounceInOut;
19245exports.easeBounceOut = bounceOut;
19246exports.easeCircle = circleInOut;
19247exports.easeCircleIn = circleIn;
19248exports.easeCircleInOut = circleInOut;
19249exports.easeCircleOut = circleOut;
19250exports.easeCubic = cubicInOut;
19251exports.easeCubicIn = cubicIn;
19252exports.easeCubicInOut = cubicInOut;
19253exports.easeCubicOut = cubicOut;
19254exports.easeElastic = elasticOut;
19255exports.easeElasticIn = elasticIn;
19256exports.easeElasticInOut = elasticInOut;
19257exports.easeElasticOut = elasticOut;
19258exports.easeExp = expInOut;
19259exports.easeExpIn = expIn;
19260exports.easeExpInOut = expInOut;
19261exports.easeExpOut = expOut;
19262exports.easeLinear = linear$1;
19263exports.easePoly = polyInOut;
19264exports.easePolyIn = polyIn;
19265exports.easePolyInOut = polyInOut;
19266exports.easePolyOut = polyOut;
19267exports.easeQuad = quadInOut;
19268exports.easeQuadIn = quadIn;
19269exports.easeQuadInOut = quadInOut;
19270exports.easeQuadOut = quadOut;
19271exports.easeSin = sinInOut;
19272exports.easeSinIn = sinIn;
19273exports.easeSinInOut = sinInOut;
19274exports.easeSinOut = sinOut;
19275exports.every = every;
19276exports.extent = extent$1;
19277exports.fcumsum = fcumsum;
19278exports.filter = filter$1;
19279exports.forceCenter = center;
19280exports.forceCollide = collide;
19281exports.forceLink = link$2;
19282exports.forceManyBody = manyBody;
19283exports.forceRadial = radial$1;
19284exports.forceSimulation = simulation;
19285exports.forceX = x$1;
19286exports.forceY = y$1;
19287exports.formatDefaultLocale = defaultLocale$1;
19288exports.formatLocale = formatLocale$1;
19289exports.formatSpecifier = formatSpecifier;
19290exports.fsum = fsum;
19291exports.geoAlbers = albers;
19292exports.geoAlbersUsa = albersUsa;
19293exports.geoArea = area$2;
19294exports.geoAzimuthalEqualArea = azimuthalEqualArea;
19295exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
19296exports.geoAzimuthalEquidistant = azimuthalEquidistant;
19297exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
19298exports.geoBounds = bounds;
19299exports.geoCentroid = centroid$1;
19300exports.geoCircle = circle$2;
19301exports.geoClipAntimeridian = clipAntimeridian;
19302exports.geoClipCircle = clipCircle;
19303exports.geoClipExtent = extent;
19304exports.geoClipRectangle = clipRectangle;
19305exports.geoConicConformal = conicConformal;
19306exports.geoConicConformalRaw = conicConformalRaw;
19307exports.geoConicEqualArea = conicEqualArea;
19308exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
19309exports.geoConicEquidistant = conicEquidistant;
19310exports.geoConicEquidistantRaw = conicEquidistantRaw;
19311exports.geoContains = contains$1;
19312exports.geoDistance = distance;
19313exports.geoEqualEarth = equalEarth;
19314exports.geoEqualEarthRaw = equalEarthRaw;
19315exports.geoEquirectangular = equirectangular;
19316exports.geoEquirectangularRaw = equirectangularRaw;
19317exports.geoGnomonic = gnomonic;
19318exports.geoGnomonicRaw = gnomonicRaw;
19319exports.geoGraticule = graticule;
19320exports.geoGraticule10 = graticule10;
19321exports.geoIdentity = identity$4;
19322exports.geoInterpolate = interpolate;
19323exports.geoLength = length$1;
19324exports.geoMercator = mercator;
19325exports.geoMercatorRaw = mercatorRaw;
19326exports.geoNaturalEarth1 = naturalEarth1;
19327exports.geoNaturalEarth1Raw = naturalEarth1Raw;
19328exports.geoOrthographic = orthographic;
19329exports.geoOrthographicRaw = orthographicRaw;
19330exports.geoPath = index$2;
19331exports.geoProjection = projection;
19332exports.geoProjectionMutator = projectionMutator;
19333exports.geoRotation = rotation;
19334exports.geoStereographic = stereographic;
19335exports.geoStereographicRaw = stereographicRaw;
19336exports.geoStream = geoStream;
19337exports.geoTransform = transform$1;
19338exports.geoTransverseMercator = transverseMercator;
19339exports.geoTransverseMercatorRaw = transverseMercatorRaw;
19340exports.gray = gray;
19341exports.greatest = greatest;
19342exports.greatestIndex = greatestIndex;
19343exports.group = group;
19344exports.groupSort = groupSort;
19345exports.groups = groups;
19346exports.hcl = hcl$2;
19347exports.hierarchy = hierarchy;
19348exports.histogram = bin;
19349exports.hsl = hsl$2;
19350exports.html = html;
19351exports.image = image;
19352exports.index = index$4;
19353exports.indexes = indexes;
19354exports.interpolate = interpolate$2;
19355exports.interpolateArray = array$3;
19356exports.interpolateBasis = basis$2;
19357exports.interpolateBasisClosed = basisClosed$1;
19358exports.interpolateBlues = Blues;
19359exports.interpolateBrBG = BrBG;
19360exports.interpolateBuGn = BuGn;
19361exports.interpolateBuPu = BuPu;
19362exports.interpolateCividis = cividis;
19363exports.interpolateCool = cool;
19364exports.interpolateCubehelix = cubehelix$2;
19365exports.interpolateCubehelixDefault = cubehelix;
19366exports.interpolateCubehelixLong = cubehelixLong;
19367exports.interpolateDate = date$1;
19368exports.interpolateDiscrete = discrete;
19369exports.interpolateGnBu = GnBu;
19370exports.interpolateGreens = Greens;
19371exports.interpolateGreys = Greys;
19372exports.interpolateHcl = hcl$1;
19373exports.interpolateHclLong = hclLong;
19374exports.interpolateHsl = hsl$1;
19375exports.interpolateHslLong = hslLong;
19376exports.interpolateHue = hue;
19377exports.interpolateInferno = inferno;
19378exports.interpolateLab = lab;
19379exports.interpolateMagma = magma;
19380exports.interpolateNumber = interpolateNumber;
19381exports.interpolateNumberArray = numberArray;
19382exports.interpolateObject = object$1;
19383exports.interpolateOrRd = OrRd;
19384exports.interpolateOranges = Oranges;
19385exports.interpolatePRGn = PRGn;
19386exports.interpolatePiYG = PiYG;
19387exports.interpolatePlasma = plasma;
19388exports.interpolatePuBu = PuBu;
19389exports.interpolatePuBuGn = PuBuGn;
19390exports.interpolatePuOr = PuOr;
19391exports.interpolatePuRd = PuRd;
19392exports.interpolatePurples = Purples;
19393exports.interpolateRainbow = rainbow;
19394exports.interpolateRdBu = RdBu;
19395exports.interpolateRdGy = RdGy;
19396exports.interpolateRdPu = RdPu;
19397exports.interpolateRdYlBu = RdYlBu;
19398exports.interpolateRdYlGn = RdYlGn;
19399exports.interpolateReds = Reds;
19400exports.interpolateRgb = interpolateRgb;
19401exports.interpolateRgbBasis = rgbBasis;
19402exports.interpolateRgbBasisClosed = rgbBasisClosed;
19403exports.interpolateRound = interpolateRound;
19404exports.interpolateSinebow = sinebow;
19405exports.interpolateSpectral = Spectral;
19406exports.interpolateString = interpolateString;
19407exports.interpolateTransformCss = interpolateTransformCss;
19408exports.interpolateTransformSvg = interpolateTransformSvg;
19409exports.interpolateTurbo = turbo;
19410exports.interpolateViridis = viridis;
19411exports.interpolateWarm = warm;
19412exports.interpolateYlGn = YlGn;
19413exports.interpolateYlGnBu = YlGnBu;
19414exports.interpolateYlOrBr = YlOrBr;
19415exports.interpolateYlOrRd = YlOrRd;
19416exports.interpolateZoom = interpolateZoom;
19417exports.interrupt = interrupt;
19418exports.intersection = intersection;
19419exports.interval = interval;
19420exports.isoFormat = formatIso;
19421exports.isoParse = parseIso;
19422exports.json = json;
19423exports.lab = lab$1;
19424exports.lch = lch;
19425exports.least = least;
19426exports.leastIndex = leastIndex;
19427exports.line = line;
19428exports.lineRadial = lineRadial$1;
19429exports.linkHorizontal = linkHorizontal;
19430exports.linkRadial = linkRadial;
19431exports.linkVertical = linkVertical;
19432exports.local = local$1;
19433exports.map = map$1;
19434exports.matcher = matcher;
19435exports.max = max$3;
19436exports.maxIndex = maxIndex;
19437exports.mean = mean;
19438exports.median = median;
19439exports.merge = merge;
19440exports.min = min$2;
19441exports.minIndex = minIndex;
19442exports.namespace = namespace;
19443exports.namespaces = namespaces;
19444exports.nice = nice$1;
19445exports.now = now;
19446exports.pack = index$1;
19447exports.packEnclose = enclose;
19448exports.packSiblings = siblings;
19449exports.pairs = pairs;
19450exports.partition = partition;
19451exports.path = path;
19452exports.permute = permute;
19453exports.pie = pie;
19454exports.piecewise = piecewise;
19455exports.pointRadial = pointRadial;
19456exports.pointer = pointer;
19457exports.pointers = pointers;
19458exports.polygonArea = area$1;
19459exports.polygonCentroid = centroid;
19460exports.polygonContains = contains;
19461exports.polygonHull = hull;
19462exports.polygonLength = length;
19463exports.precisionFixed = precisionFixed;
19464exports.precisionPrefix = precisionPrefix;
19465exports.precisionRound = precisionRound;
19466exports.quadtree = quadtree;
19467exports.quantile = quantile$1;
19468exports.quantileSorted = quantileSorted;
19469exports.quantize = quantize$1;
19470exports.quickselect = quickselect;
19471exports.radialArea = areaRadial;
19472exports.radialLine = lineRadial$1;
19473exports.randomBates = bates;
19474exports.randomBernoulli = bernoulli;
19475exports.randomBeta = beta;
19476exports.randomBinomial = binomial;
19477exports.randomCauchy = cauchy;
19478exports.randomExponential = exponential;
19479exports.randomGamma = gamma;
19480exports.randomGeometric = geometric;
19481exports.randomInt = int;
19482exports.randomIrwinHall = irwinHall;
19483exports.randomLcg = lcg;
19484exports.randomLogNormal = logNormal;
19485exports.randomLogistic = logistic;
19486exports.randomNormal = normal;
19487exports.randomPareto = pareto;
19488exports.randomPoisson = poisson;
19489exports.randomUniform = uniform;
19490exports.randomWeibull = weibull;
19491exports.range = sequence;
19492exports.reduce = reduce;
19493exports.reverse = reverse$1;
19494exports.rgb = rgb;
19495exports.ribbon = ribbon$1;
19496exports.ribbonArrow = ribbonArrow;
19497exports.rollup = rollup;
19498exports.rollups = rollups;
19499exports.scaleBand = band;
19500exports.scaleDiverging = diverging$1;
19501exports.scaleDivergingLog = divergingLog;
19502exports.scaleDivergingPow = divergingPow;
19503exports.scaleDivergingSqrt = divergingSqrt;
19504exports.scaleDivergingSymlog = divergingSymlog;
19505exports.scaleIdentity = identity$2;
19506exports.scaleImplicit = implicit;
19507exports.scaleLinear = linear;
19508exports.scaleLog = log;
19509exports.scaleOrdinal = ordinal;
19510exports.scalePoint = point$4;
19511exports.scalePow = pow;
19512exports.scaleQuantile = quantile;
19513exports.scaleQuantize = quantize;
19514exports.scaleRadial = radial;
19515exports.scaleSequential = sequential;
19516exports.scaleSequentialLog = sequentialLog;
19517exports.scaleSequentialPow = sequentialPow;
19518exports.scaleSequentialQuantile = sequentialQuantile;
19519exports.scaleSequentialSqrt = sequentialSqrt;
19520exports.scaleSequentialSymlog = sequentialSymlog;
19521exports.scaleSqrt = sqrt$1;
19522exports.scaleSymlog = symlog;
19523exports.scaleThreshold = threshold;
19524exports.scaleTime = time;
19525exports.scaleUtc = utcTime;
19526exports.scan = scan;
19527exports.schemeAccent = Accent;
19528exports.schemeBlues = scheme$5;
19529exports.schemeBrBG = scheme$q;
19530exports.schemeBuGn = scheme$h;
19531exports.schemeBuPu = scheme$g;
19532exports.schemeCategory10 = category10;
19533exports.schemeDark2 = Dark2;
19534exports.schemeGnBu = scheme$f;
19535exports.schemeGreens = scheme$4;
19536exports.schemeGreys = scheme$3;
19537exports.schemeOrRd = scheme$e;
19538exports.schemeOranges = scheme;
19539exports.schemePRGn = scheme$p;
19540exports.schemePaired = Paired;
19541exports.schemePastel1 = Pastel1;
19542exports.schemePastel2 = Pastel2;
19543exports.schemePiYG = scheme$o;
19544exports.schemePuBu = scheme$c;
19545exports.schemePuBuGn = scheme$d;
19546exports.schemePuOr = scheme$n;
19547exports.schemePuRd = scheme$b;
19548exports.schemePurples = scheme$2;
19549exports.schemeRdBu = scheme$m;
19550exports.schemeRdGy = scheme$l;
19551exports.schemeRdPu = scheme$a;
19552exports.schemeRdYlBu = scheme$k;
19553exports.schemeRdYlGn = scheme$j;
19554exports.schemeReds = scheme$1;
19555exports.schemeSet1 = Set1;
19556exports.schemeSet2 = Set2;
19557exports.schemeSet3 = Set3;
19558exports.schemeSpectral = scheme$i;
19559exports.schemeTableau10 = Tableau10;
19560exports.schemeYlGn = scheme$8;
19561exports.schemeYlGnBu = scheme$9;
19562exports.schemeYlOrBr = scheme$7;
19563exports.schemeYlOrRd = scheme$6;
19564exports.select = select;
19565exports.selectAll = selectAll;
19566exports.selection = selection;
19567exports.selector = selector;
19568exports.selectorAll = selectorAll;
19569exports.shuffle = shuffle$1;
19570exports.shuffler = shuffler;
19571exports.some = some;
19572exports.sort = sort;
19573exports.stack = stack;
19574exports.stackOffsetDiverging = diverging;
19575exports.stackOffsetExpand = expand;
19576exports.stackOffsetNone = none$1;
19577exports.stackOffsetSilhouette = silhouette;
19578exports.stackOffsetWiggle = wiggle;
19579exports.stackOrderAppearance = appearance;
19580exports.stackOrderAscending = ascending;
19581exports.stackOrderDescending = descending;
19582exports.stackOrderInsideOut = insideOut;
19583exports.stackOrderNone = none;
19584exports.stackOrderReverse = reverse;
19585exports.stratify = stratify;
19586exports.style = styleValue;
19587exports.subset = subset;
19588exports.sum = sum$1;
19589exports.superset = superset;
19590exports.svg = svg;
19591exports.symbol = symbol;
19592exports.symbolCircle = circle;
19593exports.symbolCross = cross;
19594exports.symbolDiamond = diamond;
19595exports.symbolSquare = square;
19596exports.symbolStar = star;
19597exports.symbolTriangle = triangle;
19598exports.symbolWye = wye;
19599exports.symbols = symbols;
19600exports.text = text;
19601exports.thresholdFreedmanDiaconis = freedmanDiaconis;
19602exports.thresholdScott = scott;
19603exports.thresholdSturges = thresholdSturges;
19604exports.tickFormat = tickFormat;
19605exports.tickIncrement = tickIncrement;
19606exports.tickStep = tickStep;
19607exports.ticks = ticks;
19608exports.timeDay = day;
19609exports.timeDays = days;
19610exports.timeFormatDefaultLocale = defaultLocale;
19611exports.timeFormatLocale = formatLocale;
19612exports.timeFriday = friday;
19613exports.timeFridays = fridays;
19614exports.timeHour = hour;
19615exports.timeHours = hours;
19616exports.timeInterval = newInterval;
19617exports.timeMillisecond = millisecond;
19618exports.timeMilliseconds = milliseconds;
19619exports.timeMinute = minute;
19620exports.timeMinutes = minutes;
19621exports.timeMonday = monday;
19622exports.timeMondays = mondays;
19623exports.timeMonth = month;
19624exports.timeMonths = months;
19625exports.timeSaturday = saturday;
19626exports.timeSaturdays = saturdays;
19627exports.timeSecond = second;
19628exports.timeSeconds = seconds;
19629exports.timeSunday = sunday;
19630exports.timeSundays = sundays;
19631exports.timeThursday = thursday;
19632exports.timeThursdays = thursdays;
19633exports.timeTickInterval = timeTickInterval;
19634exports.timeTicks = timeTicks;
19635exports.timeTuesday = tuesday;
19636exports.timeTuesdays = tuesdays;
19637exports.timeWednesday = wednesday;
19638exports.timeWednesdays = wednesdays;
19639exports.timeWeek = sunday;
19640exports.timeWeeks = sundays;
19641exports.timeYear = year;
19642exports.timeYears = years;
19643exports.timeout = timeout;
19644exports.timer = timer;
19645exports.timerFlush = timerFlush;
19646exports.transition = transition;
19647exports.transpose = transpose;
19648exports.tree = tree;
19649exports.treemap = index;
19650exports.treemapBinary = binary;
19651exports.treemapDice = treemapDice;
19652exports.treemapResquarify = resquarify;
19653exports.treemapSlice = treemapSlice;
19654exports.treemapSliceDice = sliceDice;
19655exports.treemapSquarify = squarify;
19656exports.tsv = tsv;
19657exports.tsvFormat = tsvFormat;
19658exports.tsvFormatBody = tsvFormatBody;
19659exports.tsvFormatRow = tsvFormatRow;
19660exports.tsvFormatRows = tsvFormatRows;
19661exports.tsvFormatValue = tsvFormatValue;
19662exports.tsvParse = tsvParse;
19663exports.tsvParseRows = tsvParseRows;
19664exports.union = union;
19665exports.utcDay = utcDay;
19666exports.utcDays = utcDays;
19667exports.utcFriday = utcFriday;
19668exports.utcFridays = utcFridays;
19669exports.utcHour = utcHour;
19670exports.utcHours = utcHours;
19671exports.utcMillisecond = millisecond;
19672exports.utcMilliseconds = milliseconds;
19673exports.utcMinute = utcMinute;
19674exports.utcMinutes = utcMinutes;
19675exports.utcMonday = utcMonday;
19676exports.utcMondays = utcMondays;
19677exports.utcMonth = utcMonth;
19678exports.utcMonths = utcMonths;
19679exports.utcSaturday = utcSaturday;
19680exports.utcSaturdays = utcSaturdays;
19681exports.utcSecond = second;
19682exports.utcSeconds = seconds;
19683exports.utcSunday = utcSunday;
19684exports.utcSundays = utcSundays;
19685exports.utcThursday = utcThursday;
19686exports.utcThursdays = utcThursdays;
19687exports.utcTickInterval = utcTickInterval;
19688exports.utcTicks = utcTicks;
19689exports.utcTuesday = utcTuesday;
19690exports.utcTuesdays = utcTuesdays;
19691exports.utcWednesday = utcWednesday;
19692exports.utcWednesdays = utcWednesdays;
19693exports.utcWeek = utcSunday;
19694exports.utcWeeks = utcSundays;
19695exports.utcYear = utcYear;
19696exports.utcYears = utcYears;
19697exports.variance = variance;
19698exports.version = version;
19699exports.window = defaultView;
19700exports.xml = xml;
19701exports.zip = zip;
19702exports.zoom = zoom;
19703exports.zoomIdentity = identity;
19704exports.zoomTransform = transform;
19705
19706Object.defineProperty(exports, '__esModule', { value: true });
19707
19708})));
19709
\No newline at end of file