otsdaq_utilities  v2_05_02_indev
d3.js
1 // https://d3js.org v5.7.0 Copyright 2018 Mike Bostock
2 (function (global, factory) {
3 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4 typeof define === 'function' && define.amd ? define(['exports'], factory) :
5 (factory((global.d3 = global.d3 || {})));
6 }(this, (function (exports) { 'use strict';
7 
8 var version = "5.7.0";
9 
10 function ascending(a, b) {
11  return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
12 }
13 
14 function bisector(compare) {
15  if (compare.length === 1) compare = ascendingComparator(compare);
16  return {
17  left: function(a, x, lo, hi) {
18  if (lo == null) lo = 0;
19  if (hi == null) hi = a.length;
20  while (lo < hi) {
21  var mid = lo + hi >>> 1;
22  if (compare(a[mid], x) < 0) lo = mid + 1;
23  else hi = mid;
24  }
25  return lo;
26  },
27  right: function(a, x, lo, hi) {
28  if (lo == null) lo = 0;
29  if (hi == null) hi = a.length;
30  while (lo < hi) {
31  var mid = lo + hi >>> 1;
32  if (compare(a[mid], x) > 0) hi = mid;
33  else lo = mid + 1;
34  }
35  return lo;
36  }
37  };
38 }
39 
40 function ascendingComparator(f) {
41  return function(d, x) {
42  return ascending(f(d), x);
43  };
44 }
45 
46 var ascendingBisect = bisector(ascending);
47 var bisectRight = ascendingBisect.right;
48 var bisectLeft = ascendingBisect.left;
49 
50 function pairs(array, f) {
51  if (f == null) f = pair;
52  var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
53  while (i < n) pairs[i] = f(p, p = array[++i]);
54  return pairs;
55 }
56 
57 function pair(a, b) {
58  return [a, b];
59 }
60 
61 function cross(values0, values1, reduce) {
62  var n0 = values0.length,
63  n1 = values1.length,
64  values = new Array(n0 * n1),
65  i0,
66  i1,
67  i,
68  value0;
69 
70  if (reduce == null) reduce = pair;
71 
72  for (i0 = i = 0; i0 < n0; ++i0) {
73  for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
74  values[i] = reduce(value0, values1[i1]);
75  }
76  }
77 
78  return values;
79 }
80 
81 function descending(a, b) {
82  return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
83 }
84 
85 function number(x) {
86  return x === null ? NaN : +x;
87 }
88 
89 function variance(values, valueof) {
90  var n = values.length,
91  m = 0,
92  i = -1,
93  mean = 0,
94  value,
95  delta,
96  sum = 0;
97 
98  if (valueof == null) {
99  while (++i < n) {
100  if (!isNaN(value = number(values[i]))) {
101  delta = value - mean;
102  mean += delta / ++m;
103  sum += delta * (value - mean);
104  }
105  }
106  }
107 
108  else {
109  while (++i < n) {
110  if (!isNaN(value = number(valueof(values[i], i, values)))) {
111  delta = value - mean;
112  mean += delta / ++m;
113  sum += delta * (value - mean);
114  }
115  }
116  }
117 
118  if (m > 1) return sum / (m - 1);
119 }
120 
121 function deviation(array, f) {
122  var v = variance(array, f);
123  return v ? Math.sqrt(v) : v;
124 }
125 
126 function extent(values, valueof) {
127  var n = values.length,
128  i = -1,
129  value,
130  min,
131  max;
132 
133  if (valueof == null) {
134  while (++i < n) { // Find the first comparable value.
135  if ((value = values[i]) != null && value >= value) {
136  min = max = value;
137  while (++i < n) { // Compare the remaining values.
138  if ((value = values[i]) != null) {
139  if (min > value) min = value;
140  if (max < value) max = value;
141  }
142  }
143  }
144  }
145  }
146 
147  else {
148  while (++i < n) { // Find the first comparable value.
149  if ((value = valueof(values[i], i, values)) != null && value >= value) {
150  min = max = value;
151  while (++i < n) { // Compare the remaining values.
152  if ((value = valueof(values[i], i, values)) != null) {
153  if (min > value) min = value;
154  if (max < value) max = value;
155  }
156  }
157  }
158  }
159  }
160 
161  return [min, max];
162 }
163 
164 var array = Array.prototype;
165 
166 var slice = array.slice;
167 var map = array.map;
168 
169 function constant(x) {
170  return function() {
171  return x;
172  };
173 }
174 
175 function identity(x) {
176  return x;
177 }
178 
179 function sequence(start, stop, step) {
180  start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
181 
182  var i = -1,
183  n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
184  range = new Array(n);
185 
186  while (++i < n) {
187  range[i] = start + i * step;
188  }
189 
190  return range;
191 }
192 
193 var e10 = Math.sqrt(50),
194  e5 = Math.sqrt(10),
195  e2 = Math.sqrt(2);
196 
197 function ticks(start, stop, count) {
198  var reverse,
199  i = -1,
200  n,
201  ticks,
202  step;
203 
204  stop = +stop, start = +start, count = +count;
205  if (start === stop && count > 0) return [start];
206  if (reverse = stop < start) n = start, start = stop, stop = n;
207  if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
208 
209  if (step > 0) {
210  start = Math.ceil(start / step);
211  stop = Math.floor(stop / step);
212  ticks = new Array(n = Math.ceil(stop - start + 1));
213  while (++i < n) ticks[i] = (start + i) * step;
214  } else {
215  start = Math.floor(start * step);
216  stop = Math.ceil(stop * step);
217  ticks = new Array(n = Math.ceil(start - stop + 1));
218  while (++i < n) ticks[i] = (start - i) / step;
219  }
220 
221  if (reverse) ticks.reverse();
222 
223  return ticks;
224 }
225 
226 function tickIncrement(start, stop, count) {
227  var step = (stop - start) / Math.max(0, count),
228  power = Math.floor(Math.log(step) / Math.LN10),
229  error = step / Math.pow(10, power);
230  return power >= 0
231  ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
232  : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
233 }
234 
235 function tickStep(start, stop, count) {
236  var step0 = Math.abs(stop - start) / Math.max(0, count),
237  step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
238  error = step0 / step1;
239  if (error >= e10) step1 *= 10;
240  else if (error >= e5) step1 *= 5;
241  else if (error >= e2) step1 *= 2;
242  return stop < start ? -step1 : step1;
243 }
244 
245 function thresholdSturges(values) {
246  return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
247 }
248 
249 function histogram() {
250  var value = identity,
251  domain = extent,
252  threshold = thresholdSturges;
253 
254  function histogram(data) {
255  var i,
256  n = data.length,
257  x,
258  values = new Array(n);
259 
260  for (i = 0; i < n; ++i) {
261  values[i] = value(data[i], i, data);
262  }
263 
264  var xz = domain(values),
265  x0 = xz[0],
266  x1 = xz[1],
267  tz = threshold(values, x0, x1);
268 
269  // Convert number of thresholds into uniform thresholds.
270  if (!Array.isArray(tz)) {
271  tz = tickStep(x0, x1, tz);
272  tz = sequence(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive
273  }
274 
275  // Remove any thresholds outside the domain.
276  var m = tz.length;
277  while (tz[0] <= x0) tz.shift(), --m;
278  while (tz[m - 1] > x1) tz.pop(), --m;
279 
280  var bins = new Array(m + 1),
281  bin;
282 
283  // Initialize bins.
284  for (i = 0; i <= m; ++i) {
285  bin = bins[i] = [];
286  bin.x0 = i > 0 ? tz[i - 1] : x0;
287  bin.x1 = i < m ? tz[i] : x1;
288  }
289 
290  // Assign data to bins by value, ignoring any outside the domain.
291  for (i = 0; i < n; ++i) {
292  x = values[i];
293  if (x0 <= x && x <= x1) {
294  bins[bisectRight(tz, x, 0, m)].push(data[i]);
295  }
296  }
297 
298  return bins;
299  }
300 
301  histogram.value = function(_) {
302  return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
303  };
304 
305  histogram.domain = function(_) {
306  return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
307  };
308 
309  histogram.thresholds = function(_) {
310  return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
311  };
312 
313  return histogram;
314 }
315 
316 function threshold(values, p, valueof) {
317  if (valueof == null) valueof = number;
318  if (!(n = values.length)) return;
319  if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
320  if (p >= 1) return +valueof(values[n - 1], n - 1, values);
321  var n,
322  i = (n - 1) * p,
323  i0 = Math.floor(i),
324  value0 = +valueof(values[i0], i0, values),
325  value1 = +valueof(values[i0 + 1], i0 + 1, values);
326  return value0 + (value1 - value0) * (i - i0);
327 }
328 
329 function freedmanDiaconis(values, min, max) {
330  values = map.call(values, number).sort(ascending);
331  return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
332 }
333 
334 function scott(values, min, max) {
335  return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
336 }
337 
338 function max(values, valueof) {
339  var n = values.length,
340  i = -1,
341  value,
342  max;
343 
344  if (valueof == null) {
345  while (++i < n) { // Find the first comparable value.
346  if ((value = values[i]) != null && value >= value) {
347  max = value;
348  while (++i < n) { // Compare the remaining values.
349  if ((value = values[i]) != null && value > max) {
350  max = value;
351  }
352  }
353  }
354  }
355  }
356 
357  else {
358  while (++i < n) { // Find the first comparable value.
359  if ((value = valueof(values[i], i, values)) != null && value >= value) {
360  max = value;
361  while (++i < n) { // Compare the remaining values.
362  if ((value = valueof(values[i], i, values)) != null && value > max) {
363  max = value;
364  }
365  }
366  }
367  }
368  }
369 
370  return max;
371 }
372 
373 function mean(values, valueof) {
374  var n = values.length,
375  m = n,
376  i = -1,
377  value,
378  sum = 0;
379 
380  if (valueof == null) {
381  while (++i < n) {
382  if (!isNaN(value = number(values[i]))) sum += value;
383  else --m;
384  }
385  }
386 
387  else {
388  while (++i < n) {
389  if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
390  else --m;
391  }
392  }
393 
394  if (m) return sum / m;
395 }
396 
397 function median(values, valueof) {
398  var n = values.length,
399  i = -1,
400  value,
401  numbers = [];
402 
403  if (valueof == null) {
404  while (++i < n) {
405  if (!isNaN(value = number(values[i]))) {
406  numbers.push(value);
407  }
408  }
409  }
410 
411  else {
412  while (++i < n) {
413  if (!isNaN(value = number(valueof(values[i], i, values)))) {
414  numbers.push(value);
415  }
416  }
417  }
418 
419  return threshold(numbers.sort(ascending), 0.5);
420 }
421 
422 function merge(arrays) {
423  var n = arrays.length,
424  m,
425  i = -1,
426  j = 0,
427  merged,
428  array;
429 
430  while (++i < n) j += arrays[i].length;
431  merged = new Array(j);
432 
433  while (--n >= 0) {
434  array = arrays[n];
435  m = array.length;
436  while (--m >= 0) {
437  merged[--j] = array[m];
438  }
439  }
440 
441  return merged;
442 }
443 
444 function min(values, valueof) {
445  var n = values.length,
446  i = -1,
447  value,
448  min;
449 
450  if (valueof == null) {
451  while (++i < n) { // Find the first comparable value.
452  if ((value = values[i]) != null && value >= value) {
453  min = value;
454  while (++i < n) { // Compare the remaining values.
455  if ((value = values[i]) != null && min > value) {
456  min = value;
457  }
458  }
459  }
460  }
461  }
462 
463  else {
464  while (++i < n) { // Find the first comparable value.
465  if ((value = valueof(values[i], i, values)) != null && value >= value) {
466  min = value;
467  while (++i < n) { // Compare the remaining values.
468  if ((value = valueof(values[i], i, values)) != null && min > value) {
469  min = value;
470  }
471  }
472  }
473  }
474  }
475 
476  return min;
477 }
478 
479 function permute(array, indexes) {
480  var i = indexes.length, permutes = new Array(i);
481  while (i--) permutes[i] = array[indexes[i]];
482  return permutes;
483 }
484 
485 function scan(values, compare) {
486  if (!(n = values.length)) return;
487  var n,
488  i = 0,
489  j = 0,
490  xi,
491  xj = values[j];
492 
493  if (compare == null) compare = ascending;
494 
495  while (++i < n) {
496  if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
497  xj = xi, j = i;
498  }
499  }
500 
501  if (compare(xj, xj) === 0) return j;
502 }
503 
504 function shuffle(array, i0, i1) {
505  var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
506  t,
507  i;
508 
509  while (m) {
510  i = Math.random() * m-- | 0;
511  t = array[m + i0];
512  array[m + i0] = array[i + i0];
513  array[i + i0] = t;
514  }
515 
516  return array;
517 }
518 
519 function sum(values, valueof) {
520  var n = values.length,
521  i = -1,
522  value,
523  sum = 0;
524 
525  if (valueof == null) {
526  while (++i < n) {
527  if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
528  }
529  }
530 
531  else {
532  while (++i < n) {
533  if (value = +valueof(values[i], i, values)) sum += value;
534  }
535  }
536 
537  return sum;
538 }
539 
540 function transpose(matrix) {
541  if (!(n = matrix.length)) return [];
542  for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
543  for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
544  row[j] = matrix[j][i];
545  }
546  }
547  return transpose;
548 }
549 
550 function length(d) {
551  return d.length;
552 }
553 
554 function zip() {
555  return transpose(arguments);
556 }
557 
558 var slice$1 = Array.prototype.slice;
559 
560 function identity$1(x) {
561  return x;
562 }
563 
564 var top = 1,
565  right = 2,
566  bottom = 3,
567  left = 4,
568  epsilon = 1e-6;
569 
570 function translateX(x) {
571  return "translate(" + (x + 0.5) + ",0)";
572 }
573 
574 function translateY(y) {
575  return "translate(0," + (y + 0.5) + ")";
576 }
577 
578 function number$1(scale) {
579  return function(d) {
580  return +scale(d);
581  };
582 }
583 
584 function center(scale) {
585  var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
586  if (scale.round()) offset = Math.round(offset);
587  return function(d) {
588  return +scale(d) + offset;
589  };
590 }
591 
592 function entering() {
593  return !this.__axis;
594 }
595 
596 function axis(orient, scale) {
597  var tickArguments = [],
598  tickValues = null,
599  tickFormat = null,
600  tickSizeInner = 6,
601  tickSizeOuter = 6,
602  tickPadding = 3,
603  k = orient === top || orient === left ? -1 : 1,
604  x = orient === left || orient === right ? "x" : "y",
605  transform = orient === top || orient === bottom ? translateX : translateY;
606 
607  function axis(context) {
608  var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
609  format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
610  spacing = Math.max(tickSizeInner, 0) + tickPadding,
611  range = scale.range(),
612  range0 = +range[0] + 0.5,
613  range1 = +range[range.length - 1] + 0.5,
614  position = (scale.bandwidth ? center : number$1)(scale.copy()),
615  selection = context.selection ? context.selection() : context,
616  path = selection.selectAll(".domain").data([null]),
617  tick = selection.selectAll(".tick").data(values, scale).order(),
618  tickExit = tick.exit(),
619  tickEnter = tick.enter().append("g").attr("class", "tick"),
620  line = tick.select("line"),
621  text = tick.select("text");
622 
623  path = path.merge(path.enter().insert("path", ".tick")
624  .attr("class", "domain")
625  .attr("stroke", "currentColor"));
626 
627  tick = tick.merge(tickEnter);
628 
629  line = line.merge(tickEnter.append("line")
630  .attr("stroke", "currentColor")
631  .attr(x + "2", k * tickSizeInner));
632 
633  text = text.merge(tickEnter.append("text")
634  .attr("fill", "currentColor")
635  .attr(x, k * spacing)
636  .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
637 
638  if (context !== selection) {
639  path = path.transition(context);
640  tick = tick.transition(context);
641  line = line.transition(context);
642  text = text.transition(context);
643 
644  tickExit = tickExit.transition(context)
645  .attr("opacity", epsilon)
646  .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
647 
648  tickEnter
649  .attr("opacity", epsilon)
650  .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
651  }
652 
653  tickExit.remove();
654 
655  path
656  .attr("d", orient === left || orient == right
657  ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M0.5," + range0 + "V" + range1)
658  : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + ",0.5H" + range1));
659 
660  tick
661  .attr("opacity", 1)
662  .attr("transform", function(d) { return transform(position(d)); });
663 
664  line
665  .attr(x + "2", k * tickSizeInner);
666 
667  text
668  .attr(x, k * spacing)
669  .text(format);
670 
671  selection.filter(entering)
672  .attr("fill", "none")
673  .attr("font-size", 10)
674  .attr("font-family", "sans-serif")
675  .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
676 
677  selection
678  .each(function() { this.__axis = position; });
679  }
680 
681  axis.scale = function(_) {
682  return arguments.length ? (scale = _, axis) : scale;
683  };
684 
685  axis.ticks = function() {
686  return tickArguments = slice$1.call(arguments), axis;
687  };
688 
689  axis.tickArguments = function(_) {
690  return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
691  };
692 
693  axis.tickValues = function(_) {
694  return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
695  };
696 
697  axis.tickFormat = function(_) {
698  return arguments.length ? (tickFormat = _, axis) : tickFormat;
699  };
700 
701  axis.tickSize = function(_) {
702  return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
703  };
704 
705  axis.tickSizeInner = function(_) {
706  return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
707  };
708 
709  axis.tickSizeOuter = function(_) {
710  return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
711  };
712 
713  axis.tickPadding = function(_) {
714  return arguments.length ? (tickPadding = +_, axis) : tickPadding;
715  };
716 
717  return axis;
718 }
719 
720 function axisTop(scale) {
721  return axis(top, scale);
722 }
723 
724 function axisRight(scale) {
725  return axis(right, scale);
726 }
727 
728 function axisBottom(scale) {
729  return axis(bottom, scale);
730 }
731 
732 function axisLeft(scale) {
733  return axis(left, scale);
734 }
735 
736 var noop = {value: function() {}};
737 
738 function dispatch() {
739  for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
740  if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
741  _[t] = [];
742  }
743  return new Dispatch(_);
744 }
745 
746 function Dispatch(_) {
747  this._ = _;
748 }
749 
750 function parseTypenames(typenames, types) {
751  return typenames.trim().split(/^|\s+/).map(function(t) {
752  var name = "", i = t.indexOf(".");
753  if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
754  if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
755  return {type: t, name: name};
756  });
757 }
758 
759 Dispatch.prototype = dispatch.prototype = {
760  constructor: Dispatch,
761  on: function(typename, callback) {
762  var _ = this._,
763  T = parseTypenames(typename + "", _),
764  t,
765  i = -1,
766  n = T.length;
767 
768  // If no callback was specified, return the callback of the given type and name.
769  if (arguments.length < 2) {
770  while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
771  return;
772  }
773 
774  // If a type was specified, set the callback for the given type and name.
775  // Otherwise, if a null callback was specified, remove callbacks of the given name.
776  if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
777  while (++i < n) {
778  if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
779  else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
780  }
781 
782  return this;
783  },
784  copy: function() {
785  var copy = {}, _ = this._;
786  for (var t in _) copy[t] = _[t].slice();
787  return new Dispatch(copy);
788  },
789  call: function(type, that) {
790  if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
791  if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
792  for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
793  },
794  apply: function(type, that, args) {
795  if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
796  for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
797  }
798 };
799 
800 function get(type, name) {
801  for (var i = 0, n = type.length, c; i < n; ++i) {
802  if ((c = type[i]).name === name) {
803  return c.value;
804  }
805  }
806 }
807 
808 function set(type, name, callback) {
809  for (var i = 0, n = type.length; i < n; ++i) {
810  if (type[i].name === name) {
811  type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
812  break;
813  }
814  }
815  if (callback != null) type.push({name: name, value: callback});
816  return type;
817 }
818 
819 var xhtml = "http://www.w3.org/1999/xhtml";
820 
821 var namespaces = {
822  svg: "http://www.w3.org/2000/svg",
823  xhtml: xhtml,
824  xlink: "http://www.w3.org/1999/xlink",
825  xml: "http://www.w3.org/XML/1998/namespace",
826  xmlns: "http://www.w3.org/2000/xmlns/"
827 };
828 
829 function namespace(name) {
830  var prefix = name += "", i = prefix.indexOf(":");
831  if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
832  return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
833 }
834 
835 function creatorInherit(name) {
836  return function() {
837  var document = this.ownerDocument,
838  uri = this.namespaceURI;
839  return uri === xhtml && document.documentElement.namespaceURI === xhtml
840  ? document.createElement(name)
841  : document.createElementNS(uri, name);
842  };
843 }
844 
845 function creatorFixed(fullname) {
846  return function() {
847  return this.ownerDocument.createElementNS(fullname.space, fullname.local);
848  };
849 }
850 
851 function creator(name) {
852  var fullname = namespace(name);
853  return (fullname.local
854  ? creatorFixed
855  : creatorInherit)(fullname);
856 }
857 
858 function none() {}
859 
860 function selector(selector) {
861  return selector == null ? none : function() {
862  return this.querySelector(selector);
863  };
864 }
865 
866 function selection_select(select) {
867  if (typeof select !== "function") select = selector(select);
868 
869  for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
870  for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
871  if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
872  if ("__data__" in node) subnode.__data__ = node.__data__;
873  subgroup[i] = subnode;
874  }
875  }
876  }
877 
878  return new Selection(subgroups, this._parents);
879 }
880 
881 function empty() {
882  return [];
883 }
884 
885 function selectorAll(selector) {
886  return selector == null ? empty : function() {
887  return this.querySelectorAll(selector);
888  };
889 }
890 
891 function selection_selectAll(select) {
892  if (typeof select !== "function") select = selectorAll(select);
893 
894  for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
895  for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
896  if (node = group[i]) {
897  subgroups.push(select.call(node, node.__data__, i, group));
898  parents.push(node);
899  }
900  }
901  }
902 
903  return new Selection(subgroups, parents);
904 }
905 
906 var matcher = function(selector) {
907  return function() {
908  return this.matches(selector);
909  };
910 };
911 
912 if (typeof document !== "undefined") {
913  var element = document.documentElement;
914  if (!element.matches) {
915  var vendorMatches = element.webkitMatchesSelector
916  || element.msMatchesSelector
917  || element.mozMatchesSelector
918  || element.oMatchesSelector;
919  matcher = function(selector) {
920  return function() {
921  return vendorMatches.call(this, selector);
922  };
923  };
924  }
925 }
926 
927 var matcher$1 = matcher;
928 
929 function selection_filter(match) {
930  if (typeof match !== "function") match = matcher$1(match);
931 
932  for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
933  for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
934  if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
935  subgroup.push(node);
936  }
937  }
938  }
939 
940  return new Selection(subgroups, this._parents);
941 }
942 
943 function sparse(update) {
944  return new Array(update.length);
945 }
946 
947 function selection_enter() {
948  return new Selection(this._enter || this._groups.map(sparse), this._parents);
949 }
950 
951 function EnterNode(parent, datum) {
952  this.ownerDocument = parent.ownerDocument;
953  this.namespaceURI = parent.namespaceURI;
954  this._next = null;
955  this._parent = parent;
956  this.__data__ = datum;
957 }
958 
959 EnterNode.prototype = {
960  constructor: EnterNode,
961  appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
962  insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
963  querySelector: function(selector) { return this._parent.querySelector(selector); },
964  querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
965 };
966 
967 function constant$1(x) {
968  return function() {
969  return x;
970  };
971 }
972 
973 var keyPrefix = "$"; // Protect against keys like “__proto__”.
974 
975 function bindIndex(parent, group, enter, update, exit, data) {
976  var i = 0,
977  node,
978  groupLength = group.length,
979  dataLength = data.length;
980 
981  // Put any non-null nodes that fit into update.
982  // Put any null nodes into enter.
983  // Put any remaining data into enter.
984  for (; i < dataLength; ++i) {
985  if (node = group[i]) {
986  node.__data__ = data[i];
987  update[i] = node;
988  } else {
989  enter[i] = new EnterNode(parent, data[i]);
990  }
991  }
992 
993  // Put any non-null nodes that don’t fit into exit.
994  for (; i < groupLength; ++i) {
995  if (node = group[i]) {
996  exit[i] = node;
997  }
998  }
999 }
1000 
1001 function bindKey(parent, group, enter, update, exit, data, key) {
1002  var i,
1003  node,
1004  nodeByKeyValue = {},
1005  groupLength = group.length,
1006  dataLength = data.length,
1007  keyValues = new Array(groupLength),
1008  keyValue;
1009 
1010  // Compute the key for each node.
1011  // If multiple nodes have the same key, the duplicates are added to exit.
1012  for (i = 0; i < groupLength; ++i) {
1013  if (node = group[i]) {
1014  keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
1015  if (keyValue in nodeByKeyValue) {
1016  exit[i] = node;
1017  } else {
1018  nodeByKeyValue[keyValue] = node;
1019  }
1020  }
1021  }
1022 
1023  // Compute the key for each datum.
1024  // If there a node associated with this key, join and add it to update.
1025  // If there is not (or the key is a duplicate), add it to enter.
1026  for (i = 0; i < dataLength; ++i) {
1027  keyValue = keyPrefix + key.call(parent, data[i], i, data);
1028  if (node = nodeByKeyValue[keyValue]) {
1029  update[i] = node;
1030  node.__data__ = data[i];
1031  nodeByKeyValue[keyValue] = null;
1032  } else {
1033  enter[i] = new EnterNode(parent, data[i]);
1034  }
1035  }
1036 
1037  // Add any remaining nodes that were not bound to data to exit.
1038  for (i = 0; i < groupLength; ++i) {
1039  if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
1040  exit[i] = node;
1041  }
1042  }
1043 }
1044 
1045 function selection_data(value, key) {
1046  if (!value) {
1047  data = new Array(this.size()), j = -1;
1048  this.each(function(d) { data[++j] = d; });
1049  return data;
1050  }
1051 
1052  var bind = key ? bindKey : bindIndex,
1053  parents = this._parents,
1054  groups = this._groups;
1055 
1056  if (typeof value !== "function") value = constant$1(value);
1057 
1058  for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
1059  var parent = parents[j],
1060  group = groups[j],
1061  groupLength = group.length,
1062  data = value.call(parent, parent && parent.__data__, j, parents),
1063  dataLength = data.length,
1064  enterGroup = enter[j] = new Array(dataLength),
1065  updateGroup = update[j] = new Array(dataLength),
1066  exitGroup = exit[j] = new Array(groupLength);
1067 
1068  bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
1069 
1070  // Now connect the enter nodes to their following update node, such that
1071  // appendChild can insert the materialized enter node before this node,
1072  // rather than at the end of the parent node.
1073  for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
1074  if (previous = enterGroup[i0]) {
1075  if (i0 >= i1) i1 = i0 + 1;
1076  while (!(next = updateGroup[i1]) && ++i1 < dataLength);
1077  previous._next = next || null;
1078  }
1079  }
1080  }
1081 
1082  update = new Selection(update, parents);
1083  update._enter = enter;
1084  update._exit = exit;
1085  return update;
1086 }
1087 
1088 function selection_exit() {
1089  return new Selection(this._exit || this._groups.map(sparse), this._parents);
1090 }
1091 
1092 function selection_merge(selection$$1) {
1093 
1094  for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
1095  for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
1096  if (node = group0[i] || group1[i]) {
1097  merge[i] = node;
1098  }
1099  }
1100  }
1101 
1102  for (; j < m0; ++j) {
1103  merges[j] = groups0[j];
1104  }
1105 
1106  return new Selection(merges, this._parents);
1107 }
1108 
1109 function selection_order() {
1110 
1111  for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
1112  for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
1113  if (node = group[i]) {
1114  if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
1115  next = node;
1116  }
1117  }
1118  }
1119 
1120  return this;
1121 }
1122 
1123 function selection_sort(compare) {
1124  if (!compare) compare = ascending$1;
1125 
1126  function compareNode(a, b) {
1127  return a && b ? compare(a.__data__, b.__data__) : !a - !b;
1128  }
1129 
1130  for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
1131  for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
1132  if (node = group[i]) {
1133  sortgroup[i] = node;
1134  }
1135  }
1136  sortgroup.sort(compareNode);
1137  }
1138 
1139  return new Selection(sortgroups, this._parents).order();
1140 }
1141 
1142 function ascending$1(a, b) {
1143  return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
1144 }
1145 
1146 function selection_call() {
1147  var callback = arguments[0];
1148  arguments[0] = this;
1149  callback.apply(null, arguments);
1150  return this;
1151 }
1152 
1153 function selection_nodes() {
1154  var nodes = new Array(this.size()), i = -1;
1155  this.each(function() { nodes[++i] = this; });
1156  return nodes;
1157 }
1158 
1159 function selection_node() {
1160 
1161  for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1162  for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
1163  var node = group[i];
1164  if (node) return node;
1165  }
1166  }
1167 
1168  return null;
1169 }
1170 
1171 function selection_size() {
1172  var size = 0;
1173  this.each(function() { ++size; });
1174  return size;
1175 }
1176 
1177 function selection_empty() {
1178  return !this.node();
1179 }
1180 
1181 function selection_each(callback) {
1182 
1183  for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
1184  for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
1185  if (node = group[i]) callback.call(node, node.__data__, i, group);
1186  }
1187  }
1188 
1189  return this;
1190 }
1191 
1192 function attrRemove(name) {
1193  return function() {
1194  this.removeAttribute(name);
1195  };
1196 }
1197 
1198 function attrRemoveNS(fullname) {
1199  return function() {
1200  this.removeAttributeNS(fullname.space, fullname.local);
1201  };
1202 }
1203 
1204 function attrConstant(name, value) {
1205  return function() {
1206  this.setAttribute(name, value);
1207  };
1208 }
1209 
1210 function attrConstantNS(fullname, value) {
1211  return function() {
1212  this.setAttributeNS(fullname.space, fullname.local, value);
1213  };
1214 }
1215 
1216 function attrFunction(name, value) {
1217  return function() {
1218  var v = value.apply(this, arguments);
1219  if (v == null) this.removeAttribute(name);
1220  else this.setAttribute(name, v);
1221  };
1222 }
1223 
1224 function attrFunctionNS(fullname, value) {
1225  return function() {
1226  var v = value.apply(this, arguments);
1227  if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
1228  else this.setAttributeNS(fullname.space, fullname.local, v);
1229  };
1230 }
1231 
1232 function selection_attr(name, value) {
1233  var fullname = namespace(name);
1234 
1235  if (arguments.length < 2) {
1236  var node = this.node();
1237  return fullname.local
1238  ? node.getAttributeNS(fullname.space, fullname.local)
1239  : node.getAttribute(fullname);
1240  }
1241 
1242  return this.each((value == null
1243  ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
1244  ? (fullname.local ? attrFunctionNS : attrFunction)
1245  : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
1246 }
1247 
1248 function defaultView(node) {
1249  return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
1250  || (node.document && node) // node is a Window
1251  || node.defaultView; // node is a Document
1252 }
1253 
1254 function styleRemove(name) {
1255  return function() {
1256  this.style.removeProperty(name);
1257  };
1258 }
1259 
1260 function styleConstant(name, value, priority) {
1261  return function() {
1262  this.style.setProperty(name, value, priority);
1263  };
1264 }
1265 
1266 function styleFunction(name, value, priority) {
1267  return function() {
1268  var v = value.apply(this, arguments);
1269  if (v == null) this.style.removeProperty(name);
1270  else this.style.setProperty(name, v, priority);
1271  };
1272 }
1273 
1274 function selection_style(name, value, priority) {
1275  return arguments.length > 1
1276  ? this.each((value == null
1277  ? styleRemove : typeof value === "function"
1278  ? styleFunction
1279  : styleConstant)(name, value, priority == null ? "" : priority))
1280  : styleValue(this.node(), name);
1281 }
1282 
1283 function styleValue(node, name) {
1284  return node.style.getPropertyValue(name)
1285  || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
1286 }
1287 
1288 function propertyRemove(name) {
1289  return function() {
1290  delete this[name];
1291  };
1292 }
1293 
1294 function propertyConstant(name, value) {
1295  return function() {
1296  this[name] = value;
1297  };
1298 }
1299 
1300 function propertyFunction(name, value) {
1301  return function() {
1302  var v = value.apply(this, arguments);
1303  if (v == null) delete this[name];
1304  else this[name] = v;
1305  };
1306 }
1307 
1308 function selection_property(name, value) {
1309  return arguments.length > 1
1310  ? this.each((value == null
1311  ? propertyRemove : typeof value === "function"
1312  ? propertyFunction
1313  : propertyConstant)(name, value))
1314  : this.node()[name];
1315 }
1316 
1317 function classArray(string) {
1318  return string.trim().split(/^|\s+/);
1319 }
1320 
1321 function classList(node) {
1322  return node.classList || new ClassList(node);
1323 }
1324 
1325 function ClassList(node) {
1326  this._node = node;
1327  this._names = classArray(node.getAttribute("class") || "");
1328 }
1329 
1330 ClassList.prototype = {
1331  add: function(name) {
1332  var i = this._names.indexOf(name);
1333  if (i < 0) {
1334  this._names.push(name);
1335  this._node.setAttribute("class", this._names.join(" "));
1336  }
1337  },
1338  remove: function(name) {
1339  var i = this._names.indexOf(name);
1340  if (i >= 0) {
1341  this._names.splice(i, 1);
1342  this._node.setAttribute("class", this._names.join(" "));
1343  }
1344  },
1345  contains: function(name) {
1346  return this._names.indexOf(name) >= 0;
1347  }
1348 };
1349 
1350 function classedAdd(node, names) {
1351  var list = classList(node), i = -1, n = names.length;
1352  while (++i < n) list.add(names[i]);
1353 }
1354 
1355 function classedRemove(node, names) {
1356  var list = classList(node), i = -1, n = names.length;
1357  while (++i < n) list.remove(names[i]);
1358 }
1359 
1360 function classedTrue(names) {
1361  return function() {
1362  classedAdd(this, names);
1363  };
1364 }
1365 
1366 function classedFalse(names) {
1367  return function() {
1368  classedRemove(this, names);
1369  };
1370 }
1371 
1372 function classedFunction(names, value) {
1373  return function() {
1374  (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
1375  };
1376 }
1377 
1378 function selection_classed(name, value) {
1379  var names = classArray(name + "");
1380 
1381  if (arguments.length < 2) {
1382  var list = classList(this.node()), i = -1, n = names.length;
1383  while (++i < n) if (!list.contains(names[i])) return false;
1384  return true;
1385  }
1386 
1387  return this.each((typeof value === "function"
1388  ? classedFunction : value
1389  ? classedTrue
1390  : classedFalse)(names, value));
1391 }
1392 
1393 function textRemove() {
1394  this.textContent = "";
1395 }
1396 
1397 function textConstant(value) {
1398  return function() {
1399  this.textContent = value;
1400  };
1401 }
1402 
1403 function textFunction(value) {
1404  return function() {
1405  var v = value.apply(this, arguments);
1406  this.textContent = v == null ? "" : v;
1407  };
1408 }
1409 
1410 function selection_text(value) {
1411  return arguments.length
1412  ? this.each(value == null
1413  ? textRemove : (typeof value === "function"
1414  ? textFunction
1415  : textConstant)(value))
1416  : this.node().textContent;
1417 }
1418 
1419 function htmlRemove() {
1420  this.innerHTML = "";
1421 }
1422 
1423 function htmlConstant(value) {
1424  return function() {
1425  this.innerHTML = value;
1426  };
1427 }
1428 
1429 function htmlFunction(value) {
1430  return function() {
1431  var v = value.apply(this, arguments);
1432  this.innerHTML = v == null ? "" : v;
1433  };
1434 }
1435 
1436 function selection_html(value) {
1437  return arguments.length
1438  ? this.each(value == null
1439  ? htmlRemove : (typeof value === "function"
1440  ? htmlFunction
1441  : htmlConstant)(value))
1442  : this.node().innerHTML;
1443 }
1444 
1445 function raise() {
1446  if (this.nextSibling) this.parentNode.appendChild(this);
1447 }
1448 
1449 function selection_raise() {
1450  return this.each(raise);
1451 }
1452 
1453 function lower() {
1454  if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
1455 }
1456 
1457 function selection_lower() {
1458  return this.each(lower);
1459 }
1460 
1461 function selection_append(name) {
1462  var create = typeof name === "function" ? name : creator(name);
1463  return this.select(function() {
1464  return this.appendChild(create.apply(this, arguments));
1465  });
1466 }
1467 
1468 function constantNull() {
1469  return null;
1470 }
1471 
1472 function selection_insert(name, before) {
1473  var create = typeof name === "function" ? name : creator(name),
1474  select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
1475  return this.select(function() {
1476  return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
1477  });
1478 }
1479 
1480 function remove() {
1481  var parent = this.parentNode;
1482  if (parent) parent.removeChild(this);
1483 }
1484 
1485 function selection_remove() {
1486  return this.each(remove);
1487 }
1488 
1489 function selection_cloneShallow() {
1490  return this.parentNode.insertBefore(this.cloneNode(false), this.nextSibling);
1491 }
1492 
1493 function selection_cloneDeep() {
1494  return this.parentNode.insertBefore(this.cloneNode(true), this.nextSibling);
1495 }
1496 
1497 function selection_clone(deep) {
1498  return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
1499 }
1500 
1501 function selection_datum(value) {
1502  return arguments.length
1503  ? this.property("__data__", value)
1504  : this.node().__data__;
1505 }
1506 
1507 var filterEvents = {};
1508 
1509 exports.event = null;
1510 
1511 if (typeof document !== "undefined") {
1512  var element$1 = document.documentElement;
1513  if (!("onmouseenter" in element$1)) {
1514  filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
1515  }
1516 }
1517 
1518 function filterContextListener(listener, index, group) {
1519  listener = contextListener(listener, index, group);
1520  return function(event) {
1521  var related = event.relatedTarget;
1522  if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
1523  listener.call(this, event);
1524  }
1525  };
1526 }
1527 
1528 function contextListener(listener, index, group) {
1529  return function(event1) {
1530  var event0 = exports.event; // Events can be reentrant (e.g., focus).
1531  exports.event = event1;
1532  try {
1533  listener.call(this, this.__data__, index, group);
1534  } finally {
1535  exports.event = event0;
1536  }
1537  };
1538 }
1539 
1540 function parseTypenames$1(typenames) {
1541  return typenames.trim().split(/^|\s+/).map(function(t) {
1542  var name = "", i = t.indexOf(".");
1543  if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
1544  return {type: t, name: name};
1545  });
1546 }
1547 
1548 function onRemove(typename) {
1549  return function() {
1550  var on = this.__on;
1551  if (!on) return;
1552  for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
1553  if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
1554  this.removeEventListener(o.type, o.listener, o.capture);
1555  } else {
1556  on[++i] = o;
1557  }
1558  }
1559  if (++i) on.length = i;
1560  else delete this.__on;
1561  };
1562 }
1563 
1564 function onAdd(typename, value, capture) {
1565  var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
1566  return function(d, i, group) {
1567  var on = this.__on, o, listener = wrap(value, i, group);
1568  if (on) for (var j = 0, m = on.length; j < m; ++j) {
1569  if ((o = on[j]).type === typename.type && o.name === typename.name) {
1570  this.removeEventListener(o.type, o.listener, o.capture);
1571  this.addEventListener(o.type, o.listener = listener, o.capture = capture);
1572  o.value = value;
1573  return;
1574  }
1575  }
1576  this.addEventListener(typename.type, listener, capture);
1577  o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
1578  if (!on) this.__on = [o];
1579  else on.push(o);
1580  };
1581 }
1582 
1583 function selection_on(typename, value, capture) {
1584  var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
1585 
1586  if (arguments.length < 2) {
1587  var on = this.node().__on;
1588  if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
1589  for (i = 0, o = on[j]; i < n; ++i) {
1590  if ((t = typenames[i]).type === o.type && t.name === o.name) {
1591  return o.value;
1592  }
1593  }
1594  }
1595  return;
1596  }
1597 
1598  on = value ? onAdd : onRemove;
1599  if (capture == null) capture = false;
1600  for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
1601  return this;
1602 }
1603 
1604 function customEvent(event1, listener, that, args) {
1605  var event0 = exports.event;
1606  event1.sourceEvent = exports.event;
1607  exports.event = event1;
1608  try {
1609  return listener.apply(that, args);
1610  } finally {
1611  exports.event = event0;
1612  }
1613 }
1614 
1615 function dispatchEvent(node, type, params) {
1616  var window = defaultView(node),
1617  event = window.CustomEvent;
1618 
1619  if (typeof event === "function") {
1620  event = new event(type, params);
1621  } else {
1622  event = window.document.createEvent("Event");
1623  if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
1624  else event.initEvent(type, false, false);
1625  }
1626 
1627  node.dispatchEvent(event);
1628 }
1629 
1630 function dispatchConstant(type, params) {
1631  return function() {
1632  return dispatchEvent(this, type, params);
1633  };
1634 }
1635 
1636 function dispatchFunction(type, params) {
1637  return function() {
1638  return dispatchEvent(this, type, params.apply(this, arguments));
1639  };
1640 }
1641 
1642 function selection_dispatch(type, params) {
1643  return this.each((typeof params === "function"
1644  ? dispatchFunction
1645  : dispatchConstant)(type, params));
1646 }
1647 
1648 var root = [null];
1649 
1650 function Selection(groups, parents) {
1651  this._groups = groups;
1652  this._parents = parents;
1653 }
1654 
1655 function selection() {
1656  return new Selection([[document.documentElement]], root);
1657 }
1658 
1659 Selection.prototype = selection.prototype = {
1660  constructor: Selection,
1661  select: selection_select,
1662  selectAll: selection_selectAll,
1663  filter: selection_filter,
1664  data: selection_data,
1665  enter: selection_enter,
1666  exit: selection_exit,
1667  merge: selection_merge,
1668  order: selection_order,
1669  sort: selection_sort,
1670  call: selection_call,
1671  nodes: selection_nodes,
1672  node: selection_node,
1673  size: selection_size,
1674  empty: selection_empty,
1675  each: selection_each,
1676  attr: selection_attr,
1677  style: selection_style,
1678  property: selection_property,
1679  classed: selection_classed,
1680  text: selection_text,
1681  html: selection_html,
1682  raise: selection_raise,
1683  lower: selection_lower,
1684  append: selection_append,
1685  insert: selection_insert,
1686  remove: selection_remove,
1687  clone: selection_clone,
1688  datum: selection_datum,
1689  on: selection_on,
1690  dispatch: selection_dispatch
1691 };
1692 
1693 function select(selector) {
1694  return typeof selector === "string"
1695  ? new Selection([[document.querySelector(selector)]], [document.documentElement])
1696  : new Selection([[selector]], root);
1697 }
1698 
1699 function create(name) {
1700  return select(creator(name).call(document.documentElement));
1701 }
1702 
1703 var nextId = 0;
1704 
1705 function local() {
1706  return new Local;
1707 }
1708 
1709 function Local() {
1710  this._ = "@" + (++nextId).toString(36);
1711 }
1712 
1713 Local.prototype = local.prototype = {
1714  constructor: Local,
1715  get: function(node) {
1716  var id = this._;
1717  while (!(id in node)) if (!(node = node.parentNode)) return;
1718  return node[id];
1719  },
1720  set: function(node, value) {
1721  return node[this._] = value;
1722  },
1723  remove: function(node) {
1724  return this._ in node && delete node[this._];
1725  },
1726  toString: function() {
1727  return this._;
1728  }
1729 };
1730 
1731 function sourceEvent() {
1732  var current = exports.event, source;
1733  while (source = current.sourceEvent) current = source;
1734  return current;
1735 }
1736 
1737 function point(node, event) {
1738  var svg = node.ownerSVGElement || node;
1739 
1740  if (svg.createSVGPoint) {
1741  var point = svg.createSVGPoint();
1742  point.x = event.clientX, point.y = event.clientY;
1743  point = point.matrixTransform(node.getScreenCTM().inverse());
1744  return [point.x, point.y];
1745  }
1746 
1747  var rect = node.getBoundingClientRect();
1748  return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
1749 }
1750 
1751 function mouse(node) {
1752  var event = sourceEvent();
1753  if (event.changedTouches) event = event.changedTouches[0];
1754  return point(node, event);
1755 }
1756 
1757 function selectAll(selector) {
1758  return typeof selector === "string"
1759  ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
1760  : new Selection([selector == null ? [] : selector], root);
1761 }
1762 
1763 function touch(node, touches, identifier) {
1764  if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
1765 
1766  for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
1767  if ((touch = touches[i]).identifier === identifier) {
1768  return point(node, touch);
1769  }
1770  }
1771 
1772  return null;
1773 }
1774 
1775 function touches(node, touches) {
1776  if (touches == null) touches = sourceEvent().touches;
1777 
1778  for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
1779  points[i] = point(node, touches[i]);
1780  }
1781 
1782  return points;
1783 }
1784 
1785 function nopropagation() {
1786  exports.event.stopImmediatePropagation();
1787 }
1788 
1789 function noevent() {
1790  exports.event.preventDefault();
1791  exports.event.stopImmediatePropagation();
1792 }
1793 
1794 function dragDisable(view) {
1795  var root = view.document.documentElement,
1796  selection$$1 = select(view).on("dragstart.drag", noevent, true);
1797  if ("onselectstart" in root) {
1798  selection$$1.on("selectstart.drag", noevent, true);
1799  } else {
1800  root.__noselect = root.style.MozUserSelect;
1801  root.style.MozUserSelect = "none";
1802  }
1803 }
1804 
1805 function yesdrag(view, noclick) {
1806  var root = view.document.documentElement,
1807  selection$$1 = select(view).on("dragstart.drag", null);
1808  if (noclick) {
1809  selection$$1.on("click.drag", noevent, true);
1810  setTimeout(function() { selection$$1.on("click.drag", null); }, 0);
1811  }
1812  if ("onselectstart" in root) {
1813  selection$$1.on("selectstart.drag", null);
1814  } else {
1815  root.style.MozUserSelect = root.__noselect;
1816  delete root.__noselect;
1817  }
1818 }
1819 
1820 function constant$2(x) {
1821  return function() {
1822  return x;
1823  };
1824 }
1825 
1826 function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
1827  this.target = target;
1828  this.type = type;
1829  this.subject = subject;
1830  this.identifier = id;
1831  this.active = active;
1832  this.x = x;
1833  this.y = y;
1834  this.dx = dx;
1835  this.dy = dy;
1836  this._ = dispatch;
1837 }
1838 
1839 DragEvent.prototype.on = function() {
1840  var value = this._.on.apply(this._, arguments);
1841  return value === this._ ? this : value;
1842 };
1843 
1844 // Ignore right-click, since that should open the context menu.
1845 function defaultFilter() {
1846  return !exports.event.button;
1847 }
1848 
1849 function defaultContainer() {
1850  return this.parentNode;
1851 }
1852 
1853 function defaultSubject(d) {
1854  return d == null ? {x: exports.event.x, y: exports.event.y} : d;
1855 }
1856 
1857 function defaultTouchable() {
1858  return "ontouchstart" in this;
1859 }
1860 
1861 function drag() {
1862  var filter = defaultFilter,
1863  container = defaultContainer,
1864  subject = defaultSubject,
1865  touchable = defaultTouchable,
1866  gestures = {},
1867  listeners = dispatch("start", "drag", "end"),
1868  active = 0,
1869  mousedownx,
1870  mousedowny,
1871  mousemoving,
1872  touchending,
1873  clickDistance2 = 0;
1874 
1875  function drag(selection$$1) {
1876  selection$$1
1877  .on("mousedown.drag", mousedowned)
1878  .filter(touchable)
1879  .on("touchstart.drag", touchstarted)
1880  .on("touchmove.drag", touchmoved)
1881  .on("touchend.drag touchcancel.drag", touchended)
1882  .style("touch-action", "none")
1883  .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
1884  }
1885 
1886  function mousedowned() {
1887  if (touchending || !filter.apply(this, arguments)) return;
1888  var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
1889  if (!gesture) return;
1890  select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
1891  dragDisable(exports.event.view);
1892  nopropagation();
1893  mousemoving = false;
1894  mousedownx = exports.event.clientX;
1895  mousedowny = exports.event.clientY;
1896  gesture("start");
1897  }
1898 
1899  function mousemoved() {
1900  noevent();
1901  if (!mousemoving) {
1902  var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
1903  mousemoving = dx * dx + dy * dy > clickDistance2;
1904  }
1905  gestures.mouse("drag");
1906  }
1907 
1908  function mouseupped() {
1909  select(exports.event.view).on("mousemove.drag mouseup.drag", null);
1910  yesdrag(exports.event.view, mousemoving);
1911  noevent();
1912  gestures.mouse("end");
1913  }
1914 
1915  function touchstarted() {
1916  if (!filter.apply(this, arguments)) return;
1917  var touches$$1 = exports.event.changedTouches,
1918  c = container.apply(this, arguments),
1919  n = touches$$1.length, i, gesture;
1920 
1921  for (i = 0; i < n; ++i) {
1922  if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
1923  nopropagation();
1924  gesture("start");
1925  }
1926  }
1927  }
1928 
1929  function touchmoved() {
1930  var touches$$1 = exports.event.changedTouches,
1931  n = touches$$1.length, i, gesture;
1932 
1933  for (i = 0; i < n; ++i) {
1934  if (gesture = gestures[touches$$1[i].identifier]) {
1935  noevent();
1936  gesture("drag");
1937  }
1938  }
1939  }
1940 
1941  function touchended() {
1942  var touches$$1 = exports.event.changedTouches,
1943  n = touches$$1.length, i, gesture;
1944 
1945  if (touchending) clearTimeout(touchending);
1946  touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
1947  for (i = 0; i < n; ++i) {
1948  if (gesture = gestures[touches$$1[i].identifier]) {
1949  nopropagation();
1950  gesture("end");
1951  }
1952  }
1953  }
1954 
1955  function beforestart(id, container, point$$1, that, args) {
1956  var p = point$$1(container, id), s, dx, dy,
1957  sublisteners = listeners.copy();
1958 
1959  if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
1960  if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
1961  dx = s.x - p[0] || 0;
1962  dy = s.y - p[1] || 0;
1963  return true;
1964  })) return;
1965 
1966  return function gesture(type) {
1967  var p0 = p, n;
1968  switch (type) {
1969  case "start": gestures[id] = gesture, n = active++; break;
1970  case "end": delete gestures[id], --active; // nobreak
1971  case "drag": p = point$$1(container, id), n = active; break;
1972  }
1973  customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
1974  };
1975  }
1976 
1977  drag.filter = function(_) {
1978  return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
1979  };
1980 
1981  drag.container = function(_) {
1982  return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
1983  };
1984 
1985  drag.subject = function(_) {
1986  return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
1987  };
1988 
1989  drag.touchable = function(_) {
1990  return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
1991  };
1992 
1993  drag.on = function() {
1994  var value = listeners.on.apply(listeners, arguments);
1995  return value === listeners ? drag : value;
1996  };
1997 
1998  drag.clickDistance = function(_) {
1999  return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
2000  };
2001 
2002  return drag;
2003 }
2004 
2005 function define(constructor, factory, prototype) {
2006  constructor.prototype = factory.prototype = prototype;
2007  prototype.constructor = constructor;
2008 }
2009 
2010 function extend(parent, definition) {
2011  var prototype = Object.create(parent.prototype);
2012  for (var key in definition) prototype[key] = definition[key];
2013  return prototype;
2014 }
2015 
2016 function Color() {}
2017 
2018 var darker = 0.7;
2019 var brighter = 1 / darker;
2020 
2021 var reI = "\\s*([+-]?\\d+)\\s*",
2022  reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
2023  reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
2024  reHex3 = /^#([0-9a-f]{3})$/,
2025  reHex6 = /^#([0-9a-f]{6})$/,
2026  reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
2027  reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
2028  reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
2029  reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
2030  reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
2031  reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
2032 
2033 var named = {
2034  aliceblue: 0xf0f8ff,
2035  antiquewhite: 0xfaebd7,
2036  aqua: 0x00ffff,
2037  aquamarine: 0x7fffd4,
2038  azure: 0xf0ffff,
2039  beige: 0xf5f5dc,
2040  bisque: 0xffe4c4,
2041  black: 0x000000,
2042  blanchedalmond: 0xffebcd,
2043  blue: 0x0000ff,
2044  blueviolet: 0x8a2be2,
2045  brown: 0xa52a2a,
2046  burlywood: 0xdeb887,
2047  cadetblue: 0x5f9ea0,
2048  chartreuse: 0x7fff00,
2049  chocolate: 0xd2691e,
2050  coral: 0xff7f50,
2051  cornflowerblue: 0x6495ed,
2052  cornsilk: 0xfff8dc,
2053  crimson: 0xdc143c,
2054  cyan: 0x00ffff,
2055  darkblue: 0x00008b,
2056  darkcyan: 0x008b8b,
2057  darkgoldenrod: 0xb8860b,
2058  darkgray: 0xa9a9a9,
2059  darkgreen: 0x006400,
2060  darkgrey: 0xa9a9a9,
2061  darkkhaki: 0xbdb76b,
2062  darkmagenta: 0x8b008b,
2063  darkolivegreen: 0x556b2f,
2064  darkorange: 0xff8c00,
2065  darkorchid: 0x9932cc,
2066  darkred: 0x8b0000,
2067  darksalmon: 0xe9967a,
2068  darkseagreen: 0x8fbc8f,
2069  darkslateblue: 0x483d8b,
2070  darkslategray: 0x2f4f4f,
2071  darkslategrey: 0x2f4f4f,
2072  darkturquoise: 0x00ced1,
2073  darkviolet: 0x9400d3,
2074  deeppink: 0xff1493,
2075  deepskyblue: 0x00bfff,
2076  dimgray: 0x696969,
2077  dimgrey: 0x696969,
2078  dodgerblue: 0x1e90ff,
2079  firebrick: 0xb22222,
2080  floralwhite: 0xfffaf0,
2081  forestgreen: 0x228b22,
2082  fuchsia: 0xff00ff,
2083  gainsboro: 0xdcdcdc,
2084  ghostwhite: 0xf8f8ff,
2085  gold: 0xffd700,
2086  goldenrod: 0xdaa520,
2087  gray: 0x808080,
2088  green: 0x008000,
2089  greenyellow: 0xadff2f,
2090  grey: 0x808080,
2091  honeydew: 0xf0fff0,
2092  hotpink: 0xff69b4,
2093  indianred: 0xcd5c5c,
2094  indigo: 0x4b0082,
2095  ivory: 0xfffff0,
2096  khaki: 0xf0e68c,
2097  lavender: 0xe6e6fa,
2098  lavenderblush: 0xfff0f5,
2099  lawngreen: 0x7cfc00,
2100  lemonchiffon: 0xfffacd,
2101  lightblue: 0xadd8e6,
2102  lightcoral: 0xf08080,
2103  lightcyan: 0xe0ffff,
2104  lightgoldenrodyellow: 0xfafad2,
2105  lightgray: 0xd3d3d3,
2106  lightgreen: 0x90ee90,
2107  lightgrey: 0xd3d3d3,
2108  lightpink: 0xffb6c1,
2109  lightsalmon: 0xffa07a,
2110  lightseagreen: 0x20b2aa,
2111  lightskyblue: 0x87cefa,
2112  lightslategray: 0x778899,
2113  lightslategrey: 0x778899,
2114  lightsteelblue: 0xb0c4de,
2115  lightyellow: 0xffffe0,
2116  lime: 0x00ff00,
2117  limegreen: 0x32cd32,
2118  linen: 0xfaf0e6,
2119  magenta: 0xff00ff,
2120  maroon: 0x800000,
2121  mediumaquamarine: 0x66cdaa,
2122  mediumblue: 0x0000cd,
2123  mediumorchid: 0xba55d3,
2124  mediumpurple: 0x9370db,
2125  mediumseagreen: 0x3cb371,
2126  mediumslateblue: 0x7b68ee,
2127  mediumspringgreen: 0x00fa9a,
2128  mediumturquoise: 0x48d1cc,
2129  mediumvioletred: 0xc71585,
2130  midnightblue: 0x191970,
2131  mintcream: 0xf5fffa,
2132  mistyrose: 0xffe4e1,
2133  moccasin: 0xffe4b5,
2134  navajowhite: 0xffdead,
2135  navy: 0x000080,
2136  oldlace: 0xfdf5e6,
2137  olive: 0x808000,
2138  olivedrab: 0x6b8e23,
2139  orange: 0xffa500,
2140  orangered: 0xff4500,
2141  orchid: 0xda70d6,
2142  palegoldenrod: 0xeee8aa,
2143  palegreen: 0x98fb98,
2144  paleturquoise: 0xafeeee,
2145  palevioletred: 0xdb7093,
2146  papayawhip: 0xffefd5,
2147  peachpuff: 0xffdab9,
2148  peru: 0xcd853f,
2149  pink: 0xffc0cb,
2150  plum: 0xdda0dd,
2151  powderblue: 0xb0e0e6,
2152  purple: 0x800080,
2153  rebeccapurple: 0x663399,
2154  red: 0xff0000,
2155  rosybrown: 0xbc8f8f,
2156  royalblue: 0x4169e1,
2157  saddlebrown: 0x8b4513,
2158  salmon: 0xfa8072,
2159  sandybrown: 0xf4a460,
2160  seagreen: 0x2e8b57,
2161  seashell: 0xfff5ee,
2162  sienna: 0xa0522d,
2163  silver: 0xc0c0c0,
2164  skyblue: 0x87ceeb,
2165  slateblue: 0x6a5acd,
2166  slategray: 0x708090,
2167  slategrey: 0x708090,
2168  snow: 0xfffafa,
2169  springgreen: 0x00ff7f,
2170  steelblue: 0x4682b4,
2171  tan: 0xd2b48c,
2172  teal: 0x008080,
2173  thistle: 0xd8bfd8,
2174  tomato: 0xff6347,
2175  turquoise: 0x40e0d0,
2176  violet: 0xee82ee,
2177  wheat: 0xf5deb3,
2178  white: 0xffffff,
2179  whitesmoke: 0xf5f5f5,
2180  yellow: 0xffff00,
2181  yellowgreen: 0x9acd32
2182 };
2183 
2184 define(Color, color, {
2185  displayable: function() {
2186  return this.rgb().displayable();
2187  },
2188  hex: function() {
2189  return this.rgb().hex();
2190  },
2191  toString: function() {
2192  return this.rgb() + "";
2193  }
2194 });
2195 
2196 function color(format) {
2197  var m;
2198  format = (format + "").trim().toLowerCase();
2199  return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
2200  : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
2201  : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
2202  : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
2203  : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
2204  : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
2205  : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
2206  : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
2207  : named.hasOwnProperty(format) ? rgbn(named[format])
2208  : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
2209  : null;
2210 }
2211 
2212 function rgbn(n) {
2213  return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
2214 }
2215 
2216 function rgba(r, g, b, a) {
2217  if (a <= 0) r = g = b = NaN;
2218  return new Rgb(r, g, b, a);
2219 }
2220 
2221 function rgbConvert(o) {
2222  if (!(o instanceof Color)) o = color(o);
2223  if (!o) return new Rgb;
2224  o = o.rgb();
2225  return new Rgb(o.r, o.g, o.b, o.opacity);
2226 }
2227 
2228 function rgb(r, g, b, opacity) {
2229  return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
2230 }
2231 
2232 function Rgb(r, g, b, opacity) {
2233  this.r = +r;
2234  this.g = +g;
2235  this.b = +b;
2236  this.opacity = +opacity;
2237 }
2238 
2239 define(Rgb, rgb, extend(Color, {
2240  brighter: function(k) {
2241  k = k == null ? brighter : Math.pow(brighter, k);
2242  return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2243  },
2244  darker: function(k) {
2245  k = k == null ? darker : Math.pow(darker, k);
2246  return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
2247  },
2248  rgb: function() {
2249  return this;
2250  },
2251  displayable: function() {
2252  return (0 <= this.r && this.r <= 255)
2253  && (0 <= this.g && this.g <= 255)
2254  && (0 <= this.b && this.b <= 255)
2255  && (0 <= this.opacity && this.opacity <= 1);
2256  },
2257  hex: function() {
2258  return "#" + hex(this.r) + hex(this.g) + hex(this.b);
2259  },
2260  toString: function() {
2261  var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
2262  return (a === 1 ? "rgb(" : "rgba(")
2263  + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
2264  + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
2265  + Math.max(0, Math.min(255, Math.round(this.b) || 0))
2266  + (a === 1 ? ")" : ", " + a + ")");
2267  }
2268 }));
2269 
2270 function hex(value) {
2271  value = Math.max(0, Math.min(255, Math.round(value) || 0));
2272  return (value < 16 ? "0" : "") + value.toString(16);
2273 }
2274 
2275 function hsla(h, s, l, a) {
2276  if (a <= 0) h = s = l = NaN;
2277  else if (l <= 0 || l >= 1) h = s = NaN;
2278  else if (s <= 0) h = NaN;
2279  return new Hsl(h, s, l, a);
2280 }
2281 
2282 function hslConvert(o) {
2283  if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
2284  if (!(o instanceof Color)) o = color(o);
2285  if (!o) return new Hsl;
2286  if (o instanceof Hsl) return o;
2287  o = o.rgb();
2288  var r = o.r / 255,
2289  g = o.g / 255,
2290  b = o.b / 255,
2291  min = Math.min(r, g, b),
2292  max = Math.max(r, g, b),
2293  h = NaN,
2294  s = max - min,
2295  l = (max + min) / 2;
2296  if (s) {
2297  if (r === max) h = (g - b) / s + (g < b) * 6;
2298  else if (g === max) h = (b - r) / s + 2;
2299  else h = (r - g) / s + 4;
2300  s /= l < 0.5 ? max + min : 2 - max - min;
2301  h *= 60;
2302  } else {
2303  s = l > 0 && l < 1 ? 0 : h;
2304  }
2305  return new Hsl(h, s, l, o.opacity);
2306 }
2307 
2308 function hsl(h, s, l, opacity) {
2309  return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
2310 }
2311 
2312 function Hsl(h, s, l, opacity) {
2313  this.h = +h;
2314  this.s = +s;
2315  this.l = +l;
2316  this.opacity = +opacity;
2317 }
2318 
2319 define(Hsl, hsl, extend(Color, {
2320  brighter: function(k) {
2321  k = k == null ? brighter : Math.pow(brighter, k);
2322  return new Hsl(this.h, this.s, this.l * k, this.opacity);
2323  },
2324  darker: function(k) {
2325  k = k == null ? darker : Math.pow(darker, k);
2326  return new Hsl(this.h, this.s, this.l * k, this.opacity);
2327  },
2328  rgb: function() {
2329  var h = this.h % 360 + (this.h < 0) * 360,
2330  s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
2331  l = this.l,
2332  m2 = l + (l < 0.5 ? l : 1 - l) * s,
2333  m1 = 2 * l - m2;
2334  return new Rgb(
2335  hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
2336  hsl2rgb(h, m1, m2),
2337  hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
2338  this.opacity
2339  );
2340  },
2341  displayable: function() {
2342  return (0 <= this.s && this.s <= 1 || isNaN(this.s))
2343  && (0 <= this.l && this.l <= 1)
2344  && (0 <= this.opacity && this.opacity <= 1);
2345  }
2346 }));
2347 
2348 /* From FvD 13.37, CSS Color Module Level 3 */
2349 function hsl2rgb(h, m1, m2) {
2350  return (h < 60 ? m1 + (m2 - m1) * h / 60
2351  : h < 180 ? m2
2352  : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
2353  : m1) * 255;
2354 }
2355 
2356 var deg2rad = Math.PI / 180;
2357 var rad2deg = 180 / Math.PI;
2358 
2359 // https://beta.observablehq.com/@mbostock/lab-and-rgb
2360 var K = 18,
2361  Xn = 0.96422,
2362  Yn = 1,
2363  Zn = 0.82521,
2364  t0 = 4 / 29,
2365  t1 = 6 / 29,
2366  t2 = 3 * t1 * t1,
2367  t3 = t1 * t1 * t1;
2368 
2369 function labConvert(o) {
2370  if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
2371  if (o instanceof Hcl) {
2372  if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
2373  var h = o.h * deg2rad;
2374  return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
2375  }
2376  if (!(o instanceof Rgb)) o = rgbConvert(o);
2377  var r = rgb2lrgb(o.r),
2378  g = rgb2lrgb(o.g),
2379  b = rgb2lrgb(o.b),
2380  y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
2381  if (r === g && g === b) x = z = y; else {
2382  x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
2383  z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
2384  }
2385  return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
2386 }
2387 
2388 function gray(l, opacity) {
2389  return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
2390 }
2391 
2392 function lab(l, a, b, opacity) {
2393  return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
2394 }
2395 
2396 function Lab(l, a, b, opacity) {
2397  this.l = +l;
2398  this.a = +a;
2399  this.b = +b;
2400  this.opacity = +opacity;
2401 }
2402 
2403 define(Lab, lab, extend(Color, {
2404  brighter: function(k) {
2405  return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
2406  },
2407  darker: function(k) {
2408  return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
2409  },
2410  rgb: function() {
2411  var y = (this.l + 16) / 116,
2412  x = isNaN(this.a) ? y : y + this.a / 500,
2413  z = isNaN(this.b) ? y : y - this.b / 200;
2414  x = Xn * lab2xyz(x);
2415  y = Yn * lab2xyz(y);
2416  z = Zn * lab2xyz(z);
2417  return new Rgb(
2418  lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
2419  lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
2420  lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
2421  this.opacity
2422  );
2423  }
2424 }));
2425 
2426 function xyz2lab(t) {
2427  return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
2428 }
2429 
2430 function lab2xyz(t) {
2431  return t > t1 ? t * t * t : t2 * (t - t0);
2432 }
2433 
2434 function lrgb2rgb(x) {
2435  return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
2436 }
2437 
2438 function rgb2lrgb(x) {
2439  return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
2440 }
2441 
2442 function hclConvert(o) {
2443  if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
2444  if (!(o instanceof Lab)) o = labConvert(o);
2445  if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);
2446  var h = Math.atan2(o.b, o.a) * rad2deg;
2447  return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
2448 }
2449 
2450 function lch(l, c, h, opacity) {
2451  return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2452 }
2453 
2454 function hcl(h, c, l, opacity) {
2455  return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
2456 }
2457 
2458 function Hcl(h, c, l, opacity) {
2459  this.h = +h;
2460  this.c = +c;
2461  this.l = +l;
2462  this.opacity = +opacity;
2463 }
2464 
2465 define(Hcl, hcl, extend(Color, {
2466  brighter: function(k) {
2467  return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
2468  },
2469  darker: function(k) {
2470  return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
2471  },
2472  rgb: function() {
2473  return labConvert(this).rgb();
2474  }
2475 }));
2476 
2477 var A = -0.14861,
2478  B = +1.78277,
2479  C = -0.29227,
2480  D = -0.90649,
2481  E = +1.97294,
2482  ED = E * D,
2483  EB = E * B,
2484  BC_DA = B * C - D * A;
2485 
2486 function cubehelixConvert(o) {
2487  if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
2488  if (!(o instanceof Rgb)) o = rgbConvert(o);
2489  var r = o.r / 255,
2490  g = o.g / 255,
2491  b = o.b / 255,
2492  l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
2493  bl = b - l,
2494  k = (E * (g - l) - C * bl) / D,
2495  s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
2496  h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
2497  return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
2498 }
2499 
2500 function cubehelix(h, s, l, opacity) {
2501  return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
2502 }
2503 
2504 function Cubehelix(h, s, l, opacity) {
2505  this.h = +h;
2506  this.s = +s;
2507  this.l = +l;
2508  this.opacity = +opacity;
2509 }
2510 
2511 define(Cubehelix, cubehelix, extend(Color, {
2512  brighter: function(k) {
2513  k = k == null ? brighter : Math.pow(brighter, k);
2514  return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2515  },
2516  darker: function(k) {
2517  k = k == null ? darker : Math.pow(darker, k);
2518  return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
2519  },
2520  rgb: function() {
2521  var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
2522  l = +this.l,
2523  a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
2524  cosh = Math.cos(h),
2525  sinh = Math.sin(h);
2526  return new Rgb(
2527  255 * (l + a * (A * cosh + B * sinh)),
2528  255 * (l + a * (C * cosh + D * sinh)),
2529  255 * (l + a * (E * cosh)),
2530  this.opacity
2531  );
2532  }
2533 }));
2534 
2535 function basis(t1, v0, v1, v2, v3) {
2536  var t2 = t1 * t1, t3 = t2 * t1;
2537  return ((1 - 3 * t1 + 3 * t2 - t3) * v0
2538  + (4 - 6 * t2 + 3 * t3) * v1
2539  + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
2540  + t3 * v3) / 6;
2541 }
2542 
2543 function basis$1(values) {
2544  var n = values.length - 1;
2545  return function(t) {
2546  var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
2547  v1 = values[i],
2548  v2 = values[i + 1],
2549  v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
2550  v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
2551  return basis((t - i / n) * n, v0, v1, v2, v3);
2552  };
2553 }
2554 
2555 function basisClosed(values) {
2556  var n = values.length;
2557  return function(t) {
2558  var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
2559  v0 = values[(i + n - 1) % n],
2560  v1 = values[i % n],
2561  v2 = values[(i + 1) % n],
2562  v3 = values[(i + 2) % n];
2563  return basis((t - i / n) * n, v0, v1, v2, v3);
2564  };
2565 }
2566 
2567 function constant$3(x) {
2568  return function() {
2569  return x;
2570  };
2571 }
2572 
2573 function linear(a, d) {
2574  return function(t) {
2575  return a + t * d;
2576  };
2577 }
2578 
2579 function exponential(a, b, y) {
2580  return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
2581  return Math.pow(a + t * b, y);
2582  };
2583 }
2584 
2585 function hue(a, b) {
2586  var d = b - a;
2587  return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
2588 }
2589 
2590 function gamma(y) {
2591  return (y = +y) === 1 ? nogamma : function(a, b) {
2592  return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
2593  };
2594 }
2595 
2596 function nogamma(a, b) {
2597  var d = b - a;
2598  return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
2599 }
2600 
2601 var interpolateRgb = (function rgbGamma(y) {
2602  var color$$1 = gamma(y);
2603 
2604  function rgb$$1(start, end) {
2605  var r = color$$1((start = rgb(start)).r, (end = rgb(end)).r),
2606  g = color$$1(start.g, end.g),
2607  b = color$$1(start.b, end.b),
2608  opacity = nogamma(start.opacity, end.opacity);
2609  return function(t) {
2610  start.r = r(t);
2611  start.g = g(t);
2612  start.b = b(t);
2613  start.opacity = opacity(t);
2614  return start + "";
2615  };
2616  }
2617 
2618  rgb$$1.gamma = rgbGamma;
2619 
2620  return rgb$$1;
2621 })(1);
2622 
2623 function rgbSpline(spline) {
2624  return function(colors) {
2625  var n = colors.length,
2626  r = new Array(n),
2627  g = new Array(n),
2628  b = new Array(n),
2629  i, color$$1;
2630  for (i = 0; i < n; ++i) {
2631  color$$1 = rgb(colors[i]);
2632  r[i] = color$$1.r || 0;
2633  g[i] = color$$1.g || 0;
2634  b[i] = color$$1.b || 0;
2635  }
2636  r = spline(r);
2637  g = spline(g);
2638  b = spline(b);
2639  color$$1.opacity = 1;
2640  return function(t) {
2641  color$$1.r = r(t);
2642  color$$1.g = g(t);
2643  color$$1.b = b(t);
2644  return color$$1 + "";
2645  };
2646  };
2647 }
2648 
2649 var rgbBasis = rgbSpline(basis$1);
2650 var rgbBasisClosed = rgbSpline(basisClosed);
2651 
2652 function array$1(a, b) {
2653  var nb = b ? b.length : 0,
2654  na = a ? Math.min(nb, a.length) : 0,
2655  x = new Array(na),
2656  c = new Array(nb),
2657  i;
2658 
2659  for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
2660  for (; i < nb; ++i) c[i] = b[i];
2661 
2662  return function(t) {
2663  for (i = 0; i < na; ++i) c[i] = x[i](t);
2664  return c;
2665  };
2666 }
2667 
2668 function date(a, b) {
2669  var d = new Date;
2670  return a = +a, b -= a, function(t) {
2671  return d.setTime(a + b * t), d;
2672  };
2673 }
2674 
2675 function interpolateNumber(a, b) {
2676  return a = +a, b -= a, function(t) {
2677  return a + b * t;
2678  };
2679 }
2680 
2681 function object(a, b) {
2682  var i = {},
2683  c = {},
2684  k;
2685 
2686  if (a === null || typeof a !== "object") a = {};
2687  if (b === null || typeof b !== "object") b = {};
2688 
2689  for (k in b) {
2690  if (k in a) {
2691  i[k] = interpolateValue(a[k], b[k]);
2692  } else {
2693  c[k] = b[k];
2694  }
2695  }
2696 
2697  return function(t) {
2698  for (k in i) c[k] = i[k](t);
2699  return c;
2700  };
2701 }
2702 
2703 var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
2704  reB = new RegExp(reA.source, "g");
2705 
2706 function zero(b) {
2707  return function() {
2708  return b;
2709  };
2710 }
2711 
2712 function one(b) {
2713  return function(t) {
2714  return b(t) + "";
2715  };
2716 }
2717 
2718 function interpolateString(a, b) {
2719  var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b
2720  am, // current match in a
2721  bm, // current match in b
2722  bs, // string preceding current number in b, if any
2723  i = -1, // index in s
2724  s = [], // string constants and placeholders
2725  q = []; // number interpolators
2726 
2727  // Coerce inputs to strings.
2728  a = a + "", b = b + "";
2729 
2730  // Interpolate pairs of numbers in a & b.
2731  while ((am = reA.exec(a))
2732  && (bm = reB.exec(b))) {
2733  if ((bs = bm.index) > bi) { // a string precedes the next number in b
2734  bs = b.slice(bi, bs);
2735  if (s[i]) s[i] += bs; // coalesce with previous string
2736  else s[++i] = bs;
2737  }
2738  if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match
2739  if (s[i]) s[i] += bm; // coalesce with previous string
2740  else s[++i] = bm;
2741  } else { // interpolate non-matching numbers
2742  s[++i] = null;
2743  q.push({i: i, x: interpolateNumber(am, bm)});
2744  }
2745  bi = reB.lastIndex;
2746  }
2747 
2748  // Add remains of b.
2749  if (bi < b.length) {
2750  bs = b.slice(bi);
2751  if (s[i]) s[i] += bs; // coalesce with previous string
2752  else s[++i] = bs;
2753  }
2754 
2755  // Special optimization for only a single match.
2756  // Otherwise, interpolate each of the numbers and rejoin the string.
2757  return s.length < 2 ? (q[0]
2758  ? one(q[0].x)
2759  : zero(b))
2760  : (b = q.length, function(t) {
2761  for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
2762  return s.join("");
2763  });
2764 }
2765 
2766 function interpolateValue(a, b) {
2767  var t = typeof b, c;
2768  return b == null || t === "boolean" ? constant$3(b)
2769  : (t === "number" ? interpolateNumber
2770  : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
2771  : b instanceof color ? interpolateRgb
2772  : b instanceof Date ? date
2773  : Array.isArray(b) ? array$1
2774  : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
2775  : interpolateNumber)(a, b);
2776 }
2777 
2778 function discrete(range) {
2779  var n = range.length;
2780  return function(t) {
2781  return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
2782  };
2783 }
2784 
2785 function hue$1(a, b) {
2786  var i = hue(+a, +b);
2787  return function(t) {
2788  var x = i(t);
2789  return x - 360 * Math.floor(x / 360);
2790  };
2791 }
2792 
2793 function interpolateRound(a, b) {
2794  return a = +a, b -= a, function(t) {
2795  return Math.round(a + b * t);
2796  };
2797 }
2798 
2799 var degrees = 180 / Math.PI;
2800 
2801 var identity$2 = {
2802  translateX: 0,
2803  translateY: 0,
2804  rotate: 0,
2805  skewX: 0,
2806  scaleX: 1,
2807  scaleY: 1
2808 };
2809 
2810 function decompose(a, b, c, d, e, f) {
2811  var scaleX, scaleY, skewX;
2812  if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
2813  if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
2814  if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
2815  if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
2816  return {
2817  translateX: e,
2818  translateY: f,
2819  rotate: Math.atan2(b, a) * degrees,
2820  skewX: Math.atan(skewX) * degrees,
2821  scaleX: scaleX,
2822  scaleY: scaleY
2823  };
2824 }
2825 
2826 var cssNode,
2827  cssRoot,
2828  cssView,
2829  svgNode;
2830 
2831 function parseCss(value) {
2832  if (value === "none") return identity$2;
2833  if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
2834  cssNode.style.transform = value;
2835  value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
2836  cssRoot.removeChild(cssNode);
2837  value = value.slice(7, -1).split(",");
2838  return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
2839 }
2840 
2841 function parseSvg(value) {
2842  if (value == null) return identity$2;
2843  if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
2844  svgNode.setAttribute("transform", value);
2845  if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
2846  value = value.matrix;
2847  return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
2848 }
2849 
2850 function interpolateTransform(parse, pxComma, pxParen, degParen) {
2851 
2852  function pop(s) {
2853  return s.length ? s.pop() + " " : "";
2854  }
2855 
2856  function translate(xa, ya, xb, yb, s, q) {
2857  if (xa !== xb || ya !== yb) {
2858  var i = s.push("translate(", null, pxComma, null, pxParen);
2859  q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
2860  } else if (xb || yb) {
2861  s.push("translate(" + xb + pxComma + yb + pxParen);
2862  }
2863  }
2864 
2865  function rotate(a, b, s, q) {
2866  if (a !== b) {
2867  if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path
2868  q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
2869  } else if (b) {
2870  s.push(pop(s) + "rotate(" + b + degParen);
2871  }
2872  }
2873 
2874  function skewX(a, b, s, q) {
2875  if (a !== b) {
2876  q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
2877  } else if (b) {
2878  s.push(pop(s) + "skewX(" + b + degParen);
2879  }
2880  }
2881 
2882  function scale(xa, ya, xb, yb, s, q) {
2883  if (xa !== xb || ya !== yb) {
2884  var i = s.push(pop(s) + "scale(", null, ",", null, ")");
2885  q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
2886  } else if (xb !== 1 || yb !== 1) {
2887  s.push(pop(s) + "scale(" + xb + "," + yb + ")");
2888  }
2889  }
2890 
2891  return function(a, b) {
2892  var s = [], // string constants and placeholders
2893  q = []; // number interpolators
2894  a = parse(a), b = parse(b);
2895  translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
2896  rotate(a.rotate, b.rotate, s, q);
2897  skewX(a.skewX, b.skewX, s, q);
2898  scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
2899  a = b = null; // gc
2900  return function(t) {
2901  var i = -1, n = q.length, o;
2902  while (++i < n) s[(o = q[i]).i] = o.x(t);
2903  return s.join("");
2904  };
2905  };
2906 }
2907 
2908 var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
2909 var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
2910 
2911 var rho = Math.SQRT2,
2912  rho2 = 2,
2913  rho4 = 4,
2914  epsilon2 = 1e-12;
2915 
2916 function cosh(x) {
2917  return ((x = Math.exp(x)) + 1 / x) / 2;
2918 }
2919 
2920 function sinh(x) {
2921  return ((x = Math.exp(x)) - 1 / x) / 2;
2922 }
2923 
2924 function tanh(x) {
2925  return ((x = Math.exp(2 * x)) - 1) / (x + 1);
2926 }
2927 
2928 // p0 = [ux0, uy0, w0]
2929 // p1 = [ux1, uy1, w1]
2930 function interpolateZoom(p0, p1) {
2931  var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
2932  ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
2933  dx = ux1 - ux0,
2934  dy = uy1 - uy0,
2935  d2 = dx * dx + dy * dy,
2936  i,
2937  S;
2938 
2939  // Special case for u0 ≅ u1.
2940  if (d2 < epsilon2) {
2941  S = Math.log(w1 / w0) / rho;
2942  i = function(t) {
2943  return [
2944  ux0 + t * dx,
2945  uy0 + t * dy,
2946  w0 * Math.exp(rho * t * S)
2947  ];
2948  };
2949  }
2950 
2951  // General case.
2952  else {
2953  var d1 = Math.sqrt(d2),
2954  b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
2955  b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
2956  r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
2957  r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
2958  S = (r1 - r0) / rho;
2959  i = function(t) {
2960  var s = t * S,
2961  coshr0 = cosh(r0),
2962  u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
2963  return [
2964  ux0 + u * dx,
2965  uy0 + u * dy,
2966  w0 * coshr0 / cosh(rho * s + r0)
2967  ];
2968  };
2969  }
2970 
2971  i.duration = S * 1000;
2972 
2973  return i;
2974 }
2975 
2976 function hsl$1(hue$$1) {
2977  return function(start, end) {
2978  var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
2979  s = nogamma(start.s, end.s),
2980  l = nogamma(start.l, end.l),
2981  opacity = nogamma(start.opacity, end.opacity);
2982  return function(t) {
2983  start.h = h(t);
2984  start.s = s(t);
2985  start.l = l(t);
2986  start.opacity = opacity(t);
2987  return start + "";
2988  };
2989  }
2990 }
2991 
2992 var hsl$2 = hsl$1(hue);
2993 var hslLong = hsl$1(nogamma);
2994 
2995 function lab$1(start, end) {
2996  var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
2997  a = nogamma(start.a, end.a),
2998  b = nogamma(start.b, end.b),
2999  opacity = nogamma(start.opacity, end.opacity);
3000  return function(t) {
3001  start.l = l(t);
3002  start.a = a(t);
3003  start.b = b(t);
3004  start.opacity = opacity(t);
3005  return start + "";
3006  };
3007 }
3008 
3009 function hcl$1(hue$$1) {
3010  return function(start, end) {
3011  var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
3012  c = nogamma(start.c, end.c),
3013  l = nogamma(start.l, end.l),
3014  opacity = nogamma(start.opacity, end.opacity);
3015  return function(t) {
3016  start.h = h(t);
3017  start.c = c(t);
3018  start.l = l(t);
3019  start.opacity = opacity(t);
3020  return start + "";
3021  };
3022  }
3023 }
3024 
3025 var hcl$2 = hcl$1(hue);
3026 var hclLong = hcl$1(nogamma);
3027 
3028 function cubehelix$1(hue$$1) {
3029  return (function cubehelixGamma(y) {
3030  y = +y;
3031 
3032  function cubehelix$$1(start, end) {
3033  var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
3034  s = nogamma(start.s, end.s),
3035  l = nogamma(start.l, end.l),
3036  opacity = nogamma(start.opacity, end.opacity);
3037  return function(t) {
3038  start.h = h(t);
3039  start.s = s(t);
3040  start.l = l(Math.pow(t, y));
3041  start.opacity = opacity(t);
3042  return start + "";
3043  };
3044  }
3045 
3046  cubehelix$$1.gamma = cubehelixGamma;
3047 
3048  return cubehelix$$1;
3049  })(1);
3050 }
3051 
3052 var cubehelix$2 = cubehelix$1(hue);
3053 var cubehelixLong = cubehelix$1(nogamma);
3054 
3055 function piecewise(interpolate, values) {
3056  var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
3057  while (i < n) I[i] = interpolate(v, v = values[++i]);
3058  return function(t) {
3059  var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
3060  return I[i](t - i);
3061  };
3062 }
3063 
3064 function quantize(interpolator, n) {
3065  var samples = new Array(n);
3066  for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
3067  return samples;
3068 }
3069 
3070 var frame = 0, // is an animation frame pending?
3071  timeout = 0, // is a timeout pending?
3072  interval = 0, // are any timers active?
3073  pokeDelay = 1000, // how frequently we check for clock skew
3074  taskHead,
3075  taskTail,
3076  clockLast = 0,
3077  clockNow = 0,
3078  clockSkew = 0,
3079  clock = typeof performance === "object" && performance.now ? performance : Date,
3080  setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
3081 
3082 function now() {
3083  return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
3084 }
3085 
3086 function clearNow() {
3087  clockNow = 0;
3088 }
3089 
3090 function Timer() {
3091  this._call =
3092  this._time =
3093  this._next = null;
3094 }
3095 
3096 Timer.prototype = timer.prototype = {
3097  constructor: Timer,
3098  restart: function(callback, delay, time) {
3099  if (typeof callback !== "function") throw new TypeError("callback is not a function");
3100  time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
3101  if (!this._next && taskTail !== this) {
3102  if (taskTail) taskTail._next = this;
3103  else taskHead = this;
3104  taskTail = this;
3105  }
3106  this._call = callback;
3107  this._time = time;
3108  sleep();
3109  },
3110  stop: function() {
3111  if (this._call) {
3112  this._call = null;
3113  this._time = Infinity;
3114  sleep();
3115  }
3116  }
3117 };
3118 
3119 function timer(callback, delay, time) {
3120  var t = new Timer;
3121  t.restart(callback, delay, time);
3122  return t;
3123 }
3124 
3125 function timerFlush() {
3126  now(); // Get the current time, if not already set.
3127  ++frame; // Pretend we’ve set an alarm, if we haven’t already.
3128  var t = taskHead, e;
3129  while (t) {
3130  if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
3131  t = t._next;
3132  }
3133  --frame;
3134 }
3135 
3136 function wake() {
3137  clockNow = (clockLast = clock.now()) + clockSkew;
3138  frame = timeout = 0;
3139  try {
3140  timerFlush();
3141  } finally {
3142  frame = 0;
3143  nap();
3144  clockNow = 0;
3145  }
3146 }
3147 
3148 function poke() {
3149  var now = clock.now(), delay = now - clockLast;
3150  if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
3151 }
3152 
3153 function nap() {
3154  var t0, t1 = taskHead, t2, time = Infinity;
3155  while (t1) {
3156  if (t1._call) {
3157  if (time > t1._time) time = t1._time;
3158  t0 = t1, t1 = t1._next;
3159  } else {
3160  t2 = t1._next, t1._next = null;
3161  t1 = t0 ? t0._next = t2 : taskHead = t2;
3162  }
3163  }
3164  taskTail = t0;
3165  sleep(time);
3166 }
3167 
3168 function sleep(time) {
3169  if (frame) return; // Soonest alarm already set, or will be.
3170  if (timeout) timeout = clearTimeout(timeout);
3171  var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
3172  if (delay > 24) {
3173  if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
3174  if (interval) interval = clearInterval(interval);
3175  } else {
3176  if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
3177  frame = 1, setFrame(wake);
3178  }
3179 }
3180 
3181 function timeout$1(callback, delay, time) {
3182  var t = new Timer;
3183  delay = delay == null ? 0 : +delay;
3184  t.restart(function(elapsed) {
3185  t.stop();
3186  callback(elapsed + delay);
3187  }, delay, time);
3188  return t;
3189 }
3190 
3191 function interval$1(callback, delay, time) {
3192  var t = new Timer, total = delay;
3193  if (delay == null) return t.restart(callback, delay, time), t;
3194  delay = +delay, time = time == null ? now() : +time;
3195  t.restart(function tick(elapsed) {
3196  elapsed += total;
3197  t.restart(tick, total += delay, time);
3198  callback(elapsed);
3199  }, delay, time);
3200  return t;
3201 }
3202 
3203 var emptyOn = dispatch("start", "end", "interrupt");
3204 var emptyTween = [];
3205 
3206 var CREATED = 0;
3207 var SCHEDULED = 1;
3208 var STARTING = 2;
3209 var STARTED = 3;
3210 var RUNNING = 4;
3211 var ENDING = 5;
3212 var ENDED = 6;
3213 
3214 function schedule(node, name, id, index, group, timing) {
3215  var schedules = node.__transition;
3216  if (!schedules) node.__transition = {};
3217  else if (id in schedules) return;
3218  create$1(node, id, {
3219  name: name,
3220  index: index, // For context during callback.
3221  group: group, // For context during callback.
3222  on: emptyOn,
3223  tween: emptyTween,
3224  time: timing.time,
3225  delay: timing.delay,
3226  duration: timing.duration,
3227  ease: timing.ease,
3228  timer: null,
3229  state: CREATED
3230  });
3231 }
3232 
3233 function init(node, id) {
3234  var schedule = get$1(node, id);
3235  if (schedule.state > CREATED) throw new Error("too late; already scheduled");
3236  return schedule;
3237 }
3238 
3239 function set$1(node, id) {
3240  var schedule = get$1(node, id);
3241  if (schedule.state > STARTING) throw new Error("too late; already started");
3242  return schedule;
3243 }
3244 
3245 function get$1(node, id) {
3246  var schedule = node.__transition;
3247  if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
3248  return schedule;
3249 }
3250 
3251 function create$1(node, id, self) {
3252  var schedules = node.__transition,
3253  tween;
3254 
3255  // Initialize the self timer when the transition is created.
3256  // Note the actual delay is not known until the first callback!
3257  schedules[id] = self;
3258  self.timer = timer(schedule, 0, self.time);
3259 
3260  function schedule(elapsed) {
3261  self.state = SCHEDULED;
3262  self.timer.restart(start, self.delay, self.time);
3263 
3264  // If the elapsed delay is less than our first sleep, start immediately.
3265  if (self.delay <= elapsed) start(elapsed - self.delay);
3266  }
3267 
3268  function start(elapsed) {
3269  var i, j, n, o;
3270 
3271  // If the state is not SCHEDULED, then we previously errored on start.
3272  if (self.state !== SCHEDULED) return stop();
3273 
3274  for (i in schedules) {
3275  o = schedules[i];
3276  if (o.name !== self.name) continue;
3277 
3278  // While this element already has a starting transition during this frame,
3279  // defer starting an interrupting transition until that transition has a
3280  // chance to tick (and possibly end); see d3/d3-transition#54!
3281  if (o.state === STARTED) return timeout$1(start);
3282 
3283  // Interrupt the active transition, if any.
3284  // Dispatch the interrupt event.
3285  if (o.state === RUNNING) {
3286  o.state = ENDED;
3287  o.timer.stop();
3288  o.on.call("interrupt", node, node.__data__, o.index, o.group);
3289  delete schedules[i];
3290  }
3291 
3292  // Cancel any pre-empted transitions. No interrupt event is dispatched
3293  // because the cancelled transitions never started. Note that this also
3294  // removes this transition from the pending list!
3295  else if (+i < id) {
3296  o.state = ENDED;
3297  o.timer.stop();
3298  delete schedules[i];
3299  }
3300  }
3301 
3302  // Defer the first tick to end of the current frame; see d3/d3#1576.
3303  // Note the transition may be canceled after start and before the first tick!
3304  // Note this must be scheduled before the start event; see d3/d3-transition#16!
3305  // Assuming this is successful, subsequent callbacks go straight to tick.
3306  timeout$1(function() {
3307  if (self.state === STARTED) {
3308  self.state = RUNNING;
3309  self.timer.restart(tick, self.delay, self.time);
3310  tick(elapsed);
3311  }
3312  });
3313 
3314  // Dispatch the start event.
3315  // Note this must be done before the tween are initialized.
3316  self.state = STARTING;
3317  self.on.call("start", node, node.__data__, self.index, self.group);
3318  if (self.state !== STARTING) return; // interrupted
3319  self.state = STARTED;
3320 
3321  // Initialize the tween, deleting null tween.
3322  tween = new Array(n = self.tween.length);
3323  for (i = 0, j = -1; i < n; ++i) {
3324  if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
3325  tween[++j] = o;
3326  }
3327  }
3328  tween.length = j + 1;
3329  }
3330 
3331  function tick(elapsed) {
3332  var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
3333  i = -1,
3334  n = tween.length;
3335 
3336  while (++i < n) {
3337  tween[i].call(null, t);
3338  }
3339 
3340  // Dispatch the end event.
3341  if (self.state === ENDING) {
3342  self.on.call("end", node, node.__data__, self.index, self.group);
3343  stop();
3344  }
3345  }
3346 
3347  function stop() {
3348  self.state = ENDED;
3349  self.timer.stop();
3350  delete schedules[id];
3351  for (var i in schedules) return; // eslint-disable-line no-unused-vars
3352  delete node.__transition;
3353  }
3354 }
3355 
3356 function interrupt(node, name) {
3357  var schedules = node.__transition,
3358  schedule$$1,
3359  active,
3360  empty = true,
3361  i;
3362 
3363  if (!schedules) return;
3364 
3365  name = name == null ? null : name + "";
3366 
3367  for (i in schedules) {
3368  if ((schedule$$1 = schedules[i]).name !== name) { empty = false; continue; }
3369  active = schedule$$1.state > STARTING && schedule$$1.state < ENDING;
3370  schedule$$1.state = ENDED;
3371  schedule$$1.timer.stop();
3372  if (active) schedule$$1.on.call("interrupt", node, node.__data__, schedule$$1.index, schedule$$1.group);
3373  delete schedules[i];
3374  }
3375 
3376  if (empty) delete node.__transition;
3377 }
3378 
3379 function selection_interrupt(name) {
3380  return this.each(function() {
3381  interrupt(this, name);
3382  });
3383 }
3384 
3385 function tweenRemove(id, name) {
3386  var tween0, tween1;
3387  return function() {
3388  var schedule$$1 = set$1(this, id),
3389  tween = schedule$$1.tween;
3390 
3391  // If this node shared tween with the previous node,
3392  // just assign the updated shared tween and we’re done!
3393  // Otherwise, copy-on-write.
3394  if (tween !== tween0) {
3395  tween1 = tween0 = tween;
3396  for (var i = 0, n = tween1.length; i < n; ++i) {
3397  if (tween1[i].name === name) {
3398  tween1 = tween1.slice();
3399  tween1.splice(i, 1);
3400  break;
3401  }
3402  }
3403  }
3404 
3405  schedule$$1.tween = tween1;
3406  };
3407 }
3408 
3409 function tweenFunction(id, name, value) {
3410  var tween0, tween1;
3411  if (typeof value !== "function") throw new Error;
3412  return function() {
3413  var schedule$$1 = set$1(this, id),
3414  tween = schedule$$1.tween;
3415 
3416  // If this node shared tween with the previous node,
3417  // just assign the updated shared tween and we’re done!
3418  // Otherwise, copy-on-write.
3419  if (tween !== tween0) {
3420  tween1 = (tween0 = tween).slice();
3421  for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
3422  if (tween1[i].name === name) {
3423  tween1[i] = t;
3424  break;
3425  }
3426  }
3427  if (i === n) tween1.push(t);
3428  }
3429 
3430  schedule$$1.tween = tween1;
3431  };
3432 }
3433 
3434 function transition_tween(name, value) {
3435  var id = this._id;
3436 
3437  name += "";
3438 
3439  if (arguments.length < 2) {
3440  var tween = get$1(this.node(), id).tween;
3441  for (var i = 0, n = tween.length, t; i < n; ++i) {
3442  if ((t = tween[i]).name === name) {
3443  return t.value;
3444  }
3445  }
3446  return null;
3447  }
3448 
3449  return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
3450 }
3451 
3452 function tweenValue(transition, name, value) {
3453  var id = transition._id;
3454 
3455  transition.each(function() {
3456  var schedule$$1 = set$1(this, id);
3457  (schedule$$1.value || (schedule$$1.value = {}))[name] = value.apply(this, arguments);
3458  });
3459 
3460  return function(node) {
3461  return get$1(node, id).value[name];
3462  };
3463 }
3464 
3465 function interpolate(a, b) {
3466  var c;
3467  return (typeof b === "number" ? interpolateNumber
3468  : b instanceof color ? interpolateRgb
3469  : (c = color(b)) ? (b = c, interpolateRgb)
3470  : interpolateString)(a, b);
3471 }
3472 
3473 function attrRemove$1(name) {
3474  return function() {
3475  this.removeAttribute(name);
3476  };
3477 }
3478 
3479 function attrRemoveNS$1(fullname) {
3480  return function() {
3481  this.removeAttributeNS(fullname.space, fullname.local);
3482  };
3483 }
3484 
3485 function attrConstant$1(name, interpolate$$1, value1) {
3486  var value00,
3487  interpolate0;
3488  return function() {
3489  var value0 = this.getAttribute(name);
3490  return value0 === value1 ? null
3491  : value0 === value00 ? interpolate0
3492  : interpolate0 = interpolate$$1(value00 = value0, value1);
3493  };
3494 }
3495 
3496 function attrConstantNS$1(fullname, interpolate$$1, value1) {
3497  var value00,
3498  interpolate0;
3499  return function() {
3500  var value0 = this.getAttributeNS(fullname.space, fullname.local);
3501  return value0 === value1 ? null
3502  : value0 === value00 ? interpolate0
3503  : interpolate0 = interpolate$$1(value00 = value0, value1);
3504  };
3505 }
3506 
3507 function attrFunction$1(name, interpolate$$1, value) {
3508  var value00,
3509  value10,
3510  interpolate0;
3511  return function() {
3512  var value0, value1 = value(this);
3513  if (value1 == null) return void this.removeAttribute(name);
3514  value0 = this.getAttribute(name);
3515  return value0 === value1 ? null
3516  : value0 === value00 && value1 === value10 ? interpolate0
3517  : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3518  };
3519 }
3520 
3521 function attrFunctionNS$1(fullname, interpolate$$1, value) {
3522  var value00,
3523  value10,
3524  interpolate0;
3525  return function() {
3526  var value0, value1 = value(this);
3527  if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
3528  value0 = this.getAttributeNS(fullname.space, fullname.local);
3529  return value0 === value1 ? null
3530  : value0 === value00 && value1 === value10 ? interpolate0
3531  : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3532  };
3533 }
3534 
3535 function transition_attr(name, value) {
3536  var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
3537  return this.attrTween(name, typeof value === "function"
3538  ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
3539  : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
3540  : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value + ""));
3541 }
3542 
3543 function attrTweenNS(fullname, value) {
3544  function tween() {
3545  var node = this, i = value.apply(node, arguments);
3546  return i && function(t) {
3547  node.setAttributeNS(fullname.space, fullname.local, i(t));
3548  };
3549  }
3550  tween._value = value;
3551  return tween;
3552 }
3553 
3554 function attrTween(name, value) {
3555  function tween() {
3556  var node = this, i = value.apply(node, arguments);
3557  return i && function(t) {
3558  node.setAttribute(name, i(t));
3559  };
3560  }
3561  tween._value = value;
3562  return tween;
3563 }
3564 
3565 function transition_attrTween(name, value) {
3566  var key = "attr." + name;
3567  if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3568  if (value == null) return this.tween(key, null);
3569  if (typeof value !== "function") throw new Error;
3570  var fullname = namespace(name);
3571  return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
3572 }
3573 
3574 function delayFunction(id, value) {
3575  return function() {
3576  init(this, id).delay = +value.apply(this, arguments);
3577  };
3578 }
3579 
3580 function delayConstant(id, value) {
3581  return value = +value, function() {
3582  init(this, id).delay = value;
3583  };
3584 }
3585 
3586 function transition_delay(value) {
3587  var id = this._id;
3588 
3589  return arguments.length
3590  ? this.each((typeof value === "function"
3591  ? delayFunction
3592  : delayConstant)(id, value))
3593  : get$1(this.node(), id).delay;
3594 }
3595 
3596 function durationFunction(id, value) {
3597  return function() {
3598  set$1(this, id).duration = +value.apply(this, arguments);
3599  };
3600 }
3601 
3602 function durationConstant(id, value) {
3603  return value = +value, function() {
3604  set$1(this, id).duration = value;
3605  };
3606 }
3607 
3608 function transition_duration(value) {
3609  var id = this._id;
3610 
3611  return arguments.length
3612  ? this.each((typeof value === "function"
3613  ? durationFunction
3614  : durationConstant)(id, value))
3615  : get$1(this.node(), id).duration;
3616 }
3617 
3618 function easeConstant(id, value) {
3619  if (typeof value !== "function") throw new Error;
3620  return function() {
3621  set$1(this, id).ease = value;
3622  };
3623 }
3624 
3625 function transition_ease(value) {
3626  var id = this._id;
3627 
3628  return arguments.length
3629  ? this.each(easeConstant(id, value))
3630  : get$1(this.node(), id).ease;
3631 }
3632 
3633 function transition_filter(match) {
3634  if (typeof match !== "function") match = matcher$1(match);
3635 
3636  for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3637  for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
3638  if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
3639  subgroup.push(node);
3640  }
3641  }
3642  }
3643 
3644  return new Transition(subgroups, this._parents, this._name, this._id);
3645 }
3646 
3647 function transition_merge(transition$$1) {
3648  if (transition$$1._id !== this._id) throw new Error;
3649 
3650  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) {
3651  for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
3652  if (node = group0[i] || group1[i]) {
3653  merge[i] = node;
3654  }
3655  }
3656  }
3657 
3658  for (; j < m0; ++j) {
3659  merges[j] = groups0[j];
3660  }
3661 
3662  return new Transition(merges, this._parents, this._name, this._id);
3663 }
3664 
3665 function start(name) {
3666  return (name + "").trim().split(/^|\s+/).every(function(t) {
3667  var i = t.indexOf(".");
3668  if (i >= 0) t = t.slice(0, i);
3669  return !t || t === "start";
3670  });
3671 }
3672 
3673 function onFunction(id, name, listener) {
3674  var on0, on1, sit = start(name) ? init : set$1;
3675  return function() {
3676  var schedule$$1 = sit(this, id),
3677  on = schedule$$1.on;
3678 
3679  // If this node shared a dispatch with the previous node,
3680  // just assign the updated shared dispatch and we’re done!
3681  // Otherwise, copy-on-write.
3682  if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
3683 
3684  schedule$$1.on = on1;
3685  };
3686 }
3687 
3688 function transition_on(name, listener) {
3689  var id = this._id;
3690 
3691  return arguments.length < 2
3692  ? get$1(this.node(), id).on.on(name)
3693  : this.each(onFunction(id, name, listener));
3694 }
3695 
3696 function removeFunction(id) {
3697  return function() {
3698  var parent = this.parentNode;
3699  for (var i in this.__transition) if (+i !== id) return;
3700  if (parent) parent.removeChild(this);
3701  };
3702 }
3703 
3704 function transition_remove() {
3705  return this.on("end.remove", removeFunction(this._id));
3706 }
3707 
3708 function transition_select(select$$1) {
3709  var name = this._name,
3710  id = this._id;
3711 
3712  if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
3713 
3714  for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
3715  for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
3716  if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
3717  if ("__data__" in node) subnode.__data__ = node.__data__;
3718  subgroup[i] = subnode;
3719  schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
3720  }
3721  }
3722  }
3723 
3724  return new Transition(subgroups, this._parents, name, id);
3725 }
3726 
3727 function transition_selectAll(select$$1) {
3728  var name = this._name,
3729  id = this._id;
3730 
3731  if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
3732 
3733  for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
3734  for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3735  if (node = group[i]) {
3736  for (var children = select$$1.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
3737  if (child = children[k]) {
3738  schedule(child, name, id, k, children, inherit);
3739  }
3740  }
3741  subgroups.push(children);
3742  parents.push(node);
3743  }
3744  }
3745  }
3746 
3747  return new Transition(subgroups, parents, name, id);
3748 }
3749 
3750 var Selection$1 = selection.prototype.constructor;
3751 
3752 function transition_selection() {
3753  return new Selection$1(this._groups, this._parents);
3754 }
3755 
3756 function styleRemove$1(name, interpolate$$1) {
3757  var value00,
3758  value10,
3759  interpolate0;
3760  return function() {
3761  var value0 = styleValue(this, name),
3762  value1 = (this.style.removeProperty(name), styleValue(this, name));
3763  return value0 === value1 ? null
3764  : value0 === value00 && value1 === value10 ? interpolate0
3765  : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3766  };
3767 }
3768 
3769 function styleRemoveEnd(name) {
3770  return function() {
3771  this.style.removeProperty(name);
3772  };
3773 }
3774 
3775 function styleConstant$1(name, interpolate$$1, value1) {
3776  var value00,
3777  interpolate0;
3778  return function() {
3779  var value0 = styleValue(this, name);
3780  return value0 === value1 ? null
3781  : value0 === value00 ? interpolate0
3782  : interpolate0 = interpolate$$1(value00 = value0, value1);
3783  };
3784 }
3785 
3786 function styleFunction$1(name, interpolate$$1, value) {
3787  var value00,
3788  value10,
3789  interpolate0;
3790  return function() {
3791  var value0 = styleValue(this, name),
3792  value1 = value(this);
3793  if (value1 == null) value1 = (this.style.removeProperty(name), styleValue(this, name));
3794  return value0 === value1 ? null
3795  : value0 === value00 && value1 === value10 ? interpolate0
3796  : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
3797  };
3798 }
3799 
3800 function transition_style(name, value, priority) {
3801  var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
3802  return value == null ? this
3803  .styleTween(name, styleRemove$1(name, i))
3804  .on("end.style." + name, styleRemoveEnd(name))
3805  : this.styleTween(name, typeof value === "function"
3806  ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
3807  : styleConstant$1(name, i, value + ""), priority);
3808 }
3809 
3810 function styleTween(name, value, priority) {
3811  function tween() {
3812  var node = this, i = value.apply(node, arguments);
3813  return i && function(t) {
3814  node.style.setProperty(name, i(t), priority);
3815  };
3816  }
3817  tween._value = value;
3818  return tween;
3819 }
3820 
3821 function transition_styleTween(name, value, priority) {
3822  var key = "style." + (name += "");
3823  if (arguments.length < 2) return (key = this.tween(key)) && key._value;
3824  if (value == null) return this.tween(key, null);
3825  if (typeof value !== "function") throw new Error;
3826  return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
3827 }
3828 
3829 function textConstant$1(value) {
3830  return function() {
3831  this.textContent = value;
3832  };
3833 }
3834 
3835 function textFunction$1(value) {
3836  return function() {
3837  var value1 = value(this);
3838  this.textContent = value1 == null ? "" : value1;
3839  };
3840 }
3841 
3842 function transition_text(value) {
3843  return this.tween("text", typeof value === "function"
3844  ? textFunction$1(tweenValue(this, "text", value))
3845  : textConstant$1(value == null ? "" : value + ""));
3846 }
3847 
3848 function transition_transition() {
3849  var name = this._name,
3850  id0 = this._id,
3851  id1 = newId();
3852 
3853  for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
3854  for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
3855  if (node = group[i]) {
3856  var inherit = get$1(node, id0);
3857  schedule(node, name, id1, i, group, {
3858  time: inherit.time + inherit.delay + inherit.duration,
3859  delay: 0,
3860  duration: inherit.duration,
3861  ease: inherit.ease
3862  });
3863  }
3864  }
3865  }
3866 
3867  return new Transition(groups, this._parents, name, id1);
3868 }
3869 
3870 var id = 0;
3871 
3872 function Transition(groups, parents, name, id) {
3873  this._groups = groups;
3874  this._parents = parents;
3875  this._name = name;
3876  this._id = id;
3877 }
3878 
3879 function transition(name) {
3880  return selection().transition(name);
3881 }
3882 
3883 function newId() {
3884  return ++id;
3885 }
3886 
3887 var selection_prototype = selection.prototype;
3888 
3889 Transition.prototype = transition.prototype = {
3890  constructor: Transition,
3891  select: transition_select,
3892  selectAll: transition_selectAll,
3893  filter: transition_filter,
3894  merge: transition_merge,
3895  selection: transition_selection,
3896  transition: transition_transition,
3897  call: selection_prototype.call,
3898  nodes: selection_prototype.nodes,
3899  node: selection_prototype.node,
3900  size: selection_prototype.size,
3901  empty: selection_prototype.empty,
3902  each: selection_prototype.each,
3903  on: transition_on,
3904  attr: transition_attr,
3905  attrTween: transition_attrTween,
3906  style: transition_style,
3907  styleTween: transition_styleTween,
3908  text: transition_text,
3909  remove: transition_remove,
3910  tween: transition_tween,
3911  delay: transition_delay,
3912  duration: transition_duration,
3913  ease: transition_ease
3914 };
3915 
3916 function linear$1(t) {
3917  return +t;
3918 }
3919 
3920 function quadIn(t) {
3921  return t * t;
3922 }
3923 
3924 function quadOut(t) {
3925  return t * (2 - t);
3926 }
3927 
3928 function quadInOut(t) {
3929  return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
3930 }
3931 
3932 function cubicIn(t) {
3933  return t * t * t;
3934 }
3935 
3936 function cubicOut(t) {
3937  return --t * t * t + 1;
3938 }
3939 
3940 function cubicInOut(t) {
3941  return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
3942 }
3943 
3944 var exponent = 3;
3945 
3946 var polyIn = (function custom(e) {
3947  e = +e;
3948 
3949  function polyIn(t) {
3950  return Math.pow(t, e);
3951  }
3952 
3953  polyIn.exponent = custom;
3954 
3955  return polyIn;
3956 })(exponent);
3957 
3958 var polyOut = (function custom(e) {
3959  e = +e;
3960 
3961  function polyOut(t) {
3962  return 1 - Math.pow(1 - t, e);
3963  }
3964 
3965  polyOut.exponent = custom;
3966 
3967  return polyOut;
3968 })(exponent);
3969 
3970 var polyInOut = (function custom(e) {
3971  e = +e;
3972 
3973  function polyInOut(t) {
3974  return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
3975  }
3976 
3977  polyInOut.exponent = custom;
3978 
3979  return polyInOut;
3980 })(exponent);
3981 
3982 var pi = Math.PI,
3983  halfPi = pi / 2;
3984 
3985 function sinIn(t) {
3986  return 1 - Math.cos(t * halfPi);
3987 }
3988 
3989 function sinOut(t) {
3990  return Math.sin(t * halfPi);
3991 }
3992 
3993 function sinInOut(t) {
3994  return (1 - Math.cos(pi * t)) / 2;
3995 }
3996 
3997 function expIn(t) {
3998  return Math.pow(2, 10 * t - 10);
3999 }
4000 
4001 function expOut(t) {
4002  return 1 - Math.pow(2, -10 * t);
4003 }
4004 
4005 function expInOut(t) {
4006  return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
4007 }
4008 
4009 function circleIn(t) {
4010  return 1 - Math.sqrt(1 - t * t);
4011 }
4012 
4013 function circleOut(t) {
4014  return Math.sqrt(1 - --t * t);
4015 }
4016 
4017 function circleInOut(t) {
4018  return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
4019 }
4020 
4021 var b1 = 4 / 11,
4022  b2 = 6 / 11,
4023  b3 = 8 / 11,
4024  b4 = 3 / 4,
4025  b5 = 9 / 11,
4026  b6 = 10 / 11,
4027  b7 = 15 / 16,
4028  b8 = 21 / 22,
4029  b9 = 63 / 64,
4030  b0 = 1 / b1 / b1;
4031 
4032 function bounceIn(t) {
4033  return 1 - bounceOut(1 - t);
4034 }
4035 
4036 function bounceOut(t) {
4037  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;
4038 }
4039 
4040 function bounceInOut(t) {
4041  return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
4042 }
4043 
4044 var overshoot = 1.70158;
4045 
4046 var backIn = (function custom(s) {
4047  s = +s;
4048 
4049  function backIn(t) {
4050  return t * t * ((s + 1) * t - s);
4051  }
4052 
4053  backIn.overshoot = custom;
4054 
4055  return backIn;
4056 })(overshoot);
4057 
4058 var backOut = (function custom(s) {
4059  s = +s;
4060 
4061  function backOut(t) {
4062  return --t * t * ((s + 1) * t + s) + 1;
4063  }
4064 
4065  backOut.overshoot = custom;
4066 
4067  return backOut;
4068 })(overshoot);
4069 
4070 var backInOut = (function custom(s) {
4071  s = +s;
4072 
4073  function backInOut(t) {
4074  return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
4075  }
4076 
4077  backInOut.overshoot = custom;
4078 
4079  return backInOut;
4080 })(overshoot);
4081 
4082 var tau = 2 * Math.PI,
4083  amplitude = 1,
4084  period = 0.3;
4085 
4086 var elasticIn = (function custom(a, p) {
4087  var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4088 
4089  function elasticIn(t) {
4090  return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
4091  }
4092 
4093  elasticIn.amplitude = function(a) { return custom(a, p * tau); };
4094  elasticIn.period = function(p) { return custom(a, p); };
4095 
4096  return elasticIn;
4097 })(amplitude, period);
4098 
4099 var elasticOut = (function custom(a, p) {
4100  var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4101 
4102  function elasticOut(t) {
4103  return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
4104  }
4105 
4106  elasticOut.amplitude = function(a) { return custom(a, p * tau); };
4107  elasticOut.period = function(p) { return custom(a, p); };
4108 
4109  return elasticOut;
4110 })(amplitude, period);
4111 
4112 var elasticInOut = (function custom(a, p) {
4113  var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
4114 
4115  function elasticInOut(t) {
4116  return ((t = t * 2 - 1) < 0
4117  ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
4118  : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
4119  }
4120 
4121  elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
4122  elasticInOut.period = function(p) { return custom(a, p); };
4123 
4124  return elasticInOut;
4125 })(amplitude, period);
4126 
4127 var defaultTiming = {
4128  time: null, // Set on use.
4129  delay: 0,
4130  duration: 250,
4131  ease: cubicInOut
4132 };
4133 
4134 function inherit(node, id) {
4135  var timing;
4136  while (!(timing = node.__transition) || !(timing = timing[id])) {
4137  if (!(node = node.parentNode)) {
4138  return defaultTiming.time = now(), defaultTiming;
4139  }
4140  }
4141  return timing;
4142 }
4143 
4144 function selection_transition(name) {
4145  var id,
4146  timing;
4147 
4148  if (name instanceof Transition) {
4149  id = name._id, name = name._name;
4150  } else {
4151  id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
4152  }
4153 
4154  for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
4155  for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
4156  if (node = group[i]) {
4157  schedule(node, name, id, i, group, timing || inherit(node, id));
4158  }
4159  }
4160  }
4161 
4162  return new Transition(groups, this._parents, name, id);
4163 }
4164 
4165 selection.prototype.interrupt = selection_interrupt;
4166 selection.prototype.transition = selection_transition;
4167 
4168 var root$1 = [null];
4169 
4170 function active(node, name) {
4171  var schedules = node.__transition,
4172  schedule$$1,
4173  i;
4174 
4175  if (schedules) {
4176  name = name == null ? null : name + "";
4177  for (i in schedules) {
4178  if ((schedule$$1 = schedules[i]).state > SCHEDULED && schedule$$1.name === name) {
4179  return new Transition([[node]], root$1, name, +i);
4180  }
4181  }
4182  }
4183 
4184  return null;
4185 }
4186 
4187 function constant$4(x) {
4188  return function() {
4189  return x;
4190  };
4191 }
4192 
4193 function BrushEvent(target, type, selection) {
4194  this.target = target;
4195  this.type = type;
4196  this.selection = selection;
4197 }
4198 
4199 function nopropagation$1() {
4200  exports.event.stopImmediatePropagation();
4201 }
4202 
4203 function noevent$1() {
4204  exports.event.preventDefault();
4205  exports.event.stopImmediatePropagation();
4206 }
4207 
4208 var MODE_DRAG = {name: "drag"},
4209  MODE_SPACE = {name: "space"},
4210  MODE_HANDLE = {name: "handle"},
4211  MODE_CENTER = {name: "center"};
4212 
4213 var X = {
4214  name: "x",
4215  handles: ["e", "w"].map(type),
4216  input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
4217  output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
4218 };
4219 
4220 var Y = {
4221  name: "y",
4222  handles: ["n", "s"].map(type),
4223  input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
4224  output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
4225 };
4226 
4227 var XY = {
4228  name: "xy",
4229  handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
4230  input: function(xy) { return xy; },
4231  output: function(xy) { return xy; }
4232 };
4233 
4234 var cursors = {
4235  overlay: "crosshair",
4236  selection: "move",
4237  n: "ns-resize",
4238  e: "ew-resize",
4239  s: "ns-resize",
4240  w: "ew-resize",
4241  nw: "nwse-resize",
4242  ne: "nesw-resize",
4243  se: "nwse-resize",
4244  sw: "nesw-resize"
4245 };
4246 
4247 var flipX = {
4248  e: "w",
4249  w: "e",
4250  nw: "ne",
4251  ne: "nw",
4252  se: "sw",
4253  sw: "se"
4254 };
4255 
4256 var flipY = {
4257  n: "s",
4258  s: "n",
4259  nw: "sw",
4260  ne: "se",
4261  se: "ne",
4262  sw: "nw"
4263 };
4264 
4265 var signsX = {
4266  overlay: +1,
4267  selection: +1,
4268  n: null,
4269  e: +1,
4270  s: null,
4271  w: -1,
4272  nw: -1,
4273  ne: +1,
4274  se: +1,
4275  sw: -1
4276 };
4277 
4278 var signsY = {
4279  overlay: +1,
4280  selection: +1,
4281  n: -1,
4282  e: null,
4283  s: +1,
4284  w: null,
4285  nw: -1,
4286  ne: -1,
4287  se: +1,
4288  sw: +1
4289 };
4290 
4291 function type(t) {
4292  return {type: t};
4293 }
4294 
4295 // Ignore right-click, since that should open the context menu.
4296 function defaultFilter$1() {
4297  return !exports.event.button;
4298 }
4299 
4300 function defaultExtent() {
4301  var svg = this.ownerSVGElement || this;
4302  return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
4303 }
4304 
4305 // Like d3.local, but with the name “__brush” rather than auto-generated.
4306 function local$1(node) {
4307  while (!node.__brush) if (!(node = node.parentNode)) return;
4308  return node.__brush;
4309 }
4310 
4311 function empty$1(extent) {
4312  return extent[0][0] === extent[1][0]
4313  || extent[0][1] === extent[1][1];
4314 }
4315 
4316 function brushSelection(node) {
4317  var state = node.__brush;
4318  return state ? state.dim.output(state.selection) : null;
4319 }
4320 
4321 function brushX() {
4322  return brush$1(X);
4323 }
4324 
4325 function brushY() {
4326  return brush$1(Y);
4327 }
4328 
4329 function brush() {
4330  return brush$1(XY);
4331 }
4332 
4333 function brush$1(dim) {
4334  var extent = defaultExtent,
4335  filter = defaultFilter$1,
4336  listeners = dispatch(brush, "start", "brush", "end"),
4337  handleSize = 6,
4338  touchending;
4339 
4340  function brush(group) {
4341  var overlay = group
4342  .property("__brush", initialize)
4343  .selectAll(".overlay")
4344  .data([type("overlay")]);
4345 
4346  overlay.enter().append("rect")
4347  .attr("class", "overlay")
4348  .attr("pointer-events", "all")
4349  .attr("cursor", cursors.overlay)
4350  .merge(overlay)
4351  .each(function() {
4352  var extent = local$1(this).extent;
4353  select(this)
4354  .attr("x", extent[0][0])
4355  .attr("y", extent[0][1])
4356  .attr("width", extent[1][0] - extent[0][0])
4357  .attr("height", extent[1][1] - extent[0][1]);
4358  });
4359 
4360  group.selectAll(".selection")
4361  .data([type("selection")])
4362  .enter().append("rect")
4363  .attr("class", "selection")
4364  .attr("cursor", cursors.selection)
4365  .attr("fill", "#777")
4366  .attr("fill-opacity", 0.3)
4367  .attr("stroke", "#fff")
4368  .attr("shape-rendering", "crispEdges");
4369 
4370  var handle = group.selectAll(".handle")
4371  .data(dim.handles, function(d) { return d.type; });
4372 
4373  handle.exit().remove();
4374 
4375  handle.enter().append("rect")
4376  .attr("class", function(d) { return "handle handle--" + d.type; })
4377  .attr("cursor", function(d) { return cursors[d.type]; });
4378 
4379  group
4380  .each(redraw)
4381  .attr("fill", "none")
4382  .attr("pointer-events", "all")
4383  .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
4384  .on("mousedown.brush touchstart.brush", started);
4385  }
4386 
4387  brush.move = function(group, selection$$1) {
4388  if (group.selection) {
4389  group
4390  .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
4391  .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
4392  .tween("brush", function() {
4393  var that = this,
4394  state = that.__brush,
4395  emit = emitter(that, arguments),
4396  selection0 = state.selection,
4397  selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
4398  i = interpolateValue(selection0, selection1);
4399 
4400  function tween(t) {
4401  state.selection = t === 1 && empty$1(selection1) ? null : i(t);
4402  redraw.call(that);
4403  emit.brush();
4404  }
4405 
4406  return selection0 && selection1 ? tween : tween(1);
4407  });
4408  } else {
4409  group
4410  .each(function() {
4411  var that = this,
4412  args = arguments,
4413  state = that.__brush,
4414  selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
4415  emit = emitter(that, args).beforestart();
4416 
4417  interrupt(that);
4418  state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
4419  redraw.call(that);
4420  emit.start().brush().end();
4421  });
4422  }
4423  };
4424 
4425  function redraw() {
4426  var group = select(this),
4427  selection$$1 = local$1(this).selection;
4428 
4429  if (selection$$1) {
4430  group.selectAll(".selection")
4431  .style("display", null)
4432  .attr("x", selection$$1[0][0])
4433  .attr("y", selection$$1[0][1])
4434  .attr("width", selection$$1[1][0] - selection$$1[0][0])
4435  .attr("height", selection$$1[1][1] - selection$$1[0][1]);
4436 
4437  group.selectAll(".handle")
4438  .style("display", null)
4439  .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2; })
4440  .attr("y", function(d) { return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2; })
4441  .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize; })
4442  .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize; });
4443  }
4444 
4445  else {
4446  group.selectAll(".selection,.handle")
4447  .style("display", "none")
4448  .attr("x", null)
4449  .attr("y", null)
4450  .attr("width", null)
4451  .attr("height", null);
4452  }
4453  }
4454 
4455  function emitter(that, args) {
4456  return that.__brush.emitter || new Emitter(that, args);
4457  }
4458 
4459  function Emitter(that, args) {
4460  this.that = that;
4461  this.args = args;
4462  this.state = that.__brush;
4463  this.active = 0;
4464  }
4465 
4466  Emitter.prototype = {
4467  beforestart: function() {
4468  if (++this.active === 1) this.state.emitter = this, this.starting = true;
4469  return this;
4470  },
4471  start: function() {
4472  if (this.starting) this.starting = false, this.emit("start");
4473  return this;
4474  },
4475  brush: function() {
4476  this.emit("brush");
4477  return this;
4478  },
4479  end: function() {
4480  if (--this.active === 0) delete this.state.emitter, this.emit("end");
4481  return this;
4482  },
4483  emit: function(type) {
4484  customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
4485  }
4486  };
4487 
4488  function started() {
4489  if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$1(); }
4490  else if (touchending) return;
4491  if (!filter.apply(this, arguments)) return;
4492 
4493  var that = this,
4494  type = exports.event.target.__data__.type,
4495  mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
4496  signX = dim === Y ? null : signsX[type],
4497  signY = dim === X ? null : signsY[type],
4498  state = local$1(that),
4499  extent = state.extent,
4500  selection$$1 = state.selection,
4501  W = extent[0][0], w0, w1,
4502  N = extent[0][1], n0, n1,
4503  E = extent[1][0], e0, e1,
4504  S = extent[1][1], s0, s1,
4505  dx,
4506  dy,
4507  moving,
4508  shifting = signX && signY && exports.event.shiftKey,
4509  lockX,
4510  lockY,
4511  point0 = mouse(that),
4512  point$$1 = point0,
4513  emit = emitter(that, arguments).beforestart();
4514 
4515  if (type === "overlay") {
4516  state.selection = selection$$1 = [
4517  [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
4518  [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
4519  ];
4520  } else {
4521  w0 = selection$$1[0][0];
4522  n0 = selection$$1[0][1];
4523  e0 = selection$$1[1][0];
4524  s0 = selection$$1[1][1];
4525  }
4526 
4527  w1 = w0;
4528  n1 = n0;
4529  e1 = e0;
4530  s1 = s0;
4531 
4532  var group = select(that)
4533  .attr("pointer-events", "none");
4534 
4535  var overlay = group.selectAll(".overlay")
4536  .attr("cursor", cursors[type]);
4537 
4538  if (exports.event.touches) {
4539  group
4540  .on("touchmove.brush", moved, true)
4541  .on("touchend.brush touchcancel.brush", ended, true);
4542  } else {
4543  var view = select(exports.event.view)
4544  .on("keydown.brush", keydowned, true)
4545  .on("keyup.brush", keyupped, true)
4546  .on("mousemove.brush", moved, true)
4547  .on("mouseup.brush", ended, true);
4548 
4549  dragDisable(exports.event.view);
4550  }
4551 
4552  nopropagation$1();
4553  interrupt(that);
4554  redraw.call(that);
4555  emit.start();
4556 
4557  function moved() {
4558  var point1 = mouse(that);
4559  if (shifting && !lockX && !lockY) {
4560  if (Math.abs(point1[0] - point$$1[0]) > Math.abs(point1[1] - point$$1[1])) lockY = true;
4561  else lockX = true;
4562  }
4563  point$$1 = point1;
4564  moving = true;
4565  noevent$1();
4566  move();
4567  }
4568 
4569  function move() {
4570  var t;
4571 
4572  dx = point$$1[0] - point0[0];
4573  dy = point$$1[1] - point0[1];
4574 
4575  switch (mode) {
4576  case MODE_SPACE:
4577  case MODE_DRAG: {
4578  if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
4579  if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
4580  break;
4581  }
4582  case MODE_HANDLE: {
4583  if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
4584  else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
4585  if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
4586  else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
4587  break;
4588  }
4589  case MODE_CENTER: {
4590  if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
4591  if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
4592  break;
4593  }
4594  }
4595 
4596  if (e1 < w1) {
4597  signX *= -1;
4598  t = w0, w0 = e0, e0 = t;
4599  t = w1, w1 = e1, e1 = t;
4600  if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
4601  }
4602 
4603  if (s1 < n1) {
4604  signY *= -1;
4605  t = n0, n0 = s0, s0 = t;
4606  t = n1, n1 = s1, s1 = t;
4607  if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
4608  }
4609 
4610  if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
4611  if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
4612  if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
4613 
4614  if (selection$$1[0][0] !== w1
4615  || selection$$1[0][1] !== n1
4616  || selection$$1[1][0] !== e1
4617  || selection$$1[1][1] !== s1) {
4618  state.selection = [[w1, n1], [e1, s1]];
4619  redraw.call(that);
4620  emit.brush();
4621  }
4622  }
4623 
4624  function ended() {
4625  nopropagation$1();
4626  if (exports.event.touches) {
4627  if (exports.event.touches.length) return;
4628  if (touchending) clearTimeout(touchending);
4629  touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
4630  group.on("touchmove.brush touchend.brush touchcancel.brush", null);
4631  } else {
4632  yesdrag(exports.event.view, moving);
4633  view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
4634  }
4635  group.attr("pointer-events", "all");
4636  overlay.attr("cursor", cursors.overlay);
4637  if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
4638  if (empty$1(selection$$1)) state.selection = null, redraw.call(that);
4639  emit.end();
4640  }
4641 
4642  function keydowned() {
4643  switch (exports.event.keyCode) {
4644  case 16: { // SHIFT
4645  shifting = signX && signY;
4646  break;
4647  }
4648  case 18: { // ALT
4649  if (mode === MODE_HANDLE) {
4650  if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4651  if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4652  mode = MODE_CENTER;
4653  move();
4654  }
4655  break;
4656  }
4657  case 32: { // SPACE; takes priority over ALT
4658  if (mode === MODE_HANDLE || mode === MODE_CENTER) {
4659  if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
4660  if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
4661  mode = MODE_SPACE;
4662  overlay.attr("cursor", cursors.selection);
4663  move();
4664  }
4665  break;
4666  }
4667  default: return;
4668  }
4669  noevent$1();
4670  }
4671 
4672  function keyupped() {
4673  switch (exports.event.keyCode) {
4674  case 16: { // SHIFT
4675  if (shifting) {
4676  lockX = lockY = shifting = false;
4677  move();
4678  }
4679  break;
4680  }
4681  case 18: { // ALT
4682  if (mode === MODE_CENTER) {
4683  if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4684  if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4685  mode = MODE_HANDLE;
4686  move();
4687  }
4688  break;
4689  }
4690  case 32: { // SPACE
4691  if (mode === MODE_SPACE) {
4692  if (exports.event.altKey) {
4693  if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
4694  if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
4695  mode = MODE_CENTER;
4696  } else {
4697  if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
4698  if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
4699  mode = MODE_HANDLE;
4700  }
4701  overlay.attr("cursor", cursors[type]);
4702  move();
4703  }
4704  break;
4705  }
4706  default: return;
4707  }
4708  noevent$1();
4709  }
4710  }
4711 
4712  function initialize() {
4713  var state = this.__brush || {selection: null};
4714  state.extent = extent.apply(this, arguments);
4715  state.dim = dim;
4716  return state;
4717  }
4718 
4719  brush.extent = function(_) {
4720  return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
4721  };
4722 
4723  brush.filter = function(_) {
4724  return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
4725  };
4726 
4727  brush.handleSize = function(_) {
4728  return arguments.length ? (handleSize = +_, brush) : handleSize;
4729  };
4730 
4731  brush.on = function() {
4732  var value = listeners.on.apply(listeners, arguments);
4733  return value === listeners ? brush : value;
4734  };
4735 
4736  return brush;
4737 }
4738 
4739 var cos = Math.cos;
4740 var sin = Math.sin;
4741 var pi$1 = Math.PI;
4742 var halfPi$1 = pi$1 / 2;
4743 var tau$1 = pi$1 * 2;
4744 var max$1 = Math.max;
4745 
4746 function compareValue(compare) {
4747  return function(a, b) {
4748  return compare(
4749  a.source.value + a.target.value,
4750  b.source.value + b.target.value
4751  );
4752  };
4753 }
4754 
4755 function chord() {
4756  var padAngle = 0,
4757  sortGroups = null,
4758  sortSubgroups = null,
4759  sortChords = null;
4760 
4761  function chord(matrix) {
4762  var n = matrix.length,
4763  groupSums = [],
4764  groupIndex = sequence(n),
4765  subgroupIndex = [],
4766  chords = [],
4767  groups = chords.groups = new Array(n),
4768  subgroups = new Array(n * n),
4769  k,
4770  x,
4771  x0,
4772  dx,
4773  i,
4774  j;
4775 
4776  // Compute the sum.
4777  k = 0, i = -1; while (++i < n) {
4778  x = 0, j = -1; while (++j < n) {
4779  x += matrix[i][j];
4780  }
4781  groupSums.push(x);
4782  subgroupIndex.push(sequence(n));
4783  k += x;
4784  }
4785 
4786  // Sort groups…
4787  if (sortGroups) groupIndex.sort(function(a, b) {
4788  return sortGroups(groupSums[a], groupSums[b]);
4789  });
4790 
4791  // Sort subgroups…
4792  if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
4793  d.sort(function(a, b) {
4794  return sortSubgroups(matrix[i][a], matrix[i][b]);
4795  });
4796  });
4797 
4798  // Convert the sum to scaling factor for [0, 2pi].
4799  // TODO Allow start and end angle to be specified?
4800  // TODO Allow padding to be specified as percentage?
4801  k = max$1(0, tau$1 - padAngle * n) / k;
4802  dx = k ? padAngle : tau$1 / n;
4803 
4804  // Compute the start and end angle for each group and subgroup.
4805  // Note: Opera has a bug reordering object literal properties!
4806  x = 0, i = -1; while (++i < n) {
4807  x0 = x, j = -1; while (++j < n) {
4808  var di = groupIndex[i],
4809  dj = subgroupIndex[di][j],
4810  v = matrix[di][dj],
4811  a0 = x,
4812  a1 = x += v * k;
4813  subgroups[dj * n + di] = {
4814  index: di,
4815  subindex: dj,
4816  startAngle: a0,
4817  endAngle: a1,
4818  value: v
4819  };
4820  }
4821  groups[di] = {
4822  index: di,
4823  startAngle: x0,
4824  endAngle: x,
4825  value: groupSums[di]
4826  };
4827  x += dx;
4828  }
4829 
4830  // Generate chords for each (non-empty) subgroup-subgroup link.
4831  i = -1; while (++i < n) {
4832  j = i - 1; while (++j < n) {
4833  var source = subgroups[j * n + i],
4834  target = subgroups[i * n + j];
4835  if (source.value || target.value) {
4836  chords.push(source.value < target.value
4837  ? {source: target, target: source}
4838  : {source: source, target: target});
4839  }
4840  }
4841  }
4842 
4843  return sortChords ? chords.sort(sortChords) : chords;
4844  }
4845 
4846  chord.padAngle = function(_) {
4847  return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
4848  };
4849 
4850  chord.sortGroups = function(_) {
4851  return arguments.length ? (sortGroups = _, chord) : sortGroups;
4852  };
4853 
4854  chord.sortSubgroups = function(_) {
4855  return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
4856  };
4857 
4858  chord.sortChords = function(_) {
4859  return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
4860  };
4861 
4862  return chord;
4863 }
4864 
4865 var slice$2 = Array.prototype.slice;
4866 
4867 function constant$5(x) {
4868  return function() {
4869  return x;
4870  };
4871 }
4872 
4873 var pi$2 = Math.PI,
4874  tau$2 = 2 * pi$2,
4875  epsilon$1 = 1e-6,
4876  tauEpsilon = tau$2 - epsilon$1;
4877 
4878 function Path() {
4879  this._x0 = this._y0 = // start of current subpath
4880  this._x1 = this._y1 = null; // end of current subpath
4881  this._ = "";
4882 }
4883 
4884 function path() {
4885  return new Path;
4886 }
4887 
4888 Path.prototype = path.prototype = {
4889  constructor: Path,
4890  moveTo: function(x, y) {
4891  this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
4892  },
4893  closePath: function() {
4894  if (this._x1 !== null) {
4895  this._x1 = this._x0, this._y1 = this._y0;
4896  this._ += "Z";
4897  }
4898  },
4899  lineTo: function(x, y) {
4900  this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
4901  },
4902  quadraticCurveTo: function(x1, y1, x, y) {
4903  this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4904  },
4905  bezierCurveTo: function(x1, y1, x2, y2, x, y) {
4906  this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
4907  },
4908  arcTo: function(x1, y1, x2, y2, r) {
4909  x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
4910  var x0 = this._x1,
4911  y0 = this._y1,
4912  x21 = x2 - x1,
4913  y21 = y2 - y1,
4914  x01 = x0 - x1,
4915  y01 = y0 - y1,
4916  l01_2 = x01 * x01 + y01 * y01;
4917 
4918  // Is the radius negative? Error.
4919  if (r < 0) throw new Error("negative radius: " + r);
4920 
4921  // Is this path empty? Move to (x1,y1).
4922  if (this._x1 === null) {
4923  this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
4924  }
4925 
4926  // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
4927  else if (!(l01_2 > epsilon$1));
4928 
4929  // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
4930  // Equivalently, is (x1,y1) coincident with (x2,y2)?
4931  // Or, is the radius zero? Line to (x1,y1).
4932  else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
4933  this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
4934  }
4935 
4936  // Otherwise, draw an arc!
4937  else {
4938  var x20 = x2 - x0,
4939  y20 = y2 - y0,
4940  l21_2 = x21 * x21 + y21 * y21,
4941  l20_2 = x20 * x20 + y20 * y20,
4942  l21 = Math.sqrt(l21_2),
4943  l01 = Math.sqrt(l01_2),
4944  l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
4945  t01 = l / l01,
4946  t21 = l / l21;
4947 
4948  // If the start tangent is not coincident with (x0,y0), line to.
4949  if (Math.abs(t01 - 1) > epsilon$1) {
4950  this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
4951  }
4952 
4953  this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
4954  }
4955  },
4956  arc: function(x, y, r, a0, a1, ccw) {
4957  x = +x, y = +y, r = +r;
4958  var dx = r * Math.cos(a0),
4959  dy = r * Math.sin(a0),
4960  x0 = x + dx,
4961  y0 = y + dy,
4962  cw = 1 ^ ccw,
4963  da = ccw ? a0 - a1 : a1 - a0;
4964 
4965  // Is the radius negative? Error.
4966  if (r < 0) throw new Error("negative radius: " + r);
4967 
4968  // Is this path empty? Move to (x0,y0).
4969  if (this._x1 === null) {
4970  this._ += "M" + x0 + "," + y0;
4971  }
4972 
4973  // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
4974  else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
4975  this._ += "L" + x0 + "," + y0;
4976  }
4977 
4978  // Is this arc empty? We’re done.
4979  if (!r) return;
4980 
4981  // Does the angle go the wrong way? Flip the direction.
4982  if (da < 0) da = da % tau$2 + tau$2;
4983 
4984  // Is this a complete circle? Draw two arcs to complete the circle.
4985  if (da > tauEpsilon) {
4986  this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
4987  }
4988 
4989  // Is this arc non-empty? Draw an arc!
4990  else if (da > epsilon$1) {
4991  this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
4992  }
4993  },
4994  rect: function(x, y, w, h) {
4995  this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
4996  },
4997  toString: function() {
4998  return this._;
4999  }
5000 };
5001 
5002 function defaultSource(d) {
5003  return d.source;
5004 }
5005 
5006 function defaultTarget(d) {
5007  return d.target;
5008 }
5009 
5010 function defaultRadius(d) {
5011  return d.radius;
5012 }
5013 
5014 function defaultStartAngle(d) {
5015  return d.startAngle;
5016 }
5017 
5018 function defaultEndAngle(d) {
5019  return d.endAngle;
5020 }
5021 
5022 function ribbon() {
5023  var source = defaultSource,
5024  target = defaultTarget,
5025  radius = defaultRadius,
5026  startAngle = defaultStartAngle,
5027  endAngle = defaultEndAngle,
5028  context = null;
5029 
5030  function ribbon() {
5031  var buffer,
5032  argv = slice$2.call(arguments),
5033  s = source.apply(this, argv),
5034  t = target.apply(this, argv),
5035  sr = +radius.apply(this, (argv[0] = s, argv)),
5036  sa0 = startAngle.apply(this, argv) - halfPi$1,
5037  sa1 = endAngle.apply(this, argv) - halfPi$1,
5038  sx0 = sr * cos(sa0),
5039  sy0 = sr * sin(sa0),
5040  tr = +radius.apply(this, (argv[0] = t, argv)),
5041  ta0 = startAngle.apply(this, argv) - halfPi$1,
5042  ta1 = endAngle.apply(this, argv) - halfPi$1;
5043 
5044  if (!context) context = buffer = path();
5045 
5046  context.moveTo(sx0, sy0);
5047  context.arc(0, 0, sr, sa0, sa1);
5048  if (sa0 !== ta0 || sa1 !== ta1) { // TODO sr !== tr?
5049  context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
5050  context.arc(0, 0, tr, ta0, ta1);
5051  }
5052  context.quadraticCurveTo(0, 0, sx0, sy0);
5053  context.closePath();
5054 
5055  if (buffer) return context = null, buffer + "" || null;
5056  }
5057 
5058  ribbon.radius = function(_) {
5059  return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
5060  };
5061 
5062  ribbon.startAngle = function(_) {
5063  return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
5064  };
5065 
5066  ribbon.endAngle = function(_) {
5067  return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
5068  };
5069 
5070  ribbon.source = function(_) {
5071  return arguments.length ? (source = _, ribbon) : source;
5072  };
5073 
5074  ribbon.target = function(_) {
5075  return arguments.length ? (target = _, ribbon) : target;
5076  };
5077 
5078  ribbon.context = function(_) {
5079  return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
5080  };
5081 
5082  return ribbon;
5083 }
5084 
5085 var prefix = "$";
5086 
5087 function Map() {}
5088 
5089 Map.prototype = map$1.prototype = {
5090  constructor: Map,
5091  has: function(key) {
5092  return (prefix + key) in this;
5093  },
5094  get: function(key) {
5095  return this[prefix + key];
5096  },
5097  set: function(key, value) {
5098  this[prefix + key] = value;
5099  return this;
5100  },
5101  remove: function(key) {
5102  var property = prefix + key;
5103  return property in this && delete this[property];
5104  },
5105  clear: function() {
5106  for (var property in this) if (property[0] === prefix) delete this[property];
5107  },
5108  keys: function() {
5109  var keys = [];
5110  for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
5111  return keys;
5112  },
5113  values: function() {
5114  var values = [];
5115  for (var property in this) if (property[0] === prefix) values.push(this[property]);
5116  return values;
5117  },
5118  entries: function() {
5119  var entries = [];
5120  for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
5121  return entries;
5122  },
5123  size: function() {
5124  var size = 0;
5125  for (var property in this) if (property[0] === prefix) ++size;
5126  return size;
5127  },
5128  empty: function() {
5129  for (var property in this) if (property[0] === prefix) return false;
5130  return true;
5131  },
5132  each: function(f) {
5133  for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
5134  }
5135 };
5136 
5137 function map$1(object, f) {
5138  var map = new Map;
5139 
5140  // Copy constructor.
5141  if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
5142 
5143  // Index array by numeric index or specified key function.
5144  else if (Array.isArray(object)) {
5145  var i = -1,
5146  n = object.length,
5147  o;
5148 
5149  if (f == null) while (++i < n) map.set(i, object[i]);
5150  else while (++i < n) map.set(f(o = object[i], i, object), o);
5151  }
5152 
5153  // Convert object to map.
5154  else if (object) for (var key in object) map.set(key, object[key]);
5155 
5156  return map;
5157 }
5158 
5159 function nest() {
5160  var keys = [],
5161  sortKeys = [],
5162  sortValues,
5163  rollup,
5164  nest;
5165 
5166  function apply(array, depth, createResult, setResult) {
5167  if (depth >= keys.length) {
5168  if (sortValues != null) array.sort(sortValues);
5169  return rollup != null ? rollup(array) : array;
5170  }
5171 
5172  var i = -1,
5173  n = array.length,
5174  key = keys[depth++],
5175  keyValue,
5176  value,
5177  valuesByKey = map$1(),
5178  values,
5179  result = createResult();
5180 
5181  while (++i < n) {
5182  if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
5183  values.push(value);
5184  } else {
5185  valuesByKey.set(keyValue, [value]);
5186  }
5187  }
5188 
5189  valuesByKey.each(function(values, key) {
5190  setResult(result, key, apply(values, depth, createResult, setResult));
5191  });
5192 
5193  return result;
5194  }
5195 
5196  function entries(map, depth) {
5197  if (++depth > keys.length) return map;
5198  var array, sortKey = sortKeys[depth - 1];
5199  if (rollup != null && depth >= keys.length) array = map.entries();
5200  else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
5201  return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
5202  }
5203 
5204  return nest = {
5205  object: function(array) { return apply(array, 0, createObject, setObject); },
5206  map: function(array) { return apply(array, 0, createMap, setMap); },
5207  entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
5208  key: function(d) { keys.push(d); return nest; },
5209  sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
5210  sortValues: function(order) { sortValues = order; return nest; },
5211  rollup: function(f) { rollup = f; return nest; }
5212  };
5213 }
5214 
5215 function createObject() {
5216  return {};
5217 }
5218 
5219 function setObject(object, key, value) {
5220  object[key] = value;
5221 }
5222 
5223 function createMap() {
5224  return map$1();
5225 }
5226 
5227 function setMap(map, key, value) {
5228  map.set(key, value);
5229 }
5230 
5231 function Set() {}
5232 
5233 var proto = map$1.prototype;
5234 
5235 Set.prototype = set$2.prototype = {
5236  constructor: Set,
5237  has: proto.has,
5238  add: function(value) {
5239  value += "";
5240  this[prefix + value] = value;
5241  return this;
5242  },
5243  remove: proto.remove,
5244  clear: proto.clear,
5245  values: proto.keys,
5246  size: proto.size,
5247  empty: proto.empty,
5248  each: proto.each
5249 };
5250 
5251 function set$2(object, f) {
5252  var set = new Set;
5253 
5254  // Copy constructor.
5255  if (object instanceof Set) object.each(function(value) { set.add(value); });
5256 
5257  // Otherwise, assume it’s an array.
5258  else if (object) {
5259  var i = -1, n = object.length;
5260  if (f == null) while (++i < n) set.add(object[i]);
5261  else while (++i < n) set.add(f(object[i], i, object));
5262  }
5263 
5264  return set;
5265 }
5266 
5267 function keys(map) {
5268  var keys = [];
5269  for (var key in map) keys.push(key);
5270  return keys;
5271 }
5272 
5273 function values(map) {
5274  var values = [];
5275  for (var key in map) values.push(map[key]);
5276  return values;
5277 }
5278 
5279 function entries(map) {
5280  var entries = [];
5281  for (var key in map) entries.push({key: key, value: map[key]});
5282  return entries;
5283 }
5284 
5285 var array$2 = Array.prototype;
5286 
5287 var slice$3 = array$2.slice;
5288 
5289 function ascending$2(a, b) {
5290  return a - b;
5291 }
5292 
5293 function area(ring) {
5294  var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
5295  while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
5296  return area;
5297 }
5298 
5299 function constant$6(x) {
5300  return function() {
5301  return x;
5302  };
5303 }
5304 
5305 function contains(ring, hole) {
5306  var i = -1, n = hole.length, c;
5307  while (++i < n) if (c = ringContains(ring, hole[i])) return c;
5308  return 0;
5309 }
5310 
5311 function ringContains(ring, point) {
5312  var x = point[0], y = point[1], contains = -1;
5313  for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
5314  var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
5315  if (segmentContains(pi, pj, point)) return 0;
5316  if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
5317  }
5318  return contains;
5319 }
5320 
5321 function segmentContains(a, b, c) {
5322  var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
5323 }
5324 
5325 function collinear(a, b, c) {
5326  return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
5327 }
5328 
5329 function within(p, q, r) {
5330  return p <= q && q <= r || r <= q && q <= p;
5331 }
5332 
5333 function noop$1() {}
5334 
5335 var cases = [
5336  [],
5337  [[[1.0, 1.5], [0.5, 1.0]]],
5338  [[[1.5, 1.0], [1.0, 1.5]]],
5339  [[[1.5, 1.0], [0.5, 1.0]]],
5340  [[[1.0, 0.5], [1.5, 1.0]]],
5341  [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
5342  [[[1.0, 0.5], [1.0, 1.5]]],
5343  [[[1.0, 0.5], [0.5, 1.0]]],
5344  [[[0.5, 1.0], [1.0, 0.5]]],
5345  [[[1.0, 1.5], [1.0, 0.5]]],
5346  [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
5347  [[[1.5, 1.0], [1.0, 0.5]]],
5348  [[[0.5, 1.0], [1.5, 1.0]]],
5349  [[[1.0, 1.5], [1.5, 1.0]]],
5350  [[[0.5, 1.0], [1.0, 1.5]]],
5351  []
5352 ];
5353 
5354 function contours() {
5355  var dx = 1,
5356  dy = 1,
5357  threshold$$1 = thresholdSturges,
5358  smooth = smoothLinear;
5359 
5360  function contours(values) {
5361  var tz = threshold$$1(values);
5362 
5363  // Convert number of thresholds into uniform thresholds.
5364  if (!Array.isArray(tz)) {
5365  var domain = extent(values), start = domain[0], stop = domain[1];
5366  tz = tickStep(start, stop, tz);
5367  tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
5368  } else {
5369  tz = tz.slice().sort(ascending$2);
5370  }
5371 
5372  return tz.map(function(value) {
5373  return contour(values, value);
5374  });
5375  }
5376 
5377  // Accumulate, smooth contour rings, assign holes to exterior rings.
5378  // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
5379  function contour(values, value) {
5380  var polygons = [],
5381  holes = [];
5382 
5383  isorings(values, value, function(ring) {
5384  smooth(ring, values, value);
5385  if (area(ring) > 0) polygons.push([ring]);
5386  else holes.push(ring);
5387  });
5388 
5389  holes.forEach(function(hole) {
5390  for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
5391  if (contains((polygon = polygons[i])[0], hole) !== -1) {
5392  polygon.push(hole);
5393  return;
5394  }
5395  }
5396  });
5397 
5398  return {
5399  type: "MultiPolygon",
5400  value: value,
5401  coordinates: polygons
5402  };
5403  }
5404 
5405  // Marching squares with isolines stitched into rings.
5406  // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
5407  function isorings(values, value, callback) {
5408  var fragmentByStart = new Array,
5409  fragmentByEnd = new Array,
5410  x, y, t0, t1, t2, t3;
5411 
5412  // Special case for the first row (y = -1, t2 = t3 = 0).
5413  x = y = -1;
5414  t1 = values[0] >= value;
5415  cases[t1 << 1].forEach(stitch);
5416  while (++x < dx - 1) {
5417  t0 = t1, t1 = values[x + 1] >= value;
5418  cases[t0 | t1 << 1].forEach(stitch);
5419  }
5420  cases[t1 << 0].forEach(stitch);
5421 
5422  // General case for the intermediate rows.
5423  while (++y < dy - 1) {
5424  x = -1;
5425  t1 = values[y * dx + dx] >= value;
5426  t2 = values[y * dx] >= value;
5427  cases[t1 << 1 | t2 << 2].forEach(stitch);
5428  while (++x < dx - 1) {
5429  t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
5430  t3 = t2, t2 = values[y * dx + x + 1] >= value;
5431  cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
5432  }
5433  cases[t1 | t2 << 3].forEach(stitch);
5434  }
5435 
5436  // Special case for the last row (y = dy - 1, t0 = t1 = 0).
5437  x = -1;
5438  t2 = values[y * dx] >= value;
5439  cases[t2 << 2].forEach(stitch);
5440  while (++x < dx - 1) {
5441  t3 = t2, t2 = values[y * dx + x + 1] >= value;
5442  cases[t2 << 2 | t3 << 3].forEach(stitch);
5443  }
5444  cases[t2 << 3].forEach(stitch);
5445 
5446  function stitch(line) {
5447  var start = [line[0][0] + x, line[0][1] + y],
5448  end = [line[1][0] + x, line[1][1] + y],
5449  startIndex = index(start),
5450  endIndex = index(end),
5451  f, g;
5452  if (f = fragmentByEnd[startIndex]) {
5453  if (g = fragmentByStart[endIndex]) {
5454  delete fragmentByEnd[f.end];
5455  delete fragmentByStart[g.start];
5456  if (f === g) {
5457  f.ring.push(end);
5458  callback(f.ring);
5459  } else {
5460  fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
5461  }
5462  } else {
5463  delete fragmentByEnd[f.end];
5464  f.ring.push(end);
5465  fragmentByEnd[f.end = endIndex] = f;
5466  }
5467  } else if (f = fragmentByStart[endIndex]) {
5468  if (g = fragmentByEnd[startIndex]) {
5469  delete fragmentByStart[f.start];
5470  delete fragmentByEnd[g.end];
5471  if (f === g) {
5472  f.ring.push(end);
5473  callback(f.ring);
5474  } else {
5475  fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
5476  }
5477  } else {
5478  delete fragmentByStart[f.start];
5479  f.ring.unshift(start);
5480  fragmentByStart[f.start = startIndex] = f;
5481  }
5482  } else {
5483  fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
5484  }
5485  }
5486  }
5487 
5488  function index(point) {
5489  return point[0] * 2 + point[1] * (dx + 1) * 4;
5490  }
5491 
5492  function smoothLinear(ring, values, value) {
5493  ring.forEach(function(point) {
5494  var x = point[0],
5495  y = point[1],
5496  xt = x | 0,
5497  yt = y | 0,
5498  v0,
5499  v1 = values[yt * dx + xt];
5500  if (x > 0 && x < dx && xt === x) {
5501  v0 = values[yt * dx + xt - 1];
5502  point[0] = x + (value - v0) / (v1 - v0) - 0.5;
5503  }
5504  if (y > 0 && y < dy && yt === y) {
5505  v0 = values[(yt - 1) * dx + xt];
5506  point[1] = y + (value - v0) / (v1 - v0) - 0.5;
5507  }
5508  });
5509  }
5510 
5511  contours.contour = contour;
5512 
5513  contours.size = function(_) {
5514  if (!arguments.length) return [dx, dy];
5515  var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
5516  if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
5517  return dx = _0, dy = _1, contours;
5518  };
5519 
5520  contours.thresholds = function(_) {
5521  return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold$$1;
5522  };
5523 
5524  contours.smooth = function(_) {
5525  return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
5526  };
5527 
5528  return contours;
5529 }
5530 
5531 // TODO Optimize edge cases.
5532 // TODO Optimize index calculation.
5533 // TODO Optimize arguments.
5534 function blurX(source, target, r) {
5535  var n = source.width,
5536  m = source.height,
5537  w = (r << 1) + 1;
5538  for (var j = 0; j < m; ++j) {
5539  for (var i = 0, sr = 0; i < n + r; ++i) {
5540  if (i < n) {
5541  sr += source.data[i + j * n];
5542  }
5543  if (i >= r) {
5544  if (i >= w) {
5545  sr -= source.data[i - w + j * n];
5546  }
5547  target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
5548  }
5549  }
5550  }
5551 }
5552 
5553 // TODO Optimize edge cases.
5554 // TODO Optimize index calculation.
5555 // TODO Optimize arguments.
5556 function blurY(source, target, r) {
5557  var n = source.width,
5558  m = source.height,
5559  w = (r << 1) + 1;
5560  for (var i = 0; i < n; ++i) {
5561  for (var j = 0, sr = 0; j < m + r; ++j) {
5562  if (j < m) {
5563  sr += source.data[i + j * n];
5564  }
5565  if (j >= r) {
5566  if (j >= w) {
5567  sr -= source.data[i + (j - w) * n];
5568  }
5569  target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
5570  }
5571  }
5572  }
5573 }
5574 
5575 function defaultX(d) {
5576  return d[0];
5577 }
5578 
5579 function defaultY(d) {
5580  return d[1];
5581 }
5582 
5583 function defaultWeight() {
5584  return 1;
5585 }
5586 
5587 function density() {
5588  var x = defaultX,
5589  y = defaultY,
5590  weight = defaultWeight,
5591  dx = 960,
5592  dy = 500,
5593  r = 20, // blur radius
5594  k = 2, // log2(grid cell size)
5595  o = r * 3, // grid offset, to pad for blur
5596  n = (dx + o * 2) >> k, // grid width
5597  m = (dy + o * 2) >> k, // grid height
5598  threshold$$1 = constant$6(20);
5599 
5600  function density(data) {
5601  var values0 = new Float32Array(n * m),
5602  values1 = new Float32Array(n * m);
5603 
5604  data.forEach(function(d, i, data) {
5605  var xi = (+x(d, i, data) + o) >> k,
5606  yi = (+y(d, i, data) + o) >> k,
5607  wi = +weight(d, i, data);
5608  if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
5609  values0[xi + yi * n] += wi;
5610  }
5611  });
5612 
5613  // TODO Optimize.
5614  blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5615  blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5616  blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5617  blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5618  blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
5619  blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
5620 
5621  var tz = threshold$$1(values0);
5622 
5623  // Convert number of thresholds into uniform thresholds.
5624  if (!Array.isArray(tz)) {
5625  var stop = max(values0);
5626  tz = tickStep(0, stop, tz);
5627  tz = sequence(0, Math.floor(stop / tz) * tz, tz);
5628  tz.shift();
5629  }
5630 
5631  return contours()
5632  .thresholds(tz)
5633  .size([n, m])
5634  (values0)
5635  .map(transform);
5636  }
5637 
5638  function transform(geometry) {
5639  geometry.value *= Math.pow(2, -2 * k); // Density in points per square pixel.
5640  geometry.coordinates.forEach(transformPolygon);
5641  return geometry;
5642  }
5643 
5644  function transformPolygon(coordinates) {
5645  coordinates.forEach(transformRing);
5646  }
5647 
5648  function transformRing(coordinates) {
5649  coordinates.forEach(transformPoint);
5650  }
5651 
5652  // TODO Optimize.
5653  function transformPoint(coordinates) {
5654  coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
5655  coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
5656  }
5657 
5658  function resize() {
5659  o = r * 3;
5660  n = (dx + o * 2) >> k;
5661  m = (dy + o * 2) >> k;
5662  return density;
5663  }
5664 
5665  density.x = function(_) {
5666  return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
5667  };
5668 
5669  density.y = function(_) {
5670  return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
5671  };
5672 
5673  density.weight = function(_) {
5674  return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
5675  };
5676 
5677  density.size = function(_) {
5678  if (!arguments.length) return [dx, dy];
5679  var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
5680  if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
5681  return dx = _0, dy = _1, resize();
5682  };
5683 
5684  density.cellSize = function(_) {
5685  if (!arguments.length) return 1 << k;
5686  if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
5687  return k = Math.floor(Math.log(_) / Math.LN2), resize();
5688  };
5689 
5690  density.thresholds = function(_) {
5691  return arguments.length ? (threshold$$1 = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold$$1;
5692  };
5693 
5694  density.bandwidth = function(_) {
5695  if (!arguments.length) return Math.sqrt(r * (r + 1));
5696  if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
5697  return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
5698  };
5699 
5700  return density;
5701 }
5702 
5703 var EOL = {},
5704  EOF = {},
5705  QUOTE = 34,
5706  NEWLINE = 10,
5707  RETURN = 13;
5708 
5709 function objectConverter(columns) {
5710  return new Function("d", "return {" + columns.map(function(name, i) {
5711  return JSON.stringify(name) + ": d[" + i + "]";
5712  }).join(",") + "}");
5713 }
5714 
5715 function customConverter(columns, f) {
5716  var object = objectConverter(columns);
5717  return function(row, i) {
5718  return f(object(row), i, columns);
5719  };
5720 }
5721 
5722 // Compute unique columns in order of discovery.
5723 function inferColumns(rows) {
5724  var columnSet = Object.create(null),
5725  columns = [];
5726 
5727  rows.forEach(function(row) {
5728  for (var column in row) {
5729  if (!(column in columnSet)) {
5730  columns.push(columnSet[column] = column);
5731  }
5732  }
5733  });
5734 
5735  return columns;
5736 }
5737 
5738 function dsvFormat(delimiter) {
5739  var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
5740  DELIMITER = delimiter.charCodeAt(0);
5741 
5742  function parse(text, f) {
5743  var convert, columns, rows = parseRows(text, function(row, i) {
5744  if (convert) return convert(row, i - 1);
5745  columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
5746  });
5747  rows.columns = columns || [];
5748  return rows;
5749  }
5750 
5751  function parseRows(text, f) {
5752  var rows = [], // output rows
5753  N = text.length,
5754  I = 0, // current character index
5755  n = 0, // current line number
5756  t, // current token
5757  eof = N <= 0, // current token followed by EOF?
5758  eol = false; // current token followed by EOL?
5759 
5760  // Strip the trailing newline.
5761  if (text.charCodeAt(N - 1) === NEWLINE) --N;
5762  if (text.charCodeAt(N - 1) === RETURN) --N;
5763 
5764  function token() {
5765  if (eof) return EOF;
5766  if (eol) return eol = false, EOL;
5767 
5768  // Unescape quotes.
5769  var i, j = I, c;
5770  if (text.charCodeAt(j) === QUOTE) {
5771  while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
5772  if ((i = I) >= N) eof = true;
5773  else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
5774  else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5775  return text.slice(j + 1, i - 1).replace(/""/g, "\"");
5776  }
5777 
5778  // Find next delimiter or newline.
5779  while (I < N) {
5780  if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
5781  else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
5782  else if (c !== DELIMITER) continue;
5783  return text.slice(j, i);
5784  }
5785 
5786  // Return last token before EOF.
5787  return eof = true, text.slice(j, N);
5788  }
5789 
5790  while ((t = token()) !== EOF) {
5791  var row = [];
5792  while (t !== EOL && t !== EOF) row.push(t), t = token();
5793  if (f && (row = f(row, n++)) == null) continue;
5794  rows.push(row);
5795  }
5796 
5797  return rows;
5798  }
5799 
5800  function format(rows, columns) {
5801  if (columns == null) columns = inferColumns(rows);
5802  return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
5803  return columns.map(function(column) {
5804  return formatValue(row[column]);
5805  }).join(delimiter);
5806  })).join("\n");
5807  }
5808 
5809  function formatRows(rows) {
5810  return rows.map(formatRow).join("\n");
5811  }
5812 
5813  function formatRow(row) {
5814  return row.map(formatValue).join(delimiter);
5815  }
5816 
5817  function formatValue(text) {
5818  return text == null ? ""
5819  : reFormat.test(text += "") ? "\"" + text.replace(/"/g, "\"\"") + "\""
5820  : text;
5821  }
5822 
5823  return {
5824  parse: parse,
5825  parseRows: parseRows,
5826  format: format,
5827  formatRows: formatRows
5828  };
5829 }
5830 
5831 var csv = dsvFormat(",");
5832 
5833 var csvParse = csv.parse;
5834 var csvParseRows = csv.parseRows;
5835 var csvFormat = csv.format;
5836 var csvFormatRows = csv.formatRows;
5837 
5838 var tsv = dsvFormat("\t");
5839 
5840 var tsvParse = tsv.parse;
5841 var tsvParseRows = tsv.parseRows;
5842 var tsvFormat = tsv.format;
5843 var tsvFormatRows = tsv.formatRows;
5844 
5845 function responseBlob(response) {
5846  if (!response.ok) throw new Error(response.status + " " + response.statusText);
5847  return response.blob();
5848 }
5849 
5850 function blob(input, init) {
5851  return fetch(input, init).then(responseBlob);
5852 }
5853 
5854 function responseArrayBuffer(response) {
5855  if (!response.ok) throw new Error(response.status + " " + response.statusText);
5856  return response.arrayBuffer();
5857 }
5858 
5859 function buffer(input, init) {
5860  return fetch(input, init).then(responseArrayBuffer);
5861 }
5862 
5863 function responseText(response) {
5864  if (!response.ok) throw new Error(response.status + " " + response.statusText);
5865  return response.text();
5866 }
5867 
5868 function text(input, init) {
5869  return fetch(input, init).then(responseText);
5870 }
5871 
5872 function dsvParse(parse) {
5873  return function(input, init, row) {
5874  if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
5875  return text(input, init).then(function(response) {
5876  return parse(response, row);
5877  });
5878  };
5879 }
5880 
5881 function dsv(delimiter, input, init, row) {
5882  if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
5883  var format = dsvFormat(delimiter);
5884  return text(input, init).then(function(response) {
5885  return format.parse(response, row);
5886  });
5887 }
5888 
5889 var csv$1 = dsvParse(csvParse);
5890 var tsv$1 = dsvParse(tsvParse);
5891 
5892 function image(input, init) {
5893  return new Promise(function(resolve, reject) {
5894  var image = new Image;
5895  for (var key in init) image[key] = init[key];
5896  image.onerror = reject;
5897  image.onload = function() { resolve(image); };
5898  image.src = input;
5899  });
5900 }
5901 
5902 function responseJson(response) {
5903  if (!response.ok) throw new Error(response.status + " " + response.statusText);
5904  return response.json();
5905 }
5906 
5907 function json(input, init) {
5908  return fetch(input, init).then(responseJson);
5909 }
5910 
5911 function parser(type) {
5912  return function(input, init) {
5913  return text(input, init).then(function(text$$1) {
5914  return (new DOMParser).parseFromString(text$$1, type);
5915  });
5916  };
5917 }
5918 
5919 var xml = parser("application/xml");
5920 
5921 var html = parser("text/html");
5922 
5923 var svg = parser("image/svg+xml");
5924 
5925 function center$1(x, y) {
5926  var nodes;
5927 
5928  if (x == null) x = 0;
5929  if (y == null) y = 0;
5930 
5931  function force() {
5932  var i,
5933  n = nodes.length,
5934  node,
5935  sx = 0,
5936  sy = 0;
5937 
5938  for (i = 0; i < n; ++i) {
5939  node = nodes[i], sx += node.x, sy += node.y;
5940  }
5941 
5942  for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
5943  node = nodes[i], node.x -= sx, node.y -= sy;
5944  }
5945  }
5946 
5947  force.initialize = function(_) {
5948  nodes = _;
5949  };
5950 
5951  force.x = function(_) {
5952  return arguments.length ? (x = +_, force) : x;
5953  };
5954 
5955  force.y = function(_) {
5956  return arguments.length ? (y = +_, force) : y;
5957  };
5958 
5959  return force;
5960 }
5961 
5962 function constant$7(x) {
5963  return function() {
5964  return x;
5965  };
5966 }
5967 
5968 function jiggle() {
5969  return (Math.random() - 0.5) * 1e-6;
5970 }
5971 
5972 function tree_add(d) {
5973  var x = +this._x.call(null, d),
5974  y = +this._y.call(null, d);
5975  return add(this.cover(x, y), x, y, d);
5976 }
5977 
5978 function add(tree, x, y, d) {
5979  if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
5980 
5981  var parent,
5982  node = tree._root,
5983  leaf = {data: d},
5984  x0 = tree._x0,
5985  y0 = tree._y0,
5986  x1 = tree._x1,
5987  y1 = tree._y1,
5988  xm,
5989  ym,
5990  xp,
5991  yp,
5992  right,
5993  bottom,
5994  i,
5995  j;
5996 
5997  // If the tree is empty, initialize the root as a leaf.
5998  if (!node) return tree._root = leaf, tree;
5999 
6000  // Find the existing leaf for the new point, or add it.
6001  while (node.length) {
6002  if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
6003  if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
6004  if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
6005  }
6006 
6007  // Is the new point is exactly coincident with the existing point?
6008  xp = +tree._x.call(null, node.data);
6009  yp = +tree._y.call(null, node.data);
6010  if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
6011 
6012  // Otherwise, split the leaf node until the old and new point are separated.
6013  do {
6014  parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
6015  if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
6016  if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
6017  } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
6018  return parent[j] = node, parent[i] = leaf, tree;
6019 }
6020 
6021 function addAll(data) {
6022  var d, i, n = data.length,
6023  x,
6024  y,
6025  xz = new Array(n),
6026  yz = new Array(n),
6027  x0 = Infinity,
6028  y0 = Infinity,
6029  x1 = -Infinity,
6030  y1 = -Infinity;
6031 
6032  // Compute the points and their extent.
6033  for (i = 0; i < n; ++i) {
6034  if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
6035  xz[i] = x;
6036  yz[i] = y;
6037  if (x < x0) x0 = x;
6038  if (x > x1) x1 = x;
6039  if (y < y0) y0 = y;
6040  if (y > y1) y1 = y;
6041  }
6042 
6043  // If there were no (valid) points, inherit the existing extent.
6044  if (x1 < x0) x0 = this._x0, x1 = this._x1;
6045  if (y1 < y0) y0 = this._y0, y1 = this._y1;
6046 
6047  // Expand the tree to cover the new points.
6048  this.cover(x0, y0).cover(x1, y1);
6049 
6050  // Add the new points.
6051  for (i = 0; i < n; ++i) {
6052  add(this, xz[i], yz[i], data[i]);
6053  }
6054 
6055  return this;
6056 }
6057 
6058 function tree_cover(x, y) {
6059  if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
6060 
6061  var x0 = this._x0,
6062  y0 = this._y0,
6063  x1 = this._x1,
6064  y1 = this._y1;
6065 
6066  // If the quadtree has no extent, initialize them.
6067  // Integer extent are necessary so that if we later double the extent,
6068  // the existing quadrant boundaries don’t change due to floating point error!
6069  if (isNaN(x0)) {
6070  x1 = (x0 = Math.floor(x)) + 1;
6071  y1 = (y0 = Math.floor(y)) + 1;
6072  }
6073 
6074  // Otherwise, double repeatedly to cover.
6075  else if (x0 > x || x > x1 || y0 > y || y > y1) {
6076  var z = x1 - x0,
6077  node = this._root,
6078  parent,
6079  i;
6080 
6081  switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
6082  case 0: {
6083  do parent = new Array(4), parent[i] = node, node = parent;
6084  while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
6085  break;
6086  }
6087  case 1: {
6088  do parent = new Array(4), parent[i] = node, node = parent;
6089  while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
6090  break;
6091  }
6092  case 2: {
6093  do parent = new Array(4), parent[i] = node, node = parent;
6094  while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
6095  break;
6096  }
6097  case 3: {
6098  do parent = new Array(4), parent[i] = node, node = parent;
6099  while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
6100  break;
6101  }
6102  }
6103 
6104  if (this._root && this._root.length) this._root = node;
6105  }
6106 
6107  // If the quadtree covers the point already, just return.
6108  else return this;
6109 
6110  this._x0 = x0;
6111  this._y0 = y0;
6112  this._x1 = x1;
6113  this._y1 = y1;
6114  return this;
6115 }
6116 
6117 function tree_data() {
6118  var data = [];
6119  this.visit(function(node) {
6120  if (!node.length) do data.push(node.data); while (node = node.next)
6121  });
6122  return data;
6123 }
6124 
6125 function tree_extent(_) {
6126  return arguments.length
6127  ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
6128  : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
6129 }
6130 
6131 function Quad(node, x0, y0, x1, y1) {
6132  this.node = node;
6133  this.x0 = x0;
6134  this.y0 = y0;
6135  this.x1 = x1;
6136  this.y1 = y1;
6137 }
6138 
6139 function tree_find(x, y, radius) {
6140  var data,
6141  x0 = this._x0,
6142  y0 = this._y0,
6143  x1,
6144  y1,
6145  x2,
6146  y2,
6147  x3 = this._x1,
6148  y3 = this._y1,
6149  quads = [],
6150  node = this._root,
6151  q,
6152  i;
6153 
6154  if (node) quads.push(new Quad(node, x0, y0, x3, y3));
6155  if (radius == null) radius = Infinity;
6156  else {
6157  x0 = x - radius, y0 = y - radius;
6158  x3 = x + radius, y3 = y + radius;
6159  radius *= radius;
6160  }
6161 
6162  while (q = quads.pop()) {
6163 
6164  // Stop searching if this quadrant can’t contain a closer node.
6165  if (!(node = q.node)
6166  || (x1 = q.x0) > x3
6167  || (y1 = q.y0) > y3
6168  || (x2 = q.x1) < x0
6169  || (y2 = q.y1) < y0) continue;
6170 
6171  // Bisect the current quadrant.
6172  if (node.length) {
6173  var xm = (x1 + x2) / 2,
6174  ym = (y1 + y2) / 2;
6175 
6176  quads.push(
6177  new Quad(node[3], xm, ym, x2, y2),
6178  new Quad(node[2], x1, ym, xm, y2),
6179  new Quad(node[1], xm, y1, x2, ym),
6180  new Quad(node[0], x1, y1, xm, ym)
6181  );
6182 
6183  // Visit the closest quadrant first.
6184  if (i = (y >= ym) << 1 | (x >= xm)) {
6185  q = quads[quads.length - 1];
6186  quads[quads.length - 1] = quads[quads.length - 1 - i];
6187  quads[quads.length - 1 - i] = q;
6188  }
6189  }
6190 
6191  // Visit this point. (Visiting coincident points isn’t necessary!)
6192  else {
6193  var dx = x - +this._x.call(null, node.data),
6194  dy = y - +this._y.call(null, node.data),
6195  d2 = dx * dx + dy * dy;
6196  if (d2 < radius) {
6197  var d = Math.sqrt(radius = d2);
6198  x0 = x - d, y0 = y - d;
6199  x3 = x + d, y3 = y + d;
6200  data = node.data;
6201  }
6202  }
6203  }
6204 
6205  return data;
6206 }
6207 
6208 function tree_remove(d) {
6209  if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
6210 
6211  var parent,
6212  node = this._root,
6213  retainer,
6214  previous,
6215  next,
6216  x0 = this._x0,
6217  y0 = this._y0,
6218  x1 = this._x1,
6219  y1 = this._y1,
6220  x,
6221  y,
6222  xm,
6223  ym,
6224  right,
6225  bottom,
6226  i,
6227  j;
6228 
6229  // If the tree is empty, initialize the root as a leaf.
6230  if (!node) return this;
6231 
6232  // Find the leaf node for the point.
6233  // While descending, also retain the deepest parent with a non-removed sibling.
6234  if (node.length) while (true) {
6235  if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
6236  if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
6237  if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
6238  if (!node.length) break;
6239  if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
6240  }
6241 
6242  // Find the point to remove.
6243  while (node.data !== d) if (!(previous = node, node = node.next)) return this;
6244  if (next = node.next) delete node.next;
6245 
6246  // If there are multiple coincident points, remove just the point.
6247  if (previous) return (next ? previous.next = next : delete previous.next), this;
6248 
6249  // If this is the root point, remove it.
6250  if (!parent) return this._root = next, this;
6251 
6252  // Remove this leaf.
6253  next ? parent[i] = next : delete parent[i];
6254 
6255  // If the parent now contains exactly one leaf, collapse superfluous parents.
6256  if ((node = parent[0] || parent[1] || parent[2] || parent[3])
6257  && node === (parent[3] || parent[2] || parent[1] || parent[0])
6258  && !node.length) {
6259  if (retainer) retainer[j] = node;
6260  else this._root = node;
6261  }
6262 
6263  return this;
6264 }
6265 
6266 function removeAll(data) {
6267  for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
6268  return this;
6269 }
6270 
6271 function tree_root() {
6272  return this._root;
6273 }
6274 
6275 function tree_size() {
6276  var size = 0;
6277  this.visit(function(node) {
6278  if (!node.length) do ++size; while (node = node.next)
6279  });
6280  return size;
6281 }
6282 
6283 function tree_visit(callback) {
6284  var quads = [], q, node = this._root, child, x0, y0, x1, y1;
6285  if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
6286  while (q = quads.pop()) {
6287  if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
6288  var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
6289  if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
6290  if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
6291  if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
6292  if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
6293  }
6294  }
6295  return this;
6296 }
6297 
6298 function tree_visitAfter(callback) {
6299  var quads = [], next = [], q;
6300  if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
6301  while (q = quads.pop()) {
6302  var node = q.node;
6303  if (node.length) {
6304  var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
6305  if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
6306  if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
6307  if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
6308  if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
6309  }
6310  next.push(q);
6311  }
6312  while (q = next.pop()) {
6313  callback(q.node, q.x0, q.y0, q.x1, q.y1);
6314  }
6315  return this;
6316 }
6317 
6318 function defaultX$1(d) {
6319  return d[0];
6320 }
6321 
6322 function tree_x(_) {
6323  return arguments.length ? (this._x = _, this) : this._x;
6324 }
6325 
6326 function defaultY$1(d) {
6327  return d[1];
6328 }
6329 
6330 function tree_y(_) {
6331  return arguments.length ? (this._y = _, this) : this._y;
6332 }
6333 
6334 function quadtree(nodes, x, y) {
6335  var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
6336  return nodes == null ? tree : tree.addAll(nodes);
6337 }
6338 
6339 function Quadtree(x, y, x0, y0, x1, y1) {
6340  this._x = x;
6341  this._y = y;
6342  this._x0 = x0;
6343  this._y0 = y0;
6344  this._x1 = x1;
6345  this._y1 = y1;
6346  this._root = undefined;
6347 }
6348 
6349 function leaf_copy(leaf) {
6350  var copy = {data: leaf.data}, next = copy;
6351  while (leaf = leaf.next) next = next.next = {data: leaf.data};
6352  return copy;
6353 }
6354 
6355 var treeProto = quadtree.prototype = Quadtree.prototype;
6356 
6357 treeProto.copy = function() {
6358  var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
6359  node = this._root,
6360  nodes,
6361  child;
6362 
6363  if (!node) return copy;
6364 
6365  if (!node.length) return copy._root = leaf_copy(node), copy;
6366 
6367  nodes = [{source: node, target: copy._root = new Array(4)}];
6368  while (node = nodes.pop()) {
6369  for (var i = 0; i < 4; ++i) {
6370  if (child = node.source[i]) {
6371  if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
6372  else node.target[i] = leaf_copy(child);
6373  }
6374  }
6375  }
6376 
6377  return copy;
6378 };
6379 
6380 treeProto.add = tree_add;
6381 treeProto.addAll = addAll;
6382 treeProto.cover = tree_cover;
6383 treeProto.data = tree_data;
6384 treeProto.extent = tree_extent;
6385 treeProto.find = tree_find;
6386 treeProto.remove = tree_remove;
6387 treeProto.removeAll = removeAll;
6388 treeProto.root = tree_root;
6389 treeProto.size = tree_size;
6390 treeProto.visit = tree_visit;
6391 treeProto.visitAfter = tree_visitAfter;
6392 treeProto.x = tree_x;
6393 treeProto.y = tree_y;
6394 
6395 function x(d) {
6396  return d.x + d.vx;
6397 }
6398 
6399 function y(d) {
6400  return d.y + d.vy;
6401 }
6402 
6403 function collide(radius) {
6404  var nodes,
6405  radii,
6406  strength = 1,
6407  iterations = 1;
6408 
6409  if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
6410 
6411  function force() {
6412  var i, n = nodes.length,
6413  tree,
6414  node,
6415  xi,
6416  yi,
6417  ri,
6418  ri2;
6419 
6420  for (var k = 0; k < iterations; ++k) {
6421  tree = quadtree(nodes, x, y).visitAfter(prepare);
6422  for (i = 0; i < n; ++i) {
6423  node = nodes[i];
6424  ri = radii[node.index], ri2 = ri * ri;
6425  xi = node.x + node.vx;
6426  yi = node.y + node.vy;
6427  tree.visit(apply);
6428  }
6429  }
6430 
6431  function apply(quad, x0, y0, x1, y1) {
6432  var data = quad.data, rj = quad.r, r = ri + rj;
6433  if (data) {
6434  if (data.index > node.index) {
6435  var x = xi - data.x - data.vx,
6436  y = yi - data.y - data.vy,
6437  l = x * x + y * y;
6438  if (l < r * r) {
6439  if (x === 0) x = jiggle(), l += x * x;
6440  if (y === 0) y = jiggle(), l += y * y;
6441  l = (r - (l = Math.sqrt(l))) / l * strength;
6442  node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
6443  node.vy += (y *= l) * r;
6444  data.vx -= x * (r = 1 - r);
6445  data.vy -= y * r;
6446  }
6447  }
6448  return;
6449  }
6450  return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
6451  }
6452  }
6453 
6454  function prepare(quad) {
6455  if (quad.data) return quad.r = radii[quad.data.index];
6456  for (var i = quad.r = 0; i < 4; ++i) {
6457  if (quad[i] && quad[i].r > quad.r) {
6458  quad.r = quad[i].r;
6459  }
6460  }
6461  }
6462 
6463  function initialize() {
6464  if (!nodes) return;
6465  var i, n = nodes.length, node;
6466  radii = new Array(n);
6467  for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
6468  }
6469 
6470  force.initialize = function(_) {
6471  nodes = _;
6472  initialize();
6473  };
6474 
6475  force.iterations = function(_) {
6476  return arguments.length ? (iterations = +_, force) : iterations;
6477  };
6478 
6479  force.strength = function(_) {
6480  return arguments.length ? (strength = +_, force) : strength;
6481  };
6482 
6483  force.radius = function(_) {
6484  return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
6485  };
6486 
6487  return force;
6488 }
6489 
6490 function index(d) {
6491  return d.index;
6492 }
6493 
6494 function find(nodeById, nodeId) {
6495  var node = nodeById.get(nodeId);
6496  if (!node) throw new Error("missing: " + nodeId);
6497  return node;
6498 }
6499 
6500 function link(links) {
6501  var id = index,
6502  strength = defaultStrength,
6503  strengths,
6504  distance = constant$7(30),
6505  distances,
6506  nodes,
6507  count,
6508  bias,
6509  iterations = 1;
6510 
6511  if (links == null) links = [];
6512 
6513  function defaultStrength(link) {
6514  return 1 / Math.min(count[link.source.index], count[link.target.index]);
6515  }
6516 
6517  function force(alpha) {
6518  for (var k = 0, n = links.length; k < iterations; ++k) {
6519  for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
6520  link = links[i], source = link.source, target = link.target;
6521  x = target.x + target.vx - source.x - source.vx || jiggle();
6522  y = target.y + target.vy - source.y - source.vy || jiggle();
6523  l = Math.sqrt(x * x + y * y);
6524  l = (l - distances[i]) / l * alpha * strengths[i];
6525  x *= l, y *= l;
6526  target.vx -= x * (b = bias[i]);
6527  target.vy -= y * b;
6528  source.vx += x * (b = 1 - b);
6529  source.vy += y * b;
6530  }
6531  }
6532  }
6533 
6534  function initialize() {
6535  if (!nodes) return;
6536 
6537  var i,
6538  n = nodes.length,
6539  m = links.length,
6540  nodeById = map$1(nodes, id),
6541  link;
6542 
6543  for (i = 0, count = new Array(n); i < m; ++i) {
6544  link = links[i], link.index = i;
6545  if (typeof link.source !== "object") link.source = find(nodeById, link.source);
6546  if (typeof link.target !== "object") link.target = find(nodeById, link.target);
6547  count[link.source.index] = (count[link.source.index] || 0) + 1;
6548  count[link.target.index] = (count[link.target.index] || 0) + 1;
6549  }
6550 
6551  for (i = 0, bias = new Array(m); i < m; ++i) {
6552  link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
6553  }
6554 
6555  strengths = new Array(m), initializeStrength();
6556  distances = new Array(m), initializeDistance();
6557  }
6558 
6559  function initializeStrength() {
6560  if (!nodes) return;
6561 
6562  for (var i = 0, n = links.length; i < n; ++i) {
6563  strengths[i] = +strength(links[i], i, links);
6564  }
6565  }
6566 
6567  function initializeDistance() {
6568  if (!nodes) return;
6569 
6570  for (var i = 0, n = links.length; i < n; ++i) {
6571  distances[i] = +distance(links[i], i, links);
6572  }
6573  }
6574 
6575  force.initialize = function(_) {
6576  nodes = _;
6577  initialize();
6578  };
6579 
6580  force.links = function(_) {
6581  return arguments.length ? (links = _, initialize(), force) : links;
6582  };
6583 
6584  force.id = function(_) {
6585  return arguments.length ? (id = _, force) : id;
6586  };
6587 
6588  force.iterations = function(_) {
6589  return arguments.length ? (iterations = +_, force) : iterations;
6590  };
6591 
6592  force.strength = function(_) {
6593  return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
6594  };
6595 
6596  force.distance = function(_) {
6597  return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
6598  };
6599 
6600  return force;
6601 }
6602 
6603 function x$1(d) {
6604  return d.x;
6605 }
6606 
6607 function y$1(d) {
6608  return d.y;
6609 }
6610 
6611 var initialRadius = 10,
6612  initialAngle = Math.PI * (3 - Math.sqrt(5));
6613 
6614 function simulation(nodes) {
6615  var simulation,
6616  alpha = 1,
6617  alphaMin = 0.001,
6618  alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
6619  alphaTarget = 0,
6620  velocityDecay = 0.6,
6621  forces = map$1(),
6622  stepper = timer(step),
6623  event = dispatch("tick", "end");
6624 
6625  if (nodes == null) nodes = [];
6626 
6627  function step() {
6628  tick();
6629  event.call("tick", simulation);
6630  if (alpha < alphaMin) {
6631  stepper.stop();
6632  event.call("end", simulation);
6633  }
6634  }
6635 
6636  function tick() {
6637  var i, n = nodes.length, node;
6638 
6639  alpha += (alphaTarget - alpha) * alphaDecay;
6640 
6641  forces.each(function(force) {
6642  force(alpha);
6643  });
6644 
6645  for (i = 0; i < n; ++i) {
6646  node = nodes[i];
6647  if (node.fx == null) node.x += node.vx *= velocityDecay;
6648  else node.x = node.fx, node.vx = 0;
6649  if (node.fy == null) node.y += node.vy *= velocityDecay;
6650  else node.y = node.fy, node.vy = 0;
6651  }
6652  }
6653 
6654  function initializeNodes() {
6655  for (var i = 0, n = nodes.length, node; i < n; ++i) {
6656  node = nodes[i], node.index = i;
6657  if (isNaN(node.x) || isNaN(node.y)) {
6658  var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
6659  node.x = radius * Math.cos(angle);
6660  node.y = radius * Math.sin(angle);
6661  }
6662  if (isNaN(node.vx) || isNaN(node.vy)) {
6663  node.vx = node.vy = 0;
6664  }
6665  }
6666  }
6667 
6668  function initializeForce(force) {
6669  if (force.initialize) force.initialize(nodes);
6670  return force;
6671  }
6672 
6673  initializeNodes();
6674 
6675  return simulation = {
6676  tick: tick,
6677 
6678  restart: function() {
6679  return stepper.restart(step), simulation;
6680  },
6681 
6682  stop: function() {
6683  return stepper.stop(), simulation;
6684  },
6685 
6686  nodes: function(_) {
6687  return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
6688  },
6689 
6690  alpha: function(_) {
6691  return arguments.length ? (alpha = +_, simulation) : alpha;
6692  },
6693 
6694  alphaMin: function(_) {
6695  return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
6696  },
6697 
6698  alphaDecay: function(_) {
6699  return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
6700  },
6701 
6702  alphaTarget: function(_) {
6703  return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
6704  },
6705 
6706  velocityDecay: function(_) {
6707  return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
6708  },
6709 
6710  force: function(name, _) {
6711  return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
6712  },
6713 
6714  find: function(x, y, radius) {
6715  var i = 0,
6716  n = nodes.length,
6717  dx,
6718  dy,
6719  d2,
6720  node,
6721  closest;
6722 
6723  if (radius == null) radius = Infinity;
6724  else radius *= radius;
6725 
6726  for (i = 0; i < n; ++i) {
6727  node = nodes[i];
6728  dx = x - node.x;
6729  dy = y - node.y;
6730  d2 = dx * dx + dy * dy;
6731  if (d2 < radius) closest = node, radius = d2;
6732  }
6733 
6734  return closest;
6735  },
6736 
6737  on: function(name, _) {
6738  return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
6739  }
6740  };
6741 }
6742 
6743 function manyBody() {
6744  var nodes,
6745  node,
6746  alpha,
6747  strength = constant$7(-30),
6748  strengths,
6749  distanceMin2 = 1,
6750  distanceMax2 = Infinity,
6751  theta2 = 0.81;
6752 
6753  function force(_) {
6754  var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
6755  for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
6756  }
6757 
6758  function initialize() {
6759  if (!nodes) return;
6760  var i, n = nodes.length, node;
6761  strengths = new Array(n);
6762  for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
6763  }
6764 
6765  function accumulate(quad) {
6766  var strength = 0, q, c, weight = 0, x, y, i;
6767 
6768  // For internal nodes, accumulate forces from child quadrants.
6769  if (quad.length) {
6770  for (x = y = i = 0; i < 4; ++i) {
6771  if ((q = quad[i]) && (c = Math.abs(q.value))) {
6772  strength += q.value, weight += c, x += c * q.x, y += c * q.y;
6773  }
6774  }
6775  quad.x = x / weight;
6776  quad.y = y / weight;
6777  }
6778 
6779  // For leaf nodes, accumulate forces from coincident quadrants.
6780  else {
6781  q = quad;
6782  q.x = q.data.x;
6783  q.y = q.data.y;
6784  do strength += strengths[q.data.index];
6785  while (q = q.next);
6786  }
6787 
6788  quad.value = strength;
6789  }
6790 
6791  function apply(quad, x1, _, x2) {
6792  if (!quad.value) return true;
6793 
6794  var x = quad.x - node.x,
6795  y = quad.y - node.y,
6796  w = x2 - x1,
6797  l = x * x + y * y;
6798 
6799  // Apply the Barnes-Hut approximation if possible.
6800  // Limit forces for very close nodes; randomize direction if coincident.
6801  if (w * w / theta2 < l) {
6802  if (l < distanceMax2) {
6803  if (x === 0) x = jiggle(), l += x * x;
6804  if (y === 0) y = jiggle(), l += y * y;
6805  if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6806  node.vx += x * quad.value * alpha / l;
6807  node.vy += y * quad.value * alpha / l;
6808  }
6809  return true;
6810  }
6811 
6812  // Otherwise, process points directly.
6813  else if (quad.length || l >= distanceMax2) return;
6814 
6815  // Limit forces for very close nodes; randomize direction if coincident.
6816  if (quad.data !== node || quad.next) {
6817  if (x === 0) x = jiggle(), l += x * x;
6818  if (y === 0) y = jiggle(), l += y * y;
6819  if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
6820  }
6821 
6822  do if (quad.data !== node) {
6823  w = strengths[quad.data.index] * alpha / l;
6824  node.vx += x * w;
6825  node.vy += y * w;
6826  } while (quad = quad.next);
6827  }
6828 
6829  force.initialize = function(_) {
6830  nodes = _;
6831  initialize();
6832  };
6833 
6834  force.strength = function(_) {
6835  return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6836  };
6837 
6838  force.distanceMin = function(_) {
6839  return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
6840  };
6841 
6842  force.distanceMax = function(_) {
6843  return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
6844  };
6845 
6846  force.theta = function(_) {
6847  return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
6848  };
6849 
6850  return force;
6851 }
6852 
6853 function radial(radius, x, y) {
6854  var nodes,
6855  strength = constant$7(0.1),
6856  strengths,
6857  radiuses;
6858 
6859  if (typeof radius !== "function") radius = constant$7(+radius);
6860  if (x == null) x = 0;
6861  if (y == null) y = 0;
6862 
6863  function force(alpha) {
6864  for (var i = 0, n = nodes.length; i < n; ++i) {
6865  var node = nodes[i],
6866  dx = node.x - x || 1e-6,
6867  dy = node.y - y || 1e-6,
6868  r = Math.sqrt(dx * dx + dy * dy),
6869  k = (radiuses[i] - r) * strengths[i] * alpha / r;
6870  node.vx += dx * k;
6871  node.vy += dy * k;
6872  }
6873  }
6874 
6875  function initialize() {
6876  if (!nodes) return;
6877  var i, n = nodes.length;
6878  strengths = new Array(n);
6879  radiuses = new Array(n);
6880  for (i = 0; i < n; ++i) {
6881  radiuses[i] = +radius(nodes[i], i, nodes);
6882  strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
6883  }
6884  }
6885 
6886  force.initialize = function(_) {
6887  nodes = _, initialize();
6888  };
6889 
6890  force.strength = function(_) {
6891  return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6892  };
6893 
6894  force.radius = function(_) {
6895  return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
6896  };
6897 
6898  force.x = function(_) {
6899  return arguments.length ? (x = +_, force) : x;
6900  };
6901 
6902  force.y = function(_) {
6903  return arguments.length ? (y = +_, force) : y;
6904  };
6905 
6906  return force;
6907 }
6908 
6909 function x$2(x) {
6910  var strength = constant$7(0.1),
6911  nodes,
6912  strengths,
6913  xz;
6914 
6915  if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
6916 
6917  function force(alpha) {
6918  for (var i = 0, n = nodes.length, node; i < n; ++i) {
6919  node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
6920  }
6921  }
6922 
6923  function initialize() {
6924  if (!nodes) return;
6925  var i, n = nodes.length;
6926  strengths = new Array(n);
6927  xz = new Array(n);
6928  for (i = 0; i < n; ++i) {
6929  strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6930  }
6931  }
6932 
6933  force.initialize = function(_) {
6934  nodes = _;
6935  initialize();
6936  };
6937 
6938  force.strength = function(_) {
6939  return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6940  };
6941 
6942  force.x = function(_) {
6943  return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
6944  };
6945 
6946  return force;
6947 }
6948 
6949 function y$2(y) {
6950  var strength = constant$7(0.1),
6951  nodes,
6952  strengths,
6953  yz;
6954 
6955  if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
6956 
6957  function force(alpha) {
6958  for (var i = 0, n = nodes.length, node; i < n; ++i) {
6959  node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
6960  }
6961  }
6962 
6963  function initialize() {
6964  if (!nodes) return;
6965  var i, n = nodes.length;
6966  strengths = new Array(n);
6967  yz = new Array(n);
6968  for (i = 0; i < n; ++i) {
6969  strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
6970  }
6971  }
6972 
6973  force.initialize = function(_) {
6974  nodes = _;
6975  initialize();
6976  };
6977 
6978  force.strength = function(_) {
6979  return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
6980  };
6981 
6982  force.y = function(_) {
6983  return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
6984  };
6985 
6986  return force;
6987 }
6988 
6989 // Computes the decimal coefficient and exponent of the specified number x with
6990 // significant digits p, where x is positive and p is in [1, 21] or undefined.
6991 // For example, formatDecimal(1.23) returns ["123", 0].
6992 function formatDecimal(x, p) {
6993  if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
6994  var i, coefficient = x.slice(0, i);
6995 
6996  // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
6997  // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
6998  return [
6999  coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
7000  +x.slice(i + 1)
7001  ];
7002 }
7003 
7004 function exponent$1(x) {
7005  return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
7006 }
7007 
7008 function formatGroup(grouping, thousands) {
7009  return function(value, width) {
7010  var i = value.length,
7011  t = [],
7012  j = 0,
7013  g = grouping[0],
7014  length = 0;
7015 
7016  while (i > 0 && g > 0) {
7017  if (length + g + 1 > width) g = Math.max(1, width - length);
7018  t.push(value.substring(i -= g, i + g));
7019  if ((length += g + 1) > width) break;
7020  g = grouping[j = (j + 1) % grouping.length];
7021  }
7022 
7023  return t.reverse().join(thousands);
7024  };
7025 }
7026 
7027 function formatNumerals(numerals) {
7028  return function(value) {
7029  return value.replace(/[0-9]/g, function(i) {
7030  return numerals[+i];
7031  });
7032  };
7033 }
7034 
7035 // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
7036 var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
7037 
7038 function formatSpecifier(specifier) {
7039  return new FormatSpecifier(specifier);
7040 }
7041 
7042 formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
7043 
7044 function FormatSpecifier(specifier) {
7045  if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
7046  var match;
7047  this.fill = match[1] || " ";
7048  this.align = match[2] || ">";
7049  this.sign = match[3] || "-";
7050  this.symbol = match[4] || "";
7051  this.zero = !!match[5];
7052  this.width = match[6] && +match[6];
7053  this.comma = !!match[7];
7054  this.precision = match[8] && +match[8].slice(1);
7055  this.trim = !!match[9];
7056  this.type = match[10] || "";
7057 }
7058 
7059 FormatSpecifier.prototype.toString = function() {
7060  return this.fill
7061  + this.align
7062  + this.sign
7063  + this.symbol
7064  + (this.zero ? "0" : "")
7065  + (this.width == null ? "" : Math.max(1, this.width | 0))
7066  + (this.comma ? "," : "")
7067  + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
7068  + (this.trim ? "~" : "")
7069  + this.type;
7070 };
7071 
7072 // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
7073 function formatTrim(s) {
7074  out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
7075  switch (s[i]) {
7076  case ".": i0 = i1 = i; break;
7077  case "0": if (i0 === 0) i0 = i; i1 = i; break;
7078  default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
7079  }
7080  }
7081  return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
7082 }
7083 
7084 var prefixExponent;
7085 
7086 function formatPrefixAuto(x, p) {
7087  var d = formatDecimal(x, p);
7088  if (!d) return x + "";
7089  var coefficient = d[0],
7090  exponent = d[1],
7091  i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
7092  n = coefficient.length;
7093  return i === n ? coefficient
7094  : i > n ? coefficient + new Array(i - n + 1).join("0")
7095  : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
7096  : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
7097 }
7098 
7099 function formatRounded(x, p) {
7100  var d = formatDecimal(x, p);
7101  if (!d) return x + "";
7102  var coefficient = d[0],
7103  exponent = d[1];
7104  return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
7105  : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
7106  : coefficient + new Array(exponent - coefficient.length + 2).join("0");
7107 }
7108 
7109 var formatTypes = {
7110  "%": function(x, p) { return (x * 100).toFixed(p); },
7111  "b": function(x) { return Math.round(x).toString(2); },
7112  "c": function(x) { return x + ""; },
7113  "d": function(x) { return Math.round(x).toString(10); },
7114  "e": function(x, p) { return x.toExponential(p); },
7115  "f": function(x, p) { return x.toFixed(p); },
7116  "g": function(x, p) { return x.toPrecision(p); },
7117  "o": function(x) { return Math.round(x).toString(8); },
7118  "p": function(x, p) { return formatRounded(x * 100, p); },
7119  "r": formatRounded,
7120  "s": formatPrefixAuto,
7121  "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
7122  "x": function(x) { return Math.round(x).toString(16); }
7123 };
7124 
7125 function identity$3(x) {
7126  return x;
7127 }
7128 
7129 var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
7130 
7131 function formatLocale(locale) {
7132  var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
7133  currency = locale.currency,
7134  decimal = locale.decimal,
7135  numerals = locale.numerals ? formatNumerals(locale.numerals) : identity$3,
7136  percent = locale.percent || "%";
7137 
7138  function newFormat(specifier) {
7139  specifier = formatSpecifier(specifier);
7140 
7141  var fill = specifier.fill,
7142  align = specifier.align,
7143  sign = specifier.sign,
7144  symbol = specifier.symbol,
7145  zero = specifier.zero,
7146  width = specifier.width,
7147  comma = specifier.comma,
7148  precision = specifier.precision,
7149  trim = specifier.trim,
7150  type = specifier.type;
7151 
7152  // The "n" type is an alias for ",g".
7153  if (type === "n") comma = true, type = "g";
7154 
7155  // The "" type, and any invalid type, is an alias for ".12~g".
7156  else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
7157 
7158  // If zero fill is specified, padding goes after sign and before digits.
7159  if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
7160 
7161  // Compute the prefix and suffix.
7162  // For SI-prefix, the suffix is lazily computed.
7163  var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
7164  suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? percent : "";
7165 
7166  // What format function should we use?
7167  // Is this an integer type?
7168  // Can this type generate exponential notation?
7169  var formatType = formatTypes[type],
7170  maybeSuffix = /[defgprs%]/.test(type);
7171 
7172  // Set the default precision if not specified,
7173  // or clamp the specified precision to the supported range.
7174  // For significant precision, it must be in [1, 21].
7175  // For fixed precision, it must be in [0, 20].
7176  precision = precision == null ? 6
7177  : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
7178  : Math.max(0, Math.min(20, precision));
7179 
7180  function format(value) {
7181  var valuePrefix = prefix,
7182  valueSuffix = suffix,
7183  i, n, c;
7184 
7185  if (type === "c") {
7186  valueSuffix = formatType(value) + valueSuffix;
7187  value = "";
7188  } else {
7189  value = +value;
7190 
7191  // Perform the initial formatting.
7192  var valueNegative = value < 0;
7193  value = formatType(Math.abs(value), precision);
7194 
7195  // Trim insignificant zeros.
7196  if (trim) value = formatTrim(value);
7197 
7198  // If a negative value rounds to zero during formatting, treat as positive.
7199  if (valueNegative && +value === 0) valueNegative = false;
7200 
7201  // Compute the prefix and suffix.
7202  valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
7203  valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
7204 
7205  // Break the formatted value into the integer “value” part that can be
7206  // grouped, and fractional or exponential “suffix” part that is not.
7207  if (maybeSuffix) {
7208  i = -1, n = value.length;
7209  while (++i < n) {
7210  if (c = value.charCodeAt(i), 48 > c || c > 57) {
7211  valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
7212  value = value.slice(0, i);
7213  break;
7214  }
7215  }
7216  }
7217  }
7218 
7219  // If the fill character is not "0", grouping is applied before padding.
7220  if (comma && !zero) value = group(value, Infinity);
7221 
7222  // Compute the padding.
7223  var length = valuePrefix.length + value.length + valueSuffix.length,
7224  padding = length < width ? new Array(width - length + 1).join(fill) : "";
7225 
7226  // If the fill character is "0", grouping is applied after padding.
7227  if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
7228 
7229  // Reconstruct the final output based on the desired alignment.
7230  switch (align) {
7231  case "<": value = valuePrefix + value + valueSuffix + padding; break;
7232  case "=": value = valuePrefix + padding + value + valueSuffix; break;
7233  case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
7234  default: value = padding + valuePrefix + value + valueSuffix; break;
7235  }
7236 
7237  return numerals(value);
7238  }
7239 
7240  format.toString = function() {
7241  return specifier + "";
7242  };
7243 
7244  return format;
7245  }
7246 
7247  function formatPrefix(specifier, value) {
7248  var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
7249  e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
7250  k = Math.pow(10, -e),
7251  prefix = prefixes[8 + e / 3];
7252  return function(value) {
7253  return f(k * value) + prefix;
7254  };
7255  }
7256 
7257  return {
7258  format: newFormat,
7259  formatPrefix: formatPrefix
7260  };
7261 }
7262 
7263 var locale;
7264 
7265 defaultLocale({
7266  decimal: ".",
7267  thousands: ",",
7268  grouping: [3],
7269  currency: ["$", ""]
7270 });
7271 
7272 function defaultLocale(definition) {
7273  locale = formatLocale(definition);
7274  exports.format = locale.format;
7275  exports.formatPrefix = locale.formatPrefix;
7276  return locale;
7277 }
7278 
7279 function precisionFixed(step) {
7280  return Math.max(0, -exponent$1(Math.abs(step)));
7281 }
7282 
7283 function precisionPrefix(step, value) {
7284  return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
7285 }
7286 
7287 function precisionRound(step, max) {
7288  step = Math.abs(step), max = Math.abs(max) - step;
7289  return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
7290 }
7291 
7292 // Adds floating point numbers with twice the normal precision.
7293 // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
7294 // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
7295 // 305–363 (1997).
7296 // Code adapted from GeographicLib by Charles F. F. Karney,
7297 // http://geographiclib.sourceforge.net/
7298 
7299 function adder() {
7300  return new Adder;
7301 }
7302 
7303 function Adder() {
7304  this.reset();
7305 }
7306 
7307 Adder.prototype = {
7308  constructor: Adder,
7309  reset: function() {
7310  this.s = // rounded value
7311  this.t = 0; // exact error
7312  },
7313  add: function(y) {
7314  add$1(temp, y, this.t);
7315  add$1(this, temp.s, this.s);
7316  if (this.s) this.t += temp.t;
7317  else this.s = temp.t;
7318  },
7319  valueOf: function() {
7320  return this.s;
7321  }
7322 };
7323 
7324 var temp = new Adder;
7325 
7326 function add$1(adder, a, b) {
7327  var x = adder.s = a + b,
7328  bv = x - a,
7329  av = x - bv;
7330  adder.t = (a - av) + (b - bv);
7331 }
7332 
7333 var epsilon$2 = 1e-6;
7334 var epsilon2$1 = 1e-12;
7335 var pi$3 = Math.PI;
7336 var halfPi$2 = pi$3 / 2;
7337 var quarterPi = pi$3 / 4;
7338 var tau$3 = pi$3 * 2;
7339 
7340 var degrees$1 = 180 / pi$3;
7341 var radians = pi$3 / 180;
7342 
7343 var abs = Math.abs;
7344 var atan = Math.atan;
7345 var atan2 = Math.atan2;
7346 var cos$1 = Math.cos;
7347 var ceil = Math.ceil;
7348 var exp = Math.exp;
7349 var log = Math.log;
7350 var pow = Math.pow;
7351 var sin$1 = Math.sin;
7352 var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
7353 var sqrt = Math.sqrt;
7354 var tan = Math.tan;
7355 
7356 function acos(x) {
7357  return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
7358 }
7359 
7360 function asin(x) {
7361  return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
7362 }
7363 
7364 function haversin(x) {
7365  return (x = sin$1(x / 2)) * x;
7366 }
7367 
7368 function noop$2() {}
7369 
7370 function streamGeometry(geometry, stream) {
7371  if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
7372  streamGeometryType[geometry.type](geometry, stream);
7373  }
7374 }
7375 
7376 var streamObjectType = {
7377  Feature: function(object, stream) {
7378  streamGeometry(object.geometry, stream);
7379  },
7380  FeatureCollection: function(object, stream) {
7381  var features = object.features, i = -1, n = features.length;
7382  while (++i < n) streamGeometry(features[i].geometry, stream);
7383  }
7384 };
7385 
7386 var streamGeometryType = {
7387  Sphere: function(object, stream) {
7388  stream.sphere();
7389  },
7390  Point: function(object, stream) {
7391  object = object.coordinates;
7392  stream.point(object[0], object[1], object[2]);
7393  },
7394  MultiPoint: function(object, stream) {
7395  var coordinates = object.coordinates, i = -1, n = coordinates.length;
7396  while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
7397  },
7398  LineString: function(object, stream) {
7399  streamLine(object.coordinates, stream, 0);
7400  },
7401  MultiLineString: function(object, stream) {
7402  var coordinates = object.coordinates, i = -1, n = coordinates.length;
7403  while (++i < n) streamLine(coordinates[i], stream, 0);
7404  },
7405  Polygon: function(object, stream) {
7406  streamPolygon(object.coordinates, stream);
7407  },
7408  MultiPolygon: function(object, stream) {
7409  var coordinates = object.coordinates, i = -1, n = coordinates.length;
7410  while (++i < n) streamPolygon(coordinates[i], stream);
7411  },
7412  GeometryCollection: function(object, stream) {
7413  var geometries = object.geometries, i = -1, n = geometries.length;
7414  while (++i < n) streamGeometry(geometries[i], stream);
7415  }
7416 };
7417 
7418 function streamLine(coordinates, stream, closed) {
7419  var i = -1, n = coordinates.length - closed, coordinate;
7420  stream.lineStart();
7421  while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
7422  stream.lineEnd();
7423 }
7424 
7425 function streamPolygon(coordinates, stream) {
7426  var i = -1, n = coordinates.length;
7427  stream.polygonStart();
7428  while (++i < n) streamLine(coordinates[i], stream, 1);
7429  stream.polygonEnd();
7430 }
7431 
7432 function geoStream(object, stream) {
7433  if (object && streamObjectType.hasOwnProperty(object.type)) {
7434  streamObjectType[object.type](object, stream);
7435  } else {
7436  streamGeometry(object, stream);
7437  }
7438 }
7439 
7440 var areaRingSum = adder();
7441 
7442 var areaSum = adder(),
7443  lambda00,
7444  phi00,
7445  lambda0,
7446  cosPhi0,
7447  sinPhi0;
7448 
7449 var areaStream = {
7450  point: noop$2,
7451  lineStart: noop$2,
7452  lineEnd: noop$2,
7453  polygonStart: function() {
7454  areaRingSum.reset();
7455  areaStream.lineStart = areaRingStart;
7456  areaStream.lineEnd = areaRingEnd;
7457  },
7458  polygonEnd: function() {
7459  var areaRing = +areaRingSum;
7460  areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
7461  this.lineStart = this.lineEnd = this.point = noop$2;
7462  },
7463  sphere: function() {
7464  areaSum.add(tau$3);
7465  }
7466 };
7467 
7468 function areaRingStart() {
7469  areaStream.point = areaPointFirst;
7470 }
7471 
7472 function areaRingEnd() {
7473  areaPoint(lambda00, phi00);
7474 }
7475 
7476 function areaPointFirst(lambda, phi) {
7477  areaStream.point = areaPoint;
7478  lambda00 = lambda, phi00 = phi;
7479  lambda *= radians, phi *= radians;
7480  lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
7481 }
7482 
7483 function areaPoint(lambda, phi) {
7484  lambda *= radians, phi *= radians;
7485  phi = phi / 2 + quarterPi; // half the angular distance from south pole
7486 
7487  // Spherical excess E for a spherical triangle with vertices: south pole,
7488  // previous point, current point. Uses a formula derived from Cagnoli’s
7489  // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
7490  var dLambda = lambda - lambda0,
7491  sdLambda = dLambda >= 0 ? 1 : -1,
7492  adLambda = sdLambda * dLambda,
7493  cosPhi = cos$1(phi),
7494  sinPhi = sin$1(phi),
7495  k = sinPhi0 * sinPhi,
7496  u = cosPhi0 * cosPhi + k * cos$1(adLambda),
7497  v = k * sdLambda * sin$1(adLambda);
7498  areaRingSum.add(atan2(v, u));
7499 
7500  // Advance the previous points.
7501  lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
7502 }
7503 
7504 function area$1(object) {
7505  areaSum.reset();
7506  geoStream(object, areaStream);
7507  return areaSum * 2;
7508 }
7509 
7510 function spherical(cartesian) {
7511  return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
7512 }
7513 
7514 function cartesian(spherical) {
7515  var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
7516  return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
7517 }
7518 
7519 function cartesianDot(a, b) {
7520  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
7521 }
7522 
7523 function cartesianCross(a, b) {
7524  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]];
7525 }
7526 
7527 // TODO return a
7528 function cartesianAddInPlace(a, b) {
7529  a[0] += b[0], a[1] += b[1], a[2] += b[2];
7530 }
7531 
7532 function cartesianScale(vector, k) {
7533  return [vector[0] * k, vector[1] * k, vector[2] * k];
7534 }
7535 
7536 // TODO return d
7537 function cartesianNormalizeInPlace(d) {
7538  var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
7539  d[0] /= l, d[1] /= l, d[2] /= l;
7540 }
7541 
7542 var lambda0$1, phi0, lambda1, phi1, // bounds
7543  lambda2, // previous lambda-coordinate
7544  lambda00$1, phi00$1, // first point
7545  p0, // previous 3D point
7546  deltaSum = adder(),
7547  ranges,
7548  range;
7549 
7550 var boundsStream = {
7551  point: boundsPoint,
7552  lineStart: boundsLineStart,
7553  lineEnd: boundsLineEnd,
7554  polygonStart: function() {
7555  boundsStream.point = boundsRingPoint;
7556  boundsStream.lineStart = boundsRingStart;
7557  boundsStream.lineEnd = boundsRingEnd;
7558  deltaSum.reset();
7559  areaStream.polygonStart();
7560  },
7561  polygonEnd: function() {
7562  areaStream.polygonEnd();
7563  boundsStream.point = boundsPoint;
7564  boundsStream.lineStart = boundsLineStart;
7565  boundsStream.lineEnd = boundsLineEnd;
7566  if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
7567  else if (deltaSum > epsilon$2) phi1 = 90;
7568  else if (deltaSum < -epsilon$2) phi0 = -90;
7569  range[0] = lambda0$1, range[1] = lambda1;
7570  }
7571 };
7572 
7573 function boundsPoint(lambda, phi) {
7574  ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7575  if (phi < phi0) phi0 = phi;
7576  if (phi > phi1) phi1 = phi;
7577 }
7578 
7579 function linePoint(lambda, phi) {
7580  var p = cartesian([lambda * radians, phi * radians]);
7581  if (p0) {
7582  var normal = cartesianCross(p0, p),
7583  equatorial = [normal[1], -normal[0], 0],
7584  inflection = cartesianCross(equatorial, normal);
7585  cartesianNormalizeInPlace(inflection);
7586  inflection = spherical(inflection);
7587  var delta = lambda - lambda2,
7588  sign$$1 = delta > 0 ? 1 : -1,
7589  lambdai = inflection[0] * degrees$1 * sign$$1,
7590  phii,
7591  antimeridian = abs(delta) > 180;
7592  if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7593  phii = inflection[1] * degrees$1;
7594  if (phii > phi1) phi1 = phii;
7595  } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
7596  phii = -inflection[1] * degrees$1;
7597  if (phii < phi0) phi0 = phii;
7598  } else {
7599  if (phi < phi0) phi0 = phi;
7600  if (phi > phi1) phi1 = phi;
7601  }
7602  if (antimeridian) {
7603  if (lambda < lambda2) {
7604  if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7605  } else {
7606  if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7607  }
7608  } else {
7609  if (lambda1 >= lambda0$1) {
7610  if (lambda < lambda0$1) lambda0$1 = lambda;
7611  if (lambda > lambda1) lambda1 = lambda;
7612  } else {
7613  if (lambda > lambda2) {
7614  if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
7615  } else {
7616  if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
7617  }
7618  }
7619  }
7620  } else {
7621  ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
7622  }
7623  if (phi < phi0) phi0 = phi;
7624  if (phi > phi1) phi1 = phi;
7625  p0 = p, lambda2 = lambda;
7626 }
7627 
7628 function boundsLineStart() {
7629  boundsStream.point = linePoint;
7630 }
7631 
7632 function boundsLineEnd() {
7633  range[0] = lambda0$1, range[1] = lambda1;
7634  boundsStream.point = boundsPoint;
7635  p0 = null;
7636 }
7637 
7638 function boundsRingPoint(lambda, phi) {
7639  if (p0) {
7640  var delta = lambda - lambda2;
7641  deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
7642  } else {
7643  lambda00$1 = lambda, phi00$1 = phi;
7644  }
7645  areaStream.point(lambda, phi);
7646  linePoint(lambda, phi);
7647 }
7648 
7649 function boundsRingStart() {
7650  areaStream.lineStart();
7651 }
7652 
7653 function boundsRingEnd() {
7654  boundsRingPoint(lambda00$1, phi00$1);
7655  areaStream.lineEnd();
7656  if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
7657  range[0] = lambda0$1, range[1] = lambda1;
7658  p0 = null;
7659 }
7660 
7661 // Finds the left-right distance between two longitudes.
7662 // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
7663 // the distance between ±180° to be 360°.
7664 function angle(lambda0, lambda1) {
7665  return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
7666 }
7667 
7668 function rangeCompare(a, b) {
7669  return a[0] - b[0];
7670 }
7671 
7672 function rangeContains(range, x) {
7673  return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
7674 }
7675 
7676 function bounds(feature) {
7677  var i, n, a, b, merged, deltaMax, delta;
7678 
7679  phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
7680  ranges = [];
7681  geoStream(feature, boundsStream);
7682 
7683  // First, sort ranges by their minimum longitudes.
7684  if (n = ranges.length) {
7685  ranges.sort(rangeCompare);
7686 
7687  // Then, merge any ranges that overlap.
7688  for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
7689  b = ranges[i];
7690  if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
7691  if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
7692  if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
7693  } else {
7694  merged.push(a = b);
7695  }
7696  }
7697 
7698  // Finally, find the largest gap between the merged ranges.
7699  // The final bounding box will be the inverse of this gap.
7700  for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
7701  b = merged[i];
7702  if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
7703  }
7704  }
7705 
7706  ranges = range = null;
7707 
7708  return lambda0$1 === Infinity || phi0 === Infinity
7709  ? [[NaN, NaN], [NaN, NaN]]
7710  : [[lambda0$1, phi0], [lambda1, phi1]];
7711 }
7712 
7713 var W0, W1,
7714  X0, Y0, Z0,
7715  X1, Y1, Z1,
7716  X2, Y2, Z2,
7717  lambda00$2, phi00$2, // first point
7718  x0, y0, z0; // previous point
7719 
7720 var centroidStream = {
7721  sphere: noop$2,
7722  point: centroidPoint,
7723  lineStart: centroidLineStart,
7724  lineEnd: centroidLineEnd,
7725  polygonStart: function() {
7726  centroidStream.lineStart = centroidRingStart;
7727  centroidStream.lineEnd = centroidRingEnd;
7728  },
7729  polygonEnd: function() {
7730  centroidStream.lineStart = centroidLineStart;
7731  centroidStream.lineEnd = centroidLineEnd;
7732  }
7733 };
7734 
7735 // Arithmetic mean of Cartesian vectors.
7736 function centroidPoint(lambda, phi) {
7737  lambda *= radians, phi *= radians;
7738  var cosPhi = cos$1(phi);
7739  centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
7740 }
7741 
7742 function centroidPointCartesian(x, y, z) {
7743  ++W0;
7744  X0 += (x - X0) / W0;
7745  Y0 += (y - Y0) / W0;
7746  Z0 += (z - Z0) / W0;
7747 }
7748 
7749 function centroidLineStart() {
7750  centroidStream.point = centroidLinePointFirst;
7751 }
7752 
7753 function centroidLinePointFirst(lambda, phi) {
7754  lambda *= radians, phi *= radians;
7755  var cosPhi = cos$1(phi);
7756  x0 = cosPhi * cos$1(lambda);
7757  y0 = cosPhi * sin$1(lambda);
7758  z0 = sin$1(phi);
7759  centroidStream.point = centroidLinePoint;
7760  centroidPointCartesian(x0, y0, z0);
7761 }
7762 
7763 function centroidLinePoint(lambda, phi) {
7764  lambda *= radians, phi *= radians;
7765  var cosPhi = cos$1(phi),
7766  x = cosPhi * cos$1(lambda),
7767  y = cosPhi * sin$1(lambda),
7768  z = sin$1(phi),
7769  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);
7770  W1 += w;
7771  X1 += w * (x0 + (x0 = x));
7772  Y1 += w * (y0 + (y0 = y));
7773  Z1 += w * (z0 + (z0 = z));
7774  centroidPointCartesian(x0, y0, z0);
7775 }
7776 
7777 function centroidLineEnd() {
7778  centroidStream.point = centroidPoint;
7779 }
7780 
7781 // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
7782 // J. Applied Mechanics 42, 239 (1975).
7783 function centroidRingStart() {
7784  centroidStream.point = centroidRingPointFirst;
7785 }
7786 
7787 function centroidRingEnd() {
7788  centroidRingPoint(lambda00$2, phi00$2);
7789  centroidStream.point = centroidPoint;
7790 }
7791 
7792 function centroidRingPointFirst(lambda, phi) {
7793  lambda00$2 = lambda, phi00$2 = phi;
7794  lambda *= radians, phi *= radians;
7795  centroidStream.point = centroidRingPoint;
7796  var cosPhi = cos$1(phi);
7797  x0 = cosPhi * cos$1(lambda);
7798  y0 = cosPhi * sin$1(lambda);
7799  z0 = sin$1(phi);
7800  centroidPointCartesian(x0, y0, z0);
7801 }
7802 
7803 function centroidRingPoint(lambda, phi) {
7804  lambda *= radians, phi *= radians;
7805  var cosPhi = cos$1(phi),
7806  x = cosPhi * cos$1(lambda),
7807  y = cosPhi * sin$1(lambda),
7808  z = sin$1(phi),
7809  cx = y0 * z - z0 * y,
7810  cy = z0 * x - x0 * z,
7811  cz = x0 * y - y0 * x,
7812  m = sqrt(cx * cx + cy * cy + cz * cz),
7813  w = asin(m), // line weight = angle
7814  v = m && -w / m; // area weight multiplier
7815  X2 += v * cx;
7816  Y2 += v * cy;
7817  Z2 += v * cz;
7818  W1 += w;
7819  X1 += w * (x0 + (x0 = x));
7820  Y1 += w * (y0 + (y0 = y));
7821  Z1 += w * (z0 + (z0 = z));
7822  centroidPointCartesian(x0, y0, z0);
7823 }
7824 
7825 function centroid(object) {
7826  W0 = W1 =
7827  X0 = Y0 = Z0 =
7828  X1 = Y1 = Z1 =
7829  X2 = Y2 = Z2 = 0;
7830  geoStream(object, centroidStream);
7831 
7832  var x = X2,
7833  y = Y2,
7834  z = Z2,
7835  m = x * x + y * y + z * z;
7836 
7837  // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
7838  if (m < epsilon2$1) {
7839  x = X1, y = Y1, z = Z1;
7840  // If the feature has zero length, fall back to arithmetic mean of point vectors.
7841  if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
7842  m = x * x + y * y + z * z;
7843  // If the feature still has an undefined ccentroid, then return.
7844  if (m < epsilon2$1) return [NaN, NaN];
7845  }
7846 
7847  return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
7848 }
7849 
7850 function constant$8(x) {
7851  return function() {
7852  return x;
7853  };
7854 }
7855 
7856 function compose(a, b) {
7857 
7858  function compose(x, y) {
7859  return x = a(x, y), b(x[0], x[1]);
7860  }
7861 
7862  if (a.invert && b.invert) compose.invert = function(x, y) {
7863  return x = b.invert(x, y), x && a.invert(x[0], x[1]);
7864  };
7865 
7866  return compose;
7867 }
7868 
7869 function rotationIdentity(lambda, phi) {
7870  return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7871 }
7872 
7873 rotationIdentity.invert = rotationIdentity;
7874 
7875 function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
7876  return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
7877  : rotationLambda(deltaLambda))
7878  : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
7879  : rotationIdentity);
7880 }
7881 
7882 function forwardRotationLambda(deltaLambda) {
7883  return function(lambda, phi) {
7884  return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
7885  };
7886 }
7887 
7888 function rotationLambda(deltaLambda) {
7889  var rotation = forwardRotationLambda(deltaLambda);
7890  rotation.invert = forwardRotationLambda(-deltaLambda);
7891  return rotation;
7892 }
7893 
7894 function rotationPhiGamma(deltaPhi, deltaGamma) {
7895  var cosDeltaPhi = cos$1(deltaPhi),
7896  sinDeltaPhi = sin$1(deltaPhi),
7897  cosDeltaGamma = cos$1(deltaGamma),
7898  sinDeltaGamma = sin$1(deltaGamma);
7899 
7900  function rotation(lambda, phi) {
7901  var cosPhi = cos$1(phi),
7902  x = cos$1(lambda) * cosPhi,
7903  y = sin$1(lambda) * cosPhi,
7904  z = sin$1(phi),
7905  k = z * cosDeltaPhi + x * sinDeltaPhi;
7906  return [
7907  atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
7908  asin(k * cosDeltaGamma + y * sinDeltaGamma)
7909  ];
7910  }
7911 
7912  rotation.invert = function(lambda, phi) {
7913  var cosPhi = cos$1(phi),
7914  x = cos$1(lambda) * cosPhi,
7915  y = sin$1(lambda) * cosPhi,
7916  z = sin$1(phi),
7917  k = z * cosDeltaGamma - y * sinDeltaGamma;
7918  return [
7919  atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
7920  asin(k * cosDeltaPhi - x * sinDeltaPhi)
7921  ];
7922  };
7923 
7924  return rotation;
7925 }
7926 
7927 function rotation(rotate) {
7928  rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
7929 
7930  function forward(coordinates) {
7931  coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
7932  return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7933  }
7934 
7935  forward.invert = function(coordinates) {
7936  coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
7937  return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
7938  };
7939 
7940  return forward;
7941 }
7942 
7943 // Generates a circle centered at [0°, 0°], with a given radius and precision.
7944 function circleStream(stream, radius, delta, direction, t0, t1) {
7945  if (!delta) return;
7946  var cosRadius = cos$1(radius),
7947  sinRadius = sin$1(radius),
7948  step = direction * delta;
7949  if (t0 == null) {
7950  t0 = radius + direction * tau$3;
7951  t1 = radius - step / 2;
7952  } else {
7953  t0 = circleRadius(cosRadius, t0);
7954  t1 = circleRadius(cosRadius, t1);
7955  if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
7956  }
7957  for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
7958  point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
7959  stream.point(point[0], point[1]);
7960  }
7961 }
7962 
7963 // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
7964 function circleRadius(cosRadius, point) {
7965  point = cartesian(point), point[0] -= cosRadius;
7966  cartesianNormalizeInPlace(point);
7967  var radius = acos(-point[1]);
7968  return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
7969 }
7970 
7971 function circle() {
7972  var center = constant$8([0, 0]),
7973  radius = constant$8(90),
7974  precision = constant$8(6),
7975  ring,
7976  rotate,
7977  stream = {point: point};
7978 
7979  function point(x, y) {
7980  ring.push(x = rotate(x, y));
7981  x[0] *= degrees$1, x[1] *= degrees$1;
7982  }
7983 
7984  function circle() {
7985  var c = center.apply(this, arguments),
7986  r = radius.apply(this, arguments) * radians,
7987  p = precision.apply(this, arguments) * radians;
7988  ring = [];
7989  rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
7990  circleStream(stream, r, p, 1);
7991  c = {type: "Polygon", coordinates: [ring]};
7992  ring = rotate = null;
7993  return c;
7994  }
7995 
7996  circle.center = function(_) {
7997  return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
7998  };
7999 
8000  circle.radius = function(_) {
8001  return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
8002  };
8003 
8004  circle.precision = function(_) {
8005  return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
8006  };
8007 
8008  return circle;
8009 }
8010 
8011 function clipBuffer() {
8012  var lines = [],
8013  line;
8014  return {
8015  point: function(x, y) {
8016  line.push([x, y]);
8017  },
8018  lineStart: function() {
8019  lines.push(line = []);
8020  },
8021  lineEnd: noop$2,
8022  rejoin: function() {
8023  if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
8024  },
8025  result: function() {
8026  var result = lines;
8027  lines = [];
8028  line = null;
8029  return result;
8030  }
8031  };
8032 }
8033 
8034 function pointEqual(a, b) {
8035  return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
8036 }
8037 
8038 function Intersection(point, points, other, entry) {
8039  this.x = point;
8040  this.z = points;
8041  this.o = other; // another intersection
8042  this.e = entry; // is an entry?
8043  this.v = false; // visited
8044  this.n = this.p = null; // next & previous
8045 }
8046 
8047 // A generalized polygon clipping algorithm: given a polygon that has been cut
8048 // into its visible line segments, and rejoins the segments by interpolating
8049 // along the clip edge.
8050 function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
8051  var subject = [],
8052  clip = [],
8053  i,
8054  n;
8055 
8056  segments.forEach(function(segment) {
8057  if ((n = segment.length - 1) <= 0) return;
8058  var n, p0 = segment[0], p1 = segment[n], x;
8059 
8060  // If the first and last points of a segment are coincident, then treat as a
8061  // closed ring. TODO if all rings are closed, then the winding order of the
8062  // exterior ring should be checked.
8063  if (pointEqual(p0, p1)) {
8064  stream.lineStart();
8065  for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
8066  stream.lineEnd();
8067  return;
8068  }
8069 
8070  subject.push(x = new Intersection(p0, segment, null, true));
8071  clip.push(x.o = new Intersection(p0, null, x, false));
8072  subject.push(x = new Intersection(p1, segment, null, false));
8073  clip.push(x.o = new Intersection(p1, null, x, true));
8074  });
8075 
8076  if (!subject.length) return;
8077 
8078  clip.sort(compareIntersection);
8079  link$1(subject);
8080  link$1(clip);
8081 
8082  for (i = 0, n = clip.length; i < n; ++i) {
8083  clip[i].e = startInside = !startInside;
8084  }
8085 
8086  var start = subject[0],
8087  points,
8088  point;
8089 
8090  while (1) {
8091  // Find first unvisited intersection.
8092  var current = start,
8093  isSubject = true;
8094  while (current.v) if ((current = current.n) === start) return;
8095  points = current.z;
8096  stream.lineStart();
8097  do {
8098  current.v = current.o.v = true;
8099  if (current.e) {
8100  if (isSubject) {
8101  for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
8102  } else {
8103  interpolate(current.x, current.n.x, 1, stream);
8104  }
8105  current = current.n;
8106  } else {
8107  if (isSubject) {
8108  points = current.p.z;
8109  for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
8110  } else {
8111  interpolate(current.x, current.p.x, -1, stream);
8112  }
8113  current = current.p;
8114  }
8115  current = current.o;
8116  points = current.z;
8117  isSubject = !isSubject;
8118  } while (!current.v);
8119  stream.lineEnd();
8120  }
8121 }
8122 
8123 function link$1(array) {
8124  if (!(n = array.length)) return;
8125  var n,
8126  i = 0,
8127  a = array[0],
8128  b;
8129  while (++i < n) {
8130  a.n = b = array[i];
8131  b.p = a;
8132  a = b;
8133  }
8134  a.n = b = array[0];
8135  b.p = a;
8136 }
8137 
8138 var sum$1 = adder();
8139 
8140 function polygonContains(polygon, point) {
8141  var lambda = point[0],
8142  phi = point[1],
8143  sinPhi = sin$1(phi),
8144  normal = [sin$1(lambda), -cos$1(lambda), 0],
8145  angle = 0,
8146  winding = 0;
8147 
8148  sum$1.reset();
8149 
8150  if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
8151  else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
8152 
8153  for (var i = 0, n = polygon.length; i < n; ++i) {
8154  if (!(m = (ring = polygon[i]).length)) continue;
8155  var ring,
8156  m,
8157  point0 = ring[m - 1],
8158  lambda0 = point0[0],
8159  phi0 = point0[1] / 2 + quarterPi,
8160  sinPhi0 = sin$1(phi0),
8161  cosPhi0 = cos$1(phi0);
8162 
8163  for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
8164  var point1 = ring[j],
8165  lambda1 = point1[0],
8166  phi1 = point1[1] / 2 + quarterPi,
8167  sinPhi1 = sin$1(phi1),
8168  cosPhi1 = cos$1(phi1),
8169  delta = lambda1 - lambda0,
8170  sign$$1 = delta >= 0 ? 1 : -1,
8171  absDelta = sign$$1 * delta,
8172  antimeridian = absDelta > pi$3,
8173  k = sinPhi0 * sinPhi1;
8174 
8175  sum$1.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
8176  angle += antimeridian ? delta + sign$$1 * tau$3 : delta;
8177 
8178  // Are the longitudes either side of the point’s meridian (lambda),
8179  // and are the latitudes smaller than the parallel (phi)?
8180  if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
8181  var arc = cartesianCross(cartesian(point0), cartesian(point1));
8182  cartesianNormalizeInPlace(arc);
8183  var intersection = cartesianCross(normal, arc);
8184  cartesianNormalizeInPlace(intersection);
8185  var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
8186  if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
8187  winding += antimeridian ^ delta >= 0 ? 1 : -1;
8188  }
8189  }
8190  }
8191  }
8192 
8193  // First, determine whether the South pole is inside or outside:
8194  //
8195  // It is inside if:
8196  // * the polygon winds around it in a clockwise direction.
8197  // * the polygon does not (cumulatively) wind around it, but has a negative
8198  // (counter-clockwise) area.
8199  //
8200  // Second, count the (signed) number of times a segment crosses a lambda
8201  // from the point to the South pole. If it is zero, then the point is the
8202  // same side as the South pole.
8203 
8204  return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
8205 }
8206 
8207 function clip(pointVisible, clipLine, interpolate, start) {
8208  return function(sink) {
8209  var line = clipLine(sink),
8210  ringBuffer = clipBuffer(),
8211  ringSink = clipLine(ringBuffer),
8212  polygonStarted = false,
8213  polygon,
8214  segments,
8215  ring;
8216 
8217  var clip = {
8218  point: point,
8219  lineStart: lineStart,
8220  lineEnd: lineEnd,
8221  polygonStart: function() {
8222  clip.point = pointRing;
8223  clip.lineStart = ringStart;
8224  clip.lineEnd = ringEnd;
8225  segments = [];
8226  polygon = [];
8227  },
8228  polygonEnd: function() {
8229  clip.point = point;
8230  clip.lineStart = lineStart;
8231  clip.lineEnd = lineEnd;
8232  segments = merge(segments);
8233  var startInside = polygonContains(polygon, start);
8234  if (segments.length) {
8235  if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8236  clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
8237  } else if (startInside) {
8238  if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8239  sink.lineStart();
8240  interpolate(null, null, 1, sink);
8241  sink.lineEnd();
8242  }
8243  if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
8244  segments = polygon = null;
8245  },
8246  sphere: function() {
8247  sink.polygonStart();
8248  sink.lineStart();
8249  interpolate(null, null, 1, sink);
8250  sink.lineEnd();
8251  sink.polygonEnd();
8252  }
8253  };
8254 
8255  function point(lambda, phi) {
8256  if (pointVisible(lambda, phi)) sink.point(lambda, phi);
8257  }
8258 
8259  function pointLine(lambda, phi) {
8260  line.point(lambda, phi);
8261  }
8262 
8263  function lineStart() {
8264  clip.point = pointLine;
8265  line.lineStart();
8266  }
8267 
8268  function lineEnd() {
8269  clip.point = point;
8270  line.lineEnd();
8271  }
8272 
8273  function pointRing(lambda, phi) {
8274  ring.push([lambda, phi]);
8275  ringSink.point(lambda, phi);
8276  }
8277 
8278  function ringStart() {
8279  ringSink.lineStart();
8280  ring = [];
8281  }
8282 
8283  function ringEnd() {
8284  pointRing(ring[0][0], ring[0][1]);
8285  ringSink.lineEnd();
8286 
8287  var clean = ringSink.clean(),
8288  ringSegments = ringBuffer.result(),
8289  i, n = ringSegments.length, m,
8290  segment,
8291  point;
8292 
8293  ring.pop();
8294  polygon.push(ring);
8295  ring = null;
8296 
8297  if (!n) return;
8298 
8299  // No intersections.
8300  if (clean & 1) {
8301  segment = ringSegments[0];
8302  if ((m = segment.length - 1) > 0) {
8303  if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
8304  sink.lineStart();
8305  for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
8306  sink.lineEnd();
8307  }
8308  return;
8309  }
8310 
8311  // Rejoin connected segments.
8312  // TODO reuse ringBuffer.rejoin()?
8313  if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
8314 
8315  segments.push(ringSegments.filter(validSegment));
8316  }
8317 
8318  return clip;
8319  };
8320 }
8321 
8322 function validSegment(segment) {
8323  return segment.length > 1;
8324 }
8325 
8326 // Intersections are sorted along the clip edge. For both antimeridian cutting
8327 // and circle clipping, the same comparison is used.
8328 function compareIntersection(a, b) {
8329  return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
8330  - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
8331 }
8332 
8333 var clipAntimeridian = clip(
8334  function() { return true; },
8335  clipAntimeridianLine,
8336  clipAntimeridianInterpolate,
8337  [-pi$3, -halfPi$2]
8338 );
8339 
8340 // Takes a line and cuts into visible segments. Return values: 0 - there were
8341 // intersections or the line was empty; 1 - no intersections; 2 - there were
8342 // intersections, and the first and last segments should be rejoined.
8343 function clipAntimeridianLine(stream) {
8344  var lambda0 = NaN,
8345  phi0 = NaN,
8346  sign0 = NaN,
8347  clean; // no intersections
8348 
8349  return {
8350  lineStart: function() {
8351  stream.lineStart();
8352  clean = 1;
8353  },
8354  point: function(lambda1, phi1) {
8355  var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
8356  delta = abs(lambda1 - lambda0);
8357  if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
8358  stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
8359  stream.point(sign0, phi0);
8360  stream.lineEnd();
8361  stream.lineStart();
8362  stream.point(sign1, phi0);
8363  stream.point(lambda1, phi0);
8364  clean = 0;
8365  } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
8366  if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
8367  if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
8368  phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
8369  stream.point(sign0, phi0);
8370  stream.lineEnd();
8371  stream.lineStart();
8372  stream.point(sign1, phi0);
8373  clean = 0;
8374  }
8375  stream.point(lambda0 = lambda1, phi0 = phi1);
8376  sign0 = sign1;
8377  },
8378  lineEnd: function() {
8379  stream.lineEnd();
8380  lambda0 = phi0 = NaN;
8381  },
8382  clean: function() {
8383  return 2 - clean; // if intersections, rejoin first and last segments
8384  }
8385  };
8386 }
8387 
8388 function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
8389  var cosPhi0,
8390  cosPhi1,
8391  sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
8392  return abs(sinLambda0Lambda1) > epsilon$2
8393  ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
8394  - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
8395  / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
8396  : (phi0 + phi1) / 2;
8397 }
8398 
8399 function clipAntimeridianInterpolate(from, to, direction, stream) {
8400  var phi;
8401  if (from == null) {
8402  phi = direction * halfPi$2;
8403  stream.point(-pi$3, phi);
8404  stream.point(0, phi);
8405  stream.point(pi$3, phi);
8406  stream.point(pi$3, 0);
8407  stream.point(pi$3, -phi);
8408  stream.point(0, -phi);
8409  stream.point(-pi$3, -phi);
8410  stream.point(-pi$3, 0);
8411  stream.point(-pi$3, phi);
8412  } else if (abs(from[0] - to[0]) > epsilon$2) {
8413  var lambda = from[0] < to[0] ? pi$3 : -pi$3;
8414  phi = direction * lambda / 2;
8415  stream.point(-lambda, phi);
8416  stream.point(0, phi);
8417  stream.point(lambda, phi);
8418  } else {
8419  stream.point(to[0], to[1]);
8420  }
8421 }
8422 
8423 function clipCircle(radius) {
8424  var cr = cos$1(radius),
8425  delta = 6 * radians,
8426  smallRadius = cr > 0,
8427  notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
8428 
8429  function interpolate(from, to, direction, stream) {
8430  circleStream(stream, radius, delta, direction, from, to);
8431  }
8432 
8433  function visible(lambda, phi) {
8434  return cos$1(lambda) * cos$1(phi) > cr;
8435  }
8436 
8437  // Takes a line and cuts into visible segments. Return values used for polygon
8438  // clipping: 0 - there were intersections or the line was empty; 1 - no
8439  // intersections 2 - there were intersections, and the first and last segments
8440  // should be rejoined.
8441  function clipLine(stream) {
8442  var point0, // previous point
8443  c0, // code for previous point
8444  v0, // visibility of previous point
8445  v00, // visibility of first point
8446  clean; // no intersections
8447  return {
8448  lineStart: function() {
8449  v00 = v0 = false;
8450  clean = 1;
8451  },
8452  point: function(lambda, phi) {
8453  var point1 = [lambda, phi],
8454  point2,
8455  v = visible(lambda, phi),
8456  c = smallRadius
8457  ? v ? 0 : code(lambda, phi)
8458  : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
8459  if (!point0 && (v00 = v0 = v)) stream.lineStart();
8460  // Handle degeneracies.
8461  // TODO ignore if not clipping polygons.
8462  if (v !== v0) {
8463  point2 = intersect(point0, point1);
8464  if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
8465  point1[0] += epsilon$2;
8466  point1[1] += epsilon$2;
8467  v = visible(point1[0], point1[1]);
8468  }
8469  }
8470  if (v !== v0) {
8471  clean = 0;
8472  if (v) {
8473  // outside going in
8474  stream.lineStart();
8475  point2 = intersect(point1, point0);
8476  stream.point(point2[0], point2[1]);
8477  } else {
8478  // inside going out
8479  point2 = intersect(point0, point1);
8480  stream.point(point2[0], point2[1]);
8481  stream.lineEnd();
8482  }
8483  point0 = point2;
8484  } else if (notHemisphere && point0 && smallRadius ^ v) {
8485  var t;
8486  // If the codes for two points are different, or are both zero,
8487  // and there this segment intersects with the small circle.
8488  if (!(c & c0) && (t = intersect(point1, point0, true))) {
8489  clean = 0;
8490  if (smallRadius) {
8491  stream.lineStart();
8492  stream.point(t[0][0], t[0][1]);
8493  stream.point(t[1][0], t[1][1]);
8494  stream.lineEnd();
8495  } else {
8496  stream.point(t[1][0], t[1][1]);
8497  stream.lineEnd();
8498  stream.lineStart();
8499  stream.point(t[0][0], t[0][1]);
8500  }
8501  }
8502  }
8503  if (v && (!point0 || !pointEqual(point0, point1))) {
8504  stream.point(point1[0], point1[1]);
8505  }
8506  point0 = point1, v0 = v, c0 = c;
8507  },
8508  lineEnd: function() {
8509  if (v0) stream.lineEnd();
8510  point0 = null;
8511  },
8512  // Rejoin first and last segments if there were intersections and the first
8513  // and last points were visible.
8514  clean: function() {
8515  return clean | ((v00 && v0) << 1);
8516  }
8517  };
8518  }
8519 
8520  // Intersects the great circle between a and b with the clip circle.
8521  function intersect(a, b, two) {
8522  var pa = cartesian(a),
8523  pb = cartesian(b);
8524 
8525  // We have two planes, n1.p = d1 and n2.p = d2.
8526  // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
8527  var n1 = [1, 0, 0], // normal
8528  n2 = cartesianCross(pa, pb),
8529  n2n2 = cartesianDot(n2, n2),
8530  n1n2 = n2[0], // cartesianDot(n1, n2),
8531  determinant = n2n2 - n1n2 * n1n2;
8532 
8533  // Two polar points.
8534  if (!determinant) return !two && a;
8535 
8536  var c1 = cr * n2n2 / determinant,
8537  c2 = -cr * n1n2 / determinant,
8538  n1xn2 = cartesianCross(n1, n2),
8539  A = cartesianScale(n1, c1),
8540  B = cartesianScale(n2, c2);
8541  cartesianAddInPlace(A, B);
8542 
8543  // Solve |p(t)|^2 = 1.
8544  var u = n1xn2,
8545  w = cartesianDot(A, u),
8546  uu = cartesianDot(u, u),
8547  t2 = w * w - uu * (cartesianDot(A, A) - 1);
8548 
8549  if (t2 < 0) return;
8550 
8551  var t = sqrt(t2),
8552  q = cartesianScale(u, (-w - t) / uu);
8553  cartesianAddInPlace(q, A);
8554  q = spherical(q);
8555 
8556  if (!two) return q;
8557 
8558  // Two intersection points.
8559  var lambda0 = a[0],
8560  lambda1 = b[0],
8561  phi0 = a[1],
8562  phi1 = b[1],
8563  z;
8564 
8565  if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
8566 
8567  var delta = lambda1 - lambda0,
8568  polar = abs(delta - pi$3) < epsilon$2,
8569  meridian = polar || delta < epsilon$2;
8570 
8571  if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
8572 
8573  // Check that the first point is between a and b.
8574  if (meridian
8575  ? polar
8576  ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
8577  : phi0 <= q[1] && q[1] <= phi1
8578  : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
8579  var q1 = cartesianScale(u, (-w + t) / uu);
8580  cartesianAddInPlace(q1, A);
8581  return [q, spherical(q1)];
8582  }
8583  }
8584 
8585  // Generates a 4-bit vector representing the location of a point relative to
8586  // the small circle's bounding box.
8587  function code(lambda, phi) {
8588  var r = smallRadius ? radius : pi$3 - radius,
8589  code = 0;
8590  if (lambda < -r) code |= 1; // left
8591  else if (lambda > r) code |= 2; // right
8592  if (phi < -r) code |= 4; // below
8593  else if (phi > r) code |= 8; // above
8594  return code;
8595  }
8596 
8597  return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
8598 }
8599 
8600 function clipLine(a, b, x0, y0, x1, y1) {
8601  var ax = a[0],
8602  ay = a[1],
8603  bx = b[0],
8604  by = b[1],
8605  t0 = 0,
8606  t1 = 1,
8607  dx = bx - ax,
8608  dy = by - ay,
8609  r;
8610 
8611  r = x0 - ax;
8612  if (!dx && r > 0) return;
8613  r /= dx;
8614  if (dx < 0) {
8615  if (r < t0) return;
8616  if (r < t1) t1 = r;
8617  } else if (dx > 0) {
8618  if (r > t1) return;
8619  if (r > t0) t0 = r;
8620  }
8621 
8622  r = x1 - ax;
8623  if (!dx && r < 0) return;
8624  r /= dx;
8625  if (dx < 0) {
8626  if (r > t1) return;
8627  if (r > t0) t0 = r;
8628  } else if (dx > 0) {
8629  if (r < t0) return;
8630  if (r < t1) t1 = r;
8631  }
8632 
8633  r = y0 - ay;
8634  if (!dy && r > 0) return;
8635  r /= dy;
8636  if (dy < 0) {
8637  if (r < t0) return;
8638  if (r < t1) t1 = r;
8639  } else if (dy > 0) {
8640  if (r > t1) return;
8641  if (r > t0) t0 = r;
8642  }
8643 
8644  r = y1 - ay;
8645  if (!dy && r < 0) return;
8646  r /= dy;
8647  if (dy < 0) {
8648  if (r > t1) return;
8649  if (r > t0) t0 = r;
8650  } else if (dy > 0) {
8651  if (r < t0) return;
8652  if (r < t1) t1 = r;
8653  }
8654 
8655  if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
8656  if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
8657  return true;
8658 }
8659 
8660 var clipMax = 1e9, clipMin = -clipMax;
8661 
8662 // TODO Use d3-polygon’s polygonContains here for the ring check?
8663 // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
8664 
8665 function clipRectangle(x0, y0, x1, y1) {
8666 
8667  function visible(x, y) {
8668  return x0 <= x && x <= x1 && y0 <= y && y <= y1;
8669  }
8670 
8671  function interpolate(from, to, direction, stream) {
8672  var a = 0, a1 = 0;
8673  if (from == null
8674  || (a = corner(from, direction)) !== (a1 = corner(to, direction))
8675  || comparePoint(from, to) < 0 ^ direction > 0) {
8676  do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
8677  while ((a = (a + direction + 4) % 4) !== a1);
8678  } else {
8679  stream.point(to[0], to[1]);
8680  }
8681  }
8682 
8683  function corner(p, direction) {
8684  return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
8685  : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
8686  : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
8687  : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
8688  }
8689 
8690  function compareIntersection(a, b) {
8691  return comparePoint(a.x, b.x);
8692  }
8693 
8694  function comparePoint(a, b) {
8695  var ca = corner(a, 1),
8696  cb = corner(b, 1);
8697  return ca !== cb ? ca - cb
8698  : ca === 0 ? b[1] - a[1]
8699  : ca === 1 ? a[0] - b[0]
8700  : ca === 2 ? a[1] - b[1]
8701  : b[0] - a[0];
8702  }
8703 
8704  return function(stream) {
8705  var activeStream = stream,
8706  bufferStream = clipBuffer(),
8707  segments,
8708  polygon,
8709  ring,
8710  x__, y__, v__, // first point
8711  x_, y_, v_, // previous point
8712  first,
8713  clean;
8714 
8715  var clipStream = {
8716  point: point,
8717  lineStart: lineStart,
8718  lineEnd: lineEnd,
8719  polygonStart: polygonStart,
8720  polygonEnd: polygonEnd
8721  };
8722 
8723  function point(x, y) {
8724  if (visible(x, y)) activeStream.point(x, y);
8725  }
8726 
8727  function polygonInside() {
8728  var winding = 0;
8729 
8730  for (var i = 0, n = polygon.length; i < n; ++i) {
8731  for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
8732  a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
8733  if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
8734  else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
8735  }
8736  }
8737 
8738  return winding;
8739  }
8740 
8741  // Buffer geometry within a polygon and then clip it en masse.
8742  function polygonStart() {
8743  activeStream = bufferStream, segments = [], polygon = [], clean = true;
8744  }
8745 
8746  function polygonEnd() {
8747  var startInside = polygonInside(),
8748  cleanInside = clean && startInside,
8749  visible = (segments = merge(segments)).length;
8750  if (cleanInside || visible) {
8751  stream.polygonStart();
8752  if (cleanInside) {
8753  stream.lineStart();
8754  interpolate(null, null, 1, stream);
8755  stream.lineEnd();
8756  }
8757  if (visible) {
8758  clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
8759  }
8760  stream.polygonEnd();
8761  }
8762  activeStream = stream, segments = polygon = ring = null;
8763  }
8764 
8765  function lineStart() {
8766  clipStream.point = linePoint;
8767  if (polygon) polygon.push(ring = []);
8768  first = true;
8769  v_ = false;
8770  x_ = y_ = NaN;
8771  }
8772 
8773  // TODO rather than special-case polygons, simply handle them separately.
8774  // Ideally, coincident intersection points should be jittered to avoid
8775  // clipping issues.
8776  function lineEnd() {
8777  if (segments) {
8778  linePoint(x__, y__);
8779  if (v__ && v_) bufferStream.rejoin();
8780  segments.push(bufferStream.result());
8781  }
8782  clipStream.point = point;
8783  if (v_) activeStream.lineEnd();
8784  }
8785 
8786  function linePoint(x, y) {
8787  var v = visible(x, y);
8788  if (polygon) ring.push([x, y]);
8789  if (first) {
8790  x__ = x, y__ = y, v__ = v;
8791  first = false;
8792  if (v) {
8793  activeStream.lineStart();
8794  activeStream.point(x, y);
8795  }
8796  } else {
8797  if (v && v_) activeStream.point(x, y);
8798  else {
8799  var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
8800  b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
8801  if (clipLine(a, b, x0, y0, x1, y1)) {
8802  if (!v_) {
8803  activeStream.lineStart();
8804  activeStream.point(a[0], a[1]);
8805  }
8806  activeStream.point(b[0], b[1]);
8807  if (!v) activeStream.lineEnd();
8808  clean = false;
8809  } else if (v) {
8810  activeStream.lineStart();
8811  activeStream.point(x, y);
8812  clean = false;
8813  }
8814  }
8815  }
8816  x_ = x, y_ = y, v_ = v;
8817  }
8818 
8819  return clipStream;
8820  };
8821 }
8822 
8823 function extent$1() {
8824  var x0 = 0,
8825  y0 = 0,
8826  x1 = 960,
8827  y1 = 500,
8828  cache,
8829  cacheStream,
8830  clip;
8831 
8832  return clip = {
8833  stream: function(stream) {
8834  return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
8835  },
8836  extent: function(_) {
8837  return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
8838  }
8839  };
8840 }
8841 
8842 var lengthSum = adder(),
8843  lambda0$2,
8844  sinPhi0$1,
8845  cosPhi0$1;
8846 
8847 var lengthStream = {
8848  sphere: noop$2,
8849  point: noop$2,
8850  lineStart: lengthLineStart,
8851  lineEnd: noop$2,
8852  polygonStart: noop$2,
8853  polygonEnd: noop$2
8854 };
8855 
8856 function lengthLineStart() {
8857  lengthStream.point = lengthPointFirst;
8858  lengthStream.lineEnd = lengthLineEnd;
8859 }
8860 
8861 function lengthLineEnd() {
8862  lengthStream.point = lengthStream.lineEnd = noop$2;
8863 }
8864 
8865 function lengthPointFirst(lambda, phi) {
8866  lambda *= radians, phi *= radians;
8867  lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
8868  lengthStream.point = lengthPoint;
8869 }
8870 
8871 function lengthPoint(lambda, phi) {
8872  lambda *= radians, phi *= radians;
8873  var sinPhi = sin$1(phi),
8874  cosPhi = cos$1(phi),
8875  delta = abs(lambda - lambda0$2),
8876  cosDelta = cos$1(delta),
8877  sinDelta = sin$1(delta),
8878  x = cosPhi * sinDelta,
8879  y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
8880  z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
8881  lengthSum.add(atan2(sqrt(x * x + y * y), z));
8882  lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
8883 }
8884 
8885 function length$1(object) {
8886  lengthSum.reset();
8887  geoStream(object, lengthStream);
8888  return +lengthSum;
8889 }
8890 
8891 var coordinates = [null, null],
8892  object$1 = {type: "LineString", coordinates: coordinates};
8893 
8894 function distance(a, b) {
8895  coordinates[0] = a;
8896  coordinates[1] = b;
8897  return length$1(object$1);
8898 }
8899 
8900 var containsObjectType = {
8901  Feature: function(object, point) {
8902  return containsGeometry(object.geometry, point);
8903  },
8904  FeatureCollection: function(object, point) {
8905  var features = object.features, i = -1, n = features.length;
8906  while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
8907  return false;
8908  }
8909 };
8910 
8911 var containsGeometryType = {
8912  Sphere: function() {
8913  return true;
8914  },
8915  Point: function(object, point) {
8916  return containsPoint(object.coordinates, point);
8917  },
8918  MultiPoint: function(object, point) {
8919  var coordinates = object.coordinates, i = -1, n = coordinates.length;
8920  while (++i < n) if (containsPoint(coordinates[i], point)) return true;
8921  return false;
8922  },
8923  LineString: function(object, point) {
8924  return containsLine(object.coordinates, point);
8925  },
8926  MultiLineString: function(object, point) {
8927  var coordinates = object.coordinates, i = -1, n = coordinates.length;
8928  while (++i < n) if (containsLine(coordinates[i], point)) return true;
8929  return false;
8930  },
8931  Polygon: function(object, point) {
8932  return containsPolygon(object.coordinates, point);
8933  },
8934  MultiPolygon: function(object, point) {
8935  var coordinates = object.coordinates, i = -1, n = coordinates.length;
8936  while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
8937  return false;
8938  },
8939  GeometryCollection: function(object, point) {
8940  var geometries = object.geometries, i = -1, n = geometries.length;
8941  while (++i < n) if (containsGeometry(geometries[i], point)) return true;
8942  return false;
8943  }
8944 };
8945 
8946 function containsGeometry(geometry, point) {
8947  return geometry && containsGeometryType.hasOwnProperty(geometry.type)
8948  ? containsGeometryType[geometry.type](geometry, point)
8949  : false;
8950 }
8951 
8952 function containsPoint(coordinates, point) {
8953  return distance(coordinates, point) === 0;
8954 }
8955 
8956 function containsLine(coordinates, point) {
8957  var ab = distance(coordinates[0], coordinates[1]),
8958  ao = distance(coordinates[0], point),
8959  ob = distance(point, coordinates[1]);
8960  return ao + ob <= ab + epsilon$2;
8961 }
8962 
8963 function containsPolygon(coordinates, point) {
8964  return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
8965 }
8966 
8967 function ringRadians(ring) {
8968  return ring = ring.map(pointRadians), ring.pop(), ring;
8969 }
8970 
8971 function pointRadians(point) {
8972  return [point[0] * radians, point[1] * radians];
8973 }
8974 
8975 function contains$1(object, point) {
8976  return (object && containsObjectType.hasOwnProperty(object.type)
8977  ? containsObjectType[object.type]
8978  : containsGeometry)(object, point);
8979 }
8980 
8981 function graticuleX(y0, y1, dy) {
8982  var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
8983  return function(x) { return y.map(function(y) { return [x, y]; }); };
8984 }
8985 
8986 function graticuleY(x0, x1, dx) {
8987  var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
8988  return function(y) { return x.map(function(x) { return [x, y]; }); };
8989 }
8990 
8991 function graticule() {
8992  var x1, x0, X1, X0,
8993  y1, y0, Y1, Y0,
8994  dx = 10, dy = dx, DX = 90, DY = 360,
8995  x, y, X, Y,
8996  precision = 2.5;
8997 
8998  function graticule() {
8999  return {type: "MultiLineString", coordinates: lines()};
9000  }
9001 
9002  function lines() {
9003  return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
9004  .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
9005  .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
9006  .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
9007  }
9008 
9009  graticule.lines = function() {
9010  return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
9011  };
9012 
9013  graticule.outline = function() {
9014  return {
9015  type: "Polygon",
9016  coordinates: [
9017  X(X0).concat(
9018  Y(Y1).slice(1),
9019  X(X1).reverse().slice(1),
9020  Y(Y0).reverse().slice(1))
9021  ]
9022  };
9023  };
9024 
9025  graticule.extent = function(_) {
9026  if (!arguments.length) return graticule.extentMinor();
9027  return graticule.extentMajor(_).extentMinor(_);
9028  };
9029 
9030  graticule.extentMajor = function(_) {
9031  if (!arguments.length) return [[X0, Y0], [X1, Y1]];
9032  X0 = +_[0][0], X1 = +_[1][0];
9033  Y0 = +_[0][1], Y1 = +_[1][1];
9034  if (X0 > X1) _ = X0, X0 = X1, X1 = _;
9035  if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
9036  return graticule.precision(precision);
9037  };
9038 
9039  graticule.extentMinor = function(_) {
9040  if (!arguments.length) return [[x0, y0], [x1, y1]];
9041  x0 = +_[0][0], x1 = +_[1][0];
9042  y0 = +_[0][1], y1 = +_[1][1];
9043  if (x0 > x1) _ = x0, x0 = x1, x1 = _;
9044  if (y0 > y1) _ = y0, y0 = y1, y1 = _;
9045  return graticule.precision(precision);
9046  };
9047 
9048  graticule.step = function(_) {
9049  if (!arguments.length) return graticule.stepMinor();
9050  return graticule.stepMajor(_).stepMinor(_);
9051  };
9052 
9053  graticule.stepMajor = function(_) {
9054  if (!arguments.length) return [DX, DY];
9055  DX = +_[0], DY = +_[1];
9056  return graticule;
9057  };
9058 
9059  graticule.stepMinor = function(_) {
9060  if (!arguments.length) return [dx, dy];
9061  dx = +_[0], dy = +_[1];
9062  return graticule;
9063  };
9064 
9065  graticule.precision = function(_) {
9066  if (!arguments.length) return precision;
9067  precision = +_;
9068  x = graticuleX(y0, y1, 90);
9069  y = graticuleY(x0, x1, precision);
9070  X = graticuleX(Y0, Y1, 90);
9071  Y = graticuleY(X0, X1, precision);
9072  return graticule;
9073  };
9074 
9075  return graticule
9076  .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
9077  .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
9078 }
9079 
9080 function graticule10() {
9081  return graticule()();
9082 }
9083 
9084 function interpolate$1(a, b) {
9085  var x0 = a[0] * radians,
9086  y0 = a[1] * radians,
9087  x1 = b[0] * radians,
9088  y1 = b[1] * radians,
9089  cy0 = cos$1(y0),
9090  sy0 = sin$1(y0),
9091  cy1 = cos$1(y1),
9092  sy1 = sin$1(y1),
9093  kx0 = cy0 * cos$1(x0),
9094  ky0 = cy0 * sin$1(x0),
9095  kx1 = cy1 * cos$1(x1),
9096  ky1 = cy1 * sin$1(x1),
9097  d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
9098  k = sin$1(d);
9099 
9100  var interpolate = d ? function(t) {
9101  var B = sin$1(t *= d) / k,
9102  A = sin$1(d - t) / k,
9103  x = A * kx0 + B * kx1,
9104  y = A * ky0 + B * ky1,
9105  z = A * sy0 + B * sy1;
9106  return [
9107  atan2(y, x) * degrees$1,
9108  atan2(z, sqrt(x * x + y * y)) * degrees$1
9109  ];
9110  } : function() {
9111  return [x0 * degrees$1, y0 * degrees$1];
9112  };
9113 
9114  interpolate.distance = d;
9115 
9116  return interpolate;
9117 }
9118 
9119 function identity$4(x) {
9120  return x;
9121 }
9122 
9123 var areaSum$1 = adder(),
9124  areaRingSum$1 = adder(),
9125  x00,
9126  y00,
9127  x0$1,
9128  y0$1;
9129 
9130 var areaStream$1 = {
9131  point: noop$2,
9132  lineStart: noop$2,
9133  lineEnd: noop$2,
9134  polygonStart: function() {
9135  areaStream$1.lineStart = areaRingStart$1;
9136  areaStream$1.lineEnd = areaRingEnd$1;
9137  },
9138  polygonEnd: function() {
9139  areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
9140  areaSum$1.add(abs(areaRingSum$1));
9141  areaRingSum$1.reset();
9142  },
9143  result: function() {
9144  var area = areaSum$1 / 2;
9145  areaSum$1.reset();
9146  return area;
9147  }
9148 };
9149 
9150 function areaRingStart$1() {
9151  areaStream$1.point = areaPointFirst$1;
9152 }
9153 
9154 function areaPointFirst$1(x, y) {
9155  areaStream$1.point = areaPoint$1;
9156  x00 = x0$1 = x, y00 = y0$1 = y;
9157 }
9158 
9159 function areaPoint$1(x, y) {
9160  areaRingSum$1.add(y0$1 * x - x0$1 * y);
9161  x0$1 = x, y0$1 = y;
9162 }
9163 
9164 function areaRingEnd$1() {
9165  areaPoint$1(x00, y00);
9166 }
9167 
9168 var x0$2 = Infinity,
9169  y0$2 = x0$2,
9170  x1 = -x0$2,
9171  y1 = x1;
9172 
9173 var boundsStream$1 = {
9174  point: boundsPoint$1,
9175  lineStart: noop$2,
9176  lineEnd: noop$2,
9177  polygonStart: noop$2,
9178  polygonEnd: noop$2,
9179  result: function() {
9180  var bounds = [[x0$2, y0$2], [x1, y1]];
9181  x1 = y1 = -(y0$2 = x0$2 = Infinity);
9182  return bounds;
9183  }
9184 };
9185 
9186 function boundsPoint$1(x, y) {
9187  if (x < x0$2) x0$2 = x;
9188  if (x > x1) x1 = x;
9189  if (y < y0$2) y0$2 = y;
9190  if (y > y1) y1 = y;
9191 }
9192 
9193 // TODO Enforce positive area for exterior, negative area for interior?
9194 
9195 var X0$1 = 0,
9196  Y0$1 = 0,
9197  Z0$1 = 0,
9198  X1$1 = 0,
9199  Y1$1 = 0,
9200  Z1$1 = 0,
9201  X2$1 = 0,
9202  Y2$1 = 0,
9203  Z2$1 = 0,
9204  x00$1,
9205  y00$1,
9206  x0$3,
9207  y0$3;
9208 
9209 var centroidStream$1 = {
9210  point: centroidPoint$1,
9211  lineStart: centroidLineStart$1,
9212  lineEnd: centroidLineEnd$1,
9213  polygonStart: function() {
9214  centroidStream$1.lineStart = centroidRingStart$1;
9215  centroidStream$1.lineEnd = centroidRingEnd$1;
9216  },
9217  polygonEnd: function() {
9218  centroidStream$1.point = centroidPoint$1;
9219  centroidStream$1.lineStart = centroidLineStart$1;
9220  centroidStream$1.lineEnd = centroidLineEnd$1;
9221  },
9222  result: function() {
9223  var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
9224  : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
9225  : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
9226  : [NaN, NaN];
9227  X0$1 = Y0$1 = Z0$1 =
9228  X1$1 = Y1$1 = Z1$1 =
9229  X2$1 = Y2$1 = Z2$1 = 0;
9230  return centroid;
9231  }
9232 };
9233 
9234 function centroidPoint$1(x, y) {
9235  X0$1 += x;
9236  Y0$1 += y;
9237  ++Z0$1;
9238 }
9239 
9240 function centroidLineStart$1() {
9241  centroidStream$1.point = centroidPointFirstLine;
9242 }
9243 
9244 function centroidPointFirstLine(x, y) {
9245  centroidStream$1.point = centroidPointLine;
9246  centroidPoint$1(x0$3 = x, y0$3 = y);
9247 }
9248 
9249 function centroidPointLine(x, y) {
9250  var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
9251  X1$1 += z * (x0$3 + x) / 2;
9252  Y1$1 += z * (y0$3 + y) / 2;
9253  Z1$1 += z;
9254  centroidPoint$1(x0$3 = x, y0$3 = y);
9255 }
9256 
9257 function centroidLineEnd$1() {
9258  centroidStream$1.point = centroidPoint$1;
9259 }
9260 
9261 function centroidRingStart$1() {
9262  centroidStream$1.point = centroidPointFirstRing;
9263 }
9264 
9265 function centroidRingEnd$1() {
9266  centroidPointRing(x00$1, y00$1);
9267 }
9268 
9269 function centroidPointFirstRing(x, y) {
9270  centroidStream$1.point = centroidPointRing;
9271  centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
9272 }
9273 
9274 function centroidPointRing(x, y) {
9275  var dx = x - x0$3,
9276  dy = y - y0$3,
9277  z = sqrt(dx * dx + dy * dy);
9278 
9279  X1$1 += z * (x0$3 + x) / 2;
9280  Y1$1 += z * (y0$3 + y) / 2;
9281  Z1$1 += z;
9282 
9283  z = y0$3 * x - x0$3 * y;
9284  X2$1 += z * (x0$3 + x);
9285  Y2$1 += z * (y0$3 + y);
9286  Z2$1 += z * 3;
9287  centroidPoint$1(x0$3 = x, y0$3 = y);
9288 }
9289 
9290 function PathContext(context) {
9291  this._context = context;
9292 }
9293 
9294 PathContext.prototype = {
9295  _radius: 4.5,
9296  pointRadius: function(_) {
9297  return this._radius = _, this;
9298  },
9299  polygonStart: function() {
9300  this._line = 0;
9301  },
9302  polygonEnd: function() {
9303  this._line = NaN;
9304  },
9305  lineStart: function() {
9306  this._point = 0;
9307  },
9308  lineEnd: function() {
9309  if (this._line === 0) this._context.closePath();
9310  this._point = NaN;
9311  },
9312  point: function(x, y) {
9313  switch (this._point) {
9314  case 0: {
9315  this._context.moveTo(x, y);
9316  this._point = 1;
9317  break;
9318  }
9319  case 1: {
9320  this._context.lineTo(x, y);
9321  break;
9322  }
9323  default: {
9324  this._context.moveTo(x + this._radius, y);
9325  this._context.arc(x, y, this._radius, 0, tau$3);
9326  break;
9327  }
9328  }
9329  },
9330  result: noop$2
9331 };
9332 
9333 var lengthSum$1 = adder(),
9334  lengthRing,
9335  x00$2,
9336  y00$2,
9337  x0$4,
9338  y0$4;
9339 
9340 var lengthStream$1 = {
9341  point: noop$2,
9342  lineStart: function() {
9343  lengthStream$1.point = lengthPointFirst$1;
9344  },
9345  lineEnd: function() {
9346  if (lengthRing) lengthPoint$1(x00$2, y00$2);
9347  lengthStream$1.point = noop$2;
9348  },
9349  polygonStart: function() {
9350  lengthRing = true;
9351  },
9352  polygonEnd: function() {
9353  lengthRing = null;
9354  },
9355  result: function() {
9356  var length = +lengthSum$1;
9357  lengthSum$1.reset();
9358  return length;
9359  }
9360 };
9361 
9362 function lengthPointFirst$1(x, y) {
9363  lengthStream$1.point = lengthPoint$1;
9364  x00$2 = x0$4 = x, y00$2 = y0$4 = y;
9365 }
9366 
9367 function lengthPoint$1(x, y) {
9368  x0$4 -= x, y0$4 -= y;
9369  lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
9370  x0$4 = x, y0$4 = y;
9371 }
9372 
9373 function PathString() {
9374  this._string = [];
9375 }
9376 
9377 PathString.prototype = {
9378  _radius: 4.5,
9379  _circle: circle$1(4.5),
9380  pointRadius: function(_) {
9381  if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
9382  return this;
9383  },
9384  polygonStart: function() {
9385  this._line = 0;
9386  },
9387  polygonEnd: function() {
9388  this._line = NaN;
9389  },
9390  lineStart: function() {
9391  this._point = 0;
9392  },
9393  lineEnd: function() {
9394  if (this._line === 0) this._string.push("Z");
9395  this._point = NaN;
9396  },
9397  point: function(x, y) {
9398  switch (this._point) {
9399  case 0: {
9400  this._string.push("M", x, ",", y);
9401  this._point = 1;
9402  break;
9403  }
9404  case 1: {
9405  this._string.push("L", x, ",", y);
9406  break;
9407  }
9408  default: {
9409  if (this._circle == null) this._circle = circle$1(this._radius);
9410  this._string.push("M", x, ",", y, this._circle);
9411  break;
9412  }
9413  }
9414  },
9415  result: function() {
9416  if (this._string.length) {
9417  var result = this._string.join("");
9418  this._string = [];
9419  return result;
9420  } else {
9421  return null;
9422  }
9423  }
9424 };
9425 
9426 function circle$1(radius) {
9427  return "m0," + radius
9428  + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
9429  + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
9430  + "z";
9431 }
9432 
9433 function index$1(projection, context) {
9434  var pointRadius = 4.5,
9435  projectionStream,
9436  contextStream;
9437 
9438  function path(object) {
9439  if (object) {
9440  if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
9441  geoStream(object, projectionStream(contextStream));
9442  }
9443  return contextStream.result();
9444  }
9445 
9446  path.area = function(object) {
9447  geoStream(object, projectionStream(areaStream$1));
9448  return areaStream$1.result();
9449  };
9450 
9451  path.measure = function(object) {
9452  geoStream(object, projectionStream(lengthStream$1));
9453  return lengthStream$1.result();
9454  };
9455 
9456  path.bounds = function(object) {
9457  geoStream(object, projectionStream(boundsStream$1));
9458  return boundsStream$1.result();
9459  };
9460 
9461  path.centroid = function(object) {
9462  geoStream(object, projectionStream(centroidStream$1));
9463  return centroidStream$1.result();
9464  };
9465 
9466  path.projection = function(_) {
9467  return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
9468  };
9469 
9470  path.context = function(_) {
9471  if (!arguments.length) return context;
9472  contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
9473  if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
9474  return path;
9475  };
9476 
9477  path.pointRadius = function(_) {
9478  if (!arguments.length) return pointRadius;
9479  pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
9480  return path;
9481  };
9482 
9483  return path.projection(projection).context(context);
9484 }
9485 
9486 function transform(methods) {
9487  return {
9488  stream: transformer(methods)
9489  };
9490 }
9491 
9492 function transformer(methods) {
9493  return function(stream) {
9494  var s = new TransformStream;
9495  for (var key in methods) s[key] = methods[key];
9496  s.stream = stream;
9497  return s;
9498  };
9499 }
9500 
9501 function TransformStream() {}
9502 
9503 TransformStream.prototype = {
9504  constructor: TransformStream,
9505  point: function(x, y) { this.stream.point(x, y); },
9506  sphere: function() { this.stream.sphere(); },
9507  lineStart: function() { this.stream.lineStart(); },
9508  lineEnd: function() { this.stream.lineEnd(); },
9509  polygonStart: function() { this.stream.polygonStart(); },
9510  polygonEnd: function() { this.stream.polygonEnd(); }
9511 };
9512 
9513 function fit(projection, fitBounds, object) {
9514  var clip = projection.clipExtent && projection.clipExtent();
9515  projection.scale(150).translate([0, 0]);
9516  if (clip != null) projection.clipExtent(null);
9517  geoStream(object, projection.stream(boundsStream$1));
9518  fitBounds(boundsStream$1.result());
9519  if (clip != null) projection.clipExtent(clip);
9520  return projection;
9521 }
9522 
9523 function fitExtent(projection, extent, object) {
9524  return fit(projection, function(b) {
9525  var w = extent[1][0] - extent[0][0],
9526  h = extent[1][1] - extent[0][1],
9527  k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
9528  x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
9529  y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
9530  projection.scale(150 * k).translate([x, y]);
9531  }, object);
9532 }
9533 
9534 function fitSize(projection, size, object) {
9535  return fitExtent(projection, [[0, 0], size], object);
9536 }
9537 
9538 function fitWidth(projection, width, object) {
9539  return fit(projection, function(b) {
9540  var w = +width,
9541  k = w / (b[1][0] - b[0][0]),
9542  x = (w - k * (b[1][0] + b[0][0])) / 2,
9543  y = -k * b[0][1];
9544  projection.scale(150 * k).translate([x, y]);
9545  }, object);
9546 }
9547 
9548 function fitHeight(projection, height, object) {
9549  return fit(projection, function(b) {
9550  var h = +height,
9551  k = h / (b[1][1] - b[0][1]),
9552  x = -k * b[0][0],
9553  y = (h - k * (b[1][1] + b[0][1])) / 2;
9554  projection.scale(150 * k).translate([x, y]);
9555  }, object);
9556 }
9557 
9558 var maxDepth = 16, // maximum depth of subdivision
9559  cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
9560 
9561 function resample(project, delta2) {
9562  return +delta2 ? resample$1(project, delta2) : resampleNone(project);
9563 }
9564 
9565 function resampleNone(project) {
9566  return transformer({
9567  point: function(x, y) {
9568  x = project(x, y);
9569  this.stream.point(x[0], x[1]);
9570  }
9571  });
9572 }
9573 
9574 function resample$1(project, delta2) {
9575 
9576  function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
9577  var dx = x1 - x0,
9578  dy = y1 - y0,
9579  d2 = dx * dx + dy * dy;
9580  if (d2 > 4 * delta2 && depth--) {
9581  var a = a0 + a1,
9582  b = b0 + b1,
9583  c = c0 + c1,
9584  m = sqrt(a * a + b * b + c * c),
9585  phi2 = asin(c /= m),
9586  lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
9587  p = project(lambda2, phi2),
9588  x2 = p[0],
9589  y2 = p[1],
9590  dx2 = x2 - x0,
9591  dy2 = y2 - y0,
9592  dz = dy * dx2 - dx * dy2;
9593  if (dz * dz / d2 > delta2 // perpendicular projected distance
9594  || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
9595  || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
9596  resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
9597  stream.point(x2, y2);
9598  resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
9599  }
9600  }
9601  }
9602  return function(stream) {
9603  var lambda00, x00, y00, a00, b00, c00, // first point
9604  lambda0, x0, y0, a0, b0, c0; // previous point
9605 
9606  var resampleStream = {
9607  point: point,
9608  lineStart: lineStart,
9609  lineEnd: lineEnd,
9610  polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
9611  polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
9612  };
9613 
9614  function point(x, y) {
9615  x = project(x, y);
9616  stream.point(x[0], x[1]);
9617  }
9618 
9619  function lineStart() {
9620  x0 = NaN;
9621  resampleStream.point = linePoint;
9622  stream.lineStart();
9623  }
9624 
9625  function linePoint(lambda, phi) {
9626  var c = cartesian([lambda, phi]), p = project(lambda, phi);
9627  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);
9628  stream.point(x0, y0);
9629  }
9630 
9631  function lineEnd() {
9632  resampleStream.point = point;
9633  stream.lineEnd();
9634  }
9635 
9636  function ringStart() {
9637  lineStart();
9638  resampleStream.point = ringPoint;
9639  resampleStream.lineEnd = ringEnd;
9640  }
9641 
9642  function ringPoint(lambda, phi) {
9643  linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
9644  resampleStream.point = linePoint;
9645  }
9646 
9647  function ringEnd() {
9648  resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
9649  resampleStream.lineEnd = lineEnd;
9650  lineEnd();
9651  }
9652 
9653  return resampleStream;
9654  };
9655 }
9656 
9657 var transformRadians = transformer({
9658  point: function(x, y) {
9659  this.stream.point(x * radians, y * radians);
9660  }
9661 });
9662 
9663 function transformRotate(rotate) {
9664  return transformer({
9665  point: function(x, y) {
9666  var r = rotate(x, y);
9667  return this.stream.point(r[0], r[1]);
9668  }
9669  });
9670 }
9671 
9672 function scaleTranslate(k, dx, dy) {
9673  function transform$$1(x, y) {
9674  return [dx + k * x, dy - k * y];
9675  }
9676  transform$$1.invert = function(x, y) {
9677  return [(x - dx) / k, (dy - y) / k];
9678  };
9679  return transform$$1;
9680 }
9681 
9682 function scaleTranslateRotate(k, dx, dy, alpha) {
9683  var cosAlpha = cos$1(alpha),
9684  sinAlpha = sin$1(alpha),
9685  a = cosAlpha * k,
9686  b = sinAlpha * k,
9687  ai = cosAlpha / k,
9688  bi = sinAlpha / k,
9689  ci = (sinAlpha * dy - cosAlpha * dx) / k,
9690  fi = (sinAlpha * dx + cosAlpha * dy) / k;
9691  function transform$$1(x, y) {
9692  return [a * x - b * y + dx, dy - b * x - a * y];
9693  }
9694  transform$$1.invert = function(x, y) {
9695  return [ai * x - bi * y + ci, fi - bi * x - ai * y];
9696  };
9697  return transform$$1;
9698 }
9699 
9700 function projection(project) {
9701  return projectionMutator(function() { return project; })();
9702 }
9703 
9704 function projectionMutator(projectAt) {
9705  var project,
9706  k = 150, // scale
9707  x = 480, y = 250, // translate
9708  lambda = 0, phi = 0, // center
9709  deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
9710  alpha = 0, // post-rotate
9711  theta = null, preclip = clipAntimeridian, // pre-clip angle
9712  x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
9713  delta2 = 0.5, // precision
9714  projectResample,
9715  projectTransform,
9716  projectRotateTransform,
9717  cache,
9718  cacheStream;
9719 
9720  function projection(point) {
9721  return projectRotateTransform(point[0] * radians, point[1] * radians);
9722  }
9723 
9724  function invert(point) {
9725  point = projectRotateTransform.invert(point[0], point[1]);
9726  return point && [point[0] * degrees$1, point[1] * degrees$1];
9727  }
9728 
9729  projection.stream = function(stream) {
9730  return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
9731  };
9732 
9733  projection.preclip = function(_) {
9734  return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
9735  };
9736 
9737  projection.postclip = function(_) {
9738  return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
9739  };
9740 
9741  projection.clipAngle = function(_) {
9742  return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
9743  };
9744 
9745  projection.clipExtent = function(_) {
9746  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]];
9747  };
9748 
9749  projection.scale = function(_) {
9750  return arguments.length ? (k = +_, recenter()) : k;
9751  };
9752 
9753  projection.translate = function(_) {
9754  return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
9755  };
9756 
9757  projection.center = function(_) {
9758  return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
9759  };
9760 
9761  projection.rotate = function(_) {
9762  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];
9763  };
9764 
9765  projection.angle = function(_) {
9766  return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
9767  };
9768 
9769  projection.precision = function(_) {
9770  return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
9771  };
9772 
9773  projection.fitExtent = function(extent, object) {
9774  return fitExtent(projection, extent, object);
9775  };
9776 
9777  projection.fitSize = function(size, object) {
9778  return fitSize(projection, size, object);
9779  };
9780 
9781  projection.fitWidth = function(width, object) {
9782  return fitWidth(projection, width, object);
9783  };
9784 
9785  projection.fitHeight = function(height, object) {
9786  return fitHeight(projection, height, object);
9787  };
9788 
9789  function recenter() {
9790  var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
9791  transform$$1 = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
9792  rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
9793  projectTransform = compose(project, transform$$1);
9794  projectRotateTransform = compose(rotate, projectTransform);
9795  projectResample = resample(projectTransform, delta2);
9796  return reset();
9797  }
9798 
9799  function reset() {
9800  cache = cacheStream = null;
9801  return projection;
9802  }
9803 
9804  return function() {
9805  project = projectAt.apply(this, arguments);
9806  projection.invert = project.invert && invert;
9807  return recenter();
9808  };
9809 }
9810 
9811 function conicProjection(projectAt) {
9812  var phi0 = 0,
9813  phi1 = pi$3 / 3,
9814  m = projectionMutator(projectAt),
9815  p = m(phi0, phi1);
9816 
9817  p.parallels = function(_) {
9818  return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
9819  };
9820 
9821  return p;
9822 }
9823 
9824 function cylindricalEqualAreaRaw(phi0) {
9825  var cosPhi0 = cos$1(phi0);
9826 
9827  function forward(lambda, phi) {
9828  return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
9829  }
9830 
9831  forward.invert = function(x, y) {
9832  return [x / cosPhi0, asin(y * cosPhi0)];
9833  };
9834 
9835  return forward;
9836 }
9837 
9838 function conicEqualAreaRaw(y0, y1) {
9839  var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
9840 
9841  // Are the parallels symmetrical around the Equator?
9842  if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
9843 
9844  var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
9845 
9846  function project(x, y) {
9847  var r = sqrt(c - 2 * n * sin$1(y)) / n;
9848  return [r * sin$1(x *= n), r0 - r * cos$1(x)];
9849  }
9850 
9851  project.invert = function(x, y) {
9852  var r0y = r0 - y;
9853  return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
9854  };
9855 
9856  return project;
9857 }
9858 
9859 function conicEqualArea() {
9860  return conicProjection(conicEqualAreaRaw)
9861  .scale(155.424)
9862  .center([0, 33.6442]);
9863 }
9864 
9865 function albers() {
9866  return conicEqualArea()
9867  .parallels([29.5, 45.5])
9868  .scale(1070)
9869  .translate([480, 250])
9870  .rotate([96, 0])
9871  .center([-0.6, 38.7]);
9872 }
9873 
9874 // The projections must have mutually exclusive clip regions on the sphere,
9875 // as this will avoid emitting interleaving lines and polygons.
9876 function multiplex(streams) {
9877  var n = streams.length;
9878  return {
9879  point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
9880  sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
9881  lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
9882  lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
9883  polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
9884  polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
9885  };
9886 }
9887 
9888 // A composite projection for the United States, configured by default for
9889 // 960×500. The projection also works quite well at 960×600 if you change the
9890 // scale to 1285 and adjust the translate accordingly. The set of standard
9891 // parallels for each region comes from USGS, which is published here:
9892 // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
9893 function albersUsa() {
9894  var cache,
9895  cacheStream,
9896  lower48 = albers(), lower48Point,
9897  alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
9898  hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
9899  point, pointStream = {point: function(x, y) { point = [x, y]; }};
9900 
9901  function albersUsa(coordinates) {
9902  var x = coordinates[0], y = coordinates[1];
9903  return point = null,
9904  (lower48Point.point(x, y), point)
9905  || (alaskaPoint.point(x, y), point)
9906  || (hawaiiPoint.point(x, y), point);
9907  }
9908 
9909  albersUsa.invert = function(coordinates) {
9910  var k = lower48.scale(),
9911  t = lower48.translate(),
9912  x = (coordinates[0] - t[0]) / k,
9913  y = (coordinates[1] - t[1]) / k;
9914  return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
9915  : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
9916  : lower48).invert(coordinates);
9917  };
9918 
9919  albersUsa.stream = function(stream) {
9920  return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
9921  };
9922 
9923  albersUsa.precision = function(_) {
9924  if (!arguments.length) return lower48.precision();
9925  lower48.precision(_), alaska.precision(_), hawaii.precision(_);
9926  return reset();
9927  };
9928 
9929  albersUsa.scale = function(_) {
9930  if (!arguments.length) return lower48.scale();
9931  lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
9932  return albersUsa.translate(lower48.translate());
9933  };
9934 
9935  albersUsa.translate = function(_) {
9936  if (!arguments.length) return lower48.translate();
9937  var k = lower48.scale(), x = +_[0], y = +_[1];
9938 
9939  lower48Point = lower48
9940  .translate(_)
9941  .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
9942  .stream(pointStream);
9943 
9944  alaskaPoint = alaska
9945  .translate([x - 0.307 * k, y + 0.201 * k])
9946  .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]])
9947  .stream(pointStream);
9948 
9949  hawaiiPoint = hawaii
9950  .translate([x - 0.205 * k, y + 0.212 * k])
9951  .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]])
9952  .stream(pointStream);
9953 
9954  return reset();
9955  };
9956 
9957  albersUsa.fitExtent = function(extent, object) {
9958  return fitExtent(albersUsa, extent, object);
9959  };
9960 
9961  albersUsa.fitSize = function(size, object) {
9962  return fitSize(albersUsa, size, object);
9963  };
9964 
9965  albersUsa.fitWidth = function(width, object) {
9966  return fitWidth(albersUsa, width, object);
9967  };
9968 
9969  albersUsa.fitHeight = function(height, object) {
9970  return fitHeight(albersUsa, height, object);
9971  };
9972 
9973  function reset() {
9974  cache = cacheStream = null;
9975  return albersUsa;
9976  }
9977 
9978  return albersUsa.scale(1070);
9979 }
9980 
9981 function azimuthalRaw(scale) {
9982  return function(x, y) {
9983  var cx = cos$1(x),
9984  cy = cos$1(y),
9985  k = scale(cx * cy);
9986  return [
9987  k * cy * sin$1(x),
9988  k * sin$1(y)
9989  ];
9990  }
9991 }
9992 
9993 function azimuthalInvert(angle) {
9994  return function(x, y) {
9995  var z = sqrt(x * x + y * y),
9996  c = angle(z),
9997  sc = sin$1(c),
9998  cc = cos$1(c);
9999  return [
10000  atan2(x * sc, z * cc),
10001  asin(z && y * sc / z)
10002  ];
10003  }
10004 }
10005 
10006 var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
10007  return sqrt(2 / (1 + cxcy));
10008 });
10009 
10010 azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
10011  return 2 * asin(z / 2);
10012 });
10013 
10014 function azimuthalEqualArea() {
10015  return projection(azimuthalEqualAreaRaw)
10016  .scale(124.75)
10017  .clipAngle(180 - 1e-3);
10018 }
10019 
10020 var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
10021  return (c = acos(c)) && c / sin$1(c);
10022 });
10023 
10024 azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
10025  return z;
10026 });
10027 
10028 function azimuthalEquidistant() {
10029  return projection(azimuthalEquidistantRaw)
10030  .scale(79.4188)
10031  .clipAngle(180 - 1e-3);
10032 }
10033 
10034 function mercatorRaw(lambda, phi) {
10035  return [lambda, log(tan((halfPi$2 + phi) / 2))];
10036 }
10037 
10038 mercatorRaw.invert = function(x, y) {
10039  return [x, 2 * atan(exp(y)) - halfPi$2];
10040 };
10041 
10042 function mercator() {
10043  return mercatorProjection(mercatorRaw)
10044  .scale(961 / tau$3);
10045 }
10046 
10047 function mercatorProjection(project) {
10048  var m = projection(project),
10049  center = m.center,
10050  scale = m.scale,
10051  translate = m.translate,
10052  clipExtent = m.clipExtent,
10053  x0 = null, y0, x1, y1; // clip extent
10054 
10055  m.scale = function(_) {
10056  return arguments.length ? (scale(_), reclip()) : scale();
10057  };
10058 
10059  m.translate = function(_) {
10060  return arguments.length ? (translate(_), reclip()) : translate();
10061  };
10062 
10063  m.center = function(_) {
10064  return arguments.length ? (center(_), reclip()) : center();
10065  };
10066 
10067  m.clipExtent = function(_) {
10068  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]];
10069  };
10070 
10071  function reclip() {
10072  var k = pi$3 * scale(),
10073  t = m(rotation(m.rotate()).invert([0, 0]));
10074  return clipExtent(x0 == null
10075  ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
10076  ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
10077  : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
10078  }
10079 
10080  return reclip();
10081 }
10082 
10083 function tany(y) {
10084  return tan((halfPi$2 + y) / 2);
10085 }
10086 
10087 function conicConformalRaw(y0, y1) {
10088  var cy0 = cos$1(y0),
10089  n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
10090  f = cy0 * pow(tany(y0), n) / n;
10091 
10092  if (!n) return mercatorRaw;
10093 
10094  function project(x, y) {
10095  if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
10096  else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
10097  var r = f / pow(tany(y), n);
10098  return [r * sin$1(n * x), f - r * cos$1(n * x)];
10099  }
10100 
10101  project.invert = function(x, y) {
10102  var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
10103  return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
10104  };
10105 
10106  return project;
10107 }
10108 
10109 function conicConformal() {
10110  return conicProjection(conicConformalRaw)
10111  .scale(109.5)
10112  .parallels([30, 30]);
10113 }
10114 
10115 function equirectangularRaw(lambda, phi) {
10116  return [lambda, phi];
10117 }
10118 
10119 equirectangularRaw.invert = equirectangularRaw;
10120 
10121 function equirectangular() {
10122  return projection(equirectangularRaw)
10123  .scale(152.63);
10124 }
10125 
10126 function conicEquidistantRaw(y0, y1) {
10127  var cy0 = cos$1(y0),
10128  n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
10129  g = cy0 / n + y0;
10130 
10131  if (abs(n) < epsilon$2) return equirectangularRaw;
10132 
10133  function project(x, y) {
10134  var gy = g - y, nx = n * x;
10135  return [gy * sin$1(nx), g - gy * cos$1(nx)];
10136  }
10137 
10138  project.invert = function(x, y) {
10139  var gy = g - y;
10140  return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
10141  };
10142 
10143  return project;
10144 }
10145 
10146 function conicEquidistant() {
10147  return conicProjection(conicEquidistantRaw)
10148  .scale(131.154)
10149  .center([0, 13.9389]);
10150 }
10151 
10152 var A1 = 1.340264,
10153  A2 = -0.081106,
10154  A3 = 0.000893,
10155  A4 = 0.003796,
10156  M = sqrt(3) / 2,
10157  iterations = 12;
10158 
10159 function equalEarthRaw(lambda, phi) {
10160  var l = asin(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
10161  return [
10162  lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
10163  l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
10164  ];
10165 }
10166 
10167 equalEarthRaw.invert = function(x, y) {
10168  var l = y, l2 = l * l, l6 = l2 * l2 * l2;
10169  for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
10170  fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
10171  fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
10172  l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
10173  if (abs(delta) < epsilon2$1) break;
10174  }
10175  return [
10176  M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
10177  asin(sin$1(l) / M)
10178  ];
10179 };
10180 
10181 function equalEarth() {
10182  return projection(equalEarthRaw)
10183  .scale(177.158);
10184 }
10185 
10186 function gnomonicRaw(x, y) {
10187  var cy = cos$1(y), k = cos$1(x) * cy;
10188  return [cy * sin$1(x) / k, sin$1(y) / k];
10189 }
10190 
10191 gnomonicRaw.invert = azimuthalInvert(atan);
10192 
10193 function gnomonic() {
10194  return projection(gnomonicRaw)
10195  .scale(144.049)
10196  .clipAngle(60);
10197 }
10198 
10199 function scaleTranslate$1(kx, ky, tx, ty) {
10200  return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
10201  point: function(x, y) {
10202  this.stream.point(x * kx + tx, y * ky + ty);
10203  }
10204  });
10205 }
10206 
10207 function identity$5() {
10208  var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform$$1 = identity$4, // scale, translate and reflect
10209  x0 = null, y0, x1, y1, // clip extent
10210  postclip = identity$4,
10211  cache,
10212  cacheStream,
10213  projection;
10214 
10215  function reset() {
10216  cache = cacheStream = null;
10217  return projection;
10218  }
10219 
10220  return projection = {
10221  stream: function(stream) {
10222  return cache && cacheStream === stream ? cache : cache = transform$$1(postclip(cacheStream = stream));
10223  },
10224  postclip: function(_) {
10225  return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
10226  },
10227  clipExtent: function(_) {
10228  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]];
10229  },
10230  scale: function(_) {
10231  return arguments.length ? (transform$$1 = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
10232  },
10233  translate: function(_) {
10234  return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
10235  },
10236  reflectX: function(_) {
10237  return arguments.length ? (transform$$1 = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
10238  },
10239  reflectY: function(_) {
10240  return arguments.length ? (transform$$1 = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
10241  },
10242  fitExtent: function(extent, object) {
10243  return fitExtent(projection, extent, object);
10244  },
10245  fitSize: function(size, object) {
10246  return fitSize(projection, size, object);
10247  },
10248  fitWidth: function(width, object) {
10249  return fitWidth(projection, width, object);
10250  },
10251  fitHeight: function(height, object) {
10252  return fitHeight(projection, height, object);
10253  }
10254  };
10255 }
10256 
10257 function naturalEarth1Raw(lambda, phi) {
10258  var phi2 = phi * phi, phi4 = phi2 * phi2;
10259  return [
10260  lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
10261  phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
10262  ];
10263 }
10264 
10265 naturalEarth1Raw.invert = function(x, y) {
10266  var phi = y, i = 25, delta;
10267  do {
10268  var phi2 = phi * phi, phi4 = phi2 * phi2;
10269  phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
10270  (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
10271  } while (abs(delta) > epsilon$2 && --i > 0);
10272  return [
10273  x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
10274  phi
10275  ];
10276 };
10277 
10278 function naturalEarth1() {
10279  return projection(naturalEarth1Raw)
10280  .scale(175.295);
10281 }
10282 
10283 function orthographicRaw(x, y) {
10284  return [cos$1(y) * sin$1(x), sin$1(y)];
10285 }
10286 
10287 orthographicRaw.invert = azimuthalInvert(asin);
10288 
10289 function orthographic() {
10290  return projection(orthographicRaw)
10291  .scale(249.5)
10292  .clipAngle(90 + epsilon$2);
10293 }
10294 
10295 function stereographicRaw(x, y) {
10296  var cy = cos$1(y), k = 1 + cos$1(x) * cy;
10297  return [cy * sin$1(x) / k, sin$1(y) / k];
10298 }
10299 
10300 stereographicRaw.invert = azimuthalInvert(function(z) {
10301  return 2 * atan(z);
10302 });
10303 
10304 function stereographic() {
10305  return projection(stereographicRaw)
10306  .scale(250)
10307  .clipAngle(142);
10308 }
10309 
10310 function transverseMercatorRaw(lambda, phi) {
10311  return [log(tan((halfPi$2 + phi) / 2)), -lambda];
10312 }
10313 
10314 transverseMercatorRaw.invert = function(x, y) {
10315  return [-y, 2 * atan(exp(x)) - halfPi$2];
10316 };
10317 
10318 function transverseMercator() {
10319  var m = mercatorProjection(transverseMercatorRaw),
10320  center = m.center,
10321  rotate = m.rotate;
10322 
10323  m.center = function(_) {
10324  return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
10325  };
10326 
10327  m.rotate = function(_) {
10328  return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
10329  };
10330 
10331  return rotate([0, 0, 90])
10332  .scale(159.155);
10333 }
10334 
10335 function defaultSeparation(a, b) {
10336  return a.parent === b.parent ? 1 : 2;
10337 }
10338 
10339 function meanX(children) {
10340  return children.reduce(meanXReduce, 0) / children.length;
10341 }
10342 
10343 function meanXReduce(x, c) {
10344  return x + c.x;
10345 }
10346 
10347 function maxY(children) {
10348  return 1 + children.reduce(maxYReduce, 0);
10349 }
10350 
10351 function maxYReduce(y, c) {
10352  return Math.max(y, c.y);
10353 }
10354 
10355 function leafLeft(node) {
10356  var children;
10357  while (children = node.children) node = children[0];
10358  return node;
10359 }
10360 
10361 function leafRight(node) {
10362  var children;
10363  while (children = node.children) node = children[children.length - 1];
10364  return node;
10365 }
10366 
10367 function cluster() {
10368  var separation = defaultSeparation,
10369  dx = 1,
10370  dy = 1,
10371  nodeSize = false;
10372 
10373  function cluster(root) {
10374  var previousNode,
10375  x = 0;
10376 
10377  // First walk, computing the initial x & y values.
10378  root.eachAfter(function(node) {
10379  var children = node.children;
10380  if (children) {
10381  node.x = meanX(children);
10382  node.y = maxY(children);
10383  } else {
10384  node.x = previousNode ? x += separation(node, previousNode) : 0;
10385  node.y = 0;
10386  previousNode = node;
10387  }
10388  });
10389 
10390  var left = leafLeft(root),
10391  right = leafRight(root),
10392  x0 = left.x - separation(left, right) / 2,
10393  x1 = right.x + separation(right, left) / 2;
10394 
10395  // Second walk, normalizing x & y to the desired size.
10396  return root.eachAfter(nodeSize ? function(node) {
10397  node.x = (node.x - root.x) * dx;
10398  node.y = (root.y - node.y) * dy;
10399  } : function(node) {
10400  node.x = (node.x - x0) / (x1 - x0) * dx;
10401  node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
10402  });
10403  }
10404 
10405  cluster.separation = function(x) {
10406  return arguments.length ? (separation = x, cluster) : separation;
10407  };
10408 
10409  cluster.size = function(x) {
10410  return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
10411  };
10412 
10413  cluster.nodeSize = function(x) {
10414  return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
10415  };
10416 
10417  return cluster;
10418 }
10419 
10420 function count(node) {
10421  var sum = 0,
10422  children = node.children,
10423  i = children && children.length;
10424  if (!i) sum = 1;
10425  else while (--i >= 0) sum += children[i].value;
10426  node.value = sum;
10427 }
10428 
10429 function node_count() {
10430  return this.eachAfter(count);
10431 }
10432 
10433 function node_each(callback) {
10434  var node = this, current, next = [node], children, i, n;
10435  do {
10436  current = next.reverse(), next = [];
10437  while (node = current.pop()) {
10438  callback(node), children = node.children;
10439  if (children) for (i = 0, n = children.length; i < n; ++i) {
10440  next.push(children[i]);
10441  }
10442  }
10443  } while (next.length);
10444  return this;
10445 }
10446 
10447 function node_eachBefore(callback) {
10448  var node = this, nodes = [node], children, i;
10449  while (node = nodes.pop()) {
10450  callback(node), children = node.children;
10451  if (children) for (i = children.length - 1; i >= 0; --i) {
10452  nodes.push(children[i]);
10453  }
10454  }
10455  return this;
10456 }
10457 
10458 function node_eachAfter(callback) {
10459  var node = this, nodes = [node], next = [], children, i, n;
10460  while (node = nodes.pop()) {
10461  next.push(node), children = node.children;
10462  if (children) for (i = 0, n = children.length; i < n; ++i) {
10463  nodes.push(children[i]);
10464  }
10465  }
10466  while (node = next.pop()) {
10467  callback(node);
10468  }
10469  return this;
10470 }
10471 
10472 function node_sum(value) {
10473  return this.eachAfter(function(node) {
10474  var sum = +value(node.data) || 0,
10475  children = node.children,
10476  i = children && children.length;
10477  while (--i >= 0) sum += children[i].value;
10478  node.value = sum;
10479  });
10480 }
10481 
10482 function node_sort(compare) {
10483  return this.eachBefore(function(node) {
10484  if (node.children) {
10485  node.children.sort(compare);
10486  }
10487  });
10488 }
10489 
10490 function node_path(end) {
10491  var start = this,
10492  ancestor = leastCommonAncestor(start, end),
10493  nodes = [start];
10494  while (start !== ancestor) {
10495  start = start.parent;
10496  nodes.push(start);
10497  }
10498  var k = nodes.length;
10499  while (end !== ancestor) {
10500  nodes.splice(k, 0, end);
10501  end = end.parent;
10502  }
10503  return nodes;
10504 }
10505 
10506 function leastCommonAncestor(a, b) {
10507  if (a === b) return a;
10508  var aNodes = a.ancestors(),
10509  bNodes = b.ancestors(),
10510  c = null;
10511  a = aNodes.pop();
10512  b = bNodes.pop();
10513  while (a === b) {
10514  c = a;
10515  a = aNodes.pop();
10516  b = bNodes.pop();
10517  }
10518  return c;
10519 }
10520 
10521 function node_ancestors() {
10522  var node = this, nodes = [node];
10523  while (node = node.parent) {
10524  nodes.push(node);
10525  }
10526  return nodes;
10527 }
10528 
10529 function node_descendants() {
10530  var nodes = [];
10531  this.each(function(node) {
10532  nodes.push(node);
10533  });
10534  return nodes;
10535 }
10536 
10537 function node_leaves() {
10538  var leaves = [];
10539  this.eachBefore(function(node) {
10540  if (!node.children) {
10541  leaves.push(node);
10542  }
10543  });
10544  return leaves;
10545 }
10546 
10547 function node_links() {
10548  var root = this, links = [];
10549  root.each(function(node) {
10550  if (node !== root) { // Don’t include the root’s parent, if any.
10551  links.push({source: node.parent, target: node});
10552  }
10553  });
10554  return links;
10555 }
10556 
10557 function hierarchy(data, children) {
10558  var root = new Node(data),
10559  valued = +data.value && (root.value = data.value),
10560  node,
10561  nodes = [root],
10562  child,
10563  childs,
10564  i,
10565  n;
10566 
10567  if (children == null) children = defaultChildren;
10568 
10569  while (node = nodes.pop()) {
10570  if (valued) node.value = +node.data.value;
10571  if ((childs = children(node.data)) && (n = childs.length)) {
10572  node.children = new Array(n);
10573  for (i = n - 1; i >= 0; --i) {
10574  nodes.push(child = node.children[i] = new Node(childs[i]));
10575  child.parent = node;
10576  child.depth = node.depth + 1;
10577  }
10578  }
10579  }
10580 
10581  return root.eachBefore(computeHeight);
10582 }
10583 
10584 function node_copy() {
10585  return hierarchy(this).eachBefore(copyData);
10586 }
10587 
10588 function defaultChildren(d) {
10589  return d.children;
10590 }
10591 
10592 function copyData(node) {
10593  node.data = node.data.data;
10594 }
10595 
10596 function computeHeight(node) {
10597  var height = 0;
10598  do node.height = height;
10599  while ((node = node.parent) && (node.height < ++height));
10600 }
10601 
10602 function Node(data) {
10603  this.data = data;
10604  this.depth =
10605  this.height = 0;
10606  this.parent = null;
10607 }
10608 
10609 Node.prototype = hierarchy.prototype = {
10610  constructor: Node,
10611  count: node_count,
10612  each: node_each,
10613  eachAfter: node_eachAfter,
10614  eachBefore: node_eachBefore,
10615  sum: node_sum,
10616  sort: node_sort,
10617  path: node_path,
10618  ancestors: node_ancestors,
10619  descendants: node_descendants,
10620  leaves: node_leaves,
10621  links: node_links,
10622  copy: node_copy
10623 };
10624 
10625 var slice$4 = Array.prototype.slice;
10626 
10627 function shuffle$1(array) {
10628  var m = array.length,
10629  t,
10630  i;
10631 
10632  while (m) {
10633  i = Math.random() * m-- | 0;
10634  t = array[m];
10635  array[m] = array[i];
10636  array[i] = t;
10637  }
10638 
10639  return array;
10640 }
10641 
10642 function enclose(circles) {
10643  var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
10644 
10645  while (i < n) {
10646  p = circles[i];
10647  if (e && enclosesWeak(e, p)) ++i;
10648  else e = encloseBasis(B = extendBasis(B, p)), i = 0;
10649  }
10650 
10651  return e;
10652 }
10653 
10654 function extendBasis(B, p) {
10655  var i, j;
10656 
10657  if (enclosesWeakAll(p, B)) return [p];
10658 
10659  // If we get here then B must have at least one element.
10660  for (i = 0; i < B.length; ++i) {
10661  if (enclosesNot(p, B[i])
10662  && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
10663  return [B[i], p];
10664  }
10665  }
10666 
10667  // If we get here then B must have at least two elements.
10668  for (i = 0; i < B.length - 1; ++i) {
10669  for (j = i + 1; j < B.length; ++j) {
10670  if (enclosesNot(encloseBasis2(B[i], B[j]), p)
10671  && enclosesNot(encloseBasis2(B[i], p), B[j])
10672  && enclosesNot(encloseBasis2(B[j], p), B[i])
10673  && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
10674  return [B[i], B[j], p];
10675  }
10676  }
10677  }
10678 
10679  // If we get here then something is very wrong.
10680  throw new Error;
10681 }
10682 
10683 function enclosesNot(a, b) {
10684  var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
10685  return dr < 0 || dr * dr < dx * dx + dy * dy;
10686 }
10687 
10688 function enclosesWeak(a, b) {
10689  var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10690  return dr > 0 && dr * dr > dx * dx + dy * dy;
10691 }
10692 
10693 function enclosesWeakAll(a, B) {
10694  for (var i = 0; i < B.length; ++i) {
10695  if (!enclosesWeak(a, B[i])) {
10696  return false;
10697  }
10698  }
10699  return true;
10700 }
10701 
10702 function encloseBasis(B) {
10703  switch (B.length) {
10704  case 1: return encloseBasis1(B[0]);
10705  case 2: return encloseBasis2(B[0], B[1]);
10706  case 3: return encloseBasis3(B[0], B[1], B[2]);
10707  }
10708 }
10709 
10710 function encloseBasis1(a) {
10711  return {
10712  x: a.x,
10713  y: a.y,
10714  r: a.r
10715  };
10716 }
10717 
10718 function encloseBasis2(a, b) {
10719  var x1 = a.x, y1 = a.y, r1 = a.r,
10720  x2 = b.x, y2 = b.y, r2 = b.r,
10721  x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
10722  l = Math.sqrt(x21 * x21 + y21 * y21);
10723  return {
10724  x: (x1 + x2 + x21 / l * r21) / 2,
10725  y: (y1 + y2 + y21 / l * r21) / 2,
10726  r: (l + r1 + r2) / 2
10727  };
10728 }
10729 
10730 function encloseBasis3(a, b, c) {
10731  var x1 = a.x, y1 = a.y, r1 = a.r,
10732  x2 = b.x, y2 = b.y, r2 = b.r,
10733  x3 = c.x, y3 = c.y, r3 = c.r,
10734  a2 = x1 - x2,
10735  a3 = x1 - x3,
10736  b2 = y1 - y2,
10737  b3 = y1 - y3,
10738  c2 = r2 - r1,
10739  c3 = r3 - r1,
10740  d1 = x1 * x1 + y1 * y1 - r1 * r1,
10741  d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
10742  d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
10743  ab = a3 * b2 - a2 * b3,
10744  xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
10745  xb = (b3 * c2 - b2 * c3) / ab,
10746  ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
10747  yb = (a2 * c3 - a3 * c2) / ab,
10748  A = xb * xb + yb * yb - 1,
10749  B = 2 * (r1 + xa * xb + ya * yb),
10750  C = xa * xa + ya * ya - r1 * r1,
10751  r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
10752  return {
10753  x: x1 + xa + xb * r,
10754  y: y1 + ya + yb * r,
10755  r: r
10756  };
10757 }
10758 
10759 function place(b, a, c) {
10760  var dx = b.x - a.x, x, a2,
10761  dy = b.y - a.y, y, b2,
10762  d2 = dx * dx + dy * dy;
10763  if (d2) {
10764  a2 = a.r + c.r, a2 *= a2;
10765  b2 = b.r + c.r, b2 *= b2;
10766  if (a2 > b2) {
10767  x = (d2 + b2 - a2) / (2 * d2);
10768  y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
10769  c.x = b.x - x * dx - y * dy;
10770  c.y = b.y - x * dy + y * dx;
10771  } else {
10772  x = (d2 + a2 - b2) / (2 * d2);
10773  y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
10774  c.x = a.x + x * dx - y * dy;
10775  c.y = a.y + x * dy + y * dx;
10776  }
10777  } else {
10778  c.x = a.x + c.r;
10779  c.y = a.y;
10780  }
10781 }
10782 
10783 function intersects(a, b) {
10784  var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
10785  return dr > 0 && dr * dr > dx * dx + dy * dy;
10786 }
10787 
10788 function score(node) {
10789  var a = node._,
10790  b = node.next._,
10791  ab = a.r + b.r,
10792  dx = (a.x * b.r + b.x * a.r) / ab,
10793  dy = (a.y * b.r + b.y * a.r) / ab;
10794  return dx * dx + dy * dy;
10795 }
10796 
10797 function Node$1(circle) {
10798  this._ = circle;
10799  this.next = null;
10800  this.previous = null;
10801 }
10802 
10803 function packEnclose(circles) {
10804  if (!(n = circles.length)) return 0;
10805 
10806  var a, b, c, n, aa, ca, i, j, k, sj, sk;
10807 
10808  // Place the first circle.
10809  a = circles[0], a.x = 0, a.y = 0;
10810  if (!(n > 1)) return a.r;
10811 
10812  // Place the second circle.
10813  b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
10814  if (!(n > 2)) return a.r + b.r;
10815 
10816  // Place the third circle.
10817  place(b, a, c = circles[2]);
10818 
10819  // Initialize the front-chain using the first three circles a, b and c.
10820  a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
10821  a.next = c.previous = b;
10822  b.next = a.previous = c;
10823  c.next = b.previous = a;
10824 
10825  // Attempt to place each remaining circle…
10826  pack: for (i = 3; i < n; ++i) {
10827  place(a._, b._, c = circles[i]), c = new Node$1(c);
10828 
10829  // Find the closest intersecting circle on the front-chain, if any.
10830  // “Closeness” is determined by linear distance along the front-chain.
10831  // “Ahead” or “behind” is likewise determined by linear distance.
10832  j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
10833  do {
10834  if (sj <= sk) {
10835  if (intersects(j._, c._)) {
10836  b = j, a.next = b, b.previous = a, --i;
10837  continue pack;
10838  }
10839  sj += j._.r, j = j.next;
10840  } else {
10841  if (intersects(k._, c._)) {
10842  a = k, a.next = b, b.previous = a, --i;
10843  continue pack;
10844  }
10845  sk += k._.r, k = k.previous;
10846  }
10847  } while (j !== k.next);
10848 
10849  // Success! Insert the new circle c between a and b.
10850  c.previous = a, c.next = b, a.next = b.previous = b = c;
10851 
10852  // Compute the new closest circle pair to the centroid.
10853  aa = score(a);
10854  while ((c = c.next) !== b) {
10855  if ((ca = score(c)) < aa) {
10856  a = c, aa = ca;
10857  }
10858  }
10859  b = a.next;
10860  }
10861 
10862  // Compute the enclosing circle of the front chain.
10863  a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
10864 
10865  // Translate the circles to put the enclosing circle around the origin.
10866  for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
10867 
10868  return c.r;
10869 }
10870 
10871 function siblings(circles) {
10872  packEnclose(circles);
10873  return circles;
10874 }
10875 
10876 function optional(f) {
10877  return f == null ? null : required(f);
10878 }
10879 
10880 function required(f) {
10881  if (typeof f !== "function") throw new Error;
10882  return f;
10883 }
10884 
10885 function constantZero() {
10886  return 0;
10887 }
10888 
10889 function constant$9(x) {
10890  return function() {
10891  return x;
10892  };
10893 }
10894 
10895 function defaultRadius$1(d) {
10896  return Math.sqrt(d.value);
10897 }
10898 
10899 function index$2() {
10900  var radius = null,
10901  dx = 1,
10902  dy = 1,
10903  padding = constantZero;
10904 
10905  function pack(root) {
10906  root.x = dx / 2, root.y = dy / 2;
10907  if (radius) {
10908  root.eachBefore(radiusLeaf(radius))
10909  .eachAfter(packChildren(padding, 0.5))
10910  .eachBefore(translateChild(1));
10911  } else {
10912  root.eachBefore(radiusLeaf(defaultRadius$1))
10913  .eachAfter(packChildren(constantZero, 1))
10914  .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
10915  .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
10916  }
10917  return root;
10918  }
10919 
10920  pack.radius = function(x) {
10921  return arguments.length ? (radius = optional(x), pack) : radius;
10922  };
10923 
10924  pack.size = function(x) {
10925  return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
10926  };
10927 
10928  pack.padding = function(x) {
10929  return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
10930  };
10931 
10932  return pack;
10933 }
10934 
10935 function radiusLeaf(radius) {
10936  return function(node) {
10937  if (!node.children) {
10938  node.r = Math.max(0, +radius(node) || 0);
10939  }
10940  };
10941 }
10942 
10943 function packChildren(padding, k) {
10944  return function(node) {
10945  if (children = node.children) {
10946  var children,
10947  i,
10948  n = children.length,
10949  r = padding(node) * k || 0,
10950  e;
10951 
10952  if (r) for (i = 0; i < n; ++i) children[i].r += r;
10953  e = packEnclose(children);
10954  if (r) for (i = 0; i < n; ++i) children[i].r -= r;
10955  node.r = e + r;
10956  }
10957  };
10958 }
10959 
10960 function translateChild(k) {
10961  return function(node) {
10962  var parent = node.parent;
10963  node.r *= k;
10964  if (parent) {
10965  node.x = parent.x + k * node.x;
10966  node.y = parent.y + k * node.y;
10967  }
10968  };
10969 }
10970 
10971 function roundNode(node) {
10972  node.x0 = Math.round(node.x0);
10973  node.y0 = Math.round(node.y0);
10974  node.x1 = Math.round(node.x1);
10975  node.y1 = Math.round(node.y1);
10976 }
10977 
10978 function treemapDice(parent, x0, y0, x1, y1) {
10979  var nodes = parent.children,
10980  node,
10981  i = -1,
10982  n = nodes.length,
10983  k = parent.value && (x1 - x0) / parent.value;
10984 
10985  while (++i < n) {
10986  node = nodes[i], node.y0 = y0, node.y1 = y1;
10987  node.x0 = x0, node.x1 = x0 += node.value * k;
10988  }
10989 }
10990 
10991 function partition() {
10992  var dx = 1,
10993  dy = 1,
10994  padding = 0,
10995  round = false;
10996 
10997  function partition(root) {
10998  var n = root.height + 1;
10999  root.x0 =
11000  root.y0 = padding;
11001  root.x1 = dx;
11002  root.y1 = dy / n;
11003  root.eachBefore(positionNode(dy, n));
11004  if (round) root.eachBefore(roundNode);
11005  return root;
11006  }
11007 
11008  function positionNode(dy, n) {
11009  return function(node) {
11010  if (node.children) {
11011  treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
11012  }
11013  var x0 = node.x0,
11014  y0 = node.y0,
11015  x1 = node.x1 - padding,
11016  y1 = node.y1 - padding;
11017  if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11018  if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11019  node.x0 = x0;
11020  node.y0 = y0;
11021  node.x1 = x1;
11022  node.y1 = y1;
11023  };
11024  }
11025 
11026  partition.round = function(x) {
11027  return arguments.length ? (round = !!x, partition) : round;
11028  };
11029 
11030  partition.size = function(x) {
11031  return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
11032  };
11033 
11034  partition.padding = function(x) {
11035  return arguments.length ? (padding = +x, partition) : padding;
11036  };
11037 
11038  return partition;
11039 }
11040 
11041 var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
11042  preroot = {depth: -1},
11043  ambiguous = {};
11044 
11045 function defaultId(d) {
11046  return d.id;
11047 }
11048 
11049 function defaultParentId(d) {
11050  return d.parentId;
11051 }
11052 
11053 function stratify() {
11054  var id = defaultId,
11055  parentId = defaultParentId;
11056 
11057  function stratify(data) {
11058  var d,
11059  i,
11060  n = data.length,
11061  root,
11062  parent,
11063  node,
11064  nodes = new Array(n),
11065  nodeId,
11066  nodeKey,
11067  nodeByKey = {};
11068 
11069  for (i = 0; i < n; ++i) {
11070  d = data[i], node = nodes[i] = new Node(d);
11071  if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
11072  nodeKey = keyPrefix$1 + (node.id = nodeId);
11073  nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
11074  }
11075  }
11076 
11077  for (i = 0; i < n; ++i) {
11078  node = nodes[i], nodeId = parentId(data[i], i, data);
11079  if (nodeId == null || !(nodeId += "")) {
11080  if (root) throw new Error("multiple roots");
11081  root = node;
11082  } else {
11083  parent = nodeByKey[keyPrefix$1 + nodeId];
11084  if (!parent) throw new Error("missing: " + nodeId);
11085  if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
11086  if (parent.children) parent.children.push(node);
11087  else parent.children = [node];
11088  node.parent = parent;
11089  }
11090  }
11091 
11092  if (!root) throw new Error("no root");
11093  root.parent = preroot;
11094  root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
11095  root.parent = null;
11096  if (n > 0) throw new Error("cycle");
11097 
11098  return root;
11099  }
11100 
11101  stratify.id = function(x) {
11102  return arguments.length ? (id = required(x), stratify) : id;
11103  };
11104 
11105  stratify.parentId = function(x) {
11106  return arguments.length ? (parentId = required(x), stratify) : parentId;
11107  };
11108 
11109  return stratify;
11110 }
11111 
11112 function defaultSeparation$1(a, b) {
11113  return a.parent === b.parent ? 1 : 2;
11114 }
11115 
11116 // function radialSeparation(a, b) {
11117 // return (a.parent === b.parent ? 1 : 2) / a.depth;
11118 // }
11119 
11120 // This function is used to traverse the left contour of a subtree (or
11121 // subforest). It returns the successor of v on this contour. This successor is
11122 // either given by the leftmost child of v or by the thread of v. The function
11123 // returns null if and only if v is on the highest level of its subtree.
11124 function nextLeft(v) {
11125  var children = v.children;
11126  return children ? children[0] : v.t;
11127 }
11128 
11129 // This function works analogously to nextLeft.
11130 function nextRight(v) {
11131  var children = v.children;
11132  return children ? children[children.length - 1] : v.t;
11133 }
11134 
11135 // Shifts the current subtree rooted at w+. This is done by increasing
11136 // prelim(w+) and mod(w+) by shift.
11137 function moveSubtree(wm, wp, shift) {
11138  var change = shift / (wp.i - wm.i);
11139  wp.c -= change;
11140  wp.s += shift;
11141  wm.c += change;
11142  wp.z += shift;
11143  wp.m += shift;
11144 }
11145 
11146 // All other shifts, applied to the smaller subtrees between w- and w+, are
11147 // performed by this function. To prepare the shifts, we have to adjust
11148 // change(w+), shift(w+), and change(w-).
11149 function executeShifts(v) {
11150  var shift = 0,
11151  change = 0,
11152  children = v.children,
11153  i = children.length,
11154  w;
11155  while (--i >= 0) {
11156  w = children[i];
11157  w.z += shift;
11158  w.m += shift;
11159  shift += w.s + (change += w.c);
11160  }
11161 }
11162 
11163 // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
11164 // returns the specified (default) ancestor.
11165 function nextAncestor(vim, v, ancestor) {
11166  return vim.a.parent === v.parent ? vim.a : ancestor;
11167 }
11168 
11169 function TreeNode(node, i) {
11170  this._ = node;
11171  this.parent = null;
11172  this.children = null;
11173  this.A = null; // default ancestor
11174  this.a = this; // ancestor
11175  this.z = 0; // prelim
11176  this.m = 0; // mod
11177  this.c = 0; // change
11178  this.s = 0; // shift
11179  this.t = null; // thread
11180  this.i = i; // number
11181 }
11182 
11183 TreeNode.prototype = Object.create(Node.prototype);
11184 
11185 function treeRoot(root) {
11186  var tree = new TreeNode(root, 0),
11187  node,
11188  nodes = [tree],
11189  child,
11190  children,
11191  i,
11192  n;
11193 
11194  while (node = nodes.pop()) {
11195  if (children = node._.children) {
11196  node.children = new Array(n = children.length);
11197  for (i = n - 1; i >= 0; --i) {
11198  nodes.push(child = node.children[i] = new TreeNode(children[i], i));
11199  child.parent = node;
11200  }
11201  }
11202  }
11203 
11204  (tree.parent = new TreeNode(null, 0)).children = [tree];
11205  return tree;
11206 }
11207 
11208 // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
11209 function tree() {
11210  var separation = defaultSeparation$1,
11211  dx = 1,
11212  dy = 1,
11213  nodeSize = null;
11214 
11215  function tree(root) {
11216  var t = treeRoot(root);
11217 
11218  // Compute the layout using Buchheim et al.’s algorithm.
11219  t.eachAfter(firstWalk), t.parent.m = -t.z;
11220  t.eachBefore(secondWalk);
11221 
11222  // If a fixed node size is specified, scale x and y.
11223  if (nodeSize) root.eachBefore(sizeNode);
11224 
11225  // If a fixed tree size is specified, scale x and y based on the extent.
11226  // Compute the left-most, right-most, and depth-most nodes for extents.
11227  else {
11228  var left = root,
11229  right = root,
11230  bottom = root;
11231  root.eachBefore(function(node) {
11232  if (node.x < left.x) left = node;
11233  if (node.x > right.x) right = node;
11234  if (node.depth > bottom.depth) bottom = node;
11235  });
11236  var s = left === right ? 1 : separation(left, right) / 2,
11237  tx = s - left.x,
11238  kx = dx / (right.x + s + tx),
11239  ky = dy / (bottom.depth || 1);
11240  root.eachBefore(function(node) {
11241  node.x = (node.x + tx) * kx;
11242  node.y = node.depth * ky;
11243  });
11244  }
11245 
11246  return root;
11247  }
11248 
11249  // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
11250  // applied recursively to the children of v, as well as the function
11251  // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
11252  // node v is placed to the midpoint of its outermost children.
11253  function firstWalk(v) {
11254  var children = v.children,
11255  siblings = v.parent.children,
11256  w = v.i ? siblings[v.i - 1] : null;
11257  if (children) {
11258  executeShifts(v);
11259  var midpoint = (children[0].z + children[children.length - 1].z) / 2;
11260  if (w) {
11261  v.z = w.z + separation(v._, w._);
11262  v.m = v.z - midpoint;
11263  } else {
11264  v.z = midpoint;
11265  }
11266  } else if (w) {
11267  v.z = w.z + separation(v._, w._);
11268  }
11269  v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
11270  }
11271 
11272  // Computes all real x-coordinates by summing up the modifiers recursively.
11273  function secondWalk(v) {
11274  v._.x = v.z + v.parent.m;
11275  v.m += v.parent.m;
11276  }
11277 
11278  // The core of the algorithm. Here, a new subtree is combined with the
11279  // previous subtrees. Threads are used to traverse the inside and outside
11280  // contours of the left and right subtree up to the highest common level. The
11281  // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
11282  // superscript o means outside and i means inside, the subscript - means left
11283  // subtree and + means right subtree. For summing up the modifiers along the
11284  // contour, we use respective variables si+, si-, so-, and so+. Whenever two
11285  // nodes of the inside contours conflict, we compute the left one of the
11286  // greatest uncommon ancestors using the function ANCESTOR and call MOVE
11287  // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
11288  // Finally, we add a new thread (if necessary).
11289  function apportion(v, w, ancestor) {
11290  if (w) {
11291  var vip = v,
11292  vop = v,
11293  vim = w,
11294  vom = vip.parent.children[0],
11295  sip = vip.m,
11296  sop = vop.m,
11297  sim = vim.m,
11298  som = vom.m,
11299  shift;
11300  while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
11301  vom = nextLeft(vom);
11302  vop = nextRight(vop);
11303  vop.a = v;
11304  shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
11305  if (shift > 0) {
11306  moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
11307  sip += shift;
11308  sop += shift;
11309  }
11310  sim += vim.m;
11311  sip += vip.m;
11312  som += vom.m;
11313  sop += vop.m;
11314  }
11315  if (vim && !nextRight(vop)) {
11316  vop.t = vim;
11317  vop.m += sim - sop;
11318  }
11319  if (vip && !nextLeft(vom)) {
11320  vom.t = vip;
11321  vom.m += sip - som;
11322  ancestor = v;
11323  }
11324  }
11325  return ancestor;
11326  }
11327 
11328  function sizeNode(node) {
11329  node.x *= dx;
11330  node.y = node.depth * dy;
11331  }
11332 
11333  tree.separation = function(x) {
11334  return arguments.length ? (separation = x, tree) : separation;
11335  };
11336 
11337  tree.size = function(x) {
11338  return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
11339  };
11340 
11341  tree.nodeSize = function(x) {
11342  return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
11343  };
11344 
11345  return tree;
11346 }
11347 
11348 function treemapSlice(parent, x0, y0, x1, y1) {
11349  var nodes = parent.children,
11350  node,
11351  i = -1,
11352  n = nodes.length,
11353  k = parent.value && (y1 - y0) / parent.value;
11354 
11355  while (++i < n) {
11356  node = nodes[i], node.x0 = x0, node.x1 = x1;
11357  node.y0 = y0, node.y1 = y0 += node.value * k;
11358  }
11359 }
11360 
11361 var phi = (1 + Math.sqrt(5)) / 2;
11362 
11363 function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
11364  var rows = [],
11365  nodes = parent.children,
11366  row,
11367  nodeValue,
11368  i0 = 0,
11369  i1 = 0,
11370  n = nodes.length,
11371  dx, dy,
11372  value = parent.value,
11373  sumValue,
11374  minValue,
11375  maxValue,
11376  newRatio,
11377  minRatio,
11378  alpha,
11379  beta;
11380 
11381  while (i0 < n) {
11382  dx = x1 - x0, dy = y1 - y0;
11383 
11384  // Find the next non-empty node.
11385  do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
11386  minValue = maxValue = sumValue;
11387  alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
11388  beta = sumValue * sumValue * alpha;
11389  minRatio = Math.max(maxValue / beta, beta / minValue);
11390 
11391  // Keep adding nodes while the aspect ratio maintains or improves.
11392  for (; i1 < n; ++i1) {
11393  sumValue += nodeValue = nodes[i1].value;
11394  if (nodeValue < minValue) minValue = nodeValue;
11395  if (nodeValue > maxValue) maxValue = nodeValue;
11396  beta = sumValue * sumValue * alpha;
11397  newRatio = Math.max(maxValue / beta, beta / minValue);
11398  if (newRatio > minRatio) { sumValue -= nodeValue; break; }
11399  minRatio = newRatio;
11400  }
11401 
11402  // Position and record the row orientation.
11403  rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
11404  if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
11405  else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
11406  value -= sumValue, i0 = i1;
11407  }
11408 
11409  return rows;
11410 }
11411 
11412 var squarify = (function custom(ratio) {
11413 
11414  function squarify(parent, x0, y0, x1, y1) {
11415  squarifyRatio(ratio, parent, x0, y0, x1, y1);
11416  }
11417 
11418  squarify.ratio = function(x) {
11419  return custom((x = +x) > 1 ? x : 1);
11420  };
11421 
11422  return squarify;
11423 })(phi);
11424 
11425 function index$3() {
11426  var tile = squarify,
11427  round = false,
11428  dx = 1,
11429  dy = 1,
11430  paddingStack = [0],
11431  paddingInner = constantZero,
11432  paddingTop = constantZero,
11433  paddingRight = constantZero,
11434  paddingBottom = constantZero,
11435  paddingLeft = constantZero;
11436 
11437  function treemap(root) {
11438  root.x0 =
11439  root.y0 = 0;
11440  root.x1 = dx;
11441  root.y1 = dy;
11442  root.eachBefore(positionNode);
11443  paddingStack = [0];
11444  if (round) root.eachBefore(roundNode);
11445  return root;
11446  }
11447 
11448  function positionNode(node) {
11449  var p = paddingStack[node.depth],
11450  x0 = node.x0 + p,
11451  y0 = node.y0 + p,
11452  x1 = node.x1 - p,
11453  y1 = node.y1 - p;
11454  if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11455  if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11456  node.x0 = x0;
11457  node.y0 = y0;
11458  node.x1 = x1;
11459  node.y1 = y1;
11460  if (node.children) {
11461  p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
11462  x0 += paddingLeft(node) - p;
11463  y0 += paddingTop(node) - p;
11464  x1 -= paddingRight(node) - p;
11465  y1 -= paddingBottom(node) - p;
11466  if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
11467  if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
11468  tile(node, x0, y0, x1, y1);
11469  }
11470  }
11471 
11472  treemap.round = function(x) {
11473  return arguments.length ? (round = !!x, treemap) : round;
11474  };
11475 
11476  treemap.size = function(x) {
11477  return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
11478  };
11479 
11480  treemap.tile = function(x) {
11481  return arguments.length ? (tile = required(x), treemap) : tile;
11482  };
11483 
11484  treemap.padding = function(x) {
11485  return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
11486  };
11487 
11488  treemap.paddingInner = function(x) {
11489  return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
11490  };
11491 
11492  treemap.paddingOuter = function(x) {
11493  return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
11494  };
11495 
11496  treemap.paddingTop = function(x) {
11497  return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
11498  };
11499 
11500  treemap.paddingRight = function(x) {
11501  return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
11502  };
11503 
11504  treemap.paddingBottom = function(x) {
11505  return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
11506  };
11507 
11508  treemap.paddingLeft = function(x) {
11509  return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
11510  };
11511 
11512  return treemap;
11513 }
11514 
11515 function binary(parent, x0, y0, x1, y1) {
11516  var nodes = parent.children,
11517  i, n = nodes.length,
11518  sum, sums = new Array(n + 1);
11519 
11520  for (sums[0] = sum = i = 0; i < n; ++i) {
11521  sums[i + 1] = sum += nodes[i].value;
11522  }
11523 
11524  partition(0, n, parent.value, x0, y0, x1, y1);
11525 
11526  function partition(i, j, value, x0, y0, x1, y1) {
11527  if (i >= j - 1) {
11528  var node = nodes[i];
11529  node.x0 = x0, node.y0 = y0;
11530  node.x1 = x1, node.y1 = y1;
11531  return;
11532  }
11533 
11534  var valueOffset = sums[i],
11535  valueTarget = (value / 2) + valueOffset,
11536  k = i + 1,
11537  hi = j - 1;
11538 
11539  while (k < hi) {
11540  var mid = k + hi >>> 1;
11541  if (sums[mid] < valueTarget) k = mid + 1;
11542  else hi = mid;
11543  }
11544 
11545  if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
11546 
11547  var valueLeft = sums[k] - valueOffset,
11548  valueRight = value - valueLeft;
11549 
11550  if ((x1 - x0) > (y1 - y0)) {
11551  var xk = (x0 * valueRight + x1 * valueLeft) / value;
11552  partition(i, k, valueLeft, x0, y0, xk, y1);
11553  partition(k, j, valueRight, xk, y0, x1, y1);
11554  } else {
11555  var yk = (y0 * valueRight + y1 * valueLeft) / value;
11556  partition(i, k, valueLeft, x0, y0, x1, yk);
11557  partition(k, j, valueRight, x0, yk, x1, y1);
11558  }
11559  }
11560 }
11561 
11562 function sliceDice(parent, x0, y0, x1, y1) {
11563  (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
11564 }
11565 
11566 var resquarify = (function custom(ratio) {
11567 
11568  function resquarify(parent, x0, y0, x1, y1) {
11569  if ((rows = parent._squarify) && (rows.ratio === ratio)) {
11570  var rows,
11571  row,
11572  nodes,
11573  i,
11574  j = -1,
11575  n,
11576  m = rows.length,
11577  value = parent.value;
11578 
11579  while (++j < m) {
11580  row = rows[j], nodes = row.children;
11581  for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
11582  if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
11583  else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
11584  value -= row.value;
11585  }
11586  } else {
11587  parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
11588  rows.ratio = ratio;
11589  }
11590  }
11591 
11592  resquarify.ratio = function(x) {
11593  return custom((x = +x) > 1 ? x : 1);
11594  };
11595 
11596  return resquarify;
11597 })(phi);
11598 
11599 function area$2(polygon) {
11600  var i = -1,
11601  n = polygon.length,
11602  a,
11603  b = polygon[n - 1],
11604  area = 0;
11605 
11606  while (++i < n) {
11607  a = b;
11608  b = polygon[i];
11609  area += a[1] * b[0] - a[0] * b[1];
11610  }
11611 
11612  return area / 2;
11613 }
11614 
11615 function centroid$1(polygon) {
11616  var i = -1,
11617  n = polygon.length,
11618  x = 0,
11619  y = 0,
11620  a,
11621  b = polygon[n - 1],
11622  c,
11623  k = 0;
11624 
11625  while (++i < n) {
11626  a = b;
11627  b = polygon[i];
11628  k += c = a[0] * b[1] - b[0] * a[1];
11629  x += (a[0] + b[0]) * c;
11630  y += (a[1] + b[1]) * c;
11631  }
11632 
11633  return k *= 3, [x / k, y / k];
11634 }
11635 
11636 // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
11637 // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
11638 // right, +y is up). Returns a positive value if ABC is counter-clockwise,
11639 // negative if clockwise, and zero if the points are collinear.
11640 function cross$1(a, b, c) {
11641  return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
11642 }
11643 
11644 function lexicographicOrder(a, b) {
11645  return a[0] - b[0] || a[1] - b[1];
11646 }
11647 
11648 // Computes the upper convex hull per the monotone chain algorithm.
11649 // Assumes points.length >= 3, is sorted by x, unique in y.
11650 // Returns an array of indices into points in left-to-right order.
11651 function computeUpperHullIndexes(points) {
11652  var n = points.length,
11653  indexes = [0, 1],
11654  size = 2;
11655 
11656  for (var i = 2; i < n; ++i) {
11657  while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
11658  indexes[size++] = i;
11659  }
11660 
11661  return indexes.slice(0, size); // remove popped points
11662 }
11663 
11664 function hull(points) {
11665  if ((n = points.length) < 3) return null;
11666 
11667  var i,
11668  n,
11669  sortedPoints = new Array(n),
11670  flippedPoints = new Array(n);
11671 
11672  for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
11673  sortedPoints.sort(lexicographicOrder);
11674  for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
11675 
11676  var upperIndexes = computeUpperHullIndexes(sortedPoints),
11677  lowerIndexes = computeUpperHullIndexes(flippedPoints);
11678 
11679  // Construct the hull polygon, removing possible duplicate endpoints.
11680  var skipLeft = lowerIndexes[0] === upperIndexes[0],
11681  skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
11682  hull = [];
11683 
11684  // Add upper hull in right-to-l order.
11685  // Then add lower hull in left-to-right order.
11686  for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
11687  for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
11688 
11689  return hull;
11690 }
11691 
11692 function contains$2(polygon, point) {
11693  var n = polygon.length,
11694  p = polygon[n - 1],
11695  x = point[0], y = point[1],
11696  x0 = p[0], y0 = p[1],
11697  x1, y1,
11698  inside = false;
11699 
11700  for (var i = 0; i < n; ++i) {
11701  p = polygon[i], x1 = p[0], y1 = p[1];
11702  if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
11703  x0 = x1, y0 = y1;
11704  }
11705 
11706  return inside;
11707 }
11708 
11709 function length$2(polygon) {
11710  var i = -1,
11711  n = polygon.length,
11712  b = polygon[n - 1],
11713  xa,
11714  ya,
11715  xb = b[0],
11716  yb = b[1],
11717  perimeter = 0;
11718 
11719  while (++i < n) {
11720  xa = xb;
11721  ya = yb;
11722  b = polygon[i];
11723  xb = b[0];
11724  yb = b[1];
11725  xa -= xb;
11726  ya -= yb;
11727  perimeter += Math.sqrt(xa * xa + ya * ya);
11728  }
11729 
11730  return perimeter;
11731 }
11732 
11733 function defaultSource$1() {
11734  return Math.random();
11735 }
11736 
11737 var uniform = (function sourceRandomUniform(source) {
11738  function randomUniform(min, max) {
11739  min = min == null ? 0 : +min;
11740  max = max == null ? 1 : +max;
11741  if (arguments.length === 1) max = min, min = 0;
11742  else max -= min;
11743  return function() {
11744  return source() * max + min;
11745  };
11746  }
11747 
11748  randomUniform.source = sourceRandomUniform;
11749 
11750  return randomUniform;
11751 })(defaultSource$1);
11752 
11753 var normal = (function sourceRandomNormal(source) {
11754  function randomNormal(mu, sigma) {
11755  var x, r;
11756  mu = mu == null ? 0 : +mu;
11757  sigma = sigma == null ? 1 : +sigma;
11758  return function() {
11759  var y;
11760 
11761  // If available, use the second previously-generated uniform random.
11762  if (x != null) y = x, x = null;
11763 
11764  // Otherwise, generate a new x and y.
11765  else do {
11766  x = source() * 2 - 1;
11767  y = source() * 2 - 1;
11768  r = x * x + y * y;
11769  } while (!r || r > 1);
11770 
11771  return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
11772  };
11773  }
11774 
11775  randomNormal.source = sourceRandomNormal;
11776 
11777  return randomNormal;
11778 })(defaultSource$1);
11779 
11780 var logNormal = (function sourceRandomLogNormal(source) {
11781  function randomLogNormal() {
11782  var randomNormal = normal.source(source).apply(this, arguments);
11783  return function() {
11784  return Math.exp(randomNormal());
11785  };
11786  }
11787 
11788  randomLogNormal.source = sourceRandomLogNormal;
11789 
11790  return randomLogNormal;
11791 })(defaultSource$1);
11792 
11793 var irwinHall = (function sourceRandomIrwinHall(source) {
11794  function randomIrwinHall(n) {
11795  return function() {
11796  for (var sum = 0, i = 0; i < n; ++i) sum += source();
11797  return sum;
11798  };
11799  }
11800 
11801  randomIrwinHall.source = sourceRandomIrwinHall;
11802 
11803  return randomIrwinHall;
11804 })(defaultSource$1);
11805 
11806 var bates = (function sourceRandomBates(source) {
11807  function randomBates(n) {
11808  var randomIrwinHall = irwinHall.source(source)(n);
11809  return function() {
11810  return randomIrwinHall() / n;
11811  };
11812  }
11813 
11814  randomBates.source = sourceRandomBates;
11815 
11816  return randomBates;
11817 })(defaultSource$1);
11818 
11819 var exponential$1 = (function sourceRandomExponential(source) {
11820  function randomExponential(lambda) {
11821  return function() {
11822  return -Math.log(1 - source()) / lambda;
11823  };
11824  }
11825 
11826  randomExponential.source = sourceRandomExponential;
11827 
11828  return randomExponential;
11829 })(defaultSource$1);
11830 
11831 var array$3 = Array.prototype;
11832 
11833 var map$2 = array$3.map;
11834 var slice$5 = array$3.slice;
11835 
11836 var implicit = {name: "implicit"};
11837 
11838 function ordinal(range) {
11839  var index = map$1(),
11840  domain = [],
11841  unknown = implicit;
11842 
11843  range = range == null ? [] : slice$5.call(range);
11844 
11845  function scale(d) {
11846  var key = d + "", i = index.get(key);
11847  if (!i) {
11848  if (unknown !== implicit) return unknown;
11849  index.set(key, i = domain.push(d));
11850  }
11851  return range[(i - 1) % range.length];
11852  }
11853 
11854  scale.domain = function(_) {
11855  if (!arguments.length) return domain.slice();
11856  domain = [], index = map$1();
11857  var i = -1, n = _.length, d, key;
11858  while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
11859  return scale;
11860  };
11861 
11862  scale.range = function(_) {
11863  return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
11864  };
11865 
11866  scale.unknown = function(_) {
11867  return arguments.length ? (unknown = _, scale) : unknown;
11868  };
11869 
11870  scale.copy = function() {
11871  return ordinal()
11872  .domain(domain)
11873  .range(range)
11874  .unknown(unknown);
11875  };
11876 
11877  return scale;
11878 }
11879 
11880 function band() {
11881  var scale = ordinal().unknown(undefined),
11882  domain = scale.domain,
11883  ordinalRange = scale.range,
11884  range$$1 = [0, 1],
11885  step,
11886  bandwidth,
11887  round = false,
11888  paddingInner = 0,
11889  paddingOuter = 0,
11890  align = 0.5;
11891 
11892  delete scale.unknown;
11893 
11894  function rescale() {
11895  var n = domain().length,
11896  reverse = range$$1[1] < range$$1[0],
11897  start = range$$1[reverse - 0],
11898  stop = range$$1[1 - reverse];
11899  step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
11900  if (round) step = Math.floor(step);
11901  start += (stop - start - step * (n - paddingInner)) * align;
11902  bandwidth = step * (1 - paddingInner);
11903  if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
11904  var values = sequence(n).map(function(i) { return start + step * i; });
11905  return ordinalRange(reverse ? values.reverse() : values);
11906  }
11907 
11908  scale.domain = function(_) {
11909  return arguments.length ? (domain(_), rescale()) : domain();
11910  };
11911 
11912  scale.range = function(_) {
11913  return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
11914  };
11915 
11916  scale.rangeRound = function(_) {
11917  return range$$1 = [+_[0], +_[1]], round = true, rescale();
11918  };
11919 
11920  scale.bandwidth = function() {
11921  return bandwidth;
11922  };
11923 
11924  scale.step = function() {
11925  return step;
11926  };
11927 
11928  scale.round = function(_) {
11929  return arguments.length ? (round = !!_, rescale()) : round;
11930  };
11931 
11932  scale.padding = function(_) {
11933  return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11934  };
11935 
11936  scale.paddingInner = function(_) {
11937  return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
11938  };
11939 
11940  scale.paddingOuter = function(_) {
11941  return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
11942  };
11943 
11944  scale.align = function(_) {
11945  return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
11946  };
11947 
11948  scale.copy = function() {
11949  return band()
11950  .domain(domain())
11951  .range(range$$1)
11952  .round(round)
11953  .paddingInner(paddingInner)
11954  .paddingOuter(paddingOuter)
11955  .align(align);
11956  };
11957 
11958  return rescale();
11959 }
11960 
11961 function pointish(scale) {
11962  var copy = scale.copy;
11963 
11964  scale.padding = scale.paddingOuter;
11965  delete scale.paddingInner;
11966  delete scale.paddingOuter;
11967 
11968  scale.copy = function() {
11969  return pointish(copy());
11970  };
11971 
11972  return scale;
11973 }
11974 
11975 function point$1() {
11976  return pointish(band().paddingInner(1));
11977 }
11978 
11979 function constant$a(x) {
11980  return function() {
11981  return x;
11982  };
11983 }
11984 
11985 function number$2(x) {
11986  return +x;
11987 }
11988 
11989 var unit = [0, 1];
11990 
11991 function deinterpolateLinear(a, b) {
11992  return (b -= (a = +a))
11993  ? function(x) { return (x - a) / b; }
11994  : constant$a(b);
11995 }
11996 
11997 function deinterpolateClamp(deinterpolate) {
11998  return function(a, b) {
11999  var d = deinterpolate(a = +a, b = +b);
12000  return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
12001  };
12002 }
12003 
12004 function reinterpolateClamp(reinterpolate) {
12005  return function(a, b) {
12006  var r = reinterpolate(a = +a, b = +b);
12007  return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
12008  };
12009 }
12010 
12011 function bimap(domain, range, deinterpolate, reinterpolate) {
12012  var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
12013  if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
12014  else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
12015  return function(x) { return r0(d0(x)); };
12016 }
12017 
12018 function polymap(domain, range, deinterpolate, reinterpolate) {
12019  var j = Math.min(domain.length, range.length) - 1,
12020  d = new Array(j),
12021  r = new Array(j),
12022  i = -1;
12023 
12024  // Reverse descending domains.
12025  if (domain[j] < domain[0]) {
12026  domain = domain.slice().reverse();
12027  range = range.slice().reverse();
12028  }
12029 
12030  while (++i < j) {
12031  d[i] = deinterpolate(domain[i], domain[i + 1]);
12032  r[i] = reinterpolate(range[i], range[i + 1]);
12033  }
12034 
12035  return function(x) {
12036  var i = bisectRight(domain, x, 1, j) - 1;
12037  return r[i](d[i](x));
12038  };
12039 }
12040 
12041 function copy(source, target) {
12042  return target
12043  .domain(source.domain())
12044  .range(source.range())
12045  .interpolate(source.interpolate())
12046  .clamp(source.clamp());
12047 }
12048 
12049 // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
12050 // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
12051 function continuous(deinterpolate, reinterpolate) {
12052  var domain = unit,
12053  range = unit,
12054  interpolate$$1 = interpolateValue,
12055  clamp = false,
12056  piecewise$$1,
12057  output,
12058  input;
12059 
12060  function rescale() {
12061  piecewise$$1 = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
12062  output = input = null;
12063  return scale;
12064  }
12065 
12066  function scale(x) {
12067  return (output || (output = piecewise$$1(domain, range, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
12068  }
12069 
12070  scale.invert = function(y) {
12071  return (input || (input = piecewise$$1(range, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
12072  };
12073 
12074  scale.domain = function(_) {
12075  return arguments.length ? (domain = map$2.call(_, number$2), rescale()) : domain.slice();
12076  };
12077 
12078  scale.range = function(_) {
12079  return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12080  };
12081 
12082  scale.rangeRound = function(_) {
12083  return range = slice$5.call(_), interpolate$$1 = interpolateRound, rescale();
12084  };
12085 
12086  scale.clamp = function(_) {
12087  return arguments.length ? (clamp = !!_, rescale()) : clamp;
12088  };
12089 
12090  scale.interpolate = function(_) {
12091  return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
12092  };
12093 
12094  return rescale();
12095 }
12096 
12097 function tickFormat(domain, count, specifier) {
12098  var start = domain[0],
12099  stop = domain[domain.length - 1],
12100  step = tickStep(start, stop, count == null ? 10 : count),
12101  precision;
12102  specifier = formatSpecifier(specifier == null ? ",f" : specifier);
12103  switch (specifier.type) {
12104  case "s": {
12105  var value = Math.max(Math.abs(start), Math.abs(stop));
12106  if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
12107  return exports.formatPrefix(specifier, value);
12108  }
12109  case "":
12110  case "e":
12111  case "g":
12112  case "p":
12113  case "r": {
12114  if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
12115  break;
12116  }
12117  case "f":
12118  case "%": {
12119  if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
12120  break;
12121  }
12122  }
12123  return exports.format(specifier);
12124 }
12125 
12126 function linearish(scale) {
12127  var domain = scale.domain;
12128 
12129  scale.ticks = function(count) {
12130  var d = domain();
12131  return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
12132  };
12133 
12134  scale.tickFormat = function(count, specifier) {
12135  return tickFormat(domain(), count, specifier);
12136  };
12137 
12138  scale.nice = function(count) {
12139  if (count == null) count = 10;
12140 
12141  var d = domain(),
12142  i0 = 0,
12143  i1 = d.length - 1,
12144  start = d[i0],
12145  stop = d[i1],
12146  step;
12147 
12148  if (stop < start) {
12149  step = start, start = stop, stop = step;
12150  step = i0, i0 = i1, i1 = step;
12151  }
12152 
12153  step = tickIncrement(start, stop, count);
12154 
12155  if (step > 0) {
12156  start = Math.floor(start / step) * step;
12157  stop = Math.ceil(stop / step) * step;
12158  step = tickIncrement(start, stop, count);
12159  } else if (step < 0) {
12160  start = Math.ceil(start * step) / step;
12161  stop = Math.floor(stop * step) / step;
12162  step = tickIncrement(start, stop, count);
12163  }
12164 
12165  if (step > 0) {
12166  d[i0] = Math.floor(start / step) * step;
12167  d[i1] = Math.ceil(stop / step) * step;
12168  domain(d);
12169  } else if (step < 0) {
12170  d[i0] = Math.ceil(start * step) / step;
12171  d[i1] = Math.floor(stop * step) / step;
12172  domain(d);
12173  }
12174 
12175  return scale;
12176  };
12177 
12178  return scale;
12179 }
12180 
12181 function linear$2() {
12182  var scale = continuous(deinterpolateLinear, interpolateNumber);
12183 
12184  scale.copy = function() {
12185  return copy(scale, linear$2());
12186  };
12187 
12188  return linearish(scale);
12189 }
12190 
12191 function identity$6() {
12192  var domain = [0, 1];
12193 
12194  function scale(x) {
12195  return +x;
12196  }
12197 
12198  scale.invert = scale;
12199 
12200  scale.domain = scale.range = function(_) {
12201  return arguments.length ? (domain = map$2.call(_, number$2), scale) : domain.slice();
12202  };
12203 
12204  scale.copy = function() {
12205  return identity$6().domain(domain);
12206  };
12207 
12208  return linearish(scale);
12209 }
12210 
12211 function nice(domain, interval) {
12212  domain = domain.slice();
12213 
12214  var i0 = 0,
12215  i1 = domain.length - 1,
12216  x0 = domain[i0],
12217  x1 = domain[i1],
12218  t;
12219 
12220  if (x1 < x0) {
12221  t = i0, i0 = i1, i1 = t;
12222  t = x0, x0 = x1, x1 = t;
12223  }
12224 
12225  domain[i0] = interval.floor(x0);
12226  domain[i1] = interval.ceil(x1);
12227  return domain;
12228 }
12229 
12230 function deinterpolate(a, b) {
12231  return (b = Math.log(b / a))
12232  ? function(x) { return Math.log(x / a) / b; }
12233  : constant$a(b);
12234 }
12235 
12236 function reinterpolate(a, b) {
12237  return a < 0
12238  ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
12239  : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
12240 }
12241 
12242 function pow10(x) {
12243  return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
12244 }
12245 
12246 function powp(base) {
12247  return base === 10 ? pow10
12248  : base === Math.E ? Math.exp
12249  : function(x) { return Math.pow(base, x); };
12250 }
12251 
12252 function logp(base) {
12253  return base === Math.E ? Math.log
12254  : base === 10 && Math.log10
12255  || base === 2 && Math.log2
12256  || (base = Math.log(base), function(x) { return Math.log(x) / base; });
12257 }
12258 
12259 function reflect(f) {
12260  return function(x) {
12261  return -f(-x);
12262  };
12263 }
12264 
12265 function log$1() {
12266  var scale = continuous(deinterpolate, reinterpolate).domain([1, 10]),
12267  domain = scale.domain,
12268  base = 10,
12269  logs = logp(10),
12270  pows = powp(10);
12271 
12272  function rescale() {
12273  logs = logp(base), pows = powp(base);
12274  if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
12275  return scale;
12276  }
12277 
12278  scale.base = function(_) {
12279  return arguments.length ? (base = +_, rescale()) : base;
12280  };
12281 
12282  scale.domain = function(_) {
12283  return arguments.length ? (domain(_), rescale()) : domain();
12284  };
12285 
12286  scale.ticks = function(count) {
12287  var d = domain(),
12288  u = d[0],
12289  v = d[d.length - 1],
12290  r;
12291 
12292  if (r = v < u) i = u, u = v, v = i;
12293 
12294  var i = logs(u),
12295  j = logs(v),
12296  p,
12297  k,
12298  t,
12299  n = count == null ? 10 : +count,
12300  z = [];
12301 
12302  if (!(base % 1) && j - i < n) {
12303  i = Math.round(i) - 1, j = Math.round(j) + 1;
12304  if (u > 0) for (; i < j; ++i) {
12305  for (k = 1, p = pows(i); k < base; ++k) {
12306  t = p * k;
12307  if (t < u) continue;
12308  if (t > v) break;
12309  z.push(t);
12310  }
12311  } else for (; i < j; ++i) {
12312  for (k = base - 1, p = pows(i); k >= 1; --k) {
12313  t = p * k;
12314  if (t < u) continue;
12315  if (t > v) break;
12316  z.push(t);
12317  }
12318  }
12319  } else {
12320  z = ticks(i, j, Math.min(j - i, n)).map(pows);
12321  }
12322 
12323  return r ? z.reverse() : z;
12324  };
12325 
12326  scale.tickFormat = function(count, specifier) {
12327  if (specifier == null) specifier = base === 10 ? ".0e" : ",";
12328  if (typeof specifier !== "function") specifier = exports.format(specifier);
12329  if (count === Infinity) return specifier;
12330  if (count == null) count = 10;
12331  var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
12332  return function(d) {
12333  var i = d / pows(Math.round(logs(d)));
12334  if (i * base < base - 0.5) i *= base;
12335  return i <= k ? specifier(d) : "";
12336  };
12337  };
12338 
12339  scale.nice = function() {
12340  return domain(nice(domain(), {
12341  floor: function(x) { return pows(Math.floor(logs(x))); },
12342  ceil: function(x) { return pows(Math.ceil(logs(x))); }
12343  }));
12344  };
12345 
12346  scale.copy = function() {
12347  return copy(scale, log$1().base(base));
12348  };
12349 
12350  return scale;
12351 }
12352 
12353 function raise$1(x, exponent) {
12354  return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
12355 }
12356 
12357 function pow$1() {
12358  var exponent = 1,
12359  scale = continuous(deinterpolate, reinterpolate),
12360  domain = scale.domain;
12361 
12362  function deinterpolate(a, b) {
12363  return (b = raise$1(b, exponent) - (a = raise$1(a, exponent)))
12364  ? function(x) { return (raise$1(x, exponent) - a) / b; }
12365  : constant$a(b);
12366  }
12367 
12368  function reinterpolate(a, b) {
12369  b = raise$1(b, exponent) - (a = raise$1(a, exponent));
12370  return function(t) { return raise$1(a + b * t, 1 / exponent); };
12371  }
12372 
12373  scale.exponent = function(_) {
12374  return arguments.length ? (exponent = +_, domain(domain())) : exponent;
12375  };
12376 
12377  scale.copy = function() {
12378  return copy(scale, pow$1().exponent(exponent));
12379  };
12380 
12381  return linearish(scale);
12382 }
12383 
12384 function sqrt$1() {
12385  return pow$1().exponent(0.5);
12386 }
12387 
12388 function quantile$$1() {
12389  var domain = [],
12390  range = [],
12391  thresholds = [];
12392 
12393  function rescale() {
12394  var i = 0, n = Math.max(1, range.length);
12395  thresholds = new Array(n - 1);
12396  while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
12397  return scale;
12398  }
12399 
12400  function scale(x) {
12401  if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
12402  }
12403 
12404  scale.invertExtent = function(y) {
12405  var i = range.indexOf(y);
12406  return i < 0 ? [NaN, NaN] : [
12407  i > 0 ? thresholds[i - 1] : domain[0],
12408  i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
12409  ];
12410  };
12411 
12412  scale.domain = function(_) {
12413  if (!arguments.length) return domain.slice();
12414  domain = [];
12415  for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
12416  domain.sort(ascending);
12417  return rescale();
12418  };
12419 
12420  scale.range = function(_) {
12421  return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
12422  };
12423 
12424  scale.quantiles = function() {
12425  return thresholds.slice();
12426  };
12427 
12428  scale.copy = function() {
12429  return quantile$$1()
12430  .domain(domain)
12431  .range(range);
12432  };
12433 
12434  return scale;
12435 }
12436 
12437 function quantize$1() {
12438  var x0 = 0,
12439  x1 = 1,
12440  n = 1,
12441  domain = [0.5],
12442  range = [0, 1];
12443 
12444  function scale(x) {
12445  if (x <= x) return range[bisectRight(domain, x, 0, n)];
12446  }
12447 
12448  function rescale() {
12449  var i = -1;
12450  domain = new Array(n);
12451  while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
12452  return scale;
12453  }
12454 
12455  scale.domain = function(_) {
12456  return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
12457  };
12458 
12459  scale.range = function(_) {
12460  return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
12461  };
12462 
12463  scale.invertExtent = function(y) {
12464  var i = range.indexOf(y);
12465  return i < 0 ? [NaN, NaN]
12466  : i < 1 ? [x0, domain[0]]
12467  : i >= n ? [domain[n - 1], x1]
12468  : [domain[i - 1], domain[i]];
12469  };
12470 
12471  scale.copy = function() {
12472  return quantize$1()
12473  .domain([x0, x1])
12474  .range(range);
12475  };
12476 
12477  return linearish(scale);
12478 }
12479 
12480 function threshold$1() {
12481  var domain = [0.5],
12482  range = [0, 1],
12483  n = 1;
12484 
12485  function scale(x) {
12486  if (x <= x) return range[bisectRight(domain, x, 0, n)];
12487  }
12488 
12489  scale.domain = function(_) {
12490  return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
12491  };
12492 
12493  scale.range = function(_) {
12494  return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
12495  };
12496 
12497  scale.invertExtent = function(y) {
12498  var i = range.indexOf(y);
12499  return [domain[i - 1], domain[i]];
12500  };
12501 
12502  scale.copy = function() {
12503  return threshold$1()
12504  .domain(domain)
12505  .range(range);
12506  };
12507 
12508  return scale;
12509 }
12510 
12511 var t0$1 = new Date,
12512  t1$1 = new Date;
12513 
12514 function newInterval(floori, offseti, count, field) {
12515 
12516  function interval(date) {
12517  return floori(date = new Date(+date)), date;
12518  }
12519 
12520  interval.floor = interval;
12521 
12522  interval.ceil = function(date) {
12523  return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
12524  };
12525 
12526  interval.round = function(date) {
12527  var d0 = interval(date),
12528  d1 = interval.ceil(date);
12529  return date - d0 < d1 - date ? d0 : d1;
12530  };
12531 
12532  interval.offset = function(date, step) {
12533  return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
12534  };
12535 
12536  interval.range = function(start, stop, step) {
12537  var range = [], previous;
12538  start = interval.ceil(start);
12539  step = step == null ? 1 : Math.floor(step);
12540  if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
12541  do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
12542  while (previous < start && start < stop);
12543  return range;
12544  };
12545 
12546  interval.filter = function(test) {
12547  return newInterval(function(date) {
12548  if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
12549  }, function(date, step) {
12550  if (date >= date) {
12551  if (step < 0) while (++step <= 0) {
12552  while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
12553  } else while (--step >= 0) {
12554  while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
12555  }
12556  }
12557  });
12558  };
12559 
12560  if (count) {
12561  interval.count = function(start, end) {
12562  t0$1.setTime(+start), t1$1.setTime(+end);
12563  floori(t0$1), floori(t1$1);
12564  return Math.floor(count(t0$1, t1$1));
12565  };
12566 
12567  interval.every = function(step) {
12568  step = Math.floor(step);
12569  return !isFinite(step) || !(step > 0) ? null
12570  : !(step > 1) ? interval
12571  : interval.filter(field
12572  ? function(d) { return field(d) % step === 0; }
12573  : function(d) { return interval.count(0, d) % step === 0; });
12574  };
12575  }
12576 
12577  return interval;
12578 }
12579 
12580 var millisecond = newInterval(function() {
12581  // noop
12582 }, function(date, step) {
12583  date.setTime(+date + step);
12584 }, function(start, end) {
12585  return end - start;
12586 });
12587 
12588 // An optimized implementation for this simple case.
12589 millisecond.every = function(k) {
12590  k = Math.floor(k);
12591  if (!isFinite(k) || !(k > 0)) return null;
12592  if (!(k > 1)) return millisecond;
12593  return newInterval(function(date) {
12594  date.setTime(Math.floor(date / k) * k);
12595  }, function(date, step) {
12596  date.setTime(+date + step * k);
12597  }, function(start, end) {
12598  return (end - start) / k;
12599  });
12600 };
12601 var milliseconds = millisecond.range;
12602 
12603 var durationSecond = 1e3;
12604 var durationMinute = 6e4;
12605 var durationHour = 36e5;
12606 var durationDay = 864e5;
12607 var durationWeek = 6048e5;
12608 
12609 var second = newInterval(function(date) {
12610  date.setTime(Math.floor(date / durationSecond) * durationSecond);
12611 }, function(date, step) {
12612  date.setTime(+date + step * durationSecond);
12613 }, function(start, end) {
12614  return (end - start) / durationSecond;
12615 }, function(date) {
12616  return date.getUTCSeconds();
12617 });
12618 var seconds = second.range;
12619 
12620 var minute = newInterval(function(date) {
12621  date.setTime(Math.floor(date / durationMinute) * durationMinute);
12622 }, function(date, step) {
12623  date.setTime(+date + step * durationMinute);
12624 }, function(start, end) {
12625  return (end - start) / durationMinute;
12626 }, function(date) {
12627  return date.getMinutes();
12628 });
12629 var minutes = minute.range;
12630 
12631 var hour = newInterval(function(date) {
12632  var offset = date.getTimezoneOffset() * durationMinute % durationHour;
12633  if (offset < 0) offset += durationHour;
12634  date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
12635 }, function(date, step) {
12636  date.setTime(+date + step * durationHour);
12637 }, function(start, end) {
12638  return (end - start) / durationHour;
12639 }, function(date) {
12640  return date.getHours();
12641 });
12642 var hours = hour.range;
12643 
12644 var day = newInterval(function(date) {
12645  date.setHours(0, 0, 0, 0);
12646 }, function(date, step) {
12647  date.setDate(date.getDate() + step);
12648 }, function(start, end) {
12649  return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
12650 }, function(date) {
12651  return date.getDate() - 1;
12652 });
12653 var days = day.range;
12654 
12655 function weekday(i) {
12656  return newInterval(function(date) {
12657  date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
12658  date.setHours(0, 0, 0, 0);
12659  }, function(date, step) {
12660  date.setDate(date.getDate() + step * 7);
12661  }, function(start, end) {
12662  return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
12663  });
12664 }
12665 
12666 var sunday = weekday(0);
12667 var monday = weekday(1);
12668 var tuesday = weekday(2);
12669 var wednesday = weekday(3);
12670 var thursday = weekday(4);
12671 var friday = weekday(5);
12672 var saturday = weekday(6);
12673 
12674 var sundays = sunday.range;
12675 var mondays = monday.range;
12676 var tuesdays = tuesday.range;
12677 var wednesdays = wednesday.range;
12678 var thursdays = thursday.range;
12679 var fridays = friday.range;
12680 var saturdays = saturday.range;
12681 
12682 var month = newInterval(function(date) {
12683  date.setDate(1);
12684  date.setHours(0, 0, 0, 0);
12685 }, function(date, step) {
12686  date.setMonth(date.getMonth() + step);
12687 }, function(start, end) {
12688  return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
12689 }, function(date) {
12690  return date.getMonth();
12691 });
12692 var months = month.range;
12693 
12694 var year = newInterval(function(date) {
12695  date.setMonth(0, 1);
12696  date.setHours(0, 0, 0, 0);
12697 }, function(date, step) {
12698  date.setFullYear(date.getFullYear() + step);
12699 }, function(start, end) {
12700  return end.getFullYear() - start.getFullYear();
12701 }, function(date) {
12702  return date.getFullYear();
12703 });
12704 
12705 // An optimized implementation for this simple case.
12706 year.every = function(k) {
12707  return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12708  date.setFullYear(Math.floor(date.getFullYear() / k) * k);
12709  date.setMonth(0, 1);
12710  date.setHours(0, 0, 0, 0);
12711  }, function(date, step) {
12712  date.setFullYear(date.getFullYear() + step * k);
12713  });
12714 };
12715 var years = year.range;
12716 
12717 var utcMinute = newInterval(function(date) {
12718  date.setUTCSeconds(0, 0);
12719 }, function(date, step) {
12720  date.setTime(+date + step * durationMinute);
12721 }, function(start, end) {
12722  return (end - start) / durationMinute;
12723 }, function(date) {
12724  return date.getUTCMinutes();
12725 });
12726 var utcMinutes = utcMinute.range;
12727 
12728 var utcHour = newInterval(function(date) {
12729  date.setUTCMinutes(0, 0, 0);
12730 }, function(date, step) {
12731  date.setTime(+date + step * durationHour);
12732 }, function(start, end) {
12733  return (end - start) / durationHour;
12734 }, function(date) {
12735  return date.getUTCHours();
12736 });
12737 var utcHours = utcHour.range;
12738 
12739 var utcDay = newInterval(function(date) {
12740  date.setUTCHours(0, 0, 0, 0);
12741 }, function(date, step) {
12742  date.setUTCDate(date.getUTCDate() + step);
12743 }, function(start, end) {
12744  return (end - start) / durationDay;
12745 }, function(date) {
12746  return date.getUTCDate() - 1;
12747 });
12748 var utcDays = utcDay.range;
12749 
12750 function utcWeekday(i) {
12751  return newInterval(function(date) {
12752  date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
12753  date.setUTCHours(0, 0, 0, 0);
12754  }, function(date, step) {
12755  date.setUTCDate(date.getUTCDate() + step * 7);
12756  }, function(start, end) {
12757  return (end - start) / durationWeek;
12758  });
12759 }
12760 
12761 var utcSunday = utcWeekday(0);
12762 var utcMonday = utcWeekday(1);
12763 var utcTuesday = utcWeekday(2);
12764 var utcWednesday = utcWeekday(3);
12765 var utcThursday = utcWeekday(4);
12766 var utcFriday = utcWeekday(5);
12767 var utcSaturday = utcWeekday(6);
12768 
12769 var utcSundays = utcSunday.range;
12770 var utcMondays = utcMonday.range;
12771 var utcTuesdays = utcTuesday.range;
12772 var utcWednesdays = utcWednesday.range;
12773 var utcThursdays = utcThursday.range;
12774 var utcFridays = utcFriday.range;
12775 var utcSaturdays = utcSaturday.range;
12776 
12777 var utcMonth = newInterval(function(date) {
12778  date.setUTCDate(1);
12779  date.setUTCHours(0, 0, 0, 0);
12780 }, function(date, step) {
12781  date.setUTCMonth(date.getUTCMonth() + step);
12782 }, function(start, end) {
12783  return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
12784 }, function(date) {
12785  return date.getUTCMonth();
12786 });
12787 var utcMonths = utcMonth.range;
12788 
12789 var utcYear = newInterval(function(date) {
12790  date.setUTCMonth(0, 1);
12791  date.setUTCHours(0, 0, 0, 0);
12792 }, function(date, step) {
12793  date.setUTCFullYear(date.getUTCFullYear() + step);
12794 }, function(start, end) {
12795  return end.getUTCFullYear() - start.getUTCFullYear();
12796 }, function(date) {
12797  return date.getUTCFullYear();
12798 });
12799 
12800 // An optimized implementation for this simple case.
12801 utcYear.every = function(k) {
12802  return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
12803  date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
12804  date.setUTCMonth(0, 1);
12805  date.setUTCHours(0, 0, 0, 0);
12806  }, function(date, step) {
12807  date.setUTCFullYear(date.getUTCFullYear() + step * k);
12808  });
12809 };
12810 var utcYears = utcYear.range;
12811 
12812 function localDate(d) {
12813  if (0 <= d.y && d.y < 100) {
12814  var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
12815  date.setFullYear(d.y);
12816  return date;
12817  }
12818  return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
12819 }
12820 
12821 function utcDate(d) {
12822  if (0 <= d.y && d.y < 100) {
12823  var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
12824  date.setUTCFullYear(d.y);
12825  return date;
12826  }
12827  return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
12828 }
12829 
12830 function newYear(y) {
12831  return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
12832 }
12833 
12834 function formatLocale$1(locale) {
12835  var locale_dateTime = locale.dateTime,
12836  locale_date = locale.date,
12837  locale_time = locale.time,
12838  locale_periods = locale.periods,
12839  locale_weekdays = locale.days,
12840  locale_shortWeekdays = locale.shortDays,
12841  locale_months = locale.months,
12842  locale_shortMonths = locale.shortMonths;
12843 
12844  var periodRe = formatRe(locale_periods),
12845  periodLookup = formatLookup(locale_periods),
12846  weekdayRe = formatRe(locale_weekdays),
12847  weekdayLookup = formatLookup(locale_weekdays),
12848  shortWeekdayRe = formatRe(locale_shortWeekdays),
12849  shortWeekdayLookup = formatLookup(locale_shortWeekdays),
12850  monthRe = formatRe(locale_months),
12851  monthLookup = formatLookup(locale_months),
12852  shortMonthRe = formatRe(locale_shortMonths),
12853  shortMonthLookup = formatLookup(locale_shortMonths);
12854 
12855  var formats = {
12856  "a": formatShortWeekday,
12857  "A": formatWeekday,
12858  "b": formatShortMonth,
12859  "B": formatMonth,
12860  "c": null,
12861  "d": formatDayOfMonth,
12862  "e": formatDayOfMonth,
12863  "f": formatMicroseconds,
12864  "H": formatHour24,
12865  "I": formatHour12,
12866  "j": formatDayOfYear,
12867  "L": formatMilliseconds,
12868  "m": formatMonthNumber,
12869  "M": formatMinutes,
12870  "p": formatPeriod,
12871  "Q": formatUnixTimestamp,
12872  "s": formatUnixTimestampSeconds,
12873  "S": formatSeconds,
12874  "u": formatWeekdayNumberMonday,
12875  "U": formatWeekNumberSunday,
12876  "V": formatWeekNumberISO,
12877  "w": formatWeekdayNumberSunday,
12878  "W": formatWeekNumberMonday,
12879  "x": null,
12880  "X": null,
12881  "y": formatYear,
12882  "Y": formatFullYear,
12883  "Z": formatZone,
12884  "%": formatLiteralPercent
12885  };
12886 
12887  var utcFormats = {
12888  "a": formatUTCShortWeekday,
12889  "A": formatUTCWeekday,
12890  "b": formatUTCShortMonth,
12891  "B": formatUTCMonth,
12892  "c": null,
12893  "d": formatUTCDayOfMonth,
12894  "e": formatUTCDayOfMonth,
12895  "f": formatUTCMicroseconds,
12896  "H": formatUTCHour24,
12897  "I": formatUTCHour12,
12898  "j": formatUTCDayOfYear,
12899  "L": formatUTCMilliseconds,
12900  "m": formatUTCMonthNumber,
12901  "M": formatUTCMinutes,
12902  "p": formatUTCPeriod,
12903  "Q": formatUnixTimestamp,
12904  "s": formatUnixTimestampSeconds,
12905  "S": formatUTCSeconds,
12906  "u": formatUTCWeekdayNumberMonday,
12907  "U": formatUTCWeekNumberSunday,
12908  "V": formatUTCWeekNumberISO,
12909  "w": formatUTCWeekdayNumberSunday,
12910  "W": formatUTCWeekNumberMonday,
12911  "x": null,
12912  "X": null,
12913  "y": formatUTCYear,
12914  "Y": formatUTCFullYear,
12915  "Z": formatUTCZone,
12916  "%": formatLiteralPercent
12917  };
12918 
12919  var parses = {
12920  "a": parseShortWeekday,
12921  "A": parseWeekday,
12922  "b": parseShortMonth,
12923  "B": parseMonth,
12924  "c": parseLocaleDateTime,
12925  "d": parseDayOfMonth,
12926  "e": parseDayOfMonth,
12927  "f": parseMicroseconds,
12928  "H": parseHour24,
12929  "I": parseHour24,
12930  "j": parseDayOfYear,
12931  "L": parseMilliseconds,
12932  "m": parseMonthNumber,
12933  "M": parseMinutes,
12934  "p": parsePeriod,
12935  "Q": parseUnixTimestamp,
12936  "s": parseUnixTimestampSeconds,
12937  "S": parseSeconds,
12938  "u": parseWeekdayNumberMonday,
12939  "U": parseWeekNumberSunday,
12940  "V": parseWeekNumberISO,
12941  "w": parseWeekdayNumberSunday,
12942  "W": parseWeekNumberMonday,
12943  "x": parseLocaleDate,
12944  "X": parseLocaleTime,
12945  "y": parseYear,
12946  "Y": parseFullYear,
12947  "Z": parseZone,
12948  "%": parseLiteralPercent
12949  };
12950 
12951  // These recursive directive definitions must be deferred.
12952  formats.x = newFormat(locale_date, formats);
12953  formats.X = newFormat(locale_time, formats);
12954  formats.c = newFormat(locale_dateTime, formats);
12955  utcFormats.x = newFormat(locale_date, utcFormats);
12956  utcFormats.X = newFormat(locale_time, utcFormats);
12957  utcFormats.c = newFormat(locale_dateTime, utcFormats);
12958 
12959  function newFormat(specifier, formats) {
12960  return function(date) {
12961  var string = [],
12962  i = -1,
12963  j = 0,
12964  n = specifier.length,
12965  c,
12966  pad,
12967  format;
12968 
12969  if (!(date instanceof Date)) date = new Date(+date);
12970 
12971  while (++i < n) {
12972  if (specifier.charCodeAt(i) === 37) {
12973  string.push(specifier.slice(j, i));
12974  if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
12975  else pad = c === "e" ? " " : "0";
12976  if (format = formats[c]) c = format(date, pad);
12977  string.push(c);
12978  j = i + 1;
12979  }
12980  }
12981 
12982  string.push(specifier.slice(j, i));
12983  return string.join("");
12984  };
12985  }
12986 
12987  function newParse(specifier, newDate) {
12988  return function(string) {
12989  var d = newYear(1900),
12990  i = parseSpecifier(d, specifier, string += "", 0),
12991  week, day$$1;
12992  if (i != string.length) return null;
12993 
12994  // If a UNIX timestamp is specified, return it.
12995  if ("Q" in d) return new Date(d.Q);
12996 
12997  // The am-pm flag is 0 for AM, and 1 for PM.
12998  if ("p" in d) d.H = d.H % 12 + d.p * 12;
12999 
13000  // Convert day-of-week and week-of-year to day-of-year.
13001  if ("V" in d) {
13002  if (d.V < 1 || d.V > 53) return null;
13003  if (!("w" in d)) d.w = 1;
13004  if ("Z" in d) {
13005  week = utcDate(newYear(d.y)), day$$1 = week.getUTCDay();
13006  week = day$$1 > 4 || day$$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
13007  week = utcDay.offset(week, (d.V - 1) * 7);
13008  d.y = week.getUTCFullYear();
13009  d.m = week.getUTCMonth();
13010  d.d = week.getUTCDate() + (d.w + 6) % 7;
13011  } else {
13012  week = newDate(newYear(d.y)), day$$1 = week.getDay();
13013  week = day$$1 > 4 || day$$1 === 0 ? monday.ceil(week) : monday(week);
13014  week = day.offset(week, (d.V - 1) * 7);
13015  d.y = week.getFullYear();
13016  d.m = week.getMonth();
13017  d.d = week.getDate() + (d.w + 6) % 7;
13018  }
13019  } else if ("W" in d || "U" in d) {
13020  if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
13021  day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
13022  d.m = 0;
13023  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;
13024  }
13025 
13026  // If a time zone is specified, all fields are interpreted as UTC and then
13027  // offset according to the specified time zone.
13028  if ("Z" in d) {
13029  d.H += d.Z / 100 | 0;
13030  d.M += d.Z % 100;
13031  return utcDate(d);
13032  }
13033 
13034  // Otherwise, all fields are in local time.
13035  return newDate(d);
13036  };
13037  }
13038 
13039  function parseSpecifier(d, specifier, string, j) {
13040  var i = 0,
13041  n = specifier.length,
13042  m = string.length,
13043  c,
13044  parse;
13045 
13046  while (i < n) {
13047  if (j >= m) return -1;
13048  c = specifier.charCodeAt(i++);
13049  if (c === 37) {
13050  c = specifier.charAt(i++);
13051  parse = parses[c in pads ? specifier.charAt(i++) : c];
13052  if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
13053  } else if (c != string.charCodeAt(j++)) {
13054  return -1;
13055  }
13056  }
13057 
13058  return j;
13059  }
13060 
13061  function parsePeriod(d, string, i) {
13062  var n = periodRe.exec(string.slice(i));
13063  return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13064  }
13065 
13066  function parseShortWeekday(d, string, i) {
13067  var n = shortWeekdayRe.exec(string.slice(i));
13068  return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13069  }
13070 
13071  function parseWeekday(d, string, i) {
13072  var n = weekdayRe.exec(string.slice(i));
13073  return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13074  }
13075 
13076  function parseShortMonth(d, string, i) {
13077  var n = shortMonthRe.exec(string.slice(i));
13078  return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13079  }
13080 
13081  function parseMonth(d, string, i) {
13082  var n = monthRe.exec(string.slice(i));
13083  return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
13084  }
13085 
13086  function parseLocaleDateTime(d, string, i) {
13087  return parseSpecifier(d, locale_dateTime, string, i);
13088  }
13089 
13090  function parseLocaleDate(d, string, i) {
13091  return parseSpecifier(d, locale_date, string, i);
13092  }
13093 
13094  function parseLocaleTime(d, string, i) {
13095  return parseSpecifier(d, locale_time, string, i);
13096  }
13097 
13098  function formatShortWeekday(d) {
13099  return locale_shortWeekdays[d.getDay()];
13100  }
13101 
13102  function formatWeekday(d) {
13103  return locale_weekdays[d.getDay()];
13104  }
13105 
13106  function formatShortMonth(d) {
13107  return locale_shortMonths[d.getMonth()];
13108  }
13109 
13110  function formatMonth(d) {
13111  return locale_months[d.getMonth()];
13112  }
13113 
13114  function formatPeriod(d) {
13115  return locale_periods[+(d.getHours() >= 12)];
13116  }
13117 
13118  function formatUTCShortWeekday(d) {
13119  return locale_shortWeekdays[d.getUTCDay()];
13120  }
13121 
13122  function formatUTCWeekday(d) {
13123  return locale_weekdays[d.getUTCDay()];
13124  }
13125 
13126  function formatUTCShortMonth(d) {
13127  return locale_shortMonths[d.getUTCMonth()];
13128  }
13129 
13130  function formatUTCMonth(d) {
13131  return locale_months[d.getUTCMonth()];
13132  }
13133 
13134  function formatUTCPeriod(d) {
13135  return locale_periods[+(d.getUTCHours() >= 12)];
13136  }
13137 
13138  return {
13139  format: function(specifier) {
13140  var f = newFormat(specifier += "", formats);
13141  f.toString = function() { return specifier; };
13142  return f;
13143  },
13144  parse: function(specifier) {
13145  var p = newParse(specifier += "", localDate);
13146  p.toString = function() { return specifier; };
13147  return p;
13148  },
13149  utcFormat: function(specifier) {
13150  var f = newFormat(specifier += "", utcFormats);
13151  f.toString = function() { return specifier; };
13152  return f;
13153  },
13154  utcParse: function(specifier) {
13155  var p = newParse(specifier, utcDate);
13156  p.toString = function() { return specifier; };
13157  return p;
13158  }
13159  };
13160 }
13161 
13162 var pads = {"-": "", "_": " ", "0": "0"},
13163  numberRe = /^\s*\d+/, // note: ignores next directive
13164  percentRe = /^%/,
13165  requoteRe = /[\\^$*+?|[\]().{}]/g;
13166 
13167 function pad(value, fill, width) {
13168  var sign = value < 0 ? "-" : "",
13169  string = (sign ? -value : value) + "",
13170  length = string.length;
13171  return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
13172 }
13173 
13174 function requote(s) {
13175  return s.replace(requoteRe, "\\$&");
13176 }
13177 
13178 function formatRe(names) {
13179  return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
13180 }
13181 
13182 function formatLookup(names) {
13183  var map = {}, i = -1, n = names.length;
13184  while (++i < n) map[names[i].toLowerCase()] = i;
13185  return map;
13186 }
13187 
13188 function parseWeekdayNumberSunday(d, string, i) {
13189  var n = numberRe.exec(string.slice(i, i + 1));
13190  return n ? (d.w = +n[0], i + n[0].length) : -1;
13191 }
13192 
13193 function parseWeekdayNumberMonday(d, string, i) {
13194  var n = numberRe.exec(string.slice(i, i + 1));
13195  return n ? (d.u = +n[0], i + n[0].length) : -1;
13196 }
13197 
13198 function parseWeekNumberSunday(d, string, i) {
13199  var n = numberRe.exec(string.slice(i, i + 2));
13200  return n ? (d.U = +n[0], i + n[0].length) : -1;
13201 }
13202 
13203 function parseWeekNumberISO(d, string, i) {
13204  var n = numberRe.exec(string.slice(i, i + 2));
13205  return n ? (d.V = +n[0], i + n[0].length) : -1;
13206 }
13207 
13208 function parseWeekNumberMonday(d, string, i) {
13209  var n = numberRe.exec(string.slice(i, i + 2));
13210  return n ? (d.W = +n[0], i + n[0].length) : -1;
13211 }
13212 
13213 function parseFullYear(d, string, i) {
13214  var n = numberRe.exec(string.slice(i, i + 4));
13215  return n ? (d.y = +n[0], i + n[0].length) : -1;
13216 }
13217 
13218 function parseYear(d, string, i) {
13219  var n = numberRe.exec(string.slice(i, i + 2));
13220  return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
13221 }
13222 
13223 function parseZone(d, string, i) {
13224  var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
13225  return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
13226 }
13227 
13228 function parseMonthNumber(d, string, i) {
13229  var n = numberRe.exec(string.slice(i, i + 2));
13230  return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
13231 }
13232 
13233 function parseDayOfMonth(d, string, i) {
13234  var n = numberRe.exec(string.slice(i, i + 2));
13235  return n ? (d.d = +n[0], i + n[0].length) : -1;
13236 }
13237 
13238 function parseDayOfYear(d, string, i) {
13239  var n = numberRe.exec(string.slice(i, i + 3));
13240  return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
13241 }
13242 
13243 function parseHour24(d, string, i) {
13244  var n = numberRe.exec(string.slice(i, i + 2));
13245  return n ? (d.H = +n[0], i + n[0].length) : -1;
13246 }
13247 
13248 function parseMinutes(d, string, i) {
13249  var n = numberRe.exec(string.slice(i, i + 2));
13250  return n ? (d.M = +n[0], i + n[0].length) : -1;
13251 }
13252 
13253 function parseSeconds(d, string, i) {
13254  var n = numberRe.exec(string.slice(i, i + 2));
13255  return n ? (d.S = +n[0], i + n[0].length) : -1;
13256 }
13257 
13258 function parseMilliseconds(d, string, i) {
13259  var n = numberRe.exec(string.slice(i, i + 3));
13260  return n ? (d.L = +n[0], i + n[0].length) : -1;
13261 }
13262 
13263 function parseMicroseconds(d, string, i) {
13264  var n = numberRe.exec(string.slice(i, i + 6));
13265  return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
13266 }
13267 
13268 function parseLiteralPercent(d, string, i) {
13269  var n = percentRe.exec(string.slice(i, i + 1));
13270  return n ? i + n[0].length : -1;
13271 }
13272 
13273 function parseUnixTimestamp(d, string, i) {
13274  var n = numberRe.exec(string.slice(i));
13275  return n ? (d.Q = +n[0], i + n[0].length) : -1;
13276 }
13277 
13278 function parseUnixTimestampSeconds(d, string, i) {
13279  var n = numberRe.exec(string.slice(i));
13280  return n ? (d.Q = (+n[0]) * 1000, i + n[0].length) : -1;
13281 }
13282 
13283 function formatDayOfMonth(d, p) {
13284  return pad(d.getDate(), p, 2);
13285 }
13286 
13287 function formatHour24(d, p) {
13288  return pad(d.getHours(), p, 2);
13289 }
13290 
13291 function formatHour12(d, p) {
13292  return pad(d.getHours() % 12 || 12, p, 2);
13293 }
13294 
13295 function formatDayOfYear(d, p) {
13296  return pad(1 + day.count(year(d), d), p, 3);
13297 }
13298 
13299 function formatMilliseconds(d, p) {
13300  return pad(d.getMilliseconds(), p, 3);
13301 }
13302 
13303 function formatMicroseconds(d, p) {
13304  return formatMilliseconds(d, p) + "000";
13305 }
13306 
13307 function formatMonthNumber(d, p) {
13308  return pad(d.getMonth() + 1, p, 2);
13309 }
13310 
13311 function formatMinutes(d, p) {
13312  return pad(d.getMinutes(), p, 2);
13313 }
13314 
13315 function formatSeconds(d, p) {
13316  return pad(d.getSeconds(), p, 2);
13317 }
13318 
13319 function formatWeekdayNumberMonday(d) {
13320  var day$$1 = d.getDay();
13321  return day$$1 === 0 ? 7 : day$$1;
13322 }
13323 
13324 function formatWeekNumberSunday(d, p) {
13325  return pad(sunday.count(year(d), d), p, 2);
13326 }
13327 
13328 function formatWeekNumberISO(d, p) {
13329  var day$$1 = d.getDay();
13330  d = (day$$1 >= 4 || day$$1 === 0) ? thursday(d) : thursday.ceil(d);
13331  return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
13332 }
13333 
13334 function formatWeekdayNumberSunday(d) {
13335  return d.getDay();
13336 }
13337 
13338 function formatWeekNumberMonday(d, p) {
13339  return pad(monday.count(year(d), d), p, 2);
13340 }
13341 
13342 function formatYear(d, p) {
13343  return pad(d.getFullYear() % 100, p, 2);
13344 }
13345 
13346 function formatFullYear(d, p) {
13347  return pad(d.getFullYear() % 10000, p, 4);
13348 }
13349 
13350 function formatZone(d) {
13351  var z = d.getTimezoneOffset();
13352  return (z > 0 ? "-" : (z *= -1, "+"))
13353  + pad(z / 60 | 0, "0", 2)
13354  + pad(z % 60, "0", 2);
13355 }
13356 
13357 function formatUTCDayOfMonth(d, p) {
13358  return pad(d.getUTCDate(), p, 2);
13359 }
13360 
13361 function formatUTCHour24(d, p) {
13362  return pad(d.getUTCHours(), p, 2);
13363 }
13364 
13365 function formatUTCHour12(d, p) {
13366  return pad(d.getUTCHours() % 12 || 12, p, 2);
13367 }
13368 
13369 function formatUTCDayOfYear(d, p) {
13370  return pad(1 + utcDay.count(utcYear(d), d), p, 3);
13371 }
13372 
13373 function formatUTCMilliseconds(d, p) {
13374  return pad(d.getUTCMilliseconds(), p, 3);
13375 }
13376 
13377 function formatUTCMicroseconds(d, p) {
13378  return formatUTCMilliseconds(d, p) + "000";
13379 }
13380 
13381 function formatUTCMonthNumber(d, p) {
13382  return pad(d.getUTCMonth() + 1, p, 2);
13383 }
13384 
13385 function formatUTCMinutes(d, p) {
13386  return pad(d.getUTCMinutes(), p, 2);
13387 }
13388 
13389 function formatUTCSeconds(d, p) {
13390  return pad(d.getUTCSeconds(), p, 2);
13391 }
13392 
13393 function formatUTCWeekdayNumberMonday(d) {
13394  var dow = d.getUTCDay();
13395  return dow === 0 ? 7 : dow;
13396 }
13397 
13398 function formatUTCWeekNumberSunday(d, p) {
13399  return pad(utcSunday.count(utcYear(d), d), p, 2);
13400 }
13401 
13402 function formatUTCWeekNumberISO(d, p) {
13403  var day$$1 = d.getUTCDay();
13404  d = (day$$1 >= 4 || day$$1 === 0) ? utcThursday(d) : utcThursday.ceil(d);
13405  return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
13406 }
13407 
13408 function formatUTCWeekdayNumberSunday(d) {
13409  return d.getUTCDay();
13410 }
13411 
13412 function formatUTCWeekNumberMonday(d, p) {
13413  return pad(utcMonday.count(utcYear(d), d), p, 2);
13414 }
13415 
13416 function formatUTCYear(d, p) {
13417  return pad(d.getUTCFullYear() % 100, p, 2);
13418 }
13419 
13420 function formatUTCFullYear(d, p) {
13421  return pad(d.getUTCFullYear() % 10000, p, 4);
13422 }
13423 
13424 function formatUTCZone() {
13425  return "+0000";
13426 }
13427 
13428 function formatLiteralPercent() {
13429  return "%";
13430 }
13431 
13432 function formatUnixTimestamp(d) {
13433  return +d;
13434 }
13435 
13436 function formatUnixTimestampSeconds(d) {
13437  return Math.floor(+d / 1000);
13438 }
13439 
13440 var locale$1;
13441 
13442 defaultLocale$1({
13443  dateTime: "%x, %X",
13444  date: "%-m/%-d/%Y",
13445  time: "%-I:%M:%S %p",
13446  periods: ["AM", "PM"],
13447  days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
13448  shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
13449  months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
13450  shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
13451 });
13452 
13453 function defaultLocale$1(definition) {
13454  locale$1 = formatLocale$1(definition);
13455  exports.timeFormat = locale$1.format;
13456  exports.timeParse = locale$1.parse;
13457  exports.utcFormat = locale$1.utcFormat;
13458  exports.utcParse = locale$1.utcParse;
13459  return locale$1;
13460 }
13461 
13462 var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
13463 
13464 function formatIsoNative(date) {
13465  return date.toISOString();
13466 }
13467 
13468 var formatIso = Date.prototype.toISOString
13469  ? formatIsoNative
13470  : exports.utcFormat(isoSpecifier);
13471 
13472 function parseIsoNative(string) {
13473  var date = new Date(string);
13474  return isNaN(date) ? null : date;
13475 }
13476 
13477 var parseIso = +new Date("2000-01-01T00:00:00.000Z")
13478  ? parseIsoNative
13479  : exports.utcParse(isoSpecifier);
13480 
13481 var durationSecond$1 = 1000,
13482  durationMinute$1 = durationSecond$1 * 60,
13483  durationHour$1 = durationMinute$1 * 60,
13484  durationDay$1 = durationHour$1 * 24,
13485  durationWeek$1 = durationDay$1 * 7,
13486  durationMonth = durationDay$1 * 30,
13487  durationYear = durationDay$1 * 365;
13488 
13489 function date$1(t) {
13490  return new Date(t);
13491 }
13492 
13493 function number$3(t) {
13494  return t instanceof Date ? +t : +new Date(+t);
13495 }
13496 
13497 function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
13498  var scale = continuous(deinterpolateLinear, interpolateNumber),
13499  invert = scale.invert,
13500  domain = scale.domain;
13501 
13502  var formatMillisecond = format(".%L"),
13503  formatSecond = format(":%S"),
13504  formatMinute = format("%I:%M"),
13505  formatHour = format("%I %p"),
13506  formatDay = format("%a %d"),
13507  formatWeek = format("%b %d"),
13508  formatMonth = format("%B"),
13509  formatYear = format("%Y");
13510 
13511  var tickIntervals = [
13512  [second$$1, 1, durationSecond$1],
13513  [second$$1, 5, 5 * durationSecond$1],
13514  [second$$1, 15, 15 * durationSecond$1],
13515  [second$$1, 30, 30 * durationSecond$1],
13516  [minute$$1, 1, durationMinute$1],
13517  [minute$$1, 5, 5 * durationMinute$1],
13518  [minute$$1, 15, 15 * durationMinute$1],
13519  [minute$$1, 30, 30 * durationMinute$1],
13520  [ hour$$1, 1, durationHour$1 ],
13521  [ hour$$1, 3, 3 * durationHour$1 ],
13522  [ hour$$1, 6, 6 * durationHour$1 ],
13523  [ hour$$1, 12, 12 * durationHour$1 ],
13524  [ day$$1, 1, durationDay$1 ],
13525  [ day$$1, 2, 2 * durationDay$1 ],
13526  [ week, 1, durationWeek$1 ],
13527  [ month$$1, 1, durationMonth ],
13528  [ month$$1, 3, 3 * durationMonth ],
13529  [ year$$1, 1, durationYear ]
13530  ];
13531 
13532  function tickFormat(date$$1) {
13533  return (second$$1(date$$1) < date$$1 ? formatMillisecond
13534  : minute$$1(date$$1) < date$$1 ? formatSecond
13535  : hour$$1(date$$1) < date$$1 ? formatMinute
13536  : day$$1(date$$1) < date$$1 ? formatHour
13537  : month$$1(date$$1) < date$$1 ? (week(date$$1) < date$$1 ? formatDay : formatWeek)
13538  : year$$1(date$$1) < date$$1 ? formatMonth
13539  : formatYear)(date$$1);
13540  }
13541 
13542  function tickInterval(interval, start, stop, step) {
13543  if (interval == null) interval = 10;
13544 
13545  // If a desired tick count is specified, pick a reasonable tick interval
13546  // based on the extent of the domain and a rough estimate of tick size.
13547  // Otherwise, assume interval is already a time interval and use it.
13548  if (typeof interval === "number") {
13549  var target = Math.abs(stop - start) / interval,
13550  i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
13551  if (i === tickIntervals.length) {
13552  step = tickStep(start / durationYear, stop / durationYear, interval);
13553  interval = year$$1;
13554  } else if (i) {
13555  i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
13556  step = i[1];
13557  interval = i[0];
13558  } else {
13559  step = Math.max(tickStep(start, stop, interval), 1);
13560  interval = millisecond$$1;
13561  }
13562  }
13563 
13564  return step == null ? interval : interval.every(step);
13565  }
13566 
13567  scale.invert = function(y) {
13568  return new Date(invert(y));
13569  };
13570 
13571  scale.domain = function(_) {
13572  return arguments.length ? domain(map$2.call(_, number$3)) : domain().map(date$1);
13573  };
13574 
13575  scale.ticks = function(interval, step) {
13576  var d = domain(),
13577  t0 = d[0],
13578  t1 = d[d.length - 1],
13579  r = t1 < t0,
13580  t;
13581  if (r) t = t0, t0 = t1, t1 = t;
13582  t = tickInterval(interval, t0, t1, step);
13583  t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
13584  return r ? t.reverse() : t;
13585  };
13586 
13587  scale.tickFormat = function(count, specifier) {
13588  return specifier == null ? tickFormat : format(specifier);
13589  };
13590 
13591  scale.nice = function(interval, step) {
13592  var d = domain();
13593  return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
13594  ? domain(nice(d, interval))
13595  : scale;
13596  };
13597 
13598  scale.copy = function() {
13599  return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
13600  };
13601 
13602  return scale;
13603 }
13604 
13605 function time() {
13606  return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
13607 }
13608 
13609 function utcTime() {
13610  return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
13611 }
13612 
13613 function sequential(interpolator) {
13614  var x0 = 0,
13615  x1 = 1,
13616  k10 = 1,
13617  clamp = false;
13618 
13619  function scale(x) {
13620  var t = (x - x0) * k10;
13621  return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
13622  }
13623 
13624  scale.domain = function(_) {
13625  return arguments.length ? (x0 = +_[0], x1 = +_[1], k10 = x0 === x1 ? 0 : 1 / (x1 - x0), scale) : [x0, x1];
13626  };
13627 
13628  scale.clamp = function(_) {
13629  return arguments.length ? (clamp = !!_, scale) : clamp;
13630  };
13631 
13632  scale.interpolator = function(_) {
13633  return arguments.length ? (interpolator = _, scale) : interpolator;
13634  };
13635 
13636  scale.copy = function() {
13637  return sequential(interpolator).domain([x0, x1]).clamp(clamp);
13638  };
13639 
13640  return linearish(scale);
13641 }
13642 
13643 function diverging(interpolator) {
13644  var x0 = 0,
13645  x1 = 0.5,
13646  x2 = 1,
13647  k10 = 1,
13648  k21 = 1,
13649  clamp = false;
13650 
13651  function scale(x) {
13652  var t = 0.5 + ((x = +x) - x1) * (x < x1 ? k10 : k21);
13653  return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
13654  }
13655 
13656  scale.domain = function(_) {
13657  return arguments.length ? (x0 = +_[0], x1 = +_[1], x2 = +_[2], k10 = x0 === x1 ? 0 : 0.5 / (x1 - x0), k21 = x1 === x2 ? 0 : 0.5 / (x2 - x1), scale) : [x0, x1, x2];
13658  };
13659 
13660  scale.clamp = function(_) {
13661  return arguments.length ? (clamp = !!_, scale) : clamp;
13662  };
13663 
13664  scale.interpolator = function(_) {
13665  return arguments.length ? (interpolator = _, scale) : interpolator;
13666  };
13667 
13668  scale.copy = function() {
13669  return diverging(interpolator).domain([x0, x1, x2]).clamp(clamp);
13670  };
13671 
13672  return linearish(scale);
13673 }
13674 
13675 function colors(specifier) {
13676  var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
13677  while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
13678  return colors;
13679 }
13680 
13681 var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
13682 
13683 var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
13684 
13685 var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
13686 
13687 var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
13688 
13689 var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
13690 
13691 var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
13692 
13693 var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
13694 
13695 var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
13696 
13697 var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
13698 
13699 function ramp(scheme) {
13700  return rgbBasis(scheme[scheme.length - 1]);
13701 }
13702 
13703 var scheme = new Array(3).concat(
13704  "d8b365f5f5f55ab4ac",
13705  "a6611adfc27d80cdc1018571",
13706  "a6611adfc27df5f5f580cdc1018571",
13707  "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
13708  "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
13709  "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
13710  "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
13711  "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
13712  "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
13713 ).map(colors);
13714 
13715 var BrBG = ramp(scheme);
13716 
13717 var scheme$1 = new Array(3).concat(
13718  "af8dc3f7f7f77fbf7b",
13719  "7b3294c2a5cfa6dba0008837",
13720  "7b3294c2a5cff7f7f7a6dba0008837",
13721  "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
13722  "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
13723  "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
13724  "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
13725  "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
13726  "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
13727 ).map(colors);
13728 
13729 var PRGn = ramp(scheme$1);
13730 
13731 var scheme$2 = new Array(3).concat(
13732  "e9a3c9f7f7f7a1d76a",
13733  "d01c8bf1b6dab8e1864dac26",
13734  "d01c8bf1b6daf7f7f7b8e1864dac26",
13735  "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
13736  "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
13737  "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
13738  "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
13739  "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
13740  "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
13741 ).map(colors);
13742 
13743 var PiYG = ramp(scheme$2);
13744 
13745 var scheme$3 = new Array(3).concat(
13746  "998ec3f7f7f7f1a340",
13747  "5e3c99b2abd2fdb863e66101",
13748  "5e3c99b2abd2f7f7f7fdb863e66101",
13749  "542788998ec3d8daebfee0b6f1a340b35806",
13750  "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
13751  "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
13752  "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
13753  "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
13754  "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
13755 ).map(colors);
13756 
13757 var PuOr = ramp(scheme$3);
13758 
13759 var scheme$4 = new Array(3).concat(
13760  "ef8a62f7f7f767a9cf",
13761  "ca0020f4a58292c5de0571b0",
13762  "ca0020f4a582f7f7f792c5de0571b0",
13763  "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
13764  "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
13765  "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
13766  "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
13767  "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
13768  "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
13769 ).map(colors);
13770 
13771 var RdBu = ramp(scheme$4);
13772 
13773 var scheme$5 = new Array(3).concat(
13774  "ef8a62ffffff999999",
13775  "ca0020f4a582bababa404040",
13776  "ca0020f4a582ffffffbababa404040",
13777  "b2182bef8a62fddbc7e0e0e09999994d4d4d",
13778  "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
13779  "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
13780  "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
13781  "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
13782  "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
13783 ).map(colors);
13784 
13785 var RdGy = ramp(scheme$5);
13786 
13787 var scheme$6 = new Array(3).concat(
13788  "fc8d59ffffbf91bfdb",
13789  "d7191cfdae61abd9e92c7bb6",
13790  "d7191cfdae61ffffbfabd9e92c7bb6",
13791  "d73027fc8d59fee090e0f3f891bfdb4575b4",
13792  "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
13793  "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
13794  "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
13795  "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
13796  "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
13797 ).map(colors);
13798 
13799 var RdYlBu = ramp(scheme$6);
13800 
13801 var scheme$7 = new Array(3).concat(
13802  "fc8d59ffffbf91cf60",
13803  "d7191cfdae61a6d96a1a9641",
13804  "d7191cfdae61ffffbfa6d96a1a9641",
13805  "d73027fc8d59fee08bd9ef8b91cf601a9850",
13806  "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
13807  "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
13808  "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
13809  "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
13810  "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
13811 ).map(colors);
13812 
13813 var RdYlGn = ramp(scheme$7);
13814 
13815 var scheme$8 = new Array(3).concat(
13816  "fc8d59ffffbf99d594",
13817  "d7191cfdae61abdda42b83ba",
13818  "d7191cfdae61ffffbfabdda42b83ba",
13819  "d53e4ffc8d59fee08be6f59899d5943288bd",
13820  "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
13821  "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
13822  "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
13823  "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
13824  "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
13825 ).map(colors);
13826 
13827 var Spectral = ramp(scheme$8);
13828 
13829 var scheme$9 = new Array(3).concat(
13830  "e5f5f999d8c92ca25f",
13831  "edf8fbb2e2e266c2a4238b45",
13832  "edf8fbb2e2e266c2a42ca25f006d2c",
13833  "edf8fbccece699d8c966c2a42ca25f006d2c",
13834  "edf8fbccece699d8c966c2a441ae76238b45005824",
13835  "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
13836  "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
13837 ).map(colors);
13838 
13839 var BuGn = ramp(scheme$9);
13840 
13841 var scheme$a = new Array(3).concat(
13842  "e0ecf49ebcda8856a7",
13843  "edf8fbb3cde38c96c688419d",
13844  "edf8fbb3cde38c96c68856a7810f7c",
13845  "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
13846  "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
13847  "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
13848  "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
13849 ).map(colors);
13850 
13851 var BuPu = ramp(scheme$a);
13852 
13853 var scheme$b = new Array(3).concat(
13854  "e0f3dba8ddb543a2ca",
13855  "f0f9e8bae4bc7bccc42b8cbe",
13856  "f0f9e8bae4bc7bccc443a2ca0868ac",
13857  "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
13858  "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
13859  "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
13860  "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
13861 ).map(colors);
13862 
13863 var GnBu = ramp(scheme$b);
13864 
13865 var scheme$c = new Array(3).concat(
13866  "fee8c8fdbb84e34a33",
13867  "fef0d9fdcc8afc8d59d7301f",
13868  "fef0d9fdcc8afc8d59e34a33b30000",
13869  "fef0d9fdd49efdbb84fc8d59e34a33b30000",
13870  "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
13871  "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
13872  "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
13873 ).map(colors);
13874 
13875 var OrRd = ramp(scheme$c);
13876 
13877 var scheme$d = new Array(3).concat(
13878  "ece2f0a6bddb1c9099",
13879  "f6eff7bdc9e167a9cf02818a",
13880  "f6eff7bdc9e167a9cf1c9099016c59",
13881  "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
13882  "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
13883  "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
13884  "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
13885 ).map(colors);
13886 
13887 var PuBuGn = ramp(scheme$d);
13888 
13889 var scheme$e = new Array(3).concat(
13890  "ece7f2a6bddb2b8cbe",
13891  "f1eef6bdc9e174a9cf0570b0",
13892  "f1eef6bdc9e174a9cf2b8cbe045a8d",
13893  "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
13894  "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
13895  "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
13896  "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
13897 ).map(colors);
13898 
13899 var PuBu = ramp(scheme$e);
13900 
13901 var scheme$f = new Array(3).concat(
13902  "e7e1efc994c7dd1c77",
13903  "f1eef6d7b5d8df65b0ce1256",
13904  "f1eef6d7b5d8df65b0dd1c77980043",
13905  "f1eef6d4b9dac994c7df65b0dd1c77980043",
13906  "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
13907  "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
13908  "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
13909 ).map(colors);
13910 
13911 var PuRd = ramp(scheme$f);
13912 
13913 var scheme$g = new Array(3).concat(
13914  "fde0ddfa9fb5c51b8a",
13915  "feebe2fbb4b9f768a1ae017e",
13916  "feebe2fbb4b9f768a1c51b8a7a0177",
13917  "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
13918  "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
13919  "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
13920  "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
13921 ).map(colors);
13922 
13923 var RdPu = ramp(scheme$g);
13924 
13925 var scheme$h = new Array(3).concat(
13926  "edf8b17fcdbb2c7fb8",
13927  "ffffcca1dab441b6c4225ea8",
13928  "ffffcca1dab441b6c42c7fb8253494",
13929  "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
13930  "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
13931  "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
13932  "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
13933 ).map(colors);
13934 
13935 var YlGnBu = ramp(scheme$h);
13936 
13937 var scheme$i = new Array(3).concat(
13938  "f7fcb9addd8e31a354",
13939  "ffffccc2e69978c679238443",
13940  "ffffccc2e69978c67931a354006837",
13941  "ffffccd9f0a3addd8e78c67931a354006837",
13942  "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
13943  "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
13944  "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
13945 ).map(colors);
13946 
13947 var YlGn = ramp(scheme$i);
13948 
13949 var scheme$j = new Array(3).concat(
13950  "fff7bcfec44fd95f0e",
13951  "ffffd4fed98efe9929cc4c02",
13952  "ffffd4fed98efe9929d95f0e993404",
13953  "ffffd4fee391fec44ffe9929d95f0e993404",
13954  "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
13955  "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
13956  "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
13957 ).map(colors);
13958 
13959 var YlOrBr = ramp(scheme$j);
13960 
13961 var scheme$k = new Array(3).concat(
13962  "ffeda0feb24cf03b20",
13963  "ffffb2fecc5cfd8d3ce31a1c",
13964  "ffffb2fecc5cfd8d3cf03b20bd0026",
13965  "ffffb2fed976feb24cfd8d3cf03b20bd0026",
13966  "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
13967  "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
13968  "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
13969 ).map(colors);
13970 
13971 var YlOrRd = ramp(scheme$k);
13972 
13973 var scheme$l = new Array(3).concat(
13974  "deebf79ecae13182bd",
13975  "eff3ffbdd7e76baed62171b5",
13976  "eff3ffbdd7e76baed63182bd08519c",
13977  "eff3ffc6dbef9ecae16baed63182bd08519c",
13978  "eff3ffc6dbef9ecae16baed64292c62171b5084594",
13979  "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
13980  "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
13981 ).map(colors);
13982 
13983 var Blues = ramp(scheme$l);
13984 
13985 var scheme$m = new Array(3).concat(
13986  "e5f5e0a1d99b31a354",
13987  "edf8e9bae4b374c476238b45",
13988  "edf8e9bae4b374c47631a354006d2c",
13989  "edf8e9c7e9c0a1d99b74c47631a354006d2c",
13990  "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
13991  "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
13992  "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
13993 ).map(colors);
13994 
13995 var Greens = ramp(scheme$m);
13996 
13997 var scheme$n = new Array(3).concat(
13998  "f0f0f0bdbdbd636363",
13999  "f7f7f7cccccc969696525252",
14000  "f7f7f7cccccc969696636363252525",
14001  "f7f7f7d9d9d9bdbdbd969696636363252525",
14002  "f7f7f7d9d9d9bdbdbd969696737373525252252525",
14003  "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
14004  "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
14005 ).map(colors);
14006 
14007 var Greys = ramp(scheme$n);
14008 
14009 var scheme$o = new Array(3).concat(
14010  "efedf5bcbddc756bb1",
14011  "f2f0f7cbc9e29e9ac86a51a3",
14012  "f2f0f7cbc9e29e9ac8756bb154278f",
14013  "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
14014  "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
14015  "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
14016  "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
14017 ).map(colors);
14018 
14019 var Purples = ramp(scheme$o);
14020 
14021 var scheme$p = new Array(3).concat(
14022  "fee0d2fc9272de2d26",
14023  "fee5d9fcae91fb6a4acb181d",
14024  "fee5d9fcae91fb6a4ade2d26a50f15",
14025  "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
14026  "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
14027  "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
14028  "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
14029 ).map(colors);
14030 
14031 var Reds = ramp(scheme$p);
14032 
14033 var scheme$q = new Array(3).concat(
14034  "fee6cefdae6be6550d",
14035  "feeddefdbe85fd8d3cd94701",
14036  "feeddefdbe85fd8d3ce6550da63603",
14037  "feeddefdd0a2fdae6bfd8d3ce6550da63603",
14038  "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
14039  "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
14040  "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
14041 ).map(colors);
14042 
14043 var Oranges = ramp(scheme$q);
14044 
14045 var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
14046 
14047 var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
14048 
14049 var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
14050 
14051 var c = cubehelix();
14052 
14053 function rainbow(t) {
14054  if (t < 0 || t > 1) t -= Math.floor(t);
14055  var ts = Math.abs(t - 0.5);
14056  c.h = 360 * t - 100;
14057  c.s = 1.5 - 1.5 * ts;
14058  c.l = 0.8 - 0.9 * ts;
14059  return c + "";
14060 }
14061 
14062 var c$1 = rgb(),
14063  pi_1_3 = Math.PI / 3,
14064  pi_2_3 = Math.PI * 2 / 3;
14065 
14066 function sinebow(t) {
14067  var x;
14068  t = (0.5 - t) * Math.PI;
14069  c$1.r = 255 * (x = Math.sin(t)) * x;
14070  c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
14071  c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
14072  return c$1 + "";
14073 }
14074 
14075 function ramp$1(range) {
14076  var n = range.length;
14077  return function(t) {
14078  return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
14079  };
14080 }
14081 
14082 var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
14083 
14084 var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
14085 
14086 var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
14087 
14088 var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
14089 
14090 function constant$b(x) {
14091  return function constant() {
14092  return x;
14093  };
14094 }
14095 
14096 var abs$1 = Math.abs;
14097 var atan2$1 = Math.atan2;
14098 var cos$2 = Math.cos;
14099 var max$2 = Math.max;
14100 var min$1 = Math.min;
14101 var sin$2 = Math.sin;
14102 var sqrt$2 = Math.sqrt;
14103 
14104 var epsilon$3 = 1e-12;
14105 var pi$4 = Math.PI;
14106 var halfPi$3 = pi$4 / 2;
14107 var tau$4 = 2 * pi$4;
14108 
14109 function acos$1(x) {
14110  return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
14111 }
14112 
14113 function asin$1(x) {
14114  return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
14115 }
14116 
14117 function arcInnerRadius(d) {
14118  return d.innerRadius;
14119 }
14120 
14121 function arcOuterRadius(d) {
14122  return d.outerRadius;
14123 }
14124 
14125 function arcStartAngle(d) {
14126  return d.startAngle;
14127 }
14128 
14129 function arcEndAngle(d) {
14130  return d.endAngle;
14131 }
14132 
14133 function arcPadAngle(d) {
14134  return d && d.padAngle; // Note: optional!
14135 }
14136 
14137 function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
14138  var x10 = x1 - x0, y10 = y1 - y0,
14139  x32 = x3 - x2, y32 = y3 - y2,
14140  t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
14141  return [x0 + t * x10, y0 + t * y10];
14142 }
14143 
14144 // Compute perpendicular offset line of length rc.
14145 // http://mathworld.wolfram.com/Circle-LineIntersection.html
14146 function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
14147  var x01 = x0 - x1,
14148  y01 = y0 - y1,
14149  lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
14150  ox = lo * y01,
14151  oy = -lo * x01,
14152  x11 = x0 + ox,
14153  y11 = y0 + oy,
14154  x10 = x1 + ox,
14155  y10 = y1 + oy,
14156  x00 = (x11 + x10) / 2,
14157  y00 = (y11 + y10) / 2,
14158  dx = x10 - x11,
14159  dy = y10 - y11,
14160  d2 = dx * dx + dy * dy,
14161  r = r1 - rc,
14162  D = x11 * y10 - x10 * y11,
14163  d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
14164  cx0 = (D * dy - dx * d) / d2,
14165  cy0 = (-D * dx - dy * d) / d2,
14166  cx1 = (D * dy + dx * d) / d2,
14167  cy1 = (-D * dx + dy * d) / d2,
14168  dx0 = cx0 - x00,
14169  dy0 = cy0 - y00,
14170  dx1 = cx1 - x00,
14171  dy1 = cy1 - y00;
14172 
14173  // Pick the closer of the two intersection points.
14174  // TODO Is there a faster way to determine which intersection to use?
14175  if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
14176 
14177  return {
14178  cx: cx0,
14179  cy: cy0,
14180  x01: -ox,
14181  y01: -oy,
14182  x11: cx0 * (r1 / r - 1),
14183  y11: cy0 * (r1 / r - 1)
14184  };
14185 }
14186 
14187 function arc() {
14188  var innerRadius = arcInnerRadius,
14189  outerRadius = arcOuterRadius,
14190  cornerRadius = constant$b(0),
14191  padRadius = null,
14192  startAngle = arcStartAngle,
14193  endAngle = arcEndAngle,
14194  padAngle = arcPadAngle,
14195  context = null;
14196 
14197  function arc() {
14198  var buffer,
14199  r,
14200  r0 = +innerRadius.apply(this, arguments),
14201  r1 = +outerRadius.apply(this, arguments),
14202  a0 = startAngle.apply(this, arguments) - halfPi$3,
14203  a1 = endAngle.apply(this, arguments) - halfPi$3,
14204  da = abs$1(a1 - a0),
14205  cw = a1 > a0;
14206 
14207  if (!context) context = buffer = path();
14208 
14209  // Ensure that the outer radius is always larger than the inner radius.
14210  if (r1 < r0) r = r1, r1 = r0, r0 = r;
14211 
14212  // Is it a point?
14213  if (!(r1 > epsilon$3)) context.moveTo(0, 0);
14214 
14215  // Or is it a circle or annulus?
14216  else if (da > tau$4 - epsilon$3) {
14217  context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
14218  context.arc(0, 0, r1, a0, a1, !cw);
14219  if (r0 > epsilon$3) {
14220  context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
14221  context.arc(0, 0, r0, a1, a0, cw);
14222  }
14223  }
14224 
14225  // Or is it a circular or annular sector?
14226  else {
14227  var a01 = a0,
14228  a11 = a1,
14229  a00 = a0,
14230  a10 = a1,
14231  da0 = da,
14232  da1 = da,
14233  ap = padAngle.apply(this, arguments) / 2,
14234  rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
14235  rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
14236  rc0 = rc,
14237  rc1 = rc,
14238  t0,
14239  t1;
14240 
14241  // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
14242  if (rp > epsilon$3) {
14243  var p0 = asin$1(rp / r0 * sin$2(ap)),
14244  p1 = asin$1(rp / r1 * sin$2(ap));
14245  if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
14246  else da0 = 0, a00 = a10 = (a0 + a1) / 2;
14247  if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
14248  else da1 = 0, a01 = a11 = (a0 + a1) / 2;
14249  }
14250 
14251  var x01 = r1 * cos$2(a01),
14252  y01 = r1 * sin$2(a01),
14253  x10 = r0 * cos$2(a10),
14254  y10 = r0 * sin$2(a10);
14255 
14256  // Apply rounded corners?
14257  if (rc > epsilon$3) {
14258  var x11 = r1 * cos$2(a11),
14259  y11 = r1 * sin$2(a11),
14260  x00 = r0 * cos$2(a00),
14261  y00 = r0 * sin$2(a00);
14262 
14263  // Restrict the corner radius according to the sector angle.
14264  if (da < pi$4) {
14265  var oc = da0 > epsilon$3 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
14266  ax = x01 - oc[0],
14267  ay = y01 - oc[1],
14268  bx = x11 - oc[0],
14269  by = y11 - oc[1],
14270  kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
14271  lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
14272  rc0 = min$1(rc, (r0 - lc) / (kc - 1));
14273  rc1 = min$1(rc, (r1 - lc) / (kc + 1));
14274  }
14275  }
14276 
14277  // Is the sector collapsed to a line?
14278  if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
14279 
14280  // Does the sector’s outer ring have rounded corners?
14281  else if (rc1 > epsilon$3) {
14282  t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
14283  t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
14284 
14285  context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
14286 
14287  // Have the corners merged?
14288  if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
14289 
14290  // Otherwise, draw the two corners and the ring.
14291  else {
14292  context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
14293  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);
14294  context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
14295  }
14296  }
14297 
14298  // Or is the outer ring just a circular arc?
14299  else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
14300 
14301  // Is there no inner ring, and it’s a circular sector?
14302  // Or perhaps it’s an annular sector collapsed due to padding?
14303  if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
14304 
14305  // Does the sector’s inner ring (or point) have rounded corners?
14306  else if (rc0 > epsilon$3) {
14307  t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
14308  t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
14309 
14310  context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
14311 
14312  // Have the corners merged?
14313  if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
14314 
14315  // Otherwise, draw the two corners and the ring.
14316  else {
14317  context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
14318  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);
14319  context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
14320  }
14321  }
14322 
14323  // Or is the inner ring just a circular arc?
14324  else context.arc(0, 0, r0, a10, a00, cw);
14325  }
14326 
14327  context.closePath();
14328 
14329  if (buffer) return context = null, buffer + "" || null;
14330  }
14331 
14332  arc.centroid = function() {
14333  var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
14334  a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
14335  return [cos$2(a) * r, sin$2(a) * r];
14336  };
14337 
14338  arc.innerRadius = function(_) {
14339  return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : innerRadius;
14340  };
14341 
14342  arc.outerRadius = function(_) {
14343  return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : outerRadius;
14344  };
14345 
14346  arc.cornerRadius = function(_) {
14347  return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : cornerRadius;
14348  };
14349 
14350  arc.padRadius = function(_) {
14351  return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), arc) : padRadius;
14352  };
14353 
14354  arc.startAngle = function(_) {
14355  return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : startAngle;
14356  };
14357 
14358  arc.endAngle = function(_) {
14359  return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : endAngle;
14360  };
14361 
14362  arc.padAngle = function(_) {
14363  return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : padAngle;
14364  };
14365 
14366  arc.context = function(_) {
14367  return arguments.length ? ((context = _ == null ? null : _), arc) : context;
14368  };
14369 
14370  return arc;
14371 }
14372 
14373 function Linear(context) {
14374  this._context = context;
14375 }
14376 
14377 Linear.prototype = {
14378  areaStart: function() {
14379  this._line = 0;
14380  },
14381  areaEnd: function() {
14382  this._line = NaN;
14383  },
14384  lineStart: function() {
14385  this._point = 0;
14386  },
14387  lineEnd: function() {
14388  if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14389  this._line = 1 - this._line;
14390  },
14391  point: function(x, y) {
14392  x = +x, y = +y;
14393  switch (this._point) {
14394  case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
14395  case 1: this._point = 2; // proceed
14396  default: this._context.lineTo(x, y); break;
14397  }
14398  }
14399 };
14400 
14401 function curveLinear(context) {
14402  return new Linear(context);
14403 }
14404 
14405 function x$3(p) {
14406  return p[0];
14407 }
14408 
14409 function y$3(p) {
14410  return p[1];
14411 }
14412 
14413 function line() {
14414  var x$$1 = x$3,
14415  y$$1 = y$3,
14416  defined = constant$b(true),
14417  context = null,
14418  curve = curveLinear,
14419  output = null;
14420 
14421  function line(data) {
14422  var i,
14423  n = data.length,
14424  d,
14425  defined0 = false,
14426  buffer;
14427 
14428  if (context == null) output = curve(buffer = path());
14429 
14430  for (i = 0; i <= n; ++i) {
14431  if (!(i < n && defined(d = data[i], i, data)) === defined0) {
14432  if (defined0 = !defined0) output.lineStart();
14433  else output.lineEnd();
14434  }
14435  if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
14436  }
14437 
14438  if (buffer) return output = null, buffer + "" || null;
14439  }
14440 
14441  line.x = function(_) {
14442  return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$b(+_), line) : x$$1;
14443  };
14444 
14445  line.y = function(_) {
14446  return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$b(+_), line) : y$$1;
14447  };
14448 
14449  line.defined = function(_) {
14450  return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), line) : defined;
14451  };
14452 
14453  line.curve = function(_) {
14454  return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
14455  };
14456 
14457  line.context = function(_) {
14458  return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
14459  };
14460 
14461  return line;
14462 }
14463 
14464 function area$3() {
14465  var x0 = x$3,
14466  x1 = null,
14467  y0 = constant$b(0),
14468  y1 = y$3,
14469  defined = constant$b(true),
14470  context = null,
14471  curve = curveLinear,
14472  output = null;
14473 
14474  function area(data) {
14475  var i,
14476  j,
14477  k,
14478  n = data.length,
14479  d,
14480  defined0 = false,
14481  buffer,
14482  x0z = new Array(n),
14483  y0z = new Array(n);
14484 
14485  if (context == null) output = curve(buffer = path());
14486 
14487  for (i = 0; i <= n; ++i) {
14488  if (!(i < n && defined(d = data[i], i, data)) === defined0) {
14489  if (defined0 = !defined0) {
14490  j = i;
14491  output.areaStart();
14492  output.lineStart();
14493  } else {
14494  output.lineEnd();
14495  output.lineStart();
14496  for (k = i - 1; k >= j; --k) {
14497  output.point(x0z[k], y0z[k]);
14498  }
14499  output.lineEnd();
14500  output.areaEnd();
14501  }
14502  }
14503  if (defined0) {
14504  x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
14505  output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
14506  }
14507  }
14508 
14509  if (buffer) return output = null, buffer + "" || null;
14510  }
14511 
14512  function arealine() {
14513  return line().defined(defined).curve(curve).context(context);
14514  }
14515 
14516  area.x = function(_) {
14517  return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), x1 = null, area) : x0;
14518  };
14519 
14520  area.x0 = function(_) {
14521  return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), area) : x0;
14522  };
14523 
14524  area.x1 = function(_) {
14525  return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : x1;
14526  };
14527 
14528  area.y = function(_) {
14529  return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), y1 = null, area) : y0;
14530  };
14531 
14532  area.y0 = function(_) {
14533  return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), area) : y0;
14534  };
14535 
14536  area.y1 = function(_) {
14537  return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : y1;
14538  };
14539 
14540  area.lineX0 =
14541  area.lineY0 = function() {
14542  return arealine().x(x0).y(y0);
14543  };
14544 
14545  area.lineY1 = function() {
14546  return arealine().x(x0).y(y1);
14547  };
14548 
14549  area.lineX1 = function() {
14550  return arealine().x(x1).y(y0);
14551  };
14552 
14553  area.defined = function(_) {
14554  return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), area) : defined;
14555  };
14556 
14557  area.curve = function(_) {
14558  return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
14559  };
14560 
14561  area.context = function(_) {
14562  return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
14563  };
14564 
14565  return area;
14566 }
14567 
14568 function descending$1(a, b) {
14569  return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
14570 }
14571 
14572 function identity$7(d) {
14573  return d;
14574 }
14575 
14576 function pie() {
14577  var value = identity$7,
14578  sortValues = descending$1,
14579  sort = null,
14580  startAngle = constant$b(0),
14581  endAngle = constant$b(tau$4),
14582  padAngle = constant$b(0);
14583 
14584  function pie(data) {
14585  var i,
14586  n = data.length,
14587  j,
14588  k,
14589  sum = 0,
14590  index = new Array(n),
14591  arcs = new Array(n),
14592  a0 = +startAngle.apply(this, arguments),
14593  da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
14594  a1,
14595  p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
14596  pa = p * (da < 0 ? -1 : 1),
14597  v;
14598 
14599  for (i = 0; i < n; ++i) {
14600  if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
14601  sum += v;
14602  }
14603  }
14604 
14605  // Optionally sort the arcs by previously-computed values or by data.
14606  if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
14607  else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
14608 
14609  // Compute the arcs! They are stored in the original data's order.
14610  for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
14611  j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
14612  data: data[j],
14613  index: i,
14614  value: v,
14615  startAngle: a0,
14616  endAngle: a1,
14617  padAngle: p
14618  };
14619  }
14620 
14621  return arcs;
14622  }
14623 
14624  pie.value = function(_) {
14625  return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), pie) : value;
14626  };
14627 
14628  pie.sortValues = function(_) {
14629  return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
14630  };
14631 
14632  pie.sort = function(_) {
14633  return arguments.length ? (sort = _, sortValues = null, pie) : sort;
14634  };
14635 
14636  pie.startAngle = function(_) {
14637  return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : startAngle;
14638  };
14639 
14640  pie.endAngle = function(_) {
14641  return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : endAngle;
14642  };
14643 
14644  pie.padAngle = function(_) {
14645  return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : padAngle;
14646  };
14647 
14648  return pie;
14649 }
14650 
14651 var curveRadialLinear = curveRadial(curveLinear);
14652 
14653 function Radial(curve) {
14654  this._curve = curve;
14655 }
14656 
14657 Radial.prototype = {
14658  areaStart: function() {
14659  this._curve.areaStart();
14660  },
14661  areaEnd: function() {
14662  this._curve.areaEnd();
14663  },
14664  lineStart: function() {
14665  this._curve.lineStart();
14666  },
14667  lineEnd: function() {
14668  this._curve.lineEnd();
14669  },
14670  point: function(a, r) {
14671  this._curve.point(r * Math.sin(a), r * -Math.cos(a));
14672  }
14673 };
14674 
14675 function curveRadial(curve) {
14676 
14677  function radial(context) {
14678  return new Radial(curve(context));
14679  }
14680 
14681  radial._curve = curve;
14682 
14683  return radial;
14684 }
14685 
14686 function lineRadial(l) {
14687  var c = l.curve;
14688 
14689  l.angle = l.x, delete l.x;
14690  l.radius = l.y, delete l.y;
14691 
14692  l.curve = function(_) {
14693  return arguments.length ? c(curveRadial(_)) : c()._curve;
14694  };
14695 
14696  return l;
14697 }
14698 
14699 function lineRadial$1() {
14700  return lineRadial(line().curve(curveRadialLinear));
14701 }
14702 
14703 function areaRadial() {
14704  var a = area$3().curve(curveRadialLinear),
14705  c = a.curve,
14706  x0 = a.lineX0,
14707  x1 = a.lineX1,
14708  y0 = a.lineY0,
14709  y1 = a.lineY1;
14710 
14711  a.angle = a.x, delete a.x;
14712  a.startAngle = a.x0, delete a.x0;
14713  a.endAngle = a.x1, delete a.x1;
14714  a.radius = a.y, delete a.y;
14715  a.innerRadius = a.y0, delete a.y0;
14716  a.outerRadius = a.y1, delete a.y1;
14717  a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
14718  a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
14719  a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
14720  a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
14721 
14722  a.curve = function(_) {
14723  return arguments.length ? c(curveRadial(_)) : c()._curve;
14724  };
14725 
14726  return a;
14727 }
14728 
14729 function pointRadial(x, y) {
14730  return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
14731 }
14732 
14733 var slice$6 = Array.prototype.slice;
14734 
14735 function linkSource(d) {
14736  return d.source;
14737 }
14738 
14739 function linkTarget(d) {
14740  return d.target;
14741 }
14742 
14743 function link$2(curve) {
14744  var source = linkSource,
14745  target = linkTarget,
14746  x$$1 = x$3,
14747  y$$1 = y$3,
14748  context = null;
14749 
14750  function link() {
14751  var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
14752  if (!context) context = buffer = path();
14753  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));
14754  if (buffer) return context = null, buffer + "" || null;
14755  }
14756 
14757  link.source = function(_) {
14758  return arguments.length ? (source = _, link) : source;
14759  };
14760 
14761  link.target = function(_) {
14762  return arguments.length ? (target = _, link) : target;
14763  };
14764 
14765  link.x = function(_) {
14766  return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$b(+_), link) : x$$1;
14767  };
14768 
14769  link.y = function(_) {
14770  return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$b(+_), link) : y$$1;
14771  };
14772 
14773  link.context = function(_) {
14774  return arguments.length ? ((context = _ == null ? null : _), link) : context;
14775  };
14776 
14777  return link;
14778 }
14779 
14780 function curveHorizontal(context, x0, y0, x1, y1) {
14781  context.moveTo(x0, y0);
14782  context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
14783 }
14784 
14785 function curveVertical(context, x0, y0, x1, y1) {
14786  context.moveTo(x0, y0);
14787  context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
14788 }
14789 
14790 function curveRadial$1(context, x0, y0, x1, y1) {
14791  var p0 = pointRadial(x0, y0),
14792  p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
14793  p2 = pointRadial(x1, y0),
14794  p3 = pointRadial(x1, y1);
14795  context.moveTo(p0[0], p0[1]);
14796  context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
14797 }
14798 
14799 function linkHorizontal() {
14800  return link$2(curveHorizontal);
14801 }
14802 
14803 function linkVertical() {
14804  return link$2(curveVertical);
14805 }
14806 
14807 function linkRadial() {
14808  var l = link$2(curveRadial$1);
14809  l.angle = l.x, delete l.x;
14810  l.radius = l.y, delete l.y;
14811  return l;
14812 }
14813 
14814 var circle$2 = {
14815  draw: function(context, size) {
14816  var r = Math.sqrt(size / pi$4);
14817  context.moveTo(r, 0);
14818  context.arc(0, 0, r, 0, tau$4);
14819  }
14820 };
14821 
14822 var cross$2 = {
14823  draw: function(context, size) {
14824  var r = Math.sqrt(size / 5) / 2;
14825  context.moveTo(-3 * r, -r);
14826  context.lineTo(-r, -r);
14827  context.lineTo(-r, -3 * r);
14828  context.lineTo(r, -3 * r);
14829  context.lineTo(r, -r);
14830  context.lineTo(3 * r, -r);
14831  context.lineTo(3 * r, r);
14832  context.lineTo(r, r);
14833  context.lineTo(r, 3 * r);
14834  context.lineTo(-r, 3 * r);
14835  context.lineTo(-r, r);
14836  context.lineTo(-3 * r, r);
14837  context.closePath();
14838  }
14839 };
14840 
14841 var tan30 = Math.sqrt(1 / 3),
14842  tan30_2 = tan30 * 2;
14843 
14844 var diamond = {
14845  draw: function(context, size) {
14846  var y = Math.sqrt(size / tan30_2),
14847  x = y * tan30;
14848  context.moveTo(0, -y);
14849  context.lineTo(x, 0);
14850  context.lineTo(0, y);
14851  context.lineTo(-x, 0);
14852  context.closePath();
14853  }
14854 };
14855 
14856 var ka = 0.89081309152928522810,
14857  kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
14858  kx = Math.sin(tau$4 / 10) * kr,
14859  ky = -Math.cos(tau$4 / 10) * kr;
14860 
14861 var star = {
14862  draw: function(context, size) {
14863  var r = Math.sqrt(size * ka),
14864  x = kx * r,
14865  y = ky * r;
14866  context.moveTo(0, -r);
14867  context.lineTo(x, y);
14868  for (var i = 1; i < 5; ++i) {
14869  var a = tau$4 * i / 5,
14870  c = Math.cos(a),
14871  s = Math.sin(a);
14872  context.lineTo(s * r, -c * r);
14873  context.lineTo(c * x - s * y, s * x + c * y);
14874  }
14875  context.closePath();
14876  }
14877 };
14878 
14879 var square = {
14880  draw: function(context, size) {
14881  var w = Math.sqrt(size),
14882  x = -w / 2;
14883  context.rect(x, x, w, w);
14884  }
14885 };
14886 
14887 var sqrt3 = Math.sqrt(3);
14888 
14889 var triangle = {
14890  draw: function(context, size) {
14891  var y = -Math.sqrt(size / (sqrt3 * 3));
14892  context.moveTo(0, y * 2);
14893  context.lineTo(-sqrt3 * y, -y);
14894  context.lineTo(sqrt3 * y, -y);
14895  context.closePath();
14896  }
14897 };
14898 
14899 var c$2 = -0.5,
14900  s = Math.sqrt(3) / 2,
14901  k = 1 / Math.sqrt(12),
14902  a = (k / 2 + 1) * 3;
14903 
14904 var wye = {
14905  draw: function(context, size) {
14906  var r = Math.sqrt(size / a),
14907  x0 = r / 2,
14908  y0 = r * k,
14909  x1 = x0,
14910  y1 = r * k + r,
14911  x2 = -x1,
14912  y2 = y1;
14913  context.moveTo(x0, y0);
14914  context.lineTo(x1, y1);
14915  context.lineTo(x2, y2);
14916  context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
14917  context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
14918  context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
14919  context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
14920  context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
14921  context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
14922  context.closePath();
14923  }
14924 };
14925 
14926 var symbols = [
14927  circle$2,
14928  cross$2,
14929  diamond,
14930  square,
14931  star,
14932  triangle,
14933  wye
14934 ];
14935 
14936 function symbol() {
14937  var type = constant$b(circle$2),
14938  size = constant$b(64),
14939  context = null;
14940 
14941  function symbol() {
14942  var buffer;
14943  if (!context) context = buffer = path();
14944  type.apply(this, arguments).draw(context, +size.apply(this, arguments));
14945  if (buffer) return context = null, buffer + "" || null;
14946  }
14947 
14948  symbol.type = function(_) {
14949  return arguments.length ? (type = typeof _ === "function" ? _ : constant$b(_), symbol) : type;
14950  };
14951 
14952  symbol.size = function(_) {
14953  return arguments.length ? (size = typeof _ === "function" ? _ : constant$b(+_), symbol) : size;
14954  };
14955 
14956  symbol.context = function(_) {
14957  return arguments.length ? (context = _ == null ? null : _, symbol) : context;
14958  };
14959 
14960  return symbol;
14961 }
14962 
14963 function noop$3() {}
14964 
14965 function point$2(that, x, y) {
14966  that._context.bezierCurveTo(
14967  (2 * that._x0 + that._x1) / 3,
14968  (2 * that._y0 + that._y1) / 3,
14969  (that._x0 + 2 * that._x1) / 3,
14970  (that._y0 + 2 * that._y1) / 3,
14971  (that._x0 + 4 * that._x1 + x) / 6,
14972  (that._y0 + 4 * that._y1 + y) / 6
14973  );
14974 }
14975 
14976 function Basis(context) {
14977  this._context = context;
14978 }
14979 
14980 Basis.prototype = {
14981  areaStart: function() {
14982  this._line = 0;
14983  },
14984  areaEnd: function() {
14985  this._line = NaN;
14986  },
14987  lineStart: function() {
14988  this._x0 = this._x1 =
14989  this._y0 = this._y1 = NaN;
14990  this._point = 0;
14991  },
14992  lineEnd: function() {
14993  switch (this._point) {
14994  case 3: point$2(this, this._x1, this._y1); // proceed
14995  case 2: this._context.lineTo(this._x1, this._y1); break;
14996  }
14997  if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
14998  this._line = 1 - this._line;
14999  },
15000  point: function(x, y) {
15001  x = +x, y = +y;
15002  switch (this._point) {
15003  case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15004  case 1: this._point = 2; break;
15005  case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
15006  default: point$2(this, x, y); break;
15007  }
15008  this._x0 = this._x1, this._x1 = x;
15009  this._y0 = this._y1, this._y1 = y;
15010  }
15011 };
15012 
15013 function basis$2(context) {
15014  return new Basis(context);
15015 }
15016 
15017 function BasisClosed(context) {
15018  this._context = context;
15019 }
15020 
15021 BasisClosed.prototype = {
15022  areaStart: noop$3,
15023  areaEnd: noop$3,
15024  lineStart: function() {
15025  this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
15026  this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
15027  this._point = 0;
15028  },
15029  lineEnd: function() {
15030  switch (this._point) {
15031  case 1: {
15032  this._context.moveTo(this._x2, this._y2);
15033  this._context.closePath();
15034  break;
15035  }
15036  case 2: {
15037  this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
15038  this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
15039  this._context.closePath();
15040  break;
15041  }
15042  case 3: {
15043  this.point(this._x2, this._y2);
15044  this.point(this._x3, this._y3);
15045  this.point(this._x4, this._y4);
15046  break;
15047  }
15048  }
15049  },
15050  point: function(x, y) {
15051  x = +x, y = +y;
15052  switch (this._point) {
15053  case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
15054  case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
15055  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;
15056  default: point$2(this, x, y); break;
15057  }
15058  this._x0 = this._x1, this._x1 = x;
15059  this._y0 = this._y1, this._y1 = y;
15060  }
15061 };
15062 
15063 function basisClosed$1(context) {
15064  return new BasisClosed(context);
15065 }
15066 
15067 function BasisOpen(context) {
15068  this._context = context;
15069 }
15070 
15071 BasisOpen.prototype = {
15072  areaStart: function() {
15073  this._line = 0;
15074  },
15075  areaEnd: function() {
15076  this._line = NaN;
15077  },
15078  lineStart: function() {
15079  this._x0 = this._x1 =
15080  this._y0 = this._y1 = NaN;
15081  this._point = 0;
15082  },
15083  lineEnd: function() {
15084  if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15085  this._line = 1 - this._line;
15086  },
15087  point: function(x, y) {
15088  x = +x, y = +y;
15089  switch (this._point) {
15090  case 0: this._point = 1; break;
15091  case 1: this._point = 2; break;
15092  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;
15093  case 3: this._point = 4; // proceed
15094  default: point$2(this, x, y); break;
15095  }
15096  this._x0 = this._x1, this._x1 = x;
15097  this._y0 = this._y1, this._y1 = y;
15098  }
15099 };
15100 
15101 function basisOpen(context) {
15102  return new BasisOpen(context);
15103 }
15104 
15105 function Bundle(context, beta) {
15106  this._basis = new Basis(context);
15107  this._beta = beta;
15108 }
15109 
15110 Bundle.prototype = {
15111  lineStart: function() {
15112  this._x = [];
15113  this._y = [];
15114  this._basis.lineStart();
15115  },
15116  lineEnd: function() {
15117  var x = this._x,
15118  y = this._y,
15119  j = x.length - 1;
15120 
15121  if (j > 0) {
15122  var x0 = x[0],
15123  y0 = y[0],
15124  dx = x[j] - x0,
15125  dy = y[j] - y0,
15126  i = -1,
15127  t;
15128 
15129  while (++i <= j) {
15130  t = i / j;
15131  this._basis.point(
15132  this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
15133  this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
15134  );
15135  }
15136  }
15137 
15138  this._x = this._y = null;
15139  this._basis.lineEnd();
15140  },
15141  point: function(x, y) {
15142  this._x.push(+x);
15143  this._y.push(+y);
15144  }
15145 };
15146 
15147 var bundle = (function custom(beta) {
15148 
15149  function bundle(context) {
15150  return beta === 1 ? new Basis(context) : new Bundle(context, beta);
15151  }
15152 
15153  bundle.beta = function(beta) {
15154  return custom(+beta);
15155  };
15156 
15157  return bundle;
15158 })(0.85);
15159 
15160 function point$3(that, x, y) {
15161  that._context.bezierCurveTo(
15162  that._x1 + that._k * (that._x2 - that._x0),
15163  that._y1 + that._k * (that._y2 - that._y0),
15164  that._x2 + that._k * (that._x1 - x),
15165  that._y2 + that._k * (that._y1 - y),
15166  that._x2,
15167  that._y2
15168  );
15169 }
15170 
15171 function Cardinal(context, tension) {
15172  this._context = context;
15173  this._k = (1 - tension) / 6;
15174 }
15175 
15176 Cardinal.prototype = {
15177  areaStart: function() {
15178  this._line = 0;
15179  },
15180  areaEnd: function() {
15181  this._line = NaN;
15182  },
15183  lineStart: function() {
15184  this._x0 = this._x1 = this._x2 =
15185  this._y0 = this._y1 = this._y2 = NaN;
15186  this._point = 0;
15187  },
15188  lineEnd: function() {
15189  switch (this._point) {
15190  case 2: this._context.lineTo(this._x2, this._y2); break;
15191  case 3: point$3(this, this._x1, this._y1); break;
15192  }
15193  if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15194  this._line = 1 - this._line;
15195  },
15196  point: function(x, y) {
15197  x = +x, y = +y;
15198  switch (this._point) {
15199  case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15200  case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
15201  case 2: this._point = 3; // proceed
15202  default: point$3(this, x, y); break;
15203  }
15204  this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15205  this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15206  }
15207 };
15208 
15209 var cardinal = (function custom(tension) {
15210 
15211  function cardinal(context) {
15212  return new Cardinal(context, tension);
15213  }
15214 
15215  cardinal.tension = function(tension) {
15216  return custom(+tension);
15217  };
15218 
15219  return cardinal;
15220 })(0);
15221 
15222 function CardinalClosed(context, tension) {
15223  this._context = context;
15224  this._k = (1 - tension) / 6;
15225 }
15226 
15227 CardinalClosed.prototype = {
15228  areaStart: noop$3,
15229  areaEnd: noop$3,
15230  lineStart: function() {
15231  this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
15232  this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
15233  this._point = 0;
15234  },
15235  lineEnd: function() {
15236  switch (this._point) {
15237  case 1: {
15238  this._context.moveTo(this._x3, this._y3);
15239  this._context.closePath();
15240  break;
15241  }
15242  case 2: {
15243  this._context.lineTo(this._x3, this._y3);
15244  this._context.closePath();
15245  break;
15246  }
15247  case 3: {
15248  this.point(this._x3, this._y3);
15249  this.point(this._x4, this._y4);
15250  this.point(this._x5, this._y5);
15251  break;
15252  }
15253  }
15254  },
15255  point: function(x, y) {
15256  x = +x, y = +y;
15257  switch (this._point) {
15258  case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
15259  case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
15260  case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
15261  default: point$3(this, x, y); break;
15262  }
15263  this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15264  this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15265  }
15266 };
15267 
15268 var cardinalClosed = (function custom(tension) {
15269 
15270  function cardinal$$1(context) {
15271  return new CardinalClosed(context, tension);
15272  }
15273 
15274  cardinal$$1.tension = function(tension) {
15275  return custom(+tension);
15276  };
15277 
15278  return cardinal$$1;
15279 })(0);
15280 
15281 function CardinalOpen(context, tension) {
15282  this._context = context;
15283  this._k = (1 - tension) / 6;
15284 }
15285 
15286 CardinalOpen.prototype = {
15287  areaStart: function() {
15288  this._line = 0;
15289  },
15290  areaEnd: function() {
15291  this._line = NaN;
15292  },
15293  lineStart: function() {
15294  this._x0 = this._x1 = this._x2 =
15295  this._y0 = this._y1 = this._y2 = NaN;
15296  this._point = 0;
15297  },
15298  lineEnd: function() {
15299  if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15300  this._line = 1 - this._line;
15301  },
15302  point: function(x, y) {
15303  x = +x, y = +y;
15304  switch (this._point) {
15305  case 0: this._point = 1; break;
15306  case 1: this._point = 2; break;
15307  case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
15308  case 3: this._point = 4; // proceed
15309  default: point$3(this, x, y); break;
15310  }
15311  this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15312  this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15313  }
15314 };
15315 
15316 var cardinalOpen = (function custom(tension) {
15317 
15318  function cardinal$$1(context) {
15319  return new CardinalOpen(context, tension);
15320  }
15321 
15322  cardinal$$1.tension = function(tension) {
15323  return custom(+tension);
15324  };
15325 
15326  return cardinal$$1;
15327 })(0);
15328 
15329 function point$4(that, x, y) {
15330  var x1 = that._x1,
15331  y1 = that._y1,
15332  x2 = that._x2,
15333  y2 = that._y2;
15334 
15335  if (that._l01_a > epsilon$3) {
15336  var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
15337  n = 3 * that._l01_a * (that._l01_a + that._l12_a);
15338  x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
15339  y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
15340  }
15341 
15342  if (that._l23_a > epsilon$3) {
15343  var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
15344  m = 3 * that._l23_a * (that._l23_a + that._l12_a);
15345  x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
15346  y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
15347  }
15348 
15349  that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
15350 }
15351 
15352 function CatmullRom(context, alpha) {
15353  this._context = context;
15354  this._alpha = alpha;
15355 }
15356 
15357 CatmullRom.prototype = {
15358  areaStart: function() {
15359  this._line = 0;
15360  },
15361  areaEnd: function() {
15362  this._line = NaN;
15363  },
15364  lineStart: function() {
15365  this._x0 = this._x1 = this._x2 =
15366  this._y0 = this._y1 = this._y2 = NaN;
15367  this._l01_a = this._l12_a = this._l23_a =
15368  this._l01_2a = this._l12_2a = this._l23_2a =
15369  this._point = 0;
15370  },
15371  lineEnd: function() {
15372  switch (this._point) {
15373  case 2: this._context.lineTo(this._x2, this._y2); break;
15374  case 3: this.point(this._x2, this._y2); break;
15375  }
15376  if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15377  this._line = 1 - this._line;
15378  },
15379  point: function(x, y) {
15380  x = +x, y = +y;
15381 
15382  if (this._point) {
15383  var x23 = this._x2 - x,
15384  y23 = this._y2 - y;
15385  this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15386  }
15387 
15388  switch (this._point) {
15389  case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15390  case 1: this._point = 2; break;
15391  case 2: this._point = 3; // proceed
15392  default: point$4(this, x, y); break;
15393  }
15394 
15395  this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15396  this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15397  this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15398  this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15399  }
15400 };
15401 
15402 var catmullRom = (function custom(alpha) {
15403 
15404  function catmullRom(context) {
15405  return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
15406  }
15407 
15408  catmullRom.alpha = function(alpha) {
15409  return custom(+alpha);
15410  };
15411 
15412  return catmullRom;
15413 })(0.5);
15414 
15415 function CatmullRomClosed(context, alpha) {
15416  this._context = context;
15417  this._alpha = alpha;
15418 }
15419 
15420 CatmullRomClosed.prototype = {
15421  areaStart: noop$3,
15422  areaEnd: noop$3,
15423  lineStart: function() {
15424  this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
15425  this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
15426  this._l01_a = this._l12_a = this._l23_a =
15427  this._l01_2a = this._l12_2a = this._l23_2a =
15428  this._point = 0;
15429  },
15430  lineEnd: function() {
15431  switch (this._point) {
15432  case 1: {
15433  this._context.moveTo(this._x3, this._y3);
15434  this._context.closePath();
15435  break;
15436  }
15437  case 2: {
15438  this._context.lineTo(this._x3, this._y3);
15439  this._context.closePath();
15440  break;
15441  }
15442  case 3: {
15443  this.point(this._x3, this._y3);
15444  this.point(this._x4, this._y4);
15445  this.point(this._x5, this._y5);
15446  break;
15447  }
15448  }
15449  },
15450  point: function(x, y) {
15451  x = +x, y = +y;
15452 
15453  if (this._point) {
15454  var x23 = this._x2 - x,
15455  y23 = this._y2 - y;
15456  this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15457  }
15458 
15459  switch (this._point) {
15460  case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
15461  case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
15462  case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
15463  default: point$4(this, x, y); break;
15464  }
15465 
15466  this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15467  this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15468  this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15469  this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15470  }
15471 };
15472 
15473 var catmullRomClosed = (function custom(alpha) {
15474 
15475  function catmullRom$$1(context) {
15476  return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
15477  }
15478 
15479  catmullRom$$1.alpha = function(alpha) {
15480  return custom(+alpha);
15481  };
15482 
15483  return catmullRom$$1;
15484 })(0.5);
15485 
15486 function CatmullRomOpen(context, alpha) {
15487  this._context = context;
15488  this._alpha = alpha;
15489 }
15490 
15491 CatmullRomOpen.prototype = {
15492  areaStart: function() {
15493  this._line = 0;
15494  },
15495  areaEnd: function() {
15496  this._line = NaN;
15497  },
15498  lineStart: function() {
15499  this._x0 = this._x1 = this._x2 =
15500  this._y0 = this._y1 = this._y2 = NaN;
15501  this._l01_a = this._l12_a = this._l23_a =
15502  this._l01_2a = this._l12_2a = this._l23_2a =
15503  this._point = 0;
15504  },
15505  lineEnd: function() {
15506  if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
15507  this._line = 1 - this._line;
15508  },
15509  point: function(x, y) {
15510  x = +x, y = +y;
15511 
15512  if (this._point) {
15513  var x23 = this._x2 - x,
15514  y23 = this._y2 - y;
15515  this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
15516  }
15517 
15518  switch (this._point) {
15519  case 0: this._point = 1; break;
15520  case 1: this._point = 2; break;
15521  case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
15522  case 3: this._point = 4; // proceed
15523  default: point$4(this, x, y); break;
15524  }
15525 
15526  this._l01_a = this._l12_a, this._l12_a = this._l23_a;
15527  this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
15528  this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
15529  this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
15530  }
15531 };
15532 
15533 var catmullRomOpen = (function custom(alpha) {
15534 
15535  function catmullRom$$1(context) {
15536  return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
15537  }
15538 
15539  catmullRom$$1.alpha = function(alpha) {
15540  return custom(+alpha);
15541  };
15542 
15543  return catmullRom$$1;
15544 })(0.5);
15545 
15546 function LinearClosed(context) {
15547  this._context = context;
15548 }
15549 
15550 LinearClosed.prototype = {
15551  areaStart: noop$3,
15552  areaEnd: noop$3,
15553  lineStart: function() {
15554  this._point = 0;
15555  },
15556  lineEnd: function() {
15557  if (this._point) this._context.closePath();
15558  },
15559  point: function(x, y) {
15560  x = +x, y = +y;
15561  if (this._point) this._context.lineTo(x, y);
15562  else this._point = 1, this._context.moveTo(x, y);
15563  }
15564 };
15565 
15566 function linearClosed(context) {
15567  return new LinearClosed(context);
15568 }
15569 
15570 function sign$1(x) {
15571  return x < 0 ? -1 : 1;
15572 }
15573 
15574 // Calculate the slopes of the tangents (Hermite-type interpolation) based on
15575 // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
15576 // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
15577 // NOV(II), P. 443, 1990.
15578 function slope3(that, x2, y2) {
15579  var h0 = that._x1 - that._x0,
15580  h1 = x2 - that._x1,
15581  s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
15582  s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
15583  p = (s0 * h1 + s1 * h0) / (h0 + h1);
15584  return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
15585 }
15586 
15587 // Calculate a one-sided slope.
15588 function slope2(that, t) {
15589  var h = that._x1 - that._x0;
15590  return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
15591 }
15592 
15593 // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
15594 // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
15595 // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
15596 function point$5(that, t0, t1) {
15597  var x0 = that._x0,
15598  y0 = that._y0,
15599  x1 = that._x1,
15600  y1 = that._y1,
15601  dx = (x1 - x0) / 3;
15602  that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
15603 }
15604 
15605 function MonotoneX(context) {
15606  this._context = context;
15607 }
15608 
15609 MonotoneX.prototype = {
15610  areaStart: function() {
15611  this._line = 0;
15612  },
15613  areaEnd: function() {
15614  this._line = NaN;
15615  },
15616  lineStart: function() {
15617  this._x0 = this._x1 =
15618  this._y0 = this._y1 =
15619  this._t0 = NaN;
15620  this._point = 0;
15621  },
15622  lineEnd: function() {
15623  switch (this._point) {
15624  case 2: this._context.lineTo(this._x1, this._y1); break;
15625  case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
15626  }
15627  if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15628  this._line = 1 - this._line;
15629  },
15630  point: function(x, y) {
15631  var t1 = NaN;
15632 
15633  x = +x, y = +y;
15634  if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
15635  switch (this._point) {
15636  case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15637  case 1: this._point = 2; break;
15638  case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
15639  default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
15640  }
15641 
15642  this._x0 = this._x1, this._x1 = x;
15643  this._y0 = this._y1, this._y1 = y;
15644  this._t0 = t1;
15645  }
15646 };
15647 
15648 function MonotoneY(context) {
15649  this._context = new ReflectContext(context);
15650 }
15651 
15652 (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
15653  MonotoneX.prototype.point.call(this, y, x);
15654 };
15655 
15656 function ReflectContext(context) {
15657  this._context = context;
15658 }
15659 
15660 ReflectContext.prototype = {
15661  moveTo: function(x, y) { this._context.moveTo(y, x); },
15662  closePath: function() { this._context.closePath(); },
15663  lineTo: function(x, y) { this._context.lineTo(y, x); },
15664  bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
15665 };
15666 
15667 function monotoneX(context) {
15668  return new MonotoneX(context);
15669 }
15670 
15671 function monotoneY(context) {
15672  return new MonotoneY(context);
15673 }
15674 
15675 function Natural(context) {
15676  this._context = context;
15677 }
15678 
15679 Natural.prototype = {
15680  areaStart: function() {
15681  this._line = 0;
15682  },
15683  areaEnd: function() {
15684  this._line = NaN;
15685  },
15686  lineStart: function() {
15687  this._x = [];
15688  this._y = [];
15689  },
15690  lineEnd: function() {
15691  var x = this._x,
15692  y = this._y,
15693  n = x.length;
15694 
15695  if (n) {
15696  this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
15697  if (n === 2) {
15698  this._context.lineTo(x[1], y[1]);
15699  } else {
15700  var px = controlPoints(x),
15701  py = controlPoints(y);
15702  for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
15703  this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
15704  }
15705  }
15706  }
15707 
15708  if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
15709  this._line = 1 - this._line;
15710  this._x = this._y = null;
15711  },
15712  point: function(x, y) {
15713  this._x.push(+x);
15714  this._y.push(+y);
15715  }
15716 };
15717 
15718 // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
15719 function controlPoints(x) {
15720  var i,
15721  n = x.length - 1,
15722  m,
15723  a = new Array(n),
15724  b = new Array(n),
15725  r = new Array(n);
15726  a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
15727  for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
15728  a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
15729  for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
15730  a[n - 1] = r[n - 1] / b[n - 1];
15731  for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
15732  b[n - 1] = (x[n] + a[n - 1]) / 2;
15733  for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
15734  return [a, b];
15735 }
15736 
15737 function natural(context) {
15738  return new Natural(context);
15739 }
15740 
15741 function Step(context, t) {
15742  this._context = context;
15743  this._t = t;
15744 }
15745 
15746 Step.prototype = {
15747  areaStart: function() {
15748  this._line = 0;
15749  },
15750  areaEnd: function() {
15751  this._line = NaN;
15752  },
15753  lineStart: function() {
15754  this._x = this._y = NaN;
15755  this._point = 0;
15756  },
15757  lineEnd: function() {
15758  if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
15759  if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
15760  if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
15761  },
15762  point: function(x, y) {
15763  x = +x, y = +y;
15764  switch (this._point) {
15765  case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
15766  case 1: this._point = 2; // proceed
15767  default: {
15768  if (this._t <= 0) {
15769  this._context.lineTo(this._x, y);
15770  this._context.lineTo(x, y);
15771  } else {
15772  var x1 = this._x * (1 - this._t) + x * this._t;
15773  this._context.lineTo(x1, this._y);
15774  this._context.lineTo(x1, y);
15775  }
15776  break;
15777  }
15778  }
15779  this._x = x, this._y = y;
15780  }
15781 };
15782 
15783 function step(context) {
15784  return new Step(context, 0.5);
15785 }
15786 
15787 function stepBefore(context) {
15788  return new Step(context, 0);
15789 }
15790 
15791 function stepAfter(context) {
15792  return new Step(context, 1);
15793 }
15794 
15795 function none$1(series, order) {
15796  if (!((n = series.length) > 1)) return;
15797  for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
15798  s0 = s1, s1 = series[order[i]];
15799  for (j = 0; j < m; ++j) {
15800  s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
15801  }
15802  }
15803 }
15804 
15805 function none$2(series) {
15806  var n = series.length, o = new Array(n);
15807  while (--n >= 0) o[n] = n;
15808  return o;
15809 }
15810 
15811 function stackValue(d, key) {
15812  return d[key];
15813 }
15814 
15815 function stack() {
15816  var keys = constant$b([]),
15817  order = none$2,
15818  offset = none$1,
15819  value = stackValue;
15820 
15821  function stack(data) {
15822  var kz = keys.apply(this, arguments),
15823  i,
15824  m = data.length,
15825  n = kz.length,
15826  sz = new Array(n),
15827  oz;
15828 
15829  for (i = 0; i < n; ++i) {
15830  for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
15831  si[j] = sij = [0, +value(data[j], ki, j, data)];
15832  sij.data = data[j];
15833  }
15834  si.key = ki;
15835  }
15836 
15837  for (i = 0, oz = order(sz); i < n; ++i) {
15838  sz[oz[i]].index = i;
15839  }
15840 
15841  offset(sz, oz);
15842  return sz;
15843  }
15844 
15845  stack.keys = function(_) {
15846  return arguments.length ? (keys = typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : keys;
15847  };
15848 
15849  stack.value = function(_) {
15850  return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), stack) : value;
15851  };
15852 
15853  stack.order = function(_) {
15854  return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : order;
15855  };
15856 
15857  stack.offset = function(_) {
15858  return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
15859  };
15860 
15861  return stack;
15862 }
15863 
15864 function expand(series, order) {
15865  if (!((n = series.length) > 0)) return;
15866  for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
15867  for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
15868  if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
15869  }
15870  none$1(series, order);
15871 }
15872 
15873 function diverging$1(series, order) {
15874  if (!((n = series.length) > 1)) return;
15875  for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
15876  for (yp = yn = 0, i = 0; i < n; ++i) {
15877  if ((dy = (d = series[order[i]][j])[1] - d[0]) >= 0) {
15878  d[0] = yp, d[1] = yp += dy;
15879  } else if (dy < 0) {
15880  d[1] = yn, d[0] = yn += dy;
15881  } else {
15882  d[0] = yp;
15883  }
15884  }
15885  }
15886 }
15887 
15888 function silhouette(series, order) {
15889  if (!((n = series.length) > 0)) return;
15890  for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
15891  for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
15892  s0[j][1] += s0[j][0] = -y / 2;
15893  }
15894  none$1(series, order);
15895 }
15896 
15897 function wiggle(series, order) {
15898  if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
15899  for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
15900  for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
15901  var si = series[order[i]],
15902  sij0 = si[j][1] || 0,
15903  sij1 = si[j - 1][1] || 0,
15904  s3 = (sij0 - sij1) / 2;
15905  for (var k = 0; k < i; ++k) {
15906  var sk = series[order[k]],
15907  skj0 = sk[j][1] || 0,
15908  skj1 = sk[j - 1][1] || 0;
15909  s3 += skj0 - skj1;
15910  }
15911  s1 += sij0, s2 += s3 * sij0;
15912  }
15913  s0[j - 1][1] += s0[j - 1][0] = y;
15914  if (s1) y -= s2 / s1;
15915  }
15916  s0[j - 1][1] += s0[j - 1][0] = y;
15917  none$1(series, order);
15918 }
15919 
15920 function ascending$3(series) {
15921  var sums = series.map(sum$2);
15922  return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
15923 }
15924 
15925 function sum$2(series) {
15926  var s = 0, i = -1, n = series.length, v;
15927  while (++i < n) if (v = +series[i][1]) s += v;
15928  return s;
15929 }
15930 
15931 function descending$2(series) {
15932  return ascending$3(series).reverse();
15933 }
15934 
15935 function insideOut(series) {
15936  var n = series.length,
15937  i,
15938  j,
15939  sums = series.map(sum$2),
15940  order = none$2(series).sort(function(a, b) { return sums[b] - sums[a]; }),
15941  top = 0,
15942  bottom = 0,
15943  tops = [],
15944  bottoms = [];
15945 
15946  for (i = 0; i < n; ++i) {
15947  j = order[i];
15948  if (top < bottom) {
15949  top += sums[j];
15950  tops.push(j);
15951  } else {
15952  bottom += sums[j];
15953  bottoms.push(j);
15954  }
15955  }
15956 
15957  return bottoms.reverse().concat(tops);
15958 }
15959 
15960 function reverse(series) {
15961  return none$2(series).reverse();
15962 }
15963 
15964 function constant$c(x) {
15965  return function() {
15966  return x;
15967  };
15968 }
15969 
15970 function x$4(d) {
15971  return d[0];
15972 }
15973 
15974 function y$4(d) {
15975  return d[1];
15976 }
15977 
15978 function RedBlackTree() {
15979  this._ = null; // root node
15980 }
15981 
15982 function RedBlackNode(node) {
15983  node.U = // parent node
15984  node.C = // color - true for red, false for black
15985  node.L = // left node
15986  node.R = // right node
15987  node.P = // previous node
15988  node.N = null; // next node
15989 }
15990 
15991 RedBlackTree.prototype = {
15992  constructor: RedBlackTree,
15993 
15994  insert: function(after, node) {
15995  var parent, grandpa, uncle;
15996 
15997  if (after) {
15998  node.P = after;
15999  node.N = after.N;
16000  if (after.N) after.N.P = node;
16001  after.N = node;
16002  if (after.R) {
16003  after = after.R;
16004  while (after.L) after = after.L;
16005  after.L = node;
16006  } else {
16007  after.R = node;
16008  }
16009  parent = after;
16010  } else if (this._) {
16011  after = RedBlackFirst(this._);
16012  node.P = null;
16013  node.N = after;
16014  after.P = after.L = node;
16015  parent = after;
16016  } else {
16017  node.P = node.N = null;
16018  this._ = node;
16019  parent = null;
16020  }
16021  node.L = node.R = null;
16022  node.U = parent;
16023  node.C = true;
16024 
16025  after = node;
16026  while (parent && parent.C) {
16027  grandpa = parent.U;
16028  if (parent === grandpa.L) {
16029  uncle = grandpa.R;
16030  if (uncle && uncle.C) {
16031  parent.C = uncle.C = false;
16032  grandpa.C = true;
16033  after = grandpa;
16034  } else {
16035  if (after === parent.R) {
16036  RedBlackRotateLeft(this, parent);
16037  after = parent;
16038  parent = after.U;
16039  }
16040  parent.C = false;
16041  grandpa.C = true;
16042  RedBlackRotateRight(this, grandpa);
16043  }
16044  } else {
16045  uncle = grandpa.L;
16046  if (uncle && uncle.C) {
16047  parent.C = uncle.C = false;
16048  grandpa.C = true;
16049  after = grandpa;
16050  } else {
16051  if (after === parent.L) {
16052  RedBlackRotateRight(this, parent);
16053  after = parent;
16054  parent = after.U;
16055  }
16056  parent.C = false;
16057  grandpa.C = true;
16058  RedBlackRotateLeft(this, grandpa);
16059  }
16060  }
16061  parent = after.U;
16062  }
16063  this._.C = false;
16064  },
16065 
16066  remove: function(node) {
16067  if (node.N) node.N.P = node.P;
16068  if (node.P) node.P.N = node.N;
16069  node.N = node.P = null;
16070 
16071  var parent = node.U,
16072  sibling,
16073  left = node.L,
16074  right = node.R,
16075  next,
16076  red;
16077 
16078  if (!left) next = right;
16079  else if (!right) next = left;
16080  else next = RedBlackFirst(right);
16081 
16082  if (parent) {
16083  if (parent.L === node) parent.L = next;
16084  else parent.R = next;
16085  } else {
16086  this._ = next;
16087  }
16088 
16089  if (left && right) {
16090  red = next.C;
16091  next.C = node.C;
16092  next.L = left;
16093  left.U = next;
16094  if (next !== right) {
16095  parent = next.U;
16096  next.U = node.U;
16097  node = next.R;
16098  parent.L = node;
16099  next.R = right;
16100  right.U = next;
16101  } else {
16102  next.U = parent;
16103  parent = next;
16104  node = next.R;
16105  }
16106  } else {
16107  red = node.C;
16108  node = next;
16109  }
16110 
16111  if (node) node.U = parent;
16112  if (red) return;
16113  if (node && node.C) { node.C = false; return; }
16114 
16115  do {
16116  if (node === this._) break;
16117  if (node === parent.L) {
16118  sibling = parent.R;
16119  if (sibling.C) {
16120  sibling.C = false;
16121  parent.C = true;
16122  RedBlackRotateLeft(this, parent);
16123  sibling = parent.R;
16124  }
16125  if ((sibling.L && sibling.L.C)
16126  || (sibling.R && sibling.R.C)) {
16127  if (!sibling.R || !sibling.R.C) {
16128  sibling.L.C = false;
16129  sibling.C = true;
16130  RedBlackRotateRight(this, sibling);
16131  sibling = parent.R;
16132  }
16133  sibling.C = parent.C;
16134  parent.C = sibling.R.C = false;
16135  RedBlackRotateLeft(this, parent);
16136  node = this._;
16137  break;
16138  }
16139  } else {
16140  sibling = parent.L;
16141  if (sibling.C) {
16142  sibling.C = false;
16143  parent.C = true;
16144  RedBlackRotateRight(this, parent);
16145  sibling = parent.L;
16146  }
16147  if ((sibling.L && sibling.L.C)
16148  || (sibling.R && sibling.R.C)) {
16149  if (!sibling.L || !sibling.L.C) {
16150  sibling.R.C = false;
16151  sibling.C = true;
16152  RedBlackRotateLeft(this, sibling);
16153  sibling = parent.L;
16154  }
16155  sibling.C = parent.C;
16156  parent.C = sibling.L.C = false;
16157  RedBlackRotateRight(this, parent);
16158  node = this._;
16159  break;
16160  }
16161  }
16162  sibling.C = true;
16163  node = parent;
16164  parent = parent.U;
16165  } while (!node.C);
16166 
16167  if (node) node.C = false;
16168  }
16169 };
16170 
16171 function RedBlackRotateLeft(tree, node) {
16172  var p = node,
16173  q = node.R,
16174  parent = p.U;
16175 
16176  if (parent) {
16177  if (parent.L === p) parent.L = q;
16178  else parent.R = q;
16179  } else {
16180  tree._ = q;
16181  }
16182 
16183  q.U = parent;
16184  p.U = q;
16185  p.R = q.L;
16186  if (p.R) p.R.U = p;
16187  q.L = p;
16188 }
16189 
16190 function RedBlackRotateRight(tree, node) {
16191  var p = node,
16192  q = node.L,
16193  parent = p.U;
16194 
16195  if (parent) {
16196  if (parent.L === p) parent.L = q;
16197  else parent.R = q;
16198  } else {
16199  tree._ = q;
16200  }
16201 
16202  q.U = parent;
16203  p.U = q;
16204  p.L = q.R;
16205  if (p.L) p.L.U = p;
16206  q.R = p;
16207 }
16208 
16209 function RedBlackFirst(node) {
16210  while (node.L) node = node.L;
16211  return node;
16212 }
16213 
16214 function createEdge(left, right, v0, v1) {
16215  var edge = [null, null],
16216  index = edges.push(edge) - 1;
16217  edge.left = left;
16218  edge.right = right;
16219  if (v0) setEdgeEnd(edge, left, right, v0);
16220  if (v1) setEdgeEnd(edge, right, left, v1);
16221  cells[left.index].halfedges.push(index);
16222  cells[right.index].halfedges.push(index);
16223  return edge;
16224 }
16225 
16226 function createBorderEdge(left, v0, v1) {
16227  var edge = [v0, v1];
16228  edge.left = left;
16229  return edge;
16230 }
16231 
16232 function setEdgeEnd(edge, left, right, vertex) {
16233  if (!edge[0] && !edge[1]) {
16234  edge[0] = vertex;
16235  edge.left = left;
16236  edge.right = right;
16237  } else if (edge.left === right) {
16238  edge[1] = vertex;
16239  } else {
16240  edge[0] = vertex;
16241  }
16242 }
16243 
16244 // Liang–Barsky line clipping.
16245 function clipEdge(edge, x0, y0, x1, y1) {
16246  var a = edge[0],
16247  b = edge[1],
16248  ax = a[0],
16249  ay = a[1],
16250  bx = b[0],
16251  by = b[1],
16252  t0 = 0,
16253  t1 = 1,
16254  dx = bx - ax,
16255  dy = by - ay,
16256  r;
16257 
16258  r = x0 - ax;
16259  if (!dx && r > 0) return;
16260  r /= dx;
16261  if (dx < 0) {
16262  if (r < t0) return;
16263  if (r < t1) t1 = r;
16264  } else if (dx > 0) {
16265  if (r > t1) return;
16266  if (r > t0) t0 = r;
16267  }
16268 
16269  r = x1 - ax;
16270  if (!dx && r < 0) return;
16271  r /= dx;
16272  if (dx < 0) {
16273  if (r > t1) return;
16274  if (r > t0) t0 = r;
16275  } else if (dx > 0) {
16276  if (r < t0) return;
16277  if (r < t1) t1 = r;
16278  }
16279 
16280  r = y0 - ay;
16281  if (!dy && r > 0) return;
16282  r /= dy;
16283  if (dy < 0) {
16284  if (r < t0) return;
16285  if (r < t1) t1 = r;
16286  } else if (dy > 0) {
16287  if (r > t1) return;
16288  if (r > t0) t0 = r;
16289  }
16290 
16291  r = y1 - ay;
16292  if (!dy && r < 0) return;
16293  r /= dy;
16294  if (dy < 0) {
16295  if (r > t1) return;
16296  if (r > t0) t0 = r;
16297  } else if (dy > 0) {
16298  if (r < t0) return;
16299  if (r < t1) t1 = r;
16300  }
16301 
16302  if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
16303 
16304  if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
16305  if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
16306  return true;
16307 }
16308 
16309 function connectEdge(edge, x0, y0, x1, y1) {
16310  var v1 = edge[1];
16311  if (v1) return true;
16312 
16313  var v0 = edge[0],
16314  left = edge.left,
16315  right = edge.right,
16316  lx = left[0],
16317  ly = left[1],
16318  rx = right[0],
16319  ry = right[1],
16320  fx = (lx + rx) / 2,
16321  fy = (ly + ry) / 2,
16322  fm,
16323  fb;
16324 
16325  if (ry === ly) {
16326  if (fx < x0 || fx >= x1) return;
16327  if (lx > rx) {
16328  if (!v0) v0 = [fx, y0];
16329  else if (v0[1] >= y1) return;
16330  v1 = [fx, y1];
16331  } else {
16332  if (!v0) v0 = [fx, y1];
16333  else if (v0[1] < y0) return;
16334  v1 = [fx, y0];
16335  }
16336  } else {
16337  fm = (lx - rx) / (ry - ly);
16338  fb = fy - fm * fx;
16339  if (fm < -1 || fm > 1) {
16340  if (lx > rx) {
16341  if (!v0) v0 = [(y0 - fb) / fm, y0];
16342  else if (v0[1] >= y1) return;
16343  v1 = [(y1 - fb) / fm, y1];
16344  } else {
16345  if (!v0) v0 = [(y1 - fb) / fm, y1];
16346  else if (v0[1] < y0) return;
16347  v1 = [(y0 - fb) / fm, y0];
16348  }
16349  } else {
16350  if (ly < ry) {
16351  if (!v0) v0 = [x0, fm * x0 + fb];
16352  else if (v0[0] >= x1) return;
16353  v1 = [x1, fm * x1 + fb];
16354  } else {
16355  if (!v0) v0 = [x1, fm * x1 + fb];
16356  else if (v0[0] < x0) return;
16357  v1 = [x0, fm * x0 + fb];
16358  }
16359  }
16360  }
16361 
16362  edge[0] = v0;
16363  edge[1] = v1;
16364  return true;
16365 }
16366 
16367 function clipEdges(x0, y0, x1, y1) {
16368  var i = edges.length,
16369  edge;
16370 
16371  while (i--) {
16372  if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
16373  || !clipEdge(edge, x0, y0, x1, y1)
16374  || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
16375  || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
16376  delete edges[i];
16377  }
16378  }
16379 }
16380 
16381 function createCell(site) {
16382  return cells[site.index] = {
16383  site: site,
16384  halfedges: []
16385  };
16386 }
16387 
16388 function cellHalfedgeAngle(cell, edge) {
16389  var site = cell.site,
16390  va = edge.left,
16391  vb = edge.right;
16392  if (site === vb) vb = va, va = site;
16393  if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
16394  if (site === va) va = edge[1], vb = edge[0];
16395  else va = edge[0], vb = edge[1];
16396  return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
16397 }
16398 
16399 function cellHalfedgeStart(cell, edge) {
16400  return edge[+(edge.left !== cell.site)];
16401 }
16402 
16403 function cellHalfedgeEnd(cell, edge) {
16404  return edge[+(edge.left === cell.site)];
16405 }
16406 
16407 function sortCellHalfedges() {
16408  for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
16409  if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
16410  var index = new Array(m),
16411  array = new Array(m);
16412  for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
16413  index.sort(function(i, j) { return array[j] - array[i]; });
16414  for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
16415  for (j = 0; j < m; ++j) halfedges[j] = array[j];
16416  }
16417  }
16418 }
16419 
16420 function clipCells(x0, y0, x1, y1) {
16421  var nCells = cells.length,
16422  iCell,
16423  cell,
16424  site,
16425  iHalfedge,
16426  halfedges,
16427  nHalfedges,
16428  start,
16429  startX,
16430  startY,
16431  end,
16432  endX,
16433  endY,
16434  cover = true;
16435 
16436  for (iCell = 0; iCell < nCells; ++iCell) {
16437  if (cell = cells[iCell]) {
16438  site = cell.site;
16439  halfedges = cell.halfedges;
16440  iHalfedge = halfedges.length;
16441 
16442  // Remove any dangling clipped edges.
16443  while (iHalfedge--) {
16444  if (!edges[halfedges[iHalfedge]]) {
16445  halfedges.splice(iHalfedge, 1);
16446  }
16447  }
16448 
16449  // Insert any border edges as necessary.
16450  iHalfedge = 0, nHalfedges = halfedges.length;
16451  while (iHalfedge < nHalfedges) {
16452  end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
16453  start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
16454  if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
16455  halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
16456  Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
16457  : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
16458  : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
16459  : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
16460  : null)) - 1);
16461  ++nHalfedges;
16462  }
16463  }
16464 
16465  if (nHalfedges) cover = false;
16466  }
16467  }
16468 
16469  // If there weren’t any edges, have the closest site cover the extent.
16470  // It doesn’t matter which corner of the extent we measure!
16471  if (cover) {
16472  var dx, dy, d2, dc = Infinity;
16473 
16474  for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
16475  if (cell = cells[iCell]) {
16476  site = cell.site;
16477  dx = site[0] - x0;
16478  dy = site[1] - y0;
16479  d2 = dx * dx + dy * dy;
16480  if (d2 < dc) dc = d2, cover = cell;
16481  }
16482  }
16483 
16484  if (cover) {
16485  var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
16486  cover.halfedges.push(
16487  edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
16488  edges.push(createBorderEdge(site, v01, v11)) - 1,
16489  edges.push(createBorderEdge(site, v11, v10)) - 1,
16490  edges.push(createBorderEdge(site, v10, v00)) - 1
16491  );
16492  }
16493  }
16494 
16495  // Lastly delete any cells with no edges; these were entirely clipped.
16496  for (iCell = 0; iCell < nCells; ++iCell) {
16497  if (cell = cells[iCell]) {
16498  if (!cell.halfedges.length) {
16499  delete cells[iCell];
16500  }
16501  }
16502  }
16503 }
16504 
16505 var circlePool = [];
16506 
16507 var firstCircle;
16508 
16509 function Circle() {
16510  RedBlackNode(this);
16511  this.x =
16512  this.y =
16513  this.arc =
16514  this.site =
16515  this.cy = null;
16516 }
16517 
16518 function attachCircle(arc) {
16519  var lArc = arc.P,
16520  rArc = arc.N;
16521 
16522  if (!lArc || !rArc) return;
16523 
16524  var lSite = lArc.site,
16525  cSite = arc.site,
16526  rSite = rArc.site;
16527 
16528  if (lSite === rSite) return;
16529 
16530  var bx = cSite[0],
16531  by = cSite[1],
16532  ax = lSite[0] - bx,
16533  ay = lSite[1] - by,
16534  cx = rSite[0] - bx,
16535  cy = rSite[1] - by;
16536 
16537  var d = 2 * (ax * cy - ay * cx);
16538  if (d >= -epsilon2$2) return;
16539 
16540  var ha = ax * ax + ay * ay,
16541  hc = cx * cx + cy * cy,
16542  x = (cy * ha - ay * hc) / d,
16543  y = (ax * hc - cx * ha) / d;
16544 
16545  var circle = circlePool.pop() || new Circle;
16546  circle.arc = arc;
16547  circle.site = cSite;
16548  circle.x = x + bx;
16549  circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
16550 
16551  arc.circle = circle;
16552 
16553  var before = null,
16554  node = circles._;
16555 
16556  while (node) {
16557  if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
16558  if (node.L) node = node.L;
16559  else { before = node.P; break; }
16560  } else {
16561  if (node.R) node = node.R;
16562  else { before = node; break; }
16563  }
16564  }
16565 
16566  circles.insert(before, circle);
16567  if (!before) firstCircle = circle;
16568 }
16569 
16570 function detachCircle(arc) {
16571  var circle = arc.circle;
16572  if (circle) {
16573  if (!circle.P) firstCircle = circle.N;
16574  circles.remove(circle);
16575  circlePool.push(circle);
16576  RedBlackNode(circle);
16577  arc.circle = null;
16578  }
16579 }
16580 
16581 var beachPool = [];
16582 
16583 function Beach() {
16584  RedBlackNode(this);
16585  this.edge =
16586  this.site =
16587  this.circle = null;
16588 }
16589 
16590 function createBeach(site) {
16591  var beach = beachPool.pop() || new Beach;
16592  beach.site = site;
16593  return beach;
16594 }
16595 
16596 function detachBeach(beach) {
16597  detachCircle(beach);
16598  beaches.remove(beach);
16599  beachPool.push(beach);
16600  RedBlackNode(beach);
16601 }
16602 
16603 function removeBeach(beach) {
16604  var circle = beach.circle,
16605  x = circle.x,
16606  y = circle.cy,
16607  vertex = [x, y],
16608  previous = beach.P,
16609  next = beach.N,
16610  disappearing = [beach];
16611 
16612  detachBeach(beach);
16613 
16614  var lArc = previous;
16615  while (lArc.circle
16616  && Math.abs(x - lArc.circle.x) < epsilon$4
16617  && Math.abs(y - lArc.circle.cy) < epsilon$4) {
16618  previous = lArc.P;
16619  disappearing.unshift(lArc);
16620  detachBeach(lArc);
16621  lArc = previous;
16622  }
16623 
16624  disappearing.unshift(lArc);
16625  detachCircle(lArc);
16626 
16627  var rArc = next;
16628  while (rArc.circle
16629  && Math.abs(x - rArc.circle.x) < epsilon$4
16630  && Math.abs(y - rArc.circle.cy) < epsilon$4) {
16631  next = rArc.N;
16632  disappearing.push(rArc);
16633  detachBeach(rArc);
16634  rArc = next;
16635  }
16636 
16637  disappearing.push(rArc);
16638  detachCircle(rArc);
16639 
16640  var nArcs = disappearing.length,
16641  iArc;
16642  for (iArc = 1; iArc < nArcs; ++iArc) {
16643  rArc = disappearing[iArc];
16644  lArc = disappearing[iArc - 1];
16645  setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
16646  }
16647 
16648  lArc = disappearing[0];
16649  rArc = disappearing[nArcs - 1];
16650  rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
16651 
16652  attachCircle(lArc);
16653  attachCircle(rArc);
16654 }
16655 
16656 function addBeach(site) {
16657  var x = site[0],
16658  directrix = site[1],
16659  lArc,
16660  rArc,
16661  dxl,
16662  dxr,
16663  node = beaches._;
16664 
16665  while (node) {
16666  dxl = leftBreakPoint(node, directrix) - x;
16667  if (dxl > epsilon$4) node = node.L; else {
16668  dxr = x - rightBreakPoint(node, directrix);
16669  if (dxr > epsilon$4) {
16670  if (!node.R) {
16671  lArc = node;
16672  break;
16673  }
16674  node = node.R;
16675  } else {
16676  if (dxl > -epsilon$4) {
16677  lArc = node.P;
16678  rArc = node;
16679  } else if (dxr > -epsilon$4) {
16680  lArc = node;
16681  rArc = node.N;
16682  } else {
16683  lArc = rArc = node;
16684  }
16685  break;
16686  }
16687  }
16688  }
16689 
16690  createCell(site);
16691  var newArc = createBeach(site);
16692  beaches.insert(lArc, newArc);
16693 
16694  if (!lArc && !rArc) return;
16695 
16696  if (lArc === rArc) {
16697  detachCircle(lArc);
16698  rArc = createBeach(lArc.site);
16699  beaches.insert(newArc, rArc);
16700  newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
16701  attachCircle(lArc);
16702  attachCircle(rArc);
16703  return;
16704  }
16705 
16706  if (!rArc) { // && lArc
16707  newArc.edge = createEdge(lArc.site, newArc.site);
16708  return;
16709  }
16710 
16711  // else lArc !== rArc
16712  detachCircle(lArc);
16713  detachCircle(rArc);
16714 
16715  var lSite = lArc.site,
16716  ax = lSite[0],
16717  ay = lSite[1],
16718  bx = site[0] - ax,
16719  by = site[1] - ay,
16720  rSite = rArc.site,
16721  cx = rSite[0] - ax,
16722  cy = rSite[1] - ay,
16723  d = 2 * (bx * cy - by * cx),
16724  hb = bx * bx + by * by,
16725  hc = cx * cx + cy * cy,
16726  vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
16727 
16728  setEdgeEnd(rArc.edge, lSite, rSite, vertex);
16729  newArc.edge = createEdge(lSite, site, null, vertex);
16730  rArc.edge = createEdge(site, rSite, null, vertex);
16731  attachCircle(lArc);
16732  attachCircle(rArc);
16733 }
16734 
16735 function leftBreakPoint(arc, directrix) {
16736  var site = arc.site,
16737  rfocx = site[0],
16738  rfocy = site[1],
16739  pby2 = rfocy - directrix;
16740 
16741  if (!pby2) return rfocx;
16742 
16743  var lArc = arc.P;
16744  if (!lArc) return -Infinity;
16745 
16746  site = lArc.site;
16747  var lfocx = site[0],
16748  lfocy = site[1],
16749  plby2 = lfocy - directrix;
16750 
16751  if (!plby2) return lfocx;
16752 
16753  var hl = lfocx - rfocx,
16754  aby2 = 1 / pby2 - 1 / plby2,
16755  b = hl / plby2;
16756 
16757  if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
16758 
16759  return (rfocx + lfocx) / 2;
16760 }
16761 
16762 function rightBreakPoint(arc, directrix) {
16763  var rArc = arc.N;
16764  if (rArc) return leftBreakPoint(rArc, directrix);
16765  var site = arc.site;
16766  return site[1] === directrix ? site[0] : Infinity;
16767 }
16768 
16769 var epsilon$4 = 1e-6;
16770 var epsilon2$2 = 1e-12;
16771 var beaches;
16772 var cells;
16773 var circles;
16774 var edges;
16775 
16776 function triangleArea(a, b, c) {
16777  return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
16778 }
16779 
16780 function lexicographic(a, b) {
16781  return b[1] - a[1]
16782  || b[0] - a[0];
16783 }
16784 
16785 function Diagram(sites, extent) {
16786  var site = sites.sort(lexicographic).pop(),
16787  x,
16788  y,
16789  circle;
16790 
16791  edges = [];
16792  cells = new Array(sites.length);
16793  beaches = new RedBlackTree;
16794  circles = new RedBlackTree;
16795 
16796  while (true) {
16797  circle = firstCircle;
16798  if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
16799  if (site[0] !== x || site[1] !== y) {
16800  addBeach(site);
16801  x = site[0], y = site[1];
16802  }
16803  site = sites.pop();
16804  } else if (circle) {
16805  removeBeach(circle.arc);
16806  } else {
16807  break;
16808  }
16809  }
16810 
16811  sortCellHalfedges();
16812 
16813  if (extent) {
16814  var x0 = +extent[0][0],
16815  y0 = +extent[0][1],
16816  x1 = +extent[1][0],
16817  y1 = +extent[1][1];
16818  clipEdges(x0, y0, x1, y1);
16819  clipCells(x0, y0, x1, y1);
16820  }
16821 
16822  this.edges = edges;
16823  this.cells = cells;
16824 
16825  beaches =
16826  circles =
16827  edges =
16828  cells = null;
16829 }
16830 
16831 Diagram.prototype = {
16832  constructor: Diagram,
16833 
16834  polygons: function() {
16835  var edges = this.edges;
16836 
16837  return this.cells.map(function(cell) {
16838  var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
16839  polygon.data = cell.site.data;
16840  return polygon;
16841  });
16842  },
16843 
16844  triangles: function() {
16845  var triangles = [],
16846  edges = this.edges;
16847 
16848  this.cells.forEach(function(cell, i) {
16849  if (!(m = (halfedges = cell.halfedges).length)) return;
16850  var site = cell.site,
16851  halfedges,
16852  j = -1,
16853  m,
16854  s0,
16855  e1 = edges[halfedges[m - 1]],
16856  s1 = e1.left === site ? e1.right : e1.left;
16857 
16858  while (++j < m) {
16859  s0 = s1;
16860  e1 = edges[halfedges[j]];
16861  s1 = e1.left === site ? e1.right : e1.left;
16862  if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
16863  triangles.push([site.data, s0.data, s1.data]);
16864  }
16865  }
16866  });
16867 
16868  return triangles;
16869  },
16870 
16871  links: function() {
16872  return this.edges.filter(function(edge) {
16873  return edge.right;
16874  }).map(function(edge) {
16875  return {
16876  source: edge.left.data,
16877  target: edge.right.data
16878  };
16879  });
16880  },
16881 
16882  find: function(x, y, radius) {
16883  var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
16884 
16885  // Use the previously-found cell, or start with an arbitrary one.
16886  while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
16887  var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
16888 
16889  // Traverse the half-edges to find a closer cell, if any.
16890  do {
16891  cell = that.cells[i0 = i1], i1 = null;
16892  cell.halfedges.forEach(function(e) {
16893  var edge = that.edges[e], v = edge.left;
16894  if ((v === cell.site || !v) && !(v = edge.right)) return;
16895  var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
16896  if (v2 < d2) d2 = v2, i1 = v.index;
16897  });
16898  } while (i1 !== null);
16899 
16900  that._found = i0;
16901 
16902  return radius == null || d2 <= radius * radius ? cell.site : null;
16903  }
16904 };
16905 
16906 function voronoi() {
16907  var x$$1 = x$4,
16908  y$$1 = y$4,
16909  extent = null;
16910 
16911  function voronoi(data) {
16912  return new Diagram(data.map(function(d, i) {
16913  var s = [Math.round(x$$1(d, i, data) / epsilon$4) * epsilon$4, Math.round(y$$1(d, i, data) / epsilon$4) * epsilon$4];
16914  s.index = i;
16915  s.data = d;
16916  return s;
16917  }), extent);
16918  }
16919 
16920  voronoi.polygons = function(data) {
16921  return voronoi(data).polygons();
16922  };
16923 
16924  voronoi.links = function(data) {
16925  return voronoi(data).links();
16926  };
16927 
16928  voronoi.triangles = function(data) {
16929  return voronoi(data).triangles();
16930  };
16931 
16932  voronoi.x = function(_) {
16933  return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$c(+_), voronoi) : x$$1;
16934  };
16935 
16936  voronoi.y = function(_) {
16937  return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$c(+_), voronoi) : y$$1;
16938  };
16939 
16940  voronoi.extent = function(_) {
16941  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]]];
16942  };
16943 
16944  voronoi.size = function(_) {
16945  return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
16946  };
16947 
16948  return voronoi;
16949 }
16950 
16951 function constant$d(x) {
16952  return function() {
16953  return x;
16954  };
16955 }
16956 
16957 function ZoomEvent(target, type, transform) {
16958  this.target = target;
16959  this.type = type;
16960  this.transform = transform;
16961 }
16962 
16963 function Transform(k, x, y) {
16964  this.k = k;
16965  this.x = x;
16966  this.y = y;
16967 }
16968 
16969 Transform.prototype = {
16970  constructor: Transform,
16971  scale: function(k) {
16972  return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
16973  },
16974  translate: function(x, y) {
16975  return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
16976  },
16977  apply: function(point) {
16978  return [point[0] * this.k + this.x, point[1] * this.k + this.y];
16979  },
16980  applyX: function(x) {
16981  return x * this.k + this.x;
16982  },
16983  applyY: function(y) {
16984  return y * this.k + this.y;
16985  },
16986  invert: function(location) {
16987  return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
16988  },
16989  invertX: function(x) {
16990  return (x - this.x) / this.k;
16991  },
16992  invertY: function(y) {
16993  return (y - this.y) / this.k;
16994  },
16995  rescaleX: function(x) {
16996  return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
16997  },
16998  rescaleY: function(y) {
16999  return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
17000  },
17001  toString: function() {
17002  return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
17003  }
17004 };
17005 
17006 var identity$8 = new Transform(1, 0, 0);
17007 
17008 transform$1.prototype = Transform.prototype;
17009 
17010 function transform$1(node) {
17011  return node.__zoom || identity$8;
17012 }
17013 
17014 function nopropagation$2() {
17015  exports.event.stopImmediatePropagation();
17016 }
17017 
17018 function noevent$2() {
17019  exports.event.preventDefault();
17020  exports.event.stopImmediatePropagation();
17021 }
17022 
17023 // Ignore right-click, since that should open the context menu.
17024 function defaultFilter$2() {
17025  return !exports.event.button;
17026 }
17027 
17028 function defaultExtent$1() {
17029  var e = this, w, h;
17030  if (e instanceof SVGElement) {
17031  e = e.ownerSVGElement || e;
17032  w = e.width.baseVal.value;
17033  h = e.height.baseVal.value;
17034  } else {
17035  w = e.clientWidth;
17036  h = e.clientHeight;
17037  }
17038  return [[0, 0], [w, h]];
17039 }
17040 
17041 function defaultTransform() {
17042  return this.__zoom || identity$8;
17043 }
17044 
17045 function defaultWheelDelta() {
17046  return -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500;
17047 }
17048 
17049 function defaultTouchable$1() {
17050  return "ontouchstart" in this;
17051 }
17052 
17053 function defaultConstrain(transform, extent, translateExtent) {
17054  var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
17055  dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
17056  dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
17057  dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
17058  return transform.translate(
17059  dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
17060  dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
17061  );
17062 }
17063 
17064 function zoom() {
17065  var filter = defaultFilter$2,
17066  extent = defaultExtent$1,
17067  constrain = defaultConstrain,
17068  wheelDelta = defaultWheelDelta,
17069  touchable = defaultTouchable$1,
17070  scaleExtent = [0, Infinity],
17071  translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
17072  duration = 250,
17073  interpolate = interpolateZoom,
17074  gestures = [],
17075  listeners = dispatch("start", "zoom", "end"),
17076  touchstarting,
17077  touchending,
17078  touchDelay = 500,
17079  wheelDelay = 150,
17080  clickDistance2 = 0;
17081 
17082  function zoom(selection$$1) {
17083  selection$$1
17084  .property("__zoom", defaultTransform)
17085  .on("wheel.zoom", wheeled)
17086  .on("mousedown.zoom", mousedowned)
17087  .on("dblclick.zoom", dblclicked)
17088  .filter(touchable)
17089  .on("touchstart.zoom", touchstarted)
17090  .on("touchmove.zoom", touchmoved)
17091  .on("touchend.zoom touchcancel.zoom", touchended)
17092  .style("touch-action", "none")
17093  .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
17094  }
17095 
17096  zoom.transform = function(collection, transform) {
17097  var selection$$1 = collection.selection ? collection.selection() : collection;
17098  selection$$1.property("__zoom", defaultTransform);
17099  if (collection !== selection$$1) {
17100  schedule(collection, transform);
17101  } else {
17102  selection$$1.interrupt().each(function() {
17103  gesture(this, arguments)
17104  .start()
17105  .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
17106  .end();
17107  });
17108  }
17109  };
17110 
17111  zoom.scaleBy = function(selection$$1, k) {
17112  zoom.scaleTo(selection$$1, function() {
17113  var k0 = this.__zoom.k,
17114  k1 = typeof k === "function" ? k.apply(this, arguments) : k;
17115  return k0 * k1;
17116  });
17117  };
17118 
17119  zoom.scaleTo = function(selection$$1, k) {
17120  zoom.transform(selection$$1, function() {
17121  var e = extent.apply(this, arguments),
17122  t0 = this.__zoom,
17123  p0 = centroid(e),
17124  p1 = t0.invert(p0),
17125  k1 = typeof k === "function" ? k.apply(this, arguments) : k;
17126  return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
17127  });
17128  };
17129 
17130  zoom.translateBy = function(selection$$1, x, y) {
17131  zoom.transform(selection$$1, function() {
17132  return constrain(this.__zoom.translate(
17133  typeof x === "function" ? x.apply(this, arguments) : x,
17134  typeof y === "function" ? y.apply(this, arguments) : y
17135  ), extent.apply(this, arguments), translateExtent);
17136  });
17137  };
17138 
17139  zoom.translateTo = function(selection$$1, x, y) {
17140  zoom.transform(selection$$1, function() {
17141  var e = extent.apply(this, arguments),
17142  t = this.__zoom,
17143  p = centroid(e);
17144  return constrain(identity$8.translate(p[0], p[1]).scale(t.k).translate(
17145  typeof x === "function" ? -x.apply(this, arguments) : -x,
17146  typeof y === "function" ? -y.apply(this, arguments) : -y
17147  ), e, translateExtent);
17148  });
17149  };
17150 
17151  function scale(transform, k) {
17152  k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
17153  return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
17154  }
17155 
17156  function translate(transform, p0, p1) {
17157  var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
17158  return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
17159  }
17160 
17161  function centroid(extent) {
17162  return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
17163  }
17164 
17165  function schedule(transition$$1, transform, center) {
17166  transition$$1
17167  .on("start.zoom", function() { gesture(this, arguments).start(); })
17168  .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
17169  .tween("zoom", function() {
17170  var that = this,
17171  args = arguments,
17172  g = gesture(that, args),
17173  e = extent.apply(that, args),
17174  p = center || centroid(e),
17175  w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
17176  a = that.__zoom,
17177  b = typeof transform === "function" ? transform.apply(that, args) : transform,
17178  i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
17179  return function(t) {
17180  if (t === 1) t = b; // Avoid rounding error on end.
17181  else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
17182  g.zoom(null, t);
17183  };
17184  });
17185  }
17186 
17187  function gesture(that, args) {
17188  for (var i = 0, n = gestures.length, g; i < n; ++i) {
17189  if ((g = gestures[i]).that === that) {
17190  return g;
17191  }
17192  }
17193  return new Gesture(that, args);
17194  }
17195 
17196  function Gesture(that, args) {
17197  this.that = that;
17198  this.args = args;
17199  this.index = -1;
17200  this.active = 0;
17201  this.extent = extent.apply(that, args);
17202  }
17203 
17204  Gesture.prototype = {
17205  start: function() {
17206  if (++this.active === 1) {
17207  this.index = gestures.push(this) - 1;
17208  this.emit("start");
17209  }
17210  return this;
17211  },
17212  zoom: function(key, transform) {
17213  if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
17214  if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
17215  if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
17216  this.that.__zoom = transform;
17217  this.emit("zoom");
17218  return this;
17219  },
17220  end: function() {
17221  if (--this.active === 0) {
17222  gestures.splice(this.index, 1);
17223  this.index = -1;
17224  this.emit("end");
17225  }
17226  return this;
17227  },
17228  emit: function(type) {
17229  customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
17230  }
17231  };
17232 
17233  function wheeled() {
17234  if (!filter.apply(this, arguments)) return;
17235  var g = gesture(this, arguments),
17236  t = this.__zoom,
17237  k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
17238  p = mouse(this);
17239 
17240  // If the mouse is in the same location as before, reuse it.
17241  // If there were recent wheel events, reset the wheel idle timeout.
17242  if (g.wheel) {
17243  if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
17244  g.mouse[1] = t.invert(g.mouse[0] = p);
17245  }
17246  clearTimeout(g.wheel);
17247  }
17248 
17249  // If this wheel event won’t trigger a transform change, ignore it.
17250  else if (t.k === k) return;
17251 
17252  // Otherwise, capture the mouse point and location at the start.
17253  else {
17254  g.mouse = [p, t.invert(p)];
17255  interrupt(this);
17256  g.start();
17257  }
17258 
17259  noevent$2();
17260  g.wheel = setTimeout(wheelidled, wheelDelay);
17261  g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
17262 
17263  function wheelidled() {
17264  g.wheel = null;
17265  g.end();
17266  }
17267  }
17268 
17269  function mousedowned() {
17270  if (touchending || !filter.apply(this, arguments)) return;
17271  var g = gesture(this, arguments),
17272  v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
17273  p = mouse(this),
17274  x0 = exports.event.clientX,
17275  y0 = exports.event.clientY;
17276 
17277  dragDisable(exports.event.view);
17278  nopropagation$2();
17279  g.mouse = [p, this.__zoom.invert(p)];
17280  interrupt(this);
17281  g.start();
17282 
17283  function mousemoved() {
17284  noevent$2();
17285  if (!g.moved) {
17286  var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
17287  g.moved = dx * dx + dy * dy > clickDistance2;
17288  }
17289  g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
17290  }
17291 
17292  function mouseupped() {
17293  v.on("mousemove.zoom mouseup.zoom", null);
17294  yesdrag(exports.event.view, g.moved);
17295  noevent$2();
17296  g.end();
17297  }
17298  }
17299 
17300  function dblclicked() {
17301  if (!filter.apply(this, arguments)) return;
17302  var t0 = this.__zoom,
17303  p0 = mouse(this),
17304  p1 = t0.invert(p0),
17305  k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
17306  t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
17307 
17308  noevent$2();
17309  if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
17310  else select(this).call(zoom.transform, t1);
17311  }
17312 
17313  function touchstarted() {
17314  if (!filter.apply(this, arguments)) return;
17315  var g = gesture(this, arguments),
17316  touches$$1 = exports.event.changedTouches,
17317  started,
17318  n = touches$$1.length, i, t, p;
17319 
17320  nopropagation$2();
17321  for (i = 0; i < n; ++i) {
17322  t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
17323  p = [p, this.__zoom.invert(p), t.identifier];
17324  if (!g.touch0) g.touch0 = p, started = true;
17325  else if (!g.touch1) g.touch1 = p;
17326  }
17327 
17328  // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
17329  if (touchstarting) {
17330  touchstarting = clearTimeout(touchstarting);
17331  if (!g.touch1) {
17332  g.end();
17333  p = select(this).on("dblclick.zoom");
17334  if (p) p.apply(this, arguments);
17335  return;
17336  }
17337  }
17338 
17339  if (started) {
17340  touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
17341  interrupt(this);
17342  g.start();
17343  }
17344  }
17345 
17346  function touchmoved() {
17347  var g = gesture(this, arguments),
17348  touches$$1 = exports.event.changedTouches,
17349  n = touches$$1.length, i, t, p, l;
17350 
17351  noevent$2();
17352  if (touchstarting) touchstarting = clearTimeout(touchstarting);
17353  for (i = 0; i < n; ++i) {
17354  t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
17355  if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
17356  else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
17357  }
17358  t = g.that.__zoom;
17359  if (g.touch1) {
17360  var p0 = g.touch0[0], l0 = g.touch0[1],
17361  p1 = g.touch1[0], l1 = g.touch1[1],
17362  dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
17363  dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
17364  t = scale(t, Math.sqrt(dp / dl));
17365  p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
17366  l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
17367  }
17368  else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
17369  else return;
17370  g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
17371  }
17372 
17373  function touchended() {
17374  var g = gesture(this, arguments),
17375  touches$$1 = exports.event.changedTouches,
17376  n = touches$$1.length, i, t;
17377 
17378  nopropagation$2();
17379  if (touchending) clearTimeout(touchending);
17380  touchending = setTimeout(function() { touchending = null; }, touchDelay);
17381  for (i = 0; i < n; ++i) {
17382  t = touches$$1[i];
17383  if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
17384  else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
17385  }
17386  if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
17387  if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
17388  else g.end();
17389  }
17390 
17391  zoom.wheelDelta = function(_) {
17392  return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$d(+_), zoom) : wheelDelta;
17393  };
17394 
17395  zoom.filter = function(_) {
17396  return arguments.length ? (filter = typeof _ === "function" ? _ : constant$d(!!_), zoom) : filter;
17397  };
17398 
17399  zoom.touchable = function(_) {
17400  return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$d(!!_), zoom) : touchable;
17401  };
17402 
17403  zoom.extent = function(_) {
17404  return arguments.length ? (extent = typeof _ === "function" ? _ : constant$d([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
17405  };
17406 
17407  zoom.scaleExtent = function(_) {
17408  return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
17409  };
17410 
17411  zoom.translateExtent = function(_) {
17412  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]]];
17413  };
17414 
17415  zoom.constrain = function(_) {
17416  return arguments.length ? (constrain = _, zoom) : constrain;
17417  };
17418 
17419  zoom.duration = function(_) {
17420  return arguments.length ? (duration = +_, zoom) : duration;
17421  };
17422 
17423  zoom.interpolate = function(_) {
17424  return arguments.length ? (interpolate = _, zoom) : interpolate;
17425  };
17426 
17427  zoom.on = function() {
17428  var value = listeners.on.apply(listeners, arguments);
17429  return value === listeners ? zoom : value;
17430  };
17431 
17432  zoom.clickDistance = function(_) {
17433  return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
17434  };
17435 
17436  return zoom;
17437 }
17438 
17439 exports.version = version;
17440 exports.bisect = bisectRight;
17441 exports.bisectRight = bisectRight;
17442 exports.bisectLeft = bisectLeft;
17443 exports.ascending = ascending;
17444 exports.bisector = bisector;
17445 exports.cross = cross;
17446 exports.descending = descending;
17447 exports.deviation = deviation;
17448 exports.extent = extent;
17449 exports.histogram = histogram;
17450 exports.thresholdFreedmanDiaconis = freedmanDiaconis;
17451 exports.thresholdScott = scott;
17452 exports.thresholdSturges = thresholdSturges;
17453 exports.max = max;
17454 exports.mean = mean;
17455 exports.median = median;
17456 exports.merge = merge;
17457 exports.min = min;
17458 exports.pairs = pairs;
17459 exports.permute = permute;
17460 exports.quantile = threshold;
17461 exports.range = sequence;
17462 exports.scan = scan;
17463 exports.shuffle = shuffle;
17464 exports.sum = sum;
17465 exports.ticks = ticks;
17466 exports.tickIncrement = tickIncrement;
17467 exports.tickStep = tickStep;
17468 exports.transpose = transpose;
17469 exports.variance = variance;
17470 exports.zip = zip;
17471 exports.axisTop = axisTop;
17472 exports.axisRight = axisRight;
17473 exports.axisBottom = axisBottom;
17474 exports.axisLeft = axisLeft;
17475 exports.brush = brush;
17476 exports.brushX = brushX;
17477 exports.brushY = brushY;
17478 exports.brushSelection = brushSelection;
17479 exports.chord = chord;
17480 exports.ribbon = ribbon;
17481 exports.nest = nest;
17482 exports.set = set$2;
17483 exports.map = map$1;
17484 exports.keys = keys;
17485 exports.values = values;
17486 exports.entries = entries;
17487 exports.color = color;
17488 exports.rgb = rgb;
17489 exports.hsl = hsl;
17490 exports.lab = lab;
17491 exports.hcl = hcl;
17492 exports.lch = lch;
17493 exports.gray = gray;
17494 exports.cubehelix = cubehelix;
17495 exports.contours = contours;
17496 exports.contourDensity = density;
17497 exports.dispatch = dispatch;
17498 exports.drag = drag;
17499 exports.dragDisable = dragDisable;
17500 exports.dragEnable = yesdrag;
17501 exports.dsvFormat = dsvFormat;
17502 exports.csvParse = csvParse;
17503 exports.csvParseRows = csvParseRows;
17504 exports.csvFormat = csvFormat;
17505 exports.csvFormatRows = csvFormatRows;
17506 exports.tsvParse = tsvParse;
17507 exports.tsvParseRows = tsvParseRows;
17508 exports.tsvFormat = tsvFormat;
17509 exports.tsvFormatRows = tsvFormatRows;
17510 exports.easeLinear = linear$1;
17511 exports.easeQuad = quadInOut;
17512 exports.easeQuadIn = quadIn;
17513 exports.easeQuadOut = quadOut;
17514 exports.easeQuadInOut = quadInOut;
17515 exports.easeCubic = cubicInOut;
17516 exports.easeCubicIn = cubicIn;
17517 exports.easeCubicOut = cubicOut;
17518 exports.easeCubicInOut = cubicInOut;
17519 exports.easePoly = polyInOut;
17520 exports.easePolyIn = polyIn;
17521 exports.easePolyOut = polyOut;
17522 exports.easePolyInOut = polyInOut;
17523 exports.easeSin = sinInOut;
17524 exports.easeSinIn = sinIn;
17525 exports.easeSinOut = sinOut;
17526 exports.easeSinInOut = sinInOut;
17527 exports.easeExp = expInOut;
17528 exports.easeExpIn = expIn;
17529 exports.easeExpOut = expOut;
17530 exports.easeExpInOut = expInOut;
17531 exports.easeCircle = circleInOut;
17532 exports.easeCircleIn = circleIn;
17533 exports.easeCircleOut = circleOut;
17534 exports.easeCircleInOut = circleInOut;
17535 exports.easeBounce = bounceOut;
17536 exports.easeBounceIn = bounceIn;
17537 exports.easeBounceOut = bounceOut;
17538 exports.easeBounceInOut = bounceInOut;
17539 exports.easeBack = backInOut;
17540 exports.easeBackIn = backIn;
17541 exports.easeBackOut = backOut;
17542 exports.easeBackInOut = backInOut;
17543 exports.easeElastic = elasticOut;
17544 exports.easeElasticIn = elasticIn;
17545 exports.easeElasticOut = elasticOut;
17546 exports.easeElasticInOut = elasticInOut;
17547 exports.blob = blob;
17548 exports.buffer = buffer;
17549 exports.dsv = dsv;
17550 exports.csv = csv$1;
17551 exports.tsv = tsv$1;
17552 exports.image = image;
17553 exports.json = json;
17554 exports.text = text;
17555 exports.xml = xml;
17556 exports.html = html;
17557 exports.svg = svg;
17558 exports.forceCenter = center$1;
17559 exports.forceCollide = collide;
17560 exports.forceLink = link;
17561 exports.forceManyBody = manyBody;
17562 exports.forceRadial = radial;
17563 exports.forceSimulation = simulation;
17564 exports.forceX = x$2;
17565 exports.forceY = y$2;
17566 exports.formatDefaultLocale = defaultLocale;
17567 exports.formatLocale = formatLocale;
17568 exports.formatSpecifier = formatSpecifier;
17569 exports.precisionFixed = precisionFixed;
17570 exports.precisionPrefix = precisionPrefix;
17571 exports.precisionRound = precisionRound;
17572 exports.geoArea = area$1;
17573 exports.geoBounds = bounds;
17574 exports.geoCentroid = centroid;
17575 exports.geoCircle = circle;
17576 exports.geoClipAntimeridian = clipAntimeridian;
17577 exports.geoClipCircle = clipCircle;
17578 exports.geoClipExtent = extent$1;
17579 exports.geoClipRectangle = clipRectangle;
17580 exports.geoContains = contains$1;
17581 exports.geoDistance = distance;
17582 exports.geoGraticule = graticule;
17583 exports.geoGraticule10 = graticule10;
17584 exports.geoInterpolate = interpolate$1;
17585 exports.geoLength = length$1;
17586 exports.geoPath = index$1;
17587 exports.geoAlbers = albers;
17588 exports.geoAlbersUsa = albersUsa;
17589 exports.geoAzimuthalEqualArea = azimuthalEqualArea;
17590 exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
17591 exports.geoAzimuthalEquidistant = azimuthalEquidistant;
17592 exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
17593 exports.geoConicConformal = conicConformal;
17594 exports.geoConicConformalRaw = conicConformalRaw;
17595 exports.geoConicEqualArea = conicEqualArea;
17596 exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
17597 exports.geoConicEquidistant = conicEquidistant;
17598 exports.geoConicEquidistantRaw = conicEquidistantRaw;
17599 exports.geoEqualEarth = equalEarth;
17600 exports.geoEqualEarthRaw = equalEarthRaw;
17601 exports.geoEquirectangular = equirectangular;
17602 exports.geoEquirectangularRaw = equirectangularRaw;
17603 exports.geoGnomonic = gnomonic;
17604 exports.geoGnomonicRaw = gnomonicRaw;
17605 exports.geoIdentity = identity$5;
17606 exports.geoProjection = projection;
17607 exports.geoProjectionMutator = projectionMutator;
17608 exports.geoMercator = mercator;
17609 exports.geoMercatorRaw = mercatorRaw;
17610 exports.geoNaturalEarth1 = naturalEarth1;
17611 exports.geoNaturalEarth1Raw = naturalEarth1Raw;
17612 exports.geoOrthographic = orthographic;
17613 exports.geoOrthographicRaw = orthographicRaw;
17614 exports.geoStereographic = stereographic;
17615 exports.geoStereographicRaw = stereographicRaw;
17616 exports.geoTransverseMercator = transverseMercator;
17617 exports.geoTransverseMercatorRaw = transverseMercatorRaw;
17618 exports.geoRotation = rotation;
17619 exports.geoStream = geoStream;
17620 exports.geoTransform = transform;
17621 exports.cluster = cluster;
17622 exports.hierarchy = hierarchy;
17623 exports.pack = index$2;
17624 exports.packSiblings = siblings;
17625 exports.packEnclose = enclose;
17626 exports.partition = partition;
17627 exports.stratify = stratify;
17628 exports.tree = tree;
17629 exports.treemap = index$3;
17630 exports.treemapBinary = binary;
17631 exports.treemapDice = treemapDice;
17632 exports.treemapSlice = treemapSlice;
17633 exports.treemapSliceDice = sliceDice;
17634 exports.treemapSquarify = squarify;
17635 exports.treemapResquarify = resquarify;
17636 exports.interpolate = interpolateValue;
17637 exports.interpolateArray = array$1;
17638 exports.interpolateBasis = basis$1;
17639 exports.interpolateBasisClosed = basisClosed;
17640 exports.interpolateDate = date;
17641 exports.interpolateDiscrete = discrete;
17642 exports.interpolateHue = hue$1;
17643 exports.interpolateNumber = interpolateNumber;
17644 exports.interpolateObject = object;
17645 exports.interpolateRound = interpolateRound;
17646 exports.interpolateString = interpolateString;
17647 exports.interpolateTransformCss = interpolateTransformCss;
17648 exports.interpolateTransformSvg = interpolateTransformSvg;
17649 exports.interpolateZoom = interpolateZoom;
17650 exports.interpolateRgb = interpolateRgb;
17651 exports.interpolateRgbBasis = rgbBasis;
17652 exports.interpolateRgbBasisClosed = rgbBasisClosed;
17653 exports.interpolateHsl = hsl$2;
17654 exports.interpolateHslLong = hslLong;
17655 exports.interpolateLab = lab$1;
17656 exports.interpolateHcl = hcl$2;
17657 exports.interpolateHclLong = hclLong;
17658 exports.interpolateCubehelix = cubehelix$2;
17659 exports.interpolateCubehelixLong = cubehelixLong;
17660 exports.piecewise = piecewise;
17661 exports.quantize = quantize;
17662 exports.path = path;
17663 exports.polygonArea = area$2;
17664 exports.polygonCentroid = centroid$1;
17665 exports.polygonHull = hull;
17666 exports.polygonContains = contains$2;
17667 exports.polygonLength = length$2;
17668 exports.quadtree = quadtree;
17669 exports.randomUniform = uniform;
17670 exports.randomNormal = normal;
17671 exports.randomLogNormal = logNormal;
17672 exports.randomBates = bates;
17673 exports.randomIrwinHall = irwinHall;
17674 exports.randomExponential = exponential$1;
17675 exports.scaleBand = band;
17676 exports.scalePoint = point$1;
17677 exports.scaleIdentity = identity$6;
17678 exports.scaleLinear = linear$2;
17679 exports.scaleLog = log$1;
17680 exports.scaleOrdinal = ordinal;
17681 exports.scaleImplicit = implicit;
17682 exports.scalePow = pow$1;
17683 exports.scaleSqrt = sqrt$1;
17684 exports.scaleQuantile = quantile$$1;
17685 exports.scaleQuantize = quantize$1;
17686 exports.scaleThreshold = threshold$1;
17687 exports.scaleTime = time;
17688 exports.scaleUtc = utcTime;
17689 exports.scaleSequential = sequential;
17690 exports.scaleDiverging = diverging;
17691 exports.schemeCategory10 = category10;
17692 exports.schemeAccent = Accent;
17693 exports.schemeDark2 = Dark2;
17694 exports.schemePaired = Paired;
17695 exports.schemePastel1 = Pastel1;
17696 exports.schemePastel2 = Pastel2;
17697 exports.schemeSet1 = Set1;
17698 exports.schemeSet2 = Set2;
17699 exports.schemeSet3 = Set3;
17700 exports.interpolateBrBG = BrBG;
17701 exports.schemeBrBG = scheme;
17702 exports.interpolatePRGn = PRGn;
17703 exports.schemePRGn = scheme$1;
17704 exports.interpolatePiYG = PiYG;
17705 exports.schemePiYG = scheme$2;
17706 exports.interpolatePuOr = PuOr;
17707 exports.schemePuOr = scheme$3;
17708 exports.interpolateRdBu = RdBu;
17709 exports.schemeRdBu = scheme$4;
17710 exports.interpolateRdGy = RdGy;
17711 exports.schemeRdGy = scheme$5;
17712 exports.interpolateRdYlBu = RdYlBu;
17713 exports.schemeRdYlBu = scheme$6;
17714 exports.interpolateRdYlGn = RdYlGn;
17715 exports.schemeRdYlGn = scheme$7;
17716 exports.interpolateSpectral = Spectral;
17717 exports.schemeSpectral = scheme$8;
17718 exports.interpolateBuGn = BuGn;
17719 exports.schemeBuGn = scheme$9;
17720 exports.interpolateBuPu = BuPu;
17721 exports.schemeBuPu = scheme$a;
17722 exports.interpolateGnBu = GnBu;
17723 exports.schemeGnBu = scheme$b;
17724 exports.interpolateOrRd = OrRd;
17725 exports.schemeOrRd = scheme$c;
17726 exports.interpolatePuBuGn = PuBuGn;
17727 exports.schemePuBuGn = scheme$d;
17728 exports.interpolatePuBu = PuBu;
17729 exports.schemePuBu = scheme$e;
17730 exports.interpolatePuRd = PuRd;
17731 exports.schemePuRd = scheme$f;
17732 exports.interpolateRdPu = RdPu;
17733 exports.schemeRdPu = scheme$g;
17734 exports.interpolateYlGnBu = YlGnBu;
17735 exports.schemeYlGnBu = scheme$h;
17736 exports.interpolateYlGn = YlGn;
17737 exports.schemeYlGn = scheme$i;
17738 exports.interpolateYlOrBr = YlOrBr;
17739 exports.schemeYlOrBr = scheme$j;
17740 exports.interpolateYlOrRd = YlOrRd;
17741 exports.schemeYlOrRd = scheme$k;
17742 exports.interpolateBlues = Blues;
17743 exports.schemeBlues = scheme$l;
17744 exports.interpolateGreens = Greens;
17745 exports.schemeGreens = scheme$m;
17746 exports.interpolateGreys = Greys;
17747 exports.schemeGreys = scheme$n;
17748 exports.interpolatePurples = Purples;
17749 exports.schemePurples = scheme$o;
17750 exports.interpolateReds = Reds;
17751 exports.schemeReds = scheme$p;
17752 exports.interpolateOranges = Oranges;
17753 exports.schemeOranges = scheme$q;
17754 exports.interpolateCubehelixDefault = cubehelix$3;
17755 exports.interpolateRainbow = rainbow;
17756 exports.interpolateWarm = warm;
17757 exports.interpolateCool = cool;
17758 exports.interpolateSinebow = sinebow;
17759 exports.interpolateViridis = viridis;
17760 exports.interpolateMagma = magma;
17761 exports.interpolateInferno = inferno;
17762 exports.interpolatePlasma = plasma;
17763 exports.create = create;
17764 exports.creator = creator;
17765 exports.local = local;
17766 exports.matcher = matcher$1;
17767 exports.mouse = mouse;
17768 exports.namespace = namespace;
17769 exports.namespaces = namespaces;
17770 exports.clientPoint = point;
17771 exports.select = select;
17772 exports.selectAll = selectAll;
17773 exports.selection = selection;
17774 exports.selector = selector;
17775 exports.selectorAll = selectorAll;
17776 exports.style = styleValue;
17777 exports.touch = touch;
17778 exports.touches = touches;
17779 exports.window = defaultView;
17780 exports.customEvent = customEvent;
17781 exports.arc = arc;
17782 exports.area = area$3;
17783 exports.line = line;
17784 exports.pie = pie;
17785 exports.areaRadial = areaRadial;
17786 exports.radialArea = areaRadial;
17787 exports.lineRadial = lineRadial$1;
17788 exports.radialLine = lineRadial$1;
17789 exports.pointRadial = pointRadial;
17790 exports.linkHorizontal = linkHorizontal;
17791 exports.linkVertical = linkVertical;
17792 exports.linkRadial = linkRadial;
17793 exports.symbol = symbol;
17794 exports.symbols = symbols;
17795 exports.symbolCircle = circle$2;
17796 exports.symbolCross = cross$2;
17797 exports.symbolDiamond = diamond;
17798 exports.symbolSquare = square;
17799 exports.symbolStar = star;
17800 exports.symbolTriangle = triangle;
17801 exports.symbolWye = wye;
17802 exports.curveBasisClosed = basisClosed$1;
17803 exports.curveBasisOpen = basisOpen;
17804 exports.curveBasis = basis$2;
17805 exports.curveBundle = bundle;
17806 exports.curveCardinalClosed = cardinalClosed;
17807 exports.curveCardinalOpen = cardinalOpen;
17808 exports.curveCardinal = cardinal;
17809 exports.curveCatmullRomClosed = catmullRomClosed;
17810 exports.curveCatmullRomOpen = catmullRomOpen;
17811 exports.curveCatmullRom = catmullRom;
17812 exports.curveLinearClosed = linearClosed;
17813 exports.curveLinear = curveLinear;
17814 exports.curveMonotoneX = monotoneX;
17815 exports.curveMonotoneY = monotoneY;
17816 exports.curveNatural = natural;
17817 exports.curveStep = step;
17818 exports.curveStepAfter = stepAfter;
17819 exports.curveStepBefore = stepBefore;
17820 exports.stack = stack;
17821 exports.stackOffsetExpand = expand;
17822 exports.stackOffsetDiverging = diverging$1;
17823 exports.stackOffsetNone = none$1;
17824 exports.stackOffsetSilhouette = silhouette;
17825 exports.stackOffsetWiggle = wiggle;
17826 exports.stackOrderAscending = ascending$3;
17827 exports.stackOrderDescending = descending$2;
17828 exports.stackOrderInsideOut = insideOut;
17829 exports.stackOrderNone = none$2;
17830 exports.stackOrderReverse = reverse;
17831 exports.timeInterval = newInterval;
17832 exports.timeMillisecond = millisecond;
17833 exports.timeMilliseconds = milliseconds;
17834 exports.utcMillisecond = millisecond;
17835 exports.utcMilliseconds = milliseconds;
17836 exports.timeSecond = second;
17837 exports.timeSeconds = seconds;
17838 exports.utcSecond = second;
17839 exports.utcSeconds = seconds;
17840 exports.timeMinute = minute;
17841 exports.timeMinutes = minutes;
17842 exports.timeHour = hour;
17843 exports.timeHours = hours;
17844 exports.timeDay = day;
17845 exports.timeDays = days;
17846 exports.timeWeek = sunday;
17847 exports.timeWeeks = sundays;
17848 exports.timeSunday = sunday;
17849 exports.timeSundays = sundays;
17850 exports.timeMonday = monday;
17851 exports.timeMondays = mondays;
17852 exports.timeTuesday = tuesday;
17853 exports.timeTuesdays = tuesdays;
17854 exports.timeWednesday = wednesday;
17855 exports.timeWednesdays = wednesdays;
17856 exports.timeThursday = thursday;
17857 exports.timeThursdays = thursdays;
17858 exports.timeFriday = friday;
17859 exports.timeFridays = fridays;
17860 exports.timeSaturday = saturday;
17861 exports.timeSaturdays = saturdays;
17862 exports.timeMonth = month;
17863 exports.timeMonths = months;
17864 exports.timeYear = year;
17865 exports.timeYears = years;
17866 exports.utcMinute = utcMinute;
17867 exports.utcMinutes = utcMinutes;
17868 exports.utcHour = utcHour;
17869 exports.utcHours = utcHours;
17870 exports.utcDay = utcDay;
17871 exports.utcDays = utcDays;
17872 exports.utcWeek = utcSunday;
17873 exports.utcWeeks = utcSundays;
17874 exports.utcSunday = utcSunday;
17875 exports.utcSundays = utcSundays;
17876 exports.utcMonday = utcMonday;
17877 exports.utcMondays = utcMondays;
17878 exports.utcTuesday = utcTuesday;
17879 exports.utcTuesdays = utcTuesdays;
17880 exports.utcWednesday = utcWednesday;
17881 exports.utcWednesdays = utcWednesdays;
17882 exports.utcThursday = utcThursday;
17883 exports.utcThursdays = utcThursdays;
17884 exports.utcFriday = utcFriday;
17885 exports.utcFridays = utcFridays;
17886 exports.utcSaturday = utcSaturday;
17887 exports.utcSaturdays = utcSaturdays;
17888 exports.utcMonth = utcMonth;
17889 exports.utcMonths = utcMonths;
17890 exports.utcYear = utcYear;
17891 exports.utcYears = utcYears;
17892 exports.timeFormatDefaultLocale = defaultLocale$1;
17893 exports.timeFormatLocale = formatLocale$1;
17894 exports.isoFormat = formatIso;
17895 exports.isoParse = parseIso;
17896 exports.now = now;
17897 exports.timer = timer;
17898 exports.timerFlush = timerFlush;
17899 exports.timeout = timeout$1;
17900 exports.interval = interval$1;
17901 exports.transition = transition;
17902 exports.active = active;
17903 exports.interrupt = interrupt;
17904 exports.voronoi = voronoi;
17905 exports.zoom = zoom;
17906 exports.zoomTransform = transform$1;
17907 exports.zoomIdentity = identity$8;
17908 
17909 Object.defineProperty(exports, '__esModule', { value: true });
17910 
17911 })));