]> ToastFreeware Gitweb - chrisu/seepark.git/blob - web/static/d3.js
Copied .js und .css files from C3 project (https://github.com/c3js/c3) version 0...
[chrisu/seepark.git] / web / static / d3.js
1 // https://d3js.org Version 4.12.0. Copyright 2017 Mike Bostock.
2 (function (global, factory) {
3         typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4         typeof define === 'function' && define.amd ? define(['exports'], factory) :
5         (factory((global.d3 = global.d3 || {})));
6 }(this, (function (exports) { 'use strict';
7
8 var version = "4.12.0";
9
10 var ascending = function(a, b) {
11   return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
12 };
13
14 var bisector = function(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 var pairs = function(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 var cross = function(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 var descending = function(a, b) {
82   return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
83 };
84
85 var number = function(x) {
86   return x === null ? NaN : +x;
87 };
88
89 var variance = function(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 var deviation = function(array, f) {
122   var v = variance(array, f);
123   return v ? Math.sqrt(v) : v;
124 };
125
126 var extent = function(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 var constant = function(x) {
170   return function() {
171     return x;
172   };
173 };
174
175 var identity = function(x) {
176   return x;
177 };
178
179 var sequence = function(start, stop, step) {
180   start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
181
182   var i = -1,
183       n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
184       range = new Array(n);
185
186   while (++i < n) {
187     range[i] = start + i * step;
188   }
189
190   return range;
191 };
192
193 var e10 = Math.sqrt(50);
194 var e5 = Math.sqrt(10);
195 var e2 = Math.sqrt(2);
196
197 var ticks = function(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 var sturges = function(values) {
246   return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
247 };
248
249 var histogram = function() {
250   var value = identity,
251       domain = extent,
252       threshold = sturges;
253
254   function histogram(data) {
255     var i,
256         n = data.length,
257         x,
258         values = new Array(n);
259
260     for (i = 0; i < n; ++i) {
261       values[i] = value(data[i], i, data);
262     }
263
264     var xz = domain(values),
265         x0 = xz[0],
266         x1 = xz[1],
267         tz = threshold(values, x0, x1);
268
269     // Convert number of thresholds into uniform thresholds.
270     if (!Array.isArray(tz)) {
271       tz = tickStep(x0, x1, tz);
272       tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
273     }
274
275     // Remove any thresholds outside the domain.
276     var m = tz.length;
277     while (tz[0] <= x0) tz.shift(), --m;
278     while (tz[m - 1] > x1) tz.pop(), --m;
279
280     var bins = new Array(m + 1),
281         bin;
282
283     // Initialize bins.
284     for (i = 0; i <= m; ++i) {
285       bin = bins[i] = [];
286       bin.x0 = i > 0 ? tz[i - 1] : x0;
287       bin.x1 = i < m ? tz[i] : x1;
288     }
289
290     // Assign data to bins by value, ignoring any outside the domain.
291     for (i = 0; i < n; ++i) {
292       x = values[i];
293       if (x0 <= x && x <= x1) {
294         bins[bisectRight(tz, x, 0, m)].push(data[i]);
295       }
296     }
297
298     return bins;
299   }
300
301   histogram.value = function(_) {
302     return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
303   };
304
305   histogram.domain = function(_) {
306     return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
307   };
308
309   histogram.thresholds = function(_) {
310     return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
311   };
312
313   return histogram;
314 };
315
316 var threshold = function(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 var freedmanDiaconis = function(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 var scott = function(values, min, max) {
335   return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
336 };
337
338 var max = function(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 var mean = function(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 var median = function(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 var merge = function(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 var min = function(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 var permute = function(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 var scan = function(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 var shuffle = function(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 var sum = function(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 var transpose = function(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 var zip = function() {
555   return transpose(arguments);
556 };
557
558 var slice$1 = Array.prototype.slice;
559
560 var identity$1 = function(x) {
561   return x;
562 };
563
564 var top = 1;
565 var right = 2;
566 var bottom = 3;
567 var left = 4;
568 var epsilon = 1e-6;
569
570 function translateX(x) {
571   return "translate(" + (x + 0.5) + ",0)";
572 }
573
574 function translateY(y) {
575   return "translate(0," + (y + 0.5) + ")";
576 }
577
578 function number$1(scale) {
579   return function(d) {
580     return +scale(d);
581   };
582 }
583
584 function center(scale) {
585   var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
586   if (scale.round()) offset = Math.round(offset);
587   return function(d) {
588     return +scale(d) + offset;
589   };
590 }
591
592 function entering() {
593   return !this.__axis;
594 }
595
596 function axis(orient, scale) {
597   var tickArguments = [],
598       tickValues = null,
599       tickFormat = null,
600       tickSizeInner = 6,
601       tickSizeOuter = 6,
602       tickPadding = 3,
603       k = orient === top || orient === left ? -1 : 1,
604       x = orient === left || orient === right ? "x" : "y",
605       transform = orient === top || orient === bottom ? translateX : translateY;
606
607   function axis(context) {
608     var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
609         format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
610         spacing = Math.max(tickSizeInner, 0) + tickPadding,
611         range = scale.range(),
612         range0 = +range[0] + 0.5,
613         range1 = +range[range.length - 1] + 0.5,
614         position = (scale.bandwidth ? center : number$1)(scale.copy()),
615         selection = context.selection ? context.selection() : context,
616         path = selection.selectAll(".domain").data([null]),
617         tick = selection.selectAll(".tick").data(values, scale).order(),
618         tickExit = tick.exit(),
619         tickEnter = tick.enter().append("g").attr("class", "tick"),
620         line = tick.select("line"),
621         text = tick.select("text");
622
623     path = path.merge(path.enter().insert("path", ".tick")
624         .attr("class", "domain")
625         .attr("stroke", "#000"));
626
627     tick = tick.merge(tickEnter);
628
629     line = line.merge(tickEnter.append("line")
630         .attr("stroke", "#000")
631         .attr(x + "2", k * tickSizeInner));
632
633     text = text.merge(tickEnter.append("text")
634         .attr("fill", "#000")
635         .attr(x, k * spacing)
636         .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
637
638     if (context !== selection) {
639       path = path.transition(context);
640       tick = tick.transition(context);
641       line = line.transition(context);
642       text = text.transition(context);
643
644       tickExit = tickExit.transition(context)
645           .attr("opacity", epsilon)
646           .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
647
648       tickEnter
649           .attr("opacity", epsilon)
650           .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
651     }
652
653     tickExit.remove();
654
655     path
656         .attr("d", orient === left || orient == right
657             ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
658             : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
659
660     tick
661         .attr("opacity", 1)
662         .attr("transform", function(d) { return transform(position(d)); });
663
664     line
665         .attr(x + "2", k * tickSizeInner);
666
667     text
668         .attr(x, k * spacing)
669         .text(format);
670
671     selection.filter(entering)
672         .attr("fill", "none")
673         .attr("font-size", 10)
674         .attr("font-family", "sans-serif")
675         .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
676
677     selection
678         .each(function() { this.__axis = position; });
679   }
680
681   axis.scale = function(_) {
682     return arguments.length ? (scale = _, axis) : scale;
683   };
684
685   axis.ticks = function() {
686     return tickArguments = slice$1.call(arguments), axis;
687   };
688
689   axis.tickArguments = function(_) {
690     return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
691   };
692
693   axis.tickValues = function(_) {
694     return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
695   };
696
697   axis.tickFormat = function(_) {
698     return arguments.length ? (tickFormat = _, axis) : tickFormat;
699   };
700
701   axis.tickSize = function(_) {
702     return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
703   };
704
705   axis.tickSizeInner = function(_) {
706     return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
707   };
708
709   axis.tickSizeOuter = function(_) {
710     return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
711   };
712
713   axis.tickPadding = function(_) {
714     return arguments.length ? (tickPadding = +_, axis) : tickPadding;
715   };
716
717   return axis;
718 }
719
720 function axisTop(scale) {
721   return axis(top, scale);
722 }
723
724 function axisRight(scale) {
725   return axis(right, scale);
726 }
727
728 function axisBottom(scale) {
729   return axis(bottom, scale);
730 }
731
732 function axisLeft(scale) {
733   return axis(left, scale);
734 }
735
736 var noop = {value: function() {}};
737
738 function dispatch() {
739   for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
740     if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
741     _[t] = [];
742   }
743   return new Dispatch(_);
744 }
745
746 function Dispatch(_) {
747   this._ = _;
748 }
749
750 function parseTypenames(typenames, types) {
751   return typenames.trim().split(/^|\s+/).map(function(t) {
752     var name = "", i = t.indexOf(".");
753     if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
754     if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
755     return {type: t, name: name};
756   });
757 }
758
759 Dispatch.prototype = dispatch.prototype = {
760   constructor: Dispatch,
761   on: function(typename, callback) {
762     var _ = this._,
763         T = parseTypenames(typename + "", _),
764         t,
765         i = -1,
766         n = T.length;
767
768     // If no callback was specified, return the callback of the given type and name.
769     if (arguments.length < 2) {
770       while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
771       return;
772     }
773
774     // If a type was specified, set the callback for the given type and name.
775     // Otherwise, if a null callback was specified, remove callbacks of the given name.
776     if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
777     while (++i < n) {
778       if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
779       else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
780     }
781
782     return this;
783   },
784   copy: function() {
785     var copy = {}, _ = this._;
786     for (var t in _) copy[t] = _[t].slice();
787     return new Dispatch(copy);
788   },
789   call: function(type, that) {
790     if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
791     if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
792     for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
793   },
794   apply: function(type, that, args) {
795     if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
796     for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
797   }
798 };
799
800 function get(type, name) {
801   for (var i = 0, n = type.length, c; i < n; ++i) {
802     if ((c = type[i]).name === name) {
803       return c.value;
804     }
805   }
806 }
807
808 function set(type, name, callback) {
809   for (var i = 0, n = type.length; i < n; ++i) {
810     if (type[i].name === name) {
811       type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
812       break;
813     }
814   }
815   if (callback != null) type.push({name: name, value: callback});
816   return type;
817 }
818
819 var xhtml = "http://www.w3.org/1999/xhtml";
820
821 var namespaces = {
822   svg: "http://www.w3.org/2000/svg",
823   xhtml: xhtml,
824   xlink: "http://www.w3.org/1999/xlink",
825   xml: "http://www.w3.org/XML/1998/namespace",
826   xmlns: "http://www.w3.org/2000/xmlns/"
827 };
828
829 var namespace = function(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 var creator = function(name) {
852   var fullname = namespace(name);
853   return (fullname.local
854       ? creatorFixed
855       : creatorInherit)(fullname);
856 };
857
858 var nextId = 0;
859
860 function local$1() {
861   return new Local;
862 }
863
864 function Local() {
865   this._ = "@" + (++nextId).toString(36);
866 }
867
868 Local.prototype = local$1.prototype = {
869   constructor: Local,
870   get: function(node) {
871     var id = this._;
872     while (!(id in node)) if (!(node = node.parentNode)) return;
873     return node[id];
874   },
875   set: function(node, value) {
876     return node[this._] = value;
877   },
878   remove: function(node) {
879     return this._ in node && delete node[this._];
880   },
881   toString: function() {
882     return this._;
883   }
884 };
885
886 var matcher = function(selector) {
887   return function() {
888     return this.matches(selector);
889   };
890 };
891
892 if (typeof document !== "undefined") {
893   var element = document.documentElement;
894   if (!element.matches) {
895     var vendorMatches = element.webkitMatchesSelector
896         || element.msMatchesSelector
897         || element.mozMatchesSelector
898         || element.oMatchesSelector;
899     matcher = function(selector) {
900       return function() {
901         return vendorMatches.call(this, selector);
902       };
903     };
904   }
905 }
906
907 var matcher$1 = matcher;
908
909 var filterEvents = {};
910
911 exports.event = null;
912
913 if (typeof document !== "undefined") {
914   var element$1 = document.documentElement;
915   if (!("onmouseenter" in element$1)) {
916     filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
917   }
918 }
919
920 function filterContextListener(listener, index, group) {
921   listener = contextListener(listener, index, group);
922   return function(event) {
923     var related = event.relatedTarget;
924     if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
925       listener.call(this, event);
926     }
927   };
928 }
929
930 function contextListener(listener, index, group) {
931   return function(event1) {
932     var event0 = exports.event; // Events can be reentrant (e.g., focus).
933     exports.event = event1;
934     try {
935       listener.call(this, this.__data__, index, group);
936     } finally {
937       exports.event = event0;
938     }
939   };
940 }
941
942 function parseTypenames$1(typenames) {
943   return typenames.trim().split(/^|\s+/).map(function(t) {
944     var name = "", i = t.indexOf(".");
945     if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
946     return {type: t, name: name};
947   });
948 }
949
950 function onRemove(typename) {
951   return function() {
952     var on = this.__on;
953     if (!on) return;
954     for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
955       if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
956         this.removeEventListener(o.type, o.listener, o.capture);
957       } else {
958         on[++i] = o;
959       }
960     }
961     if (++i) on.length = i;
962     else delete this.__on;
963   };
964 }
965
966 function onAdd(typename, value, capture) {
967   var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
968   return function(d, i, group) {
969     var on = this.__on, o, listener = wrap(value, i, group);
970     if (on) for (var j = 0, m = on.length; j < m; ++j) {
971       if ((o = on[j]).type === typename.type && o.name === typename.name) {
972         this.removeEventListener(o.type, o.listener, o.capture);
973         this.addEventListener(o.type, o.listener = listener, o.capture = capture);
974         o.value = value;
975         return;
976       }
977     }
978     this.addEventListener(typename.type, listener, capture);
979     o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
980     if (!on) this.__on = [o];
981     else on.push(o);
982   };
983 }
984
985 var selection_on = function(typename, value, capture) {
986   var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
987
988   if (arguments.length < 2) {
989     var on = this.node().__on;
990     if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
991       for (i = 0, o = on[j]; i < n; ++i) {
992         if ((t = typenames[i]).type === o.type && t.name === o.name) {
993           return o.value;
994         }
995       }
996     }
997     return;
998   }
999
1000   on = value ? onAdd : onRemove;
1001   if (capture == null) capture = false;
1002   for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
1003   return this;
1004 };
1005
1006 function customEvent(event1, listener, that, args) {
1007   var event0 = exports.event;
1008   event1.sourceEvent = exports.event;
1009   exports.event = event1;
1010   try {
1011     return listener.apply(that, args);
1012   } finally {
1013     exports.event = event0;
1014   }
1015 }
1016
1017 var sourceEvent = function() {
1018   var current = exports.event, source;
1019   while (source = current.sourceEvent) current = source;
1020   return current;
1021 };
1022
1023 var point = function(node, event) {
1024   var svg = node.ownerSVGElement || node;
1025
1026   if (svg.createSVGPoint) {
1027     var point = svg.createSVGPoint();
1028     point.x = event.clientX, point.y = event.clientY;
1029     point = point.matrixTransform(node.getScreenCTM().inverse());
1030     return [point.x, point.y];
1031   }
1032
1033   var rect = node.getBoundingClientRect();
1034   return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
1035 };
1036
1037 var mouse = function(node) {
1038   var event = sourceEvent();
1039   if (event.changedTouches) event = event.changedTouches[0];
1040   return point(node, event);
1041 };
1042
1043 function none() {}
1044
1045 var selector = function(selector) {
1046   return selector == null ? none : function() {
1047     return this.querySelector(selector);
1048   };
1049 };
1050
1051 var selection_select = function(select) {
1052   if (typeof select !== "function") select = selector(select);
1053
1054   for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
1055     for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
1056       if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
1057         if ("__data__" in node) subnode.__data__ = node.__data__;
1058         subgroup[i] = subnode;
1059       }
1060     }
1061   }
1062
1063   return new Selection(subgroups, this._parents);
1064 };
1065
1066 function empty$1() {
1067   return [];
1068 }
1069
1070 var selectorAll = function(selector) {
1071   return selector == null ? empty$1 : function() {
1072     return this.querySelectorAll(selector);
1073   };
1074 };
1075
1076 var selection_selectAll = function(select) {
1077   if (typeof select !== "function") select = selectorAll(select);
1078
1079   for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
1080     for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
1081       if (node = group[i]) {
1082         subgroups.push(select.call(node, node.__data__, i, group));
1083         parents.push(node);
1084       }
1085     }
1086   }
1087
1088   return new Selection(subgroups, parents);
1089 };
1090
1091 var selection_filter = function(match) {
1092   if (typeof match !== "function") match = matcher$1(match);
1093
1094   for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
1095     for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
1096       if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
1097         subgroup.push(node);
1098       }
1099     }
1100   }
1101
1102   return new Selection(subgroups, this._parents);
1103 };
1104
1105 var sparse = function(update) {
1106   return new Array(update.length);
1107 };
1108
1109 var selection_enter = function() {
1110   return new Selection(this._enter || this._groups.map(sparse), this._parents);
1111 };
1112
1113 function EnterNode(parent, datum) {
1114   this.ownerDocument = parent.ownerDocument;
1115   this.namespaceURI = parent.namespaceURI;
1116   this._next = null;
1117   this._parent = parent;
1118   this.__data__ = datum;
1119 }
1120
1121 EnterNode.prototype = {
1122   constructor: EnterNode,
1123   appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
1124   insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
1125   querySelector: function(selector) { return this._parent.querySelector(selector); },
1126   querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
1127 };
1128
1129 var constant$1 = function(x) {
1130   return function() {
1131     return x;
1132   };
1133 };
1134
1135 var keyPrefix = "$"; // Protect against keys like “__proto__”.
1136
1137 function bindIndex(parent, group, enter, update, exit, data) {
1138   var i = 0,
1139       node,
1140       groupLength = group.length,
1141       dataLength = data.length;
1142
1143   // Put any non-null nodes that fit into update.
1144   // Put any null nodes into enter.
1145   // Put any remaining data into enter.
1146   for (; i < dataLength; ++i) {
1147     if (node = group[i]) {
1148       node.__data__ = data[i];
1149       update[i] = node;
1150     } else {
1151       enter[i] = new EnterNode(parent, data[i]);
1152     }
1153   }
1154
1155   // Put any non-null nodes that don’t fit into exit.
1156   for (; i < groupLength; ++i) {
1157     if (node = group[i]) {
1158       exit[i] = node;
1159     }
1160   }
1161 }
1162
1163 function bindKey(parent, group, enter, update, exit, data, key) {
1164   var i,
1165       node,
1166       nodeByKeyValue = {},
1167       groupLength = group.length,
1168       dataLength = data.length,
1169       keyValues = new Array(groupLength),
1170       keyValue;
1171
1172   // Compute the key for each node.
1173   // If multiple nodes have the same key, the duplicates are added to exit.
1174   for (i = 0; i < groupLength; ++i) {
1175     if (node = group[i]) {
1176       keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
1177       if (keyValue in nodeByKeyValue) {
1178         exit[i] = node;
1179       } else {
1180         nodeByKeyValue[keyValue] = node;
1181       }
1182     }
1183   }
1184
1185   // Compute the key for each datum.
1186   // If there a node associated with this key, join and add it to update.
1187   // If there is not (or the key is a duplicate), add it to enter.
1188   for (i = 0; i < dataLength; ++i) {
1189     keyValue = keyPrefix + key.call(parent, data[i], i, data);
1190     if (node = nodeByKeyValue[keyValue]) {
1191       update[i] = node;
1192       node.__data__ = data[i];
1193       nodeByKeyValue[keyValue] = null;
1194     } else {
1195       enter[i] = new EnterNode(parent, data[i]);
1196     }
1197   }
1198
1199   // Add any remaining nodes that were not bound to data to exit.
1200   for (i = 0; i < groupLength; ++i) {
1201     if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
1202       exit[i] = node;
1203     }
1204   }
1205 }
1206
1207 var selection_data = function(value, key) {
1208   if (!value) {
1209     data = new Array(this.size()), j = -1;
1210     this.each(function(d) { data[++j] = d; });
1211     return data;
1212   }
1213
1214   var bind = key ? bindKey : bindIndex,
1215       parents = this._parents,
1216       groups = this._groups;
1217
1218   if (typeof value !== "function") value = constant$1(value);
1219
1220   for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
1221     var parent = parents[j],
1222         group = groups[j],
1223         groupLength = group.length,
1224         data = value.call(parent, parent && parent.__data__, j, parents),
1225         dataLength = data.length,
1226         enterGroup = enter[j] = new Array(dataLength),
1227         updateGroup = update[j] = new Array(dataLength),
1228         exitGroup = exit[j] = new Array(groupLength);
1229
1230     bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
1231
1232     // Now connect the enter nodes to their following update node, such that
1233     // appendChild can insert the materialized enter node before this node,
1234     // rather than at the end of the parent node.
1235     for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
1236       if (previous = enterGroup[i0]) {
1237         if (i0 >= i1) i1 = i0 + 1;
1238         while (!(next = updateGroup[i1]) && ++i1 < dataLength);
1239         previous._next = next || null;
1240       }
1241     }
1242   }
1243
1244   update = new Selection(update, parents);
1245   update._enter = enter;
1246   update._exit = exit;
1247   return update;
1248 };
1249
1250 var selection_exit = function() {
1251   return new Selection(this._exit || this._groups.map(sparse), this._parents);
1252 };
1253
1254 var selection_merge = function(selection$$1) {
1255
1256   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) {
1257     for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
1258       if (node = group0[i] || group1[i]) {
1259         merge[i] = node;
1260       }
1261     }
1262   }
1263
1264   for (; j < m0; ++j) {
1265     merges[j] = groups0[j];
1266   }
1267
1268   return new Selection(merges, this._parents);
1269 };
1270
1271 var selection_order = function() {
1272
1273   for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
1274     for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
1275       if (node = group[i]) {
1276         if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
1277         next = node;
1278       }
1279     }
1280   }
1281
1282   return this;
1283 };
1284
1285 var selection_sort = function(compare) {
1286   if (!compare) compare = ascending$1;
1287
1288   function compareNode(a, b) {
1289     return a && b ? compare(a.__data__, b.__data__) : !a - !b;
1290   }
1291
1292   for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
1293     for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
1294       if (node = group[i]) {
1295         sortgroup[i] = node;
1296       }
1297     }
1298     sortgroup.sort(compareNode);
1299   }
1300
1301   return new Selection(sortgroups, this._parents).order();
1302 };
1303
1304 function ascending$1(a, b) {
1305   return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
1306 }
1307
1308 var selection_call = function() {
1309   var callback = arguments[0];
1310   arguments[0] = this;
1311   callback.apply(null, arguments);
1312   return this;
1313 };
1314
1315 var selection_nodes = function() {
1316   var nodes = new Array(this.size()), i = -1;
1317   this.each(function() { nodes[++i] = this; });
1318   return nodes;
1319 };
1320
1321 var selection_node = function() {
1322
1323   for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1324     for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
1325       var node = group[i];
1326       if (node) return node;
1327     }
1328   }
1329
1330   return null;
1331 };
1332
1333 var selection_size = function() {
1334   var size = 0;
1335   this.each(function() { ++size; });
1336   return size;
1337 };
1338
1339 var selection_empty = function() {
1340   return !this.node();
1341 };
1342
1343 var selection_each = function(callback) {
1344
1345   for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1346     for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
1347       if (node = group[i]) callback.call(node, node.__data__, i, group);
1348     }
1349   }
1350
1351   return this;
1352 };
1353
1354 function attrRemove(name) {
1355   return function() {
1356     this.removeAttribute(name);
1357   };
1358 }
1359
1360 function attrRemoveNS(fullname) {
1361   return function() {
1362     this.removeAttributeNS(fullname.space, fullname.local);
1363   };
1364 }
1365
1366 function attrConstant(name, value) {
1367   return function() {
1368     this.setAttribute(name, value);
1369   };
1370 }
1371
1372 function attrConstantNS(fullname, value) {
1373   return function() {
1374     this.setAttributeNS(fullname.space, fullname.local, value);
1375   };
1376 }
1377
1378 function attrFunction(name, value) {
1379   return function() {
1380     var v = value.apply(this, arguments);
1381     if (v == null) this.removeAttribute(name);
1382     else this.setAttribute(name, v);
1383   };
1384 }
1385
1386 function attrFunctionNS(fullname, value) {
1387   return function() {
1388     var v = value.apply(this, arguments);
1389     if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
1390     else this.setAttributeNS(fullname.space, fullname.local, v);
1391   };
1392 }
1393
1394 var selection_attr = function(name, value) {
1395   var fullname = namespace(name);
1396
1397   if (arguments.length < 2) {
1398     var node = this.node();
1399     return fullname.local
1400         ? node.getAttributeNS(fullname.space, fullname.local)
1401         : node.getAttribute(fullname);
1402   }
1403
1404   return this.each((value == null
1405       ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
1406       ? (fullname.local ? attrFunctionNS : attrFunction)
1407       : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
1408 };
1409
1410 var defaultView = function(node) {
1411   return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
1412       || (node.document && node) // node is a Window
1413       || node.defaultView; // node is a Document
1414 };
1415
1416 function styleRemove(name) {
1417   return function() {
1418     this.style.removeProperty(name);
1419   };
1420 }
1421
1422 function styleConstant(name, value, priority) {
1423   return function() {
1424     this.style.setProperty(name, value, priority);
1425   };
1426 }
1427
1428 function styleFunction(name, value, priority) {
1429   return function() {
1430     var v = value.apply(this, arguments);
1431     if (v == null) this.style.removeProperty(name);
1432     else this.style.setProperty(name, v, priority);
1433   };
1434 }
1435
1436 var selection_style = function(name, value, priority) {
1437   return arguments.length > 1
1438       ? this.each((value == null
1439             ? styleRemove : typeof value === "function"
1440             ? styleFunction
1441             : styleConstant)(name, value, priority == null ? "" : priority))
1442       : styleValue(this.node(), name);
1443 };
1444
1445 function styleValue(node, name) {
1446   return node.style.getPropertyValue(name)
1447       || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
1448 }
1449
1450 function propertyRemove(name) {
1451   return function() {
1452     delete this[name];
1453   };
1454 }
1455
1456 function propertyConstant(name, value) {
1457   return function() {
1458     this[name] = value;
1459   };
1460 }
1461
1462 function propertyFunction(name, value) {
1463   return function() {
1464     var v = value.apply(this, arguments);
1465     if (v == null) delete this[name];
1466     else this[name] = v;
1467   };
1468 }
1469
1470 var selection_property = function(name, value) {
1471   return arguments.length > 1
1472       ? this.each((value == null
1473           ? propertyRemove : typeof value === "function"
1474           ? propertyFunction
1475           : propertyConstant)(name, value))
1476       : this.node()[name];
1477 };
1478
1479 function classArray(string) {
1480   return string.trim().split(/^|\s+/);
1481 }
1482
1483 function classList(node) {
1484   return node.classList || new ClassList(node);
1485 }
1486
1487 function ClassList(node) {
1488   this._node = node;
1489   this._names = classArray(node.getAttribute("class") || "");
1490 }
1491
1492 ClassList.prototype = {
1493   add: function(name) {
1494     var i = this._names.indexOf(name);
1495     if (i < 0) {
1496       this._names.push(name);
1497       this._node.setAttribute("class", this._names.join(" "));
1498     }
1499   },
1500   remove: function(name) {
1501     var i = this._names.indexOf(name);
1502     if (i >= 0) {
1503       this._names.splice(i, 1);
1504       this._node.setAttribute("class", this._names.join(" "));
1505     }
1506   },
1507   contains: function(name) {
1508     return this._names.indexOf(name) >= 0;
1509   }
1510 };
1511
1512 function classedAdd(node, names) {
1513   var list = classList(node), i = -1, n = names.length;
1514   while (++i < n) list.add(names[i]);
1515 }
1516
1517 function classedRemove(node, names) {
1518   var list = classList(node), i = -1, n = names.length;
1519   while (++i < n) list.remove(names[i]);
1520 }
1521
1522 function classedTrue(names) {
1523   return function() {
1524     classedAdd(this, names);
1525   };
1526 }
1527
1528 function classedFalse(names) {
1529   return function() {
1530     classedRemove(this, names);
1531   };
1532 }
1533
1534 function classedFunction(names, value) {
1535   return function() {
1536     (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
1537   };
1538 }
1539
1540 var selection_classed = function(name, value) {
1541   var names = classArray(name + "");
1542
1543   if (arguments.length < 2) {
1544     var list = classList(this.node()), i = -1, n = names.length;
1545     while (++i < n) if (!list.contains(names[i])) return false;
1546     return true;
1547   }
1548
1549   return this.each((typeof value === "function"
1550       ? classedFunction : value
1551       ? classedTrue
1552       : classedFalse)(names, value));
1553 };
1554
1555 function textRemove() {
1556   this.textContent = "";
1557 }
1558
1559 function textConstant(value) {
1560   return function() {
1561     this.textContent = value;
1562   };
1563 }
1564
1565 function textFunction(value) {
1566   return function() {
1567     var v = value.apply(this, arguments);
1568     this.textContent = v == null ? "" : v;
1569   };
1570 }
1571
1572 var selection_text = function(value) {
1573   return arguments.length
1574       ? this.each(value == null
1575           ? textRemove : (typeof value === "function"
1576           ? textFunction
1577           : textConstant)(value))
1578       : this.node().textContent;
1579 };
1580
1581 function htmlRemove() {
1582   this.innerHTML = "";
1583 }
1584
1585 function htmlConstant(value) {
1586   return function() {
1587     this.innerHTML = value;
1588   };
1589 }
1590
1591 function htmlFunction(value) {
1592   return function() {
1593     var v = value.apply(this, arguments);
1594     this.innerHTML = v == null ? "" : v;
1595   };
1596 }
1597
1598 var selection_html = function(value) {
1599   return arguments.length
1600       ? this.each(value == null
1601           ? htmlRemove : (typeof value === "function"
1602           ? htmlFunction
1603           : htmlConstant)(value))
1604       : this.node().innerHTML;
1605 };
1606
1607 function raise() {
1608   if (this.nextSibling) this.parentNode.appendChild(this);
1609 }
1610
1611 var selection_raise = function() {
1612   return this.each(raise);
1613 };
1614
1615 function lower() {
1616   if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
1617 }
1618
1619 var selection_lower = function() {
1620   return this.each(lower);
1621 };
1622
1623 var selection_append = function(name) {
1624   var create = typeof name === "function" ? name : creator(name);
1625   return this.select(function() {
1626     return this.appendChild(create.apply(this, arguments));
1627   });
1628 };
1629
1630 function constantNull() {
1631   return null;
1632 }
1633
1634 var selection_insert = function(name, before) {
1635   var create = typeof name === "function" ? name : creator(name),
1636       select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
1637   return this.select(function() {
1638     return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
1639   });
1640 };
1641
1642 function remove() {
1643   var parent = this.parentNode;
1644   if (parent) parent.removeChild(this);
1645 }
1646
1647 var selection_remove = function() {
1648   return this.each(remove);
1649 };
1650
1651 var selection_datum = function(value) {
1652   return arguments.length
1653       ? this.property("__data__", value)
1654       : this.node().__data__;
1655 };
1656
1657 function dispatchEvent(node, type, params) {
1658   var window = defaultView(node),
1659       event = window.CustomEvent;
1660
1661   if (typeof event === "function") {
1662     event = new event(type, params);
1663   } else {
1664     event = window.document.createEvent("Event");
1665     if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
1666     else event.initEvent(type, false, false);
1667   }
1668
1669   node.dispatchEvent(event);
1670 }
1671
1672 function dispatchConstant(type, params) {
1673   return function() {
1674     return dispatchEvent(this, type, params);
1675   };
1676 }
1677
1678 function dispatchFunction(type, params) {
1679   return function() {
1680     return dispatchEvent(this, type, params.apply(this, arguments));
1681   };
1682 }
1683
1684 var selection_dispatch = function(type, params) {
1685   return this.each((typeof params === "function"
1686       ? dispatchFunction
1687       : dispatchConstant)(type, params));
1688 };
1689
1690 var root = [null];
1691
1692 function Selection(groups, parents) {
1693   this._groups = groups;
1694   this._parents = parents;
1695 }
1696
1697 function selection() {
1698   return new Selection([[document.documentElement]], root);
1699 }
1700
1701 Selection.prototype = selection.prototype = {
1702   constructor: Selection,
1703   select: selection_select,
1704   selectAll: selection_selectAll,
1705   filter: selection_filter,
1706   data: selection_data,
1707   enter: selection_enter,
1708   exit: selection_exit,
1709   merge: selection_merge,
1710   order: selection_order,
1711   sort: selection_sort,
1712   call: selection_call,
1713   nodes: selection_nodes,
1714   node: selection_node,
1715   size: selection_size,
1716   empty: selection_empty,
1717   each: selection_each,
1718   attr: selection_attr,
1719   style: selection_style,
1720   property: selection_property,
1721   classed: selection_classed,
1722   text: selection_text,
1723   html: selection_html,
1724   raise: selection_raise,
1725   lower: selection_lower,
1726   append: selection_append,
1727   insert: selection_insert,
1728   remove: selection_remove,
1729   datum: selection_datum,
1730   on: selection_on,
1731   dispatch: selection_dispatch
1732 };
1733
1734 var select = function(selector) {
1735   return typeof selector === "string"
1736       ? new Selection([[document.querySelector(selector)]], [document.documentElement])
1737       : new Selection([[selector]], root);
1738 };
1739
1740 var selectAll = function(selector) {
1741   return typeof selector === "string"
1742       ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
1743       : new Selection([selector == null ? [] : selector], root);
1744 };
1745
1746 var touch = function(node, touches, identifier) {
1747   if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
1748
1749   for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
1750     if ((touch = touches[i]).identifier === identifier) {
1751       return point(node, touch);
1752     }
1753   }
1754
1755   return null;
1756 };
1757
1758 var touches = function(node, touches) {
1759   if (touches == null) touches = sourceEvent().touches;
1760
1761   for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
1762     points[i] = point(node, touches[i]);
1763   }
1764
1765   return points;
1766 };
1767
1768 function nopropagation() {
1769   exports.event.stopImmediatePropagation();
1770 }
1771
1772 var noevent = function() {
1773   exports.event.preventDefault();
1774   exports.event.stopImmediatePropagation();
1775 };
1776
1777 var dragDisable = function(view) {
1778   var root = view.document.documentElement,
1779       selection = select(view).on("dragstart.drag", noevent, true);
1780   if ("onselectstart" in root) {
1781     selection.on("selectstart.drag", noevent, true);
1782   } else {
1783     root.__noselect = root.style.MozUserSelect;
1784     root.style.MozUserSelect = "none";
1785   }
1786 };
1787
1788 function yesdrag(view, noclick) {
1789   var root = view.document.documentElement,
1790       selection = select(view).on("dragstart.drag", null);
1791   if (noclick) {
1792     selection.on("click.drag", noevent, true);
1793     setTimeout(function() { selection.on("click.drag", null); }, 0);
1794   }
1795   if ("onselectstart" in root) {
1796     selection.on("selectstart.drag", null);
1797   } else {
1798     root.style.MozUserSelect = root.__noselect;
1799     delete root.__noselect;
1800   }
1801 }
1802
1803 var constant$2 = function(x) {
1804   return function() {
1805     return x;
1806   };
1807 };
1808
1809 function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
1810   this.target = target;
1811   this.type = type;
1812   this.subject = subject;
1813   this.identifier = id;
1814   this.active = active;
1815   this.x = x;
1816   this.y = y;
1817   this.dx = dx;
1818   this.dy = dy;
1819   this._ = dispatch;
1820 }
1821
1822 DragEvent.prototype.on = function() {
1823   var value = this._.on.apply(this._, arguments);
1824   return value === this._ ? this : value;
1825 };
1826
1827 // Ignore right-click, since that should open the context menu.
1828 function defaultFilter$1() {
1829   return !exports.event.button;
1830 }
1831
1832 function defaultContainer() {
1833   return this.parentNode;
1834 }
1835
1836 function defaultSubject(d) {
1837   return d == null ? {x: exports.event.x, y: exports.event.y} : d;
1838 }
1839
1840 function defaultTouchable() {
1841   return "ontouchstart" in this;
1842 }
1843
1844 var drag = function() {
1845   var filter = defaultFilter$1,
1846       container = defaultContainer,
1847       subject = defaultSubject,
1848       touchable = defaultTouchable,
1849       gestures = {},
1850       listeners = dispatch("start", "drag", "end"),
1851       active = 0,
1852       mousedownx,
1853       mousedowny,
1854       mousemoving,
1855       touchending,
1856       clickDistance2 = 0;
1857
1858   function drag(selection) {
1859     selection
1860         .on("mousedown.drag", mousedowned)
1861       .filter(touchable)
1862         .on("touchstart.drag", touchstarted)
1863         .on("touchmove.drag", touchmoved)
1864         .on("touchend.drag touchcancel.drag", touchended)
1865         .style("touch-action", "none")
1866         .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
1867   }
1868
1869   function mousedowned() {
1870     if (touchending || !filter.apply(this, arguments)) return;
1871     var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
1872     if (!gesture) return;
1873     select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
1874     dragDisable(exports.event.view);
1875     nopropagation();
1876     mousemoving = false;
1877     mousedownx = exports.event.clientX;
1878     mousedowny = exports.event.clientY;
1879     gesture("start");
1880   }
1881
1882   function mousemoved() {
1883     noevent();
1884     if (!mousemoving) {
1885       var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
1886       mousemoving = dx * dx + dy * dy > clickDistance2;
1887     }
1888     gestures.mouse("drag");
1889   }
1890
1891   function mouseupped() {
1892     select(exports.event.view).on("mousemove.drag mouseup.drag", null);
1893     yesdrag(exports.event.view, mousemoving);
1894     noevent();
1895     gestures.mouse("end");
1896   }
1897
1898   function touchstarted() {
1899     if (!filter.apply(this, arguments)) return;
1900     var touches = exports.event.changedTouches,
1901         c = container.apply(this, arguments),
1902         n = touches.length, i, gesture;
1903
1904     for (i = 0; i < n; ++i) {
1905       if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
1906         nopropagation();
1907         gesture("start");
1908       }
1909     }
1910   }
1911
1912   function touchmoved() {
1913     var touches = exports.event.changedTouches,
1914         n = touches.length, i, gesture;
1915
1916     for (i = 0; i < n; ++i) {
1917       if (gesture = gestures[touches[i].identifier]) {
1918         noevent();
1919         gesture("drag");
1920       }
1921     }
1922   }
1923
1924   function touchended() {
1925     var touches = exports.event.changedTouches,
1926         n = touches.length, i, gesture;
1927
1928     if (touchending) clearTimeout(touchending);
1929     touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
1930     for (i = 0; i < n; ++i) {
1931       if (gesture = gestures[touches[i].identifier]) {
1932         nopropagation();
1933         gesture("end");
1934       }
1935     }
1936   }
1937
1938   function beforestart(id, container, point, that, args) {
1939     var p = point(container, id), s, dx, dy,
1940         sublisteners = listeners.copy();
1941
1942     if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
1943       if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
1944       dx = s.x - p[0] || 0;
1945       dy = s.y - p[1] || 0;
1946       return true;
1947     })) return;
1948
1949     return function gesture(type) {
1950       var p0 = p, n;
1951       switch (type) {
1952         case "start": gestures[id] = gesture, n = active++; break;
1953         case "end": delete gestures[id], --active; // nobreak
1954         case "drag": p = point(container, id), n = active; break;
1955       }
1956       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]);
1957     };
1958   }
1959
1960   drag.filter = function(_) {
1961     return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
1962   };
1963
1964   drag.container = function(_) {
1965     return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
1966   };
1967
1968   drag.subject = function(_) {
1969     return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
1970   };
1971
1972   drag.touchable = function(_) {
1973     return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
1974   };
1975
1976   drag.on = function() {
1977     var value = listeners.on.apply(listeners, arguments);
1978     return value === listeners ? drag : value;
1979   };
1980
1981   drag.clickDistance = function(_) {
1982     return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
1983   };
1984
1985   return drag;
1986 };
1987
1988 var define = function(constructor, factory, prototype) {
1989   constructor.prototype = factory.prototype = prototype;
1990   prototype.constructor = constructor;
1991 };
1992
1993 function extend(parent, definition) {
1994   var prototype = Object.create(parent.prototype);
1995   for (var key in definition) prototype[key] = definition[key];
1996   return prototype;
1997 }
1998
1999 function Color() {}
2000
2001 var darker = 0.7;
2002 var brighter = 1 / darker;
2003
2004 var reI = "\\s*([+-]?\\d+)\\s*";
2005 var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
2006 var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
2007 var reHex3 = /^#([0-9a-f]{3})$/;
2008 var reHex6 = /^#([0-9a-f]{6})$/;
2009 var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
2010 var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
2011 var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
2012 var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
2013 var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
2014 var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
2015
2016 var named = {
2017   aliceblue: 0xf0f8ff,
2018   antiquewhite: 0xfaebd7,
2019   aqua: 0x00ffff,
2020   aquamarine: 0x7fffd4,
2021   azure: 0xf0ffff,
2022   beige: 0xf5f5dc,
2023   bisque: 0xffe4c4,
2024   black: 0x000000,
2025   blanchedalmond: 0xffebcd,
2026   blue: 0x0000ff,
2027   blueviolet: 0x8a2be2,
2028   brown: 0xa52a2a,
2029   burlywood: 0xdeb887,
2030   cadetblue: 0x5f9ea0,
2031   chartreuse: 0x7fff00,
2032   chocolate: 0xd2691e,
2033   coral: 0xff7f50,
2034   cornflowerblue: 0x6495ed,
2035   cornsilk: 0xfff8dc,
2036   crimson: 0xdc143c,
2037   cyan: 0x00ffff,
2038   darkblue: 0x00008b,
2039   darkcyan: 0x008b8b,
2040   darkgoldenrod: 0xb8860b,
2041   darkgray: 0xa9a9a9,
2042   darkgreen: 0x006400,
2043   darkgrey: 0xa9a9a9,
2044   darkkhaki: 0xbdb76b,
2045   darkmagenta: 0x8b008b,
2046   darkolivegreen: 0x556b2f,
2047   darkorange: 0xff8c00,
2048   darkorchid: 0x9932cc,
2049   darkred: 0x8b0000,
2050   darksalmon: 0xe9967a,
2051   darkseagreen: 0x8fbc8f,
2052   darkslateblue: 0x483d8b,
2053   darkslategray: 0x2f4f4f,
2054   darkslategrey: 0x2f4f4f,
2055   darkturquoise: 0x00ced1,
2056   darkviolet: 0x9400d3,
2057   deeppink: 0xff1493,
2058   deepskyblue: 0x00bfff,
2059   dimgray: 0x696969,
2060   dimgrey: 0x696969,
2061   dodgerblue: 0x1e90ff,
2062   firebrick: 0xb22222,
2063   floralwhite: 0xfffaf0,
2064   forestgreen: 0x228b22,
2065   fuchsia: 0xff00ff,
2066   gainsboro: 0xdcdcdc,
2067   ghostwhite: 0xf8f8ff,
2068   gold: 0xffd700,
2069   goldenrod: 0xdaa520,
2070   gray: 0x808080,
2071   green: 0x008000,
2072   greenyellow: 0xadff2f,
2073   grey: 0x808080,
2074   honeydew: 0xf0fff0,
2075   hotpink: 0xff69b4,
2076   indianred: 0xcd5c5c,
2077   indigo: 0x4b0082,
2078   ivory: 0xfffff0,
2079   khaki: 0xf0e68c,
2080   lavender: 0xe6e6fa,
2081   lavenderblush: 0xfff0f5,
2082   lawngreen: 0x7cfc00,
2083   lemonchiffon: 0xfffacd,
2084   lightblue: 0xadd8e6,
2085   lightcoral: 0xf08080,
2086   lightcyan: 0xe0ffff,
2087   lightgoldenrodyellow: 0xfafad2,
2088   lightgray: 0xd3d3d3,
2089   lightgreen: 0x90ee90,
2090   lightgrey: 0xd3d3d3,
2091   lightpink: 0xffb6c1,
2092   lightsalmon: 0xffa07a,
2093   lightseagreen: 0x20b2aa,
2094   lightskyblue: 0x87cefa,
2095   lightslategray: 0x778899,
2096   lightslategrey: 0x778899,
2097   lightsteelblue: 0xb0c4de,
2098   lightyellow: 0xffffe0,
2099   lime: 0x00ff00,
2100   limegreen: 0x32cd32,
2101   linen: 0xfaf0e6,
2102   magenta: 0xff00ff,
2103   maroon: 0x800000,
2104   mediumaquamarine: 0x66cdaa,
2105   mediumblue: 0x0000cd,
2106   mediumorchid: 0xba55d3,
2107   mediumpurple: 0x9370db,
2108   mediumseagreen: 0x3cb371,
2109   mediumslateblue: 0x7b68ee,
2110   mediumspringgreen: 0x00fa9a,
2111   mediumturquoise: 0x48d1cc,
2112   mediumvioletred: 0xc71585,
2113   midnightblue: 0x191970,
2114   mintcream: 0xf5fffa,
2115   mistyrose: 0xffe4e1,
2116   moccasin: 0xffe4b5,
2117   navajowhite: 0xffdead,
2118   navy: 0x000080,
2119   oldlace: 0xfdf5e6,
2120   olive: 0x808000,
2121   olivedrab: 0x6b8e23,
2122   orange: 0xffa500,
2123   orangered: 0xff4500,
2124   orchid: 0xda70d6,
2125   palegoldenrod: 0xeee8aa,
2126   palegreen: 0x98fb98,
2127   paleturquoise: 0xafeeee,
2128   palevioletred: 0xdb7093,
2129   papayawhip: 0xffefd5,
2130   peachpuff: 0xffdab9,
2131   peru: 0xcd853f,
2132   pink: 0xffc0cb,
2133   plum: 0xdda0dd,
2134   powderblue: 0xb0e0e6,
2135   purple: 0x800080,
2136   rebeccapurple: 0x663399,
2137   red: 0xff0000,
2138   rosybrown: 0xbc8f8f,
2139   royalblue: 0x4169e1,
2140   saddlebrown: 0x8b4513,
2141   salmon: 0xfa8072,
2142   sandybrown: 0xf4a460,
2143   seagreen: 0x2e8b57,
2144   seashell: 0xfff5ee,
2145   sienna: 0xa0522d,
2146   silver: 0xc0c0c0,
2147   skyblue: 0x87ceeb,
2148   slateblue: 0x6a5acd,
2149   slategray: 0x708090,
2150   slategrey: 0x708090,
2151   snow: 0xfffafa,
2152   springgreen: 0x00ff7f,
2153   steelblue: 0x4682b4,
2154   tan: 0xd2b48c,
2155   teal: 0x008080,
2156   thistle: 0xd8bfd8,
2157   tomato: 0xff6347,
2158   turquoise: 0x40e0d0,
2159   violet: 0xee82ee,
2160   wheat: 0xf5deb3,
2161   white: 0xffffff,
2162   whitesmoke: 0xf5f5f5,
2163   yellow: 0xffff00,
2164   yellowgreen: 0x9acd32
2165 };
2166
2167 define(Color, color, {
2168   displayable: function() {
2169     return this.rgb().displayable();
2170   },
2171   toString: function() {
2172     return this.rgb() + "";
2173   }
2174 });
2175
2176 function color(format) {
2177   var m;
2178   format = (format + "").trim().toLowerCase();
2179   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
2180       : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
2181       : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
2182       : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
2183       : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
2184       : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
2185       : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
2186       : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
2187       : named.hasOwnProperty(format) ? rgbn(named[format])
2188       : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
2189       : null;
2190 }
2191
2192 function rgbn(n) {
2193   return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
2194 }
2195
2196 function rgba(r, g, b, a) {
2197   if (a <= 0) r = g = b = NaN;
2198   return new Rgb(r, g, b, a);
2199 }
2200
2201 function rgbConvert(o) {
2202   if (!(o instanceof Color)) o = color(o);
2203   if (!o) return new Rgb;
2204   o = o.rgb();
2205   return new Rgb(o.r, o.g, o.b, o.opacity);
2206 }
2207
2208 function rgb(r, g, b, opacity) {
2209   return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
2210 }
2211
2212 function Rgb(r, g, b, opacity) {
2213   this.r = +r;
2214   this.g = +g;
2215   this.b = +b;
2216   this.opacity = +opacity;
2217 }
2218
2219 define(Rgb, rgb, extend(Color, {
2220   brighter: function(k) {
2221     k = k == null ? brighter : Math.pow(brighter, k);
2222     return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2223   },
2224   darker: function(k) {
2225     k = k == null ? darker : Math.pow(darker, k);
2226     return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2227   },
2228   rgb: function() {
2229     return this;
2230   },
2231   displayable: function() {
2232     return (0 <= this.r && this.r <= 255)
2233         && (0 <= this.g && this.g <= 255)
2234         && (0 <= this.b && this.b <= 255)
2235         && (0 <= this.opacity && this.opacity <= 1);
2236   },
2237   toString: function() {
2238     var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2239     return (a === 1 ? "rgb(" : "rgba(")
2240         + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
2241         + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
2242         + Math.max(0, Math.min(255, Math.round(this.b) || 0))
2243         + (a === 1 ? ")" : ", " + a + ")");
2244   }
2245 }));
2246
2247 function hsla(h, s, l, a) {
2248   if (a <= 0) h = s = l = NaN;
2249   else if (l <= 0 || l >= 1) h = s = NaN;
2250   else if (s <= 0) h = NaN;
2251   return new Hsl(h, s, l, a);
2252 }
2253
2254 function hslConvert(o) {
2255   if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2256   if (!(o instanceof Color)) o = color(o);
2257   if (!o) return new Hsl;
2258   if (o instanceof Hsl) return o;
2259   o = o.rgb();
2260   var r = o.r / 255,
2261       g = o.g / 255,
2262       b = o.b / 255,
2263       min = Math.min(r, g, b),
2264       max = Math.max(r, g, b),
2265       h = NaN,
2266       s = max - min,
2267       l = (max + min) / 2;
2268   if (s) {
2269     if (r === max) h = (g - b) / s + (g < b) * 6;
2270     else if (g === max) h = (b - r) / s + 2;
2271     else h = (r - g) / s + 4;
2272     s /= l < 0.5 ? max + min : 2 - max - min;
2273     h *= 60;
2274   } else {
2275     s = l > 0 && l < 1 ? 0 : h;
2276   }
2277   return new Hsl(h, s, l, o.opacity);
2278 }
2279
2280 function hsl(h, s, l, opacity) {
2281   return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2282 }
2283
2284 function Hsl(h, s, l, opacity) {
2285   this.h = +h;
2286   this.s = +s;
2287   this.l = +l;
2288   this.opacity = +opacity;
2289 }
2290
2291 define(Hsl, hsl, extend(Color, {
2292   brighter: function(k) {
2293     k = k == null ? brighter : Math.pow(brighter, k);
2294     return new Hsl(this.h, this.s, this.l * k, this.opacity);
2295   },
2296   darker: function(k) {
2297     k = k == null ? darker : Math.pow(darker, k);
2298     return new Hsl(this.h, this.s, this.l * k, this.opacity);
2299   },
2300   rgb: function() {
2301     var h = this.h % 360 + (this.h < 0) * 360,
2302         s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
2303         l = this.l,
2304         m2 = l + (l < 0.5 ? l : 1 - l) * s,
2305         m1 = 2 * l - m2;
2306     return new Rgb(
2307       hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
2308       hsl2rgb(h, m1, m2),
2309       hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
2310       this.opacity
2311     );
2312   },
2313   displayable: function() {
2314     return (0 <= this.s && this.s <= 1 || isNaN(this.s))
2315         && (0 <= this.l && this.l <= 1)
2316         && (0 <= this.opacity && this.opacity <= 1);
2317   }
2318 }));
2319
2320 /* From FvD 13.37, CSS Color Module Level 3 */
2321 function hsl2rgb(h, m1, m2) {
2322   return (h < 60 ? m1 + (m2 - m1) * h / 60
2323       : h < 180 ? m2
2324       : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
2325       : m1) * 255;
2326 }
2327
2328 var deg2rad = Math.PI / 180;
2329 var rad2deg = 180 / Math.PI;
2330
2331 var Kn = 18;
2332 var Xn = 0.950470;
2333 var Yn = 1;
2334 var Zn = 1.088830;
2335 var t0 = 4 / 29;
2336 var t1 = 6 / 29;
2337 var t2 = 3 * t1 * t1;
2338 var t3 = t1 * t1 * t1;
2339
2340 function labConvert(o) {
2341   if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
2342   if (o instanceof Hcl) {
2343     var h = o.h * deg2rad;
2344     return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
2345   }
2346   if (!(o instanceof Rgb)) o = rgbConvert(o);
2347   var b = rgb2xyz(o.r),
2348       a = rgb2xyz(o.g),
2349       l = rgb2xyz(o.b),
2350       x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
2351       y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
2352       z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
2353   return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
2354 }
2355
2356 function lab(l, a, b, opacity) {
2357   return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
2358 }
2359
2360 function Lab(l, a, b, opacity) {
2361   this.l = +l;
2362   this.a = +a;
2363   this.b = +b;
2364   this.opacity = +opacity;
2365 }
2366
2367 define(Lab, lab, extend(Color, {
2368   brighter: function(k) {
2369     return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
2370   },
2371   darker: function(k) {
2372     return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
2373   },
2374   rgb: function() {
2375     var y = (this.l + 16) / 116,
2376         x = isNaN(this.a) ? y : y + this.a / 500,
2377         z = isNaN(this.b) ? y : y - this.b / 200;
2378     y = Yn * lab2xyz(y);
2379     x = Xn * lab2xyz(x);
2380     z = Zn * lab2xyz(z);
2381     return new Rgb(
2382       xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
2383       xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
2384       xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
2385       this.opacity
2386     );
2387   }
2388 }));
2389
2390 function xyz2lab(t) {
2391   return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
2392 }
2393
2394 function lab2xyz(t) {
2395   return t > t1 ? t * t * t : t2 * (t - t0);
2396 }
2397
2398 function xyz2rgb(x) {
2399   return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
2400 }
2401
2402 function rgb2xyz(x) {
2403   return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
2404 }
2405
2406 function hclConvert(o) {
2407   if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
2408   if (!(o instanceof Lab)) o = labConvert(o);
2409   var h = Math.atan2(o.b, o.a) * rad2deg;
2410   return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
2411 }
2412
2413 function hcl(h, c, l, opacity) {
2414   return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2415 }
2416
2417 function Hcl(h, c, l, opacity) {
2418   this.h = +h;
2419   this.c = +c;
2420   this.l = +l;
2421   this.opacity = +opacity;
2422 }
2423
2424 define(Hcl, hcl, extend(Color, {
2425   brighter: function(k) {
2426     return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
2427   },
2428   darker: function(k) {
2429     return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
2430   },
2431   rgb: function() {
2432     return labConvert(this).rgb();
2433   }
2434 }));
2435
2436 var A = -0.14861;
2437 var B = +1.78277;
2438 var C = -0.29227;
2439 var D = -0.90649;
2440 var E = +1.97294;
2441 var ED = E * D;
2442 var EB = E * B;
2443 var BC_DA = B * C - D * A;
2444
2445 function cubehelixConvert(o) {
2446   if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
2447   if (!(o instanceof Rgb)) o = rgbConvert(o);
2448   var r = o.r / 255,
2449       g = o.g / 255,
2450       b = o.b / 255,
2451       l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
2452       bl = b - l,
2453       k = (E * (g - l) - C * bl) / D,
2454       s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
2455       h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
2456   return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
2457 }
2458
2459 function cubehelix(h, s, l, opacity) {
2460   return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
2461 }
2462
2463 function Cubehelix(h, s, l, opacity) {
2464   this.h = +h;
2465   this.s = +s;
2466   this.l = +l;
2467   this.opacity = +opacity;
2468 }
2469
2470 define(Cubehelix, cubehelix, extend(Color, {
2471   brighter: function(k) {
2472     k = k == null ? brighter : Math.pow(brighter, k);
2473     return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2474   },
2475   darker: function(k) {
2476     k = k == null ? darker : Math.pow(darker, k);
2477     return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2478   },
2479   rgb: function() {
2480     var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
2481         l = +this.l,
2482         a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
2483         cosh = Math.cos(h),
2484         sinh = Math.sin(h);
2485     return new Rgb(
2486       255 * (l + a * (A * cosh + B * sinh)),
2487       255 * (l + a * (C * cosh + D * sinh)),
2488       255 * (l + a * (E * cosh)),
2489       this.opacity
2490     );
2491   }
2492 }));
2493
2494 function basis(t1, v0, v1, v2, v3) {
2495   var t2 = t1 * t1, t3 = t2 * t1;
2496   return ((1 - 3 * t1 + 3 * t2 - t3) * v0
2497       + (4 - 6 * t2 + 3 * t3) * v1
2498       + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
2499       + t3 * v3) / 6;
2500 }
2501
2502 var basis$1 = function(values) {
2503   var n = values.length - 1;
2504   return function(t) {
2505     var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
2506         v1 = values[i],
2507         v2 = values[i + 1],
2508         v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
2509         v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
2510     return basis((t - i / n) * n, v0, v1, v2, v3);
2511   };
2512 };
2513
2514 var basisClosed = function(values) {
2515   var n = values.length;
2516   return function(t) {
2517     var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
2518         v0 = values[(i + n - 1) % n],
2519         v1 = values[i % n],
2520         v2 = values[(i + 1) % n],
2521         v3 = values[(i + 2) % n];
2522     return basis((t - i / n) * n, v0, v1, v2, v3);
2523   };
2524 };
2525
2526 var constant$3 = function(x) {
2527   return function() {
2528     return x;
2529   };
2530 };
2531
2532 function linear(a, d) {
2533   return function(t) {
2534     return a + t * d;
2535   };
2536 }
2537
2538 function exponential(a, b, y) {
2539   return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
2540     return Math.pow(a + t * b, y);
2541   };
2542 }
2543
2544 function hue(a, b) {
2545   var d = b - a;
2546   return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
2547 }
2548
2549 function gamma(y) {
2550   return (y = +y) === 1 ? nogamma : function(a, b) {
2551     return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
2552   };
2553 }
2554
2555 function nogamma(a, b) {
2556   var d = b - a;
2557   return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
2558 }
2559
2560 var interpolateRgb = (function rgbGamma(y) {
2561   var color$$1 = gamma(y);
2562
2563   function rgb$$1(start, end) {
2564     var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
2565         g = color$$1(start.g, end.g),
2566         b = color$$1(start.b, end.b),
2567         opacity = nogamma(start.opacity, end.opacity);
2568     return function(t) {
2569       start.r = r(t);
2570       start.g = g(t);
2571       start.b = b(t);
2572       start.opacity = opacity(t);
2573       return start + "";
2574     };
2575   }
2576
2577   rgb$$1.gamma = rgbGamma;
2578
2579   return rgb$$1;
2580 })(1);
2581
2582 function rgbSpline(spline) {
2583   return function(colors) {
2584     var n = colors.length,
2585         r = new Array(n),
2586         g = new Array(n),
2587         b = new Array(n),
2588         i, color$$1;
2589     for (i = 0; i < n; ++i) {
2590       color$$1 = rgb(colors[i]);
2591       r[i] = color$$1.r || 0;
2592       g[i] = color$$1.g || 0;
2593       b[i] = color$$1.b || 0;
2594     }
2595     r = spline(r);
2596     g = spline(g);
2597     b = spline(b);
2598     color$$1.opacity = 1;
2599     return function(t) {
2600       color$$1.r = r(t);
2601       color$$1.g = g(t);
2602       color$$1.b = b(t);
2603       return color$$1 + "";
2604     };
2605   };
2606 }
2607
2608 var rgbBasis = rgbSpline(basis$1);
2609 var rgbBasisClosed = rgbSpline(basisClosed);
2610
2611 var array$1 = function(a, b) {
2612   var nb = b ? b.length : 0,
2613       na = a ? Math.min(nb, a.length) : 0,
2614       x = new Array(na),
2615       c = new Array(nb),
2616       i;
2617
2618   for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
2619   for (; i < nb; ++i) c[i] = b[i];
2620
2621   return function(t) {
2622     for (i = 0; i < na; ++i) c[i] = x[i](t);
2623     return c;
2624   };
2625 };
2626
2627 var date = function(a, b) {
2628   var d = new Date;
2629   return a = +a, b -= a, function(t) {
2630     return d.setTime(a + b * t), d;
2631   };
2632 };
2633
2634 var reinterpolate = function(a, b) {
2635   return a = +a, b -= a, function(t) {
2636     return a + b * t;
2637   };
2638 };
2639
2640 var object = function(a, b) {
2641   var i = {},
2642       c = {},
2643       k;
2644
2645   if (a === null || typeof a !== "object") a = {};
2646   if (b === null || typeof b !== "object") b = {};
2647
2648   for (k in b) {
2649     if (k in a) {
2650       i[k] = interpolateValue(a[k], b[k]);
2651     } else {
2652       c[k] = b[k];
2653     }
2654   }
2655
2656   return function(t) {
2657     for (k in i) c[k] = i[k](t);
2658     return c;
2659   };
2660 };
2661
2662 var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
2663 var reB = new RegExp(reA.source, "g");
2664
2665 function zero(b) {
2666   return function() {
2667     return b;
2668   };
2669 }
2670
2671 function one(b) {
2672   return function(t) {
2673     return b(t) + "";
2674   };
2675 }
2676
2677 var interpolateString = function(a, b) {
2678   var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
2679       am, // current match in a
2680       bm, // current match in b
2681       bs, // string preceding current number in b, if any
2682       i = -1, // index in s
2683       s = [], // string constants and placeholders
2684       q = []; // number interpolators
2685
2686   // Coerce inputs to strings.
2687   a = a + "", b = b + "";
2688
2689   // Interpolate pairs of numbers in a & b.
2690   while ((am = reA.exec(a))
2691       && (bm = reB.exec(b))) {
2692     if ((bs = bm.index) > bi) { // a string precedes the next number in b
2693       bs = b.slice(bi, bs);
2694       if (s[i]) s[i] += bs; // coalesce with previous string
2695       else s[++i] = bs;
2696     }
2697     if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
2698       if (s[i]) s[i] += bm; // coalesce with previous string
2699       else s[++i] = bm;
2700     } else { // interpolate non-matching numbers
2701       s[++i] = null;
2702       q.push({i: i, x: reinterpolate(am, bm)});
2703     }
2704     bi = reB.lastIndex;
2705   }
2706
2707   // Add remains of b.
2708   if (bi < b.length) {
2709     bs = b.slice(bi);
2710     if (s[i]) s[i] += bs; // coalesce with previous string
2711     else s[++i] = bs;
2712   }
2713
2714   // Special optimization for only a single match.
2715   // Otherwise, interpolate each of the numbers and rejoin the string.
2716   return s.length < 2 ? (q[0]
2717       ? one(q[0].x)
2718       : zero(b))
2719       : (b = q.length, function(t) {
2720           for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
2721           return s.join("");
2722         });
2723 };
2724
2725 var interpolateValue = function(a, b) {
2726   var t = typeof b, c;
2727   return b == null || t === "boolean" ? constant$3(b)
2728       : (t === "number" ? reinterpolate
2729       : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
2730       : b instanceof color ? interpolateRgb
2731       : b instanceof Date ? date
2732       : Array.isArray(b) ? array$1
2733       : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
2734       : reinterpolate)(a, b);
2735 };
2736
2737 var interpolateRound = function(a, b) {
2738   return a = +a, b -= a, function(t) {
2739     return Math.round(a + b * t);
2740   };
2741 };
2742
2743 var degrees = 180 / Math.PI;
2744
2745 var identity$2 = {
2746   translateX: 0,
2747   translateY: 0,
2748   rotate: 0,
2749   skewX: 0,
2750   scaleX: 1,
2751   scaleY: 1
2752 };
2753
2754 var decompose = function(a, b, c, d, e, f) {
2755   var scaleX, scaleY, skewX;
2756   if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
2757   if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
2758   if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
2759   if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
2760   return {
2761     translateX: e,
2762     translateY: f,
2763     rotate: Math.atan2(b, a) * degrees,
2764     skewX: Math.atan(skewX) * degrees,
2765     scaleX: scaleX,
2766     scaleY: scaleY
2767   };
2768 };
2769
2770 var cssNode;
2771 var cssRoot;
2772 var cssView;
2773 var svgNode;
2774
2775 function parseCss(value) {
2776   if (value === "none") return identity$2;
2777   if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
2778   cssNode.style.transform = value;
2779   value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
2780   cssRoot.removeChild(cssNode);
2781   value = value.slice(7, -1).split(",");
2782   return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
2783 }
2784
2785 function parseSvg(value) {
2786   if (value == null) return identity$2;
2787   if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
2788   svgNode.setAttribute("transform", value);
2789   if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
2790   value = value.matrix;
2791   return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
2792 }
2793
2794 function interpolateTransform(parse, pxComma, pxParen, degParen) {
2795
2796   function pop(s) {
2797     return s.length ? s.pop() + " " : "";
2798   }
2799
2800   function translate(xa, ya, xb, yb, s, q) {
2801     if (xa !== xb || ya !== yb) {
2802       var i = s.push("translate(", null, pxComma, null, pxParen);
2803       q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2804     } else if (xb || yb) {
2805       s.push("translate(" + xb + pxComma + yb + pxParen);
2806     }
2807   }
2808
2809   function rotate(a, b, s, q) {
2810     if (a !== b) {
2811       if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
2812       q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: reinterpolate(a, b)});
2813     } else if (b) {
2814       s.push(pop(s) + "rotate(" + b + degParen);
2815     }
2816   }
2817
2818   function skewX(a, b, s, q) {
2819     if (a !== b) {
2820       q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: reinterpolate(a, b)});
2821     } else if (b) {
2822       s.push(pop(s) + "skewX(" + b + degParen);
2823     }
2824   }
2825
2826   function scale(xa, ya, xb, yb, s, q) {
2827     if (xa !== xb || ya !== yb) {
2828       var i = s.push(pop(s) + "scale(", null, ",", null, ")");
2829       q.push({i: i - 4, x: reinterpolate(xa, xb)}, {i: i - 2, x: reinterpolate(ya, yb)});
2830     } else if (xb !== 1 || yb !== 1) {
2831       s.push(pop(s) + "scale(" + xb + "," + yb + ")");
2832     }
2833   }
2834
2835   return function(a, b) {
2836     var s = [], // string constants and placeholders
2837         q = []; // number interpolators
2838     a = parse(a), b = parse(b);
2839     translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
2840     rotate(a.rotate, b.rotate, s, q);
2841     skewX(a.skewX, b.skewX, s, q);
2842     scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
2843     a = b = null; // gc
2844     return function(t) {
2845       var i = -1, n = q.length, o;
2846       while (++i < n) s[(o = q[i]).i] = o.x(t);
2847       return s.join("");
2848     };
2849   };
2850 }
2851
2852 var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
2853 var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
2854
2855 var rho = Math.SQRT2;
2856 var rho2 = 2;
2857 var rho4 = 4;
2858 var epsilon2 = 1e-12;
2859
2860 function cosh(x) {
2861   return ((x = Math.exp(x)) + 1 / x) / 2;
2862 }
2863
2864 function sinh(x) {
2865   return ((x = Math.exp(x)) - 1 / x) / 2;
2866 }
2867
2868 function tanh(x) {
2869   return ((x = Math.exp(2 * x)) - 1) / (x + 1);
2870 }
2871
2872 // p0 = [ux0, uy0, w0]
2873 // p1 = [ux1, uy1, w1]
2874 var interpolateZoom = function(p0, p1) {
2875   var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
2876       ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
2877       dx = ux1 - ux0,
2878       dy = uy1 - uy0,
2879       d2 = dx * dx + dy * dy,
2880       i,
2881       S;
2882
2883   // Special case for u0 ≅ u1.
2884   if (d2 < epsilon2) {
2885     S = Math.log(w1 / w0) / rho;
2886     i = function(t) {
2887       return [
2888         ux0 + t * dx,
2889         uy0 + t * dy,
2890         w0 * Math.exp(rho * t * S)
2891       ];
2892     };
2893   }
2894
2895   // General case.
2896   else {
2897     var d1 = Math.sqrt(d2),
2898         b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
2899         b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
2900         r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
2901         r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
2902     S = (r1 - r0) / rho;
2903     i = function(t) {
2904       var s = t * S,
2905           coshr0 = cosh(r0),
2906           u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
2907       return [
2908         ux0 + u * dx,
2909         uy0 + u * dy,
2910         w0 * coshr0 / cosh(rho * s + r0)
2911       ];
2912     };
2913   }
2914
2915   i.duration = S * 1000;
2916
2917   return i;
2918 };
2919
2920 function hsl$1(hue$$1) {
2921   return function(start, end) {
2922     var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
2923         s = nogamma(start.s, end.s),
2924         l = nogamma(start.l, end.l),
2925         opacity = nogamma(start.opacity, end.opacity);
2926     return function(t) {
2927       start.h = h(t);
2928       start.s = s(t);
2929       start.l = l(t);
2930       start.opacity = opacity(t);
2931       return start + "";
2932     };
2933   }
2934 }
2935
2936 var hsl$2 = hsl$1(hue);
2937 var hslLong = hsl$1(nogamma);
2938
2939 function lab$1(start, end) {
2940   var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
2941       a = nogamma(start.a, end.a),
2942       b = nogamma(start.b, end.b),
2943       opacity = nogamma(start.opacity, end.opacity);
2944   return function(t) {
2945     start.l = l(t);
2946     start.a = a(t);
2947     start.b = b(t);
2948     start.opacity = opacity(t);
2949     return start + "";
2950   };
2951 }
2952
2953 function hcl$1(hue$$1) {
2954   return function(start, end) {
2955     var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
2956         c = nogamma(start.c, end.c),
2957         l = nogamma(start.l, end.l),
2958         opacity = nogamma(start.opacity, end.opacity);
2959     return function(t) {
2960       start.h = h(t);
2961       start.c = c(t);
2962       start.l = l(t);
2963       start.opacity = opacity(t);
2964       return start + "";
2965     };
2966   }
2967 }
2968
2969 var hcl$2 = hcl$1(hue);
2970 var hclLong = hcl$1(nogamma);
2971
2972 function cubehelix$1(hue$$1) {
2973   return (function cubehelixGamma(y) {
2974     y = +y;
2975
2976     function cubehelix$$1(start, end) {
2977       var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
2978           s = nogamma(start.s, end.s),
2979           l = nogamma(start.l, end.l),
2980           opacity = nogamma(start.opacity, end.opacity);
2981       return function(t) {
2982         start.h = h(t);
2983         start.s = s(t);
2984         start.l = l(Math.pow(t, y));
2985         start.opacity = opacity(t);
2986         return start + "";
2987       };
2988     }
2989
2990     cubehelix$$1.gamma = cubehelixGamma;
2991
2992     return cubehelix$$1;
2993   })(1);
2994 }
2995
2996 var cubehelix$2 = cubehelix$1(hue);
2997 var cubehelixLong = cubehelix$1(nogamma);
2998
2999 var quantize = function(interpolator, n) {
3000   var samples = new Array(n);
3001   for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
3002   return samples;
3003 };
3004
3005 var frame = 0;
3006 var timeout = 0;
3007 var interval = 0;
3008 var pokeDelay = 1000;
3009 var taskHead;
3010 var taskTail;
3011 var clockLast = 0;
3012 var clockNow = 0;
3013 var clockSkew = 0;
3014 var clock = typeof performance === "object" && performance.now ? performance : Date;
3015 var setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
3016
3017 function now() {
3018   return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
3019 }
3020
3021 function clearNow() {
3022   clockNow = 0;
3023 }
3024
3025 function Timer() {
3026   this._call =
3027   this._time =
3028   this._next = null;
3029 }
3030
3031 Timer.prototype = timer.prototype = {
3032   constructor: Timer,
3033   restart: function(callback, delay, time) {
3034     if (typeof callback !== "function") throw new TypeError("callback is not a function");
3035     time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
3036     if (!this._next && taskTail !== this) {
3037       if (taskTail) taskTail._next = this;
3038       else taskHead = this;
3039       taskTail = this;
3040     }
3041     this._call = callback;
3042     this._time = time;
3043     sleep();
3044   },
3045   stop: function() {
3046     if (this._call) {
3047       this._call = null;
3048       this._time = Infinity;
3049       sleep();
3050     }
3051   }
3052 };
3053
3054 function timer(callback, delay, time) {
3055   var t = new Timer;
3056   t.restart(callback, delay, time);
3057   return t;
3058 }
3059
3060 function timerFlush() {
3061   now(); // Get the current time, if not already set.
3062   ++frame; // Pretend we’ve set an alarm, if we haven’t already.
3063   var t = taskHead, e;
3064   while (t) {
3065     if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
3066     t = t._next;
3067   }
3068   --frame;
3069 }
3070
3071 function wake() {
3072   clockNow = (clockLast = clock.now()) + clockSkew;
3073   frame = timeout = 0;
3074   try {
3075     timerFlush();
3076   } finally {
3077     frame = 0;
3078     nap();
3079     clockNow = 0;
3080   }
3081 }
3082
3083 function poke() {
3084   var now = clock.now(), delay = now - clockLast;
3085   if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
3086 }
3087
3088 function nap() {
3089   var t0, t1 = taskHead, t2, time = Infinity;
3090   while (t1) {
3091     if (t1._call) {
3092       if (time > t1._time) time = t1._time;
3093       t0 = t1, t1 = t1._next;
3094     } else {
3095       t2 = t1._next, t1._next = null;
3096       t1 = t0 ? t0._next = t2 : taskHead = t2;
3097     }
3098   }
3099   taskTail = t0;
3100   sleep(time);
3101 }
3102
3103 function sleep(time) {
3104   if (frame) return; // Soonest alarm already set, or will be.
3105   if (timeout) timeout = clearTimeout(timeout);
3106   var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
3107   if (delay > 24) {
3108     if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
3109     if (interval) interval = clearInterval(interval);
3110   } else {
3111     if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
3112     frame = 1, setFrame(wake);
3113   }
3114 }
3115
3116 var timeout$1 = function(callback, delay, time) {
3117   var t = new Timer;
3118   delay = delay == null ? 0 : +delay;
3119   t.restart(function(elapsed) {
3120     t.stop();
3121     callback(elapsed + delay);
3122   }, delay, time);
3123   return t;
3124 };
3125
3126 var interval$1 = function(callback, delay, time) {
3127   var t = new Timer, total = delay;
3128   if (delay == null) return t.restart(callback, delay, time), t;
3129   delay = +delay, time = time == null ? now() : +time;
3130   t.restart(function tick(elapsed) {
3131     elapsed += total;
3132     t.restart(tick, total += delay, time);
3133     callback(elapsed);
3134   }, delay, time);
3135   return t;
3136 };
3137
3138 var emptyOn = dispatch("start", "end", "interrupt");
3139 var emptyTween = [];
3140
3141 var CREATED = 0;
3142 var SCHEDULED = 1;
3143 var STARTING = 2;
3144 var STARTED = 3;
3145 var RUNNING = 4;
3146 var ENDING = 5;
3147 var ENDED = 6;
3148
3149 var schedule = function(node, name, id, index, group, timing) {
3150   var schedules = node.__transition;
3151   if (!schedules) node.__transition = {};
3152   else if (id in schedules) return;
3153   create(node, id, {
3154     name: name,
3155     index: index, // For context during callback.
3156     group: group, // For context during callback.
3157     on: emptyOn,
3158     tween: emptyTween,
3159     time: timing.time,
3160     delay: timing.delay,
3161     duration: timing.duration,
3162     ease: timing.ease,
3163     timer: null,
3164     state: CREATED
3165   });
3166 };
3167
3168 function init(node, id) {
3169   var schedule = get$1(node, id);
3170   if (schedule.state > CREATED) throw new Error("too late; already scheduled");
3171   return schedule;
3172 }
3173
3174 function set$1(node, id) {
3175   var schedule = get$1(node, id);
3176   if (schedule.state > STARTING) throw new Error("too late; already started");
3177   return schedule;
3178 }
3179
3180 function get$1(node, id) {
3181   var schedule = node.__transition;
3182   if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
3183   return schedule;
3184 }
3185
3186 function create(node, id, self) {
3187   var schedules = node.__transition,
3188       tween;
3189
3190   // Initialize the self timer when the transition is created.
3191   // Note the actual delay is not known until the first callback!
3192   schedules[id] = self;
3193   self.timer = timer(schedule, 0, self.time);
3194
3195   function schedule(elapsed) {
3196     self.state = SCHEDULED;
3197     self.timer.restart(start, self.delay, self.time);
3198
3199     // If the elapsed delay is less than our first sleep, start immediately.
3200     if (self.delay <= elapsed) start(elapsed - self.delay);
3201   }
3202
3203   function start(elapsed) {
3204     var i, j, n, o;
3205
3206     // If the state is not SCHEDULED, then we previously errored on start.
3207     if (self.state !== SCHEDULED) return stop();
3208
3209     for (i in schedules) {
3210       o = schedules[i];
3211       if (o.name !== self.name) continue;
3212
3213       // While this element already has a starting transition during this frame,
3214       // defer starting an interrupting transition until that transition has a
3215       // chance to tick (and possibly end); see d3/d3-transition#54!
3216       if (o.state === STARTED) return timeout$1(start);
3217
3218       // Interrupt the active transition, if any.
3219       // Dispatch the interrupt event.
3220       if (o.state === RUNNING) {
3221         o.state = ENDED;
3222         o.timer.stop();
3223         o.on.call("interrupt", node, node.__data__, o.index, o.group);
3224         delete schedules[i];
3225       }
3226
3227       // Cancel any pre-empted transitions. No interrupt event is dispatched
3228       // because the cancelled transitions never started. Note that this also
3229       // removes this transition from the pending list!
3230       else if (+i < id) {
3231         o.state = ENDED;
3232         o.timer.stop();
3233         delete schedules[i];
3234       }
3235     }
3236
3237     // Defer the first tick to end of the current frame; see d3/d3#1576.
3238     // Note the transition may be canceled after start and before the first tick!
3239     // Note this must be scheduled before the start event; see d3/d3-transition#16!
3240     // Assuming this is successful, subsequent callbacks go straight to tick.
3241     timeout$1(function() {
3242       if (self.state === STARTED) {
3243         self.state = RUNNING;
3244         self.timer.restart(tick, self.delay, self.time);
3245         tick(elapsed);
3246       }
3247     });
3248
3249     // Dispatch the start event.
3250     // Note this must be done before the tween are initialized.
3251     self.state = STARTING;
3252     self.on.call("start", node, node.__data__, self.index, self.group);
3253     if (self.state !== STARTING) return; // interrupted
3254     self.state = STARTED;
3255
3256     // Initialize the tween, deleting null tween.
3257     tween = new Array(n = self.tween.length);
3258     for (i = 0, j = -1; i < n; ++i) {
3259       if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
3260         tween[++j] = o;
3261       }
3262     }
3263     tween.length = j + 1;
3264   }
3265
3266   function tick(elapsed) {
3267     var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
3268         i = -1,
3269         n = tween.length;
3270
3271     while (++i < n) {
3272       tween[i].call(null, t);
3273     }
3274
3275     // Dispatch the end event.
3276     if (self.state === ENDING) {
3277       self.on.call("end", node, node.__data__, self.index, self.group);
3278       stop();
3279     }
3280   }
3281
3282   function stop() {
3283     self.state = ENDED;
3284     self.timer.stop();
3285     delete schedules[id];
3286     for (var i in schedules) return; // eslint-disable-line no-unused-vars
3287     delete node.__transition;
3288   }
3289 }
3290
3291 var interrupt = function(node, name) {
3292   var schedules = node.__transition,
3293       schedule$$1,
3294       active,
3295       empty = true,
3296       i;
3297
3298   if (!schedules) return;
3299
3300   name = name == null ? null : name + "";
3301
3302   for (i in schedules) {
3303     if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
3304     active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
3305     schedule$$1.state = ENDED;
3306     schedule$$1.timer.stop();
3307     if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
3308     delete schedules[i];
3309   }
3310
3311   if (empty) delete node.__transition;
3312 };
3313
3314 var selection_interrupt = function(name) {
3315   return this.each(function() {
3316     interrupt(this, name);
3317   });
3318 };
3319
3320 function tweenRemove(id, name) {
3321   var tween0, tween1;
3322   return function() {
3323     var schedule$$1 = set$1(this, id),
3324         tween = schedule$$1.tween;
3325
3326     // If this node shared tween with the previous node,
3327     // just assign the updated shared tween and we’re done!
3328     // Otherwise, copy-on-write.
3329     if (tween !== tween0) {
3330       tween1 = tween0 = tween;
3331       for (var i = 0, n = tween1.length; i < n; ++i) {
3332         if (tween1[i].name === name) {
3333           tween1 = tween1.slice();
3334           tween1.splice(i, 1);
3335           break;
3336         }
3337       }
3338     }
3339
3340     schedule$$1.tween = tween1;
3341   };
3342 }
3343
3344 function tweenFunction(id, name, value) {
3345   var tween0, tween1;
3346   if (typeof value !== "function") throw new Error;
3347   return function() {
3348     var schedule$$1 = set$1(this, id),
3349         tween = schedule$$1.tween;
3350
3351     // If this node shared tween with the previous node,
3352     // just assign the updated shared tween and we’re done!
3353     // Otherwise, copy-on-write.
3354     if (tween !== tween0) {
3355       tween1 = (tween0 = tween).slice();
3356       for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
3357         if (tween1[i].name === name) {
3358           tween1[i] = t;
3359           break;
3360         }
3361       }
3362       if (i === n) tween1.push(t);
3363     }
3364
3365     schedule$$1.tween = tween1;
3366   };
3367 }
3368
3369 var transition_tween = function(name, value) {
3370   var id = this._id;
3371
3372   name += "";
3373
3374   if (arguments.length < 2) {
3375     var tween = get$1(this.node(), id).tween;
3376     for (var i = 0, n = tween.length, t; i < n; ++i) {
3377       if ((t = tween[i]).name === name) {
3378         return t.value;
3379       }
3380     }
3381     return null;
3382   }
3383
3384   return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
3385 };
3386
3387 function tweenValue(transition, name, value) {
3388   var id = transition._id;
3389
3390   transition.each(function() {
3391     var schedule$$1 = set$1(this, id);
3392     (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
3393   });
3394
3395   return function(node) {
3396     return get$1(node, id).value[name];
3397   };
3398 }
3399
3400 var interpolate = function(a, b) {
3401   var c;
3402   return (typeof b === "number" ? reinterpolate
3403       : b instanceof color ? interpolateRgb
3404       : (c = color(b)) ? (b = c, interpolateRgb)
3405       : interpolateString)(a, b);
3406 };
3407
3408 function attrRemove$1(name) {
3409   return function() {
3410     this.removeAttribute(name);
3411   };
3412 }
3413
3414 function attrRemoveNS$1(fullname) {
3415   return function() {
3416     this.removeAttributeNS(fullname.space, fullname.local);
3417   };
3418 }
3419
3420 function attrConstant$1(name, interpolate$$1, value1) {
3421   var value00,
3422       interpolate0;
3423   return function() {
3424     var value0 = this.getAttribute(name);
3425     return value0 === value1 ? null
3426         : value0 === value00 ? interpolate0
3427         : interpolate0 = interpolate$$1(value00 = value0, value1);
3428   };
3429 }
3430
3431 function attrConstantNS$1(fullname, interpolate$$1, value1) {
3432   var value00,
3433       interpolate0;
3434   return function() {
3435     var value0 = this.getAttributeNS(fullname.space, fullname.local);
3436     return value0 === value1 ? null
3437         : value0 === value00 ? interpolate0
3438         : interpolate0 = interpolate$$1(value00 = value0, value1);
3439   };
3440 }
3441
3442 function attrFunction$1(name, interpolate$$1, value) {
3443   var value00,
3444       value10,
3445       interpolate0;
3446   return function() {
3447     var value0, value1 = value(this);
3448     if (value1 == null) return void this.removeAttribute(name);
3449     value0 = this.getAttribute(name);
3450     return value0 === value1 ? null
3451         : value0 === value00 && value1 === value10 ? interpolate0
3452         : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3453   };
3454 }
3455
3456 function attrFunctionNS$1(fullname, interpolate$$1, value) {
3457   var value00,
3458       value10,
3459       interpolate0;
3460   return function() {
3461     var value0, value1 = value(this);
3462     if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
3463     value0 = this.getAttributeNS(fullname.space, fullname.local);
3464     return value0 === value1 ? null
3465         : value0 === value00 && value1 === value10 ? interpolate0
3466         : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3467   };
3468 }
3469
3470 var transition_attr = function(name, value) {
3471   var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
3472   return this.attrTween(name, typeof value === "function"
3473       ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
3474       : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
3475       : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
3476 };
3477
3478 function attrTweenNS(fullname, value) {
3479   function tween() {
3480     var node = this, i = value.apply(node, arguments);
3481     return i && function(t) {
3482       node.setAttributeNS(fullname.space, fullname.local, i(t));
3483     };
3484   }
3485   tween._value = value;
3486   return tween;
3487 }
3488
3489 function attrTween(name, value) {
3490   function tween() {
3491     var node = this, i = value.apply(node, arguments);
3492     return i && function(t) {
3493       node.setAttribute(name, i(t));
3494     };
3495   }
3496   tween._value = value;
3497   return tween;
3498 }
3499
3500 var transition_attrTween = function(name, value) {
3501   var key = "attr." + name;
3502   if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3503   if (value == null) return this.tween(key, null);
3504   if (typeof value !== "function") throw new Error;
3505   var fullname = namespace(name);
3506   return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
3507 };
3508
3509 function delayFunction(id, value) {
3510   return function() {
3511     init(this, id).delay = +value.apply(this, arguments);
3512   };
3513 }
3514
3515 function delayConstant(id, value) {
3516   return value = +value, function() {
3517     init(this, id).delay = value;
3518   };
3519 }
3520
3521 var transition_delay = function(value) {
3522   var id = this._id;
3523
3524   return arguments.length
3525       ? this.each((typeof value === "function"
3526           ? delayFunction
3527           : delayConstant)(id, value))
3528       : get$1(this.node(), id).delay;
3529 };
3530
3531 function durationFunction(id, value) {
3532   return function() {
3533     set$1(this, id).duration = +value.apply(this, arguments);
3534   };
3535 }
3536
3537 function durationConstant(id, value) {
3538   return value = +value, function() {
3539     set$1(this, id).duration = value;
3540   };
3541 }
3542
3543 var transition_duration = function(value) {
3544   var id = this._id;
3545
3546   return arguments.length
3547       ? this.each((typeof value === "function"
3548           ? durationFunction
3549           : durationConstant)(id, value))
3550       : get$1(this.node(), id).duration;
3551 };
3552
3553 function easeConstant(id, value) {
3554   if (typeof value !== "function") throw new Error;
3555   return function() {
3556     set$1(this, id).ease = value;
3557   };
3558 }
3559
3560 var transition_ease = function(value) {
3561   var id = this._id;
3562
3563   return arguments.length
3564       ? this.each(easeConstant(id, value))
3565       : get$1(this.node(), id).ease;
3566 };
3567
3568 var transition_filter = function(match) {
3569   if (typeof match !== "function") match = matcher$1(match);
3570
3571   for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3572     for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
3573       if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
3574         subgroup.push(node);
3575       }
3576     }
3577   }
3578
3579   return new Transition(subgroups, this._parents, this._name, this._id);
3580 };
3581
3582 var transition_merge = function(transition$$1) {
3583   if (transition$$1._id !== this._id) throw new Error;
3584
3585   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) {
3586     for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
3587       if (node = group0[i] || group1[i]) {
3588         merge[i] = node;
3589       }
3590     }
3591   }
3592
3593   for (; j < m0; ++j) {
3594     merges[j] = groups0[j];
3595   }
3596
3597   return new Transition(merges, this._parents, this._name, this._id);
3598 };
3599
3600 function start(name) {
3601   return (name + "").trim().split(/^|\s+/).every(function(t) {
3602     var i = t.indexOf(".");
3603     if (i >= 0) t = t.slice(0, i);
3604     return !t || t === "start";
3605   });
3606 }
3607
3608 function onFunction(id, name, listener) {
3609   var on0, on1, sit = start(name) ? init : set$1;
3610   return function() {
3611     var schedule$$1 = sit(this, id),
3612         on = schedule$$1.on;
3613
3614     // If this node shared a dispatch with the previous node,
3615     // just assign the updated shared dispatch and we’re done!
3616     // Otherwise, copy-on-write.
3617     if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
3618
3619     schedule$$1.on = on1;
3620   };
3621 }
3622
3623 var transition_on = function(name, listener) {
3624   var id = this._id;
3625
3626   return arguments.length < 2
3627       ? get$1(this.node(), id).on.on(name)
3628       : this.each(onFunction(id, name, listener));
3629 };
3630
3631 function removeFunction(id) {
3632   return function() {
3633     var parent = this.parentNode;
3634     for (var i in this.__transition) if (+i !== id) return;
3635     if (parent) parent.removeChild(this);
3636   };
3637 }
3638
3639 var transition_remove = function() {
3640   return this.on("end.remove", removeFunction(this._id));
3641 };
3642
3643 var transition_select = function(select) {
3644   var name = this._name,
3645       id = this._id;
3646
3647   if (typeof select !== "function") select = selector(select);
3648
3649   for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3650     for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
3651       if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
3652         if ("__data__" in node) subnode.__data__ = node.__data__;
3653         subgroup[i] = subnode;
3654         schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
3655       }
3656     }
3657   }
3658
3659   return new Transition(subgroups, this._parents, name, id);
3660 };
3661
3662 var transition_selectAll = function(select) {
3663   var name = this._name,
3664       id = this._id;
3665
3666   if (typeof select !== "function") select = selectorAll(select);
3667
3668   for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
3669     for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3670       if (node = group[i]) {
3671         for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
3672           if (child = children[k]) {
3673             schedule(child, name, id, k, children, inherit);
3674           }
3675         }
3676         subgroups.push(children);
3677         parents.push(node);
3678       }
3679     }
3680   }
3681
3682   return new Transition(subgroups, parents, name, id);
3683 };
3684
3685 var Selection$1 = selection.prototype.constructor;
3686
3687 var transition_selection = function() {
3688   return new Selection$1(this._groups, this._parents);
3689 };
3690
3691 function styleRemove$1(name, interpolate$$1) {
3692   var value00,
3693       value10,
3694       interpolate0;
3695   return function() {
3696     var value0 = styleValue(this, name),
3697         value1 = (this.style.removeProperty(name), styleValue(this, name));
3698     return value0 === value1 ? null
3699         : value0 === value00 && value1 === value10 ? interpolate0
3700         : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3701   };
3702 }
3703
3704 function styleRemoveEnd(name) {
3705   return function() {
3706     this.style.removeProperty(name);
3707   };
3708 }
3709
3710 function styleConstant$1(name, interpolate$$1, value1) {
3711   var value00,
3712       interpolate0;
3713   return function() {
3714     var value0 = styleValue(this, name);
3715     return value0 === value1 ? null
3716         : value0 === value00 ? interpolate0
3717         : interpolate0 = interpolate$$1(value00 = value0, value1);
3718   };
3719 }
3720
3721 function styleFunction$1(name, interpolate$$1, value) {
3722   var value00,
3723       value10,
3724       interpolate0;
3725   return function() {
3726     var value0 = styleValue(this, name),
3727         value1 = value(this);
3728     if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
3729     return value0 === value1 ? null
3730         : value0 === value00 && value1 === value10 ? interpolate0
3731         : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3732   };
3733 }
3734
3735 var transition_style = function(name, value, priority) {
3736   var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
3737   return value == null ? this
3738           .styleTween(name, styleRemove$1(name, i))
3739           .on("end.style." + name, styleRemoveEnd(name))
3740       : this.styleTween(name, typeof value === "function"
3741           ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
3742           : styleConstant$1(name, i, value + ""), priority);
3743 };
3744
3745 function styleTween(name, value, priority) {
3746   function tween() {
3747     var node = this, i = value.apply(node, arguments);
3748     return i && function(t) {
3749       node.style.setProperty(name, i(t), priority);
3750     };
3751   }
3752   tween._value = value;
3753   return tween;
3754 }
3755
3756 var transition_styleTween = function(name, value, priority) {
3757   var key = "style." + (name += "");
3758   if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3759   if (value == null) return this.tween(key, null);
3760   if (typeof value !== "function") throw new Error;
3761   return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
3762 };
3763
3764 function textConstant$1(value) {
3765   return function() {
3766     this.textContent = value;
3767   };
3768 }
3769
3770 function textFunction$1(value) {
3771   return function() {
3772     var value1 = value(this);
3773     this.textContent = value1 == null ? "" : value1;
3774   };
3775 }
3776
3777 var transition_text = function(value) {
3778   return this.tween("text", typeof value === "function"
3779       ? textFunction$1(tweenValue(this, "text", value))
3780       : textConstant$1(value == null ? "" : value + ""));
3781 };
3782
3783 var transition_transition = function() {
3784   var name = this._name,
3785       id0 = this._id,
3786       id1 = newId();
3787
3788   for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
3789     for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3790       if (node = group[i]) {
3791         var inherit = get$1(node, id0);
3792         schedule(node, name, id1, i, group, {
3793           time: inherit.time + inherit.delay + inherit.duration,
3794           delay: 0,
3795           duration: inherit.duration,
3796           ease: inherit.ease
3797         });
3798       }
3799     }
3800   }
3801
3802   return new Transition(groups, this._parents, name, id1);
3803 };
3804
3805 var id = 0;
3806
3807 function Transition(groups, parents, name, id) {
3808   this._groups = groups;
3809   this._parents = parents;
3810   this._name = name;
3811   this._id = id;
3812 }
3813
3814 function transition(name) {
3815   return selection().transition(name);
3816 }
3817
3818 function newId() {
3819   return ++id;
3820 }
3821
3822 var selection_prototype = selection.prototype;
3823
3824 Transition.prototype = transition.prototype = {
3825   constructor: Transition,
3826   select: transition_select,
3827   selectAll: transition_selectAll,
3828   filter: transition_filter,
3829   merge: transition_merge,
3830   selection: transition_selection,
3831   transition: transition_transition,
3832   call: selection_prototype.call,
3833   nodes: selection_prototype.nodes,
3834   node: selection_prototype.node,
3835   size: selection_prototype.size,
3836   empty: selection_prototype.empty,
3837   each: selection_prototype.each,
3838   on: transition_on,
3839   attr: transition_attr,
3840   attrTween: transition_attrTween,
3841   style: transition_style,
3842   styleTween: transition_styleTween,
3843   text: transition_text,
3844   remove: transition_remove,
3845   tween: transition_tween,
3846   delay: transition_delay,
3847   duration: transition_duration,
3848   ease: transition_ease
3849 };
3850
3851 function linear$1(t) {
3852   return +t;
3853 }
3854
3855 function quadIn(t) {
3856   return t * t;
3857 }
3858
3859 function quadOut(t) {
3860   return t * (2 - t);
3861 }
3862
3863 function quadInOut(t) {
3864   return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
3865 }
3866
3867 function cubicIn(t) {
3868   return t * t * t;
3869 }
3870
3871 function cubicOut(t) {
3872   return --t * t * t + 1;
3873 }
3874
3875 function cubicInOut(t) {
3876   return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
3877 }
3878
3879 var exponent = 3;
3880
3881 var polyIn = (function custom(e) {
3882   e = +e;
3883
3884   function polyIn(t) {
3885     return Math.pow(t, e);
3886   }
3887
3888   polyIn.exponent = custom;
3889
3890   return polyIn;
3891 })(exponent);
3892
3893 var polyOut = (function custom(e) {
3894   e = +e;
3895
3896   function polyOut(t) {
3897     return 1 - Math.pow(1 - t, e);
3898   }
3899
3900   polyOut.exponent = custom;
3901
3902   return polyOut;
3903 })(exponent);
3904
3905 var polyInOut = (function custom(e) {
3906   e = +e;
3907
3908   function polyInOut(t) {
3909     return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
3910   }
3911
3912   polyInOut.exponent = custom;
3913
3914   return polyInOut;
3915 })(exponent);
3916
3917 var pi = Math.PI;
3918 var halfPi = pi / 2;
3919
3920 function sinIn(t) {
3921   return 1 - Math.cos(t * halfPi);
3922 }
3923
3924 function sinOut(t) {
3925   return Math.sin(t * halfPi);
3926 }
3927
3928 function sinInOut(t) {
3929   return (1 - Math.cos(pi * t)) / 2;
3930 }
3931
3932 function expIn(t) {
3933   return Math.pow(2, 10 * t - 10);
3934 }
3935
3936 function expOut(t) {
3937   return 1 - Math.pow(2, -10 * t);
3938 }
3939
3940 function expInOut(t) {
3941   return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
3942 }
3943
3944 function circleIn(t) {
3945   return 1 - Math.sqrt(1 - t * t);
3946 }
3947
3948 function circleOut(t) {
3949   return Math.sqrt(1 - --t * t);
3950 }
3951
3952 function circleInOut(t) {
3953   return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
3954 }
3955
3956 var b1 = 4 / 11;
3957 var b2 = 6 / 11;
3958 var b3 = 8 / 11;
3959 var b4 = 3 / 4;
3960 var b5 = 9 / 11;
3961 var b6 = 10 / 11;
3962 var b7 = 15 / 16;
3963 var b8 = 21 / 22;
3964 var b9 = 63 / 64;
3965 var b0 = 1 / b1 / b1;
3966
3967 function bounceIn(t) {
3968   return 1 - bounceOut(1 - t);
3969 }
3970
3971 function bounceOut(t) {
3972   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;
3973 }
3974
3975 function bounceInOut(t) {
3976   return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
3977 }
3978
3979 var overshoot = 1.70158;
3980
3981 var backIn = (function custom(s) {
3982   s = +s;
3983
3984   function backIn(t) {
3985     return t * t * ((s + 1) * t - s);
3986   }
3987
3988   backIn.overshoot = custom;
3989
3990   return backIn;
3991 })(overshoot);
3992
3993 var backOut = (function custom(s) {
3994   s = +s;
3995
3996   function backOut(t) {
3997     return --t * t * ((s + 1) * t + s) + 1;
3998   }
3999
4000   backOut.overshoot = custom;
4001
4002   return backOut;
4003 })(overshoot);
4004
4005 var backInOut = (function custom(s) {
4006   s = +s;
4007
4008   function backInOut(t) {
4009     return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
4010   }
4011
4012   backInOut.overshoot = custom;
4013
4014   return backInOut;
4015 })(overshoot);
4016
4017 var tau = 2 * Math.PI;
4018 var amplitude = 1;
4019 var period = 0.3;
4020
4021 var elasticIn = (function custom(a, p) {
4022   var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4023
4024   function elasticIn(t) {
4025     return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
4026   }
4027
4028   elasticIn.amplitude = function(a) { return custom(a, p * tau); };
4029   elasticIn.period = function(p) { return custom(a, p); };
4030
4031   return elasticIn;
4032 })(amplitude, period);
4033
4034 var elasticOut = (function custom(a, p) {
4035   var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4036
4037   function elasticOut(t) {
4038     return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
4039   }
4040
4041   elasticOut.amplitude = function(a) { return custom(a, p * tau); };
4042   elasticOut.period = function(p) { return custom(a, p); };
4043
4044   return elasticOut;
4045 })(amplitude, period);
4046
4047 var elasticInOut = (function custom(a, p) {
4048   var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4049
4050   function elasticInOut(t) {
4051     return ((t = t * 2 - 1) < 0
4052         ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
4053         : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
4054   }
4055
4056   elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
4057   elasticInOut.period = function(p) { return custom(a, p); };
4058
4059   return elasticInOut;
4060 })(amplitude, period);
4061
4062 var defaultTiming = {
4063   time: null, // Set on use.
4064   delay: 0,
4065   duration: 250,
4066   ease: cubicInOut
4067 };
4068
4069 function inherit(node, id) {
4070   var timing;
4071   while (!(timing = node.__transition) || !(timing = timing[id])) {
4072     if (!(node = node.parentNode)) {
4073       return defaultTiming.time = now(), defaultTiming;
4074     }
4075   }
4076   return timing;
4077 }
4078
4079 var selection_transition = function(name) {
4080   var id,
4081       timing;
4082
4083   if (name instanceof Transition) {
4084     id = name._id, name = name._name;
4085   } else {
4086     id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
4087   }
4088
4089   for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4090     for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4091       if (node = group[i]) {
4092         schedule(node, name, id, i, group, timing || inherit(node, id));
4093       }
4094     }
4095   }
4096
4097   return new Transition(groups, this._parents, name, id);
4098 };
4099
4100 selection.prototype.interrupt = selection_interrupt;
4101 selection.prototype.transition = selection_transition;
4102
4103 var root$1 = [null];
4104
4105 var active = function(node, name) {
4106   var schedules = node.__transition,
4107       schedule$$1,
4108       i;
4109
4110   if (schedules) {
4111     name = name == null ? null : name + "";
4112     for (i in schedules) {
4113       if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
4114         return new Transition([[node]], root$1, name, +i);
4115       }
4116     }
4117   }
4118
4119   return null;
4120 };
4121
4122 var constant$4 = function(x) {
4123   return function() {
4124     return x;
4125   };
4126 };
4127
4128 var BrushEvent = function(target, type, selection) {
4129   this.target = target;
4130   this.type = type;
4131   this.selection = selection;
4132 };
4133
4134 function nopropagation$1() {
4135   exports.event.stopImmediatePropagation();
4136 }
4137
4138 var noevent$1 = function() {
4139   exports.event.preventDefault();
4140   exports.event.stopImmediatePropagation();
4141 };
4142
4143 var MODE_DRAG = {name: "drag"};
4144 var MODE_SPACE = {name: "space"};
4145 var MODE_HANDLE = {name: "handle"};
4146 var MODE_CENTER = {name: "center"};
4147
4148 var X = {
4149   name: "x",
4150   handles: ["e", "w"].map(type),
4151   input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
4152   output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
4153 };
4154
4155 var Y = {
4156   name: "y",
4157   handles: ["n", "s"].map(type),
4158   input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
4159   output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
4160 };
4161
4162 var XY = {
4163   name: "xy",
4164   handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
4165   input: function(xy) { return xy; },
4166   output: function(xy) { return xy; }
4167 };
4168
4169 var cursors = {
4170   overlay: "crosshair",
4171   selection: "move",
4172   n: "ns-resize",
4173   e: "ew-resize",
4174   s: "ns-resize",
4175   w: "ew-resize",
4176   nw: "nwse-resize",
4177   ne: "nesw-resize",
4178   se: "nwse-resize",
4179   sw: "nesw-resize"
4180 };
4181
4182 var flipX = {
4183   e: "w",
4184   w: "e",
4185   nw: "ne",
4186   ne: "nw",
4187   se: "sw",
4188   sw: "se"
4189 };
4190
4191 var flipY = {
4192   n: "s",
4193   s: "n",
4194   nw: "sw",
4195   ne: "se",
4196   se: "ne",
4197   sw: "nw"
4198 };
4199
4200 var signsX = {
4201   overlay: +1,
4202   selection: +1,
4203   n: null,
4204   e: +1,
4205   s: null,
4206   w: -1,
4207   nw: -1,
4208   ne: +1,
4209   se: +1,
4210   sw: -1
4211 };
4212
4213 var signsY = {
4214   overlay: +1,
4215   selection: +1,
4216   n: -1,
4217   e: null,
4218   s: +1,
4219   w: null,
4220   nw: -1,
4221   ne: -1,
4222   se: +1,
4223   sw: +1
4224 };
4225
4226 function type(t) {
4227   return {type: t};
4228 }
4229
4230 // Ignore right-click, since that should open the context menu.
4231 function defaultFilter() {
4232   return !exports.event.button;
4233 }
4234
4235 function defaultExtent() {
4236   var svg = this.ownerSVGElement || this;
4237   return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
4238 }
4239
4240 // Like d3.local, but with the name “__brush” rather than auto-generated.
4241 function local(node) {
4242   while (!node.__brush) if (!(node = node.parentNode)) return;
4243   return node.__brush;
4244 }
4245
4246 function empty(extent) {
4247   return extent[0][0] === extent[1][0]
4248       || extent[0][1] === extent[1][1];
4249 }
4250
4251 function brushSelection(node) {
4252   var state = node.__brush;
4253   return state ? state.dim.output(state.selection) : null;
4254 }
4255
4256 function brushX() {
4257   return brush$1(X);
4258 }
4259
4260 function brushY() {
4261   return brush$1(Y);
4262 }
4263
4264 var brush = function() {
4265   return brush$1(XY);
4266 };
4267
4268 function brush$1(dim) {
4269   var extent = defaultExtent,
4270       filter = defaultFilter,
4271       listeners = dispatch(brush, "start", "brush", "end"),
4272       handleSize = 6,
4273       touchending;
4274
4275   function brush(group) {
4276     var overlay = group
4277         .property("__brush", initialize)
4278       .selectAll(".overlay")
4279       .data([type("overlay")]);
4280
4281     overlay.enter().append("rect")
4282         .attr("class", "overlay")
4283         .attr("pointer-events", "all")
4284         .attr("cursor", cursors.overlay)
4285       .merge(overlay)
4286         .each(function() {
4287           var extent = local(this).extent;
4288           select(this)
4289               .attr("x", extent[0][0])
4290               .attr("y", extent[0][1])
4291               .attr("width", extent[1][0] - extent[0][0])
4292               .attr("height", extent[1][1] - extent[0][1]);
4293         });
4294
4295     group.selectAll(".selection")
4296       .data([type("selection")])
4297       .enter().append("rect")
4298         .attr("class", "selection")
4299         .attr("cursor", cursors.selection)
4300         .attr("fill", "#777")
4301         .attr("fill-opacity", 0.3)
4302         .attr("stroke", "#fff")
4303         .attr("shape-rendering", "crispEdges");
4304
4305     var handle = group.selectAll(".handle")
4306       .data(dim.handles, function(d) { return d.type; });
4307
4308     handle.exit().remove();
4309
4310     handle.enter().append("rect")
4311         .attr("class", function(d) { return "handle handle--" + d.type; })
4312         .attr("cursor", function(d) { return cursors[d.type]; });
4313
4314     group
4315         .each(redraw)
4316         .attr("fill", "none")
4317         .attr("pointer-events", "all")
4318         .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
4319         .on("mousedown.brush touchstart.brush", started);
4320   }
4321
4322   brush.move = function(group, selection) {
4323     if (group.selection) {
4324       group
4325           .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
4326           .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
4327           .tween("brush", function() {
4328             var that = this,
4329                 state = that.__brush,
4330                 emit = emitter(that, arguments),
4331                 selection0 = state.selection,
4332                 selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
4333                 i = interpolateValue(selection0, selection1);
4334
4335             function tween(t) {
4336               state.selection = t === 1 && empty(selection1) ? null : i(t);
4337               redraw.call(that);
4338               emit.brush();
4339             }
4340
4341             return selection0 && selection1 ? tween : tween(1);
4342           });
4343     } else {
4344       group
4345           .each(function() {
4346             var that = this,
4347                 args = arguments,
4348                 state = that.__brush,
4349                 selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
4350                 emit = emitter(that, args).beforestart();
4351
4352             interrupt(that);
4353             state.selection = selection1 == null || empty(selection1) ? null : selection1;
4354             redraw.call(that);
4355             emit.start().brush().end();
4356           });
4357     }
4358   };
4359
4360   function redraw() {
4361     var group = select(this),
4362         selection = local(this).selection;
4363
4364     if (selection) {
4365       group.selectAll(".selection")
4366           .style("display", null)
4367           .attr("x", selection[0][0])
4368           .attr("y", selection[0][1])
4369           .attr("width", selection[1][0] - selection[0][0])
4370           .attr("height", selection[1][1] - selection[0][1]);
4371
4372       group.selectAll(".handle")
4373           .style("display", null)
4374           .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
4375           .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
4376           .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
4377           .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
4378     }
4379
4380     else {
4381       group.selectAll(".selection,.handle")
4382           .style("display", "none")
4383           .attr("x", null)
4384           .attr("y", null)
4385           .attr("width", null)
4386           .attr("height", null);
4387     }
4388   }
4389
4390   function emitter(that, args) {
4391     return that.__brush.emitter || new Emitter(that, args);
4392   }
4393
4394   function Emitter(that, args) {
4395     this.that = that;
4396     this.args = args;
4397     this.state = that.__brush;
4398     this.active = 0;
4399   }
4400
4401   Emitter.prototype = {
4402     beforestart: function() {
4403       if (++this.active === 1) this.state.emitter = this, this.starting = true;
4404       return this;
4405     },
4406     start: function() {
4407       if (this.starting) this.starting = false, this.emit("start");
4408       return this;
4409     },
4410     brush: function() {
4411       this.emit("brush");
4412       return this;
4413     },
4414     end: function() {
4415       if (--this.active === 0) delete this.state.emitter, this.emit("end");
4416       return this;
4417     },
4418     emit: function(type) {
4419       customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
4420     }
4421   };
4422
4423   function started() {
4424     if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
4425     else if (touchending) return;
4426     if (!filter.apply(this, arguments)) return;
4427
4428     var that = this,
4429         type = exports.event.target.__data__.type,
4430         mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
4431         signX = dim === Y ? null : signsX[type],
4432         signY = dim === X ? null : signsY[type],
4433         state = local(that),
4434         extent = state.extent,
4435         selection = state.selection,
4436         W = extent[0][0], w0, w1,
4437         N = extent[0][1], n0, n1,
4438         E = extent[1][0], e0, e1,
4439         S = extent[1][1], s0, s1,
4440         dx,
4441         dy,
4442         moving,
4443         shifting = signX && signY && exports.event.shiftKey,
4444         lockX,
4445         lockY,
4446         point0 = mouse(that),
4447         point = point0,
4448         emit = emitter(that, arguments).beforestart();
4449
4450     if (type === "overlay") {
4451       state.selection = selection = [
4452         [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
4453         [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
4454       ];
4455     } else {
4456       w0 = selection[0][0];
4457       n0 = selection[0][1];
4458       e0 = selection[1][0];
4459       s0 = selection[1][1];
4460     }
4461
4462     w1 = w0;
4463     n1 = n0;
4464     e1 = e0;
4465     s1 = s0;
4466
4467     var group = select(that)
4468         .attr("pointer-events", "none");
4469
4470     var overlay = group.selectAll(".overlay")
4471         .attr("cursor", cursors[type]);
4472
4473     if (exports.event.touches) {
4474       group
4475           .on("touchmove.brush", moved, true)
4476           .on("touchend.brush touchcancel.brush", ended, true);
4477     } else {
4478       var view = select(exports.event.view)
4479           .on("keydown.brush", keydowned, true)
4480           .on("keyup.brush", keyupped, true)
4481           .on("mousemove.brush", moved, true)
4482           .on("mouseup.brush", ended, true);
4483
4484       dragDisable(exports.event.view);
4485     }
4486
4487     nopropagation$1();
4488     interrupt(that);
4489     redraw.call(that);
4490     emit.start();
4491
4492     function moved() {
4493       var point1 = mouse(that);
4494       if (shifting && !lockX && !lockY) {
4495         if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
4496         else lockX = true;
4497       }
4498       point = point1;
4499       moving = true;
4500       noevent$1();
4501       move();
4502     }
4503
4504     function move() {
4505       var t;
4506
4507       dx = point[0] - point0[0];
4508       dy = point[1] - point0[1];
4509
4510       switch (mode) {
4511         case MODE_SPACE:
4512         case MODE_DRAG: {
4513           if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
4514           if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
4515           break;
4516         }
4517         case MODE_HANDLE: {
4518           if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
4519           else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
4520           if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
4521           else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
4522           break;
4523         }
4524         case MODE_CENTER: {
4525           if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
4526           if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
4527           break;
4528         }
4529       }
4530
4531       if (e1 < w1) {
4532         signX *= -1;
4533         t = w0, w0 = e0, e0 = t;
4534         t = w1, w1 = e1, e1 = t;
4535         if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
4536       }
4537
4538       if (s1 < n1) {
4539         signY *= -1;
4540         t = n0, n0 = s0, s0 = t;
4541         t = n1, n1 = s1, s1 = t;
4542         if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
4543       }
4544
4545       if (state.selection) selection = state.selection; // May be set by brush.move!
4546       if (lockX) w1 = selection[0][0], e1 = selection[1][0];
4547       if (lockY) n1 = selection[0][1], s1 = selection[1][1];
4548
4549       if (selection[0][0] !== w1
4550           || selection[0][1] !== n1
4551           || selection[1][0] !== e1
4552           || selection[1][1] !== s1) {
4553         state.selection = [[w1, n1], [e1, s1]];
4554         redraw.call(that);
4555         emit.brush();
4556       }
4557     }
4558
4559     function ended() {
4560       nopropagation$1();
4561       if (exports.event.touches) {
4562         if (exports.event.touches.length) return;
4563         if (touchending) clearTimeout(touchending);
4564         touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
4565         group.on("touchmove.brush touchend.brush touchcancel.brush", null);
4566       } else {
4567         yesdrag(exports.event.view, moving);
4568         view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
4569       }
4570       group.attr("pointer-events", "all");
4571       overlay.attr("cursor", cursors.overlay);
4572       if (state.selection) selection = state.selection; // May be set by brush.move (on start)!
4573       if (empty(selection)) state.selection = null, redraw.call(that);
4574       emit.end();
4575     }
4576
4577     function keydowned() {
4578       switch (exports.event.keyCode) {
4579         case 16: { // SHIFT
4580           shifting = signX && signY;
4581           break;
4582         }
4583         case 18: { // ALT
4584           if (mode === MODE_HANDLE) {
4585             if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4586             if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4587             mode = MODE_CENTER;
4588             move();
4589           }
4590           break;
4591         }
4592         case 32: { // SPACE; takes priority over ALT
4593           if (mode === MODE_HANDLE || mode === MODE_CENTER) {
4594             if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
4595             if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
4596             mode = MODE_SPACE;
4597             overlay.attr("cursor", cursors.selection);
4598             move();
4599           }
4600           break;
4601         }
4602         default: return;
4603       }
4604       noevent$1();
4605     }
4606
4607     function keyupped() {
4608       switch (exports.event.keyCode) {
4609         case 16: { // SHIFT
4610           if (shifting) {
4611             lockX = lockY = shifting = false;
4612             move();
4613           }
4614           break;
4615         }
4616         case 18: { // ALT
4617           if (mode === MODE_CENTER) {
4618             if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4619             if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4620             mode = MODE_HANDLE;
4621             move();
4622           }
4623           break;
4624         }
4625         case 32: { // SPACE
4626           if (mode === MODE_SPACE) {
4627             if (exports.event.altKey) {
4628               if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4629               if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4630               mode = MODE_CENTER;
4631             } else {
4632               if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4633               if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4634               mode = MODE_HANDLE;
4635             }
4636             overlay.attr("cursor", cursors[type]);
4637             move();
4638           }
4639           break;
4640         }
4641         default: return;
4642       }
4643       noevent$1();
4644     }
4645   }
4646
4647   function initialize() {
4648     var state = this.__brush || {selection: null};
4649     state.extent = extent.apply(this, arguments);
4650     state.dim = dim;
4651     return state;
4652   }
4653
4654   brush.extent = function(_) {
4655     return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
4656   };
4657
4658   brush.filter = function(_) {
4659     return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
4660   };
4661
4662   brush.handleSize = function(_) {
4663     return arguments.length ? (handleSize = +_, brush) : handleSize;
4664   };
4665
4666   brush.on = function() {
4667     var value = listeners.on.apply(listeners, arguments);
4668     return value === listeners ? brush : value;
4669   };
4670
4671   return brush;
4672 }
4673
4674 var cos = Math.cos;
4675 var sin = Math.sin;
4676 var pi$1 = Math.PI;
4677 var halfPi$1 = pi$1 / 2;
4678 var tau$1 = pi$1 * 2;
4679 var max$1 = Math.max;
4680
4681 function compareValue(compare) {
4682   return function(a, b) {
4683     return compare(
4684       a.source.value + a.target.value,
4685       b.source.value + b.target.value
4686     );
4687   };
4688 }
4689
4690 var chord = function() {
4691   var padAngle = 0,
4692       sortGroups = null,
4693       sortSubgroups = null,
4694       sortChords = null;
4695
4696   function chord(matrix) {
4697     var n = matrix.length,
4698         groupSums = [],
4699         groupIndex = sequence(n),
4700         subgroupIndex = [],
4701         chords = [],
4702         groups = chords.groups = new Array(n),
4703         subgroups = new Array(n * n),
4704         k,
4705         x,
4706         x0,
4707         dx,
4708         i,
4709         j;
4710
4711     // Compute the sum.
4712     k = 0, i = -1; while (++i < n) {
4713       x = 0, j = -1; while (++j < n) {
4714         x += matrix[i][j];
4715       }
4716       groupSums.push(x);
4717       subgroupIndex.push(sequence(n));
4718       k += x;
4719     }
4720
4721     // Sort groups…
4722     if (sortGroups) groupIndex.sort(function(a, b) {
4723       return sortGroups(groupSums[a], groupSums[b]);
4724     });
4725
4726     // Sort subgroups…
4727     if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
4728       d.sort(function(a, b) {
4729         return sortSubgroups(matrix[i][a], matrix[i][b]);
4730       });
4731     });
4732
4733     // Convert the sum to scaling factor for [0, 2pi].
4734     // TODO Allow start and end angle to be specified?
4735     // TODO Allow padding to be specified as percentage?
4736     k = max$1(0, tau$1 - padAngle * n) / k;
4737     dx = k ? padAngle : tau$1 / n;
4738
4739     // Compute the start and end angle for each group and subgroup.
4740     // Note: Opera has a bug reordering object literal properties!
4741     x = 0, i = -1; while (++i < n) {
4742       x0 = x, j = -1; while (++j < n) {
4743         var di = groupIndex[i],
4744             dj = subgroupIndex[di][j],
4745             v = matrix[di][dj],
4746             a0 = x,
4747             a1 = x += v * k;
4748         subgroups[dj * n + di] = {
4749           index: di,
4750           subindex: dj,
4751           startAngle: a0,
4752           endAngle: a1,
4753           value: v
4754         };
4755       }
4756       groups[di] = {
4757         index: di,
4758         startAngle: x0,
4759         endAngle: x,
4760         value: groupSums[di]
4761       };
4762       x += dx;
4763     }
4764
4765     // Generate chords for each (non-empty) subgroup-subgroup link.
4766     i = -1; while (++i < n) {
4767       j = i - 1; while (++j < n) {
4768         var source = subgroups[j * n + i],
4769             target = subgroups[i * n + j];
4770         if (source.value || target.value) {
4771           chords.push(source.value < target.value
4772               ? {source: target, target: source}
4773               : {source: source, target: target});
4774         }
4775       }
4776     }
4777
4778     return sortChords ? chords.sort(sortChords) : chords;
4779   }
4780
4781   chord.padAngle = function(_) {
4782     return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
4783   };
4784
4785   chord.sortGroups = function(_) {
4786     return arguments.length ? (sortGroups = _, chord) : sortGroups;
4787   };
4788
4789   chord.sortSubgroups = function(_) {
4790     return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
4791   };
4792
4793   chord.sortChords = function(_) {
4794     return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
4795   };
4796
4797   return chord;
4798 };
4799
4800 var slice$2 = Array.prototype.slice;
4801
4802 var constant$5 = function(x) {
4803   return function() {
4804     return x;
4805   };
4806 };
4807
4808 var pi$2 = Math.PI;
4809 var tau$2 = 2 * pi$2;
4810 var epsilon$1 = 1e-6;
4811 var tauEpsilon = tau$2 - epsilon$1;
4812
4813 function Path() {
4814   this._x0 = this._y0 = // start of current subpath
4815   this._x1 = this._y1 = null; // end of current subpath
4816   this._ = "";
4817 }
4818
4819 function path() {
4820   return new Path;
4821 }
4822
4823 Path.prototype = path.prototype = {
4824   constructor: Path,
4825   moveTo: function(x, y) {
4826     this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
4827   },
4828   closePath: function() {
4829     if (this._x1 !== null) {
4830       this._x1 = this._x0, this._y1 = this._y0;
4831       this._ += "Z";
4832     }
4833   },
4834   lineTo: function(x, y) {
4835     this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
4836   },
4837   quadraticCurveTo: function(x1, y1, x, y) {
4838     this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4839   },
4840   bezierCurveTo: function(x1, y1, x2, y2, x, y) {
4841     this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4842   },
4843   arcTo: function(x1, y1, x2, y2, r) {
4844     x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
4845     var x0 = this._x1,
4846         y0 = this._y1,
4847         x21 = x2 - x1,
4848         y21 = y2 - y1,
4849         x01 = x0 - x1,
4850         y01 = y0 - y1,
4851         l01_2 = x01 * x01 + y01 * y01;
4852
4853     // Is the radius negative? Error.
4854     if (r < 0) throw new Error("negative radius: " + r);
4855
4856     // Is this path empty? Move to (x1,y1).
4857     if (this._x1 === null) {
4858       this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
4859     }
4860
4861     // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
4862     else if (!(l01_2 > epsilon$1)) {}
4863
4864     // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
4865     // Equivalently, is (x1,y1) coincident with (x2,y2)?
4866     // Or, is the radius zero? Line to (x1,y1).
4867     else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
4868       this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
4869     }
4870
4871     // Otherwise, draw an arc!
4872     else {
4873       var x20 = x2 - x0,
4874           y20 = y2 - y0,
4875           l21_2 = x21 * x21 + y21 * y21,
4876           l20_2 = x20 * x20 + y20 * y20,
4877           l21 = Math.sqrt(l21_2),
4878           l01 = Math.sqrt(l01_2),
4879           l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
4880           t01 = l / l01,
4881           t21 = l / l21;
4882
4883       // If the start tangent is not coincident with (x0,y0), line to.
4884       if (Math.abs(t01 - 1) > epsilon$1) {
4885         this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
4886       }
4887
4888       this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
4889     }
4890   },
4891   arc: function(x, y, r, a0, a1, ccw) {
4892     x = +x, y = +y, r = +r;
4893     var dx = r * Math.cos(a0),
4894         dy = r * Math.sin(a0),
4895         x0 = x + dx,
4896         y0 = y + dy,
4897         cw = 1 ^ ccw,
4898         da = ccw ? a0 - a1 : a1 - a0;
4899
4900     // Is the radius negative? Error.
4901     if (r < 0) throw new Error("negative radius: " + r);
4902
4903     // Is this path empty? Move to (x0,y0).
4904     if (this._x1 === null) {
4905       this._ += "M" + x0 + "," + y0;
4906     }
4907
4908     // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
4909     else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
4910       this._ += "L" + x0 + "," + y0;
4911     }
4912
4913     // Is this arc empty? We’re done.
4914     if (!r) return;
4915
4916     // Does the angle go the wrong way? Flip the direction.
4917     if (da < 0) da = da % tau$2 + tau$2;
4918
4919     // Is this a complete circle? Draw two arcs to complete the circle.
4920     if (da > tauEpsilon) {
4921       this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
4922     }
4923
4924     // Is this arc non-empty? Draw an arc!
4925     else if (da > epsilon$1) {
4926       this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
4927     }
4928   },
4929   rect: function(x, y, w, h) {
4930     this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
4931   },
4932   toString: function() {
4933     return this._;
4934   }
4935 };
4936
4937 function defaultSource(d) {
4938   return d.source;
4939 }
4940
4941 function defaultTarget(d) {
4942   return d.target;
4943 }
4944
4945 function defaultRadius(d) {
4946   return d.radius;
4947 }
4948
4949 function defaultStartAngle(d) {
4950   return d.startAngle;
4951 }
4952
4953 function defaultEndAngle(d) {
4954   return d.endAngle;
4955 }
4956
4957 var ribbon = function() {
4958   var source = defaultSource,
4959       target = defaultTarget,
4960       radius = defaultRadius,
4961       startAngle = defaultStartAngle,
4962       endAngle = defaultEndAngle,
4963       context = null;
4964
4965   function ribbon() {
4966     var buffer,
4967         argv = slice$2.call(arguments),
4968         s = source.apply(this, argv),
4969         t = target.apply(this, argv),
4970         sr = +radius.apply(this, (argv[0] = s, argv)),
4971         sa0 = startAngle.apply(this, argv) - halfPi$1,
4972         sa1 = endAngle.apply(this, argv) - halfPi$1,
4973         sx0 = sr * cos(sa0),
4974         sy0 = sr * sin(sa0),
4975         tr = +radius.apply(this, (argv[0] = t, argv)),
4976         ta0 = startAngle.apply(this, argv) - halfPi$1,
4977         ta1 = endAngle.apply(this, argv) - halfPi$1;
4978
4979     if (!context) context = buffer = path();
4980
4981     context.moveTo(sx0, sy0);
4982     context.arc(0, 0, sr, sa0, sa1);
4983     if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
4984       context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
4985       context.arc(0, 0, tr, ta0, ta1);
4986     }
4987     context.quadraticCurveTo(0, 0, sx0, sy0);
4988     context.closePath();
4989
4990     if (buffer) return context = null, buffer + "" || null;
4991   }
4992
4993   ribbon.radius = function(_) {
4994     return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
4995   };
4996
4997   ribbon.startAngle = function(_) {
4998     return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
4999   };
5000
5001   ribbon.endAngle = function(_) {
5002     return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
5003   };
5004
5005   ribbon.source = function(_) {
5006     return arguments.length ? (source = _, ribbon) : source;
5007   };
5008
5009   ribbon.target = function(_) {
5010     return arguments.length ? (target = _, ribbon) : target;
5011   };
5012
5013   ribbon.context = function(_) {
5014     return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
5015   };
5016
5017   return ribbon;
5018 };
5019
5020 var prefix = "$";
5021
5022 function Map() {}
5023
5024 Map.prototype = map$1.prototype = {
5025   constructor: Map,
5026   has: function(key) {
5027     return (prefix + key) in this;
5028   },
5029   get: function(key) {
5030     return this[prefix + key];
5031   },
5032   set: function(key, value) {
5033     this[prefix + key] = value;
5034     return this;
5035   },
5036   remove: function(key) {
5037     var property = prefix + key;
5038     return property in this && delete this[property];
5039   },
5040   clear: function() {
5041     for (var property in this) if (property[0] === prefix) delete this[property];
5042   },
5043   keys: function() {
5044     var keys = [];
5045     for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
5046     return keys;
5047   },
5048   values: function() {
5049     var values = [];
5050     for (var property in this) if (property[0] === prefix) values.push(this[property]);
5051     return values;
5052   },
5053   entries: function() {
5054     var entries = [];
5055     for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
5056     return entries;
5057   },
5058   size: function() {
5059     var size = 0;
5060     for (var property in this) if (property[0] === prefix) ++size;
5061     return size;
5062   },
5063   empty: function() {
5064     for (var property in this) if (property[0] === prefix) return false;
5065     return true;
5066   },
5067   each: function(f) {
5068     for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
5069   }
5070 };
5071
5072 function map$1(object, f) {
5073   var map = new Map;
5074
5075   // Copy constructor.
5076   if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
5077
5078   // Index array by numeric index or specified key function.
5079   else if (Array.isArray(object)) {
5080     var i = -1,
5081         n = object.length,
5082         o;
5083
5084     if (f == null) while (++i < n) map.set(i, object[i]);
5085     else while (++i < n) map.set(f(o = object[i], i, object), o);
5086   }
5087
5088   // Convert object to map.
5089   else if (object) for (var key in object) map.set(key, object[key]);
5090
5091   return map;
5092 }
5093
5094 var nest = function() {
5095   var keys = [],
5096       sortKeys = [],
5097       sortValues,
5098       rollup,
5099       nest;
5100
5101   function apply(array, depth, createResult, setResult) {
5102     if (depth >= keys.length) {
5103       if (sortValues != null) array.sort(sortValues);
5104       return rollup != null ? rollup(array) : array;
5105     }
5106
5107     var i = -1,
5108         n = array.length,
5109         key = keys[depth++],
5110         keyValue,
5111         value,
5112         valuesByKey = map$1(),
5113         values,
5114         result = createResult();
5115
5116     while (++i < n) {
5117       if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
5118         values.push(value);
5119       } else {
5120         valuesByKey.set(keyValue, [value]);
5121       }
5122     }
5123
5124     valuesByKey.each(function(values, key) {
5125       setResult(result, key, apply(values, depth, createResult, setResult));
5126     });
5127
5128     return result;
5129   }
5130
5131   function entries(map, depth) {
5132     if (++depth > keys.length) return map;
5133     var array, sortKey = sortKeys[depth - 1];
5134     if (rollup != null && depth >= keys.length) array = map.entries();
5135     else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
5136     return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
5137   }
5138
5139   return nest = {
5140     object: function(array) { return apply(array, 0, createObject, setObject); },
5141     map: function(array) { return apply(array, 0, createMap, setMap); },
5142     entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
5143     key: function(d) { keys.push(d); return nest; },
5144     sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
5145     sortValues: function(order) { sortValues = order; return nest; },
5146     rollup: function(f) { rollup = f; return nest; }
5147   };
5148 };
5149
5150 function createObject() {
5151   return {};
5152 }
5153
5154 function setObject(object, key, value) {
5155   object[key] = value;
5156 }
5157
5158 function createMap() {
5159   return map$1();
5160 }
5161
5162 function setMap(map, key, value) {
5163   map.set(key, value);
5164 }
5165
5166 function Set() {}
5167
5168 var proto = map$1.prototype;
5169
5170 Set.prototype = set$2.prototype = {
5171   constructor: Set,
5172   has: proto.has,
5173   add: function(value) {
5174     value += "";
5175     this[prefix + value] = value;
5176     return this;
5177   },
5178   remove: proto.remove,
5179   clear: proto.clear,
5180   values: proto.keys,
5181   size: proto.size,
5182   empty: proto.empty,
5183   each: proto.each
5184 };
5185
5186 function set$2(object, f) {
5187   var set = new Set;
5188
5189   // Copy constructor.
5190   if (object instanceof Set) object.each(function(value) { set.add(value); });
5191
5192   // Otherwise, assume it’s an array.
5193   else if (object) {
5194     var i = -1, n = object.length;
5195     if (f == null) while (++i < n) set.add(object[i]);
5196     else while (++i < n) set.add(f(object[i], i, object));
5197   }
5198
5199   return set;
5200 }
5201
5202 var keys = function(map) {
5203   var keys = [];
5204   for (var key in map) keys.push(key);
5205   return keys;
5206 };
5207
5208 var values = function(map) {
5209   var values = [];
5210   for (var key in map) values.push(map[key]);
5211   return values;
5212 };
5213
5214 var entries = function(map) {
5215   var entries = [];
5216   for (var key in map) entries.push({key: key, value: map[key]});
5217   return entries;
5218 };
5219
5220 var EOL = {};
5221 var EOF = {};
5222 var QUOTE = 34;
5223 var NEWLINE = 10;
5224 var RETURN = 13;
5225
5226 function objectConverter(columns) {
5227   return new Function("d", "return {" + columns.map(function(name, i) {
5228     return JSON.stringify(name) + ": d[" + i + "]";
5229   }).join(",") + "}");
5230 }
5231
5232 function customConverter(columns, f) {
5233   var object = objectConverter(columns);
5234   return function(row, i) {
5235     return f(object(row), i, columns);
5236   };
5237 }
5238
5239 // Compute unique columns in order of discovery.
5240 function inferColumns(rows) {
5241   var columnSet = Object.create(null),
5242       columns = [];
5243
5244   rows.forEach(function(row) {
5245     for (var column in row) {
5246       if (!(column in columnSet)) {
5247         columns.push(columnSet[column] = column);
5248       }
5249     }
5250   });
5251
5252   return columns;
5253 }
5254
5255 var dsv = function(delimiter) {
5256   var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
5257       DELIMITER = delimiter.charCodeAt(0);
5258
5259   function parse(text, f) {
5260     var convert, columns, rows = parseRows(text, function(row, i) {
5261       if (convert) return convert(row, i - 1);
5262       columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
5263     });
5264     rows.columns = columns || [];
5265     return rows;
5266   }
5267
5268   function parseRows(text, f) {
5269     var rows = [], // output rows
5270         N = text.length,
5271         I = 0, // current character index
5272         n = 0, // current line number
5273         t, // current token
5274         eof = N <= 0, // current token followed by EOF?
5275         eol = false; // current token followed by EOL?
5276
5277     // Strip the trailing newline.
5278     if (text.charCodeAt(N - 1) === NEWLINE) --N;
5279     if (text.charCodeAt(N - 1) === RETURN) --N;
5280
5281     function token() {
5282       if (eof) return EOF;
5283       if (eol) return eol = false, EOL;
5284
5285       // Unescape quotes.
5286       var i, j = I, c;
5287       if (text.charCodeAt(j) === QUOTE) {
5288         while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
5289         if ((i = I) >= N) eof = true;
5290         else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
5291         else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5292         return text.slice(j + 1, i - 1).replace(/""/g, "\"");
5293       }
5294
5295       // Find next delimiter or newline.
5296       while (I < N) {
5297         if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
5298         else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5299         else if (c !== DELIMITER) continue;
5300         return text.slice(j, i);
5301       }
5302
5303       // Return last token before EOF.
5304       return eof = true, text.slice(j, N);
5305     }
5306
5307     while ((t = token()) !== EOF) {
5308       var row = [];
5309       while (t !== EOL && t !== EOF) row.push(t), t = token();
5310       if (f && (row = f(row, n++)) == null) continue;
5311       rows.push(row);
5312     }
5313
5314     return rows;
5315   }
5316
5317   function format(rows, columns) {
5318     if (columns == null) columns = inferColumns(rows);
5319     return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
5320       return columns.map(function(column) {
5321         return formatValue(row[column]);
5322       }).join(delimiter);
5323     })).join("\n");
5324   }
5325
5326   function formatRows(rows) {
5327     return rows.map(formatRow).join("\n");
5328   }
5329
5330   function formatRow(row) {
5331     return row.map(formatValue).join(delimiter);
5332   }
5333
5334   function formatValue(text) {
5335     return text == null ? ""
5336         : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
5337         : text;
5338   }
5339
5340   return {
5341     parse: parse,
5342     parseRows: parseRows,
5343     format: format,
5344     formatRows: formatRows
5345   };
5346 };
5347
5348 var csv = dsv(",");
5349
5350 var csvParse = csv.parse;
5351 var csvParseRows = csv.parseRows;
5352 var csvFormat = csv.format;
5353 var csvFormatRows = csv.formatRows;
5354
5355 var tsv = dsv("\t");
5356
5357 var tsvParse = tsv.parse;
5358 var tsvParseRows = tsv.parseRows;
5359 var tsvFormat = tsv.format;
5360 var tsvFormatRows = tsv.formatRows;
5361
5362 var center$1 = function(x, y) {
5363   var nodes;
5364
5365   if (x == null) x = 0;
5366   if (y == null) y = 0;
5367
5368   function force() {
5369     var i,
5370         n = nodes.length,
5371         node,
5372         sx = 0,
5373         sy = 0;
5374
5375     for (i = 0; i < n; ++i) {
5376       node = nodes[i], sx += node.x, sy += node.y;
5377     }
5378
5379     for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
5380       node = nodes[i], node.x -= sx, node.y -= sy;
5381     }
5382   }
5383
5384   force.initialize = function(_) {
5385     nodes = _;
5386   };
5387
5388   force.x = function(_) {
5389     return arguments.length ? (x = +_, force) : x;
5390   };
5391
5392   force.y = function(_) {
5393     return arguments.length ? (y = +_, force) : y;
5394   };
5395
5396   return force;
5397 };
5398
5399 var constant$6 = function(x) {
5400   return function() {
5401     return x;
5402   };
5403 };
5404
5405 var jiggle = function() {
5406   return (Math.random() - 0.5) * 1e-6;
5407 };
5408
5409 var tree_add = function(d) {
5410   var x = +this._x.call(null, d),
5411       y = +this._y.call(null, d);
5412   return add(this.cover(x, y), x, y, d);
5413 };
5414
5415 function add(tree, x, y, d) {
5416   if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
5417
5418   var parent,
5419       node = tree._root,
5420       leaf = {data: d},
5421       x0 = tree._x0,
5422       y0 = tree._y0,
5423       x1 = tree._x1,
5424       y1 = tree._y1,
5425       xm,
5426       ym,
5427       xp,
5428       yp,
5429       right,
5430       bottom,
5431       i,
5432       j;
5433
5434   // If the tree is empty, initialize the root as a leaf.
5435   if (!node) return tree._root = leaf, tree;
5436
5437   // Find the existing leaf for the new point, or add it.
5438   while (node.length) {
5439     if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5440     if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5441     if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
5442   }
5443
5444   // Is the new point is exactly coincident with the existing point?
5445   xp = +tree._x.call(null, node.data);
5446   yp = +tree._y.call(null, node.data);
5447   if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
5448
5449   // Otherwise, split the leaf node until the old and new point are separated.
5450   do {
5451     parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
5452     if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5453     if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5454   } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
5455   return parent[j] = node, parent[i] = leaf, tree;
5456 }
5457
5458 function addAll(data) {
5459   var d, i, n = data.length,
5460       x,
5461       y,
5462       xz = new Array(n),
5463       yz = new Array(n),
5464       x0 = Infinity,
5465       y0 = Infinity,
5466       x1 = -Infinity,
5467       y1 = -Infinity;
5468
5469   // Compute the points and their extent.
5470   for (i = 0; i < n; ++i) {
5471     if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
5472     xz[i] = x;
5473     yz[i] = y;
5474     if (x < x0) x0 = x;
5475     if (x > x1) x1 = x;
5476     if (y < y0) y0 = y;
5477     if (y > y1) y1 = y;
5478   }
5479
5480   // If there were no (valid) points, inherit the existing extent.
5481   if (x1 < x0) x0 = this._x0, x1 = this._x1;
5482   if (y1 < y0) y0 = this._y0, y1 = this._y1;
5483
5484   // Expand the tree to cover the new points.
5485   this.cover(x0, y0).cover(x1, y1);
5486
5487   // Add the new points.
5488   for (i = 0; i < n; ++i) {
5489     add(this, xz[i], yz[i], data[i]);
5490   }
5491
5492   return this;
5493 }
5494
5495 var tree_cover = function(x, y) {
5496   if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
5497
5498   var x0 = this._x0,
5499       y0 = this._y0,
5500       x1 = this._x1,
5501       y1 = this._y1;
5502
5503   // If the quadtree has no extent, initialize them.
5504   // Integer extent are necessary so that if we later double the extent,
5505   // the existing quadrant boundaries don’t change due to floating point error!
5506   if (isNaN(x0)) {
5507     x1 = (x0 = Math.floor(x)) + 1;
5508     y1 = (y0 = Math.floor(y)) + 1;
5509   }
5510
5511   // Otherwise, double repeatedly to cover.
5512   else if (x0 > x || x > x1 || y0 > y || y > y1) {
5513     var z = x1 - x0,
5514         node = this._root,
5515         parent,
5516         i;
5517
5518     switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
5519       case 0: {
5520         do parent = new Array(4), parent[i] = node, node = parent;
5521         while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
5522         break;
5523       }
5524       case 1: {
5525         do parent = new Array(4), parent[i] = node, node = parent;
5526         while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
5527         break;
5528       }
5529       case 2: {
5530         do parent = new Array(4), parent[i] = node, node = parent;
5531         while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
5532         break;
5533       }
5534       case 3: {
5535         do parent = new Array(4), parent[i] = node, node = parent;
5536         while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
5537         break;
5538       }
5539     }
5540
5541     if (this._root && this._root.length) this._root = node;
5542   }
5543
5544   // If the quadtree covers the point already, just return.
5545   else return this;
5546
5547   this._x0 = x0;
5548   this._y0 = y0;
5549   this._x1 = x1;
5550   this._y1 = y1;
5551   return this;
5552 };
5553
5554 var tree_data = function() {
5555   var data = [];
5556   this.visit(function(node) {
5557     if (!node.length) do data.push(node.data); while (node = node.next)
5558   });
5559   return data;
5560 };
5561
5562 var tree_extent = function(_) {
5563   return arguments.length
5564       ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
5565       : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
5566 };
5567
5568 var Quad = function(node, x0, y0, x1, y1) {
5569   this.node = node;
5570   this.x0 = x0;
5571   this.y0 = y0;
5572   this.x1 = x1;
5573   this.y1 = y1;
5574 };
5575
5576 var tree_find = function(x, y, radius) {
5577   var data,
5578       x0 = this._x0,
5579       y0 = this._y0,
5580       x1,
5581       y1,
5582       x2,
5583       y2,
5584       x3 = this._x1,
5585       y3 = this._y1,
5586       quads = [],
5587       node = this._root,
5588       q,
5589       i;
5590
5591   if (node) quads.push(new Quad(node, x0, y0, x3, y3));
5592   if (radius == null) radius = Infinity;
5593   else {
5594     x0 = x - radius, y0 = y - radius;
5595     x3 = x + radius, y3 = y + radius;
5596     radius *= radius;
5597   }
5598
5599   while (q = quads.pop()) {
5600
5601     // Stop searching if this quadrant can’t contain a closer node.
5602     if (!(node = q.node)
5603         || (x1 = q.x0) > x3
5604         || (y1 = q.y0) > y3
5605         || (x2 = q.x1) < x0
5606         || (y2 = q.y1) < y0) continue;
5607
5608     // Bisect the current quadrant.
5609     if (node.length) {
5610       var xm = (x1 + x2) / 2,
5611           ym = (y1 + y2) / 2;
5612
5613       quads.push(
5614         new Quad(node[3], xm, ym, x2, y2),
5615         new Quad(node[2], x1, ym, xm, y2),
5616         new Quad(node[1], xm, y1, x2, ym),
5617         new Quad(node[0], x1, y1, xm, ym)
5618       );
5619
5620       // Visit the closest quadrant first.
5621       if (i = (y >= ym) << 1 | (x >= xm)) {
5622         q = quads[quads.length - 1];
5623         quads[quads.length - 1] = quads[quads.length - 1 - i];
5624         quads[quads.length - 1 - i] = q;
5625       }
5626     }
5627
5628     // Visit this point. (Visiting coincident points isn’t necessary!)
5629     else {
5630       var dx = x - +this._x.call(null, node.data),
5631           dy = y - +this._y.call(null, node.data),
5632           d2 = dx * dx + dy * dy;
5633       if (d2 < radius) {
5634         var d = Math.sqrt(radius = d2);
5635         x0 = x - d, y0 = y - d;
5636         x3 = x + d, y3 = y + d;
5637         data = node.data;
5638       }
5639     }
5640   }
5641
5642   return data;
5643 };
5644
5645 var tree_remove = function(d) {
5646   if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
5647
5648   var parent,
5649       node = this._root,
5650       retainer,
5651       previous,
5652       next,
5653       x0 = this._x0,
5654       y0 = this._y0,
5655       x1 = this._x1,
5656       y1 = this._y1,
5657       x,
5658       y,
5659       xm,
5660       ym,
5661       right,
5662       bottom,
5663       i,
5664       j;
5665
5666   // If the tree is empty, initialize the root as a leaf.
5667   if (!node) return this;
5668
5669   // Find the leaf node for the point.
5670   // While descending, also retain the deepest parent with a non-removed sibling.
5671   if (node.length) while (true) {
5672     if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
5673     if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
5674     if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
5675     if (!node.length) break;
5676     if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
5677   }
5678
5679   // Find the point to remove.
5680   while (node.data !== d) if (!(previous = node, node = node.next)) return this;
5681   if (next = node.next) delete node.next;
5682
5683   // If there are multiple coincident points, remove just the point.
5684   if (previous) return next ? previous.next = next : delete previous.next, this;
5685
5686   // If this is the root point, remove it.
5687   if (!parent) return this._root = next, this;
5688
5689   // Remove this leaf.
5690   next ? parent[i] = next : delete parent[i];
5691
5692   // If the parent now contains exactly one leaf, collapse superfluous parents.
5693   if ((node = parent[0] || parent[1] || parent[2] || parent[3])
5694       && node === (parent[3] || parent[2] || parent[1] || parent[0])
5695       && !node.length) {
5696     if (retainer) retainer[j] = node;
5697     else this._root = node;
5698   }
5699
5700   return this;
5701 };
5702
5703 function removeAll(data) {
5704   for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
5705   return this;
5706 }
5707
5708 var tree_root = function() {
5709   return this._root;
5710 };
5711
5712 var tree_size = function() {
5713   var size = 0;
5714   this.visit(function(node) {
5715     if (!node.length) do ++size; while (node = node.next)
5716   });
5717   return size;
5718 };
5719
5720 var tree_visit = function(callback) {
5721   var quads = [], q, node = this._root, child, x0, y0, x1, y1;
5722   if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
5723   while (q = quads.pop()) {
5724     if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
5725       var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
5726       if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
5727       if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
5728       if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
5729       if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
5730     }
5731   }
5732   return this;
5733 };
5734
5735 var tree_visitAfter = function(callback) {
5736   var quads = [], next = [], q;
5737   if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
5738   while (q = quads.pop()) {
5739     var node = q.node;
5740     if (node.length) {
5741       var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
5742       if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
5743       if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
5744       if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
5745       if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
5746     }
5747     next.push(q);
5748   }
5749   while (q = next.pop()) {
5750     callback(q.node, q.x0, q.y0, q.x1, q.y1);
5751   }
5752   return this;
5753 };
5754
5755 function defaultX(d) {
5756   return d[0];
5757 }
5758
5759 var tree_x = function(_) {
5760   return arguments.length ? (this._x = _, this) : this._x;
5761 };
5762
5763 function defaultY(d) {
5764   return d[1];
5765 }
5766
5767 var tree_y = function(_) {
5768   return arguments.length ? (this._y = _, this) : this._y;
5769 };
5770
5771 function quadtree(nodes, x, y) {
5772   var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
5773   return nodes == null ? tree : tree.addAll(nodes);
5774 }
5775
5776 function Quadtree(x, y, x0, y0, x1, y1) {
5777   this._x = x;
5778   this._y = y;
5779   this._x0 = x0;
5780   this._y0 = y0;
5781   this._x1 = x1;
5782   this._y1 = y1;
5783   this._root = undefined;
5784 }
5785
5786 function leaf_copy(leaf) {
5787   var copy = {data: leaf.data}, next = copy;
5788   while (leaf = leaf.next) next = next.next = {data: leaf.data};
5789   return copy;
5790 }
5791
5792 var treeProto = quadtree.prototype = Quadtree.prototype;
5793
5794 treeProto.copy = function() {
5795   var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
5796       node = this._root,
5797       nodes,
5798       child;
5799
5800   if (!node) return copy;
5801
5802   if (!node.length) return copy._root = leaf_copy(node), copy;
5803
5804   nodes = [{source: node, target: copy._root = new Array(4)}];
5805   while (node = nodes.pop()) {
5806     for (var i = 0; i < 4; ++i) {
5807       if (child = node.source[i]) {
5808         if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
5809         else node.target[i] = leaf_copy(child);
5810       }
5811     }
5812   }
5813
5814   return copy;
5815 };
5816
5817 treeProto.add = tree_add;
5818 treeProto.addAll = addAll;
5819 treeProto.cover = tree_cover;
5820 treeProto.data = tree_data;
5821 treeProto.extent = tree_extent;
5822 treeProto.find = tree_find;
5823 treeProto.remove = tree_remove;
5824 treeProto.removeAll = removeAll;
5825 treeProto.root = tree_root;
5826 treeProto.size = tree_size;
5827 treeProto.visit = tree_visit;
5828 treeProto.visitAfter = tree_visitAfter;
5829 treeProto.x = tree_x;
5830 treeProto.y = tree_y;
5831
5832 function x(d) {
5833   return d.x + d.vx;
5834 }
5835
5836 function y(d) {
5837   return d.y + d.vy;
5838 }
5839
5840 var collide = function(radius) {
5841   var nodes,
5842       radii,
5843       strength = 1,
5844       iterations = 1;
5845
5846   if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
5847
5848   function force() {
5849     var i, n = nodes.length,
5850         tree,
5851         node,
5852         xi,
5853         yi,
5854         ri,
5855         ri2;
5856
5857     for (var k = 0; k < iterations; ++k) {
5858       tree = quadtree(nodes, x, y).visitAfter(prepare);
5859       for (i = 0; i < n; ++i) {
5860         node = nodes[i];
5861         ri = radii[node.index], ri2 = ri * ri;
5862         xi = node.x + node.vx;
5863         yi = node.y + node.vy;
5864         tree.visit(apply);
5865       }
5866     }
5867
5868     function apply(quad, x0, y0, x1, y1) {
5869       var data = quad.data, rj = quad.r, r = ri + rj;
5870       if (data) {
5871         if (data.index > node.index) {
5872           var x = xi - data.x - data.vx,
5873               y = yi - data.y - data.vy,
5874               l = x * x + y * y;
5875           if (l < r * r) {
5876             if (x === 0) x = jiggle(), l += x * x;
5877             if (y === 0) y = jiggle(), l += y * y;
5878             l = (r - (l = Math.sqrt(l))) / l * strength;
5879             node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
5880             node.vy += (y *= l) * r;
5881             data.vx -= x * (r = 1 - r);
5882             data.vy -= y * r;
5883           }
5884         }
5885         return;
5886       }
5887       return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
5888     }
5889   }
5890
5891   function prepare(quad) {
5892     if (quad.data) return quad.r = radii[quad.data.index];
5893     for (var i = quad.r = 0; i < 4; ++i) {
5894       if (quad[i] && quad[i].r > quad.r) {
5895         quad.r = quad[i].r;
5896       }
5897     }
5898   }
5899
5900   function initialize() {
5901     if (!nodes) return;
5902     var i, n = nodes.length, node;
5903     radii = new Array(n);
5904     for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
5905   }
5906
5907   force.initialize = function(_) {
5908     nodes = _;
5909     initialize();
5910   };
5911
5912   force.iterations = function(_) {
5913     return arguments.length ? (iterations = +_, force) : iterations;
5914   };
5915
5916   force.strength = function(_) {
5917     return arguments.length ? (strength = +_, force) : strength;
5918   };
5919
5920   force.radius = function(_) {
5921     return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
5922   };
5923
5924   return force;
5925 };
5926
5927 function index(d) {
5928   return d.index;
5929 }
5930
5931 function find(nodeById, nodeId) {
5932   var node = nodeById.get(nodeId);
5933   if (!node) throw new Error("missing: " + nodeId);
5934   return node;
5935 }
5936
5937 var link = function(links) {
5938   var id = index,
5939       strength = defaultStrength,
5940       strengths,
5941       distance = constant$6(30),
5942       distances,
5943       nodes,
5944       count,
5945       bias,
5946       iterations = 1;
5947
5948   if (links == null) links = [];
5949
5950   function defaultStrength(link) {
5951     return 1 / Math.min(count[link.source.index], count[link.target.index]);
5952   }
5953
5954   function force(alpha) {
5955     for (var k = 0, n = links.length; k < iterations; ++k) {
5956       for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
5957         link = links[i], source = link.source, target = link.target;
5958         x = target.x + target.vx - source.x - source.vx || jiggle();
5959         y = target.y + target.vy - source.y - source.vy || jiggle();
5960         l = Math.sqrt(x * x + y * y);
5961         l = (l - distances[i]) / l * alpha * strengths[i];
5962         x *= l, y *= l;
5963         target.vx -= x * (b = bias[i]);
5964         target.vy -= y * b;
5965         source.vx += x * (b = 1 - b);
5966         source.vy += y * b;
5967       }
5968     }
5969   }
5970
5971   function initialize() {
5972     if (!nodes) return;
5973
5974     var i,
5975         n = nodes.length,
5976         m = links.length,
5977         nodeById = map$1(nodes, id),
5978         link;
5979
5980     for (i = 0, count = new Array(n); i < m; ++i) {
5981       link = links[i], link.index = i;
5982       if (typeof link.source !== "object") link.source = find(nodeById, link.source);
5983       if (typeof link.target !== "object") link.target = find(nodeById, link.target);
5984       count[link.source.index] = (count[link.source.index] || 0) + 1;
5985       count[link.target.index] = (count[link.target.index] || 0) + 1;
5986     }
5987
5988     for (i = 0, bias = new Array(m); i < m; ++i) {
5989       link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
5990     }
5991
5992     strengths = new Array(m), initializeStrength();
5993     distances = new Array(m), initializeDistance();
5994   }
5995
5996   function initializeStrength() {
5997     if (!nodes) return;
5998
5999     for (var i = 0, n = links.length; i < n; ++i) {
6000       strengths[i] = +strength(links[i], i, links);
6001     }
6002   }
6003
6004   function initializeDistance() {
6005     if (!nodes) return;
6006
6007     for (var i = 0, n = links.length; i < n; ++i) {
6008       distances[i] = +distance(links[i], i, links);
6009     }
6010   }
6011
6012   force.initialize = function(_) {
6013     nodes = _;
6014     initialize();
6015   };
6016
6017   force.links = function(_) {
6018     return arguments.length ? (links = _, initialize(), force) : links;
6019   };
6020
6021   force.id = function(_) {
6022     return arguments.length ? (id = _, force) : id;
6023   };
6024
6025   force.iterations = function(_) {
6026     return arguments.length ? (iterations = +_, force) : iterations;
6027   };
6028
6029   force.strength = function(_) {
6030     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
6031   };
6032
6033   force.distance = function(_) {
6034     return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
6035   };
6036
6037   return force;
6038 };
6039
6040 function x$1(d) {
6041   return d.x;
6042 }
6043
6044 function y$1(d) {
6045   return d.y;
6046 }
6047
6048 var initialRadius = 10;
6049 var initialAngle = Math.PI * (3 - Math.sqrt(5));
6050
6051 var simulation = function(nodes) {
6052   var simulation,
6053       alpha = 1,
6054       alphaMin = 0.001,
6055       alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
6056       alphaTarget = 0,
6057       velocityDecay = 0.6,
6058       forces = map$1(),
6059       stepper = timer(step),
6060       event = dispatch("tick", "end");
6061
6062   if (nodes == null) nodes = [];
6063
6064   function step() {
6065     tick();
6066     event.call("tick", simulation);
6067     if (alpha < alphaMin) {
6068       stepper.stop();
6069       event.call("end", simulation);
6070     }
6071   }
6072
6073   function tick() {
6074     var i, n = nodes.length, node;
6075
6076     alpha += (alphaTarget - alpha) * alphaDecay;
6077
6078     forces.each(function(force) {
6079       force(alpha);
6080     });
6081
6082     for (i = 0; i < n; ++i) {
6083       node = nodes[i];
6084       if (node.fx == null) node.x += node.vx *= velocityDecay;
6085       else node.x = node.fx, node.vx = 0;
6086       if (node.fy == null) node.y += node.vy *= velocityDecay;
6087       else node.y = node.fy, node.vy = 0;
6088     }
6089   }
6090
6091   function initializeNodes() {
6092     for (var i = 0, n = nodes.length, node; i < n; ++i) {
6093       node = nodes[i], node.index = i;
6094       if (isNaN(node.x) || isNaN(node.y)) {
6095         var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
6096         node.x = radius * Math.cos(angle);
6097         node.y = radius * Math.sin(angle);
6098       }
6099       if (isNaN(node.vx) || isNaN(node.vy)) {
6100         node.vx = node.vy = 0;
6101       }
6102     }
6103   }
6104
6105   function initializeForce(force) {
6106     if (force.initialize) force.initialize(nodes);
6107     return force;
6108   }
6109
6110   initializeNodes();
6111
6112   return simulation = {
6113     tick: tick,
6114
6115     restart: function() {
6116       return stepper.restart(step), simulation;
6117     },
6118
6119     stop: function() {
6120       return stepper.stop(), simulation;
6121     },
6122
6123     nodes: function(_) {
6124       return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
6125     },
6126
6127     alpha: function(_) {
6128       return arguments.length ? (alpha = +_, simulation) : alpha;
6129     },
6130
6131     alphaMin: function(_) {
6132       return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
6133     },
6134
6135     alphaDecay: function(_) {
6136       return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
6137     },
6138
6139     alphaTarget: function(_) {
6140       return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
6141     },
6142
6143     velocityDecay: function(_) {
6144       return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
6145     },
6146
6147     force: function(name, _) {
6148       return arguments.length > 1 ? (_ == null ? forces.remove(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
6149     },
6150
6151     find: function(x, y, radius) {
6152       var i = 0,
6153           n = nodes.length,
6154           dx,
6155           dy,
6156           d2,
6157           node,
6158           closest;
6159
6160       if (radius == null) radius = Infinity;
6161       else radius *= radius;
6162
6163       for (i = 0; i < n; ++i) {
6164         node = nodes[i];
6165         dx = x - node.x;
6166         dy = y - node.y;
6167         d2 = dx * dx + dy * dy;
6168         if (d2 < radius) closest = node, radius = d2;
6169       }
6170
6171       return closest;
6172     },
6173
6174     on: function(name, _) {
6175       return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
6176     }
6177   };
6178 };
6179
6180 var manyBody = function() {
6181   var nodes,
6182       node,
6183       alpha,
6184       strength = constant$6(-30),
6185       strengths,
6186       distanceMin2 = 1,
6187       distanceMax2 = Infinity,
6188       theta2 = 0.81;
6189
6190   function force(_) {
6191     var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
6192     for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
6193   }
6194
6195   function initialize() {
6196     if (!nodes) return;
6197     var i, n = nodes.length, node;
6198     strengths = new Array(n);
6199     for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
6200   }
6201
6202   function accumulate(quad) {
6203     var strength = 0, q, c, weight = 0, x, y, i;
6204
6205     // For internal nodes, accumulate forces from child quadrants.
6206     if (quad.length) {
6207       for (x = y = i = 0; i < 4; ++i) {
6208         if ((q = quad[i]) && (c = Math.abs(q.value))) {
6209           strength += q.value, weight += c, x += c * q.x, y += c * q.y;
6210         }
6211       }
6212       quad.x = x / weight;
6213       quad.y = y / weight;
6214     }
6215
6216     // For leaf nodes, accumulate forces from coincident quadrants.
6217     else {
6218       q = quad;
6219       q.x = q.data.x;
6220       q.y = q.data.y;
6221       do strength += strengths[q.data.index];
6222       while (q = q.next);
6223     }
6224
6225     quad.value = strength;
6226   }
6227
6228   function apply(quad, x1, _, x2) {
6229     if (!quad.value) return true;
6230
6231     var x = quad.x - node.x,
6232         y = quad.y - node.y,
6233         w = x2 - x1,
6234         l = x * x + y * y;
6235
6236     // Apply the Barnes-Hut approximation if possible.
6237     // Limit forces for very close nodes; randomize direction if coincident.
6238     if (w * w / theta2 < l) {
6239       if (l < distanceMax2) {
6240         if (x === 0) x = jiggle(), l += x * x;
6241         if (y === 0) y = jiggle(), l += y * y;
6242         if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6243         node.vx += x * quad.value * alpha / l;
6244         node.vy += y * quad.value * alpha / l;
6245       }
6246       return true;
6247     }
6248
6249     // Otherwise, process points directly.
6250     else if (quad.length || l >= distanceMax2) return;
6251
6252     // Limit forces for very close nodes; randomize direction if coincident.
6253     if (quad.data !== node || quad.next) {
6254       if (x === 0) x = jiggle(), l += x * x;
6255       if (y === 0) y = jiggle(), l += y * y;
6256       if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6257     }
6258
6259     do if (quad.data !== node) {
6260       w = strengths[quad.data.index] * alpha / l;
6261       node.vx += x * w;
6262       node.vy += y * w;
6263     } while (quad = quad.next);
6264   }
6265
6266   force.initialize = function(_) {
6267     nodes = _;
6268     initialize();
6269   };
6270
6271   force.strength = function(_) {
6272     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6273   };
6274
6275   force.distanceMin = function(_) {
6276     return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
6277   };
6278
6279   force.distanceMax = function(_) {
6280     return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
6281   };
6282
6283   force.theta = function(_) {
6284     return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
6285   };
6286
6287   return force;
6288 };
6289
6290 var radial = function(radius, x, y) {
6291   var nodes,
6292       strength = constant$6(0.1),
6293       strengths,
6294       radiuses;
6295
6296   if (typeof radius !== "function") radius = constant$6(+radius);
6297   if (x == null) x = 0;
6298   if (y == null) y = 0;
6299
6300   function force(alpha) {
6301     for (var i = 0, n = nodes.length; i < n; ++i) {
6302       var node = nodes[i],
6303           dx = node.x - x || 1e-6,
6304           dy = node.y - y || 1e-6,
6305           r = Math.sqrt(dx * dx + dy * dy),
6306           k = (radiuses[i] - r) * strengths[i] * alpha / r;
6307       node.vx += dx * k;
6308       node.vy += dy * k;
6309     }
6310   }
6311
6312   function initialize() {
6313     if (!nodes) return;
6314     var i, n = nodes.length;
6315     strengths = new Array(n);
6316     radiuses = new Array(n);
6317     for (i = 0; i < n; ++i) {
6318       radiuses[i] = +radius(nodes[i], i, nodes);
6319       strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
6320     }
6321   }
6322
6323   force.initialize = function(_) {
6324     nodes = _, initialize();
6325   };
6326
6327   force.strength = function(_) {
6328     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6329   };
6330
6331   force.radius = function(_) {
6332     return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : radius;
6333   };
6334
6335   force.x = function(_) {
6336     return arguments.length ? (x = +_, force) : x;
6337   };
6338
6339   force.y = function(_) {
6340     return arguments.length ? (y = +_, force) : y;
6341   };
6342
6343   return force;
6344 };
6345
6346 var x$2 = function(x) {
6347   var strength = constant$6(0.1),
6348       nodes,
6349       strengths,
6350       xz;
6351
6352   if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
6353
6354   function force(alpha) {
6355     for (var i = 0, n = nodes.length, node; i < n; ++i) {
6356       node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
6357     }
6358   }
6359
6360   function initialize() {
6361     if (!nodes) return;
6362     var i, n = nodes.length;
6363     strengths = new Array(n);
6364     xz = new Array(n);
6365     for (i = 0; i < n; ++i) {
6366       strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6367     }
6368   }
6369
6370   force.initialize = function(_) {
6371     nodes = _;
6372     initialize();
6373   };
6374
6375   force.strength = function(_) {
6376     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6377   };
6378
6379   force.x = function(_) {
6380     return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
6381   };
6382
6383   return force;
6384 };
6385
6386 var y$2 = function(y) {
6387   var strength = constant$6(0.1),
6388       nodes,
6389       strengths,
6390       yz;
6391
6392   if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
6393
6394   function force(alpha) {
6395     for (var i = 0, n = nodes.length, node; i < n; ++i) {
6396       node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
6397     }
6398   }
6399
6400   function initialize() {
6401     if (!nodes) return;
6402     var i, n = nodes.length;
6403     strengths = new Array(n);
6404     yz = new Array(n);
6405     for (i = 0; i < n; ++i) {
6406       strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6407     }
6408   }
6409
6410   force.initialize = function(_) {
6411     nodes = _;
6412     initialize();
6413   };
6414
6415   force.strength = function(_) {
6416     return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
6417   };
6418
6419   force.y = function(_) {
6420     return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
6421   };
6422
6423   return force;
6424 };
6425
6426 // Computes the decimal coefficient and exponent of the specified number x with
6427 // significant digits p, where x is positive and p is in [1, 21] or undefined.
6428 // For example, formatDecimal(1.23) returns ["123", 0].
6429 var formatDecimal = function(x, p) {
6430   if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
6431   var i, coefficient = x.slice(0, i);
6432
6433   // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
6434   // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
6435   return [
6436     coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
6437     +x.slice(i + 1)
6438   ];
6439 };
6440
6441 var exponent$1 = function(x) {
6442   return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
6443 };
6444
6445 var formatGroup = function(grouping, thousands) {
6446   return function(value, width) {
6447     var i = value.length,
6448         t = [],
6449         j = 0,
6450         g = grouping[0],
6451         length = 0;
6452
6453     while (i > 0 && g > 0) {
6454       if (length + g + 1 > width) g = Math.max(1, width - length);
6455       t.push(value.substring(i -= g, i + g));
6456       if ((length += g + 1) > width) break;
6457       g = grouping[j = (j + 1) % grouping.length];
6458     }
6459
6460     return t.reverse().join(thousands);
6461   };
6462 };
6463
6464 var formatNumerals = function(numerals) {
6465   return function(value) {
6466     return value.replace(/[0-9]/g, function(i) {
6467       return numerals[+i];
6468     });
6469   };
6470 };
6471
6472 var formatDefault = function(x, p) {
6473   x = x.toPrecision(p);
6474
6475   out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
6476     switch (x[i]) {
6477       case ".": i0 = i1 = i; break;
6478       case "0": if (i0 === 0) i0 = i; i1 = i; break;
6479       case "e": break out;
6480       default: if (i0 > 0) i0 = 0; break;
6481     }
6482   }
6483
6484   return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
6485 };
6486
6487 var prefixExponent;
6488
6489 var formatPrefixAuto = function(x, p) {
6490   var d = formatDecimal(x, p);
6491   if (!d) return x + "";
6492   var coefficient = d[0],
6493       exponent = d[1],
6494       i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
6495       n = coefficient.length;
6496   return i === n ? coefficient
6497       : i > n ? coefficient + new Array(i - n + 1).join("0")
6498       : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
6499       : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
6500 };
6501
6502 var formatRounded = function(x, p) {
6503   var d = formatDecimal(x, p);
6504   if (!d) return x + "";
6505   var coefficient = d[0],
6506       exponent = d[1];
6507   return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
6508       : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
6509       : coefficient + new Array(exponent - coefficient.length + 2).join("0");
6510 };
6511
6512 var formatTypes = {
6513   "": formatDefault,
6514   "%": function(x, p) { return (x * 100).toFixed(p); },
6515   "b": function(x) { return Math.round(x).toString(2); },
6516   "c": function(x) { return x + ""; },
6517   "d": function(x) { return Math.round(x).toString(10); },
6518   "e": function(x, p) { return x.toExponential(p); },
6519   "f": function(x, p) { return x.toFixed(p); },
6520   "g": function(x, p) { return x.toPrecision(p); },
6521   "o": function(x) { return Math.round(x).toString(8); },
6522   "p": function(x, p) { return formatRounded(x * 100, p); },
6523   "r": formatRounded,
6524   "s": formatPrefixAuto,
6525   "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
6526   "x": function(x) { return Math.round(x).toString(16); }
6527 };
6528
6529 // [[fill]align][sign][symbol][0][width][,][.precision][type]
6530 var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
6531
6532 function formatSpecifier(specifier) {
6533   return new FormatSpecifier(specifier);
6534 }
6535
6536 formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
6537
6538 function FormatSpecifier(specifier) {
6539   if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
6540
6541   var match,
6542       fill = match[1] || " ",
6543       align = match[2] || ">",
6544       sign = match[3] || "-",
6545       symbol = match[4] || "",
6546       zero = !!match[5],
6547       width = match[6] && +match[6],
6548       comma = !!match[7],
6549       precision = match[8] && +match[8].slice(1),
6550       type = match[9] || "";
6551
6552   // The "n" type is an alias for ",g".
6553   if (type === "n") comma = true, type = "g";
6554
6555   // Map invalid types to the default format.
6556   else if (!formatTypes[type]) type = "";
6557
6558   // If zero fill is specified, padding goes after sign and before digits.
6559   if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
6560
6561   this.fill = fill;
6562   this.align = align;
6563   this.sign = sign;
6564   this.symbol = symbol;
6565   this.zero = zero;
6566   this.width = width;
6567   this.comma = comma;
6568   this.precision = precision;
6569   this.type = type;
6570 }
6571
6572 FormatSpecifier.prototype.toString = function() {
6573   return this.fill
6574       + this.align
6575       + this.sign
6576       + this.symbol
6577       + (this.zero ? "0" : "")
6578       + (this.width == null ? "" : Math.max(1, this.width | 0))
6579       + (this.comma ? "," : "")
6580       + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
6581       + this.type;
6582 };
6583
6584 var identity$3 = function(x) {
6585   return x;
6586 };
6587
6588 var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
6589
6590 var formatLocale = function(locale) {
6591   var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
6592       currency = locale.currency,
6593       decimal = locale.decimal,
6594       numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
6595       percent = locale.percent || "%";
6596
6597   function newFormat(specifier) {
6598     specifier = formatSpecifier(specifier);
6599
6600     var fill = specifier.fill,
6601         align = specifier.align,
6602         sign = specifier.sign,
6603         symbol = specifier.symbol,
6604         zero = specifier.zero,
6605         width = specifier.width,
6606         comma = specifier.comma,
6607         precision = specifier.precision,
6608         type = specifier.type;
6609
6610     // Compute the prefix and suffix.
6611     // For SI-prefix, the suffix is lazily computed.
6612     var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
6613         suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
6614
6615     // What format function should we use?
6616     // Is this an integer type?
6617     // Can this type generate exponential notation?
6618     var formatType = formatTypes[type],
6619         maybeSuffix = !type || /[defgprs%]/.test(type);
6620
6621     // Set the default precision if not specified,
6622     // or clamp the specified precision to the supported range.
6623     // For significant precision, it must be in [1, 21].
6624     // For fixed precision, it must be in [0, 20].
6625     precision = precision == null ? (type ? 6 : 12)
6626         : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
6627         : Math.max(0, Math.min(20, precision));
6628
6629     function format(value) {
6630       var valuePrefix = prefix,
6631           valueSuffix = suffix,
6632           i, n, c;
6633
6634       if (type === "c") {
6635         valueSuffix = formatType(value) + valueSuffix;
6636         value = "";
6637       } else {
6638         value = +value;
6639
6640         // Perform the initial formatting.
6641         var valueNegative = value < 0;
6642         value = formatType(Math.abs(value), precision);
6643
6644         // If a negative value rounds to zero during formatting, treat as positive.
6645         if (valueNegative && +value === 0) valueNegative = false;
6646
6647         // Compute the prefix and suffix.
6648         valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
6649         valueSuffix = valueSuffix + (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + (valueNegative && sign === "(" ? ")" : "");
6650
6651         // Break the formatted value into the integer “value” part that can be
6652         // grouped, and fractional or exponential “suffix” part that is not.
6653         if (maybeSuffix) {
6654           i = -1, n = value.length;
6655           while (++i < n) {
6656             if (c = value.charCodeAt(i), 48 > c || c > 57) {
6657               valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
6658               value = value.slice(0, i);
6659               break;
6660             }
6661           }
6662         }
6663       }
6664
6665       // If the fill character is not "0", grouping is applied before padding.
6666       if (comma && !zero) value = group(value, Infinity);
6667
6668       // Compute the padding.
6669       var length = valuePrefix.length + value.length + valueSuffix.length,
6670           padding = length < width ? new Array(width - length + 1).join(fill) : "";
6671
6672       // If the fill character is "0", grouping is applied after padding.
6673       if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
6674
6675       // Reconstruct the final output based on the desired alignment.
6676       switch (align) {
6677         case "<": value = valuePrefix + value + valueSuffix + padding; break;
6678         case "=": value = valuePrefix + padding + value + valueSuffix; break;
6679         case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
6680         default: value = padding + valuePrefix + value + valueSuffix; break;
6681       }
6682
6683       return numerals(value);
6684     }
6685
6686     format.toString = function() {
6687       return specifier + "";
6688     };
6689
6690     return format;
6691   }
6692
6693   function formatPrefix(specifier, value) {
6694     var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
6695         e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
6696         k = Math.pow(10, -e),
6697         prefix = prefixes[8 + e / 3];
6698     return function(value) {
6699       return f(k * value) + prefix;
6700     };
6701   }
6702
6703   return {
6704     format: newFormat,
6705     formatPrefix: formatPrefix
6706   };
6707 };
6708
6709 var locale;
6710
6711
6712
6713 defaultLocale({
6714   decimal: ".",
6715   thousands: ",",
6716   grouping: [3],
6717   currency: ["$", ""]
6718 });
6719
6720 function defaultLocale(definition) {
6721   locale = formatLocale(definition);
6722   exports.format = locale.format;
6723   exports.formatPrefix = locale.formatPrefix;
6724   return locale;
6725 }
6726
6727 var precisionFixed = function(step) {
6728   return Math.max(0, -exponent$1(Math.abs(step)));
6729 };
6730
6731 var precisionPrefix = function(step, value) {
6732   return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
6733 };
6734
6735 var precisionRound = function(step, max) {
6736   step = Math.abs(step), max = Math.abs(max) - step;
6737   return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
6738 };
6739
6740 // Adds floating point numbers with twice the normal precision.
6741 // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
6742 // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
6743 // 305–363 (1997).
6744 // Code adapted from GeographicLib by Charles F. F. Karney,
6745 // http://geographiclib.sourceforge.net/
6746
6747 var adder = function() {
6748   return new Adder;
6749 };
6750
6751 function Adder() {
6752   this.reset();
6753 }
6754
6755 Adder.prototype = {
6756   constructor: Adder,
6757   reset: function() {
6758     this.s = // rounded value
6759     this.t = 0; // exact error
6760   },
6761   add: function(y) {
6762     add$1(temp, y, this.t);
6763     add$1(this, temp.s, this.s);
6764     if (this.s) this.t += temp.t;
6765     else this.s = temp.t;
6766   },
6767   valueOf: function() {
6768     return this.s;
6769   }
6770 };
6771
6772 var temp = new Adder;
6773
6774 function add$1(adder, a, b) {
6775   var x = adder.s = a + b,
6776       bv = x - a,
6777       av = x - bv;
6778   adder.t = (a - av) + (b - bv);
6779 }
6780
6781 var epsilon$2 = 1e-6;
6782 var epsilon2$1 = 1e-12;
6783 var pi$3 = Math.PI;
6784 var halfPi$2 = pi$3 / 2;
6785 var quarterPi = pi$3 / 4;
6786 var tau$3 = pi$3 * 2;
6787
6788 var degrees$1 = 180 / pi$3;
6789 var radians = pi$3 / 180;
6790
6791 var abs = Math.abs;
6792 var atan = Math.atan;
6793 var atan2 = Math.atan2;
6794 var cos$1 = Math.cos;
6795 var ceil = Math.ceil;
6796 var exp = Math.exp;
6797
6798 var log = Math.log;
6799 var pow = Math.pow;
6800 var sin$1 = Math.sin;
6801 var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
6802 var sqrt = Math.sqrt;
6803 var tan = Math.tan;
6804
6805 function acos(x) {
6806   return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
6807 }
6808
6809 function asin(x) {
6810   return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
6811 }
6812
6813 function haversin(x) {
6814   return (x = sin$1(x / 2)) * x;
6815 }
6816
6817 function noop$1() {}
6818
6819 function streamGeometry(geometry, stream) {
6820   if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
6821     streamGeometryType[geometry.type](geometry, stream);
6822   }
6823 }
6824
6825 var streamObjectType = {
6826   Feature: function(object, stream) {
6827     streamGeometry(object.geometry, stream);
6828   },
6829   FeatureCollection: function(object, stream) {
6830     var features = object.features, i = -1, n = features.length;
6831     while (++i < n) streamGeometry(features[i].geometry, stream);
6832   }
6833 };
6834
6835 var streamGeometryType = {
6836   Sphere: function(object, stream) {
6837     stream.sphere();
6838   },
6839   Point: function(object, stream) {
6840     object = object.coordinates;
6841     stream.point(object[0], object[1], object[2]);
6842   },
6843   MultiPoint: function(object, stream) {
6844     var coordinates = object.coordinates, i = -1, n = coordinates.length;
6845     while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
6846   },
6847   LineString: function(object, stream) {
6848     streamLine(object.coordinates, stream, 0);
6849   },
6850   MultiLineString: function(object, stream) {
6851     var coordinates = object.coordinates, i = -1, n = coordinates.length;
6852     while (++i < n) streamLine(coordinates[i], stream, 0);
6853   },
6854   Polygon: function(object, stream) {
6855     streamPolygon(object.coordinates, stream);
6856   },
6857   MultiPolygon: function(object, stream) {
6858     var coordinates = object.coordinates, i = -1, n = coordinates.length;
6859     while (++i < n) streamPolygon(coordinates[i], stream);
6860   },
6861   GeometryCollection: function(object, stream) {
6862     var geometries = object.geometries, i = -1, n = geometries.length;
6863     while (++i < n) streamGeometry(geometries[i], stream);
6864   }
6865 };
6866
6867 function streamLine(coordinates, stream, closed) {
6868   var i = -1, n = coordinates.length - closed, coordinate;
6869   stream.lineStart();
6870   while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
6871   stream.lineEnd();
6872 }
6873
6874 function streamPolygon(coordinates, stream) {
6875   var i = -1, n = coordinates.length;
6876   stream.polygonStart();
6877   while (++i < n) streamLine(coordinates[i], stream, 1);
6878   stream.polygonEnd();
6879 }
6880
6881 var geoStream = function(object, stream) {
6882   if (object && streamObjectType.hasOwnProperty(object.type)) {
6883     streamObjectType[object.type](object, stream);
6884   } else {
6885     streamGeometry(object, stream);
6886   }
6887 };
6888
6889 var areaRingSum = adder();
6890
6891 var areaSum = adder();
6892 var lambda00;
6893 var phi00;
6894 var lambda0;
6895 var cosPhi0;
6896 var sinPhi0;
6897
6898 var areaStream = {
6899   point: noop$1,
6900   lineStart: noop$1,
6901   lineEnd: noop$1,
6902   polygonStart: function() {
6903     areaRingSum.reset();
6904     areaStream.lineStart = areaRingStart;
6905     areaStream.lineEnd = areaRingEnd;
6906   },
6907   polygonEnd: function() {
6908     var areaRing = +areaRingSum;
6909     areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
6910     this.lineStart = this.lineEnd = this.point = noop$1;
6911   },
6912   sphere: function() {
6913     areaSum.add(tau$3);
6914   }
6915 };
6916
6917 function areaRingStart() {
6918   areaStream.point = areaPointFirst;
6919 }
6920
6921 function areaRingEnd() {
6922   areaPoint(lambda00, phi00);
6923 }
6924
6925 function areaPointFirst(lambda, phi) {
6926   areaStream.point = areaPoint;
6927   lambda00 = lambda, phi00 = phi;
6928   lambda *= radians, phi *= radians;
6929   lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
6930 }
6931
6932 function areaPoint(lambda, phi) {
6933   lambda *= radians, phi *= radians;
6934   phi = phi / 2 + quarterPi; // half the angular distance from south pole
6935
6936   // Spherical excess E for a spherical triangle with vertices: south pole,
6937   // previous point, current point.  Uses a formula derived from Cagnoli’s
6938   // theorem.  See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
6939   var dLambda = lambda - lambda0,
6940       sdLambda = dLambda >= 0 ? 1 : -1,
6941       adLambda = sdLambda * dLambda,
6942       cosPhi = cos$1(phi),
6943       sinPhi = sin$1(phi),
6944       k = sinPhi0 * sinPhi,
6945       u = cosPhi0 * cosPhi + k * cos$1(adLambda),
6946       v = k * sdLambda * sin$1(adLambda);
6947   areaRingSum.add(atan2(v, u));
6948
6949   // Advance the previous points.
6950   lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
6951 }
6952
6953 var area = function(object) {
6954   areaSum.reset();
6955   geoStream(object, areaStream);
6956   return areaSum * 2;
6957 };
6958
6959 function spherical(cartesian) {
6960   return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
6961 }
6962
6963 function cartesian(spherical) {
6964   var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
6965   return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
6966 }
6967
6968 function cartesianDot(a, b) {
6969   return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
6970 }
6971
6972 function cartesianCross(a, b) {
6973   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]];
6974 }
6975
6976 // TODO return a
6977 function cartesianAddInPlace(a, b) {
6978   a[0] += b[0], a[1] += b[1], a[2] += b[2];
6979 }
6980
6981 function cartesianScale(vector, k) {
6982   return [vector[0] * k, vector[1] * k, vector[2] * k];
6983 }
6984
6985 // TODO return d
6986 function cartesianNormalizeInPlace(d) {
6987   var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
6988   d[0] /= l, d[1] /= l, d[2] /= l;
6989 }
6990
6991 var lambda0$1;
6992 var phi0;
6993 var lambda1;
6994 var phi1;
6995 var lambda2;
6996 var lambda00$1;
6997 var phi00$1;
6998 var p0;
6999 var deltaSum = adder();
7000 var ranges;
7001 var range;
7002
7003 var boundsStream = {
7004   point: boundsPoint,
7005   lineStart: boundsLineStart,
7006   lineEnd: boundsLineEnd,
7007   polygonStart: function() {
7008     boundsStream.point = boundsRingPoint;
7009     boundsStream.lineStart = boundsRingStart;
7010     boundsStream.lineEnd = boundsRingEnd;
7011     deltaSum.reset();
7012     areaStream.polygonStart();
7013   },
7014   polygonEnd: function() {
7015     areaStream.polygonEnd();
7016     boundsStream.point = boundsPoint;
7017     boundsStream.lineStart = boundsLineStart;
7018     boundsStream.lineEnd = boundsLineEnd;
7019     if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
7020     else if (deltaSum > epsilon$2) phi1 = 90;
7021     else if (deltaSum < -epsilon$2) phi0 = -90;
7022     range[0] = lambda0$1, range[1] = lambda1;
7023   }
7024 };
7025
7026 function boundsPoint(lambda, phi) {
7027   ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7028   if (phi < phi0) phi0 = phi;
7029   if (phi > phi1) phi1 = phi;
7030 }
7031
7032 function linePoint(lambda, phi) {
7033   var p = cartesian([lambda * radians, phi * radians]);
7034   if (p0) {
7035     var normal = cartesianCross(p0, p),
7036         equatorial = [normal[1], -normal[0], 0],
7037         inflection = cartesianCross(equatorial, normal);
7038     cartesianNormalizeInPlace(inflection);
7039     inflection = spherical(inflection);
7040     var delta = lambda - lambda2,
7041         sign$$1 = delta > 0 ? 1 : -1,
7042         lambdai = inflection[0] * degrees$1 * sign$$1,
7043         phii,
7044         antimeridian = abs(delta) > 180;
7045     if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7046       phii = inflection[1] * degrees$1;
7047       if (phii > phi1) phi1 = phii;
7048     } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7049       phii = -inflection[1] * degrees$1;
7050       if (phii < phi0) phi0 = phii;
7051     } else {
7052       if (phi < phi0) phi0 = phi;
7053       if (phi > phi1) phi1 = phi;
7054     }
7055     if (antimeridian) {
7056       if (lambda < lambda2) {
7057         if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7058       } else {
7059         if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7060       }
7061     } else {
7062       if (lambda1 >= lambda0$1) {
7063         if (lambda < lambda0$1) lambda0$1 = lambda;
7064         if (lambda > lambda1) lambda1 = lambda;
7065       } else {
7066         if (lambda > lambda2) {
7067           if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7068         } else {
7069           if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7070         }
7071       }
7072     }
7073   } else {
7074     ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7075   }
7076   if (phi < phi0) phi0 = phi;
7077   if (phi > phi1) phi1 = phi;
7078   p0 = p, lambda2 = lambda;
7079 }
7080
7081 function boundsLineStart() {
7082   boundsStream.point = linePoint;
7083 }
7084
7085 function boundsLineEnd() {
7086   range[0] = lambda0$1, range[1] = lambda1;
7087   boundsStream.point = boundsPoint;
7088   p0 = null;
7089 }
7090
7091 function boundsRingPoint(lambda, phi) {
7092   if (p0) {
7093     var delta = lambda - lambda2;
7094     deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
7095   } else {
7096     lambda00$1 = lambda, phi00$1 = phi;
7097   }
7098   areaStream.point(lambda, phi);
7099   linePoint(lambda, phi);
7100 }
7101
7102 function boundsRingStart() {
7103   areaStream.lineStart();
7104 }
7105
7106 function boundsRingEnd() {
7107   boundsRingPoint(lambda00$1, phi00$1);
7108   areaStream.lineEnd();
7109   if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
7110   range[0] = lambda0$1, range[1] = lambda1;
7111   p0 = null;
7112 }
7113
7114 // Finds the left-right distance between two longitudes.
7115 // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
7116 // the distance between ±180° to be 360°.
7117 function angle(lambda0, lambda1) {
7118   return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
7119 }
7120
7121 function rangeCompare(a, b) {
7122   return a[0] - b[0];
7123 }
7124
7125 function rangeContains(range, x) {
7126   return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
7127 }
7128
7129 var bounds = function(feature) {
7130   var i, n, a, b, merged, deltaMax, delta;
7131
7132   phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
7133   ranges = [];
7134   geoStream(feature, boundsStream);
7135
7136   // First, sort ranges by their minimum longitudes.
7137   if (n = ranges.length) {
7138     ranges.sort(rangeCompare);
7139
7140     // Then, merge any ranges that overlap.
7141     for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
7142       b = ranges[i];
7143       if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
7144         if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
7145         if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
7146       } else {
7147         merged.push(a = b);
7148       }
7149     }
7150
7151     // Finally, find the largest gap between the merged ranges.
7152     // The final bounding box will be the inverse of this gap.
7153     for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
7154       b = merged[i];
7155       if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
7156     }
7157   }
7158
7159   ranges = range = null;
7160
7161   return lambda0$1 === Infinity || phi0 === Infinity
7162       ? [[NaN, NaN], [NaN, NaN]]
7163       : [[lambda0$1, phi0], [lambda1, phi1]];
7164 };
7165
7166 var W0;
7167 var W1;
7168 var X0;
7169 var Y0;
7170 var Z0;
7171 var X1;
7172 var Y1;
7173 var Z1;
7174 var X2;
7175 var Y2;
7176 var Z2;
7177 var lambda00$2;
7178 var phi00$2;
7179 var x0;
7180 var y0;
7181 var z0; // previous point
7182
7183 var centroidStream = {
7184   sphere: noop$1,
7185   point: centroidPoint,
7186   lineStart: centroidLineStart,
7187   lineEnd: centroidLineEnd,
7188   polygonStart: function() {
7189     centroidStream.lineStart = centroidRingStart;
7190     centroidStream.lineEnd = centroidRingEnd;
7191   },
7192   polygonEnd: function() {
7193     centroidStream.lineStart = centroidLineStart;
7194     centroidStream.lineEnd = centroidLineEnd;
7195   }
7196 };
7197
7198 // Arithmetic mean of Cartesian vectors.
7199 function centroidPoint(lambda, phi) {
7200   lambda *= radians, phi *= radians;
7201   var cosPhi = cos$1(phi);
7202   centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
7203 }
7204
7205 function centroidPointCartesian(x, y, z) {
7206   ++W0;
7207   X0 += (x - X0) / W0;
7208   Y0 += (y - Y0) / W0;
7209   Z0 += (z - Z0) / W0;
7210 }
7211
7212 function centroidLineStart() {
7213   centroidStream.point = centroidLinePointFirst;
7214 }
7215
7216 function centroidLinePointFirst(lambda, phi) {
7217   lambda *= radians, phi *= radians;
7218   var cosPhi = cos$1(phi);
7219   x0 = cosPhi * cos$1(lambda);
7220   y0 = cosPhi * sin$1(lambda);
7221   z0 = sin$1(phi);
7222   centroidStream.point = centroidLinePoint;
7223   centroidPointCartesian(x0, y0, z0);
7224 }
7225
7226 function centroidLinePoint(lambda, phi) {
7227   lambda *= radians, phi *= radians;
7228   var cosPhi = cos$1(phi),
7229       x = cosPhi * cos$1(lambda),
7230       y = cosPhi * sin$1(lambda),
7231       z = sin$1(phi),
7232       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);
7233   W1 += w;
7234   X1 += w * (x0 + (x0 = x));
7235   Y1 += w * (y0 + (y0 = y));
7236   Z1 += w * (z0 + (z0 = z));
7237   centroidPointCartesian(x0, y0, z0);
7238 }
7239
7240 function centroidLineEnd() {
7241   centroidStream.point = centroidPoint;
7242 }
7243
7244 // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
7245 // J. Applied Mechanics 42, 239 (1975).
7246 function centroidRingStart() {
7247   centroidStream.point = centroidRingPointFirst;
7248 }
7249
7250 function centroidRingEnd() {
7251   centroidRingPoint(lambda00$2, phi00$2);
7252   centroidStream.point = centroidPoint;
7253 }
7254
7255 function centroidRingPointFirst(lambda, phi) {
7256   lambda00$2 = lambda, phi00$2 = phi;
7257   lambda *= radians, phi *= radians;
7258   centroidStream.point = centroidRingPoint;
7259   var cosPhi = cos$1(phi);
7260   x0 = cosPhi * cos$1(lambda);
7261   y0 = cosPhi * sin$1(lambda);
7262   z0 = sin$1(phi);
7263   centroidPointCartesian(x0, y0, z0);
7264 }
7265
7266 function centroidRingPoint(lambda, phi) {
7267   lambda *= radians, phi *= radians;
7268   var cosPhi = cos$1(phi),
7269       x = cosPhi * cos$1(lambda),
7270       y = cosPhi * sin$1(lambda),
7271       z = sin$1(phi),
7272       cx = y0 * z - z0 * y,
7273       cy = z0 * x - x0 * z,
7274       cz = x0 * y - y0 * x,
7275       m = sqrt(cx * cx + cy * cy + cz * cz),
7276       w = asin(m), // line weight = angle
7277       v = m && -w / m; // area weight multiplier
7278   X2 += v * cx;
7279   Y2 += v * cy;
7280   Z2 += v * cz;
7281   W1 += w;
7282   X1 += w * (x0 + (x0 = x));
7283   Y1 += w * (y0 + (y0 = y));
7284   Z1 += w * (z0 + (z0 = z));
7285   centroidPointCartesian(x0, y0, z0);
7286 }
7287
7288 var centroid = function(object) {
7289   W0 = W1 =
7290   X0 = Y0 = Z0 =
7291   X1 = Y1 = Z1 =
7292   X2 = Y2 = Z2 = 0;
7293   geoStream(object, centroidStream);
7294
7295   var x = X2,
7296       y = Y2,
7297       z = Z2,
7298       m = x * x + y * y + z * z;
7299
7300   // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
7301   if (m < epsilon2$1) {
7302     x = X1, y = Y1, z = Z1;
7303     // If the feature has zero length, fall back to arithmetic mean of point vectors.
7304     if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
7305     m = x * x + y * y + z * z;
7306     // If the feature still has an undefined ccentroid, then return.
7307     if (m < epsilon2$1) return [NaN, NaN];
7308   }
7309
7310   return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
7311 };
7312
7313 var constant$7 = function(x) {
7314   return function() {
7315     return x;
7316   };
7317 };
7318
7319 var compose = function(a, b) {
7320
7321   function compose(x, y) {
7322     return x = a(x, y), b(x[0], x[1]);
7323   }
7324
7325   if (a.invert && b.invert) compose.invert = function(x, y) {
7326     return x = b.invert(x, y), x && a.invert(x[0], x[1]);
7327   };
7328
7329   return compose;
7330 };
7331
7332 function rotationIdentity(lambda, phi) {
7333   return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7334 }
7335
7336 rotationIdentity.invert = rotationIdentity;
7337
7338 function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
7339   return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
7340     : rotationLambda(deltaLambda))
7341     : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
7342     : rotationIdentity);
7343 }
7344
7345 function forwardRotationLambda(deltaLambda) {
7346   return function(lambda, phi) {
7347     return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7348   };
7349 }
7350
7351 function rotationLambda(deltaLambda) {
7352   var rotation = forwardRotationLambda(deltaLambda);
7353   rotation.invert = forwardRotationLambda(-deltaLambda);
7354   return rotation;
7355 }
7356
7357 function rotationPhiGamma(deltaPhi, deltaGamma) {
7358   var cosDeltaPhi = cos$1(deltaPhi),
7359       sinDeltaPhi = sin$1(deltaPhi),
7360       cosDeltaGamma = cos$1(deltaGamma),
7361       sinDeltaGamma = sin$1(deltaGamma);
7362
7363   function rotation(lambda, phi) {
7364     var cosPhi = cos$1(phi),
7365         x = cos$1(lambda) * cosPhi,
7366         y = sin$1(lambda) * cosPhi,
7367         z = sin$1(phi),
7368         k = z * cosDeltaPhi + x * sinDeltaPhi;
7369     return [
7370       atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
7371       asin(k * cosDeltaGamma + y * sinDeltaGamma)
7372     ];
7373   }
7374
7375   rotation.invert = function(lambda, phi) {
7376     var cosPhi = cos$1(phi),
7377         x = cos$1(lambda) * cosPhi,
7378         y = sin$1(lambda) * cosPhi,
7379         z = sin$1(phi),
7380         k = z * cosDeltaGamma - y * sinDeltaGamma;
7381     return [
7382       atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
7383       asin(k * cosDeltaPhi - x * sinDeltaPhi)
7384     ];
7385   };
7386
7387   return rotation;
7388 }
7389
7390 var rotation = function(rotate) {
7391   rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
7392
7393   function forward(coordinates) {
7394     coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
7395     return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7396   }
7397
7398   forward.invert = function(coordinates) {
7399     coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
7400     return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7401   };
7402
7403   return forward;
7404 };
7405
7406 // Generates a circle centered at [0°, 0°], with a given radius and precision.
7407 function circleStream(stream, radius, delta, direction, t0, t1) {
7408   if (!delta) return;
7409   var cosRadius = cos$1(radius),
7410       sinRadius = sin$1(radius),
7411       step = direction * delta;
7412   if (t0 == null) {
7413     t0 = radius + direction * tau$3;
7414     t1 = radius - step / 2;
7415   } else {
7416     t0 = circleRadius(cosRadius, t0);
7417     t1 = circleRadius(cosRadius, t1);
7418     if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
7419   }
7420   for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
7421     point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
7422     stream.point(point[0], point[1]);
7423   }
7424 }
7425
7426 // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
7427 function circleRadius(cosRadius, point) {
7428   point = cartesian(point), point[0] -= cosRadius;
7429   cartesianNormalizeInPlace(point);
7430   var radius = acos(-point[1]);
7431   return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
7432 }
7433
7434 var circle = function() {
7435   var center = constant$7([0, 0]),
7436       radius = constant$7(90),
7437       precision = constant$7(6),
7438       ring,
7439       rotate,
7440       stream = {point: point};
7441
7442   function point(x, y) {
7443     ring.push(x = rotate(x, y));
7444     x[0] *= degrees$1, x[1] *= degrees$1;
7445   }
7446
7447   function circle() {
7448     var c = center.apply(this, arguments),
7449         r = radius.apply(this, arguments) * radians,
7450         p = precision.apply(this, arguments) * radians;
7451     ring = [];
7452     rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
7453     circleStream(stream, r, p, 1);
7454     c = {type: "Polygon", coordinates: [ring]};
7455     ring = rotate = null;
7456     return c;
7457   }
7458
7459   circle.center = function(_) {
7460     return arguments.length ? (center = typeof _ === "function" ? _ : constant$7([+_[0], +_[1]]), circle) : center;
7461   };
7462
7463   circle.radius = function(_) {
7464     return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), circle) : radius;
7465   };
7466
7467   circle.precision = function(_) {
7468     return arguments.length ? (precision = typeof _ === "function" ? _ : constant$7(+_), circle) : precision;
7469   };
7470
7471   return circle;
7472 };
7473
7474 var clipBuffer = function() {
7475   var lines = [],
7476       line;
7477   return {
7478     point: function(x, y) {
7479       line.push([x, y]);
7480     },
7481     lineStart: function() {
7482       lines.push(line = []);
7483     },
7484     lineEnd: noop$1,
7485     rejoin: function() {
7486       if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
7487     },
7488     result: function() {
7489       var result = lines;
7490       lines = [];
7491       line = null;
7492       return result;
7493     }
7494   };
7495 };
7496
7497 var pointEqual = function(a, b) {
7498   return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
7499 };
7500
7501 function Intersection(point, points, other, entry) {
7502   this.x = point;
7503   this.z = points;
7504   this.o = other; // another intersection
7505   this.e = entry; // is an entry?
7506   this.v = false; // visited
7507   this.n = this.p = null; // next & previous
7508 }
7509
7510 // A generalized polygon clipping algorithm: given a polygon that has been cut
7511 // into its visible line segments, and rejoins the segments by interpolating
7512 // along the clip edge.
7513 var clipRejoin = function(segments, compareIntersection, startInside, interpolate, stream) {
7514   var subject = [],
7515       clip = [],
7516       i,
7517       n;
7518
7519   segments.forEach(function(segment) {
7520     if ((n = segment.length - 1) <= 0) return;
7521     var n, p0 = segment[0], p1 = segment[n], x;
7522
7523     // If the first and last points of a segment are coincident, then treat as a
7524     // closed ring. TODO if all rings are closed, then the winding order of the
7525     // exterior ring should be checked.
7526     if (pointEqual(p0, p1)) {
7527       stream.lineStart();
7528       for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
7529       stream.lineEnd();
7530       return;
7531     }
7532
7533     subject.push(x = new Intersection(p0, segment, null, true));
7534     clip.push(x.o = new Intersection(p0, null, x, false));
7535     subject.push(x = new Intersection(p1, segment, null, false));
7536     clip.push(x.o = new Intersection(p1, null, x, true));
7537   });
7538
7539   if (!subject.length) return;
7540
7541   clip.sort(compareIntersection);
7542   link$1(subject);
7543   link$1(clip);
7544
7545   for (i = 0, n = clip.length; i < n; ++i) {
7546     clip[i].e = startInside = !startInside;
7547   }
7548
7549   var start = subject[0],
7550       points,
7551       point;
7552
7553   while (1) {
7554     // Find first unvisited intersection.
7555     var current = start,
7556         isSubject = true;
7557     while (current.v) if ((current = current.n) === start) return;
7558     points = current.z;
7559     stream.lineStart();
7560     do {
7561       current.v = current.o.v = true;
7562       if (current.e) {
7563         if (isSubject) {
7564           for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
7565         } else {
7566           interpolate(current.x, current.n.x, 1, stream);
7567         }
7568         current = current.n;
7569       } else {
7570         if (isSubject) {
7571           points = current.p.z;
7572           for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
7573         } else {
7574           interpolate(current.x, current.p.x, -1, stream);
7575         }
7576         current = current.p;
7577       }
7578       current = current.o;
7579       points = current.z;
7580       isSubject = !isSubject;
7581     } while (!current.v);
7582     stream.lineEnd();
7583   }
7584 };
7585
7586 function link$1(array) {
7587   if (!(n = array.length)) return;
7588   var n,
7589       i = 0,
7590       a = array[0],
7591       b;
7592   while (++i < n) {
7593     a.n = b = array[i];
7594     b.p = a;
7595     a = b;
7596   }
7597   a.n = b = array[0];
7598   b.p = a;
7599 }
7600
7601 var sum$1 = adder();
7602
7603 var polygonContains = function(polygon, point) {
7604   var lambda = point[0],
7605       phi = point[1],
7606       normal = [sin$1(lambda), -cos$1(lambda), 0],
7607       angle = 0,
7608       winding = 0;
7609
7610   sum$1.reset();
7611
7612   for (var i = 0, n = polygon.length; i < n; ++i) {
7613     if (!(m = (ring = polygon[i]).length)) continue;
7614     var ring,
7615         m,
7616         point0 = ring[m - 1],
7617         lambda0 = point0[0],
7618         phi0 = point0[1] / 2 + quarterPi,
7619         sinPhi0 = sin$1(phi0),
7620         cosPhi0 = cos$1(phi0);
7621
7622     for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
7623       var point1 = ring[j],
7624           lambda1 = point1[0],
7625           phi1 = point1[1] / 2 + quarterPi,
7626           sinPhi1 = sin$1(phi1),
7627           cosPhi1 = cos$1(phi1),
7628           delta = lambda1 - lambda0,
7629           sign$$1 = delta >= 0 ? 1 : -1,
7630           absDelta = sign$$1 * delta,
7631           antimeridian = absDelta > pi$3,
7632           k = sinPhi0 * sinPhi1;
7633
7634       sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
7635       angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
7636
7637       // Are the longitudes either side of the point’s meridian (lambda),
7638       // and are the latitudes smaller than the parallel (phi)?
7639       if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
7640         var arc = cartesianCross(cartesian(point0), cartesian(point1));
7641         cartesianNormalizeInPlace(arc);
7642         var intersection = cartesianCross(normal, arc);
7643         cartesianNormalizeInPlace(intersection);
7644         var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
7645         if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
7646           winding += antimeridian ^ delta >= 0 ? 1 : -1;
7647         }
7648       }
7649     }
7650   }
7651
7652   // First, determine whether the South pole is inside or outside:
7653   //
7654   // It is inside if:
7655   // * the polygon winds around it in a clockwise direction.
7656   // * the polygon does not (cumulatively) wind around it, but has a negative
7657   //   (counter-clockwise) area.
7658   //
7659   // Second, count the (signed) number of times a segment crosses a lambda
7660   // from the point to the South pole.  If it is zero, then the point is the
7661   // same side as the South pole.
7662
7663   return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
7664 };
7665
7666 var clip = function(pointVisible, clipLine, interpolate, start) {
7667   return function(sink) {
7668     var line = clipLine(sink),
7669         ringBuffer = clipBuffer(),
7670         ringSink = clipLine(ringBuffer),
7671         polygonStarted = false,
7672         polygon,
7673         segments,
7674         ring;
7675
7676     var clip = {
7677       point: point,
7678       lineStart: lineStart,
7679       lineEnd: lineEnd,
7680       polygonStart: function() {
7681         clip.point = pointRing;
7682         clip.lineStart = ringStart;
7683         clip.lineEnd = ringEnd;
7684         segments = [];
7685         polygon = [];
7686       },
7687       polygonEnd: function() {
7688         clip.point = point;
7689         clip.lineStart = lineStart;
7690         clip.lineEnd = lineEnd;
7691         segments = merge(segments);
7692         var startInside = polygonContains(polygon, start);
7693         if (segments.length) {
7694           if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
7695           clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
7696         } else if (startInside) {
7697           if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
7698           sink.lineStart();
7699           interpolate(null, null, 1, sink);
7700           sink.lineEnd();
7701         }
7702         if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
7703         segments = polygon = null;
7704       },
7705       sphere: function() {
7706         sink.polygonStart();
7707         sink.lineStart();
7708         interpolate(null, null, 1, sink);
7709         sink.lineEnd();
7710         sink.polygonEnd();
7711       }
7712     };
7713
7714     function point(lambda, phi) {
7715       if (pointVisible(lambda, phi)) sink.point(lambda, phi);
7716     }
7717
7718     function pointLine(lambda, phi) {
7719       line.point(lambda, phi);
7720     }
7721
7722     function lineStart() {
7723       clip.point = pointLine;
7724       line.lineStart();
7725     }
7726
7727     function lineEnd() {
7728       clip.point = point;
7729       line.lineEnd();
7730     }
7731
7732     function pointRing(lambda, phi) {
7733       ring.push([lambda, phi]);
7734       ringSink.point(lambda, phi);
7735     }
7736
7737     function ringStart() {
7738       ringSink.lineStart();
7739       ring = [];
7740     }
7741
7742     function ringEnd() {
7743       pointRing(ring[0][0], ring[0][1]);
7744       ringSink.lineEnd();
7745
7746       var clean = ringSink.clean(),
7747           ringSegments = ringBuffer.result(),
7748           i, n = ringSegments.length, m,
7749           segment,
7750           point;
7751
7752       ring.pop();
7753       polygon.push(ring);
7754       ring = null;
7755
7756       if (!n) return;
7757
7758       // No intersections.
7759       if (clean & 1) {
7760         segment = ringSegments[0];
7761         if ((m = segment.length - 1) > 0) {
7762           if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
7763           sink.lineStart();
7764           for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
7765           sink.lineEnd();
7766         }
7767         return;
7768       }
7769
7770       // Rejoin connected segments.
7771       // TODO reuse ringBuffer.rejoin()?
7772       if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
7773
7774       segments.push(ringSegments.filter(validSegment));
7775     }
7776
7777     return clip;
7778   };
7779 };
7780
7781 function validSegment(segment) {
7782   return segment.length > 1;
7783 }
7784
7785 // Intersections are sorted along the clip edge. For both antimeridian cutting
7786 // and circle clipping, the same comparison is used.
7787 function compareIntersection(a, b) {
7788   return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
7789        - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
7790 }
7791
7792 var clipAntimeridian = clip(
7793   function() { return true; },
7794   clipAntimeridianLine,
7795   clipAntimeridianInterpolate,
7796   [-pi$3, -halfPi$2]
7797 );
7798
7799 // Takes a line and cuts into visible segments. Return values: 0 - there were
7800 // intersections or the line was empty; 1 - no intersections; 2 - there were
7801 // intersections, and the first and last segments should be rejoined.
7802 function clipAntimeridianLine(stream) {
7803   var lambda0 = NaN,
7804       phi0 = NaN,
7805       sign0 = NaN,
7806       clean; // no intersections
7807
7808   return {
7809     lineStart: function() {
7810       stream.lineStart();
7811       clean = 1;
7812     },
7813     point: function(lambda1, phi1) {
7814       var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
7815           delta = abs(lambda1 - lambda0);
7816       if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
7817         stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
7818         stream.point(sign0, phi0);
7819         stream.lineEnd();
7820         stream.lineStart();
7821         stream.point(sign1, phi0);
7822         stream.point(lambda1, phi0);
7823         clean = 0;
7824       } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
7825         if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
7826         if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
7827         phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
7828         stream.point(sign0, phi0);
7829         stream.lineEnd();
7830         stream.lineStart();
7831         stream.point(sign1, phi0);
7832         clean = 0;
7833       }
7834       stream.point(lambda0 = lambda1, phi0 = phi1);
7835       sign0 = sign1;
7836     },
7837     lineEnd: function() {
7838       stream.lineEnd();
7839       lambda0 = phi0 = NaN;
7840     },
7841     clean: function() {
7842       return 2 - clean; // if intersections, rejoin first and last segments
7843     }
7844   };
7845 }
7846
7847 function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
7848   var cosPhi0,
7849       cosPhi1,
7850       sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
7851   return abs(sinLambda0Lambda1) > epsilon$2
7852       ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
7853           - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
7854           / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
7855       : (phi0 + phi1) / 2;
7856 }
7857
7858 function clipAntimeridianInterpolate(from, to, direction, stream) {
7859   var phi;
7860   if (from == null) {
7861     phi = direction * halfPi$2;
7862     stream.point(-pi$3, phi);
7863     stream.point(0, phi);
7864     stream.point(pi$3, phi);
7865     stream.point(pi$3, 0);
7866     stream.point(pi$3, -phi);
7867     stream.point(0, -phi);
7868     stream.point(-pi$3, -phi);
7869     stream.point(-pi$3, 0);
7870     stream.point(-pi$3, phi);
7871   } else if (abs(from[0] - to[0]) > epsilon$2) {
7872     var lambda = from[0] < to[0] ? pi$3 : -pi$3;
7873     phi = direction * lambda / 2;
7874     stream.point(-lambda, phi);
7875     stream.point(0, phi);
7876     stream.point(lambda, phi);
7877   } else {
7878     stream.point(to[0], to[1]);
7879   }
7880 }
7881
7882 var clipCircle = function(radius) {
7883   var cr = cos$1(radius),
7884       delta = 6 * radians,
7885       smallRadius = cr > 0,
7886       notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
7887
7888   function interpolate(from, to, direction, stream) {
7889     circleStream(stream, radius, delta, direction, from, to);
7890   }
7891
7892   function visible(lambda, phi) {
7893     return cos$1(lambda) * cos$1(phi) > cr;
7894   }
7895
7896   // Takes a line and cuts into visible segments. Return values used for polygon
7897   // clipping: 0 - there were intersections or the line was empty; 1 - no
7898   // intersections 2 - there were intersections, and the first and last segments
7899   // should be rejoined.
7900   function clipLine(stream) {
7901     var point0, // previous point
7902         c0, // code for previous point
7903         v0, // visibility of previous point
7904         v00, // visibility of first point
7905         clean; // no intersections
7906     return {
7907       lineStart: function() {
7908         v00 = v0 = false;
7909         clean = 1;
7910       },
7911       point: function(lambda, phi) {
7912         var point1 = [lambda, phi],
7913             point2,
7914             v = visible(lambda, phi),
7915             c = smallRadius
7916               ? v ? 0 : code(lambda, phi)
7917               : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
7918         if (!point0 && (v00 = v0 = v)) stream.lineStart();
7919         // Handle degeneracies.
7920         // TODO ignore if not clipping polygons.
7921         if (v !== v0) {
7922           point2 = intersect(point0, point1);
7923           if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
7924             point1[0] += epsilon$2;
7925             point1[1] += epsilon$2;
7926             v = visible(point1[0], point1[1]);
7927           }
7928         }
7929         if (v !== v0) {
7930           clean = 0;
7931           if (v) {
7932             // outside going in
7933             stream.lineStart();
7934             point2 = intersect(point1, point0);
7935             stream.point(point2[0], point2[1]);
7936           } else {
7937             // inside going out
7938             point2 = intersect(point0, point1);
7939             stream.point(point2[0], point2[1]);
7940             stream.lineEnd();
7941           }
7942           point0 = point2;
7943         } else if (notHemisphere && point0 && smallRadius ^ v) {
7944           var t;
7945           // If the codes for two points are different, or are both zero,
7946           // and there this segment intersects with the small circle.
7947           if (!(c & c0) && (t = intersect(point1, point0, true))) {
7948             clean = 0;
7949             if (smallRadius) {
7950               stream.lineStart();
7951               stream.point(t[0][0], t[0][1]);
7952               stream.point(t[1][0], t[1][1]);
7953               stream.lineEnd();
7954             } else {
7955               stream.point(t[1][0], t[1][1]);
7956               stream.lineEnd();
7957               stream.lineStart();
7958               stream.point(t[0][0], t[0][1]);
7959             }
7960           }
7961         }
7962         if (v && (!point0 || !pointEqual(point0, point1))) {
7963           stream.point(point1[0], point1[1]);
7964         }
7965         point0 = point1, v0 = v, c0 = c;
7966       },
7967       lineEnd: function() {
7968         if (v0) stream.lineEnd();
7969         point0 = null;
7970       },
7971       // Rejoin first and last segments if there were intersections and the first
7972       // and last points were visible.
7973       clean: function() {
7974         return clean | ((v00 && v0) << 1);
7975       }
7976     };
7977   }
7978
7979   // Intersects the great circle between a and b with the clip circle.
7980   function intersect(a, b, two) {
7981     var pa = cartesian(a),
7982         pb = cartesian(b);
7983
7984     // We have two planes, n1.p = d1 and n2.p = d2.
7985     // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
7986     var n1 = [1, 0, 0], // normal
7987         n2 = cartesianCross(pa, pb),
7988         n2n2 = cartesianDot(n2, n2),
7989         n1n2 = n2[0], // cartesianDot(n1, n2),
7990         determinant = n2n2 - n1n2 * n1n2;
7991
7992     // Two polar points.
7993     if (!determinant) return !two && a;
7994
7995     var c1 =  cr * n2n2 / determinant,
7996         c2 = -cr * n1n2 / determinant,
7997         n1xn2 = cartesianCross(n1, n2),
7998         A = cartesianScale(n1, c1),
7999         B = cartesianScale(n2, c2);
8000     cartesianAddInPlace(A, B);
8001
8002     // Solve |p(t)|^2 = 1.
8003     var u = n1xn2,
8004         w = cartesianDot(A, u),
8005         uu = cartesianDot(u, u),
8006         t2 = w * w - uu * (cartesianDot(A, A) - 1);
8007
8008     if (t2 < 0) return;
8009
8010     var t = sqrt(t2),
8011         q = cartesianScale(u, (-w - t) / uu);
8012     cartesianAddInPlace(q, A);
8013     q = spherical(q);
8014
8015     if (!two) return q;
8016
8017     // Two intersection points.
8018     var lambda0 = a[0],
8019         lambda1 = b[0],
8020         phi0 = a[1],
8021         phi1 = b[1],
8022         z;
8023
8024     if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
8025
8026     var delta = lambda1 - lambda0,
8027         polar = abs(delta - pi$3) < epsilon$2,
8028         meridian = polar || delta < epsilon$2;
8029
8030     if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
8031
8032     // Check that the first point is between a and b.
8033     if (meridian
8034         ? polar
8035           ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
8036           : phi0 <= q[1] && q[1] <= phi1
8037         : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
8038       var q1 = cartesianScale(u, (-w + t) / uu);
8039       cartesianAddInPlace(q1, A);
8040       return [q, spherical(q1)];
8041     }
8042   }
8043
8044   // Generates a 4-bit vector representing the location of a point relative to
8045   // the small circle's bounding box.
8046   function code(lambda, phi) {
8047     var r = smallRadius ? radius : pi$3 - radius,
8048         code = 0;
8049     if (lambda < -r) code |= 1; // left
8050     else if (lambda > r) code |= 2; // right
8051     if (phi < -r) code |= 4; // below
8052     else if (phi > r) code |= 8; // above
8053     return code;
8054   }
8055
8056   return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
8057 };
8058
8059 var clipLine = function(a, b, x0, y0, x1, y1) {
8060   var ax = a[0],
8061       ay = a[1],
8062       bx = b[0],
8063       by = b[1],
8064       t0 = 0,
8065       t1 = 1,
8066       dx = bx - ax,
8067       dy = by - ay,
8068       r;
8069
8070   r = x0 - ax;
8071   if (!dx && r > 0) return;
8072   r /= dx;
8073   if (dx < 0) {
8074     if (r < t0) return;
8075     if (r < t1) t1 = r;
8076   } else if (dx > 0) {
8077     if (r > t1) return;
8078     if (r > t0) t0 = r;
8079   }
8080
8081   r = x1 - ax;
8082   if (!dx && r < 0) return;
8083   r /= dx;
8084   if (dx < 0) {
8085     if (r > t1) return;
8086     if (r > t0) t0 = r;
8087   } else if (dx > 0) {
8088     if (r < t0) return;
8089     if (r < t1) t1 = r;
8090   }
8091
8092   r = y0 - ay;
8093   if (!dy && r > 0) return;
8094   r /= dy;
8095   if (dy < 0) {
8096     if (r < t0) return;
8097     if (r < t1) t1 = r;
8098   } else if (dy > 0) {
8099     if (r > t1) return;
8100     if (r > t0) t0 = r;
8101   }
8102
8103   r = y1 - ay;
8104   if (!dy && r < 0) return;
8105   r /= dy;
8106   if (dy < 0) {
8107     if (r > t1) return;
8108     if (r > t0) t0 = r;
8109   } else if (dy > 0) {
8110     if (r < t0) return;
8111     if (r < t1) t1 = r;
8112   }
8113
8114   if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
8115   if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
8116   return true;
8117 };
8118
8119 var clipMax = 1e9;
8120 var clipMin = -clipMax;
8121
8122 // TODO Use d3-polygon’s polygonContains here for the ring check?
8123 // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
8124
8125 function clipRectangle(x0, y0, x1, y1) {
8126
8127   function visible(x, y) {
8128     return x0 <= x && x <= x1 && y0 <= y && y <= y1;
8129   }
8130
8131   function interpolate(from, to, direction, stream) {
8132     var a = 0, a1 = 0;
8133     if (from == null
8134         || (a = corner(from, direction)) !== (a1 = corner(to, direction))
8135         || comparePoint(from, to) < 0 ^ direction > 0) {
8136       do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
8137       while ((a = (a + direction + 4) % 4) !== a1);
8138     } else {
8139       stream.point(to[0], to[1]);
8140     }
8141   }
8142
8143   function corner(p, direction) {
8144     return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
8145         : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
8146         : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
8147         : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
8148   }
8149
8150   function compareIntersection(a, b) {
8151     return comparePoint(a.x, b.x);
8152   }
8153
8154   function comparePoint(a, b) {
8155     var ca = corner(a, 1),
8156         cb = corner(b, 1);
8157     return ca !== cb ? ca - cb
8158         : ca === 0 ? b[1] - a[1]
8159         : ca === 1 ? a[0] - b[0]
8160         : ca === 2 ? a[1] - b[1]
8161         : b[0] - a[0];
8162   }
8163
8164   return function(stream) {
8165     var activeStream = stream,
8166         bufferStream = clipBuffer(),
8167         segments,
8168         polygon,
8169         ring,
8170         x__, y__, v__, // first point
8171         x_, y_, v_, // previous point
8172         first,
8173         clean;
8174
8175     var clipStream = {
8176       point: point,
8177       lineStart: lineStart,
8178       lineEnd: lineEnd,
8179       polygonStart: polygonStart,
8180       polygonEnd: polygonEnd
8181     };
8182
8183     function point(x, y) {
8184       if (visible(x, y)) activeStream.point(x, y);
8185     }
8186
8187     function polygonInside() {
8188       var winding = 0;
8189
8190       for (var i = 0, n = polygon.length; i < n; ++i) {
8191         for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
8192           a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
8193           if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
8194           else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
8195         }
8196       }
8197
8198       return winding;
8199     }
8200
8201     // Buffer geometry within a polygon and then clip it en masse.
8202     function polygonStart() {
8203       activeStream = bufferStream, segments = [], polygon = [], clean = true;
8204     }
8205
8206     function polygonEnd() {
8207       var startInside = polygonInside(),
8208           cleanInside = clean && startInside,
8209           visible = (segments = merge(segments)).length;
8210       if (cleanInside || visible) {
8211         stream.polygonStart();
8212         if (cleanInside) {
8213           stream.lineStart();
8214           interpolate(null, null, 1, stream);
8215           stream.lineEnd();
8216         }
8217         if (visible) {
8218           clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
8219         }
8220         stream.polygonEnd();
8221       }
8222       activeStream = stream, segments = polygon = ring = null;
8223     }
8224
8225     function lineStart() {
8226       clipStream.point = linePoint;
8227       if (polygon) polygon.push(ring = []);
8228       first = true;
8229       v_ = false;
8230       x_ = y_ = NaN;
8231     }
8232
8233     // TODO rather than special-case polygons, simply handle them separately.
8234     // Ideally, coincident intersection points should be jittered to avoid
8235     // clipping issues.
8236     function lineEnd() {
8237       if (segments) {
8238         linePoint(x__, y__);
8239         if (v__ && v_) bufferStream.rejoin();
8240         segments.push(bufferStream.result());
8241       }
8242       clipStream.point = point;
8243       if (v_) activeStream.lineEnd();
8244     }
8245
8246     function linePoint(x, y) {
8247       var v = visible(x, y);
8248       if (polygon) ring.push([x, y]);
8249       if (first) {
8250         x__ = x, y__ = y, v__ = v;
8251         first = false;
8252         if (v) {
8253           activeStream.lineStart();
8254           activeStream.point(x, y);
8255         }
8256       } else {
8257         if (v && v_) activeStream.point(x, y);
8258         else {
8259           var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
8260               b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
8261           if (clipLine(a, b, x0, y0, x1, y1)) {
8262             if (!v_) {
8263               activeStream.lineStart();
8264               activeStream.point(a[0], a[1]);
8265             }
8266             activeStream.point(b[0], b[1]);
8267             if (!v) activeStream.lineEnd();
8268             clean = false;
8269           } else if (v) {
8270             activeStream.lineStart();
8271             activeStream.point(x, y);
8272             clean = false;
8273           }
8274         }
8275       }
8276       x_ = x, y_ = y, v_ = v;
8277     }
8278
8279     return clipStream;
8280   };
8281 }
8282
8283 var extent$1 = function() {
8284   var x0 = 0,
8285       y0 = 0,
8286       x1 = 960,
8287       y1 = 500,
8288       cache,
8289       cacheStream,
8290       clip;
8291
8292   return clip = {
8293     stream: function(stream) {
8294       return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
8295     },
8296     extent: function(_) {
8297       return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
8298     }
8299   };
8300 };
8301
8302 var lengthSum = adder();
8303 var lambda0$2;
8304 var sinPhi0$1;
8305 var cosPhi0$1;
8306
8307 var lengthStream = {
8308   sphere: noop$1,
8309   point: noop$1,
8310   lineStart: lengthLineStart,
8311   lineEnd: noop$1,
8312   polygonStart: noop$1,
8313   polygonEnd: noop$1
8314 };
8315
8316 function lengthLineStart() {
8317   lengthStream.point = lengthPointFirst;
8318   lengthStream.lineEnd = lengthLineEnd;
8319 }
8320
8321 function lengthLineEnd() {
8322   lengthStream.point = lengthStream.lineEnd = noop$1;
8323 }
8324
8325 function lengthPointFirst(lambda, phi) {
8326   lambda *= radians, phi *= radians;
8327   lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
8328   lengthStream.point = lengthPoint;
8329 }
8330
8331 function lengthPoint(lambda, phi) {
8332   lambda *= radians, phi *= radians;
8333   var sinPhi = sin$1(phi),
8334       cosPhi = cos$1(phi),
8335       delta = abs(lambda - lambda0$2),
8336       cosDelta = cos$1(delta),
8337       sinDelta = sin$1(delta),
8338       x = cosPhi * sinDelta,
8339       y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
8340       z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
8341   lengthSum.add(atan2(sqrt(x * x + y * y), z));
8342   lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
8343 }
8344
8345 var length$1 = function(object) {
8346   lengthSum.reset();
8347   geoStream(object, lengthStream);
8348   return +lengthSum;
8349 };
8350
8351 var coordinates = [null, null];
8352 var object$1 = {type: "LineString", coordinates: coordinates};
8353
8354 var distance = function(a, b) {
8355   coordinates[0] = a;
8356   coordinates[1] = b;
8357   return length$1(object$1);
8358 };
8359
8360 var containsObjectType = {
8361   Feature: function(object, point) {
8362     return containsGeometry(object.geometry, point);
8363   },
8364   FeatureCollection: function(object, point) {
8365     var features = object.features, i = -1, n = features.length;
8366     while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
8367     return false;
8368   }
8369 };
8370
8371 var containsGeometryType = {
8372   Sphere: function() {
8373     return true;
8374   },
8375   Point: function(object, point) {
8376     return containsPoint(object.coordinates, point);
8377   },
8378   MultiPoint: function(object, point) {
8379     var coordinates = object.coordinates, i = -1, n = coordinates.length;
8380     while (++i < n) if (containsPoint(coordinates[i], point)) return true;
8381     return false;
8382   },
8383   LineString: function(object, point) {
8384     return containsLine(object.coordinates, point);
8385   },
8386   MultiLineString: function(object, point) {
8387     var coordinates = object.coordinates, i = -1, n = coordinates.length;
8388     while (++i < n) if (containsLine(coordinates[i], point)) return true;
8389     return false;
8390   },
8391   Polygon: function(object, point) {
8392     return containsPolygon(object.coordinates, point);
8393   },
8394   MultiPolygon: function(object, point) {
8395     var coordinates = object.coordinates, i = -1, n = coordinates.length;
8396     while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
8397     return false;
8398   },
8399   GeometryCollection: function(object, point) {
8400     var geometries = object.geometries, i = -1, n = geometries.length;
8401     while (++i < n) if (containsGeometry(geometries[i], point)) return true;
8402     return false;
8403   }
8404 };
8405
8406 function containsGeometry(geometry, point) {
8407   return geometry && containsGeometryType.hasOwnProperty(geometry.type)
8408       ? containsGeometryType[geometry.type](geometry, point)
8409       : false;
8410 }
8411
8412 function containsPoint(coordinates, point) {
8413   return distance(coordinates, point) === 0;
8414 }
8415
8416 function containsLine(coordinates, point) {
8417   var ab = distance(coordinates[0], coordinates[1]),
8418       ao = distance(coordinates[0], point),
8419       ob = distance(point, coordinates[1]);
8420   return ao + ob <= ab + epsilon$2;
8421 }
8422
8423 function containsPolygon(coordinates, point) {
8424   return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
8425 }
8426
8427 function ringRadians(ring) {
8428   return ring = ring.map(pointRadians), ring.pop(), ring;
8429 }
8430
8431 function pointRadians(point) {
8432   return [point[0] * radians, point[1] * radians];
8433 }
8434
8435 var contains = function(object, point) {
8436   return (object && containsObjectType.hasOwnProperty(object.type)
8437       ? containsObjectType[object.type]
8438       : containsGeometry)(object, point);
8439 };
8440
8441 function graticuleX(y0, y1, dy) {
8442   var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
8443   return function(x) { return y.map(function(y) { return [x, y]; }); };
8444 }
8445
8446 function graticuleY(x0, x1, dx) {
8447   var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
8448   return function(y) { return x.map(function(x) { return [x, y]; }); };
8449 }
8450
8451 function graticule() {
8452   var x1, x0, X1, X0,
8453       y1, y0, Y1, Y0,
8454       dx = 10, dy = dx, DX = 90, DY = 360,
8455       x, y, X, Y,
8456       precision = 2.5;
8457
8458   function graticule() {
8459     return {type: "MultiLineString", coordinates: lines()};
8460   }
8461
8462   function lines() {
8463     return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
8464         .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
8465         .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
8466         .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
8467   }
8468
8469   graticule.lines = function() {
8470     return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
8471   };
8472
8473   graticule.outline = function() {
8474     return {
8475       type: "Polygon",
8476       coordinates: [
8477         X(X0).concat(
8478         Y(Y1).slice(1),
8479         X(X1).reverse().slice(1),
8480         Y(Y0).reverse().slice(1))
8481       ]
8482     };
8483   };
8484
8485   graticule.extent = function(_) {
8486     if (!arguments.length) return graticule.extentMinor();
8487     return graticule.extentMajor(_).extentMinor(_);
8488   };
8489
8490   graticule.extentMajor = function(_) {
8491     if (!arguments.length) return [[X0, Y0], [X1, Y1]];
8492     X0 = +_[0][0], X1 = +_[1][0];
8493     Y0 = +_[0][1], Y1 = +_[1][1];
8494     if (X0 > X1) _ = X0, X0 = X1, X1 = _;
8495     if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
8496     return graticule.precision(precision);
8497   };
8498
8499   graticule.extentMinor = function(_) {
8500     if (!arguments.length) return [[x0, y0], [x1, y1]];
8501     x0 = +_[0][0], x1 = +_[1][0];
8502     y0 = +_[0][1], y1 = +_[1][1];
8503     if (x0 > x1) _ = x0, x0 = x1, x1 = _;
8504     if (y0 > y1) _ = y0, y0 = y1, y1 = _;
8505     return graticule.precision(precision);
8506   };
8507
8508   graticule.step = function(_) {
8509     if (!arguments.length) return graticule.stepMinor();
8510     return graticule.stepMajor(_).stepMinor(_);
8511   };
8512
8513   graticule.stepMajor = function(_) {
8514     if (!arguments.length) return [DX, DY];
8515     DX = +_[0], DY = +_[1];
8516     return graticule;
8517   };
8518
8519   graticule.stepMinor = function(_) {
8520     if (!arguments.length) return [dx, dy];
8521     dx = +_[0], dy = +_[1];
8522     return graticule;
8523   };
8524
8525   graticule.precision = function(_) {
8526     if (!arguments.length) return precision;
8527     precision = +_;
8528     x = graticuleX(y0, y1, 90);
8529     y = graticuleY(x0, x1, precision);
8530     X = graticuleX(Y0, Y1, 90);
8531     Y = graticuleY(X0, X1, precision);
8532     return graticule;
8533   };
8534
8535   return graticule
8536       .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
8537       .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
8538 }
8539
8540 function graticule10() {
8541   return graticule()();
8542 }
8543
8544 var interpolate$1 = function(a, b) {
8545   var x0 = a[0] * radians,
8546       y0 = a[1] * radians,
8547       x1 = b[0] * radians,
8548       y1 = b[1] * radians,
8549       cy0 = cos$1(y0),
8550       sy0 = sin$1(y0),
8551       cy1 = cos$1(y1),
8552       sy1 = sin$1(y1),
8553       kx0 = cy0 * cos$1(x0),
8554       ky0 = cy0 * sin$1(x0),
8555       kx1 = cy1 * cos$1(x1),
8556       ky1 = cy1 * sin$1(x1),
8557       d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
8558       k = sin$1(d);
8559
8560   var interpolate = d ? function(t) {
8561     var B = sin$1(t *= d) / k,
8562         A = sin$1(d - t) / k,
8563         x = A * kx0 + B * kx1,
8564         y = A * ky0 + B * ky1,
8565         z = A * sy0 + B * sy1;
8566     return [
8567       atan2(y, x) * degrees$1,
8568       atan2(z, sqrt(x * x + y * y)) * degrees$1
8569     ];
8570   } : function() {
8571     return [x0 * degrees$1, y0 * degrees$1];
8572   };
8573
8574   interpolate.distance = d;
8575
8576   return interpolate;
8577 };
8578
8579 var identity$4 = function(x) {
8580   return x;
8581 };
8582
8583 var areaSum$1 = adder();
8584 var areaRingSum$1 = adder();
8585 var x00;
8586 var y00;
8587 var x0$1;
8588 var y0$1;
8589
8590 var areaStream$1 = {
8591   point: noop$1,
8592   lineStart: noop$1,
8593   lineEnd: noop$1,
8594   polygonStart: function() {
8595     areaStream$1.lineStart = areaRingStart$1;
8596     areaStream$1.lineEnd = areaRingEnd$1;
8597   },
8598   polygonEnd: function() {
8599     areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$1;
8600     areaSum$1.add(abs(areaRingSum$1));
8601     areaRingSum$1.reset();
8602   },
8603   result: function() {
8604     var area = areaSum$1 / 2;
8605     areaSum$1.reset();
8606     return area;
8607   }
8608 };
8609
8610 function areaRingStart$1() {
8611   areaStream$1.point = areaPointFirst$1;
8612 }
8613
8614 function areaPointFirst$1(x, y) {
8615   areaStream$1.point = areaPoint$1;
8616   x00 = x0$1 = x, y00 = y0$1 = y;
8617 }
8618
8619 function areaPoint$1(x, y) {
8620   areaRingSum$1.add(y0$1 * x - x0$1 * y);
8621   x0$1 = x, y0$1 = y;
8622 }
8623
8624 function areaRingEnd$1() {
8625   areaPoint$1(x00, y00);
8626 }
8627
8628 var x0$2 = Infinity;
8629 var y0$2 = x0$2;
8630 var x1 = -x0$2;
8631 var y1 = x1;
8632
8633 var boundsStream$1 = {
8634   point: boundsPoint$1,
8635   lineStart: noop$1,
8636   lineEnd: noop$1,
8637   polygonStart: noop$1,
8638   polygonEnd: noop$1,
8639   result: function() {
8640     var bounds = [[x0$2, y0$2], [x1, y1]];
8641     x1 = y1 = -(y0$2 = x0$2 = Infinity);
8642     return bounds;
8643   }
8644 };
8645
8646 function boundsPoint$1(x, y) {
8647   if (x < x0$2) x0$2 = x;
8648   if (x > x1) x1 = x;
8649   if (y < y0$2) y0$2 = y;
8650   if (y > y1) y1 = y;
8651 }
8652
8653 // TODO Enforce positive area for exterior, negative area for interior?
8654
8655 var X0$1 = 0;
8656 var Y0$1 = 0;
8657 var Z0$1 = 0;
8658 var X1$1 = 0;
8659 var Y1$1 = 0;
8660 var Z1$1 = 0;
8661 var X2$1 = 0;
8662 var Y2$1 = 0;
8663 var Z2$1 = 0;
8664 var x00$1;
8665 var y00$1;
8666 var x0$3;
8667 var y0$3;
8668
8669 var centroidStream$1 = {
8670   point: centroidPoint$1,
8671   lineStart: centroidLineStart$1,
8672   lineEnd: centroidLineEnd$1,
8673   polygonStart: function() {
8674     centroidStream$1.lineStart = centroidRingStart$1;
8675     centroidStream$1.lineEnd = centroidRingEnd$1;
8676   },
8677   polygonEnd: function() {
8678     centroidStream$1.point = centroidPoint$1;
8679     centroidStream$1.lineStart = centroidLineStart$1;
8680     centroidStream$1.lineEnd = centroidLineEnd$1;
8681   },
8682   result: function() {
8683     var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
8684         : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
8685         : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
8686         : [NaN, NaN];
8687     X0$1 = Y0$1 = Z0$1 =
8688     X1$1 = Y1$1 = Z1$1 =
8689     X2$1 = Y2$1 = Z2$1 = 0;
8690     return centroid;
8691   }
8692 };
8693
8694 function centroidPoint$1(x, y) {
8695   X0$1 += x;
8696   Y0$1 += y;
8697   ++Z0$1;
8698 }
8699
8700 function centroidLineStart$1() {
8701   centroidStream$1.point = centroidPointFirstLine;
8702 }
8703
8704 function centroidPointFirstLine(x, y) {
8705   centroidStream$1.point = centroidPointLine;
8706   centroidPoint$1(x0$3 = x, y0$3 = y);
8707 }
8708
8709 function centroidPointLine(x, y) {
8710   var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
8711   X1$1 += z * (x0$3 + x) / 2;
8712   Y1$1 += z * (y0$3 + y) / 2;
8713   Z1$1 += z;
8714   centroidPoint$1(x0$3 = x, y0$3 = y);
8715 }
8716
8717 function centroidLineEnd$1() {
8718   centroidStream$1.point = centroidPoint$1;
8719 }
8720
8721 function centroidRingStart$1() {
8722   centroidStream$1.point = centroidPointFirstRing;
8723 }
8724
8725 function centroidRingEnd$1() {
8726   centroidPointRing(x00$1, y00$1);
8727 }
8728
8729 function centroidPointFirstRing(x, y) {
8730   centroidStream$1.point = centroidPointRing;
8731   centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
8732 }
8733
8734 function centroidPointRing(x, y) {
8735   var dx = x - x0$3,
8736       dy = y - y0$3,
8737       z = sqrt(dx * dx + dy * dy);
8738
8739   X1$1 += z * (x0$3 + x) / 2;
8740   Y1$1 += z * (y0$3 + y) / 2;
8741   Z1$1 += z;
8742
8743   z = y0$3 * x - x0$3 * y;
8744   X2$1 += z * (x0$3 + x);
8745   Y2$1 += z * (y0$3 + y);
8746   Z2$1 += z * 3;
8747   centroidPoint$1(x0$3 = x, y0$3 = y);
8748 }
8749
8750 function PathContext(context) {
8751   this._context = context;
8752 }
8753
8754 PathContext.prototype = {
8755   _radius: 4.5,
8756   pointRadius: function(_) {
8757     return this._radius = _, this;
8758   },
8759   polygonStart: function() {
8760     this._line = 0;
8761   },
8762   polygonEnd: function() {
8763     this._line = NaN;
8764   },
8765   lineStart: function() {
8766     this._point = 0;
8767   },
8768   lineEnd: function() {
8769     if (this._line === 0) this._context.closePath();
8770     this._point = NaN;
8771   },
8772   point: function(x, y) {
8773     switch (this._point) {
8774       case 0: {
8775         this._context.moveTo(x, y);
8776         this._point = 1;
8777         break;
8778       }
8779       case 1: {
8780         this._context.lineTo(x, y);
8781         break;
8782       }
8783       default: {
8784         this._context.moveTo(x + this._radius, y);
8785         this._context.arc(x, y, this._radius, 0, tau$3);
8786         break;
8787       }
8788     }
8789   },
8790   result: noop$1
8791 };
8792
8793 var lengthSum$1 = adder();
8794 var lengthRing;
8795 var x00$2;
8796 var y00$2;
8797 var x0$4;
8798 var y0$4;
8799
8800 var lengthStream$1 = {
8801   point: noop$1,
8802   lineStart: function() {
8803     lengthStream$1.point = lengthPointFirst$1;
8804   },
8805   lineEnd: function() {
8806     if (lengthRing) lengthPoint$1(x00$2, y00$2);
8807     lengthStream$1.point = noop$1;
8808   },
8809   polygonStart: function() {
8810     lengthRing = true;
8811   },
8812   polygonEnd: function() {
8813     lengthRing = null;
8814   },
8815   result: function() {
8816     var length = +lengthSum$1;
8817     lengthSum$1.reset();
8818     return length;
8819   }
8820 };
8821
8822 function lengthPointFirst$1(x, y) {
8823   lengthStream$1.point = lengthPoint$1;
8824   x00$2 = x0$4 = x, y00$2 = y0$4 = y;
8825 }
8826
8827 function lengthPoint$1(x, y) {
8828   x0$4 -= x, y0$4 -= y;
8829   lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
8830   x0$4 = x, y0$4 = y;
8831 }
8832
8833 function PathString() {
8834   this._string = [];
8835 }
8836
8837 PathString.prototype = {
8838   _radius: 4.5,
8839   _circle: circle$1(4.5),
8840   pointRadius: function(_) {
8841     if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
8842     return this;
8843   },
8844   polygonStart: function() {
8845     this._line = 0;
8846   },
8847   polygonEnd: function() {
8848     this._line = NaN;
8849   },
8850   lineStart: function() {
8851     this._point = 0;
8852   },
8853   lineEnd: function() {
8854     if (this._line === 0) this._string.push("Z");
8855     this._point = NaN;
8856   },
8857   point: function(x, y) {
8858     switch (this._point) {
8859       case 0: {
8860         this._string.push("M", x, ",", y);
8861         this._point = 1;
8862         break;
8863       }
8864       case 1: {
8865         this._string.push("L", x, ",", y);
8866         break;
8867       }
8868       default: {
8869         if (this._circle == null) this._circle = circle$1(this._radius);
8870         this._string.push("M", x, ",", y, this._circle);
8871         break;
8872       }
8873     }
8874   },
8875   result: function() {
8876     if (this._string.length) {
8877       var result = this._string.join("");
8878       this._string = [];
8879       return result;
8880     } else {
8881       return null;
8882     }
8883   }
8884 };
8885
8886 function circle$1(radius) {
8887   return "m0," + radius
8888       + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
8889       + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
8890       + "z";
8891 }
8892
8893 var index$1 = function(projection, context) {
8894   var pointRadius = 4.5,
8895       projectionStream,
8896       contextStream;
8897
8898   function path(object) {
8899     if (object) {
8900       if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
8901       geoStream(object, projectionStream(contextStream));
8902     }
8903     return contextStream.result();
8904   }
8905
8906   path.area = function(object) {
8907     geoStream(object, projectionStream(areaStream$1));
8908     return areaStream$1.result();
8909   };
8910
8911   path.measure = function(object) {
8912     geoStream(object, projectionStream(lengthStream$1));
8913     return lengthStream$1.result();
8914   };
8915
8916   path.bounds = function(object) {
8917     geoStream(object, projectionStream(boundsStream$1));
8918     return boundsStream$1.result();
8919   };
8920
8921   path.centroid = function(object) {
8922     geoStream(object, projectionStream(centroidStream$1));
8923     return centroidStream$1.result();
8924   };
8925
8926   path.projection = function(_) {
8927     return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
8928   };
8929
8930   path.context = function(_) {
8931     if (!arguments.length) return context;
8932     contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
8933     if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
8934     return path;
8935   };
8936
8937   path.pointRadius = function(_) {
8938     if (!arguments.length) return pointRadius;
8939     pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
8940     return path;
8941   };
8942
8943   return path.projection(projection).context(context);
8944 };
8945
8946 var transform = function(methods) {
8947   return {
8948     stream: transformer(methods)
8949   };
8950 };
8951
8952 function transformer(methods) {
8953   return function(stream) {
8954     var s = new TransformStream;
8955     for (var key in methods) s[key] = methods[key];
8956     s.stream = stream;
8957     return s;
8958   };
8959 }
8960
8961 function TransformStream() {}
8962
8963 TransformStream.prototype = {
8964   constructor: TransformStream,
8965   point: function(x, y) { this.stream.point(x, y); },
8966   sphere: function() { this.stream.sphere(); },
8967   lineStart: function() { this.stream.lineStart(); },
8968   lineEnd: function() { this.stream.lineEnd(); },
8969   polygonStart: function() { this.stream.polygonStart(); },
8970   polygonEnd: function() { this.stream.polygonEnd(); }
8971 };
8972
8973 function fit(projection, fitBounds, object) {
8974   var clip = projection.clipExtent && projection.clipExtent();
8975   projection.scale(150).translate([0, 0]);
8976   if (clip != null) projection.clipExtent(null);
8977   geoStream(object, projection.stream(boundsStream$1));
8978   fitBounds(boundsStream$1.result());
8979   if (clip != null) projection.clipExtent(clip);
8980   return projection;
8981 }
8982
8983 function fitExtent(projection, extent, object) {
8984   return fit(projection, function(b) {
8985     var w = extent[1][0] - extent[0][0],
8986         h = extent[1][1] - extent[0][1],
8987         k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
8988         x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
8989         y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
8990     projection.scale(150 * k).translate([x, y]);
8991   }, object);
8992 }
8993
8994 function fitSize(projection, size, object) {
8995   return fitExtent(projection, [[0, 0], size], object);
8996 }
8997
8998 function fitWidth(projection, width, object) {
8999   return fit(projection, function(b) {
9000     var w = +width,
9001         k = w / (b[1][0] - b[0][0]),
9002         x = (w - k * (b[1][0] + b[0][0])) / 2,
9003         y = -k * b[0][1];
9004     projection.scale(150 * k).translate([x, y]);
9005   }, object);
9006 }
9007
9008 function fitHeight(projection, height, object) {
9009   return fit(projection, function(b) {
9010     var h = +height,
9011         k = h / (b[1][1] - b[0][1]),
9012         x = -k * b[0][0],
9013         y = (h - k * (b[1][1] + b[0][1])) / 2;
9014     projection.scale(150 * k).translate([x, y]);
9015   }, object);
9016 }
9017
9018 var maxDepth = 16;
9019 var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
9020
9021 var resample = function(project, delta2) {
9022   return +delta2 ? resample$1(project, delta2) : resampleNone(project);
9023 };
9024
9025 function resampleNone(project) {
9026   return transformer({
9027     point: function(x, y) {
9028       x = project(x, y);
9029       this.stream.point(x[0], x[1]);
9030     }
9031   });
9032 }
9033
9034 function resample$1(project, delta2) {
9035
9036   function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
9037     var dx = x1 - x0,
9038         dy = y1 - y0,
9039         d2 = dx * dx + dy * dy;
9040     if (d2 > 4 * delta2 && depth--) {
9041       var a = a0 + a1,
9042           b = b0 + b1,
9043           c = c0 + c1,
9044           m = sqrt(a * a + b * b + c * c),
9045           phi2 = asin(c /= m),
9046           lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
9047           p = project(lambda2, phi2),
9048           x2 = p[0],
9049           y2 = p[1],
9050           dx2 = x2 - x0,
9051           dy2 = y2 - y0,
9052           dz = dy * dx2 - dx * dy2;
9053       if (dz * dz / d2 > delta2 // perpendicular projected distance
9054           || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
9055           || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
9056         resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
9057         stream.point(x2, y2);
9058         resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
9059       }
9060     }
9061   }
9062   return function(stream) {
9063     var lambda00, x00, y00, a00, b00, c00, // first point
9064         lambda0, x0, y0, a0, b0, c0; // previous point
9065
9066     var resampleStream = {
9067       point: point,
9068       lineStart: lineStart,
9069       lineEnd: lineEnd,
9070       polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
9071       polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
9072     };
9073
9074     function point(x, y) {
9075       x = project(x, y);
9076       stream.point(x[0], x[1]);
9077     }
9078
9079     function lineStart() {
9080       x0 = NaN;
9081       resampleStream.point = linePoint;
9082       stream.lineStart();
9083     }
9084
9085     function linePoint(lambda, phi) {
9086       var c = cartesian([lambda, phi]), p = project(lambda, phi);
9087       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);
9088       stream.point(x0, y0);
9089     }
9090
9091     function lineEnd() {
9092       resampleStream.point = point;
9093       stream.lineEnd();
9094     }
9095
9096     function ringStart() {
9097       lineStart();
9098       resampleStream.point = ringPoint;
9099       resampleStream.lineEnd = ringEnd;
9100     }
9101
9102     function ringPoint(lambda, phi) {
9103       linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
9104       resampleStream.point = linePoint;
9105     }
9106
9107     function ringEnd() {
9108       resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
9109       resampleStream.lineEnd = lineEnd;
9110       lineEnd();
9111     }
9112
9113     return resampleStream;
9114   };
9115 }
9116
9117 var transformRadians = transformer({
9118   point: function(x, y) {
9119     this.stream.point(x * radians, y * radians);
9120   }
9121 });
9122
9123 function transformRotate(rotate) {
9124   return transformer({
9125     point: function(x, y) {
9126       var r = rotate(x, y);
9127       return this.stream.point(r[0], r[1]);
9128     }
9129   });
9130 }
9131
9132 function projection(project) {
9133   return projectionMutator(function() { return project; })();
9134 }
9135
9136 function projectionMutator(projectAt) {
9137   var project,
9138       k = 150, // scale
9139       x = 480, y = 250, // translate
9140       dx, dy, lambda = 0, phi = 0, // center
9141       deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
9142       theta = null, preclip = clipAntimeridian, // clip angle
9143       x0 = null, y0, x1, y1, postclip = identity$4, // clip extent
9144       delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
9145       cache,
9146       cacheStream;
9147
9148   function projection(point) {
9149     point = projectRotate(point[0] * radians, point[1] * radians);
9150     return [point[0] * k + dx, dy - point[1] * k];
9151   }
9152
9153   function invert(point) {
9154     point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
9155     return point && [point[0] * degrees$1, point[1] * degrees$1];
9156   }
9157
9158   function projectTransform(x, y) {
9159     return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
9160   }
9161
9162   projection.stream = function(stream) {
9163     return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
9164   };
9165
9166   projection.preclip = function(_) {
9167     return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
9168   };
9169
9170   projection.postclip = function(_) {
9171     return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
9172   };
9173
9174   projection.clipAngle = function(_) {
9175     return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
9176   };
9177
9178   projection.clipExtent = function(_) {
9179     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]];
9180   };
9181
9182   projection.scale = function(_) {
9183     return arguments.length ? (k = +_, recenter()) : k;
9184   };
9185
9186   projection.translate = function(_) {
9187     return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
9188   };
9189
9190   projection.center = function(_) {
9191     return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
9192   };
9193
9194   projection.rotate = function(_) {
9195     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];
9196   };
9197
9198   projection.precision = function(_) {
9199     return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
9200   };
9201
9202   projection.fitExtent = function(extent, object) {
9203     return fitExtent(projection, extent, object);
9204   };
9205
9206   projection.fitSize = function(size, object) {
9207     return fitSize(projection, size, object);
9208   };
9209
9210   projection.fitWidth = function(width, object) {
9211     return fitWidth(projection, width, object);
9212   };
9213
9214   projection.fitHeight = function(height, object) {
9215     return fitHeight(projection, height, object);
9216   };
9217
9218   function recenter() {
9219     projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
9220     var center = project(lambda, phi);
9221     dx = x - center[0] * k;
9222     dy = y + center[1] * k;
9223     return reset();
9224   }
9225
9226   function reset() {
9227     cache = cacheStream = null;
9228     return projection;
9229   }
9230
9231   return function() {
9232     project = projectAt.apply(this, arguments);
9233     projection.invert = project.invert && invert;
9234     return recenter();
9235   };
9236 }
9237
9238 function conicProjection(projectAt) {
9239   var phi0 = 0,
9240       phi1 = pi$3 / 3,
9241       m = projectionMutator(projectAt),
9242       p = m(phi0, phi1);
9243
9244   p.parallels = function(_) {
9245     return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
9246   };
9247
9248   return p;
9249 }
9250
9251 function cylindricalEqualAreaRaw(phi0) {
9252   var cosPhi0 = cos$1(phi0);
9253
9254   function forward(lambda, phi) {
9255     return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
9256   }
9257
9258   forward.invert = function(x, y) {
9259     return [x / cosPhi0, asin(y * cosPhi0)];
9260   };
9261
9262   return forward;
9263 }
9264
9265 function conicEqualAreaRaw(y0, y1) {
9266   var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
9267
9268   // Are the parallels symmetrical around the Equator?
9269   if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
9270
9271   var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
9272
9273   function project(x, y) {
9274     var r = sqrt(c - 2 * n * sin$1(y)) / n;
9275     return [r * sin$1(x *= n), r0 - r * cos$1(x)];
9276   }
9277
9278   project.invert = function(x, y) {
9279     var r0y = r0 - y;
9280     return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
9281   };
9282
9283   return project;
9284 }
9285
9286 var conicEqualArea = function() {
9287   return conicProjection(conicEqualAreaRaw)
9288       .scale(155.424)
9289       .center([0, 33.6442]);
9290 };
9291
9292 var albers = function() {
9293   return conicEqualArea()
9294       .parallels([29.5, 45.5])
9295       .scale(1070)
9296       .translate([480, 250])
9297       .rotate([96, 0])
9298       .center([-0.6, 38.7]);
9299 };
9300
9301 // The projections must have mutually exclusive clip regions on the sphere,
9302 // as this will avoid emitting interleaving lines and polygons.
9303 function multiplex(streams) {
9304   var n = streams.length;
9305   return {
9306     point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
9307     sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
9308     lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
9309     lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
9310     polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
9311     polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
9312   };
9313 }
9314
9315 // A composite projection for the United States, configured by default for
9316 // 960×500. The projection also works quite well at 960×600 if you change the
9317 // scale to 1285 and adjust the translate accordingly. The set of standard
9318 // parallels for each region comes from USGS, which is published here:
9319 // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
9320 var albersUsa = function() {
9321   var cache,
9322       cacheStream,
9323       lower48 = albers(), lower48Point,
9324       alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
9325       hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
9326       point, pointStream = {point: function(x, y) { point = [x, y]; }};
9327
9328   function albersUsa(coordinates) {
9329     var x = coordinates[0], y = coordinates[1];
9330     return point = null, (lower48Point.point(x, y), point)
9331         || (alaskaPoint.point(x, y), point)
9332         || (hawaiiPoint.point(x, y), point);
9333   }
9334
9335   albersUsa.invert = function(coordinates) {
9336     var k = lower48.scale(),
9337         t = lower48.translate(),
9338         x = (coordinates[0] - t[0]) / k,
9339         y = (coordinates[1] - t[1]) / k;
9340     return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
9341         : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
9342         : lower48).invert(coordinates);
9343   };
9344
9345   albersUsa.stream = function(stream) {
9346     return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
9347   };
9348
9349   albersUsa.precision = function(_) {
9350     if (!arguments.length) return lower48.precision();
9351     lower48.precision(_), alaska.precision(_), hawaii.precision(_);
9352     return reset();
9353   };
9354
9355   albersUsa.scale = function(_) {
9356     if (!arguments.length) return lower48.scale();
9357     lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
9358     return albersUsa.translate(lower48.translate());
9359   };
9360
9361   albersUsa.translate = function(_) {
9362     if (!arguments.length) return lower48.translate();
9363     var k = lower48.scale(), x = +_[0], y = +_[1];
9364
9365     lower48Point = lower48
9366         .translate(_)
9367         .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
9368         .stream(pointStream);
9369
9370     alaskaPoint = alaska
9371         .translate([x - 0.307 * k, y + 0.201 * k])
9372         .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]])
9373         .stream(pointStream);
9374
9375     hawaiiPoint = hawaii
9376         .translate([x - 0.205 * k, y + 0.212 * k])
9377         .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]])
9378         .stream(pointStream);
9379
9380     return reset();
9381   };
9382
9383   albersUsa.fitExtent = function(extent, object) {
9384     return fitExtent(albersUsa, extent, object);
9385   };
9386
9387   albersUsa.fitSize = function(size, object) {
9388     return fitSize(albersUsa, size, object);
9389   };
9390
9391   albersUsa.fitWidth = function(width, object) {
9392     return fitWidth(albersUsa, width, object);
9393   };
9394
9395   albersUsa.fitHeight = function(height, object) {
9396     return fitHeight(albersUsa, height, object);
9397   };
9398
9399   function reset() {
9400     cache = cacheStream = null;
9401     return albersUsa;
9402   }
9403
9404   return albersUsa.scale(1070);
9405 };
9406
9407 function azimuthalRaw(scale) {
9408   return function(x, y) {
9409     var cx = cos$1(x),
9410         cy = cos$1(y),
9411         k = scale(cx * cy);
9412     return [
9413       k * cy * sin$1(x),
9414       k * sin$1(y)
9415     ];
9416   }
9417 }
9418
9419 function azimuthalInvert(angle) {
9420   return function(x, y) {
9421     var z = sqrt(x * x + y * y),
9422         c = angle(z),
9423         sc = sin$1(c),
9424         cc = cos$1(c);
9425     return [
9426       atan2(x * sc, z * cc),
9427       asin(z && y * sc / z)
9428     ];
9429   }
9430 }
9431
9432 var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
9433   return sqrt(2 / (1 + cxcy));
9434 });
9435
9436 azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
9437   return 2 * asin(z / 2);
9438 });
9439
9440 var azimuthalEqualArea = function() {
9441   return projection(azimuthalEqualAreaRaw)
9442       .scale(124.75)
9443       .clipAngle(180 - 1e-3);
9444 };
9445
9446 var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
9447   return (c = acos(c)) && c / sin$1(c);
9448 });
9449
9450 azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
9451   return z;
9452 });
9453
9454 var azimuthalEquidistant = function() {
9455   return projection(azimuthalEquidistantRaw)
9456       .scale(79.4188)
9457       .clipAngle(180 - 1e-3);
9458 };
9459
9460 function mercatorRaw(lambda, phi) {
9461   return [lambda, log(tan((halfPi$2 + phi) / 2))];
9462 }
9463
9464 mercatorRaw.invert = function(x, y) {
9465   return [x, 2 * atan(exp(y)) - halfPi$2];
9466 };
9467
9468 var mercator = function() {
9469   return mercatorProjection(mercatorRaw)
9470       .scale(961 / tau$3);
9471 };
9472
9473 function mercatorProjection(project) {
9474   var m = projection(project),
9475       center = m.center,
9476       scale = m.scale,
9477       translate = m.translate,
9478       clipExtent = m.clipExtent,
9479       x0 = null, y0, x1, y1; // clip extent
9480
9481   m.scale = function(_) {
9482     return arguments.length ? (scale(_), reclip()) : scale();
9483   };
9484
9485   m.translate = function(_) {
9486     return arguments.length ? (translate(_), reclip()) : translate();
9487   };
9488
9489   m.center = function(_) {
9490     return arguments.length ? (center(_), reclip()) : center();
9491   };
9492
9493   m.clipExtent = function(_) {
9494     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]];
9495   };
9496
9497   function reclip() {
9498     var k = pi$3 * scale(),
9499         t = m(rotation(m.rotate()).invert([0, 0]));
9500     return clipExtent(x0 == null
9501         ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
9502         ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
9503         : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
9504   }
9505
9506   return reclip();
9507 }
9508
9509 function tany(y) {
9510   return tan((halfPi$2 + y) / 2);
9511 }
9512
9513 function conicConformalRaw(y0, y1) {
9514   var cy0 = cos$1(y0),
9515       n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
9516       f = cy0 * pow(tany(y0), n) / n;
9517
9518   if (!n) return mercatorRaw;
9519
9520   function project(x, y) {
9521     if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
9522     else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
9523     var r = f / pow(tany(y), n);
9524     return [r * sin$1(n * x), f - r * cos$1(n * x)];
9525   }
9526
9527   project.invert = function(x, y) {
9528     var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
9529     return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
9530   };
9531
9532   return project;
9533 }
9534
9535 var conicConformal = function() {
9536   return conicProjection(conicConformalRaw)
9537       .scale(109.5)
9538       .parallels([30, 30]);
9539 };
9540
9541 function equirectangularRaw(lambda, phi) {
9542   return [lambda, phi];
9543 }
9544
9545 equirectangularRaw.invert = equirectangularRaw;
9546
9547 var equirectangular = function() {
9548   return projection(equirectangularRaw)
9549       .scale(152.63);
9550 };
9551
9552 function conicEquidistantRaw(y0, y1) {
9553   var cy0 = cos$1(y0),
9554       n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
9555       g = cy0 / n + y0;
9556
9557   if (abs(n) < epsilon$2) return equirectangularRaw;
9558
9559   function project(x, y) {
9560     var gy = g - y, nx = n * x;
9561     return [gy * sin$1(nx), g - gy * cos$1(nx)];
9562   }
9563
9564   project.invert = function(x, y) {
9565     var gy = g - y;
9566     return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
9567   };
9568
9569   return project;
9570 }
9571
9572 var conicEquidistant = function() {
9573   return conicProjection(conicEquidistantRaw)
9574       .scale(131.154)
9575       .center([0, 13.9389]);
9576 };
9577
9578 function gnomonicRaw(x, y) {
9579   var cy = cos$1(y), k = cos$1(x) * cy;
9580   return [cy * sin$1(x) / k, sin$1(y) / k];
9581 }
9582
9583 gnomonicRaw.invert = azimuthalInvert(atan);
9584
9585 var gnomonic = function() {
9586   return projection(gnomonicRaw)
9587       .scale(144.049)
9588       .clipAngle(60);
9589 };
9590
9591 function scaleTranslate(kx, ky, tx, ty) {
9592   return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
9593     point: function(x, y) {
9594       this.stream.point(x * kx + tx, y * ky + ty);
9595     }
9596   });
9597 }
9598
9599 var identity$5 = function() {
9600   var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
9601       x0 = null, y0, x1, y1, // clip extent
9602       postclip = identity$4,
9603       cache,
9604       cacheStream,
9605       projection;
9606
9607   function reset() {
9608     cache = cacheStream = null;
9609     return projection;
9610   }
9611
9612   return projection = {
9613     stream: function(stream) {
9614       return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
9615     },
9616     postclip: function(_) {
9617       return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
9618     },
9619     clipExtent: function(_) {
9620       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]];
9621     },
9622     scale: function(_) {
9623       return arguments.length ? (transform$$1 = scaleTranslate((k = +_) * sx, k * sy, tx, ty), reset()) : k;
9624     },
9625     translate: function(_) {
9626       return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
9627     },
9628     reflectX: function(_) {
9629       return arguments.length ? (transform$$1 = scaleTranslate(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
9630     },
9631     reflectY: function(_) {
9632       return arguments.length ? (transform$$1 = scaleTranslate(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
9633     },
9634     fitExtent: function(extent, object) {
9635       return fitExtent(projection, extent, object);
9636     },
9637     fitSize: function(size, object) {
9638       return fitSize(projection, size, object);
9639     },
9640     fitWidth: function(width, object) {
9641       return fitWidth(projection, width, object);
9642     },
9643     fitHeight: function(height, object) {
9644       return fitHeight(projection, height, object);
9645     }
9646   };
9647 };
9648
9649 function naturalEarth1Raw(lambda, phi) {
9650   var phi2 = phi * phi, phi4 = phi2 * phi2;
9651   return [
9652     lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
9653     phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
9654   ];
9655 }
9656
9657 naturalEarth1Raw.invert = function(x, y) {
9658   var phi = y, i = 25, delta;
9659   do {
9660     var phi2 = phi * phi, phi4 = phi2 * phi2;
9661     phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
9662         (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
9663   } while (abs(delta) > epsilon$2 && --i > 0);
9664   return [
9665     x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
9666     phi
9667   ];
9668 };
9669
9670 var naturalEarth1 = function() {
9671   return projection(naturalEarth1Raw)
9672       .scale(175.295);
9673 };
9674
9675 function orthographicRaw(x, y) {
9676   return [cos$1(y) * sin$1(x), sin$1(y)];
9677 }
9678
9679 orthographicRaw.invert = azimuthalInvert(asin);
9680
9681 var orthographic = function() {
9682   return projection(orthographicRaw)
9683       .scale(249.5)
9684       .clipAngle(90 + epsilon$2);
9685 };
9686
9687 function stereographicRaw(x, y) {
9688   var cy = cos$1(y), k = 1 + cos$1(x) * cy;
9689   return [cy * sin$1(x) / k, sin$1(y) / k];
9690 }
9691
9692 stereographicRaw.invert = azimuthalInvert(function(z) {
9693   return 2 * atan(z);
9694 });
9695
9696 var stereographic = function() {
9697   return projection(stereographicRaw)
9698       .scale(250)
9699       .clipAngle(142);
9700 };
9701
9702 function transverseMercatorRaw(lambda, phi) {
9703   return [log(tan((halfPi$2 + phi) / 2)), -lambda];
9704 }
9705
9706 transverseMercatorRaw.invert = function(x, y) {
9707   return [-y, 2 * atan(exp(x)) - halfPi$2];
9708 };
9709
9710 var transverseMercator = function() {
9711   var m = mercatorProjection(transverseMercatorRaw),
9712       center = m.center,
9713       rotate = m.rotate;
9714
9715   m.center = function(_) {
9716     return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
9717   };
9718
9719   m.rotate = function(_) {
9720     return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
9721   };
9722
9723   return rotate([0, 0, 90])
9724       .scale(159.155);
9725 };
9726
9727 function defaultSeparation(a, b) {
9728   return a.parent === b.parent ? 1 : 2;
9729 }
9730
9731 function meanX(children) {
9732   return children.reduce(meanXReduce, 0) / children.length;
9733 }
9734
9735 function meanXReduce(x, c) {
9736   return x + c.x;
9737 }
9738
9739 function maxY(children) {
9740   return 1 + children.reduce(maxYReduce, 0);
9741 }
9742
9743 function maxYReduce(y, c) {
9744   return Math.max(y, c.y);
9745 }
9746
9747 function leafLeft(node) {
9748   var children;
9749   while (children = node.children) node = children[0];
9750   return node;
9751 }
9752
9753 function leafRight(node) {
9754   var children;
9755   while (children = node.children) node = children[children.length - 1];
9756   return node;
9757 }
9758
9759 var cluster = function() {
9760   var separation = defaultSeparation,
9761       dx = 1,
9762       dy = 1,
9763       nodeSize = false;
9764
9765   function cluster(root) {
9766     var previousNode,
9767         x = 0;
9768
9769     // First walk, computing the initial x & y values.
9770     root.eachAfter(function(node) {
9771       var children = node.children;
9772       if (children) {
9773         node.x = meanX(children);
9774         node.y = maxY(children);
9775       } else {
9776         node.x = previousNode ? x += separation(node, previousNode) : 0;
9777         node.y = 0;
9778         previousNode = node;
9779       }
9780     });
9781
9782     var left = leafLeft(root),
9783         right = leafRight(root),
9784         x0 = left.x - separation(left, right) / 2,
9785         x1 = right.x + separation(right, left) / 2;
9786
9787     // Second walk, normalizing x & y to the desired size.
9788     return root.eachAfter(nodeSize ? function(node) {
9789       node.x = (node.x - root.x) * dx;
9790       node.y = (root.y - node.y) * dy;
9791     } : function(node) {
9792       node.x = (node.x - x0) / (x1 - x0) * dx;
9793       node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
9794     });
9795   }
9796
9797   cluster.separation = function(x) {
9798     return arguments.length ? (separation = x, cluster) : separation;
9799   };
9800
9801   cluster.size = function(x) {
9802     return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
9803   };
9804
9805   cluster.nodeSize = function(x) {
9806     return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
9807   };
9808
9809   return cluster;
9810 };
9811
9812 function count(node) {
9813   var sum = 0,
9814       children = node.children,
9815       i = children && children.length;
9816   if (!i) sum = 1;
9817   else while (--i >= 0) sum += children[i].value;
9818   node.value = sum;
9819 }
9820
9821 var node_count = function() {
9822   return this.eachAfter(count);
9823 };
9824
9825 var node_each = function(callback) {
9826   var node = this, current, next = [node], children, i, n;
9827   do {
9828     current = next.reverse(), next = [];
9829     while (node = current.pop()) {
9830       callback(node), children = node.children;
9831       if (children) for (i = 0, n = children.length; i < n; ++i) {
9832         next.push(children[i]);
9833       }
9834     }
9835   } while (next.length);
9836   return this;
9837 };
9838
9839 var node_eachBefore = function(callback) {
9840   var node = this, nodes = [node], children, i;
9841   while (node = nodes.pop()) {
9842     callback(node), children = node.children;
9843     if (children) for (i = children.length - 1; i >= 0; --i) {
9844       nodes.push(children[i]);
9845     }
9846   }
9847   return this;
9848 };
9849
9850 var node_eachAfter = function(callback) {
9851   var node = this, nodes = [node], next = [], children, i, n;
9852   while (node = nodes.pop()) {
9853     next.push(node), children = node.children;
9854     if (children) for (i = 0, n = children.length; i < n; ++i) {
9855       nodes.push(children[i]);
9856     }
9857   }
9858   while (node = next.pop()) {
9859     callback(node);
9860   }
9861   return this;
9862 };
9863
9864 var node_sum = function(value) {
9865   return this.eachAfter(function(node) {
9866     var sum = +value(node.data) || 0,
9867         children = node.children,
9868         i = children && children.length;
9869     while (--i >= 0) sum += children[i].value;
9870     node.value = sum;
9871   });
9872 };
9873
9874 var node_sort = function(compare) {
9875   return this.eachBefore(function(node) {
9876     if (node.children) {
9877       node.children.sort(compare);
9878     }
9879   });
9880 };
9881
9882 var node_path = function(end) {
9883   var start = this,
9884       ancestor = leastCommonAncestor(start, end),
9885       nodes = [start];
9886   while (start !== ancestor) {
9887     start = start.parent;
9888     nodes.push(start);
9889   }
9890   var k = nodes.length;
9891   while (end !== ancestor) {
9892     nodes.splice(k, 0, end);
9893     end = end.parent;
9894   }
9895   return nodes;
9896 };
9897
9898 function leastCommonAncestor(a, b) {
9899   if (a === b) return a;
9900   var aNodes = a.ancestors(),
9901       bNodes = b.ancestors(),
9902       c = null;
9903   a = aNodes.pop();
9904   b = bNodes.pop();
9905   while (a === b) {
9906     c = a;
9907     a = aNodes.pop();
9908     b = bNodes.pop();
9909   }
9910   return c;
9911 }
9912
9913 var node_ancestors = function() {
9914   var node = this, nodes = [node];
9915   while (node = node.parent) {
9916     nodes.push(node);
9917   }
9918   return nodes;
9919 };
9920
9921 var node_descendants = function() {
9922   var nodes = [];
9923   this.each(function(node) {
9924     nodes.push(node);
9925   });
9926   return nodes;
9927 };
9928
9929 var node_leaves = function() {
9930   var leaves = [];
9931   this.eachBefore(function(node) {
9932     if (!node.children) {
9933       leaves.push(node);
9934     }
9935   });
9936   return leaves;
9937 };
9938
9939 var node_links = function() {
9940   var root = this, links = [];
9941   root.each(function(node) {
9942     if (node !== root) { // Don’t include the root’s parent, if any.
9943       links.push({source: node.parent, target: node});
9944     }
9945   });
9946   return links;
9947 };
9948
9949 function hierarchy(data, children) {
9950   var root = new Node(data),
9951       valued = +data.value && (root.value = data.value),
9952       node,
9953       nodes = [root],
9954       child,
9955       childs,
9956       i,
9957       n;
9958
9959   if (children == null) children = defaultChildren;
9960
9961   while (node = nodes.pop()) {
9962     if (valued) node.value = +node.data.value;
9963     if ((childs = children(node.data)) && (n = childs.length)) {
9964       node.children = new Array(n);
9965       for (i = n - 1; i >= 0; --i) {
9966         nodes.push(child = node.children[i] = new Node(childs[i]));
9967         child.parent = node;
9968         child.depth = node.depth + 1;
9969       }
9970     }
9971   }
9972
9973   return root.eachBefore(computeHeight);
9974 }
9975
9976 function node_copy() {
9977   return hierarchy(this).eachBefore(copyData);
9978 }
9979
9980 function defaultChildren(d) {
9981   return d.children;
9982 }
9983
9984 function copyData(node) {
9985   node.data = node.data.data;
9986 }
9987
9988 function computeHeight(node) {
9989   var height = 0;
9990   do node.height = height;
9991   while ((node = node.parent) && (node.height < ++height));
9992 }
9993
9994 function Node(data) {
9995   this.data = data;
9996   this.depth =
9997   this.height = 0;
9998   this.parent = null;
9999 }
10000
10001 Node.prototype = hierarchy.prototype = {
10002   constructor: Node,
10003   count: node_count,
10004   each: node_each,
10005   eachAfter: node_eachAfter,
10006   eachBefore: node_eachBefore,
10007   sum: node_sum,
10008   sort: node_sort,
10009   path: node_path,
10010   ancestors: node_ancestors,
10011   descendants: node_descendants,
10012   leaves: node_leaves,
10013   links: node_links,
10014   copy: node_copy
10015 };
10016
10017 var slice$3 = Array.prototype.slice;
10018
10019 function shuffle$1(array) {
10020   var m = array.length,
10021       t,
10022       i;
10023
10024   while (m) {
10025     i = Math.random() * m-- | 0;
10026     t = array[m];
10027     array[m] = array[i];
10028     array[i] = t;
10029   }
10030
10031   return array;
10032 }
10033
10034 var enclose = function(circles) {
10035   var i = 0, n = (circles = shuffle$1(slice$3.call(circles))).length, B = [], p, e;
10036
10037   while (i < n) {
10038     p = circles[i];
10039     if (e && enclosesWeak(e, p)) ++i;
10040     else e = encloseBasis(B = extendBasis(B, p)), i = 0;
10041   }
10042
10043   return e;
10044 };
10045
10046 function extendBasis(B, p) {
10047   var i, j;
10048
10049   if (enclosesWeakAll(p, B)) return [p];
10050
10051   // If we get here then B must have at least one element.
10052   for (i = 0; i < B.length; ++i) {
10053     if (enclosesNot(p, B[i])
10054         && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
10055       return [B[i], p];
10056     }
10057   }
10058
10059   // If we get here then B must have at least two elements.
10060   for (i = 0; i < B.length - 1; ++i) {
10061     for (j = i + 1; j < B.length; ++j) {
10062       if (enclosesNot(encloseBasis2(B[i], B[j]), p)
10063           && enclosesNot(encloseBasis2(B[i], p), B[j])
10064           && enclosesNot(encloseBasis2(B[j], p), B[i])
10065           && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
10066         return [B[i], B[j], p];
10067       }
10068     }
10069   }
10070
10071   // If we get here then something is very wrong.
10072   throw new Error;
10073 }
10074
10075 function enclosesNot(a, b) {
10076   var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
10077   return dr < 0 || dr * dr < dx * dx + dy * dy;
10078 }
10079
10080 function enclosesWeak(a, b) {
10081   var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10082   return dr > 0 && dr * dr > dx * dx + dy * dy;
10083 }
10084
10085 function enclosesWeakAll(a, B) {
10086   for (var i = 0; i < B.length; ++i) {
10087     if (!enclosesWeak(a, B[i])) {
10088       return false;
10089     }
10090   }
10091   return true;
10092 }
10093
10094 function encloseBasis(B) {
10095   switch (B.length) {
10096     case 1: return encloseBasis1(B[0]);
10097     case 2: return encloseBasis2(B[0], B[1]);
10098     case 3: return encloseBasis3(B[0], B[1], B[2]);
10099   }
10100 }
10101
10102 function encloseBasis1(a) {
10103   return {
10104     x: a.x,
10105     y: a.y,
10106     r: a.r
10107   };
10108 }
10109
10110 function encloseBasis2(a, b) {
10111   var x1 = a.x, y1 = a.y, r1 = a.r,
10112       x2 = b.x, y2 = b.y, r2 = b.r,
10113       x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
10114       l = Math.sqrt(x21 * x21 + y21 * y21);
10115   return {
10116     x: (x1 + x2 + x21 / l * r21) / 2,
10117     y: (y1 + y2 + y21 / l * r21) / 2,
10118     r: (l + r1 + r2) / 2
10119   };
10120 }
10121
10122 function encloseBasis3(a, b, c) {
10123   var x1 = a.x, y1 = a.y, r1 = a.r,
10124       x2 = b.x, y2 = b.y, r2 = b.r,
10125       x3 = c.x, y3 = c.y, r3 = c.r,
10126       a2 = x1 - x2,
10127       a3 = x1 - x3,
10128       b2 = y1 - y2,
10129       b3 = y1 - y3,
10130       c2 = r2 - r1,
10131       c3 = r3 - r1,
10132       d1 = x1 * x1 + y1 * y1 - r1 * r1,
10133       d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
10134       d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
10135       ab = a3 * b2 - a2 * b3,
10136       xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
10137       xb = (b3 * c2 - b2 * c3) / ab,
10138       ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
10139       yb = (a2 * c3 - a3 * c2) / ab,
10140       A = xb * xb + yb * yb - 1,
10141       B = 2 * (r1 + xa * xb + ya * yb),
10142       C = xa * xa + ya * ya - r1 * r1,
10143       r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
10144   return {
10145     x: x1 + xa + xb * r,
10146     y: y1 + ya + yb * r,
10147     r: r
10148   };
10149 }
10150
10151 function place(a, b, c) {
10152   var ax = a.x,
10153       ay = a.y,
10154       da = b.r + c.r,
10155       db = a.r + c.r,
10156       dx = b.x - ax,
10157       dy = b.y - ay,
10158       dc = dx * dx + dy * dy;
10159   if (dc) {
10160     var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
10161         y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
10162     c.x = ax + x * dx + y * dy;
10163     c.y = ay + x * dy - y * dx;
10164   } else {
10165     c.x = ax + db;
10166     c.y = ay;
10167   }
10168 }
10169
10170 function intersects(a, b) {
10171   var dx = b.x - a.x,
10172       dy = b.y - a.y,
10173       dr = a.r + b.r;
10174   return dr * dr - 1e-6 > dx * dx + dy * dy;
10175 }
10176
10177 function score(node) {
10178   var a = node._,
10179       b = node.next._,
10180       ab = a.r + b.r,
10181       dx = (a.x * b.r + b.x * a.r) / ab,
10182       dy = (a.y * b.r + b.y * a.r) / ab;
10183   return dx * dx + dy * dy;
10184 }
10185
10186 function Node$1(circle) {
10187   this._ = circle;
10188   this.next = null;
10189   this.previous = null;
10190 }
10191
10192 function packEnclose(circles) {
10193   if (!(n = circles.length)) return 0;
10194
10195   var a, b, c, n, aa, ca, i, j, k, sj, sk;
10196
10197   // Place the first circle.
10198   a = circles[0], a.x = 0, a.y = 0;
10199   if (!(n > 1)) return a.r;
10200
10201   // Place the second circle.
10202   b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
10203   if (!(n > 2)) return a.r + b.r;
10204
10205   // Place the third circle.
10206   place(b, a, c = circles[2]);
10207
10208   // Initialize the front-chain using the first three circles a, b and c.
10209   a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
10210   a.next = c.previous = b;
10211   b.next = a.previous = c;
10212   c.next = b.previous = a;
10213
10214   // Attempt to place each remaining circle…
10215   pack: for (i = 3; i < n; ++i) {
10216     place(a._, b._, c = circles[i]), c = new Node$1(c);
10217
10218     // Find the closest intersecting circle on the front-chain, if any.
10219     // “Closeness” is determined by linear distance along the front-chain.
10220     // “Ahead” or “behind” is likewise determined by linear distance.
10221     j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
10222     do {
10223       if (sj <= sk) {
10224         if (intersects(j._, c._)) {
10225           b = j, a.next = b, b.previous = a, --i;
10226           continue pack;
10227         }
10228         sj += j._.r, j = j.next;
10229       } else {
10230         if (intersects(k._, c._)) {
10231           a = k, a.next = b, b.previous = a, --i;
10232           continue pack;
10233         }
10234         sk += k._.r, k = k.previous;
10235       }
10236     } while (j !== k.next);
10237
10238     // Success! Insert the new circle c between a and b.
10239     c.previous = a, c.next = b, a.next = b.previous = b = c;
10240
10241     // Compute the new closest circle pair to the centroid.
10242     aa = score(a);
10243     while ((c = c.next) !== b) {
10244       if ((ca = score(c)) < aa) {
10245         a = c, aa = ca;
10246       }
10247     }
10248     b = a.next;
10249   }
10250
10251   // Compute the enclosing circle of the front chain.
10252   a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
10253
10254   // Translate the circles to put the enclosing circle around the origin.
10255   for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
10256
10257   return c.r;
10258 }
10259
10260 var siblings = function(circles) {
10261   packEnclose(circles);
10262   return circles;
10263 };
10264
10265 function optional(f) {
10266   return f == null ? null : required(f);
10267 }
10268
10269 function required(f) {
10270   if (typeof f !== "function") throw new Error;
10271   return f;
10272 }
10273
10274 function constantZero() {
10275   return 0;
10276 }
10277
10278 var constant$8 = function(x) {
10279   return function() {
10280     return x;
10281   };
10282 };
10283
10284 function defaultRadius$1(d) {
10285   return Math.sqrt(d.value);
10286 }
10287
10288 var index$2 = function() {
10289   var radius = null,
10290       dx = 1,
10291       dy = 1,
10292       padding = constantZero;
10293
10294   function pack(root) {
10295     root.x = dx / 2, root.y = dy / 2;
10296     if (radius) {
10297       root.eachBefore(radiusLeaf(radius))
10298           .eachAfter(packChildren(padding, 0.5))
10299           .eachBefore(translateChild(1));
10300     } else {
10301       root.eachBefore(radiusLeaf(defaultRadius$1))
10302           .eachAfter(packChildren(constantZero, 1))
10303           .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
10304           .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
10305     }
10306     return root;
10307   }
10308
10309   pack.radius = function(x) {
10310     return arguments.length ? (radius = optional(x), pack) : radius;
10311   };
10312
10313   pack.size = function(x) {
10314     return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
10315   };
10316
10317   pack.padding = function(x) {
10318     return arguments.length ? (padding = typeof x === "function" ? x : constant$8(+x), pack) : padding;
10319   };
10320
10321   return pack;
10322 };
10323
10324 function radiusLeaf(radius) {
10325   return function(node) {
10326     if (!node.children) {
10327       node.r = Math.max(0, +radius(node) || 0);
10328     }
10329   };
10330 }
10331
10332 function packChildren(padding, k) {
10333   return function(node) {
10334     if (children = node.children) {
10335       var children,
10336           i,
10337           n = children.length,
10338           r = padding(node) * k || 0,
10339           e;
10340
10341       if (r) for (i = 0; i < n; ++i) children[i].r += r;
10342       e = packEnclose(children);
10343       if (r) for (i = 0; i < n; ++i) children[i].r -= r;
10344       node.r = e + r;
10345     }
10346   };
10347 }
10348
10349 function translateChild(k) {
10350   return function(node) {
10351     var parent = node.parent;
10352     node.r *= k;
10353     if (parent) {
10354       node.x = parent.x + k * node.x;
10355       node.y = parent.y + k * node.y;
10356     }
10357   };
10358 }
10359
10360 var roundNode = function(node) {
10361   node.x0 = Math.round(node.x0);
10362   node.y0 = Math.round(node.y0);
10363   node.x1 = Math.round(node.x1);
10364   node.y1 = Math.round(node.y1);
10365 };
10366
10367 var treemapDice = function(parent, x0, y0, x1, y1) {
10368   var nodes = parent.children,
10369       node,
10370       i = -1,
10371       n = nodes.length,
10372       k = parent.value && (x1 - x0) / parent.value;
10373
10374   while (++i < n) {
10375     node = nodes[i], node.y0 = y0, node.y1 = y1;
10376     node.x0 = x0, node.x1 = x0 += node.value * k;
10377   }
10378 };
10379
10380 var partition = function() {
10381   var dx = 1,
10382       dy = 1,
10383       padding = 0,
10384       round = false;
10385
10386   function partition(root) {
10387     var n = root.height + 1;
10388     root.x0 =
10389     root.y0 = padding;
10390     root.x1 = dx;
10391     root.y1 = dy / n;
10392     root.eachBefore(positionNode(dy, n));
10393     if (round) root.eachBefore(roundNode);
10394     return root;
10395   }
10396
10397   function positionNode(dy, n) {
10398     return function(node) {
10399       if (node.children) {
10400         treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
10401       }
10402       var x0 = node.x0,
10403           y0 = node.y0,
10404           x1 = node.x1 - padding,
10405           y1 = node.y1 - padding;
10406       if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10407       if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10408       node.x0 = x0;
10409       node.y0 = y0;
10410       node.x1 = x1;
10411       node.y1 = y1;
10412     };
10413   }
10414
10415   partition.round = function(x) {
10416     return arguments.length ? (round = !!x, partition) : round;
10417   };
10418
10419   partition.size = function(x) {
10420     return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
10421   };
10422
10423   partition.padding = function(x) {
10424     return arguments.length ? (padding = +x, partition) : padding;
10425   };
10426
10427   return partition;
10428 };
10429
10430 var keyPrefix$1 = "$";
10431 var preroot = {depth: -1};
10432 var ambiguous = {};
10433
10434 function defaultId(d) {
10435   return d.id;
10436 }
10437
10438 function defaultParentId(d) {
10439   return d.parentId;
10440 }
10441
10442 var stratify = function() {
10443   var id = defaultId,
10444       parentId = defaultParentId;
10445
10446   function stratify(data) {
10447     var d,
10448         i,
10449         n = data.length,
10450         root,
10451         parent,
10452         node,
10453         nodes = new Array(n),
10454         nodeId,
10455         nodeKey,
10456         nodeByKey = {};
10457
10458     for (i = 0; i < n; ++i) {
10459       d = data[i], node = nodes[i] = new Node(d);
10460       if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
10461         nodeKey = keyPrefix$1 + (node.id = nodeId);
10462         nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
10463       }
10464     }
10465
10466     for (i = 0; i < n; ++i) {
10467       node = nodes[i], nodeId = parentId(data[i], i, data);
10468       if (nodeId == null || !(nodeId += "")) {
10469         if (root) throw new Error("multiple roots");
10470         root = node;
10471       } else {
10472         parent = nodeByKey[keyPrefix$1 + nodeId];
10473         if (!parent) throw new Error("missing: " + nodeId);
10474         if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
10475         if (parent.children) parent.children.push(node);
10476         else parent.children = [node];
10477         node.parent = parent;
10478       }
10479     }
10480
10481     if (!root) throw new Error("no root");
10482     root.parent = preroot;
10483     root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
10484     root.parent = null;
10485     if (n > 0) throw new Error("cycle");
10486
10487     return root;
10488   }
10489
10490   stratify.id = function(x) {
10491     return arguments.length ? (id = required(x), stratify) : id;
10492   };
10493
10494   stratify.parentId = function(x) {
10495     return arguments.length ? (parentId = required(x), stratify) : parentId;
10496   };
10497
10498   return stratify;
10499 };
10500
10501 function defaultSeparation$1(a, b) {
10502   return a.parent === b.parent ? 1 : 2;
10503 }
10504
10505 // function radialSeparation(a, b) {
10506 //   return (a.parent === b.parent ? 1 : 2) / a.depth;
10507 // }
10508
10509 // This function is used to traverse the left contour of a subtree (or
10510 // subforest). It returns the successor of v on this contour. This successor is
10511 // either given by the leftmost child of v or by the thread of v. The function
10512 // returns null if and only if v is on the highest level of its subtree.
10513 function nextLeft(v) {
10514   var children = v.children;
10515   return children ? children[0] : v.t;
10516 }
10517
10518 // This function works analogously to nextLeft.
10519 function nextRight(v) {
10520   var children = v.children;
10521   return children ? children[children.length - 1] : v.t;
10522 }
10523
10524 // Shifts the current subtree rooted at w+. This is done by increasing
10525 // prelim(w+) and mod(w+) by shift.
10526 function moveSubtree(wm, wp, shift) {
10527   var change = shift / (wp.i - wm.i);
10528   wp.c -= change;
10529   wp.s += shift;
10530   wm.c += change;
10531   wp.z += shift;
10532   wp.m += shift;
10533 }
10534
10535 // All other shifts, applied to the smaller subtrees between w- and w+, are
10536 // performed by this function. To prepare the shifts, we have to adjust
10537 // change(w+), shift(w+), and change(w-).
10538 function executeShifts(v) {
10539   var shift = 0,
10540       change = 0,
10541       children = v.children,
10542       i = children.length,
10543       w;
10544   while (--i >= 0) {
10545     w = children[i];
10546     w.z += shift;
10547     w.m += shift;
10548     shift += w.s + (change += w.c);
10549   }
10550 }
10551
10552 // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
10553 // returns the specified (default) ancestor.
10554 function nextAncestor(vim, v, ancestor) {
10555   return vim.a.parent === v.parent ? vim.a : ancestor;
10556 }
10557
10558 function TreeNode(node, i) {
10559   this._ = node;
10560   this.parent = null;
10561   this.children = null;
10562   this.A = null; // default ancestor
10563   this.a = this; // ancestor
10564   this.z = 0; // prelim
10565   this.m = 0; // mod
10566   this.c = 0; // change
10567   this.s = 0; // shift
10568   this.t = null; // thread
10569   this.i = i; // number
10570 }
10571
10572 TreeNode.prototype = Object.create(Node.prototype);
10573
10574 function treeRoot(root) {
10575   var tree = new TreeNode(root, 0),
10576       node,
10577       nodes = [tree],
10578       child,
10579       children,
10580       i,
10581       n;
10582
10583   while (node = nodes.pop()) {
10584     if (children = node._.children) {
10585       node.children = new Array(n = children.length);
10586       for (i = n - 1; i >= 0; --i) {
10587         nodes.push(child = node.children[i] = new TreeNode(children[i], i));
10588         child.parent = node;
10589       }
10590     }
10591   }
10592
10593   (tree.parent = new TreeNode(null, 0)).children = [tree];
10594   return tree;
10595 }
10596
10597 // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
10598 var tree = function() {
10599   var separation = defaultSeparation$1,
10600       dx = 1,
10601       dy = 1,
10602       nodeSize = null;
10603
10604   function tree(root) {
10605     var t = treeRoot(root);
10606
10607     // Compute the layout using Buchheim et al.’s algorithm.
10608     t.eachAfter(firstWalk), t.parent.m = -t.z;
10609     t.eachBefore(secondWalk);
10610
10611     // If a fixed node size is specified, scale x and y.
10612     if (nodeSize) root.eachBefore(sizeNode);
10613
10614     // If a fixed tree size is specified, scale x and y based on the extent.
10615     // Compute the left-most, right-most, and depth-most nodes for extents.
10616     else {
10617       var left = root,
10618           right = root,
10619           bottom = root;
10620       root.eachBefore(function(node) {
10621         if (node.x < left.x) left = node;
10622         if (node.x > right.x) right = node;
10623         if (node.depth > bottom.depth) bottom = node;
10624       });
10625       var s = left === right ? 1 : separation(left, right) / 2,
10626           tx = s - left.x,
10627           kx = dx / (right.x + s + tx),
10628           ky = dy / (bottom.depth || 1);
10629       root.eachBefore(function(node) {
10630         node.x = (node.x + tx) * kx;
10631         node.y = node.depth * ky;
10632       });
10633     }
10634
10635     return root;
10636   }
10637
10638   // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
10639   // applied recursively to the children of v, as well as the function
10640   // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
10641   // node v is placed to the midpoint of its outermost children.
10642   function firstWalk(v) {
10643     var children = v.children,
10644         siblings = v.parent.children,
10645         w = v.i ? siblings[v.i - 1] : null;
10646     if (children) {
10647       executeShifts(v);
10648       var midpoint = (children[0].z + children[children.length - 1].z) / 2;
10649       if (w) {
10650         v.z = w.z + separation(v._, w._);
10651         v.m = v.z - midpoint;
10652       } else {
10653         v.z = midpoint;
10654       }
10655     } else if (w) {
10656       v.z = w.z + separation(v._, w._);
10657     }
10658     v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
10659   }
10660
10661   // Computes all real x-coordinates by summing up the modifiers recursively.
10662   function secondWalk(v) {
10663     v._.x = v.z + v.parent.m;
10664     v.m += v.parent.m;
10665   }
10666
10667   // The core of the algorithm. Here, a new subtree is combined with the
10668   // previous subtrees. Threads are used to traverse the inside and outside
10669   // contours of the left and right subtree up to the highest common level. The
10670   // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
10671   // superscript o means outside and i means inside, the subscript - means left
10672   // subtree and + means right subtree. For summing up the modifiers along the
10673   // contour, we use respective variables si+, si-, so-, and so+. Whenever two
10674   // nodes of the inside contours conflict, we compute the left one of the
10675   // greatest uncommon ancestors using the function ANCESTOR and call MOVE
10676   // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
10677   // Finally, we add a new thread (if necessary).
10678   function apportion(v, w, ancestor) {
10679     if (w) {
10680       var vip = v,
10681           vop = v,
10682           vim = w,
10683           vom = vip.parent.children[0],
10684           sip = vip.m,
10685           sop = vop.m,
10686           sim = vim.m,
10687           som = vom.m,
10688           shift;
10689       while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
10690         vom = nextLeft(vom);
10691         vop = nextRight(vop);
10692         vop.a = v;
10693         shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
10694         if (shift > 0) {
10695           moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
10696           sip += shift;
10697           sop += shift;
10698         }
10699         sim += vim.m;
10700         sip += vip.m;
10701         som += vom.m;
10702         sop += vop.m;
10703       }
10704       if (vim && !nextRight(vop)) {
10705         vop.t = vim;
10706         vop.m += sim - sop;
10707       }
10708       if (vip && !nextLeft(vom)) {
10709         vom.t = vip;
10710         vom.m += sip - som;
10711         ancestor = v;
10712       }
10713     }
10714     return ancestor;
10715   }
10716
10717   function sizeNode(node) {
10718     node.x *= dx;
10719     node.y = node.depth * dy;
10720   }
10721
10722   tree.separation = function(x) {
10723     return arguments.length ? (separation = x, tree) : separation;
10724   };
10725
10726   tree.size = function(x) {
10727     return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
10728   };
10729
10730   tree.nodeSize = function(x) {
10731     return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
10732   };
10733
10734   return tree;
10735 };
10736
10737 var treemapSlice = function(parent, x0, y0, x1, y1) {
10738   var nodes = parent.children,
10739       node,
10740       i = -1,
10741       n = nodes.length,
10742       k = parent.value && (y1 - y0) / parent.value;
10743
10744   while (++i < n) {
10745     node = nodes[i], node.x0 = x0, node.x1 = x1;
10746     node.y0 = y0, node.y1 = y0 += node.value * k;
10747   }
10748 };
10749
10750 var phi = (1 + Math.sqrt(5)) / 2;
10751
10752 function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
10753   var rows = [],
10754       nodes = parent.children,
10755       row,
10756       nodeValue,
10757       i0 = 0,
10758       i1 = 0,
10759       n = nodes.length,
10760       dx, dy,
10761       value = parent.value,
10762       sumValue,
10763       minValue,
10764       maxValue,
10765       newRatio,
10766       minRatio,
10767       alpha,
10768       beta;
10769
10770   while (i0 < n) {
10771     dx = x1 - x0, dy = y1 - y0;
10772
10773     // Find the next non-empty node.
10774     do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
10775     minValue = maxValue = sumValue;
10776     alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
10777     beta = sumValue * sumValue * alpha;
10778     minRatio = Math.max(maxValue / beta, beta / minValue);
10779
10780     // Keep adding nodes while the aspect ratio maintains or improves.
10781     for (; i1 < n; ++i1) {
10782       sumValue += nodeValue = nodes[i1].value;
10783       if (nodeValue < minValue) minValue = nodeValue;
10784       if (nodeValue > maxValue) maxValue = nodeValue;
10785       beta = sumValue * sumValue * alpha;
10786       newRatio = Math.max(maxValue / beta, beta / minValue);
10787       if (newRatio > minRatio) { sumValue -= nodeValue; break; }
10788       minRatio = newRatio;
10789     }
10790
10791     // Position and record the row orientation.
10792     rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
10793     if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
10794     else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
10795     value -= sumValue, i0 = i1;
10796   }
10797
10798   return rows;
10799 }
10800
10801 var squarify = (function custom(ratio) {
10802
10803   function squarify(parent, x0, y0, x1, y1) {
10804     squarifyRatio(ratio, parent, x0, y0, x1, y1);
10805   }
10806
10807   squarify.ratio = function(x) {
10808     return custom((x = +x) > 1 ? x : 1);
10809   };
10810
10811   return squarify;
10812 })(phi);
10813
10814 var index$3 = function() {
10815   var tile = squarify,
10816       round = false,
10817       dx = 1,
10818       dy = 1,
10819       paddingStack = [0],
10820       paddingInner = constantZero,
10821       paddingTop = constantZero,
10822       paddingRight = constantZero,
10823       paddingBottom = constantZero,
10824       paddingLeft = constantZero;
10825
10826   function treemap(root) {
10827     root.x0 =
10828     root.y0 = 0;
10829     root.x1 = dx;
10830     root.y1 = dy;
10831     root.eachBefore(positionNode);
10832     paddingStack = [0];
10833     if (round) root.eachBefore(roundNode);
10834     return root;
10835   }
10836
10837   function positionNode(node) {
10838     var p = paddingStack[node.depth],
10839         x0 = node.x0 + p,
10840         y0 = node.y0 + p,
10841         x1 = node.x1 - p,
10842         y1 = node.y1 - p;
10843     if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10844     if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10845     node.x0 = x0;
10846     node.y0 = y0;
10847     node.x1 = x1;
10848     node.y1 = y1;
10849     if (node.children) {
10850       p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
10851       x0 += paddingLeft(node) - p;
10852       y0 += paddingTop(node) - p;
10853       x1 -= paddingRight(node) - p;
10854       y1 -= paddingBottom(node) - p;
10855       if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10856       if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10857       tile(node, x0, y0, x1, y1);
10858     }
10859   }
10860
10861   treemap.round = function(x) {
10862     return arguments.length ? (round = !!x, treemap) : round;
10863   };
10864
10865   treemap.size = function(x) {
10866     return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
10867   };
10868
10869   treemap.tile = function(x) {
10870     return arguments.length ? (tile = required(x), treemap) : tile;
10871   };
10872
10873   treemap.padding = function(x) {
10874     return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
10875   };
10876
10877   treemap.paddingInner = function(x) {
10878     return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$8(+x), treemap) : paddingInner;
10879   };
10880
10881   treemap.paddingOuter = function(x) {
10882     return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
10883   };
10884
10885   treemap.paddingTop = function(x) {
10886     return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$8(+x), treemap) : paddingTop;
10887   };
10888
10889   treemap.paddingRight = function(x) {
10890     return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$8(+x), treemap) : paddingRight;
10891   };
10892
10893   treemap.paddingBottom = function(x) {
10894     return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$8(+x), treemap) : paddingBottom;
10895   };
10896
10897   treemap.paddingLeft = function(x) {
10898     return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$8(+x), treemap) : paddingLeft;
10899   };
10900
10901   return treemap;
10902 };
10903
10904 var binary = function(parent, x0, y0, x1, y1) {
10905   var nodes = parent.children,
10906       i, n = nodes.length,
10907       sum, sums = new Array(n + 1);
10908
10909   for (sums[0] = sum = i = 0; i < n; ++i) {
10910     sums[i + 1] = sum += nodes[i].value;
10911   }
10912
10913   partition(0, n, parent.value, x0, y0, x1, y1);
10914
10915   function partition(i, j, value, x0, y0, x1, y1) {
10916     if (i >= j - 1) {
10917       var node = nodes[i];
10918       node.x0 = x0, node.y0 = y0;
10919       node.x1 = x1, node.y1 = y1;
10920       return;
10921     }
10922
10923     var valueOffset = sums[i],
10924         valueTarget = (value / 2) + valueOffset,
10925         k = i + 1,
10926         hi = j - 1;
10927
10928     while (k < hi) {
10929       var mid = k + hi >>> 1;
10930       if (sums[mid] < valueTarget) k = mid + 1;
10931       else hi = mid;
10932     }
10933
10934     if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
10935
10936     var valueLeft = sums[k] - valueOffset,
10937         valueRight = value - valueLeft;
10938
10939     if ((x1 - x0) > (y1 - y0)) {
10940       var xk = (x0 * valueRight + x1 * valueLeft) / value;
10941       partition(i, k, valueLeft, x0, y0, xk, y1);
10942       partition(k, j, valueRight, xk, y0, x1, y1);
10943     } else {
10944       var yk = (y0 * valueRight + y1 * valueLeft) / value;
10945       partition(i, k, valueLeft, x0, y0, x1, yk);
10946       partition(k, j, valueRight, x0, yk, x1, y1);
10947     }
10948   }
10949 };
10950
10951 var sliceDice = function(parent, x0, y0, x1, y1) {
10952   (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
10953 };
10954
10955 var resquarify = (function custom(ratio) {
10956
10957   function resquarify(parent, x0, y0, x1, y1) {
10958     if ((rows = parent._squarify) && (rows.ratio === ratio)) {
10959       var rows,
10960           row,
10961           nodes,
10962           i,
10963           j = -1,
10964           n,
10965           m = rows.length,
10966           value = parent.value;
10967
10968       while (++j < m) {
10969         row = rows[j], nodes = row.children;
10970         for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
10971         if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
10972         else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
10973         value -= row.value;
10974       }
10975     } else {
10976       parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
10977       rows.ratio = ratio;
10978     }
10979   }
10980
10981   resquarify.ratio = function(x) {
10982     return custom((x = +x) > 1 ? x : 1);
10983   };
10984
10985   return resquarify;
10986 })(phi);
10987
10988 var area$1 = function(polygon) {
10989   var i = -1,
10990       n = polygon.length,
10991       a,
10992       b = polygon[n - 1],
10993       area = 0;
10994
10995   while (++i < n) {
10996     a = b;
10997     b = polygon[i];
10998     area += a[1] * b[0] - a[0] * b[1];
10999   }
11000
11001   return area / 2;
11002 };
11003
11004 var centroid$1 = function(polygon) {
11005   var i = -1,
11006       n = polygon.length,
11007       x = 0,
11008       y = 0,
11009       a,
11010       b = polygon[n - 1],
11011       c,
11012       k = 0;
11013
11014   while (++i < n) {
11015     a = b;
11016     b = polygon[i];
11017     k += c = a[0] * b[1] - b[0] * a[1];
11018     x += (a[0] + b[0]) * c;
11019     y += (a[1] + b[1]) * c;
11020   }
11021
11022   return k *= 3, [x / k, y / k];
11023 };
11024
11025 // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
11026 // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
11027 // right, +y is up). Returns a positive value if ABC is counter-clockwise,
11028 // negative if clockwise, and zero if the points are collinear.
11029 var cross$1 = function(a, b, c) {
11030   return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
11031 };
11032
11033 function lexicographicOrder(a, b) {
11034   return a[0] - b[0] || a[1] - b[1];
11035 }
11036
11037 // Computes the upper convex hull per the monotone chain algorithm.
11038 // Assumes points.length >= 3, is sorted by x, unique in y.
11039 // Returns an array of indices into points in left-to-right order.
11040 function computeUpperHullIndexes(points) {
11041   var n = points.length,
11042       indexes = [0, 1],
11043       size = 2;
11044
11045   for (var i = 2; i < n; ++i) {
11046     while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
11047     indexes[size++] = i;
11048   }
11049
11050   return indexes.slice(0, size); // remove popped points
11051 }
11052
11053 var hull = function(points) {
11054   if ((n = points.length) < 3) return null;
11055
11056   var i,
11057       n,
11058       sortedPoints = new Array(n),
11059       flippedPoints = new Array(n);
11060
11061   for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
11062   sortedPoints.sort(lexicographicOrder);
11063   for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
11064
11065   var upperIndexes = computeUpperHullIndexes(sortedPoints),
11066       lowerIndexes = computeUpperHullIndexes(flippedPoints);
11067
11068   // Construct the hull polygon, removing possible duplicate endpoints.
11069   var skipLeft = lowerIndexes[0] === upperIndexes[0],
11070       skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
11071       hull = [];
11072
11073   // Add upper hull in right-to-l order.
11074   // Then add lower hull in left-to-right order.
11075   for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
11076   for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
11077
11078   return hull;
11079 };
11080
11081 var contains$1 = function(polygon, point) {
11082   var n = polygon.length,
11083       p = polygon[n - 1],
11084       x = point[0], y = point[1],
11085       x0 = p[0], y0 = p[1],
11086       x1, y1,
11087       inside = false;
11088
11089   for (var i = 0; i < n; ++i) {
11090     p = polygon[i], x1 = p[0], y1 = p[1];
11091     if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
11092     x0 = x1, y0 = y1;
11093   }
11094
11095   return inside;
11096 };
11097
11098 var length$2 = function(polygon) {
11099   var i = -1,
11100       n = polygon.length,
11101       b = polygon[n - 1],
11102       xa,
11103       ya,
11104       xb = b[0],
11105       yb = b[1],
11106       perimeter = 0;
11107
11108   while (++i < n) {
11109     xa = xb;
11110     ya = yb;
11111     b = polygon[i];
11112     xb = b[0];
11113     yb = b[1];
11114     xa -= xb;
11115     ya -= yb;
11116     perimeter += Math.sqrt(xa * xa + ya * ya);
11117   }
11118
11119   return perimeter;
11120 };
11121
11122 var slice$4 = [].slice;
11123
11124 var noabort = {};
11125
11126 function Queue(size) {
11127   this._size = size;
11128   this._call =
11129   this._error = null;
11130   this._tasks = [];
11131   this._data = [];
11132   this._waiting =
11133   this._active =
11134   this._ended =
11135   this._start = 0; // inside a synchronous task callback?
11136 }
11137
11138 Queue.prototype = queue.prototype = {
11139   constructor: Queue,
11140   defer: function(callback) {
11141     if (typeof callback !== "function") throw new Error("invalid callback");
11142     if (this._call) throw new Error("defer after await");
11143     if (this._error != null) return this;
11144     var t = slice$4.call(arguments, 1);
11145     t.push(callback);
11146     ++this._waiting, this._tasks.push(t);
11147     poke$1(this);
11148     return this;
11149   },
11150   abort: function() {
11151     if (this._error == null) abort(this, new Error("abort"));
11152     return this;
11153   },
11154   await: function(callback) {
11155     if (typeof callback !== "function") throw new Error("invalid callback");
11156     if (this._call) throw new Error("multiple await");
11157     this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
11158     maybeNotify(this);
11159     return this;
11160   },
11161   awaitAll: function(callback) {
11162     if (typeof callback !== "function") throw new Error("invalid callback");
11163     if (this._call) throw new Error("multiple await");
11164     this._call = callback;
11165     maybeNotify(this);
11166     return this;
11167   }
11168 };
11169
11170 function poke$1(q) {
11171   if (!q._start) {
11172     try { start$1(q); } // let the current task complete
11173     catch (e) {
11174       if (q._tasks[q._ended + q._active - 1]) abort(q, e); // task errored synchronously
11175       else if (!q._data) throw e; // await callback errored synchronously
11176     }
11177   }
11178 }
11179
11180 function start$1(q) {
11181   while (q._start = q._waiting && q._active < q._size) {
11182     var i = q._ended + q._active,
11183         t = q._tasks[i],
11184         j = t.length - 1,
11185         c = t[j];
11186     t[j] = end(q, i);
11187     --q._waiting, ++q._active;
11188     t = c.apply(null, t);
11189     if (!q._tasks[i]) continue; // task finished synchronously
11190     q._tasks[i] = t || noabort;
11191   }
11192 }
11193
11194 function end(q, i) {
11195   return function(e, r) {
11196     if (!q._tasks[i]) return; // ignore multiple callbacks
11197     --q._active, ++q._ended;
11198     q._tasks[i] = null;
11199     if (q._error != null) return; // ignore secondary errors
11200     if (e != null) {
11201       abort(q, e);
11202     } else {
11203       q._data[i] = r;
11204       if (q._waiting) poke$1(q);
11205       else maybeNotify(q);
11206     }
11207   };
11208 }
11209
11210 function abort(q, e) {
11211   var i = q._tasks.length, t;
11212   q._error = e; // ignore active callbacks
11213   q._data = undefined; // allow gc
11214   q._waiting = NaN; // prevent starting
11215
11216   while (--i >= 0) {
11217     if (t = q._tasks[i]) {
11218       q._tasks[i] = null;
11219       if (t.abort) {
11220         try { t.abort(); }
11221         catch (e) { /* ignore */ }
11222       }
11223     }
11224   }
11225
11226   q._active = NaN; // allow notification
11227   maybeNotify(q);
11228 }
11229
11230 function maybeNotify(q) {
11231   if (!q._active && q._call) {
11232     var d = q._data;
11233     q._data = undefined; // allow gc
11234     q._call(q._error, d);
11235   }
11236 }
11237
11238 function queue(concurrency) {
11239   if (concurrency == null) concurrency = Infinity;
11240   else if (!((concurrency = +concurrency) >= 1)) throw new Error("invalid concurrency");
11241   return new Queue(concurrency);
11242 }
11243
11244 var defaultSource$1 = function() {
11245   return Math.random();
11246 };
11247
11248 var uniform = (function sourceRandomUniform(source) {
11249   function randomUniform(min, max) {
11250     min = min == null ? 0 : +min;
11251     max = max == null ? 1 : +max;
11252     if (arguments.length === 1) max = min, min = 0;
11253     else max -= min;
11254     return function() {
11255       return source() * max + min;
11256     };
11257   }
11258
11259   randomUniform.source = sourceRandomUniform;
11260
11261   return randomUniform;
11262 })(defaultSource$1);
11263
11264 var normal = (function sourceRandomNormal(source) {
11265   function randomNormal(mu, sigma) {
11266     var x, r;
11267     mu = mu == null ? 0 : +mu;
11268     sigma = sigma == null ? 1 : +sigma;
11269     return function() {
11270       var y;
11271
11272       // If available, use the second previously-generated uniform random.
11273       if (x != null) y = x, x = null;
11274
11275       // Otherwise, generate a new x and y.
11276       else do {
11277         x = source() * 2 - 1;
11278         y = source() * 2 - 1;
11279         r = x * x + y * y;
11280       } while (!r || r > 1);
11281
11282       return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
11283     };
11284   }
11285
11286   randomNormal.source = sourceRandomNormal;
11287
11288   return randomNormal;
11289 })(defaultSource$1);
11290
11291 var logNormal = (function sourceRandomLogNormal(source) {
11292   function randomLogNormal() {
11293     var randomNormal = normal.source(source).apply(this, arguments);
11294     return function() {
11295       return Math.exp(randomNormal());
11296     };
11297   }
11298
11299   randomLogNormal.source = sourceRandomLogNormal;
11300
11301   return randomLogNormal;
11302 })(defaultSource$1);
11303
11304 var irwinHall = (function sourceRandomIrwinHall(source) {
11305   function randomIrwinHall(n) {
11306     return function() {
11307       for (var sum = 0, i = 0; i < n; ++i) sum += source();
11308       return sum;
11309     };
11310   }
11311
11312   randomIrwinHall.source = sourceRandomIrwinHall;
11313
11314   return randomIrwinHall;
11315 })(defaultSource$1);
11316
11317 var bates = (function sourceRandomBates(source) {
11318   function randomBates(n) {
11319     var randomIrwinHall = irwinHall.source(source)(n);
11320     return function() {
11321       return randomIrwinHall() / n;
11322     };
11323   }
11324
11325   randomBates.source = sourceRandomBates;
11326
11327   return randomBates;
11328 })(defaultSource$1);
11329
11330 var exponential$1 = (function sourceRandomExponential(source) {
11331   function randomExponential(lambda) {
11332     return function() {
11333       return -Math.log(1 - source()) / lambda;
11334     };
11335   }
11336
11337   randomExponential.source = sourceRandomExponential;
11338
11339   return randomExponential;
11340 })(defaultSource$1);
11341
11342 var request = function(url, callback) {
11343   var request,
11344       event = dispatch("beforesend", "progress", "load", "error"),
11345       mimeType,
11346       headers = map$1(),
11347       xhr = new XMLHttpRequest,
11348       user = null,
11349       password = null,
11350       response,
11351       responseType,
11352       timeout = 0;
11353
11354   // If IE does not support CORS, use XDomainRequest.
11355   if (typeof XDomainRequest !== "undefined"
11356       && !("withCredentials" in xhr)
11357       && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
11358
11359   "onload" in xhr
11360       ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
11361       : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
11362
11363   function respond(o) {
11364     var status = xhr.status, result;
11365     if (!status && hasResponse(xhr)
11366         || status >= 200 && status < 300
11367         || status === 304) {
11368       if (response) {
11369         try {
11370           result = response.call(request, xhr);
11371         } catch (e) {
11372           event.call("error", request, e);
11373           return;
11374         }
11375       } else {
11376         result = xhr;
11377       }
11378       event.call("load", request, result);
11379     } else {
11380       event.call("error", request, o);
11381     }
11382   }
11383
11384   xhr.onprogress = function(e) {
11385     event.call("progress", request, e);
11386   };
11387
11388   request = {
11389     header: function(name, value) {
11390       name = (name + "").toLowerCase();
11391       if (arguments.length < 2) return headers.get(name);
11392       if (value == null) headers.remove(name);
11393       else headers.set(name, value + "");
11394       return request;
11395     },
11396
11397     // If mimeType is non-null and no Accept header is set, a default is used.
11398     mimeType: function(value) {
11399       if (!arguments.length) return mimeType;
11400       mimeType = value == null ? null : value + "";
11401       return request;
11402     },
11403
11404     // Specifies what type the response value should take;
11405     // for instance, arraybuffer, blob, document, or text.
11406     responseType: function(value) {
11407       if (!arguments.length) return responseType;
11408       responseType = value;
11409       return request;
11410     },
11411
11412     timeout: function(value) {
11413       if (!arguments.length) return timeout;
11414       timeout = +value;
11415       return request;
11416     },
11417
11418     user: function(value) {
11419       return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
11420     },
11421
11422     password: function(value) {
11423       return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
11424     },
11425
11426     // Specify how to convert the response content to a specific type;
11427     // changes the callback value on "load" events.
11428     response: function(value) {
11429       response = value;
11430       return request;
11431     },
11432
11433     // Alias for send("GET", …).
11434     get: function(data, callback) {
11435       return request.send("GET", data, callback);
11436     },
11437
11438     // Alias for send("POST", …).
11439     post: function(data, callback) {
11440       return request.send("POST", data, callback);
11441     },
11442
11443     // If callback is non-null, it will be used for error and load events.
11444     send: function(method, data, callback) {
11445       xhr.open(method, url, true, user, password);
11446       if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
11447       if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
11448       if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
11449       if (responseType != null) xhr.responseType = responseType;
11450       if (timeout > 0) xhr.timeout = timeout;
11451       if (callback == null && typeof data === "function") callback = data, data = null;
11452       if (callback != null && callback.length === 1) callback = fixCallback(callback);
11453       if (callback != null) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
11454       event.call("beforesend", request, xhr);
11455       xhr.send(data == null ? null : data);
11456       return request;
11457     },
11458
11459     abort: function() {
11460       xhr.abort();
11461       return request;
11462     },
11463
11464     on: function() {
11465       var value = event.on.apply(event, arguments);
11466       return value === event ? request : value;
11467     }
11468   };
11469
11470   if (callback != null) {
11471     if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
11472     return request.get(callback);
11473   }
11474
11475   return request;
11476 };
11477
11478 function fixCallback(callback) {
11479   return function(error, xhr) {
11480     callback(error == null ? xhr : null);
11481   };
11482 }
11483
11484 function hasResponse(xhr) {
11485   var type = xhr.responseType;
11486   return type && type !== "text"
11487       ? xhr.response // null on error
11488       : xhr.responseText; // "" on error
11489 }
11490
11491 var type$1 = function(defaultMimeType, response) {
11492   return function(url, callback) {
11493     var r = request(url).mimeType(defaultMimeType).response(response);
11494     if (callback != null) {
11495       if (typeof callback !== "function") throw new Error("invalid callback: " + callback);
11496       return r.get(callback);
11497     }
11498     return r;
11499   };
11500 };
11501
11502 var html = type$1("text/html", function(xhr) {
11503   return document.createRange().createContextualFragment(xhr.responseText);
11504 });
11505
11506 var json = type$1("application/json", function(xhr) {
11507   return JSON.parse(xhr.responseText);
11508 });
11509
11510 var text = type$1("text/plain", function(xhr) {
11511   return xhr.responseText;
11512 });
11513
11514 var xml = type$1("application/xml", function(xhr) {
11515   var xml = xhr.responseXML;
11516   if (!xml) throw new Error("parse error");
11517   return xml;
11518 });
11519
11520 var dsv$1 = function(defaultMimeType, parse) {
11521   return function(url, row, callback) {
11522     if (arguments.length < 3) callback = row, row = null;
11523     var r = request(url).mimeType(defaultMimeType);
11524     r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
11525     r.row(row);
11526     return callback ? r.get(callback) : r;
11527   };
11528 };
11529
11530 function responseOf(parse, row) {
11531   return function(request$$1) {
11532     return parse(request$$1.responseText, row);
11533   };
11534 }
11535
11536 var csv$1 = dsv$1("text/csv", csvParse);
11537
11538 var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
11539
11540 var array$2 = Array.prototype;
11541
11542 var map$3 = array$2.map;
11543 var slice$5 = array$2.slice;
11544
11545 var implicit = {name: "implicit"};
11546
11547 function ordinal(range) {
11548   var index = map$1(),
11549       domain = [],
11550       unknown = implicit;
11551
11552   range = range == null ? [] : slice$5.call(range);
11553
11554   function scale(d) {
11555     var key = d + "", i = index.get(key);
11556     if (!i) {
11557       if (unknown !== implicit) return unknown;
11558       index.set(key, i = domain.push(d));
11559     }
11560     return range[(i - 1) % range.length];
11561   }
11562
11563   scale.domain = function(_) {
11564     if (!arguments.length) return domain.slice();
11565     domain = [], index = map$1();
11566     var i = -1, n = _.length, d, key;
11567     while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
11568     return scale;
11569   };
11570
11571   scale.range = function(_) {
11572     return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
11573   };
11574
11575   scale.unknown = function(_) {
11576     return arguments.length ? (unknown = _, scale) : unknown;
11577   };
11578
11579   scale.copy = function() {
11580     return ordinal()
11581         .domain(domain)
11582         .range(range)
11583         .unknown(unknown);
11584   };
11585
11586   return scale;
11587 }
11588
11589 function band() {
11590   var scale = ordinal().unknown(undefined),
11591       domain = scale.domain,
11592       ordinalRange = scale.range,
11593       range$$1 = [0, 1],
11594       step,
11595       bandwidth,
11596       round = false,
11597       paddingInner = 0,
11598       paddingOuter = 0,
11599       align = 0.5;
11600
11601   delete scale.unknown;
11602
11603   function rescale() {
11604     var n = domain().length,
11605         reverse = range$$1[1] < range$$1[0],
11606         start = range$$1[reverse - 0],
11607         stop = range$$1[1 - reverse];
11608     step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
11609     if (round) step = Math.floor(step);
11610     start += (stop - start - step * (n - paddingInner)) * align;
11611     bandwidth = step * (1 - paddingInner);
11612     if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
11613     var values = sequence(n).map(function(i) { return start + step * i; });
11614     return ordinalRange(reverse ? values.reverse() : values);
11615   }
11616
11617   scale.domain = function(_) {
11618     return arguments.length ? (domain(_), rescale()) : domain();
11619   };
11620
11621   scale.range = function(_) {
11622     return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
11623   };
11624
11625   scale.rangeRound = function(_) {
11626     return range$$1 = [+_[0], +_[1]], round = true, rescale();
11627   };
11628
11629   scale.bandwidth = function() {
11630     return bandwidth;
11631   };
11632
11633   scale.step = function() {
11634     return step;
11635   };
11636
11637   scale.round = function(_) {
11638     return arguments.length ? (round = !!_, rescale()) : round;
11639   };
11640
11641   scale.padding = function(_) {
11642     return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11643   };
11644
11645   scale.paddingInner = function(_) {
11646     return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11647   };
11648
11649   scale.paddingOuter = function(_) {
11650     return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
11651   };
11652
11653   scale.align = function(_) {
11654     return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
11655   };
11656
11657   scale.copy = function() {
11658     return band()
11659         .domain(domain())
11660         .range(range$$1)
11661         .round(round)
11662         .paddingInner(paddingInner)
11663         .paddingOuter(paddingOuter)
11664         .align(align);
11665   };
11666
11667   return rescale();
11668 }
11669
11670 function pointish(scale) {
11671   var copy = scale.copy;
11672
11673   scale.padding = scale.paddingOuter;
11674   delete scale.paddingInner;
11675   delete scale.paddingOuter;
11676
11677   scale.copy = function() {
11678     return pointish(copy());
11679   };
11680
11681   return scale;
11682 }
11683
11684 function point$1() {
11685   return pointish(band().paddingInner(1));
11686 }
11687
11688 var constant$9 = function(x) {
11689   return function() {
11690     return x;
11691   };
11692 };
11693
11694 var number$2 = function(x) {
11695   return +x;
11696 };
11697
11698 var unit = [0, 1];
11699
11700 function deinterpolateLinear(a, b) {
11701   return (b -= (a = +a))
11702       ? function(x) { return (x - a) / b; }
11703       : constant$9(b);
11704 }
11705
11706 function deinterpolateClamp(deinterpolate) {
11707   return function(a, b) {
11708     var d = deinterpolate(a = +a, b = +b);
11709     return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
11710   };
11711 }
11712
11713 function reinterpolateClamp(reinterpolate) {
11714   return function(a, b) {
11715     var r = reinterpolate(a = +a, b = +b);
11716     return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
11717   };
11718 }
11719
11720 function bimap(domain, range, deinterpolate, reinterpolate) {
11721   var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
11722   if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
11723   else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
11724   return function(x) { return r0(d0(x)); };
11725 }
11726
11727 function polymap(domain, range, deinterpolate, reinterpolate) {
11728   var j = Math.min(domain.length, range.length) - 1,
11729       d = new Array(j),
11730       r = new Array(j),
11731       i = -1;
11732
11733   // Reverse descending domains.
11734   if (domain[j] < domain[0]) {
11735     domain = domain.slice().reverse();
11736     range = range.slice().reverse();
11737   }
11738
11739   while (++i < j) {
11740     d[i] = deinterpolate(domain[i], domain[i + 1]);
11741     r[i] = reinterpolate(range[i], range[i + 1]);
11742   }
11743
11744   return function(x) {
11745     var i = bisectRight(domain, x, 1, j) - 1;
11746     return r[i](d[i](x));
11747   };
11748 }
11749
11750 function copy(source, target) {
11751   return target
11752       .domain(source.domain())
11753       .range(source.range())
11754       .interpolate(source.interpolate())
11755       .clamp(source.clamp());
11756 }
11757
11758 // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
11759 // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
11760 function continuous(deinterpolate, reinterpolate) {
11761   var domain = unit,
11762       range = unit,
11763       interpolate$$1 = interpolateValue,
11764       clamp = false,
11765       piecewise,
11766       output,
11767       input;
11768
11769   function rescale() {
11770     piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
11771     output = input = null;
11772     return scale;
11773   }
11774
11775   function scale(x) {
11776     return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
11777   }
11778
11779   scale.invert = function(y) {
11780     return (input || (input = piecewise(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
11781   };
11782
11783   scale.domain = function(_) {
11784     return arguments.length ? (domain = map$3.call(_, number$2), rescale()) : domain.slice();
11785   };
11786
11787   scale.range = function(_) {
11788     return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
11789   };
11790
11791   scale.rangeRound = function(_) {
11792     return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
11793   };
11794
11795   scale.clamp = function(_) {
11796     return arguments.length ? (clamp = !!_, rescale()) : clamp;
11797   };
11798
11799   scale.interpolate = function(_) {
11800     return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
11801   };
11802
11803   return rescale();
11804 }
11805
11806 var tickFormat = function(domain, count, specifier) {
11807   var start = domain[0],
11808       stop = domain[domain.length - 1],
11809       step = tickStep(start, stop, count == null ? 10 : count),
11810       precision;
11811   specifier = formatSpecifier(specifier == null ? ",f" : specifier);
11812   switch (specifier.type) {
11813     case "s": {
11814       var value = Math.max(Math.abs(start), Math.abs(stop));
11815       if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
11816       return exports.formatPrefix(specifier, value);
11817     }
11818     case "":
11819     case "e":
11820     case "g":
11821     case "p":
11822     case "r": {
11823       if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
11824       break;
11825     }
11826     case "f":
11827     case "%": {
11828       if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
11829       break;
11830     }
11831   }
11832   return exports.format(specifier);
11833 };
11834
11835 function linearish(scale) {
11836   var domain = scale.domain;
11837
11838   scale.ticks = function(count) {
11839     var d = domain();
11840     return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
11841   };
11842
11843   scale.tickFormat = function(count, specifier) {
11844     return tickFormat(domain(), count, specifier);
11845   };
11846
11847   scale.nice = function(count) {
11848     if (count == null) count = 10;
11849
11850     var d = domain(),
11851         i0 = 0,
11852         i1 = d.length - 1,
11853         start = d[i0],
11854         stop = d[i1],
11855         step;
11856
11857     if (stop < start) {
11858       step = start, start = stop, stop = step;
11859       step = i0, i0 = i1, i1 = step;
11860     }
11861
11862     step = tickIncrement(start, stop, count);
11863
11864     if (step > 0) {
11865       start = Math.floor(start / step) * step;
11866       stop = Math.ceil(stop / step) * step;
11867       step = tickIncrement(start, stop, count);
11868     } else if (step < 0) {
11869       start = Math.ceil(start * step) / step;
11870       stop = Math.floor(stop * step) / step;
11871       step = tickIncrement(start, stop, count);
11872     }
11873
11874     if (step > 0) {
11875       d[i0] = Math.floor(start / step) * step;
11876       d[i1] = Math.ceil(stop / step) * step;
11877       domain(d);
11878     } else if (step < 0) {
11879       d[i0] = Math.ceil(start * step) / step;
11880       d[i1] = Math.floor(stop * step) / step;
11881       domain(d);
11882     }
11883
11884     return scale;
11885   };
11886
11887   return scale;
11888 }
11889
11890 function linear$2() {
11891   var scale = continuous(deinterpolateLinear, reinterpolate);
11892
11893   scale.copy = function() {
11894     return copy(scale, linear$2());
11895   };
11896
11897   return linearish(scale);
11898 }
11899
11900 function identity$6() {
11901   var domain = [0, 1];
11902
11903   function scale(x) {
11904     return +x;
11905   }
11906
11907   scale.invert = scale;
11908
11909   scale.domain = scale.range = function(_) {
11910     return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
11911   };
11912
11913   scale.copy = function() {
11914     return identity$6().domain(domain);
11915   };
11916
11917   return linearish(scale);
11918 }
11919
11920 var nice = function(domain, interval) {
11921   domain = domain.slice();
11922
11923   var i0 = 0,
11924       i1 = domain.length - 1,
11925       x0 = domain[i0],
11926       x1 = domain[i1],
11927       t;
11928
11929   if (x1 < x0) {
11930     t = i0, i0 = i1, i1 = t;
11931     t = x0, x0 = x1, x1 = t;
11932   }
11933
11934   domain[i0] = interval.floor(x0);
11935   domain[i1] = interval.ceil(x1);
11936   return domain;
11937 };
11938
11939 function deinterpolate(a, b) {
11940   return (b = Math.log(b / a))
11941       ? function(x) { return Math.log(x / a) / b; }
11942       : constant$9(b);
11943 }
11944
11945 function reinterpolate$1(a, b) {
11946   return a < 0
11947       ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
11948       : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
11949 }
11950
11951 function pow10(x) {
11952   return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
11953 }
11954
11955 function powp(base) {
11956   return base === 10 ? pow10
11957       : base === Math.E ? Math.exp
11958       : function(x) { return Math.pow(base, x); };
11959 }
11960
11961 function logp(base) {
11962   return base === Math.E ? Math.log
11963       : base === 10 && Math.log10
11964       || base === 2 && Math.log2
11965       || (base = Math.log(base), function(x) { return Math.log(x) / base; });
11966 }
11967
11968 function reflect(f) {
11969   return function(x) {
11970     return -f(-x);
11971   };
11972 }
11973
11974 function log$1() {
11975   var scale = continuous(deinterpolate, reinterpolate$1).domain([1, 10]),
11976       domain = scale.domain,
11977       base = 10,
11978       logs = logp(10),
11979       pows = powp(10);
11980
11981   function rescale() {
11982     logs = logp(base), pows = powp(base);
11983     if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
11984     return scale;
11985   }
11986
11987   scale.base = function(_) {
11988     return arguments.length ? (base = +_, rescale()) : base;
11989   };
11990
11991   scale.domain = function(_) {
11992     return arguments.length ? (domain(_), rescale()) : domain();
11993   };
11994
11995   scale.ticks = function(count) {
11996     var d = domain(),
11997         u = d[0],
11998         v = d[d.length - 1],
11999         r;
12000
12001     if (r = v < u) i = u, u = v, v = i;
12002
12003     var i = logs(u),
12004         j = logs(v),
12005         p,
12006         k,
12007         t,
12008         n = count == null ? 10 : +count,
12009         z = [];
12010
12011     if (!(base % 1) && j - i < n) {
12012       i = Math.round(i) - 1, j = Math.round(j) + 1;
12013       if (u > 0) for (; i < j; ++i) {
12014         for (k = 1, p = pows(i); k < base; ++k) {
12015           t = p * k;
12016           if (t < u) continue;
12017           if (t > v) break;
12018           z.push(t);
12019         }
12020       } else for (; i < j; ++i) {
12021         for (k = base - 1, p = pows(i); k >= 1; --k) {
12022           t = p * k;
12023           if (t < u) continue;
12024           if (t > v) break;
12025           z.push(t);
12026         }
12027       }
12028     } else {
12029       z = ticks(i, j, Math.min(j - i, n)).map(pows);
12030     }
12031
12032     return r ? z.reverse() : z;
12033   };
12034
12035   scale.tickFormat = function(count, specifier) {
12036     if (specifier == null) specifier = base === 10 ? ".0e" : ",";
12037     if (typeof specifier !== "function") specifier = exports.format(specifier);
12038     if (count === Infinity) return specifier;
12039     if (count == null) count = 10;
12040     var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
12041     return function(d) {
12042       var i = d / pows(Math.round(logs(d)));
12043       if (i * base < base - 0.5) i *= base;
12044       return i <= k ? specifier(d) : "";
12045     };
12046   };
12047
12048   scale.nice = function() {
12049     return domain(nice(domain(), {
12050       floor: function(x) { return pows(Math.floor(logs(x))); },
12051       ceil: function(x) { return pows(Math.ceil(logs(x))); }
12052     }));
12053   };
12054
12055   scale.copy = function() {
12056     return copy(scale, log$1().base(base));
12057   };
12058
12059   return scale;
12060 }
12061
12062 function raise$1(x, exponent) {
12063   return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
12064 }
12065
12066 function pow$1() {
12067   var exponent = 1,
12068       scale = continuous(deinterpolate, reinterpolate),
12069       domain = scale.domain;
12070
12071   function deinterpolate(a, b) {
12072     return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
12073         ? function(x) { return (raise$1(x, exponent) - a) / b; }
12074         : constant$9(b);
12075   }
12076
12077   function reinterpolate(a, b) {
12078     b = raise$1(b, exponent) - (a = raise$1(a, exponent));
12079     return function(t) { return raise$1(a + b * t, 1 / exponent); };
12080   }
12081
12082   scale.exponent = function(_) {
12083     return arguments.length ? (exponent = +_, domain(domain())) : exponent;
12084   };
12085
12086   scale.copy = function() {
12087     return copy(scale, pow$1().exponent(exponent));
12088   };
12089
12090   return linearish(scale);
12091 }
12092
12093 function sqrt$1() {
12094   return pow$1().exponent(0.5);
12095 }
12096
12097 function quantile$$1() {
12098   var domain = [],
12099       range = [],
12100       thresholds = [];
12101
12102   function rescale() {
12103     var i = 0, n = Math.max(1, range.length);
12104     thresholds = new Array(n - 1);
12105     while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
12106     return scale;
12107   }
12108
12109   function scale(x) {
12110     if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
12111   }
12112
12113   scale.invertExtent = function(y) {
12114     var i = range.indexOf(y);
12115     return i < 0 ? [NaN, NaN] : [
12116       i > 0 ? thresholds[i - 1] : domain[0],
12117       i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
12118     ];
12119   };
12120
12121   scale.domain = function(_) {
12122     if (!arguments.length) return domain.slice();
12123     domain = [];
12124     for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
12125     domain.sort(ascending);
12126     return rescale();
12127   };
12128
12129   scale.range = function(_) {
12130     return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12131   };
12132
12133   scale.quantiles = function() {
12134     return thresholds.slice();
12135   };
12136
12137   scale.copy = function() {
12138     return quantile$$1()
12139         .domain(domain)
12140         .range(range);
12141   };
12142
12143   return scale;
12144 }
12145
12146 function quantize$1() {
12147   var x0 = 0,
12148       x1 = 1,
12149       n = 1,
12150       domain = [0.5],
12151       range = [0, 1];
12152
12153   function scale(x) {
12154     if (x <= x) return range[bisectRight(domain, x, 0, n)];
12155   }
12156
12157   function rescale() {
12158     var i = -1;
12159     domain = new Array(n);
12160     while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
12161     return scale;
12162   }
12163
12164   scale.domain = function(_) {
12165     return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
12166   };
12167
12168   scale.range = function(_) {
12169     return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
12170   };
12171
12172   scale.invertExtent = function(y) {
12173     var i = range.indexOf(y);
12174     return i < 0 ? [NaN, NaN]
12175         : i < 1 ? [x0, domain[0]]
12176         : i >= n ? [domain[n - 1], x1]
12177         : [domain[i - 1], domain[i]];
12178   };
12179
12180   scale.copy = function() {
12181     return quantize$1()
12182         .domain([x0, x1])
12183         .range(range);
12184   };
12185
12186   return linearish(scale);
12187 }
12188
12189 function threshold$1() {
12190   var domain = [0.5],
12191       range = [0, 1],
12192       n = 1;
12193
12194   function scale(x) {
12195     if (x <= x) return range[bisectRight(domain, x, 0, n)];
12196   }
12197
12198   scale.domain = function(_) {
12199     return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
12200   };
12201
12202   scale.range = function(_) {
12203     return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
12204   };
12205
12206   scale.invertExtent = function(y) {
12207     var i = range.indexOf(y);
12208     return [domain[i - 1], domain[i]];
12209   };
12210
12211   scale.copy = function() {
12212     return threshold$1()
12213         .domain(domain)
12214         .range(range);
12215   };
12216
12217   return scale;
12218 }
12219
12220 var t0$1 = new Date;
12221 var t1$1 = new Date;
12222
12223 function newInterval(floori, offseti, count, field) {
12224
12225   function interval(date) {
12226     return floori(date = new Date(+date)), date;
12227   }
12228
12229   interval.floor = interval;
12230
12231   interval.ceil = function(date) {
12232     return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
12233   };
12234
12235   interval.round = function(date) {
12236     var d0 = interval(date),
12237         d1 = interval.ceil(date);
12238     return date - d0 < d1 - date ? d0 : d1;
12239   };
12240
12241   interval.offset = function(date, step) {
12242     return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
12243   };
12244
12245   interval.range = function(start, stop, step) {
12246     var range = [], previous;
12247     start = interval.ceil(start);
12248     step = step == null ? 1 : Math.floor(step);
12249     if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
12250     do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
12251     while (previous < start && start < stop);
12252     return range;
12253   };
12254
12255   interval.filter = function(test) {
12256     return newInterval(function(date) {
12257       if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
12258     }, function(date, step) {
12259       if (date >= date) {
12260         if (step < 0) while (++step <= 0) {
12261           while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
12262         } else while (--step >= 0) {
12263           while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
12264         }
12265       }
12266     });
12267   };
12268
12269   if (count) {
12270     interval.count = function(start, end) {
12271       t0$1.setTime(+start), t1$1.setTime(+end);
12272       floori(t0$1), floori(t1$1);
12273       return Math.floor(count(t0$1, t1$1));
12274     };
12275
12276     interval.every = function(step) {
12277       step = Math.floor(step);
12278       return !isFinite(step) || !(step > 0) ? null
12279           : !(step > 1) ? interval
12280           : interval.filter(field
12281               ? function(d) { return field(d) % step === 0; }
12282               : function(d) { return interval.count(0, d) % step === 0; });
12283     };
12284   }
12285
12286   return interval;
12287 }
12288
12289 var millisecond = newInterval(function() {
12290   // noop
12291 }, function(date, step) {
12292   date.setTime(+date + step);
12293 }, function(start, end) {
12294   return end - start;
12295 });
12296
12297 // An optimized implementation for this simple case.
12298 millisecond.every = function(k) {
12299   k = Math.floor(k);
12300   if (!isFinite(k) || !(k > 0)) return null;
12301   if (!(k > 1)) return millisecond;
12302   return newInterval(function(date) {
12303     date.setTime(Math.floor(date / k) * k);
12304   }, function(date, step) {
12305     date.setTime(+date + step * k);
12306   }, function(start, end) {
12307     return (end - start) / k;
12308   });
12309 };
12310
12311 var milliseconds = millisecond.range;
12312
12313 var durationSecond$1 = 1e3;
12314 var durationMinute$1 = 6e4;
12315 var durationHour$1 = 36e5;
12316 var durationDay$1 = 864e5;
12317 var durationWeek$1 = 6048e5;
12318
12319 var second = newInterval(function(date) {
12320   date.setTime(Math.floor(date / durationSecond$1) * durationSecond$1);
12321 }, function(date, step) {
12322   date.setTime(+date + step * durationSecond$1);
12323 }, function(start, end) {
12324   return (end - start) / durationSecond$1;
12325 }, function(date) {
12326   return date.getUTCSeconds();
12327 });
12328
12329 var seconds = second.range;
12330
12331 var minute = newInterval(function(date) {
12332   date.setTime(Math.floor(date / durationMinute$1) * durationMinute$1);
12333 }, function(date, step) {
12334   date.setTime(+date + step * durationMinute$1);
12335 }, function(start, end) {
12336   return (end - start) / durationMinute$1;
12337 }, function(date) {
12338   return date.getMinutes();
12339 });
12340
12341 var minutes = minute.range;
12342
12343 var hour = newInterval(function(date) {
12344   var offset = date.getTimezoneOffset() * durationMinute$1 % durationHour$1;
12345   if (offset < 0) offset += durationHour$1;
12346   date.setTime(Math.floor((+date - offset) / durationHour$1) * durationHour$1 + offset);
12347 }, function(date, step) {
12348   date.setTime(+date + step * durationHour$1);
12349 }, function(start, end) {
12350   return (end - start) / durationHour$1;
12351 }, function(date) {
12352   return date.getHours();
12353 });
12354
12355 var hours = hour.range;
12356
12357 var day = newInterval(function(date) {
12358   date.setHours(0, 0, 0, 0);
12359 }, function(date, step) {
12360   date.setDate(date.getDate() + step);
12361 }, function(start, end) {
12362   return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationDay$1;
12363 }, function(date) {
12364   return date.getDate() - 1;
12365 });
12366
12367 var days = day.range;
12368
12369 function weekday(i) {
12370   return newInterval(function(date) {
12371     date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
12372     date.setHours(0, 0, 0, 0);
12373   }, function(date, step) {
12374     date.setDate(date.getDate() + step * 7);
12375   }, function(start, end) {
12376     return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute$1) / durationWeek$1;
12377   });
12378 }
12379
12380 var sunday = weekday(0);
12381 var monday = weekday(1);
12382 var tuesday = weekday(2);
12383 var wednesday = weekday(3);
12384 var thursday = weekday(4);
12385 var friday = weekday(5);
12386 var saturday = weekday(6);
12387
12388 var sundays = sunday.range;
12389 var mondays = monday.range;
12390 var tuesdays = tuesday.range;
12391 var wednesdays = wednesday.range;
12392 var thursdays = thursday.range;
12393 var fridays = friday.range;
12394 var saturdays = saturday.range;
12395
12396 var month = newInterval(function(date) {
12397   date.setDate(1);
12398   date.setHours(0, 0, 0, 0);
12399 }, function(date, step) {
12400   date.setMonth(date.getMonth() + step);
12401 }, function(start, end) {
12402   return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
12403 }, function(date) {
12404   return date.getMonth();
12405 });
12406
12407 var months = month.range;
12408
12409 var year = newInterval(function(date) {
12410   date.setMonth(0, 1);
12411   date.setHours(0, 0, 0, 0);
12412 }, function(date, step) {
12413   date.setFullYear(date.getFullYear() + step);
12414 }, function(start, end) {
12415   return end.getFullYear() - start.getFullYear();
12416 }, function(date) {
12417   return date.getFullYear();
12418 });
12419
12420 // An optimized implementation for this simple case.
12421 year.every = function(k) {
12422   return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12423     date.setFullYear(Math.floor(date.getFullYear() / k) * k);
12424     date.setMonth(0, 1);
12425     date.setHours(0, 0, 0, 0);
12426   }, function(date, step) {
12427     date.setFullYear(date.getFullYear() + step * k);
12428   });
12429 };
12430
12431 var years = year.range;
12432
12433 var utcMinute = newInterval(function(date) {
12434   date.setUTCSeconds(0, 0);
12435 }, function(date, step) {
12436   date.setTime(+date + step * durationMinute$1);
12437 }, function(start, end) {
12438   return (end - start) / durationMinute$1;
12439 }, function(date) {
12440   return date.getUTCMinutes();
12441 });
12442
12443 var utcMinutes = utcMinute.range;
12444
12445 var utcHour = newInterval(function(date) {
12446   date.setUTCMinutes(0, 0, 0);
12447 }, function(date, step) {
12448   date.setTime(+date + step * durationHour$1);
12449 }, function(start, end) {
12450   return (end - start) / durationHour$1;
12451 }, function(date) {
12452   return date.getUTCHours();
12453 });
12454
12455 var utcHours = utcHour.range;
12456
12457 var utcDay = newInterval(function(date) {
12458   date.setUTCHours(0, 0, 0, 0);
12459 }, function(date, step) {
12460   date.setUTCDate(date.getUTCDate() + step);
12461 }, function(start, end) {
12462   return (end - start) / durationDay$1;
12463 }, function(date) {
12464   return date.getUTCDate() - 1;
12465 });
12466
12467 var utcDays = utcDay.range;
12468
12469 function utcWeekday(i) {
12470   return newInterval(function(date) {
12471     date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
12472     date.setUTCHours(0, 0, 0, 0);
12473   }, function(date, step) {
12474     date.setUTCDate(date.getUTCDate() + step * 7);
12475   }, function(start, end) {
12476     return (end - start) / durationWeek$1;
12477   });
12478 }
12479
12480 var utcSunday = utcWeekday(0);
12481 var utcMonday = utcWeekday(1);
12482 var utcTuesday = utcWeekday(2);
12483 var utcWednesday = utcWeekday(3);
12484 var utcThursday = utcWeekday(4);
12485 var utcFriday = utcWeekday(5);
12486 var utcSaturday = utcWeekday(6);
12487
12488 var utcSundays = utcSunday.range;
12489 var utcMondays = utcMonday.range;
12490 var utcTuesdays = utcTuesday.range;
12491 var utcWednesdays = utcWednesday.range;
12492 var utcThursdays = utcThursday.range;
12493 var utcFridays = utcFriday.range;
12494 var utcSaturdays = utcSaturday.range;
12495
12496 var utcMonth = newInterval(function(date) {
12497   date.setUTCDate(1);
12498   date.setUTCHours(0, 0, 0, 0);
12499 }, function(date, step) {
12500   date.setUTCMonth(date.getUTCMonth() + step);
12501 }, function(start, end) {
12502   return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
12503 }, function(date) {
12504   return date.getUTCMonth();
12505 });
12506
12507 var utcMonths = utcMonth.range;
12508
12509 var utcYear = newInterval(function(date) {
12510   date.setUTCMonth(0, 1);
12511   date.setUTCHours(0, 0, 0, 0);
12512 }, function(date, step) {
12513   date.setUTCFullYear(date.getUTCFullYear() + step);
12514 }, function(start, end) {
12515   return end.getUTCFullYear() - start.getUTCFullYear();
12516 }, function(date) {
12517   return date.getUTCFullYear();
12518 });
12519
12520 // An optimized implementation for this simple case.
12521 utcYear.every = function(k) {
12522   return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12523     date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
12524     date.setUTCMonth(0, 1);
12525     date.setUTCHours(0, 0, 0, 0);
12526   }, function(date, step) {
12527     date.setUTCFullYear(date.getUTCFullYear() + step * k);
12528   });
12529 };
12530
12531 var utcYears = utcYear.range;
12532
12533 function localDate(d) {
12534   if (0 <= d.y && d.y < 100) {
12535     var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
12536     date.setFullYear(d.y);
12537     return date;
12538   }
12539   return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
12540 }
12541
12542 function utcDate(d) {
12543   if (0 <= d.y && d.y < 100) {
12544     var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
12545     date.setUTCFullYear(d.y);
12546     return date;
12547   }
12548   return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
12549 }
12550
12551 function newYear(y) {
12552   return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
12553 }
12554
12555 function formatLocale$1(locale) {
12556   var locale_dateTime = locale.dateTime,
12557       locale_date = locale.date,
12558       locale_time = locale.time,
12559       locale_periods = locale.periods,
12560       locale_weekdays = locale.days,
12561       locale_shortWeekdays = locale.shortDays,
12562       locale_months = locale.months,
12563       locale_shortMonths = locale.shortMonths;
12564
12565   var periodRe = formatRe(locale_periods),
12566       periodLookup = formatLookup(locale_periods),
12567       weekdayRe = formatRe(locale_weekdays),
12568       weekdayLookup = formatLookup(locale_weekdays),
12569       shortWeekdayRe = formatRe(locale_shortWeekdays),
12570       shortWeekdayLookup = formatLookup(locale_shortWeekdays),
12571       monthRe = formatRe(locale_months),
12572       monthLookup = formatLookup(locale_months),
12573       shortMonthRe = formatRe(locale_shortMonths),
12574       shortMonthLookup = formatLookup(locale_shortMonths);
12575
12576   var formats = {
12577     "a": formatShortWeekday,
12578     "A": formatWeekday,
12579     "b": formatShortMonth,
12580     "B": formatMonth,
12581     "c": null,
12582     "d": formatDayOfMonth,
12583     "e": formatDayOfMonth,
12584     "f": formatMicroseconds,
12585     "H": formatHour24,
12586     "I": formatHour12,
12587     "j": formatDayOfYear,
12588     "L": formatMilliseconds,
12589     "m": formatMonthNumber,
12590     "M": formatMinutes,
12591     "p": formatPeriod,
12592     "Q": formatUnixTimestamp,
12593     "s": formatUnixTimestampSeconds,
12594     "S": formatSeconds,
12595     "u": formatWeekdayNumberMonday,
12596     "U": formatWeekNumberSunday,
12597     "V": formatWeekNumberISO,
12598     "w": formatWeekdayNumberSunday,
12599     "W": formatWeekNumberMonday,
12600     "x": null,
12601     "X": null,
12602     "y": formatYear,
12603     "Y": formatFullYear,
12604     "Z": formatZone,
12605     "%": formatLiteralPercent
12606   };
12607
12608   var utcFormats = {
12609     "a": formatUTCShortWeekday,
12610     "A": formatUTCWeekday,
12611     "b": formatUTCShortMonth,
12612     "B": formatUTCMonth,
12613     "c": null,
12614     "d": formatUTCDayOfMonth,
12615     "e": formatUTCDayOfMonth,
12616     "f": formatUTCMicroseconds,
12617     "H": formatUTCHour24,
12618     "I": formatUTCHour12,
12619     "j": formatUTCDayOfYear,
12620     "L": formatUTCMilliseconds,
12621     "m": formatUTCMonthNumber,
12622     "M": formatUTCMinutes,
12623     "p": formatUTCPeriod,
12624     "Q": formatUnixTimestamp,
12625     "s": formatUnixTimestampSeconds,
12626     "S": formatUTCSeconds,
12627     "u": formatUTCWeekdayNumberMonday,
12628     "U": formatUTCWeekNumberSunday,
12629     "V": formatUTCWeekNumberISO,
12630     "w": formatUTCWeekdayNumberSunday,
12631     "W": formatUTCWeekNumberMonday,
12632     "x": null,
12633     "X": null,
12634     "y": formatUTCYear,
12635     "Y": formatUTCFullYear,
12636     "Z": formatUTCZone,
12637     "%": formatLiteralPercent
12638   };
12639
12640   var parses = {
12641     "a": parseShortWeekday,
12642     "A": parseWeekday,
12643     "b": parseShortMonth,
12644     "B": parseMonth,
12645     "c": parseLocaleDateTime,
12646     "d": parseDayOfMonth,
12647     "e": parseDayOfMonth,
12648     "f": parseMicroseconds,
12649     "H": parseHour24,
12650     "I": parseHour24,
12651     "j": parseDayOfYear,
12652     "L": parseMilliseconds,
12653     "m": parseMonthNumber,
12654     "M": parseMinutes,
12655     "p": parsePeriod,
12656     "Q": parseUnixTimestamp,
12657     "s": parseUnixTimestampSeconds,
12658     "S": parseSeconds,
12659     "u": parseWeekdayNumberMonday,
12660     "U": parseWeekNumberSunday,
12661     "V": parseWeekNumberISO,
12662     "w": parseWeekdayNumberSunday,
12663     "W": parseWeekNumberMonday,
12664     "x": parseLocaleDate,
12665     "X": parseLocaleTime,
12666     "y": parseYear,
12667     "Y": parseFullYear,
12668     "Z": parseZone,
12669     "%": parseLiteralPercent
12670   };
12671
12672   // These recursive directive definitions must be deferred.
12673   formats.x = newFormat(locale_date, formats);
12674   formats.X = newFormat(locale_time, formats);
12675   formats.c = newFormat(locale_dateTime, formats);
12676   utcFormats.x = newFormat(locale_date, utcFormats);
12677   utcFormats.X = newFormat(locale_time, utcFormats);
12678   utcFormats.c = newFormat(locale_dateTime, utcFormats);
12679
12680   function newFormat(specifier, formats) {
12681     return function(date) {
12682       var string = [],
12683           i = -1,
12684           j = 0,
12685           n = specifier.length,
12686           c,
12687           pad,
12688           format;
12689
12690       if (!(date instanceof Date)) date = new Date(+date);
12691
12692       while (++i < n) {
12693         if (specifier.charCodeAt(i) === 37) {
12694           string.push(specifier.slice(j, i));
12695           if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
12696           else pad = c === "e" ? " " : "0";
12697           if (format = formats[c]) c = format(date, pad);
12698           string.push(c);
12699           j = i + 1;
12700         }
12701       }
12702
12703       string.push(specifier.slice(j, i));
12704       return string.join("");
12705     };
12706   }
12707
12708   function newParse(specifier, newDate) {
12709     return function(string) {
12710       var d = newYear(1900),
12711           i = parseSpecifier(d, specifier, string += "", 0),
12712           week, day$$1;
12713       if (i != string.length) return null;
12714
12715       // If a UNIX timestamp is specified, return it.
12716       if ("Q" in d) return new Date(d.Q);
12717
12718       // The am-pm flag is 0 for AM, and 1 for PM.
12719       if ("p" in d) d.H = d.H % 12 + d.p * 12;
12720
12721       // Convert day-of-week and week-of-year to day-of-year.
12722       if ("V" in d) {
12723         if (d.V < 1 || d.V > 53) return null;
12724         if (!("w" in d)) d.w = 1;
12725         if ("Z" in d) {
12726           week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
12727           week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
12728           week = utcDay.offset(week, (d.V - 1) * 7);
12729           d.y = week.getUTCFullYear();
12730           d.m = week.getUTCMonth();
12731           d.d = week.getUTCDate() + (d.w + 6) % 7;
12732         } else {
12733           week = newDate(newYear(d.y)), day$$1 = week.getDay();
12734           week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
12735           week = day.offset(week, (d.V - 1) * 7);
12736           d.y = week.getFullYear();
12737           d.m = week.getMonth();
12738           d.d = week.getDate() + (d.w + 6) % 7;
12739         }
12740       } else if ("W" in d || "U" in d) {
12741         if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
12742         day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
12743         d.m = 0;
12744         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;
12745       }
12746
12747       // If a time zone is specified, all fields are interpreted as UTC and then
12748       // offset according to the specified time zone.
12749       if ("Z" in d) {
12750         d.H += d.Z / 100 | 0;
12751         d.M += d.Z % 100;
12752         return utcDate(d);
12753       }
12754
12755       // Otherwise, all fields are in local time.
12756       return newDate(d);
12757     };
12758   }
12759
12760   function parseSpecifier(d, specifier, string, j) {
12761     var i = 0,
12762         n = specifier.length,
12763         m = string.length,
12764         c,
12765         parse;
12766
12767     while (i < n) {
12768       if (j >= m) return -1;
12769       c = specifier.charCodeAt(i++);
12770       if (c === 37) {
12771         c = specifier.charAt(i++);
12772         parse = parses[c in pads ? specifier.charAt(i++) : c];
12773         if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
12774       } else if (c != string.charCodeAt(j++)) {
12775         return -1;
12776       }
12777     }
12778
12779     return j;
12780   }
12781
12782   function parsePeriod(d, string, i) {
12783     var n = periodRe.exec(string.slice(i));
12784     return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12785   }
12786
12787   function parseShortWeekday(d, string, i) {
12788     var n = shortWeekdayRe.exec(string.slice(i));
12789     return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12790   }
12791
12792   function parseWeekday(d, string, i) {
12793     var n = weekdayRe.exec(string.slice(i));
12794     return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12795   }
12796
12797   function parseShortMonth(d, string, i) {
12798     var n = shortMonthRe.exec(string.slice(i));
12799     return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12800   }
12801
12802   function parseMonth(d, string, i) {
12803     var n = monthRe.exec(string.slice(i));
12804     return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
12805   }
12806
12807   function parseLocaleDateTime(d, string, i) {
12808     return parseSpecifier(d, locale_dateTime, string, i);
12809   }
12810
12811   function parseLocaleDate(d, string, i) {
12812     return parseSpecifier(d, locale_date, string, i);
12813   }
12814
12815   function parseLocaleTime(d, string, i) {
12816     return parseSpecifier(d, locale_time, string, i);
12817   }
12818
12819   function formatShortWeekday(d) {
12820     return locale_shortWeekdays[d.getDay()];
12821   }
12822
12823   function formatWeekday(d) {
12824     return locale_weekdays[d.getDay()];
12825   }
12826
12827   function formatShortMonth(d) {
12828     return locale_shortMonths[d.getMonth()];
12829   }
12830
12831   function formatMonth(d) {
12832     return locale_months[d.getMonth()];
12833   }
12834
12835   function formatPeriod(d) {
12836     return locale_periods[+(d.getHours() >= 12)];
12837   }
12838
12839   function formatUTCShortWeekday(d) {
12840     return locale_shortWeekdays[d.getUTCDay()];
12841   }
12842
12843   function formatUTCWeekday(d) {
12844     return locale_weekdays[d.getUTCDay()];
12845   }
12846
12847   function formatUTCShortMonth(d) {
12848     return locale_shortMonths[d.getUTCMonth()];
12849   }
12850
12851   function formatUTCMonth(d) {
12852     return locale_months[d.getUTCMonth()];
12853   }
12854
12855   function formatUTCPeriod(d) {
12856     return locale_periods[+(d.getUTCHours() >= 12)];
12857   }
12858
12859   return {
12860     format: function(specifier) {
12861       var f = newFormat(specifier += "", formats);
12862       f.toString = function() { return specifier; };
12863       return f;
12864     },
12865     parse: function(specifier) {
12866       var p = newParse(specifier += "", localDate);
12867       p.toString = function() { return specifier; };
12868       return p;
12869     },
12870     utcFormat: function(specifier) {
12871       var f = newFormat(specifier += "", utcFormats);
12872       f.toString = function() { return specifier; };
12873       return f;
12874     },
12875     utcParse: function(specifier) {
12876       var p = newParse(specifier, utcDate);
12877       p.toString = function() { return specifier; };
12878       return p;
12879     }
12880   };
12881 }
12882
12883 var pads = {"-": "", "_": " ", "0": "0"};
12884 var numberRe = /^\s*\d+/;
12885 var percentRe = /^%/;
12886 var requoteRe = /[\\^$*+?|[\]().{}]/g;
12887
12888 function pad(value, fill, width) {
12889   var sign = value < 0 ? "-" : "",
12890       string = (sign ? -value : value) + "",
12891       length = string.length;
12892   return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
12893 }
12894
12895 function requote(s) {
12896   return s.replace(requoteRe, "\\$&");
12897 }
12898
12899 function formatRe(names) {
12900   return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
12901 }
12902
12903 function formatLookup(names) {
12904   var map = {}, i = -1, n = names.length;
12905   while (++i < n) map[names[i].toLowerCase()] = i;
12906   return map;
12907 }
12908
12909 function parseWeekdayNumberSunday(d, string, i) {
12910   var n = numberRe.exec(string.slice(i, i + 1));
12911   return n ? (d.w = +n[0], i + n[0].length) : -1;
12912 }
12913
12914 function parseWeekdayNumberMonday(d, string, i) {
12915   var n = numberRe.exec(string.slice(i, i + 1));
12916   return n ? (d.u = +n[0], i + n[0].length) : -1;
12917 }
12918
12919 function parseWeekNumberSunday(d, string, i) {
12920   var n = numberRe.exec(string.slice(i, i + 2));
12921   return n ? (d.U = +n[0], i + n[0].length) : -1;
12922 }
12923
12924 function parseWeekNumberISO(d, string, i) {
12925   var n = numberRe.exec(string.slice(i, i + 2));
12926   return n ? (d.V = +n[0], i + n[0].length) : -1;
12927 }
12928
12929 function parseWeekNumberMonday(d, string, i) {
12930   var n = numberRe.exec(string.slice(i, i + 2));
12931   return n ? (d.W = +n[0], i + n[0].length) : -1;
12932 }
12933
12934 function parseFullYear(d, string, i) {
12935   var n = numberRe.exec(string.slice(i, i + 4));
12936   return n ? (d.y = +n[0], i + n[0].length) : -1;
12937 }
12938
12939 function parseYear(d, string, i) {
12940   var n = numberRe.exec(string.slice(i, i + 2));
12941   return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
12942 }
12943
12944 function parseZone(d, string, i) {
12945   var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
12946   return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
12947 }
12948
12949 function parseMonthNumber(d, string, i) {
12950   var n = numberRe.exec(string.slice(i, i + 2));
12951   return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
12952 }
12953
12954 function parseDayOfMonth(d, string, i) {
12955   var n = numberRe.exec(string.slice(i, i + 2));
12956   return n ? (d.d = +n[0], i + n[0].length) : -1;
12957 }
12958
12959 function parseDayOfYear(d, string, i) {
12960   var n = numberRe.exec(string.slice(i, i + 3));
12961   return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
12962 }
12963
12964 function parseHour24(d, string, i) {
12965   var n = numberRe.exec(string.slice(i, i + 2));
12966   return n ? (d.H = +n[0], i + n[0].length) : -1;
12967 }
12968
12969 function parseMinutes(d, string, i) {
12970   var n = numberRe.exec(string.slice(i, i + 2));
12971   return n ? (d.M = +n[0], i + n[0].length) : -1;
12972 }
12973
12974 function parseSeconds(d, string, i) {
12975   var n = numberRe.exec(string.slice(i, i + 2));
12976   return n ? (d.S = +n[0], i + n[0].length) : -1;
12977 }
12978
12979 function parseMilliseconds(d, string, i) {
12980   var n = numberRe.exec(string.slice(i, i + 3));
12981   return n ? (d.L = +n[0], i + n[0].length) : -1;
12982 }
12983
12984 function parseMicroseconds(d, string, i) {
12985   var n = numberRe.exec(string.slice(i, i + 6));
12986   return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
12987 }
12988
12989 function parseLiteralPercent(d, string, i) {
12990   var n = percentRe.exec(string.slice(i, i + 1));
12991   return n ? i + n[0].length : -1;
12992 }
12993
12994 function parseUnixTimestamp(d, string, i) {
12995   var n = numberRe.exec(string.slice(i));
12996   return n ? (d.Q = +n[0], i + n[0].length) : -1;
12997 }
12998
12999 function parseUnixTimestampSeconds(d, string, i) {
13000   var n = numberRe.exec(string.slice(i));
13001   return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
13002 }
13003
13004 function formatDayOfMonth(d, p) {
13005   return pad(d.getDate(), p, 2);
13006 }
13007
13008 function formatHour24(d, p) {
13009   return pad(d.getHours(), p, 2);
13010 }
13011
13012 function formatHour12(d, p) {
13013   return pad(d.getHours() % 12 || 12, p, 2);
13014 }
13015
13016 function formatDayOfYear(d, p) {
13017   return pad(1 + day.count(year(d), d), p, 3);
13018 }
13019
13020 function formatMilliseconds(d, p) {
13021   return pad(d.getMilliseconds(), p, 3);
13022 }
13023
13024 function formatMicroseconds(d, p) {
13025   return formatMilliseconds(d, p) + "000";
13026 }
13027
13028 function formatMonthNumber(d, p) {
13029   return pad(d.getMonth() + 1, p, 2);
13030 }
13031
13032 function formatMinutes(d, p) {
13033   return pad(d.getMinutes(), p, 2);
13034 }
13035
13036 function formatSeconds(d, p) {
13037   return pad(d.getSeconds(), p, 2);
13038 }
13039
13040 function formatWeekdayNumberMonday(d) {
13041   var day$$1 = d.getDay();
13042   return day$$1 === 0 ? 7 : day$$1;
13043 }
13044
13045 function formatWeekNumberSunday(d, p) {
13046   return pad(sunday.count(year(d), d), p, 2);
13047 }
13048
13049 function formatWeekNumberISO(d, p) {
13050   var day$$1 = d.getDay();
13051   d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
13052   return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
13053 }
13054
13055 function formatWeekdayNumberSunday(d) {
13056   return d.getDay();
13057 }
13058
13059 function formatWeekNumberMonday(d, p) {
13060   return pad(monday.count(year(d), d), p, 2);
13061 }
13062
13063 function formatYear(d, p) {
13064   return pad(d.getFullYear() % 100, p, 2);
13065 }
13066
13067 function formatFullYear(d, p) {
13068   return pad(d.getFullYear() % 10000, p, 4);
13069 }
13070
13071 function formatZone(d) {
13072   var z = d.getTimezoneOffset();
13073   return (z > 0 ? "-" : (z *= -1, "+"))
13074       + pad(z / 60 | 0, "0", 2)
13075       + pad(z % 60, "0", 2);
13076 }
13077
13078 function formatUTCDayOfMonth(d, p) {
13079   return pad(d.getUTCDate(), p, 2);
13080 }
13081
13082 function formatUTCHour24(d, p) {
13083   return pad(d.getUTCHours(), p, 2);
13084 }
13085
13086 function formatUTCHour12(d, p) {
13087   return pad(d.getUTCHours() % 12 || 12, p, 2);
13088 }
13089
13090 function formatUTCDayOfYear(d, p) {
13091   return pad(1 + utcDay.count(utcYear(d), d), p, 3);
13092 }
13093
13094 function formatUTCMilliseconds(d, p) {
13095   return pad(d.getUTCMilliseconds(), p, 3);
13096 }
13097
13098 function formatUTCMicroseconds(d, p) {
13099   return formatUTCMilliseconds(d, p) + "000";
13100 }
13101
13102 function formatUTCMonthNumber(d, p) {
13103   return pad(d.getUTCMonth() + 1, p, 2);
13104 }
13105
13106 function formatUTCMinutes(d, p) {
13107   return pad(d.getUTCMinutes(), p, 2);
13108 }
13109
13110 function formatUTCSeconds(d, p) {
13111   return pad(d.getUTCSeconds(), p, 2);
13112 }
13113
13114 function formatUTCWeekdayNumberMonday(d) {
13115   var dow = d.getUTCDay();
13116   return dow === 0 ? 7 : dow;
13117 }
13118
13119 function formatUTCWeekNumberSunday(d, p) {
13120   return pad(utcSunday.count(utcYear(d), d), p, 2);
13121 }
13122
13123 function formatUTCWeekNumberISO(d, p) {
13124   var day$$1 = d.getUTCDay();
13125   d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
13126   return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
13127 }
13128
13129 function formatUTCWeekdayNumberSunday(d) {
13130   return d.getUTCDay();
13131 }
13132
13133 function formatUTCWeekNumberMonday(d, p) {
13134   return pad(utcMonday.count(utcYear(d), d), p, 2);
13135 }
13136
13137 function formatUTCYear(d, p) {
13138   return pad(d.getUTCFullYear() % 100, p, 2);
13139 }
13140
13141 function formatUTCFullYear(d, p) {
13142   return pad(d.getUTCFullYear() % 10000, p, 4);
13143 }
13144
13145 function formatUTCZone() {
13146   return "+0000";
13147 }
13148
13149 function formatLiteralPercent() {
13150   return "%";
13151 }
13152
13153 function formatUnixTimestamp(d) {
13154   return +d;
13155 }
13156
13157 function formatUnixTimestampSeconds(d) {
13158   return Math.floor(+d / 1000);
13159 }
13160
13161 var locale$1;
13162
13163
13164
13165
13166
13167 defaultLocale$1({
13168   dateTime: "%x, %X",
13169   date: "%-m/%-d/%Y",
13170   time: "%-I:%M:%S %p",
13171   periods: ["AM", "PM"],
13172   days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
13173   shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
13174   months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
13175   shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
13176 });
13177
13178 function defaultLocale$1(definition) {
13179   locale$1 = formatLocale$1(definition);
13180   exports.timeFormat = locale$1.format;
13181   exports.timeParse = locale$1.parse;
13182   exports.utcFormat = locale$1.utcFormat;
13183   exports.utcParse = locale$1.utcParse;
13184   return locale$1;
13185 }
13186
13187 var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
13188
13189 function formatIsoNative(date) {
13190   return date.toISOString();
13191 }
13192
13193 var formatIso = Date.prototype.toISOString
13194     ? formatIsoNative
13195     : exports.utcFormat(isoSpecifier);
13196
13197 function parseIsoNative(string) {
13198   var date = new Date(string);
13199   return isNaN(date) ? null : date;
13200 }
13201
13202 var parseIso = +new Date("2000-01-01T00:00:00.000Z")
13203     ? parseIsoNative
13204     : exports.utcParse(isoSpecifier);
13205
13206 var durationSecond = 1000;
13207 var durationMinute = durationSecond * 60;
13208 var durationHour = durationMinute * 60;
13209 var durationDay = durationHour * 24;
13210 var durationWeek = durationDay * 7;
13211 var durationMonth = durationDay * 30;
13212 var durationYear = durationDay * 365;
13213
13214 function date$1(t) {
13215   return new Date(t);
13216 }
13217
13218 function number$3(t) {
13219   return t instanceof Date ? +t : +new Date(+t);
13220 }
13221
13222 function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
13223   var scale = continuous(deinterpolateLinear, reinterpolate),
13224       invert = scale.invert,
13225       domain = scale.domain;
13226
13227   var formatMillisecond = format(".%L"),
13228       formatSecond = format(":%S"),
13229       formatMinute = format("%I:%M"),
13230       formatHour = format("%I %p"),
13231       formatDay = format("%a %d"),
13232       formatWeek = format("%b %d"),
13233       formatMonth = format("%B"),
13234       formatYear = format("%Y");
13235
13236   var tickIntervals = [
13237     [second$$1,  1,      durationSecond],
13238     [second$$1,  5,  5 * durationSecond],
13239     [second$$1, 15, 15 * durationSecond],
13240     [second$$1, 30, 30 * durationSecond],
13241     [minute$$1,  1,      durationMinute],
13242     [minute$$1,  5,  5 * durationMinute],
13243     [minute$$1, 15, 15 * durationMinute],
13244     [minute$$1, 30, 30 * durationMinute],
13245     [  hour$$1,  1,      durationHour  ],
13246     [  hour$$1,  3,  3 * durationHour  ],
13247     [  hour$$1,  6,  6 * durationHour  ],
13248     [  hour$$1, 12, 12 * durationHour  ],
13249     [   day$$1,  1,      durationDay   ],
13250     [   day$$1,  2,  2 * durationDay   ],
13251     [  week,  1,      durationWeek  ],
13252     [ month$$1,  1,      durationMonth ],
13253     [ month$$1,  3,  3 * durationMonth ],
13254     [  year$$1,  1,      durationYear  ]
13255   ];
13256
13257   function tickFormat(date) {
13258     return (second$$1(date) < date ? formatMillisecond
13259         : minute$$1(date) < date ? formatSecond
13260         : hour$$1(date) < date ? formatMinute
13261         : day$$1(date) < date ? formatHour
13262         : month$$1(date) < date ? (week(date) < date ? formatDay : formatWeek)
13263         : year$$1(date) < date ? formatMonth
13264         : formatYear)(date);
13265   }
13266
13267   function tickInterval(interval, start, stop, step) {
13268     if (interval == null) interval = 10;
13269
13270     // If a desired tick count is specified, pick a reasonable tick interval
13271     // based on the extent of the domain and a rough estimate of tick size.
13272     // Otherwise, assume interval is already a time interval and use it.
13273     if (typeof interval === "number") {
13274       var target = Math.abs(stop - start) / interval,
13275           i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
13276       if (i === tickIntervals.length) {
13277         step = tickStep(start / durationYear, stop / durationYear, interval);
13278         interval = year$$1;
13279       } else if (i) {
13280         i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
13281         step = i[1];
13282         interval = i[0];
13283       } else {
13284         step = Math.max(tickStep(start, stop, interval), 1);
13285         interval = millisecond$$1;
13286       }
13287     }
13288
13289     return step == null ? interval : interval.every(step);
13290   }
13291
13292   scale.invert = function(y) {
13293     return new Date(invert(y));
13294   };
13295
13296   scale.domain = function(_) {
13297     return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
13298   };
13299
13300   scale.ticks = function(interval, step) {
13301     var d = domain(),
13302         t0 = d[0],
13303         t1 = d[d.length - 1],
13304         r = t1 < t0,
13305         t;
13306     if (r) t = t0, t0 = t1, t1 = t;
13307     t = tickInterval(interval, t0, t1, step);
13308     t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
13309     return r ? t.reverse() : t;
13310   };
13311
13312   scale.tickFormat = function(count, specifier) {
13313     return specifier == null ? tickFormat : format(specifier);
13314   };
13315
13316   scale.nice = function(interval, step) {
13317     var d = domain();
13318     return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
13319         ? domain(nice(d, interval))
13320         : scale;
13321   };
13322
13323   scale.copy = function() {
13324     return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
13325   };
13326
13327   return scale;
13328 }
13329
13330 var time = function() {
13331   return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
13332 };
13333
13334 var utcTime = function() {
13335   return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
13336 };
13337
13338 var colors = function(s) {
13339   return s.match(/.{6}/g).map(function(x) {
13340     return "#" + x;
13341   });
13342 };
13343
13344 var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
13345
13346 var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
13347
13348 var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
13349
13350 var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
13351
13352 var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
13353
13354 var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13355
13356 var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
13357
13358 var rainbow = cubehelix();
13359
13360 var rainbow$1 = function(t) {
13361   if (t < 0 || t > 1) t -= Math.floor(t);
13362   var ts = Math.abs(t - 0.5);
13363   rainbow.h = 360 * t - 100;
13364   rainbow.s = 1.5 - 1.5 * ts;
13365   rainbow.l = 0.8 - 0.9 * ts;
13366   return rainbow + "";
13367 };
13368
13369 function ramp(range) {
13370   var n = range.length;
13371   return function(t) {
13372     return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
13373   };
13374 }
13375
13376 var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
13377
13378 var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
13379
13380 var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
13381
13382 var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
13383
13384 function sequential(interpolator) {
13385   var x0 = 0,
13386       x1 = 1,
13387       clamp = false;
13388
13389   function scale(x) {
13390     var t = (x - x0) / (x1 - x0);
13391     return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
13392   }
13393
13394   scale.domain = function(_) {
13395     return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
13396   };
13397
13398   scale.clamp = function(_) {
13399     return arguments.length ? (clamp = !!_, scale) : clamp;
13400   };
13401
13402   scale.interpolator = function(_) {
13403     return arguments.length ? (interpolator = _, scale) : interpolator;
13404   };
13405
13406   scale.copy = function() {
13407     return sequential(interpolator).domain([x0, x1]).clamp(clamp);
13408   };
13409
13410   return linearish(scale);
13411 }
13412
13413 var constant$10 = function(x) {
13414   return function constant() {
13415     return x;
13416   };
13417 };
13418
13419 var abs$1 = Math.abs;
13420 var atan2$1 = Math.atan2;
13421 var cos$2 = Math.cos;
13422 var max$2 = Math.max;
13423 var min$1 = Math.min;
13424 var sin$2 = Math.sin;
13425 var sqrt$2 = Math.sqrt;
13426
13427 var epsilon$3 = 1e-12;
13428 var pi$4 = Math.PI;
13429 var halfPi$3 = pi$4 / 2;
13430 var tau$4 = 2 * pi$4;
13431
13432 function acos$1(x) {
13433   return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
13434 }
13435
13436 function asin$1(x) {
13437   return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
13438 }
13439
13440 function arcInnerRadius(d) {
13441   return d.innerRadius;
13442 }
13443
13444 function arcOuterRadius(d) {
13445   return d.outerRadius;
13446 }
13447
13448 function arcStartAngle(d) {
13449   return d.startAngle;
13450 }
13451
13452 function arcEndAngle(d) {
13453   return d.endAngle;
13454 }
13455
13456 function arcPadAngle(d) {
13457   return d && d.padAngle; // Note: optional!
13458 }
13459
13460 function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
13461   var x10 = x1 - x0, y10 = y1 - y0,
13462       x32 = x3 - x2, y32 = y3 - y2,
13463       t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
13464   return [x0 + t * x10, y0 + t * y10];
13465 }
13466
13467 // Compute perpendicular offset line of length rc.
13468 // http://mathworld.wolfram.com/Circle-LineIntersection.html
13469 function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
13470   var x01 = x0 - x1,
13471       y01 = y0 - y1,
13472       lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
13473       ox = lo * y01,
13474       oy = -lo * x01,
13475       x11 = x0 + ox,
13476       y11 = y0 + oy,
13477       x10 = x1 + ox,
13478       y10 = y1 + oy,
13479       x00 = (x11 + x10) / 2,
13480       y00 = (y11 + y10) / 2,
13481       dx = x10 - x11,
13482       dy = y10 - y11,
13483       d2 = dx * dx + dy * dy,
13484       r = r1 - rc,
13485       D = x11 * y10 - x10 * y11,
13486       d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
13487       cx0 = (D * dy - dx * d) / d2,
13488       cy0 = (-D * dx - dy * d) / d2,
13489       cx1 = (D * dy + dx * d) / d2,
13490       cy1 = (-D * dx + dy * d) / d2,
13491       dx0 = cx0 - x00,
13492       dy0 = cy0 - y00,
13493       dx1 = cx1 - x00,
13494       dy1 = cy1 - y00;
13495
13496   // Pick the closer of the two intersection points.
13497   // TODO Is there a faster way to determine which intersection to use?
13498   if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
13499
13500   return {
13501     cx: cx0,
13502     cy: cy0,
13503     x01: -ox,
13504     y01: -oy,
13505     x11: cx0 * (r1 / r - 1),
13506     y11: cy0 * (r1 / r - 1)
13507   };
13508 }
13509
13510 var arc = function() {
13511   var innerRadius = arcInnerRadius,
13512       outerRadius = arcOuterRadius,
13513       cornerRadius = constant$10(0),
13514       padRadius = null,
13515       startAngle = arcStartAngle,
13516       endAngle = arcEndAngle,
13517       padAngle = arcPadAngle,
13518       context = null;
13519
13520   function arc() {
13521     var buffer,
13522         r,
13523         r0 = +innerRadius.apply(this, arguments),
13524         r1 = +outerRadius.apply(this, arguments),
13525         a0 = startAngle.apply(this, arguments) - halfPi$3,
13526         a1 = endAngle.apply(this, arguments) - halfPi$3,
13527         da = abs$1(a1 - a0),
13528         cw = a1 > a0;
13529
13530     if (!context) context = buffer = path();
13531
13532     // Ensure that the outer radius is always larger than the inner radius.
13533     if (r1 < r0) r = r1, r1 = r0, r0 = r;
13534
13535     // Is it a point?
13536     if (!(r1 > epsilon$3)) context.moveTo(0, 0);
13537
13538     // Or is it a circle or annulus?
13539     else if (da > tau$4 - epsilon$3) {
13540       context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
13541       context.arc(0, 0, r1, a0, a1, !cw);
13542       if (r0 > epsilon$3) {
13543         context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
13544         context.arc(0, 0, r0, a1, a0, cw);
13545       }
13546     }
13547
13548     // Or is it a circular or annular sector?
13549     else {
13550       var a01 = a0,
13551           a11 = a1,
13552           a00 = a0,
13553           a10 = a1,
13554           da0 = da,
13555           da1 = da,
13556           ap = padAngle.apply(this, arguments) / 2,
13557           rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
13558           rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
13559           rc0 = rc,
13560           rc1 = rc,
13561           t0,
13562           t1;
13563
13564       // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
13565       if (rp > epsilon$3) {
13566         var p0 = asin$1(rp / r0 * sin$2(ap)),
13567             p1 = asin$1(rp / r1 * sin$2(ap));
13568         if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
13569         else da0 = 0, a00 = a10 = (a0 + a1) / 2;
13570         if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
13571         else da1 = 0, a01 = a11 = (a0 + a1) / 2;
13572       }
13573
13574       var x01 = r1 * cos$2(a01),
13575           y01 = r1 * sin$2(a01),
13576           x10 = r0 * cos$2(a10),
13577           y10 = r0 * sin$2(a10);
13578
13579       // Apply rounded corners?
13580       if (rc > epsilon$3) {
13581         var x11 = r1 * cos$2(a11),
13582             y11 = r1 * sin$2(a11),
13583             x00 = r0 * cos$2(a00),
13584             y00 = r0 * sin$2(a00);
13585
13586         // Restrict the corner radius according to the sector angle.
13587         if (da < pi$4) {
13588           var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
13589               ax = x01 - oc[0],
13590               ay = y01 - oc[1],
13591               bx = x11 - oc[0],
13592               by = y11 - oc[1],
13593               kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
13594               lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
13595           rc0 = min$1(rc, (r0 - lc) / (kc - 1));
13596           rc1 = min$1(rc, (r1 - lc) / (kc + 1));
13597         }
13598       }
13599
13600       // Is the sector collapsed to a line?
13601       if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
13602
13603       // Does the sector’s outer ring have rounded corners?
13604       else if (rc1 > epsilon$3) {
13605         t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
13606         t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
13607
13608         context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
13609
13610         // Have the corners merged?
13611         if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
13612
13613         // Otherwise, draw the two corners and the ring.
13614         else {
13615           context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
13616           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);
13617           context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
13618         }
13619       }
13620
13621       // Or is the outer ring just a circular arc?
13622       else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
13623
13624       // Is there no inner ring, and it’s a circular sector?
13625       // Or perhaps it’s an annular sector collapsed due to padding?
13626       if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
13627
13628       // Does the sector’s inner ring (or point) have rounded corners?
13629       else if (rc0 > epsilon$3) {
13630         t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
13631         t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
13632
13633         context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
13634
13635         // Have the corners merged?
13636         if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
13637
13638         // Otherwise, draw the two corners and the ring.
13639         else {
13640           context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
13641           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);
13642           context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
13643         }
13644       }
13645
13646       // Or is the inner ring just a circular arc?
13647       else context.arc(0, 0, r0, a10, a00, cw);
13648     }
13649
13650     context.closePath();
13651
13652     if (buffer) return context = null, buffer + "" || null;
13653   }
13654
13655   arc.centroid = function() {
13656     var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
13657         a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
13658     return [cos$2(a) * r, sin$2(a) * r];
13659   };
13660
13661   arc.innerRadius = function(_) {
13662     return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : innerRadius;
13663   };
13664
13665   arc.outerRadius = function(_) {
13666     return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : outerRadius;
13667   };
13668
13669   arc.cornerRadius = function(_) {
13670     return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$10(+_), arc) : cornerRadius;
13671   };
13672
13673   arc.padRadius = function(_) {
13674     return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), arc) : padRadius;
13675   };
13676
13677   arc.startAngle = function(_) {
13678     return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : startAngle;
13679   };
13680
13681   arc.endAngle = function(_) {
13682     return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : endAngle;
13683   };
13684
13685   arc.padAngle = function(_) {
13686     return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), arc) : padAngle;
13687   };
13688
13689   arc.context = function(_) {
13690     return arguments.length ? (context = _ == null ? null : _, arc) : context;
13691   };
13692
13693   return arc;
13694 };
13695
13696 function Linear(context) {
13697   this._context = context;
13698 }
13699
13700 Linear.prototype = {
13701   areaStart: function() {
13702     this._line = 0;
13703   },
13704   areaEnd: function() {
13705     this._line = NaN;
13706   },
13707   lineStart: function() {
13708     this._point = 0;
13709   },
13710   lineEnd: function() {
13711     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
13712     this._line = 1 - this._line;
13713   },
13714   point: function(x, y) {
13715     x = +x, y = +y;
13716     switch (this._point) {
13717       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
13718       case 1: this._point = 2; // proceed
13719       default: this._context.lineTo(x, y); break;
13720     }
13721   }
13722 };
13723
13724 var curveLinear = function(context) {
13725   return new Linear(context);
13726 };
13727
13728 function x$3(p) {
13729   return p[0];
13730 }
13731
13732 function y$3(p) {
13733   return p[1];
13734 }
13735
13736 var line = function() {
13737   var x$$1 = x$3,
13738       y$$1 = y$3,
13739       defined = constant$10(true),
13740       context = null,
13741       curve = curveLinear,
13742       output = null;
13743
13744   function line(data) {
13745     var i,
13746         n = data.length,
13747         d,
13748         defined0 = false,
13749         buffer;
13750
13751     if (context == null) output = curve(buffer = path());
13752
13753     for (i = 0; i <= n; ++i) {
13754       if (!(i < n && defined(d = data[i], i, data)) === defined0) {
13755         if (defined0 = !defined0) output.lineStart();
13756         else output.lineEnd();
13757       }
13758       if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
13759     }
13760
13761     if (buffer) return output = null, buffer + "" || null;
13762   }
13763
13764   line.x = function(_) {
13765     return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : x$$1;
13766   };
13767
13768   line.y = function(_) {
13769     return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), line) : y$$1;
13770   };
13771
13772   line.defined = function(_) {
13773     return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), line) : defined;
13774   };
13775
13776   line.curve = function(_) {
13777     return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
13778   };
13779
13780   line.context = function(_) {
13781     return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
13782   };
13783
13784   return line;
13785 };
13786
13787 var area$2 = function() {
13788   var x0 = x$3,
13789       x1 = null,
13790       y0 = constant$10(0),
13791       y1 = y$3,
13792       defined = constant$10(true),
13793       context = null,
13794       curve = curveLinear,
13795       output = null;
13796
13797   function area(data) {
13798     var i,
13799         j,
13800         k,
13801         n = data.length,
13802         d,
13803         defined0 = false,
13804         buffer,
13805         x0z = new Array(n),
13806         y0z = new Array(n);
13807
13808     if (context == null) output = curve(buffer = path());
13809
13810     for (i = 0; i <= n; ++i) {
13811       if (!(i < n && defined(d = data[i], i, data)) === defined0) {
13812         if (defined0 = !defined0) {
13813           j = i;
13814           output.areaStart();
13815           output.lineStart();
13816         } else {
13817           output.lineEnd();
13818           output.lineStart();
13819           for (k = i - 1; k >= j; --k) {
13820             output.point(x0z[k], y0z[k]);
13821           }
13822           output.lineEnd();
13823           output.areaEnd();
13824         }
13825       }
13826       if (defined0) {
13827         x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
13828         output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
13829       }
13830     }
13831
13832     if (buffer) return output = null, buffer + "" || null;
13833   }
13834
13835   function arealine() {
13836     return line().defined(defined).curve(curve).context(context);
13837   }
13838
13839   area.x = function(_) {
13840     return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), x1 = null, area) : x0;
13841   };
13842
13843   area.x0 = function(_) {
13844     return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$10(+_), area) : x0;
13845   };
13846
13847   area.x1 = function(_) {
13848     return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : x1;
13849   };
13850
13851   area.y = function(_) {
13852     return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), y1 = null, area) : y0;
13853   };
13854
13855   area.y0 = function(_) {
13856     return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$10(+_), area) : y0;
13857   };
13858
13859   area.y1 = function(_) {
13860     return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$10(+_), area) : y1;
13861   };
13862
13863   area.lineX0 =
13864   area.lineY0 = function() {
13865     return arealine().x(x0).y(y0);
13866   };
13867
13868   area.lineY1 = function() {
13869     return arealine().x(x0).y(y1);
13870   };
13871
13872   area.lineX1 = function() {
13873     return arealine().x(x1).y(y0);
13874   };
13875
13876   area.defined = function(_) {
13877     return arguments.length ? (defined = typeof _ === "function" ? _ : constant$10(!!_), area) : defined;
13878   };
13879
13880   area.curve = function(_) {
13881     return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
13882   };
13883
13884   area.context = function(_) {
13885     return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
13886   };
13887
13888   return area;
13889 };
13890
13891 var descending$1 = function(a, b) {
13892   return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
13893 };
13894
13895 var identity$7 = function(d) {
13896   return d;
13897 };
13898
13899 var pie = function() {
13900   var value = identity$7,
13901       sortValues = descending$1,
13902       sort = null,
13903       startAngle = constant$10(0),
13904       endAngle = constant$10(tau$4),
13905       padAngle = constant$10(0);
13906
13907   function pie(data) {
13908     var i,
13909         n = data.length,
13910         j,
13911         k,
13912         sum = 0,
13913         index = new Array(n),
13914         arcs = new Array(n),
13915         a0 = +startAngle.apply(this, arguments),
13916         da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
13917         a1,
13918         p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
13919         pa = p * (da < 0 ? -1 : 1),
13920         v;
13921
13922     for (i = 0; i < n; ++i) {
13923       if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
13924         sum += v;
13925       }
13926     }
13927
13928     // Optionally sort the arcs by previously-computed values or by data.
13929     if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
13930     else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
13931
13932     // Compute the arcs! They are stored in the original data's order.
13933     for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
13934       j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
13935         data: data[j],
13936         index: i,
13937         value: v,
13938         startAngle: a0,
13939         endAngle: a1,
13940         padAngle: p
13941       };
13942     }
13943
13944     return arcs;
13945   }
13946
13947   pie.value = function(_) {
13948     return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), pie) : value;
13949   };
13950
13951   pie.sortValues = function(_) {
13952     return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
13953   };
13954
13955   pie.sort = function(_) {
13956     return arguments.length ? (sort = _, sortValues = null, pie) : sort;
13957   };
13958
13959   pie.startAngle = function(_) {
13960     return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : startAngle;
13961   };
13962
13963   pie.endAngle = function(_) {
13964     return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : endAngle;
13965   };
13966
13967   pie.padAngle = function(_) {
13968     return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$10(+_), pie) : padAngle;
13969   };
13970
13971   return pie;
13972 };
13973
13974 var curveRadialLinear = curveRadial(curveLinear);
13975
13976 function Radial(curve) {
13977   this._curve = curve;
13978 }
13979
13980 Radial.prototype = {
13981   areaStart: function() {
13982     this._curve.areaStart();
13983   },
13984   areaEnd: function() {
13985     this._curve.areaEnd();
13986   },
13987   lineStart: function() {
13988     this._curve.lineStart();
13989   },
13990   lineEnd: function() {
13991     this._curve.lineEnd();
13992   },
13993   point: function(a, r) {
13994     this._curve.point(r * Math.sin(a), r * -Math.cos(a));
13995   }
13996 };
13997
13998 function curveRadial(curve) {
13999
14000   function radial(context) {
14001     return new Radial(curve(context));
14002   }
14003
14004   radial._curve = curve;
14005
14006   return radial;
14007 }
14008
14009 function lineRadial(l) {
14010   var c = l.curve;
14011
14012   l.angle = l.x, delete l.x;
14013   l.radius = l.y, delete l.y;
14014
14015   l.curve = function(_) {
14016     return arguments.length ? c(curveRadial(_)) : c()._curve;
14017   };
14018
14019   return l;
14020 }
14021
14022 var lineRadial$1 = function() {
14023   return lineRadial(line().curve(curveRadialLinear));
14024 };
14025
14026 var areaRadial = function() {
14027   var a = area$2().curve(curveRadialLinear),
14028       c = a.curve,
14029       x0 = a.lineX0,
14030       x1 = a.lineX1,
14031       y0 = a.lineY0,
14032       y1 = a.lineY1;
14033
14034   a.angle = a.x, delete a.x;
14035   a.startAngle = a.x0, delete a.x0;
14036   a.endAngle = a.x1, delete a.x1;
14037   a.radius = a.y, delete a.y;
14038   a.innerRadius = a.y0, delete a.y0;
14039   a.outerRadius = a.y1, delete a.y1;
14040   a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
14041   a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
14042   a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
14043   a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
14044
14045   a.curve = function(_) {
14046     return arguments.length ? c(curveRadial(_)) : c()._curve;
14047   };
14048
14049   return a;
14050 };
14051
14052 var pointRadial = function(x, y) {
14053   return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
14054 };
14055
14056 var slice$6 = Array.prototype.slice;
14057
14058 function linkSource(d) {
14059   return d.source;
14060 }
14061
14062 function linkTarget(d) {
14063   return d.target;
14064 }
14065
14066 function link$2(curve) {
14067   var source = linkSource,
14068       target = linkTarget,
14069       x$$1 = x$3,
14070       y$$1 = y$3,
14071       context = null;
14072
14073   function link() {
14074     var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
14075     if (!context) context = buffer = path();
14076     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));
14077     if (buffer) return context = null, buffer + "" || null;
14078   }
14079
14080   link.source = function(_) {
14081     return arguments.length ? (source = _, link) : source;
14082   };
14083
14084   link.target = function(_) {
14085     return arguments.length ? (target = _, link) : target;
14086   };
14087
14088   link.x = function(_) {
14089     return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : x$$1;
14090   };
14091
14092   link.y = function(_) {
14093     return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$10(+_), link) : y$$1;
14094   };
14095
14096   link.context = function(_) {
14097     return arguments.length ? (context = _ == null ? null : _, link) : context;
14098   };
14099
14100   return link;
14101 }
14102
14103 function curveHorizontal(context, x0, y0, x1, y1) {
14104   context.moveTo(x0, y0);
14105   context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
14106 }
14107
14108 function curveVertical(context, x0, y0, x1, y1) {
14109   context.moveTo(x0, y0);
14110   context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
14111 }
14112
14113 function curveRadial$1(context, x0, y0, x1, y1) {
14114   var p0 = pointRadial(x0, y0),
14115       p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
14116       p2 = pointRadial(x1, y0),
14117       p3 = pointRadial(x1, y1);
14118   context.moveTo(p0[0], p0[1]);
14119   context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
14120 }
14121
14122 function linkHorizontal() {
14123   return link$2(curveHorizontal);
14124 }
14125
14126 function linkVertical() {
14127   return link$2(curveVertical);
14128 }
14129
14130 function linkRadial() {
14131   var l = link$2(curveRadial$1);
14132   l.angle = l.x, delete l.x;
14133   l.radius = l.y, delete l.y;
14134   return l;
14135 }
14136
14137 var circle$2 = {
14138   draw: function(context, size) {
14139     var r = Math.sqrt(size / pi$4);
14140     context.moveTo(r, 0);
14141     context.arc(0, 0, r, 0, tau$4);
14142   }
14143 };
14144
14145 var cross$2 = {
14146   draw: function(context, size) {
14147     var r = Math.sqrt(size / 5) / 2;
14148     context.moveTo(-3 * r, -r);
14149     context.lineTo(-r, -r);
14150     context.lineTo(-r, -3 * r);
14151     context.lineTo(r, -3 * r);
14152     context.lineTo(r, -r);
14153     context.lineTo(3 * r, -r);
14154     context.lineTo(3 * r, r);
14155     context.lineTo(r, r);
14156     context.lineTo(r, 3 * r);
14157     context.lineTo(-r, 3 * r);
14158     context.lineTo(-r, r);
14159     context.lineTo(-3 * r, r);
14160     context.closePath();
14161   }
14162 };
14163
14164 var tan30 = Math.sqrt(1 / 3);
14165 var tan30_2 = tan30 * 2;
14166
14167 var diamond = {
14168   draw: function(context, size) {
14169     var y = Math.sqrt(size / tan30_2),
14170         x = y * tan30;
14171     context.moveTo(0, -y);
14172     context.lineTo(x, 0);
14173     context.lineTo(0, y);
14174     context.lineTo(-x, 0);
14175     context.closePath();
14176   }
14177 };
14178
14179 var ka = 0.89081309152928522810;
14180 var kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10);
14181 var kx = Math.sin(tau$4 / 10) * kr;
14182 var ky = -Math.cos(tau$4 / 10) * kr;
14183
14184 var star = {
14185   draw: function(context, size) {
14186     var r = Math.sqrt(size * ka),
14187         x = kx * r,
14188         y = ky * r;
14189     context.moveTo(0, -r);
14190     context.lineTo(x, y);
14191     for (var i = 1; i < 5; ++i) {
14192       var a = tau$4 * i / 5,
14193           c = Math.cos(a),
14194           s = Math.sin(a);
14195       context.lineTo(s * r, -c * r);
14196       context.lineTo(c * x - s * y, s * x + c * y);
14197     }
14198     context.closePath();
14199   }
14200 };
14201
14202 var square = {
14203   draw: function(context, size) {
14204     var w = Math.sqrt(size),
14205         x = -w / 2;
14206     context.rect(x, x, w, w);
14207   }
14208 };
14209
14210 var sqrt3 = Math.sqrt(3);
14211
14212 var triangle = {
14213   draw: function(context, size) {
14214     var y = -Math.sqrt(size / (sqrt3 * 3));
14215     context.moveTo(0, y * 2);
14216     context.lineTo(-sqrt3 * y, -y);
14217     context.lineTo(sqrt3 * y, -y);
14218     context.closePath();
14219   }
14220 };
14221
14222 var c = -0.5;
14223 var s = Math.sqrt(3) / 2;
14224 var k = 1 / Math.sqrt(12);
14225 var a = (k / 2 + 1) * 3;
14226
14227 var wye = {
14228   draw: function(context, size) {
14229     var r = Math.sqrt(size / a),
14230         x0 = r / 2,
14231         y0 = r * k,
14232         x1 = x0,
14233         y1 = r * k + r,
14234         x2 = -x1,
14235         y2 = y1;
14236     context.moveTo(x0, y0);
14237     context.lineTo(x1, y1);
14238     context.lineTo(x2, y2);
14239     context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
14240     context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
14241     context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
14242     context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
14243     context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
14244     context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
14245     context.closePath();
14246   }
14247 };
14248
14249 var symbols = [
14250   circle$2,
14251   cross$2,
14252   diamond,
14253   square,
14254   star,
14255   triangle,
14256   wye
14257 ];
14258
14259 var symbol = function() {
14260   var type = constant$10(circle$2),
14261       size = constant$10(64),
14262       context = null;
14263
14264   function symbol() {
14265     var buffer;
14266     if (!context) context = buffer = path();
14267     type.apply(this, arguments).draw(context, +size.apply(this, arguments));
14268     if (buffer) return context = null, buffer + "" || null;
14269   }
14270
14271   symbol.type = function(_) {
14272     return arguments.length ? (type = typeof _ === "function" ? _ : constant$10(_), symbol) : type;
14273   };
14274
14275   symbol.size = function(_) {
14276     return arguments.length ? (size = typeof _ === "function" ? _ : constant$10(+_), symbol) : size;
14277   };
14278
14279   symbol.context = function(_) {
14280     return arguments.length ? (context = _ == null ? null : _, symbol) : context;
14281   };
14282
14283   return symbol;
14284 };
14285
14286 var noop$2 = function() {};
14287
14288 function point$2(that, x, y) {
14289   that._context.bezierCurveTo(
14290     (2 * that._x0 + that._x1) / 3,
14291     (2 * that._y0 + that._y1) / 3,
14292     (that._x0 + 2 * that._x1) / 3,
14293     (that._y0 + 2 * that._y1) / 3,
14294     (that._x0 + 4 * that._x1 + x) / 6,
14295     (that._y0 + 4 * that._y1 + y) / 6
14296   );
14297 }
14298
14299 function Basis(context) {
14300   this._context = context;
14301 }
14302
14303 Basis.prototype = {
14304   areaStart: function() {
14305     this._line = 0;
14306   },
14307   areaEnd: function() {
14308     this._line = NaN;
14309   },
14310   lineStart: function() {
14311     this._x0 = this._x1 =
14312     this._y0 = this._y1 = NaN;
14313     this._point = 0;
14314   },
14315   lineEnd: function() {
14316     switch (this._point) {
14317       case 3: point$2(this, this._x1, this._y1); // proceed
14318       case 2: this._context.lineTo(this._x1, this._y1); break;
14319     }
14320     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14321     this._line = 1 - this._line;
14322   },
14323   point: function(x, y) {
14324     x = +x, y = +y;
14325     switch (this._point) {
14326       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14327       case 1: this._point = 2; break;
14328       case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
14329       default: point$2(this, x, y); break;
14330     }
14331     this._x0 = this._x1, this._x1 = x;
14332     this._y0 = this._y1, this._y1 = y;
14333   }
14334 };
14335
14336 var basis$2 = function(context) {
14337   return new Basis(context);
14338 };
14339
14340 function BasisClosed(context) {
14341   this._context = context;
14342 }
14343
14344 BasisClosed.prototype = {
14345   areaStart: noop$2,
14346   areaEnd: noop$2,
14347   lineStart: function() {
14348     this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
14349     this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
14350     this._point = 0;
14351   },
14352   lineEnd: function() {
14353     switch (this._point) {
14354       case 1: {
14355         this._context.moveTo(this._x2, this._y2);
14356         this._context.closePath();
14357         break;
14358       }
14359       case 2: {
14360         this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
14361         this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
14362         this._context.closePath();
14363         break;
14364       }
14365       case 3: {
14366         this.point(this._x2, this._y2);
14367         this.point(this._x3, this._y3);
14368         this.point(this._x4, this._y4);
14369         break;
14370       }
14371     }
14372   },
14373   point: function(x, y) {
14374     x = +x, y = +y;
14375     switch (this._point) {
14376       case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
14377       case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
14378       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;
14379       default: point$2(this, x, y); break;
14380     }
14381     this._x0 = this._x1, this._x1 = x;
14382     this._y0 = this._y1, this._y1 = y;
14383   }
14384 };
14385
14386 var basisClosed$1 = function(context) {
14387   return new BasisClosed(context);
14388 };
14389
14390 function BasisOpen(context) {
14391   this._context = context;
14392 }
14393
14394 BasisOpen.prototype = {
14395   areaStart: function() {
14396     this._line = 0;
14397   },
14398   areaEnd: function() {
14399     this._line = NaN;
14400   },
14401   lineStart: function() {
14402     this._x0 = this._x1 =
14403     this._y0 = this._y1 = NaN;
14404     this._point = 0;
14405   },
14406   lineEnd: function() {
14407     if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
14408     this._line = 1 - this._line;
14409   },
14410   point: function(x, y) {
14411     x = +x, y = +y;
14412     switch (this._point) {
14413       case 0: this._point = 1; break;
14414       case 1: this._point = 2; break;
14415       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;
14416       case 3: this._point = 4; // proceed
14417       default: point$2(this, x, y); break;
14418     }
14419     this._x0 = this._x1, this._x1 = x;
14420     this._y0 = this._y1, this._y1 = y;
14421   }
14422 };
14423
14424 var basisOpen = function(context) {
14425   return new BasisOpen(context);
14426 };
14427
14428 function Bundle(context, beta) {
14429   this._basis = new Basis(context);
14430   this._beta = beta;
14431 }
14432
14433 Bundle.prototype = {
14434   lineStart: function() {
14435     this._x = [];
14436     this._y = [];
14437     this._basis.lineStart();
14438   },
14439   lineEnd: function() {
14440     var x = this._x,
14441         y = this._y,
14442         j = x.length - 1;
14443
14444     if (j > 0) {
14445       var x0 = x[0],
14446           y0 = y[0],
14447           dx = x[j] - x0,
14448           dy = y[j] - y0,
14449           i = -1,
14450           t;
14451
14452       while (++i <= j) {
14453         t = i / j;
14454         this._basis.point(
14455           this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
14456           this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
14457         );
14458       }
14459     }
14460
14461     this._x = this._y = null;
14462     this._basis.lineEnd();
14463   },
14464   point: function(x, y) {
14465     this._x.push(+x);
14466     this._y.push(+y);
14467   }
14468 };
14469
14470 var bundle = (function custom(beta) {
14471
14472   function bundle(context) {
14473     return beta === 1 ? new Basis(context) : new Bundle(context, beta);
14474   }
14475
14476   bundle.beta = function(beta) {
14477     return custom(+beta);
14478   };
14479
14480   return bundle;
14481 })(0.85);
14482
14483 function point$3(that, x, y) {
14484   that._context.bezierCurveTo(
14485     that._x1 + that._k * (that._x2 - that._x0),
14486     that._y1 + that._k * (that._y2 - that._y0),
14487     that._x2 + that._k * (that._x1 - x),
14488     that._y2 + that._k * (that._y1 - y),
14489     that._x2,
14490     that._y2
14491   );
14492 }
14493
14494 function Cardinal(context, tension) {
14495   this._context = context;
14496   this._k = (1 - tension) / 6;
14497 }
14498
14499 Cardinal.prototype = {
14500   areaStart: function() {
14501     this._line = 0;
14502   },
14503   areaEnd: function() {
14504     this._line = NaN;
14505   },
14506   lineStart: function() {
14507     this._x0 = this._x1 = this._x2 =
14508     this._y0 = this._y1 = this._y2 = NaN;
14509     this._point = 0;
14510   },
14511   lineEnd: function() {
14512     switch (this._point) {
14513       case 2: this._context.lineTo(this._x2, this._y2); break;
14514       case 3: point$3(this, this._x1, this._y1); break;
14515     }
14516     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14517     this._line = 1 - this._line;
14518   },
14519   point: function(x, y) {
14520     x = +x, y = +y;
14521     switch (this._point) {
14522       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14523       case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
14524       case 2: this._point = 3; // proceed
14525       default: point$3(this, x, y); break;
14526     }
14527     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14528     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14529   }
14530 };
14531
14532 var cardinal = (function custom(tension) {
14533
14534   function cardinal(context) {
14535     return new Cardinal(context, tension);
14536   }
14537
14538   cardinal.tension = function(tension) {
14539     return custom(+tension);
14540   };
14541
14542   return cardinal;
14543 })(0);
14544
14545 function CardinalClosed(context, tension) {
14546   this._context = context;
14547   this._k = (1 - tension) / 6;
14548 }
14549
14550 CardinalClosed.prototype = {
14551   areaStart: noop$2,
14552   areaEnd: noop$2,
14553   lineStart: function() {
14554     this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
14555     this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
14556     this._point = 0;
14557   },
14558   lineEnd: function() {
14559     switch (this._point) {
14560       case 1: {
14561         this._context.moveTo(this._x3, this._y3);
14562         this._context.closePath();
14563         break;
14564       }
14565       case 2: {
14566         this._context.lineTo(this._x3, this._y3);
14567         this._context.closePath();
14568         break;
14569       }
14570       case 3: {
14571         this.point(this._x3, this._y3);
14572         this.point(this._x4, this._y4);
14573         this.point(this._x5, this._y5);
14574         break;
14575       }
14576     }
14577   },
14578   point: function(x, y) {
14579     x = +x, y = +y;
14580     switch (this._point) {
14581       case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
14582       case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
14583       case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
14584       default: point$3(this, x, y); break;
14585     }
14586     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14587     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14588   }
14589 };
14590
14591 var cardinalClosed = (function custom(tension) {
14592
14593   function cardinal$$1(context) {
14594     return new CardinalClosed(context, tension);
14595   }
14596
14597   cardinal$$1.tension = function(tension) {
14598     return custom(+tension);
14599   };
14600
14601   return cardinal$$1;
14602 })(0);
14603
14604 function CardinalOpen(context, tension) {
14605   this._context = context;
14606   this._k = (1 - tension) / 6;
14607 }
14608
14609 CardinalOpen.prototype = {
14610   areaStart: function() {
14611     this._line = 0;
14612   },
14613   areaEnd: function() {
14614     this._line = NaN;
14615   },
14616   lineStart: function() {
14617     this._x0 = this._x1 = this._x2 =
14618     this._y0 = this._y1 = this._y2 = NaN;
14619     this._point = 0;
14620   },
14621   lineEnd: function() {
14622     if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
14623     this._line = 1 - this._line;
14624   },
14625   point: function(x, y) {
14626     x = +x, y = +y;
14627     switch (this._point) {
14628       case 0: this._point = 1; break;
14629       case 1: this._point = 2; break;
14630       case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
14631       case 3: this._point = 4; // proceed
14632       default: point$3(this, x, y); break;
14633     }
14634     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14635     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14636   }
14637 };
14638
14639 var cardinalOpen = (function custom(tension) {
14640
14641   function cardinal$$1(context) {
14642     return new CardinalOpen(context, tension);
14643   }
14644
14645   cardinal$$1.tension = function(tension) {
14646     return custom(+tension);
14647   };
14648
14649   return cardinal$$1;
14650 })(0);
14651
14652 function point$4(that, x, y) {
14653   var x1 = that._x1,
14654       y1 = that._y1,
14655       x2 = that._x2,
14656       y2 = that._y2;
14657
14658   if (that._l01_a > epsilon$3) {
14659     var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
14660         n = 3 * that._l01_a * (that._l01_a + that._l12_a);
14661     x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
14662     y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
14663   }
14664
14665   if (that._l23_a > epsilon$3) {
14666     var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
14667         m = 3 * that._l23_a * (that._l23_a + that._l12_a);
14668     x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
14669     y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
14670   }
14671
14672   that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
14673 }
14674
14675 function CatmullRom(context, alpha) {
14676   this._context = context;
14677   this._alpha = alpha;
14678 }
14679
14680 CatmullRom.prototype = {
14681   areaStart: function() {
14682     this._line = 0;
14683   },
14684   areaEnd: function() {
14685     this._line = NaN;
14686   },
14687   lineStart: function() {
14688     this._x0 = this._x1 = this._x2 =
14689     this._y0 = this._y1 = this._y2 = NaN;
14690     this._l01_a = this._l12_a = this._l23_a =
14691     this._l01_2a = this._l12_2a = this._l23_2a =
14692     this._point = 0;
14693   },
14694   lineEnd: function() {
14695     switch (this._point) {
14696       case 2: this._context.lineTo(this._x2, this._y2); break;
14697       case 3: this.point(this._x2, this._y2); break;
14698     }
14699     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14700     this._line = 1 - this._line;
14701   },
14702   point: function(x, y) {
14703     x = +x, y = +y;
14704
14705     if (this._point) {
14706       var x23 = this._x2 - x,
14707           y23 = this._y2 - y;
14708       this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
14709     }
14710
14711     switch (this._point) {
14712       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14713       case 1: this._point = 2; break;
14714       case 2: this._point = 3; // proceed
14715       default: point$4(this, x, y); break;
14716     }
14717
14718     this._l01_a = this._l12_a, this._l12_a = this._l23_a;
14719     this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
14720     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14721     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14722   }
14723 };
14724
14725 var catmullRom = (function custom(alpha) {
14726
14727   function catmullRom(context) {
14728     return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
14729   }
14730
14731   catmullRom.alpha = function(alpha) {
14732     return custom(+alpha);
14733   };
14734
14735   return catmullRom;
14736 })(0.5);
14737
14738 function CatmullRomClosed(context, alpha) {
14739   this._context = context;
14740   this._alpha = alpha;
14741 }
14742
14743 CatmullRomClosed.prototype = {
14744   areaStart: noop$2,
14745   areaEnd: noop$2,
14746   lineStart: function() {
14747     this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
14748     this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
14749     this._l01_a = this._l12_a = this._l23_a =
14750     this._l01_2a = this._l12_2a = this._l23_2a =
14751     this._point = 0;
14752   },
14753   lineEnd: function() {
14754     switch (this._point) {
14755       case 1: {
14756         this._context.moveTo(this._x3, this._y3);
14757         this._context.closePath();
14758         break;
14759       }
14760       case 2: {
14761         this._context.lineTo(this._x3, this._y3);
14762         this._context.closePath();
14763         break;
14764       }
14765       case 3: {
14766         this.point(this._x3, this._y3);
14767         this.point(this._x4, this._y4);
14768         this.point(this._x5, this._y5);
14769         break;
14770       }
14771     }
14772   },
14773   point: function(x, y) {
14774     x = +x, y = +y;
14775
14776     if (this._point) {
14777       var x23 = this._x2 - x,
14778           y23 = this._y2 - y;
14779       this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
14780     }
14781
14782     switch (this._point) {
14783       case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
14784       case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
14785       case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
14786       default: point$4(this, x, y); break;
14787     }
14788
14789     this._l01_a = this._l12_a, this._l12_a = this._l23_a;
14790     this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
14791     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14792     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14793   }
14794 };
14795
14796 var catmullRomClosed = (function custom(alpha) {
14797
14798   function catmullRom$$1(context) {
14799     return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
14800   }
14801
14802   catmullRom$$1.alpha = function(alpha) {
14803     return custom(+alpha);
14804   };
14805
14806   return catmullRom$$1;
14807 })(0.5);
14808
14809 function CatmullRomOpen(context, alpha) {
14810   this._context = context;
14811   this._alpha = alpha;
14812 }
14813
14814 CatmullRomOpen.prototype = {
14815   areaStart: function() {
14816     this._line = 0;
14817   },
14818   areaEnd: function() {
14819     this._line = NaN;
14820   },
14821   lineStart: function() {
14822     this._x0 = this._x1 = this._x2 =
14823     this._y0 = this._y1 = this._y2 = NaN;
14824     this._l01_a = this._l12_a = this._l23_a =
14825     this._l01_2a = this._l12_2a = this._l23_2a =
14826     this._point = 0;
14827   },
14828   lineEnd: function() {
14829     if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
14830     this._line = 1 - this._line;
14831   },
14832   point: function(x, y) {
14833     x = +x, y = +y;
14834
14835     if (this._point) {
14836       var x23 = this._x2 - x,
14837           y23 = this._y2 - y;
14838       this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
14839     }
14840
14841     switch (this._point) {
14842       case 0: this._point = 1; break;
14843       case 1: this._point = 2; break;
14844       case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
14845       case 3: this._point = 4; // proceed
14846       default: point$4(this, x, y); break;
14847     }
14848
14849     this._l01_a = this._l12_a, this._l12_a = this._l23_a;
14850     this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
14851     this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
14852     this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
14853   }
14854 };
14855
14856 var catmullRomOpen = (function custom(alpha) {
14857
14858   function catmullRom$$1(context) {
14859     return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
14860   }
14861
14862   catmullRom$$1.alpha = function(alpha) {
14863     return custom(+alpha);
14864   };
14865
14866   return catmullRom$$1;
14867 })(0.5);
14868
14869 function LinearClosed(context) {
14870   this._context = context;
14871 }
14872
14873 LinearClosed.prototype = {
14874   areaStart: noop$2,
14875   areaEnd: noop$2,
14876   lineStart: function() {
14877     this._point = 0;
14878   },
14879   lineEnd: function() {
14880     if (this._point) this._context.closePath();
14881   },
14882   point: function(x, y) {
14883     x = +x, y = +y;
14884     if (this._point) this._context.lineTo(x, y);
14885     else this._point = 1, this._context.moveTo(x, y);
14886   }
14887 };
14888
14889 var linearClosed = function(context) {
14890   return new LinearClosed(context);
14891 };
14892
14893 function sign$1(x) {
14894   return x < 0 ? -1 : 1;
14895 }
14896
14897 // Calculate the slopes of the tangents (Hermite-type interpolation) based on
14898 // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
14899 // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
14900 // NOV(II), P. 443, 1990.
14901 function slope3(that, x2, y2) {
14902   var h0 = that._x1 - that._x0,
14903       h1 = x2 - that._x1,
14904       s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
14905       s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
14906       p = (s0 * h1 + s1 * h0) / (h0 + h1);
14907   return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
14908 }
14909
14910 // Calculate a one-sided slope.
14911 function slope2(that, t) {
14912   var h = that._x1 - that._x0;
14913   return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
14914 }
14915
14916 // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
14917 // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
14918 // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
14919 function point$5(that, t0, t1) {
14920   var x0 = that._x0,
14921       y0 = that._y0,
14922       x1 = that._x1,
14923       y1 = that._y1,
14924       dx = (x1 - x0) / 3;
14925   that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
14926 }
14927
14928 function MonotoneX(context) {
14929   this._context = context;
14930 }
14931
14932 MonotoneX.prototype = {
14933   areaStart: function() {
14934     this._line = 0;
14935   },
14936   areaEnd: function() {
14937     this._line = NaN;
14938   },
14939   lineStart: function() {
14940     this._x0 = this._x1 =
14941     this._y0 = this._y1 =
14942     this._t0 = NaN;
14943     this._point = 0;
14944   },
14945   lineEnd: function() {
14946     switch (this._point) {
14947       case 2: this._context.lineTo(this._x1, this._y1); break;
14948       case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
14949     }
14950     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14951     this._line = 1 - this._line;
14952   },
14953   point: function(x, y) {
14954     var t1 = NaN;
14955
14956     x = +x, y = +y;
14957     if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
14958     switch (this._point) {
14959       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14960       case 1: this._point = 2; break;
14961       case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
14962       default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
14963     }
14964
14965     this._x0 = this._x1, this._x1 = x;
14966     this._y0 = this._y1, this._y1 = y;
14967     this._t0 = t1;
14968   }
14969 };
14970
14971 function MonotoneY(context) {
14972   this._context = new ReflectContext(context);
14973 }
14974
14975 (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
14976   MonotoneX.prototype.point.call(this, y, x);
14977 };
14978
14979 function ReflectContext(context) {
14980   this._context = context;
14981 }
14982
14983 ReflectContext.prototype = {
14984   moveTo: function(x, y) { this._context.moveTo(y, x); },
14985   closePath: function() { this._context.closePath(); },
14986   lineTo: function(x, y) { this._context.lineTo(y, x); },
14987   bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
14988 };
14989
14990 function monotoneX(context) {
14991   return new MonotoneX(context);
14992 }
14993
14994 function monotoneY(context) {
14995   return new MonotoneY(context);
14996 }
14997
14998 function Natural(context) {
14999   this._context = context;
15000 }
15001
15002 Natural.prototype = {
15003   areaStart: function() {
15004     this._line = 0;
15005   },
15006   areaEnd: function() {
15007     this._line = NaN;
15008   },
15009   lineStart: function() {
15010     this._x = [];
15011     this._y = [];
15012   },
15013   lineEnd: function() {
15014     var x = this._x,
15015         y = this._y,
15016         n = x.length;
15017
15018     if (n) {
15019       this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
15020       if (n === 2) {
15021         this._context.lineTo(x[1], y[1]);
15022       } else {
15023         var px = controlPoints(x),
15024             py = controlPoints(y);
15025         for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
15026           this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
15027         }
15028       }
15029     }
15030
15031     if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
15032     this._line = 1 - this._line;
15033     this._x = this._y = null;
15034   },
15035   point: function(x, y) {
15036     this._x.push(+x);
15037     this._y.push(+y);
15038   }
15039 };
15040
15041 // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
15042 function controlPoints(x) {
15043   var i,
15044       n = x.length - 1,
15045       m,
15046       a = new Array(n),
15047       b = new Array(n),
15048       r = new Array(n);
15049   a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
15050   for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
15051   a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
15052   for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
15053   a[n - 1] = r[n - 1] / b[n - 1];
15054   for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
15055   b[n - 1] = (x[n] + a[n - 1]) / 2;
15056   for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
15057   return [a, b];
15058 }
15059
15060 var natural = function(context) {
15061   return new Natural(context);
15062 };
15063
15064 function Step(context, t) {
15065   this._context = context;
15066   this._t = t;
15067 }
15068
15069 Step.prototype = {
15070   areaStart: function() {
15071     this._line = 0;
15072   },
15073   areaEnd: function() {
15074     this._line = NaN;
15075   },
15076   lineStart: function() {
15077     this._x = this._y = NaN;
15078     this._point = 0;
15079   },
15080   lineEnd: function() {
15081     if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
15082     if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15083     if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
15084   },
15085   point: function(x, y) {
15086     x = +x, y = +y;
15087     switch (this._point) {
15088       case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15089       case 1: this._point = 2; // proceed
15090       default: {
15091         if (this._t <= 0) {
15092           this._context.lineTo(this._x, y);
15093           this._context.lineTo(x, y);
15094         } else {
15095           var x1 = this._x * (1 - this._t) + x * this._t;
15096           this._context.lineTo(x1, this._y);
15097           this._context.lineTo(x1, y);
15098         }
15099         break;
15100       }
15101     }
15102     this._x = x, this._y = y;
15103   }
15104 };
15105
15106 var step = function(context) {
15107   return new Step(context, 0.5);
15108 };
15109
15110 function stepBefore(context) {
15111   return new Step(context, 0);
15112 }
15113
15114 function stepAfter(context) {
15115   return new Step(context, 1);
15116 }
15117
15118 var none$1 = function(series, order) {
15119   if (!((n = series.length) > 1)) return;
15120   for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
15121     s0 = s1, s1 = series[order[i]];
15122     for (j = 0; j < m; ++j) {
15123       s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
15124     }
15125   }
15126 };
15127
15128 var none$2 = function(series) {
15129   var n = series.length, o = new Array(n);
15130   while (--n >= 0) o[n] = n;
15131   return o;
15132 };
15133
15134 function stackValue(d, key) {
15135   return d[key];
15136 }
15137
15138 var stack = function() {
15139   var keys = constant$10([]),
15140       order = none$2,
15141       offset = none$1,
15142       value = stackValue;
15143
15144   function stack(data) {
15145     var kz = keys.apply(this, arguments),
15146         i,
15147         m = data.length,
15148         n = kz.length,
15149         sz = new Array(n),
15150         oz;
15151
15152     for (i = 0; i < n; ++i) {
15153       for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
15154         si[j] = sij = [0, +value(data[j], ki, j, data)];
15155         sij.data = data[j];
15156       }
15157       si.key = ki;
15158     }
15159
15160     for (i = 0, oz = order(sz); i < n; ++i) {
15161       sz[oz[i]].index = i;
15162     }
15163
15164     offset(sz, oz);
15165     return sz;
15166   }
15167
15168   stack.keys = function(_) {
15169     return arguments.length ? (keys = typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : keys;
15170   };
15171
15172   stack.value = function(_) {
15173     return arguments.length ? (value = typeof _ === "function" ? _ : constant$10(+_), stack) : value;
15174   };
15175
15176   stack.order = function(_) {
15177     return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$10(slice$6.call(_)), stack) : order;
15178   };
15179
15180   stack.offset = function(_) {
15181     return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
15182   };
15183
15184   return stack;
15185 };
15186
15187 var expand = function(series, order) {
15188   if (!((n = series.length) > 0)) return;
15189   for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
15190     for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
15191     if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
15192   }
15193   none$1(series, order);
15194 };
15195
15196 var diverging = function(series, order) {
15197   if (!((n = series.length) > 1)) return;
15198   for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
15199     for (yp = yn = 0, i = 0; i < n; ++i) {
15200       if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
15201         d[0] = yp, d[1] = yp += dy;
15202       } else if (dy < 0) {
15203         d[1] = yn, d[0] = yn += dy;
15204       } else {
15205         d[0] = yp;
15206       }
15207     }
15208   }
15209 };
15210
15211 var silhouette = function(series, order) {
15212   if (!((n = series.length) > 0)) return;
15213   for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
15214     for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
15215     s0[j][1] += s0[j][0] = -y / 2;
15216   }
15217   none$1(series, order);
15218 };
15219
15220 var wiggle = function(series, order) {
15221   if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
15222   for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
15223     for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
15224       var si = series[order[i]],
15225           sij0 = si[j][1] || 0,
15226           sij1 = si[j - 1][1] || 0,
15227           s3 = (sij0 - sij1) / 2;
15228       for (var k = 0; k < i; ++k) {
15229         var sk = series[order[k]],
15230             skj0 = sk[j][1] || 0,
15231             skj1 = sk[j - 1][1] || 0;
15232         s3 += skj0 - skj1;
15233       }
15234       s1 += sij0, s2 += s3 * sij0;
15235     }
15236     s0[j - 1][1] += s0[j - 1][0] = y;
15237     if (s1) y -= s2 / s1;
15238   }
15239   s0[j - 1][1] += s0[j - 1][0] = y;
15240   none$1(series, order);
15241 };
15242
15243 var ascending$2 = function(series) {
15244   var sums = series.map(sum$2);
15245   return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
15246 };
15247
15248 function sum$2(series) {
15249   var s = 0, i = -1, n = series.length, v;
15250   while (++i < n) if (v = +series[i][1]) s += v;
15251   return s;
15252 }
15253
15254 var descending$2 = function(series) {
15255   return ascending$2(series).reverse();
15256 };
15257
15258 var insideOut = function(series) {
15259   var n = series.length,
15260       i,
15261       j,
15262       sums = series.map(sum$2),
15263       order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
15264       top = 0,
15265       bottom = 0,
15266       tops = [],
15267       bottoms = [];
15268
15269   for (i = 0; i < n; ++i) {
15270     j = order[i];
15271     if (top < bottom) {
15272       top += sums[j];
15273       tops.push(j);
15274     } else {
15275       bottom += sums[j];
15276       bottoms.push(j);
15277     }
15278   }
15279
15280   return bottoms.reverse().concat(tops);
15281 };
15282
15283 var reverse = function(series) {
15284   return none$2(series).reverse();
15285 };
15286
15287 var constant$11 = function(x) {
15288   return function() {
15289     return x;
15290   };
15291 };
15292
15293 function x$4(d) {
15294   return d[0];
15295 }
15296
15297 function y$4(d) {
15298   return d[1];
15299 }
15300
15301 function RedBlackTree() {
15302   this._ = null; // root node
15303 }
15304
15305 function RedBlackNode(node) {
15306   node.U = // parent node
15307   node.C = // color - true for red, false for black
15308   node.L = // left node
15309   node.R = // right node
15310   node.P = // previous node
15311   node.N = null; // next node
15312 }
15313
15314 RedBlackTree.prototype = {
15315   constructor: RedBlackTree,
15316
15317   insert: function(after, node) {
15318     var parent, grandpa, uncle;
15319
15320     if (after) {
15321       node.P = after;
15322       node.N = after.N;
15323       if (after.N) after.N.P = node;
15324       after.N = node;
15325       if (after.R) {
15326         after = after.R;
15327         while (after.L) after = after.L;
15328         after.L = node;
15329       } else {
15330         after.R = node;
15331       }
15332       parent = after;
15333     } else if (this._) {
15334       after = RedBlackFirst(this._);
15335       node.P = null;
15336       node.N = after;
15337       after.P = after.L = node;
15338       parent = after;
15339     } else {
15340       node.P = node.N = null;
15341       this._ = node;
15342       parent = null;
15343     }
15344     node.L = node.R = null;
15345     node.U = parent;
15346     node.C = true;
15347
15348     after = node;
15349     while (parent && parent.C) {
15350       grandpa = parent.U;
15351       if (parent === grandpa.L) {
15352         uncle = grandpa.R;
15353         if (uncle && uncle.C) {
15354           parent.C = uncle.C = false;
15355           grandpa.C = true;
15356           after = grandpa;
15357         } else {
15358           if (after === parent.R) {
15359             RedBlackRotateLeft(this, parent);
15360             after = parent;
15361             parent = after.U;
15362           }
15363           parent.C = false;
15364           grandpa.C = true;
15365           RedBlackRotateRight(this, grandpa);
15366         }
15367       } else {
15368         uncle = grandpa.L;
15369         if (uncle && uncle.C) {
15370           parent.C = uncle.C = false;
15371           grandpa.C = true;
15372           after = grandpa;
15373         } else {
15374           if (after === parent.L) {
15375             RedBlackRotateRight(this, parent);
15376             after = parent;
15377             parent = after.U;
15378           }
15379           parent.C = false;
15380           grandpa.C = true;
15381           RedBlackRotateLeft(this, grandpa);
15382         }
15383       }
15384       parent = after.U;
15385     }
15386     this._.C = false;
15387   },
15388
15389   remove: function(node) {
15390     if (node.N) node.N.P = node.P;
15391     if (node.P) node.P.N = node.N;
15392     node.N = node.P = null;
15393
15394     var parent = node.U,
15395         sibling,
15396         left = node.L,
15397         right = node.R,
15398         next,
15399         red;
15400
15401     if (!left) next = right;
15402     else if (!right) next = left;
15403     else next = RedBlackFirst(right);
15404
15405     if (parent) {
15406       if (parent.L === node) parent.L = next;
15407       else parent.R = next;
15408     } else {
15409       this._ = next;
15410     }
15411
15412     if (left && right) {
15413       red = next.C;
15414       next.C = node.C;
15415       next.L = left;
15416       left.U = next;
15417       if (next !== right) {
15418         parent = next.U;
15419         next.U = node.U;
15420         node = next.R;
15421         parent.L = node;
15422         next.R = right;
15423         right.U = next;
15424       } else {
15425         next.U = parent;
15426         parent = next;
15427         node = next.R;
15428       }
15429     } else {
15430       red = node.C;
15431       node = next;
15432     }
15433
15434     if (node) node.U = parent;
15435     if (red) return;
15436     if (node && node.C) { node.C = false; return; }
15437
15438     do {
15439       if (node === this._) break;
15440       if (node === parent.L) {
15441         sibling = parent.R;
15442         if (sibling.C) {
15443           sibling.C = false;
15444           parent.C = true;
15445           RedBlackRotateLeft(this, parent);
15446           sibling = parent.R;
15447         }
15448         if ((sibling.L && sibling.L.C)
15449             || (sibling.R && sibling.R.C)) {
15450           if (!sibling.R || !sibling.R.C) {
15451             sibling.L.C = false;
15452             sibling.C = true;
15453             RedBlackRotateRight(this, sibling);
15454             sibling = parent.R;
15455           }
15456           sibling.C = parent.C;
15457           parent.C = sibling.R.C = false;
15458           RedBlackRotateLeft(this, parent);
15459           node = this._;
15460           break;
15461         }
15462       } else {
15463         sibling = parent.L;
15464         if (sibling.C) {
15465           sibling.C = false;
15466           parent.C = true;
15467           RedBlackRotateRight(this, parent);
15468           sibling = parent.L;
15469         }
15470         if ((sibling.L && sibling.L.C)
15471           || (sibling.R && sibling.R.C)) {
15472           if (!sibling.L || !sibling.L.C) {
15473             sibling.R.C = false;
15474             sibling.C = true;
15475             RedBlackRotateLeft(this, sibling);
15476             sibling = parent.L;
15477           }
15478           sibling.C = parent.C;
15479           parent.C = sibling.L.C = false;
15480           RedBlackRotateRight(this, parent);
15481           node = this._;
15482           break;
15483         }
15484       }
15485       sibling.C = true;
15486       node = parent;
15487       parent = parent.U;
15488     } while (!node.C);
15489
15490     if (node) node.C = false;
15491   }
15492 };
15493
15494 function RedBlackRotateLeft(tree, node) {
15495   var p = node,
15496       q = node.R,
15497       parent = p.U;
15498
15499   if (parent) {
15500     if (parent.L === p) parent.L = q;
15501     else parent.R = q;
15502   } else {
15503     tree._ = q;
15504   }
15505
15506   q.U = parent;
15507   p.U = q;
15508   p.R = q.L;
15509   if (p.R) p.R.U = p;
15510   q.L = p;
15511 }
15512
15513 function RedBlackRotateRight(tree, node) {
15514   var p = node,
15515       q = node.L,
15516       parent = p.U;
15517
15518   if (parent) {
15519     if (parent.L === p) parent.L = q;
15520     else parent.R = q;
15521   } else {
15522     tree._ = q;
15523   }
15524
15525   q.U = parent;
15526   p.U = q;
15527   p.L = q.R;
15528   if (p.L) p.L.U = p;
15529   q.R = p;
15530 }
15531
15532 function RedBlackFirst(node) {
15533   while (node.L) node = node.L;
15534   return node;
15535 }
15536
15537 function createEdge(left, right, v0, v1) {
15538   var edge = [null, null],
15539       index = edges.push(edge) - 1;
15540   edge.left = left;
15541   edge.right = right;
15542   if (v0) setEdgeEnd(edge, left, right, v0);
15543   if (v1) setEdgeEnd(edge, right, left, v1);
15544   cells[left.index].halfedges.push(index);
15545   cells[right.index].halfedges.push(index);
15546   return edge;
15547 }
15548
15549 function createBorderEdge(left, v0, v1) {
15550   var edge = [v0, v1];
15551   edge.left = left;
15552   return edge;
15553 }
15554
15555 function setEdgeEnd(edge, left, right, vertex) {
15556   if (!edge[0] && !edge[1]) {
15557     edge[0] = vertex;
15558     edge.left = left;
15559     edge.right = right;
15560   } else if (edge.left === right) {
15561     edge[1] = vertex;
15562   } else {
15563     edge[0] = vertex;
15564   }
15565 }
15566
15567 // Liang–Barsky line clipping.
15568 function clipEdge(edge, x0, y0, x1, y1) {
15569   var a = edge[0],
15570       b = edge[1],
15571       ax = a[0],
15572       ay = a[1],
15573       bx = b[0],
15574       by = b[1],
15575       t0 = 0,
15576       t1 = 1,
15577       dx = bx - ax,
15578       dy = by - ay,
15579       r;
15580
15581   r = x0 - ax;
15582   if (!dx && r > 0) return;
15583   r /= dx;
15584   if (dx < 0) {
15585     if (r < t0) return;
15586     if (r < t1) t1 = r;
15587   } else if (dx > 0) {
15588     if (r > t1) return;
15589     if (r > t0) t0 = r;
15590   }
15591
15592   r = x1 - ax;
15593   if (!dx && r < 0) return;
15594   r /= dx;
15595   if (dx < 0) {
15596     if (r > t1) return;
15597     if (r > t0) t0 = r;
15598   } else if (dx > 0) {
15599     if (r < t0) return;
15600     if (r < t1) t1 = r;
15601   }
15602
15603   r = y0 - ay;
15604   if (!dy && r > 0) return;
15605   r /= dy;
15606   if (dy < 0) {
15607     if (r < t0) return;
15608     if (r < t1) t1 = r;
15609   } else if (dy > 0) {
15610     if (r > t1) return;
15611     if (r > t0) t0 = r;
15612   }
15613
15614   r = y1 - ay;
15615   if (!dy && r < 0) return;
15616   r /= dy;
15617   if (dy < 0) {
15618     if (r > t1) return;
15619     if (r > t0) t0 = r;
15620   } else if (dy > 0) {
15621     if (r < t0) return;
15622     if (r < t1) t1 = r;
15623   }
15624
15625   if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
15626
15627   if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
15628   if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
15629   return true;
15630 }
15631
15632 function connectEdge(edge, x0, y0, x1, y1) {
15633   var v1 = edge[1];
15634   if (v1) return true;
15635
15636   var v0 = edge[0],
15637       left = edge.left,
15638       right = edge.right,
15639       lx = left[0],
15640       ly = left[1],
15641       rx = right[0],
15642       ry = right[1],
15643       fx = (lx + rx) / 2,
15644       fy = (ly + ry) / 2,
15645       fm,
15646       fb;
15647
15648   if (ry === ly) {
15649     if (fx < x0 || fx >= x1) return;
15650     if (lx > rx) {
15651       if (!v0) v0 = [fx, y0];
15652       else if (v0[1] >= y1) return;
15653       v1 = [fx, y1];
15654     } else {
15655       if (!v0) v0 = [fx, y1];
15656       else if (v0[1] < y0) return;
15657       v1 = [fx, y0];
15658     }
15659   } else {
15660     fm = (lx - rx) / (ry - ly);
15661     fb = fy - fm * fx;
15662     if (fm < -1 || fm > 1) {
15663       if (lx > rx) {
15664         if (!v0) v0 = [(y0 - fb) / fm, y0];
15665         else if (v0[1] >= y1) return;
15666         v1 = [(y1 - fb) / fm, y1];
15667       } else {
15668         if (!v0) v0 = [(y1 - fb) / fm, y1];
15669         else if (v0[1] < y0) return;
15670         v1 = [(y0 - fb) / fm, y0];
15671       }
15672     } else {
15673       if (ly < ry) {
15674         if (!v0) v0 = [x0, fm * x0 + fb];
15675         else if (v0[0] >= x1) return;
15676         v1 = [x1, fm * x1 + fb];
15677       } else {
15678         if (!v0) v0 = [x1, fm * x1 + fb];
15679         else if (v0[0] < x0) return;
15680         v1 = [x0, fm * x0 + fb];
15681       }
15682     }
15683   }
15684
15685   edge[0] = v0;
15686   edge[1] = v1;
15687   return true;
15688 }
15689
15690 function clipEdges(x0, y0, x1, y1) {
15691   var i = edges.length,
15692       edge;
15693
15694   while (i--) {
15695     if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
15696         || !clipEdge(edge, x0, y0, x1, y1)
15697         || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
15698             || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
15699       delete edges[i];
15700     }
15701   }
15702 }
15703
15704 function createCell(site) {
15705   return cells[site.index] = {
15706     site: site,
15707     halfedges: []
15708   };
15709 }
15710
15711 function cellHalfedgeAngle(cell, edge) {
15712   var site = cell.site,
15713       va = edge.left,
15714       vb = edge.right;
15715   if (site === vb) vb = va, va = site;
15716   if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
15717   if (site === va) va = edge[1], vb = edge[0];
15718   else va = edge[0], vb = edge[1];
15719   return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
15720 }
15721
15722 function cellHalfedgeStart(cell, edge) {
15723   return edge[+(edge.left !== cell.site)];
15724 }
15725
15726 function cellHalfedgeEnd(cell, edge) {
15727   return edge[+(edge.left === cell.site)];
15728 }
15729
15730 function sortCellHalfedges() {
15731   for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
15732     if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
15733       var index = new Array(m),
15734           array = new Array(m);
15735       for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
15736       index.sort(function(i, j) { return array[j] - array[i]; });
15737       for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
15738       for (j = 0; j < m; ++j) halfedges[j] = array[j];
15739     }
15740   }
15741 }
15742
15743 function clipCells(x0, y0, x1, y1) {
15744   var nCells = cells.length,
15745       iCell,
15746       cell,
15747       site,
15748       iHalfedge,
15749       halfedges,
15750       nHalfedges,
15751       start,
15752       startX,
15753       startY,
15754       end,
15755       endX,
15756       endY,
15757       cover = true;
15758
15759   for (iCell = 0; iCell < nCells; ++iCell) {
15760     if (cell = cells[iCell]) {
15761       site = cell.site;
15762       halfedges = cell.halfedges;
15763       iHalfedge = halfedges.length;
15764
15765       // Remove any dangling clipped edges.
15766       while (iHalfedge--) {
15767         if (!edges[halfedges[iHalfedge]]) {
15768           halfedges.splice(iHalfedge, 1);
15769         }
15770       }
15771
15772       // Insert any border edges as necessary.
15773       iHalfedge = 0, nHalfedges = halfedges.length;
15774       while (iHalfedge < nHalfedges) {
15775         end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
15776         start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
15777         if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
15778           halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
15779               Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
15780               : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
15781               : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
15782               : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
15783               : null)) - 1);
15784           ++nHalfedges;
15785         }
15786       }
15787
15788       if (nHalfedges) cover = false;
15789     }
15790   }
15791
15792   // If there weren’t any edges, have the closest site cover the extent.
15793   // It doesn’t matter which corner of the extent we measure!
15794   if (cover) {
15795     var dx, dy, d2, dc = Infinity;
15796
15797     for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
15798       if (cell = cells[iCell]) {
15799         site = cell.site;
15800         dx = site[0] - x0;
15801         dy = site[1] - y0;
15802         d2 = dx * dx + dy * dy;
15803         if (d2 < dc) dc = d2, cover = cell;
15804       }
15805     }
15806
15807     if (cover) {
15808       var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
15809       cover.halfedges.push(
15810         edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
15811         edges.push(createBorderEdge(site, v01, v11)) - 1,
15812         edges.push(createBorderEdge(site, v11, v10)) - 1,
15813         edges.push(createBorderEdge(site, v10, v00)) - 1
15814       );
15815     }
15816   }
15817
15818   // Lastly delete any cells with no edges; these were entirely clipped.
15819   for (iCell = 0; iCell < nCells; ++iCell) {
15820     if (cell = cells[iCell]) {
15821       if (!cell.halfedges.length) {
15822         delete cells[iCell];
15823       }
15824     }
15825   }
15826 }
15827
15828 var circlePool = [];
15829
15830 var firstCircle;
15831
15832 function Circle() {
15833   RedBlackNode(this);
15834   this.x =
15835   this.y =
15836   this.arc =
15837   this.site =
15838   this.cy = null;
15839 }
15840
15841 function attachCircle(arc) {
15842   var lArc = arc.P,
15843       rArc = arc.N;
15844
15845   if (!lArc || !rArc) return;
15846
15847   var lSite = lArc.site,
15848       cSite = arc.site,
15849       rSite = rArc.site;
15850
15851   if (lSite === rSite) return;
15852
15853   var bx = cSite[0],
15854       by = cSite[1],
15855       ax = lSite[0] - bx,
15856       ay = lSite[1] - by,
15857       cx = rSite[0] - bx,
15858       cy = rSite[1] - by;
15859
15860   var d = 2 * (ax * cy - ay * cx);
15861   if (d >= -epsilon2$2) return;
15862
15863   var ha = ax * ax + ay * ay,
15864       hc = cx * cx + cy * cy,
15865       x = (cy * ha - ay * hc) / d,
15866       y = (ax * hc - cx * ha) / d;
15867
15868   var circle = circlePool.pop() || new Circle;
15869   circle.arc = arc;
15870   circle.site = cSite;
15871   circle.x = x + bx;
15872   circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
15873
15874   arc.circle = circle;
15875
15876   var before = null,
15877       node = circles._;
15878
15879   while (node) {
15880     if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
15881       if (node.L) node = node.L;
15882       else { before = node.P; break; }
15883     } else {
15884       if (node.R) node = node.R;
15885       else { before = node; break; }
15886     }
15887   }
15888
15889   circles.insert(before, circle);
15890   if (!before) firstCircle = circle;
15891 }
15892
15893 function detachCircle(arc) {
15894   var circle = arc.circle;
15895   if (circle) {
15896     if (!circle.P) firstCircle = circle.N;
15897     circles.remove(circle);
15898     circlePool.push(circle);
15899     RedBlackNode(circle);
15900     arc.circle = null;
15901   }
15902 }
15903
15904 var beachPool = [];
15905
15906 function Beach() {
15907   RedBlackNode(this);
15908   this.edge =
15909   this.site =
15910   this.circle = null;
15911 }
15912
15913 function createBeach(site) {
15914   var beach = beachPool.pop() || new Beach;
15915   beach.site = site;
15916   return beach;
15917 }
15918
15919 function detachBeach(beach) {
15920   detachCircle(beach);
15921   beaches.remove(beach);
15922   beachPool.push(beach);
15923   RedBlackNode(beach);
15924 }
15925
15926 function removeBeach(beach) {
15927   var circle = beach.circle,
15928       x = circle.x,
15929       y = circle.cy,
15930       vertex = [x, y],
15931       previous = beach.P,
15932       next = beach.N,
15933       disappearing = [beach];
15934
15935   detachBeach(beach);
15936
15937   var lArc = previous;
15938   while (lArc.circle
15939       && Math.abs(x - lArc.circle.x) < epsilon$4
15940       && Math.abs(y - lArc.circle.cy) < epsilon$4) {
15941     previous = lArc.P;
15942     disappearing.unshift(lArc);
15943     detachBeach(lArc);
15944     lArc = previous;
15945   }
15946
15947   disappearing.unshift(lArc);
15948   detachCircle(lArc);
15949
15950   var rArc = next;
15951   while (rArc.circle
15952       && Math.abs(x - rArc.circle.x) < epsilon$4
15953       && Math.abs(y - rArc.circle.cy) < epsilon$4) {
15954     next = rArc.N;
15955     disappearing.push(rArc);
15956     detachBeach(rArc);
15957     rArc = next;
15958   }
15959
15960   disappearing.push(rArc);
15961   detachCircle(rArc);
15962
15963   var nArcs = disappearing.length,
15964       iArc;
15965   for (iArc = 1; iArc < nArcs; ++iArc) {
15966     rArc = disappearing[iArc];
15967     lArc = disappearing[iArc - 1];
15968     setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
15969   }
15970
15971   lArc = disappearing[0];
15972   rArc = disappearing[nArcs - 1];
15973   rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
15974
15975   attachCircle(lArc);
15976   attachCircle(rArc);
15977 }
15978
15979 function addBeach(site) {
15980   var x = site[0],
15981       directrix = site[1],
15982       lArc,
15983       rArc,
15984       dxl,
15985       dxr,
15986       node = beaches._;
15987
15988   while (node) {
15989     dxl = leftBreakPoint(node, directrix) - x;
15990     if (dxl > epsilon$4) node = node.L; else {
15991       dxr = x - rightBreakPoint(node, directrix);
15992       if (dxr > epsilon$4) {
15993         if (!node.R) {
15994           lArc = node;
15995           break;
15996         }
15997         node = node.R;
15998       } else {
15999         if (dxl > -epsilon$4) {
16000           lArc = node.P;
16001           rArc = node;
16002         } else if (dxr > -epsilon$4) {
16003           lArc = node;
16004           rArc = node.N;
16005         } else {
16006           lArc = rArc = node;
16007         }
16008         break;
16009       }
16010     }
16011   }
16012
16013   createCell(site);
16014   var newArc = createBeach(site);
16015   beaches.insert(lArc, newArc);
16016
16017   if (!lArc && !rArc) return;
16018
16019   if (lArc === rArc) {
16020     detachCircle(lArc);
16021     rArc = createBeach(lArc.site);
16022     beaches.insert(newArc, rArc);
16023     newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
16024     attachCircle(lArc);
16025     attachCircle(rArc);
16026     return;
16027   }
16028
16029   if (!rArc) { // && lArc
16030     newArc.edge = createEdge(lArc.site, newArc.site);
16031     return;
16032   }
16033
16034   // else lArc !== rArc
16035   detachCircle(lArc);
16036   detachCircle(rArc);
16037
16038   var lSite = lArc.site,
16039       ax = lSite[0],
16040       ay = lSite[1],
16041       bx = site[0] - ax,
16042       by = site[1] - ay,
16043       rSite = rArc.site,
16044       cx = rSite[0] - ax,
16045       cy = rSite[1] - ay,
16046       d = 2 * (bx * cy - by * cx),
16047       hb = bx * bx + by * by,
16048       hc = cx * cx + cy * cy,
16049       vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
16050
16051   setEdgeEnd(rArc.edge, lSite, rSite, vertex);
16052   newArc.edge = createEdge(lSite, site, null, vertex);
16053   rArc.edge = createEdge(site, rSite, null, vertex);
16054   attachCircle(lArc);
16055   attachCircle(rArc);
16056 }
16057
16058 function leftBreakPoint(arc, directrix) {
16059   var site = arc.site,
16060       rfocx = site[0],
16061       rfocy = site[1],
16062       pby2 = rfocy - directrix;
16063
16064   if (!pby2) return rfocx;
16065
16066   var lArc = arc.P;
16067   if (!lArc) return -Infinity;
16068
16069   site = lArc.site;
16070   var lfocx = site[0],
16071       lfocy = site[1],
16072       plby2 = lfocy - directrix;
16073
16074   if (!plby2) return lfocx;
16075
16076   var hl = lfocx - rfocx,
16077       aby2 = 1 / pby2 - 1 / plby2,
16078       b = hl / plby2;
16079
16080   if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
16081
16082   return (rfocx + lfocx) / 2;
16083 }
16084
16085 function rightBreakPoint(arc, directrix) {
16086   var rArc = arc.N;
16087   if (rArc) return leftBreakPoint(rArc, directrix);
16088   var site = arc.site;
16089   return site[1] === directrix ? site[0] : Infinity;
16090 }
16091
16092 var epsilon$4 = 1e-6;
16093 var epsilon2$2 = 1e-12;
16094 var beaches;
16095 var cells;
16096 var circles;
16097 var edges;
16098
16099 function triangleArea(a, b, c) {
16100   return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
16101 }
16102
16103 function lexicographic(a, b) {
16104   return b[1] - a[1]
16105       || b[0] - a[0];
16106 }
16107
16108 function Diagram(sites, extent) {
16109   var site = sites.sort(lexicographic).pop(),
16110       x,
16111       y,
16112       circle;
16113
16114   edges = [];
16115   cells = new Array(sites.length);
16116   beaches = new RedBlackTree;
16117   circles = new RedBlackTree;
16118
16119   while (true) {
16120     circle = firstCircle;
16121     if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
16122       if (site[0] !== x || site[1] !== y) {
16123         addBeach(site);
16124         x = site[0], y = site[1];
16125       }
16126       site = sites.pop();
16127     } else if (circle) {
16128       removeBeach(circle.arc);
16129     } else {
16130       break;
16131     }
16132   }
16133
16134   sortCellHalfedges();
16135
16136   if (extent) {
16137     var x0 = +extent[0][0],
16138         y0 = +extent[0][1],
16139         x1 = +extent[1][0],
16140         y1 = +extent[1][1];
16141     clipEdges(x0, y0, x1, y1);
16142     clipCells(x0, y0, x1, y1);
16143   }
16144
16145   this.edges = edges;
16146   this.cells = cells;
16147
16148   beaches =
16149   circles =
16150   edges =
16151   cells = null;
16152 }
16153
16154 Diagram.prototype = {
16155   constructor: Diagram,
16156
16157   polygons: function() {
16158     var edges = this.edges;
16159
16160     return this.cells.map(function(cell) {
16161       var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
16162       polygon.data = cell.site.data;
16163       return polygon;
16164     });
16165   },
16166
16167   triangles: function() {
16168     var triangles = [],
16169         edges = this.edges;
16170
16171     this.cells.forEach(function(cell, i) {
16172       if (!(m = (halfedges = cell.halfedges).length)) return;
16173       var site = cell.site,
16174           halfedges,
16175           j = -1,
16176           m,
16177           s0,
16178           e1 = edges[halfedges[m - 1]],
16179           s1 = e1.left === site ? e1.right : e1.left;
16180
16181       while (++j < m) {
16182         s0 = s1;
16183         e1 = edges[halfedges[j]];
16184         s1 = e1.left === site ? e1.right : e1.left;
16185         if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
16186           triangles.push([site.data, s0.data, s1.data]);
16187         }
16188       }
16189     });
16190
16191     return triangles;
16192   },
16193
16194   links: function() {
16195     return this.edges.filter(function(edge) {
16196       return edge.right;
16197     }).map(function(edge) {
16198       return {
16199         source: edge.left.data,
16200         target: edge.right.data
16201       };
16202     });
16203   },
16204
16205   find: function(x, y, radius) {
16206     var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
16207
16208     // Use the previously-found cell, or start with an arbitrary one.
16209     while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
16210     var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
16211
16212     // Traverse the half-edges to find a closer cell, if any.
16213     do {
16214       cell = that.cells[i0 = i1], i1 = null;
16215       cell.halfedges.forEach(function(e) {
16216         var edge = that.edges[e], v = edge.left;
16217         if ((v === cell.site || !v) && !(v = edge.right)) return;
16218         var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
16219         if (v2 < d2) d2 = v2, i1 = v.index;
16220       });
16221     } while (i1 !== null);
16222
16223     that._found = i0;
16224
16225     return radius == null || d2 <= radius * radius ? cell.site : null;
16226   }
16227 };
16228
16229 var voronoi = function() {
16230   var x$$1 = x$4,
16231       y$$1 = y$4,
16232       extent = null;
16233
16234   function voronoi(data) {
16235     return new Diagram(data.map(function(d, i) {
16236       var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
16237       s.index = i;
16238       s.data = d;
16239       return s;
16240     }), extent);
16241   }
16242
16243   voronoi.polygons = function(data) {
16244     return voronoi(data).polygons();
16245   };
16246
16247   voronoi.links = function(data) {
16248     return voronoi(data).links();
16249   };
16250
16251   voronoi.triangles = function(data) {
16252     return voronoi(data).triangles();
16253   };
16254
16255   voronoi.x = function(_) {
16256     return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : x$$1;
16257   };
16258
16259   voronoi.y = function(_) {
16260     return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$11(+_), voronoi) : y$$1;
16261   };
16262
16263   voronoi.extent = function(_) {
16264     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]]];
16265   };
16266
16267   voronoi.size = function(_) {
16268     return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
16269   };
16270
16271   return voronoi;
16272 };
16273
16274 var constant$12 = function(x) {
16275   return function() {
16276     return x;
16277   };
16278 };
16279
16280 function ZoomEvent(target, type, transform) {
16281   this.target = target;
16282   this.type = type;
16283   this.transform = transform;
16284 }
16285
16286 function Transform(k, x, y) {
16287   this.k = k;
16288   this.x = x;
16289   this.y = y;
16290 }
16291
16292 Transform.prototype = {
16293   constructor: Transform,
16294   scale: function(k) {
16295     return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
16296   },
16297   translate: function(x, y) {
16298     return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
16299   },
16300   apply: function(point) {
16301     return [point[0] * this.k + this.x, point[1] * this.k + this.y];
16302   },
16303   applyX: function(x) {
16304     return x * this.k + this.x;
16305   },
16306   applyY: function(y) {
16307     return y * this.k + this.y;
16308   },
16309   invert: function(location) {
16310     return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
16311   },
16312   invertX: function(x) {
16313     return (x - this.x) / this.k;
16314   },
16315   invertY: function(y) {
16316     return (y - this.y) / this.k;
16317   },
16318   rescaleX: function(x) {
16319     return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
16320   },
16321   rescaleY: function(y) {
16322     return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
16323   },
16324   toString: function() {
16325     return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
16326   }
16327 };
16328
16329 var identity$8 = new Transform(1, 0, 0);
16330
16331 transform$1.prototype = Transform.prototype;
16332
16333 function transform$1(node) {
16334   return node.__zoom || identity$8;
16335 }
16336
16337 function nopropagation$2() {
16338   exports.event.stopImmediatePropagation();
16339 }
16340
16341 var noevent$2 = function() {
16342   exports.event.preventDefault();
16343   exports.event.stopImmediatePropagation();
16344 };
16345
16346 // Ignore right-click, since that should open the context menu.
16347 function defaultFilter$2() {
16348   return !exports.event.button;
16349 }
16350
16351 function defaultExtent$1() {
16352   var e = this, w, h;
16353   if (e instanceof SVGElement) {
16354     e = e.ownerSVGElement || e;
16355     w = e.width.baseVal.value;
16356     h = e.height.baseVal.value;
16357   } else {
16358     w = e.clientWidth;
16359     h = e.clientHeight;
16360   }
16361   return [[0, 0], [w, h]];
16362 }
16363
16364 function defaultTransform() {
16365   return this.__zoom || identity$8;
16366 }
16367
16368 function defaultWheelDelta() {
16369   return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
16370 }
16371
16372 function defaultTouchable$1() {
16373   return "ontouchstart" in this;
16374 }
16375
16376 function defaultConstrain(transform$$1, extent, translateExtent) {
16377   var dx0 = transform$$1.invertX(extent[0][0]) - translateExtent[0][0],
16378       dx1 = transform$$1.invertX(extent[1][0]) - translateExtent[1][0],
16379       dy0 = transform$$1.invertY(extent[0][1]) - translateExtent[0][1],
16380       dy1 = transform$$1.invertY(extent[1][1]) - translateExtent[1][1];
16381   return transform$$1.translate(
16382     dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
16383     dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
16384   );
16385 }
16386
16387 var zoom = function() {
16388   var filter = defaultFilter$2,
16389       extent = defaultExtent$1,
16390       constrain = defaultConstrain,
16391       wheelDelta = defaultWheelDelta,
16392       touchable = defaultTouchable$1,
16393       scaleExtent = [0, Infinity],
16394       translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
16395       duration = 250,
16396       interpolate = interpolateZoom,
16397       gestures = [],
16398       listeners = dispatch("start", "zoom", "end"),
16399       touchstarting,
16400       touchending,
16401       touchDelay = 500,
16402       wheelDelay = 150,
16403       clickDistance2 = 0;
16404
16405   function zoom(selection) {
16406     selection
16407         .property("__zoom", defaultTransform)
16408         .on("wheel.zoom", wheeled)
16409         .on("mousedown.zoom", mousedowned)
16410         .on("dblclick.zoom", dblclicked)
16411       .filter(touchable)
16412         .on("touchstart.zoom", touchstarted)
16413         .on("touchmove.zoom", touchmoved)
16414         .on("touchend.zoom touchcancel.zoom", touchended)
16415         .style("touch-action", "none")
16416         .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
16417   }
16418
16419   zoom.transform = function(collection, transform$$1) {
16420     var selection = collection.selection ? collection.selection() : collection;
16421     selection.property("__zoom", defaultTransform);
16422     if (collection !== selection) {
16423       schedule(collection, transform$$1);
16424     } else {
16425       selection.interrupt().each(function() {
16426         gesture(this, arguments)
16427             .start()
16428             .zoom(null, typeof transform$$1 === "function" ? transform$$1.apply(this, arguments) : transform$$1)
16429             .end();
16430       });
16431     }
16432   };
16433
16434   zoom.scaleBy = function(selection, k) {
16435     zoom.scaleTo(selection, function() {
16436       var k0 = this.__zoom.k,
16437           k1 = typeof k === "function" ? k.apply(this, arguments) : k;
16438       return k0 * k1;
16439     });
16440   };
16441
16442   zoom.scaleTo = function(selection, k) {
16443     zoom.transform(selection, function() {
16444       var e = extent.apply(this, arguments),
16445           t0 = this.__zoom,
16446           p0 = centroid(e),
16447           p1 = t0.invert(p0),
16448           k1 = typeof k === "function" ? k.apply(this, arguments) : k;
16449       return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
16450     });
16451   };
16452
16453   zoom.translateBy = function(selection, x, y) {
16454     zoom.transform(selection, function() {
16455       return constrain(this.__zoom.translate(
16456         typeof x === "function" ? x.apply(this, arguments) : x,
16457         typeof y === "function" ? y.apply(this, arguments) : y
16458       ), extent.apply(this, arguments), translateExtent);
16459     });
16460   };
16461
16462   zoom.translateTo = function(selection, x, y) {
16463     zoom.transform(selection, function() {
16464       var e = extent.apply(this, arguments),
16465           t = this.__zoom,
16466           p = centroid(e);
16467       return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
16468         typeof x === "function" ? -x.apply(this, arguments) : -x,
16469         typeof y === "function" ? -y.apply(this, arguments) : -y
16470       ), e, translateExtent);
16471     });
16472   };
16473
16474   function scale(transform$$1, k) {
16475     k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
16476     return k === transform$$1.k ? transform$$1 : new Transform(k, transform$$1.x, transform$$1.y);
16477   }
16478
16479   function translate(transform$$1, p0, p1) {
16480     var x = p0[0] - p1[0] * transform$$1.k, y = p0[1] - p1[1] * transform$$1.k;
16481     return x === transform$$1.x && y === transform$$1.y ? transform$$1 : new Transform(transform$$1.k, x, y);
16482   }
16483
16484   function centroid(extent) {
16485     return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
16486   }
16487
16488   function schedule(transition, transform$$1, center) {
16489     transition
16490         .on("start.zoom", function() { gesture(this, arguments).start(); })
16491         .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
16492         .tween("zoom", function() {
16493           var that = this,
16494               args = arguments,
16495               g = gesture(that, args),
16496               e = extent.apply(that, args),
16497               p = center || centroid(e),
16498               w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
16499               a = that.__zoom,
16500               b = typeof transform$$1 === "function" ? transform$$1.apply(that, args) : transform$$1,
16501               i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
16502           return function(t) {
16503             if (t === 1) t = b; // Avoid rounding error on end.
16504             else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
16505             g.zoom(null, t);
16506           };
16507         });
16508   }
16509
16510   function gesture(that, args) {
16511     for (var i = 0, n = gestures.length, g; i < n; ++i) {
16512       if ((g = gestures[i]).that === that) {
16513         return g;
16514       }
16515     }
16516     return new Gesture(that, args);
16517   }
16518
16519   function Gesture(that, args) {
16520     this.that = that;
16521     this.args = args;
16522     this.index = -1;
16523     this.active = 0;
16524     this.extent = extent.apply(that, args);
16525   }
16526
16527   Gesture.prototype = {
16528     start: function() {
16529       if (++this.active === 1) {
16530         this.index = gestures.push(this) - 1;
16531         this.emit("start");
16532       }
16533       return this;
16534     },
16535     zoom: function(key, transform$$1) {
16536       if (this.mouse && key !== "mouse") this.mouse[1] = transform$$1.invert(this.mouse[0]);
16537       if (this.touch0 && key !== "touch") this.touch0[1] = transform$$1.invert(this.touch0[0]);
16538       if (this.touch1 && key !== "touch") this.touch1[1] = transform$$1.invert(this.touch1[0]);
16539       this.that.__zoom = transform$$1;
16540       this.emit("zoom");
16541       return this;
16542     },
16543     end: function() {
16544       if (--this.active === 0) {
16545         gestures.splice(this.index, 1);
16546         this.index = -1;
16547         this.emit("end");
16548       }
16549       return this;
16550     },
16551     emit: function(type) {
16552       customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
16553     }
16554   };
16555
16556   function wheeled() {
16557     if (!filter.apply(this, arguments)) return;
16558     var g = gesture(this, arguments),
16559         t = this.__zoom,
16560         k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
16561         p = mouse(this);
16562
16563     // If the mouse is in the same location as before, reuse it.
16564     // If there were recent wheel events, reset the wheel idle timeout.
16565     if (g.wheel) {
16566       if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
16567         g.mouse[1] = t.invert(g.mouse[0] = p);
16568       }
16569       clearTimeout(g.wheel);
16570     }
16571
16572     // If this wheel event won’t trigger a transform change, ignore it.
16573     else if (t.k === k) return;
16574
16575     // Otherwise, capture the mouse point and location at the start.
16576     else {
16577       g.mouse = [p, t.invert(p)];
16578       interrupt(this);
16579       g.start();
16580     }
16581
16582     noevent$2();
16583     g.wheel = setTimeout(wheelidled, wheelDelay);
16584     g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
16585
16586     function wheelidled() {
16587       g.wheel = null;
16588       g.end();
16589     }
16590   }
16591
16592   function mousedowned() {
16593     if (touchending || !filter.apply(this, arguments)) return;
16594     var g = gesture(this, arguments),
16595         v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
16596         p = mouse(this),
16597         x0 = exports.event.clientX,
16598         y0 = exports.event.clientY;
16599
16600     dragDisable(exports.event.view);
16601     nopropagation$2();
16602     g.mouse = [p, this.__zoom.invert(p)];
16603     interrupt(this);
16604     g.start();
16605
16606     function mousemoved() {
16607       noevent$2();
16608       if (!g.moved) {
16609         var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
16610         g.moved = dx * dx + dy * dy > clickDistance2;
16611       }
16612       g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
16613     }
16614
16615     function mouseupped() {
16616       v.on("mousemove.zoom mouseup.zoom", null);
16617       yesdrag(exports.event.view, g.moved);
16618       noevent$2();
16619       g.end();
16620     }
16621   }
16622
16623   function dblclicked() {
16624     if (!filter.apply(this, arguments)) return;
16625     var t0 = this.__zoom,
16626         p0 = mouse(this),
16627         p1 = t0.invert(p0),
16628         k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
16629         t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
16630
16631     noevent$2();
16632     if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
16633     else select(this).call(zoom.transform, t1);
16634   }
16635
16636   function touchstarted() {
16637     if (!filter.apply(this, arguments)) return;
16638     var g = gesture(this, arguments),
16639         touches = exports.event.changedTouches,
16640         started,
16641         n = touches.length, i, t, p;
16642
16643     nopropagation$2();
16644     for (i = 0; i < n; ++i) {
16645       t = touches[i], p = touch(this, touches, t.identifier);
16646       p = [p, this.__zoom.invert(p), t.identifier];
16647       if (!g.touch0) g.touch0 = p, started = true;
16648       else if (!g.touch1) g.touch1 = p;
16649     }
16650
16651     // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
16652     if (touchstarting) {
16653       touchstarting = clearTimeout(touchstarting);
16654       if (!g.touch1) {
16655         g.end();
16656         p = select(this).on("dblclick.zoom");
16657         if (p) p.apply(this, arguments);
16658         return;
16659       }
16660     }
16661
16662     if (started) {
16663       touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
16664       interrupt(this);
16665       g.start();
16666     }
16667   }
16668
16669   function touchmoved() {
16670     var g = gesture(this, arguments),
16671         touches = exports.event.changedTouches,
16672         n = touches.length, i, t, p, l;
16673
16674     noevent$2();
16675     if (touchstarting) touchstarting = clearTimeout(touchstarting);
16676     for (i = 0; i < n; ++i) {
16677       t = touches[i], p = touch(this, touches, t.identifier);
16678       if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
16679       else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
16680     }
16681     t = g.that.__zoom;
16682     if (g.touch1) {
16683       var p0 = g.touch0[0], l0 = g.touch0[1],
16684           p1 = g.touch1[0], l1 = g.touch1[1],
16685           dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
16686           dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
16687       t = scale(t, Math.sqrt(dp / dl));
16688       p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
16689       l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
16690     }
16691     else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
16692     else return;
16693     g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
16694   }
16695
16696   function touchended() {
16697     var g = gesture(this, arguments),
16698         touches = exports.event.changedTouches,
16699         n = touches.length, i, t;
16700
16701     nopropagation$2();
16702     if (touchending) clearTimeout(touchending);
16703     touchending = setTimeout(function() { touchending = null; }, touchDelay);
16704     for (i = 0; i < n; ++i) {
16705       t = touches[i];
16706       if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
16707       else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
16708     }
16709     if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
16710     if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
16711     else g.end();
16712   }
16713
16714   zoom.wheelDelta = function(_) {
16715     return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$12(+_), zoom) : wheelDelta;
16716   };
16717
16718   zoom.filter = function(_) {
16719     return arguments.length ? (filter = typeof _ === "function" ? _ : constant$12(!!_), zoom) : filter;
16720   };
16721
16722   zoom.touchable = function(_) {
16723     return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$12(!!_), zoom) : touchable;
16724   };
16725
16726   zoom.extent = function(_) {
16727     return arguments.length ? (extent = typeof _ === "function" ? _ : constant$12([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
16728   };
16729
16730   zoom.scaleExtent = function(_) {
16731     return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
16732   };
16733
16734   zoom.translateExtent = function(_) {
16735     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]]];
16736   };
16737
16738   zoom.constrain = function(_) {
16739     return arguments.length ? (constrain = _, zoom) : constrain;
16740   };
16741
16742   zoom.duration = function(_) {
16743     return arguments.length ? (duration = +_, zoom) : duration;
16744   };
16745
16746   zoom.interpolate = function(_) {
16747     return arguments.length ? (interpolate = _, zoom) : interpolate;
16748   };
16749
16750   zoom.on = function() {
16751     var value = listeners.on.apply(listeners, arguments);
16752     return value === listeners ? zoom : value;
16753   };
16754
16755   zoom.clickDistance = function(_) {
16756     return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
16757   };
16758
16759   return zoom;
16760 };
16761
16762 exports.version = version;
16763 exports.bisect = bisectRight;
16764 exports.bisectRight = bisectRight;
16765 exports.bisectLeft = bisectLeft;
16766 exports.ascending = ascending;
16767 exports.bisector = bisector;
16768 exports.cross = cross;
16769 exports.descending = descending;
16770 exports.deviation = deviation;
16771 exports.extent = extent;
16772 exports.histogram = histogram;
16773 exports.thresholdFreedmanDiaconis = freedmanDiaconis;
16774 exports.thresholdScott = scott;
16775 exports.thresholdSturges = sturges;
16776 exports.max = max;
16777 exports.mean = mean;
16778 exports.median = median;
16779 exports.merge = merge;
16780 exports.min = min;
16781 exports.pairs = pairs;
16782 exports.permute = permute;
16783 exports.quantile = threshold;
16784 exports.range = sequence;
16785 exports.scan = scan;
16786 exports.shuffle = shuffle;
16787 exports.sum = sum;
16788 exports.ticks = ticks;
16789 exports.tickIncrement = tickIncrement;
16790 exports.tickStep = tickStep;
16791 exports.transpose = transpose;
16792 exports.variance = variance;
16793 exports.zip = zip;
16794 exports.axisTop = axisTop;
16795 exports.axisRight = axisRight;
16796 exports.axisBottom = axisBottom;
16797 exports.axisLeft = axisLeft;
16798 exports.brush = brush;
16799 exports.brushX = brushX;
16800 exports.brushY = brushY;
16801 exports.brushSelection = brushSelection;
16802 exports.chord = chord;
16803 exports.ribbon = ribbon;
16804 exports.nest = nest;
16805 exports.set = set$2;
16806 exports.map = map$1;
16807 exports.keys = keys;
16808 exports.values = values;
16809 exports.entries = entries;
16810 exports.color = color;
16811 exports.rgb = rgb;
16812 exports.hsl = hsl;
16813 exports.lab = lab;
16814 exports.hcl = hcl;
16815 exports.cubehelix = cubehelix;
16816 exports.dispatch = dispatch;
16817 exports.drag = drag;
16818 exports.dragDisable = dragDisable;
16819 exports.dragEnable = yesdrag;
16820 exports.dsvFormat = dsv;
16821 exports.csvParse = csvParse;
16822 exports.csvParseRows = csvParseRows;
16823 exports.csvFormat = csvFormat;
16824 exports.csvFormatRows = csvFormatRows;
16825 exports.tsvParse = tsvParse;
16826 exports.tsvParseRows = tsvParseRows;
16827 exports.tsvFormat = tsvFormat;
16828 exports.tsvFormatRows = tsvFormatRows;
16829 exports.easeLinear = linear$1;
16830 exports.easeQuad = quadInOut;
16831 exports.easeQuadIn = quadIn;
16832 exports.easeQuadOut = quadOut;
16833 exports.easeQuadInOut = quadInOut;
16834 exports.easeCubic = cubicInOut;
16835 exports.easeCubicIn = cubicIn;
16836 exports.easeCubicOut = cubicOut;
16837 exports.easeCubicInOut = cubicInOut;
16838 exports.easePoly = polyInOut;
16839 exports.easePolyIn = polyIn;
16840 exports.easePolyOut = polyOut;
16841 exports.easePolyInOut = polyInOut;
16842 exports.easeSin = sinInOut;
16843 exports.easeSinIn = sinIn;
16844 exports.easeSinOut = sinOut;
16845 exports.easeSinInOut = sinInOut;
16846 exports.easeExp = expInOut;
16847 exports.easeExpIn = expIn;
16848 exports.easeExpOut = expOut;
16849 exports.easeExpInOut = expInOut;
16850 exports.easeCircle = circleInOut;
16851 exports.easeCircleIn = circleIn;
16852 exports.easeCircleOut = circleOut;
16853 exports.easeCircleInOut = circleInOut;
16854 exports.easeBounce = bounceOut;
16855 exports.easeBounceIn = bounceIn;
16856 exports.easeBounceOut = bounceOut;
16857 exports.easeBounceInOut = bounceInOut;
16858 exports.easeBack = backInOut;
16859 exports.easeBackIn = backIn;
16860 exports.easeBackOut = backOut;
16861 exports.easeBackInOut = backInOut;
16862 exports.easeElastic = elasticOut;
16863 exports.easeElasticIn = elasticIn;
16864 exports.easeElasticOut = elasticOut;
16865 exports.easeElasticInOut = elasticInOut;
16866 exports.forceCenter = center$1;
16867 exports.forceCollide = collide;
16868 exports.forceLink = link;
16869 exports.forceManyBody = manyBody;
16870 exports.forceRadial = radial;
16871 exports.forceSimulation = simulation;
16872 exports.forceX = x$2;
16873 exports.forceY = y$2;
16874 exports.formatDefaultLocale = defaultLocale;
16875 exports.formatLocale = formatLocale;
16876 exports.formatSpecifier = formatSpecifier;
16877 exports.precisionFixed = precisionFixed;
16878 exports.precisionPrefix = precisionPrefix;
16879 exports.precisionRound = precisionRound;
16880 exports.geoArea = area;
16881 exports.geoBounds = bounds;
16882 exports.geoCentroid = centroid;
16883 exports.geoCircle = circle;
16884 exports.geoClipAntimeridian = clipAntimeridian;
16885 exports.geoClipCircle = clipCircle;
16886 exports.geoClipExtent = extent$1;
16887 exports.geoClipRectangle = clipRectangle;
16888 exports.geoContains = contains;
16889 exports.geoDistance = distance;
16890 exports.geoGraticule = graticule;
16891 exports.geoGraticule10 = graticule10;
16892 exports.geoInterpolate = interpolate$1;
16893 exports.geoLength = length$1;
16894 exports.geoPath = index$1;
16895 exports.geoAlbers = albers;
16896 exports.geoAlbersUsa = albersUsa;
16897 exports.geoAzimuthalEqualArea = azimuthalEqualArea;
16898 exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
16899 exports.geoAzimuthalEquidistant = azimuthalEquidistant;
16900 exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
16901 exports.geoConicConformal = conicConformal;
16902 exports.geoConicConformalRaw = conicConformalRaw;
16903 exports.geoConicEqualArea = conicEqualArea;
16904 exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
16905 exports.geoConicEquidistant = conicEquidistant;
16906 exports.geoConicEquidistantRaw = conicEquidistantRaw;
16907 exports.geoEquirectangular = equirectangular;
16908 exports.geoEquirectangularRaw = equirectangularRaw;
16909 exports.geoGnomonic = gnomonic;
16910 exports.geoGnomonicRaw = gnomonicRaw;
16911 exports.geoIdentity = identity$5;
16912 exports.geoProjection = projection;
16913 exports.geoProjectionMutator = projectionMutator;
16914 exports.geoMercator = mercator;
16915 exports.geoMercatorRaw = mercatorRaw;
16916 exports.geoNaturalEarth1 = naturalEarth1;
16917 exports.geoNaturalEarth1Raw = naturalEarth1Raw;
16918 exports.geoOrthographic = orthographic;
16919 exports.geoOrthographicRaw = orthographicRaw;
16920 exports.geoStereographic = stereographic;
16921 exports.geoStereographicRaw = stereographicRaw;
16922 exports.geoTransverseMercator = transverseMercator;
16923 exports.geoTransverseMercatorRaw = transverseMercatorRaw;
16924 exports.geoRotation = rotation;
16925 exports.geoStream = geoStream;
16926 exports.geoTransform = transform;
16927 exports.cluster = cluster;
16928 exports.hierarchy = hierarchy;
16929 exports.pack = index$2;
16930 exports.packSiblings = siblings;
16931 exports.packEnclose = enclose;
16932 exports.partition = partition;
16933 exports.stratify = stratify;
16934 exports.tree = tree;
16935 exports.treemap = index$3;
16936 exports.treemapBinary = binary;
16937 exports.treemapDice = treemapDice;
16938 exports.treemapSlice = treemapSlice;
16939 exports.treemapSliceDice = sliceDice;
16940 exports.treemapSquarify = squarify;
16941 exports.treemapResquarify = resquarify;
16942 exports.interpolate = interpolateValue;
16943 exports.interpolateArray = array$1;
16944 exports.interpolateBasis = basis$1;
16945 exports.interpolateBasisClosed = basisClosed;
16946 exports.interpolateDate = date;
16947 exports.interpolateNumber = reinterpolate;
16948 exports.interpolateObject = object;
16949 exports.interpolateRound = interpolateRound;
16950 exports.interpolateString = interpolateString;
16951 exports.interpolateTransformCss = interpolateTransformCss;
16952 exports.interpolateTransformSvg = interpolateTransformSvg;
16953 exports.interpolateZoom = interpolateZoom;
16954 exports.interpolateRgb = interpolateRgb;
16955 exports.interpolateRgbBasis = rgbBasis;
16956 exports.interpolateRgbBasisClosed = rgbBasisClosed;
16957 exports.interpolateHsl = hsl$2;
16958 exports.interpolateHslLong = hslLong;
16959 exports.interpolateLab = lab$1;
16960 exports.interpolateHcl = hcl$2;
16961 exports.interpolateHclLong = hclLong;
16962 exports.interpolateCubehelix = cubehelix$2;
16963 exports.interpolateCubehelixLong = cubehelixLong;
16964 exports.quantize = quantize;
16965 exports.path = path;
16966 exports.polygonArea = area$1;
16967 exports.polygonCentroid = centroid$1;
16968 exports.polygonHull = hull;
16969 exports.polygonContains = contains$1;
16970 exports.polygonLength = length$2;
16971 exports.quadtree = quadtree;
16972 exports.queue = queue;
16973 exports.randomUniform = uniform;
16974 exports.randomNormal = normal;
16975 exports.randomLogNormal = logNormal;
16976 exports.randomBates = bates;
16977 exports.randomIrwinHall = irwinHall;
16978 exports.randomExponential = exponential$1;
16979 exports.request = request;
16980 exports.html = html;
16981 exports.json = json;
16982 exports.text = text;
16983 exports.xml = xml;
16984 exports.csv = csv$1;
16985 exports.tsv = tsv$1;
16986 exports.scaleBand = band;
16987 exports.scalePoint = point$1;
16988 exports.scaleIdentity = identity$6;
16989 exports.scaleLinear = linear$2;
16990 exports.scaleLog = log$1;
16991 exports.scaleOrdinal = ordinal;
16992 exports.scaleImplicit = implicit;
16993 exports.scalePow = pow$1;
16994 exports.scaleSqrt = sqrt$1;
16995 exports.scaleQuantile = quantile$$1;
16996 exports.scaleQuantize = quantize$1;
16997 exports.scaleThreshold = threshold$1;
16998 exports.scaleTime = time;
16999 exports.scaleUtc = utcTime;
17000 exports.schemeCategory10 = category10;
17001 exports.schemeCategory20b = category20b;
17002 exports.schemeCategory20c = category20c;
17003 exports.schemeCategory20 = category20;
17004 exports.interpolateCubehelixDefault = cubehelix$3;
17005 exports.interpolateRainbow = rainbow$1;
17006 exports.interpolateWarm = warm;
17007 exports.interpolateCool = cool;
17008 exports.interpolateViridis = viridis;
17009 exports.interpolateMagma = magma;
17010 exports.interpolateInferno = inferno;
17011 exports.interpolatePlasma = plasma;
17012 exports.scaleSequential = sequential;
17013 exports.creator = creator;
17014 exports.local = local$1;
17015 exports.matcher = matcher$1;
17016 exports.mouse = mouse;
17017 exports.namespace = namespace;
17018 exports.namespaces = namespaces;
17019 exports.clientPoint = point;
17020 exports.select = select;
17021 exports.selectAll = selectAll;
17022 exports.selection = selection;
17023 exports.selector = selector;
17024 exports.selectorAll = selectorAll;
17025 exports.style = styleValue;
17026 exports.touch = touch;
17027 exports.touches = touches;
17028 exports.window = defaultView;
17029 exports.customEvent = customEvent;
17030 exports.arc = arc;
17031 exports.area = area$2;
17032 exports.line = line;
17033 exports.pie = pie;
17034 exports.areaRadial = areaRadial;
17035 exports.radialArea = areaRadial;
17036 exports.lineRadial = lineRadial$1;
17037 exports.radialLine = lineRadial$1;
17038 exports.pointRadial = pointRadial;
17039 exports.linkHorizontal = linkHorizontal;
17040 exports.linkVertical = linkVertical;
17041 exports.linkRadial = linkRadial;
17042 exports.symbol = symbol;
17043 exports.symbols = symbols;
17044 exports.symbolCircle = circle$2;
17045 exports.symbolCross = cross$2;
17046 exports.symbolDiamond = diamond;
17047 exports.symbolSquare = square;
17048 exports.symbolStar = star;
17049 exports.symbolTriangle = triangle;
17050 exports.symbolWye = wye;
17051 exports.curveBasisClosed = basisClosed$1;
17052 exports.curveBasisOpen = basisOpen;
17053 exports.curveBasis = basis$2;
17054 exports.curveBundle = bundle;
17055 exports.curveCardinalClosed = cardinalClosed;
17056 exports.curveCardinalOpen = cardinalOpen;
17057 exports.curveCardinal = cardinal;
17058 exports.curveCatmullRomClosed = catmullRomClosed;
17059 exports.curveCatmullRomOpen = catmullRomOpen;
17060 exports.curveCatmullRom = catmullRom;
17061 exports.curveLinearClosed = linearClosed;
17062 exports.curveLinear = curveLinear;
17063 exports.curveMonotoneX = monotoneX;
17064 exports.curveMonotoneY = monotoneY;
17065 exports.curveNatural = natural;
17066 exports.curveStep = step;
17067 exports.curveStepAfter = stepAfter;
17068 exports.curveStepBefore = stepBefore;
17069 exports.stack = stack;
17070 exports.stackOffsetExpand = expand;
17071 exports.stackOffsetDiverging = diverging;
17072 exports.stackOffsetNone = none$1;
17073 exports.stackOffsetSilhouette = silhouette;
17074 exports.stackOffsetWiggle = wiggle;
17075 exports.stackOrderAscending = ascending$2;
17076 exports.stackOrderDescending = descending$2;
17077 exports.stackOrderInsideOut = insideOut;
17078 exports.stackOrderNone = none$2;
17079 exports.stackOrderReverse = reverse;
17080 exports.timeInterval = newInterval;
17081 exports.timeMillisecond = millisecond;
17082 exports.timeMilliseconds = milliseconds;
17083 exports.utcMillisecond = millisecond;
17084 exports.utcMilliseconds = milliseconds;
17085 exports.timeSecond = second;
17086 exports.timeSeconds = seconds;
17087 exports.utcSecond = second;
17088 exports.utcSeconds = seconds;
17089 exports.timeMinute = minute;
17090 exports.timeMinutes = minutes;
17091 exports.timeHour = hour;
17092 exports.timeHours = hours;
17093 exports.timeDay = day;
17094 exports.timeDays = days;
17095 exports.timeWeek = sunday;
17096 exports.timeWeeks = sundays;
17097 exports.timeSunday = sunday;
17098 exports.timeSundays = sundays;
17099 exports.timeMonday = monday;
17100 exports.timeMondays = mondays;
17101 exports.timeTuesday = tuesday;
17102 exports.timeTuesdays = tuesdays;
17103 exports.timeWednesday = wednesday;
17104 exports.timeWednesdays = wednesdays;
17105 exports.timeThursday = thursday;
17106 exports.timeThursdays = thursdays;
17107 exports.timeFriday = friday;
17108 exports.timeFridays = fridays;
17109 exports.timeSaturday = saturday;
17110 exports.timeSaturdays = saturdays;
17111 exports.timeMonth = month;
17112 exports.timeMonths = months;
17113 exports.timeYear = year;
17114 exports.timeYears = years;
17115 exports.utcMinute = utcMinute;
17116 exports.utcMinutes = utcMinutes;
17117 exports.utcHour = utcHour;
17118 exports.utcHours = utcHours;
17119 exports.utcDay = utcDay;
17120 exports.utcDays = utcDays;
17121 exports.utcWeek = utcSunday;
17122 exports.utcWeeks = utcSundays;
17123 exports.utcSunday = utcSunday;
17124 exports.utcSundays = utcSundays;
17125 exports.utcMonday = utcMonday;
17126 exports.utcMondays = utcMondays;
17127 exports.utcTuesday = utcTuesday;
17128 exports.utcTuesdays = utcTuesdays;
17129 exports.utcWednesday = utcWednesday;
17130 exports.utcWednesdays = utcWednesdays;
17131 exports.utcThursday = utcThursday;
17132 exports.utcThursdays = utcThursdays;
17133 exports.utcFriday = utcFriday;
17134 exports.utcFridays = utcFridays;
17135 exports.utcSaturday = utcSaturday;
17136 exports.utcSaturdays = utcSaturdays;
17137 exports.utcMonth = utcMonth;
17138 exports.utcMonths = utcMonths;
17139 exports.utcYear = utcYear;
17140 exports.utcYears = utcYears;
17141 exports.timeFormatDefaultLocale = defaultLocale$1;
17142 exports.timeFormatLocale = formatLocale$1;
17143 exports.isoFormat = formatIso;
17144 exports.isoParse = parseIso;
17145 exports.now = now;
17146 exports.timer = timer;
17147 exports.timerFlush = timerFlush;
17148 exports.timeout = timeout$1;
17149 exports.interval = interval$1;
17150 exports.transition = transition;
17151 exports.active = active;
17152 exports.interrupt = interrupt;
17153 exports.voronoi = voronoi;
17154 exports.zoom = zoom;
17155 exports.zoomTransform = transform$1;
17156 exports.zoomIdentity = identity$8;
17157
17158 Object.defineProperty(exports, '__esModule', { value: true });
17159
17160 })));