]> ToastFreeware Gitweb - chrisu/seepark.git/blob - web/static/d3.js
deduplicate reloading; we already had an unused function for that
[chrisu/seepark.git] / web / static / d3.js
1 // https://d3js.org Version 5.5.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 = "5.5.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     e5 = Math.sqrt(10),
195     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 thresholdSturges(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 = thresholdSturges;
253
254   function histogram(data) {
255     var i,
256         n = data.length,
257         x,
258         values = new Array(n);
259
260     for (i = 0; i < n; ++i) {
261       values[i] = value(data[i], i, data);
262     }
263
264     var xz = domain(values),
265         x0 = xz[0],
266         x1 = xz[1],
267         tz = threshold(values, x0, x1);
268
269     // Convert number of thresholds into uniform thresholds.
270     if (!Array.isArray(tz)) {
271       tz = tickStep(x0, x1, tz);
272       tz = sequence(Math.ceil(x0 / tz) * tz, 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     right = 2,
566     bottom = 3,
567     left = 4,
568     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() {
882   return [];
883 }
884
885 function selectorAll(selector) {
886   return selector == null ? empty : 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() {
1706   return new Local;
1707 }
1708
1709 function Local() {
1710   this._ = "@" + (++nextId).toString(36);
1711 }
1712
1713 Local.prototype = local.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$$1 = select(view).on("dragstart.drag", noevent, true);
1797   if ("onselectstart" in root) {
1798     selection$$1.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$$1 = select(view).on("dragstart.drag", null);
1808   if (noclick) {
1809     selection$$1.on("click.drag", noevent, true);
1810     setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
1811   }
1812   if ("onselectstart" in root) {
1813     selection$$1.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() {
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,
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$$1) {
1876     selection$$1
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$$1 = exports.event.changedTouches,
1918         c = container.apply(this, arguments),
1919         n = touches$$1.length, i, gesture;
1920
1921     for (i = 0; i < n; ++i) {
1922       if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
1923         nopropagation();
1924         gesture("start");
1925       }
1926     }
1927   }
1928
1929   function touchmoved() {
1930     var touches$$1 = exports.event.changedTouches,
1931         n = touches$$1.length, i, gesture;
1932
1933     for (i = 0; i < n; ++i) {
1934       if (gesture = gestures[touches$$1[i].identifier]) {
1935         noevent();
1936         gesture("drag");
1937       }
1938     }
1939   }
1940
1941   function touchended() {
1942     var touches$$1 = exports.event.changedTouches,
1943         n = touches$$1.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$$1[i].identifier]) {
1949         nopropagation();
1950         gesture("end");
1951       }
1952     }
1953   }
1954
1955   function beforestart(id, container, point$$1, that, args) {
1956     var p = point$$1(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$$1(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     reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
2023     reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
2024     reHex3 = /^#([0-9a-f]{3})$/,
2025     reHex6 = /^#([0-9a-f]{6})$/,
2026     reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
2027     reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
2028     reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
2029     reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
2030     reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
2031     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   hex: function() {
2189     return this.rgb().hex();
2190   },
2191   toString: function() {
2192     return this.rgb() + "";
2193   }
2194 });
2195
2196 function color(format) {
2197   var m;
2198   format = (format + "").trim().toLowerCase();
2199   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
2200       : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
2201       : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
2202       : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
2203       : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
2204       : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
2205       : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
2206       : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
2207       : named.hasOwnProperty(format) ? rgbn(named[format])
2208       : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
2209       : null;
2210 }
2211
2212 function rgbn(n) {
2213   return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
2214 }
2215
2216 function rgba(r, g, b, a) {
2217   if (a <= 0) r = g = b = NaN;
2218   return new Rgb(r, g, b, a);
2219 }
2220
2221 function rgbConvert(o) {
2222   if (!(o instanceof Color)) o = color(o);
2223   if (!o) return new Rgb;
2224   o = o.rgb();
2225   return new Rgb(o.r, o.g, o.b, o.opacity);
2226 }
2227
2228 function rgb(r, g, b, opacity) {
2229   return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
2230 }
2231
2232 function Rgb(r, g, b, opacity) {
2233   this.r = +r;
2234   this.g = +g;
2235   this.b = +b;
2236   this.opacity = +opacity;
2237 }
2238
2239 define(Rgb, rgb, extend(Color, {
2240   brighter: function(k) {
2241     k = k == null ? brighter : Math.pow(brighter, k);
2242     return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2243   },
2244   darker: function(k) {
2245     k = k == null ? darker : Math.pow(darker, k);
2246     return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2247   },
2248   rgb: function() {
2249     return this;
2250   },
2251   displayable: function() {
2252     return (0 <= this.r && this.r <= 255)
2253         && (0 <= this.g && this.g <= 255)
2254         && (0 <= this.b && this.b <= 255)
2255         && (0 <= this.opacity && this.opacity <= 1);
2256   },
2257   hex: function() {
2258     return "#" + hex(this.r) + hex(this.g) + hex(this.b);
2259   },
2260   toString: function() {
2261     var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2262     return (a === 1 ? "rgb(" : "rgba(")
2263         + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
2264         + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
2265         + Math.max(0, Math.min(255, Math.round(this.b) || 0))
2266         + (a === 1 ? ")" : ", " + a + ")");
2267   }
2268 }));
2269
2270 function hex(value) {
2271   value = Math.max(0, Math.min(255, Math.round(value) || 0));
2272   return (value < 16 ? "0" : "") + value.toString(16);
2273 }
2274
2275 function hsla(h, s, l, a) {
2276   if (a <= 0) h = s = l = NaN;
2277   else if (l <= 0 || l >= 1) h = s = NaN;
2278   else if (s <= 0) h = NaN;
2279   return new Hsl(h, s, l, a);
2280 }
2281
2282 function hslConvert(o) {
2283   if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2284   if (!(o instanceof Color)) o = color(o);
2285   if (!o) return new Hsl;
2286   if (o instanceof Hsl) return o;
2287   o = o.rgb();
2288   var r = o.r / 255,
2289       g = o.g / 255,
2290       b = o.b / 255,
2291       min = Math.min(r, g, b),
2292       max = Math.max(r, g, b),
2293       h = NaN,
2294       s = max - min,
2295       l = (max + min) / 2;
2296   if (s) {
2297     if (r === max) h = (g - b) / s + (g < b) * 6;
2298     else if (g === max) h = (b - r) / s + 2;
2299     else h = (r - g) / s + 4;
2300     s /= l < 0.5 ? max + min : 2 - max - min;
2301     h *= 60;
2302   } else {
2303     s = l > 0 && l < 1 ? 0 : h;
2304   }
2305   return new Hsl(h, s, l, o.opacity);
2306 }
2307
2308 function hsl(h, s, l, opacity) {
2309   return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2310 }
2311
2312 function Hsl(h, s, l, opacity) {
2313   this.h = +h;
2314   this.s = +s;
2315   this.l = +l;
2316   this.opacity = +opacity;
2317 }
2318
2319 define(Hsl, hsl, extend(Color, {
2320   brighter: function(k) {
2321     k = k == null ? brighter : Math.pow(brighter, k);
2322     return new Hsl(this.h, this.s, this.l * k, this.opacity);
2323   },
2324   darker: function(k) {
2325     k = k == null ? darker : Math.pow(darker, k);
2326     return new Hsl(this.h, this.s, this.l * k, this.opacity);
2327   },
2328   rgb: function() {
2329     var h = this.h % 360 + (this.h < 0) * 360,
2330         s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
2331         l = this.l,
2332         m2 = l + (l < 0.5 ? l : 1 - l) * s,
2333         m1 = 2 * l - m2;
2334     return new Rgb(
2335       hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
2336       hsl2rgb(h, m1, m2),
2337       hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
2338       this.opacity
2339     );
2340   },
2341   displayable: function() {
2342     return (0 <= this.s && this.s <= 1 || isNaN(this.s))
2343         && (0 <= this.l && this.l <= 1)
2344         && (0 <= this.opacity && this.opacity <= 1);
2345   }
2346 }));
2347
2348 /* From FvD 13.37, CSS Color Module Level 3 */
2349 function hsl2rgb(h, m1, m2) {
2350   return (h < 60 ? m1 + (m2 - m1) * h / 60
2351       : h < 180 ? m2
2352       : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
2353       : m1) * 255;
2354 }
2355
2356 var deg2rad = Math.PI / 180;
2357 var rad2deg = 180 / Math.PI;
2358
2359 // https://beta.observablehq.com/@mbostock/lab-and-rgb
2360 var K = 18,
2361     Xn = 0.96422,
2362     Yn = 1,
2363     Zn = 0.82521,
2364     t0 = 4 / 29,
2365     t1 = 6 / 29,
2366     t2 = 3 * t1 * t1,
2367     t3 = t1 * t1 * t1;
2368
2369 function labConvert(o) {
2370   if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
2371   if (o instanceof Hcl) {
2372     if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
2373     var h = o.h * deg2rad;
2374     return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
2375   }
2376   if (!(o instanceof Rgb)) o = rgbConvert(o);
2377   var r = rgb2lrgb(o.r),
2378       g = rgb2lrgb(o.g),
2379       b = rgb2lrgb(o.b),
2380       y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
2381   if (r === g && g === b) x = z = y; else {
2382     x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
2383     z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
2384   }
2385   return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
2386 }
2387
2388 function gray(l, opacity) {
2389   return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
2390 }
2391
2392 function lab(l, a, b, opacity) {
2393   return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
2394 }
2395
2396 function Lab(l, a, b, opacity) {
2397   this.l = +l;
2398   this.a = +a;
2399   this.b = +b;
2400   this.opacity = +opacity;
2401 }
2402
2403 define(Lab, lab, extend(Color, {
2404   brighter: function(k) {
2405     return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
2406   },
2407   darker: function(k) {
2408     return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
2409   },
2410   rgb: function() {
2411     var y = (this.l + 16) / 116,
2412         x = isNaN(this.a) ? y : y + this.a / 500,
2413         z = isNaN(this.b) ? y : y - this.b / 200;
2414     x = Xn * lab2xyz(x);
2415     y = Yn * lab2xyz(y);
2416     z = Zn * lab2xyz(z);
2417     return new Rgb(
2418       lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
2419       lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
2420       lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
2421       this.opacity
2422     );
2423   }
2424 }));
2425
2426 function xyz2lab(t) {
2427   return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
2428 }
2429
2430 function lab2xyz(t) {
2431   return t > t1 ? t * t * t : t2 * (t - t0);
2432 }
2433
2434 function lrgb2rgb(x) {
2435   return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
2436 }
2437
2438 function rgb2lrgb(x) {
2439   return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
2440 }
2441
2442 function hclConvert(o) {
2443   if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
2444   if (!(o instanceof Lab)) o = labConvert(o);
2445   if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);
2446   var h = Math.atan2(o.b, o.a) * rad2deg;
2447   return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
2448 }
2449
2450 function lch(l, c, h, opacity) {
2451   return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2452 }
2453
2454 function hcl(h, c, l, opacity) {
2455   return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2456 }
2457
2458 function Hcl(h, c, l, opacity) {
2459   this.h = +h;
2460   this.c = +c;
2461   this.l = +l;
2462   this.opacity = +opacity;
2463 }
2464
2465 define(Hcl, hcl, extend(Color, {
2466   brighter: function(k) {
2467     return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
2468   },
2469   darker: function(k) {
2470     return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
2471   },
2472   rgb: function() {
2473     return labConvert(this).rgb();
2474   }
2475 }));
2476
2477 var A = -0.14861,
2478     B = +1.78277,
2479     C = -0.29227,
2480     D = -0.90649,
2481     E = +1.97294,
2482     ED = E * D,
2483     EB = E * B,
2484     BC_DA = B * C - D * A;
2485
2486 function cubehelixConvert(o) {
2487   if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
2488   if (!(o instanceof Rgb)) o = rgbConvert(o);
2489   var r = o.r / 255,
2490       g = o.g / 255,
2491       b = o.b / 255,
2492       l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
2493       bl = b - l,
2494       k = (E * (g - l) - C * bl) / D,
2495       s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
2496       h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
2497   return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
2498 }
2499
2500 function cubehelix(h, s, l, opacity) {
2501   return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
2502 }
2503
2504 function Cubehelix(h, s, l, opacity) {
2505   this.h = +h;
2506   this.s = +s;
2507   this.l = +l;
2508   this.opacity = +opacity;
2509 }
2510
2511 define(Cubehelix, cubehelix, extend(Color, {
2512   brighter: function(k) {
2513     k = k == null ? brighter : Math.pow(brighter, k);
2514     return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2515   },
2516   darker: function(k) {
2517     k = k == null ? darker : Math.pow(darker, k);
2518     return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2519   },
2520   rgb: function() {
2521     var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
2522         l = +this.l,
2523         a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
2524         cosh = Math.cos(h),
2525         sinh = Math.sin(h);
2526     return new Rgb(
2527       255 * (l + a * (A * cosh + B * sinh)),
2528       255 * (l + a * (C * cosh + D * sinh)),
2529       255 * (l + a * (E * cosh)),
2530       this.opacity
2531     );
2532   }
2533 }));
2534
2535 function basis(t1, v0, v1, v2, v3) {
2536   var t2 = t1 * t1, t3 = t2 * t1;
2537   return ((1 - 3 * t1 + 3 * t2 - t3) * v0
2538       + (4 - 6 * t2 + 3 * t3) * v1
2539       + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
2540       + t3 * v3) / 6;
2541 }
2542
2543 function basis$1(values) {
2544   var n = values.length - 1;
2545   return function(t) {
2546     var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
2547         v1 = values[i],
2548         v2 = values[i + 1],
2549         v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
2550         v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
2551     return basis((t - i / n) * n, v0, v1, v2, v3);
2552   };
2553 }
2554
2555 function basisClosed(values) {
2556   var n = values.length;
2557   return function(t) {
2558     var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
2559         v0 = values[(i + n - 1) % n],
2560         v1 = values[i % n],
2561         v2 = values[(i + 1) % n],
2562         v3 = values[(i + 2) % n];
2563     return basis((t - i / n) * n, v0, v1, v2, v3);
2564   };
2565 }
2566
2567 function constant$3(x) {
2568   return function() {
2569     return x;
2570   };
2571 }
2572
2573 function linear(a, d) {
2574   return function(t) {
2575     return a + t * d;
2576   };
2577 }
2578
2579 function exponential(a, b, y) {
2580   return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
2581     return Math.pow(a + t * b, y);
2582   };
2583 }
2584
2585 function hue(a, b) {
2586   var d = b - a;
2587   return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
2588 }
2589
2590 function gamma(y) {
2591   return (y = +y) === 1 ? nogamma : function(a, b) {
2592     return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
2593   };
2594 }
2595
2596 function nogamma(a, b) {
2597   var d = b - a;
2598   return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
2599 }
2600
2601 var interpolateRgb = (function rgbGamma(y) {
2602   var color$$1 = gamma(y);
2603
2604   function rgb$$1(start, end) {
2605     var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
2606         g = color$$1(start.g, end.g),
2607         b = color$$1(start.b, end.b),
2608         opacity = nogamma(start.opacity, end.opacity);
2609     return function(t) {
2610       start.r = r(t);
2611       start.g = g(t);
2612       start.b = b(t);
2613       start.opacity = opacity(t);
2614       return start + "";
2615     };
2616   }
2617
2618   rgb$$1.gamma = rgbGamma;
2619
2620   return rgb$$1;
2621 })(1);
2622
2623 function rgbSpline(spline) {
2624   return function(colors) {
2625     var n = colors.length,
2626         r = new Array(n),
2627         g = new Array(n),
2628         b = new Array(n),
2629         i, color$$1;
2630     for (i = 0; i < n; ++i) {
2631       color$$1 = rgb(colors[i]);
2632       r[i] = color$$1.r || 0;
2633       g[i] = color$$1.g || 0;
2634       b[i] = color$$1.b || 0;
2635     }
2636     r = spline(r);
2637     g = spline(g);
2638     b = spline(b);
2639     color$$1.opacity = 1;
2640     return function(t) {
2641       color$$1.r = r(t);
2642       color$$1.g = g(t);
2643       color$$1.b = b(t);
2644       return color$$1 + "";
2645     };
2646   };
2647 }
2648
2649 var rgbBasis = rgbSpline(basis$1);
2650 var rgbBasisClosed = rgbSpline(basisClosed);
2651
2652 function array$1(a, b) {
2653   var nb = b ? b.length : 0,
2654       na = a ? Math.min(nb, a.length) : 0,
2655       x = new Array(na),
2656       c = new Array(nb),
2657       i;
2658
2659   for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
2660   for (; i < nb; ++i) c[i] = b[i];
2661
2662   return function(t) {
2663     for (i = 0; i < na; ++i) c[i] = x[i](t);
2664     return c;
2665   };
2666 }
2667
2668 function date(a, b) {
2669   var d = new Date;
2670   return a = +a, b -= a, function(t) {
2671     return d.setTime(a + b * t), d;
2672   };
2673 }
2674
2675 function reinterpolate(a, b) {
2676   return a = +a, b -= a, function(t) {
2677     return a + b * t;
2678   };
2679 }
2680
2681 function object(a, b) {
2682   var i = {},
2683       c = {},
2684       k;
2685
2686   if (a === null || typeof a !== "object") a = {};
2687   if (b === null || typeof b !== "object") b = {};
2688
2689   for (k in b) {
2690     if (k in a) {
2691       i[k] = interpolateValue(a[k], b[k]);
2692     } else {
2693       c[k] = b[k];
2694     }
2695   }
2696
2697   return function(t) {
2698     for (k in i) c[k] = i[k](t);
2699     return c;
2700   };
2701 }
2702
2703 var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
2704     reB = new RegExp(reA.source, "g");
2705
2706 function zero(b) {
2707   return function() {
2708     return b;
2709   };
2710 }
2711
2712 function one(b) {
2713   return function(t) {
2714     return b(t) + "";
2715   };
2716 }
2717
2718 function interpolateString(a, b) {
2719   var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
2720       am, // current match in a
2721       bm, // current match in b
2722       bs, // string preceding current number in b, if any
2723       i = -1, // index in s
2724       s = [], // string constants and placeholders
2725       q = []; // number interpolators
2726
2727   // Coerce inputs to strings.
2728   a = a + "", b = b + "";
2729
2730   // Interpolate pairs of numbers in a & b.
2731   while ((am = reA.exec(a))
2732       && (bm = reB.exec(b))) {
2733     if ((bs = bm.index) > bi) { // a string precedes the next number in b
2734       bs = b.slice(bi, bs);
2735       if (s[i]) s[i] += bs; // coalesce with previous string
2736       else s[++i] = bs;
2737     }
2738     if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
2739       if (s[i]) s[i] += bm; // coalesce with previous string
2740       else s[++i] = bm;
2741     } else { // interpolate non-matching numbers
2742       s[++i] = null;
2743       q.push({i: i, x: reinterpolate(am, bm)});
2744     }
2745     bi = reB.lastIndex;
2746   }
2747
2748   // Add remains of b.
2749   if (bi < b.length) {
2750     bs = b.slice(bi);
2751     if (s[i]) s[i] += bs; // coalesce with previous string
2752     else s[++i] = bs;
2753   }
2754
2755   // Special optimization for only a single match.
2756   // Otherwise, interpolate each of the numbers and rejoin the string.
2757   return s.length < 2 ? (q[0]
2758       ? one(q[0].x)
2759       : zero(b))
2760       : (b = q.length, function(t) {
2761           for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
2762           return s.join("");
2763         });
2764 }
2765
2766 function interpolateValue(a, b) {
2767   var t = typeof b, c;
2768   return b == null || t === "boolean" ? constant$3(b)
2769       : (t === "number" ? reinterpolate
2770       : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
2771       : b instanceof color ? interpolateRgb
2772       : b instanceof Date ? date
2773       : Array.isArray(b) ? array$1
2774       : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
2775       : reinterpolate)(a, b);
2776 }
2777
2778 function interpolateRound(a, b) {
2779   return a = +a, b -= a, function(t) {
2780     return Math.round(a + b * t);
2781   };
2782 }
2783
2784 var degrees = 180 / Math.PI;
2785
2786 var identity$2 = {
2787   translateX: 0,
2788   translateY: 0,
2789   rotate: 0,
2790   skewX: 0,
2791   scaleX: 1,
2792   scaleY: 1
2793 };
2794
2795 function decompose(a, b, c, d, e, f) {
2796   var scaleX, scaleY, skewX;
2797   if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
2798   if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
2799   if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
2800   if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
2801   return {
2802     translateX: e,
2803     translateY: f,
2804     rotate: Math.atan2(b, a) * degrees,
2805     skewX: Math.atan(skewX) * degrees,
2806     scaleX: scaleX,
2807     scaleY: scaleY
2808   };
2809 }
2810
2811 var cssNode,
2812     cssRoot,
2813     cssView,
2814     svgNode;
2815
2816 function parseCss(value) {
2817   if (value === "none") return identity$2;
2818   if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
2819   cssNode.style.transform = value;
2820   value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
2821   cssRoot.removeChild(cssNode);
2822   value = value.slice(7, -1).split(",");
2823   return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
2824 }
2825
2826 function parseSvg(value) {
2827   if (value == null) return identity$2;
2828   if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
2829   svgNode.setAttribute("transform", value);
2830   if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
2831   value = value.matrix;
2832   return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
2833 }
2834
2835 function interpolateTransform(parse, pxComma, pxParen, degParen) {
2836
2837   function pop(s) {
2838     return s.length ? s.pop() + " " : "";
2839   }
2840
2841   function translate(xa, ya, xb, yb, s, q) {
2842     if (xa !== xb || ya !== yb) {
2843       var i = s.push("translate(", null, pxComma, null, pxParen);
2844       q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2845     } else if (xb || yb) {
2846       s.push("translate(" + xb + pxComma + yb + pxParen);
2847     }
2848   }
2849
2850   function rotate(a, b, s, q) {
2851     if (a !== b) {
2852       if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
2853       q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
2854     } else if (b) {
2855       s.push(pop(s) + "rotate(" + b + degParen);
2856     }
2857   }
2858
2859   function skewX(a, b, s, q) {
2860     if (a !== b) {
2861       q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
2862     } else if (b) {
2863       s.push(pop(s) + "skewX(" + b + degParen);
2864     }
2865   }
2866
2867   function scale(xa, ya, xb, yb, s, q) {
2868     if (xa !== xb || ya !== yb) {
2869       var i = s.push(pop(s) + "scale(", null, ",", null, ")");
2870       q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2871     } else if (xb !== 1 || yb !== 1) {
2872       s.push(pop(s) + "scale(" + xb + "," + yb + ")");
2873     }
2874   }
2875
2876   return function(a, b) {
2877     var s = [], // string constants and placeholders
2878         q = []; // number interpolators
2879     a = parse(a), b = parse(b);
2880     translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
2881     rotate(a.rotate, b.rotate, s, q);
2882     skewX(a.skewX, b.skewX, s, q);
2883     scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
2884     a = b = null; // gc
2885     return function(t) {
2886       var i = -1, n = q.length, o;
2887       while (++i < n) s[(o = q[i]).i] = o.x(t);
2888       return s.join("");
2889     };
2890   };
2891 }
2892
2893 var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
2894 var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
2895
2896 var rho = Math.SQRT2,
2897     rho2 = 2,
2898     rho4 = 4,
2899     epsilon2 = 1e-12;
2900
2901 function cosh(x) {
2902   return ((x = Math.exp(x)) + 1 / x) / 2;
2903 }
2904
2905 function sinh(x) {
2906   return ((x = Math.exp(x)) - 1 / x) / 2;
2907 }
2908
2909 function tanh(x) {
2910   return ((x = Math.exp(2 * x)) - 1) / (x + 1);
2911 }
2912
2913 // p0 = [ux0, uy0, w0]
2914 // p1 = [ux1, uy1, w1]
2915 function interpolateZoom(p0, p1) {
2916   var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
2917       ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
2918       dx = ux1 - ux0,
2919       dy = uy1 - uy0,
2920       d2 = dx * dx + dy * dy,
2921       i,
2922       S;
2923
2924   // Special case for u0 ≅ u1.
2925   if (d2 < epsilon2) {
2926     S = Math.log(w1 / w0) / rho;
2927     i = function(t) {
2928       return [
2929         ux0 + t * dx,
2930         uy0 + t * dy,
2931         w0 * Math.exp(rho * t * S)
2932       ];
2933     };
2934   }
2935
2936   // General case.
2937   else {
2938     var d1 = Math.sqrt(d2),
2939         b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
2940         b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
2941         r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
2942         r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
2943     S = (r1 - r0) / rho;
2944     i = function(t) {
2945       var s = t * S,
2946           coshr0 = cosh(r0),
2947           u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
2948       return [
2949         ux0 + u * dx,
2950         uy0 + u * dy,
2951         w0 * coshr0 / cosh(rho * s + r0)
2952       ];
2953     };
2954   }
2955
2956   i.duration = S * 1000;
2957
2958   return i;
2959 }
2960
2961 function hsl$1(hue$$1) {
2962   return function(start, end) {
2963     var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
2964         s = nogamma(start.s, end.s),
2965         l = nogamma(start.l, end.l),
2966         opacity = nogamma(start.opacity, end.opacity);
2967     return function(t) {
2968       start.h = h(t);
2969       start.s = s(t);
2970       start.l = l(t);
2971       start.opacity = opacity(t);
2972       return start + "";
2973     };
2974   }
2975 }
2976
2977 var hsl$2 = hsl$1(hue);
2978 var hslLong = hsl$1(nogamma);
2979
2980 function lab$1(start, end) {
2981   var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
2982       a = nogamma(start.a, end.a),
2983       b = nogamma(start.b, end.b),
2984       opacity = nogamma(start.opacity, end.opacity);
2985   return function(t) {
2986     start.l = l(t);
2987     start.a = a(t);
2988     start.b = b(t);
2989     start.opacity = opacity(t);
2990     return start + "";
2991   };
2992 }
2993
2994 function hcl$1(hue$$1) {
2995   return function(start, end) {
2996     var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
2997         c = nogamma(start.c, end.c),
2998         l = nogamma(start.l, end.l),
2999         opacity = nogamma(start.opacity, end.opacity);
3000     return function(t) {
3001       start.h = h(t);
3002       start.c = c(t);
3003       start.l = l(t);
3004       start.opacity = opacity(t);
3005       return start + "";
3006     };
3007   }
3008 }
3009
3010 var hcl$2 = hcl$1(hue);
3011 var hclLong = hcl$1(nogamma);
3012
3013 function cubehelix$1(hue$$1) {
3014   return (function cubehelixGamma(y) {
3015     y = +y;
3016
3017     function cubehelix$$1(start, end) {
3018       var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
3019           s = nogamma(start.s, end.s),
3020           l = nogamma(start.l, end.l),
3021           opacity = nogamma(start.opacity, end.opacity);
3022       return function(t) {
3023         start.h = h(t);
3024         start.s = s(t);
3025         start.l = l(Math.pow(t, y));
3026         start.opacity = opacity(t);
3027         return start + "";
3028       };
3029     }
3030
3031     cubehelix$$1.gamma = cubehelixGamma;
3032
3033     return cubehelix$$1;
3034   })(1);
3035 }
3036
3037 var cubehelix$2 = cubehelix$1(hue);
3038 var cubehelixLong = cubehelix$1(nogamma);
3039
3040 function piecewise(interpolate, values) {
3041   var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
3042   while (i < n) I[i] = interpolate(v, v = values[++i]);
3043   return function(t) {
3044     var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
3045     return I[i](t - i);
3046   };
3047 }
3048
3049 function quantize(interpolator, n) {
3050   var samples = new Array(n);
3051   for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
3052   return samples;
3053 }
3054
3055 var frame = 0, // is an animation frame pending?
3056     timeout = 0, // is a timeout pending?
3057     interval = 0, // are any timers active?
3058     pokeDelay = 1000, // how frequently we check for clock skew
3059     taskHead,
3060     taskTail,
3061     clockLast = 0,
3062     clockNow = 0,
3063     clockSkew = 0,
3064     clock = typeof performance === "object" && performance.now ? performance : Date,
3065     setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
3066
3067 function now() {
3068   return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
3069 }
3070
3071 function clearNow() {
3072   clockNow = 0;
3073 }
3074
3075 function Timer() {
3076   this._call =
3077   this._time =
3078   this._next = null;
3079 }
3080
3081 Timer.prototype = timer.prototype = {
3082   constructor: Timer,
3083   restart: function(callback, delay, time) {
3084     if (typeof callback !== "function") throw new TypeError("callback is not a function");
3085     time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
3086     if (!this._next && taskTail !== this) {
3087       if (taskTail) taskTail._next = this;
3088       else taskHead = this;
3089       taskTail = this;
3090     }
3091     this._call = callback;
3092     this._time = time;
3093     sleep();
3094   },
3095   stop: function() {
3096     if (this._call) {
3097       this._call = null;
3098       this._time = Infinity;
3099       sleep();
3100     }
3101   }
3102 };
3103
3104 function timer(callback, delay, time) {
3105   var t = new Timer;
3106   t.restart(callback, delay, time);
3107   return t;
3108 }
3109
3110 function timerFlush() {
3111   now(); // Get the current time, if not already set.
3112   ++frame; // Pretend we’ve set an alarm, if we haven’t already.
3113   var t = taskHead, e;
3114   while (t) {
3115     if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
3116     t = t._next;
3117   }
3118   --frame;
3119 }
3120
3121 function wake() {
3122   clockNow = (clockLast = clock.now()) + clockSkew;
3123   frame = timeout = 0;
3124   try {
3125     timerFlush();
3126   } finally {
3127     frame = 0;
3128     nap();
3129     clockNow = 0;
3130   }
3131 }
3132
3133 function poke() {
3134   var now = clock.now(), delay = now - clockLast;
3135   if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
3136 }
3137
3138 function nap() {
3139   var t0, t1 = taskHead, t2, time = Infinity;
3140   while (t1) {
3141     if (t1._call) {
3142       if (time > t1._time) time = t1._time;
3143       t0 = t1, t1 = t1._next;
3144     } else {
3145       t2 = t1._next, t1._next = null;
3146       t1 = t0 ? t0._next = t2 : taskHead = t2;
3147     }
3148   }
3149   taskTail = t0;
3150   sleep(time);
3151 }
3152
3153 function sleep(time) {
3154   if (frame) return; // Soonest alarm already set, or will be.
3155   if (timeout) timeout = clearTimeout(timeout);
3156   var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
3157   if (delay > 24) {
3158     if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
3159     if (interval) interval = clearInterval(interval);
3160   } else {
3161     if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
3162     frame = 1, setFrame(wake);
3163   }
3164 }
3165
3166 function timeout$1(callback, delay, time) {
3167   var t = new Timer;
3168   delay = delay == null ? 0 : +delay;
3169   t.restart(function(elapsed) {
3170     t.stop();
3171     callback(elapsed + delay);
3172   }, delay, time);
3173   return t;
3174 }
3175
3176 function interval$1(callback, delay, time) {
3177   var t = new Timer, total = delay;
3178   if (delay == null) return t.restart(callback, delay, time), t;
3179   delay = +delay, time = time == null ? now() : +time;
3180   t.restart(function tick(elapsed) {
3181     elapsed += total;
3182     t.restart(tick, total += delay, time);
3183     callback(elapsed);
3184   }, delay, time);
3185   return t;
3186 }
3187
3188 var emptyOn = dispatch("start", "end", "interrupt");
3189 var emptyTween = [];
3190
3191 var CREATED = 0;
3192 var SCHEDULED = 1;
3193 var STARTING = 2;
3194 var STARTED = 3;
3195 var RUNNING = 4;
3196 var ENDING = 5;
3197 var ENDED = 6;
3198
3199 function schedule(node, name, id, index, group, timing) {
3200   var schedules = node.__transition;
3201   if (!schedules) node.__transition = {};
3202   else if (id in schedules) return;
3203   create$1(node, id, {
3204     name: name,
3205     index: index, // For context during callback.
3206     group: group, // For context during callback.
3207     on: emptyOn,
3208     tween: emptyTween,
3209     time: timing.time,
3210     delay: timing.delay,
3211     duration: timing.duration,
3212     ease: timing.ease,
3213     timer: null,
3214     state: CREATED
3215   });
3216 }
3217
3218 function init(node, id) {
3219   var schedule = get$1(node, id);
3220   if (schedule.state > CREATED) throw new Error("too late; already scheduled");
3221   return schedule;
3222 }
3223
3224 function set$1(node, id) {
3225   var schedule = get$1(node, id);
3226   if (schedule.state > STARTING) throw new Error("too late; already started");
3227   return schedule;
3228 }
3229
3230 function get$1(node, id) {
3231   var schedule = node.__transition;
3232   if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
3233   return schedule;
3234 }
3235
3236 function create$1(node, id, self) {
3237   var schedules = node.__transition,
3238       tween;
3239
3240   // Initialize the self timer when the transition is created.
3241   // Note the actual delay is not known until the first callback!
3242   schedules[id] = self;
3243   self.timer = timer(schedule, 0, self.time);
3244
3245   function schedule(elapsed) {
3246     self.state = SCHEDULED;
3247     self.timer.restart(start, self.delay, self.time);
3248
3249     // If the elapsed delay is less than our first sleep, start immediately.
3250     if (self.delay <= elapsed) start(elapsed - self.delay);
3251   }
3252
3253   function start(elapsed) {
3254     var i, j, n, o;
3255
3256     // If the state is not SCHEDULED, then we previously errored on start.
3257     if (self.state !== SCHEDULED) return stop();
3258
3259     for (i in schedules) {
3260       o = schedules[i];
3261       if (o.name !== self.name) continue;
3262
3263       // While this element already has a starting transition during this frame,
3264       // defer starting an interrupting transition until that transition has a
3265       // chance to tick (and possibly end); see d3/d3-transition#54!
3266       if (o.state === STARTED) return timeout$1(start);
3267
3268       // Interrupt the active transition, if any.
3269       // Dispatch the interrupt event.
3270       if (o.state === RUNNING) {
3271         o.state = ENDED;
3272         o.timer.stop();
3273         o.on.call("interrupt", node, node.__data__, o.index, o.group);
3274         delete schedules[i];
3275       }
3276
3277       // Cancel any pre-empted transitions. No interrupt event is dispatched
3278       // because the cancelled transitions never started. Note that this also
3279       // removes this transition from the pending list!
3280       else if (+i < id) {
3281         o.state = ENDED;
3282         o.timer.stop();
3283         delete schedules[i];
3284       }
3285     }
3286
3287     // Defer the first tick to end of the current frame; see d3/d3#1576.
3288     // Note the transition may be canceled after start and before the first tick!
3289     // Note this must be scheduled before the start event; see d3/d3-transition#16!
3290     // Assuming this is successful, subsequent callbacks go straight to tick.
3291     timeout$1(function() {
3292       if (self.state === STARTED) {
3293         self.state = RUNNING;
3294         self.timer.restart(tick, self.delay, self.time);
3295         tick(elapsed);
3296       }
3297     });
3298
3299     // Dispatch the start event.
3300     // Note this must be done before the tween are initialized.
3301     self.state = STARTING;
3302     self.on.call("start", node, node.__data__, self.index, self.group);
3303     if (self.state !== STARTING) return; // interrupted
3304     self.state = STARTED;
3305
3306     // Initialize the tween, deleting null tween.
3307     tween = new Array(n = self.tween.length);
3308     for (i = 0, j = -1; i < n; ++i) {
3309       if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
3310         tween[++j] = o;
3311       }
3312     }
3313     tween.length = j + 1;
3314   }
3315
3316   function tick(elapsed) {
3317     var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
3318         i = -1,
3319         n = tween.length;
3320
3321     while (++i < n) {
3322       tween[i].call(null, t);
3323     }
3324
3325     // Dispatch the end event.
3326     if (self.state === ENDING) {
3327       self.on.call("end", node, node.__data__, self.index, self.group);
3328       stop();
3329     }
3330   }
3331
3332   function stop() {
3333     self.state = ENDED;
3334     self.timer.stop();
3335     delete schedules[id];
3336     for (var i in schedules) return; // eslint-disable-line no-unused-vars
3337     delete node.__transition;
3338   }
3339 }
3340
3341 function interrupt(node, name) {
3342   var schedules = node.__transition,
3343       schedule$$1,
3344       active,
3345       empty = true,
3346       i;
3347
3348   if (!schedules) return;
3349
3350   name = name == null ? null : name + "";
3351
3352   for (i in schedules) {
3353     if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
3354     active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
3355     schedule$$1.state = ENDED;
3356     schedule$$1.timer.stop();
3357     if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
3358     delete schedules[i];
3359   }
3360
3361   if (empty) delete node.__transition;
3362 }
3363
3364 function selection_interrupt(name) {
3365   return this.each(function() {
3366     interrupt(this, name);
3367   });
3368 }
3369
3370 function tweenRemove(id, name) {
3371   var tween0, tween1;
3372   return function() {
3373     var schedule$$1 = set$1(this, id),
3374         tween = schedule$$1.tween;
3375
3376     // If this node shared tween with the previous node,
3377     // just assign the updated shared tween and we’re done!
3378     // Otherwise, copy-on-write.
3379     if (tween !== tween0) {
3380       tween1 = tween0 = tween;
3381       for (var i = 0, n = tween1.length; i < n; ++i) {
3382         if (tween1[i].name === name) {
3383           tween1 = tween1.slice();
3384           tween1.splice(i, 1);
3385           break;
3386         }
3387       }
3388     }
3389
3390     schedule$$1.tween = tween1;
3391   };
3392 }
3393
3394 function tweenFunction(id, name, value) {
3395   var tween0, tween1;
3396   if (typeof value !== "function") throw new Error;
3397   return function() {
3398     var schedule$$1 = set$1(this, id),
3399         tween = schedule$$1.tween;
3400
3401     // If this node shared tween with the previous node,
3402     // just assign the updated shared tween and we’re done!
3403     // Otherwise, copy-on-write.
3404     if (tween !== tween0) {
3405       tween1 = (tween0 = tween).slice();
3406       for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
3407         if (tween1[i].name === name) {
3408           tween1[i] = t;
3409           break;
3410         }
3411       }
3412       if (i === n) tween1.push(t);
3413     }
3414
3415     schedule$$1.tween = tween1;
3416   };
3417 }
3418
3419 function transition_tween(name, value) {
3420   var id = this._id;
3421
3422   name += "";
3423
3424   if (arguments.length < 2) {
3425     var tween = get$1(this.node(), id).tween;
3426     for (var i = 0, n = tween.length, t; i < n; ++i) {
3427       if ((t = tween[i]).name === name) {
3428         return t.value;
3429       }
3430     }
3431     return null;
3432   }
3433
3434   return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
3435 }
3436
3437 function tweenValue(transition, name, value) {
3438   var id = transition._id;
3439
3440   transition.each(function() {
3441     var schedule$$1 = set$1(this, id);
3442     (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
3443   });
3444
3445   return function(node) {
3446     return get$1(node, id).value[name];
3447   };
3448 }
3449
3450 function interpolate(a, b) {
3451   var c;
3452   return (typeof b === "number" ? reinterpolate
3453       : b instanceof color ? interpolateRgb
3454       : (c = color(b)) ? (b = c, interpolateRgb)
3455       : interpolateString)(a, b);
3456 }
3457
3458 function attrRemove$1(name) {
3459   return function() {
3460     this.removeAttribute(name);
3461   };
3462 }
3463
3464 function attrRemoveNS$1(fullname) {
3465   return function() {
3466     this.removeAttributeNS(fullname.space, fullname.local);
3467   };
3468 }
3469
3470 function attrConstant$1(name, interpolate$$1, value1) {
3471   var value00,
3472       interpolate0;
3473   return function() {
3474     var value0 = this.getAttribute(name);
3475     return value0 === value1 ? null
3476         : value0 === value00 ? interpolate0
3477         : interpolate0 = interpolate$$1(value00 = value0, value1);
3478   };
3479 }
3480
3481 function attrConstantNS$1(fullname, interpolate$$1, value1) {
3482   var value00,
3483       interpolate0;
3484   return function() {
3485     var value0 = this.getAttributeNS(fullname.space, fullname.local);
3486     return value0 === value1 ? null
3487         : value0 === value00 ? interpolate0
3488         : interpolate0 = interpolate$$1(value00 = value0, value1);
3489   };
3490 }
3491
3492 function attrFunction$1(name, interpolate$$1, value) {
3493   var value00,
3494       value10,
3495       interpolate0;
3496   return function() {
3497     var value0, value1 = value(this);
3498     if (value1 == null) return void this.removeAttribute(name);
3499     value0 = this.getAttribute(name);
3500     return value0 === value1 ? null
3501         : value0 === value00 && value1 === value10 ? interpolate0
3502         : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3503   };
3504 }
3505
3506 function attrFunctionNS$1(fullname, interpolate$$1, value) {
3507   var value00,
3508       value10,
3509       interpolate0;
3510   return function() {
3511     var value0, value1 = value(this);
3512     if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
3513     value0 = this.getAttributeNS(fullname.space, fullname.local);
3514     return value0 === value1 ? null
3515         : value0 === value00 && value1 === value10 ? interpolate0
3516         : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3517   };
3518 }
3519
3520 function transition_attr(name, value) {
3521   var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
3522   return this.attrTween(name, typeof value === "function"
3523       ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
3524       : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
3525       : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
3526 }
3527
3528 function attrTweenNS(fullname, value) {
3529   function tween() {
3530     var node = this, i = value.apply(node, arguments);
3531     return i && function(t) {
3532       node.setAttributeNS(fullname.space, fullname.local, i(t));
3533     };
3534   }
3535   tween._value = value;
3536   return tween;
3537 }
3538
3539 function attrTween(name, value) {
3540   function tween() {
3541     var node = this, i = value.apply(node, arguments);
3542     return i && function(t) {
3543       node.setAttribute(name, i(t));
3544     };
3545   }
3546   tween._value = value;
3547   return tween;
3548 }
3549
3550 function transition_attrTween(name, value) {
3551   var key = "attr." + name;
3552   if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3553   if (value == null) return this.tween(key, null);
3554   if (typeof value !== "function") throw new Error;
3555   var fullname = namespace(name);
3556   return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
3557 }
3558
3559 function delayFunction(id, value) {
3560   return function() {
3561     init(this, id).delay = +value.apply(this, arguments);
3562   };
3563 }
3564
3565 function delayConstant(id, value) {
3566   return value = +value, function() {
3567     init(this, id).delay = value;
3568   };
3569 }
3570
3571 function transition_delay(value) {
3572   var id = this._id;
3573
3574   return arguments.length
3575       ? this.each((typeof value === "function"
3576           ? delayFunction
3577           : delayConstant)(id, value))
3578       : get$1(this.node(), id).delay;
3579 }
3580
3581 function durationFunction(id, value) {
3582   return function() {
3583     set$1(this, id).duration = +value.apply(this, arguments);
3584   };
3585 }
3586
3587 function durationConstant(id, value) {
3588   return value = +value, function() {
3589     set$1(this, id).duration = value;
3590   };
3591 }
3592
3593 function transition_duration(value) {
3594   var id = this._id;
3595
3596   return arguments.length
3597       ? this.each((typeof value === "function"
3598           ? durationFunction
3599           : durationConstant)(id, value))
3600       : get$1(this.node(), id).duration;
3601 }
3602
3603 function easeConstant(id, value) {
3604   if (typeof value !== "function") throw new Error;
3605   return function() {
3606     set$1(this, id).ease = value;
3607   };
3608 }
3609
3610 function transition_ease(value) {
3611   var id = this._id;
3612
3613   return arguments.length
3614       ? this.each(easeConstant(id, value))
3615       : get$1(this.node(), id).ease;
3616 }
3617
3618 function transition_filter(match) {
3619   if (typeof match !== "function") match = matcher$1(match);
3620
3621   for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3622     for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
3623       if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
3624         subgroup.push(node);
3625       }
3626     }
3627   }
3628
3629   return new Transition(subgroups, this._parents, this._name, this._id);
3630 }
3631
3632 function transition_merge(transition$$1) {
3633   if (transition$$1._id !== this._id) throw new Error;
3634
3635   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) {
3636     for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
3637       if (node = group0[i] || group1[i]) {
3638         merge[i] = node;
3639       }
3640     }
3641   }
3642
3643   for (; j < m0; ++j) {
3644     merges[j] = groups0[j];
3645   }
3646
3647   return new Transition(merges, this._parents, this._name, this._id);
3648 }
3649
3650 function start(name) {
3651   return (name + "").trim().split(/^|\s+/).every(function(t) {
3652     var i = t.indexOf(".");
3653     if (i >= 0) t = t.slice(0, i);
3654     return !t || t === "start";
3655   });
3656 }
3657
3658 function onFunction(id, name, listener) {
3659   var on0, on1, sit = start(name) ? init : set$1;
3660   return function() {
3661     var schedule$$1 = sit(this, id),
3662         on = schedule$$1.on;
3663
3664     // If this node shared a dispatch with the previous node,
3665     // just assign the updated shared dispatch and we’re done!
3666     // Otherwise, copy-on-write.
3667     if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
3668
3669     schedule$$1.on = on1;
3670   };
3671 }
3672
3673 function transition_on(name, listener) {
3674   var id = this._id;
3675
3676   return arguments.length < 2
3677       ? get$1(this.node(), id).on.on(name)
3678       : this.each(onFunction(id, name, listener));
3679 }
3680
3681 function removeFunction(id) {
3682   return function() {
3683     var parent = this.parentNode;
3684     for (var i in this.__transition) if (+i !== id) return;
3685     if (parent) parent.removeChild(this);
3686   };
3687 }
3688
3689 function transition_remove() {
3690   return this.on("end.remove", removeFunction(this._id));
3691 }
3692
3693 function transition_select(select$$1) {
3694   var name = this._name,
3695       id = this._id;
3696
3697   if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
3698
3699   for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3700     for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
3701       if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
3702         if ("__data__" in node) subnode.__data__ = node.__data__;
3703         subgroup[i] = subnode;
3704         schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
3705       }
3706     }
3707   }
3708
3709   return new Transition(subgroups, this._parents, name, id);
3710 }
3711
3712 function transition_selectAll(select$$1) {
3713   var name = this._name,
3714       id = this._id;
3715
3716   if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
3717
3718   for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
3719     for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3720       if (node = group[i]) {
3721         for (var children = select$$1.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
3722           if (child = children[k]) {
3723             schedule(child, name, id, k, children, inherit);
3724           }
3725         }
3726         subgroups.push(children);
3727         parents.push(node);
3728       }
3729     }
3730   }
3731
3732   return new Transition(subgroups, parents, name, id);
3733 }
3734
3735 var Selection$1 = selection.prototype.constructor;
3736
3737 function transition_selection() {
3738   return new Selection$1(this._groups, this._parents);
3739 }
3740
3741 function styleRemove$1(name, interpolate$$1) {
3742   var value00,
3743       value10,
3744       interpolate0;
3745   return function() {
3746     var value0 = styleValue(this, name),
3747         value1 = (this.style.removeProperty(name), styleValue(this, name));
3748     return value0 === value1 ? null
3749         : value0 === value00 && value1 === value10 ? interpolate0
3750         : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3751   };
3752 }
3753
3754 function styleRemoveEnd(name) {
3755   return function() {
3756     this.style.removeProperty(name);
3757   };
3758 }
3759
3760 function styleConstant$1(name, interpolate$$1, value1) {
3761   var value00,
3762       interpolate0;
3763   return function() {
3764     var value0 = styleValue(this, name);
3765     return value0 === value1 ? null
3766         : value0 === value00 ? interpolate0
3767         : interpolate0 = interpolate$$1(value00 = value0, value1);
3768   };
3769 }
3770
3771 function styleFunction$1(name, interpolate$$1, value) {
3772   var value00,
3773       value10,
3774       interpolate0;
3775   return function() {
3776     var value0 = styleValue(this, name),
3777         value1 = value(this);
3778     if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
3779     return value0 === value1 ? null
3780         : value0 === value00 && value1 === value10 ? interpolate0
3781         : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3782   };
3783 }
3784
3785 function transition_style(name, value, priority) {
3786   var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
3787   return value == null ? this
3788           .styleTween(name, styleRemove$1(name, i))
3789           .on("end.style." + name, styleRemoveEnd(name))
3790       : this.styleTween(name, typeof value === "function"
3791           ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
3792           : styleConstant$1(name, i, value + ""), priority);
3793 }
3794
3795 function styleTween(name, value, priority) {
3796   function tween() {
3797     var node = this, i = value.apply(node, arguments);
3798     return i && function(t) {
3799       node.style.setProperty(name, i(t), priority);
3800     };
3801   }
3802   tween._value = value;
3803   return tween;
3804 }
3805
3806 function transition_styleTween(name, value, priority) {
3807   var key = "style." + (name += "");
3808   if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3809   if (value == null) return this.tween(key, null);
3810   if (typeof value !== "function") throw new Error;
3811   return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
3812 }
3813
3814 function textConstant$1(value) {
3815   return function() {
3816     this.textContent = value;
3817   };
3818 }
3819
3820 function textFunction$1(value) {
3821   return function() {
3822     var value1 = value(this);
3823     this.textContent = value1 == null ? "" : value1;
3824   };
3825 }
3826
3827 function transition_text(value) {
3828   return this.tween("text", typeof value === "function"
3829       ? textFunction$1(tweenValue(this, "text", value))
3830       : textConstant$1(value == null ? "" : value + ""));
3831 }
3832
3833 function transition_transition() {
3834   var name = this._name,
3835       id0 = this._id,
3836       id1 = newId();
3837
3838   for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
3839     for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3840       if (node = group[i]) {
3841         var inherit = get$1(node, id0);
3842         schedule(node, name, id1, i, group, {
3843           time: inherit.time + inherit.delay + inherit.duration,
3844           delay: 0,
3845           duration: inherit.duration,
3846           ease: inherit.ease
3847         });
3848       }
3849     }
3850   }
3851
3852   return new Transition(groups, this._parents, name, id1);
3853 }
3854
3855 var id = 0;
3856
3857 function Transition(groups, parents, name, id) {
3858   this._groups = groups;
3859   this._parents = parents;
3860   this._name = name;
3861   this._id = id;
3862 }
3863
3864 function transition(name) {
3865   return selection().transition(name);
3866 }
3867
3868 function newId() {
3869   return ++id;
3870 }
3871
3872 var selection_prototype = selection.prototype;
3873
3874 Transition.prototype = transition.prototype = {
3875   constructor: Transition,
3876   select: transition_select,
3877   selectAll: transition_selectAll,
3878   filter: transition_filter,
3879   merge: transition_merge,
3880   selection: transition_selection,
3881   transition: transition_transition,
3882   call: selection_prototype.call,
3883   nodes: selection_prototype.nodes,
3884   node: selection_prototype.node,
3885   size: selection_prototype.size,
3886   empty: selection_prototype.empty,
3887   each: selection_prototype.each,
3888   on: transition_on,
3889   attr: transition_attr,
3890   attrTween: transition_attrTween,
3891   style: transition_style,
3892   styleTween: transition_styleTween,
3893   text: transition_text,
3894   remove: transition_remove,
3895   tween: transition_tween,
3896   delay: transition_delay,
3897   duration: transition_duration,
3898   ease: transition_ease
3899 };
3900
3901 function linear$1(t) {
3902   return +t;
3903 }
3904
3905 function quadIn(t) {
3906   return t * t;
3907 }
3908
3909 function quadOut(t) {
3910   return t * (2 - t);
3911 }
3912
3913 function quadInOut(t) {
3914   return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
3915 }
3916
3917 function cubicIn(t) {
3918   return t * t * t;
3919 }
3920
3921 function cubicOut(t) {
3922   return --t * t * t + 1;
3923 }
3924
3925 function cubicInOut(t) {
3926   return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
3927 }
3928
3929 var exponent = 3;
3930
3931 var polyIn = (function custom(e) {
3932   e = +e;
3933
3934   function polyIn(t) {
3935     return Math.pow(t, e);
3936   }
3937
3938   polyIn.exponent = custom;
3939
3940   return polyIn;
3941 })(exponent);
3942
3943 var polyOut = (function custom(e) {
3944   e = +e;
3945
3946   function polyOut(t) {
3947     return 1 - Math.pow(1 - t, e);
3948   }
3949
3950   polyOut.exponent = custom;
3951
3952   return polyOut;
3953 })(exponent);
3954
3955 var polyInOut = (function custom(e) {
3956   e = +e;
3957
3958   function polyInOut(t) {
3959     return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
3960   }
3961
3962   polyInOut.exponent = custom;
3963
3964   return polyInOut;
3965 })(exponent);
3966
3967 var pi = Math.PI,
3968     halfPi = pi / 2;
3969
3970 function sinIn(t) {
3971   return 1 - Math.cos(t * halfPi);
3972 }
3973
3974 function sinOut(t) {
3975   return Math.sin(t * halfPi);
3976 }
3977
3978 function sinInOut(t) {
3979   return (1 - Math.cos(pi * t)) / 2;
3980 }
3981
3982 function expIn(t) {
3983   return Math.pow(2, 10 * t - 10);
3984 }
3985
3986 function expOut(t) {
3987   return 1 - Math.pow(2, -10 * t);
3988 }
3989
3990 function expInOut(t) {
3991   return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
3992 }
3993
3994 function circleIn(t) {
3995   return 1 - Math.sqrt(1 - t * t);
3996 }
3997
3998 function circleOut(t) {
3999   return Math.sqrt(1 - --t * t);
4000 }
4001
4002 function circleInOut(t) {
4003   return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
4004 }
4005
4006 var b1 = 4 / 11,
4007     b2 = 6 / 11,
4008     b3 = 8 / 11,
4009     b4 = 3 / 4,
4010     b5 = 9 / 11,
4011     b6 = 10 / 11,
4012     b7 = 15 / 16,
4013     b8 = 21 / 22,
4014     b9 = 63 / 64,
4015     b0 = 1 / b1 / b1;
4016
4017 function bounceIn(t) {
4018   return 1 - bounceOut(1 - t);
4019 }
4020
4021 function bounceOut(t) {
4022   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;
4023 }
4024
4025 function bounceInOut(t) {
4026   return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
4027 }
4028
4029 var overshoot = 1.70158;
4030
4031 var backIn = (function custom(s) {
4032   s = +s;
4033
4034   function backIn(t) {
4035     return t * t * ((s + 1) * t - s);
4036   }
4037
4038   backIn.overshoot = custom;
4039
4040   return backIn;
4041 })(overshoot);
4042
4043 var backOut = (function custom(s) {
4044   s = +s;
4045
4046   function backOut(t) {
4047     return --t * t * ((s + 1) * t + s) + 1;
4048   }
4049
4050   backOut.overshoot = custom;
4051
4052   return backOut;
4053 })(overshoot);
4054
4055 var backInOut = (function custom(s) {
4056   s = +s;
4057
4058   function backInOut(t) {
4059     return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
4060   }
4061
4062   backInOut.overshoot = custom;
4063
4064   return backInOut;
4065 })(overshoot);
4066
4067 var tau = 2 * Math.PI,
4068     amplitude = 1,
4069     period = 0.3;
4070
4071 var elasticIn = (function custom(a, p) {
4072   var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4073
4074   function elasticIn(t) {
4075     return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
4076   }
4077
4078   elasticIn.amplitude = function(a) { return custom(a, p * tau); };
4079   elasticIn.period = function(p) { return custom(a, p); };
4080
4081   return elasticIn;
4082 })(amplitude, period);
4083
4084 var elasticOut = (function custom(a, p) {
4085   var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4086
4087   function elasticOut(t) {
4088     return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
4089   }
4090
4091   elasticOut.amplitude = function(a) { return custom(a, p * tau); };
4092   elasticOut.period = function(p) { return custom(a, p); };
4093
4094   return elasticOut;
4095 })(amplitude, period);
4096
4097 var elasticInOut = (function custom(a, p) {
4098   var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4099
4100   function elasticInOut(t) {
4101     return ((t = t * 2 - 1) < 0
4102         ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
4103         : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
4104   }
4105
4106   elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
4107   elasticInOut.period = function(p) { return custom(a, p); };
4108
4109   return elasticInOut;
4110 })(amplitude, period);
4111
4112 var defaultTiming = {
4113   time: null, // Set on use.
4114   delay: 0,
4115   duration: 250,
4116   ease: cubicInOut
4117 };
4118
4119 function inherit(node, id) {
4120   var timing;
4121   while (!(timing = node.__transition) || !(timing = timing[id])) {
4122     if (!(node = node.parentNode)) {
4123       return defaultTiming.time = now(), defaultTiming;
4124     }
4125   }
4126   return timing;
4127 }
4128
4129 function selection_transition(name) {
4130   var id,
4131       timing;
4132
4133   if (name instanceof Transition) {
4134     id = name._id, name = name._name;
4135   } else {
4136     id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
4137   }
4138
4139   for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4140     for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4141       if (node = group[i]) {
4142         schedule(node, name, id, i, group, timing || inherit(node, id));
4143       }
4144     }
4145   }
4146
4147   return new Transition(groups, this._parents, name, id);
4148 }
4149
4150 selection.prototype.interrupt = selection_interrupt;
4151 selection.prototype.transition = selection_transition;
4152
4153 var root$1 = [null];
4154
4155 function active(node, name) {
4156   var schedules = node.__transition,
4157       schedule$$1,
4158       i;
4159
4160   if (schedules) {
4161     name = name == null ? null : name + "";
4162     for (i in schedules) {
4163       if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
4164         return new Transition([[node]], root$1, name, +i);
4165       }
4166     }
4167   }
4168
4169   return null;
4170 }
4171
4172 function constant$4(x) {
4173   return function() {
4174     return x;
4175   };
4176 }
4177
4178 function BrushEvent(target, type, selection) {
4179   this.target = target;
4180   this.type = type;
4181   this.selection = selection;
4182 }
4183
4184 function nopropagation$1() {
4185   exports.event.stopImmediatePropagation();
4186 }
4187
4188 function noevent$1() {
4189   exports.event.preventDefault();
4190   exports.event.stopImmediatePropagation();
4191 }
4192
4193 var MODE_DRAG = {name: "drag"},
4194     MODE_SPACE = {name: "space"},
4195     MODE_HANDLE = {name: "handle"},
4196     MODE_CENTER = {name: "center"};
4197
4198 var X = {
4199   name: "x",
4200   handles: ["e", "w"].map(type),
4201   input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
4202   output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
4203 };
4204
4205 var Y = {
4206   name: "y",
4207   handles: ["n", "s"].map(type),
4208   input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
4209   output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
4210 };
4211
4212 var XY = {
4213   name: "xy",
4214   handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
4215   input: function(xy) { return xy; },
4216   output: function(xy) { return xy; }
4217 };
4218
4219 var cursors = {
4220   overlay: "crosshair",
4221   selection: "move",
4222   n: "ns-resize",
4223   e: "ew-resize",
4224   s: "ns-resize",
4225   w: "ew-resize",
4226   nw: "nwse-resize",
4227   ne: "nesw-resize",
4228   se: "nwse-resize",
4229   sw: "nesw-resize"
4230 };
4231
4232 var flipX = {
4233   e: "w",
4234   w: "e",
4235   nw: "ne",
4236   ne: "nw",
4237   se: "sw",
4238   sw: "se"
4239 };
4240
4241 var flipY = {
4242   n: "s",
4243   s: "n",
4244   nw: "sw",
4245   ne: "se",
4246   se: "ne",
4247   sw: "nw"
4248 };
4249
4250 var signsX = {
4251   overlay: +1,
4252   selection: +1,
4253   n: null,
4254   e: +1,
4255   s: null,
4256   w: -1,
4257   nw: -1,
4258   ne: +1,
4259   se: +1,
4260   sw: -1
4261 };
4262
4263 var signsY = {
4264   overlay: +1,
4265   selection: +1,
4266   n: -1,
4267   e: null,
4268   s: +1,
4269   w: null,
4270   nw: -1,
4271   ne: -1,
4272   se: +1,
4273   sw: +1
4274 };
4275
4276 function type(t) {
4277   return {type: t};
4278 }
4279
4280 // Ignore right-click, since that should open the context menu.
4281 function defaultFilter$1() {
4282   return !exports.event.button;
4283 }
4284
4285 function defaultExtent() {
4286   var svg = this.ownerSVGElement || this;
4287   return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
4288 }
4289
4290 // Like d3.local, but with the name “__brush” rather than auto-generated.
4291 function local$1(node) {
4292   while (!node.__brush) if (!(node = node.parentNode)) return;
4293   return node.__brush;
4294 }
4295
4296 function empty$1(extent) {
4297   return extent[0][0] === extent[1][0]
4298       || extent[0][1] === extent[1][1];
4299 }
4300
4301 function brushSelection(node) {
4302   var state = node.__brush;
4303   return state ? state.dim.output(state.selection) : null;
4304 }
4305
4306 function brushX() {
4307   return brush$1(X);
4308 }
4309
4310 function brushY() {
4311   return brush$1(Y);
4312 }
4313
4314 function brush() {
4315   return brush$1(XY);
4316 }
4317
4318 function brush$1(dim) {
4319   var extent = defaultExtent,
4320       filter = defaultFilter$1,
4321       listeners = dispatch(brush, "start", "brush", "end"),
4322       handleSize = 6,
4323       touchending;
4324
4325   function brush(group) {
4326     var overlay = group
4327         .property("__brush", initialize)
4328       .selectAll(".overlay")
4329       .data([type("overlay")]);
4330
4331     overlay.enter().append("rect")
4332         .attr("class", "overlay")
4333         .attr("pointer-events", "all")
4334         .attr("cursor", cursors.overlay)
4335       .merge(overlay)
4336         .each(function() {
4337           var extent = local$1(this).extent;
4338           select(this)
4339               .attr("x", extent[0][0])
4340               .attr("y", extent[0][1])
4341               .attr("width", extent[1][0] - extent[0][0])
4342               .attr("height", extent[1][1] - extent[0][1]);
4343         });
4344
4345     group.selectAll(".selection")
4346       .data([type("selection")])
4347       .enter().append("rect")
4348         .attr("class", "selection")
4349         .attr("cursor", cursors.selection)
4350         .attr("fill", "#777")
4351         .attr("fill-opacity", 0.3)
4352         .attr("stroke", "#fff")
4353         .attr("shape-rendering", "crispEdges");
4354
4355     var handle = group.selectAll(".handle")
4356       .data(dim.handles, function(d) { return d.type; });
4357
4358     handle.exit().remove();
4359
4360     handle.enter().append("rect")
4361         .attr("class", function(d) { return "handle handle--" + d.type; })
4362         .attr("cursor", function(d) { return cursors[d.type]; });
4363
4364     group
4365         .each(redraw)
4366         .attr("fill", "none")
4367         .attr("pointer-events", "all")
4368         .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
4369         .on("mousedown.brush touchstart.brush", started);
4370   }
4371
4372   brush.move = function(group, selection$$1) {
4373     if (group.selection) {
4374       group
4375           .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
4376           .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
4377           .tween("brush", function() {
4378             var that = this,
4379                 state = that.__brush,
4380                 emit = emitter(that, arguments),
4381                 selection0 = state.selection,
4382                 selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
4383                 i = interpolateValue(selection0, selection1);
4384
4385             function tween(t) {
4386               state.selection = t === 1 && empty$1(selection1) ? null : i(t);
4387               redraw.call(that);
4388               emit.brush();
4389             }
4390
4391             return selection0 && selection1 ? tween : tween(1);
4392           });
4393     } else {
4394       group
4395           .each(function() {
4396             var that = this,
4397                 args = arguments,
4398                 state = that.__brush,
4399                 selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
4400                 emit = emitter(that, args).beforestart();
4401
4402             interrupt(that);
4403             state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
4404             redraw.call(that);
4405             emit.start().brush().end();
4406           });
4407     }
4408   };
4409
4410   function redraw() {
4411     var group = select(this),
4412         selection$$1 = local$1(this).selection;
4413
4414     if (selection$$1) {
4415       group.selectAll(".selection")
4416           .style("display", null)
4417           .attr("x", selection$$1[0][0])
4418           .attr("y", selection$$1[0][1])
4419           .attr("width", selection$$1[1][0] - selection$$1[0][0])
4420           .attr("height", selection$$1[1][1] - selection$$1[0][1]);
4421
4422       group.selectAll(".handle")
4423           .style("display", null)
4424           .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
4425           .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
4426           .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
4427           .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
4428     }
4429
4430     else {
4431       group.selectAll(".selection,.handle")
4432           .style("display", "none")
4433           .attr("x", null)
4434           .attr("y", null)
4435           .attr("width", null)
4436           .attr("height", null);
4437     }
4438   }
4439
4440   function emitter(that, args) {
4441     return that.__brush.emitter || new Emitter(that, args);
4442   }
4443
4444   function Emitter(that, args) {
4445     this.that = that;
4446     this.args = args;
4447     this.state = that.__brush;
4448     this.active = 0;
4449   }
4450
4451   Emitter.prototype = {
4452     beforestart: function() {
4453       if (++this.active === 1) this.state.emitter = this, this.starting = true;
4454       return this;
4455     },
4456     start: function() {
4457       if (this.starting) this.starting = false, this.emit("start");
4458       return this;
4459     },
4460     brush: function() {
4461       this.emit("brush");
4462       return this;
4463     },
4464     end: function() {
4465       if (--this.active === 0) delete this.state.emitter, this.emit("end");
4466       return this;
4467     },
4468     emit: function(type) {
4469       customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
4470     }
4471   };
4472
4473   function started() {
4474     if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
4475     else if (touchending) return;
4476     if (!filter.apply(this, arguments)) return;
4477
4478     var that = this,
4479         type = exports.event.target.__data__.type,
4480         mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
4481         signX = dim === Y ? null : signsX[type],
4482         signY = dim === X ? null : signsY[type],
4483         state = local$1(that),
4484         extent = state.extent,
4485         selection$$1 = state.selection,
4486         W = extent[0][0], w0, w1,
4487         N = extent[0][1], n0, n1,
4488         E = extent[1][0], e0, e1,
4489         S = extent[1][1], s0, s1,
4490         dx,
4491         dy,
4492         moving,
4493         shifting = signX && signY && exports.event.shiftKey,
4494         lockX,
4495         lockY,
4496         point0 = mouse(that),
4497         point$$1 = point0,
4498         emit = emitter(that, arguments).beforestart();
4499
4500     if (type === "overlay") {
4501       state.selection = selection$$1 = [
4502         [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
4503         [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
4504       ];
4505     } else {
4506       w0 = selection$$1[0][0];
4507       n0 = selection$$1[0][1];
4508       e0 = selection$$1[1][0];
4509       s0 = selection$$1[1][1];
4510     }
4511
4512     w1 = w0;
4513     n1 = n0;
4514     e1 = e0;
4515     s1 = s0;
4516
4517     var group = select(that)
4518         .attr("pointer-events", "none");
4519
4520     var overlay = group.selectAll(".overlay")
4521         .attr("cursor", cursors[type]);
4522
4523     if (exports.event.touches) {
4524       group
4525           .on("touchmove.brush", moved, true)
4526           .on("touchend.brush touchcancel.brush", ended, true);
4527     } else {
4528       var view = select(exports.event.view)
4529           .on("keydown.brush", keydowned, true)
4530           .on("keyup.brush", keyupped, true)
4531           .on("mousemove.brush", moved, true)
4532           .on("mouseup.brush", ended, true);
4533
4534       dragDisable(exports.event.view);
4535     }
4536
4537     nopropagation$1();
4538     interrupt(that);
4539     redraw.call(that);
4540     emit.start();
4541
4542     function moved() {
4543       var point1 = mouse(that);
4544       if (shifting && !lockX && !lockY) {
4545         if (Math.abs(point1[0] - point$$1[0]) > Math.abs(point1[1] - point$$1[1])) lockY = true;
4546         else lockX = true;
4547       }
4548       point$$1 = point1;
4549       moving = true;
4550       noevent$1();
4551       move();
4552     }
4553
4554     function move() {
4555       var t;
4556
4557       dx = point$$1[0] - point0[0];
4558       dy = point$$1[1] - point0[1];
4559
4560       switch (mode) {
4561         case MODE_SPACE:
4562         case MODE_DRAG: {
4563           if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
4564           if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
4565           break;
4566         }
4567         case MODE_HANDLE: {
4568           if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
4569           else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
4570           if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
4571           else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
4572           break;
4573         }
4574         case MODE_CENTER: {
4575           if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
4576           if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
4577           break;
4578         }
4579       }
4580
4581       if (e1 < w1) {
4582         signX *= -1;
4583         t = w0, w0 = e0, e0 = t;
4584         t = w1, w1 = e1, e1 = t;
4585         if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
4586       }
4587
4588       if (s1 < n1) {
4589         signY *= -1;
4590         t = n0, n0 = s0, s0 = t;
4591         t = n1, n1 = s1, s1 = t;
4592         if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
4593       }
4594
4595       if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
4596       if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
4597       if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
4598
4599       if (selection$$1[0][0] !== w1
4600           || selection$$1[0][1] !== n1
4601           || selection$$1[1][0] !== e1
4602           || selection$$1[1][1] !== s1) {
4603         state.selection = [[w1, n1], [e1, s1]];
4604         redraw.call(that);
4605         emit.brush();
4606       }
4607     }
4608
4609     function ended() {
4610       nopropagation$1();
4611       if (exports.event.touches) {
4612         if (exports.event.touches.length) return;
4613         if (touchending) clearTimeout(touchending);
4614         touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
4615         group.on("touchmove.brush touchend.brush touchcancel.brush", null);
4616       } else {
4617         yesdrag(exports.event.view, moving);
4618         view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
4619       }
4620       group.attr("pointer-events", "all");
4621       overlay.attr("cursor", cursors.overlay);
4622       if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
4623       if (empty$1(selection$$1)) state.selection = null, redraw.call(that);
4624       emit.end();
4625     }
4626
4627     function keydowned() {
4628       switch (exports.event.keyCode) {
4629         case 16: { // SHIFT
4630           shifting = signX && signY;
4631           break;
4632         }
4633         case 18: { // ALT
4634           if (mode === MODE_HANDLE) {
4635             if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4636             if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4637             mode = MODE_CENTER;
4638             move();
4639           }
4640           break;
4641         }
4642         case 32: { // SPACE; takes priority over ALT
4643           if (mode === MODE_HANDLE || mode === MODE_CENTER) {
4644             if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
4645             if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
4646             mode = MODE_SPACE;
4647             overlay.attr("cursor", cursors.selection);
4648             move();
4649           }
4650           break;
4651         }
4652         default: return;
4653       }
4654       noevent$1();
4655     }
4656
4657     function keyupped() {
4658       switch (exports.event.keyCode) {
4659         case 16: { // SHIFT
4660           if (shifting) {
4661             lockX = lockY = shifting = false;
4662             move();
4663           }
4664           break;
4665         }
4666         case 18: { // ALT
4667           if (mode === MODE_CENTER) {
4668             if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4669             if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4670             mode = MODE_HANDLE;
4671             move();
4672           }
4673           break;
4674         }
4675         case 32: { // SPACE
4676           if (mode === MODE_SPACE) {
4677             if (exports.event.altKey) {
4678               if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4679               if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4680               mode = MODE_CENTER;
4681             } else {
4682               if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4683               if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4684               mode = MODE_HANDLE;
4685             }
4686             overlay.attr("cursor", cursors[type]);
4687             move();
4688           }
4689           break;
4690         }
4691         default: return;
4692       }
4693       noevent$1();
4694     }
4695   }
4696
4697   function initialize() {
4698     var state = this.__brush || {selection: null};
4699     state.extent = extent.apply(this, arguments);
4700     state.dim = dim;
4701     return state;
4702   }
4703
4704   brush.extent = function(_) {
4705     return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
4706   };
4707
4708   brush.filter = function(_) {
4709     return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
4710   };
4711
4712   brush.handleSize = function(_) {
4713     return arguments.length ? (handleSize = +_, brush) : handleSize;
4714   };
4715
4716   brush.on = function() {
4717     var value = listeners.on.apply(listeners, arguments);
4718     return value === listeners ? brush : value;
4719   };
4720
4721   return brush;
4722 }
4723
4724 var cos = Math.cos;
4725 var sin = Math.sin;
4726 var pi$1 = Math.PI;
4727 var halfPi$1 = pi$1 / 2;
4728 var tau$1 = pi$1 * 2;
4729 var max$1 = Math.max;
4730
4731 function compareValue(compare) {
4732   return function(a, b) {
4733     return compare(
4734       a.source.value + a.target.value,
4735       b.source.value + b.target.value
4736     );
4737   };
4738 }
4739
4740 function chord() {
4741   var padAngle = 0,
4742       sortGroups = null,
4743       sortSubgroups = null,
4744       sortChords = null;
4745
4746   function chord(matrix) {
4747     var n = matrix.length,
4748         groupSums = [],
4749         groupIndex = sequence(n),
4750         subgroupIndex = [],
4751         chords = [],
4752         groups = chords.groups = new Array(n),
4753         subgroups = new Array(n * n),
4754         k,
4755         x,
4756         x0,
4757         dx,
4758         i,
4759         j;
4760
4761     // Compute the sum.
4762     k = 0, i = -1; while (++i < n) {
4763       x = 0, j = -1; while (++j < n) {
4764         x += matrix[i][j];
4765       }
4766       groupSums.push(x);
4767       subgroupIndex.push(sequence(n));
4768       k += x;
4769     }
4770
4771     // Sort groups…
4772     if (sortGroups) groupIndex.sort(function(a, b) {
4773       return sortGroups(groupSums[a], groupSums[b]);
4774     });
4775
4776     // Sort subgroups…
4777     if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
4778       d.sort(function(a, b) {
4779         return sortSubgroups(matrix[i][a], matrix[i][b]);
4780       });
4781     });
4782
4783     // Convert the sum to scaling factor for [0, 2pi].
4784     // TODO Allow start and end angle to be specified?
4785     // TODO Allow padding to be specified as percentage?
4786     k = max$1(0, tau$1 - padAngle * n) / k;
4787     dx = k ? padAngle : tau$1 / n;
4788
4789     // Compute the start and end angle for each group and subgroup.
4790     // Note: Opera has a bug reordering object literal properties!
4791     x = 0, i = -1; while (++i < n) {
4792       x0 = x, j = -1; while (++j < n) {
4793         var di = groupIndex[i],
4794             dj = subgroupIndex[di][j],
4795             v = matrix[di][dj],
4796             a0 = x,
4797             a1 = x += v * k;
4798         subgroups[dj * n + di] = {
4799           index: di,
4800           subindex: dj,
4801           startAngle: a0,
4802           endAngle: a1,
4803           value: v
4804         };
4805       }
4806       groups[di] = {
4807         index: di,
4808         startAngle: x0,
4809         endAngle: x,
4810         value: groupSums[di]
4811       };
4812       x += dx;
4813     }
4814
4815     // Generate chords for each (non-empty) subgroup-subgroup link.
4816     i = -1; while (++i < n) {
4817       j = i - 1; while (++j < n) {
4818         var source = subgroups[j * n + i],
4819             target = subgroups[i * n + j];
4820         if (source.value || target.value) {
4821           chords.push(source.value < target.value
4822               ? {source: target, target: source}
4823               : {source: source, target: target});
4824         }
4825       }
4826     }
4827
4828     return sortChords ? chords.sort(sortChords) : chords;
4829   }
4830
4831   chord.padAngle = function(_) {
4832     return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
4833   };
4834
4835   chord.sortGroups = function(_) {
4836     return arguments.length ? (sortGroups = _, chord) : sortGroups;
4837   };
4838
4839   chord.sortSubgroups = function(_) {
4840     return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
4841   };
4842
4843   chord.sortChords = function(_) {
4844     return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
4845   };
4846
4847   return chord;
4848 }
4849
4850 var slice$2 = Array.prototype.slice;
4851
4852 function constant$5(x) {
4853   return function() {
4854     return x;
4855   };
4856 }
4857
4858 var pi$2 = Math.PI,
4859     tau$2 = 2 * pi$2,
4860     epsilon$1 = 1e-6,
4861     tauEpsilon = tau$2 - epsilon$1;
4862
4863 function Path() {
4864   this._x0 = this._y0 = // start of current subpath
4865   this._x1 = this._y1 = null; // end of current subpath
4866   this._ = "";
4867 }
4868
4869 function path() {
4870   return new Path;
4871 }
4872
4873 Path.prototype = path.prototype = {
4874   constructor: Path,
4875   moveTo: function(x, y) {
4876     this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
4877   },
4878   closePath: function() {
4879     if (this._x1 !== null) {
4880       this._x1 = this._x0, this._y1 = this._y0;
4881       this._ += "Z";
4882     }
4883   },
4884   lineTo: function(x, y) {
4885     this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
4886   },
4887   quadraticCurveTo: function(x1, y1, x, y) {
4888     this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4889   },
4890   bezierCurveTo: function(x1, y1, x2, y2, x, y) {
4891     this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4892   },
4893   arcTo: function(x1, y1, x2, y2, r) {
4894     x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
4895     var x0 = this._x1,
4896         y0 = this._y1,
4897         x21 = x2 - x1,
4898         y21 = y2 - y1,
4899         x01 = x0 - x1,
4900         y01 = y0 - y1,
4901         l01_2 = x01 * x01 + y01 * y01;
4902
4903     // Is the radius negative? Error.
4904     if (r < 0) throw new Error("negative radius: " + r);
4905
4906     // Is this path empty? Move to (x1,y1).
4907     if (this._x1 === null) {
4908       this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
4909     }
4910
4911     // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
4912     else if (!(l01_2 > epsilon$1)) {}
4913
4914     // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
4915     // Equivalently, is (x1,y1) coincident with (x2,y2)?
4916     // Or, is the radius zero? Line to (x1,y1).
4917     else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
4918       this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
4919     }
4920
4921     // Otherwise, draw an arc!
4922     else {
4923       var x20 = x2 - x0,
4924           y20 = y2 - y0,
4925           l21_2 = x21 * x21 + y21 * y21,
4926           l20_2 = x20 * x20 + y20 * y20,
4927           l21 = Math.sqrt(l21_2),
4928           l01 = Math.sqrt(l01_2),
4929           l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
4930           t01 = l / l01,
4931           t21 = l / l21;
4932
4933       // If the start tangent is not coincident with (x0,y0), line to.
4934       if (Math.abs(t01 - 1) > epsilon$1) {
4935         this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
4936       }
4937
4938       this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
4939     }
4940   },
4941   arc: function(x, y, r, a0, a1, ccw) {
4942     x = +x, y = +y, r = +r;
4943     var dx = r * Math.cos(a0),
4944         dy = r * Math.sin(a0),
4945         x0 = x + dx,
4946         y0 = y + dy,
4947         cw = 1 ^ ccw,
4948         da = ccw ? a0 - a1 : a1 - a0;
4949
4950     // Is the radius negative? Error.
4951     if (r < 0) throw new Error("negative radius: " + r);
4952
4953     // Is this path empty? Move to (x0,y0).
4954     if (this._x1 === null) {
4955       this._ += "M" + x0 + "," + y0;
4956     }
4957
4958     // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
4959     else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
4960       this._ += "L" + x0 + "," + y0;
4961     }
4962
4963     // Is this arc empty? We’re done.
4964     if (!r) return;
4965
4966     // Does the angle go the wrong way? Flip the direction.
4967     if (da < 0) da = da % tau$2 + tau$2;
4968
4969     // Is this a complete circle? Draw two arcs to complete the circle.
4970     if (da > tauEpsilon) {
4971       this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
4972     }
4973
4974     // Is this arc non-empty? Draw an arc!
4975     else if (da > epsilon$1) {
4976       this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
4977     }
4978   },
4979   rect: function(x, y, w, h) {
4980     this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
4981   },
4982   toString: function() {
4983     return this._;
4984   }
4985 };
4986
4987 function defaultSource(d) {
4988   return d.source;
4989 }
4990
4991 function defaultTarget(d) {
4992   return d.target;
4993 }
4994
4995 function defaultRadius(d) {
4996   return d.radius;
4997 }
4998
4999 function defaultStartAngle(d) {
5000   return d.startAngle;
5001 }
5002
5003 function defaultEndAngle(d) {
5004   return d.endAngle;
5005 }
5006
5007 function ribbon() {
5008   var source = defaultSource,
5009       target = defaultTarget,
5010       radius = defaultRadius,
5011       startAngle = defaultStartAngle,
5012       endAngle = defaultEndAngle,
5013       context = null;
5014
5015   function ribbon() {
5016     var buffer,
5017         argv = slice$2.call(arguments),
5018         s = source.apply(this, argv),
5019         t = target.apply(this, argv),
5020         sr = +radius.apply(this, (argv[0] = s, argv)),
5021         sa0 = startAngle.apply(this, argv) - halfPi$1,
5022         sa1 = endAngle.apply(this, argv) - halfPi$1,
5023         sx0 = sr * cos(sa0),
5024         sy0 = sr * sin(sa0),
5025         tr = +radius.apply(this, (argv[0] = t, argv)),
5026         ta0 = startAngle.apply(this, argv) - halfPi$1,
5027         ta1 = endAngle.apply(this, argv) - halfPi$1;
5028
5029     if (!context) context = buffer = path();
5030
5031     context.moveTo(sx0, sy0);
5032     context.arc(0, 0, sr, sa0, sa1);
5033     if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
5034       context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
5035       context.arc(0, 0, tr, ta0, ta1);
5036     }
5037     context.quadraticCurveTo(0, 0, sx0, sy0);
5038     context.closePath();
5039
5040     if (buffer) return context = null, buffer + "" || null;
5041   }
5042
5043   ribbon.radius = function(_) {
5044     return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
5045   };
5046
5047   ribbon.startAngle = function(_) {
5048     return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
5049   };
5050
5051   ribbon.endAngle = function(_) {
5052     return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
5053   };
5054
5055   ribbon.source = function(_) {
5056     return arguments.length ? (source = _, ribbon) : source;
5057   };
5058
5059   ribbon.target = function(_) {
5060     return arguments.length ? (target = _, ribbon) : target;
5061   };
5062
5063   ribbon.context = function(_) {
5064     return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
5065   };
5066
5067   return ribbon;
5068 }
5069
5070 var prefix = "$";
5071
5072 function Map() {}
5073
5074 Map.prototype = map$1.prototype = {
5075   constructor: Map,
5076   has: function(key) {
5077     return (prefix + key) in this;
5078   },
5079   get: function(key) {
5080     return this[prefix + key];
5081   },
5082   set: function(key, value) {
5083     this[prefix + key] = value;
5084     return this;
5085   },
5086   remove: function(key) {
5087     var property = prefix + key;
5088     return property in this && delete this[property];
5089   },
5090   clear: function() {
5091     for (var property in this) if (property[0] === prefix) delete this[property];
5092   },
5093   keys: function() {
5094     var keys = [];
5095     for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
5096     return keys;
5097   },
5098   values: function() {
5099     var values = [];
5100     for (var property in this) if (property[0] === prefix) values.push(this[property]);
5101     return values;
5102   },
5103   entries: function() {
5104     var entries = [];
5105     for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
5106     return entries;
5107   },
5108   size: function() {
5109     var size = 0;
5110     for (var property in this) if (property[0] === prefix) ++size;
5111     return size;
5112   },
5113   empty: function() {
5114     for (var property in this) if (property[0] === prefix) return false;
5115     return true;
5116   },
5117   each: function(f) {
5118     for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
5119   }
5120 };
5121
5122 function map$1(object, f) {
5123   var map = new Map;
5124
5125   // Copy constructor.
5126   if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
5127
5128   // Index array by numeric index or specified key function.
5129   else if (Array.isArray(object)) {
5130     var i = -1,
5131         n = object.length,
5132         o;
5133
5134     if (f == null) while (++i < n) map.set(i, object[i]);
5135     else while (++i < n) map.set(f(o = object[i], i, object), o);
5136   }
5137
5138   // Convert object to map.
5139   else if (object) for (var key in object) map.set(key, object[key]);
5140
5141   return map;
5142 }
5143
5144 function nest() {
5145   var keys = [],
5146       sortKeys = [],
5147       sortValues,
5148       rollup,
5149       nest;
5150
5151   function apply(array, depth, createResult, setResult) {
5152     if (depth >= keys.length) {
5153       if (sortValues != null) array.sort(sortValues);
5154       return rollup != null ? rollup(array) : array;
5155     }
5156
5157     var i = -1,
5158         n = array.length,
5159         key = keys[depth++],
5160         keyValue,
5161         value,
5162         valuesByKey = map$1(),
5163         values,
5164         result = createResult();
5165
5166     while (++i < n) {
5167       if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
5168         values.push(value);
5169       } else {
5170         valuesByKey.set(keyValue, [value]);
5171       }
5172     }
5173
5174     valuesByKey.each(function(values, key) {
5175       setResult(result, key, apply(values, depth, createResult, setResult));
5176     });
5177
5178     return result;
5179   }
5180
5181   function entries(map, depth) {
5182     if (++depth > keys.length) return map;
5183     var array, sortKey = sortKeys[depth - 1];
5184     if (rollup != null && depth >= keys.length) array = map.entries();
5185     else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
5186     return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
5187   }
5188
5189   return nest = {
5190     object: function(array) { return apply(array, 0, createObject, setObject); },
5191     map: function(array) { return apply(array, 0, createMap, setMap); },
5192     entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
5193     key: function(d) { keys.push(d); return nest; },
5194     sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
5195     sortValues: function(order) { sortValues = order; return nest; },
5196     rollup: function(f) { rollup = f; return nest; }
5197   };
5198 }
5199
5200 function createObject() {
5201   return {};
5202 }
5203
5204 function setObject(object, key, value) {
5205   object[key] = value;
5206 }
5207
5208 function createMap() {
5209   return map$1();
5210 }
5211
5212 function setMap(map, key, value) {
5213   map.set(key, value);
5214 }
5215
5216 function Set() {}
5217
5218 var proto = map$1.prototype;
5219
5220 Set.prototype = set$2.prototype = {
5221   constructor: Set,
5222   has: proto.has,
5223   add: function(value) {
5224     value += "";
5225     this[prefix + value] = value;
5226     return this;
5227   },
5228   remove: proto.remove,
5229   clear: proto.clear,
5230   values: proto.keys,
5231   size: proto.size,
5232   empty: proto.empty,
5233   each: proto.each
5234 };
5235
5236 function set$2(object, f) {
5237   var set = new Set;
5238
5239   // Copy constructor.
5240   if (object instanceof Set) object.each(function(value) { set.add(value); });
5241
5242   // Otherwise, assume it’s an array.
5243   else if (object) {
5244     var i = -1, n = object.length;
5245     if (f == null) while (++i < n) set.add(object[i]);
5246     else while (++i < n) set.add(f(object[i], i, object));
5247   }
5248
5249   return set;
5250 }
5251
5252 function keys(map) {
5253   var keys = [];
5254   for (var key in map) keys.push(key);
5255   return keys;
5256 }
5257
5258 function values(map) {
5259   var values = [];
5260   for (var key in map) values.push(map[key]);
5261   return values;
5262 }
5263
5264 function entries(map) {
5265   var entries = [];
5266   for (var key in map) entries.push({key: key, value: map[key]});
5267   return entries;
5268 }
5269
5270 var array$2 = Array.prototype;
5271
5272 var slice$3 = array$2.slice;
5273
5274 function ascending$2(a, b) {
5275   return a - b;
5276 }
5277
5278 function area(ring) {
5279   var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
5280   while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
5281   return area;
5282 }
5283
5284 function constant$6(x) {
5285   return function() {
5286     return x;
5287   };
5288 }
5289
5290 function contains(ring, hole) {
5291   var i = -1, n = hole.length, c;
5292   while (++i < n) if (c = ringContains(ring, hole[i])) return c;
5293   return 0;
5294 }
5295
5296 function ringContains(ring, point) {
5297   var x = point[0], y = point[1], contains = -1;
5298   for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
5299     var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
5300     if (segmentContains(pi, pj, point)) return 0;
5301     if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
5302   }
5303   return contains;
5304 }
5305
5306 function segmentContains(a, b, c) {
5307   var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
5308 }
5309
5310 function collinear(a, b, c) {
5311   return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
5312 }
5313
5314 function within(p, q, r) {
5315   return p <= q && q <= r || r <= q && q <= p;
5316 }
5317
5318 function noop$1() {}
5319
5320 var cases = [
5321   [],
5322   [[[1.0, 1.5], [0.5, 1.0]]],
5323   [[[1.5, 1.0], [1.0, 1.5]]],
5324   [[[1.5, 1.0], [0.5, 1.0]]],
5325   [[[1.0, 0.5], [1.5, 1.0]]],
5326   [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
5327   [[[1.0, 0.5], [1.0, 1.5]]],
5328   [[[1.0, 0.5], [0.5, 1.0]]],
5329   [[[0.5, 1.0], [1.0, 0.5]]],
5330   [[[1.0, 1.5], [1.0, 0.5]]],
5331   [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
5332   [[[1.5, 1.0], [1.0, 0.5]]],
5333   [[[0.5, 1.0], [1.5, 1.0]]],
5334   [[[1.0, 1.5], [1.5, 1.0]]],
5335   [[[0.5, 1.0], [1.0, 1.5]]],
5336   []
5337 ];
5338
5339 function contours() {
5340   var dx = 1,
5341       dy = 1,
5342       threshold$$1 = thresholdSturges,
5343       smooth = smoothLinear;
5344
5345   function contours(values) {
5346     var tz = threshold$$1(values);
5347
5348     // Convert number of thresholds into uniform thresholds.
5349     if (!Array.isArray(tz)) {
5350       var domain = extent(values), start = domain[0], stop = domain[1];
5351       tz = tickStep(start, stop, tz);
5352       tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
5353     } else {
5354       tz = tz.slice().sort(ascending$2);
5355     }
5356
5357     return tz.map(function(value) {
5358       return contour(values, value);
5359     });
5360   }
5361
5362   // Accumulate, smooth contour rings, assign holes to exterior rings.
5363   // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
5364   function contour(values, value) {
5365     var polygons = [],
5366         holes = [];
5367
5368     isorings(values, value, function(ring) {
5369       smooth(ring, values, value);
5370       if (area(ring) > 0) polygons.push([ring]);
5371       else holes.push(ring);
5372     });
5373
5374     holes.forEach(function(hole) {
5375       for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
5376         if (contains((polygon = polygons[i])[0], hole) !== -1) {
5377           polygon.push(hole);
5378           return;
5379         }
5380       }
5381     });
5382
5383     return {
5384       type: "MultiPolygon",
5385       value: value,
5386       coordinates: polygons
5387     };
5388   }
5389
5390   // Marching squares with isolines stitched into rings.
5391   // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
5392   function isorings(values, value, callback) {
5393     var fragmentByStart = new Array,
5394         fragmentByEnd = new Array,
5395         x, y, t0, t1, t2, t3;
5396
5397     // Special case for the first row (y = -1, t2 = t3 = 0).
5398     x = y = -1;
5399     t1 = values[0] >= value;
5400     cases[t1 << 1].forEach(stitch);
5401     while (++x < dx - 1) {
5402       t0 = t1, t1 = values[x + 1] >= value;
5403       cases[t0 | t1 << 1].forEach(stitch);
5404     }
5405     cases[t1 << 0].forEach(stitch);
5406
5407     // General case for the intermediate rows.
5408     while (++y < dy - 1) {
5409       x = -1;
5410       t1 = values[y * dx + dx] >= value;
5411       t2 = values[y * dx] >= value;
5412       cases[t1 << 1 | t2 << 2].forEach(stitch);
5413       while (++x < dx - 1) {
5414         t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
5415         t3 = t2, t2 = values[y * dx + x + 1] >= value;
5416         cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
5417       }
5418       cases[t1 | t2 << 3].forEach(stitch);
5419     }
5420
5421     // Special case for the last row (y = dy - 1, t0 = t1 = 0).
5422     x = -1;
5423     t2 = values[y * dx] >= value;
5424     cases[t2 << 2].forEach(stitch);
5425     while (++x < dx - 1) {
5426       t3 = t2, t2 = values[y * dx + x + 1] >= value;
5427       cases[t2 << 2 | t3 << 3].forEach(stitch);
5428     }
5429     cases[t2 << 3].forEach(stitch);
5430
5431     function stitch(line) {
5432       var start = [line[0][0] + x, line[0][1] + y],
5433           end = [line[1][0] + x, line[1][1] + y],
5434           startIndex = index(start),
5435           endIndex = index(end),
5436           f, g;
5437       if (f = fragmentByEnd[startIndex]) {
5438         if (g = fragmentByStart[endIndex]) {
5439           delete fragmentByEnd[f.end];
5440           delete fragmentByStart[g.start];
5441           if (f === g) {
5442             f.ring.push(end);
5443             callback(f.ring);
5444           } else {
5445             fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
5446           }
5447         } else {
5448           delete fragmentByEnd[f.end];
5449           f.ring.push(end);
5450           fragmentByEnd[f.end = endIndex] = f;
5451         }
5452       } else if (f = fragmentByStart[endIndex]) {
5453         if (g = fragmentByEnd[startIndex]) {
5454           delete fragmentByStart[f.start];
5455           delete fragmentByEnd[g.end];
5456           if (f === g) {
5457             f.ring.push(end);
5458             callback(f.ring);
5459           } else {
5460             fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
5461           }
5462         } else {
5463           delete fragmentByStart[f.start];
5464           f.ring.unshift(start);
5465           fragmentByStart[f.start = startIndex] = f;
5466         }
5467       } else {
5468         fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
5469       }
5470     }
5471   }
5472
5473   function index(point) {
5474     return point[0] * 2 + point[1] * (dx + 1) * 4;
5475   }
5476
5477   function smoothLinear(ring, values, value) {
5478     ring.forEach(function(point) {
5479       var x = point[0],
5480           y = point[1],
5481           xt = x | 0,
5482           yt = y | 0,
5483           v0,
5484           v1 = values[yt * dx + xt];
5485       if (x > 0 && x < dx && xt === x) {
5486         v0 = values[yt * dx + xt - 1];
5487         point[0] = x + (value - v0) / (v1 - v0) - 0.5;
5488       }
5489       if (y > 0 && y < dy && yt === y) {
5490         v0 = values[(yt - 1) * dx + xt];
5491         point[1] = y + (value - v0) / (v1 - v0) - 0.5;
5492       }
5493     });
5494   }
5495
5496   contours.contour = contour;
5497
5498   contours.size = function(_) {
5499     if (!arguments.length) return [dx, dy];
5500     var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
5501     if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
5502     return dx = _0, dy = _1, contours;
5503   };
5504
5505   contours.thresholds = function(_) {
5506     return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold$$1;
5507   };
5508
5509   contours.smooth = function(_) {
5510     return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
5511   };
5512
5513   return contours;
5514 }
5515
5516 // TODO Optimize edge cases.
5517 // TODO Optimize index calculation.
5518 // TODO Optimize arguments.
5519 function blurX(source, target, r) {
5520   var n = source.width,
5521       m = source.height,
5522       w = (r << 1) + 1;
5523   for (var j = 0; j < m; ++j) {
5524     for (var i = 0, sr = 0; i < n + r; ++i) {
5525       if (i < n) {
5526         sr += source.data[i + j * n];
5527       }
5528       if (i >= r) {
5529         if (i >= w) {
5530           sr -= source.data[i - w + j * n];
5531         }
5532         target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
5533       }
5534     }
5535   }
5536 }
5537
5538 // TODO Optimize edge cases.
5539 // TODO Optimize index calculation.
5540 // TODO Optimize arguments.
5541 function blurY(source, target, r) {
5542   var n = source.width,
5543       m = source.height,
5544       w = (r << 1) + 1;
5545   for (var i = 0; i < n; ++i) {
5546     for (var j = 0, sr = 0; j < m + r; ++j) {
5547       if (j < m) {
5548         sr += source.data[i + j * n];
5549       }
5550       if (j >= r) {
5551         if (j >= w) {
5552           sr -= source.data[i + (j - w) * n];
5553         }
5554         target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
5555       }
5556     }
5557   }
5558 }
5559
5560 function defaultX(d) {
5561   return d[0];
5562 }
5563
5564 function defaultY(d) {
5565   return d[1];
5566 }
5567
5568 function density() {
5569   var x = defaultX,
5570       y = defaultY,
5571       dx = 960,
5572       dy = 500,
5573       r = 20, // blur radius
5574       k = 2, // log2(grid cell size)
5575       o = r * 3, // grid offset, to pad for blur
5576       n = (dx + o * 2) >> k, // grid width
5577       m = (dy + o * 2) >> k, // grid height
5578       threshold$$1 = constant$6(20);
5579
5580   function density(data) {
5581     var values0 = new Float32Array(n * m),
5582         values1 = new Float32Array(n * m);
5583
5584     data.forEach(function(d, i, data) {
5585       var xi = (x(d, i, data) + o) >> k,
5586           yi = (y(d, i, data) + o) >> k;
5587       if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
5588         ++values0[xi + yi * n];
5589       }
5590     });
5591
5592     // TODO Optimize.
5593     blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5594     blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5595     blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5596     blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5597     blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5598     blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5599
5600     var tz = threshold$$1(values0);
5601
5602     // Convert number of thresholds into uniform thresholds.
5603     if (!Array.isArray(tz)) {
5604       var stop = max(values0);
5605       tz = tickStep(0, stop, tz);
5606       tz = sequence(0, Math.floor(stop / tz) * tz, tz);
5607       tz.shift();
5608     }
5609
5610     return contours()
5611         .thresholds(tz)
5612         .size([n, m])
5613       (values0)
5614         .map(transform);
5615   }
5616
5617   function transform(geometry) {
5618     geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
5619     geometry.coordinates.forEach(transformPolygon);
5620     return geometry;
5621   }
5622
5623   function transformPolygon(coordinates) {
5624     coordinates.forEach(transformRing);
5625   }
5626
5627   function transformRing(coordinates) {
5628     coordinates.forEach(transformPoint);
5629   }
5630
5631   // TODO Optimize.
5632   function transformPoint(coordinates) {
5633     coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
5634     coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
5635   }
5636
5637   function resize() {
5638     o = r * 3;
5639     n = (dx + o * 2) >> k;
5640     m = (dy + o * 2) >> k;
5641     return density;
5642   }
5643
5644   density.x = function(_) {
5645     return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
5646   };
5647
5648   density.y = function(_) {
5649     return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
5650   };
5651
5652   density.size = function(_) {
5653     if (!arguments.length) return [dx, dy];
5654     var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
5655     if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
5656     return dx = _0, dy = _1, resize();
5657   };
5658
5659   density.cellSize = function(_) {
5660     if (!arguments.length) return 1 << k;
5661     if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
5662     return k = Math.floor(Math.log(_) / Math.LN2), resize();
5663   };
5664
5665   density.thresholds = function(_) {
5666     return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold$$1;
5667   };
5668
5669   density.bandwidth = function(_) {
5670     if (!arguments.length) return Math.sqrt(r * (r + 1));
5671     if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
5672     return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
5673   };
5674
5675   return density;
5676 }
5677
5678 var EOL = {},
5679     EOF = {},
5680     QUOTE = 34,
5681     NEWLINE = 10,
5682     RETURN = 13;
5683
5684 function objectConverter(columns) {
5685   return new Function("d", "return {" + columns.map(function(name, i) {
5686     return JSON.stringify(name) + ": d[" + i + "]";
5687   }).join(",") + "}");
5688 }
5689
5690 function customConverter(columns, f) {
5691   var object = objectConverter(columns);
5692   return function(row, i) {
5693     return f(object(row), i, columns);
5694   };
5695 }
5696
5697 // Compute unique columns in order of discovery.
5698 function inferColumns(rows) {
5699   var columnSet = Object.create(null),
5700       columns = [];
5701
5702   rows.forEach(function(row) {
5703     for (var column in row) {
5704       if (!(column in columnSet)) {
5705         columns.push(columnSet[column] = column);
5706       }
5707     }
5708   });
5709
5710   return columns;
5711 }
5712
5713 function dsvFormat(delimiter) {
5714   var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
5715       DELIMITER = delimiter.charCodeAt(0);
5716
5717   function parse(text, f) {
5718     var convert, columns, rows = parseRows(text, function(row, i) {
5719       if (convert) return convert(row, i - 1);
5720       columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
5721     });
5722     rows.columns = columns || [];
5723     return rows;
5724   }
5725
5726   function parseRows(text, f) {
5727     var rows = [], // output rows
5728         N = text.length,
5729         I = 0, // current character index
5730         n = 0, // current line number
5731         t, // current token
5732         eof = N <= 0, // current token followed by EOF?
5733         eol = false; // current token followed by EOL?
5734
5735     // Strip the trailing newline.
5736     if (text.charCodeAt(N - 1) === NEWLINE) --N;
5737     if (text.charCodeAt(N - 1) === RETURN) --N;
5738
5739     function token() {
5740       if (eof) return EOF;
5741       if (eol) return eol = false, EOL;
5742
5743       // Unescape quotes.
5744       var i, j = I, c;
5745       if (text.charCodeAt(j) === QUOTE) {
5746         while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
5747         if ((i = I) >= N) eof = true;
5748         else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
5749         else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5750         return text.slice(j + 1, i - 1).replace(/""/g, "\"");
5751       }
5752
5753       // Find next delimiter or newline.
5754       while (I < N) {
5755         if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
5756         else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5757         else if (c !== DELIMITER) continue;
5758         return text.slice(j, i);
5759       }
5760
5761       // Return last token before EOF.
5762       return eof = true, text.slice(j, N);
5763     }
5764
5765     while ((t = token()) !== EOF) {
5766       var row = [];
5767       while (t !== EOL && t !== EOF) row.push(t), t = token();
5768       if (f && (row = f(row, n++)) == null) continue;
5769       rows.push(row);
5770     }
5771
5772     return rows;
5773   }
5774
5775   function format(rows, columns) {
5776     if (columns == null) columns = inferColumns(rows);
5777     return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
5778       return columns.map(function(column) {
5779         return formatValue(row[column]);
5780       }).join(delimiter);
5781     })).join("\n");
5782   }
5783
5784   function formatRows(rows) {
5785     return rows.map(formatRow).join("\n");
5786   }
5787
5788   function formatRow(row) {
5789     return row.map(formatValue).join(delimiter);
5790   }
5791
5792   function formatValue(text) {
5793     return text == null ? ""
5794         : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
5795         : text;
5796   }
5797
5798   return {
5799     parse: parse,
5800     parseRows: parseRows,
5801     format: format,
5802     formatRows: formatRows
5803   };
5804 }
5805
5806 var csv = dsvFormat(",");
5807
5808 var csvParse = csv.parse;
5809 var csvParseRows = csv.parseRows;
5810 var csvFormat = csv.format;
5811 var csvFormatRows = csv.formatRows;
5812
5813 var tsv = dsvFormat("\t");
5814
5815 var tsvParse = tsv.parse;
5816 var tsvParseRows = tsv.parseRows;
5817 var tsvFormat = tsv.format;
5818 var tsvFormatRows = tsv.formatRows;
5819
5820 function responseBlob(response) {
5821   if (!response.ok) throw new Error(response.status + " " + response.statusText);
5822   return response.blob();
5823 }
5824
5825 function blob(input, init) {
5826   return fetch(input, init).then(responseBlob);
5827 }
5828
5829 function responseArrayBuffer(response) {
5830   if (!response.ok) throw new Error(response.status + " " + response.statusText);
5831   return response.arrayBuffer();
5832 }
5833
5834 function buffer(input, init) {
5835   return fetch(input, init).then(responseArrayBuffer);
5836 }
5837
5838 function responseText(response) {
5839   if (!response.ok) throw new Error(response.status + " " + response.statusText);
5840   return response.text();
5841 }
5842
5843 function text(input, init) {
5844   return fetch(input, init).then(responseText);
5845 }
5846
5847 function dsvParse(parse) {
5848   return function(input, init, row) {
5849     if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
5850     return text(input, init).then(function(response) {
5851       return parse(response, row);
5852     });
5853   };
5854 }
5855
5856 function dsv(delimiter, input, init, row) {
5857   if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
5858   var format = dsvFormat(delimiter);
5859   return text(input, init).then(function(response) {
5860     return format.parse(response, row);
5861   });
5862 }
5863
5864 var csv$1 = dsvParse(csvParse);
5865 var tsv$1 = dsvParse(tsvParse);
5866
5867 function image(input, init) {
5868   return new Promise(function(resolve, reject) {
5869     var image = new Image;
5870     for (var key in init) image[key] = init[key];
5871     image.onerror = reject;
5872     image.onload = function() { resolve(image); };
5873     image.src = input;
5874   });
5875 }
5876
5877 function responseJson(response) {
5878   if (!response.ok) throw new Error(response.status + " " + response.statusText);
5879   return response.json();
5880 }
5881
5882 function json(input, init) {
5883   return fetch(input, init).then(responseJson);
5884 }
5885
5886 function parser(type) {
5887   return function(input, init)  {
5888     return text(input, init).then(function(text$$1) {
5889       return (new DOMParser).parseFromString(text$$1, type);
5890     });
5891   };
5892 }
5893
5894 var xml = parser("application/xml");
5895
5896 var html = parser("text/html");
5897
5898 var svg = parser("image/svg+xml");
5899
5900 function center$1(x, y) {
5901   var nodes;
5902
5903   if (x == null) x = 0;
5904   if (y == null) y = 0;
5905
5906   function force() {
5907     var i,
5908         n = nodes.length,
5909         node,
5910         sx = 0,
5911         sy = 0;
5912
5913     for (i = 0; i < n; ++i) {
5914       node = nodes[i], sx += node.x, sy += node.y;
5915     }
5916
5917     for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
5918       node = nodes[i], node.x -= sx, node.y -= sy;
5919     }
5920   }
5921
5922   force.initialize = function(_) {
5923     nodes = _;
5924   };
5925
5926   force.x = function(_) {
5927     return arguments.length ? (x = +_, force) : x;
5928   };
5929
5930   force.y = function(_) {
5931     return arguments.length ? (y = +_, force) : y;
5932   };
5933
5934   return force;
5935 }
5936
5937 function constant$7(x) {
5938   return function() {
5939     return x;
5940   };
5941 }
5942
5943 function jiggle() {
5944   return (Math.random() - 0.5) * 1e-6;
5945 }
5946
5947 function tree_add(d) {
5948   var x = +this._x.call(null, d),
5949       y = +this._y.call(null, d);
5950   return add(this.cover(x, y), x, y, d);
5951 }
5952
5953 function add(tree, x, y, d) {
5954   if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
5955
5956   var parent,
5957       node = tree._root,
5958       leaf = {data: d},
5959       x0 = tree._x0,
5960       y0 = tree._y0,
5961       x1 = tree._x1,
5962       y1 = tree._y1,
5963       xm,
5964       ym,
5965       xp,
5966       yp,
5967       right,
5968       bottom,
5969       i,
5970       j;
5971
5972   // If the tree is empty, initialize the root as a leaf.
5973   if (!node) return tree._root = leaf, tree;
5974
5975   // Find the existing leaf for the new point, or add it.
5976   while (node.length) {
5977     if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5978     if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5979     if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
5980   }
5981
5982   // Is the new point is exactly coincident with the existing point?
5983   xp = +tree._x.call(null, node.data);
5984   yp = +tree._y.call(null, node.data);
5985   if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
5986
5987   // Otherwise, split the leaf node until the old and new point are separated.
5988   do {
5989     parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
5990     if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5991     if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5992   } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
5993   return parent[j] = node, parent[i] = leaf, tree;
5994 }
5995
5996 function addAll(data) {
5997   var d, i, n = data.length,
5998       x,
5999       y,
6000       xz = new Array(n),
6001       yz = new Array(n),
6002       x0 = Infinity,
6003       y0 = Infinity,
6004       x1 = -Infinity,
6005       y1 = -Infinity;
6006
6007   // Compute the points and their extent.
6008   for (i = 0; i < n; ++i) {
6009     if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
6010     xz[i] = x;
6011     yz[i] = y;
6012     if (x < x0) x0 = x;
6013     if (x > x1) x1 = x;
6014     if (y < y0) y0 = y;
6015     if (y > y1) y1 = y;
6016   }
6017
6018   // If there were no (valid) points, inherit the existing extent.
6019   if (x1 < x0) x0 = this._x0, x1 = this._x1;
6020   if (y1 < y0) y0 = this._y0, y1 = this._y1;
6021
6022   // Expand the tree to cover the new points.
6023   this.cover(x0, y0).cover(x1, y1);
6024
6025   // Add the new points.
6026   for (i = 0; i < n; ++i) {
6027     add(this, xz[i], yz[i], data[i]);
6028   }
6029
6030   return this;
6031 }
6032
6033 function tree_cover(x, y) {
6034   if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
6035
6036   var x0 = this._x0,
6037       y0 = this._y0,
6038       x1 = this._x1,
6039       y1 = this._y1;
6040
6041   // If the quadtree has no extent, initialize them.
6042   // Integer extent are necessary so that if we later double the extent,
6043   // the existing quadrant boundaries don’t change due to floating point error!
6044   if (isNaN(x0)) {
6045     x1 = (x0 = Math.floor(x)) + 1;
6046     y1 = (y0 = Math.floor(y)) + 1;
6047   }
6048
6049   // Otherwise, double repeatedly to cover.
6050   else if (x0 > x || x > x1 || y0 > y || y > y1) {
6051     var z = x1 - x0,
6052         node = this._root,
6053         parent,
6054         i;
6055
6056     switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
6057       case 0: {
6058         do parent = new Array(4), parent[i] = node, node = parent;
6059         while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
6060         break;
6061       }
6062       case 1: {
6063         do parent = new Array(4), parent[i] = node, node = parent;
6064         while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
6065         break;
6066       }
6067       case 2: {
6068         do parent = new Array(4), parent[i] = node, node = parent;
6069         while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
6070         break;
6071       }
6072       case 3: {
6073         do parent = new Array(4), parent[i] = node, node = parent;
6074         while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
6075         break;
6076       }
6077     }
6078
6079     if (this._root && this._root.length) this._root = node;
6080   }
6081
6082   // If the quadtree covers the point already, just return.
6083   else return this;
6084
6085   this._x0 = x0;
6086   this._y0 = y0;
6087   this._x1 = x1;
6088   this._y1 = y1;
6089   return this;
6090 }
6091
6092 function tree_data() {
6093   var data = [];
6094   this.visit(function(node) {
6095     if (!node.length) do data.push(node.data); while (node = node.next)
6096   });
6097   return data;
6098 }
6099
6100 function tree_extent(_) {
6101   return arguments.length
6102       ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
6103       : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
6104 }
6105
6106 function Quad(node, x0, y0, x1, y1) {
6107   this.node = node;
6108   this.x0 = x0;
6109   this.y0 = y0;
6110   this.x1 = x1;
6111   this.y1 = y1;
6112 }
6113
6114 function tree_find(x, y, radius) {
6115   var data,
6116       x0 = this._x0,
6117       y0 = this._y0,
6118       x1,
6119       y1,
6120       x2,
6121       y2,
6122       x3 = this._x1,
6123       y3 = this._y1,
6124       quads = [],
6125       node = this._root,
6126       q,
6127       i;
6128
6129   if (node) quads.push(new Quad(node, x0, y0, x3, y3));
6130   if (radius == null) radius = Infinity;
6131   else {
6132     x0 = x - radius, y0 = y - radius;
6133     x3 = x + radius, y3 = y + radius;
6134     radius *= radius;
6135   }
6136
6137   while (q = quads.pop()) {
6138
6139     // Stop searching if this quadrant can’t contain a closer node.
6140     if (!(node = q.node)
6141         || (x1 = q.x0) > x3
6142         || (y1 = q.y0) > y3
6143         || (x2 = q.x1) < x0
6144         || (y2 = q.y1) < y0) continue;
6145
6146     // Bisect the current quadrant.
6147     if (node.length) {
6148       var xm = (x1 + x2) / 2,
6149           ym = (y1 + y2) / 2;
6150
6151       quads.push(
6152         new Quad(node[3], xm, ym, x2, y2),
6153         new Quad(node[2], x1, ym, xm, y2),
6154         new Quad(node[1], xm, y1, x2, ym),
6155         new Quad(node[0], x1, y1, xm, ym)
6156       );
6157
6158       // Visit the closest quadrant first.
6159       if (i = (y >= ym) << 1 | (x >= xm)) {
6160         q = quads[quads.length - 1];
6161         quads[quads.length - 1] = quads[quads.length - 1 - i];
6162         quads[quads.length - 1 - i] = q;
6163       }
6164     }
6165
6166     // Visit this point. (Visiting coincident points isn’t necessary!)
6167     else {
6168       var dx = x - +this._x.call(null, node.data),
6169           dy = y - +this._y.call(null, node.data),
6170           d2 = dx * dx + dy * dy;
6171       if (d2 < radius) {
6172         var d = Math.sqrt(radius = d2);
6173         x0 = x - d, y0 = y - d;
6174         x3 = x + d, y3 = y + d;
6175         data = node.data;
6176       }
6177     }
6178   }
6179
6180   return data;
6181 }
6182
6183 function tree_remove(d) {
6184   if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
6185
6186   var parent,
6187       node = this._root,
6188       retainer,
6189       previous,
6190       next,
6191       x0 = this._x0,
6192       y0 = this._y0,
6193       x1 = this._x1,
6194       y1 = this._y1,
6195       x,
6196       y,
6197       xm,
6198       ym,
6199       right,
6200       bottom,
6201       i,
6202       j;
6203
6204   // If the tree is empty, initialize the root as a leaf.
6205   if (!node) return this;
6206
6207   // Find the leaf node for the point.
6208   // While descending, also retain the deepest parent with a non-removed sibling.
6209   if (node.length) while (true) {
6210     if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
6211     if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
6212     if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
6213     if (!node.length) break;
6214     if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
6215   }
6216
6217   // Find the point to remove.
6218   while (node.data !== d) if (!(previous = node, node = node.next)) return this;
6219   if (next = node.next) delete node.next;
6220
6221   // If there are multiple coincident points, remove just the point.
6222   if (previous) return next ? previous.next = next : delete previous.next, this;
6223
6224   // If this is the root point, remove it.
6225   if (!parent) return this._root = next, this;
6226
6227   // Remove this leaf.
6228   next ? parent[i] = next : delete parent[i];
6229
6230   // If the parent now contains exactly one leaf, collapse superfluous parents.
6231   if ((node = parent[0] || parent[1] || parent[2] || parent[3])
6232       && node === (parent[3] || parent[2] || parent[1] || parent[0])
6233       && !node.length) {
6234     if (retainer) retainer[j] = node;
6235     else this._root = node;
6236   }
6237
6238   return this;
6239 }
6240
6241 function removeAll(data) {
6242   for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
6243   return this;
6244 }
6245
6246 function tree_root() {
6247   return this._root;
6248 }
6249
6250 function tree_size() {
6251   var size = 0;
6252   this.visit(function(node) {
6253     if (!node.length) do ++size; while (node = node.next)
6254   });
6255   return size;
6256 }
6257
6258 function tree_visit(callback) {
6259   var quads = [], q, node = this._root, child, x0, y0, x1, y1;
6260   if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
6261   while (q = quads.pop()) {
6262     if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
6263       var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
6264       if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
6265       if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
6266       if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
6267       if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
6268     }
6269   }
6270   return this;
6271 }
6272
6273 function tree_visitAfter(callback) {
6274   var quads = [], next = [], q;
6275   if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
6276   while (q = quads.pop()) {
6277     var node = q.node;
6278     if (node.length) {
6279       var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
6280       if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
6281       if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
6282       if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
6283       if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
6284     }
6285     next.push(q);
6286   }
6287   while (q = next.pop()) {
6288     callback(q.node, q.x0, q.y0, q.x1, q.y1);
6289   }
6290   return this;
6291 }
6292
6293 function defaultX$1(d) {
6294   return d[0];
6295 }
6296
6297 function tree_x(_) {
6298   return arguments.length ? (this._x = _, this) : this._x;
6299 }
6300
6301 function defaultY$1(d) {
6302   return d[1];
6303 }
6304
6305 function tree_y(_) {
6306   return arguments.length ? (this._y = _, this) : this._y;
6307 }
6308
6309 function quadtree(nodes, x, y) {
6310   var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
6311   return nodes == null ? tree : tree.addAll(nodes);
6312 }
6313
6314 function Quadtree(x, y, x0, y0, x1, y1) {
6315   this._x = x;
6316   this._y = y;
6317   this._x0 = x0;
6318   this._y0 = y0;
6319   this._x1 = x1;
6320   this._y1 = y1;
6321   this._root = undefined;
6322 }
6323
6324 function leaf_copy(leaf) {
6325   var copy = {data: leaf.data}, next = copy;
6326   while (leaf = leaf.next) next = next.next = {data: leaf.data};
6327   return copy;
6328 }
6329
6330 var treeProto = quadtree.prototype = Quadtree.prototype;
6331
6332 treeProto.copy = function() {
6333   var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
6334       node = this._root,
6335       nodes,
6336       child;
6337
6338   if (!node) return copy;
6339
6340   if (!node.length) return copy._root = leaf_copy(node), copy;
6341
6342   nodes = [{source: node, target: copy._root = new Array(4)}];
6343   while (node = nodes.pop()) {
6344     for (var i = 0; i < 4; ++i) {
6345       if (child = node.source[i]) {
6346         if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
6347         else node.target[i] = leaf_copy(child);
6348       }
6349     }
6350   }
6351
6352   return copy;
6353 };
6354
6355 treeProto.add = tree_add;
6356 treeProto.addAll = addAll;
6357 treeProto.cover = tree_cover;
6358 treeProto.data = tree_data;
6359 treeProto.extent = tree_extent;
6360 treeProto.find = tree_find;
6361 treeProto.remove = tree_remove;
6362 treeProto.removeAll = removeAll;
6363 treeProto.root = tree_root;
6364 treeProto.size = tree_size;
6365 treeProto.visit = tree_visit;
6366 treeProto.visitAfter = tree_visitAfter;
6367 treeProto.x = tree_x;
6368 treeProto.y = tree_y;
6369
6370 function x(d) {
6371   return d.x + d.vx;
6372 }
6373
6374 function y(d) {
6375   return d.y + d.vy;
6376 }
6377
6378 function collide(radius) {
6379   var nodes,
6380       radii,
6381       strength = 1,
6382       iterations = 1;
6383
6384   if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
6385
6386   function force() {
6387     var i, n = nodes.length,
6388         tree,
6389         node,
6390         xi,
6391         yi,
6392         ri,
6393         ri2;
6394
6395     for (var k = 0; k < iterations; ++k) {
6396       tree = quadtree(nodes, x, y).visitAfter(prepare);
6397       for (i = 0; i < n; ++i) {
6398         node = nodes[i];
6399         ri = radii[node.index], ri2 = ri * ri;
6400         xi = node.x + node.vx;
6401         yi = node.y + node.vy;
6402         tree.visit(apply);
6403       }
6404     }
6405
6406     function apply(quad, x0, y0, x1, y1) {
6407       var data = quad.data, rj = quad.r, r = ri + rj;
6408       if (data) {
6409         if (data.index > node.index) {
6410           var x = xi - data.x - data.vx,
6411               y = yi - data.y - data.vy,
6412               l = x * x + y * y;
6413           if (l < r * r) {
6414             if (x === 0) x = jiggle(), l += x * x;
6415             if (y === 0) y = jiggle(), l += y * y;
6416             l = (r - (l = Math.sqrt(l))) / l * strength;
6417             node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
6418             node.vy += (y *= l) * r;
6419             data.vx -= x * (r = 1 - r);
6420             data.vy -= y * r;
6421           }
6422         }
6423         return;
6424       }
6425       return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
6426     }
6427   }
6428
6429   function prepare(quad) {
6430     if (quad.data) return quad.r = radii[quad.data.index];
6431     for (var i = quad.r = 0; i < 4; ++i) {
6432       if (quad[i] && quad[i].r > quad.r) {
6433         quad.r = quad[i].r;
6434       }
6435     }
6436   }
6437
6438   function initialize() {
6439     if (!nodes) return;
6440     var i, n = nodes.length, node;
6441     radii = new Array(n);
6442     for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
6443   }
6444
6445   force.initialize = function(_) {
6446     nodes = _;
6447     initialize();
6448   };
6449
6450   force.iterations = function(_) {
6451     return arguments.length ? (iterations = +_, force) : iterations;
6452   };
6453
6454   force.strength = function(_) {
6455     return arguments.length ? (strength = +_, force) : strength;
6456   };
6457
6458   force.radius = function(_) {
6459     return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
6460   };
6461
6462   return force;
6463 }
6464
6465 function index(d) {
6466   return d.index;
6467 }
6468
6469 function find(nodeById, nodeId) {
6470   var node = nodeById.get(nodeId);
6471   if (!node) throw new Error("missing: " + nodeId);
6472   return node;
6473 }
6474
6475 function link(links) {
6476   var id = index,
6477       strength = defaultStrength,
6478       strengths,
6479       distance = constant$7(30),
6480       distances,
6481       nodes,
6482       count,
6483       bias,
6484       iterations = 1;
6485
6486   if (links == null) links = [];
6487
6488   function defaultStrength(link) {
6489     return 1 / Math.min(count[link.source.index], count[link.target.index]);
6490   }
6491
6492   function force(alpha) {
6493     for (var k = 0, n = links.length; k < iterations; ++k) {
6494       for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
6495         link = links[i], source = link.source, target = link.target;
6496         x = target.x + target.vx - source.x - source.vx || jiggle();
6497         y = target.y + target.vy - source.y - source.vy || jiggle();
6498         l = Math.sqrt(x * x + y * y);
6499         l = (l - distances[i]) / l * alpha * strengths[i];
6500         x *= l, y *= l;
6501         target.vx -= x * (b = bias[i]);
6502         target.vy -= y * b;
6503         source.vx += x * (b = 1 - b);
6504         source.vy += y * b;
6505       }
6506     }
6507   }
6508
6509   function initialize() {
6510     if (!nodes) return;
6511
6512     var i,
6513         n = nodes.length,
6514         m = links.length,
6515         nodeById = map$1(nodes, id),
6516         link;
6517
6518     for (i = 0, count = new Array(n); i < m; ++i) {
6519       link = links[i], link.index = i;
6520       if (typeof link.source !== "object") link.source = find(nodeById, link.source);
6521       if (typeof link.target !== "object") link.target = find(nodeById, link.target);
6522       count[link.source.index] = (count[link.source.index] || 0) + 1;
6523       count[link.target.index] = (count[link.target.index] || 0) + 1;
6524     }
6525
6526     for (i = 0, bias = new Array(m); i < m; ++i) {
6527       link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
6528     }
6529
6530     strengths = new Array(m), initializeStrength();
6531     distances = new Array(m), initializeDistance();
6532   }
6533
6534   function initializeStrength() {
6535     if (!nodes) return;
6536
6537     for (var i = 0, n = links.length; i < n; ++i) {
6538       strengths[i] = +strength(links[i], i, links);
6539     }
6540   }
6541
6542   function initializeDistance() {
6543     if (!nodes) return;
6544
6545     for (var i = 0, n = links.length; i < n; ++i) {
6546       distances[i] = +distance(links[i], i, links);
6547     }
6548   }
6549
6550   force.initialize = function(_) {
6551     nodes = _;
6552     initialize();
6553   };
6554
6555   force.links = function(_) {
6556     return arguments.length ? (links = _, initialize(), force) : links;
6557   };
6558
6559   force.id = function(_) {
6560     return arguments.length ? (id = _, force) : id;
6561   };
6562
6563   force.iterations = function(_) {
6564     return arguments.length ? (iterations = +_, force) : iterations;
6565   };
6566
6567   force.strength = function(_) {
6568     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
6569   };
6570
6571   force.distance = function(_) {
6572     return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
6573   };
6574
6575   return force;
6576 }
6577
6578 function x$1(d) {
6579   return d.x;
6580 }
6581
6582 function y$1(d) {
6583   return d.y;
6584 }
6585
6586 var initialRadius = 10,
6587     initialAngle = Math.PI * (3 - Math.sqrt(5));
6588
6589 function simulation(nodes) {
6590   var simulation,
6591       alpha = 1,
6592       alphaMin = 0.001,
6593       alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
6594       alphaTarget = 0,
6595       velocityDecay = 0.6,
6596       forces = map$1(),
6597       stepper = timer(step),
6598       event = dispatch("tick", "end");
6599
6600   if (nodes == null) nodes = [];
6601
6602   function step() {
6603     tick();
6604     event.call("tick", simulation);
6605     if (alpha < alphaMin) {
6606       stepper.stop();
6607       event.call("end", simulation);
6608     }
6609   }
6610
6611   function tick() {
6612     var i, n = nodes.length, node;
6613
6614     alpha += (alphaTarget - alpha) * alphaDecay;
6615
6616     forces.each(function(force) {
6617       force(alpha);
6618     });
6619
6620     for (i = 0; i < n; ++i) {
6621       node = nodes[i];
6622       if (node.fx == null) node.x += node.vx *= velocityDecay;
6623       else node.x = node.fx, node.vx = 0;
6624       if (node.fy == null) node.y += node.vy *= velocityDecay;
6625       else node.y = node.fy, node.vy = 0;
6626     }
6627   }
6628
6629   function initializeNodes() {
6630     for (var i = 0, n = nodes.length, node; i < n; ++i) {
6631       node = nodes[i], node.index = i;
6632       if (isNaN(node.x) || isNaN(node.y)) {
6633         var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
6634         node.x = radius * Math.cos(angle);
6635         node.y = radius * Math.sin(angle);
6636       }
6637       if (isNaN(node.vx) || isNaN(node.vy)) {
6638         node.vx = node.vy = 0;
6639       }
6640     }
6641   }
6642
6643   function initializeForce(force) {
6644     if (force.initialize) force.initialize(nodes);
6645     return force;
6646   }
6647
6648   initializeNodes();
6649
6650   return simulation = {
6651     tick: tick,
6652
6653     restart: function() {
6654       return stepper.restart(step), simulation;
6655     },
6656
6657     stop: function() {
6658       return stepper.stop(), simulation;
6659     },
6660
6661     nodes: function(_) {
6662       return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
6663     },
6664
6665     alpha: function(_) {
6666       return arguments.length ? (alpha = +_, simulation) : alpha;
6667     },
6668
6669     alphaMin: function(_) {
6670       return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
6671     },
6672
6673     alphaDecay: function(_) {
6674       return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
6675     },
6676
6677     alphaTarget: function(_) {
6678       return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
6679     },
6680
6681     velocityDecay: function(_) {
6682       return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
6683     },
6684
6685     force: function(name, _) {
6686       return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
6687     },
6688
6689     find: function(x, y, radius) {
6690       var i = 0,
6691           n = nodes.length,
6692           dx,
6693           dy,
6694           d2,
6695           node,
6696           closest;
6697
6698       if (radius == null) radius = Infinity;
6699       else radius *= radius;
6700
6701       for (i = 0; i < n; ++i) {
6702         node = nodes[i];
6703         dx = x - node.x;
6704         dy = y - node.y;
6705         d2 = dx * dx + dy * dy;
6706         if (d2 < radius) closest = node, radius = d2;
6707       }
6708
6709       return closest;
6710     },
6711
6712     on: function(name, _) {
6713       return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
6714     }
6715   };
6716 }
6717
6718 function manyBody() {
6719   var nodes,
6720       node,
6721       alpha,
6722       strength = constant$7(-30),
6723       strengths,
6724       distanceMin2 = 1,
6725       distanceMax2 = Infinity,
6726       theta2 = 0.81;
6727
6728   function force(_) {
6729     var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
6730     for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
6731   }
6732
6733   function initialize() {
6734     if (!nodes) return;
6735     var i, n = nodes.length, node;
6736     strengths = new Array(n);
6737     for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
6738   }
6739
6740   function accumulate(quad) {
6741     var strength = 0, q, c, weight = 0, x, y, i;
6742
6743     // For internal nodes, accumulate forces from child quadrants.
6744     if (quad.length) {
6745       for (x = y = i = 0; i < 4; ++i) {
6746         if ((q = quad[i]) && (c = Math.abs(q.value))) {
6747           strength += q.value, weight += c, x += c * q.x, y += c * q.y;
6748         }
6749       }
6750       quad.x = x / weight;
6751       quad.y = y / weight;
6752     }
6753
6754     // For leaf nodes, accumulate forces from coincident quadrants.
6755     else {
6756       q = quad;
6757       q.x = q.data.x;
6758       q.y = q.data.y;
6759       do strength += strengths[q.data.index];
6760       while (q = q.next);
6761     }
6762
6763     quad.value = strength;
6764   }
6765
6766   function apply(quad, x1, _, x2) {
6767     if (!quad.value) return true;
6768
6769     var x = quad.x - node.x,
6770         y = quad.y - node.y,
6771         w = x2 - x1,
6772         l = x * x + y * y;
6773
6774     // Apply the Barnes-Hut approximation if possible.
6775     // Limit forces for very close nodes; randomize direction if coincident.
6776     if (w * w / theta2 < l) {
6777       if (l < distanceMax2) {
6778         if (x === 0) x = jiggle(), l += x * x;
6779         if (y === 0) y = jiggle(), l += y * y;
6780         if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6781         node.vx += x * quad.value * alpha / l;
6782         node.vy += y * quad.value * alpha / l;
6783       }
6784       return true;
6785     }
6786
6787     // Otherwise, process points directly.
6788     else if (quad.length || l >= distanceMax2) return;
6789
6790     // Limit forces for very close nodes; randomize direction if coincident.
6791     if (quad.data !== node || quad.next) {
6792       if (x === 0) x = jiggle(), l += x * x;
6793       if (y === 0) y = jiggle(), l += y * y;
6794       if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6795     }
6796
6797     do if (quad.data !== node) {
6798       w = strengths[quad.data.index] * alpha / l;
6799       node.vx += x * w;
6800       node.vy += y * w;
6801     } while (quad = quad.next);
6802   }
6803
6804   force.initialize = function(_) {
6805     nodes = _;
6806     initialize();
6807   };
6808
6809   force.strength = function(_) {
6810     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6811   };
6812
6813   force.distanceMin = function(_) {
6814     return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
6815   };
6816
6817   force.distanceMax = function(_) {
6818     return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
6819   };
6820
6821   force.theta = function(_) {
6822     return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
6823   };
6824
6825   return force;
6826 }
6827
6828 function radial(radius, x, y) {
6829   var nodes,
6830       strength = constant$7(0.1),
6831       strengths,
6832       radiuses;
6833
6834   if (typeof radius !== "function") radius = constant$7(+radius);
6835   if (x == null) x = 0;
6836   if (y == null) y = 0;
6837
6838   function force(alpha) {
6839     for (var i = 0, n = nodes.length; i < n; ++i) {
6840       var node = nodes[i],
6841           dx = node.x - x || 1e-6,
6842           dy = node.y - y || 1e-6,
6843           r = Math.sqrt(dx * dx + dy * dy),
6844           k = (radiuses[i] - r) * strengths[i] * alpha / r;
6845       node.vx += dx * k;
6846       node.vy += dy * k;
6847     }
6848   }
6849
6850   function initialize() {
6851     if (!nodes) return;
6852     var i, n = nodes.length;
6853     strengths = new Array(n);
6854     radiuses = new Array(n);
6855     for (i = 0; i < n; ++i) {
6856       radiuses[i] = +radius(nodes[i], i, nodes);
6857       strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
6858     }
6859   }
6860
6861   force.initialize = function(_) {
6862     nodes = _, initialize();
6863   };
6864
6865   force.strength = function(_) {
6866     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6867   };
6868
6869   force.radius = function(_) {
6870     return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
6871   };
6872
6873   force.x = function(_) {
6874     return arguments.length ? (x = +_, force) : x;
6875   };
6876
6877   force.y = function(_) {
6878     return arguments.length ? (y = +_, force) : y;
6879   };
6880
6881   return force;
6882 }
6883
6884 function x$2(x) {
6885   var strength = constant$7(0.1),
6886       nodes,
6887       strengths,
6888       xz;
6889
6890   if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
6891
6892   function force(alpha) {
6893     for (var i = 0, n = nodes.length, node; i < n; ++i) {
6894       node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
6895     }
6896   }
6897
6898   function initialize() {
6899     if (!nodes) return;
6900     var i, n = nodes.length;
6901     strengths = new Array(n);
6902     xz = new Array(n);
6903     for (i = 0; i < n; ++i) {
6904       strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6905     }
6906   }
6907
6908   force.initialize = function(_) {
6909     nodes = _;
6910     initialize();
6911   };
6912
6913   force.strength = function(_) {
6914     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6915   };
6916
6917   force.x = function(_) {
6918     return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
6919   };
6920
6921   return force;
6922 }
6923
6924 function y$2(y) {
6925   var strength = constant$7(0.1),
6926       nodes,
6927       strengths,
6928       yz;
6929
6930   if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
6931
6932   function force(alpha) {
6933     for (var i = 0, n = nodes.length, node; i < n; ++i) {
6934       node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
6935     }
6936   }
6937
6938   function initialize() {
6939     if (!nodes) return;
6940     var i, n = nodes.length;
6941     strengths = new Array(n);
6942     yz = new Array(n);
6943     for (i = 0; i < n; ++i) {
6944       strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6945     }
6946   }
6947
6948   force.initialize = function(_) {
6949     nodes = _;
6950     initialize();
6951   };
6952
6953   force.strength = function(_) {
6954     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6955   };
6956
6957   force.y = function(_) {
6958     return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
6959   };
6960
6961   return force;
6962 }
6963
6964 // Computes the decimal coefficient and exponent of the specified number x with
6965 // significant digits p, where x is positive and p is in [1, 21] or undefined.
6966 // For example, formatDecimal(1.23) returns ["123", 0].
6967 function formatDecimal(x, p) {
6968   if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
6969   var i, coefficient = x.slice(0, i);
6970
6971   // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
6972   // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
6973   return [
6974     coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
6975     +x.slice(i + 1)
6976   ];
6977 }
6978
6979 function exponent$1(x) {
6980   return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
6981 }
6982
6983 function formatGroup(grouping, thousands) {
6984   return function(value, width) {
6985     var i = value.length,
6986         t = [],
6987         j = 0,
6988         g = grouping[0],
6989         length = 0;
6990
6991     while (i > 0 && g > 0) {
6992       if (length + g + 1 > width) g = Math.max(1, width - length);
6993       t.push(value.substring(i -= g, i + g));
6994       if ((length += g + 1) > width) break;
6995       g = grouping[j = (j + 1) % grouping.length];
6996     }
6997
6998     return t.reverse().join(thousands);
6999   };
7000 }
7001
7002 function formatNumerals(numerals) {
7003   return function(value) {
7004     return value.replace(/[0-9]/g, function(i) {
7005       return numerals[+i];
7006     });
7007   };
7008 }
7009
7010 // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
7011 var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
7012
7013 function formatSpecifier(specifier) {
7014   return new FormatSpecifier(specifier);
7015 }
7016
7017 formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
7018
7019 function FormatSpecifier(specifier) {
7020   if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
7021   var match;
7022   this.fill = match[1] || " ";
7023   this.align = match[2] || ">";
7024   this.sign = match[3] || "-";
7025   this.symbol = match[4] || "";
7026   this.zero = !!match[5];
7027   this.width = match[6] && +match[6];
7028   this.comma = !!match[7];
7029   this.precision = match[8] && +match[8].slice(1);
7030   this.trim = !!match[9];
7031   this.type = match[10] || "";
7032 }
7033
7034 FormatSpecifier.prototype.toString = function() {
7035   return this.fill
7036       + this.align
7037       + this.sign
7038       + this.symbol
7039       + (this.zero ? "0" : "")
7040       + (this.width == null ? "" : Math.max(1, this.width | 0))
7041       + (this.comma ? "," : "")
7042       + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
7043       + (this.trim ? "~" : "")
7044       + this.type;
7045 };
7046
7047 // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
7048 function formatTrim(s) {
7049   out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
7050     switch (s[i]) {
7051       case ".": i0 = i1 = i; break;
7052       case "0": if (i0 === 0) i0 = i; i1 = i; break;
7053       default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
7054     }
7055   }
7056   return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
7057 }
7058
7059 var prefixExponent;
7060
7061 function formatPrefixAuto(x, p) {
7062   var d = formatDecimal(x, p);
7063   if (!d) return x + "";
7064   var coefficient = d[0],
7065       exponent = d[1],
7066       i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
7067       n = coefficient.length;
7068   return i === n ? coefficient
7069       : i > n ? coefficient + new Array(i - n + 1).join("0")
7070       : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
7071       : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
7072 }
7073
7074 function formatRounded(x, p) {
7075   var d = formatDecimal(x, p);
7076   if (!d) return x + "";
7077   var coefficient = d[0],
7078       exponent = d[1];
7079   return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
7080       : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
7081       : coefficient + new Array(exponent - coefficient.length + 2).join("0");
7082 }
7083
7084 var formatTypes = {
7085   "%": function(x, p) { return (x * 100).toFixed(p); },
7086   "b": function(x) { return Math.round(x).toString(2); },
7087   "c": function(x) { return x + ""; },
7088   "d": function(x) { return Math.round(x).toString(10); },
7089   "e": function(x, p) { return x.toExponential(p); },
7090   "f": function(x, p) { return x.toFixed(p); },
7091   "g": function(x, p) { return x.toPrecision(p); },
7092   "o": function(x) { return Math.round(x).toString(8); },
7093   "p": function(x, p) { return formatRounded(x * 100, p); },
7094   "r": formatRounded,
7095   "s": formatPrefixAuto,
7096   "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
7097   "x": function(x) { return Math.round(x).toString(16); }
7098 };
7099
7100 function identity$3(x) {
7101   return x;
7102 }
7103
7104 var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
7105
7106 function formatLocale(locale) {
7107   var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
7108       currency = locale.currency,
7109       decimal = locale.decimal,
7110       numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
7111       percent = locale.percent || "%";
7112
7113   function newFormat(specifier) {
7114     specifier = formatSpecifier(specifier);
7115
7116     var fill = specifier.fill,
7117         align = specifier.align,
7118         sign = specifier.sign,
7119         symbol = specifier.symbol,
7120         zero = specifier.zero,
7121         width = specifier.width,
7122         comma = specifier.comma,
7123         precision = specifier.precision,
7124         trim = specifier.trim,
7125         type = specifier.type;
7126
7127     // The "n" type is an alias for ",g".
7128     if (type === "n") comma = true, type = "g";
7129
7130     // The "" type, and any invalid type, is an alias for ".12~g".
7131     else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
7132
7133     // If zero fill is specified, padding goes after sign and before digits.
7134     if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
7135
7136     // Compute the prefix and suffix.
7137     // For SI-prefix, the suffix is lazily computed.
7138     var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
7139         suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
7140
7141     // What format function should we use?
7142     // Is this an integer type?
7143     // Can this type generate exponential notation?
7144     var formatType = formatTypes[type],
7145         maybeSuffix = /[defgprs%]/.test(type);
7146
7147     // Set the default precision if not specified,
7148     // or clamp the specified precision to the supported range.
7149     // For significant precision, it must be in [1, 21].
7150     // For fixed precision, it must be in [0, 20].
7151     precision = precision == null ? 6
7152         : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
7153         : Math.max(0, Math.min(20, precision));
7154
7155     function format(value) {
7156       var valuePrefix = prefix,
7157           valueSuffix = suffix,
7158           i, n, c;
7159
7160       if (type === "c") {
7161         valueSuffix = formatType(value) + valueSuffix;
7162         value = "";
7163       } else {
7164         value = +value;
7165
7166         // Perform the initial formatting.
7167         var valueNegative = value < 0;
7168         value = formatType(Math.abs(value), precision);
7169
7170         // Trim insignificant zeros.
7171         if (trim) value = formatTrim(value);
7172
7173         // If a negative value rounds to zero during formatting, treat as positive.
7174         if (valueNegative && +value === 0) valueNegative = false;
7175
7176         // Compute the prefix and suffix.
7177         valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
7178         valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
7179
7180         // Break the formatted value into the integer “value” part that can be
7181         // grouped, and fractional or exponential “suffix” part that is not.
7182         if (maybeSuffix) {
7183           i = -1, n = value.length;
7184           while (++i < n) {
7185             if (c = value.charCodeAt(i), 48 > c || c > 57) {
7186               valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
7187               value = value.slice(0, i);
7188               break;
7189             }
7190           }
7191         }
7192       }
7193
7194       // If the fill character is not "0", grouping is applied before padding.
7195       if (comma && !zero) value = group(value, Infinity);
7196
7197       // Compute the padding.
7198       var length = valuePrefix.length + value.length + valueSuffix.length,
7199           padding = length < width ? new Array(width - length + 1).join(fill) : "";
7200
7201       // If the fill character is "0", grouping is applied after padding.
7202       if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
7203
7204       // Reconstruct the final output based on the desired alignment.
7205       switch (align) {
7206         case "<": value = valuePrefix + value + valueSuffix + padding; break;
7207         case "=": value = valuePrefix + padding + value + valueSuffix; break;
7208         case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
7209         default: value = padding + valuePrefix + value + valueSuffix; break;
7210       }
7211
7212       return numerals(value);
7213     }
7214
7215     format.toString = function() {
7216       return specifier + "";
7217     };
7218
7219     return format;
7220   }
7221
7222   function formatPrefix(specifier, value) {
7223     var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
7224         e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
7225         k = Math.pow(10, -e),
7226         prefix = prefixes[8 + e / 3];
7227     return function(value) {
7228       return f(k * value) + prefix;
7229     };
7230   }
7231
7232   return {
7233     format: newFormat,
7234     formatPrefix: formatPrefix
7235   };
7236 }
7237
7238 var locale;
7239
7240 defaultLocale({
7241   decimal: ".",
7242   thousands: ",",
7243   grouping: [3],
7244   currency: ["$", ""]
7245 });
7246
7247 function defaultLocale(definition) {
7248   locale = formatLocale(definition);
7249   exports.format = locale.format;
7250   exports.formatPrefix = locale.formatPrefix;
7251   return locale;
7252 }
7253
7254 function precisionFixed(step) {
7255   return Math.max(0, -exponent$1(Math.abs(step)));
7256 }
7257
7258 function precisionPrefix(step, value) {
7259   return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
7260 }
7261
7262 function precisionRound(step, max) {
7263   step = Math.abs(step), max = Math.abs(max) - step;
7264   return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
7265 }
7266
7267 // Adds floating point numbers with twice the normal precision.
7268 // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
7269 // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
7270 // 305–363 (1997).
7271 // Code adapted from GeographicLib by Charles F. F. Karney,
7272 // http://geographiclib.sourceforge.net/
7273
7274 function adder() {
7275   return new Adder;
7276 }
7277
7278 function Adder() {
7279   this.reset();
7280 }
7281
7282 Adder.prototype = {
7283   constructor: Adder,
7284   reset: function() {
7285     this.s = // rounded value
7286     this.t = 0; // exact error
7287   },
7288   add: function(y) {
7289     add$1(temp, y, this.t);
7290     add$1(this, temp.s, this.s);
7291     if (this.s) this.t += temp.t;
7292     else this.s = temp.t;
7293   },
7294   valueOf: function() {
7295     return this.s;
7296   }
7297 };
7298
7299 var temp = new Adder;
7300
7301 function add$1(adder, a, b) {
7302   var x = adder.s = a + b,
7303       bv = x - a,
7304       av = x - bv;
7305   adder.t = (a - av) + (b - bv);
7306 }
7307
7308 var epsilon$2 = 1e-6;
7309 var epsilon2$1 = 1e-12;
7310 var pi$3 = Math.PI;
7311 var halfPi$2 = pi$3 / 2;
7312 var quarterPi = pi$3 / 4;
7313 var tau$3 = pi$3 * 2;
7314
7315 var degrees$1 = 180 / pi$3;
7316 var radians = pi$3 / 180;
7317
7318 var abs = Math.abs;
7319 var atan = Math.atan;
7320 var atan2 = Math.atan2;
7321 var cos$1 = Math.cos;
7322 var ceil = Math.ceil;
7323 var exp = Math.exp;
7324 var log = Math.log;
7325 var pow = Math.pow;
7326 var sin$1 = Math.sin;
7327 var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
7328 var sqrt = Math.sqrt;
7329 var tan = Math.tan;
7330
7331 function acos(x) {
7332   return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
7333 }
7334
7335 function asin(x) {
7336   return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
7337 }
7338
7339 function haversin(x) {
7340   return (x = sin$1(x / 2)) * x;
7341 }
7342
7343 function noop$2() {}
7344
7345 function streamGeometry(geometry, stream) {
7346   if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
7347     streamGeometryType[geometry.type](geometry, stream);
7348   }
7349 }
7350
7351 var streamObjectType = {
7352   Feature: function(object, stream) {
7353     streamGeometry(object.geometry, stream);
7354   },
7355   FeatureCollection: function(object, stream) {
7356     var features = object.features, i = -1, n = features.length;
7357     while (++i < n) streamGeometry(features[i].geometry, stream);
7358   }
7359 };
7360
7361 var streamGeometryType = {
7362   Sphere: function(object, stream) {
7363     stream.sphere();
7364   },
7365   Point: function(object, stream) {
7366     object = object.coordinates;
7367     stream.point(object[0], object[1], object[2]);
7368   },
7369   MultiPoint: function(object, stream) {
7370     var coordinates = object.coordinates, i = -1, n = coordinates.length;
7371     while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
7372   },
7373   LineString: function(object, stream) {
7374     streamLine(object.coordinates, stream, 0);
7375   },
7376   MultiLineString: function(object, stream) {
7377     var coordinates = object.coordinates, i = -1, n = coordinates.length;
7378     while (++i < n) streamLine(coordinates[i], stream, 0);
7379   },
7380   Polygon: function(object, stream) {
7381     streamPolygon(object.coordinates, stream);
7382   },
7383   MultiPolygon: function(object, stream) {
7384     var coordinates = object.coordinates, i = -1, n = coordinates.length;
7385     while (++i < n) streamPolygon(coordinates[i], stream);
7386   },
7387   GeometryCollection: function(object, stream) {
7388     var geometries = object.geometries, i = -1, n = geometries.length;
7389     while (++i < n) streamGeometry(geometries[i], stream);
7390   }
7391 };
7392
7393 function streamLine(coordinates, stream, closed) {
7394   var i = -1, n = coordinates.length - closed, coordinate;
7395   stream.lineStart();
7396   while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
7397   stream.lineEnd();
7398 }
7399
7400 function streamPolygon(coordinates, stream) {
7401   var i = -1, n = coordinates.length;
7402   stream.polygonStart();
7403   while (++i < n) streamLine(coordinates[i], stream, 1);
7404   stream.polygonEnd();
7405 }
7406
7407 function geoStream(object, stream) {
7408   if (object && streamObjectType.hasOwnProperty(object.type)) {
7409     streamObjectType[object.type](object, stream);
7410   } else {
7411     streamGeometry(object, stream);
7412   }
7413 }
7414
7415 var areaRingSum = adder();
7416
7417 var areaSum = adder(),
7418     lambda00,
7419     phi00,
7420     lambda0,
7421     cosPhi0,
7422     sinPhi0;
7423
7424 var areaStream = {
7425   point: noop$2,
7426   lineStart: noop$2,
7427   lineEnd: noop$2,
7428   polygonStart: function() {
7429     areaRingSum.reset();
7430     areaStream.lineStart = areaRingStart;
7431     areaStream.lineEnd = areaRingEnd;
7432   },
7433   polygonEnd: function() {
7434     var areaRing = +areaRingSum;
7435     areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
7436     this.lineStart = this.lineEnd = this.point = noop$2;
7437   },
7438   sphere: function() {
7439     areaSum.add(tau$3);
7440   }
7441 };
7442
7443 function areaRingStart() {
7444   areaStream.point = areaPointFirst;
7445 }
7446
7447 function areaRingEnd() {
7448   areaPoint(lambda00, phi00);
7449 }
7450
7451 function areaPointFirst(lambda, phi) {
7452   areaStream.point = areaPoint;
7453   lambda00 = lambda, phi00 = phi;
7454   lambda *= radians, phi *= radians;
7455   lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
7456 }
7457
7458 function areaPoint(lambda, phi) {
7459   lambda *= radians, phi *= radians;
7460   phi = phi / 2 + quarterPi; // half the angular distance from south pole
7461
7462   // Spherical excess E for a spherical triangle with vertices: south pole,
7463   // previous point, current point.  Uses a formula derived from Cagnoli’s
7464   // theorem.  See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
7465   var dLambda = lambda - lambda0,
7466       sdLambda = dLambda >= 0 ? 1 : -1,
7467       adLambda = sdLambda * dLambda,
7468       cosPhi = cos$1(phi),
7469       sinPhi = sin$1(phi),
7470       k = sinPhi0 * sinPhi,
7471       u = cosPhi0 * cosPhi + k * cos$1(adLambda),
7472       v = k * sdLambda * sin$1(adLambda);
7473   areaRingSum.add(atan2(v, u));
7474
7475   // Advance the previous points.
7476   lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
7477 }
7478
7479 function area$1(object) {
7480   areaSum.reset();
7481   geoStream(object, areaStream);
7482   return areaSum * 2;
7483 }
7484
7485 function spherical(cartesian) {
7486   return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
7487 }
7488
7489 function cartesian(spherical) {
7490   var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
7491   return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
7492 }
7493
7494 function cartesianDot(a, b) {
7495   return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
7496 }
7497
7498 function cartesianCross(a, b) {
7499   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]];
7500 }
7501
7502 // TODO return a
7503 function cartesianAddInPlace(a, b) {
7504   a[0] += b[0], a[1] += b[1], a[2] += b[2];
7505 }
7506
7507 function cartesianScale(vector, k) {
7508   return [vector[0] * k, vector[1] * k, vector[2] * k];
7509 }
7510
7511 // TODO return d
7512 function cartesianNormalizeInPlace(d) {
7513   var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
7514   d[0] /= l, d[1] /= l, d[2] /= l;
7515 }
7516
7517 var lambda0$1, phi0, lambda1, phi1, // bounds
7518     lambda2, // previous lambda-coordinate
7519     lambda00$1, phi00$1, // first point
7520     p0, // previous 3D point
7521     deltaSum = adder(),
7522     ranges,
7523     range;
7524
7525 var boundsStream = {
7526   point: boundsPoint,
7527   lineStart: boundsLineStart,
7528   lineEnd: boundsLineEnd,
7529   polygonStart: function() {
7530     boundsStream.point = boundsRingPoint;
7531     boundsStream.lineStart = boundsRingStart;
7532     boundsStream.lineEnd = boundsRingEnd;
7533     deltaSum.reset();
7534     areaStream.polygonStart();
7535   },
7536   polygonEnd: function() {
7537     areaStream.polygonEnd();
7538     boundsStream.point = boundsPoint;
7539     boundsStream.lineStart = boundsLineStart;
7540     boundsStream.lineEnd = boundsLineEnd;
7541     if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
7542     else if (deltaSum > epsilon$2) phi1 = 90;
7543     else if (deltaSum < -epsilon$2) phi0 = -90;
7544     range[0] = lambda0$1, range[1] = lambda1;
7545   }
7546 };
7547
7548 function boundsPoint(lambda, phi) {
7549   ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7550   if (phi < phi0) phi0 = phi;
7551   if (phi > phi1) phi1 = phi;
7552 }
7553
7554 function linePoint(lambda, phi) {
7555   var p = cartesian([lambda * radians, phi * radians]);
7556   if (p0) {
7557     var normal = cartesianCross(p0, p),
7558         equatorial = [normal[1], -normal[0], 0],
7559         inflection = cartesianCross(equatorial, normal);
7560     cartesianNormalizeInPlace(inflection);
7561     inflection = spherical(inflection);
7562     var delta = lambda - lambda2,
7563         sign$$1 = delta > 0 ? 1 : -1,
7564         lambdai = inflection[0] * degrees$1 * sign$$1,
7565         phii,
7566         antimeridian = abs(delta) > 180;
7567     if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7568       phii = inflection[1] * degrees$1;
7569       if (phii > phi1) phi1 = phii;
7570     } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7571       phii = -inflection[1] * degrees$1;
7572       if (phii < phi0) phi0 = phii;
7573     } else {
7574       if (phi < phi0) phi0 = phi;
7575       if (phi > phi1) phi1 = phi;
7576     }
7577     if (antimeridian) {
7578       if (lambda < lambda2) {
7579         if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7580       } else {
7581         if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7582       }
7583     } else {
7584       if (lambda1 >= lambda0$1) {
7585         if (lambda < lambda0$1) lambda0$1 = lambda;
7586         if (lambda > lambda1) lambda1 = lambda;
7587       } else {
7588         if (lambda > lambda2) {
7589           if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7590         } else {
7591           if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7592         }
7593       }
7594     }
7595   } else {
7596     ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7597   }
7598   if (phi < phi0) phi0 = phi;
7599   if (phi > phi1) phi1 = phi;
7600   p0 = p, lambda2 = lambda;
7601 }
7602
7603 function boundsLineStart() {
7604   boundsStream.point = linePoint;
7605 }
7606
7607 function boundsLineEnd() {
7608   range[0] = lambda0$1, range[1] = lambda1;
7609   boundsStream.point = boundsPoint;
7610   p0 = null;
7611 }
7612
7613 function boundsRingPoint(lambda, phi) {
7614   if (p0) {
7615     var delta = lambda - lambda2;
7616     deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
7617   } else {
7618     lambda00$1 = lambda, phi00$1 = phi;
7619   }
7620   areaStream.point(lambda, phi);
7621   linePoint(lambda, phi);
7622 }
7623
7624 function boundsRingStart() {
7625   areaStream.lineStart();
7626 }
7627
7628 function boundsRingEnd() {
7629   boundsRingPoint(lambda00$1, phi00$1);
7630   areaStream.lineEnd();
7631   if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
7632   range[0] = lambda0$1, range[1] = lambda1;
7633   p0 = null;
7634 }
7635
7636 // Finds the left-right distance between two longitudes.
7637 // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
7638 // the distance between ±180° to be 360°.
7639 function angle(lambda0, lambda1) {
7640   return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
7641 }
7642
7643 function rangeCompare(a, b) {
7644   return a[0] - b[0];
7645 }
7646
7647 function rangeContains(range, x) {
7648   return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
7649 }
7650
7651 function bounds(feature) {
7652   var i, n, a, b, merged, deltaMax, delta;
7653
7654   phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
7655   ranges = [];
7656   geoStream(feature, boundsStream);
7657
7658   // First, sort ranges by their minimum longitudes.
7659   if (n = ranges.length) {
7660     ranges.sort(rangeCompare);
7661
7662     // Then, merge any ranges that overlap.
7663     for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
7664       b = ranges[i];
7665       if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
7666         if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
7667         if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
7668       } else {
7669         merged.push(a = b);
7670       }
7671     }
7672
7673     // Finally, find the largest gap between the merged ranges.
7674     // The final bounding box will be the inverse of this gap.
7675     for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
7676       b = merged[i];
7677       if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
7678     }
7679   }
7680
7681   ranges = range = null;
7682
7683   return lambda0$1 === Infinity || phi0 === Infinity
7684       ? [[NaN, NaN], [NaN, NaN]]
7685       : [[lambda0$1, phi0], [lambda1, phi1]];
7686 }
7687
7688 var W0, W1,
7689     X0, Y0, Z0,
7690     X1, Y1, Z1,
7691     X2, Y2, Z2,
7692     lambda00$2, phi00$2, // first point
7693     x0, y0, z0; // previous point
7694
7695 var centroidStream = {
7696   sphere: noop$2,
7697   point: centroidPoint,
7698   lineStart: centroidLineStart,
7699   lineEnd: centroidLineEnd,
7700   polygonStart: function() {
7701     centroidStream.lineStart = centroidRingStart;
7702     centroidStream.lineEnd = centroidRingEnd;
7703   },
7704   polygonEnd: function() {
7705     centroidStream.lineStart = centroidLineStart;
7706     centroidStream.lineEnd = centroidLineEnd;
7707   }
7708 };
7709
7710 // Arithmetic mean of Cartesian vectors.
7711 function centroidPoint(lambda, phi) {
7712   lambda *= radians, phi *= radians;
7713   var cosPhi = cos$1(phi);
7714   centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
7715 }
7716
7717 function centroidPointCartesian(x, y, z) {
7718   ++W0;
7719   X0 += (x - X0) / W0;
7720   Y0 += (y - Y0) / W0;
7721   Z0 += (z - Z0) / W0;
7722 }
7723
7724 function centroidLineStart() {
7725   centroidStream.point = centroidLinePointFirst;
7726 }
7727
7728 function centroidLinePointFirst(lambda, phi) {
7729   lambda *= radians, phi *= radians;
7730   var cosPhi = cos$1(phi);
7731   x0 = cosPhi * cos$1(lambda);
7732   y0 = cosPhi * sin$1(lambda);
7733   z0 = sin$1(phi);
7734   centroidStream.point = centroidLinePoint;
7735   centroidPointCartesian(x0, y0, z0);
7736 }
7737
7738 function centroidLinePoint(lambda, phi) {
7739   lambda *= radians, phi *= radians;
7740   var cosPhi = cos$1(phi),
7741       x = cosPhi * cos$1(lambda),
7742       y = cosPhi * sin$1(lambda),
7743       z = sin$1(phi),
7744       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);
7745   W1 += w;
7746   X1 += w * (x0 + (x0 = x));
7747   Y1 += w * (y0 + (y0 = y));
7748   Z1 += w * (z0 + (z0 = z));
7749   centroidPointCartesian(x0, y0, z0);
7750 }
7751
7752 function centroidLineEnd() {
7753   centroidStream.point = centroidPoint;
7754 }
7755
7756 // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
7757 // J. Applied Mechanics 42, 239 (1975).
7758 function centroidRingStart() {
7759   centroidStream.point = centroidRingPointFirst;
7760 }
7761
7762 function centroidRingEnd() {
7763   centroidRingPoint(lambda00$2, phi00$2);
7764   centroidStream.point = centroidPoint;
7765 }
7766
7767 function centroidRingPointFirst(lambda, phi) {
7768   lambda00$2 = lambda, phi00$2 = phi;
7769   lambda *= radians, phi *= radians;
7770   centroidStream.point = centroidRingPoint;
7771   var cosPhi = cos$1(phi);
7772   x0 = cosPhi * cos$1(lambda);
7773   y0 = cosPhi * sin$1(lambda);
7774   z0 = sin$1(phi);
7775   centroidPointCartesian(x0, y0, z0);
7776 }
7777
7778 function centroidRingPoint(lambda, phi) {
7779   lambda *= radians, phi *= radians;
7780   var cosPhi = cos$1(phi),
7781       x = cosPhi * cos$1(lambda),
7782       y = cosPhi * sin$1(lambda),
7783       z = sin$1(phi),
7784       cx = y0 * z - z0 * y,
7785       cy = z0 * x - x0 * z,
7786       cz = x0 * y - y0 * x,
7787       m = sqrt(cx * cx + cy * cy + cz * cz),
7788       w = asin(m), // line weight = angle
7789       v = m && -w / m; // area weight multiplier
7790   X2 += v * cx;
7791   Y2 += v * cy;
7792   Z2 += v * cz;
7793   W1 += w;
7794   X1 += w * (x0 + (x0 = x));
7795   Y1 += w * (y0 + (y0 = y));
7796   Z1 += w * (z0 + (z0 = z));
7797   centroidPointCartesian(x0, y0, z0);
7798 }
7799
7800 function centroid(object) {
7801   W0 = W1 =
7802   X0 = Y0 = Z0 =
7803   X1 = Y1 = Z1 =
7804   X2 = Y2 = Z2 = 0;
7805   geoStream(object, centroidStream);
7806
7807   var x = X2,
7808       y = Y2,
7809       z = Z2,
7810       m = x * x + y * y + z * z;
7811
7812   // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
7813   if (m < epsilon2$1) {
7814     x = X1, y = Y1, z = Z1;
7815     // If the feature has zero length, fall back to arithmetic mean of point vectors.
7816     if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
7817     m = x * x + y * y + z * z;
7818     // If the feature still has an undefined ccentroid, then return.
7819     if (m < epsilon2$1) return [NaN, NaN];
7820   }
7821
7822   return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
7823 }
7824
7825 function constant$8(x) {
7826   return function() {
7827     return x;
7828   };
7829 }
7830
7831 function compose(a, b) {
7832
7833   function compose(x, y) {
7834     return x = a(x, y), b(x[0], x[1]);
7835   }
7836
7837   if (a.invert && b.invert) compose.invert = function(x, y) {
7838     return x = b.invert(x, y), x && a.invert(x[0], x[1]);
7839   };
7840
7841   return compose;
7842 }
7843
7844 function rotationIdentity(lambda, phi) {
7845   return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7846 }
7847
7848 rotationIdentity.invert = rotationIdentity;
7849
7850 function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
7851   return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
7852     : rotationLambda(deltaLambda))
7853     : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
7854     : rotationIdentity);
7855 }
7856
7857 function forwardRotationLambda(deltaLambda) {
7858   return function(lambda, phi) {
7859     return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7860   };
7861 }
7862
7863 function rotationLambda(deltaLambda) {
7864   var rotation = forwardRotationLambda(deltaLambda);
7865   rotation.invert = forwardRotationLambda(-deltaLambda);
7866   return rotation;
7867 }
7868
7869 function rotationPhiGamma(deltaPhi, deltaGamma) {
7870   var cosDeltaPhi = cos$1(deltaPhi),
7871       sinDeltaPhi = sin$1(deltaPhi),
7872       cosDeltaGamma = cos$1(deltaGamma),
7873       sinDeltaGamma = sin$1(deltaGamma);
7874
7875   function rotation(lambda, phi) {
7876     var cosPhi = cos$1(phi),
7877         x = cos$1(lambda) * cosPhi,
7878         y = sin$1(lambda) * cosPhi,
7879         z = sin$1(phi),
7880         k = z * cosDeltaPhi + x * sinDeltaPhi;
7881     return [
7882       atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
7883       asin(k * cosDeltaGamma + y * sinDeltaGamma)
7884     ];
7885   }
7886
7887   rotation.invert = function(lambda, phi) {
7888     var cosPhi = cos$1(phi),
7889         x = cos$1(lambda) * cosPhi,
7890         y = sin$1(lambda) * cosPhi,
7891         z = sin$1(phi),
7892         k = z * cosDeltaGamma - y * sinDeltaGamma;
7893     return [
7894       atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
7895       asin(k * cosDeltaPhi - x * sinDeltaPhi)
7896     ];
7897   };
7898
7899   return rotation;
7900 }
7901
7902 function rotation(rotate) {
7903   rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
7904
7905   function forward(coordinates) {
7906     coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
7907     return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7908   }
7909
7910   forward.invert = function(coordinates) {
7911     coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
7912     return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7913   };
7914
7915   return forward;
7916 }
7917
7918 // Generates a circle centered at [0°, 0°], with a given radius and precision.
7919 function circleStream(stream, radius, delta, direction, t0, t1) {
7920   if (!delta) return;
7921   var cosRadius = cos$1(radius),
7922       sinRadius = sin$1(radius),
7923       step = direction * delta;
7924   if (t0 == null) {
7925     t0 = radius + direction * tau$3;
7926     t1 = radius - step / 2;
7927   } else {
7928     t0 = circleRadius(cosRadius, t0);
7929     t1 = circleRadius(cosRadius, t1);
7930     if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
7931   }
7932   for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
7933     point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
7934     stream.point(point[0], point[1]);
7935   }
7936 }
7937
7938 // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
7939 function circleRadius(cosRadius, point) {
7940   point = cartesian(point), point[0] -= cosRadius;
7941   cartesianNormalizeInPlace(point);
7942   var radius = acos(-point[1]);
7943   return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
7944 }
7945
7946 function circle() {
7947   var center = constant$8([0, 0]),
7948       radius = constant$8(90),
7949       precision = constant$8(6),
7950       ring,
7951       rotate,
7952       stream = {point: point};
7953
7954   function point(x, y) {
7955     ring.push(x = rotate(x, y));
7956     x[0] *= degrees$1, x[1] *= degrees$1;
7957   }
7958
7959   function circle() {
7960     var c = center.apply(this, arguments),
7961         r = radius.apply(this, arguments) * radians,
7962         p = precision.apply(this, arguments) * radians;
7963     ring = [];
7964     rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
7965     circleStream(stream, r, p, 1);
7966     c = {type: "Polygon", coordinates: [ring]};
7967     ring = rotate = null;
7968     return c;
7969   }
7970
7971   circle.center = function(_) {
7972     return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
7973   };
7974
7975   circle.radius = function(_) {
7976     return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
7977   };
7978
7979   circle.precision = function(_) {
7980     return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
7981   };
7982
7983   return circle;
7984 }
7985
7986 function clipBuffer() {
7987   var lines = [],
7988       line;
7989   return {
7990     point: function(x, y) {
7991       line.push([x, y]);
7992     },
7993     lineStart: function() {
7994       lines.push(line = []);
7995     },
7996     lineEnd: noop$2,
7997     rejoin: function() {
7998       if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
7999     },
8000     result: function() {
8001       var result = lines;
8002       lines = [];
8003       line = null;
8004       return result;
8005     }
8006   };
8007 }
8008
8009 function pointEqual(a, b) {
8010   return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
8011 }
8012
8013 function Intersection(point, points, other, entry) {
8014   this.x = point;
8015   this.z = points;
8016   this.o = other; // another intersection
8017   this.e = entry; // is an entry?
8018   this.v = false; // visited
8019   this.n = this.p = null; // next & previous
8020 }
8021
8022 // A generalized polygon clipping algorithm: given a polygon that has been cut
8023 // into its visible line segments, and rejoins the segments by interpolating
8024 // along the clip edge.
8025 function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
8026   var subject = [],
8027       clip = [],
8028       i,
8029       n;
8030
8031   segments.forEach(function(segment) {
8032     if ((n = segment.length - 1) <= 0) return;
8033     var n, p0 = segment[0], p1 = segment[n], x;
8034
8035     // If the first and last points of a segment are coincident, then treat as a
8036     // closed ring. TODO if all rings are closed, then the winding order of the
8037     // exterior ring should be checked.
8038     if (pointEqual(p0, p1)) {
8039       stream.lineStart();
8040       for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
8041       stream.lineEnd();
8042       return;
8043     }
8044
8045     subject.push(x = new Intersection(p0, segment, null, true));
8046     clip.push(x.o = new Intersection(p0, null, x, false));
8047     subject.push(x = new Intersection(p1, segment, null, false));
8048     clip.push(x.o = new Intersection(p1, null, x, true));
8049   });
8050
8051   if (!subject.length) return;
8052
8053   clip.sort(compareIntersection);
8054   link$1(subject);
8055   link$1(clip);
8056
8057   for (i = 0, n = clip.length; i < n; ++i) {
8058     clip[i].e = startInside = !startInside;
8059   }
8060
8061   var start = subject[0],
8062       points,
8063       point;
8064
8065   while (1) {
8066     // Find first unvisited intersection.
8067     var current = start,
8068         isSubject = true;
8069     while (current.v) if ((current = current.n) === start) return;
8070     points = current.z;
8071     stream.lineStart();
8072     do {
8073       current.v = current.o.v = true;
8074       if (current.e) {
8075         if (isSubject) {
8076           for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
8077         } else {
8078           interpolate(current.x, current.n.x, 1, stream);
8079         }
8080         current = current.n;
8081       } else {
8082         if (isSubject) {
8083           points = current.p.z;
8084           for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
8085         } else {
8086           interpolate(current.x, current.p.x, -1, stream);
8087         }
8088         current = current.p;
8089       }
8090       current = current.o;
8091       points = current.z;
8092       isSubject = !isSubject;
8093     } while (!current.v);
8094     stream.lineEnd();
8095   }
8096 }
8097
8098 function link$1(array) {
8099   if (!(n = array.length)) return;
8100   var n,
8101       i = 0,
8102       a = array[0],
8103       b;
8104   while (++i < n) {
8105     a.n = b = array[i];
8106     b.p = a;
8107     a = b;
8108   }
8109   a.n = b = array[0];
8110   b.p = a;
8111 }
8112
8113 var sum$1 = adder();
8114
8115 function polygonContains(polygon, point) {
8116   var lambda = point[0],
8117       phi = point[1],
8118       sinPhi = sin$1(phi),
8119       normal = [sin$1(lambda), -cos$1(lambda), 0],
8120       angle = 0,
8121       winding = 0;
8122
8123   sum$1.reset();
8124
8125   if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
8126   else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
8127
8128   for (var i = 0, n = polygon.length; i < n; ++i) {
8129     if (!(m = (ring = polygon[i]).length)) continue;
8130     var ring,
8131         m,
8132         point0 = ring[m - 1],
8133         lambda0 = point0[0],
8134         phi0 = point0[1] / 2 + quarterPi,
8135         sinPhi0 = sin$1(phi0),
8136         cosPhi0 = cos$1(phi0);
8137
8138     for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
8139       var point1 = ring[j],
8140           lambda1 = point1[0],
8141           phi1 = point1[1] / 2 + quarterPi,
8142           sinPhi1 = sin$1(phi1),
8143           cosPhi1 = cos$1(phi1),
8144           delta = lambda1 - lambda0,
8145           sign$$1 = delta >= 0 ? 1 : -1,
8146           absDelta = sign$$1 * delta,
8147           antimeridian = absDelta > pi$3,
8148           k = sinPhi0 * sinPhi1;
8149
8150       sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
8151       angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
8152
8153       // Are the longitudes either side of the point’s meridian (lambda),
8154       // and are the latitudes smaller than the parallel (phi)?
8155       if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
8156         var arc = cartesianCross(cartesian(point0), cartesian(point1));
8157         cartesianNormalizeInPlace(arc);
8158         var intersection = cartesianCross(normal, arc);
8159         cartesianNormalizeInPlace(intersection);
8160         var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
8161         if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
8162           winding += antimeridian ^ delta >= 0 ? 1 : -1;
8163         }
8164       }
8165     }
8166   }
8167
8168   // First, determine whether the South pole is inside or outside:
8169   //
8170   // It is inside if:
8171   // * the polygon winds around it in a clockwise direction.
8172   // * the polygon does not (cumulatively) wind around it, but has a negative
8173   //   (counter-clockwise) area.
8174   //
8175   // Second, count the (signed) number of times a segment crosses a lambda
8176   // from the point to the South pole.  If it is zero, then the point is the
8177   // same side as the South pole.
8178
8179   return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
8180 }
8181
8182 function clip(pointVisible, clipLine, interpolate, start) {
8183   return function(sink) {
8184     var line = clipLine(sink),
8185         ringBuffer = clipBuffer(),
8186         ringSink = clipLine(ringBuffer),
8187         polygonStarted = false,
8188         polygon,
8189         segments,
8190         ring;
8191
8192     var clip = {
8193       point: point,
8194       lineStart: lineStart,
8195       lineEnd: lineEnd,
8196       polygonStart: function() {
8197         clip.point = pointRing;
8198         clip.lineStart = ringStart;
8199         clip.lineEnd = ringEnd;
8200         segments = [];
8201         polygon = [];
8202       },
8203       polygonEnd: function() {
8204         clip.point = point;
8205         clip.lineStart = lineStart;
8206         clip.lineEnd = lineEnd;
8207         segments = merge(segments);
8208         var startInside = polygonContains(polygon, start);
8209         if (segments.length) {
8210           if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8211           clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
8212         } else if (startInside) {
8213           if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8214           sink.lineStart();
8215           interpolate(null, null, 1, sink);
8216           sink.lineEnd();
8217         }
8218         if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
8219         segments = polygon = null;
8220       },
8221       sphere: function() {
8222         sink.polygonStart();
8223         sink.lineStart();
8224         interpolate(null, null, 1, sink);
8225         sink.lineEnd();
8226         sink.polygonEnd();
8227       }
8228     };
8229
8230     function point(lambda, phi) {
8231       if (pointVisible(lambda, phi)) sink.point(lambda, phi);
8232     }
8233
8234     function pointLine(lambda, phi) {
8235       line.point(lambda, phi);
8236     }
8237
8238     function lineStart() {
8239       clip.point = pointLine;
8240       line.lineStart();
8241     }
8242
8243     function lineEnd() {
8244       clip.point = point;
8245       line.lineEnd();
8246     }
8247
8248     function pointRing(lambda, phi) {
8249       ring.push([lambda, phi]);
8250       ringSink.point(lambda, phi);
8251     }
8252
8253     function ringStart() {
8254       ringSink.lineStart();
8255       ring = [];
8256     }
8257
8258     function ringEnd() {
8259       pointRing(ring[0][0], ring[0][1]);
8260       ringSink.lineEnd();
8261
8262       var clean = ringSink.clean(),
8263           ringSegments = ringBuffer.result(),
8264           i, n = ringSegments.length, m,
8265           segment,
8266           point;
8267
8268       ring.pop();
8269       polygon.push(ring);
8270       ring = null;
8271
8272       if (!n) return;
8273
8274       // No intersections.
8275       if (clean & 1) {
8276         segment = ringSegments[0];
8277         if ((m = segment.length - 1) > 0) {
8278           if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8279           sink.lineStart();
8280           for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
8281           sink.lineEnd();
8282         }
8283         return;
8284       }
8285
8286       // Rejoin connected segments.
8287       // TODO reuse ringBuffer.rejoin()?
8288       if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
8289
8290       segments.push(ringSegments.filter(validSegment));
8291     }
8292
8293     return clip;
8294   };
8295 }
8296
8297 function validSegment(segment) {
8298   return segment.length > 1;
8299 }
8300
8301 // Intersections are sorted along the clip edge. For both antimeridian cutting
8302 // and circle clipping, the same comparison is used.
8303 function compareIntersection(a, b) {
8304   return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
8305        - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
8306 }
8307
8308 var clipAntimeridian = clip(
8309   function() { return true; },
8310   clipAntimeridianLine,
8311   clipAntimeridianInterpolate,
8312   [-pi$3, -halfPi$2]
8313 );
8314
8315 // Takes a line and cuts into visible segments. Return values: 0 - there were
8316 // intersections or the line was empty; 1 - no intersections; 2 - there were
8317 // intersections, and the first and last segments should be rejoined.
8318 function clipAntimeridianLine(stream) {
8319   var lambda0 = NaN,
8320       phi0 = NaN,
8321       sign0 = NaN,
8322       clean; // no intersections
8323
8324   return {
8325     lineStart: function() {
8326       stream.lineStart();
8327       clean = 1;
8328     },
8329     point: function(lambda1, phi1) {
8330       var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
8331           delta = abs(lambda1 - lambda0);
8332       if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
8333         stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
8334         stream.point(sign0, phi0);
8335         stream.lineEnd();
8336         stream.lineStart();
8337         stream.point(sign1, phi0);
8338         stream.point(lambda1, phi0);
8339         clean = 0;
8340       } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
8341         if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
8342         if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
8343         phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
8344         stream.point(sign0, phi0);
8345         stream.lineEnd();
8346         stream.lineStart();
8347         stream.point(sign1, phi0);
8348         clean = 0;
8349       }
8350       stream.point(lambda0 = lambda1, phi0 = phi1);
8351       sign0 = sign1;
8352     },
8353     lineEnd: function() {
8354       stream.lineEnd();
8355       lambda0 = phi0 = NaN;
8356     },
8357     clean: function() {
8358       return 2 - clean; // if intersections, rejoin first and last segments
8359     }
8360   };
8361 }
8362
8363 function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
8364   var cosPhi0,
8365       cosPhi1,
8366       sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
8367   return abs(sinLambda0Lambda1) > epsilon$2
8368       ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
8369           - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
8370           / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
8371       : (phi0 + phi1) / 2;
8372 }
8373
8374 function clipAntimeridianInterpolate(from, to, direction, stream) {
8375   var phi;
8376   if (from == null) {
8377     phi = direction * halfPi$2;
8378     stream.point(-pi$3, phi);
8379     stream.point(0, phi);
8380     stream.point(pi$3, phi);
8381     stream.point(pi$3, 0);
8382     stream.point(pi$3, -phi);
8383     stream.point(0, -phi);
8384     stream.point(-pi$3, -phi);
8385     stream.point(-pi$3, 0);
8386     stream.point(-pi$3, phi);
8387   } else if (abs(from[0] - to[0]) > epsilon$2) {
8388     var lambda = from[0] < to[0] ? pi$3 : -pi$3;
8389     phi = direction * lambda / 2;
8390     stream.point(-lambda, phi);
8391     stream.point(0, phi);
8392     stream.point(lambda, phi);
8393   } else {
8394     stream.point(to[0], to[1]);
8395   }
8396 }
8397
8398 function clipCircle(radius) {
8399   var cr = cos$1(radius),
8400       delta = 6 * radians,
8401       smallRadius = cr > 0,
8402       notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
8403
8404   function interpolate(from, to, direction, stream) {
8405     circleStream(stream, radius, delta, direction, from, to);
8406   }
8407
8408   function visible(lambda, phi) {
8409     return cos$1(lambda) * cos$1(phi) > cr;
8410   }
8411
8412   // Takes a line and cuts into visible segments. Return values used for polygon
8413   // clipping: 0 - there were intersections or the line was empty; 1 - no
8414   // intersections 2 - there were intersections, and the first and last segments
8415   // should be rejoined.
8416   function clipLine(stream) {
8417     var point0, // previous point
8418         c0, // code for previous point
8419         v0, // visibility of previous point
8420         v00, // visibility of first point
8421         clean; // no intersections
8422     return {
8423       lineStart: function() {
8424         v00 = v0 = false;
8425         clean = 1;
8426       },
8427       point: function(lambda, phi) {
8428         var point1 = [lambda, phi],
8429             point2,
8430             v = visible(lambda, phi),
8431             c = smallRadius
8432               ? v ? 0 : code(lambda, phi)
8433               : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
8434         if (!point0 && (v00 = v0 = v)) stream.lineStart();
8435         // Handle degeneracies.
8436         // TODO ignore if not clipping polygons.
8437         if (v !== v0) {
8438           point2 = intersect(point0, point1);
8439           if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
8440             point1[0] += epsilon$2;
8441             point1[1] += epsilon$2;
8442             v = visible(point1[0], point1[1]);
8443           }
8444         }
8445         if (v !== v0) {
8446           clean = 0;
8447           if (v) {
8448             // outside going in
8449             stream.lineStart();
8450             point2 = intersect(point1, point0);
8451             stream.point(point2[0], point2[1]);
8452           } else {
8453             // inside going out
8454             point2 = intersect(point0, point1);
8455             stream.point(point2[0], point2[1]);
8456             stream.lineEnd();
8457           }
8458           point0 = point2;
8459         } else if (notHemisphere && point0 && smallRadius ^ v) {
8460           var t;
8461           // If the codes for two points are different, or are both zero,
8462           // and there this segment intersects with the small circle.
8463           if (!(c & c0) && (t = intersect(point1, point0, true))) {
8464             clean = 0;
8465             if (smallRadius) {
8466               stream.lineStart();
8467               stream.point(t[0][0], t[0][1]);
8468               stream.point(t[1][0], t[1][1]);
8469               stream.lineEnd();
8470             } else {
8471               stream.point(t[1][0], t[1][1]);
8472               stream.lineEnd();
8473               stream.lineStart();
8474               stream.point(t[0][0], t[0][1]);
8475             }
8476           }
8477         }
8478         if (v && (!point0 || !pointEqual(point0, point1))) {
8479           stream.point(point1[0], point1[1]);
8480         }
8481         point0 = point1, v0 = v, c0 = c;
8482       },
8483       lineEnd: function() {
8484         if (v0) stream.lineEnd();
8485         point0 = null;
8486       },
8487       // Rejoin first and last segments if there were intersections and the first
8488       // and last points were visible.
8489       clean: function() {
8490         return clean | ((v00 && v0) << 1);
8491       }
8492     };
8493   }
8494
8495   // Intersects the great circle between a and b with the clip circle.
8496   function intersect(a, b, two) {
8497     var pa = cartesian(a),
8498         pb = cartesian(b);
8499
8500     // We have two planes, n1.p = d1 and n2.p = d2.
8501     // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
8502     var n1 = [1, 0, 0], // normal
8503         n2 = cartesianCross(pa, pb),
8504         n2n2 = cartesianDot(n2, n2),
8505         n1n2 = n2[0], // cartesianDot(n1, n2),
8506         determinant = n2n2 - n1n2 * n1n2;
8507
8508     // Two polar points.
8509     if (!determinant) return !two && a;
8510
8511     var c1 =  cr * n2n2 / determinant,
8512         c2 = -cr * n1n2 / determinant,
8513         n1xn2 = cartesianCross(n1, n2),
8514         A = cartesianScale(n1, c1),
8515         B = cartesianScale(n2, c2);
8516     cartesianAddInPlace(A, B);
8517
8518     // Solve |p(t)|^2 = 1.
8519     var u = n1xn2,
8520         w = cartesianDot(A, u),
8521         uu = cartesianDot(u, u),
8522         t2 = w * w - uu * (cartesianDot(A, A) - 1);
8523
8524     if (t2 < 0) return;
8525
8526     var t = sqrt(t2),
8527         q = cartesianScale(u, (-w - t) / uu);
8528     cartesianAddInPlace(q, A);
8529     q = spherical(q);
8530
8531     if (!two) return q;
8532
8533     // Two intersection points.
8534     var lambda0 = a[0],
8535         lambda1 = b[0],
8536         phi0 = a[1],
8537         phi1 = b[1],
8538         z;
8539
8540     if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
8541
8542     var delta = lambda1 - lambda0,
8543         polar = abs(delta - pi$3) < epsilon$2,
8544         meridian = polar || delta < epsilon$2;
8545
8546     if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
8547
8548     // Check that the first point is between a and b.
8549     if (meridian
8550         ? polar
8551           ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
8552           : phi0 <= q[1] && q[1] <= phi1
8553         : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
8554       var q1 = cartesianScale(u, (-w + t) / uu);
8555       cartesianAddInPlace(q1, A);
8556       return [q, spherical(q1)];
8557     }
8558   }
8559
8560   // Generates a 4-bit vector representing the location of a point relative to
8561   // the small circle's bounding box.
8562   function code(lambda, phi) {
8563     var r = smallRadius ? radius : pi$3 - radius,
8564         code = 0;
8565     if (lambda < -r) code |= 1; // left
8566     else if (lambda > r) code |= 2; // right
8567     if (phi < -r) code |= 4; // below
8568     else if (phi > r) code |= 8; // above
8569     return code;
8570   }
8571
8572   return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
8573 }
8574
8575 function clipLine(a, b, x0, y0, x1, y1) {
8576   var ax = a[0],
8577       ay = a[1],
8578       bx = b[0],
8579       by = b[1],
8580       t0 = 0,
8581       t1 = 1,
8582       dx = bx - ax,
8583       dy = by - ay,
8584       r;
8585
8586   r = x0 - ax;
8587   if (!dx && r > 0) return;
8588   r /= dx;
8589   if (dx < 0) {
8590     if (r < t0) return;
8591     if (r < t1) t1 = r;
8592   } else if (dx > 0) {
8593     if (r > t1) return;
8594     if (r > t0) t0 = r;
8595   }
8596
8597   r = x1 - ax;
8598   if (!dx && r < 0) return;
8599   r /= dx;
8600   if (dx < 0) {
8601     if (r > t1) return;
8602     if (r > t0) t0 = r;
8603   } else if (dx > 0) {
8604     if (r < t0) return;
8605     if (r < t1) t1 = r;
8606   }
8607
8608   r = y0 - ay;
8609   if (!dy && r > 0) return;
8610   r /= dy;
8611   if (dy < 0) {
8612     if (r < t0) return;
8613     if (r < t1) t1 = r;
8614   } else if (dy > 0) {
8615     if (r > t1) return;
8616     if (r > t0) t0 = r;
8617   }
8618
8619   r = y1 - ay;
8620   if (!dy && r < 0) return;
8621   r /= dy;
8622   if (dy < 0) {
8623     if (r > t1) return;
8624     if (r > t0) t0 = r;
8625   } else if (dy > 0) {
8626     if (r < t0) return;
8627     if (r < t1) t1 = r;
8628   }
8629
8630   if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
8631   if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
8632   return true;
8633 }
8634
8635 var clipMax = 1e9, clipMin = -clipMax;
8636
8637 // TODO Use d3-polygon’s polygonContains here for the ring check?
8638 // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
8639
8640 function clipRectangle(x0, y0, x1, y1) {
8641
8642   function visible(x, y) {
8643     return x0 <= x && x <= x1 && y0 <= y && y <= y1;
8644   }
8645
8646   function interpolate(from, to, direction, stream) {
8647     var a = 0, a1 = 0;
8648     if (from == null
8649         || (a = corner(from, direction)) !== (a1 = corner(to, direction))
8650         || comparePoint(from, to) < 0 ^ direction > 0) {
8651       do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
8652       while ((a = (a + direction + 4) % 4) !== a1);
8653     } else {
8654       stream.point(to[0], to[1]);
8655     }
8656   }
8657
8658   function corner(p, direction) {
8659     return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
8660         : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
8661         : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
8662         : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
8663   }
8664
8665   function compareIntersection(a, b) {
8666     return comparePoint(a.x, b.x);
8667   }
8668
8669   function comparePoint(a, b) {
8670     var ca = corner(a, 1),
8671         cb = corner(b, 1);
8672     return ca !== cb ? ca - cb
8673         : ca === 0 ? b[1] - a[1]
8674         : ca === 1 ? a[0] - b[0]
8675         : ca === 2 ? a[1] - b[1]
8676         : b[0] - a[0];
8677   }
8678
8679   return function(stream) {
8680     var activeStream = stream,
8681         bufferStream = clipBuffer(),
8682         segments,
8683         polygon,
8684         ring,
8685         x__, y__, v__, // first point
8686         x_, y_, v_, // previous point
8687         first,
8688         clean;
8689
8690     var clipStream = {
8691       point: point,
8692       lineStart: lineStart,
8693       lineEnd: lineEnd,
8694       polygonStart: polygonStart,
8695       polygonEnd: polygonEnd
8696     };
8697
8698     function point(x, y) {
8699       if (visible(x, y)) activeStream.point(x, y);
8700     }
8701
8702     function polygonInside() {
8703       var winding = 0;
8704
8705       for (var i = 0, n = polygon.length; i < n; ++i) {
8706         for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
8707           a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
8708           if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
8709           else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
8710         }
8711       }
8712
8713       return winding;
8714     }
8715
8716     // Buffer geometry within a polygon and then clip it en masse.
8717     function polygonStart() {
8718       activeStream = bufferStream, segments = [], polygon = [], clean = true;
8719     }
8720
8721     function polygonEnd() {
8722       var startInside = polygonInside(),
8723           cleanInside = clean && startInside,
8724           visible = (segments = merge(segments)).length;
8725       if (cleanInside || visible) {
8726         stream.polygonStart();
8727         if (cleanInside) {
8728           stream.lineStart();
8729           interpolate(null, null, 1, stream);
8730           stream.lineEnd();
8731         }
8732         if (visible) {
8733           clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
8734         }
8735         stream.polygonEnd();
8736       }
8737       activeStream = stream, segments = polygon = ring = null;
8738     }
8739
8740     function lineStart() {
8741       clipStream.point = linePoint;
8742       if (polygon) polygon.push(ring = []);
8743       first = true;
8744       v_ = false;
8745       x_ = y_ = NaN;
8746     }
8747
8748     // TODO rather than special-case polygons, simply handle them separately.
8749     // Ideally, coincident intersection points should be jittered to avoid
8750     // clipping issues.
8751     function lineEnd() {
8752       if (segments) {
8753         linePoint(x__, y__);
8754         if (v__ && v_) bufferStream.rejoin();
8755         segments.push(bufferStream.result());
8756       }
8757       clipStream.point = point;
8758       if (v_) activeStream.lineEnd();
8759     }
8760
8761     function linePoint(x, y) {
8762       var v = visible(x, y);
8763       if (polygon) ring.push([x, y]);
8764       if (first) {
8765         x__ = x, y__ = y, v__ = v;
8766         first = false;
8767         if (v) {
8768           activeStream.lineStart();
8769           activeStream.point(x, y);
8770         }
8771       } else {
8772         if (v && v_) activeStream.point(x, y);
8773         else {
8774           var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
8775               b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
8776           if (clipLine(a, b, x0, y0, x1, y1)) {
8777             if (!v_) {
8778               activeStream.lineStart();
8779               activeStream.point(a[0], a[1]);
8780             }
8781             activeStream.point(b[0], b[1]);
8782             if (!v) activeStream.lineEnd();
8783             clean = false;
8784           } else if (v) {
8785             activeStream.lineStart();
8786             activeStream.point(x, y);
8787             clean = false;
8788           }
8789         }
8790       }
8791       x_ = x, y_ = y, v_ = v;
8792     }
8793
8794     return clipStream;
8795   };
8796 }
8797
8798 function extent$1() {
8799   var x0 = 0,
8800       y0 = 0,
8801       x1 = 960,
8802       y1 = 500,
8803       cache,
8804       cacheStream,
8805       clip;
8806
8807   return clip = {
8808     stream: function(stream) {
8809       return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
8810     },
8811     extent: function(_) {
8812       return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
8813     }
8814   };
8815 }
8816
8817 var lengthSum = adder(),
8818     lambda0$2,
8819     sinPhi0$1,
8820     cosPhi0$1;
8821
8822 var lengthStream = {
8823   sphere: noop$2,
8824   point: noop$2,
8825   lineStart: lengthLineStart,
8826   lineEnd: noop$2,
8827   polygonStart: noop$2,
8828   polygonEnd: noop$2
8829 };
8830
8831 function lengthLineStart() {
8832   lengthStream.point = lengthPointFirst;
8833   lengthStream.lineEnd = lengthLineEnd;
8834 }
8835
8836 function lengthLineEnd() {
8837   lengthStream.point = lengthStream.lineEnd = noop$2;
8838 }
8839
8840 function lengthPointFirst(lambda, phi) {
8841   lambda *= radians, phi *= radians;
8842   lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
8843   lengthStream.point = lengthPoint;
8844 }
8845
8846 function lengthPoint(lambda, phi) {
8847   lambda *= radians, phi *= radians;
8848   var sinPhi = sin$1(phi),
8849       cosPhi = cos$1(phi),
8850       delta = abs(lambda - lambda0$2),
8851       cosDelta = cos$1(delta),
8852       sinDelta = sin$1(delta),
8853       x = cosPhi * sinDelta,
8854       y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
8855       z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
8856   lengthSum.add(atan2(sqrt(x * x + y * y), z));
8857   lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
8858 }
8859
8860 function length$1(object) {
8861   lengthSum.reset();
8862   geoStream(object, lengthStream);
8863   return +lengthSum;
8864 }
8865
8866 var coordinates = [null, null],
8867     object$1 = {type: "LineString", coordinates: coordinates};
8868
8869 function distance(a, b) {
8870   coordinates[0] = a;
8871   coordinates[1] = b;
8872   return length$1(object$1);
8873 }
8874
8875 var containsObjectType = {
8876   Feature: function(object, point) {
8877     return containsGeometry(object.geometry, point);
8878   },
8879   FeatureCollection: function(object, point) {
8880     var features = object.features, i = -1, n = features.length;
8881     while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
8882     return false;
8883   }
8884 };
8885
8886 var containsGeometryType = {
8887   Sphere: function() {
8888     return true;
8889   },
8890   Point: function(object, point) {
8891     return containsPoint(object.coordinates, point);
8892   },
8893   MultiPoint: function(object, point) {
8894     var coordinates = object.coordinates, i = -1, n = coordinates.length;
8895     while (++i < n) if (containsPoint(coordinates[i], point)) return true;
8896     return false;
8897   },
8898   LineString: function(object, point) {
8899     return containsLine(object.coordinates, point);
8900   },
8901   MultiLineString: function(object, point) {
8902     var coordinates = object.coordinates, i = -1, n = coordinates.length;
8903     while (++i < n) if (containsLine(coordinates[i], point)) return true;
8904     return false;
8905   },
8906   Polygon: function(object, point) {
8907     return containsPolygon(object.coordinates, point);
8908   },
8909   MultiPolygon: function(object, point) {
8910     var coordinates = object.coordinates, i = -1, n = coordinates.length;
8911     while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
8912     return false;
8913   },
8914   GeometryCollection: function(object, point) {
8915     var geometries = object.geometries, i = -1, n = geometries.length;
8916     while (++i < n) if (containsGeometry(geometries[i], point)) return true;
8917     return false;
8918   }
8919 };
8920
8921 function containsGeometry(geometry, point) {
8922   return geometry && containsGeometryType.hasOwnProperty(geometry.type)
8923       ? containsGeometryType[geometry.type](geometry, point)
8924       : false;
8925 }
8926
8927 function containsPoint(coordinates, point) {
8928   return distance(coordinates, point) === 0;
8929 }
8930
8931 function containsLine(coordinates, point) {
8932   var ab = distance(coordinates[0], coordinates[1]),
8933       ao = distance(coordinates[0], point),
8934       ob = distance(point, coordinates[1]);
8935   return ao + ob <= ab + epsilon$2;
8936 }
8937
8938 function containsPolygon(coordinates, point) {
8939   return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
8940 }
8941
8942 function ringRadians(ring) {
8943   return ring = ring.map(pointRadians), ring.pop(), ring;
8944 }
8945
8946 function pointRadians(point) {
8947   return [point[0] * radians, point[1] * radians];
8948 }
8949
8950 function contains$1(object, point) {
8951   return (object && containsObjectType.hasOwnProperty(object.type)
8952       ? containsObjectType[object.type]
8953       : containsGeometry)(object, point);
8954 }
8955
8956 function graticuleX(y0, y1, dy) {
8957   var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
8958   return function(x) { return y.map(function(y) { return [x, y]; }); };
8959 }
8960
8961 function graticuleY(x0, x1, dx) {
8962   var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
8963   return function(y) { return x.map(function(x) { return [x, y]; }); };
8964 }
8965
8966 function graticule() {
8967   var x1, x0, X1, X0,
8968       y1, y0, Y1, Y0,
8969       dx = 10, dy = dx, DX = 90, DY = 360,
8970       x, y, X, Y,
8971       precision = 2.5;
8972
8973   function graticule() {
8974     return {type: "MultiLineString", coordinates: lines()};
8975   }
8976
8977   function lines() {
8978     return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
8979         .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
8980         .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
8981         .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
8982   }
8983
8984   graticule.lines = function() {
8985     return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
8986   };
8987
8988   graticule.outline = function() {
8989     return {
8990       type: "Polygon",
8991       coordinates: [
8992         X(X0).concat(
8993         Y(Y1).slice(1),
8994         X(X1).reverse().slice(1),
8995         Y(Y0).reverse().slice(1))
8996       ]
8997     };
8998   };
8999
9000   graticule.extent = function(_) {
9001     if (!arguments.length) return graticule.extentMinor();
9002     return graticule.extentMajor(_).extentMinor(_);
9003   };
9004
9005   graticule.extentMajor = function(_) {
9006     if (!arguments.length) return [[X0, Y0], [X1, Y1]];
9007     X0 = +_[0][0], X1 = +_[1][0];
9008     Y0 = +_[0][1], Y1 = +_[1][1];
9009     if (X0 > X1) _ = X0, X0 = X1, X1 = _;
9010     if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
9011     return graticule.precision(precision);
9012   };
9013
9014   graticule.extentMinor = function(_) {
9015     if (!arguments.length) return [[x0, y0], [x1, y1]];
9016     x0 = +_[0][0], x1 = +_[1][0];
9017     y0 = +_[0][1], y1 = +_[1][1];
9018     if (x0 > x1) _ = x0, x0 = x1, x1 = _;
9019     if (y0 > y1) _ = y0, y0 = y1, y1 = _;
9020     return graticule.precision(precision);
9021   };
9022
9023   graticule.step = function(_) {
9024     if (!arguments.length) return graticule.stepMinor();
9025     return graticule.stepMajor(_).stepMinor(_);
9026   };
9027
9028   graticule.stepMajor = function(_) {
9029     if (!arguments.length) return [DX, DY];
9030     DX = +_[0], DY = +_[1];
9031     return graticule;
9032   };
9033
9034   graticule.stepMinor = function(_) {
9035     if (!arguments.length) return [dx, dy];
9036     dx = +_[0], dy = +_[1];
9037     return graticule;
9038   };
9039
9040   graticule.precision = function(_) {
9041     if (!arguments.length) return precision;
9042     precision = +_;
9043     x = graticuleX(y0, y1, 90);
9044     y = graticuleY(x0, x1, precision);
9045     X = graticuleX(Y0, Y1, 90);
9046     Y = graticuleY(X0, X1, precision);
9047     return graticule;
9048   };
9049
9050   return graticule
9051       .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
9052       .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
9053 }
9054
9055 function graticule10() {
9056   return graticule()();
9057 }
9058
9059 function interpolate$1(a, b) {
9060   var x0 = a[0] * radians,
9061       y0 = a[1] * radians,
9062       x1 = b[0] * radians,
9063       y1 = b[1] * radians,
9064       cy0 = cos$1(y0),
9065       sy0 = sin$1(y0),
9066       cy1 = cos$1(y1),
9067       sy1 = sin$1(y1),
9068       kx0 = cy0 * cos$1(x0),
9069       ky0 = cy0 * sin$1(x0),
9070       kx1 = cy1 * cos$1(x1),
9071       ky1 = cy1 * sin$1(x1),
9072       d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
9073       k = sin$1(d);
9074
9075   var interpolate = d ? function(t) {
9076     var B = sin$1(t *= d) / k,
9077         A = sin$1(d - t) / k,
9078         x = A * kx0 + B * kx1,
9079         y = A * ky0 + B * ky1,
9080         z = A * sy0 + B * sy1;
9081     return [
9082       atan2(y, x) * degrees$1,
9083       atan2(z, sqrt(x * x + y * y)) * degrees$1
9084     ];
9085   } : function() {
9086     return [x0 * degrees$1, y0 * degrees$1];
9087   };
9088
9089   interpolate.distance = d;
9090
9091   return interpolate;
9092 }
9093
9094 function identity$4(x) {
9095   return x;
9096 }
9097
9098 var areaSum$1 = adder(),
9099     areaRingSum$1 = adder(),
9100     x00,
9101     y00,
9102     x0$1,
9103     y0$1;
9104
9105 var areaStream$1 = {
9106   point: noop$2,
9107   lineStart: noop$2,
9108   lineEnd: noop$2,
9109   polygonStart: function() {
9110     areaStream$1.lineStart = areaRingStart$1;
9111     areaStream$1.lineEnd = areaRingEnd$1;
9112   },
9113   polygonEnd: function() {
9114     areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
9115     areaSum$1.add(abs(areaRingSum$1));
9116     areaRingSum$1.reset();
9117   },
9118   result: function() {
9119     var area = areaSum$1 / 2;
9120     areaSum$1.reset();
9121     return area;
9122   }
9123 };
9124
9125 function areaRingStart$1() {
9126   areaStream$1.point = areaPointFirst$1;
9127 }
9128
9129 function areaPointFirst$1(x, y) {
9130   areaStream$1.point = areaPoint$1;
9131   x00 = x0$1 = x, y00 = y0$1 = y;
9132 }
9133
9134 function areaPoint$1(x, y) {
9135   areaRingSum$1.add(y0$1 * x - x0$1 * y);
9136   x0$1 = x, y0$1 = y;
9137 }
9138
9139 function areaRingEnd$1() {
9140   areaPoint$1(x00, y00);
9141 }
9142
9143 var x0$2 = Infinity,
9144     y0$2 = x0$2,
9145     x1 = -x0$2,
9146     y1 = x1;
9147
9148 var boundsStream$1 = {
9149   point: boundsPoint$1,
9150   lineStart: noop$2,
9151   lineEnd: noop$2,
9152   polygonStart: noop$2,
9153   polygonEnd: noop$2,
9154   result: function() {
9155     var bounds = [[x0$2, y0$2], [x1, y1]];
9156     x1 = y1 = -(y0$2 = x0$2 = Infinity);
9157     return bounds;
9158   }
9159 };
9160
9161 function boundsPoint$1(x, y) {
9162   if (x < x0$2) x0$2 = x;
9163   if (x > x1) x1 = x;
9164   if (y < y0$2) y0$2 = y;
9165   if (y > y1) y1 = y;
9166 }
9167
9168 // TODO Enforce positive area for exterior, negative area for interior?
9169
9170 var X0$1 = 0,
9171     Y0$1 = 0,
9172     Z0$1 = 0,
9173     X1$1 = 0,
9174     Y1$1 = 0,
9175     Z1$1 = 0,
9176     X2$1 = 0,
9177     Y2$1 = 0,
9178     Z2$1 = 0,
9179     x00$1,
9180     y00$1,
9181     x0$3,
9182     y0$3;
9183
9184 var centroidStream$1 = {
9185   point: centroidPoint$1,
9186   lineStart: centroidLineStart$1,
9187   lineEnd: centroidLineEnd$1,
9188   polygonStart: function() {
9189     centroidStream$1.lineStart = centroidRingStart$1;
9190     centroidStream$1.lineEnd = centroidRingEnd$1;
9191   },
9192   polygonEnd: function() {
9193     centroidStream$1.point = centroidPoint$1;
9194     centroidStream$1.lineStart = centroidLineStart$1;
9195     centroidStream$1.lineEnd = centroidLineEnd$1;
9196   },
9197   result: function() {
9198     var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
9199         : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
9200         : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
9201         : [NaN, NaN];
9202     X0$1 = Y0$1 = Z0$1 =
9203     X1$1 = Y1$1 = Z1$1 =
9204     X2$1 = Y2$1 = Z2$1 = 0;
9205     return centroid;
9206   }
9207 };
9208
9209 function centroidPoint$1(x, y) {
9210   X0$1 += x;
9211   Y0$1 += y;
9212   ++Z0$1;
9213 }
9214
9215 function centroidLineStart$1() {
9216   centroidStream$1.point = centroidPointFirstLine;
9217 }
9218
9219 function centroidPointFirstLine(x, y) {
9220   centroidStream$1.point = centroidPointLine;
9221   centroidPoint$1(x0$3 = x, y0$3 = y);
9222 }
9223
9224 function centroidPointLine(x, y) {
9225   var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
9226   X1$1 += z * (x0$3 + x) / 2;
9227   Y1$1 += z * (y0$3 + y) / 2;
9228   Z1$1 += z;
9229   centroidPoint$1(x0$3 = x, y0$3 = y);
9230 }
9231
9232 function centroidLineEnd$1() {
9233   centroidStream$1.point = centroidPoint$1;
9234 }
9235
9236 function centroidRingStart$1() {
9237   centroidStream$1.point = centroidPointFirstRing;
9238 }
9239
9240 function centroidRingEnd$1() {
9241   centroidPointRing(x00$1, y00$1);
9242 }
9243
9244 function centroidPointFirstRing(x, y) {
9245   centroidStream$1.point = centroidPointRing;
9246   centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
9247 }
9248
9249 function centroidPointRing(x, y) {
9250   var dx = x - x0$3,
9251       dy = y - y0$3,
9252       z = sqrt(dx * dx + dy * dy);
9253
9254   X1$1 += z * (x0$3 + x) / 2;
9255   Y1$1 += z * (y0$3 + y) / 2;
9256   Z1$1 += z;
9257
9258   z = y0$3 * x - x0$3 * y;
9259   X2$1 += z * (x0$3 + x);
9260   Y2$1 += z * (y0$3 + y);
9261   Z2$1 += z * 3;
9262   centroidPoint$1(x0$3 = x, y0$3 = y);
9263 }
9264
9265 function PathContext(context) {
9266   this._context = context;
9267 }
9268
9269 PathContext.prototype = {
9270   _radius: 4.5,
9271   pointRadius: function(_) {
9272     return this._radius = _, this;
9273   },
9274   polygonStart: function() {
9275     this._line = 0;
9276   },
9277   polygonEnd: function() {
9278     this._line = NaN;
9279   },
9280   lineStart: function() {
9281     this._point = 0;
9282   },
9283   lineEnd: function() {
9284     if (this._line === 0) this._context.closePath();
9285     this._point = NaN;
9286   },
9287   point: function(x, y) {
9288     switch (this._point) {
9289       case 0: {
9290         this._context.moveTo(x, y);
9291         this._point = 1;
9292         break;
9293       }
9294       case 1: {
9295         this._context.lineTo(x, y);
9296         break;
9297       }
9298       default: {
9299         this._context.moveTo(x + this._radius, y);
9300         this._context.arc(x, y, this._radius, 0, tau$3);
9301         break;
9302       }
9303     }
9304   },
9305   result: noop$2
9306 };
9307
9308 var lengthSum$1 = adder(),
9309     lengthRing,
9310     x00$2,
9311     y00$2,
9312     x0$4,
9313     y0$4;
9314
9315 var lengthStream$1 = {
9316   point: noop$2,
9317   lineStart: function() {
9318     lengthStream$1.point = lengthPointFirst$1;
9319   },
9320   lineEnd: function() {
9321     if (lengthRing) lengthPoint$1(x00$2, y00$2);
9322     lengthStream$1.point = noop$2;
9323   },
9324   polygonStart: function() {
9325     lengthRing = true;
9326   },
9327   polygonEnd: function() {
9328     lengthRing = null;
9329   },
9330   result: function() {
9331     var length = +lengthSum$1;
9332     lengthSum$1.reset();
9333     return length;
9334   }
9335 };
9336
9337 function lengthPointFirst$1(x, y) {
9338   lengthStream$1.point = lengthPoint$1;
9339   x00$2 = x0$4 = x, y00$2 = y0$4 = y;
9340 }
9341
9342 function lengthPoint$1(x, y) {
9343   x0$4 -= x, y0$4 -= y;
9344   lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
9345   x0$4 = x, y0$4 = y;
9346 }
9347
9348 function PathString() {
9349   this._string = [];
9350 }
9351
9352 PathString.prototype = {
9353   _radius: 4.5,
9354   _circle: circle$1(4.5),
9355   pointRadius: function(_) {
9356     if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
9357     return this;
9358   },
9359   polygonStart: function() {
9360     this._line = 0;
9361   },
9362   polygonEnd: function() {
9363     this._line = NaN;
9364   },
9365   lineStart: function() {
9366     this._point = 0;
9367   },
9368   lineEnd: function() {
9369     if (this._line === 0) this._string.push("Z");
9370     this._point = NaN;
9371   },
9372   point: function(x, y) {
9373     switch (this._point) {
9374       case 0: {
9375         this._string.push("M", x, ",", y);
9376         this._point = 1;
9377         break;
9378       }
9379       case 1: {
9380         this._string.push("L", x, ",", y);
9381         break;
9382       }
9383       default: {
9384         if (this._circle == null) this._circle = circle$1(this._radius);
9385         this._string.push("M", x, ",", y, this._circle);
9386         break;
9387       }
9388     }
9389   },
9390   result: function() {
9391     if (this._string.length) {
9392       var result = this._string.join("");
9393       this._string = [];
9394       return result;
9395     } else {
9396       return null;
9397     }
9398   }
9399 };
9400
9401 function circle$1(radius) {
9402   return "m0," + radius
9403       + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
9404       + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
9405       + "z";
9406 }
9407
9408 function index$1(projection, context) {
9409   var pointRadius = 4.5,
9410       projectionStream,
9411       contextStream;
9412
9413   function path(object) {
9414     if (object) {
9415       if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
9416       geoStream(object, projectionStream(contextStream));
9417     }
9418     return contextStream.result();
9419   }
9420
9421   path.area = function(object) {
9422     geoStream(object, projectionStream(areaStream$1));
9423     return areaStream$1.result();
9424   };
9425
9426   path.measure = function(object) {
9427     geoStream(object, projectionStream(lengthStream$1));
9428     return lengthStream$1.result();
9429   };
9430
9431   path.bounds = function(object) {
9432     geoStream(object, projectionStream(boundsStream$1));
9433     return boundsStream$1.result();
9434   };
9435
9436   path.centroid = function(object) {
9437     geoStream(object, projectionStream(centroidStream$1));
9438     return centroidStream$1.result();
9439   };
9440
9441   path.projection = function(_) {
9442     return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
9443   };
9444
9445   path.context = function(_) {
9446     if (!arguments.length) return context;
9447     contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
9448     if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
9449     return path;
9450   };
9451
9452   path.pointRadius = function(_) {
9453     if (!arguments.length) return pointRadius;
9454     pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
9455     return path;
9456   };
9457
9458   return path.projection(projection).context(context);
9459 }
9460
9461 function transform(methods) {
9462   return {
9463     stream: transformer(methods)
9464   };
9465 }
9466
9467 function transformer(methods) {
9468   return function(stream) {
9469     var s = new TransformStream;
9470     for (var key in methods) s[key] = methods[key];
9471     s.stream = stream;
9472     return s;
9473   };
9474 }
9475
9476 function TransformStream() {}
9477
9478 TransformStream.prototype = {
9479   constructor: TransformStream,
9480   point: function(x, y) { this.stream.point(x, y); },
9481   sphere: function() { this.stream.sphere(); },
9482   lineStart: function() { this.stream.lineStart(); },
9483   lineEnd: function() { this.stream.lineEnd(); },
9484   polygonStart: function() { this.stream.polygonStart(); },
9485   polygonEnd: function() { this.stream.polygonEnd(); }
9486 };
9487
9488 function fit(projection, fitBounds, object) {
9489   var clip = projection.clipExtent && projection.clipExtent();
9490   projection.scale(150).translate([0, 0]);
9491   if (clip != null) projection.clipExtent(null);
9492   geoStream(object, projection.stream(boundsStream$1));
9493   fitBounds(boundsStream$1.result());
9494   if (clip != null) projection.clipExtent(clip);
9495   return projection;
9496 }
9497
9498 function fitExtent(projection, extent, object) {
9499   return fit(projection, function(b) {
9500     var w = extent[1][0] - extent[0][0],
9501         h = extent[1][1] - extent[0][1],
9502         k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
9503         x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
9504         y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
9505     projection.scale(150 * k).translate([x, y]);
9506   }, object);
9507 }
9508
9509 function fitSize(projection, size, object) {
9510   return fitExtent(projection, [[0, 0], size], object);
9511 }
9512
9513 function fitWidth(projection, width, object) {
9514   return fit(projection, function(b) {
9515     var w = +width,
9516         k = w / (b[1][0] - b[0][0]),
9517         x = (w - k * (b[1][0] + b[0][0])) / 2,
9518         y = -k * b[0][1];
9519     projection.scale(150 * k).translate([x, y]);
9520   }, object);
9521 }
9522
9523 function fitHeight(projection, height, object) {
9524   return fit(projection, function(b) {
9525     var h = +height,
9526         k = h / (b[1][1] - b[0][1]),
9527         x = -k * b[0][0],
9528         y = (h - k * (b[1][1] + b[0][1])) / 2;
9529     projection.scale(150 * k).translate([x, y]);
9530   }, object);
9531 }
9532
9533 var maxDepth = 16, // maximum depth of subdivision
9534     cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
9535
9536 function resample(project, delta2) {
9537   return +delta2 ? resample$1(project, delta2) : resampleNone(project);
9538 }
9539
9540 function resampleNone(project) {
9541   return transformer({
9542     point: function(x, y) {
9543       x = project(x, y);
9544       this.stream.point(x[0], x[1]);
9545     }
9546   });
9547 }
9548
9549 function resample$1(project, delta2) {
9550
9551   function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
9552     var dx = x1 - x0,
9553         dy = y1 - y0,
9554         d2 = dx * dx + dy * dy;
9555     if (d2 > 4 * delta2 && depth--) {
9556       var a = a0 + a1,
9557           b = b0 + b1,
9558           c = c0 + c1,
9559           m = sqrt(a * a + b * b + c * c),
9560           phi2 = asin(c /= m),
9561           lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
9562           p = project(lambda2, phi2),
9563           x2 = p[0],
9564           y2 = p[1],
9565           dx2 = x2 - x0,
9566           dy2 = y2 - y0,
9567           dz = dy * dx2 - dx * dy2;
9568       if (dz * dz / d2 > delta2 // perpendicular projected distance
9569           || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
9570           || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
9571         resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
9572         stream.point(x2, y2);
9573         resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
9574       }
9575     }
9576   }
9577   return function(stream) {
9578     var lambda00, x00, y00, a00, b00, c00, // first point
9579         lambda0, x0, y0, a0, b0, c0; // previous point
9580
9581     var resampleStream = {
9582       point: point,
9583       lineStart: lineStart,
9584       lineEnd: lineEnd,
9585       polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
9586       polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
9587     };
9588
9589     function point(x, y) {
9590       x = project(x, y);
9591       stream.point(x[0], x[1]);
9592     }
9593
9594     function lineStart() {
9595       x0 = NaN;
9596       resampleStream.point = linePoint;
9597       stream.lineStart();
9598     }
9599
9600     function linePoint(lambda, phi) {
9601       var c = cartesian([lambda, phi]), p = project(lambda, phi);
9602       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);
9603       stream.point(x0, y0);
9604     }
9605
9606     function lineEnd() {
9607       resampleStream.point = point;
9608       stream.lineEnd();
9609     }
9610
9611     function ringStart() {
9612       lineStart();
9613       resampleStream.point = ringPoint;
9614       resampleStream.lineEnd = ringEnd;
9615     }
9616
9617     function ringPoint(lambda, phi) {
9618       linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
9619       resampleStream.point = linePoint;
9620     }
9621
9622     function ringEnd() {
9623       resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
9624       resampleStream.lineEnd = lineEnd;
9625       lineEnd();
9626     }
9627
9628     return resampleStream;
9629   };
9630 }
9631
9632 var transformRadians = transformer({
9633   point: function(x, y) {
9634     this.stream.point(x * radians, y * radians);
9635   }
9636 });
9637
9638 function transformRotate(rotate) {
9639   return transformer({
9640     point: function(x, y) {
9641       var r = rotate(x, y);
9642       return this.stream.point(r[0], r[1]);
9643     }
9644   });
9645 }
9646
9647 function scaleTranslate(k, dx, dy) {
9648   function transform$$1(x, y) {
9649     return [dx + k * x, dy - k * y];
9650   }
9651   transform$$1.invert = function(x, y) {
9652     return [(x - dx) / k, (dy - y) / k];
9653   };
9654   return transform$$1;
9655 }
9656
9657 function scaleTranslateRotate(k, dx, dy, alpha) {
9658   var cosAlpha = cos$1(alpha),
9659       sinAlpha = sin$1(alpha),
9660       a = cosAlpha * k,
9661       b = sinAlpha * k,
9662       ai = cosAlpha / k,
9663       bi = sinAlpha / k,
9664       ci = (sinAlpha * dy - cosAlpha * dx) / k,
9665       fi = (sinAlpha * dx + cosAlpha * dy) / k;
9666   function transform$$1(x, y) {
9667     return [a * x - b * y + dx, dy - b * x - a * y];
9668   }
9669   transform$$1.invert = function(x, y) {
9670     return [ai * x - bi * y + ci, fi - bi * x - ai * y];
9671   };
9672   return transform$$1;
9673 }
9674
9675 function projection(project) {
9676   return projectionMutator(function() { return project; })();
9677 }
9678
9679 function projectionMutator(projectAt) {
9680   var project,
9681       k = 150, // scale
9682       x = 480, y = 250, // translate
9683       lambda = 0, phi = 0, // center
9684       deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
9685       alpha = 0, // post-rotate
9686       theta = null, preclip = clipAntimeridian, // pre-clip angle
9687       x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
9688       delta2 = 0.5, // precision
9689       projectResample,
9690       projectTransform,
9691       projectRotateTransform,
9692       cache,
9693       cacheStream;
9694
9695   function projection(point) {
9696     return projectRotateTransform(point[0] * radians, point[1] * radians);
9697   }
9698
9699   function invert(point) {
9700     point = projectRotateTransform.invert(point[0], point[1]);
9701     return point && [point[0] * degrees$1, point[1] * degrees$1];
9702   }
9703
9704   projection.stream = function(stream) {
9705     return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
9706   };
9707
9708   projection.preclip = function(_) {
9709     return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
9710   };
9711
9712   projection.postclip = function(_) {
9713     return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
9714   };
9715
9716   projection.clipAngle = function(_) {
9717     return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
9718   };
9719
9720   projection.clipExtent = function(_) {
9721     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]];
9722   };
9723
9724   projection.scale = function(_) {
9725     return arguments.length ? (k = +_, recenter()) : k;
9726   };
9727
9728   projection.translate = function(_) {
9729     return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
9730   };
9731
9732   projection.center = function(_) {
9733     return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
9734   };
9735
9736   projection.rotate = function(_) {
9737     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];
9738   };
9739
9740   projection.angle = function(_) {
9741     return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
9742   };
9743
9744   projection.precision = function(_) {
9745     return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
9746   };
9747
9748   projection.fitExtent = function(extent, object) {
9749     return fitExtent(projection, extent, object);
9750   };
9751
9752   projection.fitSize = function(size, object) {
9753     return fitSize(projection, size, object);
9754   };
9755
9756   projection.fitWidth = function(width, object) {
9757     return fitWidth(projection, width, object);
9758   };
9759
9760   projection.fitHeight = function(height, object) {
9761     return fitHeight(projection, height, object);
9762   };
9763
9764   function recenter() {
9765     var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
9766         transform$$1 = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
9767     rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
9768     projectTransform = compose(project, transform$$1);
9769     projectRotateTransform = compose(rotate, projectTransform);
9770     projectResample = resample(projectTransform, delta2);
9771     return reset();
9772   }
9773
9774   function reset() {
9775     cache = cacheStream = null;
9776     return projection;
9777   }
9778
9779   return function() {
9780     project = projectAt.apply(this, arguments);
9781     projection.invert = project.invert && invert;
9782     return recenter();
9783   };
9784 }
9785
9786 function conicProjection(projectAt) {
9787   var phi0 = 0,
9788       phi1 = pi$3 / 3,
9789       m = projectionMutator(projectAt),
9790       p = m(phi0, phi1);
9791
9792   p.parallels = function(_) {
9793     return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
9794   };
9795
9796   return p;
9797 }
9798
9799 function cylindricalEqualAreaRaw(phi0) {
9800   var cosPhi0 = cos$1(phi0);
9801
9802   function forward(lambda, phi) {
9803     return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
9804   }
9805
9806   forward.invert = function(x, y) {
9807     return [x / cosPhi0, asin(y * cosPhi0)];
9808   };
9809
9810   return forward;
9811 }
9812
9813 function conicEqualAreaRaw(y0, y1) {
9814   var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
9815
9816   // Are the parallels symmetrical around the Equator?
9817   if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
9818
9819   var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
9820
9821   function project(x, y) {
9822     var r = sqrt(c - 2 * n * sin$1(y)) / n;
9823     return [r * sin$1(x *= n), r0 - r * cos$1(x)];
9824   }
9825
9826   project.invert = function(x, y) {
9827     var r0y = r0 - y;
9828     return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
9829   };
9830
9831   return project;
9832 }
9833
9834 function conicEqualArea() {
9835   return conicProjection(conicEqualAreaRaw)
9836       .scale(155.424)
9837       .center([0, 33.6442]);
9838 }
9839
9840 function albers() {
9841   return conicEqualArea()
9842       .parallels([29.5, 45.5])
9843       .scale(1070)
9844       .translate([480, 250])
9845       .rotate([96, 0])
9846       .center([-0.6, 38.7]);
9847 }
9848
9849 // The projections must have mutually exclusive clip regions on the sphere,
9850 // as this will avoid emitting interleaving lines and polygons.
9851 function multiplex(streams) {
9852   var n = streams.length;
9853   return {
9854     point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
9855     sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
9856     lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
9857     lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
9858     polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
9859     polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
9860   };
9861 }
9862
9863 // A composite projection for the United States, configured by default for
9864 // 960×500. The projection also works quite well at 960×600 if you change the
9865 // scale to 1285 and adjust the translate accordingly. The set of standard
9866 // parallels for each region comes from USGS, which is published here:
9867 // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
9868 function albersUsa() {
9869   var cache,
9870       cacheStream,
9871       lower48 = albers(), lower48Point,
9872       alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
9873       hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
9874       point, pointStream = {point: function(x, y) { point = [x, y]; }};
9875
9876   function albersUsa(coordinates) {
9877     var x = coordinates[0], y = coordinates[1];
9878     return point = null, (lower48Point.point(x, y), point)
9879         || (alaskaPoint.point(x, y), point)
9880         || (hawaiiPoint.point(x, y), point);
9881   }
9882
9883   albersUsa.invert = function(coordinates) {
9884     var k = lower48.scale(),
9885         t = lower48.translate(),
9886         x = (coordinates[0] - t[0]) / k,
9887         y = (coordinates[1] - t[1]) / k;
9888     return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
9889         : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
9890         : lower48).invert(coordinates);
9891   };
9892
9893   albersUsa.stream = function(stream) {
9894     return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
9895   };
9896
9897   albersUsa.precision = function(_) {
9898     if (!arguments.length) return lower48.precision();
9899     lower48.precision(_), alaska.precision(_), hawaii.precision(_);
9900     return reset();
9901   };
9902
9903   albersUsa.scale = function(_) {
9904     if (!arguments.length) return lower48.scale();
9905     lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
9906     return albersUsa.translate(lower48.translate());
9907   };
9908
9909   albersUsa.translate = function(_) {
9910     if (!arguments.length) return lower48.translate();
9911     var k = lower48.scale(), x = +_[0], y = +_[1];
9912
9913     lower48Point = lower48
9914         .translate(_)
9915         .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
9916         .stream(pointStream);
9917
9918     alaskaPoint = alaska
9919         .translate([x - 0.307 * k, y + 0.201 * k])
9920         .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]])
9921         .stream(pointStream);
9922
9923     hawaiiPoint = hawaii
9924         .translate([x - 0.205 * k, y + 0.212 * k])
9925         .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]])
9926         .stream(pointStream);
9927
9928     return reset();
9929   };
9930
9931   albersUsa.fitExtent = function(extent, object) {
9932     return fitExtent(albersUsa, extent, object);
9933   };
9934
9935   albersUsa.fitSize = function(size, object) {
9936     return fitSize(albersUsa, size, object);
9937   };
9938
9939   albersUsa.fitWidth = function(width, object) {
9940     return fitWidth(albersUsa, width, object);
9941   };
9942
9943   albersUsa.fitHeight = function(height, object) {
9944     return fitHeight(albersUsa, height, object);
9945   };
9946
9947   function reset() {
9948     cache = cacheStream = null;
9949     return albersUsa;
9950   }
9951
9952   return albersUsa.scale(1070);
9953 }
9954
9955 function azimuthalRaw(scale) {
9956   return function(x, y) {
9957     var cx = cos$1(x),
9958         cy = cos$1(y),
9959         k = scale(cx * cy);
9960     return [
9961       k * cy * sin$1(x),
9962       k * sin$1(y)
9963     ];
9964   }
9965 }
9966
9967 function azimuthalInvert(angle) {
9968   return function(x, y) {
9969     var z = sqrt(x * x + y * y),
9970         c = angle(z),
9971         sc = sin$1(c),
9972         cc = cos$1(c);
9973     return [
9974       atan2(x * sc, z * cc),
9975       asin(z && y * sc / z)
9976     ];
9977   }
9978 }
9979
9980 var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
9981   return sqrt(2 / (1 + cxcy));
9982 });
9983
9984 azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
9985   return 2 * asin(z / 2);
9986 });
9987
9988 function azimuthalEqualArea() {
9989   return projection(azimuthalEqualAreaRaw)
9990       .scale(124.75)
9991       .clipAngle(180 - 1e-3);
9992 }
9993
9994 var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
9995   return (c = acos(c)) && c / sin$1(c);
9996 });
9997
9998 azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
9999   return z;
10000 });
10001
10002 function azimuthalEquidistant() {
10003   return projection(azimuthalEquidistantRaw)
10004       .scale(79.4188)
10005       .clipAngle(180 - 1e-3);
10006 }
10007
10008 function mercatorRaw(lambda, phi) {
10009   return [lambda, log(tan((halfPi$2 + phi) / 2))];
10010 }
10011
10012 mercatorRaw.invert = function(x, y) {
10013   return [x, 2 * atan(exp(y)) - halfPi$2];
10014 };
10015
10016 function mercator() {
10017   return mercatorProjection(mercatorRaw)
10018       .scale(961 / tau$3);
10019 }
10020
10021 function mercatorProjection(project) {
10022   var m = projection(project),
10023       center = m.center,
10024       scale = m.scale,
10025       translate = m.translate,
10026       clipExtent = m.clipExtent,
10027       x0 = null, y0, x1, y1; // clip extent
10028
10029   m.scale = function(_) {
10030     return arguments.length ? (scale(_), reclip()) : scale();
10031   };
10032
10033   m.translate = function(_) {
10034     return arguments.length ? (translate(_), reclip()) : translate();
10035   };
10036
10037   m.center = function(_) {
10038     return arguments.length ? (center(_), reclip()) : center();
10039   };
10040
10041   m.clipExtent = function(_) {
10042     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]];
10043   };
10044
10045   function reclip() {
10046     var k = pi$3 * scale(),
10047         t = m(rotation(m.rotate()).invert([0, 0]));
10048     return clipExtent(x0 == null
10049         ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
10050         ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
10051         : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
10052   }
10053
10054   return reclip();
10055 }
10056
10057 function tany(y) {
10058   return tan((halfPi$2 + y) / 2);
10059 }
10060
10061 function conicConformalRaw(y0, y1) {
10062   var cy0 = cos$1(y0),
10063       n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
10064       f = cy0 * pow(tany(y0), n) / n;
10065
10066   if (!n) return mercatorRaw;
10067
10068   function project(x, y) {
10069     if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
10070     else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
10071     var r = f / pow(tany(y), n);
10072     return [r * sin$1(n * x), f - r * cos$1(n * x)];
10073   }
10074
10075   project.invert = function(x, y) {
10076     var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
10077     return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
10078   };
10079
10080   return project;
10081 }
10082
10083 function conicConformal() {
10084   return conicProjection(conicConformalRaw)
10085       .scale(109.5)
10086       .parallels([30, 30]);
10087 }
10088
10089 function equirectangularRaw(lambda, phi) {
10090   return [lambda, phi];
10091 }
10092
10093 equirectangularRaw.invert = equirectangularRaw;
10094
10095 function equirectangular() {
10096   return projection(equirectangularRaw)
10097       .scale(152.63);
10098 }
10099
10100 function conicEquidistantRaw(y0, y1) {
10101   var cy0 = cos$1(y0),
10102       n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
10103       g = cy0 / n + y0;
10104
10105   if (abs(n) < epsilon$2) return equirectangularRaw;
10106
10107   function project(x, y) {
10108     var gy = g - y, nx = n * x;
10109     return [gy * sin$1(nx), g - gy * cos$1(nx)];
10110   }
10111
10112   project.invert = function(x, y) {
10113     var gy = g - y;
10114     return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
10115   };
10116
10117   return project;
10118 }
10119
10120 function conicEquidistant() {
10121   return conicProjection(conicEquidistantRaw)
10122       .scale(131.154)
10123       .center([0, 13.9389]);
10124 }
10125
10126 function gnomonicRaw(x, y) {
10127   var cy = cos$1(y), k = cos$1(x) * cy;
10128   return [cy * sin$1(x) / k, sin$1(y) / k];
10129 }
10130
10131 gnomonicRaw.invert = azimuthalInvert(atan);
10132
10133 function gnomonic() {
10134   return projection(gnomonicRaw)
10135       .scale(144.049)
10136       .clipAngle(60);
10137 }
10138
10139 function scaleTranslate$1(kx, ky, tx, ty) {
10140   return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
10141     point: function(x, y) {
10142       this.stream.point(x * kx + tx, y * ky + ty);
10143     }
10144   });
10145 }
10146
10147 function identity$5() {
10148   var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
10149       x0 = null, y0, x1, y1, // clip extent
10150       postclip = identity$4,
10151       cache,
10152       cacheStream,
10153       projection;
10154
10155   function reset() {
10156     cache = cacheStream = null;
10157     return projection;
10158   }
10159
10160   return projection = {
10161     stream: function(stream) {
10162       return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
10163     },
10164     postclip: function(_) {
10165       return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
10166     },
10167     clipExtent: function(_) {
10168       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]];
10169     },
10170     scale: function(_) {
10171       return arguments.length ? (transform$$1 = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
10172     },
10173     translate: function(_) {
10174       return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
10175     },
10176     reflectX: function(_) {
10177       return arguments.length ? (transform$$1 = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
10178     },
10179     reflectY: function(_) {
10180       return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
10181     },
10182     fitExtent: function(extent, object) {
10183       return fitExtent(projection, extent, object);
10184     },
10185     fitSize: function(size, object) {
10186       return fitSize(projection, size, object);
10187     },
10188     fitWidth: function(width, object) {
10189       return fitWidth(projection, width, object);
10190     },
10191     fitHeight: function(height, object) {
10192       return fitHeight(projection, height, object);
10193     }
10194   };
10195 }
10196
10197 function naturalEarth1Raw(lambda, phi) {
10198   var phi2 = phi * phi, phi4 = phi2 * phi2;
10199   return [
10200     lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
10201     phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
10202   ];
10203 }
10204
10205 naturalEarth1Raw.invert = function(x, y) {
10206   var phi = y, i = 25, delta;
10207   do {
10208     var phi2 = phi * phi, phi4 = phi2 * phi2;
10209     phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
10210         (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
10211   } while (abs(delta) > epsilon$2 && --i > 0);
10212   return [
10213     x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
10214     phi
10215   ];
10216 };
10217
10218 function naturalEarth1() {
10219   return projection(naturalEarth1Raw)
10220       .scale(175.295);
10221 }
10222
10223 function orthographicRaw(x, y) {
10224   return [cos$1(y) * sin$1(x), sin$1(y)];
10225 }
10226
10227 orthographicRaw.invert = azimuthalInvert(asin);
10228
10229 function orthographic() {
10230   return projection(orthographicRaw)
10231       .scale(249.5)
10232       .clipAngle(90 + epsilon$2);
10233 }
10234
10235 function stereographicRaw(x, y) {
10236   var cy = cos$1(y), k = 1 + cos$1(x) * cy;
10237   return [cy * sin$1(x) / k, sin$1(y) / k];
10238 }
10239
10240 stereographicRaw.invert = azimuthalInvert(function(z) {
10241   return 2 * atan(z);
10242 });
10243
10244 function stereographic() {
10245   return projection(stereographicRaw)
10246       .scale(250)
10247       .clipAngle(142);
10248 }
10249
10250 function transverseMercatorRaw(lambda, phi) {
10251   return [log(tan((halfPi$2 + phi) / 2)), -lambda];
10252 }
10253
10254 transverseMercatorRaw.invert = function(x, y) {
10255   return [-y, 2 * atan(exp(x)) - halfPi$2];
10256 };
10257
10258 function transverseMercator() {
10259   var m = mercatorProjection(transverseMercatorRaw),
10260       center = m.center,
10261       rotate = m.rotate;
10262
10263   m.center = function(_) {
10264     return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
10265   };
10266
10267   m.rotate = function(_) {
10268     return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
10269   };
10270
10271   return rotate([0, 0, 90])
10272       .scale(159.155);
10273 }
10274
10275 function defaultSeparation(a, b) {
10276   return a.parent === b.parent ? 1 : 2;
10277 }
10278
10279 function meanX(children) {
10280   return children.reduce(meanXReduce, 0) / children.length;
10281 }
10282
10283 function meanXReduce(x, c) {
10284   return x + c.x;
10285 }
10286
10287 function maxY(children) {
10288   return 1 + children.reduce(maxYReduce, 0);
10289 }
10290
10291 function maxYReduce(y, c) {
10292   return Math.max(y, c.y);
10293 }
10294
10295 function leafLeft(node) {
10296   var children;
10297   while (children = node.children) node = children[0];
10298   return node;
10299 }
10300
10301 function leafRight(node) {
10302   var children;
10303   while (children = node.children) node = children[children.length - 1];
10304   return node;
10305 }
10306
10307 function cluster() {
10308   var separation = defaultSeparation,
10309       dx = 1,
10310       dy = 1,
10311       nodeSize = false;
10312
10313   function cluster(root) {
10314     var previousNode,
10315         x = 0;
10316
10317     // First walk, computing the initial x & y values.
10318     root.eachAfter(function(node) {
10319       var children = node.children;
10320       if (children) {
10321         node.x = meanX(children);
10322         node.y = maxY(children);
10323       } else {
10324         node.x = previousNode ? x += separation(node, previousNode) : 0;
10325         node.y = 0;
10326         previousNode = node;
10327       }
10328     });
10329
10330     var left = leafLeft(root),
10331         right = leafRight(root),
10332         x0 = left.x - separation(left, right) / 2,
10333         x1 = right.x + separation(right, left) / 2;
10334
10335     // Second walk, normalizing x & y to the desired size.
10336     return root.eachAfter(nodeSize ? function(node) {
10337       node.x = (node.x - root.x) * dx;
10338       node.y = (root.y - node.y) * dy;
10339     } : function(node) {
10340       node.x = (node.x - x0) / (x1 - x0) * dx;
10341       node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
10342     });
10343   }
10344
10345   cluster.separation = function(x) {
10346     return arguments.length ? (separation = x, cluster) : separation;
10347   };
10348
10349   cluster.size = function(x) {
10350     return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
10351   };
10352
10353   cluster.nodeSize = function(x) {
10354     return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
10355   };
10356
10357   return cluster;
10358 }
10359
10360 function count(node) {
10361   var sum = 0,
10362       children = node.children,
10363       i = children && children.length;
10364   if (!i) sum = 1;
10365   else while (--i >= 0) sum += children[i].value;
10366   node.value = sum;
10367 }
10368
10369 function node_count() {
10370   return this.eachAfter(count);
10371 }
10372
10373 function node_each(callback) {
10374   var node = this, current, next = [node], children, i, n;
10375   do {
10376     current = next.reverse(), next = [];
10377     while (node = current.pop()) {
10378       callback(node), children = node.children;
10379       if (children) for (i = 0, n = children.length; i < n; ++i) {
10380         next.push(children[i]);
10381       }
10382     }
10383   } while (next.length);
10384   return this;
10385 }
10386
10387 function node_eachBefore(callback) {
10388   var node = this, nodes = [node], children, i;
10389   while (node = nodes.pop()) {
10390     callback(node), children = node.children;
10391     if (children) for (i = children.length - 1; i >= 0; --i) {
10392       nodes.push(children[i]);
10393     }
10394   }
10395   return this;
10396 }
10397
10398 function node_eachAfter(callback) {
10399   var node = this, nodes = [node], next = [], children, i, n;
10400   while (node = nodes.pop()) {
10401     next.push(node), children = node.children;
10402     if (children) for (i = 0, n = children.length; i < n; ++i) {
10403       nodes.push(children[i]);
10404     }
10405   }
10406   while (node = next.pop()) {
10407     callback(node);
10408   }
10409   return this;
10410 }
10411
10412 function node_sum(value) {
10413   return this.eachAfter(function(node) {
10414     var sum = +value(node.data) || 0,
10415         children = node.children,
10416         i = children && children.length;
10417     while (--i >= 0) sum += children[i].value;
10418     node.value = sum;
10419   });
10420 }
10421
10422 function node_sort(compare) {
10423   return this.eachBefore(function(node) {
10424     if (node.children) {
10425       node.children.sort(compare);
10426     }
10427   });
10428 }
10429
10430 function node_path(end) {
10431   var start = this,
10432       ancestor = leastCommonAncestor(start, end),
10433       nodes = [start];
10434   while (start !== ancestor) {
10435     start = start.parent;
10436     nodes.push(start);
10437   }
10438   var k = nodes.length;
10439   while (end !== ancestor) {
10440     nodes.splice(k, 0, end);
10441     end = end.parent;
10442   }
10443   return nodes;
10444 }
10445
10446 function leastCommonAncestor(a, b) {
10447   if (a === b) return a;
10448   var aNodes = a.ancestors(),
10449       bNodes = b.ancestors(),
10450       c = null;
10451   a = aNodes.pop();
10452   b = bNodes.pop();
10453   while (a === b) {
10454     c = a;
10455     a = aNodes.pop();
10456     b = bNodes.pop();
10457   }
10458   return c;
10459 }
10460
10461 function node_ancestors() {
10462   var node = this, nodes = [node];
10463   while (node = node.parent) {
10464     nodes.push(node);
10465   }
10466   return nodes;
10467 }
10468
10469 function node_descendants() {
10470   var nodes = [];
10471   this.each(function(node) {
10472     nodes.push(node);
10473   });
10474   return nodes;
10475 }
10476
10477 function node_leaves() {
10478   var leaves = [];
10479   this.eachBefore(function(node) {
10480     if (!node.children) {
10481       leaves.push(node);
10482     }
10483   });
10484   return leaves;
10485 }
10486
10487 function node_links() {
10488   var root = this, links = [];
10489   root.each(function(node) {
10490     if (node !== root) { // Don’t include the root’s parent, if any.
10491       links.push({source: node.parent, target: node});
10492     }
10493   });
10494   return links;
10495 }
10496
10497 function hierarchy(data, children) {
10498   var root = new Node(data),
10499       valued = +data.value && (root.value = data.value),
10500       node,
10501       nodes = [root],
10502       child,
10503       childs,
10504       i,
10505       n;
10506
10507   if (children == null) children = defaultChildren;
10508
10509   while (node = nodes.pop()) {
10510     if (valued) node.value = +node.data.value;
10511     if ((childs = children(node.data)) && (n = childs.length)) {
10512       node.children = new Array(n);
10513       for (i = n - 1; i >= 0; --i) {
10514         nodes.push(child = node.children[i] = new Node(childs[i]));
10515         child.parent = node;
10516         child.depth = node.depth + 1;
10517       }
10518     }
10519   }
10520
10521   return root.eachBefore(computeHeight);
10522 }
10523
10524 function node_copy() {
10525   return hierarchy(this).eachBefore(copyData);
10526 }
10527
10528 function defaultChildren(d) {
10529   return d.children;
10530 }
10531
10532 function copyData(node) {
10533   node.data = node.data.data;
10534 }
10535
10536 function computeHeight(node) {
10537   var height = 0;
10538   do node.height = height;
10539   while ((node = node.parent) && (node.height < ++height));
10540 }
10541
10542 function Node(data) {
10543   this.data = data;
10544   this.depth =
10545   this.height = 0;
10546   this.parent = null;
10547 }
10548
10549 Node.prototype = hierarchy.prototype = {
10550   constructor: Node,
10551   count: node_count,
10552   each: node_each,
10553   eachAfter: node_eachAfter,
10554   eachBefore: node_eachBefore,
10555   sum: node_sum,
10556   sort: node_sort,
10557   path: node_path,
10558   ancestors: node_ancestors,
10559   descendants: node_descendants,
10560   leaves: node_leaves,
10561   links: node_links,
10562   copy: node_copy
10563 };
10564
10565 var slice$4 = Array.prototype.slice;
10566
10567 function shuffle$1(array) {
10568   var m = array.length,
10569       t,
10570       i;
10571
10572   while (m) {
10573     i = Math.random() * m-- | 0;
10574     t = array[m];
10575     array[m] = array[i];
10576     array[i] = t;
10577   }
10578
10579   return array;
10580 }
10581
10582 function enclose(circles) {
10583   var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
10584
10585   while (i < n) {
10586     p = circles[i];
10587     if (e && enclosesWeak(e, p)) ++i;
10588     else e = encloseBasis(B = extendBasis(B, p)), i = 0;
10589   }
10590
10591   return e;
10592 }
10593
10594 function extendBasis(B, p) {
10595   var i, j;
10596
10597   if (enclosesWeakAll(p, B)) return [p];
10598
10599   // If we get here then B must have at least one element.
10600   for (i = 0; i < B.length; ++i) {
10601     if (enclosesNot(p, B[i])
10602         && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
10603       return [B[i], p];
10604     }
10605   }
10606
10607   // If we get here then B must have at least two elements.
10608   for (i = 0; i < B.length - 1; ++i) {
10609     for (j = i + 1; j < B.length; ++j) {
10610       if (enclosesNot(encloseBasis2(B[i], B[j]), p)
10611           && enclosesNot(encloseBasis2(B[i], p), B[j])
10612           && enclosesNot(encloseBasis2(B[j], p), B[i])
10613           && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
10614         return [B[i], B[j], p];
10615       }
10616     }
10617   }
10618
10619   // If we get here then something is very wrong.
10620   throw new Error;
10621 }
10622
10623 function enclosesNot(a, b) {
10624   var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
10625   return dr < 0 || dr * dr < dx * dx + dy * dy;
10626 }
10627
10628 function enclosesWeak(a, b) {
10629   var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10630   return dr > 0 && dr * dr > dx * dx + dy * dy;
10631 }
10632
10633 function enclosesWeakAll(a, B) {
10634   for (var i = 0; i < B.length; ++i) {
10635     if (!enclosesWeak(a, B[i])) {
10636       return false;
10637     }
10638   }
10639   return true;
10640 }
10641
10642 function encloseBasis(B) {
10643   switch (B.length) {
10644     case 1: return encloseBasis1(B[0]);
10645     case 2: return encloseBasis2(B[0], B[1]);
10646     case 3: return encloseBasis3(B[0], B[1], B[2]);
10647   }
10648 }
10649
10650 function encloseBasis1(a) {
10651   return {
10652     x: a.x,
10653     y: a.y,
10654     r: a.r
10655   };
10656 }
10657
10658 function encloseBasis2(a, b) {
10659   var x1 = a.x, y1 = a.y, r1 = a.r,
10660       x2 = b.x, y2 = b.y, r2 = b.r,
10661       x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
10662       l = Math.sqrt(x21 * x21 + y21 * y21);
10663   return {
10664     x: (x1 + x2 + x21 / l * r21) / 2,
10665     y: (y1 + y2 + y21 / l * r21) / 2,
10666     r: (l + r1 + r2) / 2
10667   };
10668 }
10669
10670 function encloseBasis3(a, b, c) {
10671   var x1 = a.x, y1 = a.y, r1 = a.r,
10672       x2 = b.x, y2 = b.y, r2 = b.r,
10673       x3 = c.x, y3 = c.y, r3 = c.r,
10674       a2 = x1 - x2,
10675       a3 = x1 - x3,
10676       b2 = y1 - y2,
10677       b3 = y1 - y3,
10678       c2 = r2 - r1,
10679       c3 = r3 - r1,
10680       d1 = x1 * x1 + y1 * y1 - r1 * r1,
10681       d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
10682       d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
10683       ab = a3 * b2 - a2 * b3,
10684       xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
10685       xb = (b3 * c2 - b2 * c3) / ab,
10686       ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
10687       yb = (a2 * c3 - a3 * c2) / ab,
10688       A = xb * xb + yb * yb - 1,
10689       B = 2 * (r1 + xa * xb + ya * yb),
10690       C = xa * xa + ya * ya - r1 * r1,
10691       r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
10692   return {
10693     x: x1 + xa + xb * r,
10694     y: y1 + ya + yb * r,
10695     r: r
10696   };
10697 }
10698
10699 function place(b, a, c) {
10700   var dx = b.x - a.x, x, a2,
10701       dy = b.y - a.y, y, b2,
10702       d2 = dx * dx + dy * dy;
10703   if (d2) {
10704     a2 = a.r + c.r, a2 *= a2;
10705     b2 = b.r + c.r, b2 *= b2;
10706     if (a2 > b2) {
10707       x = (d2 + b2 - a2) / (2 * d2);
10708       y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
10709       c.x = b.x - x * dx - y * dy;
10710       c.y = b.y - x * dy + y * dx;
10711     } else {
10712       x = (d2 + a2 - b2) / (2 * d2);
10713       y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
10714       c.x = a.x + x * dx - y * dy;
10715       c.y = a.y + x * dy + y * dx;
10716     }
10717   } else {
10718     c.x = a.x + c.r;
10719     c.y = a.y;
10720   }
10721 }
10722
10723 function intersects(a, b) {
10724   var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10725   return dr > 0 && dr * dr > dx * dx + dy * dy;
10726 }
10727
10728 function score(node) {
10729   var a = node._,
10730       b = node.next._,
10731       ab = a.r + b.r,
10732       dx = (a.x * b.r + b.x * a.r) / ab,
10733       dy = (a.y * b.r + b.y * a.r) / ab;
10734   return dx * dx + dy * dy;
10735 }
10736
10737 function Node$1(circle) {
10738   this._ = circle;
10739   this.next = null;
10740   this.previous = null;
10741 }
10742
10743 function packEnclose(circles) {
10744   if (!(n = circles.length)) return 0;
10745
10746   var a, b, c, n, aa, ca, i, j, k, sj, sk;
10747
10748   // Place the first circle.
10749   a = circles[0], a.x = 0, a.y = 0;
10750   if (!(n > 1)) return a.r;
10751
10752   // Place the second circle.
10753   b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
10754   if (!(n > 2)) return a.r + b.r;
10755
10756   // Place the third circle.
10757   place(b, a, c = circles[2]);
10758
10759   // Initialize the front-chain using the first three circles a, b and c.
10760   a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
10761   a.next = c.previous = b;
10762   b.next = a.previous = c;
10763   c.next = b.previous = a;
10764
10765   // Attempt to place each remaining circle…
10766   pack: for (i = 3; i < n; ++i) {
10767     place(a._, b._, c = circles[i]), c = new Node$1(c);
10768
10769     // Find the closest intersecting circle on the front-chain, if any.
10770     // “Closeness” is determined by linear distance along the front-chain.
10771     // “Ahead” or “behind” is likewise determined by linear distance.
10772     j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
10773     do {
10774       if (sj <= sk) {
10775         if (intersects(j._, c._)) {
10776           b = j, a.next = b, b.previous = a, --i;
10777           continue pack;
10778         }
10779         sj += j._.r, j = j.next;
10780       } else {
10781         if (intersects(k._, c._)) {
10782           a = k, a.next = b, b.previous = a, --i;
10783           continue pack;
10784         }
10785         sk += k._.r, k = k.previous;
10786       }
10787     } while (j !== k.next);
10788
10789     // Success! Insert the new circle c between a and b.
10790     c.previous = a, c.next = b, a.next = b.previous = b = c;
10791
10792     // Compute the new closest circle pair to the centroid.
10793     aa = score(a);
10794     while ((c = c.next) !== b) {
10795       if ((ca = score(c)) < aa) {
10796         a = c, aa = ca;
10797       }
10798     }
10799     b = a.next;
10800   }
10801
10802   // Compute the enclosing circle of the front chain.
10803   a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
10804
10805   // Translate the circles to put the enclosing circle around the origin.
10806   for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
10807
10808   return c.r;
10809 }
10810
10811 function siblings(circles) {
10812   packEnclose(circles);
10813   return circles;
10814 }
10815
10816 function optional(f) {
10817   return f == null ? null : required(f);
10818 }
10819
10820 function required(f) {
10821   if (typeof f !== "function") throw new Error;
10822   return f;
10823 }
10824
10825 function constantZero() {
10826   return 0;
10827 }
10828
10829 function constant$9(x) {
10830   return function() {
10831     return x;
10832   };
10833 }
10834
10835 function defaultRadius$1(d) {
10836   return Math.sqrt(d.value);
10837 }
10838
10839 function index$2() {
10840   var radius = null,
10841       dx = 1,
10842       dy = 1,
10843       padding = constantZero;
10844
10845   function pack(root) {
10846     root.x = dx / 2, root.y = dy / 2;
10847     if (radius) {
10848       root.eachBefore(radiusLeaf(radius))
10849           .eachAfter(packChildren(padding, 0.5))
10850           .eachBefore(translateChild(1));
10851     } else {
10852       root.eachBefore(radiusLeaf(defaultRadius$1))
10853           .eachAfter(packChildren(constantZero, 1))
10854           .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
10855           .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
10856     }
10857     return root;
10858   }
10859
10860   pack.radius = function(x) {
10861     return arguments.length ? (radius = optional(x), pack) : radius;
10862   };
10863
10864   pack.size = function(x) {
10865     return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
10866   };
10867
10868   pack.padding = function(x) {
10869     return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
10870   };
10871
10872   return pack;
10873 }
10874
10875 function radiusLeaf(radius) {
10876   return function(node) {
10877     if (!node.children) {
10878       node.r = Math.max(0, +radius(node) || 0);
10879     }
10880   };
10881 }
10882
10883 function packChildren(padding, k) {
10884   return function(node) {
10885     if (children = node.children) {
10886       var children,
10887           i,
10888           n = children.length,
10889           r = padding(node) * k || 0,
10890           e;
10891
10892       if (r) for (i = 0; i < n; ++i) children[i].r += r;
10893       e = packEnclose(children);
10894       if (r) for (i = 0; i < n; ++i) children[i].r -= r;
10895       node.r = e + r;
10896     }
10897   };
10898 }
10899
10900 function translateChild(k) {
10901   return function(node) {
10902     var parent = node.parent;
10903     node.r *= k;
10904     if (parent) {
10905       node.x = parent.x + k * node.x;
10906       node.y = parent.y + k * node.y;
10907     }
10908   };
10909 }
10910
10911 function roundNode(node) {
10912   node.x0 = Math.round(node.x0);
10913   node.y0 = Math.round(node.y0);
10914   node.x1 = Math.round(node.x1);
10915   node.y1 = Math.round(node.y1);
10916 }
10917
10918 function treemapDice(parent, x0, y0, x1, y1) {
10919   var nodes = parent.children,
10920       node,
10921       i = -1,
10922       n = nodes.length,
10923       k = parent.value && (x1 - x0) / parent.value;
10924
10925   while (++i < n) {
10926     node = nodes[i], node.y0 = y0, node.y1 = y1;
10927     node.x0 = x0, node.x1 = x0 += node.value * k;
10928   }
10929 }
10930
10931 function partition() {
10932   var dx = 1,
10933       dy = 1,
10934       padding = 0,
10935       round = false;
10936
10937   function partition(root) {
10938     var n = root.height + 1;
10939     root.x0 =
10940     root.y0 = padding;
10941     root.x1 = dx;
10942     root.y1 = dy / n;
10943     root.eachBefore(positionNode(dy, n));
10944     if (round) root.eachBefore(roundNode);
10945     return root;
10946   }
10947
10948   function positionNode(dy, n) {
10949     return function(node) {
10950       if (node.children) {
10951         treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
10952       }
10953       var x0 = node.x0,
10954           y0 = node.y0,
10955           x1 = node.x1 - padding,
10956           y1 = node.y1 - padding;
10957       if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10958       if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10959       node.x0 = x0;
10960       node.y0 = y0;
10961       node.x1 = x1;
10962       node.y1 = y1;
10963     };
10964   }
10965
10966   partition.round = function(x) {
10967     return arguments.length ? (round = !!x, partition) : round;
10968   };
10969
10970   partition.size = function(x) {
10971     return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
10972   };
10973
10974   partition.padding = function(x) {
10975     return arguments.length ? (padding = +x, partition) : padding;
10976   };
10977
10978   return partition;
10979 }
10980
10981 var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
10982     preroot = {depth: -1},
10983     ambiguous = {};
10984
10985 function defaultId(d) {
10986   return d.id;
10987 }
10988
10989 function defaultParentId(d) {
10990   return d.parentId;
10991 }
10992
10993 function stratify() {
10994   var id = defaultId,
10995       parentId = defaultParentId;
10996
10997   function stratify(data) {
10998     var d,
10999         i,
11000         n = data.length,
11001         root,
11002         parent,
11003         node,
11004         nodes = new Array(n),
11005         nodeId,
11006         nodeKey,
11007         nodeByKey = {};
11008
11009     for (i = 0; i < n; ++i) {
11010       d = data[i], node = nodes[i] = new Node(d);
11011       if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
11012         nodeKey = keyPrefix$1 + (node.id = nodeId);
11013         nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
11014       }
11015     }
11016
11017     for (i = 0; i < n; ++i) {
11018       node = nodes[i], nodeId = parentId(data[i], i, data);
11019       if (nodeId == null || !(nodeId += "")) {
11020         if (root) throw new Error("multiple roots");
11021         root = node;
11022       } else {
11023         parent = nodeByKey[keyPrefix$1 + nodeId];
11024         if (!parent) throw new Error("missing: " + nodeId);
11025         if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
11026         if (parent.children) parent.children.push(node);
11027         else parent.children = [node];
11028         node.parent = parent;
11029       }
11030     }
11031
11032     if (!root) throw new Error("no root");
11033     root.parent = preroot;
11034     root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
11035     root.parent = null;
11036     if (n > 0) throw new Error("cycle");
11037
11038     return root;
11039   }
11040
11041   stratify.id = function(x) {
11042     return arguments.length ? (id = required(x), stratify) : id;
11043   };
11044
11045   stratify.parentId = function(x) {
11046     return arguments.length ? (parentId = required(x), stratify) : parentId;
11047   };
11048
11049   return stratify;
11050 }
11051
11052 function defaultSeparation$1(a, b) {
11053   return a.parent === b.parent ? 1 : 2;
11054 }
11055
11056 // function radialSeparation(a, b) {
11057 //   return (a.parent === b.parent ? 1 : 2) / a.depth;
11058 // }
11059
11060 // This function is used to traverse the left contour of a subtree (or
11061 // subforest). It returns the successor of v on this contour. This successor is
11062 // either given by the leftmost child of v or by the thread of v. The function
11063 // returns null if and only if v is on the highest level of its subtree.
11064 function nextLeft(v) {
11065   var children = v.children;
11066   return children ? children[0] : v.t;
11067 }
11068
11069 // This function works analogously to nextLeft.
11070 function nextRight(v) {
11071   var children = v.children;
11072   return children ? children[children.length - 1] : v.t;
11073 }
11074
11075 // Shifts the current subtree rooted at w+. This is done by increasing
11076 // prelim(w+) and mod(w+) by shift.
11077 function moveSubtree(wm, wp, shift) {
11078   var change = shift / (wp.i - wm.i);
11079   wp.c -= change;
11080   wp.s += shift;
11081   wm.c += change;
11082   wp.z += shift;
11083   wp.m += shift;
11084 }
11085
11086 // All other shifts, applied to the smaller subtrees between w- and w+, are
11087 // performed by this function. To prepare the shifts, we have to adjust
11088 // change(w+), shift(w+), and change(w-).
11089 function executeShifts(v) {
11090   var shift = 0,
11091       change = 0,
11092       children = v.children,
11093       i = children.length,
11094       w;
11095   while (--i >= 0) {
11096     w = children[i];
11097     w.z += shift;
11098     w.m += shift;
11099     shift += w.s + (change += w.c);
11100   }
11101 }
11102
11103 // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
11104 // returns the specified (default) ancestor.
11105 function nextAncestor(vim, v, ancestor) {
11106   return vim.a.parent === v.parent ? vim.a : ancestor;
11107 }
11108
11109 function TreeNode(node, i) {
11110   this._ = node;
11111   this.parent = null;
11112   this.children = null;
11113   this.A = null; // default ancestor
11114   this.a = this; // ancestor
11115   this.z = 0; // prelim
11116   this.m = 0; // mod
11117   this.c = 0; // change
11118   this.s = 0; // shift
11119   this.t = null; // thread
11120   this.i = i; // number
11121 }
11122
11123 TreeNode.prototype = Object.create(Node.prototype);
11124
11125 function treeRoot(root) {
11126   var tree = new TreeNode(root, 0),
11127       node,
11128       nodes = [tree],
11129       child,
11130       children,
11131       i,
11132       n;
11133
11134   while (node = nodes.pop()) {
11135     if (children = node._.children) {
11136       node.children = new Array(n = children.length);
11137       for (i = n - 1; i >= 0; --i) {
11138         nodes.push(child = node.children[i] = new TreeNode(children[i], i));
11139         child.parent = node;
11140       }
11141     }
11142   }
11143
11144   (tree.parent = new TreeNode(null, 0)).children = [tree];
11145   return tree;
11146 }
11147
11148 // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
11149 function tree() {
11150   var separation = defaultSeparation$1,
11151       dx = 1,
11152       dy = 1,
11153       nodeSize = null;
11154
11155   function tree(root) {
11156     var t = treeRoot(root);
11157
11158     // Compute the layout using Buchheim et al.’s algorithm.
11159     t.eachAfter(firstWalk), t.parent.m = -t.z;
11160     t.eachBefore(secondWalk);
11161
11162     // If a fixed node size is specified, scale x and y.
11163     if (nodeSize) root.eachBefore(sizeNode);
11164
11165     // If a fixed tree size is specified, scale x and y based on the extent.
11166     // Compute the left-most, right-most, and depth-most nodes for extents.
11167     else {
11168       var left = root,
11169           right = root,
11170           bottom = root;
11171       root.eachBefore(function(node) {
11172         if (node.x < left.x) left = node;
11173         if (node.x > right.x) right = node;
11174         if (node.depth > bottom.depth) bottom = node;
11175       });
11176       var s = left === right ? 1 : separation(left, right) / 2,
11177           tx = s - left.x,
11178           kx = dx / (right.x + s + tx),
11179           ky = dy / (bottom.depth || 1);
11180       root.eachBefore(function(node) {
11181         node.x = (node.x + tx) * kx;
11182         node.y = node.depth * ky;
11183       });
11184     }
11185
11186     return root;
11187   }
11188
11189   // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
11190   // applied recursively to the children of v, as well as the function
11191   // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
11192   // node v is placed to the midpoint of its outermost children.
11193   function firstWalk(v) {
11194     var children = v.children,
11195         siblings = v.parent.children,
11196         w = v.i ? siblings[v.i - 1] : null;
11197     if (children) {
11198       executeShifts(v);
11199       var midpoint = (children[0].z + children[children.length - 1].z) / 2;
11200       if (w) {
11201         v.z = w.z + separation(v._, w._);
11202         v.m = v.z - midpoint;
11203       } else {
11204         v.z = midpoint;
11205       }
11206     } else if (w) {
11207       v.z = w.z + separation(v._, w._);
11208     }
11209     v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
11210   }
11211
11212   // Computes all real x-coordinates by summing up the modifiers recursively.
11213   function secondWalk(v) {
11214     v._.x = v.z + v.parent.m;
11215     v.m += v.parent.m;
11216   }
11217
11218   // The core of the algorithm. Here, a new subtree is combined with the
11219   // previous subtrees. Threads are used to traverse the inside and outside
11220   // contours of the left and right subtree up to the highest common level. The
11221   // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
11222   // superscript o means outside and i means inside, the subscript - means left
11223   // subtree and + means right subtree. For summing up the modifiers along the
11224   // contour, we use respective variables si+, si-, so-, and so+. Whenever two
11225   // nodes of the inside contours conflict, we compute the left one of the
11226   // greatest uncommon ancestors using the function ANCESTOR and call MOVE
11227   // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
11228   // Finally, we add a new thread (if necessary).
11229   function apportion(v, w, ancestor) {
11230     if (w) {
11231       var vip = v,
11232           vop = v,
11233           vim = w,
11234           vom = vip.parent.children[0],
11235           sip = vip.m,
11236           sop = vop.m,
11237           sim = vim.m,
11238           som = vom.m,
11239           shift;
11240       while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
11241         vom = nextLeft(vom);
11242         vop = nextRight(vop);
11243         vop.a = v;
11244         shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
11245         if (shift > 0) {
11246           moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
11247           sip += shift;
11248           sop += shift;
11249         }
11250         sim += vim.m;
11251         sip += vip.m;
11252         som += vom.m;
11253         sop += vop.m;
11254       }
11255       if (vim && !nextRight(vop)) {
11256         vop.t = vim;
11257         vop.m += sim - sop;
11258       }
11259       if (vip && !nextLeft(vom)) {
11260         vom.t = vip;
11261         vom.m += sip - som;
11262         ancestor = v;
11263       }
11264     }
11265     return ancestor;
11266   }
11267
11268   function sizeNode(node) {
11269     node.x *= dx;
11270     node.y = node.depth * dy;
11271   }
11272
11273   tree.separation = function(x) {
11274     return arguments.length ? (separation = x, tree) : separation;
11275   };
11276
11277   tree.size = function(x) {
11278     return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
11279   };
11280
11281   tree.nodeSize = function(x) {
11282     return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
11283   };
11284
11285   return tree;
11286 }
11287
11288 function treemapSlice(parent, x0, y0, x1, y1) {
11289   var nodes = parent.children,
11290       node,
11291       i = -1,
11292       n = nodes.length,
11293       k = parent.value && (y1 - y0) / parent.value;
11294
11295   while (++i < n) {
11296     node = nodes[i], node.x0 = x0, node.x1 = x1;
11297     node.y0 = y0, node.y1 = y0 += node.value * k;
11298   }
11299 }
11300
11301 var phi = (1 + Math.sqrt(5)) / 2;
11302
11303 function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
11304   var rows = [],
11305       nodes = parent.children,
11306       row,
11307       nodeValue,
11308       i0 = 0,
11309       i1 = 0,
11310       n = nodes.length,
11311       dx, dy,
11312       value = parent.value,
11313       sumValue,
11314       minValue,
11315       maxValue,
11316       newRatio,
11317       minRatio,
11318       alpha,
11319       beta;
11320
11321   while (i0 < n) {
11322     dx = x1 - x0, dy = y1 - y0;
11323
11324     // Find the next non-empty node.
11325     do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
11326     minValue = maxValue = sumValue;
11327     alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
11328     beta = sumValue * sumValue * alpha;
11329     minRatio = Math.max(maxValue / beta, beta / minValue);
11330
11331     // Keep adding nodes while the aspect ratio maintains or improves.
11332     for (; i1 < n; ++i1) {
11333       sumValue += nodeValue = nodes[i1].value;
11334       if (nodeValue < minValue) minValue = nodeValue;
11335       if (nodeValue > maxValue) maxValue = nodeValue;
11336       beta = sumValue * sumValue * alpha;
11337       newRatio = Math.max(maxValue / beta, beta / minValue);
11338       if (newRatio > minRatio) { sumValue -= nodeValue; break; }
11339       minRatio = newRatio;
11340     }
11341
11342     // Position and record the row orientation.
11343     rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
11344     if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
11345     else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
11346     value -= sumValue, i0 = i1;
11347   }
11348
11349   return rows;
11350 }
11351
11352 var squarify = (function custom(ratio) {
11353
11354   function squarify(parent, x0, y0, x1, y1) {
11355     squarifyRatio(ratio, parent, x0, y0, x1, y1);
11356   }
11357
11358   squarify.ratio = function(x) {
11359     return custom((x = +x) > 1 ? x : 1);
11360   };
11361
11362   return squarify;
11363 })(phi);
11364
11365 function index$3() {
11366   var tile = squarify,
11367       round = false,
11368       dx = 1,
11369       dy = 1,
11370       paddingStack = [0],
11371       paddingInner = constantZero,
11372       paddingTop = constantZero,
11373       paddingRight = constantZero,
11374       paddingBottom = constantZero,
11375       paddingLeft = constantZero;
11376
11377   function treemap(root) {
11378     root.x0 =
11379     root.y0 = 0;
11380     root.x1 = dx;
11381     root.y1 = dy;
11382     root.eachBefore(positionNode);
11383     paddingStack = [0];
11384     if (round) root.eachBefore(roundNode);
11385     return root;
11386   }
11387
11388   function positionNode(node) {
11389     var p = paddingStack[node.depth],
11390         x0 = node.x0 + p,
11391         y0 = node.y0 + p,
11392         x1 = node.x1 - p,
11393         y1 = node.y1 - p;
11394     if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11395     if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11396     node.x0 = x0;
11397     node.y0 = y0;
11398     node.x1 = x1;
11399     node.y1 = y1;
11400     if (node.children) {
11401       p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
11402       x0 += paddingLeft(node) - p;
11403       y0 += paddingTop(node) - p;
11404       x1 -= paddingRight(node) - p;
11405       y1 -= paddingBottom(node) - p;
11406       if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11407       if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11408       tile(node, x0, y0, x1, y1);
11409     }
11410   }
11411
11412   treemap.round = function(x) {
11413     return arguments.length ? (round = !!x, treemap) : round;
11414   };
11415
11416   treemap.size = function(x) {
11417     return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
11418   };
11419
11420   treemap.tile = function(x) {
11421     return arguments.length ? (tile = required(x), treemap) : tile;
11422   };
11423
11424   treemap.padding = function(x) {
11425     return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
11426   };
11427
11428   treemap.paddingInner = function(x) {
11429     return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
11430   };
11431
11432   treemap.paddingOuter = function(x) {
11433     return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
11434   };
11435
11436   treemap.paddingTop = function(x) {
11437     return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
11438   };
11439
11440   treemap.paddingRight = function(x) {
11441     return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
11442   };
11443
11444   treemap.paddingBottom = function(x) {
11445     return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
11446   };
11447
11448   treemap.paddingLeft = function(x) {
11449     return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
11450   };
11451
11452   return treemap;
11453 }
11454
11455 function binary(parent, x0, y0, x1, y1) {
11456   var nodes = parent.children,
11457       i, n = nodes.length,
11458       sum, sums = new Array(n + 1);
11459
11460   for (sums[0] = sum = i = 0; i < n; ++i) {
11461     sums[i + 1] = sum += nodes[i].value;
11462   }
11463
11464   partition(0, n, parent.value, x0, y0, x1, y1);
11465
11466   function partition(i, j, value, x0, y0, x1, y1) {
11467     if (i >= j - 1) {
11468       var node = nodes[i];
11469       node.x0 = x0, node.y0 = y0;
11470       node.x1 = x1, node.y1 = y1;
11471       return;
11472     }
11473
11474     var valueOffset = sums[i],
11475         valueTarget = (value / 2) + valueOffset,
11476         k = i + 1,
11477         hi = j - 1;
11478
11479     while (k < hi) {
11480       var mid = k + hi >>> 1;
11481       if (sums[mid] < valueTarget) k = mid + 1;
11482       else hi = mid;
11483     }
11484
11485     if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
11486
11487     var valueLeft = sums[k] - valueOffset,
11488         valueRight = value - valueLeft;
11489
11490     if ((x1 - x0) > (y1 - y0)) {
11491       var xk = (x0 * valueRight + x1 * valueLeft) / value;
11492       partition(i, k, valueLeft, x0, y0, xk, y1);
11493       partition(k, j, valueRight, xk, y0, x1, y1);
11494     } else {
11495       var yk = (y0 * valueRight + y1 * valueLeft) / value;
11496       partition(i, k, valueLeft, x0, y0, x1, yk);
11497       partition(k, j, valueRight, x0, yk, x1, y1);
11498     }
11499   }
11500 }
11501
11502 function sliceDice(parent, x0, y0, x1, y1) {
11503   (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
11504 }
11505
11506 var resquarify = (function custom(ratio) {
11507
11508   function resquarify(parent, x0, y0, x1, y1) {
11509     if ((rows = parent._squarify) && (rows.ratio === ratio)) {
11510       var rows,
11511           row,
11512           nodes,
11513           i,
11514           j = -1,
11515           n,
11516           m = rows.length,
11517           value = parent.value;
11518
11519       while (++j < m) {
11520         row = rows[j], nodes = row.children;
11521         for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
11522         if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
11523         else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
11524         value -= row.value;
11525       }
11526     } else {
11527       parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
11528       rows.ratio = ratio;
11529     }
11530   }
11531
11532   resquarify.ratio = function(x) {
11533     return custom((x = +x) > 1 ? x : 1);
11534   };
11535
11536   return resquarify;
11537 })(phi);
11538
11539 function area$2(polygon) {
11540   var i = -1,
11541       n = polygon.length,
11542       a,
11543       b = polygon[n - 1],
11544       area = 0;
11545
11546   while (++i < n) {
11547     a = b;
11548     b = polygon[i];
11549     area += a[1] * b[0] - a[0] * b[1];
11550   }
11551
11552   return area / 2;
11553 }
11554
11555 function centroid$1(polygon) {
11556   var i = -1,
11557       n = polygon.length,
11558       x = 0,
11559       y = 0,
11560       a,
11561       b = polygon[n - 1],
11562       c,
11563       k = 0;
11564
11565   while (++i < n) {
11566     a = b;
11567     b = polygon[i];
11568     k += c = a[0] * b[1] - b[0] * a[1];
11569     x += (a[0] + b[0]) * c;
11570     y += (a[1] + b[1]) * c;
11571   }
11572
11573   return k *= 3, [x / k, y / k];
11574 }
11575
11576 // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
11577 // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
11578 // right, +y is up). Returns a positive value if ABC is counter-clockwise,
11579 // negative if clockwise, and zero if the points are collinear.
11580 function cross$1(a, b, c) {
11581   return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
11582 }
11583
11584 function lexicographicOrder(a, b) {
11585   return a[0] - b[0] || a[1] - b[1];
11586 }
11587
11588 // Computes the upper convex hull per the monotone chain algorithm.
11589 // Assumes points.length >= 3, is sorted by x, unique in y.
11590 // Returns an array of indices into points in left-to-right order.
11591 function computeUpperHullIndexes(points) {
11592   var n = points.length,
11593       indexes = [0, 1],
11594       size = 2;
11595
11596   for (var i = 2; i < n; ++i) {
11597     while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
11598     indexes[size++] = i;
11599   }
11600
11601   return indexes.slice(0, size); // remove popped points
11602 }
11603
11604 function hull(points) {
11605   if ((n = points.length) < 3) return null;
11606
11607   var i,
11608       n,
11609       sortedPoints = new Array(n),
11610       flippedPoints = new Array(n);
11611
11612   for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
11613   sortedPoints.sort(lexicographicOrder);
11614   for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
11615
11616   var upperIndexes = computeUpperHullIndexes(sortedPoints),
11617       lowerIndexes = computeUpperHullIndexes(flippedPoints);
11618
11619   // Construct the hull polygon, removing possible duplicate endpoints.
11620   var skipLeft = lowerIndexes[0] === upperIndexes[0],
11621       skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
11622       hull = [];
11623
11624   // Add upper hull in right-to-l order.
11625   // Then add lower hull in left-to-right order.
11626   for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
11627   for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
11628
11629   return hull;
11630 }
11631
11632 function contains$2(polygon, point) {
11633   var n = polygon.length,
11634       p = polygon[n - 1],
11635       x = point[0], y = point[1],
11636       x0 = p[0], y0 = p[1],
11637       x1, y1,
11638       inside = false;
11639
11640   for (var i = 0; i < n; ++i) {
11641     p = polygon[i], x1 = p[0], y1 = p[1];
11642     if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
11643     x0 = x1, y0 = y1;
11644   }
11645
11646   return inside;
11647 }
11648
11649 function length$2(polygon) {
11650   var i = -1,
11651       n = polygon.length,
11652       b = polygon[n - 1],
11653       xa,
11654       ya,
11655       xb = b[0],
11656       yb = b[1],
11657       perimeter = 0;
11658
11659   while (++i < n) {
11660     xa = xb;
11661     ya = yb;
11662     b = polygon[i];
11663     xb = b[0];
11664     yb = b[1];
11665     xa -= xb;
11666     ya -= yb;
11667     perimeter += Math.sqrt(xa * xa + ya * ya);
11668   }
11669
11670   return perimeter;
11671 }
11672
11673 function defaultSource$1() {
11674   return Math.random();
11675 }
11676
11677 var uniform = (function sourceRandomUniform(source) {
11678   function randomUniform(min, max) {
11679     min = min == null ? 0 : +min;
11680     max = max == null ? 1 : +max;
11681     if (arguments.length === 1) max = min, min = 0;
11682     else max -= min;
11683     return function() {
11684       return source() * max + min;
11685     };
11686   }
11687
11688   randomUniform.source = sourceRandomUniform;
11689
11690   return randomUniform;
11691 })(defaultSource$1);
11692
11693 var normal = (function sourceRandomNormal(source) {
11694   function randomNormal(mu, sigma) {
11695     var x, r;
11696     mu = mu == null ? 0 : +mu;
11697     sigma = sigma == null ? 1 : +sigma;
11698     return function() {
11699       var y;
11700
11701       // If available, use the second previously-generated uniform random.
11702       if (x != null) y = x, x = null;
11703
11704       // Otherwise, generate a new x and y.
11705       else do {
11706         x = source() * 2 - 1;
11707         y = source() * 2 - 1;
11708         r = x * x + y * y;
11709       } while (!r || r > 1);
11710
11711       return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
11712     };
11713   }
11714
11715   randomNormal.source = sourceRandomNormal;
11716
11717   return randomNormal;
11718 })(defaultSource$1);
11719
11720 var logNormal = (function sourceRandomLogNormal(source) {
11721   function randomLogNormal() {
11722     var randomNormal = normal.source(source).apply(this, arguments);
11723     return function() {
11724       return Math.exp(randomNormal());
11725     };
11726   }
11727
11728   randomLogNormal.source = sourceRandomLogNormal;
11729
11730   return randomLogNormal;
11731 })(defaultSource$1);
11732
11733 var irwinHall = (function sourceRandomIrwinHall(source) {
11734   function randomIrwinHall(n) {
11735     return function() {
11736       for (var sum = 0, i = 0; i < n; ++i) sum += source();
11737       return sum;
11738     };
11739   }
11740
11741   randomIrwinHall.source = sourceRandomIrwinHall;
11742
11743   return randomIrwinHall;
11744 })(defaultSource$1);
11745
11746 var bates = (function sourceRandomBates(source) {
11747   function randomBates(n) {
11748     var randomIrwinHall = irwinHall.source(source)(n);
11749     return function() {
11750       return randomIrwinHall() / n;
11751     };
11752   }
11753
11754   randomBates.source = sourceRandomBates;
11755
11756   return randomBates;
11757 })(defaultSource$1);
11758
11759 var exponential$1 = (function sourceRandomExponential(source) {
11760   function randomExponential(lambda) {
11761     return function() {
11762       return -Math.log(1 - source()) / lambda;
11763     };
11764   }
11765
11766   randomExponential.source = sourceRandomExponential;
11767
11768   return randomExponential;
11769 })(defaultSource$1);
11770
11771 var array$3 = Array.prototype;
11772
11773 var map$2 = array$3.map;
11774 var slice$5 = array$3.slice;
11775
11776 var implicit = {name: "implicit"};
11777
11778 function ordinal(range) {
11779   var index = map$1(),
11780       domain = [],
11781       unknown = implicit;
11782
11783   range = range == null ? [] : slice$5.call(range);
11784
11785   function scale(d) {
11786     var key = d + "", i = index.get(key);
11787     if (!i) {
11788       if (unknown !== implicit) return unknown;
11789       index.set(key, i = domain.push(d));
11790     }
11791     return range[(i - 1) % range.length];
11792   }
11793
11794   scale.domain = function(_) {
11795     if (!arguments.length) return domain.slice();
11796     domain = [], index = map$1();
11797     var i = -1, n = _.length, d, key;
11798     while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
11799     return scale;
11800   };
11801
11802   scale.range = function(_) {
11803     return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
11804   };
11805
11806   scale.unknown = function(_) {
11807     return arguments.length ? (unknown = _, scale) : unknown;
11808   };
11809
11810   scale.copy = function() {
11811     return ordinal()
11812         .domain(domain)
11813         .range(range)
11814         .unknown(unknown);
11815   };
11816
11817   return scale;
11818 }
11819
11820 function band() {
11821   var scale = ordinal().unknown(undefined),
11822       domain = scale.domain,
11823       ordinalRange = scale.range,
11824       range$$1 = [0, 1],
11825       step,
11826       bandwidth,
11827       round = false,
11828       paddingInner = 0,
11829       paddingOuter = 0,
11830       align = 0.5;
11831
11832   delete scale.unknown;
11833
11834   function rescale() {
11835     var n = domain().length,
11836         reverse = range$$1[1] < range$$1[0],
11837         start = range$$1[reverse - 0],
11838         stop = range$$1[1 - reverse];
11839     step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
11840     if (round) step = Math.floor(step);
11841     start += (stop - start - step * (n - paddingInner)) * align;
11842     bandwidth = step * (1 - paddingInner);
11843     if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
11844     var values = sequence(n).map(function(i) { return start + step * i; });
11845     return ordinalRange(reverse ? values.reverse() : values);
11846   }
11847
11848   scale.domain = function(_) {
11849     return arguments.length ? (domain(_), rescale()) : domain();
11850   };
11851
11852   scale.range = function(_) {
11853     return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
11854   };
11855
11856   scale.rangeRound = function(_) {
11857     return range$$1 = [+_[0], +_[1]], round = true, rescale();
11858   };
11859
11860   scale.bandwidth = function() {
11861     return bandwidth;
11862   };
11863
11864   scale.step = function() {
11865     return step;
11866   };
11867
11868   scale.round = function(_) {
11869     return arguments.length ? (round = !!_, rescale()) : round;
11870   };
11871
11872   scale.padding = function(_) {
11873     return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11874   };
11875
11876   scale.paddingInner = function(_) {
11877     return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11878   };
11879
11880   scale.paddingOuter = function(_) {
11881     return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
11882   };
11883
11884   scale.align = function(_) {
11885     return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
11886   };
11887
11888   scale.copy = function() {
11889     return band()
11890         .domain(domain())
11891         .range(range$$1)
11892         .round(round)
11893         .paddingInner(paddingInner)
11894         .paddingOuter(paddingOuter)
11895         .align(align);
11896   };
11897
11898   return rescale();
11899 }
11900
11901 function pointish(scale) {
11902   var copy = scale.copy;
11903
11904   scale.padding = scale.paddingOuter;
11905   delete scale.paddingInner;
11906   delete scale.paddingOuter;
11907
11908   scale.copy = function() {
11909     return pointish(copy());
11910   };
11911
11912   return scale;
11913 }
11914
11915 function point$1() {
11916   return pointish(band().paddingInner(1));
11917 }
11918
11919 function constant$10(x) {
11920   return function() {
11921     return x;
11922   };
11923 }
11924
11925 function number$2(x) {
11926   return +x;
11927 }
11928
11929 var unit = [0, 1];
11930
11931 function deinterpolateLinear(a, b) {
11932   return (b -= (a = +a))
11933       ? function(x) { return (x - a) / b; }
11934       : constant$10(b);
11935 }
11936
11937 function deinterpolateClamp(deinterpolate) {
11938   return function(a, b) {
11939     var d = deinterpolate(a = +a, b = +b);
11940     return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
11941   };
11942 }
11943
11944 function reinterpolateClamp(reinterpolate$$1) {
11945   return function(a, b) {
11946     var r = reinterpolate$$1(a = +a, b = +b);
11947     return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
11948   };
11949 }
11950
11951 function bimap(domain, range, deinterpolate, reinterpolate$$1) {
11952   var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
11953   if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate$$1(r1, r0);
11954   else d0 = deinterpolate(d0, d1), r0 = reinterpolate$$1(r0, r1);
11955   return function(x) { return r0(d0(x)); };
11956 }
11957
11958 function polymap(domain, range, deinterpolate, reinterpolate$$1) {
11959   var j = Math.min(domain.length, range.length) - 1,
11960       d = new Array(j),
11961       r = new Array(j),
11962       i = -1;
11963
11964   // Reverse descending domains.
11965   if (domain[j] < domain[0]) {
11966     domain = domain.slice().reverse();
11967     range = range.slice().reverse();
11968   }
11969
11970   while (++i < j) {
11971     d[i] = deinterpolate(domain[i], domain[i + 1]);
11972     r[i] = reinterpolate$$1(range[i], range[i + 1]);
11973   }
11974
11975   return function(x) {
11976     var i = bisectRight(domain, x, 1, j) - 1;
11977     return r[i](d[i](x));
11978   };
11979 }
11980
11981 function copy(source, target) {
11982   return target
11983       .domain(source.domain())
11984       .range(source.range())
11985       .interpolate(source.interpolate())
11986       .clamp(source.clamp());
11987 }
11988
11989 // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
11990 // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
11991 function continuous(deinterpolate, reinterpolate$$1) {
11992   var domain = unit,
11993       range = unit,
11994       interpolate$$1 = interpolateValue,
11995       clamp = false,
11996       piecewise$$1,
11997       output,
11998       input;
11999
12000   function rescale() {
12001     piecewise$$1 = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
12002     output = input = null;
12003     return scale;
12004   }
12005
12006   function scale(x) {
12007     return (output || (output = piecewise$$1(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
12008   }
12009
12010   scale.invert = function(y) {
12011     return (input || (input = piecewise$$1(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate$$1) : reinterpolate$$1)))(+y);
12012   };
12013
12014   scale.domain = function(_) {
12015     return arguments.length ? (domain = map$2.call(_, number$2), rescale()) : domain.slice();
12016   };
12017
12018   scale.range = function(_) {
12019     return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12020   };
12021
12022   scale.rangeRound = function(_) {
12023     return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
12024   };
12025
12026   scale.clamp = function(_) {
12027     return arguments.length ? (clamp = !!_, rescale()) : clamp;
12028   };
12029
12030   scale.interpolate = function(_) {
12031     return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
12032   };
12033
12034   return rescale();
12035 }
12036
12037 function tickFormat(domain, count, specifier) {
12038   var start = domain[0],
12039       stop = domain[domain.length - 1],
12040       step = tickStep(start, stop, count == null ? 10 : count),
12041       precision;
12042   specifier = formatSpecifier(specifier == null ? ",f" : specifier);
12043   switch (specifier.type) {
12044     case "s": {
12045       var value = Math.max(Math.abs(start), Math.abs(stop));
12046       if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
12047       return exports.formatPrefix(specifier, value);
12048     }
12049     case "":
12050     case "e":
12051     case "g":
12052     case "p":
12053     case "r": {
12054       if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
12055       break;
12056     }
12057     case "f":
12058     case "%": {
12059       if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
12060       break;
12061     }
12062   }
12063   return exports.format(specifier);
12064 }
12065
12066 function linearish(scale) {
12067   var domain = scale.domain;
12068
12069   scale.ticks = function(count) {
12070     var d = domain();
12071     return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
12072   };
12073
12074   scale.tickFormat = function(count, specifier) {
12075     return tickFormat(domain(), count, specifier);
12076   };
12077
12078   scale.nice = function(count) {
12079     if (count == null) count = 10;
12080
12081     var d = domain(),
12082         i0 = 0,
12083         i1 = d.length - 1,
12084         start = d[i0],
12085         stop = d[i1],
12086         step;
12087
12088     if (stop < start) {
12089       step = start, start = stop, stop = step;
12090       step = i0, i0 = i1, i1 = step;
12091     }
12092
12093     step = tickIncrement(start, stop, count);
12094
12095     if (step > 0) {
12096       start = Math.floor(start / step) * step;
12097       stop = Math.ceil(stop / step) * step;
12098       step = tickIncrement(start, stop, count);
12099     } else if (step < 0) {
12100       start = Math.ceil(start * step) / step;
12101       stop = Math.floor(stop * step) / step;
12102       step = tickIncrement(start, stop, count);
12103     }
12104
12105     if (step > 0) {
12106       d[i0] = Math.floor(start / step) * step;
12107       d[i1] = Math.ceil(stop / step) * step;
12108       domain(d);
12109     } else if (step < 0) {
12110       d[i0] = Math.ceil(start * step) / step;
12111       d[i1] = Math.floor(stop * step) / step;
12112       domain(d);
12113     }
12114
12115     return scale;
12116   };
12117
12118   return scale;
12119 }
12120
12121 function linear$2() {
12122   var scale = continuous(deinterpolateLinear, reinterpolate);
12123
12124   scale.copy = function() {
12125     return copy(scale, linear$2());
12126   };
12127
12128   return linearish(scale);
12129 }
12130
12131 function identity$6() {
12132   var domain = [0, 1];
12133
12134   function scale(x) {
12135     return +x;
12136   }
12137
12138   scale.invert = scale;
12139
12140   scale.domain = scale.range = function(_) {
12141     return arguments.length ? (domain = map$2.call(_, number$2), scale) : domain.slice();
12142   };
12143
12144   scale.copy = function() {
12145     return identity$6().domain(domain);
12146   };
12147
12148   return linearish(scale);
12149 }
12150
12151 function nice(domain, interval) {
12152   domain = domain.slice();
12153
12154   var i0 = 0,
12155       i1 = domain.length - 1,
12156       x0 = domain[i0],
12157       x1 = domain[i1],
12158       t;
12159
12160   if (x1 < x0) {
12161     t = i0, i0 = i1, i1 = t;
12162     t = x0, x0 = x1, x1 = t;
12163   }
12164
12165   domain[i0] = interval.floor(x0);
12166   domain[i1] = interval.ceil(x1);
12167   return domain;
12168 }
12169
12170 function deinterpolate(a, b) {
12171   return (b = Math.log(b / a))
12172       ? function(x) { return Math.log(x / a) / b; }
12173       : constant$10(b);
12174 }
12175
12176 function reinterpolate$1(a, b) {
12177   return a < 0
12178       ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
12179       : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
12180 }
12181
12182 function pow10(x) {
12183   return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
12184 }
12185
12186 function powp(base) {
12187   return base === 10 ? pow10
12188       : base === Math.E ? Math.exp
12189       : function(x) { return Math.pow(base, x); };
12190 }
12191
12192 function logp(base) {
12193   return base === Math.E ? Math.log
12194       : base === 10 && Math.log10
12195       || base === 2 && Math.log2
12196       || (base = Math.log(base), function(x) { return Math.log(x) / base; });
12197 }
12198
12199 function reflect(f) {
12200   return function(x) {
12201     return -f(-x);
12202   };
12203 }
12204
12205 function log$1() {
12206   var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
12207       domain = scale.domain,
12208       base = 10,
12209       logs = logp(10),
12210       pows = powp(10);
12211
12212   function rescale() {
12213     logs = logp(base), pows = powp(base);
12214     if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
12215     return scale;
12216   }
12217
12218   scale.base = function(_) {
12219     return arguments.length ? (base = +_, rescale()) : base;
12220   };
12221
12222   scale.domain = function(_) {
12223     return arguments.length ? (domain(_), rescale()) : domain();
12224   };
12225
12226   scale.ticks = function(count) {
12227     var d = domain(),
12228         u = d[0],
12229         v = d[d.length - 1],
12230         r;
12231
12232     if (r = v < u) i = u, u = v, v = i;
12233
12234     var i = logs(u),
12235         j = logs(v),
12236         p,
12237         k,
12238         t,
12239         n = count == null ? 10 : +count,
12240         z = [];
12241
12242     if (!(base % 1) && j - i < n) {
12243       i = Math.round(i) - 1, j = Math.round(j) + 1;
12244       if (u > 0) for (; i < j; ++i) {
12245         for (k = 1, p = pows(i); k < base; ++k) {
12246           t = p * k;
12247           if (t < u) continue;
12248           if (t > v) break;
12249           z.push(t);
12250         }
12251       } else for (; i < j; ++i) {
12252         for (k = base - 1, p = pows(i); k >= 1; --k) {
12253           t = p * k;
12254           if (t < u) continue;
12255           if (t > v) break;
12256           z.push(t);
12257         }
12258       }
12259     } else {
12260       z = ticks(i, j, Math.min(j - i, n)).map(pows);
12261     }
12262
12263     return r ? z.reverse() : z;
12264   };
12265
12266   scale.tickFormat = function(count, specifier) {
12267     if (specifier == null) specifier = base === 10 ? ".0e" : ",";
12268     if (typeof specifier !== "function") specifier = exports.format(specifier);
12269     if (count === Infinity) return specifier;
12270     if (count == null) count = 10;
12271     var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
12272     return function(d) {
12273       var i = d / pows(Math.round(logs(d)));
12274       if (i * base < base - 0.5) i *= base;
12275       return i <= k ? specifier(d) : "";
12276     };
12277   };
12278
12279   scale.nice = function() {
12280     return domain(nice(domain(), {
12281       floor: function(x) { return pows(Math.floor(logs(x))); },
12282       ceil: function(x) { return pows(Math.ceil(logs(x))); }
12283     }));
12284   };
12285
12286   scale.copy = function() {
12287     return copy(scale, log$1().base(base));
12288   };
12289
12290   return scale;
12291 }
12292
12293 function raise$1(x, exponent) {
12294   return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
12295 }
12296
12297 function pow$1() {
12298   var exponent = 1,
12299       scale = continuous(deinterpolate, reinterpolate),
12300       domain = scale.domain;
12301
12302   function deinterpolate(a, b) {
12303     return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
12304         ? function(x) { return (raise$1(x, exponent) - a) / b; }
12305         : constant$10(b);
12306   }
12307
12308   function reinterpolate(a, b) {
12309     b = raise$1(b, exponent) - (a = raise$1(a, exponent));
12310     return function(t) { return raise$1(a + b * t, 1 / exponent); };
12311   }
12312
12313   scale.exponent = function(_) {
12314     return arguments.length ? (exponent = +_, domain(domain())) : exponent;
12315   };
12316
12317   scale.copy = function() {
12318     return copy(scale, pow$1().exponent(exponent));
12319   };
12320
12321   return linearish(scale);
12322 }
12323
12324 function sqrt$1() {
12325   return pow$1().exponent(0.5);
12326 }
12327
12328 function quantile$$1() {
12329   var domain = [],
12330       range = [],
12331       thresholds = [];
12332
12333   function rescale() {
12334     var i = 0, n = Math.max(1, range.length);
12335     thresholds = new Array(n - 1);
12336     while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
12337     return scale;
12338   }
12339
12340   function scale(x) {
12341     if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
12342   }
12343
12344   scale.invertExtent = function(y) {
12345     var i = range.indexOf(y);
12346     return i < 0 ? [NaN, NaN] : [
12347       i > 0 ? thresholds[i - 1] : domain[0],
12348       i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
12349     ];
12350   };
12351
12352   scale.domain = function(_) {
12353     if (!arguments.length) return domain.slice();
12354     domain = [];
12355     for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
12356     domain.sort(ascending);
12357     return rescale();
12358   };
12359
12360   scale.range = function(_) {
12361     return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12362   };
12363
12364   scale.quantiles = function() {
12365     return thresholds.slice();
12366   };
12367
12368   scale.copy = function() {
12369     return quantile$$1()
12370         .domain(domain)
12371         .range(range);
12372   };
12373
12374   return scale;
12375 }
12376
12377 function quantize$1() {
12378   var x0 = 0,
12379       x1 = 1,
12380       n = 1,
12381       domain = [0.5],
12382       range = [0, 1];
12383
12384   function scale(x) {
12385     if (x <= x) return range[bisectRight(domain, x, 0, n)];
12386   }
12387
12388   function rescale() {
12389     var i = -1;
12390     domain = new Array(n);
12391     while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
12392     return scale;
12393   }
12394
12395   scale.domain = function(_) {
12396     return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
12397   };
12398
12399   scale.range = function(_) {
12400     return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
12401   };
12402
12403   scale.invertExtent = function(y) {
12404     var i = range.indexOf(y);
12405     return i < 0 ? [NaN, NaN]
12406         : i < 1 ? [x0, domain[0]]
12407         : i >= n ? [domain[n - 1], x1]
12408         : [domain[i - 1], domain[i]];
12409   };
12410
12411   scale.copy = function() {
12412     return quantize$1()
12413         .domain([x0, x1])
12414         .range(range);
12415   };
12416
12417   return linearish(scale);
12418 }
12419
12420 function threshold$1() {
12421   var domain = [0.5],
12422       range = [0, 1],
12423       n = 1;
12424
12425   function scale(x) {
12426     if (x <= x) return range[bisectRight(domain, x, 0, n)];
12427   }
12428
12429   scale.domain = function(_) {
12430     return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
12431   };
12432
12433   scale.range = function(_) {
12434     return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
12435   };
12436
12437   scale.invertExtent = function(y) {
12438     var i = range.indexOf(y);
12439     return [domain[i - 1], domain[i]];
12440   };
12441
12442   scale.copy = function() {
12443     return threshold$1()
12444         .domain(domain)
12445         .range(range);
12446   };
12447
12448   return scale;
12449 }
12450
12451 var t0$1 = new Date,
12452     t1$1 = new Date;
12453
12454 function newInterval(floori, offseti, count, field) {
12455
12456   function interval(date) {
12457     return floori(date = new Date(+date)), date;
12458   }
12459
12460   interval.floor = interval;
12461
12462   interval.ceil = function(date) {
12463     return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
12464   };
12465
12466   interval.round = function(date) {
12467     var d0 = interval(date),
12468         d1 = interval.ceil(date);
12469     return date - d0 < d1 - date ? d0 : d1;
12470   };
12471
12472   interval.offset = function(date, step) {
12473     return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
12474   };
12475
12476   interval.range = function(start, stop, step) {
12477     var range = [], previous;
12478     start = interval.ceil(start);
12479     step = step == null ? 1 : Math.floor(step);
12480     if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
12481     do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
12482     while (previous < start && start < stop);
12483     return range;
12484   };
12485
12486   interval.filter = function(test) {
12487     return newInterval(function(date) {
12488       if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
12489     }, function(date, step) {
12490       if (date >= date) {
12491         if (step < 0) while (++step <= 0) {
12492           while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
12493         } else while (--step >= 0) {
12494           while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
12495         }
12496       }
12497     });
12498   };
12499
12500   if (count) {
12501     interval.count = function(start, end) {
12502       t0$1.setTime(+start), t1$1.setTime(+end);
12503       floori(t0$1), floori(t1$1);
12504       return Math.floor(count(t0$1, t1$1));
12505     };
12506
12507     interval.every = function(step) {
12508       step = Math.floor(step);
12509       return !isFinite(step) || !(step > 0) ? null
12510           : !(step > 1) ? interval
12511           : interval.filter(field
12512               ? function(d) { return field(d) % step === 0; }
12513               : function(d) { return interval.count(0, d) % step === 0; });
12514     };
12515   }
12516
12517   return interval;
12518 }
12519
12520 var millisecond = newInterval(function() {
12521   // noop
12522 }, function(date, step) {
12523   date.setTime(+date + step);
12524 }, function(start, end) {
12525   return end - start;
12526 });
12527
12528 // An optimized implementation for this simple case.
12529 millisecond.every = function(k) {
12530   k = Math.floor(k);
12531   if (!isFinite(k) || !(k > 0)) return null;
12532   if (!(k > 1)) return millisecond;
12533   return newInterval(function(date) {
12534     date.setTime(Math.floor(date / k) * k);
12535   }, function(date, step) {
12536     date.setTime(+date + step * k);
12537   }, function(start, end) {
12538     return (end - start) / k;
12539   });
12540 };
12541 var milliseconds = millisecond.range;
12542
12543 var durationSecond = 1e3;
12544 var durationMinute = 6e4;
12545 var durationHour = 36e5;
12546 var durationDay = 864e5;
12547 var durationWeek = 6048e5;
12548
12549 var second = newInterval(function(date) {
12550   date.setTime(Math.floor(date / durationSecond) * durationSecond);
12551 }, function(date, step) {
12552   date.setTime(+date + step * durationSecond);
12553 }, function(start, end) {
12554   return (end - start) / durationSecond;
12555 }, function(date) {
12556   return date.getUTCSeconds();
12557 });
12558 var seconds = second.range;
12559
12560 var minute = newInterval(function(date) {
12561   date.setTime(Math.floor(date / durationMinute) * durationMinute);
12562 }, function(date, step) {
12563   date.setTime(+date + step * durationMinute);
12564 }, function(start, end) {
12565   return (end - start) / durationMinute;
12566 }, function(date) {
12567   return date.getMinutes();
12568 });
12569 var minutes = minute.range;
12570
12571 var hour = newInterval(function(date) {
12572   var offset = date.getTimezoneOffset() * durationMinute % durationHour;
12573   if (offset < 0) offset += durationHour;
12574   date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
12575 }, function(date, step) {
12576   date.setTime(+date + step * durationHour);
12577 }, function(start, end) {
12578   return (end - start) / durationHour;
12579 }, function(date) {
12580   return date.getHours();
12581 });
12582 var hours = hour.range;
12583
12584 var day = newInterval(function(date) {
12585   date.setHours(0, 0, 0, 0);
12586 }, function(date, step) {
12587   date.setDate(date.getDate() + step);
12588 }, function(start, end) {
12589   return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
12590 }, function(date) {
12591   return date.getDate() - 1;
12592 });
12593 var days = day.range;
12594
12595 function weekday(i) {
12596   return newInterval(function(date) {
12597     date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
12598     date.setHours(0, 0, 0, 0);
12599   }, function(date, step) {
12600     date.setDate(date.getDate() + step * 7);
12601   }, function(start, end) {
12602     return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
12603   });
12604 }
12605
12606 var sunday = weekday(0);
12607 var monday = weekday(1);
12608 var tuesday = weekday(2);
12609 var wednesday = weekday(3);
12610 var thursday = weekday(4);
12611 var friday = weekday(5);
12612 var saturday = weekday(6);
12613
12614 var sundays = sunday.range;
12615 var mondays = monday.range;
12616 var tuesdays = tuesday.range;
12617 var wednesdays = wednesday.range;
12618 var thursdays = thursday.range;
12619 var fridays = friday.range;
12620 var saturdays = saturday.range;
12621
12622 var month = newInterval(function(date) {
12623   date.setDate(1);
12624   date.setHours(0, 0, 0, 0);
12625 }, function(date, step) {
12626   date.setMonth(date.getMonth() + step);
12627 }, function(start, end) {
12628   return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
12629 }, function(date) {
12630   return date.getMonth();
12631 });
12632 var months = month.range;
12633
12634 var year = newInterval(function(date) {
12635   date.setMonth(0, 1);
12636   date.setHours(0, 0, 0, 0);
12637 }, function(date, step) {
12638   date.setFullYear(date.getFullYear() + step);
12639 }, function(start, end) {
12640   return end.getFullYear() - start.getFullYear();
12641 }, function(date) {
12642   return date.getFullYear();
12643 });
12644
12645 // An optimized implementation for this simple case.
12646 year.every = function(k) {
12647   return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12648     date.setFullYear(Math.floor(date.getFullYear() / k) * k);
12649     date.setMonth(0, 1);
12650     date.setHours(0, 0, 0, 0);
12651   }, function(date, step) {
12652     date.setFullYear(date.getFullYear() + step * k);
12653   });
12654 };
12655 var years = year.range;
12656
12657 var utcMinute = newInterval(function(date) {
12658   date.setUTCSeconds(0, 0);
12659 }, function(date, step) {
12660   date.setTime(+date + step * durationMinute);
12661 }, function(start, end) {
12662   return (end - start) / durationMinute;
12663 }, function(date) {
12664   return date.getUTCMinutes();
12665 });
12666 var utcMinutes = utcMinute.range;
12667
12668 var utcHour = newInterval(function(date) {
12669   date.setUTCMinutes(0, 0, 0);
12670 }, function(date, step) {
12671   date.setTime(+date + step * durationHour);
12672 }, function(start, end) {
12673   return (end - start) / durationHour;
12674 }, function(date) {
12675   return date.getUTCHours();
12676 });
12677 var utcHours = utcHour.range;
12678
12679 var utcDay = newInterval(function(date) {
12680   date.setUTCHours(0, 0, 0, 0);
12681 }, function(date, step) {
12682   date.setUTCDate(date.getUTCDate() + step);
12683 }, function(start, end) {
12684   return (end - start) / durationDay;
12685 }, function(date) {
12686   return date.getUTCDate() - 1;
12687 });
12688 var utcDays = utcDay.range;
12689
12690 function utcWeekday(i) {
12691   return newInterval(function(date) {
12692     date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
12693     date.setUTCHours(0, 0, 0, 0);
12694   }, function(date, step) {
12695     date.setUTCDate(date.getUTCDate() + step * 7);
12696   }, function(start, end) {
12697     return (end - start) / durationWeek;
12698   });
12699 }
12700
12701 var utcSunday = utcWeekday(0);
12702 var utcMonday = utcWeekday(1);
12703 var utcTuesday = utcWeekday(2);
12704 var utcWednesday = utcWeekday(3);
12705 var utcThursday = utcWeekday(4);
12706 var utcFriday = utcWeekday(5);
12707 var utcSaturday = utcWeekday(6);
12708
12709 var utcSundays = utcSunday.range;
12710 var utcMondays = utcMonday.range;
12711 var utcTuesdays = utcTuesday.range;
12712 var utcWednesdays = utcWednesday.range;
12713 var utcThursdays = utcThursday.range;
12714 var utcFridays = utcFriday.range;
12715 var utcSaturdays = utcSaturday.range;
12716
12717 var utcMonth = newInterval(function(date) {
12718   date.setUTCDate(1);
12719   date.setUTCHours(0, 0, 0, 0);
12720 }, function(date, step) {
12721   date.setUTCMonth(date.getUTCMonth() + step);
12722 }, function(start, end) {
12723   return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
12724 }, function(date) {
12725   return date.getUTCMonth();
12726 });
12727 var utcMonths = utcMonth.range;
12728
12729 var utcYear = newInterval(function(date) {
12730   date.setUTCMonth(0, 1);
12731   date.setUTCHours(0, 0, 0, 0);
12732 }, function(date, step) {
12733   date.setUTCFullYear(date.getUTCFullYear() + step);
12734 }, function(start, end) {
12735   return end.getUTCFullYear() - start.getUTCFullYear();
12736 }, function(date) {
12737   return date.getUTCFullYear();
12738 });
12739
12740 // An optimized implementation for this simple case.
12741 utcYear.every = function(k) {
12742   return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12743     date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
12744     date.setUTCMonth(0, 1);
12745     date.setUTCHours(0, 0, 0, 0);
12746   }, function(date, step) {
12747     date.setUTCFullYear(date.getUTCFullYear() + step * k);
12748   });
12749 };
12750 var utcYears = utcYear.range;
12751
12752 function localDate(d) {
12753   if (0 <= d.y && d.y < 100) {
12754     var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
12755     date.setFullYear(d.y);
12756     return date;
12757   }
12758   return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
12759 }
12760
12761 function utcDate(d) {
12762   if (0 <= d.y && d.y < 100) {
12763     var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
12764     date.setUTCFullYear(d.y);
12765     return date;
12766   }
12767   return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
12768 }
12769
12770 function newYear(y) {
12771   return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
12772 }
12773
12774 function formatLocale$1(locale) {
12775   var locale_dateTime = locale.dateTime,
12776       locale_date = locale.date,
12777       locale_time = locale.time,
12778       locale_periods = locale.periods,
12779       locale_weekdays = locale.days,
12780       locale_shortWeekdays = locale.shortDays,
12781       locale_months = locale.months,
12782       locale_shortMonths = locale.shortMonths;
12783
12784   var periodRe = formatRe(locale_periods),
12785       periodLookup = formatLookup(locale_periods),
12786       weekdayRe = formatRe(locale_weekdays),
12787       weekdayLookup = formatLookup(locale_weekdays),
12788       shortWeekdayRe = formatRe(locale_shortWeekdays),
12789       shortWeekdayLookup = formatLookup(locale_shortWeekdays),
12790       monthRe = formatRe(locale_months),
12791       monthLookup = formatLookup(locale_months),
12792       shortMonthRe = formatRe(locale_shortMonths),
12793       shortMonthLookup = formatLookup(locale_shortMonths);
12794
12795   var formats = {
12796     "a": formatShortWeekday,
12797     "A": formatWeekday,
12798     "b": formatShortMonth,
12799     "B": formatMonth,
12800     "c": null,
12801     "d": formatDayOfMonth,
12802     "e": formatDayOfMonth,
12803     "f": formatMicroseconds,
12804     "H": formatHour24,
12805     "I": formatHour12,
12806     "j": formatDayOfYear,
12807     "L": formatMilliseconds,
12808     "m": formatMonthNumber,
12809     "M": formatMinutes,
12810     "p": formatPeriod,
12811     "Q": formatUnixTimestamp,
12812     "s": formatUnixTimestampSeconds,
12813     "S": formatSeconds,
12814     "u": formatWeekdayNumberMonday,
12815     "U": formatWeekNumberSunday,
12816     "V": formatWeekNumberISO,
12817     "w": formatWeekdayNumberSunday,
12818     "W": formatWeekNumberMonday,
12819     "x": null,
12820     "X": null,
12821     "y": formatYear,
12822     "Y": formatFullYear,
12823     "Z": formatZone,
12824     "%": formatLiteralPercent
12825   };
12826
12827   var utcFormats = {
12828     "a": formatUTCShortWeekday,
12829     "A": formatUTCWeekday,
12830     "b": formatUTCShortMonth,
12831     "B": formatUTCMonth,
12832     "c": null,
12833     "d": formatUTCDayOfMonth,
12834     "e": formatUTCDayOfMonth,
12835     "f": formatUTCMicroseconds,
12836     "H": formatUTCHour24,
12837     "I": formatUTCHour12,
12838     "j": formatUTCDayOfYear,
12839     "L": formatUTCMilliseconds,
12840     "m": formatUTCMonthNumber,
12841     "M": formatUTCMinutes,
12842     "p": formatUTCPeriod,
12843     "Q": formatUnixTimestamp,
12844     "s": formatUnixTimestampSeconds,
12845     "S": formatUTCSeconds,
12846     "u": formatUTCWeekdayNumberMonday,
12847     "U": formatUTCWeekNumberSunday,
12848     "V": formatUTCWeekNumberISO,
12849     "w": formatUTCWeekdayNumberSunday,
12850     "W": formatUTCWeekNumberMonday,
12851     "x": null,
12852     "X": null,
12853     "y": formatUTCYear,
12854     "Y": formatUTCFullYear,
12855     "Z": formatUTCZone,
12856     "%": formatLiteralPercent
12857   };
12858
12859   var parses = {
12860     "a": parseShortWeekday,
12861     "A": parseWeekday,
12862     "b": parseShortMonth,
12863     "B": parseMonth,
12864     "c": parseLocaleDateTime,
12865     "d": parseDayOfMonth,
12866     "e": parseDayOfMonth,
12867     "f": parseMicroseconds,
12868     "H": parseHour24,
12869     "I": parseHour24,
12870     "j": parseDayOfYear,
12871     "L": parseMilliseconds,
12872     "m": parseMonthNumber,
12873     "M": parseMinutes,
12874     "p": parsePeriod,
12875     "Q": parseUnixTimestamp,
12876     "s": parseUnixTimestampSeconds,
12877     "S": parseSeconds,
12878     "u": parseWeekdayNumberMonday,
12879     "U": parseWeekNumberSunday,
12880     "V": parseWeekNumberISO,
12881     "w": parseWeekdayNumberSunday,
12882     "W": parseWeekNumberMonday,
12883     "x": parseLocaleDate,
12884     "X": parseLocaleTime,
12885     "y": parseYear,
12886     "Y": parseFullYear,
12887     "Z": parseZone,
12888     "%": parseLiteralPercent
12889   };
12890
12891   // These recursive directive definitions must be deferred.
12892   formats.x = newFormat(locale_date, formats);
12893   formats.X = newFormat(locale_time, formats);
12894   formats.c = newFormat(locale_dateTime, formats);
12895   utcFormats.x = newFormat(locale_date, utcFormats);
12896   utcFormats.X = newFormat(locale_time, utcFormats);
12897   utcFormats.c = newFormat(locale_dateTime, utcFormats);
12898
12899   function newFormat(specifier, formats) {
12900     return function(date) {
12901       var string = [],
12902           i = -1,
12903           j = 0,
12904           n = specifier.length,
12905           c,
12906           pad,
12907           format;
12908
12909       if (!(date instanceof Date)) date = new Date(+date);
12910
12911       while (++i < n) {
12912         if (specifier.charCodeAt(i) === 37) {
12913           string.push(specifier.slice(j, i));
12914           if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
12915           else pad = c === "e" ? " " : "0";
12916           if (format = formats[c]) c = format(date, pad);
12917           string.push(c);
12918           j = i + 1;
12919         }
12920       }
12921
12922       string.push(specifier.slice(j, i));
12923       return string.join("");
12924     };
12925   }
12926
12927   function newParse(specifier, newDate) {
12928     return function(string) {
12929       var d = newYear(1900),
12930           i = parseSpecifier(d, specifier, string += "", 0),
12931           week, day$$1;
12932       if (i != string.length) return null;
12933
12934       // If a UNIX timestamp is specified, return it.
12935       if ("Q" in d) return new Date(d.Q);
12936
12937       // The am-pm flag is 0 for AM, and 1 for PM.
12938       if ("p" in d) d.H = d.H % 12 + d.p * 12;
12939
12940       // Convert day-of-week and week-of-year to day-of-year.
12941       if ("V" in d) {
12942         if (d.V < 1 || d.V > 53) return null;
12943         if (!("w" in d)) d.w = 1;
12944         if ("Z" in d) {
12945           week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
12946           week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
12947           week = utcDay.offset(week, (d.V - 1) * 7);
12948           d.y = week.getUTCFullYear();
12949           d.m = week.getUTCMonth();
12950           d.d = week.getUTCDate() + (d.w + 6) % 7;
12951         } else {
12952           week = newDate(newYear(d.y)), day$$1 = week.getDay();
12953           week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
12954           week = day.offset(week, (d.V - 1) * 7);
12955           d.y = week.getFullYear();
12956           d.m = week.getMonth();
12957           d.d = week.getDate() + (d.w + 6) % 7;
12958         }
12959       } else if ("W" in d || "U" in d) {
12960         if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
12961         day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
12962         d.m = 0;
12963         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;
12964       }
12965
12966       // If a time zone is specified, all fields are interpreted as UTC and then
12967       // offset according to the specified time zone.
12968       if ("Z" in d) {
12969         d.H += d.Z / 100 | 0;
12970         d.M += d.Z % 100;
12971         return utcDate(d);
12972       }
12973
12974       // Otherwise, all fields are in local time.
12975       return newDate(d);
12976     };
12977   }
12978
12979   function parseSpecifier(d, specifier, string, j) {
12980     var i = 0,
12981         n = specifier.length,
12982         m = string.length,
12983         c,
12984         parse;
12985
12986     while (i < n) {
12987       if (j >= m) return -1;
12988       c = specifier.charCodeAt(i++);
12989       if (c === 37) {
12990         c = specifier.charAt(i++);
12991         parse = parses[c in pads ? specifier.charAt(i++) : c];
12992         if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
12993       } else if (c != string.charCodeAt(j++)) {
12994         return -1;
12995       }
12996     }
12997
12998     return j;
12999   }
13000
13001   function parsePeriod(d, string, i) {
13002     var n = periodRe.exec(string.slice(i));
13003     return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13004   }
13005
13006   function parseShortWeekday(d, string, i) {
13007     var n = shortWeekdayRe.exec(string.slice(i));
13008     return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13009   }
13010
13011   function parseWeekday(d, string, i) {
13012     var n = weekdayRe.exec(string.slice(i));
13013     return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13014   }
13015
13016   function parseShortMonth(d, string, i) {
13017     var n = shortMonthRe.exec(string.slice(i));
13018     return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13019   }
13020
13021   function parseMonth(d, string, i) {
13022     var n = monthRe.exec(string.slice(i));
13023     return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13024   }
13025
13026   function parseLocaleDateTime(d, string, i) {
13027     return parseSpecifier(d, locale_dateTime, string, i);
13028   }
13029
13030   function parseLocaleDate(d, string, i) {
13031     return parseSpecifier(d, locale_date, string, i);
13032   }
13033
13034   function parseLocaleTime(d, string, i) {
13035     return parseSpecifier(d, locale_time, string, i);
13036   }
13037
13038   function formatShortWeekday(d) {
13039     return locale_shortWeekdays[d.getDay()];
13040   }
13041
13042   function formatWeekday(d) {
13043     return locale_weekdays[d.getDay()];
13044   }
13045
13046   function formatShortMonth(d) {
13047     return locale_shortMonths[d.getMonth()];
13048   }
13049
13050   function formatMonth(d) {
13051     return locale_months[d.getMonth()];
13052   }
13053
13054   function formatPeriod(d) {
13055     return locale_periods[+(d.getHours() >= 12)];
13056   }
13057
13058   function formatUTCShortWeekday(d) {
13059     return locale_shortWeekdays[d.getUTCDay()];
13060   }
13061
13062   function formatUTCWeekday(d) {
13063     return locale_weekdays[d.getUTCDay()];
13064   }
13065
13066   function formatUTCShortMonth(d) {
13067     return locale_shortMonths[d.getUTCMonth()];
13068   }
13069
13070   function formatUTCMonth(d) {
13071     return locale_months[d.getUTCMonth()];
13072   }
13073
13074   function formatUTCPeriod(d) {
13075     return locale_periods[+(d.getUTCHours() >= 12)];
13076   }
13077
13078   return {
13079     format: function(specifier) {
13080       var f = newFormat(specifier += "", formats);
13081       f.toString = function() { return specifier; };
13082       return f;
13083     },
13084     parse: function(specifier) {
13085       var p = newParse(specifier += "", localDate);
13086       p.toString = function() { return specifier; };
13087       return p;
13088     },
13089     utcFormat: function(specifier) {
13090       var f = newFormat(specifier += "", utcFormats);
13091       f.toString = function() { return specifier; };
13092       return f;
13093     },
13094     utcParse: function(specifier) {
13095       var p = newParse(specifier, utcDate);
13096       p.toString = function() { return specifier; };
13097       return p;
13098     }
13099   };
13100 }
13101
13102 var pads = {"-": "", "_": " ", "0": "0"},
13103     numberRe = /^\s*\d+/, // note: ignores next directive
13104     percentRe = /^%/,
13105     requoteRe = /[\\^$*+?|[\]().{}]/g;
13106
13107 function pad(value, fill, width) {
13108   var sign = value < 0 ? "-" : "",
13109       string = (sign ? -value : value) + "",
13110       length = string.length;
13111   return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
13112 }
13113
13114 function requote(s) {
13115   return s.replace(requoteRe, "\\$&");
13116 }
13117
13118 function formatRe(names) {
13119   return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
13120 }
13121
13122 function formatLookup(names) {
13123   var map = {}, i = -1, n = names.length;
13124   while (++i < n) map[names[i].toLowerCase()] = i;
13125   return map;
13126 }
13127
13128 function parseWeekdayNumberSunday(d, string, i) {
13129   var n = numberRe.exec(string.slice(i, i + 1));
13130   return n ? (d.w = +n[0], i + n[0].length) : -1;
13131 }
13132
13133 function parseWeekdayNumberMonday(d, string, i) {
13134   var n = numberRe.exec(string.slice(i, i + 1));
13135   return n ? (d.u = +n[0], i + n[0].length) : -1;
13136 }
13137
13138 function parseWeekNumberSunday(d, string, i) {
13139   var n = numberRe.exec(string.slice(i, i + 2));
13140   return n ? (d.U = +n[0], i + n[0].length) : -1;
13141 }
13142
13143 function parseWeekNumberISO(d, string, i) {
13144   var n = numberRe.exec(string.slice(i, i + 2));
13145   return n ? (d.V = +n[0], i + n[0].length) : -1;
13146 }
13147
13148 function parseWeekNumberMonday(d, string, i) {
13149   var n = numberRe.exec(string.slice(i, i + 2));
13150   return n ? (d.W = +n[0], i + n[0].length) : -1;
13151 }
13152
13153 function parseFullYear(d, string, i) {
13154   var n = numberRe.exec(string.slice(i, i + 4));
13155   return n ? (d.y = +n[0], i + n[0].length) : -1;
13156 }
13157
13158 function parseYear(d, string, i) {
13159   var n = numberRe.exec(string.slice(i, i + 2));
13160   return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
13161 }
13162
13163 function parseZone(d, string, i) {
13164   var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
13165   return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
13166 }
13167
13168 function parseMonthNumber(d, string, i) {
13169   var n = numberRe.exec(string.slice(i, i + 2));
13170   return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
13171 }
13172
13173 function parseDayOfMonth(d, string, i) {
13174   var n = numberRe.exec(string.slice(i, i + 2));
13175   return n ? (d.d = +n[0], i + n[0].length) : -1;
13176 }
13177
13178 function parseDayOfYear(d, string, i) {
13179   var n = numberRe.exec(string.slice(i, i + 3));
13180   return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
13181 }
13182
13183 function parseHour24(d, string, i) {
13184   var n = numberRe.exec(string.slice(i, i + 2));
13185   return n ? (d.H = +n[0], i + n[0].length) : -1;
13186 }
13187
13188 function parseMinutes(d, string, i) {
13189   var n = numberRe.exec(string.slice(i, i + 2));
13190   return n ? (d.M = +n[0], i + n[0].length) : -1;
13191 }
13192
13193 function parseSeconds(d, string, i) {
13194   var n = numberRe.exec(string.slice(i, i + 2));
13195   return n ? (d.S = +n[0], i + n[0].length) : -1;
13196 }
13197
13198 function parseMilliseconds(d, string, i) {
13199   var n = numberRe.exec(string.slice(i, i + 3));
13200   return n ? (d.L = +n[0], i + n[0].length) : -1;
13201 }
13202
13203 function parseMicroseconds(d, string, i) {
13204   var n = numberRe.exec(string.slice(i, i + 6));
13205   return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
13206 }
13207
13208 function parseLiteralPercent(d, string, i) {
13209   var n = percentRe.exec(string.slice(i, i + 1));
13210   return n ? i + n[0].length : -1;
13211 }
13212
13213 function parseUnixTimestamp(d, string, i) {
13214   var n = numberRe.exec(string.slice(i));
13215   return n ? (d.Q = +n[0], i + n[0].length) : -1;
13216 }
13217
13218 function parseUnixTimestampSeconds(d, string, i) {
13219   var n = numberRe.exec(string.slice(i));
13220   return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
13221 }
13222
13223 function formatDayOfMonth(d, p) {
13224   return pad(d.getDate(), p, 2);
13225 }
13226
13227 function formatHour24(d, p) {
13228   return pad(d.getHours(), p, 2);
13229 }
13230
13231 function formatHour12(d, p) {
13232   return pad(d.getHours() % 12 || 12, p, 2);
13233 }
13234
13235 function formatDayOfYear(d, p) {
13236   return pad(1 + day.count(year(d), d), p, 3);
13237 }
13238
13239 function formatMilliseconds(d, p) {
13240   return pad(d.getMilliseconds(), p, 3);
13241 }
13242
13243 function formatMicroseconds(d, p) {
13244   return formatMilliseconds(d, p) + "000";
13245 }
13246
13247 function formatMonthNumber(d, p) {
13248   return pad(d.getMonth() + 1, p, 2);
13249 }
13250
13251 function formatMinutes(d, p) {
13252   return pad(d.getMinutes(), p, 2);
13253 }
13254
13255 function formatSeconds(d, p) {
13256   return pad(d.getSeconds(), p, 2);
13257 }
13258
13259 function formatWeekdayNumberMonday(d) {
13260   var day$$1 = d.getDay();
13261   return day$$1 === 0 ? 7 : day$$1;
13262 }
13263
13264 function formatWeekNumberSunday(d, p) {
13265   return pad(sunday.count(year(d), d), p, 2);
13266 }
13267
13268 function formatWeekNumberISO(d, p) {
13269   var day$$1 = d.getDay();
13270   d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
13271   return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
13272 }
13273
13274 function formatWeekdayNumberSunday(d) {
13275   return d.getDay();
13276 }
13277
13278 function formatWeekNumberMonday(d, p) {
13279   return pad(monday.count(year(d), d), p, 2);
13280 }
13281
13282 function formatYear(d, p) {
13283   return pad(d.getFullYear() % 100, p, 2);
13284 }
13285
13286 function formatFullYear(d, p) {
13287   return pad(d.getFullYear() % 10000, p, 4);
13288 }
13289
13290 function formatZone(d) {
13291   var z = d.getTimezoneOffset();
13292   return (z > 0 ? "-" : (z *= -1, "+"))
13293       + pad(z / 60 | 0, "0", 2)
13294       + pad(z % 60, "0", 2);
13295 }
13296
13297 function formatUTCDayOfMonth(d, p) {
13298   return pad(d.getUTCDate(), p, 2);
13299 }
13300
13301 function formatUTCHour24(d, p) {
13302   return pad(d.getUTCHours(), p, 2);
13303 }
13304
13305 function formatUTCHour12(d, p) {
13306   return pad(d.getUTCHours() % 12 || 12, p, 2);
13307 }
13308
13309 function formatUTCDayOfYear(d, p) {
13310   return pad(1 + utcDay.count(utcYear(d), d), p, 3);
13311 }
13312
13313 function formatUTCMilliseconds(d, p) {
13314   return pad(d.getUTCMilliseconds(), p, 3);
13315 }
13316
13317 function formatUTCMicroseconds(d, p) {
13318   return formatUTCMilliseconds(d, p) + "000";
13319 }
13320
13321 function formatUTCMonthNumber(d, p) {
13322   return pad(d.getUTCMonth() + 1, p, 2);
13323 }
13324
13325 function formatUTCMinutes(d, p) {
13326   return pad(d.getUTCMinutes(), p, 2);
13327 }
13328
13329 function formatUTCSeconds(d, p) {
13330   return pad(d.getUTCSeconds(), p, 2);
13331 }
13332
13333 function formatUTCWeekdayNumberMonday(d) {
13334   var dow = d.getUTCDay();
13335   return dow === 0 ? 7 : dow;
13336 }
13337
13338 function formatUTCWeekNumberSunday(d, p) {
13339   return pad(utcSunday.count(utcYear(d), d), p, 2);
13340 }
13341
13342 function formatUTCWeekNumberISO(d, p) {
13343   var day$$1 = d.getUTCDay();
13344   d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
13345   return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
13346 }
13347
13348 function formatUTCWeekdayNumberSunday(d) {
13349   return d.getUTCDay();
13350 }
13351
13352 function formatUTCWeekNumberMonday(d, p) {
13353   return pad(utcMonday.count(utcYear(d), d), p, 2);
13354 }
13355
13356 function formatUTCYear(d, p) {
13357   return pad(d.getUTCFullYear() % 100, p, 2);
13358 }
13359
13360 function formatUTCFullYear(d, p) {
13361   return pad(d.getUTCFullYear() % 10000, p, 4);
13362 }
13363
13364 function formatUTCZone() {
13365   return "+0000";
13366 }
13367
13368 function formatLiteralPercent() {
13369   return "%";
13370 }
13371
13372 function formatUnixTimestamp(d) {
13373   return +d;
13374 }
13375
13376 function formatUnixTimestampSeconds(d) {
13377   return Math.floor(+d / 1000);
13378 }
13379
13380 var locale$1;
13381
13382 defaultLocale$1({
13383   dateTime: "%x, %X",
13384   date: "%-m/%-d/%Y",
13385   time: "%-I:%M:%S %p",
13386   periods: ["AM", "PM"],
13387   days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
13388   shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
13389   months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
13390   shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
13391 });
13392
13393 function defaultLocale$1(definition) {
13394   locale$1 = formatLocale$1(definition);
13395   exports.timeFormat = locale$1.format;
13396   exports.timeParse = locale$1.parse;
13397   exports.utcFormat = locale$1.utcFormat;
13398   exports.utcParse = locale$1.utcParse;
13399   return locale$1;
13400 }
13401
13402 var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
13403
13404 function formatIsoNative(date) {
13405   return date.toISOString();
13406 }
13407
13408 var formatIso = Date.prototype.toISOString
13409     ? formatIsoNative
13410     : exports.utcFormat(isoSpecifier);
13411
13412 function parseIsoNative(string) {
13413   var date = new Date(string);
13414   return isNaN(date) ? null : date;
13415 }
13416
13417 var parseIso = +new Date("2000-01-01T00:00:00.000Z")
13418     ? parseIsoNative
13419     : exports.utcParse(isoSpecifier);
13420
13421 var durationSecond$1 = 1000,
13422     durationMinute$1 = durationSecond$1 * 60,
13423     durationHour$1 = durationMinute$1 * 60,
13424     durationDay$1 = durationHour$1 * 24,
13425     durationWeek$1 = durationDay$1 * 7,
13426     durationMonth = durationDay$1 * 30,
13427     durationYear = durationDay$1 * 365;
13428
13429 function date$1(t) {
13430   return new Date(t);
13431 }
13432
13433 function number$3(t) {
13434   return t instanceof Date ? +t : +new Date(+t);
13435 }
13436
13437 function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
13438   var scale = continuous(deinterpolateLinear, reinterpolate),
13439       invert = scale.invert,
13440       domain = scale.domain;
13441
13442   var formatMillisecond = format(".%L"),
13443       formatSecond = format(":%S"),
13444       formatMinute = format("%I:%M"),
13445       formatHour = format("%I %p"),
13446       formatDay = format("%a %d"),
13447       formatWeek = format("%b %d"),
13448       formatMonth = format("%B"),
13449       formatYear = format("%Y");
13450
13451   var tickIntervals = [
13452     [second$$1,  1,      durationSecond$1],
13453     [second$$1,  5,  5 * durationSecond$1],
13454     [second$$1, 15, 15 * durationSecond$1],
13455     [second$$1, 30, 30 * durationSecond$1],
13456     [minute$$1,  1,      durationMinute$1],
13457     [minute$$1,  5,  5 * durationMinute$1],
13458     [minute$$1, 15, 15 * durationMinute$1],
13459     [minute$$1, 30, 30 * durationMinute$1],
13460     [  hour$$1,  1,      durationHour$1  ],
13461     [  hour$$1,  3,  3 * durationHour$1  ],
13462     [  hour$$1,  6,  6 * durationHour$1  ],
13463     [  hour$$1, 12, 12 * durationHour$1  ],
13464     [   day$$1,  1,      durationDay$1   ],
13465     [   day$$1,  2,  2 * durationDay$1   ],
13466     [  week,  1,      durationWeek$1  ],
13467     [ month$$1,  1,      durationMonth ],
13468     [ month$$1,  3,  3 * durationMonth ],
13469     [  year$$1,  1,      durationYear  ]
13470   ];
13471
13472   function tickFormat(date$$1) {
13473     return (second$$1(date$$1) < date$$1 ? formatMillisecond
13474         : minute$$1(date$$1) < date$$1 ? formatSecond
13475         : hour$$1(date$$1) < date$$1 ? formatMinute
13476         : day$$1(date$$1) < date$$1 ? formatHour
13477         : month$$1(date$$1) < date$$1 ? (week(date$$1) < date$$1 ? formatDay : formatWeek)
13478         : year$$1(date$$1) < date$$1 ? formatMonth
13479         : formatYear)(date$$1);
13480   }
13481
13482   function tickInterval(interval, start, stop, step) {
13483     if (interval == null) interval = 10;
13484
13485     // If a desired tick count is specified, pick a reasonable tick interval
13486     // based on the extent of the domain and a rough estimate of tick size.
13487     // Otherwise, assume interval is already a time interval and use it.
13488     if (typeof interval === "number") {
13489       var target = Math.abs(stop - start) / interval,
13490           i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
13491       if (i === tickIntervals.length) {
13492         step = tickStep(start / durationYear, stop / durationYear, interval);
13493         interval = year$$1;
13494       } else if (i) {
13495         i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
13496         step = i[1];
13497         interval = i[0];
13498       } else {
13499         step = Math.max(tickStep(start, stop, interval), 1);
13500         interval = millisecond$$1;
13501       }
13502     }
13503
13504     return step == null ? interval : interval.every(step);
13505   }
13506
13507   scale.invert = function(y) {
13508     return new Date(invert(y));
13509   };
13510
13511   scale.domain = function(_) {
13512     return arguments.length ? domain(map$2.call(_, number$3)) : domain().map(date$1);
13513   };
13514
13515   scale.ticks = function(interval, step) {
13516     var d = domain(),
13517         t0 = d[0],
13518         t1 = d[d.length - 1],
13519         r = t1 < t0,
13520         t;
13521     if (r) t = t0, t0 = t1, t1 = t;
13522     t = tickInterval(interval, t0, t1, step);
13523     t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
13524     return r ? t.reverse() : t;
13525   };
13526
13527   scale.tickFormat = function(count, specifier) {
13528     return specifier == null ? tickFormat : format(specifier);
13529   };
13530
13531   scale.nice = function(interval, step) {
13532     var d = domain();
13533     return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
13534         ? domain(nice(d, interval))
13535         : scale;
13536   };
13537
13538   scale.copy = function() {
13539     return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
13540   };
13541
13542   return scale;
13543 }
13544
13545 function time() {
13546   return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
13547 }
13548
13549 function utcTime() {
13550   return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
13551 }
13552
13553 function sequential(interpolator) {
13554   var x0 = 0,
13555       x1 = 1,
13556       k10 = 1,
13557       clamp = false;
13558
13559   function scale(x) {
13560     var t = (x - x0) * k10;
13561     return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
13562   }
13563
13564   scale.domain = function(_) {
13565     return arguments.length ? (x0 = +_[0], x1 = +_[1], k10 = x0 === x1 ? 0 : 1 / (x1 - x0), scale) : [x0, x1];
13566   };
13567
13568   scale.clamp = function(_) {
13569     return arguments.length ? (clamp = !!_, scale) : clamp;
13570   };
13571
13572   scale.interpolator = function(_) {
13573     return arguments.length ? (interpolator = _, scale) : interpolator;
13574   };
13575
13576   scale.copy = function() {
13577     return sequential(interpolator).domain([x0, x1]).clamp(clamp);
13578   };
13579
13580   return linearish(scale);
13581 }
13582
13583 function diverging(interpolator) {
13584   var x0 = 0,
13585       x1 = 0.5,
13586       x2 = 1,
13587       k10 = 1,
13588       k21 = 1,
13589       clamp = false;
13590
13591   function scale(x) {
13592     var t = 0.5 + ((x = +x) - x1) * (x < x1 ? k10 : k21);
13593     return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
13594   }
13595
13596   scale.domain = function(_) {
13597     return arguments.length ? (x0 = +_[0], x1 = +_[1], x2 = +_[2], k10 = x0 === x1 ? 0 : 0.5 / (x1 - x0), k21 = x1 === x2 ? 0 : 0.5 / (x2 - x1), scale) : [x0, x1, x2];
13598   };
13599
13600   scale.clamp = function(_) {
13601     return arguments.length ? (clamp = !!_, scale) : clamp;
13602   };
13603
13604   scale.interpolator = function(_) {
13605     return arguments.length ? (interpolator = _, scale) : interpolator;
13606   };
13607
13608   scale.copy = function() {
13609     return diverging(interpolator).domain([x0, x1, x2]).clamp(clamp);
13610   };
13611
13612   return linearish(scale);
13613 }
13614
13615 function colors(specifier) {
13616   var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
13617   while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
13618   return colors;
13619 }
13620
13621 var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
13622
13623 var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
13624
13625 var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
13626
13627 var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
13628
13629 var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
13630
13631 var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
13632
13633 var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
13634
13635 var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
13636
13637 var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
13638
13639 function ramp(scheme) {
13640   return rgbBasis(scheme[scheme.length - 1]);
13641 }
13642
13643 var scheme = new Array(3).concat(
13644   "d8b365f5f5f55ab4ac",
13645   "a6611adfc27d80cdc1018571",
13646   "a6611adfc27df5f5f580cdc1018571",
13647   "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
13648   "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
13649   "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
13650   "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
13651   "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
13652   "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
13653 ).map(colors);
13654
13655 var BrBG = ramp(scheme);
13656
13657 var scheme$1 = new Array(3).concat(
13658   "af8dc3f7f7f77fbf7b",
13659   "7b3294c2a5cfa6dba0008837",
13660   "7b3294c2a5cff7f7f7a6dba0008837",
13661   "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
13662   "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
13663   "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
13664   "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
13665   "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
13666   "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
13667 ).map(colors);
13668
13669 var PRGn = ramp(scheme$1);
13670
13671 var scheme$2 = new Array(3).concat(
13672   "e9a3c9f7f7f7a1d76a",
13673   "d01c8bf1b6dab8e1864dac26",
13674   "d01c8bf1b6daf7f7f7b8e1864dac26",
13675   "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
13676   "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
13677   "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
13678   "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
13679   "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
13680   "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
13681 ).map(colors);
13682
13683 var PiYG = ramp(scheme$2);
13684
13685 var scheme$3 = new Array(3).concat(
13686   "998ec3f7f7f7f1a340",
13687   "5e3c99b2abd2fdb863e66101",
13688   "5e3c99b2abd2f7f7f7fdb863e66101",
13689   "542788998ec3d8daebfee0b6f1a340b35806",
13690   "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
13691   "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
13692   "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
13693   "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
13694   "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
13695 ).map(colors);
13696
13697 var PuOr = ramp(scheme$3);
13698
13699 var scheme$4 = new Array(3).concat(
13700   "ef8a62f7f7f767a9cf",
13701   "ca0020f4a58292c5de0571b0",
13702   "ca0020f4a582f7f7f792c5de0571b0",
13703   "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
13704   "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
13705   "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
13706   "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
13707   "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
13708   "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
13709 ).map(colors);
13710
13711 var RdBu = ramp(scheme$4);
13712
13713 var scheme$5 = new Array(3).concat(
13714   "ef8a62ffffff999999",
13715   "ca0020f4a582bababa404040",
13716   "ca0020f4a582ffffffbababa404040",
13717   "b2182bef8a62fddbc7e0e0e09999994d4d4d",
13718   "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
13719   "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
13720   "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
13721   "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
13722   "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
13723 ).map(colors);
13724
13725 var RdGy = ramp(scheme$5);
13726
13727 var scheme$6 = new Array(3).concat(
13728   "fc8d59ffffbf91bfdb",
13729   "d7191cfdae61abd9e92c7bb6",
13730   "d7191cfdae61ffffbfabd9e92c7bb6",
13731   "d73027fc8d59fee090e0f3f891bfdb4575b4",
13732   "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
13733   "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
13734   "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
13735   "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
13736   "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
13737 ).map(colors);
13738
13739 var RdYlBu = ramp(scheme$6);
13740
13741 var scheme$7 = new Array(3).concat(
13742   "fc8d59ffffbf91cf60",
13743   "d7191cfdae61a6d96a1a9641",
13744   "d7191cfdae61ffffbfa6d96a1a9641",
13745   "d73027fc8d59fee08bd9ef8b91cf601a9850",
13746   "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
13747   "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
13748   "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
13749   "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
13750   "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
13751 ).map(colors);
13752
13753 var RdYlGn = ramp(scheme$7);
13754
13755 var scheme$8 = new Array(3).concat(
13756   "fc8d59ffffbf99d594",
13757   "d7191cfdae61abdda42b83ba",
13758   "d7191cfdae61ffffbfabdda42b83ba",
13759   "d53e4ffc8d59fee08be6f59899d5943288bd",
13760   "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
13761   "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
13762   "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
13763   "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
13764   "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
13765 ).map(colors);
13766
13767 var Spectral = ramp(scheme$8);
13768
13769 var scheme$9 = new Array(3).concat(
13770   "e5f5f999d8c92ca25f",
13771   "edf8fbb2e2e266c2a4238b45",
13772   "edf8fbb2e2e266c2a42ca25f006d2c",
13773   "edf8fbccece699d8c966c2a42ca25f006d2c",
13774   "edf8fbccece699d8c966c2a441ae76238b45005824",
13775   "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
13776   "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
13777 ).map(colors);
13778
13779 var BuGn = ramp(scheme$9);
13780
13781 var scheme$10 = new Array(3).concat(
13782   "e0ecf49ebcda8856a7",
13783   "edf8fbb3cde38c96c688419d",
13784   "edf8fbb3cde38c96c68856a7810f7c",
13785   "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
13786   "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
13787   "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
13788   "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
13789 ).map(colors);
13790
13791 var BuPu = ramp(scheme$10);
13792
13793 var scheme$11 = new Array(3).concat(
13794   "e0f3dba8ddb543a2ca",
13795   "f0f9e8bae4bc7bccc42b8cbe",
13796   "f0f9e8bae4bc7bccc443a2ca0868ac",
13797   "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
13798   "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
13799   "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
13800   "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
13801 ).map(colors);
13802
13803 var GnBu = ramp(scheme$11);
13804
13805 var scheme$12 = new Array(3).concat(
13806   "fee8c8fdbb84e34a33",
13807   "fef0d9fdcc8afc8d59d7301f",
13808   "fef0d9fdcc8afc8d59e34a33b30000",
13809   "fef0d9fdd49efdbb84fc8d59e34a33b30000",
13810   "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
13811   "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
13812   "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
13813 ).map(colors);
13814
13815 var OrRd = ramp(scheme$12);
13816
13817 var scheme$13 = new Array(3).concat(
13818   "ece2f0a6bddb1c9099",
13819   "f6eff7bdc9e167a9cf02818a",
13820   "f6eff7bdc9e167a9cf1c9099016c59",
13821   "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
13822   "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
13823   "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
13824   "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
13825 ).map(colors);
13826
13827 var PuBuGn = ramp(scheme$13);
13828
13829 var scheme$14 = new Array(3).concat(
13830   "ece7f2a6bddb2b8cbe",
13831   "f1eef6bdc9e174a9cf0570b0",
13832   "f1eef6bdc9e174a9cf2b8cbe045a8d",
13833   "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
13834   "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
13835   "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
13836   "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
13837 ).map(colors);
13838
13839 var PuBu = ramp(scheme$14);
13840
13841 var scheme$15 = new Array(3).concat(
13842   "e7e1efc994c7dd1c77",
13843   "f1eef6d7b5d8df65b0ce1256",
13844   "f1eef6d7b5d8df65b0dd1c77980043",
13845   "f1eef6d4b9dac994c7df65b0dd1c77980043",
13846   "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
13847   "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
13848   "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
13849 ).map(colors);
13850
13851 var PuRd = ramp(scheme$15);
13852
13853 var scheme$16 = new Array(3).concat(
13854   "fde0ddfa9fb5c51b8a",
13855   "feebe2fbb4b9f768a1ae017e",
13856   "feebe2fbb4b9f768a1c51b8a7a0177",
13857   "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
13858   "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
13859   "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
13860   "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
13861 ).map(colors);
13862
13863 var RdPu = ramp(scheme$16);
13864
13865 var scheme$17 = new Array(3).concat(
13866   "edf8b17fcdbb2c7fb8",
13867   "ffffcca1dab441b6c4225ea8",
13868   "ffffcca1dab441b6c42c7fb8253494",
13869   "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
13870   "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
13871   "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
13872   "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
13873 ).map(colors);
13874
13875 var YlGnBu = ramp(scheme$17);
13876
13877 var scheme$18 = new Array(3).concat(
13878   "f7fcb9addd8e31a354",
13879   "ffffccc2e69978c679238443",
13880   "ffffccc2e69978c67931a354006837",
13881   "ffffccd9f0a3addd8e78c67931a354006837",
13882   "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
13883   "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
13884   "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
13885 ).map(colors);
13886
13887 var YlGn = ramp(scheme$18);
13888
13889 var scheme$19 = new Array(3).concat(
13890   "fff7bcfec44fd95f0e",
13891   "ffffd4fed98efe9929cc4c02",
13892   "ffffd4fed98efe9929d95f0e993404",
13893   "ffffd4fee391fec44ffe9929d95f0e993404",
13894   "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
13895   "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
13896   "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
13897 ).map(colors);
13898
13899 var YlOrBr = ramp(scheme$19);
13900
13901 var scheme$20 = new Array(3).concat(
13902   "ffeda0feb24cf03b20",
13903   "ffffb2fecc5cfd8d3ce31a1c",
13904   "ffffb2fecc5cfd8d3cf03b20bd0026",
13905   "ffffb2fed976feb24cfd8d3cf03b20bd0026",
13906   "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
13907   "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
13908   "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
13909 ).map(colors);
13910
13911 var YlOrRd = ramp(scheme$20);
13912
13913 var scheme$21 = new Array(3).concat(
13914   "deebf79ecae13182bd",
13915   "eff3ffbdd7e76baed62171b5",
13916   "eff3ffbdd7e76baed63182bd08519c",
13917   "eff3ffc6dbef9ecae16baed63182bd08519c",
13918   "eff3ffc6dbef9ecae16baed64292c62171b5084594",
13919   "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
13920   "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
13921 ).map(colors);
13922
13923 var Blues = ramp(scheme$21);
13924
13925 var scheme$22 = new Array(3).concat(
13926   "e5f5e0a1d99b31a354",
13927   "edf8e9bae4b374c476238b45",
13928   "edf8e9bae4b374c47631a354006d2c",
13929   "edf8e9c7e9c0a1d99b74c47631a354006d2c",
13930   "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
13931   "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
13932   "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
13933 ).map(colors);
13934
13935 var Greens = ramp(scheme$22);
13936
13937 var scheme$23 = new Array(3).concat(
13938   "f0f0f0bdbdbd636363",
13939   "f7f7f7cccccc969696525252",
13940   "f7f7f7cccccc969696636363252525",
13941   "f7f7f7d9d9d9bdbdbd969696636363252525",
13942   "f7f7f7d9d9d9bdbdbd969696737373525252252525",
13943   "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
13944   "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
13945 ).map(colors);
13946
13947 var Greys = ramp(scheme$23);
13948
13949 var scheme$24 = new Array(3).concat(
13950   "efedf5bcbddc756bb1",
13951   "f2f0f7cbc9e29e9ac86a51a3",
13952   "f2f0f7cbc9e29e9ac8756bb154278f",
13953   "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
13954   "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
13955   "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
13956   "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
13957 ).map(colors);
13958
13959 var Purples = ramp(scheme$24);
13960
13961 var scheme$25 = new Array(3).concat(
13962   "fee0d2fc9272de2d26",
13963   "fee5d9fcae91fb6a4acb181d",
13964   "fee5d9fcae91fb6a4ade2d26a50f15",
13965   "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
13966   "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
13967   "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
13968   "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
13969 ).map(colors);
13970
13971 var Reds = ramp(scheme$25);
13972
13973 var scheme$26 = new Array(3).concat(
13974   "fee6cefdae6be6550d",
13975   "feeddefdbe85fd8d3cd94701",
13976   "feeddefdbe85fd8d3ce6550da63603",
13977   "feeddefdd0a2fdae6bfd8d3ce6550da63603",
13978   "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
13979   "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
13980   "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
13981 ).map(colors);
13982
13983 var Oranges = ramp(scheme$26);
13984
13985 var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
13986
13987 var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13988
13989 var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13990
13991 var c = cubehelix();
13992
13993 function rainbow(t) {
13994   if (t < 0 || t > 1) t -= Math.floor(t);
13995   var ts = Math.abs(t - 0.5);
13996   c.h = 360 * t - 100;
13997   c.s = 1.5 - 1.5 * ts;
13998   c.l = 0.8 - 0.9 * ts;
13999   return c + "";
14000 }
14001
14002 var c$1 = rgb(),
14003     pi_1_3 = Math.PI / 3,
14004     pi_2_3 = Math.PI * 2 / 3;
14005
14006 function sinebow(t) {
14007   var x;
14008   t = (0.5 - t) * Math.PI;
14009   c$1.r = 255 * (x = Math.sin(t)) * x;
14010   c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
14011   c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
14012   return c$1 + "";
14013 }
14014
14015 function ramp$1(range) {
14016   var n = range.length;
14017   return function(t) {
14018     return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
14019   };
14020 }
14021
14022 var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
14023
14024 var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
14025
14026 var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
14027
14028 var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
14029
14030 function constant$11(x) {
14031   return function constant() {
14032     return x;
14033   };
14034 }
14035
14036 var abs$1 = Math.abs;
14037 var atan2$1 = Math.atan2;
14038 var cos$2 = Math.cos;
14039 var max$2 = Math.max;
14040 var min$1 = Math.min;
14041 var sin$2 = Math.sin;
14042 var sqrt$2 = Math.sqrt;
14043
14044 var epsilon$3 = 1e-12;
14045 var pi$4 = Math.PI;
14046 var halfPi$3 = pi$4 / 2;
14047 var tau$4 = 2 * pi$4;
14048
14049 function acos$1(x) {
14050   return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
14051 }
14052
14053 function asin$1(x) {
14054   return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
14055 }
14056
14057 function arcInnerRadius(d) {
14058   return d.innerRadius;
14059 }
14060
14061 function arcOuterRadius(d) {
14062   return d.outerRadius;
14063 }
14064
14065 function arcStartAngle(d) {
14066   return d.startAngle;
14067 }
14068
14069 function arcEndAngle(d) {
14070   return d.endAngle;
14071 }
14072
14073 function arcPadAngle(d) {
14074   return d && d.padAngle; // Note: optional!
14075 }
14076
14077 function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
14078   var x10 = x1 - x0, y10 = y1 - y0,
14079       x32 = x3 - x2, y32 = y3 - y2,
14080       t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
14081   return [x0 + t * x10, y0 + t * y10];
14082 }
14083
14084 // Compute perpendicular offset line of length rc.
14085 // http://mathworld.wolfram.com/Circle-LineIntersection.html
14086 function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
14087   var x01 = x0 - x1,
14088       y01 = y0 - y1,
14089       lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
14090       ox = lo * y01,
14091       oy = -lo * x01,
14092       x11 = x0 + ox,
14093       y11 = y0 + oy,
14094       x10 = x1 + ox,
14095       y10 = y1 + oy,
14096       x00 = (x11 + x10) / 2,
14097       y00 = (y11 + y10) / 2,
14098       dx = x10 - x11,
14099       dy = y10 - y11,
14100       d2 = dx * dx + dy * dy,
14101       r = r1 - rc,
14102       D = x11 * y10 - x10 * y11,
14103       d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
14104       cx0 = (D * dy - dx * d) / d2,
14105       cy0 = (-D * dx - dy * d) / d2,
14106       cx1 = (D * dy + dx * d) / d2,
14107       cy1 = (-D * dx + dy * d) / d2,
14108       dx0 = cx0 - x00,
14109       dy0 = cy0 - y00,
14110       dx1 = cx1 - x00,
14111       dy1 = cy1 - y00;
14112
14113   // Pick the closer of the two intersection points.
14114   // TODO Is there a faster way to determine which intersection to use?
14115   if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
14116
14117   return {
14118     cx: cx0,
14119     cy: cy0,
14120     x01: -ox,
14121     y01: -oy,
14122     x11: cx0 * (r1 / r - 1),
14123     y11: cy0 * (r1 / r - 1)
14124   };
14125 }
14126
14127 function arc() {
14128   var innerRadius = arcInnerRadius,
14129       outerRadius = arcOuterRadius,
14130       cornerRadius = constant$11(0),
14131       padRadius = null,
14132       startAngle = arcStartAngle,
14133       endAngle = arcEndAngle,
14134       padAngle = arcPadAngle,
14135       context = null;
14136
14137   function arc() {
14138     var buffer,
14139         r,
14140         r0 = +innerRadius.apply(this, arguments),
14141         r1 = +outerRadius.apply(this, arguments),
14142         a0 = startAngle.apply(this, arguments) - halfPi$3,
14143         a1 = endAngle.apply(this, arguments) - halfPi$3,
14144         da = abs$1(a1 - a0),
14145         cw = a1 > a0;
14146
14147     if (!context) context = buffer = path();
14148
14149     // Ensure that the outer radius is always larger than the inner radius.
14150     if (r1 < r0) r = r1, r1 = r0, r0 = r;
14151
14152     // Is it a point?
14153     if (!(r1 > epsilon$3)) context.moveTo(0, 0);
14154
14155     // Or is it a circle or annulus?
14156     else if (da > tau$4 - epsilon$3) {
14157       context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
14158       context.arc(0, 0, r1, a0, a1, !cw);
14159       if (r0 > epsilon$3) {
14160         context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
14161         context.arc(0, 0, r0, a1, a0, cw);
14162       }
14163     }
14164
14165     // Or is it a circular or annular sector?
14166     else {
14167       var a01 = a0,
14168           a11 = a1,
14169           a00 = a0,
14170           a10 = a1,
14171           da0 = da,
14172           da1 = da,
14173           ap = padAngle.apply(this, arguments) / 2,
14174           rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
14175           rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
14176           rc0 = rc,
14177           rc1 = rc,
14178           t0,
14179           t1;
14180
14181       // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
14182       if (rp > epsilon$3) {
14183         var p0 = asin$1(rp / r0 * sin$2(ap)),
14184             p1 = asin$1(rp / r1 * sin$2(ap));
14185         if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
14186         else da0 = 0, a00 = a10 = (a0 + a1) / 2;
14187         if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
14188         else da1 = 0, a01 = a11 = (a0 + a1) / 2;
14189       }
14190
14191       var x01 = r1 * cos$2(a01),
14192           y01 = r1 * sin$2(a01),
14193           x10 = r0 * cos$2(a10),
14194           y10 = r0 * sin$2(a10);
14195
14196       // Apply rounded corners?
14197       if (rc > epsilon$3) {
14198         var x11 = r1 * cos$2(a11),
14199             y11 = r1 * sin$2(a11),
14200             x00 = r0 * cos$2(a00),
14201             y00 = r0 * sin$2(a00);
14202
14203         // Restrict the corner radius according to the sector angle.
14204         if (da < pi$4) {
14205           var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
14206               ax = x01 - oc[0],
14207               ay = y01 - oc[1],
14208               bx = x11 - oc[0],
14209               by = y11 - oc[1],
14210               kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
14211               lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
14212           rc0 = min$1(rc, (r0 - lc) / (kc - 1));
14213           rc1 = min$1(rc, (r1 - lc) / (kc + 1));
14214         }
14215       }
14216
14217       // Is the sector collapsed to a line?
14218       if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
14219
14220       // Does the sector’s outer ring have rounded corners?
14221       else if (rc1 > epsilon$3) {
14222         t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
14223         t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
14224
14225         context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
14226
14227         // Have the corners merged?
14228         if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
14229
14230         // Otherwise, draw the two corners and the ring.
14231         else {
14232           context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
14233           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);
14234           context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
14235         }
14236       }
14237
14238       // Or is the outer ring just a circular arc?
14239       else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
14240
14241       // Is there no inner ring, and it’s a circular sector?
14242       // Or perhaps it’s an annular sector collapsed due to padding?
14243       if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
14244
14245       // Does the sector’s inner ring (or point) have rounded corners?
14246       else if (rc0 > epsilon$3) {
14247         t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
14248         t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
14249
14250         context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
14251
14252         // Have the corners merged?
14253         if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
14254
14255         // Otherwise, draw the two corners and the ring.
14256         else {
14257           context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
14258           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);
14259           context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
14260         }
14261       }
14262
14263       // Or is the inner ring just a circular arc?
14264       else context.arc(0, 0, r0, a10, a00, cw);
14265     }
14266
14267     context.closePath();
14268
14269     if (buffer) return context = null, buffer + "" || null;
14270   }
14271
14272   arc.centroid = function() {
14273     var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
14274         a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
14275     return [cos$2(a) * r, sin$2(a) * r];
14276   };
14277
14278   arc.innerRadius = function(_) {
14279     return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : innerRadius;
14280   };
14281
14282   arc.outerRadius = function(_) {
14283     return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : outerRadius;
14284   };
14285
14286   arc.cornerRadius = function(_) {
14287     return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$11(+_), arc) : cornerRadius;
14288   };
14289
14290   arc.padRadius = function(_) {
14291     return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), arc) : padRadius;
14292   };
14293
14294   arc.startAngle = function(_) {
14295     return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : startAngle;
14296   };
14297
14298   arc.endAngle = function(_) {
14299     return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : endAngle;
14300   };
14301
14302   arc.padAngle = function(_) {
14303     return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), arc) : padAngle;
14304   };
14305
14306   arc.context = function(_) {
14307     return arguments.length ? (context = _ == null ? null : _, arc) : context;
14308   };
14309
14310   return arc;
14311 }
14312
14313 function Linear(context) {
14314   this._context = context;
14315 }
14316
14317 Linear.prototype = {
14318   areaStart: function() {
14319     this._line = 0;
14320   },
14321   areaEnd: function() {
14322     this._line = NaN;
14323   },
14324   lineStart: function() {
14325     this._point = 0;
14326   },
14327   lineEnd: function() {
14328     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14329     this._line = 1 - this._line;
14330   },
14331   point: function(x, y) {
14332     x = +x, y = +y;
14333     switch (this._point) {
14334       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14335       case 1: this._point = 2; // proceed
14336       default: this._context.lineTo(x, y); break;
14337     }
14338   }
14339 };
14340
14341 function curveLinear(context) {
14342   return new Linear(context);
14343 }
14344
14345 function x$3(p) {
14346   return p[0];
14347 }
14348
14349 function y$3(p) {
14350   return p[1];
14351 }
14352
14353 function line() {
14354   var x$$1 = x$3,
14355       y$$1 = y$3,
14356       defined = constant$11(true),
14357       context = null,
14358       curve = curveLinear,
14359       output = null;
14360
14361   function line(data) {
14362     var i,
14363         n = data.length,
14364         d,
14365         defined0 = false,
14366         buffer;
14367
14368     if (context == null) output = curve(buffer = path());
14369
14370     for (i = 0; i <= n; ++i) {
14371       if (!(i < n && defined(d = data[i], i, data)) === defined0) {
14372         if (defined0 = !defined0) output.lineStart();
14373         else output.lineEnd();
14374       }
14375       if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
14376     }
14377
14378     if (buffer) return output = null, buffer + "" || null;
14379   }
14380
14381   line.x = function(_) {
14382     return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : x$$1;
14383   };
14384
14385   line.y = function(_) {
14386     return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), line) : y$$1;
14387   };
14388
14389   line.defined = function(_) {
14390     return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), line) : defined;
14391   };
14392
14393   line.curve = function(_) {
14394     return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
14395   };
14396
14397   line.context = function(_) {
14398     return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
14399   };
14400
14401   return line;
14402 }
14403
14404 function area$3() {
14405   var x0 = x$3,
14406       x1 = null,
14407       y0 = constant$11(0),
14408       y1 = y$3,
14409       defined = constant$11(true),
14410       context = null,
14411       curve = curveLinear,
14412       output = null;
14413
14414   function area(data) {
14415     var i,
14416         j,
14417         k,
14418         n = data.length,
14419         d,
14420         defined0 = false,
14421         buffer,
14422         x0z = new Array(n),
14423         y0z = new Array(n);
14424
14425     if (context == null) output = curve(buffer = path());
14426
14427     for (i = 0; i <= n; ++i) {
14428       if (!(i < n && defined(d = data[i], i, data)) === defined0) {
14429         if (defined0 = !defined0) {
14430           j = i;
14431           output.areaStart();
14432           output.lineStart();
14433         } else {
14434           output.lineEnd();
14435           output.lineStart();
14436           for (k = i - 1; k >= j; --k) {
14437             output.point(x0z[k], y0z[k]);
14438           }
14439           output.lineEnd();
14440           output.areaEnd();
14441         }
14442       }
14443       if (defined0) {
14444         x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
14445         output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
14446       }
14447     }
14448
14449     if (buffer) return output = null, buffer + "" || null;
14450   }
14451
14452   function arealine() {
14453     return line().defined(defined).curve(curve).context(context);
14454   }
14455
14456   area.x = function(_) {
14457     return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), x1 = null, area) : x0;
14458   };
14459
14460   area.x0 = function(_) {
14461     return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$11(+_), area) : x0;
14462   };
14463
14464   area.x1 = function(_) {
14465     return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : x1;
14466   };
14467
14468   area.y = function(_) {
14469     return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), y1 = null, area) : y0;
14470   };
14471
14472   area.y0 = function(_) {
14473     return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$11(+_), area) : y0;
14474   };
14475
14476   area.y1 = function(_) {
14477     return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$11(+_), area) : y1;
14478   };
14479
14480   area.lineX0 =
14481   area.lineY0 = function() {
14482     return arealine().x(x0).y(y0);
14483   };
14484
14485   area.lineY1 = function() {
14486     return arealine().x(x0).y(y1);
14487   };
14488
14489   area.lineX1 = function() {
14490     return arealine().x(x1).y(y0);
14491   };
14492
14493   area.defined = function(_) {
14494     return arguments.length ? (defined = typeof _ === "function" ? _ : constant$11(!!_), area) : defined;
14495   };
14496
14497   area.curve = function(_) {
14498     return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
14499   };
14500
14501   area.context = function(_) {
14502     return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
14503   };
14504
14505   return area;
14506 }
14507
14508 function descending$1(a, b) {
14509   return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
14510 }
14511
14512 function identity$7(d) {
14513   return d;
14514 }
14515
14516 function pie() {
14517   var value = identity$7,
14518       sortValues = descending$1,
14519       sort = null,
14520       startAngle = constant$11(0),
14521       endAngle = constant$11(tau$4),
14522       padAngle = constant$11(0);
14523
14524   function pie(data) {
14525     var i,
14526         n = data.length,
14527         j,
14528         k,
14529         sum = 0,
14530         index = new Array(n),
14531         arcs = new Array(n),
14532         a0 = +startAngle.apply(this, arguments),
14533         da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
14534         a1,
14535         p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
14536         pa = p * (da < 0 ? -1 : 1),
14537         v;
14538
14539     for (i = 0; i < n; ++i) {
14540       if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
14541         sum += v;
14542       }
14543     }
14544
14545     // Optionally sort the arcs by previously-computed values or by data.
14546     if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
14547     else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
14548
14549     // Compute the arcs! They are stored in the original data's order.
14550     for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
14551       j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
14552         data: data[j],
14553         index: i,
14554         value: v,
14555         startAngle: a0,
14556         endAngle: a1,
14557         padAngle: p
14558       };
14559     }
14560
14561     return arcs;
14562   }
14563
14564   pie.value = function(_) {
14565     return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), pie) : value;
14566   };
14567
14568   pie.sortValues = function(_) {
14569     return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
14570   };
14571
14572   pie.sort = function(_) {
14573     return arguments.length ? (sort = _, sortValues = null, pie) : sort;
14574   };
14575
14576   pie.startAngle = function(_) {
14577     return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : startAngle;
14578   };
14579
14580   pie.endAngle = function(_) {
14581     return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : endAngle;
14582   };
14583
14584   pie.padAngle = function(_) {
14585     return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$11(+_), pie) : padAngle;
14586   };
14587
14588   return pie;
14589 }
14590
14591 var curveRadialLinear = curveRadial(curveLinear);
14592
14593 function Radial(curve) {
14594   this._curve = curve;
14595 }
14596
14597 Radial.prototype = {
14598   areaStart: function() {
14599     this._curve.areaStart();
14600   },
14601   areaEnd: function() {
14602     this._curve.areaEnd();
14603   },
14604   lineStart: function() {
14605     this._curve.lineStart();
14606   },
14607   lineEnd: function() {
14608     this._curve.lineEnd();
14609   },
14610   point: function(a, r) {
14611     this._curve.point(r * Math.sin(a), r * -Math.cos(a));
14612   }
14613 };
14614
14615 function curveRadial(curve) {
14616
14617   function radial(context) {
14618     return new Radial(curve(context));
14619   }
14620
14621   radial._curve = curve;
14622
14623   return radial;
14624 }
14625
14626 function lineRadial(l) {
14627   var c = l.curve;
14628
14629   l.angle = l.x, delete l.x;
14630   l.radius = l.y, delete l.y;
14631
14632   l.curve = function(_) {
14633     return arguments.length ? c(curveRadial(_)) : c()._curve;
14634   };
14635
14636   return l;
14637 }
14638
14639 function lineRadial$1() {
14640   return lineRadial(line().curve(curveRadialLinear));
14641 }
14642
14643 function areaRadial() {
14644   var a = area$3().curve(curveRadialLinear),
14645       c = a.curve,
14646       x0 = a.lineX0,
14647       x1 = a.lineX1,
14648       y0 = a.lineY0,
14649       y1 = a.lineY1;
14650
14651   a.angle = a.x, delete a.x;
14652   a.startAngle = a.x0, delete a.x0;
14653   a.endAngle = a.x1, delete a.x1;
14654   a.radius = a.y, delete a.y;
14655   a.innerRadius = a.y0, delete a.y0;
14656   a.outerRadius = a.y1, delete a.y1;
14657   a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
14658   a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
14659   a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
14660   a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
14661
14662   a.curve = function(_) {
14663     return arguments.length ? c(curveRadial(_)) : c()._curve;
14664   };
14665
14666   return a;
14667 }
14668
14669 function pointRadial(x, y) {
14670   return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
14671 }
14672
14673 var slice$6 = Array.prototype.slice;
14674
14675 function linkSource(d) {
14676   return d.source;
14677 }
14678
14679 function linkTarget(d) {
14680   return d.target;
14681 }
14682
14683 function link$2(curve) {
14684   var source = linkSource,
14685       target = linkTarget,
14686       x$$1 = x$3,
14687       y$$1 = y$3,
14688       context = null;
14689
14690   function link() {
14691     var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
14692     if (!context) context = buffer = path();
14693     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));
14694     if (buffer) return context = null, buffer + "" || null;
14695   }
14696
14697   link.source = function(_) {
14698     return arguments.length ? (source = _, link) : source;
14699   };
14700
14701   link.target = function(_) {
14702     return arguments.length ? (target = _, link) : target;
14703   };
14704
14705   link.x = function(_) {
14706     return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : x$$1;
14707   };
14708
14709   link.y = function(_) {
14710     return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), link) : y$$1;
14711   };
14712
14713   link.context = function(_) {
14714     return arguments.length ? (context = _ == null ? null : _, link) : context;
14715   };
14716
14717   return link;
14718 }
14719
14720 function curveHorizontal(context, x0, y0, x1, y1) {
14721   context.moveTo(x0, y0);
14722   context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
14723 }
14724
14725 function curveVertical(context, x0, y0, x1, y1) {
14726   context.moveTo(x0, y0);
14727   context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
14728 }
14729
14730 function curveRadial$1(context, x0, y0, x1, y1) {
14731   var p0 = pointRadial(x0, y0),
14732       p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
14733       p2 = pointRadial(x1, y0),
14734       p3 = pointRadial(x1, y1);
14735   context.moveTo(p0[0], p0[1]);
14736   context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
14737 }
14738
14739 function linkHorizontal() {
14740   return link$2(curveHorizontal);
14741 }
14742
14743 function linkVertical() {
14744   return link$2(curveVertical);
14745 }
14746
14747 function linkRadial() {
14748   var l = link$2(curveRadial$1);
14749   l.angle = l.x, delete l.x;
14750   l.radius = l.y, delete l.y;
14751   return l;
14752 }
14753
14754 var circle$2 = {
14755   draw: function(context, size) {
14756     var r = Math.sqrt(size / pi$4);
14757     context.moveTo(r, 0);
14758     context.arc(0, 0, r, 0, tau$4);
14759   }
14760 };
14761
14762 var cross$2 = {
14763   draw: function(context, size) {
14764     var r = Math.sqrt(size / 5) / 2;
14765     context.moveTo(-3 * r, -r);
14766     context.lineTo(-r, -r);
14767     context.lineTo(-r, -3 * r);
14768     context.lineTo(r, -3 * r);
14769     context.lineTo(r, -r);
14770     context.lineTo(3 * r, -r);
14771     context.lineTo(3 * r, r);
14772     context.lineTo(r, r);
14773     context.lineTo(r, 3 * r);
14774     context.lineTo(-r, 3 * r);
14775     context.lineTo(-r, r);
14776     context.lineTo(-3 * r, r);
14777     context.closePath();
14778   }
14779 };
14780
14781 var tan30 = Math.sqrt(1 / 3),
14782     tan30_2 = tan30 * 2;
14783
14784 var diamond = {
14785   draw: function(context, size) {
14786     var y = Math.sqrt(size / tan30_2),
14787         x = y * tan30;
14788     context.moveTo(0, -y);
14789     context.lineTo(x, 0);
14790     context.lineTo(0, y);
14791     context.lineTo(-x, 0);
14792     context.closePath();
14793   }
14794 };
14795
14796 var ka = 0.89081309152928522810,
14797     kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
14798     kx = Math.sin(tau$4 / 10) * kr,
14799     ky = -Math.cos(tau$4 / 10) * kr;
14800
14801 var star = {
14802   draw: function(context, size) {
14803     var r = Math.sqrt(size * ka),
14804         x = kx * r,
14805         y = ky * r;
14806     context.moveTo(0, -r);
14807     context.lineTo(x, y);
14808     for (var i = 1; i < 5; ++i) {
14809       var a = tau$4 * i / 5,
14810           c = Math.cos(a),
14811           s = Math.sin(a);
14812       context.lineTo(s * r, -c * r);
14813       context.lineTo(c * x - s * y, s * x + c * y);
14814     }
14815     context.closePath();
14816   }
14817 };
14818
14819 var square = {
14820   draw: function(context, size) {
14821     var w = Math.sqrt(size),
14822         x = -w / 2;
14823     context.rect(x, x, w, w);
14824   }
14825 };
14826
14827 var sqrt3 = Math.sqrt(3);
14828
14829 var triangle = {
14830   draw: function(context, size) {
14831     var y = -Math.sqrt(size / (sqrt3 * 3));
14832     context.moveTo(0, y * 2);
14833     context.lineTo(-sqrt3 * y, -y);
14834     context.lineTo(sqrt3 * y, -y);
14835     context.closePath();
14836   }
14837 };
14838
14839 var c$2 = -0.5,
14840     s = Math.sqrt(3) / 2,
14841     k = 1 / Math.sqrt(12),
14842     a = (k / 2 + 1) * 3;
14843
14844 var wye = {
14845   draw: function(context, size) {
14846     var r = Math.sqrt(size / a),
14847         x0 = r / 2,
14848         y0 = r * k,
14849         x1 = x0,
14850         y1 = r * k + r,
14851         x2 = -x1,
14852         y2 = y1;
14853     context.moveTo(x0, y0);
14854     context.lineTo(x1, y1);
14855     context.lineTo(x2, y2);
14856     context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
14857     context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
14858     context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
14859     context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
14860     context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
14861     context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
14862     context.closePath();
14863   }
14864 };
14865
14866 var symbols = [
14867   circle$2,
14868   cross$2,
14869   diamond,
14870   square,
14871   star,
14872   triangle,
14873   wye
14874 ];
14875
14876 function symbol() {
14877   var type = constant$11(circle$2),
14878       size = constant$11(64),
14879       context = null;
14880
14881   function symbol() {
14882     var buffer;
14883     if (!context) context = buffer = path();
14884     type.apply(this, arguments).draw(context, +size.apply(this, arguments));
14885     if (buffer) return context = null, buffer + "" || null;
14886   }
14887
14888   symbol.type = function(_) {
14889     return arguments.length ? (type = typeof _ === "function" ? _ : constant$11(_), symbol) : type;
14890   };
14891
14892   symbol.size = function(_) {
14893     return arguments.length ? (size = typeof _ === "function" ? _ : constant$11(+_), symbol) : size;
14894   };
14895
14896   symbol.context = function(_) {
14897     return arguments.length ? (context = _ == null ? null : _, symbol) : context;
14898   };
14899
14900   return symbol;
14901 }
14902
14903 function noop$3() {}
14904
14905 function point$2(that, x, y) {
14906   that._context.bezierCurveTo(
14907     (2 * that._x0 + that._x1) / 3,
14908     (2 * that._y0 + that._y1) / 3,
14909     (that._x0 + 2 * that._x1) / 3,
14910     (that._y0 + 2 * that._y1) / 3,
14911     (that._x0 + 4 * that._x1 + x) / 6,
14912     (that._y0 + 4 * that._y1 + y) / 6
14913   );
14914 }
14915
14916 function Basis(context) {
14917   this._context = context;
14918 }
14919
14920 Basis.prototype = {
14921   areaStart: function() {
14922     this._line = 0;
14923   },
14924   areaEnd: function() {
14925     this._line = NaN;
14926   },
14927   lineStart: function() {
14928     this._x0 = this._x1 =
14929     this._y0 = this._y1 = NaN;
14930     this._point = 0;
14931   },
14932   lineEnd: function() {
14933     switch (this._point) {
14934       case 3: point$2(this, this._x1, this._y1); // proceed
14935       case 2: this._context.lineTo(this._x1, this._y1); break;
14936     }
14937     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14938     this._line = 1 - this._line;
14939   },
14940   point: function(x, y) {
14941     x = +x, y = +y;
14942     switch (this._point) {
14943       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14944       case 1: this._point = 2; break;
14945       case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
14946       default: point$2(this, x, y); break;
14947     }
14948     this._x0 = this._x1, this._x1 = x;
14949     this._y0 = this._y1, this._y1 = y;
14950   }
14951 };
14952
14953 function basis$2(context) {
14954   return new Basis(context);
14955 }
14956
14957 function BasisClosed(context) {
14958   this._context = context;
14959 }
14960
14961 BasisClosed.prototype = {
14962   areaStart: noop$3,
14963   areaEnd: noop$3,
14964   lineStart: function() {
14965     this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
14966     this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
14967     this._point = 0;
14968   },
14969   lineEnd: function() {
14970     switch (this._point) {
14971       case 1: {
14972         this._context.moveTo(this._x2, this._y2);
14973         this._context.closePath();
14974         break;
14975       }
14976       case 2: {
14977         this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
14978         this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
14979         this._context.closePath();
14980         break;
14981       }
14982       case 3: {
14983         this.point(this._x2, this._y2);
14984         this.point(this._x3, this._y3);
14985         this.point(this._x4, this._y4);
14986         break;
14987       }
14988     }
14989   },
14990   point: function(x, y) {
14991     x = +x, y = +y;
14992     switch (this._point) {
14993       case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
14994       case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
14995       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;
14996       default: point$2(this, x, y); break;
14997     }
14998     this._x0 = this._x1, this._x1 = x;
14999     this._y0 = this._y1, this._y1 = y;
15000   }
15001 };
15002
15003 function basisClosed$1(context) {
15004   return new BasisClosed(context);
15005 }
15006
15007 function BasisOpen(context) {
15008   this._context = context;
15009 }
15010
15011 BasisOpen.prototype = {
15012   areaStart: function() {
15013     this._line = 0;
15014   },
15015   areaEnd: function() {
15016     this._line = NaN;
15017   },
15018   lineStart: function() {
15019     this._x0 = this._x1 =
15020     this._y0 = this._y1 = NaN;
15021     this._point = 0;
15022   },
15023   lineEnd: function() {
15024     if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15025     this._line = 1 - this._line;
15026   },
15027   point: function(x, y) {
15028     x = +x, y = +y;
15029     switch (this._point) {
15030       case 0: this._point = 1; break;
15031       case 1: this._point = 2; break;
15032       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;
15033       case 3: this._point = 4; // proceed
15034       default: point$2(this, x, y); break;
15035     }
15036     this._x0 = this._x1, this._x1 = x;
15037     this._y0 = this._y1, this._y1 = y;
15038   }
15039 };
15040
15041 function basisOpen(context) {
15042   return new BasisOpen(context);
15043 }
15044
15045 function Bundle(context, beta) {
15046   this._basis = new Basis(context);
15047   this._beta = beta;
15048 }
15049
15050 Bundle.prototype = {
15051   lineStart: function() {
15052     this._x = [];
15053     this._y = [];
15054     this._basis.lineStart();
15055   },
15056   lineEnd: function() {
15057     var x = this._x,
15058         y = this._y,
15059         j = x.length - 1;
15060
15061     if (j > 0) {
15062       var x0 = x[0],
15063           y0 = y[0],
15064           dx = x[j] - x0,
15065           dy = y[j] - y0,
15066           i = -1,
15067           t;
15068
15069       while (++i <= j) {
15070         t = i / j;
15071         this._basis.point(
15072           this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
15073           this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
15074         );
15075       }
15076     }
15077
15078     this._x = this._y = null;
15079     this._basis.lineEnd();
15080   },
15081   point: function(x, y) {
15082     this._x.push(+x);
15083     this._y.push(+y);
15084   }
15085 };
15086
15087 var bundle = (function custom(beta) {
15088
15089   function bundle(context) {
15090     return beta === 1 ? new Basis(context) : new Bundle(context, beta);
15091   }
15092
15093   bundle.beta = function(beta) {
15094     return custom(+beta);
15095   };
15096
15097   return bundle;
15098 })(0.85);
15099
15100 function point$3(that, x, y) {
15101   that._context.bezierCurveTo(
15102     that._x1 + that._k * (that._x2 - that._x0),
15103     that._y1 + that._k * (that._y2 - that._y0),
15104     that._x2 + that._k * (that._x1 - x),
15105     that._y2 + that._k * (that._y1 - y),
15106     that._x2,
15107     that._y2
15108   );
15109 }
15110
15111 function Cardinal(context, tension) {
15112   this._context = context;
15113   this._k = (1 - tension) / 6;
15114 }
15115
15116 Cardinal.prototype = {
15117   areaStart: function() {
15118     this._line = 0;
15119   },
15120   areaEnd: function() {
15121     this._line = NaN;
15122   },
15123   lineStart: function() {
15124     this._x0 = this._x1 = this._x2 =
15125     this._y0 = this._y1 = this._y2 = NaN;
15126     this._point = 0;
15127   },
15128   lineEnd: function() {
15129     switch (this._point) {
15130       case 2: this._context.lineTo(this._x2, this._y2); break;
15131       case 3: point$3(this, this._x1, this._y1); break;
15132     }
15133     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15134     this._line = 1 - this._line;
15135   },
15136   point: function(x, y) {
15137     x = +x, y = +y;
15138     switch (this._point) {
15139       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15140       case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
15141       case 2: this._point = 3; // proceed
15142       default: point$3(this, x, y); break;
15143     }
15144     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15145     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15146   }
15147 };
15148
15149 var cardinal = (function custom(tension) {
15150
15151   function cardinal(context) {
15152     return new Cardinal(context, tension);
15153   }
15154
15155   cardinal.tension = function(tension) {
15156     return custom(+tension);
15157   };
15158
15159   return cardinal;
15160 })(0);
15161
15162 function CardinalClosed(context, tension) {
15163   this._context = context;
15164   this._k = (1 - tension) / 6;
15165 }
15166
15167 CardinalClosed.prototype = {
15168   areaStart: noop$3,
15169   areaEnd: noop$3,
15170   lineStart: function() {
15171     this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
15172     this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
15173     this._point = 0;
15174   },
15175   lineEnd: function() {
15176     switch (this._point) {
15177       case 1: {
15178         this._context.moveTo(this._x3, this._y3);
15179         this._context.closePath();
15180         break;
15181       }
15182       case 2: {
15183         this._context.lineTo(this._x3, this._y3);
15184         this._context.closePath();
15185         break;
15186       }
15187       case 3: {
15188         this.point(this._x3, this._y3);
15189         this.point(this._x4, this._y4);
15190         this.point(this._x5, this._y5);
15191         break;
15192       }
15193     }
15194   },
15195   point: function(x, y) {
15196     x = +x, y = +y;
15197     switch (this._point) {
15198       case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
15199       case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
15200       case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
15201       default: point$3(this, x, y); break;
15202     }
15203     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15204     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15205   }
15206 };
15207
15208 var cardinalClosed = (function custom(tension) {
15209
15210   function cardinal$$1(context) {
15211     return new CardinalClosed(context, tension);
15212   }
15213
15214   cardinal$$1.tension = function(tension) {
15215     return custom(+tension);
15216   };
15217
15218   return cardinal$$1;
15219 })(0);
15220
15221 function CardinalOpen(context, tension) {
15222   this._context = context;
15223   this._k = (1 - tension) / 6;
15224 }
15225
15226 CardinalOpen.prototype = {
15227   areaStart: function() {
15228     this._line = 0;
15229   },
15230   areaEnd: function() {
15231     this._line = NaN;
15232   },
15233   lineStart: function() {
15234     this._x0 = this._x1 = this._x2 =
15235     this._y0 = this._y1 = this._y2 = NaN;
15236     this._point = 0;
15237   },
15238   lineEnd: function() {
15239     if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15240     this._line = 1 - this._line;
15241   },
15242   point: function(x, y) {
15243     x = +x, y = +y;
15244     switch (this._point) {
15245       case 0: this._point = 1; break;
15246       case 1: this._point = 2; break;
15247       case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
15248       case 3: this._point = 4; // proceed
15249       default: point$3(this, x, y); break;
15250     }
15251     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15252     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15253   }
15254 };
15255
15256 var cardinalOpen = (function custom(tension) {
15257
15258   function cardinal$$1(context) {
15259     return new CardinalOpen(context, tension);
15260   }
15261
15262   cardinal$$1.tension = function(tension) {
15263     return custom(+tension);
15264   };
15265
15266   return cardinal$$1;
15267 })(0);
15268
15269 function point$4(that, x, y) {
15270   var x1 = that._x1,
15271       y1 = that._y1,
15272       x2 = that._x2,
15273       y2 = that._y2;
15274
15275   if (that._l01_a > epsilon$3) {
15276     var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
15277         n = 3 * that._l01_a * (that._l01_a + that._l12_a);
15278     x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
15279     y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
15280   }
15281
15282   if (that._l23_a > epsilon$3) {
15283     var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
15284         m = 3 * that._l23_a * (that._l23_a + that._l12_a);
15285     x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
15286     y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
15287   }
15288
15289   that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
15290 }
15291
15292 function CatmullRom(context, alpha) {
15293   this._context = context;
15294   this._alpha = alpha;
15295 }
15296
15297 CatmullRom.prototype = {
15298   areaStart: function() {
15299     this._line = 0;
15300   },
15301   areaEnd: function() {
15302     this._line = NaN;
15303   },
15304   lineStart: function() {
15305     this._x0 = this._x1 = this._x2 =
15306     this._y0 = this._y1 = this._y2 = NaN;
15307     this._l01_a = this._l12_a = this._l23_a =
15308     this._l01_2a = this._l12_2a = this._l23_2a =
15309     this._point = 0;
15310   },
15311   lineEnd: function() {
15312     switch (this._point) {
15313       case 2: this._context.lineTo(this._x2, this._y2); break;
15314       case 3: this.point(this._x2, this._y2); break;
15315     }
15316     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15317     this._line = 1 - this._line;
15318   },
15319   point: function(x, y) {
15320     x = +x, y = +y;
15321
15322     if (this._point) {
15323       var x23 = this._x2 - x,
15324           y23 = this._y2 - y;
15325       this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15326     }
15327
15328     switch (this._point) {
15329       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15330       case 1: this._point = 2; break;
15331       case 2: this._point = 3; // proceed
15332       default: point$4(this, x, y); break;
15333     }
15334
15335     this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15336     this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15337     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15338     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15339   }
15340 };
15341
15342 var catmullRom = (function custom(alpha) {
15343
15344   function catmullRom(context) {
15345     return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
15346   }
15347
15348   catmullRom.alpha = function(alpha) {
15349     return custom(+alpha);
15350   };
15351
15352   return catmullRom;
15353 })(0.5);
15354
15355 function CatmullRomClosed(context, alpha) {
15356   this._context = context;
15357   this._alpha = alpha;
15358 }
15359
15360 CatmullRomClosed.prototype = {
15361   areaStart: noop$3,
15362   areaEnd: noop$3,
15363   lineStart: function() {
15364     this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
15365     this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
15366     this._l01_a = this._l12_a = this._l23_a =
15367     this._l01_2a = this._l12_2a = this._l23_2a =
15368     this._point = 0;
15369   },
15370   lineEnd: function() {
15371     switch (this._point) {
15372       case 1: {
15373         this._context.moveTo(this._x3, this._y3);
15374         this._context.closePath();
15375         break;
15376       }
15377       case 2: {
15378         this._context.lineTo(this._x3, this._y3);
15379         this._context.closePath();
15380         break;
15381       }
15382       case 3: {
15383         this.point(this._x3, this._y3);
15384         this.point(this._x4, this._y4);
15385         this.point(this._x5, this._y5);
15386         break;
15387       }
15388     }
15389   },
15390   point: function(x, y) {
15391     x = +x, y = +y;
15392
15393     if (this._point) {
15394       var x23 = this._x2 - x,
15395           y23 = this._y2 - y;
15396       this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15397     }
15398
15399     switch (this._point) {
15400       case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
15401       case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
15402       case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
15403       default: point$4(this, x, y); break;
15404     }
15405
15406     this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15407     this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15408     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15409     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15410   }
15411 };
15412
15413 var catmullRomClosed = (function custom(alpha) {
15414
15415   function catmullRom$$1(context) {
15416     return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
15417   }
15418
15419   catmullRom$$1.alpha = function(alpha) {
15420     return custom(+alpha);
15421   };
15422
15423   return catmullRom$$1;
15424 })(0.5);
15425
15426 function CatmullRomOpen(context, alpha) {
15427   this._context = context;
15428   this._alpha = alpha;
15429 }
15430
15431 CatmullRomOpen.prototype = {
15432   areaStart: function() {
15433     this._line = 0;
15434   },
15435   areaEnd: function() {
15436     this._line = NaN;
15437   },
15438   lineStart: function() {
15439     this._x0 = this._x1 = this._x2 =
15440     this._y0 = this._y1 = this._y2 = NaN;
15441     this._l01_a = this._l12_a = this._l23_a =
15442     this._l01_2a = this._l12_2a = this._l23_2a =
15443     this._point = 0;
15444   },
15445   lineEnd: function() {
15446     if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15447     this._line = 1 - this._line;
15448   },
15449   point: function(x, y) {
15450     x = +x, y = +y;
15451
15452     if (this._point) {
15453       var x23 = this._x2 - x,
15454           y23 = this._y2 - y;
15455       this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15456     }
15457
15458     switch (this._point) {
15459       case 0: this._point = 1; break;
15460       case 1: this._point = 2; break;
15461       case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
15462       case 3: this._point = 4; // proceed
15463       default: point$4(this, x, y); break;
15464     }
15465
15466     this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15467     this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15468     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15469     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15470   }
15471 };
15472
15473 var catmullRomOpen = (function custom(alpha) {
15474
15475   function catmullRom$$1(context) {
15476     return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
15477   }
15478
15479   catmullRom$$1.alpha = function(alpha) {
15480     return custom(+alpha);
15481   };
15482
15483   return catmullRom$$1;
15484 })(0.5);
15485
15486 function LinearClosed(context) {
15487   this._context = context;
15488 }
15489
15490 LinearClosed.prototype = {
15491   areaStart: noop$3,
15492   areaEnd: noop$3,
15493   lineStart: function() {
15494     this._point = 0;
15495   },
15496   lineEnd: function() {
15497     if (this._point) this._context.closePath();
15498   },
15499   point: function(x, y) {
15500     x = +x, y = +y;
15501     if (this._point) this._context.lineTo(x, y);
15502     else this._point = 1, this._context.moveTo(x, y);
15503   }
15504 };
15505
15506 function linearClosed(context) {
15507   return new LinearClosed(context);
15508 }
15509
15510 function sign$1(x) {
15511   return x < 0 ? -1 : 1;
15512 }
15513
15514 // Calculate the slopes of the tangents (Hermite-type interpolation) based on
15515 // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
15516 // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
15517 // NOV(II), P. 443, 1990.
15518 function slope3(that, x2, y2) {
15519   var h0 = that._x1 - that._x0,
15520       h1 = x2 - that._x1,
15521       s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
15522       s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
15523       p = (s0 * h1 + s1 * h0) / (h0 + h1);
15524   return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
15525 }
15526
15527 // Calculate a one-sided slope.
15528 function slope2(that, t) {
15529   var h = that._x1 - that._x0;
15530   return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
15531 }
15532
15533 // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
15534 // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
15535 // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
15536 function point$5(that, t0, t1) {
15537   var x0 = that._x0,
15538       y0 = that._y0,
15539       x1 = that._x1,
15540       y1 = that._y1,
15541       dx = (x1 - x0) / 3;
15542   that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
15543 }
15544
15545 function MonotoneX(context) {
15546   this._context = context;
15547 }
15548
15549 MonotoneX.prototype = {
15550   areaStart: function() {
15551     this._line = 0;
15552   },
15553   areaEnd: function() {
15554     this._line = NaN;
15555   },
15556   lineStart: function() {
15557     this._x0 = this._x1 =
15558     this._y0 = this._y1 =
15559     this._t0 = NaN;
15560     this._point = 0;
15561   },
15562   lineEnd: function() {
15563     switch (this._point) {
15564       case 2: this._context.lineTo(this._x1, this._y1); break;
15565       case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
15566     }
15567     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15568     this._line = 1 - this._line;
15569   },
15570   point: function(x, y) {
15571     var t1 = NaN;
15572
15573     x = +x, y = +y;
15574     if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
15575     switch (this._point) {
15576       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15577       case 1: this._point = 2; break;
15578       case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
15579       default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
15580     }
15581
15582     this._x0 = this._x1, this._x1 = x;
15583     this._y0 = this._y1, this._y1 = y;
15584     this._t0 = t1;
15585   }
15586 };
15587
15588 function MonotoneY(context) {
15589   this._context = new ReflectContext(context);
15590 }
15591
15592 (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
15593   MonotoneX.prototype.point.call(this, y, x);
15594 };
15595
15596 function ReflectContext(context) {
15597   this._context = context;
15598 }
15599
15600 ReflectContext.prototype = {
15601   moveTo: function(x, y) { this._context.moveTo(y, x); },
15602   closePath: function() { this._context.closePath(); },
15603   lineTo: function(x, y) { this._context.lineTo(y, x); },
15604   bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
15605 };
15606
15607 function monotoneX(context) {
15608   return new MonotoneX(context);
15609 }
15610
15611 function monotoneY(context) {
15612   return new MonotoneY(context);
15613 }
15614
15615 function Natural(context) {
15616   this._context = context;
15617 }
15618
15619 Natural.prototype = {
15620   areaStart: function() {
15621     this._line = 0;
15622   },
15623   areaEnd: function() {
15624     this._line = NaN;
15625   },
15626   lineStart: function() {
15627     this._x = [];
15628     this._y = [];
15629   },
15630   lineEnd: function() {
15631     var x = this._x,
15632         y = this._y,
15633         n = x.length;
15634
15635     if (n) {
15636       this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
15637       if (n === 2) {
15638         this._context.lineTo(x[1], y[1]);
15639       } else {
15640         var px = controlPoints(x),
15641             py = controlPoints(y);
15642         for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
15643           this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
15644         }
15645       }
15646     }
15647
15648     if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
15649     this._line = 1 - this._line;
15650     this._x = this._y = null;
15651   },
15652   point: function(x, y) {
15653     this._x.push(+x);
15654     this._y.push(+y);
15655   }
15656 };
15657
15658 // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
15659 function controlPoints(x) {
15660   var i,
15661       n = x.length - 1,
15662       m,
15663       a = new Array(n),
15664       b = new Array(n),
15665       r = new Array(n);
15666   a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
15667   for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
15668   a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
15669   for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
15670   a[n - 1] = r[n - 1] / b[n - 1];
15671   for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
15672   b[n - 1] = (x[n] + a[n - 1]) / 2;
15673   for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
15674   return [a, b];
15675 }
15676
15677 function natural(context) {
15678   return new Natural(context);
15679 }
15680
15681 function Step(context, t) {
15682   this._context = context;
15683   this._t = t;
15684 }
15685
15686 Step.prototype = {
15687   areaStart: function() {
15688     this._line = 0;
15689   },
15690   areaEnd: function() {
15691     this._line = NaN;
15692   },
15693   lineStart: function() {
15694     this._x = this._y = NaN;
15695     this._point = 0;
15696   },
15697   lineEnd: function() {
15698     if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
15699     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15700     if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
15701   },
15702   point: function(x, y) {
15703     x = +x, y = +y;
15704     switch (this._point) {
15705       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15706       case 1: this._point = 2; // proceed
15707       default: {
15708         if (this._t <= 0) {
15709           this._context.lineTo(this._x, y);
15710           this._context.lineTo(x, y);
15711         } else {
15712           var x1 = this._x * (1 - this._t) + x * this._t;
15713           this._context.lineTo(x1, this._y);
15714           this._context.lineTo(x1, y);
15715         }
15716         break;
15717       }
15718     }
15719     this._x = x, this._y = y;
15720   }
15721 };
15722
15723 function step(context) {
15724   return new Step(context, 0.5);
15725 }
15726
15727 function stepBefore(context) {
15728   return new Step(context, 0);
15729 }
15730
15731 function stepAfter(context) {
15732   return new Step(context, 1);
15733 }
15734
15735 function none$1(series, order) {
15736   if (!((n = series.length) > 1)) return;
15737   for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
15738     s0 = s1, s1 = series[order[i]];
15739     for (j = 0; j < m; ++j) {
15740       s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
15741     }
15742   }
15743 }
15744
15745 function none$2(series) {
15746   var n = series.length, o = new Array(n);
15747   while (--n >= 0) o[n] = n;
15748   return o;
15749 }
15750
15751 function stackValue(d, key) {
15752   return d[key];
15753 }
15754
15755 function stack() {
15756   var keys = constant$11([]),
15757       order = none$2,
15758       offset = none$1,
15759       value = stackValue;
15760
15761   function stack(data) {
15762     var kz = keys.apply(this, arguments),
15763         i,
15764         m = data.length,
15765         n = kz.length,
15766         sz = new Array(n),
15767         oz;
15768
15769     for (i = 0; i < n; ++i) {
15770       for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
15771         si[j] = sij = [0, +value(data[j], ki, j, data)];
15772         sij.data = data[j];
15773       }
15774       si.key = ki;
15775     }
15776
15777     for (i = 0, oz = order(sz); i < n; ++i) {
15778       sz[oz[i]].index = i;
15779     }
15780
15781     offset(sz, oz);
15782     return sz;
15783   }
15784
15785   stack.keys = function(_) {
15786     return arguments.length ? (keys = typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : keys;
15787   };
15788
15789   stack.value = function(_) {
15790     return arguments.length ? (value = typeof _ === "function" ? _ : constant$11(+_), stack) : value;
15791   };
15792
15793   stack.order = function(_) {
15794     return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$11(slice$6.call(_)), stack) : order;
15795   };
15796
15797   stack.offset = function(_) {
15798     return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
15799   };
15800
15801   return stack;
15802 }
15803
15804 function expand(series, order) {
15805   if (!((n = series.length) > 0)) return;
15806   for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
15807     for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
15808     if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
15809   }
15810   none$1(series, order);
15811 }
15812
15813 function diverging$1(series, order) {
15814   if (!((n = series.length) > 1)) return;
15815   for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
15816     for (yp = yn = 0, i = 0; i < n; ++i) {
15817       if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
15818         d[0] = yp, d[1] = yp += dy;
15819       } else if (dy < 0) {
15820         d[1] = yn, d[0] = yn += dy;
15821       } else {
15822         d[0] = yp;
15823       }
15824     }
15825   }
15826 }
15827
15828 function silhouette(series, order) {
15829   if (!((n = series.length) > 0)) return;
15830   for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
15831     for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
15832     s0[j][1] += s0[j][0] = -y / 2;
15833   }
15834   none$1(series, order);
15835 }
15836
15837 function wiggle(series, order) {
15838   if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
15839   for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
15840     for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
15841       var si = series[order[i]],
15842           sij0 = si[j][1] || 0,
15843           sij1 = si[j - 1][1] || 0,
15844           s3 = (sij0 - sij1) / 2;
15845       for (var k = 0; k < i; ++k) {
15846         var sk = series[order[k]],
15847             skj0 = sk[j][1] || 0,
15848             skj1 = sk[j - 1][1] || 0;
15849         s3 += skj0 - skj1;
15850       }
15851       s1 += sij0, s2 += s3 * sij0;
15852     }
15853     s0[j - 1][1] += s0[j - 1][0] = y;
15854     if (s1) y -= s2 / s1;
15855   }
15856   s0[j - 1][1] += s0[j - 1][0] = y;
15857   none$1(series, order);
15858 }
15859
15860 function ascending$3(series) {
15861   var sums = series.map(sum$2);
15862   return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
15863 }
15864
15865 function sum$2(series) {
15866   var s = 0, i = -1, n = series.length, v;
15867   while (++i < n) if (v = +series[i][1]) s += v;
15868   return s;
15869 }
15870
15871 function descending$2(series) {
15872   return ascending$3(series).reverse();
15873 }
15874
15875 function insideOut(series) {
15876   var n = series.length,
15877       i,
15878       j,
15879       sums = series.map(sum$2),
15880       order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
15881       top = 0,
15882       bottom = 0,
15883       tops = [],
15884       bottoms = [];
15885
15886   for (i = 0; i < n; ++i) {
15887     j = order[i];
15888     if (top < bottom) {
15889       top += sums[j];
15890       tops.push(j);
15891     } else {
15892       bottom += sums[j];
15893       bottoms.push(j);
15894     }
15895   }
15896
15897   return bottoms.reverse().concat(tops);
15898 }
15899
15900 function reverse(series) {
15901   return none$2(series).reverse();
15902 }
15903
15904 function constant$12(x) {
15905   return function() {
15906     return x;
15907   };
15908 }
15909
15910 function x$4(d) {
15911   return d[0];
15912 }
15913
15914 function y$4(d) {
15915   return d[1];
15916 }
15917
15918 function RedBlackTree() {
15919   this._ = null; // root node
15920 }
15921
15922 function RedBlackNode(node) {
15923   node.U = // parent node
15924   node.C = // color - true for red, false for black
15925   node.L = // left node
15926   node.R = // right node
15927   node.P = // previous node
15928   node.N = null; // next node
15929 }
15930
15931 RedBlackTree.prototype = {
15932   constructor: RedBlackTree,
15933
15934   insert: function(after, node) {
15935     var parent, grandpa, uncle;
15936
15937     if (after) {
15938       node.P = after;
15939       node.N = after.N;
15940       if (after.N) after.N.P = node;
15941       after.N = node;
15942       if (after.R) {
15943         after = after.R;
15944         while (after.L) after = after.L;
15945         after.L = node;
15946       } else {
15947         after.R = node;
15948       }
15949       parent = after;
15950     } else if (this._) {
15951       after = RedBlackFirst(this._);
15952       node.P = null;
15953       node.N = after;
15954       after.P = after.L = node;
15955       parent = after;
15956     } else {
15957       node.P = node.N = null;
15958       this._ = node;
15959       parent = null;
15960     }
15961     node.L = node.R = null;
15962     node.U = parent;
15963     node.C = true;
15964
15965     after = node;
15966     while (parent && parent.C) {
15967       grandpa = parent.U;
15968       if (parent === grandpa.L) {
15969         uncle = grandpa.R;
15970         if (uncle && uncle.C) {
15971           parent.C = uncle.C = false;
15972           grandpa.C = true;
15973           after = grandpa;
15974         } else {
15975           if (after === parent.R) {
15976             RedBlackRotateLeft(this, parent);
15977             after = parent;
15978             parent = after.U;
15979           }
15980           parent.C = false;
15981           grandpa.C = true;
15982           RedBlackRotateRight(this, grandpa);
15983         }
15984       } else {
15985         uncle = grandpa.L;
15986         if (uncle && uncle.C) {
15987           parent.C = uncle.C = false;
15988           grandpa.C = true;
15989           after = grandpa;
15990         } else {
15991           if (after === parent.L) {
15992             RedBlackRotateRight(this, parent);
15993             after = parent;
15994             parent = after.U;
15995           }
15996           parent.C = false;
15997           grandpa.C = true;
15998           RedBlackRotateLeft(this, grandpa);
15999         }
16000       }
16001       parent = after.U;
16002     }
16003     this._.C = false;
16004   },
16005
16006   remove: function(node) {
16007     if (node.N) node.N.P = node.P;
16008     if (node.P) node.P.N = node.N;
16009     node.N = node.P = null;
16010
16011     var parent = node.U,
16012         sibling,
16013         left = node.L,
16014         right = node.R,
16015         next,
16016         red;
16017
16018     if (!left) next = right;
16019     else if (!right) next = left;
16020     else next = RedBlackFirst(right);
16021
16022     if (parent) {
16023       if (parent.L === node) parent.L = next;
16024       else parent.R = next;
16025     } else {
16026       this._ = next;
16027     }
16028
16029     if (left && right) {
16030       red = next.C;
16031       next.C = node.C;
16032       next.L = left;
16033       left.U = next;
16034       if (next !== right) {
16035         parent = next.U;
16036         next.U = node.U;
16037         node = next.R;
16038         parent.L = node;
16039         next.R = right;
16040         right.U = next;
16041       } else {
16042         next.U = parent;
16043         parent = next;
16044         node = next.R;
16045       }
16046     } else {
16047       red = node.C;
16048       node = next;
16049     }
16050
16051     if (node) node.U = parent;
16052     if (red) return;
16053     if (node && node.C) { node.C = false; return; }
16054
16055     do {
16056       if (node === this._) break;
16057       if (node === parent.L) {
16058         sibling = parent.R;
16059         if (sibling.C) {
16060           sibling.C = false;
16061           parent.C = true;
16062           RedBlackRotateLeft(this, parent);
16063           sibling = parent.R;
16064         }
16065         if ((sibling.L && sibling.L.C)
16066             || (sibling.R && sibling.R.C)) {
16067           if (!sibling.R || !sibling.R.C) {
16068             sibling.L.C = false;
16069             sibling.C = true;
16070             RedBlackRotateRight(this, sibling);
16071             sibling = parent.R;
16072           }
16073           sibling.C = parent.C;
16074           parent.C = sibling.R.C = false;
16075           RedBlackRotateLeft(this, parent);
16076           node = this._;
16077           break;
16078         }
16079       } else {
16080         sibling = parent.L;
16081         if (sibling.C) {
16082           sibling.C = false;
16083           parent.C = true;
16084           RedBlackRotateRight(this, parent);
16085           sibling = parent.L;
16086         }
16087         if ((sibling.L && sibling.L.C)
16088           || (sibling.R && sibling.R.C)) {
16089           if (!sibling.L || !sibling.L.C) {
16090             sibling.R.C = false;
16091             sibling.C = true;
16092             RedBlackRotateLeft(this, sibling);
16093             sibling = parent.L;
16094           }
16095           sibling.C = parent.C;
16096           parent.C = sibling.L.C = false;
16097           RedBlackRotateRight(this, parent);
16098           node = this._;
16099           break;
16100         }
16101       }
16102       sibling.C = true;
16103       node = parent;
16104       parent = parent.U;
16105     } while (!node.C);
16106
16107     if (node) node.C = false;
16108   }
16109 };
16110
16111 function RedBlackRotateLeft(tree, node) {
16112   var p = node,
16113       q = node.R,
16114       parent = p.U;
16115
16116   if (parent) {
16117     if (parent.L === p) parent.L = q;
16118     else parent.R = q;
16119   } else {
16120     tree._ = q;
16121   }
16122
16123   q.U = parent;
16124   p.U = q;
16125   p.R = q.L;
16126   if (p.R) p.R.U = p;
16127   q.L = p;
16128 }
16129
16130 function RedBlackRotateRight(tree, node) {
16131   var p = node,
16132       q = node.L,
16133       parent = p.U;
16134
16135   if (parent) {
16136     if (parent.L === p) parent.L = q;
16137     else parent.R = q;
16138   } else {
16139     tree._ = q;
16140   }
16141
16142   q.U = parent;
16143   p.U = q;
16144   p.L = q.R;
16145   if (p.L) p.L.U = p;
16146   q.R = p;
16147 }
16148
16149 function RedBlackFirst(node) {
16150   while (node.L) node = node.L;
16151   return node;
16152 }
16153
16154 function createEdge(left, right, v0, v1) {
16155   var edge = [null, null],
16156       index = edges.push(edge) - 1;
16157   edge.left = left;
16158   edge.right = right;
16159   if (v0) setEdgeEnd(edge, left, right, v0);
16160   if (v1) setEdgeEnd(edge, right, left, v1);
16161   cells[left.index].halfedges.push(index);
16162   cells[right.index].halfedges.push(index);
16163   return edge;
16164 }
16165
16166 function createBorderEdge(left, v0, v1) {
16167   var edge = [v0, v1];
16168   edge.left = left;
16169   return edge;
16170 }
16171
16172 function setEdgeEnd(edge, left, right, vertex) {
16173   if (!edge[0] && !edge[1]) {
16174     edge[0] = vertex;
16175     edge.left = left;
16176     edge.right = right;
16177   } else if (edge.left === right) {
16178     edge[1] = vertex;
16179   } else {
16180     edge[0] = vertex;
16181   }
16182 }
16183
16184 // Liang–Barsky line clipping.
16185 function clipEdge(edge, x0, y0, x1, y1) {
16186   var a = edge[0],
16187       b = edge[1],
16188       ax = a[0],
16189       ay = a[1],
16190       bx = b[0],
16191       by = b[1],
16192       t0 = 0,
16193       t1 = 1,
16194       dx = bx - ax,
16195       dy = by - ay,
16196       r;
16197
16198   r = x0 - ax;
16199   if (!dx && r > 0) return;
16200   r /= dx;
16201   if (dx < 0) {
16202     if (r < t0) return;
16203     if (r < t1) t1 = r;
16204   } else if (dx > 0) {
16205     if (r > t1) return;
16206     if (r > t0) t0 = r;
16207   }
16208
16209   r = x1 - ax;
16210   if (!dx && r < 0) return;
16211   r /= dx;
16212   if (dx < 0) {
16213     if (r > t1) return;
16214     if (r > t0) t0 = r;
16215   } else if (dx > 0) {
16216     if (r < t0) return;
16217     if (r < t1) t1 = r;
16218   }
16219
16220   r = y0 - ay;
16221   if (!dy && r > 0) return;
16222   r /= dy;
16223   if (dy < 0) {
16224     if (r < t0) return;
16225     if (r < t1) t1 = r;
16226   } else if (dy > 0) {
16227     if (r > t1) return;
16228     if (r > t0) t0 = r;
16229   }
16230
16231   r = y1 - ay;
16232   if (!dy && r < 0) return;
16233   r /= dy;
16234   if (dy < 0) {
16235     if (r > t1) return;
16236     if (r > t0) t0 = r;
16237   } else if (dy > 0) {
16238     if (r < t0) return;
16239     if (r < t1) t1 = r;
16240   }
16241
16242   if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
16243
16244   if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
16245   if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
16246   return true;
16247 }
16248
16249 function connectEdge(edge, x0, y0, x1, y1) {
16250   var v1 = edge[1];
16251   if (v1) return true;
16252
16253   var v0 = edge[0],
16254       left = edge.left,
16255       right = edge.right,
16256       lx = left[0],
16257       ly = left[1],
16258       rx = right[0],
16259       ry = right[1],
16260       fx = (lx + rx) / 2,
16261       fy = (ly + ry) / 2,
16262       fm,
16263       fb;
16264
16265   if (ry === ly) {
16266     if (fx < x0 || fx >= x1) return;
16267     if (lx > rx) {
16268       if (!v0) v0 = [fx, y0];
16269       else if (v0[1] >= y1) return;
16270       v1 = [fx, y1];
16271     } else {
16272       if (!v0) v0 = [fx, y1];
16273       else if (v0[1] < y0) return;
16274       v1 = [fx, y0];
16275     }
16276   } else {
16277     fm = (lx - rx) / (ry - ly);
16278     fb = fy - fm * fx;
16279     if (fm < -1 || fm > 1) {
16280       if (lx > rx) {
16281         if (!v0) v0 = [(y0 - fb) / fm, y0];
16282         else if (v0[1] >= y1) return;
16283         v1 = [(y1 - fb) / fm, y1];
16284       } else {
16285         if (!v0) v0 = [(y1 - fb) / fm, y1];
16286         else if (v0[1] < y0) return;
16287         v1 = [(y0 - fb) / fm, y0];
16288       }
16289     } else {
16290       if (ly < ry) {
16291         if (!v0) v0 = [x0, fm * x0 + fb];
16292         else if (v0[0] >= x1) return;
16293         v1 = [x1, fm * x1 + fb];
16294       } else {
16295         if (!v0) v0 = [x1, fm * x1 + fb];
16296         else if (v0[0] < x0) return;
16297         v1 = [x0, fm * x0 + fb];
16298       }
16299     }
16300   }
16301
16302   edge[0] = v0;
16303   edge[1] = v1;
16304   return true;
16305 }
16306
16307 function clipEdges(x0, y0, x1, y1) {
16308   var i = edges.length,
16309       edge;
16310
16311   while (i--) {
16312     if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
16313         || !clipEdge(edge, x0, y0, x1, y1)
16314         || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
16315             || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
16316       delete edges[i];
16317     }
16318   }
16319 }
16320
16321 function createCell(site) {
16322   return cells[site.index] = {
16323     site: site,
16324     halfedges: []
16325   };
16326 }
16327
16328 function cellHalfedgeAngle(cell, edge) {
16329   var site = cell.site,
16330       va = edge.left,
16331       vb = edge.right;
16332   if (site === vb) vb = va, va = site;
16333   if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
16334   if (site === va) va = edge[1], vb = edge[0];
16335   else va = edge[0], vb = edge[1];
16336   return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
16337 }
16338
16339 function cellHalfedgeStart(cell, edge) {
16340   return edge[+(edge.left !== cell.site)];
16341 }
16342
16343 function cellHalfedgeEnd(cell, edge) {
16344   return edge[+(edge.left === cell.site)];
16345 }
16346
16347 function sortCellHalfedges() {
16348   for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
16349     if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
16350       var index = new Array(m),
16351           array = new Array(m);
16352       for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
16353       index.sort(function(i, j) { return array[j] - array[i]; });
16354       for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
16355       for (j = 0; j < m; ++j) halfedges[j] = array[j];
16356     }
16357   }
16358 }
16359
16360 function clipCells(x0, y0, x1, y1) {
16361   var nCells = cells.length,
16362       iCell,
16363       cell,
16364       site,
16365       iHalfedge,
16366       halfedges,
16367       nHalfedges,
16368       start,
16369       startX,
16370       startY,
16371       end,
16372       endX,
16373       endY,
16374       cover = true;
16375
16376   for (iCell = 0; iCell < nCells; ++iCell) {
16377     if (cell = cells[iCell]) {
16378       site = cell.site;
16379       halfedges = cell.halfedges;
16380       iHalfedge = halfedges.length;
16381
16382       // Remove any dangling clipped edges.
16383       while (iHalfedge--) {
16384         if (!edges[halfedges[iHalfedge]]) {
16385           halfedges.splice(iHalfedge, 1);
16386         }
16387       }
16388
16389       // Insert any border edges as necessary.
16390       iHalfedge = 0, nHalfedges = halfedges.length;
16391       while (iHalfedge < nHalfedges) {
16392         end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
16393         start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
16394         if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
16395           halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
16396               Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
16397               : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
16398               : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
16399               : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
16400               : null)) - 1);
16401           ++nHalfedges;
16402         }
16403       }
16404
16405       if (nHalfedges) cover = false;
16406     }
16407   }
16408
16409   // If there weren’t any edges, have the closest site cover the extent.
16410   // It doesn’t matter which corner of the extent we measure!
16411   if (cover) {
16412     var dx, dy, d2, dc = Infinity;
16413
16414     for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
16415       if (cell = cells[iCell]) {
16416         site = cell.site;
16417         dx = site[0] - x0;
16418         dy = site[1] - y0;
16419         d2 = dx * dx + dy * dy;
16420         if (d2 < dc) dc = d2, cover = cell;
16421       }
16422     }
16423
16424     if (cover) {
16425       var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
16426       cover.halfedges.push(
16427         edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
16428         edges.push(createBorderEdge(site, v01, v11)) - 1,
16429         edges.push(createBorderEdge(site, v11, v10)) - 1,
16430         edges.push(createBorderEdge(site, v10, v00)) - 1
16431       );
16432     }
16433   }
16434
16435   // Lastly delete any cells with no edges; these were entirely clipped.
16436   for (iCell = 0; iCell < nCells; ++iCell) {
16437     if (cell = cells[iCell]) {
16438       if (!cell.halfedges.length) {
16439         delete cells[iCell];
16440       }
16441     }
16442   }
16443 }
16444
16445 var circlePool = [];
16446
16447 var firstCircle;
16448
16449 function Circle() {
16450   RedBlackNode(this);
16451   this.x =
16452   this.y =
16453   this.arc =
16454   this.site =
16455   this.cy = null;
16456 }
16457
16458 function attachCircle(arc) {
16459   var lArc = arc.P,
16460       rArc = arc.N;
16461
16462   if (!lArc || !rArc) return;
16463
16464   var lSite = lArc.site,
16465       cSite = arc.site,
16466       rSite = rArc.site;
16467
16468   if (lSite === rSite) return;
16469
16470   var bx = cSite[0],
16471       by = cSite[1],
16472       ax = lSite[0] - bx,
16473       ay = lSite[1] - by,
16474       cx = rSite[0] - bx,
16475       cy = rSite[1] - by;
16476
16477   var d = 2 * (ax * cy - ay * cx);
16478   if (d >= -epsilon2$2) return;
16479
16480   var ha = ax * ax + ay * ay,
16481       hc = cx * cx + cy * cy,
16482       x = (cy * ha - ay * hc) / d,
16483       y = (ax * hc - cx * ha) / d;
16484
16485   var circle = circlePool.pop() || new Circle;
16486   circle.arc = arc;
16487   circle.site = cSite;
16488   circle.x = x + bx;
16489   circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
16490
16491   arc.circle = circle;
16492
16493   var before = null,
16494       node = circles._;
16495
16496   while (node) {
16497     if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
16498       if (node.L) node = node.L;
16499       else { before = node.P; break; }
16500     } else {
16501       if (node.R) node = node.R;
16502       else { before = node; break; }
16503     }
16504   }
16505
16506   circles.insert(before, circle);
16507   if (!before) firstCircle = circle;
16508 }
16509
16510 function detachCircle(arc) {
16511   var circle = arc.circle;
16512   if (circle) {
16513     if (!circle.P) firstCircle = circle.N;
16514     circles.remove(circle);
16515     circlePool.push(circle);
16516     RedBlackNode(circle);
16517     arc.circle = null;
16518   }
16519 }
16520
16521 var beachPool = [];
16522
16523 function Beach() {
16524   RedBlackNode(this);
16525   this.edge =
16526   this.site =
16527   this.circle = null;
16528 }
16529
16530 function createBeach(site) {
16531   var beach = beachPool.pop() || new Beach;
16532   beach.site = site;
16533   return beach;
16534 }
16535
16536 function detachBeach(beach) {
16537   detachCircle(beach);
16538   beaches.remove(beach);
16539   beachPool.push(beach);
16540   RedBlackNode(beach);
16541 }
16542
16543 function removeBeach(beach) {
16544   var circle = beach.circle,
16545       x = circle.x,
16546       y = circle.cy,
16547       vertex = [x, y],
16548       previous = beach.P,
16549       next = beach.N,
16550       disappearing = [beach];
16551
16552   detachBeach(beach);
16553
16554   var lArc = previous;
16555   while (lArc.circle
16556       && Math.abs(x - lArc.circle.x) < epsilon$4
16557       && Math.abs(y - lArc.circle.cy) < epsilon$4) {
16558     previous = lArc.P;
16559     disappearing.unshift(lArc);
16560     detachBeach(lArc);
16561     lArc = previous;
16562   }
16563
16564   disappearing.unshift(lArc);
16565   detachCircle(lArc);
16566
16567   var rArc = next;
16568   while (rArc.circle
16569       && Math.abs(x - rArc.circle.x) < epsilon$4
16570       && Math.abs(y - rArc.circle.cy) < epsilon$4) {
16571     next = rArc.N;
16572     disappearing.push(rArc);
16573     detachBeach(rArc);
16574     rArc = next;
16575   }
16576
16577   disappearing.push(rArc);
16578   detachCircle(rArc);
16579
16580   var nArcs = disappearing.length,
16581       iArc;
16582   for (iArc = 1; iArc < nArcs; ++iArc) {
16583     rArc = disappearing[iArc];
16584     lArc = disappearing[iArc - 1];
16585     setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
16586   }
16587
16588   lArc = disappearing[0];
16589   rArc = disappearing[nArcs - 1];
16590   rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
16591
16592   attachCircle(lArc);
16593   attachCircle(rArc);
16594 }
16595
16596 function addBeach(site) {
16597   var x = site[0],
16598       directrix = site[1],
16599       lArc,
16600       rArc,
16601       dxl,
16602       dxr,
16603       node = beaches._;
16604
16605   while (node) {
16606     dxl = leftBreakPoint(node, directrix) - x;
16607     if (dxl > epsilon$4) node = node.L; else {
16608       dxr = x - rightBreakPoint(node, directrix);
16609       if (dxr > epsilon$4) {
16610         if (!node.R) {
16611           lArc = node;
16612           break;
16613         }
16614         node = node.R;
16615       } else {
16616         if (dxl > -epsilon$4) {
16617           lArc = node.P;
16618           rArc = node;
16619         } else if (dxr > -epsilon$4) {
16620           lArc = node;
16621           rArc = node.N;
16622         } else {
16623           lArc = rArc = node;
16624         }
16625         break;
16626       }
16627     }
16628   }
16629
16630   createCell(site);
16631   var newArc = createBeach(site);
16632   beaches.insert(lArc, newArc);
16633
16634   if (!lArc && !rArc) return;
16635
16636   if (lArc === rArc) {
16637     detachCircle(lArc);
16638     rArc = createBeach(lArc.site);
16639     beaches.insert(newArc, rArc);
16640     newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
16641     attachCircle(lArc);
16642     attachCircle(rArc);
16643     return;
16644   }
16645
16646   if (!rArc) { // && lArc
16647     newArc.edge = createEdge(lArc.site, newArc.site);
16648     return;
16649   }
16650
16651   // else lArc !== rArc
16652   detachCircle(lArc);
16653   detachCircle(rArc);
16654
16655   var lSite = lArc.site,
16656       ax = lSite[0],
16657       ay = lSite[1],
16658       bx = site[0] - ax,
16659       by = site[1] - ay,
16660       rSite = rArc.site,
16661       cx = rSite[0] - ax,
16662       cy = rSite[1] - ay,
16663       d = 2 * (bx * cy - by * cx),
16664       hb = bx * bx + by * by,
16665       hc = cx * cx + cy * cy,
16666       vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
16667
16668   setEdgeEnd(rArc.edge, lSite, rSite, vertex);
16669   newArc.edge = createEdge(lSite, site, null, vertex);
16670   rArc.edge = createEdge(site, rSite, null, vertex);
16671   attachCircle(lArc);
16672   attachCircle(rArc);
16673 }
16674
16675 function leftBreakPoint(arc, directrix) {
16676   var site = arc.site,
16677       rfocx = site[0],
16678       rfocy = site[1],
16679       pby2 = rfocy - directrix;
16680
16681   if (!pby2) return rfocx;
16682
16683   var lArc = arc.P;
16684   if (!lArc) return -Infinity;
16685
16686   site = lArc.site;
16687   var lfocx = site[0],
16688       lfocy = site[1],
16689       plby2 = lfocy - directrix;
16690
16691   if (!plby2) return lfocx;
16692
16693   var hl = lfocx - rfocx,
16694       aby2 = 1 / pby2 - 1 / plby2,
16695       b = hl / plby2;
16696
16697   if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
16698
16699   return (rfocx + lfocx) / 2;
16700 }
16701
16702 function rightBreakPoint(arc, directrix) {
16703   var rArc = arc.N;
16704   if (rArc) return leftBreakPoint(rArc, directrix);
16705   var site = arc.site;
16706   return site[1] === directrix ? site[0] : Infinity;
16707 }
16708
16709 var epsilon$4 = 1e-6;
16710 var epsilon2$2 = 1e-12;
16711 var beaches;
16712 var cells;
16713 var circles;
16714 var edges;
16715
16716 function triangleArea(a, b, c) {
16717   return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
16718 }
16719
16720 function lexicographic(a, b) {
16721   return b[1] - a[1]
16722       || b[0] - a[0];
16723 }
16724
16725 function Diagram(sites, extent) {
16726   var site = sites.sort(lexicographic).pop(),
16727       x,
16728       y,
16729       circle;
16730
16731   edges = [];
16732   cells = new Array(sites.length);
16733   beaches = new RedBlackTree;
16734   circles = new RedBlackTree;
16735
16736   while (true) {
16737     circle = firstCircle;
16738     if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
16739       if (site[0] !== x || site[1] !== y) {
16740         addBeach(site);
16741         x = site[0], y = site[1];
16742       }
16743       site = sites.pop();
16744     } else if (circle) {
16745       removeBeach(circle.arc);
16746     } else {
16747       break;
16748     }
16749   }
16750
16751   sortCellHalfedges();
16752
16753   if (extent) {
16754     var x0 = +extent[0][0],
16755         y0 = +extent[0][1],
16756         x1 = +extent[1][0],
16757         y1 = +extent[1][1];
16758     clipEdges(x0, y0, x1, y1);
16759     clipCells(x0, y0, x1, y1);
16760   }
16761
16762   this.edges = edges;
16763   this.cells = cells;
16764
16765   beaches =
16766   circles =
16767   edges =
16768   cells = null;
16769 }
16770
16771 Diagram.prototype = {
16772   constructor: Diagram,
16773
16774   polygons: function() {
16775     var edges = this.edges;
16776
16777     return this.cells.map(function(cell) {
16778       var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
16779       polygon.data = cell.site.data;
16780       return polygon;
16781     });
16782   },
16783
16784   triangles: function() {
16785     var triangles = [],
16786         edges = this.edges;
16787
16788     this.cells.forEach(function(cell, i) {
16789       if (!(m = (halfedges = cell.halfedges).length)) return;
16790       var site = cell.site,
16791           halfedges,
16792           j = -1,
16793           m,
16794           s0,
16795           e1 = edges[halfedges[m - 1]],
16796           s1 = e1.left === site ? e1.right : e1.left;
16797
16798       while (++j < m) {
16799         s0 = s1;
16800         e1 = edges[halfedges[j]];
16801         s1 = e1.left === site ? e1.right : e1.left;
16802         if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
16803           triangles.push([site.data, s0.data, s1.data]);
16804         }
16805       }
16806     });
16807
16808     return triangles;
16809   },
16810
16811   links: function() {
16812     return this.edges.filter(function(edge) {
16813       return edge.right;
16814     }).map(function(edge) {
16815       return {
16816         source: edge.left.data,
16817         target: edge.right.data
16818       };
16819     });
16820   },
16821
16822   find: function(x, y, radius) {
16823     var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
16824
16825     // Use the previously-found cell, or start with an arbitrary one.
16826     while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
16827     var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
16828
16829     // Traverse the half-edges to find a closer cell, if any.
16830     do {
16831       cell = that.cells[i0 = i1], i1 = null;
16832       cell.halfedges.forEach(function(e) {
16833         var edge = that.edges[e], v = edge.left;
16834         if ((v === cell.site || !v) && !(v = edge.right)) return;
16835         var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
16836         if (v2 < d2) d2 = v2, i1 = v.index;
16837       });
16838     } while (i1 !== null);
16839
16840     that._found = i0;
16841
16842     return radius == null || d2 <= radius * radius ? cell.site : null;
16843   }
16844 };
16845
16846 function voronoi() {
16847   var x$$1 = x$4,
16848       y$$1 = y$4,
16849       extent = null;
16850
16851   function voronoi(data) {
16852     return new Diagram(data.map(function(d, i) {
16853       var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
16854       s.index = i;
16855       s.data = d;
16856       return s;
16857     }), extent);
16858   }
16859
16860   voronoi.polygons = function(data) {
16861     return voronoi(data).polygons();
16862   };
16863
16864   voronoi.links = function(data) {
16865     return voronoi(data).links();
16866   };
16867
16868   voronoi.triangles = function(data) {
16869     return voronoi(data).triangles();
16870   };
16871
16872   voronoi.x = function(_) {
16873     return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : x$$1;
16874   };
16875
16876   voronoi.y = function(_) {
16877     return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$12(+_), voronoi) : y$$1;
16878   };
16879
16880   voronoi.extent = function(_) {
16881     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]]];
16882   };
16883
16884   voronoi.size = function(_) {
16885     return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
16886   };
16887
16888   return voronoi;
16889 }
16890
16891 function constant$13(x) {
16892   return function() {
16893     return x;
16894   };
16895 }
16896
16897 function ZoomEvent(target, type, transform) {
16898   this.target = target;
16899   this.type = type;
16900   this.transform = transform;
16901 }
16902
16903 function Transform(k, x, y) {
16904   this.k = k;
16905   this.x = x;
16906   this.y = y;
16907 }
16908
16909 Transform.prototype = {
16910   constructor: Transform,
16911   scale: function(k) {
16912     return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
16913   },
16914   translate: function(x, y) {
16915     return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
16916   },
16917   apply: function(point) {
16918     return [point[0] * this.k + this.x, point[1] * this.k + this.y];
16919   },
16920   applyX: function(x) {
16921     return x * this.k + this.x;
16922   },
16923   applyY: function(y) {
16924     return y * this.k + this.y;
16925   },
16926   invert: function(location) {
16927     return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
16928   },
16929   invertX: function(x) {
16930     return (x - this.x) / this.k;
16931   },
16932   invertY: function(y) {
16933     return (y - this.y) / this.k;
16934   },
16935   rescaleX: function(x) {
16936     return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
16937   },
16938   rescaleY: function(y) {
16939     return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
16940   },
16941   toString: function() {
16942     return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
16943   }
16944 };
16945
16946 var identity$8 = new Transform(1, 0, 0);
16947
16948 transform$1.prototype = Transform.prototype;
16949
16950 function transform$1(node) {
16951   return node.__zoom || identity$8;
16952 }
16953
16954 function nopropagation$2() {
16955   exports.event.stopImmediatePropagation();
16956 }
16957
16958 function noevent$2() {
16959   exports.event.preventDefault();
16960   exports.event.stopImmediatePropagation();
16961 }
16962
16963 // Ignore right-click, since that should open the context menu.
16964 function defaultFilter$2() {
16965   return !exports.event.button;
16966 }
16967
16968 function defaultExtent$1() {
16969   var e = this, w, h;
16970   if (e instanceof SVGElement) {
16971     e = e.ownerSVGElement || e;
16972     w = e.width.baseVal.value;
16973     h = e.height.baseVal.value;
16974   } else {
16975     w = e.clientWidth;
16976     h = e.clientHeight;
16977   }
16978   return [[0, 0], [w, h]];
16979 }
16980
16981 function defaultTransform() {
16982   return this.__zoom || identity$8;
16983 }
16984
16985 function defaultWheelDelta() {
16986   return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
16987 }
16988
16989 function defaultTouchable$1() {
16990   return "ontouchstart" in this;
16991 }
16992
16993 function defaultConstrain(transform, extent, translateExtent) {
16994   var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
16995       dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
16996       dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
16997       dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
16998   return transform.translate(
16999     dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
17000     dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
17001   );
17002 }
17003
17004 function zoom() {
17005   var filter = defaultFilter$2,
17006       extent = defaultExtent$1,
17007       constrain = defaultConstrain,
17008       wheelDelta = defaultWheelDelta,
17009       touchable = defaultTouchable$1,
17010       scaleExtent = [0, Infinity],
17011       translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
17012       duration = 250,
17013       interpolate = interpolateZoom,
17014       gestures = [],
17015       listeners = dispatch("start", "zoom", "end"),
17016       touchstarting,
17017       touchending,
17018       touchDelay = 500,
17019       wheelDelay = 150,
17020       clickDistance2 = 0;
17021
17022   function zoom(selection$$1) {
17023     selection$$1
17024         .property("__zoom", defaultTransform)
17025         .on("wheel.zoom", wheeled)
17026         .on("mousedown.zoom", mousedowned)
17027         .on("dblclick.zoom", dblclicked)
17028       .filter(touchable)
17029         .on("touchstart.zoom", touchstarted)
17030         .on("touchmove.zoom", touchmoved)
17031         .on("touchend.zoom touchcancel.zoom", touchended)
17032         .style("touch-action", "none")
17033         .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
17034   }
17035
17036   zoom.transform = function(collection, transform) {
17037     var selection$$1 = collection.selection ? collection.selection() : collection;
17038     selection$$1.property("__zoom", defaultTransform);
17039     if (collection !== selection$$1) {
17040       schedule(collection, transform);
17041     } else {
17042       selection$$1.interrupt().each(function() {
17043         gesture(this, arguments)
17044             .start()
17045             .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
17046             .end();
17047       });
17048     }
17049   };
17050
17051   zoom.scaleBy = function(selection$$1, k) {
17052     zoom.scaleTo(selection$$1, function() {
17053       var k0 = this.__zoom.k,
17054           k1 = typeof k === "function" ? k.apply(this, arguments) : k;
17055       return k0 * k1;
17056     });
17057   };
17058
17059   zoom.scaleTo = function(selection$$1, k) {
17060     zoom.transform(selection$$1, function() {
17061       var e = extent.apply(this, arguments),
17062           t0 = this.__zoom,
17063           p0 = centroid(e),
17064           p1 = t0.invert(p0),
17065           k1 = typeof k === "function" ? k.apply(this, arguments) : k;
17066       return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
17067     });
17068   };
17069
17070   zoom.translateBy = function(selection$$1, x, y) {
17071     zoom.transform(selection$$1, function() {
17072       return constrain(this.__zoom.translate(
17073         typeof x === "function" ? x.apply(this, arguments) : x,
17074         typeof y === "function" ? y.apply(this, arguments) : y
17075       ), extent.apply(this, arguments), translateExtent);
17076     });
17077   };
17078
17079   zoom.translateTo = function(selection$$1, x, y) {
17080     zoom.transform(selection$$1, function() {
17081       var e = extent.apply(this, arguments),
17082           t = this.__zoom,
17083           p = centroid(e);
17084       return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
17085         typeof x === "function" ? -x.apply(this, arguments) : -x,
17086         typeof y === "function" ? -y.apply(this, arguments) : -y
17087       ), e, translateExtent);
17088     });
17089   };
17090
17091   function scale(transform, k) {
17092     k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
17093     return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
17094   }
17095
17096   function translate(transform, p0, p1) {
17097     var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
17098     return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
17099   }
17100
17101   function centroid(extent) {
17102     return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
17103   }
17104
17105   function schedule(transition$$1, transform, center) {
17106     transition$$1
17107         .on("start.zoom", function() { gesture(this, arguments).start(); })
17108         .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
17109         .tween("zoom", function() {
17110           var that = this,
17111               args = arguments,
17112               g = gesture(that, args),
17113               e = extent.apply(that, args),
17114               p = center || centroid(e),
17115               w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
17116               a = that.__zoom,
17117               b = typeof transform === "function" ? transform.apply(that, args) : transform,
17118               i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
17119           return function(t) {
17120             if (t === 1) t = b; // Avoid rounding error on end.
17121             else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
17122             g.zoom(null, t);
17123           };
17124         });
17125   }
17126
17127   function gesture(that, args) {
17128     for (var i = 0, n = gestures.length, g; i < n; ++i) {
17129       if ((g = gestures[i]).that === that) {
17130         return g;
17131       }
17132     }
17133     return new Gesture(that, args);
17134   }
17135
17136   function Gesture(that, args) {
17137     this.that = that;
17138     this.args = args;
17139     this.index = -1;
17140     this.active = 0;
17141     this.extent = extent.apply(that, args);
17142   }
17143
17144   Gesture.prototype = {
17145     start: function() {
17146       if (++this.active === 1) {
17147         this.index = gestures.push(this) - 1;
17148         this.emit("start");
17149       }
17150       return this;
17151     },
17152     zoom: function(key, transform) {
17153       if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
17154       if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
17155       if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
17156       this.that.__zoom = transform;
17157       this.emit("zoom");
17158       return this;
17159     },
17160     end: function() {
17161       if (--this.active === 0) {
17162         gestures.splice(this.index, 1);
17163         this.index = -1;
17164         this.emit("end");
17165       }
17166       return this;
17167     },
17168     emit: function(type) {
17169       customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
17170     }
17171   };
17172
17173   function wheeled() {
17174     if (!filter.apply(this, arguments)) return;
17175     var g = gesture(this, arguments),
17176         t = this.__zoom,
17177         k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
17178         p = mouse(this);
17179
17180     // If the mouse is in the same location as before, reuse it.
17181     // If there were recent wheel events, reset the wheel idle timeout.
17182     if (g.wheel) {
17183       if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
17184         g.mouse[1] = t.invert(g.mouse[0] = p);
17185       }
17186       clearTimeout(g.wheel);
17187     }
17188
17189     // If this wheel event won’t trigger a transform change, ignore it.
17190     else if (t.k === k) return;
17191
17192     // Otherwise, capture the mouse point and location at the start.
17193     else {
17194       g.mouse = [p, t.invert(p)];
17195       interrupt(this);
17196       g.start();
17197     }
17198
17199     noevent$2();
17200     g.wheel = setTimeout(wheelidled, wheelDelay);
17201     g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
17202
17203     function wheelidled() {
17204       g.wheel = null;
17205       g.end();
17206     }
17207   }
17208
17209   function mousedowned() {
17210     if (touchending || !filter.apply(this, arguments)) return;
17211     var g = gesture(this, arguments),
17212         v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
17213         p = mouse(this),
17214         x0 = exports.event.clientX,
17215         y0 = exports.event.clientY;
17216
17217     dragDisable(exports.event.view);
17218     nopropagation$2();
17219     g.mouse = [p, this.__zoom.invert(p)];
17220     interrupt(this);
17221     g.start();
17222
17223     function mousemoved() {
17224       noevent$2();
17225       if (!g.moved) {
17226         var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
17227         g.moved = dx * dx + dy * dy > clickDistance2;
17228       }
17229       g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
17230     }
17231
17232     function mouseupped() {
17233       v.on("mousemove.zoom mouseup.zoom", null);
17234       yesdrag(exports.event.view, g.moved);
17235       noevent$2();
17236       g.end();
17237     }
17238   }
17239
17240   function dblclicked() {
17241     if (!filter.apply(this, arguments)) return;
17242     var t0 = this.__zoom,
17243         p0 = mouse(this),
17244         p1 = t0.invert(p0),
17245         k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
17246         t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
17247
17248     noevent$2();
17249     if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
17250     else select(this).call(zoom.transform, t1);
17251   }
17252
17253   function touchstarted() {
17254     if (!filter.apply(this, arguments)) return;
17255     var g = gesture(this, arguments),
17256         touches$$1 = exports.event.changedTouches,
17257         started,
17258         n = touches$$1.length, i, t, p;
17259
17260     nopropagation$2();
17261     for (i = 0; i < n; ++i) {
17262       t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
17263       p = [p, this.__zoom.invert(p), t.identifier];
17264       if (!g.touch0) g.touch0 = p, started = true;
17265       else if (!g.touch1) g.touch1 = p;
17266     }
17267
17268     // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
17269     if (touchstarting) {
17270       touchstarting = clearTimeout(touchstarting);
17271       if (!g.touch1) {
17272         g.end();
17273         p = select(this).on("dblclick.zoom");
17274         if (p) p.apply(this, arguments);
17275         return;
17276       }
17277     }
17278
17279     if (started) {
17280       touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
17281       interrupt(this);
17282       g.start();
17283     }
17284   }
17285
17286   function touchmoved() {
17287     var g = gesture(this, arguments),
17288         touches$$1 = exports.event.changedTouches,
17289         n = touches$$1.length, i, t, p, l;
17290
17291     noevent$2();
17292     if (touchstarting) touchstarting = clearTimeout(touchstarting);
17293     for (i = 0; i < n; ++i) {
17294       t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
17295       if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
17296       else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
17297     }
17298     t = g.that.__zoom;
17299     if (g.touch1) {
17300       var p0 = g.touch0[0], l0 = g.touch0[1],
17301           p1 = g.touch1[0], l1 = g.touch1[1],
17302           dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
17303           dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
17304       t = scale(t, Math.sqrt(dp / dl));
17305       p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
17306       l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
17307     }
17308     else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
17309     else return;
17310     g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
17311   }
17312
17313   function touchended() {
17314     var g = gesture(this, arguments),
17315         touches$$1 = exports.event.changedTouches,
17316         n = touches$$1.length, i, t;
17317
17318     nopropagation$2();
17319     if (touchending) clearTimeout(touchending);
17320     touchending = setTimeout(function() { touchending = null; }, touchDelay);
17321     for (i = 0; i < n; ++i) {
17322       t = touches$$1[i];
17323       if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
17324       else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
17325     }
17326     if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
17327     if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
17328     else g.end();
17329   }
17330
17331   zoom.wheelDelta = function(_) {
17332     return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$13(+_), zoom) : wheelDelta;
17333   };
17334
17335   zoom.filter = function(_) {
17336     return arguments.length ? (filter = typeof _ === "function" ? _ : constant$13(!!_), zoom) : filter;
17337   };
17338
17339   zoom.touchable = function(_) {
17340     return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$13(!!_), zoom) : touchable;
17341   };
17342
17343   zoom.extent = function(_) {
17344     return arguments.length ? (extent = typeof _ === "function" ? _ : constant$13([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
17345   };
17346
17347   zoom.scaleExtent = function(_) {
17348     return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
17349   };
17350
17351   zoom.translateExtent = function(_) {
17352     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]]];
17353   };
17354
17355   zoom.constrain = function(_) {
17356     return arguments.length ? (constrain = _, zoom) : constrain;
17357   };
17358
17359   zoom.duration = function(_) {
17360     return arguments.length ? (duration = +_, zoom) : duration;
17361   };
17362
17363   zoom.interpolate = function(_) {
17364     return arguments.length ? (interpolate = _, zoom) : interpolate;
17365   };
17366
17367   zoom.on = function() {
17368     var value = listeners.on.apply(listeners, arguments);
17369     return value === listeners ? zoom : value;
17370   };
17371
17372   zoom.clickDistance = function(_) {
17373     return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
17374   };
17375
17376   return zoom;
17377 }
17378
17379 exports.version = version;
17380 exports.bisect = bisectRight;
17381 exports.bisectRight = bisectRight;
17382 exports.bisectLeft = bisectLeft;
17383 exports.ascending = ascending;
17384 exports.bisector = bisector;
17385 exports.cross = cross;
17386 exports.descending = descending;
17387 exports.deviation = deviation;
17388 exports.extent = extent;
17389 exports.histogram = histogram;
17390 exports.thresholdFreedmanDiaconis = freedmanDiaconis;
17391 exports.thresholdScott = scott;
17392 exports.thresholdSturges = thresholdSturges;
17393 exports.max = max;
17394 exports.mean = mean;
17395 exports.median = median;
17396 exports.merge = merge;
17397 exports.min = min;
17398 exports.pairs = pairs;
17399 exports.permute = permute;
17400 exports.quantile = threshold;
17401 exports.range = sequence;
17402 exports.scan = scan;
17403 exports.shuffle = shuffle;
17404 exports.sum = sum;
17405 exports.ticks = ticks;
17406 exports.tickIncrement = tickIncrement;
17407 exports.tickStep = tickStep;
17408 exports.transpose = transpose;
17409 exports.variance = variance;
17410 exports.zip = zip;
17411 exports.axisTop = axisTop;
17412 exports.axisRight = axisRight;
17413 exports.axisBottom = axisBottom;
17414 exports.axisLeft = axisLeft;
17415 exports.brush = brush;
17416 exports.brushX = brushX;
17417 exports.brushY = brushY;
17418 exports.brushSelection = brushSelection;
17419 exports.chord = chord;
17420 exports.ribbon = ribbon;
17421 exports.nest = nest;
17422 exports.set = set$2;
17423 exports.map = map$1;
17424 exports.keys = keys;
17425 exports.values = values;
17426 exports.entries = entries;
17427 exports.color = color;
17428 exports.rgb = rgb;
17429 exports.hsl = hsl;
17430 exports.lab = lab;
17431 exports.hcl = hcl;
17432 exports.lch = lch;
17433 exports.gray = gray;
17434 exports.cubehelix = cubehelix;
17435 exports.contours = contours;
17436 exports.contourDensity = density;
17437 exports.dispatch = dispatch;
17438 exports.drag = drag;
17439 exports.dragDisable = dragDisable;
17440 exports.dragEnable = yesdrag;
17441 exports.dsvFormat = dsvFormat;
17442 exports.csvParse = csvParse;
17443 exports.csvParseRows = csvParseRows;
17444 exports.csvFormat = csvFormat;
17445 exports.csvFormatRows = csvFormatRows;
17446 exports.tsvParse = tsvParse;
17447 exports.tsvParseRows = tsvParseRows;
17448 exports.tsvFormat = tsvFormat;
17449 exports.tsvFormatRows = tsvFormatRows;
17450 exports.easeLinear = linear$1;
17451 exports.easeQuad = quadInOut;
17452 exports.easeQuadIn = quadIn;
17453 exports.easeQuadOut = quadOut;
17454 exports.easeQuadInOut = quadInOut;
17455 exports.easeCubic = cubicInOut;
17456 exports.easeCubicIn = cubicIn;
17457 exports.easeCubicOut = cubicOut;
17458 exports.easeCubicInOut = cubicInOut;
17459 exports.easePoly = polyInOut;
17460 exports.easePolyIn = polyIn;
17461 exports.easePolyOut = polyOut;
17462 exports.easePolyInOut = polyInOut;
17463 exports.easeSin = sinInOut;
17464 exports.easeSinIn = sinIn;
17465 exports.easeSinOut = sinOut;
17466 exports.easeSinInOut = sinInOut;
17467 exports.easeExp = expInOut;
17468 exports.easeExpIn = expIn;
17469 exports.easeExpOut = expOut;
17470 exports.easeExpInOut = expInOut;
17471 exports.easeCircle = circleInOut;
17472 exports.easeCircleIn = circleIn;
17473 exports.easeCircleOut = circleOut;
17474 exports.easeCircleInOut = circleInOut;
17475 exports.easeBounce = bounceOut;
17476 exports.easeBounceIn = bounceIn;
17477 exports.easeBounceOut = bounceOut;
17478 exports.easeBounceInOut = bounceInOut;
17479 exports.easeBack = backInOut;
17480 exports.easeBackIn = backIn;
17481 exports.easeBackOut = backOut;
17482 exports.easeBackInOut = backInOut;
17483 exports.easeElastic = elasticOut;
17484 exports.easeElasticIn = elasticIn;
17485 exports.easeElasticOut = elasticOut;
17486 exports.easeElasticInOut = elasticInOut;
17487 exports.blob = blob;
17488 exports.buffer = buffer;
17489 exports.dsv = dsv;
17490 exports.csv = csv$1;
17491 exports.tsv = tsv$1;
17492 exports.image = image;
17493 exports.json = json;
17494 exports.text = text;
17495 exports.xml = xml;
17496 exports.html = html;
17497 exports.svg = svg;
17498 exports.forceCenter = center$1;
17499 exports.forceCollide = collide;
17500 exports.forceLink = link;
17501 exports.forceManyBody = manyBody;
17502 exports.forceRadial = radial;
17503 exports.forceSimulation = simulation;
17504 exports.forceX = x$2;
17505 exports.forceY = y$2;
17506 exports.formatDefaultLocale = defaultLocale;
17507 exports.formatLocale = formatLocale;
17508 exports.formatSpecifier = formatSpecifier;
17509 exports.precisionFixed = precisionFixed;
17510 exports.precisionPrefix = precisionPrefix;
17511 exports.precisionRound = precisionRound;
17512 exports.geoArea = area$1;
17513 exports.geoBounds = bounds;
17514 exports.geoCentroid = centroid;
17515 exports.geoCircle = circle;
17516 exports.geoClipAntimeridian = clipAntimeridian;
17517 exports.geoClipCircle = clipCircle;
17518 exports.geoClipExtent = extent$1;
17519 exports.geoClipRectangle = clipRectangle;
17520 exports.geoContains = contains$1;
17521 exports.geoDistance = distance;
17522 exports.geoGraticule = graticule;
17523 exports.geoGraticule10 = graticule10;
17524 exports.geoInterpolate = interpolate$1;
17525 exports.geoLength = length$1;
17526 exports.geoPath = index$1;
17527 exports.geoAlbers = albers;
17528 exports.geoAlbersUsa = albersUsa;
17529 exports.geoAzimuthalEqualArea = azimuthalEqualArea;
17530 exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
17531 exports.geoAzimuthalEquidistant = azimuthalEquidistant;
17532 exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
17533 exports.geoConicConformal = conicConformal;
17534 exports.geoConicConformalRaw = conicConformalRaw;
17535 exports.geoConicEqualArea = conicEqualArea;
17536 exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
17537 exports.geoConicEquidistant = conicEquidistant;
17538 exports.geoConicEquidistantRaw = conicEquidistantRaw;
17539 exports.geoEquirectangular = equirectangular;
17540 exports.geoEquirectangularRaw = equirectangularRaw;
17541 exports.geoGnomonic = gnomonic;
17542 exports.geoGnomonicRaw = gnomonicRaw;
17543 exports.geoIdentity = identity$5;
17544 exports.geoProjection = projection;
17545 exports.geoProjectionMutator = projectionMutator;
17546 exports.geoMercator = mercator;
17547 exports.geoMercatorRaw = mercatorRaw;
17548 exports.geoNaturalEarth1 = naturalEarth1;
17549 exports.geoNaturalEarth1Raw = naturalEarth1Raw;
17550 exports.geoOrthographic = orthographic;
17551 exports.geoOrthographicRaw = orthographicRaw;
17552 exports.geoStereographic = stereographic;
17553 exports.geoStereographicRaw = stereographicRaw;
17554 exports.geoTransverseMercator = transverseMercator;
17555 exports.geoTransverseMercatorRaw = transverseMercatorRaw;
17556 exports.geoRotation = rotation;
17557 exports.geoStream = geoStream;
17558 exports.geoTransform = transform;
17559 exports.cluster = cluster;
17560 exports.hierarchy = hierarchy;
17561 exports.pack = index$2;
17562 exports.packSiblings = siblings;
17563 exports.packEnclose = enclose;
17564 exports.partition = partition;
17565 exports.stratify = stratify;
17566 exports.tree = tree;
17567 exports.treemap = index$3;
17568 exports.treemapBinary = binary;
17569 exports.treemapDice = treemapDice;
17570 exports.treemapSlice = treemapSlice;
17571 exports.treemapSliceDice = sliceDice;
17572 exports.treemapSquarify = squarify;
17573 exports.treemapResquarify = resquarify;
17574 exports.interpolate = interpolateValue;
17575 exports.interpolateArray = array$1;
17576 exports.interpolateBasis = basis$1;
17577 exports.interpolateBasisClosed = basisClosed;
17578 exports.interpolateDate = date;
17579 exports.interpolateNumber = reinterpolate;
17580 exports.interpolateObject = object;
17581 exports.interpolateRound = interpolateRound;
17582 exports.interpolateString = interpolateString;
17583 exports.interpolateTransformCss = interpolateTransformCss;
17584 exports.interpolateTransformSvg = interpolateTransformSvg;
17585 exports.interpolateZoom = interpolateZoom;
17586 exports.interpolateRgb = interpolateRgb;
17587 exports.interpolateRgbBasis = rgbBasis;
17588 exports.interpolateRgbBasisClosed = rgbBasisClosed;
17589 exports.interpolateHsl = hsl$2;
17590 exports.interpolateHslLong = hslLong;
17591 exports.interpolateLab = lab$1;
17592 exports.interpolateHcl = hcl$2;
17593 exports.interpolateHclLong = hclLong;
17594 exports.interpolateCubehelix = cubehelix$2;
17595 exports.interpolateCubehelixLong = cubehelixLong;
17596 exports.piecewise = piecewise;
17597 exports.quantize = quantize;
17598 exports.path = path;
17599 exports.polygonArea = area$2;
17600 exports.polygonCentroid = centroid$1;
17601 exports.polygonHull = hull;
17602 exports.polygonContains = contains$2;
17603 exports.polygonLength = length$2;
17604 exports.quadtree = quadtree;
17605 exports.randomUniform = uniform;
17606 exports.randomNormal = normal;
17607 exports.randomLogNormal = logNormal;
17608 exports.randomBates = bates;
17609 exports.randomIrwinHall = irwinHall;
17610 exports.randomExponential = exponential$1;
17611 exports.scaleBand = band;
17612 exports.scalePoint = point$1;
17613 exports.scaleIdentity = identity$6;
17614 exports.scaleLinear = linear$2;
17615 exports.scaleLog = log$1;
17616 exports.scaleOrdinal = ordinal;
17617 exports.scaleImplicit = implicit;
17618 exports.scalePow = pow$1;
17619 exports.scaleSqrt = sqrt$1;
17620 exports.scaleQuantile = quantile$$1;
17621 exports.scaleQuantize = quantize$1;
17622 exports.scaleThreshold = threshold$1;
17623 exports.scaleTime = time;
17624 exports.scaleUtc = utcTime;
17625 exports.scaleSequential = sequential;
17626 exports.scaleDiverging = diverging;
17627 exports.schemeCategory10 = category10;
17628 exports.schemeAccent = Accent;
17629 exports.schemeDark2 = Dark2;
17630 exports.schemePaired = Paired;
17631 exports.schemePastel1 = Pastel1;
17632 exports.schemePastel2 = Pastel2;
17633 exports.schemeSet1 = Set1;
17634 exports.schemeSet2 = Set2;
17635 exports.schemeSet3 = Set3;
17636 exports.interpolateBrBG = BrBG;
17637 exports.schemeBrBG = scheme;
17638 exports.interpolatePRGn = PRGn;
17639 exports.schemePRGn = scheme$1;
17640 exports.interpolatePiYG = PiYG;
17641 exports.schemePiYG = scheme$2;
17642 exports.interpolatePuOr = PuOr;
17643 exports.schemePuOr = scheme$3;
17644 exports.interpolateRdBu = RdBu;
17645 exports.schemeRdBu = scheme$4;
17646 exports.interpolateRdGy = RdGy;
17647 exports.schemeRdGy = scheme$5;
17648 exports.interpolateRdYlBu = RdYlBu;
17649 exports.schemeRdYlBu = scheme$6;
17650 exports.interpolateRdYlGn = RdYlGn;
17651 exports.schemeRdYlGn = scheme$7;
17652 exports.interpolateSpectral = Spectral;
17653 exports.schemeSpectral = scheme$8;
17654 exports.interpolateBuGn = BuGn;
17655 exports.schemeBuGn = scheme$9;
17656 exports.interpolateBuPu = BuPu;
17657 exports.schemeBuPu = scheme$10;
17658 exports.interpolateGnBu = GnBu;
17659 exports.schemeGnBu = scheme$11;
17660 exports.interpolateOrRd = OrRd;
17661 exports.schemeOrRd = scheme$12;
17662 exports.interpolatePuBuGn = PuBuGn;
17663 exports.schemePuBuGn = scheme$13;
17664 exports.interpolatePuBu = PuBu;
17665 exports.schemePuBu = scheme$14;
17666 exports.interpolatePuRd = PuRd;
17667 exports.schemePuRd = scheme$15;
17668 exports.interpolateRdPu = RdPu;
17669 exports.schemeRdPu = scheme$16;
17670 exports.interpolateYlGnBu = YlGnBu;
17671 exports.schemeYlGnBu = scheme$17;
17672 exports.interpolateYlGn = YlGn;
17673 exports.schemeYlGn = scheme$18;
17674 exports.interpolateYlOrBr = YlOrBr;
17675 exports.schemeYlOrBr = scheme$19;
17676 exports.interpolateYlOrRd = YlOrRd;
17677 exports.schemeYlOrRd = scheme$20;
17678 exports.interpolateBlues = Blues;
17679 exports.schemeBlues = scheme$21;
17680 exports.interpolateGreens = Greens;
17681 exports.schemeGreens = scheme$22;
17682 exports.interpolateGreys = Greys;
17683 exports.schemeGreys = scheme$23;
17684 exports.interpolatePurples = Purples;
17685 exports.schemePurples = scheme$24;
17686 exports.interpolateReds = Reds;
17687 exports.schemeReds = scheme$25;
17688 exports.interpolateOranges = Oranges;
17689 exports.schemeOranges = scheme$26;
17690 exports.interpolateCubehelixDefault = cubehelix$3;
17691 exports.interpolateRainbow = rainbow;
17692 exports.interpolateWarm = warm;
17693 exports.interpolateCool = cool;
17694 exports.interpolateSinebow = sinebow;
17695 exports.interpolateViridis = viridis;
17696 exports.interpolateMagma = magma;
17697 exports.interpolateInferno = inferno;
17698 exports.interpolatePlasma = plasma;
17699 exports.create = create;
17700 exports.creator = creator;
17701 exports.local = local;
17702 exports.matcher = matcher$1;
17703 exports.mouse = mouse;
17704 exports.namespace = namespace;
17705 exports.namespaces = namespaces;
17706 exports.clientPoint = point;
17707 exports.select = select;
17708 exports.selectAll = selectAll;
17709 exports.selection = selection;
17710 exports.selector = selector;
17711 exports.selectorAll = selectorAll;
17712 exports.style = styleValue;
17713 exports.touch = touch;
17714 exports.touches = touches;
17715 exports.window = defaultView;
17716 exports.customEvent = customEvent;
17717 exports.arc = arc;
17718 exports.area = area$3;
17719 exports.line = line;
17720 exports.pie = pie;
17721 exports.areaRadial = areaRadial;
17722 exports.radialArea = areaRadial;
17723 exports.lineRadial = lineRadial$1;
17724 exports.radialLine = lineRadial$1;
17725 exports.pointRadial = pointRadial;
17726 exports.linkHorizontal = linkHorizontal;
17727 exports.linkVertical = linkVertical;
17728 exports.linkRadial = linkRadial;
17729 exports.symbol = symbol;
17730 exports.symbols = symbols;
17731 exports.symbolCircle = circle$2;
17732 exports.symbolCross = cross$2;
17733 exports.symbolDiamond = diamond;
17734 exports.symbolSquare = square;
17735 exports.symbolStar = star;
17736 exports.symbolTriangle = triangle;
17737 exports.symbolWye = wye;
17738 exports.curveBasisClosed = basisClosed$1;
17739 exports.curveBasisOpen = basisOpen;
17740 exports.curveBasis = basis$2;
17741 exports.curveBundle = bundle;
17742 exports.curveCardinalClosed = cardinalClosed;
17743 exports.curveCardinalOpen = cardinalOpen;
17744 exports.curveCardinal = cardinal;
17745 exports.curveCatmullRomClosed = catmullRomClosed;
17746 exports.curveCatmullRomOpen = catmullRomOpen;
17747 exports.curveCatmullRom = catmullRom;
17748 exports.curveLinearClosed = linearClosed;
17749 exports.curveLinear = curveLinear;
17750 exports.curveMonotoneX = monotoneX;
17751 exports.curveMonotoneY = monotoneY;
17752 exports.curveNatural = natural;
17753 exports.curveStep = step;
17754 exports.curveStepAfter = stepAfter;
17755 exports.curveStepBefore = stepBefore;
17756 exports.stack = stack;
17757 exports.stackOffsetExpand = expand;
17758 exports.stackOffsetDiverging = diverging$1;
17759 exports.stackOffsetNone = none$1;
17760 exports.stackOffsetSilhouette = silhouette;
17761 exports.stackOffsetWiggle = wiggle;
17762 exports.stackOrderAscending = ascending$3;
17763 exports.stackOrderDescending = descending$2;
17764 exports.stackOrderInsideOut = insideOut;
17765 exports.stackOrderNone = none$2;
17766 exports.stackOrderReverse = reverse;
17767 exports.timeInterval = newInterval;
17768 exports.timeMillisecond = millisecond;
17769 exports.timeMilliseconds = milliseconds;
17770 exports.utcMillisecond = millisecond;
17771 exports.utcMilliseconds = milliseconds;
17772 exports.timeSecond = second;
17773 exports.timeSeconds = seconds;
17774 exports.utcSecond = second;
17775 exports.utcSeconds = seconds;
17776 exports.timeMinute = minute;
17777 exports.timeMinutes = minutes;
17778 exports.timeHour = hour;
17779 exports.timeHours = hours;
17780 exports.timeDay = day;
17781 exports.timeDays = days;
17782 exports.timeWeek = sunday;
17783 exports.timeWeeks = sundays;
17784 exports.timeSunday = sunday;
17785 exports.timeSundays = sundays;
17786 exports.timeMonday = monday;
17787 exports.timeMondays = mondays;
17788 exports.timeTuesday = tuesday;
17789 exports.timeTuesdays = tuesdays;
17790 exports.timeWednesday = wednesday;
17791 exports.timeWednesdays = wednesdays;
17792 exports.timeThursday = thursday;
17793 exports.timeThursdays = thursdays;
17794 exports.timeFriday = friday;
17795 exports.timeFridays = fridays;
17796 exports.timeSaturday = saturday;
17797 exports.timeSaturdays = saturdays;
17798 exports.timeMonth = month;
17799 exports.timeMonths = months;
17800 exports.timeYear = year;
17801 exports.timeYears = years;
17802 exports.utcMinute = utcMinute;
17803 exports.utcMinutes = utcMinutes;
17804 exports.utcHour = utcHour;
17805 exports.utcHours = utcHours;
17806 exports.utcDay = utcDay;
17807 exports.utcDays = utcDays;
17808 exports.utcWeek = utcSunday;
17809 exports.utcWeeks = utcSundays;
17810 exports.utcSunday = utcSunday;
17811 exports.utcSundays = utcSundays;
17812 exports.utcMonday = utcMonday;
17813 exports.utcMondays = utcMondays;
17814 exports.utcTuesday = utcTuesday;
17815 exports.utcTuesdays = utcTuesdays;
17816 exports.utcWednesday = utcWednesday;
17817 exports.utcWednesdays = utcWednesdays;
17818 exports.utcThursday = utcThursday;
17819 exports.utcThursdays = utcThursdays;
17820 exports.utcFriday = utcFriday;
17821 exports.utcFridays = utcFridays;
17822 exports.utcSaturday = utcSaturday;
17823 exports.utcSaturdays = utcSaturdays;
17824 exports.utcMonth = utcMonth;
17825 exports.utcMonths = utcMonths;
17826 exports.utcYear = utcYear;
17827 exports.utcYears = utcYears;
17828 exports.timeFormatDefaultLocale = defaultLocale$1;
17829 exports.timeFormatLocale = formatLocale$1;
17830 exports.isoFormat = formatIso;
17831 exports.isoParse = parseIso;
17832 exports.now = now;
17833 exports.timer = timer;
17834 exports.timerFlush = timerFlush;
17835 exports.timeout = timeout$1;
17836 exports.interval = interval$1;
17837 exports.transition = transition;
17838 exports.active = active;
17839 exports.interrupt = interrupt;
17840 exports.voronoi = voronoi;
17841 exports.zoom = zoom;
17842 exports.zoomTransform = transform$1;
17843 exports.zoomIdentity = identity$8;
17844
17845 Object.defineProperty(exports, '__esModule', { value: true });
17846
17847 })));