UNPKG

510 kBJavaScriptView Raw
1// https://github.com/quantmind/giotto Version 0.1.3. Copyright 2016 quantmind.com.
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.giotto = global.giotto || {})));
6}(this, (function (exports) { 'use strict';
7
8var ascending = function (a, b) {
9 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
10};
11
12var bisector = function (compare) {
13 if (compare.length === 1) compare = ascendingComparator(compare);
14 return {
15 left: function left(a, x, lo, hi) {
16 if (lo == null) lo = 0;
17 if (hi == null) hi = a.length;
18 while (lo < hi) {
19 var mid = lo + hi >>> 1;
20 if (compare(a[mid], x) < 0) lo = mid + 1;else hi = mid;
21 }
22 return lo;
23 },
24 right: function right(a, x, lo, hi) {
25 if (lo == null) lo = 0;
26 if (hi == null) hi = a.length;
27 while (lo < hi) {
28 var mid = lo + hi >>> 1;
29 if (compare(a[mid], x) > 0) hi = mid;else lo = mid + 1;
30 }
31 return lo;
32 }
33 };
34};
35
36function ascendingComparator(f) {
37 return function (d, x) {
38 return ascending(f(d), x);
39 };
40}
41
42var ascendingBisect = bisector(ascending);
43var bisectRight = ascendingBisect.right;
44var bisectLeft = ascendingBisect.left;
45
46var descending = function (a, b) {
47 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
48};
49
50var number = function (x) {
51 return x === null ? NaN : +x;
52};
53
54var variance = function (array, f) {
55 var n = array.length,
56 m = 0,
57 a,
58 d,
59 s = 0,
60 i = -1,
61 j = 0;
62
63 if (f == null) {
64 while (++i < n) {
65 if (!isNaN(a = number(array[i]))) {
66 d = a - m;
67 m += d / ++j;
68 s += d * (a - m);
69 }
70 }
71 } else {
72 while (++i < n) {
73 if (!isNaN(a = number(f(array[i], i, array)))) {
74 d = a - m;
75 m += d / ++j;
76 s += d * (a - m);
77 }
78 }
79 }
80
81 if (j > 1) return s / (j - 1);
82};
83
84var deviation = function (array, f) {
85 var v = variance(array, f);
86 return v ? Math.sqrt(v) : v;
87};
88
89var extent$1 = function (array, f) {
90 var i = -1,
91 n = array.length,
92 a,
93 b,
94 c;
95
96 if (f == null) {
97 while (++i < n) {
98 if ((b = array[i]) != null && b >= b) {
99 a = c = b;break;
100 }
101 }while (++i < n) {
102 if ((b = array[i]) != null) {
103 if (a > b) a = b;
104 if (c < b) c = b;
105 }
106 }
107 } else {
108 while (++i < n) {
109 if ((b = f(array[i], i, array)) != null && b >= b) {
110 a = c = b;break;
111 }
112 }while (++i < n) {
113 if ((b = f(array[i], i, array)) != null) {
114 if (a > b) a = b;
115 if (c < b) c = b;
116 }
117 }
118 }
119
120 return [a, c];
121};
122
123var array = Array.prototype;
124
125var slice = array.slice;
126var map = array.map;
127
128var constant$1 = function (x) {
129 return function () {
130 return x;
131 };
132};
133
134var identity = function (x) {
135 return x;
136};
137
138var range = function (start, stop, step) {
139 start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
140
141 var i = -1,
142 n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
143 range = new Array(n);
144
145 while (++i < n) {
146 range[i] = start + i * step;
147 }
148
149 return range;
150};
151
152var e10 = Math.sqrt(50);
153var e5 = Math.sqrt(10);
154var e2 = Math.sqrt(2);
155
156var ticks = function (start, stop, count) {
157 var step = tickStep(start, stop, count);
158 return range(Math.ceil(start / step) * step, Math.floor(stop / step) * step + step / 2, // inclusive
159 step);
160};
161
162function tickStep(start, stop, count) {
163 var step0 = Math.abs(stop - start) / Math.max(0, count),
164 step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
165 error = step0 / step1;
166 if (error >= e10) step1 *= 10;else if (error >= e5) step1 *= 5;else if (error >= e2) step1 *= 2;
167 return stop < start ? -step1 : step1;
168}
169
170var sturges = function (values) {
171 return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
172};
173
174var histogram = function () {
175 var value = identity,
176 domain = extent$1,
177 threshold = sturges;
178
179 function histogram(data) {
180 var i,
181 n = data.length,
182 x,
183 values = new Array(n);
184
185 for (i = 0; i < n; ++i) {
186 values[i] = value(data[i], i, data);
187 }
188
189 var xz = domain(values),
190 x0 = xz[0],
191 x1 = xz[1],
192 tz = threshold(values, x0, x1);
193
194 // Convert number of thresholds into uniform thresholds.
195 if (!Array.isArray(tz)) tz = ticks(x0, x1, tz);
196
197 // Remove any thresholds outside the domain.
198 var m = tz.length;
199 while (tz[0] <= x0) {
200 tz.shift(), --m;
201 }while (tz[m - 1] >= x1) {
202 tz.pop(), --m;
203 }var bins = new Array(m + 1),
204 bin;
205
206 // Initialize bins.
207 for (i = 0; i <= m; ++i) {
208 bin = bins[i] = [];
209 bin.x0 = i > 0 ? tz[i - 1] : x0;
210 bin.x1 = i < m ? tz[i] : x1;
211 }
212
213 // Assign data to bins by value, ignoring any outside the domain.
214 for (i = 0; i < n; ++i) {
215 x = values[i];
216 if (x0 <= x && x <= x1) {
217 bins[bisectRight(tz, x, 0, m)].push(data[i]);
218 }
219 }
220
221 return bins;
222 }
223
224 histogram.value = function (_) {
225 return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(_), histogram) : value;
226 };
227
228 histogram.domain = function (_) {
229 return arguments.length ? (domain = typeof _ === "function" ? _ : constant$1([_[0], _[1]]), histogram) : domain;
230 };
231
232 histogram.thresholds = function (_) {
233 return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$1(slice.call(_)) : constant$1(_), histogram) : threshold;
234 };
235
236 return histogram;
237};
238
239var threshold = function (array, p, f) {
240 if (f == null) f = number;
241 if (!(n = array.length)) return;
242 if ((p = +p) <= 0 || n < 2) return +f(array[0], 0, array);
243 if (p >= 1) return +f(array[n - 1], n - 1, array);
244 var n,
245 h = (n - 1) * p,
246 i = Math.floor(h),
247 a = +f(array[i], i, array),
248 b = +f(array[i + 1], i + 1, array);
249 return a + (b - a) * (h - i);
250};
251
252var freedmanDiaconis = function (values, min, max) {
253 values = map.call(values, number).sort(ascending);
254 return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
255};
256
257var scott = function (values, min, max) {
258 return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
259};
260
261var max = function (array, f) {
262 var i = -1,
263 n = array.length,
264 a,
265 b;
266
267 if (f == null) {
268 while (++i < n) {
269 if ((b = array[i]) != null && b >= b) {
270 a = b;break;
271 }
272 }while (++i < n) {
273 if ((b = array[i]) != null && b > a) a = b;
274 }
275 } else {
276 while (++i < n) {
277 if ((b = f(array[i], i, array)) != null && b >= b) {
278 a = b;break;
279 }
280 }while (++i < n) {
281 if ((b = f(array[i], i, array)) != null && b > a) a = b;
282 }
283 }
284
285 return a;
286};
287
288var mean = function (array, f) {
289 var s = 0,
290 n = array.length,
291 a,
292 i = -1,
293 j = n;
294
295 if (f == null) {
296 while (++i < n) {
297 if (!isNaN(a = number(array[i]))) s += a;else --j;
298 }
299 } else {
300 while (++i < n) {
301 if (!isNaN(a = number(f(array[i], i, array)))) s += a;else --j;
302 }
303 }
304
305 if (j) return s / j;
306};
307
308var median = function (array, f) {
309 var numbers = [],
310 n = array.length,
311 a,
312 i = -1;
313
314 if (f == null) {
315 while (++i < n) {
316 if (!isNaN(a = number(array[i]))) numbers.push(a);
317 }
318 } else {
319 while (++i < n) {
320 if (!isNaN(a = number(f(array[i], i, array)))) numbers.push(a);
321 }
322 }
323
324 return threshold(numbers.sort(ascending), 0.5);
325};
326
327var merge = function (arrays) {
328 var n = arrays.length,
329 m,
330 i = -1,
331 j = 0,
332 merged,
333 array;
334
335 while (++i < n) {
336 j += arrays[i].length;
337 }merged = new Array(j);
338
339 while (--n >= 0) {
340 array = arrays[n];
341 m = array.length;
342 while (--m >= 0) {
343 merged[--j] = array[m];
344 }
345 }
346
347 return merged;
348};
349
350var min = function (array, f) {
351 var i = -1,
352 n = array.length,
353 a,
354 b;
355
356 if (f == null) {
357 while (++i < n) {
358 if ((b = array[i]) != null && b >= b) {
359 a = b;break;
360 }
361 }while (++i < n) {
362 if ((b = array[i]) != null && a > b) a = b;
363 }
364 } else {
365 while (++i < n) {
366 if ((b = f(array[i], i, array)) != null && b >= b) {
367 a = b;break;
368 }
369 }while (++i < n) {
370 if ((b = f(array[i], i, array)) != null && a > b) a = b;
371 }
372 }
373
374 return a;
375};
376
377var pairs = function (array) {
378 var i = 0,
379 n = array.length - 1,
380 p = array[0],
381 pairs = new Array(n < 0 ? 0 : n);
382 while (i < n) {
383 pairs[i] = [p, p = array[++i]];
384 }return pairs;
385};
386
387var permute = function (array, indexes) {
388 var i = indexes.length,
389 permutes = new Array(i);
390 while (i--) {
391 permutes[i] = array[indexes[i]];
392 }return permutes;
393};
394
395var scan = function (array, compare) {
396 if (!(n = array.length)) return;
397 var i = 0,
398 n,
399 j = 0,
400 xi,
401 xj = array[j];
402
403 if (!compare) compare = ascending;
404
405 while (++i < n) {
406 if (compare(xi = array[i], xj) < 0 || compare(xj, xj) !== 0) xj = xi, j = i;
407 }if (compare(xj, xj) === 0) return j;
408};
409
410var shuffle = function (array, i0, i1) {
411 var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
412 t,
413 i;
414
415 while (m) {
416 i = Math.random() * m-- | 0;
417 t = array[m + i0];
418 array[m + i0] = array[i + i0];
419 array[i + i0] = t;
420 }
421
422 return array;
423};
424
425var sum = function (array, f) {
426 var s = 0,
427 n = array.length,
428 a,
429 i = -1;
430
431 if (f == null) {
432 while (++i < n) {
433 if (a = +array[i]) s += a;
434 } // Note: zero and null are equivalent.
435 } else {
436 while (++i < n) {
437 if (a = +f(array[i], i, array)) s += a;
438 }
439 }
440
441 return s;
442};
443
444var transpose = function (matrix) {
445 if (!(n = matrix.length)) return [];
446 for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
447 for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
448 row[j] = matrix[j][i];
449 }
450 }
451 return transpose;
452};
453
454function length(d) {
455 return d.length;
456}
457
458var zip = function () {
459 return transpose(arguments);
460};
461
462var prefix = "$";
463
464function Map() {}
465
466Map.prototype = map$1.prototype = {
467 constructor: Map,
468 has: function has(key) {
469 return prefix + key in this;
470 },
471 get: function get(key) {
472 return this[prefix + key];
473 },
474 set: function set(key, value) {
475 this[prefix + key] = value;
476 return this;
477 },
478 remove: function remove(key) {
479 var property = prefix + key;
480 return property in this && delete this[property];
481 },
482 clear: function clear() {
483 for (var property in this) {
484 if (property[0] === prefix) delete this[property];
485 }
486 },
487 keys: function keys() {
488 var keys = [];
489 for (var property in this) {
490 if (property[0] === prefix) keys.push(property.slice(1));
491 }return keys;
492 },
493 values: function values() {
494 var values = [];
495 for (var property in this) {
496 if (property[0] === prefix) values.push(this[property]);
497 }return values;
498 },
499 entries: function entries() {
500 var entries = [];
501 for (var property in this) {
502 if (property[0] === prefix) entries.push({ key: property.slice(1), value: this[property] });
503 }return entries;
504 },
505 size: function size() {
506 var size = 0;
507 for (var property in this) {
508 if (property[0] === prefix) ++size;
509 }return size;
510 },
511 empty: function empty() {
512 for (var property in this) {
513 if (property[0] === prefix) return false;
514 }return true;
515 },
516 each: function each(f) {
517 for (var property in this) {
518 if (property[0] === prefix) f(this[property], property.slice(1), this);
519 }
520 }
521};
522
523function map$1(object, f) {
524 var map = new Map();
525
526 // Copy constructor.
527 if (object instanceof Map) object.each(function (value, key) {
528 map.set(key, value);
529 });
530
531 // Index array by numeric index or specified key function.
532 else if (Array.isArray(object)) {
533 var i = -1,
534 n = object.length,
535 o;
536
537 if (f == null) while (++i < n) {
538 map.set(i, object[i]);
539 } else while (++i < n) {
540 map.set(f(o = object[i], i, object), o);
541 }
542 }
543
544 // Convert object to map.
545 else if (object) for (var key in object) {
546 map.set(key, object[key]);
547 }return map;
548}
549
550var nest = function () {
551 var keys = [],
552 _sortKeys = [],
553 _sortValues,
554 _rollup,
555 nest;
556
557 function apply(array, depth, createResult, setResult) {
558 if (depth >= keys.length) return _rollup != null ? _rollup(array) : _sortValues != null ? array.sort(_sortValues) : array;
559
560 var i = -1,
561 n = array.length,
562 key = keys[depth++],
563 keyValue,
564 value,
565 valuesByKey = map$1(),
566 values,
567 result = createResult();
568
569 while (++i < n) {
570 if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
571 values.push(value);
572 } else {
573 valuesByKey.set(keyValue, [value]);
574 }
575 }
576
577 valuesByKey.each(function (values, key) {
578 setResult(result, key, apply(values, depth, createResult, setResult));
579 });
580
581 return result;
582 }
583
584 function _entries(map, depth) {
585 if (++depth > keys.length) return map;
586 var array,
587 sortKey = _sortKeys[depth - 1];
588 if (_rollup != null && depth >= keys.length) array = map.entries();else array = [], map.each(function (v, k) {
589 array.push({ key: k, values: _entries(v, depth) });
590 });
591 return sortKey != null ? array.sort(function (a, b) {
592 return sortKey(a.key, b.key);
593 }) : array;
594 }
595
596 return nest = {
597 object: function object(array) {
598 return apply(array, 0, createObject, setObject);
599 },
600 map: function map$1(array) {
601 return apply(array, 0, createMap, setMap);
602 },
603 entries: function entries(array) {
604 return _entries(apply(array, 0, createMap, setMap), 0);
605 },
606 key: function key(d) {
607 keys.push(d);return nest;
608 },
609 sortKeys: function sortKeys(order) {
610 _sortKeys[keys.length - 1] = order;return nest;
611 },
612 sortValues: function sortValues(order) {
613 _sortValues = order;return nest;
614 },
615 rollup: function rollup(f) {
616 _rollup = f;return nest;
617 }
618 };
619};
620
621function createObject() {
622 return {};
623}
624
625function setObject(object, key, value) {
626 object[key] = value;
627}
628
629function createMap() {
630 return map$1();
631}
632
633function setMap(map, key, value) {
634 map.set(key, value);
635}
636
637function Set() {}
638
639var proto = map$1.prototype;
640
641Set.prototype = set$1.prototype = {
642 constructor: Set,
643 has: proto.has,
644 add: function add(value) {
645 value += "";
646 this[prefix + value] = value;
647 return this;
648 },
649 remove: proto.remove,
650 clear: proto.clear,
651 values: proto.keys,
652 size: proto.size,
653 empty: proto.empty,
654 each: proto.each
655};
656
657function set$1(object, f) {
658 var set = new Set();
659
660 // Copy constructor.
661 if (object instanceof Set) object.each(function (value) {
662 set.add(value);
663 });
664
665 // Otherwise, assume it’s an array.
666 else if (object) {
667 var i = -1,
668 n = object.length;
669 if (f == null) while (++i < n) {
670 set.add(object[i]);
671 } else while (++i < n) {
672 set.add(f(object[i], i, object));
673 }
674 }
675
676 return set;
677}
678
679var keys$1 = function (map) {
680 var keys = [];
681 for (var key in map) {
682 keys.push(key);
683 }return keys;
684};
685
686var values$1 = function (map) {
687 var values = [];
688 for (var key in map) {
689 values.push(map[key]);
690 }return values;
691};
692
693var entries$1 = function (map) {
694 var entries = [];
695 for (var key in map) {
696 entries.push({ key: key, value: map[key] });
697 }return entries;
698};
699
700var uniform = function (min, max) {
701 min = min == null ? 0 : +min;
702 max = max == null ? 1 : +max;
703 if (arguments.length === 1) max = min, min = 0;else max -= min;
704 return function () {
705 return Math.random() * max + min;
706 };
707};
708
709var normal = function (mu, sigma) {
710 var x, r;
711 mu = mu == null ? 0 : +mu;
712 sigma = sigma == null ? 1 : +sigma;
713 return function () {
714 var y;
715
716 // If available, use the second previously-generated uniform random.
717 if (x != null) y = x, x = null;
718
719 // Otherwise, generate a new x and y.
720 else do {
721 x = Math.random() * 2 - 1;
722 y = Math.random() * 2 - 1;
723 r = x * x + y * y;
724 } while (!r || r > 1);
725
726 return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
727 };
728};
729
730var logNormal = function () {
731 var randomNormal = normal.apply(this, arguments);
732 return function () {
733 return Math.exp(randomNormal());
734 };
735};
736
737var irwinHall = function (n) {
738 return function () {
739 for (var sum = 0, i = 0; i < n; ++i) {
740 sum += Math.random();
741 }return sum;
742 };
743};
744
745var bates = function (n) {
746 var randomIrwinHall = irwinHall(n);
747 return function () {
748 return randomIrwinHall() / n;
749 };
750};
751
752var exponential = function (lambda) {
753 return function () {
754 return -Math.log(1 - Math.random()) / lambda;
755 };
756};
757
758function linear(t) {
759 return +t;
760}
761
762function quadIn(t) {
763 return t * t;
764}
765
766function quadOut(t) {
767 return t * (2 - t);
768}
769
770function quadInOut(t) {
771 return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
772}
773
774function cubicIn(t) {
775 return t * t * t;
776}
777
778function cubicOut(t) {
779 return --t * t * t + 1;
780}
781
782function cubicInOut(t) {
783 return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
784}
785
786var exponent = 3;
787
788var polyIn = function custom(e) {
789 e = +e;
790
791 function polyIn(t) {
792 return Math.pow(t, e);
793 }
794
795 polyIn.exponent = custom;
796
797 return polyIn;
798}(exponent);
799
800var polyOut = function custom(e) {
801 e = +e;
802
803 function polyOut(t) {
804 return 1 - Math.pow(1 - t, e);
805 }
806
807 polyOut.exponent = custom;
808
809 return polyOut;
810}(exponent);
811
812var polyInOut = function custom(e) {
813 e = +e;
814
815 function polyInOut(t) {
816 return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
817 }
818
819 polyInOut.exponent = custom;
820
821 return polyInOut;
822}(exponent);
823
824var pi = Math.PI;
825var halfPi = pi / 2;
826
827function sinIn(t) {
828 return 1 - Math.cos(t * halfPi);
829}
830
831function sinOut(t) {
832 return Math.sin(t * halfPi);
833}
834
835function sinInOut(t) {
836 return (1 - Math.cos(pi * t)) / 2;
837}
838
839function expIn(t) {
840 return Math.pow(2, 10 * t - 10);
841}
842
843function expOut(t) {
844 return 1 - Math.pow(2, -10 * t);
845}
846
847function expInOut(t) {
848 return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
849}
850
851function circleIn(t) {
852 return 1 - Math.sqrt(1 - t * t);
853}
854
855function circleOut(t) {
856 return Math.sqrt(1 - --t * t);
857}
858
859function circleInOut(t) {
860 return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
861}
862
863var b1 = 4 / 11;
864var b2 = 6 / 11;
865var b3 = 8 / 11;
866var b4 = 3 / 4;
867var b5 = 9 / 11;
868var b6 = 10 / 11;
869var b7 = 15 / 16;
870var b8 = 21 / 22;
871var b9 = 63 / 64;
872var b0 = 1 / b1 / b1;
873
874function bounceIn(t) {
875 return 1 - bounceOut(1 - t);
876}
877
878function bounceOut(t) {
879 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;
880}
881
882function bounceInOut(t) {
883 return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
884}
885
886var overshoot = 1.70158;
887
888var backIn = function custom(s) {
889 s = +s;
890
891 function backIn(t) {
892 return t * t * ((s + 1) * t - s);
893 }
894
895 backIn.overshoot = custom;
896
897 return backIn;
898}(overshoot);
899
900var backOut = function custom(s) {
901 s = +s;
902
903 function backOut(t) {
904 return --t * t * ((s + 1) * t + s) + 1;
905 }
906
907 backOut.overshoot = custom;
908
909 return backOut;
910}(overshoot);
911
912var backInOut = function custom(s) {
913 s = +s;
914
915 function backInOut(t) {
916 return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
917 }
918
919 backInOut.overshoot = custom;
920
921 return backInOut;
922}(overshoot);
923
924var tau = 2 * Math.PI;
925var amplitude = 1;
926var period = 0.3;
927
928var elasticIn = function custom(a, p) {
929 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
930
931 function elasticIn(t) {
932 return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
933 }
934
935 elasticIn.amplitude = function (a) {
936 return custom(a, p * tau);
937 };
938 elasticIn.period = function (p) {
939 return custom(a, p);
940 };
941
942 return elasticIn;
943}(amplitude, period);
944
945var elasticOut = function custom(a, p) {
946 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
947
948 function elasticOut(t) {
949 return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
950 }
951
952 elasticOut.amplitude = function (a) {
953 return custom(a, p * tau);
954 };
955 elasticOut.period = function (p) {
956 return custom(a, p);
957 };
958
959 return elasticOut;
960}(amplitude, period);
961
962var elasticInOut = function custom(a, p) {
963 var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
964
965 function elasticInOut(t) {
966 return ((t = t * 2 - 1) < 0 ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p) : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
967 }
968
969 elasticInOut.amplitude = function (a) {
970 return custom(a, p * tau);
971 };
972 elasticInOut.period = function (p) {
973 return custom(a, p);
974 };
975
976 return elasticInOut;
977}(amplitude, period);
978
979var area = function (polygon) {
980 var i = -1,
981 n = polygon.length,
982 a,
983 b = polygon[n - 1],
984 area = 0;
985
986 while (++i < n) {
987 a = b;
988 b = polygon[i];
989 area += a[1] * b[0] - a[0] * b[1];
990 }
991
992 return area / 2;
993};
994
995var centroid = function (polygon) {
996 var i = -1,
997 n = polygon.length,
998 x = 0,
999 y = 0,
1000 a,
1001 b = polygon[n - 1],
1002 c,
1003 k = 0;
1004
1005 while (++i < n) {
1006 a = b;
1007 b = polygon[i];
1008 k += c = a[0] * b[1] - b[0] * a[1];
1009 x += (a[0] + b[0]) * c;
1010 y += (a[1] + b[1]) * c;
1011 }
1012
1013 return k *= 3, [x / k, y / k];
1014};
1015
1016// Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
1017// the 3D cross product in a quadrant I Cartesian coordinate system (+x is
1018// right, +y is up). Returns a positive value if ABC is counter-clockwise,
1019// negative if clockwise, and zero if the points are collinear.
1020var cross = function (a, b, c) {
1021 return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
1022};
1023
1024function lexicographicOrder(a, b) {
1025 return a[0] - b[0] || a[1] - b[1];
1026}
1027
1028// Computes the upper convex hull per the monotone chain algorithm.
1029// Assumes points.length >= 3, is sorted by x, unique in y.
1030// Returns an array of indices into points in left-to-right order.
1031function computeUpperHullIndexes(points) {
1032 var n = points.length,
1033 indexes = [0, 1],
1034 size = 2;
1035
1036 for (var i = 2; i < n; ++i) {
1037 while (size > 1 && cross(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) {
1038 --size;
1039 }indexes[size++] = i;
1040 }
1041
1042 return indexes.slice(0, size); // remove popped points
1043}
1044
1045var hull = function (points) {
1046 if ((n = points.length) < 3) return null;
1047
1048 var i,
1049 n,
1050 sortedPoints = new Array(n),
1051 flippedPoints = new Array(n);
1052
1053 for (i = 0; i < n; ++i) {
1054 sortedPoints[i] = [+points[i][0], +points[i][1], i];
1055 }sortedPoints.sort(lexicographicOrder);
1056 for (i = 0; i < n; ++i) {
1057 flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
1058 }var upperIndexes = computeUpperHullIndexes(sortedPoints),
1059 lowerIndexes = computeUpperHullIndexes(flippedPoints);
1060
1061 // Construct the hull polygon, removing possible duplicate endpoints.
1062 var skipLeft = lowerIndexes[0] === upperIndexes[0],
1063 skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
1064 hull = [];
1065
1066 // Add upper hull in right-to-l order.
1067 // Then add lower hull in left-to-right order.
1068 for (i = upperIndexes.length - 1; i >= 0; --i) {
1069 hull.push(points[sortedPoints[upperIndexes[i]][2]]);
1070 }for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) {
1071 hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
1072 }return hull;
1073};
1074
1075var contains$1 = function (polygon, point) {
1076 var n = polygon.length,
1077 p = polygon[n - 1],
1078 x = point[0],
1079 y = point[1],
1080 x0 = p[0],
1081 y0 = p[1],
1082 x1,
1083 y1,
1084 inside = false;
1085
1086 for (var i = 0; i < n; ++i) {
1087 p = polygon[i], x1 = p[0], y1 = p[1];
1088 if (y1 > y !== y0 > y && x < (x0 - x1) * (y - y1) / (y0 - y1) + x1) inside = !inside;
1089 x0 = x1, y0 = y1;
1090 }
1091
1092 return inside;
1093};
1094
1095var length$1 = function (polygon) {
1096 var i = -1,
1097 n = polygon.length,
1098 b = polygon[n - 1],
1099 xa,
1100 ya,
1101 xb = b[0],
1102 yb = b[1],
1103 perimeter = 0;
1104
1105 while (++i < n) {
1106 xa = xb;
1107 ya = yb;
1108 b = polygon[i];
1109 xb = b[0];
1110 yb = b[1];
1111 xa -= xb;
1112 ya -= yb;
1113 perimeter += Math.sqrt(xa * xa + ya * ya);
1114 }
1115
1116 return perimeter;
1117};
1118
1119var pi$1 = Math.PI;
1120var tau$1 = 2 * pi$1;
1121var epsilon = 1e-6;
1122var tauEpsilon = tau$1 - epsilon;
1123
1124function Path() {
1125 this._x0 = this._y0 = // start of current subpath
1126 this._x1 = this._y1 = null; // end of current subpath
1127 this._ = "";
1128}
1129
1130function path() {
1131 return new Path();
1132}
1133
1134Path.prototype = path.prototype = {
1135 constructor: Path,
1136 moveTo: function moveTo(x, y) {
1137 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
1138 },
1139 closePath: function closePath() {
1140 if (this._x1 !== null) {
1141 this._x1 = this._x0, this._y1 = this._y0;
1142 this._ += "Z";
1143 }
1144 },
1145 lineTo: function lineTo(x, y) {
1146 this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
1147 },
1148 quadraticCurveTo: function quadraticCurveTo(x1, y1, x, y) {
1149 this._ += "Q" + +x1 + "," + +y1 + "," + (this._x1 = +x) + "," + (this._y1 = +y);
1150 },
1151 bezierCurveTo: function bezierCurveTo(x1, y1, x2, y2, x, y) {
1152 this._ += "C" + +x1 + "," + +y1 + "," + +x2 + "," + +y2 + "," + (this._x1 = +x) + "," + (this._y1 = +y);
1153 },
1154 arcTo: function arcTo(x1, y1, x2, y2, r) {
1155 x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
1156 var x0 = this._x1,
1157 y0 = this._y1,
1158 x21 = x2 - x1,
1159 y21 = y2 - y1,
1160 x01 = x0 - x1,
1161 y01 = y0 - y1,
1162 l01_2 = x01 * x01 + y01 * y01;
1163
1164 // Is the radius negative? Error.
1165 if (r < 0) throw new Error("negative radius: " + r);
1166
1167 // Is this path empty? Move to (x1,y1).
1168 if (this._x1 === null) {
1169 this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
1170 }
1171
1172 // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
1173 else if (!(l01_2 > epsilon)) {}
1174
1175 // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
1176 // Equivalently, is (x1,y1) coincident with (x2,y2)?
1177 // Or, is the radius zero? Line to (x1,y1).
1178 else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon) || !r) {
1179 this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
1180 }
1181
1182 // Otherwise, draw an arc!
1183 else {
1184 var x20 = x2 - x0,
1185 y20 = y2 - y0,
1186 l21_2 = x21 * x21 + y21 * y21,
1187 l20_2 = x20 * x20 + y20 * y20,
1188 l21 = Math.sqrt(l21_2),
1189 l01 = Math.sqrt(l01_2),
1190 l = r * Math.tan((pi$1 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
1191 t01 = l / l01,
1192 t21 = l / l21;
1193
1194 // If the start tangent is not coincident with (x0,y0), line to.
1195 if (Math.abs(t01 - 1) > epsilon) {
1196 this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
1197 }
1198
1199 this._ += "A" + r + "," + r + ",0,0," + +(y01 * x20 > x01 * y20) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
1200 }
1201 },
1202 arc: function arc(x, y, r, a0, a1, ccw) {
1203 x = +x, y = +y, r = +r;
1204 var dx = r * Math.cos(a0),
1205 dy = r * Math.sin(a0),
1206 x0 = x + dx,
1207 y0 = y + dy,
1208 cw = 1 ^ ccw,
1209 da = ccw ? a0 - a1 : a1 - a0;
1210
1211 // Is the radius negative? Error.
1212 if (r < 0) throw new Error("negative radius: " + r);
1213
1214 // Is this path empty? Move to (x0,y0).
1215 if (this._x1 === null) {
1216 this._ += "M" + x0 + "," + y0;
1217 }
1218
1219 // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0).
1220 else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) {
1221 this._ += "L" + x0 + "," + y0;
1222 }
1223
1224 // Is this arc empty? We’re done.
1225 if (!r) return;
1226
1227 // Is this a complete circle? Draw two arcs to complete the circle.
1228 if (da > tauEpsilon) {
1229 this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
1230 }
1231
1232 // Otherwise, draw an arc!
1233 else {
1234 if (da < 0) da = da % tau$1 + tau$1;
1235 this._ += "A" + r + "," + r + ",0," + +(da >= pi$1) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
1236 }
1237 },
1238 rect: function rect(x, y, w, h) {
1239 this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + +w + "v" + +h + "h" + -w + "Z";
1240 },
1241 toString: function toString() {
1242 return this._;
1243 }
1244};
1245
1246var tree_add = function (d) {
1247 var x = +this._x.call(null, d),
1248 y = +this._y.call(null, d);
1249 return add$1(this.cover(x, y), x, y, d);
1250};
1251
1252function add$1(tree, x, y, d) {
1253 if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
1254
1255 var parent,
1256 node = tree._root,
1257 leaf = { data: d },
1258 x0 = tree._x0,
1259 y0 = tree._y0,
1260 x1 = tree._x1,
1261 y1 = tree._y1,
1262 xm,
1263 ym,
1264 xp,
1265 yp,
1266 right,
1267 bottom,
1268 i,
1269 j;
1270
1271 // If the tree is empty, initialize the root as a leaf.
1272 if (!node) return tree._root = leaf, tree;
1273
1274 // Find the existing leaf for the new point, or add it.
1275 while (node.length) {
1276 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm;else x1 = xm;
1277 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym;else y1 = ym;
1278 if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
1279 }
1280
1281 // Is the new point is exactly coincident with the existing point?
1282 xp = +tree._x.call(null, node.data);
1283 yp = +tree._y.call(null, node.data);
1284 if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
1285
1286 // Otherwise, split the leaf node until the old and new point are separated.
1287 do {
1288 parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
1289 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm;else x1 = xm;
1290 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym;else y1 = ym;
1291 } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | xp >= xm));
1292 return parent[j] = node, parent[i] = leaf, tree;
1293}
1294
1295function addAll(data) {
1296 var d,
1297 i,
1298 n = data.length,
1299 x,
1300 y,
1301 xz = new Array(n),
1302 yz = new Array(n),
1303 x0 = Infinity,
1304 y0 = Infinity,
1305 x1 = -Infinity,
1306 y1 = -Infinity;
1307
1308 // Compute the points and their extent.
1309 for (i = 0; i < n; ++i) {
1310 if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
1311 xz[i] = x;
1312 yz[i] = y;
1313 if (x < x0) x0 = x;
1314 if (x > x1) x1 = x;
1315 if (y < y0) y0 = y;
1316 if (y > y1) y1 = y;
1317 }
1318
1319 // If there were no (valid) points, inherit the existing extent.
1320 if (x1 < x0) x0 = this._x0, x1 = this._x1;
1321 if (y1 < y0) y0 = this._y0, y1 = this._y1;
1322
1323 // Expand the tree to cover the new points.
1324 this.cover(x0, y0).cover(x1, y1);
1325
1326 // Add the new points.
1327 for (i = 0; i < n; ++i) {
1328 add$1(this, xz[i], yz[i], data[i]);
1329 }
1330
1331 return this;
1332}
1333
1334var tree_cover = function (x, y) {
1335 if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
1336
1337 var x0 = this._x0,
1338 y0 = this._y0,
1339 x1 = this._x1,
1340 y1 = this._y1;
1341
1342 // If the quadtree has no extent, initialize them.
1343 // Integer extent are necessary so that if we later double the extent,
1344 // the existing quadrant boundaries don’t change due to floating point error!
1345 if (isNaN(x0)) {
1346 x1 = (x0 = Math.floor(x)) + 1;
1347 y1 = (y0 = Math.floor(y)) + 1;
1348 }
1349
1350 // Otherwise, double repeatedly to cover.
1351 else if (x0 > x || x > x1 || y0 > y || y > y1) {
1352 var z = x1 - x0,
1353 node = this._root,
1354 parent,
1355 i;
1356
1357 switch (i = (y < (y0 + y1) / 2) << 1 | x < (x0 + x1) / 2) {
1358 case 0:
1359 {
1360 do {
1361 parent = new Array(4), parent[i] = node, node = parent;
1362 } while ((z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1));
1363 break;
1364 }
1365 case 1:
1366 {
1367 do {
1368 parent = new Array(4), parent[i] = node, node = parent;
1369 } while ((z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1));
1370 break;
1371 }
1372 case 2:
1373 {
1374 do {
1375 parent = new Array(4), parent[i] = node, node = parent;
1376 } while ((z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y));
1377 break;
1378 }
1379 case 3:
1380 {
1381 do {
1382 parent = new Array(4), parent[i] = node, node = parent;
1383 } while ((z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y));
1384 break;
1385 }
1386 }
1387
1388 if (this._root && this._root.length) this._root = node;
1389 }
1390
1391 // If the quadtree covers the point already, just return.
1392 else return this;
1393
1394 this._x0 = x0;
1395 this._y0 = y0;
1396 this._x1 = x1;
1397 this._y1 = y1;
1398 return this;
1399};
1400
1401var tree_data = function () {
1402 var data = [];
1403 this.visit(function (node) {
1404 if (!node.length) do {
1405 data.push(node.data);
1406 } while (node = node.next);
1407 });
1408 return data;
1409};
1410
1411var tree_extent = function (_) {
1412 return arguments.length ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1]) : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
1413};
1414
1415var Quad = function (node, x0, y0, x1, y1) {
1416 this.node = node;
1417 this.x0 = x0;
1418 this.y0 = y0;
1419 this.x1 = x1;
1420 this.y1 = y1;
1421};
1422
1423var tree_find = function (x, y, radius) {
1424 var data,
1425 x0 = this._x0,
1426 y0 = this._y0,
1427 x1,
1428 y1,
1429 x2,
1430 y2,
1431 x3 = this._x1,
1432 y3 = this._y1,
1433 quads = [],
1434 node = this._root,
1435 q,
1436 i;
1437
1438 if (node) quads.push(new Quad(node, x0, y0, x3, y3));
1439 if (radius == null) radius = Infinity;else {
1440 x0 = x - radius, y0 = y - radius;
1441 x3 = x + radius, y3 = y + radius;
1442 radius *= radius;
1443 }
1444
1445 while (q = quads.pop()) {
1446
1447 // Stop searching if this quadrant can’t contain a closer node.
1448 if (!(node = q.node) || (x1 = q.x0) > x3 || (y1 = q.y0) > y3 || (x2 = q.x1) < x0 || (y2 = q.y1) < y0) continue;
1449
1450 // Bisect the current quadrant.
1451 if (node.length) {
1452 var xm = (x1 + x2) / 2,
1453 ym = (y1 + y2) / 2;
1454
1455 quads.push(new Quad(node[3], xm, ym, x2, y2), new Quad(node[2], x1, ym, xm, y2), new Quad(node[1], xm, y1, x2, ym), new Quad(node[0], x1, y1, xm, ym));
1456
1457 // Visit the closest quadrant first.
1458 if (i = (y >= ym) << 1 | x >= xm) {
1459 q = quads[quads.length - 1];
1460 quads[quads.length - 1] = quads[quads.length - 1 - i];
1461 quads[quads.length - 1 - i] = q;
1462 }
1463 }
1464
1465 // Visit this point. (Visiting coincident points isn’t necessary!)
1466 else {
1467 var dx = x - +this._x.call(null, node.data),
1468 dy = y - +this._y.call(null, node.data),
1469 d2 = dx * dx + dy * dy;
1470 if (d2 < radius) {
1471 var d = Math.sqrt(radius = d2);
1472 x0 = x - d, y0 = y - d;
1473 x3 = x + d, y3 = y + d;
1474 data = node.data;
1475 }
1476 }
1477 }
1478
1479 return data;
1480};
1481
1482var tree_remove = function (d) {
1483 if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
1484
1485 var parent,
1486 node = this._root,
1487 retainer,
1488 previous,
1489 next,
1490 x0 = this._x0,
1491 y0 = this._y0,
1492 x1 = this._x1,
1493 y1 = this._y1,
1494 x,
1495 y,
1496 xm,
1497 ym,
1498 right,
1499 bottom,
1500 i,
1501 j;
1502
1503 // If the tree is empty, initialize the root as a leaf.
1504 if (!node) return this;
1505
1506 // Find the leaf node for the point.
1507 // While descending, also retain the deepest parent with a non-removed sibling.
1508 if (node.length) while (true) {
1509 if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm;else x1 = xm;
1510 if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym;else y1 = ym;
1511 if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
1512 if (!node.length) break;
1513 if (parent[i + 1 & 3] || parent[i + 2 & 3] || parent[i + 3 & 3]) retainer = parent, j = i;
1514 }
1515
1516 // Find the point to remove.
1517 while (node.data !== d) {
1518 if (!(previous = node, node = node.next)) return this;
1519 }if (next = node.next) delete node.next;
1520
1521 // If there are multiple coincident points, remove just the point.
1522 if (previous) return next ? previous.next = next : delete previous.next, this;
1523
1524 // If this is the root point, remove it.
1525 if (!parent) return this._root = next, this;
1526
1527 // Remove this leaf.
1528 next ? parent[i] = next : delete parent[i];
1529
1530 // If the parent now contains exactly one leaf, collapse superfluous parents.
1531 if ((node = parent[0] || parent[1] || parent[2] || parent[3]) && node === (parent[3] || parent[2] || parent[1] || parent[0]) && !node.length) {
1532 if (retainer) retainer[j] = node;else this._root = node;
1533 }
1534
1535 return this;
1536};
1537
1538function removeAll(data) {
1539 for (var i = 0, n = data.length; i < n; ++i) {
1540 this.remove(data[i]);
1541 }return this;
1542}
1543
1544var tree_root = function () {
1545 return this._root;
1546};
1547
1548var tree_size = function () {
1549 var size = 0;
1550 this.visit(function (node) {
1551 if (!node.length) do {
1552 ++size;
1553 } while (node = node.next);
1554 });
1555 return size;
1556};
1557
1558var tree_visit = function (callback) {
1559 var quads = [],
1560 q,
1561 node = this._root,
1562 child,
1563 x0,
1564 y0,
1565 x1,
1566 y1;
1567 if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
1568 while (q = quads.pop()) {
1569 if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
1570 var xm = (x0 + x1) / 2,
1571 ym = (y0 + y1) / 2;
1572 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
1573 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
1574 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
1575 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
1576 }
1577 }
1578 return this;
1579};
1580
1581var tree_visitAfter = function (callback) {
1582 var quads = [],
1583 next = [],
1584 q;
1585 if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
1586 while (q = quads.pop()) {
1587 var node = q.node;
1588 if (node.length) {
1589 var child,
1590 x0 = q.x0,
1591 y0 = q.y0,
1592 x1 = q.x1,
1593 y1 = q.y1,
1594 xm = (x0 + x1) / 2,
1595 ym = (y0 + y1) / 2;
1596 if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
1597 if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
1598 if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
1599 if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
1600 }
1601 next.push(q);
1602 }
1603 while (q = next.pop()) {
1604 callback(q.node, q.x0, q.y0, q.x1, q.y1);
1605 }
1606 return this;
1607};
1608
1609function defaultX(d) {
1610 return d[0];
1611}
1612
1613var tree_x = function (_) {
1614 return arguments.length ? (this._x = _, this) : this._x;
1615};
1616
1617function defaultY(d) {
1618 return d[1];
1619}
1620
1621var tree_y = function (_) {
1622 return arguments.length ? (this._y = _, this) : this._y;
1623};
1624
1625function quadtree(nodes, x, y) {
1626 var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
1627 return nodes == null ? tree : tree.addAll(nodes);
1628}
1629
1630function Quadtree(x, y, x0, y0, x1, y1) {
1631 this._x = x;
1632 this._y = y;
1633 this._x0 = x0;
1634 this._y0 = y0;
1635 this._x1 = x1;
1636 this._y1 = y1;
1637 this._root = undefined;
1638}
1639
1640function leaf_copy(leaf) {
1641 var copy = { data: leaf.data },
1642 next = copy;
1643 while (leaf = leaf.next) {
1644 next = next.next = { data: leaf.data };
1645 }return copy;
1646}
1647
1648var treeProto = quadtree.prototype = Quadtree.prototype;
1649
1650treeProto.copy = function () {
1651 var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
1652 node = this._root,
1653 nodes,
1654 child;
1655
1656 if (!node) return copy;
1657
1658 if (!node.length) return copy._root = leaf_copy(node), copy;
1659
1660 nodes = [{ source: node, target: copy._root = new Array(4) }];
1661 while (node = nodes.pop()) {
1662 for (var i = 0; i < 4; ++i) {
1663 if (child = node.source[i]) {
1664 if (child.length) nodes.push({ source: child, target: node.target[i] = new Array(4) });else node.target[i] = leaf_copy(child);
1665 }
1666 }
1667 }
1668
1669 return copy;
1670};
1671
1672treeProto.add = tree_add;
1673treeProto.addAll = addAll;
1674treeProto.cover = tree_cover;
1675treeProto.data = tree_data;
1676treeProto.extent = tree_extent;
1677treeProto.find = tree_find;
1678treeProto.remove = tree_remove;
1679treeProto.removeAll = removeAll;
1680treeProto.root = tree_root;
1681treeProto.size = tree_size;
1682treeProto.visit = tree_visit;
1683treeProto.visitAfter = tree_visitAfter;
1684treeProto.x = tree_x;
1685treeProto.y = tree_y;
1686
1687var constant$2 = function (x) {
1688 return function constant() {
1689 return x;
1690 };
1691};
1692
1693var epsilon$1 = 1e-12;
1694var pi$2 = Math.PI;
1695var halfPi$1 = pi$2 / 2;
1696var tau$2 = 2 * pi$2;
1697
1698function arcInnerRadius(d) {
1699 return d.innerRadius;
1700}
1701
1702function arcOuterRadius(d) {
1703 return d.outerRadius;
1704}
1705
1706function arcStartAngle(d) {
1707 return d.startAngle;
1708}
1709
1710function arcEndAngle(d) {
1711 return d.endAngle;
1712}
1713
1714function arcPadAngle(d) {
1715 return d && d.padAngle; // Note: optional!
1716}
1717
1718function asin(x) {
1719 return x >= 1 ? halfPi$1 : x <= -1 ? -halfPi$1 : Math.asin(x);
1720}
1721
1722function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
1723 var x10 = x1 - x0,
1724 y10 = y1 - y0,
1725 x32 = x3 - x2,
1726 y32 = y3 - y2,
1727 t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
1728 return [x0 + t * x10, y0 + t * y10];
1729}
1730
1731// Compute perpendicular offset line of length rc.
1732// http://mathworld.wolfram.com/Circle-LineIntersection.html
1733function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
1734 var x01 = x0 - x1,
1735 y01 = y0 - y1,
1736 lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01),
1737 ox = lo * y01,
1738 oy = -lo * x01,
1739 x11 = x0 + ox,
1740 y11 = y0 + oy,
1741 x10 = x1 + ox,
1742 y10 = y1 + oy,
1743 x00 = (x11 + x10) / 2,
1744 y00 = (y11 + y10) / 2,
1745 dx = x10 - x11,
1746 dy = y10 - y11,
1747 d2 = dx * dx + dy * dy,
1748 r = r1 - rc,
1749 D = x11 * y10 - x10 * y11,
1750 d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)),
1751 cx0 = (D * dy - dx * d) / d2,
1752 cy0 = (-D * dx - dy * d) / d2,
1753 cx1 = (D * dy + dx * d) / d2,
1754 cy1 = (-D * dx + dy * d) / d2,
1755 dx0 = cx0 - x00,
1756 dy0 = cy0 - y00,
1757 dx1 = cx1 - x00,
1758 dy1 = cy1 - y00;
1759
1760 // Pick the closer of the two intersection points.
1761 // TODO Is there a faster way to determine which intersection to use?
1762 if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
1763
1764 return {
1765 cx: cx0,
1766 cy: cy0,
1767 x01: -ox,
1768 y01: -oy,
1769 x11: cx0 * (r1 / r - 1),
1770 y11: cy0 * (r1 / r - 1)
1771 };
1772}
1773
1774var arc$1 = function () {
1775 var innerRadius = arcInnerRadius,
1776 outerRadius = arcOuterRadius,
1777 cornerRadius = constant$2(0),
1778 padRadius = null,
1779 startAngle = arcStartAngle,
1780 endAngle = arcEndAngle,
1781 padAngle = arcPadAngle,
1782 context = null;
1783
1784 function arc() {
1785 var buffer,
1786 r,
1787 r0 = +innerRadius.apply(this, arguments),
1788 r1 = +outerRadius.apply(this, arguments),
1789 a0 = startAngle.apply(this, arguments) - halfPi$1,
1790 a1 = endAngle.apply(this, arguments) - halfPi$1,
1791 da = Math.abs(a1 - a0),
1792 cw = a1 > a0;
1793
1794 if (!context) context = buffer = path();
1795
1796 // Ensure that the outer radius is always larger than the inner radius.
1797 if (r1 < r0) r = r1, r1 = r0, r0 = r;
1798
1799 // Is it a point?
1800 if (!(r1 > epsilon$1)) context.moveTo(0, 0);
1801
1802 // Or is it a circle or annulus?
1803 else if (da > tau$2 - epsilon$1) {
1804 context.moveTo(r1 * Math.cos(a0), r1 * Math.sin(a0));
1805 context.arc(0, 0, r1, a0, a1, !cw);
1806 if (r0 > epsilon$1) {
1807 context.moveTo(r0 * Math.cos(a1), r0 * Math.sin(a1));
1808 context.arc(0, 0, r0, a1, a0, cw);
1809 }
1810 }
1811
1812 // Or is it a circular or annular sector?
1813 else {
1814 var a01 = a0,
1815 a11 = a1,
1816 a00 = a0,
1817 a10 = a1,
1818 da0 = da,
1819 da1 = da,
1820 ap = padAngle.apply(this, arguments) / 2,
1821 rp = ap > epsilon$1 && (padRadius ? +padRadius.apply(this, arguments) : Math.sqrt(r0 * r0 + r1 * r1)),
1822 rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
1823 rc0 = rc,
1824 rc1 = rc,
1825 t0,
1826 t1;
1827
1828 // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
1829 if (rp > epsilon$1) {
1830 var p0 = asin(rp / r0 * Math.sin(ap)),
1831 p1 = asin(rp / r1 * Math.sin(ap));
1832 if ((da0 -= p0 * 2) > epsilon$1) p0 *= cw ? 1 : -1, a00 += p0, a10 -= p0;else da0 = 0, a00 = a10 = (a0 + a1) / 2;
1833 if ((da1 -= p1 * 2) > epsilon$1) p1 *= cw ? 1 : -1, a01 += p1, a11 -= p1;else da1 = 0, a01 = a11 = (a0 + a1) / 2;
1834 }
1835
1836 var x01 = r1 * Math.cos(a01),
1837 y01 = r1 * Math.sin(a01),
1838 x10 = r0 * Math.cos(a10),
1839 y10 = r0 * Math.sin(a10);
1840
1841 // Apply rounded corners?
1842 if (rc > epsilon$1) {
1843 var x11 = r1 * Math.cos(a11),
1844 y11 = r1 * Math.sin(a11),
1845 x00 = r0 * Math.cos(a00),
1846 y00 = r0 * Math.sin(a00);
1847
1848 // Restrict the corner radius according to the sector angle.
1849 if (da < pi$2) {
1850 var oc = da0 > epsilon$1 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
1851 ax = x01 - oc[0],
1852 ay = y01 - oc[1],
1853 bx = x11 - oc[0],
1854 by = y11 - oc[1],
1855 kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2),
1856 lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
1857 rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
1858 rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
1859 }
1860 }
1861
1862 // Is the sector collapsed to a line?
1863 if (!(da1 > epsilon$1)) context.moveTo(x01, y01);
1864
1865 // Does the sector’s outer ring have rounded corners?
1866 else if (rc1 > epsilon$1) {
1867 t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
1868 t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
1869
1870 context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
1871
1872 // Have the corners merged?
1873 if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, Math.atan2(t0.y01, t0.x01), Math.atan2(t1.y01, t1.x01), !cw);
1874
1875 // Otherwise, draw the two corners and the ring.
1876 else {
1877 context.arc(t0.cx, t0.cy, rc1, Math.atan2(t0.y01, t0.x01), Math.atan2(t0.y11, t0.x11), !cw);
1878 context.arc(0, 0, r1, Math.atan2(t0.cy + t0.y11, t0.cx + t0.x11), Math.atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
1879 context.arc(t1.cx, t1.cy, rc1, Math.atan2(t1.y11, t1.x11), Math.atan2(t1.y01, t1.x01), !cw);
1880 }
1881 }
1882
1883 // Or is the outer ring just a circular arc?
1884 else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
1885
1886 // Is there no inner ring, and it’s a circular sector?
1887 // Or perhaps it’s an annular sector collapsed due to padding?
1888 if (!(r0 > epsilon$1) || !(da0 > epsilon$1)) context.lineTo(x10, y10);
1889
1890 // Does the sector’s inner ring (or point) have rounded corners?
1891 else if (rc0 > epsilon$1) {
1892 t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
1893 t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
1894
1895 context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
1896
1897 // Have the corners merged?
1898 if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, Math.atan2(t0.y01, t0.x01), Math.atan2(t1.y01, t1.x01), !cw);
1899
1900 // Otherwise, draw the two corners and the ring.
1901 else {
1902 context.arc(t0.cx, t0.cy, rc0, Math.atan2(t0.y01, t0.x01), Math.atan2(t0.y11, t0.x11), !cw);
1903 context.arc(0, 0, r0, Math.atan2(t0.cy + t0.y11, t0.cx + t0.x11), Math.atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
1904 context.arc(t1.cx, t1.cy, rc0, Math.atan2(t1.y11, t1.x11), Math.atan2(t1.y01, t1.x01), !cw);
1905 }
1906 }
1907
1908 // Or is the inner ring just a circular arc?
1909 else context.arc(0, 0, r0, a10, a00, cw);
1910 }
1911
1912 context.closePath();
1913
1914 if (buffer) return context = null, buffer + "" || null;
1915 }
1916
1917 arc.centroid = function () {
1918 var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
1919 a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$2 / 2;
1920 return [Math.cos(a) * r, Math.sin(a) * r];
1921 };
1922
1923 arc.innerRadius = function (_) {
1924 return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$2(+_), arc) : innerRadius;
1925 };
1926
1927 arc.outerRadius = function (_) {
1928 return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$2(+_), arc) : outerRadius;
1929 };
1930
1931 arc.cornerRadius = function (_) {
1932 return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$2(+_), arc) : cornerRadius;
1933 };
1934
1935 arc.padRadius = function (_) {
1936 return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$2(+_), arc) : padRadius;
1937 };
1938
1939 arc.startAngle = function (_) {
1940 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$2(+_), arc) : startAngle;
1941 };
1942
1943 arc.endAngle = function (_) {
1944 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$2(+_), arc) : endAngle;
1945 };
1946
1947 arc.padAngle = function (_) {
1948 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$2(+_), arc) : padAngle;
1949 };
1950
1951 arc.context = function (_) {
1952 return arguments.length ? (context = _ == null ? null : _, arc) : context;
1953 };
1954
1955 return arc;
1956};
1957
1958function Linear(context) {
1959 this._context = context;
1960}
1961
1962Linear.prototype = {
1963 areaStart: function areaStart() {
1964 this._line = 0;
1965 },
1966 areaEnd: function areaEnd() {
1967 this._line = NaN;
1968 },
1969 lineStart: function lineStart() {
1970 this._point = 0;
1971 },
1972 lineEnd: function lineEnd() {
1973 if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
1974 this._line = 1 - this._line;
1975 },
1976 point: function point(x, y) {
1977 x = +x, y = +y;
1978 switch (this._point) {
1979 case 0:
1980 this._point = 1;this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y);break;
1981 case 1:
1982 this._point = 2; // proceed
1983 default:
1984 this._context.lineTo(x, y);break;
1985 }
1986 }
1987};
1988
1989var curveLinear = function (context) {
1990 return new Linear(context);
1991};
1992
1993function x$1(p) {
1994 return p[0];
1995}
1996
1997function y(p) {
1998 return p[1];
1999}
2000
2001var line = function () {
2002 var x$$1 = x$1,
2003 y$$1 = y,
2004 defined = constant$2(true),
2005 context = null,
2006 curve = curveLinear,
2007 output = null;
2008
2009 function line(data) {
2010 var i,
2011 n = data.length,
2012 d,
2013 defined0 = false,
2014 buffer;
2015
2016 if (context == null) output = curve(buffer = path());
2017
2018 for (i = 0; i <= n; ++i) {
2019 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
2020 if (defined0 = !defined0) output.lineStart();else output.lineEnd();
2021 }
2022 if (defined0) output.point(+x$$1(d, i, data), +y$$1(d, i, data));
2023 }
2024
2025 if (buffer) return output = null, buffer + "" || null;
2026 }
2027
2028 line.x = function (_) {
2029 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$2(+_), line) : x$$1;
2030 };
2031
2032 line.y = function (_) {
2033 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$2(+_), line) : y$$1;
2034 };
2035
2036 line.defined = function (_) {
2037 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$2(!!_), line) : defined;
2038 };
2039
2040 line.curve = function (_) {
2041 return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
2042 };
2043
2044 line.context = function (_) {
2045 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
2046 };
2047
2048 return line;
2049};
2050
2051var area$1 = function () {
2052 var x0 = x$1,
2053 x1 = null,
2054 y0 = constant$2(0),
2055 y1 = y,
2056 defined = constant$2(true),
2057 context = null,
2058 curve = curveLinear,
2059 output = null;
2060
2061 function area(data) {
2062 var i,
2063 j,
2064 k,
2065 n = data.length,
2066 d,
2067 defined0 = false,
2068 buffer,
2069 x0z = new Array(n),
2070 y0z = new Array(n);
2071
2072 if (context == null) output = curve(buffer = path());
2073
2074 for (i = 0; i <= n; ++i) {
2075 if (!(i < n && defined(d = data[i], i, data)) === defined0) {
2076 if (defined0 = !defined0) {
2077 j = i;
2078 output.areaStart();
2079 output.lineStart();
2080 } else {
2081 output.lineEnd();
2082 output.lineStart();
2083 for (k = i - 1; k >= j; --k) {
2084 output.point(x0z[k], y0z[k]);
2085 }
2086 output.lineEnd();
2087 output.areaEnd();
2088 }
2089 }
2090 if (defined0) {
2091 x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
2092 output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
2093 }
2094 }
2095
2096 if (buffer) return output = null, buffer + "" || null;
2097 }
2098
2099 function arealine() {
2100 return line().defined(defined).curve(curve).context(context);
2101 }
2102
2103 area.x = function (_) {
2104 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$2(+_), x1 = null, area) : x0;
2105 };
2106
2107 area.x0 = function (_) {
2108 return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$2(+_), area) : x0;
2109 };
2110
2111 area.x1 = function (_) {
2112 return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$2(+_), area) : x1;
2113 };
2114
2115 area.y = function (_) {
2116 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$2(+_), y1 = null, area) : y0;
2117 };
2118
2119 area.y0 = function (_) {
2120 return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$2(+_), area) : y0;
2121 };
2122
2123 area.y1 = function (_) {
2124 return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$2(+_), area) : y1;
2125 };
2126
2127 area.lineX0 = area.lineY0 = function () {
2128 return arealine().x(x0).y(y0);
2129 };
2130
2131 area.lineY1 = function () {
2132 return arealine().x(x0).y(y1);
2133 };
2134
2135 area.lineX1 = function () {
2136 return arealine().x(x1).y(y0);
2137 };
2138
2139 area.defined = function (_) {
2140 return arguments.length ? (defined = typeof _ === "function" ? _ : constant$2(!!_), area) : defined;
2141 };
2142
2143 area.curve = function (_) {
2144 return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
2145 };
2146
2147 area.context = function (_) {
2148 return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
2149 };
2150
2151 return area;
2152};
2153
2154var descending$1 = function (a, b) {
2155 return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
2156};
2157
2158var identity$1 = function (d) {
2159 return d;
2160};
2161
2162var pie = function () {
2163 var value = identity$1,
2164 sortValues = descending$1,
2165 sort = null,
2166 startAngle = constant$2(0),
2167 endAngle = constant$2(tau$2),
2168 padAngle = constant$2(0);
2169
2170 function pie(data) {
2171 var i,
2172 n = data.length,
2173 j,
2174 k,
2175 sum = 0,
2176 index = new Array(n),
2177 arcs = new Array(n),
2178 a0 = +startAngle.apply(this, arguments),
2179 da = Math.min(tau$2, Math.max(-tau$2, endAngle.apply(this, arguments) - a0)),
2180 a1,
2181 p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
2182 pa = p * (da < 0 ? -1 : 1),
2183 v;
2184
2185 for (i = 0; i < n; ++i) {
2186 if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
2187 sum += v;
2188 }
2189 }
2190
2191 // Optionally sort the arcs by previously-computed values or by data.
2192 if (sortValues != null) index.sort(function (i, j) {
2193 return sortValues(arcs[i], arcs[j]);
2194 });else if (sort != null) index.sort(function (i, j) {
2195 return sort(data[i], data[j]);
2196 });
2197
2198 // Compute the arcs! They are stored in the original data's order.
2199 for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
2200 j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
2201 data: data[j],
2202 index: i,
2203 value: v,
2204 startAngle: a0,
2205 endAngle: a1,
2206 padAngle: p
2207 };
2208 }
2209
2210 return arcs;
2211 }
2212
2213 pie.value = function (_) {
2214 return arguments.length ? (value = typeof _ === "function" ? _ : constant$2(+_), pie) : value;
2215 };
2216
2217 pie.sortValues = function (_) {
2218 return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
2219 };
2220
2221 pie.sort = function (_) {
2222 return arguments.length ? (sort = _, sortValues = null, pie) : sort;
2223 };
2224
2225 pie.startAngle = function (_) {
2226 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$2(+_), pie) : startAngle;
2227 };
2228
2229 pie.endAngle = function (_) {
2230 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$2(+_), pie) : endAngle;
2231 };
2232
2233 pie.padAngle = function (_) {
2234 return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$2(+_), pie) : padAngle;
2235 };
2236
2237 return pie;
2238};
2239
2240var curveRadialLinear = curveRadial(curveLinear);
2241
2242function Radial(curve) {
2243 this._curve = curve;
2244}
2245
2246Radial.prototype = {
2247 areaStart: function areaStart() {
2248 this._curve.areaStart();
2249 },
2250 areaEnd: function areaEnd() {
2251 this._curve.areaEnd();
2252 },
2253 lineStart: function lineStart() {
2254 this._curve.lineStart();
2255 },
2256 lineEnd: function lineEnd() {
2257 this._curve.lineEnd();
2258 },
2259 point: function point(a, r) {
2260 this._curve.point(r * Math.sin(a), r * -Math.cos(a));
2261 }
2262};
2263
2264function curveRadial(curve) {
2265
2266 function radial(context) {
2267 return new Radial(curve(context));
2268 }
2269
2270 radial._curve = curve;
2271
2272 return radial;
2273}
2274
2275function radialLine(l) {
2276 var c = l.curve;
2277
2278 l.angle = l.x, delete l.x;
2279 l.radius = l.y, delete l.y;
2280
2281 l.curve = function (_) {
2282 return arguments.length ? c(curveRadial(_)) : c()._curve;
2283 };
2284
2285 return l;
2286}
2287
2288var radialLine$1 = function () {
2289 return radialLine(line().curve(curveRadialLinear));
2290};
2291
2292var radialArea = function () {
2293 var a = area$1().curve(curveRadialLinear),
2294 c = a.curve,
2295 x0 = a.lineX0,
2296 x1 = a.lineX1,
2297 y0 = a.lineY0,
2298 y1 = a.lineY1;
2299
2300 a.angle = a.x, delete a.x;
2301 a.startAngle = a.x0, delete a.x0;
2302 a.endAngle = a.x1, delete a.x1;
2303 a.radius = a.y, delete a.y;
2304 a.innerRadius = a.y0, delete a.y0;
2305 a.outerRadius = a.y1, delete a.y1;
2306 a.lineStartAngle = function () {
2307 return radialLine(x0());
2308 }, delete a.lineX0;
2309 a.lineEndAngle = function () {
2310 return radialLine(x1());
2311 }, delete a.lineX1;
2312 a.lineInnerRadius = function () {
2313 return radialLine(y0());
2314 }, delete a.lineY0;
2315 a.lineOuterRadius = function () {
2316 return radialLine(y1());
2317 }, delete a.lineY1;
2318
2319 a.curve = function (_) {
2320 return arguments.length ? c(curveRadial(_)) : c()._curve;
2321 };
2322
2323 return a;
2324};
2325
2326var circle = {
2327 draw: function draw(context, size) {
2328 var r = Math.sqrt(size / pi$2);
2329 context.moveTo(r, 0);
2330 context.arc(0, 0, r, 0, tau$2);
2331 }
2332};
2333
2334var cross$1 = {
2335 draw: function draw(context, size) {
2336 var r = Math.sqrt(size / 5) / 2;
2337 context.moveTo(-3 * r, -r);
2338 context.lineTo(-r, -r);
2339 context.lineTo(-r, -3 * r);
2340 context.lineTo(r, -3 * r);
2341 context.lineTo(r, -r);
2342 context.lineTo(3 * r, -r);
2343 context.lineTo(3 * r, r);
2344 context.lineTo(r, r);
2345 context.lineTo(r, 3 * r);
2346 context.lineTo(-r, 3 * r);
2347 context.lineTo(-r, r);
2348 context.lineTo(-3 * r, r);
2349 context.closePath();
2350 }
2351};
2352
2353var tan30 = Math.sqrt(1 / 3);
2354var tan30_2 = tan30 * 2;
2355
2356var diamond = {
2357 draw: function draw(context, size) {
2358 var y = Math.sqrt(size / tan30_2),
2359 x = y * tan30;
2360 context.moveTo(0, -y);
2361 context.lineTo(x, 0);
2362 context.lineTo(0, y);
2363 context.lineTo(-x, 0);
2364 context.closePath();
2365 }
2366};
2367
2368var ka = 0.89081309152928522810;
2369var kr = Math.sin(pi$2 / 10) / Math.sin(7 * pi$2 / 10);
2370var kx = Math.sin(tau$2 / 10) * kr;
2371var ky = -Math.cos(tau$2 / 10) * kr;
2372
2373var star = {
2374 draw: function draw(context, size) {
2375 var r = Math.sqrt(size * ka),
2376 x = kx * r,
2377 y = ky * r;
2378 context.moveTo(0, -r);
2379 context.lineTo(x, y);
2380 for (var i = 1; i < 5; ++i) {
2381 var a = tau$2 * i / 5,
2382 c = Math.cos(a),
2383 s = Math.sin(a);
2384 context.lineTo(s * r, -c * r);
2385 context.lineTo(c * x - s * y, s * x + c * y);
2386 }
2387 context.closePath();
2388 }
2389};
2390
2391var square = {
2392 draw: function draw(context, size) {
2393 var w = Math.sqrt(size),
2394 x = -w / 2;
2395 context.rect(x, x, w, w);
2396 }
2397};
2398
2399var sqrt3 = Math.sqrt(3);
2400
2401var triangle = {
2402 draw: function draw(context, size) {
2403 var y = -Math.sqrt(size / (sqrt3 * 3));
2404 context.moveTo(0, y * 2);
2405 context.lineTo(-sqrt3 * y, -y);
2406 context.lineTo(sqrt3 * y, -y);
2407 context.closePath();
2408 }
2409};
2410
2411var c$1 = -0.5;
2412var s = Math.sqrt(3) / 2;
2413var k = 1 / Math.sqrt(12);
2414var a = (k / 2 + 1) * 3;
2415
2416var wye = {
2417 draw: function draw(context, size) {
2418 var r = Math.sqrt(size / a),
2419 x0 = r / 2,
2420 y0 = r * k,
2421 x1 = x0,
2422 y1 = r * k + r,
2423 x2 = -x1,
2424 y2 = y1;
2425 context.moveTo(x0, y0);
2426 context.lineTo(x1, y1);
2427 context.lineTo(x2, y2);
2428 context.lineTo(c$1 * x0 - s * y0, s * x0 + c$1 * y0);
2429 context.lineTo(c$1 * x1 - s * y1, s * x1 + c$1 * y1);
2430 context.lineTo(c$1 * x2 - s * y2, s * x2 + c$1 * y2);
2431 context.lineTo(c$1 * x0 + s * y0, c$1 * y0 - s * x0);
2432 context.lineTo(c$1 * x1 + s * y1, c$1 * y1 - s * x1);
2433 context.lineTo(c$1 * x2 + s * y2, c$1 * y2 - s * x2);
2434 context.closePath();
2435 }
2436};
2437
2438var symbols = [circle, cross$1, diamond, square, star, triangle, wye];
2439
2440var symbol = function () {
2441 var type = constant$2(circle),
2442 size = constant$2(64),
2443 context = null;
2444
2445 function symbol() {
2446 var buffer;
2447 if (!context) context = buffer = path();
2448 type.apply(this, arguments).draw(context, +size.apply(this, arguments));
2449 if (buffer) return context = null, buffer + "" || null;
2450 }
2451
2452 symbol.type = function (_) {
2453 return arguments.length ? (type = typeof _ === "function" ? _ : constant$2(_), symbol) : type;
2454 };
2455
2456 symbol.size = function (_) {
2457 return arguments.length ? (size = typeof _ === "function" ? _ : constant$2(+_), symbol) : size;
2458 };
2459
2460 symbol.context = function (_) {
2461 return arguments.length ? (context = _ == null ? null : _, symbol) : context;
2462 };
2463
2464 return symbol;
2465};
2466
2467var noop = function () {};
2468
2469function _point(that, x, y) {
2470 that._context.bezierCurveTo((2 * that._x0 + that._x1) / 3, (2 * that._y0 + that._y1) / 3, (that._x0 + 2 * that._x1) / 3, (that._y0 + 2 * that._y1) / 3, (that._x0 + 4 * that._x1 + x) / 6, (that._y0 + 4 * that._y1 + y) / 6);
2471}
2472
2473function Basis(context) {
2474 this._context = context;
2475}
2476
2477Basis.prototype = {
2478 areaStart: function areaStart() {
2479 this._line = 0;
2480 },
2481 areaEnd: function areaEnd() {
2482 this._line = NaN;
2483 },
2484 lineStart: function lineStart() {
2485 this._x0 = this._x1 = this._y0 = this._y1 = NaN;
2486 this._point = 0;
2487 },
2488 lineEnd: function lineEnd() {
2489 switch (this._point) {
2490 case 3:
2491 _point(this, this._x1, this._y1); // proceed
2492 case 2:
2493 this._context.lineTo(this._x1, this._y1);break;
2494 }
2495 if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
2496 this._line = 1 - this._line;
2497 },
2498 point: function point(x, y) {
2499 x = +x, y = +y;
2500 switch (this._point) {
2501 case 0:
2502 this._point = 1;this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y);break;
2503 case 1:
2504 this._point = 2;break;
2505 case 2:
2506 this._point = 3;this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
2507 default:
2508 _point(this, x, y);break;
2509 }
2510 this._x0 = this._x1, this._x1 = x;
2511 this._y0 = this._y1, this._y1 = y;
2512 }
2513};
2514
2515var basis = function (context) {
2516 return new Basis(context);
2517};
2518
2519function BasisClosed(context) {
2520 this._context = context;
2521}
2522
2523BasisClosed.prototype = {
2524 areaStart: noop,
2525 areaEnd: noop,
2526 lineStart: function lineStart() {
2527 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
2528 this._point = 0;
2529 },
2530 lineEnd: function lineEnd() {
2531 switch (this._point) {
2532 case 1:
2533 {
2534 this._context.moveTo(this._x2, this._y2);
2535 this._context.closePath();
2536 break;
2537 }
2538 case 2:
2539 {
2540 this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
2541 this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
2542 this._context.closePath();
2543 break;
2544 }
2545 case 3:
2546 {
2547 this.point(this._x2, this._y2);
2548 this.point(this._x3, this._y3);
2549 this.point(this._x4, this._y4);
2550 break;
2551 }
2552 }
2553 },
2554 point: function point(x, y) {
2555 x = +x, y = +y;
2556 switch (this._point) {
2557 case 0:
2558 this._point = 1;this._x2 = x, this._y2 = y;break;
2559 case 1:
2560 this._point = 2;this._x3 = x, this._y3 = y;break;
2561 case 2:
2562 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;
2563 default:
2564 _point(this, x, y);break;
2565 }
2566 this._x0 = this._x1, this._x1 = x;
2567 this._y0 = this._y1, this._y1 = y;
2568 }
2569};
2570
2571var basisClosed = function (context) {
2572 return new BasisClosed(context);
2573};
2574
2575function BasisOpen(context) {
2576 this._context = context;
2577}
2578
2579BasisOpen.prototype = {
2580 areaStart: function areaStart() {
2581 this._line = 0;
2582 },
2583 areaEnd: function areaEnd() {
2584 this._line = NaN;
2585 },
2586 lineStart: function lineStart() {
2587 this._x0 = this._x1 = this._y0 = this._y1 = NaN;
2588 this._point = 0;
2589 },
2590 lineEnd: function lineEnd() {
2591 if (this._line || this._line !== 0 && this._point === 3) this._context.closePath();
2592 this._line = 1 - this._line;
2593 },
2594 point: function point(x, y) {
2595 x = +x, y = +y;
2596 switch (this._point) {
2597 case 0:
2598 this._point = 1;break;
2599 case 1:
2600 this._point = 2;break;
2601 case 2:
2602 this._point = 3;var x0 = (this._x0 + 4 * this._x1 + x) / 6,
2603 y0 = (this._y0 + 4 * this._y1 + y) / 6;this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0);break;
2604 case 3:
2605 this._point = 4; // proceed
2606 default:
2607 _point(this, x, y);break;
2608 }
2609 this._x0 = this._x1, this._x1 = x;
2610 this._y0 = this._y1, this._y1 = y;
2611 }
2612};
2613
2614var basisOpen = function (context) {
2615 return new BasisOpen(context);
2616};
2617
2618function Bundle(context, beta) {
2619 this._basis = new Basis(context);
2620 this._beta = beta;
2621}
2622
2623Bundle.prototype = {
2624 lineStart: function lineStart() {
2625 this._x = [];
2626 this._y = [];
2627 this._basis.lineStart();
2628 },
2629 lineEnd: function lineEnd() {
2630 var x = this._x,
2631 y = this._y,
2632 j = x.length - 1;
2633
2634 if (j > 0) {
2635 var x0 = x[0],
2636 y0 = y[0],
2637 dx = x[j] - x0,
2638 dy = y[j] - y0,
2639 i = -1,
2640 t;
2641
2642 while (++i <= j) {
2643 t = i / j;
2644 this._basis.point(this._beta * x[i] + (1 - this._beta) * (x0 + t * dx), this._beta * y[i] + (1 - this._beta) * (y0 + t * dy));
2645 }
2646 }
2647
2648 this._x = this._y = null;
2649 this._basis.lineEnd();
2650 },
2651 point: function point(x, y) {
2652 this._x.push(+x);
2653 this._y.push(+y);
2654 }
2655};
2656
2657var bundle = (function custom(beta) {
2658
2659 function bundle(context) {
2660 return beta === 1 ? new Basis(context) : new Bundle(context, beta);
2661 }
2662
2663 bundle.beta = function (beta) {
2664 return custom(+beta);
2665 };
2666
2667 return bundle;
2668})(0.85);
2669
2670function _point$1(that, x, y) {
2671 that._context.bezierCurveTo(that._x1 + that._k * (that._x2 - that._x0), that._y1 + that._k * (that._y2 - that._y0), that._x2 + that._k * (that._x1 - x), that._y2 + that._k * (that._y1 - y), that._x2, that._y2);
2672}
2673
2674function Cardinal(context, tension) {
2675 this._context = context;
2676 this._k = (1 - tension) / 6;
2677}
2678
2679Cardinal.prototype = {
2680 areaStart: function areaStart() {
2681 this._line = 0;
2682 },
2683 areaEnd: function areaEnd() {
2684 this._line = NaN;
2685 },
2686 lineStart: function lineStart() {
2687 this._x0 = this._x1 = this._x2 = this._y0 = this._y1 = this._y2 = NaN;
2688 this._point = 0;
2689 },
2690 lineEnd: function lineEnd() {
2691 switch (this._point) {
2692 case 2:
2693 this._context.lineTo(this._x2, this._y2);break;
2694 case 3:
2695 _point$1(this, this._x1, this._y1);break;
2696 }
2697 if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
2698 this._line = 1 - this._line;
2699 },
2700 point: function point(x, y) {
2701 x = +x, y = +y;
2702 switch (this._point) {
2703 case 0:
2704 this._point = 1;this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y);break;
2705 case 1:
2706 this._point = 2;this._x1 = x, this._y1 = y;break;
2707 case 2:
2708 this._point = 3; // proceed
2709 default:
2710 _point$1(this, x, y);break;
2711 }
2712 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
2713 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
2714 }
2715};
2716
2717var cardinal = (function custom(tension) {
2718
2719 function cardinal(context) {
2720 return new Cardinal(context, tension);
2721 }
2722
2723 cardinal.tension = function (tension) {
2724 return custom(+tension);
2725 };
2726
2727 return cardinal;
2728})(0);
2729
2730function CardinalClosed(context, tension) {
2731 this._context = context;
2732 this._k = (1 - tension) / 6;
2733}
2734
2735CardinalClosed.prototype = {
2736 areaStart: noop,
2737 areaEnd: noop,
2738 lineStart: function lineStart() {
2739 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 = this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
2740 this._point = 0;
2741 },
2742 lineEnd: function lineEnd() {
2743 switch (this._point) {
2744 case 1:
2745 {
2746 this._context.moveTo(this._x3, this._y3);
2747 this._context.closePath();
2748 break;
2749 }
2750 case 2:
2751 {
2752 this._context.lineTo(this._x3, this._y3);
2753 this._context.closePath();
2754 break;
2755 }
2756 case 3:
2757 {
2758 this.point(this._x3, this._y3);
2759 this.point(this._x4, this._y4);
2760 this.point(this._x5, this._y5);
2761 break;
2762 }
2763 }
2764 },
2765 point: function point(x, y) {
2766 x = +x, y = +y;
2767 switch (this._point) {
2768 case 0:
2769 this._point = 1;this._x3 = x, this._y3 = y;break;
2770 case 1:
2771 this._point = 2;this._context.moveTo(this._x4 = x, this._y4 = y);break;
2772 case 2:
2773 this._point = 3;this._x5 = x, this._y5 = y;break;
2774 default:
2775 _point$1(this, x, y);break;
2776 }
2777 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
2778 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
2779 }
2780};
2781
2782var cardinalClosed = (function custom(tension) {
2783
2784 function cardinal(context) {
2785 return new CardinalClosed(context, tension);
2786 }
2787
2788 cardinal.tension = function (tension) {
2789 return custom(+tension);
2790 };
2791
2792 return cardinal;
2793})(0);
2794
2795function CardinalOpen(context, tension) {
2796 this._context = context;
2797 this._k = (1 - tension) / 6;
2798}
2799
2800CardinalOpen.prototype = {
2801 areaStart: function areaStart() {
2802 this._line = 0;
2803 },
2804 areaEnd: function areaEnd() {
2805 this._line = NaN;
2806 },
2807 lineStart: function lineStart() {
2808 this._x0 = this._x1 = this._x2 = this._y0 = this._y1 = this._y2 = NaN;
2809 this._point = 0;
2810 },
2811 lineEnd: function lineEnd() {
2812 if (this._line || this._line !== 0 && this._point === 3) this._context.closePath();
2813 this._line = 1 - this._line;
2814 },
2815 point: function point(x, y) {
2816 x = +x, y = +y;
2817 switch (this._point) {
2818 case 0:
2819 this._point = 1;break;
2820 case 1:
2821 this._point = 2;break;
2822 case 2:
2823 this._point = 3;this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2);break;
2824 case 3:
2825 this._point = 4; // proceed
2826 default:
2827 _point$1(this, x, y);break;
2828 }
2829 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
2830 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
2831 }
2832};
2833
2834var cardinalOpen = (function custom(tension) {
2835
2836 function cardinal(context) {
2837 return new CardinalOpen(context, tension);
2838 }
2839
2840 cardinal.tension = function (tension) {
2841 return custom(+tension);
2842 };
2843
2844 return cardinal;
2845})(0);
2846
2847function _point$2(that, x, y) {
2848 var x1 = that._x1,
2849 y1 = that._y1,
2850 x2 = that._x2,
2851 y2 = that._y2;
2852
2853 if (that._l01_a > epsilon$1) {
2854 var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
2855 n = 3 * that._l01_a * (that._l01_a + that._l12_a);
2856 x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
2857 y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
2858 }
2859
2860 if (that._l23_a > epsilon$1) {
2861 var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
2862 m = 3 * that._l23_a * (that._l23_a + that._l12_a);
2863 x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
2864 y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
2865 }
2866
2867 that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
2868}
2869
2870function CatmullRom(context, alpha) {
2871 this._context = context;
2872 this._alpha = alpha;
2873}
2874
2875CatmullRom.prototype = {
2876 areaStart: function areaStart() {
2877 this._line = 0;
2878 },
2879 areaEnd: function areaEnd() {
2880 this._line = NaN;
2881 },
2882 lineStart: function lineStart() {
2883 this._x0 = this._x1 = this._x2 = this._y0 = this._y1 = this._y2 = NaN;
2884 this._l01_a = this._l12_a = this._l23_a = this._l01_2a = this._l12_2a = this._l23_2a = this._point = 0;
2885 },
2886 lineEnd: function lineEnd() {
2887 switch (this._point) {
2888 case 2:
2889 this._context.lineTo(this._x2, this._y2);break;
2890 case 3:
2891 this.point(this._x2, this._y2);break;
2892 }
2893 if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
2894 this._line = 1 - this._line;
2895 },
2896 point: function point(x, y) {
2897 x = +x, y = +y;
2898
2899 if (this._point) {
2900 var x23 = this._x2 - x,
2901 y23 = this._y2 - y;
2902 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
2903 }
2904
2905 switch (this._point) {
2906 case 0:
2907 this._point = 1;this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y);break;
2908 case 1:
2909 this._point = 2;break;
2910 case 2:
2911 this._point = 3; // proceed
2912 default:
2913 _point$2(this, x, y);break;
2914 }
2915
2916 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
2917 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
2918 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
2919 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
2920 }
2921};
2922
2923var catmullRom = (function custom(alpha) {
2924
2925 function catmullRom(context) {
2926 return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
2927 }
2928
2929 catmullRom.alpha = function (alpha) {
2930 return custom(+alpha);
2931 };
2932
2933 return catmullRom;
2934})(0.5);
2935
2936function CatmullRomClosed(context, alpha) {
2937 this._context = context;
2938 this._alpha = alpha;
2939}
2940
2941CatmullRomClosed.prototype = {
2942 areaStart: noop,
2943 areaEnd: noop,
2944 lineStart: function lineStart() {
2945 this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 = this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
2946 this._l01_a = this._l12_a = this._l23_a = this._l01_2a = this._l12_2a = this._l23_2a = this._point = 0;
2947 },
2948 lineEnd: function lineEnd() {
2949 switch (this._point) {
2950 case 1:
2951 {
2952 this._context.moveTo(this._x3, this._y3);
2953 this._context.closePath();
2954 break;
2955 }
2956 case 2:
2957 {
2958 this._context.lineTo(this._x3, this._y3);
2959 this._context.closePath();
2960 break;
2961 }
2962 case 3:
2963 {
2964 this.point(this._x3, this._y3);
2965 this.point(this._x4, this._y4);
2966 this.point(this._x5, this._y5);
2967 break;
2968 }
2969 }
2970 },
2971 point: function point(x, y) {
2972 x = +x, y = +y;
2973
2974 if (this._point) {
2975 var x23 = this._x2 - x,
2976 y23 = this._y2 - y;
2977 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
2978 }
2979
2980 switch (this._point) {
2981 case 0:
2982 this._point = 1;this._x3 = x, this._y3 = y;break;
2983 case 1:
2984 this._point = 2;this._context.moveTo(this._x4 = x, this._y4 = y);break;
2985 case 2:
2986 this._point = 3;this._x5 = x, this._y5 = y;break;
2987 default:
2988 _point$2(this, x, y);break;
2989 }
2990
2991 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
2992 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
2993 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
2994 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
2995 }
2996};
2997
2998var catmullRomClosed = (function custom(alpha) {
2999
3000 function catmullRom(context) {
3001 return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
3002 }
3003
3004 catmullRom.alpha = function (alpha) {
3005 return custom(+alpha);
3006 };
3007
3008 return catmullRom;
3009})(0.5);
3010
3011function CatmullRomOpen(context, alpha) {
3012 this._context = context;
3013 this._alpha = alpha;
3014}
3015
3016CatmullRomOpen.prototype = {
3017 areaStart: function areaStart() {
3018 this._line = 0;
3019 },
3020 areaEnd: function areaEnd() {
3021 this._line = NaN;
3022 },
3023 lineStart: function lineStart() {
3024 this._x0 = this._x1 = this._x2 = this._y0 = this._y1 = this._y2 = NaN;
3025 this._l01_a = this._l12_a = this._l23_a = this._l01_2a = this._l12_2a = this._l23_2a = this._point = 0;
3026 },
3027 lineEnd: function lineEnd() {
3028 if (this._line || this._line !== 0 && this._point === 3) this._context.closePath();
3029 this._line = 1 - this._line;
3030 },
3031 point: function point(x, y) {
3032 x = +x, y = +y;
3033
3034 if (this._point) {
3035 var x23 = this._x2 - x,
3036 y23 = this._y2 - y;
3037 this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
3038 }
3039
3040 switch (this._point) {
3041 case 0:
3042 this._point = 1;break;
3043 case 1:
3044 this._point = 2;break;
3045 case 2:
3046 this._point = 3;this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2);break;
3047 case 3:
3048 this._point = 4; // proceed
3049 default:
3050 _point$2(this, x, y);break;
3051 }
3052
3053 this._l01_a = this._l12_a, this._l12_a = this._l23_a;
3054 this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
3055 this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
3056 this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
3057 }
3058};
3059
3060var catmullRomOpen = (function custom(alpha) {
3061
3062 function catmullRom(context) {
3063 return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
3064 }
3065
3066 catmullRom.alpha = function (alpha) {
3067 return custom(+alpha);
3068 };
3069
3070 return catmullRom;
3071})(0.5);
3072
3073function LinearClosed(context) {
3074 this._context = context;
3075}
3076
3077LinearClosed.prototype = {
3078 areaStart: noop,
3079 areaEnd: noop,
3080 lineStart: function lineStart() {
3081 this._point = 0;
3082 },
3083 lineEnd: function lineEnd() {
3084 if (this._point) this._context.closePath();
3085 },
3086 point: function point(x, y) {
3087 x = +x, y = +y;
3088 if (this._point) this._context.lineTo(x, y);else this._point = 1, this._context.moveTo(x, y);
3089 }
3090};
3091
3092var linearClosed = function (context) {
3093 return new LinearClosed(context);
3094};
3095
3096function sign(x) {
3097 return x < 0 ? -1 : 1;
3098}
3099
3100// Calculate the slopes of the tangents (Hermite-type interpolation) based on
3101// the following paper: Steffen, M. 1990. A Simple Method for Monotonic
3102// Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
3103// NOV(II), P. 443, 1990.
3104function slope3(that, x2, y2) {
3105 var h0 = that._x1 - that._x0,
3106 h1 = x2 - that._x1,
3107 s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
3108 s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
3109 p = (s0 * h1 + s1 * h0) / (h0 + h1);
3110 return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
3111}
3112
3113// Calculate a one-sided slope.
3114function slope2(that, t) {
3115 var h = that._x1 - that._x0;
3116 return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
3117}
3118
3119// According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
3120// "you can express cubic Hermite interpolation in terms of cubic Bézier curves
3121// with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
3122function _point$3(that, t0, t1) {
3123 var x0 = that._x0,
3124 y0 = that._y0,
3125 x1 = that._x1,
3126 y1 = that._y1,
3127 dx = (x1 - x0) / 3;
3128 that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
3129}
3130
3131function MonotoneX(context) {
3132 this._context = context;
3133}
3134
3135MonotoneX.prototype = {
3136 areaStart: function areaStart() {
3137 this._line = 0;
3138 },
3139 areaEnd: function areaEnd() {
3140 this._line = NaN;
3141 },
3142 lineStart: function lineStart() {
3143 this._x0 = this._x1 = this._y0 = this._y1 = this._t0 = NaN;
3144 this._point = 0;
3145 },
3146 lineEnd: function lineEnd() {
3147 switch (this._point) {
3148 case 2:
3149 this._context.lineTo(this._x1, this._y1);break;
3150 case 3:
3151 _point$3(this, this._t0, slope2(this, this._t0));break;
3152 }
3153 if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
3154 this._line = 1 - this._line;
3155 },
3156 point: function point(x, y) {
3157 var t1 = NaN;
3158
3159 x = +x, y = +y;
3160 if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
3161 switch (this._point) {
3162 case 0:
3163 this._point = 1;this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y);break;
3164 case 1:
3165 this._point = 2;break;
3166 case 2:
3167 this._point = 3;_point$3(this, slope2(this, t1 = slope3(this, x, y)), t1);break;
3168 default:
3169 _point$3(this, this._t0, t1 = slope3(this, x, y));break;
3170 }
3171
3172 this._x0 = this._x1, this._x1 = x;
3173 this._y0 = this._y1, this._y1 = y;
3174 this._t0 = t1;
3175 }
3176};
3177
3178function MonotoneY(context) {
3179 this._context = new ReflectContext(context);
3180}
3181
3182(MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function (x, y) {
3183 MonotoneX.prototype.point.call(this, y, x);
3184};
3185
3186function ReflectContext(context) {
3187 this._context = context;
3188}
3189
3190ReflectContext.prototype = {
3191 moveTo: function moveTo(x, y) {
3192 this._context.moveTo(y, x);
3193 },
3194 closePath: function closePath() {
3195 this._context.closePath();
3196 },
3197 lineTo: function lineTo(x, y) {
3198 this._context.lineTo(y, x);
3199 },
3200 bezierCurveTo: function bezierCurveTo(x1, y1, x2, y2, x, y) {
3201 this._context.bezierCurveTo(y1, x1, y2, x2, y, x);
3202 }
3203};
3204
3205function monotoneX(context) {
3206 return new MonotoneX(context);
3207}
3208
3209function monotoneY(context) {
3210 return new MonotoneY(context);
3211}
3212
3213function Natural(context) {
3214 this._context = context;
3215}
3216
3217Natural.prototype = {
3218 areaStart: function areaStart() {
3219 this._line = 0;
3220 },
3221 areaEnd: function areaEnd() {
3222 this._line = NaN;
3223 },
3224 lineStart: function lineStart() {
3225 this._x = [];
3226 this._y = [];
3227 },
3228 lineEnd: function lineEnd() {
3229 var x = this._x,
3230 y = this._y,
3231 n = x.length;
3232
3233 if (n) {
3234 this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
3235 if (n === 2) {
3236 this._context.lineTo(x[1], y[1]);
3237 } else {
3238 var px = controlPoints(x),
3239 py = controlPoints(y);
3240 for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
3241 this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
3242 }
3243 }
3244 }
3245
3246 if (this._line || this._line !== 0 && n === 1) this._context.closePath();
3247 this._line = 1 - this._line;
3248 this._x = this._y = null;
3249 },
3250 point: function point(x, y) {
3251 this._x.push(+x);
3252 this._y.push(+y);
3253 }
3254};
3255
3256// See https://www.particleincell.com/2012/bezier-splines/ for derivation.
3257function controlPoints(x) {
3258 var i,
3259 n = x.length - 1,
3260 m,
3261 a = new Array(n),
3262 b = new Array(n),
3263 r = new Array(n);
3264 a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
3265 for (i = 1; i < n - 1; ++i) {
3266 a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
3267 }a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
3268 for (i = 1; i < n; ++i) {
3269 m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
3270 }a[n - 1] = r[n - 1] / b[n - 1];
3271 for (i = n - 2; i >= 0; --i) {
3272 a[i] = (r[i] - a[i + 1]) / b[i];
3273 }b[n - 1] = (x[n] + a[n - 1]) / 2;
3274 for (i = 0; i < n - 1; ++i) {
3275 b[i] = 2 * x[i + 1] - a[i + 1];
3276 }return [a, b];
3277}
3278
3279var natural = function (context) {
3280 return new Natural(context);
3281};
3282
3283function Step(context, t) {
3284 this._context = context;
3285 this._t = t;
3286}
3287
3288Step.prototype = {
3289 areaStart: function areaStart() {
3290 this._line = 0;
3291 },
3292 areaEnd: function areaEnd() {
3293 this._line = NaN;
3294 },
3295 lineStart: function lineStart() {
3296 this._x = this._y = NaN;
3297 this._point = 0;
3298 },
3299 lineEnd: function lineEnd() {
3300 if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
3301 if (this._line || this._line !== 0 && this._point === 1) this._context.closePath();
3302 if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
3303 },
3304 point: function point(x, y) {
3305 x = +x, y = +y;
3306 switch (this._point) {
3307 case 0:
3308 this._point = 1;this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y);break;
3309 case 1:
3310 this._point = 2; // proceed
3311 default:
3312 {
3313 if (this._t <= 0) {
3314 this._context.lineTo(this._x, y);
3315 this._context.lineTo(x, y);
3316 } else {
3317 var x1 = this._x * (1 - this._t) + x * this._t;
3318 this._context.lineTo(x1, this._y);
3319 this._context.lineTo(x1, y);
3320 }
3321 break;
3322 }
3323 }
3324 this._x = x, this._y = y;
3325 }
3326};
3327
3328var step = function (context) {
3329 return new Step(context, 0.5);
3330};
3331
3332function stepBefore(context) {
3333 return new Step(context, 0);
3334}
3335
3336function stepAfter(context) {
3337 return new Step(context, 1);
3338}
3339
3340var slice$1 = Array.prototype.slice;
3341
3342var none = function (series, order) {
3343 if (!((n = series.length) > 1)) return;
3344 for (var i = 1, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
3345 s0 = s1, s1 = series[order[i]];
3346 for (var j = 0; j < m; ++j) {
3347 s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
3348 }
3349 }
3350};
3351
3352var none$1 = function (series) {
3353 var n = series.length,
3354 o = new Array(n);
3355 while (--n >= 0) {
3356 o[n] = n;
3357 }return o;
3358};
3359
3360function stackValue(d, key) {
3361 return d[key];
3362}
3363
3364var stack = function () {
3365 var keys = constant$2([]),
3366 order = none$1,
3367 offset = none,
3368 value = stackValue;
3369
3370 function stack(data) {
3371 var kz = keys.apply(this, arguments),
3372 i,
3373 m = data.length,
3374 n = kz.length,
3375 sz = new Array(n),
3376 oz;
3377
3378 for (i = 0; i < n; ++i) {
3379 for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
3380 si[j] = sij = [0, +value(data[j], ki, j, data)];
3381 sij.data = data[j];
3382 }
3383 si.key = ki;
3384 }
3385
3386 for (i = 0, oz = order(sz); i < n; ++i) {
3387 sz[oz[i]].index = i;
3388 }
3389
3390 offset(sz, oz);
3391 return sz;
3392 }
3393
3394 stack.keys = function (_) {
3395 return arguments.length ? (keys = typeof _ === "function" ? _ : constant$2(slice$1.call(_)), stack) : keys;
3396 };
3397
3398 stack.value = function (_) {
3399 return arguments.length ? (value = typeof _ === "function" ? _ : constant$2(+_), stack) : value;
3400 };
3401
3402 stack.order = function (_) {
3403 return arguments.length ? (order = _ == null ? none$1 : typeof _ === "function" ? _ : constant$2(slice$1.call(_)), stack) : order;
3404 };
3405
3406 stack.offset = function (_) {
3407 return arguments.length ? (offset = _ == null ? none : _, stack) : offset;
3408 };
3409
3410 return stack;
3411};
3412
3413var expand = function (series, order) {
3414 if (!((n = series.length) > 0)) return;
3415 for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
3416 for (y = i = 0; i < n; ++i) {
3417 y += series[i][j][1] || 0;
3418 }if (y) for (i = 0; i < n; ++i) {
3419 series[i][j][1] /= y;
3420 }
3421 }
3422 none(series, order);
3423};
3424
3425var silhouette = function (series, order) {
3426 if (!((n = series.length) > 0)) return;
3427 for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
3428 for (var i = 0, y = 0; i < n; ++i) {
3429 y += series[i][j][1] || 0;
3430 }s0[j][1] += s0[j][0] = -y / 2;
3431 }
3432 none(series, order);
3433};
3434
3435var wiggle = function (series, order) {
3436 if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
3437 for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
3438 for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
3439 var si = series[order[i]],
3440 sij0 = si[j][1] || 0,
3441 sij1 = si[j - 1][1] || 0,
3442 s3 = (sij0 - sij1) / 2;
3443 for (var k = 0; k < i; ++k) {
3444 var sk = series[order[k]],
3445 skj0 = sk[j][1] || 0,
3446 skj1 = sk[j - 1][1] || 0;
3447 s3 += skj0 - skj1;
3448 }
3449 s1 += sij0, s2 += s3 * sij0;
3450 }
3451 s0[j - 1][1] += s0[j - 1][0] = y;
3452 if (s1) y -= s2 / s1;
3453 }
3454 s0[j - 1][1] += s0[j - 1][0] = y;
3455 none(series, order);
3456};
3457
3458var ascending$1 = function (series) {
3459 var sums = series.map(sum$1);
3460 return none$1(series).sort(function (a, b) {
3461 return sums[a] - sums[b];
3462 });
3463};
3464
3465function sum$1(series) {
3466 var s = 0,
3467 i = -1,
3468 n = series.length,
3469 v;
3470 while (++i < n) {
3471 if (v = +series[i][1]) s += v;
3472 }return s;
3473}
3474
3475var descending$2 = function (series) {
3476 return ascending$1(series).reverse();
3477};
3478
3479var insideOut = function (series) {
3480 var n = series.length,
3481 i,
3482 j,
3483 sums = series.map(sum$1),
3484 order = none$1(series).sort(function (a, b) {
3485 return sums[b] - sums[a];
3486 }),
3487 top = 0,
3488 bottom = 0,
3489 tops = [],
3490 bottoms = [];
3491
3492 for (i = 0; i < n; ++i) {
3493 j = order[i];
3494 if (top < bottom) {
3495 top += sums[j];
3496 tops.push(j);
3497 } else {
3498 bottom += sums[j];
3499 bottoms.push(j);
3500 }
3501 }
3502
3503 return bottoms.reverse().concat(tops);
3504};
3505
3506var reverse = function (series) {
3507 return none$1(series).reverse();
3508};
3509
3510var define = function (constructor, factory, prototype) {
3511 constructor.prototype = factory.prototype = prototype;
3512 prototype.constructor = constructor;
3513};
3514
3515function extend(parent, definition) {
3516 var prototype = Object.create(parent.prototype);
3517 for (var key in definition) {
3518 prototype[key] = definition[key];
3519 }return prototype;
3520}
3521
3522function Color() {}
3523
3524var _darker = 0.7;
3525var _brighter = 1 / _darker;
3526
3527var reI = "\\s*([+-]?\\d+)\\s*";
3528var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
3529var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
3530var reHex3 = /^#([0-9a-f]{3})$/;
3531var reHex6 = /^#([0-9a-f]{6})$/;
3532var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
3533var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
3534var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
3535var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
3536var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
3537var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
3538
3539var named = {
3540 aliceblue: 0xf0f8ff,
3541 antiquewhite: 0xfaebd7,
3542 aqua: 0x00ffff,
3543 aquamarine: 0x7fffd4,
3544 azure: 0xf0ffff,
3545 beige: 0xf5f5dc,
3546 bisque: 0xffe4c4,
3547 black: 0x000000,
3548 blanchedalmond: 0xffebcd,
3549 blue: 0x0000ff,
3550 blueviolet: 0x8a2be2,
3551 brown: 0xa52a2a,
3552 burlywood: 0xdeb887,
3553 cadetblue: 0x5f9ea0,
3554 chartreuse: 0x7fff00,
3555 chocolate: 0xd2691e,
3556 coral: 0xff7f50,
3557 cornflowerblue: 0x6495ed,
3558 cornsilk: 0xfff8dc,
3559 crimson: 0xdc143c,
3560 cyan: 0x00ffff,
3561 darkblue: 0x00008b,
3562 darkcyan: 0x008b8b,
3563 darkgoldenrod: 0xb8860b,
3564 darkgray: 0xa9a9a9,
3565 darkgreen: 0x006400,
3566 darkgrey: 0xa9a9a9,
3567 darkkhaki: 0xbdb76b,
3568 darkmagenta: 0x8b008b,
3569 darkolivegreen: 0x556b2f,
3570 darkorange: 0xff8c00,
3571 darkorchid: 0x9932cc,
3572 darkred: 0x8b0000,
3573 darksalmon: 0xe9967a,
3574 darkseagreen: 0x8fbc8f,
3575 darkslateblue: 0x483d8b,
3576 darkslategray: 0x2f4f4f,
3577 darkslategrey: 0x2f4f4f,
3578 darkturquoise: 0x00ced1,
3579 darkviolet: 0x9400d3,
3580 deeppink: 0xff1493,
3581 deepskyblue: 0x00bfff,
3582 dimgray: 0x696969,
3583 dimgrey: 0x696969,
3584 dodgerblue: 0x1e90ff,
3585 firebrick: 0xb22222,
3586 floralwhite: 0xfffaf0,
3587 forestgreen: 0x228b22,
3588 fuchsia: 0xff00ff,
3589 gainsboro: 0xdcdcdc,
3590 ghostwhite: 0xf8f8ff,
3591 gold: 0xffd700,
3592 goldenrod: 0xdaa520,
3593 gray: 0x808080,
3594 green: 0x008000,
3595 greenyellow: 0xadff2f,
3596 grey: 0x808080,
3597 honeydew: 0xf0fff0,
3598 hotpink: 0xff69b4,
3599 indianred: 0xcd5c5c,
3600 indigo: 0x4b0082,
3601 ivory: 0xfffff0,
3602 khaki: 0xf0e68c,
3603 lavender: 0xe6e6fa,
3604 lavenderblush: 0xfff0f5,
3605 lawngreen: 0x7cfc00,
3606 lemonchiffon: 0xfffacd,
3607 lightblue: 0xadd8e6,
3608 lightcoral: 0xf08080,
3609 lightcyan: 0xe0ffff,
3610 lightgoldenrodyellow: 0xfafad2,
3611 lightgray: 0xd3d3d3,
3612 lightgreen: 0x90ee90,
3613 lightgrey: 0xd3d3d3,
3614 lightpink: 0xffb6c1,
3615 lightsalmon: 0xffa07a,
3616 lightseagreen: 0x20b2aa,
3617 lightskyblue: 0x87cefa,
3618 lightslategray: 0x778899,
3619 lightslategrey: 0x778899,
3620 lightsteelblue: 0xb0c4de,
3621 lightyellow: 0xffffe0,
3622 lime: 0x00ff00,
3623 limegreen: 0x32cd32,
3624 linen: 0xfaf0e6,
3625 magenta: 0xff00ff,
3626 maroon: 0x800000,
3627 mediumaquamarine: 0x66cdaa,
3628 mediumblue: 0x0000cd,
3629 mediumorchid: 0xba55d3,
3630 mediumpurple: 0x9370db,
3631 mediumseagreen: 0x3cb371,
3632 mediumslateblue: 0x7b68ee,
3633 mediumspringgreen: 0x00fa9a,
3634 mediumturquoise: 0x48d1cc,
3635 mediumvioletred: 0xc71585,
3636 midnightblue: 0x191970,
3637 mintcream: 0xf5fffa,
3638 mistyrose: 0xffe4e1,
3639 moccasin: 0xffe4b5,
3640 navajowhite: 0xffdead,
3641 navy: 0x000080,
3642 oldlace: 0xfdf5e6,
3643 olive: 0x808000,
3644 olivedrab: 0x6b8e23,
3645 orange: 0xffa500,
3646 orangered: 0xff4500,
3647 orchid: 0xda70d6,
3648 palegoldenrod: 0xeee8aa,
3649 palegreen: 0x98fb98,
3650 paleturquoise: 0xafeeee,
3651 palevioletred: 0xdb7093,
3652 papayawhip: 0xffefd5,
3653 peachpuff: 0xffdab9,
3654 peru: 0xcd853f,
3655 pink: 0xffc0cb,
3656 plum: 0xdda0dd,
3657 powderblue: 0xb0e0e6,
3658 purple: 0x800080,
3659 rebeccapurple: 0x663399,
3660 red: 0xff0000,
3661 rosybrown: 0xbc8f8f,
3662 royalblue: 0x4169e1,
3663 saddlebrown: 0x8b4513,
3664 salmon: 0xfa8072,
3665 sandybrown: 0xf4a460,
3666 seagreen: 0x2e8b57,
3667 seashell: 0xfff5ee,
3668 sienna: 0xa0522d,
3669 silver: 0xc0c0c0,
3670 skyblue: 0x87ceeb,
3671 slateblue: 0x6a5acd,
3672 slategray: 0x708090,
3673 slategrey: 0x708090,
3674 snow: 0xfffafa,
3675 springgreen: 0x00ff7f,
3676 steelblue: 0x4682b4,
3677 tan: 0xd2b48c,
3678 teal: 0x008080,
3679 thistle: 0xd8bfd8,
3680 tomato: 0xff6347,
3681 turquoise: 0x40e0d0,
3682 violet: 0xee82ee,
3683 wheat: 0xf5deb3,
3684 white: 0xffffff,
3685 whitesmoke: 0xf5f5f5,
3686 yellow: 0xffff00,
3687 yellowgreen: 0x9acd32
3688};
3689
3690define(Color, color, {
3691 displayable: function displayable() {
3692 return this.rgb().displayable();
3693 },
3694 toString: function toString() {
3695 return this.rgb() + "";
3696 }
3697});
3698
3699function color(format) {
3700 var m;
3701 format = (format + "").trim().toLowerCase();
3702 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
3703 ) : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
3704 : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
3705 : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
3706 : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
3707 : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
3708 : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
3709 : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
3710 : named.hasOwnProperty(format) ? rgbn(named[format]) : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0) : null;
3711}
3712
3713function rgbn(n) {
3714 return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
3715}
3716
3717function rgba(r, g, b, a) {
3718 if (a <= 0) r = g = b = NaN;
3719 return new Rgb(r, g, b, a);
3720}
3721
3722function rgbConvert(o) {
3723 if (!(o instanceof Color)) o = color(o);
3724 if (!o) return new Rgb();
3725 o = o.rgb();
3726 return new Rgb(o.r, o.g, o.b, o.opacity);
3727}
3728
3729function rgb$1(r, g, b, opacity) {
3730 return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
3731}
3732
3733function Rgb(r, g, b, opacity) {
3734 this.r = +r;
3735 this.g = +g;
3736 this.b = +b;
3737 this.opacity = +opacity;
3738}
3739
3740define(Rgb, rgb$1, extend(Color, {
3741 brighter: function brighter(k) {
3742 k = k == null ? _brighter : Math.pow(_brighter, k);
3743 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
3744 },
3745 darker: function darker(k) {
3746 k = k == null ? _darker : Math.pow(_darker, k);
3747 return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
3748 },
3749 rgb: function rgb$1() {
3750 return this;
3751 },
3752 displayable: function displayable() {
3753 return 0 <= this.r && this.r <= 255 && 0 <= this.g && this.g <= 255 && 0 <= this.b && this.b <= 255 && 0 <= this.opacity && this.opacity <= 1;
3754 },
3755 toString: function toString() {
3756 var a = this.opacity;a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
3757 return (a === 1 ? "rgb(" : "rgba(") + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", " + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", " + Math.max(0, Math.min(255, Math.round(this.b) || 0)) + (a === 1 ? ")" : ", " + a + ")");
3758 }
3759}));
3760
3761function hsla(h, s, l, a) {
3762 if (a <= 0) h = s = l = NaN;else if (l <= 0 || l >= 1) h = s = NaN;else if (s <= 0) h = NaN;
3763 return new Hsl(h, s, l, a);
3764}
3765
3766function hslConvert(o) {
3767 if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
3768 if (!(o instanceof Color)) o = color(o);
3769 if (!o) return new Hsl();
3770 if (o instanceof Hsl) return o;
3771 o = o.rgb();
3772 var r = o.r / 255,
3773 g = o.g / 255,
3774 b = o.b / 255,
3775 min = Math.min(r, g, b),
3776 max = Math.max(r, g, b),
3777 h = NaN,
3778 s = max - min,
3779 l = (max + min) / 2;
3780 if (s) {
3781 if (r === max) h = (g - b) / s + (g < b) * 6;else if (g === max) h = (b - r) / s + 2;else h = (r - g) / s + 4;
3782 s /= l < 0.5 ? max + min : 2 - max - min;
3783 h *= 60;
3784 } else {
3785 s = l > 0 && l < 1 ? 0 : h;
3786 }
3787 return new Hsl(h, s, l, o.opacity);
3788}
3789
3790function hsl(h, s, l, opacity) {
3791 return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
3792}
3793
3794function Hsl(h, s, l, opacity) {
3795 this.h = +h;
3796 this.s = +s;
3797 this.l = +l;
3798 this.opacity = +opacity;
3799}
3800
3801define(Hsl, hsl, extend(Color, {
3802 brighter: function brighter(k) {
3803 k = k == null ? _brighter : Math.pow(_brighter, k);
3804 return new Hsl(this.h, this.s, this.l * k, this.opacity);
3805 },
3806 darker: function darker(k) {
3807 k = k == null ? _darker : Math.pow(_darker, k);
3808 return new Hsl(this.h, this.s, this.l * k, this.opacity);
3809 },
3810 rgb: function rgb$1() {
3811 var h = this.h % 360 + (this.h < 0) * 360,
3812 s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
3813 l = this.l,
3814 m2 = l + (l < 0.5 ? l : 1 - l) * s,
3815 m1 = 2 * l - m2;
3816 return new Rgb(hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2), hsl2rgb(h, m1, m2), hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2), this.opacity);
3817 },
3818 displayable: function displayable() {
3819 return (0 <= this.s && this.s <= 1 || isNaN(this.s)) && 0 <= this.l && this.l <= 1 && 0 <= this.opacity && this.opacity <= 1;
3820 }
3821}));
3822
3823/* From FvD 13.37, CSS Color Module Level 3 */
3824function hsl2rgb(h, m1, m2) {
3825 return (h < 60 ? m1 + (m2 - m1) * h / 60 : h < 180 ? m2 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60 : m1) * 255;
3826}
3827
3828var deg2rad = Math.PI / 180;
3829var rad2deg = 180 / Math.PI;
3830
3831var Kn = 18;
3832var Xn = 0.950470;
3833var Yn = 1;
3834var Zn = 1.088830;
3835var t0 = 4 / 29;
3836var t1 = 6 / 29;
3837var t2 = 3 * t1 * t1;
3838var t3 = t1 * t1 * t1;
3839
3840function labConvert(o) {
3841 if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
3842 if (o instanceof Hcl) {
3843 var h = o.h * deg2rad;
3844 return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
3845 }
3846 if (!(o instanceof Rgb)) o = rgbConvert(o);
3847 var b = rgb2xyz(o.r),
3848 a = rgb2xyz(o.g),
3849 l = rgb2xyz(o.b),
3850 x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
3851 y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
3852 z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
3853 return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
3854}
3855
3856function lab(l, a, b, opacity) {
3857 return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
3858}
3859
3860function Lab(l, a, b, opacity) {
3861 this.l = +l;
3862 this.a = +a;
3863 this.b = +b;
3864 this.opacity = +opacity;
3865}
3866
3867define(Lab, lab, extend(Color, {
3868 brighter: function brighter(k) {
3869 return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
3870 },
3871 darker: function darker(k) {
3872 return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
3873 },
3874 rgb: function rgb() {
3875 var y = (this.l + 16) / 116,
3876 x = isNaN(this.a) ? y : y + this.a / 500,
3877 z = isNaN(this.b) ? y : y - this.b / 200;
3878 y = Yn * lab2xyz(y);
3879 x = Xn * lab2xyz(x);
3880 z = Zn * lab2xyz(z);
3881 return new Rgb(xyz2rgb(3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
3882 xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z), xyz2rgb(0.0556434 * x - 0.2040259 * y + 1.0572252 * z), this.opacity);
3883 }
3884}));
3885
3886function xyz2lab(t) {
3887 return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
3888}
3889
3890function lab2xyz(t) {
3891 return t > t1 ? t * t * t : t2 * (t - t0);
3892}
3893
3894function xyz2rgb(x) {
3895 return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
3896}
3897
3898function rgb2xyz(x) {
3899 return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
3900}
3901
3902function hclConvert(o) {
3903 if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
3904 if (!(o instanceof Lab)) o = labConvert(o);
3905 var h = Math.atan2(o.b, o.a) * rad2deg;
3906 return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
3907}
3908
3909function hcl(h, c, l, opacity) {
3910 return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
3911}
3912
3913function Hcl(h, c, l, opacity) {
3914 this.h = +h;
3915 this.c = +c;
3916 this.l = +l;
3917 this.opacity = +opacity;
3918}
3919
3920define(Hcl, hcl, extend(Color, {
3921 brighter: function brighter(k) {
3922 return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
3923 },
3924 darker: function darker(k) {
3925 return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
3926 },
3927 rgb: function rgb() {
3928 return labConvert(this).rgb();
3929 }
3930}));
3931
3932var A = -0.14861;
3933var B = +1.78277;
3934var C = -0.29227;
3935var D = -0.90649;
3936var E = +1.97294;
3937var ED = E * D;
3938var EB = E * B;
3939var BC_DA = B * C - D * A;
3940
3941function cubehelixConvert(o) {
3942 if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
3943 if (!(o instanceof Rgb)) o = rgbConvert(o);
3944 var r = o.r / 255,
3945 g = o.g / 255,
3946 b = o.b / 255,
3947 l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
3948 bl = b - l,
3949 k = (E * (g - l) - C * bl) / D,
3950 s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)),
3951 // NaN if l=0 or l=1
3952 h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
3953 return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
3954}
3955
3956function cubehelix(h, s, l, opacity) {
3957 return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
3958}
3959
3960function Cubehelix(h, s, l, opacity) {
3961 this.h = +h;
3962 this.s = +s;
3963 this.l = +l;
3964 this.opacity = +opacity;
3965}
3966
3967define(Cubehelix, cubehelix, extend(Color, {
3968 brighter: function brighter(k) {
3969 k = k == null ? _brighter : Math.pow(_brighter, k);
3970 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
3971 },
3972 darker: function darker(k) {
3973 k = k == null ? _darker : Math.pow(_darker, k);
3974 return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
3975 },
3976 rgb: function rgb() {
3977 var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
3978 l = +this.l,
3979 a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
3980 cosh = Math.cos(h),
3981 sinh = Math.sin(h);
3982 return new Rgb(255 * (l + a * (A * cosh + B * sinh)), 255 * (l + a * (C * cosh + D * sinh)), 255 * (l + a * (E * cosh)), this.opacity);
3983 }
3984}));
3985
3986function basis$1(t1, v0, v1, v2, v3) {
3987 var t2 = t1 * t1,
3988 t3 = t2 * t1;
3989 return ((1 - 3 * t1 + 3 * t2 - t3) * v0 + (4 - 6 * t2 + 3 * t3) * v1 + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2 + t3 * v3) / 6;
3990}
3991
3992var basis$2 = function (values) {
3993 var n = values.length - 1;
3994 return function (t) {
3995 var i = t <= 0 ? t = 0 : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
3996 v1 = values[i],
3997 v2 = values[i + 1],
3998 v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
3999 v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
4000 return basis$1((t - i / n) * n, v0, v1, v2, v3);
4001 };
4002};
4003
4004var basisClosed$1 = function (values) {
4005 var n = values.length;
4006 return function (t) {
4007 var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
4008 v0 = values[(i + n - 1) % n],
4009 v1 = values[i % n],
4010 v2 = values[(i + 1) % n],
4011 v3 = values[(i + 2) % n];
4012 return basis$1((t - i / n) * n, v0, v1, v2, v3);
4013 };
4014};
4015
4016var constant$3 = function (x) {
4017 return function () {
4018 return x;
4019 };
4020};
4021
4022function linear$1(a, d) {
4023 return function (t) {
4024 return a + t * d;
4025 };
4026}
4027
4028function exponential$1(a, b, y) {
4029 return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function (t) {
4030 return Math.pow(a + t * b, y);
4031 };
4032}
4033
4034function hue(a, b) {
4035 var d = b - a;
4036 return d ? linear$1(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
4037}
4038
4039function gamma(y) {
4040 return (y = +y) === 1 ? nogamma : function (a, b) {
4041 return b - a ? exponential$1(a, b, y) : constant$3(isNaN(a) ? b : a);
4042 };
4043}
4044
4045function nogamma(a, b) {
4046 var d = b - a;
4047 return d ? linear$1(a, d) : constant$3(isNaN(a) ? b : a);
4048}
4049
4050var interpolateRgb = (function rgbGamma(y) {
4051 var color$$1 = gamma(y);
4052
4053 function rgb$$1(start, end) {
4054 var r = color$$1((start = rgb$1(start)).r, (end = rgb$1(end)).r),
4055 g = color$$1(start.g, end.g),
4056 b = color$$1(start.b, end.b),
4057 opacity = color$$1(start.opacity, end.opacity);
4058 return function (t) {
4059 start.r = r(t);
4060 start.g = g(t);
4061 start.b = b(t);
4062 start.opacity = opacity(t);
4063 return start + "";
4064 };
4065 }
4066
4067 rgb$$1.gamma = rgbGamma;
4068
4069 return rgb$$1;
4070})(1);
4071
4072function rgbSpline(spline) {
4073 return function (colors) {
4074 var n = colors.length,
4075 r = new Array(n),
4076 g = new Array(n),
4077 b = new Array(n),
4078 i,
4079 color$$1;
4080 for (i = 0; i < n; ++i) {
4081 color$$1 = rgb$1(colors[i]);
4082 r[i] = color$$1.r || 0;
4083 g[i] = color$$1.g || 0;
4084 b[i] = color$$1.b || 0;
4085 }
4086 r = spline(r);
4087 g = spline(g);
4088 b = spline(b);
4089 color$$1.opacity = 1;
4090 return function (t) {
4091 color$$1.r = r(t);
4092 color$$1.g = g(t);
4093 color$$1.b = b(t);
4094 return color$$1 + "";
4095 };
4096 };
4097}
4098
4099var rgbBasis = rgbSpline(basis$2);
4100var rgbBasisClosed = rgbSpline(basisClosed$1);
4101
4102var array$1 = function (a, b) {
4103 var nb = b ? b.length : 0,
4104 na = a ? Math.min(nb, a.length) : 0,
4105 x = new Array(nb),
4106 c = new Array(nb),
4107 i;
4108
4109 for (i = 0; i < na; ++i) {
4110 x[i] = interpolate(a[i], b[i]);
4111 }for (; i < nb; ++i) {
4112 c[i] = b[i];
4113 }return function (t) {
4114 for (i = 0; i < na; ++i) {
4115 c[i] = x[i](t);
4116 }return c;
4117 };
4118};
4119
4120var date = function (a, b) {
4121 var d = new Date();
4122 return a = +a, b -= a, function (t) {
4123 return d.setTime(a + b * t), d;
4124 };
4125};
4126
4127var interpolateNumber = function (a, b) {
4128 return a = +a, b -= a, function (t) {
4129 return a + b * t;
4130 };
4131};
4132
4133var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
4134 return typeof obj;
4135} : function (obj) {
4136 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
4137};
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159var get$1 = function get$1(object, property, receiver) {
4160 if (object === null) object = Function.prototype;
4161 var desc = Object.getOwnPropertyDescriptor(object, property);
4162
4163 if (desc === undefined) {
4164 var parent = Object.getPrototypeOf(object);
4165
4166 if (parent === null) {
4167 return undefined;
4168 } else {
4169 return get$1(parent, property, receiver);
4170 }
4171 } else if ("value" in desc) {
4172 return desc.value;
4173 } else {
4174 var getter = desc.get;
4175
4176 if (getter === undefined) {
4177 return undefined;
4178 }
4179
4180 return getter.call(receiver);
4181 }
4182};
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200var set$3 = function set$3(object, property, value, receiver) {
4201 var desc = Object.getOwnPropertyDescriptor(object, property);
4202
4203 if (desc === undefined) {
4204 var parent = Object.getPrototypeOf(object);
4205
4206 if (parent !== null) {
4207 set$3(parent, property, value, receiver);
4208 }
4209 } else if ("value" in desc && desc.writable) {
4210 desc.value = value;
4211 } else {
4212 var setter = desc.set;
4213
4214 if (setter !== undefined) {
4215 setter.call(receiver, value);
4216 }
4217 }
4218
4219 return value;
4220};
4221
4222var object$1 = function (a, b) {
4223 var i = {},
4224 c = {},
4225 k;
4226
4227 if (a === null || (typeof a === "undefined" ? "undefined" : _typeof(a)) !== "object") a = {};
4228 if (b === null || (typeof b === "undefined" ? "undefined" : _typeof(b)) !== "object") b = {};
4229
4230 for (k in b) {
4231 if (k in a) {
4232 i[k] = interpolate(a[k], b[k]);
4233 } else {
4234 c[k] = b[k];
4235 }
4236 }
4237
4238 return function (t) {
4239 for (k in i) {
4240 c[k] = i[k](t);
4241 }return c;
4242 };
4243};
4244
4245var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
4246var reB = new RegExp(reA.source, "g");
4247
4248function zero(b) {
4249 return function () {
4250 return b;
4251 };
4252}
4253
4254function one(b) {
4255 return function (t) {
4256 return b(t) + "";
4257 };
4258}
4259
4260var interpolateString = function (a, b) {
4261 var bi = reA.lastIndex = reB.lastIndex = 0,
4262 // scan index for next number in b
4263 am,
4264 // current match in a
4265 bm,
4266 // current match in b
4267 bs,
4268 // string preceding current number in b, if any
4269 i = -1,
4270 // index in s
4271 s = [],
4272 // string constants and placeholders
4273 q = []; // number interpolators
4274
4275 // Coerce inputs to strings.
4276 a = a + "", b = b + "";
4277
4278 // Interpolate pairs of numbers in a & b.
4279 while ((am = reA.exec(a)) && (bm = reB.exec(b))) {
4280 if ((bs = bm.index) > bi) {
4281 // a string precedes the next number in b
4282 bs = b.slice(bi, bs);
4283 if (s[i]) s[i] += bs; // coalesce with previous string
4284 else s[++i] = bs;
4285 }
4286 if ((am = am[0]) === (bm = bm[0])) {
4287 // numbers in a & b match
4288 if (s[i]) s[i] += bm; // coalesce with previous string
4289 else s[++i] = bm;
4290 } else {
4291 // interpolate non-matching numbers
4292 s[++i] = null;
4293 q.push({ i: i, x: interpolateNumber(am, bm) });
4294 }
4295 bi = reB.lastIndex;
4296 }
4297
4298 // Add remains of b.
4299 if (bi < b.length) {
4300 bs = b.slice(bi);
4301 if (s[i]) s[i] += bs; // coalesce with previous string
4302 else s[++i] = bs;
4303 }
4304
4305 // Special optimization for only a single match.
4306 // Otherwise, interpolate each of the numbers and rejoin the string.
4307 return s.length < 2 ? q[0] ? one(q[0].x) : zero(b) : (b = q.length, function (t) {
4308 for (var i = 0, o; i < b; ++i) {
4309 s[(o = q[i]).i] = o.x(t);
4310 }return s.join("");
4311 });
4312};
4313
4314var interpolate = function (a, b) {
4315 var t = typeof b === "undefined" ? "undefined" : _typeof(b),
4316 c;
4317 return b == null || t === "boolean" ? constant$3(b) : (t === "number" ? interpolateNumber : t === "string" ? (c = color(b)) ? (b = c, interpolateRgb) : interpolateString : b instanceof color ? interpolateRgb : b instanceof Date ? date : Array.isArray(b) ? array$1 : isNaN(b) ? object$1 : interpolateNumber)(a, b);
4318};
4319
4320var interpolateRound = function (a, b) {
4321 return a = +a, b -= a, function (t) {
4322 return Math.round(a + b * t);
4323 };
4324};
4325
4326var degrees = 180 / Math.PI;
4327
4328var identity$2 = {
4329 translateX: 0,
4330 translateY: 0,
4331 rotate: 0,
4332 skewX: 0,
4333 scaleX: 1,
4334 scaleY: 1
4335};
4336
4337var decompose = function (a, b, c, d, e, f) {
4338 var scaleX, scaleY, skewX;
4339 if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
4340 if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
4341 if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
4342 if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
4343 return {
4344 translateX: e,
4345 translateY: f,
4346 rotate: Math.atan2(b, a) * degrees,
4347 skewX: Math.atan(skewX) * degrees,
4348 scaleX: scaleX,
4349 scaleY: scaleY
4350 };
4351};
4352
4353var cssNode;
4354var cssRoot;
4355var cssView;
4356var svgNode;
4357
4358function parseCss(value) {
4359 if (value === "none") return identity$2;
4360 if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
4361 cssNode.style.transform = value;
4362 value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
4363 cssRoot.removeChild(cssNode);
4364 value = value.slice(7, -1).split(",");
4365 return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
4366}
4367
4368function parseSvg(value) {
4369 if (value == null) return identity$2;
4370 if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
4371 svgNode.setAttribute("transform", value);
4372 if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
4373 value = value.matrix;
4374 return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
4375}
4376
4377function interpolateTransform(parse, pxComma, pxParen, degParen) {
4378
4379 function pop(s) {
4380 return s.length ? s.pop() + " " : "";
4381 }
4382
4383 function translate(xa, ya, xb, yb, s, q) {
4384 if (xa !== xb || ya !== yb) {
4385 var i = s.push("translate(", null, pxComma, null, pxParen);
4386 q.push({ i: i - 4, x: interpolateNumber(xa, xb) }, { i: i - 2, x: interpolateNumber(ya, yb) });
4387 } else if (xb || yb) {
4388 s.push("translate(" + xb + pxComma + yb + pxParen);
4389 }
4390 }
4391
4392 function rotate(a, b, s, q) {
4393 if (a !== b) {
4394 if (a - b > 180) b += 360;else if (b - a > 180) a += 360; // shortest path
4395 q.push({ i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b) });
4396 } else if (b) {
4397 s.push(pop(s) + "rotate(" + b + degParen);
4398 }
4399 }
4400
4401 function skewX(a, b, s, q) {
4402 if (a !== b) {
4403 q.push({ i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b) });
4404 } else if (b) {
4405 s.push(pop(s) + "skewX(" + b + degParen);
4406 }
4407 }
4408
4409 function scale(xa, ya, xb, yb, s, q) {
4410 if (xa !== xb || ya !== yb) {
4411 var i = s.push(pop(s) + "scale(", null, ",", null, ")");
4412 q.push({ i: i - 4, x: interpolateNumber(xa, xb) }, { i: i - 2, x: interpolateNumber(ya, yb) });
4413 } else if (xb !== 1 || yb !== 1) {
4414 s.push(pop(s) + "scale(" + xb + "," + yb + ")");
4415 }
4416 }
4417
4418 return function (a, b) {
4419 var s = [],
4420 // string constants and placeholders
4421 q = []; // number interpolators
4422 a = parse(a), b = parse(b);
4423 translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
4424 rotate(a.rotate, b.rotate, s, q);
4425 skewX(a.skewX, b.skewX, s, q);
4426 scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
4427 a = b = null; // gc
4428 return function (t) {
4429 var i = -1,
4430 n = q.length,
4431 o;
4432 while (++i < n) {
4433 s[(o = q[i]).i] = o.x(t);
4434 }return s.join("");
4435 };
4436 };
4437}
4438
4439var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
4440var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
4441
4442var rho = Math.SQRT2;
4443var rho2 = 2;
4444var rho4 = 4;
4445var epsilon2 = 1e-12;
4446
4447function cosh(x) {
4448 return ((x = Math.exp(x)) + 1 / x) / 2;
4449}
4450
4451function sinh(x) {
4452 return ((x = Math.exp(x)) - 1 / x) / 2;
4453}
4454
4455function tanh(x) {
4456 return ((x = Math.exp(2 * x)) - 1) / (x + 1);
4457}
4458
4459// p0 = [ux0, uy0, w0]
4460// p1 = [ux1, uy1, w1]
4461var interpolateZoom = function (p0, p1) {
4462 var ux0 = p0[0],
4463 uy0 = p0[1],
4464 w0 = p0[2],
4465 ux1 = p1[0],
4466 uy1 = p1[1],
4467 w1 = p1[2],
4468 dx = ux1 - ux0,
4469 dy = uy1 - uy0,
4470 d2 = dx * dx + dy * dy,
4471 i,
4472 S;
4473
4474 // Special case for u0 ≅ u1.
4475 if (d2 < epsilon2) {
4476 S = Math.log(w1 / w0) / rho;
4477 i = function i(t) {
4478 return [ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(rho * t * S)];
4479 };
4480 }
4481
4482 // General case.
4483 else {
4484 var d1 = Math.sqrt(d2),
4485 b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
4486 b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
4487 r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
4488 r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
4489 S = (r1 - r0) / rho;
4490 i = function i(t) {
4491 var s = t * S,
4492 coshr0 = cosh(r0),
4493 u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
4494 return [ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / cosh(rho * s + r0)];
4495 };
4496 }
4497
4498 i.duration = S * 1000;
4499
4500 return i;
4501};
4502
4503function hsl$1(hue$$1) {
4504 return function (start, end) {
4505 var h = hue$$1((start = hsl(start)).h, (end = hsl(end)).h),
4506 s = nogamma(start.s, end.s),
4507 l = nogamma(start.l, end.l),
4508 opacity = nogamma(start.opacity, end.opacity);
4509 return function (t) {
4510 start.h = h(t);
4511 start.s = s(t);
4512 start.l = l(t);
4513 start.opacity = opacity(t);
4514 return start + "";
4515 };
4516 };
4517}
4518
4519var hsl$2 = hsl$1(hue);
4520var hslLong = hsl$1(nogamma);
4521
4522function lab$1(start, end) {
4523 var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
4524 a = nogamma(start.a, end.a),
4525 b = nogamma(start.b, end.b),
4526 opacity = nogamma(start.opacity, end.opacity);
4527 return function (t) {
4528 start.l = l(t);
4529 start.a = a(t);
4530 start.b = b(t);
4531 start.opacity = opacity(t);
4532 return start + "";
4533 };
4534}
4535
4536function hcl$1(hue$$1) {
4537 return function (start, end) {
4538 var h = hue$$1((start = hcl(start)).h, (end = hcl(end)).h),
4539 c = nogamma(start.c, end.c),
4540 l = nogamma(start.l, end.l),
4541 opacity = nogamma(start.opacity, end.opacity);
4542 return function (t) {
4543 start.h = h(t);
4544 start.c = c(t);
4545 start.l = l(t);
4546 start.opacity = opacity(t);
4547 return start + "";
4548 };
4549 };
4550}
4551
4552var hcl$2 = hcl$1(hue);
4553var hclLong = hcl$1(nogamma);
4554
4555function cubehelix$1(hue$$1) {
4556 return function cubehelixGamma(y) {
4557 y = +y;
4558
4559 function cubehelix$$1(start, end) {
4560 var h = hue$$1((start = cubehelix(start)).h, (end = cubehelix(end)).h),
4561 s = nogamma(start.s, end.s),
4562 l = nogamma(start.l, end.l),
4563 opacity = nogamma(start.opacity, end.opacity);
4564 return function (t) {
4565 start.h = h(t);
4566 start.s = s(t);
4567 start.l = l(Math.pow(t, y));
4568 start.opacity = opacity(t);
4569 return start + "";
4570 };
4571 }
4572
4573 cubehelix$$1.gamma = cubehelixGamma;
4574
4575 return cubehelix$$1;
4576 }(1);
4577}
4578
4579var cubehelix$2 = cubehelix$1(hue);
4580var cubehelixLong = cubehelix$1(nogamma);
4581
4582var quantize = function (interpolator, n) {
4583 var samples = new Array(n);
4584 for (var i = 0; i < n; ++i) {
4585 samples[i] = interpolator(i / (n - 1));
4586 }return samples;
4587};
4588
4589var noop$1 = { value: function value() {} };
4590
4591function dispatch() {
4592 for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
4593 if (!(t = arguments[i] + "") || t in _) throw new Error("illegal type: " + t);
4594 _[t] = [];
4595 }
4596 return new Dispatch(_);
4597}
4598
4599function Dispatch(_) {
4600 this._ = _;
4601}
4602
4603function parseTypenames(typenames, types) {
4604 return typenames.trim().split(/^|\s+/).map(function (t) {
4605 var name = "",
4606 i = t.indexOf(".");
4607 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
4608 if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
4609 return { type: t, name: name };
4610 });
4611}
4612
4613Dispatch.prototype = dispatch.prototype = {
4614 constructor: Dispatch,
4615 on: function on(typename, callback) {
4616 var _ = this._,
4617 T = parseTypenames(typename + "", _),
4618 t,
4619 i = -1,
4620 n = T.length;
4621
4622 // If no callback was specified, return the callback of the given type and name.
4623 if (arguments.length < 2) {
4624 while (++i < n) {
4625 if ((t = (typename = T[i]).type) && (t = get$2(_[t], typename.name))) return t;
4626 }return;
4627 }
4628
4629 // If a type was specified, set the callback for the given type and name.
4630 // Otherwise, if a null callback was specified, remove callbacks of the given name.
4631 if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
4632 while (++i < n) {
4633 if (t = (typename = T[i]).type) _[t] = set$4(_[t], typename.name, callback);else if (callback == null) for (t in _) {
4634 _[t] = set$4(_[t], typename.name, null);
4635 }
4636 }
4637
4638 return this;
4639 },
4640 copy: function copy() {
4641 var copy = {},
4642 _ = this._;
4643 for (var t in _) {
4644 copy[t] = _[t].slice();
4645 }return new Dispatch(copy);
4646 },
4647 call: function call(type, that) {
4648 if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) {
4649 args[i] = arguments[i + 2];
4650 }if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
4651 for (t = this._[type], i = 0, n = t.length; i < n; ++i) {
4652 t[i].value.apply(that, args);
4653 }
4654 },
4655 apply: function apply(type, that, args) {
4656 if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
4657 for (var t = this._[type], i = 0, n = t.length; i < n; ++i) {
4658 t[i].value.apply(that, args);
4659 }
4660 }
4661};
4662
4663function get$2(type, name) {
4664 for (var i = 0, n = type.length, c; i < n; ++i) {
4665 if ((c = type[i]).name === name) {
4666 return c.value;
4667 }
4668 }
4669}
4670
4671function set$4(type, name, callback) {
4672 for (var i = 0, n = type.length; i < n; ++i) {
4673 if (type[i].name === name) {
4674 type[i] = noop$1, type = type.slice(0, i).concat(type.slice(i + 1));
4675 break;
4676 }
4677 }
4678 if (callback != null) type.push({ name: name, value: callback });
4679 return type;
4680}
4681
4682function objectConverter(columns) {
4683 return new Function("d", "return {" + columns.map(function (name, i) {
4684 return JSON.stringify(name) + ": d[" + i + "]";
4685 }).join(",") + "}");
4686}
4687
4688function customConverter(columns, f) {
4689 var object = objectConverter(columns);
4690 return function (row, i) {
4691 return f(object(row), i, columns);
4692 };
4693}
4694
4695// Compute unique columns in order of discovery.
4696function inferColumns(rows) {
4697 var columnSet = Object.create(null),
4698 columns = [];
4699
4700 rows.forEach(function (row) {
4701 for (var column in row) {
4702 if (!(column in columnSet)) {
4703 columns.push(columnSet[column] = column);
4704 }
4705 }
4706 });
4707
4708 return columns;
4709}
4710
4711var dsv = function (delimiter) {
4712 var reFormat = new RegExp("[\"" + delimiter + "\n]"),
4713 delimiterCode = delimiter.charCodeAt(0);
4714
4715 function parse(text, f) {
4716 var convert,
4717 columns,
4718 rows = parseRows(text, function (row, i) {
4719 if (convert) return convert(row, i - 1);
4720 columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
4721 });
4722 rows.columns = columns;
4723 return rows;
4724 }
4725
4726 function parseRows(text, f) {
4727 var EOL = {},
4728 // sentinel value for end-of-line
4729 EOF = {},
4730 // sentinel value for end-of-file
4731 rows = [],
4732 // output rows
4733 N = text.length,
4734 I = 0,
4735 // current character index
4736 n = 0,
4737 // the current line number
4738 t,
4739 // the current token
4740 eol; // is the current token followed by EOL?
4741
4742 function token() {
4743 if (I >= N) return EOF; // special case: end of file
4744 if (eol) return eol = false, EOL; // special case: end of line
4745
4746 // special case: quotes
4747 var j = I,
4748 c;
4749 if (text.charCodeAt(j) === 34) {
4750 var i = j;
4751 while (i++ < N) {
4752 if (text.charCodeAt(i) === 34) {
4753 if (text.charCodeAt(i + 1) !== 34) break;
4754 ++i;
4755 }
4756 }
4757 I = i + 2;
4758 c = text.charCodeAt(i + 1);
4759 if (c === 13) {
4760 eol = true;
4761 if (text.charCodeAt(i + 2) === 10) ++I;
4762 } else if (c === 10) {
4763 eol = true;
4764 }
4765 return text.slice(j + 1, i).replace(/""/g, "\"");
4766 }
4767
4768 // common case: find next delimiter or newline
4769 while (I < N) {
4770 var k = 1;
4771 c = text.charCodeAt(I++);
4772 if (c === 10) eol = true; // \n
4773 else if (c === 13) {
4774 eol = true;if (text.charCodeAt(I) === 10) ++I, ++k;
4775 } // \r|\r\n
4776 else if (c !== delimiterCode) continue;
4777 return text.slice(j, I - k);
4778 }
4779
4780 // special case: last token before EOF
4781 return text.slice(j);
4782 }
4783
4784 while ((t = token()) !== EOF) {
4785 var a = [];
4786 while (t !== EOL && t !== EOF) {
4787 a.push(t);
4788 t = token();
4789 }
4790 if (f && (a = f(a, n++)) == null) continue;
4791 rows.push(a);
4792 }
4793
4794 return rows;
4795 }
4796
4797 function format(rows, columns) {
4798 if (columns == null) columns = inferColumns(rows);
4799 return [columns.map(formatValue).join(delimiter)].concat(rows.map(function (row) {
4800 return columns.map(function (column) {
4801 return formatValue(row[column]);
4802 }).join(delimiter);
4803 })).join("\n");
4804 }
4805
4806 function formatRows(rows) {
4807 return rows.map(formatRow).join("\n");
4808 }
4809
4810 function formatRow(row) {
4811 return row.map(formatValue).join(delimiter);
4812 }
4813
4814 function formatValue(text) {
4815 return text == null ? "" : reFormat.test(text += "") ? "\"" + text.replace(/\"/g, "\"\"") + "\"" : text;
4816 }
4817
4818 return {
4819 parse: parse,
4820 parseRows: parseRows,
4821 format: format,
4822 formatRows: formatRows
4823 };
4824};
4825
4826var csv = dsv(",");
4827
4828var csvParse = csv.parse;
4829var csvParseRows = csv.parseRows;
4830var csvFormat = csv.format;
4831var csvFormatRows = csv.formatRows;
4832
4833var tsv = dsv("\t");
4834
4835var tsvParse = tsv.parse;
4836var tsvParseRows = tsv.parseRows;
4837var tsvFormat = tsv.format;
4838var tsvFormatRows = tsv.formatRows;
4839
4840var frame = 0;
4841var timeout = 0;
4842var interval = 0;
4843var pokeDelay = 1000;
4844var taskHead;
4845var taskTail;
4846var clockLast = 0;
4847var clockNow = 0;
4848var clockSkew = 0;
4849var clock = (typeof performance === "undefined" ? "undefined" : _typeof(performance)) === "object" && performance.now ? performance : Date;
4850var setFrame = typeof requestAnimationFrame === "function" ? requestAnimationFrame : function (f) {
4851 setTimeout(f, 17);
4852};
4853
4854function now() {
4855 return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
4856}
4857
4858function clearNow() {
4859 clockNow = 0;
4860}
4861
4862function Timer() {
4863 this._call = this._time = this._next = null;
4864}
4865
4866Timer.prototype = timer.prototype = {
4867 constructor: Timer,
4868 restart: function restart(callback, delay, time) {
4869 if (typeof callback !== "function") throw new TypeError("callback is not a function");
4870 time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
4871 if (!this._next && taskTail !== this) {
4872 if (taskTail) taskTail._next = this;else taskHead = this;
4873 taskTail = this;
4874 }
4875 this._call = callback;
4876 this._time = time;
4877 sleep();
4878 },
4879 stop: function stop() {
4880 if (this._call) {
4881 this._call = null;
4882 this._time = Infinity;
4883 sleep();
4884 }
4885 }
4886};
4887
4888function timer(callback, delay, time) {
4889 var t = new Timer();
4890 t.restart(callback, delay, time);
4891 return t;
4892}
4893
4894function timerFlush() {
4895 now(); // Get the current time, if not already set.
4896 ++frame; // Pretend we’ve set an alarm, if we haven’t already.
4897 var t = taskHead,
4898 e;
4899 while (t) {
4900 if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
4901 t = t._next;
4902 }
4903 --frame;
4904}
4905
4906function wake() {
4907 clockNow = (clockLast = clock.now()) + clockSkew;
4908 frame = timeout = 0;
4909 try {
4910 timerFlush();
4911 } finally {
4912 frame = 0;
4913 nap();
4914 clockNow = 0;
4915 }
4916}
4917
4918function poke() {
4919 var now = clock.now(),
4920 delay = now - clockLast;
4921 if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
4922}
4923
4924function nap() {
4925 var t0,
4926 t1 = taskHead,
4927 t2,
4928 time = Infinity;
4929 while (t1) {
4930 if (t1._call) {
4931 if (time > t1._time) time = t1._time;
4932 t0 = t1, t1 = t1._next;
4933 } else {
4934 t2 = t1._next, t1._next = null;
4935 t1 = t0 ? t0._next = t2 : taskHead = t2;
4936 }
4937 }
4938 taskTail = t0;
4939 sleep(time);
4940}
4941
4942function sleep(time) {
4943 if (frame) return; // Soonest alarm already set, or will be.
4944 if (timeout) timeout = clearTimeout(timeout);
4945 var delay = time - clockNow;
4946 if (delay > 24) {
4947 if (time < Infinity) timeout = setTimeout(wake, delay);
4948 if (interval) interval = clearInterval(interval);
4949 } else {
4950 if (!interval) interval = setInterval(poke, pokeDelay);
4951 frame = 1, setFrame(wake);
4952 }
4953}
4954
4955var timeout$1 = function (callback, delay, time) {
4956 var t = new Timer();
4957 delay = delay == null ? 0 : +delay;
4958 t.restart(function (elapsed) {
4959 t.stop();
4960 callback(elapsed + delay);
4961 }, delay, time);
4962 return t;
4963};
4964
4965var interval$1 = function (callback, delay, time) {
4966 var t = new Timer(),
4967 total = delay;
4968 if (delay == null) return t.restart(callback, delay, time), t;
4969 delay = +delay, time = time == null ? now() : +time;
4970 t.restart(function tick(elapsed) {
4971 elapsed += total;
4972 t.restart(tick, total += delay, time);
4973 callback(elapsed);
4974 }, delay, time);
4975 return t;
4976};
4977
4978var t0$1 = new Date();
4979var t1$1 = new Date();
4980
4981function newInterval(floori, offseti, count, field) {
4982
4983 function interval(date) {
4984 return floori(date = new Date(+date)), date;
4985 }
4986
4987 interval.floor = interval;
4988
4989 interval.ceil = function (date) {
4990 return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
4991 };
4992
4993 interval.round = function (date) {
4994 var d0 = interval(date),
4995 d1 = interval.ceil(date);
4996 return date - d0 < d1 - date ? d0 : d1;
4997 };
4998
4999 interval.offset = function (date, step) {
5000 return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
5001 };
5002
5003 interval.range = function (start, stop, step) {
5004 var range = [];
5005 start = interval.ceil(start);
5006 step = step == null ? 1 : Math.floor(step);
5007 if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
5008 do {
5009 range.push(new Date(+start));
5010 } while ((offseti(start, step), floori(start), start < stop));
5011 return range;
5012 };
5013
5014 interval.filter = function (test) {
5015 return newInterval(function (date) {
5016 if (date >= date) while (floori(date), !test(date)) {
5017 date.setTime(date - 1);
5018 }
5019 }, function (date, step) {
5020 if (date >= date) while (--step >= 0) {
5021 while (offseti(date, 1), !test(date)) {}
5022 } // eslint-disable-line no-empty
5023 });
5024 };
5025
5026 if (count) {
5027 interval.count = function (start, end) {
5028 t0$1.setTime(+start), t1$1.setTime(+end);
5029 floori(t0$1), floori(t1$1);
5030 return Math.floor(count(t0$1, t1$1));
5031 };
5032
5033 interval.every = function (step) {
5034 step = Math.floor(step);
5035 return !isFinite(step) || !(step > 0) ? null : !(step > 1) ? interval : interval.filter(field ? function (d) {
5036 return field(d) % step === 0;
5037 } : function (d) {
5038 return interval.count(0, d) % step === 0;
5039 });
5040 };
5041 }
5042
5043 return interval;
5044}
5045
5046var millisecond = newInterval(function () {
5047 // noop
5048}, function (date, step) {
5049 date.setTime(+date + step);
5050}, function (start, end) {
5051 return end - start;
5052});
5053
5054// An optimized implementation for this simple case.
5055millisecond.every = function (k) {
5056 k = Math.floor(k);
5057 if (!isFinite(k) || !(k > 0)) return null;
5058 if (!(k > 1)) return millisecond;
5059 return newInterval(function (date) {
5060 date.setTime(Math.floor(date / k) * k);
5061 }, function (date, step) {
5062 date.setTime(+date + step * k);
5063 }, function (start, end) {
5064 return (end - start) / k;
5065 });
5066};
5067
5068var milliseconds = millisecond.range;
5069
5070var durationSecond = 1e3;
5071var durationMinute = 6e4;
5072var durationHour = 36e5;
5073var durationDay = 864e5;
5074var durationWeek = 6048e5;
5075
5076var second = newInterval(function (date) {
5077 date.setTime(Math.floor(date / durationSecond) * durationSecond);
5078}, function (date, step) {
5079 date.setTime(+date + step * durationSecond);
5080}, function (start, end) {
5081 return (end - start) / durationSecond;
5082}, function (date) {
5083 return date.getUTCSeconds();
5084});
5085
5086var seconds = second.range;
5087
5088var minute = newInterval(function (date) {
5089 date.setTime(Math.floor(date / durationMinute) * durationMinute);
5090}, function (date, step) {
5091 date.setTime(+date + step * durationMinute);
5092}, function (start, end) {
5093 return (end - start) / durationMinute;
5094}, function (date) {
5095 return date.getMinutes();
5096});
5097
5098var minutes = minute.range;
5099
5100var hour = newInterval(function (date) {
5101 var offset = date.getTimezoneOffset() * durationMinute % durationHour;
5102 if (offset < 0) offset += durationHour;
5103 date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
5104}, function (date, step) {
5105 date.setTime(+date + step * durationHour);
5106}, function (start, end) {
5107 return (end - start) / durationHour;
5108}, function (date) {
5109 return date.getHours();
5110});
5111
5112var hours = hour.range;
5113
5114var day = newInterval(function (date) {
5115 date.setHours(0, 0, 0, 0);
5116}, function (date, step) {
5117 date.setDate(date.getDate() + step);
5118}, function (start, end) {
5119 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
5120}, function (date) {
5121 return date.getDate() - 1;
5122});
5123
5124var days = day.range;
5125
5126function weekday(i) {
5127 return newInterval(function (date) {
5128 date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
5129 date.setHours(0, 0, 0, 0);
5130 }, function (date, step) {
5131 date.setDate(date.getDate() + step * 7);
5132 }, function (start, end) {
5133 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
5134 });
5135}
5136
5137var sunday = weekday(0);
5138var monday = weekday(1);
5139var tuesday = weekday(2);
5140var wednesday = weekday(3);
5141var thursday = weekday(4);
5142var friday = weekday(5);
5143var saturday = weekday(6);
5144
5145var sundays = sunday.range;
5146var mondays = monday.range;
5147var tuesdays = tuesday.range;
5148var wednesdays = wednesday.range;
5149var thursdays = thursday.range;
5150var fridays = friday.range;
5151var saturdays = saturday.range;
5152
5153var month = newInterval(function (date) {
5154 date.setDate(1);
5155 date.setHours(0, 0, 0, 0);
5156}, function (date, step) {
5157 date.setMonth(date.getMonth() + step);
5158}, function (start, end) {
5159 return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
5160}, function (date) {
5161 return date.getMonth();
5162});
5163
5164var months = month.range;
5165
5166var year = newInterval(function (date) {
5167 date.setMonth(0, 1);
5168 date.setHours(0, 0, 0, 0);
5169}, function (date, step) {
5170 date.setFullYear(date.getFullYear() + step);
5171}, function (start, end) {
5172 return end.getFullYear() - start.getFullYear();
5173}, function (date) {
5174 return date.getFullYear();
5175});
5176
5177// An optimized implementation for this simple case.
5178year.every = function (k) {
5179 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function (date) {
5180 date.setFullYear(Math.floor(date.getFullYear() / k) * k);
5181 date.setMonth(0, 1);
5182 date.setHours(0, 0, 0, 0);
5183 }, function (date, step) {
5184 date.setFullYear(date.getFullYear() + step * k);
5185 });
5186};
5187
5188var years = year.range;
5189
5190var utcMinute = newInterval(function (date) {
5191 date.setUTCSeconds(0, 0);
5192}, function (date, step) {
5193 date.setTime(+date + step * durationMinute);
5194}, function (start, end) {
5195 return (end - start) / durationMinute;
5196}, function (date) {
5197 return date.getUTCMinutes();
5198});
5199
5200var utcMinutes = utcMinute.range;
5201
5202var utcHour = newInterval(function (date) {
5203 date.setUTCMinutes(0, 0, 0);
5204}, function (date, step) {
5205 date.setTime(+date + step * durationHour);
5206}, function (start, end) {
5207 return (end - start) / durationHour;
5208}, function (date) {
5209 return date.getUTCHours();
5210});
5211
5212var utcHours = utcHour.range;
5213
5214var utcDay = newInterval(function (date) {
5215 date.setUTCHours(0, 0, 0, 0);
5216}, function (date, step) {
5217 date.setUTCDate(date.getUTCDate() + step);
5218}, function (start, end) {
5219 return (end - start) / durationDay;
5220}, function (date) {
5221 return date.getUTCDate() - 1;
5222});
5223
5224var utcDays = utcDay.range;
5225
5226function utcWeekday(i) {
5227 return newInterval(function (date) {
5228 date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
5229 date.setUTCHours(0, 0, 0, 0);
5230 }, function (date, step) {
5231 date.setUTCDate(date.getUTCDate() + step * 7);
5232 }, function (start, end) {
5233 return (end - start) / durationWeek;
5234 });
5235}
5236
5237var utcSunday = utcWeekday(0);
5238var utcMonday = utcWeekday(1);
5239var utcTuesday = utcWeekday(2);
5240var utcWednesday = utcWeekday(3);
5241var utcThursday = utcWeekday(4);
5242var utcFriday = utcWeekday(5);
5243var utcSaturday = utcWeekday(6);
5244
5245var utcSundays = utcSunday.range;
5246var utcMondays = utcMonday.range;
5247var utcTuesdays = utcTuesday.range;
5248var utcWednesdays = utcWednesday.range;
5249var utcThursdays = utcThursday.range;
5250var utcFridays = utcFriday.range;
5251var utcSaturdays = utcSaturday.range;
5252
5253var utcMonth = newInterval(function (date) {
5254 date.setUTCDate(1);
5255 date.setUTCHours(0, 0, 0, 0);
5256}, function (date, step) {
5257 date.setUTCMonth(date.getUTCMonth() + step);
5258}, function (start, end) {
5259 return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
5260}, function (date) {
5261 return date.getUTCMonth();
5262});
5263
5264var utcMonths = utcMonth.range;
5265
5266var utcYear = newInterval(function (date) {
5267 date.setUTCMonth(0, 1);
5268 date.setUTCHours(0, 0, 0, 0);
5269}, function (date, step) {
5270 date.setUTCFullYear(date.getUTCFullYear() + step);
5271}, function (start, end) {
5272 return end.getUTCFullYear() - start.getUTCFullYear();
5273}, function (date) {
5274 return date.getUTCFullYear();
5275});
5276
5277// An optimized implementation for this simple case.
5278utcYear.every = function (k) {
5279 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function (date) {
5280 date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
5281 date.setUTCMonth(0, 1);
5282 date.setUTCHours(0, 0, 0, 0);
5283 }, function (date, step) {
5284 date.setUTCFullYear(date.getUTCFullYear() + step * k);
5285 });
5286};
5287
5288var utcYears = utcYear.range;
5289
5290// Computes the decimal coefficient and exponent of the specified number x with
5291// significant digits p, where x is positive and p is in [1, 21] or undefined.
5292// For example, formatDecimal(1.23) returns ["123", 0].
5293var formatDecimal = function (x, p) {
5294 if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
5295 var i,
5296 coefficient = x.slice(0, i);
5297
5298 // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
5299 // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
5300 return [coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient, +x.slice(i + 1)];
5301};
5302
5303var exponent$1 = function (x) {
5304 return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
5305};
5306
5307var formatGroup = function (grouping, thousands) {
5308 return function (value, width) {
5309 var i = value.length,
5310 t = [],
5311 j = 0,
5312 g = grouping[0],
5313 length = 0;
5314
5315 while (i > 0 && g > 0) {
5316 if (length + g + 1 > width) g = Math.max(1, width - length);
5317 t.push(value.substring(i -= g, i + g));
5318 if ((length += g + 1) > width) break;
5319 g = grouping[j = (j + 1) % grouping.length];
5320 }
5321
5322 return t.reverse().join(thousands);
5323 };
5324};
5325
5326var formatDefault = function (x, p) {
5327 x = x.toPrecision(p);
5328
5329 out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
5330 switch (x[i]) {
5331 case ".":
5332 i0 = i1 = i;break;
5333 case "0":
5334 if (i0 === 0) i0 = i;i1 = i;break;
5335 case "e":
5336 break out;
5337 default:
5338 if (i0 > 0) i0 = 0;break;
5339 }
5340 }
5341
5342 return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
5343};
5344
5345var prefixExponent;
5346
5347var formatPrefixAuto = function (x, p) {
5348 var d = formatDecimal(x, p);
5349 if (!d) return x + "";
5350 var coefficient = d[0],
5351 exponent = d[1],
5352 i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
5353 n = coefficient.length;
5354 return i === n ? coefficient : i > n ? coefficient + new Array(i - n + 1).join("0") : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i) : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
5355};
5356
5357var formatRounded = function (x, p) {
5358 var d = formatDecimal(x, p);
5359 if (!d) return x + "";
5360 var coefficient = d[0],
5361 exponent = d[1];
5362 return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1) : coefficient + new Array(exponent - coefficient.length + 2).join("0");
5363};
5364
5365var formatTypes = {
5366 "": formatDefault,
5367 "%": function _(x, p) {
5368 return (x * 100).toFixed(p);
5369 },
5370 "b": function b(x) {
5371 return Math.round(x).toString(2);
5372 },
5373 "c": function c(x) {
5374 return x + "";
5375 },
5376 "d": function d(x) {
5377 return Math.round(x).toString(10);
5378 },
5379 "e": function e(x, p) {
5380 return x.toExponential(p);
5381 },
5382 "f": function f(x, p) {
5383 return x.toFixed(p);
5384 },
5385 "g": function g(x, p) {
5386 return x.toPrecision(p);
5387 },
5388 "o": function o(x) {
5389 return Math.round(x).toString(8);
5390 },
5391 "p": function p(x, _p) {
5392 return formatRounded(x * 100, _p);
5393 },
5394 "r": formatRounded,
5395 "s": formatPrefixAuto,
5396 "X": function X(x) {
5397 return Math.round(x).toString(16).toUpperCase();
5398 },
5399 "x": function x(_x) {
5400 return Math.round(_x).toString(16);
5401 }
5402};
5403
5404// [[fill]align][sign][symbol][0][width][,][.precision][type]
5405var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
5406
5407var formatSpecifier = function (specifier) {
5408 return new FormatSpecifier(specifier);
5409};
5410
5411function FormatSpecifier(specifier) {
5412 if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
5413
5414 var match,
5415 fill = match[1] || " ",
5416 align = match[2] || ">",
5417 sign = match[3] || "-",
5418 symbol = match[4] || "",
5419 zero = !!match[5],
5420 width = match[6] && +match[6],
5421 comma = !!match[7],
5422 precision = match[8] && +match[8].slice(1),
5423 type = match[9] || "";
5424
5425 // The "n" type is an alias for ",g".
5426 if (type === "n") comma = true, type = "g";
5427
5428 // Map invalid types to the default format.
5429 else if (!formatTypes[type]) type = "";
5430
5431 // If zero fill is specified, padding goes after sign and before digits.
5432 if (zero || fill === "0" && align === "=") zero = true, fill = "0", align = "=";
5433
5434 this.fill = fill;
5435 this.align = align;
5436 this.sign = sign;
5437 this.symbol = symbol;
5438 this.zero = zero;
5439 this.width = width;
5440 this.comma = comma;
5441 this.precision = precision;
5442 this.type = type;
5443}
5444
5445FormatSpecifier.prototype.toString = function () {
5446 return this.fill + this.align + this.sign + this.symbol + (this.zero ? "0" : "") + (this.width == null ? "" : Math.max(1, this.width | 0)) + (this.comma ? "," : "") + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0)) + this.type;
5447};
5448
5449var prefixes = ["y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y"];
5450
5451function identity$3(x) {
5452 return x;
5453}
5454
5455var formatLocale = function (locale) {
5456 var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
5457 currency = locale.currency,
5458 decimal = locale.decimal;
5459
5460 function newFormat(specifier) {
5461 specifier = formatSpecifier(specifier);
5462
5463 var fill = specifier.fill,
5464 align = specifier.align,
5465 sign = specifier.sign,
5466 symbol = specifier.symbol,
5467 zero = specifier.zero,
5468 width = specifier.width,
5469 comma = specifier.comma,
5470 precision = specifier.precision,
5471 type = specifier.type;
5472
5473 // Compute the prefix and suffix.
5474 // For SI-prefix, the suffix is lazily computed.
5475 var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
5476 suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? "%" : "";
5477
5478 // What format function should we use?
5479 // Is this an integer type?
5480 // Can this type generate exponential notation?
5481 var formatType = formatTypes[type],
5482 maybeSuffix = !type || /[defgprs%]/.test(type);
5483
5484 // Set the default precision if not specified,
5485 // or clamp the specified precision to the supported range.
5486 // For significant precision, it must be in [1, 21].
5487 // For fixed precision, it must be in [0, 20].
5488 precision = precision == null ? type ? 6 : 12 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision)) : Math.max(0, Math.min(20, precision));
5489
5490 function format(value) {
5491 var valuePrefix = prefix,
5492 valueSuffix = suffix,
5493 i,
5494 n,
5495 c;
5496
5497 if (type === "c") {
5498 valueSuffix = formatType(value) + valueSuffix;
5499 value = "";
5500 } else {
5501 value = +value;
5502
5503 // Convert negative to positive, and compute the prefix.
5504 // Note that -0 is not less than 0, but 1 / -0 is!
5505 var valueNegative = (value < 0 || 1 / value < 0) && (value *= -1, true);
5506
5507 // Perform the initial formatting.
5508 value = formatType(value, precision);
5509
5510 // If the original value was negative, it may be rounded to zero during
5511 // formatting; treat this as (positive) zero.
5512 if (valueNegative) {
5513 i = -1, n = value.length;
5514 valueNegative = false;
5515 while (++i < n) {
5516 if (c = value.charCodeAt(i), 48 < c && c < 58 || type === "x" && 96 < c && c < 103 || type === "X" && 64 < c && c < 71) {
5517 valueNegative = true;
5518 break;
5519 }
5520 }
5521 }
5522
5523 // Compute the prefix and suffix.
5524 valuePrefix = (valueNegative ? sign === "(" ? sign : "-" : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
5525 valueSuffix = valueSuffix + (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + (valueNegative && sign === "(" ? ")" : "");
5526
5527 // Break the formatted value into the integer “value” part that can be
5528 // grouped, and fractional or exponential “suffix” part that is not.
5529 if (maybeSuffix) {
5530 i = -1, n = value.length;
5531 while (++i < n) {
5532 if (c = value.charCodeAt(i), 48 > c || c > 57) {
5533 valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
5534 value = value.slice(0, i);
5535 break;
5536 }
5537 }
5538 }
5539 }
5540
5541 // If the fill character is not "0", grouping is applied before padding.
5542 if (comma && !zero) value = group(value, Infinity);
5543
5544 // Compute the padding.
5545 var length = valuePrefix.length + value.length + valueSuffix.length,
5546 padding = length < width ? new Array(width - length + 1).join(fill) : "";
5547
5548 // If the fill character is "0", grouping is applied after padding.
5549 if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
5550
5551 // Reconstruct the final output based on the desired alignment.
5552 switch (align) {
5553 case "<":
5554 return valuePrefix + value + valueSuffix + padding;
5555 case "=":
5556 return valuePrefix + padding + value + valueSuffix;
5557 case "^":
5558 return padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length);
5559 }
5560 return padding + valuePrefix + value + valueSuffix;
5561 }
5562
5563 format.toString = function () {
5564 return specifier + "";
5565 };
5566
5567 return format;
5568 }
5569
5570 function formatPrefix(specifier, value) {
5571 var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
5572 e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
5573 k = Math.pow(10, -e),
5574 prefix = prefixes[8 + e / 3];
5575 return function (value) {
5576 return f(k * value) + prefix;
5577 };
5578 }
5579
5580 return {
5581 format: newFormat,
5582 formatPrefix: formatPrefix
5583 };
5584};
5585
5586var locale$1;
5587
5588
5589
5590defaultLocale({
5591 decimal: ".",
5592 thousands: ",",
5593 grouping: [3],
5594 currency: ["$", ""]
5595});
5596
5597function defaultLocale(definition) {
5598 locale$1 = formatLocale(definition);
5599 exports.format = locale$1.format;
5600 exports.formatPrefix = locale$1.formatPrefix;
5601 return locale$1;
5602}
5603
5604var precisionFixed = function (step) {
5605 return Math.max(0, -exponent$1(Math.abs(step)));
5606};
5607
5608var precisionPrefix = function (step, value) {
5609 return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
5610};
5611
5612var precisionRound = function (step, max) {
5613 step = Math.abs(step), max = Math.abs(max) - step;
5614 return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
5615};
5616
5617function localDate(d) {
5618 if (0 <= d.y && d.y < 100) {
5619 var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
5620 date.setFullYear(d.y);
5621 return date;
5622 }
5623 return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
5624}
5625
5626function utcDate(d) {
5627 if (0 <= d.y && d.y < 100) {
5628 var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
5629 date.setUTCFullYear(d.y);
5630 return date;
5631 }
5632 return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
5633}
5634
5635function newYear(y) {
5636 return { y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0 };
5637}
5638
5639function formatLocale$1(locale) {
5640 var locale_dateTime = locale.dateTime,
5641 locale_date = locale.date,
5642 locale_time = locale.time,
5643 locale_periods = locale.periods,
5644 locale_weekdays = locale.days,
5645 locale_shortWeekdays = locale.shortDays,
5646 locale_months = locale.months,
5647 locale_shortMonths = locale.shortMonths;
5648
5649 var periodRe = formatRe(locale_periods),
5650 periodLookup = formatLookup(locale_periods),
5651 weekdayRe = formatRe(locale_weekdays),
5652 weekdayLookup = formatLookup(locale_weekdays),
5653 shortWeekdayRe = formatRe(locale_shortWeekdays),
5654 shortWeekdayLookup = formatLookup(locale_shortWeekdays),
5655 monthRe = formatRe(locale_months),
5656 monthLookup = formatLookup(locale_months),
5657 shortMonthRe = formatRe(locale_shortMonths),
5658 shortMonthLookup = formatLookup(locale_shortMonths);
5659
5660 var formats = {
5661 "a": formatShortWeekday,
5662 "A": formatWeekday,
5663 "b": formatShortMonth,
5664 "B": formatMonth,
5665 "c": null,
5666 "d": formatDayOfMonth,
5667 "e": formatDayOfMonth,
5668 "H": formatHour24,
5669 "I": formatHour12,
5670 "j": formatDayOfYear,
5671 "L": formatMilliseconds,
5672 "m": formatMonthNumber,
5673 "M": formatMinutes,
5674 "p": formatPeriod,
5675 "S": formatSeconds,
5676 "U": formatWeekNumberSunday,
5677 "w": formatWeekdayNumber,
5678 "W": formatWeekNumberMonday,
5679 "x": null,
5680 "X": null,
5681 "y": formatYear,
5682 "Y": formatFullYear,
5683 "Z": formatZone,
5684 "%": formatLiteralPercent
5685 };
5686
5687 var utcFormats = {
5688 "a": formatUTCShortWeekday,
5689 "A": formatUTCWeekday,
5690 "b": formatUTCShortMonth,
5691 "B": formatUTCMonth,
5692 "c": null,
5693 "d": formatUTCDayOfMonth,
5694 "e": formatUTCDayOfMonth,
5695 "H": formatUTCHour24,
5696 "I": formatUTCHour12,
5697 "j": formatUTCDayOfYear,
5698 "L": formatUTCMilliseconds,
5699 "m": formatUTCMonthNumber,
5700 "M": formatUTCMinutes,
5701 "p": formatUTCPeriod,
5702 "S": formatUTCSeconds,
5703 "U": formatUTCWeekNumberSunday,
5704 "w": formatUTCWeekdayNumber,
5705 "W": formatUTCWeekNumberMonday,
5706 "x": null,
5707 "X": null,
5708 "y": formatUTCYear,
5709 "Y": formatUTCFullYear,
5710 "Z": formatUTCZone,
5711 "%": formatLiteralPercent
5712 };
5713
5714 var parses = {
5715 "a": parseShortWeekday,
5716 "A": parseWeekday,
5717 "b": parseShortMonth,
5718 "B": parseMonth,
5719 "c": parseLocaleDateTime,
5720 "d": parseDayOfMonth,
5721 "e": parseDayOfMonth,
5722 "H": parseHour24,
5723 "I": parseHour24,
5724 "j": parseDayOfYear,
5725 "L": parseMilliseconds,
5726 "m": parseMonthNumber,
5727 "M": parseMinutes,
5728 "p": parsePeriod,
5729 "S": parseSeconds,
5730 "U": parseWeekNumberSunday,
5731 "w": parseWeekdayNumber,
5732 "W": parseWeekNumberMonday,
5733 "x": parseLocaleDate,
5734 "X": parseLocaleTime,
5735 "y": parseYear,
5736 "Y": parseFullYear,
5737 "Z": parseZone,
5738 "%": parseLiteralPercent
5739 };
5740
5741 // These recursive directive definitions must be deferred.
5742 formats.x = newFormat(locale_date, formats);
5743 formats.X = newFormat(locale_time, formats);
5744 formats.c = newFormat(locale_dateTime, formats);
5745 utcFormats.x = newFormat(locale_date, utcFormats);
5746 utcFormats.X = newFormat(locale_time, utcFormats);
5747 utcFormats.c = newFormat(locale_dateTime, utcFormats);
5748
5749 function newFormat(specifier, formats) {
5750 return function (date) {
5751 var string = [],
5752 i = -1,
5753 j = 0,
5754 n = specifier.length,
5755 c,
5756 pad,
5757 format;
5758
5759 if (!(date instanceof Date)) date = new Date(+date);
5760
5761 while (++i < n) {
5762 if (specifier.charCodeAt(i) === 37) {
5763 string.push(specifier.slice(j, i));
5764 if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);else pad = c === "e" ? " " : "0";
5765 if (format = formats[c]) c = format(date, pad);
5766 string.push(c);
5767 j = i + 1;
5768 }
5769 }
5770
5771 string.push(specifier.slice(j, i));
5772 return string.join("");
5773 };
5774 }
5775
5776 function newParse(specifier, newDate) {
5777 return function (string) {
5778 var d = newYear(1900),
5779 i = parseSpecifier(d, specifier, string += "", 0);
5780 if (i != string.length) return null;
5781
5782 // The am-pm flag is 0 for AM, and 1 for PM.
5783 if ("p" in d) d.H = d.H % 12 + d.p * 12;
5784
5785 // Convert day-of-week and week-of-year to day-of-year.
5786 if ("W" in d || "U" in d) {
5787 if (!("w" in d)) d.w = "W" in d ? 1 : 0;
5788 var day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
5789 d.m = 0;
5790 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;
5791 }
5792
5793 // If a time zone is specified, all fields are interpreted as UTC and then
5794 // offset according to the specified time zone.
5795 if ("Z" in d) {
5796 d.H += d.Z / 100 | 0;
5797 d.M += d.Z % 100;
5798 return utcDate(d);
5799 }
5800
5801 // Otherwise, all fields are in local time.
5802 return newDate(d);
5803 };
5804 }
5805
5806 function parseSpecifier(d, specifier, string, j) {
5807 var i = 0,
5808 n = specifier.length,
5809 m = string.length,
5810 c,
5811 parse;
5812
5813 while (i < n) {
5814 if (j >= m) return -1;
5815 c = specifier.charCodeAt(i++);
5816 if (c === 37) {
5817 c = specifier.charAt(i++);
5818 parse = parses[c in pads ? specifier.charAt(i++) : c];
5819 if (!parse || (j = parse(d, string, j)) < 0) return -1;
5820 } else if (c != string.charCodeAt(j++)) {
5821 return -1;
5822 }
5823 }
5824
5825 return j;
5826 }
5827
5828 function parsePeriod(d, string, i) {
5829 var n = periodRe.exec(string.slice(i));
5830 return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
5831 }
5832
5833 function parseShortWeekday(d, string, i) {
5834 var n = shortWeekdayRe.exec(string.slice(i));
5835 return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
5836 }
5837
5838 function parseWeekday(d, string, i) {
5839 var n = weekdayRe.exec(string.slice(i));
5840 return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
5841 }
5842
5843 function parseShortMonth(d, string, i) {
5844 var n = shortMonthRe.exec(string.slice(i));
5845 return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
5846 }
5847
5848 function parseMonth(d, string, i) {
5849 var n = monthRe.exec(string.slice(i));
5850 return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
5851 }
5852
5853 function parseLocaleDateTime(d, string, i) {
5854 return parseSpecifier(d, locale_dateTime, string, i);
5855 }
5856
5857 function parseLocaleDate(d, string, i) {
5858 return parseSpecifier(d, locale_date, string, i);
5859 }
5860
5861 function parseLocaleTime(d, string, i) {
5862 return parseSpecifier(d, locale_time, string, i);
5863 }
5864
5865 function formatShortWeekday(d) {
5866 return locale_shortWeekdays[d.getDay()];
5867 }
5868
5869 function formatWeekday(d) {
5870 return locale_weekdays[d.getDay()];
5871 }
5872
5873 function formatShortMonth(d) {
5874 return locale_shortMonths[d.getMonth()];
5875 }
5876
5877 function formatMonth(d) {
5878 return locale_months[d.getMonth()];
5879 }
5880
5881 function formatPeriod(d) {
5882 return locale_periods[+(d.getHours() >= 12)];
5883 }
5884
5885 function formatUTCShortWeekday(d) {
5886 return locale_shortWeekdays[d.getUTCDay()];
5887 }
5888
5889 function formatUTCWeekday(d) {
5890 return locale_weekdays[d.getUTCDay()];
5891 }
5892
5893 function formatUTCShortMonth(d) {
5894 return locale_shortMonths[d.getUTCMonth()];
5895 }
5896
5897 function formatUTCMonth(d) {
5898 return locale_months[d.getUTCMonth()];
5899 }
5900
5901 function formatUTCPeriod(d) {
5902 return locale_periods[+(d.getUTCHours() >= 12)];
5903 }
5904
5905 return {
5906 format: function format(specifier) {
5907 var f = newFormat(specifier += "", formats);
5908 f.toString = function () {
5909 return specifier;
5910 };
5911 return f;
5912 },
5913 parse: function parse(specifier) {
5914 var p = newParse(specifier += "", localDate);
5915 p.toString = function () {
5916 return specifier;
5917 };
5918 return p;
5919 },
5920 utcFormat: function utcFormat(specifier) {
5921 var f = newFormat(specifier += "", utcFormats);
5922 f.toString = function () {
5923 return specifier;
5924 };
5925 return f;
5926 },
5927 utcParse: function utcParse(specifier) {
5928 var p = newParse(specifier, utcDate);
5929 p.toString = function () {
5930 return specifier;
5931 };
5932 return p;
5933 }
5934 };
5935}
5936
5937var pads = { "-": "", "_": " ", "0": "0" };
5938var numberRe = /^\s*\d+/;
5939var percentRe = /^%/;
5940var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
5941
5942function pad(value, fill, width) {
5943 var sign = value < 0 ? "-" : "",
5944 string = (sign ? -value : value) + "",
5945 length = string.length;
5946 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
5947}
5948
5949function requote(s) {
5950 return s.replace(requoteRe, "\\$&");
5951}
5952
5953function formatRe(names) {
5954 return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
5955}
5956
5957function formatLookup(names) {
5958 var map = {},
5959 i = -1,
5960 n = names.length;
5961 while (++i < n) {
5962 map[names[i].toLowerCase()] = i;
5963 }return map;
5964}
5965
5966function parseWeekdayNumber(d, string, i) {
5967 var n = numberRe.exec(string.slice(i, i + 1));
5968 return n ? (d.w = +n[0], i + n[0].length) : -1;
5969}
5970
5971function parseWeekNumberSunday(d, string, i) {
5972 var n = numberRe.exec(string.slice(i));
5973 return n ? (d.U = +n[0], i + n[0].length) : -1;
5974}
5975
5976function parseWeekNumberMonday(d, string, i) {
5977 var n = numberRe.exec(string.slice(i));
5978 return n ? (d.W = +n[0], i + n[0].length) : -1;
5979}
5980
5981function parseFullYear(d, string, i) {
5982 var n = numberRe.exec(string.slice(i, i + 4));
5983 return n ? (d.y = +n[0], i + n[0].length) : -1;
5984}
5985
5986function parseYear(d, string, i) {
5987 var n = numberRe.exec(string.slice(i, i + 2));
5988 return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
5989}
5990
5991function parseZone(d, string, i) {
5992 var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
5993 return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
5994}
5995
5996function parseMonthNumber(d, string, i) {
5997 var n = numberRe.exec(string.slice(i, i + 2));
5998 return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
5999}
6000
6001function parseDayOfMonth(d, string, i) {
6002 var n = numberRe.exec(string.slice(i, i + 2));
6003 return n ? (d.d = +n[0], i + n[0].length) : -1;
6004}
6005
6006function parseDayOfYear(d, string, i) {
6007 var n = numberRe.exec(string.slice(i, i + 3));
6008 return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
6009}
6010
6011function parseHour24(d, string, i) {
6012 var n = numberRe.exec(string.slice(i, i + 2));
6013 return n ? (d.H = +n[0], i + n[0].length) : -1;
6014}
6015
6016function parseMinutes(d, string, i) {
6017 var n = numberRe.exec(string.slice(i, i + 2));
6018 return n ? (d.M = +n[0], i + n[0].length) : -1;
6019}
6020
6021function parseSeconds(d, string, i) {
6022 var n = numberRe.exec(string.slice(i, i + 2));
6023 return n ? (d.S = +n[0], i + n[0].length) : -1;
6024}
6025
6026function parseMilliseconds(d, string, i) {
6027 var n = numberRe.exec(string.slice(i, i + 3));
6028 return n ? (d.L = +n[0], i + n[0].length) : -1;
6029}
6030
6031function parseLiteralPercent(d, string, i) {
6032 var n = percentRe.exec(string.slice(i, i + 1));
6033 return n ? i + n[0].length : -1;
6034}
6035
6036function formatDayOfMonth(d, p) {
6037 return pad(d.getDate(), p, 2);
6038}
6039
6040function formatHour24(d, p) {
6041 return pad(d.getHours(), p, 2);
6042}
6043
6044function formatHour12(d, p) {
6045 return pad(d.getHours() % 12 || 12, p, 2);
6046}
6047
6048function formatDayOfYear(d, p) {
6049 return pad(1 + day.count(year(d), d), p, 3);
6050}
6051
6052function formatMilliseconds(d, p) {
6053 return pad(d.getMilliseconds(), p, 3);
6054}
6055
6056function formatMonthNumber(d, p) {
6057 return pad(d.getMonth() + 1, p, 2);
6058}
6059
6060function formatMinutes(d, p) {
6061 return pad(d.getMinutes(), p, 2);
6062}
6063
6064function formatSeconds(d, p) {
6065 return pad(d.getSeconds(), p, 2);
6066}
6067
6068function formatWeekNumberSunday(d, p) {
6069 return pad(sunday.count(year(d), d), p, 2);
6070}
6071
6072function formatWeekdayNumber(d) {
6073 return d.getDay();
6074}
6075
6076function formatWeekNumberMonday(d, p) {
6077 return pad(monday.count(year(d), d), p, 2);
6078}
6079
6080function formatYear(d, p) {
6081 return pad(d.getFullYear() % 100, p, 2);
6082}
6083
6084function formatFullYear(d, p) {
6085 return pad(d.getFullYear() % 10000, p, 4);
6086}
6087
6088function formatZone(d) {
6089 var z = d.getTimezoneOffset();
6090 return (z > 0 ? "-" : (z *= -1, "+")) + pad(z / 60 | 0, "0", 2) + pad(z % 60, "0", 2);
6091}
6092
6093function formatUTCDayOfMonth(d, p) {
6094 return pad(d.getUTCDate(), p, 2);
6095}
6096
6097function formatUTCHour24(d, p) {
6098 return pad(d.getUTCHours(), p, 2);
6099}
6100
6101function formatUTCHour12(d, p) {
6102 return pad(d.getUTCHours() % 12 || 12, p, 2);
6103}
6104
6105function formatUTCDayOfYear(d, p) {
6106 return pad(1 + utcDay.count(utcYear(d), d), p, 3);
6107}
6108
6109function formatUTCMilliseconds(d, p) {
6110 return pad(d.getUTCMilliseconds(), p, 3);
6111}
6112
6113function formatUTCMonthNumber(d, p) {
6114 return pad(d.getUTCMonth() + 1, p, 2);
6115}
6116
6117function formatUTCMinutes(d, p) {
6118 return pad(d.getUTCMinutes(), p, 2);
6119}
6120
6121function formatUTCSeconds(d, p) {
6122 return pad(d.getUTCSeconds(), p, 2);
6123}
6124
6125function formatUTCWeekNumberSunday(d, p) {
6126 return pad(utcSunday.count(utcYear(d), d), p, 2);
6127}
6128
6129function formatUTCWeekdayNumber(d) {
6130 return d.getUTCDay();
6131}
6132
6133function formatUTCWeekNumberMonday(d, p) {
6134 return pad(utcMonday.count(utcYear(d), d), p, 2);
6135}
6136
6137function formatUTCYear(d, p) {
6138 return pad(d.getUTCFullYear() % 100, p, 2);
6139}
6140
6141function formatUTCFullYear(d, p) {
6142 return pad(d.getUTCFullYear() % 10000, p, 4);
6143}
6144
6145function formatUTCZone() {
6146 return "+0000";
6147}
6148
6149function formatLiteralPercent() {
6150 return "%";
6151}
6152
6153var locale$2;
6154
6155
6156
6157
6158
6159defaultLocale$1({
6160 dateTime: "%x, %X",
6161 date: "%-m/%-d/%Y",
6162 time: "%-I:%M:%S %p",
6163 periods: ["AM", "PM"],
6164 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
6165 shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
6166 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
6167 shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
6168});
6169
6170function defaultLocale$1(definition) {
6171 locale$2 = formatLocale$1(definition);
6172 exports.timeFormat = locale$2.format;
6173 exports.timeParse = locale$2.parse;
6174 exports.utcFormat = locale$2.utcFormat;
6175 exports.utcParse = locale$2.utcParse;
6176 return locale$2;
6177}
6178
6179var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
6180
6181function formatIsoNative(date) {
6182 return date.toISOString();
6183}
6184
6185var formatIso = Date.prototype.toISOString ? formatIsoNative : exports.utcFormat(isoSpecifier);
6186
6187function parseIsoNative(string) {
6188 var date = new Date(string);
6189 return isNaN(date) ? null : date;
6190}
6191
6192var parseIso = +new Date("2000-01-01T00:00:00.000Z") ? parseIsoNative : exports.utcParse(isoSpecifier);
6193
6194var array$2 = Array.prototype;
6195
6196var map$3 = array$2.map;
6197var slice$2 = array$2.slice;
6198
6199var implicit = { name: "implicit" };
6200
6201function ordinal(range) {
6202 var index = map$1(),
6203 domain = [],
6204 unknown = implicit;
6205
6206 range = range == null ? [] : slice$2.call(range);
6207
6208 function scale(d) {
6209 var key = d + "",
6210 i = index.get(key);
6211 if (!i) {
6212 if (unknown !== implicit) return unknown;
6213 index.set(key, i = domain.push(d));
6214 }
6215 return range[(i - 1) % range.length];
6216 }
6217
6218 scale.domain = function (_) {
6219 if (!arguments.length) return domain.slice();
6220 domain = [], index = map$1();
6221 var i = -1,
6222 n = _.length,
6223 d,
6224 key;
6225 while (++i < n) {
6226 if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
6227 }return scale;
6228 };
6229
6230 scale.range = function (_) {
6231 return arguments.length ? (range = slice$2.call(_), scale) : range.slice();
6232 };
6233
6234 scale.unknown = function (_) {
6235 return arguments.length ? (unknown = _, scale) : unknown;
6236 };
6237
6238 scale.copy = function () {
6239 return ordinal().domain(domain).range(range).unknown(unknown);
6240 };
6241
6242 return scale;
6243}
6244
6245function band() {
6246 var scale = ordinal().unknown(undefined),
6247 domain = scale.domain,
6248 ordinalRange = scale.range,
6249 range$$1 = [0, 1],
6250 step,
6251 bandwidth,
6252 round = false,
6253 paddingInner = 0,
6254 paddingOuter = 0,
6255 align = 0.5;
6256
6257 delete scale.unknown;
6258
6259 function rescale() {
6260 var n = domain().length,
6261 reverse = range$$1[1] < range$$1[0],
6262 start = range$$1[reverse - 0],
6263 stop = range$$1[1 - reverse];
6264 step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
6265 if (round) step = Math.floor(step);
6266 start += (stop - start - step * (n - paddingInner)) * align;
6267 bandwidth = step * (1 - paddingInner);
6268 if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
6269 var values = range(n).map(function (i) {
6270 return start + step * i;
6271 });
6272 return ordinalRange(reverse ? values.reverse() : values);
6273 }
6274
6275 scale.domain = function (_) {
6276 return arguments.length ? (domain(_), rescale()) : domain();
6277 };
6278
6279 scale.range = function (_) {
6280 return arguments.length ? (range$$1 = [+_[0], +_[1]], rescale()) : range$$1.slice();
6281 };
6282
6283 scale.rangeRound = function (_) {
6284 return range$$1 = [+_[0], +_[1]], round = true, rescale();
6285 };
6286
6287 scale.bandwidth = function () {
6288 return bandwidth;
6289 };
6290
6291 scale.step = function () {
6292 return step;
6293 };
6294
6295 scale.round = function (_) {
6296 return arguments.length ? (round = !!_, rescale()) : round;
6297 };
6298
6299 scale.padding = function (_) {
6300 return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
6301 };
6302
6303 scale.paddingInner = function (_) {
6304 return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
6305 };
6306
6307 scale.paddingOuter = function (_) {
6308 return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
6309 };
6310
6311 scale.align = function (_) {
6312 return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
6313 };
6314
6315 scale.copy = function () {
6316 return band().domain(domain()).range(range$$1).round(round).paddingInner(paddingInner).paddingOuter(paddingOuter).align(align);
6317 };
6318
6319 return rescale();
6320}
6321
6322function pointish(scale) {
6323 var copy = scale.copy;
6324
6325 scale.padding = scale.paddingOuter;
6326 delete scale.paddingInner;
6327 delete scale.paddingOuter;
6328
6329 scale.copy = function () {
6330 return pointish(copy());
6331 };
6332
6333 return scale;
6334}
6335
6336function point$1() {
6337 return pointish(band().paddingInner(1));
6338}
6339
6340var constant$4 = function (x) {
6341 return function () {
6342 return x;
6343 };
6344};
6345
6346var number$1 = function (x) {
6347 return +x;
6348};
6349
6350var unit = [0, 1];
6351
6352function deinterpolateLinear(a, b) {
6353 return (b -= a = +a) ? function (x) {
6354 return (x - a) / b;
6355 } : constant$4(b);
6356}
6357
6358function deinterpolateClamp(deinterpolate) {
6359 return function (a, b) {
6360 var d = deinterpolate(a = +a, b = +b);
6361 return function (x) {
6362 return x <= a ? 0 : x >= b ? 1 : d(x);
6363 };
6364 };
6365}
6366
6367function reinterpolateClamp(reinterpolate) {
6368 return function (a, b) {
6369 var r = reinterpolate(a = +a, b = +b);
6370 return function (t) {
6371 return t <= 0 ? a : t >= 1 ? b : r(t);
6372 };
6373 };
6374}
6375
6376function bimap(domain, range$$1, deinterpolate, reinterpolate) {
6377 var d0 = domain[0],
6378 d1 = domain[1],
6379 r0 = range$$1[0],
6380 r1 = range$$1[1];
6381 if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
6382 return function (x) {
6383 return r0(d0(x));
6384 };
6385}
6386
6387function polymap(domain, range$$1, deinterpolate, reinterpolate) {
6388 var j = Math.min(domain.length, range$$1.length) - 1,
6389 d = new Array(j),
6390 r = new Array(j),
6391 i = -1;
6392
6393 // Reverse descending domains.
6394 if (domain[j] < domain[0]) {
6395 domain = domain.slice().reverse();
6396 range$$1 = range$$1.slice().reverse();
6397 }
6398
6399 while (++i < j) {
6400 d[i] = deinterpolate(domain[i], domain[i + 1]);
6401 r[i] = reinterpolate(range$$1[i], range$$1[i + 1]);
6402 }
6403
6404 return function (x) {
6405 var i = bisectRight(domain, x, 1, j) - 1;
6406 return r[i](d[i](x));
6407 };
6408}
6409
6410function copy(source, target) {
6411 return target.domain(source.domain()).range(source.range()).interpolate(source.interpolate()).clamp(source.clamp());
6412}
6413
6414// deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
6415// reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
6416function continuous(deinterpolate, reinterpolate) {
6417 var domain = unit,
6418 range$$1 = unit,
6419 interpolate$$1 = interpolate,
6420 clamp = false,
6421 piecewise,
6422 output,
6423 input;
6424
6425 function rescale() {
6426 piecewise = Math.min(domain.length, range$$1.length) > 2 ? polymap : bimap;
6427 output = input = null;
6428 return scale;
6429 }
6430
6431 function scale(x) {
6432 return (output || (output = piecewise(domain, range$$1, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
6433 }
6434
6435 scale.invert = function (y) {
6436 return (input || (input = piecewise(range$$1, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
6437 };
6438
6439 scale.domain = function (_) {
6440 return arguments.length ? (domain = map$3.call(_, number$1), rescale()) : domain.slice();
6441 };
6442
6443 scale.range = function (_) {
6444 return arguments.length ? (range$$1 = slice$2.call(_), rescale()) : range$$1.slice();
6445 };
6446
6447 scale.rangeRound = function (_) {
6448 return range$$1 = slice$2.call(_), interpolate$$1 = interpolateRound, rescale();
6449 };
6450
6451 scale.clamp = function (_) {
6452 return arguments.length ? (clamp = !!_, rescale()) : clamp;
6453 };
6454
6455 scale.interpolate = function (_) {
6456 return arguments.length ? (interpolate$$1 = _, rescale()) : interpolate$$1;
6457 };
6458
6459 return rescale();
6460}
6461
6462var tickFormat = function (domain, count, specifier) {
6463 var start = domain[0],
6464 stop = domain[domain.length - 1],
6465 step = tickStep(start, stop, count == null ? 10 : count),
6466 precision;
6467 specifier = formatSpecifier(specifier == null ? ",f" : specifier);
6468 switch (specifier.type) {
6469 case "s":
6470 {
6471 var value = Math.max(Math.abs(start), Math.abs(stop));
6472 if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
6473 return exports.formatPrefix(specifier, value);
6474 }
6475 case "":
6476 case "e":
6477 case "g":
6478 case "p":
6479 case "r":
6480 {
6481 if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
6482 break;
6483 }
6484 case "f":
6485 case "%":
6486 {
6487 if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
6488 break;
6489 }
6490 }
6491 return exports.format(specifier);
6492};
6493
6494function linearish(scale) {
6495 var domain = scale.domain;
6496
6497 scale.ticks = function (count) {
6498 var d = domain();
6499 return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
6500 };
6501
6502 scale.tickFormat = function (count, specifier) {
6503 return tickFormat(domain(), count, specifier);
6504 };
6505
6506 scale.nice = function (count) {
6507 var d = domain(),
6508 i = d.length - 1,
6509 n = count == null ? 10 : count,
6510 start = d[0],
6511 stop = d[i],
6512 step = tickStep(start, stop, n);
6513
6514 if (step) {
6515 step = tickStep(Math.floor(start / step) * step, Math.ceil(stop / step) * step, n);
6516 d[0] = Math.floor(start / step) * step;
6517 d[i] = Math.ceil(stop / step) * step;
6518 domain(d);
6519 }
6520
6521 return scale;
6522 };
6523
6524 return scale;
6525}
6526
6527function linear$2() {
6528 var scale = continuous(deinterpolateLinear, interpolateNumber);
6529
6530 scale.copy = function () {
6531 return copy(scale, linear$2());
6532 };
6533
6534 return linearish(scale);
6535}
6536
6537function identity$4() {
6538 var domain = [0, 1];
6539
6540 function scale(x) {
6541 return +x;
6542 }
6543
6544 scale.invert = scale;
6545
6546 scale.domain = scale.range = function (_) {
6547 return arguments.length ? (domain = map$3.call(_, number$1), scale) : domain.slice();
6548 };
6549
6550 scale.copy = function () {
6551 return identity$4().domain(domain);
6552 };
6553
6554 return linearish(scale);
6555}
6556
6557var nice = function (domain, interval) {
6558 domain = domain.slice();
6559
6560 var i0 = 0,
6561 i1 = domain.length - 1,
6562 x0 = domain[i0],
6563 x1 = domain[i1],
6564 t;
6565
6566 if (x1 < x0) {
6567 t = i0, i0 = i1, i1 = t;
6568 t = x0, x0 = x1, x1 = t;
6569 }
6570
6571 domain[i0] = interval.floor(x0);
6572 domain[i1] = interval.ceil(x1);
6573 return domain;
6574};
6575
6576function deinterpolate(a, b) {
6577 return (b = Math.log(b / a)) ? function (x) {
6578 return Math.log(x / a) / b;
6579 } : constant$4(b);
6580}
6581
6582function reinterpolate(a, b) {
6583 return a < 0 ? function (t) {
6584 return -Math.pow(-b, t) * Math.pow(-a, 1 - t);
6585 } : function (t) {
6586 return Math.pow(b, t) * Math.pow(a, 1 - t);
6587 };
6588}
6589
6590function pow10(x) {
6591 return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
6592}
6593
6594function powp(base) {
6595 return base === 10 ? pow10 : base === Math.E ? Math.exp : function (x) {
6596 return Math.pow(base, x);
6597 };
6598}
6599
6600function logp(base) {
6601 return base === Math.E ? Math.log : base === 10 && Math.log10 || base === 2 && Math.log2 || (base = Math.log(base), function (x) {
6602 return Math.log(x) / base;
6603 });
6604}
6605
6606function reflect(f) {
6607 return function (x) {
6608 return -f(-x);
6609 };
6610}
6611
6612function log() {
6613 var scale = continuous(deinterpolate, reinterpolate).domain([1, 10]),
6614 domain = scale.domain,
6615 base = 10,
6616 logs = logp(10),
6617 pows = powp(10);
6618
6619 function rescale() {
6620 logs = logp(base), pows = powp(base);
6621 if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
6622 return scale;
6623 }
6624
6625 scale.base = function (_) {
6626 return arguments.length ? (base = +_, rescale()) : base;
6627 };
6628
6629 scale.domain = function (_) {
6630 return arguments.length ? (domain(_), rescale()) : domain();
6631 };
6632
6633 scale.ticks = function (count) {
6634 var d = domain(),
6635 u = d[0],
6636 v = d[d.length - 1],
6637 r;
6638
6639 if (r = v < u) i = u, u = v, v = i;
6640
6641 var i = logs(u),
6642 j = logs(v),
6643 p,
6644 k,
6645 t,
6646 n = count == null ? 10 : +count,
6647 z = [];
6648
6649 if (!(base % 1) && j - i < n) {
6650 i = Math.round(i) - 1, j = Math.round(j) + 1;
6651 if (u > 0) for (; i < j; ++i) {
6652 for (k = 1, p = pows(i); k < base; ++k) {
6653 t = p * k;
6654 if (t < u) continue;
6655 if (t > v) break;
6656 z.push(t);
6657 }
6658 } else for (; i < j; ++i) {
6659 for (k = base - 1, p = pows(i); k >= 1; --k) {
6660 t = p * k;
6661 if (t < u) continue;
6662 if (t > v) break;
6663 z.push(t);
6664 }
6665 }
6666 } else {
6667 z = ticks(i, j, Math.min(j - i, n)).map(pows);
6668 }
6669
6670 return r ? z.reverse() : z;
6671 };
6672
6673 scale.tickFormat = function (count, specifier) {
6674 if (specifier == null) specifier = base === 10 ? ".0e" : ",";
6675 if (typeof specifier !== "function") specifier = exports.format(specifier);
6676 if (count === Infinity) return specifier;
6677 if (count == null) count = 10;
6678 var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
6679 return function (d) {
6680 var i = d / pows(Math.round(logs(d)));
6681 if (i * base < base - 0.5) i *= base;
6682 return i <= k ? specifier(d) : "";
6683 };
6684 };
6685
6686 scale.nice = function () {
6687 return domain(nice(domain(), {
6688 floor: function floor(x) {
6689 return pows(Math.floor(logs(x)));
6690 },
6691 ceil: function ceil(x) {
6692 return pows(Math.ceil(logs(x)));
6693 }
6694 }));
6695 };
6696
6697 scale.copy = function () {
6698 return copy(scale, log().base(base));
6699 };
6700
6701 return scale;
6702}
6703
6704function raise(x, exponent) {
6705 return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
6706}
6707
6708function pow() {
6709 var exponent = 1,
6710 scale = continuous(deinterpolate, reinterpolate),
6711 domain = scale.domain;
6712
6713 function deinterpolate(a, b) {
6714 return (b = raise(b, exponent) - (a = raise(a, exponent))) ? function (x) {
6715 return (raise(x, exponent) - a) / b;
6716 } : constant$4(b);
6717 }
6718
6719 function reinterpolate(a, b) {
6720 b = raise(b, exponent) - (a = raise(a, exponent));
6721 return function (t) {
6722 return raise(a + b * t, 1 / exponent);
6723 };
6724 }
6725
6726 scale.exponent = function (_) {
6727 return arguments.length ? (exponent = +_, domain(domain())) : exponent;
6728 };
6729
6730 scale.copy = function () {
6731 return copy(scale, pow().exponent(exponent));
6732 };
6733
6734 return linearish(scale);
6735}
6736
6737function sqrt() {
6738 return pow().exponent(0.5);
6739}
6740
6741function quantile$$1() {
6742 var domain = [],
6743 range$$1 = [],
6744 thresholds = [];
6745
6746 function rescale() {
6747 var i = 0,
6748 n = Math.max(1, range$$1.length);
6749 thresholds = new Array(n - 1);
6750 while (++i < n) {
6751 thresholds[i - 1] = threshold(domain, i / n);
6752 }return scale;
6753 }
6754
6755 function scale(x) {
6756 if (!isNaN(x = +x)) return range$$1[bisectRight(thresholds, x)];
6757 }
6758
6759 scale.invertExtent = function (y) {
6760 var i = range$$1.indexOf(y);
6761 return i < 0 ? [NaN, NaN] : [i > 0 ? thresholds[i - 1] : domain[0], i < thresholds.length ? thresholds[i] : domain[domain.length - 1]];
6762 };
6763
6764 scale.domain = function (_) {
6765 if (!arguments.length) return domain.slice();
6766 domain = [];
6767 for (var i = 0, n = _.length, d; i < n; ++i) {
6768 if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
6769 }domain.sort(ascending);
6770 return rescale();
6771 };
6772
6773 scale.range = function (_) {
6774 return arguments.length ? (range$$1 = slice$2.call(_), rescale()) : range$$1.slice();
6775 };
6776
6777 scale.quantiles = function () {
6778 return thresholds.slice();
6779 };
6780
6781 scale.copy = function () {
6782 return quantile$$1().domain(domain).range(range$$1);
6783 };
6784
6785 return scale;
6786}
6787
6788function quantize$1() {
6789 var x0 = 0,
6790 x1 = 1,
6791 n = 1,
6792 domain = [0.5],
6793 range$$1 = [0, 1];
6794
6795 function scale(x) {
6796 if (x <= x) return range$$1[bisectRight(domain, x, 0, n)];
6797 }
6798
6799 function rescale() {
6800 var i = -1;
6801 domain = new Array(n);
6802 while (++i < n) {
6803 domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
6804 }return scale;
6805 }
6806
6807 scale.domain = function (_) {
6808 return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
6809 };
6810
6811 scale.range = function (_) {
6812 return arguments.length ? (n = (range$$1 = slice$2.call(_)).length - 1, rescale()) : range$$1.slice();
6813 };
6814
6815 scale.invertExtent = function (y) {
6816 var i = range$$1.indexOf(y);
6817 return i < 0 ? [NaN, NaN] : i < 1 ? [x0, domain[0]] : i >= n ? [domain[n - 1], x1] : [domain[i - 1], domain[i]];
6818 };
6819
6820 scale.copy = function () {
6821 return quantize$1().domain([x0, x1]).range(range$$1);
6822 };
6823
6824 return linearish(scale);
6825}
6826
6827function threshold$1() {
6828 var domain = [0.5],
6829 range$$1 = [0, 1],
6830 n = 1;
6831
6832 function scale(x) {
6833 if (x <= x) return range$$1[bisectRight(domain, x, 0, n)];
6834 }
6835
6836 scale.domain = function (_) {
6837 return arguments.length ? (domain = slice$2.call(_), n = Math.min(domain.length, range$$1.length - 1), scale) : domain.slice();
6838 };
6839
6840 scale.range = function (_) {
6841 return arguments.length ? (range$$1 = slice$2.call(_), n = Math.min(domain.length, range$$1.length - 1), scale) : range$$1.slice();
6842 };
6843
6844 scale.invertExtent = function (y) {
6845 var i = range$$1.indexOf(y);
6846 return [domain[i - 1], domain[i]];
6847 };
6848
6849 scale.copy = function () {
6850 return threshold$1().domain(domain).range(range$$1);
6851 };
6852
6853 return scale;
6854}
6855
6856var durationSecond$1 = 1000;
6857var durationMinute$1 = durationSecond$1 * 60;
6858var durationHour$1 = durationMinute$1 * 60;
6859var durationDay$1 = durationHour$1 * 24;
6860var durationWeek$1 = durationDay$1 * 7;
6861var durationMonth = durationDay$1 * 30;
6862var durationYear = durationDay$1 * 365;
6863
6864function date$1(t) {
6865 return new Date(t);
6866}
6867
6868function number$2(t) {
6869 return t instanceof Date ? +t : +new Date(+t);
6870}
6871
6872function calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format) {
6873 var scale = continuous(deinterpolateLinear, interpolateNumber),
6874 invert = scale.invert,
6875 domain = scale.domain;
6876
6877 var formatMillisecond = format(".%L"),
6878 formatSecond = format(":%S"),
6879 formatMinute = format("%I:%M"),
6880 formatHour = format("%I %p"),
6881 formatDay = format("%a %d"),
6882 formatWeek = format("%b %d"),
6883 formatMonth = format("%B"),
6884 formatYear = format("%Y");
6885
6886 var tickIntervals = [[second$$1, 1, durationSecond$1], [second$$1, 5, 5 * durationSecond$1], [second$$1, 15, 15 * durationSecond$1], [second$$1, 30, 30 * durationSecond$1], [minute$$1, 1, durationMinute$1], [minute$$1, 5, 5 * durationMinute$1], [minute$$1, 15, 15 * durationMinute$1], [minute$$1, 30, 30 * durationMinute$1], [hour$$1, 1, durationHour$1], [hour$$1, 3, 3 * durationHour$1], [hour$$1, 6, 6 * durationHour$1], [hour$$1, 12, 12 * durationHour$1], [day$$1, 1, durationDay$1], [day$$1, 2, 2 * durationDay$1], [week, 1, durationWeek$1], [month$$1, 1, durationMonth], [month$$1, 3, 3 * durationMonth], [year$$1, 1, durationYear]];
6887
6888 function tickFormat(date) {
6889 return (second$$1(date) < date ? formatMillisecond : minute$$1(date) < date ? formatSecond : hour$$1(date) < date ? formatMinute : day$$1(date) < date ? formatHour : month$$1(date) < date ? week(date) < date ? formatDay : formatWeek : year$$1(date) < date ? formatMonth : formatYear)(date);
6890 }
6891
6892 function tickInterval(interval, start, stop, step) {
6893 if (interval == null) interval = 10;
6894
6895 // If a desired tick count is specified, pick a reasonable tick interval
6896 // based on the extent of the domain and a rough estimate of tick size.
6897 // Otherwise, assume interval is already a time interval and use it.
6898 if (typeof interval === "number") {
6899 var target = Math.abs(stop - start) / interval,
6900 i = bisector(function (i) {
6901 return i[2];
6902 }).right(tickIntervals, target);
6903 if (i === tickIntervals.length) {
6904 step = tickStep(start / durationYear, stop / durationYear, interval);
6905 interval = year$$1;
6906 } else if (i) {
6907 i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
6908 step = i[1];
6909 interval = i[0];
6910 } else {
6911 step = tickStep(start, stop, interval);
6912 interval = millisecond$$1;
6913 }
6914 }
6915
6916 return step == null ? interval : interval.every(step);
6917 }
6918
6919 scale.invert = function (y) {
6920 return new Date(invert(y));
6921 };
6922
6923 scale.domain = function (_) {
6924 return arguments.length ? domain(map$3.call(_, number$2)) : domain().map(date$1);
6925 };
6926
6927 scale.ticks = function (interval, step) {
6928 var d = domain(),
6929 t0 = d[0],
6930 t1 = d[d.length - 1],
6931 r = t1 < t0,
6932 t;
6933 if (r) t = t0, t0 = t1, t1 = t;
6934 t = tickInterval(interval, t0, t1, step);
6935 t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
6936 return r ? t.reverse() : t;
6937 };
6938
6939 scale.tickFormat = function (count, specifier) {
6940 return specifier == null ? tickFormat : format(specifier);
6941 };
6942
6943 scale.nice = function (interval, step) {
6944 var d = domain();
6945 return (interval = tickInterval(interval, d[0], d[d.length - 1], step)) ? domain(nice(d, interval)) : scale;
6946 };
6947
6948 scale.copy = function () {
6949 return copy(scale, calendar(year$$1, month$$1, week, day$$1, hour$$1, minute$$1, second$$1, millisecond$$1, format));
6950 };
6951
6952 return scale;
6953}
6954
6955var time = function () {
6956 return calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
6957};
6958
6959var utcTime = function () {
6960 return calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
6961};
6962
6963var colors = function (s) {
6964 return s.match(/.{6}/g).map(function (x) {
6965 return "#" + x;
6966 });
6967};
6968
6969var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
6970
6971var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
6972
6973var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
6974
6975var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
6976
6977var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
6978
6979var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
6980
6981var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
6982
6983var rainbow = cubehelix();
6984
6985var rainbow$1 = function (t) {
6986 if (t < 0 || t > 1) t -= Math.floor(t);
6987 var ts = Math.abs(t - 0.5);
6988 rainbow.h = 360 * t - 100;
6989 rainbow.s = 1.5 - 1.5 * ts;
6990 rainbow.l = 0.8 - 0.9 * ts;
6991 return rainbow + "";
6992};
6993
6994function ramp(range) {
6995 var n = range.length;
6996 return function (t) {
6997 return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
6998 };
6999}
7000
7001var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
7002
7003var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
7004
7005var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
7006
7007var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
7008
7009function sequential(interpolator) {
7010 var x0 = 0,
7011 x1 = 1,
7012 clamp = false;
7013
7014 function scale(x) {
7015 var t = (x - x0) / (x1 - x0);
7016 return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
7017 }
7018
7019 scale.domain = function (_) {
7020 return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
7021 };
7022
7023 scale.clamp = function (_) {
7024 return arguments.length ? (clamp = !!_, scale) : clamp;
7025 };
7026
7027 scale.interpolator = function (_) {
7028 return arguments.length ? (interpolator = _, scale) : interpolator;
7029 };
7030
7031 scale.copy = function () {
7032 return sequential(interpolator).domain([x0, x1]).clamp(clamp);
7033 };
7034
7035 return linearish(scale);
7036}
7037
7038var xhtml = "http://www.w3.org/1999/xhtml";
7039
7040var namespaces = {
7041 svg: "http://www.w3.org/2000/svg",
7042 xhtml: xhtml,
7043 xlink: "http://www.w3.org/1999/xlink",
7044 xml: "http://www.w3.org/XML/1998/namespace",
7045 xmlns: "http://www.w3.org/2000/xmlns/"
7046};
7047
7048var namespace = function (name) {
7049 var prefix = name += "",
7050 i = prefix.indexOf(":");
7051 if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
7052 return namespaces.hasOwnProperty(prefix) ? { space: namespaces[prefix], local: name } : name;
7053};
7054
7055function creatorInherit(name) {
7056 return function () {
7057 var document = this.ownerDocument,
7058 uri = this.namespaceURI;
7059 return uri === xhtml && document.documentElement.namespaceURI === xhtml ? document.createElement(name) : document.createElementNS(uri, name);
7060 };
7061}
7062
7063function creatorFixed(fullname) {
7064 return function () {
7065 return this.ownerDocument.createElementNS(fullname.space, fullname.local);
7066 };
7067}
7068
7069var creator = function (name) {
7070 var fullname = namespace(name);
7071 return (fullname.local ? creatorFixed : creatorInherit)(fullname);
7072};
7073
7074var nextId = 0;
7075
7076function local() {
7077 return new Local();
7078}
7079
7080function Local() {
7081 this._ = "@" + (++nextId).toString(36);
7082}
7083
7084Local.prototype = local.prototype = {
7085 constructor: Local,
7086 get: function get(node) {
7087 var id = this._;
7088 while (!(id in node)) {
7089 if (!(node = node.parentNode)) return;
7090 }return node[id];
7091 },
7092 set: function set(node, value) {
7093 return node[this._] = value;
7094 },
7095 remove: function remove(node) {
7096 return this._ in node && delete node[this._];
7097 },
7098 toString: function toString() {
7099 return this._;
7100 }
7101};
7102
7103var matcher = function matcher(selector) {
7104 return function () {
7105 return this.matches(selector);
7106 };
7107};
7108
7109if (typeof document !== "undefined") {
7110 var element = document.documentElement;
7111 if (!element.matches) {
7112 var vendorMatches = element.webkitMatchesSelector || element.msMatchesSelector || element.mozMatchesSelector || element.oMatchesSelector;
7113 matcher = function matcher(selector) {
7114 return function () {
7115 return vendorMatches.call(this, selector);
7116 };
7117 };
7118 }
7119}
7120
7121var matcher$1 = matcher;
7122
7123var filterEvents = {};
7124
7125exports.event = null;
7126
7127if (typeof document !== "undefined") {
7128 var element$1 = document.documentElement;
7129 if (!("onmouseenter" in element$1)) {
7130 filterEvents = { mouseenter: "mouseover", mouseleave: "mouseout" };
7131 }
7132}
7133
7134function filterContextListener(listener, index, group) {
7135 listener = contextListener(listener, index, group);
7136 return function (event) {
7137 var related = event.relatedTarget;
7138 if (!related || related !== this && !(related.compareDocumentPosition(this) & 8)) {
7139 listener.call(this, event);
7140 }
7141 };
7142}
7143
7144function contextListener(listener, index, group) {
7145 return function (event1) {
7146 var event0 = exports.event; // Events can be reentrant (e.g., focus).
7147 exports.event = event1;
7148 try {
7149 listener.call(this, this.__data__, index, group);
7150 } finally {
7151 exports.event = event0;
7152 }
7153 };
7154}
7155
7156function parseTypenames$1(typenames) {
7157 return typenames.trim().split(/^|\s+/).map(function (t) {
7158 var name = "",
7159 i = t.indexOf(".");
7160 if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
7161 return { type: t, name: name };
7162 });
7163}
7164
7165function onRemove(typename) {
7166 return function () {
7167 var on = this.__on;
7168 if (!on) return;
7169 for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
7170 if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
7171 this.removeEventListener(o.type, o.listener, o.capture);
7172 } else {
7173 on[++i] = o;
7174 }
7175 }
7176 if (++i) on.length = i;else delete this.__on;
7177 };
7178}
7179
7180function onAdd(typename, value, capture) {
7181 var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
7182 return function (d, i, group) {
7183 var on = this.__on,
7184 o,
7185 listener = wrap(value, i, group);
7186 if (on) for (var j = 0, m = on.length; j < m; ++j) {
7187 if ((o = on[j]).type === typename.type && o.name === typename.name) {
7188 this.removeEventListener(o.type, o.listener, o.capture);
7189 this.addEventListener(o.type, o.listener = listener, o.capture = capture);
7190 o.value = value;
7191 return;
7192 }
7193 }
7194 this.addEventListener(typename.type, listener, capture);
7195 o = { type: typename.type, name: typename.name, value: value, listener: listener, capture: capture };
7196 if (!on) this.__on = [o];else on.push(o);
7197 };
7198}
7199
7200var selection_on = function (typename, value, capture) {
7201 var typenames = parseTypenames$1(typename + ""),
7202 i,
7203 n = typenames.length,
7204 t;
7205
7206 if (arguments.length < 2) {
7207 var on = this.node().__on;
7208 if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
7209 for (i = 0, o = on[j]; i < n; ++i) {
7210 if ((t = typenames[i]).type === o.type && t.name === o.name) {
7211 return o.value;
7212 }
7213 }
7214 }
7215 return;
7216 }
7217
7218 on = value ? onAdd : onRemove;
7219 if (capture == null) capture = false;
7220 for (i = 0; i < n; ++i) {
7221 this.each(on(typenames[i], value, capture));
7222 }return this;
7223};
7224
7225function customEvent(event1, listener, that, args) {
7226 var event0 = exports.event;
7227 event1.sourceEvent = exports.event;
7228 exports.event = event1;
7229 try {
7230 return listener.apply(that, args);
7231 } finally {
7232 exports.event = event0;
7233 }
7234}
7235
7236var sourceEvent = function () {
7237 var current = exports.event,
7238 source;
7239 while (source = current.sourceEvent) {
7240 current = source;
7241 }return current;
7242};
7243
7244var point$2 = function (node, event) {
7245 var svg = node.ownerSVGElement || node;
7246
7247 if (svg.createSVGPoint) {
7248 var point = svg.createSVGPoint();
7249 point.x = event.clientX, point.y = event.clientY;
7250 point = point.matrixTransform(node.getScreenCTM().inverse());
7251 return [point.x, point.y];
7252 }
7253
7254 var rect = node.getBoundingClientRect();
7255 return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
7256};
7257
7258var mouse = function (node) {
7259 var event = sourceEvent();
7260 if (event.changedTouches) event = event.changedTouches[0];
7261 return point$2(node, event);
7262};
7263
7264function none$2() {}
7265
7266var selector = function (selector) {
7267 return selector == null ? none$2 : function () {
7268 return this.querySelector(selector);
7269 };
7270};
7271
7272var selection_select = function (select) {
7273 if (typeof select !== "function") select = selector(select);
7274
7275 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
7276 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
7277 if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
7278 if ("__data__" in node) subnode.__data__ = node.__data__;
7279 subgroup[i] = subnode;
7280 }
7281 }
7282 }
7283
7284 return new Selection(subgroups, this._parents);
7285};
7286
7287function empty$1() {
7288 return [];
7289}
7290
7291var selectorAll = function (selector) {
7292 return selector == null ? empty$1 : function () {
7293 return this.querySelectorAll(selector);
7294 };
7295};
7296
7297var selection_selectAll = function (select) {
7298 if (typeof select !== "function") select = selectorAll(select);
7299
7300 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
7301 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
7302 if (node = group[i]) {
7303 subgroups.push(select.call(node, node.__data__, i, group));
7304 parents.push(node);
7305 }
7306 }
7307 }
7308
7309 return new Selection(subgroups, parents);
7310};
7311
7312var selection_filter = function (match) {
7313 if (typeof match !== "function") match = matcher$1(match);
7314
7315 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
7316 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
7317 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
7318 subgroup.push(node);
7319 }
7320 }
7321 }
7322
7323 return new Selection(subgroups, this._parents);
7324};
7325
7326var sparse = function (update) {
7327 return new Array(update.length);
7328};
7329
7330var selection_enter = function () {
7331 return new Selection(this._enter || this._groups.map(sparse), this._parents);
7332};
7333
7334function EnterNode(parent, datum) {
7335 this.ownerDocument = parent.ownerDocument;
7336 this.namespaceURI = parent.namespaceURI;
7337 this._next = null;
7338 this._parent = parent;
7339 this.__data__ = datum;
7340}
7341
7342EnterNode.prototype = {
7343 constructor: EnterNode,
7344 appendChild: function appendChild(child) {
7345 return this._parent.insertBefore(child, this._next);
7346 },
7347 insertBefore: function insertBefore(child, next) {
7348 return this._parent.insertBefore(child, next);
7349 },
7350 querySelector: function querySelector(selector) {
7351 return this._parent.querySelector(selector);
7352 },
7353 querySelectorAll: function querySelectorAll(selector) {
7354 return this._parent.querySelectorAll(selector);
7355 }
7356};
7357
7358var constant$5 = function (x) {
7359 return function () {
7360 return x;
7361 };
7362};
7363
7364var keyPrefix = "$"; // Protect against keys like “__proto__”.
7365
7366function bindIndex(parent, group, enter, update, exit, data) {
7367 var i = 0,
7368 node,
7369 groupLength = group.length,
7370 dataLength = data.length;
7371
7372 // Put any non-null nodes that fit into update.
7373 // Put any null nodes into enter.
7374 // Put any remaining data into enter.
7375 for (; i < dataLength; ++i) {
7376 if (node = group[i]) {
7377 node.__data__ = data[i];
7378 update[i] = node;
7379 } else {
7380 enter[i] = new EnterNode(parent, data[i]);
7381 }
7382 }
7383
7384 // Put any non-null nodes that don’t fit into exit.
7385 for (; i < groupLength; ++i) {
7386 if (node = group[i]) {
7387 exit[i] = node;
7388 }
7389 }
7390}
7391
7392function bindKey(parent, group, enter, update, exit, data, key) {
7393 var i,
7394 node,
7395 nodeByKeyValue = {},
7396 groupLength = group.length,
7397 dataLength = data.length,
7398 keyValues = new Array(groupLength),
7399 keyValue;
7400
7401 // Compute the key for each node.
7402 // If multiple nodes have the same key, the duplicates are added to exit.
7403 for (i = 0; i < groupLength; ++i) {
7404 if (node = group[i]) {
7405 keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
7406 if (keyValue in nodeByKeyValue) {
7407 exit[i] = node;
7408 } else {
7409 nodeByKeyValue[keyValue] = node;
7410 }
7411 }
7412 }
7413
7414 // Compute the key for each datum.
7415 // If there a node associated with this key, join and add it to update.
7416 // If there is not (or the key is a duplicate), add it to enter.
7417 for (i = 0; i < dataLength; ++i) {
7418 keyValue = keyPrefix + key.call(parent, data[i], i, data);
7419 if (node = nodeByKeyValue[keyValue]) {
7420 update[i] = node;
7421 node.__data__ = data[i];
7422 nodeByKeyValue[keyValue] = null;
7423 } else {
7424 enter[i] = new EnterNode(parent, data[i]);
7425 }
7426 }
7427
7428 // Add any remaining nodes that were not bound to data to exit.
7429 for (i = 0; i < groupLength; ++i) {
7430 if ((node = group[i]) && nodeByKeyValue[keyValues[i]] === node) {
7431 exit[i] = node;
7432 }
7433 }
7434}
7435
7436var selection_data = function (value, key) {
7437 if (!value) {
7438 data = new Array(this.size()), j = -1;
7439 this.each(function (d) {
7440 data[++j] = d;
7441 });
7442 return data;
7443 }
7444
7445 var bind = key ? bindKey : bindIndex,
7446 parents = this._parents,
7447 groups = this._groups;
7448
7449 if (typeof value !== "function") value = constant$5(value);
7450
7451 for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
7452 var parent = parents[j],
7453 group = groups[j],
7454 groupLength = group.length,
7455 data = value.call(parent, parent && parent.__data__, j, parents),
7456 dataLength = data.length,
7457 enterGroup = enter[j] = new Array(dataLength),
7458 updateGroup = update[j] = new Array(dataLength),
7459 exitGroup = exit[j] = new Array(groupLength);
7460
7461 bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
7462
7463 // Now connect the enter nodes to their following update node, such that
7464 // appendChild can insert the materialized enter node before this node,
7465 // rather than at the end of the parent node.
7466 for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
7467 if (previous = enterGroup[i0]) {
7468 if (i0 >= i1) i1 = i0 + 1;
7469 while (!(next = updateGroup[i1]) && ++i1 < dataLength) {}
7470 previous._next = next || null;
7471 }
7472 }
7473 }
7474
7475 update = new Selection(update, parents);
7476 update._enter = enter;
7477 update._exit = exit;
7478 return update;
7479};
7480
7481var selection_exit = function () {
7482 return new Selection(this._exit || this._groups.map(sparse), this._parents);
7483};
7484
7485var selection_merge = function (selection) {
7486
7487 for (var groups0 = this._groups, groups1 = selection._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
7488 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
7489 if (node = group0[i] || group1[i]) {
7490 merge[i] = node;
7491 }
7492 }
7493 }
7494
7495 for (; j < m0; ++j) {
7496 merges[j] = groups0[j];
7497 }
7498
7499 return new Selection(merges, this._parents);
7500};
7501
7502var selection_order = function () {
7503
7504 for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
7505 for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
7506 if (node = group[i]) {
7507 if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
7508 next = node;
7509 }
7510 }
7511 }
7512
7513 return this;
7514};
7515
7516var selection_sort = function (compare) {
7517 if (!compare) compare = ascending$2;
7518
7519 function compareNode(a, b) {
7520 return a && b ? compare(a.__data__, b.__data__) : !a - !b;
7521 }
7522
7523 for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
7524 for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
7525 if (node = group[i]) {
7526 sortgroup[i] = node;
7527 }
7528 }
7529 sortgroup.sort(compareNode);
7530 }
7531
7532 return new Selection(sortgroups, this._parents).order();
7533};
7534
7535function ascending$2(a, b) {
7536 return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
7537}
7538
7539var selection_call = function () {
7540 var callback = arguments[0];
7541 arguments[0] = this;
7542 callback.apply(null, arguments);
7543 return this;
7544};
7545
7546var selection_nodes = function () {
7547 var nodes = new Array(this.size()),
7548 i = -1;
7549 this.each(function () {
7550 nodes[++i] = this;
7551 });
7552 return nodes;
7553};
7554
7555var selection_node = function () {
7556
7557 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
7558 for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
7559 var node = group[i];
7560 if (node) return node;
7561 }
7562 }
7563
7564 return null;
7565};
7566
7567var selection_size = function () {
7568 var size = 0;
7569 this.each(function () {
7570 ++size;
7571 });
7572 return size;
7573};
7574
7575var selection_empty = function () {
7576 return !this.node();
7577};
7578
7579var selection_each = function (callback) {
7580
7581 for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
7582 for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
7583 if (node = group[i]) callback.call(node, node.__data__, i, group);
7584 }
7585 }
7586
7587 return this;
7588};
7589
7590function attrRemove(name) {
7591 return function () {
7592 this.removeAttribute(name);
7593 };
7594}
7595
7596function attrRemoveNS(fullname) {
7597 return function () {
7598 this.removeAttributeNS(fullname.space, fullname.local);
7599 };
7600}
7601
7602function attrConstant(name, value) {
7603 return function () {
7604 this.setAttribute(name, value);
7605 };
7606}
7607
7608function attrConstantNS(fullname, value) {
7609 return function () {
7610 this.setAttributeNS(fullname.space, fullname.local, value);
7611 };
7612}
7613
7614function attrFunction(name, value) {
7615 return function () {
7616 var v = value.apply(this, arguments);
7617 if (v == null) this.removeAttribute(name);else this.setAttribute(name, v);
7618 };
7619}
7620
7621function attrFunctionNS(fullname, value) {
7622 return function () {
7623 var v = value.apply(this, arguments);
7624 if (v == null) this.removeAttributeNS(fullname.space, fullname.local);else this.setAttributeNS(fullname.space, fullname.local, v);
7625 };
7626}
7627
7628var selection_attr = function (name, value) {
7629 var fullname = namespace(name);
7630
7631 if (arguments.length < 2) {
7632 var node = this.node();
7633 return fullname.local ? node.getAttributeNS(fullname.space, fullname.local) : node.getAttribute(fullname);
7634 }
7635
7636 return this.each((value == null ? fullname.local ? attrRemoveNS : attrRemove : typeof value === "function" ? fullname.local ? attrFunctionNS : attrFunction : fullname.local ? attrConstantNS : attrConstant)(fullname, value));
7637};
7638
7639var window$1 = function (node) {
7640 return node.ownerDocument && node.ownerDocument.defaultView || // node is a Node
7641 node.document && node // node is a Window
7642 || node.defaultView; // node is a Document
7643};
7644
7645function styleRemove(name) {
7646 return function () {
7647 this.style.removeProperty(name);
7648 };
7649}
7650
7651function styleConstant(name, value, priority) {
7652 return function () {
7653 this.style.setProperty(name, value, priority);
7654 };
7655}
7656
7657function styleFunction(name, value, priority) {
7658 return function () {
7659 var v = value.apply(this, arguments);
7660 if (v == null) this.style.removeProperty(name);else this.style.setProperty(name, v, priority);
7661 };
7662}
7663
7664var selection_style = function (name, value, priority) {
7665 var node;
7666 return arguments.length > 1 ? this.each((value == null ? styleRemove : typeof value === "function" ? styleFunction : styleConstant)(name, value, priority == null ? "" : priority)) : window$1(node = this.node()).getComputedStyle(node, null).getPropertyValue(name);
7667};
7668
7669function propertyRemove(name) {
7670 return function () {
7671 delete this[name];
7672 };
7673}
7674
7675function propertyConstant(name, value) {
7676 return function () {
7677 this[name] = value;
7678 };
7679}
7680
7681function propertyFunction(name, value) {
7682 return function () {
7683 var v = value.apply(this, arguments);
7684 if (v == null) delete this[name];else this[name] = v;
7685 };
7686}
7687
7688var selection_property = function (name, value) {
7689 return arguments.length > 1 ? this.each((value == null ? propertyRemove : typeof value === "function" ? propertyFunction : propertyConstant)(name, value)) : this.node()[name];
7690};
7691
7692function classArray(string) {
7693 return string.trim().split(/^|\s+/);
7694}
7695
7696function classList(node) {
7697 return node.classList || new ClassList(node);
7698}
7699
7700function ClassList(node) {
7701 this._node = node;
7702 this._names = classArray(node.getAttribute("class") || "");
7703}
7704
7705ClassList.prototype = {
7706 add: function add(name) {
7707 var i = this._names.indexOf(name);
7708 if (i < 0) {
7709 this._names.push(name);
7710 this._node.setAttribute("class", this._names.join(" "));
7711 }
7712 },
7713 remove: function remove(name) {
7714 var i = this._names.indexOf(name);
7715 if (i >= 0) {
7716 this._names.splice(i, 1);
7717 this._node.setAttribute("class", this._names.join(" "));
7718 }
7719 },
7720 contains: function contains(name) {
7721 return this._names.indexOf(name) >= 0;
7722 }
7723};
7724
7725function classedAdd(node, names) {
7726 var list = classList(node),
7727 i = -1,
7728 n = names.length;
7729 while (++i < n) {
7730 list.add(names[i]);
7731 }
7732}
7733
7734function classedRemove(node, names) {
7735 var list = classList(node),
7736 i = -1,
7737 n = names.length;
7738 while (++i < n) {
7739 list.remove(names[i]);
7740 }
7741}
7742
7743function classedTrue(names) {
7744 return function () {
7745 classedAdd(this, names);
7746 };
7747}
7748
7749function classedFalse(names) {
7750 return function () {
7751 classedRemove(this, names);
7752 };
7753}
7754
7755function classedFunction(names, value) {
7756 return function () {
7757 (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
7758 };
7759}
7760
7761var selection_classed = function (name, value) {
7762 var names = classArray(name + "");
7763
7764 if (arguments.length < 2) {
7765 var list = classList(this.node()),
7766 i = -1,
7767 n = names.length;
7768 while (++i < n) {
7769 if (!list.contains(names[i])) return false;
7770 }return true;
7771 }
7772
7773 return this.each((typeof value === "function" ? classedFunction : value ? classedTrue : classedFalse)(names, value));
7774};
7775
7776function textRemove() {
7777 this.textContent = "";
7778}
7779
7780function textConstant(value) {
7781 return function () {
7782 this.textContent = value;
7783 };
7784}
7785
7786function textFunction(value) {
7787 return function () {
7788 var v = value.apply(this, arguments);
7789 this.textContent = v == null ? "" : v;
7790 };
7791}
7792
7793var selection_text = function (value) {
7794 return arguments.length ? this.each(value == null ? textRemove : (typeof value === "function" ? textFunction : textConstant)(value)) : this.node().textContent;
7795};
7796
7797function htmlRemove() {
7798 this.innerHTML = "";
7799}
7800
7801function htmlConstant(value) {
7802 return function () {
7803 this.innerHTML = value;
7804 };
7805}
7806
7807function htmlFunction(value) {
7808 return function () {
7809 var v = value.apply(this, arguments);
7810 this.innerHTML = v == null ? "" : v;
7811 };
7812}
7813
7814var selection_html = function (value) {
7815 return arguments.length ? this.each(value == null ? htmlRemove : (typeof value === "function" ? htmlFunction : htmlConstant)(value)) : this.node().innerHTML;
7816};
7817
7818function raise$1() {
7819 if (this.nextSibling) this.parentNode.appendChild(this);
7820}
7821
7822var selection_raise = function () {
7823 return this.each(raise$1);
7824};
7825
7826function lower() {
7827 if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
7828}
7829
7830var selection_lower = function () {
7831 return this.each(lower);
7832};
7833
7834var selection_append = function (name) {
7835 var create = typeof name === "function" ? name : creator(name);
7836 return this.select(function () {
7837 return this.appendChild(create.apply(this, arguments));
7838 });
7839};
7840
7841function constantNull() {
7842 return null;
7843}
7844
7845var selection_insert = function (name, before) {
7846 var create = typeof name === "function" ? name : creator(name),
7847 select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
7848 return this.select(function () {
7849 return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
7850 });
7851};
7852
7853function remove$1() {
7854 var parent = this.parentNode;
7855 if (parent) parent.removeChild(this);
7856}
7857
7858var selection_remove = function () {
7859 return this.each(remove$1);
7860};
7861
7862var selection_datum = function (value) {
7863 return arguments.length ? this.property("__data__", value) : this.node().__data__;
7864};
7865
7866function dispatchEvent(node, type, params) {
7867 var window = window$1(node),
7868 event = window.CustomEvent;
7869
7870 if (event) {
7871 event = new event(type, params);
7872 } else {
7873 event = window.document.createEvent("Event");
7874 if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;else event.initEvent(type, false, false);
7875 }
7876
7877 node.dispatchEvent(event);
7878}
7879
7880function dispatchConstant(type, params) {
7881 return function () {
7882 return dispatchEvent(this, type, params);
7883 };
7884}
7885
7886function dispatchFunction(type, params) {
7887 return function () {
7888 return dispatchEvent(this, type, params.apply(this, arguments));
7889 };
7890}
7891
7892var selection_dispatch = function (type, params) {
7893 return this.each((typeof params === "function" ? dispatchFunction : dispatchConstant)(type, params));
7894};
7895
7896var root = [null];
7897
7898function Selection(groups, parents) {
7899 this._groups = groups;
7900 this._parents = parents;
7901}
7902
7903function selection() {
7904 return new Selection([[document.documentElement]], root);
7905}
7906
7907Selection.prototype = selection.prototype = {
7908 constructor: Selection,
7909 select: selection_select,
7910 selectAll: selection_selectAll,
7911 filter: selection_filter,
7912 data: selection_data,
7913 enter: selection_enter,
7914 exit: selection_exit,
7915 merge: selection_merge,
7916 order: selection_order,
7917 sort: selection_sort,
7918 call: selection_call,
7919 nodes: selection_nodes,
7920 node: selection_node,
7921 size: selection_size,
7922 empty: selection_empty,
7923 each: selection_each,
7924 attr: selection_attr,
7925 style: selection_style,
7926 property: selection_property,
7927 classed: selection_classed,
7928 text: selection_text,
7929 html: selection_html,
7930 raise: selection_raise,
7931 lower: selection_lower,
7932 append: selection_append,
7933 insert: selection_insert,
7934 remove: selection_remove,
7935 datum: selection_datum,
7936 on: selection_on,
7937 dispatch: selection_dispatch
7938};
7939
7940var select = function (selector) {
7941 return typeof selector === "string" ? new Selection([[document.querySelector(selector)]], [document.documentElement]) : new Selection([[selector]], root);
7942};
7943
7944var selectAll = function (selector) {
7945 return typeof selector === "string" ? new Selection([document.querySelectorAll(selector)], [document.documentElement]) : new Selection([selector == null ? [] : selector], root);
7946};
7947
7948var touch = function (node, touches, identifier) {
7949 if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
7950
7951 for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
7952 if ((touch = touches[i]).identifier === identifier) {
7953 return point$2(node, touch);
7954 }
7955 }
7956
7957 return null;
7958};
7959
7960var touches = function (node, touches) {
7961 if (touches == null) touches = sourceEvent().touches;
7962
7963 for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
7964 points[i] = point$2(node, touches[i]);
7965 }
7966
7967 return points;
7968};
7969
7970var emptyOn = dispatch("start", "end", "interrupt");
7971var emptyTween = [];
7972
7973var CREATED = 0;
7974var SCHEDULED = 1;
7975var STARTING = 2;
7976var STARTED = 3;
7977var RUNNING = 4;
7978var ENDING = 5;
7979var ENDED = 6;
7980
7981var schedule = function (node, name, id, index, group, timing) {
7982 var schedules = node.__transition;
7983 if (!schedules) node.__transition = {};else if (id in schedules) return;
7984 create$1(node, id, {
7985 name: name,
7986 index: index, // For context during callback.
7987 group: group, // For context during callback.
7988 on: emptyOn,
7989 tween: emptyTween,
7990 time: timing.time,
7991 delay: timing.delay,
7992 duration: timing.duration,
7993 ease: timing.ease,
7994 timer: null,
7995 state: CREATED
7996 });
7997};
7998
7999function init$1(node, id) {
8000 var schedule = node.__transition;
8001 if (!schedule || !(schedule = schedule[id]) || schedule.state > CREATED) throw new Error("too late");
8002 return schedule;
8003}
8004
8005function set$5(node, id) {
8006 var schedule = node.__transition;
8007 if (!schedule || !(schedule = schedule[id]) || schedule.state > STARTING) throw new Error("too late");
8008 return schedule;
8009}
8010
8011function get$3(node, id) {
8012 var schedule = node.__transition;
8013 if (!schedule || !(schedule = schedule[id])) throw new Error("too late");
8014 return schedule;
8015}
8016
8017function create$1(node, id, self) {
8018 var schedules = node.__transition,
8019 tween;
8020
8021 // Initialize the self timer when the transition is created.
8022 // Note the actual delay is not known until the first callback!
8023 schedules[id] = self;
8024 self.timer = timer(schedule, 0, self.time);
8025
8026 function schedule(elapsed) {
8027 self.state = SCHEDULED;
8028 self.timer.restart(start, self.delay, self.time);
8029
8030 // If the elapsed delay is less than our first sleep, start immediately.
8031 if (self.delay <= elapsed) start(elapsed - self.delay);
8032 }
8033
8034 function start(elapsed) {
8035 var i, j, n, o;
8036
8037 // If the state is not SCHEDULED, then we previously errored on start.
8038 if (self.state !== SCHEDULED) return stop();
8039
8040 for (i in schedules) {
8041 o = schedules[i];
8042 if (o.name !== self.name) continue;
8043
8044 // While this element already has a starting transition during this frame,
8045 // defer starting an interrupting transition until that transition has a
8046 // chance to tick (and possibly end); see d3/d3-transition#54!
8047 if (o.state === STARTED) return timeout$1(start);
8048
8049 // Interrupt the active transition, if any.
8050 // Dispatch the interrupt event.
8051 if (o.state === RUNNING) {
8052 o.state = ENDED;
8053 o.timer.stop();
8054 o.on.call("interrupt", node, node.__data__, o.index, o.group);
8055 delete schedules[i];
8056 }
8057
8058 // Cancel any pre-empted transitions. No interrupt event is dispatched
8059 // because the cancelled transitions never started. Note that this also
8060 // removes this transition from the pending list!
8061 else if (+i < id) {
8062 o.state = ENDED;
8063 o.timer.stop();
8064 delete schedules[i];
8065 }
8066 }
8067
8068 // Defer the first tick to end of the current frame; see d3/d3#1576.
8069 // Note the transition may be canceled after start and before the first tick!
8070 // Note this must be scheduled before the start event; see d3/d3-transition#16!
8071 // Assuming this is successful, subsequent callbacks go straight to tick.
8072 timeout$1(function () {
8073 if (self.state === STARTED) {
8074 self.state = RUNNING;
8075 self.timer.restart(tick, self.delay, self.time);
8076 tick(elapsed);
8077 }
8078 });
8079
8080 // Dispatch the start event.
8081 // Note this must be done before the tween are initialized.
8082 self.state = STARTING;
8083 self.on.call("start", node, node.__data__, self.index, self.group);
8084 if (self.state !== STARTING) return; // interrupted
8085 self.state = STARTED;
8086
8087 // Initialize the tween, deleting null tween.
8088 tween = new Array(n = self.tween.length);
8089 for (i = 0, j = -1; i < n; ++i) {
8090 if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
8091 tween[++j] = o;
8092 }
8093 }
8094 tween.length = j + 1;
8095 }
8096
8097 function tick(elapsed) {
8098 var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
8099 i = -1,
8100 n = tween.length;
8101
8102 while (++i < n) {
8103 tween[i].call(null, t);
8104 }
8105
8106 // Dispatch the end event.
8107 if (self.state === ENDING) {
8108 self.on.call("end", node, node.__data__, self.index, self.group);
8109 stop();
8110 }
8111 }
8112
8113 function stop() {
8114 self.state = ENDED;
8115 self.timer.stop();
8116 delete schedules[id];
8117 for (var i in schedules) {
8118 return;
8119 } // eslint-disable-line no-unused-vars
8120 delete node.__transition;
8121 }
8122}
8123
8124var interrupt = function (node, name) {
8125 var schedules = node.__transition,
8126 schedule,
8127 active,
8128 empty = true,
8129 i;
8130
8131 if (!schedules) return;
8132
8133 name = name == null ? null : name + "";
8134
8135 for (i in schedules) {
8136 if ((schedule = schedules[i]).name !== name) {
8137 empty = false;continue;
8138 }
8139 active = schedule.state > STARTING && schedule.state < ENDING;
8140 schedule.state = ENDED;
8141 schedule.timer.stop();
8142 if (active) schedule.on.call("interrupt", node, node.__data__, schedule.index, schedule.group);
8143 delete schedules[i];
8144 }
8145
8146 if (empty) delete node.__transition;
8147};
8148
8149var selection_interrupt = function (name) {
8150 return this.each(function () {
8151 interrupt(this, name);
8152 });
8153};
8154
8155function tweenRemove(id, name) {
8156 var tween0, tween1;
8157 return function () {
8158 var schedule = set$5(this, id),
8159 tween = schedule.tween;
8160
8161 // If this node shared tween with the previous node,
8162 // just assign the updated shared tween and we’re done!
8163 // Otherwise, copy-on-write.
8164 if (tween !== tween0) {
8165 tween1 = tween0 = tween;
8166 for (var i = 0, n = tween1.length; i < n; ++i) {
8167 if (tween1[i].name === name) {
8168 tween1 = tween1.slice();
8169 tween1.splice(i, 1);
8170 break;
8171 }
8172 }
8173 }
8174
8175 schedule.tween = tween1;
8176 };
8177}
8178
8179function tweenFunction(id, name, value) {
8180 var tween0, tween1;
8181 if (typeof value !== "function") throw new Error();
8182 return function () {
8183 var schedule = set$5(this, id),
8184 tween = schedule.tween;
8185
8186 // If this node shared tween with the previous node,
8187 // just assign the updated shared tween and we’re done!
8188 // Otherwise, copy-on-write.
8189 if (tween !== tween0) {
8190 tween1 = (tween0 = tween).slice();
8191 for (var t = { name: name, value: value }, i = 0, n = tween1.length; i < n; ++i) {
8192 if (tween1[i].name === name) {
8193 tween1[i] = t;
8194 break;
8195 }
8196 }
8197 if (i === n) tween1.push(t);
8198 }
8199
8200 schedule.tween = tween1;
8201 };
8202}
8203
8204var transition_tween = function (name, value) {
8205 var id = this._id;
8206
8207 name += "";
8208
8209 if (arguments.length < 2) {
8210 var tween = get$3(this.node(), id).tween;
8211 for (var i = 0, n = tween.length, t; i < n; ++i) {
8212 if ((t = tween[i]).name === name) {
8213 return t.value;
8214 }
8215 }
8216 return null;
8217 }
8218
8219 return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
8220};
8221
8222function tweenValue(transition, name, value) {
8223 var id = transition._id;
8224
8225 transition.each(function () {
8226 var schedule = set$5(this, id);
8227 (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
8228 });
8229
8230 return function (node) {
8231 return get$3(node, id).value[name];
8232 };
8233}
8234
8235var interpolate$1 = function (a, b) {
8236 var c;
8237 return (typeof b === "number" ? interpolateNumber : b instanceof color ? interpolateRgb : (c = color(b)) ? (b = c, interpolateRgb) : interpolateString)(a, b);
8238};
8239
8240function attrRemove$1(name) {
8241 return function () {
8242 this.removeAttribute(name);
8243 };
8244}
8245
8246function attrRemoveNS$1(fullname) {
8247 return function () {
8248 this.removeAttributeNS(fullname.space, fullname.local);
8249 };
8250}
8251
8252function attrConstant$1(name, interpolate$$1, value1) {
8253 var value00, interpolate0;
8254 return function () {
8255 var value0 = this.getAttribute(name);
8256 return value0 === value1 ? null : value0 === value00 ? interpolate0 : interpolate0 = interpolate$$1(value00 = value0, value1);
8257 };
8258}
8259
8260function attrConstantNS$1(fullname, interpolate$$1, value1) {
8261 var value00, interpolate0;
8262 return function () {
8263 var value0 = this.getAttributeNS(fullname.space, fullname.local);
8264 return value0 === value1 ? null : value0 === value00 ? interpolate0 : interpolate0 = interpolate$$1(value00 = value0, value1);
8265 };
8266}
8267
8268function attrFunction$1(name, interpolate$$1, value) {
8269 var value00, value10, interpolate0;
8270 return function () {
8271 var value0,
8272 value1 = value(this);
8273 if (value1 == null) return void this.removeAttribute(name);
8274 value0 = this.getAttribute(name);
8275 return value0 === value1 ? null : value0 === value00 && value1 === value10 ? interpolate0 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
8276 };
8277}
8278
8279function attrFunctionNS$1(fullname, interpolate$$1, value) {
8280 var value00, value10, interpolate0;
8281 return function () {
8282 var value0,
8283 value1 = value(this);
8284 if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
8285 value0 = this.getAttributeNS(fullname.space, fullname.local);
8286 return value0 === value1 ? null : value0 === value00 && value1 === value10 ? interpolate0 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
8287 };
8288}
8289
8290var transition_attr = function (name, value) {
8291 var fullname = namespace(name),
8292 i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
8293 return this.attrTween(name, typeof value === "function" ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value)) : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname) : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
8294};
8295
8296function attrTweenNS(fullname, value) {
8297 function tween() {
8298 var node = this,
8299 i = value.apply(node, arguments);
8300 return i && function (t) {
8301 node.setAttributeNS(fullname.space, fullname.local, i(t));
8302 };
8303 }
8304 tween._value = value;
8305 return tween;
8306}
8307
8308function attrTween(name, value) {
8309 function tween() {
8310 var node = this,
8311 i = value.apply(node, arguments);
8312 return i && function (t) {
8313 node.setAttribute(name, i(t));
8314 };
8315 }
8316 tween._value = value;
8317 return tween;
8318}
8319
8320var transition_attrTween = function (name, value) {
8321 var key = "attr." + name;
8322 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
8323 if (value == null) return this.tween(key, null);
8324 if (typeof value !== "function") throw new Error();
8325 var fullname = namespace(name);
8326 return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
8327};
8328
8329function delayFunction(id, value) {
8330 return function () {
8331 init$1(this, id).delay = +value.apply(this, arguments);
8332 };
8333}
8334
8335function delayConstant(id, value) {
8336 return value = +value, function () {
8337 init$1(this, id).delay = value;
8338 };
8339}
8340
8341var transition_delay = function (value) {
8342 var id = this._id;
8343
8344 return arguments.length ? this.each((typeof value === "function" ? delayFunction : delayConstant)(id, value)) : get$3(this.node(), id).delay;
8345};
8346
8347function durationFunction(id, value) {
8348 return function () {
8349 set$5(this, id).duration = +value.apply(this, arguments);
8350 };
8351}
8352
8353function durationConstant(id, value) {
8354 return value = +value, function () {
8355 set$5(this, id).duration = value;
8356 };
8357}
8358
8359var transition_duration = function (value) {
8360 var id = this._id;
8361
8362 return arguments.length ? this.each((typeof value === "function" ? durationFunction : durationConstant)(id, value)) : get$3(this.node(), id).duration;
8363};
8364
8365function easeConstant(id, value) {
8366 if (typeof value !== "function") throw new Error();
8367 return function () {
8368 set$5(this, id).ease = value;
8369 };
8370}
8371
8372var transition_ease = function (value) {
8373 var id = this._id;
8374
8375 return arguments.length ? this.each(easeConstant(id, value)) : get$3(this.node(), id).ease;
8376};
8377
8378var transition_filter = function (match) {
8379 if (typeof match !== "function") match = matcher$1(match);
8380
8381 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
8382 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
8383 if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
8384 subgroup.push(node);
8385 }
8386 }
8387 }
8388
8389 return new Transition(subgroups, this._parents, this._name, this._id);
8390};
8391
8392var transition_merge = function (transition) {
8393 if (transition._id !== this._id) throw new Error();
8394
8395 for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
8396 for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
8397 if (node = group0[i] || group1[i]) {
8398 merge[i] = node;
8399 }
8400 }
8401 }
8402
8403 for (; j < m0; ++j) {
8404 merges[j] = groups0[j];
8405 }
8406
8407 return new Transition(merges, this._parents, this._name, this._id);
8408};
8409
8410function start$1(name) {
8411 return (name + "").trim().split(/^|\s+/).every(function (t) {
8412 var i = t.indexOf(".");
8413 if (i >= 0) t = t.slice(0, i);
8414 return !t || t === "start";
8415 });
8416}
8417
8418function onFunction(id, name, listener) {
8419 var on0,
8420 on1,
8421 sit = start$1(name) ? init$1 : set$5;
8422 return function () {
8423 var schedule = sit(this, id),
8424 on = schedule.on;
8425
8426 // If this node shared a dispatch with the previous node,
8427 // just assign the updated shared dispatch and we’re done!
8428 // Otherwise, copy-on-write.
8429 if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
8430
8431 schedule.on = on1;
8432 };
8433}
8434
8435var transition_on = function (name, listener) {
8436 var id = this._id;
8437
8438 return arguments.length < 2 ? get$3(this.node(), id).on.on(name) : this.each(onFunction(id, name, listener));
8439};
8440
8441function removeFunction(id) {
8442 return function () {
8443 var parent = this.parentNode;
8444 for (var i in this.__transition) {
8445 if (+i !== id) return;
8446 }if (parent) parent.removeChild(this);
8447 };
8448}
8449
8450var transition_remove = function () {
8451 return this.on("end.remove", removeFunction(this._id));
8452};
8453
8454var transition_select = function (select$$1) {
8455 var name = this._name,
8456 id = this._id;
8457
8458 if (typeof select$$1 !== "function") select$$1 = selector(select$$1);
8459
8460 for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
8461 for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
8462 if ((node = group[i]) && (subnode = select$$1.call(node, node.__data__, i, group))) {
8463 if ("__data__" in node) subnode.__data__ = node.__data__;
8464 subgroup[i] = subnode;
8465 schedule(subgroup[i], name, id, i, subgroup, get$3(node, id));
8466 }
8467 }
8468 }
8469
8470 return new Transition(subgroups, this._parents, name, id);
8471};
8472
8473var transition_selectAll = function (select$$1) {
8474 var name = this._name,
8475 id = this._id;
8476
8477 if (typeof select$$1 !== "function") select$$1 = selectorAll(select$$1);
8478
8479 for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
8480 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
8481 if (node = group[i]) {
8482 for (var children = select$$1.call(node, node.__data__, i, group), child, inherit = get$3(node, id), k = 0, l = children.length; k < l; ++k) {
8483 if (child = children[k]) {
8484 schedule(child, name, id, k, children, inherit);
8485 }
8486 }
8487 subgroups.push(children);
8488 parents.push(node);
8489 }
8490 }
8491 }
8492
8493 return new Transition(subgroups, parents, name, id);
8494};
8495
8496var Selection$1 = selection.prototype.constructor;
8497
8498var transition_selection = function () {
8499 return new Selection$1(this._groups, this._parents);
8500};
8501
8502function styleRemove$1(name, interpolate$$1) {
8503 var value00, value10, interpolate0;
8504 return function () {
8505 var style = window$1(this).getComputedStyle(this, null),
8506 value0 = style.getPropertyValue(name),
8507 value1 = (this.style.removeProperty(name), style.getPropertyValue(name));
8508 return value0 === value1 ? null : value0 === value00 && value1 === value10 ? interpolate0 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
8509 };
8510}
8511
8512function styleRemoveEnd(name) {
8513 return function () {
8514 this.style.removeProperty(name);
8515 };
8516}
8517
8518function styleConstant$1(name, interpolate$$1, value1) {
8519 var value00, interpolate0;
8520 return function () {
8521 var value0 = window$1(this).getComputedStyle(this, null).getPropertyValue(name);
8522 return value0 === value1 ? null : value0 === value00 ? interpolate0 : interpolate0 = interpolate$$1(value00 = value0, value1);
8523 };
8524}
8525
8526function styleFunction$1(name, interpolate$$1, value) {
8527 var value00, value10, interpolate0;
8528 return function () {
8529 var style = window$1(this).getComputedStyle(this, null),
8530 value0 = style.getPropertyValue(name),
8531 value1 = value(this);
8532 if (value1 == null) value1 = (this.style.removeProperty(name), style.getPropertyValue(name));
8533 return value0 === value1 ? null : value0 === value00 && value1 === value10 ? interpolate0 : interpolate0 = interpolate$$1(value00 = value0, value10 = value1);
8534 };
8535}
8536
8537var transition_style = function (name, value, priority) {
8538 var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
8539 return value == null ? this.styleTween(name, styleRemove$1(name, i)).on("end.style." + name, styleRemoveEnd(name)) : this.styleTween(name, typeof value === "function" ? styleFunction$1(name, i, tweenValue(this, "style." + name, value)) : styleConstant$1(name, i, value), priority);
8540};
8541
8542function styleTween(name, value, priority) {
8543 function tween() {
8544 var node = this,
8545 i = value.apply(node, arguments);
8546 return i && function (t) {
8547 node.style.setProperty(name, i(t), priority);
8548 };
8549 }
8550 tween._value = value;
8551 return tween;
8552}
8553
8554var transition_styleTween = function (name, value, priority) {
8555 var key = "style." + (name += "");
8556 if (arguments.length < 2) return (key = this.tween(key)) && key._value;
8557 if (value == null) return this.tween(key, null);
8558 if (typeof value !== "function") throw new Error();
8559 return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
8560};
8561
8562function textConstant$1(value) {
8563 return function () {
8564 this.textContent = value;
8565 };
8566}
8567
8568function textFunction$1(value) {
8569 return function () {
8570 var value1 = value(this);
8571 this.textContent = value1 == null ? "" : value1;
8572 };
8573}
8574
8575var transition_text = function (value) {
8576 return this.tween("text", typeof value === "function" ? textFunction$1(tweenValue(this, "text", value)) : textConstant$1(value == null ? "" : value + ""));
8577};
8578
8579var transition_transition = function () {
8580 var name = this._name,
8581 id0 = this._id,
8582 id1 = newId();
8583
8584 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
8585 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
8586 if (node = group[i]) {
8587 var inherit = get$3(node, id0);
8588 schedule(node, name, id1, i, group, {
8589 time: inherit.time + inherit.delay + inherit.duration,
8590 delay: 0,
8591 duration: inherit.duration,
8592 ease: inherit.ease
8593 });
8594 }
8595 }
8596 }
8597
8598 return new Transition(groups, this._parents, name, id1);
8599};
8600
8601var id = 0;
8602
8603function Transition(groups, parents, name, id) {
8604 this._groups = groups;
8605 this._parents = parents;
8606 this._name = name;
8607 this._id = id;
8608}
8609
8610function transition(name) {
8611 return selection().transition(name);
8612}
8613
8614function newId() {
8615 return ++id;
8616}
8617
8618var selection_prototype = selection.prototype;
8619
8620Transition.prototype = transition.prototype = {
8621 constructor: Transition,
8622 select: transition_select,
8623 selectAll: transition_selectAll,
8624 filter: transition_filter,
8625 merge: transition_merge,
8626 selection: transition_selection,
8627 transition: transition_transition,
8628 call: selection_prototype.call,
8629 nodes: selection_prototype.nodes,
8630 node: selection_prototype.node,
8631 size: selection_prototype.size,
8632 empty: selection_prototype.empty,
8633 each: selection_prototype.each,
8634 on: transition_on,
8635 attr: transition_attr,
8636 attrTween: transition_attrTween,
8637 style: transition_style,
8638 styleTween: transition_styleTween,
8639 text: transition_text,
8640 remove: transition_remove,
8641 tween: transition_tween,
8642 delay: transition_delay,
8643 duration: transition_duration,
8644 ease: transition_ease
8645};
8646
8647var defaultTiming = {
8648 time: null, // Set on use.
8649 delay: 0,
8650 duration: 250,
8651 ease: cubicInOut
8652};
8653
8654function inherit(node, id) {
8655 var timing;
8656 while (!(timing = node.__transition) || !(timing = timing[id])) {
8657 if (!(node = node.parentNode)) {
8658 return defaultTiming.time = now(), defaultTiming;
8659 }
8660 }
8661 return timing;
8662}
8663
8664var selection_transition = function (name) {
8665 var id, timing;
8666
8667 if (name instanceof Transition) {
8668 id = name._id, name = name._name;
8669 } else {
8670 id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
8671 }
8672
8673 for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
8674 for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
8675 if (node = group[i]) {
8676 schedule(node, name, id, i, group, timing || inherit(node, id));
8677 }
8678 }
8679 }
8680
8681 return new Transition(groups, this._parents, name, id);
8682};
8683
8684selection.prototype.interrupt = selection_interrupt;
8685selection.prototype.transition = selection_transition;
8686
8687var root$1 = [null];
8688
8689var active = function (node, name) {
8690 var schedules = node.__transition,
8691 schedule,
8692 i;
8693
8694 if (schedules) {
8695 name = name == null ? null : name + "";
8696 for (i in schedules) {
8697 if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
8698 return new Transition([[node]], root$1, name, +i);
8699 }
8700 }
8701 }
8702
8703 return null;
8704};
8705
8706var slice$3 = Array.prototype.slice;
8707
8708var identity$5 = function (x) {
8709 return x;
8710};
8711
8712var top = 1;
8713var right$1 = 2;
8714var bottom = 3;
8715var left$1 = 4;
8716var epsilon$2 = 1e-6;
8717
8718function translateX(scale0, scale1, d) {
8719 var x = scale0(d);
8720 return "translate(" + (isFinite(x) ? x : scale1(d)) + ",0)";
8721}
8722
8723function translateY(scale0, scale1, d) {
8724 var y = scale0(d);
8725 return "translate(0," + (isFinite(y) ? y : scale1(d)) + ")";
8726}
8727
8728function center(scale) {
8729 var offset = scale.bandwidth() / 2;
8730 if (scale.round()) offset = Math.round(offset);
8731 return function (d) {
8732 return scale(d) + offset;
8733 };
8734}
8735
8736function entering() {
8737 return !this.__axis;
8738}
8739
8740function axis(orient, scale) {
8741 var tickArguments = [],
8742 tickValues = null,
8743 tickFormat = null,
8744 tickSizeInner = 6,
8745 tickSizeOuter = 6,
8746 tickPadding = 3;
8747
8748 function axis(context) {
8749 var values = tickValues == null ? scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain() : tickValues,
8750 format = tickFormat == null ? scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$5 : tickFormat,
8751 spacing = Math.max(tickSizeInner, 0) + tickPadding,
8752 transform = orient === top || orient === bottom ? translateX : translateY,
8753 range = scale.range(),
8754 range0 = range[0] + 0.5,
8755 range1 = range[range.length - 1] + 0.5,
8756 position = (scale.bandwidth ? center : identity$5)(scale.copy()),
8757 selection = context.selection ? context.selection() : context,
8758 path = selection.selectAll(".domain").data([null]),
8759 tick = selection.selectAll(".tick").data(values, scale).order(),
8760 tickExit = tick.exit(),
8761 tickEnter = tick.enter().append("g").attr("class", "tick"),
8762 line = tick.select("line"),
8763 text = tick.select("text"),
8764 k = orient === top || orient === left$1 ? -1 : 1,
8765 x,
8766 y = orient === left$1 || orient === right$1 ? (x = "x", "y") : (x = "y", "x");
8767
8768 path = path.merge(path.enter().insert("path", ".tick").attr("class", "domain").attr("stroke", "#000"));
8769
8770 tick = tick.merge(tickEnter);
8771
8772 line = line.merge(tickEnter.append("line").attr("stroke", "#000").attr(x + "2", k * tickSizeInner).attr(y + "1", 0.5).attr(y + "2", 0.5));
8773
8774 text = text.merge(tickEnter.append("text").attr("fill", "#000").attr(x, k * spacing).attr(y, 0.5).attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
8775
8776 if (context !== selection) {
8777 path = path.transition(context);
8778 tick = tick.transition(context);
8779 line = line.transition(context);
8780 text = text.transition(context);
8781
8782 tickExit = tickExit.transition(context).attr("opacity", epsilon$2).attr("transform", function (d) {
8783 return transform(position, this.parentNode.__axis || position, d);
8784 });
8785
8786 tickEnter.attr("opacity", epsilon$2).attr("transform", function (d) {
8787 return transform(this.parentNode.__axis || position, position, d);
8788 });
8789 }
8790
8791 tickExit.remove();
8792
8793 path.attr("d", orient === left$1 || orient == right$1 ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
8794
8795 tick.attr("opacity", 1).attr("transform", function (d) {
8796 return transform(position, position, d);
8797 });
8798
8799 line.attr(x + "2", k * tickSizeInner);
8800
8801 text.attr(x, k * spacing).text(format);
8802
8803 selection.filter(entering).attr("fill", "none").attr("font-size", 10).attr("font-family", "sans-serif").attr("text-anchor", orient === right$1 ? "start" : orient === left$1 ? "end" : "middle");
8804
8805 selection.each(function () {
8806 this.__axis = position;
8807 });
8808 }
8809
8810 axis.scale = function (_) {
8811 return arguments.length ? (scale = _, axis) : scale;
8812 };
8813
8814 axis.ticks = function () {
8815 return tickArguments = slice$3.call(arguments), axis;
8816 };
8817
8818 axis.tickArguments = function (_) {
8819 return arguments.length ? (tickArguments = _ == null ? [] : slice$3.call(_), axis) : tickArguments.slice();
8820 };
8821
8822 axis.tickValues = function (_) {
8823 return arguments.length ? (tickValues = _ == null ? null : slice$3.call(_), axis) : tickValues && tickValues.slice();
8824 };
8825
8826 axis.tickFormat = function (_) {
8827 return arguments.length ? (tickFormat = _, axis) : tickFormat;
8828 };
8829
8830 axis.tickSize = function (_) {
8831 return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
8832 };
8833
8834 axis.tickSizeInner = function (_) {
8835 return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
8836 };
8837
8838 axis.tickSizeOuter = function (_) {
8839 return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
8840 };
8841
8842 axis.tickPadding = function (_) {
8843 return arguments.length ? (tickPadding = +_, axis) : tickPadding;
8844 };
8845
8846 return axis;
8847}
8848
8849function axisTop(scale) {
8850 return axis(top, scale);
8851}
8852
8853function axisRight(scale) {
8854 return axis(right$1, scale);
8855}
8856
8857function axisBottom(scale) {
8858 return axis(bottom, scale);
8859}
8860
8861function axisLeft(scale) {
8862 return axis(left$1, scale);
8863}
8864
8865function defaultSeparation(a, b) {
8866 return a.parent === b.parent ? 1 : 2;
8867}
8868
8869function meanX(children) {
8870 return children.reduce(meanXReduce, 0) / children.length;
8871}
8872
8873function meanXReduce(x, c) {
8874 return x + c.x;
8875}
8876
8877function maxY(children) {
8878 return 1 + children.reduce(maxYReduce, 0);
8879}
8880
8881function maxYReduce(y, c) {
8882 return Math.max(y, c.y);
8883}
8884
8885function leafLeft(node) {
8886 var children;
8887 while (children = node.children) {
8888 node = children[0];
8889 }return node;
8890}
8891
8892function leafRight(node) {
8893 var children;
8894 while (children = node.children) {
8895 node = children[children.length - 1];
8896 }return node;
8897}
8898
8899var cluster = function () {
8900 var separation = defaultSeparation,
8901 dx = 1,
8902 dy = 1,
8903 nodeSize = false;
8904
8905 function cluster(root) {
8906 var previousNode,
8907 x = 0;
8908
8909 // First walk, computing the initial x & y values.
8910 root.eachAfter(function (node) {
8911 var children = node.children;
8912 if (children) {
8913 node.x = meanX(children);
8914 node.y = maxY(children);
8915 } else {
8916 node.x = previousNode ? x += separation(node, previousNode) : 0;
8917 node.y = 0;
8918 previousNode = node;
8919 }
8920 });
8921
8922 var left = leafLeft(root),
8923 right = leafRight(root),
8924 x0 = left.x - separation(left, right) / 2,
8925 x1 = right.x + separation(right, left) / 2;
8926
8927 // Second walk, normalizing x & y to the desired size.
8928 return root.eachAfter(nodeSize ? function (node) {
8929 node.x = (node.x - root.x) * dx;
8930 node.y = (root.y - node.y) * dy;
8931 } : function (node) {
8932 node.x = (node.x - x0) / (x1 - x0) * dx;
8933 node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
8934 });
8935 }
8936
8937 cluster.separation = function (x) {
8938 return arguments.length ? (separation = x, cluster) : separation;
8939 };
8940
8941 cluster.size = function (x) {
8942 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : nodeSize ? null : [dx, dy];
8943 };
8944
8945 cluster.nodeSize = function (x) {
8946 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : nodeSize ? [dx, dy] : null;
8947 };
8948
8949 return cluster;
8950};
8951
8952var node_each = function (callback) {
8953 var node = this,
8954 current,
8955 next = [node],
8956 children,
8957 i,
8958 n;
8959 do {
8960 current = next.reverse(), next = [];
8961 while (node = current.pop()) {
8962 callback(node), children = node.children;
8963 if (children) for (i = 0, n = children.length; i < n; ++i) {
8964 next.push(children[i]);
8965 }
8966 }
8967 } while (next.length);
8968 return this;
8969};
8970
8971var node_eachBefore = function (callback) {
8972 var node = this,
8973 nodes = [node],
8974 children,
8975 i;
8976 while (node = nodes.pop()) {
8977 callback(node), children = node.children;
8978 if (children) for (i = children.length - 1; i >= 0; --i) {
8979 nodes.push(children[i]);
8980 }
8981 }
8982 return this;
8983};
8984
8985var node_eachAfter = function (callback) {
8986 var node = this,
8987 nodes = [node],
8988 next = [],
8989 children,
8990 i,
8991 n;
8992 while (node = nodes.pop()) {
8993 next.push(node), children = node.children;
8994 if (children) for (i = 0, n = children.length; i < n; ++i) {
8995 nodes.push(children[i]);
8996 }
8997 }
8998 while (node = next.pop()) {
8999 callback(node);
9000 }
9001 return this;
9002};
9003
9004var node_sum = function (value) {
9005 return this.eachAfter(function (node) {
9006 var sum = +value(node.data) || 0,
9007 children = node.children,
9008 i = children && children.length;
9009 while (--i >= 0) {
9010 sum += children[i].value;
9011 }node.value = sum;
9012 });
9013};
9014
9015var node_sort = function (compare) {
9016 return this.eachBefore(function (node) {
9017 if (node.children) {
9018 node.children.sort(compare);
9019 }
9020 });
9021};
9022
9023var node_path = function (end) {
9024 var start = this,
9025 ancestor = leastCommonAncestor(start, end),
9026 nodes = [start];
9027 while (start !== ancestor) {
9028 start = start.parent;
9029 nodes.push(start);
9030 }
9031 var k = nodes.length;
9032 while (end !== ancestor) {
9033 nodes.splice(k, 0, end);
9034 end = end.parent;
9035 }
9036 return nodes;
9037};
9038
9039function leastCommonAncestor(a, b) {
9040 if (a === b) return a;
9041 var aNodes = a.ancestors(),
9042 bNodes = b.ancestors(),
9043 c = null;
9044 a = aNodes.pop();
9045 b = bNodes.pop();
9046 while (a === b) {
9047 c = a;
9048 a = aNodes.pop();
9049 b = bNodes.pop();
9050 }
9051 return c;
9052}
9053
9054var node_ancestors = function () {
9055 var node = this,
9056 nodes = [node];
9057 while (node = node.parent) {
9058 nodes.push(node);
9059 }
9060 return nodes;
9061};
9062
9063var node_descendants = function () {
9064 var nodes = [];
9065 this.each(function (node) {
9066 nodes.push(node);
9067 });
9068 return nodes;
9069};
9070
9071var node_leaves = function () {
9072 var leaves = [];
9073 this.eachBefore(function (node) {
9074 if (!node.children) {
9075 leaves.push(node);
9076 }
9077 });
9078 return leaves;
9079};
9080
9081var node_links = function () {
9082 var root = this,
9083 links = [];
9084 root.each(function (node) {
9085 if (node !== root) {
9086 // Don’t include the root’s parent, if any.
9087 links.push({ source: node.parent, target: node });
9088 }
9089 });
9090 return links;
9091};
9092
9093function hierarchy(data, children) {
9094 var root = new Node(data),
9095 valued = +data.value && (root.value = data.value),
9096 node,
9097 nodes = [root],
9098 child,
9099 childs,
9100 i,
9101 n;
9102
9103 if (children == null) children = defaultChildren;
9104
9105 while (node = nodes.pop()) {
9106 if (valued) node.value = +node.data.value;
9107 if ((childs = children(node.data)) && (n = childs.length)) {
9108 node.children = new Array(n);
9109 for (i = n - 1; i >= 0; --i) {
9110 nodes.push(child = node.children[i] = new Node(childs[i]));
9111 child.parent = node;
9112 child.depth = node.depth + 1;
9113 }
9114 }
9115 }
9116
9117 return root.eachBefore(computeHeight);
9118}
9119
9120function node_copy() {
9121 return hierarchy(this).eachBefore(copyData);
9122}
9123
9124function defaultChildren(d) {
9125 return d.children;
9126}
9127
9128function copyData(node) {
9129 node.data = node.data.data;
9130}
9131
9132function computeHeight(node) {
9133 var height = 0;
9134 do {
9135 node.height = height;
9136 } while ((node = node.parent) && node.height < ++height);
9137}
9138
9139function Node(data) {
9140 this.data = data;
9141 this.depth = this.height = 0;
9142 this.parent = null;
9143}
9144
9145Node.prototype = hierarchy.prototype = {
9146 constructor: Node,
9147 each: node_each,
9148 eachAfter: node_eachAfter,
9149 eachBefore: node_eachBefore,
9150 sum: node_sum,
9151 sort: node_sort,
9152 path: node_path,
9153 ancestors: node_ancestors,
9154 descendants: node_descendants,
9155 leaves: node_leaves,
9156 links: node_links,
9157 copy: node_copy
9158};
9159
9160function Node$2(value) {
9161 this._ = value;
9162 this.next = null;
9163}
9164
9165var shuffle$1 = function (array) {
9166 var i,
9167 n = (array = array.slice()).length,
9168 head = null,
9169 node = head;
9170
9171 while (n) {
9172 var next = new Node$2(array[n - 1]);
9173 if (node) node = node.next = next;else node = head = next;
9174 array[i] = array[--n];
9175 }
9176
9177 return {
9178 head: head,
9179 tail: node
9180 };
9181};
9182
9183var enclose = function (circles) {
9184 return encloseN(shuffle$1(circles), []);
9185};
9186
9187function encloses(a, b) {
9188 var dx = b.x - a.x,
9189 dy = b.y - a.y,
9190 dr = a.r - b.r;
9191 return dr * dr + 1e-6 > dx * dx + dy * dy;
9192}
9193
9194// Returns the smallest circle that contains circles L and intersects circles B.
9195function encloseN(L, B) {
9196 var circle,
9197 l0 = null,
9198 l1 = L.head,
9199 l2,
9200 p1;
9201
9202 switch (B.length) {
9203 case 1:
9204 circle = enclose1(B[0]);break;
9205 case 2:
9206 circle = enclose2(B[0], B[1]);break;
9207 case 3:
9208 circle = enclose3(B[0], B[1], B[2]);break;
9209 }
9210
9211 while (l1) {
9212 p1 = l1._, l2 = l1.next;
9213 if (!circle || !encloses(circle, p1)) {
9214
9215 // Temporarily truncate L before l1.
9216 if (l0) L.tail = l0, l0.next = null;else L.head = L.tail = null;
9217
9218 B.push(p1);
9219 circle = encloseN(L, B); // Note: reorders L!
9220 B.pop();
9221
9222 // Move l1 to the front of L and reconnect the truncated list L.
9223 if (L.head) l1.next = L.head, L.head = l1;else l1.next = null, L.head = L.tail = l1;
9224 l0 = L.tail, l0.next = l2;
9225 } else {
9226 l0 = l1;
9227 }
9228 l1 = l2;
9229 }
9230
9231 L.tail = l0;
9232 return circle;
9233}
9234
9235function enclose1(a) {
9236 return {
9237 x: a.x,
9238 y: a.y,
9239 r: a.r
9240 };
9241}
9242
9243function enclose2(a, b) {
9244 var x1 = a.x,
9245 y1 = a.y,
9246 r1 = a.r,
9247 x2 = b.x,
9248 y2 = b.y,
9249 r2 = b.r,
9250 x21 = x2 - x1,
9251 y21 = y2 - y1,
9252 r21 = r2 - r1,
9253 l = Math.sqrt(x21 * x21 + y21 * y21);
9254 return {
9255 x: (x1 + x2 + x21 / l * r21) / 2,
9256 y: (y1 + y2 + y21 / l * r21) / 2,
9257 r: (l + r1 + r2) / 2
9258 };
9259}
9260
9261function enclose3(a, b, c) {
9262 var x1 = a.x,
9263 y1 = a.y,
9264 r1 = a.r,
9265 x2 = b.x,
9266 y2 = b.y,
9267 r2 = b.r,
9268 x3 = c.x,
9269 y3 = c.y,
9270 r3 = c.r,
9271 a2 = 2 * (x1 - x2),
9272 b2 = 2 * (y1 - y2),
9273 c2 = 2 * (r2 - r1),
9274 d2 = x1 * x1 + y1 * y1 - r1 * r1 - x2 * x2 - y2 * y2 + r2 * r2,
9275 a3 = 2 * (x1 - x3),
9276 b3 = 2 * (y1 - y3),
9277 c3 = 2 * (r3 - r1),
9278 d3 = x1 * x1 + y1 * y1 - r1 * r1 - x3 * x3 - y3 * y3 + r3 * r3,
9279 ab = a3 * b2 - a2 * b3,
9280 xa = (b2 * d3 - b3 * d2) / ab - x1,
9281 xb = (b3 * c2 - b2 * c3) / ab,
9282 ya = (a3 * d2 - a2 * d3) / ab - y1,
9283 yb = (a2 * c3 - a3 * c2) / ab,
9284 A = xb * xb + yb * yb - 1,
9285 B = 2 * (xa * xb + ya * yb + r1),
9286 C = xa * xa + ya * ya - r1 * r1,
9287 r = (-B - Math.sqrt(B * B - 4 * A * C)) / (2 * A);
9288 return {
9289 x: xa + xb * r + x1,
9290 y: ya + yb * r + y1,
9291 r: r
9292 };
9293}
9294
9295function place(a, b, c) {
9296 var ax = a.x,
9297 ay = a.y,
9298 da = b.r + c.r,
9299 db = a.r + c.r,
9300 dx = b.x - ax,
9301 dy = b.y - ay,
9302 dc = dx * dx + dy * dy;
9303 if (dc) {
9304 var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
9305 y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
9306 c.x = ax + x * dx + y * dy;
9307 c.y = ay + x * dy - y * dx;
9308 } else {
9309 c.x = ax + db;
9310 c.y = ay;
9311 }
9312}
9313
9314function intersects(a, b) {
9315 var dx = b.x - a.x,
9316 dy = b.y - a.y,
9317 dr = a.r + b.r;
9318 return dr * dr > dx * dx + dy * dy;
9319}
9320
9321function distance2(circle, x, y) {
9322 var dx = circle.x - x,
9323 dy = circle.y - y;
9324 return dx * dx + dy * dy;
9325}
9326
9327function Node$1(circle) {
9328 this._ = circle;
9329 this.next = null;
9330 this.previous = null;
9331}
9332
9333function packEnclose(circles) {
9334 if (!(n = circles.length)) return 0;
9335
9336 var a, b, c, n;
9337
9338 // Place the first circle.
9339 a = circles[0], a.x = 0, a.y = 0;
9340 if (!(n > 1)) return a.r;
9341
9342 // Place the second circle.
9343 b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
9344 if (!(n > 2)) return a.r + b.r;
9345
9346 // Place the third circle.
9347 place(b, a, c = circles[2]);
9348
9349 // Initialize the weighted centroid.
9350 var aa = a.r * a.r,
9351 ba = b.r * b.r,
9352 ca = c.r * c.r,
9353 oa = aa + ba + ca,
9354 ox = aa * a.x + ba * b.x + ca * c.x,
9355 oy = aa * a.y + ba * b.y + ca * c.y,
9356 cx,
9357 cy,
9358 i,
9359 j,
9360 k,
9361 sj,
9362 sk;
9363
9364 // Initialize the front-chain using the first three circles a, b and c.
9365 a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
9366 a.next = c.previous = b;
9367 b.next = a.previous = c;
9368 c.next = b.previous = a;
9369
9370 // Attempt to place each remaining circle…
9371 pack: for (i = 3; i < n; ++i) {
9372 place(a._, b._, c = circles[i]), c = new Node$1(c);
9373
9374 // If there are only three elements in the front-chain…
9375 if ((k = a.previous) === (j = b.next)) {
9376 // If the new circle intersects the third circle,
9377 // rotate the front chain to try the next position.
9378 if (intersects(j._, c._)) {
9379 a = b, b = j, --i;
9380 continue pack;
9381 }
9382 }
9383
9384 // Find the closest intersecting circle on the front-chain, if any.
9385 else {
9386 sj = j._.r, sk = k._.r;
9387 do {
9388 if (sj <= sk) {
9389 if (intersects(j._, c._)) {
9390 b = j, a.next = b, b.previous = a, --i;
9391 continue pack;
9392 }
9393 j = j.next, sj += j._.r;
9394 } else {
9395 if (intersects(k._, c._)) {
9396 a = k, a.next = b, b.previous = a, --i;
9397 continue pack;
9398 }
9399 k = k.previous, sk += k._.r;
9400 }
9401 } while (j !== k.next);
9402 }
9403
9404 // Success! Insert the new circle c between a and b.
9405 c.previous = a, c.next = b, a.next = b.previous = b = c;
9406
9407 // Update the weighted centroid.
9408 oa += ca = c._.r * c._.r;
9409 ox += ca * c._.x;
9410 oy += ca * c._.y;
9411
9412 // Compute the new closest circle a to centroid.
9413 aa = distance2(a._, cx = ox / oa, cy = oy / oa);
9414 while ((c = c.next) !== b) {
9415 if ((ca = distance2(c._, cx, cy)) < aa) {
9416 a = c, aa = ca;
9417 }
9418 }
9419 b = a.next;
9420 }
9421
9422 // Compute the enclosing circle of the front chain.
9423 a = [b._], c = b;while ((c = c.next) !== b) {
9424 a.push(c._);
9425 }c = enclose(a);
9426
9427 // Translate the circles to put the enclosing circle around the origin.
9428 for (i = 0; i < n; ++i) {
9429 a = circles[i], a.x -= c.x, a.y -= c.y;
9430 }return c.r;
9431}
9432
9433var siblings = function (circles) {
9434 packEnclose(circles);
9435 return circles;
9436};
9437
9438function optional(f) {
9439 return f == null ? null : required(f);
9440}
9441
9442function required(f) {
9443 if (typeof f !== "function") throw new Error();
9444 return f;
9445}
9446
9447function constantZero() {
9448 return 0;
9449}
9450
9451var constant$6 = function (x) {
9452 return function () {
9453 return x;
9454 };
9455};
9456
9457function defaultRadius(d) {
9458 return Math.sqrt(d.value);
9459}
9460
9461var index = function () {
9462 var radius = null,
9463 dx = 1,
9464 dy = 1,
9465 padding = constantZero;
9466
9467 function pack(root) {
9468 root.x = dx / 2, root.y = dy / 2;
9469 if (radius) {
9470 root.eachBefore(radiusLeaf(radius)).eachAfter(packChildren(padding, 0.5)).eachBefore(translateChild(1));
9471 } else {
9472 root.eachBefore(radiusLeaf(defaultRadius)).eachAfter(packChildren(constantZero, 1)).eachAfter(packChildren(padding, root.r / Math.min(dx, dy))).eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
9473 }
9474 return root;
9475 }
9476
9477 pack.radius = function (x) {
9478 return arguments.length ? (radius = optional(x), pack) : radius;
9479 };
9480
9481 pack.size = function (x) {
9482 return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
9483 };
9484
9485 pack.padding = function (x) {
9486 return arguments.length ? (padding = typeof x === "function" ? x : constant$6(+x), pack) : padding;
9487 };
9488
9489 return pack;
9490};
9491
9492function radiusLeaf(radius) {
9493 return function (node) {
9494 if (!node.children) {
9495 node.r = Math.max(0, +radius(node) || 0);
9496 }
9497 };
9498}
9499
9500function packChildren(padding, k) {
9501 return function (node) {
9502 if (children = node.children) {
9503 var children,
9504 i,
9505 n = children.length,
9506 r = padding(node) * k || 0,
9507 e;
9508
9509 if (r) for (i = 0; i < n; ++i) {
9510 children[i].r += r;
9511 }e = packEnclose(children);
9512 if (r) for (i = 0; i < n; ++i) {
9513 children[i].r -= r;
9514 }node.r = e + r;
9515 }
9516 };
9517}
9518
9519function translateChild(k) {
9520 return function (node) {
9521 var parent = node.parent;
9522 node.r *= k;
9523 if (parent) {
9524 node.x = parent.x + k * node.x;
9525 node.y = parent.y + k * node.y;
9526 }
9527 };
9528}
9529
9530var roundNode = function (node) {
9531 node.x0 = Math.round(node.x0);
9532 node.y0 = Math.round(node.y0);
9533 node.x1 = Math.round(node.x1);
9534 node.y1 = Math.round(node.y1);
9535};
9536
9537var treemapDice = function (parent, x0, y0, x1, y1) {
9538 var nodes = parent.children,
9539 node,
9540 i = -1,
9541 n = nodes.length,
9542 k = parent.value && (x1 - x0) / parent.value;
9543
9544 while (++i < n) {
9545 node = nodes[i], node.y0 = y0, node.y1 = y1;
9546 node.x0 = x0, node.x1 = x0 += node.value * k;
9547 }
9548};
9549
9550var partition = function () {
9551 var dx = 1,
9552 dy = 1,
9553 padding = 0,
9554 round = false;
9555
9556 function partition(root) {
9557 var n = root.height + 1;
9558 root.x0 = root.y0 = padding;
9559 root.x1 = dx;
9560 root.y1 = dy / n;
9561 root.eachBefore(positionNode(dy, n));
9562 if (round) root.eachBefore(roundNode);
9563 return root;
9564 }
9565
9566 function positionNode(dy, n) {
9567 return function (node) {
9568 if (node.children) {
9569 treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
9570 }
9571 var x0 = node.x0,
9572 y0 = node.y0,
9573 x1 = node.x1 - padding,
9574 y1 = node.y1 - padding;
9575 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
9576 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
9577 node.x0 = x0;
9578 node.y0 = y0;
9579 node.x1 = x1;
9580 node.y1 = y1;
9581 };
9582 }
9583
9584 partition.round = function (x) {
9585 return arguments.length ? (round = !!x, partition) : round;
9586 };
9587
9588 partition.size = function (x) {
9589 return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
9590 };
9591
9592 partition.padding = function (x) {
9593 return arguments.length ? (padding = +x, partition) : padding;
9594 };
9595
9596 return partition;
9597};
9598
9599var keyPrefix$1 = "$";
9600var preroot = { depth: -1 };
9601var ambiguous = {};
9602
9603function defaultId(d) {
9604 return d.id;
9605}
9606
9607function defaultParentId(d) {
9608 return d.parentId;
9609}
9610
9611var stratify = function () {
9612 var id = defaultId,
9613 parentId = defaultParentId;
9614
9615 function stratify(data) {
9616 var d,
9617 i,
9618 n = data.length,
9619 root,
9620 parent,
9621 node,
9622 nodes = new Array(n),
9623 nodeId,
9624 nodeKey,
9625 nodeByKey = {};
9626
9627 for (i = 0; i < n; ++i) {
9628 d = data[i], node = nodes[i] = new Node(d);
9629 if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
9630 nodeKey = keyPrefix$1 + (node.id = nodeId);
9631 nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
9632 }
9633 }
9634
9635 for (i = 0; i < n; ++i) {
9636 node = nodes[i], nodeId = parentId(data[i], i, data);
9637 if (nodeId == null || !(nodeId += "")) {
9638 if (root) throw new Error("multiple roots");
9639 root = node;
9640 } else {
9641 parent = nodeByKey[keyPrefix$1 + nodeId];
9642 if (!parent) throw new Error("missing: " + nodeId);
9643 if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
9644 if (parent.children) parent.children.push(node);else parent.children = [node];
9645 node.parent = parent;
9646 }
9647 }
9648
9649 if (!root) throw new Error("no root");
9650 root.parent = preroot;
9651 root.eachBefore(function (node) {
9652 node.depth = node.parent.depth + 1;--n;
9653 }).eachBefore(computeHeight);
9654 root.parent = null;
9655 if (n > 0) throw new Error("cycle");
9656
9657 return root;
9658 }
9659
9660 stratify.id = function (x) {
9661 return arguments.length ? (id = required(x), stratify) : id;
9662 };
9663
9664 stratify.parentId = function (x) {
9665 return arguments.length ? (parentId = required(x), stratify) : parentId;
9666 };
9667
9668 return stratify;
9669};
9670
9671function defaultSeparation$1(a, b) {
9672 return a.parent === b.parent ? 1 : 2;
9673}
9674
9675// function radialSeparation(a, b) {
9676// return (a.parent === b.parent ? 1 : 2) / a.depth;
9677// }
9678
9679// This function is used to traverse the left contour of a subtree (or
9680// subforest). It returns the successor of v on this contour. This successor is
9681// either given by the leftmost child of v or by the thread of v. The function
9682// returns null if and only if v is on the highest level of its subtree.
9683function nextLeft(v) {
9684 var children = v.children;
9685 return children ? children[0] : v.t;
9686}
9687
9688// This function works analogously to nextLeft.
9689function nextRight(v) {
9690 var children = v.children;
9691 return children ? children[children.length - 1] : v.t;
9692}
9693
9694// Shifts the current subtree rooted at w+. This is done by increasing
9695// prelim(w+) and mod(w+) by shift.
9696function moveSubtree(wm, wp, shift) {
9697 var change = shift / (wp.i - wm.i);
9698 wp.c -= change;
9699 wp.s += shift;
9700 wm.c += change;
9701 wp.z += shift;
9702 wp.m += shift;
9703}
9704
9705// All other shifts, applied to the smaller subtrees between w- and w+, are
9706// performed by this function. To prepare the shifts, we have to adjust
9707// change(w+), shift(w+), and change(w-).
9708function executeShifts(v) {
9709 var shift = 0,
9710 change = 0,
9711 children = v.children,
9712 i = children.length,
9713 w;
9714 while (--i >= 0) {
9715 w = children[i];
9716 w.z += shift;
9717 w.m += shift;
9718 shift += w.s + (change += w.c);
9719 }
9720}
9721
9722// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
9723// returns the specified (default) ancestor.
9724function nextAncestor(vim, v, ancestor) {
9725 return vim.a.parent === v.parent ? vim.a : ancestor;
9726}
9727
9728function TreeNode(node, i) {
9729 this._ = node;
9730 this.parent = null;
9731 this.children = null;
9732 this.A = null; // default ancestor
9733 this.a = this; // ancestor
9734 this.z = 0; // prelim
9735 this.m = 0; // mod
9736 this.c = 0; // change
9737 this.s = 0; // shift
9738 this.t = null; // thread
9739 this.i = i; // number
9740}
9741
9742TreeNode.prototype = Object.create(Node.prototype);
9743
9744function treeRoot(root) {
9745 var tree = new TreeNode(root, 0),
9746 node,
9747 nodes = [tree],
9748 child,
9749 children,
9750 i,
9751 n;
9752
9753 while (node = nodes.pop()) {
9754 if (children = node._.children) {
9755 node.children = new Array(n = children.length);
9756 for (i = n - 1; i >= 0; --i) {
9757 nodes.push(child = node.children[i] = new TreeNode(children[i], i));
9758 child.parent = node;
9759 }
9760 }
9761 }
9762
9763 (tree.parent = new TreeNode(null, 0)).children = [tree];
9764 return tree;
9765}
9766
9767// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
9768var tree = function () {
9769 var separation = defaultSeparation$1,
9770 dx = 1,
9771 dy = 1,
9772 nodeSize = null;
9773
9774 function tree(root) {
9775 var t = treeRoot(root);
9776
9777 // Compute the layout using Buchheim et al.’s algorithm.
9778 t.eachAfter(firstWalk), t.parent.m = -t.z;
9779 t.eachBefore(secondWalk);
9780
9781 // If a fixed node size is specified, scale x and y.
9782 if (nodeSize) root.eachBefore(sizeNode);
9783
9784 // If a fixed tree size is specified, scale x and y based on the extent.
9785 // Compute the left-most, right-most, and depth-most nodes for extents.
9786 else {
9787 var left = root,
9788 right = root,
9789 bottom = root;
9790 root.eachBefore(function (node) {
9791 if (node.x < left.x) left = node;
9792 if (node.x > right.x) right = node;
9793 if (node.depth > bottom.depth) bottom = node;
9794 });
9795 var s = left === right ? 1 : separation(left, right) / 2,
9796 tx = s - left.x,
9797 kx = dx / (right.x + s + tx),
9798 ky = dy / (bottom.depth || 1);
9799 root.eachBefore(function (node) {
9800 node.x = (node.x + tx) * kx;
9801 node.y = node.depth * ky;
9802 });
9803 }
9804
9805 return root;
9806 }
9807
9808 // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
9809 // applied recursively to the children of v, as well as the function
9810 // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
9811 // node v is placed to the midpoint of its outermost children.
9812 function firstWalk(v) {
9813 var children = v.children,
9814 siblings = v.parent.children,
9815 w = v.i ? siblings[v.i - 1] : null;
9816 if (children) {
9817 executeShifts(v);
9818 var midpoint = (children[0].z + children[children.length - 1].z) / 2;
9819 if (w) {
9820 v.z = w.z + separation(v._, w._);
9821 v.m = v.z - midpoint;
9822 } else {
9823 v.z = midpoint;
9824 }
9825 } else if (w) {
9826 v.z = w.z + separation(v._, w._);
9827 }
9828 v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
9829 }
9830
9831 // Computes all real x-coordinates by summing up the modifiers recursively.
9832 function secondWalk(v) {
9833 v._.x = v.z + v.parent.m;
9834 v.m += v.parent.m;
9835 }
9836
9837 // The core of the algorithm. Here, a new subtree is combined with the
9838 // previous subtrees. Threads are used to traverse the inside and outside
9839 // contours of the left and right subtree up to the highest common level. The
9840 // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
9841 // superscript o means outside and i means inside, the subscript - means left
9842 // subtree and + means right subtree. For summing up the modifiers along the
9843 // contour, we use respective variables si+, si-, so-, and so+. Whenever two
9844 // nodes of the inside contours conflict, we compute the left one of the
9845 // greatest uncommon ancestors using the function ANCESTOR and call MOVE
9846 // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
9847 // Finally, we add a new thread (if necessary).
9848 function apportion(v, w, ancestor) {
9849 if (w) {
9850 var vip = v,
9851 vop = v,
9852 vim = w,
9853 vom = vip.parent.children[0],
9854 sip = vip.m,
9855 sop = vop.m,
9856 sim = vim.m,
9857 som = vom.m,
9858 shift;
9859 while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
9860 vom = nextLeft(vom);
9861 vop = nextRight(vop);
9862 vop.a = v;
9863 shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
9864 if (shift > 0) {
9865 moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
9866 sip += shift;
9867 sop += shift;
9868 }
9869 sim += vim.m;
9870 sip += vip.m;
9871 som += vom.m;
9872 sop += vop.m;
9873 }
9874 if (vim && !nextRight(vop)) {
9875 vop.t = vim;
9876 vop.m += sim - sop;
9877 }
9878 if (vip && !nextLeft(vom)) {
9879 vom.t = vip;
9880 vom.m += sip - som;
9881 ancestor = v;
9882 }
9883 }
9884 return ancestor;
9885 }
9886
9887 function sizeNode(node) {
9888 node.x *= dx;
9889 node.y = node.depth * dy;
9890 }
9891
9892 tree.separation = function (x) {
9893 return arguments.length ? (separation = x, tree) : separation;
9894 };
9895
9896 tree.size = function (x) {
9897 return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : nodeSize ? null : [dx, dy];
9898 };
9899
9900 tree.nodeSize = function (x) {
9901 return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : nodeSize ? [dx, dy] : null;
9902 };
9903
9904 return tree;
9905};
9906
9907var treemapSlice = function (parent, x0, y0, x1, y1) {
9908 var nodes = parent.children,
9909 node,
9910 i = -1,
9911 n = nodes.length,
9912 k = parent.value && (y1 - y0) / parent.value;
9913
9914 while (++i < n) {
9915 node = nodes[i], node.x0 = x0, node.x1 = x1;
9916 node.y0 = y0, node.y1 = y0 += node.value * k;
9917 }
9918};
9919
9920var phi = (1 + Math.sqrt(5)) / 2;
9921
9922function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
9923 var rows = [],
9924 nodes = parent.children,
9925 row,
9926 nodeValue,
9927 i0 = 0,
9928 i1 = 0,
9929 n = nodes.length,
9930 dx,
9931 dy,
9932 value = parent.value,
9933 sumValue,
9934 minValue,
9935 maxValue,
9936 newRatio,
9937 minRatio,
9938 alpha,
9939 beta;
9940
9941 while (i0 < n) {
9942 dx = x1 - x0, dy = y1 - y0;
9943
9944 // Find the next non-empty node.
9945 do {
9946 sumValue = nodes[i1++].value;
9947 } while (!sumValue && i1 < n);
9948 minValue = maxValue = sumValue;
9949 alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
9950 beta = sumValue * sumValue * alpha;
9951 minRatio = Math.max(maxValue / beta, beta / minValue);
9952
9953 // Keep adding nodes while the aspect ratio maintains or improves.
9954 for (; i1 < n; ++i1) {
9955 sumValue += nodeValue = nodes[i1].value;
9956 if (nodeValue < minValue) minValue = nodeValue;
9957 if (nodeValue > maxValue) maxValue = nodeValue;
9958 beta = sumValue * sumValue * alpha;
9959 newRatio = Math.max(maxValue / beta, beta / minValue);
9960 if (newRatio > minRatio) {
9961 sumValue -= nodeValue;break;
9962 }
9963 minRatio = newRatio;
9964 }
9965
9966 // Position and record the row orientation.
9967 rows.push(row = { value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1) });
9968 if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
9969 value -= sumValue, i0 = i1;
9970 }
9971
9972 return rows;
9973}
9974
9975var squarify = (function custom(ratio) {
9976
9977 function squarify(parent, x0, y0, x1, y1) {
9978 squarifyRatio(ratio, parent, x0, y0, x1, y1);
9979 }
9980
9981 squarify.ratio = function (x) {
9982 return custom((x = +x) > 1 ? x : 1);
9983 };
9984
9985 return squarify;
9986})(phi);
9987
9988var index$1 = function () {
9989 var tile = squarify,
9990 round = false,
9991 dx = 1,
9992 dy = 1,
9993 paddingStack = [0],
9994 paddingInner = constantZero,
9995 paddingTop = constantZero,
9996 paddingRight = constantZero,
9997 paddingBottom = constantZero,
9998 paddingLeft = constantZero;
9999
10000 function treemap(root) {
10001 root.x0 = root.y0 = 0;
10002 root.x1 = dx;
10003 root.y1 = dy;
10004 root.eachBefore(positionNode);
10005 paddingStack = [0];
10006 if (round) root.eachBefore(roundNode);
10007 return root;
10008 }
10009
10010 function positionNode(node) {
10011 var p = paddingStack[node.depth],
10012 x0 = node.x0 + p,
10013 y0 = node.y0 + p,
10014 x1 = node.x1 - p,
10015 y1 = node.y1 - p;
10016 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10017 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10018 node.x0 = x0;
10019 node.y0 = y0;
10020 node.x1 = x1;
10021 node.y1 = y1;
10022 if (node.children) {
10023 p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
10024 x0 += paddingLeft(node) - p;
10025 y0 += paddingTop(node) - p;
10026 x1 -= paddingRight(node) - p;
10027 y1 -= paddingBottom(node) - p;
10028 if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
10029 if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
10030 tile(node, x0, y0, x1, y1);
10031 }
10032 }
10033
10034 treemap.round = function (x) {
10035 return arguments.length ? (round = !!x, treemap) : round;
10036 };
10037
10038 treemap.size = function (x) {
10039 return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
10040 };
10041
10042 treemap.tile = function (x) {
10043 return arguments.length ? (tile = required(x), treemap) : tile;
10044 };
10045
10046 treemap.padding = function (x) {
10047 return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
10048 };
10049
10050 treemap.paddingInner = function (x) {
10051 return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$6(+x), treemap) : paddingInner;
10052 };
10053
10054 treemap.paddingOuter = function (x) {
10055 return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
10056 };
10057
10058 treemap.paddingTop = function (x) {
10059 return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$6(+x), treemap) : paddingTop;
10060 };
10061
10062 treemap.paddingRight = function (x) {
10063 return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$6(+x), treemap) : paddingRight;
10064 };
10065
10066 treemap.paddingBottom = function (x) {
10067 return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$6(+x), treemap) : paddingBottom;
10068 };
10069
10070 treemap.paddingLeft = function (x) {
10071 return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$6(+x), treemap) : paddingLeft;
10072 };
10073
10074 return treemap;
10075};
10076
10077var binary = function (parent, x0, y0, x1, y1) {
10078 var nodes = parent.children,
10079 i,
10080 n = nodes.length,
10081 sum,
10082 sums = new Array(n + 1);
10083
10084 for (sums[0] = sum = i = 0; i < n; ++i) {
10085 sums[i + 1] = sum += nodes[i].value;
10086 }
10087
10088 partition(0, n, parent.value, x0, y0, x1, y1);
10089
10090 function partition(i, j, value, x0, y0, x1, y1) {
10091 if (i >= j - 1) {
10092 var node = nodes[i];
10093 node.x0 = x0, node.y0 = y0;
10094 node.x1 = x1, node.y1 = y1;
10095 return;
10096 }
10097
10098 var valueOffset = sums[i],
10099 valueTarget = value / 2 + valueOffset,
10100 k = i + 1,
10101 hi = j - 1;
10102
10103 while (k < hi) {
10104 var mid = k + hi >>> 1;
10105 if (sums[mid] < valueTarget) k = mid + 1;else hi = mid;
10106 }
10107
10108 var valueLeft = sums[k] - valueOffset,
10109 valueRight = value - valueLeft;
10110
10111 if (y1 - y0 > x1 - x0) {
10112 var yk = (y0 * valueRight + y1 * valueLeft) / value;
10113 partition(i, k, valueLeft, x0, y0, x1, yk);
10114 partition(k, j, valueRight, x0, yk, x1, y1);
10115 } else {
10116 var xk = (x0 * valueRight + x1 * valueLeft) / value;
10117 partition(i, k, valueLeft, x0, y0, xk, y1);
10118 partition(k, j, valueRight, xk, y0, x1, y1);
10119 }
10120 }
10121};
10122
10123var sliceDice = function (parent, x0, y0, x1, y1) {
10124 (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
10125};
10126
10127var resquarify = (function custom(ratio) {
10128
10129 function resquarify(parent, x0, y0, x1, y1) {
10130 if ((rows = parent._squarify) && rows.ratio === ratio) {
10131 var rows,
10132 row,
10133 nodes,
10134 i,
10135 j = -1,
10136 n,
10137 m = rows.length,
10138 value = parent.value;
10139
10140 while (++j < m) {
10141 row = rows[j], nodes = row.children;
10142 for (i = row.value = 0, n = nodes.length; i < n; ++i) {
10143 row.value += nodes[i].value;
10144 }if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
10145 value -= row.value;
10146 }
10147 } else {
10148 parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
10149 rows.ratio = ratio;
10150 }
10151 }
10152
10153 resquarify.ratio = function (x) {
10154 return custom((x = +x) > 1 ? x : 1);
10155 };
10156
10157 return resquarify;
10158})(phi);
10159
10160function nopropagation() {
10161 exports.event.stopImmediatePropagation();
10162}
10163
10164var noevent = function () {
10165 exports.event.preventDefault();
10166 exports.event.stopImmediatePropagation();
10167};
10168
10169var dragDisable = function (view) {
10170 var root = view.document.documentElement,
10171 selection$$1 = select(view).on("dragstart.drag", noevent, true);
10172 if ("onselectstart" in root) {
10173 selection$$1.on("selectstart.drag", noevent, true);
10174 } else {
10175 root.__noselect = root.style.MozUserSelect;
10176 root.style.MozUserSelect = "none";
10177 }
10178};
10179
10180function yesdrag(view, noclick) {
10181 var root = view.document.documentElement,
10182 selection$$1 = select(view).on("dragstart.drag", null);
10183 if (noclick) {
10184 selection$$1.on("click.drag", noevent, true);
10185 setTimeout(function () {
10186 selection$$1.on("click.drag", null);
10187 }, 0);
10188 }
10189 if ("onselectstart" in root) {
10190 selection$$1.on("selectstart.drag", null);
10191 } else {
10192 root.style.MozUserSelect = root.__noselect;
10193 delete root.__noselect;
10194 }
10195}
10196
10197var constant$7 = function (x) {
10198 return function () {
10199 return x;
10200 };
10201};
10202
10203function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
10204 this.target = target;
10205 this.type = type;
10206 this.subject = subject;
10207 this.identifier = id;
10208 this.active = active;
10209 this.x = x;
10210 this.y = y;
10211 this.dx = dx;
10212 this.dy = dy;
10213 this._ = dispatch;
10214}
10215
10216DragEvent.prototype.on = function () {
10217 var value = this._.on.apply(this._, arguments);
10218 return value === this._ ? this : value;
10219};
10220
10221// Ignore right-click, since that should open the context menu.
10222function defaultFilter() {
10223 return !exports.event.button;
10224}
10225
10226function defaultContainer() {
10227 return this.parentNode;
10228}
10229
10230function defaultSubject(d) {
10231 return d == null ? { x: exports.event.x, y: exports.event.y } : d;
10232}
10233
10234var drag = function () {
10235 var filter = defaultFilter,
10236 container = defaultContainer,
10237 subject = defaultSubject,
10238 gestures = {},
10239 listeners = dispatch("start", "drag", "end"),
10240 active = 0,
10241 mousemoving,
10242 touchending;
10243
10244 function drag(selection$$1) {
10245 selection$$1.on("mousedown.drag", mousedowned).on("touchstart.drag", touchstarted).on("touchmove.drag", touchmoved).on("touchend.drag touchcancel.drag", touchended).style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
10246 }
10247
10248 function mousedowned() {
10249 if (touchending || !filter.apply(this, arguments)) return;
10250 var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
10251 if (!gesture) return;
10252 select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
10253 dragDisable(exports.event.view);
10254 nopropagation();
10255 mousemoving = false;
10256 gesture("start");
10257 }
10258
10259 function mousemoved() {
10260 noevent();
10261 mousemoving = true;
10262 gestures.mouse("drag");
10263 }
10264
10265 function mouseupped() {
10266 select(exports.event.view).on("mousemove.drag mouseup.drag", null);
10267 yesdrag(exports.event.view, mousemoving);
10268 noevent();
10269 gestures.mouse("end");
10270 }
10271
10272 function touchstarted() {
10273 if (!filter.apply(this, arguments)) return;
10274 var touches$$1 = exports.event.changedTouches,
10275 c = container.apply(this, arguments),
10276 n = touches$$1.length,
10277 i,
10278 gesture;
10279
10280 for (i = 0; i < n; ++i) {
10281 if (gesture = beforestart(touches$$1[i].identifier, c, touch, this, arguments)) {
10282 nopropagation();
10283 gesture("start");
10284 }
10285 }
10286 }
10287
10288 function touchmoved() {
10289 var touches$$1 = exports.event.changedTouches,
10290 n = touches$$1.length,
10291 i,
10292 gesture;
10293
10294 for (i = 0; i < n; ++i) {
10295 if (gesture = gestures[touches$$1[i].identifier]) {
10296 noevent();
10297 gesture("drag");
10298 }
10299 }
10300 }
10301
10302 function touchended() {
10303 var touches$$1 = exports.event.changedTouches,
10304 n = touches$$1.length,
10305 i,
10306 gesture;
10307
10308 if (touchending) clearTimeout(touchending);
10309 touchending = setTimeout(function () {
10310 touchending = null;
10311 }, 500); // Ghost clicks are delayed!
10312 for (i = 0; i < n; ++i) {
10313 if (gesture = gestures[touches$$1[i].identifier]) {
10314 nopropagation();
10315 gesture("end");
10316 }
10317 }
10318 }
10319
10320 function beforestart(id, container, point, that, args) {
10321 var p = point(container, id),
10322 s,
10323 dx,
10324 dy,
10325 sublisteners = listeners.copy();
10326
10327 if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function () {
10328 if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
10329 dx = s.x - p[0] || 0;
10330 dy = s.y - p[1] || 0;
10331 return true;
10332 })) return;
10333
10334 return function gesture(type) {
10335 var p0 = p,
10336 n;
10337 switch (type) {
10338 case "start":
10339 gestures[id] = gesture, n = active++;break;
10340 case "end":
10341 delete gestures[id], --active; // nobreak
10342 case "drag":
10343 p = point(container, id), n = active;break;
10344 }
10345 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]);
10346 };
10347 }
10348
10349 drag.filter = function (_) {
10350 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), drag) : filter;
10351 };
10352
10353 drag.container = function (_) {
10354 return arguments.length ? (container = typeof _ === "function" ? _ : constant$7(_), drag) : container;
10355 };
10356
10357 drag.subject = function (_) {
10358 return arguments.length ? (subject = typeof _ === "function" ? _ : constant$7(_), drag) : subject;
10359 };
10360
10361 drag.on = function () {
10362 var value = listeners.on.apply(listeners, arguments);
10363 return value === listeners ? drag : value;
10364 };
10365
10366 return drag;
10367};
10368
10369var constant$8 = function (x) {
10370 return function () {
10371 return x;
10372 };
10373};
10374
10375function x$2(d) {
10376 return d[0];
10377}
10378
10379function y$1(d) {
10380 return d[1];
10381}
10382
10383function RedBlackTree() {
10384 this._ = null; // root node
10385}
10386
10387function RedBlackNode(node) {
10388 node.U = // parent node
10389 node.C = // color - true for red, false for black
10390 node.L = // left node
10391 node.R = // right node
10392 node.P = // previous node
10393 node.N = null; // next node
10394}
10395
10396RedBlackTree.prototype = {
10397 constructor: RedBlackTree,
10398
10399 insert: function insert(after, node) {
10400 var parent, grandpa, uncle;
10401
10402 if (after) {
10403 node.P = after;
10404 node.N = after.N;
10405 if (after.N) after.N.P = node;
10406 after.N = node;
10407 if (after.R) {
10408 after = after.R;
10409 while (after.L) {
10410 after = after.L;
10411 }after.L = node;
10412 } else {
10413 after.R = node;
10414 }
10415 parent = after;
10416 } else if (this._) {
10417 after = RedBlackFirst(this._);
10418 node.P = null;
10419 node.N = after;
10420 after.P = after.L = node;
10421 parent = after;
10422 } else {
10423 node.P = node.N = null;
10424 this._ = node;
10425 parent = null;
10426 }
10427 node.L = node.R = null;
10428 node.U = parent;
10429 node.C = true;
10430
10431 after = node;
10432 while (parent && parent.C) {
10433 grandpa = parent.U;
10434 if (parent === grandpa.L) {
10435 uncle = grandpa.R;
10436 if (uncle && uncle.C) {
10437 parent.C = uncle.C = false;
10438 grandpa.C = true;
10439 after = grandpa;
10440 } else {
10441 if (after === parent.R) {
10442 RedBlackRotateLeft(this, parent);
10443 after = parent;
10444 parent = after.U;
10445 }
10446 parent.C = false;
10447 grandpa.C = true;
10448 RedBlackRotateRight(this, grandpa);
10449 }
10450 } else {
10451 uncle = grandpa.L;
10452 if (uncle && uncle.C) {
10453 parent.C = uncle.C = false;
10454 grandpa.C = true;
10455 after = grandpa;
10456 } else {
10457 if (after === parent.L) {
10458 RedBlackRotateRight(this, parent);
10459 after = parent;
10460 parent = after.U;
10461 }
10462 parent.C = false;
10463 grandpa.C = true;
10464 RedBlackRotateLeft(this, grandpa);
10465 }
10466 }
10467 parent = after.U;
10468 }
10469 this._.C = false;
10470 },
10471
10472 remove: function remove(node) {
10473 if (node.N) node.N.P = node.P;
10474 if (node.P) node.P.N = node.N;
10475 node.N = node.P = null;
10476
10477 var parent = node.U,
10478 sibling,
10479 left = node.L,
10480 right = node.R,
10481 next,
10482 red;
10483
10484 if (!left) next = right;else if (!right) next = left;else next = RedBlackFirst(right);
10485
10486 if (parent) {
10487 if (parent.L === node) parent.L = next;else parent.R = next;
10488 } else {
10489 this._ = next;
10490 }
10491
10492 if (left && right) {
10493 red = next.C;
10494 next.C = node.C;
10495 next.L = left;
10496 left.U = next;
10497 if (next !== right) {
10498 parent = next.U;
10499 next.U = node.U;
10500 node = next.R;
10501 parent.L = node;
10502 next.R = right;
10503 right.U = next;
10504 } else {
10505 next.U = parent;
10506 parent = next;
10507 node = next.R;
10508 }
10509 } else {
10510 red = node.C;
10511 node = next;
10512 }
10513
10514 if (node) node.U = parent;
10515 if (red) return;
10516 if (node && node.C) {
10517 node.C = false;return;
10518 }
10519
10520 do {
10521 if (node === this._) break;
10522 if (node === parent.L) {
10523 sibling = parent.R;
10524 if (sibling.C) {
10525 sibling.C = false;
10526 parent.C = true;
10527 RedBlackRotateLeft(this, parent);
10528 sibling = parent.R;
10529 }
10530 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
10531 if (!sibling.R || !sibling.R.C) {
10532 sibling.L.C = false;
10533 sibling.C = true;
10534 RedBlackRotateRight(this, sibling);
10535 sibling = parent.R;
10536 }
10537 sibling.C = parent.C;
10538 parent.C = sibling.R.C = false;
10539 RedBlackRotateLeft(this, parent);
10540 node = this._;
10541 break;
10542 }
10543 } else {
10544 sibling = parent.L;
10545 if (sibling.C) {
10546 sibling.C = false;
10547 parent.C = true;
10548 RedBlackRotateRight(this, parent);
10549 sibling = parent.L;
10550 }
10551 if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
10552 if (!sibling.L || !sibling.L.C) {
10553 sibling.R.C = false;
10554 sibling.C = true;
10555 RedBlackRotateLeft(this, sibling);
10556 sibling = parent.L;
10557 }
10558 sibling.C = parent.C;
10559 parent.C = sibling.L.C = false;
10560 RedBlackRotateRight(this, parent);
10561 node = this._;
10562 break;
10563 }
10564 }
10565 sibling.C = true;
10566 node = parent;
10567 parent = parent.U;
10568 } while (!node.C);
10569
10570 if (node) node.C = false;
10571 }
10572};
10573
10574function RedBlackRotateLeft(tree, node) {
10575 var p = node,
10576 q = node.R,
10577 parent = p.U;
10578
10579 if (parent) {
10580 if (parent.L === p) parent.L = q;else parent.R = q;
10581 } else {
10582 tree._ = q;
10583 }
10584
10585 q.U = parent;
10586 p.U = q;
10587 p.R = q.L;
10588 if (p.R) p.R.U = p;
10589 q.L = p;
10590}
10591
10592function RedBlackRotateRight(tree, node) {
10593 var p = node,
10594 q = node.L,
10595 parent = p.U;
10596
10597 if (parent) {
10598 if (parent.L === p) parent.L = q;else parent.R = q;
10599 } else {
10600 tree._ = q;
10601 }
10602
10603 q.U = parent;
10604 p.U = q;
10605 p.L = q.R;
10606 if (p.L) p.L.U = p;
10607 q.R = p;
10608}
10609
10610function RedBlackFirst(node) {
10611 while (node.L) {
10612 node = node.L;
10613 }return node;
10614}
10615
10616function createEdge(left, right, v0, v1) {
10617 var edge = [null, null],
10618 index = edges.push(edge) - 1;
10619 edge.left = left;
10620 edge.right = right;
10621 if (v0) setEdgeEnd(edge, left, right, v0);
10622 if (v1) setEdgeEnd(edge, right, left, v1);
10623 cells[left.index].halfedges.push(index);
10624 cells[right.index].halfedges.push(index);
10625 return edge;
10626}
10627
10628function createBorderEdge(left, v0, v1) {
10629 var edge = [v0, v1];
10630 edge.left = left;
10631 return edge;
10632}
10633
10634function setEdgeEnd(edge, left, right, vertex) {
10635 if (!edge[0] && !edge[1]) {
10636 edge[0] = vertex;
10637 edge.left = left;
10638 edge.right = right;
10639 } else if (edge.left === right) {
10640 edge[1] = vertex;
10641 } else {
10642 edge[0] = vertex;
10643 }
10644}
10645
10646// Liang–Barsky line clipping.
10647function clipEdge(edge, x0, y0, x1, y1) {
10648 var a = edge[0],
10649 b = edge[1],
10650 ax = a[0],
10651 ay = a[1],
10652 bx = b[0],
10653 by = b[1],
10654 t0 = 0,
10655 t1 = 1,
10656 dx = bx - ax,
10657 dy = by - ay,
10658 r;
10659
10660 r = x0 - ax;
10661 if (!dx && r > 0) return;
10662 r /= dx;
10663 if (dx < 0) {
10664 if (r < t0) return;
10665 if (r < t1) t1 = r;
10666 } else if (dx > 0) {
10667 if (r > t1) return;
10668 if (r > t0) t0 = r;
10669 }
10670
10671 r = x1 - ax;
10672 if (!dx && r < 0) return;
10673 r /= dx;
10674 if (dx < 0) {
10675 if (r > t1) return;
10676 if (r > t0) t0 = r;
10677 } else if (dx > 0) {
10678 if (r < t0) return;
10679 if (r < t1) t1 = r;
10680 }
10681
10682 r = y0 - ay;
10683 if (!dy && r > 0) return;
10684 r /= dy;
10685 if (dy < 0) {
10686 if (r < t0) return;
10687 if (r < t1) t1 = r;
10688 } else if (dy > 0) {
10689 if (r > t1) return;
10690 if (r > t0) t0 = r;
10691 }
10692
10693 r = y1 - ay;
10694 if (!dy && r < 0) return;
10695 r /= dy;
10696 if (dy < 0) {
10697 if (r > t1) return;
10698 if (r > t0) t0 = r;
10699 } else if (dy > 0) {
10700 if (r < t0) return;
10701 if (r < t1) t1 = r;
10702 }
10703
10704 if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
10705
10706 if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
10707 if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
10708 return true;
10709}
10710
10711function connectEdge(edge, x0, y0, x1, y1) {
10712 var v1 = edge[1];
10713 if (v1) return true;
10714
10715 var v0 = edge[0],
10716 left = edge.left,
10717 right = edge.right,
10718 lx = left[0],
10719 ly = left[1],
10720 rx = right[0],
10721 ry = right[1],
10722 fx = (lx + rx) / 2,
10723 fy = (ly + ry) / 2,
10724 fm,
10725 fb;
10726
10727 if (ry === ly) {
10728 if (fx < x0 || fx >= x1) return;
10729 if (lx > rx) {
10730 if (!v0) v0 = [fx, y0];else if (v0[1] >= y1) return;
10731 v1 = [fx, y1];
10732 } else {
10733 if (!v0) v0 = [fx, y1];else if (v0[1] < y0) return;
10734 v1 = [fx, y0];
10735 }
10736 } else {
10737 fm = (lx - rx) / (ry - ly);
10738 fb = fy - fm * fx;
10739 if (fm < -1 || fm > 1) {
10740 if (lx > rx) {
10741 if (!v0) v0 = [(y0 - fb) / fm, y0];else if (v0[1] >= y1) return;
10742 v1 = [(y1 - fb) / fm, y1];
10743 } else {
10744 if (!v0) v0 = [(y1 - fb) / fm, y1];else if (v0[1] < y0) return;
10745 v1 = [(y0 - fb) / fm, y0];
10746 }
10747 } else {
10748 if (ly < ry) {
10749 if (!v0) v0 = [x0, fm * x0 + fb];else if (v0[0] >= x1) return;
10750 v1 = [x1, fm * x1 + fb];
10751 } else {
10752 if (!v0) v0 = [x1, fm * x1 + fb];else if (v0[0] < x0) return;
10753 v1 = [x0, fm * x0 + fb];
10754 }
10755 }
10756 }
10757
10758 edge[0] = v0;
10759 edge[1] = v1;
10760 return true;
10761}
10762
10763function clipEdges(x0, y0, x1, y1) {
10764 var i = edges.length,
10765 edge;
10766
10767 while (i--) {
10768 if (!connectEdge(edge = edges[i], x0, y0, x1, y1) || !clipEdge(edge, x0, y0, x1, y1) || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$3 || Math.abs(edge[0][1] - edge[1][1]) > epsilon$3)) {
10769 delete edges[i];
10770 }
10771 }
10772}
10773
10774function createCell(site) {
10775 return cells[site.index] = {
10776 site: site,
10777 halfedges: []
10778 };
10779}
10780
10781function cellHalfedgeAngle(cell, edge) {
10782 var site = cell.site,
10783 va = edge.left,
10784 vb = edge.right;
10785 if (site === vb) vb = va, va = site;
10786 if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
10787 if (site === va) va = edge[1], vb = edge[0];else va = edge[0], vb = edge[1];
10788 return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
10789}
10790
10791function cellHalfedgeStart(cell, edge) {
10792 return edge[+(edge.left !== cell.site)];
10793}
10794
10795function cellHalfedgeEnd(cell, edge) {
10796 return edge[+(edge.left === cell.site)];
10797}
10798
10799function sortCellHalfedges() {
10800 for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
10801 if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
10802 var index = new Array(m),
10803 array = new Array(m);
10804 for (j = 0; j < m; ++j) {
10805 index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
10806 }index.sort(function (i, j) {
10807 return array[j] - array[i];
10808 });
10809 for (j = 0; j < m; ++j) {
10810 array[j] = halfedges[index[j]];
10811 }for (j = 0; j < m; ++j) {
10812 halfedges[j] = array[j];
10813 }
10814 }
10815 }
10816}
10817
10818function clipCells(x0, y0, x1, y1) {
10819 var nCells = cells.length,
10820 iCell,
10821 cell,
10822 site,
10823 iHalfedge,
10824 halfedges,
10825 nHalfedges,
10826 start,
10827 startX,
10828 startY,
10829 end,
10830 endX,
10831 endY,
10832 cover = true;
10833
10834 for (iCell = 0; iCell < nCells; ++iCell) {
10835 if (cell = cells[iCell]) {
10836 site = cell.site;
10837 halfedges = cell.halfedges;
10838 iHalfedge = halfedges.length;
10839
10840 // Remove any dangling clipped edges.
10841 while (iHalfedge--) {
10842 if (!edges[halfedges[iHalfedge]]) {
10843 halfedges.splice(iHalfedge, 1);
10844 }
10845 }
10846
10847 // Insert any border edges as necessary.
10848 iHalfedge = 0, nHalfedges = halfedges.length;
10849 while (iHalfedge < nHalfedges) {
10850 end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
10851 start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
10852 if (Math.abs(endX - startX) > epsilon$3 || Math.abs(endY - startY) > epsilon$3) {
10853 halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end, Math.abs(endX - x0) < epsilon$3 && y1 - endY > epsilon$3 ? [x0, Math.abs(startX - x0) < epsilon$3 ? startY : y1] : Math.abs(endY - y1) < epsilon$3 && x1 - endX > epsilon$3 ? [Math.abs(startY - y1) < epsilon$3 ? startX : x1, y1] : Math.abs(endX - x1) < epsilon$3 && endY - y0 > epsilon$3 ? [x1, Math.abs(startX - x1) < epsilon$3 ? startY : y0] : Math.abs(endY - y0) < epsilon$3 && endX - x0 > epsilon$3 ? [Math.abs(startY - y0) < epsilon$3 ? startX : x0, y0] : null)) - 1);
10854 ++nHalfedges;
10855 }
10856 }
10857
10858 if (nHalfedges) cover = false;
10859 }
10860 }
10861
10862 // If there weren’t any edges, have the closest site cover the extent.
10863 // It doesn’t matter which corner of the extent we measure!
10864 if (cover) {
10865 var dx,
10866 dy,
10867 d2,
10868 dc = Infinity;
10869
10870 for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
10871 if (cell = cells[iCell]) {
10872 site = cell.site;
10873 dx = site[0] - x0;
10874 dy = site[1] - y0;
10875 d2 = dx * dx + dy * dy;
10876 if (d2 < dc) dc = d2, cover = cell;
10877 }
10878 }
10879
10880 if (cover) {
10881 var v00 = [x0, y0],
10882 v01 = [x0, y1],
10883 v11 = [x1, y1],
10884 v10 = [x1, y0];
10885 cover.halfedges.push(edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1, edges.push(createBorderEdge(site, v01, v11)) - 1, edges.push(createBorderEdge(site, v11, v10)) - 1, edges.push(createBorderEdge(site, v10, v00)) - 1);
10886 }
10887 }
10888
10889 // Lastly delete any cells with no edges; these were entirely clipped.
10890 for (iCell = 0; iCell < nCells; ++iCell) {
10891 if (cell = cells[iCell]) {
10892 if (!cell.halfedges.length) {
10893 delete cells[iCell];
10894 }
10895 }
10896 }
10897}
10898
10899var circlePool = [];
10900
10901var firstCircle;
10902
10903function Circle() {
10904 RedBlackNode(this);
10905 this.x = this.y = this.arc = this.site = this.cy = null;
10906}
10907
10908function attachCircle(arc) {
10909 var lArc = arc.P,
10910 rArc = arc.N;
10911
10912 if (!lArc || !rArc) return;
10913
10914 var lSite = lArc.site,
10915 cSite = arc.site,
10916 rSite = rArc.site;
10917
10918 if (lSite === rSite) return;
10919
10920 var bx = cSite[0],
10921 by = cSite[1],
10922 ax = lSite[0] - bx,
10923 ay = lSite[1] - by,
10924 cx = rSite[0] - bx,
10925 cy = rSite[1] - by;
10926
10927 var d = 2 * (ax * cy - ay * cx);
10928 if (d >= -epsilon2$1) return;
10929
10930 var ha = ax * ax + ay * ay,
10931 hc = cx * cx + cy * cy,
10932 x = (cy * ha - ay * hc) / d,
10933 y = (ax * hc - cx * ha) / d;
10934
10935 var circle = circlePool.pop() || new Circle();
10936 circle.arc = arc;
10937 circle.site = cSite;
10938 circle.x = x + bx;
10939 circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
10940
10941 arc.circle = circle;
10942
10943 var before = null,
10944 node = circles._;
10945
10946 while (node) {
10947 if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
10948 if (node.L) node = node.L;else {
10949 before = node.P;break;
10950 }
10951 } else {
10952 if (node.R) node = node.R;else {
10953 before = node;break;
10954 }
10955 }
10956 }
10957
10958 circles.insert(before, circle);
10959 if (!before) firstCircle = circle;
10960}
10961
10962function detachCircle(arc) {
10963 var circle = arc.circle;
10964 if (circle) {
10965 if (!circle.P) firstCircle = circle.N;
10966 circles.remove(circle);
10967 circlePool.push(circle);
10968 RedBlackNode(circle);
10969 arc.circle = null;
10970 }
10971}
10972
10973var beachPool = [];
10974
10975function Beach() {
10976 RedBlackNode(this);
10977 this.edge = this.site = this.circle = null;
10978}
10979
10980function createBeach(site) {
10981 var beach = beachPool.pop() || new Beach();
10982 beach.site = site;
10983 return beach;
10984}
10985
10986function detachBeach(beach) {
10987 detachCircle(beach);
10988 beaches.remove(beach);
10989 beachPool.push(beach);
10990 RedBlackNode(beach);
10991}
10992
10993function removeBeach(beach) {
10994 var circle = beach.circle,
10995 x = circle.x,
10996 y = circle.cy,
10997 vertex = [x, y],
10998 previous = beach.P,
10999 next = beach.N,
11000 disappearing = [beach];
11001
11002 detachBeach(beach);
11003
11004 var lArc = previous;
11005 while (lArc.circle && Math.abs(x - lArc.circle.x) < epsilon$3 && Math.abs(y - lArc.circle.cy) < epsilon$3) {
11006 previous = lArc.P;
11007 disappearing.unshift(lArc);
11008 detachBeach(lArc);
11009 lArc = previous;
11010 }
11011
11012 disappearing.unshift(lArc);
11013 detachCircle(lArc);
11014
11015 var rArc = next;
11016 while (rArc.circle && Math.abs(x - rArc.circle.x) < epsilon$3 && Math.abs(y - rArc.circle.cy) < epsilon$3) {
11017 next = rArc.N;
11018 disappearing.push(rArc);
11019 detachBeach(rArc);
11020 rArc = next;
11021 }
11022
11023 disappearing.push(rArc);
11024 detachCircle(rArc);
11025
11026 var nArcs = disappearing.length,
11027 iArc;
11028 for (iArc = 1; iArc < nArcs; ++iArc) {
11029 rArc = disappearing[iArc];
11030 lArc = disappearing[iArc - 1];
11031 setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
11032 }
11033
11034 lArc = disappearing[0];
11035 rArc = disappearing[nArcs - 1];
11036 rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
11037
11038 attachCircle(lArc);
11039 attachCircle(rArc);
11040}
11041
11042function addBeach(site) {
11043 var x = site[0],
11044 directrix = site[1],
11045 lArc,
11046 rArc,
11047 dxl,
11048 dxr,
11049 node = beaches._;
11050
11051 while (node) {
11052 dxl = leftBreakPoint(node, directrix) - x;
11053 if (dxl > epsilon$3) node = node.L;else {
11054 dxr = x - rightBreakPoint(node, directrix);
11055 if (dxr > epsilon$3) {
11056 if (!node.R) {
11057 lArc = node;
11058 break;
11059 }
11060 node = node.R;
11061 } else {
11062 if (dxl > -epsilon$3) {
11063 lArc = node.P;
11064 rArc = node;
11065 } else if (dxr > -epsilon$3) {
11066 lArc = node;
11067 rArc = node.N;
11068 } else {
11069 lArc = rArc = node;
11070 }
11071 break;
11072 }
11073 }
11074 }
11075
11076 createCell(site);
11077 var newArc = createBeach(site);
11078 beaches.insert(lArc, newArc);
11079
11080 if (!lArc && !rArc) return;
11081
11082 if (lArc === rArc) {
11083 detachCircle(lArc);
11084 rArc = createBeach(lArc.site);
11085 beaches.insert(newArc, rArc);
11086 newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
11087 attachCircle(lArc);
11088 attachCircle(rArc);
11089 return;
11090 }
11091
11092 if (!rArc) {
11093 // && lArc
11094 newArc.edge = createEdge(lArc.site, newArc.site);
11095 return;
11096 }
11097
11098 // else lArc !== rArc
11099 detachCircle(lArc);
11100 detachCircle(rArc);
11101
11102 var lSite = lArc.site,
11103 ax = lSite[0],
11104 ay = lSite[1],
11105 bx = site[0] - ax,
11106 by = site[1] - ay,
11107 rSite = rArc.site,
11108 cx = rSite[0] - ax,
11109 cy = rSite[1] - ay,
11110 d = 2 * (bx * cy - by * cx),
11111 hb = bx * bx + by * by,
11112 hc = cx * cx + cy * cy,
11113 vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
11114
11115 setEdgeEnd(rArc.edge, lSite, rSite, vertex);
11116 newArc.edge = createEdge(lSite, site, null, vertex);
11117 rArc.edge = createEdge(site, rSite, null, vertex);
11118 attachCircle(lArc);
11119 attachCircle(rArc);
11120}
11121
11122function leftBreakPoint(arc, directrix) {
11123 var site = arc.site,
11124 rfocx = site[0],
11125 rfocy = site[1],
11126 pby2 = rfocy - directrix;
11127
11128 if (!pby2) return rfocx;
11129
11130 var lArc = arc.P;
11131 if (!lArc) return -Infinity;
11132
11133 site = lArc.site;
11134 var lfocx = site[0],
11135 lfocy = site[1],
11136 plby2 = lfocy - directrix;
11137
11138 if (!plby2) return lfocx;
11139
11140 var hl = lfocx - rfocx,
11141 aby2 = 1 / pby2 - 1 / plby2,
11142 b = hl / plby2;
11143
11144 if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
11145
11146 return (rfocx + lfocx) / 2;
11147}
11148
11149function rightBreakPoint(arc, directrix) {
11150 var rArc = arc.N;
11151 if (rArc) return leftBreakPoint(rArc, directrix);
11152 var site = arc.site;
11153 return site[1] === directrix ? site[0] : Infinity;
11154}
11155
11156var epsilon$3 = 1e-6;
11157var epsilon2$1 = 1e-12;
11158var beaches;
11159var cells;
11160var circles;
11161var edges;
11162
11163function triangleArea(a, b, c) {
11164 return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
11165}
11166
11167function lexicographic(a, b) {
11168 return b[1] - a[1] || b[0] - a[0];
11169}
11170
11171function Diagram(sites, extent) {
11172 var site = sites.sort(lexicographic).pop(),
11173 x,
11174 y,
11175 circle;
11176
11177 edges = [];
11178 cells = new Array(sites.length);
11179 beaches = new RedBlackTree();
11180 circles = new RedBlackTree();
11181
11182 while (true) {
11183 circle = firstCircle;
11184 if (site && (!circle || site[1] < circle.y || site[1] === circle.y && site[0] < circle.x)) {
11185 if (site[0] !== x || site[1] !== y) {
11186 addBeach(site);
11187 x = site[0], y = site[1];
11188 }
11189 site = sites.pop();
11190 } else if (circle) {
11191 removeBeach(circle.arc);
11192 } else {
11193 break;
11194 }
11195 }
11196
11197 sortCellHalfedges();
11198
11199 if (extent) {
11200 var x0 = +extent[0][0],
11201 y0 = +extent[0][1],
11202 x1 = +extent[1][0],
11203 y1 = +extent[1][1];
11204 clipEdges(x0, y0, x1, y1);
11205 clipCells(x0, y0, x1, y1);
11206 }
11207
11208 this.edges = edges;
11209 this.cells = cells;
11210
11211 beaches = circles = edges = cells = null;
11212}
11213
11214Diagram.prototype = {
11215 constructor: Diagram,
11216
11217 polygons: function polygons() {
11218 var edges = this.edges;
11219
11220 return this.cells.map(function (cell) {
11221 var polygon = cell.halfedges.map(function (i) {
11222 return cellHalfedgeStart(cell, edges[i]);
11223 });
11224 polygon.data = cell.site.data;
11225 return polygon;
11226 });
11227 },
11228
11229 triangles: function triangles() {
11230 var triangles = [],
11231 edges = this.edges;
11232
11233 this.cells.forEach(function (cell, i) {
11234 var site = cell.site,
11235 halfedges = cell.halfedges,
11236 j = -1,
11237 m = halfedges.length,
11238 s0,
11239 e1 = edges[halfedges[m - 1]],
11240 s1 = e1.left === site ? e1.right : e1.left;
11241
11242 while (++j < m) {
11243 s0 = s1;
11244 e1 = edges[halfedges[j]];
11245 s1 = e1.left === site ? e1.right : e1.left;
11246 if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
11247 triangles.push([site.data, s0.data, s1.data]);
11248 }
11249 }
11250 });
11251
11252 return triangles;
11253 },
11254
11255 links: function links() {
11256 return this.edges.filter(function (edge) {
11257 return edge.right;
11258 }).map(function (edge) {
11259 return {
11260 source: edge.left.data,
11261 target: edge.right.data
11262 };
11263 });
11264 },
11265
11266 find: function find(x, y, radius) {
11267 var that = this,
11268 i0,
11269 i1 = that._found || 0,
11270 cell = that.cells[i1] || that.cells[i1 = 0],
11271 dx = x - cell.site[0],
11272 dy = y - cell.site[1],
11273 d2 = dx * dx + dy * dy;
11274
11275 do {
11276 cell = that.cells[i0 = i1], i1 = null;
11277 cell.halfedges.forEach(function (e) {
11278 var edge = that.edges[e],
11279 v = edge.left;
11280 if ((v === cell.site || !v) && !(v = edge.right)) return;
11281 var vx = x - v[0],
11282 vy = y - v[1],
11283 v2 = vx * vx + vy * vy;
11284 if (v2 < d2) d2 = v2, i1 = v.index;
11285 });
11286 } while (i1 !== null);
11287
11288 that._found = i0;
11289
11290 return radius == null || d2 <= radius * radius ? cell.site : null;
11291 }
11292};
11293
11294var voronoi = function () {
11295 var x$$1 = x$2,
11296 y$$1 = y$1,
11297 extent = null;
11298
11299 function voronoi(data) {
11300 return new Diagram(data.map(function (d, i) {
11301 var s = [Math.round(x$$1(d, i, data) / epsilon$3) * epsilon$3, Math.round(y$$1(d, i, data) / epsilon$3) * epsilon$3];
11302 s.index = i;
11303 s.data = d;
11304 return s;
11305 }), extent);
11306 }
11307
11308 voronoi.polygons = function (data) {
11309 return voronoi(data).polygons();
11310 };
11311
11312 voronoi.links = function (data) {
11313 return voronoi(data).links();
11314 };
11315
11316 voronoi.triangles = function (data) {
11317 return voronoi(data).triangles();
11318 };
11319
11320 voronoi.x = function (_) {
11321 return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant$8(+_), voronoi) : x$$1;
11322 };
11323
11324 voronoi.y = function (_) {
11325 return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant$8(+_), voronoi) : y$$1;
11326 };
11327
11328 voronoi.extent = function (_) {
11329 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]]];
11330 };
11331
11332 voronoi.size = function (_) {
11333 return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
11334 };
11335
11336 return voronoi;
11337};
11338
11339var constant$9 = function (x) {
11340 return function () {
11341 return x;
11342 };
11343};
11344
11345function ZoomEvent(target, type, transform) {
11346 this.target = target;
11347 this.type = type;
11348 this.transform = transform;
11349}
11350
11351function Transform(k, x, y) {
11352 this.k = k;
11353 this.x = x;
11354 this.y = y;
11355}
11356
11357Transform.prototype = {
11358 constructor: Transform,
11359 scale: function scale(k) {
11360 return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
11361 },
11362 translate: function translate(x, y) {
11363 return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
11364 },
11365 apply: function apply(point) {
11366 return [point[0] * this.k + this.x, point[1] * this.k + this.y];
11367 },
11368 applyX: function applyX(x) {
11369 return x * this.k + this.x;
11370 },
11371 applyY: function applyY(y) {
11372 return y * this.k + this.y;
11373 },
11374 invert: function invert(location) {
11375 return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
11376 },
11377 invertX: function invertX(x) {
11378 return (x - this.x) / this.k;
11379 },
11380 invertY: function invertY(y) {
11381 return (y - this.y) / this.k;
11382 },
11383 rescaleX: function rescaleX(x) {
11384 return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
11385 },
11386 rescaleY: function rescaleY(y) {
11387 return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
11388 },
11389 toString: function toString() {
11390 return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
11391 }
11392};
11393
11394var identity$6 = new Transform(1, 0, 0);
11395
11396transform.prototype = Transform.prototype;
11397
11398function transform(node) {
11399 return node.__zoom || identity$6;
11400}
11401
11402function nopropagation$1() {
11403 exports.event.stopImmediatePropagation();
11404}
11405
11406var noevent$1 = function () {
11407 exports.event.preventDefault();
11408 exports.event.stopImmediatePropagation();
11409};
11410
11411// Ignore right-click, since that should open the context menu.
11412function defaultFilter$1() {
11413 return !exports.event.button;
11414}
11415
11416function defaultExtent() {
11417 var e = this,
11418 w,
11419 h;
11420 if (e instanceof SVGElement) {
11421 e = e.ownerSVGElement || e;
11422 w = e.width.baseVal.value;
11423 h = e.height.baseVal.value;
11424 } else {
11425 w = e.clientWidth;
11426 h = e.clientHeight;
11427 }
11428 return [[0, 0], [w, h]];
11429}
11430
11431function defaultTransform() {
11432 return this.__zoom || identity$6;
11433}
11434
11435var zoom = function () {
11436 var filter = defaultFilter$1,
11437 extent = defaultExtent,
11438 k0 = 0,
11439 k1 = Infinity,
11440 x0 = -k1,
11441 x1 = k1,
11442 y0 = x0,
11443 y1 = x1,
11444 duration = 250,
11445 interpolate$$1 = interpolateZoom,
11446 gestures = [],
11447 listeners = dispatch("start", "zoom", "end"),
11448 touchstarting,
11449 touchending,
11450 touchDelay = 500,
11451 wheelDelay = 150;
11452
11453 function zoom(selection$$1) {
11454 selection$$1.on("wheel.zoom", wheeled).on("mousedown.zoom", mousedowned).on("dblclick.zoom", dblclicked).on("touchstart.zoom", touchstarted).on("touchmove.zoom", touchmoved).on("touchend.zoom touchcancel.zoom", touchended).style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").property("__zoom", defaultTransform);
11455 }
11456
11457 zoom.transform = function (collection, transform) {
11458 var selection$$1 = collection.selection ? collection.selection() : collection;
11459 selection$$1.property("__zoom", defaultTransform);
11460 if (collection !== selection$$1) {
11461 schedule(collection, transform);
11462 } else {
11463 selection$$1.interrupt().each(function () {
11464 gesture(this, arguments).start().zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform).end();
11465 });
11466 }
11467 };
11468
11469 zoom.scaleBy = function (selection$$1, k) {
11470 zoom.scaleTo(selection$$1, function () {
11471 var k0 = this.__zoom.k,
11472 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
11473 return k0 * k1;
11474 });
11475 };
11476
11477 zoom.scaleTo = function (selection$$1, k) {
11478 zoom.transform(selection$$1, function () {
11479 var e = extent.apply(this, arguments),
11480 t0 = this.__zoom,
11481 p0 = centroid(e),
11482 p1 = t0.invert(p0),
11483 k1 = typeof k === "function" ? k.apply(this, arguments) : k;
11484 return constrain(translate(scale(t0, k1), p0, p1), e);
11485 });
11486 };
11487
11488 zoom.translateBy = function (selection$$1, x, y) {
11489 zoom.transform(selection$$1, function () {
11490 return constrain(this.__zoom.translate(typeof x === "function" ? x.apply(this, arguments) : x, typeof y === "function" ? y.apply(this, arguments) : y), extent.apply(this, arguments));
11491 });
11492 };
11493
11494 function scale(transform, k) {
11495 k = Math.max(k0, Math.min(k1, k));
11496 return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
11497 }
11498
11499 function translate(transform, p0, p1) {
11500 var x = p0[0] - p1[0] * transform.k,
11501 y = p0[1] - p1[1] * transform.k;
11502 return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
11503 }
11504
11505 function constrain(transform, extent) {
11506 var dx0 = transform.invertX(extent[0][0]) - x0,
11507 dx1 = transform.invertX(extent[1][0]) - x1,
11508 dy0 = transform.invertY(extent[0][1]) - y0,
11509 dy1 = transform.invertY(extent[1][1]) - y1;
11510 return transform.translate(dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1), dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1));
11511 }
11512
11513 function centroid(extent) {
11514 return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
11515 }
11516
11517 function schedule(transition$$1, transform, center) {
11518 transition$$1.on("start.zoom", function () {
11519 gesture(this, arguments).start();
11520 }).on("interrupt.zoom end.zoom", function () {
11521 gesture(this, arguments).end();
11522 }).tween("zoom", function () {
11523 var that = this,
11524 args = arguments,
11525 g = gesture(that, args),
11526 e = extent.apply(that, args),
11527 p = center || centroid(e),
11528 w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
11529 a = that.__zoom,
11530 b = typeof transform === "function" ? transform.apply(that, args) : transform,
11531 i = interpolate$$1(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
11532 return function (t) {
11533 if (t === 1) t = b; // Avoid rounding error on end.
11534 else {
11535 var l = i(t),
11536 k = w / l[2];t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k);
11537 }
11538 g.zoom(null, t);
11539 };
11540 });
11541 }
11542
11543 function gesture(that, args) {
11544 for (var i = 0, n = gestures.length, g; i < n; ++i) {
11545 if ((g = gestures[i]).that === that) {
11546 return g;
11547 }
11548 }
11549 return new Gesture(that, args);
11550 }
11551
11552 function Gesture(that, args) {
11553 this.that = that;
11554 this.args = args;
11555 this.index = -1;
11556 this.active = 0;
11557 this.extent = extent.apply(that, args);
11558 }
11559
11560 Gesture.prototype = {
11561 start: function start() {
11562 if (++this.active === 1) {
11563 this.index = gestures.push(this) - 1;
11564 this.emit("start");
11565 }
11566 return this;
11567 },
11568 zoom: function zoom(key, transform) {
11569 if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
11570 if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
11571 if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
11572 this.that.__zoom = transform;
11573 this.emit("zoom");
11574 return this;
11575 },
11576 end: function end() {
11577 if (--this.active === 0) {
11578 gestures.splice(this.index, 1);
11579 this.index = -1;
11580 this.emit("end");
11581 }
11582 return this;
11583 },
11584 emit: function emit(type) {
11585 customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
11586 }
11587 };
11588
11589 function wheeled() {
11590 if (!filter.apply(this, arguments)) return;
11591 var g = gesture(this, arguments),
11592 t = this.__zoom,
11593 k = Math.max(k0, Math.min(k1, t.k * Math.pow(2, -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500))),
11594 p = mouse(this);
11595
11596 // If the mouse is in the same location as before, reuse it.
11597 // If there were recent wheel events, reset the wheel idle timeout.
11598 if (g.wheel) {
11599 if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
11600 g.mouse[1] = t.invert(g.mouse[0] = p);
11601 }
11602 clearTimeout(g.wheel);
11603 }
11604
11605 // If this wheel event won’t trigger a transform change, ignore it.
11606 else if (t.k === k) return;
11607
11608 // Otherwise, capture the mouse point and location at the start.
11609 else {
11610 g.mouse = [p, t.invert(p)];
11611 interrupt(this);
11612 g.start();
11613 }
11614
11615 noevent$1();
11616 g.wheel = setTimeout(wheelidled, wheelDelay);
11617 g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent));
11618
11619 function wheelidled() {
11620 g.wheel = null;
11621 g.end();
11622 }
11623 }
11624
11625 function mousedowned() {
11626 if (touchending || !filter.apply(this, arguments)) return;
11627 var g = gesture(this, arguments),
11628 v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
11629 p = mouse(this);
11630
11631 dragDisable(exports.event.view);
11632 nopropagation$1();
11633 g.mouse = [p, this.__zoom.invert(p)];
11634 interrupt(this);
11635 g.start();
11636
11637 function mousemoved() {
11638 noevent$1();
11639 g.moved = true;
11640 g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent));
11641 }
11642
11643 function mouseupped() {
11644 v.on("mousemove.zoom mouseup.zoom", null);
11645 yesdrag(exports.event.view, g.moved);
11646 noevent$1();
11647 g.end();
11648 }
11649 }
11650
11651 function dblclicked() {
11652 if (!filter.apply(this, arguments)) return;
11653 var t0 = this.__zoom,
11654 p0 = mouse(this),
11655 p1 = t0.invert(p0),
11656 k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
11657 t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments));
11658
11659 noevent$1();
11660 if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);else select(this).call(zoom.transform, t1);
11661 }
11662
11663 function touchstarted() {
11664 if (!filter.apply(this, arguments)) return;
11665 var g = gesture(this, arguments),
11666 touches$$1 = exports.event.changedTouches,
11667 n = touches$$1.length,
11668 i,
11669 t,
11670 p;
11671
11672 nopropagation$1();
11673 for (i = 0; i < n; ++i) {
11674 t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
11675 p = [p, this.__zoom.invert(p), t.identifier];
11676 if (!g.touch0) g.touch0 = p;else if (!g.touch1) g.touch1 = p;
11677 }
11678
11679 // If this is a dbltap, reroute to the (optional) dblclick.zoom handler.
11680 if (touchstarting) {
11681 touchstarting = clearTimeout(touchstarting);
11682 if (!g.touch1) {
11683 g.end();
11684 p = select(this).on("dblclick.zoom");
11685 if (p) p.apply(this, arguments);
11686 return;
11687 }
11688 }
11689
11690 if (exports.event.touches.length === n) {
11691 touchstarting = setTimeout(function () {
11692 touchstarting = null;
11693 }, touchDelay);
11694 interrupt(this);
11695 g.start();
11696 }
11697 }
11698
11699 function touchmoved() {
11700 var g = gesture(this, arguments),
11701 touches$$1 = exports.event.changedTouches,
11702 n = touches$$1.length,
11703 i,
11704 t,
11705 p,
11706 l;
11707
11708 noevent$1();
11709 if (touchstarting) touchstarting = clearTimeout(touchstarting);
11710 for (i = 0; i < n; ++i) {
11711 t = touches$$1[i], p = touch(this, touches$$1, t.identifier);
11712 if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
11713 }
11714 t = g.that.__zoom;
11715 if (g.touch1) {
11716 var p0 = g.touch0[0],
11717 l0 = g.touch0[1],
11718 p1 = g.touch1[0],
11719 l1 = g.touch1[1],
11720 dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
11721 dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
11722 t = scale(t, Math.sqrt(dp / dl));
11723 p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
11724 l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
11725 } else if (g.touch0) p = g.touch0[0], l = g.touch0[1];else return;
11726 g.zoom("touch", constrain(translate(t, p, l), g.extent));
11727 }
11728
11729 function touchended() {
11730 var g = gesture(this, arguments),
11731 touches$$1 = exports.event.changedTouches,
11732 n = touches$$1.length,
11733 i,
11734 t;
11735
11736 nopropagation$1();
11737 if (touchending) clearTimeout(touchending);
11738 touchending = setTimeout(function () {
11739 touchending = null;
11740 }, touchDelay);
11741 for (i = 0; i < n; ++i) {
11742 t = touches$$1[i];
11743 if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
11744 }
11745 if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
11746 if (!g.touch0) g.end();
11747 }
11748
11749 zoom.filter = function (_) {
11750 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), zoom) : filter;
11751 };
11752
11753 zoom.extent = function (_) {
11754 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$9([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
11755 };
11756
11757 zoom.scaleExtent = function (_) {
11758 return arguments.length ? (k0 = +_[0], k1 = +_[1], zoom) : [k0, k1];
11759 };
11760
11761 zoom.translateExtent = function (_) {
11762 return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], zoom) : [[x0, y0], [x1, y1]];
11763 };
11764
11765 zoom.duration = function (_) {
11766 return arguments.length ? (duration = +_, zoom) : duration;
11767 };
11768
11769 zoom.interpolate = function (_) {
11770 return arguments.length ? (interpolate$$1 = _, zoom) : interpolate$$1;
11771 };
11772
11773 zoom.on = function () {
11774 var value = listeners.on.apply(listeners, arguments);
11775 return value === listeners ? zoom : value;
11776 };
11777
11778 return zoom;
11779};
11780
11781var constant$10 = function (x) {
11782 return function () {
11783 return x;
11784 };
11785};
11786
11787var BrushEvent = function (target, type, selection) {
11788 this.target = target;
11789 this.type = type;
11790 this.selection = selection;
11791};
11792
11793function nopropagation$2() {
11794 exports.event.stopImmediatePropagation();
11795}
11796
11797var noevent$2 = function () {
11798 exports.event.preventDefault();
11799 exports.event.stopImmediatePropagation();
11800};
11801
11802var MODE_DRAG = { name: "drag" };
11803var MODE_SPACE = { name: "space" };
11804var MODE_HANDLE = { name: "handle" };
11805var MODE_CENTER = { name: "center" };
11806
11807var X$1 = {
11808 name: "x",
11809 handles: ["e", "w"].map(type),
11810 input: function input(x, e) {
11811 return x && [[x[0], e[0][1]], [x[1], e[1][1]]];
11812 },
11813 output: function output(xy) {
11814 return xy && [xy[0][0], xy[1][0]];
11815 }
11816};
11817
11818var Y = {
11819 name: "y",
11820 handles: ["n", "s"].map(type),
11821 input: function input(y, e) {
11822 return y && [[e[0][0], y[0]], [e[1][0], y[1]]];
11823 },
11824 output: function output(xy) {
11825 return xy && [xy[0][1], xy[1][1]];
11826 }
11827};
11828
11829var XY = {
11830 name: "xy",
11831 handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type),
11832 input: function input(xy) {
11833 return xy;
11834 },
11835 output: function output(xy) {
11836 return xy;
11837 }
11838};
11839
11840var cursors = {
11841 overlay: "crosshair",
11842 selection: "move",
11843 n: "ns-resize",
11844 e: "ew-resize",
11845 s: "ns-resize",
11846 w: "ew-resize",
11847 nw: "nwse-resize",
11848 ne: "nesw-resize",
11849 se: "nwse-resize",
11850 sw: "nesw-resize"
11851};
11852
11853var flipX = {
11854 e: "w",
11855 w: "e",
11856 nw: "ne",
11857 ne: "nw",
11858 se: "sw",
11859 sw: "se"
11860};
11861
11862var flipY = {
11863 n: "s",
11864 s: "n",
11865 nw: "sw",
11866 ne: "se",
11867 se: "ne",
11868 sw: "nw"
11869};
11870
11871var signsX = {
11872 overlay: +1,
11873 selection: +1,
11874 n: null,
11875 e: +1,
11876 s: null,
11877 w: -1,
11878 nw: -1,
11879 ne: +1,
11880 se: +1,
11881 sw: -1
11882};
11883
11884var signsY = {
11885 overlay: +1,
11886 selection: +1,
11887 n: -1,
11888 e: null,
11889 s: +1,
11890 w: null,
11891 nw: -1,
11892 ne: -1,
11893 se: +1,
11894 sw: +1
11895};
11896
11897function type(t) {
11898 return { type: t };
11899}
11900
11901// Ignore right-click, since that should open the context menu.
11902function defaultFilter$2() {
11903 return !exports.event.button;
11904}
11905
11906function defaultExtent$1() {
11907 var svg = this.ownerSVGElement || this;
11908 return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
11909}
11910
11911// Like d3.local, but with the name “__brush” rather than auto-generated.
11912function local$1(node) {
11913 while (!node.__brush) {
11914 if (!(node = node.parentNode)) return;
11915 }return node.__brush;
11916}
11917
11918function empty$2(extent) {
11919 return extent[0][0] === extent[1][0] || extent[0][1] === extent[1][1];
11920}
11921
11922function brushSelection(node) {
11923 var state = node.__brush;
11924 return state ? state.dim.output(state.selection) : null;
11925}
11926
11927function brushX() {
11928 return brush$1(X$1);
11929}
11930
11931function brushY() {
11932 return brush$1(Y);
11933}
11934
11935var brush = function () {
11936 return brush$1(XY);
11937};
11938
11939function brush$1(dim) {
11940 var extent = defaultExtent$1,
11941 filter = defaultFilter$2,
11942 listeners = dispatch(brush, "start", "brush", "end"),
11943 handleSize = 6,
11944 touchending;
11945
11946 function brush(group) {
11947 var overlay = group.property("__brush", initialize).selectAll(".overlay").data([type("overlay")]);
11948
11949 overlay.enter().append("rect").attr("class", "overlay").attr("pointer-events", "all").attr("cursor", cursors.overlay).merge(overlay).each(function () {
11950 var extent = local$1(this).extent;
11951 select(this).attr("x", extent[0][0]).attr("y", extent[0][1]).attr("width", extent[1][0] - extent[0][0]).attr("height", extent[1][1] - extent[0][1]);
11952 });
11953
11954 group.selectAll(".selection").data([type("selection")]).enter().append("rect").attr("class", "selection").attr("cursor", cursors.selection).attr("fill", "#777").attr("fill-opacity", 0.3).attr("stroke", "#fff").attr("shape-rendering", "crispEdges");
11955
11956 var handle = group.selectAll(".handle").data(dim.handles, function (d) {
11957 return d.type;
11958 });
11959
11960 handle.exit().remove();
11961
11962 handle.enter().append("rect").attr("class", function (d) {
11963 return "handle handle--" + d.type;
11964 }).attr("cursor", function (d) {
11965 return cursors[d.type];
11966 });
11967
11968 group.each(redraw).attr("fill", "none").attr("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush touchstart.brush", started);
11969 }
11970
11971 brush.move = function (group, selection$$1) {
11972 if (group.selection) {
11973 group.on("start.brush", function () {
11974 emitter(this, arguments).beforestart().start();
11975 }).on("interrupt.brush end.brush", function () {
11976 emitter(this, arguments).end();
11977 }).tween("brush", function () {
11978 var that = this,
11979 state = that.__brush,
11980 emit = emitter(that, arguments),
11981 selection0 = state.selection,
11982 selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(this, arguments) : selection$$1, state.extent),
11983 i = interpolate(selection0, selection1);
11984
11985 function tween(t) {
11986 state.selection = t === 1 && empty$2(selection1) ? null : i(t);
11987 redraw.call(that);
11988 emit.brush();
11989 }
11990
11991 return selection0 && selection1 ? tween : tween(1);
11992 });
11993 } else {
11994 group.each(function () {
11995 var that = this,
11996 args = arguments,
11997 state = that.__brush,
11998 selection1 = dim.input(typeof selection$$1 === "function" ? selection$$1.apply(that, args) : selection$$1, state.extent),
11999 emit = emitter(that, args).beforestart();
12000
12001 interrupt(that);
12002 state.selection = selection1 == null || empty$2(selection1) ? null : selection1;
12003 redraw.call(that);
12004 emit.start().brush().end();
12005 });
12006 }
12007 };
12008
12009 function redraw() {
12010 var group = select(this),
12011 selection$$1 = local$1(this).selection;
12012
12013 if (selection$$1) {
12014 group.selectAll(".selection").style("display", null).attr("x", selection$$1[0][0]).attr("y", selection$$1[0][1]).attr("width", selection$$1[1][0] - selection$$1[0][0]).attr("height", selection$$1[1][1] - selection$$1[0][1]);
12015
12016 group.selectAll(".handle").style("display", null).attr("x", function (d) {
12017 return d.type[d.type.length - 1] === "e" ? selection$$1[1][0] - handleSize / 2 : selection$$1[0][0] - handleSize / 2;
12018 }).attr("y", function (d) {
12019 return d.type[0] === "s" ? selection$$1[1][1] - handleSize / 2 : selection$$1[0][1] - handleSize / 2;
12020 }).attr("width", function (d) {
12021 return d.type === "n" || d.type === "s" ? selection$$1[1][0] - selection$$1[0][0] + handleSize : handleSize;
12022 }).attr("height", function (d) {
12023 return d.type === "e" || d.type === "w" ? selection$$1[1][1] - selection$$1[0][1] + handleSize : handleSize;
12024 });
12025 } else {
12026 group.selectAll(".selection,.handle").style("display", "none").attr("x", null).attr("y", null).attr("width", null).attr("height", null);
12027 }
12028 }
12029
12030 function emitter(that, args) {
12031 return that.__brush.emitter || new Emitter(that, args);
12032 }
12033
12034 function Emitter(that, args) {
12035 this.that = that;
12036 this.args = args;
12037 this.state = that.__brush;
12038 this.active = 0;
12039 }
12040
12041 Emitter.prototype = {
12042 beforestart: function beforestart() {
12043 if (++this.active === 1) this.state.emitter = this, this.starting = true;
12044 return this;
12045 },
12046 start: function start() {
12047 if (this.starting) this.starting = false, this.emit("start");
12048 return this;
12049 },
12050 brush: function brush() {
12051 this.emit("brush");
12052 return this;
12053 },
12054 end: function end() {
12055 if (--this.active === 0) delete this.state.emitter, this.emit("end");
12056 return this;
12057 },
12058 emit: function emit(type) {
12059 customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
12060 }
12061 };
12062
12063 function started() {
12064 if (exports.event.touches) {
12065 if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$2();
12066 } else if (touchending) return;
12067 if (!filter.apply(this, arguments)) return;
12068
12069 var that = this,
12070 type = exports.event.target.__data__.type,
12071 mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : exports.event.altKey ? MODE_CENTER : MODE_HANDLE,
12072 signX = dim === Y ? null : signsX[type],
12073 signY = dim === X$1 ? null : signsY[type],
12074 state = local$1(that),
12075 extent = state.extent,
12076 selection$$1 = state.selection,
12077 W = extent[0][0],
12078 w0,
12079 w1,
12080 N = extent[0][1],
12081 n0,
12082 n1,
12083 E = extent[1][0],
12084 e0,
12085 e1,
12086 S = extent[1][1],
12087 s0,
12088 s1,
12089 dx,
12090 dy,
12091 moving,
12092 shifting = signX && signY && exports.event.shiftKey,
12093 lockX,
12094 lockY,
12095 point0 = mouse(that),
12096 point = point0,
12097 emit = emitter(that, arguments).beforestart();
12098
12099 if (type === "overlay") {
12100 state.selection = selection$$1 = [[w0 = dim === Y ? W : point0[0], n0 = dim === X$1 ? N : point0[1]], [e0 = dim === Y ? E : w0, s0 = dim === X$1 ? S : n0]];
12101 } else {
12102 w0 = selection$$1[0][0];
12103 n0 = selection$$1[0][1];
12104 e0 = selection$$1[1][0];
12105 s0 = selection$$1[1][1];
12106 }
12107
12108 w1 = w0;
12109 n1 = n0;
12110 e1 = e0;
12111 s1 = s0;
12112
12113 var group = select(that).attr("pointer-events", "none");
12114
12115 var overlay = group.selectAll(".overlay").attr("cursor", cursors[type]);
12116
12117 if (exports.event.touches) {
12118 group.on("touchmove.brush", moved, true).on("touchend.brush touchcancel.brush", ended, true);
12119 } else {
12120 var view = select(exports.event.view).on("keydown.brush", keydowned, true).on("keyup.brush", keyupped, true).on("mousemove.brush", moved, true).on("mouseup.brush", ended, true);
12121
12122 dragDisable(exports.event.view);
12123 }
12124
12125 nopropagation$2();
12126 interrupt(that);
12127 redraw.call(that);
12128 emit.start();
12129
12130 function moved() {
12131 var point1 = mouse(that);
12132 if (shifting && !lockX && !lockY) {
12133 if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;else lockX = true;
12134 }
12135 point = point1;
12136 moving = true;
12137 noevent$2();
12138 move();
12139 }
12140
12141 function move() {
12142 var t;
12143
12144 dx = point[0] - point0[0];
12145 dy = point[1] - point0[1];
12146
12147 switch (mode) {
12148 case MODE_SPACE:
12149 case MODE_DRAG:
12150 {
12151 if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
12152 if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
12153 break;
12154 }
12155 case MODE_HANDLE:
12156 {
12157 if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
12158 if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
12159 break;
12160 }
12161 case MODE_CENTER:
12162 {
12163 if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
12164 if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
12165 break;
12166 }
12167 }
12168
12169 if (e1 < w1) {
12170 signX *= -1;
12171 t = w0, w0 = e0, e0 = t;
12172 t = w1, w1 = e1, e1 = t;
12173 if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
12174 }
12175
12176 if (s1 < n1) {
12177 signY *= -1;
12178 t = n0, n0 = s0, s0 = t;
12179 t = n1, n1 = s1, s1 = t;
12180 if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
12181 }
12182
12183 if (state.selection) selection$$1 = state.selection; // May be set by brush.move!
12184 if (lockX) w1 = selection$$1[0][0], e1 = selection$$1[1][0];
12185 if (lockY) n1 = selection$$1[0][1], s1 = selection$$1[1][1];
12186
12187 if (selection$$1[0][0] !== w1 || selection$$1[0][1] !== n1 || selection$$1[1][0] !== e1 || selection$$1[1][1] !== s1) {
12188 state.selection = [[w1, n1], [e1, s1]];
12189 redraw.call(that);
12190 emit.brush();
12191 }
12192 }
12193
12194 function ended() {
12195 nopropagation$2();
12196 if (exports.event.touches) {
12197 if (exports.event.touches.length) return;
12198 if (touchending) clearTimeout(touchending);
12199 touchending = setTimeout(function () {
12200 touchending = null;
12201 }, 500); // Ghost clicks are delayed!
12202 group.on("touchmove.brush touchend.brush touchcancel.brush", null);
12203 } else {
12204 yesdrag(exports.event.view, moving);
12205 view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
12206 }
12207 group.attr("pointer-events", "all");
12208 overlay.attr("cursor", cursors.overlay);
12209 if (state.selection) selection$$1 = state.selection; // May be set by brush.move (on start)!
12210 if (empty$2(selection$$1)) state.selection = null, redraw.call(that);
12211 emit.end();
12212 }
12213
12214 function keydowned() {
12215 switch (exports.event.keyCode) {
12216 case 16:
12217 {
12218 // SHIFT
12219 shifting = signX && signY;
12220 break;
12221 }
12222 case 18:
12223 {
12224 // ALT
12225 if (mode === MODE_HANDLE) {
12226 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
12227 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
12228 mode = MODE_CENTER;
12229 move();
12230 }
12231 break;
12232 }
12233 case 32:
12234 {
12235 // SPACE; takes priority over ALT
12236 if (mode === MODE_HANDLE || mode === MODE_CENTER) {
12237 if (signX < 0) e0 = e1 - dx;else if (signX > 0) w0 = w1 - dx;
12238 if (signY < 0) s0 = s1 - dy;else if (signY > 0) n0 = n1 - dy;
12239 mode = MODE_SPACE;
12240 overlay.attr("cursor", cursors.selection);
12241 move();
12242 }
12243 break;
12244 }
12245 default:
12246 return;
12247 }
12248 noevent$2();
12249 }
12250
12251 function keyupped() {
12252 switch (exports.event.keyCode) {
12253 case 16:
12254 {
12255 // SHIFT
12256 if (shifting) {
12257 lockX = lockY = shifting = false;
12258 move();
12259 }
12260 break;
12261 }
12262 case 18:
12263 {
12264 // ALT
12265 if (mode === MODE_CENTER) {
12266 if (signX < 0) e0 = e1;else if (signX > 0) w0 = w1;
12267 if (signY < 0) s0 = s1;else if (signY > 0) n0 = n1;
12268 mode = MODE_HANDLE;
12269 move();
12270 }
12271 break;
12272 }
12273 case 32:
12274 {
12275 // SPACE
12276 if (mode === MODE_SPACE) {
12277 if (exports.event.altKey) {
12278 if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
12279 if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
12280 mode = MODE_CENTER;
12281 } else {
12282 if (signX < 0) e0 = e1;else if (signX > 0) w0 = w1;
12283 if (signY < 0) s0 = s1;else if (signY > 0) n0 = n1;
12284 mode = MODE_HANDLE;
12285 }
12286 overlay.attr("cursor", cursors[type]);
12287 move();
12288 }
12289 break;
12290 }
12291 default:
12292 return;
12293 }
12294 noevent$2();
12295 }
12296 }
12297
12298 function initialize() {
12299 var state = this.__brush || { selection: null };
12300 state.extent = extent.apply(this, arguments);
12301 state.dim = dim;
12302 return state;
12303 }
12304
12305 brush.extent = function (_) {
12306 return arguments.length ? (extent = typeof _ === "function" ? _ : constant$10([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
12307 };
12308
12309 brush.filter = function (_) {
12310 return arguments.length ? (filter = typeof _ === "function" ? _ : constant$10(!!_), brush) : filter;
12311 };
12312
12313 brush.handleSize = function (_) {
12314 return arguments.length ? (handleSize = +_, brush) : handleSize;
12315 };
12316
12317 brush.on = function () {
12318 var value = listeners.on.apply(listeners, arguments);
12319 return value === listeners ? brush : value;
12320 };
12321
12322 return brush;
12323}
12324
12325var cos = Math.cos;
12326var sin = Math.sin;
12327var pi$3 = Math.PI;
12328var halfPi$2 = pi$3 / 2;
12329var tau$3 = pi$3 * 2;
12330var max$1 = Math.max;
12331
12332function compareValue(compare) {
12333 return function (a, b) {
12334 return compare(a.source.value + a.target.value, b.source.value + b.target.value);
12335 };
12336}
12337
12338var chord = function () {
12339 var padAngle = 0,
12340 sortGroups = null,
12341 sortSubgroups = null,
12342 sortChords = null;
12343
12344 function chord(matrix) {
12345 var n = matrix.length,
12346 groupSums = [],
12347 groupIndex = range(n),
12348 subgroupIndex = [],
12349 chords = [],
12350 groups = chords.groups = new Array(n),
12351 subgroups = new Array(n * n),
12352 k,
12353 x,
12354 x0,
12355 dx,
12356 i,
12357 j;
12358
12359 // Compute the sum.
12360 k = 0, i = -1;while (++i < n) {
12361 x = 0, j = -1;while (++j < n) {
12362 x += matrix[i][j];
12363 }
12364 groupSums.push(x);
12365 subgroupIndex.push(range(n));
12366 k += x;
12367 }
12368
12369 // Sort groups…
12370 if (sortGroups) groupIndex.sort(function (a, b) {
12371 return sortGroups(groupSums[a], groupSums[b]);
12372 });
12373
12374 // Sort subgroups…
12375 if (sortSubgroups) subgroupIndex.forEach(function (d, i) {
12376 d.sort(function (a, b) {
12377 return sortSubgroups(matrix[i][a], matrix[i][b]);
12378 });
12379 });
12380
12381 // Convert the sum to scaling factor for [0, 2pi].
12382 // TODO Allow start and end angle to be specified?
12383 // TODO Allow padding to be specified as percentage?
12384 k = max$1(0, tau$3 - padAngle * n) / k;
12385 dx = k ? padAngle : tau$3 / n;
12386
12387 // Compute the start and end angle for each group and subgroup.
12388 // Note: Opera has a bug reordering object literal properties!
12389 x = 0, i = -1;while (++i < n) {
12390 x0 = x, j = -1;while (++j < n) {
12391 var di = groupIndex[i],
12392 dj = subgroupIndex[di][j],
12393 v = matrix[di][dj],
12394 a0 = x,
12395 a1 = x += v * k;
12396 subgroups[dj * n + di] = {
12397 index: di,
12398 subindex: dj,
12399 startAngle: a0,
12400 endAngle: a1,
12401 value: v
12402 };
12403 }
12404 groups[di] = {
12405 index: di,
12406 startAngle: x0,
12407 endAngle: x,
12408 value: groupSums[di]
12409 };
12410 x += dx;
12411 }
12412
12413 // Generate chords for each (non-empty) subgroup-subgroup link.
12414 i = -1;while (++i < n) {
12415 j = i - 1;while (++j < n) {
12416 var source = subgroups[j * n + i],
12417 target = subgroups[i * n + j];
12418 if (source.value || target.value) {
12419 chords.push(source.value < target.value ? { source: target, target: source } : { source: source, target: target });
12420 }
12421 }
12422 }
12423
12424 return sortChords ? chords.sort(sortChords) : chords;
12425 }
12426
12427 chord.padAngle = function (_) {
12428 return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
12429 };
12430
12431 chord.sortGroups = function (_) {
12432 return arguments.length ? (sortGroups = _, chord) : sortGroups;
12433 };
12434
12435 chord.sortSubgroups = function (_) {
12436 return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
12437 };
12438
12439 chord.sortChords = function (_) {
12440 return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
12441 };
12442
12443 return chord;
12444};
12445
12446var slice$4 = Array.prototype.slice;
12447
12448var constant$11 = function (x) {
12449 return function () {
12450 return x;
12451 };
12452};
12453
12454function defaultSource(d) {
12455 return d.source;
12456}
12457
12458function defaultTarget(d) {
12459 return d.target;
12460}
12461
12462function defaultRadius$1(d) {
12463 return d.radius;
12464}
12465
12466function defaultStartAngle(d) {
12467 return d.startAngle;
12468}
12469
12470function defaultEndAngle(d) {
12471 return d.endAngle;
12472}
12473
12474var ribbon = function () {
12475 var source = defaultSource,
12476 target = defaultTarget,
12477 radius = defaultRadius$1,
12478 startAngle = defaultStartAngle,
12479 endAngle = defaultEndAngle,
12480 context = null;
12481
12482 function ribbon() {
12483 var buffer,
12484 argv = slice$4.call(arguments),
12485 s = source.apply(this, argv),
12486 t = target.apply(this, argv),
12487 sr = +radius.apply(this, (argv[0] = s, argv)),
12488 sa0 = startAngle.apply(this, argv) - halfPi$2,
12489 sa1 = endAngle.apply(this, argv) - halfPi$2,
12490 sx0 = sr * cos(sa0),
12491 sy0 = sr * sin(sa0),
12492 tr = +radius.apply(this, (argv[0] = t, argv)),
12493 ta0 = startAngle.apply(this, argv) - halfPi$2,
12494 ta1 = endAngle.apply(this, argv) - halfPi$2;
12495
12496 if (!context) context = buffer = path();
12497
12498 context.moveTo(sx0, sy0);
12499 context.arc(0, 0, sr, sa0, sa1);
12500 if (sa0 !== ta0 || sa1 !== ta1) {
12501 // TODO sr !== tr?
12502 context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
12503 context.arc(0, 0, tr, ta0, ta1);
12504 }
12505 context.quadraticCurveTo(0, 0, sx0, sy0);
12506 context.closePath();
12507
12508 if (buffer) return context = null, buffer + "" || null;
12509 }
12510
12511 ribbon.radius = function (_) {
12512 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$11(+_), ribbon) : radius;
12513 };
12514
12515 ribbon.startAngle = function (_) {
12516 return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$11(+_), ribbon) : startAngle;
12517 };
12518
12519 ribbon.endAngle = function (_) {
12520 return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$11(+_), ribbon) : endAngle;
12521 };
12522
12523 ribbon.source = function (_) {
12524 return arguments.length ? (source = _, ribbon) : source;
12525 };
12526
12527 ribbon.target = function (_) {
12528 return arguments.length ? (target = _, ribbon) : target;
12529 };
12530
12531 ribbon.context = function (_) {
12532 return arguments.length ? (context = _ == null ? null : _, ribbon) : context;
12533 };
12534
12535 return ribbon;
12536};
12537
12538// Adds floating point numbers with twice the normal precision.
12539// Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
12540// Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
12541// 305–363 (1997).
12542// Code adapted from GeographicLib by Charles F. F. Karney,
12543// http://geographiclib.sourceforge.net/
12544
12545var adder = function () {
12546 return new Adder();
12547};
12548
12549function Adder() {
12550 this.reset();
12551}
12552
12553Adder.prototype = {
12554 constructor: Adder,
12555 reset: function reset() {
12556 this.s = // rounded value
12557 this.t = 0; // exact error
12558 },
12559 add: function add(y) {
12560 _add(temp, y, this.t);
12561 _add(this, temp.s, this.s);
12562 if (this.s) this.t += temp.t;else this.s = temp.t;
12563 },
12564 valueOf: function valueOf() {
12565 return this.s;
12566 }
12567};
12568
12569var temp = new Adder();
12570
12571function _add(adder, a, b) {
12572 var x = adder.s = a + b,
12573 bv = x - a,
12574 av = x - bv;
12575 adder.t = a - av + (b - bv);
12576}
12577
12578var epsilon$4 = 1e-6;
12579var epsilon2$2 = 1e-12;
12580var pi$4 = Math.PI;
12581var halfPi$3 = pi$4 / 2;
12582var quarterPi = pi$4 / 4;
12583var tau$4 = pi$4 * 2;
12584
12585var degrees$1 = 180 / pi$4;
12586var radians = pi$4 / 180;
12587
12588var abs = Math.abs;
12589var atan = Math.atan;
12590var atan2 = Math.atan2;
12591var cos$1 = Math.cos;
12592var ceil$1 = Math.ceil;
12593var exp = Math.exp;
12594
12595var log$1 = Math.log;
12596var pow$1 = Math.pow;
12597var sin$1 = Math.sin;
12598var sign$1 = Math.sign || function (x) {
12599 return x > 0 ? 1 : x < 0 ? -1 : 0;
12600};
12601var sqrt$1 = Math.sqrt;
12602var tan = Math.tan;
12603
12604function acos(x) {
12605 return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
12606}
12607
12608function asin$1(x) {
12609 return x > 1 ? halfPi$3 : x < -1 ? -halfPi$3 : Math.asin(x);
12610}
12611
12612function haversin(x) {
12613 return (x = sin$1(x / 2)) * x;
12614}
12615
12616function noop$2() {}
12617
12618function streamGeometry(geometry, stream) {
12619 if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
12620 streamGeometryType[geometry.type](geometry, stream);
12621 }
12622}
12623
12624var streamObjectType = {
12625 Feature: function Feature(feature, stream) {
12626 streamGeometry(feature.geometry, stream);
12627 },
12628 FeatureCollection: function FeatureCollection(object, stream) {
12629 var features = object.features,
12630 i = -1,
12631 n = features.length;
12632 while (++i < n) {
12633 streamGeometry(features[i].geometry, stream);
12634 }
12635 }
12636};
12637
12638var streamGeometryType = {
12639 Sphere: function Sphere(object, stream) {
12640 stream.sphere();
12641 },
12642 Point: function Point(object, stream) {
12643 object = object.coordinates;
12644 stream.point(object[0], object[1], object[2]);
12645 },
12646 MultiPoint: function MultiPoint(object, stream) {
12647 var coordinates = object.coordinates,
12648 i = -1,
12649 n = coordinates.length;
12650 while (++i < n) {
12651 object = coordinates[i], stream.point(object[0], object[1], object[2]);
12652 }
12653 },
12654 LineString: function LineString(object, stream) {
12655 streamLine(object.coordinates, stream, 0);
12656 },
12657 MultiLineString: function MultiLineString(object, stream) {
12658 var coordinates = object.coordinates,
12659 i = -1,
12660 n = coordinates.length;
12661 while (++i < n) {
12662 streamLine(coordinates[i], stream, 0);
12663 }
12664 },
12665 Polygon: function Polygon(object, stream) {
12666 streamPolygon(object.coordinates, stream);
12667 },
12668 MultiPolygon: function MultiPolygon(object, stream) {
12669 var coordinates = object.coordinates,
12670 i = -1,
12671 n = coordinates.length;
12672 while (++i < n) {
12673 streamPolygon(coordinates[i], stream);
12674 }
12675 },
12676 GeometryCollection: function GeometryCollection(object, stream) {
12677 var geometries = object.geometries,
12678 i = -1,
12679 n = geometries.length;
12680 while (++i < n) {
12681 streamGeometry(geometries[i], stream);
12682 }
12683 }
12684};
12685
12686function streamLine(coordinates, stream, closed) {
12687 var i = -1,
12688 n = coordinates.length - closed,
12689 coordinate;
12690 stream.lineStart();
12691 while (++i < n) {
12692 coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
12693 }stream.lineEnd();
12694}
12695
12696function streamPolygon(coordinates, stream) {
12697 var i = -1,
12698 n = coordinates.length;
12699 stream.polygonStart();
12700 while (++i < n) {
12701 streamLine(coordinates[i], stream, 1);
12702 }stream.polygonEnd();
12703}
12704
12705var geoStream = function (object, stream) {
12706 if (object && streamObjectType.hasOwnProperty(object.type)) {
12707 streamObjectType[object.type](object, stream);
12708 } else {
12709 streamGeometry(object, stream);
12710 }
12711};
12712
12713var areaRingSum = adder();
12714
12715var areaSum = adder();
12716var lambda00;
12717var phi00;
12718var lambda0;
12719var cosPhi0;
12720var sinPhi0;
12721
12722var areaStream = {
12723 point: noop$2,
12724 lineStart: noop$2,
12725 lineEnd: noop$2,
12726 polygonStart: function polygonStart() {
12727 areaRingSum.reset();
12728 areaStream.lineStart = areaRingStart;
12729 areaStream.lineEnd = areaRingEnd;
12730 },
12731 polygonEnd: function polygonEnd() {
12732 var areaRing = +areaRingSum;
12733 areaSum.add(areaRing < 0 ? tau$4 + areaRing : areaRing);
12734 this.lineStart = this.lineEnd = this.point = noop$2;
12735 },
12736 sphere: function sphere() {
12737 areaSum.add(tau$4);
12738 }
12739};
12740
12741function areaRingStart() {
12742 areaStream.point = areaPointFirst;
12743}
12744
12745function areaRingEnd() {
12746 areaPoint(lambda00, phi00);
12747}
12748
12749function areaPointFirst(lambda, phi) {
12750 areaStream.point = areaPoint;
12751 lambda00 = lambda, phi00 = phi;
12752 lambda *= radians, phi *= radians;
12753 lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
12754}
12755
12756function areaPoint(lambda, phi) {
12757 lambda *= radians, phi *= radians;
12758 phi = phi / 2 + quarterPi; // half the angular distance from south pole
12759
12760 // Spherical excess E for a spherical triangle with vertices: south pole,
12761 // previous point, current point. Uses a formula derived from Cagnoli’s
12762 // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
12763 var dLambda = lambda - lambda0,
12764 sdLambda = dLambda >= 0 ? 1 : -1,
12765 adLambda = sdLambda * dLambda,
12766 cosPhi = cos$1(phi),
12767 sinPhi = sin$1(phi),
12768 k = sinPhi0 * sinPhi,
12769 u = cosPhi0 * cosPhi + k * cos$1(adLambda),
12770 v = k * sdLambda * sin$1(adLambda);
12771 areaRingSum.add(atan2(v, u));
12772
12773 // Advance the previous points.
12774 lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
12775}
12776
12777var area$2 = function (object) {
12778 areaSum.reset();
12779 geoStream(object, areaStream);
12780 return areaSum * 2;
12781};
12782
12783function spherical(cartesian) {
12784 return [atan2(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
12785}
12786
12787function cartesian(spherical) {
12788 var lambda = spherical[0],
12789 phi = spherical[1],
12790 cosPhi = cos$1(phi);
12791 return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
12792}
12793
12794function cartesianDot(a, b) {
12795 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
12796}
12797
12798function cartesianCross(a, b) {
12799 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]];
12800}
12801
12802// TODO return a
12803function cartesianAddInPlace(a, b) {
12804 a[0] += b[0], a[1] += b[1], a[2] += b[2];
12805}
12806
12807function cartesianScale(vector, k) {
12808 return [vector[0] * k, vector[1] * k, vector[2] * k];
12809}
12810
12811// TODO return d
12812function cartesianNormalizeInPlace(d) {
12813 var l = sqrt$1(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
12814 d[0] /= l, d[1] /= l, d[2] /= l;
12815}
12816
12817var lambda0$1;
12818var phi0;
12819var lambda1;
12820var phi1;
12821var lambda2;
12822var lambda00$1;
12823var phi00$1;
12824var p0;
12825var deltaSum = adder();
12826var ranges;
12827var range$1;
12828
12829var boundsStream = {
12830 point: boundsPoint,
12831 lineStart: boundsLineStart,
12832 lineEnd: boundsLineEnd,
12833 polygonStart: function polygonStart() {
12834 boundsStream.point = boundsRingPoint;
12835 boundsStream.lineStart = boundsRingStart;
12836 boundsStream.lineEnd = boundsRingEnd;
12837 deltaSum.reset();
12838 areaStream.polygonStart();
12839 },
12840 polygonEnd: function polygonEnd() {
12841 areaStream.polygonEnd();
12842 boundsStream.point = boundsPoint;
12843 boundsStream.lineStart = boundsLineStart;
12844 boundsStream.lineEnd = boundsLineEnd;
12845 if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);else if (deltaSum > epsilon$4) phi1 = 90;else if (deltaSum < -epsilon$4) phi0 = -90;
12846 range$1[0] = lambda0$1, range$1[1] = lambda1;
12847 }
12848};
12849
12850function boundsPoint(lambda, phi) {
12851 ranges.push(range$1 = [lambda0$1 = lambda, lambda1 = lambda]);
12852 if (phi < phi0) phi0 = phi;
12853 if (phi > phi1) phi1 = phi;
12854}
12855
12856function linePoint(lambda, phi) {
12857 var p = cartesian([lambda * radians, phi * radians]);
12858 if (p0) {
12859 var normal = cartesianCross(p0, p),
12860 equatorial = [normal[1], -normal[0], 0],
12861 inflection = cartesianCross(equatorial, normal);
12862 cartesianNormalizeInPlace(inflection);
12863 inflection = spherical(inflection);
12864 var delta = lambda - lambda2,
12865 sign$$1 = delta > 0 ? 1 : -1,
12866 lambdai = inflection[0] * degrees$1 * sign$$1,
12867 phii,
12868 antimeridian = abs(delta) > 180;
12869 if (antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
12870 phii = inflection[1] * degrees$1;
12871 if (phii > phi1) phi1 = phii;
12872 } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign$$1 * lambda2 < lambdai && lambdai < sign$$1 * lambda)) {
12873 phii = -inflection[1] * degrees$1;
12874 if (phii < phi0) phi0 = phii;
12875 } else {
12876 if (phi < phi0) phi0 = phi;
12877 if (phi > phi1) phi1 = phi;
12878 }
12879 if (antimeridian) {
12880 if (lambda < lambda2) {
12881 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
12882 } else {
12883 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
12884 }
12885 } else {
12886 if (lambda1 >= lambda0$1) {
12887 if (lambda < lambda0$1) lambda0$1 = lambda;
12888 if (lambda > lambda1) lambda1 = lambda;
12889 } else {
12890 if (lambda > lambda2) {
12891 if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
12892 } else {
12893 if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
12894 }
12895 }
12896 }
12897 } else {
12898 boundsPoint(lambda, phi);
12899 }
12900 p0 = p, lambda2 = lambda;
12901}
12902
12903function boundsLineStart() {
12904 boundsStream.point = linePoint;
12905}
12906
12907function boundsLineEnd() {
12908 range$1[0] = lambda0$1, range$1[1] = lambda1;
12909 boundsStream.point = boundsPoint;
12910 p0 = null;
12911}
12912
12913function boundsRingPoint(lambda, phi) {
12914 if (p0) {
12915 var delta = lambda - lambda2;
12916 deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
12917 } else {
12918 lambda00$1 = lambda, phi00$1 = phi;
12919 }
12920 areaStream.point(lambda, phi);
12921 linePoint(lambda, phi);
12922}
12923
12924function boundsRingStart() {
12925 areaStream.lineStart();
12926}
12927
12928function boundsRingEnd() {
12929 boundsRingPoint(lambda00$1, phi00$1);
12930 areaStream.lineEnd();
12931 if (abs(deltaSum) > epsilon$4) lambda0$1 = -(lambda1 = 180);
12932 range$1[0] = lambda0$1, range$1[1] = lambda1;
12933 p0 = null;
12934}
12935
12936// Finds the left-right distance between two longitudes.
12937// This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
12938// the distance between ±180° to be 360°.
12939function angle(lambda0, lambda1) {
12940 return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
12941}
12942
12943function rangeCompare(a, b) {
12944 return a[0] - b[0];
12945}
12946
12947function rangeContains(range, x) {
12948 return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
12949}
12950
12951var bounds = function (feature) {
12952 var i, n, a, b, merged, deltaMax, delta;
12953
12954 phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
12955 ranges = [];
12956 geoStream(feature, boundsStream);
12957
12958 // First, sort ranges by their minimum longitudes.
12959 if (n = ranges.length) {
12960 ranges.sort(rangeCompare);
12961
12962 // Then, merge any ranges that overlap.
12963 for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
12964 b = ranges[i];
12965 if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
12966 if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
12967 if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
12968 } else {
12969 merged.push(a = b);
12970 }
12971 }
12972
12973 // Finally, find the largest gap between the merged ranges.
12974 // The final bounding box will be the inverse of this gap.
12975 for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
12976 b = merged[i];
12977 if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
12978 }
12979 }
12980
12981 ranges = range$1 = null;
12982
12983 return lambda0$1 === Infinity || phi0 === Infinity ? [[NaN, NaN], [NaN, NaN]] : [[lambda0$1, phi0], [lambda1, phi1]];
12984};
12985
12986var W0;
12987var W1;
12988var X0;
12989var Y0;
12990var Z0;
12991var X1;
12992var Y1;
12993var Z1;
12994var X2;
12995var Y2;
12996var Z2;
12997var lambda00$2;
12998var phi00$2;
12999var x0;
13000var y0;
13001var z0; // previous point
13002
13003var centroidStream = {
13004 sphere: noop$2,
13005 point: centroidPoint,
13006 lineStart: centroidLineStart,
13007 lineEnd: centroidLineEnd,
13008 polygonStart: function polygonStart() {
13009 centroidStream.lineStart = centroidRingStart;
13010 centroidStream.lineEnd = centroidRingEnd;
13011 },
13012 polygonEnd: function polygonEnd() {
13013 centroidStream.lineStart = centroidLineStart;
13014 centroidStream.lineEnd = centroidLineEnd;
13015 }
13016};
13017
13018// Arithmetic mean of Cartesian vectors.
13019function centroidPoint(lambda, phi) {
13020 lambda *= radians, phi *= radians;
13021 var cosPhi = cos$1(phi);
13022 centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
13023}
13024
13025function centroidPointCartesian(x, y, z) {
13026 ++W0;
13027 X0 += (x - X0) / W0;
13028 Y0 += (y - Y0) / W0;
13029 Z0 += (z - Z0) / W0;
13030}
13031
13032function centroidLineStart() {
13033 centroidStream.point = centroidLinePointFirst;
13034}
13035
13036function centroidLinePointFirst(lambda, phi) {
13037 lambda *= radians, phi *= radians;
13038 var cosPhi = cos$1(phi);
13039 x0 = cosPhi * cos$1(lambda);
13040 y0 = cosPhi * sin$1(lambda);
13041 z0 = sin$1(phi);
13042 centroidStream.point = centroidLinePoint;
13043 centroidPointCartesian(x0, y0, z0);
13044}
13045
13046function centroidLinePoint(lambda, phi) {
13047 lambda *= radians, phi *= radians;
13048 var cosPhi = cos$1(phi),
13049 x = cosPhi * cos$1(lambda),
13050 y = cosPhi * sin$1(lambda),
13051 z = sin$1(phi),
13052 w = atan2(sqrt$1((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
13053 W1 += w;
13054 X1 += w * (x0 + (x0 = x));
13055 Y1 += w * (y0 + (y0 = y));
13056 Z1 += w * (z0 + (z0 = z));
13057 centroidPointCartesian(x0, y0, z0);
13058}
13059
13060function centroidLineEnd() {
13061 centroidStream.point = centroidPoint;
13062}
13063
13064// See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
13065// J. Applied Mechanics 42, 239 (1975).
13066function centroidRingStart() {
13067 centroidStream.point = centroidRingPointFirst;
13068}
13069
13070function centroidRingEnd() {
13071 centroidRingPoint(lambda00$2, phi00$2);
13072 centroidStream.point = centroidPoint;
13073}
13074
13075function centroidRingPointFirst(lambda, phi) {
13076 lambda00$2 = lambda, phi00$2 = phi;
13077 lambda *= radians, phi *= radians;
13078 centroidStream.point = centroidRingPoint;
13079 var cosPhi = cos$1(phi);
13080 x0 = cosPhi * cos$1(lambda);
13081 y0 = cosPhi * sin$1(lambda);
13082 z0 = sin$1(phi);
13083 centroidPointCartesian(x0, y0, z0);
13084}
13085
13086function centroidRingPoint(lambda, phi) {
13087 lambda *= radians, phi *= radians;
13088 var cosPhi = cos$1(phi),
13089 x = cosPhi * cos$1(lambda),
13090 y = cosPhi * sin$1(lambda),
13091 z = sin$1(phi),
13092 cx = y0 * z - z0 * y,
13093 cy = z0 * x - x0 * z,
13094 cz = x0 * y - y0 * x,
13095 m = sqrt$1(cx * cx + cy * cy + cz * cz),
13096 u = x0 * x + y0 * y + z0 * z,
13097 v = m && -acos(u) / m,
13098 // area weight
13099 w = atan2(m, u); // line weight
13100 X2 += v * cx;
13101 Y2 += v * cy;
13102 Z2 += v * cz;
13103 W1 += w;
13104 X1 += w * (x0 + (x0 = x));
13105 Y1 += w * (y0 + (y0 = y));
13106 Z1 += w * (z0 + (z0 = z));
13107 centroidPointCartesian(x0, y0, z0);
13108}
13109
13110var centroid$1 = function (object) {
13111 W0 = W1 = X0 = Y0 = Z0 = X1 = Y1 = Z1 = X2 = Y2 = Z2 = 0;
13112 geoStream(object, centroidStream);
13113
13114 var x = X2,
13115 y = Y2,
13116 z = Z2,
13117 m = x * x + y * y + z * z;
13118
13119 // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
13120 if (m < epsilon2$2) {
13121 x = X1, y = Y1, z = Z1;
13122 // If the feature has zero length, fall back to arithmetic mean of point vectors.
13123 if (W1 < epsilon$4) x = X0, y = Y0, z = Z0;
13124 m = x * x + y * y + z * z;
13125 // If the feature still has an undefined ccentroid, then return.
13126 if (m < epsilon2$2) return [NaN, NaN];
13127 }
13128
13129 return [atan2(y, x) * degrees$1, asin$1(z / sqrt$1(m)) * degrees$1];
13130};
13131
13132var constant$12 = function (x) {
13133 return function () {
13134 return x;
13135 };
13136};
13137
13138var compose = function (a, b) {
13139
13140 function compose(x, y) {
13141 return x = a(x, y), b(x[0], x[1]);
13142 }
13143
13144 if (a.invert && b.invert) compose.invert = function (x, y) {
13145 return x = b.invert(x, y), x && a.invert(x[0], x[1]);
13146 };
13147
13148 return compose;
13149};
13150
13151function rotationIdentity(lambda, phi) {
13152 return [lambda > pi$4 ? lambda - tau$4 : lambda < -pi$4 ? lambda + tau$4 : lambda, phi];
13153}
13154
13155rotationIdentity.invert = rotationIdentity;
13156
13157function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
13158 return (deltaLambda %= tau$4) ? deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma)) : rotationLambda(deltaLambda) : deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma) : rotationIdentity;
13159}
13160
13161function forwardRotationLambda(deltaLambda) {
13162 return function (lambda, phi) {
13163 return lambda += deltaLambda, [lambda > pi$4 ? lambda - tau$4 : lambda < -pi$4 ? lambda + tau$4 : lambda, phi];
13164 };
13165}
13166
13167function rotationLambda(deltaLambda) {
13168 var rotation = forwardRotationLambda(deltaLambda);
13169 rotation.invert = forwardRotationLambda(-deltaLambda);
13170 return rotation;
13171}
13172
13173function rotationPhiGamma(deltaPhi, deltaGamma) {
13174 var cosDeltaPhi = cos$1(deltaPhi),
13175 sinDeltaPhi = sin$1(deltaPhi),
13176 cosDeltaGamma = cos$1(deltaGamma),
13177 sinDeltaGamma = sin$1(deltaGamma);
13178
13179 function rotation(lambda, phi) {
13180 var cosPhi = cos$1(phi),
13181 x = cos$1(lambda) * cosPhi,
13182 y = sin$1(lambda) * cosPhi,
13183 z = sin$1(phi),
13184 k = z * cosDeltaPhi + x * sinDeltaPhi;
13185 return [atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi), asin$1(k * cosDeltaGamma + y * sinDeltaGamma)];
13186 }
13187
13188 rotation.invert = function (lambda, phi) {
13189 var cosPhi = cos$1(phi),
13190 x = cos$1(lambda) * cosPhi,
13191 y = sin$1(lambda) * cosPhi,
13192 z = sin$1(phi),
13193 k = z * cosDeltaGamma - y * sinDeltaGamma;
13194 return [atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi), asin$1(k * cosDeltaPhi - x * sinDeltaPhi)];
13195 };
13196
13197 return rotation;
13198}
13199
13200var rotation = function (rotate) {
13201 rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
13202
13203 function forward(coordinates) {
13204 coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
13205 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
13206 }
13207
13208 forward.invert = function (coordinates) {
13209 coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
13210 return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
13211 };
13212
13213 return forward;
13214};
13215
13216// Generates a circle centered at [0°, 0°], with a given radius and precision.
13217function circleStream(stream, radius, delta, direction, t0, t1) {
13218 if (!delta) return;
13219 var cosRadius = cos$1(radius),
13220 sinRadius = sin$1(radius),
13221 step = direction * delta;
13222 if (t0 == null) {
13223 t0 = radius + direction * tau$4;
13224 t1 = radius - step / 2;
13225 } else {
13226 t0 = circleRadius(cosRadius, t0);
13227 t1 = circleRadius(cosRadius, t1);
13228 if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$4;
13229 }
13230 for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
13231 point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
13232 stream.point(point[0], point[1]);
13233 }
13234}
13235
13236// Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
13237function circleRadius(cosRadius, point) {
13238 point = cartesian(point), point[0] -= cosRadius;
13239 cartesianNormalizeInPlace(point);
13240 var radius = acos(-point[1]);
13241 return ((-point[2] < 0 ? -radius : radius) + tau$4 - epsilon$4) % tau$4;
13242}
13243
13244var circle$1 = function () {
13245 var center = constant$12([0, 0]),
13246 radius = constant$12(90),
13247 precision = constant$12(6),
13248 ring,
13249 rotate,
13250 stream = { point: point };
13251
13252 function point(x, y) {
13253 ring.push(x = rotate(x, y));
13254 x[0] *= degrees$1, x[1] *= degrees$1;
13255 }
13256
13257 function circle() {
13258 var c = center.apply(this, arguments),
13259 r = radius.apply(this, arguments) * radians,
13260 p = precision.apply(this, arguments) * radians;
13261 ring = [];
13262 rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
13263 circleStream(stream, r, p, 1);
13264 c = { type: "Polygon", coordinates: [ring] };
13265 ring = rotate = null;
13266 return c;
13267 }
13268
13269 circle.center = function (_) {
13270 return arguments.length ? (center = typeof _ === "function" ? _ : constant$12([+_[0], +_[1]]), circle) : center;
13271 };
13272
13273 circle.radius = function (_) {
13274 return arguments.length ? (radius = typeof _ === "function" ? _ : constant$12(+_), circle) : radius;
13275 };
13276
13277 circle.precision = function (_) {
13278 return arguments.length ? (precision = typeof _ === "function" ? _ : constant$12(+_), circle) : precision;
13279 };
13280
13281 return circle;
13282};
13283
13284var clipBuffer = function () {
13285 var lines = [],
13286 line;
13287 return {
13288 point: function point(x, y) {
13289 line.push([x, y]);
13290 },
13291 lineStart: function lineStart() {
13292 lines.push(line = []);
13293 },
13294 lineEnd: noop$2,
13295 rejoin: function rejoin() {
13296 if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
13297 },
13298 result: function result() {
13299 var result = lines;
13300 lines = [];
13301 line = null;
13302 return result;
13303 }
13304 };
13305};
13306
13307var clipLine = function (a, b, x0, y0, x1, y1) {
13308 var ax = a[0],
13309 ay = a[1],
13310 bx = b[0],
13311 by = b[1],
13312 t0 = 0,
13313 t1 = 1,
13314 dx = bx - ax,
13315 dy = by - ay,
13316 r;
13317
13318 r = x0 - ax;
13319 if (!dx && r > 0) return;
13320 r /= dx;
13321 if (dx < 0) {
13322 if (r < t0) return;
13323 if (r < t1) t1 = r;
13324 } else if (dx > 0) {
13325 if (r > t1) return;
13326 if (r > t0) t0 = r;
13327 }
13328
13329 r = x1 - ax;
13330 if (!dx && r < 0) return;
13331 r /= dx;
13332 if (dx < 0) {
13333 if (r > t1) return;
13334 if (r > t0) t0 = r;
13335 } else if (dx > 0) {
13336 if (r < t0) return;
13337 if (r < t1) t1 = r;
13338 }
13339
13340 r = y0 - ay;
13341 if (!dy && r > 0) return;
13342 r /= dy;
13343 if (dy < 0) {
13344 if (r < t0) return;
13345 if (r < t1) t1 = r;
13346 } else if (dy > 0) {
13347 if (r > t1) return;
13348 if (r > t0) t0 = r;
13349 }
13350
13351 r = y1 - ay;
13352 if (!dy && r < 0) return;
13353 r /= dy;
13354 if (dy < 0) {
13355 if (r > t1) return;
13356 if (r > t0) t0 = r;
13357 } else if (dy > 0) {
13358 if (r < t0) return;
13359 if (r < t1) t1 = r;
13360 }
13361
13362 if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
13363 if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
13364 return true;
13365};
13366
13367var pointEqual = function (a, b) {
13368 return abs(a[0] - b[0]) < epsilon$4 && abs(a[1] - b[1]) < epsilon$4;
13369};
13370
13371function Intersection(point, points, other, entry) {
13372 this.x = point;
13373 this.z = points;
13374 this.o = other; // another intersection
13375 this.e = entry; // is an entry?
13376 this.v = false; // visited
13377 this.n = this.p = null; // next & previous
13378}
13379
13380// A generalized polygon clipping algorithm: given a polygon that has been cut
13381// into its visible line segments, and rejoins the segments by interpolating
13382// along the clip edge.
13383var clipPolygon = function (segments, compareIntersection, startInside, interpolate, stream) {
13384 var subject = [],
13385 clip = [],
13386 i,
13387 n;
13388
13389 segments.forEach(function (segment) {
13390 if ((n = segment.length - 1) <= 0) return;
13391 var n,
13392 p0 = segment[0],
13393 p1 = segment[n],
13394 x;
13395
13396 // If the first and last points of a segment are coincident, then treat as a
13397 // closed ring. TODO if all rings are closed, then the winding order of the
13398 // exterior ring should be checked.
13399 if (pointEqual(p0, p1)) {
13400 stream.lineStart();
13401 for (i = 0; i < n; ++i) {
13402 stream.point((p0 = segment[i])[0], p0[1]);
13403 }stream.lineEnd();
13404 return;
13405 }
13406
13407 subject.push(x = new Intersection(p0, segment, null, true));
13408 clip.push(x.o = new Intersection(p0, null, x, false));
13409 subject.push(x = new Intersection(p1, segment, null, false));
13410 clip.push(x.o = new Intersection(p1, null, x, true));
13411 });
13412
13413 if (!subject.length) return;
13414
13415 clip.sort(compareIntersection);
13416 link(subject);
13417 link(clip);
13418
13419 for (i = 0, n = clip.length; i < n; ++i) {
13420 clip[i].e = startInside = !startInside;
13421 }
13422
13423 var start = subject[0],
13424 points,
13425 point;
13426
13427 while (1) {
13428 // Find first unvisited intersection.
13429 var current = start,
13430 isSubject = true;
13431 while (current.v) {
13432 if ((current = current.n) === start) return;
13433 }points = current.z;
13434 stream.lineStart();
13435 do {
13436 current.v = current.o.v = true;
13437 if (current.e) {
13438 if (isSubject) {
13439 for (i = 0, n = points.length; i < n; ++i) {
13440 stream.point((point = points[i])[0], point[1]);
13441 }
13442 } else {
13443 interpolate(current.x, current.n.x, 1, stream);
13444 }
13445 current = current.n;
13446 } else {
13447 if (isSubject) {
13448 points = current.p.z;
13449 for (i = points.length - 1; i >= 0; --i) {
13450 stream.point((point = points[i])[0], point[1]);
13451 }
13452 } else {
13453 interpolate(current.x, current.p.x, -1, stream);
13454 }
13455 current = current.p;
13456 }
13457 current = current.o;
13458 points = current.z;
13459 isSubject = !isSubject;
13460 } while (!current.v);
13461 stream.lineEnd();
13462 }
13463};
13464
13465function link(array) {
13466 if (!(n = array.length)) return;
13467 var n,
13468 i = 0,
13469 a = array[0],
13470 b;
13471 while (++i < n) {
13472 a.n = b = array[i];
13473 b.p = a;
13474 a = b;
13475 }
13476 a.n = b = array[0];
13477 b.p = a;
13478}
13479
13480var clipMax = 1e9;
13481var clipMin = -clipMax;
13482
13483// TODO Use d3-polygon’s polygonContains here for the ring check?
13484// TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
13485
13486function clipExtent$1(x0, y0, x1, y1) {
13487
13488 function visible(x, y) {
13489 return x0 <= x && x <= x1 && y0 <= y && y <= y1;
13490 }
13491
13492 function interpolate(from, to, direction, stream) {
13493 var a = 0,
13494 a1 = 0;
13495 if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoint(from, to) < 0 ^ direction > 0) {
13496 do {
13497 stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
13498 } while ((a = (a + direction + 4) % 4) !== a1);
13499 } else {
13500 stream.point(to[0], to[1]);
13501 }
13502 }
13503
13504 function corner(p, direction) {
13505 return abs(p[0] - x0) < epsilon$4 ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < epsilon$4 ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < epsilon$4 ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
13506 }
13507
13508 function compareIntersection(a, b) {
13509 return comparePoint(a.x, b.x);
13510 }
13511
13512 function comparePoint(a, b) {
13513 var ca = corner(a, 1),
13514 cb = corner(b, 1);
13515 return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
13516 }
13517
13518 return function (stream) {
13519 var activeStream = stream,
13520 bufferStream = clipBuffer(),
13521 segments,
13522 polygon,
13523 ring,
13524 x__,
13525 y__,
13526 v__,
13527 // first point
13528 x_,
13529 y_,
13530 v_,
13531 // previous point
13532 first,
13533 clean;
13534
13535 var clipStream = {
13536 point: point,
13537 lineStart: lineStart,
13538 lineEnd: lineEnd,
13539 polygonStart: polygonStart,
13540 polygonEnd: polygonEnd
13541 };
13542
13543 function point(x, y) {
13544 if (visible(x, y)) activeStream.point(x, y);
13545 }
13546
13547 function polygonInside() {
13548 var winding = 0;
13549
13550 for (var i = 0, n = polygon.length; i < n; ++i) {
13551 for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
13552 a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
13553 if (a1 <= y1) {
13554 if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding;
13555 } else {
13556 if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding;
13557 }
13558 }
13559 }
13560
13561 return winding;
13562 }
13563
13564 // Buffer geometry within a polygon and then clip it en masse.
13565 function polygonStart() {
13566 activeStream = bufferStream, segments = [], polygon = [], clean = true;
13567 }
13568
13569 function polygonEnd() {
13570 var startInside = polygonInside(),
13571 cleanInside = clean && startInside,
13572 visible = (segments = merge(segments)).length;
13573 if (cleanInside || visible) {
13574 stream.polygonStart();
13575 if (cleanInside) {
13576 stream.lineStart();
13577 interpolate(null, null, 1, stream);
13578 stream.lineEnd();
13579 }
13580 if (visible) {
13581 clipPolygon(segments, compareIntersection, startInside, interpolate, stream);
13582 }
13583 stream.polygonEnd();
13584 }
13585 activeStream = stream, segments = polygon = ring = null;
13586 }
13587
13588 function lineStart() {
13589 clipStream.point = linePoint;
13590 if (polygon) polygon.push(ring = []);
13591 first = true;
13592 v_ = false;
13593 x_ = y_ = NaN;
13594 }
13595
13596 // TODO rather than special-case polygons, simply handle them separately.
13597 // Ideally, coincident intersection points should be jittered to avoid
13598 // clipping issues.
13599 function lineEnd() {
13600 if (segments) {
13601 linePoint(x__, y__);
13602 if (v__ && v_) bufferStream.rejoin();
13603 segments.push(bufferStream.result());
13604 }
13605 clipStream.point = point;
13606 if (v_) activeStream.lineEnd();
13607 }
13608
13609 function linePoint(x, y) {
13610 var v = visible(x, y);
13611 if (polygon) ring.push([x, y]);
13612 if (first) {
13613 x__ = x, y__ = y, v__ = v;
13614 first = false;
13615 if (v) {
13616 activeStream.lineStart();
13617 activeStream.point(x, y);
13618 }
13619 } else {
13620 if (v && v_) activeStream.point(x, y);else {
13621 var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
13622 b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
13623 if (clipLine(a, b, x0, y0, x1, y1)) {
13624 if (!v_) {
13625 activeStream.lineStart();
13626 activeStream.point(a[0], a[1]);
13627 }
13628 activeStream.point(b[0], b[1]);
13629 if (!v) activeStream.lineEnd();
13630 clean = false;
13631 } else if (v) {
13632 activeStream.lineStart();
13633 activeStream.point(x, y);
13634 clean = false;
13635 }
13636 }
13637 }
13638 x_ = x, y_ = y, v_ = v;
13639 }
13640
13641 return clipStream;
13642 };
13643}
13644
13645var extent$2 = function () {
13646 var x0 = 0,
13647 y0 = 0,
13648 x1 = 960,
13649 y1 = 500,
13650 cache,
13651 cacheStream,
13652 clip;
13653
13654 return clip = {
13655 stream: function stream(_stream) {
13656 return cache && cacheStream === _stream ? cache : cache = clipExtent$1(x0, y0, x1, y1)(cacheStream = _stream);
13657 },
13658 extent: function extent(_) {
13659 return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
13660 }
13661 };
13662};
13663
13664var lengthSum = adder();
13665var lambda0$2;
13666var sinPhi0$1;
13667var cosPhi0$1;
13668
13669var lengthStream = {
13670 sphere: noop$2,
13671 point: noop$2,
13672 lineStart: lengthLineStart,
13673 lineEnd: noop$2,
13674 polygonStart: noop$2,
13675 polygonEnd: noop$2
13676};
13677
13678function lengthLineStart() {
13679 lengthStream.point = lengthPointFirst;
13680 lengthStream.lineEnd = lengthLineEnd;
13681}
13682
13683function lengthLineEnd() {
13684 lengthStream.point = lengthStream.lineEnd = noop$2;
13685}
13686
13687function lengthPointFirst(lambda, phi) {
13688 lambda *= radians, phi *= radians;
13689 lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
13690 lengthStream.point = lengthPoint;
13691}
13692
13693function lengthPoint(lambda, phi) {
13694 lambda *= radians, phi *= radians;
13695 var sinPhi = sin$1(phi),
13696 cosPhi = cos$1(phi),
13697 delta = abs(lambda - lambda0$2),
13698 cosDelta = cos$1(delta),
13699 sinDelta = sin$1(delta),
13700 x = cosPhi * sinDelta,
13701 y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
13702 z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
13703 lengthSum.add(atan2(sqrt$1(x * x + y * y), z));
13704 lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
13705}
13706
13707var length$2 = function (object) {
13708 lengthSum.reset();
13709 geoStream(object, lengthStream);
13710 return +lengthSum;
13711};
13712
13713var coordinates = [null, null];
13714var object$2 = { type: "LineString", coordinates: coordinates };
13715
13716var distance = function (a, b) {
13717 coordinates[0] = a;
13718 coordinates[1] = b;
13719 return length$2(object$2);
13720};
13721
13722function graticuleX(y0, y1, dy) {
13723 var y = range(y0, y1 - epsilon$4, dy).concat(y1);
13724 return function (x) {
13725 return y.map(function (y) {
13726 return [x, y];
13727 });
13728 };
13729}
13730
13731function graticuleY(x0, x1, dx) {
13732 var x = range(x0, x1 - epsilon$4, dx).concat(x1);
13733 return function (y) {
13734 return x.map(function (x) {
13735 return [x, y];
13736 });
13737 };
13738}
13739
13740function graticule() {
13741 var x1,
13742 x0,
13743 X1,
13744 X0,
13745 y1,
13746 y0,
13747 Y1,
13748 Y0,
13749 dx = 10,
13750 dy = dx,
13751 DX = 90,
13752 DY = 360,
13753 x,
13754 y,
13755 X,
13756 Y,
13757 precision = 2.5;
13758
13759 function graticule() {
13760 return { type: "MultiLineString", coordinates: lines() };
13761 }
13762
13763 function lines() {
13764 return range(ceil$1(X0 / DX) * DX, X1, DX).map(X).concat(range(ceil$1(Y0 / DY) * DY, Y1, DY).map(Y)).concat(range(ceil$1(x0 / dx) * dx, x1, dx).filter(function (x) {
13765 return abs(x % DX) > epsilon$4;
13766 }).map(x)).concat(range(ceil$1(y0 / dy) * dy, y1, dy).filter(function (y) {
13767 return abs(y % DY) > epsilon$4;
13768 }).map(y));
13769 }
13770
13771 graticule.lines = function () {
13772 return lines().map(function (coordinates) {
13773 return { type: "LineString", coordinates: coordinates };
13774 });
13775 };
13776
13777 graticule.outline = function () {
13778 return {
13779 type: "Polygon",
13780 coordinates: [X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1))]
13781 };
13782 };
13783
13784 graticule.extent = function (_) {
13785 if (!arguments.length) return graticule.extentMinor();
13786 return graticule.extentMajor(_).extentMinor(_);
13787 };
13788
13789 graticule.extentMajor = function (_) {
13790 if (!arguments.length) return [[X0, Y0], [X1, Y1]];
13791 X0 = +_[0][0], X1 = +_[1][0];
13792 Y0 = +_[0][1], Y1 = +_[1][1];
13793 if (X0 > X1) _ = X0, X0 = X1, X1 = _;
13794 if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
13795 return graticule.precision(precision);
13796 };
13797
13798 graticule.extentMinor = function (_) {
13799 if (!arguments.length) return [[x0, y0], [x1, y1]];
13800 x0 = +_[0][0], x1 = +_[1][0];
13801 y0 = +_[0][1], y1 = +_[1][1];
13802 if (x0 > x1) _ = x0, x0 = x1, x1 = _;
13803 if (y0 > y1) _ = y0, y0 = y1, y1 = _;
13804 return graticule.precision(precision);
13805 };
13806
13807 graticule.step = function (_) {
13808 if (!arguments.length) return graticule.stepMinor();
13809 return graticule.stepMajor(_).stepMinor(_);
13810 };
13811
13812 graticule.stepMajor = function (_) {
13813 if (!arguments.length) return [DX, DY];
13814 DX = +_[0], DY = +_[1];
13815 return graticule;
13816 };
13817
13818 graticule.stepMinor = function (_) {
13819 if (!arguments.length) return [dx, dy];
13820 dx = +_[0], dy = +_[1];
13821 return graticule;
13822 };
13823
13824 graticule.precision = function (_) {
13825 if (!arguments.length) return precision;
13826 precision = +_;
13827 x = graticuleX(y0, y1, 90);
13828 y = graticuleY(x0, x1, precision);
13829 X = graticuleX(Y0, Y1, 90);
13830 Y = graticuleY(X0, X1, precision);
13831 return graticule;
13832 };
13833
13834 return graticule.extentMajor([[-180, -90 + epsilon$4], [180, 90 - epsilon$4]]).extentMinor([[-180, -80 - epsilon$4], [180, 80 + epsilon$4]]);
13835}
13836
13837function graticule10() {
13838 return graticule()();
13839}
13840
13841var interpolate$2 = function (a, b) {
13842 var x0 = a[0] * radians,
13843 y0 = a[1] * radians,
13844 x1 = b[0] * radians,
13845 y1 = b[1] * radians,
13846 cy0 = cos$1(y0),
13847 sy0 = sin$1(y0),
13848 cy1 = cos$1(y1),
13849 sy1 = sin$1(y1),
13850 kx0 = cy0 * cos$1(x0),
13851 ky0 = cy0 * sin$1(x0),
13852 kx1 = cy1 * cos$1(x1),
13853 ky1 = cy1 * sin$1(x1),
13854 d = 2 * asin$1(sqrt$1(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
13855 k = sin$1(d);
13856
13857 var interpolate = d ? function (t) {
13858 var B = sin$1(t *= d) / k,
13859 A = sin$1(d - t) / k,
13860 x = A * kx0 + B * kx1,
13861 y = A * ky0 + B * ky1,
13862 z = A * sy0 + B * sy1;
13863 return [atan2(y, x) * degrees$1, atan2(z, sqrt$1(x * x + y * y)) * degrees$1];
13864 } : function () {
13865 return [x0 * degrees$1, y0 * degrees$1];
13866 };
13867
13868 interpolate.distance = d;
13869
13870 return interpolate;
13871};
13872
13873var identity$7 = function (x) {
13874 return x;
13875};
13876
13877var areaSum$1 = adder();
13878var areaRingSum$1 = adder();
13879var x00;
13880var y00;
13881var x0$1;
13882var y0$1;
13883
13884var areaStream$1 = {
13885 point: noop$2,
13886 lineStart: noop$2,
13887 lineEnd: noop$2,
13888 polygonStart: function polygonStart() {
13889 areaStream$1.lineStart = areaRingStart$1;
13890 areaStream$1.lineEnd = areaRingEnd$1;
13891 },
13892 polygonEnd: function polygonEnd() {
13893 areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
13894 areaSum$1.add(abs(areaRingSum$1));
13895 areaRingSum$1.reset();
13896 },
13897 result: function result() {
13898 var area = areaSum$1 / 2;
13899 areaSum$1.reset();
13900 return area;
13901 }
13902};
13903
13904function areaRingStart$1() {
13905 areaStream$1.point = areaPointFirst$1;
13906}
13907
13908function areaPointFirst$1(x, y) {
13909 areaStream$1.point = areaPoint$1;
13910 x00 = x0$1 = x, y00 = y0$1 = y;
13911}
13912
13913function areaPoint$1(x, y) {
13914 areaRingSum$1.add(y0$1 * x - x0$1 * y);
13915 x0$1 = x, y0$1 = y;
13916}
13917
13918function areaRingEnd$1() {
13919 areaPoint$1(x00, y00);
13920}
13921
13922var x0$2 = Infinity;
13923var y0$2 = x0$2;
13924var x1 = -x0$2;
13925var y1 = x1;
13926
13927var boundsStream$1 = {
13928 point: boundsPoint$1,
13929 lineStart: noop$2,
13930 lineEnd: noop$2,
13931 polygonStart: noop$2,
13932 polygonEnd: noop$2,
13933 result: function result() {
13934 var bounds = [[x0$2, y0$2], [x1, y1]];
13935 x1 = y1 = -(y0$2 = x0$2 = Infinity);
13936 return bounds;
13937 }
13938};
13939
13940function boundsPoint$1(x, y) {
13941 if (x < x0$2) x0$2 = x;
13942 if (x > x1) x1 = x;
13943 if (y < y0$2) y0$2 = y;
13944 if (y > y1) y1 = y;
13945}
13946
13947// TODO Enforce positive area for exterior, negative area for interior?
13948
13949var X0$1 = 0;
13950var Y0$1 = 0;
13951var Z0$1 = 0;
13952var X1$1 = 0;
13953var Y1$1 = 0;
13954var Z1$1 = 0;
13955var X2$1 = 0;
13956var Y2$1 = 0;
13957var Z2$1 = 0;
13958var x00$1;
13959var y00$1;
13960var x0$3;
13961var y0$3;
13962
13963var centroidStream$1 = {
13964 point: centroidPoint$1,
13965 lineStart: centroidLineStart$1,
13966 lineEnd: centroidLineEnd$1,
13967 polygonStart: function polygonStart() {
13968 centroidStream$1.lineStart = centroidRingStart$1;
13969 centroidStream$1.lineEnd = centroidRingEnd$1;
13970 },
13971 polygonEnd: function polygonEnd() {
13972 centroidStream$1.point = centroidPoint$1;
13973 centroidStream$1.lineStart = centroidLineStart$1;
13974 centroidStream$1.lineEnd = centroidLineEnd$1;
13975 },
13976 result: function result() {
13977 var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1] : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1] : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1] : [NaN, NaN];
13978 X0$1 = Y0$1 = Z0$1 = X1$1 = Y1$1 = Z1$1 = X2$1 = Y2$1 = Z2$1 = 0;
13979 return centroid;
13980 }
13981};
13982
13983function centroidPoint$1(x, y) {
13984 X0$1 += x;
13985 Y0$1 += y;
13986 ++Z0$1;
13987}
13988
13989function centroidLineStart$1() {
13990 centroidStream$1.point = centroidPointFirstLine;
13991}
13992
13993function centroidPointFirstLine(x, y) {
13994 centroidStream$1.point = centroidPointLine;
13995 centroidPoint$1(x0$3 = x, y0$3 = y);
13996}
13997
13998function centroidPointLine(x, y) {
13999 var dx = x - x0$3,
14000 dy = y - y0$3,
14001 z = sqrt$1(dx * dx + dy * dy);
14002 X1$1 += z * (x0$3 + x) / 2;
14003 Y1$1 += z * (y0$3 + y) / 2;
14004 Z1$1 += z;
14005 centroidPoint$1(x0$3 = x, y0$3 = y);
14006}
14007
14008function centroidLineEnd$1() {
14009 centroidStream$1.point = centroidPoint$1;
14010}
14011
14012function centroidRingStart$1() {
14013 centroidStream$1.point = centroidPointFirstRing;
14014}
14015
14016function centroidRingEnd$1() {
14017 centroidPointRing(x00$1, y00$1);
14018}
14019
14020function centroidPointFirstRing(x, y) {
14021 centroidStream$1.point = centroidPointRing;
14022 centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
14023}
14024
14025function centroidPointRing(x, y) {
14026 var dx = x - x0$3,
14027 dy = y - y0$3,
14028 z = sqrt$1(dx * dx + dy * dy);
14029
14030 X1$1 += z * (x0$3 + x) / 2;
14031 Y1$1 += z * (y0$3 + y) / 2;
14032 Z1$1 += z;
14033
14034 z = y0$3 * x - x0$3 * y;
14035 X2$1 += z * (x0$3 + x);
14036 Y2$1 += z * (y0$3 + y);
14037 Z2$1 += z * 3;
14038 centroidPoint$1(x0$3 = x, y0$3 = y);
14039}
14040
14041function PathContext(context) {
14042 this._context = context;
14043}
14044
14045PathContext.prototype = {
14046 _radius: 4.5,
14047 pointRadius: function pointRadius(_) {
14048 return this._radius = _, this;
14049 },
14050 polygonStart: function polygonStart() {
14051 this._line = 0;
14052 },
14053 polygonEnd: function polygonEnd() {
14054 this._line = NaN;
14055 },
14056 lineStart: function lineStart() {
14057 this._point = 0;
14058 },
14059 lineEnd: function lineEnd() {
14060 if (this._line === 0) this._context.closePath();
14061 this._point = NaN;
14062 },
14063 point: function point(x, y) {
14064 switch (this._point) {
14065 case 0:
14066 {
14067 this._context.moveTo(x, y);
14068 this._point = 1;
14069 break;
14070 }
14071 case 1:
14072 {
14073 this._context.lineTo(x, y);
14074 break;
14075 }
14076 default:
14077 {
14078 this._context.moveTo(x + this._radius, y);
14079 this._context.arc(x, y, this._radius, 0, tau$4);
14080 break;
14081 }
14082 }
14083 },
14084 result: noop$2
14085};
14086
14087function PathString() {
14088 this._string = [];
14089}
14090
14091PathString.prototype = {
14092 _circle: circle$2(4.5),
14093 pointRadius: function pointRadius(_) {
14094 return this._circle = circle$2(_), this;
14095 },
14096 polygonStart: function polygonStart() {
14097 this._line = 0;
14098 },
14099 polygonEnd: function polygonEnd() {
14100 this._line = NaN;
14101 },
14102 lineStart: function lineStart() {
14103 this._point = 0;
14104 },
14105 lineEnd: function lineEnd() {
14106 if (this._line === 0) this._string.push("Z");
14107 this._point = NaN;
14108 },
14109 point: function point(x, y) {
14110 switch (this._point) {
14111 case 0:
14112 {
14113 this._string.push("M", x, ",", y);
14114 this._point = 1;
14115 break;
14116 }
14117 case 1:
14118 {
14119 this._string.push("L", x, ",", y);
14120 break;
14121 }
14122 default:
14123 {
14124 this._string.push("M", x, ",", y, this._circle);
14125 break;
14126 }
14127 }
14128 },
14129 result: function result() {
14130 if (this._string.length) {
14131 var result = this._string.join("");
14132 this._string = [];
14133 return result;
14134 }
14135 }
14136};
14137
14138function circle$2(radius) {
14139 return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
14140}
14141
14142var index$2 = function (projection, context) {
14143 var pointRadius = 4.5,
14144 projectionStream,
14145 contextStream;
14146
14147 function path(object) {
14148 if (object) {
14149 if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
14150 geoStream(object, projectionStream(contextStream));
14151 }
14152 return contextStream.result();
14153 }
14154
14155 path.area = function (object) {
14156 geoStream(object, projectionStream(areaStream$1));
14157 return areaStream$1.result();
14158 };
14159
14160 path.bounds = function (object) {
14161 geoStream(object, projectionStream(boundsStream$1));
14162 return boundsStream$1.result();
14163 };
14164
14165 path.centroid = function (object) {
14166 geoStream(object, projectionStream(centroidStream$1));
14167 return centroidStream$1.result();
14168 };
14169
14170 path.projection = function (_) {
14171 return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$7) : (projection = _).stream, path) : projection;
14172 };
14173
14174 path.context = function (_) {
14175 if (!arguments.length) return context;
14176 contextStream = _ == null ? (context = null, new PathString()) : new PathContext(context = _);
14177 if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
14178 return path;
14179 };
14180
14181 path.pointRadius = function (_) {
14182 if (!arguments.length) return pointRadius;
14183 pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
14184 return path;
14185 };
14186
14187 return path.projection(projection).context(context);
14188};
14189
14190var sum$2 = adder();
14191
14192var polygonContains = function (polygon, point) {
14193 var lambda = point[0],
14194 phi = point[1],
14195 normal = [sin$1(lambda), -cos$1(lambda), 0],
14196 angle = 0,
14197 winding = 0;
14198
14199 sum$2.reset();
14200
14201 for (var i = 0, n = polygon.length; i < n; ++i) {
14202 if (!(m = (ring = polygon[i]).length)) continue;
14203 var ring,
14204 m,
14205 point0 = ring[m - 1],
14206 lambda0 = point0[0],
14207 phi0 = point0[1] / 2 + quarterPi,
14208 sinPhi0 = sin$1(phi0),
14209 cosPhi0 = cos$1(phi0);
14210
14211 for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
14212 var point1 = ring[j],
14213 lambda1 = point1[0],
14214 phi1 = point1[1] / 2 + quarterPi,
14215 sinPhi1 = sin$1(phi1),
14216 cosPhi1 = cos$1(phi1),
14217 delta = lambda1 - lambda0,
14218 sign$$1 = delta >= 0 ? 1 : -1,
14219 absDelta = sign$$1 * delta,
14220 antimeridian = absDelta > pi$4,
14221 k = sinPhi0 * sinPhi1;
14222
14223 sum$2.add(atan2(k * sign$$1 * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
14224 angle += antimeridian ? delta + sign$$1 * tau$4 : delta;
14225
14226 // Are the longitudes either side of the point’s meridian (lambda),
14227 // and are the latitudes smaller than the parallel (phi)?
14228 if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
14229 var arc = cartesianCross(cartesian(point0), cartesian(point1));
14230 cartesianNormalizeInPlace(arc);
14231 var intersection = cartesianCross(normal, arc);
14232 cartesianNormalizeInPlace(intersection);
14233 var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
14234 if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
14235 winding += antimeridian ^ delta >= 0 ? 1 : -1;
14236 }
14237 }
14238 }
14239 }
14240
14241 // First, determine whether the South pole is inside or outside:
14242 //
14243 // It is inside if:
14244 // * the polygon winds around it in a clockwise direction.
14245 // * the polygon does not (cumulatively) wind around it, but has a negative
14246 // (counter-clockwise) area.
14247 //
14248 // Second, count the (signed) number of times a segment crosses a lambda
14249 // from the point to the South pole. If it is zero, then the point is the
14250 // same side as the South pole.
14251
14252 return (angle < -epsilon$4 || angle < epsilon$4 && sum$2 < -epsilon$4) ^ winding & 1;
14253};
14254
14255var clip = function (pointVisible, clipLine, interpolate, start) {
14256 return function (rotate, sink) {
14257 var line = clipLine(sink),
14258 rotatedStart = rotate.invert(start[0], start[1]),
14259 ringBuffer = clipBuffer(),
14260 ringSink = clipLine(ringBuffer),
14261 polygonStarted = false,
14262 polygon,
14263 segments,
14264 ring;
14265
14266 var clip = {
14267 point: point,
14268 lineStart: lineStart,
14269 lineEnd: lineEnd,
14270 polygonStart: function polygonStart() {
14271 clip.point = pointRing;
14272 clip.lineStart = ringStart;
14273 clip.lineEnd = ringEnd;
14274 segments = [];
14275 polygon = [];
14276 },
14277 polygonEnd: function polygonEnd() {
14278 clip.point = point;
14279 clip.lineStart = lineStart;
14280 clip.lineEnd = lineEnd;
14281 segments = merge(segments);
14282 var startInside = polygonContains(polygon, rotatedStart);
14283 if (segments.length) {
14284 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
14285 clipPolygon(segments, compareIntersection, startInside, interpolate, sink);
14286 } else if (startInside) {
14287 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
14288 sink.lineStart();
14289 interpolate(null, null, 1, sink);
14290 sink.lineEnd();
14291 }
14292 if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
14293 segments = polygon = null;
14294 },
14295 sphere: function sphere() {
14296 sink.polygonStart();
14297 sink.lineStart();
14298 interpolate(null, null, 1, sink);
14299 sink.lineEnd();
14300 sink.polygonEnd();
14301 }
14302 };
14303
14304 function point(lambda, phi) {
14305 var point = rotate(lambda, phi);
14306 if (pointVisible(lambda = point[0], phi = point[1])) sink.point(lambda, phi);
14307 }
14308
14309 function pointLine(lambda, phi) {
14310 var point = rotate(lambda, phi);
14311 line.point(point[0], point[1]);
14312 }
14313
14314 function lineStart() {
14315 clip.point = pointLine;
14316 line.lineStart();
14317 }
14318
14319 function lineEnd() {
14320 clip.point = point;
14321 line.lineEnd();
14322 }
14323
14324 function pointRing(lambda, phi) {
14325 ring.push([lambda, phi]);
14326 var point = rotate(lambda, phi);
14327 ringSink.point(point[0], point[1]);
14328 }
14329
14330 function ringStart() {
14331 ringSink.lineStart();
14332 ring = [];
14333 }
14334
14335 function ringEnd() {
14336 pointRing(ring[0][0], ring[0][1]);
14337 ringSink.lineEnd();
14338
14339 var clean = ringSink.clean(),
14340 ringSegments = ringBuffer.result(),
14341 i,
14342 n = ringSegments.length,
14343 m,
14344 segment,
14345 point;
14346
14347 ring.pop();
14348 polygon.push(ring);
14349 ring = null;
14350
14351 if (!n) return;
14352
14353 // No intersections.
14354 if (clean & 1) {
14355 segment = ringSegments[0];
14356 if ((m = segment.length - 1) > 0) {
14357 if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
14358 sink.lineStart();
14359 for (i = 0; i < m; ++i) {
14360 sink.point((point = segment[i])[0], point[1]);
14361 }sink.lineEnd();
14362 }
14363 return;
14364 }
14365
14366 // Rejoin connected segments.
14367 // TODO reuse ringBuffer.rejoin()?
14368 if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
14369
14370 segments.push(ringSegments.filter(validSegment));
14371 }
14372
14373 return clip;
14374 };
14375};
14376
14377function validSegment(segment) {
14378 return segment.length > 1;
14379}
14380
14381// Intersections are sorted along the clip edge. For both antimeridian cutting
14382// and circle clipping, the same comparison is used.
14383function compareIntersection(a, b) {
14384 return ((a = a.x)[0] < 0 ? a[1] - halfPi$3 - epsilon$4 : halfPi$3 - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfPi$3 - epsilon$4 : halfPi$3 - b[1]);
14385}
14386
14387var clipAntimeridian = clip(function () {
14388 return true;
14389}, clipAntimeridianLine, clipAntimeridianInterpolate, [-pi$4, -halfPi$3]);
14390
14391// Takes a line and cuts into visible segments. Return values: 0 - there were
14392// intersections or the line was empty; 1 - no intersections; 2 - there were
14393// intersections, and the first and last segments should be rejoined.
14394function clipAntimeridianLine(stream) {
14395 var lambda0 = NaN,
14396 phi0 = NaN,
14397 sign0 = NaN,
14398 _clean; // no intersections
14399
14400 return {
14401 lineStart: function lineStart() {
14402 stream.lineStart();
14403 _clean = 1;
14404 },
14405 point: function point(lambda1, phi1) {
14406 var sign1 = lambda1 > 0 ? pi$4 : -pi$4,
14407 delta = abs(lambda1 - lambda0);
14408 if (abs(delta - pi$4) < epsilon$4) {
14409 // line crosses a pole
14410 stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$3 : -halfPi$3);
14411 stream.point(sign0, phi0);
14412 stream.lineEnd();
14413 stream.lineStart();
14414 stream.point(sign1, phi0);
14415 stream.point(lambda1, phi0);
14416 _clean = 0;
14417 } else if (sign0 !== sign1 && delta >= pi$4) {
14418 // line crosses antimeridian
14419 if (abs(lambda0 - sign0) < epsilon$4) lambda0 -= sign0 * epsilon$4; // handle degeneracies
14420 if (abs(lambda1 - sign1) < epsilon$4) lambda1 -= sign1 * epsilon$4;
14421 phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
14422 stream.point(sign0, phi0);
14423 stream.lineEnd();
14424 stream.lineStart();
14425 stream.point(sign1, phi0);
14426 _clean = 0;
14427 }
14428 stream.point(lambda0 = lambda1, phi0 = phi1);
14429 sign0 = sign1;
14430 },
14431 lineEnd: function lineEnd() {
14432 stream.lineEnd();
14433 lambda0 = phi0 = NaN;
14434 },
14435 clean: function clean() {
14436 return 2 - _clean; // if intersections, rejoin first and last segments
14437 }
14438 };
14439}
14440
14441function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
14442 var cosPhi0,
14443 cosPhi1,
14444 sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
14445 return abs(sinLambda0Lambda1) > epsilon$4 ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1) - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0)) / (cosPhi0 * cosPhi1 * sinLambda0Lambda1)) : (phi0 + phi1) / 2;
14446}
14447
14448function clipAntimeridianInterpolate(from, to, direction, stream) {
14449 var phi;
14450 if (from == null) {
14451 phi = direction * halfPi$3;
14452 stream.point(-pi$4, phi);
14453 stream.point(0, phi);
14454 stream.point(pi$4, phi);
14455 stream.point(pi$4, 0);
14456 stream.point(pi$4, -phi);
14457 stream.point(0, -phi);
14458 stream.point(-pi$4, -phi);
14459 stream.point(-pi$4, 0);
14460 stream.point(-pi$4, phi);
14461 } else if (abs(from[0] - to[0]) > epsilon$4) {
14462 var lambda = from[0] < to[0] ? pi$4 : -pi$4;
14463 phi = direction * lambda / 2;
14464 stream.point(-lambda, phi);
14465 stream.point(0, phi);
14466 stream.point(lambda, phi);
14467 } else {
14468 stream.point(to[0], to[1]);
14469 }
14470}
14471
14472var clipCircle = function (radius, delta) {
14473 var cr = cos$1(radius),
14474 smallRadius = cr > 0,
14475 notHemisphere = abs(cr) > epsilon$4; // TODO optimise for this common case
14476
14477 function interpolate(from, to, direction, stream) {
14478 circleStream(stream, radius, delta, direction, from, to);
14479 }
14480
14481 function visible(lambda, phi) {
14482 return cos$1(lambda) * cos$1(phi) > cr;
14483 }
14484
14485 // Takes a line and cuts into visible segments. Return values used for polygon
14486 // clipping: 0 - there were intersections or the line was empty; 1 - no
14487 // intersections 2 - there were intersections, and the first and last segments
14488 // should be rejoined.
14489 function clipLine(stream) {
14490 var point0, // previous point
14491 c0, // code for previous point
14492 v0, // visibility of previous point
14493 v00, // visibility of first point
14494 _clean; // no intersections
14495 return {
14496 lineStart: function lineStart() {
14497 v00 = v0 = false;
14498 _clean = 1;
14499 },
14500 point: function point(lambda, phi) {
14501 var point1 = [lambda, phi],
14502 point2,
14503 v = visible(lambda, phi),
14504 c = smallRadius ? v ? 0 : code(lambda, phi) : v ? code(lambda + (lambda < 0 ? pi$4 : -pi$4), phi) : 0;
14505 if (!point0 && (v00 = v0 = v)) stream.lineStart();
14506 // Handle degeneracies.
14507 // TODO ignore if not clipping polygons.
14508 if (v !== v0) {
14509 point2 = intersect(point0, point1);
14510 if (pointEqual(point0, point2) || pointEqual(point1, point2)) {
14511 point1[0] += epsilon$4;
14512 point1[1] += epsilon$4;
14513 v = visible(point1[0], point1[1]);
14514 }
14515 }
14516 if (v !== v0) {
14517 _clean = 0;
14518 if (v) {
14519 // outside going in
14520 stream.lineStart();
14521 point2 = intersect(point1, point0);
14522 stream.point(point2[0], point2[1]);
14523 } else {
14524 // inside going out
14525 point2 = intersect(point0, point1);
14526 stream.point(point2[0], point2[1]);
14527 stream.lineEnd();
14528 }
14529 point0 = point2;
14530 } else if (notHemisphere && point0 && smallRadius ^ v) {
14531 var t;
14532 // If the codes for two points are different, or are both zero,
14533 // and there this segment intersects with the small circle.
14534 if (!(c & c0) && (t = intersect(point1, point0, true))) {
14535 _clean = 0;
14536 if (smallRadius) {
14537 stream.lineStart();
14538 stream.point(t[0][0], t[0][1]);
14539 stream.point(t[1][0], t[1][1]);
14540 stream.lineEnd();
14541 } else {
14542 stream.point(t[1][0], t[1][1]);
14543 stream.lineEnd();
14544 stream.lineStart();
14545 stream.point(t[0][0], t[0][1]);
14546 }
14547 }
14548 }
14549 if (v && (!point0 || !pointEqual(point0, point1))) {
14550 stream.point(point1[0], point1[1]);
14551 }
14552 point0 = point1, v0 = v, c0 = c;
14553 },
14554 lineEnd: function lineEnd() {
14555 if (v0) stream.lineEnd();
14556 point0 = null;
14557 },
14558 // Rejoin first and last segments if there were intersections and the first
14559 // and last points were visible.
14560 clean: function clean() {
14561 return _clean | (v00 && v0) << 1;
14562 }
14563 };
14564 }
14565
14566 // Intersects the great circle between a and b with the clip circle.
14567 function intersect(a, b, two) {
14568 var pa = cartesian(a),
14569 pb = cartesian(b);
14570
14571 // We have two planes, n1.p = d1 and n2.p = d2.
14572 // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
14573 var n1 = [1, 0, 0],
14574 // normal
14575 n2 = cartesianCross(pa, pb),
14576 n2n2 = cartesianDot(n2, n2),
14577 n1n2 = n2[0],
14578 // cartesianDot(n1, n2),
14579 determinant = n2n2 - n1n2 * n1n2;
14580
14581 // Two polar points.
14582 if (!determinant) return !two && a;
14583
14584 var c1 = cr * n2n2 / determinant,
14585 c2 = -cr * n1n2 / determinant,
14586 n1xn2 = cartesianCross(n1, n2),
14587 A = cartesianScale(n1, c1),
14588 B = cartesianScale(n2, c2);
14589 cartesianAddInPlace(A, B);
14590
14591 // Solve |p(t)|^2 = 1.
14592 var u = n1xn2,
14593 w = cartesianDot(A, u),
14594 uu = cartesianDot(u, u),
14595 t2 = w * w - uu * (cartesianDot(A, A) - 1);
14596
14597 if (t2 < 0) return;
14598
14599 var t = sqrt$1(t2),
14600 q = cartesianScale(u, (-w - t) / uu);
14601 cartesianAddInPlace(q, A);
14602 q = spherical(q);
14603
14604 if (!two) return q;
14605
14606 // Two intersection points.
14607 var lambda0 = a[0],
14608 lambda1 = b[0],
14609 phi0 = a[1],
14610 phi1 = b[1],
14611 z;
14612
14613 if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
14614
14615 var delta = lambda1 - lambda0,
14616 polar = abs(delta - pi$4) < epsilon$4,
14617 meridian = polar || delta < epsilon$4;
14618
14619 if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
14620
14621 // Check that the first point is between a and b.
14622 if (meridian ? polar ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$4 ? phi0 : phi1) : phi0 <= q[1] && q[1] <= phi1 : delta > pi$4 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
14623 var q1 = cartesianScale(u, (-w + t) / uu);
14624 cartesianAddInPlace(q1, A);
14625 return [q, spherical(q1)];
14626 }
14627 }
14628
14629 // Generates a 4-bit vector representing the location of a point relative to
14630 // the small circle's bounding box.
14631 function code(lambda, phi) {
14632 var r = smallRadius ? radius : pi$4 - radius,
14633 code = 0;
14634 if (lambda < -r) code |= 1; // left
14635 else if (lambda > r) code |= 2; // right
14636 if (phi < -r) code |= 4; // below
14637 else if (phi > r) code |= 8; // above
14638 return code;
14639 }
14640
14641 return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$4, radius - pi$4]);
14642};
14643
14644var transform$1 = function (methods) {
14645 return {
14646 stream: transformer(methods)
14647 };
14648};
14649
14650function transformer(methods) {
14651 return function (stream) {
14652 var s = new TransformStream();
14653 for (var key in methods) {
14654 s[key] = methods[key];
14655 }s.stream = stream;
14656 return s;
14657 };
14658}
14659
14660function TransformStream() {}
14661
14662TransformStream.prototype = {
14663 constructor: TransformStream,
14664 point: function point(x, y) {
14665 this.stream.point(x, y);
14666 },
14667 sphere: function sphere() {
14668 this.stream.sphere();
14669 },
14670 lineStart: function lineStart() {
14671 this.stream.lineStart();
14672 },
14673 lineEnd: function lineEnd() {
14674 this.stream.lineEnd();
14675 },
14676 polygonStart: function polygonStart() {
14677 this.stream.polygonStart();
14678 },
14679 polygonEnd: function polygonEnd() {
14680 this.stream.polygonEnd();
14681 }
14682};
14683
14684function fitExtent$1(projection, extent, object) {
14685 var w = extent[1][0] - extent[0][0],
14686 h = extent[1][1] - extent[0][1],
14687 clip = projection.clipExtent && projection.clipExtent();
14688
14689 projection.scale(150).translate([0, 0]);
14690
14691 if (clip != null) projection.clipExtent(null);
14692
14693 geoStream(object, projection.stream(boundsStream$1));
14694
14695 var b = boundsStream$1.result(),
14696 k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
14697 x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
14698 y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
14699
14700 if (clip != null) projection.clipExtent(clip);
14701
14702 return projection.scale(k * 150).translate([x, y]);
14703}
14704
14705function fitSize$1(projection, size, object) {
14706 return fitExtent$1(projection, [[0, 0], size], object);
14707}
14708
14709var maxDepth = 16;
14710var cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
14711
14712var resample = function (project, delta2) {
14713 return +delta2 ? resample$1(project, delta2) : resampleNone(project);
14714};
14715
14716function resampleNone(project) {
14717 return transformer({
14718 point: function point(x, y) {
14719 x = project(x, y);
14720 this.stream.point(x[0], x[1]);
14721 }
14722 });
14723}
14724
14725function resample$1(project, delta2) {
14726
14727 function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
14728 var dx = x1 - x0,
14729 dy = y1 - y0,
14730 d2 = dx * dx + dy * dy;
14731 if (d2 > 4 * delta2 && depth--) {
14732 var a = a0 + a1,
14733 b = b0 + b1,
14734 c = c0 + c1,
14735 m = sqrt$1(a * a + b * b + c * c),
14736 phi2 = asin$1(c /= m),
14737 lambda2 = abs(abs(c) - 1) < epsilon$4 || abs(lambda0 - lambda1) < epsilon$4 ? (lambda0 + lambda1) / 2 : atan2(b, a),
14738 p = project(lambda2, phi2),
14739 x2 = p[0],
14740 y2 = p[1],
14741 dx2 = x2 - x0,
14742 dy2 = y2 - y0,
14743 dz = dy * dx2 - dx * dy2;
14744 if (dz * dz / d2 > delta2 // perpendicular projected distance
14745 || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
14746 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
14747 // angular distance
14748 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
14749 stream.point(x2, y2);
14750 resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
14751 }
14752 }
14753 }
14754 return function (stream) {
14755 var lambda00, x00, y00, a00, b00, c00, // first point
14756 lambda0, x0, y0, a0, b0, c0; // previous point
14757
14758 var resampleStream = {
14759 point: point,
14760 lineStart: lineStart,
14761 lineEnd: lineEnd,
14762 polygonStart: function polygonStart() {
14763 stream.polygonStart();resampleStream.lineStart = ringStart;
14764 },
14765 polygonEnd: function polygonEnd() {
14766 stream.polygonEnd();resampleStream.lineStart = lineStart;
14767 }
14768 };
14769
14770 function point(x, y) {
14771 x = project(x, y);
14772 stream.point(x[0], x[1]);
14773 }
14774
14775 function lineStart() {
14776 x0 = NaN;
14777 resampleStream.point = linePoint;
14778 stream.lineStart();
14779 }
14780
14781 function linePoint(lambda, phi) {
14782 var c = cartesian([lambda, phi]),
14783 p = project(lambda, phi);
14784 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);
14785 stream.point(x0, y0);
14786 }
14787
14788 function lineEnd() {
14789 resampleStream.point = point;
14790 stream.lineEnd();
14791 }
14792
14793 function ringStart() {
14794 lineStart();
14795 resampleStream.point = ringPoint;
14796 resampleStream.lineEnd = ringEnd;
14797 }
14798
14799 function ringPoint(lambda, phi) {
14800 linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
14801 resampleStream.point = linePoint;
14802 }
14803
14804 function ringEnd() {
14805 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
14806 resampleStream.lineEnd = lineEnd;
14807 lineEnd();
14808 }
14809
14810 return resampleStream;
14811 };
14812}
14813
14814var transformRadians = transformer({
14815 point: function point(x, y) {
14816 this.stream.point(x * radians, y * radians);
14817 }
14818});
14819
14820function projection(project) {
14821 return projectionMutator(function () {
14822 return project;
14823 })();
14824}
14825
14826function projectionMutator(projectAt) {
14827 var project,
14828 k = 150,
14829 // scale
14830 x = 480,
14831 y = 250,
14832 // translate
14833 dx,
14834 dy,
14835 lambda = 0,
14836 phi = 0,
14837 // center
14838 deltaLambda = 0,
14839 deltaPhi = 0,
14840 deltaGamma = 0,
14841 rotate,
14842 projectRotate,
14843 // rotate
14844 theta = null,
14845 preclip = clipAntimeridian,
14846 // clip angle
14847 x0 = null,
14848 y0,
14849 x1,
14850 y1,
14851 postclip = identity$7,
14852 // clip extent
14853 delta2 = 0.5,
14854 projectResample = resample(projectTransform, delta2),
14855 // precision
14856 cache,
14857 cacheStream;
14858
14859 function projection(point) {
14860 point = projectRotate(point[0] * radians, point[1] * radians);
14861 return [point[0] * k + dx, dy - point[1] * k];
14862 }
14863
14864 function invert(point) {
14865 point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
14866 return point && [point[0] * degrees$1, point[1] * degrees$1];
14867 }
14868
14869 function projectTransform(x, y) {
14870 return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
14871 }
14872
14873 projection.stream = function (stream) {
14874 return cache && cacheStream === stream ? cache : cache = transformRadians(preclip(rotate, projectResample(postclip(cacheStream = stream))));
14875 };
14876
14877 projection.clipAngle = function (_) {
14878 return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians, 6 * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
14879 };
14880
14881 projection.clipExtent = function (_) {
14882 return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$7) : clipExtent$1(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
14883 };
14884
14885 projection.scale = function (_) {
14886 return arguments.length ? (k = +_, recenter()) : k;
14887 };
14888
14889 projection.translate = function (_) {
14890 return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
14891 };
14892
14893 projection.center = function (_) {
14894 return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
14895 };
14896
14897 projection.rotate = function (_) {
14898 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];
14899 };
14900
14901 projection.precision = function (_) {
14902 return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$1(delta2);
14903 };
14904
14905 projection.fitExtent = function (extent, object) {
14906 return fitExtent$1(projection, extent, object);
14907 };
14908
14909 projection.fitSize = function (size, object) {
14910 return fitSize$1(projection, size, object);
14911 };
14912
14913 function recenter() {
14914 projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
14915 var center = project(lambda, phi);
14916 dx = x - center[0] * k;
14917 dy = y + center[1] * k;
14918 return reset();
14919 }
14920
14921 function reset() {
14922 cache = cacheStream = null;
14923 return projection;
14924 }
14925
14926 return function () {
14927 project = projectAt.apply(this, arguments);
14928 projection.invert = project.invert && invert;
14929 return recenter();
14930 };
14931}
14932
14933function conicProjection(projectAt) {
14934 var phi0 = 0,
14935 phi1 = pi$4 / 3,
14936 m = projectionMutator(projectAt),
14937 p = m(phi0, phi1);
14938
14939 p.parallels = function (_) {
14940 return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
14941 };
14942
14943 return p;
14944}
14945
14946function cylindricalEqualAreaRaw(phi0) {
14947 var cosPhi0 = cos$1(phi0);
14948
14949 function forward(lambda, phi) {
14950 return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
14951 }
14952
14953 forward.invert = function (x, y) {
14954 return [x / cosPhi0, asin$1(y * cosPhi0)];
14955 };
14956
14957 return forward;
14958}
14959
14960function conicEqualAreaRaw(y0, y1) {
14961 var sy0 = sin$1(y0),
14962 n = (sy0 + sin$1(y1)) / 2;
14963
14964 // Are the parallels symmetrical around the Equator?
14965 if (abs(n) < epsilon$4) return cylindricalEqualAreaRaw(y0);
14966
14967 var c = 1 + sy0 * (2 * n - sy0),
14968 r0 = sqrt$1(c) / n;
14969
14970 function project(x, y) {
14971 var r = sqrt$1(c - 2 * n * sin$1(y)) / n;
14972 return [r * sin$1(x *= n), r0 - r * cos$1(x)];
14973 }
14974
14975 project.invert = function (x, y) {
14976 var r0y = r0 - y;
14977 return [atan2(x, abs(r0y)) / n * sign$1(r0y), asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
14978 };
14979
14980 return project;
14981}
14982
14983var conicEqualArea = function () {
14984 return conicProjection(conicEqualAreaRaw).scale(155.424).center([0, 33.6442]);
14985};
14986
14987var albers = function () {
14988 return conicEqualArea().parallels([29.5, 45.5]).scale(1070).translate([480, 250]).rotate([96, 0]).center([-0.6, 38.7]);
14989};
14990
14991// The projections must have mutually exclusive clip regions on the sphere,
14992// as this will avoid emitting interleaving lines and polygons.
14993function multiplex(streams) {
14994 var n = streams.length;
14995 return {
14996 point: function point(x, y) {
14997 var i = -1;while (++i < n) {
14998 streams[i].point(x, y);
14999 }
15000 },
15001 sphere: function sphere() {
15002 var i = -1;while (++i < n) {
15003 streams[i].sphere();
15004 }
15005 },
15006 lineStart: function lineStart() {
15007 var i = -1;while (++i < n) {
15008 streams[i].lineStart();
15009 }
15010 },
15011 lineEnd: function lineEnd() {
15012 var i = -1;while (++i < n) {
15013 streams[i].lineEnd();
15014 }
15015 },
15016 polygonStart: function polygonStart() {
15017 var i = -1;while (++i < n) {
15018 streams[i].polygonStart();
15019 }
15020 },
15021 polygonEnd: function polygonEnd() {
15022 var i = -1;while (++i < n) {
15023 streams[i].polygonEnd();
15024 }
15025 }
15026 };
15027}
15028
15029// A composite projection for the United States, configured by default for
15030// 960×500. The projection also works quite well at 960×600 if you change the
15031// scale to 1285 and adjust the translate accordingly. The set of standard
15032// parallels for each region comes from USGS, which is published here:
15033// http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
15034var albersUsa = function () {
15035 var cache,
15036 cacheStream,
15037 lower48 = albers(),
15038 lower48Point,
15039 alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]),
15040 alaskaPoint,
15041 // EPSG:3338
15042 hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]),
15043 hawaiiPoint,
15044 // ESRI:102007
15045 _point,
15046 pointStream = { point: function point(x, y) {
15047 _point = [x, y];
15048 } };
15049
15050 function albersUsa(coordinates) {
15051 var x = coordinates[0],
15052 y = coordinates[1];
15053 return _point = null, (lower48Point.point(x, y), _point) || (alaskaPoint.point(x, y), _point) || (hawaiiPoint.point(x, y), _point);
15054 }
15055
15056 albersUsa.invert = function (coordinates) {
15057 var k = lower48.scale(),
15058 t = lower48.translate(),
15059 x = (coordinates[0] - t[0]) / k,
15060 y = (coordinates[1] - t[1]) / k;
15061 return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii : lower48).invert(coordinates);
15062 };
15063
15064 albersUsa.stream = function (stream) {
15065 return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
15066 };
15067
15068 albersUsa.precision = function (_) {
15069 if (!arguments.length) return lower48.precision();
15070 lower48.precision(_), alaska.precision(_), hawaii.precision(_);
15071 return reset();
15072 };
15073
15074 albersUsa.scale = function (_) {
15075 if (!arguments.length) return lower48.scale();
15076 lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
15077 return albersUsa.translate(lower48.translate());
15078 };
15079
15080 albersUsa.translate = function (_) {
15081 if (!arguments.length) return lower48.translate();
15082 var k = lower48.scale(),
15083 x = +_[0],
15084 y = +_[1];
15085
15086 lower48Point = lower48.translate(_).clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]]).stream(pointStream);
15087
15088 alaskaPoint = alaska.translate([x - 0.307 * k, y + 0.201 * k]).clipExtent([[x - 0.425 * k + epsilon$4, y + 0.120 * k + epsilon$4], [x - 0.214 * k - epsilon$4, y + 0.234 * k - epsilon$4]]).stream(pointStream);
15089
15090 hawaiiPoint = hawaii.translate([x - 0.205 * k, y + 0.212 * k]).clipExtent([[x - 0.214 * k + epsilon$4, y + 0.166 * k + epsilon$4], [x - 0.115 * k - epsilon$4, y + 0.234 * k - epsilon$4]]).stream(pointStream);
15091
15092 return reset();
15093 };
15094
15095 albersUsa.fitExtent = function (extent, object) {
15096 return fitExtent$1(albersUsa, extent, object);
15097 };
15098
15099 albersUsa.fitSize = function (size, object) {
15100 return fitSize$1(albersUsa, size, object);
15101 };
15102
15103 function reset() {
15104 cache = cacheStream = null;
15105 return albersUsa;
15106 }
15107
15108 return albersUsa.scale(1070);
15109};
15110
15111function azimuthalRaw(scale) {
15112 return function (x, y) {
15113 var cx = cos$1(x),
15114 cy = cos$1(y),
15115 k = scale(cx * cy);
15116 return [k * cy * sin$1(x), k * sin$1(y)];
15117 };
15118}
15119
15120function azimuthalInvert(angle) {
15121 return function (x, y) {
15122 var z = sqrt$1(x * x + y * y),
15123 c = angle(z),
15124 sc = sin$1(c),
15125 cc = cos$1(c);
15126 return [atan2(x * sc, z * cc), asin$1(z && y * sc / z)];
15127 };
15128}
15129
15130var azimuthalEqualAreaRaw = azimuthalRaw(function (cxcy) {
15131 return sqrt$1(2 / (1 + cxcy));
15132});
15133
15134azimuthalEqualAreaRaw.invert = azimuthalInvert(function (z) {
15135 return 2 * asin$1(z / 2);
15136});
15137
15138var azimuthalEqualArea = function () {
15139 return projection(azimuthalEqualAreaRaw).scale(124.75).clipAngle(180 - 1e-3);
15140};
15141
15142var azimuthalEquidistantRaw = azimuthalRaw(function (c) {
15143 return (c = acos(c)) && c / sin$1(c);
15144});
15145
15146azimuthalEquidistantRaw.invert = azimuthalInvert(function (z) {
15147 return z;
15148});
15149
15150var azimuthalEquidistant = function () {
15151 return projection(azimuthalEquidistantRaw).scale(79.4188).clipAngle(180 - 1e-3);
15152};
15153
15154function mercatorRaw(lambda, phi) {
15155 return [lambda, log$1(tan((halfPi$3 + phi) / 2))];
15156}
15157
15158mercatorRaw.invert = function (x, y) {
15159 return [x, 2 * atan(exp(y)) - halfPi$3];
15160};
15161
15162var mercator = function () {
15163 return mercatorProjection(mercatorRaw).scale(961 / tau$4);
15164};
15165
15166function mercatorProjection(project) {
15167 var m = projection(project),
15168 scale = m.scale,
15169 translate = m.translate,
15170 clipExtent = m.clipExtent,
15171 clipAuto;
15172
15173 m.scale = function (_) {
15174 return arguments.length ? (scale(_), clipAuto && m.clipExtent(null), m) : scale();
15175 };
15176
15177 m.translate = function (_) {
15178 return arguments.length ? (translate(_), clipAuto && m.clipExtent(null), m) : translate();
15179 };
15180
15181 m.clipExtent = function (_) {
15182 if (!arguments.length) return clipAuto ? null : clipExtent();
15183 if (clipAuto = _ == null) {
15184 var k = pi$4 * scale(),
15185 t = translate();
15186 _ = [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]];
15187 }
15188 clipExtent(_);
15189 return m;
15190 };
15191
15192 return m.clipExtent(null);
15193}
15194
15195function tany(y) {
15196 return tan((halfPi$3 + y) / 2);
15197}
15198
15199function conicConformalRaw(y0, y1) {
15200 var cy0 = cos$1(y0),
15201 n = y0 === y1 ? sin$1(y0) : log$1(cy0 / cos$1(y1)) / log$1(tany(y1) / tany(y0)),
15202 f = cy0 * pow$1(tany(y0), n) / n;
15203
15204 if (!n) return mercatorRaw;
15205
15206 function project(x, y) {
15207 if (f > 0) {
15208 if (y < -halfPi$3 + epsilon$4) y = -halfPi$3 + epsilon$4;
15209 } else {
15210 if (y > halfPi$3 - epsilon$4) y = halfPi$3 - epsilon$4;
15211 }
15212 var r = f / pow$1(tany(y), n);
15213 return [r * sin$1(n * x), f - r * cos$1(n * x)];
15214 }
15215
15216 project.invert = function (x, y) {
15217 var fy = f - y,
15218 r = sign$1(n) * sqrt$1(x * x + fy * fy);
15219 return [atan2(x, abs(fy)) / n * sign$1(fy), 2 * atan(pow$1(f / r, 1 / n)) - halfPi$3];
15220 };
15221
15222 return project;
15223}
15224
15225var conicConformal = function () {
15226 return conicProjection(conicConformalRaw).scale(109.5).parallels([30, 30]);
15227};
15228
15229function equirectangularRaw(lambda, phi) {
15230 return [lambda, phi];
15231}
15232
15233equirectangularRaw.invert = equirectangularRaw;
15234
15235var equirectangular = function () {
15236 return projection(equirectangularRaw).scale(152.63);
15237};
15238
15239function conicEquidistantRaw(y0, y1) {
15240 var cy0 = cos$1(y0),
15241 n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
15242 g = cy0 / n + y0;
15243
15244 if (abs(n) < epsilon$4) return equirectangularRaw;
15245
15246 function project(x, y) {
15247 var gy = g - y,
15248 nx = n * x;
15249 return [gy * sin$1(nx), g - gy * cos$1(nx)];
15250 }
15251
15252 project.invert = function (x, y) {
15253 var gy = g - y;
15254 return [atan2(x, abs(gy)) / n * sign$1(gy), g - sign$1(n) * sqrt$1(x * x + gy * gy)];
15255 };
15256
15257 return project;
15258}
15259
15260var conicEquidistant = function () {
15261 return conicProjection(conicEquidistantRaw).scale(131.154).center([0, 13.9389]);
15262};
15263
15264function gnomonicRaw(x, y) {
15265 var cy = cos$1(y),
15266 k = cos$1(x) * cy;
15267 return [cy * sin$1(x) / k, sin$1(y) / k];
15268}
15269
15270gnomonicRaw.invert = azimuthalInvert(atan);
15271
15272var gnomonic = function () {
15273 return projection(gnomonicRaw).scale(144.049).clipAngle(60);
15274};
15275
15276function scaleTranslate(kx, ky, tx, ty) {
15277 return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$7 : transformer({
15278 point: function point(x, y) {
15279 this.stream.point(x * kx + tx, y * ky + ty);
15280 }
15281 });
15282}
15283
15284var identity$8 = function () {
15285 var k = 1,
15286 tx = 0,
15287 ty = 0,
15288 sx = 1,
15289 sy = 1,
15290 transform = identity$7,
15291 // scale, translate and reflect
15292 x0 = null,
15293 y0,
15294 x1,
15295 y1,
15296 clip = identity$7,
15297 // clip extent
15298 cache,
15299 cacheStream,
15300 projection;
15301
15302 function reset() {
15303 cache = cacheStream = null;
15304 return projection;
15305 }
15306
15307 return projection = {
15308 stream: function stream(_stream) {
15309 return cache && cacheStream === _stream ? cache : cache = transform(clip(cacheStream = _stream));
15310 },
15311 clipExtent: function clipExtent(_) {
15312 return arguments.length ? (clip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$7) : clipExtent$1(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
15313 },
15314 scale: function scale(_) {
15315 return arguments.length ? (transform = scaleTranslate((k = +_) * sx, k * sy, tx, ty), reset()) : k;
15316 },
15317 translate: function translate(_) {
15318 return arguments.length ? (transform = scaleTranslate(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
15319 },
15320 reflectX: function reflectX(_) {
15321 return arguments.length ? (transform = scaleTranslate(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
15322 },
15323 reflectY: function reflectY(_) {
15324 return arguments.length ? (transform = scaleTranslate(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
15325 },
15326 fitExtent: function fitExtent(extent, object) {
15327 return fitExtent$1(projection, extent, object);
15328 },
15329 fitSize: function fitSize(size, object) {
15330 return fitSize$1(projection, size, object);
15331 }
15332 };
15333};
15334
15335function orthographicRaw(x, y) {
15336 return [cos$1(y) * sin$1(x), sin$1(y)];
15337}
15338
15339orthographicRaw.invert = azimuthalInvert(asin$1);
15340
15341var orthographic = function () {
15342 return projection(orthographicRaw).scale(249.5).clipAngle(90 + epsilon$4);
15343};
15344
15345function stereographicRaw(x, y) {
15346 var cy = cos$1(y),
15347 k = 1 + cos$1(x) * cy;
15348 return [cy * sin$1(x) / k, sin$1(y) / k];
15349}
15350
15351stereographicRaw.invert = azimuthalInvert(function (z) {
15352 return 2 * atan(z);
15353});
15354
15355var stereographic = function () {
15356 return projection(stereographicRaw).scale(250).clipAngle(142);
15357};
15358
15359function transverseMercatorRaw(lambda, phi) {
15360 return [log$1(tan((halfPi$3 + phi) / 2)), -lambda];
15361}
15362
15363transverseMercatorRaw.invert = function (x, y) {
15364 return [-y, 2 * atan(exp(x)) - halfPi$3];
15365};
15366
15367var transverseMercator = function () {
15368 var m = mercatorProjection(transverseMercatorRaw),
15369 center = m.center,
15370 rotate = m.rotate;
15371
15372 m.center = function (_) {
15373 return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
15374 };
15375
15376 m.rotate = function (_) {
15377 return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
15378 };
15379
15380 return rotate([0, 0, 90]).scale(159.155);
15381};
15382
15383var ostring = Object.prototype.toString;
15384var inBrowser = typeof window !== 'undefined' && ostring.call(window) !== '[object Object]';
15385
15386var logger = inBrowser ? window.console : require('console');
15387
15388// From https://github.com/sindresorhus/object-assign
15389// The MIT License (MIT)
15390//
15391// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
15392var hasOwnProperty = Object.prototype.hasOwnProperty;
15393var propIsEnumerable = Object.prototype.propertyIsEnumerable;
15394
15395var assign = assign$1();
15396
15397function toObject(val) {
15398 if (val === null || val === undefined) {
15399 throw new TypeError('Object.assign cannot be called with null or undefined');
15400 }
15401
15402 return Object(val);
15403}
15404
15405function shouldUseNative() {
15406 try {
15407 if (!Object.assign) {
15408 return false;
15409 }
15410
15411 // Detect buggy property enumeration order in older V8 versions.
15412
15413 // https://bugs.chromium.org/p/v8/issues/detail?id=4118
15414 var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
15415 test1[5] = 'de';
15416 if (Object.getOwnPropertyNames(test1)[0] === '5') {
15417 return false;
15418 }
15419
15420 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
15421 var test2 = {};
15422 for (var i = 0; i < 10; i++) {
15423 test2['_' + String.fromCharCode(i)] = i;
15424 }
15425 var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
15426 return test2[n];
15427 });
15428 if (order2.join('') !== '0123456789') {
15429 return false;
15430 }
15431
15432 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
15433 var test3 = {};
15434 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
15435 test3[letter] = letter;
15436 });
15437 if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
15438 return false;
15439 }
15440
15441 return true;
15442 } catch (err) {
15443 // We don't expect any of the above to throw, but better to be safe.
15444 return false;
15445 }
15446}
15447
15448function assign$1() {
15449 return shouldUseNative() ? Object.assign : function (target) {
15450 var from;
15451 var to = toObject(target);
15452 var symbols;
15453
15454 for (var s = 1; s < arguments.length; s++) {
15455 from = Object(arguments[s]);
15456
15457 for (var key in from) {
15458 if (hasOwnProperty.call(from, key)) {
15459 to[key] = from[key];
15460 }
15461 }
15462
15463 if (Object.getOwnPropertySymbols) {
15464 symbols = Object.getOwnPropertySymbols(from);
15465 for (var i = 0; i < symbols.length; i++) {
15466 if (propIsEnumerable.call(from, symbols[i])) {
15467 to[symbols[i]] = from[symbols[i]];
15468 }
15469 }
15470 }
15471 }
15472
15473 return to;
15474 };
15475}
15476
15477// Simulate a WeekMap for now
15478
15479function isObject(value) {
15480 return ostring.call(value) === '[object Object]';
15481}
15482
15483function isString(value) {
15484 return ostring.call(value) === '[object String]';
15485}
15486
15487function isFunction(value) {
15488 return ostring.call(value) === '[object Function]';
15489}
15490
15491function isArray(value) {
15492 return ostring.call(value) === '[object Array]';
15493}
15494
15495
15496
15497
15498
15499function isPromise(value) {
15500 return ostring.call(value) === '[object Promise]';
15501}
15502
15503var pop$1 = function (obj, prop) {
15504 var value = void 0;
15505 if (isObject(obj)) {
15506 value = obj[prop];
15507 delete obj[prop];
15508 return value;
15509 } else if (isArray(obj)) {
15510 var index = +prop;
15511 if (index === index) return obj.splice(index, 1)[0];
15512 value = obj[prop];
15513 delete obj[prop];
15514 return value;
15515 }
15516};
15517
15518var prefix$1 = "$";
15519
15520function Map$1() {
15521 this._array = [];
15522}
15523
15524Map$1.prototype = map$4.prototype = {
15525 constructor: Map$1,
15526
15527 size: function size() {
15528 return this._array.length;
15529 },
15530 get: function get(key) {
15531 return this[prefix$1 + key];
15532 },
15533 set: function set(key, value) {
15534 if (!this.has(key)) this._array.push(key);
15535 this[prefix$1 + key] = value;
15536 return this;
15537 },
15538 has: function has(key) {
15539 return prefix$1 + key in this;
15540 },
15541 clear: function clear() {
15542 var self = this;
15543 this.each(function (_, property) {
15544 delete self[prefix$1 + property];
15545 });
15546 this._array.splice(0);
15547 },
15548 keys: function keys() {
15549 var entries = [];
15550 this.each(function (_, key) {
15551 entries.push(key);
15552 });
15553 return entries;
15554 },
15555 values: function values() {
15556 var entries = [];
15557 this.each(function (v) {
15558 entries.push(v);
15559 });
15560 return entries;
15561 },
15562 each: function each(callback) {
15563 var a = this._array,
15564 key;
15565 for (var i = 0; i < a.length; ++i) {
15566 key = a[i];
15567 callback(this.get(key), key, i);
15568 }
15569 }
15570};
15571
15572function map$4(object, f) {
15573 var map = new Map$1();
15574
15575 // Copy constructor.
15576 if (object instanceof Map$1) object.each(function (value, key) {
15577 map.set(key, value);
15578 });
15579
15580 // Index array by numeric index or specified key function.
15581 else if (Array.isArray(object)) {
15582 var i = -1,
15583 n = object.length,
15584 o;
15585 if (f == null) while (++i < n) {
15586 map.set(i, object[i]);
15587 } else while (++i < n) {
15588 map.set(f(o = object[i], i, object), o);
15589 }
15590 }
15591
15592 // Convert object to map.
15593 else if (object) for (var key in object) {
15594 map.set(key, object[key]);
15595 }return map;
15596}
15597
15598// Code originally from https://github.com/soney/jsep
15599// Copyright (c) 2013 Stephen Oney, http://jsep.from.so/
15600
15601// This is the full set of types that any JSEP node can be.
15602// Store them here to save space when minified
15603var code = {
15604 COMPOUND: 'Compound',
15605 IDENTIFIER: 'Identifier',
15606 MEMBER_EXP: 'MemberExpression',
15607 LITERAL: 'Literal',
15608 THIS_EXP: 'ThisExpression',
15609 CALL_EXP: 'CallExpression',
15610 UNARY_EXP: 'UnaryExpression',
15611 BINARY_EXP: 'BinaryExpression',
15612 LOGICAL_EXP: 'LogicalExpression',
15613 CONDITIONAL_EXP: 'ConditionalExpression',
15614 ARRAY_EXP: 'ArrayExpression'
15615};
15616
15617var PERIOD_CODE = 46;
15618var COMMA_CODE = 44;
15619var SQUOTE_CODE = 39;
15620var DQUOTE_CODE = 34;
15621var OPAREN_CODE = 40;
15622var CPAREN_CODE = 41;
15623var OBRACK_CODE = 91;
15624var CBRACK_CODE = 93;
15625var QUMARK_CODE = 63;
15626var SEMCOL_CODE = 59;
15627var COLON_CODE = 58;
15628var throwError = function throwError(message, index) {
15629 var error = new Error(message + ' at character ' + index);
15630 error.index = index;
15631 error.description = message;
15632 throw error;
15633};
15634var t = true;
15635var unary_ops = { '-': t, '!': t, '~': t, '+': t };
15636var binary_ops = {
15637 '||': 1, '&&': 2, '|': 3, '^': 4, '&': 5,
15638 '==': 6, '!=': 6, '===': 6, '!==': 6,
15639 '<': 7, '>': 7, '<=': 7, '>=': 7,
15640 '<<': 8, '>>': 8, '>>>': 8,
15641 '+': 9, '-': 9,
15642 '*': 10, '/': 10, '%': 10
15643};
15644var getMaxKeyLen = function getMaxKeyLen(obj) {
15645 var max_len = 0,
15646 len;
15647 for (var key in obj) {
15648 if ((len = key.length) > max_len && obj.hasOwnProperty(key)) {
15649 max_len = len;
15650 }
15651 }
15652 return max_len;
15653};
15654var max_unop_len = getMaxKeyLen(unary_ops);
15655var max_binop_len = getMaxKeyLen(binary_ops);
15656var literals = {
15657 'true': true,
15658 'false': false,
15659 'null': null
15660};
15661var this_str = 'this';
15662var binaryPrecedence = function binaryPrecedence(op_val) {
15663 return binary_ops[op_val] || 0;
15664};
15665var createBinaryExpression = function createBinaryExpression(operator, left, right) {
15666 var type = operator === '||' || operator === '&&' ? code.LOGICAL_EXP : code.BINARY_EXP;
15667 return {
15668 type: type,
15669 operator: operator,
15670 left: left,
15671 right: right
15672 };
15673};
15674var isDecimalDigit = function isDecimalDigit(ch) {
15675 return ch >= 48 && ch <= 57; // 0...9
15676};
15677var isIdentifierStart = function isIdentifierStart(ch) {
15678 return ch === 36 || ch === 95 || // `$` and `_`
15679 ch >= 65 && ch <= 90 || // A...Z
15680 ch >= 97 && ch <= 122 || // a...z
15681 ch >= 128 && !binary_ops[String.fromCharCode(ch)]; // any non-ASCII that is not an operator
15682};
15683var isIdentifierPart = function isIdentifierPart(ch) {
15684 return ch === 36 || ch === 95 || // `$` and `_`
15685 ch >= 65 && ch <= 90 || // A...Z
15686 ch >= 97 && ch <= 122 || // a...z
15687 ch >= 48 && ch <= 57 || // 0...9
15688 ch >= 128 && !binary_ops[String.fromCharCode(ch)]; // any non-ASCII that is not an operator
15689};
15690var jsep = function jsep(expr) {
15691 // `index` stores the character number we are currently at while `length` is a constant
15692 // All of the gobbles below will modify `index` as we move along
15693 var index = 0,
15694 charAtFunc = expr.charAt,
15695 charCodeAtFunc = expr.charCodeAt,
15696 exprI = function exprI(i) {
15697 return charAtFunc.call(expr, i);
15698 },
15699 exprICode = function exprICode(i) {
15700 return charCodeAtFunc.call(expr, i);
15701 },
15702 length = expr.length,
15703
15704
15705 // Push `index` up to the next non-space character
15706 gobbleSpaces = function gobbleSpaces() {
15707 var ch = exprICode(index);
15708 // space or tab
15709 while (ch === 32 || ch === 9) {
15710 ch = exprICode(++index);
15711 }
15712 },
15713
15714
15715 // The main parsing function. Much of this code is dedicated to ternary expressions
15716 gobbleExpression = function gobbleExpression() {
15717 var test = gobbleBinaryExpression(),
15718 consequent,
15719 alternate;
15720 gobbleSpaces();
15721 if (exprICode(index) === QUMARK_CODE) {
15722 // Ternary expression: test ? consequent : alternate
15723 index++;
15724 consequent = gobbleExpression();
15725 if (!consequent) {
15726 throwError('Expected expression', index);
15727 }
15728 gobbleSpaces();
15729 if (exprICode(index) === COLON_CODE) {
15730 index++;
15731 alternate = gobbleExpression();
15732 if (!alternate) {
15733 throwError('Expected expression', index);
15734 }
15735 return {
15736 type: code.CONDITIONAL_EXP,
15737 test: test,
15738 consequent: consequent,
15739 alternate: alternate
15740 };
15741 } else {
15742 throwError('Expected :', index);
15743 }
15744 } else {
15745 return test;
15746 }
15747 },
15748
15749
15750 // Search for the operation portion of the string (e.g. `+`, `===`)
15751 // Start by taking the longest possible binary operations (3 characters: `===`, `!==`, `>>>`)
15752 // and move down from 3 to 2 to 1 character until a matching binary operation is found
15753 // then, return that binary operation
15754 gobbleBinaryOp = function gobbleBinaryOp() {
15755 gobbleSpaces();
15756 var to_check = expr.substr(index, max_binop_len),
15757 tc_len = to_check.length;
15758 while (tc_len > 0) {
15759 if (binary_ops.hasOwnProperty(to_check)) {
15760 index += tc_len;
15761 return to_check;
15762 }
15763 to_check = to_check.substr(0, --tc_len);
15764 }
15765 return false;
15766 },
15767
15768
15769 // This function is responsible for gobbling an individual expression,
15770 // e.g. `1`, `1+2`, `a+(b*2)-Math.sqrt(2)`
15771 gobbleBinaryExpression = function gobbleBinaryExpression() {
15772 var node, biop, prec, stack, biop_info, left, right, i;
15773
15774 // First, try to get the leftmost thing
15775 // Then, check to see if there's a binary operator operating on that leftmost thing
15776 left = gobbleToken();
15777 biop = gobbleBinaryOp();
15778
15779 // If there wasn't a binary operator, just return the leftmost node
15780 if (!biop) {
15781 return left;
15782 }
15783
15784 // Otherwise, we need to start a stack to properly place the binary operations in their
15785 // precedence structure
15786 biop_info = { value: biop, prec: binaryPrecedence(biop) };
15787
15788 right = gobbleToken();
15789 if (!right) {
15790 throwError("Expected expression after " + biop, index);
15791 }
15792 stack = [left, biop_info, right];
15793
15794 // Properly deal with precedence using [recursive descent](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm)
15795 while (biop = gobbleBinaryOp()) {
15796 prec = binaryPrecedence(biop);
15797
15798 if (prec === 0) {
15799 break;
15800 }
15801 biop_info = { value: biop, prec: prec };
15802
15803 // Reduce: make a binary expression from the three topmost entries.
15804 while (stack.length > 2 && prec <= stack[stack.length - 2].prec) {
15805 right = stack.pop();
15806 biop = stack.pop().value;
15807 left = stack.pop();
15808 node = createBinaryExpression(biop, left, right);
15809 stack.push(node);
15810 }
15811
15812 node = gobbleToken();
15813 if (!node) {
15814 throwError("Expected expression after " + biop, index);
15815 }
15816 stack.push(biop_info, node);
15817 }
15818
15819 i = stack.length - 1;
15820 node = stack[i];
15821 while (i > 1) {
15822 node = createBinaryExpression(stack[i - 1].value, stack[i - 2], node);
15823 i -= 2;
15824 }
15825 return node;
15826 },
15827
15828
15829 // An individual part of a binary expression:
15830 // e.g. `foo.bar(baz)`, `1`, `"abc"`, `(a % 2)` (because it's in parenthesis)
15831 gobbleToken = function gobbleToken() {
15832 var ch, to_check, tc_len;
15833
15834 gobbleSpaces();
15835 ch = exprICode(index);
15836
15837 if (isDecimalDigit(ch) || ch === PERIOD_CODE) {
15838 // Char code 46 is a dot `.` which can start off a numeric literal
15839 return gobbleNumericLiteral();
15840 } else if (ch === SQUOTE_CODE || ch === DQUOTE_CODE) {
15841 // Single or double quotes
15842 return gobbleStringLiteral();
15843 } else if (isIdentifierStart(ch) || ch === OPAREN_CODE) {
15844 // open parenthesis
15845 // `foo`, `bar.baz`
15846 return gobbleVariable();
15847 } else if (ch === OBRACK_CODE) {
15848 return gobbleArray();
15849 } else {
15850 to_check = expr.substr(index, max_unop_len);
15851 tc_len = to_check.length;
15852 while (tc_len > 0) {
15853 if (unary_ops.hasOwnProperty(to_check)) {
15854 index += tc_len;
15855 return {
15856 type: code.UNARY_EXP,
15857 operator: to_check,
15858 argument: gobbleToken(),
15859 prefix: true
15860 };
15861 }
15862 to_check = to_check.substr(0, --tc_len);
15863 }
15864
15865 return false;
15866 }
15867 },
15868
15869 // Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to
15870 // keep track of everything in the numeric literal and then calling `parseFloat` on that string
15871 gobbleNumericLiteral = function gobbleNumericLiteral() {
15872 var number = '',
15873 ch,
15874 chCode;
15875 while (isDecimalDigit(exprICode(index))) {
15876 number += exprI(index++);
15877 }
15878
15879 if (exprICode(index) === PERIOD_CODE) {
15880 // can start with a decimal marker
15881 number += exprI(index++);
15882
15883 while (isDecimalDigit(exprICode(index))) {
15884 number += exprI(index++);
15885 }
15886 }
15887
15888 ch = exprI(index);
15889 if (ch === 'e' || ch === 'E') {
15890 // exponent marker
15891 number += exprI(index++);
15892 ch = exprI(index);
15893 if (ch === '+' || ch === '-') {
15894 // exponent sign
15895 number += exprI(index++);
15896 }
15897 while (isDecimalDigit(exprICode(index))) {
15898 //exponent itself
15899 number += exprI(index++);
15900 }
15901 if (!isDecimalDigit(exprICode(index - 1))) {
15902 throwError('Expected exponent (' + number + exprI(index) + ')', index);
15903 }
15904 }
15905
15906 chCode = exprICode(index);
15907 // Check to make sure this isn't a variable name that start with a number (123abc)
15908 if (isIdentifierStart(chCode)) {
15909 throwError('Variable names cannot start with a number (' + number + exprI(index) + ')', index);
15910 } else if (chCode === PERIOD_CODE) {
15911 throwError('Unexpected period', index);
15912 }
15913
15914 return {
15915 type: code.LITERAL,
15916 value: parseFloat(number),
15917 raw: number
15918 };
15919 },
15920
15921
15922 // Parses a string literal, staring with single or double quotes with basic support for escape codes
15923 // e.g. `"hello world"`, `'this is\nJSEP'`
15924 gobbleStringLiteral = function gobbleStringLiteral() {
15925 var str = '',
15926 quote = exprI(index++),
15927 closed = false,
15928 ch;
15929
15930 while (index < length) {
15931 ch = exprI(index++);
15932 if (ch === quote) {
15933 closed = true;
15934 break;
15935 } else if (ch === '\\') {
15936 // Check for all of the common escape codes
15937 ch = exprI(index++);
15938 switch (ch) {
15939 case 'n':
15940 str += '\n';break;
15941 case 'r':
15942 str += '\r';break;
15943 case 't':
15944 str += '\t';break;
15945 case 'b':
15946 str += '\b';break;
15947 case 'f':
15948 str += '\f';break;
15949 case 'v':
15950 str += '\x0B';break;
15951 default:
15952 str += '\\' + ch;
15953 }
15954 } else {
15955 str += ch;
15956 }
15957 }
15958
15959 if (!closed) {
15960 throwError('Unclosed quote after "' + str + '"', index);
15961 }
15962
15963 return {
15964 type: code.LITERAL,
15965 value: str,
15966 raw: quote + str + quote
15967 };
15968 },
15969
15970
15971 // Gobbles only identifiers
15972 // e.g.: `foo`, `_value`, `$x1`
15973 // Also, this function checks if that identifier is a literal:
15974 // (e.g. `true`, `false`, `null`) or `this`
15975 gobbleIdentifier = function gobbleIdentifier() {
15976 var ch = exprICode(index),
15977 start = index,
15978 identifier;
15979
15980 if (isIdentifierStart(ch)) {
15981 index++;
15982 } else {
15983 throwError('Unexpected ' + exprI(index), index);
15984 }
15985
15986 while (index < length) {
15987 ch = exprICode(index);
15988 if (isIdentifierPart(ch)) {
15989 index++;
15990 } else {
15991 break;
15992 }
15993 }
15994 identifier = expr.slice(start, index);
15995
15996 if (literals.hasOwnProperty(identifier)) {
15997 return {
15998 type: code.LITERAL,
15999 value: literals[identifier],
16000 raw: identifier
16001 };
16002 } else if (identifier === this_str) {
16003 return { type: code.THIS_EXP };
16004 } else {
16005 return {
16006 type: code.IDENTIFIER,
16007 name: identifier
16008 };
16009 }
16010 },
16011
16012
16013 // Gobbles a list of arguments within the context of a function call
16014 // or array literal. This function also assumes that the opening character
16015 // `(` or `[` has already been gobbled, and gobbles expressions and commas
16016 // until the terminator character `)` or `]` is encountered.
16017 // e.g. `foo(bar, baz)`, `my_func()`, or `[bar, baz]`
16018 gobbleArguments = function gobbleArguments(termination) {
16019 var ch_i,
16020 args = [],
16021 node,
16022 closed = false;
16023 while (index < length) {
16024 gobbleSpaces();
16025 ch_i = exprICode(index);
16026 if (ch_i === termination) {
16027 // done parsing
16028 closed = true;
16029 index++;
16030 break;
16031 } else if (ch_i === COMMA_CODE) {
16032 // between expressions
16033 index++;
16034 } else {
16035 node = gobbleExpression();
16036 if (!node || node.type === code.COMPOUND) {
16037 throwError('Expected comma', index);
16038 }
16039 args.push(node);
16040 }
16041 }
16042 if (!closed) {
16043 throwError('Expected ' + String.fromCharCode(termination), index);
16044 }
16045 return args;
16046 },
16047
16048
16049 // Gobble a non-literal variable name. This variable name may include properties
16050 // e.g. `foo`, `bar.baz`, `foo['bar'].baz`
16051 // It also gobbles function calls:
16052 // e.g. `Math.acos(obj.angle)`
16053 gobbleVariable = function gobbleVariable() {
16054 var ch_i, node;
16055 ch_i = exprICode(index);
16056
16057 if (ch_i === OPAREN_CODE) {
16058 node = gobbleGroup();
16059 } else {
16060 node = gobbleIdentifier();
16061 }
16062 gobbleSpaces();
16063 ch_i = exprICode(index);
16064 while (ch_i === PERIOD_CODE || ch_i === OBRACK_CODE || ch_i === OPAREN_CODE) {
16065 index++;
16066 if (ch_i === PERIOD_CODE) {
16067 gobbleSpaces();
16068 node = {
16069 type: code.MEMBER_EXP,
16070 computed: false,
16071 object: node,
16072 property: gobbleIdentifier()
16073 };
16074 } else if (ch_i === OBRACK_CODE) {
16075 node = {
16076 type: code.MEMBER_EXP,
16077 computed: true,
16078 object: node,
16079 property: gobbleExpression()
16080 };
16081 gobbleSpaces();
16082 ch_i = exprICode(index);
16083 if (ch_i !== CBRACK_CODE) {
16084 throwError('Unclosed [', index);
16085 }
16086 index++;
16087 } else if (ch_i === OPAREN_CODE) {
16088 // A function call is being made; gobble all the arguments
16089 node = {
16090 type: code.CALL_EXP,
16091 'arguments': gobbleArguments(CPAREN_CODE),
16092 callee: node
16093 };
16094 }
16095 gobbleSpaces();
16096 ch_i = exprICode(index);
16097 }
16098 return node;
16099 },
16100
16101
16102 // Responsible for parsing a group of things within parentheses `()`
16103 // This function assumes that it needs to gobble the opening parenthesis
16104 // and then tries to gobble everything within that parenthesis, assuming
16105 // that the next thing it should see is the close parenthesis. If not,
16106 // then the expression probably doesn't have a `)`
16107 gobbleGroup = function gobbleGroup() {
16108 index++;
16109 var node = gobbleExpression();
16110 gobbleSpaces();
16111 if (exprICode(index) === CPAREN_CODE) {
16112 index++;
16113 return node;
16114 } else {
16115 throwError('Unclosed (', index);
16116 }
16117 },
16118
16119
16120 // Responsible for parsing Array literals `[1, 2, 3]`
16121 // This function assumes that it needs to gobble the opening bracket
16122 // and then tries to gobble the expressions as arguments.
16123 gobbleArray = function gobbleArray() {
16124 index++;
16125 return {
16126 type: code.ARRAY_EXP,
16127 elements: gobbleArguments(CBRACK_CODE)
16128 };
16129 },
16130 nodes = [],
16131 ch_i,
16132 node;
16133
16134 while (index < length) {
16135 ch_i = exprICode(index);
16136
16137 // Expressions can be separated by semicolons, commas, or just inferred without any
16138 // separators
16139 if (ch_i === SEMCOL_CODE || ch_i === COMMA_CODE) {
16140 index++; // ignore separators
16141 } else {
16142 // Try to gobble each expression individually
16143 if (node = gobbleExpression()) {
16144 nodes.push(node);
16145 // If we weren't able to find a binary expression and are out of room, then
16146 // the expression passed in probably has too much
16147 } else if (index < length) {
16148 throwError('Unexpected "' + exprI(index) + '"', index);
16149 }
16150 }
16151 }
16152
16153 // If there's only one expression just try returning the expression
16154 if (nodes.length === 1) {
16155 return nodes[0];
16156 } else {
16157 return {
16158 type: code.COMPOUND,
16159 body: nodes
16160 };
16161 }
16162};
16163
16164/**
16165 * @method jsep.addUnaryOp
16166 * @param {string} op_name The name of the unary op to add
16167 * @return jsep
16168 */
16169jsep.addUnaryOp = function (op_name) {
16170 max_unop_len = Math.max(op_name.length, max_unop_len);
16171 unary_ops[op_name] = t;return this;
16172};
16173
16174/**
16175 * @method jsep.addBinaryOp
16176 * @param {string} op_name The name of the binary op to add
16177 * @param {number} precedence The precedence of the binary op (can be a float)
16178 * @return jsep
16179 */
16180jsep.addBinaryOp = function (op_name, precedence) {
16181 max_binop_len = Math.max(op_name.length, max_binop_len);
16182 binary_ops[op_name] = precedence;
16183 return this;
16184};
16185
16186/**
16187 * @method jsep.addLiteral
16188 * @param {string} literal_name The name of the literal to add
16189 * @param {*} literal_value The value of the literal
16190 * @return jsep
16191 */
16192jsep.addLiteral = function (literal_name, literal_value) {
16193 literals[literal_name] = literal_value;
16194 return this;
16195};
16196
16197/**
16198 * @method jsep.removeUnaryOp
16199 * @param {string} op_name The name of the unary op to remove
16200 * @return jsep
16201 */
16202jsep.removeUnaryOp = function (op_name) {
16203 delete unary_ops[op_name];
16204 if (op_name.length === max_unop_len) {
16205 max_unop_len = getMaxKeyLen(unary_ops);
16206 }
16207 return this;
16208};
16209
16210/**
16211 * @method jsep.removeBinaryOp
16212 * @param {string} op_name The name of the binary op to remove
16213 * @return jsep
16214 */
16215jsep.removeBinaryOp = function (op_name) {
16216 delete binary_ops[op_name];
16217 if (op_name.length === max_binop_len) {
16218 max_binop_len = getMaxKeyLen(binary_ops);
16219 }
16220 return this;
16221};
16222
16223/**
16224 * @method jsep.removeLiteral
16225 * @param {string} literal_name The name of the literal to remove
16226 * @return jsep
16227 */
16228jsep.removeLiteral = function (literal_name) {
16229 delete literals[literal_name];
16230 return this;
16231};
16232
16233function evaluate(self, expr) {
16234
16235 switch (expr.type) {
16236 case code.IDENTIFIER:
16237 return self[expr.name];
16238 case code.LITERAL:
16239 return expr.value;
16240 case code.ARRAY_EXP:
16241 return expr.elements.map(function (elem) {
16242 return evaluate(self, elem);
16243 });
16244 case code.LOGICAL_EXP:
16245 case code.BINARY_EXP:
16246 return binaryExp(expr.operator, evaluate(self, expr.left), evaluate(self, expr.right));
16247 case code.CALL_EXP:
16248 return callExpression(self, expr.callee, expr.arguments);
16249 case code.MEMBER_EXP:
16250 return evaluate(evaluate(self, expr.object), expr.property);
16251 case code.CONDITIONAL_EXP:
16252 return evaluate(self, expr.test) ? evaluate(self, expr.consequent) : evaluate(self, expr.alternate);
16253 case code.UNARY_EXP:
16254 return unaryExp(expr.operator, evaluate(self, expr.argument));
16255 }
16256}
16257
16258function identifiers$1(expr, all) {
16259 if (arguments.length === 1) all = set$1();
16260 switch (expr.type) {
16261 case code.IDENTIFIER:
16262 all.add(expr.name);break;
16263 case code.ARRAY_EXP:
16264 expr.elements.forEach(function (elem) {
16265 identifiers$1(elem, all);
16266 });break;
16267 case code.BINARY_EXP:
16268 identifiers$1(expr.left, all);identifiers$1(expr.right, all);break;
16269 case code.CALL_EXP:
16270 identifiers$1(expr.arguments, all);break;
16271 case code.MEMBER_EXP:
16272 identifiers$1(expr.object, all);break;
16273 case code.CONDITIONAL_EXP:
16274 identifiers$1(expr.test, all);identifiers$1(expr.consequent, all);evaluate(expr.alternate, all);break;
16275 }
16276 return all;
16277}
16278
16279function callExpression(self, callee, args) {
16280 var func;
16281
16282 args = args.map(function (arg) {
16283 return evaluate(self, arg);
16284 });
16285
16286 if (callee.type !== code.IDENTIFIER) {
16287 self = evaluate(self, callee.object);
16288 callee = callee.property;
16289 }
16290
16291 func = self[callee.name];
16292 return func.apply(self, args);
16293}
16294
16295function unaryExp(op, arg) {
16296 if (!unaryFunctions[op]) unaryFunctions[op] = new Function("arg", 'return ' + op + ' arg');
16297 return unaryFunctions[op](arg);
16298}
16299
16300function binaryExp(op, a, b) {
16301 if (!binaryFunctions[op]) binaryFunctions[op] = new Function("a", "b", 'return a ' + op + ' b');
16302 return binaryFunctions[op](a, b);
16303}
16304
16305var unaryFunctions = {};
16306var binaryFunctions = {};
16307
16308var providers = {
16309 logger: logger,
16310 fetch: fetch()
16311};
16312
16313function fetch() {
16314 if (inBrowser) return window.fetch;
16315}
16316
16317var prefix$2 = '[d3-view]';
16318
16319var warn = function (msg) {
16320 providers.logger.warn(prefix$2 + ' ' + msg);
16321};
16322
16323// tiny javascript expression parser
16324var proto$2 = {
16325
16326 eval: function _eval(model) {
16327 return evaluate(model, this.parsed);
16328 },
16329
16330 safeEval: function safeEval(model) {
16331 try {
16332 return evaluate(model, this.parsed);
16333 } catch (msg) {
16334 warn('Could not evaluate <<' + this.expr + '>> expression: ' + msg);
16335 }
16336 },
16337
16338 identifiers: function identifiers() {
16339 return identifiers$1(this.parsed).values();
16340 }
16341};
16342
16343function Expression(expr) {
16344 this.codes = code;
16345 this.expr = expr;
16346 this.parsed = jsep(expr);
16347}
16348
16349Expression.prototype = proto$2;
16350
16351var viewExpression = function (expr) {
16352 try {
16353 return new Expression(expr);
16354 } catch (msg) {
16355 warn('Could not parse <<' + expr + '>> expression: ' + msg);
16356 }
16357};
16358
16359var UID = 0;
16360
16361// Add a unique identifier to an object
16362var uid = function (o) {
16363 var uid = ++UID;
16364
16365 Object.defineProperty(o, 'uid', {
16366 get: function get() {
16367 return uid;
16368 }
16369 });
16370
16371 return o;
16372};
16373
16374var sel = function (o) {
16375
16376 Object.defineProperty(o, 'sel', {
16377 get: function get() {
16378 return select(this.el);
16379 }
16380 });
16381
16382 return o;
16383};
16384
16385//
16386// Directive Prototype
16387//
16388// Directives are special attributes with the d3- prefix.
16389// Directive attribute values are expected to be binding expressions.
16390// A directive’s job is to reactively apply special behavior to the DOM
16391// when the value of its expression changes.
16392//
16393// A directive can implement one or more of the directive methods:
16394//
16395// * create
16396// * mount
16397// * refresh
16398// * destroy
16399//
16400var prototype = {
16401 priority: 1,
16402
16403 // hooks
16404 create: function create(expression) {
16405 return expression;
16406 },
16407
16408 mount: function mount(model) {
16409 return model;
16410 },
16411
16412 refresh: function refresh() {},
16413
16414 destroy: function destroy() {},
16415
16416 removeAttribute: function removeAttribute() {
16417 this.el.removeAttribute(this.name);
16418 },
16419
16420 // Execute directive
16421 execute: function execute(model) {
16422 var _this = this;
16423
16424 // No binding expression - nothing to do
16425 if (!this.expression) return;
16426 this.removeAttribute();
16427
16428 model = this.mount(model);
16429 // No model returned - abort execution
16430 if (!model) return;
16431
16432 var dir = this,
16433 sel$$1 = this.sel,
16434 refresh = function refresh() {
16435 try {
16436 dir.refresh(model, dir.expression.eval(model));
16437 } catch (msg) {
16438 warn('Error while refreshing "' + dir.name + '" directive: ' + msg);
16439 }
16440 };
16441
16442 // Bind expression identifiers with model
16443 this.identifiers = this.expression.identifiers().map(function (id) {
16444 var event = id + '.' + dir.uid;
16445 model.$on(event, refresh);
16446 return id;
16447 });
16448
16449 sel$$1.on('remove.' + dir.uid, function () {
16450 _this.identifiers.forEach(function (id) {
16451 model.$off(id + '.' + dir.uid);
16452 });
16453 dir.destroy(model);
16454 });
16455
16456 refresh();
16457 }
16458};
16459
16460// Directive constructor
16461var createDirective = function (obj) {
16462
16463 function Directive(el, attr, arg) {
16464 this.el = el;
16465 this.name = attr.name;
16466 this.arg = arg;
16467 var expr = sel(uid(this)).create(attr.value);
16468 if (expr) this.expression = viewExpression(expr);
16469 }
16470
16471 Directive.prototype = assign({}, prototype, obj);
16472
16473 function directive(el, attr, arg) {
16474 return new Directive(el, attr, arg);
16475 }
16476
16477 directive.prototype = Directive.prototype;
16478 return directive;
16479};
16480
16481selection.prototype.model = model$1;
16482
16483var asModel = function (model, initials) {
16484 var events = map$1();
16485
16486 // event handler for any change in the model
16487 events.set('', dispatch('change'));
16488
16489 Object.defineProperty(uid(model), '$events', {
16490 get: function get() {
16491 return events;
16492 }
16493 });
16494 model._Child = null;
16495 model.$update(initials);
16496};
16497
16498
16499
16500function model$1(value) {
16501 return arguments.length ? this.property("__model__", value) : this.node().__model__;
16502}
16503
16504// $get method for an Model
16505//
16506// attribute is a dotted string
16507var $get = function (attribute) {
16508
16509 var bits = attribute.split('.'),
16510 key = bits.splice(0, 1),
16511 model = getModel(this, key);
16512
16513 if (!(key in model)) return;
16514
16515 var value = model[key];
16516
16517 while (value && bits.length) {
16518 value = value[bits.splice(0, 1)];
16519 }return value;
16520};
16521
16522function getModel(model, key) {
16523
16524 while (!(key in model) && model.$parent) {
16525 model = model.$parent;
16526 }return model;
16527}
16528
16529var debounce = function (callback) {
16530 var queued = false;
16531 return function () {
16532 if (!queued) {
16533 var args = Array.prototype.slice.call(arguments);
16534 queued = true;
16535 timeout$1(function () {
16536 queued = false;
16537 callback.apply(undefined, args);
16538 });
16539 }
16540 };
16541};
16542
16543// $set a reactive attribute for a Model
16544//
16545// Set the value of a dotted attribute in the model or its parents
16546// If the attribute is not already reactive make it as such.
16547//
16548var $set = function (key, value) {
16549 // property not reactive - make it as such
16550 if (!this.$events.get(key)) reactive(this, key, value);else this[key] = value;
16551};
16552
16553function reactive(model, key, value) {
16554 var events = model.$events,
16555 oldValue,
16556 lazy;
16557
16558 events.set(key, dispatch('change'));
16559
16560 Object.defineProperty(model, key, property());
16561
16562 // the event is fired at the next tick of the event loop
16563 // Cannot use the () => notation here otherwise arguments are incorrect
16564 var trigger = debounce(function () {
16565 oldValue = arguments[0];
16566 events.get(key).call('change', model, value, oldValue);
16567 // trigger model change event only when not a lazy property
16568 if (!lazy) events.get('').call('change', model, key);
16569 });
16570
16571 // Trigger the callback once for initialization
16572 trigger();
16573
16574 function update(newValue) {
16575 if (lazy) newValue = lazy.get.call(model);
16576 if (newValue === value) return;
16577 // trigger lazy callbacks
16578 trigger(value);
16579 // update the value
16580 value = newValue;
16581 }
16582
16583 function property() {
16584 var prop = {
16585 get: function get() {
16586 return value;
16587 }
16588 };
16589
16590 if (isFunction(value)) value = { get: value };
16591
16592 // calculated attribute
16593 if (isObject(value) && isFunction(value.get)) {
16594 lazy = value;
16595 value = lazy.get.call(model);
16596
16597 if (lazy.reactOn) lazy.reactOn.forEach(function (name) {
16598 model.$on(name + '.' + key, update);
16599 });else model.$on('.' + key, update);
16600
16601 if (isFunction(lazy.set)) prop.set = lazy.set;
16602 } else prop.set = update;
16603
16604 return prop;
16605 }
16606}
16607
16608// Add change callback to a model reactive attribute
16609var $on = function (name, callback) {
16610
16611 // When no name is provided, whait for changes on this model - no its parents
16612 if (arguments.length === 1 && isFunction(name)) {
16613 callback = name;
16614 name = '';
16615 }
16616
16617 var bits = name.split('.'),
16618 key = bits[0],
16619 event = getEvent(this, key);
16620
16621 if (!event) return warn('Cannot bind to "' + key + '" - no such reactive property');
16622
16623 // event from a parent model, add model uid to distinguish it from other child callbacks
16624 if (!this.$events.get(name)) bits.push(this.uid);
16625
16626 bits[0] = 'change';
16627 return event.on(bits.join('.'), callback);
16628};
16629
16630function getEvent(model, name) {
16631 var event = model.$events.get(name);
16632 if (!event && model.parent) return getEvent(model.parent, name);
16633 return event;
16634}
16635
16636// Update a model with reactive model data
16637var $update = function (data) {
16638 if (data) for (var key in data) {
16639 if (key.substring(0, 1) === '$') {
16640 if (this.constructor.prototype[key]) warn('Cannot set attribute method ' + key + ', it is protected');else this[key] = data[key];
16641 } else this.$set(key, data[key]);
16642 }
16643 return this;
16644};
16645
16646// create a child model
16647var $child = function (initials) {
16648 if (!this._Child) this._Child = createChildConstructor(this);
16649
16650 var parent = this,
16651 child = new this._Child(initials);
16652
16653 Object.defineProperty(child, 'parent', {
16654 get: function get() {
16655 return parent;
16656 }
16657 });
16658
16659 return child;
16660};
16661
16662function createChildConstructor(model) {
16663
16664 function Child(initials) {
16665 asModel(this, initials);
16666 }
16667
16668 Child.prototype = model;
16669 return Child;
16670}
16671
16672function setbase(key, value) {
16673 if (!this.$events.has(key) && this.$parent) return setbase.call(this.$parent, key, value);
16674 this.$set(key, value);
16675}
16676
16677//
16678// Model class
16679//
16680// The model is at the core of d3-view reactive data component
16681function Model(initials) {
16682 asModel(this, initials);
16683}
16684
16685function model(initials) {
16686 return new Model(initials);
16687}
16688
16689model.prototype = Model.prototype;
16690
16691// Public API methods
16692Model.prototype.$on = $on;
16693Model.prototype.$update = $update;
16694Model.prototype.$get = $get;
16695Model.prototype.$set = $set;
16696Model.prototype.$child = $child;
16697Model.prototype.$new = $new;
16698Model.prototype.$setbase = setbase;
16699
16700function $new(initials) {
16701
16702 var parent = this,
16703 child = model(initials);
16704
16705 Object.defineProperty(child, 'parent', {
16706 get: function get() {
16707 return parent;
16708 }
16709 });
16710
16711 return child;
16712}
16713
16714// Model factory function
16715var createModel = function (directives, data, parent) {
16716 // model directive
16717 var dir = directives.pop('model');
16718
16719 // For loop directive not permitted in the root view
16720 if (directives.get('for') && !parent) {
16721 warn('Cannot have a "d3-for" directive in the root view element');
16722 directives.pop('for');
16723 }
16724
16725 if (!parent) {
16726 if (dir) warn('Cannot have a d3-model directive in the root element');
16727 return model(data);
16728 }
16729
16730 // Execute model directive
16731 if (dir) {
16732 dir.execute(parent);
16733 var model$$1 = dir.sel.model();
16734 if (model$$1) model$$1.$update(data);
16735 return model$$1;
16736 } else if (data) return parent.$child(data);else return parent;
16737};
16738
16739// No value, it has its own directive
16740var attributes = ['name', 'class', 'disabled', 'readonly', 'required'];
16741
16742selection.prototype.directives = directives;
16743
16744function directives(value) {
16745 return arguments.length ? this.property("__directives__", value) : this.node().__directives__;
16746}
16747
16748var getdirs = function (element, directives) {
16749 var sel = select(element),
16750 dirs = sel.directives();
16751 if (dirs) return dirs;
16752 dirs = new Directives();
16753 sel.directives(dirs);
16754
16755 if (!directives) return dirs;
16756
16757 for (var i = 0; i < element.attributes.length; ++i) {
16758 var attr = element.attributes[i],
16759 bits = attr.name.split('-'),
16760 arg = bits[2],
16761 dirName = bits[0] === 'd3' ? bits[1] : null;
16762
16763 if (dirName) {
16764 if (!arg && attributes.indexOf(dirName) > -1) {
16765 arg = dirName;
16766 dirName = 'attr';
16767 }
16768 var directive = directives.get(dirName);
16769 if (directive) dirs.add(dirName, directive(element, attr, arg));else warn(element.tagName + ' cannot find directive "' + dirName + '". Did you forget to register it?');
16770 }
16771 dirs.attrs[attr.name] = attr.value;
16772 }
16773 return dirs.sorted();
16774};
16775
16776// Directives container
16777function Directives() {
16778 this.attrs = {};
16779 this._dirs = {};
16780 this._all = [];
16781}
16782
16783Directives.prototype = {
16784 size: function size() {
16785 return this._all.length;
16786 },
16787
16788 get: function get(name) {
16789 return this._dirs[name];
16790 },
16791
16792 pop: function pop(name) {
16793 var dir = this._dirs[name];
16794 if (dir) {
16795 delete this._dirs[name];
16796 dir.removeAttribute();
16797 var index = this._all.indexOf(dir);
16798 if (index > -1) this._all.splice(index, 1);
16799 }
16800 return dir;
16801 },
16802
16803 add: function add(name, dir) {
16804 this._dirs[name] = dir;
16805 this._all.push(dir);
16806 },
16807
16808 sorted: function sorted() {
16809 this._all.sort(function (d) {
16810 return -d.priority;
16811 });
16812 return this;
16813 },
16814
16815 forEach: function forEach(callback) {
16816 this._all.forEach(callback);
16817 }
16818};
16819
16820// Mount a model into an element
16821function mount$1(model, el) {
16822 var sel = select(el),
16823 directives = sel.directives();
16824
16825 // directives not available, this is a mount from
16826 // a directive/loop and requires a new model
16827 if (!directives) {
16828 directives = getdirs(el, model.$vm ? model.$vm.directives : null);
16829 model = createModel(directives, null, model);
16830 }
16831
16832 // Loop directive is special
16833 var loop = directives.pop('for');
16834
16835 if (loop) {
16836 loop.execute(model);
16837 return true; // Important - skip mounting a component
16838 } else {
16839 if (!sel.model()) sel.model(model);
16840 mountChildren(sel, directives);
16841 }
16842}
16843
16844function mountChildren(sel, directives) {
16845 var model = sel.model(),
16846 vm = model.$vm;
16847
16848 sel.selectAll(function () {
16849 return this.children;
16850 }).each(function () {
16851 var component = vm ? vm.components.get(this.tagName.toLowerCase()) : null;
16852
16853 if (component) component({ parent: vm }).mount(this);else {
16854 // vanilla element
16855 mount$1(model, this);
16856 var child = select(this);
16857 // cleanup model if not needed
16858 if (child.model() === model) child.model(null);
16859 }
16860 });
16861
16862 // Execute directives
16863 if (directives.size()) {
16864 directives.forEach(function (d) {
16865 d.execute(model);
16866 });
16867 } else
16868 // no directives - remove property
16869 sel.directives(null);
16870}
16871
16872//
16873// d3-model directive
16874// ===================
16875//
16876// Create a new model on the element based on data from parent models
16877// This is a special directive and the first to be mounted
16878var model$2 = {
16879
16880 mount: function mount(model) {
16881 var expr = this.expression;
16882 if (expr.parsed.type !== expr.codes.IDENTIFIER) return warn('d3-model expression support identifiers only, got "' + expr.parsed.type + '": ' + this.expression);
16883 var newModel = model.$child(expr.eval(model));
16884 this.sel.model(newModel);
16885 model.$setbase(this.expression.expr, newModel);
16886 }
16887
16888};
16889
16890var properties = ['disabled', 'readonly', 'required'];
16891
16892//
16893// d3-attr:<attr> directive
16894// ==============================
16895//
16896// Create a one-way binding between a model and a HTML element attribute
16897var attr = {
16898
16899 create: function create(expression) {
16900 if (!this.arg) return warn('Cannot bind to empty attribute. Specify :<attr-name>');
16901 return expression;
16902 },
16903
16904 refresh: function refresh(model, value) {
16905 if (this.arg === 'class') return this.refreshClass(value);
16906 if (isArray(value)) return warn('Cannot apply array to attribute ' + this.arg);
16907 if (properties.indexOf(this.arg) > -1) this.sel.property(this.arg, value || null);else this.sel.attr(this.arg, value);
16908 },
16909
16910 refreshClass: function refreshClass(value) {
16911 var sel = this.sel;
16912
16913 if (!isArray(value)) value = [value];
16914
16915 if (this.oldValue) this.oldValue.forEach(function (entry) {
16916 if (entry) sel.classed(entry, false);
16917 });
16918
16919 this.oldValue = value.map(function (entry) {
16920 var exist = true;
16921 if (isArray(entry)) {
16922 exist = entry[1];
16923 entry = entry[0];
16924 }
16925 if (entry) sel.classed(entry, exist);
16926 return entry;
16927 });
16928 }
16929
16930};
16931
16932//
16933// d3-html
16934// =============
16935// attach html or text to the innerHtml property
16936//
16937// Usage:
16938// <div id="foo" d3-html="output"></div>
16939var html = {
16940
16941 refresh: function refresh(model, html) {
16942 if (isString(html)) this.sel.html(html);
16943 }
16944};
16945
16946var base = {
16947
16948 on: function on(model, attrName) {
16949 var refresh = refreshFunction(this, model, attrName);
16950
16951 // DOM => model binding
16952 select(this.el).on('input', refresh).on('change', refresh);
16953 }
16954};
16955
16956function createTag(proto) {
16957
16958 function Tag(el) {
16959 this.el = el;
16960 }
16961
16962 Tag.prototype = assign({}, base, proto);
16963
16964 function tag(el) {
16965 var t = new Tag(el);
16966
16967 Object.defineProperty(t, 'value', {
16968 get: function get() {
16969 return select(t.el).property('value');
16970 },
16971 set: function set(v) {
16972 select(t.el).property('value', v);
16973 }
16974 });
16975
16976 return t;
16977 }
16978
16979 tag.prototype = Tag.prototype;
16980
16981 return tag;
16982}
16983
16984function refreshFunction(dom, model, attrName) {
16985
16986 return debounce(function () {
16987 model.$set(attrName, dom.value);
16988 });
16989}
16990
16991var input$1 = createTag();
16992
16993var textarea = createTag();
16994
16995var tags = {
16996 input: input$1,
16997 textarea: textarea
16998};
16999
17000//
17001// d3-value directive
17002// ===================
17003//
17004// Two-way data binding for HTML elements supporting the value property
17005var value$1 = {
17006
17007 create: function create(expression) {
17008 var type = this.sel.attr('type'),
17009 tag = this.el.tagName.toLowerCase(),
17010 Tag = tags[type] || tags[tag];
17011
17012 if (!Tag) return warn('Cannot apply d3-value directive to ' + tag);
17013 this.tag = new Tag(this.el);
17014 return expression;
17015 },
17016
17017 mount: function mount(model) {
17018 var expr = this.expression;
17019 // TODO: relax this constraint
17020 if (expr.parsed.type !== expr.codes.IDENTIFIER) return warn('d3-value expression support identifiers only, got "' + expr.parsed.type + '": ' + this.expression);
17021 var attrName = this.expression.expr;
17022 //
17023 // Create the model reactive attribute
17024 model.$set(attrName, this.tag.value);
17025
17026 this.tag.on(model, attrName);
17027 return model;
17028 },
17029
17030 refresh: function refresh(model, value) {
17031 this.tag.value = value;
17032 },
17033
17034 destroy: function destroy() {
17035 this.tag.off();
17036 }
17037};
17038
17039//
17040// d3-show
17041// =============
17042// Show or hide an element
17043//
17044var show = {
17045
17046 mount: function mount(model) {
17047 this.block = this.sel.style('display') ? 'block' : null;
17048 return model;
17049 },
17050
17051 refresh: function refresh(model, value) {
17052 if (value) this.sel.style('display', this.block);else this.sel.style('display', 'none');
17053 }
17054};
17055
17056//
17057// d3-on directive
17058var on$1 = {
17059
17060 mount: function mount(model) {
17061 var event = this.arg || 'click',
17062 expr = this.expression;
17063
17064 // DOM event => model binding
17065 this.sel.on(event + '.' + this.uid, function () {
17066 expr.eval(model);
17067 });
17068 }
17069};
17070
17071//
17072// d3-transition
17073// =============
17074var transition$1 = {
17075
17076 refresh: function refresh(model) {
17077 transition(model);
17078 }
17079};
17080
17081//
17082// d3-for directive
17083// ======================
17084//
17085// Repeat a element over an array of items and establish
17086// a one way binding between the array and the Dom
17087var d3For = {
17088
17089 create: function create(expression) {
17090 var bits = [];
17091 expression.trim().split(' ').forEach(function (v) {
17092 v ? bits.push(v) : null;
17093 });
17094 if (bits.length !== 3 || bits[1] != 'in') return warn('d3-for directive requires "item in expression" template');
17095 this.itemName = bits[0];
17096 this.itemClass = 'for' + this.uid;
17097 return bits[2];
17098 },
17099
17100 mount: function mount$1(model) {
17101 this.creator = this.el;
17102 this.el = this.creator.parentNode;
17103 // remove the creator from the DOM
17104 select(this.creator).remove();
17105 return model;
17106 },
17107
17108 refresh: function refresh(model, items) {
17109 if (!isArray(items)) return;
17110
17111 var creator$$1 = this.creator,
17112 selector$$1 = creator$$1.tagName + '.' + this.itemClass,
17113 itemName = this.itemName,
17114 entries = this.sel.selectAll(selector$$1).data(items);
17115
17116 entries.enter().append(function () {
17117 return creator$$1.cloneNode(true);
17118 }).classed(this.itemClass, true).each(function (d, index) {
17119 var x = { index: index };
17120 x[itemName] = d;
17121 mount$1(model.$child(x), this);
17122 });
17123
17124 entries.exit().remove();
17125 }
17126};
17127
17128//
17129// d3-if
17130// =============
17131//
17132// Remove an element if the condition is not satisfied
17133//
17134var d3If = {
17135
17136 refresh: function refresh(model, value) {
17137 if (value) this.sel.style('display', null);else this.sel.style('display', 'none');
17138 }
17139};
17140
17141var directives$1 = {
17142 model: model$2,
17143 attr: attr,
17144 html: html,
17145 value: value$1,
17146 show: show,
17147 on: on$1,
17148 transition: transition$1,
17149 'for': d3For,
17150 'if': d3If
17151};
17152
17153var asSelect = function (el) {
17154 if (el && !isFunction(el.size)) return select(el);
17155 return el;
17156};
17157
17158var maybeJson = function (value) {
17159 if (isString(value)) {
17160 try {
17161 return JSON.parse(value);
17162 } catch (msg) {
17163 return value;
17164 }
17165 }
17166 return value;
17167};
17168
17169// require handlebar
17170function compile$1(text) {
17171 var handlebars = inBrowser ? window.handlebars : require('handlebars');
17172 if (handlebars) return handlebars.compile(text);
17173 warn('compile function requires handlebars');
17174}
17175
17176function html$1(source, context) {
17177 if (isString(source)) {
17178 if (context) {
17179 var s = compile$1(source);
17180 if (!s) return source;
17181 } else return source;
17182 }
17183 return source(context);
17184}
17185
17186function htmlElement(source, context) {
17187 var el = select(document.createElement('div'));
17188 el.html(html$1(source, context));
17189 var children = el.node().children;
17190 if (children.length !== 1) warn('HtmlElement function should return one root element only, got ' + children.length);
17191 return children[0];
17192}
17193
17194// Core Directives
17195var coreDirectives = extendDirectives(map$1(), directives$1);
17196
17197// prototype for both views and components
17198var proto$1 = {
17199 isd3: true,
17200 providers: providers,
17201 htmlElement: htmlElement,
17202 // same as export
17203 viewElement: htmlElement,
17204
17205 init: function init() {},
17206
17207 mounted: function mounted$1() {},
17208
17209 createElement: function createElement(tag) {
17210 return select(document.createElement(tag));
17211 },
17212
17213 responseError: function responseError(response) {
17214 var self$$1 = this;
17215 response.json().then(function (data) {
17216 self$$1.error(data, response);
17217 });
17218 },
17219 error: function error(data) {
17220 data.level = 'error';
17221 this.message(data);
17222 },
17223 message: function message(data) {
17224 var self$$1 = this;
17225 this.root.events.call('message', self$$1, data);
17226 },
17227
17228
17229 // Shortcut for fetch function in providers
17230 fetch: function fetch(url, options) {
17231 var fetch = providers.fetch;
17232 return arguments.length == 1 ? fetch(url) : fetch(url, options);
17233 }
17234};
17235
17236//
17237// prototype for views
17238var protoView = assign({}, proto$1, {
17239
17240 use: function use(plugin) {
17241 if (isObject(plugin)) plugin.install(this);else plugin(this);
17242 return this;
17243 },
17244
17245 addComponent: function addComponent(name, obj) {
17246 if (this.isMounted) return warn('already mounted, cannot add component');
17247 var component = createComponent(obj, protoComponent);
17248 this.components.set(name, component);
17249 return component;
17250 },
17251
17252 addDirective: function addDirective(name, obj) {
17253 if (this.isMounted) return warn('already mounted, cannot add directive');
17254 var directive = createDirective(obj);
17255 this.directives.set(name, directive);
17256 return directive;
17257 },
17258
17259 mount: function mount(el) {
17260 if (mounted$1(this)) warn('already mounted');else {
17261 el = element$2(el);
17262 if (el) {
17263 var parent = this.parent ? this.parent.model : null;
17264 this.model = createModel(getdirs(el, this.directives), this.model, parent);
17265 asView(this, el);
17266 }
17267 }
17268 return this;
17269 }
17270});
17271
17272//
17273// prototype for components
17274var protoComponent = assign({}, proto$1, {
17275
17276 render: function render() {},
17277
17278 mount: function mount(el) {
17279 if (mounted$1(this)) warn('already mounted');else {
17280 var parent = this.parent ? this.parent.model : null,
17281 directives = getdirs(el, this.directives),
17282 model = createModel(directives, this.model, parent);
17283 //
17284 this.model = model;
17285 //
17286 // When a for d3-for loop is active we abort mounting this component
17287 // The component will be mounted as many times the the for loop requires
17288 if (mount$1(this.model, el)) return;
17289
17290 var data = select(el).datum() || {};
17291
17292 if (isArray(this.props)) {
17293 var key, value;
17294 this.props.forEach(function (prop) {
17295 key = directives.attrs[prop];
17296 if (model[key]) value = model[key];else value = maybeJson(key);
17297 data[prop] = value;
17298 });
17299 }
17300 //
17301 // create the new element from the render function
17302 var newEl = this.render(data, directives.attrs);
17303 if (isPromise(newEl)) {
17304 var self$$1 = this;
17305 newEl.then(function (element) {
17306 compile$$1(self$$1, el, element);
17307 });
17308 } else compile$$1(this, el, newEl);
17309 }
17310 return this;
17311 }
17312});
17313
17314// factory of View and Component constructors
17315function createComponent(o, prototype) {
17316 prototype = prototype || protoView;
17317 if (isFunction(o)) o = { render: o };
17318
17319 var obj = assign({}, o),
17320 classComponents = extendComponents(map$1(), pop$1(obj, 'components')),
17321 classDirectives = extendDirectives(map$1(), pop$1(obj, 'directives')),
17322 model = pop$1(obj, 'model'),
17323 props = pop$1(obj, 'props');
17324
17325 function Component(options) {
17326 var parent = pop$1(options, 'parent'),
17327 components = map$1(parent ? parent.components : null),
17328 directives = map$1(parent ? parent.directives : coreDirectives),
17329 events = dispatch('message');
17330
17331 classComponents.each(function (comp, key) {
17332 components.set(key, comp);
17333 });
17334 classDirectives.each(function (comp, key) {
17335 directives.set(key, comp);
17336 });
17337 extendComponents(components, pop$1(options, 'components'));
17338 extendDirectives(directives, pop$1(options, 'directives'));
17339
17340 Object.defineProperties(this, {
17341 components: {
17342 get: function get() {
17343 return components;
17344 }
17345 },
17346 directives: {
17347 get: function get() {
17348 return directives;
17349 }
17350 },
17351 parent: {
17352 get: function get() {
17353 return parent;
17354 }
17355 },
17356 root: {
17357 get: function get() {
17358 return parent ? parent.root : this;
17359 }
17360 },
17361 props: {
17362 get: function get() {
17363 return props;
17364 }
17365 },
17366 uid: {
17367 get: function get() {
17368 return this.model.uid;
17369 }
17370 },
17371 events: {
17372 get: function get() {
17373 return events;
17374 }
17375 }
17376 });
17377 this.model = assign({}, model, pop$1(options, 'model'));
17378 this.init(options);
17379 }
17380
17381 Component.prototype = assign({}, prototype, obj);
17382
17383 function component(options) {
17384 return new Component(options);
17385 }
17386
17387 component.prototype = Component.prototype;
17388
17389 return component;
17390}
17391
17392function extendComponents(container, components) {
17393 map$1(components).each(function (obj, key) {
17394 container.set(key, createComponent(obj, protoComponent));
17395 });
17396 return container;
17397}
17398
17399function extendDirectives(container, directives) {
17400 map$1(directives).each(function (obj, key) {
17401 container.set(key, createDirective(obj));
17402 });
17403 return container;
17404}
17405
17406function asView(vm, element) {
17407 var model = vm.model;
17408
17409 Object.defineProperty(sel(vm), 'el', {
17410 get: function get() {
17411 return element;
17412 }
17413 });
17414
17415 Object.defineProperty(model, '$vm', {
17416 get: function get() {
17417 return vm;
17418 }
17419 });
17420
17421 // Apply model to element
17422 select(element).model(model);
17423
17424 mount$1(model, element);
17425 //
17426 // mounted hook
17427 timeout$1(function () {
17428 vm.mounted();
17429 });
17430}
17431
17432function element$2(el) {
17433 if (!el) return warn('element not defined, pass an identifier or an HTMLElement object');
17434 var d3el = isFunction(el.node) ? el : select(el),
17435 element = d3el.node();
17436 if (!element) warn('could not find ' + el + ' element');else return element;
17437}
17438
17439function mounted$1(view) {
17440 var mounted = view.isMounted;
17441 if (!mounted) Object.defineProperty(view, 'isMounted', {
17442 get: function get() {
17443 return true;
17444 }
17445 });
17446 return mounted;
17447}
17448
17449function compile$$1(vm, el, element) {
17450 if (!element) return warn('render function must return a single HTML node. It returned nothing!');
17451 element = asSelect(element);
17452 if (element.size() !== 1) warn('render function must return a single HTML node');
17453 element = element.node();
17454 //
17455 // Insert before the component element
17456 el.parentNode.insertBefore(element, el);
17457 // remove the component element
17458 select(el).remove();
17459 //
17460 // Mount
17461 asView(vm, element);
17462}
17463
17464// the view constructor
17465var index$3 = createComponent();
17466
17467// Add callback to execute when the DOM is ready
17468var dom = function (callback) {
17469 readyCallbacks.push(callback);
17470 if (document.readyState !== 'complete') {
17471 document.addEventListener('DOMContentLoaded', _completed);
17472 // A fallback to window.onload, that will always work
17473 window.addEventListener('load', _completed);
17474 } else domReady();
17475};
17476
17477var readyCallbacks = [];
17478
17479function _completed() {
17480 document.removeEventListener('DOMContentLoaded', _completed);
17481 window.removeEventListener('load', _completed);
17482 domReady();
17483}
17484
17485function domReady() {
17486 var callback = void 0;
17487 while (readyCallbacks.length) {
17488 callback = readyCallbacks.shift();
17489 timeout$1(callback);
17490 }
17491}
17492
17493var providers$1 = {
17494 logger: logger
17495};
17496
17497var prefix$3 = '[d3-form]';
17498
17499var warn$1 = function (msg) {
17500 providers$1.logger.warn(prefix$3 + ' ' + msg);
17501};
17502
17503var modelDataKeys = ['labelSrOnly', 'layout'];
17504
17505var componentsFromType = {
17506 'text': 'input',
17507 'password': 'input',
17508 'number': 'input'
17509};
17510
17511// return A promise which execute a callback at the next event Loop cycle
17512function nextTick(callback) {
17513 var self$$1 = this;
17514 return new Promise(function (resolve) {
17515 resolve();
17516 }).then(function () {
17517 return callback.call(self$$1);
17518 });
17519}
17520
17521function formComponent(child) {
17522 var type = child.type || 'text';
17523 return componentsFromType[type] || type;
17524}
17525
17526function addChildren(sel) {
17527 var children = this.data.children;
17528 if (children) {
17529 if (!isArray(children)) {
17530 warn$1('children should be an array of fields, for ' + (typeof children === 'undefined' ? 'undefined' : _typeof(children)));
17531 return sel;
17532 }
17533 sel.selectAll('.d3form').data(children).enter().append(formChild).classed('d3form', true);
17534 }
17535 return sel;
17536}
17537
17538function modelData(data) {
17539 if (!data) data = {};
17540 this.data = data;
17541 var model = this.model;
17542 modelDataKeys.forEach(function (key) {
17543 if (key in data) model.$set(key, data[key]);
17544 });
17545 return data;
17546}
17547
17548function formChild(child) {
17549 var component = formComponent(child);
17550 if (!component) {
17551 warn$1('Could not find form component ' + child.type);
17552 component = 'input';
17553 child.type = 'hidden';
17554 }
17555 return document.createElement('d3' + component);
17556}
17557
17558//
17559// Fieldset element
17560var fieldset = {
17561
17562 render: function render(data) {
17563 var el = this.createElement('fieldset');
17564 modelData.call(this, data);
17565 return addChildren.call(this, el);
17566 }
17567
17568};
17569
17570var formElement = {
17571 wrap: function wrap(sel) {
17572 var field = this,
17573 theme = getTheme(field),
17574 wrappers = theme ? theme[sel.attr('type')] || theme[sel.node().tagName.toLowerCase()] : null;
17575 if (!wrappers || !theme.wrappers) return sel;
17576
17577 var wrapped = sel,
17578 wrap;
17579
17580 wrappers.forEach(function (wrapper) {
17581 wrap = theme.wrappers[wrapper];
17582 if (wrap) wrapped = wrap.call(field, wrapped, sel);else warn$1('Could not find form field wrapper ' + wrapper);
17583 });
17584
17585 return wrapped;
17586 },
17587 wrapTemplate: function wrapTemplate(sel, template) {
17588 var div = document.createElement('div'),
17589 outer = select(div).html(template),
17590 slot = outer.select('slot');
17591
17592 if (!slot.size()) {
17593 warn$1('template does not provide a slot element');
17594 return sel;
17595 }
17596 var target = select(slot.node().parentNode);
17597 sel.nodes().forEach(function (node) {
17598 target.insert(function () {
17599 return node;
17600 }, 'slot');
17601 });
17602 slot.remove();
17603 return selectAll(div.children);
17604 }
17605};
17606
17607// A mixin for all form field components
17608var field = assign({
17609
17610 model: {
17611 error: '',
17612 isDirty: false,
17613 showError: {
17614 reactOn: ['error', 'isDirty', 'formSubmitted'],
17615 get: function get() {
17616 if (this.error) return this.isDirty || this.formSubmitted;
17617 return false;
17618 }
17619 }
17620 },
17621
17622 mounted: function mounted() {
17623 this.model.$on('value', function () {
17624 this.isDirty = true;
17625 });
17626 },
17627 inputData: function inputData(data) {
17628 data = modelData.call(this, data);
17629 if (!data.name) warn$1('Input field without a name');
17630 data.placeholder = data.placeholder || data.label || data.name;
17631 data.id = data.id || 'd3f' + this.uid;
17632 this.model.inputs[data.name] = this.model;
17633 return data;
17634 }
17635}, formElement);
17636
17637function getTheme(component) {
17638 var theme = component.formTheme;
17639 if (!theme && component.parent) return getTheme(component.parent);else return theme;
17640}
17641
17642var required$1 = {
17643 set: function set(el, data) {
17644 var value = data.required;
17645 if (isString(value)) el.attr('d3-required', value);else el.property('required', value || null);
17646 },
17647 validate: function validate(el, value) {
17648 if (el.property('required')) {
17649 if (!value) return 'required';
17650 } else if (value === '') return true;
17651 }
17652};
17653
17654var minlength = {
17655 set: function set(el, data) {
17656 var value = data.minlength;
17657 if (isString(value)) el.attr('d3-attr-minlength', value);else if (value !== undefined) el.attr('minlength', value);
17658 },
17659 validate: function validate(el, value) {
17660 var l = +el.attr('minlength');
17661 if (l === l && l > 0 && value.length < l) return 'too short - ' + l + ' characters or more expected';
17662 }
17663};
17664
17665var maxlength = {
17666 set: function set(el, data) {
17667 var value = data.maxlength;
17668 if (isString(value)) el.attr('d3-attr-maxlength', value);else if (value !== undefined) el.attr('maxlength', value);
17669 },
17670 validate: function validate(el, value) {
17671 var l = +el.attr('maxlength');
17672 if (l === l && l > 0 && value.length > l) return 'too long - ' + l + ' characters or less expected';
17673 }
17674};
17675
17676var min$1 = {
17677 set: function set(el, data) {
17678 var value = data.min;
17679 if (isString(value)) el.attr('d3-attr-min', value);else if (value !== undefined) el.attr('min', value);
17680 },
17681 validate: function validate(el, value) {
17682 var r = range$2(el);
17683 if (r && +value < r[0]) return 'must be greater or equal ' + r[0];
17684 }
17685};
17686
17687var max$2 = {
17688 set: function set(el, data) {
17689 var value = data.max;
17690 if (isString(value)) el.attr('d3-attr-max', value);else if (value !== undefined) el.attr('max', value);
17691 },
17692 validate: function validate(el, value) {
17693 var r = range$2(el);
17694 if (r && +value > r[1]) return 'must be less or equal ' + r[1];
17695 }
17696};
17697
17698var validators = {
17699 get: function get(model, custom) {
17700 var validators = this.all.slice(0);
17701 if (isObject(custom)) for (var key in custom) {
17702 validators.push(customValidator(key, custom[key]));
17703 }return validators;
17704 },
17705 set: function set(vm, el) {
17706 vm.model.validators.forEach(function (validator) {
17707 validator.set(el, vm.data);
17708 });
17709
17710 vm.model.$on(this.validate);
17711 },
17712 validate: function validate(property) {
17713 if (property !== 'value') return;
17714
17715 var vm = this.$vm,
17716 validators = this.validators,
17717 el = vm.sel.attr('id') === vm.data.id ? vm.sel : vm.sel.select('#' + vm.data.id),
17718 value = this.value,
17719 validator,
17720 msg;
17721
17722 for (var i = 0; i < validators.length; ++i) {
17723 validator = validators[i];
17724 msg = validator.validate(el, value);
17725 if (msg) {
17726 if (msg === true) msg = '';
17727 break;
17728 }
17729 }
17730
17731 this.error = msg || '';
17732 },
17733
17734
17735 all: [required$1, minlength, maxlength, min$1, max$2]
17736};
17737
17738function range$2(el) {
17739 var l0 = el.attr('min'),
17740 l1 = el.attr('max');
17741 l0 = l0 === null ? -Infinity : +l0;
17742 l1 = l1 === null ? Infinity : +l1;
17743 return [l0, l1];
17744}
17745
17746function customValidator(key, method) {
17747
17748 return {
17749 set: function set(el, data) {
17750 var value = data[key];
17751 if (!value) return;
17752 },
17753 validate: function validate(el, value) {
17754 return method(el, value);
17755 }
17756 };
17757}
17758
17759//
17760// Input element
17761var input$2 = assign({
17762
17763 render: function render(data) {
17764 data = this.inputData(data);
17765 var el = this.createElement('input').attr('id', data.id).attr('type', data.type || 'text').attr('name', data.name).attr('d3-value', 'value').attr('placeholder', data.placeholder);
17766
17767 validators.set(this, el);
17768 return this.wrap(el);
17769 }
17770}, field);
17771
17772//
17773// Textarea element
17774var textarea$1 = assign({
17775
17776 render: function render(data) {
17777 data = this.inputData(data);
17778 var el = this.createElement('textarea').attr('id', data.id).attr('name', data.name).attr('placeholder', data.placeholder).attr('d3-value', 'value').attr('d3-validate', 'validators');
17779
17780 validators.set(this, el);
17781 return this.wrap(el);
17782 }
17783
17784}, field);
17785
17786//
17787// Select element
17788var select$1 = assign({}, field, {
17789
17790 model: assign({
17791 options: [],
17792 $optionLabel: optionLabel,
17793 $optionValue: optionValue
17794 }, field.model),
17795
17796 render: function render(data) {
17797 data = this.inputData(data);
17798 var el = this.createElement('select').attr('id', data.id).attr('name', data.name).attr('d3-value', 'value').attr('placeholder', data.placeholder);
17799
17800 this.model.options = data.options;
17801
17802 el.append('option').attr('d3-for', 'option in options').attr('d3-html', '$optionLabel()').attr('d3-attr-value', '$optionValue()');
17803
17804 validators.set(this, el);
17805 return this.wrap(el);
17806 }
17807});
17808
17809function optionValue() {
17810 if (isArray(this.option)) return this.option[0];
17811 return this.option;
17812}
17813
17814function optionLabel() {
17815 if (isArray(this.option)) return this.option[1] || this.option[0];
17816 return this.option;
17817}
17818
17819//
17820// Submit element
17821var submit = assign({
17822
17823 render: function render(data) {
17824 data = modelData.call(this, data);
17825 data.type = data.type || 'submit';
17826 this.model.$set('error', false);
17827 if (!isString(data.disabled)) {
17828 this.model.$set('disabled', data.disabled || null);
17829 data.disabled = 'disabled';
17830 }
17831 if (!data.click) data.click = '$vm.click()';
17832
17833 var el = this.createElement('button').attr('type', data.type).attr('name', data.name).attr('d3-attr-disabled', data.disabled).attr('d3-on-click', data.click).html(data.label || 'submit');
17834
17835 return this.wrap(el);
17836 },
17837
17838 click: function click() {
17839 this.model.form.actions.submit.call(this, exports.event);
17840 }
17841}, formElement);
17842
17843// Form Responses
17844var responses = {
17845 "default": defaultResponse,
17846 redirect: redirect
17847};
17848
17849function defaultResponse(response) {
17850 var data = response.json();
17851 this.message(data);
17852}
17853
17854function redirect() {
17855 window.location.href = this.data.redirectTo || '/';
17856}
17857
17858// Form Actions
17859var actions = {
17860 submit: submit$1
17861};
17862
17863function submit$1(e) {
17864 var form = this && this.model ? this.model.form : null;
17865
17866 if (!form) {
17867 warn$1('form not available, cannot submit');
17868 return;
17869 }
17870
17871 if (e) {
17872 e.preventDefault();
17873 e.stopPropagation();
17874 }
17875
17876 var fetch = providers$1.fetch,
17877 ct = (form.data.enctype || '').split(';')[0],
17878 action = form.data.action,
17879 url = isObject(action) ? action.url : action,
17880 data = form.inputData(),
17881 options = {};
17882
17883 if (!fetch) {
17884 warn$1('fetch provider not available, cannot submit');
17885 return;
17886 }
17887
17888 if (!url) {
17889 warn$1('No url, cannot submit');
17890 return;
17891 }
17892
17893 if (ct === 'application/json') {
17894 options.headers = {
17895 'Content-Type': form.data.enctype
17896 };
17897 options.body = JSON.stringify(data);
17898 } else {
17899 options.body = new FormData();
17900 for (var key in data) {
17901 options.body.set(key, data[key]);
17902 }
17903 }
17904
17905 // Flag the form as submitted
17906 form.setSubmit();
17907 options.method = form.method || 'post';
17908 fetch(url, options).then(success, failure);
17909
17910 function success(response) {
17911 form.setSubmitDone();
17912 form.response(response);
17913 }
17914
17915 function failure() {
17916 form.setSubmitDone();
17917 }
17918}
17919
17920// Main form component
17921var form = {
17922
17923 // make sure a new model is created for this component
17924 props: ['json'],
17925
17926 model: {
17927 formSubmitted: false,
17928 formPending: false
17929 },
17930
17931 components: {
17932 'd3fieldset': fieldset,
17933 'd3input': input$2,
17934 'd3textarea': textarea$1,
17935 'd3select': select$1,
17936 'd3submit': submit
17937 },
17938
17939 render: function render(data) {
17940 var model = this.model,
17941 form = this.createElement('form').attr('novalidate', ''),
17942 self$$1 = this;
17943 //
17944 model.inputs = {};
17945 model.form = this;
17946 //
17947 var json = data['json'];
17948 if (isString(json)) {
17949 var fetch = providers$1.fetch;
17950 return fetch(json, { method: 'GET' }).then(function (response) {
17951 if (response.status === 200) return response.json().then(build);else warn$1('Could not load form from ' + json + ': status ' + response.status);
17952 });
17953 } else return build(json);
17954
17955 function build(formData) {
17956 modelData.call(self$$1, formData);
17957 //
17958 // Form validations
17959 model.validators = validators.get(model, data.validators);
17960 //
17961 // Form actions
17962 self$$1.actions = {};
17963 for (var key in actions) {
17964 var action = self$$1.data[key];
17965 if (isString(action)) action = self$$1.model.$get(action);
17966 self$$1.actions[key] = action || actions[key];
17967 }
17968 addChildren.call(self$$1, form);
17969 return form;
17970 }
17971 },
17972
17973 inputData: function inputData() {
17974 var inputs = this.model.inputs,
17975 data = {},
17976 value;
17977 for (var key in inputs) {
17978 value = inputs[key].value;
17979 if (value !== undefined) data[key] = value;
17980 }
17981
17982 return data;
17983 },
17984
17985 setSubmit: function setSubmit() {
17986 var _this = this;
17987
17988 this.model.formSubmitted = true;
17989 this.model.formPending = true;
17990 return nextTick.call(this, function () {
17991 return _this.isValid();
17992 });
17993 },
17994
17995 setSubmitDone: function setSubmitDone() {
17996 this.model.formPending = false;
17997 },
17998
17999 isValid: function isValid() {
18000 var inp;
18001 for (var key in this.model.inputs) {
18002 inp = this.model.inputs[key];
18003 if (inp.error) return false;
18004 }
18005 return true;
18006 },
18007 inputError: function inputError(error) {
18008 var input = this.model.inputs[error.name];
18009 if (!input) {
18010 warn$1('Unknown input, cannot set input error');
18011 this.error(error);
18012 }
18013 },
18014 response: function response(_response) {
18015 if (!_response) return;
18016 var handler;
18017
18018 if (_response.status) {
18019 if (_response.status < 300) {
18020 if (this.data.resultHandler) {
18021 handler = responses[this.data.resultHandler];
18022 if (!handler) warn$1('Could not find ' + this.data.resultHandler + ' result handler');else handler.call(this, _response);
18023 } else {
18024 responses.default.call(this, _response);
18025 }
18026 } else this.responseError(_response);
18027 } else if (_response.error) {
18028 this.error(_response.error);
18029 } else if (isArray(_response.errors)) {
18030 var self$$1 = this;
18031 _response.errors.forEach(function (error) {
18032 self$$1.inputError(error);
18033 });
18034 } else {
18035 if (this.data.resultHandler) {
18036 handler = responses[this.data.resultHandler];
18037 if (!handler) warn$1('Could not find ' + this.data.resultHandler + ' result handler');else handler.call(this, _response);
18038 } else {
18039 responses.default.call(this, _response);
18040 }
18041 }
18042 }
18043};
18044
18045// Forms plugin
18046var index$4 = {
18047
18048 install: function install(view) {
18049 view.addComponent('d3form', form);
18050 for (var key in view.providers) {
18051 providers$1[key] = view.providers[key];
18052 }
18053 },
18054
18055 actions: actions,
18056
18057 responses: responses
18058};
18059
18060var label = function (el) {
18061 return this.wrapTemplate(el, labelTpl(this.data));
18062};
18063
18064function labelTpl(data) {
18065 var label = data.label || data.name;
18066
18067 return "<label for=" + data.id + " class=\"control-label\" d3-class=\"[required, labelSrOnly ? 'sr-only' : null]\">" + label + "</label>\n<slot></slot>";
18068}
18069
18070var groupTpl = '<div class="form-group" d3-class=\'showError ? "has-danger" : null\'>\n<slot></slot>\n<p d3-if="showError" class="text-danger error-block" d3-html="error"></p>\n</div>';
18071
18072var formGroup = function (el, formEl) {
18073 formEl.classed('form-control', true).attr('d3-class', 'showError ? "form-control-danger" : null');
18074 return this.wrapTemplate(el, groupTpl);
18075};
18076
18077var inputGroup = function (el, formEl) {
18078 var ig = this.data['group'];
18079 if (!ig) return el;
18080 var gid = 'g' + formEl.attr('id');
18081 formEl.attr('aria-describedby', gid);
18082 return this.wrapTemplate(el, groupTpl$1(gid, ig));
18083};
18084
18085function groupTpl$1(gid, group) {
18086 return '<div class="input-group" :class="bootstrapStatus()">\n<span class="input-group-addon" id="' + gid + '">' + group + '</span>\n<slot></slot>\n</div>';
18087}
18088
18089var groupTpl$2 = '<div class="form-group">\n<slot></slot>\n</div>';
18090
18091var submit$2 = function (el, formEl) {
18092 var theme = this.data.theme || 'primary';
18093 formEl.classed('btn', true).classed('btn-' + theme, true);
18094 return this.wrapTemplate(el, groupTpl$2);
18095};
18096
18097var bootstrap = {
18098
18099 input: ['inputGroup', 'label', 'formGroup'],
18100 textarea: ['label', 'formGroup'],
18101 select: ['label', 'formGroup'],
18102 submit: ['submit'],
18103 wrappers: {
18104 label: label,
18105 formGroup: formGroup,
18106 inputGroup: inputGroup,
18107 submit: submit$2
18108 }
18109};
18110
18111// Bootstrap theme
18112var index$5 = {
18113
18114 install: function install(view) {
18115 var d3form = view.components.get('d3form');
18116 if (d3form) d3form.prototype.formTheme = bootstrap;
18117 }
18118};
18119
18120var version$1 = "0.1.9";
18121
18122var version$2 = "0.1.3";
18123
18124exports.version = version$2;
18125exports.bisect = bisectRight;
18126exports.bisectRight = bisectRight;
18127exports.bisectLeft = bisectLeft;
18128exports.ascending = ascending;
18129exports.bisector = bisector;
18130exports.descending = descending;
18131exports.deviation = deviation;
18132exports.extent = extent$1;
18133exports.histogram = histogram;
18134exports.thresholdFreedmanDiaconis = freedmanDiaconis;
18135exports.thresholdScott = scott;
18136exports.thresholdSturges = sturges;
18137exports.max = max;
18138exports.mean = mean;
18139exports.median = median;
18140exports.merge = merge;
18141exports.min = min;
18142exports.pairs = pairs;
18143exports.permute = permute;
18144exports.quantile = threshold;
18145exports.range = range;
18146exports.scan = scan;
18147exports.shuffle = shuffle;
18148exports.sum = sum;
18149exports.ticks = ticks;
18150exports.tickStep = tickStep;
18151exports.transpose = transpose;
18152exports.variance = variance;
18153exports.zip = zip;
18154exports.nest = nest;
18155exports.set = set$1;
18156exports.map = map$1;
18157exports.keys = keys$1;
18158exports.values = values$1;
18159exports.entries = entries$1;
18160exports.randomUniform = uniform;
18161exports.randomNormal = normal;
18162exports.randomLogNormal = logNormal;
18163exports.randomBates = bates;
18164exports.randomIrwinHall = irwinHall;
18165exports.randomExponential = exponential;
18166exports.easeLinear = linear;
18167exports.easeQuad = quadInOut;
18168exports.easeQuadIn = quadIn;
18169exports.easeQuadOut = quadOut;
18170exports.easeQuadInOut = quadInOut;
18171exports.easeCubic = cubicInOut;
18172exports.easeCubicIn = cubicIn;
18173exports.easeCubicOut = cubicOut;
18174exports.easeCubicInOut = cubicInOut;
18175exports.easePoly = polyInOut;
18176exports.easePolyIn = polyIn;
18177exports.easePolyOut = polyOut;
18178exports.easePolyInOut = polyInOut;
18179exports.easeSin = sinInOut;
18180exports.easeSinIn = sinIn;
18181exports.easeSinOut = sinOut;
18182exports.easeSinInOut = sinInOut;
18183exports.easeExp = expInOut;
18184exports.easeExpIn = expIn;
18185exports.easeExpOut = expOut;
18186exports.easeExpInOut = expInOut;
18187exports.easeCircle = circleInOut;
18188exports.easeCircleIn = circleIn;
18189exports.easeCircleOut = circleOut;
18190exports.easeCircleInOut = circleInOut;
18191exports.easeBounce = bounceOut;
18192exports.easeBounceIn = bounceIn;
18193exports.easeBounceOut = bounceOut;
18194exports.easeBounceInOut = bounceInOut;
18195exports.easeBack = backInOut;
18196exports.easeBackIn = backIn;
18197exports.easeBackOut = backOut;
18198exports.easeBackInOut = backInOut;
18199exports.easeElastic = elasticOut;
18200exports.easeElasticIn = elasticIn;
18201exports.easeElasticOut = elasticOut;
18202exports.easeElasticInOut = elasticInOut;
18203exports.polygonArea = area;
18204exports.polygonCentroid = centroid;
18205exports.polygonHull = hull;
18206exports.polygonContains = contains$1;
18207exports.polygonLength = length$1;
18208exports.path = path;
18209exports.quadtree = quadtree;
18210exports.arc = arc$1;
18211exports.area = area$1;
18212exports.line = line;
18213exports.pie = pie;
18214exports.radialArea = radialArea;
18215exports.radialLine = radialLine$1;
18216exports.symbol = symbol;
18217exports.symbols = symbols;
18218exports.symbolCircle = circle;
18219exports.symbolCross = cross$1;
18220exports.symbolDiamond = diamond;
18221exports.symbolSquare = square;
18222exports.symbolStar = star;
18223exports.symbolTriangle = triangle;
18224exports.symbolWye = wye;
18225exports.curveBasisClosed = basisClosed;
18226exports.curveBasisOpen = basisOpen;
18227exports.curveBasis = basis;
18228exports.curveBundle = bundle;
18229exports.curveCardinalClosed = cardinalClosed;
18230exports.curveCardinalOpen = cardinalOpen;
18231exports.curveCardinal = cardinal;
18232exports.curveCatmullRomClosed = catmullRomClosed;
18233exports.curveCatmullRomOpen = catmullRomOpen;
18234exports.curveCatmullRom = catmullRom;
18235exports.curveLinearClosed = linearClosed;
18236exports.curveLinear = curveLinear;
18237exports.curveMonotoneX = monotoneX;
18238exports.curveMonotoneY = monotoneY;
18239exports.curveNatural = natural;
18240exports.curveStep = step;
18241exports.curveStepAfter = stepAfter;
18242exports.curveStepBefore = stepBefore;
18243exports.stack = stack;
18244exports.stackOffsetExpand = expand;
18245exports.stackOffsetNone = none;
18246exports.stackOffsetSilhouette = silhouette;
18247exports.stackOffsetWiggle = wiggle;
18248exports.stackOrderAscending = ascending$1;
18249exports.stackOrderDescending = descending$2;
18250exports.stackOrderInsideOut = insideOut;
18251exports.stackOrderNone = none$1;
18252exports.stackOrderReverse = reverse;
18253exports.color = color;
18254exports.rgb = rgb$1;
18255exports.hsl = hsl;
18256exports.lab = lab;
18257exports.hcl = hcl;
18258exports.cubehelix = cubehelix;
18259exports.interpolate = interpolate;
18260exports.interpolateArray = array$1;
18261exports.interpolateBasis = basis$2;
18262exports.interpolateBasisClosed = basisClosed$1;
18263exports.interpolateDate = date;
18264exports.interpolateNumber = interpolateNumber;
18265exports.interpolateObject = object$1;
18266exports.interpolateRound = interpolateRound;
18267exports.interpolateString = interpolateString;
18268exports.interpolateTransformCss = interpolateTransformCss;
18269exports.interpolateTransformSvg = interpolateTransformSvg;
18270exports.interpolateZoom = interpolateZoom;
18271exports.interpolateRgb = interpolateRgb;
18272exports.interpolateRgbBasis = rgbBasis;
18273exports.interpolateRgbBasisClosed = rgbBasisClosed;
18274exports.interpolateHsl = hsl$2;
18275exports.interpolateHslLong = hslLong;
18276exports.interpolateLab = lab$1;
18277exports.interpolateHcl = hcl$2;
18278exports.interpolateHclLong = hclLong;
18279exports.interpolateCubehelix = cubehelix$2;
18280exports.interpolateCubehelixLong = cubehelixLong;
18281exports.quantize = quantize;
18282exports.dispatch = dispatch;
18283exports.dsvFormat = dsv;
18284exports.csvParse = csvParse;
18285exports.csvParseRows = csvParseRows;
18286exports.csvFormat = csvFormat;
18287exports.csvFormatRows = csvFormatRows;
18288exports.tsvParse = tsvParse;
18289exports.tsvParseRows = tsvParseRows;
18290exports.tsvFormat = tsvFormat;
18291exports.tsvFormatRows = tsvFormatRows;
18292exports.now = now;
18293exports.timer = timer;
18294exports.timerFlush = timerFlush;
18295exports.timeout = timeout$1;
18296exports.interval = interval$1;
18297exports.timeInterval = newInterval;
18298exports.timeMillisecond = millisecond;
18299exports.timeMilliseconds = milliseconds;
18300exports.utcMillisecond = millisecond;
18301exports.utcMilliseconds = milliseconds;
18302exports.timeSecond = second;
18303exports.timeSeconds = seconds;
18304exports.utcSecond = second;
18305exports.utcSeconds = seconds;
18306exports.timeMinute = minute;
18307exports.timeMinutes = minutes;
18308exports.timeHour = hour;
18309exports.timeHours = hours;
18310exports.timeDay = day;
18311exports.timeDays = days;
18312exports.timeWeek = sunday;
18313exports.timeWeeks = sundays;
18314exports.timeSunday = sunday;
18315exports.timeSundays = sundays;
18316exports.timeMonday = monday;
18317exports.timeMondays = mondays;
18318exports.timeTuesday = tuesday;
18319exports.timeTuesdays = tuesdays;
18320exports.timeWednesday = wednesday;
18321exports.timeWednesdays = wednesdays;
18322exports.timeThursday = thursday;
18323exports.timeThursdays = thursdays;
18324exports.timeFriday = friday;
18325exports.timeFridays = fridays;
18326exports.timeSaturday = saturday;
18327exports.timeSaturdays = saturdays;
18328exports.timeMonth = month;
18329exports.timeMonths = months;
18330exports.timeYear = year;
18331exports.timeYears = years;
18332exports.utcMinute = utcMinute;
18333exports.utcMinutes = utcMinutes;
18334exports.utcHour = utcHour;
18335exports.utcHours = utcHours;
18336exports.utcDay = utcDay;
18337exports.utcDays = utcDays;
18338exports.utcWeek = utcSunday;
18339exports.utcWeeks = utcSundays;
18340exports.utcSunday = utcSunday;
18341exports.utcSundays = utcSundays;
18342exports.utcMonday = utcMonday;
18343exports.utcMondays = utcMondays;
18344exports.utcTuesday = utcTuesday;
18345exports.utcTuesdays = utcTuesdays;
18346exports.utcWednesday = utcWednesday;
18347exports.utcWednesdays = utcWednesdays;
18348exports.utcThursday = utcThursday;
18349exports.utcThursdays = utcThursdays;
18350exports.utcFriday = utcFriday;
18351exports.utcFridays = utcFridays;
18352exports.utcSaturday = utcSaturday;
18353exports.utcSaturdays = utcSaturdays;
18354exports.utcMonth = utcMonth;
18355exports.utcMonths = utcMonths;
18356exports.utcYear = utcYear;
18357exports.utcYears = utcYears;
18358exports.formatDefaultLocale = defaultLocale;
18359exports.formatLocale = formatLocale;
18360exports.formatSpecifier = formatSpecifier;
18361exports.precisionFixed = precisionFixed;
18362exports.precisionPrefix = precisionPrefix;
18363exports.precisionRound = precisionRound;
18364exports.timeFormatDefaultLocale = defaultLocale$1;
18365exports.timeFormatLocale = formatLocale$1;
18366exports.isoFormat = formatIso;
18367exports.isoParse = parseIso;
18368exports.scaleBand = band;
18369exports.scalePoint = point$1;
18370exports.scaleIdentity = identity$4;
18371exports.scaleLinear = linear$2;
18372exports.scaleLog = log;
18373exports.scaleOrdinal = ordinal;
18374exports.scaleImplicit = implicit;
18375exports.scalePow = pow;
18376exports.scaleSqrt = sqrt;
18377exports.scaleQuantile = quantile$$1;
18378exports.scaleQuantize = quantize$1;
18379exports.scaleThreshold = threshold$1;
18380exports.scaleTime = time;
18381exports.scaleUtc = utcTime;
18382exports.schemeCategory10 = category10;
18383exports.schemeCategory20b = category20b;
18384exports.schemeCategory20c = category20c;
18385exports.schemeCategory20 = category20;
18386exports.interpolateCubehelixDefault = cubehelix$3;
18387exports.interpolateRainbow = rainbow$1;
18388exports.interpolateWarm = warm;
18389exports.interpolateCool = cool;
18390exports.interpolateViridis = viridis;
18391exports.interpolateMagma = magma;
18392exports.interpolateInferno = inferno;
18393exports.interpolatePlasma = plasma;
18394exports.scaleSequential = sequential;
18395exports.creator = creator;
18396exports.local = local;
18397exports.matcher = matcher$1;
18398exports.mouse = mouse;
18399exports.namespace = namespace;
18400exports.namespaces = namespaces;
18401exports.select = select;
18402exports.selectAll = selectAll;
18403exports.selection = selection;
18404exports.selector = selector;
18405exports.selectorAll = selectorAll;
18406exports.touch = touch;
18407exports.touches = touches;
18408exports.window = window$1;
18409exports.customEvent = customEvent;
18410exports.transition = transition;
18411exports.active = active;
18412exports.interrupt = interrupt;
18413exports.axisTop = axisTop;
18414exports.axisRight = axisRight;
18415exports.axisBottom = axisBottom;
18416exports.axisLeft = axisLeft;
18417exports.cluster = cluster;
18418exports.hierarchy = hierarchy;
18419exports.pack = index;
18420exports.packSiblings = siblings;
18421exports.packEnclose = enclose;
18422exports.partition = partition;
18423exports.stratify = stratify;
18424exports.tree = tree;
18425exports.treemap = index$1;
18426exports.treemapBinary = binary;
18427exports.treemapDice = treemapDice;
18428exports.treemapSlice = treemapSlice;
18429exports.treemapSliceDice = sliceDice;
18430exports.treemapSquarify = squarify;
18431exports.treemapResquarify = resquarify;
18432exports.drag = drag;
18433exports.dragDisable = dragDisable;
18434exports.dragEnable = yesdrag;
18435exports.voronoi = voronoi;
18436exports.zoom = zoom;
18437exports.zoomTransform = transform;
18438exports.zoomIdentity = identity$6;
18439exports.brush = brush;
18440exports.brushX = brushX;
18441exports.brushY = brushY;
18442exports.brushSelection = brushSelection;
18443exports.chord = chord;
18444exports.ribbon = ribbon;
18445exports.geoArea = area$2;
18446exports.geoBounds = bounds;
18447exports.geoCentroid = centroid$1;
18448exports.geoCircle = circle$1;
18449exports.geoClipExtent = extent$2;
18450exports.geoDistance = distance;
18451exports.geoGraticule = graticule;
18452exports.geoGraticule10 = graticule10;
18453exports.geoInterpolate = interpolate$2;
18454exports.geoLength = length$2;
18455exports.geoPath = index$2;
18456exports.geoAlbers = albers;
18457exports.geoAlbersUsa = albersUsa;
18458exports.geoAzimuthalEqualArea = azimuthalEqualArea;
18459exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
18460exports.geoAzimuthalEquidistant = azimuthalEquidistant;
18461exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
18462exports.geoConicConformal = conicConformal;
18463exports.geoConicConformalRaw = conicConformalRaw;
18464exports.geoConicEqualArea = conicEqualArea;
18465exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
18466exports.geoConicEquidistant = conicEquidistant;
18467exports.geoConicEquidistantRaw = conicEquidistantRaw;
18468exports.geoEquirectangular = equirectangular;
18469exports.geoEquirectangularRaw = equirectangularRaw;
18470exports.geoGnomonic = gnomonic;
18471exports.geoGnomonicRaw = gnomonicRaw;
18472exports.geoIdentity = identity$8;
18473exports.geoProjection = projection;
18474exports.geoProjectionMutator = projectionMutator;
18475exports.geoMercator = mercator;
18476exports.geoMercatorRaw = mercatorRaw;
18477exports.geoOrthographic = orthographic;
18478exports.geoOrthographicRaw = orthographicRaw;
18479exports.geoStereographic = stereographic;
18480exports.geoStereographicRaw = stereographicRaw;
18481exports.geoTransverseMercator = transverseMercator;
18482exports.geoTransverseMercatorRaw = transverseMercatorRaw;
18483exports.geoRotation = rotation;
18484exports.geoStream = geoStream;
18485exports.geoTransform = transform$1;
18486exports.view = index$3;
18487exports.viewModel = model;
18488exports.viewExpression = viewExpression;
18489exports.viewReady = dom;
18490exports.viewProviders = providers;
18491exports.viewWarn = warn;
18492exports.viewForms = index$4;
18493exports.viewBootstrapForms = index$5;
18494exports.viewVersion = version$1;
18495exports.viewElement = htmlElement;
18496exports.viewTemplate = compile$1;
18497exports.viewHtml = html$1;
18498
18499Object.defineProperty(exports, '__esModule', { value: true });
18500
18501})));