UNPKG

514 kBJavaScriptView Raw
1// https://d3js.org v5.14.2 Copyright 2019 Mike Bostock
2(function (global, factory) {
3typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4typeof define === 'function' && define.amd ? define(['exports'], factory) :
5(global = global || self, factory(global.d3 = global.d3 || {}));
6}(this, function (exports) { 'use strict';
7
8var version = "5.14.2";
9
10function ascending(a, b) {
11 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
12}
13
14function bisector(compare) {
15 if (compare.length === 1) compare = ascendingComparator(compare);
16 return {
17 left: function(a, x, lo, hi) {
18 if (lo == null) lo = 0;
19 if (hi == null) hi = a.length;
20 while (lo < hi) {
21 var mid = lo + hi >>> 1;
22 if (compare(a[mid], x) < 0) lo = mid + 1;
23 else hi = mid;
24 }
25 return lo;
26 },
27 right: function(a, x, lo, hi) {
28 if (lo == null) lo = 0;
29 if (hi == null) hi = a.length;
30 while (lo < hi) {
31 var mid = lo + hi >>> 1;
32 if (compare(a[mid], x) > 0) hi = mid;
33 else lo = mid + 1;
34 }
35 return lo;
36 }
37 };
38}
39
40function ascendingComparator(f) {
41 return function(d, x) {
42 return ascending(f(d), x);
43 };
44}
45
46var ascendingBisect = bisector(ascending);
47var bisectRight = ascendingBisect.right;
48var bisectLeft = ascendingBisect.left;
49
50function pairs(array, f) {
51 if (f == null) f = pair;
52 var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
53 while (i < n) pairs[i] = f(p, p = array[++i]);
54 return pairs;
55}
56
57function pair(a, b) {
58 return [a, b];
59}
60
61function cross(values0, values1, reduce) {
62 var n0 = values0.length,
63 n1 = values1.length,
64 values = new Array(n0 * n1),
65 i0,
66 i1,
67 i,
68 value0;
69
70 if (reduce == null) reduce = pair;
71
72 for (i0 = i = 0; i0 < n0; ++i0) {
73 for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
74 values[i] = reduce(value0, values1[i1]);
75 }
76 }
77
78 return values;
79}
80
81function descending(a, b) {
82 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
83}
84
85function number(x) {
86 return x === null ? NaN : +x;
87}
88
89function variance(values, valueof) {
90 var n = values.length,
91 m = 0,
92 i = -1,
93 mean = 0,
94 value,
95 delta,
96 sum = 0;
97
98 if (valueof == null) {
99 while (++i < n) {
100 if (!isNaN(value = number(values[i]))) {
101 delta = value - mean;
102 mean += delta / ++m;
103 sum += delta * (value - mean);
104 }
105 }
106 }
107
108 else {
109 while (++i < n) {
110 if (!isNaN(value = number(valueof(values[i], i, values)))) {
111 delta = value - mean;
112 mean += delta / ++m;
113 sum += delta * (value - mean);
114 }
115 }
116 }
117
118 if (m > 1) return sum / (m - 1);
119}
120
121function deviation(array, f) {
122 var v = variance(array, f);
123 return v ? Math.sqrt(v) : v;
124}
125
126function extent(values, valueof) {
127 var n = values.length,
128 i = -1,
129 value,
130 min,
131 max;
132
133 if (valueof == null) {
134 while (++i < n) { // Find the first comparable value.
135 if ((value = values[i]) != null && value >= value) {
136 min = max = value;
137 while (++i < n) { // Compare the remaining values.
138 if ((value = values[i]) != null) {
139 if (min > value) min = value;
140 if (max < value) max = value;
141 }
142 }
143 }
144 }
145 }
146
147 else {
148 while (++i < n) { // Find the first comparable value.
149 if ((value = valueof(values[i], i, values)) != null && value >= value) {
150 min = max = value;
151 while (++i < n) { // Compare the remaining values.
152 if ((value = valueof(values[i], i, values)) != null) {
153 if (min > value) min = value;
154 if (max < value) max = value;
155 }
156 }
157 }
158 }
159 }
160
161 return [min, max];
162}
163
164var array = Array.prototype;
165
166var slice = array.slice;
167var map = array.map;
168
169function constant(x) {
170 return function() {
171 return x;
172 };
173}
174
175function identity(x) {
176 return x;
177}
178
179function sequence(start, stop, step) {
180 start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
181
182 var i = -1,
183 n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
184 range = new Array(n);
185
186 while (++i < n) {
187 range[i] = start + i * step;
188 }
189
190 return range;
191}
192
193var e10 = Math.sqrt(50),
194 e5 = Math.sqrt(10),
195 e2 = Math.sqrt(2);
196
197function ticks(start, stop, count) {
198 var reverse,
199 i = -1,
200 n,
201 ticks,
202 step;
203
204 stop = +stop, start = +start, count = +count;
205 if (start === stop && count > 0) return [start];
206 if (reverse = stop < start) n = start, start = stop, stop = n;
207 if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
208
209 if (step > 0) {
210 start = Math.ceil(start / step);
211 stop = Math.floor(stop / step);
212 ticks = new Array(n = Math.ceil(stop - start + 1));
213 while (++i < n) ticks[i] = (start + i) * step;
214 } else {
215 start = Math.floor(start * step);
216 stop = Math.ceil(stop * step);
217 ticks = new Array(n = Math.ceil(start - stop + 1));
218 while (++i < n) ticks[i] = (start - i) / step;
219 }
220
221 if (reverse) ticks.reverse();
222
223 return ticks;
224}
225
226function tickIncrement(start, stop, count) {
227 var step = (stop - start) / Math.max(0, count),
228 power = Math.floor(Math.log(step) / Math.LN10),
229 error = step / Math.pow(10, power);
230 return power >= 0
231 ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
232 : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
233}
234
235function tickStep(start, stop, count) {
236 var step0 = Math.abs(stop - start) / Math.max(0, count),
237 step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
238 error = step0 / step1;
239 if (error >= e10) step1 *= 10;
240 else if (error >= e5) step1 *= 5;
241 else if (error >= e2) step1 *= 2;
242 return stop < start ? -step1 : step1;
243}
244
245function thresholdSturges(values) {
246 return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
247}
248
249function histogram() {
250 var value = identity,
251 domain = extent,
252 threshold = thresholdSturges;
253
254 function histogram(data) {
255 var i,
256 n = data.length,
257 x,
258 values = new Array(n);
259
260 for (i = 0; i < n; ++i) {
261 values[i] = value(data[i], i, data);
262 }
263
264 var xz = domain(values),
265 x0 = xz[0],
266 x1 = xz[1],
267 tz = threshold(values, x0, x1);
268
269 // Convert number of thresholds into uniform thresholds.
270 if (!Array.isArray(tz)) {
271 tz = tickStep(x0, x1, tz);
272 tz = sequence(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive
273 }
274
275 // Remove any thresholds outside the domain.
276 var m = tz.length;
277 while (tz[0] <= x0) tz.shift(), --m;
278 while (tz[m - 1] > x1) tz.pop(), --m;
279
280 var bins = new Array(m + 1),
281 bin;
282
283 // Initialize bins.
284 for (i = 0; i <= m; ++i) {
285 bin = bins[i] = [];
286 bin.x0 = i > 0 ? tz[i - 1] : x0;
287 bin.x1 = i < m ? tz[i] : x1;
288 }
289
290 // Assign data to bins by value, ignoring any outside the domain.
291 for (i = 0; i < n; ++i) {
292 x = values[i];
293 if (x0 <= x && x <= x1) {
294 bins[bisectRight(tz, x, 0, m)].push(data[i]);
295 }
296 }
297
298 return bins;
299 }
300
301 histogram.value = function(_) {
302 return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
303 };
304
305 histogram.domain = function(_) {
306 return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
307 };
308
309 histogram.thresholds = function(_) {
310 return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
311 };
312
313 return histogram;
314}
315
316function threshold(values, p, valueof) {
317 if (valueof == null) valueof = number;
318 if (!(n = values.length)) return;
319 if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
320 if (p >= 1) return +valueof(values[n - 1], n - 1, values);
321 var n,
322 i = (n - 1) * p,
323 i0 = Math.floor(i),
324 value0 = +valueof(values[i0], i0, values),
325 value1 = +valueof(values[i0 + 1], i0 + 1, values);
326 return value0 + (value1 - value0) * (i - i0);
327}
328
329function freedmanDiaconis(values, min, max) {
330 values = map.call(values, number).sort(ascending);
331 return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
332}
333
334function scott(values, min, max) {
335 return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
336}
337
338function max(values, valueof) {
339 var n = values.length,
340 i = -1,
341 value,
342 max;
343
344 if (valueof == null) {
345 while (++i < n) { // Find the first comparable value.
346 if ((value = values[i]) != null && value >= value) {
347 max = value;
348 while (++i < n) { // Compare the remaining values.
349 if ((value = values[i]) != null && value > max) {
350 max = value;
351 }
352 }
353 }
354 }
355 }
356
357 else {
358 while (++i < n) { // Find the first comparable value.
359 if ((value = valueof(values[i], i, values)) != null && value >= value) {
360 max = value;
361 while (++i < n) { // Compare the remaining values.
362 if ((value = valueof(values[i], i, values)) != null && value > max) {
363 max = value;
364 }
365 }
366 }
367 }
368 }
369
370 return max;
371}
372
373function mean(values, valueof) {
374 var n = values.length,
375 m = n,
376 i = -1,
377 value,
378 sum = 0;
379
380 if (valueof == null) {
381 while (++i < n) {
382 if (!isNaN(value = number(values[i]))) sum += value;
383 else --m;
384 }
385 }
386
387 else {
388 while (++i < n) {
389 if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
390 else --m;
391 }
392 }
393
394 if (m) return sum / m;
395}
396
397function median(values, valueof) {
398 var n = values.length,
399 i = -1,
400 value,
401 numbers = [];
402
403 if (valueof == null) {
404 while (++i < n) {
405 if (!isNaN(value = number(values[i]))) {
406 numbers.push(value);
407 }
408 }
409 }
410
411 else {
412 while (++i < n) {
413 if (!isNaN(value = number(valueof(values[i], i, values)))) {
414 numbers.push(value);
415 }
416 }
417 }
418
419 return threshold(numbers.sort(ascending), 0.5);
420}
421
422function merge(arrays) {
423 var n = arrays.length,
424 m,
425 i = -1,
426 j = 0,
427 merged,
428 array;
429
430 while (++i < n) j += arrays[i].length;
431 merged = new Array(j);
432
433 while (--n >= 0) {
434 array = arrays[n];
435 m = array.length;
436 while (--m >= 0) {
437 merged[--j] = array[m];
438 }
439 }
440
441 return merged;
442}
443
444function min(values, valueof) {
445 var n = values.length,
446 i = -1,
447 value,
448 min;
449
450 if (valueof == null) {
451 while (++i < n) { // Find the first comparable value.
452 if ((value = values[i]) != null && value >= value) {
453 min = value;
454 while (++i < n) { // Compare the remaining values.
455 if ((value = values[i]) != null && min > value) {
456 min = value;
457 }
458 }
459 }
460 }
461 }
462
463 else {
464 while (++i < n) { // Find the first comparable value.
465 if ((value = valueof(values[i], i, values)) != null && value >= value) {
466 min = value;
467 while (++i < n) { // Compare the remaining values.
468 if ((value = valueof(values[i], i, values)) != null && min > value) {
469 min = value;
470 }
471 }
472 }
473 }
474 }
475
476 return min;
477}
478
479function permute(array, indexes) {
480 var i = indexes.length, permutes = new Array(i);
481 while (i--) permutes[i] = array[indexes[i]];
482 return permutes;
483}
484
485function scan(values, compare) {
486 if (!(n = values.length)) return;
487 var n,
488 i = 0,
489 j = 0,
490 xi,
491 xj = values[j];
492
493 if (compare == null) compare = ascending;
494
495 while (++i < n) {
496 if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
497 xj = xi, j = i;
498 }
499 }
500
501 if (compare(xj, xj) === 0) return j;
502}
503
504function shuffle(array, i0, i1) {
505 var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
506 t,
507 i;
508
509 while (m) {
510 i = Math.random() * m-- | 0;
511 t = array[m + i0];
512 array[m + i0] = array[i + i0];
513 array[i + i0] = t;
514 }
515
516 return array;
517}
518
519function sum(values, valueof) {
520 var n = values.length,
521 i = -1,
522 value,
523 sum = 0;
524
525 if (valueof == null) {
526 while (++i < n) {
527 if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
528 }
529 }
530
531 else {
532 while (++i < n) {
533 if (value = +valueof(values[i], i, values)) sum += value;
534 }
535 }
536
537 return sum;
538}
539
540function transpose(matrix) {
541 if (!(n = matrix.length)) return [];
542 for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
543 for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
544 row[j] = matrix[j][i];
545 }
546 }
547 return transpose;
548}
549
550function length(d) {
551 return d.length;
552}
553
554function zip() {
555 return transpose(arguments);
556}
557
558var slice$1 = Array.prototype.slice;
559
560function identity$1(x) {
561 return x;
562}
563
564var top = 1,
565 right = 2,
566 bottom = 3,
567 left = 4,
568 epsilon = 1e-6;
569
570function translateX(x) {
571 return "translate(" + (x + 0.5) + ",0)";
572}
573
574function translateY(y) {
575 return "translate(0," + (y + 0.5) + ")";
576}
577
578function number$1(scale) {
579 return function(d) {
580 return +scale(d);
581 };
582}
583
584function center(scale) {
585 var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
586 if (scale.round()) offset = Math.round(offset);
587 return function(d) {
588 return +scale(d) + offset;
589 };
590}
591
592function entering() {
593 return !this.__axis;
594}
595
596function axis(orient, scale) {
597 var tickArguments = [],
598 tickValues = null,
599 tickFormat = null,
600 tickSizeInner = 6,
601 tickSizeOuter = 6,
602 tickPadding = 3,
603 k = orient === top || orient === left ? -1 : 1,
604 x = orient === left || orient === right ? "x" : "y",
605 transform = orient === top || orient === bottom ? translateX : translateY;
606
607 function axis(context) {
608 var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
609 format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
610 spacing = Math.max(tickSizeInner, 0) + tickPadding,
611 range = scale.range(),
612 range0 = +range[0] + 0.5,
613 range1 = +range[range.length - 1] + 0.5,
614 position = (scale.bandwidth ? center : number$1)(scale.copy()),
615 selection = context.selection ? context.selection() : context,
616 path = selection.selectAll(".domain").data([null]),
617 tick = selection.selectAll(".tick").data(values, scale).order(),
618 tickExit = tick.exit(),
619 tickEnter = tick.enter().append("g").attr("class", "tick"),
620 line = tick.select("line"),
621 text = tick.select("text");
622
623 path = path.merge(path.enter().insert("path", ".tick")
624 .attr("class", "domain")
625 .attr("stroke", "currentColor"));
626
627 tick = tick.merge(tickEnter);
628
629 line = line.merge(tickEnter.append("line")
630 .attr("stroke", "currentColor")
631 .attr(x + "2", k * tickSizeInner));
632
633 text = text.merge(tickEnter.append("text")
634 .attr("fill", "currentColor")
635 .attr(x, k * spacing)
636 .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
637
638 if (context !== selection) {
639 path = path.transition(context);
640 tick = tick.transition(context);
641 line = line.transition(context);
642 text = text.transition(context);
643
644 tickExit = tickExit.transition(context)
645 .attr("opacity", epsilon)
646 .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
647
648 tickEnter
649 .attr("opacity", epsilon)
650 .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
651 }
652
653 tickExit.remove();
654
655 path
656 .attr("d", orient === left || orient == right
657 ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M0.5," + range0 + "V" + range1)
658 : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + ",0.5H" + range1));
659
660 tick
661 .attr("opacity", 1)
662 .attr("transform", function(d) { return transform(position(d)); });
663
664 line
665 .attr(x + "2", k * tickSizeInner);
666
667 text
668 .attr(x, k * spacing)
669 .text(format);
670
671 selection.filter(entering)
672 .attr("fill", "none")
673 .attr("font-size", 10)
674 .attr("font-family", "sans-serif")
675 .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
676
677 selection
678 .each(function() { this.__axis = position; });
679 }
680
681 axis.scale = function(_) {
682 return arguments.length ? (scale = _, axis) : scale;
683 };
684
685 axis.ticks = function() {
686 return tickArguments = slice$1.call(arguments), axis;
687 };
688
689 axis.tickArguments = function(_) {
690 return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
691 };
692
693 axis.tickValues = function(_) {
694 return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
695 };
696
697 axis.tickFormat = function(_) {
698 return arguments.length ? (tickFormat = _, axis) : tickFormat;
699 };
700
701 axis.tickSize = function(_) {
702 return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
703 };
704
705 axis.tickSizeInner = function(_) {
706 return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
707 };
708
709 axis.tickSizeOuter = function(_) {
710 return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
711 };
712
713 axis.tickPadding = function(_) {
714 return arguments.length ? (tickPadding = +_, axis) : tickPadding;
715 };
716
717 return axis;
718}
719
720function axisTop(scale) {
721 return axis(top, scale);
722}
723
724function axisRight(scale) {
725 return axis(right, scale);
726}
727
728function axisBottom(scale) {
729 return axis(bottom, scale);
730}
731
732function axisLeft(scale) {
733 return axis(left, scale);
734}
735
736var noop = {value: function() {}};
737
738function dispatch() {
739 for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
740 if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
741 _[t] = [];
742 }
743 return new Dispatch(_);
744}
745
746function Dispatch(_) {
747 this._ = _;
748}
749
750function parseTypenames(typenames, types) {
751 return typenames.trim().split(/^|\s+/).map(function(t) {
752 var name = "", i = t.indexOf(".");
753 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
754 if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
755 return {type: t, name: name};
756 });
757}
758
759Dispatch.prototype = dispatch.prototype = {
760 constructor: Dispatch,
761 on: function(typename, callback) {
762 var _ = this._,
763 T = parseTypenames(typename + "", _),
764 t,
765 i = -1,
766 n = T.length;
767
768 // If no callback was specified, return the callback of the given type and name.
769 if (arguments.length < 2) {
770 while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
771 return;
772 }
773
774 // If a type was specified, set the callback for the given type and name.
775 // Otherwise, if a null callback was specified, remove callbacks of the given name.
776 if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
777 while (++i < n) {
778 if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
779 else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
780 }
781
782 return this;
783 },
784 copy: function() {
785 var copy = {}, _ = this._;
786 for (var t in _) copy[t] = _[t].slice();
787 return new Dispatch(copy);
788 },
789 call: function(type, that) {
790 if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
791 if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
792 for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
793 },
794 apply: function(type, that, args) {
795 if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
796 for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
797 }
798};
799
800function get(type, name) {
801 for (var i = 0, n = type.length, c; i < n; ++i) {
802 if ((c = type[i]).name === name) {
803 return c.value;
804 }
805 }
806}
807
808function set(type, name, callback) {
809 for (var i = 0, n = type.length; i < n; ++i) {
810 if (type[i].name === name) {
811 type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
812 break;
813 }
814 }
815 if (callback != null) type.push({name: name, value: callback});
816 return type;
817}
818
819var xhtml = "http://www.w3.org/1999/xhtml";
820
821var namespaces = {
822 svg: "http://www.w3.org/2000/svg",
823 xhtml: xhtml,
824 xlink: "http://www.w3.org/1999/xlink",
825 xml: "http://www.w3.org/XML/1998/namespace",
826 xmlns: "http://www.w3.org/2000/xmlns/"
827};
828
829function namespace(name) {
830 var prefix = name += "", i = prefix.indexOf(":");
831 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
832 return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
833}
834
835function creatorInherit(name) {
836 return function() {
837 var document = this.ownerDocument,
838 uri = this.namespaceURI;
839 return uri === xhtml && document.documentElement.namespaceURI === xhtml
840 ? document.createElement(name)
841 : document.createElementNS(uri, name);
842 };
843}
844
845function creatorFixed(fullname) {
846 return function() {
847 return this.ownerDocument.createElementNS(fullname.space, fullname.local);
848 };
849}
850
851function creator(name) {
852 var fullname = namespace(name);
853 return (fullname.local
854 ? creatorFixed
855 : creatorInherit)(fullname);
856}
857
858function none() {}
859
860function selector(selector) {
861 return selector == null ? none : function() {
862 return this.querySelector(selector);
863 };
864}
865
866function selection_select(select) {
867 if (typeof select !== "function") select = selector(select);
868
869 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
870 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
871 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
872 if ("__data__" in node) subnode.__data__ = node.__data__;
873 subgroup[i] = subnode;
874 }
875 }
876 }
877
878 return new Selection(subgroups, this._parents);
879}
880
881function empty() {
882 return [];
883}
884
885function selectorAll(selector) {
886 return selector == null ? empty : function() {
887 return this.querySelectorAll(selector);
888 };
889}
890
891function selection_selectAll(select) {
892 if (typeof select !== "function") select = selectorAll(select);
893
894 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
895 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
896 if (node = group[i]) {
897 subgroups.push(select.call(node, node.__data__, i, group));
898 parents.push(node);
899 }
900 }
901 }
902
903 return new Selection(subgroups, parents);
904}
905
906function matcher(selector) {
907 return function() {
908 return this.matches(selector);
909 };
910}
911
912function selection_filter(match) {
913 if (typeof match !== "function") match = matcher(match);
914
915 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
916 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
917 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
918 subgroup.push(node);
919 }
920 }
921 }
922
923 return new Selection(subgroups, this._parents);
924}
925
926function sparse(update) {
927 return new Array(update.length);
928}
929
930function selection_enter() {
931 return new Selection(this._enter || this._groups.map(sparse), this._parents);
932}
933
934function EnterNode(parent, datum) {
935 this.ownerDocument = parent.ownerDocument;
936 this.namespaceURI = parent.namespaceURI;
937 this._next = null;
938 this._parent = parent;
939 this.__data__ = datum;
940}
941
942EnterNode.prototype = {
943 constructor: EnterNode,
944 appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
945 insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
946 querySelector: function(selector) { return this._parent.querySelector(selector); },
947 querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
948};
949
950function constant$1(x) {
951 return function() {
952 return x;
953 };
954}
955
956var keyPrefix = "$"; // Protect against keys like “__proto__”.
957
958function bindIndex(parent, group, enter, update, exit, data) {
959 var i = 0,
960 node,
961 groupLength = group.length,
962 dataLength = data.length;
963
964 // Put any non-null nodes that fit into update.
965 // Put any null nodes into enter.
966 // Put any remaining data into enter.
967 for (; i < dataLength; ++i) {
968 if (node = group[i]) {
969 node.__data__ = data[i];
970 update[i] = node;
971 } else {
972 enter[i] = new EnterNode(parent, data[i]);
973 }
974 }
975
976 // Put any non-null nodes that don’t fit into exit.
977 for (; i < groupLength; ++i) {
978 if (node = group[i]) {
979 exit[i] = node;
980 }
981 }
982}
983
984function bindKey(parent, group, enter, update, exit, data, key) {
985 var i,
986 node,
987 nodeByKeyValue = {},
988 groupLength = group.length,
989 dataLength = data.length,
990 keyValues = new Array(groupLength),
991 keyValue;
992
993 // Compute the key for each node.
994 // If multiple nodes have the same key, the duplicates are added to exit.
995 for (i = 0; i < groupLength; ++i) {
996 if (node = group[i]) {
997 keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
998 if (keyValue in nodeByKeyValue) {
999 exit[i] = node;
1000 } else {
1001 nodeByKeyValue[keyValue] = node;
1002 }
1003 }
1004 }
1005
1006 // Compute the key for each datum.
1007 // If there a node associated with this key, join and add it to update.
1008 // If there is not (or the key is a duplicate), add it to enter.
1009 for (i = 0; i < dataLength; ++i) {
1010 keyValue = keyPrefix + key.call(parent, data[i], i, data);
1011 if (node = nodeByKeyValue[keyValue]) {
1012 update[i] = node;
1013 node.__data__ = data[i];
1014 nodeByKeyValue[keyValue] = null;
1015 } else {
1016 enter[i] = new EnterNode(parent, data[i]);
1017 }
1018 }
1019
1020 // Add any remaining nodes that were not bound to data to exit.
1021 for (i = 0; i < groupLength; ++i) {
1022 if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
1023 exit[i] = node;
1024 }
1025 }
1026}
1027
1028function selection_data(value, key) {
1029 if (!value) {
1030 data = new Array(this.size()), j = -1;
1031 this.each(function(d) { data[++j] = d; });
1032 return data;
1033 }
1034
1035 var bind = key ? bindKey : bindIndex,
1036 parents = this._parents,
1037 groups = this._groups;
1038
1039 if (typeof value !== "function") value = constant$1(value);
1040
1041 for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
1042 var parent = parents[j],
1043 group = groups[j],
1044 groupLength = group.length,
1045 data = value.call(parent, parent && parent.__data__, j, parents),
1046 dataLength = data.length,
1047 enterGroup = enter[j] = new Array(dataLength),
1048 updateGroup = update[j] = new Array(dataLength),
1049 exitGroup = exit[j] = new Array(groupLength);
1050
1051 bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
1052
1053 // Now connect the enter nodes to their following update node, such that
1054 // appendChild can insert the materialized enter node before this node,
1055 // rather than at the end of the parent node.
1056 for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
1057 if (previous = enterGroup[i0]) {
1058 if (i0 >= i1) i1 = i0 + 1;
1059 while (!(next = updateGroup[i1]) && ++i1 < dataLength);
1060 previous._next = next || null;
1061 }
1062 }
1063 }
1064
1065 update = new Selection(update, parents);
1066 update._enter = enter;
1067 update._exit = exit;
1068 return update;
1069}
1070
1071function selection_exit() {
1072 return new Selection(this._exit || this._groups.map(sparse), this._parents);
1073}
1074
1075function selection_join(onenter, onupdate, onexit) {
1076 var enter = this.enter(), update = this, exit = this.exit();
1077 enter = typeof onenter === "function" ? onenter(enter) : enter.append(onenter + "");
1078 if (onupdate != null) update = onupdate(update);
1079 if (onexit == null) exit.remove(); else onexit(exit);
1080 return enter && update ? enter.merge(update).order() : update;
1081}
1082
1083function selection_merge(selection) {
1084
1085 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) {
1086 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
1087 if (node = group0[i] || group1[i]) {
1088 merge[i] = node;
1089 }
1090 }
1091 }
1092
1093 for (; j < m0; ++j) {
1094 merges[j] = groups0[j];
1095 }
1096
1097 return new Selection(merges, this._parents);
1098}
1099
1100function selection_order() {
1101
1102 for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
1103 for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
1104 if (node = group[i]) {
1105 if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
1106 next = node;
1107 }
1108 }
1109 }
1110
1111 return this;
1112}
1113
1114function selection_sort(compare) {
1115 if (!compare) compare = ascending$1;
1116
1117 function compareNode(a, b) {
1118 return a && b ? compare(a.__data__, b.__data__) : !a - !b;
1119 }
1120
1121 for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
1122 for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
1123 if (node = group[i]) {
1124 sortgroup[i] = node;
1125 }
1126 }
1127 sortgroup.sort(compareNode);
1128 }
1129
1130 return new Selection(sortgroups, this._parents).order();
1131}
1132
1133function ascending$1(a, b) {
1134 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
1135}
1136
1137function selection_call() {
1138 var callback = arguments[0];
1139 arguments[0] = this;
1140 callback.apply(null, arguments);
1141 return this;
1142}
1143
1144function selection_nodes() {
1145 var nodes = new Array(this.size()), i = -1;
1146 this.each(function() { nodes[++i] = this; });
1147 return nodes;
1148}
1149
1150function selection_node() {
1151
1152 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1153 for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
1154 var node = group[i];
1155 if (node) return node;
1156 }
1157 }
1158
1159 return null;
1160}
1161
1162function selection_size() {
1163 var size = 0;
1164 this.each(function() { ++size; });
1165 return size;
1166}
1167
1168function selection_empty() {
1169 return !this.node();
1170}
1171
1172function selection_each(callback) {
1173
1174 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1175 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
1176 if (node = group[i]) callback.call(node, node.__data__, i, group);
1177 }
1178 }
1179
1180 return this;
1181}
1182
1183function attrRemove(name) {
1184 return function() {
1185 this.removeAttribute(name);
1186 };
1187}
1188
1189function attrRemoveNS(fullname) {
1190 return function() {
1191 this.removeAttributeNS(fullname.space, fullname.local);
1192 };
1193}
1194
1195function attrConstant(name, value) {
1196 return function() {
1197 this.setAttribute(name, value);
1198 };
1199}
1200
1201function attrConstantNS(fullname, value) {
1202 return function() {
1203 this.setAttributeNS(fullname.space, fullname.local, value);
1204 };
1205}
1206
1207function attrFunction(name, value) {
1208 return function() {
1209 var v = value.apply(this, arguments);
1210 if (v == null) this.removeAttribute(name);
1211 else this.setAttribute(name, v);
1212 };
1213}
1214
1215function attrFunctionNS(fullname, value) {
1216 return function() {
1217 var v = value.apply(this, arguments);
1218 if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
1219 else this.setAttributeNS(fullname.space, fullname.local, v);
1220 };
1221}
1222
1223function selection_attr(name, value) {
1224 var fullname = namespace(name);
1225
1226 if (arguments.length < 2) {
1227 var node = this.node();
1228 return fullname.local
1229 ? node.getAttributeNS(fullname.space, fullname.local)
1230 : node.getAttribute(fullname);
1231 }
1232
1233 return this.each((value == null
1234 ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
1235 ? (fullname.local ? attrFunctionNS : attrFunction)
1236 : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
1237}
1238
1239function defaultView(node) {
1240 return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
1241 || (node.document && node) // node is a Window
1242 || node.defaultView; // node is a Document
1243}
1244
1245function styleRemove(name) {
1246 return function() {
1247 this.style.removeProperty(name);
1248 };
1249}
1250
1251function styleConstant(name, value, priority) {
1252 return function() {
1253 this.style.setProperty(name, value, priority);
1254 };
1255}
1256
1257function styleFunction(name, value, priority) {
1258 return function() {
1259 var v = value.apply(this, arguments);
1260 if (v == null) this.style.removeProperty(name);
1261 else this.style.setProperty(name, v, priority);
1262 };
1263}
1264
1265function selection_style(name, value, priority) {
1266 return arguments.length > 1
1267 ? this.each((value == null
1268 ? styleRemove : typeof value === "function"
1269 ? styleFunction
1270 : styleConstant)(name, value, priority == null ? "" : priority))
1271 : styleValue(this.node(), name);
1272}
1273
1274function styleValue(node, name) {
1275 return node.style.getPropertyValue(name)
1276 || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
1277}
1278
1279function propertyRemove(name) {
1280 return function() {
1281 delete this[name];
1282 };
1283}
1284
1285function propertyConstant(name, value) {
1286 return function() {
1287 this[name] = value;
1288 };
1289}
1290
1291function propertyFunction(name, value) {
1292 return function() {
1293 var v = value.apply(this, arguments);
1294 if (v == null) delete this[name];
1295 else this[name] = v;
1296 };
1297}
1298
1299function selection_property(name, value) {
1300 return arguments.length > 1
1301 ? this.each((value == null
1302 ? propertyRemove : typeof value === "function"
1303 ? propertyFunction
1304 : propertyConstant)(name, value))
1305 : this.node()[name];
1306}
1307
1308function classArray(string) {
1309 return string.trim().split(/^|\s+/);
1310}
1311
1312function classList(node) {
1313 return node.classList || new ClassList(node);
1314}
1315
1316function ClassList(node) {
1317 this._node = node;
1318 this._names = classArray(node.getAttribute("class") || "");
1319}
1320
1321ClassList.prototype = {
1322 add: function(name) {
1323 var i = this._names.indexOf(name);
1324 if (i < 0) {
1325 this._names.push(name);
1326 this._node.setAttribute("class", this._names.join(" "));
1327 }
1328 },
1329 remove: function(name) {
1330 var i = this._names.indexOf(name);
1331 if (i >= 0) {
1332 this._names.splice(i, 1);
1333 this._node.setAttribute("class", this._names.join(" "));
1334 }
1335 },
1336 contains: function(name) {
1337 return this._names.indexOf(name) >= 0;
1338 }
1339};
1340
1341function classedAdd(node, names) {
1342 var list = classList(node), i = -1, n = names.length;
1343 while (++i < n) list.add(names[i]);
1344}
1345
1346function classedRemove(node, names) {
1347 var list = classList(node), i = -1, n = names.length;
1348 while (++i < n) list.remove(names[i]);
1349}
1350
1351function classedTrue(names) {
1352 return function() {
1353 classedAdd(this, names);
1354 };
1355}
1356
1357function classedFalse(names) {
1358 return function() {
1359 classedRemove(this, names);
1360 };
1361}
1362
1363function classedFunction(names, value) {
1364 return function() {
1365 (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
1366 };
1367}
1368
1369function selection_classed(name, value) {
1370 var names = classArray(name + "");
1371
1372 if (arguments.length < 2) {
1373 var list = classList(this.node()), i = -1, n = names.length;
1374 while (++i < n) if (!list.contains(names[i])) return false;
1375 return true;
1376 }
1377
1378 return this.each((typeof value === "function"
1379 ? classedFunction : value
1380 ? classedTrue
1381 : classedFalse)(names, value));
1382}
1383
1384function textRemove() {
1385 this.textContent = "";
1386}
1387
1388function textConstant(value) {
1389 return function() {
1390 this.textContent = value;
1391 };
1392}
1393
1394function textFunction(value) {
1395 return function() {
1396 var v = value.apply(this, arguments);
1397 this.textContent = v == null ? "" : v;
1398 };
1399}
1400
1401function selection_text(value) {
1402 return arguments.length
1403 ? this.each(value == null
1404 ? textRemove : (typeof value === "function"
1405 ? textFunction
1406 : textConstant)(value))
1407 : this.node().textContent;
1408}
1409
1410function htmlRemove() {
1411 this.innerHTML = "";
1412}
1413
1414function htmlConstant(value) {
1415 return function() {
1416 this.innerHTML = value;
1417 };
1418}
1419
1420function htmlFunction(value) {
1421 return function() {
1422 var v = value.apply(this, arguments);
1423 this.innerHTML = v == null ? "" : v;
1424 };
1425}
1426
1427function selection_html(value) {
1428 return arguments.length
1429 ? this.each(value == null
1430 ? htmlRemove : (typeof value === "function"
1431 ? htmlFunction
1432 : htmlConstant)(value))
1433 : this.node().innerHTML;
1434}
1435
1436function raise() {
1437 if (this.nextSibling) this.parentNode.appendChild(this);
1438}
1439
1440function selection_raise() {
1441 return this.each(raise);
1442}
1443
1444function lower() {
1445 if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
1446}
1447
1448function selection_lower() {
1449 return this.each(lower);
1450}
1451
1452function selection_append(name) {
1453 var create = typeof name === "function" ? name : creator(name);
1454 return this.select(function() {
1455 return this.appendChild(create.apply(this, arguments));
1456 });
1457}
1458
1459function constantNull() {
1460 return null;
1461}
1462
1463function selection_insert(name, before) {
1464 var create = typeof name === "function" ? name : creator(name),
1465 select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
1466 return this.select(function() {
1467 return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
1468 });
1469}
1470
1471function remove() {
1472 var parent = this.parentNode;
1473 if (parent) parent.removeChild(this);
1474}
1475
1476function selection_remove() {
1477 return this.each(remove);
1478}
1479
1480function selection_cloneShallow() {
1481 var clone = this.cloneNode(false), parent = this.parentNode;
1482 return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
1483}
1484
1485function selection_cloneDeep() {
1486 var clone = this.cloneNode(true), parent = this.parentNode;
1487 return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
1488}
1489
1490function selection_clone(deep) {
1491 return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
1492}
1493
1494function selection_datum(value) {
1495 return arguments.length
1496 ? this.property("__data__", value)
1497 : this.node().__data__;
1498}
1499
1500var filterEvents = {};
1501
1502exports.event = null;
1503
1504if (typeof document !== "undefined") {
1505 var element = document.documentElement;
1506 if (!("onmouseenter" in element)) {
1507 filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
1508 }
1509}
1510
1511function filterContextListener(listener, index, group) {
1512 listener = contextListener(listener, index, group);
1513 return function(event) {
1514 var related = event.relatedTarget;
1515 if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
1516 listener.call(this, event);
1517 }
1518 };
1519}
1520
1521function contextListener(listener, index, group) {
1522 return function(event1) {
1523 var event0 = exports.event; // Events can be reentrant (e.g., focus).
1524 exports.event = event1;
1525 try {
1526 listener.call(this, this.__data__, index, group);
1527 } finally {
1528 exports.event = event0;
1529 }
1530 };
1531}
1532
1533function parseTypenames$1(typenames) {
1534 return typenames.trim().split(/^|\s+/).map(function(t) {
1535 var name = "", i = t.indexOf(".");
1536 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
1537 return {type: t, name: name};
1538 });
1539}
1540
1541function onRemove(typename) {
1542 return function() {
1543 var on = this.__on;
1544 if (!on) return;
1545 for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
1546 if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
1547 this.removeEventListener(o.type, o.listener, o.capture);
1548 } else {
1549 on[++i] = o;
1550 }
1551 }
1552 if (++i) on.length = i;
1553 else delete this.__on;
1554 };
1555}
1556
1557function onAdd(typename, value, capture) {
1558 var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
1559 return function(d, i, group) {
1560 var on = this.__on, o, listener = wrap(value, i, group);
1561 if (on) for (var j = 0, m = on.length; j < m; ++j) {
1562 if ((o = on[j]).type === typename.type && o.name === typename.name) {
1563 this.removeEventListener(o.type, o.listener, o.capture);
1564 this.addEventListener(o.type, o.listener = listener, o.capture = capture);
1565 o.value = value;
1566 return;
1567 }
1568 }
1569 this.addEventListener(typename.type, listener, capture);
1570 o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
1571 if (!on) this.__on = [o];
1572 else on.push(o);
1573 };
1574}
1575
1576function selection_on(typename, value, capture) {
1577 var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
1578
1579 if (arguments.length < 2) {
1580 var on = this.node().__on;
1581 if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
1582 for (i = 0, o = on[j]; i < n; ++i) {
1583 if ((t = typenames[i]).type === o.type && t.name === o.name) {
1584 return o.value;
1585 }
1586 }
1587 }
1588 return;
1589 }
1590
1591 on = value ? onAdd : onRemove;
1592 if (capture == null) capture = false;
1593 for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
1594 return this;
1595}
1596
1597function customEvent(event1, listener, that, args) {
1598 var event0 = exports.event;
1599 event1.sourceEvent = exports.event;
1600 exports.event = event1;
1601 try {
1602 return listener.apply(that, args);
1603 } finally {
1604 exports.event = event0;
1605 }
1606}
1607
1608function dispatchEvent(node, type, params) {
1609 var window = defaultView(node),
1610 event = window.CustomEvent;
1611
1612 if (typeof event === "function") {
1613 event = new event(type, params);
1614 } else {
1615 event = window.document.createEvent("Event");
1616 if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
1617 else event.initEvent(type, false, false);
1618 }
1619
1620 node.dispatchEvent(event);
1621}
1622
1623function dispatchConstant(type, params) {
1624 return function() {
1625 return dispatchEvent(this, type, params);
1626 };
1627}
1628
1629function dispatchFunction(type, params) {
1630 return function() {
1631 return dispatchEvent(this, type, params.apply(this, arguments));
1632 };
1633}
1634
1635function selection_dispatch(type, params) {
1636 return this.each((typeof params === "function"
1637 ? dispatchFunction
1638 : dispatchConstant)(type, params));
1639}
1640
1641var root = [null];
1642
1643function Selection(groups, parents) {
1644 this._groups = groups;
1645 this._parents = parents;
1646}
1647
1648function selection() {
1649 return new Selection([[document.documentElement]], root);
1650}
1651
1652Selection.prototype = selection.prototype = {
1653 constructor: Selection,
1654 select: selection_select,
1655 selectAll: selection_selectAll,
1656 filter: selection_filter,
1657 data: selection_data,
1658 enter: selection_enter,
1659 exit: selection_exit,
1660 join: selection_join,
1661 merge: selection_merge,
1662 order: selection_order,
1663 sort: selection_sort,
1664 call: selection_call,
1665 nodes: selection_nodes,
1666 node: selection_node,
1667 size: selection_size,
1668 empty: selection_empty,
1669 each: selection_each,
1670 attr: selection_attr,
1671 style: selection_style,
1672 property: selection_property,
1673 classed: selection_classed,
1674 text: selection_text,
1675 html: selection_html,
1676 raise: selection_raise,
1677 lower: selection_lower,
1678 append: selection_append,
1679 insert: selection_insert,
1680 remove: selection_remove,
1681 clone: selection_clone,
1682 datum: selection_datum,
1683 on: selection_on,
1684 dispatch: selection_dispatch
1685};
1686
1687function select(selector) {
1688 return typeof selector === "string"
1689 ? new Selection([[document.querySelector(selector)]], [document.documentElement])
1690 : new Selection([[selector]], root);
1691}
1692
1693function create(name) {
1694 return select(creator(name).call(document.documentElement));
1695}
1696
1697var nextId = 0;
1698
1699function local() {
1700 return new Local;
1701}
1702
1703function Local() {
1704 this._ = "@" + (++nextId).toString(36);
1705}
1706
1707Local.prototype = local.prototype = {
1708 constructor: Local,
1709 get: function(node) {
1710 var id = this._;
1711 while (!(id in node)) if (!(node = node.parentNode)) return;
1712 return node[id];
1713 },
1714 set: function(node, value) {
1715 return node[this._] = value;
1716 },
1717 remove: function(node) {
1718 return this._ in node && delete node[this._];
1719 },
1720 toString: function() {
1721 return this._;
1722 }
1723};
1724
1725function sourceEvent() {
1726 var current = exports.event, source;
1727 while (source = current.sourceEvent) current = source;
1728 return current;
1729}
1730
1731function point(node, event) {
1732 var svg = node.ownerSVGElement || node;
1733
1734 if (svg.createSVGPoint) {
1735 var point = svg.createSVGPoint();
1736 point.x = event.clientX, point.y = event.clientY;
1737 point = point.matrixTransform(node.getScreenCTM().inverse());
1738 return [point.x, point.y];
1739 }
1740
1741 var rect = node.getBoundingClientRect();
1742 return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
1743}
1744
1745function mouse(node) {
1746 var event = sourceEvent();
1747 if (event.changedTouches) event = event.changedTouches[0];
1748 return point(node, event);
1749}
1750
1751function selectAll(selector) {
1752 return typeof selector === "string"
1753 ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
1754 : new Selection([selector == null ? [] : selector], root);
1755}
1756
1757function touch(node, touches, identifier) {
1758 if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
1759
1760 for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
1761 if ((touch = touches[i]).identifier === identifier) {
1762 return point(node, touch);
1763 }
1764 }
1765
1766 return null;
1767}
1768
1769function touches(node, touches) {
1770 if (touches == null) touches = sourceEvent().touches;
1771
1772 for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
1773 points[i] = point(node, touches[i]);
1774 }
1775
1776 return points;
1777}
1778
1779function nopropagation() {
1780 exports.event.stopImmediatePropagation();
1781}
1782
1783function noevent() {
1784 exports.event.preventDefault();
1785 exports.event.stopImmediatePropagation();
1786}
1787
1788function dragDisable(view) {
1789 var root = view.document.documentElement,
1790 selection = select(view).on("dragstart.drag", noevent, true);
1791 if ("onselectstart" in root) {
1792 selection.on("selectstart.drag", noevent, true);
1793 } else {
1794 root.__noselect = root.style.MozUserSelect;
1795 root.style.MozUserSelect = "none";
1796 }
1797}
1798
1799function yesdrag(view, noclick) {
1800 var root = view.document.documentElement,
1801 selection = select(view).on("dragstart.drag", null);
1802 if (noclick) {
1803 selection.on("click.drag", noevent, true);
1804 setTimeout(function() { selection.on("click.drag", null); }, 0);
1805 }
1806 if ("onselectstart" in root) {
1807 selection.on("selectstart.drag", null);
1808 } else {
1809 root.style.MozUserSelect = root.__noselect;
1810 delete root.__noselect;
1811 }
1812}
1813
1814function constant$2(x) {
1815 return function() {
1816 return x;
1817 };
1818}
1819
1820function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
1821 this.target = target;
1822 this.type = type;
1823 this.subject = subject;
1824 this.identifier = id;
1825 this.active = active;
1826 this.x = x;
1827 this.y = y;
1828 this.dx = dx;
1829 this.dy = dy;
1830 this._ = dispatch;
1831}
1832
1833DragEvent.prototype.on = function() {
1834 var value = this._.on.apply(this._, arguments);
1835 return value === this._ ? this : value;
1836};
1837
1838// Ignore right-click, since that should open the context menu.
1839function defaultFilter() {
1840 return !exports.event.ctrlKey && !exports.event.button;
1841}
1842
1843function defaultContainer() {
1844 return this.parentNode;
1845}
1846
1847function defaultSubject(d) {
1848 return d == null ? {x: exports.event.x, y: exports.event.y} : d;
1849}
1850
1851function defaultTouchable() {
1852 return navigator.maxTouchPoints || ("ontouchstart" in this);
1853}
1854
1855function drag() {
1856 var filter = defaultFilter,
1857 container = defaultContainer,
1858 subject = defaultSubject,
1859 touchable = defaultTouchable,
1860 gestures = {},
1861 listeners = dispatch("start", "drag", "end"),
1862 active = 0,
1863 mousedownx,
1864 mousedowny,
1865 mousemoving,
1866 touchending,
1867 clickDistance2 = 0;
1868
1869 function drag(selection) {
1870 selection
1871 .on("mousedown.drag", mousedowned)
1872 .filter(touchable)
1873 .on("touchstart.drag", touchstarted)
1874 .on("touchmove.drag", touchmoved)
1875 .on("touchend.drag touchcancel.drag", touchended)
1876 .style("touch-action", "none")
1877 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
1878 }
1879
1880 function mousedowned() {
1881 if (touchending || !filter.apply(this, arguments)) return;
1882 var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
1883 if (!gesture) return;
1884 select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
1885 dragDisable(exports.event.view);
1886 nopropagation();
1887 mousemoving = false;
1888 mousedownx = exports.event.clientX;
1889 mousedowny = exports.event.clientY;
1890 gesture("start");
1891 }
1892
1893 function mousemoved() {
1894 noevent();
1895 if (!mousemoving) {
1896 var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
1897 mousemoving = dx * dx + dy * dy > clickDistance2;
1898 }
1899 gestures.mouse("drag");
1900 }
1901
1902 function mouseupped() {
1903 select(exports.event.view).on("mousemove.drag mouseup.drag", null);
1904 yesdrag(exports.event.view, mousemoving);
1905 noevent();
1906 gestures.mouse("end");
1907 }
1908
1909 function touchstarted() {
1910 if (!filter.apply(this, arguments)) return;
1911 var touches = exports.event.changedTouches,
1912 c = container.apply(this, arguments),
1913 n = touches.length, i, gesture;
1914
1915 for (i = 0; i < n; ++i) {
1916 if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
1917 nopropagation();
1918 gesture("start");
1919 }
1920 }
1921 }
1922
1923 function touchmoved() {
1924 var touches = exports.event.changedTouches,
1925 n = touches.length, i, gesture;
1926
1927 for (i = 0; i < n; ++i) {
1928 if (gesture = gestures[touches[i].identifier]) {
1929 noevent();
1930 gesture("drag");
1931 }
1932 }
1933 }
1934
1935 function touchended() {
1936 var touches = exports.event.changedTouches,
1937 n = touches.length, i, gesture;
1938
1939 if (touchending) clearTimeout(touchending);
1940 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
1941 for (i = 0; i < n; ++i) {
1942 if (gesture = gestures[touches[i].identifier]) {
1943 nopropagation();
1944 gesture("end");
1945 }
1946 }
1947 }
1948
1949 function beforestart(id, container, point, that, args) {
1950 var p = point(container, id), s, dx, dy,
1951 sublisteners = listeners.copy();
1952
1953 if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
1954 if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
1955 dx = s.x - p[0] || 0;
1956 dy = s.y - p[1] || 0;
1957 return true;
1958 })) return;
1959
1960 return function gesture(type) {
1961 var p0 = p, n;
1962 switch (type) {
1963 case "start": gestures[id] = gesture, n = active++; break;
1964 case "end": delete gestures[id], --active; // nobreak
1965 case "drag": p = point(container, id), n = active; break;
1966 }
1967 customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
1968 };
1969 }
1970
1971 drag.filter = function(_) {
1972 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
1973 };
1974
1975 drag.container = function(_) {
1976 return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
1977 };
1978
1979 drag.subject = function(_) {
1980 return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
1981 };
1982
1983 drag.touchable = function(_) {
1984 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
1985 };
1986
1987 drag.on = function() {
1988 var value = listeners.on.apply(listeners, arguments);
1989 return value === listeners ? drag : value;
1990 };
1991
1992 drag.clickDistance = function(_) {
1993 return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
1994 };
1995
1996 return drag;
1997}
1998
1999function define(constructor, factory, prototype) {
2000 constructor.prototype = factory.prototype = prototype;
2001 prototype.constructor = constructor;
2002}
2003
2004function extend(parent, definition) {
2005 var prototype = Object.create(parent.prototype);
2006 for (var key in definition) prototype[key] = definition[key];
2007 return prototype;
2008}
2009
2010function Color() {}
2011
2012var darker = 0.7;
2013var brighter = 1 / darker;
2014
2015var reI = "\\s*([+-]?\\d+)\\s*",
2016 reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
2017 reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
2018 reHex = /^#([0-9a-f]{3,8})$/,
2019 reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
2020 reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
2021 reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
2022 reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
2023 reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
2024 reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
2025
2026var named = {
2027 aliceblue: 0xf0f8ff,
2028 antiquewhite: 0xfaebd7,
2029 aqua: 0x00ffff,
2030 aquamarine: 0x7fffd4,
2031 azure: 0xf0ffff,
2032 beige: 0xf5f5dc,
2033 bisque: 0xffe4c4,
2034 black: 0x000000,
2035 blanchedalmond: 0xffebcd,
2036 blue: 0x0000ff,
2037 blueviolet: 0x8a2be2,
2038 brown: 0xa52a2a,
2039 burlywood: 0xdeb887,
2040 cadetblue: 0x5f9ea0,
2041 chartreuse: 0x7fff00,
2042 chocolate: 0xd2691e,
2043 coral: 0xff7f50,
2044 cornflowerblue: 0x6495ed,
2045 cornsilk: 0xfff8dc,
2046 crimson: 0xdc143c,
2047 cyan: 0x00ffff,
2048 darkblue: 0x00008b,
2049 darkcyan: 0x008b8b,
2050 darkgoldenrod: 0xb8860b,
2051 darkgray: 0xa9a9a9,
2052 darkgreen: 0x006400,
2053 darkgrey: 0xa9a9a9,
2054 darkkhaki: 0xbdb76b,
2055 darkmagenta: 0x8b008b,
2056 darkolivegreen: 0x556b2f,
2057 darkorange: 0xff8c00,
2058 darkorchid: 0x9932cc,
2059 darkred: 0x8b0000,
2060 darksalmon: 0xe9967a,
2061 darkseagreen: 0x8fbc8f,
2062 darkslateblue: 0x483d8b,
2063 darkslategray: 0x2f4f4f,
2064 darkslategrey: 0x2f4f4f,
2065 darkturquoise: 0x00ced1,
2066 darkviolet: 0x9400d3,
2067 deeppink: 0xff1493,
2068 deepskyblue: 0x00bfff,
2069 dimgray: 0x696969,
2070 dimgrey: 0x696969,
2071 dodgerblue: 0x1e90ff,
2072 firebrick: 0xb22222,
2073 floralwhite: 0xfffaf0,
2074 forestgreen: 0x228b22,
2075 fuchsia: 0xff00ff,
2076 gainsboro: 0xdcdcdc,
2077 ghostwhite: 0xf8f8ff,
2078 gold: 0xffd700,
2079 goldenrod: 0xdaa520,
2080 gray: 0x808080,
2081 green: 0x008000,
2082 greenyellow: 0xadff2f,
2083 grey: 0x808080,
2084 honeydew: 0xf0fff0,
2085 hotpink: 0xff69b4,
2086 indianred: 0xcd5c5c,
2087 indigo: 0x4b0082,
2088 ivory: 0xfffff0,
2089 khaki: 0xf0e68c,
2090 lavender: 0xe6e6fa,
2091 lavenderblush: 0xfff0f5,
2092 lawngreen: 0x7cfc00,
2093 lemonchiffon: 0xfffacd,
2094 lightblue: 0xadd8e6,
2095 lightcoral: 0xf08080,
2096 lightcyan: 0xe0ffff,
2097 lightgoldenrodyellow: 0xfafad2,
2098 lightgray: 0xd3d3d3,
2099 lightgreen: 0x90ee90,
2100 lightgrey: 0xd3d3d3,
2101 lightpink: 0xffb6c1,
2102 lightsalmon: 0xffa07a,
2103 lightseagreen: 0x20b2aa,
2104 lightskyblue: 0x87cefa,
2105 lightslategray: 0x778899,
2106 lightslategrey: 0x778899,
2107 lightsteelblue: 0xb0c4de,
2108 lightyellow: 0xffffe0,
2109 lime: 0x00ff00,
2110 limegreen: 0x32cd32,
2111 linen: 0xfaf0e6,
2112 magenta: 0xff00ff,
2113 maroon: 0x800000,
2114 mediumaquamarine: 0x66cdaa,
2115 mediumblue: 0x0000cd,
2116 mediumorchid: 0xba55d3,
2117 mediumpurple: 0x9370db,
2118 mediumseagreen: 0x3cb371,
2119 mediumslateblue: 0x7b68ee,
2120 mediumspringgreen: 0x00fa9a,
2121 mediumturquoise: 0x48d1cc,
2122 mediumvioletred: 0xc71585,
2123 midnightblue: 0x191970,
2124 mintcream: 0xf5fffa,
2125 mistyrose: 0xffe4e1,
2126 moccasin: 0xffe4b5,
2127 navajowhite: 0xffdead,
2128 navy: 0x000080,
2129 oldlace: 0xfdf5e6,
2130 olive: 0x808000,
2131 olivedrab: 0x6b8e23,
2132 orange: 0xffa500,
2133 orangered: 0xff4500,
2134 orchid: 0xda70d6,
2135 palegoldenrod: 0xeee8aa,
2136 palegreen: 0x98fb98,
2137 paleturquoise: 0xafeeee,
2138 palevioletred: 0xdb7093,
2139 papayawhip: 0xffefd5,
2140 peachpuff: 0xffdab9,
2141 peru: 0xcd853f,
2142 pink: 0xffc0cb,
2143 plum: 0xdda0dd,
2144 powderblue: 0xb0e0e6,
2145 purple: 0x800080,
2146 rebeccapurple: 0x663399,
2147 red: 0xff0000,
2148 rosybrown: 0xbc8f8f,
2149 royalblue: 0x4169e1,
2150 saddlebrown: 0x8b4513,
2151 salmon: 0xfa8072,
2152 sandybrown: 0xf4a460,
2153 seagreen: 0x2e8b57,
2154 seashell: 0xfff5ee,
2155 sienna: 0xa0522d,
2156 silver: 0xc0c0c0,
2157 skyblue: 0x87ceeb,
2158 slateblue: 0x6a5acd,
2159 slategray: 0x708090,
2160 slategrey: 0x708090,
2161 snow: 0xfffafa,
2162 springgreen: 0x00ff7f,
2163 steelblue: 0x4682b4,
2164 tan: 0xd2b48c,
2165 teal: 0x008080,
2166 thistle: 0xd8bfd8,
2167 tomato: 0xff6347,
2168 turquoise: 0x40e0d0,
2169 violet: 0xee82ee,
2170 wheat: 0xf5deb3,
2171 white: 0xffffff,
2172 whitesmoke: 0xf5f5f5,
2173 yellow: 0xffff00,
2174 yellowgreen: 0x9acd32
2175};
2176
2177define(Color, color, {
2178 copy: function(channels) {
2179 return Object.assign(new this.constructor, this, channels);
2180 },
2181 displayable: function() {
2182 return this.rgb().displayable();
2183 },
2184 hex: color_formatHex, // Deprecated! Use color.formatHex.
2185 formatHex: color_formatHex,
2186 formatHsl: color_formatHsl,
2187 formatRgb: color_formatRgb,
2188 toString: color_formatRgb
2189});
2190
2191function color_formatHex() {
2192 return this.rgb().formatHex();
2193}
2194
2195function color_formatHsl() {
2196 return hslConvert(this).formatHsl();
2197}
2198
2199function color_formatRgb() {
2200 return this.rgb().formatRgb();
2201}
2202
2203function color(format) {
2204 var m, l;
2205 format = (format + "").trim().toLowerCase();
2206 return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
2207 : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00
2208 : l === 8 ? new Rgb(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
2209 : l === 4 ? new Rgb((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000
2210 : null) // invalid hex
2211 : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
2212 : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
2213 : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
2214 : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
2215 : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
2216 : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
2217 : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
2218 : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
2219 : null;
2220}
2221
2222function rgbn(n) {
2223 return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
2224}
2225
2226function rgba(r, g, b, a) {
2227 if (a <= 0) r = g = b = NaN;
2228 return new Rgb(r, g, b, a);
2229}
2230
2231function rgbConvert(o) {
2232 if (!(o instanceof Color)) o = color(o);
2233 if (!o) return new Rgb;
2234 o = o.rgb();
2235 return new Rgb(o.r, o.g, o.b, o.opacity);
2236}
2237
2238function rgb(r, g, b, opacity) {
2239 return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
2240}
2241
2242function Rgb(r, g, b, opacity) {
2243 this.r = +r;
2244 this.g = +g;
2245 this.b = +b;
2246 this.opacity = +opacity;
2247}
2248
2249define(Rgb, rgb, extend(Color, {
2250 brighter: function(k) {
2251 k = k == null ? brighter : Math.pow(brighter, k);
2252 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2253 },
2254 darker: function(k) {
2255 k = k == null ? darker : Math.pow(darker, k);
2256 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2257 },
2258 rgb: function() {
2259 return this;
2260 },
2261 displayable: function() {
2262 return (-0.5 <= this.r && this.r < 255.5)
2263 && (-0.5 <= this.g && this.g < 255.5)
2264 && (-0.5 <= this.b && this.b < 255.5)
2265 && (0 <= this.opacity && this.opacity <= 1);
2266 },
2267 hex: rgb_formatHex, // Deprecated! Use color.formatHex.
2268 formatHex: rgb_formatHex,
2269 formatRgb: rgb_formatRgb,
2270 toString: rgb_formatRgb
2271}));
2272
2273function rgb_formatHex() {
2274 return "#" + hex(this.r) + hex(this.g) + hex(this.b);
2275}
2276
2277function rgb_formatRgb() {
2278 var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2279 return (a === 1 ? "rgb(" : "rgba(")
2280 + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
2281 + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
2282 + Math.max(0, Math.min(255, Math.round(this.b) || 0))
2283 + (a === 1 ? ")" : ", " + a + ")");
2284}
2285
2286function hex(value) {
2287 value = Math.max(0, Math.min(255, Math.round(value) || 0));
2288 return (value < 16 ? "0" : "") + value.toString(16);
2289}
2290
2291function hsla(h, s, l, a) {
2292 if (a <= 0) h = s = l = NaN;
2293 else if (l <= 0 || l >= 1) h = s = NaN;
2294 else if (s <= 0) h = NaN;
2295 return new Hsl(h, s, l, a);
2296}
2297
2298function hslConvert(o) {
2299 if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2300 if (!(o instanceof Color)) o = color(o);
2301 if (!o) return new Hsl;
2302 if (o instanceof Hsl) return o;
2303 o = o.rgb();
2304 var r = o.r / 255,
2305 g = o.g / 255,
2306 b = o.b / 255,
2307 min = Math.min(r, g, b),
2308 max = Math.max(r, g, b),
2309 h = NaN,
2310 s = max - min,
2311 l = (max + min) / 2;
2312 if (s) {
2313 if (r === max) h = (g - b) / s + (g < b) * 6;
2314 else if (g === max) h = (b - r) / s + 2;
2315 else h = (r - g) / s + 4;
2316 s /= l < 0.5 ? max + min : 2 - max - min;
2317 h *= 60;
2318 } else {
2319 s = l > 0 && l < 1 ? 0 : h;
2320 }
2321 return new Hsl(h, s, l, o.opacity);
2322}
2323
2324function hsl(h, s, l, opacity) {
2325 return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2326}
2327
2328function Hsl(h, s, l, opacity) {
2329 this.h = +h;
2330 this.s = +s;
2331 this.l = +l;
2332 this.opacity = +opacity;
2333}
2334
2335define(Hsl, hsl, extend(Color, {
2336 brighter: function(k) {
2337 k = k == null ? brighter : Math.pow(brighter, k);
2338 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2339 },
2340 darker: function(k) {
2341 k = k == null ? darker : Math.pow(darker, k);
2342 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2343 },
2344 rgb: function() {
2345 var h = this.h % 360 + (this.h < 0) * 360,
2346 s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
2347 l = this.l,
2348 m2 = l + (l < 0.5 ? l : 1 - l) * s,
2349 m1 = 2 * l - m2;
2350 return new Rgb(
2351 hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
2352 hsl2rgb(h, m1, m2),
2353 hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
2354 this.opacity
2355 );
2356 },
2357 displayable: function() {
2358 return (0 <= this.s && this.s <= 1 || isNaN(this.s))
2359 && (0 <= this.l && this.l <= 1)
2360 && (0 <= this.opacity && this.opacity <= 1);
2361 },
2362 formatHsl: function() {
2363 var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2364 return (a === 1 ? "hsl(" : "hsla(")
2365 + (this.h || 0) + ", "
2366 + (this.s || 0) * 100 + "%, "
2367 + (this.l || 0) * 100 + "%"
2368 + (a === 1 ? ")" : ", " + a + ")");
2369 }
2370}));
2371
2372/* From FvD 13.37, CSS Color Module Level 3 */
2373function hsl2rgb(h, m1, m2) {
2374 return (h < 60 ? m1 + (m2 - m1) * h / 60
2375 : h < 180 ? m2
2376 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
2377 : m1) * 255;
2378}
2379
2380var deg2rad = Math.PI / 180;
2381var rad2deg = 180 / Math.PI;
2382
2383// https://observablehq.com/@mbostock/lab-and-rgb
2384var K = 18,
2385 Xn = 0.96422,
2386 Yn = 1,
2387 Zn = 0.82521,
2388 t0 = 4 / 29,
2389 t1 = 6 / 29,
2390 t2 = 3 * t1 * t1,
2391 t3 = t1 * t1 * t1;
2392
2393function labConvert(o) {
2394 if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
2395 if (o instanceof Hcl) return hcl2lab(o);
2396 if (!(o instanceof Rgb)) o = rgbConvert(o);
2397 var r = rgb2lrgb(o.r),
2398 g = rgb2lrgb(o.g),
2399 b = rgb2lrgb(o.b),
2400 y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
2401 if (r === g && g === b) x = z = y; else {
2402 x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
2403 z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
2404 }
2405 return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
2406}
2407
2408function gray(l, opacity) {
2409 return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
2410}
2411
2412function lab(l, a, b, opacity) {
2413 return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
2414}
2415
2416function Lab(l, a, b, opacity) {
2417 this.l = +l;
2418 this.a = +a;
2419 this.b = +b;
2420 this.opacity = +opacity;
2421}
2422
2423define(Lab, lab, extend(Color, {
2424 brighter: function(k) {
2425 return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
2426 },
2427 darker: function(k) {
2428 return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
2429 },
2430 rgb: function() {
2431 var y = (this.l + 16) / 116,
2432 x = isNaN(this.a) ? y : y + this.a / 500,
2433 z = isNaN(this.b) ? y : y - this.b / 200;
2434 x = Xn * lab2xyz(x);
2435 y = Yn * lab2xyz(y);
2436 z = Zn * lab2xyz(z);
2437 return new Rgb(
2438 lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
2439 lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
2440 lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
2441 this.opacity
2442 );
2443 }
2444}));
2445
2446function xyz2lab(t) {
2447 return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
2448}
2449
2450function lab2xyz(t) {
2451 return t > t1 ? t * t * t : t2 * (t - t0);
2452}
2453
2454function lrgb2rgb(x) {
2455 return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
2456}
2457
2458function rgb2lrgb(x) {
2459 return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
2460}
2461
2462function hclConvert(o) {
2463 if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
2464 if (!(o instanceof Lab)) o = labConvert(o);
2465 if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
2466 var h = Math.atan2(o.b, o.a) * rad2deg;
2467 return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
2468}
2469
2470function lch(l, c, h, opacity) {
2471 return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2472}
2473
2474function hcl(h, c, l, opacity) {
2475 return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2476}
2477
2478function Hcl(h, c, l, opacity) {
2479 this.h = +h;
2480 this.c = +c;
2481 this.l = +l;
2482 this.opacity = +opacity;
2483}
2484
2485function hcl2lab(o) {
2486 if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
2487 var h = o.h * deg2rad;
2488 return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
2489}
2490
2491define(Hcl, hcl, extend(Color, {
2492 brighter: function(k) {
2493 return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
2494 },
2495 darker: function(k) {
2496 return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
2497 },
2498 rgb: function() {
2499 return hcl2lab(this).rgb();
2500 }
2501}));
2502
2503var A = -0.14861,
2504 B = +1.78277,
2505 C = -0.29227,
2506 D = -0.90649,
2507 E = +1.97294,
2508 ED = E * D,
2509 EB = E * B,
2510 BC_DA = B * C - D * A;
2511
2512function cubehelixConvert(o) {
2513 if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
2514 if (!(o instanceof Rgb)) o = rgbConvert(o);
2515 var r = o.r / 255,
2516 g = o.g / 255,
2517 b = o.b / 255,
2518 l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
2519 bl = b - l,
2520 k = (E * (g - l) - C * bl) / D,
2521 s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
2522 h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
2523 return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
2524}
2525
2526function cubehelix(h, s, l, opacity) {
2527 return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
2528}
2529
2530function Cubehelix(h, s, l, opacity) {
2531 this.h = +h;
2532 this.s = +s;
2533 this.l = +l;
2534 this.opacity = +opacity;
2535}
2536
2537define(Cubehelix, cubehelix, extend(Color, {
2538 brighter: function(k) {
2539 k = k == null ? brighter : Math.pow(brighter, k);
2540 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2541 },
2542 darker: function(k) {
2543 k = k == null ? darker : Math.pow(darker, k);
2544 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2545 },
2546 rgb: function() {
2547 var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
2548 l = +this.l,
2549 a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
2550 cosh = Math.cos(h),
2551 sinh = Math.sin(h);
2552 return new Rgb(
2553 255 * (l + a * (A * cosh + B * sinh)),
2554 255 * (l + a * (C * cosh + D * sinh)),
2555 255 * (l + a * (E * cosh)),
2556 this.opacity
2557 );
2558 }
2559}));
2560
2561function basis(t1, v0, v1, v2, v3) {
2562 var t2 = t1 * t1, t3 = t2 * t1;
2563 return ((1 - 3 * t1 + 3 * t2 - t3) * v0
2564 + (4 - 6 * t2 + 3 * t3) * v1
2565 + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
2566 + t3 * v3) / 6;
2567}
2568
2569function basis$1(values) {
2570 var n = values.length - 1;
2571 return function(t) {
2572 var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
2573 v1 = values[i],
2574 v2 = values[i + 1],
2575 v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
2576 v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
2577 return basis((t - i / n) * n, v0, v1, v2, v3);
2578 };
2579}
2580
2581function basisClosed(values) {
2582 var n = values.length;
2583 return function(t) {
2584 var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
2585 v0 = values[(i + n - 1) % n],
2586 v1 = values[i % n],
2587 v2 = values[(i + 1) % n],
2588 v3 = values[(i + 2) % n];
2589 return basis((t - i / n) * n, v0, v1, v2, v3);
2590 };
2591}
2592
2593function constant$3(x) {
2594 return function() {
2595 return x;
2596 };
2597}
2598
2599function linear(a, d) {
2600 return function(t) {
2601 return a + t * d;
2602 };
2603}
2604
2605function exponential(a, b, y) {
2606 return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
2607 return Math.pow(a + t * b, y);
2608 };
2609}
2610
2611function hue(a, b) {
2612 var d = b - a;
2613 return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
2614}
2615
2616function gamma(y) {
2617 return (y = +y) === 1 ? nogamma : function(a, b) {
2618 return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
2619 };
2620}
2621
2622function nogamma(a, b) {
2623 var d = b - a;
2624 return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
2625}
2626
2627var interpolateRgb = (function rgbGamma(y) {
2628 var color = gamma(y);
2629
2630 function rgb$1(start, end) {
2631 var r = color((start = rgb(start)).r, (end = rgb(end)).r),
2632 g = color(start.g, end.g),
2633 b = color(start.b, end.b),
2634 opacity = nogamma(start.opacity, end.opacity);
2635 return function(t) {
2636 start.r = r(t);
2637 start.g = g(t);
2638 start.b = b(t);
2639 start.opacity = opacity(t);
2640 return start + "";
2641 };
2642 }
2643
2644 rgb$1.gamma = rgbGamma;
2645
2646 return rgb$1;
2647})(1);
2648
2649function rgbSpline(spline) {
2650 return function(colors) {
2651 var n = colors.length,
2652 r = new Array(n),
2653 g = new Array(n),
2654 b = new Array(n),
2655 i, color;
2656 for (i = 0; i < n; ++i) {
2657 color = rgb(colors[i]);
2658 r[i] = color.r || 0;
2659 g[i] = color.g || 0;
2660 b[i] = color.b || 0;
2661 }
2662 r = spline(r);
2663 g = spline(g);
2664 b = spline(b);
2665 color.opacity = 1;
2666 return function(t) {
2667 color.r = r(t);
2668 color.g = g(t);
2669 color.b = b(t);
2670 return color + "";
2671 };
2672 };
2673}
2674
2675var rgbBasis = rgbSpline(basis$1);
2676var rgbBasisClosed = rgbSpline(basisClosed);
2677
2678function array$1(a, b) {
2679 var nb = b ? b.length : 0,
2680 na = a ? Math.min(nb, a.length) : 0,
2681 x = new Array(na),
2682 c = new Array(nb),
2683 i;
2684
2685 for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
2686 for (; i < nb; ++i) c[i] = b[i];
2687
2688 return function(t) {
2689 for (i = 0; i < na; ++i) c[i] = x[i](t);
2690 return c;
2691 };
2692}
2693
2694function date(a, b) {
2695 var d = new Date;
2696 return a = +a, b -= a, function(t) {
2697 return d.setTime(a + b * t), d;
2698 };
2699}
2700
2701function interpolateNumber(a, b) {
2702 return a = +a, b -= a, function(t) {
2703 return a + b * t;
2704 };
2705}
2706
2707function object(a, b) {
2708 var i = {},
2709 c = {},
2710 k;
2711
2712 if (a === null || typeof a !== "object") a = {};
2713 if (b === null || typeof b !== "object") b = {};
2714
2715 for (k in b) {
2716 if (k in a) {
2717 i[k] = interpolateValue(a[k], b[k]);
2718 } else {
2719 c[k] = b[k];
2720 }
2721 }
2722
2723 return function(t) {
2724 for (k in i) c[k] = i[k](t);
2725 return c;
2726 };
2727}
2728
2729var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
2730 reB = new RegExp(reA.source, "g");
2731
2732function zero(b) {
2733 return function() {
2734 return b;
2735 };
2736}
2737
2738function one(b) {
2739 return function(t) {
2740 return b(t) + "";
2741 };
2742}
2743
2744function interpolateString(a, b) {
2745 var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
2746 am, // current match in a
2747 bm, // current match in b
2748 bs, // string preceding current number in b, if any
2749 i = -1, // index in s
2750 s = [], // string constants and placeholders
2751 q = []; // number interpolators
2752
2753 // Coerce inputs to strings.
2754 a = a + "", b = b + "";
2755
2756 // Interpolate pairs of numbers in a & b.
2757 while ((am = reA.exec(a))
2758 && (bm = reB.exec(b))) {
2759 if ((bs = bm.index) > bi) { // a string precedes the next number in b
2760 bs = b.slice(bi, bs);
2761 if (s[i]) s[i] += bs; // coalesce with previous string
2762 else s[++i] = bs;
2763 }
2764 if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
2765 if (s[i]) s[i] += bm; // coalesce with previous string
2766 else s[++i] = bm;
2767 } else { // interpolate non-matching numbers
2768 s[++i] = null;
2769 q.push({i: i, x: interpolateNumber(am, bm)});
2770 }
2771 bi = reB.lastIndex;
2772 }
2773
2774 // Add remains of b.
2775 if (bi < b.length) {
2776 bs = b.slice(bi);
2777 if (s[i]) s[i] += bs; // coalesce with previous string
2778 else s[++i] = bs;
2779 }
2780
2781 // Special optimization for only a single match.
2782 // Otherwise, interpolate each of the numbers and rejoin the string.
2783 return s.length < 2 ? (q[0]
2784 ? one(q[0].x)
2785 : zero(b))
2786 : (b = q.length, function(t) {
2787 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
2788 return s.join("");
2789 });
2790}
2791
2792function interpolateValue(a, b) {
2793 var t = typeof b, c;
2794 return b == null || t === "boolean" ? constant$3(b)
2795 : (t === "number" ? interpolateNumber
2796 : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
2797 : b instanceof color ? interpolateRgb
2798 : b instanceof Date ? date
2799 : Array.isArray(b) ? array$1
2800 : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
2801 : interpolateNumber)(a, b);
2802}
2803
2804function discrete(range) {
2805 var n = range.length;
2806 return function(t) {
2807 return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
2808 };
2809}
2810
2811function hue$1(a, b) {
2812 var i = hue(+a, +b);
2813 return function(t) {
2814 var x = i(t);
2815 return x - 360 * Math.floor(x / 360);
2816 };
2817}
2818
2819function interpolateRound(a, b) {
2820 return a = +a, b -= a, function(t) {
2821 return Math.round(a + b * t);
2822 };
2823}
2824
2825var degrees = 180 / Math.PI;
2826
2827var identity$2 = {
2828 translateX: 0,
2829 translateY: 0,
2830 rotate: 0,
2831 skewX: 0,
2832 scaleX: 1,
2833 scaleY: 1
2834};
2835
2836function decompose(a, b, c, d, e, f) {
2837 var scaleX, scaleY, skewX;
2838 if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
2839 if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
2840 if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
2841 if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
2842 return {
2843 translateX: e,
2844 translateY: f,
2845 rotate: Math.atan2(b, a) * degrees,
2846 skewX: Math.atan(skewX) * degrees,
2847 scaleX: scaleX,
2848 scaleY: scaleY
2849 };
2850}
2851
2852var cssNode,
2853 cssRoot,
2854 cssView,
2855 svgNode;
2856
2857function parseCss(value) {
2858 if (value === "none") return identity$2;
2859 if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
2860 cssNode.style.transform = value;
2861 value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
2862 cssRoot.removeChild(cssNode);
2863 value = value.slice(7, -1).split(",");
2864 return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
2865}
2866
2867function parseSvg(value) {
2868 if (value == null) return identity$2;
2869 if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
2870 svgNode.setAttribute("transform", value);
2871 if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
2872 value = value.matrix;
2873 return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
2874}
2875
2876function interpolateTransform(parse, pxComma, pxParen, degParen) {
2877
2878 function pop(s) {
2879 return s.length ? s.pop() + " " : "";
2880 }
2881
2882 function translate(xa, ya, xb, yb, s, q) {
2883 if (xa !== xb || ya !== yb) {
2884 var i = s.push("translate(", null, pxComma, null, pxParen);
2885 q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
2886 } else if (xb || yb) {
2887 s.push("translate(" + xb + pxComma + yb + pxParen);
2888 }
2889 }
2890
2891 function rotate(a, b, s, q) {
2892 if (a !== b) {
2893 if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
2894 q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
2895 } else if (b) {
2896 s.push(pop(s) + "rotate(" + b + degParen);
2897 }
2898 }
2899
2900 function skewX(a, b, s, q) {
2901 if (a !== b) {
2902 q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
2903 } else if (b) {
2904 s.push(pop(s) + "skewX(" + b + degParen);
2905 }
2906 }
2907
2908 function scale(xa, ya, xb, yb, s, q) {
2909 if (xa !== xb || ya !== yb) {
2910 var i = s.push(pop(s) + "scale(", null, ",", null, ")");
2911 q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
2912 } else if (xb !== 1 || yb !== 1) {
2913 s.push(pop(s) + "scale(" + xb + "," + yb + ")");
2914 }
2915 }
2916
2917 return function(a, b) {
2918 var s = [], // string constants and placeholders
2919 q = []; // number interpolators
2920 a = parse(a), b = parse(b);
2921 translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
2922 rotate(a.rotate, b.rotate, s, q);
2923 skewX(a.skewX, b.skewX, s, q);
2924 scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
2925 a = b = null; // gc
2926 return function(t) {
2927 var i = -1, n = q.length, o;
2928 while (++i < n) s[(o = q[i]).i] = o.x(t);
2929 return s.join("");
2930 };
2931 };
2932}
2933
2934var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
2935var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
2936
2937var rho = Math.SQRT2,
2938 rho2 = 2,
2939 rho4 = 4,
2940 epsilon2 = 1e-12;
2941
2942function cosh(x) {
2943 return ((x = Math.exp(x)) + 1 / x) / 2;
2944}
2945
2946function sinh(x) {
2947 return ((x = Math.exp(x)) - 1 / x) / 2;
2948}
2949
2950function tanh(x) {
2951 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
2952}
2953
2954// p0 = [ux0, uy0, w0]
2955// p1 = [ux1, uy1, w1]
2956function interpolateZoom(p0, p1) {
2957 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
2958 ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
2959 dx = ux1 - ux0,
2960 dy = uy1 - uy0,
2961 d2 = dx * dx + dy * dy,
2962 i,
2963 S;
2964
2965 // Special case for u0 ≅ u1.
2966 if (d2 < epsilon2) {
2967 S = Math.log(w1 / w0) / rho;
2968 i = function(t) {
2969 return [
2970 ux0 + t * dx,
2971 uy0 + t * dy,
2972 w0 * Math.exp(rho * t * S)
2973 ];
2974 };
2975 }
2976
2977 // General case.
2978 else {
2979 var d1 = Math.sqrt(d2),
2980 b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
2981 b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
2982 r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
2983 r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
2984 S = (r1 - r0) / rho;
2985 i = function(t) {
2986 var s = t * S,
2987 coshr0 = cosh(r0),
2988 u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
2989 return [
2990 ux0 + u * dx,
2991 uy0 + u * dy,
2992 w0 * coshr0 / cosh(rho * s + r0)
2993 ];
2994 };
2995 }
2996
2997 i.duration = S * 1000;
2998
2999 return i;
3000}
3001
3002function hsl$1(hue) {
3003 return function(start, end) {
3004 var h = hue((start = hsl(start)).h, (end = hsl(end)).h),
3005 s = nogamma(start.s, end.s),
3006 l = nogamma(start.l, end.l),
3007 opacity = nogamma(start.opacity, end.opacity);
3008 return function(t) {
3009 start.h = h(t);
3010 start.s = s(t);
3011 start.l = l(t);
3012 start.opacity = opacity(t);
3013 return start + "";
3014 };
3015 }
3016}
3017
3018var hsl$2 = hsl$1(hue);
3019var hslLong = hsl$1(nogamma);
3020
3021function lab$1(start, end) {
3022 var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
3023 a = nogamma(start.a, end.a),
3024 b = nogamma(start.b, end.b),
3025 opacity = nogamma(start.opacity, end.opacity);
3026 return function(t) {
3027 start.l = l(t);
3028 start.a = a(t);
3029 start.b = b(t);
3030 start.opacity = opacity(t);
3031 return start + "";
3032 };
3033}
3034
3035function hcl$1(hue) {
3036 return function(start, end) {
3037 var h = hue((start = hcl(start)).h, (end = hcl(end)).h),
3038 c = nogamma(start.c, end.c),
3039 l = nogamma(start.l, end.l),
3040 opacity = nogamma(start.opacity, end.opacity);
3041 return function(t) {
3042 start.h = h(t);
3043 start.c = c(t);
3044 start.l = l(t);
3045 start.opacity = opacity(t);
3046 return start + "";
3047 };
3048 }
3049}
3050
3051var hcl$2 = hcl$1(hue);
3052var hclLong = hcl$1(nogamma);
3053
3054function cubehelix$1(hue) {
3055 return (function cubehelixGamma(y) {
3056 y = +y;
3057
3058 function cubehelix$1(start, end) {
3059 var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h),
3060 s = nogamma(start.s, end.s),
3061 l = nogamma(start.l, end.l),
3062 opacity = nogamma(start.opacity, end.opacity);
3063 return function(t) {
3064 start.h = h(t);
3065 start.s = s(t);
3066 start.l = l(Math.pow(t, y));
3067 start.opacity = opacity(t);
3068 return start + "";
3069 };
3070 }
3071
3072 cubehelix$1.gamma = cubehelixGamma;
3073
3074 return cubehelix$1;
3075 })(1);
3076}
3077
3078var cubehelix$2 = cubehelix$1(hue);
3079var cubehelixLong = cubehelix$1(nogamma);
3080
3081function piecewise(interpolate, values) {
3082 var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
3083 while (i < n) I[i] = interpolate(v, v = values[++i]);
3084 return function(t) {
3085 var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
3086 return I[i](t - i);
3087 };
3088}
3089
3090function quantize(interpolator, n) {
3091 var samples = new Array(n);
3092 for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
3093 return samples;
3094}
3095
3096var frame = 0, // is an animation frame pending?
3097 timeout = 0, // is a timeout pending?
3098 interval = 0, // are any timers active?
3099 pokeDelay = 1000, // how frequently we check for clock skew
3100 taskHead,
3101 taskTail,
3102 clockLast = 0,
3103 clockNow = 0,
3104 clockSkew = 0,
3105 clock = typeof performance === "object" && performance.now ? performance : Date,
3106 setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
3107
3108function now() {
3109 return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
3110}
3111
3112function clearNow() {
3113 clockNow = 0;
3114}
3115
3116function Timer() {
3117 this._call =
3118 this._time =
3119 this._next = null;
3120}
3121
3122Timer.prototype = timer.prototype = {
3123 constructor: Timer,
3124 restart: function(callback, delay, time) {
3125 if (typeof callback !== "function") throw new TypeError("callback is not a function");
3126 time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
3127 if (!this._next && taskTail !== this) {
3128 if (taskTail) taskTail._next = this;
3129 else taskHead = this;
3130 taskTail = this;
3131 }
3132 this._call = callback;
3133 this._time = time;
3134 sleep();
3135 },
3136 stop: function() {
3137 if (this._call) {
3138 this._call = null;
3139 this._time = Infinity;
3140 sleep();
3141 }
3142 }
3143};
3144
3145function timer(callback, delay, time) {
3146 var t = new Timer;
3147 t.restart(callback, delay, time);
3148 return t;
3149}
3150
3151function timerFlush() {
3152 now(); // Get the current time, if not already set.
3153 ++frame; // Pretend we’ve set an alarm, if we haven’t already.
3154 var t = taskHead, e;
3155 while (t) {
3156 if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
3157 t = t._next;
3158 }
3159 --frame;
3160}
3161
3162function wake() {
3163 clockNow = (clockLast = clock.now()) + clockSkew;
3164 frame = timeout = 0;
3165 try {
3166 timerFlush();
3167 } finally {
3168 frame = 0;
3169 nap();
3170 clockNow = 0;
3171 }
3172}
3173
3174function poke() {
3175 var now = clock.now(), delay = now - clockLast;
3176 if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
3177}
3178
3179function nap() {
3180 var t0, t1 = taskHead, t2, time = Infinity;
3181 while (t1) {
3182 if (t1._call) {
3183 if (time > t1._time) time = t1._time;
3184 t0 = t1, t1 = t1._next;
3185 } else {
3186 t2 = t1._next, t1._next = null;
3187 t1 = t0 ? t0._next = t2 : taskHead = t2;
3188 }
3189 }
3190 taskTail = t0;
3191 sleep(time);
3192}
3193
3194function sleep(time) {
3195 if (frame) return; // Soonest alarm already set, or will be.
3196 if (timeout) timeout = clearTimeout(timeout);
3197 var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
3198 if (delay > 24) {
3199 if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
3200 if (interval) interval = clearInterval(interval);
3201 } else {
3202 if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
3203 frame = 1, setFrame(wake);
3204 }
3205}
3206
3207function timeout$1(callback, delay, time) {
3208 var t = new Timer;
3209 delay = delay == null ? 0 : +delay;
3210 t.restart(function(elapsed) {
3211 t.stop();
3212 callback(elapsed + delay);
3213 }, delay, time);
3214 return t;
3215}
3216
3217function interval$1(callback, delay, time) {
3218 var t = new Timer, total = delay;
3219 if (delay == null) return t.restart(callback, delay, time), t;
3220 delay = +delay, time = time == null ? now() : +time;
3221 t.restart(function tick(elapsed) {
3222 elapsed += total;
3223 t.restart(tick, total += delay, time);
3224 callback(elapsed);
3225 }, delay, time);
3226 return t;
3227}
3228
3229var emptyOn = dispatch("start", "end", "cancel", "interrupt");
3230var emptyTween = [];
3231
3232var CREATED = 0;
3233var SCHEDULED = 1;
3234var STARTING = 2;
3235var STARTED = 3;
3236var RUNNING = 4;
3237var ENDING = 5;
3238var ENDED = 6;
3239
3240function schedule(node, name, id, index, group, timing) {
3241 var schedules = node.__transition;
3242 if (!schedules) node.__transition = {};
3243 else if (id in schedules) return;
3244 create$1(node, id, {
3245 name: name,
3246 index: index, // For context during callback.
3247 group: group, // For context during callback.
3248 on: emptyOn,
3249 tween: emptyTween,
3250 time: timing.time,
3251 delay: timing.delay,
3252 duration: timing.duration,
3253 ease: timing.ease,
3254 timer: null,
3255 state: CREATED
3256 });
3257}
3258
3259function init(node, id) {
3260 var schedule = get$1(node, id);
3261 if (schedule.state > CREATED) throw new Error("too late; already scheduled");
3262 return schedule;
3263}
3264
3265function set$1(node, id) {
3266 var schedule = get$1(node, id);
3267 if (schedule.state > STARTED) throw new Error("too late; already running");
3268 return schedule;
3269}
3270
3271function get$1(node, id) {
3272 var schedule = node.__transition;
3273 if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
3274 return schedule;
3275}
3276
3277function create$1(node, id, self) {
3278 var schedules = node.__transition,
3279 tween;
3280
3281 // Initialize the self timer when the transition is created.
3282 // Note the actual delay is not known until the first callback!
3283 schedules[id] = self;
3284 self.timer = timer(schedule, 0, self.time);
3285
3286 function schedule(elapsed) {
3287 self.state = SCHEDULED;
3288 self.timer.restart(start, self.delay, self.time);
3289
3290 // If the elapsed delay is less than our first sleep, start immediately.
3291 if (self.delay <= elapsed) start(elapsed - self.delay);
3292 }
3293
3294 function start(elapsed) {
3295 var i, j, n, o;
3296
3297 // If the state is not SCHEDULED, then we previously errored on start.
3298 if (self.state !== SCHEDULED) return stop();
3299
3300 for (i in schedules) {
3301 o = schedules[i];
3302 if (o.name !== self.name) continue;
3303
3304 // While this element already has a starting transition during this frame,
3305 // defer starting an interrupting transition until that transition has a
3306 // chance to tick (and possibly end); see d3/d3-transition#54!
3307 if (o.state === STARTED) return timeout$1(start);
3308
3309 // Interrupt the active transition, if any.
3310 if (o.state === RUNNING) {
3311 o.state = ENDED;
3312 o.timer.stop();
3313 o.on.call("interrupt", node, node.__data__, o.index, o.group);
3314 delete schedules[i];
3315 }
3316
3317 // Cancel any pre-empted transitions.
3318 else if (+i < id) {
3319 o.state = ENDED;
3320 o.timer.stop();
3321 o.on.call("cancel", node, node.__data__, o.index, o.group);
3322 delete schedules[i];
3323 }
3324 }
3325
3326 // Defer the first tick to end of the current frame; see d3/d3#1576.
3327 // Note the transition may be canceled after start and before the first tick!
3328 // Note this must be scheduled before the start event; see d3/d3-transition#16!
3329 // Assuming this is successful, subsequent callbacks go straight to tick.
3330 timeout$1(function() {
3331 if (self.state === STARTED) {
3332 self.state = RUNNING;
3333 self.timer.restart(tick, self.delay, self.time);
3334 tick(elapsed);
3335 }
3336 });
3337
3338 // Dispatch the start event.
3339 // Note this must be done before the tween are initialized.
3340 self.state = STARTING;
3341 self.on.call("start", node, node.__data__, self.index, self.group);
3342 if (self.state !== STARTING) return; // interrupted
3343 self.state = STARTED;
3344
3345 // Initialize the tween, deleting null tween.
3346 tween = new Array(n = self.tween.length);
3347 for (i = 0, j = -1; i < n; ++i) {
3348 if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
3349 tween[++j] = o;
3350 }
3351 }
3352 tween.length = j + 1;
3353 }
3354
3355 function tick(elapsed) {
3356 var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
3357 i = -1,
3358 n = tween.length;
3359
3360 while (++i < n) {
3361 tween[i].call(node, t);
3362 }
3363
3364 // Dispatch the end event.
3365 if (self.state === ENDING) {
3366 self.on.call("end", node, node.__data__, self.index, self.group);
3367 stop();
3368 }
3369 }
3370
3371 function stop() {
3372 self.state = ENDED;
3373 self.timer.stop();
3374 delete schedules[id];
3375 for (var i in schedules) return; // eslint-disable-line no-unused-vars
3376 delete node.__transition;
3377 }
3378}
3379
3380function interrupt(node, name) {
3381 var schedules = node.__transition,
3382 schedule,
3383 active,
3384 empty = true,
3385 i;
3386
3387 if (!schedules) return;
3388
3389 name = name == null ? null : name + "";
3390
3391 for (i in schedules) {
3392 if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
3393 active = schedule.state > STARTING && schedule.state < ENDING;
3394 schedule.state = ENDED;
3395 schedule.timer.stop();
3396 schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
3397 delete schedules[i];
3398 }
3399
3400 if (empty) delete node.__transition;
3401}
3402
3403function selection_interrupt(name) {
3404 return this.each(function() {
3405 interrupt(this, name);
3406 });
3407}
3408
3409function tweenRemove(id, name) {
3410 var tween0, tween1;
3411 return function() {
3412 var schedule = set$1(this, id),
3413 tween = schedule.tween;
3414
3415 // If this node shared tween with the previous node,
3416 // just assign the updated shared tween and we’re done!
3417 // Otherwise, copy-on-write.
3418 if (tween !== tween0) {
3419 tween1 = tween0 = tween;
3420 for (var i = 0, n = tween1.length; i < n; ++i) {
3421 if (tween1[i].name === name) {
3422 tween1 = tween1.slice();
3423 tween1.splice(i, 1);
3424 break;
3425 }
3426 }
3427 }
3428
3429 schedule.tween = tween1;
3430 };
3431}
3432
3433function tweenFunction(id, name, value) {
3434 var tween0, tween1;
3435 if (typeof value !== "function") throw new Error;
3436 return function() {
3437 var schedule = set$1(this, id),
3438 tween = schedule.tween;
3439
3440 // If this node shared tween with the previous node,
3441 // just assign the updated shared tween and we’re done!
3442 // Otherwise, copy-on-write.
3443 if (tween !== tween0) {
3444 tween1 = (tween0 = tween).slice();
3445 for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
3446 if (tween1[i].name === name) {
3447 tween1[i] = t;
3448 break;
3449 }
3450 }
3451 if (i === n) tween1.push(t);
3452 }
3453
3454 schedule.tween = tween1;
3455 };
3456}
3457
3458function transition_tween(name, value) {
3459 var id = this._id;
3460
3461 name += "";
3462
3463 if (arguments.length < 2) {
3464 var tween = get$1(this.node(), id).tween;
3465 for (var i = 0, n = tween.length, t; i < n; ++i) {
3466 if ((t = tween[i]).name === name) {
3467 return t.value;
3468 }
3469 }
3470 return null;
3471 }
3472
3473 return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
3474}
3475
3476function tweenValue(transition, name, value) {
3477 var id = transition._id;
3478
3479 transition.each(function() {
3480 var schedule = set$1(this, id);
3481 (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
3482 });
3483
3484 return function(node) {
3485 return get$1(node, id).value[name];
3486 };
3487}
3488
3489function interpolate(a, b) {
3490 var c;
3491 return (typeof b === "number" ? interpolateNumber
3492 : b instanceof color ? interpolateRgb
3493 : (c = color(b)) ? (b = c, interpolateRgb)
3494 : interpolateString)(a, b);
3495}
3496
3497function attrRemove$1(name) {
3498 return function() {
3499 this.removeAttribute(name);
3500 };
3501}
3502
3503function attrRemoveNS$1(fullname) {
3504 return function() {
3505 this.removeAttributeNS(fullname.space, fullname.local);
3506 };
3507}
3508
3509function attrConstant$1(name, interpolate, value1) {
3510 var string00,
3511 string1 = value1 + "",
3512 interpolate0;
3513 return function() {
3514 var string0 = this.getAttribute(name);
3515 return string0 === string1 ? null
3516 : string0 === string00 ? interpolate0
3517 : interpolate0 = interpolate(string00 = string0, value1);
3518 };
3519}
3520
3521function attrConstantNS$1(fullname, interpolate, value1) {
3522 var string00,
3523 string1 = value1 + "",
3524 interpolate0;
3525 return function() {
3526 var string0 = this.getAttributeNS(fullname.space, fullname.local);
3527 return string0 === string1 ? null
3528 : string0 === string00 ? interpolate0
3529 : interpolate0 = interpolate(string00 = string0, value1);
3530 };
3531}
3532
3533function attrFunction$1(name, interpolate, value) {
3534 var string00,
3535 string10,
3536 interpolate0;
3537 return function() {
3538 var string0, value1 = value(this), string1;
3539 if (value1 == null) return void this.removeAttribute(name);
3540 string0 = this.getAttribute(name);
3541 string1 = value1 + "";
3542 return string0 === string1 ? null
3543 : string0 === string00 && string1 === string10 ? interpolate0
3544 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
3545 };
3546}
3547
3548function attrFunctionNS$1(fullname, interpolate, value) {
3549 var string00,
3550 string10,
3551 interpolate0;
3552 return function() {
3553 var string0, value1 = value(this), string1;
3554 if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
3555 string0 = this.getAttributeNS(fullname.space, fullname.local);
3556 string1 = value1 + "";
3557 return string0 === string1 ? null
3558 : string0 === string00 && string1 === string10 ? interpolate0
3559 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
3560 };
3561}
3562
3563function transition_attr(name, value) {
3564 var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
3565 return this.attrTween(name, typeof value === "function"
3566 ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
3567 : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
3568 : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
3569}
3570
3571function attrInterpolate(name, i) {
3572 return function(t) {
3573 this.setAttribute(name, i.call(this, t));
3574 };
3575}
3576
3577function attrInterpolateNS(fullname, i) {
3578 return function(t) {
3579 this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
3580 };
3581}
3582
3583function attrTweenNS(fullname, value) {
3584 var t0, i0;
3585 function tween() {
3586 var i = value.apply(this, arguments);
3587 if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
3588 return t0;
3589 }
3590 tween._value = value;
3591 return tween;
3592}
3593
3594function attrTween(name, value) {
3595 var t0, i0;
3596 function tween() {
3597 var i = value.apply(this, arguments);
3598 if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
3599 return t0;
3600 }
3601 tween._value = value;
3602 return tween;
3603}
3604
3605function transition_attrTween(name, value) {
3606 var key = "attr." + name;
3607 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3608 if (value == null) return this.tween(key, null);
3609 if (typeof value !== "function") throw new Error;
3610 var fullname = namespace(name);
3611 return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
3612}
3613
3614function delayFunction(id, value) {
3615 return function() {
3616 init(this, id).delay = +value.apply(this, arguments);
3617 };
3618}
3619
3620function delayConstant(id, value) {
3621 return value = +value, function() {
3622 init(this, id).delay = value;
3623 };
3624}
3625
3626function transition_delay(value) {
3627 var id = this._id;
3628
3629 return arguments.length
3630 ? this.each((typeof value === "function"
3631 ? delayFunction
3632 : delayConstant)(id, value))
3633 : get$1(this.node(), id).delay;
3634}
3635
3636function durationFunction(id, value) {
3637 return function() {
3638 set$1(this, id).duration = +value.apply(this, arguments);
3639 };
3640}
3641
3642function durationConstant(id, value) {
3643 return value = +value, function() {
3644 set$1(this, id).duration = value;
3645 };
3646}
3647
3648function transition_duration(value) {
3649 var id = this._id;
3650
3651 return arguments.length
3652 ? this.each((typeof value === "function"
3653 ? durationFunction
3654 : durationConstant)(id, value))
3655 : get$1(this.node(), id).duration;
3656}
3657
3658function easeConstant(id, value) {
3659 if (typeof value !== "function") throw new Error;
3660 return function() {
3661 set$1(this, id).ease = value;
3662 };
3663}
3664
3665function transition_ease(value) {
3666 var id = this._id;
3667
3668 return arguments.length
3669 ? this.each(easeConstant(id, value))
3670 : get$1(this.node(), id).ease;
3671}
3672
3673function transition_filter(match) {
3674 if (typeof match !== "function") match = matcher(match);
3675
3676 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3677 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
3678 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
3679 subgroup.push(node);
3680 }
3681 }
3682 }
3683
3684 return new Transition(subgroups, this._parents, this._name, this._id);
3685}
3686
3687function transition_merge(transition) {
3688 if (transition._id !== this._id) throw new Error;
3689
3690 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) {
3691 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
3692 if (node = group0[i] || group1[i]) {
3693 merge[i] = node;
3694 }
3695 }
3696 }
3697
3698 for (; j < m0; ++j) {
3699 merges[j] = groups0[j];
3700 }
3701
3702 return new Transition(merges, this._parents, this._name, this._id);
3703}
3704
3705function start(name) {
3706 return (name + "").trim().split(/^|\s+/).every(function(t) {
3707 var i = t.indexOf(".");
3708 if (i >= 0) t = t.slice(0, i);
3709 return !t || t === "start";
3710 });
3711}
3712
3713function onFunction(id, name, listener) {
3714 var on0, on1, sit = start(name) ? init : set$1;
3715 return function() {
3716 var schedule = sit(this, id),
3717 on = schedule.on;
3718
3719 // If this node shared a dispatch with the previous node,
3720 // just assign the updated shared dispatch and we’re done!
3721 // Otherwise, copy-on-write.
3722 if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
3723
3724 schedule.on = on1;
3725 };
3726}
3727
3728function transition_on(name, listener) {
3729 var id = this._id;
3730
3731 return arguments.length < 2
3732 ? get$1(this.node(), id).on.on(name)
3733 : this.each(onFunction(id, name, listener));
3734}
3735
3736function removeFunction(id) {
3737 return function() {
3738 var parent = this.parentNode;
3739 for (var i in this.__transition) if (+i !== id) return;
3740 if (parent) parent.removeChild(this);
3741 };
3742}
3743
3744function transition_remove() {
3745 return this.on("end.remove", removeFunction(this._id));
3746}
3747
3748function transition_select(select) {
3749 var name = this._name,
3750 id = this._id;
3751
3752 if (typeof select !== "function") select = selector(select);
3753
3754 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3755 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
3756 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
3757 if ("__data__" in node) subnode.__data__ = node.__data__;
3758 subgroup[i] = subnode;
3759 schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
3760 }
3761 }
3762 }
3763
3764 return new Transition(subgroups, this._parents, name, id);
3765}
3766
3767function transition_selectAll(select) {
3768 var name = this._name,
3769 id = this._id;
3770
3771 if (typeof select !== "function") select = selectorAll(select);
3772
3773 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
3774 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3775 if (node = group[i]) {
3776 for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
3777 if (child = children[k]) {
3778 schedule(child, name, id, k, children, inherit);
3779 }
3780 }
3781 subgroups.push(children);
3782 parents.push(node);
3783 }
3784 }
3785 }
3786
3787 return new Transition(subgroups, parents, name, id);
3788}
3789
3790var Selection$1 = selection.prototype.constructor;
3791
3792function transition_selection() {
3793 return new Selection$1(this._groups, this._parents);
3794}
3795
3796function styleNull(name, interpolate) {
3797 var string00,
3798 string10,
3799 interpolate0;
3800 return function() {
3801 var string0 = styleValue(this, name),
3802 string1 = (this.style.removeProperty(name), styleValue(this, name));
3803 return string0 === string1 ? null
3804 : string0 === string00 && string1 === string10 ? interpolate0
3805 : interpolate0 = interpolate(string00 = string0, string10 = string1);
3806 };
3807}
3808
3809function styleRemove$1(name) {
3810 return function() {
3811 this.style.removeProperty(name);
3812 };
3813}
3814
3815function styleConstant$1(name, interpolate, value1) {
3816 var string00,
3817 string1 = value1 + "",
3818 interpolate0;
3819 return function() {
3820 var string0 = styleValue(this, name);
3821 return string0 === string1 ? null
3822 : string0 === string00 ? interpolate0
3823 : interpolate0 = interpolate(string00 = string0, value1);
3824 };
3825}
3826
3827function styleFunction$1(name, interpolate, value) {
3828 var string00,
3829 string10,
3830 interpolate0;
3831 return function() {
3832 var string0 = styleValue(this, name),
3833 value1 = value(this),
3834 string1 = value1 + "";
3835 if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
3836 return string0 === string1 ? null
3837 : string0 === string00 && string1 === string10 ? interpolate0
3838 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
3839 };
3840}
3841
3842function styleMaybeRemove(id, name) {
3843 var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
3844 return function() {
3845 var schedule = set$1(this, id),
3846 on = schedule.on,
3847 listener = schedule.value[key] == null ? remove || (remove = styleRemove$1(name)) : undefined;
3848
3849 // If this node shared a dispatch with the previous node,
3850 // just assign the updated shared dispatch and we’re done!
3851 // Otherwise, copy-on-write.
3852 if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
3853
3854 schedule.on = on1;
3855 };
3856}
3857
3858function transition_style(name, value, priority) {
3859 var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
3860 return value == null ? this
3861 .styleTween(name, styleNull(name, i))
3862 .on("end.style." + name, styleRemove$1(name))
3863 : typeof value === "function" ? this
3864 .styleTween(name, styleFunction$1(name, i, tweenValue(this, "style." + name, value)))
3865 .each(styleMaybeRemove(this._id, name))
3866 : this
3867 .styleTween(name, styleConstant$1(name, i, value), priority)
3868 .on("end.style." + name, null);
3869}
3870
3871function styleInterpolate(name, i, priority) {
3872 return function(t) {
3873 this.style.setProperty(name, i.call(this, t), priority);
3874 };
3875}
3876
3877function styleTween(name, value, priority) {
3878 var t, i0;
3879 function tween() {
3880 var i = value.apply(this, arguments);
3881 if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
3882 return t;
3883 }
3884 tween._value = value;
3885 return tween;
3886}
3887
3888function transition_styleTween(name, value, priority) {
3889 var key = "style." + (name += "");
3890 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3891 if (value == null) return this.tween(key, null);
3892 if (typeof value !== "function") throw new Error;
3893 return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
3894}
3895
3896function textConstant$1(value) {
3897 return function() {
3898 this.textContent = value;
3899 };
3900}
3901
3902function textFunction$1(value) {
3903 return function() {
3904 var value1 = value(this);
3905 this.textContent = value1 == null ? "" : value1;
3906 };
3907}
3908
3909function transition_text(value) {
3910 return this.tween("text", typeof value === "function"
3911 ? textFunction$1(tweenValue(this, "text", value))
3912 : textConstant$1(value == null ? "" : value + ""));
3913}
3914
3915function textInterpolate(i) {
3916 return function(t) {
3917 this.textContent = i.call(this, t);
3918 };
3919}
3920
3921function textTween(value) {
3922 var t0, i0;
3923 function tween() {
3924 var i = value.apply(this, arguments);
3925 if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
3926 return t0;
3927 }
3928 tween._value = value;
3929 return tween;
3930}
3931
3932function transition_textTween(value) {
3933 var key = "text";
3934 if (arguments.length < 1) return (key = this.tween(key)) && key._value;
3935 if (value == null) return this.tween(key, null);
3936 if (typeof value !== "function") throw new Error;
3937 return this.tween(key, textTween(value));
3938}
3939
3940function transition_transition() {
3941 var name = this._name,
3942 id0 = this._id,
3943 id1 = newId();
3944
3945 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
3946 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3947 if (node = group[i]) {
3948 var inherit = get$1(node, id0);
3949 schedule(node, name, id1, i, group, {
3950 time: inherit.time + inherit.delay + inherit.duration,
3951 delay: 0,
3952 duration: inherit.duration,
3953 ease: inherit.ease
3954 });
3955 }
3956 }
3957 }
3958
3959 return new Transition(groups, this._parents, name, id1);
3960}
3961
3962function transition_end() {
3963 var on0, on1, that = this, id = that._id, size = that.size();
3964 return new Promise(function(resolve, reject) {
3965 var cancel = {value: reject},
3966 end = {value: function() { if (--size === 0) resolve(); }};
3967
3968 that.each(function() {
3969 var schedule = set$1(this, id),
3970 on = schedule.on;
3971
3972 // If this node shared a dispatch with the previous node,
3973 // just assign the updated shared dispatch and we’re done!
3974 // Otherwise, copy-on-write.
3975 if (on !== on0) {
3976 on1 = (on0 = on).copy();
3977 on1._.cancel.push(cancel);
3978 on1._.interrupt.push(cancel);
3979 on1._.end.push(end);
3980 }
3981
3982 schedule.on = on1;
3983 });
3984 });
3985}
3986
3987var id = 0;
3988
3989function Transition(groups, parents, name, id) {
3990 this._groups = groups;
3991 this._parents = parents;
3992 this._name = name;
3993 this._id = id;
3994}
3995
3996function transition(name) {
3997 return selection().transition(name);
3998}
3999
4000function newId() {
4001 return ++id;
4002}
4003
4004var selection_prototype = selection.prototype;
4005
4006Transition.prototype = transition.prototype = {
4007 constructor: Transition,
4008 select: transition_select,
4009 selectAll: transition_selectAll,
4010 filter: transition_filter,
4011 merge: transition_merge,
4012 selection: transition_selection,
4013 transition: transition_transition,
4014 call: selection_prototype.call,
4015 nodes: selection_prototype.nodes,
4016 node: selection_prototype.node,
4017 size: selection_prototype.size,
4018 empty: selection_prototype.empty,
4019 each: selection_prototype.each,
4020 on: transition_on,
4021 attr: transition_attr,
4022 attrTween: transition_attrTween,
4023 style: transition_style,
4024 styleTween: transition_styleTween,
4025 text: transition_text,
4026 textTween: transition_textTween,
4027 remove: transition_remove,
4028 tween: transition_tween,
4029 delay: transition_delay,
4030 duration: transition_duration,
4031 ease: transition_ease,
4032 end: transition_end
4033};
4034
4035function linear$1(t) {
4036 return +t;
4037}
4038
4039function quadIn(t) {
4040 return t * t;
4041}
4042
4043function quadOut(t) {
4044 return t * (2 - t);
4045}
4046
4047function quadInOut(t) {
4048 return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
4049}
4050
4051function cubicIn(t) {
4052 return t * t * t;
4053}
4054
4055function cubicOut(t) {
4056 return --t * t * t + 1;
4057}
4058
4059function cubicInOut(t) {
4060 return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
4061}
4062
4063var exponent = 3;
4064
4065var polyIn = (function custom(e) {
4066 e = +e;
4067
4068 function polyIn(t) {
4069 return Math.pow(t, e);
4070 }
4071
4072 polyIn.exponent = custom;
4073
4074 return polyIn;
4075})(exponent);
4076
4077var polyOut = (function custom(e) {
4078 e = +e;
4079
4080 function polyOut(t) {
4081 return 1 - Math.pow(1 - t, e);
4082 }
4083
4084 polyOut.exponent = custom;
4085
4086 return polyOut;
4087})(exponent);
4088
4089var polyInOut = (function custom(e) {
4090 e = +e;
4091
4092 function polyInOut(t) {
4093 return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
4094 }
4095
4096 polyInOut.exponent = custom;
4097
4098 return polyInOut;
4099})(exponent);
4100
4101var pi = Math.PI,
4102 halfPi = pi / 2;
4103
4104function sinIn(t) {
4105 return 1 - Math.cos(t * halfPi);
4106}
4107
4108function sinOut(t) {
4109 return Math.sin(t * halfPi);
4110}
4111
4112function sinInOut(t) {
4113 return (1 - Math.cos(pi * t)) / 2;
4114}
4115
4116function expIn(t) {
4117 return Math.pow(2, 10 * t - 10);
4118}
4119
4120function expOut(t) {
4121 return 1 - Math.pow(2, -10 * t);
4122}
4123
4124function expInOut(t) {
4125 return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
4126}
4127
4128function circleIn(t) {
4129 return 1 - Math.sqrt(1 - t * t);
4130}
4131
4132function circleOut(t) {
4133 return Math.sqrt(1 - --t * t);
4134}
4135
4136function circleInOut(t) {
4137 return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
4138}
4139
4140var b1 = 4 / 11,
4141 b2 = 6 / 11,
4142 b3 = 8 / 11,
4143 b4 = 3 / 4,
4144 b5 = 9 / 11,
4145 b6 = 10 / 11,
4146 b7 = 15 / 16,
4147 b8 = 21 / 22,
4148 b9 = 63 / 64,
4149 b0 = 1 / b1 / b1;
4150
4151function bounceIn(t) {
4152 return 1 - bounceOut(1 - t);
4153}
4154
4155function bounceOut(t) {
4156 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;
4157}
4158
4159function bounceInOut(t) {
4160 return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
4161}
4162
4163var overshoot = 1.70158;
4164
4165var backIn = (function custom(s) {
4166 s = +s;
4167
4168 function backIn(t) {
4169 return t * t * ((s + 1) * t - s);
4170 }
4171
4172 backIn.overshoot = custom;
4173
4174 return backIn;
4175})(overshoot);
4176
4177var backOut = (function custom(s) {
4178 s = +s;
4179
4180 function backOut(t) {
4181 return --t * t * ((s + 1) * t + s) + 1;
4182 }
4183
4184 backOut.overshoot = custom;
4185
4186 return backOut;
4187})(overshoot);
4188
4189var backInOut = (function custom(s) {
4190 s = +s;
4191
4192 function backInOut(t) {
4193 return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
4194 }
4195
4196 backInOut.overshoot = custom;
4197
4198 return backInOut;
4199})(overshoot);
4200
4201var tau = 2 * Math.PI,
4202 amplitude = 1,
4203 period = 0.3;
4204
4205var elasticIn = (function custom(a, p) {
4206 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4207
4208 function elasticIn(t) {
4209 return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
4210 }
4211
4212 elasticIn.amplitude = function(a) { return custom(a, p * tau); };
4213 elasticIn.period = function(p) { return custom(a, p); };
4214
4215 return elasticIn;
4216})(amplitude, period);
4217
4218var elasticOut = (function custom(a, p) {
4219 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4220
4221 function elasticOut(t) {
4222 return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
4223 }
4224
4225 elasticOut.amplitude = function(a) { return custom(a, p * tau); };
4226 elasticOut.period = function(p) { return custom(a, p); };
4227
4228 return elasticOut;
4229})(amplitude, period);
4230
4231var elasticInOut = (function custom(a, p) {
4232 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4233
4234 function elasticInOut(t) {
4235 return ((t = t * 2 - 1) < 0
4236 ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
4237 : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
4238 }
4239
4240 elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
4241 elasticInOut.period = function(p) { return custom(a, p); };
4242
4243 return elasticInOut;
4244})(amplitude, period);
4245
4246var defaultTiming = {
4247 time: null, // Set on use.
4248 delay: 0,
4249 duration: 250,
4250 ease: cubicInOut
4251};
4252
4253function inherit(node, id) {
4254 var timing;
4255 while (!(timing = node.__transition) || !(timing = timing[id])) {
4256 if (!(node = node.parentNode)) {
4257 return defaultTiming.time = now(), defaultTiming;
4258 }
4259 }
4260 return timing;
4261}
4262
4263function selection_transition(name) {
4264 var id,
4265 timing;
4266
4267 if (name instanceof Transition) {
4268 id = name._id, name = name._name;
4269 } else {
4270 id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
4271 }
4272
4273 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4274 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4275 if (node = group[i]) {
4276 schedule(node, name, id, i, group, timing || inherit(node, id));
4277 }
4278 }
4279 }
4280
4281 return new Transition(groups, this._parents, name, id);
4282}
4283
4284selection.prototype.interrupt = selection_interrupt;
4285selection.prototype.transition = selection_transition;
4286
4287var root$1 = [null];
4288
4289function active(node, name) {
4290 var schedules = node.__transition,
4291 schedule,
4292 i;
4293
4294 if (schedules) {
4295 name = name == null ? null : name + "";
4296 for (i in schedules) {
4297 if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
4298 return new Transition([[node]], root$1, name, +i);
4299 }
4300 }
4301 }
4302
4303 return null;
4304}
4305
4306function constant$4(x) {
4307 return function() {
4308 return x;
4309 };
4310}
4311
4312function BrushEvent(target, type, selection) {
4313 this.target = target;
4314 this.type = type;
4315 this.selection = selection;
4316}
4317
4318function nopropagation$1() {
4319 exports.event.stopImmediatePropagation();
4320}
4321
4322function noevent$1() {
4323 exports.event.preventDefault();
4324 exports.event.stopImmediatePropagation();
4325}
4326
4327var MODE_DRAG = {name: "drag"},
4328 MODE_SPACE = {name: "space"},
4329 MODE_HANDLE = {name: "handle"},
4330 MODE_CENTER = {name: "center"};
4331
4332function number1(e) {
4333 return [+e[0], +e[1]];
4334}
4335
4336function number2(e) {
4337 return [number1(e[0]), number1(e[1])];
4338}
4339
4340function toucher(identifier) {
4341 return function(target) {
4342 return touch(target, exports.event.touches, identifier);
4343 };
4344}
4345
4346var X = {
4347 name: "x",
4348 handles: ["w", "e"].map(type),
4349 input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
4350 output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
4351};
4352
4353var Y = {
4354 name: "y",
4355 handles: ["n", "s"].map(type),
4356 input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
4357 output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
4358};
4359
4360var XY = {
4361 name: "xy",
4362 handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
4363 input: function(xy) { return xy == null ? null : number2(xy); },
4364 output: function(xy) { return xy; }
4365};
4366
4367var cursors = {
4368 overlay: "crosshair",
4369 selection: "move",
4370 n: "ns-resize",
4371 e: "ew-resize",
4372 s: "ns-resize",
4373 w: "ew-resize",
4374 nw: "nwse-resize",
4375 ne: "nesw-resize",
4376 se: "nwse-resize",
4377 sw: "nesw-resize"
4378};
4379
4380var flipX = {
4381 e: "w",
4382 w: "e",
4383 nw: "ne",
4384 ne: "nw",
4385 se: "sw",
4386 sw: "se"
4387};
4388
4389var flipY = {
4390 n: "s",
4391 s: "n",
4392 nw: "sw",
4393 ne: "se",
4394 se: "ne",
4395 sw: "nw"
4396};
4397
4398var signsX = {
4399 overlay: +1,
4400 selection: +1,
4401 n: null,
4402 e: +1,
4403 s: null,
4404 w: -1,
4405 nw: -1,
4406 ne: +1,
4407 se: +1,
4408 sw: -1
4409};
4410
4411var signsY = {
4412 overlay: +1,
4413 selection: +1,
4414 n: -1,
4415 e: null,
4416 s: +1,
4417 w: null,
4418 nw: -1,
4419 ne: -1,
4420 se: +1,
4421 sw: +1
4422};
4423
4424function type(t) {
4425 return {type: t};
4426}
4427
4428// Ignore right-click, since that should open the context menu.
4429function defaultFilter$1() {
4430 return !exports.event.ctrlKey && !exports.event.button;
4431}
4432
4433function defaultExtent() {
4434 var svg = this.ownerSVGElement || this;
4435 if (svg.hasAttribute("viewBox")) {
4436 svg = svg.viewBox.baseVal;
4437 return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
4438 }
4439 return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
4440}
4441
4442function defaultTouchable$1() {
4443 return navigator.maxTouchPoints || ("ontouchstart" in this);
4444}
4445
4446// Like d3.local, but with the name “__brush” rather than auto-generated.
4447function local$1(node) {
4448 while (!node.__brush) if (!(node = node.parentNode)) return;
4449 return node.__brush;
4450}
4451
4452function empty$1(extent) {
4453 return extent[0][0] === extent[1][0]
4454 || extent[0][1] === extent[1][1];
4455}
4456
4457function brushSelection(node) {
4458 var state = node.__brush;
4459 return state ? state.dim.output(state.selection) : null;
4460}
4461
4462function brushX() {
4463 return brush$1(X);
4464}
4465
4466function brushY() {
4467 return brush$1(Y);
4468}
4469
4470function brush() {
4471 return brush$1(XY);
4472}
4473
4474function brush$1(dim) {
4475 var extent = defaultExtent,
4476 filter = defaultFilter$1,
4477 touchable = defaultTouchable$1,
4478 keys = true,
4479 listeners = dispatch("start", "brush", "end"),
4480 handleSize = 6,
4481 touchending;
4482
4483 function brush(group) {
4484 var overlay = group
4485 .property("__brush", initialize)
4486 .selectAll(".overlay")
4487 .data([type("overlay")]);
4488
4489 overlay.enter().append("rect")
4490 .attr("class", "overlay")
4491 .attr("pointer-events", "all")
4492 .attr("cursor", cursors.overlay)
4493 .merge(overlay)
4494 .each(function() {
4495 var extent = local$1(this).extent;
4496 select(this)
4497 .attr("x", extent[0][0])
4498 .attr("y", extent[0][1])
4499 .attr("width", extent[1][0] - extent[0][0])
4500 .attr("height", extent[1][1] - extent[0][1]);
4501 });
4502
4503 group.selectAll(".selection")
4504 .data([type("selection")])
4505 .enter().append("rect")
4506 .attr("class", "selection")
4507 .attr("cursor", cursors.selection)
4508 .attr("fill", "#777")
4509 .attr("fill-opacity", 0.3)
4510 .attr("stroke", "#fff")
4511 .attr("shape-rendering", "crispEdges");
4512
4513 var handle = group.selectAll(".handle")
4514 .data(dim.handles, function(d) { return d.type; });
4515
4516 handle.exit().remove();
4517
4518 handle.enter().append("rect")
4519 .attr("class", function(d) { return "handle handle--" + d.type; })
4520 .attr("cursor", function(d) { return cursors[d.type]; });
4521
4522 group
4523 .each(redraw)
4524 .attr("fill", "none")
4525 .attr("pointer-events", "all")
4526 .on("mousedown.brush", started)
4527 .filter(touchable)
4528 .on("touchstart.brush", started)
4529 .on("touchmove.brush", touchmoved)
4530 .on("touchend.brush touchcancel.brush", touchended)
4531 .style("touch-action", "none")
4532 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
4533 }
4534
4535 brush.move = function(group, selection) {
4536 if (group.selection) {
4537 group
4538 .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
4539 .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
4540 .tween("brush", function() {
4541 var that = this,
4542 state = that.__brush,
4543 emit = emitter(that, arguments),
4544 selection0 = state.selection,
4545 selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
4546 i = interpolateValue(selection0, selection1);
4547
4548 function tween(t) {
4549 state.selection = t === 1 && selection1 === null ? null : i(t);
4550 redraw.call(that);
4551 emit.brush();
4552 }
4553
4554 return selection0 !== null && selection1 !== null ? tween : tween(1);
4555 });
4556 } else {
4557 group
4558 .each(function() {
4559 var that = this,
4560 args = arguments,
4561 state = that.__brush,
4562 selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
4563 emit = emitter(that, args).beforestart();
4564
4565 interrupt(that);
4566 state.selection = selection1 === null ? null : selection1;
4567 redraw.call(that);
4568 emit.start().brush().end();
4569 });
4570 }
4571 };
4572
4573 brush.clear = function(group) {
4574 brush.move(group, null);
4575 };
4576
4577 function redraw() {
4578 var group = select(this),
4579 selection = local$1(this).selection;
4580
4581 if (selection) {
4582 group.selectAll(".selection")
4583 .style("display", null)
4584 .attr("x", selection[0][0])
4585 .attr("y", selection[0][1])
4586 .attr("width", selection[1][0] - selection[0][0])
4587 .attr("height", selection[1][1] - selection[0][1]);
4588
4589 group.selectAll(".handle")
4590 .style("display", null)
4591 .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
4592 .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
4593 .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
4594 .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
4595 }
4596
4597 else {
4598 group.selectAll(".selection,.handle")
4599 .style("display", "none")
4600 .attr("x", null)
4601 .attr("y", null)
4602 .attr("width", null)
4603 .attr("height", null);
4604 }
4605 }
4606
4607 function emitter(that, args, clean) {
4608 return (!clean && that.__brush.emitter) || new Emitter(that, args);
4609 }
4610
4611 function Emitter(that, args) {
4612 this.that = that;
4613 this.args = args;
4614 this.state = that.__brush;
4615 this.active = 0;
4616 }
4617
4618 Emitter.prototype = {
4619 beforestart: function() {
4620 if (++this.active === 1) this.state.emitter = this, this.starting = true;
4621 return this;
4622 },
4623 start: function() {
4624 if (this.starting) this.starting = false, this.emit("start");
4625 else this.emit("brush");
4626 return this;
4627 },
4628 brush: function() {
4629 this.emit("brush");
4630 return this;
4631 },
4632 end: function() {
4633 if (--this.active === 0) delete this.state.emitter, this.emit("end");
4634 return this;
4635 },
4636 emit: function(type) {
4637 customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
4638 }
4639 };
4640
4641 function started() {
4642 if (touchending && !exports.event.touches) return;
4643 if (!filter.apply(this, arguments)) return;
4644
4645 var that = this,
4646 type = exports.event.target.__data__.type,
4647 mode = (keys && exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
4648 signX = dim === Y ? null : signsX[type],
4649 signY = dim === X ? null : signsY[type],
4650 state = local$1(that),
4651 extent = state.extent,
4652 selection = state.selection,
4653 W = extent[0][0], w0, w1,
4654 N = extent[0][1], n0, n1,
4655 E = extent[1][0], e0, e1,
4656 S = extent[1][1], s0, s1,
4657 dx = 0,
4658 dy = 0,
4659 moving,
4660 shifting = signX && signY && keys && exports.event.shiftKey,
4661 lockX,
4662 lockY,
4663 pointer = exports.event.touches ? toucher(exports.event.changedTouches[0].identifier) : mouse,
4664 point0 = pointer(that),
4665 point = point0,
4666 emit = emitter(that, arguments, true).beforestart();
4667
4668 if (type === "overlay") {
4669 if (selection) moving = true;
4670 state.selection = selection = [
4671 [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
4672 [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
4673 ];
4674 } else {
4675 w0 = selection[0][0];
4676 n0 = selection[0][1];
4677 e0 = selection[1][0];
4678 s0 = selection[1][1];
4679 }
4680
4681 w1 = w0;
4682 n1 = n0;
4683 e1 = e0;
4684 s1 = s0;
4685
4686 var group = select(that)
4687 .attr("pointer-events", "none");
4688
4689 var overlay = group.selectAll(".overlay")
4690 .attr("cursor", cursors[type]);
4691
4692 if (exports.event.touches) {
4693 emit.moved = moved;
4694 emit.ended = ended;
4695 } else {
4696 var view = select(exports.event.view)
4697 .on("mousemove.brush", moved, true)
4698 .on("mouseup.brush", ended, true);
4699 if (keys) view
4700 .on("keydown.brush", keydowned, true)
4701 .on("keyup.brush", keyupped, true);
4702
4703 dragDisable(exports.event.view);
4704 }
4705
4706 nopropagation$1();
4707 interrupt(that);
4708 redraw.call(that);
4709 emit.start();
4710
4711 function moved() {
4712 var point1 = pointer(that);
4713 if (shifting && !lockX && !lockY) {
4714 if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
4715 else lockX = true;
4716 }
4717 point = point1;
4718 moving = true;
4719 noevent$1();
4720 move();
4721 }
4722
4723 function move() {
4724 var t;
4725
4726 dx = point[0] - point0[0];
4727 dy = point[1] - point0[1];
4728
4729 switch (mode) {
4730 case MODE_SPACE:
4731 case MODE_DRAG: {
4732 if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
4733 if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
4734 break;
4735 }
4736 case MODE_HANDLE: {
4737 if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
4738 else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
4739 if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
4740 else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
4741 break;
4742 }
4743 case MODE_CENTER: {
4744 if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
4745 if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
4746 break;
4747 }
4748 }
4749
4750 if (e1 < w1) {
4751 signX *= -1;
4752 t = w0, w0 = e0, e0 = t;
4753 t = w1, w1 = e1, e1 = t;
4754 if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
4755 }
4756
4757 if (s1 < n1) {
4758 signY *= -1;
4759 t = n0, n0 = s0, s0 = t;
4760 t = n1, n1 = s1, s1 = t;
4761 if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
4762 }
4763
4764 if (state.selection) selection = state.selection; // May be set by brush.move!
4765 if (lockX) w1 = selection[0][0], e1 = selection[1][0];
4766 if (lockY) n1 = selection[0][1], s1 = selection[1][1];
4767
4768 if (selection[0][0] !== w1
4769 || selection[0][1] !== n1
4770 || selection[1][0] !== e1
4771 || selection[1][1] !== s1) {
4772 state.selection = [[w1, n1], [e1, s1]];
4773 redraw.call(that);
4774 emit.brush();
4775 }
4776 }
4777
4778 function ended() {
4779 nopropagation$1();
4780 if (exports.event.touches) {
4781 if (exports.event.touches.length) return;
4782 if (touchending) clearTimeout(touchending);
4783 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
4784 } else {
4785 yesdrag(exports.event.view, moving);
4786 view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
4787 }
4788 group.attr("pointer-events", "all");
4789 overlay.attr("cursor", cursors.overlay);
4790 if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
4791 if (empty$1(selection)) state.selection = null, redraw.call(that);
4792 emit.end();
4793 }
4794
4795 function keydowned() {
4796 switch (exports.event.keyCode) {
4797 case 16: { // SHIFT
4798 shifting = signX && signY;
4799 break;
4800 }
4801 case 18: { // ALT
4802 if (mode === MODE_HANDLE) {
4803 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4804 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4805 mode = MODE_CENTER;
4806 move();
4807 }
4808 break;
4809 }
4810 case 32: { // SPACE; takes priority over ALT
4811 if (mode === MODE_HANDLE || mode === MODE_CENTER) {
4812 if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
4813 if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
4814 mode = MODE_SPACE;
4815 overlay.attr("cursor", cursors.selection);
4816 move();
4817 }
4818 break;
4819 }
4820 default: return;
4821 }
4822 noevent$1();
4823 }
4824
4825 function keyupped() {
4826 switch (exports.event.keyCode) {
4827 case 16: { // SHIFT
4828 if (shifting) {
4829 lockX = lockY = shifting = false;
4830 move();
4831 }
4832 break;
4833 }
4834 case 18: { // ALT
4835 if (mode === MODE_CENTER) {
4836 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4837 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4838 mode = MODE_HANDLE;
4839 move();
4840 }
4841 break;
4842 }
4843 case 32: { // SPACE
4844 if (mode === MODE_SPACE) {
4845 if (exports.event.altKey) {
4846 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4847 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4848 mode = MODE_CENTER;
4849 } else {
4850 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4851 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4852 mode = MODE_HANDLE;
4853 }
4854 overlay.attr("cursor", cursors[type]);
4855 move();
4856 }
4857 break;
4858 }
4859 default: return;
4860 }
4861 noevent$1();
4862 }
4863 }
4864
4865 function touchmoved() {
4866 emitter(this, arguments).moved();
4867 }
4868
4869 function touchended() {
4870 emitter(this, arguments).ended();
4871 }
4872
4873 function initialize() {
4874 var state = this.__brush || {selection: null};
4875 state.extent = number2(extent.apply(this, arguments));
4876 state.dim = dim;
4877 return state;
4878 }
4879
4880 brush.extent = function(_) {
4881 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4(number2(_)), brush) : extent;
4882 };
4883
4884 brush.filter = function(_) {
4885 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
4886 };
4887
4888 brush.touchable = function(_) {
4889 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$4(!!_), brush) : touchable;
4890 };
4891
4892 brush.handleSize = function(_) {
4893 return arguments.length ? (handleSize = +_, brush) : handleSize;
4894 };
4895
4896 brush.keyModifiers = function(_) {
4897 return arguments.length ? (keys = !!_, brush) : keys;
4898 };
4899
4900 brush.on = function() {
4901 var value = listeners.on.apply(listeners, arguments);
4902 return value === listeners ? brush : value;
4903 };
4904
4905 return brush;
4906}
4907
4908var cos = Math.cos;
4909var sin = Math.sin;
4910var pi$1 = Math.PI;
4911var halfPi$1 = pi$1 / 2;
4912var tau$1 = pi$1 * 2;
4913var max$1 = Math.max;
4914
4915function compareValue(compare) {
4916 return function(a, b) {
4917 return compare(
4918 a.source.value + a.target.value,
4919 b.source.value + b.target.value
4920 );
4921 };
4922}
4923
4924function chord() {
4925 var padAngle = 0,
4926 sortGroups = null,
4927 sortSubgroups = null,
4928 sortChords = null;
4929
4930 function chord(matrix) {
4931 var n = matrix.length,
4932 groupSums = [],
4933 groupIndex = sequence(n),
4934 subgroupIndex = [],
4935 chords = [],
4936 groups = chords.groups = new Array(n),
4937 subgroups = new Array(n * n),
4938 k,
4939 x,
4940 x0,
4941 dx,
4942 i,
4943 j;
4944
4945 // Compute the sum.
4946 k = 0, i = -1; while (++i < n) {
4947 x = 0, j = -1; while (++j < n) {
4948 x += matrix[i][j];
4949 }
4950 groupSums.push(x);
4951 subgroupIndex.push(sequence(n));
4952 k += x;
4953 }
4954
4955 // Sort groups…
4956 if (sortGroups) groupIndex.sort(function(a, b) {
4957 return sortGroups(groupSums[a], groupSums[b]);
4958 });
4959
4960 // Sort subgroups…
4961 if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
4962 d.sort(function(a, b) {
4963 return sortSubgroups(matrix[i][a], matrix[i][b]);
4964 });
4965 });
4966
4967 // Convert the sum to scaling factor for [0, 2pi].
4968 // TODO Allow start and end angle to be specified?
4969 // TODO Allow padding to be specified as percentage?
4970 k = max$1(0, tau$1 - padAngle * n) / k;
4971 dx = k ? padAngle : tau$1 / n;
4972
4973 // Compute the start and end angle for each group and subgroup.
4974 // Note: Opera has a bug reordering object literal properties!
4975 x = 0, i = -1; while (++i < n) {
4976 x0 = x, j = -1; while (++j < n) {
4977 var di = groupIndex[i],
4978 dj = subgroupIndex[di][j],
4979 v = matrix[di][dj],
4980 a0 = x,
4981 a1 = x += v * k;
4982 subgroups[dj * n + di] = {
4983 index: di,
4984 subindex: dj,
4985 startAngle: a0,
4986 endAngle: a1,
4987 value: v
4988 };
4989 }
4990 groups[di] = {
4991 index: di,
4992 startAngle: x0,
4993 endAngle: x,
4994 value: groupSums[di]
4995 };
4996 x += dx;
4997 }
4998
4999 // Generate chords for each (non-empty) subgroup-subgroup link.
5000 i = -1; while (++i < n) {
5001 j = i - 1; while (++j < n) {
5002 var source = subgroups[j * n + i],
5003 target = subgroups[i * n + j];
5004 if (source.value || target.value) {
5005 chords.push(source.value < target.value
5006 ? {source: target, target: source}
5007 : {source: source, target: target});
5008 }
5009 }
5010 }
5011
5012 return sortChords ? chords.sort(sortChords) : chords;
5013 }
5014
5015 chord.padAngle = function(_) {
5016 return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
5017 };
5018
5019 chord.sortGroups = function(_) {
5020 return arguments.length ? (sortGroups = _, chord) : sortGroups;
5021 };
5022
5023 chord.sortSubgroups = function(_) {
5024 return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
5025 };
5026
5027 chord.sortChords = function(_) {
5028 return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
5029 };
5030
5031 return chord;
5032}
5033
5034var slice$2 = Array.prototype.slice;
5035
5036function constant$5(x) {
5037 return function() {
5038 return x;
5039 };
5040}
5041
5042var pi$2 = Math.PI,
5043 tau$2 = 2 * pi$2,
5044 epsilon$1 = 1e-6,
5045 tauEpsilon = tau$2 - epsilon$1;
5046
5047function Path() {
5048 this._x0 = this._y0 = // start of current subpath
5049 this._x1 = this._y1 = null; // end of current subpath
5050 this._ = "";
5051}
5052
5053function path() {
5054 return new Path;
5055}
5056
5057Path.prototype = path.prototype = {
5058 constructor: Path,
5059 moveTo: function(x, y) {
5060 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
5061 },
5062 closePath: function() {
5063 if (this._x1 !== null) {
5064 this._x1 = this._x0, this._y1 = this._y0;
5065 this._ += "Z";
5066 }
5067 },
5068 lineTo: function(x, y) {
5069 this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
5070 },
5071 quadraticCurveTo: function(x1, y1, x, y) {
5072 this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
5073 },
5074 bezierCurveTo: function(x1, y1, x2, y2, x, y) {
5075 this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
5076 },
5077 arcTo: function(x1, y1, x2, y2, r) {
5078 x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
5079 var x0 = this._x1,
5080 y0 = this._y1,
5081 x21 = x2 - x1,
5082 y21 = y2 - y1,
5083 x01 = x0 - x1,
5084 y01 = y0 - y1,
5085 l01_2 = x01 * x01 + y01 * y01;
5086
5087 // Is the radius negative? Error.
5088 if (r < 0) throw new Error("negative radius: " + r);
5089
5090 // Is this path empty? Move to (x1,y1).
5091 if (this._x1 === null) {
5092 this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
5093 }
5094
5095 // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
5096 else if (!(l01_2 > epsilon$1));
5097
5098 // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
5099 // Equivalently, is (x1,y1) coincident with (x2,y2)?
5100 // Or, is the radius zero? Line to (x1,y1).
5101 else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
5102 this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
5103 }
5104
5105 // Otherwise, draw an arc!
5106 else {
5107 var x20 = x2 - x0,
5108 y20 = y2 - y0,
5109 l21_2 = x21 * x21 + y21 * y21,
5110 l20_2 = x20 * x20 + y20 * y20,
5111 l21 = Math.sqrt(l21_2),
5112 l01 = Math.sqrt(l01_2),
5113 l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
5114 t01 = l / l01,
5115 t21 = l / l21;
5116
5117 // If the start tangent is not coincident with (x0,y0), line to.
5118 if (Math.abs(t01 - 1) > epsilon$1) {
5119 this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
5120 }
5121
5122 this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
5123 }
5124 },
5125 arc: function(x, y, r, a0, a1, ccw) {
5126 x = +x, y = +y, r = +r, ccw = !!ccw;
5127 var dx = r * Math.cos(a0),
5128 dy = r * Math.sin(a0),
5129 x0 = x + dx,
5130 y0 = y + dy,
5131 cw = 1 ^ ccw,
5132 da = ccw ? a0 - a1 : a1 - a0;
5133
5134 // Is the radius negative? Error.
5135 if (r < 0) throw new Error("negative radius: " + r);
5136
5137 // Is this path empty? Move to (x0,y0).
5138 if (this._x1 === null) {
5139 this._ += "M" + x0 + "," + y0;
5140 }
5141
5142 // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
5143 else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
5144 this._ += "L" + x0 + "," + y0;
5145 }
5146
5147 // Is this arc empty? We’re done.
5148 if (!r) return;
5149
5150 // Does the angle go the wrong way? Flip the direction.
5151 if (da < 0) da = da % tau$2 + tau$2;
5152
5153 // Is this a complete circle? Draw two arcs to complete the circle.
5154 if (da > tauEpsilon) {
5155 this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
5156 }
5157
5158 // Is this arc non-empty? Draw an arc!
5159 else if (da > epsilon$1) {
5160 this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
5161 }
5162 },
5163 rect: function(x, y, w, h) {
5164 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
5165 },
5166 toString: function() {
5167 return this._;
5168 }
5169};
5170
5171function defaultSource(d) {
5172 return d.source;
5173}
5174
5175function defaultTarget(d) {
5176 return d.target;
5177}
5178
5179function defaultRadius(d) {
5180 return d.radius;
5181}
5182
5183function defaultStartAngle(d) {
5184 return d.startAngle;
5185}
5186
5187function defaultEndAngle(d) {
5188 return d.endAngle;
5189}
5190
5191function ribbon() {
5192 var source = defaultSource,
5193 target = defaultTarget,
5194 radius = defaultRadius,
5195 startAngle = defaultStartAngle,
5196 endAngle = defaultEndAngle,
5197 context = null;
5198
5199 function ribbon() {
5200 var buffer,
5201 argv = slice$2.call(arguments),
5202 s = source.apply(this, argv),
5203 t = target.apply(this, argv),
5204 sr = +radius.apply(this, (argv[0] = s, argv)),
5205 sa0 = startAngle.apply(this, argv) - halfPi$1,
5206 sa1 = endAngle.apply(this, argv) - halfPi$1,
5207 sx0 = sr * cos(sa0),
5208 sy0 = sr * sin(sa0),
5209 tr = +radius.apply(this, (argv[0] = t, argv)),
5210 ta0 = startAngle.apply(this, argv) - halfPi$1,
5211 ta1 = endAngle.apply(this, argv) - halfPi$1;
5212
5213 if (!context) context = buffer = path();
5214
5215 context.moveTo(sx0, sy0);
5216 context.arc(0, 0, sr, sa0, sa1);
5217 if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
5218 context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
5219 context.arc(0, 0, tr, ta0, ta1);
5220 }
5221 context.quadraticCurveTo(0, 0, sx0, sy0);
5222 context.closePath();
5223
5224 if (buffer) return context = null, buffer + "" || null;
5225 }
5226
5227 ribbon.radius = function(_) {
5228 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
5229 };
5230
5231 ribbon.startAngle = function(_) {
5232 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
5233 };
5234
5235 ribbon.endAngle = function(_) {
5236 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
5237 };
5238
5239 ribbon.source = function(_) {
5240 return arguments.length ? (source = _, ribbon) : source;
5241 };
5242
5243 ribbon.target = function(_) {
5244 return arguments.length ? (target = _, ribbon) : target;
5245 };
5246
5247 ribbon.context = function(_) {
5248 return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
5249 };
5250
5251 return ribbon;
5252}
5253
5254var prefix = "$";
5255
5256function Map() {}
5257
5258Map.prototype = map$1.prototype = {
5259 constructor: Map,
5260 has: function(key) {
5261 return (prefix + key) in this;
5262 },
5263 get: function(key) {
5264 return this[prefix + key];
5265 },
5266 set: function(key, value) {
5267 this[prefix + key] = value;
5268 return this;
5269 },
5270 remove: function(key) {
5271 var property = prefix + key;
5272 return property in this && delete this[property];
5273 },
5274 clear: function() {
5275 for (var property in this) if (property[0] === prefix) delete this[property];
5276 },
5277 keys: function() {
5278 var keys = [];
5279 for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
5280 return keys;
5281 },
5282 values: function() {
5283 var values = [];
5284 for (var property in this) if (property[0] === prefix) values.push(this[property]);
5285 return values;
5286 },
5287 entries: function() {
5288 var entries = [];
5289 for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
5290 return entries;
5291 },
5292 size: function() {
5293 var size = 0;
5294 for (var property in this) if (property[0] === prefix) ++size;
5295 return size;
5296 },
5297 empty: function() {
5298 for (var property in this) if (property[0] === prefix) return false;
5299 return true;
5300 },
5301 each: function(f) {
5302 for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
5303 }
5304};
5305
5306function map$1(object, f) {
5307 var map = new Map;
5308
5309 // Copy constructor.
5310 if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
5311
5312 // Index array by numeric index or specified key function.
5313 else if (Array.isArray(object)) {
5314 var i = -1,
5315 n = object.length,
5316 o;
5317
5318 if (f == null) while (++i < n) map.set(i, object[i]);
5319 else while (++i < n) map.set(f(o = object[i], i, object), o);
5320 }
5321
5322 // Convert object to map.
5323 else if (object) for (var key in object) map.set(key, object[key]);
5324
5325 return map;
5326}
5327
5328function nest() {
5329 var keys = [],
5330 sortKeys = [],
5331 sortValues,
5332 rollup,
5333 nest;
5334
5335 function apply(array, depth, createResult, setResult) {
5336 if (depth >= keys.length) {
5337 if (sortValues != null) array.sort(sortValues);
5338 return rollup != null ? rollup(array) : array;
5339 }
5340
5341 var i = -1,
5342 n = array.length,
5343 key = keys[depth++],
5344 keyValue,
5345 value,
5346 valuesByKey = map$1(),
5347 values,
5348 result = createResult();
5349
5350 while (++i < n) {
5351 if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
5352 values.push(value);
5353 } else {
5354 valuesByKey.set(keyValue, [value]);
5355 }
5356 }
5357
5358 valuesByKey.each(function(values, key) {
5359 setResult(result, key, apply(values, depth, createResult, setResult));
5360 });
5361
5362 return result;
5363 }
5364
5365 function entries(map, depth) {
5366 if (++depth > keys.length) return map;
5367 var array, sortKey = sortKeys[depth - 1];
5368 if (rollup != null && depth >= keys.length) array = map.entries();
5369 else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
5370 return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
5371 }
5372
5373 return nest = {
5374 object: function(array) { return apply(array, 0, createObject, setObject); },
5375 map: function(array) { return apply(array, 0, createMap, setMap); },
5376 entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
5377 key: function(d) { keys.push(d); return nest; },
5378 sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
5379 sortValues: function(order) { sortValues = order; return nest; },
5380 rollup: function(f) { rollup = f; return nest; }
5381 };
5382}
5383
5384function createObject() {
5385 return {};
5386}
5387
5388function setObject(object, key, value) {
5389 object[key] = value;
5390}
5391
5392function createMap() {
5393 return map$1();
5394}
5395
5396function setMap(map, key, value) {
5397 map.set(key, value);
5398}
5399
5400function Set() {}
5401
5402var proto = map$1.prototype;
5403
5404Set.prototype = set$2.prototype = {
5405 constructor: Set,
5406 has: proto.has,
5407 add: function(value) {
5408 value += "";
5409 this[prefix + value] = value;
5410 return this;
5411 },
5412 remove: proto.remove,
5413 clear: proto.clear,
5414 values: proto.keys,
5415 size: proto.size,
5416 empty: proto.empty,
5417 each: proto.each
5418};
5419
5420function set$2(object, f) {
5421 var set = new Set;
5422
5423 // Copy constructor.
5424 if (object instanceof Set) object.each(function(value) { set.add(value); });
5425
5426 // Otherwise, assume it’s an array.
5427 else if (object) {
5428 var i = -1, n = object.length;
5429 if (f == null) while (++i < n) set.add(object[i]);
5430 else while (++i < n) set.add(f(object[i], i, object));
5431 }
5432
5433 return set;
5434}
5435
5436function keys(map) {
5437 var keys = [];
5438 for (var key in map) keys.push(key);
5439 return keys;
5440}
5441
5442function values(map) {
5443 var values = [];
5444 for (var key in map) values.push(map[key]);
5445 return values;
5446}
5447
5448function entries(map) {
5449 var entries = [];
5450 for (var key in map) entries.push({key: key, value: map[key]});
5451 return entries;
5452}
5453
5454var array$2 = Array.prototype;
5455
5456var slice$3 = array$2.slice;
5457
5458function ascending$2(a, b) {
5459 return a - b;
5460}
5461
5462function area(ring) {
5463 var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
5464 while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
5465 return area;
5466}
5467
5468function constant$6(x) {
5469 return function() {
5470 return x;
5471 };
5472}
5473
5474function contains(ring, hole) {
5475 var i = -1, n = hole.length, c;
5476 while (++i < n) if (c = ringContains(ring, hole[i])) return c;
5477 return 0;
5478}
5479
5480function ringContains(ring, point) {
5481 var x = point[0], y = point[1], contains = -1;
5482 for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
5483 var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
5484 if (segmentContains(pi, pj, point)) return 0;
5485 if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
5486 }
5487 return contains;
5488}
5489
5490function segmentContains(a, b, c) {
5491 var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
5492}
5493
5494function collinear(a, b, c) {
5495 return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
5496}
5497
5498function within(p, q, r) {
5499 return p <= q && q <= r || r <= q && q <= p;
5500}
5501
5502function noop$1() {}
5503
5504var cases = [
5505 [],
5506 [[[1.0, 1.5], [0.5, 1.0]]],
5507 [[[1.5, 1.0], [1.0, 1.5]]],
5508 [[[1.5, 1.0], [0.5, 1.0]]],
5509 [[[1.0, 0.5], [1.5, 1.0]]],
5510 [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
5511 [[[1.0, 0.5], [1.0, 1.5]]],
5512 [[[1.0, 0.5], [0.5, 1.0]]],
5513 [[[0.5, 1.0], [1.0, 0.5]]],
5514 [[[1.0, 1.5], [1.0, 0.5]]],
5515 [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
5516 [[[1.5, 1.0], [1.0, 0.5]]],
5517 [[[0.5, 1.0], [1.5, 1.0]]],
5518 [[[1.0, 1.5], [1.5, 1.0]]],
5519 [[[0.5, 1.0], [1.0, 1.5]]],
5520 []
5521];
5522
5523function contours() {
5524 var dx = 1,
5525 dy = 1,
5526 threshold = thresholdSturges,
5527 smooth = smoothLinear;
5528
5529 function contours(values) {
5530 var tz = threshold(values);
5531
5532 // Convert number of thresholds into uniform thresholds.
5533 if (!Array.isArray(tz)) {
5534 var domain = extent(values), start = domain[0], stop = domain[1];
5535 tz = tickStep(start, stop, tz);
5536 tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
5537 } else {
5538 tz = tz.slice().sort(ascending$2);
5539 }
5540
5541 return tz.map(function(value) {
5542 return contour(values, value);
5543 });
5544 }
5545
5546 // Accumulate, smooth contour rings, assign holes to exterior rings.
5547 // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
5548 function contour(values, value) {
5549 var polygons = [],
5550 holes = [];
5551
5552 isorings(values, value, function(ring) {
5553 smooth(ring, values, value);
5554 if (area(ring) > 0) polygons.push([ring]);
5555 else holes.push(ring);
5556 });
5557
5558 holes.forEach(function(hole) {
5559 for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
5560 if (contains((polygon = polygons[i])[0], hole) !== -1) {
5561 polygon.push(hole);
5562 return;
5563 }
5564 }
5565 });
5566
5567 return {
5568 type: "MultiPolygon",
5569 value: value,
5570 coordinates: polygons
5571 };
5572 }
5573
5574 // Marching squares with isolines stitched into rings.
5575 // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
5576 function isorings(values, value, callback) {
5577 var fragmentByStart = new Array,
5578 fragmentByEnd = new Array,
5579 x, y, t0, t1, t2, t3;
5580
5581 // Special case for the first row (y = -1, t2 = t3 = 0).
5582 x = y = -1;
5583 t1 = values[0] >= value;
5584 cases[t1 << 1].forEach(stitch);
5585 while (++x < dx - 1) {
5586 t0 = t1, t1 = values[x + 1] >= value;
5587 cases[t0 | t1 << 1].forEach(stitch);
5588 }
5589 cases[t1 << 0].forEach(stitch);
5590
5591 // General case for the intermediate rows.
5592 while (++y < dy - 1) {
5593 x = -1;
5594 t1 = values[y * dx + dx] >= value;
5595 t2 = values[y * dx] >= value;
5596 cases[t1 << 1 | t2 << 2].forEach(stitch);
5597 while (++x < dx - 1) {
5598 t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
5599 t3 = t2, t2 = values[y * dx + x + 1] >= value;
5600 cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
5601 }
5602 cases[t1 | t2 << 3].forEach(stitch);
5603 }
5604
5605 // Special case for the last row (y = dy - 1, t0 = t1 = 0).
5606 x = -1;
5607 t2 = values[y * dx] >= value;
5608 cases[t2 << 2].forEach(stitch);
5609 while (++x < dx - 1) {
5610 t3 = t2, t2 = values[y * dx + x + 1] >= value;
5611 cases[t2 << 2 | t3 << 3].forEach(stitch);
5612 }
5613 cases[t2 << 3].forEach(stitch);
5614
5615 function stitch(line) {
5616 var start = [line[0][0] + x, line[0][1] + y],
5617 end = [line[1][0] + x, line[1][1] + y],
5618 startIndex = index(start),
5619 endIndex = index(end),
5620 f, g;
5621 if (f = fragmentByEnd[startIndex]) {
5622 if (g = fragmentByStart[endIndex]) {
5623 delete fragmentByEnd[f.end];
5624 delete fragmentByStart[g.start];
5625 if (f === g) {
5626 f.ring.push(end);
5627 callback(f.ring);
5628 } else {
5629 fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
5630 }
5631 } else {
5632 delete fragmentByEnd[f.end];
5633 f.ring.push(end);
5634 fragmentByEnd[f.end = endIndex] = f;
5635 }
5636 } else if (f = fragmentByStart[endIndex]) {
5637 if (g = fragmentByEnd[startIndex]) {
5638 delete fragmentByStart[f.start];
5639 delete fragmentByEnd[g.end];
5640 if (f === g) {
5641 f.ring.push(end);
5642 callback(f.ring);
5643 } else {
5644 fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
5645 }
5646 } else {
5647 delete fragmentByStart[f.start];
5648 f.ring.unshift(start);
5649 fragmentByStart[f.start = startIndex] = f;
5650 }
5651 } else {
5652 fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
5653 }
5654 }
5655 }
5656
5657 function index(point) {
5658 return point[0] * 2 + point[1] * (dx + 1) * 4;
5659 }
5660
5661 function smoothLinear(ring, values, value) {
5662 ring.forEach(function(point) {
5663 var x = point[0],
5664 y = point[1],
5665 xt = x | 0,
5666 yt = y | 0,
5667 v0,
5668 v1 = values[yt * dx + xt];
5669 if (x > 0 && x < dx && xt === x) {
5670 v0 = values[yt * dx + xt - 1];
5671 point[0] = x + (value - v0) / (v1 - v0) - 0.5;
5672 }
5673 if (y > 0 && y < dy && yt === y) {
5674 v0 = values[(yt - 1) * dx + xt];
5675 point[1] = y + (value - v0) / (v1 - v0) - 0.5;
5676 }
5677 });
5678 }
5679
5680 contours.contour = contour;
5681
5682 contours.size = function(_) {
5683 if (!arguments.length) return [dx, dy];
5684 var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
5685 if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
5686 return dx = _0, dy = _1, contours;
5687 };
5688
5689 contours.thresholds = function(_) {
5690 return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold;
5691 };
5692
5693 contours.smooth = function(_) {
5694 return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
5695 };
5696
5697 return contours;
5698}
5699
5700// TODO Optimize edge cases.
5701// TODO Optimize index calculation.
5702// TODO Optimize arguments.
5703function blurX(source, target, r) {
5704 var n = source.width,
5705 m = source.height,
5706 w = (r << 1) + 1;
5707 for (var j = 0; j < m; ++j) {
5708 for (var i = 0, sr = 0; i < n + r; ++i) {
5709 if (i < n) {
5710 sr += source.data[i + j * n];
5711 }
5712 if (i >= r) {
5713 if (i >= w) {
5714 sr -= source.data[i - w + j * n];
5715 }
5716 target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
5717 }
5718 }
5719 }
5720}
5721
5722// TODO Optimize edge cases.
5723// TODO Optimize index calculation.
5724// TODO Optimize arguments.
5725function blurY(source, target, r) {
5726 var n = source.width,
5727 m = source.height,
5728 w = (r << 1) + 1;
5729 for (var i = 0; i < n; ++i) {
5730 for (var j = 0, sr = 0; j < m + r; ++j) {
5731 if (j < m) {
5732 sr += source.data[i + j * n];
5733 }
5734 if (j >= r) {
5735 if (j >= w) {
5736 sr -= source.data[i + (j - w) * n];
5737 }
5738 target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
5739 }
5740 }
5741 }
5742}
5743
5744function defaultX(d) {
5745 return d[0];
5746}
5747
5748function defaultY(d) {
5749 return d[1];
5750}
5751
5752function defaultWeight() {
5753 return 1;
5754}
5755
5756function density() {
5757 var x = defaultX,
5758 y = defaultY,
5759 weight = defaultWeight,
5760 dx = 960,
5761 dy = 500,
5762 r = 20, // blur radius
5763 k = 2, // log2(grid cell size)
5764 o = r * 3, // grid offset, to pad for blur
5765 n = (dx + o * 2) >> k, // grid width
5766 m = (dy + o * 2) >> k, // grid height
5767 threshold = constant$6(20);
5768
5769 function density(data) {
5770 var values0 = new Float32Array(n * m),
5771 values1 = new Float32Array(n * m);
5772
5773 data.forEach(function(d, i, data) {
5774 var xi = (+x(d, i, data) + o) >> k,
5775 yi = (+y(d, i, data) + o) >> k,
5776 wi = +weight(d, i, data);
5777 if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
5778 values0[xi + yi * n] += wi;
5779 }
5780 });
5781
5782 // TODO Optimize.
5783 blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5784 blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5785 blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5786 blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5787 blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5788 blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5789
5790 var tz = threshold(values0);
5791
5792 // Convert number of thresholds into uniform thresholds.
5793 if (!Array.isArray(tz)) {
5794 var stop = max(values0);
5795 tz = tickStep(0, stop, tz);
5796 tz = sequence(0, Math.floor(stop / tz) * tz, tz);
5797 tz.shift();
5798 }
5799
5800 return contours()
5801 .thresholds(tz)
5802 .size([n, m])
5803 (values0)
5804 .map(transform);
5805 }
5806
5807 function transform(geometry) {
5808 geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
5809 geometry.coordinates.forEach(transformPolygon);
5810 return geometry;
5811 }
5812
5813 function transformPolygon(coordinates) {
5814 coordinates.forEach(transformRing);
5815 }
5816
5817 function transformRing(coordinates) {
5818 coordinates.forEach(transformPoint);
5819 }
5820
5821 // TODO Optimize.
5822 function transformPoint(coordinates) {
5823 coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
5824 coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
5825 }
5826
5827 function resize() {
5828 o = r * 3;
5829 n = (dx + o * 2) >> k;
5830 m = (dy + o * 2) >> k;
5831 return density;
5832 }
5833
5834 density.x = function(_) {
5835 return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
5836 };
5837
5838 density.y = function(_) {
5839 return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
5840 };
5841
5842 density.weight = function(_) {
5843 return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
5844 };
5845
5846 density.size = function(_) {
5847 if (!arguments.length) return [dx, dy];
5848 var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
5849 if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
5850 return dx = _0, dy = _1, resize();
5851 };
5852
5853 density.cellSize = function(_) {
5854 if (!arguments.length) return 1 << k;
5855 if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
5856 return k = Math.floor(Math.log(_) / Math.LN2), resize();
5857 };
5858
5859 density.thresholds = function(_) {
5860 return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold;
5861 };
5862
5863 density.bandwidth = function(_) {
5864 if (!arguments.length) return Math.sqrt(r * (r + 1));
5865 if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
5866 return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
5867 };
5868
5869 return density;
5870}
5871
5872var EOL = {},
5873 EOF = {},
5874 QUOTE = 34,
5875 NEWLINE = 10,
5876 RETURN = 13;
5877
5878function objectConverter(columns) {
5879 return new Function("d", "return {" + columns.map(function(name, i) {
5880 return JSON.stringify(name) + ": d[" + i + "] || \"\"";
5881 }).join(",") + "}");
5882}
5883
5884function customConverter(columns, f) {
5885 var object = objectConverter(columns);
5886 return function(row, i) {
5887 return f(object(row), i, columns);
5888 };
5889}
5890
5891// Compute unique columns in order of discovery.
5892function inferColumns(rows) {
5893 var columnSet = Object.create(null),
5894 columns = [];
5895
5896 rows.forEach(function(row) {
5897 for (var column in row) {
5898 if (!(column in columnSet)) {
5899 columns.push(columnSet[column] = column);
5900 }
5901 }
5902 });
5903
5904 return columns;
5905}
5906
5907function pad(value, width) {
5908 var s = value + "", length = s.length;
5909 return length < width ? new Array(width - length + 1).join(0) + s : s;
5910}
5911
5912function formatYear(year) {
5913 return year < 0 ? "-" + pad(-year, 6)
5914 : year > 9999 ? "+" + pad(year, 6)
5915 : pad(year, 4);
5916}
5917
5918function formatDate(date) {
5919 var hours = date.getUTCHours(),
5920 minutes = date.getUTCMinutes(),
5921 seconds = date.getUTCSeconds(),
5922 milliseconds = date.getUTCMilliseconds();
5923 return isNaN(date) ? "Invalid Date"
5924 : formatYear(date.getUTCFullYear()) + "-" + pad(date.getUTCMonth() + 1, 2) + "-" + pad(date.getUTCDate(), 2)
5925 + (milliseconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "." + pad(milliseconds, 3) + "Z"
5926 : seconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "Z"
5927 : minutes || hours ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + "Z"
5928 : "");
5929}
5930
5931function dsvFormat(delimiter) {
5932 var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
5933 DELIMITER = delimiter.charCodeAt(0);
5934
5935 function parse(text, f) {
5936 var convert, columns, rows = parseRows(text, function(row, i) {
5937 if (convert) return convert(row, i - 1);
5938 columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
5939 });
5940 rows.columns = columns || [];
5941 return rows;
5942 }
5943
5944 function parseRows(text, f) {
5945 var rows = [], // output rows
5946 N = text.length,
5947 I = 0, // current character index
5948 n = 0, // current line number
5949 t, // current token
5950 eof = N <= 0, // current token followed by EOF?
5951 eol = false; // current token followed by EOL?
5952
5953 // Strip the trailing newline.
5954 if (text.charCodeAt(N - 1) === NEWLINE) --N;
5955 if (text.charCodeAt(N - 1) === RETURN) --N;
5956
5957 function token() {
5958 if (eof) return EOF;
5959 if (eol) return eol = false, EOL;
5960
5961 // Unescape quotes.
5962 var i, j = I, c;
5963 if (text.charCodeAt(j) === QUOTE) {
5964 while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
5965 if ((i = I) >= N) eof = true;
5966 else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
5967 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5968 return text.slice(j + 1, i - 1).replace(/""/g, "\"");
5969 }
5970
5971 // Find next delimiter or newline.
5972 while (I < N) {
5973 if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
5974 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5975 else if (c !== DELIMITER) continue;
5976 return text.slice(j, i);
5977 }
5978
5979 // Return last token before EOF.
5980 return eof = true, text.slice(j, N);
5981 }
5982
5983 while ((t = token()) !== EOF) {
5984 var row = [];
5985 while (t !== EOL && t !== EOF) row.push(t), t = token();
5986 if (f && (row = f(row, n++)) == null) continue;
5987 rows.push(row);
5988 }
5989
5990 return rows;
5991 }
5992
5993 function preformatBody(rows, columns) {
5994 return rows.map(function(row) {
5995 return columns.map(function(column) {
5996 return formatValue(row[column]);
5997 }).join(delimiter);
5998 });
5999 }
6000
6001 function format(rows, columns) {
6002 if (columns == null) columns = inferColumns(rows);
6003 return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
6004 }
6005
6006 function formatBody(rows, columns) {
6007 if (columns == null) columns = inferColumns(rows);
6008 return preformatBody(rows, columns).join("\n");
6009 }
6010
6011 function formatRows(rows) {
6012 return rows.map(formatRow).join("\n");
6013 }
6014
6015 function formatRow(row) {
6016 return row.map(formatValue).join(delimiter);
6017 }
6018
6019 function formatValue(value) {
6020 return value == null ? ""
6021 : value instanceof Date ? formatDate(value)
6022 : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
6023 : value;
6024 }
6025
6026 return {
6027 parse: parse,
6028 parseRows: parseRows,
6029 format: format,
6030 formatBody: formatBody,
6031 formatRows: formatRows,
6032 formatRow: formatRow,
6033 formatValue: formatValue
6034 };
6035}
6036
6037var csv = dsvFormat(",");
6038
6039var csvParse = csv.parse;
6040var csvParseRows = csv.parseRows;
6041var csvFormat = csv.format;
6042var csvFormatBody = csv.formatBody;
6043var csvFormatRows = csv.formatRows;
6044var csvFormatRow = csv.formatRow;
6045var csvFormatValue = csv.formatValue;
6046
6047var tsv = dsvFormat("\t");
6048
6049var tsvParse = tsv.parse;
6050var tsvParseRows = tsv.parseRows;
6051var tsvFormat = tsv.format;
6052var tsvFormatBody = tsv.formatBody;
6053var tsvFormatRows = tsv.formatRows;
6054var tsvFormatRow = tsv.formatRow;
6055var tsvFormatValue = tsv.formatValue;
6056
6057function autoType(object) {
6058 for (var key in object) {
6059 var value = object[key].trim(), number, m;
6060 if (!value) value = null;
6061 else if (value === "true") value = true;
6062 else if (value === "false") value = false;
6063 else if (value === "NaN") value = NaN;
6064 else if (!isNaN(number = +value)) value = number;
6065 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})?)?$/)) {
6066 if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
6067 value = new Date(value);
6068 }
6069 else continue;
6070 object[key] = value;
6071 }
6072 return object;
6073}
6074
6075// https://github.com/d3/d3-dsv/issues/45
6076var fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
6077
6078function responseBlob(response) {
6079 if (!response.ok) throw new Error(response.status + " " + response.statusText);
6080 return response.blob();
6081}
6082
6083function blob(input, init) {
6084 return fetch(input, init).then(responseBlob);
6085}
6086
6087function responseArrayBuffer(response) {
6088 if (!response.ok) throw new Error(response.status + " " + response.statusText);
6089 return response.arrayBuffer();
6090}
6091
6092function buffer(input, init) {
6093 return fetch(input, init).then(responseArrayBuffer);
6094}
6095
6096function responseText(response) {
6097 if (!response.ok) throw new Error(response.status + " " + response.statusText);
6098 return response.text();
6099}
6100
6101function text(input, init) {
6102 return fetch(input, init).then(responseText);
6103}
6104
6105function dsvParse(parse) {
6106 return function(input, init, row) {
6107 if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
6108 return text(input, init).then(function(response) {
6109 return parse(response, row);
6110 });
6111 };
6112}
6113
6114function dsv(delimiter, input, init, row) {
6115 if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
6116 var format = dsvFormat(delimiter);
6117 return text(input, init).then(function(response) {
6118 return format.parse(response, row);
6119 });
6120}
6121
6122var csv$1 = dsvParse(csvParse);
6123var tsv$1 = dsvParse(tsvParse);
6124
6125function image(input, init) {
6126 return new Promise(function(resolve, reject) {
6127 var image = new Image;
6128 for (var key in init) image[key] = init[key];
6129 image.onerror = reject;
6130 image.onload = function() { resolve(image); };
6131 image.src = input;
6132 });
6133}
6134
6135function responseJson(response) {
6136 if (!response.ok) throw new Error(response.status + " " + response.statusText);
6137 return response.json();
6138}
6139
6140function json(input, init) {
6141 return fetch(input, init).then(responseJson);
6142}
6143
6144function parser(type) {
6145 return function(input, init) {
6146 return text(input, init).then(function(text) {
6147 return (new DOMParser).parseFromString(text, type);
6148 });
6149 };
6150}
6151
6152var xml = parser("application/xml");
6153
6154var html = parser("text/html");
6155
6156var svg = parser("image/svg+xml");
6157
6158function center$1(x, y) {
6159 var nodes;
6160
6161 if (x == null) x = 0;
6162 if (y == null) y = 0;
6163
6164 function force() {
6165 var i,
6166 n = nodes.length,
6167 node,
6168 sx = 0,
6169 sy = 0;
6170
6171 for (i = 0; i < n; ++i) {
6172 node = nodes[i], sx += node.x, sy += node.y;
6173 }
6174
6175 for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
6176 node = nodes[i], node.x -= sx, node.y -= sy;
6177 }
6178 }
6179
6180 force.initialize = function(_) {
6181 nodes = _;
6182 };
6183
6184 force.x = function(_) {
6185 return arguments.length ? (x = +_, force) : x;
6186 };
6187
6188 force.y = function(_) {
6189 return arguments.length ? (y = +_, force) : y;
6190 };
6191
6192 return force;
6193}
6194
6195function constant$7(x) {
6196 return function() {
6197 return x;
6198 };
6199}
6200
6201function jiggle() {
6202 return (Math.random() - 0.5) * 1e-6;
6203}
6204
6205function tree_add(d) {
6206 var x = +this._x.call(null, d),
6207 y = +this._y.call(null, d);
6208 return add(this.cover(x, y), x, y, d);
6209}
6210
6211function add(tree, x, y, d) {
6212 if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
6213
6214 var parent,
6215 node = tree._root,
6216 leaf = {data: d},
6217 x0 = tree._x0,
6218 y0 = tree._y0,
6219 x1 = tree._x1,
6220 y1 = tree._y1,
6221 xm,
6222 ym,
6223 xp,
6224 yp,
6225 right,
6226 bottom,
6227 i,
6228 j;
6229
6230 // If the tree is empty, initialize the root as a leaf.
6231 if (!node) return tree._root = leaf, tree;
6232
6233 // Find the existing leaf for the new point, or add it.
6234 while (node.length) {
6235 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
6236 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
6237 if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
6238 }
6239
6240 // Is the new point is exactly coincident with the existing point?
6241 xp = +tree._x.call(null, node.data);
6242 yp = +tree._y.call(null, node.data);
6243 if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
6244
6245 // Otherwise, split the leaf node until the old and new point are separated.
6246 do {
6247 parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
6248 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
6249 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
6250 } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
6251 return parent[j] = node, parent[i] = leaf, tree;
6252}
6253
6254function addAll(data) {
6255 var d, i, n = data.length,
6256 x,
6257 y,
6258 xz = new Array(n),
6259 yz = new Array(n),
6260 x0 = Infinity,
6261 y0 = Infinity,
6262 x1 = -Infinity,
6263 y1 = -Infinity;
6264
6265 // Compute the points and their extent.
6266 for (i = 0; i < n; ++i) {
6267 if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
6268 xz[i] = x;
6269 yz[i] = y;
6270 if (x < x0) x0 = x;
6271 if (x > x1) x1 = x;
6272 if (y < y0) y0 = y;
6273 if (y > y1) y1 = y;
6274 }
6275
6276 // If there were no (valid) points, abort.
6277 if (x0 > x1 || y0 > y1) return this;
6278
6279 // Expand the tree to cover the new points.
6280 this.cover(x0, y0).cover(x1, y1);
6281
6282 // Add the new points.
6283 for (i = 0; i < n; ++i) {
6284 add(this, xz[i], yz[i], data[i]);
6285 }
6286
6287 return this;
6288}
6289
6290function tree_cover(x, y) {
6291 if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
6292
6293 var x0 = this._x0,
6294 y0 = this._y0,
6295 x1 = this._x1,
6296 y1 = this._y1;
6297
6298 // If the quadtree has no extent, initialize them.
6299 // Integer extent are necessary so that if we later double the extent,
6300 // the existing quadrant boundaries don’t change due to floating point error!
6301 if (isNaN(x0)) {
6302 x1 = (x0 = Math.floor(x)) + 1;
6303 y1 = (y0 = Math.floor(y)) + 1;
6304 }
6305
6306 // Otherwise, double repeatedly to cover.
6307 else {
6308 var z = x1 - x0,
6309 node = this._root,
6310 parent,
6311 i;
6312
6313 while (x0 > x || x >= x1 || y0 > y || y >= y1) {
6314 i = (y < y0) << 1 | (x < x0);
6315 parent = new Array(4), parent[i] = node, node = parent, z *= 2;
6316 switch (i) {
6317 case 0: x1 = x0 + z, y1 = y0 + z; break;
6318 case 1: x0 = x1 - z, y1 = y0 + z; break;
6319 case 2: x1 = x0 + z, y0 = y1 - z; break;
6320 case 3: x0 = x1 - z, y0 = y1 - z; break;
6321 }
6322 }
6323
6324 if (this._root && this._root.length) this._root = node;
6325 }
6326
6327 this._x0 = x0;
6328 this._y0 = y0;
6329 this._x1 = x1;
6330 this._y1 = y1;
6331 return this;
6332}
6333
6334function tree_data() {
6335 var data = [];
6336 this.visit(function(node) {
6337 if (!node.length) do data.push(node.data); while (node = node.next)
6338 });
6339 return data;
6340}
6341
6342function tree_extent(_) {
6343 return arguments.length
6344 ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
6345 : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
6346}
6347
6348function Quad(node, x0, y0, x1, y1) {
6349 this.node = node;
6350 this.x0 = x0;
6351 this.y0 = y0;
6352 this.x1 = x1;
6353 this.y1 = y1;
6354}
6355
6356function tree_find(x, y, radius) {
6357 var data,
6358 x0 = this._x0,
6359 y0 = this._y0,
6360 x1,
6361 y1,
6362 x2,
6363 y2,
6364 x3 = this._x1,
6365 y3 = this._y1,
6366 quads = [],
6367 node = this._root,
6368 q,
6369 i;
6370
6371 if (node) quads.push(new Quad(node, x0, y0, x3, y3));
6372 if (radius == null) radius = Infinity;
6373 else {
6374 x0 = x - radius, y0 = y - radius;
6375 x3 = x + radius, y3 = y + radius;
6376 radius *= radius;
6377 }
6378
6379 while (q = quads.pop()) {
6380
6381 // Stop searching if this quadrant can’t contain a closer node.
6382 if (!(node = q.node)
6383 || (x1 = q.x0) > x3
6384 || (y1 = q.y0) > y3
6385 || (x2 = q.x1) < x0
6386 || (y2 = q.y1) < y0) continue;
6387
6388 // Bisect the current quadrant.
6389 if (node.length) {
6390 var xm = (x1 + x2) / 2,
6391 ym = (y1 + y2) / 2;
6392
6393 quads.push(
6394 new Quad(node[3], xm, ym, x2, y2),
6395 new Quad(node[2], x1, ym, xm, y2),
6396 new Quad(node[1], xm, y1, x2, ym),
6397 new Quad(node[0], x1, y1, xm, ym)
6398 );
6399
6400 // Visit the closest quadrant first.
6401 if (i = (y >= ym) << 1 | (x >= xm)) {
6402 q = quads[quads.length - 1];
6403 quads[quads.length - 1] = quads[quads.length - 1 - i];
6404 quads[quads.length - 1 - i] = q;
6405 }
6406 }
6407
6408 // Visit this point. (Visiting coincident points isn’t necessary!)
6409 else {
6410 var dx = x - +this._x.call(null, node.data),
6411 dy = y - +this._y.call(null, node.data),
6412 d2 = dx * dx + dy * dy;
6413 if (d2 < radius) {
6414 var d = Math.sqrt(radius = d2);
6415 x0 = x - d, y0 = y - d;
6416 x3 = x + d, y3 = y + d;
6417 data = node.data;
6418 }
6419 }
6420 }
6421
6422 return data;
6423}
6424
6425function tree_remove(d) {
6426 if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
6427
6428 var parent,
6429 node = this._root,
6430 retainer,
6431 previous,
6432 next,
6433 x0 = this._x0,
6434 y0 = this._y0,
6435 x1 = this._x1,
6436 y1 = this._y1,
6437 x,
6438 y,
6439 xm,
6440 ym,
6441 right,
6442 bottom,
6443 i,
6444 j;
6445
6446 // If the tree is empty, initialize the root as a leaf.
6447 if (!node) return this;
6448
6449 // Find the leaf node for the point.
6450 // While descending, also retain the deepest parent with a non-removed sibling.
6451 if (node.length) while (true) {
6452 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
6453 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
6454 if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
6455 if (!node.length) break;
6456 if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
6457 }
6458
6459 // Find the point to remove.
6460 while (node.data !== d) if (!(previous = node, node = node.next)) return this;
6461 if (next = node.next) delete node.next;
6462
6463 // If there are multiple coincident points, remove just the point.
6464 if (previous) return (next ? previous.next = next : delete previous.next), this;
6465
6466 // If this is the root point, remove it.
6467 if (!parent) return this._root = next, this;
6468
6469 // Remove this leaf.
6470 next ? parent[i] = next : delete parent[i];
6471
6472 // If the parent now contains exactly one leaf, collapse superfluous parents.
6473 if ((node = parent[0] || parent[1] || parent[2] || parent[3])
6474 && node === (parent[3] || parent[2] || parent[1] || parent[0])
6475 && !node.length) {
6476 if (retainer) retainer[j] = node;
6477 else this._root = node;
6478 }
6479
6480 return this;
6481}
6482
6483function removeAll(data) {
6484 for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
6485 return this;
6486}
6487
6488function tree_root() {
6489 return this._root;
6490}
6491
6492function tree_size() {
6493 var size = 0;
6494 this.visit(function(node) {
6495 if (!node.length) do ++size; while (node = node.next)
6496 });
6497 return size;
6498}
6499
6500function tree_visit(callback) {
6501 var quads = [], q, node = this._root, child, x0, y0, x1, y1;
6502 if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
6503 while (q = quads.pop()) {
6504 if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
6505 var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
6506 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
6507 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
6508 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
6509 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
6510 }
6511 }
6512 return this;
6513}
6514
6515function tree_visitAfter(callback) {
6516 var quads = [], next = [], q;
6517 if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
6518 while (q = quads.pop()) {
6519 var node = q.node;
6520 if (node.length) {
6521 var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
6522 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
6523 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
6524 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
6525 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
6526 }
6527 next.push(q);
6528 }
6529 while (q = next.pop()) {
6530 callback(q.node, q.x0, q.y0, q.x1, q.y1);
6531 }
6532 return this;
6533}
6534
6535function defaultX$1(d) {
6536 return d[0];
6537}
6538
6539function tree_x(_) {
6540 return arguments.length ? (this._x = _, this) : this._x;
6541}
6542
6543function defaultY$1(d) {
6544 return d[1];
6545}
6546
6547function tree_y(_) {
6548 return arguments.length ? (this._y = _, this) : this._y;
6549}
6550
6551function quadtree(nodes, x, y) {
6552 var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
6553 return nodes == null ? tree : tree.addAll(nodes);
6554}
6555
6556function Quadtree(x, y, x0, y0, x1, y1) {
6557 this._x = x;
6558 this._y = y;
6559 this._x0 = x0;
6560 this._y0 = y0;
6561 this._x1 = x1;
6562 this._y1 = y1;
6563 this._root = undefined;
6564}
6565
6566function leaf_copy(leaf) {
6567 var copy = {data: leaf.data}, next = copy;
6568 while (leaf = leaf.next) next = next.next = {data: leaf.data};
6569 return copy;
6570}
6571
6572var treeProto = quadtree.prototype = Quadtree.prototype;
6573
6574treeProto.copy = function() {
6575 var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
6576 node = this._root,
6577 nodes,
6578 child;
6579
6580 if (!node) return copy;
6581
6582 if (!node.length) return copy._root = leaf_copy(node), copy;
6583
6584 nodes = [{source: node, target: copy._root = new Array(4)}];
6585 while (node = nodes.pop()) {
6586 for (var i = 0; i < 4; ++i) {
6587 if (child = node.source[i]) {
6588 if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
6589 else node.target[i] = leaf_copy(child);
6590 }
6591 }
6592 }
6593
6594 return copy;
6595};
6596
6597treeProto.add = tree_add;
6598treeProto.addAll = addAll;
6599treeProto.cover = tree_cover;
6600treeProto.data = tree_data;
6601treeProto.extent = tree_extent;
6602treeProto.find = tree_find;
6603treeProto.remove = tree_remove;
6604treeProto.removeAll = removeAll;
6605treeProto.root = tree_root;
6606treeProto.size = tree_size;
6607treeProto.visit = tree_visit;
6608treeProto.visitAfter = tree_visitAfter;
6609treeProto.x = tree_x;
6610treeProto.y = tree_y;
6611
6612function x(d) {
6613 return d.x + d.vx;
6614}
6615
6616function y(d) {
6617 return d.y + d.vy;
6618}
6619
6620function collide(radius) {
6621 var nodes,
6622 radii,
6623 strength = 1,
6624 iterations = 1;
6625
6626 if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
6627
6628 function force() {
6629 var i, n = nodes.length,
6630 tree,
6631 node,
6632 xi,
6633 yi,
6634 ri,
6635 ri2;
6636
6637 for (var k = 0; k < iterations; ++k) {
6638 tree = quadtree(nodes, x, y).visitAfter(prepare);
6639 for (i = 0; i < n; ++i) {
6640 node = nodes[i];
6641 ri = radii[node.index], ri2 = ri * ri;
6642 xi = node.x + node.vx;
6643 yi = node.y + node.vy;
6644 tree.visit(apply);
6645 }
6646 }
6647
6648 function apply(quad, x0, y0, x1, y1) {
6649 var data = quad.data, rj = quad.r, r = ri + rj;
6650 if (data) {
6651 if (data.index > node.index) {
6652 var x = xi - data.x - data.vx,
6653 y = yi - data.y - data.vy,
6654 l = x * x + y * y;
6655 if (l < r * r) {
6656 if (x === 0) x = jiggle(), l += x * x;
6657 if (y === 0) y = jiggle(), l += y * y;
6658 l = (r - (l = Math.sqrt(l))) / l * strength;
6659 node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
6660 node.vy += (y *= l) * r;
6661 data.vx -= x * (r = 1 - r);
6662 data.vy -= y * r;
6663 }
6664 }
6665 return;
6666 }
6667 return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
6668 }
6669 }
6670
6671 function prepare(quad) {
6672 if (quad.data) return quad.r = radii[quad.data.index];
6673 for (var i = quad.r = 0; i < 4; ++i) {
6674 if (quad[i] && quad[i].r > quad.r) {
6675 quad.r = quad[i].r;
6676 }
6677 }
6678 }
6679
6680 function initialize() {
6681 if (!nodes) return;
6682 var i, n = nodes.length, node;
6683 radii = new Array(n);
6684 for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
6685 }
6686
6687 force.initialize = function(_) {
6688 nodes = _;
6689 initialize();
6690 };
6691
6692 force.iterations = function(_) {
6693 return arguments.length ? (iterations = +_, force) : iterations;
6694 };
6695
6696 force.strength = function(_) {
6697 return arguments.length ? (strength = +_, force) : strength;
6698 };
6699
6700 force.radius = function(_) {
6701 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
6702 };
6703
6704 return force;
6705}
6706
6707function index(d) {
6708 return d.index;
6709}
6710
6711function find(nodeById, nodeId) {
6712 var node = nodeById.get(nodeId);
6713 if (!node) throw new Error("missing: " + nodeId);
6714 return node;
6715}
6716
6717function link(links) {
6718 var id = index,
6719 strength = defaultStrength,
6720 strengths,
6721 distance = constant$7(30),
6722 distances,
6723 nodes,
6724 count,
6725 bias,
6726 iterations = 1;
6727
6728 if (links == null) links = [];
6729
6730 function defaultStrength(link) {
6731 return 1 / Math.min(count[link.source.index], count[link.target.index]);
6732 }
6733
6734 function force(alpha) {
6735 for (var k = 0, n = links.length; k < iterations; ++k) {
6736 for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
6737 link = links[i], source = link.source, target = link.target;
6738 x = target.x + target.vx - source.x - source.vx || jiggle();
6739 y = target.y + target.vy - source.y - source.vy || jiggle();
6740 l = Math.sqrt(x * x + y * y);
6741 l = (l - distances[i]) / l * alpha * strengths[i];
6742 x *= l, y *= l;
6743 target.vx -= x * (b = bias[i]);
6744 target.vy -= y * b;
6745 source.vx += x * (b = 1 - b);
6746 source.vy += y * b;
6747 }
6748 }
6749 }
6750
6751 function initialize() {
6752 if (!nodes) return;
6753
6754 var i,
6755 n = nodes.length,
6756 m = links.length,
6757 nodeById = map$1(nodes, id),
6758 link;
6759
6760 for (i = 0, count = new Array(n); i < m; ++i) {
6761 link = links[i], link.index = i;
6762 if (typeof link.source !== "object") link.source = find(nodeById, link.source);
6763 if (typeof link.target !== "object") link.target = find(nodeById, link.target);
6764 count[link.source.index] = (count[link.source.index] || 0) + 1;
6765 count[link.target.index] = (count[link.target.index] || 0) + 1;
6766 }
6767
6768 for (i = 0, bias = new Array(m); i < m; ++i) {
6769 link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
6770 }
6771
6772 strengths = new Array(m), initializeStrength();
6773 distances = new Array(m), initializeDistance();
6774 }
6775
6776 function initializeStrength() {
6777 if (!nodes) return;
6778
6779 for (var i = 0, n = links.length; i < n; ++i) {
6780 strengths[i] = +strength(links[i], i, links);
6781 }
6782 }
6783
6784 function initializeDistance() {
6785 if (!nodes) return;
6786
6787 for (var i = 0, n = links.length; i < n; ++i) {
6788 distances[i] = +distance(links[i], i, links);
6789 }
6790 }
6791
6792 force.initialize = function(_) {
6793 nodes = _;
6794 initialize();
6795 };
6796
6797 force.links = function(_) {
6798 return arguments.length ? (links = _, initialize(), force) : links;
6799 };
6800
6801 force.id = function(_) {
6802 return arguments.length ? (id = _, force) : id;
6803 };
6804
6805 force.iterations = function(_) {
6806 return arguments.length ? (iterations = +_, force) : iterations;
6807 };
6808
6809 force.strength = function(_) {
6810 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
6811 };
6812
6813 force.distance = function(_) {
6814 return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
6815 };
6816
6817 return force;
6818}
6819
6820function x$1(d) {
6821 return d.x;
6822}
6823
6824function y$1(d) {
6825 return d.y;
6826}
6827
6828var initialRadius = 10,
6829 initialAngle = Math.PI * (3 - Math.sqrt(5));
6830
6831function simulation(nodes) {
6832 var simulation,
6833 alpha = 1,
6834 alphaMin = 0.001,
6835 alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
6836 alphaTarget = 0,
6837 velocityDecay = 0.6,
6838 forces = map$1(),
6839 stepper = timer(step),
6840 event = dispatch("tick", "end");
6841
6842 if (nodes == null) nodes = [];
6843
6844 function step() {
6845 tick();
6846 event.call("tick", simulation);
6847 if (alpha < alphaMin) {
6848 stepper.stop();
6849 event.call("end", simulation);
6850 }
6851 }
6852
6853 function tick(iterations) {
6854 var i, n = nodes.length, node;
6855
6856 if (iterations === undefined) iterations = 1;
6857
6858 for (var k = 0; k < iterations; ++k) {
6859 alpha += (alphaTarget - alpha) * alphaDecay;
6860
6861 forces.each(function (force) {
6862 force(alpha);
6863 });
6864
6865 for (i = 0; i < n; ++i) {
6866 node = nodes[i];
6867 if (node.fx == null) node.x += node.vx *= velocityDecay;
6868 else node.x = node.fx, node.vx = 0;
6869 if (node.fy == null) node.y += node.vy *= velocityDecay;
6870 else node.y = node.fy, node.vy = 0;
6871 }
6872 }
6873
6874 return simulation;
6875 }
6876
6877 function initializeNodes() {
6878 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6879 node = nodes[i], node.index = i;
6880 if (node.fx != null) node.x = node.fx;
6881 if (node.fy != null) node.y = node.fy;
6882 if (isNaN(node.x) || isNaN(node.y)) {
6883 var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
6884 node.x = radius * Math.cos(angle);
6885 node.y = radius * Math.sin(angle);
6886 }
6887 if (isNaN(node.vx) || isNaN(node.vy)) {
6888 node.vx = node.vy = 0;
6889 }
6890 }
6891 }
6892
6893 function initializeForce(force) {
6894 if (force.initialize) force.initialize(nodes);
6895 return force;
6896 }
6897
6898 initializeNodes();
6899
6900 return simulation = {
6901 tick: tick,
6902
6903 restart: function() {
6904 return stepper.restart(step), simulation;
6905 },
6906
6907 stop: function() {
6908 return stepper.stop(), simulation;
6909 },
6910
6911 nodes: function(_) {
6912 return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
6913 },
6914
6915 alpha: function(_) {
6916 return arguments.length ? (alpha = +_, simulation) : alpha;
6917 },
6918
6919 alphaMin: function(_) {
6920 return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
6921 },
6922
6923 alphaDecay: function(_) {
6924 return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
6925 },
6926
6927 alphaTarget: function(_) {
6928 return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
6929 },
6930
6931 velocityDecay: function(_) {
6932 return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
6933 },
6934
6935 force: function(name, _) {
6936 return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
6937 },
6938
6939 find: function(x, y, radius) {
6940 var i = 0,
6941 n = nodes.length,
6942 dx,
6943 dy,
6944 d2,
6945 node,
6946 closest;
6947
6948 if (radius == null) radius = Infinity;
6949 else radius *= radius;
6950
6951 for (i = 0; i < n; ++i) {
6952 node = nodes[i];
6953 dx = x - node.x;
6954 dy = y - node.y;
6955 d2 = dx * dx + dy * dy;
6956 if (d2 < radius) closest = node, radius = d2;
6957 }
6958
6959 return closest;
6960 },
6961
6962 on: function(name, _) {
6963 return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
6964 }
6965 };
6966}
6967
6968function manyBody() {
6969 var nodes,
6970 node,
6971 alpha,
6972 strength = constant$7(-30),
6973 strengths,
6974 distanceMin2 = 1,
6975 distanceMax2 = Infinity,
6976 theta2 = 0.81;
6977
6978 function force(_) {
6979 var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
6980 for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
6981 }
6982
6983 function initialize() {
6984 if (!nodes) return;
6985 var i, n = nodes.length, node;
6986 strengths = new Array(n);
6987 for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
6988 }
6989
6990 function accumulate(quad) {
6991 var strength = 0, q, c, weight = 0, x, y, i;
6992
6993 // For internal nodes, accumulate forces from child quadrants.
6994 if (quad.length) {
6995 for (x = y = i = 0; i < 4; ++i) {
6996 if ((q = quad[i]) && (c = Math.abs(q.value))) {
6997 strength += q.value, weight += c, x += c * q.x, y += c * q.y;
6998 }
6999 }
7000 quad.x = x / weight;
7001 quad.y = y / weight;
7002 }
7003
7004 // For leaf nodes, accumulate forces from coincident quadrants.
7005 else {
7006 q = quad;
7007 q.x = q.data.x;
7008 q.y = q.data.y;
7009 do strength += strengths[q.data.index];
7010 while (q = q.next);
7011 }
7012
7013 quad.value = strength;
7014 }
7015
7016 function apply(quad, x1, _, x2) {
7017 if (!quad.value) return true;
7018
7019 var x = quad.x - node.x,
7020 y = quad.y - node.y,
7021 w = x2 - x1,
7022 l = x * x + y * y;
7023
7024 // Apply the Barnes-Hut approximation if possible.
7025 // Limit forces for very close nodes; randomize direction if coincident.
7026 if (w * w / theta2 < l) {
7027 if (l < distanceMax2) {
7028 if (x === 0) x = jiggle(), l += x * x;
7029 if (y === 0) y = jiggle(), l += y * y;
7030 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
7031 node.vx += x * quad.value * alpha / l;
7032 node.vy += y * quad.value * alpha / l;
7033 }
7034 return true;
7035 }
7036
7037 // Otherwise, process points directly.
7038 else if (quad.length || l >= distanceMax2) return;
7039
7040 // Limit forces for very close nodes; randomize direction if coincident.
7041 if (quad.data !== node || quad.next) {
7042 if (x === 0) x = jiggle(), l += x * x;
7043 if (y === 0) y = jiggle(), l += y * y;
7044 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
7045 }
7046
7047 do if (quad.data !== node) {
7048 w = strengths[quad.data.index] * alpha / l;
7049 node.vx += x * w;
7050 node.vy += y * w;
7051 } while (quad = quad.next);
7052 }
7053
7054 force.initialize = function(_) {
7055 nodes = _;
7056 initialize();
7057 };
7058
7059 force.strength = function(_) {
7060 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
7061 };
7062
7063 force.distanceMin = function(_) {
7064 return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
7065 };
7066
7067 force.distanceMax = function(_) {
7068 return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
7069 };
7070
7071 force.theta = function(_) {
7072 return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
7073 };
7074
7075 return force;
7076}
7077
7078function radial(radius, x, y) {
7079 var nodes,
7080 strength = constant$7(0.1),
7081 strengths,
7082 radiuses;
7083
7084 if (typeof radius !== "function") radius = constant$7(+radius);
7085 if (x == null) x = 0;
7086 if (y == null) y = 0;
7087
7088 function force(alpha) {
7089 for (var i = 0, n = nodes.length; i < n; ++i) {
7090 var node = nodes[i],
7091 dx = node.x - x || 1e-6,
7092 dy = node.y - y || 1e-6,
7093 r = Math.sqrt(dx * dx + dy * dy),
7094 k = (radiuses[i] - r) * strengths[i] * alpha / r;
7095 node.vx += dx * k;
7096 node.vy += dy * k;
7097 }
7098 }
7099
7100 function initialize() {
7101 if (!nodes) return;
7102 var i, n = nodes.length;
7103 strengths = new Array(n);
7104 radiuses = new Array(n);
7105 for (i = 0; i < n; ++i) {
7106 radiuses[i] = +radius(nodes[i], i, nodes);
7107 strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
7108 }
7109 }
7110
7111 force.initialize = function(_) {
7112 nodes = _, initialize();
7113 };
7114
7115 force.strength = function(_) {
7116 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
7117 };
7118
7119 force.radius = function(_) {
7120 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
7121 };
7122
7123 force.x = function(_) {
7124 return arguments.length ? (x = +_, force) : x;
7125 };
7126
7127 force.y = function(_) {
7128 return arguments.length ? (y = +_, force) : y;
7129 };
7130
7131 return force;
7132}
7133
7134function x$2(x) {
7135 var strength = constant$7(0.1),
7136 nodes,
7137 strengths,
7138 xz;
7139
7140 if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
7141
7142 function force(alpha) {
7143 for (var i = 0, n = nodes.length, node; i < n; ++i) {
7144 node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
7145 }
7146 }
7147
7148 function initialize() {
7149 if (!nodes) return;
7150 var i, n = nodes.length;
7151 strengths = new Array(n);
7152 xz = new Array(n);
7153 for (i = 0; i < n; ++i) {
7154 strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
7155 }
7156 }
7157
7158 force.initialize = function(_) {
7159 nodes = _;
7160 initialize();
7161 };
7162
7163 force.strength = function(_) {
7164 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
7165 };
7166
7167 force.x = function(_) {
7168 return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
7169 };
7170
7171 return force;
7172}
7173
7174function y$2(y) {
7175 var strength = constant$7(0.1),
7176 nodes,
7177 strengths,
7178 yz;
7179
7180 if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
7181
7182 function force(alpha) {
7183 for (var i = 0, n = nodes.length, node; i < n; ++i) {
7184 node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
7185 }
7186 }
7187
7188 function initialize() {
7189 if (!nodes) return;
7190 var i, n = nodes.length;
7191 strengths = new Array(n);
7192 yz = new Array(n);
7193 for (i = 0; i < n; ++i) {
7194 strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
7195 }
7196 }
7197
7198 force.initialize = function(_) {
7199 nodes = _;
7200 initialize();
7201 };
7202
7203 force.strength = function(_) {
7204 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
7205 };
7206
7207 force.y = function(_) {
7208 return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
7209 };
7210
7211 return force;
7212}
7213
7214// Computes the decimal coefficient and exponent of the specified number x with
7215// significant digits p, where x is positive and p is in [1, 21] or undefined.
7216// For example, formatDecimal(1.23) returns ["123", 0].
7217function formatDecimal(x, p) {
7218 if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
7219 var i, coefficient = x.slice(0, i);
7220
7221 // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
7222 // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
7223 return [
7224 coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
7225 +x.slice(i + 1)
7226 ];
7227}
7228
7229function exponent$1(x) {
7230 return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
7231}
7232
7233function formatGroup(grouping, thousands) {
7234 return function(value, width) {
7235 var i = value.length,
7236 t = [],
7237 j = 0,
7238 g = grouping[0],
7239 length = 0;
7240
7241 while (i > 0 && g > 0) {
7242 if (length + g + 1 > width) g = Math.max(1, width - length);
7243 t.push(value.substring(i -= g, i + g));
7244 if ((length += g + 1) > width) break;
7245 g = grouping[j = (j + 1) % grouping.length];
7246 }
7247
7248 return t.reverse().join(thousands);
7249 };
7250}
7251
7252function formatNumerals(numerals) {
7253 return function(value) {
7254 return value.replace(/[0-9]/g, function(i) {
7255 return numerals[+i];
7256 });
7257 };
7258}
7259
7260// [[fill]align][sign][symbol][0][width][,][.precision][~][type]
7261var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
7262
7263function formatSpecifier(specifier) {
7264 if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
7265 var match;
7266 return new FormatSpecifier({
7267 fill: match[1],
7268 align: match[2],
7269 sign: match[3],
7270 symbol: match[4],
7271 zero: match[5],
7272 width: match[6],
7273 comma: match[7],
7274 precision: match[8] && match[8].slice(1),
7275 trim: match[9],
7276 type: match[10]
7277 });
7278}
7279
7280formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
7281
7282function FormatSpecifier(specifier) {
7283 this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
7284 this.align = specifier.align === undefined ? ">" : specifier.align + "";
7285 this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
7286 this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
7287 this.zero = !!specifier.zero;
7288 this.width = specifier.width === undefined ? undefined : +specifier.width;
7289 this.comma = !!specifier.comma;
7290 this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
7291 this.trim = !!specifier.trim;
7292 this.type = specifier.type === undefined ? "" : specifier.type + "";
7293}
7294
7295FormatSpecifier.prototype.toString = function() {
7296 return this.fill
7297 + this.align
7298 + this.sign
7299 + this.symbol
7300 + (this.zero ? "0" : "")
7301 + (this.width === undefined ? "" : Math.max(1, this.width | 0))
7302 + (this.comma ? "," : "")
7303 + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
7304 + (this.trim ? "~" : "")
7305 + this.type;
7306};
7307
7308// Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
7309function formatTrim(s) {
7310 out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
7311 switch (s[i]) {
7312 case ".": i0 = i1 = i; break;
7313 case "0": if (i0 === 0) i0 = i; i1 = i; break;
7314 default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
7315 }
7316 }
7317 return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
7318}
7319
7320var prefixExponent;
7321
7322function formatPrefixAuto(x, p) {
7323 var d = formatDecimal(x, p);
7324 if (!d) return x + "";
7325 var coefficient = d[0],
7326 exponent = d[1],
7327 i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
7328 n = coefficient.length;
7329 return i === n ? coefficient
7330 : i > n ? coefficient + new Array(i - n + 1).join("0")
7331 : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
7332 : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
7333}
7334
7335function formatRounded(x, p) {
7336 var d = formatDecimal(x, p);
7337 if (!d) return x + "";
7338 var coefficient = d[0],
7339 exponent = d[1];
7340 return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
7341 : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
7342 : coefficient + new Array(exponent - coefficient.length + 2).join("0");
7343}
7344
7345var formatTypes = {
7346 "%": function(x, p) { return (x * 100).toFixed(p); },
7347 "b": function(x) { return Math.round(x).toString(2); },
7348 "c": function(x) { return x + ""; },
7349 "d": function(x) { return Math.round(x).toString(10); },
7350 "e": function(x, p) { return x.toExponential(p); },
7351 "f": function(x, p) { return x.toFixed(p); },
7352 "g": function(x, p) { return x.toPrecision(p); },
7353 "o": function(x) { return Math.round(x).toString(8); },
7354 "p": function(x, p) { return formatRounded(x * 100, p); },
7355 "r": formatRounded,
7356 "s": formatPrefixAuto,
7357 "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
7358 "x": function(x) { return Math.round(x).toString(16); }
7359};
7360
7361function identity$3(x) {
7362 return x;
7363}
7364
7365var map$2 = Array.prototype.map,
7366 prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
7367
7368function formatLocale(locale) {
7369 var group = locale.grouping === undefined || locale.thousands === undefined ? identity$3 : formatGroup(map$2.call(locale.grouping, Number), locale.thousands + ""),
7370 currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
7371 currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
7372 decimal = locale.decimal === undefined ? "." : locale.decimal + "",
7373 numerals = locale.numerals === undefined ? identity$3 : formatNumerals(map$2.call(locale.numerals, String)),
7374 percent = locale.percent === undefined ? "%" : locale.percent + "",
7375 minus = locale.minus === undefined ? "-" : locale.minus + "",
7376 nan = locale.nan === undefined ? "NaN" : locale.nan + "";
7377
7378 function newFormat(specifier) {
7379 specifier = formatSpecifier(specifier);
7380
7381 var fill = specifier.fill,
7382 align = specifier.align,
7383 sign = specifier.sign,
7384 symbol = specifier.symbol,
7385 zero = specifier.zero,
7386 width = specifier.width,
7387 comma = specifier.comma,
7388 precision = specifier.precision,
7389 trim = specifier.trim,
7390 type = specifier.type;
7391
7392 // The "n" type is an alias for ",g".
7393 if (type === "n") comma = true, type = "g";
7394
7395 // The "" type, and any invalid type, is an alias for ".12~g".
7396 else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
7397
7398 // If zero fill is specified, padding goes after sign and before digits.
7399 if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
7400
7401 // Compute the prefix and suffix.
7402 // For SI-prefix, the suffix is lazily computed.
7403 var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
7404 suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
7405
7406 // What format function should we use?
7407 // Is this an integer type?
7408 // Can this type generate exponential notation?
7409 var formatType = formatTypes[type],
7410 maybeSuffix = /[defgprs%]/.test(type);
7411
7412 // Set the default precision if not specified,
7413 // or clamp the specified precision to the supported range.
7414 // For significant precision, it must be in [1, 21].
7415 // For fixed precision, it must be in [0, 20].
7416 precision = precision === undefined ? 6
7417 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
7418 : Math.max(0, Math.min(20, precision));
7419
7420 function format(value) {
7421 var valuePrefix = prefix,
7422 valueSuffix = suffix,
7423 i, n, c;
7424
7425 if (type === "c") {
7426 valueSuffix = formatType(value) + valueSuffix;
7427 value = "";
7428 } else {
7429 value = +value;
7430
7431 // Perform the initial formatting.
7432 var valueNegative = value < 0;
7433 value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
7434
7435 // Trim insignificant zeros.
7436 if (trim) value = formatTrim(value);
7437
7438 // If a negative value rounds to zero during formatting, treat as positive.
7439 if (valueNegative && +value === 0) valueNegative = false;
7440
7441 // Compute the prefix and suffix.
7442 valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
7443
7444 valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
7445
7446 // Break the formatted value into the integer “value” part that can be
7447 // grouped, and fractional or exponential “suffix” part that is not.
7448 if (maybeSuffix) {
7449 i = -1, n = value.length;
7450 while (++i < n) {
7451 if (c = value.charCodeAt(i), 48 > c || c > 57) {
7452 valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
7453 value = value.slice(0, i);
7454 break;
7455 }
7456 }
7457 }
7458 }
7459
7460 // If the fill character is not "0", grouping is applied before padding.
7461 if (comma && !zero) value = group(value, Infinity);
7462
7463 // Compute the padding.
7464 var length = valuePrefix.length + value.length + valueSuffix.length,
7465 padding = length < width ? new Array(width - length + 1).join(fill) : "";
7466
7467 // If the fill character is "0", grouping is applied after padding.
7468 if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
7469
7470 // Reconstruct the final output based on the desired alignment.
7471 switch (align) {
7472 case "<": value = valuePrefix + value + valueSuffix + padding; break;
7473 case "=": value = valuePrefix + padding + value + valueSuffix; break;
7474 case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
7475 default: value = padding + valuePrefix + value + valueSuffix; break;
7476 }
7477
7478 return numerals(value);
7479 }
7480
7481 format.toString = function() {
7482 return specifier + "";
7483 };
7484
7485 return format;
7486 }
7487
7488 function formatPrefix(specifier, value) {
7489 var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
7490 e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
7491 k = Math.pow(10, -e),
7492 prefix = prefixes[8 + e / 3];
7493 return function(value) {
7494 return f(k * value) + prefix;
7495 };
7496 }
7497
7498 return {
7499 format: newFormat,
7500 formatPrefix: formatPrefix
7501 };
7502}
7503
7504var locale;
7505
7506defaultLocale({
7507 decimal: ".",
7508 thousands: ",",
7509 grouping: [3],
7510 currency: ["$", ""],
7511 minus: "-"
7512});
7513
7514function defaultLocale(definition) {
7515 locale = formatLocale(definition);
7516 exports.format = locale.format;
7517 exports.formatPrefix = locale.formatPrefix;
7518 return locale;
7519}
7520
7521function precisionFixed(step) {
7522 return Math.max(0, -exponent$1(Math.abs(step)));
7523}
7524
7525function precisionPrefix(step, value) {
7526 return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
7527}
7528
7529function precisionRound(step, max) {
7530 step = Math.abs(step), max = Math.abs(max) - step;
7531 return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
7532}
7533
7534// Adds floating point numbers with twice the normal precision.
7535// Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
7536// Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
7537// 305–363 (1997).
7538// Code adapted from GeographicLib by Charles F. F. Karney,
7539// http://geographiclib.sourceforge.net/
7540
7541function adder() {
7542 return new Adder;
7543}
7544
7545function Adder() {
7546 this.reset();
7547}
7548
7549Adder.prototype = {
7550 constructor: Adder,
7551 reset: function() {
7552 this.s = // rounded value
7553 this.t = 0; // exact error
7554 },
7555 add: function(y) {
7556 add$1(temp, y, this.t);
7557 add$1(this, temp.s, this.s);
7558 if (this.s) this.t += temp.t;
7559 else this.s = temp.t;
7560 },
7561 valueOf: function() {
7562 return this.s;
7563 }
7564};
7565
7566var temp = new Adder;
7567
7568function add$1(adder, a, b) {
7569 var x = adder.s = a + b,
7570 bv = x - a,
7571 av = x - bv;
7572 adder.t = (a - av) + (b - bv);
7573}
7574
7575var epsilon$2 = 1e-6;
7576var epsilon2$1 = 1e-12;
7577var pi$3 = Math.PI;
7578var halfPi$2 = pi$3 / 2;
7579var quarterPi = pi$3 / 4;
7580var tau$3 = pi$3 * 2;
7581
7582var degrees$1 = 180 / pi$3;
7583var radians = pi$3 / 180;
7584
7585var abs = Math.abs;
7586var atan = Math.atan;
7587var atan2 = Math.atan2;
7588var cos$1 = Math.cos;
7589var ceil = Math.ceil;
7590var exp = Math.exp;
7591var log = Math.log;
7592var pow = Math.pow;
7593var sin$1 = Math.sin;
7594var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
7595var sqrt = Math.sqrt;
7596var tan = Math.tan;
7597
7598function acos(x) {
7599 return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
7600}
7601
7602function asin(x) {
7603 return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
7604}
7605
7606function haversin(x) {
7607 return (x = sin$1(x / 2)) * x;
7608}
7609
7610function noop$2() {}
7611
7612function streamGeometry(geometry, stream) {
7613 if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
7614 streamGeometryType[geometry.type](geometry, stream);
7615 }
7616}
7617
7618var streamObjectType = {
7619 Feature: function(object, stream) {
7620 streamGeometry(object.geometry, stream);
7621 },
7622 FeatureCollection: function(object, stream) {
7623 var features = object.features, i = -1, n = features.length;
7624 while (++i < n) streamGeometry(features[i].geometry, stream);
7625 }
7626};
7627
7628var streamGeometryType = {
7629 Sphere: function(object, stream) {
7630 stream.sphere();
7631 },
7632 Point: function(object, stream) {
7633 object = object.coordinates;
7634 stream.point(object[0], object[1], object[2]);
7635 },
7636 MultiPoint: function(object, stream) {
7637 var coordinates = object.coordinates, i = -1, n = coordinates.length;
7638 while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
7639 },
7640 LineString: function(object, stream) {
7641 streamLine(object.coordinates, stream, 0);
7642 },
7643 MultiLineString: function(object, stream) {
7644 var coordinates = object.coordinates, i = -1, n = coordinates.length;
7645 while (++i < n) streamLine(coordinates[i], stream, 0);
7646 },
7647 Polygon: function(object, stream) {
7648 streamPolygon(object.coordinates, stream);
7649 },
7650 MultiPolygon: function(object, stream) {
7651 var coordinates = object.coordinates, i = -1, n = coordinates.length;
7652 while (++i < n) streamPolygon(coordinates[i], stream);
7653 },
7654 GeometryCollection: function(object, stream) {
7655 var geometries = object.geometries, i = -1, n = geometries.length;
7656 while (++i < n) streamGeometry(geometries[i], stream);
7657 }
7658};
7659
7660function streamLine(coordinates, stream, closed) {
7661 var i = -1, n = coordinates.length - closed, coordinate;
7662 stream.lineStart();
7663 while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
7664 stream.lineEnd();
7665}
7666
7667function streamPolygon(coordinates, stream) {
7668 var i = -1, n = coordinates.length;
7669 stream.polygonStart();
7670 while (++i < n) streamLine(coordinates[i], stream, 1);
7671 stream.polygonEnd();
7672}
7673
7674function geoStream(object, stream) {
7675 if (object && streamObjectType.hasOwnProperty(object.type)) {
7676 streamObjectType[object.type](object, stream);
7677 } else {
7678 streamGeometry(object, stream);
7679 }
7680}
7681
7682var areaRingSum = adder();
7683
7684var areaSum = adder(),
7685 lambda00,
7686 phi00,
7687 lambda0,
7688 cosPhi0,
7689 sinPhi0;
7690
7691var areaStream = {
7692 point: noop$2,
7693 lineStart: noop$2,
7694 lineEnd: noop$2,
7695 polygonStart: function() {
7696 areaRingSum.reset();
7697 areaStream.lineStart = areaRingStart;
7698 areaStream.lineEnd = areaRingEnd;
7699 },
7700 polygonEnd: function() {
7701 var areaRing = +areaRingSum;
7702 areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
7703 this.lineStart = this.lineEnd = this.point = noop$2;
7704 },
7705 sphere: function() {
7706 areaSum.add(tau$3);
7707 }
7708};
7709
7710function areaRingStart() {
7711 areaStream.point = areaPointFirst;
7712}
7713
7714function areaRingEnd() {
7715 areaPoint(lambda00, phi00);
7716}
7717
7718function areaPointFirst(lambda, phi) {
7719 areaStream.point = areaPoint;
7720 lambda00 = lambda, phi00 = phi;
7721 lambda *= radians, phi *= radians;
7722 lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
7723}
7724
7725function areaPoint(lambda, phi) {
7726 lambda *= radians, phi *= radians;
7727 phi = phi / 2 + quarterPi; // half the angular distance from south pole
7728
7729 // Spherical excess E for a spherical triangle with vertices: south pole,
7730 // previous point, current point. Uses a formula derived from Cagnoli’s
7731 // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
7732 var dLambda = lambda - lambda0,
7733 sdLambda = dLambda >= 0 ? 1 : -1,
7734 adLambda = sdLambda * dLambda,
7735 cosPhi = cos$1(phi),
7736 sinPhi = sin$1(phi),
7737 k = sinPhi0 * sinPhi,
7738 u = cosPhi0 * cosPhi + k * cos$1(adLambda),
7739 v = k * sdLambda * sin$1(adLambda);
7740 areaRingSum.add(atan2(v, u));
7741
7742 // Advance the previous points.
7743 lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
7744}
7745
7746function area$1(object) {
7747 areaSum.reset();
7748 geoStream(object, areaStream);
7749 return areaSum * 2;
7750}
7751
7752function spherical(cartesian) {
7753 return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
7754}
7755
7756function cartesian(spherical) {
7757 var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
7758 return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
7759}
7760
7761function cartesianDot(a, b) {
7762 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
7763}
7764
7765function cartesianCross(a, b) {
7766 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]];
7767}
7768
7769// TODO return a
7770function cartesianAddInPlace(a, b) {
7771 a[0] += b[0], a[1] += b[1], a[2] += b[2];
7772}
7773
7774function cartesianScale(vector, k) {
7775 return [vector[0] * k, vector[1] * k, vector[2] * k];
7776}
7777
7778// TODO return d
7779function cartesianNormalizeInPlace(d) {
7780 var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
7781 d[0] /= l, d[1] /= l, d[2] /= l;
7782}
7783
7784var lambda0$1, phi0, lambda1, phi1, // bounds
7785 lambda2, // previous lambda-coordinate
7786 lambda00$1, phi00$1, // first point
7787 p0, // previous 3D point
7788 deltaSum = adder(),
7789 ranges,
7790 range;
7791
7792var boundsStream = {
7793 point: boundsPoint,
7794 lineStart: boundsLineStart,
7795 lineEnd: boundsLineEnd,
7796 polygonStart: function() {
7797 boundsStream.point = boundsRingPoint;
7798 boundsStream.lineStart = boundsRingStart;
7799 boundsStream.lineEnd = boundsRingEnd;
7800 deltaSum.reset();
7801 areaStream.polygonStart();
7802 },
7803 polygonEnd: function() {
7804 areaStream.polygonEnd();
7805 boundsStream.point = boundsPoint;
7806 boundsStream.lineStart = boundsLineStart;
7807 boundsStream.lineEnd = boundsLineEnd;
7808 if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
7809 else if (deltaSum > epsilon$2) phi1 = 90;
7810 else if (deltaSum < -epsilon$2) phi0 = -90;
7811 range[0] = lambda0$1, range[1] = lambda1;
7812 },
7813 sphere: function() {
7814 lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
7815 }
7816};
7817
7818function boundsPoint(lambda, phi) {
7819 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7820 if (phi < phi0) phi0 = phi;
7821 if (phi > phi1) phi1 = phi;
7822}
7823
7824function linePoint(lambda, phi) {
7825 var p = cartesian([lambda * radians, phi * radians]);
7826 if (p0) {
7827 var normal = cartesianCross(p0, p),
7828 equatorial = [normal[1], -normal[0], 0],
7829 inflection = cartesianCross(equatorial, normal);
7830 cartesianNormalizeInPlace(inflection);
7831 inflection = spherical(inflection);
7832 var delta = lambda - lambda2,
7833 sign = delta > 0 ? 1 : -1,
7834 lambdai = inflection[0] * degrees$1 * sign,
7835 phii,
7836 antimeridian = abs(delta) > 180;
7837 if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
7838 phii = inflection[1] * degrees$1;
7839 if (phii > phi1) phi1 = phii;
7840 } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
7841 phii = -inflection[1] * degrees$1;
7842 if (phii < phi0) phi0 = phii;
7843 } else {
7844 if (phi < phi0) phi0 = phi;
7845 if (phi > phi1) phi1 = phi;
7846 }
7847 if (antimeridian) {
7848 if (lambda < lambda2) {
7849 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7850 } else {
7851 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7852 }
7853 } else {
7854 if (lambda1 >= lambda0$1) {
7855 if (lambda < lambda0$1) lambda0$1 = lambda;
7856 if (lambda > lambda1) lambda1 = lambda;
7857 } else {
7858 if (lambda > lambda2) {
7859 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7860 } else {
7861 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7862 }
7863 }
7864 }
7865 } else {
7866 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7867 }
7868 if (phi < phi0) phi0 = phi;
7869 if (phi > phi1) phi1 = phi;
7870 p0 = p, lambda2 = lambda;
7871}
7872
7873function boundsLineStart() {
7874 boundsStream.point = linePoint;
7875}
7876
7877function boundsLineEnd() {
7878 range[0] = lambda0$1, range[1] = lambda1;
7879 boundsStream.point = boundsPoint;
7880 p0 = null;
7881}
7882
7883function boundsRingPoint(lambda, phi) {
7884 if (p0) {
7885 var delta = lambda - lambda2;
7886 deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
7887 } else {
7888 lambda00$1 = lambda, phi00$1 = phi;
7889 }
7890 areaStream.point(lambda, phi);
7891 linePoint(lambda, phi);
7892}
7893
7894function boundsRingStart() {
7895 areaStream.lineStart();
7896}
7897
7898function boundsRingEnd() {
7899 boundsRingPoint(lambda00$1, phi00$1);
7900 areaStream.lineEnd();
7901 if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
7902 range[0] = lambda0$1, range[1] = lambda1;
7903 p0 = null;
7904}
7905
7906// Finds the left-right distance between two longitudes.
7907// This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
7908// the distance between ±180° to be 360°.
7909function angle(lambda0, lambda1) {
7910 return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
7911}
7912
7913function rangeCompare(a, b) {
7914 return a[0] - b[0];
7915}
7916
7917function rangeContains(range, x) {
7918 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
7919}
7920
7921function bounds(feature) {
7922 var i, n, a, b, merged, deltaMax, delta;
7923
7924 phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
7925 ranges = [];
7926 geoStream(feature, boundsStream);
7927
7928 // First, sort ranges by their minimum longitudes.
7929 if (n = ranges.length) {
7930 ranges.sort(rangeCompare);
7931
7932 // Then, merge any ranges that overlap.
7933 for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
7934 b = ranges[i];
7935 if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
7936 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
7937 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
7938 } else {
7939 merged.push(a = b);
7940 }
7941 }
7942
7943 // Finally, find the largest gap between the merged ranges.
7944 // The final bounding box will be the inverse of this gap.
7945 for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
7946 b = merged[i];
7947 if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
7948 }
7949 }
7950
7951 ranges = range = null;
7952
7953 return lambda0$1 === Infinity || phi0 === Infinity
7954 ? [[NaN, NaN], [NaN, NaN]]
7955 : [[lambda0$1, phi0], [lambda1, phi1]];
7956}
7957
7958var W0, W1,
7959 X0, Y0, Z0,
7960 X1, Y1, Z1,
7961 X2, Y2, Z2,
7962 lambda00$2, phi00$2, // first point
7963 x0, y0, z0; // previous point
7964
7965var centroidStream = {
7966 sphere: noop$2,
7967 point: centroidPoint,
7968 lineStart: centroidLineStart,
7969 lineEnd: centroidLineEnd,
7970 polygonStart: function() {
7971 centroidStream.lineStart = centroidRingStart;
7972 centroidStream.lineEnd = centroidRingEnd;
7973 },
7974 polygonEnd: function() {
7975 centroidStream.lineStart = centroidLineStart;
7976 centroidStream.lineEnd = centroidLineEnd;
7977 }
7978};
7979
7980// Arithmetic mean of Cartesian vectors.
7981function centroidPoint(lambda, phi) {
7982 lambda *= radians, phi *= radians;
7983 var cosPhi = cos$1(phi);
7984 centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
7985}
7986
7987function centroidPointCartesian(x, y, z) {
7988 ++W0;
7989 X0 += (x - X0) / W0;
7990 Y0 += (y - Y0) / W0;
7991 Z0 += (z - Z0) / W0;
7992}
7993
7994function centroidLineStart() {
7995 centroidStream.point = centroidLinePointFirst;
7996}
7997
7998function centroidLinePointFirst(lambda, phi) {
7999 lambda *= radians, phi *= radians;
8000 var cosPhi = cos$1(phi);
8001 x0 = cosPhi * cos$1(lambda);
8002 y0 = cosPhi * sin$1(lambda);
8003 z0 = sin$1(phi);
8004 centroidStream.point = centroidLinePoint;
8005 centroidPointCartesian(x0, y0, z0);
8006}
8007
8008function centroidLinePoint(lambda, phi) {
8009 lambda *= radians, phi *= radians;
8010 var cosPhi = cos$1(phi),
8011 x = cosPhi * cos$1(lambda),
8012 y = cosPhi * sin$1(lambda),
8013 z = sin$1(phi),
8014 w = atan2(sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
8015 W1 += w;
8016 X1 += w * (x0 + (x0 = x));
8017 Y1 += w * (y0 + (y0 = y));
8018 Z1 += w * (z0 + (z0 = z));
8019 centroidPointCartesian(x0, y0, z0);
8020}
8021
8022function centroidLineEnd() {
8023 centroidStream.point = centroidPoint;
8024}
8025
8026// See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
8027// J. Applied Mechanics 42, 239 (1975).
8028function centroidRingStart() {
8029 centroidStream.point = centroidRingPointFirst;
8030}
8031
8032function centroidRingEnd() {
8033 centroidRingPoint(lambda00$2, phi00$2);
8034 centroidStream.point = centroidPoint;
8035}
8036
8037function centroidRingPointFirst(lambda, phi) {
8038 lambda00$2 = lambda, phi00$2 = phi;
8039 lambda *= radians, phi *= radians;
8040 centroidStream.point = centroidRingPoint;
8041 var cosPhi = cos$1(phi);
8042 x0 = cosPhi * cos$1(lambda);
8043 y0 = cosPhi * sin$1(lambda);
8044 z0 = sin$1(phi);
8045 centroidPointCartesian(x0, y0, z0);
8046}
8047
8048function centroidRingPoint(lambda, phi) {
8049 lambda *= radians, phi *= radians;
8050 var cosPhi = cos$1(phi),
8051 x = cosPhi * cos$1(lambda),
8052 y = cosPhi * sin$1(lambda),
8053 z = sin$1(phi),
8054 cx = y0 * z - z0 * y,
8055 cy = z0 * x - x0 * z,
8056 cz = x0 * y - y0 * x,
8057 m = sqrt(cx * cx + cy * cy + cz * cz),
8058 w = asin(m), // line weight = angle
8059 v = m && -w / m; // area weight multiplier
8060 X2 += v * cx;
8061 Y2 += v * cy;
8062 Z2 += v * cz;
8063 W1 += w;
8064 X1 += w * (x0 + (x0 = x));
8065 Y1 += w * (y0 + (y0 = y));
8066 Z1 += w * (z0 + (z0 = z));
8067 centroidPointCartesian(x0, y0, z0);
8068}
8069
8070function centroid(object) {
8071 W0 = W1 =
8072 X0 = Y0 = Z0 =
8073 X1 = Y1 = Z1 =
8074 X2 = Y2 = Z2 = 0;
8075 geoStream(object, centroidStream);
8076
8077 var x = X2,
8078 y = Y2,
8079 z = Z2,
8080 m = x * x + y * y + z * z;
8081
8082 // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
8083 if (m < epsilon2$1) {
8084 x = X1, y = Y1, z = Z1;
8085 // If the feature has zero length, fall back to arithmetic mean of point vectors.
8086 if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
8087 m = x * x + y * y + z * z;
8088 // If the feature still has an undefined ccentroid, then return.
8089 if (m < epsilon2$1) return [NaN, NaN];
8090 }
8091
8092 return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
8093}
8094
8095function constant$8(x) {
8096 return function() {
8097 return x;
8098 };
8099}
8100
8101function compose(a, b) {
8102
8103 function compose(x, y) {
8104 return x = a(x, y), b(x[0], x[1]);
8105 }
8106
8107 if (a.invert && b.invert) compose.invert = function(x, y) {
8108 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
8109 };
8110
8111 return compose;
8112}
8113
8114function rotationIdentity(lambda, phi) {
8115 return [abs(lambda) > pi$3 ? lambda + Math.round(-lambda / tau$3) * tau$3 : lambda, phi];
8116}
8117
8118rotationIdentity.invert = rotationIdentity;
8119
8120function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
8121 return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
8122 : rotationLambda(deltaLambda))
8123 : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
8124 : rotationIdentity);
8125}
8126
8127function forwardRotationLambda(deltaLambda) {
8128 return function(lambda, phi) {
8129 return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
8130 };
8131}
8132
8133function rotationLambda(deltaLambda) {
8134 var rotation = forwardRotationLambda(deltaLambda);
8135 rotation.invert = forwardRotationLambda(-deltaLambda);
8136 return rotation;
8137}
8138
8139function rotationPhiGamma(deltaPhi, deltaGamma) {
8140 var cosDeltaPhi = cos$1(deltaPhi),
8141 sinDeltaPhi = sin$1(deltaPhi),
8142 cosDeltaGamma = cos$1(deltaGamma),
8143 sinDeltaGamma = sin$1(deltaGamma);
8144
8145 function rotation(lambda, phi) {
8146 var cosPhi = cos$1(phi),
8147 x = cos$1(lambda) * cosPhi,
8148 y = sin$1(lambda) * cosPhi,
8149 z = sin$1(phi),
8150 k = z * cosDeltaPhi + x * sinDeltaPhi;
8151 return [
8152 atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
8153 asin(k * cosDeltaGamma + y * sinDeltaGamma)
8154 ];
8155 }
8156
8157 rotation.invert = function(lambda, phi) {
8158 var cosPhi = cos$1(phi),
8159 x = cos$1(lambda) * cosPhi,
8160 y = sin$1(lambda) * cosPhi,
8161 z = sin$1(phi),
8162 k = z * cosDeltaGamma - y * sinDeltaGamma;
8163 return [
8164 atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
8165 asin(k * cosDeltaPhi - x * sinDeltaPhi)
8166 ];
8167 };
8168
8169 return rotation;
8170}
8171
8172function rotation(rotate) {
8173 rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
8174
8175 function forward(coordinates) {
8176 coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
8177 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
8178 }
8179
8180 forward.invert = function(coordinates) {
8181 coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
8182 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
8183 };
8184
8185 return forward;
8186}
8187
8188// Generates a circle centered at [0°, 0°], with a given radius and precision.
8189function circleStream(stream, radius, delta, direction, t0, t1) {
8190 if (!delta) return;
8191 var cosRadius = cos$1(radius),
8192 sinRadius = sin$1(radius),
8193 step = direction * delta;
8194 if (t0 == null) {
8195 t0 = radius + direction * tau$3;
8196 t1 = radius - step / 2;
8197 } else {
8198 t0 = circleRadius(cosRadius, t0);
8199 t1 = circleRadius(cosRadius, t1);
8200 if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
8201 }
8202 for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
8203 point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
8204 stream.point(point[0], point[1]);
8205 }
8206}
8207
8208// Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
8209function circleRadius(cosRadius, point) {
8210 point = cartesian(point), point[0] -= cosRadius;
8211 cartesianNormalizeInPlace(point);
8212 var radius = acos(-point[1]);
8213 return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
8214}
8215
8216function circle() {
8217 var center = constant$8([0, 0]),
8218 radius = constant$8(90),
8219 precision = constant$8(6),
8220 ring,
8221 rotate,
8222 stream = {point: point};
8223
8224 function point(x, y) {
8225 ring.push(x = rotate(x, y));
8226 x[0] *= degrees$1, x[1] *= degrees$1;
8227 }
8228
8229 function circle() {
8230 var c = center.apply(this, arguments),
8231 r = radius.apply(this, arguments) * radians,
8232 p = precision.apply(this, arguments) * radians;
8233 ring = [];
8234 rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
8235 circleStream(stream, r, p, 1);
8236 c = {type: "Polygon", coordinates: [ring]};
8237 ring = rotate = null;
8238 return c;
8239 }
8240
8241 circle.center = function(_) {
8242 return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
8243 };
8244
8245 circle.radius = function(_) {
8246 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
8247 };
8248
8249 circle.precision = function(_) {
8250 return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
8251 };
8252
8253 return circle;
8254}
8255
8256function clipBuffer() {
8257 var lines = [],
8258 line;
8259 return {
8260 point: function(x, y) {
8261 line.push([x, y]);
8262 },
8263 lineStart: function() {
8264 lines.push(line = []);
8265 },
8266 lineEnd: noop$2,
8267 rejoin: function() {
8268 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
8269 },
8270 result: function() {
8271 var result = lines;
8272 lines = [];
8273 line = null;
8274 return result;
8275 }
8276 };
8277}
8278
8279function pointEqual(a, b) {
8280 return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
8281}
8282
8283function Intersection(point, points, other, entry) {
8284 this.x = point;
8285 this.z = points;
8286 this.o = other; // another intersection
8287 this.e = entry; // is an entry?
8288 this.v = false; // visited
8289 this.n = this.p = null; // next & previous
8290}
8291
8292// A generalized polygon clipping algorithm: given a polygon that has been cut
8293// into its visible line segments, and rejoins the segments by interpolating
8294// along the clip edge.
8295function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
8296 var subject = [],
8297 clip = [],
8298 i,
8299 n;
8300
8301 segments.forEach(function(segment) {
8302 if ((n = segment.length - 1) <= 0) return;
8303 var n, p0 = segment[0], p1 = segment[n], x;
8304
8305 // If the first and last points of a segment are coincident, then treat as a
8306 // closed ring. TODO if all rings are closed, then the winding order of the
8307 // exterior ring should be checked.
8308 if (pointEqual(p0, p1)) {
8309 stream.lineStart();
8310 for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
8311 stream.lineEnd();
8312 return;
8313 }
8314
8315 subject.push(x = new Intersection(p0, segment, null, true));
8316 clip.push(x.o = new Intersection(p0, null, x, false));
8317 subject.push(x = new Intersection(p1, segment, null, false));
8318 clip.push(x.o = new Intersection(p1, null, x, true));
8319 });
8320
8321 if (!subject.length) return;
8322
8323 clip.sort(compareIntersection);
8324 link$1(subject);
8325 link$1(clip);
8326
8327 for (i = 0, n = clip.length; i < n; ++i) {
8328 clip[i].e = startInside = !startInside;
8329 }
8330
8331 var start = subject[0],
8332 points,
8333 point;
8334
8335 while (1) {
8336 // Find first unvisited intersection.
8337 var current = start,
8338 isSubject = true;
8339 while (current.v) if ((current = current.n) === start) return;
8340 points = current.z;
8341 stream.lineStart();
8342 do {
8343 current.v = current.o.v = true;
8344 if (current.e) {
8345 if (isSubject) {
8346 for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
8347 } else {
8348 interpolate(current.x, current.n.x, 1, stream);
8349 }
8350 current = current.n;
8351 } else {
8352 if (isSubject) {
8353 points = current.p.z;
8354 for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
8355 } else {
8356 interpolate(current.x, current.p.x, -1, stream);
8357 }
8358 current = current.p;
8359 }
8360 current = current.o;
8361 points = current.z;
8362 isSubject = !isSubject;
8363 } while (!current.v);
8364 stream.lineEnd();
8365 }
8366}
8367
8368function link$1(array) {
8369 if (!(n = array.length)) return;
8370 var n,
8371 i = 0,
8372 a = array[0],
8373 b;
8374 while (++i < n) {
8375 a.n = b = array[i];
8376 b.p = a;
8377 a = b;
8378 }
8379 a.n = b = array[0];
8380 b.p = a;
8381}
8382
8383var sum$1 = adder();
8384
8385function longitude(point) {
8386 if (abs(point[0]) <= pi$3)
8387 return point[0];
8388 else
8389 return sign(point[0]) * ((abs(point[0]) + pi$3) % tau$3 - pi$3);
8390}
8391
8392function polygonContains(polygon, point) {
8393 var lambda = longitude(point),
8394 phi = point[1],
8395 sinPhi = sin$1(phi),
8396 normal = [sin$1(lambda), -cos$1(lambda), 0],
8397 angle = 0,
8398 winding = 0;
8399
8400 sum$1.reset();
8401
8402 if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
8403 else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
8404
8405 for (var i = 0, n = polygon.length; i < n; ++i) {
8406 if (!(m = (ring = polygon[i]).length)) continue;
8407 var ring,
8408 m,
8409 point0 = ring[m - 1],
8410 lambda0 = longitude(point0),
8411 phi0 = point0[1] / 2 + quarterPi,
8412 sinPhi0 = sin$1(phi0),
8413 cosPhi0 = cos$1(phi0);
8414
8415 for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
8416 var point1 = ring[j],
8417 lambda1 = longitude(point1),
8418 phi1 = point1[1] / 2 + quarterPi,
8419 sinPhi1 = sin$1(phi1),
8420 cosPhi1 = cos$1(phi1),
8421 delta = lambda1 - lambda0,
8422 sign = delta >= 0 ? 1 : -1,
8423 absDelta = sign * delta,
8424 antimeridian = absDelta > pi$3,
8425 k = sinPhi0 * sinPhi1;
8426
8427 sum$1.add(atan2(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
8428 angle += antimeridian ? delta + sign * tau$3 : delta;
8429
8430 // Are the longitudes either side of the point’s meridian (lambda),
8431 // and are the latitudes smaller than the parallel (phi)?
8432 if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
8433 var arc = cartesianCross(cartesian(point0), cartesian(point1));
8434 cartesianNormalizeInPlace(arc);
8435 var intersection = cartesianCross(normal, arc);
8436 cartesianNormalizeInPlace(intersection);
8437 var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
8438 if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
8439 winding += antimeridian ^ delta >= 0 ? 1 : -1;
8440 }
8441 }
8442 }
8443 }
8444
8445 // First, determine whether the South pole is inside or outside:
8446 //
8447 // It is inside if:
8448 // * the polygon winds around it in a clockwise direction.
8449 // * the polygon does not (cumulatively) wind around it, but has a negative
8450 // (counter-clockwise) area.
8451 //
8452 // Second, count the (signed) number of times a segment crosses a lambda
8453 // from the point to the South pole. If it is zero, then the point is the
8454 // same side as the South pole.
8455
8456 return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
8457}
8458
8459function clip(pointVisible, clipLine, interpolate, start) {
8460 return function(sink) {
8461 var line = clipLine(sink),
8462 ringBuffer = clipBuffer(),
8463 ringSink = clipLine(ringBuffer),
8464 polygonStarted = false,
8465 polygon,
8466 segments,
8467 ring;
8468
8469 var clip = {
8470 point: point,
8471 lineStart: lineStart,
8472 lineEnd: lineEnd,
8473 polygonStart: function() {
8474 clip.point = pointRing;
8475 clip.lineStart = ringStart;
8476 clip.lineEnd = ringEnd;
8477 segments = [];
8478 polygon = [];
8479 },
8480 polygonEnd: function() {
8481 clip.point = point;
8482 clip.lineStart = lineStart;
8483 clip.lineEnd = lineEnd;
8484 segments = merge(segments);
8485 var startInside = polygonContains(polygon, start);
8486 if (segments.length) {
8487 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8488 clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
8489 } else if (startInside) {
8490 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8491 sink.lineStart();
8492 interpolate(null, null, 1, sink);
8493 sink.lineEnd();
8494 }
8495 if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
8496 segments = polygon = null;
8497 },
8498 sphere: function() {
8499 sink.polygonStart();
8500 sink.lineStart();
8501 interpolate(null, null, 1, sink);
8502 sink.lineEnd();
8503 sink.polygonEnd();
8504 }
8505 };
8506
8507 function point(lambda, phi) {
8508 if (pointVisible(lambda, phi)) sink.point(lambda, phi);
8509 }
8510
8511 function pointLine(lambda, phi) {
8512 line.point(lambda, phi);
8513 }
8514
8515 function lineStart() {
8516 clip.point = pointLine;
8517 line.lineStart();
8518 }
8519
8520 function lineEnd() {
8521 clip.point = point;
8522 line.lineEnd();
8523 }
8524
8525 function pointRing(lambda, phi) {
8526 ring.push([lambda, phi]);
8527 ringSink.point(lambda, phi);
8528 }
8529
8530 function ringStart() {
8531 ringSink.lineStart();
8532 ring = [];
8533 }
8534
8535 function ringEnd() {
8536 pointRing(ring[0][0], ring[0][1]);
8537 ringSink.lineEnd();
8538
8539 var clean = ringSink.clean(),
8540 ringSegments = ringBuffer.result(),
8541 i, n = ringSegments.length, m,
8542 segment,
8543 point;
8544
8545 ring.pop();
8546 polygon.push(ring);
8547 ring = null;
8548
8549 if (!n) return;
8550
8551 // No intersections.
8552 if (clean & 1) {
8553 segment = ringSegments[0];
8554 if ((m = segment.length - 1) > 0) {
8555 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8556 sink.lineStart();
8557 for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
8558 sink.lineEnd();
8559 }
8560 return;
8561 }
8562
8563 // Rejoin connected segments.
8564 // TODO reuse ringBuffer.rejoin()?
8565 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
8566
8567 segments.push(ringSegments.filter(validSegment));
8568 }
8569
8570 return clip;
8571 };
8572}
8573
8574function validSegment(segment) {
8575 return segment.length > 1;
8576}
8577
8578// Intersections are sorted along the clip edge. For both antimeridian cutting
8579// and circle clipping, the same comparison is used.
8580function compareIntersection(a, b) {
8581 return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
8582 - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
8583}
8584
8585var clipAntimeridian = clip(
8586 function() { return true; },
8587 clipAntimeridianLine,
8588 clipAntimeridianInterpolate,
8589 [-pi$3, -halfPi$2]
8590);
8591
8592// Takes a line and cuts into visible segments. Return values: 0 - there were
8593// intersections or the line was empty; 1 - no intersections; 2 - there were
8594// intersections, and the first and last segments should be rejoined.
8595function clipAntimeridianLine(stream) {
8596 var lambda0 = NaN,
8597 phi0 = NaN,
8598 sign0 = NaN,
8599 clean; // no intersections
8600
8601 return {
8602 lineStart: function() {
8603 stream.lineStart();
8604 clean = 1;
8605 },
8606 point: function(lambda1, phi1) {
8607 var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
8608 delta = abs(lambda1 - lambda0);
8609 if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
8610 stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
8611 stream.point(sign0, phi0);
8612 stream.lineEnd();
8613 stream.lineStart();
8614 stream.point(sign1, phi0);
8615 stream.point(lambda1, phi0);
8616 clean = 0;
8617 } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
8618 if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
8619 if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
8620 phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
8621 stream.point(sign0, phi0);
8622 stream.lineEnd();
8623 stream.lineStart();
8624 stream.point(sign1, phi0);
8625 clean = 0;
8626 }
8627 stream.point(lambda0 = lambda1, phi0 = phi1);
8628 sign0 = sign1;
8629 },
8630 lineEnd: function() {
8631 stream.lineEnd();
8632 lambda0 = phi0 = NaN;
8633 },
8634 clean: function() {
8635 return 2 - clean; // if intersections, rejoin first and last segments
8636 }
8637 };
8638}
8639
8640function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
8641 var cosPhi0,
8642 cosPhi1,
8643 sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
8644 return abs(sinLambda0Lambda1) > epsilon$2
8645 ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
8646 - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
8647 / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
8648 : (phi0 + phi1) / 2;
8649}
8650
8651function clipAntimeridianInterpolate(from, to, direction, stream) {
8652 var phi;
8653 if (from == null) {
8654 phi = direction * halfPi$2;
8655 stream.point(-pi$3, phi);
8656 stream.point(0, phi);
8657 stream.point(pi$3, phi);
8658 stream.point(pi$3, 0);
8659 stream.point(pi$3, -phi);
8660 stream.point(0, -phi);
8661 stream.point(-pi$3, -phi);
8662 stream.point(-pi$3, 0);
8663 stream.point(-pi$3, phi);
8664 } else if (abs(from[0] - to[0]) > epsilon$2) {
8665 var lambda = from[0] < to[0] ? pi$3 : -pi$3;
8666 phi = direction * lambda / 2;
8667 stream.point(-lambda, phi);
8668 stream.point(0, phi);
8669 stream.point(lambda, phi);
8670 } else {
8671 stream.point(to[0], to[1]);
8672 }
8673}
8674
8675function clipCircle(radius) {
8676 var cr = cos$1(radius),
8677 delta = 6 * radians,
8678 smallRadius = cr > 0,
8679 notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
8680
8681 function interpolate(from, to, direction, stream) {
8682 circleStream(stream, radius, delta, direction, from, to);
8683 }
8684
8685 function visible(lambda, phi) {
8686 return cos$1(lambda) * cos$1(phi) > cr;
8687 }
8688
8689 // Takes a line and cuts into visible segments. Return values used for polygon
8690 // clipping: 0 - there were intersections or the line was empty; 1 - no
8691 // intersections 2 - there were intersections, and the first and last segments
8692 // should be rejoined.
8693 function clipLine(stream) {
8694 var point0, // previous point
8695 c0, // code for previous point
8696 v0, // visibility of previous point
8697 v00, // visibility of first point
8698 clean; // no intersections
8699 return {
8700 lineStart: function() {
8701 v00 = v0 = false;
8702 clean = 1;
8703 },
8704 point: function(lambda, phi) {
8705 var point1 = [lambda, phi],
8706 point2,
8707 v = visible(lambda, phi),
8708 c = smallRadius
8709 ? v ? 0 : code(lambda, phi)
8710 : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
8711 if (!point0 && (v00 = v0 = v)) stream.lineStart();
8712 // Handle degeneracies.
8713 // TODO ignore if not clipping polygons.
8714 if (v !== v0) {
8715 point2 = intersect(point0, point1);
8716 if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
8717 point1[0] += epsilon$2;
8718 point1[1] += epsilon$2;
8719 v = visible(point1[0], point1[1]);
8720 }
8721 }
8722 if (v !== v0) {
8723 clean = 0;
8724 if (v) {
8725 // outside going in
8726 stream.lineStart();
8727 point2 = intersect(point1, point0);
8728 stream.point(point2[0], point2[1]);
8729 } else {
8730 // inside going out
8731 point2 = intersect(point0, point1);
8732 stream.point(point2[0], point2[1]);
8733 stream.lineEnd();
8734 }
8735 point0 = point2;
8736 } else if (notHemisphere && point0 && smallRadius ^ v) {
8737 var t;
8738 // If the codes for two points are different, or are both zero,
8739 // and there this segment intersects with the small circle.
8740 if (!(c & c0) && (t = intersect(point1, point0, true))) {
8741 clean = 0;
8742 if (smallRadius) {
8743 stream.lineStart();
8744 stream.point(t[0][0], t[0][1]);
8745 stream.point(t[1][0], t[1][1]);
8746 stream.lineEnd();
8747 } else {
8748 stream.point(t[1][0], t[1][1]);
8749 stream.lineEnd();
8750 stream.lineStart();
8751 stream.point(t[0][0], t[0][1]);
8752 }
8753 }
8754 }
8755 if (v && (!point0 || !pointEqual(point0, point1))) {
8756 stream.point(point1[0], point1[1]);
8757 }
8758 point0 = point1, v0 = v, c0 = c;
8759 },
8760 lineEnd: function() {
8761 if (v0) stream.lineEnd();
8762 point0 = null;
8763 },
8764 // Rejoin first and last segments if there were intersections and the first
8765 // and last points were visible.
8766 clean: function() {
8767 return clean | ((v00 && v0) << 1);
8768 }
8769 };
8770 }
8771
8772 // Intersects the great circle between a and b with the clip circle.
8773 function intersect(a, b, two) {
8774 var pa = cartesian(a),
8775 pb = cartesian(b);
8776
8777 // We have two planes, n1.p = d1 and n2.p = d2.
8778 // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
8779 var n1 = [1, 0, 0], // normal
8780 n2 = cartesianCross(pa, pb),
8781 n2n2 = cartesianDot(n2, n2),
8782 n1n2 = n2[0], // cartesianDot(n1, n2),
8783 determinant = n2n2 - n1n2 * n1n2;
8784
8785 // Two polar points.
8786 if (!determinant) return !two && a;
8787
8788 var c1 = cr * n2n2 / determinant,
8789 c2 = -cr * n1n2 / determinant,
8790 n1xn2 = cartesianCross(n1, n2),
8791 A = cartesianScale(n1, c1),
8792 B = cartesianScale(n2, c2);
8793 cartesianAddInPlace(A, B);
8794
8795 // Solve |p(t)|^2 = 1.
8796 var u = n1xn2,
8797 w = cartesianDot(A, u),
8798 uu = cartesianDot(u, u),
8799 t2 = w * w - uu * (cartesianDot(A, A) - 1);
8800
8801 if (t2 < 0) return;
8802
8803 var t = sqrt(t2),
8804 q = cartesianScale(u, (-w - t) / uu);
8805 cartesianAddInPlace(q, A);
8806 q = spherical(q);
8807
8808 if (!two) return q;
8809
8810 // Two intersection points.
8811 var lambda0 = a[0],
8812 lambda1 = b[0],
8813 phi0 = a[1],
8814 phi1 = b[1],
8815 z;
8816
8817 if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
8818
8819 var delta = lambda1 - lambda0,
8820 polar = abs(delta - pi$3) < epsilon$2,
8821 meridian = polar || delta < epsilon$2;
8822
8823 if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
8824
8825 // Check that the first point is between a and b.
8826 if (meridian
8827 ? polar
8828 ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
8829 : phi0 <= q[1] && q[1] <= phi1
8830 : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
8831 var q1 = cartesianScale(u, (-w + t) / uu);
8832 cartesianAddInPlace(q1, A);
8833 return [q, spherical(q1)];
8834 }
8835 }
8836
8837 // Generates a 4-bit vector representing the location of a point relative to
8838 // the small circle's bounding box.
8839 function code(lambda, phi) {
8840 var r = smallRadius ? radius : pi$3 - radius,
8841 code = 0;
8842 if (lambda < -r) code |= 1; // left
8843 else if (lambda > r) code |= 2; // right
8844 if (phi < -r) code |= 4; // below
8845 else if (phi > r) code |= 8; // above
8846 return code;
8847 }
8848
8849 return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
8850}
8851
8852function clipLine(a, b, x0, y0, x1, y1) {
8853 var ax = a[0],
8854 ay = a[1],
8855 bx = b[0],
8856 by = b[1],
8857 t0 = 0,
8858 t1 = 1,
8859 dx = bx - ax,
8860 dy = by - ay,
8861 r;
8862
8863 r = x0 - ax;
8864 if (!dx && r > 0) return;
8865 r /= dx;
8866 if (dx < 0) {
8867 if (r < t0) return;
8868 if (r < t1) t1 = r;
8869 } else if (dx > 0) {
8870 if (r > t1) return;
8871 if (r > t0) t0 = r;
8872 }
8873
8874 r = x1 - ax;
8875 if (!dx && r < 0) return;
8876 r /= dx;
8877 if (dx < 0) {
8878 if (r > t1) return;
8879 if (r > t0) t0 = r;
8880 } else if (dx > 0) {
8881 if (r < t0) return;
8882 if (r < t1) t1 = r;
8883 }
8884
8885 r = y0 - ay;
8886 if (!dy && r > 0) return;
8887 r /= dy;
8888 if (dy < 0) {
8889 if (r < t0) return;
8890 if (r < t1) t1 = r;
8891 } else if (dy > 0) {
8892 if (r > t1) return;
8893 if (r > t0) t0 = r;
8894 }
8895
8896 r = y1 - ay;
8897 if (!dy && r < 0) return;
8898 r /= dy;
8899 if (dy < 0) {
8900 if (r > t1) return;
8901 if (r > t0) t0 = r;
8902 } else if (dy > 0) {
8903 if (r < t0) return;
8904 if (r < t1) t1 = r;
8905 }
8906
8907 if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
8908 if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
8909 return true;
8910}
8911
8912var clipMax = 1e9, clipMin = -clipMax;
8913
8914// TODO Use d3-polygon’s polygonContains here for the ring check?
8915// TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
8916
8917function clipRectangle(x0, y0, x1, y1) {
8918
8919 function visible(x, y) {
8920 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
8921 }
8922
8923 function interpolate(from, to, direction, stream) {
8924 var a = 0, a1 = 0;
8925 if (from == null
8926 || (a = corner(from, direction)) !== (a1 = corner(to, direction))
8927 || comparePoint(from, to) < 0 ^ direction > 0) {
8928 do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
8929 while ((a = (a + direction + 4) % 4) !== a1);
8930 } else {
8931 stream.point(to[0], to[1]);
8932 }
8933 }
8934
8935 function corner(p, direction) {
8936 return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
8937 : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
8938 : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
8939 : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
8940 }
8941
8942 function compareIntersection(a, b) {
8943 return comparePoint(a.x, b.x);
8944 }
8945
8946 function comparePoint(a, b) {
8947 var ca = corner(a, 1),
8948 cb = corner(b, 1);
8949 return ca !== cb ? ca - cb
8950 : ca === 0 ? b[1] - a[1]
8951 : ca === 1 ? a[0] - b[0]
8952 : ca === 2 ? a[1] - b[1]
8953 : b[0] - a[0];
8954 }
8955
8956 return function(stream) {
8957 var activeStream = stream,
8958 bufferStream = clipBuffer(),
8959 segments,
8960 polygon,
8961 ring,
8962 x__, y__, v__, // first point
8963 x_, y_, v_, // previous point
8964 first,
8965 clean;
8966
8967 var clipStream = {
8968 point: point,
8969 lineStart: lineStart,
8970 lineEnd: lineEnd,
8971 polygonStart: polygonStart,
8972 polygonEnd: polygonEnd
8973 };
8974
8975 function point(x, y) {
8976 if (visible(x, y)) activeStream.point(x, y);
8977 }
8978
8979 function polygonInside() {
8980 var winding = 0;
8981
8982 for (var i = 0, n = polygon.length; i < n; ++i) {
8983 for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
8984 a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
8985 if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
8986 else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
8987 }
8988 }
8989
8990 return winding;
8991 }
8992
8993 // Buffer geometry within a polygon and then clip it en masse.
8994 function polygonStart() {
8995 activeStream = bufferStream, segments = [], polygon = [], clean = true;
8996 }
8997
8998 function polygonEnd() {
8999 var startInside = polygonInside(),
9000 cleanInside = clean && startInside,
9001 visible = (segments = merge(segments)).length;
9002 if (cleanInside || visible) {
9003 stream.polygonStart();
9004 if (cleanInside) {
9005 stream.lineStart();
9006 interpolate(null, null, 1, stream);
9007 stream.lineEnd();
9008 }
9009 if (visible) {
9010 clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
9011 }
9012 stream.polygonEnd();
9013 }
9014 activeStream = stream, segments = polygon = ring = null;
9015 }
9016
9017 function lineStart() {
9018 clipStream.point = linePoint;
9019 if (polygon) polygon.push(ring = []);
9020 first = true;
9021 v_ = false;
9022 x_ = y_ = NaN;
9023 }
9024
9025 // TODO rather than special-case polygons, simply handle them separately.
9026 // Ideally, coincident intersection points should be jittered to avoid
9027 // clipping issues.
9028 function lineEnd() {
9029 if (segments) {
9030 linePoint(x__, y__);
9031 if (v__ && v_) bufferStream.rejoin();
9032 segments.push(bufferStream.result());
9033 }
9034 clipStream.point = point;
9035 if (v_) activeStream.lineEnd();
9036 }
9037
9038 function linePoint(x, y) {
9039 var v = visible(x, y);
9040 if (polygon) ring.push([x, y]);
9041 if (first) {
9042 x__ = x, y__ = y, v__ = v;
9043 first = false;
9044 if (v) {
9045 activeStream.lineStart();
9046 activeStream.point(x, y);
9047 }
9048 } else {
9049 if (v && v_) activeStream.point(x, y);
9050 else {
9051 var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
9052 b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
9053 if (clipLine(a, b, x0, y0, x1, y1)) {
9054 if (!v_) {
9055 activeStream.lineStart();
9056 activeStream.point(a[0], a[1]);
9057 }
9058 activeStream.point(b[0], b[1]);
9059 if (!v) activeStream.lineEnd();
9060 clean = false;
9061 } else if (v) {
9062 activeStream.lineStart();
9063 activeStream.point(x, y);
9064 clean = false;
9065 }
9066 }
9067 }
9068 x_ = x, y_ = y, v_ = v;
9069 }
9070
9071 return clipStream;
9072 };
9073}
9074
9075function extent$1() {
9076 var x0 = 0,
9077 y0 = 0,
9078 x1 = 960,
9079 y1 = 500,
9080 cache,
9081 cacheStream,
9082 clip;
9083
9084 return clip = {
9085 stream: function(stream) {
9086 return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
9087 },
9088 extent: function(_) {
9089 return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
9090 }
9091 };
9092}
9093
9094var lengthSum = adder(),
9095 lambda0$2,
9096 sinPhi0$1,
9097 cosPhi0$1;
9098
9099var lengthStream = {
9100 sphere: noop$2,
9101 point: noop$2,
9102 lineStart: lengthLineStart,
9103 lineEnd: noop$2,
9104 polygonStart: noop$2,
9105 polygonEnd: noop$2
9106};
9107
9108function lengthLineStart() {
9109 lengthStream.point = lengthPointFirst;
9110 lengthStream.lineEnd = lengthLineEnd;
9111}
9112
9113function lengthLineEnd() {
9114 lengthStream.point = lengthStream.lineEnd = noop$2;
9115}
9116
9117function lengthPointFirst(lambda, phi) {
9118 lambda *= radians, phi *= radians;
9119 lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
9120 lengthStream.point = lengthPoint;
9121}
9122
9123function lengthPoint(lambda, phi) {
9124 lambda *= radians, phi *= radians;
9125 var sinPhi = sin$1(phi),
9126 cosPhi = cos$1(phi),
9127 delta = abs(lambda - lambda0$2),
9128 cosDelta = cos$1(delta),
9129 sinDelta = sin$1(delta),
9130 x = cosPhi * sinDelta,
9131 y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
9132 z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
9133 lengthSum.add(atan2(sqrt(x * x + y * y), z));
9134 lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
9135}
9136
9137function length$1(object) {
9138 lengthSum.reset();
9139 geoStream(object, lengthStream);
9140 return +lengthSum;
9141}
9142
9143var coordinates = [null, null],
9144 object$1 = {type: "LineString", coordinates: coordinates};
9145
9146function distance(a, b) {
9147 coordinates[0] = a;
9148 coordinates[1] = b;
9149 return length$1(object$1);
9150}
9151
9152var containsObjectType = {
9153 Feature: function(object, point) {
9154 return containsGeometry(object.geometry, point);
9155 },
9156 FeatureCollection: function(object, point) {
9157 var features = object.features, i = -1, n = features.length;
9158 while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
9159 return false;
9160 }
9161};
9162
9163var containsGeometryType = {
9164 Sphere: function() {
9165 return true;
9166 },
9167 Point: function(object, point) {
9168 return containsPoint(object.coordinates, point);
9169 },
9170 MultiPoint: function(object, point) {
9171 var coordinates = object.coordinates, i = -1, n = coordinates.length;
9172 while (++i < n) if (containsPoint(coordinates[i], point)) return true;
9173 return false;
9174 },
9175 LineString: function(object, point) {
9176 return containsLine(object.coordinates, point);
9177 },
9178 MultiLineString: function(object, point) {
9179 var coordinates = object.coordinates, i = -1, n = coordinates.length;
9180 while (++i < n) if (containsLine(coordinates[i], point)) return true;
9181 return false;
9182 },
9183 Polygon: function(object, point) {
9184 return containsPolygon(object.coordinates, point);
9185 },
9186 MultiPolygon: function(object, point) {
9187 var coordinates = object.coordinates, i = -1, n = coordinates.length;
9188 while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
9189 return false;
9190 },
9191 GeometryCollection: function(object, point) {
9192 var geometries = object.geometries, i = -1, n = geometries.length;
9193 while (++i < n) if (containsGeometry(geometries[i], point)) return true;
9194 return false;
9195 }
9196};
9197
9198function containsGeometry(geometry, point) {
9199 return geometry && containsGeometryType.hasOwnProperty(geometry.type)
9200 ? containsGeometryType[geometry.type](geometry, point)
9201 : false;
9202}
9203
9204function containsPoint(coordinates, point) {
9205 return distance(coordinates, point) === 0;
9206}
9207
9208function containsLine(coordinates, point) {
9209 var ao, bo, ab;
9210 for (var i = 0, n = coordinates.length; i < n; i++) {
9211 bo = distance(coordinates[i], point);
9212 if (bo === 0) return true;
9213 if (i > 0) {
9214 ab = distance(coordinates[i], coordinates[i - 1]);
9215 if (
9216 ab > 0 &&
9217 ao <= ab &&
9218 bo <= ab &&
9219 (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2$1 * ab
9220 )
9221 return true;
9222 }
9223 ao = bo;
9224 }
9225 return false;
9226}
9227
9228function containsPolygon(coordinates, point) {
9229 return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
9230}
9231
9232function ringRadians(ring) {
9233 return ring = ring.map(pointRadians), ring.pop(), ring;
9234}
9235
9236function pointRadians(point) {
9237 return [point[0] * radians, point[1] * radians];
9238}
9239
9240function contains$1(object, point) {
9241 return (object && containsObjectType.hasOwnProperty(object.type)
9242 ? containsObjectType[object.type]
9243 : containsGeometry)(object, point);
9244}
9245
9246function graticuleX(y0, y1, dy) {
9247 var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
9248 return function(x) { return y.map(function(y) { return [x, y]; }); };
9249}
9250
9251function graticuleY(x0, x1, dx) {
9252 var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
9253 return function(y) { return x.map(function(x) { return [x, y]; }); };
9254}
9255
9256function graticule() {
9257 var x1, x0, X1, X0,
9258 y1, y0, Y1, Y0,
9259 dx = 10, dy = dx, DX = 90, DY = 360,
9260 x, y, X, Y,
9261 precision = 2.5;
9262
9263 function graticule() {
9264 return {type: "MultiLineString", coordinates: lines()};
9265 }
9266
9267 function lines() {
9268 return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
9269 .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
9270 .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
9271 .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
9272 }
9273
9274 graticule.lines = function() {
9275 return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
9276 };
9277
9278 graticule.outline = function() {
9279 return {
9280 type: "Polygon",
9281 coordinates: [
9282 X(X0).concat(
9283 Y(Y1).slice(1),
9284 X(X1).reverse().slice(1),
9285 Y(Y0).reverse().slice(1))
9286 ]
9287 };
9288 };
9289
9290 graticule.extent = function(_) {
9291 if (!arguments.length) return graticule.extentMinor();
9292 return graticule.extentMajor(_).extentMinor(_);
9293 };
9294
9295 graticule.extentMajor = function(_) {
9296 if (!arguments.length) return [[X0, Y0], [X1, Y1]];
9297 X0 = +_[0][0], X1 = +_[1][0];
9298 Y0 = +_[0][1], Y1 = +_[1][1];
9299 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
9300 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
9301 return graticule.precision(precision);
9302 };
9303
9304 graticule.extentMinor = function(_) {
9305 if (!arguments.length) return [[x0, y0], [x1, y1]];
9306 x0 = +_[0][0], x1 = +_[1][0];
9307 y0 = +_[0][1], y1 = +_[1][1];
9308 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
9309 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
9310 return graticule.precision(precision);
9311 };
9312
9313 graticule.step = function(_) {
9314 if (!arguments.length) return graticule.stepMinor();
9315 return graticule.stepMajor(_).stepMinor(_);
9316 };
9317
9318 graticule.stepMajor = function(_) {
9319 if (!arguments.length) return [DX, DY];
9320 DX = +_[0], DY = +_[1];
9321 return graticule;
9322 };
9323
9324 graticule.stepMinor = function(_) {
9325 if (!arguments.length) return [dx, dy];
9326 dx = +_[0], dy = +_[1];
9327 return graticule;
9328 };
9329
9330 graticule.precision = function(_) {
9331 if (!arguments.length) return precision;
9332 precision = +_;
9333 x = graticuleX(y0, y1, 90);
9334 y = graticuleY(x0, x1, precision);
9335 X = graticuleX(Y0, Y1, 90);
9336 Y = graticuleY(X0, X1, precision);
9337 return graticule;
9338 };
9339
9340 return graticule
9341 .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
9342 .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
9343}
9344
9345function graticule10() {
9346 return graticule()();
9347}
9348
9349function interpolate$1(a, b) {
9350 var x0 = a[0] * radians,
9351 y0 = a[1] * radians,
9352 x1 = b[0] * radians,
9353 y1 = b[1] * radians,
9354 cy0 = cos$1(y0),
9355 sy0 = sin$1(y0),
9356 cy1 = cos$1(y1),
9357 sy1 = sin$1(y1),
9358 kx0 = cy0 * cos$1(x0),
9359 ky0 = cy0 * sin$1(x0),
9360 kx1 = cy1 * cos$1(x1),
9361 ky1 = cy1 * sin$1(x1),
9362 d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
9363 k = sin$1(d);
9364
9365 var interpolate = d ? function(t) {
9366 var B = sin$1(t *= d) / k,
9367 A = sin$1(d - t) / k,
9368 x = A * kx0 + B * kx1,
9369 y = A * ky0 + B * ky1,
9370 z = A * sy0 + B * sy1;
9371 return [
9372 atan2(y, x) * degrees$1,
9373 atan2(z, sqrt(x * x + y * y)) * degrees$1
9374 ];
9375 } : function() {
9376 return [x0 * degrees$1, y0 * degrees$1];
9377 };
9378
9379 interpolate.distance = d;
9380
9381 return interpolate;
9382}
9383
9384function identity$4(x) {
9385 return x;
9386}
9387
9388var areaSum$1 = adder(),
9389 areaRingSum$1 = adder(),
9390 x00,
9391 y00,
9392 x0$1,
9393 y0$1;
9394
9395var areaStream$1 = {
9396 point: noop$2,
9397 lineStart: noop$2,
9398 lineEnd: noop$2,
9399 polygonStart: function() {
9400 areaStream$1.lineStart = areaRingStart$1;
9401 areaStream$1.lineEnd = areaRingEnd$1;
9402 },
9403 polygonEnd: function() {
9404 areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
9405 areaSum$1.add(abs(areaRingSum$1));
9406 areaRingSum$1.reset();
9407 },
9408 result: function() {
9409 var area = areaSum$1 / 2;
9410 areaSum$1.reset();
9411 return area;
9412 }
9413};
9414
9415function areaRingStart$1() {
9416 areaStream$1.point = areaPointFirst$1;
9417}
9418
9419function areaPointFirst$1(x, y) {
9420 areaStream$1.point = areaPoint$1;
9421 x00 = x0$1 = x, y00 = y0$1 = y;
9422}
9423
9424function areaPoint$1(x, y) {
9425 areaRingSum$1.add(y0$1 * x - x0$1 * y);
9426 x0$1 = x, y0$1 = y;
9427}
9428
9429function areaRingEnd$1() {
9430 areaPoint$1(x00, y00);
9431}
9432
9433var x0$2 = Infinity,
9434 y0$2 = x0$2,
9435 x1 = -x0$2,
9436 y1 = x1;
9437
9438var boundsStream$1 = {
9439 point: boundsPoint$1,
9440 lineStart: noop$2,
9441 lineEnd: noop$2,
9442 polygonStart: noop$2,
9443 polygonEnd: noop$2,
9444 result: function() {
9445 var bounds = [[x0$2, y0$2], [x1, y1]];
9446 x1 = y1 = -(y0$2 = x0$2 = Infinity);
9447 return bounds;
9448 }
9449};
9450
9451function boundsPoint$1(x, y) {
9452 if (x < x0$2) x0$2 = x;
9453 if (x > x1) x1 = x;
9454 if (y < y0$2) y0$2 = y;
9455 if (y > y1) y1 = y;
9456}
9457
9458// TODO Enforce positive area for exterior, negative area for interior?
9459
9460var X0$1 = 0,
9461 Y0$1 = 0,
9462 Z0$1 = 0,
9463 X1$1 = 0,
9464 Y1$1 = 0,
9465 Z1$1 = 0,
9466 X2$1 = 0,
9467 Y2$1 = 0,
9468 Z2$1 = 0,
9469 x00$1,
9470 y00$1,
9471 x0$3,
9472 y0$3;
9473
9474var centroidStream$1 = {
9475 point: centroidPoint$1,
9476 lineStart: centroidLineStart$1,
9477 lineEnd: centroidLineEnd$1,
9478 polygonStart: function() {
9479 centroidStream$1.lineStart = centroidRingStart$1;
9480 centroidStream$1.lineEnd = centroidRingEnd$1;
9481 },
9482 polygonEnd: function() {
9483 centroidStream$1.point = centroidPoint$1;
9484 centroidStream$1.lineStart = centroidLineStart$1;
9485 centroidStream$1.lineEnd = centroidLineEnd$1;
9486 },
9487 result: function() {
9488 var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
9489 : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
9490 : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
9491 : [NaN, NaN];
9492 X0$1 = Y0$1 = Z0$1 =
9493 X1$1 = Y1$1 = Z1$1 =
9494 X2$1 = Y2$1 = Z2$1 = 0;
9495 return centroid;
9496 }
9497};
9498
9499function centroidPoint$1(x, y) {
9500 X0$1 += x;
9501 Y0$1 += y;
9502 ++Z0$1;
9503}
9504
9505function centroidLineStart$1() {
9506 centroidStream$1.point = centroidPointFirstLine;
9507}
9508
9509function centroidPointFirstLine(x, y) {
9510 centroidStream$1.point = centroidPointLine;
9511 centroidPoint$1(x0$3 = x, y0$3 = y);
9512}
9513
9514function centroidPointLine(x, y) {
9515 var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
9516 X1$1 += z * (x0$3 + x) / 2;
9517 Y1$1 += z * (y0$3 + y) / 2;
9518 Z1$1 += z;
9519 centroidPoint$1(x0$3 = x, y0$3 = y);
9520}
9521
9522function centroidLineEnd$1() {
9523 centroidStream$1.point = centroidPoint$1;
9524}
9525
9526function centroidRingStart$1() {
9527 centroidStream$1.point = centroidPointFirstRing;
9528}
9529
9530function centroidRingEnd$1() {
9531 centroidPointRing(x00$1, y00$1);
9532}
9533
9534function centroidPointFirstRing(x, y) {
9535 centroidStream$1.point = centroidPointRing;
9536 centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
9537}
9538
9539function centroidPointRing(x, y) {
9540 var dx = x - x0$3,
9541 dy = y - y0$3,
9542 z = sqrt(dx * dx + dy * dy);
9543
9544 X1$1 += z * (x0$3 + x) / 2;
9545 Y1$1 += z * (y0$3 + y) / 2;
9546 Z1$1 += z;
9547
9548 z = y0$3 * x - x0$3 * y;
9549 X2$1 += z * (x0$3 + x);
9550 Y2$1 += z * (y0$3 + y);
9551 Z2$1 += z * 3;
9552 centroidPoint$1(x0$3 = x, y0$3 = y);
9553}
9554
9555function PathContext(context) {
9556 this._context = context;
9557}
9558
9559PathContext.prototype = {
9560 _radius: 4.5,
9561 pointRadius: function(_) {
9562 return this._radius = _, this;
9563 },
9564 polygonStart: function() {
9565 this._line = 0;
9566 },
9567 polygonEnd: function() {
9568 this._line = NaN;
9569 },
9570 lineStart: function() {
9571 this._point = 0;
9572 },
9573 lineEnd: function() {
9574 if (this._line === 0) this._context.closePath();
9575 this._point = NaN;
9576 },
9577 point: function(x, y) {
9578 switch (this._point) {
9579 case 0: {
9580 this._context.moveTo(x, y);
9581 this._point = 1;
9582 break;
9583 }
9584 case 1: {
9585 this._context.lineTo(x, y);
9586 break;
9587 }
9588 default: {
9589 this._context.moveTo(x + this._radius, y);
9590 this._context.arc(x, y, this._radius, 0, tau$3);
9591 break;
9592 }
9593 }
9594 },
9595 result: noop$2
9596};
9597
9598var lengthSum$1 = adder(),
9599 lengthRing,
9600 x00$2,
9601 y00$2,
9602 x0$4,
9603 y0$4;
9604
9605var lengthStream$1 = {
9606 point: noop$2,
9607 lineStart: function() {
9608 lengthStream$1.point = lengthPointFirst$1;
9609 },
9610 lineEnd: function() {
9611 if (lengthRing) lengthPoint$1(x00$2, y00$2);
9612 lengthStream$1.point = noop$2;
9613 },
9614 polygonStart: function() {
9615 lengthRing = true;
9616 },
9617 polygonEnd: function() {
9618 lengthRing = null;
9619 },
9620 result: function() {
9621 var length = +lengthSum$1;
9622 lengthSum$1.reset();
9623 return length;
9624 }
9625};
9626
9627function lengthPointFirst$1(x, y) {
9628 lengthStream$1.point = lengthPoint$1;
9629 x00$2 = x0$4 = x, y00$2 = y0$4 = y;
9630}
9631
9632function lengthPoint$1(x, y) {
9633 x0$4 -= x, y0$4 -= y;
9634 lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
9635 x0$4 = x, y0$4 = y;
9636}
9637
9638function PathString() {
9639 this._string = [];
9640}
9641
9642PathString.prototype = {
9643 _radius: 4.5,
9644 _circle: circle$1(4.5),
9645 pointRadius: function(_) {
9646 if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
9647 return this;
9648 },
9649 polygonStart: function() {
9650 this._line = 0;
9651 },
9652 polygonEnd: function() {
9653 this._line = NaN;
9654 },
9655 lineStart: function() {
9656 this._point = 0;
9657 },
9658 lineEnd: function() {
9659 if (this._line === 0) this._string.push("Z");
9660 this._point = NaN;
9661 },
9662 point: function(x, y) {
9663 switch (this._point) {
9664 case 0: {
9665 this._string.push("M", x, ",", y);
9666 this._point = 1;
9667 break;
9668 }
9669 case 1: {
9670 this._string.push("L", x, ",", y);
9671 break;
9672 }
9673 default: {
9674 if (this._circle == null) this._circle = circle$1(this._radius);
9675 this._string.push("M", x, ",", y, this._circle);
9676 break;
9677 }
9678 }
9679 },
9680 result: function() {
9681 if (this._string.length) {
9682 var result = this._string.join("");
9683 this._string = [];
9684 return result;
9685 } else {
9686 return null;
9687 }
9688 }
9689};
9690
9691function circle$1(radius) {
9692 return "m0," + radius
9693 + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
9694 + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
9695 + "z";
9696}
9697
9698function index$1(projection, context) {
9699 var pointRadius = 4.5,
9700 projectionStream,
9701 contextStream;
9702
9703 function path(object) {
9704 if (object) {
9705 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
9706 geoStream(object, projectionStream(contextStream));
9707 }
9708 return contextStream.result();
9709 }
9710
9711 path.area = function(object) {
9712 geoStream(object, projectionStream(areaStream$1));
9713 return areaStream$1.result();
9714 };
9715
9716 path.measure = function(object) {
9717 geoStream(object, projectionStream(lengthStream$1));
9718 return lengthStream$1.result();
9719 };
9720
9721 path.bounds = function(object) {
9722 geoStream(object, projectionStream(boundsStream$1));
9723 return boundsStream$1.result();
9724 };
9725
9726 path.centroid = function(object) {
9727 geoStream(object, projectionStream(centroidStream$1));
9728 return centroidStream$1.result();
9729 };
9730
9731 path.projection = function(_) {
9732 return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
9733 };
9734
9735 path.context = function(_) {
9736 if (!arguments.length) return context;
9737 contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
9738 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
9739 return path;
9740 };
9741
9742 path.pointRadius = function(_) {
9743 if (!arguments.length) return pointRadius;
9744 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
9745 return path;
9746 };
9747
9748 return path.projection(projection).context(context);
9749}
9750
9751function transform(methods) {
9752 return {
9753 stream: transformer(methods)
9754 };
9755}
9756
9757function transformer(methods) {
9758 return function(stream) {
9759 var s = new TransformStream;
9760 for (var key in methods) s[key] = methods[key];
9761 s.stream = stream;
9762 return s;
9763 };
9764}
9765
9766function TransformStream() {}
9767
9768TransformStream.prototype = {
9769 constructor: TransformStream,
9770 point: function(x, y) { this.stream.point(x, y); },
9771 sphere: function() { this.stream.sphere(); },
9772 lineStart: function() { this.stream.lineStart(); },
9773 lineEnd: function() { this.stream.lineEnd(); },
9774 polygonStart: function() { this.stream.polygonStart(); },
9775 polygonEnd: function() { this.stream.polygonEnd(); }
9776};
9777
9778function fit(projection, fitBounds, object) {
9779 var clip = projection.clipExtent && projection.clipExtent();
9780 projection.scale(150).translate([0, 0]);
9781 if (clip != null) projection.clipExtent(null);
9782 geoStream(object, projection.stream(boundsStream$1));
9783 fitBounds(boundsStream$1.result());
9784 if (clip != null) projection.clipExtent(clip);
9785 return projection;
9786}
9787
9788function fitExtent(projection, extent, object) {
9789 return fit(projection, function(b) {
9790 var w = extent[1][0] - extent[0][0],
9791 h = extent[1][1] - extent[0][1],
9792 k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
9793 x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
9794 y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
9795 projection.scale(150 * k).translate([x, y]);
9796 }, object);
9797}
9798
9799function fitSize(projection, size, object) {
9800 return fitExtent(projection, [[0, 0], size], object);
9801}
9802
9803function fitWidth(projection, width, object) {
9804 return fit(projection, function(b) {
9805 var w = +width,
9806 k = w / (b[1][0] - b[0][0]),
9807 x = (w - k * (b[1][0] + b[0][0])) / 2,
9808 y = -k * b[0][1];
9809 projection.scale(150 * k).translate([x, y]);
9810 }, object);
9811}
9812
9813function fitHeight(projection, height, object) {
9814 return fit(projection, function(b) {
9815 var h = +height,
9816 k = h / (b[1][1] - b[0][1]),
9817 x = -k * b[0][0],
9818 y = (h - k * (b[1][1] + b[0][1])) / 2;
9819 projection.scale(150 * k).translate([x, y]);
9820 }, object);
9821}
9822
9823var maxDepth = 16, // maximum depth of subdivision
9824 cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
9825
9826function resample(project, delta2) {
9827 return +delta2 ? resample$1(project, delta2) : resampleNone(project);
9828}
9829
9830function resampleNone(project) {
9831 return transformer({
9832 point: function(x, y) {
9833 x = project(x, y);
9834 this.stream.point(x[0], x[1]);
9835 }
9836 });
9837}
9838
9839function resample$1(project, delta2) {
9840
9841 function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
9842 var dx = x1 - x0,
9843 dy = y1 - y0,
9844 d2 = dx * dx + dy * dy;
9845 if (d2 > 4 * delta2 && depth--) {
9846 var a = a0 + a1,
9847 b = b0 + b1,
9848 c = c0 + c1,
9849 m = sqrt(a * a + b * b + c * c),
9850 phi2 = asin(c /= m),
9851 lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
9852 p = project(lambda2, phi2),
9853 x2 = p[0],
9854 y2 = p[1],
9855 dx2 = x2 - x0,
9856 dy2 = y2 - y0,
9857 dz = dy * dx2 - dx * dy2;
9858 if (dz * dz / d2 > delta2 // perpendicular projected distance
9859 || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
9860 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
9861 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
9862 stream.point(x2, y2);
9863 resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
9864 }
9865 }
9866 }
9867 return function(stream) {
9868 var lambda00, x00, y00, a00, b00, c00, // first point
9869 lambda0, x0, y0, a0, b0, c0; // previous point
9870
9871 var resampleStream = {
9872 point: point,
9873 lineStart: lineStart,
9874 lineEnd: lineEnd,
9875 polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
9876 polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
9877 };
9878
9879 function point(x, y) {
9880 x = project(x, y);
9881 stream.point(x[0], x[1]);
9882 }
9883
9884 function lineStart() {
9885 x0 = NaN;
9886 resampleStream.point = linePoint;
9887 stream.lineStart();
9888 }
9889
9890 function linePoint(lambda, phi) {
9891 var c = cartesian([lambda, phi]), p = project(lambda, phi);
9892 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);
9893 stream.point(x0, y0);
9894 }
9895
9896 function lineEnd() {
9897 resampleStream.point = point;
9898 stream.lineEnd();
9899 }
9900
9901 function ringStart() {
9902 lineStart();
9903 resampleStream.point = ringPoint;
9904 resampleStream.lineEnd = ringEnd;
9905 }
9906
9907 function ringPoint(lambda, phi) {
9908 linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
9909 resampleStream.point = linePoint;
9910 }
9911
9912 function ringEnd() {
9913 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
9914 resampleStream.lineEnd = lineEnd;
9915 lineEnd();
9916 }
9917
9918 return resampleStream;
9919 };
9920}
9921
9922var transformRadians = transformer({
9923 point: function(x, y) {
9924 this.stream.point(x * radians, y * radians);
9925 }
9926});
9927
9928function transformRotate(rotate) {
9929 return transformer({
9930 point: function(x, y) {
9931 var r = rotate(x, y);
9932 return this.stream.point(r[0], r[1]);
9933 }
9934 });
9935}
9936
9937function scaleTranslate(k, dx, dy) {
9938 function transform(x, y) {
9939 return [dx + k * x, dy - k * y];
9940 }
9941 transform.invert = function(x, y) {
9942 return [(x - dx) / k, (dy - y) / k];
9943 };
9944 return transform;
9945}
9946
9947function scaleTranslateRotate(k, dx, dy, alpha) {
9948 var cosAlpha = cos$1(alpha),
9949 sinAlpha = sin$1(alpha),
9950 a = cosAlpha * k,
9951 b = sinAlpha * k,
9952 ai = cosAlpha / k,
9953 bi = sinAlpha / k,
9954 ci = (sinAlpha * dy - cosAlpha * dx) / k,
9955 fi = (sinAlpha * dx + cosAlpha * dy) / k;
9956 function transform(x, y) {
9957 return [a * x - b * y + dx, dy - b * x - a * y];
9958 }
9959 transform.invert = function(x, y) {
9960 return [ai * x - bi * y + ci, fi - bi * x - ai * y];
9961 };
9962 return transform;
9963}
9964
9965function projection(project) {
9966 return projectionMutator(function() { return project; })();
9967}
9968
9969function projectionMutator(projectAt) {
9970 var project,
9971 k = 150, // scale
9972 x = 480, y = 250, // translate
9973 lambda = 0, phi = 0, // center
9974 deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
9975 alpha = 0, // post-rotate
9976 theta = null, preclip = clipAntimeridian, // pre-clip angle
9977 x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
9978 delta2 = 0.5, // precision
9979 projectResample,
9980 projectTransform,
9981 projectRotateTransform,
9982 cache,
9983 cacheStream;
9984
9985 function projection(point) {
9986 return projectRotateTransform(point[0] * radians, point[1] * radians);
9987 }
9988
9989 function invert(point) {
9990 point = projectRotateTransform.invert(point[0], point[1]);
9991 return point && [point[0] * degrees$1, point[1] * degrees$1];
9992 }
9993
9994 projection.stream = function(stream) {
9995 return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
9996 };
9997
9998 projection.preclip = function(_) {
9999 return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
10000 };
10001
10002 projection.postclip = function(_) {
10003 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
10004 };
10005
10006 projection.clipAngle = function(_) {
10007 return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
10008 };
10009
10010 projection.clipExtent = function(_) {
10011 return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
10012 };
10013
10014 projection.scale = function(_) {
10015 return arguments.length ? (k = +_, recenter()) : k;
10016 };
10017
10018 projection.translate = function(_) {
10019 return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
10020 };
10021
10022 projection.center = function(_) {
10023 return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
10024 };
10025
10026 projection.rotate = function(_) {
10027 return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees$1, deltaPhi * degrees$1, deltaGamma * degrees$1];
10028 };
10029
10030 projection.angle = function(_) {
10031 return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
10032 };
10033
10034 projection.precision = function(_) {
10035 return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
10036 };
10037
10038 projection.fitExtent = function(extent, object) {
10039 return fitExtent(projection, extent, object);
10040 };
10041
10042 projection.fitSize = function(size, object) {
10043 return fitSize(projection, size, object);
10044 };
10045
10046 projection.fitWidth = function(width, object) {
10047 return fitWidth(projection, width, object);
10048 };
10049
10050 projection.fitHeight = function(height, object) {
10051 return fitHeight(projection, height, object);
10052 };
10053
10054 function recenter() {
10055 var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
10056 transform = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
10057 rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
10058 projectTransform = compose(project, transform);
10059 projectRotateTransform = compose(rotate, projectTransform);
10060 projectResample = resample(projectTransform, delta2);
10061 return reset();
10062 }
10063
10064 function reset() {
10065 cache = cacheStream = null;
10066 return projection;
10067 }
10068
10069 return function() {
10070 project = projectAt.apply(this, arguments);
10071 projection.invert = project.invert && invert;
10072 return recenter();
10073 };
10074}
10075
10076function conicProjection(projectAt) {
10077 var phi0 = 0,
10078 phi1 = pi$3 / 3,
10079 m = projectionMutator(projectAt),
10080 p = m(phi0, phi1);
10081
10082 p.parallels = function(_) {
10083 return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
10084 };
10085
10086 return p;
10087}
10088
10089function cylindricalEqualAreaRaw(phi0) {
10090 var cosPhi0 = cos$1(phi0);
10091
10092 function forward(lambda, phi) {
10093 return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
10094 }
10095
10096 forward.invert = function(x, y) {
10097 return [x / cosPhi0, asin(y * cosPhi0)];
10098 };
10099
10100 return forward;
10101}
10102
10103function conicEqualAreaRaw(y0, y1) {
10104 var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
10105
10106 // Are the parallels symmetrical around the Equator?
10107 if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
10108
10109 var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
10110
10111 function project(x, y) {
10112 var r = sqrt(c - 2 * n * sin$1(y)) / n;
10113 return [r * sin$1(x *= n), r0 - r * cos$1(x)];
10114 }
10115
10116 project.invert = function(x, y) {
10117 var r0y = r0 - y;
10118 return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
10119 };
10120
10121 return project;
10122}
10123
10124function conicEqualArea() {
10125 return conicProjection(conicEqualAreaRaw)
10126 .scale(155.424)
10127 .center([0, 33.6442]);
10128}
10129
10130function albers() {
10131 return conicEqualArea()
10132 .parallels([29.5, 45.5])
10133 .scale(1070)
10134 .translate([480, 250])
10135 .rotate([96, 0])
10136 .center([-0.6, 38.7]);
10137}
10138
10139// The projections must have mutually exclusive clip regions on the sphere,
10140// as this will avoid emitting interleaving lines and polygons.
10141function multiplex(streams) {
10142 var n = streams.length;
10143 return {
10144 point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
10145 sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
10146 lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
10147 lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
10148 polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
10149 polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
10150 };
10151}
10152
10153// A composite projection for the United States, configured by default for
10154// 960×500. The projection also works quite well at 960×600 if you change the
10155// scale to 1285 and adjust the translate accordingly. The set of standard
10156// parallels for each region comes from USGS, which is published here:
10157// http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
10158function albersUsa() {
10159 var cache,
10160 cacheStream,
10161 lower48 = albers(), lower48Point,
10162 alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
10163 hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
10164 point, pointStream = {point: function(x, y) { point = [x, y]; }};
10165
10166 function albersUsa(coordinates) {
10167 var x = coordinates[0], y = coordinates[1];
10168 return point = null,
10169 (lower48Point.point(x, y), point)
10170 || (alaskaPoint.point(x, y), point)
10171 || (hawaiiPoint.point(x, y), point);
10172 }
10173
10174 albersUsa.invert = function(coordinates) {
10175 var k = lower48.scale(),
10176 t = lower48.translate(),
10177 x = (coordinates[0] - t[0]) / k,
10178 y = (coordinates[1] - t[1]) / k;
10179 return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
10180 : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
10181 : lower48).invert(coordinates);
10182 };
10183
10184 albersUsa.stream = function(stream) {
10185 return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
10186 };
10187
10188 albersUsa.precision = function(_) {
10189 if (!arguments.length) return lower48.precision();
10190 lower48.precision(_), alaska.precision(_), hawaii.precision(_);
10191 return reset();
10192 };
10193
10194 albersUsa.scale = function(_) {
10195 if (!arguments.length) return lower48.scale();
10196 lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
10197 return albersUsa.translate(lower48.translate());
10198 };
10199
10200 albersUsa.translate = function(_) {
10201 if (!arguments.length) return lower48.translate();
10202 var k = lower48.scale(), x = +_[0], y = +_[1];
10203
10204 lower48Point = lower48
10205 .translate(_)
10206 .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
10207 .stream(pointStream);
10208
10209 alaskaPoint = alaska
10210 .translate([x - 0.307 * k, y + 0.201 * k])
10211 .clipExtent([[x - 0.425 * k + epsilon$2, y + 0.120 * k + epsilon$2], [x - 0.214 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
10212 .stream(pointStream);
10213
10214 hawaiiPoint = hawaii
10215 .translate([x - 0.205 * k, y + 0.212 * k])
10216 .clipExtent([[x - 0.214 * k + epsilon$2, y + 0.166 * k + epsilon$2], [x - 0.115 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
10217 .stream(pointStream);
10218
10219 return reset();
10220 };
10221
10222 albersUsa.fitExtent = function(extent, object) {
10223 return fitExtent(albersUsa, extent, object);
10224 };
10225
10226 albersUsa.fitSize = function(size, object) {
10227 return fitSize(albersUsa, size, object);
10228 };
10229
10230 albersUsa.fitWidth = function(width, object) {
10231 return fitWidth(albersUsa, width, object);
10232 };
10233
10234 albersUsa.fitHeight = function(height, object) {
10235 return fitHeight(albersUsa, height, object);
10236 };
10237
10238 function reset() {
10239 cache = cacheStream = null;
10240 return albersUsa;
10241 }
10242
10243 return albersUsa.scale(1070);
10244}
10245
10246function azimuthalRaw(scale) {
10247 return function(x, y) {
10248 var cx = cos$1(x),
10249 cy = cos$1(y),
10250 k = scale(cx * cy);
10251 return [
10252 k * cy * sin$1(x),
10253 k * sin$1(y)
10254 ];
10255 }
10256}
10257
10258function azimuthalInvert(angle) {
10259 return function(x, y) {
10260 var z = sqrt(x * x + y * y),
10261 c = angle(z),
10262 sc = sin$1(c),
10263 cc = cos$1(c);
10264 return [
10265 atan2(x * sc, z * cc),
10266 asin(z && y * sc / z)
10267 ];
10268 }
10269}
10270
10271var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
10272 return sqrt(2 / (1 + cxcy));
10273});
10274
10275azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
10276 return 2 * asin(z / 2);
10277});
10278
10279function azimuthalEqualArea() {
10280 return projection(azimuthalEqualAreaRaw)
10281 .scale(124.75)
10282 .clipAngle(180 - 1e-3);
10283}
10284
10285var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
10286 return (c = acos(c)) && c / sin$1(c);
10287});
10288
10289azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
10290 return z;
10291});
10292
10293function azimuthalEquidistant() {
10294 return projection(azimuthalEquidistantRaw)
10295 .scale(79.4188)
10296 .clipAngle(180 - 1e-3);
10297}
10298
10299function mercatorRaw(lambda, phi) {
10300 return [lambda, log(tan((halfPi$2 + phi) / 2))];
10301}
10302
10303mercatorRaw.invert = function(x, y) {
10304 return [x, 2 * atan(exp(y)) - halfPi$2];
10305};
10306
10307function mercator() {
10308 return mercatorProjection(mercatorRaw)
10309 .scale(961 / tau$3);
10310}
10311
10312function mercatorProjection(project) {
10313 var m = projection(project),
10314 center = m.center,
10315 scale = m.scale,
10316 translate = m.translate,
10317 clipExtent = m.clipExtent,
10318 x0 = null, y0, x1, y1; // clip extent
10319
10320 m.scale = function(_) {
10321 return arguments.length ? (scale(_), reclip()) : scale();
10322 };
10323
10324 m.translate = function(_) {
10325 return arguments.length ? (translate(_), reclip()) : translate();
10326 };
10327
10328 m.center = function(_) {
10329 return arguments.length ? (center(_), reclip()) : center();
10330 };
10331
10332 m.clipExtent = function(_) {
10333 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]];
10334 };
10335
10336 function reclip() {
10337 var k = pi$3 * scale(),
10338 t = m(rotation(m.rotate()).invert([0, 0]));
10339 return clipExtent(x0 == null
10340 ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
10341 ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
10342 : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
10343 }
10344
10345 return reclip();
10346}
10347
10348function tany(y) {
10349 return tan((halfPi$2 + y) / 2);
10350}
10351
10352function conicConformalRaw(y0, y1) {
10353 var cy0 = cos$1(y0),
10354 n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
10355 f = cy0 * pow(tany(y0), n) / n;
10356
10357 if (!n) return mercatorRaw;
10358
10359 function project(x, y) {
10360 if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
10361 else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
10362 var r = f / pow(tany(y), n);
10363 return [r * sin$1(n * x), f - r * cos$1(n * x)];
10364 }
10365
10366 project.invert = function(x, y) {
10367 var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
10368 return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
10369 };
10370
10371 return project;
10372}
10373
10374function conicConformal() {
10375 return conicProjection(conicConformalRaw)
10376 .scale(109.5)
10377 .parallels([30, 30]);
10378}
10379
10380function equirectangularRaw(lambda, phi) {
10381 return [lambda, phi];
10382}
10383
10384equirectangularRaw.invert = equirectangularRaw;
10385
10386function equirectangular() {
10387 return projection(equirectangularRaw)
10388 .scale(152.63);
10389}
10390
10391function conicEquidistantRaw(y0, y1) {
10392 var cy0 = cos$1(y0),
10393 n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
10394 g = cy0 / n + y0;
10395
10396 if (abs(n) < epsilon$2) return equirectangularRaw;
10397
10398 function project(x, y) {
10399 var gy = g - y, nx = n * x;
10400 return [gy * sin$1(nx), g - gy * cos$1(nx)];
10401 }
10402
10403 project.invert = function(x, y) {
10404 var gy = g - y;
10405 return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
10406 };
10407
10408 return project;
10409}
10410
10411function conicEquidistant() {
10412 return conicProjection(conicEquidistantRaw)
10413 .scale(131.154)
10414 .center([0, 13.9389]);
10415}
10416
10417var A1 = 1.340264,
10418 A2 = -0.081106,
10419 A3 = 0.000893,
10420 A4 = 0.003796,
10421 M = sqrt(3) / 2,
10422 iterations = 12;
10423
10424function equalEarthRaw(lambda, phi) {
10425 var l = asin(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
10426 return [
10427 lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
10428 l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
10429 ];
10430}
10431
10432equalEarthRaw.invert = function(x, y) {
10433 var l = y, l2 = l * l, l6 = l2 * l2 * l2;
10434 for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
10435 fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
10436 fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
10437 l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
10438 if (abs(delta) < epsilon2$1) break;
10439 }
10440 return [
10441 M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
10442 asin(sin$1(l) / M)
10443 ];
10444};
10445
10446function equalEarth() {
10447 return projection(equalEarthRaw)
10448 .scale(177.158);
10449}
10450
10451function gnomonicRaw(x, y) {
10452 var cy = cos$1(y), k = cos$1(x) * cy;
10453 return [cy * sin$1(x) / k, sin$1(y) / k];
10454}
10455
10456gnomonicRaw.invert = azimuthalInvert(atan);
10457
10458function gnomonic() {
10459 return projection(gnomonicRaw)
10460 .scale(144.049)
10461 .clipAngle(60);
10462}
10463
10464function scaleTranslate$1(kx, ky, tx, ty) {
10465 return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
10466 point: function(x, y) {
10467 this.stream.point(x * kx + tx, y * ky + ty);
10468 }
10469 });
10470}
10471
10472function identity$5() {
10473 var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform = identity$4, // scale, translate and reflect
10474 x0 = null, y0, x1, y1, // clip extent
10475 postclip = identity$4,
10476 cache,
10477 cacheStream,
10478 projection;
10479
10480 function reset() {
10481 cache = cacheStream = null;
10482 return projection;
10483 }
10484
10485 return projection = {
10486 stream: function(stream) {
10487 return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
10488 },
10489 postclip: function(_) {
10490 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
10491 },
10492 clipExtent: function(_) {
10493 return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
10494 },
10495 scale: function(_) {
10496 return arguments.length ? (transform = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
10497 },
10498 translate: function(_) {
10499 return arguments.length ? (transform = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
10500 },
10501 reflectX: function(_) {
10502 return arguments.length ? (transform = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
10503 },
10504 reflectY: function(_) {
10505 return arguments.length ? (transform = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
10506 },
10507 fitExtent: function(extent, object) {
10508 return fitExtent(projection, extent, object);
10509 },
10510 fitSize: function(size, object) {
10511 return fitSize(projection, size, object);
10512 },
10513 fitWidth: function(width, object) {
10514 return fitWidth(projection, width, object);
10515 },
10516 fitHeight: function(height, object) {
10517 return fitHeight(projection, height, object);
10518 }
10519 };
10520}
10521
10522function naturalEarth1Raw(lambda, phi) {
10523 var phi2 = phi * phi, phi4 = phi2 * phi2;
10524 return [
10525 lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
10526 phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
10527 ];
10528}
10529
10530naturalEarth1Raw.invert = function(x, y) {
10531 var phi = y, i = 25, delta;
10532 do {
10533 var phi2 = phi * phi, phi4 = phi2 * phi2;
10534 phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
10535 (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
10536 } while (abs(delta) > epsilon$2 && --i > 0);
10537 return [
10538 x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
10539 phi
10540 ];
10541};
10542
10543function naturalEarth1() {
10544 return projection(naturalEarth1Raw)
10545 .scale(175.295);
10546}
10547
10548function orthographicRaw(x, y) {
10549 return [cos$1(y) * sin$1(x), sin$1(y)];
10550}
10551
10552orthographicRaw.invert = azimuthalInvert(asin);
10553
10554function orthographic() {
10555 return projection(orthographicRaw)
10556 .scale(249.5)
10557 .clipAngle(90 + epsilon$2);
10558}
10559
10560function stereographicRaw(x, y) {
10561 var cy = cos$1(y), k = 1 + cos$1(x) * cy;
10562 return [cy * sin$1(x) / k, sin$1(y) / k];
10563}
10564
10565stereographicRaw.invert = azimuthalInvert(function(z) {
10566 return 2 * atan(z);
10567});
10568
10569function stereographic() {
10570 return projection(stereographicRaw)
10571 .scale(250)
10572 .clipAngle(142);
10573}
10574
10575function transverseMercatorRaw(lambda, phi) {
10576 return [log(tan((halfPi$2 + phi) / 2)), -lambda];
10577}
10578
10579transverseMercatorRaw.invert = function(x, y) {
10580 return [-y, 2 * atan(exp(x)) - halfPi$2];
10581};
10582
10583function transverseMercator() {
10584 var m = mercatorProjection(transverseMercatorRaw),
10585 center = m.center,
10586 rotate = m.rotate;
10587
10588 m.center = function(_) {
10589 return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
10590 };
10591
10592 m.rotate = function(_) {
10593 return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
10594 };
10595
10596 return rotate([0, 0, 90])
10597 .scale(159.155);
10598}
10599
10600function defaultSeparation(a, b) {
10601 return a.parent === b.parent ? 1 : 2;
10602}
10603
10604function meanX(children) {
10605 return children.reduce(meanXReduce, 0) / children.length;
10606}
10607
10608function meanXReduce(x, c) {
10609 return x + c.x;
10610}
10611
10612function maxY(children) {
10613 return 1 + children.reduce(maxYReduce, 0);
10614}
10615
10616function maxYReduce(y, c) {
10617 return Math.max(y, c.y);
10618}
10619
10620function leafLeft(node) {
10621 var children;
10622 while (children = node.children) node = children[0];
10623 return node;
10624}
10625
10626function leafRight(node) {
10627 var children;
10628 while (children = node.children) node = children[children.length - 1];
10629 return node;
10630}
10631
10632function cluster() {
10633 var separation = defaultSeparation,
10634 dx = 1,
10635 dy = 1,
10636 nodeSize = false;
10637
10638 function cluster(root) {
10639 var previousNode,
10640 x = 0;
10641
10642 // First walk, computing the initial x & y values.
10643 root.eachAfter(function(node) {
10644 var children = node.children;
10645 if (children) {
10646 node.x = meanX(children);
10647 node.y = maxY(children);
10648 } else {
10649 node.x = previousNode ? x += separation(node, previousNode) : 0;
10650 node.y = 0;
10651 previousNode = node;
10652 }
10653 });
10654
10655 var left = leafLeft(root),
10656 right = leafRight(root),
10657 x0 = left.x - separation(left, right) / 2,
10658 x1 = right.x + separation(right, left) / 2;
10659
10660 // Second walk, normalizing x & y to the desired size.
10661 return root.eachAfter(nodeSize ? function(node) {
10662 node.x = (node.x - root.x) * dx;
10663 node.y = (root.y - node.y) * dy;
10664 } : function(node) {
10665 node.x = (node.x - x0) / (x1 - x0) * dx;
10666 node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
10667 });
10668 }
10669
10670 cluster.separation = function(x) {
10671 return arguments.length ? (separation = x, cluster) : separation;
10672 };
10673
10674 cluster.size = function(x) {
10675 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
10676 };
10677
10678 cluster.nodeSize = function(x) {
10679 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
10680 };
10681
10682 return cluster;
10683}
10684
10685function count(node) {
10686 var sum = 0,
10687 children = node.children,
10688 i = children && children.length;
10689 if (!i) sum = 1;
10690 else while (--i >= 0) sum += children[i].value;
10691 node.value = sum;
10692}
10693
10694function node_count() {
10695 return this.eachAfter(count);
10696}
10697
10698function node_each(callback) {
10699 var node = this, current, next = [node], children, i, n;
10700 do {
10701 current = next.reverse(), next = [];
10702 while (node = current.pop()) {
10703 callback(node), children = node.children;
10704 if (children) for (i = 0, n = children.length; i < n; ++i) {
10705 next.push(children[i]);
10706 }
10707 }
10708 } while (next.length);
10709 return this;
10710}
10711
10712function node_eachBefore(callback) {
10713 var node = this, nodes = [node], children, i;
10714 while (node = nodes.pop()) {
10715 callback(node), children = node.children;
10716 if (children) for (i = children.length - 1; i >= 0; --i) {
10717 nodes.push(children[i]);
10718 }
10719 }
10720 return this;
10721}
10722
10723function node_eachAfter(callback) {
10724 var node = this, nodes = [node], next = [], children, i, n;
10725 while (node = nodes.pop()) {
10726 next.push(node), children = node.children;
10727 if (children) for (i = 0, n = children.length; i < n; ++i) {
10728 nodes.push(children[i]);
10729 }
10730 }
10731 while (node = next.pop()) {
10732 callback(node);
10733 }
10734 return this;
10735}
10736
10737function node_sum(value) {
10738 return this.eachAfter(function(node) {
10739 var sum = +value(node.data) || 0,
10740 children = node.children,
10741 i = children && children.length;
10742 while (--i >= 0) sum += children[i].value;
10743 node.value = sum;
10744 });
10745}
10746
10747function node_sort(compare) {
10748 return this.eachBefore(function(node) {
10749 if (node.children) {
10750 node.children.sort(compare);
10751 }
10752 });
10753}
10754
10755function node_path(end) {
10756 var start = this,
10757 ancestor = leastCommonAncestor(start, end),
10758 nodes = [start];
10759 while (start !== ancestor) {
10760 start = start.parent;
10761 nodes.push(start);
10762 }
10763 var k = nodes.length;
10764 while (end !== ancestor) {
10765 nodes.splice(k, 0, end);
10766 end = end.parent;
10767 }
10768 return nodes;
10769}
10770
10771function leastCommonAncestor(a, b) {
10772 if (a === b) return a;
10773 var aNodes = a.ancestors(),
10774 bNodes = b.ancestors(),
10775 c = null;
10776 a = aNodes.pop();
10777 b = bNodes.pop();
10778 while (a === b) {
10779 c = a;
10780 a = aNodes.pop();
10781 b = bNodes.pop();
10782 }
10783 return c;
10784}
10785
10786function node_ancestors() {
10787 var node = this, nodes = [node];
10788 while (node = node.parent) {
10789 nodes.push(node);
10790 }
10791 return nodes;
10792}
10793
10794function node_descendants() {
10795 var nodes = [];
10796 this.each(function(node) {
10797 nodes.push(node);
10798 });
10799 return nodes;
10800}
10801
10802function node_leaves() {
10803 var leaves = [];
10804 this.eachBefore(function(node) {
10805 if (!node.children) {
10806 leaves.push(node);
10807 }
10808 });
10809 return leaves;
10810}
10811
10812function node_links() {
10813 var root = this, links = [];
10814 root.each(function(node) {
10815 if (node !== root) { // Don’t include the root’s parent, if any.
10816 links.push({source: node.parent, target: node});
10817 }
10818 });
10819 return links;
10820}
10821
10822function hierarchy(data, children) {
10823 var root = new Node(data),
10824 valued = +data.value && (root.value = data.value),
10825 node,
10826 nodes = [root],
10827 child,
10828 childs,
10829 i,
10830 n;
10831
10832 if (children == null) children = defaultChildren;
10833
10834 while (node = nodes.pop()) {
10835 if (valued) node.value = +node.data.value;
10836 if ((childs = children(node.data)) && (n = childs.length)) {
10837 node.children = new Array(n);
10838 for (i = n - 1; i >= 0; --i) {
10839 nodes.push(child = node.children[i] = new Node(childs[i]));
10840 child.parent = node;
10841 child.depth = node.depth + 1;
10842 }
10843 }
10844 }
10845
10846 return root.eachBefore(computeHeight);
10847}
10848
10849function node_copy() {
10850 return hierarchy(this).eachBefore(copyData);
10851}
10852
10853function defaultChildren(d) {
10854 return d.children;
10855}
10856
10857function copyData(node) {
10858 node.data = node.data.data;
10859}
10860
10861function computeHeight(node) {
10862 var height = 0;
10863 do node.height = height;
10864 while ((node = node.parent) && (node.height < ++height));
10865}
10866
10867function Node(data) {
10868 this.data = data;
10869 this.depth =
10870 this.height = 0;
10871 this.parent = null;
10872}
10873
10874Node.prototype = hierarchy.prototype = {
10875 constructor: Node,
10876 count: node_count,
10877 each: node_each,
10878 eachAfter: node_eachAfter,
10879 eachBefore: node_eachBefore,
10880 sum: node_sum,
10881 sort: node_sort,
10882 path: node_path,
10883 ancestors: node_ancestors,
10884 descendants: node_descendants,
10885 leaves: node_leaves,
10886 links: node_links,
10887 copy: node_copy
10888};
10889
10890var slice$4 = Array.prototype.slice;
10891
10892function shuffle$1(array) {
10893 var m = array.length,
10894 t,
10895 i;
10896
10897 while (m) {
10898 i = Math.random() * m-- | 0;
10899 t = array[m];
10900 array[m] = array[i];
10901 array[i] = t;
10902 }
10903
10904 return array;
10905}
10906
10907function enclose(circles) {
10908 var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
10909
10910 while (i < n) {
10911 p = circles[i];
10912 if (e && enclosesWeak(e, p)) ++i;
10913 else e = encloseBasis(B = extendBasis(B, p)), i = 0;
10914 }
10915
10916 return e;
10917}
10918
10919function extendBasis(B, p) {
10920 var i, j;
10921
10922 if (enclosesWeakAll(p, B)) return [p];
10923
10924 // If we get here then B must have at least one element.
10925 for (i = 0; i < B.length; ++i) {
10926 if (enclosesNot(p, B[i])
10927 && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
10928 return [B[i], p];
10929 }
10930 }
10931
10932 // If we get here then B must have at least two elements.
10933 for (i = 0; i < B.length - 1; ++i) {
10934 for (j = i + 1; j < B.length; ++j) {
10935 if (enclosesNot(encloseBasis2(B[i], B[j]), p)
10936 && enclosesNot(encloseBasis2(B[i], p), B[j])
10937 && enclosesNot(encloseBasis2(B[j], p), B[i])
10938 && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
10939 return [B[i], B[j], p];
10940 }
10941 }
10942 }
10943
10944 // If we get here then something is very wrong.
10945 throw new Error;
10946}
10947
10948function enclosesNot(a, b) {
10949 var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
10950 return dr < 0 || dr * dr < dx * dx + dy * dy;
10951}
10952
10953function enclosesWeak(a, b) {
10954 var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10955 return dr > 0 && dr * dr > dx * dx + dy * dy;
10956}
10957
10958function enclosesWeakAll(a, B) {
10959 for (var i = 0; i < B.length; ++i) {
10960 if (!enclosesWeak(a, B[i])) {
10961 return false;
10962 }
10963 }
10964 return true;
10965}
10966
10967function encloseBasis(B) {
10968 switch (B.length) {
10969 case 1: return encloseBasis1(B[0]);
10970 case 2: return encloseBasis2(B[0], B[1]);
10971 case 3: return encloseBasis3(B[0], B[1], B[2]);
10972 }
10973}
10974
10975function encloseBasis1(a) {
10976 return {
10977 x: a.x,
10978 y: a.y,
10979 r: a.r
10980 };
10981}
10982
10983function encloseBasis2(a, b) {
10984 var x1 = a.x, y1 = a.y, r1 = a.r,
10985 x2 = b.x, y2 = b.y, r2 = b.r,
10986 x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
10987 l = Math.sqrt(x21 * x21 + y21 * y21);
10988 return {
10989 x: (x1 + x2 + x21 / l * r21) / 2,
10990 y: (y1 + y2 + y21 / l * r21) / 2,
10991 r: (l + r1 + r2) / 2
10992 };
10993}
10994
10995function encloseBasis3(a, b, c) {
10996 var x1 = a.x, y1 = a.y, r1 = a.r,
10997 x2 = b.x, y2 = b.y, r2 = b.r,
10998 x3 = c.x, y3 = c.y, r3 = c.r,
10999 a2 = x1 - x2,
11000 a3 = x1 - x3,
11001 b2 = y1 - y2,
11002 b3 = y1 - y3,
11003 c2 = r2 - r1,
11004 c3 = r3 - r1,
11005 d1 = x1 * x1 + y1 * y1 - r1 * r1,
11006 d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
11007 d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
11008 ab = a3 * b2 - a2 * b3,
11009 xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
11010 xb = (b3 * c2 - b2 * c3) / ab,
11011 ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
11012 yb = (a2 * c3 - a3 * c2) / ab,
11013 A = xb * xb + yb * yb - 1,
11014 B = 2 * (r1 + xa * xb + ya * yb),
11015 C = xa * xa + ya * ya - r1 * r1,
11016 r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
11017 return {
11018 x: x1 + xa + xb * r,
11019 y: y1 + ya + yb * r,
11020 r: r
11021 };
11022}
11023
11024function place(b, a, c) {
11025 var dx = b.x - a.x, x, a2,
11026 dy = b.y - a.y, y, b2,
11027 d2 = dx * dx + dy * dy;
11028 if (d2) {
11029 a2 = a.r + c.r, a2 *= a2;
11030 b2 = b.r + c.r, b2 *= b2;
11031 if (a2 > b2) {
11032 x = (d2 + b2 - a2) / (2 * d2);
11033 y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
11034 c.x = b.x - x * dx - y * dy;
11035 c.y = b.y - x * dy + y * dx;
11036 } else {
11037 x = (d2 + a2 - b2) / (2 * d2);
11038 y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
11039 c.x = a.x + x * dx - y * dy;
11040 c.y = a.y + x * dy + y * dx;
11041 }
11042 } else {
11043 c.x = a.x + c.r;
11044 c.y = a.y;
11045 }
11046}
11047
11048function intersects(a, b) {
11049 var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
11050 return dr > 0 && dr * dr > dx * dx + dy * dy;
11051}
11052
11053function score(node) {
11054 var a = node._,
11055 b = node.next._,
11056 ab = a.r + b.r,
11057 dx = (a.x * b.r + b.x * a.r) / ab,
11058 dy = (a.y * b.r + b.y * a.r) / ab;
11059 return dx * dx + dy * dy;
11060}
11061
11062function Node$1(circle) {
11063 this._ = circle;
11064 this.next = null;
11065 this.previous = null;
11066}
11067
11068function packEnclose(circles) {
11069 if (!(n = circles.length)) return 0;
11070
11071 var a, b, c, n, aa, ca, i, j, k, sj, sk;
11072
11073 // Place the first circle.
11074 a = circles[0], a.x = 0, a.y = 0;
11075 if (!(n > 1)) return a.r;
11076
11077 // Place the second circle.
11078 b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
11079 if (!(n > 2)) return a.r + b.r;
11080
11081 // Place the third circle.
11082 place(b, a, c = circles[2]);
11083
11084 // Initialize the front-chain using the first three circles a, b and c.
11085 a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
11086 a.next = c.previous = b;
11087 b.next = a.previous = c;
11088 c.next = b.previous = a;
11089
11090 // Attempt to place each remaining circle…
11091 pack: for (i = 3; i < n; ++i) {
11092 place(a._, b._, c = circles[i]), c = new Node$1(c);
11093
11094 // Find the closest intersecting circle on the front-chain, if any.
11095 // “Closeness” is determined by linear distance along the front-chain.
11096 // “Ahead” or “behind” is likewise determined by linear distance.
11097 j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
11098 do {
11099 if (sj <= sk) {
11100 if (intersects(j._, c._)) {
11101 b = j, a.next = b, b.previous = a, --i;
11102 continue pack;
11103 }
11104 sj += j._.r, j = j.next;
11105 } else {
11106 if (intersects(k._, c._)) {
11107 a = k, a.next = b, b.previous = a, --i;
11108 continue pack;
11109 }
11110 sk += k._.r, k = k.previous;
11111 }
11112 } while (j !== k.next);
11113
11114 // Success! Insert the new circle c between a and b.
11115 c.previous = a, c.next = b, a.next = b.previous = b = c;
11116
11117 // Compute the new closest circle pair to the centroid.
11118 aa = score(a);
11119 while ((c = c.next) !== b) {
11120 if ((ca = score(c)) < aa) {
11121 a = c, aa = ca;
11122 }
11123 }
11124 b = a.next;
11125 }
11126
11127 // Compute the enclosing circle of the front chain.
11128 a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
11129
11130 // Translate the circles to put the enclosing circle around the origin.
11131 for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
11132
11133 return c.r;
11134}
11135
11136function siblings(circles) {
11137 packEnclose(circles);
11138 return circles;
11139}
11140
11141function optional(f) {
11142 return f == null ? null : required(f);
11143}
11144
11145function required(f) {
11146 if (typeof f !== "function") throw new Error;
11147 return f;
11148}
11149
11150function constantZero() {
11151 return 0;
11152}
11153
11154function constant$9(x) {
11155 return function() {
11156 return x;
11157 };
11158}
11159
11160function defaultRadius$1(d) {
11161 return Math.sqrt(d.value);
11162}
11163
11164function index$2() {
11165 var radius = null,
11166 dx = 1,
11167 dy = 1,
11168 padding = constantZero;
11169
11170 function pack(root) {
11171 root.x = dx / 2, root.y = dy / 2;
11172 if (radius) {
11173 root.eachBefore(radiusLeaf(radius))
11174 .eachAfter(packChildren(padding, 0.5))
11175 .eachBefore(translateChild(1));
11176 } else {
11177 root.eachBefore(radiusLeaf(defaultRadius$1))
11178 .eachAfter(packChildren(constantZero, 1))
11179 .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
11180 .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
11181 }
11182 return root;
11183 }
11184
11185 pack.radius = function(x) {
11186 return arguments.length ? (radius = optional(x), pack) : radius;
11187 };
11188
11189 pack.size = function(x) {
11190 return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
11191 };
11192
11193 pack.padding = function(x) {
11194 return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
11195 };
11196
11197 return pack;
11198}
11199
11200function radiusLeaf(radius) {
11201 return function(node) {
11202 if (!node.children) {
11203 node.r = Math.max(0, +radius(node) || 0);
11204 }
11205 };
11206}
11207
11208function packChildren(padding, k) {
11209 return function(node) {
11210 if (children = node.children) {
11211 var children,
11212 i,
11213 n = children.length,
11214 r = padding(node) * k || 0,
11215 e;
11216
11217 if (r) for (i = 0; i < n; ++i) children[i].r += r;
11218 e = packEnclose(children);
11219 if (r) for (i = 0; i < n; ++i) children[i].r -= r;
11220 node.r = e + r;
11221 }
11222 };
11223}
11224
11225function translateChild(k) {
11226 return function(node) {
11227 var parent = node.parent;
11228 node.r *= k;
11229 if (parent) {
11230 node.x = parent.x + k * node.x;
11231 node.y = parent.y + k * node.y;
11232 }
11233 };
11234}
11235
11236function roundNode(node) {
11237 node.x0 = Math.round(node.x0);
11238 node.y0 = Math.round(node.y0);
11239 node.x1 = Math.round(node.x1);
11240 node.y1 = Math.round(node.y1);
11241}
11242
11243function treemapDice(parent, x0, y0, x1, y1) {
11244 var nodes = parent.children,
11245 node,
11246 i = -1,
11247 n = nodes.length,
11248 k = parent.value && (x1 - x0) / parent.value;
11249
11250 while (++i < n) {
11251 node = nodes[i], node.y0 = y0, node.y1 = y1;
11252 node.x0 = x0, node.x1 = x0 += node.value * k;
11253 }
11254}
11255
11256function partition() {
11257 var dx = 1,
11258 dy = 1,
11259 padding = 0,
11260 round = false;
11261
11262 function partition(root) {
11263 var n = root.height + 1;
11264 root.x0 =
11265 root.y0 = padding;
11266 root.x1 = dx;
11267 root.y1 = dy / n;
11268 root.eachBefore(positionNode(dy, n));
11269 if (round) root.eachBefore(roundNode);
11270 return root;
11271 }
11272
11273 function positionNode(dy, n) {
11274 return function(node) {
11275 if (node.children) {
11276 treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
11277 }
11278 var x0 = node.x0,
11279 y0 = node.y0,
11280 x1 = node.x1 - padding,
11281 y1 = node.y1 - padding;
11282 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11283 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11284 node.x0 = x0;
11285 node.y0 = y0;
11286 node.x1 = x1;
11287 node.y1 = y1;
11288 };
11289 }
11290
11291 partition.round = function(x) {
11292 return arguments.length ? (round = !!x, partition) : round;
11293 };
11294
11295 partition.size = function(x) {
11296 return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
11297 };
11298
11299 partition.padding = function(x) {
11300 return arguments.length ? (padding = +x, partition) : padding;
11301 };
11302
11303 return partition;
11304}
11305
11306var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
11307 preroot = {depth: -1},
11308 ambiguous = {};
11309
11310function defaultId(d) {
11311 return d.id;
11312}
11313
11314function defaultParentId(d) {
11315 return d.parentId;
11316}
11317
11318function stratify() {
11319 var id = defaultId,
11320 parentId = defaultParentId;
11321
11322 function stratify(data) {
11323 var d,
11324 i,
11325 n = data.length,
11326 root,
11327 parent,
11328 node,
11329 nodes = new Array(n),
11330 nodeId,
11331 nodeKey,
11332 nodeByKey = {};
11333
11334 for (i = 0; i < n; ++i) {
11335 d = data[i], node = nodes[i] = new Node(d);
11336 if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
11337 nodeKey = keyPrefix$1 + (node.id = nodeId);
11338 nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
11339 }
11340 }
11341
11342 for (i = 0; i < n; ++i) {
11343 node = nodes[i], nodeId = parentId(data[i], i, data);
11344 if (nodeId == null || !(nodeId += "")) {
11345 if (root) throw new Error("multiple roots");
11346 root = node;
11347 } else {
11348 parent = nodeByKey[keyPrefix$1 + nodeId];
11349 if (!parent) throw new Error("missing: " + nodeId);
11350 if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
11351 if (parent.children) parent.children.push(node);
11352 else parent.children = [node];
11353 node.parent = parent;
11354 }
11355 }
11356
11357 if (!root) throw new Error("no root");
11358 root.parent = preroot;
11359 root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
11360 root.parent = null;
11361 if (n > 0) throw new Error("cycle");
11362
11363 return root;
11364 }
11365
11366 stratify.id = function(x) {
11367 return arguments.length ? (id = required(x), stratify) : id;
11368 };
11369
11370 stratify.parentId = function(x) {
11371 return arguments.length ? (parentId = required(x), stratify) : parentId;
11372 };
11373
11374 return stratify;
11375}
11376
11377function defaultSeparation$1(a, b) {
11378 return a.parent === b.parent ? 1 : 2;
11379}
11380
11381// function radialSeparation(a, b) {
11382// return (a.parent === b.parent ? 1 : 2) / a.depth;
11383// }
11384
11385// This function is used to traverse the left contour of a subtree (or
11386// subforest). It returns the successor of v on this contour. This successor is
11387// either given by the leftmost child of v or by the thread of v. The function
11388// returns null if and only if v is on the highest level of its subtree.
11389function nextLeft(v) {
11390 var children = v.children;
11391 return children ? children[0] : v.t;
11392}
11393
11394// This function works analogously to nextLeft.
11395function nextRight(v) {
11396 var children = v.children;
11397 return children ? children[children.length - 1] : v.t;
11398}
11399
11400// Shifts the current subtree rooted at w+. This is done by increasing
11401// prelim(w+) and mod(w+) by shift.
11402function moveSubtree(wm, wp, shift) {
11403 var change = shift / (wp.i - wm.i);
11404 wp.c -= change;
11405 wp.s += shift;
11406 wm.c += change;
11407 wp.z += shift;
11408 wp.m += shift;
11409}
11410
11411// All other shifts, applied to the smaller subtrees between w- and w+, are
11412// performed by this function. To prepare the shifts, we have to adjust
11413// change(w+), shift(w+), and change(w-).
11414function executeShifts(v) {
11415 var shift = 0,
11416 change = 0,
11417 children = v.children,
11418 i = children.length,
11419 w;
11420 while (--i >= 0) {
11421 w = children[i];
11422 w.z += shift;
11423 w.m += shift;
11424 shift += w.s + (change += w.c);
11425 }
11426}
11427
11428// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
11429// returns the specified (default) ancestor.
11430function nextAncestor(vim, v, ancestor) {
11431 return vim.a.parent === v.parent ? vim.a : ancestor;
11432}
11433
11434function TreeNode(node, i) {
11435 this._ = node;
11436 this.parent = null;
11437 this.children = null;
11438 this.A = null; // default ancestor
11439 this.a = this; // ancestor
11440 this.z = 0; // prelim
11441 this.m = 0; // mod
11442 this.c = 0; // change
11443 this.s = 0; // shift
11444 this.t = null; // thread
11445 this.i = i; // number
11446}
11447
11448TreeNode.prototype = Object.create(Node.prototype);
11449
11450function treeRoot(root) {
11451 var tree = new TreeNode(root, 0),
11452 node,
11453 nodes = [tree],
11454 child,
11455 children,
11456 i,
11457 n;
11458
11459 while (node = nodes.pop()) {
11460 if (children = node._.children) {
11461 node.children = new Array(n = children.length);
11462 for (i = n - 1; i >= 0; --i) {
11463 nodes.push(child = node.children[i] = new TreeNode(children[i], i));
11464 child.parent = node;
11465 }
11466 }
11467 }
11468
11469 (tree.parent = new TreeNode(null, 0)).children = [tree];
11470 return tree;
11471}
11472
11473// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
11474function tree() {
11475 var separation = defaultSeparation$1,
11476 dx = 1,
11477 dy = 1,
11478 nodeSize = null;
11479
11480 function tree(root) {
11481 var t = treeRoot(root);
11482
11483 // Compute the layout using Buchheim et al.’s algorithm.
11484 t.eachAfter(firstWalk), t.parent.m = -t.z;
11485 t.eachBefore(secondWalk);
11486
11487 // If a fixed node size is specified, scale x and y.
11488 if (nodeSize) root.eachBefore(sizeNode);
11489
11490 // If a fixed tree size is specified, scale x and y based on the extent.
11491 // Compute the left-most, right-most, and depth-most nodes for extents.
11492 else {
11493 var left = root,
11494 right = root,
11495 bottom = root;
11496 root.eachBefore(function(node) {
11497 if (node.x < left.x) left = node;
11498 if (node.x > right.x) right = node;
11499 if (node.depth > bottom.depth) bottom = node;
11500 });
11501 var s = left === right ? 1 : separation(left, right) / 2,
11502 tx = s - left.x,
11503 kx = dx / (right.x + s + tx),
11504 ky = dy / (bottom.depth || 1);
11505 root.eachBefore(function(node) {
11506 node.x = (node.x + tx) * kx;
11507 node.y = node.depth * ky;
11508 });
11509 }
11510
11511 return root;
11512 }
11513
11514 // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
11515 // applied recursively to the children of v, as well as the function
11516 // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
11517 // node v is placed to the midpoint of its outermost children.
11518 function firstWalk(v) {
11519 var children = v.children,
11520 siblings = v.parent.children,
11521 w = v.i ? siblings[v.i - 1] : null;
11522 if (children) {
11523 executeShifts(v);
11524 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
11525 if (w) {
11526 v.z = w.z + separation(v._, w._);
11527 v.m = v.z - midpoint;
11528 } else {
11529 v.z = midpoint;
11530 }
11531 } else if (w) {
11532 v.z = w.z + separation(v._, w._);
11533 }
11534 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
11535 }
11536
11537 // Computes all real x-coordinates by summing up the modifiers recursively.
11538 function secondWalk(v) {
11539 v._.x = v.z + v.parent.m;
11540 v.m += v.parent.m;
11541 }
11542
11543 // The core of the algorithm. Here, a new subtree is combined with the
11544 // previous subtrees. Threads are used to traverse the inside and outside
11545 // contours of the left and right subtree up to the highest common level. The
11546 // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
11547 // superscript o means outside and i means inside, the subscript - means left
11548 // subtree and + means right subtree. For summing up the modifiers along the
11549 // contour, we use respective variables si+, si-, so-, and so+. Whenever two
11550 // nodes of the inside contours conflict, we compute the left one of the
11551 // greatest uncommon ancestors using the function ANCESTOR and call MOVE
11552 // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
11553 // Finally, we add a new thread (if necessary).
11554 function apportion(v, w, ancestor) {
11555 if (w) {
11556 var vip = v,
11557 vop = v,
11558 vim = w,
11559 vom = vip.parent.children[0],
11560 sip = vip.m,
11561 sop = vop.m,
11562 sim = vim.m,
11563 som = vom.m,
11564 shift;
11565 while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
11566 vom = nextLeft(vom);
11567 vop = nextRight(vop);
11568 vop.a = v;
11569 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
11570 if (shift > 0) {
11571 moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
11572 sip += shift;
11573 sop += shift;
11574 }
11575 sim += vim.m;
11576 sip += vip.m;
11577 som += vom.m;
11578 sop += vop.m;
11579 }
11580 if (vim && !nextRight(vop)) {
11581 vop.t = vim;
11582 vop.m += sim - sop;
11583 }
11584 if (vip && !nextLeft(vom)) {
11585 vom.t = vip;
11586 vom.m += sip - som;
11587 ancestor = v;
11588 }
11589 }
11590 return ancestor;
11591 }
11592
11593 function sizeNode(node) {
11594 node.x *= dx;
11595 node.y = node.depth * dy;
11596 }
11597
11598 tree.separation = function(x) {
11599 return arguments.length ? (separation = x, tree) : separation;
11600 };
11601
11602 tree.size = function(x) {
11603 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
11604 };
11605
11606 tree.nodeSize = function(x) {
11607 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
11608 };
11609
11610 return tree;
11611}
11612
11613function treemapSlice(parent, x0, y0, x1, y1) {
11614 var nodes = parent.children,
11615 node,
11616 i = -1,
11617 n = nodes.length,
11618 k = parent.value && (y1 - y0) / parent.value;
11619
11620 while (++i < n) {
11621 node = nodes[i], node.x0 = x0, node.x1 = x1;
11622 node.y0 = y0, node.y1 = y0 += node.value * k;
11623 }
11624}
11625
11626var phi = (1 + Math.sqrt(5)) / 2;
11627
11628function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
11629 var rows = [],
11630 nodes = parent.children,
11631 row,
11632 nodeValue,
11633 i0 = 0,
11634 i1 = 0,
11635 n = nodes.length,
11636 dx, dy,
11637 value = parent.value,
11638 sumValue,
11639 minValue,
11640 maxValue,
11641 newRatio,
11642 minRatio,
11643 alpha,
11644 beta;
11645
11646 while (i0 < n) {
11647 dx = x1 - x0, dy = y1 - y0;
11648
11649 // Find the next non-empty node.
11650 do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
11651 minValue = maxValue = sumValue;
11652 alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
11653 beta = sumValue * sumValue * alpha;
11654 minRatio = Math.max(maxValue / beta, beta / minValue);
11655
11656 // Keep adding nodes while the aspect ratio maintains or improves.
11657 for (; i1 < n; ++i1) {
11658 sumValue += nodeValue = nodes[i1].value;
11659 if (nodeValue < minValue) minValue = nodeValue;
11660 if (nodeValue > maxValue) maxValue = nodeValue;
11661 beta = sumValue * sumValue * alpha;
11662 newRatio = Math.max(maxValue / beta, beta / minValue);
11663 if (newRatio > minRatio) { sumValue -= nodeValue; break; }
11664 minRatio = newRatio;
11665 }
11666
11667 // Position and record the row orientation.
11668 rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
11669 if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
11670 else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
11671 value -= sumValue, i0 = i1;
11672 }
11673
11674 return rows;
11675}
11676
11677var squarify = (function custom(ratio) {
11678
11679 function squarify(parent, x0, y0, x1, y1) {
11680 squarifyRatio(ratio, parent, x0, y0, x1, y1);
11681 }
11682
11683 squarify.ratio = function(x) {
11684 return custom((x = +x) > 1 ? x : 1);
11685 };
11686
11687 return squarify;
11688})(phi);
11689
11690function index$3() {
11691 var tile = squarify,
11692 round = false,
11693 dx = 1,
11694 dy = 1,
11695 paddingStack = [0],
11696 paddingInner = constantZero,
11697 paddingTop = constantZero,
11698 paddingRight = constantZero,
11699 paddingBottom = constantZero,
11700 paddingLeft = constantZero;
11701
11702 function treemap(root) {
11703 root.x0 =
11704 root.y0 = 0;
11705 root.x1 = dx;
11706 root.y1 = dy;
11707 root.eachBefore(positionNode);
11708 paddingStack = [0];
11709 if (round) root.eachBefore(roundNode);
11710 return root;
11711 }
11712
11713 function positionNode(node) {
11714 var p = paddingStack[node.depth],
11715 x0 = node.x0 + p,
11716 y0 = node.y0 + p,
11717 x1 = node.x1 - p,
11718 y1 = node.y1 - p;
11719 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11720 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11721 node.x0 = x0;
11722 node.y0 = y0;
11723 node.x1 = x1;
11724 node.y1 = y1;
11725 if (node.children) {
11726 p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
11727 x0 += paddingLeft(node) - p;
11728 y0 += paddingTop(node) - p;
11729 x1 -= paddingRight(node) - p;
11730 y1 -= paddingBottom(node) - p;
11731 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11732 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11733 tile(node, x0, y0, x1, y1);
11734 }
11735 }
11736
11737 treemap.round = function(x) {
11738 return arguments.length ? (round = !!x, treemap) : round;
11739 };
11740
11741 treemap.size = function(x) {
11742 return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
11743 };
11744
11745 treemap.tile = function(x) {
11746 return arguments.length ? (tile = required(x), treemap) : tile;
11747 };
11748
11749 treemap.padding = function(x) {
11750 return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
11751 };
11752
11753 treemap.paddingInner = function(x) {
11754 return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
11755 };
11756
11757 treemap.paddingOuter = function(x) {
11758 return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
11759 };
11760
11761 treemap.paddingTop = function(x) {
11762 return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
11763 };
11764
11765 treemap.paddingRight = function(x) {
11766 return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
11767 };
11768
11769 treemap.paddingBottom = function(x) {
11770 return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
11771 };
11772
11773 treemap.paddingLeft = function(x) {
11774 return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
11775 };
11776
11777 return treemap;
11778}
11779
11780function binary(parent, x0, y0, x1, y1) {
11781 var nodes = parent.children,
11782 i, n = nodes.length,
11783 sum, sums = new Array(n + 1);
11784
11785 for (sums[0] = sum = i = 0; i < n; ++i) {
11786 sums[i + 1] = sum += nodes[i].value;
11787 }
11788
11789 partition(0, n, parent.value, x0, y0, x1, y1);
11790
11791 function partition(i, j, value, x0, y0, x1, y1) {
11792 if (i >= j - 1) {
11793 var node = nodes[i];
11794 node.x0 = x0, node.y0 = y0;
11795 node.x1 = x1, node.y1 = y1;
11796 return;
11797 }
11798
11799 var valueOffset = sums[i],
11800 valueTarget = (value / 2) + valueOffset,
11801 k = i + 1,
11802 hi = j - 1;
11803
11804 while (k < hi) {
11805 var mid = k + hi >>> 1;
11806 if (sums[mid] < valueTarget) k = mid + 1;
11807 else hi = mid;
11808 }
11809
11810 if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
11811
11812 var valueLeft = sums[k] - valueOffset,
11813 valueRight = value - valueLeft;
11814
11815 if ((x1 - x0) > (y1 - y0)) {
11816 var xk = (x0 * valueRight + x1 * valueLeft) / value;
11817 partition(i, k, valueLeft, x0, y0, xk, y1);
11818 partition(k, j, valueRight, xk, y0, x1, y1);
11819 } else {
11820 var yk = (y0 * valueRight + y1 * valueLeft) / value;
11821 partition(i, k, valueLeft, x0, y0, x1, yk);
11822 partition(k, j, valueRight, x0, yk, x1, y1);
11823 }
11824 }
11825}
11826
11827function sliceDice(parent, x0, y0, x1, y1) {
11828 (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
11829}
11830
11831var resquarify = (function custom(ratio) {
11832
11833 function resquarify(parent, x0, y0, x1, y1) {
11834 if ((rows = parent._squarify) && (rows.ratio === ratio)) {
11835 var rows,
11836 row,
11837 nodes,
11838 i,
11839 j = -1,
11840 n,
11841 m = rows.length,
11842 value = parent.value;
11843
11844 while (++j < m) {
11845 row = rows[j], nodes = row.children;
11846 for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
11847 if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
11848 else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
11849 value -= row.value;
11850 }
11851 } else {
11852 parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
11853 rows.ratio = ratio;
11854 }
11855 }
11856
11857 resquarify.ratio = function(x) {
11858 return custom((x = +x) > 1 ? x : 1);
11859 };
11860
11861 return resquarify;
11862})(phi);
11863
11864function area$2(polygon) {
11865 var i = -1,
11866 n = polygon.length,
11867 a,
11868 b = polygon[n - 1],
11869 area = 0;
11870
11871 while (++i < n) {
11872 a = b;
11873 b = polygon[i];
11874 area += a[1] * b[0] - a[0] * b[1];
11875 }
11876
11877 return area / 2;
11878}
11879
11880function centroid$1(polygon) {
11881 var i = -1,
11882 n = polygon.length,
11883 x = 0,
11884 y = 0,
11885 a,
11886 b = polygon[n - 1],
11887 c,
11888 k = 0;
11889
11890 while (++i < n) {
11891 a = b;
11892 b = polygon[i];
11893 k += c = a[0] * b[1] - b[0] * a[1];
11894 x += (a[0] + b[0]) * c;
11895 y += (a[1] + b[1]) * c;
11896 }
11897
11898 return k *= 3, [x / k, y / k];
11899}
11900
11901// Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
11902// the 3D cross product in a quadrant I Cartesian coordinate system (+x is
11903// right, +y is up). Returns a positive value if ABC is counter-clockwise,
11904// negative if clockwise, and zero if the points are collinear.
11905function cross$1(a, b, c) {
11906 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
11907}
11908
11909function lexicographicOrder(a, b) {
11910 return a[0] - b[0] || a[1] - b[1];
11911}
11912
11913// Computes the upper convex hull per the monotone chain algorithm.
11914// Assumes points.length >= 3, is sorted by x, unique in y.
11915// Returns an array of indices into points in left-to-right order.
11916function computeUpperHullIndexes(points) {
11917 var n = points.length,
11918 indexes = [0, 1],
11919 size = 2;
11920
11921 for (var i = 2; i < n; ++i) {
11922 while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
11923 indexes[size++] = i;
11924 }
11925
11926 return indexes.slice(0, size); // remove popped points
11927}
11928
11929function hull(points) {
11930 if ((n = points.length) < 3) return null;
11931
11932 var i,
11933 n,
11934 sortedPoints = new Array(n),
11935 flippedPoints = new Array(n);
11936
11937 for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
11938 sortedPoints.sort(lexicographicOrder);
11939 for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
11940
11941 var upperIndexes = computeUpperHullIndexes(sortedPoints),
11942 lowerIndexes = computeUpperHullIndexes(flippedPoints);
11943
11944 // Construct the hull polygon, removing possible duplicate endpoints.
11945 var skipLeft = lowerIndexes[0] === upperIndexes[0],
11946 skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
11947 hull = [];
11948
11949 // Add upper hull in right-to-l order.
11950 // Then add lower hull in left-to-right order.
11951 for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
11952 for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
11953
11954 return hull;
11955}
11956
11957function contains$2(polygon, point) {
11958 var n = polygon.length,
11959 p = polygon[n - 1],
11960 x = point[0], y = point[1],
11961 x0 = p[0], y0 = p[1],
11962 x1, y1,
11963 inside = false;
11964
11965 for (var i = 0; i < n; ++i) {
11966 p = polygon[i], x1 = p[0], y1 = p[1];
11967 if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
11968 x0 = x1, y0 = y1;
11969 }
11970
11971 return inside;
11972}
11973
11974function length$2(polygon) {
11975 var i = -1,
11976 n = polygon.length,
11977 b = polygon[n - 1],
11978 xa,
11979 ya,
11980 xb = b[0],
11981 yb = b[1],
11982 perimeter = 0;
11983
11984 while (++i < n) {
11985 xa = xb;
11986 ya = yb;
11987 b = polygon[i];
11988 xb = b[0];
11989 yb = b[1];
11990 xa -= xb;
11991 ya -= yb;
11992 perimeter += Math.sqrt(xa * xa + ya * ya);
11993 }
11994
11995 return perimeter;
11996}
11997
11998function defaultSource$1() {
11999 return Math.random();
12000}
12001
12002var uniform = (function sourceRandomUniform(source) {
12003 function randomUniform(min, max) {
12004 min = min == null ? 0 : +min;
12005 max = max == null ? 1 : +max;
12006 if (arguments.length === 1) max = min, min = 0;
12007 else max -= min;
12008 return function() {
12009 return source() * max + min;
12010 };
12011 }
12012
12013 randomUniform.source = sourceRandomUniform;
12014
12015 return randomUniform;
12016})(defaultSource$1);
12017
12018var normal = (function sourceRandomNormal(source) {
12019 function randomNormal(mu, sigma) {
12020 var x, r;
12021 mu = mu == null ? 0 : +mu;
12022 sigma = sigma == null ? 1 : +sigma;
12023 return function() {
12024 var y;
12025
12026 // If available, use the second previously-generated uniform random.
12027 if (x != null) y = x, x = null;
12028
12029 // Otherwise, generate a new x and y.
12030 else do {
12031 x = source() * 2 - 1;
12032 y = source() * 2 - 1;
12033 r = x * x + y * y;
12034 } while (!r || r > 1);
12035
12036 return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
12037 };
12038 }
12039
12040 randomNormal.source = sourceRandomNormal;
12041
12042 return randomNormal;
12043})(defaultSource$1);
12044
12045var logNormal = (function sourceRandomLogNormal(source) {
12046 function randomLogNormal() {
12047 var randomNormal = normal.source(source).apply(this, arguments);
12048 return function() {
12049 return Math.exp(randomNormal());
12050 };
12051 }
12052
12053 randomLogNormal.source = sourceRandomLogNormal;
12054
12055 return randomLogNormal;
12056})(defaultSource$1);
12057
12058var irwinHall = (function sourceRandomIrwinHall(source) {
12059 function randomIrwinHall(n) {
12060 return function() {
12061 for (var sum = 0, i = 0; i < n; ++i) sum += source();
12062 return sum;
12063 };
12064 }
12065
12066 randomIrwinHall.source = sourceRandomIrwinHall;
12067
12068 return randomIrwinHall;
12069})(defaultSource$1);
12070
12071var bates = (function sourceRandomBates(source) {
12072 function randomBates(n) {
12073 var randomIrwinHall = irwinHall.source(source)(n);
12074 return function() {
12075 return randomIrwinHall() / n;
12076 };
12077 }
12078
12079 randomBates.source = sourceRandomBates;
12080
12081 return randomBates;
12082})(defaultSource$1);
12083
12084var exponential$1 = (function sourceRandomExponential(source) {
12085 function randomExponential(lambda) {
12086 return function() {
12087 return -Math.log(1 - source()) / lambda;
12088 };
12089 }
12090
12091 randomExponential.source = sourceRandomExponential;
12092
12093 return randomExponential;
12094})(defaultSource$1);
12095
12096function initRange(domain, range) {
12097 switch (arguments.length) {
12098 case 0: break;
12099 case 1: this.range(domain); break;
12100 default: this.range(range).domain(domain); break;
12101 }
12102 return this;
12103}
12104
12105function initInterpolator(domain, interpolator) {
12106 switch (arguments.length) {
12107 case 0: break;
12108 case 1: this.interpolator(domain); break;
12109 default: this.interpolator(interpolator).domain(domain); break;
12110 }
12111 return this;
12112}
12113
12114var array$3 = Array.prototype;
12115
12116var map$3 = array$3.map;
12117var slice$5 = array$3.slice;
12118
12119var implicit = {name: "implicit"};
12120
12121function ordinal() {
12122 var index = map$1(),
12123 domain = [],
12124 range = [],
12125 unknown = implicit;
12126
12127 function scale(d) {
12128 var key = d + "", i = index.get(key);
12129 if (!i) {
12130 if (unknown !== implicit) return unknown;
12131 index.set(key, i = domain.push(d));
12132 }
12133 return range[(i - 1) % range.length];
12134 }
12135
12136 scale.domain = function(_) {
12137 if (!arguments.length) return domain.slice();
12138 domain = [], index = map$1();
12139 var i = -1, n = _.length, d, key;
12140 while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
12141 return scale;
12142 };
12143
12144 scale.range = function(_) {
12145 return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
12146 };
12147
12148 scale.unknown = function(_) {
12149 return arguments.length ? (unknown = _, scale) : unknown;
12150 };
12151
12152 scale.copy = function() {
12153 return ordinal(domain, range).unknown(unknown);
12154 };
12155
12156 initRange.apply(scale, arguments);
12157
12158 return scale;
12159}
12160
12161function band() {
12162 var scale = ordinal().unknown(undefined),
12163 domain = scale.domain,
12164 ordinalRange = scale.range,
12165 range = [0, 1],
12166 step,
12167 bandwidth,
12168 round = false,
12169 paddingInner = 0,
12170 paddingOuter = 0,
12171 align = 0.5;
12172
12173 delete scale.unknown;
12174
12175 function rescale() {
12176 var n = domain().length,
12177 reverse = range[1] < range[0],
12178 start = range[reverse - 0],
12179 stop = range[1 - reverse];
12180 step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
12181 if (round) step = Math.floor(step);
12182 start += (stop - start - step * (n - paddingInner)) * align;
12183 bandwidth = step * (1 - paddingInner);
12184 if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
12185 var values = sequence(n).map(function(i) { return start + step * i; });
12186 return ordinalRange(reverse ? values.reverse() : values);
12187 }
12188
12189 scale.domain = function(_) {
12190 return arguments.length ? (domain(_), rescale()) : domain();
12191 };
12192
12193 scale.range = function(_) {
12194 return arguments.length ? (range = [+_[0], +_[1]], rescale()) : range.slice();
12195 };
12196
12197 scale.rangeRound = function(_) {
12198 return range = [+_[0], +_[1]], round = true, rescale();
12199 };
12200
12201 scale.bandwidth = function() {
12202 return bandwidth;
12203 };
12204
12205 scale.step = function() {
12206 return step;
12207 };
12208
12209 scale.round = function(_) {
12210 return arguments.length ? (round = !!_, rescale()) : round;
12211 };
12212
12213 scale.padding = function(_) {
12214 return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
12215 };
12216
12217 scale.paddingInner = function(_) {
12218 return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
12219 };
12220
12221 scale.paddingOuter = function(_) {
12222 return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
12223 };
12224
12225 scale.align = function(_) {
12226 return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
12227 };
12228
12229 scale.copy = function() {
12230 return band(domain(), range)
12231 .round(round)
12232 .paddingInner(paddingInner)
12233 .paddingOuter(paddingOuter)
12234 .align(align);
12235 };
12236
12237 return initRange.apply(rescale(), arguments);
12238}
12239
12240function pointish(scale) {
12241 var copy = scale.copy;
12242
12243 scale.padding = scale.paddingOuter;
12244 delete scale.paddingInner;
12245 delete scale.paddingOuter;
12246
12247 scale.copy = function() {
12248 return pointish(copy());
12249 };
12250
12251 return scale;
12252}
12253
12254function point$1() {
12255 return pointish(band.apply(null, arguments).paddingInner(1));
12256}
12257
12258function constant$a(x) {
12259 return function() {
12260 return x;
12261 };
12262}
12263
12264function number$2(x) {
12265 return +x;
12266}
12267
12268var unit = [0, 1];
12269
12270function identity$6(x) {
12271 return x;
12272}
12273
12274function normalize(a, b) {
12275 return (b -= (a = +a))
12276 ? function(x) { return (x - a) / b; }
12277 : constant$a(isNaN(b) ? NaN : 0.5);
12278}
12279
12280function clamper(domain) {
12281 var a = domain[0], b = domain[domain.length - 1], t;
12282 if (a > b) t = a, a = b, b = t;
12283 return function(x) { return Math.max(a, Math.min(b, x)); };
12284}
12285
12286// normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
12287// interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
12288function bimap(domain, range, interpolate) {
12289 var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
12290 if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
12291 else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
12292 return function(x) { return r0(d0(x)); };
12293}
12294
12295function polymap(domain, range, interpolate) {
12296 var j = Math.min(domain.length, range.length) - 1,
12297 d = new Array(j),
12298 r = new Array(j),
12299 i = -1;
12300
12301 // Reverse descending domains.
12302 if (domain[j] < domain[0]) {
12303 domain = domain.slice().reverse();
12304 range = range.slice().reverse();
12305 }
12306
12307 while (++i < j) {
12308 d[i] = normalize(domain[i], domain[i + 1]);
12309 r[i] = interpolate(range[i], range[i + 1]);
12310 }
12311
12312 return function(x) {
12313 var i = bisectRight(domain, x, 1, j) - 1;
12314 return r[i](d[i](x));
12315 };
12316}
12317
12318function copy(source, target) {
12319 return target
12320 .domain(source.domain())
12321 .range(source.range())
12322 .interpolate(source.interpolate())
12323 .clamp(source.clamp())
12324 .unknown(source.unknown());
12325}
12326
12327function transformer$1() {
12328 var domain = unit,
12329 range = unit,
12330 interpolate = interpolateValue,
12331 transform,
12332 untransform,
12333 unknown,
12334 clamp = identity$6,
12335 piecewise,
12336 output,
12337 input;
12338
12339 function rescale() {
12340 piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
12341 output = input = null;
12342 return scale;
12343 }
12344
12345 function scale(x) {
12346 return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
12347 }
12348
12349 scale.invert = function(y) {
12350 return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
12351 };
12352
12353 scale.domain = function(_) {
12354 return arguments.length ? (domain = map$3.call(_, number$2), clamp === identity$6 || (clamp = clamper(domain)), rescale()) : domain.slice();
12355 };
12356
12357 scale.range = function(_) {
12358 return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12359 };
12360
12361 scale.rangeRound = function(_) {
12362 return range = slice$5.call(_), interpolate = interpolateRound, rescale();
12363 };
12364
12365 scale.clamp = function(_) {
12366 return arguments.length ? (clamp = _ ? clamper(domain) : identity$6, scale) : clamp !== identity$6;
12367 };
12368
12369 scale.interpolate = function(_) {
12370 return arguments.length ? (interpolate = _, rescale()) : interpolate;
12371 };
12372
12373 scale.unknown = function(_) {
12374 return arguments.length ? (unknown = _, scale) : unknown;
12375 };
12376
12377 return function(t, u) {
12378 transform = t, untransform = u;
12379 return rescale();
12380 };
12381}
12382
12383function continuous(transform, untransform) {
12384 return transformer$1()(transform, untransform);
12385}
12386
12387function tickFormat(start, stop, count, specifier) {
12388 var step = tickStep(start, stop, count),
12389 precision;
12390 specifier = formatSpecifier(specifier == null ? ",f" : specifier);
12391 switch (specifier.type) {
12392 case "s": {
12393 var value = Math.max(Math.abs(start), Math.abs(stop));
12394 if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
12395 return exports.formatPrefix(specifier, value);
12396 }
12397 case "":
12398 case "e":
12399 case "g":
12400 case "p":
12401 case "r": {
12402 if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
12403 break;
12404 }
12405 case "f":
12406 case "%": {
12407 if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
12408 break;
12409 }
12410 }
12411 return exports.format(specifier);
12412}
12413
12414function linearish(scale) {
12415 var domain = scale.domain;
12416
12417 scale.ticks = function(count) {
12418 var d = domain();
12419 return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
12420 };
12421
12422 scale.tickFormat = function(count, specifier) {
12423 var d = domain();
12424 return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
12425 };
12426
12427 scale.nice = function(count) {
12428 if (count == null) count = 10;
12429
12430 var d = domain(),
12431 i0 = 0,
12432 i1 = d.length - 1,
12433 start = d[i0],
12434 stop = d[i1],
12435 step;
12436
12437 if (stop < start) {
12438 step = start, start = stop, stop = step;
12439 step = i0, i0 = i1, i1 = step;
12440 }
12441
12442 step = tickIncrement(start, stop, count);
12443
12444 if (step > 0) {
12445 start = Math.floor(start / step) * step;
12446 stop = Math.ceil(stop / step) * step;
12447 step = tickIncrement(start, stop, count);
12448 } else if (step < 0) {
12449 start = Math.ceil(start * step) / step;
12450 stop = Math.floor(stop * step) / step;
12451 step = tickIncrement(start, stop, count);
12452 }
12453
12454 if (step > 0) {
12455 d[i0] = Math.floor(start / step) * step;
12456 d[i1] = Math.ceil(stop / step) * step;
12457 domain(d);
12458 } else if (step < 0) {
12459 d[i0] = Math.ceil(start * step) / step;
12460 d[i1] = Math.floor(stop * step) / step;
12461 domain(d);
12462 }
12463
12464 return scale;
12465 };
12466
12467 return scale;
12468}
12469
12470function linear$2() {
12471 var scale = continuous(identity$6, identity$6);
12472
12473 scale.copy = function() {
12474 return copy(scale, linear$2());
12475 };
12476
12477 initRange.apply(scale, arguments);
12478
12479 return linearish(scale);
12480}
12481
12482function identity$7(domain) {
12483 var unknown;
12484
12485 function scale(x) {
12486 return isNaN(x = +x) ? unknown : x;
12487 }
12488
12489 scale.invert = scale;
12490
12491 scale.domain = scale.range = function(_) {
12492 return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
12493 };
12494
12495 scale.unknown = function(_) {
12496 return arguments.length ? (unknown = _, scale) : unknown;
12497 };
12498
12499 scale.copy = function() {
12500 return identity$7(domain).unknown(unknown);
12501 };
12502
12503 domain = arguments.length ? map$3.call(domain, number$2) : [0, 1];
12504
12505 return linearish(scale);
12506}
12507
12508function nice(domain, interval) {
12509 domain = domain.slice();
12510
12511 var i0 = 0,
12512 i1 = domain.length - 1,
12513 x0 = domain[i0],
12514 x1 = domain[i1],
12515 t;
12516
12517 if (x1 < x0) {
12518 t = i0, i0 = i1, i1 = t;
12519 t = x0, x0 = x1, x1 = t;
12520 }
12521
12522 domain[i0] = interval.floor(x0);
12523 domain[i1] = interval.ceil(x1);
12524 return domain;
12525}
12526
12527function transformLog(x) {
12528 return Math.log(x);
12529}
12530
12531function transformExp(x) {
12532 return Math.exp(x);
12533}
12534
12535function transformLogn(x) {
12536 return -Math.log(-x);
12537}
12538
12539function transformExpn(x) {
12540 return -Math.exp(-x);
12541}
12542
12543function pow10(x) {
12544 return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
12545}
12546
12547function powp(base) {
12548 return base === 10 ? pow10
12549 : base === Math.E ? Math.exp
12550 : function(x) { return Math.pow(base, x); };
12551}
12552
12553function logp(base) {
12554 return base === Math.E ? Math.log
12555 : base === 10 && Math.log10
12556 || base === 2 && Math.log2
12557 || (base = Math.log(base), function(x) { return Math.log(x) / base; });
12558}
12559
12560function reflect(f) {
12561 return function(x) {
12562 return -f(-x);
12563 };
12564}
12565
12566function loggish(transform) {
12567 var scale = transform(transformLog, transformExp),
12568 domain = scale.domain,
12569 base = 10,
12570 logs,
12571 pows;
12572
12573 function rescale() {
12574 logs = logp(base), pows = powp(base);
12575 if (domain()[0] < 0) {
12576 logs = reflect(logs), pows = reflect(pows);
12577 transform(transformLogn, transformExpn);
12578 } else {
12579 transform(transformLog, transformExp);
12580 }
12581 return scale;
12582 }
12583
12584 scale.base = function(_) {
12585 return arguments.length ? (base = +_, rescale()) : base;
12586 };
12587
12588 scale.domain = function(_) {
12589 return arguments.length ? (domain(_), rescale()) : domain();
12590 };
12591
12592 scale.ticks = function(count) {
12593 var d = domain(),
12594 u = d[0],
12595 v = d[d.length - 1],
12596 r;
12597
12598 if (r = v < u) i = u, u = v, v = i;
12599
12600 var i = logs(u),
12601 j = logs(v),
12602 p,
12603 k,
12604 t,
12605 n = count == null ? 10 : +count,
12606 z = [];
12607
12608 if (!(base % 1) && j - i < n) {
12609 i = Math.round(i) - 1, j = Math.round(j) + 1;
12610 if (u > 0) for (; i < j; ++i) {
12611 for (k = 1, p = pows(i); k < base; ++k) {
12612 t = p * k;
12613 if (t < u) continue;
12614 if (t > v) break;
12615 z.push(t);
12616 }
12617 } else for (; i < j; ++i) {
12618 for (k = base - 1, p = pows(i); k >= 1; --k) {
12619 t = p * k;
12620 if (t < u) continue;
12621 if (t > v) break;
12622 z.push(t);
12623 }
12624 }
12625 } else {
12626 z = ticks(i, j, Math.min(j - i, n)).map(pows);
12627 }
12628
12629 return r ? z.reverse() : z;
12630 };
12631
12632 scale.tickFormat = function(count, specifier) {
12633 if (specifier == null) specifier = base === 10 ? ".0e" : ",";
12634 if (typeof specifier !== "function") specifier = exports.format(specifier);
12635 if (count === Infinity) return specifier;
12636 if (count == null) count = 10;
12637 var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
12638 return function(d) {
12639 var i = d / pows(Math.round(logs(d)));
12640 if (i * base < base - 0.5) i *= base;
12641 return i <= k ? specifier(d) : "";
12642 };
12643 };
12644
12645 scale.nice = function() {
12646 return domain(nice(domain(), {
12647 floor: function(x) { return pows(Math.floor(logs(x))); },
12648 ceil: function(x) { return pows(Math.ceil(logs(x))); }
12649 }));
12650 };
12651
12652 return scale;
12653}
12654
12655function log$1() {
12656 var scale = loggish(transformer$1()).domain([1, 10]);
12657
12658 scale.copy = function() {
12659 return copy(scale, log$1()).base(scale.base());
12660 };
12661
12662 initRange.apply(scale, arguments);
12663
12664 return scale;
12665}
12666
12667function transformSymlog(c) {
12668 return function(x) {
12669 return Math.sign(x) * Math.log1p(Math.abs(x / c));
12670 };
12671}
12672
12673function transformSymexp(c) {
12674 return function(x) {
12675 return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
12676 };
12677}
12678
12679function symlogish(transform) {
12680 var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
12681
12682 scale.constant = function(_) {
12683 return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
12684 };
12685
12686 return linearish(scale);
12687}
12688
12689function symlog() {
12690 var scale = symlogish(transformer$1());
12691
12692 scale.copy = function() {
12693 return copy(scale, symlog()).constant(scale.constant());
12694 };
12695
12696 return initRange.apply(scale, arguments);
12697}
12698
12699function transformPow(exponent) {
12700 return function(x) {
12701 return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
12702 };
12703}
12704
12705function transformSqrt(x) {
12706 return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
12707}
12708
12709function transformSquare(x) {
12710 return x < 0 ? -x * x : x * x;
12711}
12712
12713function powish(transform) {
12714 var scale = transform(identity$6, identity$6),
12715 exponent = 1;
12716
12717 function rescale() {
12718 return exponent === 1 ? transform(identity$6, identity$6)
12719 : exponent === 0.5 ? transform(transformSqrt, transformSquare)
12720 : transform(transformPow(exponent), transformPow(1 / exponent));
12721 }
12722
12723 scale.exponent = function(_) {
12724 return arguments.length ? (exponent = +_, rescale()) : exponent;
12725 };
12726
12727 return linearish(scale);
12728}
12729
12730function pow$1() {
12731 var scale = powish(transformer$1());
12732
12733 scale.copy = function() {
12734 return copy(scale, pow$1()).exponent(scale.exponent());
12735 };
12736
12737 initRange.apply(scale, arguments);
12738
12739 return scale;
12740}
12741
12742function sqrt$1() {
12743 return pow$1.apply(null, arguments).exponent(0.5);
12744}
12745
12746function quantile() {
12747 var domain = [],
12748 range = [],
12749 thresholds = [],
12750 unknown;
12751
12752 function rescale() {
12753 var i = 0, n = Math.max(1, range.length);
12754 thresholds = new Array(n - 1);
12755 while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
12756 return scale;
12757 }
12758
12759 function scale(x) {
12760 return isNaN(x = +x) ? unknown : range[bisectRight(thresholds, x)];
12761 }
12762
12763 scale.invertExtent = function(y) {
12764 var i = range.indexOf(y);
12765 return i < 0 ? [NaN, NaN] : [
12766 i > 0 ? thresholds[i - 1] : domain[0],
12767 i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
12768 ];
12769 };
12770
12771 scale.domain = function(_) {
12772 if (!arguments.length) return domain.slice();
12773 domain = [];
12774 for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
12775 domain.sort(ascending);
12776 return rescale();
12777 };
12778
12779 scale.range = function(_) {
12780 return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12781 };
12782
12783 scale.unknown = function(_) {
12784 return arguments.length ? (unknown = _, scale) : unknown;
12785 };
12786
12787 scale.quantiles = function() {
12788 return thresholds.slice();
12789 };
12790
12791 scale.copy = function() {
12792 return quantile()
12793 .domain(domain)
12794 .range(range)
12795 .unknown(unknown);
12796 };
12797
12798 return initRange.apply(scale, arguments);
12799}
12800
12801function quantize$1() {
12802 var x0 = 0,
12803 x1 = 1,
12804 n = 1,
12805 domain = [0.5],
12806 range = [0, 1],
12807 unknown;
12808
12809 function scale(x) {
12810 return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
12811 }
12812
12813 function rescale() {
12814 var i = -1;
12815 domain = new Array(n);
12816 while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
12817 return scale;
12818 }
12819
12820 scale.domain = function(_) {
12821 return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
12822 };
12823
12824 scale.range = function(_) {
12825 return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
12826 };
12827
12828 scale.invertExtent = function(y) {
12829 var i = range.indexOf(y);
12830 return i < 0 ? [NaN, NaN]
12831 : i < 1 ? [x0, domain[0]]
12832 : i >= n ? [domain[n - 1], x1]
12833 : [domain[i - 1], domain[i]];
12834 };
12835
12836 scale.unknown = function(_) {
12837 return arguments.length ? (unknown = _, scale) : scale;
12838 };
12839
12840 scale.thresholds = function() {
12841 return domain.slice();
12842 };
12843
12844 scale.copy = function() {
12845 return quantize$1()
12846 .domain([x0, x1])
12847 .range(range)
12848 .unknown(unknown);
12849 };
12850
12851 return initRange.apply(linearish(scale), arguments);
12852}
12853
12854function threshold$1() {
12855 var domain = [0.5],
12856 range = [0, 1],
12857 unknown,
12858 n = 1;
12859
12860 function scale(x) {
12861 return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
12862 }
12863
12864 scale.domain = function(_) {
12865 return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
12866 };
12867
12868 scale.range = function(_) {
12869 return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
12870 };
12871
12872 scale.invertExtent = function(y) {
12873 var i = range.indexOf(y);
12874 return [domain[i - 1], domain[i]];
12875 };
12876
12877 scale.unknown = function(_) {
12878 return arguments.length ? (unknown = _, scale) : unknown;
12879 };
12880
12881 scale.copy = function() {
12882 return threshold$1()
12883 .domain(domain)
12884 .range(range)
12885 .unknown(unknown);
12886 };
12887
12888 return initRange.apply(scale, arguments);
12889}
12890
12891var t0$1 = new Date,
12892 t1$1 = new Date;
12893
12894function newInterval(floori, offseti, count, field) {
12895
12896 function interval(date) {
12897 return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
12898 }
12899
12900 interval.floor = function(date) {
12901 return floori(date = new Date(+date)), date;
12902 };
12903
12904 interval.ceil = function(date) {
12905 return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
12906 };
12907
12908 interval.round = function(date) {
12909 var d0 = interval(date),
12910 d1 = interval.ceil(date);
12911 return date - d0 < d1 - date ? d0 : d1;
12912 };
12913
12914 interval.offset = function(date, step) {
12915 return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
12916 };
12917
12918 interval.range = function(start, stop, step) {
12919 var range = [], previous;
12920 start = interval.ceil(start);
12921 step = step == null ? 1 : Math.floor(step);
12922 if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
12923 do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
12924 while (previous < start && start < stop);
12925 return range;
12926 };
12927
12928 interval.filter = function(test) {
12929 return newInterval(function(date) {
12930 if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
12931 }, function(date, step) {
12932 if (date >= date) {
12933 if (step < 0) while (++step <= 0) {
12934 while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
12935 } else while (--step >= 0) {
12936 while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
12937 }
12938 }
12939 });
12940 };
12941
12942 if (count) {
12943 interval.count = function(start, end) {
12944 t0$1.setTime(+start), t1$1.setTime(+end);
12945 floori(t0$1), floori(t1$1);
12946 return Math.floor(count(t0$1, t1$1));
12947 };
12948
12949 interval.every = function(step) {
12950 step = Math.floor(step);
12951 return !isFinite(step) || !(step > 0) ? null
12952 : !(step > 1) ? interval
12953 : interval.filter(field
12954 ? function(d) { return field(d) % step === 0; }
12955 : function(d) { return interval.count(0, d) % step === 0; });
12956 };
12957 }
12958
12959 return interval;
12960}
12961
12962var millisecond = newInterval(function() {
12963 // noop
12964}, function(date, step) {
12965 date.setTime(+date + step);
12966}, function(start, end) {
12967 return end - start;
12968});
12969
12970// An optimized implementation for this simple case.
12971millisecond.every = function(k) {
12972 k = Math.floor(k);
12973 if (!isFinite(k) || !(k > 0)) return null;
12974 if (!(k > 1)) return millisecond;
12975 return newInterval(function(date) {
12976 date.setTime(Math.floor(date / k) * k);
12977 }, function(date, step) {
12978 date.setTime(+date + step * k);
12979 }, function(start, end) {
12980 return (end - start) / k;
12981 });
12982};
12983var milliseconds = millisecond.range;
12984
12985var durationSecond = 1e3;
12986var durationMinute = 6e4;
12987var durationHour = 36e5;
12988var durationDay = 864e5;
12989var durationWeek = 6048e5;
12990
12991var second = newInterval(function(date) {
12992 date.setTime(date - date.getMilliseconds());
12993}, function(date, step) {
12994 date.setTime(+date + step * durationSecond);
12995}, function(start, end) {
12996 return (end - start) / durationSecond;
12997}, function(date) {
12998 return date.getUTCSeconds();
12999});
13000var seconds = second.range;
13001
13002var minute = newInterval(function(date) {
13003 date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
13004}, function(date, step) {
13005 date.setTime(+date + step * durationMinute);
13006}, function(start, end) {
13007 return (end - start) / durationMinute;
13008}, function(date) {
13009 return date.getMinutes();
13010});
13011var minutes = minute.range;
13012
13013var hour = newInterval(function(date) {
13014 date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
13015}, function(date, step) {
13016 date.setTime(+date + step * durationHour);
13017}, function(start, end) {
13018 return (end - start) / durationHour;
13019}, function(date) {
13020 return date.getHours();
13021});
13022var hours = hour.range;
13023
13024var day = newInterval(function(date) {
13025 date.setHours(0, 0, 0, 0);
13026}, function(date, step) {
13027 date.setDate(date.getDate() + step);
13028}, function(start, end) {
13029 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
13030}, function(date) {
13031 return date.getDate() - 1;
13032});
13033var days = day.range;
13034
13035function weekday(i) {
13036 return newInterval(function(date) {
13037 date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
13038 date.setHours(0, 0, 0, 0);
13039 }, function(date, step) {
13040 date.setDate(date.getDate() + step * 7);
13041 }, function(start, end) {
13042 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
13043 });
13044}
13045
13046var sunday = weekday(0);
13047var monday = weekday(1);
13048var tuesday = weekday(2);
13049var wednesday = weekday(3);
13050var thursday = weekday(4);
13051var friday = weekday(5);
13052var saturday = weekday(6);
13053
13054var sundays = sunday.range;
13055var mondays = monday.range;
13056var tuesdays = tuesday.range;
13057var wednesdays = wednesday.range;
13058var thursdays = thursday.range;
13059var fridays = friday.range;
13060var saturdays = saturday.range;
13061
13062var month = newInterval(function(date) {
13063 date.setDate(1);
13064 date.setHours(0, 0, 0, 0);
13065}, function(date, step) {
13066 date.setMonth(date.getMonth() + step);
13067}, function(start, end) {
13068 return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
13069}, function(date) {
13070 return date.getMonth();
13071});
13072var months = month.range;
13073
13074var year = newInterval(function(date) {
13075 date.setMonth(0, 1);
13076 date.setHours(0, 0, 0, 0);
13077}, function(date, step) {
13078 date.setFullYear(date.getFullYear() + step);
13079}, function(start, end) {
13080 return end.getFullYear() - start.getFullYear();
13081}, function(date) {
13082 return date.getFullYear();
13083});
13084
13085// An optimized implementation for this simple case.
13086year.every = function(k) {
13087 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
13088 date.setFullYear(Math.floor(date.getFullYear() / k) * k);
13089 date.setMonth(0, 1);
13090 date.setHours(0, 0, 0, 0);
13091 }, function(date, step) {
13092 date.setFullYear(date.getFullYear() + step * k);
13093 });
13094};
13095var years = year.range;
13096
13097var utcMinute = newInterval(function(date) {
13098 date.setUTCSeconds(0, 0);
13099}, function(date, step) {
13100 date.setTime(+date + step * durationMinute);
13101}, function(start, end) {
13102 return (end - start) / durationMinute;
13103}, function(date) {
13104 return date.getUTCMinutes();
13105});
13106var utcMinutes = utcMinute.range;
13107
13108var utcHour = newInterval(function(date) {
13109 date.setUTCMinutes(0, 0, 0);
13110}, function(date, step) {
13111 date.setTime(+date + step * durationHour);
13112}, function(start, end) {
13113 return (end - start) / durationHour;
13114}, function(date) {
13115 return date.getUTCHours();
13116});
13117var utcHours = utcHour.range;
13118
13119var utcDay = newInterval(function(date) {
13120 date.setUTCHours(0, 0, 0, 0);
13121}, function(date, step) {
13122 date.setUTCDate(date.getUTCDate() + step);
13123}, function(start, end) {
13124 return (end - start) / durationDay;
13125}, function(date) {
13126 return date.getUTCDate() - 1;
13127});
13128var utcDays = utcDay.range;
13129
13130function utcWeekday(i) {
13131 return newInterval(function(date) {
13132 date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
13133 date.setUTCHours(0, 0, 0, 0);
13134 }, function(date, step) {
13135 date.setUTCDate(date.getUTCDate() + step * 7);
13136 }, function(start, end) {
13137 return (end - start) / durationWeek;
13138 });
13139}
13140
13141var utcSunday = utcWeekday(0);
13142var utcMonday = utcWeekday(1);
13143var utcTuesday = utcWeekday(2);
13144var utcWednesday = utcWeekday(3);
13145var utcThursday = utcWeekday(4);
13146var utcFriday = utcWeekday(5);
13147var utcSaturday = utcWeekday(6);
13148
13149var utcSundays = utcSunday.range;
13150var utcMondays = utcMonday.range;
13151var utcTuesdays = utcTuesday.range;
13152var utcWednesdays = utcWednesday.range;
13153var utcThursdays = utcThursday.range;
13154var utcFridays = utcFriday.range;
13155var utcSaturdays = utcSaturday.range;
13156
13157var utcMonth = newInterval(function(date) {
13158 date.setUTCDate(1);
13159 date.setUTCHours(0, 0, 0, 0);
13160}, function(date, step) {
13161 date.setUTCMonth(date.getUTCMonth() + step);
13162}, function(start, end) {
13163 return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
13164}, function(date) {
13165 return date.getUTCMonth();
13166});
13167var utcMonths = utcMonth.range;
13168
13169var utcYear = newInterval(function(date) {
13170 date.setUTCMonth(0, 1);
13171 date.setUTCHours(0, 0, 0, 0);
13172}, function(date, step) {
13173 date.setUTCFullYear(date.getUTCFullYear() + step);
13174}, function(start, end) {
13175 return end.getUTCFullYear() - start.getUTCFullYear();
13176}, function(date) {
13177 return date.getUTCFullYear();
13178});
13179
13180// An optimized implementation for this simple case.
13181utcYear.every = function(k) {
13182 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
13183 date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
13184 date.setUTCMonth(0, 1);
13185 date.setUTCHours(0, 0, 0, 0);
13186 }, function(date, step) {
13187 date.setUTCFullYear(date.getUTCFullYear() + step * k);
13188 });
13189};
13190var utcYears = utcYear.range;
13191
13192function localDate(d) {
13193 if (0 <= d.y && d.y < 100) {
13194 var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
13195 date.setFullYear(d.y);
13196 return date;
13197 }
13198 return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
13199}
13200
13201function utcDate(d) {
13202 if (0 <= d.y && d.y < 100) {
13203 var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
13204 date.setUTCFullYear(d.y);
13205 return date;
13206 }
13207 return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
13208}
13209
13210function newDate(y, m, d) {
13211 return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
13212}
13213
13214function formatLocale$1(locale) {
13215 var locale_dateTime = locale.dateTime,
13216 locale_date = locale.date,
13217 locale_time = locale.time,
13218 locale_periods = locale.periods,
13219 locale_weekdays = locale.days,
13220 locale_shortWeekdays = locale.shortDays,
13221 locale_months = locale.months,
13222 locale_shortMonths = locale.shortMonths;
13223
13224 var periodRe = formatRe(locale_periods),
13225 periodLookup = formatLookup(locale_periods),
13226 weekdayRe = formatRe(locale_weekdays),
13227 weekdayLookup = formatLookup(locale_weekdays),
13228 shortWeekdayRe = formatRe(locale_shortWeekdays),
13229 shortWeekdayLookup = formatLookup(locale_shortWeekdays),
13230 monthRe = formatRe(locale_months),
13231 monthLookup = formatLookup(locale_months),
13232 shortMonthRe = formatRe(locale_shortMonths),
13233 shortMonthLookup = formatLookup(locale_shortMonths);
13234
13235 var formats = {
13236 "a": formatShortWeekday,
13237 "A": formatWeekday,
13238 "b": formatShortMonth,
13239 "B": formatMonth,
13240 "c": null,
13241 "d": formatDayOfMonth,
13242 "e": formatDayOfMonth,
13243 "f": formatMicroseconds,
13244 "H": formatHour24,
13245 "I": formatHour12,
13246 "j": formatDayOfYear,
13247 "L": formatMilliseconds,
13248 "m": formatMonthNumber,
13249 "M": formatMinutes,
13250 "p": formatPeriod,
13251 "q": formatQuarter,
13252 "Q": formatUnixTimestamp,
13253 "s": formatUnixTimestampSeconds,
13254 "S": formatSeconds,
13255 "u": formatWeekdayNumberMonday,
13256 "U": formatWeekNumberSunday,
13257 "V": formatWeekNumberISO,
13258 "w": formatWeekdayNumberSunday,
13259 "W": formatWeekNumberMonday,
13260 "x": null,
13261 "X": null,
13262 "y": formatYear$1,
13263 "Y": formatFullYear,
13264 "Z": formatZone,
13265 "%": formatLiteralPercent
13266 };
13267
13268 var utcFormats = {
13269 "a": formatUTCShortWeekday,
13270 "A": formatUTCWeekday,
13271 "b": formatUTCShortMonth,
13272 "B": formatUTCMonth,
13273 "c": null,
13274 "d": formatUTCDayOfMonth,
13275 "e": formatUTCDayOfMonth,
13276 "f": formatUTCMicroseconds,
13277 "H": formatUTCHour24,
13278 "I": formatUTCHour12,
13279 "j": formatUTCDayOfYear,
13280 "L": formatUTCMilliseconds,
13281 "m": formatUTCMonthNumber,
13282 "M": formatUTCMinutes,
13283 "p": formatUTCPeriod,
13284 "q": formatUTCQuarter,
13285 "Q": formatUnixTimestamp,
13286 "s": formatUnixTimestampSeconds,
13287 "S": formatUTCSeconds,
13288 "u": formatUTCWeekdayNumberMonday,
13289 "U": formatUTCWeekNumberSunday,
13290 "V": formatUTCWeekNumberISO,
13291 "w": formatUTCWeekdayNumberSunday,
13292 "W": formatUTCWeekNumberMonday,
13293 "x": null,
13294 "X": null,
13295 "y": formatUTCYear,
13296 "Y": formatUTCFullYear,
13297 "Z": formatUTCZone,
13298 "%": formatLiteralPercent
13299 };
13300
13301 var parses = {
13302 "a": parseShortWeekday,
13303 "A": parseWeekday,
13304 "b": parseShortMonth,
13305 "B": parseMonth,
13306 "c": parseLocaleDateTime,
13307 "d": parseDayOfMonth,
13308 "e": parseDayOfMonth,
13309 "f": parseMicroseconds,
13310 "H": parseHour24,
13311 "I": parseHour24,
13312 "j": parseDayOfYear,
13313 "L": parseMilliseconds,
13314 "m": parseMonthNumber,
13315 "M": parseMinutes,
13316 "p": parsePeriod,
13317 "q": parseQuarter,
13318 "Q": parseUnixTimestamp,
13319 "s": parseUnixTimestampSeconds,
13320 "S": parseSeconds,
13321 "u": parseWeekdayNumberMonday,
13322 "U": parseWeekNumberSunday,
13323 "V": parseWeekNumberISO,
13324 "w": parseWeekdayNumberSunday,
13325 "W": parseWeekNumberMonday,
13326 "x": parseLocaleDate,
13327 "X": parseLocaleTime,
13328 "y": parseYear,
13329 "Y": parseFullYear,
13330 "Z": parseZone,
13331 "%": parseLiteralPercent
13332 };
13333
13334 // These recursive directive definitions must be deferred.
13335 formats.x = newFormat(locale_date, formats);
13336 formats.X = newFormat(locale_time, formats);
13337 formats.c = newFormat(locale_dateTime, formats);
13338 utcFormats.x = newFormat(locale_date, utcFormats);
13339 utcFormats.X = newFormat(locale_time, utcFormats);
13340 utcFormats.c = newFormat(locale_dateTime, utcFormats);
13341
13342 function newFormat(specifier, formats) {
13343 return function(date) {
13344 var string = [],
13345 i = -1,
13346 j = 0,
13347 n = specifier.length,
13348 c,
13349 pad,
13350 format;
13351
13352 if (!(date instanceof Date)) date = new Date(+date);
13353
13354 while (++i < n) {
13355 if (specifier.charCodeAt(i) === 37) {
13356 string.push(specifier.slice(j, i));
13357 if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
13358 else pad = c === "e" ? " " : "0";
13359 if (format = formats[c]) c = format(date, pad);
13360 string.push(c);
13361 j = i + 1;
13362 }
13363 }
13364
13365 string.push(specifier.slice(j, i));
13366 return string.join("");
13367 };
13368 }
13369
13370 function newParse(specifier, Z) {
13371 return function(string) {
13372 var d = newDate(1900, undefined, 1),
13373 i = parseSpecifier(d, specifier, string += "", 0),
13374 week, day$1;
13375 if (i != string.length) return null;
13376
13377 // If a UNIX timestamp is specified, return it.
13378 if ("Q" in d) return new Date(d.Q);
13379 if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
13380
13381 // If this is utcParse, never use the local timezone.
13382 if (Z && !("Z" in d)) d.Z = 0;
13383
13384 // The am-pm flag is 0 for AM, and 1 for PM.
13385 if ("p" in d) d.H = d.H % 12 + d.p * 12;
13386
13387 // If the month was not specified, inherit from the quarter.
13388 if (d.m === undefined) d.m = "q" in d ? d.q : 0;
13389
13390 // Convert day-of-week and week-of-year to day-of-year.
13391 if ("V" in d) {
13392 if (d.V < 1 || d.V > 53) return null;
13393 if (!("w" in d)) d.w = 1;
13394 if ("Z" in d) {
13395 week = utcDate(newDate(d.y, 0, 1)), day$1 = week.getUTCDay();
13396 week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
13397 week = utcDay.offset(week, (d.V - 1) * 7);
13398 d.y = week.getUTCFullYear();
13399 d.m = week.getUTCMonth();
13400 d.d = week.getUTCDate() + (d.w + 6) % 7;
13401 } else {
13402 week = localDate(newDate(d.y, 0, 1)), day$1 = week.getDay();
13403 week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
13404 week = day.offset(week, (d.V - 1) * 7);
13405 d.y = week.getFullYear();
13406 d.m = week.getMonth();
13407 d.d = week.getDate() + (d.w + 6) % 7;
13408 }
13409 } else if ("W" in d || "U" in d) {
13410 if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
13411 day$1 = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
13412 d.m = 0;
13413 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;
13414 }
13415
13416 // If a time zone is specified, all fields are interpreted as UTC and then
13417 // offset according to the specified time zone.
13418 if ("Z" in d) {
13419 d.H += d.Z / 100 | 0;
13420 d.M += d.Z % 100;
13421 return utcDate(d);
13422 }
13423
13424 // Otherwise, all fields are in local time.
13425 return localDate(d);
13426 };
13427 }
13428
13429 function parseSpecifier(d, specifier, string, j) {
13430 var i = 0,
13431 n = specifier.length,
13432 m = string.length,
13433 c,
13434 parse;
13435
13436 while (i < n) {
13437 if (j >= m) return -1;
13438 c = specifier.charCodeAt(i++);
13439 if (c === 37) {
13440 c = specifier.charAt(i++);
13441 parse = parses[c in pads ? specifier.charAt(i++) : c];
13442 if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
13443 } else if (c != string.charCodeAt(j++)) {
13444 return -1;
13445 }
13446 }
13447
13448 return j;
13449 }
13450
13451 function parsePeriod(d, string, i) {
13452 var n = periodRe.exec(string.slice(i));
13453 return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13454 }
13455
13456 function parseShortWeekday(d, string, i) {
13457 var n = shortWeekdayRe.exec(string.slice(i));
13458 return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13459 }
13460
13461 function parseWeekday(d, string, i) {
13462 var n = weekdayRe.exec(string.slice(i));
13463 return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13464 }
13465
13466 function parseShortMonth(d, string, i) {
13467 var n = shortMonthRe.exec(string.slice(i));
13468 return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13469 }
13470
13471 function parseMonth(d, string, i) {
13472 var n = monthRe.exec(string.slice(i));
13473 return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13474 }
13475
13476 function parseLocaleDateTime(d, string, i) {
13477 return parseSpecifier(d, locale_dateTime, string, i);
13478 }
13479
13480 function parseLocaleDate(d, string, i) {
13481 return parseSpecifier(d, locale_date, string, i);
13482 }
13483
13484 function parseLocaleTime(d, string, i) {
13485 return parseSpecifier(d, locale_time, string, i);
13486 }
13487
13488 function formatShortWeekday(d) {
13489 return locale_shortWeekdays[d.getDay()];
13490 }
13491
13492 function formatWeekday(d) {
13493 return locale_weekdays[d.getDay()];
13494 }
13495
13496 function formatShortMonth(d) {
13497 return locale_shortMonths[d.getMonth()];
13498 }
13499
13500 function formatMonth(d) {
13501 return locale_months[d.getMonth()];
13502 }
13503
13504 function formatPeriod(d) {
13505 return locale_periods[+(d.getHours() >= 12)];
13506 }
13507
13508 function formatQuarter(d) {
13509 return 1 + ~~(d.getMonth() / 3);
13510 }
13511
13512 function formatUTCShortWeekday(d) {
13513 return locale_shortWeekdays[d.getUTCDay()];
13514 }
13515
13516 function formatUTCWeekday(d) {
13517 return locale_weekdays[d.getUTCDay()];
13518 }
13519
13520 function formatUTCShortMonth(d) {
13521 return locale_shortMonths[d.getUTCMonth()];
13522 }
13523
13524 function formatUTCMonth(d) {
13525 return locale_months[d.getUTCMonth()];
13526 }
13527
13528 function formatUTCPeriod(d) {
13529 return locale_periods[+(d.getUTCHours() >= 12)];
13530 }
13531
13532 function formatUTCQuarter(d) {
13533 return 1 + ~~(d.getUTCMonth() / 3);
13534 }
13535
13536 return {
13537 format: function(specifier) {
13538 var f = newFormat(specifier += "", formats);
13539 f.toString = function() { return specifier; };
13540 return f;
13541 },
13542 parse: function(specifier) {
13543 var p = newParse(specifier += "", false);
13544 p.toString = function() { return specifier; };
13545 return p;
13546 },
13547 utcFormat: function(specifier) {
13548 var f = newFormat(specifier += "", utcFormats);
13549 f.toString = function() { return specifier; };
13550 return f;
13551 },
13552 utcParse: function(specifier) {
13553 var p = newParse(specifier += "", true);
13554 p.toString = function() { return specifier; };
13555 return p;
13556 }
13557 };
13558}
13559
13560var pads = {"-": "", "_": " ", "0": "0"},
13561 numberRe = /^\s*\d+/, // note: ignores next directive
13562 percentRe = /^%/,
13563 requoteRe = /[\\^$*+?|[\]().{}]/g;
13564
13565function pad$1(value, fill, width) {
13566 var sign = value < 0 ? "-" : "",
13567 string = (sign ? -value : value) + "",
13568 length = string.length;
13569 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
13570}
13571
13572function requote(s) {
13573 return s.replace(requoteRe, "\\$&");
13574}
13575
13576function formatRe(names) {
13577 return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
13578}
13579
13580function formatLookup(names) {
13581 var map = {}, i = -1, n = names.length;
13582 while (++i < n) map[names[i].toLowerCase()] = i;
13583 return map;
13584}
13585
13586function parseWeekdayNumberSunday(d, string, i) {
13587 var n = numberRe.exec(string.slice(i, i + 1));
13588 return n ? (d.w = +n[0], i + n[0].length) : -1;
13589}
13590
13591function parseWeekdayNumberMonday(d, string, i) {
13592 var n = numberRe.exec(string.slice(i, i + 1));
13593 return n ? (d.u = +n[0], i + n[0].length) : -1;
13594}
13595
13596function parseWeekNumberSunday(d, string, i) {
13597 var n = numberRe.exec(string.slice(i, i + 2));
13598 return n ? (d.U = +n[0], i + n[0].length) : -1;
13599}
13600
13601function parseWeekNumberISO(d, string, i) {
13602 var n = numberRe.exec(string.slice(i, i + 2));
13603 return n ? (d.V = +n[0], i + n[0].length) : -1;
13604}
13605
13606function parseWeekNumberMonday(d, string, i) {
13607 var n = numberRe.exec(string.slice(i, i + 2));
13608 return n ? (d.W = +n[0], i + n[0].length) : -1;
13609}
13610
13611function parseFullYear(d, string, i) {
13612 var n = numberRe.exec(string.slice(i, i + 4));
13613 return n ? (d.y = +n[0], i + n[0].length) : -1;
13614}
13615
13616function parseYear(d, string, i) {
13617 var n = numberRe.exec(string.slice(i, i + 2));
13618 return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
13619}
13620
13621function parseZone(d, string, i) {
13622 var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
13623 return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
13624}
13625
13626function parseQuarter(d, string, i) {
13627 var n = numberRe.exec(string.slice(i, i + 1));
13628 return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
13629}
13630
13631function parseMonthNumber(d, string, i) {
13632 var n = numberRe.exec(string.slice(i, i + 2));
13633 return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
13634}
13635
13636function parseDayOfMonth(d, string, i) {
13637 var n = numberRe.exec(string.slice(i, i + 2));
13638 return n ? (d.d = +n[0], i + n[0].length) : -1;
13639}
13640
13641function parseDayOfYear(d, string, i) {
13642 var n = numberRe.exec(string.slice(i, i + 3));
13643 return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
13644}
13645
13646function parseHour24(d, string, i) {
13647 var n = numberRe.exec(string.slice(i, i + 2));
13648 return n ? (d.H = +n[0], i + n[0].length) : -1;
13649}
13650
13651function parseMinutes(d, string, i) {
13652 var n = numberRe.exec(string.slice(i, i + 2));
13653 return n ? (d.M = +n[0], i + n[0].length) : -1;
13654}
13655
13656function parseSeconds(d, string, i) {
13657 var n = numberRe.exec(string.slice(i, i + 2));
13658 return n ? (d.S = +n[0], i + n[0].length) : -1;
13659}
13660
13661function parseMilliseconds(d, string, i) {
13662 var n = numberRe.exec(string.slice(i, i + 3));
13663 return n ? (d.L = +n[0], i + n[0].length) : -1;
13664}
13665
13666function parseMicroseconds(d, string, i) {
13667 var n = numberRe.exec(string.slice(i, i + 6));
13668 return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
13669}
13670
13671function parseLiteralPercent(d, string, i) {
13672 var n = percentRe.exec(string.slice(i, i + 1));
13673 return n ? i + n[0].length : -1;
13674}
13675
13676function parseUnixTimestamp(d, string, i) {
13677 var n = numberRe.exec(string.slice(i));
13678 return n ? (d.Q = +n[0], i + n[0].length) : -1;
13679}
13680
13681function parseUnixTimestampSeconds(d, string, i) {
13682 var n = numberRe.exec(string.slice(i));
13683 return n ? (d.s = +n[0], i + n[0].length) : -1;
13684}
13685
13686function formatDayOfMonth(d, p) {
13687 return pad$1(d.getDate(), p, 2);
13688}
13689
13690function formatHour24(d, p) {
13691 return pad$1(d.getHours(), p, 2);
13692}
13693
13694function formatHour12(d, p) {
13695 return pad$1(d.getHours() % 12 || 12, p, 2);
13696}
13697
13698function formatDayOfYear(d, p) {
13699 return pad$1(1 + day.count(year(d), d), p, 3);
13700}
13701
13702function formatMilliseconds(d, p) {
13703 return pad$1(d.getMilliseconds(), p, 3);
13704}
13705
13706function formatMicroseconds(d, p) {
13707 return formatMilliseconds(d, p) + "000";
13708}
13709
13710function formatMonthNumber(d, p) {
13711 return pad$1(d.getMonth() + 1, p, 2);
13712}
13713
13714function formatMinutes(d, p) {
13715 return pad$1(d.getMinutes(), p, 2);
13716}
13717
13718function formatSeconds(d, p) {
13719 return pad$1(d.getSeconds(), p, 2);
13720}
13721
13722function formatWeekdayNumberMonday(d) {
13723 var day = d.getDay();
13724 return day === 0 ? 7 : day;
13725}
13726
13727function formatWeekNumberSunday(d, p) {
13728 return pad$1(sunday.count(year(d) - 1, d), p, 2);
13729}
13730
13731function formatWeekNumberISO(d, p) {
13732 var day = d.getDay();
13733 d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
13734 return pad$1(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
13735}
13736
13737function formatWeekdayNumberSunday(d) {
13738 return d.getDay();
13739}
13740
13741function formatWeekNumberMonday(d, p) {
13742 return pad$1(monday.count(year(d) - 1, d), p, 2);
13743}
13744
13745function formatYear$1(d, p) {
13746 return pad$1(d.getFullYear() % 100, p, 2);
13747}
13748
13749function formatFullYear(d, p) {
13750 return pad$1(d.getFullYear() % 10000, p, 4);
13751}
13752
13753function formatZone(d) {
13754 var z = d.getTimezoneOffset();
13755 return (z > 0 ? "-" : (z *= -1, "+"))
13756 + pad$1(z / 60 | 0, "0", 2)
13757 + pad$1(z % 60, "0", 2);
13758}
13759
13760function formatUTCDayOfMonth(d, p) {
13761 return pad$1(d.getUTCDate(), p, 2);
13762}
13763
13764function formatUTCHour24(d, p) {
13765 return pad$1(d.getUTCHours(), p, 2);
13766}
13767
13768function formatUTCHour12(d, p) {
13769 return pad$1(d.getUTCHours() % 12 || 12, p, 2);
13770}
13771
13772function formatUTCDayOfYear(d, p) {
13773 return pad$1(1 + utcDay.count(utcYear(d), d), p, 3);
13774}
13775
13776function formatUTCMilliseconds(d, p) {
13777 return pad$1(d.getUTCMilliseconds(), p, 3);
13778}
13779
13780function formatUTCMicroseconds(d, p) {
13781 return formatUTCMilliseconds(d, p) + "000";
13782}
13783
13784function formatUTCMonthNumber(d, p) {
13785 return pad$1(d.getUTCMonth() + 1, p, 2);
13786}
13787
13788function formatUTCMinutes(d, p) {
13789 return pad$1(d.getUTCMinutes(), p, 2);
13790}
13791
13792function formatUTCSeconds(d, p) {
13793 return pad$1(d.getUTCSeconds(), p, 2);
13794}
13795
13796function formatUTCWeekdayNumberMonday(d) {
13797 var dow = d.getUTCDay();
13798 return dow === 0 ? 7 : dow;
13799}
13800
13801function formatUTCWeekNumberSunday(d, p) {
13802 return pad$1(utcSunday.count(utcYear(d) - 1, d), p, 2);
13803}
13804
13805function formatUTCWeekNumberISO(d, p) {
13806 var day = d.getUTCDay();
13807 d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
13808 return pad$1(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
13809}
13810
13811function formatUTCWeekdayNumberSunday(d) {
13812 return d.getUTCDay();
13813}
13814
13815function formatUTCWeekNumberMonday(d, p) {
13816 return pad$1(utcMonday.count(utcYear(d) - 1, d), p, 2);
13817}
13818
13819function formatUTCYear(d, p) {
13820 return pad$1(d.getUTCFullYear() % 100, p, 2);
13821}
13822
13823function formatUTCFullYear(d, p) {
13824 return pad$1(d.getUTCFullYear() % 10000, p, 4);
13825}
13826
13827function formatUTCZone() {
13828 return "+0000";
13829}
13830
13831function formatLiteralPercent() {
13832 return "%";
13833}
13834
13835function formatUnixTimestamp(d) {
13836 return +d;
13837}
13838
13839function formatUnixTimestampSeconds(d) {
13840 return Math.floor(+d / 1000);
13841}
13842
13843var locale$1;
13844
13845defaultLocale$1({
13846 dateTime: "%x, %X",
13847 date: "%-m/%-d/%Y",
13848 time: "%-I:%M:%S %p",
13849 periods: ["AM", "PM"],
13850 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
13851 shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
13852 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
13853 shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
13854});
13855
13856function defaultLocale$1(definition) {
13857 locale$1 = formatLocale$1(definition);
13858 exports.timeFormat = locale$1.format;
13859 exports.timeParse = locale$1.parse;
13860 exports.utcFormat = locale$1.utcFormat;
13861 exports.utcParse = locale$1.utcParse;
13862 return locale$1;
13863}
13864
13865var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
13866
13867function formatIsoNative(date) {
13868 return date.toISOString();
13869}
13870
13871var formatIso = Date.prototype.toISOString
13872 ? formatIsoNative
13873 : exports.utcFormat(isoSpecifier);
13874
13875function parseIsoNative(string) {
13876 var date = new Date(string);
13877 return isNaN(date) ? null : date;
13878}
13879
13880var parseIso = +new Date("2000-01-01T00:00:00.000Z")
13881 ? parseIsoNative
13882 : exports.utcParse(isoSpecifier);
13883
13884var durationSecond$1 = 1000,
13885 durationMinute$1 = durationSecond$1 * 60,
13886 durationHour$1 = durationMinute$1 * 60,
13887 durationDay$1 = durationHour$1 * 24,
13888 durationWeek$1 = durationDay$1 * 7,
13889 durationMonth = durationDay$1 * 30,
13890 durationYear = durationDay$1 * 365;
13891
13892function date$1(t) {
13893 return new Date(t);
13894}
13895
13896function number$3(t) {
13897 return t instanceof Date ? +t : +new Date(+t);
13898}
13899
13900function calendar(year, month, week, day, hour, minute, second, millisecond, format) {
13901 var scale = continuous(identity$6, identity$6),
13902 invert = scale.invert,
13903 domain = scale.domain;
13904
13905 var formatMillisecond = format(".%L"),
13906 formatSecond = format(":%S"),
13907 formatMinute = format("%I:%M"),
13908 formatHour = format("%I %p"),
13909 formatDay = format("%a %d"),
13910 formatWeek = format("%b %d"),
13911 formatMonth = format("%B"),
13912 formatYear = format("%Y");
13913
13914 var tickIntervals = [
13915 [second, 1, durationSecond$1],
13916 [second, 5, 5 * durationSecond$1],
13917 [second, 15, 15 * durationSecond$1],
13918 [second, 30, 30 * durationSecond$1],
13919 [minute, 1, durationMinute$1],
13920 [minute, 5, 5 * durationMinute$1],
13921 [minute, 15, 15 * durationMinute$1],
13922 [minute, 30, 30 * durationMinute$1],
13923 [ hour, 1, durationHour$1 ],
13924 [ hour, 3, 3 * durationHour$1 ],
13925 [ hour, 6, 6 * durationHour$1 ],
13926 [ hour, 12, 12 * durationHour$1 ],
13927 [ day, 1, durationDay$1 ],
13928 [ day, 2, 2 * durationDay$1 ],
13929 [ week, 1, durationWeek$1 ],
13930 [ month, 1, durationMonth ],
13931 [ month, 3, 3 * durationMonth ],
13932 [ year, 1, durationYear ]
13933 ];
13934
13935 function tickFormat(date) {
13936 return (second(date) < date ? formatMillisecond
13937 : minute(date) < date ? formatSecond
13938 : hour(date) < date ? formatMinute
13939 : day(date) < date ? formatHour
13940 : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
13941 : year(date) < date ? formatMonth
13942 : formatYear)(date);
13943 }
13944
13945 function tickInterval(interval, start, stop, step) {
13946 if (interval == null) interval = 10;
13947
13948 // If a desired tick count is specified, pick a reasonable tick interval
13949 // based on the extent of the domain and a rough estimate of tick size.
13950 // Otherwise, assume interval is already a time interval and use it.
13951 if (typeof interval === "number") {
13952 var target = Math.abs(stop - start) / interval,
13953 i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
13954 if (i === tickIntervals.length) {
13955 step = tickStep(start / durationYear, stop / durationYear, interval);
13956 interval = year;
13957 } else if (i) {
13958 i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
13959 step = i[1];
13960 interval = i[0];
13961 } else {
13962 step = Math.max(tickStep(start, stop, interval), 1);
13963 interval = millisecond;
13964 }
13965 }
13966
13967 return step == null ? interval : interval.every(step);
13968 }
13969
13970 scale.invert = function(y) {
13971 return new Date(invert(y));
13972 };
13973
13974 scale.domain = function(_) {
13975 return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
13976 };
13977
13978 scale.ticks = function(interval, step) {
13979 var d = domain(),
13980 t0 = d[0],
13981 t1 = d[d.length - 1],
13982 r = t1 < t0,
13983 t;
13984 if (r) t = t0, t0 = t1, t1 = t;
13985 t = tickInterval(interval, t0, t1, step);
13986 t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
13987 return r ? t.reverse() : t;
13988 };
13989
13990 scale.tickFormat = function(count, specifier) {
13991 return specifier == null ? tickFormat : format(specifier);
13992 };
13993
13994 scale.nice = function(interval, step) {
13995 var d = domain();
13996 return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
13997 ? domain(nice(d, interval))
13998 : scale;
13999 };
14000
14001 scale.copy = function() {
14002 return copy(scale, calendar(year, month, week, day, hour, minute, second, millisecond, format));
14003 };
14004
14005 return scale;
14006}
14007
14008function time() {
14009 return initRange.apply(calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
14010}
14011
14012function utcTime() {
14013 return initRange.apply(calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
14014}
14015
14016function transformer$2() {
14017 var x0 = 0,
14018 x1 = 1,
14019 t0,
14020 t1,
14021 k10,
14022 transform,
14023 interpolator = identity$6,
14024 clamp = false,
14025 unknown;
14026
14027 function scale(x) {
14028 return isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
14029 }
14030
14031 scale.domain = function(_) {
14032 return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
14033 };
14034
14035 scale.clamp = function(_) {
14036 return arguments.length ? (clamp = !!_, scale) : clamp;
14037 };
14038
14039 scale.interpolator = function(_) {
14040 return arguments.length ? (interpolator = _, scale) : interpolator;
14041 };
14042
14043 scale.unknown = function(_) {
14044 return arguments.length ? (unknown = _, scale) : unknown;
14045 };
14046
14047 return function(t) {
14048 transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
14049 return scale;
14050 };
14051}
14052
14053function copy$1(source, target) {
14054 return target
14055 .domain(source.domain())
14056 .interpolator(source.interpolator())
14057 .clamp(source.clamp())
14058 .unknown(source.unknown());
14059}
14060
14061function sequential() {
14062 var scale = linearish(transformer$2()(identity$6));
14063
14064 scale.copy = function() {
14065 return copy$1(scale, sequential());
14066 };
14067
14068 return initInterpolator.apply(scale, arguments);
14069}
14070
14071function sequentialLog() {
14072 var scale = loggish(transformer$2()).domain([1, 10]);
14073
14074 scale.copy = function() {
14075 return copy$1(scale, sequentialLog()).base(scale.base());
14076 };
14077
14078 return initInterpolator.apply(scale, arguments);
14079}
14080
14081function sequentialSymlog() {
14082 var scale = symlogish(transformer$2());
14083
14084 scale.copy = function() {
14085 return copy$1(scale, sequentialSymlog()).constant(scale.constant());
14086 };
14087
14088 return initInterpolator.apply(scale, arguments);
14089}
14090
14091function sequentialPow() {
14092 var scale = powish(transformer$2());
14093
14094 scale.copy = function() {
14095 return copy$1(scale, sequentialPow()).exponent(scale.exponent());
14096 };
14097
14098 return initInterpolator.apply(scale, arguments);
14099}
14100
14101function sequentialSqrt() {
14102 return sequentialPow.apply(null, arguments).exponent(0.5);
14103}
14104
14105function sequentialQuantile() {
14106 var domain = [],
14107 interpolator = identity$6;
14108
14109 function scale(x) {
14110 if (!isNaN(x = +x)) return interpolator((bisectRight(domain, x) - 1) / (domain.length - 1));
14111 }
14112
14113 scale.domain = function(_) {
14114 if (!arguments.length) return domain.slice();
14115 domain = [];
14116 for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
14117 domain.sort(ascending);
14118 return scale;
14119 };
14120
14121 scale.interpolator = function(_) {
14122 return arguments.length ? (interpolator = _, scale) : interpolator;
14123 };
14124
14125 scale.copy = function() {
14126 return sequentialQuantile(interpolator).domain(domain);
14127 };
14128
14129 return initInterpolator.apply(scale, arguments);
14130}
14131
14132function transformer$3() {
14133 var x0 = 0,
14134 x1 = 0.5,
14135 x2 = 1,
14136 t0,
14137 t1,
14138 t2,
14139 k10,
14140 k21,
14141 interpolator = identity$6,
14142 transform,
14143 clamp = false,
14144 unknown;
14145
14146 function scale(x) {
14147 return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (x < t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
14148 }
14149
14150 scale.domain = function(_) {
14151 return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), t2 = transform(x2 = +_[2]), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), scale) : [x0, x1, x2];
14152 };
14153
14154 scale.clamp = function(_) {
14155 return arguments.length ? (clamp = !!_, scale) : clamp;
14156 };
14157
14158 scale.interpolator = function(_) {
14159 return arguments.length ? (interpolator = _, scale) : interpolator;
14160 };
14161
14162 scale.unknown = function(_) {
14163 return arguments.length ? (unknown = _, scale) : unknown;
14164 };
14165
14166 return function(t) {
14167 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);
14168 return scale;
14169 };
14170}
14171
14172function diverging() {
14173 var scale = linearish(transformer$3()(identity$6));
14174
14175 scale.copy = function() {
14176 return copy$1(scale, diverging());
14177 };
14178
14179 return initInterpolator.apply(scale, arguments);
14180}
14181
14182function divergingLog() {
14183 var scale = loggish(transformer$3()).domain([0.1, 1, 10]);
14184
14185 scale.copy = function() {
14186 return copy$1(scale, divergingLog()).base(scale.base());
14187 };
14188
14189 return initInterpolator.apply(scale, arguments);
14190}
14191
14192function divergingSymlog() {
14193 var scale = symlogish(transformer$3());
14194
14195 scale.copy = function() {
14196 return copy$1(scale, divergingSymlog()).constant(scale.constant());
14197 };
14198
14199 return initInterpolator.apply(scale, arguments);
14200}
14201
14202function divergingPow() {
14203 var scale = powish(transformer$3());
14204
14205 scale.copy = function() {
14206 return copy$1(scale, divergingPow()).exponent(scale.exponent());
14207 };
14208
14209 return initInterpolator.apply(scale, arguments);
14210}
14211
14212function divergingSqrt() {
14213 return divergingPow.apply(null, arguments).exponent(0.5);
14214}
14215
14216function colors(specifier) {
14217 var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
14218 while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
14219 return colors;
14220}
14221
14222var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
14223
14224var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
14225
14226var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
14227
14228var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
14229
14230var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
14231
14232var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
14233
14234var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
14235
14236var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
14237
14238var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
14239
14240var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
14241
14242function ramp(scheme) {
14243 return rgbBasis(scheme[scheme.length - 1]);
14244}
14245
14246var scheme = new Array(3).concat(
14247 "d8b365f5f5f55ab4ac",
14248 "a6611adfc27d80cdc1018571",
14249 "a6611adfc27df5f5f580cdc1018571",
14250 "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
14251 "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
14252 "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
14253 "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
14254 "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
14255 "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
14256).map(colors);
14257
14258var BrBG = ramp(scheme);
14259
14260var scheme$1 = new Array(3).concat(
14261 "af8dc3f7f7f77fbf7b",
14262 "7b3294c2a5cfa6dba0008837",
14263 "7b3294c2a5cff7f7f7a6dba0008837",
14264 "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
14265 "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
14266 "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
14267 "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
14268 "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
14269 "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
14270).map(colors);
14271
14272var PRGn = ramp(scheme$1);
14273
14274var scheme$2 = new Array(3).concat(
14275 "e9a3c9f7f7f7a1d76a",
14276 "d01c8bf1b6dab8e1864dac26",
14277 "d01c8bf1b6daf7f7f7b8e1864dac26",
14278 "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
14279 "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
14280 "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
14281 "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
14282 "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
14283 "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
14284).map(colors);
14285
14286var PiYG = ramp(scheme$2);
14287
14288var scheme$3 = new Array(3).concat(
14289 "998ec3f7f7f7f1a340",
14290 "5e3c99b2abd2fdb863e66101",
14291 "5e3c99b2abd2f7f7f7fdb863e66101",
14292 "542788998ec3d8daebfee0b6f1a340b35806",
14293 "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
14294 "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
14295 "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
14296 "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
14297 "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
14298).map(colors);
14299
14300var PuOr = ramp(scheme$3);
14301
14302var scheme$4 = new Array(3).concat(
14303 "ef8a62f7f7f767a9cf",
14304 "ca0020f4a58292c5de0571b0",
14305 "ca0020f4a582f7f7f792c5de0571b0",
14306 "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
14307 "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
14308 "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
14309 "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
14310 "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
14311 "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
14312).map(colors);
14313
14314var RdBu = ramp(scheme$4);
14315
14316var scheme$5 = new Array(3).concat(
14317 "ef8a62ffffff999999",
14318 "ca0020f4a582bababa404040",
14319 "ca0020f4a582ffffffbababa404040",
14320 "b2182bef8a62fddbc7e0e0e09999994d4d4d",
14321 "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
14322 "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
14323 "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
14324 "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
14325 "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
14326).map(colors);
14327
14328var RdGy = ramp(scheme$5);
14329
14330var scheme$6 = new Array(3).concat(
14331 "fc8d59ffffbf91bfdb",
14332 "d7191cfdae61abd9e92c7bb6",
14333 "d7191cfdae61ffffbfabd9e92c7bb6",
14334 "d73027fc8d59fee090e0f3f891bfdb4575b4",
14335 "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
14336 "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
14337 "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
14338 "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
14339 "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
14340).map(colors);
14341
14342var RdYlBu = ramp(scheme$6);
14343
14344var scheme$7 = new Array(3).concat(
14345 "fc8d59ffffbf91cf60",
14346 "d7191cfdae61a6d96a1a9641",
14347 "d7191cfdae61ffffbfa6d96a1a9641",
14348 "d73027fc8d59fee08bd9ef8b91cf601a9850",
14349 "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
14350 "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
14351 "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
14352 "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
14353 "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
14354).map(colors);
14355
14356var RdYlGn = ramp(scheme$7);
14357
14358var scheme$8 = new Array(3).concat(
14359 "fc8d59ffffbf99d594",
14360 "d7191cfdae61abdda42b83ba",
14361 "d7191cfdae61ffffbfabdda42b83ba",
14362 "d53e4ffc8d59fee08be6f59899d5943288bd",
14363 "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
14364 "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
14365 "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
14366 "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
14367 "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
14368).map(colors);
14369
14370var Spectral = ramp(scheme$8);
14371
14372var scheme$9 = new Array(3).concat(
14373 "e5f5f999d8c92ca25f",
14374 "edf8fbb2e2e266c2a4238b45",
14375 "edf8fbb2e2e266c2a42ca25f006d2c",
14376 "edf8fbccece699d8c966c2a42ca25f006d2c",
14377 "edf8fbccece699d8c966c2a441ae76238b45005824",
14378 "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
14379 "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
14380).map(colors);
14381
14382var BuGn = ramp(scheme$9);
14383
14384var scheme$a = new Array(3).concat(
14385 "e0ecf49ebcda8856a7",
14386 "edf8fbb3cde38c96c688419d",
14387 "edf8fbb3cde38c96c68856a7810f7c",
14388 "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
14389 "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
14390 "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
14391 "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
14392).map(colors);
14393
14394var BuPu = ramp(scheme$a);
14395
14396var scheme$b = new Array(3).concat(
14397 "e0f3dba8ddb543a2ca",
14398 "f0f9e8bae4bc7bccc42b8cbe",
14399 "f0f9e8bae4bc7bccc443a2ca0868ac",
14400 "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
14401 "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
14402 "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
14403 "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
14404).map(colors);
14405
14406var GnBu = ramp(scheme$b);
14407
14408var scheme$c = new Array(3).concat(
14409 "fee8c8fdbb84e34a33",
14410 "fef0d9fdcc8afc8d59d7301f",
14411 "fef0d9fdcc8afc8d59e34a33b30000",
14412 "fef0d9fdd49efdbb84fc8d59e34a33b30000",
14413 "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
14414 "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
14415 "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
14416).map(colors);
14417
14418var OrRd = ramp(scheme$c);
14419
14420var scheme$d = new Array(3).concat(
14421 "ece2f0a6bddb1c9099",
14422 "f6eff7bdc9e167a9cf02818a",
14423 "f6eff7bdc9e167a9cf1c9099016c59",
14424 "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
14425 "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
14426 "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
14427 "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
14428).map(colors);
14429
14430var PuBuGn = ramp(scheme$d);
14431
14432var scheme$e = new Array(3).concat(
14433 "ece7f2a6bddb2b8cbe",
14434 "f1eef6bdc9e174a9cf0570b0",
14435 "f1eef6bdc9e174a9cf2b8cbe045a8d",
14436 "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
14437 "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
14438 "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
14439 "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
14440).map(colors);
14441
14442var PuBu = ramp(scheme$e);
14443
14444var scheme$f = new Array(3).concat(
14445 "e7e1efc994c7dd1c77",
14446 "f1eef6d7b5d8df65b0ce1256",
14447 "f1eef6d7b5d8df65b0dd1c77980043",
14448 "f1eef6d4b9dac994c7df65b0dd1c77980043",
14449 "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
14450 "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
14451 "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
14452).map(colors);
14453
14454var PuRd = ramp(scheme$f);
14455
14456var scheme$g = new Array(3).concat(
14457 "fde0ddfa9fb5c51b8a",
14458 "feebe2fbb4b9f768a1ae017e",
14459 "feebe2fbb4b9f768a1c51b8a7a0177",
14460 "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
14461 "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
14462 "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
14463 "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
14464).map(colors);
14465
14466var RdPu = ramp(scheme$g);
14467
14468var scheme$h = new Array(3).concat(
14469 "edf8b17fcdbb2c7fb8",
14470 "ffffcca1dab441b6c4225ea8",
14471 "ffffcca1dab441b6c42c7fb8253494",
14472 "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
14473 "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
14474 "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
14475 "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
14476).map(colors);
14477
14478var YlGnBu = ramp(scheme$h);
14479
14480var scheme$i = new Array(3).concat(
14481 "f7fcb9addd8e31a354",
14482 "ffffccc2e69978c679238443",
14483 "ffffccc2e69978c67931a354006837",
14484 "ffffccd9f0a3addd8e78c67931a354006837",
14485 "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
14486 "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
14487 "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
14488).map(colors);
14489
14490var YlGn = ramp(scheme$i);
14491
14492var scheme$j = new Array(3).concat(
14493 "fff7bcfec44fd95f0e",
14494 "ffffd4fed98efe9929cc4c02",
14495 "ffffd4fed98efe9929d95f0e993404",
14496 "ffffd4fee391fec44ffe9929d95f0e993404",
14497 "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
14498 "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
14499 "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
14500).map(colors);
14501
14502var YlOrBr = ramp(scheme$j);
14503
14504var scheme$k = new Array(3).concat(
14505 "ffeda0feb24cf03b20",
14506 "ffffb2fecc5cfd8d3ce31a1c",
14507 "ffffb2fecc5cfd8d3cf03b20bd0026",
14508 "ffffb2fed976feb24cfd8d3cf03b20bd0026",
14509 "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
14510 "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
14511 "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
14512).map(colors);
14513
14514var YlOrRd = ramp(scheme$k);
14515
14516var scheme$l = new Array(3).concat(
14517 "deebf79ecae13182bd",
14518 "eff3ffbdd7e76baed62171b5",
14519 "eff3ffbdd7e76baed63182bd08519c",
14520 "eff3ffc6dbef9ecae16baed63182bd08519c",
14521 "eff3ffc6dbef9ecae16baed64292c62171b5084594",
14522 "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
14523 "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
14524).map(colors);
14525
14526var Blues = ramp(scheme$l);
14527
14528var scheme$m = new Array(3).concat(
14529 "e5f5e0a1d99b31a354",
14530 "edf8e9bae4b374c476238b45",
14531 "edf8e9bae4b374c47631a354006d2c",
14532 "edf8e9c7e9c0a1d99b74c47631a354006d2c",
14533 "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
14534 "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
14535 "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
14536).map(colors);
14537
14538var Greens = ramp(scheme$m);
14539
14540var scheme$n = new Array(3).concat(
14541 "f0f0f0bdbdbd636363",
14542 "f7f7f7cccccc969696525252",
14543 "f7f7f7cccccc969696636363252525",
14544 "f7f7f7d9d9d9bdbdbd969696636363252525",
14545 "f7f7f7d9d9d9bdbdbd969696737373525252252525",
14546 "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
14547 "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
14548).map(colors);
14549
14550var Greys = ramp(scheme$n);
14551
14552var scheme$o = new Array(3).concat(
14553 "efedf5bcbddc756bb1",
14554 "f2f0f7cbc9e29e9ac86a51a3",
14555 "f2f0f7cbc9e29e9ac8756bb154278f",
14556 "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
14557 "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
14558 "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
14559 "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
14560).map(colors);
14561
14562var Purples = ramp(scheme$o);
14563
14564var scheme$p = new Array(3).concat(
14565 "fee0d2fc9272de2d26",
14566 "fee5d9fcae91fb6a4acb181d",
14567 "fee5d9fcae91fb6a4ade2d26a50f15",
14568 "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
14569 "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
14570 "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
14571 "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
14572).map(colors);
14573
14574var Reds = ramp(scheme$p);
14575
14576var scheme$q = new Array(3).concat(
14577 "fee6cefdae6be6550d",
14578 "feeddefdbe85fd8d3cd94701",
14579 "feeddefdbe85fd8d3ce6550da63603",
14580 "feeddefdd0a2fdae6bfd8d3ce6550da63603",
14581 "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
14582 "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
14583 "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
14584).map(colors);
14585
14586var Oranges = ramp(scheme$q);
14587
14588function cividis(t) {
14589 t = Math.max(0, Math.min(1, t));
14590 return "rgb("
14591 + 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))))))) + ", "
14592 + 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))))))) + ", "
14593 + 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)))))))
14594 + ")";
14595}
14596
14597var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
14598
14599var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
14600
14601var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
14602
14603var c = cubehelix();
14604
14605function rainbow(t) {
14606 if (t < 0 || t > 1) t -= Math.floor(t);
14607 var ts = Math.abs(t - 0.5);
14608 c.h = 360 * t - 100;
14609 c.s = 1.5 - 1.5 * ts;
14610 c.l = 0.8 - 0.9 * ts;
14611 return c + "";
14612}
14613
14614var c$1 = rgb(),
14615 pi_1_3 = Math.PI / 3,
14616 pi_2_3 = Math.PI * 2 / 3;
14617
14618function sinebow(t) {
14619 var x;
14620 t = (0.5 - t) * Math.PI;
14621 c$1.r = 255 * (x = Math.sin(t)) * x;
14622 c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
14623 c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
14624 return c$1 + "";
14625}
14626
14627function turbo(t) {
14628 t = Math.max(0, Math.min(1, t));
14629 return "rgb("
14630 + 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))))))) + ", "
14631 + 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))))))) + ", "
14632 + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
14633 + ")";
14634}
14635
14636function ramp$1(range) {
14637 var n = range.length;
14638 return function(t) {
14639 return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
14640 };
14641}
14642
14643var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
14644
14645var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
14646
14647var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
14648
14649var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
14650
14651function constant$b(x) {
14652 return function constant() {
14653 return x;
14654 };
14655}
14656
14657var abs$1 = Math.abs;
14658var atan2$1 = Math.atan2;
14659var cos$2 = Math.cos;
14660var max$2 = Math.max;
14661var min$1 = Math.min;
14662var sin$2 = Math.sin;
14663var sqrt$2 = Math.sqrt;
14664
14665var epsilon$3 = 1e-12;
14666var pi$4 = Math.PI;
14667var halfPi$3 = pi$4 / 2;
14668var tau$4 = 2 * pi$4;
14669
14670function acos$1(x) {
14671 return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
14672}
14673
14674function asin$1(x) {
14675 return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
14676}
14677
14678function arcInnerRadius(d) {
14679 return d.innerRadius;
14680}
14681
14682function arcOuterRadius(d) {
14683 return d.outerRadius;
14684}
14685
14686function arcStartAngle(d) {
14687 return d.startAngle;
14688}
14689
14690function arcEndAngle(d) {
14691 return d.endAngle;
14692}
14693
14694function arcPadAngle(d) {
14695 return d && d.padAngle; // Note: optional!
14696}
14697
14698function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
14699 var x10 = x1 - x0, y10 = y1 - y0,
14700 x32 = x3 - x2, y32 = y3 - y2,
14701 t = y32 * x10 - x32 * y10;
14702 if (t * t < epsilon$3) return;
14703 t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
14704 return [x0 + t * x10, y0 + t * y10];
14705}
14706
14707// Compute perpendicular offset line of length rc.
14708// http://mathworld.wolfram.com/Circle-LineIntersection.html
14709function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
14710 var x01 = x0 - x1,
14711 y01 = y0 - y1,
14712 lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
14713 ox = lo * y01,
14714 oy = -lo * x01,
14715 x11 = x0 + ox,
14716 y11 = y0 + oy,
14717 x10 = x1 + ox,
14718 y10 = y1 + oy,
14719 x00 = (x11 + x10) / 2,
14720 y00 = (y11 + y10) / 2,
14721 dx = x10 - x11,
14722 dy = y10 - y11,
14723 d2 = dx * dx + dy * dy,
14724 r = r1 - rc,
14725 D = x11 * y10 - x10 * y11,
14726 d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
14727 cx0 = (D * dy - dx * d) / d2,
14728 cy0 = (-D * dx - dy * d) / d2,
14729 cx1 = (D * dy + dx * d) / d2,
14730 cy1 = (-D * dx + dy * d) / d2,
14731 dx0 = cx0 - x00,
14732 dy0 = cy0 - y00,
14733 dx1 = cx1 - x00,
14734 dy1 = cy1 - y00;
14735
14736 // Pick the closer of the two intersection points.
14737 // TODO Is there a faster way to determine which intersection to use?
14738 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
14739
14740 return {
14741 cx: cx0,
14742 cy: cy0,
14743 x01: -ox,
14744 y01: -oy,
14745 x11: cx0 * (r1 / r - 1),
14746 y11: cy0 * (r1 / r - 1)
14747 };
14748}
14749
14750function arc() {
14751 var innerRadius = arcInnerRadius,
14752 outerRadius = arcOuterRadius,
14753 cornerRadius = constant$b(0),
14754 padRadius = null,
14755 startAngle = arcStartAngle,
14756 endAngle = arcEndAngle,
14757 padAngle = arcPadAngle,
14758 context = null;
14759
14760 function arc() {
14761 var buffer,
14762 r,
14763 r0 = +innerRadius.apply(this, arguments),
14764 r1 = +outerRadius.apply(this, arguments),
14765 a0 = startAngle.apply(this, arguments) - halfPi$3,
14766 a1 = endAngle.apply(this, arguments) - halfPi$3,
14767 da = abs$1(a1 - a0),
14768 cw = a1 > a0;
14769
14770 if (!context) context = buffer = path();
14771
14772 // Ensure that the outer radius is always larger than the inner radius.
14773 if (r1 < r0) r = r1, r1 = r0, r0 = r;
14774
14775 // Is it a point?
14776 if (!(r1 > epsilon$3)) context.moveTo(0, 0);
14777
14778 // Or is it a circle or annulus?
14779 else if (da > tau$4 - epsilon$3) {
14780 context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
14781 context.arc(0, 0, r1, a0, a1, !cw);
14782 if (r0 > epsilon$3) {
14783 context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
14784 context.arc(0, 0, r0, a1, a0, cw);
14785 }
14786 }
14787
14788 // Or is it a circular or annular sector?
14789 else {
14790 var a01 = a0,
14791 a11 = a1,
14792 a00 = a0,
14793 a10 = a1,
14794 da0 = da,
14795 da1 = da,
14796 ap = padAngle.apply(this, arguments) / 2,
14797 rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
14798 rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
14799 rc0 = rc,
14800 rc1 = rc,
14801 t0,
14802 t1;
14803
14804 // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
14805 if (rp > epsilon$3) {
14806 var p0 = asin$1(rp / r0 * sin$2(ap)),
14807 p1 = asin$1(rp / r1 * sin$2(ap));
14808 if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
14809 else da0 = 0, a00 = a10 = (a0 + a1) / 2;
14810 if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
14811 else da1 = 0, a01 = a11 = (a0 + a1) / 2;
14812 }
14813
14814 var x01 = r1 * cos$2(a01),
14815 y01 = r1 * sin$2(a01),
14816 x10 = r0 * cos$2(a10),
14817 y10 = r0 * sin$2(a10);
14818
14819 // Apply rounded corners?
14820 if (rc > epsilon$3) {
14821 var x11 = r1 * cos$2(a11),
14822 y11 = r1 * sin$2(a11),
14823 x00 = r0 * cos$2(a00),
14824 y00 = r0 * sin$2(a00),
14825 oc;
14826
14827 // Restrict the corner radius according to the sector angle.
14828 if (da < pi$4 && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
14829 var ax = x01 - oc[0],
14830 ay = y01 - oc[1],
14831 bx = x11 - oc[0],
14832 by = y11 - oc[1],
14833 kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
14834 lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
14835 rc0 = min$1(rc, (r0 - lc) / (kc - 1));
14836 rc1 = min$1(rc, (r1 - lc) / (kc + 1));
14837 }
14838 }
14839
14840 // Is the sector collapsed to a line?
14841 if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
14842
14843 // Does the sector’s outer ring have rounded corners?
14844 else if (rc1 > epsilon$3) {
14845 t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
14846 t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
14847
14848 context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
14849
14850 // Have the corners merged?
14851 if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
14852
14853 // Otherwise, draw the two corners and the ring.
14854 else {
14855 context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
14856 context.arc(0, 0, r1, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
14857 context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
14858 }
14859 }
14860
14861 // Or is the outer ring just a circular arc?
14862 else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
14863
14864 // Is there no inner ring, and it’s a circular sector?
14865 // Or perhaps it’s an annular sector collapsed due to padding?
14866 if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
14867
14868 // Does the sector’s inner ring (or point) have rounded corners?
14869 else if (rc0 > epsilon$3) {
14870 t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
14871 t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
14872
14873 context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
14874
14875 // Have the corners merged?
14876 if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
14877
14878 // Otherwise, draw the two corners and the ring.
14879 else {
14880 context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
14881 context.arc(0, 0, r0, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), cw);
14882 context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
14883 }
14884 }
14885
14886 // Or is the inner ring just a circular arc?
14887 else context.arc(0, 0, r0, a10, a00, cw);
14888 }
14889
14890 context.closePath();
14891
14892 if (buffer) return context = null, buffer + "" || null;
14893 }
14894
14895 arc.centroid = function() {
14896 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
14897 a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
14898 return [cos$2(a) * r, sin$2(a) * r];
14899 };
14900
14901 arc.innerRadius = function(_) {
14902 return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : innerRadius;
14903 };
14904
14905 arc.outerRadius = function(_) {
14906 return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : outerRadius;
14907 };
14908
14909 arc.cornerRadius = function(_) {
14910 return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : cornerRadius;
14911 };
14912
14913 arc.padRadius = function(_) {
14914 return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), arc) : padRadius;
14915 };
14916
14917 arc.startAngle = function(_) {
14918 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : startAngle;
14919 };
14920
14921 arc.endAngle = function(_) {
14922 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : endAngle;
14923 };
14924
14925 arc.padAngle = function(_) {
14926 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : padAngle;
14927 };
14928
14929 arc.context = function(_) {
14930 return arguments.length ? ((context = _ == null ? null : _), arc) : context;
14931 };
14932
14933 return arc;
14934}
14935
14936function Linear(context) {
14937 this._context = context;
14938}
14939
14940Linear.prototype = {
14941 areaStart: function() {
14942 this._line = 0;
14943 },
14944 areaEnd: function() {
14945 this._line = NaN;
14946 },
14947 lineStart: function() {
14948 this._point = 0;
14949 },
14950 lineEnd: function() {
14951 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14952 this._line = 1 - this._line;
14953 },
14954 point: function(x, y) {
14955 x = +x, y = +y;
14956 switch (this._point) {
14957 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14958 case 1: this._point = 2; // proceed
14959 default: this._context.lineTo(x, y); break;
14960 }
14961 }
14962};
14963
14964function curveLinear(context) {
14965 return new Linear(context);
14966}
14967
14968function x$3(p) {
14969 return p[0];
14970}
14971
14972function y$3(p) {
14973 return p[1];
14974}
14975
14976function line() {
14977 var x = x$3,
14978 y = y$3,
14979 defined = constant$b(true),
14980 context = null,
14981 curve = curveLinear,
14982 output = null;
14983
14984 function line(data) {
14985 var i,
14986 n = data.length,
14987 d,
14988 defined0 = false,
14989 buffer;
14990
14991 if (context == null) output = curve(buffer = path());
14992
14993 for (i = 0; i <= n; ++i) {
14994 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
14995 if (defined0 = !defined0) output.lineStart();
14996 else output.lineEnd();
14997 }
14998 if (defined0) output.point(+x(d, i, data), +y(d, i, data));
14999 }
15000
15001 if (buffer) return output = null, buffer + "" || null;
15002 }
15003
15004 line.x = function(_) {
15005 return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), line) : x;
15006 };
15007
15008 line.y = function(_) {
15009 return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), line) : y;
15010 };
15011
15012 line.defined = function(_) {
15013 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), line) : defined;
15014 };
15015
15016 line.curve = function(_) {
15017 return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
15018 };
15019
15020 line.context = function(_) {
15021 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
15022 };
15023
15024 return line;
15025}
15026
15027function area$3() {
15028 var x0 = x$3,
15029 x1 = null,
15030 y0 = constant$b(0),
15031 y1 = y$3,
15032 defined = constant$b(true),
15033 context = null,
15034 curve = curveLinear,
15035 output = null;
15036
15037 function area(data) {
15038 var i,
15039 j,
15040 k,
15041 n = data.length,
15042 d,
15043 defined0 = false,
15044 buffer,
15045 x0z = new Array(n),
15046 y0z = new Array(n);
15047
15048 if (context == null) output = curve(buffer = path());
15049
15050 for (i = 0; i <= n; ++i) {
15051 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
15052 if (defined0 = !defined0) {
15053 j = i;
15054 output.areaStart();
15055 output.lineStart();
15056 } else {
15057 output.lineEnd();
15058 output.lineStart();
15059 for (k = i - 1; k >= j; --k) {
15060 output.point(x0z[k], y0z[k]);
15061 }
15062 output.lineEnd();
15063 output.areaEnd();
15064 }
15065 }
15066 if (defined0) {
15067 x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
15068 output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
15069 }
15070 }
15071
15072 if (buffer) return output = null, buffer + "" || null;
15073 }
15074
15075 function arealine() {
15076 return line().defined(defined).curve(curve).context(context);
15077 }
15078
15079 area.x = function(_) {
15080 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), x1 = null, area) : x0;
15081 };
15082
15083 area.x0 = function(_) {
15084 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), area) : x0;
15085 };
15086
15087 area.x1 = function(_) {
15088 return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : x1;
15089 };
15090
15091 area.y = function(_) {
15092 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), y1 = null, area) : y0;
15093 };
15094
15095 area.y0 = function(_) {
15096 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), area) : y0;
15097 };
15098
15099 area.y1 = function(_) {
15100 return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : y1;
15101 };
15102
15103 area.lineX0 =
15104 area.lineY0 = function() {
15105 return arealine().x(x0).y(y0);
15106 };
15107
15108 area.lineY1 = function() {
15109 return arealine().x(x0).y(y1);
15110 };
15111
15112 area.lineX1 = function() {
15113 return arealine().x(x1).y(y0);
15114 };
15115
15116 area.defined = function(_) {
15117 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), area) : defined;
15118 };
15119
15120 area.curve = function(_) {
15121 return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
15122 };
15123
15124 area.context = function(_) {
15125 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
15126 };
15127
15128 return area;
15129}
15130
15131function descending$1(a, b) {
15132 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
15133}
15134
15135function identity$8(d) {
15136 return d;
15137}
15138
15139function pie() {
15140 var value = identity$8,
15141 sortValues = descending$1,
15142 sort = null,
15143 startAngle = constant$b(0),
15144 endAngle = constant$b(tau$4),
15145 padAngle = constant$b(0);
15146
15147 function pie(data) {
15148 var i,
15149 n = data.length,
15150 j,
15151 k,
15152 sum = 0,
15153 index = new Array(n),
15154 arcs = new Array(n),
15155 a0 = +startAngle.apply(this, arguments),
15156 da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
15157 a1,
15158 p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
15159 pa = p * (da < 0 ? -1 : 1),
15160 v;
15161
15162 for (i = 0; i < n; ++i) {
15163 if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
15164 sum += v;
15165 }
15166 }
15167
15168 // Optionally sort the arcs by previously-computed values or by data.
15169 if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
15170 else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
15171
15172 // Compute the arcs! They are stored in the original data's order.
15173 for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
15174 j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
15175 data: data[j],
15176 index: i,
15177 value: v,
15178 startAngle: a0,
15179 endAngle: a1,
15180 padAngle: p
15181 };
15182 }
15183
15184 return arcs;
15185 }
15186
15187 pie.value = function(_) {
15188 return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), pie) : value;
15189 };
15190
15191 pie.sortValues = function(_) {
15192 return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
15193 };
15194
15195 pie.sort = function(_) {
15196 return arguments.length ? (sort = _, sortValues = null, pie) : sort;
15197 };
15198
15199 pie.startAngle = function(_) {
15200 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : startAngle;
15201 };
15202
15203 pie.endAngle = function(_) {
15204 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : endAngle;
15205 };
15206
15207 pie.padAngle = function(_) {
15208 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : padAngle;
15209 };
15210
15211 return pie;
15212}
15213
15214var curveRadialLinear = curveRadial(curveLinear);
15215
15216function Radial(curve) {
15217 this._curve = curve;
15218}
15219
15220Radial.prototype = {
15221 areaStart: function() {
15222 this._curve.areaStart();
15223 },
15224 areaEnd: function() {
15225 this._curve.areaEnd();
15226 },
15227 lineStart: function() {
15228 this._curve.lineStart();
15229 },
15230 lineEnd: function() {
15231 this._curve.lineEnd();
15232 },
15233 point: function(a, r) {
15234 this._curve.point(r * Math.sin(a), r * -Math.cos(a));
15235 }
15236};
15237
15238function curveRadial(curve) {
15239
15240 function radial(context) {
15241 return new Radial(curve(context));
15242 }
15243
15244 radial._curve = curve;
15245
15246 return radial;
15247}
15248
15249function lineRadial(l) {
15250 var c = l.curve;
15251
15252 l.angle = l.x, delete l.x;
15253 l.radius = l.y, delete l.y;
15254
15255 l.curve = function(_) {
15256 return arguments.length ? c(curveRadial(_)) : c()._curve;
15257 };
15258
15259 return l;
15260}
15261
15262function lineRadial$1() {
15263 return lineRadial(line().curve(curveRadialLinear));
15264}
15265
15266function areaRadial() {
15267 var a = area$3().curve(curveRadialLinear),
15268 c = a.curve,
15269 x0 = a.lineX0,
15270 x1 = a.lineX1,
15271 y0 = a.lineY0,
15272 y1 = a.lineY1;
15273
15274 a.angle = a.x, delete a.x;
15275 a.startAngle = a.x0, delete a.x0;
15276 a.endAngle = a.x1, delete a.x1;
15277 a.radius = a.y, delete a.y;
15278 a.innerRadius = a.y0, delete a.y0;
15279 a.outerRadius = a.y1, delete a.y1;
15280 a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
15281 a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
15282 a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
15283 a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
15284
15285 a.curve = function(_) {
15286 return arguments.length ? c(curveRadial(_)) : c()._curve;
15287 };
15288
15289 return a;
15290}
15291
15292function pointRadial(x, y) {
15293 return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
15294}
15295
15296var slice$6 = Array.prototype.slice;
15297
15298function linkSource(d) {
15299 return d.source;
15300}
15301
15302function linkTarget(d) {
15303 return d.target;
15304}
15305
15306function link$2(curve) {
15307 var source = linkSource,
15308 target = linkTarget,
15309 x = x$3,
15310 y = y$3,
15311 context = null;
15312
15313 function link() {
15314 var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
15315 if (!context) context = buffer = path();
15316 curve(context, +x.apply(this, (argv[0] = s, argv)), +y.apply(this, argv), +x.apply(this, (argv[0] = t, argv)), +y.apply(this, argv));
15317 if (buffer) return context = null, buffer + "" || null;
15318 }
15319
15320 link.source = function(_) {
15321 return arguments.length ? (source = _, link) : source;
15322 };
15323
15324 link.target = function(_) {
15325 return arguments.length ? (target = _, link) : target;
15326 };
15327
15328 link.x = function(_) {
15329 return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), link) : x;
15330 };
15331
15332 link.y = function(_) {
15333 return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), link) : y;
15334 };
15335
15336 link.context = function(_) {
15337 return arguments.length ? ((context = _ == null ? null : _), link) : context;
15338 };
15339
15340 return link;
15341}
15342
15343function curveHorizontal(context, x0, y0, x1, y1) {
15344 context.moveTo(x0, y0);
15345 context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
15346}
15347
15348function curveVertical(context, x0, y0, x1, y1) {
15349 context.moveTo(x0, y0);
15350 context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
15351}
15352
15353function curveRadial$1(context, x0, y0, x1, y1) {
15354 var p0 = pointRadial(x0, y0),
15355 p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
15356 p2 = pointRadial(x1, y0),
15357 p3 = pointRadial(x1, y1);
15358 context.moveTo(p0[0], p0[1]);
15359 context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
15360}
15361
15362function linkHorizontal() {
15363 return link$2(curveHorizontal);
15364}
15365
15366function linkVertical() {
15367 return link$2(curveVertical);
15368}
15369
15370function linkRadial() {
15371 var l = link$2(curveRadial$1);
15372 l.angle = l.x, delete l.x;
15373 l.radius = l.y, delete l.y;
15374 return l;
15375}
15376
15377var circle$2 = {
15378 draw: function(context, size) {
15379 var r = Math.sqrt(size / pi$4);
15380 context.moveTo(r, 0);
15381 context.arc(0, 0, r, 0, tau$4);
15382 }
15383};
15384
15385var cross$2 = {
15386 draw: function(context, size) {
15387 var r = Math.sqrt(size / 5) / 2;
15388 context.moveTo(-3 * r, -r);
15389 context.lineTo(-r, -r);
15390 context.lineTo(-r, -3 * r);
15391 context.lineTo(r, -3 * r);
15392 context.lineTo(r, -r);
15393 context.lineTo(3 * r, -r);
15394 context.lineTo(3 * r, r);
15395 context.lineTo(r, r);
15396 context.lineTo(r, 3 * r);
15397 context.lineTo(-r, 3 * r);
15398 context.lineTo(-r, r);
15399 context.lineTo(-3 * r, r);
15400 context.closePath();
15401 }
15402};
15403
15404var tan30 = Math.sqrt(1 / 3),
15405 tan30_2 = tan30 * 2;
15406
15407var diamond = {
15408 draw: function(context, size) {
15409 var y = Math.sqrt(size / tan30_2),
15410 x = y * tan30;
15411 context.moveTo(0, -y);
15412 context.lineTo(x, 0);
15413 context.lineTo(0, y);
15414 context.lineTo(-x, 0);
15415 context.closePath();
15416 }
15417};
15418
15419var ka = 0.89081309152928522810,
15420 kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
15421 kx = Math.sin(tau$4 / 10) * kr,
15422 ky = -Math.cos(tau$4 / 10) * kr;
15423
15424var star = {
15425 draw: function(context, size) {
15426 var r = Math.sqrt(size * ka),
15427 x = kx * r,
15428 y = ky * r;
15429 context.moveTo(0, -r);
15430 context.lineTo(x, y);
15431 for (var i = 1; i < 5; ++i) {
15432 var a = tau$4 * i / 5,
15433 c = Math.cos(a),
15434 s = Math.sin(a);
15435 context.lineTo(s * r, -c * r);
15436 context.lineTo(c * x - s * y, s * x + c * y);
15437 }
15438 context.closePath();
15439 }
15440};
15441
15442var square = {
15443 draw: function(context, size) {
15444 var w = Math.sqrt(size),
15445 x = -w / 2;
15446 context.rect(x, x, w, w);
15447 }
15448};
15449
15450var sqrt3 = Math.sqrt(3);
15451
15452var triangle = {
15453 draw: function(context, size) {
15454 var y = -Math.sqrt(size / (sqrt3 * 3));
15455 context.moveTo(0, y * 2);
15456 context.lineTo(-sqrt3 * y, -y);
15457 context.lineTo(sqrt3 * y, -y);
15458 context.closePath();
15459 }
15460};
15461
15462var c$2 = -0.5,
15463 s = Math.sqrt(3) / 2,
15464 k = 1 / Math.sqrt(12),
15465 a = (k / 2 + 1) * 3;
15466
15467var wye = {
15468 draw: function(context, size) {
15469 var r = Math.sqrt(size / a),
15470 x0 = r / 2,
15471 y0 = r * k,
15472 x1 = x0,
15473 y1 = r * k + r,
15474 x2 = -x1,
15475 y2 = y1;
15476 context.moveTo(x0, y0);
15477 context.lineTo(x1, y1);
15478 context.lineTo(x2, y2);
15479 context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
15480 context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
15481 context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
15482 context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
15483 context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
15484 context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
15485 context.closePath();
15486 }
15487};
15488
15489var symbols = [
15490 circle$2,
15491 cross$2,
15492 diamond,
15493 square,
15494 star,
15495 triangle,
15496 wye
15497];
15498
15499function symbol() {
15500 var type = constant$b(circle$2),
15501 size = constant$b(64),
15502 context = null;
15503
15504 function symbol() {
15505 var buffer;
15506 if (!context) context = buffer = path();
15507 type.apply(this, arguments).draw(context, +size.apply(this, arguments));
15508 if (buffer) return context = null, buffer + "" || null;
15509 }
15510
15511 symbol.type = function(_) {
15512 return arguments.length ? (type = typeof _ === "function" ? _ : constant$b(_), symbol) : type;
15513 };
15514
15515 symbol.size = function(_) {
15516 return arguments.length ? (size = typeof _ === "function" ? _ : constant$b(+_), symbol) : size;
15517 };
15518
15519 symbol.context = function(_) {
15520 return arguments.length ? (context = _ == null ? null : _, symbol) : context;
15521 };
15522
15523 return symbol;
15524}
15525
15526function noop$3() {}
15527
15528function point$2(that, x, y) {
15529 that._context.bezierCurveTo(
15530 (2 * that._x0 + that._x1) / 3,
15531 (2 * that._y0 + that._y1) / 3,
15532 (that._x0 + 2 * that._x1) / 3,
15533 (that._y0 + 2 * that._y1) / 3,
15534 (that._x0 + 4 * that._x1 + x) / 6,
15535 (that._y0 + 4 * that._y1 + y) / 6
15536 );
15537}
15538
15539function Basis(context) {
15540 this._context = context;
15541}
15542
15543Basis.prototype = {
15544 areaStart: function() {
15545 this._line = 0;
15546 },
15547 areaEnd: function() {
15548 this._line = NaN;
15549 },
15550 lineStart: function() {
15551 this._x0 = this._x1 =
15552 this._y0 = this._y1 = NaN;
15553 this._point = 0;
15554 },
15555 lineEnd: function() {
15556 switch (this._point) {
15557 case 3: point$2(this, this._x1, this._y1); // proceed
15558 case 2: this._context.lineTo(this._x1, this._y1); break;
15559 }
15560 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15561 this._line = 1 - this._line;
15562 },
15563 point: function(x, y) {
15564 x = +x, y = +y;
15565 switch (this._point) {
15566 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15567 case 1: this._point = 2; break;
15568 case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
15569 default: point$2(this, x, y); break;
15570 }
15571 this._x0 = this._x1, this._x1 = x;
15572 this._y0 = this._y1, this._y1 = y;
15573 }
15574};
15575
15576function basis$2(context) {
15577 return new Basis(context);
15578}
15579
15580function BasisClosed(context) {
15581 this._context = context;
15582}
15583
15584BasisClosed.prototype = {
15585 areaStart: noop$3,
15586 areaEnd: noop$3,
15587 lineStart: function() {
15588 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
15589 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
15590 this._point = 0;
15591 },
15592 lineEnd: function() {
15593 switch (this._point) {
15594 case 1: {
15595 this._context.moveTo(this._x2, this._y2);
15596 this._context.closePath();
15597 break;
15598 }
15599 case 2: {
15600 this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
15601 this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
15602 this._context.closePath();
15603 break;
15604 }
15605 case 3: {
15606 this.point(this._x2, this._y2);
15607 this.point(this._x3, this._y3);
15608 this.point(this._x4, this._y4);
15609 break;
15610 }
15611 }
15612 },
15613 point: function(x, y) {
15614 x = +x, y = +y;
15615 switch (this._point) {
15616 case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
15617 case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
15618 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;
15619 default: point$2(this, x, y); break;
15620 }
15621 this._x0 = this._x1, this._x1 = x;
15622 this._y0 = this._y1, this._y1 = y;
15623 }
15624};
15625
15626function basisClosed$1(context) {
15627 return new BasisClosed(context);
15628}
15629
15630function BasisOpen(context) {
15631 this._context = context;
15632}
15633
15634BasisOpen.prototype = {
15635 areaStart: function() {
15636 this._line = 0;
15637 },
15638 areaEnd: function() {
15639 this._line = NaN;
15640 },
15641 lineStart: function() {
15642 this._x0 = this._x1 =
15643 this._y0 = this._y1 = NaN;
15644 this._point = 0;
15645 },
15646 lineEnd: function() {
15647 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15648 this._line = 1 - this._line;
15649 },
15650 point: function(x, y) {
15651 x = +x, y = +y;
15652 switch (this._point) {
15653 case 0: this._point = 1; break;
15654 case 1: this._point = 2; break;
15655 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;
15656 case 3: this._point = 4; // proceed
15657 default: point$2(this, x, y); break;
15658 }
15659 this._x0 = this._x1, this._x1 = x;
15660 this._y0 = this._y1, this._y1 = y;
15661 }
15662};
15663
15664function basisOpen(context) {
15665 return new BasisOpen(context);
15666}
15667
15668function Bundle(context, beta) {
15669 this._basis = new Basis(context);
15670 this._beta = beta;
15671}
15672
15673Bundle.prototype = {
15674 lineStart: function() {
15675 this._x = [];
15676 this._y = [];
15677 this._basis.lineStart();
15678 },
15679 lineEnd: function() {
15680 var x = this._x,
15681 y = this._y,
15682 j = x.length - 1;
15683
15684 if (j > 0) {
15685 var x0 = x[0],
15686 y0 = y[0],
15687 dx = x[j] - x0,
15688 dy = y[j] - y0,
15689 i = -1,
15690 t;
15691
15692 while (++i <= j) {
15693 t = i / j;
15694 this._basis.point(
15695 this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
15696 this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
15697 );
15698 }
15699 }
15700
15701 this._x = this._y = null;
15702 this._basis.lineEnd();
15703 },
15704 point: function(x, y) {
15705 this._x.push(+x);
15706 this._y.push(+y);
15707 }
15708};
15709
15710var bundle = (function custom(beta) {
15711
15712 function bundle(context) {
15713 return beta === 1 ? new Basis(context) : new Bundle(context, beta);
15714 }
15715
15716 bundle.beta = function(beta) {
15717 return custom(+beta);
15718 };
15719
15720 return bundle;
15721})(0.85);
15722
15723function point$3(that, x, y) {
15724 that._context.bezierCurveTo(
15725 that._x1 + that._k * (that._x2 - that._x0),
15726 that._y1 + that._k * (that._y2 - that._y0),
15727 that._x2 + that._k * (that._x1 - x),
15728 that._y2 + that._k * (that._y1 - y),
15729 that._x2,
15730 that._y2
15731 );
15732}
15733
15734function Cardinal(context, tension) {
15735 this._context = context;
15736 this._k = (1 - tension) / 6;
15737}
15738
15739Cardinal.prototype = {
15740 areaStart: function() {
15741 this._line = 0;
15742 },
15743 areaEnd: function() {
15744 this._line = NaN;
15745 },
15746 lineStart: function() {
15747 this._x0 = this._x1 = this._x2 =
15748 this._y0 = this._y1 = this._y2 = NaN;
15749 this._point = 0;
15750 },
15751 lineEnd: function() {
15752 switch (this._point) {
15753 case 2: this._context.lineTo(this._x2, this._y2); break;
15754 case 3: point$3(this, this._x1, this._y1); break;
15755 }
15756 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15757 this._line = 1 - this._line;
15758 },
15759 point: function(x, y) {
15760 x = +x, y = +y;
15761 switch (this._point) {
15762 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15763 case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
15764 case 2: this._point = 3; // proceed
15765 default: point$3(this, x, y); break;
15766 }
15767 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15768 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15769 }
15770};
15771
15772var cardinal = (function custom(tension) {
15773
15774 function cardinal(context) {
15775 return new Cardinal(context, tension);
15776 }
15777
15778 cardinal.tension = function(tension) {
15779 return custom(+tension);
15780 };
15781
15782 return cardinal;
15783})(0);
15784
15785function CardinalClosed(context, tension) {
15786 this._context = context;
15787 this._k = (1 - tension) / 6;
15788}
15789
15790CardinalClosed.prototype = {
15791 areaStart: noop$3,
15792 areaEnd: noop$3,
15793 lineStart: function() {
15794 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
15795 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
15796 this._point = 0;
15797 },
15798 lineEnd: function() {
15799 switch (this._point) {
15800 case 1: {
15801 this._context.moveTo(this._x3, this._y3);
15802 this._context.closePath();
15803 break;
15804 }
15805 case 2: {
15806 this._context.lineTo(this._x3, this._y3);
15807 this._context.closePath();
15808 break;
15809 }
15810 case 3: {
15811 this.point(this._x3, this._y3);
15812 this.point(this._x4, this._y4);
15813 this.point(this._x5, this._y5);
15814 break;
15815 }
15816 }
15817 },
15818 point: function(x, y) {
15819 x = +x, y = +y;
15820 switch (this._point) {
15821 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
15822 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
15823 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
15824 default: point$3(this, x, y); break;
15825 }
15826 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15827 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15828 }
15829};
15830
15831var cardinalClosed = (function custom(tension) {
15832
15833 function cardinal(context) {
15834 return new CardinalClosed(context, tension);
15835 }
15836
15837 cardinal.tension = function(tension) {
15838 return custom(+tension);
15839 };
15840
15841 return cardinal;
15842})(0);
15843
15844function CardinalOpen(context, tension) {
15845 this._context = context;
15846 this._k = (1 - tension) / 6;
15847}
15848
15849CardinalOpen.prototype = {
15850 areaStart: function() {
15851 this._line = 0;
15852 },
15853 areaEnd: function() {
15854 this._line = NaN;
15855 },
15856 lineStart: function() {
15857 this._x0 = this._x1 = this._x2 =
15858 this._y0 = this._y1 = this._y2 = NaN;
15859 this._point = 0;
15860 },
15861 lineEnd: function() {
15862 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15863 this._line = 1 - this._line;
15864 },
15865 point: function(x, y) {
15866 x = +x, y = +y;
15867 switch (this._point) {
15868 case 0: this._point = 1; break;
15869 case 1: this._point = 2; break;
15870 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
15871 case 3: this._point = 4; // proceed
15872 default: point$3(this, x, y); break;
15873 }
15874 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15875 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15876 }
15877};
15878
15879var cardinalOpen = (function custom(tension) {
15880
15881 function cardinal(context) {
15882 return new CardinalOpen(context, tension);
15883 }
15884
15885 cardinal.tension = function(tension) {
15886 return custom(+tension);
15887 };
15888
15889 return cardinal;
15890})(0);
15891
15892function point$4(that, x, y) {
15893 var x1 = that._x1,
15894 y1 = that._y1,
15895 x2 = that._x2,
15896 y2 = that._y2;
15897
15898 if (that._l01_a > epsilon$3) {
15899 var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
15900 n = 3 * that._l01_a * (that._l01_a + that._l12_a);
15901 x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
15902 y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
15903 }
15904
15905 if (that._l23_a > epsilon$3) {
15906 var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
15907 m = 3 * that._l23_a * (that._l23_a + that._l12_a);
15908 x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
15909 y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
15910 }
15911
15912 that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
15913}
15914
15915function CatmullRom(context, alpha) {
15916 this._context = context;
15917 this._alpha = alpha;
15918}
15919
15920CatmullRom.prototype = {
15921 areaStart: function() {
15922 this._line = 0;
15923 },
15924 areaEnd: function() {
15925 this._line = NaN;
15926 },
15927 lineStart: function() {
15928 this._x0 = this._x1 = this._x2 =
15929 this._y0 = this._y1 = this._y2 = NaN;
15930 this._l01_a = this._l12_a = this._l23_a =
15931 this._l01_2a = this._l12_2a = this._l23_2a =
15932 this._point = 0;
15933 },
15934 lineEnd: function() {
15935 switch (this._point) {
15936 case 2: this._context.lineTo(this._x2, this._y2); break;
15937 case 3: this.point(this._x2, this._y2); break;
15938 }
15939 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15940 this._line = 1 - this._line;
15941 },
15942 point: function(x, y) {
15943 x = +x, y = +y;
15944
15945 if (this._point) {
15946 var x23 = this._x2 - x,
15947 y23 = this._y2 - y;
15948 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15949 }
15950
15951 switch (this._point) {
15952 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15953 case 1: this._point = 2; break;
15954 case 2: this._point = 3; // proceed
15955 default: point$4(this, x, y); break;
15956 }
15957
15958 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15959 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15960 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15961 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15962 }
15963};
15964
15965var catmullRom = (function custom(alpha) {
15966
15967 function catmullRom(context) {
15968 return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
15969 }
15970
15971 catmullRom.alpha = function(alpha) {
15972 return custom(+alpha);
15973 };
15974
15975 return catmullRom;
15976})(0.5);
15977
15978function CatmullRomClosed(context, alpha) {
15979 this._context = context;
15980 this._alpha = alpha;
15981}
15982
15983CatmullRomClosed.prototype = {
15984 areaStart: noop$3,
15985 areaEnd: noop$3,
15986 lineStart: function() {
15987 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
15988 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
15989 this._l01_a = this._l12_a = this._l23_a =
15990 this._l01_2a = this._l12_2a = this._l23_2a =
15991 this._point = 0;
15992 },
15993 lineEnd: function() {
15994 switch (this._point) {
15995 case 1: {
15996 this._context.moveTo(this._x3, this._y3);
15997 this._context.closePath();
15998 break;
15999 }
16000 case 2: {
16001 this._context.lineTo(this._x3, this._y3);
16002 this._context.closePath();
16003 break;
16004 }
16005 case 3: {
16006 this.point(this._x3, this._y3);
16007 this.point(this._x4, this._y4);
16008 this.point(this._x5, this._y5);
16009 break;
16010 }
16011 }
16012 },
16013 point: function(x, y) {
16014 x = +x, y = +y;
16015
16016 if (this._point) {
16017 var x23 = this._x2 - x,
16018 y23 = this._y2 - y;
16019 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
16020 }
16021
16022 switch (this._point) {
16023 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
16024 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
16025 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
16026 default: point$4(this, x, y); break;
16027 }
16028
16029 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
16030 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
16031 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
16032 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
16033 }
16034};
16035
16036var catmullRomClosed = (function custom(alpha) {
16037
16038 function catmullRom(context) {
16039 return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
16040 }
16041
16042 catmullRom.alpha = function(alpha) {
16043 return custom(+alpha);
16044 };
16045
16046 return catmullRom;
16047})(0.5);
16048
16049function CatmullRomOpen(context, alpha) {
16050 this._context = context;
16051 this._alpha = alpha;
16052}
16053
16054CatmullRomOpen.prototype = {
16055 areaStart: function() {
16056 this._line = 0;
16057 },
16058 areaEnd: function() {
16059 this._line = NaN;
16060 },
16061 lineStart: function() {
16062 this._x0 = this._x1 = this._x2 =
16063 this._y0 = this._y1 = this._y2 = NaN;
16064 this._l01_a = this._l12_a = this._l23_a =
16065 this._l01_2a = this._l12_2a = this._l23_2a =
16066 this._point = 0;
16067 },
16068 lineEnd: function() {
16069 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
16070 this._line = 1 - this._line;
16071 },
16072 point: function(x, y) {
16073 x = +x, y = +y;
16074
16075 if (this._point) {
16076 var x23 = this._x2 - x,
16077 y23 = this._y2 - y;
16078 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
16079 }
16080
16081 switch (this._point) {
16082 case 0: this._point = 1; break;
16083 case 1: this._point = 2; break;
16084 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
16085 case 3: this._point = 4; // proceed
16086 default: point$4(this, x, y); break;
16087 }
16088
16089 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
16090 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
16091 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
16092 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
16093 }
16094};
16095
16096var catmullRomOpen = (function custom(alpha) {
16097
16098 function catmullRom(context) {
16099 return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
16100 }
16101
16102 catmullRom.alpha = function(alpha) {
16103 return custom(+alpha);
16104 };
16105
16106 return catmullRom;
16107})(0.5);
16108
16109function LinearClosed(context) {
16110 this._context = context;
16111}
16112
16113LinearClosed.prototype = {
16114 areaStart: noop$3,
16115 areaEnd: noop$3,
16116 lineStart: function() {
16117 this._point = 0;
16118 },
16119 lineEnd: function() {
16120 if (this._point) this._context.closePath();
16121 },
16122 point: function(x, y) {
16123 x = +x, y = +y;
16124 if (this._point) this._context.lineTo(x, y);
16125 else this._point = 1, this._context.moveTo(x, y);
16126 }
16127};
16128
16129function linearClosed(context) {
16130 return new LinearClosed(context);
16131}
16132
16133function sign$1(x) {
16134 return x < 0 ? -1 : 1;
16135}
16136
16137// Calculate the slopes of the tangents (Hermite-type interpolation) based on
16138// the following paper: Steffen, M. 1990. A Simple Method for Monotonic
16139// Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
16140// NOV(II), P. 443, 1990.
16141function slope3(that, x2, y2) {
16142 var h0 = that._x1 - that._x0,
16143 h1 = x2 - that._x1,
16144 s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
16145 s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
16146 p = (s0 * h1 + s1 * h0) / (h0 + h1);
16147 return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
16148}
16149
16150// Calculate a one-sided slope.
16151function slope2(that, t) {
16152 var h = that._x1 - that._x0;
16153 return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
16154}
16155
16156// According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
16157// "you can express cubic Hermite interpolation in terms of cubic Bézier curves
16158// with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
16159function point$5(that, t0, t1) {
16160 var x0 = that._x0,
16161 y0 = that._y0,
16162 x1 = that._x1,
16163 y1 = that._y1,
16164 dx = (x1 - x0) / 3;
16165 that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
16166}
16167
16168function MonotoneX(context) {
16169 this._context = context;
16170}
16171
16172MonotoneX.prototype = {
16173 areaStart: function() {
16174 this._line = 0;
16175 },
16176 areaEnd: function() {
16177 this._line = NaN;
16178 },
16179 lineStart: function() {
16180 this._x0 = this._x1 =
16181 this._y0 = this._y1 =
16182 this._t0 = NaN;
16183 this._point = 0;
16184 },
16185 lineEnd: function() {
16186 switch (this._point) {
16187 case 2: this._context.lineTo(this._x1, this._y1); break;
16188 case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
16189 }
16190 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
16191 this._line = 1 - this._line;
16192 },
16193 point: function(x, y) {
16194 var t1 = NaN;
16195
16196 x = +x, y = +y;
16197 if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
16198 switch (this._point) {
16199 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
16200 case 1: this._point = 2; break;
16201 case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
16202 default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
16203 }
16204
16205 this._x0 = this._x1, this._x1 = x;
16206 this._y0 = this._y1, this._y1 = y;
16207 this._t0 = t1;
16208 }
16209};
16210
16211function MonotoneY(context) {
16212 this._context = new ReflectContext(context);
16213}
16214
16215(MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
16216 MonotoneX.prototype.point.call(this, y, x);
16217};
16218
16219function ReflectContext(context) {
16220 this._context = context;
16221}
16222
16223ReflectContext.prototype = {
16224 moveTo: function(x, y) { this._context.moveTo(y, x); },
16225 closePath: function() { this._context.closePath(); },
16226 lineTo: function(x, y) { this._context.lineTo(y, x); },
16227 bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
16228};
16229
16230function monotoneX(context) {
16231 return new MonotoneX(context);
16232}
16233
16234function monotoneY(context) {
16235 return new MonotoneY(context);
16236}
16237
16238function Natural(context) {
16239 this._context = context;
16240}
16241
16242Natural.prototype = {
16243 areaStart: function() {
16244 this._line = 0;
16245 },
16246 areaEnd: function() {
16247 this._line = NaN;
16248 },
16249 lineStart: function() {
16250 this._x = [];
16251 this._y = [];
16252 },
16253 lineEnd: function() {
16254 var x = this._x,
16255 y = this._y,
16256 n = x.length;
16257
16258 if (n) {
16259 this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
16260 if (n === 2) {
16261 this._context.lineTo(x[1], y[1]);
16262 } else {
16263 var px = controlPoints(x),
16264 py = controlPoints(y);
16265 for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
16266 this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
16267 }
16268 }
16269 }
16270
16271 if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
16272 this._line = 1 - this._line;
16273 this._x = this._y = null;
16274 },
16275 point: function(x, y) {
16276 this._x.push(+x);
16277 this._y.push(+y);
16278 }
16279};
16280
16281// See https://www.particleincell.com/2012/bezier-splines/ for derivation.
16282function controlPoints(x) {
16283 var i,
16284 n = x.length - 1,
16285 m,
16286 a = new Array(n),
16287 b = new Array(n),
16288 r = new Array(n);
16289 a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
16290 for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
16291 a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
16292 for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
16293 a[n - 1] = r[n - 1] / b[n - 1];
16294 for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
16295 b[n - 1] = (x[n] + a[n - 1]) / 2;
16296 for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
16297 return [a, b];
16298}
16299
16300function natural(context) {
16301 return new Natural(context);
16302}
16303
16304function Step(context, t) {
16305 this._context = context;
16306 this._t = t;
16307}
16308
16309Step.prototype = {
16310 areaStart: function() {
16311 this._line = 0;
16312 },
16313 areaEnd: function() {
16314 this._line = NaN;
16315 },
16316 lineStart: function() {
16317 this._x = this._y = NaN;
16318 this._point = 0;
16319 },
16320 lineEnd: function() {
16321 if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
16322 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
16323 if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
16324 },
16325 point: function(x, y) {
16326 x = +x, y = +y;
16327 switch (this._point) {
16328 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
16329 case 1: this._point = 2; // proceed
16330 default: {
16331 if (this._t <= 0) {
16332 this._context.lineTo(this._x, y);
16333 this._context.lineTo(x, y);
16334 } else {
16335 var x1 = this._x * (1 - this._t) + x * this._t;
16336 this._context.lineTo(x1, this._y);
16337 this._context.lineTo(x1, y);
16338 }
16339 break;
16340 }
16341 }
16342 this._x = x, this._y = y;
16343 }
16344};
16345
16346function step(context) {
16347 return new Step(context, 0.5);
16348}
16349
16350function stepBefore(context) {
16351 return new Step(context, 0);
16352}
16353
16354function stepAfter(context) {
16355 return new Step(context, 1);
16356}
16357
16358function none$1(series, order) {
16359 if (!((n = series.length) > 1)) return;
16360 for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
16361 s0 = s1, s1 = series[order[i]];
16362 for (j = 0; j < m; ++j) {
16363 s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
16364 }
16365 }
16366}
16367
16368function none$2(series) {
16369 var n = series.length, o = new Array(n);
16370 while (--n >= 0) o[n] = n;
16371 return o;
16372}
16373
16374function stackValue(d, key) {
16375 return d[key];
16376}
16377
16378function stack() {
16379 var keys = constant$b([]),
16380 order = none$2,
16381 offset = none$1,
16382 value = stackValue;
16383
16384 function stack(data) {
16385 var kz = keys.apply(this, arguments),
16386 i,
16387 m = data.length,
16388 n = kz.length,
16389 sz = new Array(n),
16390 oz;
16391
16392 for (i = 0; i < n; ++i) {
16393 for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
16394 si[j] = sij = [0, +value(data[j], ki, j, data)];
16395 sij.data = data[j];
16396 }
16397 si.key = ki;
16398 }
16399
16400 for (i = 0, oz = order(sz); i < n; ++i) {
16401 sz[oz[i]].index = i;
16402 }
16403
16404 offset(sz, oz);
16405 return sz;
16406 }
16407
16408 stack.keys = function(_) {
16409 return arguments.length ? (keys = typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : keys;
16410 };
16411
16412 stack.value = function(_) {
16413 return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), stack) : value;
16414 };
16415
16416 stack.order = function(_) {
16417 return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : order;
16418 };
16419
16420 stack.offset = function(_) {
16421 return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
16422 };
16423
16424 return stack;
16425}
16426
16427function expand(series, order) {
16428 if (!((n = series.length) > 0)) return;
16429 for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
16430 for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
16431 if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
16432 }
16433 none$1(series, order);
16434}
16435
16436function diverging$1(series, order) {
16437 if (!((n = series.length) > 0)) return;
16438 for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
16439 for (yp = yn = 0, i = 0; i < n; ++i) {
16440 if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
16441 d[0] = yp, d[1] = yp += dy;
16442 } else if (dy < 0) {
16443 d[1] = yn, d[0] = yn += dy;
16444 } else {
16445 d[0] = 0, d[1] = dy;
16446 }
16447 }
16448 }
16449}
16450
16451function silhouette(series, order) {
16452 if (!((n = series.length) > 0)) return;
16453 for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
16454 for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
16455 s0[j][1] += s0[j][0] = -y / 2;
16456 }
16457 none$1(series, order);
16458}
16459
16460function wiggle(series, order) {
16461 if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
16462 for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
16463 for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
16464 var si = series[order[i]],
16465 sij0 = si[j][1] || 0,
16466 sij1 = si[j - 1][1] || 0,
16467 s3 = (sij0 - sij1) / 2;
16468 for (var k = 0; k < i; ++k) {
16469 var sk = series[order[k]],
16470 skj0 = sk[j][1] || 0,
16471 skj1 = sk[j - 1][1] || 0;
16472 s3 += skj0 - skj1;
16473 }
16474 s1 += sij0, s2 += s3 * sij0;
16475 }
16476 s0[j - 1][1] += s0[j - 1][0] = y;
16477 if (s1) y -= s2 / s1;
16478 }
16479 s0[j - 1][1] += s0[j - 1][0] = y;
16480 none$1(series, order);
16481}
16482
16483function appearance(series) {
16484 var peaks = series.map(peak);
16485 return none$2(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
16486}
16487
16488function peak(series) {
16489 var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
16490 while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
16491 return j;
16492}
16493
16494function ascending$3(series) {
16495 var sums = series.map(sum$2);
16496 return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
16497}
16498
16499function sum$2(series) {
16500 var s = 0, i = -1, n = series.length, v;
16501 while (++i < n) if (v = +series[i][1]) s += v;
16502 return s;
16503}
16504
16505function descending$2(series) {
16506 return ascending$3(series).reverse();
16507}
16508
16509function insideOut(series) {
16510 var n = series.length,
16511 i,
16512 j,
16513 sums = series.map(sum$2),
16514 order = appearance(series),
16515 top = 0,
16516 bottom = 0,
16517 tops = [],
16518 bottoms = [];
16519
16520 for (i = 0; i < n; ++i) {
16521 j = order[i];
16522 if (top < bottom) {
16523 top += sums[j];
16524 tops.push(j);
16525 } else {
16526 bottom += sums[j];
16527 bottoms.push(j);
16528 }
16529 }
16530
16531 return bottoms.reverse().concat(tops);
16532}
16533
16534function reverse(series) {
16535 return none$2(series).reverse();
16536}
16537
16538function constant$c(x) {
16539 return function() {
16540 return x;
16541 };
16542}
16543
16544function x$4(d) {
16545 return d[0];
16546}
16547
16548function y$4(d) {
16549 return d[1];
16550}
16551
16552function RedBlackTree() {
16553 this._ = null; // root node
16554}
16555
16556function RedBlackNode(node) {
16557 node.U = // parent node
16558 node.C = // color - true for red, false for black
16559 node.L = // left node
16560 node.R = // right node
16561 node.P = // previous node
16562 node.N = null; // next node
16563}
16564
16565RedBlackTree.prototype = {
16566 constructor: RedBlackTree,
16567
16568 insert: function(after, node) {
16569 var parent, grandpa, uncle;
16570
16571 if (after) {
16572 node.P = after;
16573 node.N = after.N;
16574 if (after.N) after.N.P = node;
16575 after.N = node;
16576 if (after.R) {
16577 after = after.R;
16578 while (after.L) after = after.L;
16579 after.L = node;
16580 } else {
16581 after.R = node;
16582 }
16583 parent = after;
16584 } else if (this._) {
16585 after = RedBlackFirst(this._);
16586 node.P = null;
16587 node.N = after;
16588 after.P = after.L = node;
16589 parent = after;
16590 } else {
16591 node.P = node.N = null;
16592 this._ = node;
16593 parent = null;
16594 }
16595 node.L = node.R = null;
16596 node.U = parent;
16597 node.C = true;
16598
16599 after = node;
16600 while (parent && parent.C) {
16601 grandpa = parent.U;
16602 if (parent === grandpa.L) {
16603 uncle = grandpa.R;
16604 if (uncle && uncle.C) {
16605 parent.C = uncle.C = false;
16606 grandpa.C = true;
16607 after = grandpa;
16608 } else {
16609 if (after === parent.R) {
16610 RedBlackRotateLeft(this, parent);
16611 after = parent;
16612 parent = after.U;
16613 }
16614 parent.C = false;
16615 grandpa.C = true;
16616 RedBlackRotateRight(this, grandpa);
16617 }
16618 } else {
16619 uncle = grandpa.L;
16620 if (uncle && uncle.C) {
16621 parent.C = uncle.C = false;
16622 grandpa.C = true;
16623 after = grandpa;
16624 } else {
16625 if (after === parent.L) {
16626 RedBlackRotateRight(this, parent);
16627 after = parent;
16628 parent = after.U;
16629 }
16630 parent.C = false;
16631 grandpa.C = true;
16632 RedBlackRotateLeft(this, grandpa);
16633 }
16634 }
16635 parent = after.U;
16636 }
16637 this._.C = false;
16638 },
16639
16640 remove: function(node) {
16641 if (node.N) node.N.P = node.P;
16642 if (node.P) node.P.N = node.N;
16643 node.N = node.P = null;
16644
16645 var parent = node.U,
16646 sibling,
16647 left = node.L,
16648 right = node.R,
16649 next,
16650 red;
16651
16652 if (!left) next = right;
16653 else if (!right) next = left;
16654 else next = RedBlackFirst(right);
16655
16656 if (parent) {
16657 if (parent.L === node) parent.L = next;
16658 else parent.R = next;
16659 } else {
16660 this._ = next;
16661 }
16662
16663 if (left && right) {
16664 red = next.C;
16665 next.C = node.C;
16666 next.L = left;
16667 left.U = next;
16668 if (next !== right) {
16669 parent = next.U;
16670 next.U = node.U;
16671 node = next.R;
16672 parent.L = node;
16673 next.R = right;
16674 right.U = next;
16675 } else {
16676 next.U = parent;
16677 parent = next;
16678 node = next.R;
16679 }
16680 } else {
16681 red = node.C;
16682 node = next;
16683 }
16684
16685 if (node) node.U = parent;
16686 if (red) return;
16687 if (node && node.C) { node.C = false; return; }
16688
16689 do {
16690 if (node === this._) break;
16691 if (node === parent.L) {
16692 sibling = parent.R;
16693 if (sibling.C) {
16694 sibling.C = false;
16695 parent.C = true;
16696 RedBlackRotateLeft(this, parent);
16697 sibling = parent.R;
16698 }
16699 if ((sibling.L && sibling.L.C)
16700 || (sibling.R && sibling.R.C)) {
16701 if (!sibling.R || !sibling.R.C) {
16702 sibling.L.C = false;
16703 sibling.C = true;
16704 RedBlackRotateRight(this, sibling);
16705 sibling = parent.R;
16706 }
16707 sibling.C = parent.C;
16708 parent.C = sibling.R.C = false;
16709 RedBlackRotateLeft(this, parent);
16710 node = this._;
16711 break;
16712 }
16713 } else {
16714 sibling = parent.L;
16715 if (sibling.C) {
16716 sibling.C = false;
16717 parent.C = true;
16718 RedBlackRotateRight(this, parent);
16719 sibling = parent.L;
16720 }
16721 if ((sibling.L && sibling.L.C)
16722 || (sibling.R && sibling.R.C)) {
16723 if (!sibling.L || !sibling.L.C) {
16724 sibling.R.C = false;
16725 sibling.C = true;
16726 RedBlackRotateLeft(this, sibling);
16727 sibling = parent.L;
16728 }
16729 sibling.C = parent.C;
16730 parent.C = sibling.L.C = false;
16731 RedBlackRotateRight(this, parent);
16732 node = this._;
16733 break;
16734 }
16735 }
16736 sibling.C = true;
16737 node = parent;
16738 parent = parent.U;
16739 } while (!node.C);
16740
16741 if (node) node.C = false;
16742 }
16743};
16744
16745function RedBlackRotateLeft(tree, node) {
16746 var p = node,
16747 q = node.R,
16748 parent = p.U;
16749
16750 if (parent) {
16751 if (parent.L === p) parent.L = q;
16752 else parent.R = q;
16753 } else {
16754 tree._ = q;
16755 }
16756
16757 q.U = parent;
16758 p.U = q;
16759 p.R = q.L;
16760 if (p.R) p.R.U = p;
16761 q.L = p;
16762}
16763
16764function RedBlackRotateRight(tree, node) {
16765 var p = node,
16766 q = node.L,
16767 parent = p.U;
16768
16769 if (parent) {
16770 if (parent.L === p) parent.L = q;
16771 else parent.R = q;
16772 } else {
16773 tree._ = q;
16774 }
16775
16776 q.U = parent;
16777 p.U = q;
16778 p.L = q.R;
16779 if (p.L) p.L.U = p;
16780 q.R = p;
16781}
16782
16783function RedBlackFirst(node) {
16784 while (node.L) node = node.L;
16785 return node;
16786}
16787
16788function createEdge(left, right, v0, v1) {
16789 var edge = [null, null],
16790 index = edges.push(edge) - 1;
16791 edge.left = left;
16792 edge.right = right;
16793 if (v0) setEdgeEnd(edge, left, right, v0);
16794 if (v1) setEdgeEnd(edge, right, left, v1);
16795 cells[left.index].halfedges.push(index);
16796 cells[right.index].halfedges.push(index);
16797 return edge;
16798}
16799
16800function createBorderEdge(left, v0, v1) {
16801 var edge = [v0, v1];
16802 edge.left = left;
16803 return edge;
16804}
16805
16806function setEdgeEnd(edge, left, right, vertex) {
16807 if (!edge[0] && !edge[1]) {
16808 edge[0] = vertex;
16809 edge.left = left;
16810 edge.right = right;
16811 } else if (edge.left === right) {
16812 edge[1] = vertex;
16813 } else {
16814 edge[0] = vertex;
16815 }
16816}
16817
16818// Liang–Barsky line clipping.
16819function clipEdge(edge, x0, y0, x1, y1) {
16820 var a = edge[0],
16821 b = edge[1],
16822 ax = a[0],
16823 ay = a[1],
16824 bx = b[0],
16825 by = b[1],
16826 t0 = 0,
16827 t1 = 1,
16828 dx = bx - ax,
16829 dy = by - ay,
16830 r;
16831
16832 r = x0 - ax;
16833 if (!dx && r > 0) return;
16834 r /= dx;
16835 if (dx < 0) {
16836 if (r < t0) return;
16837 if (r < t1) t1 = r;
16838 } else if (dx > 0) {
16839 if (r > t1) return;
16840 if (r > t0) t0 = r;
16841 }
16842
16843 r = x1 - ax;
16844 if (!dx && r < 0) return;
16845 r /= dx;
16846 if (dx < 0) {
16847 if (r > t1) return;
16848 if (r > t0) t0 = r;
16849 } else if (dx > 0) {
16850 if (r < t0) return;
16851 if (r < t1) t1 = r;
16852 }
16853
16854 r = y0 - ay;
16855 if (!dy && r > 0) return;
16856 r /= dy;
16857 if (dy < 0) {
16858 if (r < t0) return;
16859 if (r < t1) t1 = r;
16860 } else if (dy > 0) {
16861 if (r > t1) return;
16862 if (r > t0) t0 = r;
16863 }
16864
16865 r = y1 - ay;
16866 if (!dy && r < 0) return;
16867 r /= dy;
16868 if (dy < 0) {
16869 if (r > t1) return;
16870 if (r > t0) t0 = r;
16871 } else if (dy > 0) {
16872 if (r < t0) return;
16873 if (r < t1) t1 = r;
16874 }
16875
16876 if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
16877
16878 if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
16879 if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
16880 return true;
16881}
16882
16883function connectEdge(edge, x0, y0, x1, y1) {
16884 var v1 = edge[1];
16885 if (v1) return true;
16886
16887 var v0 = edge[0],
16888 left = edge.left,
16889 right = edge.right,
16890 lx = left[0],
16891 ly = left[1],
16892 rx = right[0],
16893 ry = right[1],
16894 fx = (lx + rx) / 2,
16895 fy = (ly + ry) / 2,
16896 fm,
16897 fb;
16898
16899 if (ry === ly) {
16900 if (fx < x0 || fx >= x1) return;
16901 if (lx > rx) {
16902 if (!v0) v0 = [fx, y0];
16903 else if (v0[1] >= y1) return;
16904 v1 = [fx, y1];
16905 } else {
16906 if (!v0) v0 = [fx, y1];
16907 else if (v0[1] < y0) return;
16908 v1 = [fx, y0];
16909 }
16910 } else {
16911 fm = (lx - rx) / (ry - ly);
16912 fb = fy - fm * fx;
16913 if (fm < -1 || fm > 1) {
16914 if (lx > rx) {
16915 if (!v0) v0 = [(y0 - fb) / fm, y0];
16916 else if (v0[1] >= y1) return;
16917 v1 = [(y1 - fb) / fm, y1];
16918 } else {
16919 if (!v0) v0 = [(y1 - fb) / fm, y1];
16920 else if (v0[1] < y0) return;
16921 v1 = [(y0 - fb) / fm, y0];
16922 }
16923 } else {
16924 if (ly < ry) {
16925 if (!v0) v0 = [x0, fm * x0 + fb];
16926 else if (v0[0] >= x1) return;
16927 v1 = [x1, fm * x1 + fb];
16928 } else {
16929 if (!v0) v0 = [x1, fm * x1 + fb];
16930 else if (v0[0] < x0) return;
16931 v1 = [x0, fm * x0 + fb];
16932 }
16933 }
16934 }
16935
16936 edge[0] = v0;
16937 edge[1] = v1;
16938 return true;
16939}
16940
16941function clipEdges(x0, y0, x1, y1) {
16942 var i = edges.length,
16943 edge;
16944
16945 while (i--) {
16946 if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
16947 || !clipEdge(edge, x0, y0, x1, y1)
16948 || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
16949 || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
16950 delete edges[i];
16951 }
16952 }
16953}
16954
16955function createCell(site) {
16956 return cells[site.index] = {
16957 site: site,
16958 halfedges: []
16959 };
16960}
16961
16962function cellHalfedgeAngle(cell, edge) {
16963 var site = cell.site,
16964 va = edge.left,
16965 vb = edge.right;
16966 if (site === vb) vb = va, va = site;
16967 if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
16968 if (site === va) va = edge[1], vb = edge[0];
16969 else va = edge[0], vb = edge[1];
16970 return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
16971}
16972
16973function cellHalfedgeStart(cell, edge) {
16974 return edge[+(edge.left !== cell.site)];
16975}
16976
16977function cellHalfedgeEnd(cell, edge) {
16978 return edge[+(edge.left === cell.site)];
16979}
16980
16981function sortCellHalfedges() {
16982 for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
16983 if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
16984 var index = new Array(m),
16985 array = new Array(m);
16986 for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
16987 index.sort(function(i, j) { return array[j] - array[i]; });
16988 for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
16989 for (j = 0; j < m; ++j) halfedges[j] = array[j];
16990 }
16991 }
16992}
16993
16994function clipCells(x0, y0, x1, y1) {
16995 var nCells = cells.length,
16996 iCell,
16997 cell,
16998 site,
16999 iHalfedge,
17000 halfedges,
17001 nHalfedges,
17002 start,
17003 startX,
17004 startY,
17005 end,
17006 endX,
17007 endY,
17008 cover = true;
17009
17010 for (iCell = 0; iCell < nCells; ++iCell) {
17011 if (cell = cells[iCell]) {
17012 site = cell.site;
17013 halfedges = cell.halfedges;
17014 iHalfedge = halfedges.length;
17015
17016 // Remove any dangling clipped edges.
17017 while (iHalfedge--) {
17018 if (!edges[halfedges[iHalfedge]]) {
17019 halfedges.splice(iHalfedge, 1);
17020 }
17021 }
17022
17023 // Insert any border edges as necessary.
17024 iHalfedge = 0, nHalfedges = halfedges.length;
17025 while (iHalfedge < nHalfedges) {
17026 end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
17027 start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
17028 if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
17029 halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
17030 Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
17031 : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
17032 : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
17033 : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
17034 : null)) - 1);
17035 ++nHalfedges;
17036 }
17037 }
17038
17039 if (nHalfedges) cover = false;
17040 }
17041 }
17042
17043 // If there weren’t any edges, have the closest site cover the extent.
17044 // It doesn’t matter which corner of the extent we measure!
17045 if (cover) {
17046 var dx, dy, d2, dc = Infinity;
17047
17048 for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
17049 if (cell = cells[iCell]) {
17050 site = cell.site;
17051 dx = site[0] - x0;
17052 dy = site[1] - y0;
17053 d2 = dx * dx + dy * dy;
17054 if (d2 < dc) dc = d2, cover = cell;
17055 }
17056 }
17057
17058 if (cover) {
17059 var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
17060 cover.halfedges.push(
17061 edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
17062 edges.push(createBorderEdge(site, v01, v11)) - 1,
17063 edges.push(createBorderEdge(site, v11, v10)) - 1,
17064 edges.push(createBorderEdge(site, v10, v00)) - 1
17065 );
17066 }
17067 }
17068
17069 // Lastly delete any cells with no edges; these were entirely clipped.
17070 for (iCell = 0; iCell < nCells; ++iCell) {
17071 if (cell = cells[iCell]) {
17072 if (!cell.halfedges.length) {
17073 delete cells[iCell];
17074 }
17075 }
17076 }
17077}
17078
17079var circlePool = [];
17080
17081var firstCircle;
17082
17083function Circle() {
17084 RedBlackNode(this);
17085 this.x =
17086 this.y =
17087 this.arc =
17088 this.site =
17089 this.cy = null;
17090}
17091
17092function attachCircle(arc) {
17093 var lArc = arc.P,
17094 rArc = arc.N;
17095
17096 if (!lArc || !rArc) return;
17097
17098 var lSite = lArc.site,
17099 cSite = arc.site,
17100 rSite = rArc.site;
17101
17102 if (lSite === rSite) return;
17103
17104 var bx = cSite[0],
17105 by = cSite[1],
17106 ax = lSite[0] - bx,
17107 ay = lSite[1] - by,
17108 cx = rSite[0] - bx,
17109 cy = rSite[1] - by;
17110
17111 var d = 2 * (ax * cy - ay * cx);
17112 if (d >= -epsilon2$2) return;
17113
17114 var ha = ax * ax + ay * ay,
17115 hc = cx * cx + cy * cy,
17116 x = (cy * ha - ay * hc) / d,
17117 y = (ax * hc - cx * ha) / d;
17118
17119 var circle = circlePool.pop() || new Circle;
17120 circle.arc = arc;
17121 circle.site = cSite;
17122 circle.x = x + bx;
17123 circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
17124
17125 arc.circle = circle;
17126
17127 var before = null,
17128 node = circles._;
17129
17130 while (node) {
17131 if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
17132 if (node.L) node = node.L;
17133 else { before = node.P; break; }
17134 } else {
17135 if (node.R) node = node.R;
17136 else { before = node; break; }
17137 }
17138 }
17139
17140 circles.insert(before, circle);
17141 if (!before) firstCircle = circle;
17142}
17143
17144function detachCircle(arc) {
17145 var circle = arc.circle;
17146 if (circle) {
17147 if (!circle.P) firstCircle = circle.N;
17148 circles.remove(circle);
17149 circlePool.push(circle);
17150 RedBlackNode(circle);
17151 arc.circle = null;
17152 }
17153}
17154
17155var beachPool = [];
17156
17157function Beach() {
17158 RedBlackNode(this);
17159 this.edge =
17160 this.site =
17161 this.circle = null;
17162}
17163
17164function createBeach(site) {
17165 var beach = beachPool.pop() || new Beach;
17166 beach.site = site;
17167 return beach;
17168}
17169
17170function detachBeach(beach) {
17171 detachCircle(beach);
17172 beaches.remove(beach);
17173 beachPool.push(beach);
17174 RedBlackNode(beach);
17175}
17176
17177function removeBeach(beach) {
17178 var circle = beach.circle,
17179 x = circle.x,
17180 y = circle.cy,
17181 vertex = [x, y],
17182 previous = beach.P,
17183 next = beach.N,
17184 disappearing = [beach];
17185
17186 detachBeach(beach);
17187
17188 var lArc = previous;
17189 while (lArc.circle
17190 && Math.abs(x - lArc.circle.x) < epsilon$4
17191 && Math.abs(y - lArc.circle.cy) < epsilon$4) {
17192 previous = lArc.P;
17193 disappearing.unshift(lArc);
17194 detachBeach(lArc);
17195 lArc = previous;
17196 }
17197
17198 disappearing.unshift(lArc);
17199 detachCircle(lArc);
17200
17201 var rArc = next;
17202 while (rArc.circle
17203 && Math.abs(x - rArc.circle.x) < epsilon$4
17204 && Math.abs(y - rArc.circle.cy) < epsilon$4) {
17205 next = rArc.N;
17206 disappearing.push(rArc);
17207 detachBeach(rArc);
17208 rArc = next;
17209 }
17210
17211 disappearing.push(rArc);
17212 detachCircle(rArc);
17213
17214 var nArcs = disappearing.length,
17215 iArc;
17216 for (iArc = 1; iArc < nArcs; ++iArc) {
17217 rArc = disappearing[iArc];
17218 lArc = disappearing[iArc - 1];
17219 setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
17220 }
17221
17222 lArc = disappearing[0];
17223 rArc = disappearing[nArcs - 1];
17224 rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
17225
17226 attachCircle(lArc);
17227 attachCircle(rArc);
17228}
17229
17230function addBeach(site) {
17231 var x = site[0],
17232 directrix = site[1],
17233 lArc,
17234 rArc,
17235 dxl,
17236 dxr,
17237 node = beaches._;
17238
17239 while (node) {
17240 dxl = leftBreakPoint(node, directrix) - x;
17241 if (dxl > epsilon$4) node = node.L; else {
17242 dxr = x - rightBreakPoint(node, directrix);
17243 if (dxr > epsilon$4) {
17244 if (!node.R) {
17245 lArc = node;
17246 break;
17247 }
17248 node = node.R;
17249 } else {
17250 if (dxl > -epsilon$4) {
17251 lArc = node.P;
17252 rArc = node;
17253 } else if (dxr > -epsilon$4) {
17254 lArc = node;
17255 rArc = node.N;
17256 } else {
17257 lArc = rArc = node;
17258 }
17259 break;
17260 }
17261 }
17262 }
17263
17264 createCell(site);
17265 var newArc = createBeach(site);
17266 beaches.insert(lArc, newArc);
17267
17268 if (!lArc && !rArc) return;
17269
17270 if (lArc === rArc) {
17271 detachCircle(lArc);
17272 rArc = createBeach(lArc.site);
17273 beaches.insert(newArc, rArc);
17274 newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
17275 attachCircle(lArc);
17276 attachCircle(rArc);
17277 return;
17278 }
17279
17280 if (!rArc) { // && lArc
17281 newArc.edge = createEdge(lArc.site, newArc.site);
17282 return;
17283 }
17284
17285 // else lArc !== rArc
17286 detachCircle(lArc);
17287 detachCircle(rArc);
17288
17289 var lSite = lArc.site,
17290 ax = lSite[0],
17291 ay = lSite[1],
17292 bx = site[0] - ax,
17293 by = site[1] - ay,
17294 rSite = rArc.site,
17295 cx = rSite[0] - ax,
17296 cy = rSite[1] - ay,
17297 d = 2 * (bx * cy - by * cx),
17298 hb = bx * bx + by * by,
17299 hc = cx * cx + cy * cy,
17300 vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
17301
17302 setEdgeEnd(rArc.edge, lSite, rSite, vertex);
17303 newArc.edge = createEdge(lSite, site, null, vertex);
17304 rArc.edge = createEdge(site, rSite, null, vertex);
17305 attachCircle(lArc);
17306 attachCircle(rArc);
17307}
17308
17309function leftBreakPoint(arc, directrix) {
17310 var site = arc.site,
17311 rfocx = site[0],
17312 rfocy = site[1],
17313 pby2 = rfocy - directrix;
17314
17315 if (!pby2) return rfocx;
17316
17317 var lArc = arc.P;
17318 if (!lArc) return -Infinity;
17319
17320 site = lArc.site;
17321 var lfocx = site[0],
17322 lfocy = site[1],
17323 plby2 = lfocy - directrix;
17324
17325 if (!plby2) return lfocx;
17326
17327 var hl = lfocx - rfocx,
17328 aby2 = 1 / pby2 - 1 / plby2,
17329 b = hl / plby2;
17330
17331 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
17332
17333 return (rfocx + lfocx) / 2;
17334}
17335
17336function rightBreakPoint(arc, directrix) {
17337 var rArc = arc.N;
17338 if (rArc) return leftBreakPoint(rArc, directrix);
17339 var site = arc.site;
17340 return site[1] === directrix ? site[0] : Infinity;
17341}
17342
17343var epsilon$4 = 1e-6;
17344var epsilon2$2 = 1e-12;
17345var beaches;
17346var cells;
17347var circles;
17348var edges;
17349
17350function triangleArea(a, b, c) {
17351 return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
17352}
17353
17354function lexicographic(a, b) {
17355 return b[1] - a[1]
17356 || b[0] - a[0];
17357}
17358
17359function Diagram(sites, extent) {
17360 var site = sites.sort(lexicographic).pop(),
17361 x,
17362 y,
17363 circle;
17364
17365 edges = [];
17366 cells = new Array(sites.length);
17367 beaches = new RedBlackTree;
17368 circles = new RedBlackTree;
17369
17370 while (true) {
17371 circle = firstCircle;
17372 if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
17373 if (site[0] !== x || site[1] !== y) {
17374 addBeach(site);
17375 x = site[0], y = site[1];
17376 }
17377 site = sites.pop();
17378 } else if (circle) {
17379 removeBeach(circle.arc);
17380 } else {
17381 break;
17382 }
17383 }
17384
17385 sortCellHalfedges();
17386
17387 if (extent) {
17388 var x0 = +extent[0][0],
17389 y0 = +extent[0][1],
17390 x1 = +extent[1][0],
17391 y1 = +extent[1][1];
17392 clipEdges(x0, y0, x1, y1);
17393 clipCells(x0, y0, x1, y1);
17394 }
17395
17396 this.edges = edges;
17397 this.cells = cells;
17398
17399 beaches =
17400 circles =
17401 edges =
17402 cells = null;
17403}
17404
17405Diagram.prototype = {
17406 constructor: Diagram,
17407
17408 polygons: function() {
17409 var edges = this.edges;
17410
17411 return this.cells.map(function(cell) {
17412 var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
17413 polygon.data = cell.site.data;
17414 return polygon;
17415 });
17416 },
17417
17418 triangles: function() {
17419 var triangles = [],
17420 edges = this.edges;
17421
17422 this.cells.forEach(function(cell, i) {
17423 if (!(m = (halfedges = cell.halfedges).length)) return;
17424 var site = cell.site,
17425 halfedges,
17426 j = -1,
17427 m,
17428 s0,
17429 e1 = edges[halfedges[m - 1]],
17430 s1 = e1.left === site ? e1.right : e1.left;
17431
17432 while (++j < m) {
17433 s0 = s1;
17434 e1 = edges[halfedges[j]];
17435 s1 = e1.left === site ? e1.right : e1.left;
17436 if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
17437 triangles.push([site.data, s0.data, s1.data]);
17438 }
17439 }
17440 });
17441
17442 return triangles;
17443 },
17444
17445 links: function() {
17446 return this.edges.filter(function(edge) {
17447 return edge.right;
17448 }).map(function(edge) {
17449 return {
17450 source: edge.left.data,
17451 target: edge.right.data
17452 };
17453 });
17454 },
17455
17456 find: function(x, y, radius) {
17457 var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
17458
17459 // Use the previously-found cell, or start with an arbitrary one.
17460 while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
17461 var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
17462
17463 // Traverse the half-edges to find a closer cell, if any.
17464 do {
17465 cell = that.cells[i0 = i1], i1 = null;
17466 cell.halfedges.forEach(function(e) {
17467 var edge = that.edges[e], v = edge.left;
17468 if ((v === cell.site || !v) && !(v = edge.right)) return;
17469 var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
17470 if (v2 < d2) d2 = v2, i1 = v.index;
17471 });
17472 } while (i1 !== null);
17473
17474 that._found = i0;
17475
17476 return radius == null || d2 <= radius * radius ? cell.site : null;
17477 }
17478};
17479
17480function voronoi() {
17481 var x = x$4,
17482 y = y$4,
17483 extent = null;
17484
17485 function voronoi(data) {
17486 return new Diagram(data.map(function(d, i) {
17487 var s = [Math.round(x(d, i, data) / epsilon$4) * epsilon$4, Math.round(y(d, i, data) / epsilon$4) * epsilon$4];
17488 s.index = i;
17489 s.data = d;
17490 return s;
17491 }), extent);
17492 }
17493
17494 voronoi.polygons = function(data) {
17495 return voronoi(data).polygons();
17496 };
17497
17498 voronoi.links = function(data) {
17499 return voronoi(data).links();
17500 };
17501
17502 voronoi.triangles = function(data) {
17503 return voronoi(data).triangles();
17504 };
17505
17506 voronoi.x = function(_) {
17507 return arguments.length ? (x = typeof _ === "function" ? _ : constant$c(+_), voronoi) : x;
17508 };
17509
17510 voronoi.y = function(_) {
17511 return arguments.length ? (y = typeof _ === "function" ? _ : constant$c(+_), voronoi) : y;
17512 };
17513
17514 voronoi.extent = function(_) {
17515 return arguments.length ? (extent = _ == null ? null : [[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]], voronoi) : extent && [[extent[0][0], extent[0][1]], [extent[1][0], extent[1][1]]];
17516 };
17517
17518 voronoi.size = function(_) {
17519 return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
17520 };
17521
17522 return voronoi;
17523}
17524
17525function constant$d(x) {
17526 return function() {
17527 return x;
17528 };
17529}
17530
17531function ZoomEvent(target, type, transform) {
17532 this.target = target;
17533 this.type = type;
17534 this.transform = transform;
17535}
17536
17537function Transform(k, x, y) {
17538 this.k = k;
17539 this.x = x;
17540 this.y = y;
17541}
17542
17543Transform.prototype = {
17544 constructor: Transform,
17545 scale: function(k) {
17546 return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
17547 },
17548 translate: function(x, y) {
17549 return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
17550 },
17551 apply: function(point) {
17552 return [point[0] * this.k + this.x, point[1] * this.k + this.y];
17553 },
17554 applyX: function(x) {
17555 return x * this.k + this.x;
17556 },
17557 applyY: function(y) {
17558 return y * this.k + this.y;
17559 },
17560 invert: function(location) {
17561 return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
17562 },
17563 invertX: function(x) {
17564 return (x - this.x) / this.k;
17565 },
17566 invertY: function(y) {
17567 return (y - this.y) / this.k;
17568 },
17569 rescaleX: function(x) {
17570 return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
17571 },
17572 rescaleY: function(y) {
17573 return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
17574 },
17575 toString: function() {
17576 return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
17577 }
17578};
17579
17580var identity$9 = new Transform(1, 0, 0);
17581
17582transform$1.prototype = Transform.prototype;
17583
17584function transform$1(node) {
17585 while (!node.__zoom) if (!(node = node.parentNode)) return identity$9;
17586 return node.__zoom;
17587}
17588
17589function nopropagation$2() {
17590 exports.event.stopImmediatePropagation();
17591}
17592
17593function noevent$2() {
17594 exports.event.preventDefault();
17595 exports.event.stopImmediatePropagation();
17596}
17597
17598// Ignore right-click, since that should open the context menu.
17599function defaultFilter$2() {
17600 return !exports.event.ctrlKey && !exports.event.button;
17601}
17602
17603function defaultExtent$1() {
17604 var e = this;
17605 if (e instanceof SVGElement) {
17606 e = e.ownerSVGElement || e;
17607 if (e.hasAttribute("viewBox")) {
17608 e = e.viewBox.baseVal;
17609 return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
17610 }
17611 return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
17612 }
17613 return [[0, 0], [e.clientWidth, e.clientHeight]];
17614}
17615
17616function defaultTransform() {
17617 return this.__zoom || identity$9;
17618}
17619
17620function defaultWheelDelta() {
17621 return -exports.event.deltaY * (exports.event.deltaMode === 1 ? 0.05 : exports.event.deltaMode ? 1 : 0.002);
17622}
17623
17624function defaultTouchable$2() {
17625 return navigator.maxTouchPoints || ("ontouchstart" in this);
17626}
17627
17628function defaultConstrain(transform, extent, translateExtent) {
17629 var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
17630 dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
17631 dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
17632 dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
17633 return transform.translate(
17634 dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
17635 dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
17636 );
17637}
17638
17639function zoom() {
17640 var filter = defaultFilter$2,
17641 extent = defaultExtent$1,
17642 constrain = defaultConstrain,
17643 wheelDelta = defaultWheelDelta,
17644 touchable = defaultTouchable$2,
17645 scaleExtent = [0, Infinity],
17646 translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
17647 duration = 250,
17648 interpolate = interpolateZoom,
17649 listeners = dispatch("start", "zoom", "end"),
17650 touchstarting,
17651 touchending,
17652 touchDelay = 500,
17653 wheelDelay = 150,
17654 clickDistance2 = 0;
17655
17656 function zoom(selection) {
17657 selection
17658 .property("__zoom", defaultTransform)
17659 .on("wheel.zoom", wheeled)
17660 .on("mousedown.zoom", mousedowned)
17661 .on("dblclick.zoom", dblclicked)
17662 .filter(touchable)
17663 .on("touchstart.zoom", touchstarted)
17664 .on("touchmove.zoom", touchmoved)
17665 .on("touchend.zoom touchcancel.zoom", touchended)
17666 .style("touch-action", "none")
17667 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
17668 }
17669
17670 zoom.transform = function(collection, transform, point) {
17671 var selection = collection.selection ? collection.selection() : collection;
17672 selection.property("__zoom", defaultTransform);
17673 if (collection !== selection) {
17674 schedule(collection, transform, point);
17675 } else {
17676 selection.interrupt().each(function() {
17677 gesture(this, arguments)
17678 .start()
17679 .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
17680 .end();
17681 });
17682 }
17683 };
17684
17685 zoom.scaleBy = function(selection, k, p) {
17686 zoom.scaleTo(selection, function() {
17687 var k0 = this.__zoom.k,
17688 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
17689 return k0 * k1;
17690 }, p);
17691 };
17692
17693 zoom.scaleTo = function(selection, k, p) {
17694 zoom.transform(selection, function() {
17695 var e = extent.apply(this, arguments),
17696 t0 = this.__zoom,
17697 p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
17698 p1 = t0.invert(p0),
17699 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
17700 return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
17701 }, p);
17702 };
17703
17704 zoom.translateBy = function(selection, x, y) {
17705 zoom.transform(selection, function() {
17706 return constrain(this.__zoom.translate(
17707 typeof x === "function" ? x.apply(this, arguments) : x,
17708 typeof y === "function" ? y.apply(this, arguments) : y
17709 ), extent.apply(this, arguments), translateExtent);
17710 });
17711 };
17712
17713 zoom.translateTo = function(selection, x, y, p) {
17714 zoom.transform(selection, function() {
17715 var e = extent.apply(this, arguments),
17716 t = this.__zoom,
17717 p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
17718 return constrain(identity$9.translate(p0[0], p0[1]).scale(t.k).translate(
17719 typeof x === "function" ? -x.apply(this, arguments) : -x,
17720 typeof y === "function" ? -y.apply(this, arguments) : -y
17721 ), e, translateExtent);
17722 }, p);
17723 };
17724
17725 function scale(transform, k) {
17726 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
17727 return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
17728 }
17729
17730 function translate(transform, p0, p1) {
17731 var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
17732 return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
17733 }
17734
17735 function centroid(extent) {
17736 return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
17737 }
17738
17739 function schedule(transition, transform, point) {
17740 transition
17741 .on("start.zoom", function() { gesture(this, arguments).start(); })
17742 .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
17743 .tween("zoom", function() {
17744 var that = this,
17745 args = arguments,
17746 g = gesture(that, args),
17747 e = extent.apply(that, args),
17748 p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
17749 w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
17750 a = that.__zoom,
17751 b = typeof transform === "function" ? transform.apply(that, args) : transform,
17752 i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
17753 return function(t) {
17754 if (t === 1) t = b; // Avoid rounding error on end.
17755 else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
17756 g.zoom(null, t);
17757 };
17758 });
17759 }
17760
17761 function gesture(that, args, clean) {
17762 return (!clean && that.__zooming) || new Gesture(that, args);
17763 }
17764
17765 function Gesture(that, args) {
17766 this.that = that;
17767 this.args = args;
17768 this.active = 0;
17769 this.extent = extent.apply(that, args);
17770 this.taps = 0;
17771 }
17772
17773 Gesture.prototype = {
17774 start: function() {
17775 if (++this.active === 1) {
17776 this.that.__zooming = this;
17777 this.emit("start");
17778 }
17779 return this;
17780 },
17781 zoom: function(key, transform) {
17782 if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
17783 if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
17784 if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
17785 this.that.__zoom = transform;
17786 this.emit("zoom");
17787 return this;
17788 },
17789 end: function() {
17790 if (--this.active === 0) {
17791 delete this.that.__zooming;
17792 this.emit("end");
17793 }
17794 return this;
17795 },
17796 emit: function(type) {
17797 customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
17798 }
17799 };
17800
17801 function wheeled() {
17802 if (!filter.apply(this, arguments)) return;
17803 var g = gesture(this, arguments),
17804 t = this.__zoom,
17805 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
17806 p = mouse(this);
17807
17808 // If the mouse is in the same location as before, reuse it.
17809 // If there were recent wheel events, reset the wheel idle timeout.
17810 if (g.wheel) {
17811 if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
17812 g.mouse[1] = t.invert(g.mouse[0] = p);
17813 }
17814 clearTimeout(g.wheel);
17815 }
17816
17817 // If this wheel event won’t trigger a transform change, ignore it.
17818 else if (t.k === k) return;
17819
17820 // Otherwise, capture the mouse point and location at the start.
17821 else {
17822 g.mouse = [p, t.invert(p)];
17823 interrupt(this);
17824 g.start();
17825 }
17826
17827 noevent$2();
17828 g.wheel = setTimeout(wheelidled, wheelDelay);
17829 g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
17830
17831 function wheelidled() {
17832 g.wheel = null;
17833 g.end();
17834 }
17835 }
17836
17837 function mousedowned() {
17838 if (touchending || !filter.apply(this, arguments)) return;
17839 var g = gesture(this, arguments, true),
17840 v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
17841 p = mouse(this),
17842 x0 = exports.event.clientX,
17843 y0 = exports.event.clientY;
17844
17845 dragDisable(exports.event.view);
17846 nopropagation$2();
17847 g.mouse = [p, this.__zoom.invert(p)];
17848 interrupt(this);
17849 g.start();
17850
17851 function mousemoved() {
17852 noevent$2();
17853 if (!g.moved) {
17854 var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
17855 g.moved = dx * dx + dy * dy > clickDistance2;
17856 }
17857 g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
17858 }
17859
17860 function mouseupped() {
17861 v.on("mousemove.zoom mouseup.zoom", null);
17862 yesdrag(exports.event.view, g.moved);
17863 noevent$2();
17864 g.end();
17865 }
17866 }
17867
17868 function dblclicked() {
17869 if (!filter.apply(this, arguments)) return;
17870 var t0 = this.__zoom,
17871 p0 = mouse(this),
17872 p1 = t0.invert(p0),
17873 k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
17874 t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
17875
17876 noevent$2();
17877 if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
17878 else select(this).call(zoom.transform, t1);
17879 }
17880
17881 function touchstarted() {
17882 if (!filter.apply(this, arguments)) return;
17883 var touches = exports.event.touches,
17884 n = touches.length,
17885 g = gesture(this, arguments, exports.event.changedTouches.length === n),
17886 started, i, t, p;
17887
17888 nopropagation$2();
17889 for (i = 0; i < n; ++i) {
17890 t = touches[i], p = touch(this, touches, t.identifier);
17891 p = [p, this.__zoom.invert(p), t.identifier];
17892 if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
17893 else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
17894 }
17895
17896 if (touchstarting) touchstarting = clearTimeout(touchstarting);
17897
17898 if (started) {
17899 if (g.taps < 2) touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
17900 interrupt(this);
17901 g.start();
17902 }
17903 }
17904
17905 function touchmoved() {
17906 if (!this.__zooming) return;
17907 var g = gesture(this, arguments),
17908 touches = exports.event.changedTouches,
17909 n = touches.length, i, t, p, l;
17910
17911 noevent$2();
17912 if (touchstarting) touchstarting = clearTimeout(touchstarting);
17913 g.taps = 0;
17914 for (i = 0; i < n; ++i) {
17915 t = touches[i], p = touch(this, touches, t.identifier);
17916 if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
17917 else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
17918 }
17919 t = g.that.__zoom;
17920 if (g.touch1) {
17921 var p0 = g.touch0[0], l0 = g.touch0[1],
17922 p1 = g.touch1[0], l1 = g.touch1[1],
17923 dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
17924 dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
17925 t = scale(t, Math.sqrt(dp / dl));
17926 p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
17927 l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
17928 }
17929 else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
17930 else return;
17931 g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
17932 }
17933
17934 function touchended() {
17935 if (!this.__zooming) return;
17936 var g = gesture(this, arguments),
17937 touches = exports.event.changedTouches,
17938 n = touches.length, i, t;
17939
17940 nopropagation$2();
17941 if (touchending) clearTimeout(touchending);
17942 touchending = setTimeout(function() { touchending = null; }, touchDelay);
17943 for (i = 0; i < n; ++i) {
17944 t = touches[i];
17945 if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
17946 else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
17947 }
17948 if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
17949 if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
17950 else {
17951 g.end();
17952 // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
17953 if (g.taps === 2) {
17954 var p = select(this).on("dblclick.zoom");
17955 if (p) p.apply(this, arguments);
17956 }
17957 }
17958 }
17959
17960 zoom.wheelDelta = function(_) {
17961 return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$d(+_), zoom) : wheelDelta;
17962 };
17963
17964 zoom.filter = function(_) {
17965 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$d(!!_), zoom) : filter;
17966 };
17967
17968 zoom.touchable = function(_) {
17969 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$d(!!_), zoom) : touchable;
17970 };
17971
17972 zoom.extent = function(_) {
17973 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$d([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
17974 };
17975
17976 zoom.scaleExtent = function(_) {
17977 return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
17978 };
17979
17980 zoom.translateExtent = function(_) {
17981 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]]];
17982 };
17983
17984 zoom.constrain = function(_) {
17985 return arguments.length ? (constrain = _, zoom) : constrain;
17986 };
17987
17988 zoom.duration = function(_) {
17989 return arguments.length ? (duration = +_, zoom) : duration;
17990 };
17991
17992 zoom.interpolate = function(_) {
17993 return arguments.length ? (interpolate = _, zoom) : interpolate;
17994 };
17995
17996 zoom.on = function() {
17997 var value = listeners.on.apply(listeners, arguments);
17998 return value === listeners ? zoom : value;
17999 };
18000
18001 zoom.clickDistance = function(_) {
18002 return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
18003 };
18004
18005 return zoom;
18006}
18007
18008exports.FormatSpecifier = FormatSpecifier;
18009exports.active = active;
18010exports.arc = arc;
18011exports.area = area$3;
18012exports.areaRadial = areaRadial;
18013exports.ascending = ascending;
18014exports.autoType = autoType;
18015exports.axisBottom = axisBottom;
18016exports.axisLeft = axisLeft;
18017exports.axisRight = axisRight;
18018exports.axisTop = axisTop;
18019exports.bisect = bisectRight;
18020exports.bisectLeft = bisectLeft;
18021exports.bisectRight = bisectRight;
18022exports.bisector = bisector;
18023exports.blob = blob;
18024exports.brush = brush;
18025exports.brushSelection = brushSelection;
18026exports.brushX = brushX;
18027exports.brushY = brushY;
18028exports.buffer = buffer;
18029exports.chord = chord;
18030exports.clientPoint = point;
18031exports.cluster = cluster;
18032exports.color = color;
18033exports.contourDensity = density;
18034exports.contours = contours;
18035exports.create = create;
18036exports.creator = creator;
18037exports.cross = cross;
18038exports.csv = csv$1;
18039exports.csvFormat = csvFormat;
18040exports.csvFormatBody = csvFormatBody;
18041exports.csvFormatRow = csvFormatRow;
18042exports.csvFormatRows = csvFormatRows;
18043exports.csvFormatValue = csvFormatValue;
18044exports.csvParse = csvParse;
18045exports.csvParseRows = csvParseRows;
18046exports.cubehelix = cubehelix;
18047exports.curveBasis = basis$2;
18048exports.curveBasisClosed = basisClosed$1;
18049exports.curveBasisOpen = basisOpen;
18050exports.curveBundle = bundle;
18051exports.curveCardinal = cardinal;
18052exports.curveCardinalClosed = cardinalClosed;
18053exports.curveCardinalOpen = cardinalOpen;
18054exports.curveCatmullRom = catmullRom;
18055exports.curveCatmullRomClosed = catmullRomClosed;
18056exports.curveCatmullRomOpen = catmullRomOpen;
18057exports.curveLinear = curveLinear;
18058exports.curveLinearClosed = linearClosed;
18059exports.curveMonotoneX = monotoneX;
18060exports.curveMonotoneY = monotoneY;
18061exports.curveNatural = natural;
18062exports.curveStep = step;
18063exports.curveStepAfter = stepAfter;
18064exports.curveStepBefore = stepBefore;
18065exports.customEvent = customEvent;
18066exports.descending = descending;
18067exports.deviation = deviation;
18068exports.dispatch = dispatch;
18069exports.drag = drag;
18070exports.dragDisable = dragDisable;
18071exports.dragEnable = yesdrag;
18072exports.dsv = dsv;
18073exports.dsvFormat = dsvFormat;
18074exports.easeBack = backInOut;
18075exports.easeBackIn = backIn;
18076exports.easeBackInOut = backInOut;
18077exports.easeBackOut = backOut;
18078exports.easeBounce = bounceOut;
18079exports.easeBounceIn = bounceIn;
18080exports.easeBounceInOut = bounceInOut;
18081exports.easeBounceOut = bounceOut;
18082exports.easeCircle = circleInOut;
18083exports.easeCircleIn = circleIn;
18084exports.easeCircleInOut = circleInOut;
18085exports.easeCircleOut = circleOut;
18086exports.easeCubic = cubicInOut;
18087exports.easeCubicIn = cubicIn;
18088exports.easeCubicInOut = cubicInOut;
18089exports.easeCubicOut = cubicOut;
18090exports.easeElastic = elasticOut;
18091exports.easeElasticIn = elasticIn;
18092exports.easeElasticInOut = elasticInOut;
18093exports.easeElasticOut = elasticOut;
18094exports.easeExp = expInOut;
18095exports.easeExpIn = expIn;
18096exports.easeExpInOut = expInOut;
18097exports.easeExpOut = expOut;
18098exports.easeLinear = linear$1;
18099exports.easePoly = polyInOut;
18100exports.easePolyIn = polyIn;
18101exports.easePolyInOut = polyInOut;
18102exports.easePolyOut = polyOut;
18103exports.easeQuad = quadInOut;
18104exports.easeQuadIn = quadIn;
18105exports.easeQuadInOut = quadInOut;
18106exports.easeQuadOut = quadOut;
18107exports.easeSin = sinInOut;
18108exports.easeSinIn = sinIn;
18109exports.easeSinInOut = sinInOut;
18110exports.easeSinOut = sinOut;
18111exports.entries = entries;
18112exports.extent = extent;
18113exports.forceCenter = center$1;
18114exports.forceCollide = collide;
18115exports.forceLink = link;
18116exports.forceManyBody = manyBody;
18117exports.forceRadial = radial;
18118exports.forceSimulation = simulation;
18119exports.forceX = x$2;
18120exports.forceY = y$2;
18121exports.formatDefaultLocale = defaultLocale;
18122exports.formatLocale = formatLocale;
18123exports.formatSpecifier = formatSpecifier;
18124exports.geoAlbers = albers;
18125exports.geoAlbersUsa = albersUsa;
18126exports.geoArea = area$1;
18127exports.geoAzimuthalEqualArea = azimuthalEqualArea;
18128exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
18129exports.geoAzimuthalEquidistant = azimuthalEquidistant;
18130exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
18131exports.geoBounds = bounds;
18132exports.geoCentroid = centroid;
18133exports.geoCircle = circle;
18134exports.geoClipAntimeridian = clipAntimeridian;
18135exports.geoClipCircle = clipCircle;
18136exports.geoClipExtent = extent$1;
18137exports.geoClipRectangle = clipRectangle;
18138exports.geoConicConformal = conicConformal;
18139exports.geoConicConformalRaw = conicConformalRaw;
18140exports.geoConicEqualArea = conicEqualArea;
18141exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
18142exports.geoConicEquidistant = conicEquidistant;
18143exports.geoConicEquidistantRaw = conicEquidistantRaw;
18144exports.geoContains = contains$1;
18145exports.geoDistance = distance;
18146exports.geoEqualEarth = equalEarth;
18147exports.geoEqualEarthRaw = equalEarthRaw;
18148exports.geoEquirectangular = equirectangular;
18149exports.geoEquirectangularRaw = equirectangularRaw;
18150exports.geoGnomonic = gnomonic;
18151exports.geoGnomonicRaw = gnomonicRaw;
18152exports.geoGraticule = graticule;
18153exports.geoGraticule10 = graticule10;
18154exports.geoIdentity = identity$5;
18155exports.geoInterpolate = interpolate$1;
18156exports.geoLength = length$1;
18157exports.geoMercator = mercator;
18158exports.geoMercatorRaw = mercatorRaw;
18159exports.geoNaturalEarth1 = naturalEarth1;
18160exports.geoNaturalEarth1Raw = naturalEarth1Raw;
18161exports.geoOrthographic = orthographic;
18162exports.geoOrthographicRaw = orthographicRaw;
18163exports.geoPath = index$1;
18164exports.geoProjection = projection;
18165exports.geoProjectionMutator = projectionMutator;
18166exports.geoRotation = rotation;
18167exports.geoStereographic = stereographic;
18168exports.geoStereographicRaw = stereographicRaw;
18169exports.geoStream = geoStream;
18170exports.geoTransform = transform;
18171exports.geoTransverseMercator = transverseMercator;
18172exports.geoTransverseMercatorRaw = transverseMercatorRaw;
18173exports.gray = gray;
18174exports.hcl = hcl;
18175exports.hierarchy = hierarchy;
18176exports.histogram = histogram;
18177exports.hsl = hsl;
18178exports.html = html;
18179exports.image = image;
18180exports.interpolate = interpolateValue;
18181exports.interpolateArray = array$1;
18182exports.interpolateBasis = basis$1;
18183exports.interpolateBasisClosed = basisClosed;
18184exports.interpolateBlues = Blues;
18185exports.interpolateBrBG = BrBG;
18186exports.interpolateBuGn = BuGn;
18187exports.interpolateBuPu = BuPu;
18188exports.interpolateCividis = cividis;
18189exports.interpolateCool = cool;
18190exports.interpolateCubehelix = cubehelix$2;
18191exports.interpolateCubehelixDefault = cubehelix$3;
18192exports.interpolateCubehelixLong = cubehelixLong;
18193exports.interpolateDate = date;
18194exports.interpolateDiscrete = discrete;
18195exports.interpolateGnBu = GnBu;
18196exports.interpolateGreens = Greens;
18197exports.interpolateGreys = Greys;
18198exports.interpolateHcl = hcl$2;
18199exports.interpolateHclLong = hclLong;
18200exports.interpolateHsl = hsl$2;
18201exports.interpolateHslLong = hslLong;
18202exports.interpolateHue = hue$1;
18203exports.interpolateInferno = inferno;
18204exports.interpolateLab = lab$1;
18205exports.interpolateMagma = magma;
18206exports.interpolateNumber = interpolateNumber;
18207exports.interpolateObject = object;
18208exports.interpolateOrRd = OrRd;
18209exports.interpolateOranges = Oranges;
18210exports.interpolatePRGn = PRGn;
18211exports.interpolatePiYG = PiYG;
18212exports.interpolatePlasma = plasma;
18213exports.interpolatePuBu = PuBu;
18214exports.interpolatePuBuGn = PuBuGn;
18215exports.interpolatePuOr = PuOr;
18216exports.interpolatePuRd = PuRd;
18217exports.interpolatePurples = Purples;
18218exports.interpolateRainbow = rainbow;
18219exports.interpolateRdBu = RdBu;
18220exports.interpolateRdGy = RdGy;
18221exports.interpolateRdPu = RdPu;
18222exports.interpolateRdYlBu = RdYlBu;
18223exports.interpolateRdYlGn = RdYlGn;
18224exports.interpolateReds = Reds;
18225exports.interpolateRgb = interpolateRgb;
18226exports.interpolateRgbBasis = rgbBasis;
18227exports.interpolateRgbBasisClosed = rgbBasisClosed;
18228exports.interpolateRound = interpolateRound;
18229exports.interpolateSinebow = sinebow;
18230exports.interpolateSpectral = Spectral;
18231exports.interpolateString = interpolateString;
18232exports.interpolateTransformCss = interpolateTransformCss;
18233exports.interpolateTransformSvg = interpolateTransformSvg;
18234exports.interpolateTurbo = turbo;
18235exports.interpolateViridis = viridis;
18236exports.interpolateWarm = warm;
18237exports.interpolateYlGn = YlGn;
18238exports.interpolateYlGnBu = YlGnBu;
18239exports.interpolateYlOrBr = YlOrBr;
18240exports.interpolateYlOrRd = YlOrRd;
18241exports.interpolateZoom = interpolateZoom;
18242exports.interrupt = interrupt;
18243exports.interval = interval$1;
18244exports.isoFormat = formatIso;
18245exports.isoParse = parseIso;
18246exports.json = json;
18247exports.keys = keys;
18248exports.lab = lab;
18249exports.lch = lch;
18250exports.line = line;
18251exports.lineRadial = lineRadial$1;
18252exports.linkHorizontal = linkHorizontal;
18253exports.linkRadial = linkRadial;
18254exports.linkVertical = linkVertical;
18255exports.local = local;
18256exports.map = map$1;
18257exports.matcher = matcher;
18258exports.max = max;
18259exports.mean = mean;
18260exports.median = median;
18261exports.merge = merge;
18262exports.min = min;
18263exports.mouse = mouse;
18264exports.namespace = namespace;
18265exports.namespaces = namespaces;
18266exports.nest = nest;
18267exports.now = now;
18268exports.pack = index$2;
18269exports.packEnclose = enclose;
18270exports.packSiblings = siblings;
18271exports.pairs = pairs;
18272exports.partition = partition;
18273exports.path = path;
18274exports.permute = permute;
18275exports.pie = pie;
18276exports.piecewise = piecewise;
18277exports.pointRadial = pointRadial;
18278exports.polygonArea = area$2;
18279exports.polygonCentroid = centroid$1;
18280exports.polygonContains = contains$2;
18281exports.polygonHull = hull;
18282exports.polygonLength = length$2;
18283exports.precisionFixed = precisionFixed;
18284exports.precisionPrefix = precisionPrefix;
18285exports.precisionRound = precisionRound;
18286exports.quadtree = quadtree;
18287exports.quantile = threshold;
18288exports.quantize = quantize;
18289exports.radialArea = areaRadial;
18290exports.radialLine = lineRadial$1;
18291exports.randomBates = bates;
18292exports.randomExponential = exponential$1;
18293exports.randomIrwinHall = irwinHall;
18294exports.randomLogNormal = logNormal;
18295exports.randomNormal = normal;
18296exports.randomUniform = uniform;
18297exports.range = sequence;
18298exports.rgb = rgb;
18299exports.ribbon = ribbon;
18300exports.scaleBand = band;
18301exports.scaleDiverging = diverging;
18302exports.scaleDivergingLog = divergingLog;
18303exports.scaleDivergingPow = divergingPow;
18304exports.scaleDivergingSqrt = divergingSqrt;
18305exports.scaleDivergingSymlog = divergingSymlog;
18306exports.scaleIdentity = identity$7;
18307exports.scaleImplicit = implicit;
18308exports.scaleLinear = linear$2;
18309exports.scaleLog = log$1;
18310exports.scaleOrdinal = ordinal;
18311exports.scalePoint = point$1;
18312exports.scalePow = pow$1;
18313exports.scaleQuantile = quantile;
18314exports.scaleQuantize = quantize$1;
18315exports.scaleSequential = sequential;
18316exports.scaleSequentialLog = sequentialLog;
18317exports.scaleSequentialPow = sequentialPow;
18318exports.scaleSequentialQuantile = sequentialQuantile;
18319exports.scaleSequentialSqrt = sequentialSqrt;
18320exports.scaleSequentialSymlog = sequentialSymlog;
18321exports.scaleSqrt = sqrt$1;
18322exports.scaleSymlog = symlog;
18323exports.scaleThreshold = threshold$1;
18324exports.scaleTime = time;
18325exports.scaleUtc = utcTime;
18326exports.scan = scan;
18327exports.schemeAccent = Accent;
18328exports.schemeBlues = scheme$l;
18329exports.schemeBrBG = scheme;
18330exports.schemeBuGn = scheme$9;
18331exports.schemeBuPu = scheme$a;
18332exports.schemeCategory10 = category10;
18333exports.schemeDark2 = Dark2;
18334exports.schemeGnBu = scheme$b;
18335exports.schemeGreens = scheme$m;
18336exports.schemeGreys = scheme$n;
18337exports.schemeOrRd = scheme$c;
18338exports.schemeOranges = scheme$q;
18339exports.schemePRGn = scheme$1;
18340exports.schemePaired = Paired;
18341exports.schemePastel1 = Pastel1;
18342exports.schemePastel2 = Pastel2;
18343exports.schemePiYG = scheme$2;
18344exports.schemePuBu = scheme$e;
18345exports.schemePuBuGn = scheme$d;
18346exports.schemePuOr = scheme$3;
18347exports.schemePuRd = scheme$f;
18348exports.schemePurples = scheme$o;
18349exports.schemeRdBu = scheme$4;
18350exports.schemeRdGy = scheme$5;
18351exports.schemeRdPu = scheme$g;
18352exports.schemeRdYlBu = scheme$6;
18353exports.schemeRdYlGn = scheme$7;
18354exports.schemeReds = scheme$p;
18355exports.schemeSet1 = Set1;
18356exports.schemeSet2 = Set2;
18357exports.schemeSet3 = Set3;
18358exports.schemeSpectral = scheme$8;
18359exports.schemeTableau10 = Tableau10;
18360exports.schemeYlGn = scheme$i;
18361exports.schemeYlGnBu = scheme$h;
18362exports.schemeYlOrBr = scheme$j;
18363exports.schemeYlOrRd = scheme$k;
18364exports.select = select;
18365exports.selectAll = selectAll;
18366exports.selection = selection;
18367exports.selector = selector;
18368exports.selectorAll = selectorAll;
18369exports.set = set$2;
18370exports.shuffle = shuffle;
18371exports.stack = stack;
18372exports.stackOffsetDiverging = diverging$1;
18373exports.stackOffsetExpand = expand;
18374exports.stackOffsetNone = none$1;
18375exports.stackOffsetSilhouette = silhouette;
18376exports.stackOffsetWiggle = wiggle;
18377exports.stackOrderAppearance = appearance;
18378exports.stackOrderAscending = ascending$3;
18379exports.stackOrderDescending = descending$2;
18380exports.stackOrderInsideOut = insideOut;
18381exports.stackOrderNone = none$2;
18382exports.stackOrderReverse = reverse;
18383exports.stratify = stratify;
18384exports.style = styleValue;
18385exports.sum = sum;
18386exports.svg = svg;
18387exports.symbol = symbol;
18388exports.symbolCircle = circle$2;
18389exports.symbolCross = cross$2;
18390exports.symbolDiamond = diamond;
18391exports.symbolSquare = square;
18392exports.symbolStar = star;
18393exports.symbolTriangle = triangle;
18394exports.symbolWye = wye;
18395exports.symbols = symbols;
18396exports.text = text;
18397exports.thresholdFreedmanDiaconis = freedmanDiaconis;
18398exports.thresholdScott = scott;
18399exports.thresholdSturges = thresholdSturges;
18400exports.tickFormat = tickFormat;
18401exports.tickIncrement = tickIncrement;
18402exports.tickStep = tickStep;
18403exports.ticks = ticks;
18404exports.timeDay = day;
18405exports.timeDays = days;
18406exports.timeFormatDefaultLocale = defaultLocale$1;
18407exports.timeFormatLocale = formatLocale$1;
18408exports.timeFriday = friday;
18409exports.timeFridays = fridays;
18410exports.timeHour = hour;
18411exports.timeHours = hours;
18412exports.timeInterval = newInterval;
18413exports.timeMillisecond = millisecond;
18414exports.timeMilliseconds = milliseconds;
18415exports.timeMinute = minute;
18416exports.timeMinutes = minutes;
18417exports.timeMonday = monday;
18418exports.timeMondays = mondays;
18419exports.timeMonth = month;
18420exports.timeMonths = months;
18421exports.timeSaturday = saturday;
18422exports.timeSaturdays = saturdays;
18423exports.timeSecond = second;
18424exports.timeSeconds = seconds;
18425exports.timeSunday = sunday;
18426exports.timeSundays = sundays;
18427exports.timeThursday = thursday;
18428exports.timeThursdays = thursdays;
18429exports.timeTuesday = tuesday;
18430exports.timeTuesdays = tuesdays;
18431exports.timeWednesday = wednesday;
18432exports.timeWednesdays = wednesdays;
18433exports.timeWeek = sunday;
18434exports.timeWeeks = sundays;
18435exports.timeYear = year;
18436exports.timeYears = years;
18437exports.timeout = timeout$1;
18438exports.timer = timer;
18439exports.timerFlush = timerFlush;
18440exports.touch = touch;
18441exports.touches = touches;
18442exports.transition = transition;
18443exports.transpose = transpose;
18444exports.tree = tree;
18445exports.treemap = index$3;
18446exports.treemapBinary = binary;
18447exports.treemapDice = treemapDice;
18448exports.treemapResquarify = resquarify;
18449exports.treemapSlice = treemapSlice;
18450exports.treemapSliceDice = sliceDice;
18451exports.treemapSquarify = squarify;
18452exports.tsv = tsv$1;
18453exports.tsvFormat = tsvFormat;
18454exports.tsvFormatBody = tsvFormatBody;
18455exports.tsvFormatRow = tsvFormatRow;
18456exports.tsvFormatRows = tsvFormatRows;
18457exports.tsvFormatValue = tsvFormatValue;
18458exports.tsvParse = tsvParse;
18459exports.tsvParseRows = tsvParseRows;
18460exports.utcDay = utcDay;
18461exports.utcDays = utcDays;
18462exports.utcFriday = utcFriday;
18463exports.utcFridays = utcFridays;
18464exports.utcHour = utcHour;
18465exports.utcHours = utcHours;
18466exports.utcMillisecond = millisecond;
18467exports.utcMilliseconds = milliseconds;
18468exports.utcMinute = utcMinute;
18469exports.utcMinutes = utcMinutes;
18470exports.utcMonday = utcMonday;
18471exports.utcMondays = utcMondays;
18472exports.utcMonth = utcMonth;
18473exports.utcMonths = utcMonths;
18474exports.utcSaturday = utcSaturday;
18475exports.utcSaturdays = utcSaturdays;
18476exports.utcSecond = second;
18477exports.utcSeconds = seconds;
18478exports.utcSunday = utcSunday;
18479exports.utcSundays = utcSundays;
18480exports.utcThursday = utcThursday;
18481exports.utcThursdays = utcThursdays;
18482exports.utcTuesday = utcTuesday;
18483exports.utcTuesdays = utcTuesdays;
18484exports.utcWednesday = utcWednesday;
18485exports.utcWednesdays = utcWednesdays;
18486exports.utcWeek = utcSunday;
18487exports.utcWeeks = utcSundays;
18488exports.utcYear = utcYear;
18489exports.utcYears = utcYears;
18490exports.values = values;
18491exports.variance = variance;
18492exports.version = version;
18493exports.voronoi = voronoi;
18494exports.window = defaultView;
18495exports.xml = xml;
18496exports.zip = zip;
18497exports.zoom = zoom;
18498exports.zoomIdentity = identity$9;
18499exports.zoomTransform = transform$1;
18500
18501Object.defineProperty(exports, '__esModule', { value: true });
18502
18503}));
18504
\No newline at end of file