1 |
|
2 | (function (global, factory) {
|
3 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
4 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
5 | (factory((global.d3 = global.d3 || {})));
|
6 | }(this, function (exports) { 'use strict';
|
7 |
|
8 | var version = "4.0.0";
|
9 |
|
10 | function ascending(a, b) {
|
11 | return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
12 | }
|
13 |
|
14 | function bisector(compare) {
|
15 | if (compare.length === 1) compare = ascendingComparator(compare);
|
16 | return {
|
17 | left: function(a, x, lo, hi) {
|
18 | if (lo == null) lo = 0;
|
19 | if (hi == null) hi = a.length;
|
20 | while (lo < hi) {
|
21 | var mid = lo + hi >>> 1;
|
22 | if (compare(a[mid], x) < 0) lo = mid + 1;
|
23 | else hi = mid;
|
24 | }
|
25 | return lo;
|
26 | },
|
27 | right: function(a, x, lo, hi) {
|
28 | if (lo == null) lo = 0;
|
29 | if (hi == null) hi = a.length;
|
30 | while (lo < hi) {
|
31 | var mid = lo + hi >>> 1;
|
32 | if (compare(a[mid], x) > 0) hi = mid;
|
33 | else lo = mid + 1;
|
34 | }
|
35 | return lo;
|
36 | }
|
37 | };
|
38 | }
|
39 |
|
40 | function ascendingComparator(f) {
|
41 | return function(d, x) {
|
42 | return ascending(f(d), x);
|
43 | };
|
44 | }
|
45 |
|
46 | var ascendingBisect = bisector(ascending);
|
47 | var bisectRight = ascendingBisect.right;
|
48 | var bisectLeft = ascendingBisect.left;
|
49 |
|
50 | function descending(a, b) {
|
51 | return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
52 | }
|
53 |
|
54 | function number(x) {
|
55 | return x === null ? NaN : +x;
|
56 | }
|
57 |
|
58 | function variance(array, f) {
|
59 | var n = array.length,
|
60 | m = 0,
|
61 | a,
|
62 | d,
|
63 | s = 0,
|
64 | i = -1,
|
65 | j = 0;
|
66 |
|
67 | if (f == null) {
|
68 | while (++i < n) {
|
69 | if (!isNaN(a = number(array[i]))) {
|
70 | d = a - m;
|
71 | m += d / ++j;
|
72 | s += d * (a - m);
|
73 | }
|
74 | }
|
75 | }
|
76 |
|
77 | else {
|
78 | while (++i < n) {
|
79 | if (!isNaN(a = number(f(array[i], i, array)))) {
|
80 | d = a - m;
|
81 | m += d / ++j;
|
82 | s += d * (a - m);
|
83 | }
|
84 | }
|
85 | }
|
86 |
|
87 | if (j > 1) return s / (j - 1);
|
88 | }
|
89 |
|
90 | function deviation(array, f) {
|
91 | var v = variance(array, f);
|
92 | return v ? Math.sqrt(v) : v;
|
93 | }
|
94 |
|
95 | function extent(array, f) {
|
96 | var i = -1,
|
97 | n = array.length,
|
98 | a,
|
99 | b,
|
100 | c;
|
101 |
|
102 | if (f == null) {
|
103 | while (++i < n) if ((b = array[i]) != null && b >= b) { a = c = b; break; }
|
104 | while (++i < n) if ((b = array[i]) != null) {
|
105 | if (a > b) a = b;
|
106 | if (c < b) c = b;
|
107 | }
|
108 | }
|
109 |
|
110 | else {
|
111 | while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = c = b; break; }
|
112 | while (++i < n) if ((b = f(array[i], i, array)) != null) {
|
113 | if (a > b) a = b;
|
114 | if (c < b) c = b;
|
115 | }
|
116 | }
|
117 |
|
118 | return [a, c];
|
119 | }
|
120 |
|
121 | var array = Array.prototype;
|
122 |
|
123 | var slice = array.slice;
|
124 | var map = array.map;
|
125 |
|
126 | function constant(x) {
|
127 | return function() {
|
128 | return x;
|
129 | };
|
130 | }
|
131 |
|
132 | function identity(x) {
|
133 | return x;
|
134 | }
|
135 |
|
136 | function range(start, stop, step) {
|
137 | start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
|
138 |
|
139 | var i = -1,
|
140 | n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
|
141 | range = new Array(n);
|
142 |
|
143 | while (++i < n) {
|
144 | range[i] = start + i * step;
|
145 | }
|
146 |
|
147 | return range;
|
148 | }
|
149 |
|
150 | var e10 = Math.sqrt(50);
|
151 | var e5 = Math.sqrt(10);
|
152 | var e2 = Math.sqrt(2);
|
153 | function ticks(start, stop, count) {
|
154 | var step = tickStep(start, stop, count);
|
155 | return range(
|
156 | Math.ceil(start / step) * step,
|
157 | Math.floor(stop / step) * step + step / 2,
|
158 | step
|
159 | );
|
160 | }
|
161 |
|
162 | function 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;
|
167 | else if (error >= e5) step1 *= 5;
|
168 | else if (error >= e2) step1 *= 2;
|
169 | return stop < start ? -step1 : step1;
|
170 | }
|
171 |
|
172 | function sturges(values) {
|
173 | return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
|
174 | }
|
175 |
|
176 | function histogram() {
|
177 | var value = identity,
|
178 | domain = extent,
|
179 | threshold = sturges;
|
180 |
|
181 | function histogram(data) {
|
182 | var i,
|
183 | n = data.length,
|
184 | x,
|
185 | values = new Array(n);
|
186 |
|
187 | for (i = 0; i < n; ++i) {
|
188 | values[i] = value(data[i], i, data);
|
189 | }
|
190 |
|
191 | var xz = domain(values),
|
192 | x0 = xz[0],
|
193 | x1 = xz[1],
|
194 | tz = threshold(values, x0, x1);
|
195 |
|
196 |
|
197 | if (!Array.isArray(tz)) tz = ticks(x0, x1, tz);
|
198 |
|
199 |
|
200 | var m = tz.length;
|
201 | while (tz[0] <= x0) tz.shift(), --m;
|
202 | while (tz[m - 1] >= x1) tz.pop(), --m;
|
203 |
|
204 | var bins = new Array(m + 1),
|
205 | bin;
|
206 |
|
207 |
|
208 | for (i = 0; i <= m; ++i) {
|
209 | bin = bins[i] = [];
|
210 | bin.x0 = i > 0 ? tz[i - 1] : x0;
|
211 | bin.x1 = i < m ? tz[i] : x1;
|
212 | }
|
213 |
|
214 |
|
215 | for (i = 0; i < n; ++i) {
|
216 | x = values[i];
|
217 | if (x0 <= x && x <= x1) {
|
218 | bins[bisectRight(tz, x, 0, m)].push(data[i]);
|
219 | }
|
220 | }
|
221 |
|
222 | return bins;
|
223 | }
|
224 |
|
225 | histogram.value = function(_) {
|
226 | return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
|
227 | };
|
228 |
|
229 | histogram.domain = function(_) {
|
230 | return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
|
231 | };
|
232 |
|
233 | histogram.thresholds = function(_) {
|
234 | return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
|
235 | };
|
236 |
|
237 | return histogram;
|
238 | }
|
239 |
|
240 | function threshold(array, p, f) {
|
241 | if (f == null) f = number;
|
242 | if (!(n = array.length)) return;
|
243 | if ((p = +p) <= 0 || n < 2) return +f(array[0], 0, array);
|
244 | if (p >= 1) return +f(array[n - 1], n - 1, array);
|
245 | var n,
|
246 | h = (n - 1) * p,
|
247 | i = Math.floor(h),
|
248 | a = +f(array[i], i, array),
|
249 | b = +f(array[i + 1], i + 1, array);
|
250 | return a + (b - a) * (h - i);
|
251 | }
|
252 |
|
253 | function freedmanDiaconis(values, min, max) {
|
254 | values = map.call(values, number).sort(ascending);
|
255 | return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
|
256 | }
|
257 |
|
258 | function scott(values, min, max) {
|
259 | return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
|
260 | }
|
261 |
|
262 | function max(array, f) {
|
263 | var i = -1,
|
264 | n = array.length,
|
265 | a,
|
266 | b;
|
267 |
|
268 | if (f == null) {
|
269 | while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; }
|
270 | while (++i < n) if ((b = array[i]) != null && b > a) a = b;
|
271 | }
|
272 |
|
273 | else {
|
274 | while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = b; break; }
|
275 | while (++i < n) if ((b = f(array[i], i, array)) != null && b > a) a = b;
|
276 | }
|
277 |
|
278 | return a;
|
279 | }
|
280 |
|
281 | function mean(array, f) {
|
282 | var s = 0,
|
283 | n = array.length,
|
284 | a,
|
285 | i = -1,
|
286 | j = n;
|
287 |
|
288 | if (f == null) {
|
289 | while (++i < n) if (!isNaN(a = number(array[i]))) s += a; else --j;
|
290 | }
|
291 |
|
292 | else {
|
293 | while (++i < n) if (!isNaN(a = number(f(array[i], i, array)))) s += a; else --j;
|
294 | }
|
295 |
|
296 | if (j) return s / j;
|
297 | }
|
298 |
|
299 | function median(array, f) {
|
300 | var numbers = [],
|
301 | n = array.length,
|
302 | a,
|
303 | i = -1;
|
304 |
|
305 | if (f == null) {
|
306 | while (++i < n) if (!isNaN(a = number(array[i]))) numbers.push(a);
|
307 | }
|
308 |
|
309 | else {
|
310 | while (++i < n) if (!isNaN(a = number(f(array[i], i, array)))) numbers.push(a);
|
311 | }
|
312 |
|
313 | return threshold(numbers.sort(ascending), 0.5);
|
314 | }
|
315 |
|
316 | function merge(arrays) {
|
317 | var n = arrays.length,
|
318 | m,
|
319 | i = -1,
|
320 | j = 0,
|
321 | merged,
|
322 | array;
|
323 |
|
324 | while (++i < n) j += arrays[i].length;
|
325 | merged = new Array(j);
|
326 |
|
327 | while (--n >= 0) {
|
328 | array = arrays[n];
|
329 | m = array.length;
|
330 | while (--m >= 0) {
|
331 | merged[--j] = array[m];
|
332 | }
|
333 | }
|
334 |
|
335 | return merged;
|
336 | }
|
337 |
|
338 | function min(array, f) {
|
339 | var i = -1,
|
340 | n = array.length,
|
341 | a,
|
342 | b;
|
343 |
|
344 | if (f == null) {
|
345 | while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; }
|
346 | while (++i < n) if ((b = array[i]) != null && a > b) a = b;
|
347 | }
|
348 |
|
349 | else {
|
350 | while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = b; break; }
|
351 | while (++i < n) if ((b = f(array[i], i, array)) != null && a > b) a = b;
|
352 | }
|
353 |
|
354 | return a;
|
355 | }
|
356 |
|
357 | function pairs(array) {
|
358 | var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
|
359 | while (i < n) pairs[i] = [p, p = array[++i]];
|
360 | return pairs;
|
361 | }
|
362 |
|
363 | function permute(array, indexes) {
|
364 | var i = indexes.length, permutes = new Array(i);
|
365 | while (i--) permutes[i] = array[indexes[i]];
|
366 | return permutes;
|
367 | }
|
368 |
|
369 | function scan(array, compare) {
|
370 | if (!(n = array.length)) return;
|
371 | var i = 0,
|
372 | n,
|
373 | j = 0,
|
374 | xi,
|
375 | xj = array[j];
|
376 |
|
377 | if (!compare) compare = ascending;
|
378 |
|
379 | while (++i < n) if (compare(xi = array[i], xj) < 0 || compare(xj, xj) !== 0) xj = xi, j = i;
|
380 |
|
381 | if (compare(xj, xj) === 0) return j;
|
382 | }
|
383 |
|
384 | function shuffle(array, i0, i1) {
|
385 | var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
|
386 | t,
|
387 | i;
|
388 |
|
389 | while (m) {
|
390 | i = Math.random() * m-- | 0;
|
391 | t = array[m + i0];
|
392 | array[m + i0] = array[i + i0];
|
393 | array[i + i0] = t;
|
394 | }
|
395 |
|
396 | return array;
|
397 | }
|
398 |
|
399 | function sum(array, f) {
|
400 | var s = 0,
|
401 | n = array.length,
|
402 | a,
|
403 | i = -1;
|
404 |
|
405 | if (f == null) {
|
406 | while (++i < n) if (a = +array[i]) s += a;
|
407 | }
|
408 |
|
409 | else {
|
410 | while (++i < n) if (a = +f(array[i], i, array)) s += a;
|
411 | }
|
412 |
|
413 | return s;
|
414 | }
|
415 |
|
416 | function transpose(matrix) {
|
417 | if (!(n = matrix.length)) return [];
|
418 | for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
|
419 | for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
|
420 | row[j] = matrix[j][i];
|
421 | }
|
422 | }
|
423 | return transpose;
|
424 | }
|
425 |
|
426 | function length(d) {
|
427 | return d.length;
|
428 | }
|
429 |
|
430 | function zip() {
|
431 | return transpose(arguments);
|
432 | }
|
433 |
|
434 | var prefix = "$";
|
435 |
|
436 | function Map() {}
|
437 |
|
438 | Map.prototype = map$1.prototype = {
|
439 | constructor: Map,
|
440 | has: function(key) {
|
441 | return (prefix + key) in this;
|
442 | },
|
443 | get: function(key) {
|
444 | return this[prefix + key];
|
445 | },
|
446 | set: function(key, value) {
|
447 | this[prefix + key] = value;
|
448 | return this;
|
449 | },
|
450 | remove: function(key) {
|
451 | var property = prefix + key;
|
452 | return property in this && delete this[property];
|
453 | },
|
454 | clear: function() {
|
455 | for (var property in this) if (property[0] === prefix) delete this[property];
|
456 | },
|
457 | keys: function() {
|
458 | var keys = [];
|
459 | for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
|
460 | return keys;
|
461 | },
|
462 | values: function() {
|
463 | var values = [];
|
464 | for (var property in this) if (property[0] === prefix) values.push(this[property]);
|
465 | return values;
|
466 | },
|
467 | entries: function() {
|
468 | var entries = [];
|
469 | for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
|
470 | return entries;
|
471 | },
|
472 | size: function() {
|
473 | var size = 0;
|
474 | for (var property in this) if (property[0] === prefix) ++size;
|
475 | return size;
|
476 | },
|
477 | empty: function() {
|
478 | for (var property in this) if (property[0] === prefix) return false;
|
479 | return true;
|
480 | },
|
481 | each: function(f) {
|
482 | for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
|
483 | }
|
484 | };
|
485 |
|
486 | function map$1(object, f) {
|
487 | var map = new Map;
|
488 |
|
489 |
|
490 | if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
|
491 |
|
492 |
|
493 | else if (Array.isArray(object)) {
|
494 | var i = -1,
|
495 | n = object.length,
|
496 | o;
|
497 |
|
498 | if (f == null) while (++i < n) map.set(i, object[i]);
|
499 | else while (++i < n) map.set(f(o = object[i], i, object), o);
|
500 | }
|
501 |
|
502 |
|
503 | else if (object) for (var key in object) map.set(key, object[key]);
|
504 |
|
505 | return map;
|
506 | }
|
507 |
|
508 | function nest() {
|
509 | var keys = [],
|
510 | sortKeys = [],
|
511 | sortValues,
|
512 | rollup,
|
513 | nest;
|
514 |
|
515 | function apply(array, depth, createResult, setResult) {
|
516 | if (depth >= keys.length) return rollup != null
|
517 | ? rollup(array) : (sortValues != null
|
518 | ? array.sort(sortValues)
|
519 | : array);
|
520 |
|
521 | var i = -1,
|
522 | n = array.length,
|
523 | key = keys[depth++],
|
524 | keyValue,
|
525 | value,
|
526 | valuesByKey = map$1(),
|
527 | values,
|
528 | result = createResult();
|
529 |
|
530 | while (++i < n) {
|
531 | if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
|
532 | values.push(value);
|
533 | } else {
|
534 | valuesByKey.set(keyValue, [value]);
|
535 | }
|
536 | }
|
537 |
|
538 | valuesByKey.each(function(values, key) {
|
539 | setResult(result, key, apply(values, depth, createResult, setResult));
|
540 | });
|
541 |
|
542 | return result;
|
543 | }
|
544 |
|
545 | function entries(map, depth) {
|
546 | if (++depth > keys.length) return map;
|
547 | var array, sortKey = sortKeys[depth - 1];
|
548 | if (rollup != null && depth >= keys.length) array = map.entries();
|
549 | else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
|
550 | return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
|
551 | }
|
552 |
|
553 | return nest = {
|
554 | object: function(array) { return apply(array, 0, createObject, setObject); },
|
555 | map: function(array) { return apply(array, 0, createMap, setMap); },
|
556 | entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
|
557 | key: function(d) { keys.push(d); return nest; },
|
558 | sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
|
559 | sortValues: function(order) { sortValues = order; return nest; },
|
560 | rollup: function(f) { rollup = f; return nest; }
|
561 | };
|
562 | }
|
563 |
|
564 | function createObject() {
|
565 | return {};
|
566 | }
|
567 |
|
568 | function setObject(object, key, value) {
|
569 | object[key] = value;
|
570 | }
|
571 |
|
572 | function createMap() {
|
573 | return map$1();
|
574 | }
|
575 |
|
576 | function setMap(map, key, value) {
|
577 | map.set(key, value);
|
578 | }
|
579 |
|
580 | function Set() {}
|
581 |
|
582 | var proto = map$1.prototype;
|
583 |
|
584 | Set.prototype = set.prototype = {
|
585 | constructor: Set,
|
586 | has: proto.has,
|
587 | add: function(value) {
|
588 | value += "";
|
589 | this[prefix + value] = value;
|
590 | return this;
|
591 | },
|
592 | remove: proto.remove,
|
593 | clear: proto.clear,
|
594 | values: proto.keys,
|
595 | size: proto.size,
|
596 | empty: proto.empty,
|
597 | each: proto.each
|
598 | };
|
599 |
|
600 | function set(object, f) {
|
601 | var set = new Set;
|
602 |
|
603 | // Copy constructor.
|
604 | if (object instanceof Set) object.each(function(value) { set.add(value); });
|
605 |
|
606 | // Otherwise, assume it’s an array.
|
607 | else if (object) {
|
608 | var i = -1, n = object.length;
|
609 | if (f == null) while (++i < n) set.add(object[i]);
|
610 | else while (++i < n) set.add(f(object[i], i, object));
|
611 | }
|
612 |
|
613 | return set;
|
614 | }
|
615 |
|
616 | function keys(map) {
|
617 | var keys = [];
|
618 | for (var key in map) keys.push(key);
|
619 | return keys;
|
620 | }
|
621 |
|
622 | function values(map) {
|
623 | var values = [];
|
624 | for (var key in map) values.push(map[key]);
|
625 | return values;
|
626 | }
|
627 |
|
628 | function entries(map) {
|
629 | var entries = [];
|
630 | for (var key in map) entries.push({key: key, value: map[key]});
|
631 | return entries;
|
632 | }
|
633 |
|
634 | function uniform(min, max) {
|
635 | min = min == null ? 0 : +min;
|
636 | max = max == null ? 1 : +max;
|
637 | if (arguments.length === 1) max = min, min = 0;
|
638 | else max -= min;
|
639 | return function() {
|
640 | return Math.random() * max + min;
|
641 | };
|
642 | }
|
643 |
|
644 | function normal(mu, sigma) {
|
645 | var x, r;
|
646 | mu = mu == null ? 0 : +mu;
|
647 | sigma = sigma == null ? 1 : +sigma;
|
648 | return function() {
|
649 | var y;
|
650 |
|
651 |
|
652 | if (x != null) y = x, x = null;
|
653 |
|
654 |
|
655 | else do {
|
656 | x = Math.random() * 2 - 1;
|
657 | y = Math.random() * 2 - 1;
|
658 | r = x * x + y * y;
|
659 | } while (!r || r > 1);
|
660 |
|
661 | return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
|
662 | };
|
663 | }
|
664 |
|
665 | function logNormal() {
|
666 | var randomNormal = normal.apply(this, arguments);
|
667 | return function() {
|
668 | return Math.exp(randomNormal());
|
669 | };
|
670 | }
|
671 |
|
672 | function irwinHall(n) {
|
673 | return function() {
|
674 | for (var sum = 0, i = 0; i < n; ++i) sum += Math.random();
|
675 | return sum;
|
676 | };
|
677 | }
|
678 |
|
679 | function bates(n) {
|
680 | var randomIrwinHall = irwinHall(n);
|
681 | return function() {
|
682 | return randomIrwinHall() / n;
|
683 | };
|
684 | }
|
685 |
|
686 | function exponential(lambda) {
|
687 | return function() {
|
688 | return -Math.log(1 - Math.random()) / lambda;
|
689 | };
|
690 | }
|
691 |
|
692 | function linear(t) {
|
693 | return +t;
|
694 | }
|
695 |
|
696 | function quadIn(t) {
|
697 | return t * t;
|
698 | }
|
699 |
|
700 | function quadOut(t) {
|
701 | return t * (2 - t);
|
702 | }
|
703 |
|
704 | function quadInOut(t) {
|
705 | return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
|
706 | }
|
707 |
|
708 | function cubicIn(t) {
|
709 | return t * t * t;
|
710 | }
|
711 |
|
712 | function cubicOut(t) {
|
713 | return --t * t * t + 1;
|
714 | }
|
715 |
|
716 | function easeCubicInOut(t) {
|
717 | return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
|
718 | }
|
719 |
|
720 | var exponent = 3;
|
721 |
|
722 | var polyIn = (function custom(e) {
|
723 | e = +e;
|
724 |
|
725 | function polyIn(t) {
|
726 | return Math.pow(t, e);
|
727 | }
|
728 |
|
729 | polyIn.exponent = custom;
|
730 |
|
731 | return polyIn;
|
732 | })(exponent);
|
733 |
|
734 | var polyOut = (function custom(e) {
|
735 | e = +e;
|
736 |
|
737 | function polyOut(t) {
|
738 | return 1 - Math.pow(1 - t, e);
|
739 | }
|
740 |
|
741 | polyOut.exponent = custom;
|
742 |
|
743 | return polyOut;
|
744 | })(exponent);
|
745 |
|
746 | var polyInOut = (function custom(e) {
|
747 | e = +e;
|
748 |
|
749 | function polyInOut(t) {
|
750 | return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
|
751 | }
|
752 |
|
753 | polyInOut.exponent = custom;
|
754 |
|
755 | return polyInOut;
|
756 | })(exponent);
|
757 |
|
758 | var pi = Math.PI;
|
759 | var halfPi = pi / 2;
|
760 | function sinIn(t) {
|
761 | return 1 - Math.cos(t * halfPi);
|
762 | }
|
763 |
|
764 | function sinOut(t) {
|
765 | return Math.sin(t * halfPi);
|
766 | }
|
767 |
|
768 | function sinInOut(t) {
|
769 | return (1 - Math.cos(pi * t)) / 2;
|
770 | }
|
771 |
|
772 | function expIn(t) {
|
773 | return Math.pow(2, 10 * t - 10);
|
774 | }
|
775 |
|
776 | function expOut(t) {
|
777 | return 1 - Math.pow(2, -10 * t);
|
778 | }
|
779 |
|
780 | function expInOut(t) {
|
781 | return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
|
782 | }
|
783 |
|
784 | function circleIn(t) {
|
785 | return 1 - Math.sqrt(1 - t * t);
|
786 | }
|
787 |
|
788 | function circleOut(t) {
|
789 | return Math.sqrt(1 - --t * t);
|
790 | }
|
791 |
|
792 | function circleInOut(t) {
|
793 | return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
|
794 | }
|
795 |
|
796 | var b1 = 4 / 11;
|
797 | var b2 = 6 / 11;
|
798 | var b3 = 8 / 11;
|
799 | var b4 = 3 / 4;
|
800 | var b5 = 9 / 11;
|
801 | var b6 = 10 / 11;
|
802 | var b7 = 15 / 16;
|
803 | var b8 = 21 / 22;
|
804 | var b9 = 63 / 64;
|
805 | var b0 = 1 / b1 / b1;
|
806 | function bounceIn(t) {
|
807 | return 1 - bounceOut(1 - t);
|
808 | }
|
809 |
|
810 | function bounceOut(t) {
|
811 | 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;
|
812 | }
|
813 |
|
814 | function bounceInOut(t) {
|
815 | return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
|
816 | }
|
817 |
|
818 | var overshoot = 1.70158;
|
819 |
|
820 | var backIn = (function custom(s) {
|
821 | s = +s;
|
822 |
|
823 | function backIn(t) {
|
824 | return t * t * ((s + 1) * t - s);
|
825 | }
|
826 |
|
827 | backIn.overshoot = custom;
|
828 |
|
829 | return backIn;
|
830 | })(overshoot);
|
831 |
|
832 | var backOut = (function custom(s) {
|
833 | s = +s;
|
834 |
|
835 | function backOut(t) {
|
836 | return --t * t * ((s + 1) * t + s) + 1;
|
837 | }
|
838 |
|
839 | backOut.overshoot = custom;
|
840 |
|
841 | return backOut;
|
842 | })(overshoot);
|
843 |
|
844 | var backInOut = (function custom(s) {
|
845 | s = +s;
|
846 |
|
847 | function backInOut(t) {
|
848 | return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
|
849 | }
|
850 |
|
851 | backInOut.overshoot = custom;
|
852 |
|
853 | return backInOut;
|
854 | })(overshoot);
|
855 |
|
856 | var tau = 2 * Math.PI;
|
857 | var amplitude = 1;
|
858 | var period = 0.3;
|
859 | var elasticIn = (function custom(a, p) {
|
860 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
|
861 |
|
862 | function elasticIn(t) {
|
863 | return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
|
864 | }
|
865 |
|
866 | elasticIn.amplitude = function(a) { return custom(a, p * tau); };
|
867 | elasticIn.period = function(p) { return custom(a, p); };
|
868 |
|
869 | return elasticIn;
|
870 | })(amplitude, period);
|
871 |
|
872 | var elasticOut = (function custom(a, p) {
|
873 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
|
874 |
|
875 | function elasticOut(t) {
|
876 | return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
|
877 | }
|
878 |
|
879 | elasticOut.amplitude = function(a) { return custom(a, p * tau); };
|
880 | elasticOut.period = function(p) { return custom(a, p); };
|
881 |
|
882 | return elasticOut;
|
883 | })(amplitude, period);
|
884 |
|
885 | var elasticInOut = (function custom(a, p) {
|
886 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
|
887 |
|
888 | function elasticInOut(t) {
|
889 | return ((t = t * 2 - 1) < 0
|
890 | ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
|
891 | : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
|
892 | }
|
893 |
|
894 | elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
|
895 | elasticInOut.period = function(p) { return custom(a, p); };
|
896 |
|
897 | return elasticInOut;
|
898 | })(amplitude, period);
|
899 |
|
900 | function area(polygon) {
|
901 | var i = -1,
|
902 | n = polygon.length,
|
903 | a,
|
904 | b = polygon[n - 1],
|
905 | area = 0;
|
906 |
|
907 | while (++i < n) {
|
908 | a = b;
|
909 | b = polygon[i];
|
910 | area += a[1] * b[0] - a[0] * b[1];
|
911 | }
|
912 |
|
913 | return area / 2;
|
914 | }
|
915 |
|
916 | function centroid(polygon) {
|
917 | var i = -1,
|
918 | n = polygon.length,
|
919 | x = 0,
|
920 | y = 0,
|
921 | a,
|
922 | b = polygon[n - 1],
|
923 | c,
|
924 | k = 0;
|
925 |
|
926 | while (++i < n) {
|
927 | a = b;
|
928 | b = polygon[i];
|
929 | k += c = a[0] * b[1] - b[0] * a[1];
|
930 | x += (a[0] + b[0]) * c;
|
931 | y += (a[1] + b[1]) * c;
|
932 | }
|
933 |
|
934 | return k *= 3, [x / k, y / k];
|
935 | }
|
936 |
|
937 |
|
938 |
|
939 |
|
940 |
|
941 | function cross(a, b, c) {
|
942 | return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
943 | }
|
944 |
|
945 | function lexicographicOrder(a, b) {
|
946 | return a[0] - b[0] || a[1] - b[1];
|
947 | }
|
948 |
|
949 |
|
950 |
|
951 |
|
952 | function computeUpperHullIndexes(points) {
|
953 | var n = points.length,
|
954 | indexes = [0, 1],
|
955 | size = 2;
|
956 |
|
957 | for (var i = 2; i < n; ++i) {
|
958 | while (size > 1 && cross(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
|
959 | indexes[size++] = i;
|
960 | }
|
961 |
|
962 | return indexes.slice(0, size);
|
963 | }
|
964 |
|
965 | function hull(points) {
|
966 | if ((n = points.length) < 3) return null;
|
967 |
|
968 | var i,
|
969 | n,
|
970 | sortedPoints = new Array(n),
|
971 | flippedPoints = new Array(n);
|
972 |
|
973 | for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
|
974 | sortedPoints.sort(lexicographicOrder);
|
975 | for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
|
976 |
|
977 | var upperIndexes = computeUpperHullIndexes(sortedPoints),
|
978 | lowerIndexes = computeUpperHullIndexes(flippedPoints);
|
979 |
|
980 |
|
981 | var skipLeft = lowerIndexes[0] === upperIndexes[0],
|
982 | skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
|
983 | hull = [];
|
984 |
|
985 |
|
986 |
|
987 | for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
|
988 | for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
|
989 |
|
990 | return hull;
|
991 | }
|
992 |
|
993 | function contains(polygon, point) {
|
994 | var n = polygon.length,
|
995 | p = polygon[n - 1],
|
996 | x = point[0], y = point[1],
|
997 | x0 = p[0], y0 = p[1],
|
998 | x1, y1,
|
999 | inside = false;
|
1000 |
|
1001 | for (var i = 0; i < n; ++i) {
|
1002 | p = polygon[i], x1 = p[0], y1 = p[1];
|
1003 | if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
|
1004 | x0 = x1, y0 = y1;
|
1005 | }
|
1006 |
|
1007 | return inside;
|
1008 | }
|
1009 |
|
1010 | function length$1(polygon) {
|
1011 | var i = -1,
|
1012 | n = polygon.length,
|
1013 | b = polygon[n - 1],
|
1014 | xa,
|
1015 | ya,
|
1016 | xb = b[0],
|
1017 | yb = b[1],
|
1018 | perimeter = 0;
|
1019 |
|
1020 | while (++i < n) {
|
1021 | xa = xb;
|
1022 | ya = yb;
|
1023 | b = polygon[i];
|
1024 | xb = b[0];
|
1025 | yb = b[1];
|
1026 | xa -= xb;
|
1027 | ya -= yb;
|
1028 | perimeter += Math.sqrt(xa * xa + ya * ya);
|
1029 | }
|
1030 |
|
1031 | return perimeter;
|
1032 | }
|
1033 |
|
1034 | var pi$1 = Math.PI;
|
1035 | var tau$1 = 2 * pi$1;
|
1036 | var epsilon = 1e-6;
|
1037 | var tauEpsilon = tau$1 - epsilon;
|
1038 | function Path() {
|
1039 | this._x0 = this._y0 =
|
1040 | this._x1 = this._y1 = null;
|
1041 | this._ = [];
|
1042 | }
|
1043 |
|
1044 | function path() {
|
1045 | return new Path;
|
1046 | }
|
1047 |
|
1048 | Path.prototype = path.prototype = {
|
1049 | constructor: Path,
|
1050 | moveTo: function(x, y) {
|
1051 | this._.push("M", this._x0 = this._x1 = +x, ",", this._y0 = this._y1 = +y);
|
1052 | },
|
1053 | closePath: function() {
|
1054 | if (this._x1 !== null) {
|
1055 | this._x1 = this._x0, this._y1 = this._y0;
|
1056 | this._.push("Z");
|
1057 | }
|
1058 | },
|
1059 | lineTo: function(x, y) {
|
1060 | this._.push("L", this._x1 = +x, ",", this._y1 = +y);
|
1061 | },
|
1062 | quadraticCurveTo: function(x1, y1, x, y) {
|
1063 | this._.push("Q", +x1, ",", +y1, ",", this._x1 = +x, ",", this._y1 = +y);
|
1064 | },
|
1065 | bezierCurveTo: function(x1, y1, x2, y2, x, y) {
|
1066 | this._.push("C", +x1, ",", +y1, ",", +x2, ",", +y2, ",", this._x1 = +x, ",", this._y1 = +y);
|
1067 | },
|
1068 | arcTo: function(x1, y1, x2, y2, r) {
|
1069 | x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
|
1070 | var x0 = this._x1,
|
1071 | y0 = this._y1,
|
1072 | x21 = x2 - x1,
|
1073 | y21 = y2 - y1,
|
1074 | x01 = x0 - x1,
|
1075 | y01 = y0 - y1,
|
1076 | l01_2 = x01 * x01 + y01 * y01;
|
1077 |
|
1078 |
|
1079 | if (r < 0) throw new Error("negative radius: " + r);
|
1080 |
|
1081 |
|
1082 | if (this._x1 === null) {
|
1083 | this._.push(
|
1084 | "M", this._x1 = x1, ",", this._y1 = y1
|
1085 | );
|
1086 | }
|
1087 |
|
1088 |
|
1089 | else if (!(l01_2 > epsilon));
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 | else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon) || !r) {
|
1095 | this._.push(
|
1096 | "L", this._x1 = x1, ",", this._y1 = y1
|
1097 | );
|
1098 | }
|
1099 |
|
1100 |
|
1101 | else {
|
1102 | var x20 = x2 - x0,
|
1103 | y20 = y2 - y0,
|
1104 | l21_2 = x21 * x21 + y21 * y21,
|
1105 | l20_2 = x20 * x20 + y20 * y20,
|
1106 | l21 = Math.sqrt(l21_2),
|
1107 | l01 = Math.sqrt(l01_2),
|
1108 | l = r * Math.tan((pi$1 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
|
1109 | t01 = l / l01,
|
1110 | t21 = l / l21;
|
1111 |
|
1112 |
|
1113 | if (Math.abs(t01 - 1) > epsilon) {
|
1114 | this._.push(
|
1115 | "L", x1 + t01 * x01, ",", y1 + t01 * y01
|
1116 | );
|
1117 | }
|
1118 |
|
1119 | this._.push(
|
1120 | "A", r, ",", r, ",0,0,", +(y01 * x20 > x01 * y20), ",", this._x1 = x1 + t21 * x21, ",", this._y1 = y1 + t21 * y21
|
1121 | );
|
1122 | }
|
1123 | },
|
1124 | arc: function(x, y, r, a0, a1, ccw) {
|
1125 | x = +x, y = +y, r = +r;
|
1126 | var dx = r * Math.cos(a0),
|
1127 | dy = r * Math.sin(a0),
|
1128 | x0 = x + dx,
|
1129 | y0 = y + dy,
|
1130 | cw = 1 ^ ccw,
|
1131 | da = ccw ? a0 - a1 : a1 - a0;
|
1132 |
|
1133 |
|
1134 | if (r < 0) throw new Error("negative radius: " + r);
|
1135 |
|
1136 |
|
1137 | if (this._x1 === null) {
|
1138 | this._.push(
|
1139 | "M", x0, ",", y0
|
1140 | );
|
1141 | }
|
1142 |
|
1143 |
|
1144 | else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) {
|
1145 | this._.push(
|
1146 | "L", x0, ",", y0
|
1147 | );
|
1148 | }
|
1149 |
|
1150 |
|
1151 | if (!r) return;
|
1152 |
|
1153 |
|
1154 | if (da > tauEpsilon) {
|
1155 | this._.push(
|
1156 | "A", r, ",", r, ",0,1,", cw, ",", x - dx, ",", y - dy,
|
1157 | "A", r, ",", r, ",0,1,", cw, ",", this._x1 = x0, ",", this._y1 = y0
|
1158 | );
|
1159 | }
|
1160 |
|
1161 |
|
1162 | else {
|
1163 | if (da < 0) da = da % tau$1 + tau$1;
|
1164 | this._.push(
|
1165 | "A", r, ",", r, ",0,", +(da >= pi$1), ",", cw, ",", this._x1 = x + r * Math.cos(a1), ",", this._y1 = y + r * Math.sin(a1)
|
1166 | );
|
1167 | }
|
1168 | },
|
1169 | rect: function(x, y, w, h) {
|
1170 | this._.push("M", this._x0 = this._x1 = +x, ",", this._y0 = this._y1 = +y, "h", +w, "v", +h, "h", -w, "Z");
|
1171 | },
|
1172 | toString: function() {
|
1173 | return this._.join("");
|
1174 | }
|
1175 | };
|
1176 |
|
1177 | function tree_add(d) {
|
1178 | var x = +this._x.call(null, d),
|
1179 | y = +this._y.call(null, d);
|
1180 | return add(this.cover(x, y), x, y, d);
|
1181 | }
|
1182 |
|
1183 | function add(tree, x, y, d) {
|
1184 | if (isNaN(x) || isNaN(y)) return tree;
|
1185 |
|
1186 | var parent,
|
1187 | node = tree._root,
|
1188 | leaf = {data: d},
|
1189 | x0 = tree._x0,
|
1190 | y0 = tree._y0,
|
1191 | x1 = tree._x1,
|
1192 | y1 = tree._y1,
|
1193 | xm,
|
1194 | ym,
|
1195 | xp,
|
1196 | yp,
|
1197 | right,
|
1198 | bottom,
|
1199 | i,
|
1200 | j;
|
1201 |
|
1202 |
|
1203 | if (!node) return tree._root = leaf, tree;
|
1204 |
|
1205 |
|
1206 | while (node.length) {
|
1207 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
1208 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
1209 | if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
|
1210 | }
|
1211 |
|
1212 |
|
1213 | xp = +tree._x.call(null, node.data);
|
1214 | yp = +tree._y.call(null, node.data);
|
1215 | if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
|
1216 |
|
1217 |
|
1218 | do {
|
1219 | parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
|
1220 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
1221 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
1222 | } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
|
1223 | return parent[j] = node, parent[i] = leaf, tree;
|
1224 | }
|
1225 |
|
1226 | function addAll(data) {
|
1227 | var d, i, n = data.length,
|
1228 | x,
|
1229 | y,
|
1230 | xz = new Array(n),
|
1231 | yz = new Array(n),
|
1232 | x0 = Infinity,
|
1233 | y0 = Infinity,
|
1234 | x1 = -Infinity,
|
1235 | y1 = -Infinity;
|
1236 |
|
1237 |
|
1238 | for (i = 0; i < n; ++i) {
|
1239 | if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
|
1240 | xz[i] = x;
|
1241 | yz[i] = y;
|
1242 | if (x < x0) x0 = x;
|
1243 | if (x > x1) x1 = x;
|
1244 | if (y < y0) y0 = y;
|
1245 | if (y > y1) y1 = y;
|
1246 | }
|
1247 |
|
1248 |
|
1249 | if (x1 < x0) x0 = this._x0, x1 = this._x1;
|
1250 | if (y1 < y0) y0 = this._y0, y1 = this._y1;
|
1251 |
|
1252 |
|
1253 | this.cover(x0, y0).cover(x1, y1);
|
1254 |
|
1255 |
|
1256 | for (i = 0; i < n; ++i) {
|
1257 | add(this, xz[i], yz[i], data[i]);
|
1258 | }
|
1259 |
|
1260 | return this;
|
1261 | }
|
1262 |
|
1263 | function tree_cover(x, y) {
|
1264 | if (isNaN(x = +x) || isNaN(y = +y)) return this;
|
1265 |
|
1266 | var x0 = this._x0,
|
1267 | y0 = this._y0,
|
1268 | x1 = this._x1,
|
1269 | y1 = this._y1;
|
1270 |
|
1271 |
|
1272 |
|
1273 |
|
1274 | if (isNaN(x0)) {
|
1275 | x1 = (x0 = Math.floor(x)) + 1;
|
1276 | y1 = (y0 = Math.floor(y)) + 1;
|
1277 | }
|
1278 |
|
1279 |
|
1280 | else if (x0 > x || x > x1 || y0 > y || y > y1) {
|
1281 | var z = x1 - x0,
|
1282 | node = this._root,
|
1283 | parent,
|
1284 | i;
|
1285 |
|
1286 | switch (i = (y < (y0 + y1) / 2) << 1 | (x < (x0 + x1) / 2)) {
|
1287 | case 0: {
|
1288 | do parent = new Array(4), parent[i] = node, node = parent;
|
1289 | while (z *= 2, x1 = x0 + z, y1 = y0 + z, x > x1 || y > y1);
|
1290 | break;
|
1291 | }
|
1292 | case 1: {
|
1293 | do parent = new Array(4), parent[i] = node, node = parent;
|
1294 | while (z *= 2, x0 = x1 - z, y1 = y0 + z, x0 > x || y > y1);
|
1295 | break;
|
1296 | }
|
1297 | case 2: {
|
1298 | do parent = new Array(4), parent[i] = node, node = parent;
|
1299 | while (z *= 2, x1 = x0 + z, y0 = y1 - z, x > x1 || y0 > y);
|
1300 | break;
|
1301 | }
|
1302 | case 3: {
|
1303 | do parent = new Array(4), parent[i] = node, node = parent;
|
1304 | while (z *= 2, x0 = x1 - z, y0 = y1 - z, x0 > x || y0 > y);
|
1305 | break;
|
1306 | }
|
1307 | }
|
1308 |
|
1309 | if (this._root && this._root.length) this._root = node;
|
1310 | }
|
1311 |
|
1312 |
|
1313 | else return this;
|
1314 |
|
1315 | this._x0 = x0;
|
1316 | this._y0 = y0;
|
1317 | this._x1 = x1;
|
1318 | this._y1 = y1;
|
1319 | return this;
|
1320 | }
|
1321 |
|
1322 | function tree_data() {
|
1323 | var data = [];
|
1324 | this.visit(function(node) {
|
1325 | if (!node.length) do data.push(node.data); while (node = node.next)
|
1326 | });
|
1327 | return data;
|
1328 | }
|
1329 |
|
1330 | function tree_extent(_) {
|
1331 | return arguments.length
|
1332 | ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
|
1333 | : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
|
1334 | }
|
1335 |
|
1336 | function Quad(node, x0, y0, x1, y1) {
|
1337 | this.node = node;
|
1338 | this.x0 = x0;
|
1339 | this.y0 = y0;
|
1340 | this.x1 = x1;
|
1341 | this.y1 = y1;
|
1342 | }
|
1343 |
|
1344 | function tree_find(x, y, radius) {
|
1345 | var data,
|
1346 | x0 = this._x0,
|
1347 | y0 = this._y0,
|
1348 | x1,
|
1349 | y1,
|
1350 | x2,
|
1351 | y2,
|
1352 | x3 = this._x1,
|
1353 | y3 = this._y1,
|
1354 | quads = [],
|
1355 | node = this._root,
|
1356 | q,
|
1357 | i;
|
1358 |
|
1359 | if (node) quads.push(new Quad(node, x0, y0, x3, y3));
|
1360 | if (radius == null) radius = Infinity;
|
1361 | else {
|
1362 | x0 = x - radius, y0 = y - radius;
|
1363 | x3 = x + radius, y3 = y + radius;
|
1364 | radius *= radius;
|
1365 | }
|
1366 |
|
1367 | while (q = quads.pop()) {
|
1368 |
|
1369 |
|
1370 | if (!(node = q.node)
|
1371 | || (x1 = q.x0) > x3
|
1372 | || (y1 = q.y0) > y3
|
1373 | || (x2 = q.x1) < x0
|
1374 | || (y2 = q.y1) < y0) continue;
|
1375 |
|
1376 |
|
1377 | if (node.length) {
|
1378 | var xm = (x1 + x2) / 2,
|
1379 | ym = (y1 + y2) / 2;
|
1380 |
|
1381 | quads.push(
|
1382 | new Quad(node[3], xm, ym, x2, y2),
|
1383 | new Quad(node[2], x1, ym, xm, y2),
|
1384 | new Quad(node[1], xm, y1, x2, ym),
|
1385 | new Quad(node[0], x1, y1, xm, ym)
|
1386 | );
|
1387 |
|
1388 |
|
1389 | if (i = (y >= ym) << 1 | (x >= xm)) {
|
1390 | q = quads[quads.length - 1];
|
1391 | quads[quads.length - 1] = quads[quads.length - 1 - i];
|
1392 | quads[quads.length - 1 - i] = q;
|
1393 | }
|
1394 | }
|
1395 |
|
1396 |
|
1397 | else {
|
1398 | var dx = x - +this._x.call(null, node.data),
|
1399 | dy = y - +this._y.call(null, node.data),
|
1400 | d2 = dx * dx + dy * dy;
|
1401 | if (d2 < radius) {
|
1402 | var d = Math.sqrt(radius = d2);
|
1403 | x0 = x - d, y0 = y - d;
|
1404 | x3 = x + d, y3 = y + d;
|
1405 | data = node.data;
|
1406 | }
|
1407 | }
|
1408 | }
|
1409 |
|
1410 | return data;
|
1411 | }
|
1412 |
|
1413 | function tree_remove(d) {
|
1414 | if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this;
|
1415 |
|
1416 | var parent,
|
1417 | node = this._root,
|
1418 | retainer,
|
1419 | previous,
|
1420 | next,
|
1421 | x0 = this._x0,
|
1422 | y0 = this._y0,
|
1423 | x1 = this._x1,
|
1424 | y1 = this._y1,
|
1425 | x,
|
1426 | y,
|
1427 | xm,
|
1428 | ym,
|
1429 | right,
|
1430 | bottom,
|
1431 | i,
|
1432 | j;
|
1433 |
|
1434 |
|
1435 | if (!node) return this;
|
1436 |
|
1437 |
|
1438 |
|
1439 | if (node.length) while (true) {
|
1440 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
1441 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
1442 | if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
|
1443 | if (!node.length) break;
|
1444 | if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
|
1445 | }
|
1446 |
|
1447 |
|
1448 | while (node.data !== d) if (!(previous = node, node = node.next)) return this;
|
1449 | if (next = node.next) delete node.next;
|
1450 |
|
1451 |
|
1452 | if (previous) return (next ? previous.next = next : delete previous.next), this;
|
1453 |
|
1454 |
|
1455 | if (!parent) return this._root = next, this;
|
1456 |
|
1457 |
|
1458 | next ? parent[i] = next : delete parent[i];
|
1459 |
|
1460 |
|
1461 | if ((node = parent[0] || parent[1] || parent[2] || parent[3])
|
1462 | && node === (parent[3] || parent[2] || parent[1] || parent[0])
|
1463 | && !node.length) {
|
1464 | if (retainer) retainer[j] = node;
|
1465 | else this._root = node;
|
1466 | }
|
1467 |
|
1468 | return this;
|
1469 | }
|
1470 |
|
1471 | function removeAll(data) {
|
1472 | for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
|
1473 | return this;
|
1474 | }
|
1475 |
|
1476 | function tree_root() {
|
1477 | return this._root;
|
1478 | }
|
1479 |
|
1480 | function tree_size() {
|
1481 | var size = 0;
|
1482 | this.visit(function(node) {
|
1483 | if (!node.length) do ++size; while (node = node.next)
|
1484 | });
|
1485 | return size;
|
1486 | }
|
1487 |
|
1488 | function tree_visit(callback) {
|
1489 | var quads = [], q, node = this._root, child, x0, y0, x1, y1;
|
1490 | if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
|
1491 | while (q = quads.pop()) {
|
1492 | if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
|
1493 | var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
1494 | if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
1495 | if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
1496 | if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
1497 | if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
1498 | }
|
1499 | }
|
1500 | return this;
|
1501 | }
|
1502 |
|
1503 | function tree_visitAfter(callback) {
|
1504 | var quads = [], next = [], q;
|
1505 | if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
|
1506 | while (q = quads.pop()) {
|
1507 | var node = q.node;
|
1508 | if (node.length) {
|
1509 | var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
1510 | if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
1511 | if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
1512 | if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
1513 | if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
1514 | }
|
1515 | next.push(q);
|
1516 | }
|
1517 | while (q = next.pop()) {
|
1518 | callback(q.node, q.x0, q.y0, q.x1, q.y1);
|
1519 | }
|
1520 | return this;
|
1521 | }
|
1522 |
|
1523 | function defaultX(d) {
|
1524 | return d[0];
|
1525 | }
|
1526 |
|
1527 | function tree_x(_) {
|
1528 | return arguments.length ? (this._x = _, this) : this._x;
|
1529 | }
|
1530 |
|
1531 | function defaultY(d) {
|
1532 | return d[1];
|
1533 | }
|
1534 |
|
1535 | function tree_y(_) {
|
1536 | return arguments.length ? (this._y = _, this) : this._y;
|
1537 | }
|
1538 |
|
1539 | function quadtree(nodes, x, y) {
|
1540 | var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
|
1541 | return nodes == null ? tree : tree.addAll(nodes);
|
1542 | }
|
1543 |
|
1544 | function Quadtree(x, y, x0, y0, x1, y1) {
|
1545 | this._x = x;
|
1546 | this._y = y;
|
1547 | this._x0 = x0;
|
1548 | this._y0 = y0;
|
1549 | this._x1 = x1;
|
1550 | this._y1 = y1;
|
1551 | this._root = undefined;
|
1552 | }
|
1553 |
|
1554 | function leaf_copy(leaf) {
|
1555 | var copy = {data: leaf.data}, next = copy;
|
1556 | while (leaf = leaf.next) next = next.next = {data: leaf.data};
|
1557 | return copy;
|
1558 | }
|
1559 |
|
1560 | var treeProto = quadtree.prototype = Quadtree.prototype;
|
1561 |
|
1562 | treeProto.copy = function() {
|
1563 | var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
|
1564 | node = this._root,
|
1565 | nodes,
|
1566 | child;
|
1567 |
|
1568 | if (!node) return copy;
|
1569 |
|
1570 | if (!node.length) return copy._root = leaf_copy(node), copy;
|
1571 |
|
1572 | nodes = [{source: node, target: copy._root = new Array(4)}];
|
1573 | while (node = nodes.pop()) {
|
1574 | for (var i = 0; i < 4; ++i) {
|
1575 | if (child = node.source[i]) {
|
1576 | if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
|
1577 | else node.target[i] = leaf_copy(child);
|
1578 | }
|
1579 | }
|
1580 | }
|
1581 |
|
1582 | return copy;
|
1583 | };
|
1584 |
|
1585 | treeProto.add = tree_add;
|
1586 | treeProto.addAll = addAll;
|
1587 | treeProto.cover = tree_cover;
|
1588 | treeProto.data = tree_data;
|
1589 | treeProto.extent = tree_extent;
|
1590 | treeProto.find = tree_find;
|
1591 | treeProto.remove = tree_remove;
|
1592 | treeProto.removeAll = removeAll;
|
1593 | treeProto.root = tree_root;
|
1594 | treeProto.size = tree_size;
|
1595 | treeProto.visit = tree_visit;
|
1596 | treeProto.visitAfter = tree_visitAfter;
|
1597 | treeProto.x = tree_x;
|
1598 | treeProto.y = tree_y;
|
1599 |
|
1600 | var slice$1 = [].slice;
|
1601 |
|
1602 | var noabort = {};
|
1603 |
|
1604 | function Queue(size) {
|
1605 | if (!(size >= 1)) throw new Error;
|
1606 | this._size = size;
|
1607 | this._call =
|
1608 | this._error = null;
|
1609 | this._tasks = [];
|
1610 | this._data = [];
|
1611 | this._waiting =
|
1612 | this._active =
|
1613 | this._ended =
|
1614 | this._start = 0;
|
1615 | }
|
1616 |
|
1617 | Queue.prototype = queue.prototype = {
|
1618 | constructor: Queue,
|
1619 | defer: function(callback) {
|
1620 | if (typeof callback !== "function" || this._call) throw new Error;
|
1621 | if (this._error != null) return this;
|
1622 | var t = slice$1.call(arguments, 1);
|
1623 | t.push(callback);
|
1624 | ++this._waiting, this._tasks.push(t);
|
1625 | poke(this);
|
1626 | return this;
|
1627 | },
|
1628 | abort: function() {
|
1629 | if (this._error == null) abort(this, new Error("abort"));
|
1630 | return this;
|
1631 | },
|
1632 | await: function(callback) {
|
1633 | if (typeof callback !== "function" || this._call) throw new Error;
|
1634 | this._call = function(error, results) { callback.apply(null, [error].concat(results)); };
|
1635 | maybeNotify(this);
|
1636 | return this;
|
1637 | },
|
1638 | awaitAll: function(callback) {
|
1639 | if (typeof callback !== "function" || this._call) throw new Error;
|
1640 | this._call = callback;
|
1641 | maybeNotify(this);
|
1642 | return this;
|
1643 | }
|
1644 | };
|
1645 |
|
1646 | function poke(q) {
|
1647 | if (!q._start) try { start(q); }
|
1648 | catch (e) { if (q._tasks[q._ended + q._active - 1]) abort(q, e); }
|
1649 | }
|
1650 |
|
1651 | function start(q) {
|
1652 | while (q._start = q._waiting && q._active < q._size) {
|
1653 | var i = q._ended + q._active,
|
1654 | t = q._tasks[i],
|
1655 | j = t.length - 1,
|
1656 | c = t[j];
|
1657 | t[j] = end(q, i);
|
1658 | --q._waiting, ++q._active;
|
1659 | t = c.apply(null, t);
|
1660 | if (!q._tasks[i]) continue;
|
1661 | q._tasks[i] = t || noabort;
|
1662 | }
|
1663 | }
|
1664 |
|
1665 | function end(q, i) {
|
1666 | return function(e, r) {
|
1667 | if (!q._tasks[i]) return;
|
1668 | --q._active, ++q._ended;
|
1669 | q._tasks[i] = null;
|
1670 | if (q._error != null) return;
|
1671 | if (e != null) {
|
1672 | abort(q, e);
|
1673 | } else {
|
1674 | q._data[i] = r;
|
1675 | if (q._waiting) poke(q);
|
1676 | else maybeNotify(q);
|
1677 | }
|
1678 | };
|
1679 | }
|
1680 |
|
1681 | function abort(q, e) {
|
1682 | var i = q._tasks.length, t;
|
1683 | q._error = e;
|
1684 | q._data = undefined;
|
1685 | q._waiting = NaN;
|
1686 |
|
1687 | while (--i >= 0) {
|
1688 | if (t = q._tasks[i]) {
|
1689 | q._tasks[i] = null;
|
1690 | if (t.abort) try { t.abort(); }
|
1691 | catch (e) { }
|
1692 | }
|
1693 | }
|
1694 |
|
1695 | q._active = NaN;
|
1696 | maybeNotify(q);
|
1697 | }
|
1698 |
|
1699 | function maybeNotify(q) {
|
1700 | if (!q._active && q._call) q._call(q._error, q._data);
|
1701 | }
|
1702 |
|
1703 | function queue(concurrency) {
|
1704 | return new Queue(arguments.length ? +concurrency : Infinity);
|
1705 | }
|
1706 |
|
1707 | function constant$1(x) {
|
1708 | return function constant() {
|
1709 | return x;
|
1710 | };
|
1711 | }
|
1712 |
|
1713 | var epsilon$1 = 1e-12;
|
1714 | var pi$2 = Math.PI;
|
1715 | var halfPi$1 = pi$2 / 2;
|
1716 | var tau$2 = 2 * pi$2;
|
1717 |
|
1718 | function arcInnerRadius(d) {
|
1719 | return d.innerRadius;
|
1720 | }
|
1721 |
|
1722 | function arcOuterRadius(d) {
|
1723 | return d.outerRadius;
|
1724 | }
|
1725 |
|
1726 | function arcStartAngle(d) {
|
1727 | return d.startAngle;
|
1728 | }
|
1729 |
|
1730 | function arcEndAngle(d) {
|
1731 | return d.endAngle;
|
1732 | }
|
1733 |
|
1734 | function arcPadAngle(d) {
|
1735 | return d && d.padAngle;
|
1736 | }
|
1737 |
|
1738 | function asin(x) {
|
1739 | return x >= 1 ? halfPi$1 : x <= -1 ? -halfPi$1 : Math.asin(x);
|
1740 | }
|
1741 |
|
1742 | function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
|
1743 | var x10 = x1 - x0, y10 = y1 - y0,
|
1744 | x32 = x3 - x2, y32 = y3 - y2,
|
1745 | t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
|
1746 | return [x0 + t * x10, y0 + t * y10];
|
1747 | }
|
1748 |
|
1749 |
|
1750 |
|
1751 | function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
|
1752 | var x01 = x0 - x1,
|
1753 | y01 = y0 - y1,
|
1754 | lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01),
|
1755 | ox = lo * y01,
|
1756 | oy = -lo * x01,
|
1757 | x11 = x0 + ox,
|
1758 | y11 = y0 + oy,
|
1759 | x10 = x1 + ox,
|
1760 | y10 = y1 + oy,
|
1761 | x00 = (x11 + x10) / 2,
|
1762 | y00 = (y11 + y10) / 2,
|
1763 | dx = x10 - x11,
|
1764 | dy = y10 - y11,
|
1765 | d2 = dx * dx + dy * dy,
|
1766 | r = r1 - rc,
|
1767 | D = x11 * y10 - x10 * y11,
|
1768 | d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)),
|
1769 | cx0 = (D * dy - dx * d) / d2,
|
1770 | cy0 = (-D * dx - dy * d) / d2,
|
1771 | cx1 = (D * dy + dx * d) / d2,
|
1772 | cy1 = (-D * dx + dy * d) / d2,
|
1773 | dx0 = cx0 - x00,
|
1774 | dy0 = cy0 - y00,
|
1775 | dx1 = cx1 - x00,
|
1776 | dy1 = cy1 - y00;
|
1777 |
|
1778 |
|
1779 |
|
1780 | if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
|
1781 |
|
1782 | return {
|
1783 | cx: cx0,
|
1784 | cy: cy0,
|
1785 | x01: -ox,
|
1786 | y01: -oy,
|
1787 | x11: cx0 * (r1 / r - 1),
|
1788 | y11: cy0 * (r1 / r - 1)
|
1789 | };
|
1790 | }
|
1791 |
|
1792 | function arc() {
|
1793 | var innerRadius = arcInnerRadius,
|
1794 | outerRadius = arcOuterRadius,
|
1795 | cornerRadius = constant$1(0),
|
1796 | padRadius = null,
|
1797 | startAngle = arcStartAngle,
|
1798 | endAngle = arcEndAngle,
|
1799 | padAngle = arcPadAngle,
|
1800 | context = null;
|
1801 |
|
1802 | function arc() {
|
1803 | var buffer,
|
1804 | r,
|
1805 | r0 = +innerRadius.apply(this, arguments),
|
1806 | r1 = +outerRadius.apply(this, arguments),
|
1807 | a0 = startAngle.apply(this, arguments) - halfPi$1,
|
1808 | a1 = endAngle.apply(this, arguments) - halfPi$1,
|
1809 | da = Math.abs(a1 - a0),
|
1810 | cw = a1 > a0;
|
1811 |
|
1812 | if (!context) context = buffer = path();
|
1813 |
|
1814 |
|
1815 | if (r1 < r0) r = r1, r1 = r0, r0 = r;
|
1816 |
|
1817 |
|
1818 | if (!(r1 > epsilon$1)) context.moveTo(0, 0);
|
1819 |
|
1820 |
|
1821 | else if (da > tau$2 - epsilon$1) {
|
1822 | context.moveTo(r1 * Math.cos(a0), r1 * Math.sin(a0));
|
1823 | context.arc(0, 0, r1, a0, a1, !cw);
|
1824 | if (r0 > epsilon$1) {
|
1825 | context.moveTo(r0 * Math.cos(a1), r0 * Math.sin(a1));
|
1826 | context.arc(0, 0, r0, a1, a0, cw);
|
1827 | }
|
1828 | }
|
1829 |
|
1830 |
|
1831 | else {
|
1832 | var a01 = a0,
|
1833 | a11 = a1,
|
1834 | a00 = a0,
|
1835 | a10 = a1,
|
1836 | da0 = da,
|
1837 | da1 = da,
|
1838 | ap = padAngle.apply(this, arguments) / 2,
|
1839 | rp = (ap > epsilon$1) && (padRadius ? +padRadius.apply(this, arguments) : Math.sqrt(r0 * r0 + r1 * r1)),
|
1840 | rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
|
1841 | rc0 = rc,
|
1842 | rc1 = rc,
|
1843 | t0,
|
1844 | t1;
|
1845 |
|
1846 |
|
1847 | if (rp > epsilon$1) {
|
1848 | var p0 = asin(rp / r0 * Math.sin(ap)),
|
1849 | p1 = asin(rp / r1 * Math.sin(ap));
|
1850 | if ((da0 -= p0 * 2) > epsilon$1) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
|
1851 | else da0 = 0, a00 = a10 = (a0 + a1) / 2;
|
1852 | if ((da1 -= p1 * 2) > epsilon$1) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
|
1853 | else da1 = 0, a01 = a11 = (a0 + a1) / 2;
|
1854 | }
|
1855 |
|
1856 | var x01 = r1 * Math.cos(a01),
|
1857 | y01 = r1 * Math.sin(a01),
|
1858 | x10 = r0 * Math.cos(a10),
|
1859 | y10 = r0 * Math.sin(a10);
|
1860 |
|
1861 |
|
1862 | if (rc > epsilon$1) {
|
1863 | var x11 = r1 * Math.cos(a11),
|
1864 | y11 = r1 * Math.sin(a11),
|
1865 | x00 = r0 * Math.cos(a00),
|
1866 | y00 = r0 * Math.sin(a00);
|
1867 |
|
1868 |
|
1869 | if (da < pi$2) {
|
1870 | var oc = da0 > epsilon$1 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
|
1871 | ax = x01 - oc[0],
|
1872 | ay = y01 - oc[1],
|
1873 | bx = x11 - oc[0],
|
1874 | by = y11 - oc[1],
|
1875 | kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2),
|
1876 | lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
|
1877 | rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
|
1878 | rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
|
1879 | }
|
1880 | }
|
1881 |
|
1882 |
|
1883 | if (!(da1 > epsilon$1)) context.moveTo(x01, y01);
|
1884 |
|
1885 |
|
1886 | else if (rc1 > epsilon$1) {
|
1887 | t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
|
1888 | t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
|
1889 |
|
1890 | context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
1891 |
|
1892 |
|
1893 | if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, Math.atan2(t0.y01, t0.x01), Math.atan2(t1.y01, t1.x01), !cw);
|
1894 |
|
1895 |
|
1896 | else {
|
1897 | context.arc(t0.cx, t0.cy, rc1, Math.atan2(t0.y01, t0.x01), Math.atan2(t0.y11, t0.x11), !cw);
|
1898 | 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);
|
1899 | context.arc(t1.cx, t1.cy, rc1, Math.atan2(t1.y11, t1.x11), Math.atan2(t1.y01, t1.x01), !cw);
|
1900 | }
|
1901 | }
|
1902 |
|
1903 |
|
1904 | else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
|
1905 |
|
1906 |
|
1907 |
|
1908 | if (!(r0 > epsilon$1) || !(da0 > epsilon$1)) context.lineTo(x10, y10);
|
1909 |
|
1910 |
|
1911 | else if (rc0 > epsilon$1) {
|
1912 | t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
|
1913 | t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
|
1914 |
|
1915 | context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
1916 |
|
1917 |
|
1918 | if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, Math.atan2(t0.y01, t0.x01), Math.atan2(t1.y01, t1.x01), !cw);
|
1919 |
|
1920 |
|
1921 | else {
|
1922 | context.arc(t0.cx, t0.cy, rc0, Math.atan2(t0.y01, t0.x01), Math.atan2(t0.y11, t0.x11), !cw);
|
1923 | 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);
|
1924 | context.arc(t1.cx, t1.cy, rc0, Math.atan2(t1.y11, t1.x11), Math.atan2(t1.y01, t1.x01), !cw);
|
1925 | }
|
1926 | }
|
1927 |
|
1928 |
|
1929 | else context.arc(0, 0, r0, a10, a00, cw);
|
1930 | }
|
1931 |
|
1932 | context.closePath();
|
1933 |
|
1934 | if (buffer) return context = null, buffer + "" || null;
|
1935 | }
|
1936 |
|
1937 | arc.centroid = function() {
|
1938 | var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
|
1939 | a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$2 / 2;
|
1940 | return [Math.cos(a) * r, Math.sin(a) * r];
|
1941 | };
|
1942 |
|
1943 | arc.innerRadius = function(_) {
|
1944 | return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : innerRadius;
|
1945 | };
|
1946 |
|
1947 | arc.outerRadius = function(_) {
|
1948 | return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : outerRadius;
|
1949 | };
|
1950 |
|
1951 | arc.cornerRadius = function(_) {
|
1952 | return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : cornerRadius;
|
1953 | };
|
1954 |
|
1955 | arc.padRadius = function(_) {
|
1956 | return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), arc) : padRadius;
|
1957 | };
|
1958 |
|
1959 | arc.startAngle = function(_) {
|
1960 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : startAngle;
|
1961 | };
|
1962 |
|
1963 | arc.endAngle = function(_) {
|
1964 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : endAngle;
|
1965 | };
|
1966 |
|
1967 | arc.padAngle = function(_) {
|
1968 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : padAngle;
|
1969 | };
|
1970 |
|
1971 | arc.context = function(_) {
|
1972 | return arguments.length ? ((context = _ == null ? null : _), arc) : context;
|
1973 | };
|
1974 |
|
1975 | return arc;
|
1976 | }
|
1977 |
|
1978 | function Linear(context) {
|
1979 | this._context = context;
|
1980 | }
|
1981 |
|
1982 | Linear.prototype = {
|
1983 | areaStart: function() {
|
1984 | this._line = 0;
|
1985 | },
|
1986 | areaEnd: function() {
|
1987 | this._line = NaN;
|
1988 | },
|
1989 | lineStart: function() {
|
1990 | this._point = 0;
|
1991 | },
|
1992 | lineEnd: function() {
|
1993 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
1994 | this._line = 1 - this._line;
|
1995 | },
|
1996 | point: function(x, y) {
|
1997 | x = +x, y = +y;
|
1998 | switch (this._point) {
|
1999 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
2000 | case 1: this._point = 2;
|
2001 | default: this._context.lineTo(x, y); break;
|
2002 | }
|
2003 | }
|
2004 | };
|
2005 |
|
2006 | function curveLinear(context) {
|
2007 | return new Linear(context);
|
2008 | }
|
2009 |
|
2010 | function x(p) {
|
2011 | return p[0];
|
2012 | }
|
2013 |
|
2014 | function y(p) {
|
2015 | return p[1];
|
2016 | }
|
2017 |
|
2018 | function line() {
|
2019 | var x$$ = x,
|
2020 | y$$ = y,
|
2021 | defined = constant$1(true),
|
2022 | context = null,
|
2023 | curve = curveLinear,
|
2024 | output = null;
|
2025 |
|
2026 | function line(data) {
|
2027 | var i,
|
2028 | n = data.length,
|
2029 | d,
|
2030 | defined0 = false,
|
2031 | buffer;
|
2032 |
|
2033 | if (context == null) output = curve(buffer = path());
|
2034 |
|
2035 | for (i = 0; i <= n; ++i) {
|
2036 | if (!(i < n && defined(d = data[i], i, data)) === defined0) {
|
2037 | if (defined0 = !defined0) output.lineStart();
|
2038 | else output.lineEnd();
|
2039 | }
|
2040 | if (defined0) output.point(+x$$(d, i, data), +y$$(d, i, data));
|
2041 | }
|
2042 |
|
2043 | if (buffer) return output = null, buffer + "" || null;
|
2044 | }
|
2045 |
|
2046 | line.x = function(_) {
|
2047 | return arguments.length ? (x$$ = typeof _ === "function" ? _ : constant$1(+_), line) : x$$;
|
2048 | };
|
2049 |
|
2050 | line.y = function(_) {
|
2051 | return arguments.length ? (y$$ = typeof _ === "function" ? _ : constant$1(+_), line) : y$$;
|
2052 | };
|
2053 |
|
2054 | line.defined = function(_) {
|
2055 | return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), line) : defined;
|
2056 | };
|
2057 |
|
2058 | line.curve = function(_) {
|
2059 | return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
|
2060 | };
|
2061 |
|
2062 | line.context = function(_) {
|
2063 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
|
2064 | };
|
2065 |
|
2066 | return line;
|
2067 | }
|
2068 |
|
2069 | function area$1() {
|
2070 | var x0 = x,
|
2071 | x1 = null,
|
2072 | y0 = constant$1(0),
|
2073 | y1 = y,
|
2074 | defined = constant$1(true),
|
2075 | context = null,
|
2076 | curve = curveLinear,
|
2077 | output = null;
|
2078 |
|
2079 | function area(data) {
|
2080 | var i,
|
2081 | j,
|
2082 | k,
|
2083 | n = data.length,
|
2084 | d,
|
2085 | defined0 = false,
|
2086 | buffer,
|
2087 | x0z = new Array(n),
|
2088 | y0z = new Array(n);
|
2089 |
|
2090 | if (context == null) output = curve(buffer = path());
|
2091 |
|
2092 | for (i = 0; i <= n; ++i) {
|
2093 | if (!(i < n && defined(d = data[i], i, data)) === defined0) {
|
2094 | if (defined0 = !defined0) {
|
2095 | j = i;
|
2096 | output.areaStart();
|
2097 | output.lineStart();
|
2098 | } else {
|
2099 | output.lineEnd();
|
2100 | output.lineStart();
|
2101 | for (k = i - 1; k >= j; --k) {
|
2102 | output.point(x0z[k], y0z[k]);
|
2103 | }
|
2104 | output.lineEnd();
|
2105 | output.areaEnd();
|
2106 | }
|
2107 | }
|
2108 | if (defined0) {
|
2109 | x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
|
2110 | output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
|
2111 | }
|
2112 | }
|
2113 |
|
2114 | if (buffer) return output = null, buffer + "" || null;
|
2115 | }
|
2116 |
|
2117 | function arealine() {
|
2118 | return line().defined(defined).curve(curve).context(context);
|
2119 | }
|
2120 |
|
2121 | area.x = function(_) {
|
2122 | return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), x1 = null, area) : x0;
|
2123 | };
|
2124 |
|
2125 | area.x0 = function(_) {
|
2126 | return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), area) : x0;
|
2127 | };
|
2128 |
|
2129 | area.x1 = function(_) {
|
2130 | return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : x1;
|
2131 | };
|
2132 |
|
2133 | area.y = function(_) {
|
2134 | return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), y1 = null, area) : y0;
|
2135 | };
|
2136 |
|
2137 | area.y0 = function(_) {
|
2138 | return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), area) : y0;
|
2139 | };
|
2140 |
|
2141 | area.y1 = function(_) {
|
2142 | return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : y1;
|
2143 | };
|
2144 |
|
2145 | area.lineX0 =
|
2146 | area.lineY0 = function() {
|
2147 | return arealine().x(x0).y(y0);
|
2148 | };
|
2149 |
|
2150 | area.lineY1 = function() {
|
2151 | return arealine().x(x0).y(y1);
|
2152 | };
|
2153 |
|
2154 | area.lineX1 = function() {
|
2155 | return arealine().x(x1).y(y0);
|
2156 | };
|
2157 |
|
2158 | area.defined = function(_) {
|
2159 | return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), area) : defined;
|
2160 | };
|
2161 |
|
2162 | area.curve = function(_) {
|
2163 | return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
|
2164 | };
|
2165 |
|
2166 | area.context = function(_) {
|
2167 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
|
2168 | };
|
2169 |
|
2170 | return area;
|
2171 | }
|
2172 |
|
2173 | function descending$1(a, b) {
|
2174 | return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
2175 | }
|
2176 |
|
2177 | function identity$1(d) {
|
2178 | return d;
|
2179 | }
|
2180 |
|
2181 | function pie() {
|
2182 | var value = identity$1,
|
2183 | sortValues = descending$1,
|
2184 | sort = null,
|
2185 | startAngle = constant$1(0),
|
2186 | endAngle = constant$1(tau$2),
|
2187 | padAngle = constant$1(0);
|
2188 |
|
2189 | function pie(data) {
|
2190 | var i,
|
2191 | n = data.length,
|
2192 | j,
|
2193 | k,
|
2194 | sum = 0,
|
2195 | index = new Array(n),
|
2196 | arcs = new Array(n),
|
2197 | a0 = +startAngle.apply(this, arguments),
|
2198 | da = Math.min(tau$2, Math.max(-tau$2, endAngle.apply(this, arguments) - a0)),
|
2199 | a1,
|
2200 | p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
|
2201 | pa = p * (da < 0 ? -1 : 1),
|
2202 | v;
|
2203 |
|
2204 | for (i = 0; i < n; ++i) {
|
2205 | if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
|
2206 | sum += v;
|
2207 | }
|
2208 | }
|
2209 |
|
2210 |
|
2211 | if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
|
2212 | else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
|
2213 |
|
2214 |
|
2215 | for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
|
2216 | j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
|
2217 | data: data[j],
|
2218 | index: i,
|
2219 | value: v,
|
2220 | startAngle: a0,
|
2221 | endAngle: a1,
|
2222 | padAngle: p
|
2223 | };
|
2224 | }
|
2225 |
|
2226 | return arcs;
|
2227 | }
|
2228 |
|
2229 | pie.value = function(_) {
|
2230 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value;
|
2231 | };
|
2232 |
|
2233 | pie.sortValues = function(_) {
|
2234 | return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
|
2235 | };
|
2236 |
|
2237 | pie.sort = function(_) {
|
2238 | return arguments.length ? (sort = _, sortValues = null, pie) : sort;
|
2239 | };
|
2240 |
|
2241 | pie.startAngle = function(_) {
|
2242 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : startAngle;
|
2243 | };
|
2244 |
|
2245 | pie.endAngle = function(_) {
|
2246 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : endAngle;
|
2247 | };
|
2248 |
|
2249 | pie.padAngle = function(_) {
|
2250 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : padAngle;
|
2251 | };
|
2252 |
|
2253 | return pie;
|
2254 | }
|
2255 |
|
2256 | var curveRadialLinear = curveRadial(curveLinear);
|
2257 |
|
2258 | function Radial(curve) {
|
2259 | this._curve = curve;
|
2260 | }
|
2261 |
|
2262 | Radial.prototype = {
|
2263 | areaStart: function() {
|
2264 | this._curve.areaStart();
|
2265 | },
|
2266 | areaEnd: function() {
|
2267 | this._curve.areaEnd();
|
2268 | },
|
2269 | lineStart: function() {
|
2270 | this._curve.lineStart();
|
2271 | },
|
2272 | lineEnd: function() {
|
2273 | this._curve.lineEnd();
|
2274 | },
|
2275 | point: function(a, r) {
|
2276 | this._curve.point(r * Math.sin(a), r * -Math.cos(a));
|
2277 | }
|
2278 | };
|
2279 |
|
2280 | function curveRadial(curve) {
|
2281 |
|
2282 | function radial(context) {
|
2283 | return new Radial(curve(context));
|
2284 | }
|
2285 |
|
2286 | radial._curve = curve;
|
2287 |
|
2288 | return radial;
|
2289 | }
|
2290 |
|
2291 | function radialLine(l) {
|
2292 | var c = l.curve;
|
2293 |
|
2294 | l.angle = l.x, delete l.x;
|
2295 | l.radius = l.y, delete l.y;
|
2296 |
|
2297 | l.curve = function(_) {
|
2298 | return arguments.length ? c(curveRadial(_)) : c()._curve;
|
2299 | };
|
2300 |
|
2301 | return l;
|
2302 | }
|
2303 |
|
2304 | function radialLine$1() {
|
2305 | return radialLine(line().curve(curveRadialLinear));
|
2306 | }
|
2307 |
|
2308 | function radialArea() {
|
2309 | var a = area$1().curve(curveRadialLinear),
|
2310 | c = a.curve,
|
2311 | x0 = a.lineX0,
|
2312 | x1 = a.lineX1,
|
2313 | y0 = a.lineY0,
|
2314 | y1 = a.lineY1;
|
2315 |
|
2316 | a.angle = a.x, delete a.x;
|
2317 | a.startAngle = a.x0, delete a.x0;
|
2318 | a.endAngle = a.x1, delete a.x1;
|
2319 | a.radius = a.y, delete a.y;
|
2320 | a.innerRadius = a.y0, delete a.y0;
|
2321 | a.outerRadius = a.y1, delete a.y1;
|
2322 | a.lineStartAngle = function() { return radialLine(x0()); }, delete a.lineX0;
|
2323 | a.lineEndAngle = function() { return radialLine(x1()); }, delete a.lineX1;
|
2324 | a.lineInnerRadius = function() { return radialLine(y0()); }, delete a.lineY0;
|
2325 | a.lineOuterRadius = function() { return radialLine(y1()); }, delete a.lineY1;
|
2326 |
|
2327 | a.curve = function(_) {
|
2328 | return arguments.length ? c(curveRadial(_)) : c()._curve;
|
2329 | };
|
2330 |
|
2331 | return a;
|
2332 | }
|
2333 |
|
2334 | var circle = {
|
2335 | draw: function(context, size) {
|
2336 | var r = Math.sqrt(size / pi$2);
|
2337 | context.moveTo(r, 0);
|
2338 | context.arc(0, 0, r, 0, tau$2);
|
2339 | }
|
2340 | };
|
2341 |
|
2342 | var cross$1 = {
|
2343 | draw: function(context, size) {
|
2344 | var r = Math.sqrt(size / 5) / 2;
|
2345 | context.moveTo(-3 * r, -r);
|
2346 | context.lineTo(-r, -r);
|
2347 | context.lineTo(-r, -3 * r);
|
2348 | context.lineTo(r, -3 * r);
|
2349 | context.lineTo(r, -r);
|
2350 | context.lineTo(3 * r, -r);
|
2351 | context.lineTo(3 * r, r);
|
2352 | context.lineTo(r, r);
|
2353 | context.lineTo(r, 3 * r);
|
2354 | context.lineTo(-r, 3 * r);
|
2355 | context.lineTo(-r, r);
|
2356 | context.lineTo(-3 * r, r);
|
2357 | context.closePath();
|
2358 | }
|
2359 | };
|
2360 |
|
2361 | var tan30 = Math.sqrt(1 / 3);
|
2362 | var tan30_2 = tan30 * 2;
|
2363 | var diamond = {
|
2364 | draw: function(context, size) {
|
2365 | var y = Math.sqrt(size / tan30_2),
|
2366 | x = y * tan30;
|
2367 | context.moveTo(0, -y);
|
2368 | context.lineTo(x, 0);
|
2369 | context.lineTo(0, y);
|
2370 | context.lineTo(-x, 0);
|
2371 | context.closePath();
|
2372 | }
|
2373 | };
|
2374 |
|
2375 | var ka = 0.89081309152928522810;
|
2376 | var kr = Math.sin(pi$2 / 10) / Math.sin(7 * pi$2 / 10);
|
2377 | var kx = Math.sin(tau$2 / 10) * kr;
|
2378 | var ky = -Math.cos(tau$2 / 10) * kr;
|
2379 | var star = {
|
2380 | draw: function(context, size) {
|
2381 | var r = Math.sqrt(size * ka),
|
2382 | x = kx * r,
|
2383 | y = ky * r;
|
2384 | context.moveTo(0, -r);
|
2385 | context.lineTo(x, y);
|
2386 | for (var i = 1; i < 5; ++i) {
|
2387 | var a = tau$2 * i / 5,
|
2388 | c = Math.cos(a),
|
2389 | s = Math.sin(a);
|
2390 | context.lineTo(s * r, -c * r);
|
2391 | context.lineTo(c * x - s * y, s * x + c * y);
|
2392 | }
|
2393 | context.closePath();
|
2394 | }
|
2395 | };
|
2396 |
|
2397 | var square = {
|
2398 | draw: function(context, size) {
|
2399 | var w = Math.sqrt(size),
|
2400 | x = -w / 2;
|
2401 | context.rect(x, x, w, w);
|
2402 | }
|
2403 | };
|
2404 |
|
2405 | var sqrt3 = Math.sqrt(3);
|
2406 |
|
2407 | var triangle = {
|
2408 | draw: function(context, size) {
|
2409 | var y = -Math.sqrt(size / (sqrt3 * 3));
|
2410 | context.moveTo(0, y * 2);
|
2411 | context.lineTo(-sqrt3 * y, -y);
|
2412 | context.lineTo(sqrt3 * y, -y);
|
2413 | context.closePath();
|
2414 | }
|
2415 | };
|
2416 |
|
2417 | var c = -0.5;
|
2418 | var s = Math.sqrt(3) / 2;
|
2419 | var k = 1 / Math.sqrt(12);
|
2420 | var a = (k / 2 + 1) * 3;
|
2421 | var wye = {
|
2422 | draw: function(context, size) {
|
2423 | var r = Math.sqrt(size / a),
|
2424 | x0 = r / 2,
|
2425 | y0 = r * k,
|
2426 | x1 = x0,
|
2427 | y1 = r * k + r,
|
2428 | x2 = -x1,
|
2429 | y2 = y1;
|
2430 | context.moveTo(x0, y0);
|
2431 | context.lineTo(x1, y1);
|
2432 | context.lineTo(x2, y2);
|
2433 | context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
|
2434 | context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
|
2435 | context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
|
2436 | context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
|
2437 | context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
|
2438 | context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
|
2439 | context.closePath();
|
2440 | }
|
2441 | };
|
2442 |
|
2443 | var symbols = [
|
2444 | circle,
|
2445 | cross$1,
|
2446 | diamond,
|
2447 | square,
|
2448 | star,
|
2449 | triangle,
|
2450 | wye
|
2451 | ];
|
2452 |
|
2453 | function symbol() {
|
2454 | var type = constant$1(circle),
|
2455 | size = constant$1(64),
|
2456 | context = null;
|
2457 |
|
2458 | function symbol() {
|
2459 | var buffer;
|
2460 | if (!context) context = buffer = path();
|
2461 | type.apply(this, arguments).draw(context, +size.apply(this, arguments));
|
2462 | if (buffer) return context = null, buffer + "" || null;
|
2463 | }
|
2464 |
|
2465 | symbol.type = function(_) {
|
2466 | return arguments.length ? (type = typeof _ === "function" ? _ : constant$1(_), symbol) : type;
|
2467 | };
|
2468 |
|
2469 | symbol.size = function(_) {
|
2470 | return arguments.length ? (size = typeof _ === "function" ? _ : constant$1(+_), symbol) : size;
|
2471 | };
|
2472 |
|
2473 | symbol.context = function(_) {
|
2474 | return arguments.length ? (context = _ == null ? null : _, symbol) : context;
|
2475 | };
|
2476 |
|
2477 | return symbol;
|
2478 | }
|
2479 |
|
2480 | function noop() {}
|
2481 |
|
2482 | function point(that, x, y) {
|
2483 | that._context.bezierCurveTo(
|
2484 | (2 * that._x0 + that._x1) / 3,
|
2485 | (2 * that._y0 + that._y1) / 3,
|
2486 | (that._x0 + 2 * that._x1) / 3,
|
2487 | (that._y0 + 2 * that._y1) / 3,
|
2488 | (that._x0 + 4 * that._x1 + x) / 6,
|
2489 | (that._y0 + 4 * that._y1 + y) / 6
|
2490 | );
|
2491 | }
|
2492 |
|
2493 | function Basis(context) {
|
2494 | this._context = context;
|
2495 | }
|
2496 |
|
2497 | Basis.prototype = {
|
2498 | areaStart: function() {
|
2499 | this._line = 0;
|
2500 | },
|
2501 | areaEnd: function() {
|
2502 | this._line = NaN;
|
2503 | },
|
2504 | lineStart: function() {
|
2505 | this._x0 = this._x1 =
|
2506 | this._y0 = this._y1 = NaN;
|
2507 | this._point = 0;
|
2508 | },
|
2509 | lineEnd: function() {
|
2510 | switch (this._point) {
|
2511 | case 3: point(this, this._x1, this._y1);
|
2512 | case 2: this._context.lineTo(this._x1, this._y1); break;
|
2513 | }
|
2514 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
2515 | this._line = 1 - this._line;
|
2516 | },
|
2517 | point: function(x, y) {
|
2518 | x = +x, y = +y;
|
2519 | switch (this._point) {
|
2520 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
2521 | case 1: this._point = 2; break;
|
2522 | case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6);
|
2523 | default: point(this, x, y); break;
|
2524 | }
|
2525 | this._x0 = this._x1, this._x1 = x;
|
2526 | this._y0 = this._y1, this._y1 = y;
|
2527 | }
|
2528 | };
|
2529 |
|
2530 | function basis(context) {
|
2531 | return new Basis(context);
|
2532 | }
|
2533 |
|
2534 | function BasisClosed(context) {
|
2535 | this._context = context;
|
2536 | }
|
2537 |
|
2538 | BasisClosed.prototype = {
|
2539 | areaStart: noop,
|
2540 | areaEnd: noop,
|
2541 | lineStart: function() {
|
2542 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
|
2543 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
|
2544 | this._point = 0;
|
2545 | },
|
2546 | lineEnd: function() {
|
2547 | switch (this._point) {
|
2548 | case 1: {
|
2549 | this._context.moveTo(this._x2, this._y2);
|
2550 | this._context.closePath();
|
2551 | break;
|
2552 | }
|
2553 | case 2: {
|
2554 | this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
|
2555 | this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
|
2556 | this._context.closePath();
|
2557 | break;
|
2558 | }
|
2559 | case 3: {
|
2560 | this.point(this._x2, this._y2);
|
2561 | this.point(this._x3, this._y3);
|
2562 | this.point(this._x4, this._y4);
|
2563 | break;
|
2564 | }
|
2565 | }
|
2566 | },
|
2567 | point: function(x, y) {
|
2568 | x = +x, y = +y;
|
2569 | switch (this._point) {
|
2570 | case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
|
2571 | case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
|
2572 | case 2: this._point = 3; this._x4 = x, this._y4 = y; this._context.moveTo((this._x0 + 4 * this._x1 + x) / 6, (this._y0 + 4 * this._y1 + y) / 6); break;
|
2573 | default: point(this, x, y); break;
|
2574 | }
|
2575 | this._x0 = this._x1, this._x1 = x;
|
2576 | this._y0 = this._y1, this._y1 = y;
|
2577 | }
|
2578 | };
|
2579 |
|
2580 | function basisClosed(context) {
|
2581 | return new BasisClosed(context);
|
2582 | }
|
2583 |
|
2584 | function BasisOpen(context) {
|
2585 | this._context = context;
|
2586 | }
|
2587 |
|
2588 | BasisOpen.prototype = {
|
2589 | areaStart: function() {
|
2590 | this._line = 0;
|
2591 | },
|
2592 | areaEnd: function() {
|
2593 | this._line = NaN;
|
2594 | },
|
2595 | lineStart: function() {
|
2596 | this._x0 = this._x1 =
|
2597 | this._y0 = this._y1 = NaN;
|
2598 | this._point = 0;
|
2599 | },
|
2600 | lineEnd: function() {
|
2601 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
2602 | this._line = 1 - this._line;
|
2603 | },
|
2604 | point: function(x, y) {
|
2605 | x = +x, y = +y;
|
2606 | switch (this._point) {
|
2607 | case 0: this._point = 1; break;
|
2608 | case 1: this._point = 2; break;
|
2609 | case 2: this._point = 3; var x0 = (this._x0 + 4 * this._x1 + x) / 6, y0 = (this._y0 + 4 * this._y1 + y) / 6; this._line ? this._context.lineTo(x0, y0) : this._context.moveTo(x0, y0); break;
|
2610 | case 3: this._point = 4;
|
2611 | default: point(this, x, y); break;
|
2612 | }
|
2613 | this._x0 = this._x1, this._x1 = x;
|
2614 | this._y0 = this._y1, this._y1 = y;
|
2615 | }
|
2616 | };
|
2617 |
|
2618 | function basisOpen(context) {
|
2619 | return new BasisOpen(context);
|
2620 | }
|
2621 |
|
2622 | function Bundle(context, beta) {
|
2623 | this._basis = new Basis(context);
|
2624 | this._beta = beta;
|
2625 | }
|
2626 |
|
2627 | Bundle.prototype = {
|
2628 | lineStart: function() {
|
2629 | this._x = [];
|
2630 | this._y = [];
|
2631 | this._basis.lineStart();
|
2632 | },
|
2633 | lineEnd: function() {
|
2634 | var x = this._x,
|
2635 | y = this._y,
|
2636 | j = x.length - 1;
|
2637 |
|
2638 | if (j > 0) {
|
2639 | var x0 = x[0],
|
2640 | y0 = y[0],
|
2641 | dx = x[j] - x0,
|
2642 | dy = y[j] - y0,
|
2643 | i = -1,
|
2644 | t;
|
2645 |
|
2646 | while (++i <= j) {
|
2647 | t = i / j;
|
2648 | this._basis.point(
|
2649 | this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
|
2650 | this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
|
2651 | );
|
2652 | }
|
2653 | }
|
2654 |
|
2655 | this._x = this._y = null;
|
2656 | this._basis.lineEnd();
|
2657 | },
|
2658 | point: function(x, y) {
|
2659 | this._x.push(+x);
|
2660 | this._y.push(+y);
|
2661 | }
|
2662 | };
|
2663 |
|
2664 | var bundle = (function custom(beta) {
|
2665 |
|
2666 | function bundle(context) {
|
2667 | return beta === 1 ? new Basis(context) : new Bundle(context, beta);
|
2668 | }
|
2669 |
|
2670 | bundle.beta = function(beta) {
|
2671 | return custom(+beta);
|
2672 | };
|
2673 |
|
2674 | return bundle;
|
2675 | })(0.85);
|
2676 |
|
2677 | function point$1(that, x, y) {
|
2678 | that._context.bezierCurveTo(
|
2679 | that._x1 + that._k * (that._x2 - that._x0),
|
2680 | that._y1 + that._k * (that._y2 - that._y0),
|
2681 | that._x2 + that._k * (that._x1 - x),
|
2682 | that._y2 + that._k * (that._y1 - y),
|
2683 | that._x2,
|
2684 | that._y2
|
2685 | );
|
2686 | }
|
2687 |
|
2688 | function Cardinal(context, tension) {
|
2689 | this._context = context;
|
2690 | this._k = (1 - tension) / 6;
|
2691 | }
|
2692 |
|
2693 | Cardinal.prototype = {
|
2694 | areaStart: function() {
|
2695 | this._line = 0;
|
2696 | },
|
2697 | areaEnd: function() {
|
2698 | this._line = NaN;
|
2699 | },
|
2700 | lineStart: function() {
|
2701 | this._x0 = this._x1 = this._x2 =
|
2702 | this._y0 = this._y1 = this._y2 = NaN;
|
2703 | this._point = 0;
|
2704 | },
|
2705 | lineEnd: function() {
|
2706 | switch (this._point) {
|
2707 | case 2: this._context.lineTo(this._x2, this._y2); break;
|
2708 | case 3: point$1(this, this._x1, this._y1); break;
|
2709 | }
|
2710 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
2711 | this._line = 1 - this._line;
|
2712 | },
|
2713 | point: function(x, y) {
|
2714 | x = +x, y = +y;
|
2715 | switch (this._point) {
|
2716 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
2717 | case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
|
2718 | case 2: this._point = 3;
|
2719 | default: point$1(this, x, y); break;
|
2720 | }
|
2721 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
2722 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
2723 | }
|
2724 | };
|
2725 |
|
2726 | var cardinal = (function custom(tension) {
|
2727 |
|
2728 | function cardinal(context) {
|
2729 | return new Cardinal(context, tension);
|
2730 | }
|
2731 |
|
2732 | cardinal.tension = function(tension) {
|
2733 | return custom(+tension);
|
2734 | };
|
2735 |
|
2736 | return cardinal;
|
2737 | })(0);
|
2738 |
|
2739 | function CardinalClosed(context, tension) {
|
2740 | this._context = context;
|
2741 | this._k = (1 - tension) / 6;
|
2742 | }
|
2743 |
|
2744 | CardinalClosed.prototype = {
|
2745 | areaStart: noop,
|
2746 | areaEnd: noop,
|
2747 | lineStart: function() {
|
2748 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
|
2749 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
|
2750 | this._point = 0;
|
2751 | },
|
2752 | lineEnd: function() {
|
2753 | switch (this._point) {
|
2754 | case 1: {
|
2755 | this._context.moveTo(this._x3, this._y3);
|
2756 | this._context.closePath();
|
2757 | break;
|
2758 | }
|
2759 | case 2: {
|
2760 | this._context.lineTo(this._x3, this._y3);
|
2761 | this._context.closePath();
|
2762 | break;
|
2763 | }
|
2764 | case 3: {
|
2765 | this.point(this._x3, this._y3);
|
2766 | this.point(this._x4, this._y4);
|
2767 | this.point(this._x5, this._y5);
|
2768 | break;
|
2769 | }
|
2770 | }
|
2771 | },
|
2772 | point: function(x, y) {
|
2773 | x = +x, y = +y;
|
2774 | switch (this._point) {
|
2775 | case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
|
2776 | case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
|
2777 | case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
|
2778 | default: point$1(this, x, y); break;
|
2779 | }
|
2780 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
2781 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
2782 | }
|
2783 | };
|
2784 |
|
2785 | var cardinalClosed = (function custom(tension) {
|
2786 |
|
2787 | function cardinal(context) {
|
2788 | return new CardinalClosed(context, tension);
|
2789 | }
|
2790 |
|
2791 | cardinal.tension = function(tension) {
|
2792 | return custom(+tension);
|
2793 | };
|
2794 |
|
2795 | return cardinal;
|
2796 | })(0);
|
2797 |
|
2798 | function CardinalOpen(context, tension) {
|
2799 | this._context = context;
|
2800 | this._k = (1 - tension) / 6;
|
2801 | }
|
2802 |
|
2803 | CardinalOpen.prototype = {
|
2804 | areaStart: function() {
|
2805 | this._line = 0;
|
2806 | },
|
2807 | areaEnd: function() {
|
2808 | this._line = NaN;
|
2809 | },
|
2810 | lineStart: function() {
|
2811 | this._x0 = this._x1 = this._x2 =
|
2812 | this._y0 = this._y1 = this._y2 = NaN;
|
2813 | this._point = 0;
|
2814 | },
|
2815 | lineEnd: function() {
|
2816 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
2817 | this._line = 1 - this._line;
|
2818 | },
|
2819 | point: function(x, y) {
|
2820 | x = +x, y = +y;
|
2821 | switch (this._point) {
|
2822 | case 0: this._point = 1; break;
|
2823 | case 1: this._point = 2; break;
|
2824 | case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
|
2825 | case 3: this._point = 4;
|
2826 | default: point$1(this, x, y); break;
|
2827 | }
|
2828 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
2829 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
2830 | }
|
2831 | };
|
2832 |
|
2833 | var cardinalOpen = (function custom(tension) {
|
2834 |
|
2835 | function cardinal(context) {
|
2836 | return new CardinalOpen(context, tension);
|
2837 | }
|
2838 |
|
2839 | cardinal.tension = function(tension) {
|
2840 | return custom(+tension);
|
2841 | };
|
2842 |
|
2843 | return cardinal;
|
2844 | })(0);
|
2845 |
|
2846 | function point$2(that, x, y) {
|
2847 | var x1 = that._x1,
|
2848 | y1 = that._y1,
|
2849 | x2 = that._x2,
|
2850 | y2 = that._y2;
|
2851 |
|
2852 | if (that._l01_a > epsilon$1) {
|
2853 | var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
|
2854 | n = 3 * that._l01_a * (that._l01_a + that._l12_a);
|
2855 | x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
|
2856 | y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
|
2857 | }
|
2858 |
|
2859 | if (that._l23_a > epsilon$1) {
|
2860 | var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
|
2861 | m = 3 * that._l23_a * (that._l23_a + that._l12_a);
|
2862 | x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
|
2863 | y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
|
2864 | }
|
2865 |
|
2866 | that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
|
2867 | }
|
2868 |
|
2869 | function CatmullRom(context, alpha) {
|
2870 | this._context = context;
|
2871 | this._alpha = alpha;
|
2872 | }
|
2873 |
|
2874 | CatmullRom.prototype = {
|
2875 | areaStart: function() {
|
2876 | this._line = 0;
|
2877 | },
|
2878 | areaEnd: function() {
|
2879 | this._line = NaN;
|
2880 | },
|
2881 | lineStart: function() {
|
2882 | this._x0 = this._x1 = this._x2 =
|
2883 | this._y0 = this._y1 = this._y2 = NaN;
|
2884 | this._l01_a = this._l12_a = this._l23_a =
|
2885 | this._l01_2a = this._l12_2a = this._l23_2a =
|
2886 | this._point = 0;
|
2887 | },
|
2888 | lineEnd: function() {
|
2889 | switch (this._point) {
|
2890 | case 2: this._context.lineTo(this._x2, this._y2); break;
|
2891 | case 3: this.point(this, 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(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: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
2907 | case 1: this._point = 2; break;
|
2908 | case 2: this._point = 3;
|
2909 | default: point$2(this, x, y); break;
|
2910 | }
|
2911 |
|
2912 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
2913 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
2914 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
2915 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
2916 | }
|
2917 | };
|
2918 |
|
2919 | var catmullRom = (function custom(alpha) {
|
2920 |
|
2921 | function catmullRom(context) {
|
2922 | return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
|
2923 | }
|
2924 |
|
2925 | catmullRom.alpha = function(alpha) {
|
2926 | return custom(+alpha);
|
2927 | };
|
2928 |
|
2929 | return catmullRom;
|
2930 | })(0.5);
|
2931 |
|
2932 | function CatmullRomClosed(context, alpha) {
|
2933 | this._context = context;
|
2934 | this._alpha = alpha;
|
2935 | }
|
2936 |
|
2937 | CatmullRomClosed.prototype = {
|
2938 | areaStart: noop,
|
2939 | areaEnd: noop,
|
2940 | lineStart: function() {
|
2941 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
|
2942 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
|
2943 | this._l01_a = this._l12_a = this._l23_a =
|
2944 | this._l01_2a = this._l12_2a = this._l23_2a =
|
2945 | this._point = 0;
|
2946 | },
|
2947 | lineEnd: function() {
|
2948 | switch (this._point) {
|
2949 | case 1: {
|
2950 | this._context.moveTo(this._x3, this._y3);
|
2951 | this._context.closePath();
|
2952 | break;
|
2953 | }
|
2954 | case 2: {
|
2955 | this._context.lineTo(this._x3, this._y3);
|
2956 | this._context.closePath();
|
2957 | break;
|
2958 | }
|
2959 | case 3: {
|
2960 | this.point(this._x3, this._y3);
|
2961 | this.point(this._x4, this._y4);
|
2962 | this.point(this._x5, this._y5);
|
2963 | break;
|
2964 | }
|
2965 | }
|
2966 | },
|
2967 | point: function(x, y) {
|
2968 | x = +x, y = +y;
|
2969 |
|
2970 | if (this._point) {
|
2971 | var x23 = this._x2 - x,
|
2972 | y23 = this._y2 - y;
|
2973 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
2974 | }
|
2975 |
|
2976 | switch (this._point) {
|
2977 | case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
|
2978 | case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
|
2979 | case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
|
2980 | default: point$2(this, x, y); break;
|
2981 | }
|
2982 |
|
2983 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
2984 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
2985 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
2986 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
2987 | }
|
2988 | };
|
2989 |
|
2990 | var catmullRomClosed = (function custom(alpha) {
|
2991 |
|
2992 | function catmullRom(context) {
|
2993 | return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
|
2994 | }
|
2995 |
|
2996 | catmullRom.alpha = function(alpha) {
|
2997 | return custom(+alpha);
|
2998 | };
|
2999 |
|
3000 | return catmullRom;
|
3001 | })(0.5);
|
3002 |
|
3003 | function CatmullRomOpen(context, alpha) {
|
3004 | this._context = context;
|
3005 | this._alpha = alpha;
|
3006 | }
|
3007 |
|
3008 | CatmullRomOpen.prototype = {
|
3009 | areaStart: function() {
|
3010 | this._line = 0;
|
3011 | },
|
3012 | areaEnd: function() {
|
3013 | this._line = NaN;
|
3014 | },
|
3015 | lineStart: function() {
|
3016 | this._x0 = this._x1 = this._x2 =
|
3017 | this._y0 = this._y1 = this._y2 = NaN;
|
3018 | this._l01_a = this._l12_a = this._l23_a =
|
3019 | this._l01_2a = this._l12_2a = this._l23_2a =
|
3020 | this._point = 0;
|
3021 | },
|
3022 | lineEnd: function() {
|
3023 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
3024 | this._line = 1 - this._line;
|
3025 | },
|
3026 | point: function(x, y) {
|
3027 | x = +x, y = +y;
|
3028 |
|
3029 | if (this._point) {
|
3030 | var x23 = this._x2 - x,
|
3031 | y23 = this._y2 - y;
|
3032 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
3033 | }
|
3034 |
|
3035 | switch (this._point) {
|
3036 | case 0: this._point = 1; break;
|
3037 | case 1: this._point = 2; break;
|
3038 | case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
|
3039 | case 3: this._point = 4;
|
3040 | default: point$2(this, x, y); break;
|
3041 | }
|
3042 |
|
3043 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
3044 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
3045 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
3046 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
3047 | }
|
3048 | };
|
3049 |
|
3050 | var catmullRomOpen = (function custom(alpha) {
|
3051 |
|
3052 | function catmullRom(context) {
|
3053 | return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
|
3054 | }
|
3055 |
|
3056 | catmullRom.alpha = function(alpha) {
|
3057 | return custom(+alpha);
|
3058 | };
|
3059 |
|
3060 | return catmullRom;
|
3061 | })(0.5);
|
3062 |
|
3063 | function LinearClosed(context) {
|
3064 | this._context = context;
|
3065 | }
|
3066 |
|
3067 | LinearClosed.prototype = {
|
3068 | areaStart: noop,
|
3069 | areaEnd: noop,
|
3070 | lineStart: function() {
|
3071 | this._point = 0;
|
3072 | },
|
3073 | lineEnd: function() {
|
3074 | if (this._point) this._context.closePath();
|
3075 | },
|
3076 | point: function(x, y) {
|
3077 | x = +x, y = +y;
|
3078 | if (this._point) this._context.lineTo(x, y);
|
3079 | else this._point = 1, this._context.moveTo(x, y);
|
3080 | }
|
3081 | };
|
3082 |
|
3083 | function linearClosed(context) {
|
3084 | return new LinearClosed(context);
|
3085 | }
|
3086 |
|
3087 | function sign(x) {
|
3088 | return x < 0 ? -1 : 1;
|
3089 | }
|
3090 |
|
3091 |
|
3092 |
|
3093 |
|
3094 |
|
3095 | function slope3(that, x2, y2) {
|
3096 | var h0 = that._x1 - that._x0,
|
3097 | h1 = x2 - that._x1,
|
3098 | s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
|
3099 | s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
|
3100 | p = (s0 * h1 + s1 * h0) / (h0 + h1);
|
3101 | return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
|
3102 | }
|
3103 |
|
3104 |
|
3105 | function slope2(that, t) {
|
3106 | var h = that._x1 - that._x0;
|
3107 | return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
|
3108 | }
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 | function point$3(that, t0, t1) {
|
3114 | var x0 = that._x0,
|
3115 | y0 = that._y0,
|
3116 | x1 = that._x1,
|
3117 | y1 = that._y1,
|
3118 | dx = (x1 - x0) / 3;
|
3119 | that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
|
3120 | }
|
3121 |
|
3122 | function MonotoneX(context) {
|
3123 | this._context = context;
|
3124 | }
|
3125 |
|
3126 | MonotoneX.prototype = {
|
3127 | areaStart: function() {
|
3128 | this._line = 0;
|
3129 | },
|
3130 | areaEnd: function() {
|
3131 | this._line = NaN;
|
3132 | },
|
3133 | lineStart: function() {
|
3134 | this._x0 = this._x1 =
|
3135 | this._y0 = this._y1 =
|
3136 | this._t0 = NaN;
|
3137 | this._point = 0;
|
3138 | },
|
3139 | lineEnd: function() {
|
3140 | switch (this._point) {
|
3141 | case 2: this._context.lineTo(this._x1, this._y1); break;
|
3142 | case 3: point$3(this, this._t0, slope2(this, this._t0)); break;
|
3143 | }
|
3144 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
3145 | this._line = 1 - this._line;
|
3146 | },
|
3147 | point: function(x, y) {
|
3148 | var t1 = NaN;
|
3149 |
|
3150 | x = +x, y = +y;
|
3151 | if (x === this._x1 && y === this._y1) return;
|
3152 | switch (this._point) {
|
3153 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
3154 | case 1: this._point = 2; break;
|
3155 | case 2: this._point = 3; point$3(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
|
3156 | default: point$3(this, this._t0, t1 = slope3(this, x, y)); break;
|
3157 | }
|
3158 |
|
3159 | this._x0 = this._x1, this._x1 = x;
|
3160 | this._y0 = this._y1, this._y1 = y;
|
3161 | this._t0 = t1;
|
3162 | }
|
3163 | }
|
3164 |
|
3165 | function MonotoneY(context) {
|
3166 | this._context = new ReflectContext(context);
|
3167 | }
|
3168 |
|
3169 | (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
|
3170 | MonotoneX.prototype.point.call(this, y, x);
|
3171 | };
|
3172 |
|
3173 | function ReflectContext(context) {
|
3174 | this._context = context;
|
3175 | }
|
3176 |
|
3177 | ReflectContext.prototype = {
|
3178 | moveTo: function(x, y) { this._context.moveTo(y, x); },
|
3179 | closePath: function() { this._context.closePath(); },
|
3180 | lineTo: function(x, y) { this._context.lineTo(y, x); },
|
3181 | bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
|
3182 | };
|
3183 |
|
3184 | function monotoneX(context) {
|
3185 | return new MonotoneX(context);
|
3186 | }
|
3187 |
|
3188 | function monotoneY(context) {
|
3189 | return new MonotoneY(context);
|
3190 | }
|
3191 |
|
3192 | function Natural(context) {
|
3193 | this._context = context;
|
3194 | }
|
3195 |
|
3196 | Natural.prototype = {
|
3197 | areaStart: function() {
|
3198 | this._line = 0;
|
3199 | },
|
3200 | areaEnd: function() {
|
3201 | this._line = NaN;
|
3202 | },
|
3203 | lineStart: function() {
|
3204 | this._x = [];
|
3205 | this._y = [];
|
3206 | },
|
3207 | lineEnd: function() {
|
3208 | var x = this._x,
|
3209 | y = this._y,
|
3210 | n = x.length;
|
3211 |
|
3212 | if (n) {
|
3213 | this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
|
3214 | if (n === 2) {
|
3215 | this._context.lineTo(x[1], y[1]);
|
3216 | } else {
|
3217 | var px = controlPoints(x),
|
3218 | py = controlPoints(y);
|
3219 | for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
|
3220 | this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
|
3221 | }
|
3222 | }
|
3223 | }
|
3224 |
|
3225 | if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
|
3226 | this._line = 1 - this._line;
|
3227 | this._x = this._y = null;
|
3228 | },
|
3229 | point: function(x, y) {
|
3230 | this._x.push(+x);
|
3231 | this._y.push(+y);
|
3232 | }
|
3233 | };
|
3234 |
|
3235 |
|
3236 | function controlPoints(x) {
|
3237 | var i,
|
3238 | n = x.length - 1,
|
3239 | m,
|
3240 | a = new Array(n),
|
3241 | b = new Array(n),
|
3242 | r = new Array(n);
|
3243 | a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
|
3244 | for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
|
3245 | a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
|
3246 | for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
|
3247 | a[n - 1] = r[n - 1] / b[n - 1];
|
3248 | for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
|
3249 | b[n - 1] = (x[n] + a[n - 1]) / 2;
|
3250 | for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
|
3251 | return [a, b];
|
3252 | }
|
3253 |
|
3254 | function natural(context) {
|
3255 | return new Natural(context);
|
3256 | }
|
3257 |
|
3258 | function Step(context, t) {
|
3259 | this._context = context;
|
3260 | this._t = t;
|
3261 | }
|
3262 |
|
3263 | Step.prototype = {
|
3264 | areaStart: function() {
|
3265 | this._line = 0;
|
3266 | },
|
3267 | areaEnd: function() {
|
3268 | this._line = NaN;
|
3269 | },
|
3270 | lineStart: function() {
|
3271 | this._x = this._y = NaN;
|
3272 | this._point = 0;
|
3273 | },
|
3274 | lineEnd: function() {
|
3275 | if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
|
3276 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
3277 | if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
|
3278 | },
|
3279 | point: function(x, y) {
|
3280 | x = +x, y = +y;
|
3281 | switch (this._point) {
|
3282 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
3283 | case 1: this._point = 2;
|
3284 | default: {
|
3285 | if (this._t <= 0) {
|
3286 | this._context.lineTo(this._x, y);
|
3287 | this._context.lineTo(x, y);
|
3288 | } else {
|
3289 | var x1 = this._x * (1 - this._t) + x * this._t;
|
3290 | this._context.lineTo(x1, this._y);
|
3291 | this._context.lineTo(x1, y);
|
3292 | }
|
3293 | break;
|
3294 | }
|
3295 | }
|
3296 | this._x = x, this._y = y;
|
3297 | }
|
3298 | };
|
3299 |
|
3300 | function step(context) {
|
3301 | return new Step(context, 0.5);
|
3302 | }
|
3303 |
|
3304 | function stepBefore(context) {
|
3305 | return new Step(context, 0);
|
3306 | }
|
3307 |
|
3308 | function stepAfter(context) {
|
3309 | return new Step(context, 1);
|
3310 | }
|
3311 |
|
3312 | var slice$2 = Array.prototype.slice;
|
3313 |
|
3314 | function none(series, order) {
|
3315 | if (!((n = series.length) > 1)) return;
|
3316 | for (var i = 1, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
|
3317 | s0 = s1, s1 = series[order[i]];
|
3318 | for (var j = 0; j < m; ++j) {
|
3319 | s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
|
3320 | }
|
3321 | }
|
3322 | }
|
3323 |
|
3324 | function none$1(series) {
|
3325 | var n = series.length, o = new Array(n);
|
3326 | while (--n >= 0) o[n] = n;
|
3327 | return o;
|
3328 | }
|
3329 |
|
3330 | function stackValue(d, key) {
|
3331 | return d[key];
|
3332 | }
|
3333 |
|
3334 | function stack() {
|
3335 | var keys = constant$1([]),
|
3336 | order = none$1,
|
3337 | offset = none,
|
3338 | value = stackValue;
|
3339 |
|
3340 | function stack(data) {
|
3341 | var kz = keys.apply(this, arguments),
|
3342 | i,
|
3343 | m = data.length,
|
3344 | n = kz.length,
|
3345 | sz = new Array(n),
|
3346 | oz;
|
3347 |
|
3348 | for (i = 0; i < n; ++i) {
|
3349 | for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
|
3350 | si[j] = sij = [0, +value(data[j], ki, j, data)];
|
3351 | sij.data = data[j];
|
3352 | }
|
3353 | si.key = ki;
|
3354 | }
|
3355 |
|
3356 | for (i = 0, oz = order(sz); i < n; ++i) {
|
3357 | sz[oz[i]].index = i;
|
3358 | }
|
3359 |
|
3360 | offset(sz, oz);
|
3361 | return sz;
|
3362 | }
|
3363 |
|
3364 | stack.keys = function(_) {
|
3365 | return arguments.length ? (keys = typeof _ === "function" ? _ : constant$1(slice$2.call(_)), stack) : keys;
|
3366 | };
|
3367 |
|
3368 | stack.value = function(_) {
|
3369 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), stack) : value;
|
3370 | };
|
3371 |
|
3372 | stack.order = function(_) {
|
3373 | return arguments.length ? (order = _ == null ? none$1 : typeof _ === "function" ? _ : constant$1(slice$2.call(_)), stack) : order;
|
3374 | };
|
3375 |
|
3376 | stack.offset = function(_) {
|
3377 | return arguments.length ? (offset = _ == null ? none : _, stack) : offset;
|
3378 | };
|
3379 |
|
3380 | return stack;
|
3381 | }
|
3382 |
|
3383 | function expand(series, order) {
|
3384 | if (!((n = series.length) > 0)) return;
|
3385 | for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
|
3386 | for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
|
3387 | if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
|
3388 | }
|
3389 | none(series, order);
|
3390 | }
|
3391 |
|
3392 | function silhouette(series, order) {
|
3393 | if (!((n = series.length) > 0)) return;
|
3394 | for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
|
3395 | for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
|
3396 | s0[j][1] += s0[j][0] = -y / 2;
|
3397 | }
|
3398 | none(series, order);
|
3399 | }
|
3400 |
|
3401 | function wiggle(series, order) {
|
3402 | if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
|
3403 | for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
|
3404 | for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
|
3405 | var si = series[order[i]],
|
3406 | sij0 = si[j][1] || 0,
|
3407 | sij1 = si[j - 1][1] || 0,
|
3408 | s3 = (sij0 - sij1) / 2;
|
3409 | for (var k = 0; k < i; ++k) {
|
3410 | var sk = series[order[k]],
|
3411 | skj0 = sk[j][1] || 0,
|
3412 | skj1 = sk[j - 1][1] || 0;
|
3413 | s3 += skj0 - skj1;
|
3414 | }
|
3415 | s1 += sij0, s2 += s3 * sij0;
|
3416 | }
|
3417 | s0[j - 1][1] += s0[j - 1][0] = y;
|
3418 | if (s1) y -= s2 / s1;
|
3419 | }
|
3420 | s0[j - 1][1] += s0[j - 1][0] = y;
|
3421 | none(series, order);
|
3422 | }
|
3423 |
|
3424 | function ascending$1(series) {
|
3425 | var sums = series.map(sum$1);
|
3426 | return none$1(series).sort(function(a, b) { return sums[a] - sums[b]; });
|
3427 | }
|
3428 |
|
3429 | function sum$1(series) {
|
3430 | var s = 0, i = -1, n = series.length, v;
|
3431 | while (++i < n) if (v = +series[i][1]) s += v;
|
3432 | return s;
|
3433 | }
|
3434 |
|
3435 | function descending$2(series) {
|
3436 | return ascending$1(series).reverse();
|
3437 | }
|
3438 |
|
3439 | function insideOut(series) {
|
3440 | var n = series.length,
|
3441 | i,
|
3442 | j,
|
3443 | sums = series.map(sum$1),
|
3444 | order = none$1(series).sort(function(a, b) { return sums[b] - sums[a]; }),
|
3445 | top = 0,
|
3446 | bottom = 0,
|
3447 | tops = [],
|
3448 | bottoms = [];
|
3449 |
|
3450 | for (i = 0; i < n; ++i) {
|
3451 | j = order[i];
|
3452 | if (top < bottom) {
|
3453 | top += sums[j];
|
3454 | tops.push(j);
|
3455 | } else {
|
3456 | bottom += sums[j];
|
3457 | bottoms.push(j);
|
3458 | }
|
3459 | }
|
3460 |
|
3461 | return bottoms.reverse().concat(tops);
|
3462 | }
|
3463 |
|
3464 | function reverse(series) {
|
3465 | return none$1(series).reverse();
|
3466 | }
|
3467 |
|
3468 | function define(constructor, factory, prototype) {
|
3469 | constructor.prototype = factory.prototype = prototype;
|
3470 | prototype.constructor = constructor;
|
3471 | }
|
3472 |
|
3473 | function extend(parent, definition) {
|
3474 | var prototype = Object.create(parent.prototype);
|
3475 | for (var key in definition) prototype[key] = definition[key];
|
3476 | return prototype;
|
3477 | }
|
3478 |
|
3479 | function Color() {}
|
3480 |
|
3481 | var darker = 0.7;
|
3482 | var brighter = 1 / darker;
|
3483 |
|
3484 | var reHex3 = /^#([0-9a-f]{3})$/;
|
3485 | var reHex6 = /^#([0-9a-f]{6})$/;
|
3486 | var reRgbInteger = /^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/;
|
3487 | var reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
|
3488 | var reRgbaInteger = /^rgba\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
|
3489 | var reRgbaPercent = /^rgba\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
|
3490 | var reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
|
3491 | var reHslaPercent = /^hsla\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
|
3492 | var named = {
|
3493 | aliceblue: 0xf0f8ff,
|
3494 | antiquewhite: 0xfaebd7,
|
3495 | aqua: 0x00ffff,
|
3496 | aquamarine: 0x7fffd4,
|
3497 | azure: 0xf0ffff,
|
3498 | beige: 0xf5f5dc,
|
3499 | bisque: 0xffe4c4,
|
3500 | black: 0x000000,
|
3501 | blanchedalmond: 0xffebcd,
|
3502 | blue: 0x0000ff,
|
3503 | blueviolet: 0x8a2be2,
|
3504 | brown: 0xa52a2a,
|
3505 | burlywood: 0xdeb887,
|
3506 | cadetblue: 0x5f9ea0,
|
3507 | chartreuse: 0x7fff00,
|
3508 | chocolate: 0xd2691e,
|
3509 | coral: 0xff7f50,
|
3510 | cornflowerblue: 0x6495ed,
|
3511 | cornsilk: 0xfff8dc,
|
3512 | crimson: 0xdc143c,
|
3513 | cyan: 0x00ffff,
|
3514 | darkblue: 0x00008b,
|
3515 | darkcyan: 0x008b8b,
|
3516 | darkgoldenrod: 0xb8860b,
|
3517 | darkgray: 0xa9a9a9,
|
3518 | darkgreen: 0x006400,
|
3519 | darkgrey: 0xa9a9a9,
|
3520 | darkkhaki: 0xbdb76b,
|
3521 | darkmagenta: 0x8b008b,
|
3522 | darkolivegreen: 0x556b2f,
|
3523 | darkorange: 0xff8c00,
|
3524 | darkorchid: 0x9932cc,
|
3525 | darkred: 0x8b0000,
|
3526 | darksalmon: 0xe9967a,
|
3527 | darkseagreen: 0x8fbc8f,
|
3528 | darkslateblue: 0x483d8b,
|
3529 | darkslategray: 0x2f4f4f,
|
3530 | darkslategrey: 0x2f4f4f,
|
3531 | darkturquoise: 0x00ced1,
|
3532 | darkviolet: 0x9400d3,
|
3533 | deeppink: 0xff1493,
|
3534 | deepskyblue: 0x00bfff,
|
3535 | dimgray: 0x696969,
|
3536 | dimgrey: 0x696969,
|
3537 | dodgerblue: 0x1e90ff,
|
3538 | firebrick: 0xb22222,
|
3539 | floralwhite: 0xfffaf0,
|
3540 | forestgreen: 0x228b22,
|
3541 | fuchsia: 0xff00ff,
|
3542 | gainsboro: 0xdcdcdc,
|
3543 | ghostwhite: 0xf8f8ff,
|
3544 | gold: 0xffd700,
|
3545 | goldenrod: 0xdaa520,
|
3546 | gray: 0x808080,
|
3547 | green: 0x008000,
|
3548 | greenyellow: 0xadff2f,
|
3549 | grey: 0x808080,
|
3550 | honeydew: 0xf0fff0,
|
3551 | hotpink: 0xff69b4,
|
3552 | indianred: 0xcd5c5c,
|
3553 | indigo: 0x4b0082,
|
3554 | ivory: 0xfffff0,
|
3555 | khaki: 0xf0e68c,
|
3556 | lavender: 0xe6e6fa,
|
3557 | lavenderblush: 0xfff0f5,
|
3558 | lawngreen: 0x7cfc00,
|
3559 | lemonchiffon: 0xfffacd,
|
3560 | lightblue: 0xadd8e6,
|
3561 | lightcoral: 0xf08080,
|
3562 | lightcyan: 0xe0ffff,
|
3563 | lightgoldenrodyellow: 0xfafad2,
|
3564 | lightgray: 0xd3d3d3,
|
3565 | lightgreen: 0x90ee90,
|
3566 | lightgrey: 0xd3d3d3,
|
3567 | lightpink: 0xffb6c1,
|
3568 | lightsalmon: 0xffa07a,
|
3569 | lightseagreen: 0x20b2aa,
|
3570 | lightskyblue: 0x87cefa,
|
3571 | lightslategray: 0x778899,
|
3572 | lightslategrey: 0x778899,
|
3573 | lightsteelblue: 0xb0c4de,
|
3574 | lightyellow: 0xffffe0,
|
3575 | lime: 0x00ff00,
|
3576 | limegreen: 0x32cd32,
|
3577 | linen: 0xfaf0e6,
|
3578 | magenta: 0xff00ff,
|
3579 | maroon: 0x800000,
|
3580 | mediumaquamarine: 0x66cdaa,
|
3581 | mediumblue: 0x0000cd,
|
3582 | mediumorchid: 0xba55d3,
|
3583 | mediumpurple: 0x9370db,
|
3584 | mediumseagreen: 0x3cb371,
|
3585 | mediumslateblue: 0x7b68ee,
|
3586 | mediumspringgreen: 0x00fa9a,
|
3587 | mediumturquoise: 0x48d1cc,
|
3588 | mediumvioletred: 0xc71585,
|
3589 | midnightblue: 0x191970,
|
3590 | mintcream: 0xf5fffa,
|
3591 | mistyrose: 0xffe4e1,
|
3592 | moccasin: 0xffe4b5,
|
3593 | navajowhite: 0xffdead,
|
3594 | navy: 0x000080,
|
3595 | oldlace: 0xfdf5e6,
|
3596 | olive: 0x808000,
|
3597 | olivedrab: 0x6b8e23,
|
3598 | orange: 0xffa500,
|
3599 | orangered: 0xff4500,
|
3600 | orchid: 0xda70d6,
|
3601 | palegoldenrod: 0xeee8aa,
|
3602 | palegreen: 0x98fb98,
|
3603 | paleturquoise: 0xafeeee,
|
3604 | palevioletred: 0xdb7093,
|
3605 | papayawhip: 0xffefd5,
|
3606 | peachpuff: 0xffdab9,
|
3607 | peru: 0xcd853f,
|
3608 | pink: 0xffc0cb,
|
3609 | plum: 0xdda0dd,
|
3610 | powderblue: 0xb0e0e6,
|
3611 | purple: 0x800080,
|
3612 | rebeccapurple: 0x663399,
|
3613 | red: 0xff0000,
|
3614 | rosybrown: 0xbc8f8f,
|
3615 | royalblue: 0x4169e1,
|
3616 | saddlebrown: 0x8b4513,
|
3617 | salmon: 0xfa8072,
|
3618 | sandybrown: 0xf4a460,
|
3619 | seagreen: 0x2e8b57,
|
3620 | seashell: 0xfff5ee,
|
3621 | sienna: 0xa0522d,
|
3622 | silver: 0xc0c0c0,
|
3623 | skyblue: 0x87ceeb,
|
3624 | slateblue: 0x6a5acd,
|
3625 | slategray: 0x708090,
|
3626 | slategrey: 0x708090,
|
3627 | snow: 0xfffafa,
|
3628 | springgreen: 0x00ff7f,
|
3629 | steelblue: 0x4682b4,
|
3630 | tan: 0xd2b48c,
|
3631 | teal: 0x008080,
|
3632 | thistle: 0xd8bfd8,
|
3633 | tomato: 0xff6347,
|
3634 | turquoise: 0x40e0d0,
|
3635 | violet: 0xee82ee,
|
3636 | wheat: 0xf5deb3,
|
3637 | white: 0xffffff,
|
3638 | whitesmoke: 0xf5f5f5,
|
3639 | yellow: 0xffff00,
|
3640 | yellowgreen: 0x9acd32
|
3641 | };
|
3642 |
|
3643 | define(Color, color, {
|
3644 | displayable: function() {
|
3645 | return this.rgb().displayable();
|
3646 | },
|
3647 | toString: function() {
|
3648 | return this.rgb() + "";
|
3649 | }
|
3650 | });
|
3651 |
|
3652 | function color(format) {
|
3653 | var m;
|
3654 | format = (format + "").trim().toLowerCase();
|
3655 | 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))
|
3656 | : (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16))
|
3657 | : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1)
|
3658 | : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1)
|
3659 | : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4])
|
3660 | : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4])
|
3661 | : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1)
|
3662 | : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4])
|
3663 | : named.hasOwnProperty(format) ? rgbn(named[format])
|
3664 | : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
|
3665 | : null;
|
3666 | }
|
3667 |
|
3668 | function rgbn(n) {
|
3669 | return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
|
3670 | }
|
3671 |
|
3672 | function rgba(r, g, b, a) {
|
3673 | if (a <= 0) r = g = b = NaN;
|
3674 | return new Rgb(r, g, b, a);
|
3675 | }
|
3676 |
|
3677 | function rgbConvert(o) {
|
3678 | if (!(o instanceof Color)) o = color(o);
|
3679 | if (!o) return new Rgb;
|
3680 | o = o.rgb();
|
3681 | return new Rgb(o.r, o.g, o.b, o.opacity);
|
3682 | }
|
3683 |
|
3684 | function colorRgb(r, g, b, opacity) {
|
3685 | return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
|
3686 | }
|
3687 |
|
3688 | function Rgb(r, g, b, opacity) {
|
3689 | this.r = +r;
|
3690 | this.g = +g;
|
3691 | this.b = +b;
|
3692 | this.opacity = +opacity;
|
3693 | }
|
3694 |
|
3695 | define(Rgb, colorRgb, extend(Color, {
|
3696 | brighter: function(k) {
|
3697 | k = k == null ? brighter : Math.pow(brighter, k);
|
3698 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
3699 | },
|
3700 | darker: function(k) {
|
3701 | k = k == null ? darker : Math.pow(darker, k);
|
3702 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
3703 | },
|
3704 | rgb: function() {
|
3705 | return this;
|
3706 | },
|
3707 | displayable: function() {
|
3708 | return (0 <= this.r && this.r <= 255)
|
3709 | && (0 <= this.g && this.g <= 255)
|
3710 | && (0 <= this.b && this.b <= 255)
|
3711 | && (0 <= this.opacity && this.opacity <= 1);
|
3712 | },
|
3713 | toString: function() {
|
3714 | var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
|
3715 | return (a === 1 ? "rgb(" : "rgba(")
|
3716 | + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
|
3717 | + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
|
3718 | + Math.max(0, Math.min(255, Math.round(this.b) || 0))
|
3719 | + (a === 1 ? ")" : ", " + a + ")");
|
3720 | }
|
3721 | }));
|
3722 |
|
3723 | function hsla(h, s, l, a) {
|
3724 | if (a <= 0) h = s = l = NaN;
|
3725 | else if (l <= 0 || l >= 1) h = s = NaN;
|
3726 | else if (s <= 0) h = NaN;
|
3727 | return new Hsl(h, s, l, a);
|
3728 | }
|
3729 |
|
3730 | function hslConvert(o) {
|
3731 | if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
|
3732 | if (!(o instanceof Color)) o = color(o);
|
3733 | if (!o) return new Hsl;
|
3734 | if (o instanceof Hsl) return o;
|
3735 | o = o.rgb();
|
3736 | var r = o.r / 255,
|
3737 | g = o.g / 255,
|
3738 | b = o.b / 255,
|
3739 | min = Math.min(r, g, b),
|
3740 | max = Math.max(r, g, b),
|
3741 | h = NaN,
|
3742 | s = max - min,
|
3743 | l = (max + min) / 2;
|
3744 | if (s) {
|
3745 | if (r === max) h = (g - b) / s + (g < b) * 6;
|
3746 | else if (g === max) h = (b - r) / s + 2;
|
3747 | else h = (r - g) / s + 4;
|
3748 | s /= l < 0.5 ? max + min : 2 - max - min;
|
3749 | h *= 60;
|
3750 | } else {
|
3751 | s = l > 0 && l < 1 ? 0 : h;
|
3752 | }
|
3753 | return new Hsl(h, s, l, o.opacity);
|
3754 | }
|
3755 |
|
3756 | function colorHsl(h, s, l, opacity) {
|
3757 | return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
|
3758 | }
|
3759 |
|
3760 | function Hsl(h, s, l, opacity) {
|
3761 | this.h = +h;
|
3762 | this.s = +s;
|
3763 | this.l = +l;
|
3764 | this.opacity = +opacity;
|
3765 | }
|
3766 |
|
3767 | define(Hsl, colorHsl, extend(Color, {
|
3768 | brighter: function(k) {
|
3769 | k = k == null ? brighter : Math.pow(brighter, k);
|
3770 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
3771 | },
|
3772 | darker: function(k) {
|
3773 | k = k == null ? darker : Math.pow(darker, k);
|
3774 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
3775 | },
|
3776 | rgb: function() {
|
3777 | var h = this.h % 360 + (this.h < 0) * 360,
|
3778 | s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
|
3779 | l = this.l,
|
3780 | m2 = l + (l < 0.5 ? l : 1 - l) * s,
|
3781 | m1 = 2 * l - m2;
|
3782 | return new Rgb(
|
3783 | hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
|
3784 | hsl2rgb(h, m1, m2),
|
3785 | hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
|
3786 | this.opacity
|
3787 | );
|
3788 | },
|
3789 | displayable: function() {
|
3790 | return (0 <= this.s && this.s <= 1 || isNaN(this.s))
|
3791 | && (0 <= this.l && this.l <= 1)
|
3792 | && (0 <= this.opacity && this.opacity <= 1);
|
3793 | }
|
3794 | }));
|
3795 |
|
3796 |
|
3797 | function hsl2rgb(h, m1, m2) {
|
3798 | return (h < 60 ? m1 + (m2 - m1) * h / 60
|
3799 | : h < 180 ? m2
|
3800 | : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
|
3801 | : m1) * 255;
|
3802 | }
|
3803 |
|
3804 | var deg2rad = Math.PI / 180;
|
3805 | var rad2deg = 180 / Math.PI;
|
3806 |
|
3807 | var Kn = 18;
|
3808 | var Xn = 0.950470;
|
3809 | var Yn = 1;
|
3810 | var Zn = 1.088830;
|
3811 | var t0 = 4 / 29;
|
3812 | var t1 = 6 / 29;
|
3813 | var t2 = 3 * t1 * t1;
|
3814 | var t3 = t1 * t1 * t1;
|
3815 | function labConvert(o) {
|
3816 | if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
|
3817 | if (o instanceof Hcl) {
|
3818 | var h = o.h * deg2rad;
|
3819 | return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
|
3820 | }
|
3821 | if (!(o instanceof Rgb)) o = rgbConvert(o);
|
3822 | var b = rgb2xyz(o.r),
|
3823 | a = rgb2xyz(o.g),
|
3824 | l = rgb2xyz(o.b),
|
3825 | x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
|
3826 | y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
|
3827 | z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
|
3828 | return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
|
3829 | }
|
3830 |
|
3831 | function lab(l, a, b, opacity) {
|
3832 | return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
|
3833 | }
|
3834 |
|
3835 | function Lab(l, a, b, opacity) {
|
3836 | this.l = +l;
|
3837 | this.a = +a;
|
3838 | this.b = +b;
|
3839 | this.opacity = +opacity;
|
3840 | }
|
3841 |
|
3842 | define(Lab, lab, extend(Color, {
|
3843 | brighter: function(k) {
|
3844 | return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
|
3845 | },
|
3846 | darker: function(k) {
|
3847 | return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
|
3848 | },
|
3849 | rgb: function() {
|
3850 | var y = (this.l + 16) / 116,
|
3851 | x = isNaN(this.a) ? y : y + this.a / 500,
|
3852 | z = isNaN(this.b) ? y : y - this.b / 200;
|
3853 | y = Yn * lab2xyz(y);
|
3854 | x = Xn * lab2xyz(x);
|
3855 | z = Zn * lab2xyz(z);
|
3856 | return new Rgb(
|
3857 | xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z),
|
3858 | xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
|
3859 | xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
|
3860 | this.opacity
|
3861 | );
|
3862 | }
|
3863 | }));
|
3864 |
|
3865 | function xyz2lab(t) {
|
3866 | return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
|
3867 | }
|
3868 |
|
3869 | function lab2xyz(t) {
|
3870 | return t > t1 ? t * t * t : t2 * (t - t0);
|
3871 | }
|
3872 |
|
3873 | function xyz2rgb(x) {
|
3874 | return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
|
3875 | }
|
3876 |
|
3877 | function rgb2xyz(x) {
|
3878 | return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
|
3879 | }
|
3880 |
|
3881 | function hclConvert(o) {
|
3882 | if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
|
3883 | if (!(o instanceof Lab)) o = labConvert(o);
|
3884 | var h = Math.atan2(o.b, o.a) * rad2deg;
|
3885 | return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
|
3886 | }
|
3887 |
|
3888 | function colorHcl(h, c, l, opacity) {
|
3889 | return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
|
3890 | }
|
3891 |
|
3892 | function Hcl(h, c, l, opacity) {
|
3893 | this.h = +h;
|
3894 | this.c = +c;
|
3895 | this.l = +l;
|
3896 | this.opacity = +opacity;
|
3897 | }
|
3898 |
|
3899 | define(Hcl, colorHcl, extend(Color, {
|
3900 | brighter: function(k) {
|
3901 | return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
|
3902 | },
|
3903 | darker: function(k) {
|
3904 | return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
|
3905 | },
|
3906 | rgb: function() {
|
3907 | return labConvert(this).rgb();
|
3908 | }
|
3909 | }));
|
3910 |
|
3911 | var A = -0.14861;
|
3912 | var B = +1.78277;
|
3913 | var C = -0.29227;
|
3914 | var D = -0.90649;
|
3915 | var E = +1.97294;
|
3916 | var ED = E * D;
|
3917 | var EB = E * B;
|
3918 | var BC_DA = B * C - D * A;
|
3919 | function cubehelixConvert(o) {
|
3920 | if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
|
3921 | if (!(o instanceof Rgb)) o = rgbConvert(o);
|
3922 | var r = o.r / 255,
|
3923 | g = o.g / 255,
|
3924 | b = o.b / 255,
|
3925 | l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
|
3926 | bl = b - l,
|
3927 | k = (E * (g - l) - C * bl) / D,
|
3928 | s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)),
|
3929 | h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
|
3930 | return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
|
3931 | }
|
3932 |
|
3933 | function cubehelix(h, s, l, opacity) {
|
3934 | return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
|
3935 | }
|
3936 |
|
3937 | function Cubehelix(h, s, l, opacity) {
|
3938 | this.h = +h;
|
3939 | this.s = +s;
|
3940 | this.l = +l;
|
3941 | this.opacity = +opacity;
|
3942 | }
|
3943 |
|
3944 | define(Cubehelix, cubehelix, extend(Color, {
|
3945 | brighter: function(k) {
|
3946 | k = k == null ? brighter : Math.pow(brighter, k);
|
3947 | return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
|
3948 | },
|
3949 | darker: function(k) {
|
3950 | k = k == null ? darker : Math.pow(darker, k);
|
3951 | return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
|
3952 | },
|
3953 | rgb: function() {
|
3954 | var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
|
3955 | l = +this.l,
|
3956 | a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
|
3957 | cosh = Math.cos(h),
|
3958 | sinh = Math.sin(h);
|
3959 | return new Rgb(
|
3960 | 255 * (l + a * (A * cosh + B * sinh)),
|
3961 | 255 * (l + a * (C * cosh + D * sinh)),
|
3962 | 255 * (l + a * (E * cosh)),
|
3963 | this.opacity
|
3964 | );
|
3965 | }
|
3966 | }));
|
3967 |
|
3968 | function basis$1(t1, v0, v1, v2, v3) {
|
3969 | var t2 = t1 * t1, t3 = t2 * t1;
|
3970 | return ((1 - 3 * t1 + 3 * t2 - t3) * v0
|
3971 | + (4 - 6 * t2 + 3 * t3) * v1
|
3972 | + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
|
3973 | + t3 * v3) / 6;
|
3974 | }
|
3975 |
|
3976 | function basis$2(values) {
|
3977 | var n = values.length - 1;
|
3978 | return function(t) {
|
3979 | var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
|
3980 | v1 = values[i],
|
3981 | v2 = values[i + 1],
|
3982 | v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
|
3983 | v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
|
3984 | return basis$1((t - i / n) * n, v0, v1, v2, v3);
|
3985 | };
|
3986 | }
|
3987 |
|
3988 | function basisClosed$1(values) {
|
3989 | var n = values.length;
|
3990 | return function(t) {
|
3991 | var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
|
3992 | v0 = values[(i + n - 1) % n],
|
3993 | v1 = values[i % n],
|
3994 | v2 = values[(i + 1) % n],
|
3995 | v3 = values[(i + 2) % n];
|
3996 | return basis$1((t - i / n) * n, v0, v1, v2, v3);
|
3997 | };
|
3998 | }
|
3999 |
|
4000 | function constant$2(x) {
|
4001 | return function() {
|
4002 | return x;
|
4003 | };
|
4004 | }
|
4005 |
|
4006 | function linear$1(a, d) {
|
4007 | return function(t) {
|
4008 | return a + t * d;
|
4009 | };
|
4010 | }
|
4011 |
|
4012 | function exponential$1(a, b, y) {
|
4013 | return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
|
4014 | return Math.pow(a + t * b, y);
|
4015 | };
|
4016 | }
|
4017 |
|
4018 | function hue(a, b) {
|
4019 | var d = b - a;
|
4020 | return d ? linear$1(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$2(isNaN(a) ? b : a);
|
4021 | }
|
4022 |
|
4023 | function gamma(y) {
|
4024 | return (y = +y) === 1 ? nogamma : function(a, b) {
|
4025 | return b - a ? exponential$1(a, b, y) : constant$2(isNaN(a) ? b : a);
|
4026 | };
|
4027 | }
|
4028 |
|
4029 | function nogamma(a, b) {
|
4030 | var d = b - a;
|
4031 | return d ? linear$1(a, d) : constant$2(isNaN(a) ? b : a);
|
4032 | }
|
4033 |
|
4034 | var interpolateRgb = (function rgbGamma(y) {
|
4035 | var color = gamma(y);
|
4036 |
|
4037 | function rgb(start, end) {
|
4038 | var r = color((start = colorRgb(start)).r, (end = colorRgb(end)).r),
|
4039 | g = color(start.g, end.g),
|
4040 | b = color(start.b, end.b),
|
4041 | opacity = color(start.opacity, end.opacity);
|
4042 | return function(t) {
|
4043 | start.r = r(t);
|
4044 | start.g = g(t);
|
4045 | start.b = b(t);
|
4046 | start.opacity = opacity(t);
|
4047 | return start + "";
|
4048 | };
|
4049 | }
|
4050 |
|
4051 | rgb.gamma = rgbGamma;
|
4052 |
|
4053 | return rgb;
|
4054 | })(1);
|
4055 |
|
4056 | function rgbSpline(spline) {
|
4057 | return function(colors) {
|
4058 | var n = colors.length,
|
4059 | r = new Array(n),
|
4060 | g = new Array(n),
|
4061 | b = new Array(n),
|
4062 | i, color;
|
4063 | for (i = 0; i < n; ++i) {
|
4064 | color = colorRgb(colors[i]);
|
4065 | r[i] = color.r || 0;
|
4066 | g[i] = color.g || 0;
|
4067 | b[i] = color.b || 0;
|
4068 | }
|
4069 | r = spline(r);
|
4070 | g = spline(g);
|
4071 | b = spline(b);
|
4072 | color.opacity = 1;
|
4073 | return function(t) {
|
4074 | color.r = r(t);
|
4075 | color.g = g(t);
|
4076 | color.b = b(t);
|
4077 | return color + "";
|
4078 | };
|
4079 | };
|
4080 | }
|
4081 |
|
4082 | var rgbBasis = rgbSpline(basis$2);
|
4083 | var rgbBasisClosed = rgbSpline(basisClosed$1);
|
4084 |
|
4085 | function array$1(a, b) {
|
4086 | var nb = b ? b.length : 0,
|
4087 | na = a ? Math.min(nb, a.length) : 0,
|
4088 | x = new Array(nb),
|
4089 | c = new Array(nb),
|
4090 | i;
|
4091 |
|
4092 | for (i = 0; i < na; ++i) x[i] = interpolate(a[i], b[i]);
|
4093 | for (; i < nb; ++i) c[i] = b[i];
|
4094 |
|
4095 | return function(t) {
|
4096 | for (i = 0; i < na; ++i) c[i] = x[i](t);
|
4097 | return c;
|
4098 | };
|
4099 | }
|
4100 |
|
4101 | function interpolateNumber(a, b) {
|
4102 | return a = +a, b -= a, function(t) {
|
4103 | return a + b * t;
|
4104 | };
|
4105 | }
|
4106 |
|
4107 | function object(a, b) {
|
4108 | var i = {},
|
4109 | c = {},
|
4110 | k;
|
4111 |
|
4112 | if (a === null || typeof a !== "object") a = {};
|
4113 | if (b === null || typeof b !== "object") b = {};
|
4114 |
|
4115 | for (k in b) {
|
4116 | if (k in a) {
|
4117 | i[k] = interpolate(a[k], b[k]);
|
4118 | } else {
|
4119 | c[k] = b[k];
|
4120 | }
|
4121 | }
|
4122 |
|
4123 | return function(t) {
|
4124 | for (k in i) c[k] = i[k](t);
|
4125 | return c;
|
4126 | };
|
4127 | }
|
4128 |
|
4129 | var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;
|
4130 | var reB = new RegExp(reA.source, "g");
|
4131 | function zero(b) {
|
4132 | return function() {
|
4133 | return b;
|
4134 | };
|
4135 | }
|
4136 |
|
4137 | function one(b) {
|
4138 | return function(t) {
|
4139 | return b(t) + "";
|
4140 | };
|
4141 | }
|
4142 |
|
4143 | function interpolateString(a, b) {
|
4144 | var bi = reA.lastIndex = reB.lastIndex = 0,
|
4145 | am,
|
4146 | bm,
|
4147 | bs,
|
4148 | i = -1,
|
4149 | s = [],
|
4150 | q = [];
|
4151 |
|
4152 |
|
4153 | a = a + "", b = b + "";
|
4154 |
|
4155 |
|
4156 | while ((am = reA.exec(a))
|
4157 | && (bm = reB.exec(b))) {
|
4158 | if ((bs = bm.index) > bi) {
|
4159 | bs = b.slice(bi, bs);
|
4160 | if (s[i]) s[i] += bs;
|
4161 | else s[++i] = bs;
|
4162 | }
|
4163 | if ((am = am[0]) === (bm = bm[0])) {
|
4164 | if (s[i]) s[i] += bm;
|
4165 | else s[++i] = bm;
|
4166 | } else {
|
4167 | s[++i] = null;
|
4168 | q.push({i: i, x: interpolateNumber(am, bm)});
|
4169 | }
|
4170 | bi = reB.lastIndex;
|
4171 | }
|
4172 |
|
4173 |
|
4174 | if (bi < b.length) {
|
4175 | bs = b.slice(bi);
|
4176 | if (s[i]) s[i] += bs;
|
4177 | else s[++i] = bs;
|
4178 | }
|
4179 |
|
4180 |
|
4181 |
|
4182 | return s.length < 2 ? (q[0]
|
4183 | ? one(q[0].x)
|
4184 | : zero(b))
|
4185 | : (b = q.length, function(t) {
|
4186 | for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
|
4187 | return s.join("");
|
4188 | });
|
4189 | }
|
4190 |
|
4191 | function interpolate(a, b) {
|
4192 | var t = typeof b, c;
|
4193 | return b == null || t === "boolean" ? constant$2(b)
|
4194 | : (t === "number" ? interpolateNumber
|
4195 | : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
|
4196 | : b instanceof color ? interpolateRgb
|
4197 | : Array.isArray(b) ? array$1
|
4198 | : object)(a, b);
|
4199 | }
|
4200 |
|
4201 | function interpolateRound(a, b) {
|
4202 | return a = +a, b -= a, function(t) {
|
4203 | return Math.round(a + b * t);
|
4204 | };
|
4205 | }
|
4206 |
|
4207 | var degrees = 180 / Math.PI;
|
4208 |
|
4209 | var identity$2 = {
|
4210 | translateX: 0,
|
4211 | translateY: 0,
|
4212 | rotate: 0,
|
4213 | skewX: 0,
|
4214 | scaleX: 1,
|
4215 | scaleY: 1
|
4216 | };
|
4217 |
|
4218 | function decompose(a, b, c, d, e, f) {
|
4219 | var scaleX, scaleY, skewX;
|
4220 | if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
|
4221 | if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
|
4222 | if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
|
4223 | if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
|
4224 | return {
|
4225 | translateX: e,
|
4226 | translateY: f,
|
4227 | rotate: Math.atan2(b, a) * degrees,
|
4228 | skewX: Math.atan(skewX) * degrees,
|
4229 | scaleX: scaleX,
|
4230 | scaleY: scaleY
|
4231 | };
|
4232 | }
|
4233 |
|
4234 | var cssNode;
|
4235 | var cssRoot;
|
4236 | var cssView;
|
4237 | var svgNode;
|
4238 | function parseCss(value) {
|
4239 | if (value === "none") return identity$2;
|
4240 | if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
|
4241 | cssNode.style.transform = value;
|
4242 | value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
|
4243 | cssRoot.removeChild(cssNode);
|
4244 | var m = value.slice(7, -1).split(",");
|
4245 | return decompose(+m[0], +m[1], +m[2], +m[3], +m[4], +m[5]);
|
4246 | }
|
4247 |
|
4248 | function parseSvg(value) {
|
4249 | if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
4250 | svgNode.setAttribute("transform", value == null ? "" : value);
|
4251 | var m = svgNode.transform.baseVal.consolidate().matrix;
|
4252 | return decompose(m.a, m.b, m.c, m.d, m.e, m.f);
|
4253 | }
|
4254 |
|
4255 | function interpolateTransform(parse, pxComma, pxParen, degParen) {
|
4256 |
|
4257 | function pop(s) {
|
4258 | return s.length ? s.pop() + " " : "";
|
4259 | }
|
4260 |
|
4261 | function translate(xa, ya, xb, yb, s, q) {
|
4262 | if (xa !== xb || ya !== yb) {
|
4263 | var i = s.push("translate(", null, pxComma, null, pxParen);
|
4264 | q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
|
4265 | } else if (xb || yb) {
|
4266 | s.push("translate(" + xb + pxComma + yb + pxParen);
|
4267 | }
|
4268 | }
|
4269 |
|
4270 | function rotate(a, b, s, q) {
|
4271 | if (a !== b) {
|
4272 | if (a - b > 180) b += 360; else if (b - a > 180) a += 360;
|
4273 | q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
|
4274 | } else if (b) {
|
4275 | s.push(pop(s) + "rotate(" + b + degParen);
|
4276 | }
|
4277 | }
|
4278 |
|
4279 | function skewX(a, b, s, q) {
|
4280 | if (a !== b) {
|
4281 | q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
|
4282 | } else if (b) {
|
4283 | s.push(pop(s) + "skewX(" + b + degParen);
|
4284 | }
|
4285 | }
|
4286 |
|
4287 | function scale(xa, ya, xb, yb, s, q) {
|
4288 | if (xa !== xb || ya !== yb) {
|
4289 | var i = s.push(pop(s) + "scale(", null, ",", null, ")");
|
4290 | q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
|
4291 | } else if (xb !== 1 || yb !== 1) {
|
4292 | s.push(pop(s) + "scale(" + xb + "," + yb + ")");
|
4293 | }
|
4294 | }
|
4295 |
|
4296 | return function(a, b) {
|
4297 | var s = [],
|
4298 | q = [];
|
4299 | a = parse(a), b = parse(b);
|
4300 | translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
|
4301 | rotate(a.rotate, b.rotate, s, q);
|
4302 | skewX(a.skewX, b.skewX, s, q);
|
4303 | scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
|
4304 | a = b = null;
|
4305 | return function(t) {
|
4306 | var i = -1, n = q.length, o;
|
4307 | while (++i < n) s[(o = q[i]).i] = o.x(t);
|
4308 | return s.join("");
|
4309 | };
|
4310 | };
|
4311 | }
|
4312 |
|
4313 | var interpolateTransform$1 = interpolateTransform(parseCss, "px, ", "px)", "deg)");
|
4314 | var interpolateTransform$2 = interpolateTransform(parseSvg, ", ", ")", ")");
|
4315 |
|
4316 | var rho = Math.SQRT2;
|
4317 | var rho2 = 2;
|
4318 | var rho4 = 4;
|
4319 | var epsilon2 = 1e-12;
|
4320 | function cosh(x) {
|
4321 | return ((x = Math.exp(x)) + 1 / x) / 2;
|
4322 | }
|
4323 |
|
4324 | function sinh(x) {
|
4325 | return ((x = Math.exp(x)) - 1 / x) / 2;
|
4326 | }
|
4327 |
|
4328 | function tanh(x) {
|
4329 | return ((x = Math.exp(2 * x)) - 1) / (x + 1);
|
4330 | }
|
4331 |
|
4332 |
|
4333 |
|
4334 | function interpolateZoom(p0, p1) {
|
4335 | var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
|
4336 | ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
|
4337 | dx = ux1 - ux0,
|
4338 | dy = uy1 - uy0,
|
4339 | d2 = dx * dx + dy * dy,
|
4340 | i,
|
4341 | S;
|
4342 |
|
4343 |
|
4344 | if (d2 < epsilon2) {
|
4345 | S = Math.log(w1 / w0) / rho;
|
4346 | i = function(t) {
|
4347 | return [
|
4348 | ux0 + t * dx,
|
4349 | uy0 + t * dy,
|
4350 | w0 * Math.exp(rho * t * S)
|
4351 | ];
|
4352 | }
|
4353 | }
|
4354 |
|
4355 |
|
4356 | else {
|
4357 | var d1 = Math.sqrt(d2),
|
4358 | b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
|
4359 | b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
|
4360 | r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
|
4361 | r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
|
4362 | S = (r1 - r0) / rho;
|
4363 | i = function(t) {
|
4364 | var s = t * S,
|
4365 | coshr0 = cosh(r0),
|
4366 | u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
|
4367 | return [
|
4368 | ux0 + u * dx,
|
4369 | uy0 + u * dy,
|
4370 | w0 * coshr0 / cosh(rho * s + r0)
|
4371 | ];
|
4372 | }
|
4373 | }
|
4374 |
|
4375 | i.duration = S * 1000;
|
4376 |
|
4377 | return i;
|
4378 | }
|
4379 |
|
4380 | function hsl(hue) {
|
4381 | return function(start, end) {
|
4382 | var h = hue((start = colorHsl(start)).h, (end = colorHsl(end)).h),
|
4383 | s = nogamma(start.s, end.s),
|
4384 | l = nogamma(start.l, end.l),
|
4385 | opacity = nogamma(start.opacity, end.opacity);
|
4386 | return function(t) {
|
4387 | start.h = h(t);
|
4388 | start.s = s(t);
|
4389 | start.l = l(t);
|
4390 | start.opacity = opacity(t);
|
4391 | return start + "";
|
4392 | };
|
4393 | }
|
4394 | }
|
4395 |
|
4396 | var hsl$1 = hsl(hue);
|
4397 | var hslLong = hsl(nogamma);
|
4398 |
|
4399 | function lab$1(start, end) {
|
4400 | var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
|
4401 | a = nogamma(start.a, end.a),
|
4402 | b = nogamma(start.b, end.b),
|
4403 | opacity = nogamma(start.opacity, end.opacity);
|
4404 | return function(t) {
|
4405 | start.l = l(t);
|
4406 | start.a = a(t);
|
4407 | start.b = b(t);
|
4408 | start.opacity = opacity(t);
|
4409 | return start + "";
|
4410 | };
|
4411 | }
|
4412 |
|
4413 | function hcl(hue) {
|
4414 | return function(start, end) {
|
4415 | var h = hue((start = colorHcl(start)).h, (end = colorHcl(end)).h),
|
4416 | c = nogamma(start.c, end.c),
|
4417 | l = nogamma(start.l, end.l),
|
4418 | opacity = nogamma(start.opacity, end.opacity);
|
4419 | return function(t) {
|
4420 | start.h = h(t);
|
4421 | start.c = c(t);
|
4422 | start.l = l(t);
|
4423 | start.opacity = opacity(t);
|
4424 | return start + "";
|
4425 | };
|
4426 | }
|
4427 | }
|
4428 |
|
4429 | var hcl$1 = hcl(hue);
|
4430 | var hclLong = hcl(nogamma);
|
4431 |
|
4432 | function cubehelix$1(hue) {
|
4433 | return (function cubehelixGamma(y) {
|
4434 | y = +y;
|
4435 |
|
4436 | function cubehelix$$(start, end) {
|
4437 | var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h),
|
4438 | s = nogamma(start.s, end.s),
|
4439 | l = nogamma(start.l, end.l),
|
4440 | opacity = nogamma(start.opacity, end.opacity);
|
4441 | return function(t) {
|
4442 | start.h = h(t);
|
4443 | start.s = s(t);
|
4444 | start.l = l(Math.pow(t, y));
|
4445 | start.opacity = opacity(t);
|
4446 | return start + "";
|
4447 | };
|
4448 | }
|
4449 |
|
4450 | cubehelix$$.gamma = cubehelixGamma;
|
4451 |
|
4452 | return cubehelix$$;
|
4453 | })(1);
|
4454 | }
|
4455 |
|
4456 | var cubehelix$2 = cubehelix$1(hue);
|
4457 | var interpolateCubehelixLong = cubehelix$1(nogamma);
|
4458 |
|
4459 | function quantize(interpolate, n) {
|
4460 | var samples = new Array(n);
|
4461 | for (var i = 0; i < n; ++i) samples[i] = interpolate(i / (n - 1));
|
4462 | return samples;
|
4463 | }
|
4464 |
|
4465 | var noop$1 = {value: function() {}};
|
4466 |
|
4467 | function dispatch() {
|
4468 | for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
|
4469 | if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
|
4470 | _[t] = [];
|
4471 | }
|
4472 | return new Dispatch(_);
|
4473 | }
|
4474 |
|
4475 | function Dispatch(_) {
|
4476 | this._ = _;
|
4477 | }
|
4478 |
|
4479 | function parseTypenames(typenames, types) {
|
4480 | return typenames.trim().split(/^|\s+/).map(function(t) {
|
4481 | var name = "", i = t.indexOf(".");
|
4482 | if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
4483 | if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
|
4484 | return {type: t, name: name};
|
4485 | });
|
4486 | }
|
4487 |
|
4488 | Dispatch.prototype = dispatch.prototype = {
|
4489 | constructor: Dispatch,
|
4490 | on: function(typename, callback) {
|
4491 | var _ = this._,
|
4492 | T = parseTypenames(typename + "", _),
|
4493 | t,
|
4494 | i = -1,
|
4495 | n = T.length;
|
4496 |
|
4497 |
|
4498 | if (arguments.length < 2) {
|
4499 | while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
|
4500 | return;
|
4501 | }
|
4502 |
|
4503 | // If a type was specified, set the callback for the given type and name.
|
4504 | // Otherwise, if a null callback was specified, remove callbacks of the given name.
|
4505 | if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
|
4506 | while (++i < n) {
|
4507 | if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
|
4508 | else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
|
4509 | }
|
4510 |
|
4511 | return this;
|
4512 | },
|
4513 | copy: function() {
|
4514 | var copy = {}, _ = this._;
|
4515 | for (var t in _) copy[t] = _[t].slice();
|
4516 | return new Dispatch(copy);
|
4517 | },
|
4518 | call: function(type, that) {
|
4519 | if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
|
4520 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
4521 | for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
4522 | },
|
4523 | apply: function(type, that, args) {
|
4524 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
4525 | for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
4526 | }
|
4527 | };
|
4528 |
|
4529 | function get(type, name) {
|
4530 | for (var i = 0, n = type.length, c; i < n; ++i) {
|
4531 | if ((c = type[i]).name === name) {
|
4532 | return c.value;
|
4533 | }
|
4534 | }
|
4535 | }
|
4536 |
|
4537 | function set$1(type, name, callback) {
|
4538 | for (var i = 0, n = type.length; i < n; ++i) {
|
4539 | if (type[i].name === name) {
|
4540 | type[i] = noop$1, type = type.slice(0, i).concat(type.slice(i + 1));
|
4541 | break;
|
4542 | }
|
4543 | }
|
4544 | if (callback != null) type.push({name: name, value: callback});
|
4545 | return type;
|
4546 | }
|
4547 |
|
4548 | function objectConverter(columns) {
|
4549 | return new Function("d", "return {" + columns.map(function(name, i) {
|
4550 | return JSON.stringify(name) + ": d[" + i + "]";
|
4551 | }).join(",") + "}");
|
4552 | }
|
4553 |
|
4554 | function customConverter(columns, f) {
|
4555 | var object = objectConverter(columns);
|
4556 | return function(row, i) {
|
4557 | return f(object(row), i, columns);
|
4558 | };
|
4559 | }
|
4560 |
|
4561 |
|
4562 | function inferColumns(rows) {
|
4563 | var columnSet = Object.create(null),
|
4564 | columns = [];
|
4565 |
|
4566 | rows.forEach(function(row) {
|
4567 | for (var column in row) {
|
4568 | if (!(column in columnSet)) {
|
4569 | columns.push(columnSet[column] = column);
|
4570 | }
|
4571 | }
|
4572 | });
|
4573 |
|
4574 | return columns;
|
4575 | }
|
4576 |
|
4577 | function dsv(delimiter) {
|
4578 | var reFormat = new RegExp("[\"" + delimiter + "\n]"),
|
4579 | delimiterCode = delimiter.charCodeAt(0);
|
4580 |
|
4581 | function parse(text, f) {
|
4582 | var convert, columns, rows = parseRows(text, function(row, i) {
|
4583 | if (convert) return convert(row, i - 1);
|
4584 | columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
|
4585 | });
|
4586 | rows.columns = columns;
|
4587 | return rows;
|
4588 | }
|
4589 |
|
4590 | function parseRows(text, f) {
|
4591 | var EOL = {},
|
4592 | EOF = {},
|
4593 | rows = [],
|
4594 | N = text.length,
|
4595 | I = 0,
|
4596 | n = 0,
|
4597 | t,
|
4598 | eol;
|
4599 |
|
4600 | function token() {
|
4601 | if (I >= N) return EOF;
|
4602 | if (eol) return eol = false, EOL;
|
4603 |
|
4604 |
|
4605 | var j = I, c;
|
4606 | if (text.charCodeAt(j) === 34) {
|
4607 | var i = j;
|
4608 | while (i++ < N) {
|
4609 | if (text.charCodeAt(i) === 34) {
|
4610 | if (text.charCodeAt(i + 1) !== 34) break;
|
4611 | ++i;
|
4612 | }
|
4613 | }
|
4614 | I = i + 2;
|
4615 | c = text.charCodeAt(i + 1);
|
4616 | if (c === 13) {
|
4617 | eol = true;
|
4618 | if (text.charCodeAt(i + 2) === 10) ++I;
|
4619 | } else if (c === 10) {
|
4620 | eol = true;
|
4621 | }
|
4622 | return text.slice(j + 1, i).replace(/""/g, "\"");
|
4623 | }
|
4624 |
|
4625 | // common case: find next delimiter or newline
|
4626 | while (I < N) {
|
4627 | var k = 1;
|
4628 | c = text.charCodeAt(I++);
|
4629 | if (c === 10) eol = true; // \n
|
4630 | else if (c === 13) { eol = true; if (text.charCodeAt(I) === 10) ++I, ++k; } // \r|\r\n
|
4631 | else if (c !== delimiterCode) continue;
|
4632 | return text.slice(j, I - k);
|
4633 | }
|
4634 |
|
4635 | // special case: last token before EOF
|
4636 | return text.slice(j);
|
4637 | }
|
4638 |
|
4639 | while ((t = token()) !== EOF) {
|
4640 | var a = [];
|
4641 | while (t !== EOL && t !== EOF) {
|
4642 | a.push(t);
|
4643 | t = token();
|
4644 | }
|
4645 | if (f && (a = f(a, n++)) == null) continue;
|
4646 | rows.push(a);
|
4647 | }
|
4648 |
|
4649 | return rows;
|
4650 | }
|
4651 |
|
4652 | function format(rows, columns) {
|
4653 | if (columns == null) columns = inferColumns(rows);
|
4654 | return [columns.map(formatValue).join(delimiter)].concat(rows.map(function(row) {
|
4655 | return columns.map(function(column) {
|
4656 | return formatValue(row[column]);
|
4657 | }).join(delimiter);
|
4658 | })).join("\n");
|
4659 | }
|
4660 |
|
4661 | function formatRows(rows) {
|
4662 | return rows.map(formatRow).join("\n");
|
4663 | }
|
4664 |
|
4665 | function formatRow(row) {
|
4666 | return row.map(formatValue).join(delimiter);
|
4667 | }
|
4668 |
|
4669 | function formatValue(text) {
|
4670 | return text == null ? ""
|
4671 | : reFormat.test(text += "") ? "\"" + text.replace(/\"/g, "\"\"") + "\""
|
4672 | : text;
|
4673 | }
|
4674 |
|
4675 | return {
|
4676 | parse: parse,
|
4677 | parseRows: parseRows,
|
4678 | format: format,
|
4679 | formatRows: formatRows
|
4680 | };
|
4681 | }
|
4682 |
|
4683 | var csv = dsv(",");
|
4684 |
|
4685 | var csvParse = csv.parse;
|
4686 | var csvParseRows = csv.parseRows;
|
4687 | var csvFormat = csv.format;
|
4688 | var csvFormatRows = csv.formatRows;
|
4689 |
|
4690 | var tsv = dsv("\t");
|
4691 |
|
4692 | var tsvParse = tsv.parse;
|
4693 | var tsvParseRows = tsv.parseRows;
|
4694 | var tsvFormat = tsv.format;
|
4695 | var tsvFormatRows = tsv.formatRows;
|
4696 |
|
4697 | function request(url, callback) {
|
4698 | var request,
|
4699 | event = dispatch("beforesend", "progress", "load", "error"),
|
4700 | mimeType,
|
4701 | headers = map$1(),
|
4702 | xhr = new XMLHttpRequest,
|
4703 | user = null,
|
4704 | password = null,
|
4705 | response,
|
4706 | responseType,
|
4707 | timeout = 0;
|
4708 |
|
4709 | // If IE does not support CORS, use XDomainRequest.
|
4710 | if (typeof XDomainRequest !== "undefined"
|
4711 | && !("withCredentials" in xhr)
|
4712 | && /^(http(s)?:)?\/\//.test(url)) xhr = new XDomainRequest;
|
4713 |
|
4714 | "onload" in xhr
|
4715 | ? xhr.onload = xhr.onerror = xhr.ontimeout = respond
|
4716 | : xhr.onreadystatechange = function(o) { xhr.readyState > 3 && respond(o); };
|
4717 |
|
4718 | function respond(o) {
|
4719 | var status = xhr.status, result;
|
4720 | if (!status && hasResponse(xhr)
|
4721 | || status >= 200 && status < 300
|
4722 | || status === 304) {
|
4723 | if (response) {
|
4724 | try {
|
4725 | result = response.call(request, xhr);
|
4726 | } catch (e) {
|
4727 | event.call("error", request, e);
|
4728 | return;
|
4729 | }
|
4730 | } else {
|
4731 | result = xhr;
|
4732 | }
|
4733 | event.call("load", request, result);
|
4734 | } else {
|
4735 | event.call("error", request, o);
|
4736 | }
|
4737 | }
|
4738 |
|
4739 | xhr.onprogress = function(e) {
|
4740 | event.call("progress", request, e);
|
4741 | };
|
4742 |
|
4743 | request = {
|
4744 | header: function(name, value) {
|
4745 | name = (name + "").toLowerCase();
|
4746 | if (arguments.length < 2) return headers.get(name);
|
4747 | if (value == null) headers.remove(name);
|
4748 | else headers.set(name, value + "");
|
4749 | return request;
|
4750 | },
|
4751 |
|
4752 | // If mimeType is non-null and no Accept header is set, a default is used.
|
4753 | mimeType: function(value) {
|
4754 | if (!arguments.length) return mimeType;
|
4755 | mimeType = value == null ? null : value + "";
|
4756 | return request;
|
4757 | },
|
4758 |
|
4759 | // Specifies what type the response value should take;
|
4760 | // for instance, arraybuffer, blob, document, or text.
|
4761 | responseType: function(value) {
|
4762 | if (!arguments.length) return responseType;
|
4763 | responseType = value;
|
4764 | return request;
|
4765 | },
|
4766 |
|
4767 | timeout: function(value) {
|
4768 | if (!arguments.length) return timeout;
|
4769 | timeout = +value;
|
4770 | return request;
|
4771 | },
|
4772 |
|
4773 | user: function(value) {
|
4774 | return arguments.length < 1 ? user : (user = value == null ? null : value + "", request);
|
4775 | },
|
4776 |
|
4777 | password: function(value) {
|
4778 | return arguments.length < 1 ? password : (password = value == null ? null : value + "", request);
|
4779 | },
|
4780 |
|
4781 | // Specify how to convert the response content to a specific type;
|
4782 | // changes the callback value on "load" events.
|
4783 | response: function(value) {
|
4784 | response = value;
|
4785 | return request;
|
4786 | },
|
4787 |
|
4788 | // Alias for send("GET", …).
|
4789 | get: function(data, callback) {
|
4790 | return request.send("GET", data, callback);
|
4791 | },
|
4792 |
|
4793 | // Alias for send("POST", …).
|
4794 | post: function(data, callback) {
|
4795 | return request.send("POST", data, callback);
|
4796 | },
|
4797 |
|
4798 | // If callback is non-null, it will be used for error and load events.
|
4799 | send: function(method, data, callback) {
|
4800 | if (!callback && typeof data === "function") callback = data, data = null;
|
4801 | if (callback && callback.length === 1) callback = fixCallback(callback);
|
4802 | xhr.open(method, url, true, user, password);
|
4803 | if (mimeType != null && !headers.has("accept")) headers.set("accept", mimeType + ",*/*");
|
4804 | if (xhr.setRequestHeader) headers.each(function(value, name) { xhr.setRequestHeader(name, value); });
|
4805 | if (mimeType != null && xhr.overrideMimeType) xhr.overrideMimeType(mimeType);
|
4806 | if (responseType != null) xhr.responseType = responseType;
|
4807 | if (timeout > 0) xhr.timeout = timeout;
|
4808 | if (callback) request.on("error", callback).on("load", function(xhr) { callback(null, xhr); });
|
4809 | event.call("beforesend", request, xhr);
|
4810 | xhr.send(data == null ? null : data);
|
4811 | return request;
|
4812 | },
|
4813 |
|
4814 | abort: function() {
|
4815 | xhr.abort();
|
4816 | return request;
|
4817 | },
|
4818 |
|
4819 | on: function() {
|
4820 | var value = event.on.apply(event, arguments);
|
4821 | return value === event ? request : value;
|
4822 | }
|
4823 | };
|
4824 |
|
4825 | return callback
|
4826 | ? request.get(callback)
|
4827 | : request;
|
4828 | }
|
4829 |
|
4830 | function fixCallback(callback) {
|
4831 | return function(error, xhr) {
|
4832 | callback(error == null ? xhr : null);
|
4833 | };
|
4834 | }
|
4835 |
|
4836 | function hasResponse(xhr) {
|
4837 | var type = xhr.responseType;
|
4838 | return type && type !== "text"
|
4839 | ? xhr.response // null on error
|
4840 | : xhr.responseText; // "" on error
|
4841 | }
|
4842 |
|
4843 | function type(defaultMimeType, response) {
|
4844 | return function(url, callback) {
|
4845 | var r = request(url).mimeType(defaultMimeType).response(response);
|
4846 | return callback ? r.get(callback) : r;
|
4847 | };
|
4848 | }
|
4849 |
|
4850 | var html = type("text/html", function(xhr) {
|
4851 | return document.createRange().createContextualFragment(xhr.responseText);
|
4852 | });
|
4853 |
|
4854 | var json = type("application/json", function(xhr) {
|
4855 | return JSON.parse(xhr.responseText);
|
4856 | });
|
4857 |
|
4858 | var text = type("text/plain", function(xhr) {
|
4859 | return xhr.responseText;
|
4860 | });
|
4861 |
|
4862 | var xml = type("application/xml", function(xhr) {
|
4863 | var xml = xhr.responseXML;
|
4864 | if (!xml) throw new Error("parse error");
|
4865 | return xml;
|
4866 | });
|
4867 |
|
4868 | function dsv$1(defaultMimeType, parse) {
|
4869 | return function(url, row, callback) {
|
4870 | if (arguments.length < 3) callback = row, row = null;
|
4871 | var r = request(url).mimeType(defaultMimeType);
|
4872 | r.row = function(_) { return arguments.length ? r.response(responseOf(parse, row = _)) : row; };
|
4873 | r.row(row);
|
4874 | return callback ? r.get(callback) : r;
|
4875 | };
|
4876 | }
|
4877 |
|
4878 | function responseOf(parse, row) {
|
4879 | return function(request) {
|
4880 | return parse(request.responseText, row);
|
4881 | };
|
4882 | }
|
4883 |
|
4884 | var csv$1 = dsv$1("text/csv", csvParse);
|
4885 |
|
4886 | var tsv$1 = dsv$1("text/tab-separated-values", tsvParse);
|
4887 |
|
4888 | var frame = 0;
|
4889 | var timeout = 0;
|
4890 | var interval = 0;
|
4891 | var pokeDelay = 1000;
|
4892 | var taskHead;
|
4893 | var taskTail;
|
4894 | var clockLast = 0;
|
4895 | var clockNow = 0;
|
4896 | var clockSkew = 0;
|
4897 | var clock = typeof performance === "object" ? performance : Date;
|
4898 | var setFrame = typeof requestAnimationFrame === "function"
|
4899 | ? (clock === Date ? function(f) { requestAnimationFrame(function() { f(clock.now()); }); } : requestAnimationFrame)
|
4900 | : function(f) { setTimeout(f, 17); };
|
4901 | function now() {
|
4902 | return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
|
4903 | }
|
4904 |
|
4905 | function clearNow() {
|
4906 | clockNow = 0;
|
4907 | }
|
4908 |
|
4909 | function Timer() {
|
4910 | this._call =
|
4911 | this._time =
|
4912 | this._next = null;
|
4913 | }
|
4914 |
|
4915 | Timer.prototype = timer.prototype = {
|
4916 | constructor: Timer,
|
4917 | restart: function(callback, delay, time) {
|
4918 | if (typeof callback !== "function") throw new TypeError("callback is not a function");
|
4919 | time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
|
4920 | if (!this._next && taskTail !== this) {
|
4921 | if (taskTail) taskTail._next = this;
|
4922 | else taskHead = this;
|
4923 | taskTail = this;
|
4924 | }
|
4925 | this._call = callback;
|
4926 | this._time = time;
|
4927 | sleep();
|
4928 | },
|
4929 | stop: function() {
|
4930 | if (this._call) {
|
4931 | this._call = null;
|
4932 | this._time = Infinity;
|
4933 | sleep();
|
4934 | }
|
4935 | }
|
4936 | };
|
4937 |
|
4938 | function timer(callback, delay, time) {
|
4939 | var t = new Timer;
|
4940 | t.restart(callback, delay, time);
|
4941 | return t;
|
4942 | }
|
4943 |
|
4944 | function timerFlush() {
|
4945 | now(); // Get the current time, if not already set.
|
4946 | ++frame; // Pretend we’ve set an alarm, if we haven’t already.
|
4947 | var t = taskHead, e;
|
4948 | while (t) {
|
4949 | if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
|
4950 | t = t._next;
|
4951 | }
|
4952 | --frame;
|
4953 | }
|
4954 |
|
4955 | function wake(time) {
|
4956 | clockNow = (clockLast = time || clock.now()) + clockSkew;
|
4957 | frame = timeout = 0;
|
4958 | try {
|
4959 | timerFlush();
|
4960 | } finally {
|
4961 | frame = 0;
|
4962 | nap();
|
4963 | clockNow = 0;
|
4964 | }
|
4965 | }
|
4966 |
|
4967 | function poke$1() {
|
4968 | var now = clock.now(), delay = now - clockLast;
|
4969 | if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
|
4970 | }
|
4971 |
|
4972 | function nap() {
|
4973 | var t0, t1 = taskHead, t2, time = Infinity;
|
4974 | while (t1) {
|
4975 | if (t1._call) {
|
4976 | if (time > t1._time) time = t1._time;
|
4977 | t0 = t1, t1 = t1._next;
|
4978 | } else {
|
4979 | t2 = t1._next, t1._next = null;
|
4980 | t1 = t0 ? t0._next = t2 : taskHead = t2;
|
4981 | }
|
4982 | }
|
4983 | taskTail = t0;
|
4984 | sleep(time);
|
4985 | }
|
4986 |
|
4987 | function sleep(time) {
|
4988 | if (frame) return; // Soonest alarm already set, or will be.
|
4989 | if (timeout) timeout = clearTimeout(timeout);
|
4990 | var delay = time - clockNow;
|
4991 | if (delay > 24) {
|
4992 | if (time < Infinity) timeout = setTimeout(wake, delay);
|
4993 | if (interval) interval = clearInterval(interval);
|
4994 | } else {
|
4995 | if (!interval) interval = setInterval(poke$1, pokeDelay);
|
4996 | frame = 1, setFrame(wake);
|
4997 | }
|
4998 | }
|
4999 |
|
5000 | function timeout$1(callback, delay, time) {
|
5001 | var t = new Timer;
|
5002 | delay = delay == null ? 0 : +delay;
|
5003 | t.restart(function(elapsed) {
|
5004 | t.stop();
|
5005 | callback(elapsed + delay);
|
5006 | }, delay, time);
|
5007 | return t;
|
5008 | }
|
5009 |
|
5010 | function interval$1(callback, delay, time) {
|
5011 | var t = new Timer, total = delay;
|
5012 | if (delay == null) return t.restart(callback, delay, time), t;
|
5013 | delay = +delay, time = time == null ? now() : +time;
|
5014 | t.restart(function tick(elapsed) {
|
5015 | elapsed += total;
|
5016 | t.restart(tick, total += delay, time);
|
5017 | callback(elapsed);
|
5018 | }, delay, time);
|
5019 | return t;
|
5020 | }
|
5021 |
|
5022 | var t0$1 = new Date;
|
5023 | var t1$1 = new Date;
|
5024 | function newInterval(floori, offseti, count, field) {
|
5025 |
|
5026 | function interval(date) {
|
5027 | return floori(date = new Date(+date)), date;
|
5028 | }
|
5029 |
|
5030 | interval.floor = interval;
|
5031 |
|
5032 | interval.ceil = function(date) {
|
5033 | return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
|
5034 | };
|
5035 |
|
5036 | interval.round = function(date) {
|
5037 | var d0 = interval(date),
|
5038 | d1 = interval.ceil(date);
|
5039 | return date - d0 < d1 - date ? d0 : d1;
|
5040 | };
|
5041 |
|
5042 | interval.offset = function(date, step) {
|
5043 | return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
|
5044 | };
|
5045 |
|
5046 | interval.range = function(start, stop, step) {
|
5047 | var range = [];
|
5048 | start = interval.ceil(start);
|
5049 | step = step == null ? 1 : Math.floor(step);
|
5050 | if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
|
5051 | do range.push(new Date(+start)); while (offseti(start, step), floori(start), start < stop)
|
5052 | return range;
|
5053 | };
|
5054 |
|
5055 | interval.filter = function(test) {
|
5056 | return newInterval(function(date) {
|
5057 | while (floori(date), !test(date)) date.setTime(date - 1);
|
5058 | }, function(date, step) {
|
5059 | while (--step >= 0) while (offseti(date, 1), !test(date));
|
5060 | });
|
5061 | };
|
5062 |
|
5063 | if (count) {
|
5064 | interval.count = function(start, end) {
|
5065 | t0$1.setTime(+start), t1$1.setTime(+end);
|
5066 | floori(t0$1), floori(t1$1);
|
5067 | return Math.floor(count(t0$1, t1$1));
|
5068 | };
|
5069 |
|
5070 | interval.every = function(step) {
|
5071 | step = Math.floor(step);
|
5072 | return !isFinite(step) || !(step > 0) ? null
|
5073 | : !(step > 1) ? interval
|
5074 | : interval.filter(field
|
5075 | ? function(d) { return field(d) % step === 0; }
|
5076 | : function(d) { return interval.count(0, d) % step === 0; });
|
5077 | };
|
5078 | }
|
5079 |
|
5080 | return interval;
|
5081 | }
|
5082 |
|
5083 | var millisecond = newInterval(function() {
|
5084 | // noop
|
5085 | }, function(date, step) {
|
5086 | date.setTime(+date + step);
|
5087 | }, function(start, end) {
|
5088 | return end - start;
|
5089 | });
|
5090 |
|
5091 | // An optimized implementation for this simple case.
|
5092 | millisecond.every = function(k) {
|
5093 | k = Math.floor(k);
|
5094 | if (!isFinite(k) || !(k > 0)) return null;
|
5095 | if (!(k > 1)) return millisecond;
|
5096 | return newInterval(function(date) {
|
5097 | date.setTime(Math.floor(date / k) * k);
|
5098 | }, function(date, step) {
|
5099 | date.setTime(+date + step * k);
|
5100 | }, function(start, end) {
|
5101 | return (end - start) / k;
|
5102 | });
|
5103 | };
|
5104 |
|
5105 | var milliseconds = millisecond.range;
|
5106 |
|
5107 | var durationSecond = 1e3;
|
5108 | var durationMinute = 6e4;
|
5109 | var durationHour = 36e5;
|
5110 | var durationDay = 864e5;
|
5111 | var durationWeek = 6048e5;
|
5112 |
|
5113 | var second = newInterval(function(date) {
|
5114 | date.setTime(Math.floor(date / durationSecond) * durationSecond);
|
5115 | }, function(date, step) {
|
5116 | date.setTime(+date + step * durationSecond);
|
5117 | }, function(start, end) {
|
5118 | return (end - start) / durationSecond;
|
5119 | }, function(date) {
|
5120 | return date.getUTCSeconds();
|
5121 | });
|
5122 |
|
5123 | var seconds = second.range;
|
5124 |
|
5125 | var minute = newInterval(function(date) {
|
5126 | date.setTime(Math.floor(date / durationMinute) * durationMinute);
|
5127 | }, function(date, step) {
|
5128 | date.setTime(+date + step * durationMinute);
|
5129 | }, function(start, end) {
|
5130 | return (end - start) / durationMinute;
|
5131 | }, function(date) {
|
5132 | return date.getMinutes();
|
5133 | });
|
5134 |
|
5135 | var minutes = minute.range;
|
5136 |
|
5137 | var hour = newInterval(function(date) {
|
5138 | var offset = date.getTimezoneOffset() * durationMinute % durationHour;
|
5139 | if (offset < 0) offset += durationHour;
|
5140 | date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
|
5141 | }, function(date, step) {
|
5142 | date.setTime(+date + step * durationHour);
|
5143 | }, function(start, end) {
|
5144 | return (end - start) / durationHour;
|
5145 | }, function(date) {
|
5146 | return date.getHours();
|
5147 | });
|
5148 |
|
5149 | var hours = hour.range;
|
5150 |
|
5151 | var day = newInterval(function(date) {
|
5152 | date.setHours(0, 0, 0, 0);
|
5153 | }, function(date, step) {
|
5154 | date.setDate(date.getDate() + step);
|
5155 | }, function(start, end) {
|
5156 | return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
|
5157 | }, function(date) {
|
5158 | return date.getDate() - 1;
|
5159 | });
|
5160 |
|
5161 | var days = day.range;
|
5162 |
|
5163 | function weekday(i) {
|
5164 | return newInterval(function(date) {
|
5165 | date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
|
5166 | date.setHours(0, 0, 0, 0);
|
5167 | }, function(date, step) {
|
5168 | date.setDate(date.getDate() + step * 7);
|
5169 | }, function(start, end) {
|
5170 | return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
|
5171 | });
|
5172 | }
|
5173 |
|
5174 | var timeWeek = weekday(0);
|
5175 | var timeMonday = weekday(1);
|
5176 | var tuesday = weekday(2);
|
5177 | var wednesday = weekday(3);
|
5178 | var thursday = weekday(4);
|
5179 | var friday = weekday(5);
|
5180 | var saturday = weekday(6);
|
5181 |
|
5182 | var sundays = timeWeek.range;
|
5183 | var mondays = timeMonday.range;
|
5184 | var tuesdays = tuesday.range;
|
5185 | var wednesdays = wednesday.range;
|
5186 | var thursdays = thursday.range;
|
5187 | var fridays = friday.range;
|
5188 | var saturdays = saturday.range;
|
5189 |
|
5190 | var month = newInterval(function(date) {
|
5191 | date.setDate(1);
|
5192 | date.setHours(0, 0, 0, 0);
|
5193 | }, function(date, step) {
|
5194 | date.setMonth(date.getMonth() + step);
|
5195 | }, function(start, end) {
|
5196 | return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
|
5197 | }, function(date) {
|
5198 | return date.getMonth();
|
5199 | });
|
5200 |
|
5201 | var months = month.range;
|
5202 |
|
5203 | var year = newInterval(function(date) {
|
5204 | date.setMonth(0, 1);
|
5205 | date.setHours(0, 0, 0, 0);
|
5206 | }, function(date, step) {
|
5207 | date.setFullYear(date.getFullYear() + step);
|
5208 | }, function(start, end) {
|
5209 | return end.getFullYear() - start.getFullYear();
|
5210 | }, function(date) {
|
5211 | return date.getFullYear();
|
5212 | });
|
5213 |
|
5214 | // An optimized implementation for this simple case.
|
5215 | year.every = function(k) {
|
5216 | return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
|
5217 | date.setFullYear(Math.floor(date.getFullYear() / k) * k);
|
5218 | date.setMonth(0, 1);
|
5219 | date.setHours(0, 0, 0, 0);
|
5220 | }, function(date, step) {
|
5221 | date.setFullYear(date.getFullYear() + step * k);
|
5222 | });
|
5223 | };
|
5224 |
|
5225 | var years = year.range;
|
5226 |
|
5227 | var utcMinute = newInterval(function(date) {
|
5228 | date.setUTCSeconds(0, 0);
|
5229 | }, function(date, step) {
|
5230 | date.setTime(+date + step * durationMinute);
|
5231 | }, function(start, end) {
|
5232 | return (end - start) / durationMinute;
|
5233 | }, function(date) {
|
5234 | return date.getUTCMinutes();
|
5235 | });
|
5236 |
|
5237 | var utcMinutes = utcMinute.range;
|
5238 |
|
5239 | var utcHour = newInterval(function(date) {
|
5240 | date.setUTCMinutes(0, 0, 0);
|
5241 | }, function(date, step) {
|
5242 | date.setTime(+date + step * durationHour);
|
5243 | }, function(start, end) {
|
5244 | return (end - start) / durationHour;
|
5245 | }, function(date) {
|
5246 | return date.getUTCHours();
|
5247 | });
|
5248 |
|
5249 | var utcHours = utcHour.range;
|
5250 |
|
5251 | var utcDay = newInterval(function(date) {
|
5252 | date.setUTCHours(0, 0, 0, 0);
|
5253 | }, function(date, step) {
|
5254 | date.setUTCDate(date.getUTCDate() + step);
|
5255 | }, function(start, end) {
|
5256 | return (end - start) / durationDay;
|
5257 | }, function(date) {
|
5258 | return date.getUTCDate() - 1;
|
5259 | });
|
5260 |
|
5261 | var utcDays = utcDay.range;
|
5262 |
|
5263 | function utcWeekday(i) {
|
5264 | return newInterval(function(date) {
|
5265 | date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
|
5266 | date.setUTCHours(0, 0, 0, 0);
|
5267 | }, function(date, step) {
|
5268 | date.setUTCDate(date.getUTCDate() + step * 7);
|
5269 | }, function(start, end) {
|
5270 | return (end - start) / durationWeek;
|
5271 | });
|
5272 | }
|
5273 |
|
5274 | var utcWeek = utcWeekday(0);
|
5275 | var utcMonday = utcWeekday(1);
|
5276 | var utcTuesday = utcWeekday(2);
|
5277 | var utcWednesday = utcWeekday(3);
|
5278 | var utcThursday = utcWeekday(4);
|
5279 | var utcFriday = utcWeekday(5);
|
5280 | var utcSaturday = utcWeekday(6);
|
5281 |
|
5282 | var utcSundays = utcWeek.range;
|
5283 | var utcMondays = utcMonday.range;
|
5284 | var utcTuesdays = utcTuesday.range;
|
5285 | var utcWednesdays = utcWednesday.range;
|
5286 | var utcThursdays = utcThursday.range;
|
5287 | var utcFridays = utcFriday.range;
|
5288 | var utcSaturdays = utcSaturday.range;
|
5289 |
|
5290 | var utcMonth = newInterval(function(date) {
|
5291 | date.setUTCDate(1);
|
5292 | date.setUTCHours(0, 0, 0, 0);
|
5293 | }, function(date, step) {
|
5294 | date.setUTCMonth(date.getUTCMonth() + step);
|
5295 | }, function(start, end) {
|
5296 | return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
|
5297 | }, function(date) {
|
5298 | return date.getUTCMonth();
|
5299 | });
|
5300 |
|
5301 | var utcMonths = utcMonth.range;
|
5302 |
|
5303 | var utcYear = newInterval(function(date) {
|
5304 | date.setUTCMonth(0, 1);
|
5305 | date.setUTCHours(0, 0, 0, 0);
|
5306 | }, function(date, step) {
|
5307 | date.setUTCFullYear(date.getUTCFullYear() + step);
|
5308 | }, function(start, end) {
|
5309 | return end.getUTCFullYear() - start.getUTCFullYear();
|
5310 | }, function(date) {
|
5311 | return date.getUTCFullYear();
|
5312 | });
|
5313 |
|
5314 | // An optimized implementation for this simple case.
|
5315 | utcYear.every = function(k) {
|
5316 | return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
|
5317 | date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
|
5318 | date.setUTCMonth(0, 1);
|
5319 | date.setUTCHours(0, 0, 0, 0);
|
5320 | }, function(date, step) {
|
5321 | date.setUTCFullYear(date.getUTCFullYear() + step * k);
|
5322 | });
|
5323 | };
|
5324 |
|
5325 | var utcYears = utcYear.range;
|
5326 |
|
5327 | // Computes the decimal coefficient and exponent of the specified number x with
|
5328 | // significant digits p, where x is positive and p is in [1, 21] or undefined.
|
5329 | // For example, formatDecimal(1.23) returns ["123", 0].
|
5330 | function formatDecimal(x, p) {
|
5331 | if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
|
5332 | var i, coefficient = x.slice(0, i);
|
5333 |
|
5334 | // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
|
5335 | // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
|
5336 | return [
|
5337 | coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
|
5338 | +x.slice(i + 1)
|
5339 | ];
|
5340 | }
|
5341 |
|
5342 | function exponent$1(x) {
|
5343 | return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
|
5344 | }
|
5345 |
|
5346 | function formatGroup(grouping, thousands) {
|
5347 | return function(value, width) {
|
5348 | var i = value.length,
|
5349 | t = [],
|
5350 | j = 0,
|
5351 | g = grouping[0],
|
5352 | length = 0;
|
5353 |
|
5354 | while (i > 0 && g > 0) {
|
5355 | if (length + g + 1 > width) g = Math.max(1, width - length);
|
5356 | t.push(value.substring(i -= g, i + g));
|
5357 | if ((length += g + 1) > width) break;
|
5358 | g = grouping[j = (j + 1) % grouping.length];
|
5359 | }
|
5360 |
|
5361 | return t.reverse().join(thousands);
|
5362 | };
|
5363 | }
|
5364 |
|
5365 | function formatDefault(x, p) {
|
5366 | x = x.toPrecision(p);
|
5367 |
|
5368 | out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
|
5369 | switch (x[i]) {
|
5370 | case ".": i0 = i1 = i; break;
|
5371 | case "0": if (i0 === 0) i0 = i; i1 = i; break;
|
5372 | case "e": break out;
|
5373 | default: if (i0 > 0) i0 = 0; break;
|
5374 | }
|
5375 | }
|
5376 |
|
5377 | return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
|
5378 | }
|
5379 |
|
5380 | var prefixExponent;
|
5381 |
|
5382 | function formatPrefixAuto(x, p) {
|
5383 | var d = formatDecimal(x, p);
|
5384 | if (!d) return x + "";
|
5385 | var coefficient = d[0],
|
5386 | exponent = d[1],
|
5387 | i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
|
5388 | n = coefficient.length;
|
5389 | return i === n ? coefficient
|
5390 | : i > n ? coefficient + new Array(i - n + 1).join("0")
|
5391 | : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
|
5392 | : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
|
5393 | }
|
5394 |
|
5395 | function formatRounded(x, p) {
|
5396 | var d = formatDecimal(x, p);
|
5397 | if (!d) return x + "";
|
5398 | var coefficient = d[0],
|
5399 | exponent = d[1];
|
5400 | return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
|
5401 | : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
|
5402 | : coefficient + new Array(exponent - coefficient.length + 2).join("0");
|
5403 | }
|
5404 |
|
5405 | var formatTypes = {
|
5406 | "": formatDefault,
|
5407 | "%": function(x, p) { return (x * 100).toFixed(p); },
|
5408 | "b": function(x) { return Math.round(x).toString(2); },
|
5409 | "c": function(x) { return x + ""; },
|
5410 | "d": function(x) { return Math.round(x).toString(10); },
|
5411 | "e": function(x, p) { return x.toExponential(p); },
|
5412 | "f": function(x, p) { return x.toFixed(p); },
|
5413 | "g": function(x, p) { return x.toPrecision(p); },
|
5414 | "o": function(x) { return Math.round(x).toString(8); },
|
5415 | "p": function(x, p) { return formatRounded(x * 100, p); },
|
5416 | "r": formatRounded,
|
5417 | "s": formatPrefixAuto,
|
5418 | "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
|
5419 | "x": function(x) { return Math.round(x).toString(16); }
|
5420 | };
|
5421 |
|
5422 | // [[fill]align][sign][symbol][0][width][,][.precision][type]
|
5423 | var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
|
5424 |
|
5425 | function formatSpecifier(specifier) {
|
5426 | return new FormatSpecifier(specifier);
|
5427 | }
|
5428 |
|
5429 | function FormatSpecifier(specifier) {
|
5430 | if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
|
5431 |
|
5432 | var match,
|
5433 | fill = match[1] || " ",
|
5434 | align = match[2] || ">",
|
5435 | sign = match[3] || "-",
|
5436 | symbol = match[4] || "",
|
5437 | zero = !!match[5],
|
5438 | width = match[6] && +match[6],
|
5439 | comma = !!match[7],
|
5440 | precision = match[8] && +match[8].slice(1),
|
5441 | type = match[9] || "";
|
5442 |
|
5443 | // The "n" type is an alias for ",g".
|
5444 | if (type === "n") comma = true, type = "g";
|
5445 |
|
5446 | // Map invalid types to the default format.
|
5447 | else if (!formatTypes[type]) type = "";
|
5448 |
|
5449 | // If zero fill is specified, padding goes after sign and before digits.
|
5450 | if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
|
5451 |
|
5452 | this.fill = fill;
|
5453 | this.align = align;
|
5454 | this.sign = sign;
|
5455 | this.symbol = symbol;
|
5456 | this.zero = zero;
|
5457 | this.width = width;
|
5458 | this.comma = comma;
|
5459 | this.precision = precision;
|
5460 | this.type = type;
|
5461 | }
|
5462 |
|
5463 | FormatSpecifier.prototype.toString = function() {
|
5464 | return this.fill
|
5465 | + this.align
|
5466 | + this.sign
|
5467 | + this.symbol
|
5468 | + (this.zero ? "0" : "")
|
5469 | + (this.width == null ? "" : Math.max(1, this.width | 0))
|
5470 | + (this.comma ? "," : "")
|
5471 | + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
|
5472 | + this.type;
|
5473 | };
|
5474 |
|
5475 | var prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
|
5476 |
|
5477 | function identity$3(x) {
|
5478 | return x;
|
5479 | }
|
5480 |
|
5481 | function formatLocale(locale) {
|
5482 | var group = locale.grouping && locale.thousands ? formatGroup(locale.grouping, locale.thousands) : identity$3,
|
5483 | currency = locale.currency,
|
5484 | decimal = locale.decimal;
|
5485 |
|
5486 | function newFormat(specifier) {
|
5487 | specifier = formatSpecifier(specifier);
|
5488 |
|
5489 | var fill = specifier.fill,
|
5490 | align = specifier.align,
|
5491 | sign = specifier.sign,
|
5492 | symbol = specifier.symbol,
|
5493 | zero = specifier.zero,
|
5494 | width = specifier.width,
|
5495 | comma = specifier.comma,
|
5496 | precision = specifier.precision,
|
5497 | type = specifier.type;
|
5498 |
|
5499 | // Compute the prefix and suffix.
|
5500 | // For SI-prefix, the suffix is lazily computed.
|
5501 | var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
|
5502 | suffix = symbol === "$" ? currency[1] : /[%p]/.test(type) ? "%" : "";
|
5503 |
|
5504 | // What format function should we use?
|
5505 | // Is this an integer type?
|
5506 | // Can this type generate exponential notation?
|
5507 | var formatType = formatTypes[type],
|
5508 | maybeSuffix = !type || /[defgprs%]/.test(type);
|
5509 |
|
5510 | // Set the default precision if not specified,
|
5511 | // or clamp the specified precision to the supported range.
|
5512 | // For significant precision, it must be in [1, 21].
|
5513 | // For fixed precision, it must be in [0, 20].
|
5514 | precision = precision == null ? (type ? 6 : 12)
|
5515 | : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
|
5516 | : Math.max(0, Math.min(20, precision));
|
5517 |
|
5518 | function format(value) {
|
5519 | var valuePrefix = prefix,
|
5520 | valueSuffix = suffix,
|
5521 | i, n, c;
|
5522 |
|
5523 | if (type === "c") {
|
5524 | valueSuffix = formatType(value) + valueSuffix;
|
5525 | value = "";
|
5526 | } else {
|
5527 | value = +value;
|
5528 |
|
5529 | // Convert negative to positive, and compute the prefix.
|
5530 | // Note that -0 is not less than 0, but 1 / -0 is!
|
5531 | var valueNegative = (value < 0 || 1 / value < 0) && (value *= -1, true);
|
5532 |
|
5533 | // Perform the initial formatting.
|
5534 | value = formatType(value, precision);
|
5535 |
|
5536 | // If the original value was negative, it may be rounded to zero during
|
5537 | // formatting; treat this as (positive) zero.
|
5538 | if (valueNegative) {
|
5539 | i = -1, n = value.length;
|
5540 | valueNegative = false;
|
5541 | while (++i < n) {
|
5542 | if (c = value.charCodeAt(i), (48 < c && c < 58)
|
5543 | || (type === "x" && 96 < c && c < 103)
|
5544 | || (type === "X" && 64 < c && c < 71)) {
|
5545 | valueNegative = true;
|
5546 | break;
|
5547 | }
|
5548 | }
|
5549 | }
|
5550 |
|
5551 | // Compute the prefix and suffix.
|
5552 | valuePrefix = (valueNegative ? (sign === "(" ? sign : "-") : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
|
5553 | valueSuffix = valueSuffix + (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + (valueNegative && sign === "(" ? ")" : "");
|
5554 |
|
5555 | // Break the formatted value into the integer “value” part that can be
|
5556 | // grouped, and fractional or exponential “suffix” part that is not.
|
5557 | if (maybeSuffix) {
|
5558 | i = -1, n = value.length;
|
5559 | while (++i < n) {
|
5560 | if (c = value.charCodeAt(i), 48 > c || c > 57) {
|
5561 | valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
|
5562 | value = value.slice(0, i);
|
5563 | break;
|
5564 | }
|
5565 | }
|
5566 | }
|
5567 | }
|
5568 |
|
5569 | // If the fill character is not "0", grouping is applied before padding.
|
5570 | if (comma && !zero) value = group(value, Infinity);
|
5571 |
|
5572 | // Compute the padding.
|
5573 | var length = valuePrefix.length + value.length + valueSuffix.length,
|
5574 | padding = length < width ? new Array(width - length + 1).join(fill) : "";
|
5575 |
|
5576 | // If the fill character is "0", grouping is applied after padding.
|
5577 | if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
|
5578 |
|
5579 | // Reconstruct the final output based on the desired alignment.
|
5580 | switch (align) {
|
5581 | case "<": return valuePrefix + value + valueSuffix + padding;
|
5582 | case "=": return valuePrefix + padding + value + valueSuffix;
|
5583 | case "^": return padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length);
|
5584 | }
|
5585 | return padding + valuePrefix + value + valueSuffix;
|
5586 | }
|
5587 |
|
5588 | format.toString = function() {
|
5589 | return specifier + "";
|
5590 | };
|
5591 |
|
5592 | return format;
|
5593 | }
|
5594 |
|
5595 | function formatPrefix(specifier, value) {
|
5596 | var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
|
5597 | e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
|
5598 | k = Math.pow(10, -e),
|
5599 | prefix = prefixes[8 + e / 3];
|
5600 | return function(value) {
|
5601 | return f(k * value) + prefix;
|
5602 | };
|
5603 | }
|
5604 |
|
5605 | return {
|
5606 | format: newFormat,
|
5607 | formatPrefix: formatPrefix
|
5608 | };
|
5609 | }
|
5610 |
|
5611 | var locale;
|
5612 | exports.format;
|
5613 | exports.formatPrefix;
|
5614 |
|
5615 | defaultLocale({
|
5616 | decimal: ".",
|
5617 | thousands: ",",
|
5618 | grouping: [3],
|
5619 | currency: ["$", ""]
|
5620 | });
|
5621 |
|
5622 | function defaultLocale(definition) {
|
5623 | locale = formatLocale(definition);
|
5624 | exports.format = locale.format;
|
5625 | exports.formatPrefix = locale.formatPrefix;
|
5626 | return locale;
|
5627 | }
|
5628 |
|
5629 | function precisionFixed(step) {
|
5630 | return Math.max(0, -exponent$1(Math.abs(step)));
|
5631 | }
|
5632 |
|
5633 | function precisionPrefix(step, value) {
|
5634 | return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
|
5635 | }
|
5636 |
|
5637 | function precisionRound(step, max) {
|
5638 | step = Math.abs(step), max = Math.abs(max) - step;
|
5639 | return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
|
5640 | }
|
5641 |
|
5642 | function localDate(d) {
|
5643 | if (0 <= d.y && d.y < 100) {
|
5644 | var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
|
5645 | date.setFullYear(d.y);
|
5646 | return date;
|
5647 | }
|
5648 | return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
|
5649 | }
|
5650 |
|
5651 | function utcDate(d) {
|
5652 | if (0 <= d.y && d.y < 100) {
|
5653 | var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
|
5654 | date.setUTCFullYear(d.y);
|
5655 | return date;
|
5656 | }
|
5657 | return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
|
5658 | }
|
5659 |
|
5660 | function newYear(y) {
|
5661 | return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
|
5662 | }
|
5663 |
|
5664 | function formatLocale$1(locale) {
|
5665 | var locale_dateTime = locale.dateTime,
|
5666 | locale_date = locale.date,
|
5667 | locale_time = locale.time,
|
5668 | locale_periods = locale.periods,
|
5669 | locale_weekdays = locale.days,
|
5670 | locale_shortWeekdays = locale.shortDays,
|
5671 | locale_months = locale.months,
|
5672 | locale_shortMonths = locale.shortMonths;
|
5673 |
|
5674 | var periodRe = formatRe(locale_periods),
|
5675 | periodLookup = formatLookup(locale_periods),
|
5676 | weekdayRe = formatRe(locale_weekdays),
|
5677 | weekdayLookup = formatLookup(locale_weekdays),
|
5678 | shortWeekdayRe = formatRe(locale_shortWeekdays),
|
5679 | shortWeekdayLookup = formatLookup(locale_shortWeekdays),
|
5680 | monthRe = formatRe(locale_months),
|
5681 | monthLookup = formatLookup(locale_months),
|
5682 | shortMonthRe = formatRe(locale_shortMonths),
|
5683 | shortMonthLookup = formatLookup(locale_shortMonths);
|
5684 |
|
5685 | var formats = {
|
5686 | "a": formatShortWeekday,
|
5687 | "A": formatWeekday,
|
5688 | "b": formatShortMonth,
|
5689 | "B": formatMonth,
|
5690 | "c": null,
|
5691 | "d": formatDayOfMonth,
|
5692 | "e": formatDayOfMonth,
|
5693 | "H": formatHour24,
|
5694 | "I": formatHour12,
|
5695 | "j": formatDayOfYear,
|
5696 | "L": formatMilliseconds,
|
5697 | "m": formatMonthNumber,
|
5698 | "M": formatMinutes,
|
5699 | "p": formatPeriod,
|
5700 | "S": formatSeconds,
|
5701 | "U": formatWeekNumberSunday,
|
5702 | "w": formatWeekdayNumber,
|
5703 | "W": formatWeekNumberMonday,
|
5704 | "x": null,
|
5705 | "X": null,
|
5706 | "y": formatYear,
|
5707 | "Y": formatFullYear,
|
5708 | "Z": formatZone,
|
5709 | "%": formatLiteralPercent
|
5710 | };
|
5711 |
|
5712 | var utcFormats = {
|
5713 | "a": formatUTCShortWeekday,
|
5714 | "A": formatUTCWeekday,
|
5715 | "b": formatUTCShortMonth,
|
5716 | "B": formatUTCMonth,
|
5717 | "c": null,
|
5718 | "d": formatUTCDayOfMonth,
|
5719 | "e": formatUTCDayOfMonth,
|
5720 | "H": formatUTCHour24,
|
5721 | "I": formatUTCHour12,
|
5722 | "j": formatUTCDayOfYear,
|
5723 | "L": formatUTCMilliseconds,
|
5724 | "m": formatUTCMonthNumber,
|
5725 | "M": formatUTCMinutes,
|
5726 | "p": formatUTCPeriod,
|
5727 | "S": formatUTCSeconds,
|
5728 | "U": formatUTCWeekNumberSunday,
|
5729 | "w": formatUTCWeekdayNumber,
|
5730 | "W": formatUTCWeekNumberMonday,
|
5731 | "x": null,
|
5732 | "X": null,
|
5733 | "y": formatUTCYear,
|
5734 | "Y": formatUTCFullYear,
|
5735 | "Z": formatUTCZone,
|
5736 | "%": formatLiteralPercent
|
5737 | };
|
5738 |
|
5739 | var parses = {
|
5740 | "a": parseShortWeekday,
|
5741 | "A": parseWeekday,
|
5742 | "b": parseShortMonth,
|
5743 | "B": parseMonth,
|
5744 | "c": parseLocaleDateTime,
|
5745 | "d": parseDayOfMonth,
|
5746 | "e": parseDayOfMonth,
|
5747 | "H": parseHour24,
|
5748 | "I": parseHour24,
|
5749 | "j": parseDayOfYear,
|
5750 | "L": parseMilliseconds,
|
5751 | "m": parseMonthNumber,
|
5752 | "M": parseMinutes,
|
5753 | "p": parsePeriod,
|
5754 | "S": parseSeconds,
|
5755 | "U": parseWeekNumberSunday,
|
5756 | "w": parseWeekdayNumber,
|
5757 | "W": parseWeekNumberMonday,
|
5758 | "x": parseLocaleDate,
|
5759 | "X": parseLocaleTime,
|
5760 | "y": parseYear,
|
5761 | "Y": parseFullYear,
|
5762 | "Z": parseZone,
|
5763 | "%": parseLiteralPercent
|
5764 | };
|
5765 |
|
5766 | // These recursive directive definitions must be deferred.
|
5767 | formats.x = newFormat(locale_date, formats);
|
5768 | formats.X = newFormat(locale_time, formats);
|
5769 | formats.c = newFormat(locale_dateTime, formats);
|
5770 | utcFormats.x = newFormat(locale_date, utcFormats);
|
5771 | utcFormats.X = newFormat(locale_time, utcFormats);
|
5772 | utcFormats.c = newFormat(locale_dateTime, utcFormats);
|
5773 |
|
5774 | function newFormat(specifier, formats) {
|
5775 | return function(date) {
|
5776 | var string = [],
|
5777 | i = -1,
|
5778 | j = 0,
|
5779 | n = specifier.length,
|
5780 | c,
|
5781 | pad,
|
5782 | format;
|
5783 |
|
5784 | if (!(date instanceof Date)) date = new Date(+date);
|
5785 |
|
5786 | while (++i < n) {
|
5787 | if (specifier.charCodeAt(i) === 37) {
|
5788 | string.push(specifier.slice(j, i));
|
5789 | if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
|
5790 | else pad = c === "e" ? " " : "0";
|
5791 | if (format = formats[c]) c = format(date, pad);
|
5792 | string.push(c);
|
5793 | j = i + 1;
|
5794 | }
|
5795 | }
|
5796 |
|
5797 | string.push(specifier.slice(j, i));
|
5798 | return string.join("");
|
5799 | };
|
5800 | }
|
5801 |
|
5802 | function newParse(specifier, newDate) {
|
5803 | return function(string) {
|
5804 | var d = newYear(1900),
|
5805 | i = parseSpecifier(d, specifier, string += "", 0);
|
5806 | if (i != string.length) return null;
|
5807 |
|
5808 | // The am-pm flag is 0 for AM, and 1 for PM.
|
5809 | if ("p" in d) d.H = d.H % 12 + d.p * 12;
|
5810 |
|
5811 | // Convert day-of-week and week-of-year to day-of-year.
|
5812 | if ("W" in d || "U" in d) {
|
5813 | if (!("w" in d)) d.w = "W" in d ? 1 : 0;
|
5814 | var day = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
|
5815 | d.m = 0;
|
5816 | d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
|
5817 | }
|
5818 |
|
5819 | // If a time zone is specified, all fields are interpreted as UTC and then
|
5820 | // offset according to the specified time zone.
|
5821 | if ("Z" in d) {
|
5822 | d.H += d.Z / 100 | 0;
|
5823 | d.M += d.Z % 100;
|
5824 | return utcDate(d);
|
5825 | }
|
5826 |
|
5827 | // Otherwise, all fields are in local time.
|
5828 | return newDate(d);
|
5829 | };
|
5830 | }
|
5831 |
|
5832 | function parseSpecifier(d, specifier, string, j) {
|
5833 | var i = 0,
|
5834 | n = specifier.length,
|
5835 | m = string.length,
|
5836 | c,
|
5837 | parse;
|
5838 |
|
5839 | while (i < n) {
|
5840 | if (j >= m) return -1;
|
5841 | c = specifier.charCodeAt(i++);
|
5842 | if (c === 37) {
|
5843 | c = specifier.charAt(i++);
|
5844 | parse = parses[c in pads ? specifier.charAt(i++) : c];
|
5845 | if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
|
5846 | } else if (c != string.charCodeAt(j++)) {
|
5847 | return -1;
|
5848 | }
|
5849 | }
|
5850 |
|
5851 | return j;
|
5852 | }
|
5853 |
|
5854 | function parsePeriod(d, string, i) {
|
5855 | var n = periodRe.exec(string.slice(i));
|
5856 | return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
5857 | }
|
5858 |
|
5859 | function parseShortWeekday(d, string, i) {
|
5860 | var n = shortWeekdayRe.exec(string.slice(i));
|
5861 | return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
5862 | }
|
5863 |
|
5864 | function parseWeekday(d, string, i) {
|
5865 | var n = weekdayRe.exec(string.slice(i));
|
5866 | return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
5867 | }
|
5868 |
|
5869 | function parseShortMonth(d, string, i) {
|
5870 | var n = shortMonthRe.exec(string.slice(i));
|
5871 | return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
5872 | }
|
5873 |
|
5874 | function parseMonth(d, string, i) {
|
5875 | var n = monthRe.exec(string.slice(i));
|
5876 | return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
5877 | }
|
5878 |
|
5879 | function parseLocaleDateTime(d, string, i) {
|
5880 | return parseSpecifier(d, locale_dateTime, string, i);
|
5881 | }
|
5882 |
|
5883 | function parseLocaleDate(d, string, i) {
|
5884 | return parseSpecifier(d, locale_date, string, i);
|
5885 | }
|
5886 |
|
5887 | function parseLocaleTime(d, string, i) {
|
5888 | return parseSpecifier(d, locale_time, string, i);
|
5889 | }
|
5890 |
|
5891 | function formatShortWeekday(d) {
|
5892 | return locale_shortWeekdays[d.getDay()];
|
5893 | }
|
5894 |
|
5895 | function formatWeekday(d) {
|
5896 | return locale_weekdays[d.getDay()];
|
5897 | }
|
5898 |
|
5899 | function formatShortMonth(d) {
|
5900 | return locale_shortMonths[d.getMonth()];
|
5901 | }
|
5902 |
|
5903 | function formatMonth(d) {
|
5904 | return locale_months[d.getMonth()];
|
5905 | }
|
5906 |
|
5907 | function formatPeriod(d) {
|
5908 | return locale_periods[+(d.getHours() >= 12)];
|
5909 | }
|
5910 |
|
5911 | function formatUTCShortWeekday(d) {
|
5912 | return locale_shortWeekdays[d.getUTCDay()];
|
5913 | }
|
5914 |
|
5915 | function formatUTCWeekday(d) {
|
5916 | return locale_weekdays[d.getUTCDay()];
|
5917 | }
|
5918 |
|
5919 | function formatUTCShortMonth(d) {
|
5920 | return locale_shortMonths[d.getUTCMonth()];
|
5921 | }
|
5922 |
|
5923 | function formatUTCMonth(d) {
|
5924 | return locale_months[d.getUTCMonth()];
|
5925 | }
|
5926 |
|
5927 | function formatUTCPeriod(d) {
|
5928 | return locale_periods[+(d.getUTCHours() >= 12)];
|
5929 | }
|
5930 |
|
5931 | return {
|
5932 | format: function(specifier) {
|
5933 | var f = newFormat(specifier += "", formats);
|
5934 | f.toString = function() { return specifier; };
|
5935 | return f;
|
5936 | },
|
5937 | parse: function(specifier) {
|
5938 | var p = newParse(specifier += "", localDate);
|
5939 | p.toString = function() { return specifier; };
|
5940 | return p;
|
5941 | },
|
5942 | utcFormat: function(specifier) {
|
5943 | var f = newFormat(specifier += "", utcFormats);
|
5944 | f.toString = function() { return specifier; };
|
5945 | return f;
|
5946 | },
|
5947 | utcParse: function(specifier) {
|
5948 | var p = newParse(specifier, utcDate);
|
5949 | p.toString = function() { return specifier; };
|
5950 | return p;
|
5951 | }
|
5952 | };
|
5953 | }
|
5954 |
|
5955 | var pads = {"-": "", "_": " ", "0": "0"};
|
5956 | var numberRe = /^\s*\d+/;
|
5957 | var percentRe = /^%/;
|
5958 | var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
|
5959 | function pad(value, fill, width) {
|
5960 | var sign = value < 0 ? "-" : "",
|
5961 | string = (sign ? -value : value) + "",
|
5962 | length = string.length;
|
5963 | return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
|
5964 | }
|
5965 |
|
5966 | function requote(s) {
|
5967 | return s.replace(requoteRe, "\\$&");
|
5968 | }
|
5969 |
|
5970 | function formatRe(names) {
|
5971 | return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
|
5972 | }
|
5973 |
|
5974 | function formatLookup(names) {
|
5975 | var map = {}, i = -1, n = names.length;
|
5976 | while (++i < n) map[names[i].toLowerCase()] = i;
|
5977 | return map;
|
5978 | }
|
5979 |
|
5980 | function parseWeekdayNumber(d, string, i) {
|
5981 | var n = numberRe.exec(string.slice(i, i + 1));
|
5982 | return n ? (d.w = +n[0], i + n[0].length) : -1;
|
5983 | }
|
5984 |
|
5985 | function parseWeekNumberSunday(d, string, i) {
|
5986 | var n = numberRe.exec(string.slice(i));
|
5987 | return n ? (d.U = +n[0], i + n[0].length) : -1;
|
5988 | }
|
5989 |
|
5990 | function parseWeekNumberMonday(d, string, i) {
|
5991 | var n = numberRe.exec(string.slice(i));
|
5992 | return n ? (d.W = +n[0], i + n[0].length) : -1;
|
5993 | }
|
5994 |
|
5995 | function parseFullYear(d, string, i) {
|
5996 | var n = numberRe.exec(string.slice(i, i + 4));
|
5997 | return n ? (d.y = +n[0], i + n[0].length) : -1;
|
5998 | }
|
5999 |
|
6000 | function parseYear(d, string, i) {
|
6001 | var n = numberRe.exec(string.slice(i, i + 2));
|
6002 | return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
|
6003 | }
|
6004 |
|
6005 | function parseZone(d, string, i) {
|
6006 | var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
|
6007 | return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
|
6008 | }
|
6009 |
|
6010 | function parseMonthNumber(d, string, i) {
|
6011 | var n = numberRe.exec(string.slice(i, i + 2));
|
6012 | return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
|
6013 | }
|
6014 |
|
6015 | function parseDayOfMonth(d, string, i) {
|
6016 | var n = numberRe.exec(string.slice(i, i + 2));
|
6017 | return n ? (d.d = +n[0], i + n[0].length) : -1;
|
6018 | }
|
6019 |
|
6020 | function parseDayOfYear(d, string, i) {
|
6021 | var n = numberRe.exec(string.slice(i, i + 3));
|
6022 | return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
|
6023 | }
|
6024 |
|
6025 | function parseHour24(d, string, i) {
|
6026 | var n = numberRe.exec(string.slice(i, i + 2));
|
6027 | return n ? (d.H = +n[0], i + n[0].length) : -1;
|
6028 | }
|
6029 |
|
6030 | function parseMinutes(d, string, i) {
|
6031 | var n = numberRe.exec(string.slice(i, i + 2));
|
6032 | return n ? (d.M = +n[0], i + n[0].length) : -1;
|
6033 | }
|
6034 |
|
6035 | function parseSeconds(d, string, i) {
|
6036 | var n = numberRe.exec(string.slice(i, i + 2));
|
6037 | return n ? (d.S = +n[0], i + n[0].length) : -1;
|
6038 | }
|
6039 |
|
6040 | function parseMilliseconds(d, string, i) {
|
6041 | var n = numberRe.exec(string.slice(i, i + 3));
|
6042 | return n ? (d.L = +n[0], i + n[0].length) : -1;
|
6043 | }
|
6044 |
|
6045 | function parseLiteralPercent(d, string, i) {
|
6046 | var n = percentRe.exec(string.slice(i, i + 1));
|
6047 | return n ? i + n[0].length : -1;
|
6048 | }
|
6049 |
|
6050 | function formatDayOfMonth(d, p) {
|
6051 | return pad(d.getDate(), p, 2);
|
6052 | }
|
6053 |
|
6054 | function formatHour24(d, p) {
|
6055 | return pad(d.getHours(), p, 2);
|
6056 | }
|
6057 |
|
6058 | function formatHour12(d, p) {
|
6059 | return pad(d.getHours() % 12 || 12, p, 2);
|
6060 | }
|
6061 |
|
6062 | function formatDayOfYear(d, p) {
|
6063 | return pad(1 + day.count(year(d), d), p, 3);
|
6064 | }
|
6065 |
|
6066 | function formatMilliseconds(d, p) {
|
6067 | return pad(d.getMilliseconds(), p, 3);
|
6068 | }
|
6069 |
|
6070 | function formatMonthNumber(d, p) {
|
6071 | return pad(d.getMonth() + 1, p, 2);
|
6072 | }
|
6073 |
|
6074 | function formatMinutes(d, p) {
|
6075 | return pad(d.getMinutes(), p, 2);
|
6076 | }
|
6077 |
|
6078 | function formatSeconds(d, p) {
|
6079 | return pad(d.getSeconds(), p, 2);
|
6080 | }
|
6081 |
|
6082 | function formatWeekNumberSunday(d, p) {
|
6083 | return pad(timeWeek.count(year(d), d), p, 2);
|
6084 | }
|
6085 |
|
6086 | function formatWeekdayNumber(d) {
|
6087 | return d.getDay();
|
6088 | }
|
6089 |
|
6090 | function formatWeekNumberMonday(d, p) {
|
6091 | return pad(timeMonday.count(year(d), d), p, 2);
|
6092 | }
|
6093 |
|
6094 | function formatYear(d, p) {
|
6095 | return pad(d.getFullYear() % 100, p, 2);
|
6096 | }
|
6097 |
|
6098 | function formatFullYear(d, p) {
|
6099 | return pad(d.getFullYear() % 10000, p, 4);
|
6100 | }
|
6101 |
|
6102 | function formatZone(d) {
|
6103 | var z = d.getTimezoneOffset();
|
6104 | return (z > 0 ? "-" : (z *= -1, "+"))
|
6105 | + pad(z / 60 | 0, "0", 2)
|
6106 | + pad(z % 60, "0", 2);
|
6107 | }
|
6108 |
|
6109 | function formatUTCDayOfMonth(d, p) {
|
6110 | return pad(d.getUTCDate(), p, 2);
|
6111 | }
|
6112 |
|
6113 | function formatUTCHour24(d, p) {
|
6114 | return pad(d.getUTCHours(), p, 2);
|
6115 | }
|
6116 |
|
6117 | function formatUTCHour12(d, p) {
|
6118 | return pad(d.getUTCHours() % 12 || 12, p, 2);
|
6119 | }
|
6120 |
|
6121 | function formatUTCDayOfYear(d, p) {
|
6122 | return pad(1 + utcDay.count(utcYear(d), d), p, 3);
|
6123 | }
|
6124 |
|
6125 | function formatUTCMilliseconds(d, p) {
|
6126 | return pad(d.getUTCMilliseconds(), p, 3);
|
6127 | }
|
6128 |
|
6129 | function formatUTCMonthNumber(d, p) {
|
6130 | return pad(d.getUTCMonth() + 1, p, 2);
|
6131 | }
|
6132 |
|
6133 | function formatUTCMinutes(d, p) {
|
6134 | return pad(d.getUTCMinutes(), p, 2);
|
6135 | }
|
6136 |
|
6137 | function formatUTCSeconds(d, p) {
|
6138 | return pad(d.getUTCSeconds(), p, 2);
|
6139 | }
|
6140 |
|
6141 | function formatUTCWeekNumberSunday(d, p) {
|
6142 | return pad(utcWeek.count(utcYear(d), d), p, 2);
|
6143 | }
|
6144 |
|
6145 | function formatUTCWeekdayNumber(d) {
|
6146 | return d.getUTCDay();
|
6147 | }
|
6148 |
|
6149 | function formatUTCWeekNumberMonday(d, p) {
|
6150 | return pad(utcMonday.count(utcYear(d), d), p, 2);
|
6151 | }
|
6152 |
|
6153 | function formatUTCYear(d, p) {
|
6154 | return pad(d.getUTCFullYear() % 100, p, 2);
|
6155 | }
|
6156 |
|
6157 | function formatUTCFullYear(d, p) {
|
6158 | return pad(d.getUTCFullYear() % 10000, p, 4);
|
6159 | }
|
6160 |
|
6161 | function formatUTCZone() {
|
6162 | return "+0000";
|
6163 | }
|
6164 |
|
6165 | function formatLiteralPercent() {
|
6166 | return "%";
|
6167 | }
|
6168 |
|
6169 | var locale$1;
|
6170 | exports.timeFormat;
|
6171 | exports.timeParse;
|
6172 | exports.utcFormat;
|
6173 | exports.utcParse;
|
6174 |
|
6175 | defaultLocale$1({
|
6176 | dateTime: "%x, %X",
|
6177 | date: "%-m/%-d/%Y",
|
6178 | time: "%-I:%M:%S %p",
|
6179 | periods: ["AM", "PM"],
|
6180 | days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
6181 | shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
6182 | months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
6183 | shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
6184 | });
|
6185 |
|
6186 | function defaultLocale$1(definition) {
|
6187 | locale$1 = formatLocale$1(definition);
|
6188 | exports.timeFormat = locale$1.format;
|
6189 | exports.timeParse = locale$1.parse;
|
6190 | exports.utcFormat = locale$1.utcFormat;
|
6191 | exports.utcParse = locale$1.utcParse;
|
6192 | return locale$1;
|
6193 | }
|
6194 |
|
6195 | var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
|
6196 |
|
6197 | function formatIsoNative(date) {
|
6198 | return date.toISOString();
|
6199 | }
|
6200 |
|
6201 | var formatIso = Date.prototype.toISOString
|
6202 | ? formatIsoNative
|
6203 | : exports.utcFormat(isoSpecifier);
|
6204 |
|
6205 | function parseIsoNative(string) {
|
6206 | var date = new Date(string);
|
6207 | return isNaN(date) ? null : date;
|
6208 | }
|
6209 |
|
6210 | var parseIso = +new Date("2000-01-01T00:00:00.000Z")
|
6211 | ? parseIsoNative
|
6212 | : exports.utcParse(isoSpecifier);
|
6213 |
|
6214 | var array$2 = Array.prototype;
|
6215 |
|
6216 | var map$2 = array$2.map;
|
6217 | var slice$3 = array$2.slice;
|
6218 |
|
6219 | var implicit = {name: "implicit"};
|
6220 |
|
6221 | function ordinal(range) {
|
6222 | var index = map$1(),
|
6223 | domain = [],
|
6224 | unknown = implicit;
|
6225 |
|
6226 | range = range == null ? [] : slice$3.call(range);
|
6227 |
|
6228 | function scale(d) {
|
6229 | var key = d + "", i = index.get(key);
|
6230 | if (!i) {
|
6231 | if (unknown !== implicit) return unknown;
|
6232 | index.set(key, i = domain.push(d));
|
6233 | }
|
6234 | return range[(i - 1) % range.length];
|
6235 | }
|
6236 |
|
6237 | scale.domain = function(_) {
|
6238 | if (!arguments.length) return domain.slice();
|
6239 | domain = [], index = map$1();
|
6240 | var i = -1, n = _.length, d, key;
|
6241 | while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
|
6242 | return scale;
|
6243 | };
|
6244 |
|
6245 | scale.range = function(_) {
|
6246 | return arguments.length ? (range = slice$3.call(_), scale) : range.slice();
|
6247 | };
|
6248 |
|
6249 | scale.unknown = function(_) {
|
6250 | return arguments.length ? (unknown = _, scale) : unknown;
|
6251 | };
|
6252 |
|
6253 | scale.copy = function() {
|
6254 | return ordinal()
|
6255 | .domain(domain)
|
6256 | .range(range)
|
6257 | .unknown(unknown);
|
6258 | };
|
6259 |
|
6260 | return scale;
|
6261 | }
|
6262 |
|
6263 | function band() {
|
6264 | var scale = ordinal().unknown(undefined),
|
6265 | domain = scale.domain,
|
6266 | ordinalRange = scale.range,
|
6267 | range$$ = [0, 1],
|
6268 | step,
|
6269 | bandwidth,
|
6270 | round = false,
|
6271 | paddingInner = 0,
|
6272 | paddingOuter = 0,
|
6273 | align = 0.5;
|
6274 |
|
6275 | delete scale.unknown;
|
6276 |
|
6277 | function rescale() {
|
6278 | var n = domain().length,
|
6279 | reverse = range$$[1] < range$$[0],
|
6280 | start = range$$[reverse - 0],
|
6281 | stop = range$$[1 - reverse];
|
6282 | step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
|
6283 | if (round) step = Math.floor(step);
|
6284 | start += (stop - start - step * (n - paddingInner)) * align;
|
6285 | bandwidth = step * (1 - paddingInner);
|
6286 | if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
|
6287 | var values = range(n).map(function(i) { return start + step * i; });
|
6288 | return ordinalRange(reverse ? values.reverse() : values);
|
6289 | }
|
6290 |
|
6291 | scale.domain = function(_) {
|
6292 | return arguments.length ? (domain(_), rescale()) : domain();
|
6293 | };
|
6294 |
|
6295 | scale.range = function(_) {
|
6296 | return arguments.length ? (range$$ = [+_[0], +_[1]], rescale()) : range$$.slice();
|
6297 | };
|
6298 |
|
6299 | scale.rangeRound = function(_) {
|
6300 | return range$$ = [+_[0], +_[1]], round = true, rescale();
|
6301 | };
|
6302 |
|
6303 | scale.bandwidth = function() {
|
6304 | return bandwidth;
|
6305 | };
|
6306 |
|
6307 | scale.step = function() {
|
6308 | return step;
|
6309 | };
|
6310 |
|
6311 | scale.round = function(_) {
|
6312 | return arguments.length ? (round = !!_, rescale()) : round;
|
6313 | };
|
6314 |
|
6315 | scale.padding = function(_) {
|
6316 | return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
|
6317 | };
|
6318 |
|
6319 | scale.paddingInner = function(_) {
|
6320 | return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
|
6321 | };
|
6322 |
|
6323 | scale.paddingOuter = function(_) {
|
6324 | return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
|
6325 | };
|
6326 |
|
6327 | scale.align = function(_) {
|
6328 | return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
|
6329 | };
|
6330 |
|
6331 | scale.copy = function() {
|
6332 | return band()
|
6333 | .domain(domain())
|
6334 | .range(range$$)
|
6335 | .round(round)
|
6336 | .paddingInner(paddingInner)
|
6337 | .paddingOuter(paddingOuter)
|
6338 | .align(align);
|
6339 | };
|
6340 |
|
6341 | return rescale();
|
6342 | }
|
6343 |
|
6344 | function pointish(scale) {
|
6345 | var copy = scale.copy;
|
6346 |
|
6347 | scale.padding = scale.paddingOuter;
|
6348 | delete scale.paddingInner;
|
6349 | delete scale.paddingOuter;
|
6350 |
|
6351 | scale.copy = function() {
|
6352 | return pointish(copy());
|
6353 | };
|
6354 |
|
6355 | return scale;
|
6356 | }
|
6357 |
|
6358 | function point$4() {
|
6359 | return pointish(band().paddingInner(1));
|
6360 | }
|
6361 |
|
6362 | function constant$3(x) {
|
6363 | return function() {
|
6364 | return x;
|
6365 | };
|
6366 | }
|
6367 |
|
6368 | function number$1(x) {
|
6369 | return +x;
|
6370 | }
|
6371 |
|
6372 | var unit = [0, 1];
|
6373 |
|
6374 | function deinterpolate(a, b) {
|
6375 | return (b -= (a = +a))
|
6376 | ? function(x) { return (x - a) / b; }
|
6377 | : constant$3(b);
|
6378 | }
|
6379 |
|
6380 | function deinterpolateClamp(deinterpolate) {
|
6381 | return function(a, b) {
|
6382 | var d = deinterpolate(a = +a, b = +b);
|
6383 | return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
|
6384 | };
|
6385 | }
|
6386 |
|
6387 | function reinterpolateClamp(reinterpolate) {
|
6388 | return function(a, b) {
|
6389 | var r = reinterpolate(a = +a, b = +b);
|
6390 | return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
|
6391 | };
|
6392 | }
|
6393 |
|
6394 | function bimap(domain, range, deinterpolate, reinterpolate) {
|
6395 | var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
|
6396 | if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
|
6397 | else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
|
6398 | return function(x) { return r0(d0(x)); };
|
6399 | }
|
6400 |
|
6401 | function polymap(domain, range, deinterpolate, reinterpolate) {
|
6402 | var j = Math.min(domain.length, range.length) - 1,
|
6403 | d = new Array(j),
|
6404 | r = new Array(j),
|
6405 | i = -1;
|
6406 |
|
6407 | // Reverse descending domains.
|
6408 | if (domain[j] < domain[0]) {
|
6409 | domain = domain.slice().reverse();
|
6410 | range = range.slice().reverse();
|
6411 | }
|
6412 |
|
6413 | while (++i < j) {
|
6414 | d[i] = deinterpolate(domain[i], domain[i + 1]);
|
6415 | r[i] = reinterpolate(range[i], range[i + 1]);
|
6416 | }
|
6417 |
|
6418 | return function(x) {
|
6419 | var i = bisectRight(domain, x, 1, j) - 1;
|
6420 | return r[i](d[i](x));
|
6421 | };
|
6422 | }
|
6423 |
|
6424 | function copy(source, target) {
|
6425 | return target
|
6426 | .domain(source.domain())
|
6427 | .range(source.range())
|
6428 | .interpolate(source.interpolate())
|
6429 | .clamp(source.clamp());
|
6430 | }
|
6431 |
|
6432 | // deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
|
6433 | // reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
|
6434 | function continuous(deinterpolate$$, reinterpolate) {
|
6435 | var domain = unit,
|
6436 | range = unit,
|
6437 | interpolate$$ = interpolate,
|
6438 | clamp = false,
|
6439 | piecewise,
|
6440 | output,
|
6441 | input;
|
6442 |
|
6443 | function rescale() {
|
6444 | piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
|
6445 | output = input = null;
|
6446 | return scale;
|
6447 | }
|
6448 |
|
6449 | function scale(x) {
|
6450 | return (output || (output = piecewise(domain, range, clamp ? deinterpolateClamp(deinterpolate$$) : deinterpolate$$, interpolate$$)))(+x);
|
6451 | }
|
6452 |
|
6453 | scale.invert = function(y) {
|
6454 | return (input || (input = piecewise(range, domain, deinterpolate, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
|
6455 | };
|
6456 |
|
6457 | scale.domain = function(_) {
|
6458 | return arguments.length ? (domain = map$2.call(_, number$1), rescale()) : domain.slice();
|
6459 | };
|
6460 |
|
6461 | scale.range = function(_) {
|
6462 | return arguments.length ? (range = slice$3.call(_), rescale()) : range.slice();
|
6463 | };
|
6464 |
|
6465 | scale.rangeRound = function(_) {
|
6466 | return range = slice$3.call(_), interpolate$$ = interpolateRound, rescale();
|
6467 | };
|
6468 |
|
6469 | scale.clamp = function(_) {
|
6470 | return arguments.length ? (clamp = !!_, rescale()) : clamp;
|
6471 | };
|
6472 |
|
6473 | scale.interpolate = function(_) {
|
6474 | return arguments.length ? (interpolate$$ = _, rescale()) : interpolate$$;
|
6475 | };
|
6476 |
|
6477 | return rescale();
|
6478 | }
|
6479 |
|
6480 | function tickFormat(domain, count, specifier) {
|
6481 | var start = domain[0],
|
6482 | stop = domain[domain.length - 1],
|
6483 | step = tickStep(start, stop, count == null ? 10 : count),
|
6484 | precision;
|
6485 | specifier = formatSpecifier(specifier == null ? ",f" : specifier);
|
6486 | switch (specifier.type) {
|
6487 | case "s": {
|
6488 | var value = Math.max(Math.abs(start), Math.abs(stop));
|
6489 | if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
|
6490 | return exports.formatPrefix(specifier, value);
|
6491 | }
|
6492 | case "":
|
6493 | case "e":
|
6494 | case "g":
|
6495 | case "p":
|
6496 | case "r": {
|
6497 | if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
|
6498 | break;
|
6499 | }
|
6500 | case "f":
|
6501 | case "%": {
|
6502 | if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
|
6503 | break;
|
6504 | }
|
6505 | }
|
6506 | return exports.format(specifier);
|
6507 | }
|
6508 |
|
6509 | function linearish(scale) {
|
6510 | var domain = scale.domain;
|
6511 |
|
6512 | scale.ticks = function(count) {
|
6513 | var d = domain();
|
6514 | return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
|
6515 | };
|
6516 |
|
6517 | scale.tickFormat = function(count, specifier) {
|
6518 | return tickFormat(domain(), count, specifier);
|
6519 | };
|
6520 |
|
6521 | scale.nice = function(count) {
|
6522 | var d = domain(),
|
6523 | i = d.length - 1,
|
6524 | n = count == null ? 10 : count,
|
6525 | start = d[0],
|
6526 | stop = d[i],
|
6527 | step = tickStep(start, stop, n);
|
6528 |
|
6529 | if (step) {
|
6530 | step = tickStep(Math.floor(start / step) * step, Math.ceil(stop / step) * step, n);
|
6531 | d[0] = Math.floor(start / step) * step;
|
6532 | d[i] = Math.ceil(stop / step) * step;
|
6533 | domain(d);
|
6534 | }
|
6535 |
|
6536 | return scale;
|
6537 | };
|
6538 |
|
6539 | return scale;
|
6540 | }
|
6541 |
|
6542 | function linear$2() {
|
6543 | var scale = continuous(deinterpolate, interpolateNumber);
|
6544 |
|
6545 | scale.copy = function() {
|
6546 | return copy(scale, linear$2());
|
6547 | };
|
6548 |
|
6549 | return linearish(scale);
|
6550 | }
|
6551 |
|
6552 | function identity$4() {
|
6553 | var domain = [0, 1];
|
6554 |
|
6555 | function scale(x) {
|
6556 | return +x;
|
6557 | }
|
6558 |
|
6559 | scale.invert = scale;
|
6560 |
|
6561 | scale.domain = scale.range = function(_) {
|
6562 | return arguments.length ? (domain = map$2.call(_, number$1), scale) : domain.slice();
|
6563 | };
|
6564 |
|
6565 | scale.copy = function() {
|
6566 | return identity$4().domain(domain);
|
6567 | };
|
6568 |
|
6569 | return linearish(scale);
|
6570 | }
|
6571 |
|
6572 | function nice(domain, interval) {
|
6573 | domain = domain.slice();
|
6574 |
|
6575 | var i0 = 0,
|
6576 | i1 = domain.length - 1,
|
6577 | x0 = domain[i0],
|
6578 | x1 = domain[i1],
|
6579 | t;
|
6580 |
|
6581 | if (x1 < x0) {
|
6582 | t = i0, i0 = i1, i1 = t;
|
6583 | t = x0, x0 = x1, x1 = t;
|
6584 | }
|
6585 |
|
6586 | domain[i0] = interval.floor(x0);
|
6587 | domain[i1] = interval.ceil(x1);
|
6588 | return domain;
|
6589 | }
|
6590 |
|
6591 | function deinterpolate$1(a, b) {
|
6592 | return (b = Math.log(b / a))
|
6593 | ? function(x) { return Math.log(x / a) / b; }
|
6594 | : constant$3(b);
|
6595 | }
|
6596 |
|
6597 | function reinterpolate(a, b) {
|
6598 | return a < 0
|
6599 | ? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
|
6600 | : function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
|
6601 | }
|
6602 |
|
6603 | function pow10(x) {
|
6604 | return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
|
6605 | }
|
6606 |
|
6607 | function powp(base) {
|
6608 | return base === 10 ? pow10
|
6609 | : base === Math.E ? Math.exp
|
6610 | : function(x) { return Math.pow(base, x); };
|
6611 | }
|
6612 |
|
6613 | function logp(base) {
|
6614 | return base === Math.E ? Math.log
|
6615 | : base === 10 && Math.log10
|
6616 | || base === 2 && Math.log2
|
6617 | || (base = Math.log(base), function(x) { return Math.log(x) / base; });
|
6618 | }
|
6619 |
|
6620 | function reflect(f) {
|
6621 | return function(x) {
|
6622 | return -f(-x);
|
6623 | };
|
6624 | }
|
6625 |
|
6626 | function log() {
|
6627 | var scale = continuous(deinterpolate$1, reinterpolate).domain([1, 10]),
|
6628 | domain = scale.domain,
|
6629 | base = 10,
|
6630 | logs = logp(10),
|
6631 | pows = powp(10);
|
6632 |
|
6633 | function rescale() {
|
6634 | logs = logp(base), pows = powp(base);
|
6635 | if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
|
6636 | return scale;
|
6637 | }
|
6638 |
|
6639 | scale.base = function(_) {
|
6640 | return arguments.length ? (base = +_, rescale()) : base;
|
6641 | };
|
6642 |
|
6643 | scale.domain = function(_) {
|
6644 | return arguments.length ? (domain(_), rescale()) : domain();
|
6645 | };
|
6646 |
|
6647 | scale.ticks = function(count) {
|
6648 | var d = domain(),
|
6649 | u = d[0],
|
6650 | v = d[d.length - 1],
|
6651 | r;
|
6652 |
|
6653 | if (r = v < u) i = u, u = v, v = i;
|
6654 |
|
6655 | var i = logs(u),
|
6656 | j = logs(v),
|
6657 | p,
|
6658 | k,
|
6659 | t,
|
6660 | n = count == null ? 10 : +count,
|
6661 | z = [];
|
6662 |
|
6663 | if (!(base % 1) && j - i < n) {
|
6664 | i = Math.round(i) - 1, j = Math.round(j) + 1;
|
6665 | if (u > 0) for (; i < j; ++i) {
|
6666 | for (k = 1, p = pows(i); k < base; ++k) {
|
6667 | t = p * k;
|
6668 | if (t < u) continue;
|
6669 | if (t > v) break;
|
6670 | z.push(t);
|
6671 | }
|
6672 | } else for (; i < j; ++i) {
|
6673 | for (k = base - 1, p = pows(i); k >= 1; --k) {
|
6674 | t = p * k;
|
6675 | if (t < u) continue;
|
6676 | if (t > v) break;
|
6677 | z.push(t);
|
6678 | }
|
6679 | }
|
6680 | } else {
|
6681 | z = ticks(i, j, Math.min(j - i, n)).map(pows);
|
6682 | }
|
6683 |
|
6684 | return r ? z.reverse() : z;
|
6685 | };
|
6686 |
|
6687 | scale.tickFormat = function(count, specifier) {
|
6688 | if (specifier == null) specifier = base === 10 ? ".0e" : ",";
|
6689 | if (typeof specifier !== "function") specifier = exports.format(specifier);
|
6690 | if (count === Infinity) return specifier;
|
6691 | if (count == null) count = 10;
|
6692 | var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
|
6693 | return function(d) {
|
6694 | var i = d / pows(Math.round(logs(d)));
|
6695 | if (i * base < base - 0.5) i *= base;
|
6696 | return i <= k ? specifier(d) : "";
|
6697 | };
|
6698 | };
|
6699 |
|
6700 | scale.nice = function() {
|
6701 | return domain(nice(domain(), {
|
6702 | floor: function(x) { return pows(Math.floor(logs(x))); },
|
6703 | ceil: function(x) { return pows(Math.ceil(logs(x))); }
|
6704 | }));
|
6705 | };
|
6706 |
|
6707 | scale.copy = function() {
|
6708 | return copy(scale, log().base(base));
|
6709 | };
|
6710 |
|
6711 | return scale;
|
6712 | }
|
6713 |
|
6714 | function raise(x, exponent) {
|
6715 | return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
|
6716 | }
|
6717 |
|
6718 | function pow() {
|
6719 | var exponent = 1,
|
6720 | scale = continuous(deinterpolate, reinterpolate),
|
6721 | domain = scale.domain;
|
6722 |
|
6723 | function deinterpolate(a, b) {
|
6724 | return (b = raise(b, exponent) - (a = raise(a, exponent)))
|
6725 | ? function(x) { return (raise(x, exponent) - a) / b; }
|
6726 | : constant$3(b);
|
6727 | }
|
6728 |
|
6729 | function reinterpolate(a, b) {
|
6730 | b = raise(b, exponent) - (a = raise(a, exponent));
|
6731 | return function(t) { return raise(a + b * t, 1 / exponent); };
|
6732 | }
|
6733 |
|
6734 | scale.exponent = function(_) {
|
6735 | return arguments.length ? (exponent = +_, domain(domain())) : exponent;
|
6736 | };
|
6737 |
|
6738 | scale.copy = function() {
|
6739 | return copy(scale, pow().exponent(exponent));
|
6740 | };
|
6741 |
|
6742 | return linearish(scale);
|
6743 | }
|
6744 |
|
6745 | function sqrt() {
|
6746 | return pow().exponent(0.5);
|
6747 | }
|
6748 |
|
6749 | function quantile() {
|
6750 | var domain = [],
|
6751 | range = [],
|
6752 | thresholds = [];
|
6753 |
|
6754 | function rescale() {
|
6755 | var i = 0, n = Math.max(1, range.length);
|
6756 | thresholds = new Array(n - 1);
|
6757 | while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
|
6758 | return scale;
|
6759 | }
|
6760 |
|
6761 | function scale(x) {
|
6762 | if (!isNaN(x = +x)) return range[bisectRight(thresholds, x)];
|
6763 | }
|
6764 |
|
6765 | scale.invertExtent = function(y) {
|
6766 | var i = range.indexOf(y);
|
6767 | return i < 0 ? [NaN, NaN] : [
|
6768 | i > 0 ? thresholds[i - 1] : domain[0],
|
6769 | i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
|
6770 | ];
|
6771 | };
|
6772 |
|
6773 | scale.domain = function(_) {
|
6774 | if (!arguments.length) return domain.slice();
|
6775 | domain = [];
|
6776 | for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
|
6777 | domain.sort(ascending);
|
6778 | return rescale();
|
6779 | };
|
6780 |
|
6781 | scale.range = function(_) {
|
6782 | return arguments.length ? (range = slice$3.call(_), rescale()) : range.slice();
|
6783 | };
|
6784 |
|
6785 | scale.quantiles = function() {
|
6786 | return thresholds.slice();
|
6787 | };
|
6788 |
|
6789 | scale.copy = function() {
|
6790 | return quantile()
|
6791 | .domain(domain)
|
6792 | .range(range);
|
6793 | };
|
6794 |
|
6795 | return scale;
|
6796 | }
|
6797 |
|
6798 | function quantize$1() {
|
6799 | var x0 = 0,
|
6800 | x1 = 1,
|
6801 | n = 1,
|
6802 | domain = [0.5],
|
6803 | range = [0, 1];
|
6804 |
|
6805 | function scale(x) {
|
6806 | if (x <= x) return range[bisectRight(domain, x, 0, n)];
|
6807 | }
|
6808 |
|
6809 | function rescale() {
|
6810 | var i = -1;
|
6811 | domain = new Array(n);
|
6812 | while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
|
6813 | return scale;
|
6814 | }
|
6815 |
|
6816 | scale.domain = function(_) {
|
6817 | return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
|
6818 | };
|
6819 |
|
6820 | scale.range = function(_) {
|
6821 | return arguments.length ? (n = (range = slice$3.call(_)).length - 1, rescale()) : range.slice();
|
6822 | };
|
6823 |
|
6824 | scale.invertExtent = function(y) {
|
6825 | var i = range.indexOf(y);
|
6826 | return i < 0 ? [NaN, NaN]
|
6827 | : i < 1 ? [x0, domain[0]]
|
6828 | : i >= n ? [domain[n - 1], x1]
|
6829 | : [domain[i - 1], domain[i]];
|
6830 | };
|
6831 |
|
6832 | scale.copy = function() {
|
6833 | return quantize$1()
|
6834 | .domain([x0, x1])
|
6835 | .range(range);
|
6836 | };
|
6837 |
|
6838 | return linearish(scale);
|
6839 | }
|
6840 |
|
6841 | function threshold$1() {
|
6842 | var domain = [0.5],
|
6843 | range = [0, 1],
|
6844 | n = 1;
|
6845 |
|
6846 | function scale(x) {
|
6847 | if (x <= x) return range[bisectRight(domain, x, 0, n)];
|
6848 | }
|
6849 |
|
6850 | scale.domain = function(_) {
|
6851 | return arguments.length ? (domain = slice$3.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
|
6852 | };
|
6853 |
|
6854 | scale.range = function(_) {
|
6855 | return arguments.length ? (range = slice$3.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
|
6856 | };
|
6857 |
|
6858 | scale.invertExtent = function(y) {
|
6859 | var i = range.indexOf(y);
|
6860 | return [domain[i - 1], domain[i]];
|
6861 | };
|
6862 |
|
6863 | scale.copy = function() {
|
6864 | return threshold$1()
|
6865 | .domain(domain)
|
6866 | .range(range);
|
6867 | };
|
6868 |
|
6869 | return scale;
|
6870 | }
|
6871 |
|
6872 | var durationSecond$1 = 1000;
|
6873 | var durationMinute$1 = durationSecond$1 * 60;
|
6874 | var durationHour$1 = durationMinute$1 * 60;
|
6875 | var durationDay$1 = durationHour$1 * 24;
|
6876 | var durationWeek$1 = durationDay$1 * 7;
|
6877 | var durationMonth = durationDay$1 * 30;
|
6878 | var durationYear = durationDay$1 * 365;
|
6879 | function date(t) {
|
6880 | return new Date(t);
|
6881 | }
|
6882 |
|
6883 | function number$2(t) {
|
6884 | return t instanceof Date ? +t : +new Date(+t);
|
6885 | }
|
6886 |
|
6887 | function calendar(year, month, week, day, hour, minute, second, millisecond, format) {
|
6888 | var scale = continuous(deinterpolate, interpolateNumber),
|
6889 | invert = scale.invert,
|
6890 | domain = scale.domain;
|
6891 |
|
6892 | var formatMillisecond = format(".%L"),
|
6893 | formatSecond = format(":%S"),
|
6894 | formatMinute = format("%I:%M"),
|
6895 | formatHour = format("%I %p"),
|
6896 | formatDay = format("%a %d"),
|
6897 | formatWeek = format("%b %d"),
|
6898 | formatMonth = format("%B"),
|
6899 | formatYear = format("%Y");
|
6900 |
|
6901 | var tickIntervals = [
|
6902 | [second, 1, durationSecond$1],
|
6903 | [second, 5, 5 * durationSecond$1],
|
6904 | [second, 15, 15 * durationSecond$1],
|
6905 | [second, 30, 30 * durationSecond$1],
|
6906 | [minute, 1, durationMinute$1],
|
6907 | [minute, 5, 5 * durationMinute$1],
|
6908 | [minute, 15, 15 * durationMinute$1],
|
6909 | [minute, 30, 30 * durationMinute$1],
|
6910 | [ hour, 1, durationHour$1 ],
|
6911 | [ hour, 3, 3 * durationHour$1 ],
|
6912 | [ hour, 6, 6 * durationHour$1 ],
|
6913 | [ hour, 12, 12 * durationHour$1 ],
|
6914 | [ day, 1, durationDay$1 ],
|
6915 | [ day, 2, 2 * durationDay$1 ],
|
6916 | [ week, 1, durationWeek$1 ],
|
6917 | [ month, 1, durationMonth ],
|
6918 | [ month, 3, 3 * durationMonth ],
|
6919 | [ year, 1, durationYear ]
|
6920 | ];
|
6921 |
|
6922 | function tickFormat(date) {
|
6923 | return (second(date) < date ? formatMillisecond
|
6924 | : minute(date) < date ? formatSecond
|
6925 | : hour(date) < date ? formatMinute
|
6926 | : day(date) < date ? formatHour
|
6927 | : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
|
6928 | : year(date) < date ? formatMonth
|
6929 | : formatYear)(date);
|
6930 | }
|
6931 |
|
6932 | function tickInterval(interval, start, stop, step) {
|
6933 | if (interval == null) interval = 10;
|
6934 |
|
6935 | // If a desired tick count is specified, pick a reasonable tick interval
|
6936 | // based on the extent of the domain and a rough estimate of tick size.
|
6937 | // Otherwise, assume interval is already a time interval and use it.
|
6938 | if (typeof interval === "number") {
|
6939 | var target = Math.abs(stop - start) / interval,
|
6940 | i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
|
6941 | if (i === tickIntervals.length) {
|
6942 | step = tickStep(start / durationYear, stop / durationYear, interval);
|
6943 | interval = year;
|
6944 | } else if (i) {
|
6945 | i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
|
6946 | step = i[1];
|
6947 | interval = i[0];
|
6948 | } else {
|
6949 | step = tickStep(start, stop, interval);
|
6950 | interval = millisecond;
|
6951 | }
|
6952 | }
|
6953 |
|
6954 | return step == null ? interval : interval.every(step);
|
6955 | }
|
6956 |
|
6957 | scale.invert = function(y) {
|
6958 | return new Date(invert(y));
|
6959 | };
|
6960 |
|
6961 | scale.domain = function(_) {
|
6962 | return arguments.length ? domain(map$2.call(_, number$2)) : domain().map(date);
|
6963 | };
|
6964 |
|
6965 | scale.ticks = function(interval, step) {
|
6966 | var d = domain(),
|
6967 | t0 = d[0],
|
6968 | t1 = d[d.length - 1],
|
6969 | r = t1 < t0,
|
6970 | t;
|
6971 | if (r) t = t0, t0 = t1, t1 = t;
|
6972 | t = tickInterval(interval, t0, t1, step);
|
6973 | t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
|
6974 | return r ? t.reverse() : t;
|
6975 | };
|
6976 |
|
6977 | scale.tickFormat = function(count, specifier) {
|
6978 | return specifier == null ? tickFormat : format(specifier);
|
6979 | };
|
6980 |
|
6981 | scale.nice = function(interval, step) {
|
6982 | var d = domain();
|
6983 | return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
|
6984 | ? domain(nice(d, interval))
|
6985 | : scale;
|
6986 | };
|
6987 |
|
6988 | scale.copy = function() {
|
6989 | return copy(scale, calendar(year, month, week, day, hour, minute, second, millisecond, format));
|
6990 | };
|
6991 |
|
6992 | return scale;
|
6993 | }
|
6994 |
|
6995 | function time() {
|
6996 | return calendar(year, month, timeWeek, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]);
|
6997 | }
|
6998 |
|
6999 | function utcTime() {
|
7000 | return calendar(utcYear, utcMonth, utcWeek, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]);
|
7001 | }
|
7002 |
|
7003 | function colors(s) {
|
7004 | return s.match(/.{6}/g).map(function(x) {
|
7005 | return "#" + x;
|
7006 | });
|
7007 | }
|
7008 |
|
7009 | var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
|
7010 |
|
7011 | var category20b = colors("393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6");
|
7012 |
|
7013 | var category20c = colors("3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9");
|
7014 |
|
7015 | var category20 = colors("1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5");
|
7016 |
|
7017 | var cubehelix$3 = interpolateCubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
|
7018 |
|
7019 | var warm = interpolateCubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
|
7020 |
|
7021 | var cool = interpolateCubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
|
7022 |
|
7023 | var rainbow = cubehelix();
|
7024 |
|
7025 | function rainbow$1(t) {
|
7026 | if (t < 0 || t > 1) t -= Math.floor(t);
|
7027 | var ts = Math.abs(t - 0.5);
|
7028 | rainbow.h = 360 * t - 100;
|
7029 | rainbow.s = 1.5 - 1.5 * ts;
|
7030 | rainbow.l = 0.8 - 0.9 * ts;
|
7031 | return rainbow + "";
|
7032 | }
|
7033 |
|
7034 | function ramp(range) {
|
7035 | var n = range.length;
|
7036 | return function(t) {
|
7037 | return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
7038 | };
|
7039 | }
|
7040 |
|
7041 | var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
|
7042 |
|
7043 | var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
|
7044 |
|
7045 | var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
|
7046 |
|
7047 | var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
|
7048 |
|
7049 | function sequential(interpolator) {
|
7050 | var x0 = 0,
|
7051 | x1 = 1,
|
7052 | clamp = false;
|
7053 |
|
7054 | function scale(x) {
|
7055 | var t = (x - x0) / (x1 - x0);
|
7056 | return interpolator(clamp ? Math.max(0, Math.min(1, t)) : t);
|
7057 | }
|
7058 |
|
7059 | scale.domain = function(_) {
|
7060 | return arguments.length ? (x0 = +_[0], x1 = +_[1], scale) : [x0, x1];
|
7061 | };
|
7062 |
|
7063 | scale.clamp = function(_) {
|
7064 | return arguments.length ? (clamp = !!_, scale) : clamp;
|
7065 | };
|
7066 |
|
7067 | scale.interpolator = function(_) {
|
7068 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
7069 | };
|
7070 |
|
7071 | scale.copy = function() {
|
7072 | return sequential(interpolator).domain([x0, x1]).clamp(clamp);
|
7073 | };
|
7074 |
|
7075 | return linearish(scale);
|
7076 | }
|
7077 |
|
7078 | var xhtml = "http://www.w3.org/1999/xhtml";
|
7079 |
|
7080 | var namespaces = {
|
7081 | svg: "http://www.w3.org/2000/svg",
|
7082 | xhtml: xhtml,
|
7083 | xlink: "http://www.w3.org/1999/xlink",
|
7084 | xml: "http://www.w3.org/XML/1998/namespace",
|
7085 | xmlns: "http://www.w3.org/2000/xmlns/"
|
7086 | };
|
7087 |
|
7088 | function namespace(name) {
|
7089 | var prefix = name += "", i = prefix.indexOf(":");
|
7090 | if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
|
7091 | return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
|
7092 | }
|
7093 |
|
7094 | function creatorInherit(name) {
|
7095 | return function() {
|
7096 | var document = this.ownerDocument,
|
7097 | uri = this.namespaceURI;
|
7098 | return uri === xhtml && document.documentElement.namespaceURI === xhtml
|
7099 | ? document.createElement(name)
|
7100 | : document.createElementNS(uri, name);
|
7101 | };
|
7102 | }
|
7103 |
|
7104 | function creatorFixed(fullname) {
|
7105 | return function() {
|
7106 | return this.ownerDocument.createElementNS(fullname.space, fullname.local);
|
7107 | };
|
7108 | }
|
7109 |
|
7110 | function creator(name) {
|
7111 | var fullname = namespace(name);
|
7112 | return (fullname.local
|
7113 | ? creatorFixed
|
7114 | : creatorInherit)(fullname);
|
7115 | }
|
7116 |
|
7117 | var nextId = 0;
|
7118 |
|
7119 | function local() {
|
7120 | return new Local;
|
7121 | }
|
7122 |
|
7123 | function Local() {
|
7124 | this._ = "@" + (++nextId).toString(36);
|
7125 | }
|
7126 |
|
7127 | Local.prototype = local.prototype = {
|
7128 | constructor: Local,
|
7129 | get: function(node) {
|
7130 | var id = this._;
|
7131 | while (!(id in node)) if (!(node = node.parentNode)) return;
|
7132 | return node[id];
|
7133 | },
|
7134 | set: function(node, value) {
|
7135 | return node[this._] = value;
|
7136 | },
|
7137 | remove: function(node) {
|
7138 | return this._ in node && delete node[this._];
|
7139 | },
|
7140 | toString: function() {
|
7141 | return this._;
|
7142 | }
|
7143 | };
|
7144 |
|
7145 | var matcher = function(selector) {
|
7146 | return function() {
|
7147 | return this.matches(selector);
|
7148 | };
|
7149 | };
|
7150 |
|
7151 | if (typeof document !== "undefined") {
|
7152 | var element = document.documentElement;
|
7153 | if (!element.matches) {
|
7154 | var vendorMatches = element.webkitMatchesSelector
|
7155 | || element.msMatchesSelector
|
7156 | || element.mozMatchesSelector
|
7157 | || element.oMatchesSelector;
|
7158 | matcher = function(selector) {
|
7159 | return function() {
|
7160 | return vendorMatches.call(this, selector);
|
7161 | };
|
7162 | };
|
7163 | }
|
7164 | }
|
7165 |
|
7166 | var matcher$1 = matcher;
|
7167 |
|
7168 | var filterEvents = {};
|
7169 |
|
7170 | exports.event = null;
|
7171 |
|
7172 | if (typeof document !== "undefined") {
|
7173 | var element$1 = document.documentElement;
|
7174 | if (!("onmouseenter" in element$1)) {
|
7175 | filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
|
7176 | }
|
7177 | }
|
7178 |
|
7179 | function filterContextListener(listener, index, group) {
|
7180 | listener = contextListener(listener, index, group);
|
7181 | return function(event) {
|
7182 | var related = event.relatedTarget;
|
7183 | if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
|
7184 | listener.call(this, event);
|
7185 | }
|
7186 | };
|
7187 | }
|
7188 |
|
7189 | function contextListener(listener, index, group) {
|
7190 | return function(event1) {
|
7191 | var event0 = exports.event; // Events can be reentrant (e.g., focus).
|
7192 | exports.event = event1;
|
7193 | try {
|
7194 | listener.call(this, this.__data__, index, group);
|
7195 | } finally {
|
7196 | exports.event = event0;
|
7197 | }
|
7198 | };
|
7199 | }
|
7200 |
|
7201 | function parseTypenames$1(typenames) {
|
7202 | return typenames.trim().split(/^|\s+/).map(function(t) {
|
7203 | var name = "", i = t.indexOf(".");
|
7204 | if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
7205 | return {type: t, name: name};
|
7206 | });
|
7207 | }
|
7208 |
|
7209 | function onRemove(typename) {
|
7210 | return function() {
|
7211 | var on = this.__on;
|
7212 | if (!on) return;
|
7213 | for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
|
7214 | if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
|
7215 | this.removeEventListener(o.type, o.listener, o.capture);
|
7216 | } else {
|
7217 | on[++i] = o;
|
7218 | }
|
7219 | }
|
7220 | if (++i) on.length = i;
|
7221 | else delete this.__on;
|
7222 | };
|
7223 | }
|
7224 |
|
7225 | function onAdd(typename, value, capture) {
|
7226 | var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
|
7227 | return function(d, i, group) {
|
7228 | var on = this.__on, o, listener = wrap(value, i, group);
|
7229 | if (on) for (var j = 0, m = on.length; j < m; ++j) {
|
7230 | if ((o = on[j]).type === typename.type && o.name === typename.name) {
|
7231 | this.removeEventListener(o.type, o.listener, o.capture);
|
7232 | this.addEventListener(o.type, o.listener = listener, o.capture = capture);
|
7233 | o.value = value;
|
7234 | return;
|
7235 | }
|
7236 | }
|
7237 | this.addEventListener(typename.type, listener, capture);
|
7238 | o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
|
7239 | if (!on) this.__on = [o];
|
7240 | else on.push(o);
|
7241 | };
|
7242 | }
|
7243 |
|
7244 | function selection_on(typename, value, capture) {
|
7245 | var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
|
7246 |
|
7247 | if (arguments.length < 2) {
|
7248 | var on = this.node().__on;
|
7249 | if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
|
7250 | for (i = 0, o = on[j]; i < n; ++i) {
|
7251 | if ((t = typenames[i]).type === o.type && t.name === o.name) {
|
7252 | return o.value;
|
7253 | }
|
7254 | }
|
7255 | }
|
7256 | return;
|
7257 | }
|
7258 |
|
7259 | on = value ? onAdd : onRemove;
|
7260 | if (capture == null) capture = false;
|
7261 | for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
|
7262 | return this;
|
7263 | }
|
7264 |
|
7265 | function customEvent(event1, listener, that, args) {
|
7266 | var event0 = exports.event;
|
7267 | event1.sourceEvent = exports.event;
|
7268 | exports.event = event1;
|
7269 | try {
|
7270 | return listener.apply(that, args);
|
7271 | } finally {
|
7272 | exports.event = event0;
|
7273 | }
|
7274 | }
|
7275 |
|
7276 | function sourceEvent() {
|
7277 | var current = exports.event, source;
|
7278 | while (source = current.sourceEvent) current = source;
|
7279 | return current;
|
7280 | }
|
7281 |
|
7282 | function point$5(node, event) {
|
7283 | var svg = node.ownerSVGElement || node;
|
7284 |
|
7285 | if (svg.createSVGPoint) {
|
7286 | var point = svg.createSVGPoint();
|
7287 | point.x = event.clientX, point.y = event.clientY;
|
7288 | point = point.matrixTransform(node.getScreenCTM().inverse());
|
7289 | return [point.x, point.y];
|
7290 | }
|
7291 |
|
7292 | var rect = node.getBoundingClientRect();
|
7293 | return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
|
7294 | }
|
7295 |
|
7296 | function mouse(node) {
|
7297 | var event = sourceEvent();
|
7298 | if (event.changedTouches) event = event.changedTouches[0];
|
7299 | return point$5(node, event);
|
7300 | }
|
7301 |
|
7302 | function none$2() {}
|
7303 |
|
7304 | function selector(selector) {
|
7305 | return selector == null ? none$2 : function() {
|
7306 | return this.querySelector(selector);
|
7307 | };
|
7308 | }
|
7309 |
|
7310 | function selection_select(select) {
|
7311 | if (typeof select !== "function") select = selector(select);
|
7312 |
|
7313 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
7314 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
|
7315 | if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
7316 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
7317 | subgroup[i] = subnode;
|
7318 | }
|
7319 | }
|
7320 | }
|
7321 |
|
7322 | return new Selection(subgroups, this._parents);
|
7323 | }
|
7324 |
|
7325 | function empty() {
|
7326 | return [];
|
7327 | }
|
7328 |
|
7329 | function selectorAll(selector) {
|
7330 | return selector == null ? empty : function() {
|
7331 | return this.querySelectorAll(selector);
|
7332 | };
|
7333 | }
|
7334 |
|
7335 | function selection_selectAll(select) {
|
7336 | if (typeof select !== "function") select = selectorAll(select);
|
7337 |
|
7338 | for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
|
7339 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
7340 | if (node = group[i]) {
|
7341 | subgroups.push(select.call(node, node.__data__, i, group));
|
7342 | parents.push(node);
|
7343 | }
|
7344 | }
|
7345 | }
|
7346 |
|
7347 | return new Selection(subgroups, parents);
|
7348 | }
|
7349 |
|
7350 | function selection_filter(match) {
|
7351 | if (typeof match !== "function") match = matcher$1(match);
|
7352 |
|
7353 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
7354 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
|
7355 | if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
7356 | subgroup.push(node);
|
7357 | }
|
7358 | }
|
7359 | }
|
7360 |
|
7361 | return new Selection(subgroups, this._parents);
|
7362 | }
|
7363 |
|
7364 | function sparse(update) {
|
7365 | return new Array(update.length);
|
7366 | }
|
7367 |
|
7368 | function selection_enter() {
|
7369 | return new Selection(this._enter || this._groups.map(sparse), this._parents);
|
7370 | }
|
7371 |
|
7372 | function EnterNode(parent, datum) {
|
7373 | this.ownerDocument = parent.ownerDocument;
|
7374 | this.namespaceURI = parent.namespaceURI;
|
7375 | this._next = null;
|
7376 | this._parent = parent;
|
7377 | this.__data__ = datum;
|
7378 | }
|
7379 |
|
7380 | EnterNode.prototype = {
|
7381 | constructor: EnterNode,
|
7382 | appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
|
7383 | insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
|
7384 | querySelector: function(selector) { return this._parent.querySelector(selector); },
|
7385 | querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
|
7386 | };
|
7387 |
|
7388 | function constant$4(x) {
|
7389 | return function() {
|
7390 | return x;
|
7391 | };
|
7392 | }
|
7393 |
|
7394 | var keyPrefix = "$"; // Protect against keys like “__proto__”.
|
7395 |
|
7396 | function bindIndex(parent, group, enter, update, exit, data) {
|
7397 | var i = 0,
|
7398 | node,
|
7399 | groupLength = group.length,
|
7400 | dataLength = data.length;
|
7401 |
|
7402 | // Put any non-null nodes that fit into update.
|
7403 | // Put any null nodes into enter.
|
7404 | // Put any remaining data into enter.
|
7405 | for (; i < dataLength; ++i) {
|
7406 | if (node = group[i]) {
|
7407 | node.__data__ = data[i];
|
7408 | update[i] = node;
|
7409 | } else {
|
7410 | enter[i] = new EnterNode(parent, data[i]);
|
7411 | }
|
7412 | }
|
7413 |
|
7414 | // Put any non-null nodes that don’t fit into exit.
|
7415 | for (; i < groupLength; ++i) {
|
7416 | if (node = group[i]) {
|
7417 | exit[i] = node;
|
7418 | }
|
7419 | }
|
7420 | }
|
7421 |
|
7422 | function bindKey(parent, group, enter, update, exit, data, key) {
|
7423 | var i,
|
7424 | node,
|
7425 | nodeByKeyValue = {},
|
7426 | groupLength = group.length,
|
7427 | dataLength = data.length,
|
7428 | keyValues = new Array(groupLength),
|
7429 | keyValue;
|
7430 |
|
7431 | // Compute the key for each node.
|
7432 | // If multiple nodes have the same key, the duplicates are added to exit.
|
7433 | for (i = 0; i < groupLength; ++i) {
|
7434 | if (node = group[i]) {
|
7435 | keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
|
7436 | if (keyValue in nodeByKeyValue) {
|
7437 | exit[i] = node;
|
7438 | } else {
|
7439 | nodeByKeyValue[keyValue] = node;
|
7440 | }
|
7441 | }
|
7442 | }
|
7443 |
|
7444 | // Compute the key for each datum.
|
7445 | // If there a node associated with this key, join and add it to update.
|
7446 | // If there is not (or the key is a duplicate), add it to enter.
|
7447 | for (i = 0; i < dataLength; ++i) {
|
7448 | keyValue = keyPrefix + key.call(parent, data[i], i, data);
|
7449 | if (node = nodeByKeyValue[keyValue]) {
|
7450 | update[i] = node;
|
7451 | node.__data__ = data[i];
|
7452 | nodeByKeyValue[keyValue] = null;
|
7453 | } else {
|
7454 | enter[i] = new EnterNode(parent, data[i]);
|
7455 | }
|
7456 | }
|
7457 |
|
7458 | // Add any remaining nodes that were not bound to data to exit.
|
7459 | for (i = 0; i < groupLength; ++i) {
|
7460 | if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
|
7461 | exit[i] = node;
|
7462 | }
|
7463 | }
|
7464 | }
|
7465 |
|
7466 | function selection_data(value, key) {
|
7467 | if (!value) {
|
7468 | data = new Array(this.size()), j = -1;
|
7469 | this.each(function(d) { data[++j] = d; });
|
7470 | return data;
|
7471 | }
|
7472 |
|
7473 | var bind = key ? bindKey : bindIndex,
|
7474 | parents = this._parents,
|
7475 | groups = this._groups;
|
7476 |
|
7477 | if (typeof value !== "function") value = constant$4(value);
|
7478 |
|
7479 | for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
|
7480 | var parent = parents[j],
|
7481 | group = groups[j],
|
7482 | groupLength = group.length,
|
7483 | data = value.call(parent, parent && parent.__data__, j, parents),
|
7484 | dataLength = data.length,
|
7485 | enterGroup = enter[j] = new Array(dataLength),
|
7486 | updateGroup = update[j] = new Array(dataLength),
|
7487 | exitGroup = exit[j] = new Array(groupLength);
|
7488 |
|
7489 | bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
|
7490 |
|
7491 | // Now connect the enter nodes to their following update node, such that
|
7492 | // appendChild can insert the materialized enter node before this node,
|
7493 | // rather than at the end of the parent node.
|
7494 | for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
|
7495 | if (previous = enterGroup[i0]) {
|
7496 | if (i0 >= i1) i1 = i0 + 1;
|
7497 | while (!(next = updateGroup[i1]) && ++i1 < dataLength);
|
7498 | previous._next = next || null;
|
7499 | }
|
7500 | }
|
7501 | }
|
7502 |
|
7503 | update = new Selection(update, parents);
|
7504 | update._enter = enter;
|
7505 | update._exit = exit;
|
7506 | return update;
|
7507 | }
|
7508 |
|
7509 | function selection_exit() {
|
7510 | return new Selection(this._exit || this._groups.map(sparse), this._parents);
|
7511 | }
|
7512 |
|
7513 | function selection_merge(selection) {
|
7514 |
|
7515 | 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) {
|
7516 | for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
|
7517 | if (node = group0[i] || group1[i]) {
|
7518 | merge[i] = node;
|
7519 | }
|
7520 | }
|
7521 | }
|
7522 |
|
7523 | for (; j < m0; ++j) {
|
7524 | merges[j] = groups0[j];
|
7525 | }
|
7526 |
|
7527 | return new Selection(merges, this._parents);
|
7528 | }
|
7529 |
|
7530 | function selection_order() {
|
7531 |
|
7532 | for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
|
7533 | for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
|
7534 | if (node = group[i]) {
|
7535 | if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
|
7536 | next = node;
|
7537 | }
|
7538 | }
|
7539 | }
|
7540 |
|
7541 | return this;
|
7542 | }
|
7543 |
|
7544 | function selection_sort(compare) {
|
7545 | if (!compare) compare = ascending$2;
|
7546 |
|
7547 | function compareNode(a, b) {
|
7548 | return a && b ? compare(a.__data__, b.__data__) : !a - !b;
|
7549 | }
|
7550 |
|
7551 | for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
|
7552 | for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
|
7553 | if (node = group[i]) {
|
7554 | sortgroup[i] = node;
|
7555 | }
|
7556 | }
|
7557 | sortgroup.sort(compareNode);
|
7558 | }
|
7559 |
|
7560 | return new Selection(sortgroups, this._parents).order();
|
7561 | }
|
7562 |
|
7563 | function ascending$2(a, b) {
|
7564 | return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
7565 | }
|
7566 |
|
7567 | function selection_call() {
|
7568 | var callback = arguments[0];
|
7569 | arguments[0] = this;
|
7570 | callback.apply(null, arguments);
|
7571 | return this;
|
7572 | }
|
7573 |
|
7574 | function selection_nodes() {
|
7575 | var nodes = new Array(this.size()), i = -1;
|
7576 | this.each(function() { nodes[++i] = this; });
|
7577 | return nodes;
|
7578 | }
|
7579 |
|
7580 | function selection_node() {
|
7581 |
|
7582 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
7583 | for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
|
7584 | var node = group[i];
|
7585 | if (node) return node;
|
7586 | }
|
7587 | }
|
7588 |
|
7589 | return null;
|
7590 | }
|
7591 |
|
7592 | function selection_size() {
|
7593 | var size = 0;
|
7594 | this.each(function() { ++size; });
|
7595 | return size;
|
7596 | }
|
7597 |
|
7598 | function selection_empty() {
|
7599 | return !this.node();
|
7600 | }
|
7601 |
|
7602 | function selection_each(callback) {
|
7603 |
|
7604 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
7605 | for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
|
7606 | if (node = group[i]) callback.call(node, node.__data__, i, group);
|
7607 | }
|
7608 | }
|
7609 |
|
7610 | return this;
|
7611 | }
|
7612 |
|
7613 | function attrRemove(name) {
|
7614 | return function() {
|
7615 | this.removeAttribute(name);
|
7616 | };
|
7617 | }
|
7618 |
|
7619 | function attrRemoveNS(fullname) {
|
7620 | return function() {
|
7621 | this.removeAttributeNS(fullname.space, fullname.local);
|
7622 | };
|
7623 | }
|
7624 |
|
7625 | function attrConstant(name, value) {
|
7626 | return function() {
|
7627 | this.setAttribute(name, value);
|
7628 | };
|
7629 | }
|
7630 |
|
7631 | function attrConstantNS(fullname, value) {
|
7632 | return function() {
|
7633 | this.setAttributeNS(fullname.space, fullname.local, value);
|
7634 | };
|
7635 | }
|
7636 |
|
7637 | function attrFunction(name, value) {
|
7638 | return function() {
|
7639 | var v = value.apply(this, arguments);
|
7640 | if (v == null) this.removeAttribute(name);
|
7641 | else this.setAttribute(name, v);
|
7642 | };
|
7643 | }
|
7644 |
|
7645 | function attrFunctionNS(fullname, value) {
|
7646 | return function() {
|
7647 | var v = value.apply(this, arguments);
|
7648 | if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
|
7649 | else this.setAttributeNS(fullname.space, fullname.local, v);
|
7650 | };
|
7651 | }
|
7652 |
|
7653 | function selection_attr(name, value) {
|
7654 | var fullname = namespace(name);
|
7655 |
|
7656 | if (arguments.length < 2) {
|
7657 | var node = this.node();
|
7658 | return fullname.local
|
7659 | ? node.getAttributeNS(fullname.space, fullname.local)
|
7660 | : node.getAttribute(fullname);
|
7661 | }
|
7662 |
|
7663 | return this.each((value == null
|
7664 | ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
|
7665 | ? (fullname.local ? attrFunctionNS : attrFunction)
|
7666 | : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
|
7667 | }
|
7668 |
|
7669 | function window(node) {
|
7670 | return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
|
7671 | || (node.document && node) // node is a Window
|
7672 | || node.defaultView; // node is a Document
|
7673 | }
|
7674 |
|
7675 | function styleRemove(name) {
|
7676 | return function() {
|
7677 | this.style.removeProperty(name);
|
7678 | };
|
7679 | }
|
7680 |
|
7681 | function styleConstant(name, value, priority) {
|
7682 | return function() {
|
7683 | this.style.setProperty(name, value, priority);
|
7684 | };
|
7685 | }
|
7686 |
|
7687 | function styleFunction(name, value, priority) {
|
7688 | return function() {
|
7689 | var v = value.apply(this, arguments);
|
7690 | if (v == null) this.style.removeProperty(name);
|
7691 | else this.style.setProperty(name, v, priority);
|
7692 | };
|
7693 | }
|
7694 |
|
7695 | function selection_style(name, value, priority) {
|
7696 | var node;
|
7697 | return arguments.length > 1
|
7698 | ? this.each((value == null
|
7699 | ? styleRemove : typeof value === "function"
|
7700 | ? styleFunction
|
7701 | : styleConstant)(name, value, priority == null ? "" : priority))
|
7702 | : window(node = this.node())
|
7703 | .getComputedStyle(node, null)
|
7704 | .getPropertyValue(name);
|
7705 | }
|
7706 |
|
7707 | function propertyRemove(name) {
|
7708 | return function() {
|
7709 | delete this[name];
|
7710 | };
|
7711 | }
|
7712 |
|
7713 | function propertyConstant(name, value) {
|
7714 | return function() {
|
7715 | this[name] = value;
|
7716 | };
|
7717 | }
|
7718 |
|
7719 | function propertyFunction(name, value) {
|
7720 | return function() {
|
7721 | var v = value.apply(this, arguments);
|
7722 | if (v == null) delete this[name];
|
7723 | else this[name] = v;
|
7724 | };
|
7725 | }
|
7726 |
|
7727 | function selection_property(name, value) {
|
7728 | return arguments.length > 1
|
7729 | ? this.each((value == null
|
7730 | ? propertyRemove : typeof value === "function"
|
7731 | ? propertyFunction
|
7732 | : propertyConstant)(name, value))
|
7733 | : this.node()[name];
|
7734 | }
|
7735 |
|
7736 | function classArray(string) {
|
7737 | return string.trim().split(/^|\s+/);
|
7738 | }
|
7739 |
|
7740 | function classList(node) {
|
7741 | return node.classList || new ClassList(node);
|
7742 | }
|
7743 |
|
7744 | function ClassList(node) {
|
7745 | this._node = node;
|
7746 | this._names = classArray(node.getAttribute("class") || "");
|
7747 | }
|
7748 |
|
7749 | ClassList.prototype = {
|
7750 | add: function(name) {
|
7751 | var i = this._names.indexOf(name);
|
7752 | if (i < 0) {
|
7753 | this._names.push(name);
|
7754 | this._node.setAttribute("class", this._names.join(" "));
|
7755 | }
|
7756 | },
|
7757 | remove: function(name) {
|
7758 | var i = this._names.indexOf(name);
|
7759 | if (i >= 0) {
|
7760 | this._names.splice(i, 1);
|
7761 | this._node.setAttribute("class", this._names.join(" "));
|
7762 | }
|
7763 | },
|
7764 | contains: function(name) {
|
7765 | return this._names.indexOf(name) >= 0;
|
7766 | }
|
7767 | };
|
7768 |
|
7769 | function classedAdd(node, names) {
|
7770 | var list = classList(node), i = -1, n = names.length;
|
7771 | while (++i < n) list.add(names[i]);
|
7772 | }
|
7773 |
|
7774 | function classedRemove(node, names) {
|
7775 | var list = classList(node), i = -1, n = names.length;
|
7776 | while (++i < n) list.remove(names[i]);
|
7777 | }
|
7778 |
|
7779 | function classedTrue(names) {
|
7780 | return function() {
|
7781 | classedAdd(this, names);
|
7782 | };
|
7783 | }
|
7784 |
|
7785 | function classedFalse(names) {
|
7786 | return function() {
|
7787 | classedRemove(this, names);
|
7788 | };
|
7789 | }
|
7790 |
|
7791 | function classedFunction(names, value) {
|
7792 | return function() {
|
7793 | (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
|
7794 | };
|
7795 | }
|
7796 |
|
7797 | function selection_classed(name, value) {
|
7798 | var names = classArray(name + "");
|
7799 |
|
7800 | if (arguments.length < 2) {
|
7801 | var list = classList(this.node()), i = -1, n = names.length;
|
7802 | while (++i < n) if (!list.contains(names[i])) return false;
|
7803 | return true;
|
7804 | }
|
7805 |
|
7806 | return this.each((typeof value === "function"
|
7807 | ? classedFunction : value
|
7808 | ? classedTrue
|
7809 | : classedFalse)(names, value));
|
7810 | }
|
7811 |
|
7812 | function textRemove() {
|
7813 | this.textContent = "";
|
7814 | }
|
7815 |
|
7816 | function textConstant(value) {
|
7817 | return function() {
|
7818 | this.textContent = value;
|
7819 | };
|
7820 | }
|
7821 |
|
7822 | function textFunction(value) {
|
7823 | return function() {
|
7824 | var v = value.apply(this, arguments);
|
7825 | this.textContent = v == null ? "" : v;
|
7826 | };
|
7827 | }
|
7828 |
|
7829 | function selection_text(value) {
|
7830 | return arguments.length
|
7831 | ? this.each(value == null
|
7832 | ? textRemove : (typeof value === "function"
|
7833 | ? textFunction
|
7834 | : textConstant)(value))
|
7835 | : this.node().textContent;
|
7836 | }
|
7837 |
|
7838 | function htmlRemove() {
|
7839 | this.innerHTML = "";
|
7840 | }
|
7841 |
|
7842 | function htmlConstant(value) {
|
7843 | return function() {
|
7844 | this.innerHTML = value;
|
7845 | };
|
7846 | }
|
7847 |
|
7848 | function htmlFunction(value) {
|
7849 | return function() {
|
7850 | var v = value.apply(this, arguments);
|
7851 | this.innerHTML = v == null ? "" : v;
|
7852 | };
|
7853 | }
|
7854 |
|
7855 | function selection_html(value) {
|
7856 | return arguments.length
|
7857 | ? this.each(value == null
|
7858 | ? htmlRemove : (typeof value === "function"
|
7859 | ? htmlFunction
|
7860 | : htmlConstant)(value))
|
7861 | : this.node().innerHTML;
|
7862 | }
|
7863 |
|
7864 | function raise$1() {
|
7865 | if (this.nextSibling) this.parentNode.appendChild(this);
|
7866 | }
|
7867 |
|
7868 | function selection_raise() {
|
7869 | return this.each(raise$1);
|
7870 | }
|
7871 |
|
7872 | function lower() {
|
7873 | if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
|
7874 | }
|
7875 |
|
7876 | function selection_lower() {
|
7877 | return this.each(lower);
|
7878 | }
|
7879 |
|
7880 | function selection_append(name) {
|
7881 | var create = typeof name === "function" ? name : creator(name);
|
7882 | return this.select(function() {
|
7883 | return this.appendChild(create.apply(this, arguments));
|
7884 | });
|
7885 | }
|
7886 |
|
7887 | function constantNull() {
|
7888 | return null;
|
7889 | }
|
7890 |
|
7891 | function selection_insert(name, before) {
|
7892 | var create = typeof name === "function" ? name : creator(name),
|
7893 | select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
|
7894 | return this.select(function() {
|
7895 | return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
|
7896 | });
|
7897 | }
|
7898 |
|
7899 | function remove() {
|
7900 | var parent = this.parentNode;
|
7901 | if (parent) parent.removeChild(this);
|
7902 | }
|
7903 |
|
7904 | function selection_remove() {
|
7905 | return this.each(remove);
|
7906 | }
|
7907 |
|
7908 | function selection_datum(value) {
|
7909 | return arguments.length
|
7910 | ? this.property("__data__", value)
|
7911 | : this.node().__data__;
|
7912 | }
|
7913 |
|
7914 | function dispatchEvent(node, type, params) {
|
7915 | var window$$ = window(node),
|
7916 | event = window$$.CustomEvent;
|
7917 |
|
7918 | if (event) {
|
7919 | event = new event(type, params);
|
7920 | } else {
|
7921 | event = window$$.document.createEvent("Event");
|
7922 | if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
|
7923 | else event.initEvent(type, false, false);
|
7924 | }
|
7925 |
|
7926 | node.dispatchEvent(event);
|
7927 | }
|
7928 |
|
7929 | function dispatchConstant(type, params) {
|
7930 | return function() {
|
7931 | return dispatchEvent(this, type, params);
|
7932 | };
|
7933 | }
|
7934 |
|
7935 | function dispatchFunction(type, params) {
|
7936 | return function() {
|
7937 | return dispatchEvent(this, type, params.apply(this, arguments));
|
7938 | };
|
7939 | }
|
7940 |
|
7941 | function selection_dispatch(type, params) {
|
7942 | return this.each((typeof params === "function"
|
7943 | ? dispatchFunction
|
7944 | : dispatchConstant)(type, params));
|
7945 | }
|
7946 |
|
7947 | var root = [null];
|
7948 |
|
7949 | function Selection(groups, parents) {
|
7950 | this._groups = groups;
|
7951 | this._parents = parents;
|
7952 | }
|
7953 |
|
7954 | function selection() {
|
7955 | return new Selection([[document.documentElement]], root);
|
7956 | }
|
7957 |
|
7958 | Selection.prototype = selection.prototype = {
|
7959 | constructor: Selection,
|
7960 | select: selection_select,
|
7961 | selectAll: selection_selectAll,
|
7962 | filter: selection_filter,
|
7963 | data: selection_data,
|
7964 | enter: selection_enter,
|
7965 | exit: selection_exit,
|
7966 | merge: selection_merge,
|
7967 | order: selection_order,
|
7968 | sort: selection_sort,
|
7969 | call: selection_call,
|
7970 | nodes: selection_nodes,
|
7971 | node: selection_node,
|
7972 | size: selection_size,
|
7973 | empty: selection_empty,
|
7974 | each: selection_each,
|
7975 | attr: selection_attr,
|
7976 | style: selection_style,
|
7977 | property: selection_property,
|
7978 | classed: selection_classed,
|
7979 | text: selection_text,
|
7980 | html: selection_html,
|
7981 | raise: selection_raise,
|
7982 | lower: selection_lower,
|
7983 | append: selection_append,
|
7984 | insert: selection_insert,
|
7985 | remove: selection_remove,
|
7986 | datum: selection_datum,
|
7987 | on: selection_on,
|
7988 | dispatch: selection_dispatch
|
7989 | };
|
7990 |
|
7991 | function select(selector) {
|
7992 | return typeof selector === "string"
|
7993 | ? new Selection([[document.querySelector(selector)]], [document.documentElement])
|
7994 | : new Selection([[selector]], root);
|
7995 | }
|
7996 |
|
7997 | function selectAll(selector) {
|
7998 | return typeof selector === "string"
|
7999 | ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
|
8000 | : new Selection([selector == null ? [] : selector], root);
|
8001 | }
|
8002 |
|
8003 | function touch(node, touches, identifier) {
|
8004 | if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
|
8005 |
|
8006 | for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
|
8007 | if ((touch = touches[i]).identifier === identifier) {
|
8008 | return point$5(node, touch);
|
8009 | }
|
8010 | }
|
8011 |
|
8012 | return null;
|
8013 | }
|
8014 |
|
8015 | function touches(node, touches) {
|
8016 | if (touches == null) touches = sourceEvent().touches;
|
8017 |
|
8018 | for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
|
8019 | points[i] = point$5(node, touches[i]);
|
8020 | }
|
8021 |
|
8022 | return points;
|
8023 | }
|
8024 |
|
8025 | var emptyOn = dispatch("start", "end", "interrupt");
|
8026 | var emptyTween = [];
|
8027 |
|
8028 | var CREATED = 0;
|
8029 | var SCHEDULED = 1;
|
8030 | var STARTING = 2;
|
8031 | var STARTED = 3;
|
8032 | var ENDING = 4;
|
8033 | var ENDED = 5;
|
8034 |
|
8035 | function schedule(node, name, id, index, group, timing) {
|
8036 | var schedules = node.__transition;
|
8037 | if (!schedules) node.__transition = {};
|
8038 | else if (id in schedules) return;
|
8039 | create(node, id, {
|
8040 | name: name,
|
8041 | index: index, // For context during callback.
|
8042 | group: group, // For context during callback.
|
8043 | on: emptyOn,
|
8044 | tween: emptyTween,
|
8045 | time: timing.time,
|
8046 | delay: timing.delay,
|
8047 | duration: timing.duration,
|
8048 | ease: timing.ease,
|
8049 | timer: null,
|
8050 | state: CREATED
|
8051 | });
|
8052 | }
|
8053 |
|
8054 | function init(node, id) {
|
8055 | var schedule = node.__transition;
|
8056 | if (!schedule || !(schedule = schedule[id]) || schedule.state > CREATED) throw new Error("too late");
|
8057 | return schedule;
|
8058 | }
|
8059 |
|
8060 | function set$2(node, id) {
|
8061 | var schedule = node.__transition;
|
8062 | if (!schedule || !(schedule = schedule[id]) || schedule.state > STARTING) throw new Error("too late");
|
8063 | return schedule;
|
8064 | }
|
8065 |
|
8066 | function get$1(node, id) {
|
8067 | var schedule = node.__transition;
|
8068 | if (!schedule || !(schedule = schedule[id])) throw new Error("too late");
|
8069 | return schedule;
|
8070 | }
|
8071 |
|
8072 | function create(node, id, self) {
|
8073 | var schedules = node.__transition,
|
8074 | tween;
|
8075 |
|
8076 | // Initialize the self timer when the transition is created.
|
8077 | // Note the actual delay is not known until the first callback!
|
8078 | schedules[id] = self;
|
8079 | self.timer = timer(schedule, 0, self.time);
|
8080 |
|
8081 | // If the delay is greater than this first sleep, sleep some more;
|
8082 | // otherwise, start immediately.
|
8083 | function schedule(elapsed) {
|
8084 | self.state = SCHEDULED;
|
8085 | if (self.delay <= elapsed) start(elapsed - self.delay);
|
8086 | else self.timer.restart(start, self.delay, self.time);
|
8087 | }
|
8088 |
|
8089 | function start(elapsed) {
|
8090 | var i, j, n, o;
|
8091 |
|
8092 | for (i in schedules) {
|
8093 | o = schedules[i];
|
8094 | if (o.name !== self.name) continue;
|
8095 |
|
8096 | // Interrupt the active transition, if any.
|
8097 | // Dispatch the interrupt event.
|
8098 | if (o.state === STARTED) {
|
8099 | o.state = ENDED;
|
8100 | o.timer.stop();
|
8101 | o.on.call("interrupt", node, node.__data__, o.index, o.group);
|
8102 | delete schedules[i];
|
8103 | }
|
8104 |
|
8105 | // Cancel any pre-empted transitions. No interrupt event is dispatched
|
8106 | // because the cancelled transitions never started. Note that this also
|
8107 | // removes this transition from the pending list!
|
8108 | else if (+i < id) {
|
8109 | o.state = ENDED;
|
8110 | o.timer.stop();
|
8111 | delete schedules[i];
|
8112 | }
|
8113 | }
|
8114 |
|
8115 | // Defer the first tick to end of the current frame; see mbostock/d3#1576.
|
8116 | // Note the transition may be canceled after start and before the first tick!
|
8117 | // Note this must be scheduled before the start event; see d3/d3-transition#16!
|
8118 | // Assuming this is successful, subsequent callbacks go straight to tick.
|
8119 | timeout$1(function() {
|
8120 | if (self.state === STARTED) {
|
8121 | self.timer.restart(tick, self.delay, self.time);
|
8122 | tick(elapsed);
|
8123 | }
|
8124 | });
|
8125 |
|
8126 | // Dispatch the start event.
|
8127 | // Note this must be done before the tween are initialized.
|
8128 | self.state = STARTING;
|
8129 | self.on.call("start", node, node.__data__, self.index, self.group);
|
8130 | if (self.state !== STARTING) return; // interrupted
|
8131 | self.state = STARTED;
|
8132 |
|
8133 | // Initialize the tween, deleting null tween.
|
8134 | tween = new Array(n = self.tween.length);
|
8135 | for (i = 0, j = -1; i < n; ++i) {
|
8136 | if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
|
8137 | tween[++j] = o;
|
8138 | }
|
8139 | }
|
8140 | tween.length = j + 1;
|
8141 | }
|
8142 |
|
8143 | function tick(elapsed) {
|
8144 | var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.state = ENDING, 1),
|
8145 | i = -1,
|
8146 | n = tween.length;
|
8147 |
|
8148 | while (++i < n) {
|
8149 | tween[i].call(null, t);
|
8150 | }
|
8151 |
|
8152 | // Dispatch the end event.
|
8153 | if (self.state === ENDING) {
|
8154 | self.state = ENDED;
|
8155 | self.timer.stop();
|
8156 | self.on.call("end", node, node.__data__, self.index, self.group);
|
8157 | for (i in schedules) if (+i !== id) return void delete schedules[id];
|
8158 | delete node.__transition;
|
8159 | }
|
8160 | }
|
8161 | }
|
8162 |
|
8163 | function interrupt(node, name) {
|
8164 | var schedules = node.__transition,
|
8165 | schedule,
|
8166 | active,
|
8167 | empty = true,
|
8168 | i;
|
8169 |
|
8170 | if (!schedules) return;
|
8171 |
|
8172 | name = name == null ? null : name + "";
|
8173 |
|
8174 | for (i in schedules) {
|
8175 | if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
|
8176 | active = schedule.state === STARTED;
|
8177 | schedule.state = ENDED;
|
8178 | schedule.timer.stop();
|
8179 | if (active) schedule.on.call("interrupt", node, node.__data__, schedule.index, schedule.group);
|
8180 | delete schedules[i];
|
8181 | }
|
8182 |
|
8183 | if (empty) delete node.__transition;
|
8184 | }
|
8185 |
|
8186 | function selection_interrupt(name) {
|
8187 | return this.each(function() {
|
8188 | interrupt(this, name);
|
8189 | });
|
8190 | }
|
8191 |
|
8192 | function tweenRemove(id, name) {
|
8193 | var tween0, tween1;
|
8194 | return function() {
|
8195 | var schedule = set$2(this, id),
|
8196 | tween = schedule.tween;
|
8197 |
|
8198 | // If this node shared tween with the previous node,
|
8199 | // just assign the updated shared tween and we’re done!
|
8200 | // Otherwise, copy-on-write.
|
8201 | if (tween !== tween0) {
|
8202 | tween1 = tween0 = tween;
|
8203 | for (var i = 0, n = tween1.length; i < n; ++i) {
|
8204 | if (tween1[i].name === name) {
|
8205 | tween1 = tween1.slice();
|
8206 | tween1.splice(i, 1);
|
8207 | break;
|
8208 | }
|
8209 | }
|
8210 | }
|
8211 |
|
8212 | schedule.tween = tween1;
|
8213 | };
|
8214 | }
|
8215 |
|
8216 | function tweenFunction(id, name, value) {
|
8217 | var tween0, tween1;
|
8218 | if (typeof value !== "function") throw new Error;
|
8219 | return function() {
|
8220 | var schedule = set$2(this, id),
|
8221 | tween = schedule.tween;
|
8222 |
|
8223 | // If this node shared tween with the previous node,
|
8224 | // just assign the updated shared tween and we’re done!
|
8225 | // Otherwise, copy-on-write.
|
8226 | if (tween !== tween0) {
|
8227 | tween1 = (tween0 = tween).slice();
|
8228 | for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
|
8229 | if (tween1[i].name === name) {
|
8230 | tween1[i] = t;
|
8231 | break;
|
8232 | }
|
8233 | }
|
8234 | if (i === n) tween1.push(t);
|
8235 | }
|
8236 |
|
8237 | schedule.tween = tween1;
|
8238 | };
|
8239 | }
|
8240 |
|
8241 | function transition_tween(name, value) {
|
8242 | var id = this._id;
|
8243 |
|
8244 | name += "";
|
8245 |
|
8246 | if (arguments.length < 2) {
|
8247 | var tween = get$1(this.node(), id).tween;
|
8248 | for (var i = 0, n = tween.length, t; i < n; ++i) {
|
8249 | if ((t = tween[i]).name === name) {
|
8250 | return t.value;
|
8251 | }
|
8252 | }
|
8253 | return null;
|
8254 | }
|
8255 |
|
8256 | return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
|
8257 | }
|
8258 |
|
8259 | function tweenValue(transition, name, value) {
|
8260 | var id = transition._id;
|
8261 |
|
8262 | transition.each(function() {
|
8263 | var schedule = set$2(this, id);
|
8264 | (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
|
8265 | });
|
8266 |
|
8267 | return function(node) {
|
8268 | return get$1(node, id).value[name];
|
8269 | };
|
8270 | }
|
8271 |
|
8272 | function interpolate$1(a, b) {
|
8273 | var c;
|
8274 | return (typeof b === "number" ? interpolateNumber
|
8275 | : b instanceof color ? interpolateRgb
|
8276 | : (c = color(b)) ? (b = c, interpolateRgb)
|
8277 | : interpolateString)(a, b);
|
8278 | }
|
8279 |
|
8280 | function attrRemove$1(name) {
|
8281 | return function() {
|
8282 | this.removeAttribute(name);
|
8283 | };
|
8284 | }
|
8285 |
|
8286 | function attrRemoveNS$1(fullname) {
|
8287 | return function() {
|
8288 | this.removeAttributeNS(fullname.space, fullname.local);
|
8289 | };
|
8290 | }
|
8291 |
|
8292 | function attrConstant$1(name, interpolate, value1) {
|
8293 | var value00,
|
8294 | interpolate0;
|
8295 | return function() {
|
8296 | var value0 = this.getAttribute(name);
|
8297 | return value0 === value1 ? null
|
8298 | : value0 === value00 ? interpolate0
|
8299 | : interpolate0 = interpolate(value00 = value0, value1);
|
8300 | };
|
8301 | }
|
8302 |
|
8303 | function attrConstantNS$1(fullname, interpolate, value1) {
|
8304 | var value00,
|
8305 | interpolate0;
|
8306 | return function() {
|
8307 | var value0 = this.getAttributeNS(fullname.space, fullname.local);
|
8308 | return value0 === value1 ? null
|
8309 | : value0 === value00 ? interpolate0
|
8310 | : interpolate0 = interpolate(value00 = value0, value1);
|
8311 | };
|
8312 | }
|
8313 |
|
8314 | function attrFunction$1(name, interpolate, value) {
|
8315 | var value00,
|
8316 | value10,
|
8317 | interpolate0;
|
8318 | return function() {
|
8319 | var value0, value1 = value(this);
|
8320 | if (value1 == null) return void this.removeAttribute(name);
|
8321 | value0 = this.getAttribute(name);
|
8322 | return value0 === value1 ? null
|
8323 | : value0 === value00 && value1 === value10 ? interpolate0
|
8324 | : interpolate0 = interpolate(value00 = value0, value10 = value1);
|
8325 | };
|
8326 | }
|
8327 |
|
8328 | function attrFunctionNS$1(fullname, interpolate, value) {
|
8329 | var value00,
|
8330 | value10,
|
8331 | interpolate0;
|
8332 | return function() {
|
8333 | var value0, value1 = value(this);
|
8334 | if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
|
8335 | value0 = this.getAttributeNS(fullname.space, fullname.local);
|
8336 | return value0 === value1 ? null
|
8337 | : value0 === value00 && value1 === value10 ? interpolate0
|
8338 | : interpolate0 = interpolate(value00 = value0, value10 = value1);
|
8339 | };
|
8340 | }
|
8341 |
|
8342 | function transition_attr(name, value) {
|
8343 | var fullname = namespace(name), i = fullname === "transform" ? interpolateTransform$2 : interpolate$1;
|
8344 | return this.attrTween(name, typeof value === "function"
|
8345 | ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
|
8346 | : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
|
8347 | : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
|
8348 | }
|
8349 |
|
8350 | function attrTweenNS(fullname, value) {
|
8351 | function tween() {
|
8352 | var node = this, i = value.apply(node, arguments);
|
8353 | return i && function(t) {
|
8354 | node.setAttributeNS(fullname.space, fullname.local, i(t));
|
8355 | };
|
8356 | }
|
8357 | tween._value = value;
|
8358 | return tween;
|
8359 | }
|
8360 |
|
8361 | function attrTween(name, value) {
|
8362 | function tween() {
|
8363 | var node = this, i = value.apply(node, arguments);
|
8364 | return i && function(t) {
|
8365 | node.setAttribute(name, i(t));
|
8366 | };
|
8367 | }
|
8368 | tween._value = value;
|
8369 | return tween;
|
8370 | }
|
8371 |
|
8372 | function transition_attrTween(name, value) {
|
8373 | var key = "attr." + name;
|
8374 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
8375 | if (value == null) return this.tween(key, null);
|
8376 | if (typeof value !== "function") throw new Error;
|
8377 | var fullname = namespace(name);
|
8378 | return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
|
8379 | }
|
8380 |
|
8381 | function delayFunction(id, value) {
|
8382 | return function() {
|
8383 | init(this, id).delay = +value.apply(this, arguments);
|
8384 | };
|
8385 | }
|
8386 |
|
8387 | function delayConstant(id, value) {
|
8388 | return value = +value, function() {
|
8389 | init(this, id).delay = value;
|
8390 | };
|
8391 | }
|
8392 |
|
8393 | function transition_delay(value) {
|
8394 | var id = this._id;
|
8395 |
|
8396 | return arguments.length
|
8397 | ? this.each((typeof value === "function"
|
8398 | ? delayFunction
|
8399 | : delayConstant)(id, value))
|
8400 | : get$1(this.node(), id).delay;
|
8401 | }
|
8402 |
|
8403 | function durationFunction(id, value) {
|
8404 | return function() {
|
8405 | set$2(this, id).duration = +value.apply(this, arguments);
|
8406 | };
|
8407 | }
|
8408 |
|
8409 | function durationConstant(id, value) {
|
8410 | return value = +value, function() {
|
8411 | set$2(this, id).duration = value;
|
8412 | };
|
8413 | }
|
8414 |
|
8415 | function transition_duration(value) {
|
8416 | var id = this._id;
|
8417 |
|
8418 | return arguments.length
|
8419 | ? this.each((typeof value === "function"
|
8420 | ? durationFunction
|
8421 | : durationConstant)(id, value))
|
8422 | : get$1(this.node(), id).duration;
|
8423 | }
|
8424 |
|
8425 | function easeConstant(id, value) {
|
8426 | if (typeof value !== "function") throw new Error;
|
8427 | return function() {
|
8428 | set$2(this, id).ease = value;
|
8429 | };
|
8430 | }
|
8431 |
|
8432 | function transition_ease(value) {
|
8433 | var id = this._id;
|
8434 |
|
8435 | return arguments.length
|
8436 | ? this.each(easeConstant(id, value))
|
8437 | : get$1(this.node(), id).ease;
|
8438 | }
|
8439 |
|
8440 | function transition_filter(match) {
|
8441 | if (typeof match !== "function") match = matcher$1(match);
|
8442 |
|
8443 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
8444 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
|
8445 | if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
8446 | subgroup.push(node);
|
8447 | }
|
8448 | }
|
8449 | }
|
8450 |
|
8451 | return new Transition(subgroups, this._parents, this._name, this._id);
|
8452 | }
|
8453 |
|
8454 | function transition_merge(transition) {
|
8455 | if (transition._id !== this._id) throw new Error;
|
8456 |
|
8457 | 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) {
|
8458 | for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
|
8459 | if (node = group0[i] || group1[i]) {
|
8460 | merge[i] = node;
|
8461 | }
|
8462 | }
|
8463 | }
|
8464 |
|
8465 | for (; j < m0; ++j) {
|
8466 | merges[j] = groups0[j];
|
8467 | }
|
8468 |
|
8469 | return new Transition(merges, this._parents, this._name, this._id);
|
8470 | }
|
8471 |
|
8472 | function start$1(name) {
|
8473 | return (name + "").trim().split(/^|\s+/).every(function(t) {
|
8474 | var i = t.indexOf(".");
|
8475 | if (i >= 0) t = t.slice(0, i);
|
8476 | return !t || t === "start";
|
8477 | });
|
8478 | }
|
8479 |
|
8480 | function onFunction(id, name, listener) {
|
8481 | var on0, on1, sit = start$1(name) ? init : set$2;
|
8482 | return function() {
|
8483 | var schedule = sit(this, id),
|
8484 | on = schedule.on;
|
8485 |
|
8486 | // If this node shared a dispatch with the previous node,
|
8487 | // just assign the updated shared dispatch and we’re done!
|
8488 | // Otherwise, copy-on-write.
|
8489 | if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
|
8490 |
|
8491 | schedule.on = on1;
|
8492 | };
|
8493 | }
|
8494 |
|
8495 | function transition_on(name, listener) {
|
8496 | var id = this._id;
|
8497 |
|
8498 | return arguments.length < 2
|
8499 | ? get$1(this.node(), id).on.on(name)
|
8500 | : this.each(onFunction(id, name, listener));
|
8501 | }
|
8502 |
|
8503 | function removeFunction(id) {
|
8504 | return function() {
|
8505 | var parent = this.parentNode;
|
8506 | for (var i in this.__transition) if (+i !== id) return;
|
8507 | if (parent) parent.removeChild(this);
|
8508 | };
|
8509 | }
|
8510 |
|
8511 | function transition_remove() {
|
8512 | return this.on("end.remove", removeFunction(this._id));
|
8513 | }
|
8514 |
|
8515 | function transition_select(select) {
|
8516 | var name = this._name,
|
8517 | id = this._id;
|
8518 |
|
8519 | if (typeof select !== "function") select = selector(select);
|
8520 |
|
8521 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
8522 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
|
8523 | if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
8524 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
8525 | subgroup[i] = subnode;
|
8526 | schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
|
8527 | }
|
8528 | }
|
8529 | }
|
8530 |
|
8531 | return new Transition(subgroups, this._parents, name, id);
|
8532 | }
|
8533 |
|
8534 | function transition_selectAll(select) {
|
8535 | var name = this._name,
|
8536 | id = this._id;
|
8537 |
|
8538 | if (typeof select !== "function") select = selectorAll(select);
|
8539 |
|
8540 | for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
|
8541 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
8542 | if (node = group[i]) {
|
8543 | for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
|
8544 | if (child = children[k]) {
|
8545 | schedule(child, name, id, k, children, inherit);
|
8546 | }
|
8547 | }
|
8548 | subgroups.push(children);
|
8549 | parents.push(node);
|
8550 | }
|
8551 | }
|
8552 | }
|
8553 |
|
8554 | return new Transition(subgroups, parents, name, id);
|
8555 | }
|
8556 |
|
8557 | var Selection$1 = selection.prototype.constructor;
|
8558 |
|
8559 | function transition_selection() {
|
8560 | return new Selection$1(this._groups, this._parents);
|
8561 | }
|
8562 |
|
8563 | function styleRemove$1(name, interpolate) {
|
8564 | var value00,
|
8565 | value10,
|
8566 | interpolate0;
|
8567 | return function() {
|
8568 | var style = window(this).getComputedStyle(this, null),
|
8569 | value0 = style.getPropertyValue(name),
|
8570 | value1 = (this.style.removeProperty(name), style.getPropertyValue(name));
|
8571 | return value0 === value1 ? null
|
8572 | : value0 === value00 && value1 === value10 ? interpolate0
|
8573 | : interpolate0 = interpolate(value00 = value0, value10 = value1);
|
8574 | };
|
8575 | }
|
8576 |
|
8577 | function styleRemoveEnd(name) {
|
8578 | return function() {
|
8579 | this.style.removeProperty(name);
|
8580 | };
|
8581 | }
|
8582 |
|
8583 | function styleConstant$1(name, interpolate, value1) {
|
8584 | var value00,
|
8585 | interpolate0;
|
8586 | return function() {
|
8587 | var value0 = window(this).getComputedStyle(this, null).getPropertyValue(name);
|
8588 | return value0 === value1 ? null
|
8589 | : value0 === value00 ? interpolate0
|
8590 | : interpolate0 = interpolate(value00 = value0, value1);
|
8591 | };
|
8592 | }
|
8593 |
|
8594 | function styleFunction$1(name, interpolate, value) {
|
8595 | var value00,
|
8596 | value10,
|
8597 | interpolate0;
|
8598 | return function() {
|
8599 | var style = window(this).getComputedStyle(this, null),
|
8600 | value0 = style.getPropertyValue(name),
|
8601 | value1 = value(this);
|
8602 | if (value1 == null) value1 = (this.style.removeProperty(name), style.getPropertyValue(name));
|
8603 | return value0 === value1 ? null
|
8604 | : value0 === value00 && value1 === value10 ? interpolate0
|
8605 | : interpolate0 = interpolate(value00 = value0, value10 = value1);
|
8606 | };
|
8607 | }
|
8608 |
|
8609 | function transition_style(name, value, priority) {
|
8610 | var i = (name += "") === "transform" ? interpolateTransform$1 : interpolate$1;
|
8611 | return value == null ? this
|
8612 | .styleTween(name, styleRemove$1(name, i))
|
8613 | .on("end.style." + name, styleRemoveEnd(name))
|
8614 | : this.styleTween(name, typeof value === "function"
|
8615 | ? styleFunction$1(name, i, tweenValue(this, "style." + name, value))
|
8616 | : styleConstant$1(name, i, value), priority);
|
8617 | }
|
8618 |
|
8619 | function styleTween(name, value, priority) {
|
8620 | function tween() {
|
8621 | var node = this, i = value.apply(node, arguments);
|
8622 | return i && function(t) {
|
8623 | node.style.setProperty(name, i(t), priority);
|
8624 | };
|
8625 | }
|
8626 | tween._value = value;
|
8627 | return tween;
|
8628 | }
|
8629 |
|
8630 | function transition_styleTween(name, value, priority) {
|
8631 | var key = "style." + (name += "");
|
8632 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
8633 | if (value == null) return this.tween(key, null);
|
8634 | if (typeof value !== "function") throw new Error;
|
8635 | return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
|
8636 | }
|
8637 |
|
8638 | function textConstant$1(value) {
|
8639 | return function() {
|
8640 | this.textContent = value;
|
8641 | };
|
8642 | }
|
8643 |
|
8644 | function textFunction$1(value) {
|
8645 | return function() {
|
8646 | var value1 = value(this);
|
8647 | this.textContent = value1 == null ? "" : value1;
|
8648 | };
|
8649 | }
|
8650 |
|
8651 | function transition_text(value) {
|
8652 | return this.tween("text", typeof value === "function"
|
8653 | ? textFunction$1(tweenValue(this, "text", value))
|
8654 | : textConstant$1(value == null ? "" : value + ""));
|
8655 | }
|
8656 |
|
8657 | function transition_transition() {
|
8658 | var name = this._name,
|
8659 | id0 = this._id,
|
8660 | id1 = newId();
|
8661 |
|
8662 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
8663 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
8664 | if (node = group[i]) {
|
8665 | var inherit = get$1(node, id0);
|
8666 | schedule(node, name, id1, i, group, {
|
8667 | time: inherit.time + inherit.delay + inherit.duration,
|
8668 | delay: 0,
|
8669 | duration: inherit.duration,
|
8670 | ease: inherit.ease
|
8671 | });
|
8672 | }
|
8673 | }
|
8674 | }
|
8675 |
|
8676 | return new Transition(groups, this._parents, name, id1);
|
8677 | }
|
8678 |
|
8679 | var id = 0;
|
8680 |
|
8681 | function Transition(groups, parents, name, id) {
|
8682 | this._groups = groups;
|
8683 | this._parents = parents;
|
8684 | this._name = name;
|
8685 | this._id = id;
|
8686 | }
|
8687 |
|
8688 | function transition(name) {
|
8689 | return selection().transition(name);
|
8690 | }
|
8691 |
|
8692 | function newId() {
|
8693 | return ++id;
|
8694 | }
|
8695 |
|
8696 | var selection_prototype = selection.prototype;
|
8697 |
|
8698 | Transition.prototype = transition.prototype = {
|
8699 | constructor: Transition,
|
8700 | select: transition_select,
|
8701 | selectAll: transition_selectAll,
|
8702 | filter: transition_filter,
|
8703 | merge: transition_merge,
|
8704 | selection: transition_selection,
|
8705 | transition: transition_transition,
|
8706 | call: selection_prototype.call,
|
8707 | nodes: selection_prototype.nodes,
|
8708 | node: selection_prototype.node,
|
8709 | size: selection_prototype.size,
|
8710 | empty: selection_prototype.empty,
|
8711 | each: selection_prototype.each,
|
8712 | on: transition_on,
|
8713 | attr: transition_attr,
|
8714 | attrTween: transition_attrTween,
|
8715 | style: transition_style,
|
8716 | styleTween: transition_styleTween,
|
8717 | text: transition_text,
|
8718 | remove: transition_remove,
|
8719 | tween: transition_tween,
|
8720 | delay: transition_delay,
|
8721 | duration: transition_duration,
|
8722 | ease: transition_ease
|
8723 | };
|
8724 |
|
8725 | var defaultTiming = {
|
8726 | time: null, // Set on use.
|
8727 | delay: 0,
|
8728 | duration: 250,
|
8729 | ease: easeCubicInOut
|
8730 | };
|
8731 |
|
8732 | function inherit(node, id) {
|
8733 | var timing;
|
8734 | while (!(timing = node.__transition) || !(timing = timing[id])) {
|
8735 | if (!(node = node.parentNode)) {
|
8736 | return defaultTiming.time = now(), defaultTiming;
|
8737 | }
|
8738 | }
|
8739 | return timing;
|
8740 | }
|
8741 |
|
8742 | function selection_transition(name) {
|
8743 | var id,
|
8744 | timing;
|
8745 |
|
8746 | if (name instanceof Transition) {
|
8747 | id = name._id, name = name._name;
|
8748 | } else {
|
8749 | id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
|
8750 | }
|
8751 |
|
8752 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
8753 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
8754 | if (node = group[i]) {
|
8755 | schedule(node, name, id, i, group, timing || inherit(node, id));
|
8756 | }
|
8757 | }
|
8758 | }
|
8759 |
|
8760 | return new Transition(groups, this._parents, name, id);
|
8761 | }
|
8762 |
|
8763 | selection.prototype.interrupt = selection_interrupt;
|
8764 | selection.prototype.transition = selection_transition;
|
8765 |
|
8766 | var root$1 = [null];
|
8767 |
|
8768 | function active(node, name) {
|
8769 | var schedules = node.__transition,
|
8770 | schedule,
|
8771 | i;
|
8772 |
|
8773 | if (schedules) {
|
8774 | name = name == null ? null : name + "";
|
8775 | for (i in schedules) {
|
8776 | if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
|
8777 | return new Transition([[node]], root$1, name, +i);
|
8778 | }
|
8779 | }
|
8780 | }
|
8781 |
|
8782 | return null;
|
8783 | }
|
8784 |
|
8785 | var slice$4 = Array.prototype.slice;
|
8786 |
|
8787 | function identity$5(x) {
|
8788 | return x;
|
8789 | }
|
8790 |
|
8791 | var top = 1;
|
8792 | var right = 2;
|
8793 | var bottom = 3;
|
8794 | var left = 4;
|
8795 | var epsilon$2 = 1e-6;
|
8796 | function translateX(scale0, scale1, d) {
|
8797 | var x = scale0(d);
|
8798 | return "translate(" + (isFinite(x) ? x : scale1(d)) + ",0)";
|
8799 | }
|
8800 |
|
8801 | function translateY(scale0, scale1, d) {
|
8802 | var y = scale0(d);
|
8803 | return "translate(0," + (isFinite(y) ? y : scale1(d)) + ")";
|
8804 | }
|
8805 |
|
8806 | function center(scale) {
|
8807 | var width = scale.bandwidth() / 2;
|
8808 | return function(d) {
|
8809 | return scale(d) + width;
|
8810 | };
|
8811 | }
|
8812 |
|
8813 | function entering() {
|
8814 | return !this.__axis;
|
8815 | }
|
8816 |
|
8817 | function axis(orient, scale) {
|
8818 | var tickArguments = [],
|
8819 | tickValues = null,
|
8820 | tickFormat = null,
|
8821 | tickSizeInner = 6,
|
8822 | tickSizeOuter = 6,
|
8823 | tickPadding = 3;
|
8824 |
|
8825 | function axis(context) {
|
8826 | var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
|
8827 | format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$5) : tickFormat,
|
8828 | spacing = Math.max(tickSizeInner, 0) + tickPadding,
|
8829 | transform = orient === top || orient === bottom ? translateX : translateY,
|
8830 | range = scale.range(),
|
8831 | range0 = range[0] + 0.5,
|
8832 | range1 = range[range.length - 1] + 0.5,
|
8833 | position = (scale.bandwidth ? center : identity$5)(scale.copy()),
|
8834 | selection = context.selection ? context.selection() : context,
|
8835 | path = selection.selectAll(".domain").data([null]),
|
8836 | tick = selection.selectAll(".tick").data(values, scale).order(),
|
8837 | tickExit = tick.exit(),
|
8838 | tickEnter = tick.enter().append("g").attr("class", "tick"),
|
8839 | line = tick.select("line"),
|
8840 | text = tick.select("text"),
|
8841 | k = orient === top || orient === left ? -1 : 1,
|
8842 | x, y = orient === left || orient === right ? (x = "x", "y") : (x = "y", "x");
|
8843 |
|
8844 | path = path.merge(path.enter().insert("path", ".tick")
|
8845 | .attr("class", "domain")
|
8846 | .attr("stroke", "#000"));
|
8847 |
|
8848 | tick = tick.merge(tickEnter);
|
8849 |
|
8850 | line = line.merge(tickEnter.append("line")
|
8851 | .attr("stroke", "#000")
|
8852 | .attr(x + "2", k * tickSizeInner)
|
8853 | .attr(y + "1", 0.5)
|
8854 | .attr(y + "2", 0.5));
|
8855 |
|
8856 | text = text.merge(tickEnter.append("text")
|
8857 | .attr("fill", "#000")
|
8858 | .attr(x, k * spacing)
|
8859 | .attr(y, 0.5)
|
8860 | .attr("dy", orient === top ? "0em" : orient === bottom ? ".71em" : ".32em"));
|
8861 |
|
8862 | if (context !== selection) {
|
8863 | path = path.transition(context);
|
8864 | tick = tick.transition(context);
|
8865 | line = line.transition(context);
|
8866 | text = text.transition(context);
|
8867 |
|
8868 | tickExit = tickExit.transition(context)
|
8869 | .attr("opacity", epsilon$2)
|
8870 | .attr("transform", function(d) { return transform(position, this.parentNode.__axis || position, d); });
|
8871 |
|
8872 | tickEnter
|
8873 | .attr("opacity", epsilon$2)
|
8874 | .attr("transform", function(d) { return transform(this.parentNode.__axis || position, position, d); });
|
8875 | }
|
8876 |
|
8877 | tickExit.remove();
|
8878 |
|
8879 | path
|
8880 | .attr("d", orient === left || orient == right
|
8881 | ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
|
8882 | : "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
|
8883 |
|
8884 | tick
|
8885 | .attr("opacity", 1)
|
8886 | .attr("transform", function(d) { return transform(position, position, d); });
|
8887 |
|
8888 | line
|
8889 | .attr(x + "2", k * tickSizeInner);
|
8890 |
|
8891 | text
|
8892 | .attr(x, k * spacing)
|
8893 | .text(format);
|
8894 |
|
8895 | selection.filter(entering)
|
8896 | .attr("fill", "none")
|
8897 | .attr("font-size", 10)
|
8898 | .attr("font-family", "sans-serif")
|
8899 | .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
|
8900 |
|
8901 | selection
|
8902 | .each(function() { this.__axis = position; });
|
8903 | }
|
8904 |
|
8905 | axis.scale = function(_) {
|
8906 | return arguments.length ? (scale = _, axis) : scale;
|
8907 | };
|
8908 |
|
8909 | axis.ticks = function() {
|
8910 | return tickArguments = slice$4.call(arguments), axis;
|
8911 | };
|
8912 |
|
8913 | axis.tickArguments = function(_) {
|
8914 | return arguments.length ? (tickArguments = _ == null ? [] : slice$4.call(_), axis) : tickArguments.slice();
|
8915 | };
|
8916 |
|
8917 | axis.tickValues = function(_) {
|
8918 | return arguments.length ? (tickValues = _ == null ? null : slice$4.call(_), axis) : tickValues && tickValues.slice();
|
8919 | };
|
8920 |
|
8921 | axis.tickFormat = function(_) {
|
8922 | return arguments.length ? (tickFormat = _, axis) : tickFormat;
|
8923 | };
|
8924 |
|
8925 | axis.tickSize = function(_) {
|
8926 | return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
|
8927 | };
|
8928 |
|
8929 | axis.tickSizeInner = function(_) {
|
8930 | return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
|
8931 | };
|
8932 |
|
8933 | axis.tickSizeOuter = function(_) {
|
8934 | return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
|
8935 | };
|
8936 |
|
8937 | axis.tickPadding = function(_) {
|
8938 | return arguments.length ? (tickPadding = +_, axis) : tickPadding;
|
8939 | };
|
8940 |
|
8941 | return axis;
|
8942 | }
|
8943 |
|
8944 | function axisTop(scale) {
|
8945 | return axis(top, scale);
|
8946 | }
|
8947 |
|
8948 | function axisRight(scale) {
|
8949 | return axis(right, scale);
|
8950 | }
|
8951 |
|
8952 | function axisBottom(scale) {
|
8953 | return axis(bottom, scale);
|
8954 | }
|
8955 |
|
8956 | function axisLeft(scale) {
|
8957 | return axis(left, scale);
|
8958 | }
|
8959 |
|
8960 | function defaultSeparation(a, b) {
|
8961 | return a.parent === b.parent ? 1 : 2;
|
8962 | }
|
8963 |
|
8964 | function meanX(children) {
|
8965 | return children.reduce(meanXReduce, 0) / children.length;
|
8966 | }
|
8967 |
|
8968 | function meanXReduce(x, c) {
|
8969 | return x + c.x;
|
8970 | }
|
8971 |
|
8972 | function maxY(children) {
|
8973 | return 1 + children.reduce(maxYReduce, 0);
|
8974 | }
|
8975 |
|
8976 | function maxYReduce(y, c) {
|
8977 | return Math.max(y, c.y);
|
8978 | }
|
8979 |
|
8980 | function leafLeft(node) {
|
8981 | var children;
|
8982 | while (children = node.children) node = children[0];
|
8983 | return node;
|
8984 | }
|
8985 |
|
8986 | function leafRight(node) {
|
8987 | var children;
|
8988 | while (children = node.children) node = children[children.length - 1];
|
8989 | return node;
|
8990 | }
|
8991 |
|
8992 | function cluster() {
|
8993 | var separation = defaultSeparation,
|
8994 | dx = 1,
|
8995 | dy = 1,
|
8996 | nodeSize = false;
|
8997 |
|
8998 | function cluster(root) {
|
8999 | var previousNode,
|
9000 | x = 0;
|
9001 |
|
9002 | // First walk, computing the initial x & y values.
|
9003 | root.eachAfter(function(node) {
|
9004 | var children = node.children;
|
9005 | if (children) {
|
9006 | node.x = meanX(children);
|
9007 | node.y = maxY(children);
|
9008 | } else {
|
9009 | node.x = previousNode ? x += separation(node, previousNode) : 0;
|
9010 | node.y = 0;
|
9011 | previousNode = node;
|
9012 | }
|
9013 | });
|
9014 |
|
9015 | var left = leafLeft(root),
|
9016 | right = leafRight(root),
|
9017 | x0 = left.x - separation(left, right) / 2,
|
9018 | x1 = right.x + separation(right, left) / 2;
|
9019 |
|
9020 | // Second walk, normalizing x & y to the desired size.
|
9021 | return root.eachAfter(nodeSize ? function(node) {
|
9022 | node.x = (node.x - root.x) * dx;
|
9023 | node.y = (root.y - node.y) * dy;
|
9024 | } : function(node) {
|
9025 | node.x = (node.x - x0) / (x1 - x0) * dx;
|
9026 | node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
|
9027 | });
|
9028 | }
|
9029 |
|
9030 | cluster.separation = function(x) {
|
9031 | return arguments.length ? (separation = x, cluster) : separation;
|
9032 | };
|
9033 |
|
9034 | cluster.size = function(x) {
|
9035 | return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
|
9036 | };
|
9037 |
|
9038 | cluster.nodeSize = function(x) {
|
9039 | return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
|
9040 | };
|
9041 |
|
9042 | return cluster;
|
9043 | }
|
9044 |
|
9045 | function node_each(callback) {
|
9046 | var node = this, current, next = [node], children, i, n;
|
9047 | do {
|
9048 | current = next.reverse(), next = [];
|
9049 | while (node = current.pop()) {
|
9050 | callback(node), children = node.children;
|
9051 | if (children) for (i = 0, n = children.length; i < n; ++i) {
|
9052 | next.push(children[i]);
|
9053 | }
|
9054 | }
|
9055 | } while (next.length);
|
9056 | return this;
|
9057 | }
|
9058 |
|
9059 | function node_eachBefore(callback) {
|
9060 | var node = this, nodes = [node], children, i;
|
9061 | while (node = nodes.pop()) {
|
9062 | callback(node), children = node.children;
|
9063 | if (children) for (i = children.length - 1; i >= 0; --i) {
|
9064 | nodes.push(children[i]);
|
9065 | }
|
9066 | }
|
9067 | return this;
|
9068 | }
|
9069 |
|
9070 | function node_eachAfter(callback) {
|
9071 | var node = this, nodes = [node], next = [], children, i, n;
|
9072 | while (node = nodes.pop()) {
|
9073 | next.push(node), children = node.children;
|
9074 | if (children) for (i = 0, n = children.length; i < n; ++i) {
|
9075 | nodes.push(children[i]);
|
9076 | }
|
9077 | }
|
9078 | while (node = next.pop()) {
|
9079 | callback(node);
|
9080 | }
|
9081 | return this;
|
9082 | }
|
9083 |
|
9084 | function node_sum(value) {
|
9085 | return this.eachAfter(function(node) {
|
9086 | var sum = +value(node.data) || 0,
|
9087 | children = node.children,
|
9088 | i = children && children.length;
|
9089 | while (--i >= 0) sum += children[i].value;
|
9090 | node.value = sum;
|
9091 | });
|
9092 | }
|
9093 |
|
9094 | function node_sort(compare) {
|
9095 | return this.eachBefore(function(node) {
|
9096 | if (node.children) {
|
9097 | node.children.sort(compare);
|
9098 | }
|
9099 | });
|
9100 | }
|
9101 |
|
9102 | function node_path(end) {
|
9103 | var start = this,
|
9104 | ancestor = leastCommonAncestor(start, end),
|
9105 | nodes = [start];
|
9106 | while (start !== ancestor) {
|
9107 | start = start.parent;
|
9108 | nodes.push(start);
|
9109 | }
|
9110 | var k = nodes.length;
|
9111 | while (end !== ancestor) {
|
9112 | nodes.splice(k, 0, end);
|
9113 | end = end.parent;
|
9114 | }
|
9115 | return nodes;
|
9116 | }
|
9117 |
|
9118 | function leastCommonAncestor(a, b) {
|
9119 | if (a === b) return a;
|
9120 | var aNodes = a.ancestors(),
|
9121 | bNodes = b.ancestors(),
|
9122 | c = null;
|
9123 | a = aNodes.pop();
|
9124 | b = bNodes.pop();
|
9125 | while (a === b) {
|
9126 | c = a;
|
9127 | a = aNodes.pop();
|
9128 | b = bNodes.pop();
|
9129 | }
|
9130 | return c;
|
9131 | }
|
9132 |
|
9133 | function node_ancestors() {
|
9134 | var node = this, nodes = [node];
|
9135 | while (node = node.parent) {
|
9136 | nodes.push(node);
|
9137 | }
|
9138 | return nodes;
|
9139 | }
|
9140 |
|
9141 | function node_descendants() {
|
9142 | var nodes = [];
|
9143 | this.each(function(node) {
|
9144 | nodes.push(node);
|
9145 | });
|
9146 | return nodes;
|
9147 | }
|
9148 |
|
9149 | function node_leaves() {
|
9150 | var leaves = [];
|
9151 | this.eachBefore(function(node) {
|
9152 | if (!node.children) {
|
9153 | leaves.push(node);
|
9154 | }
|
9155 | });
|
9156 | return leaves;
|
9157 | }
|
9158 |
|
9159 | function node_links() {
|
9160 | var root = this, links = [];
|
9161 | root.each(function(node) {
|
9162 | if (node !== root) { // Don’t include the root’s parent, if any.
|
9163 | links.push({source: node.parent, target: node});
|
9164 | }
|
9165 | });
|
9166 | return links;
|
9167 | }
|
9168 |
|
9169 | function hierarchy(data, children) {
|
9170 | var root = new Node(data),
|
9171 | valued = +data.value && (root.value = data.value),
|
9172 | node,
|
9173 | nodes = [root],
|
9174 | child,
|
9175 | childs,
|
9176 | i,
|
9177 | n;
|
9178 |
|
9179 | if (children == null) children = defaultChildren;
|
9180 |
|
9181 | while (node = nodes.pop()) {
|
9182 | if (valued) node.value = +node.data.value;
|
9183 | if ((childs = children(node.data)) && (n = childs.length)) {
|
9184 | node.children = new Array(n);
|
9185 | for (i = n - 1; i >= 0; --i) {
|
9186 | nodes.push(child = node.children[i] = new Node(childs[i]));
|
9187 | child.parent = node;
|
9188 | child.depth = node.depth + 1;
|
9189 | }
|
9190 | }
|
9191 | }
|
9192 |
|
9193 | return root.eachBefore(computeHeight);
|
9194 | }
|
9195 |
|
9196 | function node_copy() {
|
9197 | return hierarchy(this).eachBefore(copyData);
|
9198 | }
|
9199 |
|
9200 | function defaultChildren(d) {
|
9201 | return d.children;
|
9202 | }
|
9203 |
|
9204 | function copyData(node) {
|
9205 | node.data = node.data.data;
|
9206 | }
|
9207 |
|
9208 | function computeHeight(node) {
|
9209 | var height = 0;
|
9210 | do node.height = height;
|
9211 | while ((node = node.parent) && (node.height < ++height));
|
9212 | }
|
9213 |
|
9214 | function Node(data) {
|
9215 | this.data = data;
|
9216 | this.depth =
|
9217 | this.height = 0;
|
9218 | this.parent = null;
|
9219 | }
|
9220 |
|
9221 | Node.prototype = hierarchy.prototype = {
|
9222 | constructor: Node,
|
9223 | each: node_each,
|
9224 | eachAfter: node_eachAfter,
|
9225 | eachBefore: node_eachBefore,
|
9226 | sum: node_sum,
|
9227 | sort: node_sort,
|
9228 | path: node_path,
|
9229 | ancestors: node_ancestors,
|
9230 | descendants: node_descendants,
|
9231 | leaves: node_leaves,
|
9232 | links: node_links,
|
9233 | copy: node_copy
|
9234 | };
|
9235 |
|
9236 | function Node$2(value) {
|
9237 | this._ = value;
|
9238 | this.next = null;
|
9239 | }
|
9240 |
|
9241 | function shuffle$1(array) {
|
9242 | var i,
|
9243 | n = (array = array.slice()).length,
|
9244 | head = null,
|
9245 | node = head;
|
9246 |
|
9247 | while (n) {
|
9248 | var next = new Node$2(array[n - 1]);
|
9249 | if (node) node = node.next = next;
|
9250 | else node = head = next;
|
9251 | array[i] = array[--n];
|
9252 | }
|
9253 |
|
9254 | return {
|
9255 | head: head,
|
9256 | tail: node
|
9257 | };
|
9258 | }
|
9259 |
|
9260 | function enclose(circles) {
|
9261 | return encloseN(shuffle$1(circles), []);
|
9262 | }
|
9263 |
|
9264 | function encloses(a, b) {
|
9265 | var dx = b.x - a.x,
|
9266 | dy = b.y - a.y,
|
9267 | dr = a.r - b.r;
|
9268 | return dr * dr + 1e-6 > dx * dx + dy * dy;
|
9269 | }
|
9270 |
|
9271 | // Returns the smallest circle that contains circles L and intersects circles B.
|
9272 | function encloseN(L, B) {
|
9273 | var circle,
|
9274 | l0 = null,
|
9275 | l1 = L.head,
|
9276 | l2,
|
9277 | p1;
|
9278 |
|
9279 | switch (B.length) {
|
9280 | case 1: circle = enclose1(B[0]); break;
|
9281 | case 2: circle = enclose2(B[0], B[1]); break;
|
9282 | case 3: circle = enclose3(B[0], B[1], B[2]); break;
|
9283 | }
|
9284 |
|
9285 | while (l1) {
|
9286 | p1 = l1._, l2 = l1.next;
|
9287 | if (!circle || !encloses(circle, p1)) {
|
9288 |
|
9289 | // Temporarily truncate L before l1.
|
9290 | if (l0) L.tail = l0, l0.next = null;
|
9291 | else L.head = L.tail = null;
|
9292 |
|
9293 | B.push(p1);
|
9294 | circle = encloseN(L, B); // Note: reorders L!
|
9295 | B.pop();
|
9296 |
|
9297 | // Move l1 to the front of L and reconnect the truncated list L.
|
9298 | if (L.head) l1.next = L.head, L.head = l1;
|
9299 | else l1.next = null, L.head = L.tail = l1;
|
9300 | l0 = L.tail, l0.next = l2;
|
9301 |
|
9302 | } else {
|
9303 | l0 = l1;
|
9304 | }
|
9305 | l1 = l2;
|
9306 | }
|
9307 |
|
9308 | L.tail = l0;
|
9309 | return circle;
|
9310 | }
|
9311 |
|
9312 | function enclose1(a) {
|
9313 | return {
|
9314 | x: a.x,
|
9315 | y: a.y,
|
9316 | r: a.r
|
9317 | };
|
9318 | }
|
9319 |
|
9320 | function enclose2(a, b) {
|
9321 | var x1 = a.x, y1 = a.y, r1 = a.r,
|
9322 | x2 = b.x, y2 = b.y, r2 = b.r,
|
9323 | x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
|
9324 | l = Math.sqrt(x21 * x21 + y21 * y21);
|
9325 | return {
|
9326 | x: (x1 + x2 + x21 / l * r21) / 2,
|
9327 | y: (y1 + y2 + y21 / l * r21) / 2,
|
9328 | r: (l + r1 + r2) / 2
|
9329 | };
|
9330 | }
|
9331 |
|
9332 | function enclose3(a, b, c) {
|
9333 | var x1 = a.x, y1 = a.y, r1 = a.r,
|
9334 | x2 = b.x, y2 = b.y, r2 = b.r,
|
9335 | x3 = c.x, y3 = c.y, r3 = c.r,
|
9336 | a2 = 2 * (x1 - x2),
|
9337 | b2 = 2 * (y1 - y2),
|
9338 | c2 = 2 * (r2 - r1),
|
9339 | d2 = x1 * x1 + y1 * y1 - r1 * r1 - x2 * x2 - y2 * y2 + r2 * r2,
|
9340 | a3 = 2 * (x1 - x3),
|
9341 | b3 = 2 * (y1 - y3),
|
9342 | c3 = 2 * (r3 - r1),
|
9343 | d3 = x1 * x1 + y1 * y1 - r1 * r1 - x3 * x3 - y3 * y3 + r3 * r3,
|
9344 | ab = a3 * b2 - a2 * b3,
|
9345 | xa = (b2 * d3 - b3 * d2) / ab - x1,
|
9346 | xb = (b3 * c2 - b2 * c3) / ab,
|
9347 | ya = (a3 * d2 - a2 * d3) / ab - y1,
|
9348 | yb = (a2 * c3 - a3 * c2) / ab,
|
9349 | A = xb * xb + yb * yb - 1,
|
9350 | B = 2 * (xa * xb + ya * yb + r1),
|
9351 | C = xa * xa + ya * ya - r1 * r1,
|
9352 | r = (-B - Math.sqrt(B * B - 4 * A * C)) / (2 * A);
|
9353 | return {
|
9354 | x: xa + xb * r + x1,
|
9355 | y: ya + yb * r + y1,
|
9356 | r: r
|
9357 | };
|
9358 | }
|
9359 |
|
9360 | function place(a, b, c) {
|
9361 | var ax = a.x,
|
9362 | ay = a.y,
|
9363 | da = b.r + c.r,
|
9364 | db = a.r + c.r,
|
9365 | dx = b.x - ax,
|
9366 | dy = b.y - ay,
|
9367 | dc = dx * dx + dy * dy;
|
9368 | if (dc) {
|
9369 | var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
|
9370 | y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
|
9371 | c.x = ax + x * dx + y * dy;
|
9372 | c.y = ay + x * dy - y * dx;
|
9373 | } else {
|
9374 | c.x = ax + db;
|
9375 | c.y = ay;
|
9376 | }
|
9377 | }
|
9378 |
|
9379 | function intersects(a, b) {
|
9380 | var dx = b.x - a.x,
|
9381 | dy = b.y - a.y,
|
9382 | dr = a.r + b.r;
|
9383 | return dr * dr > dx * dx + dy * dy;
|
9384 | }
|
9385 |
|
9386 | function distance2(circle, x, y) {
|
9387 | var dx = circle.x - x,
|
9388 | dy = circle.y - y;
|
9389 | return dx * dx + dy * dy;
|
9390 | }
|
9391 |
|
9392 | function Node$1(circle) {
|
9393 | this._ = circle;
|
9394 | this.next = null;
|
9395 | this.previous = null;
|
9396 | }
|
9397 |
|
9398 | function packEnclose(circles) {
|
9399 | if (!(n = circles.length)) return 0;
|
9400 |
|
9401 | var a, b, c, n;
|
9402 |
|
9403 | // Place the first circle.
|
9404 | a = circles[0], a.x = 0, a.y = 0;
|
9405 | if (!(n > 1)) return a.r;
|
9406 |
|
9407 | // Place the second circle.
|
9408 | b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
|
9409 | if (!(n > 2)) return a.r + b.r;
|
9410 |
|
9411 | // Place the third circle.
|
9412 | place(b, a, c = circles[2]);
|
9413 |
|
9414 | // Initialize the weighted centroid.
|
9415 | var aa = a.r * a.r,
|
9416 | ba = b.r * b.r,
|
9417 | ca = c.r * c.r,
|
9418 | oa = aa + ba + ca,
|
9419 | ox = aa * a.x + ba * b.x + ca * c.x,
|
9420 | oy = aa * a.y + ba * b.y + ca * c.y,
|
9421 | cx, cy, i, j, k, sj, sk;
|
9422 |
|
9423 | // Initialize the front-chain using the first three circles a, b and c.
|
9424 | a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
|
9425 | a.next = c.previous = b;
|
9426 | b.next = a.previous = c;
|
9427 | c.next = b.previous = a;
|
9428 |
|
9429 | // Attempt to place each remaining circle…
|
9430 | pack: for (i = 3; i < n; ++i) {
|
9431 | place(a._, b._, c = circles[i]), c = new Node$1(c);
|
9432 |
|
9433 | // If there are only three elements in the front-chain…
|
9434 | if ((k = a.previous) === (j = b.next)) {
|
9435 | // If the new circle intersects the third circle,
|
9436 | // rotate the front chain to try the next position.
|
9437 | if (intersects(j._, c._)) {
|
9438 | a = b, b = j, --i;
|
9439 | continue pack;
|
9440 | }
|
9441 | }
|
9442 |
|
9443 | // Find the closest intersecting circle on the front-chain, if any.
|
9444 | else {
|
9445 | sj = j._.r, sk = k._.r;
|
9446 | do {
|
9447 | if (sj <= sk) {
|
9448 | if (intersects(j._, c._)) {
|
9449 | b = j, a.next = b, b.previous = a, --i;
|
9450 | continue pack;
|
9451 | }
|
9452 | j = j.next, sj += j._.r;
|
9453 | } else {
|
9454 | if (intersects(k._, c._)) {
|
9455 | a = k, a.next = b, b.previous = a, --i;
|
9456 | continue pack;
|
9457 | }
|
9458 | k = k.previous, sk += k._.r;
|
9459 | }
|
9460 | } while (j !== k.next);
|
9461 | }
|
9462 |
|
9463 | // Success! Insert the new circle c between a and b.
|
9464 | c.previous = a, c.next = b, a.next = b.previous = b = c;
|
9465 |
|
9466 | // Update the weighted centroid.
|
9467 | oa += ca = c._.r * c._.r;
|
9468 | ox += ca * c._.x;
|
9469 | oy += ca * c._.y;
|
9470 |
|
9471 | // Compute the new closest circle a to centroid.
|
9472 | aa = distance2(a._, cx = ox / oa, cy = oy / oa);
|
9473 | while ((c = c.next) !== b) {
|
9474 | if ((ca = distance2(c._, cx, cy)) < aa) {
|
9475 | a = c, aa = ca;
|
9476 | }
|
9477 | }
|
9478 | b = a.next;
|
9479 | }
|
9480 |
|
9481 | // Compute the enclosing circle of the front chain.
|
9482 | a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
|
9483 |
|
9484 | // Translate the circles to put the enclosing circle around the origin.
|
9485 | for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
|
9486 |
|
9487 | return c.r;
|
9488 | }
|
9489 |
|
9490 | function siblings(circles) {
|
9491 | packEnclose(circles);
|
9492 | return circles;
|
9493 | }
|
9494 |
|
9495 | function optional(f) {
|
9496 | return f == null ? null : required(f);
|
9497 | }
|
9498 |
|
9499 | function required(f) {
|
9500 | if (typeof f !== "function") throw new Error;
|
9501 | return f;
|
9502 | }
|
9503 |
|
9504 | function constantZero() {
|
9505 | return 0;
|
9506 | }
|
9507 |
|
9508 | function constant$5(x) {
|
9509 | return function() {
|
9510 | return x;
|
9511 | };
|
9512 | }
|
9513 |
|
9514 | function defaultRadius(d) {
|
9515 | return Math.sqrt(d.value);
|
9516 | }
|
9517 |
|
9518 | function index() {
|
9519 | var radius = null,
|
9520 | dx = 1,
|
9521 | dy = 1,
|
9522 | padding = constantZero;
|
9523 |
|
9524 | function pack(root) {
|
9525 | root.x = dx / 2, root.y = dy / 2;
|
9526 | if (radius) {
|
9527 | root.eachBefore(radiusLeaf(radius))
|
9528 | .eachAfter(packChildren(padding, 0.5))
|
9529 | .eachBefore(translateChild(1));
|
9530 | } else {
|
9531 | root.eachBefore(radiusLeaf(defaultRadius))
|
9532 | .eachAfter(packChildren(constantZero, 1))
|
9533 | .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
|
9534 | .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
|
9535 | }
|
9536 | return root;
|
9537 | }
|
9538 |
|
9539 | pack.radius = function(x) {
|
9540 | return arguments.length ? (radius = optional(x), pack) : radius;
|
9541 | };
|
9542 |
|
9543 | pack.size = function(x) {
|
9544 | return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
|
9545 | };
|
9546 |
|
9547 | pack.padding = function(x) {
|
9548 | return arguments.length ? (padding = typeof x === "function" ? x : constant$5(+x), pack) : padding;
|
9549 | };
|
9550 |
|
9551 | return pack;
|
9552 | }
|
9553 |
|
9554 | function radiusLeaf(radius) {
|
9555 | return function(node) {
|
9556 | if (!node.children) {
|
9557 | node.r = Math.max(0, +radius(node) || 0);
|
9558 | }
|
9559 | };
|
9560 | }
|
9561 |
|
9562 | function packChildren(padding, k) {
|
9563 | return function(node) {
|
9564 | if (children = node.children) {
|
9565 | var children,
|
9566 | i,
|
9567 | n = children.length,
|
9568 | r = padding(node) * k || 0,
|
9569 | e;
|
9570 |
|
9571 | if (r) for (i = 0; i < n; ++i) children[i].r += r;
|
9572 | e = packEnclose(children);
|
9573 | if (r) for (i = 0; i < n; ++i) children[i].r -= r;
|
9574 | node.r = e + r;
|
9575 | }
|
9576 | };
|
9577 | }
|
9578 |
|
9579 | function translateChild(k) {
|
9580 | return function(node) {
|
9581 | var parent = node.parent;
|
9582 | node.r *= k;
|
9583 | if (parent) {
|
9584 | node.x = parent.x + k * node.x;
|
9585 | node.y = parent.y + k * node.y;
|
9586 | }
|
9587 | };
|
9588 | }
|
9589 |
|
9590 | function roundNode(node) {
|
9591 | node.x0 = Math.round(node.x0);
|
9592 | node.y0 = Math.round(node.y0);
|
9593 | node.x1 = Math.round(node.x1);
|
9594 | node.y1 = Math.round(node.y1);
|
9595 | }
|
9596 |
|
9597 | function treemapDice(parent, x0, y0, x1, y1) {
|
9598 | var nodes = parent.children,
|
9599 | node,
|
9600 | i = -1,
|
9601 | n = nodes.length,
|
9602 | k = parent.value && (x1 - x0) / parent.value;
|
9603 |
|
9604 | while (++i < n) {
|
9605 | node = nodes[i], node.y0 = y0, node.y1 = y1;
|
9606 | node.x0 = x0, node.x1 = x0 += node.value * k;
|
9607 | }
|
9608 | }
|
9609 |
|
9610 | function partition() {
|
9611 | var dx = 1,
|
9612 | dy = 1,
|
9613 | padding = 0,
|
9614 | round = false;
|
9615 |
|
9616 | function partition(root) {
|
9617 | var n = root.height + 1;
|
9618 | root.x0 =
|
9619 | root.y0 = padding;
|
9620 | root.x1 = dx;
|
9621 | root.y1 = dy / n;
|
9622 | root.eachBefore(positionNode(dy, n));
|
9623 | if (round) root.eachBefore(roundNode);
|
9624 | return root;
|
9625 | }
|
9626 |
|
9627 | function positionNode(dy, n) {
|
9628 | return function(node) {
|
9629 | if (node.children) {
|
9630 | treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
|
9631 | }
|
9632 | var x0 = node.x0,
|
9633 | y0 = node.y0,
|
9634 | x1 = node.x1 - padding,
|
9635 | y1 = node.y1 - padding;
|
9636 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
9637 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
9638 | node.x0 = x0;
|
9639 | node.y0 = y0;
|
9640 | node.x1 = x1;
|
9641 | node.y1 = y1;
|
9642 | };
|
9643 | }
|
9644 |
|
9645 | partition.round = function(x) {
|
9646 | return arguments.length ? (round = !!x, partition) : round;
|
9647 | };
|
9648 |
|
9649 | partition.size = function(x) {
|
9650 | return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
|
9651 | };
|
9652 |
|
9653 | partition.padding = function(x) {
|
9654 | return arguments.length ? (padding = +x, partition) : padding;
|
9655 | };
|
9656 |
|
9657 | return partition;
|
9658 | }
|
9659 |
|
9660 | var keyPrefix$1 = "$";
|
9661 | var preroot = {depth: -1};
|
9662 | var ambiguous = {};
|
9663 | function defaultId(d) {
|
9664 | return d.id;
|
9665 | }
|
9666 |
|
9667 | function defaultParentId(d) {
|
9668 | return d.parentId;
|
9669 | }
|
9670 |
|
9671 | function stratify() {
|
9672 | var id = defaultId,
|
9673 | parentId = defaultParentId;
|
9674 |
|
9675 | function stratify(data) {
|
9676 | var d,
|
9677 | i,
|
9678 | n = data.length,
|
9679 | root,
|
9680 | parent,
|
9681 | node,
|
9682 | nodes = new Array(n),
|
9683 | nodeId,
|
9684 | nodeKey,
|
9685 | nodeByKey = {};
|
9686 |
|
9687 | for (i = 0; i < n; ++i) {
|
9688 | d = data[i], node = nodes[i] = new Node(d);
|
9689 | if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
|
9690 | nodeKey = keyPrefix$1 + (node.id = nodeId);
|
9691 | nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
|
9692 | }
|
9693 | }
|
9694 |
|
9695 | for (i = 0; i < n; ++i) {
|
9696 | node = nodes[i], nodeId = parentId(data[i], i, data);
|
9697 | if (nodeId == null || !(nodeId += "")) {
|
9698 | if (root) throw new Error("multiple roots");
|
9699 | root = node;
|
9700 | } else {
|
9701 | parent = nodeByKey[keyPrefix$1 + nodeId];
|
9702 | if (!parent) throw new Error("missing: " + nodeId);
|
9703 | if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
|
9704 | if (parent.children) parent.children.push(node);
|
9705 | else parent.children = [node];
|
9706 | node.parent = parent;
|
9707 | }
|
9708 | }
|
9709 |
|
9710 | if (!root) throw new Error("no root");
|
9711 | root.parent = preroot;
|
9712 | root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
|
9713 | root.parent = null;
|
9714 | if (n > 0) throw new Error("cycle");
|
9715 |
|
9716 | return root;
|
9717 | }
|
9718 |
|
9719 | stratify.id = function(x) {
|
9720 | return arguments.length ? (id = required(x), stratify) : id;
|
9721 | };
|
9722 |
|
9723 | stratify.parentId = function(x) {
|
9724 | return arguments.length ? (parentId = required(x), stratify) : parentId;
|
9725 | };
|
9726 |
|
9727 | return stratify;
|
9728 | }
|
9729 |
|
9730 | function defaultSeparation$1(a, b) {
|
9731 | return a.parent === b.parent ? 1 : 2;
|
9732 | }
|
9733 |
|
9734 | // function radialSeparation(a, b) {
|
9735 | // return (a.parent === b.parent ? 1 : 2) / a.depth;
|
9736 | // }
|
9737 |
|
9738 | // This function is used to traverse the left contour of a subtree (or
|
9739 | // subforest). It returns the successor of v on this contour. This successor is
|
9740 | // either given by the leftmost child of v or by the thread of v. The function
|
9741 | // returns null if and only if v is on the highest level of its subtree.
|
9742 | function nextLeft(v) {
|
9743 | var children = v.children;
|
9744 | return children ? children[0] : v.t;
|
9745 | }
|
9746 |
|
9747 | // This function works analogously to nextLeft.
|
9748 | function nextRight(v) {
|
9749 | var children = v.children;
|
9750 | return children ? children[children.length - 1] : v.t;
|
9751 | }
|
9752 |
|
9753 | // Shifts the current subtree rooted at w+. This is done by increasing
|
9754 | // prelim(w+) and mod(w+) by shift.
|
9755 | function moveSubtree(wm, wp, shift) {
|
9756 | var change = shift / (wp.i - wm.i);
|
9757 | wp.c -= change;
|
9758 | wp.s += shift;
|
9759 | wm.c += change;
|
9760 | wp.z += shift;
|
9761 | wp.m += shift;
|
9762 | }
|
9763 |
|
9764 | // All other shifts, applied to the smaller subtrees between w- and w+, are
|
9765 | // performed by this function. To prepare the shifts, we have to adjust
|
9766 | // change(w+), shift(w+), and change(w-).
|
9767 | function executeShifts(v) {
|
9768 | var shift = 0,
|
9769 | change = 0,
|
9770 | children = v.children,
|
9771 | i = children.length,
|
9772 | w;
|
9773 | while (--i >= 0) {
|
9774 | w = children[i];
|
9775 | w.z += shift;
|
9776 | w.m += shift;
|
9777 | shift += w.s + (change += w.c);
|
9778 | }
|
9779 | }
|
9780 |
|
9781 | // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
|
9782 | // returns the specified (default) ancestor.
|
9783 | function nextAncestor(vim, v, ancestor) {
|
9784 | return vim.a.parent === v.parent ? vim.a : ancestor;
|
9785 | }
|
9786 |
|
9787 | function TreeNode(node, i) {
|
9788 | this._ = node;
|
9789 | this.parent = null;
|
9790 | this.children = null;
|
9791 | this.A = null; // default ancestor
|
9792 | this.a = this; // ancestor
|
9793 | this.z = 0; // prelim
|
9794 | this.m = 0; // mod
|
9795 | this.c = 0; // change
|
9796 | this.s = 0; // shift
|
9797 | this.t = null; // thread
|
9798 | this.i = i; // number
|
9799 | }
|
9800 |
|
9801 | TreeNode.prototype = Object.create(Node.prototype);
|
9802 |
|
9803 | function treeRoot(root) {
|
9804 | var tree = new TreeNode(root, 0),
|
9805 | node,
|
9806 | nodes = [tree],
|
9807 | child,
|
9808 | children,
|
9809 | i,
|
9810 | n;
|
9811 |
|
9812 | while (node = nodes.pop()) {
|
9813 | if (children = node._.children) {
|
9814 | node.children = new Array(n = children.length);
|
9815 | for (i = n - 1; i >= 0; --i) {
|
9816 | nodes.push(child = node.children[i] = new TreeNode(children[i], i));
|
9817 | child.parent = node;
|
9818 | }
|
9819 | }
|
9820 | }
|
9821 |
|
9822 | (tree.parent = new TreeNode(null, 0)).children = [tree];
|
9823 | return tree;
|
9824 | }
|
9825 |
|
9826 | // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
|
9827 | function tree() {
|
9828 | var separation = defaultSeparation$1,
|
9829 | dx = 1,
|
9830 | dy = 1,
|
9831 | nodeSize = null;
|
9832 |
|
9833 | function tree(root) {
|
9834 | var t = treeRoot(root);
|
9835 |
|
9836 | // Compute the layout using Buchheim et al.’s algorithm.
|
9837 | t.eachAfter(firstWalk), t.parent.m = -t.z;
|
9838 | t.eachBefore(secondWalk);
|
9839 |
|
9840 | // If a fixed node size is specified, scale x and y.
|
9841 | if (nodeSize) root.eachBefore(sizeNode);
|
9842 |
|
9843 | // If a fixed tree size is specified, scale x and y based on the extent.
|
9844 | // Compute the left-most, right-most, and depth-most nodes for extents.
|
9845 | else {
|
9846 | var left = root,
|
9847 | right = root,
|
9848 | bottom = root;
|
9849 | root.eachBefore(function(node) {
|
9850 | if (node.x < left.x) left = node;
|
9851 | if (node.x > right.x) right = node;
|
9852 | if (node.depth > bottom.depth) bottom = node;
|
9853 | });
|
9854 | var s = left === right ? 1 : separation(left, right) / 2,
|
9855 | tx = s - left.x,
|
9856 | kx = dx / (right.x + s + tx),
|
9857 | ky = dy / (bottom.depth || 1);
|
9858 | root.eachBefore(function(node) {
|
9859 | node.x = (node.x + tx) * kx;
|
9860 | node.y = node.depth * ky;
|
9861 | });
|
9862 | }
|
9863 |
|
9864 | return root;
|
9865 | }
|
9866 |
|
9867 | // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
|
9868 | // applied recursively to the children of v, as well as the function
|
9869 | // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
|
9870 | // node v is placed to the midpoint of its outermost children.
|
9871 | function firstWalk(v) {
|
9872 | var children = v.children,
|
9873 | siblings = v.parent.children,
|
9874 | w = v.i ? siblings[v.i - 1] : null;
|
9875 | if (children) {
|
9876 | executeShifts(v);
|
9877 | var midpoint = (children[0].z + children[children.length - 1].z) / 2;
|
9878 | if (w) {
|
9879 | v.z = w.z + separation(v._, w._);
|
9880 | v.m = v.z - midpoint;
|
9881 | } else {
|
9882 | v.z = midpoint;
|
9883 | }
|
9884 | } else if (w) {
|
9885 | v.z = w.z + separation(v._, w._);
|
9886 | }
|
9887 | v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
|
9888 | }
|
9889 |
|
9890 | // Computes all real x-coordinates by summing up the modifiers recursively.
|
9891 | function secondWalk(v) {
|
9892 | v._.x = v.z + v.parent.m;
|
9893 | v.m += v.parent.m;
|
9894 | }
|
9895 |
|
9896 | // The core of the algorithm. Here, a new subtree is combined with the
|
9897 | // previous subtrees. Threads are used to traverse the inside and outside
|
9898 | // contours of the left and right subtree up to the highest common level. The
|
9899 | // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
|
9900 | // superscript o means outside and i means inside, the subscript - means left
|
9901 | // subtree and + means right subtree. For summing up the modifiers along the
|
9902 | // contour, we use respective variables si+, si-, so-, and so+. Whenever two
|
9903 | // nodes of the inside contours conflict, we compute the left one of the
|
9904 | // greatest uncommon ancestors using the function ANCESTOR and call MOVE
|
9905 | // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
|
9906 | // Finally, we add a new thread (if necessary).
|
9907 | function apportion(v, w, ancestor) {
|
9908 | if (w) {
|
9909 | var vip = v,
|
9910 | vop = v,
|
9911 | vim = w,
|
9912 | vom = vip.parent.children[0],
|
9913 | sip = vip.m,
|
9914 | sop = vop.m,
|
9915 | sim = vim.m,
|
9916 | som = vom.m,
|
9917 | shift;
|
9918 | while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
|
9919 | vom = nextLeft(vom);
|
9920 | vop = nextRight(vop);
|
9921 | vop.a = v;
|
9922 | shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
|
9923 | if (shift > 0) {
|
9924 | moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
|
9925 | sip += shift;
|
9926 | sop += shift;
|
9927 | }
|
9928 | sim += vim.m;
|
9929 | sip += vip.m;
|
9930 | som += vom.m;
|
9931 | sop += vop.m;
|
9932 | }
|
9933 | if (vim && !nextRight(vop)) {
|
9934 | vop.t = vim;
|
9935 | vop.m += sim - sop;
|
9936 | }
|
9937 | if (vip && !nextLeft(vom)) {
|
9938 | vom.t = vip;
|
9939 | vom.m += sip - som;
|
9940 | ancestor = v;
|
9941 | }
|
9942 | }
|
9943 | return ancestor;
|
9944 | }
|
9945 |
|
9946 | function sizeNode(node) {
|
9947 | node.x *= dx;
|
9948 | node.y = node.depth * dy;
|
9949 | }
|
9950 |
|
9951 | tree.separation = function(x) {
|
9952 | return arguments.length ? (separation = x, tree) : separation;
|
9953 | };
|
9954 |
|
9955 | tree.size = function(x) {
|
9956 | return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
|
9957 | };
|
9958 |
|
9959 | tree.nodeSize = function(x) {
|
9960 | return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
|
9961 | };
|
9962 |
|
9963 | return tree;
|
9964 | }
|
9965 |
|
9966 | function treemapSlice(parent, x0, y0, x1, y1) {
|
9967 | var nodes = parent.children,
|
9968 | node,
|
9969 | i = -1,
|
9970 | n = nodes.length,
|
9971 | k = parent.value && (y1 - y0) / parent.value;
|
9972 |
|
9973 | while (++i < n) {
|
9974 | node = nodes[i], node.x0 = x0, node.x1 = x1;
|
9975 | node.y0 = y0, node.y1 = y0 += node.value * k;
|
9976 | }
|
9977 | }
|
9978 |
|
9979 | var phi = (1 + Math.sqrt(5)) / 2;
|
9980 |
|
9981 | function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
|
9982 | var rows = [],
|
9983 | nodes = parent.children,
|
9984 | row,
|
9985 | nodeValue,
|
9986 | i0 = 0,
|
9987 | i1,
|
9988 | n = nodes.length,
|
9989 | dx, dy,
|
9990 | value = parent.value,
|
9991 | sumValue,
|
9992 | minValue,
|
9993 | maxValue,
|
9994 | newRatio,
|
9995 | minRatio,
|
9996 | alpha,
|
9997 | beta;
|
9998 |
|
9999 | while (i0 < n) {
|
10000 | dx = x1 - x0, dy = y1 - y0;
|
10001 | minValue = maxValue = sumValue = nodes[i0].value;
|
10002 | alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
|
10003 | beta = sumValue * sumValue * alpha;
|
10004 | minRatio = Math.max(maxValue / beta, beta / minValue);
|
10005 |
|
10006 | // Keep adding nodes while the aspect ratio maintains or improves.
|
10007 | for (i1 = i0 + 1; i1 < n; ++i1) {
|
10008 | sumValue += nodeValue = nodes[i1].value;
|
10009 | if (nodeValue < minValue) minValue = nodeValue;
|
10010 | if (nodeValue > maxValue) maxValue = nodeValue;
|
10011 | beta = sumValue * sumValue * alpha;
|
10012 | newRatio = Math.max(maxValue / beta, beta / minValue);
|
10013 | if (newRatio > minRatio) { sumValue -= nodeValue; break; }
|
10014 | minRatio = newRatio;
|
10015 | }
|
10016 |
|
10017 | // Position and record the row orientation.
|
10018 | rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
|
10019 | if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
|
10020 | else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
|
10021 | value -= sumValue, i0 = i1;
|
10022 | }
|
10023 |
|
10024 | return rows;
|
10025 | }
|
10026 |
|
10027 | var squarify = (function custom(ratio) {
|
10028 |
|
10029 | function squarify(parent, x0, y0, x1, y1) {
|
10030 | squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
10031 | }
|
10032 |
|
10033 | squarify.ratio = function(x) {
|
10034 | return custom((x = +x) > 1 ? x : 1);
|
10035 | };
|
10036 |
|
10037 | return squarify;
|
10038 | })(phi);
|
10039 |
|
10040 | function index$1() {
|
10041 | var tile = squarify,
|
10042 | round = false,
|
10043 | dx = 1,
|
10044 | dy = 1,
|
10045 | paddingStack = [0],
|
10046 | paddingInner = constantZero,
|
10047 | paddingTop = constantZero,
|
10048 | paddingRight = constantZero,
|
10049 | paddingBottom = constantZero,
|
10050 | paddingLeft = constantZero;
|
10051 |
|
10052 | function treemap(root) {
|
10053 | root.x0 =
|
10054 | root.y0 = 0;
|
10055 | root.x1 = dx;
|
10056 | root.y1 = dy;
|
10057 | root.eachBefore(positionNode);
|
10058 | paddingStack = [0];
|
10059 | if (round) root.eachBefore(roundNode);
|
10060 | return root;
|
10061 | }
|
10062 |
|
10063 | function positionNode(node) {
|
10064 | var p = paddingStack[node.depth],
|
10065 | x0 = node.x0 + p,
|
10066 | y0 = node.y0 + p,
|
10067 | x1 = node.x1 - p,
|
10068 | y1 = node.y1 - p;
|
10069 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
10070 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
10071 | node.x0 = x0;
|
10072 | node.y0 = y0;
|
10073 | node.x1 = x1;
|
10074 | node.y1 = y1;
|
10075 | if (node.children) {
|
10076 | p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
|
10077 | x0 += paddingLeft(node) - p;
|
10078 | y0 += paddingTop(node) - p;
|
10079 | x1 -= paddingRight(node) - p;
|
10080 | y1 -= paddingBottom(node) - p;
|
10081 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
10082 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
10083 | tile(node, x0, y0, x1, y1);
|
10084 | }
|
10085 | }
|
10086 |
|
10087 | treemap.round = function(x) {
|
10088 | return arguments.length ? (round = !!x, treemap) : round;
|
10089 | };
|
10090 |
|
10091 | treemap.size = function(x) {
|
10092 | return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
|
10093 | };
|
10094 |
|
10095 | treemap.tile = function(x) {
|
10096 | return arguments.length ? (tile = required(x), treemap) : tile;
|
10097 | };
|
10098 |
|
10099 | treemap.padding = function(x) {
|
10100 | return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
|
10101 | };
|
10102 |
|
10103 | treemap.paddingInner = function(x) {
|
10104 | return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$5(+x), treemap) : paddingInner;
|
10105 | };
|
10106 |
|
10107 | treemap.paddingOuter = function(x) {
|
10108 | return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
|
10109 | };
|
10110 |
|
10111 | treemap.paddingTop = function(x) {
|
10112 | return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$5(+x), treemap) : paddingTop;
|
10113 | };
|
10114 |
|
10115 | treemap.paddingRight = function(x) {
|
10116 | return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$5(+x), treemap) : paddingRight;
|
10117 | };
|
10118 |
|
10119 | treemap.paddingBottom = function(x) {
|
10120 | return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$5(+x), treemap) : paddingBottom;
|
10121 | };
|
10122 |
|
10123 | treemap.paddingLeft = function(x) {
|
10124 | return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$5(+x), treemap) : paddingLeft;
|
10125 | };
|
10126 |
|
10127 | return treemap;
|
10128 | }
|
10129 |
|
10130 | function binary(parent, x0, y0, x1, y1) {
|
10131 | var nodes = parent.children,
|
10132 | i, n = nodes.length,
|
10133 | sum, sums = new Array(n + 1);
|
10134 |
|
10135 | for (sums[0] = sum = i = 0; i < n; ++i) {
|
10136 | sums[i + 1] = sum += nodes[i].value;
|
10137 | }
|
10138 |
|
10139 | partition(0, n, parent.value, x0, y0, x1, y1);
|
10140 |
|
10141 | function partition(i, j, value, x0, y0, x1, y1) {
|
10142 | if (i >= j - 1) {
|
10143 | var node = nodes[i];
|
10144 | node.x0 = x0, node.y0 = y0;
|
10145 | node.x1 = x1, node.y1 = y1;
|
10146 | return;
|
10147 | }
|
10148 |
|
10149 | var valueOffset = sums[i],
|
10150 | valueTarget = (value / 2) + valueOffset,
|
10151 | k = i + 1,
|
10152 | hi = j - 1;
|
10153 |
|
10154 | while (k < hi) {
|
10155 | var mid = k + hi >>> 1;
|
10156 | if (sums[mid] < valueTarget) k = mid + 1;
|
10157 | else hi = mid;
|
10158 | }
|
10159 |
|
10160 | var valueLeft = sums[k] - valueOffset,
|
10161 | valueRight = value - valueLeft;
|
10162 |
|
10163 | if ((y1 - y0) > (x1 - x0)) {
|
10164 | var yk = (y0 * valueRight + y1 * valueLeft) / value;
|
10165 | partition(i, k, valueLeft, x0, y0, x1, yk);
|
10166 | partition(k, j, valueRight, x0, yk, x1, y1);
|
10167 | } else {
|
10168 | var xk = (x0 * valueRight + x1 * valueLeft) / value;
|
10169 | partition(i, k, valueLeft, x0, y0, xk, y1);
|
10170 | partition(k, j, valueRight, xk, y0, x1, y1);
|
10171 | }
|
10172 | }
|
10173 | }
|
10174 |
|
10175 | function sliceDice(parent, x0, y0, x1, y1) {
|
10176 | (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
|
10177 | }
|
10178 |
|
10179 | var resquarify = (function custom(ratio) {
|
10180 |
|
10181 | function resquarify(parent, x0, y0, x1, y1) {
|
10182 | if ((rows = parent._squarify) && (rows.ratio === ratio)) {
|
10183 | var rows,
|
10184 | row,
|
10185 | nodes,
|
10186 | i,
|
10187 | j = -1,
|
10188 | n,
|
10189 | m = rows.length,
|
10190 | value = parent.value;
|
10191 |
|
10192 | while (++j < m) {
|
10193 | row = rows[j], nodes = row.children;
|
10194 | for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
|
10195 | if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
|
10196 | else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
|
10197 | value -= row.value;
|
10198 | }
|
10199 | } else {
|
10200 | parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
10201 | rows.ratio = ratio;
|
10202 | }
|
10203 | }
|
10204 |
|
10205 | resquarify.ratio = function(x) {
|
10206 | return custom((x = +x) > 1 ? x : 1);
|
10207 | };
|
10208 |
|
10209 | return resquarify;
|
10210 | })(phi);
|
10211 |
|
10212 | function center$1(x, y) {
|
10213 | var nodes;
|
10214 |
|
10215 | if (x == null) x = 0;
|
10216 | if (y == null) y = 0;
|
10217 |
|
10218 | function force() {
|
10219 | var i,
|
10220 | n = nodes.length,
|
10221 | node,
|
10222 | sx = 0,
|
10223 | sy = 0;
|
10224 |
|
10225 | for (i = 0; i < n; ++i) {
|
10226 | node = nodes[i], sx += node.x, sy += node.y;
|
10227 | }
|
10228 |
|
10229 | for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
|
10230 | node = nodes[i], node.x -= sx, node.y -= sy;
|
10231 | }
|
10232 | }
|
10233 |
|
10234 | force.initialize = function(_) {
|
10235 | nodes = _;
|
10236 | };
|
10237 |
|
10238 | force.x = function(_) {
|
10239 | return arguments.length ? (x = +_, force) : x;
|
10240 | };
|
10241 |
|
10242 | force.y = function(_) {
|
10243 | return arguments.length ? (y = +_, force) : y;
|
10244 | };
|
10245 |
|
10246 | return force;
|
10247 | }
|
10248 |
|
10249 | function constant$6(x) {
|
10250 | return function() {
|
10251 | return x;
|
10252 | };
|
10253 | }
|
10254 |
|
10255 | function jiggle() {
|
10256 | return (Math.random() - 0.5) * 1e-6;
|
10257 | }
|
10258 |
|
10259 | function x$1(d) {
|
10260 | return d.x + d.vx;
|
10261 | }
|
10262 |
|
10263 | function y$1(d) {
|
10264 | return d.y + d.vy;
|
10265 | }
|
10266 |
|
10267 | function collide(radius) {
|
10268 | var nodes,
|
10269 | radii,
|
10270 | strength = 1,
|
10271 | iterations = 1;
|
10272 |
|
10273 | if (typeof radius !== "function") radius = constant$6(radius == null ? 1 : +radius);
|
10274 |
|
10275 | function force() {
|
10276 | var i, n = nodes.length,
|
10277 | tree,
|
10278 | node,
|
10279 | xi,
|
10280 | yi,
|
10281 | ri,
|
10282 | ri2;
|
10283 |
|
10284 | for (var k = 0; k < iterations; ++k) {
|
10285 | tree = quadtree(nodes, x$1, y$1).visitAfter(prepare);
|
10286 | for (i = 0; i < n; ++i) {
|
10287 | node = nodes[i];
|
10288 | ri = radii[i], ri2 = ri * ri;
|
10289 | xi = node.x + node.vx;
|
10290 | yi = node.y + node.vy;
|
10291 | tree.visit(apply);
|
10292 | }
|
10293 | }
|
10294 |
|
10295 | function apply(quad, x0, y0, x1, y1) {
|
10296 | var data = quad.data, rj = quad.r, r = ri + rj;
|
10297 | if (data) {
|
10298 | if (data.index > i) {
|
10299 | var x = xi - data.x - data.vx,
|
10300 | y = yi - data.y - data.vy,
|
10301 | l = x * x + y * y;
|
10302 | if (l < r * r) {
|
10303 | if (x === 0) x = jiggle(), l += x * x;
|
10304 | if (y === 0) y = jiggle(), l += y * y;
|
10305 | l = (r - (l = Math.sqrt(l))) / l * strength;
|
10306 | node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
|
10307 | node.vy += (y *= l) * r;
|
10308 | data.vx -= x * (r = 1 - r);
|
10309 | data.vy -= y * r;
|
10310 | }
|
10311 | }
|
10312 | return;
|
10313 | }
|
10314 | return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
|
10315 | }
|
10316 | }
|
10317 |
|
10318 | function prepare(quad) {
|
10319 | if (quad.data) return quad.r = radii[quad.data.index];
|
10320 | for (var i = quad.r = 0; i < 4; ++i) {
|
10321 | if (quad[i] && quad[i].r > quad.r) {
|
10322 | quad.r = quad[i].r;
|
10323 | }
|
10324 | }
|
10325 | }
|
10326 |
|
10327 | force.initialize = function(_) {
|
10328 | var i, n = (nodes = _).length; radii = new Array(n);
|
10329 | for (i = 0; i < n; ++i) radii[i] = +radius(nodes[i], i, nodes);
|
10330 | };
|
10331 |
|
10332 | force.iterations = function(_) {
|
10333 | return arguments.length ? (iterations = +_, force) : iterations;
|
10334 | };
|
10335 |
|
10336 | force.strength = function(_) {
|
10337 | return arguments.length ? (strength = +_, force) : strength;
|
10338 | };
|
10339 |
|
10340 | force.radius = function(_) {
|
10341 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$6(+_), force) : radius;
|
10342 | };
|
10343 |
|
10344 | return force;
|
10345 | }
|
10346 |
|
10347 | function index$2(d, i) {
|
10348 | return i;
|
10349 | }
|
10350 |
|
10351 | function link(links) {
|
10352 | var id = index$2,
|
10353 | strength = defaultStrength,
|
10354 | strengths,
|
10355 | distance = constant$6(30),
|
10356 | distances,
|
10357 | nodes,
|
10358 | count,
|
10359 | bias,
|
10360 | iterations = 1;
|
10361 |
|
10362 | if (links == null) links = [];
|
10363 |
|
10364 | function defaultStrength(link) {
|
10365 | return 1 / Math.min(count[link.source.index], count[link.target.index]);
|
10366 | }
|
10367 |
|
10368 | function force(alpha) {
|
10369 | for (var k = 0, n = links.length; k < iterations; ++k) {
|
10370 | for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
|
10371 | link = links[i], source = link.source, target = link.target;
|
10372 | x = target.x + target.vx - source.x - source.vx || jiggle();
|
10373 | y = target.y + target.vy - source.y - source.vy || jiggle();
|
10374 | l = Math.sqrt(x * x + y * y);
|
10375 | l = (l - distances[i]) / l * alpha * strengths[i];
|
10376 | x *= l, y *= l;
|
10377 | target.vx -= x * (b = bias[i]);
|
10378 | target.vy -= y * b;
|
10379 | source.vx += x * (b = 1 - b);
|
10380 | source.vy += y * b;
|
10381 | }
|
10382 | }
|
10383 | }
|
10384 |
|
10385 | function initialize() {
|
10386 | if (!nodes) return;
|
10387 |
|
10388 | var i,
|
10389 | n = nodes.length,
|
10390 | m = links.length,
|
10391 | nodeById = map$1(nodes, id),
|
10392 | link;
|
10393 |
|
10394 | for (i = 0, count = new Array(n); i < n; ++i) {
|
10395 | count[i] = 0;
|
10396 | }
|
10397 |
|
10398 | for (i = 0; i < m; ++i) {
|
10399 | link = links[i], link.index = i;
|
10400 | if (typeof link.source !== "object") link.source = nodeById.get(link.source);
|
10401 | if (typeof link.target !== "object") link.target = nodeById.get(link.target);
|
10402 | ++count[link.source.index], ++count[link.target.index];
|
10403 | }
|
10404 |
|
10405 | for (i = 0, bias = new Array(m); i < m; ++i) {
|
10406 | link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
|
10407 | }
|
10408 |
|
10409 | strengths = new Array(m), initializeStrength();
|
10410 | distances = new Array(m), initializeDistance();
|
10411 | }
|
10412 |
|
10413 | function initializeStrength() {
|
10414 | if (!nodes) return;
|
10415 |
|
10416 | for (var i = 0, n = links.length; i < n; ++i) {
|
10417 | strengths[i] = +strength(links[i], i, links);
|
10418 | }
|
10419 | }
|
10420 |
|
10421 | function initializeDistance() {
|
10422 | if (!nodes) return;
|
10423 |
|
10424 | for (var i = 0, n = links.length; i < n; ++i) {
|
10425 | distances[i] = +distance(links[i], i, links);
|
10426 | }
|
10427 | }
|
10428 |
|
10429 | force.initialize = function(_) {
|
10430 | nodes = _;
|
10431 | initialize();
|
10432 | };
|
10433 |
|
10434 | force.links = function(_) {
|
10435 | return arguments.length ? (links = _, initialize(), force) : links;
|
10436 | };
|
10437 |
|
10438 | force.id = function(_) {
|
10439 | return arguments.length ? (id = _, force) : id;
|
10440 | };
|
10441 |
|
10442 | force.iterations = function(_) {
|
10443 | return arguments.length ? (iterations = +_, force) : iterations;
|
10444 | };
|
10445 |
|
10446 | force.strength = function(_) {
|
10447 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initializeStrength(), force) : strength;
|
10448 | };
|
10449 |
|
10450 | force.distance = function(_) {
|
10451 | return arguments.length ? (distance = typeof _ === "function" ? _ : constant$6(+_), initializeDistance(), force) : distance;
|
10452 | };
|
10453 |
|
10454 | return force;
|
10455 | }
|
10456 |
|
10457 | function x$2(d) {
|
10458 | return d.x;
|
10459 | }
|
10460 |
|
10461 | function y$2(d) {
|
10462 | return d.y;
|
10463 | }
|
10464 |
|
10465 | var initialRadius = 10;
|
10466 | var initialAngle = Math.PI * (3 - Math.sqrt(5));
|
10467 | function simulation(nodes) {
|
10468 | var simulation,
|
10469 | alpha = 1,
|
10470 | alphaMin = 0.001,
|
10471 | alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
|
10472 | alphaTarget = 0,
|
10473 | velocityDecay = 0.6,
|
10474 | forces = map$1(),
|
10475 | stepper = timer(step),
|
10476 | event = dispatch("tick", "end");
|
10477 |
|
10478 | if (nodes == null) nodes = [];
|
10479 |
|
10480 | function step() {
|
10481 | tick();
|
10482 | event.call("tick", simulation);
|
10483 | if (alpha < alphaMin) {
|
10484 | stepper.stop();
|
10485 | event.call("end", simulation);
|
10486 | }
|
10487 | }
|
10488 |
|
10489 | function tick() {
|
10490 | var i, n = nodes.length, node;
|
10491 |
|
10492 | alpha += (alphaTarget - alpha) * alphaDecay;
|
10493 |
|
10494 | forces.each(function(force) {
|
10495 | force(alpha);
|
10496 | });
|
10497 |
|
10498 | for (i = 0; i < n; ++i) {
|
10499 | node = nodes[i];
|
10500 | if (node.fx == null) node.x += node.vx *= velocityDecay;
|
10501 | else node.x = node.fx, node.vx = 0;
|
10502 | if (node.fy == null) node.y += node.vy *= velocityDecay;
|
10503 | else node.y = node.fy, node.vy = 0;
|
10504 | }
|
10505 | }
|
10506 |
|
10507 | function initializeNodes() {
|
10508 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
10509 | node = nodes[i], node.index = i;
|
10510 | if (isNaN(node.x) || isNaN(node.y)) {
|
10511 | var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
|
10512 | node.x = radius * Math.cos(angle);
|
10513 | node.y = radius * Math.sin(angle);
|
10514 | }
|
10515 | if (isNaN(node.vx) || isNaN(node.vy)) {
|
10516 | node.vx = node.vy = 0;
|
10517 | }
|
10518 | }
|
10519 | }
|
10520 |
|
10521 | function initializeForce(force) {
|
10522 | if (force.initialize) force.initialize(nodes);
|
10523 | return force;
|
10524 | }
|
10525 |
|
10526 | initializeNodes();
|
10527 |
|
10528 | return simulation = {
|
10529 | tick: tick,
|
10530 |
|
10531 | restart: function() {
|
10532 | return stepper.restart(step), simulation;
|
10533 | },
|
10534 |
|
10535 | stop: function() {
|
10536 | return stepper.stop(), simulation;
|
10537 | },
|
10538 |
|
10539 | nodes: function(_) {
|
10540 | return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
|
10541 | },
|
10542 |
|
10543 | alpha: function(_) {
|
10544 | return arguments.length ? (alpha = +_, simulation) : alpha;
|
10545 | },
|
10546 |
|
10547 | alphaMin: function(_) {
|
10548 | return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
|
10549 | },
|
10550 |
|
10551 | alphaDecay: function(_) {
|
10552 | return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
|
10553 | },
|
10554 |
|
10555 | alphaTarget: function(_) {
|
10556 | return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
|
10557 | },
|
10558 |
|
10559 | velocityDecay: function(_) {
|
10560 | return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
|
10561 | },
|
10562 |
|
10563 | force: function(name, _) {
|
10564 | return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
|
10565 | },
|
10566 |
|
10567 | find: function(x, y, radius) {
|
10568 | var i = 0,
|
10569 | n = nodes.length,
|
10570 | dx,
|
10571 | dy,
|
10572 | d2,
|
10573 | node,
|
10574 | closest;
|
10575 |
|
10576 | if (radius == null) radius = Infinity;
|
10577 | else radius *= radius;
|
10578 |
|
10579 | for (i = 0; i < n; ++i) {
|
10580 | node = nodes[i];
|
10581 | dx = x - node.x;
|
10582 | dy = y - node.y;
|
10583 | d2 = dx * dx + dy * dy;
|
10584 | if (d2 < radius) closest = node, radius = d2;
|
10585 | }
|
10586 |
|
10587 | return closest;
|
10588 | },
|
10589 |
|
10590 | on: function(name, _) {
|
10591 | return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
|
10592 | }
|
10593 | };
|
10594 | }
|
10595 |
|
10596 | function manyBody() {
|
10597 | var nodes,
|
10598 | node,
|
10599 | alpha,
|
10600 | strength = constant$6(-30),
|
10601 | strengths,
|
10602 | distanceMin2 = 1,
|
10603 | distanceMax2 = Infinity,
|
10604 | theta2 = 0.81;
|
10605 |
|
10606 | function force(_) {
|
10607 | var i, n = nodes.length, tree = quadtree(nodes, x$2, y$2).visitAfter(accumulate);
|
10608 | for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
|
10609 | }
|
10610 |
|
10611 | function initialize() {
|
10612 | if (!nodes) return;
|
10613 | var i, n = nodes.length;
|
10614 | strengths = new Array(n);
|
10615 | for (i = 0; i < n; ++i) strengths[i] = +strength(nodes[i], i, nodes);
|
10616 | }
|
10617 |
|
10618 | function accumulate(quad) {
|
10619 | var strength = 0, q, c, x, y, i;
|
10620 |
|
10621 | // For internal nodes, accumulate forces from child quadrants.
|
10622 | if (quad.length) {
|
10623 | for (x = y = i = 0; i < 4; ++i) {
|
10624 | if ((q = quad[i]) && (c = q.value)) {
|
10625 | strength += c, x += c * q.x, y += c * q.y;
|
10626 | }
|
10627 | }
|
10628 | quad.x = x / strength;
|
10629 | quad.y = y / strength;
|
10630 | }
|
10631 |
|
10632 | // For leaf nodes, accumulate forces from coincident quadrants.
|
10633 | else {
|
10634 | q = quad;
|
10635 | q.x = q.data.x;
|
10636 | q.y = q.data.y;
|
10637 | do strength += strengths[q.data.index];
|
10638 | while (q = q.next);
|
10639 | }
|
10640 |
|
10641 | quad.value = strength;
|
10642 | }
|
10643 |
|
10644 | function apply(quad, x1, _, x2) {
|
10645 | if (!quad.value) return true;
|
10646 |
|
10647 | var x = quad.x - node.x,
|
10648 | y = quad.y - node.y,
|
10649 | w = x2 - x1,
|
10650 | l = x * x + y * y;
|
10651 |
|
10652 | // Apply the Barnes-Hut approximation if possible.
|
10653 | // Limit forces for very close nodes; randomize direction if coincident.
|
10654 | if (w * w / theta2 < l) {
|
10655 | if (l < distanceMax2) {
|
10656 | if (x === 0) x = jiggle(), l += x * x;
|
10657 | if (y === 0) y = jiggle(), l += y * y;
|
10658 | if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
10659 | node.vx += x * quad.value * alpha / l;
|
10660 | node.vy += y * quad.value * alpha / l;
|
10661 | }
|
10662 | return true;
|
10663 | }
|
10664 |
|
10665 | // Otherwise, process points directly.
|
10666 | else if (quad.length || l >= distanceMax2) return;
|
10667 |
|
10668 | // Limit forces for very close nodes; randomize direction if coincident.
|
10669 | if (quad.data !== node || quad.next) {
|
10670 | if (x === 0) x = jiggle(), l += x * x;
|
10671 | if (y === 0) y = jiggle(), l += y * y;
|
10672 | if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
10673 | }
|
10674 |
|
10675 | do if (quad.data !== node) {
|
10676 | w = strengths[quad.data.index] * alpha / l;
|
10677 | node.vx += x * w;
|
10678 | node.vy += y * w;
|
10679 | } while (quad = quad.next);
|
10680 | }
|
10681 |
|
10682 | force.initialize = function(_) {
|
10683 | nodes = _;
|
10684 | initialize();
|
10685 | };
|
10686 |
|
10687 | force.strength = function(_) {
|
10688 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
|
10689 | };
|
10690 |
|
10691 | force.distanceMin = function(_) {
|
10692 | return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
|
10693 | };
|
10694 |
|
10695 | force.distanceMax = function(_) {
|
10696 | return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
|
10697 | };
|
10698 |
|
10699 | force.theta = function(_) {
|
10700 | return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
|
10701 | };
|
10702 |
|
10703 | return force;
|
10704 | }
|
10705 |
|
10706 | function x$3(x) {
|
10707 | var strength = constant$6(0.1),
|
10708 | nodes,
|
10709 | strengths,
|
10710 | xz;
|
10711 |
|
10712 | if (typeof x !== "function") x = constant$6(x == null ? 0 : +x);
|
10713 |
|
10714 | function force(alpha) {
|
10715 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
10716 | node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
|
10717 | }
|
10718 | }
|
10719 |
|
10720 | function initialize() {
|
10721 | if (!nodes) return;
|
10722 | var i, n = nodes.length;
|
10723 | strengths = new Array(n);
|
10724 | xz = new Array(n);
|
10725 | for (i = 0; i < n; ++i) {
|
10726 | strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
10727 | }
|
10728 | }
|
10729 |
|
10730 | force.initialize = function(_) {
|
10731 | nodes = _;
|
10732 | initialize();
|
10733 | };
|
10734 |
|
10735 | force.strength = function(_) {
|
10736 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
|
10737 | };
|
10738 |
|
10739 | force.x = function(_) {
|
10740 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : x;
|
10741 | };
|
10742 |
|
10743 | return force;
|
10744 | }
|
10745 |
|
10746 | function y$3(y) {
|
10747 | var strength = constant$6(0.1),
|
10748 | nodes,
|
10749 | strengths,
|
10750 | yz;
|
10751 |
|
10752 | if (typeof y !== "function") y = constant$6(y == null ? 0 : +y);
|
10753 |
|
10754 | function force(alpha) {
|
10755 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
10756 | node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
|
10757 | }
|
10758 | }
|
10759 |
|
10760 | function initialize() {
|
10761 | if (!nodes) return;
|
10762 | var i, n = nodes.length;
|
10763 | strengths = new Array(n);
|
10764 | yz = new Array(n);
|
10765 | for (i = 0; i < n; ++i) {
|
10766 | strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
10767 | }
|
10768 | }
|
10769 |
|
10770 | force.initialize = function(_) {
|
10771 | nodes = _;
|
10772 | initialize();
|
10773 | };
|
10774 |
|
10775 | force.strength = function(_) {
|
10776 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : strength;
|
10777 | };
|
10778 |
|
10779 | force.y = function(_) {
|
10780 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), initialize(), force) : y;
|
10781 | };
|
10782 |
|
10783 | return force;
|
10784 | }
|
10785 |
|
10786 | function nopropagation() {
|
10787 | exports.event.stopImmediatePropagation();
|
10788 | }
|
10789 |
|
10790 | function noevent() {
|
10791 | exports.event.preventDefault();
|
10792 | exports.event.stopImmediatePropagation();
|
10793 | }
|
10794 |
|
10795 | function dragDisable(view) {
|
10796 | var root = view.document.documentElement,
|
10797 | selection = select(view).on("dragstart.drag", noevent, true);
|
10798 | if ("onselectstart" in root) {
|
10799 | selection.on("selectstart.drag", noevent, true);
|
10800 | } else {
|
10801 | root.__noselect = root.style.MozUserSelect;
|
10802 | root.style.MozUserSelect = "none";
|
10803 | }
|
10804 | }
|
10805 |
|
10806 | function dragEnable(view, noclick) {
|
10807 | var root = view.document.documentElement,
|
10808 | selection = select(view).on("dragstart.drag", null);
|
10809 | if (noclick) {
|
10810 | selection.on("click.drag", noevent, true);
|
10811 | setTimeout(function() { selection.on("click.drag", null); }, 0);
|
10812 | }
|
10813 | if ("onselectstart" in root) {
|
10814 | selection.on("selectstart.drag", null);
|
10815 | } else {
|
10816 | root.style.MozUserSelect = root.__noselect;
|
10817 | delete root.__noselect;
|
10818 | }
|
10819 | }
|
10820 |
|
10821 | function constant$7(x) {
|
10822 | return function() {
|
10823 | return x;
|
10824 | };
|
10825 | }
|
10826 |
|
10827 | function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
|
10828 | this.target = target;
|
10829 | this.type = type;
|
10830 | this.subject = subject;
|
10831 | this.identifier = id;
|
10832 | this.active = active;
|
10833 | this.x = x;
|
10834 | this.y = y;
|
10835 | this.dx = dx;
|
10836 | this.dy = dy;
|
10837 | this._ = dispatch;
|
10838 | }
|
10839 |
|
10840 | DragEvent.prototype.on = function() {
|
10841 | var value = this._.on.apply(this._, arguments);
|
10842 | return value === this._ ? this : value;
|
10843 | };
|
10844 |
|
10845 | // Ignore right-click, since that should open the context menu.
|
10846 | function defaultFilter() {
|
10847 | return !exports.event.button;
|
10848 | }
|
10849 |
|
10850 | function defaultContainer() {
|
10851 | return this.parentNode;
|
10852 | }
|
10853 |
|
10854 | function defaultSubject(d) {
|
10855 | return d == null ? {x: exports.event.x, y: exports.event.y} : d;
|
10856 | }
|
10857 |
|
10858 | function drag() {
|
10859 | var filter = defaultFilter,
|
10860 | container = defaultContainer,
|
10861 | subject = defaultSubject,
|
10862 | gestures = {},
|
10863 | listeners = dispatch("start", "drag", "end"),
|
10864 | active = 0,
|
10865 | mousemoving,
|
10866 | touchending;
|
10867 |
|
10868 | function drag(selection) {
|
10869 | selection
|
10870 | .on("mousedown.drag", mousedowned)
|
10871 | .on("touchstart.drag", touchstarted)
|
10872 | .on("touchmove.drag", touchmoved)
|
10873 | .on("touchend.drag touchcancel.drag", touchended)
|
10874 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
10875 | }
|
10876 |
|
10877 | function mousedowned() {
|
10878 | if (touchending || !filter.apply(this, arguments)) return;
|
10879 | var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
|
10880 | if (!gesture) return;
|
10881 | select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
|
10882 | dragDisable(exports.event.view);
|
10883 | nopropagation();
|
10884 | mousemoving = false;
|
10885 | gesture("start");
|
10886 | }
|
10887 |
|
10888 | function mousemoved() {
|
10889 | noevent();
|
10890 | mousemoving = true;
|
10891 | gestures.mouse("drag");
|
10892 | }
|
10893 |
|
10894 | function mouseupped() {
|
10895 | select(exports.event.view).on("mousemove.drag mouseup.drag", null);
|
10896 | dragEnable(exports.event.view, mousemoving);
|
10897 | noevent();
|
10898 | gestures.mouse("end");
|
10899 | }
|
10900 |
|
10901 | function touchstarted() {
|
10902 | if (!filter.apply(this, arguments)) return;
|
10903 | var touches = exports.event.changedTouches,
|
10904 | c = container.apply(this, arguments),
|
10905 | n = touches.length, i, gesture;
|
10906 |
|
10907 | for (i = 0; i < n; ++i) {
|
10908 | if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
|
10909 | nopropagation();
|
10910 | gesture("start");
|
10911 | }
|
10912 | }
|
10913 | }
|
10914 |
|
10915 | function touchmoved() {
|
10916 | var touches = exports.event.changedTouches,
|
10917 | n = touches.length, i, gesture;
|
10918 |
|
10919 | for (i = 0; i < n; ++i) {
|
10920 | if (gesture = gestures[touches[i].identifier]) {
|
10921 | noevent();
|
10922 | gesture("drag");
|
10923 | }
|
10924 | }
|
10925 | }
|
10926 |
|
10927 | function touchended() {
|
10928 | var touches = exports.event.changedTouches,
|
10929 | n = touches.length, i, gesture;
|
10930 |
|
10931 | if (touchending) clearTimeout(touchending);
|
10932 | touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
|
10933 | for (i = 0; i < n; ++i) {
|
10934 | if (gesture = gestures[touches[i].identifier]) {
|
10935 | nopropagation();
|
10936 | gesture("end");
|
10937 | }
|
10938 | }
|
10939 | }
|
10940 |
|
10941 | function beforestart(id, container, point, that, args) {
|
10942 | var p = point(container, id), s, dx, dy,
|
10943 | sublisteners = listeners.copy();
|
10944 |
|
10945 | if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
|
10946 | if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
|
10947 | dx = s.x - p[0] || 0;
|
10948 | dy = s.y - p[1] || 0;
|
10949 | return true;
|
10950 | })) return;
|
10951 |
|
10952 | return function gesture(type) {
|
10953 | var p0 = p, n;
|
10954 | switch (type) {
|
10955 | case "start": gestures[id] = gesture, n = active++; break;
|
10956 | case "end": delete gestures[id], --active; // nobreak
|
10957 | case "drag": p = point(container, id), n = active; break;
|
10958 | }
|
10959 | 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]);
|
10960 | };
|
10961 | }
|
10962 |
|
10963 | drag.filter = function(_) {
|
10964 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), drag) : filter;
|
10965 | };
|
10966 |
|
10967 | drag.container = function(_) {
|
10968 | return arguments.length ? (container = typeof _ === "function" ? _ : constant$7(_), drag) : container;
|
10969 | };
|
10970 |
|
10971 | drag.subject = function(_) {
|
10972 | return arguments.length ? (subject = typeof _ === "function" ? _ : constant$7(_), drag) : subject;
|
10973 | };
|
10974 |
|
10975 | drag.on = function() {
|
10976 | var value = listeners.on.apply(listeners, arguments);
|
10977 | return value === listeners ? drag : value;
|
10978 | };
|
10979 |
|
10980 | return drag;
|
10981 | }
|
10982 |
|
10983 | function constant$8(x) {
|
10984 | return function() {
|
10985 | return x;
|
10986 | };
|
10987 | }
|
10988 |
|
10989 | function x$4(d) {
|
10990 | return d[0];
|
10991 | }
|
10992 |
|
10993 | function y$4(d) {
|
10994 | return d[1];
|
10995 | }
|
10996 |
|
10997 | function RedBlackTree() {
|
10998 | this._ = null; // root node
|
10999 | }
|
11000 |
|
11001 | function RedBlackNode(node) {
|
11002 | node.U = // parent node
|
11003 | node.C = // color - true for red, false for black
|
11004 | node.L = // left node
|
11005 | node.R = // right node
|
11006 | node.P = // previous node
|
11007 | node.N = null; // next node
|
11008 | }
|
11009 |
|
11010 | RedBlackTree.prototype = {
|
11011 | constructor: RedBlackTree,
|
11012 |
|
11013 | insert: function(after, node) {
|
11014 | var parent, grandpa, uncle;
|
11015 |
|
11016 | if (after) {
|
11017 | node.P = after;
|
11018 | node.N = after.N;
|
11019 | if (after.N) after.N.P = node;
|
11020 | after.N = node;
|
11021 | if (after.R) {
|
11022 | after = after.R;
|
11023 | while (after.L) after = after.L;
|
11024 | after.L = node;
|
11025 | } else {
|
11026 | after.R = node;
|
11027 | }
|
11028 | parent = after;
|
11029 | } else if (this._) {
|
11030 | after = RedBlackFirst(this._);
|
11031 | node.P = null;
|
11032 | node.N = after;
|
11033 | after.P = after.L = node;
|
11034 | parent = after;
|
11035 | } else {
|
11036 | node.P = node.N = null;
|
11037 | this._ = node;
|
11038 | parent = null;
|
11039 | }
|
11040 | node.L = node.R = null;
|
11041 | node.U = parent;
|
11042 | node.C = true;
|
11043 |
|
11044 | after = node;
|
11045 | while (parent && parent.C) {
|
11046 | grandpa = parent.U;
|
11047 | if (parent === grandpa.L) {
|
11048 | uncle = grandpa.R;
|
11049 | if (uncle && uncle.C) {
|
11050 | parent.C = uncle.C = false;
|
11051 | grandpa.C = true;
|
11052 | after = grandpa;
|
11053 | } else {
|
11054 | if (after === parent.R) {
|
11055 | RedBlackRotateLeft(this, parent);
|
11056 | after = parent;
|
11057 | parent = after.U;
|
11058 | }
|
11059 | parent.C = false;
|
11060 | grandpa.C = true;
|
11061 | RedBlackRotateRight(this, grandpa);
|
11062 | }
|
11063 | } else {
|
11064 | uncle = grandpa.L;
|
11065 | if (uncle && uncle.C) {
|
11066 | parent.C = uncle.C = false;
|
11067 | grandpa.C = true;
|
11068 | after = grandpa;
|
11069 | } else {
|
11070 | if (after === parent.L) {
|
11071 | RedBlackRotateRight(this, parent);
|
11072 | after = parent;
|
11073 | parent = after.U;
|
11074 | }
|
11075 | parent.C = false;
|
11076 | grandpa.C = true;
|
11077 | RedBlackRotateLeft(this, grandpa);
|
11078 | }
|
11079 | }
|
11080 | parent = after.U;
|
11081 | }
|
11082 | this._.C = false;
|
11083 | },
|
11084 |
|
11085 | remove: function(node) {
|
11086 | if (node.N) node.N.P = node.P;
|
11087 | if (node.P) node.P.N = node.N;
|
11088 | node.N = node.P = null;
|
11089 |
|
11090 | var parent = node.U,
|
11091 | sibling,
|
11092 | left = node.L,
|
11093 | right = node.R,
|
11094 | next,
|
11095 | red;
|
11096 |
|
11097 | if (!left) next = right;
|
11098 | else if (!right) next = left;
|
11099 | else next = RedBlackFirst(right);
|
11100 |
|
11101 | if (parent) {
|
11102 | if (parent.L === node) parent.L = next;
|
11103 | else parent.R = next;
|
11104 | } else {
|
11105 | this._ = next;
|
11106 | }
|
11107 |
|
11108 | if (left && right) {
|
11109 | red = next.C;
|
11110 | next.C = node.C;
|
11111 | next.L = left;
|
11112 | left.U = next;
|
11113 | if (next !== right) {
|
11114 | parent = next.U;
|
11115 | next.U = node.U;
|
11116 | node = next.R;
|
11117 | parent.L = node;
|
11118 | next.R = right;
|
11119 | right.U = next;
|
11120 | } else {
|
11121 | next.U = parent;
|
11122 | parent = next;
|
11123 | node = next.R;
|
11124 | }
|
11125 | } else {
|
11126 | red = node.C;
|
11127 | node = next;
|
11128 | }
|
11129 |
|
11130 | if (node) node.U = parent;
|
11131 | if (red) return;
|
11132 | if (node && node.C) { node.C = false; return; }
|
11133 |
|
11134 | do {
|
11135 | if (node === this._) break;
|
11136 | if (node === parent.L) {
|
11137 | sibling = parent.R;
|
11138 | if (sibling.C) {
|
11139 | sibling.C = false;
|
11140 | parent.C = true;
|
11141 | RedBlackRotateLeft(this, parent);
|
11142 | sibling = parent.R;
|
11143 | }
|
11144 | if ((sibling.L && sibling.L.C)
|
11145 | || (sibling.R && sibling.R.C)) {
|
11146 | if (!sibling.R || !sibling.R.C) {
|
11147 | sibling.L.C = false;
|
11148 | sibling.C = true;
|
11149 | RedBlackRotateRight(this, sibling);
|
11150 | sibling = parent.R;
|
11151 | }
|
11152 | sibling.C = parent.C;
|
11153 | parent.C = sibling.R.C = false;
|
11154 | RedBlackRotateLeft(this, parent);
|
11155 | node = this._;
|
11156 | break;
|
11157 | }
|
11158 | } else {
|
11159 | sibling = parent.L;
|
11160 | if (sibling.C) {
|
11161 | sibling.C = false;
|
11162 | parent.C = true;
|
11163 | RedBlackRotateRight(this, parent);
|
11164 | sibling = parent.L;
|
11165 | }
|
11166 | if ((sibling.L && sibling.L.C)
|
11167 | || (sibling.R && sibling.R.C)) {
|
11168 | if (!sibling.L || !sibling.L.C) {
|
11169 | sibling.R.C = false;
|
11170 | sibling.C = true;
|
11171 | RedBlackRotateLeft(this, sibling);
|
11172 | sibling = parent.L;
|
11173 | }
|
11174 | sibling.C = parent.C;
|
11175 | parent.C = sibling.L.C = false;
|
11176 | RedBlackRotateRight(this, parent);
|
11177 | node = this._;
|
11178 | break;
|
11179 | }
|
11180 | }
|
11181 | sibling.C = true;
|
11182 | node = parent;
|
11183 | parent = parent.U;
|
11184 | } while (!node.C);
|
11185 |
|
11186 | if (node) node.C = false;
|
11187 | }
|
11188 | };
|
11189 |
|
11190 | function RedBlackRotateLeft(tree, node) {
|
11191 | var p = node,
|
11192 | q = node.R,
|
11193 | parent = p.U;
|
11194 |
|
11195 | if (parent) {
|
11196 | if (parent.L === p) parent.L = q;
|
11197 | else parent.R = q;
|
11198 | } else {
|
11199 | tree._ = q;
|
11200 | }
|
11201 |
|
11202 | q.U = parent;
|
11203 | p.U = q;
|
11204 | p.R = q.L;
|
11205 | if (p.R) p.R.U = p;
|
11206 | q.L = p;
|
11207 | }
|
11208 |
|
11209 | function RedBlackRotateRight(tree, node) {
|
11210 | var p = node,
|
11211 | q = node.L,
|
11212 | parent = p.U;
|
11213 |
|
11214 | if (parent) {
|
11215 | if (parent.L === p) parent.L = q;
|
11216 | else parent.R = q;
|
11217 | } else {
|
11218 | tree._ = q;
|
11219 | }
|
11220 |
|
11221 | q.U = parent;
|
11222 | p.U = q;
|
11223 | p.L = q.R;
|
11224 | if (p.L) p.L.U = p;
|
11225 | q.R = p;
|
11226 | }
|
11227 |
|
11228 | function RedBlackFirst(node) {
|
11229 | while (node.L) node = node.L;
|
11230 | return node;
|
11231 | }
|
11232 |
|
11233 | function createEdge(left, right, v0, v1) {
|
11234 | var edge = [null, null],
|
11235 | index = edges.push(edge) - 1;
|
11236 | edge.left = left;
|
11237 | edge.right = right;
|
11238 | if (v0) setEdgeEnd(edge, left, right, v0);
|
11239 | if (v1) setEdgeEnd(edge, right, left, v1);
|
11240 | cells[left.index].halfedges.push(index);
|
11241 | cells[right.index].halfedges.push(index);
|
11242 | return edge;
|
11243 | }
|
11244 |
|
11245 | function createBorderEdge(left, v0, v1) {
|
11246 | var edge = [v0, v1];
|
11247 | edge.left = left;
|
11248 | return edge;
|
11249 | }
|
11250 |
|
11251 | function setEdgeEnd(edge, left, right, vertex) {
|
11252 | if (!edge[0] && !edge[1]) {
|
11253 | edge[0] = vertex;
|
11254 | edge.left = left;
|
11255 | edge.right = right;
|
11256 | } else if (edge.left === right) {
|
11257 | edge[1] = vertex;
|
11258 | } else {
|
11259 | edge[0] = vertex;
|
11260 | }
|
11261 | }
|
11262 |
|
11263 | // Liang–Barsky line clipping.
|
11264 | function clipEdge(edge, x0, y0, x1, y1) {
|
11265 | var a = edge[0],
|
11266 | b = edge[1],
|
11267 | ax = a[0],
|
11268 | ay = a[1],
|
11269 | bx = b[0],
|
11270 | by = b[1],
|
11271 | t0 = 0,
|
11272 | t1 = 1,
|
11273 | dx = bx - ax,
|
11274 | dy = by - ay,
|
11275 | r;
|
11276 |
|
11277 | r = x0 - ax;
|
11278 | if (!dx && r > 0) return;
|
11279 | r /= dx;
|
11280 | if (dx < 0) {
|
11281 | if (r < t0) return;
|
11282 | if (r < t1) t1 = r;
|
11283 | } else if (dx > 0) {
|
11284 | if (r > t1) return;
|
11285 | if (r > t0) t0 = r;
|
11286 | }
|
11287 |
|
11288 | r = x1 - ax;
|
11289 | if (!dx && r < 0) return;
|
11290 | r /= dx;
|
11291 | if (dx < 0) {
|
11292 | if (r > t1) return;
|
11293 | if (r > t0) t0 = r;
|
11294 | } else if (dx > 0) {
|
11295 | if (r < t0) return;
|
11296 | if (r < t1) t1 = r;
|
11297 | }
|
11298 |
|
11299 | r = y0 - ay;
|
11300 | if (!dy && r > 0) return;
|
11301 | r /= dy;
|
11302 | if (dy < 0) {
|
11303 | if (r < t0) return;
|
11304 | if (r < t1) t1 = r;
|
11305 | } else if (dy > 0) {
|
11306 | if (r > t1) return;
|
11307 | if (r > t0) t0 = r;
|
11308 | }
|
11309 |
|
11310 | r = y1 - ay;
|
11311 | if (!dy && r < 0) return;
|
11312 | r /= dy;
|
11313 | if (dy < 0) {
|
11314 | if (r > t1) return;
|
11315 | if (r > t0) t0 = r;
|
11316 | } else if (dy > 0) {
|
11317 | if (r < t0) return;
|
11318 | if (r < t1) t1 = r;
|
11319 | }
|
11320 |
|
11321 | if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
|
11322 |
|
11323 | if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
|
11324 | if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
|
11325 | return true;
|
11326 | }
|
11327 |
|
11328 | function connectEdge(edge, x0, y0, x1, y1) {
|
11329 | var v1 = edge[1];
|
11330 | if (v1) return true;
|
11331 |
|
11332 | var v0 = edge[0],
|
11333 | left = edge.left,
|
11334 | right = edge.right,
|
11335 | lx = left[0],
|
11336 | ly = left[1],
|
11337 | rx = right[0],
|
11338 | ry = right[1],
|
11339 | fx = (lx + rx) / 2,
|
11340 | fy = (ly + ry) / 2,
|
11341 | fm,
|
11342 | fb;
|
11343 |
|
11344 | if (ry === ly) {
|
11345 | if (fx < x0 || fx >= x1) return;
|
11346 | if (lx > rx) {
|
11347 | if (!v0) v0 = [fx, y0];
|
11348 | else if (v0[1] >= y1) return;
|
11349 | v1 = [fx, y1];
|
11350 | } else {
|
11351 | if (!v0) v0 = [fx, y1];
|
11352 | else if (v0[1] < y0) return;
|
11353 | v1 = [fx, y0];
|
11354 | }
|
11355 | } else {
|
11356 | fm = (lx - rx) / (ry - ly);
|
11357 | fb = fy - fm * fx;
|
11358 | if (fm < -1 || fm > 1) {
|
11359 | if (lx > rx) {
|
11360 | if (!v0) v0 = [(y0 - fb) / fm, y0];
|
11361 | else if (v0[1] >= y1) return;
|
11362 | v1 = [(y1 - fb) / fm, y1];
|
11363 | } else {
|
11364 | if (!v0) v0 = [(y1 - fb) / fm, y1];
|
11365 | else if (v0[1] < y0) return;
|
11366 | v1 = [(y0 - fb) / fm, y0];
|
11367 | }
|
11368 | } else {
|
11369 | if (ly < ry) {
|
11370 | if (!v0) v0 = [x0, fm * x0 + fb];
|
11371 | else if (v0[0] >= x1) return;
|
11372 | v1 = [x1, fm * x1 + fb];
|
11373 | } else {
|
11374 | if (!v0) v0 = [x1, fm * x1 + fb];
|
11375 | else if (v0[0] < x0) return;
|
11376 | v1 = [x0, fm * x0 + fb];
|
11377 | }
|
11378 | }
|
11379 | }
|
11380 |
|
11381 | edge[0] = v0;
|
11382 | edge[1] = v1;
|
11383 | return true;
|
11384 | }
|
11385 |
|
11386 | function clipEdges(x0, y0, x1, y1) {
|
11387 | var i = edges.length,
|
11388 | edge;
|
11389 |
|
11390 | while (i--) {
|
11391 | if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
|
11392 | || !clipEdge(edge, x0, y0, x1, y1)
|
11393 | || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$3
|
11394 | || Math.abs(edge[0][1] - edge[1][1]) > epsilon$3)) {
|
11395 | delete edges[i];
|
11396 | }
|
11397 | }
|
11398 | }
|
11399 |
|
11400 | function createCell(site) {
|
11401 | return cells[site.index] = {
|
11402 | site: site,
|
11403 | halfedges: []
|
11404 | };
|
11405 | }
|
11406 |
|
11407 | function cellHalfedgeAngle(cell, edge) {
|
11408 | var site = cell.site,
|
11409 | va = edge.left,
|
11410 | vb = edge.right;
|
11411 | if (site === vb) vb = va, va = site;
|
11412 | if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
|
11413 | if (site === va) va = edge[1], vb = edge[0];
|
11414 | else va = edge[0], vb = edge[1];
|
11415 | return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
|
11416 | }
|
11417 |
|
11418 | function cellHalfedgeStart(cell, edge) {
|
11419 | return edge[+(edge.left !== cell.site)];
|
11420 | }
|
11421 |
|
11422 | function cellHalfedgeEnd(cell, edge) {
|
11423 | return edge[+(edge.left === cell.site)];
|
11424 | }
|
11425 |
|
11426 | function sortCellHalfedges() {
|
11427 | for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
|
11428 | if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
|
11429 | var index = new Array(m),
|
11430 | array = new Array(m);
|
11431 | for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
|
11432 | index.sort(function(i, j) { return array[j] - array[i]; });
|
11433 | for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
|
11434 | for (j = 0; j < m; ++j) halfedges[j] = array[j];
|
11435 | }
|
11436 | }
|
11437 | }
|
11438 |
|
11439 | function clipCells(x0, y0, x1, y1) {
|
11440 | var nCells = cells.length,
|
11441 | iCell,
|
11442 | cell,
|
11443 | site,
|
11444 | iHalfedge,
|
11445 | halfedges,
|
11446 | nHalfedges,
|
11447 | start,
|
11448 | startX,
|
11449 | startY,
|
11450 | end,
|
11451 | endX,
|
11452 | endY,
|
11453 | cover = true;
|
11454 |
|
11455 | for (iCell = 0; iCell < nCells; ++iCell) {
|
11456 | if (cell = cells[iCell]) {
|
11457 | site = cell.site;
|
11458 | halfedges = cell.halfedges;
|
11459 | iHalfedge = halfedges.length;
|
11460 |
|
11461 | // Remove any dangling clipped edges.
|
11462 | while (iHalfedge--) {
|
11463 | if (!edges[halfedges[iHalfedge]]) {
|
11464 | halfedges.splice(iHalfedge, 1);
|
11465 | }
|
11466 | }
|
11467 |
|
11468 | // Insert any border edges as necessary.
|
11469 | iHalfedge = 0, nHalfedges = halfedges.length;
|
11470 | while (iHalfedge < nHalfedges) {
|
11471 | end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
|
11472 | start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
|
11473 | if (Math.abs(endX - startX) > epsilon$3 || Math.abs(endY - startY) > epsilon$3) {
|
11474 | halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
|
11475 | Math.abs(endX - x0) < epsilon$3 && y1 - endY > epsilon$3 ? [x0, Math.abs(startX - x0) < epsilon$3 ? startY : y1]
|
11476 | : Math.abs(endY - y1) < epsilon$3 && x1 - endX > epsilon$3 ? [Math.abs(startY - y1) < epsilon$3 ? startX : x1, y1]
|
11477 | : Math.abs(endX - x1) < epsilon$3 && endY - y0 > epsilon$3 ? [x1, Math.abs(startX - x1) < epsilon$3 ? startY : y0]
|
11478 | : Math.abs(endY - y0) < epsilon$3 && endX - x0 > epsilon$3 ? [Math.abs(startY - y0) < epsilon$3 ? startX : x0, y0]
|
11479 | : null)) - 1);
|
11480 | ++nHalfedges;
|
11481 | }
|
11482 | }
|
11483 |
|
11484 | if (nHalfedges) cover = false;
|
11485 | }
|
11486 | }
|
11487 |
|
11488 | // If there weren’t any edges, have the closest site cover the extent.
|
11489 | // It doesn’t matter which corner of the extent we measure!
|
11490 | if (cover) {
|
11491 | var dx, dy, d2, dc = Infinity;
|
11492 |
|
11493 | for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
|
11494 | if (cell = cells[iCell]) {
|
11495 | site = cell.site;
|
11496 | dx = site[0] - x0;
|
11497 | dy = site[1] - y0;
|
11498 | d2 = dx * dx + dy * dy;
|
11499 | if (d2 < dc) dc = d2, cover = cell;
|
11500 | }
|
11501 | }
|
11502 |
|
11503 | if (cover) {
|
11504 | var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
|
11505 | cover.halfedges.push(
|
11506 | edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
|
11507 | edges.push(createBorderEdge(site, v01, v11)) - 1,
|
11508 | edges.push(createBorderEdge(site, v11, v10)) - 1,
|
11509 | edges.push(createBorderEdge(site, v10, v00)) - 1
|
11510 | );
|
11511 | }
|
11512 | }
|
11513 |
|
11514 | // Lastly delete any cells with no edges; these were entirely clipped.
|
11515 | for (iCell = 0; iCell < nCells; ++iCell) {
|
11516 | if (cell = cells[iCell]) {
|
11517 | if (!cell.halfedges.length) {
|
11518 | delete cells[iCell];
|
11519 | }
|
11520 | }
|
11521 | }
|
11522 | }
|
11523 |
|
11524 | var circlePool = [];
|
11525 |
|
11526 | var firstCircle;
|
11527 |
|
11528 | function Circle() {
|
11529 | RedBlackNode(this);
|
11530 | this.x =
|
11531 | this.y =
|
11532 | this.arc =
|
11533 | this.site =
|
11534 | this.cy = null;
|
11535 | }
|
11536 |
|
11537 | function attachCircle(arc) {
|
11538 | var lArc = arc.P,
|
11539 | rArc = arc.N;
|
11540 |
|
11541 | if (!lArc || !rArc) return;
|
11542 |
|
11543 | var lSite = lArc.site,
|
11544 | cSite = arc.site,
|
11545 | rSite = rArc.site;
|
11546 |
|
11547 | if (lSite === rSite) return;
|
11548 |
|
11549 | var bx = cSite[0],
|
11550 | by = cSite[1],
|
11551 | ax = lSite[0] - bx,
|
11552 | ay = lSite[1] - by,
|
11553 | cx = rSite[0] - bx,
|
11554 | cy = rSite[1] - by;
|
11555 |
|
11556 | var d = 2 * (ax * cy - ay * cx);
|
11557 | if (d >= -epsilon2$1) return;
|
11558 |
|
11559 | var ha = ax * ax + ay * ay,
|
11560 | hc = cx * cx + cy * cy,
|
11561 | x = (cy * ha - ay * hc) / d,
|
11562 | y = (ax * hc - cx * ha) / d;
|
11563 |
|
11564 | var circle = circlePool.pop() || new Circle;
|
11565 | circle.arc = arc;
|
11566 | circle.site = cSite;
|
11567 | circle.x = x + bx;
|
11568 | circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
|
11569 |
|
11570 | arc.circle = circle;
|
11571 |
|
11572 | var before = null,
|
11573 | node = circles._;
|
11574 |
|
11575 | while (node) {
|
11576 | if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
|
11577 | if (node.L) node = node.L;
|
11578 | else { before = node.P; break; }
|
11579 | } else {
|
11580 | if (node.R) node = node.R;
|
11581 | else { before = node; break; }
|
11582 | }
|
11583 | }
|
11584 |
|
11585 | circles.insert(before, circle);
|
11586 | if (!before) firstCircle = circle;
|
11587 | }
|
11588 |
|
11589 | function detachCircle(arc) {
|
11590 | var circle = arc.circle;
|
11591 | if (circle) {
|
11592 | if (!circle.P) firstCircle = circle.N;
|
11593 | circles.remove(circle);
|
11594 | circlePool.push(circle);
|
11595 | RedBlackNode(circle);
|
11596 | arc.circle = null;
|
11597 | }
|
11598 | }
|
11599 |
|
11600 | var beachPool = [];
|
11601 |
|
11602 | function Beach() {
|
11603 | RedBlackNode(this);
|
11604 | this.edge =
|
11605 | this.site =
|
11606 | this.circle = null;
|
11607 | }
|
11608 |
|
11609 | function createBeach(site) {
|
11610 | var beach = beachPool.pop() || new Beach;
|
11611 | beach.site = site;
|
11612 | return beach;
|
11613 | }
|
11614 |
|
11615 | function detachBeach(beach) {
|
11616 | detachCircle(beach);
|
11617 | beaches.remove(beach);
|
11618 | beachPool.push(beach);
|
11619 | RedBlackNode(beach);
|
11620 | }
|
11621 |
|
11622 | function removeBeach(beach) {
|
11623 | var circle = beach.circle,
|
11624 | x = circle.x,
|
11625 | y = circle.cy,
|
11626 | vertex = [x, y],
|
11627 | previous = beach.P,
|
11628 | next = beach.N,
|
11629 | disappearing = [beach];
|
11630 |
|
11631 | detachBeach(beach);
|
11632 |
|
11633 | var lArc = previous;
|
11634 | while (lArc.circle
|
11635 | && Math.abs(x - lArc.circle.x) < epsilon$3
|
11636 | && Math.abs(y - lArc.circle.cy) < epsilon$3) {
|
11637 | previous = lArc.P;
|
11638 | disappearing.unshift(lArc);
|
11639 | detachBeach(lArc);
|
11640 | lArc = previous;
|
11641 | }
|
11642 |
|
11643 | disappearing.unshift(lArc);
|
11644 | detachCircle(lArc);
|
11645 |
|
11646 | var rArc = next;
|
11647 | while (rArc.circle
|
11648 | && Math.abs(x - rArc.circle.x) < epsilon$3
|
11649 | && Math.abs(y - rArc.circle.cy) < epsilon$3) {
|
11650 | next = rArc.N;
|
11651 | disappearing.push(rArc);
|
11652 | detachBeach(rArc);
|
11653 | rArc = next;
|
11654 | }
|
11655 |
|
11656 | disappearing.push(rArc);
|
11657 | detachCircle(rArc);
|
11658 |
|
11659 | var nArcs = disappearing.length,
|
11660 | iArc;
|
11661 | for (iArc = 1; iArc < nArcs; ++iArc) {
|
11662 | rArc = disappearing[iArc];
|
11663 | lArc = disappearing[iArc - 1];
|
11664 | setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
|
11665 | }
|
11666 |
|
11667 | lArc = disappearing[0];
|
11668 | rArc = disappearing[nArcs - 1];
|
11669 | rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
|
11670 |
|
11671 | attachCircle(lArc);
|
11672 | attachCircle(rArc);
|
11673 | }
|
11674 |
|
11675 | function addBeach(site) {
|
11676 | var x = site[0],
|
11677 | directrix = site[1],
|
11678 | lArc,
|
11679 | rArc,
|
11680 | dxl,
|
11681 | dxr,
|
11682 | node = beaches._;
|
11683 |
|
11684 | while (node) {
|
11685 | dxl = leftBreakPoint(node, directrix) - x;
|
11686 | if (dxl > epsilon$3) node = node.L; else {
|
11687 | dxr = x - rightBreakPoint(node, directrix);
|
11688 | if (dxr > epsilon$3) {
|
11689 | if (!node.R) {
|
11690 | lArc = node;
|
11691 | break;
|
11692 | }
|
11693 | node = node.R;
|
11694 | } else {
|
11695 | if (dxl > -epsilon$3) {
|
11696 | lArc = node.P;
|
11697 | rArc = node;
|
11698 | } else if (dxr > -epsilon$3) {
|
11699 | lArc = node;
|
11700 | rArc = node.N;
|
11701 | } else {
|
11702 | lArc = rArc = node;
|
11703 | }
|
11704 | break;
|
11705 | }
|
11706 | }
|
11707 | }
|
11708 |
|
11709 | createCell(site);
|
11710 | var newArc = createBeach(site);
|
11711 | beaches.insert(lArc, newArc);
|
11712 |
|
11713 | if (!lArc && !rArc) return;
|
11714 |
|
11715 | if (lArc === rArc) {
|
11716 | detachCircle(lArc);
|
11717 | rArc = createBeach(lArc.site);
|
11718 | beaches.insert(newArc, rArc);
|
11719 | newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
|
11720 | attachCircle(lArc);
|
11721 | attachCircle(rArc);
|
11722 | return;
|
11723 | }
|
11724 |
|
11725 | if (!rArc) { // && lArc
|
11726 | newArc.edge = createEdge(lArc.site, newArc.site);
|
11727 | return;
|
11728 | }
|
11729 |
|
11730 | // else lArc !== rArc
|
11731 | detachCircle(lArc);
|
11732 | detachCircle(rArc);
|
11733 |
|
11734 | var lSite = lArc.site,
|
11735 | ax = lSite[0],
|
11736 | ay = lSite[1],
|
11737 | bx = site[0] - ax,
|
11738 | by = site[1] - ay,
|
11739 | rSite = rArc.site,
|
11740 | cx = rSite[0] - ax,
|
11741 | cy = rSite[1] - ay,
|
11742 | d = 2 * (bx * cy - by * cx),
|
11743 | hb = bx * bx + by * by,
|
11744 | hc = cx * cx + cy * cy,
|
11745 | vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
|
11746 |
|
11747 | setEdgeEnd(rArc.edge, lSite, rSite, vertex);
|
11748 | newArc.edge = createEdge(lSite, site, null, vertex);
|
11749 | rArc.edge = createEdge(site, rSite, null, vertex);
|
11750 | attachCircle(lArc);
|
11751 | attachCircle(rArc);
|
11752 | }
|
11753 |
|
11754 | function leftBreakPoint(arc, directrix) {
|
11755 | var site = arc.site,
|
11756 | rfocx = site[0],
|
11757 | rfocy = site[1],
|
11758 | pby2 = rfocy - directrix;
|
11759 |
|
11760 | if (!pby2) return rfocx;
|
11761 |
|
11762 | var lArc = arc.P;
|
11763 | if (!lArc) return -Infinity;
|
11764 |
|
11765 | site = lArc.site;
|
11766 | var lfocx = site[0],
|
11767 | lfocy = site[1],
|
11768 | plby2 = lfocy - directrix;
|
11769 |
|
11770 | if (!plby2) return lfocx;
|
11771 |
|
11772 | var hl = lfocx - rfocx,
|
11773 | aby2 = 1 / pby2 - 1 / plby2,
|
11774 | b = hl / plby2;
|
11775 |
|
11776 | if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
|
11777 |
|
11778 | return (rfocx + lfocx) / 2;
|
11779 | }
|
11780 |
|
11781 | function rightBreakPoint(arc, directrix) {
|
11782 | var rArc = arc.N;
|
11783 | if (rArc) return leftBreakPoint(rArc, directrix);
|
11784 | var site = arc.site;
|
11785 | return site[1] === directrix ? site[0] : Infinity;
|
11786 | }
|
11787 |
|
11788 | var epsilon$3 = 1e-6;
|
11789 | var epsilon2$1 = 1e-12;
|
11790 | var beaches;
|
11791 | var cells;
|
11792 | var circles;
|
11793 | var edges;
|
11794 |
|
11795 | function triangleArea(a, b, c) {
|
11796 | return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
|
11797 | }
|
11798 |
|
11799 | function lexicographic(a, b) {
|
11800 | return b[1] - a[1]
|
11801 | || b[0] - a[0];
|
11802 | }
|
11803 |
|
11804 | function Diagram(sites, extent) {
|
11805 | var site = sites.sort(lexicographic).pop(),
|
11806 | x,
|
11807 | y,
|
11808 | circle;
|
11809 |
|
11810 | edges = [];
|
11811 | cells = new Array(sites.length);
|
11812 | beaches = new RedBlackTree;
|
11813 | circles = new RedBlackTree;
|
11814 |
|
11815 | while (true) {
|
11816 | circle = firstCircle;
|
11817 | if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
|
11818 | if (site[0] !== x || site[1] !== y) {
|
11819 | addBeach(site);
|
11820 | x = site[0], y = site[1];
|
11821 | }
|
11822 | site = sites.pop();
|
11823 | } else if (circle) {
|
11824 | removeBeach(circle.arc);
|
11825 | } else {
|
11826 | break;
|
11827 | }
|
11828 | }
|
11829 |
|
11830 | sortCellHalfedges();
|
11831 |
|
11832 | if (extent) {
|
11833 | var x0 = +extent[0][0],
|
11834 | y0 = +extent[0][1],
|
11835 | x1 = +extent[1][0],
|
11836 | y1 = +extent[1][1];
|
11837 | clipEdges(x0, y0, x1, y1);
|
11838 | clipCells(x0, y0, x1, y1);
|
11839 | }
|
11840 |
|
11841 | this.edges = edges;
|
11842 | this.cells = cells;
|
11843 |
|
11844 | beaches =
|
11845 | circles =
|
11846 | edges =
|
11847 | cells = null;
|
11848 | }
|
11849 |
|
11850 | Diagram.prototype = {
|
11851 | constructor: Diagram,
|
11852 |
|
11853 | polygons: function() {
|
11854 | var edges = this.edges;
|
11855 |
|
11856 | return this.cells.map(function(cell) {
|
11857 | var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
|
11858 | polygon.data = cell.site.data;
|
11859 | return polygon;
|
11860 | });
|
11861 | },
|
11862 |
|
11863 | triangles: function() {
|
11864 | var triangles = [],
|
11865 | edges = this.edges;
|
11866 |
|
11867 | this.cells.forEach(function(cell, i) {
|
11868 | var site = cell.site,
|
11869 | halfedges = cell.halfedges,
|
11870 | j = -1,
|
11871 | m = halfedges.length,
|
11872 | s0,
|
11873 | e1 = edges[halfedges[m - 1]],
|
11874 | s1 = e1.left === site ? e1.right : e1.left;
|
11875 |
|
11876 | while (++j < m) {
|
11877 | s0 = s1;
|
11878 | e1 = edges[halfedges[j]];
|
11879 | s1 = e1.left === site ? e1.right : e1.left;
|
11880 | if (i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
|
11881 | triangles.push([site.data, s0.data, s1.data]);
|
11882 | }
|
11883 | }
|
11884 | });
|
11885 |
|
11886 | return triangles;
|
11887 | },
|
11888 |
|
11889 | links: function() {
|
11890 | return this.edges.filter(function(edge) {
|
11891 | return edge.right;
|
11892 | }).map(function(edge) {
|
11893 | return {
|
11894 | source: edge.left.data,
|
11895 | target: edge.right.data
|
11896 | };
|
11897 | });
|
11898 | }
|
11899 | }
|
11900 |
|
11901 | function voronoi() {
|
11902 | var x = x$4,
|
11903 | y = y$4,
|
11904 | extent = null;
|
11905 |
|
11906 | function voronoi(data) {
|
11907 | return new Diagram(data.map(function(d, i) {
|
11908 | var s = [Math.round(x(d, i, data) / epsilon$3) * epsilon$3, Math.round(y(d, i, data) / epsilon$3) * epsilon$3];
|
11909 | s.index = i;
|
11910 | s.data = d;
|
11911 | return s;
|
11912 | }), extent);
|
11913 | }
|
11914 |
|
11915 | voronoi.polygons = function(data) {
|
11916 | return voronoi(data).polygons();
|
11917 | };
|
11918 |
|
11919 | voronoi.links = function(data) {
|
11920 | return voronoi(data).links();
|
11921 | };
|
11922 |
|
11923 | voronoi.triangles = function(data) {
|
11924 | return voronoi(data).triangles();
|
11925 | };
|
11926 |
|
11927 | voronoi.x = function(_) {
|
11928 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$8(+_), voronoi) : x;
|
11929 | };
|
11930 |
|
11931 | voronoi.y = function(_) {
|
11932 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$8(+_), voronoi) : y;
|
11933 | };
|
11934 |
|
11935 | voronoi.extent = function(_) {
|
11936 | 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]]];
|
11937 | };
|
11938 |
|
11939 | voronoi.size = function(_) {
|
11940 | return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0], extent[1][1]];
|
11941 | };
|
11942 |
|
11943 | return voronoi;
|
11944 | }
|
11945 |
|
11946 | function constant$9(x) {
|
11947 | return function() {
|
11948 | return x;
|
11949 | };
|
11950 | }
|
11951 |
|
11952 | function ZoomEvent(target, type, transform) {
|
11953 | this.target = target;
|
11954 | this.type = type;
|
11955 | this.transform = transform;
|
11956 | }
|
11957 |
|
11958 | function Transform(k, x, y) {
|
11959 | this.k = k;
|
11960 | this.x = x;
|
11961 | this.y = y;
|
11962 | }
|
11963 |
|
11964 | Transform.prototype = {
|
11965 | constructor: Transform,
|
11966 | scale: function(k) {
|
11967 | return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
|
11968 | },
|
11969 | translate: function(x, y) {
|
11970 | return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
|
11971 | },
|
11972 | apply: function(point) {
|
11973 | return [point[0] * this.k + this.x, point[1] * this.k + this.y];
|
11974 | },
|
11975 | applyX: function(x) {
|
11976 | return x * this.k + this.x;
|
11977 | },
|
11978 | applyY: function(y) {
|
11979 | return y * this.k + this.y;
|
11980 | },
|
11981 | invert: function(location) {
|
11982 | return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
|
11983 | },
|
11984 | invertX: function(x) {
|
11985 | return (x - this.x) / this.k;
|
11986 | },
|
11987 | invertY: function(y) {
|
11988 | return (y - this.y) / this.k;
|
11989 | },
|
11990 | rescaleX: function(x) {
|
11991 | return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
|
11992 | },
|
11993 | rescaleY: function(y) {
|
11994 | return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
|
11995 | },
|
11996 | toString: function() {
|
11997 | return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
|
11998 | }
|
11999 | };
|
12000 |
|
12001 | var identity$6 = new Transform(1, 0, 0);
|
12002 |
|
12003 | transform.prototype = Transform.prototype;
|
12004 |
|
12005 | function transform(node) {
|
12006 | return node.__zoom || identity$6;
|
12007 | }
|
12008 |
|
12009 | function nopropagation$1() {
|
12010 | exports.event.stopImmediatePropagation();
|
12011 | }
|
12012 |
|
12013 | function noevent$1() {
|
12014 | exports.event.preventDefault();
|
12015 | exports.event.stopImmediatePropagation();
|
12016 | }
|
12017 |
|
12018 | // Ignore right-click, since that should open the context menu.
|
12019 | function defaultFilter$1() {
|
12020 | return !exports.event.button;
|
12021 | }
|
12022 |
|
12023 | function defaultExtent() {
|
12024 | var e = this, w, h;
|
12025 | if (e instanceof SVGElement) {
|
12026 | e = e.ownerSVGElement || e;
|
12027 | w = e.width.baseVal.value;
|
12028 | h = e.height.baseVal.value;
|
12029 | } else {
|
12030 | w = e.clientWidth;
|
12031 | h = e.clientHeight;
|
12032 | }
|
12033 | return [[0, 0], [w, h]];
|
12034 | }
|
12035 |
|
12036 | function defaultTransform() {
|
12037 | return this.__zoom || identity$6;
|
12038 | }
|
12039 |
|
12040 | function zoom() {
|
12041 | var filter = defaultFilter$1,
|
12042 | extent = defaultExtent,
|
12043 | k0 = 0,
|
12044 | k1 = Infinity,
|
12045 | x0 = -k1,
|
12046 | x1 = k1,
|
12047 | y0 = x0,
|
12048 | y1 = x1,
|
12049 | duration = 250,
|
12050 | gestures = [],
|
12051 | listeners = dispatch("start", "zoom", "end"),
|
12052 | mousemoving,
|
12053 | mousePoint,
|
12054 | mouseLocation,
|
12055 | touchstarting,
|
12056 | touchending,
|
12057 | touchDelay = 500,
|
12058 | wheelTimer,
|
12059 | wheelDelay = 150;
|
12060 |
|
12061 | function zoom(selection) {
|
12062 | selection
|
12063 | .on("wheel.zoom", wheeled)
|
12064 | .on("mousedown.zoom", mousedowned)
|
12065 | .on("dblclick.zoom", dblclicked)
|
12066 | .on("touchstart.zoom", touchstarted)
|
12067 | .on("touchmove.zoom", touchmoved)
|
12068 | .on("touchend.zoom touchcancel.zoom", touchended)
|
12069 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
|
12070 | .property("__zoom", defaultTransform);
|
12071 | }
|
12072 |
|
12073 | zoom.transform = function(collection, transform) {
|
12074 | var selection = collection.selection ? collection.selection() : collection;
|
12075 | selection.property("__zoom", defaultTransform);
|
12076 | if (collection !== selection) {
|
12077 | schedule(collection, transform);
|
12078 | } else {
|
12079 | selection.interrupt().each(function() {
|
12080 | gesture(this, arguments)
|
12081 | .start()
|
12082 | .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
|
12083 | .end();
|
12084 | });
|
12085 | }
|
12086 | };
|
12087 |
|
12088 | zoom.scaleBy = function(selection, k) {
|
12089 | zoom.scaleTo(selection, function() {
|
12090 | var k0 = this.__zoom.k,
|
12091 | k1 = typeof k === "function" ? k.apply(this, arguments) : k;
|
12092 | return k0 * k1;
|
12093 | });
|
12094 | };
|
12095 |
|
12096 | zoom.scaleTo = function(selection, k) {
|
12097 | zoom.transform(selection, function() {
|
12098 | var e = extent.apply(this, arguments),
|
12099 | t0 = this.__zoom,
|
12100 | p0 = centroid(e),
|
12101 | p1 = t0.invert(p0),
|
12102 | k1 = typeof k === "function" ? k.apply(this, arguments) : k;
|
12103 | return constrain(translate(scale(t0, k1), p0, p1), e);
|
12104 | });
|
12105 | };
|
12106 |
|
12107 | zoom.translateBy = function(selection, x, y) {
|
12108 | zoom.transform(selection, function() {
|
12109 | return constrain(this.__zoom.translate(
|
12110 | typeof x === "function" ? x.apply(this, arguments) : x,
|
12111 | typeof y === "function" ? y.apply(this, arguments) : y
|
12112 | ), extent.apply(this, arguments));
|
12113 | });
|
12114 | };
|
12115 |
|
12116 | function scale(transform, k) {
|
12117 | k = Math.max(k0, Math.min(k1, k));
|
12118 | return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
|
12119 | }
|
12120 |
|
12121 | function translate(transform, p0, p1) {
|
12122 | var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
|
12123 | return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
|
12124 | }
|
12125 |
|
12126 | function constrain(transform, extent) {
|
12127 | var dx = Math.min(0, transform.invertX(extent[0][0]) - x0) || Math.max(0, transform.invertX(extent[1][0]) - x1),
|
12128 | dy = Math.min(0, transform.invertY(extent[0][1]) - y0) || Math.max(0, transform.invertY(extent[1][1]) - y1);
|
12129 | return dx || dy ? transform.translate(dx, dy) : transform;
|
12130 | }
|
12131 |
|
12132 | function centroid(extent) {
|
12133 | return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
|
12134 | }
|
12135 |
|
12136 | function schedule(transition, transform, center) {
|
12137 | transition
|
12138 | .on("start.zoom", function() { gesture(this, arguments).start(); })
|
12139 | .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
|
12140 | .tween("zoom", function() {
|
12141 | var that = this,
|
12142 | args = arguments,
|
12143 | g = gesture(that, args),
|
12144 | e = extent.apply(that, args),
|
12145 | p = center || centroid(e),
|
12146 | w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
|
12147 | a = that.__zoom,
|
12148 | b = typeof transform === "function" ? transform.apply(that, args) : transform,
|
12149 | i = interpolateZoom(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
|
12150 | return function(t) {
|
12151 | if (t === 1) t = b; // Avoid rounding error on end.
|
12152 | else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
|
12153 | g.zoom(null, t);
|
12154 | };
|
12155 | });
|
12156 | }
|
12157 |
|
12158 | function gesture(that, args) {
|
12159 | for (var i = 0, n = gestures.length, g; i < n; ++i) {
|
12160 | if ((g = gestures[i]).that === that) {
|
12161 | return g;
|
12162 | }
|
12163 | }
|
12164 | return new Gesture(that, args);
|
12165 | }
|
12166 |
|
12167 | function Gesture(that, args) {
|
12168 | this.that = that;
|
12169 | this.args = args;
|
12170 | this.index = -1;
|
12171 | this.active = 0;
|
12172 | }
|
12173 |
|
12174 | Gesture.prototype = {
|
12175 | start: function() {
|
12176 | if (++this.active === 1) {
|
12177 | this.index = gestures.push(this) - 1;
|
12178 | this.emit("start");
|
12179 | }
|
12180 | return this;
|
12181 | },
|
12182 | zoom: function(key, transform) {
|
12183 | if (mousePoint && key !== "mouse") mouseLocation = transform.invert(mousePoint);
|
12184 | if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
|
12185 | if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
|
12186 | this.that.__zoom = transform;
|
12187 | this.emit("zoom");
|
12188 | return this;
|
12189 | },
|
12190 | end: function() {
|
12191 | if (--this.active === 0) {
|
12192 | gestures.splice(this.index, 1);
|
12193 | mousePoint = mouseLocation = null;
|
12194 | this.index = -1;
|
12195 | this.emit("end");
|
12196 | }
|
12197 | return this;
|
12198 | },
|
12199 | emit: function(type) {
|
12200 | customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
|
12201 | }
|
12202 | };
|
12203 |
|
12204 | function wheeled() {
|
12205 | if (!filter.apply(this, arguments)) return;
|
12206 | var g = gesture(this, arguments),
|
12207 | t = this.__zoom,
|
12208 | k = Math.max(k0, Math.min(k1, t.k * Math.pow(2, -exports.event.deltaY * (exports.event.deltaMode ? 120 : 1) / 500)));
|
12209 |
|
12210 | // If the mouse is in the same location as before, reuse it.
|
12211 | // If there were recent wheel events, reset the wheel idle timeout.
|
12212 | if (wheelTimer) {
|
12213 | var point = mouse(this);
|
12214 | if (mousePoint[0] !== point[0] || mousePoint[1] !== point[1]) {
|
12215 | mouseLocation = t.invert(mousePoint = point);
|
12216 | }
|
12217 | clearTimeout(wheelTimer);
|
12218 | }
|
12219 |
|
12220 | // If this wheel event won’t trigger a transform change, ignore it.
|
12221 | else if (t.k === k) return;
|
12222 |
|
12223 | // Otherwise, capture the mouse point and location at the start.
|
12224 | else {
|
12225 | g.extent = extent.apply(this, arguments);
|
12226 | mouseLocation = t.invert(mousePoint = mouse(this));
|
12227 | interrupt(this);
|
12228 | g.start();
|
12229 | }
|
12230 |
|
12231 | noevent$1();
|
12232 | wheelTimer = setTimeout(wheelidled, wheelDelay);
|
12233 | g.zoom("mouse", constrain(translate(scale(t, k), mousePoint, mouseLocation), g.extent));
|
12234 |
|
12235 | function wheelidled() {
|
12236 | wheelTimer = null;
|
12237 | g.end();
|
12238 | }
|
12239 | }
|
12240 |
|
12241 | function mousedowned() {
|
12242 | if (touchending || !filter.apply(this, arguments)) return;
|
12243 | var g = gesture(this, arguments),
|
12244 | v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true);
|
12245 |
|
12246 | dragDisable(exports.event.view);
|
12247 | nopropagation$1();
|
12248 | mousemoving = false;
|
12249 | g.extent = extent.apply(this, arguments);
|
12250 | mouseLocation = this.__zoom.invert(mousePoint = mouse(this));
|
12251 | interrupt(this);
|
12252 | g.start();
|
12253 |
|
12254 | function mousemoved() {
|
12255 | noevent$1();
|
12256 | mousemoving = true;
|
12257 | g.zoom("mouse", constrain(translate(g.that.__zoom, mousePoint = mouse(g.that), mouseLocation), g.extent));
|
12258 | }
|
12259 |
|
12260 | function mouseupped() {
|
12261 | v.on("mousemove.zoom mouseup.zoom", null);
|
12262 | dragEnable(exports.event.view, mousemoving);
|
12263 | noevent$1();
|
12264 | g.end();
|
12265 | }
|
12266 | }
|
12267 |
|
12268 | function dblclicked() {
|
12269 | if (!filter.apply(this, arguments)) return;
|
12270 | var t0 = this.__zoom,
|
12271 | p0 = mouse(this),
|
12272 | p1 = t0.invert(p0),
|
12273 | k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
|
12274 | t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments));
|
12275 |
|
12276 | noevent$1();
|
12277 | if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
|
12278 | else select(this).call(zoom.transform, t1);
|
12279 | }
|
12280 |
|
12281 | function touchstarted() {
|
12282 | if (!filter.apply(this, arguments)) return;
|
12283 | var g = gesture(this, arguments),
|
12284 | touches = exports.event.changedTouches,
|
12285 | n = touches.length, i, t, p;
|
12286 |
|
12287 | nopropagation$1();
|
12288 | for (i = 0; i < n; ++i) {
|
12289 | t = touches[i], p = touch(this, touches, t.identifier);
|
12290 | p = [p, this.__zoom.invert(p), t.identifier];
|
12291 | if (!g.touch0) g.touch0 = p;
|
12292 | else if (!g.touch1) g.touch1 = p;
|
12293 | }
|
12294 | if (touchstarting) {
|
12295 | touchstarting = clearTimeout(touchstarting);
|
12296 | if (!g.touch1) return g.end(), dblclicked.apply(this, arguments);
|
12297 | }
|
12298 | if (exports.event.touches.length === n) {
|
12299 | touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
|
12300 | interrupt(this);
|
12301 | g.extent = extent.apply(this, arguments);
|
12302 | g.start();
|
12303 | }
|
12304 | }
|
12305 |
|
12306 | function touchmoved() {
|
12307 | var g = gesture(this, arguments),
|
12308 | touches = exports.event.changedTouches,
|
12309 | n = touches.length, i, t, p, l;
|
12310 |
|
12311 | noevent$1();
|
12312 | if (touchstarting) touchstarting = clearTimeout(touchstarting);
|
12313 | for (i = 0; i < n; ++i) {
|
12314 | t = touches[i], p = touch(this, touches, t.identifier);
|
12315 | if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
|
12316 | else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
|
12317 | }
|
12318 | t = g.that.__zoom;
|
12319 | if (g.touch1) {
|
12320 | var p0 = g.touch0[0], l0 = g.touch0[1],
|
12321 | p1 = g.touch1[0], l1 = g.touch1[1],
|
12322 | dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
|
12323 | dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
|
12324 | t = scale(t, Math.sqrt(dp / dl));
|
12325 | p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
|
12326 | l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
|
12327 | }
|
12328 | else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
|
12329 | else return;
|
12330 | g.zoom("touch", constrain(translate(t, p, l), g.extent));
|
12331 | }
|
12332 |
|
12333 | function touchended() {
|
12334 | var g = gesture(this, arguments),
|
12335 | touches = exports.event.changedTouches,
|
12336 | n = touches.length, i, t;
|
12337 |
|
12338 | nopropagation$1();
|
12339 | if (touchending) clearTimeout(touchending);
|
12340 | touchending = setTimeout(function() { touchending = null; }, touchDelay);
|
12341 | for (i = 0; i < n; ++i) {
|
12342 | t = touches[i];
|
12343 | if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
|
12344 | else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
|
12345 | }
|
12346 | if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
|
12347 | if (!g.touch0) g.end();
|
12348 | }
|
12349 |
|
12350 | zoom.filter = function(_) {
|
12351 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), zoom) : filter;
|
12352 | };
|
12353 |
|
12354 | zoom.extent = function(_) {
|
12355 | return arguments.length ? (extent = typeof _ === "function" ? _ : constant$9([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
|
12356 | };
|
12357 |
|
12358 | zoom.scaleExtent = function(_) {
|
12359 | return arguments.length ? (k0 = +_[0], k1 = +_[1], zoom) : [k0, k1];
|
12360 | };
|
12361 |
|
12362 | zoom.translateExtent = function(_) {
|
12363 | return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], zoom) : [[x0, y0], [x1, y1]];
|
12364 | };
|
12365 |
|
12366 | zoom.duration = function(_) {
|
12367 | return arguments.length ? (duration = +_, zoom) : duration;
|
12368 | };
|
12369 |
|
12370 | zoom.on = function() {
|
12371 | var value = listeners.on.apply(listeners, arguments);
|
12372 | return value === listeners ? zoom : value;
|
12373 | };
|
12374 |
|
12375 | return zoom;
|
12376 | }
|
12377 |
|
12378 | function constant$10(x) {
|
12379 | return function() {
|
12380 | return x;
|
12381 | };
|
12382 | }
|
12383 |
|
12384 | function BrushEvent(target, type, selection) {
|
12385 | this.target = target;
|
12386 | this.type = type;
|
12387 | this.selection = selection;
|
12388 | }
|
12389 |
|
12390 | function nopropagation$2() {
|
12391 | exports.event.stopImmediatePropagation();
|
12392 | }
|
12393 |
|
12394 | function noevent$2() {
|
12395 | exports.event.preventDefault();
|
12396 | exports.event.stopImmediatePropagation();
|
12397 | }
|
12398 |
|
12399 | var MODE_DRAG = {name: "drag"};
|
12400 | var MODE_SPACE = {name: "space"};
|
12401 | var MODE_HANDLE = {name: "handle"};
|
12402 | var MODE_CENTER = {name: "center"};
|
12403 | var X = {
|
12404 | name: "x",
|
12405 | handles: ["e", "w"].map(type$1),
|
12406 | input: function(x, e) { return x && [[x[0], e[0][1]], [x[1], e[1][1]]]; },
|
12407 | output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
|
12408 | };
|
12409 |
|
12410 | var Y = {
|
12411 | name: "y",
|
12412 | handles: ["n", "s"].map(type$1),
|
12413 | input: function(y, e) { return y && [[e[0][0], y[0]], [e[1][0], y[1]]]; },
|
12414 | output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
|
12415 | };
|
12416 |
|
12417 | var XY = {
|
12418 | name: "xy",
|
12419 | handles: ["n", "e", "s", "w", "nw", "ne", "se", "sw"].map(type$1),
|
12420 | input: function(xy) { return xy; },
|
12421 | output: function(xy) { return xy; }
|
12422 | };
|
12423 |
|
12424 | var cursors = {
|
12425 | overlay: "crosshair",
|
12426 | selection: "move",
|
12427 | n: "ns-resize",
|
12428 | e: "ew-resize",
|
12429 | s: "ns-resize",
|
12430 | w: "ew-resize",
|
12431 | nw: "nwse-resize",
|
12432 | ne: "nesw-resize",
|
12433 | se: "nwse-resize",
|
12434 | sw: "nesw-resize"
|
12435 | };
|
12436 |
|
12437 | var flipX = {
|
12438 | e: "w",
|
12439 | w: "e",
|
12440 | nw: "ne",
|
12441 | ne: "nw",
|
12442 | se: "sw",
|
12443 | sw: "se"
|
12444 | };
|
12445 |
|
12446 | var flipY = {
|
12447 | n: "s",
|
12448 | s: "n",
|
12449 | nw: "sw",
|
12450 | ne: "se",
|
12451 | se: "ne",
|
12452 | sw: "nw"
|
12453 | };
|
12454 |
|
12455 | var signsX = {
|
12456 | overlay: +1,
|
12457 | selection: +1,
|
12458 | n: null,
|
12459 | e: +1,
|
12460 | s: null,
|
12461 | w: -1,
|
12462 | nw: -1,
|
12463 | ne: +1,
|
12464 | se: +1,
|
12465 | sw: -1
|
12466 | };
|
12467 |
|
12468 | var signsY = {
|
12469 | overlay: +1,
|
12470 | selection: +1,
|
12471 | n: -1,
|
12472 | e: null,
|
12473 | s: +1,
|
12474 | w: null,
|
12475 | nw: -1,
|
12476 | ne: -1,
|
12477 | se: +1,
|
12478 | sw: +1
|
12479 | };
|
12480 |
|
12481 | function type$1(t) {
|
12482 | return {type: t};
|
12483 | }
|
12484 |
|
12485 | // Ignore right-click, since that should open the context menu.
|
12486 | function defaultFilter$2() {
|
12487 | return !exports.event.button;
|
12488 | }
|
12489 |
|
12490 | function defaultExtent$1() {
|
12491 | var svg = this.ownerSVGElement || this;
|
12492 | return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
|
12493 | }
|
12494 |
|
12495 | // Like d3.local, but with the name “__brush” rather than auto-generated.
|
12496 | function local$1(node) {
|
12497 | while (!node.__brush) if (!(node = node.parentNode)) return;
|
12498 | return node.__brush;
|
12499 | }
|
12500 |
|
12501 | function empty$1(extent) {
|
12502 | return extent[0][0] === extent[1][0]
|
12503 | || extent[0][1] === extent[1][1];
|
12504 | }
|
12505 |
|
12506 | function brushSelection(node) {
|
12507 | var state = node.__brush;
|
12508 | return state ? state.dim.output(state.selection) : null;
|
12509 | }
|
12510 |
|
12511 | function brushX() {
|
12512 | return brush$1(X);
|
12513 | }
|
12514 |
|
12515 | function brushY() {
|
12516 | return brush$1(Y);
|
12517 | }
|
12518 |
|
12519 | function brush() {
|
12520 | return brush$1(XY);
|
12521 | }
|
12522 |
|
12523 | function brush$1(dim) {
|
12524 | var extent = defaultExtent$1,
|
12525 | filter = defaultFilter$2,
|
12526 | listeners = dispatch(brush, "start", "brush", "end"),
|
12527 | handleSize = 6,
|
12528 | touchending;
|
12529 |
|
12530 | function brush(group) {
|
12531 | var overlay = group
|
12532 | .property("__brush", initialize)
|
12533 | .selectAll(".overlay")
|
12534 | .data([type$1("overlay")]);
|
12535 |
|
12536 | overlay.enter().append("rect")
|
12537 | .attr("class", "overlay")
|
12538 | .attr("pointer-events", "all")
|
12539 | .attr("cursor", cursors.overlay)
|
12540 | .merge(overlay)
|
12541 | .each(function() {
|
12542 | var extent = local$1(this).extent;
|
12543 | select(this)
|
12544 | .attr("x", extent[0][0])
|
12545 | .attr("y", extent[0][1])
|
12546 | .attr("width", extent[1][0] - extent[0][0])
|
12547 | .attr("height", extent[1][1] - extent[0][1]);
|
12548 | });
|
12549 |
|
12550 | group.selectAll(".selection")
|
12551 | .data([type$1("selection")])
|
12552 | .enter().append("rect")
|
12553 | .attr("class", "selection")
|
12554 | .attr("cursor", cursors.selection)
|
12555 | .attr("fill", "#777")
|
12556 | .attr("fill-opacity", 0.3)
|
12557 | .attr("stroke", "#fff")
|
12558 | .attr("shape-rendering", "crispEdges");
|
12559 |
|
12560 | var handle = group.selectAll(".handle")
|
12561 | .data(dim.handles, function(d) { return d.type; });
|
12562 |
|
12563 | handle.exit().remove();
|
12564 |
|
12565 | handle.enter().append("rect")
|
12566 | .attr("class", function(d) { return "handle handle--" + d.type; })
|
12567 | .attr("cursor", function(d) { return cursors[d.type]; });
|
12568 |
|
12569 | group
|
12570 | .each(redraw)
|
12571 | .attr("fill", "none")
|
12572 | .attr("pointer-events", "all")
|
12573 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
|
12574 | .on("mousedown.brush touchstart.brush", started);
|
12575 | }
|
12576 |
|
12577 | brush.move = function(group, selection) {
|
12578 | if (group.selection) {
|
12579 | group
|
12580 | .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
|
12581 | .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
|
12582 | .tween("brush", function() {
|
12583 | var that = this,
|
12584 | state = that.__brush,
|
12585 | emit = emitter(that, arguments),
|
12586 | selection0 = state.selection,
|
12587 | selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
|
12588 | i = interpolate(selection0, selection1);
|
12589 |
|
12590 | function tween(t) {
|
12591 | state.selection = t === 1 && empty$1(selection1) ? null : i(t);
|
12592 | redraw.call(that);
|
12593 | emit.brush();
|
12594 | }
|
12595 |
|
12596 | return selection0 && selection1 ? tween : tween(1);
|
12597 | });
|
12598 | } else {
|
12599 | group
|
12600 | .each(function() {
|
12601 | var that = this,
|
12602 | args = arguments,
|
12603 | state = that.__brush,
|
12604 | selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
|
12605 | emit = emitter(that, args).beforestart();
|
12606 |
|
12607 | interrupt(that);
|
12608 | state.selection = selection1 == null || empty$1(selection1) ? null : selection1;
|
12609 | redraw.call(that);
|
12610 | emit.start().brush().end();
|
12611 | });
|
12612 | }
|
12613 | };
|
12614 |
|
12615 | function redraw() {
|
12616 | var group = select(this),
|
12617 | selection = local$1(this).selection;
|
12618 |
|
12619 | if (selection) {
|
12620 | group.selectAll(".selection")
|
12621 | .style("display", null)
|
12622 | .attr("x", selection[0][0])
|
12623 | .attr("y", selection[0][1])
|
12624 | .attr("width", selection[1][0] - selection[0][0])
|
12625 | .attr("height", selection[1][1] - selection[0][1]);
|
12626 |
|
12627 | group.selectAll(".handle")
|
12628 | .style("display", null)
|
12629 | .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
|
12630 | .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
|
12631 | .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
|
12632 | .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
|
12633 | }
|
12634 |
|
12635 | else {
|
12636 | group.selectAll(".selection,.handle")
|
12637 | .style("display", "none")
|
12638 | .attr("x", null)
|
12639 | .attr("y", null)
|
12640 | .attr("width", null)
|
12641 | .attr("height", null);
|
12642 | }
|
12643 | }
|
12644 |
|
12645 | function emitter(that, args) {
|
12646 | return that.__brush.emitter || new Emitter(that, args);
|
12647 | }
|
12648 |
|
12649 | function Emitter(that, args) {
|
12650 | this.that = that;
|
12651 | this.args = args;
|
12652 | this.state = that.__brush;
|
12653 | this.active = 0;
|
12654 | }
|
12655 |
|
12656 | Emitter.prototype = {
|
12657 | beforestart: function() {
|
12658 | if (++this.active === 1) this.state.emitter = this, this.starting = true;
|
12659 | return this;
|
12660 | },
|
12661 | start: function() {
|
12662 | if (this.starting) this.starting = false, this.emit("start");
|
12663 | return this;
|
12664 | },
|
12665 | brush: function() {
|
12666 | this.emit("brush");
|
12667 | return this;
|
12668 | },
|
12669 | end: function() {
|
12670 | if (--this.active === 0) delete this.state.emitter, this.emit("end");
|
12671 | return this;
|
12672 | },
|
12673 | emit: function(type) {
|
12674 | customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
|
12675 | }
|
12676 | };
|
12677 |
|
12678 | function started() {
|
12679 | if (exports.event.touches) { if (exports.event.changedTouches.length < exports.event.touches.length) return noevent$2(); }
|
12680 | else if (touchending) return;
|
12681 | if (!filter.apply(this, arguments)) return;
|
12682 |
|
12683 | var that = this,
|
12684 | type = exports.event.target.__data__.type,
|
12685 | mode = (exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
|
12686 | signX = dim === Y ? null : signsX[type],
|
12687 | signY = dim === X ? null : signsY[type],
|
12688 | state = local$1(that),
|
12689 | extent = state.extent,
|
12690 | selection = state.selection,
|
12691 | W = extent[0][0], w0, w1,
|
12692 | N = extent[0][1], n0, n1,
|
12693 | E = extent[1][0], e0, e1,
|
12694 | S = extent[1][1], s0, s1,
|
12695 | dx,
|
12696 | dy,
|
12697 | moving,
|
12698 | shifting = signX && signY && exports.event.shiftKey,
|
12699 | lockX,
|
12700 | lockY,
|
12701 | point0 = mouse(that),
|
12702 | point = point0,
|
12703 | emit = emitter(that, arguments).beforestart();
|
12704 |
|
12705 | if (type === "overlay") {
|
12706 | state.selection = selection = [
|
12707 | [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
|
12708 | [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
|
12709 | ];
|
12710 | } else {
|
12711 | w0 = selection[0][0];
|
12712 | n0 = selection[0][1];
|
12713 | e0 = selection[1][0];
|
12714 | s0 = selection[1][1];
|
12715 | }
|
12716 |
|
12717 | w1 = w0;
|
12718 | n1 = n0;
|
12719 | e1 = e0;
|
12720 | s1 = s0;
|
12721 |
|
12722 | var group = select(that)
|
12723 | .attr("pointer-events", "none");
|
12724 |
|
12725 | var overlay = group.selectAll(".overlay")
|
12726 | .attr("cursor", cursors[type]);
|
12727 |
|
12728 | if (exports.event.touches) {
|
12729 | group
|
12730 | .on("touchmove.brush", moved, true)
|
12731 | .on("touchend.brush touchcancel.brush", ended, true);
|
12732 | } else {
|
12733 | var view = select(exports.event.view)
|
12734 | .on("keydown.brush", keydowned, true)
|
12735 | .on("keyup.brush", keyupped, true)
|
12736 | .on("mousemove.brush", moved, true)
|
12737 | .on("mouseup.brush", ended, true);
|
12738 |
|
12739 | dragDisable(exports.event.view);
|
12740 | }
|
12741 |
|
12742 | nopropagation$2();
|
12743 | interrupt(that);
|
12744 | redraw.call(that);
|
12745 | emit.start();
|
12746 |
|
12747 | function moved() {
|
12748 | var point1 = mouse(that);
|
12749 | if (shifting && !lockX && !lockY) {
|
12750 | if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
|
12751 | else lockX = true;
|
12752 | }
|
12753 | point = point1;
|
12754 | moving = true;
|
12755 | noevent$2();
|
12756 | move();
|
12757 | }
|
12758 |
|
12759 | function move() {
|
12760 | var t;
|
12761 |
|
12762 | dx = point[0] - point0[0];
|
12763 | dy = point[1] - point0[1];
|
12764 |
|
12765 | switch (mode) {
|
12766 | case MODE_SPACE:
|
12767 | case MODE_DRAG: {
|
12768 | if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
|
12769 | if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
|
12770 | break;
|
12771 | }
|
12772 | case MODE_HANDLE: {
|
12773 | if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
|
12774 | else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
|
12775 | if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
|
12776 | else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
|
12777 | break;
|
12778 | }
|
12779 | case MODE_CENTER: {
|
12780 | if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
|
12781 | if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
|
12782 | break;
|
12783 | }
|
12784 | }
|
12785 |
|
12786 | if (e1 < w1) {
|
12787 | signX *= -1;
|
12788 | t = w0, w0 = e0, e0 = t;
|
12789 | t = w1, w1 = e1, e1 = t;
|
12790 | if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
|
12791 | }
|
12792 |
|
12793 | if (s1 < n1) {
|
12794 | signY *= -1;
|
12795 | t = n0, n0 = s0, s0 = t;
|
12796 | t = n1, n1 = s1, s1 = t;
|
12797 | if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
|
12798 | }
|
12799 |
|
12800 | selection = state.selection; // May be set by brush.move!
|
12801 |
|
12802 | if (lockX) w1 = selection[0][0], e1 = selection[1][0];
|
12803 | if (lockY) n1 = selection[0][1], s1 = selection[1][1];
|
12804 |
|
12805 | if (selection[0][0] !== w1
|
12806 | || selection[0][1] !== n1
|
12807 | || selection[1][0] !== e1
|
12808 | || selection[1][1] !== s1) {
|
12809 | state.selection = [[w1, n1], [e1, s1]];
|
12810 | redraw.call(that);
|
12811 | emit.brush();
|
12812 | }
|
12813 | }
|
12814 |
|
12815 | function ended() {
|
12816 | nopropagation$2();
|
12817 | if (exports.event.touches) {
|
12818 | if (exports.event.touches.length) return;
|
12819 | if (touchending) clearTimeout(touchending);
|
12820 | touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
|
12821 | group.on("touchmove.brush touchend.brush touchcancel.brush", null);
|
12822 | } else {
|
12823 | dragEnable(exports.event.view, moving);
|
12824 | view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
|
12825 | }
|
12826 | group.attr("pointer-events", "all");
|
12827 | overlay.attr("cursor", cursors.overlay);
|
12828 | if (empty$1(selection)) state.selection = null, redraw.call(that);
|
12829 | emit.end();
|
12830 | }
|
12831 |
|
12832 | function keydowned() {
|
12833 | switch (exports.event.keyCode) {
|
12834 | case 16: { // SHIFT
|
12835 | shifting = signX && signY;
|
12836 | break;
|
12837 | }
|
12838 | case 18: { // ALT
|
12839 | if (mode === MODE_HANDLE) {
|
12840 | if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
|
12841 | if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
|
12842 | mode = MODE_CENTER;
|
12843 | move();
|
12844 | }
|
12845 | break;
|
12846 | }
|
12847 | case 32: { // SPACE; takes priority over ALT
|
12848 | if (mode === MODE_HANDLE || mode === MODE_CENTER) {
|
12849 | if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
|
12850 | if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
|
12851 | mode = MODE_SPACE;
|
12852 | overlay.attr("cursor", cursors.selection);
|
12853 | move();
|
12854 | }
|
12855 | break;
|
12856 | }
|
12857 | default: return;
|
12858 | }
|
12859 | noevent$2();
|
12860 | }
|
12861 |
|
12862 | function keyupped() {
|
12863 | switch (exports.event.keyCode) {
|
12864 | case 16: { // SHIFT
|
12865 | if (shifting) {
|
12866 | lockX = lockY = shifting = false;
|
12867 | move();
|
12868 | }
|
12869 | break;
|
12870 | }
|
12871 | case 18: { // ALT
|
12872 | if (mode === MODE_CENTER) {
|
12873 | if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
|
12874 | if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
|
12875 | mode = MODE_HANDLE;
|
12876 | move();
|
12877 | }
|
12878 | break;
|
12879 | }
|
12880 | case 32: { // SPACE
|
12881 | if (mode === MODE_SPACE) {
|
12882 | if (exports.event.altKey) {
|
12883 | if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
|
12884 | if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
|
12885 | mode = MODE_CENTER;
|
12886 | } else {
|
12887 | if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
|
12888 | if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
|
12889 | mode = MODE_HANDLE;
|
12890 | }
|
12891 | overlay.attr("cursor", cursors[type]);
|
12892 | move();
|
12893 | }
|
12894 | break;
|
12895 | }
|
12896 | default: return;
|
12897 | }
|
12898 | noevent$2();
|
12899 | }
|
12900 | }
|
12901 |
|
12902 | function initialize() {
|
12903 | var state = this.__brush || {selection: null};
|
12904 | state.extent = extent.apply(this, arguments);
|
12905 | state.dim = dim;
|
12906 | return state;
|
12907 | }
|
12908 |
|
12909 | brush.extent = function(_) {
|
12910 | return arguments.length ? (extent = typeof _ === "function" ? _ : constant$10([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), brush) : extent;
|
12911 | };
|
12912 |
|
12913 | brush.filter = function(_) {
|
12914 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$10(!!_), brush) : filter;
|
12915 | };
|
12916 |
|
12917 | brush.handleSize = function(_) {
|
12918 | return arguments.length ? (handleSize = +_, brush) : handleSize;
|
12919 | };
|
12920 |
|
12921 | brush.on = function() {
|
12922 | var value = listeners.on.apply(listeners, arguments);
|
12923 | return value === listeners ? brush : value;
|
12924 | };
|
12925 |
|
12926 | return brush;
|
12927 | }
|
12928 |
|
12929 | // Adds floating point numbers with twice the normal precision.
|
12930 | // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
|
12931 | // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
|
12932 | // 305–363 (1997).
|
12933 | // Code adapted from GeographicLib by Charles F. F. Karney,
|
12934 | // http://geographiclib.sourceforge.net/
|
12935 |
|
12936 | function adder() {
|
12937 | return new Adder;
|
12938 | }
|
12939 |
|
12940 | function Adder() {
|
12941 | this.reset();
|
12942 | }
|
12943 |
|
12944 | Adder.prototype = {
|
12945 | constructor: Adder,
|
12946 | reset: function() {
|
12947 | this.s = // rounded value
|
12948 | this.t = 0; // exact error
|
12949 | },
|
12950 | add: function(y) {
|
12951 | add$1(temp, y, this.t);
|
12952 | add$1(this, temp.s, this.s);
|
12953 | if (this.s) this.t += temp.t;
|
12954 | else this.s = temp.t;
|
12955 | },
|
12956 | valueOf: function() {
|
12957 | return this.s;
|
12958 | }
|
12959 | };
|
12960 |
|
12961 | var temp = new Adder;
|
12962 |
|
12963 | function add$1(adder, a, b) {
|
12964 | var x = adder.s = a + b,
|
12965 | bv = x - a,
|
12966 | av = x - bv;
|
12967 | adder.t = (a - av) + (b - bv);
|
12968 | }
|
12969 |
|
12970 | var epsilon$4 = 1e-6;
|
12971 | var epsilon2$2 = 1e-12;
|
12972 | var pi$3 = Math.PI;
|
12973 | var halfPi$2 = pi$3 / 2;
|
12974 | var quarterPi = pi$3 / 4;
|
12975 | var tau$3 = pi$3 * 2;
|
12976 |
|
12977 | var degrees$1 = 180 / pi$3;
|
12978 | var radians = pi$3 / 180;
|
12979 |
|
12980 | var abs = Math.abs;
|
12981 | var atan = Math.atan;
|
12982 | var atan2 = Math.atan2;
|
12983 | var cos = Math.cos;
|
12984 | var ceil = Math.ceil;
|
12985 | var exp = Math.exp;
|
12986 | var log$1 = Math.log;
|
12987 | var pow$1 = Math.pow;
|
12988 | var sin = Math.sin;
|
12989 | var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
|
12990 | var sqrt$1 = Math.sqrt;
|
12991 | var tan = Math.tan;
|
12992 |
|
12993 | function acos(x) {
|
12994 | return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
|
12995 | }
|
12996 |
|
12997 | function asin$1(x) {
|
12998 | return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
|
12999 | }
|
13000 |
|
13001 | function haversin(x) {
|
13002 | return (x = sin(x / 2)) * x;
|
13003 | }
|
13004 |
|
13005 | function noop$2() {}
|
13006 |
|
13007 | function streamGeometry(geometry, stream) {
|
13008 | if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
|
13009 | streamGeometryType[geometry.type](geometry, stream);
|
13010 | }
|
13011 | }
|
13012 |
|
13013 | var streamObjectType = {
|
13014 | Feature: function(feature, stream) {
|
13015 | streamGeometry(feature.geometry, stream);
|
13016 | },
|
13017 | FeatureCollection: function(object, stream) {
|
13018 | var features = object.features, i = -1, n = features.length;
|
13019 | while (++i < n) streamGeometry(features[i].geometry, stream);
|
13020 | }
|
13021 | };
|
13022 |
|
13023 | var streamGeometryType = {
|
13024 | Sphere: function(object, stream) {
|
13025 | stream.sphere();
|
13026 | },
|
13027 | Point: function(object, stream) {
|
13028 | object = object.coordinates;
|
13029 | stream.point(object[0], object[1], object[2]);
|
13030 | },
|
13031 | MultiPoint: function(object, stream) {
|
13032 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
13033 | while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
|
13034 | },
|
13035 | LineString: function(object, stream) {
|
13036 | streamLine(object.coordinates, stream, 0);
|
13037 | },
|
13038 | MultiLineString: function(object, stream) {
|
13039 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
13040 | while (++i < n) streamLine(coordinates[i], stream, 0);
|
13041 | },
|
13042 | Polygon: function(object, stream) {
|
13043 | streamPolygon(object.coordinates, stream);
|
13044 | },
|
13045 | MultiPolygon: function(object, stream) {
|
13046 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
13047 | while (++i < n) streamPolygon(coordinates[i], stream);
|
13048 | },
|
13049 | GeometryCollection: function(object, stream) {
|
13050 | var geometries = object.geometries, i = -1, n = geometries.length;
|
13051 | while (++i < n) streamGeometry(geometries[i], stream);
|
13052 | }
|
13053 | };
|
13054 |
|
13055 | function streamLine(coordinates, stream, closed) {
|
13056 | var i = -1, n = coordinates.length - closed, coordinate;
|
13057 | stream.lineStart();
|
13058 | while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
|
13059 | stream.lineEnd();
|
13060 | }
|
13061 |
|
13062 | function streamPolygon(coordinates, stream) {
|
13063 | var i = -1, n = coordinates.length;
|
13064 | stream.polygonStart();
|
13065 | while (++i < n) streamLine(coordinates[i], stream, 1);
|
13066 | stream.polygonEnd();
|
13067 | }
|
13068 |
|
13069 | function stream(object, stream) {
|
13070 | if (object && streamObjectType.hasOwnProperty(object.type)) {
|
13071 | streamObjectType[object.type](object, stream);
|
13072 | } else {
|
13073 | streamGeometry(object, stream);
|
13074 | }
|
13075 | }
|
13076 |
|
13077 | var areaRingSum;
|
13078 |
|
13079 | var areaSum;
|
13080 | var lambda00;
|
13081 | var phi00;
|
13082 | var lambda0;
|
13083 | var cosPhi0;
|
13084 | var sinPhi0;
|
13085 | var areaStream = {
|
13086 | point: noop$2,
|
13087 | lineStart: noop$2,
|
13088 | lineEnd: noop$2,
|
13089 | polygonStart: function() {
|
13090 | areaRingSum.reset();
|
13091 | areaStream.lineStart = areaRingStart;
|
13092 | areaStream.lineEnd = areaRingEnd;
|
13093 | },
|
13094 | polygonEnd: function() {
|
13095 | var areaRing = +areaRingSum;
|
13096 | areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
|
13097 | this.lineStart = this.lineEnd = this.point = noop$2;
|
13098 | },
|
13099 | sphere: function() {
|
13100 | areaSum.add(tau$3);
|
13101 | }
|
13102 | };
|
13103 |
|
13104 | function areaRingStart() {
|
13105 | areaStream.point = areaPointFirst;
|
13106 | }
|
13107 |
|
13108 | function areaRingEnd() {
|
13109 | areaPoint(lambda00, phi00);
|
13110 | }
|
13111 |
|
13112 | function areaPointFirst(lambda, phi) {
|
13113 | areaStream.point = areaPoint;
|
13114 | lambda00 = lambda, phi00 = phi;
|
13115 | lambda *= radians, phi *= radians;
|
13116 | lambda0 = lambda, cosPhi0 = cos(phi = phi / 2 + quarterPi), sinPhi0 = sin(phi);
|
13117 | }
|
13118 |
|
13119 | function areaPoint(lambda, phi) {
|
13120 | lambda *= radians, phi *= radians;
|
13121 | phi = phi / 2 + quarterPi; // half the angular distance from south pole
|
13122 |
|
13123 | // Spherical excess E for a spherical triangle with vertices: south pole,
|
13124 | // previous point, current point. Uses a formula derived from Cagnoli’s
|
13125 | // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
|
13126 | var dLambda = lambda - lambda0,
|
13127 | sdLambda = dLambda >= 0 ? 1 : -1,
|
13128 | adLambda = sdLambda * dLambda,
|
13129 | cosPhi = cos(phi),
|
13130 | sinPhi = sin(phi),
|
13131 | k = sinPhi0 * sinPhi,
|
13132 | u = cosPhi0 * cosPhi + k * cos(adLambda),
|
13133 | v = k * sdLambda * sin(adLambda);
|
13134 | areaRingSum.add(atan2(v, u));
|
13135 |
|
13136 | // Advance the previous points.
|
13137 | lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
|
13138 | }
|
13139 |
|
13140 | function area$2(object) {
|
13141 | if (areaSum) areaSum.reset();
|
13142 | else areaSum = adder(), areaRingSum = adder();
|
13143 | stream(object, areaStream);
|
13144 | return areaSum * 2;
|
13145 | }
|
13146 |
|
13147 | function spherical(cartesian) {
|
13148 | return [atan2(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
|
13149 | }
|
13150 |
|
13151 | function cartesian(spherical) {
|
13152 | var lambda = spherical[0], phi = spherical[1], cosPhi = cos(phi);
|
13153 | return [cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi)];
|
13154 | }
|
13155 |
|
13156 | function cartesianDot(a, b) {
|
13157 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
13158 | }
|
13159 |
|
13160 | function cartesianCross(a, b) {
|
13161 | 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]];
|
13162 | }
|
13163 |
|
13164 | // TODO return a
|
13165 | function cartesianAddInPlace(a, b) {
|
13166 | a[0] += b[0], a[1] += b[1], a[2] += b[2];
|
13167 | }
|
13168 |
|
13169 | function cartesianScale(vector, k) {
|
13170 | return [vector[0] * k, vector[1] * k, vector[2] * k];
|
13171 | }
|
13172 |
|
13173 | // TODO return d
|
13174 | function cartesianNormalizeInPlace(d) {
|
13175 | var l = sqrt$1(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
|
13176 | d[0] /= l, d[1] /= l, d[2] /= l;
|
13177 | }
|
13178 |
|
13179 | var lambda0$1;
|
13180 | var phi0;
|
13181 | var lambda1;
|
13182 | var phi1;
|
13183 | var lambda2;
|
13184 | var lambda00$1;
|
13185 | var phi00$1;
|
13186 | var p0;
|
13187 | var deltaSum;
|
13188 | var ranges;
|
13189 | var range$1;
|
13190 | var boundsStream = {
|
13191 | point: boundsPoint,
|
13192 | lineStart: boundsLineStart,
|
13193 | lineEnd: boundsLineEnd,
|
13194 | polygonStart: function() {
|
13195 | boundsStream.point = boundsRingPoint;
|
13196 | boundsStream.lineStart = boundsRingStart;
|
13197 | boundsStream.lineEnd = boundsRingEnd;
|
13198 | deltaSum.reset();
|
13199 | areaStream.polygonStart();
|
13200 | },
|
13201 | polygonEnd: function() {
|
13202 | areaStream.polygonEnd();
|
13203 | boundsStream.point = boundsPoint;
|
13204 | boundsStream.lineStart = boundsLineStart;
|
13205 | boundsStream.lineEnd = boundsLineEnd;
|
13206 | if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
|
13207 | else if (deltaSum > epsilon$4) phi1 = 90;
|
13208 | else if (deltaSum < -epsilon$4) phi0 = -90;
|
13209 | range$1[0] = lambda0$1, range$1[1] = lambda1;
|
13210 | }
|
13211 | };
|
13212 |
|
13213 | function boundsPoint(lambda, phi) {
|
13214 | ranges.push(range$1 = [lambda0$1 = lambda, lambda1 = lambda]);
|
13215 | if (phi < phi0) phi0 = phi;
|
13216 | if (phi > phi1) phi1 = phi;
|
13217 | }
|
13218 |
|
13219 | function linePoint(lambda, phi) {
|
13220 | var p = cartesian([lambda * radians, phi * radians]);
|
13221 | if (p0) {
|
13222 | var normal = cartesianCross(p0, p),
|
13223 | equatorial = [normal[1], -normal[0], 0],
|
13224 | inflection = cartesianCross(equatorial, normal);
|
13225 | cartesianNormalizeInPlace(inflection);
|
13226 | inflection = spherical(inflection);
|
13227 | var delta = lambda - lambda2,
|
13228 | sign = delta > 0 ? 1 : -1,
|
13229 | lambdai = inflection[0] * degrees$1 * sign,
|
13230 | phii,
|
13231 | antimeridian = abs(delta) > 180;
|
13232 | if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
|
13233 | phii = inflection[1] * degrees$1;
|
13234 | if (phii > phi1) phi1 = phii;
|
13235 | } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
|
13236 | phii = -inflection[1] * degrees$1;
|
13237 | if (phii < phi0) phi0 = phii;
|
13238 | } else {
|
13239 | if (phi < phi0) phi0 = phi;
|
13240 | if (phi > phi1) phi1 = phi;
|
13241 | }
|
13242 | if (antimeridian) {
|
13243 | if (lambda < lambda2) {
|
13244 | if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
|
13245 | } else {
|
13246 | if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
|
13247 | }
|
13248 | } else {
|
13249 | if (lambda1 >= lambda0$1) {
|
13250 | if (lambda < lambda0$1) lambda0$1 = lambda;
|
13251 | if (lambda > lambda1) lambda1 = lambda;
|
13252 | } else {
|
13253 | if (lambda > lambda2) {
|
13254 | if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
|
13255 | } else {
|
13256 | if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
|
13257 | }
|
13258 | }
|
13259 | }
|
13260 | } else {
|
13261 | boundsPoint(lambda, phi);
|
13262 | }
|
13263 | p0 = p, lambda2 = lambda;
|
13264 | }
|
13265 |
|
13266 | function boundsLineStart() {
|
13267 | boundsStream.point = linePoint;
|
13268 | }
|
13269 |
|
13270 | function boundsLineEnd() {
|
13271 | range$1[0] = lambda0$1, range$1[1] = lambda1;
|
13272 | boundsStream.point = boundsPoint;
|
13273 | p0 = null;
|
13274 | }
|
13275 |
|
13276 | function boundsRingPoint(lambda, phi) {
|
13277 | if (p0) {
|
13278 | var delta = lambda - lambda2;
|
13279 | deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
|
13280 | } else {
|
13281 | lambda00$1 = lambda, phi00$1 = phi;
|
13282 | }
|
13283 | areaStream.point(lambda, phi);
|
13284 | linePoint(lambda, phi);
|
13285 | }
|
13286 |
|
13287 | function boundsRingStart() {
|
13288 | areaStream.lineStart();
|
13289 | }
|
13290 |
|
13291 | function boundsRingEnd() {
|
13292 | boundsRingPoint(lambda00$1, phi00$1);
|
13293 | areaStream.lineEnd();
|
13294 | if (abs(deltaSum) > epsilon$4) lambda0$1 = -(lambda1 = 180);
|
13295 | range$1[0] = lambda0$1, range$1[1] = lambda1;
|
13296 | p0 = null;
|
13297 | }
|
13298 |
|
13299 | // Finds the left-right distance between two longitudes.
|
13300 | // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
|
13301 | // the distance between ±180° to be 360°.
|
13302 | function angle(lambda0, lambda1) {
|
13303 | return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
|
13304 | }
|
13305 |
|
13306 | function rangeCompare(a, b) {
|
13307 | return a[0] - b[0];
|
13308 | }
|
13309 |
|
13310 | function rangeContains(range, x) {
|
13311 | return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
|
13312 | }
|
13313 |
|
13314 | function bounds(feature) {
|
13315 | var i, n, a, b, merged, deltaMax, delta;
|
13316 |
|
13317 | if (deltaSum) deltaSum.reset();
|
13318 | else deltaSum = adder();
|
13319 | phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
|
13320 | ranges = [];
|
13321 | stream(feature, boundsStream);
|
13322 |
|
13323 | // First, sort ranges by their minimum longitudes.
|
13324 | if (n = ranges.length) {
|
13325 | ranges.sort(rangeCompare);
|
13326 |
|
13327 | // Then, merge any ranges that overlap.
|
13328 | for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
|
13329 | b = ranges[i];
|
13330 | if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
|
13331 | if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
|
13332 | if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
|
13333 | } else {
|
13334 | merged.push(a = b);
|
13335 | }
|
13336 | }
|
13337 |
|
13338 | // Finally, find the largest gap between the merged ranges.
|
13339 | // The final bounding box will be the inverse of this gap.
|
13340 | for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
|
13341 | b = merged[i];
|
13342 | if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
|
13343 | }
|
13344 | }
|
13345 |
|
13346 | ranges = range$1 = null;
|
13347 |
|
13348 | return lambda0$1 === Infinity || phi0 === Infinity
|
13349 | ? [[NaN, NaN], [NaN, NaN]]
|
13350 | : [[lambda0$1, phi0], [lambda1, phi1]];
|
13351 | }
|
13352 |
|
13353 | var W0;
|
13354 | var W1;
|
13355 | var X0;
|
13356 | var Y0;
|
13357 | var Z0;
|
13358 | var X1;
|
13359 | var Y1;
|
13360 | var Z1;
|
13361 | var X2;
|
13362 | var Y2;
|
13363 | var Z2;
|
13364 | var lambda00$2;
|
13365 | var phi00$2;
|
13366 | var x0;
|
13367 | var y0;
|
13368 | var z0;
|
13369 | // previous point
|
13370 |
|
13371 | var centroidStream = {
|
13372 | sphere: noop$2,
|
13373 | point: centroidPoint,
|
13374 | lineStart: centroidLineStart,
|
13375 | lineEnd: centroidLineEnd,
|
13376 | polygonStart: function() {
|
13377 | centroidStream.lineStart = centroidRingStart;
|
13378 | centroidStream.lineEnd = centroidRingEnd;
|
13379 | },
|
13380 | polygonEnd: function() {
|
13381 | centroidStream.lineStart = centroidLineStart;
|
13382 | centroidStream.lineEnd = centroidLineEnd;
|
13383 | }
|
13384 | };
|
13385 |
|
13386 | // Arithmetic mean of Cartesian vectors.
|
13387 | function centroidPoint(lambda, phi) {
|
13388 | lambda *= radians, phi *= radians;
|
13389 | var cosPhi = cos(phi);
|
13390 | centroidPointCartesian(cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi));
|
13391 | }
|
13392 |
|
13393 | function centroidPointCartesian(x, y, z) {
|
13394 | ++W0;
|
13395 | X0 += (x - X0) / W0;
|
13396 | Y0 += (y - Y0) / W0;
|
13397 | Z0 += (z - Z0) / W0;
|
13398 | }
|
13399 |
|
13400 | function centroidLineStart() {
|
13401 | centroidStream.point = centroidLinePointFirst;
|
13402 | }
|
13403 |
|
13404 | function centroidLinePointFirst(lambda, phi) {
|
13405 | lambda *= radians, phi *= radians;
|
13406 | var cosPhi = cos(phi);
|
13407 | x0 = cosPhi * cos(lambda);
|
13408 | y0 = cosPhi * sin(lambda);
|
13409 | z0 = sin(phi);
|
13410 | centroidStream.point = centroidLinePoint;
|
13411 | centroidPointCartesian(x0, y0, z0);
|
13412 | }
|
13413 |
|
13414 | function centroidLinePoint(lambda, phi) {
|
13415 | lambda *= radians, phi *= radians;
|
13416 | var cosPhi = cos(phi),
|
13417 | x = cosPhi * cos(lambda),
|
13418 | y = cosPhi * sin(lambda),
|
13419 | z = sin(phi),
|
13420 | 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);
|
13421 | W1 += w;
|
13422 | X1 += w * (x0 + (x0 = x));
|
13423 | Y1 += w * (y0 + (y0 = y));
|
13424 | Z1 += w * (z0 + (z0 = z));
|
13425 | centroidPointCartesian(x0, y0, z0);
|
13426 | }
|
13427 |
|
13428 | function centroidLineEnd() {
|
13429 | centroidStream.point = centroidPoint;
|
13430 | }
|
13431 |
|
13432 | // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
|
13433 | // J. Applied Mechanics 42, 239 (1975).
|
13434 | function centroidRingStart() {
|
13435 | centroidStream.point = centroidRingPointFirst;
|
13436 | }
|
13437 |
|
13438 | function centroidRingEnd() {
|
13439 | centroidRingPoint(lambda00$2, phi00$2);
|
13440 | centroidStream.point = centroidPoint;
|
13441 | }
|
13442 |
|
13443 | function centroidRingPointFirst(lambda, phi) {
|
13444 | lambda00$2 = lambda, phi00$2 = phi;
|
13445 | lambda *= radians, phi *= radians;
|
13446 | centroidStream.point = centroidRingPoint;
|
13447 | var cosPhi = cos(phi);
|
13448 | x0 = cosPhi * cos(lambda);
|
13449 | y0 = cosPhi * sin(lambda);
|
13450 | z0 = sin(phi);
|
13451 | centroidPointCartesian(x0, y0, z0);
|
13452 | }
|
13453 |
|
13454 | function centroidRingPoint(lambda, phi) {
|
13455 | lambda *= radians, phi *= radians;
|
13456 | var cosPhi = cos(phi),
|
13457 | x = cosPhi * cos(lambda),
|
13458 | y = cosPhi * sin(lambda),
|
13459 | z = sin(phi),
|
13460 | cx = y0 * z - z0 * y,
|
13461 | cy = z0 * x - x0 * z,
|
13462 | cz = x0 * y - y0 * x,
|
13463 | m = sqrt$1(cx * cx + cy * cy + cz * cz),
|
13464 | u = x0 * x + y0 * y + z0 * z,
|
13465 | v = m && -acos(u) / m, // area weight
|
13466 | w = atan2(m, u); // line weight
|
13467 | X2 += v * cx;
|
13468 | Y2 += v * cy;
|
13469 | Z2 += v * cz;
|
13470 | W1 += w;
|
13471 | X1 += w * (x0 + (x0 = x));
|
13472 | Y1 += w * (y0 + (y0 = y));
|
13473 | Z1 += w * (z0 + (z0 = z));
|
13474 | centroidPointCartesian(x0, y0, z0);
|
13475 | }
|
13476 |
|
13477 | function centroid$1(object) {
|
13478 | W0 = W1 =
|
13479 | X0 = Y0 = Z0 =
|
13480 | X1 = Y1 = Z1 =
|
13481 | X2 = Y2 = Z2 = 0;
|
13482 | stream(object, centroidStream);
|
13483 |
|
13484 | var x = X2,
|
13485 | y = Y2,
|
13486 | z = Z2,
|
13487 | m = x * x + y * y + z * z;
|
13488 |
|
13489 | // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
|
13490 | if (m < epsilon2$2) {
|
13491 | x = X1, y = Y1, z = Z1;
|
13492 | // If the feature has zero length, fall back to arithmetic mean of point vectors.
|
13493 | if (W1 < epsilon$4) x = X0, y = Y0, z = Z0;
|
13494 | m = x * x + y * y + z * z;
|
13495 | // If the feature still has an undefined ccentroid, then return.
|
13496 | if (m < epsilon2$2) return [NaN, NaN];
|
13497 | }
|
13498 |
|
13499 | return [atan2(y, x) * degrees$1, asin$1(z / sqrt$1(m)) * degrees$1];
|
13500 | }
|
13501 |
|
13502 | function constant$11(x) {
|
13503 | return function() {
|
13504 | return x;
|
13505 | };
|
13506 | }
|
13507 |
|
13508 | function compose(a, b) {
|
13509 |
|
13510 | function compose(x, y) {
|
13511 | return x = a(x, y), b(x[0], x[1]);
|
13512 | }
|
13513 |
|
13514 | if (a.invert && b.invert) compose.invert = function(x, y) {
|
13515 | return x = b.invert(x, y), x && a.invert(x[0], x[1]);
|
13516 | };
|
13517 |
|
13518 | return compose;
|
13519 | }
|
13520 |
|
13521 | function rotationIdentity(lambda, phi) {
|
13522 | return [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
|
13523 | }
|
13524 |
|
13525 | rotationIdentity.invert = rotationIdentity;
|
13526 |
|
13527 | function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
|
13528 | return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
|
13529 | : rotationLambda(deltaLambda))
|
13530 | : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
|
13531 | : rotationIdentity);
|
13532 | }
|
13533 |
|
13534 | function forwardRotationLambda(deltaLambda) {
|
13535 | return function(lambda, phi) {
|
13536 | return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
|
13537 | };
|
13538 | }
|
13539 |
|
13540 | function rotationLambda(deltaLambda) {
|
13541 | var rotation = forwardRotationLambda(deltaLambda);
|
13542 | rotation.invert = forwardRotationLambda(-deltaLambda);
|
13543 | return rotation;
|
13544 | }
|
13545 |
|
13546 | function rotationPhiGamma(deltaPhi, deltaGamma) {
|
13547 | var cosDeltaPhi = cos(deltaPhi),
|
13548 | sinDeltaPhi = sin(deltaPhi),
|
13549 | cosDeltaGamma = cos(deltaGamma),
|
13550 | sinDeltaGamma = sin(deltaGamma);
|
13551 |
|
13552 | function rotation(lambda, phi) {
|
13553 | var cosPhi = cos(phi),
|
13554 | x = cos(lambda) * cosPhi,
|
13555 | y = sin(lambda) * cosPhi,
|
13556 | z = sin(phi),
|
13557 | k = z * cosDeltaPhi + x * sinDeltaPhi;
|
13558 | return [
|
13559 | atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
|
13560 | asin$1(k * cosDeltaGamma + y * sinDeltaGamma)
|
13561 | ];
|
13562 | }
|
13563 |
|
13564 | rotation.invert = function(lambda, phi) {
|
13565 | var cosPhi = cos(phi),
|
13566 | x = cos(lambda) * cosPhi,
|
13567 | y = sin(lambda) * cosPhi,
|
13568 | z = sin(phi),
|
13569 | k = z * cosDeltaGamma - y * sinDeltaGamma;
|
13570 | return [
|
13571 | atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
|
13572 | asin$1(k * cosDeltaPhi - x * sinDeltaPhi)
|
13573 | ];
|
13574 | };
|
13575 |
|
13576 | return rotation;
|
13577 | }
|
13578 |
|
13579 | function rotation(rotate) {
|
13580 | rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
|
13581 |
|
13582 | function forward(coordinates) {
|
13583 | coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
|
13584 | return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
|
13585 | }
|
13586 |
|
13587 | forward.invert = function(coordinates) {
|
13588 | coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
|
13589 | return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
|
13590 | };
|
13591 |
|
13592 | return forward;
|
13593 | }
|
13594 |
|
13595 | // Generates a circle centered at [0°, 0°], with a given radius and precision.
|
13596 | function circleStream(stream, radius, delta, direction, t0, t1) {
|
13597 | if (!delta) return;
|
13598 | var cosRadius = cos(radius),
|
13599 | sinRadius = sin(radius),
|
13600 | step = direction * delta;
|
13601 | if (t0 == null) {
|
13602 | t0 = radius + direction * tau$3;
|
13603 | t1 = radius - step / 2;
|
13604 | } else {
|
13605 | t0 = circleRadius(cosRadius, t0);
|
13606 | t1 = circleRadius(cosRadius, t1);
|
13607 | if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
|
13608 | }
|
13609 | for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
|
13610 | point = spherical([cosRadius, -sinRadius * cos(t), -sinRadius * sin(t)]);
|
13611 | stream.point(point[0], point[1]);
|
13612 | }
|
13613 | }
|
13614 |
|
13615 | // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
|
13616 | function circleRadius(cosRadius, point) {
|
13617 | point = cartesian(point), point[0] -= cosRadius;
|
13618 | cartesianNormalizeInPlace(point);
|
13619 | var radius = acos(-point[1]);
|
13620 | return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$4) % tau$3;
|
13621 | }
|
13622 |
|
13623 | function circle$1() {
|
13624 | var center = constant$11([0, 0]),
|
13625 | radius = constant$11(90),
|
13626 | precision = constant$11(6),
|
13627 | ring,
|
13628 | rotate,
|
13629 | stream = {point: point};
|
13630 |
|
13631 | function point(x, y) {
|
13632 | ring.push(x = rotate(x, y));
|
13633 | x[0] *= degrees$1, x[1] *= degrees$1;
|
13634 | }
|
13635 |
|
13636 | function circle() {
|
13637 | var c = center.apply(this, arguments),
|
13638 | r = radius.apply(this, arguments) * radians,
|
13639 | p = precision.apply(this, arguments) * radians;
|
13640 | ring = [];
|
13641 | rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
|
13642 | circleStream(stream, r, p, 1);
|
13643 | c = {type: "Polygon", coordinates: [ring]};
|
13644 | ring = rotate = null;
|
13645 | return c;
|
13646 | }
|
13647 |
|
13648 | circle.center = function(_) {
|
13649 | return arguments.length ? (center = typeof _ === "function" ? _ : constant$11([+_[0], +_[1]]), circle) : center;
|
13650 | };
|
13651 |
|
13652 | circle.radius = function(_) {
|
13653 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$11(+_), circle) : radius;
|
13654 | };
|
13655 |
|
13656 | circle.precision = function(_) {
|
13657 | return arguments.length ? (precision = typeof _ === "function" ? _ : constant$11(+_), circle) : precision;
|
13658 | };
|
13659 |
|
13660 | return circle;
|
13661 | }
|
13662 |
|
13663 | function clipBuffer() {
|
13664 | var lines = [],
|
13665 | line;
|
13666 | return {
|
13667 | point: function(x, y) {
|
13668 | line.push([x, y]);
|
13669 | },
|
13670 | lineStart: function() {
|
13671 | lines.push(line = []);
|
13672 | },
|
13673 | lineEnd: noop$2,
|
13674 | rejoin: function() {
|
13675 | if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
|
13676 | },
|
13677 | result: function() {
|
13678 | var result = lines;
|
13679 | lines = [];
|
13680 | line = null;
|
13681 | return result;
|
13682 | }
|
13683 | };
|
13684 | }
|
13685 |
|
13686 | function clipLine(a, b, x0, y0, x1, y1) {
|
13687 | var ax = a[0],
|
13688 | ay = a[1],
|
13689 | bx = b[0],
|
13690 | by = b[1],
|
13691 | t0 = 0,
|
13692 | t1 = 1,
|
13693 | dx = bx - ax,
|
13694 | dy = by - ay,
|
13695 | r;
|
13696 |
|
13697 | r = x0 - ax;
|
13698 | if (!dx && r > 0) return;
|
13699 | r /= dx;
|
13700 | if (dx < 0) {
|
13701 | if (r < t0) return;
|
13702 | if (r < t1) t1 = r;
|
13703 | } else if (dx > 0) {
|
13704 | if (r > t1) return;
|
13705 | if (r > t0) t0 = r;
|
13706 | }
|
13707 |
|
13708 | r = x1 - ax;
|
13709 | if (!dx && r < 0) return;
|
13710 | r /= dx;
|
13711 | if (dx < 0) {
|
13712 | if (r > t1) return;
|
13713 | if (r > t0) t0 = r;
|
13714 | } else if (dx > 0) {
|
13715 | if (r < t0) return;
|
13716 | if (r < t1) t1 = r;
|
13717 | }
|
13718 |
|
13719 | r = y0 - ay;
|
13720 | if (!dy && r > 0) return;
|
13721 | r /= dy;
|
13722 | if (dy < 0) {
|
13723 | if (r < t0) return;
|
13724 | if (r < t1) t1 = r;
|
13725 | } else if (dy > 0) {
|
13726 | if (r > t1) return;
|
13727 | if (r > t0) t0 = r;
|
13728 | }
|
13729 |
|
13730 | r = y1 - ay;
|
13731 | if (!dy && r < 0) return;
|
13732 | r /= dy;
|
13733 | if (dy < 0) {
|
13734 | if (r > t1) return;
|
13735 | if (r > t0) t0 = r;
|
13736 | } else if (dy > 0) {
|
13737 | if (r < t0) return;
|
13738 | if (r < t1) t1 = r;
|
13739 | }
|
13740 |
|
13741 | if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
|
13742 | if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
|
13743 | return true;
|
13744 | }
|
13745 |
|
13746 | function pointEqual(a, b) {
|
13747 | return abs(a[0] - b[0]) < epsilon$4 && abs(a[1] - b[1]) < epsilon$4;
|
13748 | }
|
13749 |
|
13750 | function Intersection(point, points, other, entry) {
|
13751 | this.x = point;
|
13752 | this.z = points;
|
13753 | this.o = other; // another intersection
|
13754 | this.e = entry; // is an entry?
|
13755 | this.v = false; // visited
|
13756 | this.n = this.p = null; // next & previous
|
13757 | }
|
13758 |
|
13759 | // A generalized polygon clipping algorithm: given a polygon that has been cut
|
13760 | // into its visible line segments, and rejoins the segments by interpolating
|
13761 | // along the clip edge.
|
13762 | function clipPolygon(segments, compareIntersection, startInside, interpolate, stream) {
|
13763 | var subject = [],
|
13764 | clip = [],
|
13765 | i,
|
13766 | n;
|
13767 |
|
13768 | segments.forEach(function(segment) {
|
13769 | if ((n = segment.length - 1) <= 0) return;
|
13770 | var n, p0 = segment[0], p1 = segment[n], x;
|
13771 |
|
13772 | // If the first and last points of a segment are coincident, then treat as a
|
13773 | // closed ring. TODO if all rings are closed, then the winding order of the
|
13774 | // exterior ring should be checked.
|
13775 | if (pointEqual(p0, p1)) {
|
13776 | stream.lineStart();
|
13777 | for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
|
13778 | stream.lineEnd();
|
13779 | return;
|
13780 | }
|
13781 |
|
13782 | subject.push(x = new Intersection(p0, segment, null, true));
|
13783 | clip.push(x.o = new Intersection(p0, null, x, false));
|
13784 | subject.push(x = new Intersection(p1, segment, null, false));
|
13785 | clip.push(x.o = new Intersection(p1, null, x, true));
|
13786 | });
|
13787 |
|
13788 | if (!subject.length) return;
|
13789 |
|
13790 | clip.sort(compareIntersection);
|
13791 | link$1(subject);
|
13792 | link$1(clip);
|
13793 |
|
13794 | for (i = 0, n = clip.length; i < n; ++i) {
|
13795 | clip[i].e = startInside = !startInside;
|
13796 | }
|
13797 |
|
13798 | var start = subject[0],
|
13799 | points,
|
13800 | point;
|
13801 |
|
13802 | while (1) {
|
13803 | // Find first unvisited intersection.
|
13804 | var current = start,
|
13805 | isSubject = true;
|
13806 | while (current.v) if ((current = current.n) === start) return;
|
13807 | points = current.z;
|
13808 | stream.lineStart();
|
13809 | do {
|
13810 | current.v = current.o.v = true;
|
13811 | if (current.e) {
|
13812 | if (isSubject) {
|
13813 | for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
|
13814 | } else {
|
13815 | interpolate(current.x, current.n.x, 1, stream);
|
13816 | }
|
13817 | current = current.n;
|
13818 | } else {
|
13819 | if (isSubject) {
|
13820 | points = current.p.z;
|
13821 | for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
|
13822 | } else {
|
13823 | interpolate(current.x, current.p.x, -1, stream);
|
13824 | }
|
13825 | current = current.p;
|
13826 | }
|
13827 | current = current.o;
|
13828 | points = current.z;
|
13829 | isSubject = !isSubject;
|
13830 | } while (!current.v);
|
13831 | stream.lineEnd();
|
13832 | }
|
13833 | }
|
13834 |
|
13835 | function link$1(array) {
|
13836 | if (!(n = array.length)) return;
|
13837 | var n,
|
13838 | i = 0,
|
13839 | a = array[0],
|
13840 | b;
|
13841 | while (++i < n) {
|
13842 | a.n = b = array[i];
|
13843 | b.p = a;
|
13844 | a = b;
|
13845 | }
|
13846 | a.n = b = array[0];
|
13847 | b.p = a;
|
13848 | }
|
13849 |
|
13850 | var clipMax = 1e9;
|
13851 | var clipMin = -clipMax;
|
13852 | // TODO Use d3-polygon’s polygonContains here for the ring check?
|
13853 | // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
|
13854 |
|
13855 | function clipExtent(x0, y0, x1, y1) {
|
13856 |
|
13857 | function visible(x, y) {
|
13858 | return x0 <= x && x <= x1 && y0 <= y && y <= y1;
|
13859 | }
|
13860 |
|
13861 | function interpolate(from, to, direction, stream) {
|
13862 | var a = 0, a1 = 0;
|
13863 | if (from == null
|
13864 | || (a = corner(from, direction)) !== (a1 = corner(to, direction))
|
13865 | || comparePoint(from, to) < 0 ^ direction > 0) {
|
13866 | do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
|
13867 | while ((a = (a + direction + 4) % 4) !== a1);
|
13868 | } else {
|
13869 | stream.point(to[0], to[1]);
|
13870 | }
|
13871 | }
|
13872 |
|
13873 | function corner(p, direction) {
|
13874 | return abs(p[0] - x0) < epsilon$4 ? direction > 0 ? 0 : 3
|
13875 | : abs(p[0] - x1) < epsilon$4 ? direction > 0 ? 2 : 1
|
13876 | : abs(p[1] - y0) < epsilon$4 ? direction > 0 ? 1 : 0
|
13877 | : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
|
13878 | }
|
13879 |
|
13880 | function compareIntersection(a, b) {
|
13881 | return comparePoint(a.x, b.x);
|
13882 | }
|
13883 |
|
13884 | function comparePoint(a, b) {
|
13885 | var ca = corner(a, 1),
|
13886 | cb = corner(b, 1);
|
13887 | return ca !== cb ? ca - cb
|
13888 | : ca === 0 ? b[1] - a[1]
|
13889 | : ca === 1 ? a[0] - b[0]
|
13890 | : ca === 2 ? a[1] - b[1]
|
13891 | : b[0] - a[0];
|
13892 | }
|
13893 |
|
13894 | return function(stream) {
|
13895 | var activeStream = stream,
|
13896 | bufferStream = clipBuffer(),
|
13897 | segments,
|
13898 | polygon,
|
13899 | ring,
|
13900 | x__, y__, v__, // first point
|
13901 | x_, y_, v_, // previous point
|
13902 | first,
|
13903 | clean;
|
13904 |
|
13905 | var clipStream = {
|
13906 | point: point,
|
13907 | lineStart: lineStart,
|
13908 | lineEnd: lineEnd,
|
13909 | polygonStart: polygonStart,
|
13910 | polygonEnd: polygonEnd
|
13911 | };
|
13912 |
|
13913 | function point(x, y) {
|
13914 | if (visible(x, y)) activeStream.point(x, y);
|
13915 | }
|
13916 |
|
13917 | function polygonInside() {
|
13918 | var winding = 0;
|
13919 |
|
13920 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
13921 | for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
|
13922 | a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
|
13923 | if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
|
13924 | else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
|
13925 | }
|
13926 | }
|
13927 |
|
13928 | return winding;
|
13929 | }
|
13930 |
|
13931 | // Buffer geometry within a polygon and then clip it en masse.
|
13932 | function polygonStart() {
|
13933 | activeStream = bufferStream, segments = [], polygon = [], clean = true;
|
13934 | }
|
13935 |
|
13936 | function polygonEnd() {
|
13937 | var startInside = polygonInside(),
|
13938 | cleanInside = clean && startInside,
|
13939 | visible = (segments = merge(segments)).length;
|
13940 | if (cleanInside || visible) {
|
13941 | stream.polygonStart();
|
13942 | if (cleanInside) {
|
13943 | stream.lineStart();
|
13944 | interpolate(null, null, 1, stream);
|
13945 | stream.lineEnd();
|
13946 | }
|
13947 | if (visible) {
|
13948 | clipPolygon(segments, compareIntersection, startInside, interpolate, stream);
|
13949 | }
|
13950 | stream.polygonEnd();
|
13951 | }
|
13952 | activeStream = stream, segments = polygon = ring = null;
|
13953 | }
|
13954 |
|
13955 | function lineStart() {
|
13956 | clipStream.point = linePoint;
|
13957 | if (polygon) polygon.push(ring = []);
|
13958 | first = true;
|
13959 | v_ = false;
|
13960 | x_ = y_ = NaN;
|
13961 | }
|
13962 |
|
13963 | // TODO rather than special-case polygons, simply handle them separately.
|
13964 | // Ideally, coincident intersection points should be jittered to avoid
|
13965 | // clipping issues.
|
13966 | function lineEnd() {
|
13967 | if (segments) {
|
13968 | linePoint(x__, y__);
|
13969 | if (v__ && v_) bufferStream.rejoin();
|
13970 | segments.push(bufferStream.result());
|
13971 | }
|
13972 | clipStream.point = point;
|
13973 | if (v_) activeStream.lineEnd();
|
13974 | }
|
13975 |
|
13976 | function linePoint(x, y) {
|
13977 | var v = visible(x, y);
|
13978 | if (polygon) ring.push([x, y]);
|
13979 | if (first) {
|
13980 | x__ = x, y__ = y, v__ = v;
|
13981 | first = false;
|
13982 | if (v) {
|
13983 | activeStream.lineStart();
|
13984 | activeStream.point(x, y);
|
13985 | }
|
13986 | } else {
|
13987 | if (v && v_) activeStream.point(x, y);
|
13988 | else {
|
13989 | var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
|
13990 | b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
|
13991 | if (clipLine(a, b, x0, y0, x1, y1)) {
|
13992 | if (!v_) {
|
13993 | activeStream.lineStart();
|
13994 | activeStream.point(a[0], a[1]);
|
13995 | }
|
13996 | activeStream.point(b[0], b[1]);
|
13997 | if (!v) activeStream.lineEnd();
|
13998 | clean = false;
|
13999 | } else if (v) {
|
14000 | activeStream.lineStart();
|
14001 | activeStream.point(x, y);
|
14002 | clean = false;
|
14003 | }
|
14004 | }
|
14005 | }
|
14006 | x_ = x, y_ = y, v_ = v;
|
14007 | }
|
14008 |
|
14009 | return clipStream;
|
14010 | };
|
14011 | }
|
14012 |
|
14013 | function extent$1() {
|
14014 | var x0 = 0,
|
14015 | y0 = 0,
|
14016 | x1 = 960,
|
14017 | y1 = 500,
|
14018 | cache,
|
14019 | cacheStream,
|
14020 | clip;
|
14021 |
|
14022 | return clip = {
|
14023 | stream: function(stream) {
|
14024 | return cache && cacheStream === stream ? cache : cache = clipExtent(x0, y0, x1, y1)(cacheStream = stream);
|
14025 | },
|
14026 | extent: function(_) {
|
14027 | return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
|
14028 | }
|
14029 | };
|
14030 | }
|
14031 |
|
14032 | var lengthSum;
|
14033 | var lambda0$2;
|
14034 | var sinPhi0$1;
|
14035 | var cosPhi0$1;
|
14036 | var lengthStream = {
|
14037 | sphere: noop$2,
|
14038 | point: noop$2,
|
14039 | lineStart: lengthLineStart,
|
14040 | lineEnd: noop$2,
|
14041 | polygonStart: noop$2,
|
14042 | polygonEnd: noop$2
|
14043 | };
|
14044 |
|
14045 | function lengthLineStart() {
|
14046 | lengthStream.point = lengthPointFirst;
|
14047 | lengthStream.lineEnd = lengthLineEnd;
|
14048 | }
|
14049 |
|
14050 | function lengthLineEnd() {
|
14051 | lengthStream.point = lengthStream.lineEnd = noop$2;
|
14052 | }
|
14053 |
|
14054 | function lengthPointFirst(lambda, phi) {
|
14055 | lambda *= radians, phi *= radians;
|
14056 | lambda0$2 = lambda, sinPhi0$1 = sin(phi), cosPhi0$1 = cos(phi);
|
14057 | lengthStream.point = lengthPoint;
|
14058 | }
|
14059 |
|
14060 | function lengthPoint(lambda, phi) {
|
14061 | lambda *= radians, phi *= radians;
|
14062 | var sinPhi = sin(phi),
|
14063 | cosPhi = cos(phi),
|
14064 | delta = abs(lambda - lambda0$2),
|
14065 | cosDelta = cos(delta),
|
14066 | sinDelta = sin(delta),
|
14067 | x = cosPhi * sinDelta,
|
14068 | y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
|
14069 | z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
|
14070 | lengthSum.add(atan2(sqrt$1(x * x + y * y), z));
|
14071 | lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
|
14072 | }
|
14073 |
|
14074 | function length$2(object) {
|
14075 | if (lengthSum) lengthSum.reset();
|
14076 | else lengthSum = adder();
|
14077 | stream(object, lengthStream);
|
14078 | return +lengthSum;
|
14079 | }
|
14080 |
|
14081 | var coordinates = [null, null];
|
14082 | var object$1 = {type: "LineString", coordinates: coordinates};
|
14083 | function distance(a, b) {
|
14084 | coordinates[0] = a;
|
14085 | coordinates[1] = b;
|
14086 | return length$2(object$1);
|
14087 | }
|
14088 |
|
14089 | function graticuleX(y0, y1, dy) {
|
14090 | var y = range(y0, y1 - epsilon$4, dy).concat(y1);
|
14091 | return function(x) { return y.map(function(y) { return [x, y]; }); };
|
14092 | }
|
14093 |
|
14094 | function graticuleY(x0, x1, dx) {
|
14095 | var x = range(x0, x1 - epsilon$4, dx).concat(x1);
|
14096 | return function(y) { return x.map(function(x) { return [x, y]; }); };
|
14097 | }
|
14098 |
|
14099 | function graticule() {
|
14100 | var x1, x0, X1, X0,
|
14101 | y1, y0, Y1, Y0,
|
14102 | dx = 10, dy = dx, DX = 90, DY = 360,
|
14103 | x, y, X, Y,
|
14104 | precision = 2.5;
|
14105 |
|
14106 | function graticule() {
|
14107 | return {type: "MultiLineString", coordinates: lines()};
|
14108 | }
|
14109 |
|
14110 | function lines() {
|
14111 | return range(ceil(X0 / DX) * DX, X1, DX).map(X)
|
14112 | .concat(range(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
|
14113 | .concat(range(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$4; }).map(x))
|
14114 | .concat(range(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$4; }).map(y));
|
14115 | }
|
14116 |
|
14117 | graticule.lines = function() {
|
14118 | return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
|
14119 | };
|
14120 |
|
14121 | graticule.outline = function() {
|
14122 | return {
|
14123 | type: "Polygon",
|
14124 | coordinates: [
|
14125 | X(X0).concat(
|
14126 | Y(Y1).slice(1),
|
14127 | X(X1).reverse().slice(1),
|
14128 | Y(Y0).reverse().slice(1))
|
14129 | ]
|
14130 | };
|
14131 | };
|
14132 |
|
14133 | graticule.extent = function(_) {
|
14134 | if (!arguments.length) return graticule.extentMinor();
|
14135 | return graticule.extentMajor(_).extentMinor(_);
|
14136 | };
|
14137 |
|
14138 | graticule.extentMajor = function(_) {
|
14139 | if (!arguments.length) return [[X0, Y0], [X1, Y1]];
|
14140 | X0 = +_[0][0], X1 = +_[1][0];
|
14141 | Y0 = +_[0][1], Y1 = +_[1][1];
|
14142 | if (X0 > X1) _ = X0, X0 = X1, X1 = _;
|
14143 | if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
|
14144 | return graticule.precision(precision);
|
14145 | };
|
14146 |
|
14147 | graticule.extentMinor = function(_) {
|
14148 | if (!arguments.length) return [[x0, y0], [x1, y1]];
|
14149 | x0 = +_[0][0], x1 = +_[1][0];
|
14150 | y0 = +_[0][1], y1 = +_[1][1];
|
14151 | if (x0 > x1) _ = x0, x0 = x1, x1 = _;
|
14152 | if (y0 > y1) _ = y0, y0 = y1, y1 = _;
|
14153 | return graticule.precision(precision);
|
14154 | };
|
14155 |
|
14156 | graticule.step = function(_) {
|
14157 | if (!arguments.length) return graticule.stepMinor();
|
14158 | return graticule.stepMajor(_).stepMinor(_);
|
14159 | };
|
14160 |
|
14161 | graticule.stepMajor = function(_) {
|
14162 | if (!arguments.length) return [DX, DY];
|
14163 | DX = +_[0], DY = +_[1];
|
14164 | return graticule;
|
14165 | };
|
14166 |
|
14167 | graticule.stepMinor = function(_) {
|
14168 | if (!arguments.length) return [dx, dy];
|
14169 | dx = +_[0], dy = +_[1];
|
14170 | return graticule;
|
14171 | };
|
14172 |
|
14173 | graticule.precision = function(_) {
|
14174 | if (!arguments.length) return precision;
|
14175 | precision = +_;
|
14176 | x = graticuleX(y0, y1, 90);
|
14177 | y = graticuleY(x0, x1, precision);
|
14178 | X = graticuleX(Y0, Y1, 90);
|
14179 | Y = graticuleY(X0, X1, precision);
|
14180 | return graticule;
|
14181 | };
|
14182 |
|
14183 | return graticule
|
14184 | .extentMajor([[-180, -90 + epsilon$4], [180, 90 - epsilon$4]])
|
14185 | .extentMinor([[-180, -80 - epsilon$4], [180, 80 + epsilon$4]]);
|
14186 | }
|
14187 |
|
14188 | function interpolate$2(a, b) {
|
14189 | var x0 = a[0] * radians,
|
14190 | y0 = a[1] * radians,
|
14191 | x1 = b[0] * radians,
|
14192 | y1 = b[1] * radians,
|
14193 | cy0 = cos(y0),
|
14194 | sy0 = sin(y0),
|
14195 | cy1 = cos(y1),
|
14196 | sy1 = sin(y1),
|
14197 | kx0 = cy0 * cos(x0),
|
14198 | ky0 = cy0 * sin(x0),
|
14199 | kx1 = cy1 * cos(x1),
|
14200 | ky1 = cy1 * sin(x1),
|
14201 | d = 2 * asin$1(sqrt$1(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
|
14202 | k = sin(d);
|
14203 |
|
14204 | var interpolate = d ? function(t) {
|
14205 | var B = sin(t *= d) / k,
|
14206 | A = sin(d - t) / k,
|
14207 | x = A * kx0 + B * kx1,
|
14208 | y = A * ky0 + B * ky1,
|
14209 | z = A * sy0 + B * sy1;
|
14210 | return [
|
14211 | atan2(y, x) * degrees$1,
|
14212 | atan2(z, sqrt$1(x * x + y * y)) * degrees$1
|
14213 | ];
|
14214 | } : function() {
|
14215 | return [x0 * degrees$1, y0 * degrees$1];
|
14216 | };
|
14217 |
|
14218 | interpolate.distance = d;
|
14219 |
|
14220 | return interpolate;
|
14221 | }
|
14222 |
|
14223 | function identity$7(x) {
|
14224 | return x;
|
14225 | }
|
14226 |
|
14227 | var areaSum$1 = adder();
|
14228 | var areaRingSum$1 = adder();
|
14229 | var x00;
|
14230 | var y00;
|
14231 | var x0$1;
|
14232 | var y0$1;
|
14233 | var areaStream$1 = {
|
14234 | point: noop$2,
|
14235 | lineStart: noop$2,
|
14236 | lineEnd: noop$2,
|
14237 | polygonStart: function() {
|
14238 | areaStream$1.lineStart = areaRingStart$1;
|
14239 | areaStream$1.lineEnd = areaRingEnd$1;
|
14240 | },
|
14241 | polygonEnd: function() {
|
14242 | areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
|
14243 | areaSum$1.add(abs(areaRingSum$1));
|
14244 | areaRingSum$1.reset();
|
14245 | },
|
14246 | result: function() {
|
14247 | var area = areaSum$1 / 2;
|
14248 | areaSum$1.reset();
|
14249 | return area;
|
14250 | }
|
14251 | };
|
14252 |
|
14253 | function areaRingStart$1() {
|
14254 | areaStream$1.point = areaPointFirst$1;
|
14255 | }
|
14256 |
|
14257 | function areaPointFirst$1(x, y) {
|
14258 | areaStream$1.point = areaPoint$1;
|
14259 | x00 = x0$1 = x, y00 = y0$1 = y;
|
14260 | }
|
14261 |
|
14262 | function areaPoint$1(x, y) {
|
14263 | areaRingSum$1.add(y0$1 * x - x0$1 * y);
|
14264 | x0$1 = x, y0$1 = y;
|
14265 | }
|
14266 |
|
14267 | function areaRingEnd$1() {
|
14268 | areaPoint$1(x00, y00);
|
14269 | }
|
14270 |
|
14271 | var x0$2 = Infinity;
|
14272 | var y0$2 = x0$2;
|
14273 | var x1 = -x0$2;
|
14274 | var y1 = x1;
|
14275 | var boundsStream$1 = {
|
14276 | point: boundsPoint$1,
|
14277 | lineStart: noop$2,
|
14278 | lineEnd: noop$2,
|
14279 | polygonStart: noop$2,
|
14280 | polygonEnd: noop$2,
|
14281 | result: function() {
|
14282 | var bounds = [[x0$2, y0$2], [x1, y1]];
|
14283 | x1 = y1 = -(y0$2 = x0$2 = Infinity);
|
14284 | return bounds;
|
14285 | }
|
14286 | };
|
14287 |
|
14288 | function boundsPoint$1(x, y) {
|
14289 | if (x < x0$2) x0$2 = x;
|
14290 | if (x > x1) x1 = x;
|
14291 | if (y < y0$2) y0$2 = y;
|
14292 | if (y > y1) y1 = y;
|
14293 | }
|
14294 |
|
14295 | var X0$1 = 0;
|
14296 | var Y0$1 = 0;
|
14297 | var Z0$1 = 0;
|
14298 | var X1$1 = 0;
|
14299 | var Y1$1 = 0;
|
14300 | var Z1$1 = 0;
|
14301 | var X2$1 = 0;
|
14302 | var Y2$1 = 0;
|
14303 | var Z2$1 = 0;
|
14304 | var x00$1;
|
14305 | var y00$1;
|
14306 | var x0$3;
|
14307 | var y0$3;
|
14308 | var centroidStream$1 = {
|
14309 | point: centroidPoint$1,
|
14310 | lineStart: centroidLineStart$1,
|
14311 | lineEnd: centroidLineEnd$1,
|
14312 | polygonStart: function() {
|
14313 | centroidStream$1.lineStart = centroidRingStart$1;
|
14314 | centroidStream$1.lineEnd = centroidRingEnd$1;
|
14315 | },
|
14316 | polygonEnd: function() {
|
14317 | centroidStream$1.point = centroidPoint$1;
|
14318 | centroidStream$1.lineStart = centroidLineStart$1;
|
14319 | centroidStream$1.lineEnd = centroidLineEnd$1;
|
14320 | },
|
14321 | result: function() {
|
14322 | var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
|
14323 | : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
|
14324 | : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
|
14325 | : [NaN, NaN];
|
14326 | X0$1 = Y0$1 = Z0$1 =
|
14327 | X1$1 = Y1$1 = Z1$1 =
|
14328 | X2$1 = Y2$1 = Z2$1 = 0;
|
14329 | return centroid;
|
14330 | }
|
14331 | };
|
14332 |
|
14333 | function centroidPoint$1(x, y) {
|
14334 | X0$1 += x;
|
14335 | Y0$1 += y;
|
14336 | ++Z0$1;
|
14337 | }
|
14338 |
|
14339 | function centroidLineStart$1() {
|
14340 | centroidStream$1.point = centroidPointFirstLine;
|
14341 | }
|
14342 |
|
14343 | function centroidPointFirstLine(x, y) {
|
14344 | centroidStream$1.point = centroidPointLine;
|
14345 | centroidPoint$1(x0$3 = x, y0$3 = y);
|
14346 | }
|
14347 |
|
14348 | function centroidPointLine(x, y) {
|
14349 | var dx = x - x0$3, dy = y - y0$3, z = sqrt$1(dx * dx + dy * dy);
|
14350 | X1$1 += z * (x0$3 + x) / 2;
|
14351 | Y1$1 += z * (y0$3 + y) / 2;
|
14352 | Z1$1 += z;
|
14353 | centroidPoint$1(x0$3 = x, y0$3 = y);
|
14354 | }
|
14355 |
|
14356 | function centroidLineEnd$1() {
|
14357 | centroidStream$1.point = centroidPoint$1;
|
14358 | }
|
14359 |
|
14360 | function centroidRingStart$1() {
|
14361 | centroidStream$1.point = centroidPointFirstRing;
|
14362 | }
|
14363 |
|
14364 | function centroidRingEnd$1() {
|
14365 | centroidPointRing(x00$1, y00$1);
|
14366 | }
|
14367 |
|
14368 | function centroidPointFirstRing(x, y) {
|
14369 | centroidStream$1.point = centroidPointRing;
|
14370 | centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
|
14371 | }
|
14372 |
|
14373 | function centroidPointRing(x, y) {
|
14374 | var dx = x - x0$3,
|
14375 | dy = y - y0$3,
|
14376 | z = sqrt$1(dx * dx + dy * dy);
|
14377 |
|
14378 | X1$1 += z * (x0$3 + x) / 2;
|
14379 | Y1$1 += z * (y0$3 + y) / 2;
|
14380 | Z1$1 += z;
|
14381 |
|
14382 | z = y0$3 * x - x0$3 * y;
|
14383 | X2$1 += z * (x0$3 + x);
|
14384 | Y2$1 += z * (y0$3 + y);
|
14385 | Z2$1 += z * 3;
|
14386 | centroidPoint$1(x0$3 = x, y0$3 = y);
|
14387 | }
|
14388 |
|
14389 | function PathContext(context) {
|
14390 | var pointRadius = 4.5;
|
14391 |
|
14392 | var stream = {
|
14393 | point: point,
|
14394 |
|
14395 | // While inside a line, override point to moveTo then lineTo.
|
14396 | lineStart: function() { stream.point = pointLineStart; },
|
14397 | lineEnd: lineEnd,
|
14398 |
|
14399 | // While inside a polygon, override lineEnd to closePath.
|
14400 | polygonStart: function() { stream.lineEnd = lineEndPolygon; },
|
14401 | polygonEnd: function() { stream.lineEnd = lineEnd; stream.point = point; },
|
14402 |
|
14403 | pointRadius: function(_) {
|
14404 | pointRadius = _;
|
14405 | return stream;
|
14406 | },
|
14407 |
|
14408 | result: noop$2
|
14409 | };
|
14410 |
|
14411 | function point(x, y) {
|
14412 | context.moveTo(x + pointRadius, y);
|
14413 | context.arc(x, y, pointRadius, 0, tau$3);
|
14414 | }
|
14415 |
|
14416 | function pointLineStart(x, y) {
|
14417 | context.moveTo(x, y);
|
14418 | stream.point = pointLine;
|
14419 | }
|
14420 |
|
14421 | function pointLine(x, y) {
|
14422 | context.lineTo(x, y);
|
14423 | }
|
14424 |
|
14425 | function lineEnd() {
|
14426 | stream.point = point;
|
14427 | }
|
14428 |
|
14429 | function lineEndPolygon() {
|
14430 | context.closePath();
|
14431 | }
|
14432 |
|
14433 | return stream;
|
14434 | }
|
14435 |
|
14436 | function PathString() {
|
14437 | var pointCircle = circle$2(4.5),
|
14438 | string = [];
|
14439 |
|
14440 | var stream = {
|
14441 | point: point,
|
14442 | lineStart: lineStart,
|
14443 | lineEnd: lineEnd,
|
14444 | polygonStart: function() {
|
14445 | stream.lineEnd = lineEndPolygon;
|
14446 | },
|
14447 | polygonEnd: function() {
|
14448 | stream.lineEnd = lineEnd;
|
14449 | stream.point = point;
|
14450 | },
|
14451 | pointRadius: function(_) {
|
14452 | pointCircle = circle$2(_);
|
14453 | return stream;
|
14454 | },
|
14455 | result: function() {
|
14456 | if (string.length) {
|
14457 | var result = string.join("");
|
14458 | string = [];
|
14459 | return result;
|
14460 | }
|
14461 | }
|
14462 | };
|
14463 |
|
14464 | function point(x, y) {
|
14465 | string.push("M", x, ",", y, pointCircle);
|
14466 | }
|
14467 |
|
14468 | function pointLineStart(x, y) {
|
14469 | string.push("M", x, ",", y);
|
14470 | stream.point = pointLine;
|
14471 | }
|
14472 |
|
14473 | function pointLine(x, y) {
|
14474 | string.push("L", x, ",", y);
|
14475 | }
|
14476 |
|
14477 | function lineStart() {
|
14478 | stream.point = pointLineStart;
|
14479 | }
|
14480 |
|
14481 | function lineEnd() {
|
14482 | stream.point = point;
|
14483 | }
|
14484 |
|
14485 | function lineEndPolygon() {
|
14486 | string.push("Z");
|
14487 | }
|
14488 |
|
14489 | return stream;
|
14490 | }
|
14491 |
|
14492 | function circle$2(radius) {
|
14493 | return "m0," + radius
|
14494 | + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
|
14495 | + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
|
14496 | + "z";
|
14497 | }
|
14498 |
|
14499 | function index$3() {
|
14500 | var pointRadius = 4.5,
|
14501 | projection,
|
14502 | projectionStream,
|
14503 | context,
|
14504 | contextStream;
|
14505 |
|
14506 | function path(object) {
|
14507 | if (object) {
|
14508 | if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
|
14509 | stream(object, projectionStream(contextStream));
|
14510 | }
|
14511 | return contextStream.result();
|
14512 | }
|
14513 |
|
14514 | path.area = function(object) {
|
14515 | stream(object, projectionStream(areaStream$1));
|
14516 | return areaStream$1.result();
|
14517 | };
|
14518 |
|
14519 | path.bounds = function(object) {
|
14520 | stream(object, projectionStream(boundsStream$1));
|
14521 | return boundsStream$1.result();
|
14522 | };
|
14523 |
|
14524 | path.centroid = function(object) {
|
14525 | stream(object, projectionStream(centroidStream$1));
|
14526 | return centroidStream$1.result();
|
14527 | };
|
14528 |
|
14529 | path.projection = function(_) {
|
14530 | return arguments.length ? (projectionStream = (projection = _) == null ? identity$7 : _.stream, path) : projection;
|
14531 | };
|
14532 |
|
14533 | path.context = function(_) {
|
14534 | if (!arguments.length) return context;
|
14535 | contextStream = (context = _) == null ? new PathString : new PathContext(_);
|
14536 | if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
|
14537 | return path;
|
14538 | };
|
14539 |
|
14540 | path.pointRadius = function(_) {
|
14541 | if (!arguments.length) return pointRadius;
|
14542 | pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
|
14543 | return path;
|
14544 | };
|
14545 |
|
14546 | return path.projection(null).context(null);
|
14547 | }
|
14548 |
|
14549 | var sum$2 = adder();
|
14550 |
|
14551 | function polygonContains(polygon, point) {
|
14552 | var lambda = point[0],
|
14553 | phi = point[1],
|
14554 | normal = [sin(lambda), -cos(lambda), 0],
|
14555 | angle = 0,
|
14556 | winding = 0;
|
14557 |
|
14558 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
14559 | if (!(m = (ring = polygon[i]).length)) continue;
|
14560 | var ring,
|
14561 | m,
|
14562 | point0 = ring[m - 1],
|
14563 | lambda0 = point0[0],
|
14564 | phi0 = point0[1] / 2 + quarterPi,
|
14565 | sinPhi0 = sin(phi0),
|
14566 | cosPhi0 = cos(phi0);
|
14567 |
|
14568 | for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
|
14569 | var point1 = ring[j],
|
14570 | lambda1 = point1[0],
|
14571 | phi1 = point1[1] / 2 + quarterPi,
|
14572 | sinPhi1 = sin(phi1),
|
14573 | cosPhi1 = cos(phi1),
|
14574 | delta = lambda1 - lambda0,
|
14575 | sign = delta >= 0 ? 1 : -1,
|
14576 | absDelta = sign * delta,
|
14577 | antimeridian = absDelta > pi$3,
|
14578 | k = sinPhi0 * sinPhi1;
|
14579 |
|
14580 | sum$2.add(atan2(k * sign * sin(absDelta), cosPhi0 * cosPhi1 + k * cos(absDelta)));
|
14581 | angle += antimeridian ? delta + sign * tau$3 : delta;
|
14582 |
|
14583 | // Are the longitudes either side of the point’s meridian (lambda),
|
14584 | // and are the latitudes smaller than the parallel (phi)?
|
14585 | if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
|
14586 | var arc = cartesianCross(cartesian(point0), cartesian(point1));
|
14587 | cartesianNormalizeInPlace(arc);
|
14588 | var intersection = cartesianCross(normal, arc);
|
14589 | cartesianNormalizeInPlace(intersection);
|
14590 | var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
|
14591 | if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
|
14592 | winding += antimeridian ^ delta >= 0 ? 1 : -1;
|
14593 | }
|
14594 | }
|
14595 | }
|
14596 | }
|
14597 |
|
14598 | // First, determine whether the South pole is inside or outside:
|
14599 | //
|
14600 | // It is inside if:
|
14601 | // * the polygon winds around it in a clockwise direction.
|
14602 | // * the polygon does not (cumulatively) wind around it, but has a negative
|
14603 | // (counter-clockwise) area.
|
14604 | //
|
14605 | // Second, count the (signed) number of times a segment crosses a lambda
|
14606 | // from the point to the South pole. If it is zero, then the point is the
|
14607 | // same side as the South pole.
|
14608 |
|
14609 | var contains = (angle < -epsilon$4 || angle < epsilon$4 && sum$2 < -epsilon$4) ^ (winding & 1);
|
14610 | sum$2.reset();
|
14611 | return contains;
|
14612 | }
|
14613 |
|
14614 | function clip(pointVisible, clipLine, interpolate, start) {
|
14615 | return function(rotate, sink) {
|
14616 | var line = clipLine(sink),
|
14617 | rotatedStart = rotate.invert(start[0], start[1]),
|
14618 | ringBuffer = clipBuffer(),
|
14619 | ringSink = clipLine(ringBuffer),
|
14620 | polygonStarted = false,
|
14621 | polygon,
|
14622 | segments,
|
14623 | ring;
|
14624 |
|
14625 | var clip = {
|
14626 | point: point,
|
14627 | lineStart: lineStart,
|
14628 | lineEnd: lineEnd,
|
14629 | polygonStart: function() {
|
14630 | clip.point = pointRing;
|
14631 | clip.lineStart = ringStart;
|
14632 | clip.lineEnd = ringEnd;
|
14633 | segments = [];
|
14634 | polygon = [];
|
14635 | },
|
14636 | polygonEnd: function() {
|
14637 | clip.point = point;
|
14638 | clip.lineStart = lineStart;
|
14639 | clip.lineEnd = lineEnd;
|
14640 | segments = merge(segments);
|
14641 | var startInside = polygonContains(polygon, rotatedStart);
|
14642 | if (segments.length) {
|
14643 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
14644 | clipPolygon(segments, compareIntersection, startInside, interpolate, sink);
|
14645 | } else if (startInside) {
|
14646 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
14647 | sink.lineStart();
|
14648 | interpolate(null, null, 1, sink);
|
14649 | sink.lineEnd();
|
14650 | }
|
14651 | if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
|
14652 | segments = polygon = null;
|
14653 | },
|
14654 | sphere: function() {
|
14655 | sink.polygonStart();
|
14656 | sink.lineStart();
|
14657 | interpolate(null, null, 1, sink);
|
14658 | sink.lineEnd();
|
14659 | sink.polygonEnd();
|
14660 | }
|
14661 | };
|
14662 |
|
14663 | function point(lambda, phi) {
|
14664 | var point = rotate(lambda, phi);
|
14665 | if (pointVisible(lambda = point[0], phi = point[1])) sink.point(lambda, phi);
|
14666 | }
|
14667 |
|
14668 | function pointLine(lambda, phi) {
|
14669 | var point = rotate(lambda, phi);
|
14670 | line.point(point[0], point[1]);
|
14671 | }
|
14672 |
|
14673 | function lineStart() {
|
14674 | clip.point = pointLine;
|
14675 | line.lineStart();
|
14676 | }
|
14677 |
|
14678 | function lineEnd() {
|
14679 | clip.point = point;
|
14680 | line.lineEnd();
|
14681 | }
|
14682 |
|
14683 | function pointRing(lambda, phi) {
|
14684 | ring.push([lambda, phi]);
|
14685 | var point = rotate(lambda, phi);
|
14686 | ringSink.point(point[0], point[1]);
|
14687 | }
|
14688 |
|
14689 | function ringStart() {
|
14690 | ringSink.lineStart();
|
14691 | ring = [];
|
14692 | }
|
14693 |
|
14694 | function ringEnd() {
|
14695 | pointRing(ring[0][0], ring[0][1]);
|
14696 | ringSink.lineEnd();
|
14697 |
|
14698 | var clean = ringSink.clean(),
|
14699 | ringSegments = ringBuffer.result(),
|
14700 | i, n = ringSegments.length, m,
|
14701 | segment,
|
14702 | point;
|
14703 |
|
14704 | ring.pop();
|
14705 | polygon.push(ring);
|
14706 | ring = null;
|
14707 |
|
14708 | if (!n) return;
|
14709 |
|
14710 | // No intersections.
|
14711 | if (clean & 1) {
|
14712 | segment = ringSegments[0];
|
14713 | if ((m = segment.length - 1) > 0) {
|
14714 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
14715 | sink.lineStart();
|
14716 | for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
|
14717 | sink.lineEnd();
|
14718 | }
|
14719 | return;
|
14720 | }
|
14721 |
|
14722 | // Rejoin connected segments.
|
14723 | // TODO reuse ringBuffer.rejoin()?
|
14724 | if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
|
14725 |
|
14726 | segments.push(ringSegments.filter(validSegment));
|
14727 | }
|
14728 |
|
14729 | return clip;
|
14730 | };
|
14731 | }
|
14732 |
|
14733 | function validSegment(segment) {
|
14734 | return segment.length > 1;
|
14735 | }
|
14736 |
|
14737 | // Intersections are sorted along the clip edge. For both antimeridian cutting
|
14738 | // and circle clipping, the same comparison is used.
|
14739 | function compareIntersection(a, b) {
|
14740 | return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$4 : halfPi$2 - a[1])
|
14741 | - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$4 : halfPi$2 - b[1]);
|
14742 | }
|
14743 |
|
14744 | var clipAntimeridian = clip(
|
14745 | function() { return true; },
|
14746 | clipAntimeridianLine,
|
14747 | clipAntimeridianInterpolate,
|
14748 | [-pi$3, -halfPi$2]
|
14749 | );
|
14750 |
|
14751 | // Takes a line and cuts into visible segments. Return values: 0 - there were
|
14752 | // intersections or the line was empty; 1 - no intersections; 2 - there were
|
14753 | // intersections, and the first and last segments should be rejoined.
|
14754 | function clipAntimeridianLine(stream) {
|
14755 | var lambda0 = NaN,
|
14756 | phi0 = NaN,
|
14757 | sign0 = NaN,
|
14758 | clean; // no intersections
|
14759 |
|
14760 | return {
|
14761 | lineStart: function() {
|
14762 | stream.lineStart();
|
14763 | clean = 1;
|
14764 | },
|
14765 | point: function(lambda1, phi1) {
|
14766 | var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
|
14767 | delta = abs(lambda1 - lambda0);
|
14768 | if (abs(delta - pi$3) < epsilon$4) { // line crosses a pole
|
14769 | stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
|
14770 | stream.point(sign0, phi0);
|
14771 | stream.lineEnd();
|
14772 | stream.lineStart();
|
14773 | stream.point(sign1, phi0);
|
14774 | stream.point(lambda1, phi0);
|
14775 | clean = 0;
|
14776 | } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
|
14777 | if (abs(lambda0 - sign0) < epsilon$4) lambda0 -= sign0 * epsilon$4; // handle degeneracies
|
14778 | if (abs(lambda1 - sign1) < epsilon$4) lambda1 -= sign1 * epsilon$4;
|
14779 | phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
|
14780 | stream.point(sign0, phi0);
|
14781 | stream.lineEnd();
|
14782 | stream.lineStart();
|
14783 | stream.point(sign1, phi0);
|
14784 | clean = 0;
|
14785 | }
|
14786 | stream.point(lambda0 = lambda1, phi0 = phi1);
|
14787 | sign0 = sign1;
|
14788 | },
|
14789 | lineEnd: function() {
|
14790 | stream.lineEnd();
|
14791 | lambda0 = phi0 = NaN;
|
14792 | },
|
14793 | clean: function() {
|
14794 | return 2 - clean; // if intersections, rejoin first and last segments
|
14795 | }
|
14796 | };
|
14797 | }
|
14798 |
|
14799 | function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
|
14800 | var cosPhi0,
|
14801 | cosPhi1,
|
14802 | sinLambda0Lambda1 = sin(lambda0 - lambda1);
|
14803 | return abs(sinLambda0Lambda1) > epsilon$4
|
14804 | ? atan((sin(phi0) * (cosPhi1 = cos(phi1)) * sin(lambda1)
|
14805 | - sin(phi1) * (cosPhi0 = cos(phi0)) * sin(lambda0))
|
14806 | / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
|
14807 | : (phi0 + phi1) / 2;
|
14808 | }
|
14809 |
|
14810 | function clipAntimeridianInterpolate(from, to, direction, stream) {
|
14811 | var phi;
|
14812 | if (from == null) {
|
14813 | phi = direction * halfPi$2;
|
14814 | stream.point(-pi$3, phi);
|
14815 | stream.point(0, phi);
|
14816 | stream.point(pi$3, phi);
|
14817 | stream.point(pi$3, 0);
|
14818 | stream.point(pi$3, -phi);
|
14819 | stream.point(0, -phi);
|
14820 | stream.point(-pi$3, -phi);
|
14821 | stream.point(-pi$3, 0);
|
14822 | stream.point(-pi$3, phi);
|
14823 | } else if (abs(from[0] - to[0]) > epsilon$4) {
|
14824 | var lambda = from[0] < to[0] ? pi$3 : -pi$3;
|
14825 | phi = direction * lambda / 2;
|
14826 | stream.point(-lambda, phi);
|
14827 | stream.point(0, phi);
|
14828 | stream.point(lambda, phi);
|
14829 | } else {
|
14830 | stream.point(to[0], to[1]);
|
14831 | }
|
14832 | }
|
14833 |
|
14834 | function clipCircle(radius, delta) {
|
14835 | var cr = cos(radius),
|
14836 | smallRadius = cr > 0,
|
14837 | notHemisphere = abs(cr) > epsilon$4; // TODO optimise for this common case
|
14838 |
|
14839 | function interpolate(from, to, direction, stream) {
|
14840 | circleStream(stream, radius, delta, direction, from, to);
|
14841 | }
|
14842 |
|
14843 | function visible(lambda, phi) {
|
14844 | return cos(lambda) * cos(phi) > cr;
|
14845 | }
|
14846 |
|
14847 | // Takes a line and cuts into visible segments. Return values used for polygon
|
14848 | // clipping: 0 - there were intersections or the line was empty; 1 - no
|
14849 | // intersections 2 - there were intersections, and the first and last segments
|
14850 | // should be rejoined.
|
14851 | function clipLine(stream) {
|
14852 | var point0, // previous point
|
14853 | c0, // code for previous point
|
14854 | v0, // visibility of previous point
|
14855 | v00, // visibility of first point
|
14856 | clean; // no intersections
|
14857 | return {
|
14858 | lineStart: function() {
|
14859 | v00 = v0 = false;
|
14860 | clean = 1;
|
14861 | },
|
14862 | point: function(lambda, phi) {
|
14863 | var point1 = [lambda, phi],
|
14864 | point2,
|
14865 | v = visible(lambda, phi),
|
14866 | c = smallRadius
|
14867 | ? v ? 0 : code(lambda, phi)
|
14868 | : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
|
14869 | if (!point0 && (v00 = v0 = v)) stream.lineStart();
|
14870 | // Handle degeneracies.
|
14871 | // TODO ignore if not clipping polygons.
|
14872 | if (v !== v0) {
|
14873 | point2 = intersect(point0, point1);
|
14874 | if (pointEqual(point0, point2) || pointEqual(point1, point2)) {
|
14875 | point1[0] += epsilon$4;
|
14876 | point1[1] += epsilon$4;
|
14877 | v = visible(point1[0], point1[1]);
|
14878 | }
|
14879 | }
|
14880 | if (v !== v0) {
|
14881 | clean = 0;
|
14882 | if (v) {
|
14883 | // outside going in
|
14884 | stream.lineStart();
|
14885 | point2 = intersect(point1, point0);
|
14886 | stream.point(point2[0], point2[1]);
|
14887 | } else {
|
14888 | // inside going out
|
14889 | point2 = intersect(point0, point1);
|
14890 | stream.point(point2[0], point2[1]);
|
14891 | stream.lineEnd();
|
14892 | }
|
14893 | point0 = point2;
|
14894 | } else if (notHemisphere && point0 && smallRadius ^ v) {
|
14895 | var t;
|
14896 | // If the codes for two points are different, or are both zero,
|
14897 | // and there this segment intersects with the small circle.
|
14898 | if (!(c & c0) && (t = intersect(point1, point0, true))) {
|
14899 | clean = 0;
|
14900 | if (smallRadius) {
|
14901 | stream.lineStart();
|
14902 | stream.point(t[0][0], t[0][1]);
|
14903 | stream.point(t[1][0], t[1][1]);
|
14904 | stream.lineEnd();
|
14905 | } else {
|
14906 | stream.point(t[1][0], t[1][1]);
|
14907 | stream.lineEnd();
|
14908 | stream.lineStart();
|
14909 | stream.point(t[0][0], t[0][1]);
|
14910 | }
|
14911 | }
|
14912 | }
|
14913 | if (v && (!point0 || !pointEqual(point0, point1))) {
|
14914 | stream.point(point1[0], point1[1]);
|
14915 | }
|
14916 | point0 = point1, v0 = v, c0 = c;
|
14917 | },
|
14918 | lineEnd: function() {
|
14919 | if (v0) stream.lineEnd();
|
14920 | point0 = null;
|
14921 | },
|
14922 | // Rejoin first and last segments if there were intersections and the first
|
14923 | // and last points were visible.
|
14924 | clean: function() {
|
14925 | return clean | ((v00 && v0) << 1);
|
14926 | }
|
14927 | };
|
14928 | }
|
14929 |
|
14930 | // Intersects the great circle between a and b with the clip circle.
|
14931 | function intersect(a, b, two) {
|
14932 | var pa = cartesian(a),
|
14933 | pb = cartesian(b);
|
14934 |
|
14935 | // We have two planes, n1.p = d1 and n2.p = d2.
|
14936 | // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
|
14937 | var n1 = [1, 0, 0], // normal
|
14938 | n2 = cartesianCross(pa, pb),
|
14939 | n2n2 = cartesianDot(n2, n2),
|
14940 | n1n2 = n2[0], // cartesianDot(n1, n2),
|
14941 | determinant = n2n2 - n1n2 * n1n2;
|
14942 |
|
14943 | // Two polar points.
|
14944 | if (!determinant) return !two && a;
|
14945 |
|
14946 | var c1 = cr * n2n2 / determinant,
|
14947 | c2 = -cr * n1n2 / determinant,
|
14948 | n1xn2 = cartesianCross(n1, n2),
|
14949 | A = cartesianScale(n1, c1),
|
14950 | B = cartesianScale(n2, c2);
|
14951 | cartesianAddInPlace(A, B);
|
14952 |
|
14953 | // Solve |p(t)|^2 = 1.
|
14954 | var u = n1xn2,
|
14955 | w = cartesianDot(A, u),
|
14956 | uu = cartesianDot(u, u),
|
14957 | t2 = w * w - uu * (cartesianDot(A, A) - 1);
|
14958 |
|
14959 | if (t2 < 0) return;
|
14960 |
|
14961 | var t = sqrt$1(t2),
|
14962 | q = cartesianScale(u, (-w - t) / uu);
|
14963 | cartesianAddInPlace(q, A);
|
14964 | q = spherical(q);
|
14965 |
|
14966 | if (!two) return q;
|
14967 |
|
14968 | // Two intersection points.
|
14969 | var lambda0 = a[0],
|
14970 | lambda1 = b[0],
|
14971 | phi0 = a[1],
|
14972 | phi1 = b[1],
|
14973 | z;
|
14974 |
|
14975 | if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
|
14976 |
|
14977 | var delta = lambda1 - lambda0,
|
14978 | polar = abs(delta - pi$3) < epsilon$4,
|
14979 | meridian = polar || delta < epsilon$4;
|
14980 |
|
14981 | if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
|
14982 |
|
14983 | // Check that the first point is between a and b.
|
14984 | if (meridian
|
14985 | ? polar
|
14986 | ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$4 ? phi0 : phi1)
|
14987 | : phi0 <= q[1] && q[1] <= phi1
|
14988 | : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
|
14989 | var q1 = cartesianScale(u, (-w + t) / uu);
|
14990 | cartesianAddInPlace(q1, A);
|
14991 | return [q, spherical(q1)];
|
14992 | }
|
14993 | }
|
14994 |
|
14995 | // Generates a 4-bit vector representing the location of a point relative to
|
14996 | // the small circle's bounding box.
|
14997 | function code(lambda, phi) {
|
14998 | var r = smallRadius ? radius : pi$3 - radius,
|
14999 | code = 0;
|
15000 | if (lambda < -r) code |= 1; // left
|
15001 | else if (lambda > r) code |= 2; // right
|
15002 | if (phi < -r) code |= 4; // below
|
15003 | else if (phi > r) code |= 8; // above
|
15004 | return code;
|
15005 | }
|
15006 |
|
15007 | return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
|
15008 | }
|
15009 |
|
15010 | function transform$1(prototype) {
|
15011 | return {
|
15012 | stream: transform$2(prototype)
|
15013 | };
|
15014 | }
|
15015 |
|
15016 | function transform$2(prototype) {
|
15017 | function T() {}
|
15018 | var p = T.prototype = Object.create(Transform$1.prototype);
|
15019 | for (var k in prototype) p[k] = prototype[k];
|
15020 | return function(stream) {
|
15021 | var t = new T;
|
15022 | t.stream = stream;
|
15023 | return t;
|
15024 | };
|
15025 | }
|
15026 |
|
15027 | function Transform$1() {}
|
15028 |
|
15029 | Transform$1.prototype = {
|
15030 | point: function(x, y) { this.stream.point(x, y); },
|
15031 | sphere: function() { this.stream.sphere(); },
|
15032 | lineStart: function() { this.stream.lineStart(); },
|
15033 | lineEnd: function() { this.stream.lineEnd(); },
|
15034 | polygonStart: function() { this.stream.polygonStart(); },
|
15035 | polygonEnd: function() { this.stream.polygonEnd(); }
|
15036 | };
|
15037 |
|
15038 | var maxDepth = 16;
|
15039 | var cosMinDistance = cos(30 * radians);
|
15040 | // cos(minimum angular distance)
|
15041 |
|
15042 | function resample(project, delta2) {
|
15043 | return +delta2 ? resample$1(project, delta2) : resampleNone(project);
|
15044 | }
|
15045 |
|
15046 | function resampleNone(project) {
|
15047 | return transform$2({
|
15048 | point: function(x, y) {
|
15049 | x = project(x, y);
|
15050 | this.stream.point(x[0], x[1]);
|
15051 | }
|
15052 | });
|
15053 | }
|
15054 |
|
15055 | function resample$1(project, delta2) {
|
15056 |
|
15057 | function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
|
15058 | var dx = x1 - x0,
|
15059 | dy = y1 - y0,
|
15060 | d2 = dx * dx + dy * dy;
|
15061 | if (d2 > 4 * delta2 && depth--) {
|
15062 | var a = a0 + a1,
|
15063 | b = b0 + b1,
|
15064 | c = c0 + c1,
|
15065 | m = sqrt$1(a * a + b * b + c * c),
|
15066 | phi2 = asin$1(c /= m),
|
15067 | lambda2 = abs(abs(c) - 1) < epsilon$4 || abs(lambda0 - lambda1) < epsilon$4 ? (lambda0 + lambda1) / 2 : atan2(b, a),
|
15068 | p = project(lambda2, phi2),
|
15069 | x2 = p[0],
|
15070 | y2 = p[1],
|
15071 | dx2 = x2 - x0,
|
15072 | dy2 = y2 - y0,
|
15073 | dz = dy * dx2 - dx * dy2;
|
15074 | if (dz * dz / d2 > delta2 // perpendicular projected distance
|
15075 | || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
|
15076 | || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
|
15077 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
|
15078 | stream.point(x2, y2);
|
15079 | resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
|
15080 | }
|
15081 | }
|
15082 | }
|
15083 | return function(stream) {
|
15084 | var lambda00, x00, y00, a00, b00, c00, // first point
|
15085 | lambda0, x0, y0, a0, b0, c0; // previous point
|
15086 |
|
15087 | var resampleStream = {
|
15088 | point: point,
|
15089 | lineStart: lineStart,
|
15090 | lineEnd: lineEnd,
|
15091 | polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
|
15092 | polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
|
15093 | };
|
15094 |
|
15095 | function point(x, y) {
|
15096 | x = project(x, y);
|
15097 | stream.point(x[0], x[1]);
|
15098 | }
|
15099 |
|
15100 | function lineStart() {
|
15101 | x0 = NaN;
|
15102 | resampleStream.point = linePoint;
|
15103 | stream.lineStart();
|
15104 | }
|
15105 |
|
15106 | function linePoint(lambda, phi) {
|
15107 | var c = cartesian([lambda, phi]), p = project(lambda, phi);
|
15108 | 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);
|
15109 | stream.point(x0, y0);
|
15110 | }
|
15111 |
|
15112 | function lineEnd() {
|
15113 | resampleStream.point = point;
|
15114 | stream.lineEnd();
|
15115 | }
|
15116 |
|
15117 | function ringStart() {
|
15118 | lineStart();
|
15119 | resampleStream.point = ringPoint;
|
15120 | resampleStream.lineEnd = ringEnd;
|
15121 | }
|
15122 |
|
15123 | function ringPoint(lambda, phi) {
|
15124 | linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
|
15125 | resampleStream.point = linePoint;
|
15126 | }
|
15127 |
|
15128 | function ringEnd() {
|
15129 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
|
15130 | resampleStream.lineEnd = lineEnd;
|
15131 | lineEnd();
|
15132 | }
|
15133 |
|
15134 | return resampleStream;
|
15135 | };
|
15136 | }
|
15137 |
|
15138 | var transformRadians = transform$2({
|
15139 | point: function(x, y) {
|
15140 | this.stream.point(x * radians, y * radians);
|
15141 | }
|
15142 | });
|
15143 |
|
15144 | function projection(project) {
|
15145 | return projectionMutator(function() { return project; })();
|
15146 | }
|
15147 |
|
15148 | function projectionMutator(projectAt) {
|
15149 | var project,
|
15150 | k = 150, // scale
|
15151 | x = 480, y = 250, // translate
|
15152 | dx, dy, lambda = 0, phi = 0, // center
|
15153 | deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate, // rotate
|
15154 | theta = null, preclip = clipAntimeridian, // clip angle
|
15155 | x0 = null, y0, x1, y1, postclip = identity$7, // clip extent
|
15156 | delta2 = 0.5, projectResample = resample(projectTransform, delta2), // precision
|
15157 | cache,
|
15158 | cacheStream;
|
15159 |
|
15160 | function projection(point) {
|
15161 | point = projectRotate(point[0] * radians, point[1] * radians);
|
15162 | return [point[0] * k + dx, dy - point[1] * k];
|
15163 | }
|
15164 |
|
15165 | function invert(point) {
|
15166 | point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
|
15167 | return point && [point[0] * degrees$1, point[1] * degrees$1];
|
15168 | }
|
15169 |
|
15170 | function projectTransform(x, y) {
|
15171 | return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
|
15172 | }
|
15173 |
|
15174 | projection.stream = function(stream) {
|
15175 | return cache && cacheStream === stream ? cache : cache = transformRadians(preclip(rotate, projectResample(postclip(cacheStream = stream))));
|
15176 | };
|
15177 |
|
15178 | projection.clipAngle = function(_) {
|
15179 | return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians, 6 * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
|
15180 | };
|
15181 |
|
15182 | projection.clipExtent = function(_) {
|
15183 | return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$7) : clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
|
15184 | };
|
15185 |
|
15186 | projection.scale = function(_) {
|
15187 | return arguments.length ? (k = +_, recenter()) : k;
|
15188 | };
|
15189 |
|
15190 | projection.translate = function(_) {
|
15191 | return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
|
15192 | };
|
15193 |
|
15194 | projection.center = function(_) {
|
15195 | return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
|
15196 | };
|
15197 |
|
15198 | projection.rotate = function(_) {
|
15199 | 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];
|
15200 | };
|
15201 |
|
15202 | projection.precision = function(_) {
|
15203 | return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$1(delta2);
|
15204 | };
|
15205 |
|
15206 | function recenter() {
|
15207 | projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
|
15208 | var center = project(lambda, phi);
|
15209 | dx = x - center[0] * k;
|
15210 | dy = y + center[1] * k;
|
15211 | return reset();
|
15212 | }
|
15213 |
|
15214 | function reset() {
|
15215 | cache = cacheStream = null;
|
15216 | return projection;
|
15217 | }
|
15218 |
|
15219 | return function() {
|
15220 | project = projectAt.apply(this, arguments);
|
15221 | projection.invert = project.invert && invert;
|
15222 | return recenter();
|
15223 | };
|
15224 | }
|
15225 |
|
15226 | function conicProjection(projectAt) {
|
15227 | var phi0 = 0,
|
15228 | phi1 = pi$3 / 3,
|
15229 | m = projectionMutator(projectAt),
|
15230 | p = m(phi0, phi1);
|
15231 |
|
15232 | p.parallels = function(_) {
|
15233 | return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
|
15234 | };
|
15235 |
|
15236 | return p;
|
15237 | }
|
15238 |
|
15239 | function conicEqualArea(y0, y1) {
|
15240 | var sy0 = sin(y0),
|
15241 | n = (sy0 + sin(y1)) / 2,
|
15242 | c = 1 + sy0 * (2 * n - sy0),
|
15243 | r0 = sqrt$1(c) / n;
|
15244 |
|
15245 | function project(x, y) {
|
15246 | var r = sqrt$1(c - 2 * n * sin(y)) / n;
|
15247 | return [r * sin(x *= n), r0 - r * cos(x)];
|
15248 | }
|
15249 |
|
15250 | project.invert = function(x, y) {
|
15251 | var r0y = r0 - y;
|
15252 | return [atan2(x, r0y) / n, asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
|
15253 | };
|
15254 |
|
15255 | return project;
|
15256 | }
|
15257 |
|
15258 | function conicEqualArea$1() {
|
15259 | return conicProjection(conicEqualArea)
|
15260 | .scale(151)
|
15261 | .translate([480, 347]);
|
15262 | }
|
15263 |
|
15264 | function albers() {
|
15265 | return conicEqualArea$1()
|
15266 | .parallels([29.5, 45.5])
|
15267 | .scale(1070)
|
15268 | .translate([480, 250])
|
15269 | .rotate([96, 0])
|
15270 | .center([-0.6, 38.7]);
|
15271 | }
|
15272 |
|
15273 | // The projections must have mutually exclusive clip regions on the sphere,
|
15274 | // as this will avoid emitting interleaving lines and polygons.
|
15275 | function multiplex(streams) {
|
15276 | var n = streams.length;
|
15277 | return {
|
15278 | point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
|
15279 | sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
|
15280 | lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
|
15281 | lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
|
15282 | polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
|
15283 | polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
|
15284 | };
|
15285 | }
|
15286 |
|
15287 | // A composite projection for the United States, configured by default for
|
15288 | // 960×500. Also works quite well at 960×600 with scale 1285. The set of
|
15289 | // standard parallels for each region comes from USGS, which is published here:
|
15290 | // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
|
15291 | function albersUsa() {
|
15292 | var cache,
|
15293 | cacheStream,
|
15294 | lower48 = albers(), lower48Point,
|
15295 | alaska = conicEqualArea$1().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
|
15296 | hawaii = conicEqualArea$1().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
|
15297 | point, pointStream = {point: function(x, y) { point = [x, y]; }};
|
15298 |
|
15299 | function albersUsa(coordinates) {
|
15300 | var x = coordinates[0], y = coordinates[1];
|
15301 | return point = null,
|
15302 | (lower48Point.point(x, y), point)
|
15303 | || (alaskaPoint.point(x, y), point)
|
15304 | || (hawaiiPoint.point(x, y), point);
|
15305 | }
|
15306 |
|
15307 | albersUsa.invert = function(coordinates) {
|
15308 | var k = lower48.scale(),
|
15309 | t = lower48.translate(),
|
15310 | x = (coordinates[0] - t[0]) / k,
|
15311 | y = (coordinates[1] - t[1]) / k;
|
15312 | return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
|
15313 | : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
|
15314 | : lower48).invert(coordinates);
|
15315 | };
|
15316 |
|
15317 | albersUsa.stream = function(stream) {
|
15318 | return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
|
15319 | };
|
15320 |
|
15321 | albersUsa.precision = function(_) {
|
15322 | if (!arguments.length) return lower48.precision();
|
15323 | lower48.precision(_), alaska.precision(_), hawaii.precision(_);
|
15324 | return albersUsa;
|
15325 | };
|
15326 |
|
15327 | albersUsa.scale = function(_) {
|
15328 | if (!arguments.length) return lower48.scale();
|
15329 | lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
|
15330 | return albersUsa.translate(lower48.translate());
|
15331 | };
|
15332 |
|
15333 | albersUsa.translate = function(_) {
|
15334 | if (!arguments.length) return lower48.translate();
|
15335 | var k = lower48.scale(), x = +_[0], y = +_[1];
|
15336 |
|
15337 | lower48Point = lower48
|
15338 | .translate(_)
|
15339 | .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
|
15340 | .stream(pointStream);
|
15341 |
|
15342 | alaskaPoint = alaska
|
15343 | .translate([x - 0.307 * k, y + 0.201 * k])
|
15344 | .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]])
|
15345 | .stream(pointStream);
|
15346 |
|
15347 | hawaiiPoint = hawaii
|
15348 | .translate([x - 0.205 * k, y + 0.212 * k])
|
15349 | .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]])
|
15350 | .stream(pointStream);
|
15351 |
|
15352 | return albersUsa;
|
15353 | };
|
15354 |
|
15355 | return albersUsa.scale(1070);
|
15356 | }
|
15357 |
|
15358 | function azimuthal(scale) {
|
15359 | return function(x, y) {
|
15360 | var cx = cos(x),
|
15361 | cy = cos(y),
|
15362 | k = scale(cx * cy);
|
15363 | return [
|
15364 | k * cy * sin(x),
|
15365 | k * sin(y)
|
15366 | ];
|
15367 | }
|
15368 | }
|
15369 |
|
15370 | function azimuthalInvert(angle) {
|
15371 | return function(x, y) {
|
15372 | var z = sqrt$1(x * x + y * y),
|
15373 | c = angle(z),
|
15374 | sc = sin(c),
|
15375 | cc = cos(c);
|
15376 | return [
|
15377 | atan2(x * sc, z * cc),
|
15378 | asin$1(z && y * sc / z)
|
15379 | ];
|
15380 | }
|
15381 | }
|
15382 |
|
15383 | var azimuthalEqualArea = azimuthal(function(cxcy) {
|
15384 | return sqrt$1(2 / (1 + cxcy));
|
15385 | });
|
15386 |
|
15387 | azimuthalEqualArea.invert = azimuthalInvert(function(z) {
|
15388 | return 2 * asin$1(z / 2);
|
15389 | });
|
15390 |
|
15391 | function azimuthalEqualArea$1() {
|
15392 | return projection(azimuthalEqualArea)
|
15393 | .scale(120)
|
15394 | .clipAngle(180 - 1e-3);
|
15395 | }
|
15396 |
|
15397 | var azimuthalEquidistant = azimuthal(function(c) {
|
15398 | return (c = acos(c)) && c / sin(c);
|
15399 | });
|
15400 |
|
15401 | azimuthalEquidistant.invert = azimuthalInvert(function(z) {
|
15402 | return z;
|
15403 | });
|
15404 |
|
15405 | function azimuthalEquidistant$1() {
|
15406 | return projection(azimuthalEquidistant)
|
15407 | .scale(480 / tau$3)
|
15408 | .clipAngle(180 - 1e-3);
|
15409 | }
|
15410 |
|
15411 | function mercator(lambda, phi) {
|
15412 | return [lambda, log$1(tan((halfPi$2 + phi) / 2))];
|
15413 | }
|
15414 |
|
15415 | mercator.invert = function(x, y) {
|
15416 | return [x, 2 * atan(exp(y)) - halfPi$2];
|
15417 | };
|
15418 |
|
15419 | function mercator$1() {
|
15420 | return mercatorProjection(mercator);
|
15421 | }
|
15422 |
|
15423 | function mercatorProjection(project) {
|
15424 | var m = projection(project),
|
15425 | scale = m.scale,
|
15426 | translate = m.translate,
|
15427 | clipExtent = m.clipExtent,
|
15428 | clipAuto;
|
15429 |
|
15430 | m.scale = function(_) {
|
15431 | return arguments.length ? (scale(_), clipAuto && m.clipExtent(null), m) : scale();
|
15432 | };
|
15433 |
|
15434 | m.translate = function(_) {
|
15435 | return arguments.length ? (translate(_), clipAuto && m.clipExtent(null), m) : translate();
|
15436 | };
|
15437 |
|
15438 | m.clipExtent = function(_) {
|
15439 | if (!arguments.length) return clipAuto ? null : clipExtent();
|
15440 | if (clipAuto = _ == null) {
|
15441 | var k = pi$3 * scale(), t = translate();
|
15442 | _ = [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]];
|
15443 | }
|
15444 | clipExtent(_);
|
15445 | return m;
|
15446 | };
|
15447 |
|
15448 | return m.clipExtent(null).scale(961 / tau$3);
|
15449 | }
|
15450 |
|
15451 | function tany(y) {
|
15452 | return tan((halfPi$2 + y) / 2);
|
15453 | }
|
15454 |
|
15455 | function conicConformal(y0, y1) {
|
15456 | var cy0 = cos(y0),
|
15457 | n = y0 === y1 ? sin(y0) : log$1(cy0 / cos(y1)) / log$1(tany(y1) / tany(y0)),
|
15458 | f = cy0 * pow$1(tany(y0), n) / n;
|
15459 |
|
15460 | if (!n) return mercator;
|
15461 |
|
15462 | function project(x, y) {
|
15463 | if (f > 0) { if (y < -halfPi$2 + epsilon$4) y = -halfPi$2 + epsilon$4; }
|
15464 | else { if (y > halfPi$2 - epsilon$4) y = halfPi$2 - epsilon$4; }
|
15465 | var r = f / pow$1(tany(y), n);
|
15466 | return [r * sin(n * x), f - r * cos(n * x)];
|
15467 | }
|
15468 |
|
15469 | project.invert = function(x, y) {
|
15470 | var fy = f - y, r = sign$1(n) * sqrt$1(x * x + fy * fy);
|
15471 | return [atan2(x, fy) / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$2];
|
15472 | };
|
15473 |
|
15474 | return project;
|
15475 | }
|
15476 |
|
15477 | function conicConformal$1() {
|
15478 | return conicProjection(conicConformal);
|
15479 | }
|
15480 |
|
15481 | function equirectangular(lambda, phi) {
|
15482 | return [lambda, phi];
|
15483 | }
|
15484 |
|
15485 | equirectangular.invert = equirectangular;
|
15486 |
|
15487 | function equirectangular$1() {
|
15488 | return projection(equirectangular).scale(480 / pi$3);
|
15489 | }
|
15490 |
|
15491 | function conicEquidistant(y0, y1) {
|
15492 | var cy0 = cos(y0),
|
15493 | n = y0 === y1 ? sin(y0) : (cy0 - cos(y1)) / (y1 - y0),
|
15494 | g = cy0 / n + y0;
|
15495 |
|
15496 | if (abs(n) < epsilon$4) return equirectangular;
|
15497 |
|
15498 | function project(x, y) {
|
15499 | var gy = g - y, nx = n * x;
|
15500 | return [gy * sin(nx), g - gy * cos(nx)];
|
15501 | }
|
15502 |
|
15503 | project.invert = function(x, y) {
|
15504 | var gy = g - y;
|
15505 | return [atan2(x, gy) / n, g - sign$1(n) * sqrt$1(x * x + gy * gy)];
|
15506 | };
|
15507 |
|
15508 | return project;
|
15509 | }
|
15510 |
|
15511 | function conicEquidistant$1() {
|
15512 | return conicProjection(conicEquidistant)
|
15513 | .scale(128)
|
15514 | .translate([480, 280]);
|
15515 | }
|
15516 |
|
15517 | function gnomonic(x, y) {
|
15518 | var cy = cos(y), k = cos(x) * cy;
|
15519 | return [cy * sin(x) / k, sin(y) / k];
|
15520 | }
|
15521 |
|
15522 | gnomonic.invert = azimuthalInvert(atan);
|
15523 |
|
15524 | function gnomonic$1() {
|
15525 | return projection(gnomonic)
|
15526 | .scale(139)
|
15527 | .clipAngle(60);
|
15528 | }
|
15529 |
|
15530 | function orthographic(x, y) {
|
15531 | return [cos(y) * sin(x), sin(y)];
|
15532 | }
|
15533 |
|
15534 | orthographic.invert = azimuthalInvert(asin$1);
|
15535 |
|
15536 | function orthographic$1() {
|
15537 | return projection(orthographic)
|
15538 | .scale(240)
|
15539 | .clipAngle(90 + epsilon$4);
|
15540 | }
|
15541 |
|
15542 | function stereographic(x, y) {
|
15543 | var cy = cos(y), k = 1 + cos(x) * cy;
|
15544 | return [cy * sin(x) / k, sin(y) / k];
|
15545 | }
|
15546 |
|
15547 | stereographic.invert = azimuthalInvert(function(z) {
|
15548 | return 2 + atan(z);
|
15549 | });
|
15550 |
|
15551 | function stereographic$1() {
|
15552 | return projection(stereographic)
|
15553 | .scale(240)
|
15554 | .clipAngle(142);
|
15555 | }
|
15556 |
|
15557 | function transverseMercator(lambda, phi) {
|
15558 | return [log$1(tan((halfPi$2 + phi) / 2)), -lambda];
|
15559 | }
|
15560 |
|
15561 | transverseMercator.invert = function(x, y) {
|
15562 | return [-y, 2 * atan(exp(x)) - halfPi$2];
|
15563 | };
|
15564 |
|
15565 | function transverseMercator$1() {
|
15566 | var m = mercatorProjection(transverseMercator),
|
15567 | center = m.center,
|
15568 | rotate = m.rotate;
|
15569 |
|
15570 | m.center = function(_) {
|
15571 | return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
|
15572 | };
|
15573 |
|
15574 | m.rotate = function(_) {
|
15575 | return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
|
15576 | };
|
15577 |
|
15578 | return rotate([0, 0, 90]);
|
15579 | }
|
15580 |
|
15581 | exports.version = version;
|
15582 | exports.bisect = bisectRight;
|
15583 | exports.bisectRight = bisectRight;
|
15584 | exports.bisectLeft = bisectLeft;
|
15585 | exports.ascending = ascending;
|
15586 | exports.bisector = bisector;
|
15587 | exports.descending = descending;
|
15588 | exports.deviation = deviation;
|
15589 | exports.extent = extent;
|
15590 | exports.histogram = histogram;
|
15591 | exports.thresholdFreedmanDiaconis = freedmanDiaconis;
|
15592 | exports.thresholdScott = scott;
|
15593 | exports.thresholdSturges = sturges;
|
15594 | exports.max = max;
|
15595 | exports.mean = mean;
|
15596 | exports.median = median;
|
15597 | exports.merge = merge;
|
15598 | exports.min = min;
|
15599 | exports.pairs = pairs;
|
15600 | exports.permute = permute;
|
15601 | exports.quantile = threshold;
|
15602 | exports.range = range;
|
15603 | exports.scan = scan;
|
15604 | exports.shuffle = shuffle;
|
15605 | exports.sum = sum;
|
15606 | exports.ticks = ticks;
|
15607 | exports.tickStep = tickStep;
|
15608 | exports.transpose = transpose;
|
15609 | exports.variance = variance;
|
15610 | exports.zip = zip;
|
15611 | exports.entries = entries;
|
15612 | exports.keys = keys;
|
15613 | exports.values = values;
|
15614 | exports.map = map$1;
|
15615 | exports.set = set;
|
15616 | exports.nest = nest;
|
15617 | exports.randomUniform = uniform;
|
15618 | exports.randomNormal = normal;
|
15619 | exports.randomLogNormal = logNormal;
|
15620 | exports.randomBates = bates;
|
15621 | exports.randomIrwinHall = irwinHall;
|
15622 | exports.randomExponential = exponential;
|
15623 | exports.easeLinear = linear;
|
15624 | exports.easeQuad = quadInOut;
|
15625 | exports.easeQuadIn = quadIn;
|
15626 | exports.easeQuadOut = quadOut;
|
15627 | exports.easeQuadInOut = quadInOut;
|
15628 | exports.easeCubic = easeCubicInOut;
|
15629 | exports.easeCubicIn = cubicIn;
|
15630 | exports.easeCubicOut = cubicOut;
|
15631 | exports.easeCubicInOut = easeCubicInOut;
|
15632 | exports.easePoly = polyInOut;
|
15633 | exports.easePolyIn = polyIn;
|
15634 | exports.easePolyOut = polyOut;
|
15635 | exports.easePolyInOut = polyInOut;
|
15636 | exports.easeSin = sinInOut;
|
15637 | exports.easeSinIn = sinIn;
|
15638 | exports.easeSinOut = sinOut;
|
15639 | exports.easeSinInOut = sinInOut;
|
15640 | exports.easeExp = expInOut;
|
15641 | exports.easeExpIn = expIn;
|
15642 | exports.easeExpOut = expOut;
|
15643 | exports.easeExpInOut = expInOut;
|
15644 | exports.easeCircle = circleInOut;
|
15645 | exports.easeCircleIn = circleIn;
|
15646 | exports.easeCircleOut = circleOut;
|
15647 | exports.easeCircleInOut = circleInOut;
|
15648 | exports.easeBounce = bounceOut;
|
15649 | exports.easeBounceIn = bounceIn;
|
15650 | exports.easeBounceOut = bounceOut;
|
15651 | exports.easeBounceInOut = bounceInOut;
|
15652 | exports.easeBack = backInOut;
|
15653 | exports.easeBackIn = backIn;
|
15654 | exports.easeBackOut = backOut;
|
15655 | exports.easeBackInOut = backInOut;
|
15656 | exports.easeElastic = elasticOut;
|
15657 | exports.easeElasticIn = elasticIn;
|
15658 | exports.easeElasticOut = elasticOut;
|
15659 | exports.easeElasticInOut = elasticInOut;
|
15660 | exports.polygonArea = area;
|
15661 | exports.polygonCentroid = centroid;
|
15662 | exports.polygonHull = hull;
|
15663 | exports.polygonContains = contains;
|
15664 | exports.polygonLength = length$1;
|
15665 | exports.path = path;
|
15666 | exports.quadtree = quadtree;
|
15667 | exports.queue = queue;
|
15668 | exports.arc = arc;
|
15669 | exports.area = area$1;
|
15670 | exports.line = line;
|
15671 | exports.pie = pie;
|
15672 | exports.radialArea = radialArea;
|
15673 | exports.radialLine = radialLine$1;
|
15674 | exports.symbol = symbol;
|
15675 | exports.symbols = symbols;
|
15676 | exports.symbolCircle = circle;
|
15677 | exports.symbolCross = cross$1;
|
15678 | exports.symbolDiamond = diamond;
|
15679 | exports.symbolSquare = square;
|
15680 | exports.symbolStar = star;
|
15681 | exports.symbolTriangle = triangle;
|
15682 | exports.symbolWye = wye;
|
15683 | exports.curveBasisClosed = basisClosed;
|
15684 | exports.curveBasisOpen = basisOpen;
|
15685 | exports.curveBasis = basis;
|
15686 | exports.curveBundle = bundle;
|
15687 | exports.curveCardinalClosed = cardinalClosed;
|
15688 | exports.curveCardinalOpen = cardinalOpen;
|
15689 | exports.curveCardinal = cardinal;
|
15690 | exports.curveCatmullRomClosed = catmullRomClosed;
|
15691 | exports.curveCatmullRomOpen = catmullRomOpen;
|
15692 | exports.curveCatmullRom = catmullRom;
|
15693 | exports.curveLinearClosed = linearClosed;
|
15694 | exports.curveLinear = curveLinear;
|
15695 | exports.curveMonotoneX = monotoneX;
|
15696 | exports.curveMonotoneY = monotoneY;
|
15697 | exports.curveNatural = natural;
|
15698 | exports.curveStep = step;
|
15699 | exports.curveStepAfter = stepAfter;
|
15700 | exports.curveStepBefore = stepBefore;
|
15701 | exports.stack = stack;
|
15702 | exports.stackOffsetExpand = expand;
|
15703 | exports.stackOffsetNone = none;
|
15704 | exports.stackOffsetSilhouette = silhouette;
|
15705 | exports.stackOffsetWiggle = wiggle;
|
15706 | exports.stackOrderAscending = ascending$1;
|
15707 | exports.stackOrderDescending = descending$2;
|
15708 | exports.stackOrderInsideOut = insideOut;
|
15709 | exports.stackOrderNone = none$1;
|
15710 | exports.stackOrderReverse = reverse;
|
15711 | exports.color = color;
|
15712 | exports.rgb = colorRgb;
|
15713 | exports.hsl = colorHsl;
|
15714 | exports.lab = lab;
|
15715 | exports.hcl = colorHcl;
|
15716 | exports.cubehelix = cubehelix;
|
15717 | exports.interpolate = interpolate;
|
15718 | exports.interpolateArray = array$1;
|
15719 | exports.interpolateNumber = interpolateNumber;
|
15720 | exports.interpolateObject = object;
|
15721 | exports.interpolateRound = interpolateRound;
|
15722 | exports.interpolateString = interpolateString;
|
15723 | exports.interpolateTransformCss = interpolateTransform$1;
|
15724 | exports.interpolateTransformSvg = interpolateTransform$2;
|
15725 | exports.interpolateZoom = interpolateZoom;
|
15726 | exports.interpolateRgb = interpolateRgb;
|
15727 | exports.interpolateRgbBasis = rgbBasis;
|
15728 | exports.interpolateRgbBasisClosed = rgbBasisClosed;
|
15729 | exports.interpolateHsl = hsl$1;
|
15730 | exports.interpolateHslLong = hslLong;
|
15731 | exports.interpolateLab = lab$1;
|
15732 | exports.interpolateHcl = hcl$1;
|
15733 | exports.interpolateHclLong = hclLong;
|
15734 | exports.interpolateCubehelix = cubehelix$2;
|
15735 | exports.interpolateCubehelixLong = interpolateCubehelixLong;
|
15736 | exports.interpolateBasis = basis$2;
|
15737 | exports.interpolateBasisClosed = basisClosed$1;
|
15738 | exports.quantize = quantize;
|
15739 | exports.dispatch = dispatch;
|
15740 | exports.dsvFormat = dsv;
|
15741 | exports.csvParse = csvParse;
|
15742 | exports.csvParseRows = csvParseRows;
|
15743 | exports.csvFormat = csvFormat;
|
15744 | exports.csvFormatRows = csvFormatRows;
|
15745 | exports.tsvParse = tsvParse;
|
15746 | exports.tsvParseRows = tsvParseRows;
|
15747 | exports.tsvFormat = tsvFormat;
|
15748 | exports.tsvFormatRows = tsvFormatRows;
|
15749 | exports.request = request;
|
15750 | exports.html = html;
|
15751 | exports.json = json;
|
15752 | exports.text = text;
|
15753 | exports.xml = xml;
|
15754 | exports.csv = csv$1;
|
15755 | exports.tsv = tsv$1;
|
15756 | exports.now = now;
|
15757 | exports.timer = timer;
|
15758 | exports.timerFlush = timerFlush;
|
15759 | exports.timeout = timeout$1;
|
15760 | exports.interval = interval$1;
|
15761 | exports.timeInterval = newInterval;
|
15762 | exports.timeMillisecond = millisecond;
|
15763 | exports.timeMilliseconds = milliseconds;
|
15764 | exports.timeSecond = second;
|
15765 | exports.timeSeconds = seconds;
|
15766 | exports.timeMinute = minute;
|
15767 | exports.timeMinutes = minutes;
|
15768 | exports.timeHour = hour;
|
15769 | exports.timeHours = hours;
|
15770 | exports.timeDay = day;
|
15771 | exports.timeDays = days;
|
15772 | exports.timeWeek = timeWeek;
|
15773 | exports.timeWeeks = sundays;
|
15774 | exports.timeSunday = timeWeek;
|
15775 | exports.timeSundays = sundays;
|
15776 | exports.timeMonday = timeMonday;
|
15777 | exports.timeMondays = mondays;
|
15778 | exports.timeTuesday = tuesday;
|
15779 | exports.timeTuesdays = tuesdays;
|
15780 | exports.timeWednesday = wednesday;
|
15781 | exports.timeWednesdays = wednesdays;
|
15782 | exports.timeThursday = thursday;
|
15783 | exports.timeThursdays = thursdays;
|
15784 | exports.timeFriday = friday;
|
15785 | exports.timeFridays = fridays;
|
15786 | exports.timeSaturday = saturday;
|
15787 | exports.timeSaturdays = saturdays;
|
15788 | exports.timeMonth = month;
|
15789 | exports.timeMonths = months;
|
15790 | exports.timeYear = year;
|
15791 | exports.timeYears = years;
|
15792 | exports.utcMillisecond = millisecond;
|
15793 | exports.utcMilliseconds = milliseconds;
|
15794 | exports.utcSecond = second;
|
15795 | exports.utcSeconds = seconds;
|
15796 | exports.utcMinute = utcMinute;
|
15797 | exports.utcMinutes = utcMinutes;
|
15798 | exports.utcHour = utcHour;
|
15799 | exports.utcHours = utcHours;
|
15800 | exports.utcDay = utcDay;
|
15801 | exports.utcDays = utcDays;
|
15802 | exports.utcWeek = utcWeek;
|
15803 | exports.utcWeeks = utcSundays;
|
15804 | exports.utcSunday = utcWeek;
|
15805 | exports.utcSundays = utcSundays;
|
15806 | exports.utcMonday = utcMonday;
|
15807 | exports.utcMondays = utcMondays;
|
15808 | exports.utcTuesday = utcTuesday;
|
15809 | exports.utcTuesdays = utcTuesdays;
|
15810 | exports.utcWednesday = utcWednesday;
|
15811 | exports.utcWednesdays = utcWednesdays;
|
15812 | exports.utcThursday = utcThursday;
|
15813 | exports.utcThursdays = utcThursdays;
|
15814 | exports.utcFriday = utcFriday;
|
15815 | exports.utcFridays = utcFridays;
|
15816 | exports.utcSaturday = utcSaturday;
|
15817 | exports.utcSaturdays = utcSaturdays;
|
15818 | exports.utcMonth = utcMonth;
|
15819 | exports.utcMonths = utcMonths;
|
15820 | exports.utcYear = utcYear;
|
15821 | exports.utcYears = utcYears;
|
15822 | exports.formatLocale = formatLocale;
|
15823 | exports.formatDefaultLocale = defaultLocale;
|
15824 | exports.formatSpecifier = formatSpecifier;
|
15825 | exports.precisionFixed = precisionFixed;
|
15826 | exports.precisionPrefix = precisionPrefix;
|
15827 | exports.precisionRound = precisionRound;
|
15828 | exports.isoFormat = formatIso;
|
15829 | exports.isoParse = parseIso;
|
15830 | exports.timeFormatLocale = formatLocale$1;
|
15831 | exports.timeFormatDefaultLocale = defaultLocale$1;
|
15832 | exports.scaleBand = band;
|
15833 | exports.scalePoint = point$4;
|
15834 | exports.scaleIdentity = identity$4;
|
15835 | exports.scaleLinear = linear$2;
|
15836 | exports.scaleLog = log;
|
15837 | exports.scaleOrdinal = ordinal;
|
15838 | exports.scaleImplicit = implicit;
|
15839 | exports.scalePow = pow;
|
15840 | exports.scaleSqrt = sqrt;
|
15841 | exports.scaleQuantile = quantile;
|
15842 | exports.scaleQuantize = quantize$1;
|
15843 | exports.scaleThreshold = threshold$1;
|
15844 | exports.scaleTime = time;
|
15845 | exports.scaleUtc = utcTime;
|
15846 | exports.schemeCategory10 = category10;
|
15847 | exports.schemeCategory20b = category20b;
|
15848 | exports.schemeCategory20c = category20c;
|
15849 | exports.schemeCategory20 = category20;
|
15850 | exports.scaleSequential = sequential;
|
15851 | exports.interpolateCubehelixDefault = cubehelix$3;
|
15852 | exports.interpolateRainbow = rainbow$1;
|
15853 | exports.interpolateWarm = warm;
|
15854 | exports.interpolateCool = cool;
|
15855 | exports.interpolateViridis = viridis;
|
15856 | exports.interpolateMagma = magma;
|
15857 | exports.interpolateInferno = inferno;
|
15858 | exports.interpolatePlasma = plasma;
|
15859 | exports.creator = creator;
|
15860 | exports.customEvent = customEvent;
|
15861 | exports.local = local;
|
15862 | exports.matcher = matcher$1;
|
15863 | exports.mouse = mouse;
|
15864 | exports.namespace = namespace;
|
15865 | exports.namespaces = namespaces;
|
15866 | exports.select = select;
|
15867 | exports.selectAll = selectAll;
|
15868 | exports.selection = selection;
|
15869 | exports.selector = selector;
|
15870 | exports.selectorAll = selectorAll;
|
15871 | exports.touch = touch;
|
15872 | exports.touches = touches;
|
15873 | exports.window = window;
|
15874 | exports.active = active;
|
15875 | exports.interrupt = interrupt;
|
15876 | exports.transition = transition;
|
15877 | exports.axisTop = axisTop;
|
15878 | exports.axisRight = axisRight;
|
15879 | exports.axisBottom = axisBottom;
|
15880 | exports.axisLeft = axisLeft;
|
15881 | exports.cluster = cluster;
|
15882 | exports.hierarchy = hierarchy;
|
15883 | exports.pack = index;
|
15884 | exports.packSiblings = siblings;
|
15885 | exports.packEnclose = enclose;
|
15886 | exports.partition = partition;
|
15887 | exports.stratify = stratify;
|
15888 | exports.tree = tree;
|
15889 | exports.treemap = index$1;
|
15890 | exports.treemapBinary = binary;
|
15891 | exports.treemapDice = treemapDice;
|
15892 | exports.treemapSlice = treemapSlice;
|
15893 | exports.treemapSliceDice = sliceDice;
|
15894 | exports.treemapSquarify = squarify;
|
15895 | exports.treemapResquarify = resquarify;
|
15896 | exports.forceCenter = center$1;
|
15897 | exports.forceCollide = collide;
|
15898 | exports.forceLink = link;
|
15899 | exports.forceManyBody = manyBody;
|
15900 | exports.forceSimulation = simulation;
|
15901 | exports.forceX = x$3;
|
15902 | exports.forceY = y$3;
|
15903 | exports.drag = drag;
|
15904 | exports.dragDisable = dragDisable;
|
15905 | exports.dragEnable = dragEnable;
|
15906 | exports.voronoi = voronoi;
|
15907 | exports.zoom = zoom;
|
15908 | exports.zoomIdentity = identity$6;
|
15909 | exports.zoomTransform = transform;
|
15910 | exports.brush = brush;
|
15911 | exports.brushX = brushX;
|
15912 | exports.brushY = brushY;
|
15913 | exports.brushSelection = brushSelection;
|
15914 | exports.geoArea = area$2;
|
15915 | exports.geoBounds = bounds;
|
15916 | exports.geoCentroid = centroid$1;
|
15917 | exports.geoCircle = circle$1;
|
15918 | exports.geoClipExtent = extent$1;
|
15919 | exports.geoDistance = distance;
|
15920 | exports.geoGraticule = graticule;
|
15921 | exports.geoInterpolate = interpolate$2;
|
15922 | exports.geoLength = length$2;
|
15923 | exports.geoPath = index$3;
|
15924 | exports.geoAlbers = albers;
|
15925 | exports.geoAlbersUsa = albersUsa;
|
15926 | exports.geoAzimuthalEqualArea = azimuthalEqualArea$1;
|
15927 | exports.geoAzimuthalEquidistant = azimuthalEquidistant$1;
|
15928 | exports.geoConicConformal = conicConformal$1;
|
15929 | exports.geoConicEqualArea = conicEqualArea$1;
|
15930 | exports.geoConicEquidistant = conicEquidistant$1;
|
15931 | exports.geoEquirectangular = equirectangular$1;
|
15932 | exports.geoGnomonic = gnomonic$1;
|
15933 | exports.geoProjection = projection;
|
15934 | exports.geoProjectionMutator = projectionMutator;
|
15935 | exports.geoMercator = mercator$1;
|
15936 | exports.geoOrthographic = orthographic$1;
|
15937 | exports.geoStereographic = stereographic$1;
|
15938 | exports.geoTransverseMercator = transverseMercator$1;
|
15939 | exports.geoRotation = rotation;
|
15940 | exports.geoStream = stream;
|
15941 | exports.geoTransform = transform$1;
|
15942 |
|
15943 | Object.defineProperty(exports, '__esModule', { value: true });
|
15944 |
|
15945 | })); |
\ | No newline at end of file |