PluginProbe
WebTotem Security / 2.2.4
WebTotem Security v2.2.4
3.0.1 3.0.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.1 2.2.2 2.2.3 2.2.4 All 109 releases
wt-security / htdocs / js / d3.v4.js

d3.v4.js in WebTotem Security 2.2.4, at htdocs/js/d3.v4.js

17,179 lines 461.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // https://d3js.org Version 4.13.0. Copyright 2018 Mike Bostock.
2 (function (global, factory) {
3 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4 typeof define === 'function' && define.amd ? define(['exports'], factory) :
5 (factory((global.d3 = global.d3 || {})));
6 }(this, (function (exports) { 'use strict';
7
8 var version = "4.13.0";
9
10 function ascending(a, b) {
11 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
12 }
13
14 function 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
40 function ascendingComparator(f) {
41 return function(d, x) {
42 return ascending(f(d), x);
43 };
44 }
45
46 var ascendingBisect = bisector(ascending);
47 var bisectRight = ascendingBisect.right;
48 var bisectLeft = ascendingBisect.left;
49
50 function 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
57 function pair(a, b) {
58 return [a, b];
59 }
60
61 function 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
81 function descending(a, b) {
82 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
83 }
84
85 function number(x) {
86 return x === null ? NaN : +x;
87 }
88
89 function 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
121 function deviation(array, f) {
122 var v = variance(array, f);
123 return v ? Math.sqrt(v) : v;
124 }
125
126 function 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
164 var array = Array.prototype;
165
166 var slice = array.slice;
167 var map = array.map;
168
169 function constant(x) {
170 return function() {
171 return x;
172 };
173 }
174
175 function identity(x) {
176 return x;
177 }
178
179 function 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
193 var e10 = Math.sqrt(50);
194 var e5 = Math.sqrt(10);
195 var e2 = Math.sqrt(2);
196
197 function 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
226 function 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
235 function 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
245 function sturges(values) {
246 return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
247 }
248
249 function histogram() {
250 var value = identity,
251 domain = extent,
252 threshold = sturges;
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, Math.floor(x1 / tz) * tz, 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
316 function 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
329 function 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
334 function scott(values, min, max) {
335 return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
336 }
337
338 function 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
373 function 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
397 function 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
422 function 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
444 function 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
479 function 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
485 function 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
504 function 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
519 function 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
540 function 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
550 function length(d) {
551 return d.length;
552 }
553
554 function zip() {
555 return transpose(arguments);
556 }
557
558 var slice$1 = Array.prototype.slice;
559
560 function identity$1(x) {
561 return x;
562 }
563
564 var top = 1;
565 var right = 2;
566 var bottom = 3;
567 var left = 4;
568 var epsilon = 1e-6;
569
570 function translateX(x) {
571 return "translate(" + (x + 0.5) + ",0)";
572 }
573
574 function translateY(y) {
575 return "translate(0," + (y + 0.5) + ")";
576 }
577
578 function number$1(scale) {
579 return function(d) {
580 return +scale(d);
581 };
582 }
583
584 function 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
592 function entering() {
593 return !this.__axis;
594 }
595
596 function 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", "#000"));
626
627 tick = tick.merge(tickEnter);
628
629 line = line.merge(tickEnter.append("line")
630 .attr("stroke", "#000")
631 .attr(x + "2", k * tickSizeInner));
632
633 text = text.merge(tickEnter.append("text")
634 .attr("fill", "#000")
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 ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
658 : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
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
720 function axisTop(scale) {
721 return axis(top, scale);
722 }
723
724 function axisRight(scale) {
725 return axis(right, scale);
726 }
727
728 function axisBottom(scale) {
729 return axis(bottom, scale);
730 }
731
732 function axisLeft(scale) {
733 return axis(left, scale);
734 }
735
736 var noop = {value: function() {}};
737
738 function dispatch() {
739 for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
740 if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
741 _[t] = [];
742 }
743 return new Dispatch(_);
744 }
745
746 function Dispatch(_) {
747 this._ = _;
748 }
749
750 function 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
759 Dispatch.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
800 function 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
808 function 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
819 var xhtml = "http://www.w3.org/1999/xhtml";
820
821 var 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
829 function 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
835 function 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
845 function creatorFixed(fullname) {
846 return function() {
847 return this.ownerDocument.createElementNS(fullname.space, fullname.local);
848 };
849 }
850
851 function creator(name) {
852 var fullname = namespace(name);
853 return (fullname.local
854 ? creatorFixed
855 : creatorInherit)(fullname);
856 }
857
858 function none() {}
859
860 function selector(selector) {
861 return selector == null ? none : function() {
862 return this.querySelector(selector);
863 };
864 }
865
866 function 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
881 function empty$1() {
882 return [];
883 }
884
885 function selectorAll(selector) {
886 return selector == null ? empty$1 : function() {
887 return this.querySelectorAll(selector);
888 };
889 }
890
891 function 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
906 var matcher = function(selector) {
907 return function() {
908 return this.matches(selector);
909 };
910 };
911
912 if (typeof document !== "undefined") {
913 var element = document.documentElement;
914 if (!element.matches) {
915 var vendorMatches = element.webkitMatchesSelector
916 || element.msMatchesSelector
917 || element.mozMatchesSelector
918 || element.oMatchesSelector;
919 matcher = function(selector) {
920 return function() {
921 return vendorMatches.call(this, selector);
922 };
923 };
924 }
925 }
926
927 var matcher$1 = matcher;
928
929 function selection_filter(match) {
930 if (typeof match !== "function") match = matcher$1(match);
931
932 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
933 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
934 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
935 subgroup.push(node);
936 }
937 }
938 }
939
940 return new Selection(subgroups, this._parents);
941 }
942
943 function sparse(update) {
944 return new Array(update.length);
945 }
946
947 function selection_enter() {
948 return new Selection(this._enter || this._groups.map(sparse), this._parents);
949 }
950
951 function EnterNode(parent, datum) {
952 this.ownerDocument = parent.ownerDocument;
953 this.namespaceURI = parent.namespaceURI;
954 this._next = null;
955 this._parent = parent;
956 this.__data__ = datum;
957 }
958
959 EnterNode.prototype = {
960 constructor: EnterNode,
961 appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
962 insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
963 querySelector: function(selector) { return this._parent.querySelector(selector); },
964 querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
965 };
966
967 function constant$1(x) {
968 return function() {
969 return x;
970 };
971 }
972
973 var keyPrefix = "$"; // Protect against keys like “__proto__”.
974
975 function bindIndex(parent, group, enter, update, exit, data) {
976 var i = 0,
977 node,
978 groupLength = group.length,
979 dataLength = data.length;
980
981 // Put any non-null nodes that fit into update.
982 // Put any null nodes into enter.
983 // Put any remaining data into enter.
984 for (; i < dataLength; ++i) {
985 if (node = group[i]) {
986 node.__data__ = data[i];
987 update[i] = node;
988 } else {
989 enter[i] = new EnterNode(parent, data[i]);
990 }
991 }
992
993 // Put any non-null nodes that don’t fit into exit.
994 for (; i < groupLength; ++i) {
995 if (node = group[i]) {
996 exit[i] = node;
997 }
998 }
999 }
1000
1001 function bindKey(parent, group, enter, update, exit, data, key) {
1002 var i,
1003 node,
1004 nodeByKeyValue = {},
1005 groupLength = group.length,
1006 dataLength = data.length,
1007 keyValues = new Array(groupLength),
1008 keyValue;
1009
1010 // Compute the key for each node.
1011 // If multiple nodes have the same key, the duplicates are added to exit.
1012 for (i = 0; i < groupLength; ++i) {
1013 if (node = group[i]) {
1014 keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
1015 if (keyValue in nodeByKeyValue) {
1016 exit[i] = node;
1017 } else {
1018 nodeByKeyValue[keyValue] = node;
1019 }
1020 }
1021 }
1022
1023 // Compute the key for each datum.
1024 // If there a node associated with this key, join and add it to update.
1025 // If there is not (or the key is a duplicate), add it to enter.
1026 for (i = 0; i < dataLength; ++i) {
1027 keyValue = keyPrefix + key.call(parent, data[i], i, data);
1028 if (node = nodeByKeyValue[keyValue]) {
1029 update[i] = node;
1030 node.__data__ = data[i];
1031 nodeByKeyValue[keyValue] = null;
1032 } else {
1033 enter[i] = new EnterNode(parent, data[i]);
1034 }
1035 }
1036
1037 // Add any remaining nodes that were not bound to data to exit.
1038 for (i = 0; i < groupLength; ++i) {
1039 if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
1040 exit[i] = node;
1041 }
1042 }
1043 }
1044
1045 function selection_data(value, key) {
1046 if (!value) {
1047 data = new Array(this.size()), j = -1;
1048 this.each(function(d) { data[++j] = d; });
1049 return data;
1050 }
1051
1052 var bind = key ? bindKey : bindIndex,
1053 parents = this._parents,
1054 groups = this._groups;
1055
1056 if (typeof value !== "function") value = constant$1(value);
1057
1058 for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
1059 var parent = parents[j],
1060 group = groups[j],
1061 groupLength = group.length,
1062 data = value.call(parent, parent && parent.__data__, j, parents),
1063 dataLength = data.length,
1064 enterGroup = enter[j] = new Array(dataLength),
1065 updateGroup = update[j] = new Array(dataLength),
1066 exitGroup = exit[j] = new Array(groupLength);
1067
1068 bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
1069
1070 // Now connect the enter nodes to their following update node, such that
1071 // appendChild can insert the materialized enter node before this node,
1072 // rather than at the end of the parent node.
1073 for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
1074 if (previous = enterGroup[i0]) {
1075 if (i0 >= i1) i1 = i0 + 1;
1076 while (!(next = updateGroup[i1]) && ++i1 < dataLength);
1077 previous._next = next || null;
1078 }
1079 }
1080 }
1081
1082 update = new Selection(update, parents);
1083 update._enter = enter;
1084 update._exit = exit;
1085 return update;
1086 }
1087
1088 function selection_exit() {
1089 return new Selection(this._exit || this._groups.map(sparse), this._parents);
1090 }
1091
1092 function selection_merge(selection$$1) {
1093
1094 for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
1095 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
1096 if (node = group0[i] || group1[i]) {
1097 merge[i] = node;
1098 }
1099 }
1100 }
1101
1102 for (; j < m0; ++j) {
1103 merges[j] = groups0[j];
1104 }
1105
1106 return new Selection(merges, this._parents);
1107 }
1108
1109 function selection_order() {
1110
1111 for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
1112 for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
1113 if (node = group[i]) {
1114 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
1115 next = node;
1116 }
1117 }
1118 }
1119
1120 return this;
1121 }
1122
1123 function selection_sort(compare) {
1124 if (!compare) compare = ascending$1;
1125
1126 function compareNode(a, b) {
1127 return a && b ? compare(a.__data__, b.__data__) : !a - !b;
1128 }
1129
1130 for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
1131 for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
1132 if (node = group[i]) {
1133 sortgroup[i] = node;
1134 }
1135 }
1136 sortgroup.sort(compareNode);
1137 }
1138
1139 return new Selection(sortgroups, this._parents).order();
1140 }
1141
1142 function ascending$1(a, b) {
1143 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
1144 }
1145
1146 function selection_call() {
1147 var callback = arguments[0];
1148 arguments[0] = this;
1149 callback.apply(null, arguments);
1150 return this;
1151 }
1152
1153 function selection_nodes() {
1154 var nodes = new Array(this.size()), i = -1;
1155 this.each(function() { nodes[++i] = this; });
1156 return nodes;
1157 }
1158
1159 function selection_node() {
1160
1161 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1162 for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
1163 var node = group[i];
1164 if (node) return node;
1165 }
1166 }
1167
1168 return null;
1169 }
1170
1171 function selection_size() {
1172 var size = 0;
1173 this.each(function() { ++size; });
1174 return size;
1175 }
1176
1177 function selection_empty() {
1178 return !this.node();
1179 }
1180
1181 function selection_each(callback) {
1182
1183 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1184 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
1185 if (node = group[i]) callback.call(node, node.__data__, i, group);
1186 }
1187 }
1188
1189 return this;
1190 }
1191
1192 function attrRemove(name) {
1193 return function() {
1194 this.removeAttribute(name);
1195 };
1196 }
1197
1198 function attrRemoveNS(fullname) {
1199 return function() {
1200 this.removeAttributeNS(fullname.space, fullname.local);
1201 };
1202 }
1203
1204 function attrConstant(name, value) {
1205 return function() {
1206 this.setAttribute(name, value);
1207 };
1208 }
1209
1210 function attrConstantNS(fullname, value) {
1211 return function() {
1212 this.setAttributeNS(fullname.space, fullname.local, value);
1213 };
1214 }
1215
1216 function attrFunction(name, value) {
1217 return function() {
1218 var v = value.apply(this, arguments);
1219 if (v == null) this.removeAttribute(name);
1220 else this.setAttribute(name, v);
1221 };
1222 }
1223
1224 function attrFunctionNS(fullname, value) {
1225 return function() {
1226 var v = value.apply(this, arguments);
1227 if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
1228 else this.setAttributeNS(fullname.space, fullname.local, v);
1229 };
1230 }
1231
1232 function selection_attr(name, value) {
1233 var fullname = namespace(name);
1234
1235 if (arguments.length < 2) {
1236 var node = this.node();
1237 return fullname.local
1238 ? node.getAttributeNS(fullname.space, fullname.local)
1239 : node.getAttribute(fullname);
1240 }
1241
1242 return this.each((value == null
1243 ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
1244 ? (fullname.local ? attrFunctionNS : attrFunction)
1245 : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
1246 }
1247
1248 function defaultView(node) {
1249 return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
1250 || (node.document && node) // node is a Window
1251 || node.defaultView; // node is a Document
1252 }
1253
1254 function styleRemove(name) {
1255 return function() {
1256 this.style.removeProperty(name);
1257 };
1258 }
1259
1260 function styleConstant(name, value, priority) {
1261 return function() {
1262 this.style.setProperty(name, value, priority);
1263 };
1264 }
1265
1266 function styleFunction(name, value, priority) {
1267 return function() {
1268 var v = value.apply(this, arguments);
1269 if (v == null) this.style.removeProperty(name);
1270 else this.style.setProperty(name, v, priority);
1271 };
1272 }
1273
1274 function selection_style(name, value, priority) {
1275 return arguments.length > 1
1276 ? this.each((value == null
1277 ? styleRemove : typeof value === "function"
1278 ? styleFunction
1279 : styleConstant)(name, value, priority == null ? "" : priority))
1280 : styleValue(this.node(), name);
1281 }
1282
1283 function styleValue(node, name) {
1284 return node.style.getPropertyValue(name)
1285 || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
1286 }
1287
1288 function propertyRemove(name) {
1289 return function() {
1290 delete this[name];
1291 };
1292 }
1293
1294 function propertyConstant(name, value) {
1295 return function() {
1296 this[name] = value;
1297 };
1298 }
1299
1300 function propertyFunction(name, value) {
1301 return function() {
1302 var v = value.apply(this, arguments);
1303 if (v == null) delete this[name];
1304 else this[name] = v;
1305 };
1306 }
1307
1308 function selection_property(name, value) {
1309 return arguments.length > 1
1310 ? this.each((value == null
1311 ? propertyRemove : typeof value === "function"
1312 ? propertyFunction
1313 : propertyConstant)(name, value))
1314 : this.node()[name];
1315 }
1316
1317 function classArray(string) {
1318 return string.trim().split(/^|\s+/);
1319 }
1320
1321 function classList(node) {
1322 return node.classList || new ClassList(node);
1323 }
1324
1325 function ClassList(node) {
1326 this._node = node;
1327 this._names = classArray(node.getAttribute("class") || "");
1328 }
1329
1330 ClassList.prototype = {
1331 add: function(name) {
1332 var i = this._names.indexOf(name);
1333 if (i < 0) {
1334 this._names.push(name);
1335 this._node.setAttribute("class", this._names.join(" "));
1336 }
1337 },
1338 remove: function(name) {
1339 var i = this._names.indexOf(name);
1340 if (i >= 0) {
1341 this._names.splice(i, 1);
1342 this._node.setAttribute("class", this._names.join(" "));
1343 }
1344 },
1345 contains: function(name) {
1346 return this._names.indexOf(name) >= 0;
1347 }
1348 };
1349
1350 function classedAdd(node, names) {
1351 var list = classList(node), i = -1, n = names.length;
1352 while (++i < n) list.add(names[i]);
1353 }
1354
1355 function classedRemove(node, names) {
1356 var list = classList(node), i = -1, n = names.length;
1357 while (++i < n) list.remove(names[i]);
1358 }
1359
1360 function classedTrue(names) {
1361 return function() {
1362 classedAdd(this, names);
1363 };
1364 }
1365
1366 function classedFalse(names) {
1367 return function() {
1368 classedRemove(this, names);
1369 };
1370 }
1371
1372 function classedFunction(names, value) {
1373 return function() {
1374 (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
1375 };
1376 }
1377
1378 function selection_classed(name, value) {
1379 var names = classArray(name + "");
1380
1381 if (arguments.length < 2) {
1382 var list = classList(this.node()), i = -1, n = names.length;
1383 while (++i < n) if (!list.contains(names[i])) return false;
1384 return true;
1385 }
1386
1387 return this.each((typeof value === "function"
1388 ? classedFunction : value
1389 ? classedTrue
1390 : classedFalse)(names, value));
1391 }
1392
1393 function textRemove() {
1394 this.textContent = "";
1395 }
1396
1397 function textConstant(value) {
1398 return function() {
1399 this.textContent = value;
1400 };
1401 }
1402
1403 function textFunction(value) {
1404 return function() {
1405 var v = value.apply(this, arguments);
1406 this.textContent = v == null ? "" : v;
1407 };
1408 }
1409
1410 function selection_text(value) {
1411 return arguments.length
1412 ? this.each(value == null
1413 ? textRemove : (typeof value === "function"
1414 ? textFunction
1415 : textConstant)(value))
1416 : this.node().textContent;
1417 }
1418
1419 function htmlRemove() {
1420 this.innerHTML = "";
1421 }
1422
1423 function htmlConstant(value) {
1424 return function() {
1425 this.innerHTML = value;
1426 };
1427 }
1428
1429 function htmlFunction(value) {
1430 return function() {
1431 var v = value.apply(this, arguments);
1432 this.innerHTML = v == null ? "" : v;
1433 };
1434 }
1435
1436 function selection_html(value) {
1437 return arguments.length
1438 ? this.each(value == null
1439 ? htmlRemove : (typeof value === "function"
1440 ? htmlFunction
1441 : htmlConstant)(value))
1442 : this.node().innerHTML;
1443 }
1444
1445 function raise() {
1446 if (this.nextSibling) this.parentNode.appendChild(this);
1447 }
1448
1449 function selection_raise() {
1450 return this.each(raise);
1451 }
1452
1453 function lower() {
1454 if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
1455 }
1456
1457 function selection_lower() {
1458 return this.each(lower);
1459 }
1460
1461 function selection_append(name) {
1462 var create = typeof name === "function" ? name : creator(name);
1463 return this.select(function() {
1464 return this.appendChild(create.apply(this, arguments));
1465 });
1466 }
1467
1468 function constantNull() {
1469 return null;
1470 }
1471
1472 function selection_insert(name, before) {
1473 var create = typeof name === "function" ? name : creator(name),
1474 select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
1475 return this.select(function() {
1476 return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
1477 });
1478 }
1479
1480 function remove() {
1481 var parent = this.parentNode;
1482 if (parent) parent.removeChild(this);
1483 }
1484
1485 function selection_remove() {
1486 return this.each(remove);
1487 }
1488
1489 function selection_cloneShallow() {
1490 return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
1491 }
1492
1493 function selection_cloneDeep() {
1494 return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
1495 }
1496
1497 function selection_clone(deep) {
1498 return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
1499 }
1500
1501 function selection_datum(value) {
1502 return arguments.length
1503 ? this.property("__data__", value)
1504 : this.node().__data__;
1505 }
1506
1507 var filterEvents = {};
1508
1509 exports.event = null;
1510
1511 if (typeof document !== "undefined") {
1512 var element$1 = document.documentElement;
1513 if (!("onmouseenter" in element$1)) {
1514 filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
1515 }
1516 }
1517
1518 function filterContextListener(listener, index, group) {
1519 listener = contextListener(listener, index, group);
1520 return function(event) {
1521 var related = event.relatedTarget;
1522 if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
1523 listener.call(this, event);
1524 }
1525 };
1526 }
1527
1528 function contextListener(listener, index, group) {
1529 return function(event1) {
1530 var event0 = exports.event; // Events can be reentrant (e.g., focus).
1531 exports.event = event1;
1532 try {
1533 listener.call(this, this.__data__, index, group);
1534 } finally {
1535 exports.event = event0;
1536 }
1537 };
1538 }
1539
1540 function parseTypenames$1(typenames) {
1541 return typenames.trim().split(/^|\s+/).map(function(t) {
1542 var name = "", i = t.indexOf(".");
1543 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
1544 return {type: t, name: name};
1545 });
1546 }
1547
1548 function onRemove(typename) {
1549 return function() {
1550 var on = this.__on;
1551 if (!on) return;
1552 for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
1553 if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
1554 this.removeEventListener(o.type, o.listener, o.capture);
1555 } else {
1556 on[++i] = o;
1557 }
1558 }
1559 if (++i) on.length = i;
1560 else delete this.__on;
1561 };
1562 }
1563
1564 function onAdd(typename, value, capture) {
1565 var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
1566 return function(d, i, group) {
1567 var on = this.__on, o, listener = wrap(value, i, group);
1568 if (on) for (var j = 0, m = on.length; j < m; ++j) {
1569 if ((o = on[j]).type === typename.type && o.name === typename.name) {
1570 this.removeEventListener(o.type, o.listener, o.capture);
1571 this.addEventListener(o.type, o.listener = listener, o.capture = capture);
1572 o.value = value;
1573 return;
1574 }
1575 }
1576 this.addEventListener(typename.type, listener, capture);
1577 o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
1578 if (!on) this.__on = [o];
1579 else on.push(o);
1580 };
1581 }
1582
1583 function selection_on(typename, value, capture) {
1584 var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
1585
1586 if (arguments.length < 2) {
1587 var on = this.node().__on;
1588 if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
1589 for (i = 0, o = on[j]; i < n; ++i) {
1590 if ((t = typenames[i]).type === o.type && t.name === o.name) {
1591 return o.value;
1592 }
1593 }
1594 }
1595 return;
1596 }
1597
1598 on = value ? onAdd : onRemove;
1599 if (capture == null) capture = false;
1600 for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
1601 return this;
1602 }
1603
1604 function customEvent(event1, listener, that, args) {
1605 var event0 = exports.event;
1606 event1.sourceEvent = exports.event;
1607 exports.event = event1;
1608 try {
1609 return listener.apply(that, args);
1610 } finally {
1611 exports.event = event0;
1612 }
1613 }
1614
1615 function dispatchEvent(node, type, params) {
1616 var window = defaultView(node),
1617 event = window.CustomEvent;
1618
1619 if (typeof event === "function") {
1620 event = new event(type, params);
1621 } else {
1622 event = window.document.createEvent("Event");
1623 if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
1624 else event.initEvent(type, false, false);
1625 }
1626
1627 node.dispatchEvent(event);
1628 }
1629
1630 function dispatchConstant(type, params) {
1631 return function() {
1632 return dispatchEvent(this, type, params);
1633 };
1634 }
1635
1636 function dispatchFunction(type, params) {
1637 return function() {
1638 return dispatchEvent(this, type, params.apply(this, arguments));
1639 };
1640 }
1641
1642 function selection_dispatch(type, params) {
1643 return this.each((typeof params === "function"
1644 ? dispatchFunction
1645 : dispatchConstant)(type, params));
1646 }
1647
1648 var root = [null];
1649
1650 function Selection(groups, parents) {
1651 this._groups = groups;
1652 this._parents = parents;
1653 }
1654
1655 function selection() {
1656 return new Selection([[document.documentElement]], root);
1657 }
1658
1659 Selection.prototype = selection.prototype = {
1660 constructor: Selection,
1661 select: selection_select,
1662 selectAll: selection_selectAll,
1663 filter: selection_filter,
1664 data: selection_data,
1665 enter: selection_enter,
1666 exit: selection_exit,
1667 merge: selection_merge,
1668 order: selection_order,
1669 sort: selection_sort,
1670 call: selection_call,
1671 nodes: selection_nodes,
1672 node: selection_node,
1673 size: selection_size,
1674 empty: selection_empty,
1675 each: selection_each,
1676 attr: selection_attr,
1677 style: selection_style,
1678 property: selection_property,
1679 classed: selection_classed,
1680 text: selection_text,
1681 html: selection_html,
1682 raise: selection_raise,
1683 lower: selection_lower,
1684 append: selection_append,
1685 insert: selection_insert,
1686 remove: selection_remove,
1687 clone: selection_clone,
1688 datum: selection_datum,
1689 on: selection_on,
1690 dispatch: selection_dispatch
1691 };
1692
1693 function select(selector) {
1694 return typeof selector === "string"
1695 ? new Selection([[document.querySelector(selector)]], [document.documentElement])
1696 : new Selection([[selector]], root);
1697 }
1698
1699 function create(name) {
1700 return select(creator(name).call(document.documentElement));
1701 }
1702
1703 var nextId = 0;
1704
1705 function local$1() {
1706 return new Local;
1707 }
1708
1709 function Local() {
1710 this._ = "@" + (++nextId).toString(36);
1711 }
1712
1713 Local.prototype = local$1.prototype = {
1714 constructor: Local,
1715 get: function(node) {
1716 var id = this._;
1717 while (!(id in node)) if (!(node = node.parentNode)) return;
1718 return node[id];
1719 },
1720 set: function(node, value) {
1721 return node[this._] = value;
1722 },
1723 remove: function(node) {
1724 return this._ in node && delete node[this._];
1725 },
1726 toString: function() {
1727 return this._;
1728 }
1729 };
1730
1731 function sourceEvent() {
1732 var current = exports.event, source;
1733 while (source = current.sourceEvent) current = source;
1734 return current;
1735 }
1736
1737 function point(node, event) {
1738 var svg = node.ownerSVGElement || node;
1739
1740 if (svg.createSVGPoint) {
1741 var point = svg.createSVGPoint();
1742 point.x = event.clientX, point.y = event.clientY;
1743 point = point.matrixTransform(node.getScreenCTM().inverse());
1744 return [point.x, point.y];
1745 }
1746
1747 var rect = node.getBoundingClientRect();
1748 return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
1749 }
1750
1751 function mouse(node) {
1752 var event = sourceEvent();
1753 if (event.changedTouches) event = event.changedTouches[0];
1754 return point(node, event);
1755 }
1756
1757 function selectAll(selector) {
1758 return typeof selector === "string"
1759 ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
1760 : new Selection([selector == null ? [] : selector], root);
1761 }
1762
1763 function touch(node, touches, identifier) {
1764 if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
1765
1766 for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
1767 if ((touch = touches[i]).identifier === identifier) {
1768 return point(node, touch);
1769 }
1770 }
1771
1772 return null;
1773 }
1774
1775 function touches(node, touches) {
1776 if (touches == null) touches = sourceEvent().touches;
1777
1778 for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
1779 points[i] = point(node, touches[i]);
1780 }
1781
1782 return points;
1783 }
1784
1785 function nopropagation() {
1786 exports.event.stopImmediatePropagation();
1787 }
1788
1789 function noevent() {
1790 exports.event.preventDefault();
1791 exports.event.stopImmediatePropagation();
1792 }
1793
1794 function dragDisable(view) {
1795 var root = view.document.documentElement,
1796 selection = select(view).on("dragstart.drag", noevent, true);
1797 if ("onselectstart" in root) {
1798 selection.on("selectstart.drag", noevent, true);
1799 } else {
1800 root.__noselect = root.style.MozUserSelect;
1801 root.style.MozUserSelect = "none";
1802 }
1803 }
1804
1805 function yesdrag(view, noclick) {
1806 var root = view.document.documentElement,
1807 selection = select(view).on("dragstart.drag", null);
1808 if (noclick) {
1809 selection.on("click.drag", noevent, true);
1810 setTimeout(function() { selection.on("click.drag", null); }, 0);
1811 }
1812 if ("onselectstart" in root) {
1813 selection.on("selectstart.drag", null);
1814 } else {
1815 root.style.MozUserSelect = root.__noselect;
1816 delete root.__noselect;
1817 }
1818 }
1819
1820 function constant$2(x) {
1821 return function() {
1822 return x;
1823 };
1824 }
1825
1826 function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
1827 this.target = target;
1828 this.type = type;
1829 this.subject = subject;
1830 this.identifier = id;
1831 this.active = active;
1832 this.x = x;
1833 this.y = y;
1834 this.dx = dx;
1835 this.dy = dy;
1836 this._ = dispatch;
1837 }
1838
1839 DragEvent.prototype.on = function() {
1840 var value = this._.on.apply(this._, arguments);
1841 return value === this._ ? this : value;
1842 };
1843
1844 // Ignore right-click, since that should open the context menu.
1845 function defaultFilter$1() {
1846 return !exports.event.button;
1847 }
1848
1849 function defaultContainer() {
1850 return this.parentNode;
1851 }
1852
1853 function defaultSubject(d) {
1854 return d == null ? {x: exports.event.x, y: exports.event.y} : d;
1855 }
1856
1857 function defaultTouchable() {
1858 return "ontouchstart" in this;
1859 }
1860
1861 function drag() {
1862 var filter = defaultFilter$1,
1863 container = defaultContainer,
1864 subject = defaultSubject,
1865 touchable = defaultTouchable,
1866 gestures = {},
1867 listeners = dispatch("start", "drag", "end"),
1868 active = 0,
1869 mousedownx,
1870 mousedowny,
1871 mousemoving,
1872 touchending,
1873 clickDistance2 = 0;
1874
1875 function drag(selection) {
1876 selection
1877 .on("mousedown.drag", mousedowned)
1878 .filter(touchable)
1879 .on("touchstart.drag", touchstarted)
1880 .on("touchmove.drag", touchmoved)
1881 .on("touchend.drag touchcancel.drag", touchended)
1882 .style("touch-action", "none")
1883 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
1884 }
1885
1886 function mousedowned() {
1887 if (touchending || !filter.apply(this, arguments)) return;
1888 var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
1889 if (!gesture) return;
1890 select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
1891 dragDisable(exports.event.view);
1892 nopropagation();
1893 mousemoving = false;
1894 mousedownx = exports.event.clientX;
1895 mousedowny = exports.event.clientY;
1896 gesture("start");
1897 }
1898
1899 function mousemoved() {
1900 noevent();
1901 if (!mousemoving) {
1902 var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
1903 mousemoving = dx * dx + dy * dy > clickDistance2;
1904 }
1905 gestures.mouse("drag");
1906 }
1907
1908 function mouseupped() {
1909 select(exports.event.view).on("mousemove.drag mouseup.drag", null);
1910 yesdrag(exports.event.view, mousemoving);
1911 noevent();
1912 gestures.mouse("end");
1913 }
1914
1915 function touchstarted() {
1916 if (!filter.apply(this, arguments)) return;
1917 var touches = exports.event.changedTouches,
1918 c = container.apply(this, arguments),
1919 n = touches.length, i, gesture;
1920
1921 for (i = 0; i < n; ++i) {
1922 if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
1923 nopropagation();
1924 gesture("start");
1925 }
1926 }
1927 }
1928
1929 function touchmoved() {
1930 var touches = exports.event.changedTouches,
1931 n = touches.length, i, gesture;
1932
1933 for (i = 0; i < n; ++i) {
1934 if (gesture = gestures[touches[i].identifier]) {
1935 noevent();
1936 gesture("drag");
1937 }
1938 }
1939 }
1940
1941 function touchended() {
1942 var touches = exports.event.changedTouches,
1943 n = touches.length, i, gesture;
1944
1945 if (touchending) clearTimeout(touchending);
1946 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
1947 for (i = 0; i < n; ++i) {
1948 if (gesture = gestures[touches[i].identifier]) {
1949 nopropagation();
1950 gesture("end");
1951 }
1952 }
1953 }
1954
1955 function beforestart(id, container, point, that, args) {
1956 var p = point(container, id), s, dx, dy,
1957 sublisteners = listeners.copy();
1958
1959 if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
1960 if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
1961 dx = s.x - p[0] || 0;
1962 dy = s.y - p[1] || 0;
1963 return true;
1964 })) return;
1965
1966 return function gesture(type) {
1967 var p0 = p, n;
1968 switch (type) {
1969 case "start": gestures[id] = gesture, n = active++; break;
1970 case "end": delete gestures[id], --active; // nobreak
1971 case "drag": p = point(container, id), n = active; break;
1972 }
1973 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]);
1974 };
1975 }
1976
1977 drag.filter = function(_) {
1978 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
1979 };
1980
1981 drag.container = function(_) {
1982 return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
1983 };
1984
1985 drag.subject = function(_) {
1986 return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
1987 };
1988
1989 drag.touchable = function(_) {
1990 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
1991 };
1992
1993 drag.on = function() {
1994 var value = listeners.on.apply(listeners, arguments);
1995 return value === listeners ? drag : value;
1996 };
1997
1998 drag.clickDistance = function(_) {
1999 return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
2000 };
2001
2002 return drag;
2003 }
2004
2005 function define(constructor, factory, prototype) {
2006 constructor.prototype = factory.prototype = prototype;
2007 prototype.constructor = constructor;
2008 }
2009
2010 function extend(parent, definition) {
2011 var prototype = Object.create(parent.prototype);
2012 for (var key in definition) prototype[key] = definition[key];
2013 return prototype;
2014 }
2015
2016 function Color() {}
2017
2018 var darker = 0.7;
2019 var brighter = 1 / darker;
2020
2021 var reI = "\\s*([+-]?\\d+)\\s*";
2022 var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
2023 var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
2024 var reHex3 = /^#([0-9a-f]{3})$/;
2025 var reHex6 = /^#([0-9a-f]{6})$/;
2026 var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
2027 var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
2028 var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
2029 var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
2030 var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
2031 var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
2032
2033 var named = {
2034 aliceblue: 0xf0f8ff,
2035 antiquewhite: 0xfaebd7,
2036 aqua: 0x00ffff,
2037 aquamarine: 0x7fffd4,
2038 azure: 0xf0ffff,
2039 beige: 0xf5f5dc,
2040 bisque: 0xffe4c4,
2041 black: 0x000000,
2042 blanchedalmond: 0xffebcd,
2043 blue: 0x0000ff,
2044 blueviolet: 0x8a2be2,
2045 brown: 0xa52a2a,
2046 burlywood: 0xdeb887,
2047 cadetblue: 0x5f9ea0,
2048 chartreuse: 0x7fff00,
2049 chocolate: 0xd2691e,
2050 coral: 0xff7f50,
2051 cornflowerblue: 0x6495ed,
2052 cornsilk: 0xfff8dc,
2053 crimson: 0xdc143c,
2054 cyan: 0x00ffff,
2055 darkblue: 0x00008b,
2056 darkcyan: 0x008b8b,
2057 darkgoldenrod: 0xb8860b,
2058 darkgray: 0xa9a9a9,
2059 darkgreen: 0x006400,
2060 darkgrey: 0xa9a9a9,
2061 darkkhaki: 0xbdb76b,
2062 darkmagenta: 0x8b008b,
2063 darkolivegreen: 0x556b2f,
2064 darkorange: 0xff8c00,
2065 darkorchid: 0x9932cc,
2066 darkred: 0x8b0000,
2067 darksalmon: 0xe9967a,
2068 darkseagreen: 0x8fbc8f,
2069 darkslateblue: 0x483d8b,
2070 darkslategray: 0x2f4f4f,
2071 darkslategrey: 0x2f4f4f,
2072 darkturquoise: 0x00ced1,
2073 darkviolet: 0x9400d3,
2074 deeppink: 0xff1493,
2075 deepskyblue: 0x00bfff,
2076 dimgray: 0x696969,
2077 dimgrey: 0x696969,
2078 dodgerblue: 0x1e90ff,
2079 firebrick: 0xb22222,
2080 floralwhite: 0xfffaf0,
2081 forestgreen: 0x228b22,
2082 fuchsia: 0xff00ff,
2083 gainsboro: 0xdcdcdc,
2084 ghostwhite: 0xf8f8ff,
2085 gold: 0xffd700,
2086 goldenrod: 0xdaa520,
2087 gray: 0x808080,
2088 green: 0x008000,
2089 greenyellow: 0xadff2f,
2090 grey: 0x808080,
2091 honeydew: 0xf0fff0,
2092 hotpink: 0xff69b4,
2093 indianred: 0xcd5c5c,
2094 indigo: 0x4b0082,
2095 ivory: 0xfffff0,
2096 khaki: 0xf0e68c,
2097 lavender: 0xe6e6fa,
2098 lavenderblush: 0xfff0f5,
2099 lawngreen: 0x7cfc00,
2100 lemonchiffon: 0xfffacd,
2101 lightblue: 0xadd8e6,
2102 lightcoral: 0xf08080,
2103 lightcyan: 0xe0ffff,
2104 lightgoldenrodyellow: 0xfafad2,
2105 lightgray: 0xd3d3d3,
2106 lightgreen: 0x90ee90,
2107 lightgrey: 0xd3d3d3,
2108 lightpink: 0xffb6c1,
2109 lightsalmon: 0xffa07a,
2110 lightseagreen: 0x20b2aa,
2111 lightskyblue: 0x87cefa,
2112 lightslategray: 0x778899,
2113 lightslategrey: 0x778899,
2114 lightsteelblue: 0xb0c4de,
2115 lightyellow: 0xffffe0,
2116 lime: 0x00ff00,
2117 limegreen: 0x32cd32,
2118 linen: 0xfaf0e6,
2119 magenta: 0xff00ff,
2120 maroon: 0x800000,
2121 mediumaquamarine: 0x66cdaa,
2122 mediumblue: 0x0000cd,
2123 mediumorchid: 0xba55d3,
2124 mediumpurple: 0x9370db,
2125 mediumseagreen: 0x3cb371,
2126 mediumslateblue: 0x7b68ee,
2127 mediumspringgreen: 0x00fa9a,
2128 mediumturquoise: 0x48d1cc,
2129 mediumvioletred: 0xc71585,
2130 midnightblue: 0x191970,
2131 mintcream: 0xf5fffa,
2132 mistyrose: 0xffe4e1,
2133 moccasin: 0xffe4b5,
2134 navajowhite: 0xffdead,
2135 navy: 0x000080,
2136 oldlace: 0xfdf5e6,
2137 olive: 0x808000,
2138 olivedrab: 0x6b8e23,
2139 orange: 0xffa500,
2140 orangered: 0xff4500,
2141 orchid: 0xda70d6,
2142 palegoldenrod: 0xeee8aa,
2143 palegreen: 0x98fb98,
2144 paleturquoise: 0xafeeee,
2145 palevioletred: 0xdb7093,
2146 papayawhip: 0xffefd5,
2147 peachpuff: 0xffdab9,
2148 peru: 0xcd853f,
2149 pink: 0xffc0cb,
2150 plum: 0xdda0dd,
2151 powderblue: 0xb0e0e6,
2152 purple: 0x800080,
2153 rebeccapurple: 0x663399,
2154 red: 0xff0000,
2155 rosybrown: 0xbc8f8f,
2156 royalblue: 0x4169e1,
2157 saddlebrown: 0x8b4513,
2158 salmon: 0xfa8072,
2159 sandybrown: 0xf4a460,
2160 seagreen: 0x2e8b57,
2161 seashell: 0xfff5ee,
2162 sienna: 0xa0522d,
2163 silver: 0xc0c0c0,
2164 skyblue: 0x87ceeb,
2165 slateblue: 0x6a5acd,
2166 slategray: 0x708090,
2167 slategrey: 0x708090,
2168 snow: 0xfffafa,
2169 springgreen: 0x00ff7f,
2170 steelblue: 0x4682b4,
2171 tan: 0xd2b48c,
2172 teal: 0x008080,
2173 thistle: 0xd8bfd8,
2174 tomato: 0xff6347,
2175 turquoise: 0x40e0d0,
2176 violet: 0xee82ee,
2177 wheat: 0xf5deb3,
2178 white: 0xffffff,
2179 whitesmoke: 0xf5f5f5,
2180 yellow: 0xffff00,
2181 yellowgreen: 0x9acd32
2182 };
2183
2184 define(Color, color, {
2185 displayable: function() {
2186 return this.rgb().displayable();
2187 },
2188 toString: function() {
2189 return this.rgb() + "";
2190 }
2191 });
2192
2193 function color(format) {
2194 var m;
2195 format = (format + "").trim().toLowerCase();
2196 return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
2197 : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
2198 : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
2199 : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
2200 : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
2201 : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
2202 : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
2203 : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
2204 : named.hasOwnProperty(format) ? rgbn(named[format])
2205 : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
2206 : null;
2207 }
2208
2209 function rgbn(n) {
2210 return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
2211 }
2212
2213 function rgba(r, g, b, a) {
2214 if (a <= 0) r = g = b = NaN;
2215 return new Rgb(r, g, b, a);
2216 }
2217
2218 function rgbConvert(o) {
2219 if (!(o instanceof Color)) o = color(o);
2220 if (!o) return new Rgb;
2221 o = o.rgb();
2222 return new Rgb(o.r, o.g, o.b, o.opacity);
2223 }
2224
2225 function rgb(r, g, b, opacity) {
2226 return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
2227 }
2228
2229 function Rgb(r, g, b, opacity) {
2230 this.r = +r;
2231 this.g = +g;
2232 this.b = +b;
2233 this.opacity = +opacity;
2234 }
2235
2236 define(Rgb, rgb, extend(Color, {
2237 brighter: function(k) {
2238 k = k == null ? brighter : Math.pow(brighter, k);
2239 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2240 },
2241 darker: function(k) {
2242 k = k == null ? darker : Math.pow(darker, k);
2243 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2244 },
2245 rgb: function() {
2246 return this;
2247 },
2248 displayable: function() {
2249 return (0 <= this.r && this.r <= 255)
2250 && (0 <= this.g && this.g <= 255)
2251 && (0 <= this.b && this.b <= 255)
2252 && (0 <= this.opacity && this.opacity <= 1);
2253 },
2254 toString: function() {
2255 var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2256 return (a === 1 ? "rgb(" : "rgba(")
2257 + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
2258 + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
2259 + Math.max(0, Math.min(255, Math.round(this.b) || 0))
2260 + (a === 1 ? ")" : ", " + a + ")");
2261 }
2262 }));
2263
2264 function hsla(h, s, l, a) {
2265 if (a <= 0) h = s = l = NaN;
2266 else if (l <= 0 || l >= 1) h = s = NaN;
2267 else if (s <= 0) h = NaN;
2268 return new Hsl(h, s, l, a);
2269 }
2270
2271 function hslConvert(o) {
2272 if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2273 if (!(o instanceof Color)) o = color(o);
2274 if (!o) return new Hsl;
2275 if (o instanceof Hsl) return o;
2276 o = o.rgb();
2277 var r = o.r / 255,
2278 g = o.g / 255,
2279 b = o.b / 255,
2280 min = Math.min(r, g, b),
2281 max = Math.max(r, g, b),
2282 h = NaN,
2283 s = max - min,
2284 l = (max + min) / 2;
2285 if (s) {
2286 if (r === max) h = (g - b) / s + (g < b) * 6;
2287 else if (g === max) h = (b - r) / s + 2;
2288 else h = (r - g) / s + 4;
2289 s /= l < 0.5 ? max + min : 2 - max - min;
2290 h *= 60;
2291 } else {
2292 s = l > 0 && l < 1 ? 0 : h;
2293 }
2294 return new Hsl(h, s, l, o.opacity);
2295 }
2296
2297 function hsl(h, s, l, opacity) {
2298 return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2299 }
2300
2301 function Hsl(h, s, l, opacity) {
2302 this.h = +h;
2303 this.s = +s;
2304 this.l = +l;
2305 this.opacity = +opacity;
2306 }
2307
2308 define(Hsl, hsl, extend(Color, {
2309 brighter: function(k) {
2310 k = k == null ? brighter : Math.pow(brighter, k);
2311 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2312 },
2313 darker: function(k) {
2314 k = k == null ? darker : Math.pow(darker, k);
2315 return new Hsl(this.h, this.s, this.l * k, this.opacity);
2316 },
2317 rgb: function() {
2318 var h = this.h % 360 + (this.h < 0) * 360,
2319 s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
2320 l = this.l,
2321 m2 = l + (l < 0.5 ? l : 1 - l) * s,
2322 m1 = 2 * l - m2;
2323 return new Rgb(
2324 hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
2325 hsl2rgb(h, m1, m2),
2326 hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
2327 this.opacity
2328 );
2329 },
2330 displayable: function() {
2331 return (0 <= this.s && this.s <= 1 || isNaN(this.s))
2332 && (0 <= this.l && this.l <= 1)
2333 && (0 <= this.opacity && this.opacity <= 1);
2334 }
2335 }));
2336
2337 /* From FvD 13.37, CSS Color Module Level 3 */
2338 function hsl2rgb(h, m1, m2) {
2339 return (h < 60 ? m1 + (m2 - m1) * h / 60
2340 : h < 180 ? m2
2341 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
2342 : m1) * 255;
2343 }
2344
2345 var deg2rad = Math.PI / 180;
2346 var rad2deg = 180 / Math.PI;
2347
2348 var Kn = 18;
2349 var Xn = 0.950470;
2350 var Yn = 1;
2351 var Zn = 1.088830;
2352 var t0 = 4 / 29;
2353 var t1 = 6 / 29;
2354 var t2 = 3 * t1 * t1;
2355 var t3 = t1 * t1 * t1;
2356
2357 function labConvert(o) {
2358 if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
2359 if (o instanceof Hcl) {
2360 var h = o.h * deg2rad;
2361 return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
2362 }
2363 if (!(o instanceof Rgb)) o = rgbConvert(o);
2364 var b = rgb2xyz(o.r),
2365 a = rgb2xyz(o.g),
2366 l = rgb2xyz(o.b),
2367 x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
2368 y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
2369 z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
2370 return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
2371 }
2372
2373 function lab(l, a, b, opacity) {
2374 return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
2375 }
2376
2377 function Lab(l, a, b, opacity) {
2378 this.l = +l;
2379 this.a = +a;
2380 this.b = +b;
2381 this.opacity = +opacity;
2382 }
2383
2384 define(Lab, lab, extend(Color, {
2385 brighter: function(k) {
2386 return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
2387 },
2388 darker: function(k) {
2389 return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
2390 },
2391 rgb: function() {
2392 var y = (this.l + 16) / 116,
2393 x = isNaN(this.a) ? y : y + this.a / 500,
2394 z = isNaN(this.b) ? y : y - this.b / 200;
2395 y = Yn * lab2xyz(y);
2396 x = Xn * lab2xyz(x);
2397 z = Zn * lab2xyz(z);
2398 return new Rgb(
2399 xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
2400 xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
2401 xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
2402 this.opacity
2403 );
2404 }
2405 }));
2406
2407 function xyz2lab(t) {
2408 return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
2409 }
2410
2411 function lab2xyz(t) {
2412 return t > t1 ? t * t * t : t2 * (t - t0);
2413 }
2414
2415 function xyz2rgb(x) {
2416 return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
2417 }
2418
2419 function rgb2xyz(x) {
2420 return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
2421 }
2422
2423 function hclConvert(o) {
2424 if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
2425 if (!(o instanceof Lab)) o = labConvert(o);
2426 var h = Math.atan2(o.b, o.a) * rad2deg;
2427 return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
2428 }
2429
2430 function hcl(h, c, l, opacity) {
2431 return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2432 }
2433
2434 function Hcl(h, c, l, opacity) {
2435 this.h = +h;
2436 this.c = +c;
2437 this.l = +l;
2438 this.opacity = +opacity;
2439 }
2440
2441 define(Hcl, hcl, extend(Color, {
2442 brighter: function(k) {
2443 return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
2444 },
2445 darker: function(k) {
2446 return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
2447 },
2448 rgb: function() {
2449 return labConvert(this).rgb();
2450 }
2451 }));
2452
2453 var A = -0.14861;
2454 var B = +1.78277;
2455 var C = -0.29227;
2456 var D = -0.90649;
2457 var E = +1.97294;
2458 var ED = E * D;
2459 var EB = E * B;
2460 var BC_DA = B * C - D * A;
2461
2462 function cubehelixConvert(o) {
2463 if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
2464 if (!(o instanceof Rgb)) o = rgbConvert(o);
2465 var r = o.r / 255,
2466 g = o.g / 255,
2467 b = o.b / 255,
2468 l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
2469 bl = b - l,
2470 k = (E * (g - l) - C * bl) / D,
2471 s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
2472 h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
2473 return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
2474 }
2475
2476 function cubehelix(h, s, l, opacity) {
2477 return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
2478 }
2479
2480 function Cubehelix(h, s, l, opacity) {
2481 this.h = +h;
2482 this.s = +s;
2483 this.l = +l;
2484 this.opacity = +opacity;
2485 }
2486
2487 define(Cubehelix, cubehelix, extend(Color, {
2488 brighter: function(k) {
2489 k = k == null ? brighter : Math.pow(brighter, k);
2490 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2491 },
2492 darker: function(k) {
2493 k = k == null ? darker : Math.pow(darker, k);
2494 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2495 },
2496 rgb: function() {
2497 var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
2498 l = +this.l,
2499 a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
2500 cosh = Math.cos(h),
2501 sinh = Math.sin(h);
2502 return new Rgb(
2503 255 * (l + a * (A * cosh + B * sinh)),
2504 255 * (l + a * (C * cosh + D * sinh)),
2505 255 * (l + a * (E * cosh)),
2506 this.opacity
2507 );
2508 }
2509 }));
2510
2511 function basis(t1, v0, v1, v2, v3) {
2512 var t2 = t1 * t1, t3 = t2 * t1;
2513 return ((1 - 3 * t1 + 3 * t2 - t3) * v0
2514 + (4 - 6 * t2 + 3 * t3) * v1
2515 + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
2516 + t3 * v3) / 6;
2517 }
2518
2519 function basis$1(values) {
2520 var n = values.length - 1;
2521 return function(t) {
2522 var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
2523 v1 = values[i],
2524 v2 = values[i + 1],
2525 v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
2526 v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
2527 return basis((t - i / n) * n, v0, v1, v2, v3);
2528 };
2529 }
2530
2531 function basisClosed(values) {
2532 var n = values.length;
2533 return function(t) {
2534 var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
2535 v0 = values[(i + n - 1) % n],
2536 v1 = values[i % n],
2537 v2 = values[(i + 1) % n],
2538 v3 = values[(i + 2) % n];
2539 return basis((t - i / n) * n, v0, v1, v2, v3);
2540 };
2541 }
2542
2543 function constant$3(x) {
2544 return function() {
2545 return x;
2546 };
2547 }
2548
2549 function linear(a, d) {
2550 return function(t) {
2551 return a + t * d;
2552 };
2553 }
2554
2555 function exponential(a, b, y) {
2556 return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
2557 return Math.pow(a + t * b, y);
2558 };
2559 }
2560
2561 function hue(a, b) {
2562 var d = b - a;
2563 return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
2564 }
2565
2566 function gamma(y) {
2567 return (y = +y) === 1 ? nogamma : function(a, b) {
2568 return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
2569 };
2570 }
2571
2572 function nogamma(a, b) {
2573 var d = b - a;
2574 return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
2575 }
2576
2577 var interpolateRgb = (function rgbGamma(y) {
2578 var color$$1 = gamma(y);
2579
2580 function rgb$$1(start, end) {
2581 var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
2582 g = color$$1(start.g, end.g),
2583 b = color$$1(start.b, end.b),
2584 opacity = nogamma(start.opacity, end.opacity);
2585 return function(t) {
2586 start.r = r(t);
2587 start.g = g(t);
2588 start.b = b(t);
2589 start.opacity = opacity(t);
2590 return start + "";
2591 };
2592 }
2593
2594 rgb$$1.gamma = rgbGamma;
2595
2596 return rgb$$1;
2597 })(1);
2598
2599 function rgbSpline(spline) {
2600 return function(colors) {
2601 var n = colors.length,
2602 r = new Array(n),
2603 g = new Array(n),
2604 b = new Array(n),
2605 i, color$$1;
2606 for (i = 0; i < n; ++i) {
2607 color$$1 = rgb(colors[i]);
2608 r[i] = color$$1.r || 0;
2609 g[i] = color$$1.g || 0;
2610 b[i] = color$$1.b || 0;
2611 }
2612 r = spline(r);
2613 g = spline(g);
2614 b = spline(b);
2615 color$$1.opacity = 1;
2616 return function(t) {
2617 color$$1.r = r(t);
2618 color$$1.g = g(t);
2619 color$$1.b = b(t);
2620 return color$$1 + "";
2621 };
2622 };
2623 }
2624
2625 var rgbBasis = rgbSpline(basis$1);
2626 var rgbBasisClosed = rgbSpline(basisClosed);
2627
2628 function array$1(a, b) {
2629 var nb = b ? b.length : 0,
2630 na = a ? Math.min(nb, a.length) : 0,
2631 x = new Array(na),
2632 c = new Array(nb),
2633 i;
2634
2635 for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
2636 for (; i < nb; ++i) c[i] = b[i];
2637
2638 return function(t) {
2639 for (i = 0; i < na; ++i) c[i] = x[i](t);
2640 return c;
2641 };
2642 }
2643
2644 function date(a, b) {
2645 var d = new Date;
2646 return a = +a, b -= a, function(t) {
2647 return d.setTime(a + b * t), d;
2648 };
2649 }
2650
2651 function reinterpolate(a, b) {
2652 return a = +a, b -= a, function(t) {
2653 return a + b * t;
2654 };
2655 }
2656
2657 function object(a, b) {
2658 var i = {},
2659 c = {},
2660 k;
2661
2662 if (a === null || typeof a !== "object") a = {};
2663 if (b === null || typeof b !== "object") b = {};
2664
2665 for (k in b) {
2666 if (k in a) {
2667 i[k] = interpolateValue(a[k], b[k]);
2668 } else {
2669 c[k] = b[k];
2670 }
2671 }
2672
2673 return function(t) {
2674 for (k in i) c[k] = i[k](t);
2675 return c;
2676 };
2677 }
2678
2679 var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
2680 var reB = new RegExp(reA.source, "g");
2681
2682 function zero(b) {
2683 return function() {
2684 return b;
2685 };
2686 }
2687
2688 function one(b) {
2689 return function(t) {
2690 return b(t) + "";
2691 };
2692 }
2693
2694 function interpolateString(a, b) {
2695 var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
2696 am, // current match in a
2697 bm, // current match in b
2698 bs, // string preceding current number in b, if any
2699 i = -1, // index in s
2700 s = [], // string constants and placeholders
2701 q = []; // number interpolators
2702
2703 // Coerce inputs to strings.
2704 a = a + "", b = b + "";
2705
2706 // Interpolate pairs of numbers in a & b.
2707 while ((am = reA.exec(a))
2708 && (bm = reB.exec(b))) {
2709 if ((bs = bm.index) > bi) { // a string precedes the next number in b
2710 bs = b.slice(bi, bs);
2711 if (s[i]) s[i] += bs; // coalesce with previous string
2712 else s[++i] = bs;
2713 }
2714 if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
2715 if (s[i]) s[i] += bm; // coalesce with previous string
2716 else s[++i] = bm;
2717 } else { // interpolate non-matching numbers
2718 s[++i] = null;
2719 q.push({i: i, x: reinterpolate(am, bm)});
2720 }
2721 bi = reB.lastIndex;
2722 }
2723
2724 // Add remains of b.
2725 if (bi < b.length) {
2726 bs = b.slice(bi);
2727 if (s[i]) s[i] += bs; // coalesce with previous string
2728 else s[++i] = bs;
2729 }
2730
2731 // Special optimization for only a single match.
2732 // Otherwise, interpolate each of the numbers and rejoin the string.
2733 return s.length < 2 ? (q[0]
2734 ? one(q[0].x)
2735 : zero(b))
2736 : (b = q.length, function(t) {
2737 for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
2738 return s.join("");
2739 });
2740 }
2741
2742 function interpolateValue(a, b) {
2743 var t = typeof b, c;
2744 return b == null || t === "boolean" ? constant$3(b)
2745 : (t === "number" ? reinterpolate
2746 : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
2747 : b instanceof color ? interpolateRgb
2748 : b instanceof Date ? date
2749 : Array.isArray(b) ? array$1
2750 : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
2751 : reinterpolate)(a, b);
2752 }
2753
2754 function interpolateRound(a, b) {
2755 return a = +a, b -= a, function(t) {
2756 return Math.round(a + b * t);
2757 };
2758 }
2759
2760 var degrees = 180 / Math.PI;
2761
2762 var identity$2 = {
2763 translateX: 0,
2764 translateY: 0,
2765 rotate: 0,
2766 skewX: 0,
2767 scaleX: 1,
2768 scaleY: 1
2769 };
2770
2771 function decompose(a, b, c, d, e, f) {
2772 var scaleX, scaleY, skewX;
2773 if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
2774 if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
2775 if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
2776 if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
2777 return {
2778 translateX: e,
2779 translateY: f,
2780 rotate: Math.atan2(b, a) * degrees,
2781 skewX: Math.atan(skewX) * degrees,
2782 scaleX: scaleX,
2783 scaleY: scaleY
2784 };
2785 }
2786
2787 var cssNode;
2788 var cssRoot;
2789 var cssView;
2790 var svgNode;
2791
2792 function parseCss(value) {
2793 if (value === "none") return identity$2;
2794 if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
2795 cssNode.style.transform = value;
2796 value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
2797 cssRoot.removeChild(cssNode);
2798 value = value.slice(7, -1).split(",");
2799 return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
2800 }
2801
2802 function parseSvg(value) {
2803 if (value == null) return identity$2;
2804 if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
2805 svgNode.setAttribute("transform", value);
2806 if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
2807 value = value.matrix;
2808 return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
2809 }
2810
2811 function interpolateTransform(parse, pxComma, pxParen, degParen) {
2812
2813 function pop(s) {
2814 return s.length ? s.pop() + " " : "";
2815 }
2816
2817 function translate(xa, ya, xb, yb, s, q) {
2818 if (xa !== xb || ya !== yb) {
2819 var i = s.push("translate(", null, pxComma, null, pxParen);
2820 q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2821 } else if (xb || yb) {
2822 s.push("translate(" + xb + pxComma + yb + pxParen);
2823 }
2824 }
2825
2826 function rotate(a, b, s, q) {
2827 if (a !== b) {
2828 if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
2829 q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
2830 } else if (b) {
2831 s.push(pop(s) + "rotate(" + b + degParen);
2832 }
2833 }
2834
2835 function skewX(a, b, s, q) {
2836 if (a !== b) {
2837 q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
2838 } else if (b) {
2839 s.push(pop(s) + "skewX(" + b + degParen);
2840 }
2841 }
2842
2843 function scale(xa, ya, xb, yb, s, q) {
2844 if (xa !== xb || ya !== yb) {
2845 var i = s.push(pop(s) + "scale(", null, ",", null, ")");
2846 q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2847 } else if (xb !== 1 || yb !== 1) {
2848 s.push(pop(s) + "scale(" + xb + "," + yb + ")");
2849 }
2850 }
2851
2852 return function(a, b) {
2853 var s = [], // string constants and placeholders
2854 q = []; // number interpolators
2855 a = parse(a), b = parse(b);
2856 translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
2857 rotate(a.rotate, b.rotate, s, q);
2858 skewX(a.skewX, b.skewX, s, q);
2859 scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
2860 a = b = null; // gc
2861 return function(t) {
2862 var i = -1, n = q.length, o;
2863 while (++i < n) s[(o = q[i]).i] = o.x(t);
2864 return s.join("");
2865 };
2866 };
2867 }
2868
2869 var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
2870 var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
2871
2872 var rho = Math.SQRT2;
2873 var rho2 = 2;
2874 var rho4 = 4;
2875 var epsilon2 = 1e-12;
2876
2877 function cosh(x) {
2878 return ((x = Math.exp(x)) + 1 / x) / 2;
2879 }
2880
2881 function sinh(x) {
2882 return ((x = Math.exp(x)) - 1 / x) / 2;
2883 }
2884
2885 function tanh(x) {
2886 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
2887 }
2888
2889 // p0 = [ux0, uy0, w0]
2890 // p1 = [ux1, uy1, w1]
2891 function interpolateZoom(p0, p1) {
2892 var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
2893 ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
2894 dx = ux1 - ux0,
2895 dy = uy1 - uy0,
2896 d2 = dx * dx + dy * dy,
2897 i,
2898 S;
2899
2900 // Special case for u0 ≅ u1.
2901 if (d2 < epsilon2) {
2902 S = Math.log(w1 / w0) / rho;
2903 i = function(t) {
2904 return [
2905 ux0 + t * dx,
2906 uy0 + t * dy,
2907 w0 * Math.exp(rho * t * S)
2908 ];
2909 };
2910 }
2911
2912 // General case.
2913 else {
2914 var d1 = Math.sqrt(d2),
2915 b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
2916 b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
2917 r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
2918 r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
2919 S = (r1 - r0) / rho;
2920 i = function(t) {
2921 var s = t * S,
2922 coshr0 = cosh(r0),
2923 u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
2924 return [
2925 ux0 + u * dx,
2926 uy0 + u * dy,
2927 w0 * coshr0 / cosh(rho * s + r0)
2928 ];
2929 };
2930 }
2931
2932 i.duration = S * 1000;
2933
2934 return i;
2935 }
2936
2937 function hsl$1(hue$$1) {
2938 return function(start, end) {
2939 var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
2940 s = nogamma(start.s, end.s),
2941 l = nogamma(start.l, end.l),
2942 opacity = nogamma(start.opacity, end.opacity);
2943 return function(t) {
2944 start.h = h(t);
2945 start.s = s(t);
2946 start.l = l(t);
2947 start.opacity = opacity(t);
2948 return start + "";
2949 };
2950 }
2951 }
2952
2953 var hsl$2 = hsl$1(hue);
2954 var hslLong = hsl$1(nogamma);
2955
2956 function lab$1(start, end) {
2957 var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
2958 a = nogamma(start.a, end.a),
2959 b = nogamma(start.b, end.b),
2960 opacity = nogamma(start.opacity, end.opacity);
2961 return function(t) {
2962 start.l = l(t);
2963 start.a = a(t);
2964 start.b = b(t);
2965 start.opacity = opacity(t);
2966 return start + "";
2967 };
2968 }
2969
2970 function hcl$1(hue$$1) {
2971 return function(start, end) {
2972 var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
2973 c = nogamma(start.c, end.c),
2974 l = nogamma(start.l, end.l),
2975 opacity = nogamma(start.opacity, end.opacity);
2976 return function(t) {
2977 start.h = h(t);
2978 start.c = c(t);
2979 start.l = l(t);
2980 start.opacity = opacity(t);
2981 return start + "";
2982 };
2983 }
2984 }
2985
2986 var hcl$2 = hcl$1(hue);
2987 var hclLong = hcl$1(nogamma);
2988
2989 function cubehelix$1(hue$$1) {
2990 return (function cubehelixGamma(y) {
2991 y = +y;
2992
2993 function cubehelix$$1(start, end) {
2994 var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
2995 s = nogamma(start.s, end.s),
2996 l = nogamma(start.l, end.l),
2997 opacity = nogamma(start.opacity, end.opacity);
2998 return function(t) {
2999 start.h = h(t);
3000 start.s = s(t);
3001 start.l = l(Math.pow(t, y));
3002 start.opacity = opacity(t);
3003 return start + "";
3004 };
3005 }
3006
3007 cubehelix$$1.gamma = cubehelixGamma;
3008
3009 return cubehelix$$1;
3010 })(1);
3011 }
3012
3013 var cubehelix$2 = cubehelix$1(hue);
3014 var cubehelixLong = cubehelix$1(nogamma);
3015
3016 function quantize(interpolator, n) {
3017 var samples = new Array(n);
3018 for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
3019 return samples;
3020 }
3021
3022 var frame = 0;
3023 var timeout = 0;
3024 var interval = 0;
3025 var pokeDelay = 1000;
3026 var taskHead;
3027 var taskTail;
3028 var clockLast = 0;
3029 var clockNow = 0;
3030 var clockSkew = 0;
3031 var clock = typeof performance === "object" && performance.now ? performance : Date;
3032 var setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
3033
3034 function now() {
3035 return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
3036 }
3037
3038 function clearNow() {
3039 clockNow = 0;
3040 }
3041
3042 function Timer() {
3043 this._call =
3044 this._time =
3045 this._next = null;
3046 }
3047
3048 Timer.prototype = timer.prototype = {
3049 constructor: Timer,
3050 restart: function(callback, delay, time) {
3051 if (typeof callback !== "function") throw new TypeError("callback is not a function");
3052 time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
3053 if (!this._next && taskTail !== this) {
3054 if (taskTail) taskTail._next = this;
3055 else taskHead = this;
3056 taskTail = this;
3057 }
3058 this._call = callback;
3059 this._time = time;
3060 sleep();
3061 },
3062 stop: function() {
3063 if (this._call) {
3064 this._call = null;
3065 this._time = Infinity;
3066 sleep();
3067 }
3068 }
3069 };
3070
3071 function timer(callback, delay, time) {
3072 var t = new Timer;
3073 t.restart(callback, delay, time);
3074 return t;
3075 }
3076
3077 function timerFlush() {
3078 now(); // Get the current time, if not already set.
3079 ++frame; // Pretend we’ve set an alarm, if we haven’t already.
3080 var t = taskHead, e;
3081 while (t) {
3082 if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
3083 t = t._next;
3084 }
3085 --frame;
3086 }
3087
3088 function wake() {
3089 clockNow = (clockLast = clock.now()) + clockSkew;
3090 frame = timeout = 0;
3091 try {
3092 timerFlush();
3093 } finally {
3094 frame = 0;
3095 nap();
3096 clockNow = 0;
3097 }
3098 }
3099
3100 function poke() {
3101 var now = clock.now(), delay = now - clockLast;
3102 if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
3103 }
3104
3105 function nap() {
3106 var t0, t1 = taskHead, t2, time = Infinity;
3107 while (t1) {
3108 if (t1._call) {
3109 if (time > t1._time) time = t1._time;
3110 t0 = t1, t1 = t1._next;
3111 } else {
3112 t2 = t1._next, t1._next = null;
3113 t1 = t0 ? t0._next = t2 : taskHead = t2;
3114 }
3115 }
3116 taskTail = t0;
3117 sleep(time);
3118 }
3119
3120 function sleep(time) {
3121 if (frame) return; // Soonest alarm already set, or will be.
3122 if (timeout) timeout = clearTimeout(timeout);
3123 var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
3124 if (delay > 24) {
3125 if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
3126 if (interval) interval = clearInterval(interval);
3127 } else {
3128 if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
3129 frame = 1, setFrame(wake);
3130 }
3131 }
3132
3133 function timeout$1(callback, delay, time) {
3134 var t = new Timer;
3135 delay = delay == null ? 0 : +delay;
3136 t.restart(function(elapsed) {
3137 t.stop();
3138 callback(elapsed + delay);
3139 }, delay, time);
3140 return t;
3141 }
3142
3143 function interval$1(callback, delay, time) {
3144 var t = new Timer, total = delay;
3145 if (delay == null) return t.restart(callback, delay, time), t;
3146 delay = +delay, time = time == null ? now() : +time;
3147 t.restart(function tick(elapsed) {
3148 elapsed += total;
3149 t.restart(tick, total += delay, time);
3150 callback(elapsed);
3151 }, delay, time);
3152 return t;
3153 }
3154
3155 var emptyOn = dispatch("start", "end", "interrupt");
3156 var emptyTween = [];
3157
3158 var CREATED = 0;
3159 var SCHEDULED = 1;
3160 var STARTING = 2;
3161 var STARTED = 3;
3162 var RUNNING = 4;
3163 var ENDING = 5;
3164 var ENDED = 6;
3165
3166 function schedule(node, name, id, index, group, timing) {
3167 var schedules = node.__transition;
3168 if (!schedules) node.__transition = {};
3169 else if (id in schedules) return;
3170 create$1(node, id, {
3171 name: name,
3172 index: index, // For context during callback.
3173 group: group, // For context during callback.
3174 on: emptyOn,
3175 tween: emptyTween,
3176 time: timing.time,
3177 delay: timing.delay,
3178 duration: timing.duration,
3179 ease: timing.ease,
3180 timer: null,
3181 state: CREATED
3182 });
3183 }
3184
3185 function init(node, id) {
3186 var schedule = get$1(node, id);
3187 if (schedule.state > CREATED) throw new Error("too late; already scheduled");
3188 return schedule;
3189 }
3190
3191 function set$1(node, id) {
3192 var schedule = get$1(node, id);
3193 if (schedule.state > STARTING) throw new Error("too late; already started");
3194 return schedule;
3195 }
3196
3197 function get$1(node, id) {
3198 var schedule = node.__transition;
3199 if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
3200 return schedule;
3201 }
3202
3203 function create$1(node, id, self) {
3204 var schedules = node.__transition,
3205 tween;
3206
3207 // Initialize the self timer when the transition is created.
3208 // Note the actual delay is not known until the first callback!
3209 schedules[id] = self;
3210 self.timer = timer(schedule, 0, self.time);
3211
3212 function schedule(elapsed) {
3213 self.state = SCHEDULED;
3214 self.timer.restart(start, self.delay, self.time);
3215
3216 // If the elapsed delay is less than our first sleep, start immediately.
3217 if (self.delay <= elapsed) start(elapsed - self.delay);
3218 }
3219
3220 function start(elapsed) {
3221 var i, j, n, o;
3222
3223 // If the state is not SCHEDULED, then we previously errored on start.
3224 if (self.state !== SCHEDULED) return stop();
3225
3226 for (i in schedules) {
3227 o = schedules[i];
3228 if (o.name !== self.name) continue;
3229
3230 // While this element already has a starting transition during this frame,
3231 // defer starting an interrupting transition until that transition has a
3232 // chance to tick (and possibly end); see d3/d3-transition#54!
3233 if (o.state === STARTED) return timeout$1(start);
3234
3235 // Interrupt the active transition, if any.
3236 // Dispatch the interrupt event.
3237 if (o.state === RUNNING) {
3238 o.state = ENDED;
3239 o.timer.stop();
3240 o.on.call("interrupt", node, node.__data__, o.index, o.group);
3241 delete schedules[i];
3242 }
3243
3244 // Cancel any pre-empted transitions. No interrupt event is dispatched
3245 // because the cancelled transitions never started. Note that this also
3246 // removes this transition from the pending list!
3247 else if (+i < id) {
3248 o.state = ENDED;
3249 o.timer.stop();
3250 delete schedules[i];
3251 }
3252 }
3253
3254 // Defer the first tick to end of the current frame; see d3/d3#1576.
3255 // Note the transition may be canceled after start and before the first tick!
3256 // Note this must be scheduled before the start event; see d3/d3-transition#16!
3257 // Assuming this is successful, subsequent callbacks go straight to tick.
3258 timeout$1(function() {
3259 if (self.state === STARTED) {
3260 self.state = RUNNING;
3261 self.timer.restart(tick, self.delay, self.time);
3262 tick(elapsed);
3263 }
3264 });
3265
3266 // Dispatch the start event.
3267 // Note this must be done before the tween are initialized.
3268 self.state = STARTING;
3269 self.on.call("start", node, node.__data__, self.index, self.group);
3270 if (self.state !== STARTING) return; // interrupted
3271 self.state = STARTED;
3272
3273 // Initialize the tween, deleting null tween.
3274 tween = new Array(n = self.tween.length);
3275 for (i = 0, j = -1; i < n; ++i) {
3276 if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
3277 tween[++j] = o;
3278 }
3279 }
3280 tween.length = j + 1;
3281 }
3282
3283 function tick(elapsed) {
3284 var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
3285 i = -1,
3286 n = tween.length;
3287
3288 while (++i < n) {
3289 tween[i].call(null, t);
3290 }
3291
3292 // Dispatch the end event.
3293 if (self.state === ENDING) {
3294 self.on.call("end", node, node.__data__, self.index, self.group);
3295 stop();
3296 }
3297 }
3298
3299 function stop() {
3300 self.state = ENDED;
3301 self.timer.stop();
3302 delete schedules[id];
3303 for (var i in schedules) return; // eslint-disable-line no-unused-vars
3304 delete node.__transition;
3305 }
3306 }
3307
3308 function interrupt(node, name) {
3309 var schedules = node.__transition,
3310 schedule$$1,
3311 active,
3312 empty = true,
3313 i;
3314
3315 if (!schedules) return;
3316
3317 name = name == null ? null : name + "";
3318
3319 for (i in schedules) {
3320 if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
3321 active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
3322 schedule$$1.state = ENDED;
3323 schedule$$1.timer.stop();
3324 if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
3325 delete schedules[i];
3326 }
3327
3328 if (empty) delete node.__transition;
3329 }
3330
3331 function selection_interrupt(name) {
3332 return this.each(function() {
3333 interrupt(this, name);
3334 });
3335 }
3336
3337 function tweenRemove(id, name) {
3338 var tween0, tween1;
3339 return function() {
3340 var schedule$$1 = set$1(this, id),
3341 tween = schedule$$1.tween;
3342
3343 // If this node shared tween with the previous node,
3344 // just assign the updated shared tween and we’re done!
3345 // Otherwise, copy-on-write.
3346 if (tween !== tween0) {
3347 tween1 = tween0 = tween;
3348 for (var i = 0, n = tween1.length; i < n; ++i) {
3349 if (tween1[i].name === name) {
3350 tween1 = tween1.slice();
3351 tween1.splice(i, 1);
3352 break;
3353 }
3354 }
3355 }
3356
3357 schedule$$1.tween = tween1;
3358 };
3359 }
3360
3361 function tweenFunction(id, name, value) {
3362 var tween0, tween1;
3363 if (typeof value !== "function") throw new Error;
3364 return function() {
3365 var schedule$$1 = set$1(this, id),
3366 tween = schedule$$1.tween;
3367
3368 // If this node shared tween with the previous node,
3369 // just assign the updated shared tween and we’re done!
3370 // Otherwise, copy-on-write.
3371 if (tween !== tween0) {
3372 tween1 = (tween0 = tween).slice();
3373 for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
3374 if (tween1[i].name === name) {
3375 tween1[i] = t;
3376 break;
3377 }
3378 }
3379 if (i === n) tween1.push(t);
3380 }
3381
3382 schedule$$1.tween = tween1;
3383 };
3384 }
3385
3386 function transition_tween(name, value) {
3387 var id = this._id;
3388
3389 name += "";
3390
3391 if (arguments.length < 2) {
3392 var tween = get$1(this.node(), id).tween;
3393 for (var i = 0, n = tween.length, t; i < n; ++i) {
3394 if ((t = tween[i]).name === name) {
3395 return t.value;
3396 }
3397 }
3398 return null;
3399 }
3400
3401 return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
3402 }
3403
3404 function tweenValue(transition, name, value) {
3405 var id = transition._id;
3406
3407 transition.each(function() {
3408 var schedule$$1 = set$1(this, id);
3409 (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
3410 });
3411
3412 return function(node) {
3413 return get$1(node, id).value[name];
3414 };
3415 }
3416
3417 function interpolate(a, b) {
3418 var c;
3419 return (typeof b === "number" ? reinterpolate
3420 : b instanceof color ? interpolateRgb
3421 : (c = color(b)) ? (b = c, interpolateRgb)
3422 : interpolateString)(a, b);
3423 }
3424
3425 function attrRemove$1(name) {
3426 return function() {
3427 this.removeAttribute(name);
3428 };
3429 }
3430
3431 function attrRemoveNS$1(fullname) {
3432 return function() {
3433 this.removeAttributeNS(fullname.space, fullname.local);
3434 };
3435 }
3436
3437 function attrConstant$1(name, interpolate$$1, value1) {
3438 var value00,
3439 interpolate0;
3440 return function() {
3441 var value0 = this.getAttribute(name);
3442 return value0 === value1 ? null
3443 : value0 === value00 ? interpolate0
3444 : interpolate0 = interpolate$$1(value00 = value0, value1);
3445 };
3446 }
3447
3448 function attrConstantNS$1(fullname, interpolate$$1, value1) {
3449 var value00,
3450 interpolate0;
3451 return function() {
3452 var value0 = this.getAttributeNS(fullname.space, fullname.local);
3453 return value0 === value1 ? null
3454 : value0 === value00 ? interpolate0
3455 : interpolate0 = interpolate$$1(value00 = value0, value1);
3456 };
3457 }
3458
3459 function attrFunction$1(name, interpolate$$1, value) {
3460 var value00,
3461 value10,
3462 interpolate0;
3463 return function() {
3464 var value0, value1 = value(this);
3465 if (value1 == null) return void this.removeAttribute(name);
3466 value0 = this.getAttribute(name);
3467 return value0 === value1 ? null
3468 : value0 === value00 && value1 === value10 ? interpolate0
3469 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3470 };
3471 }
3472
3473 function attrFunctionNS$1(fullname, interpolate$$1, value) {
3474 var value00,
3475 value10,
3476 interpolate0;
3477 return function() {
3478 var value0, value1 = value(this);
3479 if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
3480 value0 = this.getAttributeNS(fullname.space, fullname.local);
3481 return value0 === value1 ? null
3482 : value0 === value00 && value1 === value10 ? interpolate0
3483 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3484 };
3485 }
3486
3487 function transition_attr(name, value) {
3488 var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
3489 return this.attrTween(name, typeof value === "function"
3490 ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
3491 : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
3492 : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
3493 }
3494
3495 function attrTweenNS(fullname, value) {
3496 function tween() {
3497 var node = this, i = value.apply(node, arguments);
3498 return i && function(t) {
3499 node.setAttributeNS(fullname.space, fullname.local, i(t));
3500 };
3501 }
3502 tween._value = value;
3503 return tween;
3504 }
3505
3506 function attrTween(name, value) {
3507 function tween() {
3508 var node = this, i = value.apply(node, arguments);
3509 return i && function(t) {
3510 node.setAttribute(name, i(t));
3511 };
3512 }
3513 tween._value = value;
3514 return tween;
3515 }
3516
3517 function transition_attrTween(name, value) {
3518 var key = "attr." + name;
3519 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3520 if (value == null) return this.tween(key, null);
3521 if (typeof value !== "function") throw new Error;
3522 var fullname = namespace(name);
3523 return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
3524 }
3525
3526 function delayFunction(id, value) {
3527 return function() {
3528 init(this, id).delay = +value.apply(this, arguments);
3529 };
3530 }
3531
3532 function delayConstant(id, value) {
3533 return value = +value, function() {
3534 init(this, id).delay = value;
3535 };
3536 }
3537
3538 function transition_delay(value) {
3539 var id = this._id;
3540
3541 return arguments.length
3542 ? this.each((typeof value === "function"
3543 ? delayFunction
3544 : delayConstant)(id, value))
3545 : get$1(this.node(), id).delay;
3546 }
3547
3548 function durationFunction(id, value) {
3549 return function() {
3550 set$1(this, id).duration = +value.apply(this, arguments);
3551 };
3552 }
3553
3554 function durationConstant(id, value) {
3555 return value = +value, function() {
3556 set$1(this, id).duration = value;
3557 };
3558 }
3559
3560 function transition_duration(value) {
3561 var id = this._id;
3562
3563 return arguments.length
3564 ? this.each((typeof value === "function"
3565 ? durationFunction
3566 : durationConstant)(id, value))
3567 : get$1(this.node(), id).duration;
3568 }
3569
3570 function easeConstant(id, value) {
3571 if (typeof value !== "function") throw new Error;
3572 return function() {
3573 set$1(this, id).ease = value;
3574 };
3575 }
3576
3577 function transition_ease(value) {
3578 var id = this._id;
3579
3580 return arguments.length
3581 ? this.each(easeConstant(id, value))
3582 : get$1(this.node(), id).ease;
3583 }
3584
3585 function transition_filter(match) {
3586 if (typeof match !== "function") match = matcher$1(match);
3587
3588 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3589 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
3590 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
3591 subgroup.push(node);
3592 }
3593 }
3594 }
3595
3596 return new Transition(subgroups, this._parents, this._name, this._id);
3597 }
3598
3599 function transition_merge(transition$$1) {
3600 if (transition$$1._id !== this._id) throw new Error;
3601
3602 for (var groups0 = this._groups, groups1 = transition$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
3603 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
3604 if (node = group0[i] || group1[i]) {
3605 merge[i] = node;
3606 }
3607 }
3608 }
3609
3610 for (; j < m0; ++j) {
3611 merges[j] = groups0[j];
3612 }
3613
3614 return new Transition(merges, this._parents, this._name, this._id);
3615 }
3616
3617 function start(name) {
3618 return (name + "").trim().split(/^|\s+/).every(function(t) {
3619 var i = t.indexOf(".");
3620 if (i >= 0) t = t.slice(0, i);
3621 return !t || t === "start";
3622 });
3623 }
3624
3625 function onFunction(id, name, listener) {
3626 var on0, on1, sit = start(name) ? init : set$1;
3627 return function() {
3628 var schedule$$1 = sit(this, id),
3629 on = schedule$$1.on;
3630
3631 // If this node shared a dispatch with the previous node,
3632 // just assign the updated shared dispatch and we’re done!
3633 // Otherwise, copy-on-write.
3634 if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
3635
3636 schedule$$1.on = on1;
3637 };
3638 }
3639
3640 function transition_on(name, listener) {
3641 var id = this._id;
3642
3643 return arguments.length < 2
3644 ? get$1(this.node(), id).on.on(name)
3645 : this.each(onFunction(id, name, listener));
3646 }
3647
3648 function removeFunction(id) {
3649 return function() {
3650 var parent = this.parentNode;
3651 for (var i in this.__transition) if (+i !== id) return;
3652 if (parent) parent.removeChild(this);
3653 };
3654 }
3655
3656 function transition_remove() {
3657 return this.on("end.remove", removeFunction(this._id));
3658 }
3659
3660 function transition_select(select) {
3661 var name = this._name,
3662 id = this._id;
3663
3664 if (typeof select !== "function") select = selector(select);
3665
3666 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3667 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
3668 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
3669 if ("__data__" in node) subnode.__data__ = node.__data__;
3670 subgroup[i] = subnode;
3671 schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
3672 }
3673 }
3674 }
3675
3676 return new Transition(subgroups, this._parents, name, id);
3677 }
3678
3679 function transition_selectAll(select) {
3680 var name = this._name,
3681 id = this._id;
3682
3683 if (typeof select !== "function") select = selectorAll(select);
3684
3685 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
3686 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3687 if (node = group[i]) {
3688 for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
3689 if (child = children[k]) {
3690 schedule(child, name, id, k, children, inherit);
3691 }
3692 }
3693 subgroups.push(children);
3694 parents.push(node);
3695 }
3696 }
3697 }
3698
3699 return new Transition(subgroups, parents, name, id);
3700 }
3701
3702 var Selection$1 = selection.prototype.constructor;
3703
3704 function transition_selection() {
3705 return new Selection$1(this._groups, this._parents);
3706 }
3707
3708 function styleRemove$1(name, interpolate$$1) {
3709 var value00,
3710 value10,
3711 interpolate0;
3712 return function() {
3713 var value0 = styleValue(this, name),
3714 value1 = (this.style.removeProperty(name), styleValue(this, name));
3715 return value0 === value1 ? null
3716 : value0 === value00 && value1 === value10 ? interpolate0
3717 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3718 };
3719 }
3720
3721 function styleRemoveEnd(name) {
3722 return function() {
3723 this.style.removeProperty(name);
3724 };
3725 }
3726
3727 function styleConstant$1(name, interpolate$$1, value1) {
3728 var value00,
3729 interpolate0;
3730 return function() {
3731 var value0 = styleValue(this, name);
3732 return value0 === value1 ? null
3733 : value0 === value00 ? interpolate0
3734 : interpolate0 = interpolate$$1(value00 = value0, value1);
3735 };
3736 }
3737
3738 function styleFunction$1(name, interpolate$$1, value) {
3739 var value00,
3740 value10,
3741 interpolate0;
3742 return function() {
3743 var value0 = styleValue(this, name),
3744 value1 = value(this);
3745 if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
3746 return value0 === value1 ? null
3747 : value0 === value00 && value1 === value10 ? interpolate0
3748 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3749 };
3750 }
3751
3752 function transition_style(name, value, priority) {
3753 var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
3754 return value == null ? this
3755 .styleTween(name, styleRemove$1(name, i))
3756 .on("end.style." + name, styleRemoveEnd(name))
3757 : this.styleTween(name, typeof value === "function"
3758 ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
3759 : styleConstant$1(name, i, value + ""), priority);
3760 }
3761
3762 function styleTween(name, value, priority) {
3763 function tween() {
3764 var node = this, i = value.apply(node, arguments);
3765 return i && function(t) {
3766 node.style.setProperty(name, i(t), priority);
3767 };
3768 }
3769 tween._value = value;
3770 return tween;
3771 }
3772
3773 function transition_styleTween(name, value, priority) {
3774 var key = "style." + (name += "");
3775 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3776 if (value == null) return this.tween(key, null);
3777 if (typeof value !== "function") throw new Error;
3778 return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
3779 }
3780
3781 function textConstant$1(value) {
3782 return function() {
3783 this.textContent = value;
3784 };
3785 }
3786
3787 function textFunction$1(value) {
3788 return function() {
3789 var value1 = value(this);
3790 this.textContent = value1 == null ? "" : value1;
3791 };
3792 }
3793
3794 function transition_text(value) {
3795 return this.tween("text", typeof value === "function"
3796 ? textFunction$1(tweenValue(this, "text", value))
3797 : textConstant$1(value == null ? "" : value + ""));
3798 }
3799
3800 function transition_transition() {
3801 var name = this._name,
3802 id0 = this._id,
3803 id1 = newId();
3804
3805 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
3806 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3807 if (node = group[i]) {
3808 var inherit = get$1(node, id0);
3809 schedule(node, name, id1, i, group, {
3810 time: inherit.time + inherit.delay + inherit.duration,
3811 delay: 0,
3812 duration: inherit.duration,
3813 ease: inherit.ease
3814 });
3815 }
3816 }
3817 }
3818
3819 return new Transition(groups, this._parents, name, id1);
3820 }
3821
3822 var id = 0;
3823
3824 function Transition(groups, parents, name, id) {
3825 this._groups = groups;
3826 this._parents = parents;
3827 this._name = name;
3828 this._id = id;
3829 }
3830
3831 function transition(name) {
3832 return selection().transition(name);
3833 }
3834
3835 function newId() {
3836 return ++id;
3837 }
3838
3839 var selection_prototype = selection.prototype;
3840
3841 Transition.prototype = transition.prototype = {
3842 constructor: Transition,
3843 select: transition_select,
3844 selectAll: transition_selectAll,
3845 filter: transition_filter,
3846 merge: transition_merge,
3847 selection: transition_selection,
3848 transition: transition_transition,
3849 call: selection_prototype.call,
3850 nodes: selection_prototype.nodes,
3851 node: selection_prototype.node,
3852 size: selection_prototype.size,
3853 empty: selection_prototype.empty,
3854 each: selection_prototype.each,
3855 on: transition_on,
3856 attr: transition_attr,
3857 attrTween: transition_attrTween,
3858 style: transition_style,
3859 styleTween: transition_styleTween,
3860 text: transition_text,
3861 remove: transition_remove,
3862 tween: transition_tween,
3863 delay: transition_delay,
3864 duration: transition_duration,
3865 ease: transition_ease
3866 };
3867
3868 function linear$1(t) {
3869 return +t;
3870 }
3871
3872 function quadIn(t) {
3873 return t * t;
3874 }
3875
3876 function quadOut(t) {
3877 return t * (2 - t);
3878 }
3879
3880 function quadInOut(t) {
3881 return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
3882 }
3883
3884 function cubicIn(t) {
3885 return t * t * t;
3886 }
3887
3888 function cubicOut(t) {
3889 return --t * t * t + 1;
3890 }
3891
3892 function cubicInOut(t) {
3893 return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
3894 }
3895
3896 var exponent = 3;
3897
3898 var polyIn = (function custom(e) {
3899 e = +e;
3900
3901 function polyIn(t) {
3902 return Math.pow(t, e);
3903 }
3904
3905 polyIn.exponent = custom;
3906
3907 return polyIn;
3908 })(exponent);
3909
3910 var polyOut = (function custom(e) {
3911 e = +e;
3912
3913 function polyOut(t) {
3914 return 1 - Math.pow(1 - t, e);
3915 }
3916
3917 polyOut.exponent = custom;
3918
3919 return polyOut;
3920 })(exponent);
3921
3922 var polyInOut = (function custom(e) {
3923 e = +e;
3924
3925 function polyInOut(t) {
3926 return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
3927 }
3928
3929 polyInOut.exponent = custom;
3930
3931 return polyInOut;
3932 })(exponent);
3933
3934 var pi = Math.PI;
3935 var halfPi = pi / 2;
3936
3937 function sinIn(t) {
3938 return 1 - Math.cos(t * halfPi);
3939 }
3940
3941 function sinOut(t) {
3942 return Math.sin(t * halfPi);
3943 }
3944
3945 function sinInOut(t) {
3946 return (1 - Math.cos(pi * t)) / 2;
3947 }
3948
3949 function expIn(t) {
3950 return Math.pow(2, 10 * t - 10);
3951 }
3952
3953 function expOut(t) {
3954 return 1 - Math.pow(2, -10 * t);
3955 }
3956
3957 function expInOut(t) {
3958 return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
3959 }
3960
3961 function circleIn(t) {
3962 return 1 - Math.sqrt(1 - t * t);
3963 }
3964
3965 function circleOut(t) {
3966 return Math.sqrt(1 - --t * t);
3967 }
3968
3969 function circleInOut(t) {
3970 return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
3971 }
3972
3973 var b1 = 4 / 11;
3974 var b2 = 6 / 11;
3975 var b3 = 8 / 11;
3976 var b4 = 3 / 4;
3977 var b5 = 9 / 11;
3978 var b6 = 10 / 11;
3979 var b7 = 15 / 16;
3980 var b8 = 21 / 22;
3981 var b9 = 63 / 64;
3982 var b0 = 1 / b1 / b1;
3983
3984 function bounceIn(t) {
3985 return 1 - bounceOut(1 - t);
3986 }
3987
3988 function bounceOut(t) {
3989 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;
3990 }
3991
3992 function bounceInOut(t) {
3993 return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
3994 }
3995
3996 var overshoot = 1.70158;
3997
3998 var backIn = (function custom(s) {
3999 s = +s;
4000
4001 function backIn(t) {
4002 return t * t * ((s + 1) * t - s);
4003 }
4004
4005 backIn.overshoot = custom;
4006
4007 return backIn;
4008 })(overshoot);
4009
4010 var backOut = (function custom(s) {
4011 s = +s;
4012
4013 function backOut(t) {
4014 return --t * t * ((s + 1) * t + s) + 1;
4015 }
4016
4017 backOut.overshoot = custom;
4018
4019 return backOut;
4020 })(overshoot);
4021
4022 var backInOut = (function custom(s) {
4023 s = +s;
4024
4025 function backInOut(t) {
4026 return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
4027 }
4028
4029 backInOut.overshoot = custom;
4030
4031 return backInOut;
4032 })(overshoot);
4033
4034 var tau = 2 * Math.PI;
4035 var amplitude = 1;
4036 var period = 0.3;
4037
4038 var elasticIn = (function custom(a, p) {
4039 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4040
4041 function elasticIn(t) {
4042 return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
4043 }
4044
4045 elasticIn.amplitude = function(a) { return custom(a, p * tau); };
4046 elasticIn.period = function(p) { return custom(a, p); };
4047
4048 return elasticIn;
4049 })(amplitude, period);
4050
4051 var elasticOut = (function custom(a, p) {
4052 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4053
4054 function elasticOut(t) {
4055 return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
4056 }
4057
4058 elasticOut.amplitude = function(a) { return custom(a, p * tau); };
4059 elasticOut.period = function(p) { return custom(a, p); };
4060
4061 return elasticOut;
4062 })(amplitude, period);
4063
4064 var elasticInOut = (function custom(a, p) {
4065 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4066
4067 function elasticInOut(t) {
4068 return ((t = t * 2 - 1) < 0
4069 ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
4070 : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
4071 }
4072
4073 elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
4074 elasticInOut.period = function(p) { return custom(a, p); };
4075
4076 return elasticInOut;
4077 })(amplitude, period);
4078
4079 var defaultTiming = {
4080 time: null, // Set on use.
4081 delay: 0,
4082 duration: 250,
4083 ease: cubicInOut
4084 };
4085
4086 function inherit(node, id) {
4087 var timing;
4088 while (!(timing = node.__transition) || !(timing = timing[id])) {
4089 if (!(node = node.parentNode)) {
4090 return defaultTiming.time = now(), defaultTiming;
4091 }
4092 }
4093 return timing;
4094 }
4095
4096 function selection_transition(name) {
4097 var id,
4098 timing;
4099
4100 if (name instanceof Transition) {
4101 id = name._id, name = name._name;
4102 } else {
4103 id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
4104 }
4105
4106 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4107 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4108 if (node = group[i]) {
4109 schedule(node, name, id, i, group, timing || inherit(node, id));
4110 }
4111 }
4112 }
4113
4114 return new Transition(groups, this._parents, name, id);
4115 }
4116
4117 selection.prototype.interrupt = selection_interrupt;
4118 selection.prototype.transition = selection_transition;
4119
4120 var root$1 = [null];
4121
4122 function active(node, name) {
4123 var schedules = node.__transition,
4124 schedule$$1,
4125 i;
4126
4127 if (schedules) {
4128 name = name == null ? null : name + "";
4129 for (i in schedules) {
4130 if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
4131 return new Transition([[node]], root$1, name, +i);
4132 }
4133 }
4134 }
4135
4136 return null;
4137 }
4138
4139 function constant$4(x) {
4140 return function() {
4141 return x;
4142 };
4143 }
4144
4145 function BrushEvent(target, type, selection) {
4146 this.target = target;
4147 this.type = type;
4148 this.selection = selection;
4149 }
4150
4151 function nopropagation$1() {
4152 exports.event.stopImmediatePropagation();
4153 }
4154
4155 function noevent$1() {
4156 exports.event.preventDefault();
4157 exports.event.stopImmediatePropagation();
4158 }
4159
4160 var MODE_DRAG = {name: "drag"};
4161 var MODE_SPACE = {name: "space"};
4162 var MODE_HANDLE = {name: "handle"};
4163 var MODE_CENTER = {name: "center"};
4164
4165 var X = {
4166 name: "x",
4167 handles: ["e", "w"].map(type),
4168 input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
4169 output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
4170 };
4171
4172 var Y = {
4173 name: "y",
4174 handles: ["n", "s"].map(type),
4175 input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
4176 output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
4177 };
4178
4179 var XY = {
4180 name: "xy",
4181 handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
4182 input: function(xy) { return xy; },
4183 output: function(xy) { return xy; }
4184 };
4185
4186 var cursors = {
4187 overlay: "crosshair",
4188 selection: "move",
4189 n: "ns-resize",
4190 e: "ew-resize",
4191 s: "ns-resize",
4192 w: "ew-resize",
4193 nw: "nwse-resize",
4194 ne: "nesw-resize",
4195 se: "nwse-resize",
4196 sw: "nesw-resize"
4197 };
4198
4199 var flipX = {
4200 e: "w",
4201 w: "e",
4202 nw: "ne",
4203 ne: "nw",
4204 se: "sw",
4205 sw: "se"
4206 };
4207
4208 var flipY = {
4209 n: "s",
4210 s: "n",
4211 nw: "sw",
4212 ne: "se",
4213 se: "ne",
4214 sw: "nw"
4215 };
4216
4217 var signsX = {
4218 overlay: +1,
4219 selection: +1,
4220 n: null,
4221 e: +1,
4222 s: null,
4223 w: -1,
4224 nw: -1,
4225 ne: +1,
4226 se: +1,
4227 sw: -1
4228 };
4229
4230 var signsY = {
4231 overlay: +1,
4232 selection: +1,
4233 n: -1,
4234 e: null,
4235 s: +1,
4236 w: null,
4237 nw: -1,
4238 ne: -1,
4239 se: +1,
4240 sw: +1
4241 };
4242
4243 function type(t) {
4244 return {type: t};
4245 }
4246
4247 // Ignore right-click, since that should open the context menu.
4248 function defaultFilter() {
4249 return !exports.event.button;
4250 }
4251
4252 function defaultExtent() {
4253 var svg = this.ownerSVGElement || this;
4254 return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
4255 }
4256
4257 // Like d3.local, but with the name “__brush” rather than auto-generated.
4258 function local(node) {
4259 while (!node.__brush) if (!(node = node.parentNode)) return;
4260 return node.__brush;
4261 }
4262
4263 function empty(extent) {
4264 return extent[0][0] === extent[1][0]
4265 || extent[0][1] === extent[1][1];
4266 }
4267
4268 function brushSelection(node) {
4269 var state = node.__brush;
4270 return state ? state.dim.output(state.selection) : null;
4271 }
4272
4273 function brushX() {
4274 return brush$1(X);
4275 }
4276
4277 function brushY() {
4278 return brush$1(Y);
4279 }
4280
4281 function brush() {
4282 return brush$1(XY);
4283 }
4284
4285 function brush$1(dim) {
4286 var extent = defaultExtent,
4287 filter = defaultFilter,
4288 listeners = dispatch(brush, "start", "brush", "end"),
4289 handleSize = 6,
4290 touchending;
4291
4292 function brush(group) {
4293 var overlay = group
4294 .property("__brush", initialize)
4295 .selectAll(".overlay")
4296 .data([type("overlay")]);
4297
4298 overlay.enter().append("rect")
4299 .attr("class", "overlay")
4300 .attr("pointer-events", "all")
4301 .attr("cursor", cursors.overlay)
4302 .merge(overlay)
4303 .each(function() {
4304 var extent = local(this).extent;
4305 select(this)
4306 .attr("x", extent[0][0])
4307 .attr("y", extent[0][1])
4308 .attr("width", extent[1][0] - extent[0][0])
4309 .attr("height", extent[1][1] - extent[0][1]);
4310 });
4311
4312 group.selectAll(".selection")
4313 .data([type("selection")])
4314 .enter().append("rect")
4315 .attr("class", "selection")
4316 .attr("cursor", cursors.selection)
4317 .attr("fill", "#777")
4318 .attr("fill-opacity", 0.3)
4319 .attr("stroke", "#fff")
4320 .attr("shape-rendering", "crispEdges");
4321
4322 var handle = group.selectAll(".handle")
4323 .data(dim.handles, function(d) { return d.type; });
4324
4325 handle.exit().remove();
4326
4327 handle.enter().append("rect")
4328 .attr("class", function(d) { return "handle handle--" + d.type; })
4329 .attr("cursor", function(d) { return cursors[d.type]; });
4330
4331 group
4332 .each(redraw)
4333 .attr("fill", "none")
4334 .attr("pointer-events", "all")
4335 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
4336 .on("mousedown.brush touchstart.brush", started);
4337 }
4338
4339 brush.move = function(group, selection) {
4340 if (group.selection) {
4341 group
4342 .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
4343 .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
4344 .tween("brush", function() {
4345 var that = this,
4346 state = that.__brush,
4347 emit = emitter(that, arguments),
4348 selection0 = state.selection,
4349 selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
4350 i = interpolateValue(selection0, selection1);
4351
4352 function tween(t) {
4353 state.selection = t === 1 && empty(selection1) ? null : i(t);
4354 redraw.call(that);
4355 emit.brush();
4356 }
4357
4358 return selection0 && selection1 ? tween : tween(1);
4359 });
4360 } else {
4361 group
4362 .each(function() {
4363 var that = this,
4364 args = arguments,
4365 state = that.__brush,
4366 selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
4367 emit = emitter(that, args).beforestart();
4368
4369 interrupt(that);
4370 state.selection = selection1 == null || empty(selection1) ? null : selection1;
4371 redraw.call(that);
4372 emit.start().brush().end();
4373 });
4374 }
4375 };
4376
4377 function redraw() {
4378 var group = select(this),
4379 selection = local(this).selection;
4380
4381 if (selection) {
4382 group.selectAll(".selection")
4383 .style("display", null)
4384 .attr("x", selection[0][0])
4385 .attr("y", selection[0][1])
4386 .attr("width", selection[1][0] - selection[0][0])
4387 .attr("height", selection[1][1] - selection[0][1]);
4388
4389 group.selectAll(".handle")
4390 .style("display", null)
4391 .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
4392 .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
4393 .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
4394 .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
4395 }
4396
4397 else {
4398 group.selectAll(".selection,.handle")
4399 .style("display", "none")
4400 .attr("x", null)
4401 .attr("y", null)
4402 .attr("width", null)
4403 .attr("height", null);
4404 }
4405 }
4406
4407 function emitter(that, args) {
4408 return that.__brush.emitter || new Emitter(that, args);
4409 }
4410
4411 function Emitter(that, args) {
4412 this.that = that;
4413 this.args = args;
4414 this.state = that.__brush;
4415 this.active = 0;
4416 }
4417
4418 Emitter.prototype = {
4419 beforestart: function() {
4420 if (++this.active === 1) this.state.emitter = this, this.starting = true;
4421 return this;
4422 },
4423 start: function() {
4424 if (this.starting) this.starting = false, this.emit("start");
4425 return this;
4426 },
4427 brush: function() {
4428 this.emit("brush");
4429 return this;
4430 },
4431 end: function() {
4432 if (--this.active === 0) delete this.state.emitter, this.emit("end");
4433 return this;
4434 },
4435 emit: function(type) {
4436 customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
4437 }
4438 };
4439
4440 function started() {
4441 if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
4442 else if (touchending) return;
4443 if (!filter.apply(this, arguments)) return;
4444
4445 var that = this,
4446 type = exports.event.target.__data__.type,
4447 mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
4448 signX = dim === Y ? null : signsX[type],
4449 signY = dim === X ? null : signsY[type],
4450 state = local(that),
4451 extent = state.extent,
4452 selection = state.selection,
4453 W = extent[0][0], w0, w1,
4454 N = extent[0][1], n0, n1,
4455 E = extent[1][0], e0, e1,
4456 S = extent[1][1], s0, s1,
4457 dx,
4458 dy,
4459 moving,
4460 shifting = signX && signY && exports.event.shiftKey,
4461 lockX,
4462 lockY,
4463 point0 = mouse(that),
4464 point = point0,
4465 emit = emitter(that, arguments).beforestart();
4466
4467 if (type === "overlay") {
4468 state.selection = selection = [
4469 [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
4470 [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
4471 ];
4472 } else {
4473 w0 = selection[0][0];
4474 n0 = selection[0][1];
4475 e0 = selection[1][0];
4476 s0 = selection[1][1];
4477 }
4478
4479 w1 = w0;
4480 n1 = n0;
4481 e1 = e0;
4482 s1 = s0;
4483
4484 var group = select(that)
4485 .attr("pointer-events", "none");
4486
4487 var overlay = group.selectAll(".overlay")
4488 .attr("cursor", cursors[type]);
4489
4490 if (exports.event.touches) {
4491 group
4492 .on("touchmove.brush", moved, true)
4493 .on("touchend.brush touchcancel.brush", ended, true);
4494 } else {
4495 var view = select(exports.event.view)
4496 .on("keydown.brush", keydowned, true)
4497 .on("keyup.brush", keyupped, true)
4498 .on("mousemove.brush", moved, true)
4499 .on("mouseup.brush", ended, true);
4500
4501 dragDisable(exports.event.view);
4502 }
4503
4504 nopropagation$1();
4505 interrupt(that);
4506 redraw.call(that);
4507 emit.start();
4508
4509 function moved() {
4510 var point1 = mouse(that);
4511 if (shifting && !lockX && !lockY) {
4512 if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
4513 else lockX = true;
4514 }
4515 point = point1;
4516 moving = true;
4517 noevent$1();
4518 move();
4519 }
4520
4521 function move() {
4522 var t;
4523
4524 dx = point[0] - point0[0];
4525 dy = point[1] - point0[1];
4526
4527 switch (mode) {
4528 case MODE_SPACE:
4529 case MODE_DRAG: {
4530 if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
4531 if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
4532 break;
4533 }
4534 case MODE_HANDLE: {
4535 if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
4536 else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
4537 if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
4538 else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
4539 break;
4540 }
4541 case MODE_CENTER: {
4542 if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
4543 if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
4544 break;
4545 }
4546 }
4547
4548 if (e1 < w1) {
4549 signX *= -1;
4550 t = w0, w0 = e0, e0 = t;
4551 t = w1, w1 = e1, e1 = t;
4552 if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
4553 }
4554
4555 if (s1 < n1) {
4556 signY *= -1;
4557 t = n0, n0 = s0, s0 = t;
4558 t = n1, n1 = s1, s1 = t;
4559 if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
4560 }
4561
4562 if (state.selection) selection = state.selection; // May be set by brush.move!
4563 if (lockX) w1 = selection[0][0], e1 = selection[1][0];
4564 if (lockY) n1 = selection[0][1], s1 = selection[1][1];
4565
4566 if (selection[0][0] !== w1
4567 || selection[0][1] !== n1
4568 || selection[1][0] !== e1
4569 || selection[1][1] !== s1) {
4570 state.selection = [[w1, n1], [e1, s1]];
4571 redraw.call(that);
4572 emit.brush();
4573 }
4574 }
4575
4576 function ended() {
4577 nopropagation$1();
4578 if (exports.event.touches) {
4579 if (exports.event.touches.length) return;
4580 if (touchending) clearTimeout(touchending);
4581 touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
4582 group.on("touchmove.brush touchend.brush touchcancel.brush", null);
4583 } else {
4584 yesdrag(exports.event.view, moving);
4585 view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
4586 }
4587 group.attr("pointer-events", "all");
4588 overlay.attr("cursor", cursors.overlay);
4589 if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
4590 if (empty(selection)) state.selection = null, redraw.call(that);
4591 emit.end();
4592 }
4593
4594 function keydowned() {
4595 switch (exports.event.keyCode) {
4596 case 16: { // SHIFT
4597 shifting = signX && signY;
4598 break;
4599 }
4600 case 18: { // ALT
4601 if (mode === MODE_HANDLE) {
4602 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4603 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4604 mode = MODE_CENTER;
4605 move();
4606 }
4607 break;
4608 }
4609 case 32: { // SPACE; takes priority over ALT
4610 if (mode === MODE_HANDLE || mode === MODE_CENTER) {
4611 if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
4612 if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
4613 mode = MODE_SPACE;
4614 overlay.attr("cursor", cursors.selection);
4615 move();
4616 }
4617 break;
4618 }
4619 default: return;
4620 }
4621 noevent$1();
4622 }
4623
4624 function keyupped() {
4625 switch (exports.event.keyCode) {
4626 case 16: { // SHIFT
4627 if (shifting) {
4628 lockX = lockY = shifting = false;
4629 move();
4630 }
4631 break;
4632 }
4633 case 18: { // ALT
4634 if (mode === MODE_CENTER) {
4635 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4636 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4637 mode = MODE_HANDLE;
4638 move();
4639 }
4640 break;
4641 }
4642 case 32: { // SPACE
4643 if (mode === MODE_SPACE) {
4644 if (exports.event.altKey) {
4645 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4646 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4647 mode = MODE_CENTER;
4648 } else {
4649 if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4650 if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4651 mode = MODE_HANDLE;
4652 }
4653 overlay.attr("cursor", cursors[type]);
4654 move();
4655 }
4656 break;
4657 }
4658 default: return;
4659 }
4660 noevent$1();
4661 }
4662 }
4663
4664 function initialize() {
4665 var state = this.__brush || {selection: null};
4666 state.extent = extent.apply(this, arguments);
4667 state.dim = dim;
4668 return state;
4669 }
4670
4671 brush.extent = function(_) {
4672 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
4673 };
4674
4675 brush.filter = function(_) {
4676 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
4677 };
4678
4679 brush.handleSize = function(_) {
4680 return arguments.length ? (handleSize = +_, brush) : handleSize;
4681 };
4682
4683 brush.on = function() {
4684 var value = listeners.on.apply(listeners, arguments);
4685 return value === listeners ? brush : value;
4686 };
4687
4688 return brush;
4689 }
4690
4691 var cos = Math.cos;
4692 var sin = Math.sin;
4693 var pi$1 = Math.PI;
4694 var halfPi$1 = pi$1 / 2;
4695 var tau$1 = pi$1 * 2;
4696 var max$1 = Math.max;
4697
4698 function compareValue(compare) {
4699 return function(a, b) {
4700 return compare(
4701 a.source.value + a.target.value,
4702 b.source.value + b.target.value
4703 );
4704 };
4705 }
4706
4707 function chord() {
4708 var padAngle = 0,
4709 sortGroups = null,
4710 sortSubgroups = null,
4711 sortChords = null;
4712
4713 function chord(matrix) {
4714 var n = matrix.length,
4715 groupSums = [],
4716 groupIndex = sequence(n),
4717 subgroupIndex = [],
4718 chords = [],
4719 groups = chords.groups = new Array(n),
4720 subgroups = new Array(n * n),
4721 k,
4722 x,
4723 x0,
4724 dx,
4725 i,
4726 j;
4727
4728 // Compute the sum.
4729 k = 0, i = -1; while (++i < n) {
4730 x = 0, j = -1; while (++j < n) {
4731 x += matrix[i][j];
4732 }
4733 groupSums.push(x);
4734 subgroupIndex.push(sequence(n));
4735 k += x;
4736 }
4737
4738 // Sort groups…
4739 if (sortGroups) groupIndex.sort(function(a, b) {
4740 return sortGroups(groupSums[a], groupSums[b]);
4741 });
4742
4743 // Sort subgroups…
4744 if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
4745 d.sort(function(a, b) {
4746 return sortSubgroups(matrix[i][a], matrix[i][b]);
4747 });
4748 });
4749
4750 // Convert the sum to scaling factor for [0, 2pi].
4751 // TODO Allow start and end angle to be specified?
4752 // TODO Allow padding to be specified as percentage?
4753 k = max$1(0, tau$1 - padAngle * n) / k;
4754 dx = k ? padAngle : tau$1 / n;
4755
4756 // Compute the start and end angle for each group and subgroup.
4757 // Note: Opera has a bug reordering object literal properties!
4758 x = 0, i = -1; while (++i < n) {
4759 x0 = x, j = -1; while (++j < n) {
4760 var di = groupIndex[i],
4761 dj = subgroupIndex[di][j],
4762 v = matrix[di][dj],
4763 a0 = x,
4764 a1 = x += v * k;
4765 subgroups[dj * n + di] = {
4766 index: di,
4767 subindex: dj,
4768 startAngle: a0,
4769 endAngle: a1,
4770 value: v
4771 };
4772 }
4773 groups[di] = {
4774 index: di,
4775 startAngle: x0,
4776 endAngle: x,
4777 value: groupSums[di]
4778 };
4779 x += dx;
4780 }
4781
4782 // Generate chords for each (non-empty) subgroup-subgroup link.
4783 i = -1; while (++i < n) {
4784 j = i - 1; while (++j < n) {
4785 var source = subgroups[j * n + i],
4786 target = subgroups[i * n + j];
4787 if (source.value || target.value) {
4788 chords.push(source.value < target.value
4789 ? {source: target, target: source}
4790 : {source: source, target: target});
4791 }
4792 }
4793 }
4794
4795 return sortChords ? chords.sort(sortChords) : chords;
4796 }
4797
4798 chord.padAngle = function(_) {
4799 return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
4800 };
4801
4802 chord.sortGroups = function(_) {
4803 return arguments.length ? (sortGroups = _, chord) : sortGroups;
4804 };
4805
4806 chord.sortSubgroups = function(_) {
4807 return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
4808 };
4809
4810 chord.sortChords = function(_) {
4811 return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
4812 };
4813
4814 return chord;
4815 }
4816
4817 var slice$2 = Array.prototype.slice;
4818
4819 function constant$5(x) {
4820 return function() {
4821 return x;
4822 };
4823 }
4824
4825 var pi$2 = Math.PI;
4826 var tau$2 = 2 * pi$2;
4827 var epsilon$1 = 1e-6;
4828 var tauEpsilon = tau$2 - epsilon$1;
4829
4830 function Path() {
4831 this._x0 = this._y0 = // start of current subpath
4832 this._x1 = this._y1 = null; // end of current subpath
4833 this._ = "";
4834 }
4835
4836 function path() {
4837 return new Path;
4838 }
4839
4840 Path.prototype = path.prototype = {
4841 constructor: Path,
4842 moveTo: function(x, y) {
4843 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
4844 },
4845 closePath: function() {
4846 if (this._x1 !== null) {
4847 this._x1 = this._x0, this._y1 = this._y0;
4848 this._ += "Z";
4849 }
4850 },
4851 lineTo: function(x, y) {
4852 this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
4853 },
4854 quadraticCurveTo: function(x1, y1, x, y) {
4855 this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4856 },
4857 bezierCurveTo: function(x1, y1, x2, y2, x, y) {
4858 this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4859 },
4860 arcTo: function(x1, y1, x2, y2, r) {
4861 x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
4862 var x0 = this._x1,
4863 y0 = this._y1,
4864 x21 = x2 - x1,
4865 y21 = y2 - y1,
4866 x01 = x0 - x1,
4867 y01 = y0 - y1,
4868 l01_2 = x01 * x01 + y01 * y01;
4869
4870 // Is the radius negative? Error.
4871 if (r < 0) throw new Error("negative radius: " + r);
4872
4873 // Is this path empty? Move to (x1,y1).
4874 if (this._x1 === null) {
4875 this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
4876 }
4877
4878 // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
4879 else if (!(l01_2 > epsilon$1)) {}
4880
4881 // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
4882 // Equivalently, is (x1,y1) coincident with (x2,y2)?
4883 // Or, is the radius zero? Line to (x1,y1).
4884 else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
4885 this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
4886 }
4887
4888 // Otherwise, draw an arc!
4889 else {
4890 var x20 = x2 - x0,
4891 y20 = y2 - y0,
4892 l21_2 = x21 * x21 + y21 * y21,
4893 l20_2 = x20 * x20 + y20 * y20,
4894 l21 = Math.sqrt(l21_2),
4895 l01 = Math.sqrt(l01_2),
4896 l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
4897 t01 = l / l01,
4898 t21 = l / l21;
4899
4900 // If the start tangent is not coincident with (x0,y0), line to.
4901 if (Math.abs(t01 - 1) > epsilon$1) {
4902 this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
4903 }
4904
4905 this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
4906 }
4907 },
4908 arc: function(x, y, r, a0, a1, ccw) {
4909 x = +x, y = +y, r = +r;
4910 var dx = r * Math.cos(a0),
4911 dy = r * Math.sin(a0),
4912 x0 = x + dx,
4913 y0 = y + dy,
4914 cw = 1 ^ ccw,
4915 da = ccw ? a0 - a1 : a1 - a0;
4916
4917 // Is the radius negative? Error.
4918 if (r < 0) throw new Error("negative radius: " + r);
4919
4920 // Is this path empty? Move to (x0,y0).
4921 if (this._x1 === null) {
4922 this._ += "M" + x0 + "," + y0;
4923 }
4924
4925 // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
4926 else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
4927 this._ += "L" + x0 + "," + y0;
4928 }
4929
4930 // Is this arc empty? We’re done.
4931 if (!r) return;
4932
4933 // Does the angle go the wrong way? Flip the direction.
4934 if (da < 0) da = da % tau$2 + tau$2;
4935
4936 // Is this a complete circle? Draw two arcs to complete the circle.
4937 if (da > tauEpsilon) {
4938 this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
4939 }
4940
4941 // Is this arc non-empty? Draw an arc!
4942 else if (da > epsilon$1) {
4943 this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
4944 }
4945 },
4946 rect: function(x, y, w, h) {
4947 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
4948 },
4949 toString: function() {
4950 return this._;
4951 }
4952 };
4953
4954 function defaultSource(d) {
4955 return d.source;
4956 }
4957
4958 function defaultTarget(d) {
4959 return d.target;
4960 }
4961
4962 function defaultRadius(d) {
4963 return d.radius;
4964 }
4965
4966 function defaultStartAngle(d) {
4967 return d.startAngle;
4968 }
4969
4970 function defaultEndAngle(d) {
4971 return d.endAngle;
4972 }
4973
4974 function ribbon() {
4975 var source = defaultSource,
4976 target = defaultTarget,
4977 radius = defaultRadius,
4978 startAngle = defaultStartAngle,
4979 endAngle = defaultEndAngle,
4980 context = null;
4981
4982 function ribbon() {
4983 var buffer,
4984 argv = slice$2.call(arguments),
4985 s = source.apply(this, argv),
4986 t = target.apply(this, argv),
4987 sr = +radius.apply(this, (argv[0] = s, argv)),
4988 sa0 = startAngle.apply(this, argv) - halfPi$1,
4989 sa1 = endAngle.apply(this, argv) - halfPi$1,
4990 sx0 = sr * cos(sa0),
4991 sy0 = sr * sin(sa0),
4992 tr = +radius.apply(this, (argv[0] = t, argv)),
4993 ta0 = startAngle.apply(this, argv) - halfPi$1,
4994 ta1 = endAngle.apply(this, argv) - halfPi$1;
4995
4996 if (!context) context = buffer = path();
4997
4998 context.moveTo(sx0, sy0);
4999 context.arc(0, 0, sr, sa0, sa1);
5000 if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
5001 context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
5002 context.arc(0, 0, tr, ta0, ta1);
5003 }
5004 context.quadraticCurveTo(0, 0, sx0, sy0);
5005 context.closePath();
5006
5007 if (buffer) return context = null, buffer + "" || null;
5008 }
5009
5010 ribbon.radius = function(_) {
5011 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
5012 };
5013
5014 ribbon.startAngle = function(_) {
5015 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
5016 };
5017
5018 ribbon.endAngle = function(_) {
5019 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
5020 };
5021
5022 ribbon.source = function(_) {
5023 return arguments.length ? (source = _, ribbon) : source;
5024 };
5025
5026 ribbon.target = function(_) {
5027 return arguments.length ? (target = _, ribbon) : target;
5028 };
5029
5030 ribbon.context = function(_) {
5031 return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
5032 };
5033
5034 return ribbon;
5035 }
5036
5037 var prefix = "$";
5038
5039 function Map() {}
5040
5041 Map.prototype = map$1.prototype = {
5042 constructor: Map,
5043 has: function(key) {
5044 return (prefix + key) in this;
5045 },
5046 get: function(key) {
5047 return this[prefix + key];
5048 },
5049 set: function(key, value) {
5050 this[prefix + key] = value;
5051 return this;
5052 },
5053 remove: function(key) {
5054 var property = prefix + key;
5055 return property in this && delete this[property];
5056 },
5057 clear: function() {
5058 for (var property in this) if (property[0] === prefix) delete this[property];
5059 },
5060 keys: function() {
5061 var keys = [];
5062 for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
5063 return keys;
5064 },
5065 values: function() {
5066 var values = [];
5067 for (var property in this) if (property[0] === prefix) values.push(this[property]);
5068 return values;
5069 },
5070 entries: function() {
5071 var entries = [];
5072 for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
5073 return entries;
5074 },
5075 size: function() {
5076 var size = 0;
5077 for (var property in this) if (property[0] === prefix) ++size;
5078 return size;
5079 },
5080 empty: function() {
5081 for (var property in this) if (property[0] === prefix) return false;
5082 return true;
5083 },
5084 each: function(f) {
5085 for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
5086 }
5087 };
5088
5089 function map$1(object, f) {
5090 var map = new Map;
5091
5092 // Copy constructor.
5093 if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
5094
5095 // Index array by numeric index or specified key function.
5096 else if (Array.isArray(object)) {
5097 var i = -1,
5098 n = object.length,
5099 o;
5100
5101 if (f == null) while (++i < n) map.set(i, object[i]);
5102 else while (++i < n) map.set(f(o = object[i], i, object), o);
5103 }
5104
5105 // Convert object to map.
5106 else if (object) for (var key in object) map.set(key, object[key]);
5107
5108 return map;
5109 }
5110
5111 function nest() {
5112 var keys = [],
5113 sortKeys = [],
5114 sortValues,
5115 rollup,
5116 nest;
5117
5118 function apply(array, depth, createResult, setResult) {
5119 if (depth >= keys.length) {
5120 if (sortValues != null) array.sort(sortValues);
5121 return rollup != null ? rollup(array) : array;
5122 }
5123
5124 var i = -1,
5125 n = array.length,
5126 key = keys[depth++],
5127 keyValue,
5128 value,
5129 valuesByKey = map$1(),
5130 values,
5131 result = createResult();
5132
5133 while (++i < n) {
5134 if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
5135 values.push(value);
5136 } else {
5137 valuesByKey.set(keyValue, [value]);
5138 }
5139 }
5140
5141 valuesByKey.each(function(values, key) {
5142 setResult(result, key, apply(values, depth, createResult, setResult));
5143 });
5144
5145 return result;
5146 }
5147
5148 function entries(map, depth) {
5149 if (++depth > keys.length) return map;
5150 var array, sortKey = sortKeys[depth - 1];
5151 if (rollup != null && depth >= keys.length) array = map.entries();
5152 else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
5153 return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
5154 }
5155
5156 return nest = {
5157 object: function(array) { return apply(array, 0, createObject, setObject); },
5158 map: function(array) { return apply(array, 0, createMap, setMap); },
5159 entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
5160 key: function(d) { keys.push(d); return nest; },
5161 sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
5162 sortValues: function(order) { sortValues = order; return nest; },
5163 rollup: function(f) { rollup = f; return nest; }
5164 };
5165 }
5166
5167 function createObject() {
5168 return {};
5169 }
5170
5171 function setObject(object, key, value) {
5172 object[key] = value;
5173 }
5174
5175 function createMap() {
5176 return map$1();
5177 }
5178
5179 function setMap(map, key, value) {
5180 map.set(key, value);
5181 }
5182
5183 function Set() {}
5184
5185 var proto = map$1.prototype;
5186
5187 Set.prototype = set$2.prototype = {
5188 constructor: Set,
5189 has: proto.has,
5190 add: function(value) {
5191 value += "";
5192 this[prefix + value] = value;
5193 return this;
5194 },
5195 remove: proto.remove,
5196 clear: proto.clear,
5197 values: proto.keys,
5198 size: proto.size,
5199 empty: proto.empty,
5200 each: proto.each
5201 };
5202
5203 function set$2(object, f) {
5204 var set = new Set;
5205
5206 // Copy constructor.
5207 if (object instanceof Set) object.each(function(value) { set.add(value); });
5208
5209 // Otherwise, assume it’s an array.
5210 else if (object) {
5211 var i = -1, n = object.length;
5212 if (f == null) while (++i < n) set.add(object[i]);
5213 else while (++i < n) set.add(f(object[i], i, object));
5214 }
5215
5216 return set;
5217 }
5218
5219 function keys(map) {
5220 var keys = [];
5221 for (var key in map) keys.push(key);
5222 return keys;
5223 }
5224
5225 function values(map) {
5226 var values = [];
5227 for (var key in map) values.push(map[key]);
5228 return values;
5229 }
5230
5231 function entries(map) {
5232 var entries = [];
5233 for (var key in map) entries.push({key: key, value: map[key]});
5234 return entries;
5235 }
5236
5237 var EOL = {};
5238 var EOF = {};
5239 var QUOTE = 34;
5240 var NEWLINE = 10;
5241 var RETURN = 13;
5242
5243 function objectConverter(columns) {
5244 return new Function("d", "return {" + columns.map(function(name, i) {
5245 return JSON.stringify(name) + ": d[" + i + "]";
5246 }).join(",") + "}");
5247 }
5248
5249 function customConverter(columns, f) {
5250 var object = objectConverter(columns);
5251 return function(row, i) {
5252 return f(object(row), i, columns);
5253 };
5254 }
5255
5256 // Compute unique columns in order of discovery.
5257 function inferColumns(rows) {
5258 var columnSet = Object.create(null),
5259 columns = [];
5260
5261 rows.forEach(function(row) {
5262 for (var column in row) {
5263 if (!(column in columnSet)) {
5264 columns.push(columnSet[column] = column);
5265 }
5266 }
5267 });
5268
5269 return columns;
5270 }
5271
5272 function dsv(delimiter) {
5273 var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
5274 DELIMITER = delimiter.charCodeAt(0);
5275
5276 function parse(text, f) {
5277 var convert, columns, rows = parseRows(text, function(row, i) {
5278 if (convert) return convert(row, i - 1);
5279 columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
5280 });
5281 rows.columns = columns || [];
5282 return rows;
5283 }
5284
5285 function parseRows(text, f) {
5286 var rows = [], // output rows
5287 N = text.length,
5288 I = 0, // current character index
5289 n = 0, // current line number
5290 t, // current token
5291 eof = N <= 0, // current token followed by EOF?
5292 eol = false; // current token followed by EOL?
5293
5294 // Strip the trailing newline.
5295 if (text.charCodeAt(N - 1) === NEWLINE) --N;
5296 if (text.charCodeAt(N - 1) === RETURN) --N;
5297
5298 function token() {
5299 if (eof) return EOF;
5300 if (eol) return eol = false, EOL;
5301
5302 // Unescape quotes.
5303 var i, j = I, c;
5304 if (text.charCodeAt(j) === QUOTE) {
5305 while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
5306 if ((i = I) >= N) eof = true;
5307 else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
5308 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5309 return text.slice(j + 1, i - 1).replace(/""/g, "\"");
5310 }
5311
5312 // Find next delimiter or newline.
5313 while (I < N) {
5314 if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
5315 else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5316 else if (c !== DELIMITER) continue;
5317 return text.slice(j, i);
5318 }
5319
5320 // Return last token before EOF.
5321 return eof = true, text.slice(j, N);
5322 }
5323
5324 while ((t = token()) !== EOF) {
5325 var row = [];
5326 while (t !== EOL && t !== EOF) row.push(t), t = token();
5327 if (f && (row = f(row, n++)) == null) continue;
5328 rows.push(row);
5329 }
5330
5331 return rows;
5332 }
5333
5334 function format(rows, columns) {
5335 if (columns == null) columns = inferColumns(rows);
5336 return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
5337 return columns.map(function(column) {
5338 return formatValue(row[column]);
5339 }).join(delimiter);
5340 })).join("\n");
5341 }
5342
5343 function formatRows(rows) {
5344 return rows.map(formatRow).join("\n");
5345 }
5346
5347 function formatRow(row) {
5348 return row.map(formatValue).join(delimiter);
5349 }
5350
5351 function formatValue(text) {
5352 return text == null ? ""
5353 : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
5354 : text;
5355 }
5356
5357 return {
5358 parse: parse,
5359 parseRows: parseRows,
5360 format: format,
5361 formatRows: formatRows
5362 };
5363 }
5364
5365 var csv = dsv(",");
5366
5367 var csvParse = csv.parse;
5368 var csvParseRows = csv.parseRows;
5369 var csvFormat = csv.format;
5370 var csvFormatRows = csv.formatRows;
5371
5372 var tsv = dsv("\t");
5373
5374 var tsvParse = tsv.parse;
5375 var tsvParseRows = tsv.parseRows;
5376 var tsvFormat = tsv.format;
5377 var tsvFormatRows = tsv.formatRows;
5378
5379 function center$1(x, y) {
5380 var nodes;
5381
5382 if (x == null) x = 0;
5383 if (y == null) y = 0;
5384
5385 function force() {
5386 var i,
5387 n = nodes.length,
5388 node,
5389 sx = 0,
5390 sy = 0;
5391
5392 for (i = 0; i < n; ++i) {
5393 node = nodes[i], sx += node.x, sy += node.y;
5394 }
5395
5396 for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
5397 node = nodes[i], node.x -= sx, node.y -= sy;
5398 }
5399 }
5400
5401 force.initialize = function(_) {
5402 nodes = _;
5403 };
5404
5405 force.x = function(_) {
5406 return arguments.length ? (x = +_, force) : x;
5407 };
5408
5409 force.y = function(_) {
5410 return arguments.length ? (y = +_, force) : y;
5411 };
5412
5413 return force;
5414 }
5415
5416 function constant$6(x) {
5417 return function() {
5418 return x;
5419 };
5420 }
5421
5422 function jiggle() {
5423 return (Math.random() - 0.5) * 1e-6;
5424 }
5425
5426 function tree_add(d) {
5427 var x = +this._x.call(null, d),
5428 y = +this._y.call(null, d);
5429 return add(this.cover(x, y), x, y, d);
5430 }
5431
5432 function add(tree, x, y, d) {
5433 if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
5434
5435 var parent,
5436 node = tree._root,
5437 leaf = {data: d},
5438 x0 = tree._x0,
5439 y0 = tree._y0,
5440 x1 = tree._x1,
5441 y1 = tree._y1,
5442 xm,
5443 ym,
5444 xp,
5445 yp,
5446 right,
5447 bottom,
5448 i,
5449 j;
5450
5451 // If the tree is empty, initialize the root as a leaf.
5452 if (!node) return tree._root = leaf, tree;
5453
5454 // Find the existing leaf for the new point, or add it.
5455 while (node.length) {
5456 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5457 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5458 if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
5459 }
5460
5461 // Is the new point is exactly coincident with the existing point?
5462 xp = +tree._x.call(null, node.data);
5463 yp = +tree._y.call(null, node.data);
5464 if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
5465
5466 // Otherwise, split the leaf node until the old and new point are separated.
5467 do {
5468 parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
5469 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5470 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5471 } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
5472 return parent[j] = node, parent[i] = leaf, tree;
5473 }
5474
5475 function addAll(data) {
5476 var d, i, n = data.length,
5477 x,
5478 y,
5479 xz = new Array(n),
5480 yz = new Array(n),
5481 x0 = Infinity,
5482 y0 = Infinity,
5483 x1 = -Infinity,
5484 y1 = -Infinity;
5485
5486 // Compute the points and their extent.
5487 for (i = 0; i < n; ++i) {
5488 if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
5489 xz[i] = x;
5490 yz[i] = y;
5491 if (x < x0) x0 = x;
5492 if (x > x1) x1 = x;
5493 if (y < y0) y0 = y;
5494 if (y > y1) y1 = y;
5495 }
5496
5497 // If there were no (valid) points, inherit the existing extent.
5498 if (x1 < x0) x0 = this._x0, x1 = this._x1;
5499 if (y1 < y0) y0 = this._y0, y1 = this._y1;
5500
5501 // Expand the tree to cover the new points.
5502 this.cover(x0, y0).cover(x1, y1);
5503
5504 // Add the new points.
5505 for (i = 0; i < n; ++i) {
5506 add(this, xz[i], yz[i], data[i]);
5507 }
5508
5509 return this;
5510 }
5511
5512 function tree_cover(x, y) {
5513 if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
5514
5515 var x0 = this._x0,
5516 y0 = this._y0,
5517 x1 = this._x1,
5518 y1 = this._y1;
5519
5520 // If the quadtree has no extent, initialize them.
5521 // Integer extent are necessary so that if we later double the extent,
5522 // the existing quadrant boundaries don’t change due to floating point error!
5523 if (isNaN(x0)) {
5524 x1 = (x0 = Math.floor(x)) + 1;
5525 y1 = (y0 = Math.floor(y)) + 1;
5526 }
5527
5528 // Otherwise, double repeatedly to cover.
5529 else if (x0 > x || x > x1 || y0 > y || y > y1) {
5530 var z = x1 - x0,
5531 node = this._root,
5532 parent,
5533 i;
5534
5535 switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
5536 case 0: {
5537 do parent = new Array(4), parent[i] = node, node = parent;
5538 while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
5539 break;
5540 }
5541 case 1: {
5542 do parent = new Array(4), parent[i] = node, node = parent;
5543 while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
5544 break;
5545 }
5546 case 2: {
5547 do parent = new Array(4), parent[i] = node, node = parent;
5548 while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
5549 break;
5550 }
5551 case 3: {
5552 do parent = new Array(4), parent[i] = node, node = parent;
5553 while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
5554 break;
5555 }
5556 }
5557
5558 if (this._root && this._root.length) this._root = node;
5559 }
5560
5561 // If the quadtree covers the point already, just return.
5562 else return this;
5563
5564 this._x0 = x0;
5565 this._y0 = y0;
5566 this._x1 = x1;
5567 this._y1 = y1;
5568 return this;
5569 }
5570
5571 function tree_data() {
5572 var data = [];
5573 this.visit(function(node) {
5574 if (!node.length) do data.push(node.data); while (node = node.next)
5575 });
5576 return data;
5577 }
5578
5579 function tree_extent(_) {
5580 return arguments.length
5581 ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
5582 : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
5583 }
5584
5585 function Quad(node, x0, y0, x1, y1) {
5586 this.node = node;
5587 this.x0 = x0;
5588 this.y0 = y0;
5589 this.x1 = x1;
5590 this.y1 = y1;
5591 }
5592
5593 function tree_find(x, y, radius) {
5594 var data,
5595 x0 = this._x0,
5596 y0 = this._y0,
5597 x1,
5598 y1,
5599 x2,
5600 y2,
5601 x3 = this._x1,
5602 y3 = this._y1,
5603 quads = [],
5604 node = this._root,
5605 q,
5606 i;
5607
5608 if (node) quads.push(new Quad(node, x0, y0, x3, y3));
5609 if (radius == null) radius = Infinity;
5610 else {
5611 x0 = x - radius, y0 = y - radius;
5612 x3 = x + radius, y3 = y + radius;
5613 radius *= radius;
5614 }
5615
5616 while (q = quads.pop()) {
5617
5618 // Stop searching if this quadrant can’t contain a closer node.
5619 if (!(node = q.node)
5620 || (x1 = q.x0) > x3
5621 || (y1 = q.y0) > y3
5622 || (x2 = q.x1) < x0
5623 || (y2 = q.y1) < y0) continue;
5624
5625 // Bisect the current quadrant.
5626 if (node.length) {
5627 var xm = (x1 + x2) / 2,
5628 ym = (y1 + y2) / 2;
5629
5630 quads.push(
5631 new Quad(node[3], xm, ym, x2, y2),
5632 new Quad(node[2], x1, ym, xm, y2),
5633 new Quad(node[1], xm, y1, x2, ym),
5634 new Quad(node[0], x1, y1, xm, ym)
5635 );
5636
5637 // Visit the closest quadrant first.
5638 if (i = (y >= ym) << 1 | (x >= xm)) {
5639 q = quads[quads.length - 1];
5640 quads[quads.length - 1] = quads[quads.length - 1 - i];
5641 quads[quads.length - 1 - i] = q;
5642 }
5643 }
5644
5645 // Visit this point. (Visiting coincident points isn’t necessary!)
5646 else {
5647 var dx = x - +this._x.call(null, node.data),
5648 dy = y - +this._y.call(null, node.data),
5649 d2 = dx * dx + dy * dy;
5650 if (d2 < radius) {
5651 var d = Math.sqrt(radius = d2);
5652 x0 = x - d, y0 = y - d;
5653 x3 = x + d, y3 = y + d;
5654 data = node.data;
5655 }
5656 }
5657 }
5658
5659 return data;
5660 }
5661
5662 function tree_remove(d) {
5663 if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
5664
5665 var parent,
5666 node = this._root,
5667 retainer,
5668 previous,
5669 next,
5670 x0 = this._x0,
5671 y0 = this._y0,
5672 x1 = this._x1,
5673 y1 = this._y1,
5674 x,
5675 y,
5676 xm,
5677 ym,
5678 right,
5679 bottom,
5680 i,
5681 j;
5682
5683 // If the tree is empty, initialize the root as a leaf.
5684 if (!node) return this;
5685
5686 // Find the leaf node for the point.
5687 // While descending, also retain the deepest parent with a non-removed sibling.
5688 if (node.length) while (true) {
5689 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5690 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5691 if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
5692 if (!node.length) break;
5693 if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
5694 }
5695
5696 // Find the point to remove.
5697 while (node.data !== d) if (!(previous = node, node = node.next)) return this;
5698 if (next = node.next) delete node.next;
5699
5700 // If there are multiple coincident points, remove just the point.
5701 if (previous) return next ? previous.next = next : delete previous.next, this;
5702
5703 // If this is the root point, remove it.
5704 if (!parent) return this._root = next, this;
5705
5706 // Remove this leaf.
5707 next ? parent[i] = next : delete parent[i];
5708
5709 // If the parent now contains exactly one leaf, collapse superfluous parents.
5710 if ((node = parent[0] || parent[1] || parent[2] || parent[3])
5711 && node === (parent[3] || parent[2] || parent[1] || parent[0])
5712 && !node.length) {
5713 if (retainer) retainer[j] = node;
5714 else this._root = node;
5715 }
5716
5717 return this;
5718 }
5719
5720 function removeAll(data) {
5721 for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
5722 return this;
5723 }
5724
5725 function tree_root() {
5726 return this._root;
5727 }
5728
5729 function tree_size() {
5730 var size = 0;
5731 this.visit(function(node) {
5732 if (!node.length) do ++size; while (node = node.next)
5733 });
5734 return size;
5735 }
5736
5737 function tree_visit(callback) {
5738 var quads = [], q, node = this._root, child, x0, y0, x1, y1;
5739 if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
5740 while (q = quads.pop()) {
5741 if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
5742 var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
5743 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
5744 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
5745 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
5746 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
5747 }
5748 }
5749 return this;
5750 }
5751
5752 function tree_visitAfter(callback) {
5753 var quads = [], next = [], q;
5754 if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
5755 while (q = quads.pop()) {
5756 var node = q.node;
5757 if (node.length) {
5758 var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
5759 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
5760 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
5761 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
5762 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
5763 }
5764 next.push(q);
5765 }
5766 while (q = next.pop()) {
5767 callback(q.node, q.x0, q.y0, q.x1, q.y1);
5768 }
5769 return this;
5770 }
5771
5772 function defaultX(d) {
5773 return d[0];
5774 }
5775
5776 function tree_x(_) {
5777 return arguments.length ? (this._x = _, this) : this._x;
5778 }
5779
5780 function defaultY(d) {
5781 return d[1];
5782 }
5783
5784 function tree_y(_) {
5785 return arguments.length ? (this._y = _, this) : this._y;
5786 }
5787
5788 function quadtree(nodes, x, y) {
5789 var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
5790 return nodes == null ? tree : tree.addAll(nodes);
5791 }
5792
5793 function Quadtree(x, y, x0, y0, x1, y1) {
5794 this._x = x;
5795 this._y = y;
5796 this._x0 = x0;
5797 this._y0 = y0;
5798 this._x1 = x1;
5799 this._y1 = y1;
5800 this._root = undefined;
5801 }
5802
5803 function leaf_copy(leaf) {
5804 var copy = {data: leaf.data}, next = copy;
5805 while (leaf = leaf.next) next = next.next = {data: leaf.data};
5806 return copy;
5807 }
5808
5809 var treeProto = quadtree.prototype = Quadtree.prototype;
5810
5811 treeProto.copy = function() {
5812 var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
5813 node = this._root,
5814 nodes,
5815 child;
5816
5817 if (!node) return copy;
5818
5819 if (!node.length) return copy._root = leaf_copy(node), copy;
5820
5821 nodes = [{source: node, target: copy._root = new Array(4)}];
5822 while (node = nodes.pop()) {
5823 for (var i = 0; i < 4; ++i) {
5824 if (child = node.source[i]) {
5825 if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
5826 else node.target[i] = leaf_copy(child);
5827 }
5828 }
5829 }
5830
5831 return copy;
5832 };
5833
5834 treeProto.add = tree_add;
5835 treeProto.addAll = addAll;
5836 treeProto.cover = tree_cover;
5837 treeProto.data = tree_data;
5838 treeProto.extent = tree_extent;
5839 treeProto.find = tree_find;
5840 treeProto.remove = tree_remove;
5841 treeProto.removeAll = removeAll;
5842 treeProto.root = tree_root;
5843 treeProto.size = tree_size;
5844 treeProto.visit = tree_visit;
5845 treeProto.visitAfter = tree_visitAfter;
5846 treeProto.x = tree_x;
5847 treeProto.y = tree_y;
5848
5849 function x(d) {
5850 return d.x + d.vx;
5851 }
5852
5853 function y(d) {
5854 return d.y + d.vy;
5855 }
5856
5857 function collide(radius) {
5858 var nodes,
5859 radii,
5860 strength = 1,
5861 iterations = 1;
5862
5863 if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
5864
5865 function force() {
5866 var i, n = nodes.length,
5867 tree,
5868 node,
5869 xi,
5870 yi,
5871 ri,
5872 ri2;
5873
5874 for (var k = 0; k < iterations; ++k) {
5875 tree = quadtree(nodes, x, y).visitAfter(prepare);
5876 for (i = 0; i < n; ++i) {
5877 node = nodes[i];
5878 ri = radii[node.index], ri2 = ri * ri;
5879 xi = node.x + node.vx;
5880 yi = node.y + node.vy;
5881 tree.visit(apply);
5882 }
5883 }
5884
5885 function apply(quad, x0, y0, x1, y1) {
5886 var data = quad.data, rj = quad.r, r = ri + rj;
5887 if (data) {
5888 if (data.index > node.index) {
5889 var x = xi - data.x - data.vx,
5890 y = yi - data.y - data.vy,
5891 l = x * x + y * y;
5892 if (l < r * r) {
5893 if (x === 0) x = jiggle(), l += x * x;
5894 if (y === 0) y = jiggle(), l += y * y;
5895 l = (r - (l = Math.sqrt(l))) / l * strength;
5896 node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
5897 node.vy += (y *= l) * r;
5898 data.vx -= x * (r = 1 - r);
5899 data.vy -= y * r;
5900 }
5901 }
5902 return;
5903 }
5904 return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
5905 }
5906 }
5907
5908 function prepare(quad) {
5909 if (quad.data) return quad.r = radii[quad.data.index];
5910 for (var i = quad.r = 0; i < 4; ++i) {
5911 if (quad[i] && quad[i].r > quad.r) {
5912 quad.r = quad[i].r;
5913 }
5914 }
5915 }
5916
5917 function initialize() {
5918 if (!nodes) return;
5919 var i, n = nodes.length, node;
5920 radii = new Array(n);
5921 for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
5922 }
5923
5924 force.initialize = function(_) {
5925 nodes = _;
5926 initialize();
5927 };
5928
5929 force.iterations = function(_) {
5930 return arguments.length ? (iterations = +_, force) : iterations;
5931 };
5932
5933 force.strength = function(_) {
5934 return arguments.length ? (strength = +_, force) : strength;
5935 };
5936
5937 force.radius = function(_) {
5938 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
5939 };
5940
5941 return force;
5942 }
5943
5944 function index(d) {
5945 return d.index;
5946 }
5947
5948 function find(nodeById, nodeId) {
5949 var node = nodeById.get(nodeId);
5950 if (!node) throw new Error("missing: " + nodeId);
5951 return node;
5952 }
5953
5954 function link(links) {
5955 var id = index,
5956 strength = defaultStrength,
5957 strengths,
5958 distance = constant$6(30),
5959 distances,
5960 nodes,
5961 count,
5962 bias,
5963 iterations = 1;
5964
5965 if (links == null) links = [];
5966
5967 function defaultStrength(link) {
5968 return 1 / Math.min(count[link.source.index], count[link.target.index]);
5969 }
5970
5971 function force(alpha) {
5972 for (var k = 0, n = links.length; k < iterations; ++k) {
5973 for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
5974 link = links[i], source = link.source, target = link.target;
5975 x = target.x + target.vx - source.x - source.vx || jiggle();
5976 y = target.y + target.vy - source.y - source.vy || jiggle();
5977 l = Math.sqrt(x * x + y * y);
5978 l = (l - distances[i]) / l * alpha * strengths[i];
5979 x *= l, y *= l;
5980 target.vx -= x * (b = bias[i]);
5981 target.vy -= y * b;
5982 source.vx += x * (b = 1 - b);
5983 source.vy += y * b;
5984 }
5985 }
5986 }
5987
5988 function initialize() {
5989 if (!nodes) return;
5990
5991 var i,
5992 n = nodes.length,
5993 m = links.length,
5994 nodeById = map$1(nodes, id),
5995 link;
5996
5997 for (i = 0, count = new Array(n); i < m; ++i) {
5998 link = links[i], link.index = i;
5999 if (typeof link.source !== "object") link.source = find(nodeById, link.source);
6000 if (typeof link.target !== "object") link.target = find(nodeById, link.target);
6001 count[link.source.index] = (count[link.source.index] || 0) + 1;
6002 count[link.target.index] = (count[link.target.index] || 0) + 1;
6003 }
6004
6005 for (i = 0, bias = new Array(m); i < m; ++i) {
6006 link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
6007 }
6008
6009 strengths = new Array(m), initializeStrength();
6010 distances = new Array(m), initializeDistance();
6011 }
6012
6013 function initializeStrength() {
6014 if (!nodes) return;
6015
6016 for (var i = 0, n = links.length; i < n; ++i) {
6017 strengths[i] = +strength(links[i], i, links);
6018 }
6019 }
6020
6021 function initializeDistance() {
6022 if (!nodes) return;
6023
6024 for (var i = 0, n = links.length; i < n; ++i) {
6025 distances[i] = +distance(links[i], i, links);
6026 }
6027 }
6028
6029 force.initialize = function(_) {
6030 nodes = _;
6031 initialize();
6032 };
6033
6034 force.links = function(_) {
6035 return arguments.length ? (links = _, initialize(), force) : links;
6036 };
6037
6038 force.id = function(_) {
6039 return arguments.length ? (id = _, force) : id;
6040 };
6041
6042 force.iterations = function(_) {
6043 return arguments.length ? (iterations = +_, force) : iterations;
6044 };
6045
6046 force.strength = function(_) {
6047 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
6048 };
6049
6050 force.distance = function(_) {
6051 return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
6052 };
6053
6054 return force;
6055 }
6056
6057 function x$1(d) {
6058 return d.x;
6059 }
6060
6061 function y$1(d) {
6062 return d.y;
6063 }
6064
6065 var initialRadius = 10;
6066 var initialAngle = Math.PI * (3 - Math.sqrt(5));
6067
6068 function simulation(nodes) {
6069 var simulation,
6070 alpha = 1,
6071 alphaMin = 0.001,
6072 alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
6073 alphaTarget = 0,
6074 velocityDecay = 0.6,
6075 forces = map$1(),
6076 stepper = timer(step),
6077 event = dispatch("tick", "end");
6078
6079 if (nodes == null) nodes = [];
6080
6081 function step() {
6082 tick();
6083 event.call("tick", simulation);
6084 if (alpha < alphaMin) {
6085 stepper.stop();
6086 event.call("end", simulation);
6087 }
6088 }
6089
6090 function tick() {
6091 var i, n = nodes.length, node;
6092
6093 alpha += (alphaTarget - alpha) * alphaDecay;
6094
6095 forces.each(function(force) {
6096 force(alpha);
6097 });
6098
6099 for (i = 0; i < n; ++i) {
6100 node = nodes[i];
6101 if (node.fx == null) node.x += node.vx *= velocityDecay;
6102 else node.x = node.fx, node.vx = 0;
6103 if (node.fy == null) node.y += node.vy *= velocityDecay;
6104 else node.y = node.fy, node.vy = 0;
6105 }
6106 }
6107
6108 function initializeNodes() {
6109 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6110 node = nodes[i], node.index = i;
6111 if (isNaN(node.x) || isNaN(node.y)) {
6112 var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
6113 node.x = radius * Math.cos(angle);
6114 node.y = radius * Math.sin(angle);
6115 }
6116 if (isNaN(node.vx) || isNaN(node.vy)) {
6117 node.vx = node.vy = 0;
6118 }
6119 }
6120 }
6121
6122 function initializeForce(force) {
6123 if (force.initialize) force.initialize(nodes);
6124 return force;
6125 }
6126
6127 initializeNodes();
6128
6129 return simulation = {
6130 tick: tick,
6131
6132 restart: function() {
6133 return stepper.restart(step), simulation;
6134 },
6135
6136 stop: function() {
6137 return stepper.stop(), simulation;
6138 },
6139
6140 nodes: function(_) {
6141 return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
6142 },
6143
6144 alpha: function(_) {
6145 return arguments.length ? (alpha = +_, simulation) : alpha;
6146 },
6147
6148 alphaMin: function(_) {
6149 return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
6150 },
6151
6152 alphaDecay: function(_) {
6153 return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
6154 },
6155
6156 alphaTarget: function(_) {
6157 return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
6158 },
6159
6160 velocityDecay: function(_) {
6161 return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
6162 },
6163
6164 force: function(name, _) {
6165 return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
6166 },
6167
6168 find: function(x, y, radius) {
6169 var i = 0,
6170 n = nodes.length,
6171 dx,
6172 dy,
6173 d2,
6174 node,
6175 closest;
6176
6177 if (radius == null) radius = Infinity;
6178 else radius *= radius;
6179
6180 for (i = 0; i < n; ++i) {
6181 node = nodes[i];
6182 dx = x - node.x;
6183 dy = y - node.y;
6184 d2 = dx * dx + dy * dy;
6185 if (d2 < radius) closest = node, radius = d2;
6186 }
6187
6188 return closest;
6189 },
6190
6191 on: function(name, _) {
6192 return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
6193 }
6194 };
6195 }
6196
6197 function manyBody() {
6198 var nodes,
6199 node,
6200 alpha,
6201 strength = constant$6(-30),
6202 strengths,
6203 distanceMin2 = 1,
6204 distanceMax2 = Infinity,
6205 theta2 = 0.81;
6206
6207 function force(_) {
6208 var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
6209 for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
6210 }
6211
6212 function initialize() {
6213 if (!nodes) return;
6214 var i, n = nodes.length, node;
6215 strengths = new Array(n);
6216 for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
6217 }
6218
6219 function accumulate(quad) {
6220 var strength = 0, q, c, weight = 0, x, y, i;
6221
6222 // For internal nodes, accumulate forces from child quadrants.
6223 if (quad.length) {
6224 for (x = y = i = 0; i < 4; ++i) {
6225 if ((q = quad[i]) && (c = Math.abs(q.value))) {
6226 strength += q.value, weight += c, x += c * q.x, y += c * q.y;
6227 }
6228 }
6229 quad.x = x / weight;
6230 quad.y = y / weight;
6231 }
6232
6233 // For leaf nodes, accumulate forces from coincident quadrants.
6234 else {
6235 q = quad;
6236 q.x = q.data.x;
6237 q.y = q.data.y;
6238 do strength += strengths[q.data.index];
6239 while (q = q.next);
6240 }
6241
6242 quad.value = strength;
6243 }
6244
6245 function apply(quad, x1, _, x2) {
6246 if (!quad.value) return true;
6247
6248 var x = quad.x - node.x,
6249 y = quad.y - node.y,
6250 w = x2 - x1,
6251 l = x * x + y * y;
6252
6253 // Apply the Barnes-Hut approximation if possible.
6254 // Limit forces for very close nodes; randomize direction if coincident.
6255 if (w * w / theta2 < l) {
6256 if (l < distanceMax2) {
6257 if (x === 0) x = jiggle(), l += x * x;
6258 if (y === 0) y = jiggle(), l += y * y;
6259 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6260 node.vx += x * quad.value * alpha / l;
6261 node.vy += y * quad.value * alpha / l;
6262 }
6263 return true;
6264 }
6265
6266 // Otherwise, process points directly.
6267 else if (quad.length || l >= distanceMax2) return;
6268
6269 // Limit forces for very close nodes; randomize direction if coincident.
6270 if (quad.data !== node || quad.next) {
6271 if (x === 0) x = jiggle(), l += x * x;
6272 if (y === 0) y = jiggle(), l += y * y;
6273 if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6274 }
6275
6276 do if (quad.data !== node) {
6277 w = strengths[quad.data.index] * alpha / l;
6278 node.vx += x * w;
6279 node.vy += y * w;
6280 } while (quad = quad.next);
6281 }
6282
6283 force.initialize = function(_) {
6284 nodes = _;
6285 initialize();
6286 };
6287
6288 force.strength = function(_) {
6289 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6290 };
6291
6292 force.distanceMin = function(_) {
6293 return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
6294 };
6295
6296 force.distanceMax = function(_) {
6297 return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
6298 };
6299
6300 force.theta = function(_) {
6301 return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
6302 };
6303
6304 return force;
6305 }
6306
6307 function radial(radius, x, y) {
6308 var nodes,
6309 strength = constant$6(0.1),
6310 strengths,
6311 radiuses;
6312
6313 if (typeof radius !== "function") radius = constant$6(+radius);
6314 if (x == null) x = 0;
6315 if (y == null) y = 0;
6316
6317 function force(alpha) {
6318 for (var i = 0, n = nodes.length; i < n; ++i) {
6319 var node = nodes[i],
6320 dx = node.x - x || 1e-6,
6321 dy = node.y - y || 1e-6,
6322 r = Math.sqrt(dx * dx + dy * dy),
6323 k = (radiuses[i] - r) * strengths[i] * alpha / r;
6324 node.vx += dx * k;
6325 node.vy += dy * k;
6326 }
6327 }
6328
6329 function initialize() {
6330 if (!nodes) return;
6331 var i, n = nodes.length;
6332 strengths = new Array(n);
6333 radiuses = new Array(n);
6334 for (i = 0; i < n; ++i) {
6335 radiuses[i] = +radius(nodes[i], i, nodes);
6336 strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
6337 }
6338 }
6339
6340 force.initialize = function(_) {
6341 nodes = _, initialize();
6342 };
6343
6344 force.strength = function(_) {
6345 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6346 };
6347
6348 force.radius = function(_) {
6349 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
6350 };
6351
6352 force.x = function(_) {
6353 return arguments.length ? (x = +_, force) : x;
6354 };
6355
6356 force.y = function(_) {
6357 return arguments.length ? (y = +_, force) : y;
6358 };
6359
6360 return force;
6361 }
6362
6363 function x$2(x) {
6364 var strength = constant$6(0.1),
6365 nodes,
6366 strengths,
6367 xz;
6368
6369 if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
6370
6371 function force(alpha) {
6372 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6373 node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
6374 }
6375 }
6376
6377 function initialize() {
6378 if (!nodes) return;
6379 var i, n = nodes.length;
6380 strengths = new Array(n);
6381 xz = new Array(n);
6382 for (i = 0; i < n; ++i) {
6383 strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6384 }
6385 }
6386
6387 force.initialize = function(_) {
6388 nodes = _;
6389 initialize();
6390 };
6391
6392 force.strength = function(_) {
6393 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6394 };
6395
6396 force.x = function(_) {
6397 return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
6398 };
6399
6400 return force;
6401 }
6402
6403 function y$2(y) {
6404 var strength = constant$6(0.1),
6405 nodes,
6406 strengths,
6407 yz;
6408
6409 if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
6410
6411 function force(alpha) {
6412 for (var i = 0, n = nodes.length, node; i < n; ++i) {
6413 node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
6414 }
6415 }
6416
6417 function initialize() {
6418 if (!nodes) return;
6419 var i, n = nodes.length;
6420 strengths = new Array(n);
6421 yz = new Array(n);
6422 for (i = 0; i < n; ++i) {
6423 strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6424 }
6425 }
6426
6427 force.initialize = function(_) {
6428 nodes = _;
6429 initialize();
6430 };
6431
6432 force.strength = function(_) {
6433 return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6434 };
6435
6436 force.y = function(_) {
6437 return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
6438 };
6439
6440 return force;
6441 }
6442
6443 // Computes the decimal coefficient and exponent of the specified number x with
6444 // significant digits p, where x is positive and p is in [1, 21] or undefined.
6445 // For example, formatDecimal(1.23) returns ["123", 0].
6446 function formatDecimal(x, p) {
6447 if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
6448 var i, coefficient = x.slice(0, i);
6449
6450 // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
6451 // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
6452 return [
6453 coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
6454 +x.slice(i + 1)
6455 ];
6456 }
6457
6458 function exponent$1(x) {
6459 return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
6460 }
6461
6462 function formatGroup(grouping, thousands) {
6463 return function(value, width) {
6464 var i = value.length,
6465 t = [],
6466 j = 0,
6467 g = grouping[0],
6468 length = 0;
6469
6470 while (i > 0 && g > 0) {
6471 if (length + g + 1 > width) g = Math.max(1, width - length);
6472 t.push(value.substring(i -= g, i + g));
6473 if ((length += g + 1) > width) break;
6474 g = grouping[j = (j + 1) % grouping.length];
6475 }
6476
6477 return t.reverse().join(thousands);
6478 };
6479 }
6480
6481 function formatNumerals(numerals) {
6482 return function(value) {
6483 return value.replace(/[0-9]/g, function(i) {
6484 return numerals[+i];
6485 });
6486 };
6487 }
6488
6489 function formatDefault(x, p) {
6490 x = x.toPrecision(p);
6491
6492 out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
6493 switch (x[i]) {
6494 case ".": i0 = i1 = i; break;
6495 case "0": if (i0 === 0) i0 = i; i1 = i; break;
6496 case "e": break out;
6497 default: if (i0 > 0) i0 = 0; break;
6498 }
6499 }
6500
6501 return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
6502 }
6503
6504 var prefixExponent;
6505
6506 function formatPrefixAuto(x, p) {
6507 var d = formatDecimal(x, p);
6508 if (!d) return x + "";
6509 var coefficient = d[0],
6510 exponent = d[1],
6511 i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
6512 n = coefficient.length;
6513 return i === n ? coefficient
6514 : i > n ? coefficient + new Array(i - n + 1).join("0")
6515 : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
6516 : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
6517 }
6518
6519 function formatRounded(x, p) {
6520 var d = formatDecimal(x, p);
6521 if (!d) return x + "";
6522 var coefficient = d[0],
6523 exponent = d[1];
6524 return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
6525 : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
6526 : coefficient + new Array(exponent - coefficient.length + 2).join("0");
6527 }
6528
6529 var formatTypes = {
6530 "": formatDefault,
6531 "%": function(x, p) { return (x * 100).toFixed(p); },
6532 "b": function(x) { return Math.round(x).toString(2); },
6533 "c": function(x) { return x + ""; },
6534 "d": function(x) { return Math.round(x).toString(10); },
6535 "e": function(x, p) { return x.toExponential(p); },
6536 "f": function(x, p) { return x.toFixed(p); },
6537 "g": function(x, p) { return x.toPrecision(p); },
6538 "o": function(x) { return Math.round(x).toString(8); },
6539 "p": function(x, p) { return formatRounded(x * 100, p); },
6540 "r": formatRounded,
6541 "s": formatPrefixAuto,
6542 "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
6543 "x": function(x) { return Math.round(x).toString(16); }
6544 };
6545
6546 // [[fill]align][sign][symbol][0][width][,][.precision][type]
6547 var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
6548
6549 function formatSpecifier(specifier) {
6550 return new FormatSpecifier(specifier);
6551 }
6552
6553 formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
6554
6555 function FormatSpecifier(specifier) {
6556 if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
6557
6558 var match,
6559 fill = match[1] || " ",
6560 align = match[2] || ">",
6561 sign = match[3] || "-",
6562 symbol = match[4] || "",
6563 zero = !!match[5],
6564 width = match[6] && +match[6],
6565 comma = !!match[7],
6566 precision = match[8] && +match[8].slice(1),
6567 type = match[9] || "";
6568
6569 // The "n" type is an alias for ",g".
6570 if (type === "n") comma = true, type = "g";
6571
6572 // Map invalid types to the default format.
6573 else if (!formatTypes[type]) type = "";
6574
6575 // If zero fill is specified, padding goes after sign and before digits.
6576 if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
6577
6578 this.fill = fill;
6579 this.align = align;
6580 this.sign = sign;
6581 this.symbol = symbol;
6582 this.zero = zero;
6583 this.width = width;
6584 this.comma = comma;
6585 this.precision = precision;
6586 this.type = type;
6587 }
6588
6589 FormatSpecifier.prototype.toString = function() {
6590 return this.fill
6591 + this.align
6592 + this.sign
6593 + this.symbol
6594 + (this.zero ? "0" : "")
6595 + (this.width == null ? "" : Math.max(1, this.width | 0))
6596 + (this.comma ? "," : "")
6597 + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
6598 + this.type;
6599 };
6600
6601 function identity$3(x) {
6602 return x;
6603 }
6604
6605 var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
6606
6607 function formatLocale(locale) {
6608 var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
6609 currency = locale.currency,
6610 decimal = locale.decimal,
6611 numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
6612 percent = locale.percent || "%";
6613
6614 function newFormat(specifier) {
6615 specifier = formatSpecifier(specifier);
6616
6617 var fill = specifier.fill,
6618 align = specifier.align,
6619 sign = specifier.sign,
6620 symbol = specifier.symbol,
6621 zero = specifier.zero,
6622 width = specifier.width,
6623 comma = specifier.comma,
6624 precision = specifier.precision,
6625 type = specifier.type;
6626
6627 // Compute the prefix and suffix.
6628 // For SI-prefix, the suffix is lazily computed.
6629 var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
6630 suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
6631
6632 // What format function should we use?
6633 // Is this an integer type?
6634 // Can this type generate exponential notation?
6635 var formatType = formatTypes[type],
6636 maybeSuffix = !type || /[defgprs%]/.test(type);
6637
6638 // Set the default precision if not specified,
6639 // or clamp the specified precision to the supported range.
6640 // For significant precision, it must be in [1, 21].
6641 // For fixed precision, it must be in [0, 20].
6642 precision = precision == null ? (type ? 6 : 12)
6643 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
6644 : Math.max(0, Math.min(20, precision));
6645
6646 function format(value) {
6647 var valuePrefix = prefix,
6648 valueSuffix = suffix,
6649 i, n, c;
6650
6651 if (type === "c") {
6652 valueSuffix = formatType(value) + valueSuffix;
6653 value = "";
6654 } else {
6655 value = +value;
6656
6657 // Perform the initial formatting.
6658 var valueNegative = value < 0;
6659 value = formatType(Math.abs(value), precision);
6660
6661 // If a negative value rounds to zero during formatting, treat as positive.
6662 if (valueNegative && +value === 0) valueNegative = false;
6663
6664 // Compute the prefix and suffix.
6665 valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
6666 valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
6667
6668 // Break the formatted value into the integer “value” part that can be
6669 // grouped, and fractional or exponential “suffix” part that is not.
6670 if (maybeSuffix) {
6671 i = -1, n = value.length;
6672 while (++i < n) {
6673 if (c = value.charCodeAt(i), 48 > c || c > 57) {
6674 valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
6675 value = value.slice(0, i);
6676 break;
6677 }
6678 }
6679 }
6680 }
6681
6682 // If the fill character is not "0", grouping is applied before padding.
6683 if (comma && !zero) value = group(value, Infinity);
6684
6685 // Compute the padding.
6686 var length = valuePrefix.length + value.length + valueSuffix.length,
6687 padding = length < width ? new Array(width - length + 1).join(fill) : "";
6688
6689 // If the fill character is "0", grouping is applied after padding.
6690 if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
6691
6692 // Reconstruct the final output based on the desired alignment.
6693 switch (align) {
6694 case "<": value = valuePrefix + value + valueSuffix + padding; break;
6695 case "=": value = valuePrefix + padding + value + valueSuffix; break;
6696 case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
6697 default: value = padding + valuePrefix + value + valueSuffix; break;
6698 }
6699
6700 return numerals(value);
6701 }
6702
6703 format.toString = function() {
6704 return specifier + "";
6705 };
6706
6707 return format;
6708 }
6709
6710 function formatPrefix(specifier, value) {
6711 var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
6712 e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
6713 k = Math.pow(10, -e),
6714 prefix = prefixes[8 + e / 3];
6715 return function(value) {
6716 return f(k * value) + prefix;
6717 };
6718 }
6719
6720 return {
6721 format: newFormat,
6722 formatPrefix: formatPrefix
6723 };
6724 }
6725
6726 var locale;
6727
6728
6729
6730 defaultLocale({
6731 decimal: ".",
6732 thousands: ",",
6733 grouping: [3],
6734 currency: ["$", ""]
6735 });
6736
6737 function defaultLocale(definition) {
6738 locale = formatLocale(definition);
6739 exports.format = locale.format;
6740 exports.formatPrefix = locale.formatPrefix;
6741 return locale;
6742 }
6743
6744 function precisionFixed(step) {
6745 return Math.max(0, -exponent$1(Math.abs(step)));
6746 }
6747
6748 function precisionPrefix(step, value) {
6749 return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
6750 }
6751
6752 function precisionRound(step, max) {
6753 step = Math.abs(step), max = Math.abs(max) - step;
6754 return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
6755 }
6756
6757 // Adds floating point numbers with twice the normal precision.
6758 // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
6759 // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
6760 // 305–363 (1997).
6761 // Code adapted from GeographicLib by Charles F. F. Karney,
6762 // http://geographiclib.sourceforge.net/
6763
6764 function adder() {
6765 return new Adder;
6766 }
6767
6768 function Adder() {
6769 this.reset();
6770 }
6771
6772 Adder.prototype = {
6773 constructor: Adder,
6774 reset: function() {
6775 this.s = // rounded value
6776 this.t = 0; // exact error
6777 },
6778 add: function(y) {
6779 add$1(temp, y, this.t);
6780 add$1(this, temp.s, this.s);
6781 if (this.s) this.t += temp.t;
6782 else this.s = temp.t;
6783 },
6784 valueOf: function() {
6785 return this.s;
6786 }
6787 };
6788
6789 var temp = new Adder;
6790
6791 function add$1(adder, a, b) {
6792 var x = adder.s = a + b,
6793 bv = x - a,
6794 av = x - bv;
6795 adder.t = (a - av) + (b - bv);
6796 }
6797
6798 var epsilon$2 = 1e-6;
6799 var epsilon2$1 = 1e-12;
6800 var pi$3 = Math.PI;
6801 var halfPi$2 = pi$3 / 2;
6802 var quarterPi = pi$3 / 4;
6803 var tau$3 = pi$3 * 2;
6804
6805 var degrees$1 = 180 / pi$3;
6806 var radians = pi$3 / 180;
6807
6808 var abs = Math.abs;
6809 var atan = Math.atan;
6810 var atan2 = Math.atan2;
6811 var cos$1 = Math.cos;
6812 var ceil = Math.ceil;
6813 var exp = Math.exp;
6814
6815 var log = Math.log;
6816 var pow = Math.pow;
6817 var sin$1 = Math.sin;
6818 var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
6819 var sqrt = Math.sqrt;
6820 var tan = Math.tan;
6821
6822 function acos(x) {
6823 return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
6824 }
6825
6826 function asin(x) {
6827 return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
6828 }
6829
6830 function haversin(x) {
6831 return (x = sin$1(x / 2)) * x;
6832 }
6833
6834 function noop$1() {}
6835
6836 function streamGeometry(geometry, stream) {
6837 if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
6838 streamGeometryType[geometry.type](geometry, stream);
6839 }
6840 }
6841
6842 var streamObjectType = {
6843 Feature: function(object, stream) {
6844 streamGeometry(object.geometry, stream);
6845 },
6846 FeatureCollection: function(object, stream) {
6847 var features = object.features, i = -1, n = features.length;
6848 while (++i < n) streamGeometry(features[i].geometry, stream);
6849 }
6850 };
6851
6852 var streamGeometryType = {
6853 Sphere: function(object, stream) {
6854 stream.sphere();
6855 },
6856 Point: function(object, stream) {
6857 object = object.coordinates;
6858 stream.point(object[0], object[1], object[2]);
6859 },
6860 MultiPoint: function(object, stream) {
6861 var coordinates = object.coordinates, i = -1, n = coordinates.length;
6862 while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
6863 },
6864 LineString: function(object, stream) {
6865 streamLine(object.coordinates, stream, 0);
6866 },
6867 MultiLineString: function(object, stream) {
6868 var coordinates = object.coordinates, i = -1, n = coordinates.length;
6869 while (++i < n) streamLine(coordinates[i], stream, 0);
6870 },
6871 Polygon: function(object, stream) {
6872 streamPolygon(object.coordinates, stream);
6873 },
6874 MultiPolygon: function(object, stream) {
6875 var coordinates = object.coordinates, i = -1, n = coordinates.length;
6876 while (++i < n) streamPolygon(coordinates[i], stream);
6877 },
6878 GeometryCollection: function(object, stream) {
6879 var geometries = object.geometries, i = -1, n = geometries.length;
6880 while (++i < n) streamGeometry(geometries[i], stream);
6881 }
6882 };
6883
6884 function streamLine(coordinates, stream, closed) {
6885 var i = -1, n = coordinates.length - closed, coordinate;
6886 stream.lineStart();
6887 while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
6888 stream.lineEnd();
6889 }
6890
6891 function streamPolygon(coordinates, stream) {
6892 var i = -1, n = coordinates.length;
6893 stream.polygonStart();
6894 while (++i < n) streamLine(coordinates[i], stream, 1);
6895 stream.polygonEnd();
6896 }
6897
6898 function geoStream(object, stream) {
6899 if (object && streamObjectType.hasOwnProperty(object.type)) {
6900 streamObjectType[object.type](object, stream);
6901 } else {
6902 streamGeometry(object, stream);
6903 }
6904 }
6905
6906 var areaRingSum = adder();
6907
6908 var areaSum = adder();
6909 var lambda00;
6910 var phi00;
6911 var lambda0;
6912 var cosPhi0;
6913 var sinPhi0;
6914
6915 var areaStream = {
6916 point: noop$1,
6917 lineStart: noop$1,
6918 lineEnd: noop$1,
6919 polygonStart: function() {
6920 areaRingSum.reset();
6921 areaStream.lineStart = areaRingStart;
6922 areaStream.lineEnd = areaRingEnd;
6923 },
6924 polygonEnd: function() {
6925 var areaRing = +areaRingSum;
6926 areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
6927 this.lineStart = this.lineEnd = this.point = noop$1;
6928 },
6929 sphere: function() {
6930 areaSum.add(tau$3);
6931 }
6932 };
6933
6934 function areaRingStart() {
6935 areaStream.point = areaPointFirst;
6936 }
6937
6938 function areaRingEnd() {
6939 areaPoint(lambda00, phi00);
6940 }
6941
6942 function areaPointFirst(lambda, phi) {
6943 areaStream.point = areaPoint;
6944 lambda00 = lambda, phi00 = phi;
6945 lambda *= radians, phi *= radians;
6946 lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
6947 }
6948
6949 function areaPoint(lambda, phi) {
6950 lambda *= radians, phi *= radians;
6951 phi = phi / 2 + quarterPi; // half the angular distance from south pole
6952
6953 // Spherical excess E for a spherical triangle with vertices: south pole,
6954 // previous point, current point. Uses a formula derived from Cagnoli’s
6955 // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
6956 var dLambda = lambda - lambda0,
6957 sdLambda = dLambda >= 0 ? 1 : -1,
6958 adLambda = sdLambda * dLambda,
6959 cosPhi = cos$1(phi),
6960 sinPhi = sin$1(phi),
6961 k = sinPhi0 * sinPhi,
6962 u = cosPhi0 * cosPhi + k * cos$1(adLambda),
6963 v = k * sdLambda * sin$1(adLambda);
6964 areaRingSum.add(atan2(v, u));
6965
6966 // Advance the previous points.
6967 lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
6968 }
6969
6970 function area(object) {
6971 areaSum.reset();
6972 geoStream(object, areaStream);
6973 return areaSum * 2;
6974 }
6975
6976 function spherical(cartesian) {
6977 return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
6978 }
6979
6980 function cartesian(spherical) {
6981 var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
6982 return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
6983 }
6984
6985 function cartesianDot(a, b) {
6986 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
6987 }
6988
6989 function cartesianCross(a, b) {
6990 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]];
6991 }
6992
6993 // TODO return a
6994 function cartesianAddInPlace(a, b) {
6995 a[0] += b[0], a[1] += b[1], a[2] += b[2];
6996 }
6997
6998 function cartesianScale(vector, k) {
6999 return [vector[0] * k, vector[1] * k, vector[2] * k];
7000 }
7001
7002 // TODO return d
7003 function cartesianNormalizeInPlace(d) {
7004 var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
7005 d[0] /= l, d[1] /= l, d[2] /= l;
7006 }
7007
7008 var lambda0$1;
7009 var phi0;
7010 var lambda1;
7011 var phi1;
7012 var lambda2;
7013 var lambda00$1;
7014 var phi00$1;
7015 var p0;
7016 var deltaSum = adder();
7017 var ranges;
7018 var range;
7019
7020 var boundsStream = {
7021 point: boundsPoint,
7022 lineStart: boundsLineStart,
7023 lineEnd: boundsLineEnd,
7024 polygonStart: function() {
7025 boundsStream.point = boundsRingPoint;
7026 boundsStream.lineStart = boundsRingStart;
7027 boundsStream.lineEnd = boundsRingEnd;
7028 deltaSum.reset();
7029 areaStream.polygonStart();
7030 },
7031 polygonEnd: function() {
7032 areaStream.polygonEnd();
7033 boundsStream.point = boundsPoint;
7034 boundsStream.lineStart = boundsLineStart;
7035 boundsStream.lineEnd = boundsLineEnd;
7036 if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
7037 else if (deltaSum > epsilon$2) phi1 = 90;
7038 else if (deltaSum < -epsilon$2) phi0 = -90;
7039 range[0] = lambda0$1, range[1] = lambda1;
7040 }
7041 };
7042
7043 function boundsPoint(lambda, phi) {
7044 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7045 if (phi < phi0) phi0 = phi;
7046 if (phi > phi1) phi1 = phi;
7047 }
7048
7049 function linePoint(lambda, phi) {
7050 var p = cartesian([lambda * radians, phi * radians]);
7051 if (p0) {
7052 var normal = cartesianCross(p0, p),
7053 equatorial = [normal[1], -normal[0], 0],
7054 inflection = cartesianCross(equatorial, normal);
7055 cartesianNormalizeInPlace(inflection);
7056 inflection = spherical(inflection);
7057 var delta = lambda - lambda2,
7058 sign$$1 = delta > 0 ? 1 : -1,
7059 lambdai = inflection[0] * degrees$1 * sign$$1,
7060 phii,
7061 antimeridian = abs(delta) > 180;
7062 if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7063 phii = inflection[1] * degrees$1;
7064 if (phii > phi1) phi1 = phii;
7065 } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7066 phii = -inflection[1] * degrees$1;
7067 if (phii < phi0) phi0 = phii;
7068 } else {
7069 if (phi < phi0) phi0 = phi;
7070 if (phi > phi1) phi1 = phi;
7071 }
7072 if (antimeridian) {
7073 if (lambda < lambda2) {
7074 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7075 } else {
7076 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7077 }
7078 } else {
7079 if (lambda1 >= lambda0$1) {
7080 if (lambda < lambda0$1) lambda0$1 = lambda;
7081 if (lambda > lambda1) lambda1 = lambda;
7082 } else {
7083 if (lambda > lambda2) {
7084 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7085 } else {
7086 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7087 }
7088 }
7089 }
7090 } else {
7091 ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7092 }
7093 if (phi < phi0) phi0 = phi;
7094 if (phi > phi1) phi1 = phi;
7095 p0 = p, lambda2 = lambda;
7096 }
7097
7098 function boundsLineStart() {
7099 boundsStream.point = linePoint;
7100 }
7101
7102 function boundsLineEnd() {
7103 range[0] = lambda0$1, range[1] = lambda1;
7104 boundsStream.point = boundsPoint;
7105 p0 = null;
7106 }
7107
7108 function boundsRingPoint(lambda, phi) {
7109 if (p0) {
7110 var delta = lambda - lambda2;
7111 deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
7112 } else {
7113 lambda00$1 = lambda, phi00$1 = phi;
7114 }
7115 areaStream.point(lambda, phi);
7116 linePoint(lambda, phi);
7117 }
7118
7119 function boundsRingStart() {
7120 areaStream.lineStart();
7121 }
7122
7123 function boundsRingEnd() {
7124 boundsRingPoint(lambda00$1, phi00$1);
7125 areaStream.lineEnd();
7126 if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
7127 range[0] = lambda0$1, range[1] = lambda1;
7128 p0 = null;
7129 }
7130
7131 // Finds the left-right distance between two longitudes.
7132 // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
7133 // the distance between ±180° to be 360°.
7134 function angle(lambda0, lambda1) {
7135 return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
7136 }
7137
7138 function rangeCompare(a, b) {
7139 return a[0] - b[0];
7140 }
7141
7142 function rangeContains(range, x) {
7143 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
7144 }
7145
7146 function bounds(feature) {
7147 var i, n, a, b, merged, deltaMax, delta;
7148
7149 phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
7150 ranges = [];
7151 geoStream(feature, boundsStream);
7152
7153 // First, sort ranges by their minimum longitudes.
7154 if (n = ranges.length) {
7155 ranges.sort(rangeCompare);
7156
7157 // Then, merge any ranges that overlap.
7158 for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
7159 b = ranges[i];
7160 if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
7161 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
7162 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
7163 } else {
7164 merged.push(a = b);
7165 }
7166 }
7167
7168 // Finally, find the largest gap between the merged ranges.
7169 // The final bounding box will be the inverse of this gap.
7170 for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
7171 b = merged[i];
7172 if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
7173 }
7174 }
7175
7176 ranges = range = null;
7177
7178 return lambda0$1 === Infinity || phi0 === Infinity
7179 ? [[NaN, NaN], [NaN, NaN]]
7180 : [[lambda0$1, phi0], [lambda1, phi1]];
7181 }
7182
7183 var W0;
7184 var W1;
7185 var X0;
7186 var Y0;
7187 var Z0;
7188 var X1;
7189 var Y1;
7190 var Z1;
7191 var X2;
7192 var Y2;
7193 var Z2;
7194 var lambda00$2;
7195 var phi00$2;
7196 var x0;
7197 var y0;
7198 var z0; // previous point
7199
7200 var centroidStream = {
7201 sphere: noop$1,
7202 point: centroidPoint,
7203 lineStart: centroidLineStart,
7204 lineEnd: centroidLineEnd,
7205 polygonStart: function() {
7206 centroidStream.lineStart = centroidRingStart;
7207 centroidStream.lineEnd = centroidRingEnd;
7208 },
7209 polygonEnd: function() {
7210 centroidStream.lineStart = centroidLineStart;
7211 centroidStream.lineEnd = centroidLineEnd;
7212 }
7213 };
7214
7215 // Arithmetic mean of Cartesian vectors.
7216 function centroidPoint(lambda, phi) {
7217 lambda *= radians, phi *= radians;
7218 var cosPhi = cos$1(phi);
7219 centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
7220 }
7221
7222 function centroidPointCartesian(x, y, z) {
7223 ++W0;
7224 X0 += (x - X0) / W0;
7225 Y0 += (y - Y0) / W0;
7226 Z0 += (z - Z0) / W0;
7227 }
7228
7229 function centroidLineStart() {
7230 centroidStream.point = centroidLinePointFirst;
7231 }
7232
7233 function centroidLinePointFirst(lambda, phi) {
7234 lambda *= radians, phi *= radians;
7235 var cosPhi = cos$1(phi);
7236 x0 = cosPhi * cos$1(lambda);
7237 y0 = cosPhi * sin$1(lambda);
7238 z0 = sin$1(phi);
7239 centroidStream.point = centroidLinePoint;
7240 centroidPointCartesian(x0, y0, z0);
7241 }
7242
7243 function centroidLinePoint(lambda, phi) {
7244 lambda *= radians, phi *= radians;
7245 var cosPhi = cos$1(phi),
7246 x = cosPhi * cos$1(lambda),
7247 y = cosPhi * sin$1(lambda),
7248 z = sin$1(phi),
7249 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);
7250 W1 += w;
7251 X1 += w * (x0 + (x0 = x));
7252 Y1 += w * (y0 + (y0 = y));
7253 Z1 += w * (z0 + (z0 = z));
7254 centroidPointCartesian(x0, y0, z0);
7255 }
7256
7257 function centroidLineEnd() {
7258 centroidStream.point = centroidPoint;
7259 }
7260
7261 // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
7262 // J. Applied Mechanics 42, 239 (1975).
7263 function centroidRingStart() {
7264 centroidStream.point = centroidRingPointFirst;
7265 }
7266
7267 function centroidRingEnd() {
7268 centroidRingPoint(lambda00$2, phi00$2);
7269 centroidStream.point = centroidPoint;
7270 }
7271
7272 function centroidRingPointFirst(lambda, phi) {
7273 lambda00$2 = lambda, phi00$2 = phi;
7274 lambda *= radians, phi *= radians;
7275 centroidStream.point = centroidRingPoint;
7276 var cosPhi = cos$1(phi);
7277 x0 = cosPhi * cos$1(lambda);
7278 y0 = cosPhi * sin$1(lambda);
7279 z0 = sin$1(phi);
7280 centroidPointCartesian(x0, y0, z0);
7281 }
7282
7283 function centroidRingPoint(lambda, phi) {
7284 lambda *= radians, phi *= radians;
7285 var cosPhi = cos$1(phi),
7286 x = cosPhi * cos$1(lambda),
7287 y = cosPhi * sin$1(lambda),
7288 z = sin$1(phi),
7289 cx = y0 * z - z0 * y,
7290 cy = z0 * x - x0 * z,
7291 cz = x0 * y - y0 * x,
7292 m = sqrt(cx * cx + cy * cy + cz * cz),
7293 w = asin(m), // line weight = angle
7294 v = m && -w / m; // area weight multiplier
7295 X2 += v * cx;
7296 Y2 += v * cy;
7297 Z2 += v * cz;
7298 W1 += w;
7299 X1 += w * (x0 + (x0 = x));
7300 Y1 += w * (y0 + (y0 = y));
7301 Z1 += w * (z0 + (z0 = z));
7302 centroidPointCartesian(x0, y0, z0);
7303 }
7304
7305 function centroid(object) {
7306 W0 = W1 =
7307 X0 = Y0 = Z0 =
7308 X1 = Y1 = Z1 =
7309 X2 = Y2 = Z2 = 0;
7310 geoStream(object, centroidStream);
7311
7312 var x = X2,
7313 y = Y2,
7314 z = Z2,
7315 m = x * x + y * y + z * z;
7316
7317 // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
7318 if (m < epsilon2$1) {
7319 x = X1, y = Y1, z = Z1;
7320 // If the feature has zero length, fall back to arithmetic mean of point vectors.
7321 if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
7322 m = x * x + y * y + z * z;
7323 // If the feature still has an undefined ccentroid, then return.
7324 if (m < epsilon2$1) return [NaN, NaN];
7325 }
7326
7327 return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
7328 }
7329
7330 function constant$7(x) {
7331 return function() {
7332 return x;
7333 };
7334 }
7335
7336 function compose(a, b) {
7337
7338 function compose(x, y) {
7339 return x = a(x, y), b(x[0], x[1]);
7340 }
7341
7342 if (a.invert && b.invert) compose.invert = function(x, y) {
7343 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
7344 };
7345
7346 return compose;
7347 }
7348
7349 function rotationIdentity(lambda, phi) {
7350 return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7351 }
7352
7353 rotationIdentity.invert = rotationIdentity;
7354
7355 function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
7356 return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
7357 : rotationLambda(deltaLambda))
7358 : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
7359 : rotationIdentity);
7360 }
7361
7362 function forwardRotationLambda(deltaLambda) {
7363 return function(lambda, phi) {
7364 return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7365 };
7366 }
7367
7368 function rotationLambda(deltaLambda) {
7369 var rotation = forwardRotationLambda(deltaLambda);
7370 rotation.invert = forwardRotationLambda(-deltaLambda);
7371 return rotation;
7372 }
7373
7374 function rotationPhiGamma(deltaPhi, deltaGamma) {
7375 var cosDeltaPhi = cos$1(deltaPhi),
7376 sinDeltaPhi = sin$1(deltaPhi),
7377 cosDeltaGamma = cos$1(deltaGamma),
7378 sinDeltaGamma = sin$1(deltaGamma);
7379
7380 function rotation(lambda, phi) {
7381 var cosPhi = cos$1(phi),
7382 x = cos$1(lambda) * cosPhi,
7383 y = sin$1(lambda) * cosPhi,
7384 z = sin$1(phi),
7385 k = z * cosDeltaPhi + x * sinDeltaPhi;
7386 return [
7387 atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
7388 asin(k * cosDeltaGamma + y * sinDeltaGamma)
7389 ];
7390 }
7391
7392 rotation.invert = function(lambda, phi) {
7393 var cosPhi = cos$1(phi),
7394 x = cos$1(lambda) * cosPhi,
7395 y = sin$1(lambda) * cosPhi,
7396 z = sin$1(phi),
7397 k = z * cosDeltaGamma - y * sinDeltaGamma;
7398 return [
7399 atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
7400 asin(k * cosDeltaPhi - x * sinDeltaPhi)
7401 ];
7402 };
7403
7404 return rotation;
7405 }
7406
7407 function rotation(rotate) {
7408 rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
7409
7410 function forward(coordinates) {
7411 coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
7412 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7413 }
7414
7415 forward.invert = function(coordinates) {
7416 coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
7417 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7418 };
7419
7420 return forward;
7421 }
7422
7423 // Generates a circle centered at [0°, 0°], with a given radius and precision.
7424 function circleStream(stream, radius, delta, direction, t0, t1) {
7425 if (!delta) return;
7426 var cosRadius = cos$1(radius),
7427 sinRadius = sin$1(radius),
7428 step = direction * delta;
7429 if (t0 == null) {
7430 t0 = radius + direction * tau$3;
7431 t1 = radius - step / 2;
7432 } else {
7433 t0 = circleRadius(cosRadius, t0);
7434 t1 = circleRadius(cosRadius, t1);
7435 if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
7436 }
7437 for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
7438 point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
7439 stream.point(point[0], point[1]);
7440 }
7441 }
7442
7443 // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
7444 function circleRadius(cosRadius, point) {
7445 point = cartesian(point), point[0] -= cosRadius;
7446 cartesianNormalizeInPlace(point);
7447 var radius = acos(-point[1]);
7448 return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
7449 }
7450
7451 function circle() {
7452 var center = constant$7([0, 0]),
7453 radius = constant$7(90),
7454 precision = constant$7(6),
7455 ring,
7456 rotate,
7457 stream = {point: point};
7458
7459 function point(x, y) {
7460 ring.push(x = rotate(x, y));
7461 x[0] *= degrees$1, x[1] *= degrees$1;
7462 }
7463
7464 function circle() {
7465 var c = center.apply(this, arguments),
7466 r = radius.apply(this, arguments) * radians,
7467 p = precision.apply(this, arguments) * radians;
7468 ring = [];
7469 rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
7470 circleStream(stream, r, p, 1);
7471 c = {type: "Polygon", coordinates: [ring]};
7472 ring = rotate = null;
7473 return c;
7474 }
7475
7476 circle.center = function(_) {
7477 return arguments.length ? (center = typeof _ === "function" ? _ : constant$7([+_[0], +_[1]]), circle) : center;
7478 };
7479
7480 circle.radius = function(_) {
7481 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), circle) : radius;
7482 };
7483
7484 circle.precision = function(_) {
7485 return arguments.length ? (precision = typeof _ === "function" ? _ : constant$7(+_), circle) : precision;
7486 };
7487
7488 return circle;
7489 }
7490
7491 function clipBuffer() {
7492 var lines = [],
7493 line;
7494 return {
7495 point: function(x, y) {
7496 line.push([x, y]);
7497 },
7498 lineStart: function() {
7499 lines.push(line = []);
7500 },
7501 lineEnd: noop$1,
7502 rejoin: function() {
7503 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
7504 },
7505 result: function() {
7506 var result = lines;
7507 lines = [];
7508 line = null;
7509 return result;
7510 }
7511 };
7512 }
7513
7514 function pointEqual(a, b) {
7515 return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
7516 }
7517
7518 function Intersection(point, points, other, entry) {
7519 this.x = point;
7520 this.z = points;
7521 this.o = other; // another intersection
7522 this.e = entry; // is an entry?
7523 this.v = false; // visited
7524 this.n = this.p = null; // next & previous
7525 }
7526
7527 // A generalized polygon clipping algorithm: given a polygon that has been cut
7528 // into its visible line segments, and rejoins the segments by interpolating
7529 // along the clip edge.
7530 function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
7531 var subject = [],
7532 clip = [],
7533 i,
7534 n;
7535
7536 segments.forEach(function(segment) {
7537 if ((n = segment.length - 1) <= 0) return;
7538 var n, p0 = segment[0], p1 = segment[n], x;
7539
7540 // If the first and last points of a segment are coincident, then treat as a
7541 // closed ring. TODO if all rings are closed, then the winding order of the
7542 // exterior ring should be checked.
7543 if (pointEqual(p0, p1)) {
7544 stream.lineStart();
7545 for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
7546 stream.lineEnd();
7547 return;
7548 }
7549
7550 subject.push(x = new Intersection(p0, segment, null, true));
7551 clip.push(x.o = new Intersection(p0, null, x, false));
7552 subject.push(x = new Intersection(p1, segment, null, false));
7553 clip.push(x.o = new Intersection(p1, null, x, true));
7554 });
7555
7556 if (!subject.length) return;
7557
7558 clip.sort(compareIntersection);
7559 link$1(subject);
7560 link$1(clip);
7561
7562 for (i = 0, n = clip.length; i < n; ++i) {
7563 clip[i].e = startInside = !startInside;
7564 }
7565
7566 var start = subject[0],
7567 points,
7568 point;
7569
7570 while (1) {
7571 // Find first unvisited intersection.
7572 var current = start,
7573 isSubject = true;
7574 while (current.v) if ((current = current.n) === start) return;
7575 points = current.z;
7576 stream.lineStart();
7577 do {
7578 current.v = current.o.v = true;
7579 if (current.e) {
7580 if (isSubject) {
7581 for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
7582 } else {
7583 interpolate(current.x, current.n.x, 1, stream);
7584 }
7585 current = current.n;
7586 } else {
7587 if (isSubject) {
7588 points = current.p.z;
7589 for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
7590 } else {
7591 interpolate(current.x, current.p.x, -1, stream);
7592 }
7593 current = current.p;
7594 }
7595 current = current.o;
7596 points = current.z;
7597 isSubject = !isSubject;
7598 } while (!current.v);
7599 stream.lineEnd();
7600 }
7601 }
7602
7603 function link$1(array) {
7604 if (!(n = array.length)) return;
7605 var n,
7606 i = 0,
7607 a = array[0],
7608 b;
7609 while (++i < n) {
7610 a.n = b = array[i];
7611 b.p = a;
7612 a = b;
7613 }
7614 a.n = b = array[0];
7615 b.p = a;
7616 }
7617
7618 var sum$1 = adder();
7619
7620 function polygonContains(polygon, point) {
7621 var lambda = point[0],
7622 phi = point[1],
7623 normal = [sin$1(lambda), -cos$1(lambda), 0],
7624 angle = 0,
7625 winding = 0;
7626
7627 sum$1.reset();
7628
7629 for (var i = 0, n = polygon.length; i < n; ++i) {
7630 if (!(m = (ring = polygon[i]).length)) continue;
7631 var ring,
7632 m,
7633 point0 = ring[m - 1],
7634 lambda0 = point0[0],
7635 phi0 = point0[1] / 2 + quarterPi,
7636 sinPhi0 = sin$1(phi0),
7637 cosPhi0 = cos$1(phi0);
7638
7639 for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
7640 var point1 = ring[j],
7641 lambda1 = point1[0],
7642 phi1 = point1[1] / 2 + quarterPi,
7643 sinPhi1 = sin$1(phi1),
7644 cosPhi1 = cos$1(phi1),
7645 delta = lambda1 - lambda0,
7646 sign$$1 = delta >= 0 ? 1 : -1,
7647 absDelta = sign$$1 * delta,
7648 antimeridian = absDelta > pi$3,
7649 k = sinPhi0 * sinPhi1;
7650
7651 sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
7652 angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
7653
7654 // Are the longitudes either side of the point’s meridian (lambda),
7655 // and are the latitudes smaller than the parallel (phi)?
7656 if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
7657 var arc = cartesianCross(cartesian(point0), cartesian(point1));
7658 cartesianNormalizeInPlace(arc);
7659 var intersection = cartesianCross(normal, arc);
7660 cartesianNormalizeInPlace(intersection);
7661 var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
7662 if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
7663 winding += antimeridian ^ delta >= 0 ? 1 : -1;
7664 }
7665 }
7666 }
7667 }
7668
7669 // First, determine whether the South pole is inside or outside:
7670 //
7671 // It is inside if:
7672 // * the polygon winds around it in a clockwise direction.
7673 // * the polygon does not (cumulatively) wind around it, but has a negative
7674 // (counter-clockwise) area.
7675 //
7676 // Second, count the (signed) number of times a segment crosses a lambda
7677 // from the point to the South pole. If it is zero, then the point is the
7678 // same side as the South pole.
7679
7680 return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
7681 }
7682
7683 function clip(pointVisible, clipLine, interpolate, start) {
7684 return function(sink) {
7685 var line = clipLine(sink),
7686 ringBuffer = clipBuffer(),
7687 ringSink = clipLine(ringBuffer),
7688 polygonStarted = false,
7689 polygon,
7690 segments,
7691 ring;
7692
7693 var clip = {
7694 point: point,
7695 lineStart: lineStart,
7696 lineEnd: lineEnd,
7697 polygonStart: function() {
7698 clip.point = pointRing;
7699 clip.lineStart = ringStart;
7700 clip.lineEnd = ringEnd;
7701 segments = [];
7702 polygon = [];
7703 },
7704 polygonEnd: function() {
7705 clip.point = point;
7706 clip.lineStart = lineStart;
7707 clip.lineEnd = lineEnd;
7708 segments = merge(segments);
7709 var startInside = polygonContains(polygon, start);
7710 if (segments.length) {
7711 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
7712 clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
7713 } else if (startInside) {
7714 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
7715 sink.lineStart();
7716 interpolate(null, null, 1, sink);
7717 sink.lineEnd();
7718 }
7719 if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
7720 segments = polygon = null;
7721 },
7722 sphere: function() {
7723 sink.polygonStart();
7724 sink.lineStart();
7725 interpolate(null, null, 1, sink);
7726 sink.lineEnd();
7727 sink.polygonEnd();
7728 }
7729 };
7730
7731 function point(lambda, phi) {
7732 if (pointVisible(lambda, phi)) sink.point(lambda, phi);
7733 }
7734
7735 function pointLine(lambda, phi) {
7736 line.point(lambda, phi);
7737 }
7738
7739 function lineStart() {
7740 clip.point = pointLine;
7741 line.lineStart();
7742 }
7743
7744 function lineEnd() {
7745 clip.point = point;
7746 line.lineEnd();
7747 }
7748
7749 function pointRing(lambda, phi) {
7750 ring.push([lambda, phi]);
7751 ringSink.point(lambda, phi);
7752 }
7753
7754 function ringStart() {
7755 ringSink.lineStart();
7756 ring = [];
7757 }
7758
7759 function ringEnd() {
7760 pointRing(ring[0][0], ring[0][1]);
7761 ringSink.lineEnd();
7762
7763 var clean = ringSink.clean(),
7764 ringSegments = ringBuffer.result(),
7765 i, n = ringSegments.length, m,
7766 segment,
7767 point;
7768
7769 ring.pop();
7770 polygon.push(ring);
7771 ring = null;
7772
7773 if (!n) return;
7774
7775 // No intersections.
7776 if (clean & 1) {
7777 segment = ringSegments[0];
7778 if ((m = segment.length - 1) > 0) {
7779 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
7780 sink.lineStart();
7781 for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
7782 sink.lineEnd();
7783 }
7784 return;
7785 }
7786
7787 // Rejoin connected segments.
7788 // TODO reuse ringBuffer.rejoin()?
7789 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
7790
7791 segments.push(ringSegments.filter(validSegment));
7792 }
7793
7794 return clip;
7795 };
7796 }
7797
7798 function validSegment(segment) {
7799 return segment.length > 1;
7800 }
7801
7802 // Intersections are sorted along the clip edge. For both antimeridian cutting
7803 // and circle clipping, the same comparison is used.
7804 function compareIntersection(a, b) {
7805 return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
7806 - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
7807 }
7808
7809 var clipAntimeridian = clip(
7810 function() { return true; },
7811 clipAntimeridianLine,
7812 clipAntimeridianInterpolate,
7813 [-pi$3, -halfPi$2]
7814 );
7815
7816 // Takes a line and cuts into visible segments. Return values: 0 - there were
7817 // intersections or the line was empty; 1 - no intersections; 2 - there were
7818 // intersections, and the first and last segments should be rejoined.
7819 function clipAntimeridianLine(stream) {
7820 var lambda0 = NaN,
7821 phi0 = NaN,
7822 sign0 = NaN,
7823 clean; // no intersections
7824
7825 return {
7826 lineStart: function() {
7827 stream.lineStart();
7828 clean = 1;
7829 },
7830 point: function(lambda1, phi1) {
7831 var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
7832 delta = abs(lambda1 - lambda0);
7833 if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
7834 stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
7835 stream.point(sign0, phi0);
7836 stream.lineEnd();
7837 stream.lineStart();
7838 stream.point(sign1, phi0);
7839 stream.point(lambda1, phi0);
7840 clean = 0;
7841 } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
7842 if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
7843 if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
7844 phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
7845 stream.point(sign0, phi0);
7846 stream.lineEnd();
7847 stream.lineStart();
7848 stream.point(sign1, phi0);
7849 clean = 0;
7850 }
7851 stream.point(lambda0 = lambda1, phi0 = phi1);
7852 sign0 = sign1;
7853 },
7854 lineEnd: function() {
7855 stream.lineEnd();
7856 lambda0 = phi0 = NaN;
7857 },
7858 clean: function() {
7859 return 2 - clean; // if intersections, rejoin first and last segments
7860 }
7861 };
7862 }
7863
7864 function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
7865 var cosPhi0,
7866 cosPhi1,
7867 sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
7868 return abs(sinLambda0Lambda1) > epsilon$2
7869 ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
7870 - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
7871 / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
7872 : (phi0 + phi1) / 2;
7873 }
7874
7875 function clipAntimeridianInterpolate(from, to, direction, stream) {
7876 var phi;
7877 if (from == null) {
7878 phi = direction * halfPi$2;
7879 stream.point(-pi$3, phi);
7880 stream.point(0, phi);
7881 stream.point(pi$3, phi);
7882 stream.point(pi$3, 0);
7883 stream.point(pi$3, -phi);
7884 stream.point(0, -phi);
7885 stream.point(-pi$3, -phi);
7886 stream.point(-pi$3, 0);
7887 stream.point(-pi$3, phi);
7888 } else if (abs(from[0] - to[0]) > epsilon$2) {
7889 var lambda = from[0] < to[0] ? pi$3 : -pi$3;
7890 phi = direction * lambda / 2;
7891 stream.point(-lambda, phi);
7892 stream.point(0, phi);
7893 stream.point(lambda, phi);
7894 } else {
7895 stream.point(to[0], to[1]);
7896 }
7897 }
7898
7899 function clipCircle(radius) {
7900 var cr = cos$1(radius),
7901 delta = 6 * radians,
7902 smallRadius = cr > 0,
7903 notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
7904
7905 function interpolate(from, to, direction, stream) {
7906 circleStream(stream, radius, delta, direction, from, to);
7907 }
7908
7909 function visible(lambda, phi) {
7910 return cos$1(lambda) * cos$1(phi) > cr;
7911 }
7912
7913 // Takes a line and cuts into visible segments. Return values used for polygon
7914 // clipping: 0 - there were intersections or the line was empty; 1 - no
7915 // intersections 2 - there were intersections, and the first and last segments
7916 // should be rejoined.
7917 function clipLine(stream) {
7918 var point0, // previous point
7919 c0, // code for previous point
7920 v0, // visibility of previous point
7921 v00, // visibility of first point
7922 clean; // no intersections
7923 return {
7924 lineStart: function() {
7925 v00 = v0 = false;
7926 clean = 1;
7927 },
7928 point: function(lambda, phi) {
7929 var point1 = [lambda, phi],
7930 point2,
7931 v = visible(lambda, phi),
7932 c = smallRadius
7933 ? v ? 0 : code(lambda, phi)
7934 : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
7935 if (!point0 && (v00 = v0 = v)) stream.lineStart();
7936 // Handle degeneracies.
7937 // TODO ignore if not clipping polygons.
7938 if (v !== v0) {
7939 point2 = intersect(point0, point1);
7940 if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
7941 point1[0] += epsilon$2;
7942 point1[1] += epsilon$2;
7943 v = visible(point1[0], point1[1]);
7944 }
7945 }
7946 if (v !== v0) {
7947 clean = 0;
7948 if (v) {
7949 // outside going in
7950 stream.lineStart();
7951 point2 = intersect(point1, point0);
7952 stream.point(point2[0], point2[1]);
7953 } else {
7954 // inside going out
7955 point2 = intersect(point0, point1);
7956 stream.point(point2[0], point2[1]);
7957 stream.lineEnd();
7958 }
7959 point0 = point2;
7960 } else if (notHemisphere && point0 && smallRadius ^ v) {
7961 var t;
7962 // If the codes for two points are different, or are both zero,
7963 // and there this segment intersects with the small circle.
7964 if (!(c & c0) && (t = intersect(point1, point0, true))) {
7965 clean = 0;
7966 if (smallRadius) {
7967 stream.lineStart();
7968 stream.point(t[0][0], t[0][1]);
7969 stream.point(t[1][0], t[1][1]);
7970 stream.lineEnd();
7971 } else {
7972 stream.point(t[1][0], t[1][1]);
7973 stream.lineEnd();
7974 stream.lineStart();
7975 stream.point(t[0][0], t[0][1]);
7976 }
7977 }
7978 }
7979 if (v && (!point0 || !pointEqual(point0, point1))) {
7980 stream.point(point1[0], point1[1]);
7981 }
7982 point0 = point1, v0 = v, c0 = c;
7983 },
7984 lineEnd: function() {
7985 if (v0) stream.lineEnd();
7986 point0 = null;
7987 },
7988 // Rejoin first and last segments if there were intersections and the first
7989 // and last points were visible.
7990 clean: function() {
7991 return clean | ((v00 && v0) << 1);
7992 }
7993 };
7994 }
7995
7996 // Intersects the great circle between a and b with the clip circle.
7997 function intersect(a, b, two) {
7998 var pa = cartesian(a),
7999 pb = cartesian(b);
8000
8001 // We have two planes, n1.p = d1 and n2.p = d2.
8002 // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
8003 var n1 = [1, 0, 0], // normal
8004 n2 = cartesianCross(pa, pb),
8005 n2n2 = cartesianDot(n2, n2),
8006 n1n2 = n2[0], // cartesianDot(n1, n2),
8007 determinant = n2n2 - n1n2 * n1n2;
8008
8009 // Two polar points.
8010 if (!determinant) return !two && a;
8011
8012 var c1 = cr * n2n2 / determinant,
8013 c2 = -cr * n1n2 / determinant,
8014 n1xn2 = cartesianCross(n1, n2),
8015 A = cartesianScale(n1, c1),
8016 B = cartesianScale(n2, c2);
8017 cartesianAddInPlace(A, B);
8018
8019 // Solve |p(t)|^2 = 1.
8020 var u = n1xn2,
8021 w = cartesianDot(A, u),
8022 uu = cartesianDot(u, u),
8023 t2 = w * w - uu * (cartesianDot(A, A) - 1);
8024
8025 if (t2 < 0) return;
8026
8027 var t = sqrt(t2),
8028 q = cartesianScale(u, (-w - t) / uu);
8029 cartesianAddInPlace(q, A);
8030 q = spherical(q);
8031
8032 if (!two) return q;
8033
8034 // Two intersection points.
8035 var lambda0 = a[0],
8036 lambda1 = b[0],
8037 phi0 = a[1],
8038 phi1 = b[1],
8039 z;
8040
8041 if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
8042
8043 var delta = lambda1 - lambda0,
8044 polar = abs(delta - pi$3) < epsilon$2,
8045 meridian = polar || delta < epsilon$2;
8046
8047 if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
8048
8049 // Check that the first point is between a and b.
8050 if (meridian
8051 ? polar
8052 ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
8053 : phi0 <= q[1] && q[1] <= phi1
8054 : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
8055 var q1 = cartesianScale(u, (-w + t) / uu);
8056 cartesianAddInPlace(q1, A);
8057 return [q, spherical(q1)];
8058 }
8059 }
8060
8061 // Generates a 4-bit vector representing the location of a point relative to
8062 // the small circle's bounding box.
8063 function code(lambda, phi) {
8064 var r = smallRadius ? radius : pi$3 - radius,
8065 code = 0;
8066 if (lambda < -r) code |= 1; // left
8067 else if (lambda > r) code |= 2; // right
8068 if (phi < -r) code |= 4; // below
8069 else if (phi > r) code |= 8; // above
8070 return code;
8071 }
8072
8073 return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
8074 }
8075
8076 function clipLine(a, b, x0, y0, x1, y1) {
8077 var ax = a[0],
8078 ay = a[1],
8079 bx = b[0],
8080 by = b[1],
8081 t0 = 0,
8082 t1 = 1,
8083 dx = bx - ax,
8084 dy = by - ay,
8085 r;
8086
8087 r = x0 - ax;
8088 if (!dx && r > 0) return;
8089 r /= dx;
8090 if (dx < 0) {
8091 if (r < t0) return;
8092 if (r < t1) t1 = r;
8093 } else if (dx > 0) {
8094 if (r > t1) return;
8095 if (r > t0) t0 = r;
8096 }
8097
8098 r = x1 - ax;
8099 if (!dx && r < 0) return;
8100 r /= dx;
8101 if (dx < 0) {
8102 if (r > t1) return;
8103 if (r > t0) t0 = r;
8104 } else if (dx > 0) {
8105 if (r < t0) return;
8106 if (r < t1) t1 = r;
8107 }
8108
8109 r = y0 - ay;
8110 if (!dy && r > 0) return;
8111 r /= dy;
8112 if (dy < 0) {
8113 if (r < t0) return;
8114 if (r < t1) t1 = r;
8115 } else if (dy > 0) {
8116 if (r > t1) return;
8117 if (r > t0) t0 = r;
8118 }
8119
8120 r = y1 - ay;
8121 if (!dy && r < 0) return;
8122 r /= dy;
8123 if (dy < 0) {
8124 if (r > t1) return;
8125 if (r > t0) t0 = r;
8126 } else if (dy > 0) {
8127 if (r < t0) return;
8128 if (r < t1) t1 = r;
8129 }
8130
8131 if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
8132 if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
8133 return true;
8134 }
8135
8136 var clipMax = 1e9;
8137 var clipMin = -clipMax;
8138
8139 // TODO Use d3-polygon’s polygonContains here for the ring check?
8140 // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
8141
8142 function clipRectangle(x0, y0, x1, y1) {
8143
8144 function visible(x, y) {
8145 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
8146 }
8147
8148 function interpolate(from, to, direction, stream) {
8149 var a = 0, a1 = 0;
8150 if (from == null
8151 || (a = corner(from, direction)) !== (a1 = corner(to, direction))
8152 || comparePoint(from, to) < 0 ^ direction > 0) {
8153 do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
8154 while ((a = (a + direction + 4) % 4) !== a1);
8155 } else {
8156 stream.point(to[0], to[1]);
8157 }
8158 }
8159
8160 function corner(p, direction) {
8161 return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
8162 : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
8163 : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
8164 : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
8165 }
8166
8167 function compareIntersection(a, b) {
8168 return comparePoint(a.x, b.x);
8169 }
8170
8171 function comparePoint(a, b) {
8172 var ca = corner(a, 1),
8173 cb = corner(b, 1);
8174 return ca !== cb ? ca - cb
8175 : ca === 0 ? b[1] - a[1]
8176 : ca === 1 ? a[0] - b[0]
8177 : ca === 2 ? a[1] - b[1]
8178 : b[0] - a[0];
8179 }
8180
8181 return function(stream) {
8182 var activeStream = stream,
8183 bufferStream = clipBuffer(),
8184 segments,
8185 polygon,
8186 ring,
8187 x__, y__, v__, // first point
8188 x_, y_, v_, // previous point
8189 first,
8190 clean;
8191
8192 var clipStream = {
8193 point: point,
8194 lineStart: lineStart,
8195 lineEnd: lineEnd,
8196 polygonStart: polygonStart,
8197 polygonEnd: polygonEnd
8198 };
8199
8200 function point(x, y) {
8201 if (visible(x, y)) activeStream.point(x, y);
8202 }
8203
8204 function polygonInside() {
8205 var winding = 0;
8206
8207 for (var i = 0, n = polygon.length; i < n; ++i) {
8208 for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
8209 a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
8210 if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
8211 else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
8212 }
8213 }
8214
8215 return winding;
8216 }
8217
8218 // Buffer geometry within a polygon and then clip it en masse.
8219 function polygonStart() {
8220 activeStream = bufferStream, segments = [], polygon = [], clean = true;
8221 }
8222
8223 function polygonEnd() {
8224 var startInside = polygonInside(),
8225 cleanInside = clean && startInside,
8226 visible = (segments = merge(segments)).length;
8227 if (cleanInside || visible) {
8228 stream.polygonStart();
8229 if (cleanInside) {
8230 stream.lineStart();
8231 interpolate(null, null, 1, stream);
8232 stream.lineEnd();
8233 }
8234 if (visible) {
8235 clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
8236 }
8237 stream.polygonEnd();
8238 }
8239 activeStream = stream, segments = polygon = ring = null;
8240 }
8241
8242 function lineStart() {
8243 clipStream.point = linePoint;
8244 if (polygon) polygon.push(ring = []);
8245 first = true;
8246 v_ = false;
8247 x_ = y_ = NaN;
8248 }
8249
8250 // TODO rather than special-case polygons, simply handle them separately.
8251 // Ideally, coincident intersection points should be jittered to avoid
8252 // clipping issues.
8253 function lineEnd() {
8254 if (segments) {
8255 linePoint(x__, y__);
8256 if (v__ && v_) bufferStream.rejoin();
8257 segments.push(bufferStream.result());
8258 }
8259 clipStream.point = point;
8260 if (v_) activeStream.lineEnd();
8261 }
8262
8263 function linePoint(x, y) {
8264 var v = visible(x, y);
8265 if (polygon) ring.push([x, y]);
8266 if (first) {
8267 x__ = x, y__ = y, v__ = v;
8268 first = false;
8269 if (v) {
8270 activeStream.lineStart();
8271 activeStream.point(x, y);
8272 }
8273 } else {
8274 if (v && v_) activeStream.point(x, y);
8275 else {
8276 var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
8277 b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
8278 if (clipLine(a, b, x0, y0, x1, y1)) {
8279 if (!v_) {
8280 activeStream.lineStart();
8281 activeStream.point(a[0], a[1]);
8282 }
8283 activeStream.point(b[0], b[1]);
8284 if (!v) activeStream.lineEnd();
8285 clean = false;
8286 } else if (v) {
8287 activeStream.lineStart();
8288 activeStream.point(x, y);
8289 clean = false;
8290 }
8291 }
8292 }
8293 x_ = x, y_ = y, v_ = v;
8294 }
8295
8296 return clipStream;
8297 };
8298 }
8299
8300 function extent$1() {
8301 var x0 = 0,
8302 y0 = 0,
8303 x1 = 960,
8304 y1 = 500,
8305 cache,
8306 cacheStream,
8307 clip;
8308
8309 return clip = {
8310 stream: function(stream) {
8311 return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
8312 },
8313 extent: function(_) {
8314 return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
8315 }
8316 };
8317 }
8318
8319 var lengthSum = adder();
8320 var lambda0$2;
8321 var sinPhi0$1;
8322 var cosPhi0$1;
8323
8324 var lengthStream = {
8325 sphere: noop$1,
8326 point: noop$1,
8327 lineStart: lengthLineStart,
8328 lineEnd: noop$1,
8329 polygonStart: noop$1,
8330 polygonEnd: noop$1
8331 };
8332
8333 function lengthLineStart() {
8334 lengthStream.point = lengthPointFirst;
8335 lengthStream.lineEnd = lengthLineEnd;
8336 }
8337
8338 function lengthLineEnd() {
8339 lengthStream.point = lengthStream.lineEnd = noop$1;
8340 }
8341
8342 function lengthPointFirst(lambda, phi) {
8343 lambda *= radians, phi *= radians;
8344 lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
8345 lengthStream.point = lengthPoint;
8346 }
8347
8348 function lengthPoint(lambda, phi) {
8349 lambda *= radians, phi *= radians;
8350 var sinPhi = sin$1(phi),
8351 cosPhi = cos$1(phi),
8352 delta = abs(lambda - lambda0$2),
8353 cosDelta = cos$1(delta),
8354 sinDelta = sin$1(delta),
8355 x = cosPhi * sinDelta,
8356 y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
8357 z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
8358 lengthSum.add(atan2(sqrt(x * x + y * y), z));
8359 lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
8360 }
8361
8362 function length$1(object) {
8363 lengthSum.reset();
8364 geoStream(object, lengthStream);
8365 return +lengthSum;
8366 }
8367
8368 var coordinates = [null, null];
8369 var object$1 = {type: "LineString", coordinates: coordinates};
8370
8371 function distance(a, b) {
8372 coordinates[0] = a;
8373 coordinates[1] = b;
8374 return length$1(object$1);
8375 }
8376
8377 var containsObjectType = {
8378 Feature: function(object, point) {
8379 return containsGeometry(object.geometry, point);
8380 },
8381 FeatureCollection: function(object, point) {
8382 var features = object.features, i = -1, n = features.length;
8383 while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
8384 return false;
8385 }
8386 };
8387
8388 var containsGeometryType = {
8389 Sphere: function() {
8390 return true;
8391 },
8392 Point: function(object, point) {
8393 return containsPoint(object.coordinates, point);
8394 },
8395 MultiPoint: function(object, point) {
8396 var coordinates = object.coordinates, i = -1, n = coordinates.length;
8397 while (++i < n) if (containsPoint(coordinates[i], point)) return true;
8398 return false;
8399 },
8400 LineString: function(object, point) {
8401 return containsLine(object.coordinates, point);
8402 },
8403 MultiLineString: function(object, point) {
8404 var coordinates = object.coordinates, i = -1, n = coordinates.length;
8405 while (++i < n) if (containsLine(coordinates[i], point)) return true;
8406 return false;
8407 },
8408 Polygon: function(object, point) {
8409 return containsPolygon(object.coordinates, point);
8410 },
8411 MultiPolygon: function(object, point) {
8412 var coordinates = object.coordinates, i = -1, n = coordinates.length;
8413 while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
8414 return false;
8415 },
8416 GeometryCollection: function(object, point) {
8417 var geometries = object.geometries, i = -1, n = geometries.length;
8418 while (++i < n) if (containsGeometry(geometries[i], point)) return true;
8419 return false;
8420 }
8421 };
8422
8423 function containsGeometry(geometry, point) {
8424 return geometry && containsGeometryType.hasOwnProperty(geometry.type)
8425 ? containsGeometryType[geometry.type](geometry, point)
8426 : false;
8427 }
8428
8429 function containsPoint(coordinates, point) {
8430 return distance(coordinates, point) === 0;
8431 }
8432
8433 function containsLine(coordinates, point) {
8434 var ab = distance(coordinates[0], coordinates[1]),
8435 ao = distance(coordinates[0], point),
8436 ob = distance(point, coordinates[1]);
8437 return ao + ob <= ab + epsilon$2;
8438 }
8439
8440 function containsPolygon(coordinates, point) {
8441 return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
8442 }
8443
8444 function ringRadians(ring) {
8445 return ring = ring.map(pointRadians), ring.pop(), ring;
8446 }
8447
8448 function pointRadians(point) {
8449 return [point[0] * radians, point[1] * radians];
8450 }
8451
8452 function contains(object, point) {
8453 return (object && containsObjectType.hasOwnProperty(object.type)
8454 ? containsObjectType[object.type]
8455 : containsGeometry)(object, point);
8456 }
8457
8458 function graticuleX(y0, y1, dy) {
8459 var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
8460 return function(x) { return y.map(function(y) { return [x, y]; }); };
8461 }
8462
8463 function graticuleY(x0, x1, dx) {
8464 var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
8465 return function(y) { return x.map(function(x) { return [x, y]; }); };
8466 }
8467
8468 function graticule() {
8469 var x1, x0, X1, X0,
8470 y1, y0, Y1, Y0,
8471 dx = 10, dy = dx, DX = 90, DY = 360,
8472 x, y, X, Y,
8473 precision = 2.5;
8474
8475 function graticule() {
8476 return {type: "MultiLineString", coordinates: lines()};
8477 }
8478
8479 function lines() {
8480 return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
8481 .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
8482 .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
8483 .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
8484 }
8485
8486 graticule.lines = function() {
8487 return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
8488 };
8489
8490 graticule.outline = function() {
8491 return {
8492 type: "Polygon",
8493 coordinates: [
8494 X(X0).concat(
8495 Y(Y1).slice(1),
8496 X(X1).reverse().slice(1),
8497 Y(Y0).reverse().slice(1))
8498 ]
8499 };
8500 };
8501
8502 graticule.extent = function(_) {
8503 if (!arguments.length) return graticule.extentMinor();
8504 return graticule.extentMajor(_).extentMinor(_);
8505 };
8506
8507 graticule.extentMajor = function(_) {
8508 if (!arguments.length) return [[X0, Y0], [X1, Y1]];
8509 X0 = +_[0][0], X1 = +_[1][0];
8510 Y0 = +_[0][1], Y1 = +_[1][1];
8511 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
8512 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
8513 return graticule.precision(precision);
8514 };
8515
8516 graticule.extentMinor = function(_) {
8517 if (!arguments.length) return [[x0, y0], [x1, y1]];
8518 x0 = +_[0][0], x1 = +_[1][0];
8519 y0 = +_[0][1], y1 = +_[1][1];
8520 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
8521 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
8522 return graticule.precision(precision);
8523 };
8524
8525 graticule.step = function(_) {
8526 if (!arguments.length) return graticule.stepMinor();
8527 return graticule.stepMajor(_).stepMinor(_);
8528 };
8529
8530 graticule.stepMajor = function(_) {
8531 if (!arguments.length) return [DX, DY];
8532 DX = +_[0], DY = +_[1];
8533 return graticule;
8534 };
8535
8536 graticule.stepMinor = function(_) {
8537 if (!arguments.length) return [dx, dy];
8538 dx = +_[0], dy = +_[1];
8539 return graticule;
8540 };
8541
8542 graticule.precision = function(_) {
8543 if (!arguments.length) return precision;
8544 precision = +_;
8545 x = graticuleX(y0, y1, 90);
8546 y = graticuleY(x0, x1, precision);
8547 X = graticuleX(Y0, Y1, 90);
8548 Y = graticuleY(X0, X1, precision);
8549 return graticule;
8550 };
8551
8552 return graticule
8553 .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
8554 .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
8555 }
8556
8557 function graticule10() {
8558 return graticule()();
8559 }
8560
8561 function interpolate$1(a, b) {
8562 var x0 = a[0] * radians,
8563 y0 = a[1] * radians,
8564 x1 = b[0] * radians,
8565 y1 = b[1] * radians,
8566 cy0 = cos$1(y0),
8567 sy0 = sin$1(y0),
8568 cy1 = cos$1(y1),
8569 sy1 = sin$1(y1),
8570 kx0 = cy0 * cos$1(x0),
8571 ky0 = cy0 * sin$1(x0),
8572 kx1 = cy1 * cos$1(x1),
8573 ky1 = cy1 * sin$1(x1),
8574 d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
8575 k = sin$1(d);
8576
8577 var interpolate = d ? function(t) {
8578 var B = sin$1(t *= d) / k,
8579 A = sin$1(d - t) / k,
8580 x = A * kx0 + B * kx1,
8581 y = A * ky0 + B * ky1,
8582 z = A * sy0 + B * sy1;
8583 return [
8584 atan2(y, x) * degrees$1,
8585 atan2(z, sqrt(x * x + y * y)) * degrees$1
8586 ];
8587 } : function() {
8588 return [x0 * degrees$1, y0 * degrees$1];
8589 };
8590
8591 interpolate.distance = d;
8592
8593 return interpolate;
8594 }
8595
8596 function identity$4(x) {
8597 return x;
8598 }
8599
8600 var areaSum$1 = adder();
8601 var areaRingSum$1 = adder();
8602 var x00;
8603 var y00;
8604 var x0$1;
8605 var y0$1;
8606
8607 var areaStream$1 = {
8608 point: noop$1,
8609 lineStart: noop$1,
8610 lineEnd: noop$1,
8611 polygonStart: function() {
8612 areaStream$1.lineStart = areaRingStart$1;
8613 areaStream$1.lineEnd = areaRingEnd$1;
8614 },
8615 polygonEnd: function() {
8616 areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$1;
8617 areaSum$1.add(abs(areaRingSum$1));
8618 areaRingSum$1.reset();
8619 },
8620 result: function() {
8621 var area = areaSum$1 / 2;
8622 areaSum$1.reset();
8623 return area;
8624 }
8625 };
8626
8627 function areaRingStart$1() {
8628 areaStream$1.point = areaPointFirst$1;
8629 }
8630
8631 function areaPointFirst$1(x, y) {
8632 areaStream$1.point = areaPoint$1;
8633 x00 = x0$1 = x, y00 = y0$1 = y;
8634 }
8635
8636 function areaPoint$1(x, y) {
8637 areaRingSum$1.add(y0$1 * x - x0$1 * y);
8638 x0$1 = x, y0$1 = y;
8639 }
8640
8641 function areaRingEnd$1() {
8642 areaPoint$1(x00, y00);
8643 }
8644
8645 var x0$2 = Infinity;
8646 var y0$2 = x0$2;
8647 var x1 = -x0$2;
8648 var y1 = x1;
8649
8650 var boundsStream$1 = {
8651 point: boundsPoint$1,
8652 lineStart: noop$1,
8653 lineEnd: noop$1,
8654 polygonStart: noop$1,
8655 polygonEnd: noop$1,
8656 result: function() {
8657 var bounds = [[x0$2, y0$2], [x1, y1]];
8658 x1 = y1 = -(y0$2 = x0$2 = Infinity);
8659 return bounds;
8660 }
8661 };
8662
8663 function boundsPoint$1(x, y) {
8664 if (x < x0$2) x0$2 = x;
8665 if (x > x1) x1 = x;
8666 if (y < y0$2) y0$2 = y;
8667 if (y > y1) y1 = y;
8668 }
8669
8670 // TODO Enforce positive area for exterior, negative area for interior?
8671
8672 var X0$1 = 0;
8673 var Y0$1 = 0;
8674 var Z0$1 = 0;
8675 var X1$1 = 0;
8676 var Y1$1 = 0;
8677 var Z1$1 = 0;
8678 var X2$1 = 0;
8679 var Y2$1 = 0;
8680 var Z2$1 = 0;
8681 var x00$1;
8682 var y00$1;
8683 var x0$3;
8684 var y0$3;
8685
8686 var centroidStream$1 = {
8687 point: centroidPoint$1,
8688 lineStart: centroidLineStart$1,
8689 lineEnd: centroidLineEnd$1,
8690 polygonStart: function() {
8691 centroidStream$1.lineStart = centroidRingStart$1;
8692 centroidStream$1.lineEnd = centroidRingEnd$1;
8693 },
8694 polygonEnd: function() {
8695 centroidStream$1.point = centroidPoint$1;
8696 centroidStream$1.lineStart = centroidLineStart$1;
8697 centroidStream$1.lineEnd = centroidLineEnd$1;
8698 },
8699 result: function() {
8700 var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
8701 : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
8702 : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
8703 : [NaN, NaN];
8704 X0$1 = Y0$1 = Z0$1 =
8705 X1$1 = Y1$1 = Z1$1 =
8706 X2$1 = Y2$1 = Z2$1 = 0;
8707 return centroid;
8708 }
8709 };
8710
8711 function centroidPoint$1(x, y) {
8712 X0$1 += x;
8713 Y0$1 += y;
8714 ++Z0$1;
8715 }
8716
8717 function centroidLineStart$1() {
8718 centroidStream$1.point = centroidPointFirstLine;
8719 }
8720
8721 function centroidPointFirstLine(x, y) {
8722 centroidStream$1.point = centroidPointLine;
8723 centroidPoint$1(x0$3 = x, y0$3 = y);
8724 }
8725
8726 function centroidPointLine(x, y) {
8727 var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
8728 X1$1 += z * (x0$3 + x) / 2;
8729 Y1$1 += z * (y0$3 + y) / 2;
8730 Z1$1 += z;
8731 centroidPoint$1(x0$3 = x, y0$3 = y);
8732 }
8733
8734 function centroidLineEnd$1() {
8735 centroidStream$1.point = centroidPoint$1;
8736 }
8737
8738 function centroidRingStart$1() {
8739 centroidStream$1.point = centroidPointFirstRing;
8740 }
8741
8742 function centroidRingEnd$1() {
8743 centroidPointRing(x00$1, y00$1);
8744 }
8745
8746 function centroidPointFirstRing(x, y) {
8747 centroidStream$1.point = centroidPointRing;
8748 centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
8749 }
8750
8751 function centroidPointRing(x, y) {
8752 var dx = x - x0$3,
8753 dy = y - y0$3,
8754 z = sqrt(dx * dx + dy * dy);
8755
8756 X1$1 += z * (x0$3 + x) / 2;
8757 Y1$1 += z * (y0$3 + y) / 2;
8758 Z1$1 += z;
8759
8760 z = y0$3 * x - x0$3 * y;
8761 X2$1 += z * (x0$3 + x);
8762 Y2$1 += z * (y0$3 + y);
8763 Z2$1 += z * 3;
8764 centroidPoint$1(x0$3 = x, y0$3 = y);
8765 }
8766
8767 function PathContext(context) {
8768 this._context = context;
8769 }
8770
8771 PathContext.prototype = {
8772 _radius: 4.5,
8773 pointRadius: function(_) {
8774 return this._radius = _, this;
8775 },
8776 polygonStart: function() {
8777 this._line = 0;
8778 },
8779 polygonEnd: function() {
8780 this._line = NaN;
8781 },
8782 lineStart: function() {
8783 this._point = 0;
8784 },
8785 lineEnd: function() {
8786 if (this._line === 0) this._context.closePath();
8787 this._point = NaN;
8788 },
8789 point: function(x, y) {
8790 switch (this._point) {
8791 case 0: {
8792 this._context.moveTo(x, y);
8793 this._point = 1;
8794 break;
8795 }
8796 case 1: {
8797 this._context.lineTo(x, y);
8798 break;
8799 }
8800 default: {
8801 this._context.moveTo(x + this._radius, y);
8802 this._context.arc(x, y, this._radius, 0, tau$3);
8803 break;
8804 }
8805 }
8806 },
8807 result: noop$1
8808 };
8809
8810 var lengthSum$1 = adder();
8811 var lengthRing;
8812 var x00$2;
8813 var y00$2;
8814 var x0$4;
8815 var y0$4;
8816
8817 var lengthStream$1 = {
8818 point: noop$1,
8819 lineStart: function() {
8820 lengthStream$1.point = lengthPointFirst$1;
8821 },
8822 lineEnd: function() {
8823 if (lengthRing) lengthPoint$1(x00$2, y00$2);
8824 lengthStream$1.point = noop$1;
8825 },
8826 polygonStart: function() {
8827 lengthRing = true;
8828 },
8829 polygonEnd: function() {
8830 lengthRing = null;
8831 },
8832 result: function() {
8833 var length = +lengthSum$1;
8834 lengthSum$1.reset();
8835 return length;
8836 }
8837 };
8838
8839 function lengthPointFirst$1(x, y) {
8840 lengthStream$1.point = lengthPoint$1;
8841 x00$2 = x0$4 = x, y00$2 = y0$4 = y;
8842 }
8843
8844 function lengthPoint$1(x, y) {
8845 x0$4 -= x, y0$4 -= y;
8846 lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
8847 x0$4 = x, y0$4 = y;
8848 }
8849
8850 function PathString() {
8851 this._string = [];
8852 }
8853
8854 PathString.prototype = {
8855 _radius: 4.5,
8856 _circle: circle$1(4.5),
8857 pointRadius: function(_) {
8858 if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
8859 return this;
8860 },
8861 polygonStart: function() {
8862 this._line = 0;
8863 },
8864 polygonEnd: function() {
8865 this._line = NaN;
8866 },
8867 lineStart: function() {
8868 this._point = 0;
8869 },
8870 lineEnd: function() {
8871 if (this._line === 0) this._string.push("Z");
8872 this._point = NaN;
8873 },
8874 point: function(x, y) {
8875 switch (this._point) {
8876 case 0: {
8877 this._string.push("M", x, ",", y);
8878 this._point = 1;
8879 break;
8880 }
8881 case 1: {
8882 this._string.push("L", x, ",", y);
8883 break;
8884 }
8885 default: {
8886 if (this._circle == null) this._circle = circle$1(this._radius);
8887 this._string.push("M", x, ",", y, this._circle);
8888 break;
8889 }
8890 }
8891 },
8892 result: function() {
8893 if (this._string.length) {
8894 var result = this._string.join("");
8895 this._string = [];
8896 return result;
8897 } else {
8898 return null;
8899 }
8900 }
8901 };
8902
8903 function circle$1(radius) {
8904 return "m0," + radius
8905 + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
8906 + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
8907 + "z";
8908 }
8909
8910 function index$1(projection, context) {
8911 var pointRadius = 4.5,
8912 projectionStream,
8913 contextStream;
8914
8915 function path(object) {
8916 if (object) {
8917 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
8918 geoStream(object, projectionStream(contextStream));
8919 }
8920 return contextStream.result();
8921 }
8922
8923 path.area = function(object) {
8924 geoStream(object, projectionStream(areaStream$1));
8925 return areaStream$1.result();
8926 };
8927
8928 path.measure = function(object) {
8929 geoStream(object, projectionStream(lengthStream$1));
8930 return lengthStream$1.result();
8931 };
8932
8933 path.bounds = function(object) {
8934 geoStream(object, projectionStream(boundsStream$1));
8935 return boundsStream$1.result();
8936 };
8937
8938 path.centroid = function(object) {
8939 geoStream(object, projectionStream(centroidStream$1));
8940 return centroidStream$1.result();
8941 };
8942
8943 path.projection = function(_) {
8944 return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
8945 };
8946
8947 path.context = function(_) {
8948 if (!arguments.length) return context;
8949 contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
8950 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
8951 return path;
8952 };
8953
8954 path.pointRadius = function(_) {
8955 if (!arguments.length) return pointRadius;
8956 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
8957 return path;
8958 };
8959
8960 return path.projection(projection).context(context);
8961 }
8962
8963 function transform(methods) {
8964 return {
8965 stream: transformer(methods)
8966 };
8967 }
8968
8969 function transformer(methods) {
8970 return function(stream) {
8971 var s = new TransformStream;
8972 for (var key in methods) s[key] = methods[key];
8973 s.stream = stream;
8974 return s;
8975 };
8976 }
8977
8978 function TransformStream() {}
8979
8980 TransformStream.prototype = {
8981 constructor: TransformStream,
8982 point: function(x, y) { this.stream.point(x, y); },
8983 sphere: function() { this.stream.sphere(); },
8984 lineStart: function() { this.stream.lineStart(); },
8985 lineEnd: function() { this.stream.lineEnd(); },
8986 polygonStart: function() { this.stream.polygonStart(); },
8987 polygonEnd: function() { this.stream.polygonEnd(); }
8988 };
8989
8990 function fit(projection, fitBounds, object) {
8991 var clip = projection.clipExtent && projection.clipExtent();
8992 projection.scale(150).translate([0, 0]);
8993 if (clip != null) projection.clipExtent(null);
8994 geoStream(object, projection.stream(boundsStream$1));
8995 fitBounds(boundsStream$1.result());
8996 if (clip != null) projection.clipExtent(clip);
8997 return projection;
8998 }
8999
9000 function fitExtent(projection, extent, object) {
9001 return fit(projection, function(b) {
9002 var w = extent[1][0] - extent[0][0],
9003 h = extent[1][1] - extent[0][1],
9004 k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
9005 x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
9006 y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
9007 projection.scale(150 * k).translate([x, y]);
9008 }, object);
9009 }
9010
9011 function fitSize(projection, size, object) {
9012 return fitExtent(projection, [[0, 0], size], object);
9013 }
9014
9015 function fitWidth(projection, width, object) {
9016 return fit(projection, function(b) {
9017 var w = +width,
9018 k = w / (b[1][0] - b[0][0]),
9019 x = (w - k * (b[1][0] + b[0][0])) / 2,
9020 y = -k * b[0][1];
9021 projection.scale(150 * k).translate([x, y]);
9022 }, object);
9023 }
9024
9025 function fitHeight(projection, height, object) {
9026 return fit(projection, function(b) {
9027 var h = +height,
9028 k = h / (b[1][1] - b[0][1]),
9029 x = -k * b[0][0],
9030 y = (h - k * (b[1][1] + b[0][1])) / 2;
9031 projection.scale(150 * k).translate([x, y]);
9032 }, object);
9033 }
9034
9035 var maxDepth = 16;
9036 var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
9037
9038 function resample(project, delta2) {
9039 return +delta2 ? resample$1(project, delta2) : resampleNone(project);
9040 }
9041
9042 function resampleNone(project) {
9043 return transformer({
9044 point: function(x, y) {
9045 x = project(x, y);
9046 this.stream.point(x[0], x[1]);
9047 }
9048 });
9049 }
9050
9051 function resample$1(project, delta2) {
9052
9053 function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
9054 var dx = x1 - x0,
9055 dy = y1 - y0,
9056 d2 = dx * dx + dy * dy;
9057 if (d2 > 4 * delta2 && depth--) {
9058 var a = a0 + a1,
9059 b = b0 + b1,
9060 c = c0 + c1,
9061 m = sqrt(a * a + b * b + c * c),
9062 phi2 = asin(c /= m),
9063 lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
9064 p = project(lambda2, phi2),
9065 x2 = p[0],
9066 y2 = p[1],
9067 dx2 = x2 - x0,
9068 dy2 = y2 - y0,
9069 dz = dy * dx2 - dx * dy2;
9070 if (dz * dz / d2 > delta2 // perpendicular projected distance
9071 || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
9072 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
9073 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
9074 stream.point(x2, y2);
9075 resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
9076 }
9077 }
9078 }
9079 return function(stream) {
9080 var lambda00, x00, y00, a00, b00, c00, // first point
9081 lambda0, x0, y0, a0, b0, c0; // previous point
9082
9083 var resampleStream = {
9084 point: point,
9085 lineStart: lineStart,
9086 lineEnd: lineEnd,
9087 polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
9088 polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
9089 };
9090
9091 function point(x, y) {
9092 x = project(x, y);
9093 stream.point(x[0], x[1]);
9094 }
9095
9096 function lineStart() {
9097 x0 = NaN;
9098 resampleStream.point = linePoint;
9099 stream.lineStart();
9100 }
9101
9102 function linePoint(lambda, phi) {
9103 var c = cartesian([lambda, phi]), p = project(lambda, phi);
9104 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);
9105 stream.point(x0, y0);
9106 }
9107
9108 function lineEnd() {
9109 resampleStream.point = point;
9110 stream.lineEnd();
9111 }
9112
9113 function ringStart() {
9114 lineStart();
9115 resampleStream.point = ringPoint;
9116 resampleStream.lineEnd = ringEnd;
9117 }
9118
9119 function ringPoint(lambda, phi) {
9120 linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
9121 resampleStream.point = linePoint;
9122 }
9123
9124 function ringEnd() {
9125 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
9126 resampleStream.lineEnd = lineEnd;
9127 lineEnd();
9128 }
9129
9130 return resampleStream;
9131 };
9132 }
9133
9134 var transformRadians = transformer({
9135 point: function(x, y) {
9136 this.stream.point(x * radians, y * radians);
9137 }
9138 });
9139
9140 function transformRotate(rotate) {
9141 return transformer({
9142 point: function(x, y) {
9143 var r = rotate(x, y);
9144 return this.stream.point(r[0], r[1]);
9145 }
9146 });
9147 }
9148
9149 function projection(project) {
9150 return projectionMutator(function() { return project; })();
9151 }
9152
9153 function projectionMutator(projectAt) {
9154 var project,
9155 k = 150, // scale
9156 x = 480, y = 250, // translate
9157 dx, dy, lambda = 0, phi = 0, // center
9158 deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
9159 theta = null, preclip = clipAntimeridian, // clip angle
9160 x0 = null, y0, x1, y1, postclip = identity$4, // clip extent
9161 delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
9162 cache,
9163 cacheStream;
9164
9165 function projection(point) {
9166 point = projectRotate(point[0] * radians, point[1] * radians);
9167 return [point[0] * k + dx, dy - point[1] * k];
9168 }
9169
9170 function invert(point) {
9171 point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
9172 return point && [point[0] * degrees$1, point[1] * degrees$1];
9173 }
9174
9175 function projectTransform(x, y) {
9176 return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
9177 }
9178
9179 projection.stream = function(stream) {
9180 return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
9181 };
9182
9183 projection.preclip = function(_) {
9184 return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
9185 };
9186
9187 projection.postclip = function(_) {
9188 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
9189 };
9190
9191 projection.clipAngle = function(_) {
9192 return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
9193 };
9194
9195 projection.clipExtent = function(_) {
9196 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]];
9197 };
9198
9199 projection.scale = function(_) {
9200 return arguments.length ? (k = +_, recenter()) : k;
9201 };
9202
9203 projection.translate = function(_) {
9204 return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
9205 };
9206
9207 projection.center = function(_) {
9208 return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
9209 };
9210
9211 projection.rotate = function(_) {
9212 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];
9213 };
9214
9215 projection.precision = function(_) {
9216 return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
9217 };
9218
9219 projection.fitExtent = function(extent, object) {
9220 return fitExtent(projection, extent, object);
9221 };
9222
9223 projection.fitSize = function(size, object) {
9224 return fitSize(projection, size, object);
9225 };
9226
9227 projection.fitWidth = function(width, object) {
9228 return fitWidth(projection, width, object);
9229 };
9230
9231 projection.fitHeight = function(height, object) {
9232 return fitHeight(projection, height, object);
9233 };
9234
9235 function recenter() {
9236 projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
9237 var center = project(lambda, phi);
9238 dx = x - center[0] * k;
9239 dy = y + center[1] * k;
9240 return reset();
9241 }
9242
9243 function reset() {
9244 cache = cacheStream = null;
9245 return projection;
9246 }
9247
9248 return function() {
9249 project = projectAt.apply(this, arguments);
9250 projection.invert = project.invert && invert;
9251 return recenter();
9252 };
9253 }
9254
9255 function conicProjection(projectAt) {
9256 var phi0 = 0,
9257 phi1 = pi$3 / 3,
9258 m = projectionMutator(projectAt),
9259 p = m(phi0, phi1);
9260
9261 p.parallels = function(_) {
9262 return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
9263 };
9264
9265 return p;
9266 }
9267
9268 function cylindricalEqualAreaRaw(phi0) {
9269 var cosPhi0 = cos$1(phi0);
9270
9271 function forward(lambda, phi) {
9272 return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
9273 }
9274
9275 forward.invert = function(x, y) {
9276 return [x / cosPhi0, asin(y * cosPhi0)];
9277 };
9278
9279 return forward;
9280 }
9281
9282 function conicEqualAreaRaw(y0, y1) {
9283 var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
9284
9285 // Are the parallels symmetrical around the Equator?
9286 if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
9287
9288 var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
9289
9290 function project(x, y) {
9291 var r = sqrt(c - 2 * n * sin$1(y)) / n;
9292 return [r * sin$1(x *= n), r0 - r * cos$1(x)];
9293 }
9294
9295 project.invert = function(x, y) {
9296 var r0y = r0 - y;
9297 return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
9298 };
9299
9300 return project;
9301 }
9302
9303 function conicEqualArea() {
9304 return conicProjection(conicEqualAreaRaw)
9305 .scale(155.424)
9306 .center([0, 33.6442]);
9307 }
9308
9309 function albers() {
9310 return conicEqualArea()
9311 .parallels([29.5, 45.5])
9312 .scale(1070)
9313 .translate([480, 250])
9314 .rotate([96, 0])
9315 .center([-0.6, 38.7]);
9316 }
9317
9318 // The projections must have mutually exclusive clip regions on the sphere,
9319 // as this will avoid emitting interleaving lines and polygons.
9320 function multiplex(streams) {
9321 var n = streams.length;
9322 return {
9323 point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
9324 sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
9325 lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
9326 lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
9327 polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
9328 polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
9329 };
9330 }
9331
9332 // A composite projection for the United States, configured by default for
9333 // 960×500. The projection also works quite well at 960×600 if you change the
9334 // scale to 1285 and adjust the translate accordingly. The set of standard
9335 // parallels for each region comes from USGS, which is published here:
9336 // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
9337 function albersUsa() {
9338 var cache,
9339 cacheStream,
9340 lower48 = albers(), lower48Point,
9341 alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
9342 hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
9343 point, pointStream = {point: function(x, y) { point = [x, y]; }};
9344
9345 function albersUsa(coordinates) {
9346 var x = coordinates[0], y = coordinates[1];
9347 return point = null, (lower48Point.point(x, y), point)
9348 || (alaskaPoint.point(x, y), point)
9349 || (hawaiiPoint.point(x, y), point);
9350 }
9351
9352 albersUsa.invert = function(coordinates) {
9353 var k = lower48.scale(),
9354 t = lower48.translate(),
9355 x = (coordinates[0] - t[0]) / k,
9356 y = (coordinates[1] - t[1]) / k;
9357 return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
9358 : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
9359 : lower48).invert(coordinates);
9360 };
9361
9362 albersUsa.stream = function(stream) {
9363 return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
9364 };
9365
9366 albersUsa.precision = function(_) {
9367 if (!arguments.length) return lower48.precision();
9368 lower48.precision(_), alaska.precision(_), hawaii.precision(_);
9369 return reset();
9370 };
9371
9372 albersUsa.scale = function(_) {
9373 if (!arguments.length) return lower48.scale();
9374 lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
9375 return albersUsa.translate(lower48.translate());
9376 };
9377
9378 albersUsa.translate = function(_) {
9379 if (!arguments.length) return lower48.translate();
9380 var k = lower48.scale(), x = +_[0], y = +_[1];
9381
9382 lower48Point = lower48
9383 .translate(_)
9384 .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
9385 .stream(pointStream);
9386
9387 alaskaPoint = alaska
9388 .translate([x - 0.307 * k, y + 0.201 * k])
9389 .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]])
9390 .stream(pointStream);
9391
9392 hawaiiPoint = hawaii
9393 .translate([x - 0.205 * k, y + 0.212 * k])
9394 .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]])
9395 .stream(pointStream);
9396
9397 return reset();
9398 };
9399
9400 albersUsa.fitExtent = function(extent, object) {
9401 return fitExtent(albersUsa, extent, object);
9402 };
9403
9404 albersUsa.fitSize = function(size, object) {
9405 return fitSize(albersUsa, size, object);
9406 };
9407
9408 albersUsa.fitWidth = function(width, object) {
9409 return fitWidth(albersUsa, width, object);
9410 };
9411
9412 albersUsa.fitHeight = function(height, object) {
9413 return fitHeight(albersUsa, height, object);
9414 };
9415
9416 function reset() {
9417 cache = cacheStream = null;
9418 return albersUsa;
9419 }
9420
9421 return albersUsa.scale(1070);
9422 }
9423
9424 function azimuthalRaw(scale) {
9425 return function(x, y) {
9426 var cx = cos$1(x),
9427 cy = cos$1(y),
9428 k = scale(cx * cy);
9429 return [
9430 k * cy * sin$1(x),
9431 k * sin$1(y)
9432 ];
9433 }
9434 }
9435
9436 function azimuthalInvert(angle) {
9437 return function(x, y) {
9438 var z = sqrt(x * x + y * y),
9439 c = angle(z),
9440 sc = sin$1(c),
9441 cc = cos$1(c);
9442 return [
9443 atan2(x * sc, z * cc),
9444 asin(z && y * sc / z)
9445 ];
9446 }
9447 }
9448
9449 var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
9450 return sqrt(2 / (1 + cxcy));
9451 });
9452
9453 azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
9454 return 2 * asin(z / 2);
9455 });
9456
9457 function azimuthalEqualArea() {
9458 return projection(azimuthalEqualAreaRaw)
9459 .scale(124.75)
9460 .clipAngle(180 - 1e-3);
9461 }
9462
9463 var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
9464 return (c = acos(c)) && c / sin$1(c);
9465 });
9466
9467 azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
9468 return z;
9469 });
9470
9471 function azimuthalEquidistant() {
9472 return projection(azimuthalEquidistantRaw)
9473 .scale(79.4188)
9474 .clipAngle(180 - 1e-3);
9475 }
9476
9477 function mercatorRaw(lambda, phi) {
9478 return [lambda, log(tan((halfPi$2 + phi) / 2))];
9479 }
9480
9481 mercatorRaw.invert = function(x, y) {
9482 return [x, 2 * atan(exp(y)) - halfPi$2];
9483 };
9484
9485 function mercator() {
9486 return mercatorProjection(mercatorRaw)
9487 .scale(961 / tau$3);
9488 }
9489
9490 function mercatorProjection(project) {
9491 var m = projection(project),
9492 center = m.center,
9493 scale = m.scale,
9494 translate = m.translate,
9495 clipExtent = m.clipExtent,
9496 x0 = null, y0, x1, y1; // clip extent
9497
9498 m.scale = function(_) {
9499 return arguments.length ? (scale(_), reclip()) : scale();
9500 };
9501
9502 m.translate = function(_) {
9503 return arguments.length ? (translate(_), reclip()) : translate();
9504 };
9505
9506 m.center = function(_) {
9507 return arguments.length ? (center(_), reclip()) : center();
9508 };
9509
9510 m.clipExtent = function(_) {
9511 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]];
9512 };
9513
9514 function reclip() {
9515 var k = pi$3 * scale(),
9516 t = m(rotation(m.rotate()).invert([0, 0]));
9517 return clipExtent(x0 == null
9518 ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
9519 ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
9520 : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
9521 }
9522
9523 return reclip();
9524 }
9525
9526 function tany(y) {
9527 return tan((halfPi$2 + y) / 2);
9528 }
9529
9530 function conicConformalRaw(y0, y1) {
9531 var cy0 = cos$1(y0),
9532 n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
9533 f = cy0 * pow(tany(y0), n) / n;
9534
9535 if (!n) return mercatorRaw;
9536
9537 function project(x, y) {
9538 if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
9539 else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
9540 var r = f / pow(tany(y), n);
9541 return [r * sin$1(n * x), f - r * cos$1(n * x)];
9542 }
9543
9544 project.invert = function(x, y) {
9545 var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
9546 return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
9547 };
9548
9549 return project;
9550 }
9551
9552 function conicConformal() {
9553 return conicProjection(conicConformalRaw)
9554 .scale(109.5)
9555 .parallels([30, 30]);
9556 }
9557
9558 function equirectangularRaw(lambda, phi) {
9559 return [lambda, phi];
9560 }
9561
9562 equirectangularRaw.invert = equirectangularRaw;
9563
9564 function equirectangular() {
9565 return projection(equirectangularRaw)
9566 .scale(152.63);
9567 }
9568
9569 function conicEquidistantRaw(y0, y1) {
9570 var cy0 = cos$1(y0),
9571 n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
9572 g = cy0 / n + y0;
9573
9574 if (abs(n) < epsilon$2) return equirectangularRaw;
9575
9576 function project(x, y) {
9577 var gy = g - y, nx = n * x;
9578 return [gy * sin$1(nx), g - gy * cos$1(nx)];
9579 }
9580
9581 project.invert = function(x, y) {
9582 var gy = g - y;
9583 return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
9584 };
9585
9586 return project;
9587 }
9588
9589 function conicEquidistant() {
9590 return conicProjection(conicEquidistantRaw)
9591 .scale(131.154)
9592 .center([0, 13.9389]);
9593 }
9594
9595 function gnomonicRaw(x, y) {
9596 var cy = cos$1(y), k = cos$1(x) * cy;
9597 return [cy * sin$1(x) / k, sin$1(y) / k];
9598 }
9599
9600 gnomonicRaw.invert = azimuthalInvert(atan);
9601
9602 function gnomonic() {
9603 return projection(gnomonicRaw)
9604 .scale(144.049)
9605 .clipAngle(60);
9606 }
9607
9608 function scaleTranslate(kx, ky, tx, ty) {
9609 return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
9610 point: function(x, y) {
9611 this.stream.point(x * kx + tx, y * ky + ty);
9612 }
9613 });
9614 }
9615
9616 function identity$5() {
9617 var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
9618 x0 = null, y0, x1, y1, // clip extent
9619 postclip = identity$4,
9620 cache,
9621 cacheStream,
9622 projection;
9623
9624 function reset() {
9625 cache = cacheStream = null;
9626 return projection;
9627 }
9628
9629 return projection = {
9630 stream: function(stream) {
9631 return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
9632 },
9633 postclip: function(_) {
9634 return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
9635 },
9636 clipExtent: function(_) {
9637 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]];
9638 },
9639 scale: function(_) {
9640 return arguments.length ? (transform$$1 = scaleTranslate((k = +_) * sx, k * sy, tx, ty), reset()) : k;
9641 },
9642 translate: function(_) {
9643 return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
9644 },
9645 reflectX: function(_) {
9646 return arguments.length ? (transform$$1 = scaleTranslate(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
9647 },
9648 reflectY: function(_) {
9649 return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
9650 },
9651 fitExtent: function(extent, object) {
9652 return fitExtent(projection, extent, object);
9653 },
9654 fitSize: function(size, object) {
9655 return fitSize(projection, size, object);
9656 },
9657 fitWidth: function(width, object) {
9658 return fitWidth(projection, width, object);
9659 },
9660 fitHeight: function(height, object) {
9661 return fitHeight(projection, height, object);
9662 }
9663 };
9664 }
9665
9666 function naturalEarth1Raw(lambda, phi) {
9667 var phi2 = phi * phi, phi4 = phi2 * phi2;
9668 return [
9669 lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
9670 phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
9671 ];
9672 }
9673
9674 naturalEarth1Raw.invert = function(x, y) {
9675 var phi = y, i = 25, delta;
9676 do {
9677 var phi2 = phi * phi, phi4 = phi2 * phi2;
9678 phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
9679 (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
9680 } while (abs(delta) > epsilon$2 && --i > 0);
9681 return [
9682 x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
9683 phi
9684 ];
9685 };
9686
9687 function naturalEarth1() {
9688 return projection(naturalEarth1Raw)
9689 .scale(175.295);
9690 }
9691
9692 function orthographicRaw(x, y) {
9693 return [cos$1(y) * sin$1(x), sin$1(y)];
9694 }
9695
9696 orthographicRaw.invert = azimuthalInvert(asin);
9697
9698 function orthographic() {
9699 return projection(orthographicRaw)
9700 .scale(249.5)
9701 .clipAngle(90 + epsilon$2);
9702 }
9703
9704 function stereographicRaw(x, y) {
9705 var cy = cos$1(y), k = 1 + cos$1(x) * cy;
9706 return [cy * sin$1(x) / k, sin$1(y) / k];
9707 }
9708
9709 stereographicRaw.invert = azimuthalInvert(function(z) {
9710 return 2 * atan(z);
9711 });
9712
9713 function stereographic() {
9714 return projection(stereographicRaw)
9715 .scale(250)
9716 .clipAngle(142);
9717 }
9718
9719 function transverseMercatorRaw(lambda, phi) {
9720 return [log(tan((halfPi$2 + phi) / 2)), -lambda];
9721 }
9722
9723 transverseMercatorRaw.invert = function(x, y) {
9724 return [-y, 2 * atan(exp(x)) - halfPi$2];
9725 };
9726
9727 function transverseMercator() {
9728 var m = mercatorProjection(transverseMercatorRaw),
9729 center = m.center,
9730 rotate = m.rotate;
9731
9732 m.center = function(_) {
9733 return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
9734 };
9735
9736 m.rotate = function(_) {
9737 return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
9738 };
9739
9740 return rotate([0, 0, 90])
9741 .scale(159.155);
9742 }
9743
9744 function defaultSeparation(a, b) {
9745 return a.parent === b.parent ? 1 : 2;
9746 }
9747
9748 function meanX(children) {
9749 return children.reduce(meanXReduce, 0) / children.length;
9750 }
9751
9752 function meanXReduce(x, c) {
9753 return x + c.x;
9754 }
9755
9756 function maxY(children) {
9757 return 1 + children.reduce(maxYReduce, 0);
9758 }
9759
9760 function maxYReduce(y, c) {
9761 return Math.max(y, c.y);
9762 }
9763
9764 function leafLeft(node) {
9765 var children;
9766 while (children = node.children) node = children[0];
9767 return node;
9768 }
9769
9770 function leafRight(node) {
9771 var children;
9772 while (children = node.children) node = children[children.length - 1];
9773 return node;
9774 }
9775
9776 function cluster() {
9777 var separation = defaultSeparation,
9778 dx = 1,
9779 dy = 1,
9780 nodeSize = false;
9781
9782 function cluster(root) {
9783 var previousNode,
9784 x = 0;
9785
9786 // First walk, computing the initial x & y values.
9787 root.eachAfter(function(node) {
9788 var children = node.children;
9789 if (children) {
9790 node.x = meanX(children);
9791 node.y = maxY(children);
9792 } else {
9793 node.x = previousNode ? x += separation(node, previousNode) : 0;
9794 node.y = 0;
9795 previousNode = node;
9796 }
9797 });
9798
9799 var left = leafLeft(root),
9800 right = leafRight(root),
9801 x0 = left.x - separation(left, right) / 2,
9802 x1 = right.x + separation(right, left) / 2;
9803
9804 // Second walk, normalizing x & y to the desired size.
9805 return root.eachAfter(nodeSize ? function(node) {
9806 node.x = (node.x - root.x) * dx;
9807 node.y = (root.y - node.y) * dy;
9808 } : function(node) {
9809 node.x = (node.x - x0) / (x1 - x0) * dx;
9810 node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
9811 });
9812 }
9813
9814 cluster.separation = function(x) {
9815 return arguments.length ? (separation = x, cluster) : separation;
9816 };
9817
9818 cluster.size = function(x) {
9819 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
9820 };
9821
9822 cluster.nodeSize = function(x) {
9823 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
9824 };
9825
9826 return cluster;
9827 }
9828
9829 function count(node) {
9830 var sum = 0,
9831 children = node.children,
9832 i = children && children.length;
9833 if (!i) sum = 1;
9834 else while (--i >= 0) sum += children[i].value;
9835 node.value = sum;
9836 }
9837
9838 function node_count() {
9839 return this.eachAfter(count);
9840 }
9841
9842 function node_each(callback) {
9843 var node = this, current, next = [node], children, i, n;
9844 do {
9845 current = next.reverse(), next = [];
9846 while (node = current.pop()) {
9847 callback(node), children = node.children;
9848 if (children) for (i = 0, n = children.length; i < n; ++i) {
9849 next.push(children[i]);
9850 }
9851 }
9852 } while (next.length);
9853 return this;
9854 }
9855
9856 function node_eachBefore(callback) {
9857 var node = this, nodes = [node], children, i;
9858 while (node = nodes.pop()) {
9859 callback(node), children = node.children;
9860 if (children) for (i = children.length - 1; i >= 0; --i) {
9861 nodes.push(children[i]);
9862 }
9863 }
9864 return this;
9865 }
9866
9867 function node_eachAfter(callback) {
9868 var node = this, nodes = [node], next = [], children, i, n;
9869 while (node = nodes.pop()) {
9870 next.push(node), children = node.children;
9871 if (children) for (i = 0, n = children.length; i < n; ++i) {
9872 nodes.push(children[i]);
9873 }
9874 }
9875 while (node = next.pop()) {
9876 callback(node);
9877 }
9878 return this;
9879 }
9880
9881 function node_sum(value) {
9882 return this.eachAfter(function(node) {
9883 var sum = +value(node.data) || 0,
9884 children = node.children,
9885 i = children && children.length;
9886 while (--i >= 0) sum += children[i].value;
9887 node.value = sum;
9888 });
9889 }
9890
9891 function node_sort(compare) {
9892 return this.eachBefore(function(node) {
9893 if (node.children) {
9894 node.children.sort(compare);
9895 }
9896 });
9897 }
9898
9899 function node_path(end) {
9900 var start = this,
9901 ancestor = leastCommonAncestor(start, end),
9902 nodes = [start];
9903 while (start !== ancestor) {
9904 start = start.parent;
9905 nodes.push(start);
9906 }
9907 var k = nodes.length;
9908 while (end !== ancestor) {
9909 nodes.splice(k, 0, end);
9910 end = end.parent;
9911 }
9912 return nodes;
9913 }
9914
9915 function leastCommonAncestor(a, b) {
9916 if (a === b) return a;
9917 var aNodes = a.ancestors(),
9918 bNodes = b.ancestors(),
9919 c = null;
9920 a = aNodes.pop();
9921 b = bNodes.pop();
9922 while (a === b) {
9923 c = a;
9924 a = aNodes.pop();
9925 b = bNodes.pop();
9926 }
9927 return c;
9928 }
9929
9930 function node_ancestors() {
9931 var node = this, nodes = [node];
9932 while (node = node.parent) {
9933 nodes.push(node);
9934 }
9935 return nodes;
9936 }
9937
9938 function node_descendants() {
9939 var nodes = [];
9940 this.each(function(node) {
9941 nodes.push(node);
9942 });
9943 return nodes;
9944 }
9945
9946 function node_leaves() {
9947 var leaves = [];
9948 this.eachBefore(function(node) {
9949 if (!node.children) {
9950 leaves.push(node);
9951 }
9952 });
9953 return leaves;
9954 }
9955
9956 function node_links() {
9957 var root = this, links = [];
9958 root.each(function(node) {
9959 if (node !== root) { // Don’t include the root’s parent, if any.
9960 links.push({source: node.parent, target: node});
9961 }
9962 });
9963 return links;
9964 }
9965
9966 function hierarchy(data, children) {
9967 var root = new Node(data),
9968 valued = +data.value && (root.value = data.value),
9969 node,
9970 nodes = [root],
9971 child,
9972 childs,
9973 i,
9974 n;
9975
9976 if (children == null) children = defaultChildren;
9977
9978 while (node = nodes.pop()) {
9979 if (valued) node.value = +node.data.value;
9980 if ((childs = children(node.data)) && (n = childs.length)) {
9981 node.children = new Array(n);
9982 for (i = n - 1; i >= 0; --i) {
9983 nodes.push(child = node.children[i] = new Node(childs[i]));
9984 child.parent = node;
9985 child.depth = node.depth + 1;
9986 }
9987 }
9988 }
9989
9990 return root.eachBefore(computeHeight);
9991 }
9992
9993 function node_copy() {
9994 return hierarchy(this).eachBefore(copyData);
9995 }
9996
9997 function defaultChildren(d) {
9998 return d.children;
9999 }
10000
10001 function copyData(node) {
10002 node.data = node.data.data;
10003 }
10004
10005 function computeHeight(node) {
10006 var height = 0;
10007 do node.height = height;
10008 while ((node = node.parent) && (node.height < ++height));
10009 }
10010
10011 function Node(data) {
10012 this.data = data;
10013 this.depth =
10014 this.height = 0;
10015 this.parent = null;
10016 }
10017
10018 Node.prototype = hierarchy.prototype = {
10019 constructor: Node,
10020 count: node_count,
10021 each: node_each,
10022 eachAfter: node_eachAfter,
10023 eachBefore: node_eachBefore,
10024 sum: node_sum,
10025 sort: node_sort,
10026 path: node_path,
10027 ancestors: node_ancestors,
10028 descendants: node_descendants,
10029 leaves: node_leaves,
10030 links: node_links,
10031 copy: node_copy
10032 };
10033
10034 var slice$3 = Array.prototype.slice;
10035
10036 function shuffle$1(array) {
10037 var m = array.length,
10038 t,
10039 i;
10040
10041 while (m) {
10042 i = Math.random() * m-- | 0;
10043 t = array[m];
10044 array[m] = array[i];
10045 array[i] = t;
10046 }
10047
10048 return array;
10049 }
10050
10051 function enclose(circles) {
10052 var i = 0, n = (circles = shuffle$1(slice$3.call(circles))).length, B = [], p, e;
10053
10054 while (i < n) {
10055 p = circles[i];
10056 if (e && enclosesWeak(e, p)) ++i;
10057 else e = encloseBasis(B = extendBasis(B, p)), i = 0;
10058 }
10059
10060 return e;
10061 }
10062
10063 function extendBasis(B, p) {
10064 var i, j;
10065
10066 if (enclosesWeakAll(p, B)) return [p];
10067
10068 // If we get here then B must have at least one element.
10069 for (i = 0; i < B.length; ++i) {
10070 if (enclosesNot(p, B[i])
10071 && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
10072 return [B[i], p];
10073 }
10074 }
10075
10076 // If we get here then B must have at least two elements.
10077 for (i = 0; i < B.length - 1; ++i) {
10078 for (j = i + 1; j < B.length; ++j) {
10079 if (enclosesNot(encloseBasis2(B[i], B[j]), p)
10080 && enclosesNot(encloseBasis2(B[i], p), B[j])
10081 && enclosesNot(encloseBasis2(B[j], p), B[i])
10082 && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
10083 return [B[i], B[j], p];
10084 }
10085 }
10086 }
10087
10088 // If we get here then something is very wrong.
10089 throw new Error;
10090 }
10091
10092 function enclosesNot(a, b) {
10093 var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
10094 return dr < 0 || dr * dr < dx * dx + dy * dy;
10095 }
10096
10097 function enclosesWeak(a, b) {
10098 var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10099 return dr > 0 && dr * dr > dx * dx + dy * dy;
10100 }
10101
10102 function enclosesWeakAll(a, B) {
10103 for (var i = 0; i < B.length; ++i) {
10104 if (!enclosesWeak(a, B[i])) {
10105 return false;
10106 }
10107 }
10108 return true;
10109 }
10110
10111 function encloseBasis(B) {
10112 switch (B.length) {
10113 case 1: return encloseBasis1(B[0]);
10114 case 2: return encloseBasis2(B[0], B[1]);
10115 case 3: return encloseBasis3(B[0], B[1], B[2]);
10116 }
10117 }
10118
10119 function encloseBasis1(a) {
10120 return {
10121 x: a.x,
10122 y: a.y,
10123 r: a.r
10124 };
10125 }
10126
10127 function encloseBasis2(a, b) {
10128 var x1 = a.x, y1 = a.y, r1 = a.r,
10129 x2 = b.x, y2 = b.y, r2 = b.r,
10130 x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
10131 l = Math.sqrt(x21 * x21 + y21 * y21);
10132 return {
10133 x: (x1 + x2 + x21 / l * r21) / 2,
10134 y: (y1 + y2 + y21 / l * r21) / 2,
10135 r: (l + r1 + r2) / 2
10136 };
10137 }
10138
10139 function encloseBasis3(a, b, c) {
10140 var x1 = a.x, y1 = a.y, r1 = a.r,
10141 x2 = b.x, y2 = b.y, r2 = b.r,
10142 x3 = c.x, y3 = c.y, r3 = c.r,
10143 a2 = x1 - x2,
10144 a3 = x1 - x3,
10145 b2 = y1 - y2,
10146 b3 = y1 - y3,
10147 c2 = r2 - r1,
10148 c3 = r3 - r1,
10149 d1 = x1 * x1 + y1 * y1 - r1 * r1,
10150 d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
10151 d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
10152 ab = a3 * b2 - a2 * b3,
10153 xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
10154 xb = (b3 * c2 - b2 * c3) / ab,
10155 ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
10156 yb = (a2 * c3 - a3 * c2) / ab,
10157 A = xb * xb + yb * yb - 1,
10158 B = 2 * (r1 + xa * xb + ya * yb),
10159 C = xa * xa + ya * ya - r1 * r1,
10160 r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
10161 return {
10162 x: x1 + xa + xb * r,
10163 y: y1 + ya + yb * r,
10164 r: r
10165 };
10166 }
10167
10168 function place(a, b, c) {
10169 var ax = a.x,
10170 ay = a.y,
10171 da = b.r + c.r,
10172 db = a.r + c.r,
10173 dx = b.x - ax,
10174 dy = b.y - ay,
10175 dc = dx * dx + dy * dy;
10176 if (dc) {
10177 var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
10178 y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
10179 c.x = ax + x * dx + y * dy;
10180 c.y = ay + x * dy - y * dx;
10181 } else {
10182 c.x = ax + db;
10183 c.y = ay;
10184 }
10185 }
10186
10187 function intersects(a, b) {
10188 var dx = b.x - a.x,
10189 dy = b.y - a.y,
10190 dr = a.r + b.r;
10191 return dr * dr - 1e-6 > dx * dx + dy * dy;
10192 }
10193
10194 function score(node) {
10195 var a = node._,
10196 b = node.next._,
10197 ab = a.r + b.r,
10198 dx = (a.x * b.r + b.x * a.r) / ab,
10199 dy = (a.y * b.r + b.y * a.r) / ab;
10200 return dx * dx + dy * dy;
10201 }
10202
10203 function Node$1(circle) {
10204 this._ = circle;
10205 this.next = null;
10206 this.previous = null;
10207 }
10208
10209 function packEnclose(circles) {
10210 if (!(n = circles.length)) return 0;
10211
10212 var a, b, c, n, aa, ca, i, j, k, sj, sk;
10213
10214 // Place the first circle.
10215 a = circles[0], a.x = 0, a.y = 0;
10216 if (!(n > 1)) return a.r;
10217
10218 // Place the second circle.
10219 b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
10220 if (!(n > 2)) return a.r + b.r;
10221
10222 // Place the third circle.
10223 place(b, a, c = circles[2]);
10224
10225 // Initialize the front-chain using the first three circles a, b and c.
10226 a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
10227 a.next = c.previous = b;
10228 b.next = a.previous = c;
10229 c.next = b.previous = a;
10230
10231 // Attempt to place each remaining circle…
10232 pack: for (i = 3; i < n; ++i) {
10233 place(a._, b._, c = circles[i]), c = new Node$1(c);
10234
10235 // Find the closest intersecting circle on the front-chain, if any.
10236 // “Closeness” is determined by linear distance along the front-chain.
10237 // “Ahead” or “behind” is likewise determined by linear distance.
10238 j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
10239 do {
10240 if (sj <= sk) {
10241 if (intersects(j._, c._)) {
10242 b = j, a.next = b, b.previous = a, --i;
10243 continue pack;
10244 }
10245 sj += j._.r, j = j.next;
10246 } else {
10247 if (intersects(k._, c._)) {
10248 a = k, a.next = b, b.previous = a, --i;
10249 continue pack;
10250 }
10251 sk += k._.r, k = k.previous;
10252 }
10253 } while (j !== k.next);
10254
10255 // Success! Insert the new circle c between a and b.
10256 c.previous = a, c.next = b, a.next = b.previous = b = c;
10257
10258 // Compute the new closest circle pair to the centroid.
10259 aa = score(a);
10260 while ((c = c.next) !== b) {
10261 if ((ca = score(c)) < aa) {
10262 a = c, aa = ca;
10263 }
10264 }
10265 b = a.next;
10266 }
10267
10268 // Compute the enclosing circle of the front chain.
10269 a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
10270
10271 // Translate the circles to put the enclosing circle around the origin.
10272 for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
10273
10274 return c.r;
10275 }
10276
10277 function siblings(circles) {
10278 packEnclose(circles);
10279 return circles;
10280 }
10281
10282 function optional(f) {
10283 return f == null ? null : required(f);
10284 }
10285
10286 function required(f) {
10287 if (typeof f !== "function") throw new Error;
10288 return f;
10289 }
10290
10291 function constantZero() {
10292 return 0;
10293 }
10294
10295 function constant$8(x) {
10296 return function() {
10297 return x;
10298 };
10299 }
10300
10301 function defaultRadius$1(d) {
10302 return Math.sqrt(d.value);
10303 }
10304
10305 function index$2() {
10306 var radius = null,
10307 dx = 1,
10308 dy = 1,
10309 padding = constantZero;
10310
10311 function pack(root) {
10312 root.x = dx / 2, root.y = dy / 2;
10313 if (radius) {
10314 root.eachBefore(radiusLeaf(radius))
10315 .eachAfter(packChildren(padding, 0.5))
10316 .eachBefore(translateChild(1));
10317 } else {
10318 root.eachBefore(radiusLeaf(defaultRadius$1))
10319 .eachAfter(packChildren(constantZero, 1))
10320 .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
10321 .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
10322 }
10323 return root;
10324 }
10325
10326 pack.radius = function(x) {
10327 return arguments.length ? (radius = optional(x), pack) : radius;
10328 };
10329
10330 pack.size = function(x) {
10331 return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
10332 };
10333
10334 pack.padding = function(x) {
10335 return arguments.length ? (padding = typeof x === "function" ? x : constant$8(+x), pack) : padding;
10336 };
10337
10338 return pack;
10339 }
10340
10341 function radiusLeaf(radius) {
10342 return function(node) {
10343 if (!node.children) {
10344 node.r = Math.max(0, +radius(node) || 0);
10345 }
10346 };
10347 }
10348
10349 function packChildren(padding, k) {
10350 return function(node) {
10351 if (children = node.children) {
10352 var children,
10353 i,
10354 n = children.length,
10355 r = padding(node) * k || 0,
10356 e;
10357
10358 if (r) for (i = 0; i < n; ++i) children[i].r += r;
10359 e = packEnclose(children);
10360 if (r) for (i = 0; i < n; ++i) children[i].r -= r;
10361 node.r = e + r;
10362 }
10363 };
10364 }
10365
10366 function translateChild(k) {
10367 return function(node) {
10368 var parent = node.parent;
10369 node.r *= k;
10370 if (parent) {
10371 node.x = parent.x + k * node.x;
10372 node.y = parent.y + k * node.y;
10373 }
10374 };
10375 }
10376
10377 function roundNode(node) {
10378 node.x0 = Math.round(node.x0);
10379 node.y0 = Math.round(node.y0);
10380 node.x1 = Math.round(node.x1);
10381 node.y1 = Math.round(node.y1);
10382 }
10383
10384 function treemapDice(parent, x0, y0, x1, y1) {
10385 var nodes = parent.children,
10386 node,
10387 i = -1,
10388 n = nodes.length,
10389 k = parent.value && (x1 - x0) / parent.value;
10390
10391 while (++i < n) {
10392 node = nodes[i], node.y0 = y0, node.y1 = y1;
10393 node.x0 = x0, node.x1 = x0 += node.value * k;
10394 }
10395 }
10396
10397 function partition() {
10398 var dx = 1,
10399 dy = 1,
10400 padding = 0,
10401 round = false;
10402
10403 function partition(root) {
10404 var n = root.height + 1;
10405 root.x0 =
10406 root.y0 = padding;
10407 root.x1 = dx;
10408 root.y1 = dy / n;
10409 root.eachBefore(positionNode(dy, n));
10410 if (round) root.eachBefore(roundNode);
10411 return root;
10412 }
10413
10414 function positionNode(dy, n) {
10415 return function(node) {
10416 if (node.children) {
10417 treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
10418 }
10419 var x0 = node.x0,
10420 y0 = node.y0,
10421 x1 = node.x1 - padding,
10422 y1 = node.y1 - padding;
10423 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10424 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10425 node.x0 = x0;
10426 node.y0 = y0;
10427 node.x1 = x1;
10428 node.y1 = y1;
10429 };
10430 }
10431
10432 partition.round = function(x) {
10433 return arguments.length ? (round = !!x, partition) : round;
10434 };
10435
10436 partition.size = function(x) {
10437 return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
10438 };
10439
10440 partition.padding = function(x) {
10441 return arguments.length ? (padding = +x, partition) : padding;
10442 };
10443
10444 return partition;
10445 }
10446
10447 var keyPrefix$1 = "$";
10448 var preroot = {depth: -1};
10449 var ambiguous = {};
10450
10451 function defaultId(d) {
10452 return d.id;
10453 }
10454
10455 function defaultParentId(d) {
10456 return d.parentId;
10457 }
10458
10459 function stratify() {
10460 var id = defaultId,
10461 parentId = defaultParentId;
10462
10463 function stratify(data) {
10464 var d,
10465 i,
10466 n = data.length,
10467 root,
10468 parent,
10469 node,
10470 nodes = new Array(n),
10471 nodeId,
10472 nodeKey,
10473 nodeByKey = {};
10474
10475 for (i = 0; i < n; ++i) {
10476 d = data[i], node = nodes[i] = new Node(d);
10477 if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
10478 nodeKey = keyPrefix$1 + (node.id = nodeId);
10479 nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
10480 }
10481 }
10482
10483 for (i = 0; i < n; ++i) {
10484 node = nodes[i], nodeId = parentId(data[i], i, data);
10485 if (nodeId == null || !(nodeId += "")) {
10486 if (root) throw new Error("multiple roots");
10487 root = node;
10488 } else {
10489 parent = nodeByKey[keyPrefix$1 + nodeId];
10490 if (!parent) throw new Error("missing: " + nodeId);
10491 if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
10492 if (parent.children) parent.children.push(node);
10493 else parent.children = [node];
10494 node.parent = parent;
10495 }
10496 }
10497
10498 if (!root) throw new Error("no root");
10499 root.parent = preroot;
10500 root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
10501 root.parent = null;
10502 if (n > 0) throw new Error("cycle");
10503
10504 return root;
10505 }
10506
10507 stratify.id = function(x) {
10508 return arguments.length ? (id = required(x), stratify) : id;
10509 };
10510
10511 stratify.parentId = function(x) {
10512 return arguments.length ? (parentId = required(x), stratify) : parentId;
10513 };
10514
10515 return stratify;
10516 }
10517
10518 function defaultSeparation$1(a, b) {
10519 return a.parent === b.parent ? 1 : 2;
10520 }
10521
10522 // function radialSeparation(a, b) {
10523 // return (a.parent === b.parent ? 1 : 2) / a.depth;
10524 // }
10525
10526 // This function is used to traverse the left contour of a subtree (or
10527 // subforest). It returns the successor of v on this contour. This successor is
10528 // either given by the leftmost child of v or by the thread of v. The function
10529 // returns null if and only if v is on the highest level of its subtree.
10530 function nextLeft(v) {
10531 var children = v.children;
10532 return children ? children[0] : v.t;
10533 }
10534
10535 // This function works analogously to nextLeft.
10536 function nextRight(v) {
10537 var children = v.children;
10538 return children ? children[children.length - 1] : v.t;
10539 }
10540
10541 // Shifts the current subtree rooted at w+. This is done by increasing
10542 // prelim(w+) and mod(w+) by shift.
10543 function moveSubtree(wm, wp, shift) {
10544 var change = shift / (wp.i - wm.i);
10545 wp.c -= change;
10546 wp.s += shift;
10547 wm.c += change;
10548 wp.z += shift;
10549 wp.m += shift;
10550 }
10551
10552 // All other shifts, applied to the smaller subtrees between w- and w+, are
10553 // performed by this function. To prepare the shifts, we have to adjust
10554 // change(w+), shift(w+), and change(w-).
10555 function executeShifts(v) {
10556 var shift = 0,
10557 change = 0,
10558 children = v.children,
10559 i = children.length,
10560 w;
10561 while (--i >= 0) {
10562 w = children[i];
10563 w.z += shift;
10564 w.m += shift;
10565 shift += w.s + (change += w.c);
10566 }
10567 }
10568
10569 // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
10570 // returns the specified (default) ancestor.
10571 function nextAncestor(vim, v, ancestor) {
10572 return vim.a.parent === v.parent ? vim.a : ancestor;
10573 }
10574
10575 function TreeNode(node, i) {
10576 this._ = node;
10577 this.parent = null;
10578 this.children = null;
10579 this.A = null; // default ancestor
10580 this.a = this; // ancestor
10581 this.z = 0; // prelim
10582 this.m = 0; // mod
10583 this.c = 0; // change
10584 this.s = 0; // shift
10585 this.t = null; // thread
10586 this.i = i; // number
10587 }
10588
10589 TreeNode.prototype = Object.create(Node.prototype);
10590
10591 function treeRoot(root) {
10592 var tree = new TreeNode(root, 0),
10593 node,
10594 nodes = [tree],
10595 child,
10596 children,
10597 i,
10598 n;
10599
10600 while (node = nodes.pop()) {
10601 if (children = node._.children) {
10602 node.children = new Array(n = children.length);
10603 for (i = n - 1; i >= 0; --i) {
10604 nodes.push(child = node.children[i] = new TreeNode(children[i], i));
10605 child.parent = node;
10606 }
10607 }
10608 }
10609
10610 (tree.parent = new TreeNode(null, 0)).children = [tree];
10611 return tree;
10612 }
10613
10614 // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
10615 function tree() {
10616 var separation = defaultSeparation$1,
10617 dx = 1,
10618 dy = 1,
10619 nodeSize = null;
10620
10621 function tree(root) {
10622 var t = treeRoot(root);
10623
10624 // Compute the layout using Buchheim et al.’s algorithm.
10625 t.eachAfter(firstWalk), t.parent.m = -t.z;
10626 t.eachBefore(secondWalk);
10627
10628 // If a fixed node size is specified, scale x and y.
10629 if (nodeSize) root.eachBefore(sizeNode);
10630
10631 // If a fixed tree size is specified, scale x and y based on the extent.
10632 // Compute the left-most, right-most, and depth-most nodes for extents.
10633 else {
10634 var left = root,
10635 right = root,
10636 bottom = root;
10637 root.eachBefore(function(node) {
10638 if (node.x < left.x) left = node;
10639 if (node.x > right.x) right = node;
10640 if (node.depth > bottom.depth) bottom = node;
10641 });
10642 var s = left === right ? 1 : separation(left, right) / 2,
10643 tx = s - left.x,
10644 kx = dx / (right.x + s + tx),
10645 ky = dy / (bottom.depth || 1);
10646 root.eachBefore(function(node) {
10647 node.x = (node.x + tx) * kx;
10648 node.y = node.depth * ky;
10649 });
10650 }
10651
10652 return root;
10653 }
10654
10655 // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
10656 // applied recursively to the children of v, as well as the function
10657 // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
10658 // node v is placed to the midpoint of its outermost children.
10659 function firstWalk(v) {
10660 var children = v.children,
10661 siblings = v.parent.children,
10662 w = v.i ? siblings[v.i - 1] : null;
10663 if (children) {
10664 executeShifts(v);
10665 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
10666 if (w) {
10667 v.z = w.z + separation(v._, w._);
10668 v.m = v.z - midpoint;
10669 } else {
10670 v.z = midpoint;
10671 }
10672 } else if (w) {
10673 v.z = w.z + separation(v._, w._);
10674 }
10675 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
10676 }
10677
10678 // Computes all real x-coordinates by summing up the modifiers recursively.
10679 function secondWalk(v) {
10680 v._.x = v.z + v.parent.m;
10681 v.m += v.parent.m;
10682 }
10683
10684 // The core of the algorithm. Here, a new subtree is combined with the
10685 // previous subtrees. Threads are used to traverse the inside and outside
10686 // contours of the left and right subtree up to the highest common level. The
10687 // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
10688 // superscript o means outside and i means inside, the subscript - means left
10689 // subtree and + means right subtree. For summing up the modifiers along the
10690 // contour, we use respective variables si+, si-, so-, and so+. Whenever two
10691 // nodes of the inside contours conflict, we compute the left one of the
10692 // greatest uncommon ancestors using the function ANCESTOR and call MOVE
10693 // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
10694 // Finally, we add a new thread (if necessary).
10695 function apportion(v, w, ancestor) {
10696 if (w) {
10697 var vip = v,
10698 vop = v,
10699 vim = w,
10700 vom = vip.parent.children[0],
10701 sip = vip.m,
10702 sop = vop.m,
10703 sim = vim.m,
10704 som = vom.m,
10705 shift;
10706 while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
10707 vom = nextLeft(vom);
10708 vop = nextRight(vop);
10709 vop.a = v;
10710 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
10711 if (shift > 0) {
10712 moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
10713 sip += shift;
10714 sop += shift;
10715 }
10716 sim += vim.m;
10717 sip += vip.m;
10718 som += vom.m;
10719 sop += vop.m;
10720 }
10721 if (vim && !nextRight(vop)) {
10722 vop.t = vim;
10723 vop.m += sim - sop;
10724 }
10725 if (vip && !nextLeft(vom)) {
10726 vom.t = vip;
10727 vom.m += sip - som;
10728 ancestor = v;
10729 }
10730 }
10731 return ancestor;
10732 }
10733
10734 function sizeNode(node) {
10735 node.x *= dx;
10736 node.y = node.depth * dy;
10737 }
10738
10739 tree.separation = function(x) {
10740 return arguments.length ? (separation = x, tree) : separation;
10741 };
10742
10743 tree.size = function(x) {
10744 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
10745 };
10746
10747 tree.nodeSize = function(x) {
10748 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
10749 };
10750
10751 return tree;
10752 }
10753
10754 function treemapSlice(parent, x0, y0, x1, y1) {
10755 var nodes = parent.children,
10756 node,
10757 i = -1,
10758 n = nodes.length,
10759 k = parent.value && (y1 - y0) / parent.value;
10760
10761 while (++i < n) {
10762 node = nodes[i], node.x0 = x0, node.x1 = x1;
10763 node.y0 = y0, node.y1 = y0 += node.value * k;
10764 }
10765 }
10766
10767 var phi = (1 + Math.sqrt(5)) / 2;
10768
10769 function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
10770 var rows = [],
10771 nodes = parent.children,
10772 row,
10773 nodeValue,
10774 i0 = 0,
10775 i1 = 0,
10776 n = nodes.length,
10777 dx, dy,
10778 value = parent.value,
10779 sumValue,
10780 minValue,
10781 maxValue,
10782 newRatio,
10783 minRatio,
10784 alpha,
10785 beta;
10786
10787 while (i0 < n) {
10788 dx = x1 - x0, dy = y1 - y0;
10789
10790 // Find the next non-empty node.
10791 do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
10792 minValue = maxValue = sumValue;
10793 alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
10794 beta = sumValue * sumValue * alpha;
10795 minRatio = Math.max(maxValue / beta, beta / minValue);
10796
10797 // Keep adding nodes while the aspect ratio maintains or improves.
10798 for (; i1 < n; ++i1) {
10799 sumValue += nodeValue = nodes[i1].value;
10800 if (nodeValue < minValue) minValue = nodeValue;
10801 if (nodeValue > maxValue) maxValue = nodeValue;
10802 beta = sumValue * sumValue * alpha;
10803 newRatio = Math.max(maxValue / beta, beta / minValue);
10804 if (newRatio > minRatio) { sumValue -= nodeValue; break; }
10805 minRatio = newRatio;
10806 }
10807
10808 // Position and record the row orientation.
10809 rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
10810 if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
10811 else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
10812 value -= sumValue, i0 = i1;
10813 }
10814
10815 return rows;
10816 }
10817
10818 var squarify = (function custom(ratio) {
10819
10820 function squarify(parent, x0, y0, x1, y1) {
10821 squarifyRatio(ratio, parent, x0, y0, x1, y1);
10822 }
10823
10824 squarify.ratio = function(x) {
10825 return custom((x = +x) > 1 ? x : 1);
10826 };
10827
10828 return squarify;
10829 })(phi);
10830
10831 function index$3() {
10832 var tile = squarify,
10833 round = false,
10834 dx = 1,
10835 dy = 1,
10836 paddingStack = [0],
10837 paddingInner = constantZero,
10838 paddingTop = constantZero,
10839 paddingRight = constantZero,
10840 paddingBottom = constantZero,
10841 paddingLeft = constantZero;
10842
10843 function treemap(root) {
10844 root.x0 =
10845 root.y0 = 0;
10846 root.x1 = dx;
10847 root.y1 = dy;
10848 root.eachBefore(positionNode);
10849 paddingStack = [0];
10850 if (round) root.eachBefore(roundNode);
10851 return root;
10852 }
10853
10854 function positionNode(node) {
10855 var p = paddingStack[node.depth],
10856 x0 = node.x0 + p,
10857 y0 = node.y0 + p,
10858 x1 = node.x1 - p,
10859 y1 = node.y1 - p;
10860 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10861 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10862 node.x0 = x0;
10863 node.y0 = y0;
10864 node.x1 = x1;
10865 node.y1 = y1;
10866 if (node.children) {
10867 p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
10868 x0 += paddingLeft(node) - p;
10869 y0 += paddingTop(node) - p;
10870 x1 -= paddingRight(node) - p;
10871 y1 -= paddingBottom(node) - p;
10872 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10873 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10874 tile(node, x0, y0, x1, y1);
10875 }
10876 }
10877
10878 treemap.round = function(x) {
10879 return arguments.length ? (round = !!x, treemap) : round;
10880 };
10881
10882 treemap.size = function(x) {
10883 return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
10884 };
10885
10886 treemap.tile = function(x) {
10887 return arguments.length ? (tile = required(x), treemap) : tile;
10888 };
10889
10890 treemap.padding = function(x) {
10891 return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
10892 };
10893
10894 treemap.paddingInner = function(x) {
10895 return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$8(+x), treemap) : paddingInner;
10896 };
10897
10898 treemap.paddingOuter = function(x) {
10899 return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
10900 };
10901
10902 treemap.paddingTop = function(x) {
10903 return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$8(+x), treemap) : paddingTop;
10904 };
10905
10906 treemap.paddingRight = function(x) {
10907 return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$8(+x), treemap) : paddingRight;
10908 };
10909
10910 treemap.paddingBottom = function(x) {
10911 return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$8(+x), treemap) : paddingBottom;
10912 };
10913
10914 treemap.paddingLeft = function(x) {
10915 return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$8(+x), treemap) : paddingLeft;
10916 };
10917
10918 return treemap;
10919 }
10920
10921 function binary(parent, x0, y0, x1, y1) {
10922 var nodes = parent.children,
10923 i, n = nodes.length,
10924 sum, sums = new Array(n + 1);
10925
10926 for (sums[0] = sum = i = 0; i < n; ++i) {
10927 sums[i + 1] = sum += nodes[i].value;
10928 }
10929
10930 partition(0, n, parent.value, x0, y0, x1, y1);
10931
10932 function partition(i, j, value, x0, y0, x1, y1) {
10933 if (i >= j - 1) {
10934 var node = nodes[i];
10935 node.x0 = x0, node.y0 = y0;
10936 node.x1 = x1, node.y1 = y1;
10937 return;
10938 }
10939
10940 var valueOffset = sums[i],
10941 valueTarget = (value / 2) + valueOffset,
10942 k = i + 1,
10943 hi = j - 1;
10944
10945 while (k < hi) {
10946 var mid = k + hi >>> 1;
10947 if (sums[mid] < valueTarget) k = mid + 1;
10948 else hi = mid;
10949 }
10950
10951 if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
10952
10953 var valueLeft = sums[k] - valueOffset,
10954 valueRight = value - valueLeft;
10955
10956 if ((x1 - x0) > (y1 - y0)) {
10957 var xk = (x0 * valueRight + x1 * valueLeft) / value;
10958 partition(i, k, valueLeft, x0, y0, xk, y1);
10959 partition(k, j, valueRight, xk, y0, x1, y1);
10960 } else {
10961 var yk = (y0 * valueRight + y1 * valueLeft) / value;
10962 partition(i, k, valueLeft, x0, y0, x1, yk);
10963 partition(k, j, valueRight, x0, yk, x1, y1);
10964 }
10965 }
10966 }
10967
10968 function sliceDice(parent, x0, y0, x1, y1) {
10969 (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
10970 }
10971
10972 var resquarify = (function custom(ratio) {
10973
10974 function resquarify(parent, x0, y0, x1, y1) {
10975 if ((rows = parent._squarify) && (rows.ratio === ratio)) {
10976 var rows,
10977 row,
10978 nodes,
10979 i,
10980 j = -1,
10981 n,
10982 m = rows.length,
10983 value = parent.value;
10984
10985 while (++j < m) {
10986 row = rows[j], nodes = row.children;
10987 for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
10988 if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
10989 else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
10990 value -= row.value;
10991 }
10992 } else {
10993 parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
10994 rows.ratio = ratio;
10995 }
10996 }
10997
10998 resquarify.ratio = function(x) {
10999 return custom((x = +x) > 1 ? x : 1);
11000 };
11001
11002 return resquarify;
11003 })(phi);
11004
11005 function area$1(polygon) {
11006 var i = -1,
11007 n = polygon.length,
11008 a,
11009 b = polygon[n - 1],
11010 area = 0;
11011
11012 while (++i < n) {
11013 a = b;
11014 b = polygon[i];
11015 area += a[1] * b[0] - a[0] * b[1];
11016 }
11017
11018 return area / 2;
11019 }
11020
11021 function centroid$1(polygon) {
11022 var i = -1,
11023 n = polygon.length,
11024 x = 0,
11025 y = 0,
11026 a,
11027 b = polygon[n - 1],
11028 c,
11029 k = 0;
11030
11031 while (++i < n) {
11032 a = b;
11033 b = polygon[i];
11034 k += c = a[0] * b[1] - b[0] * a[1];
11035 x += (a[0] + b[0]) * c;
11036 y += (a[1] + b[1]) * c;
11037 }
11038
11039 return k *= 3, [x / k, y / k];
11040 }
11041
11042 // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
11043 // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
11044 // right, +y is up). Returns a positive value if ABC is counter-clockwise,
11045 // negative if clockwise, and zero if the points are collinear.
11046 function cross$1(a, b, c) {
11047 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
11048 }
11049
11050 function lexicographicOrder(a, b) {
11051 return a[0] - b[0] || a[1] - b[1];
11052 }
11053
11054 // Computes the upper convex hull per the monotone chain algorithm.
11055 // Assumes points.length >= 3, is sorted by x, unique in y.
11056 // Returns an array of indices into points in left-to-right order.
11057 function computeUpperHullIndexes(points) {
11058 var n = points.length,
11059 indexes = [0, 1],
11060 size = 2;
11061
11062 for (var i = 2; i < n; ++i) {
11063 while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
11064 indexes[size++] = i;
11065 }
11066
11067 return indexes.slice(0, size); // remove popped points
11068 }
11069
11070 function hull(points) {
11071 if ((n = points.length) < 3) return null;
11072
11073 var i,
11074 n,
11075 sortedPoints = new Array(n),
11076 flippedPoints = new Array(n);
11077
11078 for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
11079 sortedPoints.sort(lexicographicOrder);
11080 for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
11081
11082 var upperIndexes = computeUpperHullIndexes(sortedPoints),
11083 lowerIndexes = computeUpperHullIndexes(flippedPoints);
11084
11085 // Construct the hull polygon, removing possible duplicate endpoints.
11086 var skipLeft = lowerIndexes[0] === upperIndexes[0],
11087 skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
11088 hull = [];
11089
11090 // Add upper hull in right-to-l order.
11091 // Then add lower hull in left-to-right order.
11092 for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
11093 for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
11094
11095 return hull;
11096 }
11097
11098 function contains$1(polygon, point) {
11099 var n = polygon.length,
11100 p = polygon[n - 1],
11101 x = point[0], y = point[1],
11102 x0 = p[0], y0 = p[1],
11103 x1, y1,
11104 inside = false;
11105
11106 for (var i = 0; i < n; ++i) {
11107 p = polygon[i], x1 = p[0], y1 = p[1];
11108 if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
11109 x0 = x1, y0 = y1;
11110 }
11111
11112 return inside;
11113 }
11114
11115 function length$2(polygon) {
11116 var i = -1,
11117 n = polygon.length,
11118 b = polygon[n - 1],
11119 xa,
11120 ya,
11121 xb = b[0],
11122 yb = b[1],
11123 perimeter = 0;
11124
11125 while (++i < n) {
11126 xa = xb;
11127 ya = yb;
11128 b = polygon[i];
11129 xb = b[0];
11130 yb = b[1];
11131 xa -= xb;
11132 ya -= yb;
11133 perimeter += Math.sqrt(xa * xa + ya * ya);
11134 }
11135
11136 return perimeter;
11137 }
11138
11139 var slice$4 = [].slice;
11140
11141 var noabort = {};
11142
11143 function Queue(size) {
11144 this._size = size;
11145 this._call =
11146 this._error = null;
11147 this._tasks = [];
11148 this._data = [];
11149 this._waiting =
11150 this._active =
11151 this._ended =
11152 this._start = 0; // inside a synchronous task callback?
11153 }
11154
11155 Queue.prototype = queue.prototype = {
11156 constructor: Queue,
11157 defer: function(callback) {
11158 if (typeof callback !== "function") throw new Error("invalid callback");
11159 if (this._call) throw new Error("defer after await");
11160 if (this._error != null) return this;
11161 var t = slice$4.call(arguments, 1);
11162 t.push(callback);
11163 ++this._waiting, this._tasks.push(t);
11164 poke$1(this);
11165 return this;
11166 },
11167 abort: function() {
11168 if (this._error == null) abort(this, new Error("abort"));
11169 return this;
11170 },
11171 await: function(callback) {
11172 if (typeof callback !== "function") throw new Error("invalid callback");
11173 if (this._call) throw new Error("multiple await");
11174 this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
11175 maybeNotify(this);
11176 return this;
11177 },
11178 awaitAll: function(callback) {
11179 if (typeof callback !== "function") throw new Error("invalid callback");
11180 if (this._call) throw new Error("multiple await");
11181 this._call = callback;
11182 maybeNotify(this);
11183 return this;
11184 }
11185 };
11186
11187 function poke$1(q) {
11188 if (!q._start) {
11189 try { start$1(q); } // let the current task complete
11190 catch (e) {
11191 if (q._tasks[q._ended + q._active - 1]) abort(q, e); // task errored synchronously
11192 else if (!q._data) throw e; // await callback errored synchronously
11193 }
11194 }
11195 }
11196
11197 function start$1(q) {
11198 while (q._start = q._waiting && q._active < q._size) {
11199 var i = q._ended + q._active,
11200 t = q._tasks[i],
11201 j = t.length - 1,
11202 c = t[j];
11203 t[j] = end(q, i);
11204 --q._waiting, ++q._active;
11205 t = c.apply(null, t);
11206 if (!q._tasks[i]) continue; // task finished synchronously
11207 q._tasks[i] = t || noabort;
11208 }
11209 }
11210
11211 function end(q, i) {
11212 return function(e, r) {
11213 if (!q._tasks[i]) return; // ignore multiple callbacks
11214 --q._active, ++q._ended;
11215 q._tasks[i] = null;
11216 if (q._error != null) return; // ignore secondary errors
11217 if (e != null) {
11218 abort(q, e);
11219 } else {
11220 q._data[i] = r;
11221 if (q._waiting) poke$1(q);
11222 else maybeNotify(q);
11223 }
11224 };
11225 }
11226
11227 function abort(q, e) {
11228 var i = q._tasks.length, t;
11229 q._error = e; // ignore active callbacks
11230 q._data = undefined; // allow gc
11231 q._waiting = NaN; // prevent starting
11232
11233 while (--i >= 0) {
11234 if (t = q._tasks[i]) {
11235 q._tasks[i] = null;
11236 if (t.abort) {
11237 try { t.abort(); }
11238 catch (e) { /* ignore */ }
11239 }
11240 }
11241 }
11242
11243 q._active = NaN; // allow notification
11244 maybeNotify(q);
11245 }
11246
11247 function maybeNotify(q) {
11248 if (!q._active && q._call) {
11249 var d = q._data;
11250 q._data = undefined; // allow gc
11251 q._call(q._error, d);
11252 }
11253 }
11254
11255 function queue(concurrency) {
11256 if (concurrency == null) concurrency = Infinity;
11257 else if (!((concurrency = +concurrency) >= 1)) throw new Error("invalid concurrency");
11258 return new Queue(concurrency);
11259 }
11260
11261 function defaultSource$1() {
11262 return Math.random();
11263 }
11264
11265 var uniform = (function sourceRandomUniform(source) {
11266 function randomUniform(min, max) {
11267 min = min == null ? 0 : +min;
11268 max = max == null ? 1 : +max;
11269 if (arguments.length === 1) max = min, min = 0;
11270 else max -= min;
11271 return function() {
11272 return source() * max + min;
11273 };
11274 }
11275
11276 randomUniform.source = sourceRandomUniform;
11277
11278 return randomUniform;
11279 })(defaultSource$1);
11280
11281 var normal = (function sourceRandomNormal(source) {
11282 function randomNormal(mu, sigma) {
11283 var x, r;
11284 mu = mu == null ? 0 : +mu;
11285 sigma = sigma == null ? 1 : +sigma;
11286 return function() {
11287 var y;
11288
11289 // If available, use the second previously-generated uniform random.
11290 if (x != null) y = x, x = null;
11291
11292 // Otherwise, generate a new x and y.
11293 else do {
11294 x = source() * 2 - 1;
11295 y = source() * 2 - 1;
11296 r = x * x + y * y;
11297 } while (!r || r > 1);
11298
11299 return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
11300 };
11301 }
11302
11303 randomNormal.source = sourceRandomNormal;
11304
11305 return randomNormal;
11306 })(defaultSource$1);
11307
11308 var logNormal = (function sourceRandomLogNormal(source) {
11309 function randomLogNormal() {
11310 var randomNormal = normal.source(source).apply(this, arguments);
11311 return function() {
11312 return Math.exp(randomNormal());
11313 };
11314 }
11315
11316 randomLogNormal.source = sourceRandomLogNormal;
11317
11318 return randomLogNormal;
11319 })(defaultSource$1);
11320
11321 var irwinHall = (function sourceRandomIrwinHall(source) {
11322 function randomIrwinHall(n) {
11323 return function() {
11324 for (var sum = 0, i = 0; i < n; ++i) sum += source();
11325 return sum;
11326 };
11327 }
11328
11329 randomIrwinHall.source = sourceRandomIrwinHall;
11330
11331 return randomIrwinHall;
11332 })(defaultSource$1);
11333
11334 var bates = (function sourceRandomBates(source) {
11335 function randomBates(n) {
11336 var randomIrwinHall = irwinHall.source(source)(n);
11337 return function() {
11338 return randomIrwinHall() / n;
11339 };
11340 }
11341
11342 randomBates.source = sourceRandomBates;
11343
11344 return randomBates;
11345 })(defaultSource$1);
11346
11347 var exponential$1 = (function sourceRandomExponential(source) {
11348 function randomExponential(lambda) {
11349 return function() {
11350 return -Math.log(1 - source()) / lambda;
11351 };
11352 }
11353
11354 randomExponential.source = sourceRandomExponential;
11355
11356 return randomExponential;
11357 })(defaultSource$1);
11358
11359 function request(url, callback) {
11360 var request,
11361 event = dispatch("beforesend", "progress", "load", "error"),
11362 mimeType,
11363 headers = map$1(),
11364 xhr = new XMLHttpRequest,
11365 user = null,
11366 password = null,
11367 response,
11368 responseType,
11369 timeout = 0;
11370
11371 // If IE does not support CORS, use XDomainRequest.
11372 if (typeof XDomainRequest !== "undefined"
11373 && !("withCredentials" in xhr)
11374 && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
11375
11376 "onload" in xhr
11377 ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
11378 : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
11379
11380 function respond(o) {
11381 var status = xhr.status, result;
11382 if (!status && hasResponse(xhr)
11383 || status >= 200 && status < 300
11384 || status === 304) {
11385 if (response) {
11386 try {
11387 result = response.call(request, xhr);
11388 } catch (e) {
11389 event.call("error", request, e);
11390 return;
11391 }
11392 } else {
11393 result = xhr;
11394 }
11395 event.call("load", request, result);
11396 } else {
11397 event.call("error", request, o);
11398 }
11399 }
11400
11401 xhr.onprogress = function(e) {
11402 event.call("progress", request, e);
11403 };
11404
11405 request = {
11406 header: function(name, value) {
11407 name = (name + "").toLowerCase();
11408 if (arguments.length < 2) return headers.get(name);
11409 if (value == null) headers.remove(name);
11410 else headers.set(name, value + "");
11411 return request;
11412 },
11413
11414 // If mimeType is non-null and no Accept header is set, a default is used.
11415 mimeType: function(value) {
11416 if (!arguments.length) return mimeType;
11417 mimeType = value == null ? null : value + "";
11418 return request;
11419 },
11420
11421 // Specifies what type the response value should take;
11422 // for instance, arraybuffer, blob, document, or text.
11423 responseType: function(value) {
11424 if (!arguments.length) return responseType;
11425 responseType = value;
11426 return request;
11427 },
11428
11429 timeout: function(value) {
11430 if (!arguments.length) return timeout;
11431 timeout = +value;
11432 return request;
11433 },
11434
11435 user: function(value) {
11436 return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
11437 },
11438
11439 password: function(value) {
11440 return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
11441 },
11442
11443 // Specify how to convert the response content to a specific type;
11444 // changes the callback value on "load" events.
11445 response: function(value) {
11446 response = value;
11447 return request;
11448 },
11449
11450 // Alias for send("GET", …).
11451 get: function(data, callback) {
11452 return request.send("GET", data, callback);
11453 },
11454
11455 // Alias for send("POST", …).
11456 post: function(data, callback) {
11457 return request.send("POST", data, callback);
11458 },
11459
11460 // If callback is non-null, it will be used for error and load events.
11461 send: function(method, data, callback) {
11462 xhr.open(method, url, true, user, password);
11463 if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
11464 if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
11465 if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
11466 if (responseType != null) xhr.responseType = responseType;
11467 if (timeout > 0) xhr.timeout = timeout;
11468 if (callback == null && typeof data === "function") callback = data, data = null;
11469 if (callback != null && callback.length === 1) callback = fixCallback(callback);
11470 if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
11471 event.call("beforesend", request, xhr);
11472 xhr.send(data == null ? null : data);
11473 return request;
11474 },
11475
11476 abort: function() {
11477 xhr.abort();
11478 return request;
11479 },
11480
11481 on: function() {
11482 var value = event.on.apply(event, arguments);
11483 return value === event ? request : value;
11484 }
11485 };
11486
11487 if (callback != null) {
11488 if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
11489 return request.get(callback);
11490 }
11491
11492 return request;
11493 }
11494
11495 function fixCallback(callback) {
11496 return function(error, xhr) {
11497 callback(error == null ? xhr : null);
11498 };
11499 }
11500
11501 function hasResponse(xhr) {
11502 var type = xhr.responseType;
11503 return type && type !== "text"
11504 ? xhr.response // null on error
11505 : xhr.responseText; // "" on error
11506 }
11507
11508 function type$1(defaultMimeType, response) {
11509 return function(url, callback) {
11510 var r = request(url).mimeType(defaultMimeType).response(response);
11511 if (callback != null) {
11512 if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
11513 return r.get(callback);
11514 }
11515 return r;
11516 };
11517 }
11518
11519 var html = type$1("text/html", function(xhr) {
11520 return document.createRange().createContextualFragment(xhr.responseText);
11521 });
11522
11523 var json = type$1("application/json", function(xhr) {
11524 return JSON.parse(xhr.responseText);
11525 });
11526
11527 var text = type$1("text/plain", function(xhr) {
11528 return xhr.responseText;
11529 });
11530
11531 var xml = type$1("application/xml", function(xhr) {
11532 var xml = xhr.responseXML;
11533 if (!xml) throw new Error("parse error");
11534 return xml;
11535 });
11536
11537 function dsv$1(defaultMimeType, parse) {
11538 return function(url, row, callback) {
11539 if (arguments.length < 3) callback = row, row = null;
11540 var r = request(url).mimeType(defaultMimeType);
11541 r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
11542 r.row(row);
11543 return callback ? r.get(callback) : r;
11544 };
11545 }
11546
11547 function responseOf(parse, row) {
11548 return function(request$$1) {
11549 return parse(request$$1.responseText, row);
11550 };
11551 }
11552
11553 var csv$1 = dsv$1("text/csv", csvParse);
11554
11555 var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
11556
11557 var array$2 = Array.prototype;
11558
11559 var map$3 = array$2.map;
11560 var slice$5 = array$2.slice;
11561
11562 var implicit = {name: "implicit"};
11563
11564 function ordinal(range) {
11565 var index = map$1(),
11566 domain = [],
11567 unknown = implicit;
11568
11569 range = range == null ? [] : slice$5.call(range);
11570
11571 function scale(d) {
11572 var key = d + "", i = index.get(key);
11573 if (!i) {
11574 if (unknown !== implicit) return unknown;
11575 index.set(key, i = domain.push(d));
11576 }
11577 return range[(i - 1) % range.length];
11578 }
11579
11580 scale.domain = function(_) {
11581 if (!arguments.length) return domain.slice();
11582 domain = [], index = map$1();
11583 var i = -1, n = _.length, d, key;
11584 while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
11585 return scale;
11586 };
11587
11588 scale.range = function(_) {
11589 return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
11590 };
11591
11592 scale.unknown = function(_) {
11593 return arguments.length ? (unknown = _, scale) : unknown;
11594 };
11595
11596 scale.copy = function() {
11597 return ordinal()
11598 .domain(domain)
11599 .range(range)
11600 .unknown(unknown);
11601 };
11602
11603 return scale;
11604 }
11605
11606 function band() {
11607 var scale = ordinal().unknown(undefined),
11608 domain = scale.domain,
11609 ordinalRange = scale.range,
11610 range$$1 = [0, 1],
11611 step,
11612 bandwidth,
11613 round = false,
11614 paddingInner = 0,
11615 paddingOuter = 0,
11616 align = 0.5;
11617
11618 delete scale.unknown;
11619
11620 function rescale() {
11621 var n = domain().length,
11622 reverse = range$$1[1] < range$$1[0],
11623 start = range$$1[reverse - 0],
11624 stop = range$$1[1 - reverse];
11625 step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
11626 if (round) step = Math.floor(step);
11627 start += (stop - start - step * (n - paddingInner)) * align;
11628 bandwidth = step * (1 - paddingInner);
11629 if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
11630 var values = sequence(n).map(function(i) { return start + step * i; });
11631 return ordinalRange(reverse ? values.reverse() : values);
11632 }
11633
11634 scale.domain = function(_) {
11635 return arguments.length ? (domain(_), rescale()) : domain();
11636 };
11637
11638 scale.range = function(_) {
11639 return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
11640 };
11641
11642 scale.rangeRound = function(_) {
11643 return range$$1 = [+_[0], +_[1]], round = true, rescale();
11644 };
11645
11646 scale.bandwidth = function() {
11647 return bandwidth;
11648 };
11649
11650 scale.step = function() {
11651 return step;
11652 };
11653
11654 scale.round = function(_) {
11655 return arguments.length ? (round = !!_, rescale()) : round;
11656 };
11657
11658 scale.padding = function(_) {
11659 return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11660 };
11661
11662 scale.paddingInner = function(_) {
11663 return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11664 };
11665
11666 scale.paddingOuter = function(_) {
11667 return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
11668 };
11669
11670 scale.align = function(_) {
11671 return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
11672 };
11673
11674 scale.copy = function() {
11675 return band()
11676 .domain(domain())
11677 .range(range$$1)
11678 .round(round)
11679 .paddingInner(paddingInner)
11680 .paddingOuter(paddingOuter)
11681 .align(align);
11682 };
11683
11684 return rescale();
11685 }
11686
11687 function pointish(scale) {
11688 var copy = scale.copy;
11689
11690 scale.padding = scale.paddingOuter;
11691 delete scale.paddingInner;
11692 delete scale.paddingOuter;
11693
11694 scale.copy = function() {
11695 return pointish(copy());
11696 };
11697
11698 return scale;
11699 }
11700
11701 function point$1() {
11702 return pointish(band().paddingInner(1));
11703 }
11704
11705 function constant$9(x) {
11706 return function() {
11707 return x;
11708 };
11709 }
11710
11711 function number$2(x) {
11712 return +x;
11713 }
11714
11715 var unit = [0, 1];
11716
11717 function deinterpolateLinear(a, b) {
11718 return (b -= (a = +a))
11719 ? function(x) { return (x - a) / b; }
11720 : constant$9(b);
11721 }
11722
11723 function deinterpolateClamp(deinterpolate) {
11724 return function(a, b) {
11725 var d = deinterpolate(a = +a, b = +b);
11726 return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
11727 };
11728 }
11729
11730 function reinterpolateClamp(reinterpolate) {
11731 return function(a, b) {
11732 var r = reinterpolate(a = +a, b = +b);
11733 return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
11734 };
11735 }
11736
11737 function bimap(domain, range, deinterpolate, reinterpolate) {
11738 var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
11739 if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
11740 else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
11741 return function(x) { return r0(d0(x)); };
11742 }
11743
11744 function polymap(domain, range, deinterpolate, reinterpolate) {
11745 var j = Math.min(domain.length, range.length) - 1,
11746 d = new Array(j),
11747 r = new Array(j),
11748 i = -1;
11749
11750 // Reverse descending domains.
11751 if (domain[j] < domain[0]) {
11752 domain = domain.slice().reverse();
11753 range = range.slice().reverse();
11754 }
11755
11756 while (++i < j) {
11757 d[i] = deinterpolate(domain[i], domain[i + 1]);
11758 r[i] = reinterpolate(range[i], range[i + 1]);
11759 }
11760
11761 return function(x) {
11762 var i = bisectRight(domain, x, 1, j) - 1;
11763 return r[i](d[i](x));
11764 };
11765 }
11766
11767 function copy(source, target) {
11768 return target
11769 .domain(source.domain())
11770 .range(source.range())
11771 .interpolate(source.interpolate())
11772 .clamp(source.clamp());
11773 }
11774
11775 // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
11776 // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
11777 function continuous(deinterpolate, reinterpolate) {
11778 var domain = unit,
11779 range = unit,
11780 interpolate$$1 = interpolateValue,
11781 clamp = false,
11782 piecewise,
11783 output,
11784 input;
11785
11786 function rescale() {
11787 piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
11788 output = input = null;
11789 return scale;
11790 }
11791
11792 function scale(x) {
11793 return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
11794 }
11795
11796 scale.invert = function(y) {
11797 return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
11798 };
11799
11800 scale.domain = function(_) {
11801 return arguments.length ? (domain = map$3.call(_, number$2), rescale()) : domain.slice();
11802 };
11803
11804 scale.range = function(_) {
11805 return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
11806 };
11807
11808 scale.rangeRound = function(_) {
11809 return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
11810 };
11811
11812 scale.clamp = function(_) {
11813 return arguments.length ? (clamp = !!_, rescale()) : clamp;
11814 };
11815
11816 scale.interpolate = function(_) {
11817 return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
11818 };
11819
11820 return rescale();
11821 }
11822
11823 function tickFormat(domain, count, specifier) {
11824 var start = domain[0],
11825 stop = domain[domain.length - 1],
11826 step = tickStep(start, stop, count == null ? 10 : count),
11827 precision;
11828 specifier = formatSpecifier(specifier == null ? ",f" : specifier);
11829 switch (specifier.type) {
11830 case "s": {
11831 var value = Math.max(Math.abs(start), Math.abs(stop));
11832 if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
11833 return exports.formatPrefix(specifier, value);
11834 }
11835 case "":
11836 case "e":
11837 case "g":
11838 case "p":
11839 case "r": {
11840 if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
11841 break;
11842 }
11843 case "f":
11844 case "%": {
11845 if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
11846 break;
11847 }
11848 }
11849 return exports.format(specifier);
11850 }
11851
11852 function linearish(scale) {
11853 var domain = scale.domain;
11854
11855 scale.ticks = function(count) {
11856 var d = domain();
11857 return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
11858 };
11859
11860 scale.tickFormat = function(count, specifier) {
11861 return tickFormat(domain(), count, specifier);
11862 };
11863
11864 scale.nice = function(count) {
11865 if (count == null) count = 10;
11866
11867 var d = domain(),
11868 i0 = 0,
11869 i1 = d.length - 1,
11870 start = d[i0],
11871 stop = d[i1],
11872 step;
11873
11874 if (stop < start) {
11875 step = start, start = stop, stop = step;
11876 step = i0, i0 = i1, i1 = step;
11877 }
11878
11879 step = tickIncrement(start, stop, count);
11880
11881 if (step > 0) {
11882 start = Math.floor(start / step) * step;
11883 stop = Math.ceil(stop / step) * step;
11884 step = tickIncrement(start, stop, count);
11885 } else if (step < 0) {
11886 start = Math.ceil(start * step) / step;
11887 stop = Math.floor(stop * step) / step;
11888 step = tickIncrement(start, stop, count);
11889 }
11890
11891 if (step > 0) {
11892 d[i0] = Math.floor(start / step) * step;
11893 d[i1] = Math.ceil(stop / step) * step;
11894 domain(d);
11895 } else if (step < 0) {
11896 d[i0] = Math.ceil(start * step) / step;
11897 d[i1] = Math.floor(stop * step) / step;
11898 domain(d);
11899 }
11900
11901 return scale;
11902 };
11903
11904 return scale;
11905 }
11906
11907 function linear$2() {
11908 var scale = continuous(deinterpolateLinear, reinterpolate);
11909
11910 scale.copy = function() {
11911 return copy(scale, linear$2());
11912 };
11913
11914 return linearish(scale);
11915 }
11916
11917 function identity$6() {
11918 var domain = [0, 1];
11919
11920 function scale(x) {
11921 return +x;
11922 }
11923
11924 scale.invert = scale;
11925
11926 scale.domain = scale.range = function(_) {
11927 return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
11928 };
11929
11930 scale.copy = function() {
11931 return identity$6().domain(domain);
11932 };
11933
11934 return linearish(scale);
11935 }
11936
11937 function nice(domain, interval) {
11938 domain = domain.slice();
11939
11940 var i0 = 0,
11941 i1 = domain.length - 1,
11942 x0 = domain[i0],
11943 x1 = domain[i1],
11944 t;
11945
11946 if (x1 < x0) {
11947 t = i0, i0 = i1, i1 = t;
11948 t = x0, x0 = x1, x1 = t;
11949 }
11950
11951 domain[i0] = interval.floor(x0);
11952 domain[i1] = interval.ceil(x1);
11953 return domain;
11954 }
11955
11956 function deinterpolate(a, b) {
11957 return (b = Math.log(b / a))
11958 ? function(x) { return Math.log(x / a) / b; }
11959 : constant$9(b);
11960 }
11961
11962 function reinterpolate$1(a, b) {
11963 return a < 0
11964 ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
11965 : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
11966 }
11967
11968 function pow10(x) {
11969 return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
11970 }
11971
11972 function powp(base) {
11973 return base === 10 ? pow10
11974 : base === Math.E ? Math.exp
11975 : function(x) { return Math.pow(base, x); };
11976 }
11977
11978 function logp(base) {
11979 return base === Math.E ? Math.log
11980 : base === 10 && Math.log10
11981 || base === 2 && Math.log2
11982 || (base = Math.log(base), function(x) { return Math.log(x) / base; });
11983 }
11984
11985 function reflect(f) {
11986 return function(x) {
11987 return -f(-x);
11988 };
11989 }
11990
11991 function log$1() {
11992 var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
11993 domain = scale.domain,
11994 base = 10,
11995 logs = logp(10),
11996 pows = powp(10);
11997
11998 function rescale() {
11999 logs = logp(base), pows = powp(base);
12000 if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
12001 return scale;
12002 }
12003
12004 scale.base = function(_) {
12005 return arguments.length ? (base = +_, rescale()) : base;
12006 };
12007
12008 scale.domain = function(_) {
12009 return arguments.length ? (domain(_), rescale()) : domain();
12010 };
12011
12012 scale.ticks = function(count) {
12013 var d = domain(),
12014 u = d[0],
12015 v = d[d.length - 1],
12016 r;
12017
12018 if (r = v < u) i = u, u = v, v = i;
12019
12020 var i = logs(u),
12021 j = logs(v),
12022 p,
12023 k,
12024 t,
12025 n = count == null ? 10 : +count,
12026 z = [];
12027
12028 if (!(base % 1) && j - i < n) {
12029 i = Math.round(i) - 1, j = Math.round(j) + 1;
12030 if (u > 0) for (; i < j; ++i) {
12031 for (k = 1, p = pows(i); k < base; ++k) {
12032 t = p * k;
12033 if (t < u) continue;
12034 if (t > v) break;
12035 z.push(t);
12036 }
12037 } else for (; i < j; ++i) {
12038 for (k = base - 1, p = pows(i); k >= 1; --k) {
12039 t = p * k;
12040 if (t < u) continue;
12041 if (t > v) break;
12042 z.push(t);
12043 }
12044 }
12045 } else {
12046 z = ticks(i, j, Math.min(j - i, n)).map(pows);
12047 }
12048
12049 return r ? z.reverse() : z;
12050 };
12051
12052 scale.tickFormat = function(count, specifier) {
12053 if (specifier == null) specifier = base === 10 ? ".0e" : ",";
12054 if (typeof specifier !== "function") specifier = exports.format(specifier);
12055 if (count === Infinity) return specifier;
12056 if (count == null) count = 10;
12057 var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
12058 return function(d) {
12059 var i = d / pows(Math.round(logs(d)));
12060 if (i * base < base - 0.5) i *= base;
12061 return i <= k ? specifier(d) : "";
12062 };
12063 };
12064
12065 scale.nice = function() {
12066 return domain(nice(domain(), {
12067 floor: function(x) { return pows(Math.floor(logs(x))); },
12068 ceil: function(x) { return pows(Math.ceil(logs(x))); }
12069 }));
12070 };
12071
12072 scale.copy = function() {
12073 return copy(scale, log$1().base(base));
12074 };
12075
12076 return scale;
12077 }
12078
12079 function raise$1(x, exponent) {
12080 return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
12081 }
12082
12083 function pow$1() {
12084 var exponent = 1,
12085 scale = continuous(deinterpolate, reinterpolate),
12086 domain = scale.domain;
12087
12088 function deinterpolate(a, b) {
12089 return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
12090 ? function(x) { return (raise$1(x, exponent) - a) / b; }
12091 : constant$9(b);
12092 }
12093
12094 function reinterpolate(a, b) {
12095 b = raise$1(b, exponent) - (a = raise$1(a, exponent));
12096 return function(t) { return raise$1(a + b * t, 1 / exponent); };
12097 }
12098
12099 scale.exponent = function(_) {
12100 return arguments.length ? (exponent = +_, domain(domain())) : exponent;
12101 };
12102
12103 scale.copy = function() {
12104 return copy(scale, pow$1().exponent(exponent));
12105 };
12106
12107 return linearish(scale);
12108 }
12109
12110 function sqrt$1() {
12111 return pow$1().exponent(0.5);
12112 }
12113
12114 function quantile$$1() {
12115 var domain = [],
12116 range = [],
12117 thresholds = [];
12118
12119 function rescale() {
12120 var i = 0, n = Math.max(1, range.length);
12121 thresholds = new Array(n - 1);
12122 while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
12123 return scale;
12124 }
12125
12126 function scale(x) {
12127 if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
12128 }
12129
12130 scale.invertExtent = function(y) {
12131 var i = range.indexOf(y);
12132 return i < 0 ? [NaN, NaN] : [
12133 i > 0 ? thresholds[i - 1] : domain[0],
12134 i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
12135 ];
12136 };
12137
12138 scale.domain = function(_) {
12139 if (!arguments.length) return domain.slice();
12140 domain = [];
12141 for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
12142 domain.sort(ascending);
12143 return rescale();
12144 };
12145
12146 scale.range = function(_) {
12147 return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12148 };
12149
12150 scale.quantiles = function() {
12151 return thresholds.slice();
12152 };
12153
12154 scale.copy = function() {
12155 return quantile$$1()
12156 .domain(domain)
12157 .range(range);
12158 };
12159
12160 return scale;
12161 }
12162
12163 function quantize$1() {
12164 var x0 = 0,
12165 x1 = 1,
12166 n = 1,
12167 domain = [0.5],
12168 range = [0, 1];
12169
12170 function scale(x) {
12171 if (x <= x) return range[bisectRight(domain, x, 0, n)];
12172 }
12173
12174 function rescale() {
12175 var i = -1;
12176 domain = new Array(n);
12177 while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
12178 return scale;
12179 }
12180
12181 scale.domain = function(_) {
12182 return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
12183 };
12184
12185 scale.range = function(_) {
12186 return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
12187 };
12188
12189 scale.invertExtent = function(y) {
12190 var i = range.indexOf(y);
12191 return i < 0 ? [NaN, NaN]
12192 : i < 1 ? [x0, domain[0]]
12193 : i >= n ? [domain[n - 1], x1]
12194 : [domain[i - 1], domain[i]];
12195 };
12196
12197 scale.copy = function() {
12198 return quantize$1()
12199 .domain([x0, x1])
12200 .range(range);
12201 };
12202
12203 return linearish(scale);
12204 }
12205
12206 function threshold$1() {
12207 var domain = [0.5],
12208 range = [0, 1],
12209 n = 1;
12210
12211 function scale(x) {
12212 if (x <= x) return range[bisectRight(domain, x, 0, n)];
12213 }
12214
12215 scale.domain = function(_) {
12216 return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
12217 };
12218
12219 scale.range = function(_) {
12220 return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
12221 };
12222
12223 scale.invertExtent = function(y) {
12224 var i = range.indexOf(y);
12225 return [domain[i - 1], domain[i]];
12226 };
12227
12228 scale.copy = function() {
12229 return threshold$1()
12230 .domain(domain)
12231 .range(range);
12232 };
12233
12234 return scale;
12235 }
12236
12237 var t0$1 = new Date;
12238 var t1$1 = new Date;
12239
12240 function newInterval(floori, offseti, count, field) {
12241
12242 function interval(date) {
12243 return floori(date = new Date(+date)), date;
12244 }
12245
12246 interval.floor = interval;
12247
12248 interval.ceil = function(date) {
12249 return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
12250 };
12251
12252 interval.round = function(date) {
12253 var d0 = interval(date),
12254 d1 = interval.ceil(date);
12255 return date - d0 < d1 - date ? d0 : d1;
12256 };
12257
12258 interval.offset = function(date, step) {
12259 return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
12260 };
12261
12262 interval.range = function(start, stop, step) {
12263 var range = [], previous;
12264 start = interval.ceil(start);
12265 step = step == null ? 1 : Math.floor(step);
12266 if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
12267 do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
12268 while (previous < start && start < stop);
12269 return range;
12270 };
12271
12272 interval.filter = function(test) {
12273 return newInterval(function(date) {
12274 if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
12275 }, function(date, step) {
12276 if (date >= date) {
12277 if (step < 0) while (++step <= 0) {
12278 while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
12279 } else while (--step >= 0) {
12280 while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
12281 }
12282 }
12283 });
12284 };
12285
12286 if (count) {
12287 interval.count = function(start, end) {
12288 t0$1.setTime(+start), t1$1.setTime(+end);
12289 floori(t0$1), floori(t1$1);
12290 return Math.floor(count(t0$1, t1$1));
12291 };
12292
12293 interval.every = function(step) {
12294 step = Math.floor(step);
12295 return !isFinite(step) || !(step > 0) ? null
12296 : !(step > 1) ? interval
12297 : interval.filter(field
12298 ? function(d) { return field(d) % step === 0; }
12299 : function(d) { return interval.count(0, d) % step === 0; });
12300 };
12301 }
12302
12303 return interval;
12304 }
12305
12306 var millisecond = newInterval(function() {
12307 // noop
12308 }, function(date, step) {
12309 date.setTime(+date + step);
12310 }, function(start, end) {
12311 return end - start;
12312 });
12313
12314 // An optimized implementation for this simple case.
12315 millisecond.every = function(k) {
12316 k = Math.floor(k);
12317 if (!isFinite(k) || !(k > 0)) return null;
12318 if (!(k > 1)) return millisecond;
12319 return newInterval(function(date) {
12320 date.setTime(Math.floor(date / k) * k);
12321 }, function(date, step) {
12322 date.setTime(+date + step * k);
12323 }, function(start, end) {
12324 return (end - start) / k;
12325 });
12326 };
12327
12328 var milliseconds = millisecond.range;
12329
12330 var durationSecond$1 = 1e3;
12331 var durationMinute$1 = 6e4;
12332 var durationHour$1 = 36e5;
12333 var durationDay$1 = 864e5;
12334 var durationWeek$1 = 6048e5;
12335
12336 var second = newInterval(function(date) {
12337 date.setTime(Math.floor(date / durationSecond$1) * durationSecond$1);
12338 }, function(date, step) {
12339 date.setTime(+date + step * durationSecond$1);
12340 }, function(start, end) {
12341 return (end - start) / durationSecond$1;
12342 }, function(date) {
12343 return date.getUTCSeconds();
12344 });
12345
12346 var seconds = second.range;
12347
12348 var minute = newInterval(function(date) {
12349 date.setTime(Math.floor(date / durationMinute$1) * durationMinute$1);
12350 }, function(date, step) {
12351 date.setTime(+date + step * durationMinute$1);
12352 }, function(start, end) {
12353 return (end - start) / durationMinute$1;
12354 }, function(date) {
12355 return date.getMinutes();
12356 });
12357
12358 var minutes = minute.range;
12359
12360 var hour = newInterval(function(date) {
12361 var offset = date.getTimezoneOffset() * durationMinute$1 % durationHour$1;
12362 if (offset < 0) offset += durationHour$1;
12363 date.setTime(Math.floor((+date - offset) / durationHour$1) * durationHour$1 + offset);
12364 }, function(date, step) {
12365 date.setTime(+date + step * durationHour$1);
12366 }, function(start, end) {
12367 return (end - start) / durationHour$1;
12368 }, function(date) {
12369 return date.getHours();
12370 });
12371
12372 var hours = hour.range;
12373
12374 var day = newInterval(function(date) {
12375 date.setHours(0, 0, 0, 0);
12376 }, function(date, step) {
12377 date.setDate(date.getDate() + step);
12378 }, function(start, end) {
12379 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationDay$1;
12380 }, function(date) {
12381 return date.getDate() - 1;
12382 });
12383
12384 var days = day.range;
12385
12386 function weekday(i) {
12387 return newInterval(function(date) {
12388 date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
12389 date.setHours(0, 0, 0, 0);
12390 }, function(date, step) {
12391 date.setDate(date.getDate() + step * 7);
12392 }, function(start, end) {
12393 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
12394 });
12395 }
12396
12397 var sunday = weekday(0);
12398 var monday = weekday(1);
12399 var tuesday = weekday(2);
12400 var wednesday = weekday(3);
12401 var thursday = weekday(4);
12402 var friday = weekday(5);
12403 var saturday = weekday(6);
12404
12405 var sundays = sunday.range;
12406 var mondays = monday.range;
12407 var tuesdays = tuesday.range;
12408 var wednesdays = wednesday.range;
12409 var thursdays = thursday.range;
12410 var fridays = friday.range;
12411 var saturdays = saturday.range;
12412
12413 var month = newInterval(function(date) {
12414 date.setDate(1);
12415 date.setHours(0, 0, 0, 0);
12416 }, function(date, step) {
12417 date.setMonth(date.getMonth() + step);
12418 }, function(start, end) {
12419 return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
12420 }, function(date) {
12421 return date.getMonth();
12422 });
12423
12424 var months = month.range;
12425
12426 var year = newInterval(function(date) {
12427 date.setMonth(0, 1);
12428 date.setHours(0, 0, 0, 0);
12429 }, function(date, step) {
12430 date.setFullYear(date.getFullYear() + step);
12431 }, function(start, end) {
12432 return end.getFullYear() - start.getFullYear();
12433 }, function(date) {
12434 return date.getFullYear();
12435 });
12436
12437 // An optimized implementation for this simple case.
12438 year.every = function(k) {
12439 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12440 date.setFullYear(Math.floor(date.getFullYear() / k) * k);
12441 date.setMonth(0, 1);
12442 date.setHours(0, 0, 0, 0);
12443 }, function(date, step) {
12444 date.setFullYear(date.getFullYear() + step * k);
12445 });
12446 };
12447
12448 var years = year.range;
12449
12450 var utcMinute = newInterval(function(date) {
12451 date.setUTCSeconds(0, 0);
12452 }, function(date, step) {
12453 date.setTime(+date + step * durationMinute$1);
12454 }, function(start, end) {
12455 return (end - start) / durationMinute$1;
12456 }, function(date) {
12457 return date.getUTCMinutes();
12458 });
12459
12460 var utcMinutes = utcMinute.range;
12461
12462 var utcHour = newInterval(function(date) {
12463 date.setUTCMinutes(0, 0, 0);
12464 }, function(date, step) {
12465 date.setTime(+date + step * durationHour$1);
12466 }, function(start, end) {
12467 return (end - start) / durationHour$1;
12468 }, function(date) {
12469 return date.getUTCHours();
12470 });
12471
12472 var utcHours = utcHour.range;
12473
12474 var utcDay = newInterval(function(date) {
12475 date.setUTCHours(0, 0, 0, 0);
12476 }, function(date, step) {
12477 date.setUTCDate(date.getUTCDate() + step);
12478 }, function(start, end) {
12479 return (end - start) / durationDay$1;
12480 }, function(date) {
12481 return date.getUTCDate() - 1;
12482 });
12483
12484 var utcDays = utcDay.range;
12485
12486 function utcWeekday(i) {
12487 return newInterval(function(date) {
12488 date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
12489 date.setUTCHours(0, 0, 0, 0);
12490 }, function(date, step) {
12491 date.setUTCDate(date.getUTCDate() + step * 7);
12492 }, function(start, end) {
12493 return (end - start) / durationWeek$1;
12494 });
12495 }
12496
12497 var utcSunday = utcWeekday(0);
12498 var utcMonday = utcWeekday(1);
12499 var utcTuesday = utcWeekday(2);
12500 var utcWednesday = utcWeekday(3);
12501 var utcThursday = utcWeekday(4);
12502 var utcFriday = utcWeekday(5);
12503 var utcSaturday = utcWeekday(6);
12504
12505 var utcSundays = utcSunday.range;
12506 var utcMondays = utcMonday.range;
12507 var utcTuesdays = utcTuesday.range;
12508 var utcWednesdays = utcWednesday.range;
12509 var utcThursdays = utcThursday.range;
12510 var utcFridays = utcFriday.range;
12511 var utcSaturdays = utcSaturday.range;
12512
12513 var utcMonth = newInterval(function(date) {
12514 date.setUTCDate(1);
12515 date.setUTCHours(0, 0, 0, 0);
12516 }, function(date, step) {
12517 date.setUTCMonth(date.getUTCMonth() + step);
12518 }, function(start, end) {
12519 return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
12520 }, function(date) {
12521 return date.getUTCMonth();
12522 });
12523
12524 var utcMonths = utcMonth.range;
12525
12526 var utcYear = newInterval(function(date) {
12527 date.setUTCMonth(0, 1);
12528 date.setUTCHours(0, 0, 0, 0);
12529 }, function(date, step) {
12530 date.setUTCFullYear(date.getUTCFullYear() + step);
12531 }, function(start, end) {
12532 return end.getUTCFullYear() - start.getUTCFullYear();
12533 }, function(date) {
12534 return date.getUTCFullYear();
12535 });
12536
12537 // An optimized implementation for this simple case.
12538 utcYear.every = function(k) {
12539 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12540 date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
12541 date.setUTCMonth(0, 1);
12542 date.setUTCHours(0, 0, 0, 0);
12543 }, function(date, step) {
12544 date.setUTCFullYear(date.getUTCFullYear() + step * k);
12545 });
12546 };
12547
12548 var utcYears = utcYear.range;
12549
12550 function localDate(d) {
12551 if (0 <= d.y && d.y < 100) {
12552 var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
12553 date.setFullYear(d.y);
12554 return date;
12555 }
12556 return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
12557 }
12558
12559 function utcDate(d) {
12560 if (0 <= d.y && d.y < 100) {
12561 var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
12562 date.setUTCFullYear(d.y);
12563 return date;
12564 }
12565 return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
12566 }
12567
12568 function newYear(y) {
12569 return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
12570 }
12571
12572 function formatLocale$1(locale) {
12573 var locale_dateTime = locale.dateTime,
12574 locale_date = locale.date,
12575 locale_time = locale.time,
12576 locale_periods = locale.periods,
12577 locale_weekdays = locale.days,
12578 locale_shortWeekdays = locale.shortDays,
12579 locale_months = locale.months,
12580 locale_shortMonths = locale.shortMonths;
12581
12582 var periodRe = formatRe(locale_periods),
12583 periodLookup = formatLookup(locale_periods),
12584 weekdayRe = formatRe(locale_weekdays),
12585 weekdayLookup = formatLookup(locale_weekdays),
12586 shortWeekdayRe = formatRe(locale_shortWeekdays),
12587 shortWeekdayLookup = formatLookup(locale_shortWeekdays),
12588 monthRe = formatRe(locale_months),
12589 monthLookup = formatLookup(locale_months),
12590 shortMonthRe = formatRe(locale_shortMonths),
12591 shortMonthLookup = formatLookup(locale_shortMonths);
12592
12593 var formats = {
12594 "a": formatShortWeekday,
12595 "A": formatWeekday,
12596 "b": formatShortMonth,
12597 "B": formatMonth,
12598 "c": null,
12599 "d": formatDayOfMonth,
12600 "e": formatDayOfMonth,
12601 "f": formatMicroseconds,
12602 "H": formatHour24,
12603 "I": formatHour12,
12604 "j": formatDayOfYear,
12605 "L": formatMilliseconds,
12606 "m": formatMonthNumber,
12607 "M": formatMinutes,
12608 "p": formatPeriod,
12609 "Q": formatUnixTimestamp,
12610 "s": formatUnixTimestampSeconds,
12611 "S": formatSeconds,
12612 "u": formatWeekdayNumberMonday,
12613 "U": formatWeekNumberSunday,
12614 "V": formatWeekNumberISO,
12615 "w": formatWeekdayNumberSunday,
12616 "W": formatWeekNumberMonday,
12617 "x": null,
12618 "X": null,
12619 "y": formatYear,
12620 "Y": formatFullYear,
12621 "Z": formatZone,
12622 "%": formatLiteralPercent
12623 };
12624
12625 var utcFormats = {
12626 "a": formatUTCShortWeekday,
12627 "A": formatUTCWeekday,
12628 "b": formatUTCShortMonth,
12629 "B": formatUTCMonth,
12630 "c": null,
12631 "d": formatUTCDayOfMonth,
12632 "e": formatUTCDayOfMonth,
12633 "f": formatUTCMicroseconds,
12634 "H": formatUTCHour24,
12635 "I": formatUTCHour12,
12636 "j": formatUTCDayOfYear,
12637 "L": formatUTCMilliseconds,
12638 "m": formatUTCMonthNumber,
12639 "M": formatUTCMinutes,
12640 "p": formatUTCPeriod,
12641 "Q": formatUnixTimestamp,
12642 "s": formatUnixTimestampSeconds,
12643 "S": formatUTCSeconds,
12644 "u": formatUTCWeekdayNumberMonday,
12645 "U": formatUTCWeekNumberSunday,
12646 "V": formatUTCWeekNumberISO,
12647 "w": formatUTCWeekdayNumberSunday,
12648 "W": formatUTCWeekNumberMonday,
12649 "x": null,
12650 "X": null,
12651 "y": formatUTCYear,
12652 "Y": formatUTCFullYear,
12653 "Z": formatUTCZone,
12654 "%": formatLiteralPercent
12655 };
12656
12657 var parses = {
12658 "a": parseShortWeekday,
12659 "A": parseWeekday,
12660 "b": parseShortMonth,
12661 "B": parseMonth,
12662 "c": parseLocaleDateTime,
12663 "d": parseDayOfMonth,
12664 "e": parseDayOfMonth,
12665 "f": parseMicroseconds,
12666 "H": parseHour24,
12667 "I": parseHour24,
12668 "j": parseDayOfYear,
12669 "L": parseMilliseconds,
12670 "m": parseMonthNumber,
12671 "M": parseMinutes,
12672 "p": parsePeriod,
12673 "Q": parseUnixTimestamp,
12674 "s": parseUnixTimestampSeconds,
12675 "S": parseSeconds,
12676 "u": parseWeekdayNumberMonday,
12677 "U": parseWeekNumberSunday,
12678 "V": parseWeekNumberISO,
12679 "w": parseWeekdayNumberSunday,
12680 "W": parseWeekNumberMonday,
12681 "x": parseLocaleDate,
12682 "X": parseLocaleTime,
12683 "y": parseYear,
12684 "Y": parseFullYear,
12685 "Z": parseZone,
12686 "%": parseLiteralPercent
12687 };
12688
12689 // These recursive directive definitions must be deferred.
12690 formats.x = newFormat(locale_date, formats);
12691 formats.X = newFormat(locale_time, formats);
12692 formats.c = newFormat(locale_dateTime, formats);
12693 utcFormats.x = newFormat(locale_date, utcFormats);
12694 utcFormats.X = newFormat(locale_time, utcFormats);
12695 utcFormats.c = newFormat(locale_dateTime, utcFormats);
12696
12697 function newFormat(specifier, formats) {
12698 return function(date) {
12699 var string = [],
12700 i = -1,
12701 j = 0,
12702 n = specifier.length,
12703 c,
12704 pad,
12705 format;
12706
12707 if (!(date instanceof Date)) date = new Date(+date);
12708
12709 while (++i < n) {
12710 if (specifier.charCodeAt(i) === 37) {
12711 string.push(specifier.slice(j, i));
12712 if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
12713 else pad = c === "e" ? " " : "0";
12714 if (format = formats[c]) c = format(date, pad);
12715 string.push(c);
12716 j = i + 1;
12717 }
12718 }
12719
12720 string.push(specifier.slice(j, i));
12721 return string.join("");
12722 };
12723 }
12724
12725 function newParse(specifier, newDate) {
12726 return function(string) {
12727 var d = newYear(1900),
12728 i = parseSpecifier(d, specifier, string += "", 0),
12729 week, day$$1;
12730 if (i != string.length) return null;
12731
12732 // If a UNIX timestamp is specified, return it.
12733 if ("Q" in d) return new Date(d.Q);
12734
12735 // The am-pm flag is 0 for AM, and 1 for PM.
12736 if ("p" in d) d.H = d.H % 12 + d.p * 12;
12737
12738 // Convert day-of-week and week-of-year to day-of-year.
12739 if ("V" in d) {
12740 if (d.V < 1 || d.V > 53) return null;
12741 if (!("w" in d)) d.w = 1;
12742 if ("Z" in d) {
12743 week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
12744 week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
12745 week = utcDay.offset(week, (d.V - 1) * 7);
12746 d.y = week.getUTCFullYear();
12747 d.m = week.getUTCMonth();
12748 d.d = week.getUTCDate() + (d.w + 6) % 7;
12749 } else {
12750 week = newDate(newYear(d.y)), day$$1 = week.getDay();
12751 week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
12752 week = day.offset(week, (d.V - 1) * 7);
12753 d.y = week.getFullYear();
12754 d.m = week.getMonth();
12755 d.d = week.getDate() + (d.w + 6) % 7;
12756 }
12757 } else if ("W" in d || "U" in d) {
12758 if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
12759 day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
12760 d.m = 0;
12761 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;
12762 }
12763
12764 // If a time zone is specified, all fields are interpreted as UTC and then
12765 // offset according to the specified time zone.
12766 if ("Z" in d) {
12767 d.H += d.Z / 100 | 0;
12768 d.M += d.Z % 100;
12769 return utcDate(d);
12770 }
12771
12772 // Otherwise, all fields are in local time.
12773 return newDate(d);
12774 };
12775 }
12776
12777 function parseSpecifier(d, specifier, string, j) {
12778 var i = 0,
12779 n = specifier.length,
12780 m = string.length,
12781 c,
12782 parse;
12783
12784 while (i < n) {
12785 if (j >= m) return -1;
12786 c = specifier.charCodeAt(i++);
12787 if (c === 37) {
12788 c = specifier.charAt(i++);
12789 parse = parses[c in pads ? specifier.charAt(i++) : c];
12790 if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
12791 } else if (c != string.charCodeAt(j++)) {
12792 return -1;
12793 }
12794 }
12795
12796 return j;
12797 }
12798
12799 function parsePeriod(d, string, i) {
12800 var n = periodRe.exec(string.slice(i));
12801 return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12802 }
12803
12804 function parseShortWeekday(d, string, i) {
12805 var n = shortWeekdayRe.exec(string.slice(i));
12806 return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12807 }
12808
12809 function parseWeekday(d, string, i) {
12810 var n = weekdayRe.exec(string.slice(i));
12811 return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12812 }
12813
12814 function parseShortMonth(d, string, i) {
12815 var n = shortMonthRe.exec(string.slice(i));
12816 return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12817 }
12818
12819 function parseMonth(d, string, i) {
12820 var n = monthRe.exec(string.slice(i));
12821 return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12822 }
12823
12824 function parseLocaleDateTime(d, string, i) {
12825 return parseSpecifier(d, locale_dateTime, string, i);
12826 }
12827
12828 function parseLocaleDate(d, string, i) {
12829 return parseSpecifier(d, locale_date, string, i);
12830 }
12831
12832 function parseLocaleTime(d, string, i) {
12833 return parseSpecifier(d, locale_time, string, i);
12834 }
12835
12836 function formatShortWeekday(d) {
12837 return locale_shortWeekdays[d.getDay()];
12838 }
12839
12840 function formatWeekday(d) {
12841 return locale_weekdays[d.getDay()];
12842 }
12843
12844 function formatShortMonth(d) {
12845 return locale_shortMonths[d.getMonth()];
12846 }
12847
12848 function formatMonth(d) {
12849 return locale_months[d.getMonth()];
12850 }
12851
12852 function formatPeriod(d) {
12853 return locale_periods[+(d.getHours() >= 12)];
12854 }
12855
12856 function formatUTCShortWeekday(d) {
12857 return locale_shortWeekdays[d.getUTCDay()];
12858 }
12859
12860 function formatUTCWeekday(d) {
12861 return locale_weekdays[d.getUTCDay()];
12862 }
12863
12864 function formatUTCShortMonth(d) {
12865 return locale_shortMonths[d.getUTCMonth()];
12866 }
12867
12868 function formatUTCMonth(d) {
12869 return locale_months[d.getUTCMonth()];
12870 }
12871
12872 function formatUTCPeriod(d) {
12873 return locale_periods[+(d.getUTCHours() >= 12)];
12874 }
12875
12876 return {
12877 format: function(specifier) {
12878 var f = newFormat(specifier += "", formats);
12879 f.toString = function() { return specifier; };
12880 return f;
12881 },
12882 parse: function(specifier) {
12883 var p = newParse(specifier += "", localDate);
12884 p.toString = function() { return specifier; };
12885 return p;
12886 },
12887 utcFormat: function(specifier) {
12888 var f = newFormat(specifier += "", utcFormats);
12889 f.toString = function() { return specifier; };
12890 return f;
12891 },
12892 utcParse: function(specifier) {
12893 var p = newParse(specifier, utcDate);
12894 p.toString = function() { return specifier; };
12895 return p;
12896 }
12897 };
12898 }
12899
12900 var pads = {"-": "", "_": " ", "0": "0"};
12901 var numberRe = /^\s*\d+/;
12902 var percentRe = /^%/;
12903 var requoteRe = /[\\^$*+?|[\]().{}]/g;
12904
12905 function pad(value, fill, width) {
12906 var sign = value < 0 ? "-" : "",
12907 string = (sign ? -value : value) + "",
12908 length = string.length;
12909 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
12910 }
12911
12912 function requote(s) {
12913 return s.replace(requoteRe, "\\$&");
12914 }
12915
12916 function formatRe(names) {
12917 return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
12918 }
12919
12920 function formatLookup(names) {
12921 var map = {}, i = -1, n = names.length;
12922 while (++i < n) map[names[i].toLowerCase()] = i;
12923 return map;
12924 }
12925
12926 function parseWeekdayNumberSunday(d, string, i) {
12927 var n = numberRe.exec(string.slice(i, i + 1));
12928 return n ? (d.w = +n[0], i + n[0].length) : -1;
12929 }
12930
12931 function parseWeekdayNumberMonday(d, string, i) {
12932 var n = numberRe.exec(string.slice(i, i + 1));
12933 return n ? (d.u = +n[0], i + n[0].length) : -1;
12934 }
12935
12936 function parseWeekNumberSunday(d, string, i) {
12937 var n = numberRe.exec(string.slice(i, i + 2));
12938 return n ? (d.U = +n[0], i + n[0].length) : -1;
12939 }
12940
12941 function parseWeekNumberISO(d, string, i) {
12942 var n = numberRe.exec(string.slice(i, i + 2));
12943 return n ? (d.V = +n[0], i + n[0].length) : -1;
12944 }
12945
12946 function parseWeekNumberMonday(d, string, i) {
12947 var n = numberRe.exec(string.slice(i, i + 2));
12948 return n ? (d.W = +n[0], i + n[0].length) : -1;
12949 }
12950
12951 function parseFullYear(d, string, i) {
12952 var n = numberRe.exec(string.slice(i, i + 4));
12953 return n ? (d.y = +n[0], i + n[0].length) : -1;
12954 }
12955
12956 function parseYear(d, string, i) {
12957 var n = numberRe.exec(string.slice(i, i + 2));
12958 return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
12959 }
12960
12961 function parseZone(d, string, i) {
12962 var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
12963 return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
12964 }
12965
12966 function parseMonthNumber(d, string, i) {
12967 var n = numberRe.exec(string.slice(i, i + 2));
12968 return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
12969 }
12970
12971 function parseDayOfMonth(d, string, i) {
12972 var n = numberRe.exec(string.slice(i, i + 2));
12973 return n ? (d.d = +n[0], i + n[0].length) : -1;
12974 }
12975
12976 function parseDayOfYear(d, string, i) {
12977 var n = numberRe.exec(string.slice(i, i + 3));
12978 return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
12979 }
12980
12981 function parseHour24(d, string, i) {
12982 var n = numberRe.exec(string.slice(i, i + 2));
12983 return n ? (d.H = +n[0], i + n[0].length) : -1;
12984 }
12985
12986 function parseMinutes(d, string, i) {
12987 var n = numberRe.exec(string.slice(i, i + 2));
12988 return n ? (d.M = +n[0], i + n[0].length) : -1;
12989 }
12990
12991 function parseSeconds(d, string, i) {
12992 var n = numberRe.exec(string.slice(i, i + 2));
12993 return n ? (d.S = +n[0], i + n[0].length) : -1;
12994 }
12995
12996 function parseMilliseconds(d, string, i) {
12997 var n = numberRe.exec(string.slice(i, i + 3));
12998 return n ? (d.L = +n[0], i + n[0].length) : -1;
12999 }
13000
13001 function parseMicroseconds(d, string, i) {
13002 var n = numberRe.exec(string.slice(i, i + 6));
13003 return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
13004 }
13005
13006 function parseLiteralPercent(d, string, i) {
13007 var n = percentRe.exec(string.slice(i, i + 1));
13008 return n ? i + n[0].length : -1;
13009 }
13010
13011 function parseUnixTimestamp(d, string, i) {
13012 var n = numberRe.exec(string.slice(i));
13013 return n ? (d.Q = +n[0], i + n[0].length) : -1;
13014 }
13015
13016 function parseUnixTimestampSeconds(d, string, i) {
13017 var n = numberRe.exec(string.slice(i));
13018 return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
13019 }
13020
13021 function formatDayOfMonth(d, p) {
13022 return pad(d.getDate(), p, 2);
13023 }
13024
13025 function formatHour24(d, p) {
13026 return pad(d.getHours(), p, 2);
13027 }
13028
13029 function formatHour12(d, p) {
13030 return pad(d.getHours() % 12 || 12, p, 2);
13031 }
13032
13033 function formatDayOfYear(d, p) {
13034 return pad(1 + day.count(year(d), d), p, 3);
13035 }
13036
13037 function formatMilliseconds(d, p) {
13038 return pad(d.getMilliseconds(), p, 3);
13039 }
13040
13041 function formatMicroseconds(d, p) {
13042 return formatMilliseconds(d, p) + "000";
13043 }
13044
13045 function formatMonthNumber(d, p) {
13046 return pad(d.getMonth() + 1, p, 2);
13047 }
13048
13049 function formatMinutes(d, p) {
13050 return pad(d.getMinutes(), p, 2);
13051 }
13052
13053 function formatSeconds(d, p) {
13054 return pad(d.getSeconds(), p, 2);
13055 }
13056
13057 function formatWeekdayNumberMonday(d) {
13058 var day$$1 = d.getDay();
13059 return day$$1 === 0 ? 7 : day$$1;
13060 }
13061
13062 function formatWeekNumberSunday(d, p) {
13063 return pad(sunday.count(year(d), d), p, 2);
13064 }
13065
13066 function formatWeekNumberISO(d, p) {
13067 var day$$1 = d.getDay();
13068 d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
13069 return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
13070 }
13071
13072 function formatWeekdayNumberSunday(d) {
13073 return d.getDay();
13074 }
13075
13076 function formatWeekNumberMonday(d, p) {
13077 return pad(monday.count(year(d), d), p, 2);
13078 }
13079
13080 function formatYear(d, p) {
13081 return pad(d.getFullYear() % 100, p, 2);
13082 }
13083
13084 function formatFullYear(d, p) {
13085 return pad(d.getFullYear() % 10000, p, 4);
13086 }
13087
13088 function formatZone(d) {
13089 var z = d.getTimezoneOffset();
13090 return (z > 0 ? "-" : (z *= -1, "+"))
13091 + pad(z / 60 | 0, "0", 2)
13092 + pad(z % 60, "0", 2);
13093 }
13094
13095 function formatUTCDayOfMonth(d, p) {
13096 return pad(d.getUTCDate(), p, 2);
13097 }
13098
13099 function formatUTCHour24(d, p) {
13100 return pad(d.getUTCHours(), p, 2);
13101 }
13102
13103 function formatUTCHour12(d, p) {
13104 return pad(d.getUTCHours() % 12 || 12, p, 2);
13105 }
13106
13107 function formatUTCDayOfYear(d, p) {
13108 return pad(1 + utcDay.count(utcYear(d), d), p, 3);
13109 }
13110
13111 function formatUTCMilliseconds(d, p) {
13112 return pad(d.getUTCMilliseconds(), p, 3);
13113 }
13114
13115 function formatUTCMicroseconds(d, p) {
13116 return formatUTCMilliseconds(d, p) + "000";
13117 }
13118
13119 function formatUTCMonthNumber(d, p) {
13120 return pad(d.getUTCMonth() + 1, p, 2);
13121 }
13122
13123 function formatUTCMinutes(d, p) {
13124 return pad(d.getUTCMinutes(), p, 2);
13125 }
13126
13127 function formatUTCSeconds(d, p) {
13128 return pad(d.getUTCSeconds(), p, 2);
13129 }
13130
13131 function formatUTCWeekdayNumberMonday(d) {
13132 var dow = d.getUTCDay();
13133 return dow === 0 ? 7 : dow;
13134 }
13135
13136 function formatUTCWeekNumberSunday(d, p) {
13137 return pad(utcSunday.count(utcYear(d), d), p, 2);
13138 }
13139
13140 function formatUTCWeekNumberISO(d, p) {
13141 var day$$1 = d.getUTCDay();
13142 d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
13143 return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
13144 }
13145
13146 function formatUTCWeekdayNumberSunday(d) {
13147 return d.getUTCDay();
13148 }
13149
13150 function formatUTCWeekNumberMonday(d, p) {
13151 return pad(utcMonday.count(utcYear(d), d), p, 2);
13152 }
13153
13154 function formatUTCYear(d, p) {
13155 return pad(d.getUTCFullYear() % 100, p, 2);
13156 }
13157
13158 function formatUTCFullYear(d, p) {
13159 return pad(d.getUTCFullYear() % 10000, p, 4);
13160 }
13161
13162 function formatUTCZone() {
13163 return "+0000";
13164 }
13165
13166 function formatLiteralPercent() {
13167 return "%";
13168 }
13169
13170 function formatUnixTimestamp(d) {
13171 return +d;
13172 }
13173
13174 function formatUnixTimestampSeconds(d) {
13175 return Math.floor(+d / 1000);
13176 }
13177
13178 var locale$1;
13179
13180
13181
13182
13183
13184 defaultLocale$1({
13185 dateTime: "%x, %X",
13186 date: "%-m/%-d/%Y",
13187 time: "%-I:%M:%S %p",
13188 periods: ["AM", "PM"],
13189 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
13190 shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
13191 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
13192 shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
13193 });
13194
13195 function defaultLocale$1(definition) {
13196 locale$1 = formatLocale$1(definition);
13197 exports.timeFormat = locale$1.format;
13198 exports.timeParse = locale$1.parse;
13199 exports.utcFormat = locale$1.utcFormat;
13200 exports.utcParse = locale$1.utcParse;
13201 return locale$1;
13202 }
13203
13204 var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
13205
13206 function formatIsoNative(date) {
13207 return date.toISOString();
13208 }
13209
13210 var formatIso = Date.prototype.toISOString
13211 ? formatIsoNative
13212 : exports.utcFormat(isoSpecifier);
13213
13214 function parseIsoNative(string) {
13215 var date = new Date(string);
13216 return isNaN(date) ? null : date;
13217 }
13218
13219 var parseIso = +new Date("2000-01-01T00:00:00.000Z")
13220 ? parseIsoNative
13221 : exports.utcParse(isoSpecifier);
13222
13223 var durationSecond = 1000;
13224 var durationMinute = durationSecond * 60;
13225 var durationHour = durationMinute * 60;
13226 var durationDay = durationHour * 24;
13227 var durationWeek = durationDay * 7;
13228 var durationMonth = durationDay * 30;
13229 var durationYear = durationDay * 365;
13230
13231 function date$1(t) {
13232 return new Date(t);
13233 }
13234
13235 function number$3(t) {
13236 return t instanceof Date ? +t : +new Date(+t);
13237 }
13238
13239 function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
13240 var scale = continuous(deinterpolateLinear, reinterpolate),
13241 invert = scale.invert,
13242 domain = scale.domain;
13243
13244 var formatMillisecond = format(".%L"),
13245 formatSecond = format(":%S"),
13246 formatMinute = format("%I:%M"),
13247 formatHour = format("%I %p"),
13248 formatDay = format("%a %d"),
13249 formatWeek = format("%b %d"),
13250 formatMonth = format("%B"),
13251 formatYear = format("%Y");
13252
13253 var tickIntervals = [
13254 [second$$1, 1, durationSecond],
13255 [second$$1, 5, 5 * durationSecond],
13256 [second$$1, 15, 15 * durationSecond],
13257 [second$$1, 30, 30 * durationSecond],
13258 [minute$$1, 1, durationMinute],
13259 [minute$$1, 5, 5 * durationMinute],
13260 [minute$$1, 15, 15 * durationMinute],
13261 [minute$$1, 30, 30 * durationMinute],
13262 [ hour$$1, 1, durationHour ],
13263 [ hour$$1, 3, 3 * durationHour ],
13264 [ hour$$1, 6, 6 * durationHour ],
13265 [ hour$$1, 12, 12 * durationHour ],
13266 [ day$$1, 1, durationDay ],
13267 [ day$$1, 2, 2 * durationDay ],
13268 [ week, 1, durationWeek ],
13269 [ month$$1, 1, durationMonth ],
13270 [ month$$1, 3, 3 * durationMonth ],
13271 [ year$$1, 1, durationYear ]
13272 ];
13273
13274 function tickFormat(date) {
13275 return (second$$1(date) < date ? formatMillisecond
13276 : minute$$1(date) < date ? formatSecond
13277 : hour$$1(date) < date ? formatMinute
13278 : day$$1(date) < date ? formatHour
13279 : month$$1(date) < date ? (week(date) < date ? formatDay : formatWeek)
13280 : year$$1(date) < date ? formatMonth
13281 : formatYear)(date);
13282 }
13283
13284 function tickInterval(interval, start, stop, step) {
13285 if (interval == null) interval = 10;
13286
13287 // If a desired tick count is specified, pick a reasonable tick interval
13288 // based on the extent of the domain and a rough estimate of tick size.
13289 // Otherwise, assume interval is already a time interval and use it.
13290 if (typeof interval === "number") {
13291 var target = Math.abs(stop - start) / interval,
13292 i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
13293 if (i === tickIntervals.length) {
13294 step = tickStep(start / durationYear, stop / durationYear, interval);
13295 interval = year$$1;
13296 } else if (i) {
13297 i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
13298 step = i[1];
13299 interval = i[0];
13300 } else {
13301 step = Math.max(tickStep(start, stop, interval), 1);
13302 interval = millisecond$$1;
13303 }
13304 }
13305
13306 return step == null ? interval : interval.every(step);
13307 }
13308
13309 scale.invert = function(y) {
13310 return new Date(invert(y));
13311 };
13312
13313 scale.domain = function(_) {
13314 return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
13315 };
13316
13317 scale.ticks = function(interval, step) {
13318 var d = domain(),
13319 t0 = d[0],
13320 t1 = d[d.length - 1],
13321 r = t1 < t0,
13322 t;
13323 if (r) t = t0, t0 = t1, t1 = t;
13324 t = tickInterval(interval, t0, t1, step);
13325 t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
13326 return r ? t.reverse() : t;
13327 };
13328
13329 scale.tickFormat = function(count, specifier) {
13330 return specifier == null ? tickFormat : format(specifier);
13331 };
13332
13333 scale.nice = function(interval, step) {
13334 var d = domain();
13335 return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
13336 ? domain(nice(d, interval))
13337 : scale;
13338 };
13339
13340 scale.copy = function() {
13341 return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
13342 };
13343
13344 return scale;
13345 }
13346
13347 function time() {
13348 return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
13349 }
13350
13351 function utcTime() {
13352 return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
13353 }
13354
13355 function colors(s) {
13356 return s.match(/.{6}/g).map(function(x) {
13357 return "#" + x;
13358 });
13359 }
13360
13361 var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
13362
13363 var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
13364
13365 var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
13366
13367 var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
13368
13369 var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
13370
13371 var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13372
13373 var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13374
13375 var rainbow = cubehelix();
13376
13377 function rainbow$1(t) {
13378 if (t < 0 || t > 1) t -= Math.floor(t);
13379 var ts = Math.abs(t - 0.5);
13380 rainbow.h = 360 * t - 100;
13381 rainbow.s = 1.5 - 1.5 * ts;
13382 rainbow.l = 0.8 - 0.9 * ts;
13383 return rainbow + "";
13384 }
13385
13386 function ramp(range) {
13387 var n = range.length;
13388 return function(t) {
13389 return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
13390 };
13391 }
13392
13393 var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
13394
13395 var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
13396
13397 var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
13398
13399 var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
13400
13401 function sequential(interpolator) {
13402 var x0 = 0,
13403 x1 = 1,
13404 clamp = false;
13405
13406 function scale(x) {
13407 var t = (x - x0) / (x1 - x0);
13408 return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
13409 }
13410
13411 scale.domain = function(_) {
13412 return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
13413 };
13414
13415 scale.clamp = function(_) {
13416 return arguments.length ? (clamp = !!_, scale) : clamp;
13417 };
13418
13419 scale.interpolator = function(_) {
13420 return arguments.length ? (interpolator = _, scale) : interpolator;
13421 };
13422
13423 scale.copy = function() {
13424 return sequential(interpolator).domain([x0, x1]).clamp(clamp);
13425 };
13426
13427 return linearish(scale);
13428 }
13429
13430 function constant$10(x) {
13431 return function constant() {
13432 return x;
13433 };
13434 }
13435
13436 var abs$1 = Math.abs;
13437 var atan2$1 = Math.atan2;
13438 var cos$2 = Math.cos;
13439 var max$2 = Math.max;
13440 var min$1 = Math.min;
13441 var sin$2 = Math.sin;
13442 var sqrt$2 = Math.sqrt;
13443
13444 var epsilon$3 = 1e-12;
13445 var pi$4 = Math.PI;
13446 var halfPi$3 = pi$4 / 2;
13447 var tau$4 = 2 * pi$4;
13448
13449 function acos$1(x) {
13450 return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
13451 }
13452
13453 function asin$1(x) {
13454 return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
13455 }
13456
13457 function arcInnerRadius(d) {
13458 return d.innerRadius;
13459 }
13460
13461 function arcOuterRadius(d) {
13462 return d.outerRadius;
13463 }
13464
13465 function arcStartAngle(d) {
13466 return d.startAngle;
13467 }
13468
13469 function arcEndAngle(d) {
13470 return d.endAngle;
13471 }
13472
13473 function arcPadAngle(d) {
13474 return d && d.padAngle; // Note: optional!
13475 }
13476
13477 function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
13478 var x10 = x1 - x0, y10 = y1 - y0,
13479 x32 = x3 - x2, y32 = y3 - y2,
13480 t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
13481 return [x0 + t * x10, y0 + t * y10];
13482 }
13483
13484 // Compute perpendicular offset line of length rc.
13485 // http://mathworld.wolfram.com/Circle-LineIntersection.html
13486 function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
13487 var x01 = x0 - x1,
13488 y01 = y0 - y1,
13489 lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
13490 ox = lo * y01,
13491 oy = -lo * x01,
13492 x11 = x0 + ox,
13493 y11 = y0 + oy,
13494 x10 = x1 + ox,
13495 y10 = y1 + oy,
13496 x00 = (x11 + x10) / 2,
13497 y00 = (y11 + y10) / 2,
13498 dx = x10 - x11,
13499 dy = y10 - y11,
13500 d2 = dx * dx + dy * dy,
13501 r = r1 - rc,
13502 D = x11 * y10 - x10 * y11,
13503 d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
13504 cx0 = (D * dy - dx * d) / d2,
13505 cy0 = (-D * dx - dy * d) / d2,
13506 cx1 = (D * dy + dx * d) / d2,
13507 cy1 = (-D * dx + dy * d) / d2,
13508 dx0 = cx0 - x00,
13509 dy0 = cy0 - y00,
13510 dx1 = cx1 - x00,
13511 dy1 = cy1 - y00;
13512
13513 // Pick the closer of the two intersection points.
13514 // TODO Is there a faster way to determine which intersection to use?
13515 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
13516
13517 return {
13518 cx: cx0,
13519 cy: cy0,
13520 x01: -ox,
13521 y01: -oy,
13522 x11: cx0 * (r1 / r - 1),
13523 y11: cy0 * (r1 / r - 1)
13524 };
13525 }
13526
13527 function arc() {
13528 var innerRadius = arcInnerRadius,
13529 outerRadius = arcOuterRadius,
13530 cornerRadius = constant$10(0),
13531 padRadius = null,
13532 startAngle = arcStartAngle,
13533 endAngle = arcEndAngle,
13534 padAngle = arcPadAngle,
13535 context = null;
13536
13537 function arc() {
13538 var buffer,
13539 r,
13540 r0 = +innerRadius.apply(this, arguments),
13541 r1 = +outerRadius.apply(this, arguments),
13542 a0 = startAngle.apply(this, arguments) - halfPi$3,
13543 a1 = endAngle.apply(this, arguments) - halfPi$3,
13544 da = abs$1(a1 - a0),
13545 cw = a1 > a0;
13546
13547 if (!context) context = buffer = path();
13548
13549 // Ensure that the outer radius is always larger than the inner radius.
13550 if (r1 < r0) r = r1, r1 = r0, r0 = r;
13551
13552 // Is it a point?
13553 if (!(r1 > epsilon$3)) context.moveTo(0, 0);
13554
13555 // Or is it a circle or annulus?
13556 else if (da > tau$4 - epsilon$3) {
13557 context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
13558 context.arc(0, 0, r1, a0, a1, !cw);
13559 if (r0 > epsilon$3) {
13560 context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
13561 context.arc(0, 0, r0, a1, a0, cw);
13562 }
13563 }
13564
13565 // Or is it a circular or annular sector?
13566 else {
13567 var a01 = a0,
13568 a11 = a1,
13569 a00 = a0,
13570 a10 = a1,
13571 da0 = da,
13572 da1 = da,
13573 ap = padAngle.apply(this, arguments) / 2,
13574 rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
13575 rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
13576 rc0 = rc,
13577 rc1 = rc,
13578 t0,
13579 t1;
13580
13581 // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
13582 if (rp > epsilon$3) {
13583 var p0 = asin$1(rp / r0 * sin$2(ap)),
13584 p1 = asin$1(rp / r1 * sin$2(ap));
13585 if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
13586 else da0 = 0, a00 = a10 = (a0 + a1) / 2;
13587 if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
13588 else da1 = 0, a01 = a11 = (a0 + a1) / 2;
13589 }
13590
13591 var x01 = r1 * cos$2(a01),
13592 y01 = r1 * sin$2(a01),
13593 x10 = r0 * cos$2(a10),
13594 y10 = r0 * sin$2(a10);
13595
13596 // Apply rounded corners?
13597 if (rc > epsilon$3) {
13598 var x11 = r1 * cos$2(a11),
13599 y11 = r1 * sin$2(a11),
13600 x00 = r0 * cos$2(a00),
13601 y00 = r0 * sin$2(a00);
13602
13603 // Restrict the corner radius according to the sector angle.
13604 if (da < pi$4) {
13605 var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
13606 ax = x01 - oc[0],
13607 ay = y01 - oc[1],
13608 bx = x11 - oc[0],
13609 by = y11 - oc[1],
13610 kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
13611 lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
13612 rc0 = min$1(rc, (r0 - lc) / (kc - 1));
13613 rc1 = min$1(rc, (r1 - lc) / (kc + 1));
13614 }
13615 }
13616
13617 // Is the sector collapsed to a line?
13618 if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
13619
13620 // Does the sector’s outer ring have rounded corners?
13621 else if (rc1 > epsilon$3) {
13622 t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
13623 t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
13624
13625 context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
13626
13627 // Have the corners merged?
13628 if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
13629
13630 // Otherwise, draw the two corners and the ring.
13631 else {
13632 context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
13633 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);
13634 context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
13635 }
13636 }
13637
13638 // Or is the outer ring just a circular arc?
13639 else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
13640
13641 // Is there no inner ring, and it’s a circular sector?
13642 // Or perhaps it’s an annular sector collapsed due to padding?
13643 if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
13644
13645 // Does the sector’s inner ring (or point) have rounded corners?
13646 else if (rc0 > epsilon$3) {
13647 t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
13648 t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
13649
13650 context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
13651
13652 // Have the corners merged?
13653 if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
13654
13655 // Otherwise, draw the two corners and the ring.
13656 else {
13657 context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
13658 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);
13659 context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
13660 }
13661 }
13662
13663 // Or is the inner ring just a circular arc?
13664 else context.arc(0, 0, r0, a10, a00, cw);
13665 }
13666
13667 context.closePath();
13668
13669 if (buffer) return context = null, buffer + "" || null;
13670 }
13671
13672 arc.centroid = function() {
13673 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
13674 a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
13675 return [cos$2(a) * r, sin$2(a) * r];
13676 };
13677
13678 arc.innerRadius = function(_) {
13679 return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : innerRadius;
13680 };
13681
13682 arc.outerRadius = function(_) {
13683 return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : outerRadius;
13684 };
13685
13686 arc.cornerRadius = function(_) {
13687 return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : cornerRadius;
13688 };
13689
13690 arc.padRadius = function(_) {
13691 return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), arc) : padRadius;
13692 };
13693
13694 arc.startAngle = function(_) {
13695 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : startAngle;
13696 };
13697
13698 arc.endAngle = function(_) {
13699 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : endAngle;
13700 };
13701
13702 arc.padAngle = function(_) {
13703 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : padAngle;
13704 };
13705
13706 arc.context = function(_) {
13707 return arguments.length ? (context = _ == null ? null : _, arc) : context;
13708 };
13709
13710 return arc;
13711 }
13712
13713 function Linear(context) {
13714 this._context = context;
13715 }
13716
13717 Linear.prototype = {
13718 areaStart: function() {
13719 this._line = 0;
13720 },
13721 areaEnd: function() {
13722 this._line = NaN;
13723 },
13724 lineStart: function() {
13725 this._point = 0;
13726 },
13727 lineEnd: function() {
13728 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
13729 this._line = 1 - this._line;
13730 },
13731 point: function(x, y) {
13732 x = +x, y = +y;
13733 switch (this._point) {
13734 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
13735 case 1: this._point = 2; // proceed
13736 default: this._context.lineTo(x, y); break;
13737 }
13738 }
13739 };
13740
13741 function curveLinear(context) {
13742 return new Linear(context);
13743 }
13744
13745 function x$3(p) {
13746 return p[0];
13747 }
13748
13749 function y$3(p) {
13750 return p[1];
13751 }
13752
13753 function line() {
13754 var x$$1 = x$3,
13755 y$$1 = y$3,
13756 defined = constant$10(true),
13757 context = null,
13758 curve = curveLinear,
13759 output = null;
13760
13761 function line(data) {
13762 var i,
13763 n = data.length,
13764 d,
13765 defined0 = false,
13766 buffer;
13767
13768 if (context == null) output = curve(buffer = path());
13769
13770 for (i = 0; i <= n; ++i) {
13771 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
13772 if (defined0 = !defined0) output.lineStart();
13773 else output.lineEnd();
13774 }
13775 if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
13776 }
13777
13778 if (buffer) return output = null, buffer + "" || null;
13779 }
13780
13781 line.x = function(_) {
13782 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : x$$1;
13783 };
13784
13785 line.y = function(_) {
13786 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : y$$1;
13787 };
13788
13789 line.defined = function(_) {
13790 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), line) : defined;
13791 };
13792
13793 line.curve = function(_) {
13794 return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
13795 };
13796
13797 line.context = function(_) {
13798 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
13799 };
13800
13801 return line;
13802 }
13803
13804 function area$2() {
13805 var x0 = x$3,
13806 x1 = null,
13807 y0 = constant$10(0),
13808 y1 = y$3,
13809 defined = constant$10(true),
13810 context = null,
13811 curve = curveLinear,
13812 output = null;
13813
13814 function area(data) {
13815 var i,
13816 j,
13817 k,
13818 n = data.length,
13819 d,
13820 defined0 = false,
13821 buffer,
13822 x0z = new Array(n),
13823 y0z = new Array(n);
13824
13825 if (context == null) output = curve(buffer = path());
13826
13827 for (i = 0; i <= n; ++i) {
13828 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
13829 if (defined0 = !defined0) {
13830 j = i;
13831 output.areaStart();
13832 output.lineStart();
13833 } else {
13834 output.lineEnd();
13835 output.lineStart();
13836 for (k = i - 1; k >= j; --k) {
13837 output.point(x0z[k], y0z[k]);
13838 }
13839 output.lineEnd();
13840 output.areaEnd();
13841 }
13842 }
13843 if (defined0) {
13844 x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
13845 output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
13846 }
13847 }
13848
13849 if (buffer) return output = null, buffer + "" || null;
13850 }
13851
13852 function arealine() {
13853 return line().defined(defined).curve(curve).context(context);
13854 }
13855
13856 area.x = function(_) {
13857 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), x1 = null, area) : x0;
13858 };
13859
13860 area.x0 = function(_) {
13861 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), area) : x0;
13862 };
13863
13864 area.x1 = function(_) {
13865 return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : x1;
13866 };
13867
13868 area.y = function(_) {
13869 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), y1 = null, area) : y0;
13870 };
13871
13872 area.y0 = function(_) {
13873 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), area) : y0;
13874 };
13875
13876 area.y1 = function(_) {
13877 return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : y1;
13878 };
13879
13880 area.lineX0 =
13881 area.lineY0 = function() {
13882 return arealine().x(x0).y(y0);
13883 };
13884
13885 area.lineY1 = function() {
13886 return arealine().x(x0).y(y1);
13887 };
13888
13889 area.lineX1 = function() {
13890 return arealine().x(x1).y(y0);
13891 };
13892
13893 area.defined = function(_) {
13894 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), area) : defined;
13895 };
13896
13897 area.curve = function(_) {
13898 return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
13899 };
13900
13901 area.context = function(_) {
13902 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
13903 };
13904
13905 return area;
13906 }
13907
13908 function descending$1(a, b) {
13909 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
13910 }
13911
13912 function identity$7(d) {
13913 return d;
13914 }
13915
13916 function pie() {
13917 var value = identity$7,
13918 sortValues = descending$1,
13919 sort = null,
13920 startAngle = constant$10(0),
13921 endAngle = constant$10(tau$4),
13922 padAngle = constant$10(0);
13923
13924 function pie(data) {
13925 var i,
13926 n = data.length,
13927 j,
13928 k,
13929 sum = 0,
13930 index = new Array(n),
13931 arcs = new Array(n),
13932 a0 = +startAngle.apply(this, arguments),
13933 da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
13934 a1,
13935 p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
13936 pa = p * (da < 0 ? -1 : 1),
13937 v;
13938
13939 for (i = 0; i < n; ++i) {
13940 if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
13941 sum += v;
13942 }
13943 }
13944
13945 // Optionally sort the arcs by previously-computed values or by data.
13946 if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
13947 else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
13948
13949 // Compute the arcs! They are stored in the original data's order.
13950 for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
13951 j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
13952 data: data[j],
13953 index: i,
13954 value: v,
13955 startAngle: a0,
13956 endAngle: a1,
13957 padAngle: p
13958 };
13959 }
13960
13961 return arcs;
13962 }
13963
13964 pie.value = function(_) {
13965 return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), pie) : value;
13966 };
13967
13968 pie.sortValues = function(_) {
13969 return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
13970 };
13971
13972 pie.sort = function(_) {
13973 return arguments.length ? (sort = _, sortValues = null, pie) : sort;
13974 };
13975
13976 pie.startAngle = function(_) {
13977 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : startAngle;
13978 };
13979
13980 pie.endAngle = function(_) {
13981 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : endAngle;
13982 };
13983
13984 pie.padAngle = function(_) {
13985 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : padAngle;
13986 };
13987
13988 return pie;
13989 }
13990
13991 var curveRadialLinear = curveRadial(curveLinear);
13992
13993 function Radial(curve) {
13994 this._curve = curve;
13995 }
13996
13997 Radial.prototype = {
13998 areaStart: function() {
13999 this._curve.areaStart();
14000 },
14001 areaEnd: function() {
14002 this._curve.areaEnd();
14003 },
14004 lineStart: function() {
14005 this._curve.lineStart();
14006 },
14007 lineEnd: function() {
14008 this._curve.lineEnd();
14009 },
14010 point: function(a, r) {
14011 this._curve.point(r * Math.sin(a), r * -Math.cos(a));
14012 }
14013 };
14014
14015 function curveRadial(curve) {
14016
14017 function radial(context) {
14018 return new Radial(curve(context));
14019 }
14020
14021 radial._curve = curve;
14022
14023 return radial;
14024 }
14025
14026 function lineRadial(l) {
14027 var c = l.curve;
14028
14029 l.angle = l.x, delete l.x;
14030 l.radius = l.y, delete l.y;
14031
14032 l.curve = function(_) {
14033 return arguments.length ? c(curveRadial(_)) : c()._curve;
14034 };
14035
14036 return l;
14037 }
14038
14039 function lineRadial$1() {
14040 return lineRadial(line().curve(curveRadialLinear));
14041 }
14042
14043 function areaRadial() {
14044 var a = area$2().curve(curveRadialLinear),
14045 c = a.curve,
14046 x0 = a.lineX0,
14047 x1 = a.lineX1,
14048 y0 = a.lineY0,
14049 y1 = a.lineY1;
14050
14051 a.angle = a.x, delete a.x;
14052 a.startAngle = a.x0, delete a.x0;
14053 a.endAngle = a.x1, delete a.x1;
14054 a.radius = a.y, delete a.y;
14055 a.innerRadius = a.y0, delete a.y0;
14056 a.outerRadius = a.y1, delete a.y1;
14057 a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
14058 a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
14059 a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
14060 a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
14061
14062 a.curve = function(_) {
14063 return arguments.length ? c(curveRadial(_)) : c()._curve;
14064 };
14065
14066 return a;
14067 }
14068
14069 function pointRadial(x, y) {
14070 return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
14071 }
14072
14073 var slice$6 = Array.prototype.slice;
14074
14075 function linkSource(d) {
14076 return d.source;
14077 }
14078
14079 function linkTarget(d) {
14080 return d.target;
14081 }
14082
14083 function link$2(curve) {
14084 var source = linkSource,
14085 target = linkTarget,
14086 x$$1 = x$3,
14087 y$$1 = y$3,
14088 context = null;
14089
14090 function link() {
14091 var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
14092 if (!context) context = buffer = path();
14093 curve(context, +x$$1.apply(this, (argv[0] = s, argv)), +y$$1.apply(this, argv), +x$$1.apply(this, (argv[0] = t, argv)), +y$$1.apply(this, argv));
14094 if (buffer) return context = null, buffer + "" || null;
14095 }
14096
14097 link.source = function(_) {
14098 return arguments.length ? (source = _, link) : source;
14099 };
14100
14101 link.target = function(_) {
14102 return arguments.length ? (target = _, link) : target;
14103 };
14104
14105 link.x = function(_) {
14106 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : x$$1;
14107 };
14108
14109 link.y = function(_) {
14110 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : y$$1;
14111 };
14112
14113 link.context = function(_) {
14114 return arguments.length ? (context = _ == null ? null : _, link) : context;
14115 };
14116
14117 return link;
14118 }
14119
14120 function curveHorizontal(context, x0, y0, x1, y1) {
14121 context.moveTo(x0, y0);
14122 context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
14123 }
14124
14125 function curveVertical(context, x0, y0, x1, y1) {
14126 context.moveTo(x0, y0);
14127 context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
14128 }
14129
14130 function curveRadial$1(context, x0, y0, x1, y1) {
14131 var p0 = pointRadial(x0, y0),
14132 p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
14133 p2 = pointRadial(x1, y0),
14134 p3 = pointRadial(x1, y1);
14135 context.moveTo(p0[0], p0[1]);
14136 context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
14137 }
14138
14139 function linkHorizontal() {
14140 return link$2(curveHorizontal);
14141 }
14142
14143 function linkVertical() {
14144 return link$2(curveVertical);
14145 }
14146
14147 function linkRadial() {
14148 var l = link$2(curveRadial$1);
14149 l.angle = l.x, delete l.x;
14150 l.radius = l.y, delete l.y;
14151 return l;
14152 }
14153
14154 var circle$2 = {
14155 draw: function(context, size) {
14156 var r = Math.sqrt(size / pi$4);
14157 context.moveTo(r, 0);
14158 context.arc(0, 0, r, 0, tau$4);
14159 }
14160 };
14161
14162 var cross$2 = {
14163 draw: function(context, size) {
14164 var r = Math.sqrt(size / 5) / 2;
14165 context.moveTo(-3 * r, -r);
14166 context.lineTo(-r, -r);
14167 context.lineTo(-r, -3 * r);
14168 context.lineTo(r, -3 * r);
14169 context.lineTo(r, -r);
14170 context.lineTo(3 * r, -r);
14171 context.lineTo(3 * r, r);
14172 context.lineTo(r, r);
14173 context.lineTo(r, 3 * r);
14174 context.lineTo(-r, 3 * r);
14175 context.lineTo(-r, r);
14176 context.lineTo(-3 * r, r);
14177 context.closePath();
14178 }
14179 };
14180
14181 var tan30 = Math.sqrt(1 / 3);
14182 var tan30_2 = tan30 * 2;
14183
14184 var diamond = {
14185 draw: function(context, size) {
14186 var y = Math.sqrt(size / tan30_2),
14187 x = y * tan30;
14188 context.moveTo(0, -y);
14189 context.lineTo(x, 0);
14190 context.lineTo(0, y);
14191 context.lineTo(-x, 0);
14192 context.closePath();
14193 }
14194 };
14195
14196 var ka = 0.89081309152928522810;
14197 var kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10);
14198 var kx = Math.sin(tau$4 / 10) * kr;
14199 var ky = -Math.cos(tau$4 / 10) * kr;
14200
14201 var star = {
14202 draw: function(context, size) {
14203 var r = Math.sqrt(size * ka),
14204 x = kx * r,
14205 y = ky * r;
14206 context.moveTo(0, -r);
14207 context.lineTo(x, y);
14208 for (var i = 1; i < 5; ++i) {
14209 var a = tau$4 * i / 5,
14210 c = Math.cos(a),
14211 s = Math.sin(a);
14212 context.lineTo(s * r, -c * r);
14213 context.lineTo(c * x - s * y, s * x + c * y);
14214 }
14215 context.closePath();
14216 }
14217 };
14218
14219 var square = {
14220 draw: function(context, size) {
14221 var w = Math.sqrt(size),
14222 x = -w / 2;
14223 context.rect(x, x, w, w);
14224 }
14225 };
14226
14227 var sqrt3 = Math.sqrt(3);
14228
14229 var triangle = {
14230 draw: function(context, size) {
14231 var y = -Math.sqrt(size / (sqrt3 * 3));
14232 context.moveTo(0, y * 2);
14233 context.lineTo(-sqrt3 * y, -y);
14234 context.lineTo(sqrt3 * y, -y);
14235 context.closePath();
14236 }
14237 };
14238
14239 var c = -0.5;
14240 var s = Math.sqrt(3) / 2;
14241 var k = 1 / Math.sqrt(12);
14242 var a = (k / 2 + 1) * 3;
14243
14244 var wye = {
14245 draw: function(context, size) {
14246 var r = Math.sqrt(size / a),
14247 x0 = r / 2,
14248 y0 = r * k,
14249 x1 = x0,
14250 y1 = r * k + r,
14251 x2 = -x1,
14252 y2 = y1;
14253 context.moveTo(x0, y0);
14254 context.lineTo(x1, y1);
14255 context.lineTo(x2, y2);
14256 context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
14257 context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
14258 context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
14259 context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
14260 context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
14261 context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
14262 context.closePath();
14263 }
14264 };
14265
14266 var symbols = [
14267 circle$2,
14268 cross$2,
14269 diamond,
14270 square,
14271 star,
14272 triangle,
14273 wye
14274 ];
14275
14276 function symbol() {
14277 var type = constant$10(circle$2),
14278 size = constant$10(64),
14279 context = null;
14280
14281 function symbol() {
14282 var buffer;
14283 if (!context) context = buffer = path();
14284 type.apply(this, arguments).draw(context, +size.apply(this, arguments));
14285 if (buffer) return context = null, buffer + "" || null;
14286 }
14287
14288 symbol.type = function(_) {
14289 return arguments.length ? (type = typeof _ === "function" ? _ : constant$10(_), symbol) : type;
14290 };
14291
14292 symbol.size = function(_) {
14293 return arguments.length ? (size = typeof _ === "function" ? _ : constant$10(+_), symbol) : size;
14294 };
14295
14296 symbol.context = function(_) {
14297 return arguments.length ? (context = _ == null ? null : _, symbol) : context;
14298 };
14299
14300 return symbol;
14301 }
14302
14303 function noop$2() {}
14304
14305 function point$2(that, x, y) {
14306 that._context.bezierCurveTo(
14307 (2 * that._x0 + that._x1) / 3,
14308 (2 * that._y0 + that._y1) / 3,
14309 (that._x0 + 2 * that._x1) / 3,
14310 (that._y0 + 2 * that._y1) / 3,
14311 (that._x0 + 4 * that._x1 + x) / 6,
14312 (that._y0 + 4 * that._y1 + y) / 6
14313 );
14314 }
14315
14316 function Basis(context) {
14317 this._context = context;
14318 }
14319
14320 Basis.prototype = {
14321 areaStart: function() {
14322 this._line = 0;
14323 },
14324 areaEnd: function() {
14325 this._line = NaN;
14326 },
14327 lineStart: function() {
14328 this._x0 = this._x1 =
14329 this._y0 = this._y1 = NaN;
14330 this._point = 0;
14331 },
14332 lineEnd: function() {
14333 switch (this._point) {
14334 case 3: point$2(this, this._x1, this._y1); // proceed
14335 case 2: this._context.lineTo(this._x1, this._y1); break;
14336 }
14337 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14338 this._line = 1 - this._line;
14339 },
14340 point: function(x, y) {
14341 x = +x, y = +y;
14342 switch (this._point) {
14343 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14344 case 1: this._point = 2; break;
14345 case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
14346 default: point$2(this, x, y); break;
14347 }
14348 this._x0 = this._x1, this._x1 = x;
14349 this._y0 = this._y1, this._y1 = y;
14350 }
14351 };
14352
14353 function basis$2(context) {
14354 return new Basis(context);
14355 }
14356
14357 function BasisClosed(context) {
14358 this._context = context;
14359 }
14360
14361 BasisClosed.prototype = {
14362 areaStart: noop$2,
14363 areaEnd: noop$2,
14364 lineStart: function() {
14365 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
14366 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
14367 this._point = 0;
14368 },
14369 lineEnd: function() {
14370 switch (this._point) {
14371 case 1: {
14372 this._context.moveTo(this._x2, this._y2);
14373 this._context.closePath();
14374 break;
14375 }
14376 case 2: {
14377 this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
14378 this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
14379 this._context.closePath();
14380 break;
14381 }
14382 case 3: {
14383 this.point(this._x2, this._y2);
14384 this.point(this._x3, this._y3);
14385 this.point(this._x4, this._y4);
14386 break;
14387 }
14388 }
14389 },
14390 point: function(x, y) {
14391 x = +x, y = +y;
14392 switch (this._point) {
14393 case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
14394 case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
14395 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;
14396 default: point$2(this, x, y); break;
14397 }
14398 this._x0 = this._x1, this._x1 = x;
14399 this._y0 = this._y1, this._y1 = y;
14400 }
14401 };
14402
14403 function basisClosed$1(context) {
14404 return new BasisClosed(context);
14405 }
14406
14407 function BasisOpen(context) {
14408 this._context = context;
14409 }
14410
14411 BasisOpen.prototype = {
14412 areaStart: function() {
14413 this._line = 0;
14414 },
14415 areaEnd: function() {
14416 this._line = NaN;
14417 },
14418 lineStart: function() {
14419 this._x0 = this._x1 =
14420 this._y0 = this._y1 = NaN;
14421 this._point = 0;
14422 },
14423 lineEnd: function() {
14424 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
14425 this._line = 1 - this._line;
14426 },
14427 point: function(x, y) {
14428 x = +x, y = +y;
14429 switch (this._point) {
14430 case 0: this._point = 1; break;
14431 case 1: this._point = 2; break;
14432 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;
14433 case 3: this._point = 4; // proceed
14434 default: point$2(this, x, y); break;
14435 }
14436 this._x0 = this._x1, this._x1 = x;
14437 this._y0 = this._y1, this._y1 = y;
14438 }
14439 };
14440
14441 function basisOpen(context) {
14442 return new BasisOpen(context);
14443 }
14444
14445 function Bundle(context, beta) {
14446 this._basis = new Basis(context);
14447 this._beta = beta;
14448 }
14449
14450 Bundle.prototype = {
14451 lineStart: function() {
14452 this._x = [];
14453 this._y = [];
14454 this._basis.lineStart();
14455 },
14456 lineEnd: function() {
14457 var x = this._x,
14458 y = this._y,
14459 j = x.length - 1;
14460
14461 if (j > 0) {
14462 var x0 = x[0],
14463 y0 = y[0],
14464 dx = x[j] - x0,
14465 dy = y[j] - y0,
14466 i = -1,
14467 t;
14468
14469 while (++i <= j) {
14470 t = i / j;
14471 this._basis.point(
14472 this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
14473 this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
14474 );
14475 }
14476 }
14477
14478 this._x = this._y = null;
14479 this._basis.lineEnd();
14480 },
14481 point: function(x, y) {
14482 this._x.push(+x);
14483 this._y.push(+y);
14484 }
14485 };
14486
14487 var bundle = (function custom(beta) {
14488
14489 function bundle(context) {
14490 return beta === 1 ? new Basis(context) : new Bundle(context, beta);
14491 }
14492
14493 bundle.beta = function(beta) {
14494 return custom(+beta);
14495 };
14496
14497 return bundle;
14498 })(0.85);
14499
14500 function point$3(that, x, y) {
14501 that._context.bezierCurveTo(
14502 that._x1 + that._k * (that._x2 - that._x0),
14503 that._y1 + that._k * (that._y2 - that._y0),
14504 that._x2 + that._k * (that._x1 - x),
14505 that._y2 + that._k * (that._y1 - y),
14506 that._x2,
14507 that._y2
14508 );
14509 }
14510
14511 function Cardinal(context, tension) {
14512 this._context = context;
14513 this._k = (1 - tension) / 6;
14514 }
14515
14516 Cardinal.prototype = {
14517 areaStart: function() {
14518 this._line = 0;
14519 },
14520 areaEnd: function() {
14521 this._line = NaN;
14522 },
14523 lineStart: function() {
14524 this._x0 = this._x1 = this._x2 =
14525 this._y0 = this._y1 = this._y2 = NaN;
14526 this._point = 0;
14527 },
14528 lineEnd: function() {
14529 switch (this._point) {
14530 case 2: this._context.lineTo(this._x2, this._y2); break;
14531 case 3: point$3(this, this._x1, this._y1); break;
14532 }
14533 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14534 this._line = 1 - this._line;
14535 },
14536 point: function(x, y) {
14537 x = +x, y = +y;
14538 switch (this._point) {
14539 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14540 case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
14541 case 2: this._point = 3; // proceed
14542 default: point$3(this, x, y); break;
14543 }
14544 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14545 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14546 }
14547 };
14548
14549 var cardinal = (function custom(tension) {
14550
14551 function cardinal(context) {
14552 return new Cardinal(context, tension);
14553 }
14554
14555 cardinal.tension = function(tension) {
14556 return custom(+tension);
14557 };
14558
14559 return cardinal;
14560 })(0);
14561
14562 function CardinalClosed(context, tension) {
14563 this._context = context;
14564 this._k = (1 - tension) / 6;
14565 }
14566
14567 CardinalClosed.prototype = {
14568 areaStart: noop$2,
14569 areaEnd: noop$2,
14570 lineStart: function() {
14571 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
14572 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
14573 this._point = 0;
14574 },
14575 lineEnd: function() {
14576 switch (this._point) {
14577 case 1: {
14578 this._context.moveTo(this._x3, this._y3);
14579 this._context.closePath();
14580 break;
14581 }
14582 case 2: {
14583 this._context.lineTo(this._x3, this._y3);
14584 this._context.closePath();
14585 break;
14586 }
14587 case 3: {
14588 this.point(this._x3, this._y3);
14589 this.point(this._x4, this._y4);
14590 this.point(this._x5, this._y5);
14591 break;
14592 }
14593 }
14594 },
14595 point: function(x, y) {
14596 x = +x, y = +y;
14597 switch (this._point) {
14598 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
14599 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
14600 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
14601 default: point$3(this, x, y); break;
14602 }
14603 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14604 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14605 }
14606 };
14607
14608 var cardinalClosed = (function custom(tension) {
14609
14610 function cardinal$$1(context) {
14611 return new CardinalClosed(context, tension);
14612 }
14613
14614 cardinal$$1.tension = function(tension) {
14615 return custom(+tension);
14616 };
14617
14618 return cardinal$$1;
14619 })(0);
14620
14621 function CardinalOpen(context, tension) {
14622 this._context = context;
14623 this._k = (1 - tension) / 6;
14624 }
14625
14626 CardinalOpen.prototype = {
14627 areaStart: function() {
14628 this._line = 0;
14629 },
14630 areaEnd: function() {
14631 this._line = NaN;
14632 },
14633 lineStart: function() {
14634 this._x0 = this._x1 = this._x2 =
14635 this._y0 = this._y1 = this._y2 = NaN;
14636 this._point = 0;
14637 },
14638 lineEnd: function() {
14639 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
14640 this._line = 1 - this._line;
14641 },
14642 point: function(x, y) {
14643 x = +x, y = +y;
14644 switch (this._point) {
14645 case 0: this._point = 1; break;
14646 case 1: this._point = 2; break;
14647 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
14648 case 3: this._point = 4; // proceed
14649 default: point$3(this, x, y); break;
14650 }
14651 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14652 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14653 }
14654 };
14655
14656 var cardinalOpen = (function custom(tension) {
14657
14658 function cardinal$$1(context) {
14659 return new CardinalOpen(context, tension);
14660 }
14661
14662 cardinal$$1.tension = function(tension) {
14663 return custom(+tension);
14664 };
14665
14666 return cardinal$$1;
14667 })(0);
14668
14669 function point$4(that, x, y) {
14670 var x1 = that._x1,
14671 y1 = that._y1,
14672 x2 = that._x2,
14673 y2 = that._y2;
14674
14675 if (that._l01_a > epsilon$3) {
14676 var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
14677 n = 3 * that._l01_a * (that._l01_a + that._l12_a);
14678 x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
14679 y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
14680 }
14681
14682 if (that._l23_a > epsilon$3) {
14683 var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
14684 m = 3 * that._l23_a * (that._l23_a + that._l12_a);
14685 x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
14686 y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
14687 }
14688
14689 that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
14690 }
14691
14692 function CatmullRom(context, alpha) {
14693 this._context = context;
14694 this._alpha = alpha;
14695 }
14696
14697 CatmullRom.prototype = {
14698 areaStart: function() {
14699 this._line = 0;
14700 },
14701 areaEnd: function() {
14702 this._line = NaN;
14703 },
14704 lineStart: function() {
14705 this._x0 = this._x1 = this._x2 =
14706 this._y0 = this._y1 = this._y2 = NaN;
14707 this._l01_a = this._l12_a = this._l23_a =
14708 this._l01_2a = this._l12_2a = this._l23_2a =
14709 this._point = 0;
14710 },
14711 lineEnd: function() {
14712 switch (this._point) {
14713 case 2: this._context.lineTo(this._x2, this._y2); break;
14714 case 3: this.point(this._x2, this._y2); break;
14715 }
14716 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14717 this._line = 1 - this._line;
14718 },
14719 point: function(x, y) {
14720 x = +x, y = +y;
14721
14722 if (this._point) {
14723 var x23 = this._x2 - x,
14724 y23 = this._y2 - y;
14725 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
14726 }
14727
14728 switch (this._point) {
14729 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14730 case 1: this._point = 2; break;
14731 case 2: this._point = 3; // proceed
14732 default: point$4(this, x, y); break;
14733 }
14734
14735 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
14736 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
14737 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14738 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14739 }
14740 };
14741
14742 var catmullRom = (function custom(alpha) {
14743
14744 function catmullRom(context) {
14745 return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
14746 }
14747
14748 catmullRom.alpha = function(alpha) {
14749 return custom(+alpha);
14750 };
14751
14752 return catmullRom;
14753 })(0.5);
14754
14755 function CatmullRomClosed(context, alpha) {
14756 this._context = context;
14757 this._alpha = alpha;
14758 }
14759
14760 CatmullRomClosed.prototype = {
14761 areaStart: noop$2,
14762 areaEnd: noop$2,
14763 lineStart: function() {
14764 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
14765 this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
14766 this._l01_a = this._l12_a = this._l23_a =
14767 this._l01_2a = this._l12_2a = this._l23_2a =
14768 this._point = 0;
14769 },
14770 lineEnd: function() {
14771 switch (this._point) {
14772 case 1: {
14773 this._context.moveTo(this._x3, this._y3);
14774 this._context.closePath();
14775 break;
14776 }
14777 case 2: {
14778 this._context.lineTo(this._x3, this._y3);
14779 this._context.closePath();
14780 break;
14781 }
14782 case 3: {
14783 this.point(this._x3, this._y3);
14784 this.point(this._x4, this._y4);
14785 this.point(this._x5, this._y5);
14786 break;
14787 }
14788 }
14789 },
14790 point: function(x, y) {
14791 x = +x, y = +y;
14792
14793 if (this._point) {
14794 var x23 = this._x2 - x,
14795 y23 = this._y2 - y;
14796 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
14797 }
14798
14799 switch (this._point) {
14800 case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
14801 case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
14802 case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
14803 default: point$4(this, x, y); break;
14804 }
14805
14806 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
14807 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
14808 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14809 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14810 }
14811 };
14812
14813 var catmullRomClosed = (function custom(alpha) {
14814
14815 function catmullRom$$1(context) {
14816 return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
14817 }
14818
14819 catmullRom$$1.alpha = function(alpha) {
14820 return custom(+alpha);
14821 };
14822
14823 return catmullRom$$1;
14824 })(0.5);
14825
14826 function CatmullRomOpen(context, alpha) {
14827 this._context = context;
14828 this._alpha = alpha;
14829 }
14830
14831 CatmullRomOpen.prototype = {
14832 areaStart: function() {
14833 this._line = 0;
14834 },
14835 areaEnd: function() {
14836 this._line = NaN;
14837 },
14838 lineStart: function() {
14839 this._x0 = this._x1 = this._x2 =
14840 this._y0 = this._y1 = this._y2 = NaN;
14841 this._l01_a = this._l12_a = this._l23_a =
14842 this._l01_2a = this._l12_2a = this._l23_2a =
14843 this._point = 0;
14844 },
14845 lineEnd: function() {
14846 if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
14847 this._line = 1 - this._line;
14848 },
14849 point: function(x, y) {
14850 x = +x, y = +y;
14851
14852 if (this._point) {
14853 var x23 = this._x2 - x,
14854 y23 = this._y2 - y;
14855 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
14856 }
14857
14858 switch (this._point) {
14859 case 0: this._point = 1; break;
14860 case 1: this._point = 2; break;
14861 case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
14862 case 3: this._point = 4; // proceed
14863 default: point$4(this, x, y); break;
14864 }
14865
14866 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
14867 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
14868 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14869 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14870 }
14871 };
14872
14873 var catmullRomOpen = (function custom(alpha) {
14874
14875 function catmullRom$$1(context) {
14876 return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
14877 }
14878
14879 catmullRom$$1.alpha = function(alpha) {
14880 return custom(+alpha);
14881 };
14882
14883 return catmullRom$$1;
14884 })(0.5);
14885
14886 function LinearClosed(context) {
14887 this._context = context;
14888 }
14889
14890 LinearClosed.prototype = {
14891 areaStart: noop$2,
14892 areaEnd: noop$2,
14893 lineStart: function() {
14894 this._point = 0;
14895 },
14896 lineEnd: function() {
14897 if (this._point) this._context.closePath();
14898 },
14899 point: function(x, y) {
14900 x = +x, y = +y;
14901 if (this._point) this._context.lineTo(x, y);
14902 else this._point = 1, this._context.moveTo(x, y);
14903 }
14904 };
14905
14906 function linearClosed(context) {
14907 return new LinearClosed(context);
14908 }
14909
14910 function sign$1(x) {
14911 return x < 0 ? -1 : 1;
14912 }
14913
14914 // Calculate the slopes of the tangents (Hermite-type interpolation) based on
14915 // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
14916 // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
14917 // NOV(II), P. 443, 1990.
14918 function slope3(that, x2, y2) {
14919 var h0 = that._x1 - that._x0,
14920 h1 = x2 - that._x1,
14921 s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
14922 s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
14923 p = (s0 * h1 + s1 * h0) / (h0 + h1);
14924 return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
14925 }
14926
14927 // Calculate a one-sided slope.
14928 function slope2(that, t) {
14929 var h = that._x1 - that._x0;
14930 return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
14931 }
14932
14933 // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
14934 // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
14935 // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
14936 function point$5(that, t0, t1) {
14937 var x0 = that._x0,
14938 y0 = that._y0,
14939 x1 = that._x1,
14940 y1 = that._y1,
14941 dx = (x1 - x0) / 3;
14942 that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
14943 }
14944
14945 function MonotoneX(context) {
14946 this._context = context;
14947 }
14948
14949 MonotoneX.prototype = {
14950 areaStart: function() {
14951 this._line = 0;
14952 },
14953 areaEnd: function() {
14954 this._line = NaN;
14955 },
14956 lineStart: function() {
14957 this._x0 = this._x1 =
14958 this._y0 = this._y1 =
14959 this._t0 = NaN;
14960 this._point = 0;
14961 },
14962 lineEnd: function() {
14963 switch (this._point) {
14964 case 2: this._context.lineTo(this._x1, this._y1); break;
14965 case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
14966 }
14967 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14968 this._line = 1 - this._line;
14969 },
14970 point: function(x, y) {
14971 var t1 = NaN;
14972
14973 x = +x, y = +y;
14974 if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
14975 switch (this._point) {
14976 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14977 case 1: this._point = 2; break;
14978 case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
14979 default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
14980 }
14981
14982 this._x0 = this._x1, this._x1 = x;
14983 this._y0 = this._y1, this._y1 = y;
14984 this._t0 = t1;
14985 }
14986 };
14987
14988 function MonotoneY(context) {
14989 this._context = new ReflectContext(context);
14990 }
14991
14992 (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
14993 MonotoneX.prototype.point.call(this, y, x);
14994 };
14995
14996 function ReflectContext(context) {
14997 this._context = context;
14998 }
14999
15000 ReflectContext.prototype = {
15001 moveTo: function(x, y) { this._context.moveTo(y, x); },
15002 closePath: function() { this._context.closePath(); },
15003 lineTo: function(x, y) { this._context.lineTo(y, x); },
15004 bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
15005 };
15006
15007 function monotoneX(context) {
15008 return new MonotoneX(context);
15009 }
15010
15011 function monotoneY(context) {
15012 return new MonotoneY(context);
15013 }
15014
15015 function Natural(context) {
15016 this._context = context;
15017 }
15018
15019 Natural.prototype = {
15020 areaStart: function() {
15021 this._line = 0;
15022 },
15023 areaEnd: function() {
15024 this._line = NaN;
15025 },
15026 lineStart: function() {
15027 this._x = [];
15028 this._y = [];
15029 },
15030 lineEnd: function() {
15031 var x = this._x,
15032 y = this._y,
15033 n = x.length;
15034
15035 if (n) {
15036 this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
15037 if (n === 2) {
15038 this._context.lineTo(x[1], y[1]);
15039 } else {
15040 var px = controlPoints(x),
15041 py = controlPoints(y);
15042 for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
15043 this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
15044 }
15045 }
15046 }
15047
15048 if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
15049 this._line = 1 - this._line;
15050 this._x = this._y = null;
15051 },
15052 point: function(x, y) {
15053 this._x.push(+x);
15054 this._y.push(+y);
15055 }
15056 };
15057
15058 // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
15059 function controlPoints(x) {
15060 var i,
15061 n = x.length - 1,
15062 m,
15063 a = new Array(n),
15064 b = new Array(n),
15065 r = new Array(n);
15066 a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
15067 for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
15068 a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
15069 for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
15070 a[n - 1] = r[n - 1] / b[n - 1];
15071 for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
15072 b[n - 1] = (x[n] + a[n - 1]) / 2;
15073 for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
15074 return [a, b];
15075 }
15076
15077 function natural(context) {
15078 return new Natural(context);
15079 }
15080
15081 function Step(context, t) {
15082 this._context = context;
15083 this._t = t;
15084 }
15085
15086 Step.prototype = {
15087 areaStart: function() {
15088 this._line = 0;
15089 },
15090 areaEnd: function() {
15091 this._line = NaN;
15092 },
15093 lineStart: function() {
15094 this._x = this._y = NaN;
15095 this._point = 0;
15096 },
15097 lineEnd: function() {
15098 if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
15099 if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15100 if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
15101 },
15102 point: function(x, y) {
15103 x = +x, y = +y;
15104 switch (this._point) {
15105 case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15106 case 1: this._point = 2; // proceed
15107 default: {
15108 if (this._t <= 0) {
15109 this._context.lineTo(this._x, y);
15110 this._context.lineTo(x, y);
15111 } else {
15112 var x1 = this._x * (1 - this._t) + x * this._t;
15113 this._context.lineTo(x1, this._y);
15114 this._context.lineTo(x1, y);
15115 }
15116 break;
15117 }
15118 }
15119 this._x = x, this._y = y;
15120 }
15121 };
15122
15123 function step(context) {
15124 return new Step(context, 0.5);
15125 }
15126
15127 function stepBefore(context) {
15128 return new Step(context, 0);
15129 }
15130
15131 function stepAfter(context) {
15132 return new Step(context, 1);
15133 }
15134
15135 function none$1(series, order) {
15136 if (!((n = series.length) > 1)) return;
15137 for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
15138 s0 = s1, s1 = series[order[i]];
15139 for (j = 0; j < m; ++j) {
15140 s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
15141 }
15142 }
15143 }
15144
15145 function none$2(series) {
15146 var n = series.length, o = new Array(n);
15147 while (--n >= 0) o[n] = n;
15148 return o;
15149 }
15150
15151 function stackValue(d, key) {
15152 return d[key];
15153 }
15154
15155 function stack() {
15156 var keys = constant$10([]),
15157 order = none$2,
15158 offset = none$1,
15159 value = stackValue;
15160
15161 function stack(data) {
15162 var kz = keys.apply(this, arguments),
15163 i,
15164 m = data.length,
15165 n = kz.length,
15166 sz = new Array(n),
15167 oz;
15168
15169 for (i = 0; i < n; ++i) {
15170 for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
15171 si[j] = sij = [0, +value(data[j], ki, j, data)];
15172 sij.data = data[j];
15173 }
15174 si.key = ki;
15175 }
15176
15177 for (i = 0, oz = order(sz); i < n; ++i) {
15178 sz[oz[i]].index = i;
15179 }
15180
15181 offset(sz, oz);
15182 return sz;
15183 }
15184
15185 stack.keys = function(_) {
15186 return arguments.length ? (keys = typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : keys;
15187 };
15188
15189 stack.value = function(_) {
15190 return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), stack) : value;
15191 };
15192
15193 stack.order = function(_) {
15194 return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : order;
15195 };
15196
15197 stack.offset = function(_) {
15198 return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
15199 };
15200
15201 return stack;
15202 }
15203
15204 function expand(series, order) {
15205 if (!((n = series.length) > 0)) return;
15206 for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
15207 for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
15208 if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
15209 }
15210 none$1(series, order);
15211 }
15212
15213 function diverging(series, order) {
15214 if (!((n = series.length) > 1)) return;
15215 for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
15216 for (yp = yn = 0, i = 0; i < n; ++i) {
15217 if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
15218 d[0] = yp, d[1] = yp += dy;
15219 } else if (dy < 0) {
15220 d[1] = yn, d[0] = yn += dy;
15221 } else {
15222 d[0] = yp;
15223 }
15224 }
15225 }
15226 }
15227
15228 function silhouette(series, order) {
15229 if (!((n = series.length) > 0)) return;
15230 for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
15231 for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
15232 s0[j][1] += s0[j][0] = -y / 2;
15233 }
15234 none$1(series, order);
15235 }
15236
15237 function wiggle(series, order) {
15238 if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
15239 for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
15240 for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
15241 var si = series[order[i]],
15242 sij0 = si[j][1] || 0,
15243 sij1 = si[j - 1][1] || 0,
15244 s3 = (sij0 - sij1) / 2;
15245 for (var k = 0; k < i; ++k) {
15246 var sk = series[order[k]],
15247 skj0 = sk[j][1] || 0,
15248 skj1 = sk[j - 1][1] || 0;
15249 s3 += skj0 - skj1;
15250 }
15251 s1 += sij0, s2 += s3 * sij0;
15252 }
15253 s0[j - 1][1] += s0[j - 1][0] = y;
15254 if (s1) y -= s2 / s1;
15255 }
15256 s0[j - 1][1] += s0[j - 1][0] = y;
15257 none$1(series, order);
15258 }
15259
15260 function ascending$2(series) {
15261 var sums = series.map(sum$2);
15262 return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
15263 }
15264
15265 function sum$2(series) {
15266 var s = 0, i = -1, n = series.length, v;
15267 while (++i < n) if (v = +series[i][1]) s += v;
15268 return s;
15269 }
15270
15271 function descending$2(series) {
15272 return ascending$2(series).reverse();
15273 }
15274
15275 function insideOut(series) {
15276 var n = series.length,
15277 i,
15278 j,
15279 sums = series.map(sum$2),
15280 order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
15281 top = 0,
15282 bottom = 0,
15283 tops = [],
15284 bottoms = [];
15285
15286 for (i = 0; i < n; ++i) {
15287 j = order[i];
15288 if (top < bottom) {
15289 top += sums[j];
15290 tops.push(j);
15291 } else {
15292 bottom += sums[j];
15293 bottoms.push(j);
15294 }
15295 }
15296
15297 return bottoms.reverse().concat(tops);
15298 }
15299
15300 function reverse(series) {
15301 return none$2(series).reverse();
15302 }
15303
15304 function constant$11(x) {
15305 return function() {
15306 return x;
15307 };
15308 }
15309
15310 function x$4(d) {
15311 return d[0];
15312 }
15313
15314 function y$4(d) {
15315 return d[1];
15316 }
15317
15318 function RedBlackTree() {
15319 this._ = null; // root node
15320 }
15321
15322 function RedBlackNode(node) {
15323 node.U = // parent node
15324 node.C = // color - true for red, false for black
15325 node.L = // left node
15326 node.R = // right node
15327 node.P = // previous node
15328 node.N = null; // next node
15329 }
15330
15331 RedBlackTree.prototype = {
15332 constructor: RedBlackTree,
15333
15334 insert: function(after, node) {
15335 var parent, grandpa, uncle;
15336
15337 if (after) {
15338 node.P = after;
15339 node.N = after.N;
15340 if (after.N) after.N.P = node;
15341 after.N = node;
15342 if (after.R) {
15343 after = after.R;
15344 while (after.L) after = after.L;
15345 after.L = node;
15346 } else {
15347 after.R = node;
15348 }
15349 parent = after;
15350 } else if (this._) {
15351 after = RedBlackFirst(this._);
15352 node.P = null;
15353 node.N = after;
15354 after.P = after.L = node;
15355 parent = after;
15356 } else {
15357 node.P = node.N = null;
15358 this._ = node;
15359 parent = null;
15360 }
15361 node.L = node.R = null;
15362 node.U = parent;
15363 node.C = true;
15364
15365 after = node;
15366 while (parent && parent.C) {
15367 grandpa = parent.U;
15368 if (parent === grandpa.L) {
15369 uncle = grandpa.R;
15370 if (uncle && uncle.C) {
15371 parent.C = uncle.C = false;
15372 grandpa.C = true;
15373 after = grandpa;
15374 } else {
15375 if (after === parent.R) {
15376 RedBlackRotateLeft(this, parent);
15377 after = parent;
15378 parent = after.U;
15379 }
15380 parent.C = false;
15381 grandpa.C = true;
15382 RedBlackRotateRight(this, grandpa);
15383 }
15384 } else {
15385 uncle = grandpa.L;
15386 if (uncle && uncle.C) {
15387 parent.C = uncle.C = false;
15388 grandpa.C = true;
15389 after = grandpa;
15390 } else {
15391 if (after === parent.L) {
15392 RedBlackRotateRight(this, parent);
15393 after = parent;
15394 parent = after.U;
15395 }
15396 parent.C = false;
15397 grandpa.C = true;
15398 RedBlackRotateLeft(this, grandpa);
15399 }
15400 }
15401 parent = after.U;
15402 }
15403 this._.C = false;
15404 },
15405
15406 remove: function(node) {
15407 if (node.N) node.N.P = node.P;
15408 if (node.P) node.P.N = node.N;
15409 node.N = node.P = null;
15410
15411 var parent = node.U,
15412 sibling,
15413 left = node.L,
15414 right = node.R,
15415 next,
15416 red;
15417
15418 if (!left) next = right;
15419 else if (!right) next = left;
15420 else next = RedBlackFirst(right);
15421
15422 if (parent) {
15423 if (parent.L === node) parent.L = next;
15424 else parent.R = next;
15425 } else {
15426 this._ = next;
15427 }
15428
15429 if (left && right) {
15430 red = next.C;
15431 next.C = node.C;
15432 next.L = left;
15433 left.U = next;
15434 if (next !== right) {
15435 parent = next.U;
15436 next.U = node.U;
15437 node = next.R;
15438 parent.L = node;
15439 next.R = right;
15440 right.U = next;
15441 } else {
15442 next.U = parent;
15443 parent = next;
15444 node = next.R;
15445 }
15446 } else {
15447 red = node.C;
15448 node = next;
15449 }
15450
15451 if (node) node.U = parent;
15452 if (red) return;
15453 if (node && node.C) { node.C = false; return; }
15454
15455 do {
15456 if (node === this._) break;
15457 if (node === parent.L) {
15458 sibling = parent.R;
15459 if (sibling.C) {
15460 sibling.C = false;
15461 parent.C = true;
15462 RedBlackRotateLeft(this, parent);
15463 sibling = parent.R;
15464 }
15465 if ((sibling.L && sibling.L.C)
15466 || (sibling.R && sibling.R.C)) {
15467 if (!sibling.R || !sibling.R.C) {
15468 sibling.L.C = false;
15469 sibling.C = true;
15470 RedBlackRotateRight(this, sibling);
15471 sibling = parent.R;
15472 }
15473 sibling.C = parent.C;
15474 parent.C = sibling.R.C = false;
15475 RedBlackRotateLeft(this, parent);
15476 node = this._;
15477 break;
15478 }
15479 } else {
15480 sibling = parent.L;
15481 if (sibling.C) {
15482 sibling.C = false;
15483 parent.C = true;
15484 RedBlackRotateRight(this, parent);
15485 sibling = parent.L;
15486 }
15487 if ((sibling.L && sibling.L.C)
15488 || (sibling.R && sibling.R.C)) {
15489 if (!sibling.L || !sibling.L.C) {
15490 sibling.R.C = false;
15491 sibling.C = true;
15492 RedBlackRotateLeft(this, sibling);
15493 sibling = parent.L;
15494 }
15495 sibling.C = parent.C;
15496 parent.C = sibling.L.C = false;
15497 RedBlackRotateRight(this, parent);
15498 node = this._;
15499 break;
15500 }
15501 }
15502 sibling.C = true;
15503 node = parent;
15504 parent = parent.U;
15505 } while (!node.C);
15506
15507 if (node) node.C = false;
15508 }
15509 };
15510
15511 function RedBlackRotateLeft(tree, node) {
15512 var p = node,
15513 q = node.R,
15514 parent = p.U;
15515
15516 if (parent) {
15517 if (parent.L === p) parent.L = q;
15518 else parent.R = q;
15519 } else {
15520 tree._ = q;
15521 }
15522
15523 q.U = parent;
15524 p.U = q;
15525 p.R = q.L;
15526 if (p.R) p.R.U = p;
15527 q.L = p;
15528 }
15529
15530 function RedBlackRotateRight(tree, node) {
15531 var p = node,
15532 q = node.L,
15533 parent = p.U;
15534
15535 if (parent) {
15536 if (parent.L === p) parent.L = q;
15537 else parent.R = q;
15538 } else {
15539 tree._ = q;
15540 }
15541
15542 q.U = parent;
15543 p.U = q;
15544 p.L = q.R;
15545 if (p.L) p.L.U = p;
15546 q.R = p;
15547 }
15548
15549 function RedBlackFirst(node) {
15550 while (node.L) node = node.L;
15551 return node;
15552 }
15553
15554 function createEdge(left, right, v0, v1) {
15555 var edge = [null, null],
15556 index = edges.push(edge) - 1;
15557 edge.left = left;
15558 edge.right = right;
15559 if (v0) setEdgeEnd(edge, left, right, v0);
15560 if (v1) setEdgeEnd(edge, right, left, v1);
15561 cells[left.index].halfedges.push(index);
15562 cells[right.index].halfedges.push(index);
15563 return edge;
15564 }
15565
15566 function createBorderEdge(left, v0, v1) {
15567 var edge = [v0, v1];
15568 edge.left = left;
15569 return edge;
15570 }
15571
15572 function setEdgeEnd(edge, left, right, vertex) {
15573 if (!edge[0] && !edge[1]) {
15574 edge[0] = vertex;
15575 edge.left = left;
15576 edge.right = right;
15577 } else if (edge.left === right) {
15578 edge[1] = vertex;
15579 } else {
15580 edge[0] = vertex;
15581 }
15582 }
15583
15584 // Liang–Barsky line clipping.
15585 function clipEdge(edge, x0, y0, x1, y1) {
15586 var a = edge[0],
15587 b = edge[1],
15588 ax = a[0],
15589 ay = a[1],
15590 bx = b[0],
15591 by = b[1],
15592 t0 = 0,
15593 t1 = 1,
15594 dx = bx - ax,
15595 dy = by - ay,
15596 r;
15597
15598 r = x0 - ax;
15599 if (!dx && r > 0) return;
15600 r /= dx;
15601 if (dx < 0) {
15602 if (r < t0) return;
15603 if (r < t1) t1 = r;
15604 } else if (dx > 0) {
15605 if (r > t1) return;
15606 if (r > t0) t0 = r;
15607 }
15608
15609 r = x1 - ax;
15610 if (!dx && r < 0) return;
15611 r /= dx;
15612 if (dx < 0) {
15613 if (r > t1) return;
15614 if (r > t0) t0 = r;
15615 } else if (dx > 0) {
15616 if (r < t0) return;
15617 if (r < t1) t1 = r;
15618 }
15619
15620 r = y0 - ay;
15621 if (!dy && r > 0) return;
15622 r /= dy;
15623 if (dy < 0) {
15624 if (r < t0) return;
15625 if (r < t1) t1 = r;
15626 } else if (dy > 0) {
15627 if (r > t1) return;
15628 if (r > t0) t0 = r;
15629 }
15630
15631 r = y1 - ay;
15632 if (!dy && r < 0) return;
15633 r /= dy;
15634 if (dy < 0) {
15635 if (r > t1) return;
15636 if (r > t0) t0 = r;
15637 } else if (dy > 0) {
15638 if (r < t0) return;
15639 if (r < t1) t1 = r;
15640 }
15641
15642 if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
15643
15644 if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
15645 if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
15646 return true;
15647 }
15648
15649 function connectEdge(edge, x0, y0, x1, y1) {
15650 var v1 = edge[1];
15651 if (v1) return true;
15652
15653 var v0 = edge[0],
15654 left = edge.left,
15655 right = edge.right,
15656 lx = left[0],
15657 ly = left[1],
15658 rx = right[0],
15659 ry = right[1],
15660 fx = (lx + rx) / 2,
15661 fy = (ly + ry) / 2,
15662 fm,
15663 fb;
15664
15665 if (ry === ly) {
15666 if (fx < x0 || fx >= x1) return;
15667 if (lx > rx) {
15668 if (!v0) v0 = [fx, y0];
15669 else if (v0[1] >= y1) return;
15670 v1 = [fx, y1];
15671 } else {
15672 if (!v0) v0 = [fx, y1];
15673 else if (v0[1] < y0) return;
15674 v1 = [fx, y0];
15675 }
15676 } else {
15677 fm = (lx - rx) / (ry - ly);
15678 fb = fy - fm * fx;
15679 if (fm < -1 || fm > 1) {
15680 if (lx > rx) {
15681 if (!v0) v0 = [(y0 - fb) / fm, y0];
15682 else if (v0[1] >= y1) return;
15683 v1 = [(y1 - fb) / fm, y1];
15684 } else {
15685 if (!v0) v0 = [(y1 - fb) / fm, y1];
15686 else if (v0[1] < y0) return;
15687 v1 = [(y0 - fb) / fm, y0];
15688 }
15689 } else {
15690 if (ly < ry) {
15691 if (!v0) v0 = [x0, fm * x0 + fb];
15692 else if (v0[0] >= x1) return;
15693 v1 = [x1, fm * x1 + fb];
15694 } else {
15695 if (!v0) v0 = [x1, fm * x1 + fb];
15696 else if (v0[0] < x0) return;
15697 v1 = [x0, fm * x0 + fb];
15698 }
15699 }
15700 }
15701
15702 edge[0] = v0;
15703 edge[1] = v1;
15704 return true;
15705 }
15706
15707 function clipEdges(x0, y0, x1, y1) {
15708 var i = edges.length,
15709 edge;
15710
15711 while (i--) {
15712 if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
15713 || !clipEdge(edge, x0, y0, x1, y1)
15714 || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
15715 || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
15716 delete edges[i];
15717 }
15718 }
15719 }
15720
15721 function createCell(site) {
15722 return cells[site.index] = {
15723 site: site,
15724 halfedges: []
15725 };
15726 }
15727
15728 function cellHalfedgeAngle(cell, edge) {
15729 var site = cell.site,
15730 va = edge.left,
15731 vb = edge.right;
15732 if (site === vb) vb = va, va = site;
15733 if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
15734 if (site === va) va = edge[1], vb = edge[0];
15735 else va = edge[0], vb = edge[1];
15736 return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
15737 }
15738
15739 function cellHalfedgeStart(cell, edge) {
15740 return edge[+(edge.left !== cell.site)];
15741 }
15742
15743 function cellHalfedgeEnd(cell, edge) {
15744 return edge[+(edge.left === cell.site)];
15745 }
15746
15747 function sortCellHalfedges() {
15748 for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
15749 if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
15750 var index = new Array(m),
15751 array = new Array(m);
15752 for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
15753 index.sort(function(i, j) { return array[j] - array[i]; });
15754 for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
15755 for (j = 0; j < m; ++j) halfedges[j] = array[j];
15756 }
15757 }
15758 }
15759
15760 function clipCells(x0, y0, x1, y1) {
15761 var nCells = cells.length,
15762 iCell,
15763 cell,
15764 site,
15765 iHalfedge,
15766 halfedges,
15767 nHalfedges,
15768 start,
15769 startX,
15770 startY,
15771 end,
15772 endX,
15773 endY,
15774 cover = true;
15775
15776 for (iCell = 0; iCell < nCells; ++iCell) {
15777 if (cell = cells[iCell]) {
15778 site = cell.site;
15779 halfedges = cell.halfedges;
15780 iHalfedge = halfedges.length;
15781
15782 // Remove any dangling clipped edges.
15783 while (iHalfedge--) {
15784 if (!edges[halfedges[iHalfedge]]) {
15785 halfedges.splice(iHalfedge, 1);
15786 }
15787 }
15788
15789 // Insert any border edges as necessary.
15790 iHalfedge = 0, nHalfedges = halfedges.length;
15791 while (iHalfedge < nHalfedges) {
15792 end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
15793 start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
15794 if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
15795 halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
15796 Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
15797 : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
15798 : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
15799 : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
15800 : null)) - 1);
15801 ++nHalfedges;
15802 }
15803 }
15804
15805 if (nHalfedges) cover = false;
15806 }
15807 }
15808
15809 // If there weren’t any edges, have the closest site cover the extent.
15810 // It doesn’t matter which corner of the extent we measure!
15811 if (cover) {
15812 var dx, dy, d2, dc = Infinity;
15813
15814 for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
15815 if (cell = cells[iCell]) {
15816 site = cell.site;
15817 dx = site[0] - x0;
15818 dy = site[1] - y0;
15819 d2 = dx * dx + dy * dy;
15820 if (d2 < dc) dc = d2, cover = cell;
15821 }
15822 }
15823
15824 if (cover) {
15825 var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
15826 cover.halfedges.push(
15827 edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
15828 edges.push(createBorderEdge(site, v01, v11)) - 1,
15829 edges.push(createBorderEdge(site, v11, v10)) - 1,
15830 edges.push(createBorderEdge(site, v10, v00)) - 1
15831 );
15832 }
15833 }
15834
15835 // Lastly delete any cells with no edges; these were entirely clipped.
15836 for (iCell = 0; iCell < nCells; ++iCell) {
15837 if (cell = cells[iCell]) {
15838 if (!cell.halfedges.length) {
15839 delete cells[iCell];
15840 }
15841 }
15842 }
15843 }
15844
15845 var circlePool = [];
15846
15847 var firstCircle;
15848
15849 function Circle() {
15850 RedBlackNode(this);
15851 this.x =
15852 this.y =
15853 this.arc =
15854 this.site =
15855 this.cy = null;
15856 }
15857
15858 function attachCircle(arc) {
15859 var lArc = arc.P,
15860 rArc = arc.N;
15861
15862 if (!lArc || !rArc) return;
15863
15864 var lSite = lArc.site,
15865 cSite = arc.site,
15866 rSite = rArc.site;
15867
15868 if (lSite === rSite) return;
15869
15870 var bx = cSite[0],
15871 by = cSite[1],
15872 ax = lSite[0] - bx,
15873 ay = lSite[1] - by,
15874 cx = rSite[0] - bx,
15875 cy = rSite[1] - by;
15876
15877 var d = 2 * (ax * cy - ay * cx);
15878 if (d >= -epsilon2$2) return;
15879
15880 var ha = ax * ax + ay * ay,
15881 hc = cx * cx + cy * cy,
15882 x = (cy * ha - ay * hc) / d,
15883 y = (ax * hc - cx * ha) / d;
15884
15885 var circle = circlePool.pop() || new Circle;
15886 circle.arc = arc;
15887 circle.site = cSite;
15888 circle.x = x + bx;
15889 circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
15890
15891 arc.circle = circle;
15892
15893 var before = null,
15894 node = circles._;
15895
15896 while (node) {
15897 if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
15898 if (node.L) node = node.L;
15899 else { before = node.P; break; }
15900 } else {
15901 if (node.R) node = node.R;
15902 else { before = node; break; }
15903 }
15904 }
15905
15906 circles.insert(before, circle);
15907 if (!before) firstCircle = circle;
15908 }
15909
15910 function detachCircle(arc) {
15911 var circle = arc.circle;
15912 if (circle) {
15913 if (!circle.P) firstCircle = circle.N;
15914 circles.remove(circle);
15915 circlePool.push(circle);
15916 RedBlackNode(circle);
15917 arc.circle = null;
15918 }
15919 }
15920
15921 var beachPool = [];
15922
15923 function Beach() {
15924 RedBlackNode(this);
15925 this.edge =
15926 this.site =
15927 this.circle = null;
15928 }
15929
15930 function createBeach(site) {
15931 var beach = beachPool.pop() || new Beach;
15932 beach.site = site;
15933 return beach;
15934 }
15935
15936 function detachBeach(beach) {
15937 detachCircle(beach);
15938 beaches.remove(beach);
15939 beachPool.push(beach);
15940 RedBlackNode(beach);
15941 }
15942
15943 function removeBeach(beach) {
15944 var circle = beach.circle,
15945 x = circle.x,
15946 y = circle.cy,
15947 vertex = [x, y],
15948 previous = beach.P,
15949 next = beach.N,
15950 disappearing = [beach];
15951
15952 detachBeach(beach);
15953
15954 var lArc = previous;
15955 while (lArc.circle
15956 && Math.abs(x - lArc.circle.x) < epsilon$4
15957 && Math.abs(y - lArc.circle.cy) < epsilon$4) {
15958 previous = lArc.P;
15959 disappearing.unshift(lArc);
15960 detachBeach(lArc);
15961 lArc = previous;
15962 }
15963
15964 disappearing.unshift(lArc);
15965 detachCircle(lArc);
15966
15967 var rArc = next;
15968 while (rArc.circle
15969 && Math.abs(x - rArc.circle.x) < epsilon$4
15970 && Math.abs(y - rArc.circle.cy) < epsilon$4) {
15971 next = rArc.N;
15972 disappearing.push(rArc);
15973 detachBeach(rArc);
15974 rArc = next;
15975 }
15976
15977 disappearing.push(rArc);
15978 detachCircle(rArc);
15979
15980 var nArcs = disappearing.length,
15981 iArc;
15982 for (iArc = 1; iArc < nArcs; ++iArc) {
15983 rArc = disappearing[iArc];
15984 lArc = disappearing[iArc - 1];
15985 setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
15986 }
15987
15988 lArc = disappearing[0];
15989 rArc = disappearing[nArcs - 1];
15990 rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
15991
15992 attachCircle(lArc);
15993 attachCircle(rArc);
15994 }
15995
15996 function addBeach(site) {
15997 var x = site[0],
15998 directrix = site[1],
15999 lArc,
16000 rArc,
16001 dxl,
16002 dxr,
16003 node = beaches._;
16004
16005 while (node) {
16006 dxl = leftBreakPoint(node, directrix) - x;
16007 if (dxl > epsilon$4) node = node.L; else {
16008 dxr = x - rightBreakPoint(node, directrix);
16009 if (dxr > epsilon$4) {
16010 if (!node.R) {
16011 lArc = node;
16012 break;
16013 }
16014 node = node.R;
16015 } else {
16016 if (dxl > -epsilon$4) {
16017 lArc = node.P;
16018 rArc = node;
16019 } else if (dxr > -epsilon$4) {
16020 lArc = node;
16021 rArc = node.N;
16022 } else {
16023 lArc = rArc = node;
16024 }
16025 break;
16026 }
16027 }
16028 }
16029
16030 createCell(site);
16031 var newArc = createBeach(site);
16032 beaches.insert(lArc, newArc);
16033
16034 if (!lArc && !rArc) return;
16035
16036 if (lArc === rArc) {
16037 detachCircle(lArc);
16038 rArc = createBeach(lArc.site);
16039 beaches.insert(newArc, rArc);
16040 newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
16041 attachCircle(lArc);
16042 attachCircle(rArc);
16043 return;
16044 }
16045
16046 if (!rArc) { // && lArc
16047 newArc.edge = createEdge(lArc.site, newArc.site);
16048 return;
16049 }
16050
16051 // else lArc !== rArc
16052 detachCircle(lArc);
16053 detachCircle(rArc);
16054
16055 var lSite = lArc.site,
16056 ax = lSite[0],
16057 ay = lSite[1],
16058 bx = site[0] - ax,
16059 by = site[1] - ay,
16060 rSite = rArc.site,
16061 cx = rSite[0] - ax,
16062 cy = rSite[1] - ay,
16063 d = 2 * (bx * cy - by * cx),
16064 hb = bx * bx + by * by,
16065 hc = cx * cx + cy * cy,
16066 vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
16067
16068 setEdgeEnd(rArc.edge, lSite, rSite, vertex);
16069 newArc.edge = createEdge(lSite, site, null, vertex);
16070 rArc.edge = createEdge(site, rSite, null, vertex);
16071 attachCircle(lArc);
16072 attachCircle(rArc);
16073 }
16074
16075 function leftBreakPoint(arc, directrix) {
16076 var site = arc.site,
16077 rfocx = site[0],
16078 rfocy = site[1],
16079 pby2 = rfocy - directrix;
16080
16081 if (!pby2) return rfocx;
16082
16083 var lArc = arc.P;
16084 if (!lArc) return -Infinity;
16085
16086 site = lArc.site;
16087 var lfocx = site[0],
16088 lfocy = site[1],
16089 plby2 = lfocy - directrix;
16090
16091 if (!plby2) return lfocx;
16092
16093 var hl = lfocx - rfocx,
16094 aby2 = 1 / pby2 - 1 / plby2,
16095 b = hl / plby2;
16096
16097 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
16098
16099 return (rfocx + lfocx) / 2;
16100 }
16101
16102 function rightBreakPoint(arc, directrix) {
16103 var rArc = arc.N;
16104 if (rArc) return leftBreakPoint(rArc, directrix);
16105 var site = arc.site;
16106 return site[1] === directrix ? site[0] : Infinity;
16107 }
16108
16109 var epsilon$4 = 1e-6;
16110 var epsilon2$2 = 1e-12;
16111 var beaches;
16112 var cells;
16113 var circles;
16114 var edges;
16115
16116 function triangleArea(a, b, c) {
16117 return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
16118 }
16119
16120 function lexicographic(a, b) {
16121 return b[1] - a[1]
16122 || b[0] - a[0];
16123 }
16124
16125 function Diagram(sites, extent) {
16126 var site = sites.sort(lexicographic).pop(),
16127 x,
16128 y,
16129 circle;
16130
16131 edges = [];
16132 cells = new Array(sites.length);
16133 beaches = new RedBlackTree;
16134 circles = new RedBlackTree;
16135
16136 while (true) {
16137 circle = firstCircle;
16138 if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
16139 if (site[0] !== x || site[1] !== y) {
16140 addBeach(site);
16141 x = site[0], y = site[1];
16142 }
16143 site = sites.pop();
16144 } else if (circle) {
16145 removeBeach(circle.arc);
16146 } else {
16147 break;
16148 }
16149 }
16150
16151 sortCellHalfedges();
16152
16153 if (extent) {
16154 var x0 = +extent[0][0],
16155 y0 = +extent[0][1],
16156 x1 = +extent[1][0],
16157 y1 = +extent[1][1];
16158 clipEdges(x0, y0, x1, y1);
16159 clipCells(x0, y0, x1, y1);
16160 }
16161
16162 this.edges = edges;
16163 this.cells = cells;
16164
16165 beaches =
16166 circles =
16167 edges =
16168 cells = null;
16169 }
16170
16171 Diagram.prototype = {
16172 constructor: Diagram,
16173
16174 polygons: function() {
16175 var edges = this.edges;
16176
16177 return this.cells.map(function(cell) {
16178 var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
16179 polygon.data = cell.site.data;
16180 return polygon;
16181 });
16182 },
16183
16184 triangles: function() {
16185 var triangles = [],
16186 edges = this.edges;
16187
16188 this.cells.forEach(function(cell, i) {
16189 if (!(m = (halfedges = cell.halfedges).length)) return;
16190 var site = cell.site,
16191 halfedges,
16192 j = -1,
16193 m,
16194 s0,
16195 e1 = edges[halfedges[m - 1]],
16196 s1 = e1.left === site ? e1.right : e1.left;
16197
16198 while (++j < m) {
16199 s0 = s1;
16200 e1 = edges[halfedges[j]];
16201 s1 = e1.left === site ? e1.right : e1.left;
16202 if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
16203 triangles.push([site.data, s0.data, s1.data]);
16204 }
16205 }
16206 });
16207
16208 return triangles;
16209 },
16210
16211 links: function() {
16212 return this.edges.filter(function(edge) {
16213 return edge.right;
16214 }).map(function(edge) {
16215 return {
16216 source: edge.left.data,
16217 target: edge.right.data
16218 };
16219 });
16220 },
16221
16222 find: function(x, y, radius) {
16223 var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
16224
16225 // Use the previously-found cell, or start with an arbitrary one.
16226 while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
16227 var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
16228
16229 // Traverse the half-edges to find a closer cell, if any.
16230 do {
16231 cell = that.cells[i0 = i1], i1 = null;
16232 cell.halfedges.forEach(function(e) {
16233 var edge = that.edges[e], v = edge.left;
16234 if ((v === cell.site || !v) && !(v = edge.right)) return;
16235 var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
16236 if (v2 < d2) d2 = v2, i1 = v.index;
16237 });
16238 } while (i1 !== null);
16239
16240 that._found = i0;
16241
16242 return radius == null || d2 <= radius * radius ? cell.site : null;
16243 }
16244 };
16245
16246 function voronoi() {
16247 var x$$1 = x$4,
16248 y$$1 = y$4,
16249 extent = null;
16250
16251 function voronoi(data) {
16252 return new Diagram(data.map(function(d, i) {
16253 var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
16254 s.index = i;
16255 s.data = d;
16256 return s;
16257 }), extent);
16258 }
16259
16260 voronoi.polygons = function(data) {
16261 return voronoi(data).polygons();
16262 };
16263
16264 voronoi.links = function(data) {
16265 return voronoi(data).links();
16266 };
16267
16268 voronoi.triangles = function(data) {
16269 return voronoi(data).triangles();
16270 };
16271
16272 voronoi.x = function(_) {
16273 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : x$$1;
16274 };
16275
16276 voronoi.y = function(_) {
16277 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : y$$1;
16278 };
16279
16280 voronoi.extent = function(_) {
16281 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]]];
16282 };
16283
16284 voronoi.size = function(_) {
16285 return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
16286 };
16287
16288 return voronoi;
16289 }
16290
16291 function constant$12(x) {
16292 return function() {
16293 return x;
16294 };
16295 }
16296
16297 function ZoomEvent(target, type, transform) {
16298 this.target = target;
16299 this.type = type;
16300 this.transform = transform;
16301 }
16302
16303 function Transform(k, x, y) {
16304 this.k = k;
16305 this.x = x;
16306 this.y = y;
16307 }
16308
16309 Transform.prototype = {
16310 constructor: Transform,
16311 scale: function(k) {
16312 return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
16313 },
16314 translate: function(x, y) {
16315 return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
16316 },
16317 apply: function(point) {
16318 return [point[0] * this.k + this.x, point[1] * this.k + this.y];
16319 },
16320 applyX: function(x) {
16321 return x * this.k + this.x;
16322 },
16323 applyY: function(y) {
16324 return y * this.k + this.y;
16325 },
16326 invert: function(location) {
16327 return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
16328 },
16329 invertX: function(x) {
16330 return (x - this.x) / this.k;
16331 },
16332 invertY: function(y) {
16333 return (y - this.y) / this.k;
16334 },
16335 rescaleX: function(x) {
16336 return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
16337 },
16338 rescaleY: function(y) {
16339 return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
16340 },
16341 toString: function() {
16342 return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
16343 }
16344 };
16345
16346 var identity$8 = new Transform(1, 0, 0);
16347
16348 transform$1.prototype = Transform.prototype;
16349
16350 function transform$1(node) {
16351 return node.__zoom || identity$8;
16352 }
16353
16354 function nopropagation$2() {
16355 exports.event.stopImmediatePropagation();
16356 }
16357
16358 function noevent$2() {
16359 exports.event.preventDefault();
16360 exports.event.stopImmediatePropagation();
16361 }
16362
16363 // Ignore right-click, since that should open the context menu.
16364 function defaultFilter$2() {
16365 return !exports.event.button;
16366 }
16367
16368 function defaultExtent$1() {
16369 var e = this, w, h;
16370 if (e instanceof SVGElement) {
16371 e = e.ownerSVGElement || e;
16372 w = e.width.baseVal.value;
16373 h = e.height.baseVal.value;
16374 } else {
16375 w = e.clientWidth;
16376 h = e.clientHeight;
16377 }
16378 return [[0, 0], [w, h]];
16379 }
16380
16381 function defaultTransform() {
16382 return this.__zoom || identity$8;
16383 }
16384
16385 function defaultWheelDelta() {
16386 return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
16387 }
16388
16389 function defaultTouchable$1() {
16390 return "ontouchstart" in this;
16391 }
16392
16393 function defaultConstrain(transform$$1, extent, translateExtent) {
16394 var dx0 = transform$$1.invertX(extent[0][0]) - translateExtent[0][0],
16395 dx1 = transform$$1.invertX(extent[1][0]) - translateExtent[1][0],
16396 dy0 = transform$$1.invertY(extent[0][1]) - translateExtent[0][1],
16397 dy1 = transform$$1.invertY(extent[1][1]) - translateExtent[1][1];
16398 return transform$$1.translate(
16399 dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
16400 dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
16401 );
16402 }
16403
16404 function zoom() {
16405 var filter = defaultFilter$2,
16406 extent = defaultExtent$1,
16407 constrain = defaultConstrain,
16408 wheelDelta = defaultWheelDelta,
16409 touchable = defaultTouchable$1,
16410 scaleExtent = [0, Infinity],
16411 translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
16412 duration = 250,
16413 interpolate = interpolateZoom,
16414 gestures = [],
16415 listeners = dispatch("start", "zoom", "end"),
16416 touchstarting,
16417 touchending,
16418 touchDelay = 500,
16419 wheelDelay = 150,
16420 clickDistance2 = 0;
16421
16422 function zoom(selection) {
16423 selection
16424 .property("__zoom", defaultTransform)
16425 .on("wheel.zoom", wheeled)
16426 .on("mousedown.zoom", mousedowned)
16427 .on("dblclick.zoom", dblclicked)
16428 .filter(touchable)
16429 .on("touchstart.zoom", touchstarted)
16430 .on("touchmove.zoom", touchmoved)
16431 .on("touchend.zoom touchcancel.zoom", touchended)
16432 .style("touch-action", "none")
16433 .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
16434 }
16435
16436 zoom.transform = function(collection, transform$$1) {
16437 var selection = collection.selection ? collection.selection() : collection;
16438 selection.property("__zoom", defaultTransform);
16439 if (collection !== selection) {
16440 schedule(collection, transform$$1);
16441 } else {
16442 selection.interrupt().each(function() {
16443 gesture(this, arguments)
16444 .start()
16445 .zoom(null, typeof transform$$1 === "function" ? transform$$1.apply(this, arguments) : transform$$1)
16446 .end();
16447 });
16448 }
16449 };
16450
16451 zoom.scaleBy = function(selection, k) {
16452 zoom.scaleTo(selection, function() {
16453 var k0 = this.__zoom.k,
16454 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
16455 return k0 * k1;
16456 });
16457 };
16458
16459 zoom.scaleTo = function(selection, k) {
16460 zoom.transform(selection, function() {
16461 var e = extent.apply(this, arguments),
16462 t0 = this.__zoom,
16463 p0 = centroid(e),
16464 p1 = t0.invert(p0),
16465 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
16466 return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
16467 });
16468 };
16469
16470 zoom.translateBy = function(selection, x, y) {
16471 zoom.transform(selection, function() {
16472 return constrain(this.__zoom.translate(
16473 typeof x === "function" ? x.apply(this, arguments) : x,
16474 typeof y === "function" ? y.apply(this, arguments) : y
16475 ), extent.apply(this, arguments), translateExtent);
16476 });
16477 };
16478
16479 zoom.translateTo = function(selection, x, y) {
16480 zoom.transform(selection, function() {
16481 var e = extent.apply(this, arguments),
16482 t = this.__zoom,
16483 p = centroid(e);
16484 return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
16485 typeof x === "function" ? -x.apply(this, arguments) : -x,
16486 typeof y === "function" ? -y.apply(this, arguments) : -y
16487 ), e, translateExtent);
16488 });
16489 };
16490
16491 function scale(transform$$1, k) {
16492 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
16493 return k === transform$$1.k ? transform$$1 : new Transform(k, transform$$1.x, transform$$1.y);
16494 }
16495
16496 function translate(transform$$1, p0, p1) {
16497 var x = p0[0] - p1[0] * transform$$1.k, y = p0[1] - p1[1] * transform$$1.k;
16498 return x === transform$$1.x && y === transform$$1.y ? transform$$1 : new Transform(transform$$1.k, x, y);
16499 }
16500
16501 function centroid(extent) {
16502 return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
16503 }
16504
16505 function schedule(transition, transform$$1, center) {
16506 transition
16507 .on("start.zoom", function() { gesture(this, arguments).start(); })
16508 .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
16509 .tween("zoom", function() {
16510 var that = this,
16511 args = arguments,
16512 g = gesture(that, args),
16513 e = extent.apply(that, args),
16514 p = center || centroid(e),
16515 w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
16516 a = that.__zoom,
16517 b = typeof transform$$1 === "function" ? transform$$1.apply(that, args) : transform$$1,
16518 i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
16519 return function(t) {
16520 if (t === 1) t = b; // Avoid rounding error on end.
16521 else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
16522 g.zoom(null, t);
16523 };
16524 });
16525 }
16526
16527 function gesture(that, args) {
16528 for (var i = 0, n = gestures.length, g; i < n; ++i) {
16529 if ((g = gestures[i]).that === that) {
16530 return g;
16531 }
16532 }
16533 return new Gesture(that, args);
16534 }
16535
16536 function Gesture(that, args) {
16537 this.that = that;
16538 this.args = args;
16539 this.index = -1;
16540 this.active = 0;
16541 this.extent = extent.apply(that, args);
16542 }
16543
16544 Gesture.prototype = {
16545 start: function() {
16546 if (++this.active === 1) {
16547 this.index = gestures.push(this) - 1;
16548 this.emit("start");
16549 }
16550 return this;
16551 },
16552 zoom: function(key, transform$$1) {
16553 if (this.mouse && key !== "mouse") this.mouse[1] = transform$$1.invert(this.mouse[0]);
16554 if (this.touch0 && key !== "touch") this.touch0[1] = transform$$1.invert(this.touch0[0]);
16555 if (this.touch1 && key !== "touch") this.touch1[1] = transform$$1.invert(this.touch1[0]);
16556 this.that.__zoom = transform$$1;
16557 this.emit("zoom");
16558 return this;
16559 },
16560 end: function() {
16561 if (--this.active === 0) {
16562 gestures.splice(this.index, 1);
16563 this.index = -1;
16564 this.emit("end");
16565 }
16566 return this;
16567 },
16568 emit: function(type) {
16569 customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
16570 }
16571 };
16572
16573 function wheeled() {
16574 if (!filter.apply(this, arguments)) return;
16575 var g = gesture(this, arguments),
16576 t = this.__zoom,
16577 k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
16578 p = mouse(this);
16579
16580 // If the mouse is in the same location as before, reuse it.
16581 // If there were recent wheel events, reset the wheel idle timeout.
16582 if (g.wheel) {
16583 if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
16584 g.mouse[1] = t.invert(g.mouse[0] = p);
16585 }
16586 clearTimeout(g.wheel);
16587 }
16588
16589 // If this wheel event won’t trigger a transform change, ignore it.
16590 else if (t.k === k) return;
16591
16592 // Otherwise, capture the mouse point and location at the start.
16593 else {
16594 g.mouse = [p, t.invert(p)];
16595 interrupt(this);
16596 g.start();
16597 }
16598
16599 noevent$2();
16600 g.wheel = setTimeout(wheelidled, wheelDelay);
16601 g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
16602
16603 function wheelidled() {
16604 g.wheel = null;
16605 g.end();
16606 }
16607 }
16608
16609 function mousedowned() {
16610 if (touchending || !filter.apply(this, arguments)) return;
16611 var g = gesture(this, arguments),
16612 v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
16613 p = mouse(this),
16614 x0 = exports.event.clientX,
16615 y0 = exports.event.clientY;
16616
16617 dragDisable(exports.event.view);
16618 nopropagation$2();
16619 g.mouse = [p, this.__zoom.invert(p)];
16620 interrupt(this);
16621 g.start();
16622
16623 function mousemoved() {
16624 noevent$2();
16625 if (!g.moved) {
16626 var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
16627 g.moved = dx * dx + dy * dy > clickDistance2;
16628 }
16629 g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
16630 }
16631
16632 function mouseupped() {
16633 v.on("mousemove.zoom mouseup.zoom", null);
16634 yesdrag(exports.event.view, g.moved);
16635 noevent$2();
16636 g.end();
16637 }
16638 }
16639
16640 function dblclicked() {
16641 if (!filter.apply(this, arguments)) return;
16642 var t0 = this.__zoom,
16643 p0 = mouse(this),
16644 p1 = t0.invert(p0),
16645 k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
16646 t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
16647
16648 noevent$2();
16649 if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
16650 else select(this).call(zoom.transform, t1);
16651 }
16652
16653 function touchstarted() {
16654 if (!filter.apply(this, arguments)) return;
16655 var g = gesture(this, arguments),
16656 touches = exports.event.changedTouches,
16657 started,
16658 n = touches.length, i, t, p;
16659
16660 nopropagation$2();
16661 for (i = 0; i < n; ++i) {
16662 t = touches[i], p = touch(this, touches, t.identifier);
16663 p = [p, this.__zoom.invert(p), t.identifier];
16664 if (!g.touch0) g.touch0 = p, started = true;
16665 else if (!g.touch1) g.touch1 = p;
16666 }
16667
16668 // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
16669 if (touchstarting) {
16670 touchstarting = clearTimeout(touchstarting);
16671 if (!g.touch1) {
16672 g.end();
16673 p = select(this).on("dblclick.zoom");
16674 if (p) p.apply(this, arguments);
16675 return;
16676 }
16677 }
16678
16679 if (started) {
16680 touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
16681 interrupt(this);
16682 g.start();
16683 }
16684 }
16685
16686 function touchmoved() {
16687 var g = gesture(this, arguments),
16688 touches = exports.event.changedTouches,
16689 n = touches.length, i, t, p, l;
16690
16691 noevent$2();
16692 if (touchstarting) touchstarting = clearTimeout(touchstarting);
16693 for (i = 0; i < n; ++i) {
16694 t = touches[i], p = touch(this, touches, t.identifier);
16695 if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
16696 else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
16697 }
16698 t = g.that.__zoom;
16699 if (g.touch1) {
16700 var p0 = g.touch0[0], l0 = g.touch0[1],
16701 p1 = g.touch1[0], l1 = g.touch1[1],
16702 dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
16703 dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
16704 t = scale(t, Math.sqrt(dp / dl));
16705 p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
16706 l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
16707 }
16708 else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
16709 else return;
16710 g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
16711 }
16712
16713 function touchended() {
16714 var g = gesture(this, arguments),
16715 touches = exports.event.changedTouches,
16716 n = touches.length, i, t;
16717
16718 nopropagation$2();
16719 if (touchending) clearTimeout(touchending);
16720 touchending = setTimeout(function() { touchending = null; }, touchDelay);
16721 for (i = 0; i < n; ++i) {
16722 t = touches[i];
16723 if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
16724 else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
16725 }
16726 if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
16727 if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
16728 else g.end();
16729 }
16730
16731 zoom.wheelDelta = function(_) {
16732 return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$12(+_), zoom) : wheelDelta;
16733 };
16734
16735 zoom.filter = function(_) {
16736 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$12(!!_), zoom) : filter;
16737 };
16738
16739 zoom.touchable = function(_) {
16740 return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$12(!!_), zoom) : touchable;
16741 };
16742
16743 zoom.extent = function(_) {
16744 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$12([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
16745 };
16746
16747 zoom.scaleExtent = function(_) {
16748 return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
16749 };
16750
16751 zoom.translateExtent = function(_) {
16752 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]]];
16753 };
16754
16755 zoom.constrain = function(_) {
16756 return arguments.length ? (constrain = _, zoom) : constrain;
16757 };
16758
16759 zoom.duration = function(_) {
16760 return arguments.length ? (duration = +_, zoom) : duration;
16761 };
16762
16763 zoom.interpolate = function(_) {
16764 return arguments.length ? (interpolate = _, zoom) : interpolate;
16765 };
16766
16767 zoom.on = function() {
16768 var value = listeners.on.apply(listeners, arguments);
16769 return value === listeners ? zoom : value;
16770 };
16771
16772 zoom.clickDistance = function(_) {
16773 return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
16774 };
16775
16776 return zoom;
16777 }
16778
16779 exports.version = version;
16780 exports.bisect = bisectRight;
16781 exports.bisectRight = bisectRight;
16782 exports.bisectLeft = bisectLeft;
16783 exports.ascending = ascending;
16784 exports.bisector = bisector;
16785 exports.cross = cross;
16786 exports.descending = descending;
16787 exports.deviation = deviation;
16788 exports.extent = extent;
16789 exports.histogram = histogram;
16790 exports.thresholdFreedmanDiaconis = freedmanDiaconis;
16791 exports.thresholdScott = scott;
16792 exports.thresholdSturges = sturges;
16793 exports.max = max;
16794 exports.mean = mean;
16795 exports.median = median;
16796 exports.merge = merge;
16797 exports.min = min;
16798 exports.pairs = pairs;
16799 exports.permute = permute;
16800 exports.quantile = threshold;
16801 exports.range = sequence;
16802 exports.scan = scan;
16803 exports.shuffle = shuffle;
16804 exports.sum = sum;
16805 exports.ticks = ticks;
16806 exports.tickIncrement = tickIncrement;
16807 exports.tickStep = tickStep;
16808 exports.transpose = transpose;
16809 exports.variance = variance;
16810 exports.zip = zip;
16811 exports.axisTop = axisTop;
16812 exports.axisRight = axisRight;
16813 exports.axisBottom = axisBottom;
16814 exports.axisLeft = axisLeft;
16815 exports.brush = brush;
16816 exports.brushX = brushX;
16817 exports.brushY = brushY;
16818 exports.brushSelection = brushSelection;
16819 exports.chord = chord;
16820 exports.ribbon = ribbon;
16821 exports.nest = nest;
16822 exports.set = set$2;
16823 exports.map = map$1;
16824 exports.keys = keys;
16825 exports.values = values;
16826 exports.entries = entries;
16827 exports.color = color;
16828 exports.rgb = rgb;
16829 exports.hsl = hsl;
16830 exports.lab = lab;
16831 exports.hcl = hcl;
16832 exports.cubehelix = cubehelix;
16833 exports.dispatch = dispatch;
16834 exports.drag = drag;
16835 exports.dragDisable = dragDisable;
16836 exports.dragEnable = yesdrag;
16837 exports.dsvFormat = dsv;
16838 exports.csvParse = csvParse;
16839 exports.csvParseRows = csvParseRows;
16840 exports.csvFormat = csvFormat;
16841 exports.csvFormatRows = csvFormatRows;
16842 exports.tsvParse = tsvParse;
16843 exports.tsvParseRows = tsvParseRows;
16844 exports.tsvFormat = tsvFormat;
16845 exports.tsvFormatRows = tsvFormatRows;
16846 exports.easeLinear = linear$1;
16847 exports.easeQuad = quadInOut;
16848 exports.easeQuadIn = quadIn;
16849 exports.easeQuadOut = quadOut;
16850 exports.easeQuadInOut = quadInOut;
16851 exports.easeCubic = cubicInOut;
16852 exports.easeCubicIn = cubicIn;
16853 exports.easeCubicOut = cubicOut;
16854 exports.easeCubicInOut = cubicInOut;
16855 exports.easePoly = polyInOut;
16856 exports.easePolyIn = polyIn;
16857 exports.easePolyOut = polyOut;
16858 exports.easePolyInOut = polyInOut;
16859 exports.easeSin = sinInOut;
16860 exports.easeSinIn = sinIn;
16861 exports.easeSinOut = sinOut;
16862 exports.easeSinInOut = sinInOut;
16863 exports.easeExp = expInOut;
16864 exports.easeExpIn = expIn;
16865 exports.easeExpOut = expOut;
16866 exports.easeExpInOut = expInOut;
16867 exports.easeCircle = circleInOut;
16868 exports.easeCircleIn = circleIn;
16869 exports.easeCircleOut = circleOut;
16870 exports.easeCircleInOut = circleInOut;
16871 exports.easeBounce = bounceOut;
16872 exports.easeBounceIn = bounceIn;
16873 exports.easeBounceOut = bounceOut;
16874 exports.easeBounceInOut = bounceInOut;
16875 exports.easeBack = backInOut;
16876 exports.easeBackIn = backIn;
16877 exports.easeBackOut = backOut;
16878 exports.easeBackInOut = backInOut;
16879 exports.easeElastic = elasticOut;
16880 exports.easeElasticIn = elasticIn;
16881 exports.easeElasticOut = elasticOut;
16882 exports.easeElasticInOut = elasticInOut;
16883 exports.forceCenter = center$1;
16884 exports.forceCollide = collide;
16885 exports.forceLink = link;
16886 exports.forceManyBody = manyBody;
16887 exports.forceRadial = radial;
16888 exports.forceSimulation = simulation;
16889 exports.forceX = x$2;
16890 exports.forceY = y$2;
16891 exports.formatDefaultLocale = defaultLocale;
16892 exports.formatLocale = formatLocale;
16893 exports.formatSpecifier = formatSpecifier;
16894 exports.precisionFixed = precisionFixed;
16895 exports.precisionPrefix = precisionPrefix;
16896 exports.precisionRound = precisionRound;
16897 exports.geoArea = area;
16898 exports.geoBounds = bounds;
16899 exports.geoCentroid = centroid;
16900 exports.geoCircle = circle;
16901 exports.geoClipAntimeridian = clipAntimeridian;
16902 exports.geoClipCircle = clipCircle;
16903 exports.geoClipExtent = extent$1;
16904 exports.geoClipRectangle = clipRectangle;
16905 exports.geoContains = contains;
16906 exports.geoDistance = distance;
16907 exports.geoGraticule = graticule;
16908 exports.geoGraticule10 = graticule10;
16909 exports.geoInterpolate = interpolate$1;
16910 exports.geoLength = length$1;
16911 exports.geoPath = index$1;
16912 exports.geoAlbers = albers;
16913 exports.geoAlbersUsa = albersUsa;
16914 exports.geoAzimuthalEqualArea = azimuthalEqualArea;
16915 exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
16916 exports.geoAzimuthalEquidistant = azimuthalEquidistant;
16917 exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
16918 exports.geoConicConformal = conicConformal;
16919 exports.geoConicConformalRaw = conicConformalRaw;
16920 exports.geoConicEqualArea = conicEqualArea;
16921 exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
16922 exports.geoConicEquidistant = conicEquidistant;
16923 exports.geoConicEquidistantRaw = conicEquidistantRaw;
16924 exports.geoEquirectangular = equirectangular;
16925 exports.geoEquirectangularRaw = equirectangularRaw;
16926 exports.geoGnomonic = gnomonic;
16927 exports.geoGnomonicRaw = gnomonicRaw;
16928 exports.geoIdentity = identity$5;
16929 exports.geoProjection = projection;
16930 exports.geoProjectionMutator = projectionMutator;
16931 exports.geoMercator = mercator;
16932 exports.geoMercatorRaw = mercatorRaw;
16933 exports.geoNaturalEarth1 = naturalEarth1;
16934 exports.geoNaturalEarth1Raw = naturalEarth1Raw;
16935 exports.geoOrthographic = orthographic;
16936 exports.geoOrthographicRaw = orthographicRaw;
16937 exports.geoStereographic = stereographic;
16938 exports.geoStereographicRaw = stereographicRaw;
16939 exports.geoTransverseMercator = transverseMercator;
16940 exports.geoTransverseMercatorRaw = transverseMercatorRaw;
16941 exports.geoRotation = rotation;
16942 exports.geoStream = geoStream;
16943 exports.geoTransform = transform;
16944 exports.cluster = cluster;
16945 exports.hierarchy = hierarchy;
16946 exports.pack = index$2;
16947 exports.packSiblings = siblings;
16948 exports.packEnclose = enclose;
16949 exports.partition = partition;
16950 exports.stratify = stratify;
16951 exports.tree = tree;
16952 exports.treemap = index$3;
16953 exports.treemapBinary = binary;
16954 exports.treemapDice = treemapDice;
16955 exports.treemapSlice = treemapSlice;
16956 exports.treemapSliceDice = sliceDice;
16957 exports.treemapSquarify = squarify;
16958 exports.treemapResquarify = resquarify;
16959 exports.interpolate = interpolateValue;
16960 exports.interpolateArray = array$1;
16961 exports.interpolateBasis = basis$1;
16962 exports.interpolateBasisClosed = basisClosed;
16963 exports.interpolateDate = date;
16964 exports.interpolateNumber = reinterpolate;
16965 exports.interpolateObject = object;
16966 exports.interpolateRound = interpolateRound;
16967 exports.interpolateString = interpolateString;
16968 exports.interpolateTransformCss = interpolateTransformCss;
16969 exports.interpolateTransformSvg = interpolateTransformSvg;
16970 exports.interpolateZoom = interpolateZoom;
16971 exports.interpolateRgb = interpolateRgb;
16972 exports.interpolateRgbBasis = rgbBasis;
16973 exports.interpolateRgbBasisClosed = rgbBasisClosed;
16974 exports.interpolateHsl = hsl$2;
16975 exports.interpolateHslLong = hslLong;
16976 exports.interpolateLab = lab$1;
16977 exports.interpolateHcl = hcl$2;
16978 exports.interpolateHclLong = hclLong;
16979 exports.interpolateCubehelix = cubehelix$2;
16980 exports.interpolateCubehelixLong = cubehelixLong;
16981 exports.quantize = quantize;
16982 exports.path = path;
16983 exports.polygonArea = area$1;
16984 exports.polygonCentroid = centroid$1;
16985 exports.polygonHull = hull;
16986 exports.polygonContains = contains$1;
16987 exports.polygonLength = length$2;
16988 exports.quadtree = quadtree;
16989 exports.queue = queue;
16990 exports.randomUniform = uniform;
16991 exports.randomNormal = normal;
16992 exports.randomLogNormal = logNormal;
16993 exports.randomBates = bates;
16994 exports.randomIrwinHall = irwinHall;
16995 exports.randomExponential = exponential$1;
16996 exports.request = request;
16997 exports.html = html;
16998 exports.json = json;
16999 exports.text = text;
17000 exports.xml = xml;
17001 exports.csv = csv$1;
17002 exports.tsv = tsv$1;
17003 exports.scaleBand = band;
17004 exports.scalePoint = point$1;
17005 exports.scaleIdentity = identity$6;
17006 exports.scaleLinear = linear$2;
17007 exports.scaleLog = log$1;
17008 exports.scaleOrdinal = ordinal;
17009 exports.scaleImplicit = implicit;
17010 exports.scalePow = pow$1;
17011 exports.scaleSqrt = sqrt$1;
17012 exports.scaleQuantile = quantile$$1;
17013 exports.scaleQuantize = quantize$1;
17014 exports.scaleThreshold = threshold$1;
17015 exports.scaleTime = time;
17016 exports.scaleUtc = utcTime;
17017 exports.schemeCategory10 = category10;
17018 exports.schemeCategory20b = category20b;
17019 exports.schemeCategory20c = category20c;
17020 exports.schemeCategory20 = category20;
17021 exports.interpolateCubehelixDefault = cubehelix$3;
17022 exports.interpolateRainbow = rainbow$1;
17023 exports.interpolateWarm = warm;
17024 exports.interpolateCool = cool;
17025 exports.interpolateViridis = viridis;
17026 exports.interpolateMagma = magma;
17027 exports.interpolateInferno = inferno;
17028 exports.interpolatePlasma = plasma;
17029 exports.scaleSequential = sequential;
17030 exports.create = create;
17031 exports.creator = creator;
17032 exports.local = local$1;
17033 exports.matcher = matcher$1;
17034 exports.mouse = mouse;
17035 exports.namespace = namespace;
17036 exports.namespaces = namespaces;
17037 exports.clientPoint = point;
17038 exports.select = select;
17039 exports.selectAll = selectAll;
17040 exports.selection = selection;
17041 exports.selector = selector;
17042 exports.selectorAll = selectorAll;
17043 exports.style = styleValue;
17044 exports.touch = touch;
17045 exports.touches = touches;
17046 exports.window = defaultView;
17047 exports.customEvent = customEvent;
17048 exports.arc = arc;
17049 exports.area = area$2;
17050 exports.line = line;
17051 exports.pie = pie;
17052 exports.areaRadial = areaRadial;
17053 exports.radialArea = areaRadial;
17054 exports.lineRadial = lineRadial$1;
17055 exports.radialLine = lineRadial$1;
17056 exports.pointRadial = pointRadial;
17057 exports.linkHorizontal = linkHorizontal;
17058 exports.linkVertical = linkVertical;
17059 exports.linkRadial = linkRadial;
17060 exports.symbol = symbol;
17061 exports.symbols = symbols;
17062 exports.symbolCircle = circle$2;
17063 exports.symbolCross = cross$2;
17064 exports.symbolDiamond = diamond;
17065 exports.symbolSquare = square;
17066 exports.symbolStar = star;
17067 exports.symbolTriangle = triangle;
17068 exports.symbolWye = wye;
17069 exports.curveBasisClosed = basisClosed$1;
17070 exports.curveBasisOpen = basisOpen;
17071 exports.curveBasis = basis$2;
17072 exports.curveBundle = bundle;
17073 exports.curveCardinalClosed = cardinalClosed;
17074 exports.curveCardinalOpen = cardinalOpen;
17075 exports.curveCardinal = cardinal;
17076 exports.curveCatmullRomClosed = catmullRomClosed;
17077 exports.curveCatmullRomOpen = catmullRomOpen;
17078 exports.curveCatmullRom = catmullRom;
17079 exports.curveLinearClosed = linearClosed;
17080 exports.curveLinear = curveLinear;
17081 exports.curveMonotoneX = monotoneX;
17082 exports.curveMonotoneY = monotoneY;
17083 exports.curveNatural = natural;
17084 exports.curveStep = step;
17085 exports.curveStepAfter = stepAfter;
17086 exports.curveStepBefore = stepBefore;
17087 exports.stack = stack;
17088 exports.stackOffsetExpand = expand;
17089 exports.stackOffsetDiverging = diverging;
17090 exports.stackOffsetNone = none$1;
17091 exports.stackOffsetSilhouette = silhouette;
17092 exports.stackOffsetWiggle = wiggle;
17093 exports.stackOrderAscending = ascending$2;
17094 exports.stackOrderDescending = descending$2;
17095 exports.stackOrderInsideOut = insideOut;
17096 exports.stackOrderNone = none$2;
17097 exports.stackOrderReverse = reverse;
17098 exports.timeInterval = newInterval;
17099 exports.timeMillisecond = millisecond;
17100 exports.timeMilliseconds = milliseconds;
17101 exports.utcMillisecond = millisecond;
17102 exports.utcMilliseconds = milliseconds;
17103 exports.timeSecond = second;
17104 exports.timeSeconds = seconds;
17105 exports.utcSecond = second;
17106 exports.utcSeconds = seconds;
17107 exports.timeMinute = minute;
17108 exports.timeMinutes = minutes;
17109 exports.timeHour = hour;
17110 exports.timeHours = hours;
17111 exports.timeDay = day;
17112 exports.timeDays = days;
17113 exports.timeWeek = sunday;
17114 exports.timeWeeks = sundays;
17115 exports.timeSunday = sunday;
17116 exports.timeSundays = sundays;
17117 exports.timeMonday = monday;
17118 exports.timeMondays = mondays;
17119 exports.timeTuesday = tuesday;
17120 exports.timeTuesdays = tuesdays;
17121 exports.timeWednesday = wednesday;
17122 exports.timeWednesdays = wednesdays;
17123 exports.timeThursday = thursday;
17124 exports.timeThursdays = thursdays;
17125 exports.timeFriday = friday;
17126 exports.timeFridays = fridays;
17127 exports.timeSaturday = saturday;
17128 exports.timeSaturdays = saturdays;
17129 exports.timeMonth = month;
17130 exports.timeMonths = months;
17131 exports.timeYear = year;
17132 exports.timeYears = years;
17133 exports.utcMinute = utcMinute;
17134 exports.utcMinutes = utcMinutes;
17135 exports.utcHour = utcHour;
17136 exports.utcHours = utcHours;
17137 exports.utcDay = utcDay;
17138 exports.utcDays = utcDays;
17139 exports.utcWeek = utcSunday;
17140 exports.utcWeeks = utcSundays;
17141 exports.utcSunday = utcSunday;
17142 exports.utcSundays = utcSundays;
17143 exports.utcMonday = utcMonday;
17144 exports.utcMondays = utcMondays;
17145 exports.utcTuesday = utcTuesday;
17146 exports.utcTuesdays = utcTuesdays;
17147 exports.utcWednesday = utcWednesday;
17148 exports.utcWednesdays = utcWednesdays;
17149 exports.utcThursday = utcThursday;
17150 exports.utcThursdays = utcThursdays;
17151 exports.utcFriday = utcFriday;
17152 exports.utcFridays = utcFridays;
17153 exports.utcSaturday = utcSaturday;
17154 exports.utcSaturdays = utcSaturdays;
17155 exports.utcMonth = utcMonth;
17156 exports.utcMonths = utcMonths;
17157 exports.utcYear = utcYear;
17158 exports.utcYears = utcYears;
17159 exports.timeFormatDefaultLocale = defaultLocale$1;
17160 exports.timeFormatLocale = formatLocale$1;
17161 exports.isoFormat = formatIso;
17162 exports.isoParse = parseIso;
17163 exports.now = now;
17164 exports.timer = timer;
17165 exports.timerFlush = timerFlush;
17166 exports.timeout = timeout$1;
17167 exports.interval = interval$1;
17168 exports.transition = transition;
17169 exports.active = active;
17170 exports.interrupt = interrupt;
17171 exports.voronoi = voronoi;
17172 exports.zoom = zoom;
17173 exports.zoomTransform = transform$1;
17174 exports.zoomIdentity = identity$8;
17175
17176 Object.defineProperty(exports, '__esModule', { value: true });
17177
17178 })));
17179