1 |
|
2 | (function (global, factory) {
|
3 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
4 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
5 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
|
6 | })(this, (function (exports) { 'use strict';
|
7 |
|
8 | var version = "7.6.1";
|
9 |
|
10 | function ascending$3(a, b) {
|
11 | return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
12 | }
|
13 |
|
14 | function descending$2(a, b) {
|
15 | return a == null || b == null ? NaN
|
16 | : b < a ? -1
|
17 | : b > a ? 1
|
18 | : b >= a ? 0
|
19 | : NaN;
|
20 | }
|
21 |
|
22 | function bisector(f) {
|
23 | let compare1, compare2, delta;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | if (f.length !== 2) {
|
31 | compare1 = ascending$3;
|
32 | compare2 = (d, x) => ascending$3(f(d), x);
|
33 | delta = (d, x) => f(d) - x;
|
34 | } else {
|
35 | compare1 = f === ascending$3 || f === descending$2 ? f : zero$1;
|
36 | compare2 = f;
|
37 | delta = f;
|
38 | }
|
39 |
|
40 | function left(a, x, lo = 0, hi = a.length) {
|
41 | if (lo < hi) {
|
42 | if (compare1(x, x) !== 0) return hi;
|
43 | do {
|
44 | const mid = (lo + hi) >>> 1;
|
45 | if (compare2(a[mid], x) < 0) lo = mid + 1;
|
46 | else hi = mid;
|
47 | } while (lo < hi);
|
48 | }
|
49 | return lo;
|
50 | }
|
51 |
|
52 | function right(a, x, lo = 0, hi = a.length) {
|
53 | if (lo < hi) {
|
54 | if (compare1(x, x) !== 0) return hi;
|
55 | do {
|
56 | const mid = (lo + hi) >>> 1;
|
57 | if (compare2(a[mid], x) <= 0) lo = mid + 1;
|
58 | else hi = mid;
|
59 | } while (lo < hi);
|
60 | }
|
61 | return lo;
|
62 | }
|
63 |
|
64 | function center(a, x, lo = 0, hi = a.length) {
|
65 | const i = left(a, x, lo, hi - 1);
|
66 | return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
|
67 | }
|
68 |
|
69 | return {left, center, right};
|
70 | }
|
71 |
|
72 | function zero$1() {
|
73 | return 0;
|
74 | }
|
75 |
|
76 | function number$3(x) {
|
77 | return x === null ? NaN : +x;
|
78 | }
|
79 |
|
80 | function* numbers(values, valueof) {
|
81 | if (valueof === undefined) {
|
82 | for (let value of values) {
|
83 | if (value != null && (value = +value) >= value) {
|
84 | yield value;
|
85 | }
|
86 | }
|
87 | } else {
|
88 | let index = -1;
|
89 | for (let value of values) {
|
90 | if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
|
91 | yield value;
|
92 | }
|
93 | }
|
94 | }
|
95 | }
|
96 |
|
97 | const ascendingBisect = bisector(ascending$3);
|
98 | const bisectRight = ascendingBisect.right;
|
99 | const bisectLeft = ascendingBisect.left;
|
100 | const bisectCenter = bisector(number$3).center;
|
101 | var bisect = bisectRight;
|
102 |
|
103 | function blur(values, r) {
|
104 | if (!((r = +r) >= 0)) throw new RangeError("invalid r");
|
105 | let length = values.length;
|
106 | if (!((length = Math.floor(length)) >= 0)) throw new RangeError("invalid length");
|
107 | if (!length || !r) return values;
|
108 | const blur = blurf(r);
|
109 | const temp = values.slice();
|
110 | blur(values, temp, 0, length, 1);
|
111 | blur(temp, values, 0, length, 1);
|
112 | blur(values, temp, 0, length, 1);
|
113 | return values;
|
114 | }
|
115 |
|
116 | const blur2 = Blur2(blurf);
|
117 |
|
118 | const blurImage = Blur2(blurfImage);
|
119 |
|
120 | function Blur2(blur) {
|
121 | return function(data, rx, ry = rx) {
|
122 | if (!((rx = +rx) >= 0)) throw new RangeError("invalid rx");
|
123 | if (!((ry = +ry) >= 0)) throw new RangeError("invalid ry");
|
124 | let {data: values, width, height} = data;
|
125 | if (!((width = Math.floor(width)) >= 0)) throw new RangeError("invalid width");
|
126 | if (!((height = Math.floor(height !== undefined ? height : values.length / width)) >= 0)) throw new RangeError("invalid height");
|
127 | if (!width || !height || (!rx && !ry)) return data;
|
128 | const blurx = rx && blur(rx);
|
129 | const blury = ry && blur(ry);
|
130 | const temp = values.slice();
|
131 | if (blurx && blury) {
|
132 | blurh(blurx, temp, values, width, height);
|
133 | blurh(blurx, values, temp, width, height);
|
134 | blurh(blurx, temp, values, width, height);
|
135 | blurv(blury, values, temp, width, height);
|
136 | blurv(blury, temp, values, width, height);
|
137 | blurv(blury, values, temp, width, height);
|
138 | } else if (blurx) {
|
139 | blurh(blurx, values, temp, width, height);
|
140 | blurh(blurx, temp, values, width, height);
|
141 | blurh(blurx, values, temp, width, height);
|
142 | } else if (blury) {
|
143 | blurv(blury, values, temp, width, height);
|
144 | blurv(blury, temp, values, width, height);
|
145 | blurv(blury, values, temp, width, height);
|
146 | }
|
147 | return data;
|
148 | };
|
149 | }
|
150 |
|
151 | function blurh(blur, T, S, w, h) {
|
152 | for (let y = 0, n = w * h; y < n;) {
|
153 | blur(T, S, y, y += w, 1);
|
154 | }
|
155 | }
|
156 |
|
157 | function blurv(blur, T, S, w, h) {
|
158 | for (let x = 0, n = w * h; x < w; ++x) {
|
159 | blur(T, S, x, x + n, w);
|
160 | }
|
161 | }
|
162 |
|
163 | function blurfImage(radius) {
|
164 | const blur = blurf(radius);
|
165 | return (T, S, start, stop, step) => {
|
166 | start <<= 2, stop <<= 2, step <<= 2;
|
167 | blur(T, S, start + 0, stop + 0, step);
|
168 | blur(T, S, start + 1, stop + 1, step);
|
169 | blur(T, S, start + 2, stop + 2, step);
|
170 | blur(T, S, start + 3, stop + 3, step);
|
171 | };
|
172 | }
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | function blurf(radius) {
|
181 | const radius0 = Math.floor(radius);
|
182 | if (radius0 === radius) return bluri(radius);
|
183 | const t = radius - radius0;
|
184 | const w = 2 * radius + 1;
|
185 | return (T, S, start, stop, step) => {
|
186 | if (!((stop -= step) >= start)) return;
|
187 | let sum = radius0 * S[start];
|
188 | const s0 = step * radius0;
|
189 | const s1 = s0 + step;
|
190 | for (let i = start, j = start + s0; i < j; i += step) {
|
191 | sum += S[Math.min(stop, i)];
|
192 | }
|
193 | for (let i = start, j = stop; i <= j; i += step) {
|
194 | sum += S[Math.min(stop, i + s0)];
|
195 | T[i] = (sum + t * (S[Math.max(start, i - s1)] + S[Math.min(stop, i + s1)])) / w;
|
196 | sum -= S[Math.max(start, i - s0)];
|
197 | }
|
198 | };
|
199 | }
|
200 |
|
201 |
|
202 | function bluri(radius) {
|
203 | const w = 2 * radius + 1;
|
204 | return (T, S, start, stop, step) => {
|
205 | if (!((stop -= step) >= start)) return;
|
206 | let sum = radius * S[start];
|
207 | const s = step * radius;
|
208 | for (let i = start, j = start + s; i < j; i += step) {
|
209 | sum += S[Math.min(stop, i)];
|
210 | }
|
211 | for (let i = start, j = stop; i <= j; i += step) {
|
212 | sum += S[Math.min(stop, i + s)];
|
213 | T[i] = sum / w;
|
214 | sum -= S[Math.max(start, i - s)];
|
215 | }
|
216 | };
|
217 | }
|
218 |
|
219 | function count$1(values, valueof) {
|
220 | let count = 0;
|
221 | if (valueof === undefined) {
|
222 | for (let value of values) {
|
223 | if (value != null && (value = +value) >= value) {
|
224 | ++count;
|
225 | }
|
226 | }
|
227 | } else {
|
228 | let index = -1;
|
229 | for (let value of values) {
|
230 | if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
|
231 | ++count;
|
232 | }
|
233 | }
|
234 | }
|
235 | return count;
|
236 | }
|
237 |
|
238 | function length$3(array) {
|
239 | return array.length | 0;
|
240 | }
|
241 |
|
242 | function empty$2(length) {
|
243 | return !(length > 0);
|
244 | }
|
245 |
|
246 | function arrayify(values) {
|
247 | return typeof values !== "object" || "length" in values ? values : Array.from(values);
|
248 | }
|
249 |
|
250 | function reducer(reduce) {
|
251 | return values => reduce(...values);
|
252 | }
|
253 |
|
254 | function cross$2(...values) {
|
255 | const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
|
256 | values = values.map(arrayify);
|
257 | const lengths = values.map(length$3);
|
258 | const j = values.length - 1;
|
259 | const index = new Array(j + 1).fill(0);
|
260 | const product = [];
|
261 | if (j < 0 || lengths.some(empty$2)) return product;
|
262 | while (true) {
|
263 | product.push(index.map((j, i) => values[i][j]));
|
264 | let i = j;
|
265 | while (++index[i] === lengths[i]) {
|
266 | if (i === 0) return reduce ? product.map(reduce) : product;
|
267 | index[i--] = 0;
|
268 | }
|
269 | }
|
270 | }
|
271 |
|
272 | function cumsum(values, valueof) {
|
273 | var sum = 0, index = 0;
|
274 | return Float64Array.from(values, valueof === undefined
|
275 | ? v => (sum += +v || 0)
|
276 | : v => (sum += +valueof(v, index++, values) || 0));
|
277 | }
|
278 |
|
279 | function variance(values, valueof) {
|
280 | let count = 0;
|
281 | let delta;
|
282 | let mean = 0;
|
283 | let sum = 0;
|
284 | if (valueof === undefined) {
|
285 | for (let value of values) {
|
286 | if (value != null && (value = +value) >= value) {
|
287 | delta = value - mean;
|
288 | mean += delta / ++count;
|
289 | sum += delta * (value - mean);
|
290 | }
|
291 | }
|
292 | } else {
|
293 | let index = -1;
|
294 | for (let value of values) {
|
295 | if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
|
296 | delta = value - mean;
|
297 | mean += delta / ++count;
|
298 | sum += delta * (value - mean);
|
299 | }
|
300 | }
|
301 | }
|
302 | if (count > 1) return sum / (count - 1);
|
303 | }
|
304 |
|
305 | function deviation(values, valueof) {
|
306 | const v = variance(values, valueof);
|
307 | return v ? Math.sqrt(v) : v;
|
308 | }
|
309 |
|
310 | function extent$1(values, valueof) {
|
311 | let min;
|
312 | let max;
|
313 | if (valueof === undefined) {
|
314 | for (const value of values) {
|
315 | if (value != null) {
|
316 | if (min === undefined) {
|
317 | if (value >= value) min = max = value;
|
318 | } else {
|
319 | if (min > value) min = value;
|
320 | if (max < value) max = value;
|
321 | }
|
322 | }
|
323 | }
|
324 | } else {
|
325 | let index = -1;
|
326 | for (let value of values) {
|
327 | if ((value = valueof(value, ++index, values)) != null) {
|
328 | if (min === undefined) {
|
329 | if (value >= value) min = max = value;
|
330 | } else {
|
331 | if (min > value) min = value;
|
332 | if (max < value) max = value;
|
333 | }
|
334 | }
|
335 | }
|
336 | }
|
337 | return [min, max];
|
338 | }
|
339 |
|
340 |
|
341 | class Adder {
|
342 | constructor() {
|
343 | this._partials = new Float64Array(32);
|
344 | this._n = 0;
|
345 | }
|
346 | add(x) {
|
347 | const p = this._partials;
|
348 | let i = 0;
|
349 | for (let j = 0; j < this._n && j < 32; j++) {
|
350 | const y = p[j],
|
351 | hi = x + y,
|
352 | lo = Math.abs(x) < Math.abs(y) ? x - (hi - y) : y - (hi - x);
|
353 | if (lo) p[i++] = lo;
|
354 | x = hi;
|
355 | }
|
356 | p[i] = x;
|
357 | this._n = i + 1;
|
358 | return this;
|
359 | }
|
360 | valueOf() {
|
361 | const p = this._partials;
|
362 | let n = this._n, x, y, lo, hi = 0;
|
363 | if (n > 0) {
|
364 | hi = p[--n];
|
365 | while (n > 0) {
|
366 | x = hi;
|
367 | y = p[--n];
|
368 | hi = x + y;
|
369 | lo = y - (hi - x);
|
370 | if (lo) break;
|
371 | }
|
372 | if (n > 0 && ((lo < 0 && p[n - 1] < 0) || (lo > 0 && p[n - 1] > 0))) {
|
373 | y = lo * 2;
|
374 | x = hi + y;
|
375 | if (y == x - hi) hi = x;
|
376 | }
|
377 | }
|
378 | return hi;
|
379 | }
|
380 | }
|
381 |
|
382 | function fsum(values, valueof) {
|
383 | const adder = new Adder();
|
384 | if (valueof === undefined) {
|
385 | for (let value of values) {
|
386 | if (value = +value) {
|
387 | adder.add(value);
|
388 | }
|
389 | }
|
390 | } else {
|
391 | let index = -1;
|
392 | for (let value of values) {
|
393 | if (value = +valueof(value, ++index, values)) {
|
394 | adder.add(value);
|
395 | }
|
396 | }
|
397 | }
|
398 | return +adder;
|
399 | }
|
400 |
|
401 | function fcumsum(values, valueof) {
|
402 | const adder = new Adder();
|
403 | let index = -1;
|
404 | return Float64Array.from(values, valueof === undefined
|
405 | ? v => adder.add(+v || 0)
|
406 | : v => adder.add(+valueof(v, ++index, values) || 0)
|
407 | );
|
408 | }
|
409 |
|
410 | class InternMap extends Map {
|
411 | constructor(entries, key = keyof) {
|
412 | super();
|
413 | Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
|
414 | if (entries != null) for (const [key, value] of entries) this.set(key, value);
|
415 | }
|
416 | get(key) {
|
417 | return super.get(intern_get(this, key));
|
418 | }
|
419 | has(key) {
|
420 | return super.has(intern_get(this, key));
|
421 | }
|
422 | set(key, value) {
|
423 | return super.set(intern_set(this, key), value);
|
424 | }
|
425 | delete(key) {
|
426 | return super.delete(intern_delete(this, key));
|
427 | }
|
428 | }
|
429 |
|
430 | class InternSet extends Set {
|
431 | constructor(values, key = keyof) {
|
432 | super();
|
433 | Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
|
434 | if (values != null) for (const value of values) this.add(value);
|
435 | }
|
436 | has(value) {
|
437 | return super.has(intern_get(this, value));
|
438 | }
|
439 | add(value) {
|
440 | return super.add(intern_set(this, value));
|
441 | }
|
442 | delete(value) {
|
443 | return super.delete(intern_delete(this, value));
|
444 | }
|
445 | }
|
446 |
|
447 | function intern_get({_intern, _key}, value) {
|
448 | const key = _key(value);
|
449 | return _intern.has(key) ? _intern.get(key) : value;
|
450 | }
|
451 |
|
452 | function intern_set({_intern, _key}, value) {
|
453 | const key = _key(value);
|
454 | if (_intern.has(key)) return _intern.get(key);
|
455 | _intern.set(key, value);
|
456 | return value;
|
457 | }
|
458 |
|
459 | function intern_delete({_intern, _key}, value) {
|
460 | const key = _key(value);
|
461 | if (_intern.has(key)) {
|
462 | value = _intern.get(key);
|
463 | _intern.delete(key);
|
464 | }
|
465 | return value;
|
466 | }
|
467 |
|
468 | function keyof(value) {
|
469 | return value !== null && typeof value === "object" ? value.valueOf() : value;
|
470 | }
|
471 |
|
472 | function identity$9(x) {
|
473 | return x;
|
474 | }
|
475 |
|
476 | function group(values, ...keys) {
|
477 | return nest(values, identity$9, identity$9, keys);
|
478 | }
|
479 |
|
480 | function groups(values, ...keys) {
|
481 | return nest(values, Array.from, identity$9, keys);
|
482 | }
|
483 |
|
484 | function flatten$1(groups, keys) {
|
485 | for (let i = 1, n = keys.length; i < n; ++i) {
|
486 | groups = groups.flatMap(g => g.pop().map(([key, value]) => [...g, key, value]));
|
487 | }
|
488 | return groups;
|
489 | }
|
490 |
|
491 | function flatGroup(values, ...keys) {
|
492 | return flatten$1(groups(values, ...keys), keys);
|
493 | }
|
494 |
|
495 | function flatRollup(values, reduce, ...keys) {
|
496 | return flatten$1(rollups(values, reduce, ...keys), keys);
|
497 | }
|
498 |
|
499 | function rollup(values, reduce, ...keys) {
|
500 | return nest(values, identity$9, reduce, keys);
|
501 | }
|
502 |
|
503 | function rollups(values, reduce, ...keys) {
|
504 | return nest(values, Array.from, reduce, keys);
|
505 | }
|
506 |
|
507 | function index$4(values, ...keys) {
|
508 | return nest(values, identity$9, unique, keys);
|
509 | }
|
510 |
|
511 | function indexes(values, ...keys) {
|
512 | return nest(values, Array.from, unique, keys);
|
513 | }
|
514 |
|
515 | function unique(values) {
|
516 | if (values.length !== 1) throw new Error("duplicate key");
|
517 | return values[0];
|
518 | }
|
519 |
|
520 | function nest(values, map, reduce, keys) {
|
521 | return (function regroup(values, i) {
|
522 | if (i >= keys.length) return reduce(values);
|
523 | const groups = new InternMap();
|
524 | const keyof = keys[i++];
|
525 | let index = -1;
|
526 | for (const value of values) {
|
527 | const key = keyof(value, ++index, values);
|
528 | const group = groups.get(key);
|
529 | if (group) group.push(value);
|
530 | else groups.set(key, [value]);
|
531 | }
|
532 | for (const [key, values] of groups) {
|
533 | groups.set(key, regroup(values, i));
|
534 | }
|
535 | return map(groups);
|
536 | })(values, 0);
|
537 | }
|
538 |
|
539 | function permute(source, keys) {
|
540 | return Array.from(keys, key => source[key]);
|
541 | }
|
542 |
|
543 | function sort(values, ...F) {
|
544 | if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
|
545 | values = Array.from(values);
|
546 | let [f] = F;
|
547 | if ((f && f.length !== 2) || F.length > 1) {
|
548 | const index = Uint32Array.from(values, (d, i) => i);
|
549 | if (F.length > 1) {
|
550 | F = F.map(f => values.map(f));
|
551 | index.sort((i, j) => {
|
552 | for (const f of F) {
|
553 | const c = ascendingDefined(f[i], f[j]);
|
554 | if (c) return c;
|
555 | }
|
556 | });
|
557 | } else {
|
558 | f = values.map(f);
|
559 | index.sort((i, j) => ascendingDefined(f[i], f[j]));
|
560 | }
|
561 | return permute(values, index);
|
562 | }
|
563 | return values.sort(compareDefined(f));
|
564 | }
|
565 |
|
566 | function compareDefined(compare = ascending$3) {
|
567 | if (compare === ascending$3) return ascendingDefined;
|
568 | if (typeof compare !== "function") throw new TypeError("compare is not a function");
|
569 | return (a, b) => {
|
570 | const x = compare(a, b);
|
571 | if (x || x === 0) return x;
|
572 | return (compare(b, b) === 0) - (compare(a, a) === 0);
|
573 | };
|
574 | }
|
575 |
|
576 | function ascendingDefined(a, b) {
|
577 | return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0);
|
578 | }
|
579 |
|
580 | function groupSort(values, reduce, key) {
|
581 | return (reduce.length !== 2
|
582 | ? sort(rollup(values, reduce, key), (([ak, av], [bk, bv]) => ascending$3(av, bv) || ascending$3(ak, bk)))
|
583 | : sort(group(values, key), (([ak, av], [bk, bv]) => reduce(av, bv) || ascending$3(ak, bk))))
|
584 | .map(([key]) => key);
|
585 | }
|
586 |
|
587 | var array$5 = Array.prototype;
|
588 |
|
589 | var slice$3 = array$5.slice;
|
590 |
|
591 | function constant$b(x) {
|
592 | return () => x;
|
593 | }
|
594 |
|
595 | var e10 = Math.sqrt(50),
|
596 | e5 = Math.sqrt(10),
|
597 | e2 = Math.sqrt(2);
|
598 |
|
599 | function ticks(start, stop, count) {
|
600 | var reverse,
|
601 | i = -1,
|
602 | n,
|
603 | ticks,
|
604 | step;
|
605 |
|
606 | stop = +stop, start = +start, count = +count;
|
607 | if (start === stop && count > 0) return [start];
|
608 | if (reverse = stop < start) n = start, start = stop, stop = n;
|
609 | if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
|
610 |
|
611 | if (step > 0) {
|
612 | let r0 = Math.round(start / step), r1 = Math.round(stop / step);
|
613 | if (r0 * step < start) ++r0;
|
614 | if (r1 * step > stop) --r1;
|
615 | ticks = new Array(n = r1 - r0 + 1);
|
616 | while (++i < n) ticks[i] = (r0 + i) * step;
|
617 | } else {
|
618 | step = -step;
|
619 | let r0 = Math.round(start * step), r1 = Math.round(stop * step);
|
620 | if (r0 / step < start) ++r0;
|
621 | if (r1 / step > stop) --r1;
|
622 | ticks = new Array(n = r1 - r0 + 1);
|
623 | while (++i < n) ticks[i] = (r0 + i) / step;
|
624 | }
|
625 |
|
626 | if (reverse) ticks.reverse();
|
627 |
|
628 | return ticks;
|
629 | }
|
630 |
|
631 | function tickIncrement(start, stop, count) {
|
632 | var step = (stop - start) / Math.max(0, count),
|
633 | power = Math.floor(Math.log(step) / Math.LN10),
|
634 | error = step / Math.pow(10, power);
|
635 | return power >= 0
|
636 | ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
|
637 | : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
|
638 | }
|
639 |
|
640 | function tickStep(start, stop, count) {
|
641 | var step0 = Math.abs(stop - start) / Math.max(0, count),
|
642 | step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
|
643 | error = step0 / step1;
|
644 | if (error >= e10) step1 *= 10;
|
645 | else if (error >= e5) step1 *= 5;
|
646 | else if (error >= e2) step1 *= 2;
|
647 | return stop < start ? -step1 : step1;
|
648 | }
|
649 |
|
650 | function nice$1(start, stop, count) {
|
651 | let prestep;
|
652 | while (true) {
|
653 | const step = tickIncrement(start, stop, count);
|
654 | if (step === prestep || step === 0 || !isFinite(step)) {
|
655 | return [start, stop];
|
656 | } else if (step > 0) {
|
657 | start = Math.floor(start / step) * step;
|
658 | stop = Math.ceil(stop / step) * step;
|
659 | } else if (step < 0) {
|
660 | start = Math.ceil(start * step) / step;
|
661 | stop = Math.floor(stop * step) / step;
|
662 | }
|
663 | prestep = step;
|
664 | }
|
665 | }
|
666 |
|
667 | function thresholdSturges(values) {
|
668 | return Math.ceil(Math.log(count$1(values)) / Math.LN2) + 1;
|
669 | }
|
670 |
|
671 | function bin() {
|
672 | var value = identity$9,
|
673 | domain = extent$1,
|
674 | threshold = thresholdSturges;
|
675 |
|
676 | function histogram(data) {
|
677 | if (!Array.isArray(data)) data = Array.from(data);
|
678 |
|
679 | var i,
|
680 | n = data.length,
|
681 | x,
|
682 | step,
|
683 | values = new Array(n);
|
684 |
|
685 | for (i = 0; i < n; ++i) {
|
686 | values[i] = value(data[i], i, data);
|
687 | }
|
688 |
|
689 | var xz = domain(values),
|
690 | x0 = xz[0],
|
691 | x1 = xz[1],
|
692 | tz = threshold(values, x0, x1);
|
693 |
|
694 |
|
695 |
|
696 | if (!Array.isArray(tz)) {
|
697 | const max = x1, tn = +tz;
|
698 | if (domain === extent$1) [x0, x1] = nice$1(x0, x1, tn);
|
699 | tz = ticks(x0, x1, tn);
|
700 |
|
701 |
|
702 |
|
703 |
|
704 | if (tz[0] <= x0) step = tickIncrement(x0, x1, tn);
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 | if (tz[tz.length - 1] >= x1) {
|
714 | if (max >= x1 && domain === extent$1) {
|
715 | const step = tickIncrement(x0, x1, tn);
|
716 | if (isFinite(step)) {
|
717 | if (step > 0) {
|
718 | x1 = (Math.floor(x1 / step) + 1) * step;
|
719 | } else if (step < 0) {
|
720 | x1 = (Math.ceil(x1 * -step) + 1) / -step;
|
721 | }
|
722 | }
|
723 | } else {
|
724 | tz.pop();
|
725 | }
|
726 | }
|
727 | }
|
728 |
|
729 |
|
730 | var m = tz.length;
|
731 | while (tz[0] <= x0) tz.shift(), --m;
|
732 | while (tz[m - 1] > x1) tz.pop(), --m;
|
733 |
|
734 | var bins = new Array(m + 1),
|
735 | bin;
|
736 |
|
737 |
|
738 | for (i = 0; i <= m; ++i) {
|
739 | bin = bins[i] = [];
|
740 | bin.x0 = i > 0 ? tz[i - 1] : x0;
|
741 | bin.x1 = i < m ? tz[i] : x1;
|
742 | }
|
743 |
|
744 |
|
745 | if (isFinite(step)) {
|
746 | if (step > 0) {
|
747 | for (i = 0; i < n; ++i) {
|
748 | if ((x = values[i]) != null && x0 <= x && x <= x1) {
|
749 | bins[Math.min(m, Math.floor((x - x0) / step))].push(data[i]);
|
750 | }
|
751 | }
|
752 | } else if (step < 0) {
|
753 | for (i = 0; i < n; ++i) {
|
754 | if ((x = values[i]) != null && x0 <= x && x <= x1) {
|
755 | const j = Math.floor((x0 - x) * step);
|
756 | bins[Math.min(m, j + (tz[j] <= x))].push(data[i]);
|
757 | }
|
758 | }
|
759 | }
|
760 | } else {
|
761 | for (i = 0; i < n; ++i) {
|
762 | if ((x = values[i]) != null && x0 <= x && x <= x1) {
|
763 | bins[bisect(tz, x, 0, m)].push(data[i]);
|
764 | }
|
765 | }
|
766 | }
|
767 |
|
768 | return bins;
|
769 | }
|
770 |
|
771 | histogram.value = function(_) {
|
772 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(_), histogram) : value;
|
773 | };
|
774 |
|
775 | histogram.domain = function(_) {
|
776 | return arguments.length ? (domain = typeof _ === "function" ? _ : constant$b([_[0], _[1]]), histogram) : domain;
|
777 | };
|
778 |
|
779 | histogram.thresholds = function(_) {
|
780 | return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$b(slice$3.call(_)) : constant$b(_), histogram) : threshold;
|
781 | };
|
782 |
|
783 | return histogram;
|
784 | }
|
785 |
|
786 | function max$3(values, valueof) {
|
787 | let max;
|
788 | if (valueof === undefined) {
|
789 | for (const value of values) {
|
790 | if (value != null
|
791 | && (max < value || (max === undefined && value >= value))) {
|
792 | max = value;
|
793 | }
|
794 | }
|
795 | } else {
|
796 | let index = -1;
|
797 | for (let value of values) {
|
798 | if ((value = valueof(value, ++index, values)) != null
|
799 | && (max < value || (max === undefined && value >= value))) {
|
800 | max = value;
|
801 | }
|
802 | }
|
803 | }
|
804 | return max;
|
805 | }
|
806 |
|
807 | function maxIndex(values, valueof) {
|
808 | let max;
|
809 | let maxIndex = -1;
|
810 | let index = -1;
|
811 | if (valueof === undefined) {
|
812 | for (const value of values) {
|
813 | ++index;
|
814 | if (value != null
|
815 | && (max < value || (max === undefined && value >= value))) {
|
816 | max = value, maxIndex = index;
|
817 | }
|
818 | }
|
819 | } else {
|
820 | for (let value of values) {
|
821 | if ((value = valueof(value, ++index, values)) != null
|
822 | && (max < value || (max === undefined && value >= value))) {
|
823 | max = value, maxIndex = index;
|
824 | }
|
825 | }
|
826 | }
|
827 | return maxIndex;
|
828 | }
|
829 |
|
830 | function min$2(values, valueof) {
|
831 | let min;
|
832 | if (valueof === undefined) {
|
833 | for (const value of values) {
|
834 | if (value != null
|
835 | && (min > value || (min === undefined && value >= value))) {
|
836 | min = value;
|
837 | }
|
838 | }
|
839 | } else {
|
840 | let index = -1;
|
841 | for (let value of values) {
|
842 | if ((value = valueof(value, ++index, values)) != null
|
843 | && (min > value || (min === undefined && value >= value))) {
|
844 | min = value;
|
845 | }
|
846 | }
|
847 | }
|
848 | return min;
|
849 | }
|
850 |
|
851 | function minIndex(values, valueof) {
|
852 | let min;
|
853 | let minIndex = -1;
|
854 | let index = -1;
|
855 | if (valueof === undefined) {
|
856 | for (const value of values) {
|
857 | ++index;
|
858 | if (value != null
|
859 | && (min > value || (min === undefined && value >= value))) {
|
860 | min = value, minIndex = index;
|
861 | }
|
862 | }
|
863 | } else {
|
864 | for (let value of values) {
|
865 | if ((value = valueof(value, ++index, values)) != null
|
866 | && (min > value || (min === undefined && value >= value))) {
|
867 | min = value, minIndex = index;
|
868 | }
|
869 | }
|
870 | }
|
871 | return minIndex;
|
872 | }
|
873 |
|
874 |
|
875 |
|
876 | function quickselect(array, k, left = 0, right = array.length - 1, compare) {
|
877 | compare = compare === undefined ? ascendingDefined : compareDefined(compare);
|
878 |
|
879 | while (right > left) {
|
880 | if (right - left > 600) {
|
881 | const n = right - left + 1;
|
882 | const m = k - left + 1;
|
883 | const z = Math.log(n);
|
884 | const s = 0.5 * Math.exp(2 * z / 3);
|
885 | const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
|
886 | const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
|
887 | const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
|
888 | quickselect(array, k, newLeft, newRight, compare);
|
889 | }
|
890 |
|
891 | const t = array[k];
|
892 | let i = left;
|
893 | let j = right;
|
894 |
|
895 | swap$1(array, left, k);
|
896 | if (compare(array[right], t) > 0) swap$1(array, left, right);
|
897 |
|
898 | while (i < j) {
|
899 | swap$1(array, i, j), ++i, --j;
|
900 | while (compare(array[i], t) < 0) ++i;
|
901 | while (compare(array[j], t) > 0) --j;
|
902 | }
|
903 |
|
904 | if (compare(array[left], t) === 0) swap$1(array, left, j);
|
905 | else ++j, swap$1(array, j, right);
|
906 |
|
907 | if (j <= k) left = j + 1;
|
908 | if (k <= j) right = j - 1;
|
909 | }
|
910 |
|
911 | return array;
|
912 | }
|
913 |
|
914 | function swap$1(array, i, j) {
|
915 | const t = array[i];
|
916 | array[i] = array[j];
|
917 | array[j] = t;
|
918 | }
|
919 |
|
920 | function greatest(values, compare = ascending$3) {
|
921 | let max;
|
922 | let defined = false;
|
923 | if (compare.length === 1) {
|
924 | let maxValue;
|
925 | for (const element of values) {
|
926 | const value = compare(element);
|
927 | if (defined
|
928 | ? ascending$3(value, maxValue) > 0
|
929 | : ascending$3(value, value) === 0) {
|
930 | max = element;
|
931 | maxValue = value;
|
932 | defined = true;
|
933 | }
|
934 | }
|
935 | } else {
|
936 | for (const value of values) {
|
937 | if (defined
|
938 | ? compare(value, max) > 0
|
939 | : compare(value, value) === 0) {
|
940 | max = value;
|
941 | defined = true;
|
942 | }
|
943 | }
|
944 | }
|
945 | return max;
|
946 | }
|
947 |
|
948 | function quantile$1(values, p, valueof) {
|
949 | values = Float64Array.from(numbers(values, valueof));
|
950 | if (!(n = values.length)) return;
|
951 | if ((p = +p) <= 0 || n < 2) return min$2(values);
|
952 | if (p >= 1) return max$3(values);
|
953 | var n,
|
954 | i = (n - 1) * p,
|
955 | i0 = Math.floor(i),
|
956 | value0 = max$3(quickselect(values, i0).subarray(0, i0 + 1)),
|
957 | value1 = min$2(values.subarray(i0 + 1));
|
958 | return value0 + (value1 - value0) * (i - i0);
|
959 | }
|
960 |
|
961 | function quantileSorted(values, p, valueof = number$3) {
|
962 | if (!(n = values.length)) return;
|
963 | if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
|
964 | if (p >= 1) return +valueof(values[n - 1], n - 1, values);
|
965 | var n,
|
966 | i = (n - 1) * p,
|
967 | i0 = Math.floor(i),
|
968 | value0 = +valueof(values[i0], i0, values),
|
969 | value1 = +valueof(values[i0 + 1], i0 + 1, values);
|
970 | return value0 + (value1 - value0) * (i - i0);
|
971 | }
|
972 |
|
973 | function quantileIndex(values, p, valueof) {
|
974 | values = Float64Array.from(numbers(values, valueof));
|
975 | if (!(n = values.length)) return;
|
976 | if ((p = +p) <= 0 || n < 2) return minIndex(values);
|
977 | if (p >= 1) return maxIndex(values);
|
978 | var n,
|
979 | i = Math.floor((n - 1) * p),
|
980 | order = (i, j) => ascendingDefined(values[i], values[j]),
|
981 | index = quickselect(Uint32Array.from(values, (_, i) => i), i, 0, n - 1, order);
|
982 | return greatest(index.subarray(0, i + 1), i => values[i]);
|
983 | }
|
984 |
|
985 | function thresholdFreedmanDiaconis(values, min, max) {
|
986 | return Math.ceil((max - min) / (2 * (quantile$1(values, 0.75) - quantile$1(values, 0.25)) * Math.pow(count$1(values), -1 / 3)));
|
987 | }
|
988 |
|
989 | function thresholdScott(values, min, max) {
|
990 | return Math.ceil((max - min) * Math.cbrt(count$1(values)) / (3.49 * deviation(values)));
|
991 | }
|
992 |
|
993 | function mean(values, valueof) {
|
994 | let count = 0;
|
995 | let sum = 0;
|
996 | if (valueof === undefined) {
|
997 | for (let value of values) {
|
998 | if (value != null && (value = +value) >= value) {
|
999 | ++count, sum += value;
|
1000 | }
|
1001 | }
|
1002 | } else {
|
1003 | let index = -1;
|
1004 | for (let value of values) {
|
1005 | if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
|
1006 | ++count, sum += value;
|
1007 | }
|
1008 | }
|
1009 | }
|
1010 | if (count) return sum / count;
|
1011 | }
|
1012 |
|
1013 | function median(values, valueof) {
|
1014 | return quantile$1(values, 0.5, valueof);
|
1015 | }
|
1016 |
|
1017 | function medianIndex(values, valueof) {
|
1018 | return quantileIndex(values, 0.5, valueof);
|
1019 | }
|
1020 |
|
1021 | function* flatten(arrays) {
|
1022 | for (const array of arrays) {
|
1023 | yield* array;
|
1024 | }
|
1025 | }
|
1026 |
|
1027 | function merge(arrays) {
|
1028 | return Array.from(flatten(arrays));
|
1029 | }
|
1030 |
|
1031 | function mode(values, valueof) {
|
1032 | const counts = new InternMap();
|
1033 | if (valueof === undefined) {
|
1034 | for (let value of values) {
|
1035 | if (value != null && value >= value) {
|
1036 | counts.set(value, (counts.get(value) || 0) + 1);
|
1037 | }
|
1038 | }
|
1039 | } else {
|
1040 | let index = -1;
|
1041 | for (let value of values) {
|
1042 | if ((value = valueof(value, ++index, values)) != null && value >= value) {
|
1043 | counts.set(value, (counts.get(value) || 0) + 1);
|
1044 | }
|
1045 | }
|
1046 | }
|
1047 | let modeValue;
|
1048 | let modeCount = 0;
|
1049 | for (const [value, count] of counts) {
|
1050 | if (count > modeCount) {
|
1051 | modeCount = count;
|
1052 | modeValue = value;
|
1053 | }
|
1054 | }
|
1055 | return modeValue;
|
1056 | }
|
1057 |
|
1058 | function pairs(values, pairof = pair) {
|
1059 | const pairs = [];
|
1060 | let previous;
|
1061 | let first = false;
|
1062 | for (const value of values) {
|
1063 | if (first) pairs.push(pairof(previous, value));
|
1064 | previous = value;
|
1065 | first = true;
|
1066 | }
|
1067 | return pairs;
|
1068 | }
|
1069 |
|
1070 | function pair(a, b) {
|
1071 | return [a, b];
|
1072 | }
|
1073 |
|
1074 | function range$2(start, stop, step) {
|
1075 | start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
|
1076 |
|
1077 | var i = -1,
|
1078 | n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
|
1079 | range = new Array(n);
|
1080 |
|
1081 | while (++i < n) {
|
1082 | range[i] = start + i * step;
|
1083 | }
|
1084 |
|
1085 | return range;
|
1086 | }
|
1087 |
|
1088 | function rank(values, valueof = ascending$3) {
|
1089 | if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
|
1090 | let V = Array.from(values);
|
1091 | const R = new Float64Array(V.length);
|
1092 | if (valueof.length !== 2) V = V.map(valueof), valueof = ascending$3;
|
1093 | const compareIndex = (i, j) => valueof(V[i], V[j]);
|
1094 | let k, r;
|
1095 | Uint32Array
|
1096 | .from(V, (_, i) => i)
|
1097 | .sort(valueof === ascending$3 ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex))
|
1098 | .forEach((j, i) => {
|
1099 | const c = compareIndex(j, k === undefined ? j : k);
|
1100 | if (c >= 0) {
|
1101 | if (k === undefined || c > 0) k = j, r = i;
|
1102 | R[j] = r;
|
1103 | } else {
|
1104 | R[j] = NaN;
|
1105 | }
|
1106 | });
|
1107 | return R;
|
1108 | }
|
1109 |
|
1110 | function least(values, compare = ascending$3) {
|
1111 | let min;
|
1112 | let defined = false;
|
1113 | if (compare.length === 1) {
|
1114 | let minValue;
|
1115 | for (const element of values) {
|
1116 | const value = compare(element);
|
1117 | if (defined
|
1118 | ? ascending$3(value, minValue) < 0
|
1119 | : ascending$3(value, value) === 0) {
|
1120 | min = element;
|
1121 | minValue = value;
|
1122 | defined = true;
|
1123 | }
|
1124 | }
|
1125 | } else {
|
1126 | for (const value of values) {
|
1127 | if (defined
|
1128 | ? compare(value, min) < 0
|
1129 | : compare(value, value) === 0) {
|
1130 | min = value;
|
1131 | defined = true;
|
1132 | }
|
1133 | }
|
1134 | }
|
1135 | return min;
|
1136 | }
|
1137 |
|
1138 | function leastIndex(values, compare = ascending$3) {
|
1139 | if (compare.length === 1) return minIndex(values, compare);
|
1140 | let minValue;
|
1141 | let min = -1;
|
1142 | let index = -1;
|
1143 | for (const value of values) {
|
1144 | ++index;
|
1145 | if (min < 0
|
1146 | ? compare(value, value) === 0
|
1147 | : compare(value, minValue) < 0) {
|
1148 | minValue = value;
|
1149 | min = index;
|
1150 | }
|
1151 | }
|
1152 | return min;
|
1153 | }
|
1154 |
|
1155 | function greatestIndex(values, compare = ascending$3) {
|
1156 | if (compare.length === 1) return maxIndex(values, compare);
|
1157 | let maxValue;
|
1158 | let max = -1;
|
1159 | let index = -1;
|
1160 | for (const value of values) {
|
1161 | ++index;
|
1162 | if (max < 0
|
1163 | ? compare(value, value) === 0
|
1164 | : compare(value, maxValue) > 0) {
|
1165 | maxValue = value;
|
1166 | max = index;
|
1167 | }
|
1168 | }
|
1169 | return max;
|
1170 | }
|
1171 |
|
1172 | function scan(values, compare) {
|
1173 | const index = leastIndex(values, compare);
|
1174 | return index < 0 ? undefined : index;
|
1175 | }
|
1176 |
|
1177 | var shuffle$1 = shuffler(Math.random);
|
1178 |
|
1179 | function shuffler(random) {
|
1180 | return function shuffle(array, i0 = 0, i1 = array.length) {
|
1181 | let m = i1 - (i0 = +i0);
|
1182 | while (m) {
|
1183 | const i = random() * m-- | 0, t = array[m + i0];
|
1184 | array[m + i0] = array[i + i0];
|
1185 | array[i + i0] = t;
|
1186 | }
|
1187 | return array;
|
1188 | };
|
1189 | }
|
1190 |
|
1191 | function sum$2(values, valueof) {
|
1192 | let sum = 0;
|
1193 | if (valueof === undefined) {
|
1194 | for (let value of values) {
|
1195 | if (value = +value) {
|
1196 | sum += value;
|
1197 | }
|
1198 | }
|
1199 | } else {
|
1200 | let index = -1;
|
1201 | for (let value of values) {
|
1202 | if (value = +valueof(value, ++index, values)) {
|
1203 | sum += value;
|
1204 | }
|
1205 | }
|
1206 | }
|
1207 | return sum;
|
1208 | }
|
1209 |
|
1210 | function transpose(matrix) {
|
1211 | if (!(n = matrix.length)) return [];
|
1212 | for (var i = -1, m = min$2(matrix, length$2), transpose = new Array(m); ++i < m;) {
|
1213 | for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
|
1214 | row[j] = matrix[j][i];
|
1215 | }
|
1216 | }
|
1217 | return transpose;
|
1218 | }
|
1219 |
|
1220 | function length$2(d) {
|
1221 | return d.length;
|
1222 | }
|
1223 |
|
1224 | function zip() {
|
1225 | return transpose(arguments);
|
1226 | }
|
1227 |
|
1228 | function every(values, test) {
|
1229 | if (typeof test !== "function") throw new TypeError("test is not a function");
|
1230 | let index = -1;
|
1231 | for (const value of values) {
|
1232 | if (!test(value, ++index, values)) {
|
1233 | return false;
|
1234 | }
|
1235 | }
|
1236 | return true;
|
1237 | }
|
1238 |
|
1239 | function some(values, test) {
|
1240 | if (typeof test !== "function") throw new TypeError("test is not a function");
|
1241 | let index = -1;
|
1242 | for (const value of values) {
|
1243 | if (test(value, ++index, values)) {
|
1244 | return true;
|
1245 | }
|
1246 | }
|
1247 | return false;
|
1248 | }
|
1249 |
|
1250 | function filter$1(values, test) {
|
1251 | if (typeof test !== "function") throw new TypeError("test is not a function");
|
1252 | const array = [];
|
1253 | let index = -1;
|
1254 | for (const value of values) {
|
1255 | if (test(value, ++index, values)) {
|
1256 | array.push(value);
|
1257 | }
|
1258 | }
|
1259 | return array;
|
1260 | }
|
1261 |
|
1262 | function map$1(values, mapper) {
|
1263 | if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
|
1264 | if (typeof mapper !== "function") throw new TypeError("mapper is not a function");
|
1265 | return Array.from(values, (value, index) => mapper(value, index, values));
|
1266 | }
|
1267 |
|
1268 | function reduce(values, reducer, value) {
|
1269 | if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
|
1270 | const iterator = values[Symbol.iterator]();
|
1271 | let done, next, index = -1;
|
1272 | if (arguments.length < 3) {
|
1273 | ({done, value} = iterator.next());
|
1274 | if (done) return;
|
1275 | ++index;
|
1276 | }
|
1277 | while (({done, value: next} = iterator.next()), !done) {
|
1278 | value = reducer(value, next, ++index, values);
|
1279 | }
|
1280 | return value;
|
1281 | }
|
1282 |
|
1283 | function reverse$1(values) {
|
1284 | if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
|
1285 | return Array.from(values).reverse();
|
1286 | }
|
1287 |
|
1288 | function difference(values, ...others) {
|
1289 | values = new InternSet(values);
|
1290 | for (const other of others) {
|
1291 | for (const value of other) {
|
1292 | values.delete(value);
|
1293 | }
|
1294 | }
|
1295 | return values;
|
1296 | }
|
1297 |
|
1298 | function disjoint(values, other) {
|
1299 | const iterator = other[Symbol.iterator](), set = new InternSet();
|
1300 | for (const v of values) {
|
1301 | if (set.has(v)) return false;
|
1302 | let value, done;
|
1303 | while (({value, done} = iterator.next())) {
|
1304 | if (done) break;
|
1305 | if (Object.is(v, value)) return false;
|
1306 | set.add(value);
|
1307 | }
|
1308 | }
|
1309 | return true;
|
1310 | }
|
1311 |
|
1312 | function intersection(values, ...others) {
|
1313 | values = new InternSet(values);
|
1314 | others = others.map(set$2);
|
1315 | out: for (const value of values) {
|
1316 | for (const other of others) {
|
1317 | if (!other.has(value)) {
|
1318 | values.delete(value);
|
1319 | continue out;
|
1320 | }
|
1321 | }
|
1322 | }
|
1323 | return values;
|
1324 | }
|
1325 |
|
1326 | function set$2(values) {
|
1327 | return values instanceof InternSet ? values : new InternSet(values);
|
1328 | }
|
1329 |
|
1330 | function superset(values, other) {
|
1331 | const iterator = values[Symbol.iterator](), set = new Set();
|
1332 | for (const o of other) {
|
1333 | const io = intern(o);
|
1334 | if (set.has(io)) continue;
|
1335 | let value, done;
|
1336 | while (({value, done} = iterator.next())) {
|
1337 | if (done) return false;
|
1338 | const ivalue = intern(value);
|
1339 | set.add(ivalue);
|
1340 | if (Object.is(io, ivalue)) break;
|
1341 | }
|
1342 | }
|
1343 | return true;
|
1344 | }
|
1345 |
|
1346 | function intern(value) {
|
1347 | return value !== null && typeof value === "object" ? value.valueOf() : value;
|
1348 | }
|
1349 |
|
1350 | function subset(values, other) {
|
1351 | return superset(other, values);
|
1352 | }
|
1353 |
|
1354 | function union(...others) {
|
1355 | const set = new InternSet();
|
1356 | for (const other of others) {
|
1357 | for (const o of other) {
|
1358 | set.add(o);
|
1359 | }
|
1360 | }
|
1361 | return set;
|
1362 | }
|
1363 |
|
1364 | function identity$8(x) {
|
1365 | return x;
|
1366 | }
|
1367 |
|
1368 | var top = 1,
|
1369 | right = 2,
|
1370 | bottom = 3,
|
1371 | left = 4,
|
1372 | epsilon$6 = 1e-6;
|
1373 |
|
1374 | function translateX(x) {
|
1375 | return "translate(" + x + ",0)";
|
1376 | }
|
1377 |
|
1378 | function translateY(y) {
|
1379 | return "translate(0," + y + ")";
|
1380 | }
|
1381 |
|
1382 | function number$2(scale) {
|
1383 | return d => +scale(d);
|
1384 | }
|
1385 |
|
1386 | function center$1(scale, offset) {
|
1387 | offset = Math.max(0, scale.bandwidth() - offset * 2) / 2;
|
1388 | if (scale.round()) offset = Math.round(offset);
|
1389 | return d => +scale(d) + offset;
|
1390 | }
|
1391 |
|
1392 | function entering() {
|
1393 | return !this.__axis;
|
1394 | }
|
1395 |
|
1396 | function axis(orient, scale) {
|
1397 | var tickArguments = [],
|
1398 | tickValues = null,
|
1399 | tickFormat = null,
|
1400 | tickSizeInner = 6,
|
1401 | tickSizeOuter = 6,
|
1402 | tickPadding = 3,
|
1403 | offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5,
|
1404 | k = orient === top || orient === left ? -1 : 1,
|
1405 | x = orient === left || orient === right ? "x" : "y",
|
1406 | transform = orient === top || orient === bottom ? translateX : translateY;
|
1407 |
|
1408 | function axis(context) {
|
1409 | var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
|
1410 | format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$8) : tickFormat,
|
1411 | spacing = Math.max(tickSizeInner, 0) + tickPadding,
|
1412 | range = scale.range(),
|
1413 | range0 = +range[0] + offset,
|
1414 | range1 = +range[range.length - 1] + offset,
|
1415 | position = (scale.bandwidth ? center$1 : number$2)(scale.copy(), offset),
|
1416 | selection = context.selection ? context.selection() : context,
|
1417 | path = selection.selectAll(".domain").data([null]),
|
1418 | tick = selection.selectAll(".tick").data(values, scale).order(),
|
1419 | tickExit = tick.exit(),
|
1420 | tickEnter = tick.enter().append("g").attr("class", "tick"),
|
1421 | line = tick.select("line"),
|
1422 | text = tick.select("text");
|
1423 |
|
1424 | path = path.merge(path.enter().insert("path", ".tick")
|
1425 | .attr("class", "domain")
|
1426 | .attr("stroke", "currentColor"));
|
1427 |
|
1428 | tick = tick.merge(tickEnter);
|
1429 |
|
1430 | line = line.merge(tickEnter.append("line")
|
1431 | .attr("stroke", "currentColor")
|
1432 | .attr(x + "2", k * tickSizeInner));
|
1433 |
|
1434 | text = text.merge(tickEnter.append("text")
|
1435 | .attr("fill", "currentColor")
|
1436 | .attr(x, k * spacing)
|
1437 | .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
|
1438 |
|
1439 | if (context !== selection) {
|
1440 | path = path.transition(context);
|
1441 | tick = tick.transition(context);
|
1442 | line = line.transition(context);
|
1443 | text = text.transition(context);
|
1444 |
|
1445 | tickExit = tickExit.transition(context)
|
1446 | .attr("opacity", epsilon$6)
|
1447 | .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform"); });
|
1448 |
|
1449 | tickEnter
|
1450 | .attr("opacity", epsilon$6)
|
1451 | .attr("transform", function(d) { var p = this.parentNode.__axis; return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset); });
|
1452 | }
|
1453 |
|
1454 | tickExit.remove();
|
1455 |
|
1456 | path
|
1457 | .attr("d", orient === left || orient === right
|
1458 | ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1)
|
1459 | : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1));
|
1460 |
|
1461 | tick
|
1462 | .attr("opacity", 1)
|
1463 | .attr("transform", function(d) { return transform(position(d) + offset); });
|
1464 |
|
1465 | line
|
1466 | .attr(x + "2", k * tickSizeInner);
|
1467 |
|
1468 | text
|
1469 | .attr(x, k * spacing)
|
1470 | .text(format);
|
1471 |
|
1472 | selection.filter(entering)
|
1473 | .attr("fill", "none")
|
1474 | .attr("font-size", 10)
|
1475 | .attr("font-family", "sans-serif")
|
1476 | .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
|
1477 |
|
1478 | selection
|
1479 | .each(function() { this.__axis = position; });
|
1480 | }
|
1481 |
|
1482 | axis.scale = function(_) {
|
1483 | return arguments.length ? (scale = _, axis) : scale;
|
1484 | };
|
1485 |
|
1486 | axis.ticks = function() {
|
1487 | return tickArguments = Array.from(arguments), axis;
|
1488 | };
|
1489 |
|
1490 | axis.tickArguments = function(_) {
|
1491 | return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice();
|
1492 | };
|
1493 |
|
1494 | axis.tickValues = function(_) {
|
1495 | return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice();
|
1496 | };
|
1497 |
|
1498 | axis.tickFormat = function(_) {
|
1499 | return arguments.length ? (tickFormat = _, axis) : tickFormat;
|
1500 | };
|
1501 |
|
1502 | axis.tickSize = function(_) {
|
1503 | return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
|
1504 | };
|
1505 |
|
1506 | axis.tickSizeInner = function(_) {
|
1507 | return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
|
1508 | };
|
1509 |
|
1510 | axis.tickSizeOuter = function(_) {
|
1511 | return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
|
1512 | };
|
1513 |
|
1514 | axis.tickPadding = function(_) {
|
1515 | return arguments.length ? (tickPadding = +_, axis) : tickPadding;
|
1516 | };
|
1517 |
|
1518 | axis.offset = function(_) {
|
1519 | return arguments.length ? (offset = +_, axis) : offset;
|
1520 | };
|
1521 |
|
1522 | return axis;
|
1523 | }
|
1524 |
|
1525 | function axisTop(scale) {
|
1526 | return axis(top, scale);
|
1527 | }
|
1528 |
|
1529 | function axisRight(scale) {
|
1530 | return axis(right, scale);
|
1531 | }
|
1532 |
|
1533 | function axisBottom(scale) {
|
1534 | return axis(bottom, scale);
|
1535 | }
|
1536 |
|
1537 | function axisLeft(scale) {
|
1538 | return axis(left, scale);
|
1539 | }
|
1540 |
|
1541 | var noop$3 = {value: () => {}};
|
1542 |
|
1543 | function dispatch() {
|
1544 | for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
|
1545 | if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
|
1546 | _[t] = [];
|
1547 | }
|
1548 | return new Dispatch(_);
|
1549 | }
|
1550 |
|
1551 | function Dispatch(_) {
|
1552 | this._ = _;
|
1553 | }
|
1554 |
|
1555 | function parseTypenames$1(typenames, types) {
|
1556 | return typenames.trim().split(/^|\s+/).map(function(t) {
|
1557 | var name = "", i = t.indexOf(".");
|
1558 | if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
1559 | if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
|
1560 | return {type: t, name: name};
|
1561 | });
|
1562 | }
|
1563 |
|
1564 | Dispatch.prototype = dispatch.prototype = {
|
1565 | constructor: Dispatch,
|
1566 | on: function(typename, callback) {
|
1567 | var _ = this._,
|
1568 | T = parseTypenames$1(typename + "", _),
|
1569 | t,
|
1570 | i = -1,
|
1571 | n = T.length;
|
1572 |
|
1573 |
|
1574 | if (arguments.length < 2) {
|
1575 | while (++i < n) if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t;
|
1576 | return;
|
1577 | }
|
1578 |
|
1579 | // If a type was specified, set the callback for the given type and name.
|
1580 | // Otherwise, if a null callback was specified, remove callbacks of the given name.
|
1581 | if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
|
1582 | while (++i < n) {
|
1583 | if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
|
1584 | else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
|
1585 | }
|
1586 |
|
1587 | return this;
|
1588 | },
|
1589 | copy: function() {
|
1590 | var copy = {}, _ = this._;
|
1591 | for (var t in _) copy[t] = _[t].slice();
|
1592 | return new Dispatch(copy);
|
1593 | },
|
1594 | call: function(type, that) {
|
1595 | if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
|
1596 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
1597 | for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
1598 | },
|
1599 | apply: function(type, that, args) {
|
1600 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
1601 | for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
1602 | }
|
1603 | };
|
1604 |
|
1605 | function get$1(type, name) {
|
1606 | for (var i = 0, n = type.length, c; i < n; ++i) {
|
1607 | if ((c = type[i]).name === name) {
|
1608 | return c.value;
|
1609 | }
|
1610 | }
|
1611 | }
|
1612 |
|
1613 | function set$1(type, name, callback) {
|
1614 | for (var i = 0, n = type.length; i < n; ++i) {
|
1615 | if (type[i].name === name) {
|
1616 | type[i] = noop$3, type = type.slice(0, i).concat(type.slice(i + 1));
|
1617 | break;
|
1618 | }
|
1619 | }
|
1620 | if (callback != null) type.push({name: name, value: callback});
|
1621 | return type;
|
1622 | }
|
1623 |
|
1624 | var xhtml = "http://www.w3.org/1999/xhtml";
|
1625 |
|
1626 | var namespaces = {
|
1627 | svg: "http://www.w3.org/2000/svg",
|
1628 | xhtml: xhtml,
|
1629 | xlink: "http://www.w3.org/1999/xlink",
|
1630 | xml: "http://www.w3.org/XML/1998/namespace",
|
1631 | xmlns: "http://www.w3.org/2000/xmlns/"
|
1632 | };
|
1633 |
|
1634 | function namespace(name) {
|
1635 | var prefix = name += "", i = prefix.indexOf(":");
|
1636 | if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
|
1637 | return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
|
1638 | }
|
1639 |
|
1640 | function creatorInherit(name) {
|
1641 | return function() {
|
1642 | var document = this.ownerDocument,
|
1643 | uri = this.namespaceURI;
|
1644 | return uri === xhtml && document.documentElement.namespaceURI === xhtml
|
1645 | ? document.createElement(name)
|
1646 | : document.createElementNS(uri, name);
|
1647 | };
|
1648 | }
|
1649 |
|
1650 | function creatorFixed(fullname) {
|
1651 | return function() {
|
1652 | return this.ownerDocument.createElementNS(fullname.space, fullname.local);
|
1653 | };
|
1654 | }
|
1655 |
|
1656 | function creator(name) {
|
1657 | var fullname = namespace(name);
|
1658 | return (fullname.local
|
1659 | ? creatorFixed
|
1660 | : creatorInherit)(fullname);
|
1661 | }
|
1662 |
|
1663 | function none$2() {}
|
1664 |
|
1665 | function selector(selector) {
|
1666 | return selector == null ? none$2 : function() {
|
1667 | return this.querySelector(selector);
|
1668 | };
|
1669 | }
|
1670 |
|
1671 | function selection_select(select) {
|
1672 | if (typeof select !== "function") select = selector(select);
|
1673 |
|
1674 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
1675 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
|
1676 | if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
1677 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
1678 | subgroup[i] = subnode;
|
1679 | }
|
1680 | }
|
1681 | }
|
1682 |
|
1683 | return new Selection$1(subgroups, this._parents);
|
1684 | }
|
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 |
|
1692 | function array$4(x) {
|
1693 | return x == null ? [] : Array.isArray(x) ? x : Array.from(x);
|
1694 | }
|
1695 |
|
1696 | function empty$1() {
|
1697 | return [];
|
1698 | }
|
1699 |
|
1700 | function selectorAll(selector) {
|
1701 | return selector == null ? empty$1 : function() {
|
1702 | return this.querySelectorAll(selector);
|
1703 | };
|
1704 | }
|
1705 |
|
1706 | function arrayAll(select) {
|
1707 | return function() {
|
1708 | return array$4(select.apply(this, arguments));
|
1709 | };
|
1710 | }
|
1711 |
|
1712 | function selection_selectAll(select) {
|
1713 | if (typeof select === "function") select = arrayAll(select);
|
1714 | else select = selectorAll(select);
|
1715 |
|
1716 | for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
|
1717 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
1718 | if (node = group[i]) {
|
1719 | subgroups.push(select.call(node, node.__data__, i, group));
|
1720 | parents.push(node);
|
1721 | }
|
1722 | }
|
1723 | }
|
1724 |
|
1725 | return new Selection$1(subgroups, parents);
|
1726 | }
|
1727 |
|
1728 | function matcher(selector) {
|
1729 | return function() {
|
1730 | return this.matches(selector);
|
1731 | };
|
1732 | }
|
1733 |
|
1734 | function childMatcher(selector) {
|
1735 | return function(node) {
|
1736 | return node.matches(selector);
|
1737 | };
|
1738 | }
|
1739 |
|
1740 | var find$1 = Array.prototype.find;
|
1741 |
|
1742 | function childFind(match) {
|
1743 | return function() {
|
1744 | return find$1.call(this.children, match);
|
1745 | };
|
1746 | }
|
1747 |
|
1748 | function childFirst() {
|
1749 | return this.firstElementChild;
|
1750 | }
|
1751 |
|
1752 | function selection_selectChild(match) {
|
1753 | return this.select(match == null ? childFirst
|
1754 | : childFind(typeof match === "function" ? match : childMatcher(match)));
|
1755 | }
|
1756 |
|
1757 | var filter = Array.prototype.filter;
|
1758 |
|
1759 | function children() {
|
1760 | return Array.from(this.children);
|
1761 | }
|
1762 |
|
1763 | function childrenFilter(match) {
|
1764 | return function() {
|
1765 | return filter.call(this.children, match);
|
1766 | };
|
1767 | }
|
1768 |
|
1769 | function selection_selectChildren(match) {
|
1770 | return this.selectAll(match == null ? children
|
1771 | : childrenFilter(typeof match === "function" ? match : childMatcher(match)));
|
1772 | }
|
1773 |
|
1774 | function selection_filter(match) {
|
1775 | if (typeof match !== "function") match = matcher(match);
|
1776 |
|
1777 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
1778 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
|
1779 | if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
1780 | subgroup.push(node);
|
1781 | }
|
1782 | }
|
1783 | }
|
1784 |
|
1785 | return new Selection$1(subgroups, this._parents);
|
1786 | }
|
1787 |
|
1788 | function sparse(update) {
|
1789 | return new Array(update.length);
|
1790 | }
|
1791 |
|
1792 | function selection_enter() {
|
1793 | return new Selection$1(this._enter || this._groups.map(sparse), this._parents);
|
1794 | }
|
1795 |
|
1796 | function EnterNode(parent, datum) {
|
1797 | this.ownerDocument = parent.ownerDocument;
|
1798 | this.namespaceURI = parent.namespaceURI;
|
1799 | this._next = null;
|
1800 | this._parent = parent;
|
1801 | this.__data__ = datum;
|
1802 | }
|
1803 |
|
1804 | EnterNode.prototype = {
|
1805 | constructor: EnterNode,
|
1806 | appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
|
1807 | insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
|
1808 | querySelector: function(selector) { return this._parent.querySelector(selector); },
|
1809 | querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
|
1810 | };
|
1811 |
|
1812 | function constant$a(x) {
|
1813 | return function() {
|
1814 | return x;
|
1815 | };
|
1816 | }
|
1817 |
|
1818 | function bindIndex(parent, group, enter, update, exit, data) {
|
1819 | var i = 0,
|
1820 | node,
|
1821 | groupLength = group.length,
|
1822 | dataLength = data.length;
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 | for (; i < dataLength; ++i) {
|
1828 | if (node = group[i]) {
|
1829 | node.__data__ = data[i];
|
1830 | update[i] = node;
|
1831 | } else {
|
1832 | enter[i] = new EnterNode(parent, data[i]);
|
1833 | }
|
1834 | }
|
1835 |
|
1836 |
|
1837 | for (; i < groupLength; ++i) {
|
1838 | if (node = group[i]) {
|
1839 | exit[i] = node;
|
1840 | }
|
1841 | }
|
1842 | }
|
1843 |
|
1844 | function bindKey(parent, group, enter, update, exit, data, key) {
|
1845 | var i,
|
1846 | node,
|
1847 | nodeByKeyValue = new Map,
|
1848 | groupLength = group.length,
|
1849 | dataLength = data.length,
|
1850 | keyValues = new Array(groupLength),
|
1851 | keyValue;
|
1852 |
|
1853 |
|
1854 |
|
1855 | for (i = 0; i < groupLength; ++i) {
|
1856 | if (node = group[i]) {
|
1857 | keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
|
1858 | if (nodeByKeyValue.has(keyValue)) {
|
1859 | exit[i] = node;
|
1860 | } else {
|
1861 | nodeByKeyValue.set(keyValue, node);
|
1862 | }
|
1863 | }
|
1864 | }
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 | for (i = 0; i < dataLength; ++i) {
|
1870 | keyValue = key.call(parent, data[i], i, data) + "";
|
1871 | if (node = nodeByKeyValue.get(keyValue)) {
|
1872 | update[i] = node;
|
1873 | node.__data__ = data[i];
|
1874 | nodeByKeyValue.delete(keyValue);
|
1875 | } else {
|
1876 | enter[i] = new EnterNode(parent, data[i]);
|
1877 | }
|
1878 | }
|
1879 |
|
1880 |
|
1881 | for (i = 0; i < groupLength; ++i) {
|
1882 | if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) {
|
1883 | exit[i] = node;
|
1884 | }
|
1885 | }
|
1886 | }
|
1887 |
|
1888 | function datum(node) {
|
1889 | return node.__data__;
|
1890 | }
|
1891 |
|
1892 | function selection_data(value, key) {
|
1893 | if (!arguments.length) return Array.from(this, datum);
|
1894 |
|
1895 | var bind = key ? bindKey : bindIndex,
|
1896 | parents = this._parents,
|
1897 | groups = this._groups;
|
1898 |
|
1899 | if (typeof value !== "function") value = constant$a(value);
|
1900 |
|
1901 | for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
|
1902 | var parent = parents[j],
|
1903 | group = groups[j],
|
1904 | groupLength = group.length,
|
1905 | data = arraylike(value.call(parent, parent && parent.__data__, j, parents)),
|
1906 | dataLength = data.length,
|
1907 | enterGroup = enter[j] = new Array(dataLength),
|
1908 | updateGroup = update[j] = new Array(dataLength),
|
1909 | exitGroup = exit[j] = new Array(groupLength);
|
1910 |
|
1911 | bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 | for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
|
1917 | if (previous = enterGroup[i0]) {
|
1918 | if (i0 >= i1) i1 = i0 + 1;
|
1919 | while (!(next = updateGroup[i1]) && ++i1 < dataLength);
|
1920 | previous._next = next || null;
|
1921 | }
|
1922 | }
|
1923 | }
|
1924 |
|
1925 | update = new Selection$1(update, parents);
|
1926 | update._enter = enter;
|
1927 | update._exit = exit;
|
1928 | return update;
|
1929 | }
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 | function arraylike(data) {
|
1938 | return typeof data === "object" && "length" in data
|
1939 | ? data
|
1940 | : Array.from(data);
|
1941 | }
|
1942 |
|
1943 | function selection_exit() {
|
1944 | return new Selection$1(this._exit || this._groups.map(sparse), this._parents);
|
1945 | }
|
1946 |
|
1947 | function selection_join(onenter, onupdate, onexit) {
|
1948 | var enter = this.enter(), update = this, exit = this.exit();
|
1949 | if (typeof onenter === "function") {
|
1950 | enter = onenter(enter);
|
1951 | if (enter) enter = enter.selection();
|
1952 | } else {
|
1953 | enter = enter.append(onenter + "");
|
1954 | }
|
1955 | if (onupdate != null) {
|
1956 | update = onupdate(update);
|
1957 | if (update) update = update.selection();
|
1958 | }
|
1959 | if (onexit == null) exit.remove(); else onexit(exit);
|
1960 | return enter && update ? enter.merge(update).order() : update;
|
1961 | }
|
1962 |
|
1963 | function selection_merge(context) {
|
1964 | var selection = context.selection ? context.selection() : context;
|
1965 |
|
1966 | 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) {
|
1967 | for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
|
1968 | if (node = group0[i] || group1[i]) {
|
1969 | merge[i] = node;
|
1970 | }
|
1971 | }
|
1972 | }
|
1973 |
|
1974 | for (; j < m0; ++j) {
|
1975 | merges[j] = groups0[j];
|
1976 | }
|
1977 |
|
1978 | return new Selection$1(merges, this._parents);
|
1979 | }
|
1980 |
|
1981 | function selection_order() {
|
1982 |
|
1983 | for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
|
1984 | for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
|
1985 | if (node = group[i]) {
|
1986 | if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
|
1987 | next = node;
|
1988 | }
|
1989 | }
|
1990 | }
|
1991 |
|
1992 | return this;
|
1993 | }
|
1994 |
|
1995 | function selection_sort(compare) {
|
1996 | if (!compare) compare = ascending$2;
|
1997 |
|
1998 | function compareNode(a, b) {
|
1999 | return a && b ? compare(a.__data__, b.__data__) : !a - !b;
|
2000 | }
|
2001 |
|
2002 | for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
|
2003 | for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
|
2004 | if (node = group[i]) {
|
2005 | sortgroup[i] = node;
|
2006 | }
|
2007 | }
|
2008 | sortgroup.sort(compareNode);
|
2009 | }
|
2010 |
|
2011 | return new Selection$1(sortgroups, this._parents).order();
|
2012 | }
|
2013 |
|
2014 | function ascending$2(a, b) {
|
2015 | return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
2016 | }
|
2017 |
|
2018 | function selection_call() {
|
2019 | var callback = arguments[0];
|
2020 | arguments[0] = this;
|
2021 | callback.apply(null, arguments);
|
2022 | return this;
|
2023 | }
|
2024 |
|
2025 | function selection_nodes() {
|
2026 | return Array.from(this);
|
2027 | }
|
2028 |
|
2029 | function selection_node() {
|
2030 |
|
2031 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
2032 | for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
|
2033 | var node = group[i];
|
2034 | if (node) return node;
|
2035 | }
|
2036 | }
|
2037 |
|
2038 | return null;
|
2039 | }
|
2040 |
|
2041 | function selection_size() {
|
2042 | let size = 0;
|
2043 | for (const node of this) ++size;
|
2044 | return size;
|
2045 | }
|
2046 |
|
2047 | function selection_empty() {
|
2048 | return !this.node();
|
2049 | }
|
2050 |
|
2051 | function selection_each(callback) {
|
2052 |
|
2053 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
2054 | for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
|
2055 | if (node = group[i]) callback.call(node, node.__data__, i, group);
|
2056 | }
|
2057 | }
|
2058 |
|
2059 | return this;
|
2060 | }
|
2061 |
|
2062 | function attrRemove$1(name) {
|
2063 | return function() {
|
2064 | this.removeAttribute(name);
|
2065 | };
|
2066 | }
|
2067 |
|
2068 | function attrRemoveNS$1(fullname) {
|
2069 | return function() {
|
2070 | this.removeAttributeNS(fullname.space, fullname.local);
|
2071 | };
|
2072 | }
|
2073 |
|
2074 | function attrConstant$1(name, value) {
|
2075 | return function() {
|
2076 | this.setAttribute(name, value);
|
2077 | };
|
2078 | }
|
2079 |
|
2080 | function attrConstantNS$1(fullname, value) {
|
2081 | return function() {
|
2082 | this.setAttributeNS(fullname.space, fullname.local, value);
|
2083 | };
|
2084 | }
|
2085 |
|
2086 | function attrFunction$1(name, value) {
|
2087 | return function() {
|
2088 | var v = value.apply(this, arguments);
|
2089 | if (v == null) this.removeAttribute(name);
|
2090 | else this.setAttribute(name, v);
|
2091 | };
|
2092 | }
|
2093 |
|
2094 | function attrFunctionNS$1(fullname, value) {
|
2095 | return function() {
|
2096 | var v = value.apply(this, arguments);
|
2097 | if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
|
2098 | else this.setAttributeNS(fullname.space, fullname.local, v);
|
2099 | };
|
2100 | }
|
2101 |
|
2102 | function selection_attr(name, value) {
|
2103 | var fullname = namespace(name);
|
2104 |
|
2105 | if (arguments.length < 2) {
|
2106 | var node = this.node();
|
2107 | return fullname.local
|
2108 | ? node.getAttributeNS(fullname.space, fullname.local)
|
2109 | : node.getAttribute(fullname);
|
2110 | }
|
2111 |
|
2112 | return this.each((value == null
|
2113 | ? (fullname.local ? attrRemoveNS$1 : attrRemove$1) : (typeof value === "function"
|
2114 | ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)
|
2115 | : (fullname.local ? attrConstantNS$1 : attrConstant$1)))(fullname, value));
|
2116 | }
|
2117 |
|
2118 | function defaultView(node) {
|
2119 | return (node.ownerDocument && node.ownerDocument.defaultView)
|
2120 | || (node.document && node)
|
2121 | || node.defaultView;
|
2122 | }
|
2123 |
|
2124 | function styleRemove$1(name) {
|
2125 | return function() {
|
2126 | this.style.removeProperty(name);
|
2127 | };
|
2128 | }
|
2129 |
|
2130 | function styleConstant$1(name, value, priority) {
|
2131 | return function() {
|
2132 | this.style.setProperty(name, value, priority);
|
2133 | };
|
2134 | }
|
2135 |
|
2136 | function styleFunction$1(name, value, priority) {
|
2137 | return function() {
|
2138 | var v = value.apply(this, arguments);
|
2139 | if (v == null) this.style.removeProperty(name);
|
2140 | else this.style.setProperty(name, v, priority);
|
2141 | };
|
2142 | }
|
2143 |
|
2144 | function selection_style(name, value, priority) {
|
2145 | return arguments.length > 1
|
2146 | ? this.each((value == null
|
2147 | ? styleRemove$1 : typeof value === "function"
|
2148 | ? styleFunction$1
|
2149 | : styleConstant$1)(name, value, priority == null ? "" : priority))
|
2150 | : styleValue(this.node(), name);
|
2151 | }
|
2152 |
|
2153 | function styleValue(node, name) {
|
2154 | return node.style.getPropertyValue(name)
|
2155 | || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
|
2156 | }
|
2157 |
|
2158 | function propertyRemove(name) {
|
2159 | return function() {
|
2160 | delete this[name];
|
2161 | };
|
2162 | }
|
2163 |
|
2164 | function propertyConstant(name, value) {
|
2165 | return function() {
|
2166 | this[name] = value;
|
2167 | };
|
2168 | }
|
2169 |
|
2170 | function propertyFunction(name, value) {
|
2171 | return function() {
|
2172 | var v = value.apply(this, arguments);
|
2173 | if (v == null) delete this[name];
|
2174 | else this[name] = v;
|
2175 | };
|
2176 | }
|
2177 |
|
2178 | function selection_property(name, value) {
|
2179 | return arguments.length > 1
|
2180 | ? this.each((value == null
|
2181 | ? propertyRemove : typeof value === "function"
|
2182 | ? propertyFunction
|
2183 | : propertyConstant)(name, value))
|
2184 | : this.node()[name];
|
2185 | }
|
2186 |
|
2187 | function classArray(string) {
|
2188 | return string.trim().split(/^|\s+/);
|
2189 | }
|
2190 |
|
2191 | function classList(node) {
|
2192 | return node.classList || new ClassList(node);
|
2193 | }
|
2194 |
|
2195 | function ClassList(node) {
|
2196 | this._node = node;
|
2197 | this._names = classArray(node.getAttribute("class") || "");
|
2198 | }
|
2199 |
|
2200 | ClassList.prototype = {
|
2201 | add: function(name) {
|
2202 | var i = this._names.indexOf(name);
|
2203 | if (i < 0) {
|
2204 | this._names.push(name);
|
2205 | this._node.setAttribute("class", this._names.join(" "));
|
2206 | }
|
2207 | },
|
2208 | remove: function(name) {
|
2209 | var i = this._names.indexOf(name);
|
2210 | if (i >= 0) {
|
2211 | this._names.splice(i, 1);
|
2212 | this._node.setAttribute("class", this._names.join(" "));
|
2213 | }
|
2214 | },
|
2215 | contains: function(name) {
|
2216 | return this._names.indexOf(name) >= 0;
|
2217 | }
|
2218 | };
|
2219 |
|
2220 | function classedAdd(node, names) {
|
2221 | var list = classList(node), i = -1, n = names.length;
|
2222 | while (++i < n) list.add(names[i]);
|
2223 | }
|
2224 |
|
2225 | function classedRemove(node, names) {
|
2226 | var list = classList(node), i = -1, n = names.length;
|
2227 | while (++i < n) list.remove(names[i]);
|
2228 | }
|
2229 |
|
2230 | function classedTrue(names) {
|
2231 | return function() {
|
2232 | classedAdd(this, names);
|
2233 | };
|
2234 | }
|
2235 |
|
2236 | function classedFalse(names) {
|
2237 | return function() {
|
2238 | classedRemove(this, names);
|
2239 | };
|
2240 | }
|
2241 |
|
2242 | function classedFunction(names, value) {
|
2243 | return function() {
|
2244 | (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
|
2245 | };
|
2246 | }
|
2247 |
|
2248 | function selection_classed(name, value) {
|
2249 | var names = classArray(name + "");
|
2250 |
|
2251 | if (arguments.length < 2) {
|
2252 | var list = classList(this.node()), i = -1, n = names.length;
|
2253 | while (++i < n) if (!list.contains(names[i])) return false;
|
2254 | return true;
|
2255 | }
|
2256 |
|
2257 | return this.each((typeof value === "function"
|
2258 | ? classedFunction : value
|
2259 | ? classedTrue
|
2260 | : classedFalse)(names, value));
|
2261 | }
|
2262 |
|
2263 | function textRemove() {
|
2264 | this.textContent = "";
|
2265 | }
|
2266 |
|
2267 | function textConstant$1(value) {
|
2268 | return function() {
|
2269 | this.textContent = value;
|
2270 | };
|
2271 | }
|
2272 |
|
2273 | function textFunction$1(value) {
|
2274 | return function() {
|
2275 | var v = value.apply(this, arguments);
|
2276 | this.textContent = v == null ? "" : v;
|
2277 | };
|
2278 | }
|
2279 |
|
2280 | function selection_text(value) {
|
2281 | return arguments.length
|
2282 | ? this.each(value == null
|
2283 | ? textRemove : (typeof value === "function"
|
2284 | ? textFunction$1
|
2285 | : textConstant$1)(value))
|
2286 | : this.node().textContent;
|
2287 | }
|
2288 |
|
2289 | function htmlRemove() {
|
2290 | this.innerHTML = "";
|
2291 | }
|
2292 |
|
2293 | function htmlConstant(value) {
|
2294 | return function() {
|
2295 | this.innerHTML = value;
|
2296 | };
|
2297 | }
|
2298 |
|
2299 | function htmlFunction(value) {
|
2300 | return function() {
|
2301 | var v = value.apply(this, arguments);
|
2302 | this.innerHTML = v == null ? "" : v;
|
2303 | };
|
2304 | }
|
2305 |
|
2306 | function selection_html(value) {
|
2307 | return arguments.length
|
2308 | ? this.each(value == null
|
2309 | ? htmlRemove : (typeof value === "function"
|
2310 | ? htmlFunction
|
2311 | : htmlConstant)(value))
|
2312 | : this.node().innerHTML;
|
2313 | }
|
2314 |
|
2315 | function raise() {
|
2316 | if (this.nextSibling) this.parentNode.appendChild(this);
|
2317 | }
|
2318 |
|
2319 | function selection_raise() {
|
2320 | return this.each(raise);
|
2321 | }
|
2322 |
|
2323 | function lower() {
|
2324 | if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
|
2325 | }
|
2326 |
|
2327 | function selection_lower() {
|
2328 | return this.each(lower);
|
2329 | }
|
2330 |
|
2331 | function selection_append(name) {
|
2332 | var create = typeof name === "function" ? name : creator(name);
|
2333 | return this.select(function() {
|
2334 | return this.appendChild(create.apply(this, arguments));
|
2335 | });
|
2336 | }
|
2337 |
|
2338 | function constantNull() {
|
2339 | return null;
|
2340 | }
|
2341 |
|
2342 | function selection_insert(name, before) {
|
2343 | var create = typeof name === "function" ? name : creator(name),
|
2344 | select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
|
2345 | return this.select(function() {
|
2346 | return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
|
2347 | });
|
2348 | }
|
2349 |
|
2350 | function remove() {
|
2351 | var parent = this.parentNode;
|
2352 | if (parent) parent.removeChild(this);
|
2353 | }
|
2354 |
|
2355 | function selection_remove() {
|
2356 | return this.each(remove);
|
2357 | }
|
2358 |
|
2359 | function selection_cloneShallow() {
|
2360 | var clone = this.cloneNode(false), parent = this.parentNode;
|
2361 | return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
|
2362 | }
|
2363 |
|
2364 | function selection_cloneDeep() {
|
2365 | var clone = this.cloneNode(true), parent = this.parentNode;
|
2366 | return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
|
2367 | }
|
2368 |
|
2369 | function selection_clone(deep) {
|
2370 | return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
|
2371 | }
|
2372 |
|
2373 | function selection_datum(value) {
|
2374 | return arguments.length
|
2375 | ? this.property("__data__", value)
|
2376 | : this.node().__data__;
|
2377 | }
|
2378 |
|
2379 | function contextListener(listener) {
|
2380 | return function(event) {
|
2381 | listener.call(this, event, this.__data__);
|
2382 | };
|
2383 | }
|
2384 |
|
2385 | function parseTypenames(typenames) {
|
2386 | return typenames.trim().split(/^|\s+/).map(function(t) {
|
2387 | var name = "", i = t.indexOf(".");
|
2388 | if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
2389 | return {type: t, name: name};
|
2390 | });
|
2391 | }
|
2392 |
|
2393 | function onRemove(typename) {
|
2394 | return function() {
|
2395 | var on = this.__on;
|
2396 | if (!on) return;
|
2397 | for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
|
2398 | if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
|
2399 | this.removeEventListener(o.type, o.listener, o.options);
|
2400 | } else {
|
2401 | on[++i] = o;
|
2402 | }
|
2403 | }
|
2404 | if (++i) on.length = i;
|
2405 | else delete this.__on;
|
2406 | };
|
2407 | }
|
2408 |
|
2409 | function onAdd(typename, value, options) {
|
2410 | return function() {
|
2411 | var on = this.__on, o, listener = contextListener(value);
|
2412 | if (on) for (var j = 0, m = on.length; j < m; ++j) {
|
2413 | if ((o = on[j]).type === typename.type && o.name === typename.name) {
|
2414 | this.removeEventListener(o.type, o.listener, o.options);
|
2415 | this.addEventListener(o.type, o.listener = listener, o.options = options);
|
2416 | o.value = value;
|
2417 | return;
|
2418 | }
|
2419 | }
|
2420 | this.addEventListener(typename.type, listener, options);
|
2421 | o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options};
|
2422 | if (!on) this.__on = [o];
|
2423 | else on.push(o);
|
2424 | };
|
2425 | }
|
2426 |
|
2427 | function selection_on(typename, value, options) {
|
2428 | var typenames = parseTypenames(typename + ""), i, n = typenames.length, t;
|
2429 |
|
2430 | if (arguments.length < 2) {
|
2431 | var on = this.node().__on;
|
2432 | if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
|
2433 | for (i = 0, o = on[j]; i < n; ++i) {
|
2434 | if ((t = typenames[i]).type === o.type && t.name === o.name) {
|
2435 | return o.value;
|
2436 | }
|
2437 | }
|
2438 | }
|
2439 | return;
|
2440 | }
|
2441 |
|
2442 | on = value ? onAdd : onRemove;
|
2443 | for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options));
|
2444 | return this;
|
2445 | }
|
2446 |
|
2447 | function dispatchEvent(node, type, params) {
|
2448 | var window = defaultView(node),
|
2449 | event = window.CustomEvent;
|
2450 |
|
2451 | if (typeof event === "function") {
|
2452 | event = new event(type, params);
|
2453 | } else {
|
2454 | event = window.document.createEvent("Event");
|
2455 | if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
|
2456 | else event.initEvent(type, false, false);
|
2457 | }
|
2458 |
|
2459 | node.dispatchEvent(event);
|
2460 | }
|
2461 |
|
2462 | function dispatchConstant(type, params) {
|
2463 | return function() {
|
2464 | return dispatchEvent(this, type, params);
|
2465 | };
|
2466 | }
|
2467 |
|
2468 | function dispatchFunction(type, params) {
|
2469 | return function() {
|
2470 | return dispatchEvent(this, type, params.apply(this, arguments));
|
2471 | };
|
2472 | }
|
2473 |
|
2474 | function selection_dispatch(type, params) {
|
2475 | return this.each((typeof params === "function"
|
2476 | ? dispatchFunction
|
2477 | : dispatchConstant)(type, params));
|
2478 | }
|
2479 |
|
2480 | function* selection_iterator() {
|
2481 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
2482 | for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
|
2483 | if (node = group[i]) yield node;
|
2484 | }
|
2485 | }
|
2486 | }
|
2487 |
|
2488 | var root$1 = [null];
|
2489 |
|
2490 | function Selection$1(groups, parents) {
|
2491 | this._groups = groups;
|
2492 | this._parents = parents;
|
2493 | }
|
2494 |
|
2495 | function selection() {
|
2496 | return new Selection$1([[document.documentElement]], root$1);
|
2497 | }
|
2498 |
|
2499 | function selection_selection() {
|
2500 | return this;
|
2501 | }
|
2502 |
|
2503 | Selection$1.prototype = selection.prototype = {
|
2504 | constructor: Selection$1,
|
2505 | select: selection_select,
|
2506 | selectAll: selection_selectAll,
|
2507 | selectChild: selection_selectChild,
|
2508 | selectChildren: selection_selectChildren,
|
2509 | filter: selection_filter,
|
2510 | data: selection_data,
|
2511 | enter: selection_enter,
|
2512 | exit: selection_exit,
|
2513 | join: selection_join,
|
2514 | merge: selection_merge,
|
2515 | selection: selection_selection,
|
2516 | order: selection_order,
|
2517 | sort: selection_sort,
|
2518 | call: selection_call,
|
2519 | nodes: selection_nodes,
|
2520 | node: selection_node,
|
2521 | size: selection_size,
|
2522 | empty: selection_empty,
|
2523 | each: selection_each,
|
2524 | attr: selection_attr,
|
2525 | style: selection_style,
|
2526 | property: selection_property,
|
2527 | classed: selection_classed,
|
2528 | text: selection_text,
|
2529 | html: selection_html,
|
2530 | raise: selection_raise,
|
2531 | lower: selection_lower,
|
2532 | append: selection_append,
|
2533 | insert: selection_insert,
|
2534 | remove: selection_remove,
|
2535 | clone: selection_clone,
|
2536 | datum: selection_datum,
|
2537 | on: selection_on,
|
2538 | dispatch: selection_dispatch,
|
2539 | [Symbol.iterator]: selection_iterator
|
2540 | };
|
2541 |
|
2542 | function select(selector) {
|
2543 | return typeof selector === "string"
|
2544 | ? new Selection$1([[document.querySelector(selector)]], [document.documentElement])
|
2545 | : new Selection$1([[selector]], root$1);
|
2546 | }
|
2547 |
|
2548 | function create$1(name) {
|
2549 | return select(creator(name).call(document.documentElement));
|
2550 | }
|
2551 |
|
2552 | var nextId = 0;
|
2553 |
|
2554 | function local$1() {
|
2555 | return new Local;
|
2556 | }
|
2557 |
|
2558 | function Local() {
|
2559 | this._ = "@" + (++nextId).toString(36);
|
2560 | }
|
2561 |
|
2562 | Local.prototype = local$1.prototype = {
|
2563 | constructor: Local,
|
2564 | get: function(node) {
|
2565 | var id = this._;
|
2566 | while (!(id in node)) if (!(node = node.parentNode)) return;
|
2567 | return node[id];
|
2568 | },
|
2569 | set: function(node, value) {
|
2570 | return node[this._] = value;
|
2571 | },
|
2572 | remove: function(node) {
|
2573 | return this._ in node && delete node[this._];
|
2574 | },
|
2575 | toString: function() {
|
2576 | return this._;
|
2577 | }
|
2578 | };
|
2579 |
|
2580 | function sourceEvent(event) {
|
2581 | let sourceEvent;
|
2582 | while (sourceEvent = event.sourceEvent) event = sourceEvent;
|
2583 | return event;
|
2584 | }
|
2585 |
|
2586 | function pointer(event, node) {
|
2587 | event = sourceEvent(event);
|
2588 | if (node === undefined) node = event.currentTarget;
|
2589 | if (node) {
|
2590 | var svg = node.ownerSVGElement || node;
|
2591 | if (svg.createSVGPoint) {
|
2592 | var point = svg.createSVGPoint();
|
2593 | point.x = event.clientX, point.y = event.clientY;
|
2594 | point = point.matrixTransform(node.getScreenCTM().inverse());
|
2595 | return [point.x, point.y];
|
2596 | }
|
2597 | if (node.getBoundingClientRect) {
|
2598 | var rect = node.getBoundingClientRect();
|
2599 | return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
|
2600 | }
|
2601 | }
|
2602 | return [event.pageX, event.pageY];
|
2603 | }
|
2604 |
|
2605 | function pointers(events, node) {
|
2606 | if (events.target) {
|
2607 | events = sourceEvent(events);
|
2608 | if (node === undefined) node = events.currentTarget;
|
2609 | events = events.touches || [events];
|
2610 | }
|
2611 | return Array.from(events, event => pointer(event, node));
|
2612 | }
|
2613 |
|
2614 | function selectAll(selector) {
|
2615 | return typeof selector === "string"
|
2616 | ? new Selection$1([document.querySelectorAll(selector)], [document.documentElement])
|
2617 | : new Selection$1([array$4(selector)], root$1);
|
2618 | }
|
2619 |
|
2620 |
|
2621 |
|
2622 | const nonpassive = {passive: false};
|
2623 | const nonpassivecapture = {capture: true, passive: false};
|
2624 |
|
2625 | function nopropagation$2(event) {
|
2626 | event.stopImmediatePropagation();
|
2627 | }
|
2628 |
|
2629 | function noevent$2(event) {
|
2630 | event.preventDefault();
|
2631 | event.stopImmediatePropagation();
|
2632 | }
|
2633 |
|
2634 | function dragDisable(view) {
|
2635 | var root = view.document.documentElement,
|
2636 | selection = select(view).on("dragstart.drag", noevent$2, nonpassivecapture);
|
2637 | if ("onselectstart" in root) {
|
2638 | selection.on("selectstart.drag", noevent$2, nonpassivecapture);
|
2639 | } else {
|
2640 | root.__noselect = root.style.MozUserSelect;
|
2641 | root.style.MozUserSelect = "none";
|
2642 | }
|
2643 | }
|
2644 |
|
2645 | function yesdrag(view, noclick) {
|
2646 | var root = view.document.documentElement,
|
2647 | selection = select(view).on("dragstart.drag", null);
|
2648 | if (noclick) {
|
2649 | selection.on("click.drag", noevent$2, nonpassivecapture);
|
2650 | setTimeout(function() { selection.on("click.drag", null); }, 0);
|
2651 | }
|
2652 | if ("onselectstart" in root) {
|
2653 | selection.on("selectstart.drag", null);
|
2654 | } else {
|
2655 | root.style.MozUserSelect = root.__noselect;
|
2656 | delete root.__noselect;
|
2657 | }
|
2658 | }
|
2659 |
|
2660 | var constant$9 = x => () => x;
|
2661 |
|
2662 | function DragEvent(type, {
|
2663 | sourceEvent,
|
2664 | subject,
|
2665 | target,
|
2666 | identifier,
|
2667 | active,
|
2668 | x, y, dx, dy,
|
2669 | dispatch
|
2670 | }) {
|
2671 | Object.defineProperties(this, {
|
2672 | type: {value: type, enumerable: true, configurable: true},
|
2673 | sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
|
2674 | subject: {value: subject, enumerable: true, configurable: true},
|
2675 | target: {value: target, enumerable: true, configurable: true},
|
2676 | identifier: {value: identifier, enumerable: true, configurable: true},
|
2677 | active: {value: active, enumerable: true, configurable: true},
|
2678 | x: {value: x, enumerable: true, configurable: true},
|
2679 | y: {value: y, enumerable: true, configurable: true},
|
2680 | dx: {value: dx, enumerable: true, configurable: true},
|
2681 | dy: {value: dy, enumerable: true, configurable: true},
|
2682 | _: {value: dispatch}
|
2683 | });
|
2684 | }
|
2685 |
|
2686 | DragEvent.prototype.on = function() {
|
2687 | var value = this._.on.apply(this._, arguments);
|
2688 | return value === this._ ? this : value;
|
2689 | };
|
2690 |
|
2691 |
|
2692 | function defaultFilter$2(event) {
|
2693 | return !event.ctrlKey && !event.button;
|
2694 | }
|
2695 |
|
2696 | function defaultContainer() {
|
2697 | return this.parentNode;
|
2698 | }
|
2699 |
|
2700 | function defaultSubject(event, d) {
|
2701 | return d == null ? {x: event.x, y: event.y} : d;
|
2702 | }
|
2703 |
|
2704 | function defaultTouchable$2() {
|
2705 | return navigator.maxTouchPoints || ("ontouchstart" in this);
|
2706 | }
|
2707 |
|
2708 | function drag() {
|
2709 | var filter = defaultFilter$2,
|
2710 | container = defaultContainer,
|
2711 | subject = defaultSubject,
|
2712 | touchable = defaultTouchable$2,
|
2713 | gestures = {},
|
2714 | listeners = dispatch("start", "drag", "end"),
|
2715 | active = 0,
|
2716 | mousedownx,
|
2717 | mousedowny,
|
2718 | mousemoving,
|
2719 | touchending,
|
2720 | clickDistance2 = 0;
|
2721 |
|
2722 | function drag(selection) {
|
2723 | selection
|
2724 | .on("mousedown.drag", mousedowned)
|
2725 | .filter(touchable)
|
2726 | .on("touchstart.drag", touchstarted)
|
2727 | .on("touchmove.drag", touchmoved, nonpassive)
|
2728 | .on("touchend.drag touchcancel.drag", touchended)
|
2729 | .style("touch-action", "none")
|
2730 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
2731 | }
|
2732 |
|
2733 | function mousedowned(event, d) {
|
2734 | if (touchending || !filter.call(this, event, d)) return;
|
2735 | var gesture = beforestart(this, container.call(this, event, d), event, d, "mouse");
|
2736 | if (!gesture) return;
|
2737 | select(event.view)
|
2738 | .on("mousemove.drag", mousemoved, nonpassivecapture)
|
2739 | .on("mouseup.drag", mouseupped, nonpassivecapture);
|
2740 | dragDisable(event.view);
|
2741 | nopropagation$2(event);
|
2742 | mousemoving = false;
|
2743 | mousedownx = event.clientX;
|
2744 | mousedowny = event.clientY;
|
2745 | gesture("start", event);
|
2746 | }
|
2747 |
|
2748 | function mousemoved(event) {
|
2749 | noevent$2(event);
|
2750 | if (!mousemoving) {
|
2751 | var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
|
2752 | mousemoving = dx * dx + dy * dy > clickDistance2;
|
2753 | }
|
2754 | gestures.mouse("drag", event);
|
2755 | }
|
2756 |
|
2757 | function mouseupped(event) {
|
2758 | select(event.view).on("mousemove.drag mouseup.drag", null);
|
2759 | yesdrag(event.view, mousemoving);
|
2760 | noevent$2(event);
|
2761 | gestures.mouse("end", event);
|
2762 | }
|
2763 |
|
2764 | function touchstarted(event, d) {
|
2765 | if (!filter.call(this, event, d)) return;
|
2766 | var touches = event.changedTouches,
|
2767 | c = container.call(this, event, d),
|
2768 | n = touches.length, i, gesture;
|
2769 |
|
2770 | for (i = 0; i < n; ++i) {
|
2771 | if (gesture = beforestart(this, c, event, d, touches[i].identifier, touches[i])) {
|
2772 | nopropagation$2(event);
|
2773 | gesture("start", event, touches[i]);
|
2774 | }
|
2775 | }
|
2776 | }
|
2777 |
|
2778 | function touchmoved(event) {
|
2779 | var touches = event.changedTouches,
|
2780 | n = touches.length, i, gesture;
|
2781 |
|
2782 | for (i = 0; i < n; ++i) {
|
2783 | if (gesture = gestures[touches[i].identifier]) {
|
2784 | noevent$2(event);
|
2785 | gesture("drag", event, touches[i]);
|
2786 | }
|
2787 | }
|
2788 | }
|
2789 |
|
2790 | function touchended(event) {
|
2791 | var touches = event.changedTouches,
|
2792 | n = touches.length, i, gesture;
|
2793 |
|
2794 | if (touchending) clearTimeout(touchending);
|
2795 | touchending = setTimeout(function() { touchending = null; }, 500);
|
2796 | for (i = 0; i < n; ++i) {
|
2797 | if (gesture = gestures[touches[i].identifier]) {
|
2798 | nopropagation$2(event);
|
2799 | gesture("end", event, touches[i]);
|
2800 | }
|
2801 | }
|
2802 | }
|
2803 |
|
2804 | function beforestart(that, container, event, d, identifier, touch) {
|
2805 | var dispatch = listeners.copy(),
|
2806 | p = pointer(touch || event, container), dx, dy,
|
2807 | s;
|
2808 |
|
2809 | if ((s = subject.call(that, new DragEvent("beforestart", {
|
2810 | sourceEvent: event,
|
2811 | target: drag,
|
2812 | identifier,
|
2813 | active,
|
2814 | x: p[0],
|
2815 | y: p[1],
|
2816 | dx: 0,
|
2817 | dy: 0,
|
2818 | dispatch
|
2819 | }), d)) == null) return;
|
2820 |
|
2821 | dx = s.x - p[0] || 0;
|
2822 | dy = s.y - p[1] || 0;
|
2823 |
|
2824 | return function gesture(type, event, touch) {
|
2825 | var p0 = p, n;
|
2826 | switch (type) {
|
2827 | case "start": gestures[identifier] = gesture, n = active++; break;
|
2828 | case "end": delete gestures[identifier], --active;
|
2829 | case "drag": p = pointer(touch || event, container), n = active; break;
|
2830 | }
|
2831 | dispatch.call(
|
2832 | type,
|
2833 | that,
|
2834 | new DragEvent(type, {
|
2835 | sourceEvent: event,
|
2836 | subject: s,
|
2837 | target: drag,
|
2838 | identifier,
|
2839 | active: n,
|
2840 | x: p[0] + dx,
|
2841 | y: p[1] + dy,
|
2842 | dx: p[0] - p0[0],
|
2843 | dy: p[1] - p0[1],
|
2844 | dispatch
|
2845 | }),
|
2846 | d
|
2847 | );
|
2848 | };
|
2849 | }
|
2850 |
|
2851 | drag.filter = function(_) {
|
2852 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), drag) : filter;
|
2853 | };
|
2854 |
|
2855 | drag.container = function(_) {
|
2856 | return arguments.length ? (container = typeof _ === "function" ? _ : constant$9(_), drag) : container;
|
2857 | };
|
2858 |
|
2859 | drag.subject = function(_) {
|
2860 | return arguments.length ? (subject = typeof _ === "function" ? _ : constant$9(_), drag) : subject;
|
2861 | };
|
2862 |
|
2863 | drag.touchable = function(_) {
|
2864 | return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$9(!!_), drag) : touchable;
|
2865 | };
|
2866 |
|
2867 | drag.on = function() {
|
2868 | var value = listeners.on.apply(listeners, arguments);
|
2869 | return value === listeners ? drag : value;
|
2870 | };
|
2871 |
|
2872 | drag.clickDistance = function(_) {
|
2873 | return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
|
2874 | };
|
2875 |
|
2876 | return drag;
|
2877 | }
|
2878 |
|
2879 | function define(constructor, factory, prototype) {
|
2880 | constructor.prototype = factory.prototype = prototype;
|
2881 | prototype.constructor = constructor;
|
2882 | }
|
2883 |
|
2884 | function extend(parent, definition) {
|
2885 | var prototype = Object.create(parent.prototype);
|
2886 | for (var key in definition) prototype[key] = definition[key];
|
2887 | return prototype;
|
2888 | }
|
2889 |
|
2890 | function Color() {}
|
2891 |
|
2892 | var darker = 0.7;
|
2893 | var brighter = 1 / darker;
|
2894 |
|
2895 | var reI = "\\s*([+-]?\\d+)\\s*",
|
2896 | reN = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",
|
2897 | reP = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
|
2898 | reHex = /^#([0-9a-f]{3,8})$/,
|
2899 | reRgbInteger = new RegExp(`^rgb\\(${reI},${reI},${reI}\\)$`),
|
2900 | reRgbPercent = new RegExp(`^rgb\\(${reP},${reP},${reP}\\)$`),
|
2901 | reRgbaInteger = new RegExp(`^rgba\\(${reI},${reI},${reI},${reN}\\)$`),
|
2902 | reRgbaPercent = new RegExp(`^rgba\\(${reP},${reP},${reP},${reN}\\)$`),
|
2903 | reHslPercent = new RegExp(`^hsl\\(${reN},${reP},${reP}\\)$`),
|
2904 | reHslaPercent = new RegExp(`^hsla\\(${reN},${reP},${reP},${reN}\\)$`);
|
2905 |
|
2906 | var named = {
|
2907 | aliceblue: 0xf0f8ff,
|
2908 | antiquewhite: 0xfaebd7,
|
2909 | aqua: 0x00ffff,
|
2910 | aquamarine: 0x7fffd4,
|
2911 | azure: 0xf0ffff,
|
2912 | beige: 0xf5f5dc,
|
2913 | bisque: 0xffe4c4,
|
2914 | black: 0x000000,
|
2915 | blanchedalmond: 0xffebcd,
|
2916 | blue: 0x0000ff,
|
2917 | blueviolet: 0x8a2be2,
|
2918 | brown: 0xa52a2a,
|
2919 | burlywood: 0xdeb887,
|
2920 | cadetblue: 0x5f9ea0,
|
2921 | chartreuse: 0x7fff00,
|
2922 | chocolate: 0xd2691e,
|
2923 | coral: 0xff7f50,
|
2924 | cornflowerblue: 0x6495ed,
|
2925 | cornsilk: 0xfff8dc,
|
2926 | crimson: 0xdc143c,
|
2927 | cyan: 0x00ffff,
|
2928 | darkblue: 0x00008b,
|
2929 | darkcyan: 0x008b8b,
|
2930 | darkgoldenrod: 0xb8860b,
|
2931 | darkgray: 0xa9a9a9,
|
2932 | darkgreen: 0x006400,
|
2933 | darkgrey: 0xa9a9a9,
|
2934 | darkkhaki: 0xbdb76b,
|
2935 | darkmagenta: 0x8b008b,
|
2936 | darkolivegreen: 0x556b2f,
|
2937 | darkorange: 0xff8c00,
|
2938 | darkorchid: 0x9932cc,
|
2939 | darkred: 0x8b0000,
|
2940 | darksalmon: 0xe9967a,
|
2941 | darkseagreen: 0x8fbc8f,
|
2942 | darkslateblue: 0x483d8b,
|
2943 | darkslategray: 0x2f4f4f,
|
2944 | darkslategrey: 0x2f4f4f,
|
2945 | darkturquoise: 0x00ced1,
|
2946 | darkviolet: 0x9400d3,
|
2947 | deeppink: 0xff1493,
|
2948 | deepskyblue: 0x00bfff,
|
2949 | dimgray: 0x696969,
|
2950 | dimgrey: 0x696969,
|
2951 | dodgerblue: 0x1e90ff,
|
2952 | firebrick: 0xb22222,
|
2953 | floralwhite: 0xfffaf0,
|
2954 | forestgreen: 0x228b22,
|
2955 | fuchsia: 0xff00ff,
|
2956 | gainsboro: 0xdcdcdc,
|
2957 | ghostwhite: 0xf8f8ff,
|
2958 | gold: 0xffd700,
|
2959 | goldenrod: 0xdaa520,
|
2960 | gray: 0x808080,
|
2961 | green: 0x008000,
|
2962 | greenyellow: 0xadff2f,
|
2963 | grey: 0x808080,
|
2964 | honeydew: 0xf0fff0,
|
2965 | hotpink: 0xff69b4,
|
2966 | indianred: 0xcd5c5c,
|
2967 | indigo: 0x4b0082,
|
2968 | ivory: 0xfffff0,
|
2969 | khaki: 0xf0e68c,
|
2970 | lavender: 0xe6e6fa,
|
2971 | lavenderblush: 0xfff0f5,
|
2972 | lawngreen: 0x7cfc00,
|
2973 | lemonchiffon: 0xfffacd,
|
2974 | lightblue: 0xadd8e6,
|
2975 | lightcoral: 0xf08080,
|
2976 | lightcyan: 0xe0ffff,
|
2977 | lightgoldenrodyellow: 0xfafad2,
|
2978 | lightgray: 0xd3d3d3,
|
2979 | lightgreen: 0x90ee90,
|
2980 | lightgrey: 0xd3d3d3,
|
2981 | lightpink: 0xffb6c1,
|
2982 | lightsalmon: 0xffa07a,
|
2983 | lightseagreen: 0x20b2aa,
|
2984 | lightskyblue: 0x87cefa,
|
2985 | lightslategray: 0x778899,
|
2986 | lightslategrey: 0x778899,
|
2987 | lightsteelblue: 0xb0c4de,
|
2988 | lightyellow: 0xffffe0,
|
2989 | lime: 0x00ff00,
|
2990 | limegreen: 0x32cd32,
|
2991 | linen: 0xfaf0e6,
|
2992 | magenta: 0xff00ff,
|
2993 | maroon: 0x800000,
|
2994 | mediumaquamarine: 0x66cdaa,
|
2995 | mediumblue: 0x0000cd,
|
2996 | mediumorchid: 0xba55d3,
|
2997 | mediumpurple: 0x9370db,
|
2998 | mediumseagreen: 0x3cb371,
|
2999 | mediumslateblue: 0x7b68ee,
|
3000 | mediumspringgreen: 0x00fa9a,
|
3001 | mediumturquoise: 0x48d1cc,
|
3002 | mediumvioletred: 0xc71585,
|
3003 | midnightblue: 0x191970,
|
3004 | mintcream: 0xf5fffa,
|
3005 | mistyrose: 0xffe4e1,
|
3006 | moccasin: 0xffe4b5,
|
3007 | navajowhite: 0xffdead,
|
3008 | navy: 0x000080,
|
3009 | oldlace: 0xfdf5e6,
|
3010 | olive: 0x808000,
|
3011 | olivedrab: 0x6b8e23,
|
3012 | orange: 0xffa500,
|
3013 | orangered: 0xff4500,
|
3014 | orchid: 0xda70d6,
|
3015 | palegoldenrod: 0xeee8aa,
|
3016 | palegreen: 0x98fb98,
|
3017 | paleturquoise: 0xafeeee,
|
3018 | palevioletred: 0xdb7093,
|
3019 | papayawhip: 0xffefd5,
|
3020 | peachpuff: 0xffdab9,
|
3021 | peru: 0xcd853f,
|
3022 | pink: 0xffc0cb,
|
3023 | plum: 0xdda0dd,
|
3024 | powderblue: 0xb0e0e6,
|
3025 | purple: 0x800080,
|
3026 | rebeccapurple: 0x663399,
|
3027 | red: 0xff0000,
|
3028 | rosybrown: 0xbc8f8f,
|
3029 | royalblue: 0x4169e1,
|
3030 | saddlebrown: 0x8b4513,
|
3031 | salmon: 0xfa8072,
|
3032 | sandybrown: 0xf4a460,
|
3033 | seagreen: 0x2e8b57,
|
3034 | seashell: 0xfff5ee,
|
3035 | sienna: 0xa0522d,
|
3036 | silver: 0xc0c0c0,
|
3037 | skyblue: 0x87ceeb,
|
3038 | slateblue: 0x6a5acd,
|
3039 | slategray: 0x708090,
|
3040 | slategrey: 0x708090,
|
3041 | snow: 0xfffafa,
|
3042 | springgreen: 0x00ff7f,
|
3043 | steelblue: 0x4682b4,
|
3044 | tan: 0xd2b48c,
|
3045 | teal: 0x008080,
|
3046 | thistle: 0xd8bfd8,
|
3047 | tomato: 0xff6347,
|
3048 | turquoise: 0x40e0d0,
|
3049 | violet: 0xee82ee,
|
3050 | wheat: 0xf5deb3,
|
3051 | white: 0xffffff,
|
3052 | whitesmoke: 0xf5f5f5,
|
3053 | yellow: 0xffff00,
|
3054 | yellowgreen: 0x9acd32
|
3055 | };
|
3056 |
|
3057 | define(Color, color, {
|
3058 | copy(channels) {
|
3059 | return Object.assign(new this.constructor, this, channels);
|
3060 | },
|
3061 | displayable() {
|
3062 | return this.rgb().displayable();
|
3063 | },
|
3064 | hex: color_formatHex,
|
3065 | formatHex: color_formatHex,
|
3066 | formatHex8: color_formatHex8,
|
3067 | formatHsl: color_formatHsl,
|
3068 | formatRgb: color_formatRgb,
|
3069 | toString: color_formatRgb
|
3070 | });
|
3071 |
|
3072 | function color_formatHex() {
|
3073 | return this.rgb().formatHex();
|
3074 | }
|
3075 |
|
3076 | function color_formatHex8() {
|
3077 | return this.rgb().formatHex8();
|
3078 | }
|
3079 |
|
3080 | function color_formatHsl() {
|
3081 | return hslConvert(this).formatHsl();
|
3082 | }
|
3083 |
|
3084 | function color_formatRgb() {
|
3085 | return this.rgb().formatRgb();
|
3086 | }
|
3087 |
|
3088 | function color(format) {
|
3089 | var m, l;
|
3090 | format = (format + "").trim().toLowerCase();
|
3091 | return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m)
|
3092 | : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)
|
3093 | : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff)
|
3094 | : l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff)
|
3095 | : null)
|
3096 | : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1)
|
3097 | : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1)
|
3098 | : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4])
|
3099 | : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4])
|
3100 | : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1)
|
3101 | : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4])
|
3102 | : named.hasOwnProperty(format) ? rgbn(named[format])
|
3103 | : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
|
3104 | : null;
|
3105 | }
|
3106 |
|
3107 | function rgbn(n) {
|
3108 | return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
|
3109 | }
|
3110 |
|
3111 | function rgba(r, g, b, a) {
|
3112 | if (a <= 0) r = g = b = NaN;
|
3113 | return new Rgb(r, g, b, a);
|
3114 | }
|
3115 |
|
3116 | function rgbConvert(o) {
|
3117 | if (!(o instanceof Color)) o = color(o);
|
3118 | if (!o) return new Rgb;
|
3119 | o = o.rgb();
|
3120 | return new Rgb(o.r, o.g, o.b, o.opacity);
|
3121 | }
|
3122 |
|
3123 | function rgb(r, g, b, opacity) {
|
3124 | return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
|
3125 | }
|
3126 |
|
3127 | function Rgb(r, g, b, opacity) {
|
3128 | this.r = +r;
|
3129 | this.g = +g;
|
3130 | this.b = +b;
|
3131 | this.opacity = +opacity;
|
3132 | }
|
3133 |
|
3134 | define(Rgb, rgb, extend(Color, {
|
3135 | brighter(k) {
|
3136 | k = k == null ? brighter : Math.pow(brighter, k);
|
3137 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
3138 | },
|
3139 | darker(k) {
|
3140 | k = k == null ? darker : Math.pow(darker, k);
|
3141 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
3142 | },
|
3143 | rgb() {
|
3144 | return this;
|
3145 | },
|
3146 | clamp() {
|
3147 | return new Rgb(clampi(this.r), clampi(this.g), clampi(this.b), clampa(this.opacity));
|
3148 | },
|
3149 | displayable() {
|
3150 | return (-0.5 <= this.r && this.r < 255.5)
|
3151 | && (-0.5 <= this.g && this.g < 255.5)
|
3152 | && (-0.5 <= this.b && this.b < 255.5)
|
3153 | && (0 <= this.opacity && this.opacity <= 1);
|
3154 | },
|
3155 | hex: rgb_formatHex,
|
3156 | formatHex: rgb_formatHex,
|
3157 | formatHex8: rgb_formatHex8,
|
3158 | formatRgb: rgb_formatRgb,
|
3159 | toString: rgb_formatRgb
|
3160 | }));
|
3161 |
|
3162 | function rgb_formatHex() {
|
3163 | return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}`;
|
3164 | }
|
3165 |
|
3166 | function rgb_formatHex8() {
|
3167 | return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}${hex((isNaN(this.opacity) ? 1 : this.opacity) * 255)}`;
|
3168 | }
|
3169 |
|
3170 | function rgb_formatRgb() {
|
3171 | const a = clampa(this.opacity);
|
3172 | return `${a === 1 ? "rgb(" : "rgba("}${clampi(this.r)}, ${clampi(this.g)}, ${clampi(this.b)}${a === 1 ? ")" : `, ${a})`}`;
|
3173 | }
|
3174 |
|
3175 | function clampa(opacity) {
|
3176 | return isNaN(opacity) ? 1 : Math.max(0, Math.min(1, opacity));
|
3177 | }
|
3178 |
|
3179 | function clampi(value) {
|
3180 | return Math.max(0, Math.min(255, Math.round(value) || 0));
|
3181 | }
|
3182 |
|
3183 | function hex(value) {
|
3184 | value = clampi(value);
|
3185 | return (value < 16 ? "0" : "") + value.toString(16);
|
3186 | }
|
3187 |
|
3188 | function hsla(h, s, l, a) {
|
3189 | if (a <= 0) h = s = l = NaN;
|
3190 | else if (l <= 0 || l >= 1) h = s = NaN;
|
3191 | else if (s <= 0) h = NaN;
|
3192 | return new Hsl(h, s, l, a);
|
3193 | }
|
3194 |
|
3195 | function hslConvert(o) {
|
3196 | if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
|
3197 | if (!(o instanceof Color)) o = color(o);
|
3198 | if (!o) return new Hsl;
|
3199 | if (o instanceof Hsl) return o;
|
3200 | o = o.rgb();
|
3201 | var r = o.r / 255,
|
3202 | g = o.g / 255,
|
3203 | b = o.b / 255,
|
3204 | min = Math.min(r, g, b),
|
3205 | max = Math.max(r, g, b),
|
3206 | h = NaN,
|
3207 | s = max - min,
|
3208 | l = (max + min) / 2;
|
3209 | if (s) {
|
3210 | if (r === max) h = (g - b) / s + (g < b) * 6;
|
3211 | else if (g === max) h = (b - r) / s + 2;
|
3212 | else h = (r - g) / s + 4;
|
3213 | s /= l < 0.5 ? max + min : 2 - max - min;
|
3214 | h *= 60;
|
3215 | } else {
|
3216 | s = l > 0 && l < 1 ? 0 : h;
|
3217 | }
|
3218 | return new Hsl(h, s, l, o.opacity);
|
3219 | }
|
3220 |
|
3221 | function hsl$2(h, s, l, opacity) {
|
3222 | return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
|
3223 | }
|
3224 |
|
3225 | function Hsl(h, s, l, opacity) {
|
3226 | this.h = +h;
|
3227 | this.s = +s;
|
3228 | this.l = +l;
|
3229 | this.opacity = +opacity;
|
3230 | }
|
3231 |
|
3232 | define(Hsl, hsl$2, extend(Color, {
|
3233 | brighter(k) {
|
3234 | k = k == null ? brighter : Math.pow(brighter, k);
|
3235 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
3236 | },
|
3237 | darker(k) {
|
3238 | k = k == null ? darker : Math.pow(darker, k);
|
3239 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
3240 | },
|
3241 | rgb() {
|
3242 | var h = this.h % 360 + (this.h < 0) * 360,
|
3243 | s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
|
3244 | l = this.l,
|
3245 | m2 = l + (l < 0.5 ? l : 1 - l) * s,
|
3246 | m1 = 2 * l - m2;
|
3247 | return new Rgb(
|
3248 | hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
|
3249 | hsl2rgb(h, m1, m2),
|
3250 | hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
|
3251 | this.opacity
|
3252 | );
|
3253 | },
|
3254 | clamp() {
|
3255 | return new Hsl(clamph(this.h), clampt(this.s), clampt(this.l), clampa(this.opacity));
|
3256 | },
|
3257 | displayable() {
|
3258 | return (0 <= this.s && this.s <= 1 || isNaN(this.s))
|
3259 | && (0 <= this.l && this.l <= 1)
|
3260 | && (0 <= this.opacity && this.opacity <= 1);
|
3261 | },
|
3262 | formatHsl() {
|
3263 | const a = clampa(this.opacity);
|
3264 | return `${a === 1 ? "hsl(" : "hsla("}${clamph(this.h)}, ${clampt(this.s) * 100}%, ${clampt(this.l) * 100}%${a === 1 ? ")" : `, ${a})`}`;
|
3265 | }
|
3266 | }));
|
3267 |
|
3268 | function clamph(value) {
|
3269 | value = (value || 0) % 360;
|
3270 | return value < 0 ? value + 360 : value;
|
3271 | }
|
3272 |
|
3273 | function clampt(value) {
|
3274 | return Math.max(0, Math.min(1, value || 0));
|
3275 | }
|
3276 |
|
3277 |
|
3278 | function hsl2rgb(h, m1, m2) {
|
3279 | return (h < 60 ? m1 + (m2 - m1) * h / 60
|
3280 | : h < 180 ? m2
|
3281 | : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
|
3282 | : m1) * 255;
|
3283 | }
|
3284 |
|
3285 | const radians$1 = Math.PI / 180;
|
3286 | const degrees$2 = 180 / Math.PI;
|
3287 |
|
3288 |
|
3289 | const K = 18,
|
3290 | Xn = 0.96422,
|
3291 | Yn = 1,
|
3292 | Zn = 0.82521,
|
3293 | t0$1 = 4 / 29,
|
3294 | t1$1 = 6 / 29,
|
3295 | t2 = 3 * t1$1 * t1$1,
|
3296 | t3 = t1$1 * t1$1 * t1$1;
|
3297 |
|
3298 | function labConvert(o) {
|
3299 | if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
|
3300 | if (o instanceof Hcl) return hcl2lab(o);
|
3301 | if (!(o instanceof Rgb)) o = rgbConvert(o);
|
3302 | var r = rgb2lrgb(o.r),
|
3303 | g = rgb2lrgb(o.g),
|
3304 | b = rgb2lrgb(o.b),
|
3305 | y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
|
3306 | if (r === g && g === b) x = z = y; else {
|
3307 | x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
|
3308 | z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
|
3309 | }
|
3310 | return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
|
3311 | }
|
3312 |
|
3313 | function gray(l, opacity) {
|
3314 | return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
|
3315 | }
|
3316 |
|
3317 | function lab$1(l, a, b, opacity) {
|
3318 | return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
|
3319 | }
|
3320 |
|
3321 | function Lab(l, a, b, opacity) {
|
3322 | this.l = +l;
|
3323 | this.a = +a;
|
3324 | this.b = +b;
|
3325 | this.opacity = +opacity;
|
3326 | }
|
3327 |
|
3328 | define(Lab, lab$1, extend(Color, {
|
3329 | brighter(k) {
|
3330 | return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
|
3331 | },
|
3332 | darker(k) {
|
3333 | return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
|
3334 | },
|
3335 | rgb() {
|
3336 | var y = (this.l + 16) / 116,
|
3337 | x = isNaN(this.a) ? y : y + this.a / 500,
|
3338 | z = isNaN(this.b) ? y : y - this.b / 200;
|
3339 | x = Xn * lab2xyz(x);
|
3340 | y = Yn * lab2xyz(y);
|
3341 | z = Zn * lab2xyz(z);
|
3342 | return new Rgb(
|
3343 | lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
|
3344 | lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
|
3345 | lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
|
3346 | this.opacity
|
3347 | );
|
3348 | }
|
3349 | }));
|
3350 |
|
3351 | function xyz2lab(t) {
|
3352 | return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0$1;
|
3353 | }
|
3354 |
|
3355 | function lab2xyz(t) {
|
3356 | return t > t1$1 ? t * t * t : t2 * (t - t0$1);
|
3357 | }
|
3358 |
|
3359 | function lrgb2rgb(x) {
|
3360 | return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
|
3361 | }
|
3362 |
|
3363 | function rgb2lrgb(x) {
|
3364 | return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
|
3365 | }
|
3366 |
|
3367 | function hclConvert(o) {
|
3368 | if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
|
3369 | if (!(o instanceof Lab)) o = labConvert(o);
|
3370 | if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
|
3371 | var h = Math.atan2(o.b, o.a) * degrees$2;
|
3372 | return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
|
3373 | }
|
3374 |
|
3375 | function lch(l, c, h, opacity) {
|
3376 | return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
|
3377 | }
|
3378 |
|
3379 | function hcl$2(h, c, l, opacity) {
|
3380 | return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
|
3381 | }
|
3382 |
|
3383 | function Hcl(h, c, l, opacity) {
|
3384 | this.h = +h;
|
3385 | this.c = +c;
|
3386 | this.l = +l;
|
3387 | this.opacity = +opacity;
|
3388 | }
|
3389 |
|
3390 | function hcl2lab(o) {
|
3391 | if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
|
3392 | var h = o.h * radians$1;
|
3393 | return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
|
3394 | }
|
3395 |
|
3396 | define(Hcl, hcl$2, extend(Color, {
|
3397 | brighter(k) {
|
3398 | return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
|
3399 | },
|
3400 | darker(k) {
|
3401 | return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
|
3402 | },
|
3403 | rgb() {
|
3404 | return hcl2lab(this).rgb();
|
3405 | }
|
3406 | }));
|
3407 |
|
3408 | var A = -0.14861,
|
3409 | B$1 = +1.78277,
|
3410 | C = -0.29227,
|
3411 | D$1 = -0.90649,
|
3412 | E = +1.97294,
|
3413 | ED = E * D$1,
|
3414 | EB = E * B$1,
|
3415 | BC_DA = B$1 * C - D$1 * A;
|
3416 |
|
3417 | function cubehelixConvert(o) {
|
3418 | if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
|
3419 | if (!(o instanceof Rgb)) o = rgbConvert(o);
|
3420 | var r = o.r / 255,
|
3421 | g = o.g / 255,
|
3422 | b = o.b / 255,
|
3423 | l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
|
3424 | bl = b - l,
|
3425 | k = (E * (g - l) - C * bl) / D$1,
|
3426 | s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)),
|
3427 | h = s ? Math.atan2(k, bl) * degrees$2 - 120 : NaN;
|
3428 | return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
|
3429 | }
|
3430 |
|
3431 | function cubehelix$3(h, s, l, opacity) {
|
3432 | return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
|
3433 | }
|
3434 |
|
3435 | function Cubehelix(h, s, l, opacity) {
|
3436 | this.h = +h;
|
3437 | this.s = +s;
|
3438 | this.l = +l;
|
3439 | this.opacity = +opacity;
|
3440 | }
|
3441 |
|
3442 | define(Cubehelix, cubehelix$3, extend(Color, {
|
3443 | brighter(k) {
|
3444 | k = k == null ? brighter : Math.pow(brighter, k);
|
3445 | return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
|
3446 | },
|
3447 | darker(k) {
|
3448 | k = k == null ? darker : Math.pow(darker, k);
|
3449 | return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
|
3450 | },
|
3451 | rgb() {
|
3452 | var h = isNaN(this.h) ? 0 : (this.h + 120) * radians$1,
|
3453 | l = +this.l,
|
3454 | a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
|
3455 | cosh = Math.cos(h),
|
3456 | sinh = Math.sin(h);
|
3457 | return new Rgb(
|
3458 | 255 * (l + a * (A * cosh + B$1 * sinh)),
|
3459 | 255 * (l + a * (C * cosh + D$1 * sinh)),
|
3460 | 255 * (l + a * (E * cosh)),
|
3461 | this.opacity
|
3462 | );
|
3463 | }
|
3464 | }));
|
3465 |
|
3466 | function basis$1(t1, v0, v1, v2, v3) {
|
3467 | var t2 = t1 * t1, t3 = t2 * t1;
|
3468 | return ((1 - 3 * t1 + 3 * t2 - t3) * v0
|
3469 | + (4 - 6 * t2 + 3 * t3) * v1
|
3470 | + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
|
3471 | + t3 * v3) / 6;
|
3472 | }
|
3473 |
|
3474 | function basis$2(values) {
|
3475 | var n = values.length - 1;
|
3476 | return function(t) {
|
3477 | var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
|
3478 | v1 = values[i],
|
3479 | v2 = values[i + 1],
|
3480 | v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
|
3481 | v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
|
3482 | return basis$1((t - i / n) * n, v0, v1, v2, v3);
|
3483 | };
|
3484 | }
|
3485 |
|
3486 | function basisClosed$1(values) {
|
3487 | var n = values.length;
|
3488 | return function(t) {
|
3489 | var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
|
3490 | v0 = values[(i + n - 1) % n],
|
3491 | v1 = values[i % n],
|
3492 | v2 = values[(i + 1) % n],
|
3493 | v3 = values[(i + 2) % n];
|
3494 | return basis$1((t - i / n) * n, v0, v1, v2, v3);
|
3495 | };
|
3496 | }
|
3497 |
|
3498 | var constant$8 = x => () => x;
|
3499 |
|
3500 | function linear$2(a, d) {
|
3501 | return function(t) {
|
3502 | return a + t * d;
|
3503 | };
|
3504 | }
|
3505 |
|
3506 | function exponential$1(a, b, y) {
|
3507 | return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
|
3508 | return Math.pow(a + t * b, y);
|
3509 | };
|
3510 | }
|
3511 |
|
3512 | function hue$1(a, b) {
|
3513 | var d = b - a;
|
3514 | return d ? linear$2(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$8(isNaN(a) ? b : a);
|
3515 | }
|
3516 |
|
3517 | function gamma$1(y) {
|
3518 | return (y = +y) === 1 ? nogamma : function(a, b) {
|
3519 | return b - a ? exponential$1(a, b, y) : constant$8(isNaN(a) ? b : a);
|
3520 | };
|
3521 | }
|
3522 |
|
3523 | function nogamma(a, b) {
|
3524 | var d = b - a;
|
3525 | return d ? linear$2(a, d) : constant$8(isNaN(a) ? b : a);
|
3526 | }
|
3527 |
|
3528 | var interpolateRgb = (function rgbGamma(y) {
|
3529 | var color = gamma$1(y);
|
3530 |
|
3531 | function rgb$1(start, end) {
|
3532 | var r = color((start = rgb(start)).r, (end = rgb(end)).r),
|
3533 | g = color(start.g, end.g),
|
3534 | b = color(start.b, end.b),
|
3535 | opacity = nogamma(start.opacity, end.opacity);
|
3536 | return function(t) {
|
3537 | start.r = r(t);
|
3538 | start.g = g(t);
|
3539 | start.b = b(t);
|
3540 | start.opacity = opacity(t);
|
3541 | return start + "";
|
3542 | };
|
3543 | }
|
3544 |
|
3545 | rgb$1.gamma = rgbGamma;
|
3546 |
|
3547 | return rgb$1;
|
3548 | })(1);
|
3549 |
|
3550 | function rgbSpline(spline) {
|
3551 | return function(colors) {
|
3552 | var n = colors.length,
|
3553 | r = new Array(n),
|
3554 | g = new Array(n),
|
3555 | b = new Array(n),
|
3556 | i, color;
|
3557 | for (i = 0; i < n; ++i) {
|
3558 | color = rgb(colors[i]);
|
3559 | r[i] = color.r || 0;
|
3560 | g[i] = color.g || 0;
|
3561 | b[i] = color.b || 0;
|
3562 | }
|
3563 | r = spline(r);
|
3564 | g = spline(g);
|
3565 | b = spline(b);
|
3566 | color.opacity = 1;
|
3567 | return function(t) {
|
3568 | color.r = r(t);
|
3569 | color.g = g(t);
|
3570 | color.b = b(t);
|
3571 | return color + "";
|
3572 | };
|
3573 | };
|
3574 | }
|
3575 |
|
3576 | var rgbBasis = rgbSpline(basis$2);
|
3577 | var rgbBasisClosed = rgbSpline(basisClosed$1);
|
3578 |
|
3579 | function numberArray(a, b) {
|
3580 | if (!b) b = [];
|
3581 | var n = a ? Math.min(b.length, a.length) : 0,
|
3582 | c = b.slice(),
|
3583 | i;
|
3584 | return function(t) {
|
3585 | for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
|
3586 | return c;
|
3587 | };
|
3588 | }
|
3589 |
|
3590 | function isNumberArray(x) {
|
3591 | return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
3592 | }
|
3593 |
|
3594 | function array$3(a, b) {
|
3595 | return (isNumberArray(b) ? numberArray : genericArray)(a, b);
|
3596 | }
|
3597 |
|
3598 | function genericArray(a, b) {
|
3599 | var nb = b ? b.length : 0,
|
3600 | na = a ? Math.min(nb, a.length) : 0,
|
3601 | x = new Array(na),
|
3602 | c = new Array(nb),
|
3603 | i;
|
3604 |
|
3605 | for (i = 0; i < na; ++i) x[i] = interpolate$2(a[i], b[i]);
|
3606 | for (; i < nb; ++i) c[i] = b[i];
|
3607 |
|
3608 | return function(t) {
|
3609 | for (i = 0; i < na; ++i) c[i] = x[i](t);
|
3610 | return c;
|
3611 | };
|
3612 | }
|
3613 |
|
3614 | function date$1(a, b) {
|
3615 | var d = new Date;
|
3616 | return a = +a, b = +b, function(t) {
|
3617 | return d.setTime(a * (1 - t) + b * t), d;
|
3618 | };
|
3619 | }
|
3620 |
|
3621 | function interpolateNumber(a, b) {
|
3622 | return a = +a, b = +b, function(t) {
|
3623 | return a * (1 - t) + b * t;
|
3624 | };
|
3625 | }
|
3626 |
|
3627 | function object$1(a, b) {
|
3628 | var i = {},
|
3629 | c = {},
|
3630 | k;
|
3631 |
|
3632 | if (a === null || typeof a !== "object") a = {};
|
3633 | if (b === null || typeof b !== "object") b = {};
|
3634 |
|
3635 | for (k in b) {
|
3636 | if (k in a) {
|
3637 | i[k] = interpolate$2(a[k], b[k]);
|
3638 | } else {
|
3639 | c[k] = b[k];
|
3640 | }
|
3641 | }
|
3642 |
|
3643 | return function(t) {
|
3644 | for (k in i) c[k] = i[k](t);
|
3645 | return c;
|
3646 | };
|
3647 | }
|
3648 |
|
3649 | var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
|
3650 | reB = new RegExp(reA.source, "g");
|
3651 |
|
3652 | function zero(b) {
|
3653 | return function() {
|
3654 | return b;
|
3655 | };
|
3656 | }
|
3657 |
|
3658 | function one(b) {
|
3659 | return function(t) {
|
3660 | return b(t) + "";
|
3661 | };
|
3662 | }
|
3663 |
|
3664 | function interpolateString(a, b) {
|
3665 | var bi = reA.lastIndex = reB.lastIndex = 0,
|
3666 | am,
|
3667 | bm,
|
3668 | bs,
|
3669 | i = -1,
|
3670 | s = [],
|
3671 | q = [];
|
3672 |
|
3673 |
|
3674 | a = a + "", b = b + "";
|
3675 |
|
3676 |
|
3677 | while ((am = reA.exec(a))
|
3678 | && (bm = reB.exec(b))) {
|
3679 | if ((bs = bm.index) > bi) {
|
3680 | bs = b.slice(bi, bs);
|
3681 | if (s[i]) s[i] += bs;
|
3682 | else s[++i] = bs;
|
3683 | }
|
3684 | if ((am = am[0]) === (bm = bm[0])) {
|
3685 | if (s[i]) s[i] += bm;
|
3686 | else s[++i] = bm;
|
3687 | } else {
|
3688 | s[++i] = null;
|
3689 | q.push({i: i, x: interpolateNumber(am, bm)});
|
3690 | }
|
3691 | bi = reB.lastIndex;
|
3692 | }
|
3693 |
|
3694 |
|
3695 | if (bi < b.length) {
|
3696 | bs = b.slice(bi);
|
3697 | if (s[i]) s[i] += bs;
|
3698 | else s[++i] = bs;
|
3699 | }
|
3700 |
|
3701 |
|
3702 |
|
3703 | return s.length < 2 ? (q[0]
|
3704 | ? one(q[0].x)
|
3705 | : zero(b))
|
3706 | : (b = q.length, function(t) {
|
3707 | for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
|
3708 | return s.join("");
|
3709 | });
|
3710 | }
|
3711 |
|
3712 | function interpolate$2(a, b) {
|
3713 | var t = typeof b, c;
|
3714 | return b == null || t === "boolean" ? constant$8(b)
|
3715 | : (t === "number" ? interpolateNumber
|
3716 | : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
|
3717 | : b instanceof color ? interpolateRgb
|
3718 | : b instanceof Date ? date$1
|
3719 | : isNumberArray(b) ? numberArray
|
3720 | : Array.isArray(b) ? genericArray
|
3721 | : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object$1
|
3722 | : interpolateNumber)(a, b);
|
3723 | }
|
3724 |
|
3725 | function discrete(range) {
|
3726 | var n = range.length;
|
3727 | return function(t) {
|
3728 | return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
3729 | };
|
3730 | }
|
3731 |
|
3732 | function hue(a, b) {
|
3733 | var i = hue$1(+a, +b);
|
3734 | return function(t) {
|
3735 | var x = i(t);
|
3736 | return x - 360 * Math.floor(x / 360);
|
3737 | };
|
3738 | }
|
3739 |
|
3740 | function interpolateRound(a, b) {
|
3741 | return a = +a, b = +b, function(t) {
|
3742 | return Math.round(a * (1 - t) + b * t);
|
3743 | };
|
3744 | }
|
3745 |
|
3746 | var degrees$1 = 180 / Math.PI;
|
3747 |
|
3748 | var identity$7 = {
|
3749 | translateX: 0,
|
3750 | translateY: 0,
|
3751 | rotate: 0,
|
3752 | skewX: 0,
|
3753 | scaleX: 1,
|
3754 | scaleY: 1
|
3755 | };
|
3756 |
|
3757 | function decompose(a, b, c, d, e, f) {
|
3758 | var scaleX, scaleY, skewX;
|
3759 | if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
|
3760 | if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
|
3761 | if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
|
3762 | if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
|
3763 | return {
|
3764 | translateX: e,
|
3765 | translateY: f,
|
3766 | rotate: Math.atan2(b, a) * degrees$1,
|
3767 | skewX: Math.atan(skewX) * degrees$1,
|
3768 | scaleX: scaleX,
|
3769 | scaleY: scaleY
|
3770 | };
|
3771 | }
|
3772 |
|
3773 | var svgNode;
|
3774 |
|
3775 |
|
3776 | function parseCss(value) {
|
3777 | const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
|
3778 | return m.isIdentity ? identity$7 : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
|
3779 | }
|
3780 |
|
3781 | function parseSvg(value) {
|
3782 | if (value == null) return identity$7;
|
3783 | if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
3784 | svgNode.setAttribute("transform", value);
|
3785 | if (!(value = svgNode.transform.baseVal.consolidate())) return identity$7;
|
3786 | value = value.matrix;
|
3787 | return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
|
3788 | }
|
3789 |
|
3790 | function interpolateTransform(parse, pxComma, pxParen, degParen) {
|
3791 |
|
3792 | function pop(s) {
|
3793 | return s.length ? s.pop() + " " : "";
|
3794 | }
|
3795 |
|
3796 | function translate(xa, ya, xb, yb, s, q) {
|
3797 | if (xa !== xb || ya !== yb) {
|
3798 | var i = s.push("translate(", null, pxComma, null, pxParen);
|
3799 | q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
|
3800 | } else if (xb || yb) {
|
3801 | s.push("translate(" + xb + pxComma + yb + pxParen);
|
3802 | }
|
3803 | }
|
3804 |
|
3805 | function rotate(a, b, s, q) {
|
3806 | if (a !== b) {
|
3807 | if (a - b > 180) b += 360; else if (b - a > 180) a += 360;
|
3808 | q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
|
3809 | } else if (b) {
|
3810 | s.push(pop(s) + "rotate(" + b + degParen);
|
3811 | }
|
3812 | }
|
3813 |
|
3814 | function skewX(a, b, s, q) {
|
3815 | if (a !== b) {
|
3816 | q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
|
3817 | } else if (b) {
|
3818 | s.push(pop(s) + "skewX(" + b + degParen);
|
3819 | }
|
3820 | }
|
3821 |
|
3822 | function scale(xa, ya, xb, yb, s, q) {
|
3823 | if (xa !== xb || ya !== yb) {
|
3824 | var i = s.push(pop(s) + "scale(", null, ",", null, ")");
|
3825 | q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
|
3826 | } else if (xb !== 1 || yb !== 1) {
|
3827 | s.push(pop(s) + "scale(" + xb + "," + yb + ")");
|
3828 | }
|
3829 | }
|
3830 |
|
3831 | return function(a, b) {
|
3832 | var s = [],
|
3833 | q = [];
|
3834 | a = parse(a), b = parse(b);
|
3835 | translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
|
3836 | rotate(a.rotate, b.rotate, s, q);
|
3837 | skewX(a.skewX, b.skewX, s, q);
|
3838 | scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
|
3839 | a = b = null;
|
3840 | return function(t) {
|
3841 | var i = -1, n = q.length, o;
|
3842 | while (++i < n) s[(o = q[i]).i] = o.x(t);
|
3843 | return s.join("");
|
3844 | };
|
3845 | };
|
3846 | }
|
3847 |
|
3848 | var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
|
3849 | var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
|
3850 |
|
3851 | var epsilon2$1 = 1e-12;
|
3852 |
|
3853 | function cosh(x) {
|
3854 | return ((x = Math.exp(x)) + 1 / x) / 2;
|
3855 | }
|
3856 |
|
3857 | function sinh(x) {
|
3858 | return ((x = Math.exp(x)) - 1 / x) / 2;
|
3859 | }
|
3860 |
|
3861 | function tanh(x) {
|
3862 | return ((x = Math.exp(2 * x)) - 1) / (x + 1);
|
3863 | }
|
3864 |
|
3865 | var interpolateZoom = (function zoomRho(rho, rho2, rho4) {
|
3866 |
|
3867 |
|
3868 |
|
3869 | function zoom(p0, p1) {
|
3870 | var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
|
3871 | ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
|
3872 | dx = ux1 - ux0,
|
3873 | dy = uy1 - uy0,
|
3874 | d2 = dx * dx + dy * dy,
|
3875 | i,
|
3876 | S;
|
3877 |
|
3878 |
|
3879 | if (d2 < epsilon2$1) {
|
3880 | S = Math.log(w1 / w0) / rho;
|
3881 | i = function(t) {
|
3882 | return [
|
3883 | ux0 + t * dx,
|
3884 | uy0 + t * dy,
|
3885 | w0 * Math.exp(rho * t * S)
|
3886 | ];
|
3887 | };
|
3888 | }
|
3889 |
|
3890 |
|
3891 | else {
|
3892 | var d1 = Math.sqrt(d2),
|
3893 | b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
|
3894 | b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
|
3895 | r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
|
3896 | r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
|
3897 | S = (r1 - r0) / rho;
|
3898 | i = function(t) {
|
3899 | var s = t * S,
|
3900 | coshr0 = cosh(r0),
|
3901 | u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
|
3902 | return [
|
3903 | ux0 + u * dx,
|
3904 | uy0 + u * dy,
|
3905 | w0 * coshr0 / cosh(rho * s + r0)
|
3906 | ];
|
3907 | };
|
3908 | }
|
3909 |
|
3910 | i.duration = S * 1000 * rho / Math.SQRT2;
|
3911 |
|
3912 | return i;
|
3913 | }
|
3914 |
|
3915 | zoom.rho = function(_) {
|
3916 | var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
|
3917 | return zoomRho(_1, _2, _4);
|
3918 | };
|
3919 |
|
3920 | return zoom;
|
3921 | })(Math.SQRT2, 2, 4);
|
3922 |
|
3923 | function hsl(hue) {
|
3924 | return function(start, end) {
|
3925 | var h = hue((start = hsl$2(start)).h, (end = hsl$2(end)).h),
|
3926 | s = nogamma(start.s, end.s),
|
3927 | l = nogamma(start.l, end.l),
|
3928 | opacity = nogamma(start.opacity, end.opacity);
|
3929 | return function(t) {
|
3930 | start.h = h(t);
|
3931 | start.s = s(t);
|
3932 | start.l = l(t);
|
3933 | start.opacity = opacity(t);
|
3934 | return start + "";
|
3935 | };
|
3936 | }
|
3937 | }
|
3938 |
|
3939 | var hsl$1 = hsl(hue$1);
|
3940 | var hslLong = hsl(nogamma);
|
3941 |
|
3942 | function lab(start, end) {
|
3943 | var l = nogamma((start = lab$1(start)).l, (end = lab$1(end)).l),
|
3944 | a = nogamma(start.a, end.a),
|
3945 | b = nogamma(start.b, end.b),
|
3946 | opacity = nogamma(start.opacity, end.opacity);
|
3947 | return function(t) {
|
3948 | start.l = l(t);
|
3949 | start.a = a(t);
|
3950 | start.b = b(t);
|
3951 | start.opacity = opacity(t);
|
3952 | return start + "";
|
3953 | };
|
3954 | }
|
3955 |
|
3956 | function hcl(hue) {
|
3957 | return function(start, end) {
|
3958 | var h = hue((start = hcl$2(start)).h, (end = hcl$2(end)).h),
|
3959 | c = nogamma(start.c, end.c),
|
3960 | l = nogamma(start.l, end.l),
|
3961 | opacity = nogamma(start.opacity, end.opacity);
|
3962 | return function(t) {
|
3963 | start.h = h(t);
|
3964 | start.c = c(t);
|
3965 | start.l = l(t);
|
3966 | start.opacity = opacity(t);
|
3967 | return start + "";
|
3968 | };
|
3969 | }
|
3970 | }
|
3971 |
|
3972 | var hcl$1 = hcl(hue$1);
|
3973 | var hclLong = hcl(nogamma);
|
3974 |
|
3975 | function cubehelix$1(hue) {
|
3976 | return (function cubehelixGamma(y) {
|
3977 | y = +y;
|
3978 |
|
3979 | function cubehelix(start, end) {
|
3980 | var h = hue((start = cubehelix$3(start)).h, (end = cubehelix$3(end)).h),
|
3981 | s = nogamma(start.s, end.s),
|
3982 | l = nogamma(start.l, end.l),
|
3983 | opacity = nogamma(start.opacity, end.opacity);
|
3984 | return function(t) {
|
3985 | start.h = h(t);
|
3986 | start.s = s(t);
|
3987 | start.l = l(Math.pow(t, y));
|
3988 | start.opacity = opacity(t);
|
3989 | return start + "";
|
3990 | };
|
3991 | }
|
3992 |
|
3993 | cubehelix.gamma = cubehelixGamma;
|
3994 |
|
3995 | return cubehelix;
|
3996 | })(1);
|
3997 | }
|
3998 |
|
3999 | var cubehelix$2 = cubehelix$1(hue$1);
|
4000 | var cubehelixLong = cubehelix$1(nogamma);
|
4001 |
|
4002 | function piecewise(interpolate, values) {
|
4003 | if (values === undefined) values = interpolate, interpolate = interpolate$2;
|
4004 | var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
|
4005 | while (i < n) I[i] = interpolate(v, v = values[++i]);
|
4006 | return function(t) {
|
4007 | var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
|
4008 | return I[i](t - i);
|
4009 | };
|
4010 | }
|
4011 |
|
4012 | function quantize$1(interpolator, n) {
|
4013 | var samples = new Array(n);
|
4014 | for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
|
4015 | return samples;
|
4016 | }
|
4017 |
|
4018 | var frame = 0,
|
4019 | timeout$1 = 0,
|
4020 | interval$1 = 0,
|
4021 | pokeDelay = 1000,
|
4022 | taskHead,
|
4023 | taskTail,
|
4024 | clockLast = 0,
|
4025 | clockNow = 0,
|
4026 | clockSkew = 0,
|
4027 | clock = typeof performance === "object" && performance.now ? performance : Date,
|
4028 | setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
|
4029 |
|
4030 | function now() {
|
4031 | return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
|
4032 | }
|
4033 |
|
4034 | function clearNow() {
|
4035 | clockNow = 0;
|
4036 | }
|
4037 |
|
4038 | function Timer() {
|
4039 | this._call =
|
4040 | this._time =
|
4041 | this._next = null;
|
4042 | }
|
4043 |
|
4044 | Timer.prototype = timer.prototype = {
|
4045 | constructor: Timer,
|
4046 | restart: function(callback, delay, time) {
|
4047 | if (typeof callback !== "function") throw new TypeError("callback is not a function");
|
4048 | time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
|
4049 | if (!this._next && taskTail !== this) {
|
4050 | if (taskTail) taskTail._next = this;
|
4051 | else taskHead = this;
|
4052 | taskTail = this;
|
4053 | }
|
4054 | this._call = callback;
|
4055 | this._time = time;
|
4056 | sleep();
|
4057 | },
|
4058 | stop: function() {
|
4059 | if (this._call) {
|
4060 | this._call = null;
|
4061 | this._time = Infinity;
|
4062 | sleep();
|
4063 | }
|
4064 | }
|
4065 | };
|
4066 |
|
4067 | function timer(callback, delay, time) {
|
4068 | var t = new Timer;
|
4069 | t.restart(callback, delay, time);
|
4070 | return t;
|
4071 | }
|
4072 |
|
4073 | function timerFlush() {
|
4074 | now();
|
4075 | ++frame;
|
4076 | var t = taskHead, e;
|
4077 | while (t) {
|
4078 | if ((e = clockNow - t._time) >= 0) t._call.call(undefined, e);
|
4079 | t = t._next;
|
4080 | }
|
4081 | --frame;
|
4082 | }
|
4083 |
|
4084 | function wake() {
|
4085 | clockNow = (clockLast = clock.now()) + clockSkew;
|
4086 | frame = timeout$1 = 0;
|
4087 | try {
|
4088 | timerFlush();
|
4089 | } finally {
|
4090 | frame = 0;
|
4091 | nap();
|
4092 | clockNow = 0;
|
4093 | }
|
4094 | }
|
4095 |
|
4096 | function poke() {
|
4097 | var now = clock.now(), delay = now - clockLast;
|
4098 | if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
|
4099 | }
|
4100 |
|
4101 | function nap() {
|
4102 | var t0, t1 = taskHead, t2, time = Infinity;
|
4103 | while (t1) {
|
4104 | if (t1._call) {
|
4105 | if (time > t1._time) time = t1._time;
|
4106 | t0 = t1, t1 = t1._next;
|
4107 | } else {
|
4108 | t2 = t1._next, t1._next = null;
|
4109 | t1 = t0 ? t0._next = t2 : taskHead = t2;
|
4110 | }
|
4111 | }
|
4112 | taskTail = t0;
|
4113 | sleep(time);
|
4114 | }
|
4115 |
|
4116 | function sleep(time) {
|
4117 | if (frame) return;
|
4118 | if (timeout$1) timeout$1 = clearTimeout(timeout$1);
|
4119 | var delay = time - clockNow;
|
4120 | if (delay > 24) {
|
4121 | if (time < Infinity) timeout$1 = setTimeout(wake, time - clock.now() - clockSkew);
|
4122 | if (interval$1) interval$1 = clearInterval(interval$1);
|
4123 | } else {
|
4124 | if (!interval$1) clockLast = clock.now(), interval$1 = setInterval(poke, pokeDelay);
|
4125 | frame = 1, setFrame(wake);
|
4126 | }
|
4127 | }
|
4128 |
|
4129 | function timeout(callback, delay, time) {
|
4130 | var t = new Timer;
|
4131 | delay = delay == null ? 0 : +delay;
|
4132 | t.restart(elapsed => {
|
4133 | t.stop();
|
4134 | callback(elapsed + delay);
|
4135 | }, delay, time);
|
4136 | return t;
|
4137 | }
|
4138 |
|
4139 | function interval(callback, delay, time) {
|
4140 | var t = new Timer, total = delay;
|
4141 | if (delay == null) return t.restart(callback, delay, time), t;
|
4142 | t._restart = t.restart;
|
4143 | t.restart = function(callback, delay, time) {
|
4144 | delay = +delay, time = time == null ? now() : +time;
|
4145 | t._restart(function tick(elapsed) {
|
4146 | elapsed += total;
|
4147 | t._restart(tick, total += delay, time);
|
4148 | callback(elapsed);
|
4149 | }, delay, time);
|
4150 | };
|
4151 | t.restart(callback, delay, time);
|
4152 | return t;
|
4153 | }
|
4154 |
|
4155 | var emptyOn = dispatch("start", "end", "cancel", "interrupt");
|
4156 | var emptyTween = [];
|
4157 |
|
4158 | var CREATED = 0;
|
4159 | var SCHEDULED = 1;
|
4160 | var STARTING = 2;
|
4161 | var STARTED = 3;
|
4162 | var RUNNING = 4;
|
4163 | var ENDING = 5;
|
4164 | var ENDED = 6;
|
4165 |
|
4166 | function schedule(node, name, id, index, group, timing) {
|
4167 | var schedules = node.__transition;
|
4168 | if (!schedules) node.__transition = {};
|
4169 | else if (id in schedules) return;
|
4170 | create(node, id, {
|
4171 | name: name,
|
4172 | index: index,
|
4173 | group: group,
|
4174 | on: emptyOn,
|
4175 | tween: emptyTween,
|
4176 | time: timing.time,
|
4177 | delay: timing.delay,
|
4178 | duration: timing.duration,
|
4179 | ease: timing.ease,
|
4180 | timer: null,
|
4181 | state: CREATED
|
4182 | });
|
4183 | }
|
4184 |
|
4185 | function init(node, id) {
|
4186 | var schedule = get(node, id);
|
4187 | if (schedule.state > CREATED) throw new Error("too late; already scheduled");
|
4188 | return schedule;
|
4189 | }
|
4190 |
|
4191 | function set(node, id) {
|
4192 | var schedule = get(node, id);
|
4193 | if (schedule.state > STARTED) throw new Error("too late; already running");
|
4194 | return schedule;
|
4195 | }
|
4196 |
|
4197 | function get(node, id) {
|
4198 | var schedule = node.__transition;
|
4199 | if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
|
4200 | return schedule;
|
4201 | }
|
4202 |
|
4203 | function create(node, id, self) {
|
4204 | var schedules = node.__transition,
|
4205 | tween;
|
4206 |
|
4207 |
|
4208 |
|
4209 | schedules[id] = self;
|
4210 | self.timer = timer(schedule, 0, self.time);
|
4211 |
|
4212 | function schedule(elapsed) {
|
4213 | self.state = SCHEDULED;
|
4214 | self.timer.restart(start, self.delay, self.time);
|
4215 |
|
4216 |
|
4217 | if (self.delay <= elapsed) start(elapsed - self.delay);
|
4218 | }
|
4219 |
|
4220 | function start(elapsed) {
|
4221 | var i, j, n, o;
|
4222 |
|
4223 |
|
4224 | if (self.state !== SCHEDULED) return stop();
|
4225 |
|
4226 | for (i in schedules) {
|
4227 | o = schedules[i];
|
4228 | if (o.name !== self.name) continue;
|
4229 |
|
4230 |
|
4231 |
|
4232 |
|
4233 | if (o.state === STARTED) return timeout(start);
|
4234 |
|
4235 |
|
4236 | if (o.state === RUNNING) {
|
4237 | o.state = ENDED;
|
4238 | o.timer.stop();
|
4239 | o.on.call("interrupt", node, node.__data__, o.index, o.group);
|
4240 | delete schedules[i];
|
4241 | }
|
4242 |
|
4243 |
|
4244 | else if (+i < id) {
|
4245 | o.state = ENDED;
|
4246 | o.timer.stop();
|
4247 | o.on.call("cancel", node, node.__data__, o.index, o.group);
|
4248 | delete schedules[i];
|
4249 | }
|
4250 | }
|
4251 |
|
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 | timeout(function() {
|
4257 | if (self.state === STARTED) {
|
4258 | self.state = RUNNING;
|
4259 | self.timer.restart(tick, self.delay, self.time);
|
4260 | tick(elapsed);
|
4261 | }
|
4262 | });
|
4263 |
|
4264 |
|
4265 |
|
4266 | self.state = STARTING;
|
4267 | self.on.call("start", node, node.__data__, self.index, self.group);
|
4268 | if (self.state !== STARTING) return;
|
4269 | self.state = STARTED;
|
4270 |
|
4271 |
|
4272 | tween = new Array(n = self.tween.length);
|
4273 | for (i = 0, j = -1; i < n; ++i) {
|
4274 | if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
|
4275 | tween[++j] = o;
|
4276 | }
|
4277 | }
|
4278 | tween.length = j + 1;
|
4279 | }
|
4280 |
|
4281 | function tick(elapsed) {
|
4282 | var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
|
4283 | i = -1,
|
4284 | n = tween.length;
|
4285 |
|
4286 | while (++i < n) {
|
4287 | tween[i].call(node, t);
|
4288 | }
|
4289 |
|
4290 |
|
4291 | if (self.state === ENDING) {
|
4292 | self.on.call("end", node, node.__data__, self.index, self.group);
|
4293 | stop();
|
4294 | }
|
4295 | }
|
4296 |
|
4297 | function stop() {
|
4298 | self.state = ENDED;
|
4299 | self.timer.stop();
|
4300 | delete schedules[id];
|
4301 | for (var i in schedules) return;
|
4302 | delete node.__transition;
|
4303 | }
|
4304 | }
|
4305 |
|
4306 | function interrupt(node, name) {
|
4307 | var schedules = node.__transition,
|
4308 | schedule,
|
4309 | active,
|
4310 | empty = true,
|
4311 | i;
|
4312 |
|
4313 | if (!schedules) return;
|
4314 |
|
4315 | name = name == null ? null : name + "";
|
4316 |
|
4317 | for (i in schedules) {
|
4318 | if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
|
4319 | active = schedule.state > STARTING && schedule.state < ENDING;
|
4320 | schedule.state = ENDED;
|
4321 | schedule.timer.stop();
|
4322 | schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
|
4323 | delete schedules[i];
|
4324 | }
|
4325 |
|
4326 | if (empty) delete node.__transition;
|
4327 | }
|
4328 |
|
4329 | function selection_interrupt(name) {
|
4330 | return this.each(function() {
|
4331 | interrupt(this, name);
|
4332 | });
|
4333 | }
|
4334 |
|
4335 | function tweenRemove(id, name) {
|
4336 | var tween0, tween1;
|
4337 | return function() {
|
4338 | var schedule = set(this, id),
|
4339 | tween = schedule.tween;
|
4340 |
|
4341 | // If this node shared tween with the previous node,
|
4342 | // just assign the updated shared tween and we’re done!
|
4343 | // Otherwise, copy-on-write.
|
4344 | if (tween !== tween0) {
|
4345 | tween1 = tween0 = tween;
|
4346 | for (var i = 0, n = tween1.length; i < n; ++i) {
|
4347 | if (tween1[i].name === name) {
|
4348 | tween1 = tween1.slice();
|
4349 | tween1.splice(i, 1);
|
4350 | break;
|
4351 | }
|
4352 | }
|
4353 | }
|
4354 |
|
4355 | schedule.tween = tween1;
|
4356 | };
|
4357 | }
|
4358 |
|
4359 | function tweenFunction(id, name, value) {
|
4360 | var tween0, tween1;
|
4361 | if (typeof value !== "function") throw new Error;
|
4362 | return function() {
|
4363 | var schedule = set(this, id),
|
4364 | tween = schedule.tween;
|
4365 |
|
4366 | // If this node shared tween with the previous node,
|
4367 | // just assign the updated shared tween and we’re done!
|
4368 | // Otherwise, copy-on-write.
|
4369 | if (tween !== tween0) {
|
4370 | tween1 = (tween0 = tween).slice();
|
4371 | for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
|
4372 | if (tween1[i].name === name) {
|
4373 | tween1[i] = t;
|
4374 | break;
|
4375 | }
|
4376 | }
|
4377 | if (i === n) tween1.push(t);
|
4378 | }
|
4379 |
|
4380 | schedule.tween = tween1;
|
4381 | };
|
4382 | }
|
4383 |
|
4384 | function transition_tween(name, value) {
|
4385 | var id = this._id;
|
4386 |
|
4387 | name += "";
|
4388 |
|
4389 | if (arguments.length < 2) {
|
4390 | var tween = get(this.node(), id).tween;
|
4391 | for (var i = 0, n = tween.length, t; i < n; ++i) {
|
4392 | if ((t = tween[i]).name === name) {
|
4393 | return t.value;
|
4394 | }
|
4395 | }
|
4396 | return null;
|
4397 | }
|
4398 |
|
4399 | return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
|
4400 | }
|
4401 |
|
4402 | function tweenValue(transition, name, value) {
|
4403 | var id = transition._id;
|
4404 |
|
4405 | transition.each(function() {
|
4406 | var schedule = set(this, id);
|
4407 | (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
|
4408 | });
|
4409 |
|
4410 | return function(node) {
|
4411 | return get(node, id).value[name];
|
4412 | };
|
4413 | }
|
4414 |
|
4415 | function interpolate$1(a, b) {
|
4416 | var c;
|
4417 | return (typeof b === "number" ? interpolateNumber
|
4418 | : b instanceof color ? interpolateRgb
|
4419 | : (c = color(b)) ? (b = c, interpolateRgb)
|
4420 | : interpolateString)(a, b);
|
4421 | }
|
4422 |
|
4423 | function attrRemove(name) {
|
4424 | return function() {
|
4425 | this.removeAttribute(name);
|
4426 | };
|
4427 | }
|
4428 |
|
4429 | function attrRemoveNS(fullname) {
|
4430 | return function() {
|
4431 | this.removeAttributeNS(fullname.space, fullname.local);
|
4432 | };
|
4433 | }
|
4434 |
|
4435 | function attrConstant(name, interpolate, value1) {
|
4436 | var string00,
|
4437 | string1 = value1 + "",
|
4438 | interpolate0;
|
4439 | return function() {
|
4440 | var string0 = this.getAttribute(name);
|
4441 | return string0 === string1 ? null
|
4442 | : string0 === string00 ? interpolate0
|
4443 | : interpolate0 = interpolate(string00 = string0, value1);
|
4444 | };
|
4445 | }
|
4446 |
|
4447 | function attrConstantNS(fullname, interpolate, value1) {
|
4448 | var string00,
|
4449 | string1 = value1 + "",
|
4450 | interpolate0;
|
4451 | return function() {
|
4452 | var string0 = this.getAttributeNS(fullname.space, fullname.local);
|
4453 | return string0 === string1 ? null
|
4454 | : string0 === string00 ? interpolate0
|
4455 | : interpolate0 = interpolate(string00 = string0, value1);
|
4456 | };
|
4457 | }
|
4458 |
|
4459 | function attrFunction(name, interpolate, value) {
|
4460 | var string00,
|
4461 | string10,
|
4462 | interpolate0;
|
4463 | return function() {
|
4464 | var string0, value1 = value(this), string1;
|
4465 | if (value1 == null) return void this.removeAttribute(name);
|
4466 | string0 = this.getAttribute(name);
|
4467 | string1 = value1 + "";
|
4468 | return string0 === string1 ? null
|
4469 | : string0 === string00 && string1 === string10 ? interpolate0
|
4470 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
4471 | };
|
4472 | }
|
4473 |
|
4474 | function attrFunctionNS(fullname, interpolate, value) {
|
4475 | var string00,
|
4476 | string10,
|
4477 | interpolate0;
|
4478 | return function() {
|
4479 | var string0, value1 = value(this), string1;
|
4480 | if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
|
4481 | string0 = this.getAttributeNS(fullname.space, fullname.local);
|
4482 | string1 = value1 + "";
|
4483 | return string0 === string1 ? null
|
4484 | : string0 === string00 && string1 === string10 ? interpolate0
|
4485 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
4486 | };
|
4487 | }
|
4488 |
|
4489 | function transition_attr(name, value) {
|
4490 | var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
|
4491 | return this.attrTween(name, typeof value === "function"
|
4492 | ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value))
|
4493 | : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname)
|
4494 | : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value));
|
4495 | }
|
4496 |
|
4497 | function attrInterpolate(name, i) {
|
4498 | return function(t) {
|
4499 | this.setAttribute(name, i.call(this, t));
|
4500 | };
|
4501 | }
|
4502 |
|
4503 | function attrInterpolateNS(fullname, i) {
|
4504 | return function(t) {
|
4505 | this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
|
4506 | };
|
4507 | }
|
4508 |
|
4509 | function attrTweenNS(fullname, value) {
|
4510 | var t0, i0;
|
4511 | function tween() {
|
4512 | var i = value.apply(this, arguments);
|
4513 | if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
|
4514 | return t0;
|
4515 | }
|
4516 | tween._value = value;
|
4517 | return tween;
|
4518 | }
|
4519 |
|
4520 | function attrTween(name, value) {
|
4521 | var t0, i0;
|
4522 | function tween() {
|
4523 | var i = value.apply(this, arguments);
|
4524 | if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
|
4525 | return t0;
|
4526 | }
|
4527 | tween._value = value;
|
4528 | return tween;
|
4529 | }
|
4530 |
|
4531 | function transition_attrTween(name, value) {
|
4532 | var key = "attr." + name;
|
4533 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
4534 | if (value == null) return this.tween(key, null);
|
4535 | if (typeof value !== "function") throw new Error;
|
4536 | var fullname = namespace(name);
|
4537 | return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
|
4538 | }
|
4539 |
|
4540 | function delayFunction(id, value) {
|
4541 | return function() {
|
4542 | init(this, id).delay = +value.apply(this, arguments);
|
4543 | };
|
4544 | }
|
4545 |
|
4546 | function delayConstant(id, value) {
|
4547 | return value = +value, function() {
|
4548 | init(this, id).delay = value;
|
4549 | };
|
4550 | }
|
4551 |
|
4552 | function transition_delay(value) {
|
4553 | var id = this._id;
|
4554 |
|
4555 | return arguments.length
|
4556 | ? this.each((typeof value === "function"
|
4557 | ? delayFunction
|
4558 | : delayConstant)(id, value))
|
4559 | : get(this.node(), id).delay;
|
4560 | }
|
4561 |
|
4562 | function durationFunction(id, value) {
|
4563 | return function() {
|
4564 | set(this, id).duration = +value.apply(this, arguments);
|
4565 | };
|
4566 | }
|
4567 |
|
4568 | function durationConstant(id, value) {
|
4569 | return value = +value, function() {
|
4570 | set(this, id).duration = value;
|
4571 | };
|
4572 | }
|
4573 |
|
4574 | function transition_duration(value) {
|
4575 | var id = this._id;
|
4576 |
|
4577 | return arguments.length
|
4578 | ? this.each((typeof value === "function"
|
4579 | ? durationFunction
|
4580 | : durationConstant)(id, value))
|
4581 | : get(this.node(), id).duration;
|
4582 | }
|
4583 |
|
4584 | function easeConstant(id, value) {
|
4585 | if (typeof value !== "function") throw new Error;
|
4586 | return function() {
|
4587 | set(this, id).ease = value;
|
4588 | };
|
4589 | }
|
4590 |
|
4591 | function transition_ease(value) {
|
4592 | var id = this._id;
|
4593 |
|
4594 | return arguments.length
|
4595 | ? this.each(easeConstant(id, value))
|
4596 | : get(this.node(), id).ease;
|
4597 | }
|
4598 |
|
4599 | function easeVarying(id, value) {
|
4600 | return function() {
|
4601 | var v = value.apply(this, arguments);
|
4602 | if (typeof v !== "function") throw new Error;
|
4603 | set(this, id).ease = v;
|
4604 | };
|
4605 | }
|
4606 |
|
4607 | function transition_easeVarying(value) {
|
4608 | if (typeof value !== "function") throw new Error;
|
4609 | return this.each(easeVarying(this._id, value));
|
4610 | }
|
4611 |
|
4612 | function transition_filter(match) {
|
4613 | if (typeof match !== "function") match = matcher(match);
|
4614 |
|
4615 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
4616 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
|
4617 | if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
4618 | subgroup.push(node);
|
4619 | }
|
4620 | }
|
4621 | }
|
4622 |
|
4623 | return new Transition(subgroups, this._parents, this._name, this._id);
|
4624 | }
|
4625 |
|
4626 | function transition_merge(transition) {
|
4627 | if (transition._id !== this._id) throw new Error;
|
4628 |
|
4629 | 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) {
|
4630 | for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
|
4631 | if (node = group0[i] || group1[i]) {
|
4632 | merge[i] = node;
|
4633 | }
|
4634 | }
|
4635 | }
|
4636 |
|
4637 | for (; j < m0; ++j) {
|
4638 | merges[j] = groups0[j];
|
4639 | }
|
4640 |
|
4641 | return new Transition(merges, this._parents, this._name, this._id);
|
4642 | }
|
4643 |
|
4644 | function start(name) {
|
4645 | return (name + "").trim().split(/^|\s+/).every(function(t) {
|
4646 | var i = t.indexOf(".");
|
4647 | if (i >= 0) t = t.slice(0, i);
|
4648 | return !t || t === "start";
|
4649 | });
|
4650 | }
|
4651 |
|
4652 | function onFunction(id, name, listener) {
|
4653 | var on0, on1, sit = start(name) ? init : set;
|
4654 | return function() {
|
4655 | var schedule = sit(this, id),
|
4656 | on = schedule.on;
|
4657 |
|
4658 |
|
4659 |
|
4660 |
|
4661 | if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
|
4662 |
|
4663 | schedule.on = on1;
|
4664 | };
|
4665 | }
|
4666 |
|
4667 | function transition_on(name, listener) {
|
4668 | var id = this._id;
|
4669 |
|
4670 | return arguments.length < 2
|
4671 | ? get(this.node(), id).on.on(name)
|
4672 | : this.each(onFunction(id, name, listener));
|
4673 | }
|
4674 |
|
4675 | function removeFunction(id) {
|
4676 | return function() {
|
4677 | var parent = this.parentNode;
|
4678 | for (var i in this.__transition) if (+i !== id) return;
|
4679 | if (parent) parent.removeChild(this);
|
4680 | };
|
4681 | }
|
4682 |
|
4683 | function transition_remove() {
|
4684 | return this.on("end.remove", removeFunction(this._id));
|
4685 | }
|
4686 |
|
4687 | function transition_select(select) {
|
4688 | var name = this._name,
|
4689 | id = this._id;
|
4690 |
|
4691 | if (typeof select !== "function") select = selector(select);
|
4692 |
|
4693 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
4694 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
|
4695 | if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
4696 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
4697 | subgroup[i] = subnode;
|
4698 | schedule(subgroup[i], name, id, i, subgroup, get(node, id));
|
4699 | }
|
4700 | }
|
4701 | }
|
4702 |
|
4703 | return new Transition(subgroups, this._parents, name, id);
|
4704 | }
|
4705 |
|
4706 | function transition_selectAll(select) {
|
4707 | var name = this._name,
|
4708 | id = this._id;
|
4709 |
|
4710 | if (typeof select !== "function") select = selectorAll(select);
|
4711 |
|
4712 | for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
|
4713 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
4714 | if (node = group[i]) {
|
4715 | for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) {
|
4716 | if (child = children[k]) {
|
4717 | schedule(child, name, id, k, children, inherit);
|
4718 | }
|
4719 | }
|
4720 | subgroups.push(children);
|
4721 | parents.push(node);
|
4722 | }
|
4723 | }
|
4724 | }
|
4725 |
|
4726 | return new Transition(subgroups, parents, name, id);
|
4727 | }
|
4728 |
|
4729 | var Selection = selection.prototype.constructor;
|
4730 |
|
4731 | function transition_selection() {
|
4732 | return new Selection(this._groups, this._parents);
|
4733 | }
|
4734 |
|
4735 | function styleNull(name, interpolate) {
|
4736 | var string00,
|
4737 | string10,
|
4738 | interpolate0;
|
4739 | return function() {
|
4740 | var string0 = styleValue(this, name),
|
4741 | string1 = (this.style.removeProperty(name), styleValue(this, name));
|
4742 | return string0 === string1 ? null
|
4743 | : string0 === string00 && string1 === string10 ? interpolate0
|
4744 | : interpolate0 = interpolate(string00 = string0, string10 = string1);
|
4745 | };
|
4746 | }
|
4747 |
|
4748 | function styleRemove(name) {
|
4749 | return function() {
|
4750 | this.style.removeProperty(name);
|
4751 | };
|
4752 | }
|
4753 |
|
4754 | function styleConstant(name, interpolate, value1) {
|
4755 | var string00,
|
4756 | string1 = value1 + "",
|
4757 | interpolate0;
|
4758 | return function() {
|
4759 | var string0 = styleValue(this, name);
|
4760 | return string0 === string1 ? null
|
4761 | : string0 === string00 ? interpolate0
|
4762 | : interpolate0 = interpolate(string00 = string0, value1);
|
4763 | };
|
4764 | }
|
4765 |
|
4766 | function styleFunction(name, interpolate, value) {
|
4767 | var string00,
|
4768 | string10,
|
4769 | interpolate0;
|
4770 | return function() {
|
4771 | var string0 = styleValue(this, name),
|
4772 | value1 = value(this),
|
4773 | string1 = value1 + "";
|
4774 | if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
|
4775 | return string0 === string1 ? null
|
4776 | : string0 === string00 && string1 === string10 ? interpolate0
|
4777 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
4778 | };
|
4779 | }
|
4780 |
|
4781 | function styleMaybeRemove(id, name) {
|
4782 | var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
|
4783 | return function() {
|
4784 | var schedule = set(this, id),
|
4785 | on = schedule.on,
|
4786 | listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;
|
4787 |
|
4788 | // If this node shared a dispatch with the previous node,
|
4789 | // just assign the updated shared dispatch and we’re done!
|
4790 | // Otherwise, copy-on-write.
|
4791 | if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
|
4792 |
|
4793 | schedule.on = on1;
|
4794 | };
|
4795 | }
|
4796 |
|
4797 | function transition_style(name, value, priority) {
|
4798 | var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
|
4799 | return value == null ? this
|
4800 | .styleTween(name, styleNull(name, i))
|
4801 | .on("end.style." + name, styleRemove(name))
|
4802 | : typeof value === "function" ? this
|
4803 | .styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value)))
|
4804 | .each(styleMaybeRemove(this._id, name))
|
4805 | : this
|
4806 | .styleTween(name, styleConstant(name, i, value), priority)
|
4807 | .on("end.style." + name, null);
|
4808 | }
|
4809 |
|
4810 | function styleInterpolate(name, i, priority) {
|
4811 | return function(t) {
|
4812 | this.style.setProperty(name, i.call(this, t), priority);
|
4813 | };
|
4814 | }
|
4815 |
|
4816 | function styleTween(name, value, priority) {
|
4817 | var t, i0;
|
4818 | function tween() {
|
4819 | var i = value.apply(this, arguments);
|
4820 | if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
|
4821 | return t;
|
4822 | }
|
4823 | tween._value = value;
|
4824 | return tween;
|
4825 | }
|
4826 |
|
4827 | function transition_styleTween(name, value, priority) {
|
4828 | var key = "style." + (name += "");
|
4829 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
4830 | if (value == null) return this.tween(key, null);
|
4831 | if (typeof value !== "function") throw new Error;
|
4832 | return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
|
4833 | }
|
4834 |
|
4835 | function textConstant(value) {
|
4836 | return function() {
|
4837 | this.textContent = value;
|
4838 | };
|
4839 | }
|
4840 |
|
4841 | function textFunction(value) {
|
4842 | return function() {
|
4843 | var value1 = value(this);
|
4844 | this.textContent = value1 == null ? "" : value1;
|
4845 | };
|
4846 | }
|
4847 |
|
4848 | function transition_text(value) {
|
4849 | return this.tween("text", typeof value === "function"
|
4850 | ? textFunction(tweenValue(this, "text", value))
|
4851 | : textConstant(value == null ? "" : value + ""));
|
4852 | }
|
4853 |
|
4854 | function textInterpolate(i) {
|
4855 | return function(t) {
|
4856 | this.textContent = i.call(this, t);
|
4857 | };
|
4858 | }
|
4859 |
|
4860 | function textTween(value) {
|
4861 | var t0, i0;
|
4862 | function tween() {
|
4863 | var i = value.apply(this, arguments);
|
4864 | if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
|
4865 | return t0;
|
4866 | }
|
4867 | tween._value = value;
|
4868 | return tween;
|
4869 | }
|
4870 |
|
4871 | function transition_textTween(value) {
|
4872 | var key = "text";
|
4873 | if (arguments.length < 1) return (key = this.tween(key)) && key._value;
|
4874 | if (value == null) return this.tween(key, null);
|
4875 | if (typeof value !== "function") throw new Error;
|
4876 | return this.tween(key, textTween(value));
|
4877 | }
|
4878 |
|
4879 | function transition_transition() {
|
4880 | var name = this._name,
|
4881 | id0 = this._id,
|
4882 | id1 = newId();
|
4883 |
|
4884 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
4885 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
4886 | if (node = group[i]) {
|
4887 | var inherit = get(node, id0);
|
4888 | schedule(node, name, id1, i, group, {
|
4889 | time: inherit.time + inherit.delay + inherit.duration,
|
4890 | delay: 0,
|
4891 | duration: inherit.duration,
|
4892 | ease: inherit.ease
|
4893 | });
|
4894 | }
|
4895 | }
|
4896 | }
|
4897 |
|
4898 | return new Transition(groups, this._parents, name, id1);
|
4899 | }
|
4900 |
|
4901 | function transition_end() {
|
4902 | var on0, on1, that = this, id = that._id, size = that.size();
|
4903 | return new Promise(function(resolve, reject) {
|
4904 | var cancel = {value: reject},
|
4905 | end = {value: function() { if (--size === 0) resolve(); }};
|
4906 |
|
4907 | that.each(function() {
|
4908 | var schedule = set(this, id),
|
4909 | on = schedule.on;
|
4910 |
|
4911 | // If this node shared a dispatch with the previous node,
|
4912 | // just assign the updated shared dispatch and we’re done!
|
4913 | // Otherwise, copy-on-write.
|
4914 | if (on !== on0) {
|
4915 | on1 = (on0 = on).copy();
|
4916 | on1._.cancel.push(cancel);
|
4917 | on1._.interrupt.push(cancel);
|
4918 | on1._.end.push(end);
|
4919 | }
|
4920 |
|
4921 | schedule.on = on1;
|
4922 | });
|
4923 |
|
4924 |
|
4925 | if (size === 0) resolve();
|
4926 | });
|
4927 | }
|
4928 |
|
4929 | var id = 0;
|
4930 |
|
4931 | function Transition(groups, parents, name, id) {
|
4932 | this._groups = groups;
|
4933 | this._parents = parents;
|
4934 | this._name = name;
|
4935 | this._id = id;
|
4936 | }
|
4937 |
|
4938 | function transition(name) {
|
4939 | return selection().transition(name);
|
4940 | }
|
4941 |
|
4942 | function newId() {
|
4943 | return ++id;
|
4944 | }
|
4945 |
|
4946 | var selection_prototype = selection.prototype;
|
4947 |
|
4948 | Transition.prototype = transition.prototype = {
|
4949 | constructor: Transition,
|
4950 | select: transition_select,
|
4951 | selectAll: transition_selectAll,
|
4952 | selectChild: selection_prototype.selectChild,
|
4953 | selectChildren: selection_prototype.selectChildren,
|
4954 | filter: transition_filter,
|
4955 | merge: transition_merge,
|
4956 | selection: transition_selection,
|
4957 | transition: transition_transition,
|
4958 | call: selection_prototype.call,
|
4959 | nodes: selection_prototype.nodes,
|
4960 | node: selection_prototype.node,
|
4961 | size: selection_prototype.size,
|
4962 | empty: selection_prototype.empty,
|
4963 | each: selection_prototype.each,
|
4964 | on: transition_on,
|
4965 | attr: transition_attr,
|
4966 | attrTween: transition_attrTween,
|
4967 | style: transition_style,
|
4968 | styleTween: transition_styleTween,
|
4969 | text: transition_text,
|
4970 | textTween: transition_textTween,
|
4971 | remove: transition_remove,
|
4972 | tween: transition_tween,
|
4973 | delay: transition_delay,
|
4974 | duration: transition_duration,
|
4975 | ease: transition_ease,
|
4976 | easeVarying: transition_easeVarying,
|
4977 | end: transition_end,
|
4978 | [Symbol.iterator]: selection_prototype[Symbol.iterator]
|
4979 | };
|
4980 |
|
4981 | const linear$1 = t => +t;
|
4982 |
|
4983 | function quadIn(t) {
|
4984 | return t * t;
|
4985 | }
|
4986 |
|
4987 | function quadOut(t) {
|
4988 | return t * (2 - t);
|
4989 | }
|
4990 |
|
4991 | function quadInOut(t) {
|
4992 | return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
|
4993 | }
|
4994 |
|
4995 | function cubicIn(t) {
|
4996 | return t * t * t;
|
4997 | }
|
4998 |
|
4999 | function cubicOut(t) {
|
5000 | return --t * t * t + 1;
|
5001 | }
|
5002 |
|
5003 | function cubicInOut(t) {
|
5004 | return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
|
5005 | }
|
5006 |
|
5007 | var exponent$1 = 3;
|
5008 |
|
5009 | var polyIn = (function custom(e) {
|
5010 | e = +e;
|
5011 |
|
5012 | function polyIn(t) {
|
5013 | return Math.pow(t, e);
|
5014 | }
|
5015 |
|
5016 | polyIn.exponent = custom;
|
5017 |
|
5018 | return polyIn;
|
5019 | })(exponent$1);
|
5020 |
|
5021 | var polyOut = (function custom(e) {
|
5022 | e = +e;
|
5023 |
|
5024 | function polyOut(t) {
|
5025 | return 1 - Math.pow(1 - t, e);
|
5026 | }
|
5027 |
|
5028 | polyOut.exponent = custom;
|
5029 |
|
5030 | return polyOut;
|
5031 | })(exponent$1);
|
5032 |
|
5033 | var polyInOut = (function custom(e) {
|
5034 | e = +e;
|
5035 |
|
5036 | function polyInOut(t) {
|
5037 | return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
|
5038 | }
|
5039 |
|
5040 | polyInOut.exponent = custom;
|
5041 |
|
5042 | return polyInOut;
|
5043 | })(exponent$1);
|
5044 |
|
5045 | var pi$4 = Math.PI,
|
5046 | halfPi$3 = pi$4 / 2;
|
5047 |
|
5048 | function sinIn(t) {
|
5049 | return (+t === 1) ? 1 : 1 - Math.cos(t * halfPi$3);
|
5050 | }
|
5051 |
|
5052 | function sinOut(t) {
|
5053 | return Math.sin(t * halfPi$3);
|
5054 | }
|
5055 |
|
5056 | function sinInOut(t) {
|
5057 | return (1 - Math.cos(pi$4 * t)) / 2;
|
5058 | }
|
5059 |
|
5060 |
|
5061 | function tpmt(x) {
|
5062 | return (Math.pow(2, -10 * x) - 0.0009765625) * 1.0009775171065494;
|
5063 | }
|
5064 |
|
5065 | function expIn(t) {
|
5066 | return tpmt(1 - +t);
|
5067 | }
|
5068 |
|
5069 | function expOut(t) {
|
5070 | return 1 - tpmt(t);
|
5071 | }
|
5072 |
|
5073 | function expInOut(t) {
|
5074 | return ((t *= 2) <= 1 ? tpmt(1 - t) : 2 - tpmt(t - 1)) / 2;
|
5075 | }
|
5076 |
|
5077 | function circleIn(t) {
|
5078 | return 1 - Math.sqrt(1 - t * t);
|
5079 | }
|
5080 |
|
5081 | function circleOut(t) {
|
5082 | return Math.sqrt(1 - --t * t);
|
5083 | }
|
5084 |
|
5085 | function circleInOut(t) {
|
5086 | return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
|
5087 | }
|
5088 |
|
5089 | var b1 = 4 / 11,
|
5090 | b2 = 6 / 11,
|
5091 | b3 = 8 / 11,
|
5092 | b4 = 3 / 4,
|
5093 | b5 = 9 / 11,
|
5094 | b6 = 10 / 11,
|
5095 | b7 = 15 / 16,
|
5096 | b8 = 21 / 22,
|
5097 | b9 = 63 / 64,
|
5098 | b0 = 1 / b1 / b1;
|
5099 |
|
5100 | function bounceIn(t) {
|
5101 | return 1 - bounceOut(1 - t);
|
5102 | }
|
5103 |
|
5104 | function bounceOut(t) {
|
5105 | 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;
|
5106 | }
|
5107 |
|
5108 | function bounceInOut(t) {
|
5109 | return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
|
5110 | }
|
5111 |
|
5112 | var overshoot = 1.70158;
|
5113 |
|
5114 | var backIn = (function custom(s) {
|
5115 | s = +s;
|
5116 |
|
5117 | function backIn(t) {
|
5118 | return (t = +t) * t * (s * (t - 1) + t);
|
5119 | }
|
5120 |
|
5121 | backIn.overshoot = custom;
|
5122 |
|
5123 | return backIn;
|
5124 | })(overshoot);
|
5125 |
|
5126 | var backOut = (function custom(s) {
|
5127 | s = +s;
|
5128 |
|
5129 | function backOut(t) {
|
5130 | return --t * t * ((t + 1) * s + t) + 1;
|
5131 | }
|
5132 |
|
5133 | backOut.overshoot = custom;
|
5134 |
|
5135 | return backOut;
|
5136 | })(overshoot);
|
5137 |
|
5138 | var backInOut = (function custom(s) {
|
5139 | s = +s;
|
5140 |
|
5141 | function backInOut(t) {
|
5142 | return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
|
5143 | }
|
5144 |
|
5145 | backInOut.overshoot = custom;
|
5146 |
|
5147 | return backInOut;
|
5148 | })(overshoot);
|
5149 |
|
5150 | var tau$5 = 2 * Math.PI,
|
5151 | amplitude = 1,
|
5152 | period = 0.3;
|
5153 |
|
5154 | var elasticIn = (function custom(a, p) {
|
5155 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
|
5156 |
|
5157 | function elasticIn(t) {
|
5158 | return a * tpmt(-(--t)) * Math.sin((s - t) / p);
|
5159 | }
|
5160 |
|
5161 | elasticIn.amplitude = function(a) { return custom(a, p * tau$5); };
|
5162 | elasticIn.period = function(p) { return custom(a, p); };
|
5163 |
|
5164 | return elasticIn;
|
5165 | })(amplitude, period);
|
5166 |
|
5167 | var elasticOut = (function custom(a, p) {
|
5168 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
|
5169 |
|
5170 | function elasticOut(t) {
|
5171 | return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p);
|
5172 | }
|
5173 |
|
5174 | elasticOut.amplitude = function(a) { return custom(a, p * tau$5); };
|
5175 | elasticOut.period = function(p) { return custom(a, p); };
|
5176 |
|
5177 | return elasticOut;
|
5178 | })(amplitude, period);
|
5179 |
|
5180 | var elasticInOut = (function custom(a, p) {
|
5181 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
|
5182 |
|
5183 | function elasticInOut(t) {
|
5184 | return ((t = t * 2 - 1) < 0
|
5185 | ? a * tpmt(-t) * Math.sin((s - t) / p)
|
5186 | : 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2;
|
5187 | }
|
5188 |
|
5189 | elasticInOut.amplitude = function(a) { return custom(a, p * tau$5); };
|
5190 | elasticInOut.period = function(p) { return custom(a, p); };
|
5191 |
|
5192 | return elasticInOut;
|
5193 | })(amplitude, period);
|
5194 |
|
5195 | var defaultTiming = {
|
5196 | time: null,
|
5197 | delay: 0,
|
5198 | duration: 250,
|
5199 | ease: cubicInOut
|
5200 | };
|
5201 |
|
5202 | function inherit(node, id) {
|
5203 | var timing;
|
5204 | while (!(timing = node.__transition) || !(timing = timing[id])) {
|
5205 | if (!(node = node.parentNode)) {
|
5206 | throw new Error(`transition ${id} not found`);
|
5207 | }
|
5208 | }
|
5209 | return timing;
|
5210 | }
|
5211 |
|
5212 | function selection_transition(name) {
|
5213 | var id,
|
5214 | timing;
|
5215 |
|
5216 | if (name instanceof Transition) {
|
5217 | id = name._id, name = name._name;
|
5218 | } else {
|
5219 | id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
|
5220 | }
|
5221 |
|
5222 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
5223 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
5224 | if (node = group[i]) {
|
5225 | schedule(node, name, id, i, group, timing || inherit(node, id));
|
5226 | }
|
5227 | }
|
5228 | }
|
5229 |
|
5230 | return new Transition(groups, this._parents, name, id);
|
5231 | }
|
5232 |
|
5233 | selection.prototype.interrupt = selection_interrupt;
|
5234 | selection.prototype.transition = selection_transition;
|
5235 |
|
5236 | var root = [null];
|
5237 |
|
5238 | function active(node, name) {
|
5239 | var schedules = node.__transition,
|
5240 | schedule,
|
5241 | i;
|
5242 |
|
5243 | if (schedules) {
|
5244 | name = name == null ? null : name + "";
|
5245 | for (i in schedules) {
|
5246 | if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
|
5247 | return new Transition([[node]], root, name, +i);
|
5248 | }
|
5249 | }
|
5250 | }
|
5251 |
|
5252 | return null;
|
5253 | }
|
5254 |
|
5255 | var constant$7 = x => () => x;
|
5256 |
|
5257 | function BrushEvent(type, {
|
5258 | sourceEvent,
|
5259 | target,
|
5260 | selection,
|
5261 | mode,
|
5262 | dispatch
|
5263 | }) {
|
5264 | Object.defineProperties(this, {
|
5265 | type: {value: type, enumerable: true, configurable: true},
|
5266 | sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
|
5267 | target: {value: target, enumerable: true, configurable: true},
|
5268 | selection: {value: selection, enumerable: true, configurable: true},
|
5269 | mode: {value: mode, enumerable: true, configurable: true},
|
5270 | _: {value: dispatch}
|
5271 | });
|
5272 | }
|
5273 |
|
5274 | function nopropagation$1(event) {
|
5275 | event.stopImmediatePropagation();
|
5276 | }
|
5277 |
|
5278 | function noevent$1(event) {
|
5279 | event.preventDefault();
|
5280 | event.stopImmediatePropagation();
|
5281 | }
|
5282 |
|
5283 | var MODE_DRAG = {name: "drag"},
|
5284 | MODE_SPACE = {name: "space"},
|
5285 | MODE_HANDLE = {name: "handle"},
|
5286 | MODE_CENTER = {name: "center"};
|
5287 |
|
5288 | const {abs: abs$3, max: max$2, min: min$1} = Math;
|
5289 |
|
5290 | function number1(e) {
|
5291 | return [+e[0], +e[1]];
|
5292 | }
|
5293 |
|
5294 | function number2(e) {
|
5295 | return [number1(e[0]), number1(e[1])];
|
5296 | }
|
5297 |
|
5298 | var X = {
|
5299 | name: "x",
|
5300 | handles: ["w", "e"].map(type),
|
5301 | input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
|
5302 | output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
|
5303 | };
|
5304 |
|
5305 | var Y = {
|
5306 | name: "y",
|
5307 | handles: ["n", "s"].map(type),
|
5308 | input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
|
5309 | output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
|
5310 | };
|
5311 |
|
5312 | var XY = {
|
5313 | name: "xy",
|
5314 | handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
|
5315 | input: function(xy) { return xy == null ? null : number2(xy); },
|
5316 | output: function(xy) { return xy; }
|
5317 | };
|
5318 |
|
5319 | var cursors = {
|
5320 | overlay: "crosshair",
|
5321 | selection: "move",
|
5322 | n: "ns-resize",
|
5323 | e: "ew-resize",
|
5324 | s: "ns-resize",
|
5325 | w: "ew-resize",
|
5326 | nw: "nwse-resize",
|
5327 | ne: "nesw-resize",
|
5328 | se: "nwse-resize",
|
5329 | sw: "nesw-resize"
|
5330 | };
|
5331 |
|
5332 | var flipX = {
|
5333 | e: "w",
|
5334 | w: "e",
|
5335 | nw: "ne",
|
5336 | ne: "nw",
|
5337 | se: "sw",
|
5338 | sw: "se"
|
5339 | };
|
5340 |
|
5341 | var flipY = {
|
5342 | n: "s",
|
5343 | s: "n",
|
5344 | nw: "sw",
|
5345 | ne: "se",
|
5346 | se: "ne",
|
5347 | sw: "nw"
|
5348 | };
|
5349 |
|
5350 | var signsX = {
|
5351 | overlay: +1,
|
5352 | selection: +1,
|
5353 | n: null,
|
5354 | e: +1,
|
5355 | s: null,
|
5356 | w: -1,
|
5357 | nw: -1,
|
5358 | ne: +1,
|
5359 | se: +1,
|
5360 | sw: -1
|
5361 | };
|
5362 |
|
5363 | var signsY = {
|
5364 | overlay: +1,
|
5365 | selection: +1,
|
5366 | n: -1,
|
5367 | e: null,
|
5368 | s: +1,
|
5369 | w: null,
|
5370 | nw: -1,
|
5371 | ne: -1,
|
5372 | se: +1,
|
5373 | sw: +1
|
5374 | };
|
5375 |
|
5376 | function type(t) {
|
5377 | return {type: t};
|
5378 | }
|
5379 |
|
5380 |
|
5381 | function defaultFilter$1(event) {
|
5382 | return !event.ctrlKey && !event.button;
|
5383 | }
|
5384 |
|
5385 | function defaultExtent$1() {
|
5386 | var svg = this.ownerSVGElement || this;
|
5387 | if (svg.hasAttribute("viewBox")) {
|
5388 | svg = svg.viewBox.baseVal;
|
5389 | return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
|
5390 | }
|
5391 | return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
|
5392 | }
|
5393 |
|
5394 | function defaultTouchable$1() {
|
5395 | return navigator.maxTouchPoints || ("ontouchstart" in this);
|
5396 | }
|
5397 |
|
5398 |
|
5399 | function local(node) {
|
5400 | while (!node.__brush) if (!(node = node.parentNode)) return;
|
5401 | return node.__brush;
|
5402 | }
|
5403 |
|
5404 | function empty(extent) {
|
5405 | return extent[0][0] === extent[1][0]
|
5406 | || extent[0][1] === extent[1][1];
|
5407 | }
|
5408 |
|
5409 | function brushSelection(node) {
|
5410 | var state = node.__brush;
|
5411 | return state ? state.dim.output(state.selection) : null;
|
5412 | }
|
5413 |
|
5414 | function brushX() {
|
5415 | return brush$1(X);
|
5416 | }
|
5417 |
|
5418 | function brushY() {
|
5419 | return brush$1(Y);
|
5420 | }
|
5421 |
|
5422 | function brush() {
|
5423 | return brush$1(XY);
|
5424 | }
|
5425 |
|
5426 | function brush$1(dim) {
|
5427 | var extent = defaultExtent$1,
|
5428 | filter = defaultFilter$1,
|
5429 | touchable = defaultTouchable$1,
|
5430 | keys = true,
|
5431 | listeners = dispatch("start", "brush", "end"),
|
5432 | handleSize = 6,
|
5433 | touchending;
|
5434 |
|
5435 | function brush(group) {
|
5436 | var overlay = group
|
5437 | .property("__brush", initialize)
|
5438 | .selectAll(".overlay")
|
5439 | .data([type("overlay")]);
|
5440 |
|
5441 | overlay.enter().append("rect")
|
5442 | .attr("class", "overlay")
|
5443 | .attr("pointer-events", "all")
|
5444 | .attr("cursor", cursors.overlay)
|
5445 | .merge(overlay)
|
5446 | .each(function() {
|
5447 | var extent = local(this).extent;
|
5448 | select(this)
|
5449 | .attr("x", extent[0][0])
|
5450 | .attr("y", extent[0][1])
|
5451 | .attr("width", extent[1][0] - extent[0][0])
|
5452 | .attr("height", extent[1][1] - extent[0][1]);
|
5453 | });
|
5454 |
|
5455 | group.selectAll(".selection")
|
5456 | .data([type("selection")])
|
5457 | .enter().append("rect")
|
5458 | .attr("class", "selection")
|
5459 | .attr("cursor", cursors.selection)
|
5460 | .attr("fill", "#777")
|
5461 | .attr("fill-opacity", 0.3)
|
5462 | .attr("stroke", "#fff")
|
5463 | .attr("shape-rendering", "crispEdges");
|
5464 |
|
5465 | var handle = group.selectAll(".handle")
|
5466 | .data(dim.handles, function(d) { return d.type; });
|
5467 |
|
5468 | handle.exit().remove();
|
5469 |
|
5470 | handle.enter().append("rect")
|
5471 | .attr("class", function(d) { return "handle handle--" + d.type; })
|
5472 | .attr("cursor", function(d) { return cursors[d.type]; });
|
5473 |
|
5474 | group
|
5475 | .each(redraw)
|
5476 | .attr("fill", "none")
|
5477 | .attr("pointer-events", "all")
|
5478 | .on("mousedown.brush", started)
|
5479 | .filter(touchable)
|
5480 | .on("touchstart.brush", started)
|
5481 | .on("touchmove.brush", touchmoved)
|
5482 | .on("touchend.brush touchcancel.brush", touchended)
|
5483 | .style("touch-action", "none")
|
5484 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
5485 | }
|
5486 |
|
5487 | brush.move = function(group, selection, event) {
|
5488 | if (group.tween) {
|
5489 | group
|
5490 | .on("start.brush", function(event) { emitter(this, arguments).beforestart().start(event); })
|
5491 | .on("interrupt.brush end.brush", function(event) { emitter(this, arguments).end(event); })
|
5492 | .tween("brush", function() {
|
5493 | var that = this,
|
5494 | state = that.__brush,
|
5495 | emit = emitter(that, arguments),
|
5496 | selection0 = state.selection,
|
5497 | selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
|
5498 | i = interpolate$2(selection0, selection1);
|
5499 |
|
5500 | function tween(t) {
|
5501 | state.selection = t === 1 && selection1 === null ? null : i(t);
|
5502 | redraw.call(that);
|
5503 | emit.brush();
|
5504 | }
|
5505 |
|
5506 | return selection0 !== null && selection1 !== null ? tween : tween(1);
|
5507 | });
|
5508 | } else {
|
5509 | group
|
5510 | .each(function() {
|
5511 | var that = this,
|
5512 | args = arguments,
|
5513 | state = that.__brush,
|
5514 | selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
|
5515 | emit = emitter(that, args).beforestart();
|
5516 |
|
5517 | interrupt(that);
|
5518 | state.selection = selection1 === null ? null : selection1;
|
5519 | redraw.call(that);
|
5520 | emit.start(event).brush(event).end(event);
|
5521 | });
|
5522 | }
|
5523 | };
|
5524 |
|
5525 | brush.clear = function(group, event) {
|
5526 | brush.move(group, null, event);
|
5527 | };
|
5528 |
|
5529 | function redraw() {
|
5530 | var group = select(this),
|
5531 | selection = local(this).selection;
|
5532 |
|
5533 | if (selection) {
|
5534 | group.selectAll(".selection")
|
5535 | .style("display", null)
|
5536 | .attr("x", selection[0][0])
|
5537 | .attr("y", selection[0][1])
|
5538 | .attr("width", selection[1][0] - selection[0][0])
|
5539 | .attr("height", selection[1][1] - selection[0][1]);
|
5540 |
|
5541 | group.selectAll(".handle")
|
5542 | .style("display", null)
|
5543 | .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
|
5544 | .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
|
5545 | .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
|
5546 | .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
|
5547 | }
|
5548 |
|
5549 | else {
|
5550 | group.selectAll(".selection,.handle")
|
5551 | .style("display", "none")
|
5552 | .attr("x", null)
|
5553 | .attr("y", null)
|
5554 | .attr("width", null)
|
5555 | .attr("height", null);
|
5556 | }
|
5557 | }
|
5558 |
|
5559 | function emitter(that, args, clean) {
|
5560 | var emit = that.__brush.emitter;
|
5561 | return emit && (!clean || !emit.clean) ? emit : new Emitter(that, args, clean);
|
5562 | }
|
5563 |
|
5564 | function Emitter(that, args, clean) {
|
5565 | this.that = that;
|
5566 | this.args = args;
|
5567 | this.state = that.__brush;
|
5568 | this.active = 0;
|
5569 | this.clean = clean;
|
5570 | }
|
5571 |
|
5572 | Emitter.prototype = {
|
5573 | beforestart: function() {
|
5574 | if (++this.active === 1) this.state.emitter = this, this.starting = true;
|
5575 | return this;
|
5576 | },
|
5577 | start: function(event, mode) {
|
5578 | if (this.starting) this.starting = false, this.emit("start", event, mode);
|
5579 | else this.emit("brush", event);
|
5580 | return this;
|
5581 | },
|
5582 | brush: function(event, mode) {
|
5583 | this.emit("brush", event, mode);
|
5584 | return this;
|
5585 | },
|
5586 | end: function(event, mode) {
|
5587 | if (--this.active === 0) delete this.state.emitter, this.emit("end", event, mode);
|
5588 | return this;
|
5589 | },
|
5590 | emit: function(type, event, mode) {
|
5591 | var d = select(this.that).datum();
|
5592 | listeners.call(
|
5593 | type,
|
5594 | this.that,
|
5595 | new BrushEvent(type, {
|
5596 | sourceEvent: event,
|
5597 | target: brush,
|
5598 | selection: dim.output(this.state.selection),
|
5599 | mode,
|
5600 | dispatch: listeners
|
5601 | }),
|
5602 | d
|
5603 | );
|
5604 | }
|
5605 | };
|
5606 |
|
5607 | function started(event) {
|
5608 | if (touchending && !event.touches) return;
|
5609 | if (!filter.apply(this, arguments)) return;
|
5610 |
|
5611 | var that = this,
|
5612 | type = event.target.__data__.type,
|
5613 | mode = (keys && event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && event.altKey ? MODE_CENTER : MODE_HANDLE),
|
5614 | signX = dim === Y ? null : signsX[type],
|
5615 | signY = dim === X ? null : signsY[type],
|
5616 | state = local(that),
|
5617 | extent = state.extent,
|
5618 | selection = state.selection,
|
5619 | W = extent[0][0], w0, w1,
|
5620 | N = extent[0][1], n0, n1,
|
5621 | E = extent[1][0], e0, e1,
|
5622 | S = extent[1][1], s0, s1,
|
5623 | dx = 0,
|
5624 | dy = 0,
|
5625 | moving,
|
5626 | shifting = signX && signY && keys && event.shiftKey,
|
5627 | lockX,
|
5628 | lockY,
|
5629 | points = Array.from(event.touches || [event], t => {
|
5630 | const i = t.identifier;
|
5631 | t = pointer(t, that);
|
5632 | t.point0 = t.slice();
|
5633 | t.identifier = i;
|
5634 | return t;
|
5635 | });
|
5636 |
|
5637 | interrupt(that);
|
5638 | var emit = emitter(that, arguments, true).beforestart();
|
5639 |
|
5640 | if (type === "overlay") {
|
5641 | if (selection) moving = true;
|
5642 | const pts = [points[0], points[1] || points[0]];
|
5643 | state.selection = selection = [[
|
5644 | w0 = dim === Y ? W : min$1(pts[0][0], pts[1][0]),
|
5645 | n0 = dim === X ? N : min$1(pts[0][1], pts[1][1])
|
5646 | ], [
|
5647 | e0 = dim === Y ? E : max$2(pts[0][0], pts[1][0]),
|
5648 | s0 = dim === X ? S : max$2(pts[0][1], pts[1][1])
|
5649 | ]];
|
5650 | if (points.length > 1) move(event);
|
5651 | } else {
|
5652 | w0 = selection[0][0];
|
5653 | n0 = selection[0][1];
|
5654 | e0 = selection[1][0];
|
5655 | s0 = selection[1][1];
|
5656 | }
|
5657 |
|
5658 | w1 = w0;
|
5659 | n1 = n0;
|
5660 | e1 = e0;
|
5661 | s1 = s0;
|
5662 |
|
5663 | var group = select(that)
|
5664 | .attr("pointer-events", "none");
|
5665 |
|
5666 | var overlay = group.selectAll(".overlay")
|
5667 | .attr("cursor", cursors[type]);
|
5668 |
|
5669 | if (event.touches) {
|
5670 | emit.moved = moved;
|
5671 | emit.ended = ended;
|
5672 | } else {
|
5673 | var view = select(event.view)
|
5674 | .on("mousemove.brush", moved, true)
|
5675 | .on("mouseup.brush", ended, true);
|
5676 | if (keys) view
|
5677 | .on("keydown.brush", keydowned, true)
|
5678 | .on("keyup.brush", keyupped, true);
|
5679 |
|
5680 | dragDisable(event.view);
|
5681 | }
|
5682 |
|
5683 | redraw.call(that);
|
5684 | emit.start(event, mode.name);
|
5685 |
|
5686 | function moved(event) {
|
5687 | for (const p of event.changedTouches || [event]) {
|
5688 | for (const d of points)
|
5689 | if (d.identifier === p.identifier) d.cur = pointer(p, that);
|
5690 | }
|
5691 | if (shifting && !lockX && !lockY && points.length === 1) {
|
5692 | const point = points[0];
|
5693 | if (abs$3(point.cur[0] - point[0]) > abs$3(point.cur[1] - point[1]))
|
5694 | lockY = true;
|
5695 | else
|
5696 | lockX = true;
|
5697 | }
|
5698 | for (const point of points)
|
5699 | if (point.cur) point[0] = point.cur[0], point[1] = point.cur[1];
|
5700 | moving = true;
|
5701 | noevent$1(event);
|
5702 | move(event);
|
5703 | }
|
5704 |
|
5705 | function move(event) {
|
5706 | const point = points[0], point0 = point.point0;
|
5707 | var t;
|
5708 |
|
5709 | dx = point[0] - point0[0];
|
5710 | dy = point[1] - point0[1];
|
5711 |
|
5712 | switch (mode) {
|
5713 | case MODE_SPACE:
|
5714 | case MODE_DRAG: {
|
5715 | if (signX) dx = max$2(W - w0, min$1(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
|
5716 | if (signY) dy = max$2(N - n0, min$1(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
|
5717 | break;
|
5718 | }
|
5719 | case MODE_HANDLE: {
|
5720 | if (points[1]) {
|
5721 | if (signX) w1 = max$2(W, min$1(E, points[0][0])), e1 = max$2(W, min$1(E, points[1][0])), signX = 1;
|
5722 | if (signY) n1 = max$2(N, min$1(S, points[0][1])), s1 = max$2(N, min$1(S, points[1][1])), signY = 1;
|
5723 | } else {
|
5724 | if (signX < 0) dx = max$2(W - w0, min$1(E - w0, dx)), w1 = w0 + dx, e1 = e0;
|
5725 | else if (signX > 0) dx = max$2(W - e0, min$1(E - e0, dx)), w1 = w0, e1 = e0 + dx;
|
5726 | if (signY < 0) dy = max$2(N - n0, min$1(S - n0, dy)), n1 = n0 + dy, s1 = s0;
|
5727 | else if (signY > 0) dy = max$2(N - s0, min$1(S - s0, dy)), n1 = n0, s1 = s0 + dy;
|
5728 | }
|
5729 | break;
|
5730 | }
|
5731 | case MODE_CENTER: {
|
5732 | if (signX) w1 = max$2(W, min$1(E, w0 - dx * signX)), e1 = max$2(W, min$1(E, e0 + dx * signX));
|
5733 | if (signY) n1 = max$2(N, min$1(S, n0 - dy * signY)), s1 = max$2(N, min$1(S, s0 + dy * signY));
|
5734 | break;
|
5735 | }
|
5736 | }
|
5737 |
|
5738 | if (e1 < w1) {
|
5739 | signX *= -1;
|
5740 | t = w0, w0 = e0, e0 = t;
|
5741 | t = w1, w1 = e1, e1 = t;
|
5742 | if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
|
5743 | }
|
5744 |
|
5745 | if (s1 < n1) {
|
5746 | signY *= -1;
|
5747 | t = n0, n0 = s0, s0 = t;
|
5748 | t = n1, n1 = s1, s1 = t;
|
5749 | if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
|
5750 | }
|
5751 |
|
5752 | if (state.selection) selection = state.selection;
|
5753 | if (lockX) w1 = selection[0][0], e1 = selection[1][0];
|
5754 | if (lockY) n1 = selection[0][1], s1 = selection[1][1];
|
5755 |
|
5756 | if (selection[0][0] !== w1
|
5757 | || selection[0][1] !== n1
|
5758 | || selection[1][0] !== e1
|
5759 | || selection[1][1] !== s1) {
|
5760 | state.selection = [[w1, n1], [e1, s1]];
|
5761 | redraw.call(that);
|
5762 | emit.brush(event, mode.name);
|
5763 | }
|
5764 | }
|
5765 |
|
5766 | function ended(event) {
|
5767 | nopropagation$1(event);
|
5768 | if (event.touches) {
|
5769 | if (event.touches.length) return;
|
5770 | if (touchending) clearTimeout(touchending);
|
5771 | touchending = setTimeout(function() { touchending = null; }, 500);
|
5772 | } else {
|
5773 | yesdrag(event.view, moving);
|
5774 | view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
|
5775 | }
|
5776 | group.attr("pointer-events", "all");
|
5777 | overlay.attr("cursor", cursors.overlay);
|
5778 | if (state.selection) selection = state.selection;
|
5779 | if (empty(selection)) state.selection = null, redraw.call(that);
|
5780 | emit.end(event, mode.name);
|
5781 | }
|
5782 |
|
5783 | function keydowned(event) {
|
5784 | switch (event.keyCode) {
|
5785 | case 16: {
|
5786 | shifting = signX && signY;
|
5787 | break;
|
5788 | }
|
5789 | case 18: {
|
5790 | if (mode === MODE_HANDLE) {
|
5791 | if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
|
5792 | if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
|
5793 | mode = MODE_CENTER;
|
5794 | move(event);
|
5795 | }
|
5796 | break;
|
5797 | }
|
5798 | case 32: {
|
5799 | if (mode === MODE_HANDLE || mode === MODE_CENTER) {
|
5800 | if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
|
5801 | if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
|
5802 | mode = MODE_SPACE;
|
5803 | overlay.attr("cursor", cursors.selection);
|
5804 | move(event);
|
5805 | }
|
5806 | break;
|
5807 | }
|
5808 | default: return;
|
5809 | }
|
5810 | noevent$1(event);
|
5811 | }
|
5812 |
|
5813 | function keyupped(event) {
|
5814 | switch (event.keyCode) {
|
5815 | case 16: {
|
5816 | if (shifting) {
|
5817 | lockX = lockY = shifting = false;
|
5818 | move(event);
|
5819 | }
|
5820 | break;
|
5821 | }
|
5822 | case 18: {
|
5823 | if (mode === MODE_CENTER) {
|
5824 | if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
|
5825 | if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
|
5826 | mode = MODE_HANDLE;
|
5827 | move(event);
|
5828 | }
|
5829 | break;
|
5830 | }
|
5831 | case 32: {
|
5832 | if (mode === MODE_SPACE) {
|
5833 | if (event.altKey) {
|
5834 | if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
|
5835 | if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
|
5836 | mode = MODE_CENTER;
|
5837 | } else {
|
5838 | if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
|
5839 | if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
|
5840 | mode = MODE_HANDLE;
|
5841 | }
|
5842 | overlay.attr("cursor", cursors[type]);
|
5843 | move(event);
|
5844 | }
|
5845 | break;
|
5846 | }
|
5847 | default: return;
|
5848 | }
|
5849 | noevent$1(event);
|
5850 | }
|
5851 | }
|
5852 |
|
5853 | function touchmoved(event) {
|
5854 | emitter(this, arguments).moved(event);
|
5855 | }
|
5856 |
|
5857 | function touchended(event) {
|
5858 | emitter(this, arguments).ended(event);
|
5859 | }
|
5860 |
|
5861 | function initialize() {
|
5862 | var state = this.__brush || {selection: null};
|
5863 | state.extent = number2(extent.apply(this, arguments));
|
5864 | state.dim = dim;
|
5865 | return state;
|
5866 | }
|
5867 |
|
5868 | brush.extent = function(_) {
|
5869 | return arguments.length ? (extent = typeof _ === "function" ? _ : constant$7(number2(_)), brush) : extent;
|
5870 | };
|
5871 |
|
5872 | brush.filter = function(_) {
|
5873 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), brush) : filter;
|
5874 | };
|
5875 |
|
5876 | brush.touchable = function(_) {
|
5877 | return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$7(!!_), brush) : touchable;
|
5878 | };
|
5879 |
|
5880 | brush.handleSize = function(_) {
|
5881 | return arguments.length ? (handleSize = +_, brush) : handleSize;
|
5882 | };
|
5883 |
|
5884 | brush.keyModifiers = function(_) {
|
5885 | return arguments.length ? (keys = !!_, brush) : keys;
|
5886 | };
|
5887 |
|
5888 | brush.on = function() {
|
5889 | var value = listeners.on.apply(listeners, arguments);
|
5890 | return value === listeners ? brush : value;
|
5891 | };
|
5892 |
|
5893 | return brush;
|
5894 | }
|
5895 |
|
5896 | var abs$2 = Math.abs;
|
5897 | var cos$2 = Math.cos;
|
5898 | var sin$2 = Math.sin;
|
5899 | var pi$3 = Math.PI;
|
5900 | var halfPi$2 = pi$3 / 2;
|
5901 | var tau$4 = pi$3 * 2;
|
5902 | var max$1 = Math.max;
|
5903 | var epsilon$5 = 1e-12;
|
5904 |
|
5905 | function range$1(i, j) {
|
5906 | return Array.from({length: j - i}, (_, k) => i + k);
|
5907 | }
|
5908 |
|
5909 | function compareValue(compare) {
|
5910 | return function(a, b) {
|
5911 | return compare(
|
5912 | a.source.value + a.target.value,
|
5913 | b.source.value + b.target.value
|
5914 | );
|
5915 | };
|
5916 | }
|
5917 |
|
5918 | function chord() {
|
5919 | return chord$1(false, false);
|
5920 | }
|
5921 |
|
5922 | function chordTranspose() {
|
5923 | return chord$1(false, true);
|
5924 | }
|
5925 |
|
5926 | function chordDirected() {
|
5927 | return chord$1(true, false);
|
5928 | }
|
5929 |
|
5930 | function chord$1(directed, transpose) {
|
5931 | var padAngle = 0,
|
5932 | sortGroups = null,
|
5933 | sortSubgroups = null,
|
5934 | sortChords = null;
|
5935 |
|
5936 | function chord(matrix) {
|
5937 | var n = matrix.length,
|
5938 | groupSums = new Array(n),
|
5939 | groupIndex = range$1(0, n),
|
5940 | chords = new Array(n * n),
|
5941 | groups = new Array(n),
|
5942 | k = 0, dx;
|
5943 |
|
5944 | matrix = Float64Array.from({length: n * n}, transpose
|
5945 | ? (_, i) => matrix[i % n][i / n | 0]
|
5946 | : (_, i) => matrix[i / n | 0][i % n]);
|
5947 |
|
5948 |
|
5949 | for (let i = 0; i < n; ++i) {
|
5950 | let x = 0;
|
5951 | for (let j = 0; j < n; ++j) x += matrix[i * n + j] + directed * matrix[j * n + i];
|
5952 | k += groupSums[i] = x;
|
5953 | }
|
5954 | k = max$1(0, tau$4 - padAngle * n) / k;
|
5955 | dx = k ? padAngle : tau$4 / n;
|
5956 |
|
5957 |
|
5958 | {
|
5959 | let x = 0;
|
5960 | if (sortGroups) groupIndex.sort((a, b) => sortGroups(groupSums[a], groupSums[b]));
|
5961 | for (const i of groupIndex) {
|
5962 | const x0 = x;
|
5963 | if (directed) {
|
5964 | const subgroupIndex = range$1(~n + 1, n).filter(j => j < 0 ? matrix[~j * n + i] : matrix[i * n + j]);
|
5965 | if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(a < 0 ? -matrix[~a * n + i] : matrix[i * n + a], b < 0 ? -matrix[~b * n + i] : matrix[i * n + b]));
|
5966 | for (const j of subgroupIndex) {
|
5967 | if (j < 0) {
|
5968 | const chord = chords[~j * n + i] || (chords[~j * n + i] = {source: null, target: null});
|
5969 | chord.target = {index: i, startAngle: x, endAngle: x += matrix[~j * n + i] * k, value: matrix[~j * n + i]};
|
5970 | } else {
|
5971 | const chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
|
5972 | chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
|
5973 | }
|
5974 | }
|
5975 | groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
|
5976 | } else {
|
5977 | const subgroupIndex = range$1(0, n).filter(j => matrix[i * n + j] || matrix[j * n + i]);
|
5978 | if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(matrix[i * n + a], matrix[i * n + b]));
|
5979 | for (const j of subgroupIndex) {
|
5980 | let chord;
|
5981 | if (i < j) {
|
5982 | chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
|
5983 | chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
|
5984 | } else {
|
5985 | chord = chords[j * n + i] || (chords[j * n + i] = {source: null, target: null});
|
5986 | chord.target = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
|
5987 | if (i === j) chord.source = chord.target;
|
5988 | }
|
5989 | if (chord.source && chord.target && chord.source.value < chord.target.value) {
|
5990 | const source = chord.source;
|
5991 | chord.source = chord.target;
|
5992 | chord.target = source;
|
5993 | }
|
5994 | }
|
5995 | groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
|
5996 | }
|
5997 | x += dx;
|
5998 | }
|
5999 | }
|
6000 |
|
6001 |
|
6002 | chords = Object.values(chords);
|
6003 | chords.groups = groups;
|
6004 | return sortChords ? chords.sort(sortChords) : chords;
|
6005 | }
|
6006 |
|
6007 | chord.padAngle = function(_) {
|
6008 | return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
|
6009 | };
|
6010 |
|
6011 | chord.sortGroups = function(_) {
|
6012 | return arguments.length ? (sortGroups = _, chord) : sortGroups;
|
6013 | };
|
6014 |
|
6015 | chord.sortSubgroups = function(_) {
|
6016 | return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
|
6017 | };
|
6018 |
|
6019 | chord.sortChords = function(_) {
|
6020 | return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
|
6021 | };
|
6022 |
|
6023 | return chord;
|
6024 | }
|
6025 |
|
6026 | const pi$2 = Math.PI,
|
6027 | tau$3 = 2 * pi$2,
|
6028 | epsilon$4 = 1e-6,
|
6029 | tauEpsilon = tau$3 - epsilon$4;
|
6030 |
|
6031 | function Path$1() {
|
6032 | this._x0 = this._y0 =
|
6033 | this._x1 = this._y1 = null;
|
6034 | this._ = "";
|
6035 | }
|
6036 |
|
6037 | function path() {
|
6038 | return new Path$1;
|
6039 | }
|
6040 |
|
6041 | Path$1.prototype = path.prototype = {
|
6042 | constructor: Path$1,
|
6043 | moveTo: function(x, y) {
|
6044 | this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
|
6045 | },
|
6046 | closePath: function() {
|
6047 | if (this._x1 !== null) {
|
6048 | this._x1 = this._x0, this._y1 = this._y0;
|
6049 | this._ += "Z";
|
6050 | }
|
6051 | },
|
6052 | lineTo: function(x, y) {
|
6053 | this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
|
6054 | },
|
6055 | quadraticCurveTo: function(x1, y1, x, y) {
|
6056 | this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
6057 | },
|
6058 | bezierCurveTo: function(x1, y1, x2, y2, x, y) {
|
6059 | this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
6060 | },
|
6061 | arcTo: function(x1, y1, x2, y2, r) {
|
6062 | x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
|
6063 | var x0 = this._x1,
|
6064 | y0 = this._y1,
|
6065 | x21 = x2 - x1,
|
6066 | y21 = y2 - y1,
|
6067 | x01 = x0 - x1,
|
6068 | y01 = y0 - y1,
|
6069 | l01_2 = x01 * x01 + y01 * y01;
|
6070 |
|
6071 |
|
6072 | if (r < 0) throw new Error("negative radius: " + r);
|
6073 |
|
6074 |
|
6075 | if (this._x1 === null) {
|
6076 | this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
|
6077 | }
|
6078 |
|
6079 |
|
6080 | else if (!(l01_2 > epsilon$4));
|
6081 |
|
6082 |
|
6083 |
|
6084 |
|
6085 | else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$4) || !r) {
|
6086 | this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
|
6087 | }
|
6088 |
|
6089 |
|
6090 | else {
|
6091 | var x20 = x2 - x0,
|
6092 | y20 = y2 - y0,
|
6093 | l21_2 = x21 * x21 + y21 * y21,
|
6094 | l20_2 = x20 * x20 + y20 * y20,
|
6095 | l21 = Math.sqrt(l21_2),
|
6096 | l01 = Math.sqrt(l01_2),
|
6097 | l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
|
6098 | t01 = l / l01,
|
6099 | t21 = l / l21;
|
6100 |
|
6101 |
|
6102 | if (Math.abs(t01 - 1) > epsilon$4) {
|
6103 | this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
|
6104 | }
|
6105 |
|
6106 | this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
|
6107 | }
|
6108 | },
|
6109 | arc: function(x, y, r, a0, a1, ccw) {
|
6110 | x = +x, y = +y, r = +r, ccw = !!ccw;
|
6111 | var dx = r * Math.cos(a0),
|
6112 | dy = r * Math.sin(a0),
|
6113 | x0 = x + dx,
|
6114 | y0 = y + dy,
|
6115 | cw = 1 ^ ccw,
|
6116 | da = ccw ? a0 - a1 : a1 - a0;
|
6117 |
|
6118 |
|
6119 | if (r < 0) throw new Error("negative radius: " + r);
|
6120 |
|
6121 |
|
6122 | if (this._x1 === null) {
|
6123 | this._ += "M" + x0 + "," + y0;
|
6124 | }
|
6125 |
|
6126 |
|
6127 | else if (Math.abs(this._x1 - x0) > epsilon$4 || Math.abs(this._y1 - y0) > epsilon$4) {
|
6128 | this._ += "L" + x0 + "," + y0;
|
6129 | }
|
6130 |
|
6131 |
|
6132 | if (!r) return;
|
6133 |
|
6134 |
|
6135 | if (da < 0) da = da % tau$3 + tau$3;
|
6136 |
|
6137 |
|
6138 | if (da > tauEpsilon) {
|
6139 | this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
|
6140 | }
|
6141 |
|
6142 |
|
6143 | else if (da > epsilon$4) {
|
6144 | this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
|
6145 | }
|
6146 | },
|
6147 | rect: function(x, y, w, h) {
|
6148 | this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
|
6149 | },
|
6150 | toString: function() {
|
6151 | return this._;
|
6152 | }
|
6153 | };
|
6154 |
|
6155 | var slice$2 = Array.prototype.slice;
|
6156 |
|
6157 | function constant$6(x) {
|
6158 | return function() {
|
6159 | return x;
|
6160 | };
|
6161 | }
|
6162 |
|
6163 | function defaultSource$1(d) {
|
6164 | return d.source;
|
6165 | }
|
6166 |
|
6167 | function defaultTarget(d) {
|
6168 | return d.target;
|
6169 | }
|
6170 |
|
6171 | function defaultRadius$1(d) {
|
6172 | return d.radius;
|
6173 | }
|
6174 |
|
6175 | function defaultStartAngle(d) {
|
6176 | return d.startAngle;
|
6177 | }
|
6178 |
|
6179 | function defaultEndAngle(d) {
|
6180 | return d.endAngle;
|
6181 | }
|
6182 |
|
6183 | function defaultPadAngle() {
|
6184 | return 0;
|
6185 | }
|
6186 |
|
6187 | function defaultArrowheadRadius() {
|
6188 | return 10;
|
6189 | }
|
6190 |
|
6191 | function ribbon(headRadius) {
|
6192 | var source = defaultSource$1,
|
6193 | target = defaultTarget,
|
6194 | sourceRadius = defaultRadius$1,
|
6195 | targetRadius = defaultRadius$1,
|
6196 | startAngle = defaultStartAngle,
|
6197 | endAngle = defaultEndAngle,
|
6198 | padAngle = defaultPadAngle,
|
6199 | context = null;
|
6200 |
|
6201 | function ribbon() {
|
6202 | var buffer,
|
6203 | s = source.apply(this, arguments),
|
6204 | t = target.apply(this, arguments),
|
6205 | ap = padAngle.apply(this, arguments) / 2,
|
6206 | argv = slice$2.call(arguments),
|
6207 | sr = +sourceRadius.apply(this, (argv[0] = s, argv)),
|
6208 | sa0 = startAngle.apply(this, argv) - halfPi$2,
|
6209 | sa1 = endAngle.apply(this, argv) - halfPi$2,
|
6210 | tr = +targetRadius.apply(this, (argv[0] = t, argv)),
|
6211 | ta0 = startAngle.apply(this, argv) - halfPi$2,
|
6212 | ta1 = endAngle.apply(this, argv) - halfPi$2;
|
6213 |
|
6214 | if (!context) context = buffer = path();
|
6215 |
|
6216 | if (ap > epsilon$5) {
|
6217 | if (abs$2(sa1 - sa0) > ap * 2 + epsilon$5) sa1 > sa0 ? (sa0 += ap, sa1 -= ap) : (sa0 -= ap, sa1 += ap);
|
6218 | else sa0 = sa1 = (sa0 + sa1) / 2;
|
6219 | if (abs$2(ta1 - ta0) > ap * 2 + epsilon$5) ta1 > ta0 ? (ta0 += ap, ta1 -= ap) : (ta0 -= ap, ta1 += ap);
|
6220 | else ta0 = ta1 = (ta0 + ta1) / 2;
|
6221 | }
|
6222 |
|
6223 | context.moveTo(sr * cos$2(sa0), sr * sin$2(sa0));
|
6224 | context.arc(0, 0, sr, sa0, sa1);
|
6225 | if (sa0 !== ta0 || sa1 !== ta1) {
|
6226 | if (headRadius) {
|
6227 | var hr = +headRadius.apply(this, arguments), tr2 = tr - hr, ta2 = (ta0 + ta1) / 2;
|
6228 | context.quadraticCurveTo(0, 0, tr2 * cos$2(ta0), tr2 * sin$2(ta0));
|
6229 | context.lineTo(tr * cos$2(ta2), tr * sin$2(ta2));
|
6230 | context.lineTo(tr2 * cos$2(ta1), tr2 * sin$2(ta1));
|
6231 | } else {
|
6232 | context.quadraticCurveTo(0, 0, tr * cos$2(ta0), tr * sin$2(ta0));
|
6233 | context.arc(0, 0, tr, ta0, ta1);
|
6234 | }
|
6235 | }
|
6236 | context.quadraticCurveTo(0, 0, sr * cos$2(sa0), sr * sin$2(sa0));
|
6237 | context.closePath();
|
6238 |
|
6239 | if (buffer) return context = null, buffer + "" || null;
|
6240 | }
|
6241 |
|
6242 | if (headRadius) ribbon.headRadius = function(_) {
|
6243 | return arguments.length ? (headRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : headRadius;
|
6244 | };
|
6245 |
|
6246 | ribbon.radius = function(_) {
|
6247 | return arguments.length ? (sourceRadius = targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
|
6248 | };
|
6249 |
|
6250 | ribbon.sourceRadius = function(_) {
|
6251 | return arguments.length ? (sourceRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
|
6252 | };
|
6253 |
|
6254 | ribbon.targetRadius = function(_) {
|
6255 | return arguments.length ? (targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : targetRadius;
|
6256 | };
|
6257 |
|
6258 | ribbon.startAngle = function(_) {
|
6259 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : startAngle;
|
6260 | };
|
6261 |
|
6262 | ribbon.endAngle = function(_) {
|
6263 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : endAngle;
|
6264 | };
|
6265 |
|
6266 | ribbon.padAngle = function(_) {
|
6267 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : padAngle;
|
6268 | };
|
6269 |
|
6270 | ribbon.source = function(_) {
|
6271 | return arguments.length ? (source = _, ribbon) : source;
|
6272 | };
|
6273 |
|
6274 | ribbon.target = function(_) {
|
6275 | return arguments.length ? (target = _, ribbon) : target;
|
6276 | };
|
6277 |
|
6278 | ribbon.context = function(_) {
|
6279 | return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
|
6280 | };
|
6281 |
|
6282 | return ribbon;
|
6283 | }
|
6284 |
|
6285 | function ribbon$1() {
|
6286 | return ribbon();
|
6287 | }
|
6288 |
|
6289 | function ribbonArrow() {
|
6290 | return ribbon(defaultArrowheadRadius);
|
6291 | }
|
6292 |
|
6293 | var array$2 = Array.prototype;
|
6294 |
|
6295 | var slice$1 = array$2.slice;
|
6296 |
|
6297 | function ascending$1(a, b) {
|
6298 | return a - b;
|
6299 | }
|
6300 |
|
6301 | function area$3(ring) {
|
6302 | var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
|
6303 | while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
|
6304 | return area;
|
6305 | }
|
6306 |
|
6307 | var constant$5 = x => () => x;
|
6308 |
|
6309 | function contains$2(ring, hole) {
|
6310 | var i = -1, n = hole.length, c;
|
6311 | while (++i < n) if (c = ringContains(ring, hole[i])) return c;
|
6312 | return 0;
|
6313 | }
|
6314 |
|
6315 | function ringContains(ring, point) {
|
6316 | var x = point[0], y = point[1], contains = -1;
|
6317 | for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
|
6318 | var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
|
6319 | if (segmentContains(pi, pj, point)) return 0;
|
6320 | if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
|
6321 | }
|
6322 | return contains;
|
6323 | }
|
6324 |
|
6325 | function segmentContains(a, b, c) {
|
6326 | var i; return collinear$1(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
|
6327 | }
|
6328 |
|
6329 | function collinear$1(a, b, c) {
|
6330 | return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
|
6331 | }
|
6332 |
|
6333 | function within(p, q, r) {
|
6334 | return p <= q && q <= r || r <= q && q <= p;
|
6335 | }
|
6336 |
|
6337 | function noop$2() {}
|
6338 |
|
6339 | var cases = [
|
6340 | [],
|
6341 | [[[1.0, 1.5], [0.5, 1.0]]],
|
6342 | [[[1.5, 1.0], [1.0, 1.5]]],
|
6343 | [[[1.5, 1.0], [0.5, 1.0]]],
|
6344 | [[[1.0, 0.5], [1.5, 1.0]]],
|
6345 | [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
|
6346 | [[[1.0, 0.5], [1.0, 1.5]]],
|
6347 | [[[1.0, 0.5], [0.5, 1.0]]],
|
6348 | [[[0.5, 1.0], [1.0, 0.5]]],
|
6349 | [[[1.0, 1.5], [1.0, 0.5]]],
|
6350 | [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
|
6351 | [[[1.5, 1.0], [1.0, 0.5]]],
|
6352 | [[[0.5, 1.0], [1.5, 1.0]]],
|
6353 | [[[1.0, 1.5], [1.5, 1.0]]],
|
6354 | [[[0.5, 1.0], [1.0, 1.5]]],
|
6355 | []
|
6356 | ];
|
6357 |
|
6358 | function Contours() {
|
6359 | var dx = 1,
|
6360 | dy = 1,
|
6361 | threshold = thresholdSturges,
|
6362 | smooth = smoothLinear;
|
6363 |
|
6364 | function contours(values) {
|
6365 | var tz = threshold(values);
|
6366 |
|
6367 |
|
6368 | if (!Array.isArray(tz)) {
|
6369 | const e = extent$1(values), ts = tickStep(e[0], e[1], tz);
|
6370 | tz = ticks(Math.floor(e[0] / ts) * ts, Math.floor(e[1] / ts - 1) * ts, tz);
|
6371 | } else {
|
6372 | tz = tz.slice().sort(ascending$1);
|
6373 | }
|
6374 |
|
6375 | return tz.map(value => contour(values, value));
|
6376 | }
|
6377 |
|
6378 |
|
6379 |
|
6380 | function contour(values, value) {
|
6381 | var polygons = [],
|
6382 | holes = [];
|
6383 |
|
6384 | isorings(values, value, function(ring) {
|
6385 | smooth(ring, values, value);
|
6386 | if (area$3(ring) > 0) polygons.push([ring]);
|
6387 | else holes.push(ring);
|
6388 | });
|
6389 |
|
6390 | holes.forEach(function(hole) {
|
6391 | for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
|
6392 | if (contains$2((polygon = polygons[i])[0], hole) !== -1) {
|
6393 | polygon.push(hole);
|
6394 | return;
|
6395 | }
|
6396 | }
|
6397 | });
|
6398 |
|
6399 | return {
|
6400 | type: "MultiPolygon",
|
6401 | value: value,
|
6402 | coordinates: polygons
|
6403 | };
|
6404 | }
|
6405 |
|
6406 |
|
6407 |
|
6408 | function isorings(values, value, callback) {
|
6409 | var fragmentByStart = new Array,
|
6410 | fragmentByEnd = new Array,
|
6411 | x, y, t0, t1, t2, t3;
|
6412 |
|
6413 |
|
6414 | x = y = -1;
|
6415 | t1 = values[0] >= value;
|
6416 | cases[t1 << 1].forEach(stitch);
|
6417 | while (++x < dx - 1) {
|
6418 | t0 = t1, t1 = values[x + 1] >= value;
|
6419 | cases[t0 | t1 << 1].forEach(stitch);
|
6420 | }
|
6421 | cases[t1 << 0].forEach(stitch);
|
6422 |
|
6423 |
|
6424 | while (++y < dy - 1) {
|
6425 | x = -1;
|
6426 | t1 = values[y * dx + dx] >= value;
|
6427 | t2 = values[y * dx] >= value;
|
6428 | cases[t1 << 1 | t2 << 2].forEach(stitch);
|
6429 | while (++x < dx - 1) {
|
6430 | t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
|
6431 | t3 = t2, t2 = values[y * dx + x + 1] >= value;
|
6432 | cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
|
6433 | }
|
6434 | cases[t1 | t2 << 3].forEach(stitch);
|
6435 | }
|
6436 |
|
6437 |
|
6438 | x = -1;
|
6439 | t2 = values[y * dx] >= value;
|
6440 | cases[t2 << 2].forEach(stitch);
|
6441 | while (++x < dx - 1) {
|
6442 | t3 = t2, t2 = values[y * dx + x + 1] >= value;
|
6443 | cases[t2 << 2 | t3 << 3].forEach(stitch);
|
6444 | }
|
6445 | cases[t2 << 3].forEach(stitch);
|
6446 |
|
6447 | function stitch(line) {
|
6448 | var start = [line[0][0] + x, line[0][1] + y],
|
6449 | end = [line[1][0] + x, line[1][1] + y],
|
6450 | startIndex = index(start),
|
6451 | endIndex = index(end),
|
6452 | f, g;
|
6453 | if (f = fragmentByEnd[startIndex]) {
|
6454 | if (g = fragmentByStart[endIndex]) {
|
6455 | delete fragmentByEnd[f.end];
|
6456 | delete fragmentByStart[g.start];
|
6457 | if (f === g) {
|
6458 | f.ring.push(end);
|
6459 | callback(f.ring);
|
6460 | } else {
|
6461 | fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
|
6462 | }
|
6463 | } else {
|
6464 | delete fragmentByEnd[f.end];
|
6465 | f.ring.push(end);
|
6466 | fragmentByEnd[f.end = endIndex] = f;
|
6467 | }
|
6468 | } else if (f = fragmentByStart[endIndex]) {
|
6469 | if (g = fragmentByEnd[startIndex]) {
|
6470 | delete fragmentByStart[f.start];
|
6471 | delete fragmentByEnd[g.end];
|
6472 | if (f === g) {
|
6473 | f.ring.push(end);
|
6474 | callback(f.ring);
|
6475 | } else {
|
6476 | fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
|
6477 | }
|
6478 | } else {
|
6479 | delete fragmentByStart[f.start];
|
6480 | f.ring.unshift(start);
|
6481 | fragmentByStart[f.start = startIndex] = f;
|
6482 | }
|
6483 | } else {
|
6484 | fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
|
6485 | }
|
6486 | }
|
6487 | }
|
6488 |
|
6489 | function index(point) {
|
6490 | return point[0] * 2 + point[1] * (dx + 1) * 4;
|
6491 | }
|
6492 |
|
6493 | function smoothLinear(ring, values, value) {
|
6494 | ring.forEach(function(point) {
|
6495 | var x = point[0],
|
6496 | y = point[1],
|
6497 | xt = x | 0,
|
6498 | yt = y | 0,
|
6499 | v0,
|
6500 | v1 = values[yt * dx + xt];
|
6501 | if (x > 0 && x < dx && xt === x) {
|
6502 | v0 = values[yt * dx + xt - 1];
|
6503 | point[0] = x + (value - v0) / (v1 - v0) - 0.5;
|
6504 | }
|
6505 | if (y > 0 && y < dy && yt === y) {
|
6506 | v0 = values[(yt - 1) * dx + xt];
|
6507 | point[1] = y + (value - v0) / (v1 - v0) - 0.5;
|
6508 | }
|
6509 | });
|
6510 | }
|
6511 |
|
6512 | contours.contour = contour;
|
6513 |
|
6514 | contours.size = function(_) {
|
6515 | if (!arguments.length) return [dx, dy];
|
6516 | var _0 = Math.floor(_[0]), _1 = Math.floor(_[1]);
|
6517 | if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
|
6518 | return dx = _0, dy = _1, contours;
|
6519 | };
|
6520 |
|
6521 | contours.thresholds = function(_) {
|
6522 | return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), contours) : threshold;
|
6523 | };
|
6524 |
|
6525 | contours.smooth = function(_) {
|
6526 | return arguments.length ? (smooth = _ ? smoothLinear : noop$2, contours) : smooth === smoothLinear;
|
6527 | };
|
6528 |
|
6529 | return contours;
|
6530 | }
|
6531 |
|
6532 | function defaultX$1(d) {
|
6533 | return d[0];
|
6534 | }
|
6535 |
|
6536 | function defaultY$1(d) {
|
6537 | return d[1];
|
6538 | }
|
6539 |
|
6540 | function defaultWeight() {
|
6541 | return 1;
|
6542 | }
|
6543 |
|
6544 | function density() {
|
6545 | var x = defaultX$1,
|
6546 | y = defaultY$1,
|
6547 | weight = defaultWeight,
|
6548 | dx = 960,
|
6549 | dy = 500,
|
6550 | r = 20,
|
6551 | k = 2,
|
6552 | o = r * 3,
|
6553 | n = (dx + o * 2) >> k,
|
6554 | m = (dy + o * 2) >> k,
|
6555 | threshold = constant$5(20);
|
6556 |
|
6557 | function grid(data) {
|
6558 | var values = new Float32Array(n * m),
|
6559 | pow2k = Math.pow(2, -k),
|
6560 | i = -1;
|
6561 |
|
6562 | for (const d of data) {
|
6563 | var xi = (x(d, ++i, data) + o) * pow2k,
|
6564 | yi = (y(d, i, data) + o) * pow2k,
|
6565 | wi = +weight(d, i, data);
|
6566 | if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
|
6567 | var x0 = Math.floor(xi),
|
6568 | y0 = Math.floor(yi),
|
6569 | xt = xi - x0 - 0.5,
|
6570 | yt = yi - y0 - 0.5;
|
6571 | values[x0 + y0 * n] += (1 - xt) * (1 - yt) * wi;
|
6572 | values[x0 + 1 + y0 * n] += xt * (1 - yt) * wi;
|
6573 | values[x0 + 1 + (y0 + 1) * n] += xt * yt * wi;
|
6574 | values[x0 + (y0 + 1) * n] += (1 - xt) * yt * wi;
|
6575 | }
|
6576 | }
|
6577 |
|
6578 | blur2({data: values, width: n, height: m}, r * pow2k);
|
6579 | return values;
|
6580 | }
|
6581 |
|
6582 | function density(data) {
|
6583 | var values = grid(data),
|
6584 | tz = threshold(values),
|
6585 | pow4k = Math.pow(2, 2 * k);
|
6586 |
|
6587 |
|
6588 | if (!Array.isArray(tz)) {
|
6589 | tz = ticks(Number.MIN_VALUE, max$3(values) / pow4k, tz);
|
6590 | }
|
6591 |
|
6592 | return Contours()
|
6593 | .size([n, m])
|
6594 | .thresholds(tz.map(d => d * pow4k))
|
6595 | (values)
|
6596 | .map((c, i) => (c.value = +tz[i], transform(c)));
|
6597 | }
|
6598 |
|
6599 | density.contours = function(data) {
|
6600 | var values = grid(data),
|
6601 | contours = Contours().size([n, m]),
|
6602 | pow4k = Math.pow(2, 2 * k),
|
6603 | contour = value => {
|
6604 | value = +value;
|
6605 | var c = transform(contours.contour(values, value * pow4k));
|
6606 | c.value = value;
|
6607 | return c;
|
6608 | };
|
6609 | Object.defineProperty(contour, "max", {get: () => max$3(values) / pow4k});
|
6610 | return contour;
|
6611 | };
|
6612 |
|
6613 | function transform(geometry) {
|
6614 | geometry.coordinates.forEach(transformPolygon);
|
6615 | return geometry;
|
6616 | }
|
6617 |
|
6618 | function transformPolygon(coordinates) {
|
6619 | coordinates.forEach(transformRing);
|
6620 | }
|
6621 |
|
6622 | function transformRing(coordinates) {
|
6623 | coordinates.forEach(transformPoint);
|
6624 | }
|
6625 |
|
6626 |
|
6627 | function transformPoint(coordinates) {
|
6628 | coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
|
6629 | coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
|
6630 | }
|
6631 |
|
6632 | function resize() {
|
6633 | o = r * 3;
|
6634 | n = (dx + o * 2) >> k;
|
6635 | m = (dy + o * 2) >> k;
|
6636 | return density;
|
6637 | }
|
6638 |
|
6639 | density.x = function(_) {
|
6640 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$5(+_), density) : x;
|
6641 | };
|
6642 |
|
6643 | density.y = function(_) {
|
6644 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$5(+_), density) : y;
|
6645 | };
|
6646 |
|
6647 | density.weight = function(_) {
|
6648 | return arguments.length ? (weight = typeof _ === "function" ? _ : constant$5(+_), density) : weight;
|
6649 | };
|
6650 |
|
6651 | density.size = function(_) {
|
6652 | if (!arguments.length) return [dx, dy];
|
6653 | var _0 = +_[0], _1 = +_[1];
|
6654 | if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
|
6655 | return dx = _0, dy = _1, resize();
|
6656 | };
|
6657 |
|
6658 | density.cellSize = function(_) {
|
6659 | if (!arguments.length) return 1 << k;
|
6660 | if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
|
6661 | return k = Math.floor(Math.log(_) / Math.LN2), resize();
|
6662 | };
|
6663 |
|
6664 | density.thresholds = function(_) {
|
6665 | return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), density) : threshold;
|
6666 | };
|
6667 |
|
6668 | density.bandwidth = function(_) {
|
6669 | if (!arguments.length) return Math.sqrt(r * (r + 1));
|
6670 | if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
|
6671 | return r = (Math.sqrt(4 * _ * _ + 1) - 1) / 2, resize();
|
6672 | };
|
6673 |
|
6674 | return density;
|
6675 | }
|
6676 |
|
6677 | const epsilon$3 = 1.1102230246251565e-16;
|
6678 | const splitter = 134217729;
|
6679 | const resulterrbound = (3 + 8 * epsilon$3) * epsilon$3;
|
6680 |
|
6681 |
|
6682 | function sum$1(elen, e, flen, f, h) {
|
6683 | let Q, Qnew, hh, bvirt;
|
6684 | let enow = e[0];
|
6685 | let fnow = f[0];
|
6686 | let eindex = 0;
|
6687 | let findex = 0;
|
6688 | if ((fnow > enow) === (fnow > -enow)) {
|
6689 | Q = enow;
|
6690 | enow = e[++eindex];
|
6691 | } else {
|
6692 | Q = fnow;
|
6693 | fnow = f[++findex];
|
6694 | }
|
6695 | let hindex = 0;
|
6696 | if (eindex < elen && findex < flen) {
|
6697 | if ((fnow > enow) === (fnow > -enow)) {
|
6698 | Qnew = enow + Q;
|
6699 | hh = Q - (Qnew - enow);
|
6700 | enow = e[++eindex];
|
6701 | } else {
|
6702 | Qnew = fnow + Q;
|
6703 | hh = Q - (Qnew - fnow);
|
6704 | fnow = f[++findex];
|
6705 | }
|
6706 | Q = Qnew;
|
6707 | if (hh !== 0) {
|
6708 | h[hindex++] = hh;
|
6709 | }
|
6710 | while (eindex < elen && findex < flen) {
|
6711 | if ((fnow > enow) === (fnow > -enow)) {
|
6712 | Qnew = Q + enow;
|
6713 | bvirt = Qnew - Q;
|
6714 | hh = Q - (Qnew - bvirt) + (enow - bvirt);
|
6715 | enow = e[++eindex];
|
6716 | } else {
|
6717 | Qnew = Q + fnow;
|
6718 | bvirt = Qnew - Q;
|
6719 | hh = Q - (Qnew - bvirt) + (fnow - bvirt);
|
6720 | fnow = f[++findex];
|
6721 | }
|
6722 | Q = Qnew;
|
6723 | if (hh !== 0) {
|
6724 | h[hindex++] = hh;
|
6725 | }
|
6726 | }
|
6727 | }
|
6728 | while (eindex < elen) {
|
6729 | Qnew = Q + enow;
|
6730 | bvirt = Qnew - Q;
|
6731 | hh = Q - (Qnew - bvirt) + (enow - bvirt);
|
6732 | enow = e[++eindex];
|
6733 | Q = Qnew;
|
6734 | if (hh !== 0) {
|
6735 | h[hindex++] = hh;
|
6736 | }
|
6737 | }
|
6738 | while (findex < flen) {
|
6739 | Qnew = Q + fnow;
|
6740 | bvirt = Qnew - Q;
|
6741 | hh = Q - (Qnew - bvirt) + (fnow - bvirt);
|
6742 | fnow = f[++findex];
|
6743 | Q = Qnew;
|
6744 | if (hh !== 0) {
|
6745 | h[hindex++] = hh;
|
6746 | }
|
6747 | }
|
6748 | if (Q !== 0 || hindex === 0) {
|
6749 | h[hindex++] = Q;
|
6750 | }
|
6751 | return hindex;
|
6752 | }
|
6753 |
|
6754 | function estimate(elen, e) {
|
6755 | let Q = e[0];
|
6756 | for (let i = 1; i < elen; i++) Q += e[i];
|
6757 | return Q;
|
6758 | }
|
6759 |
|
6760 | function vec(n) {
|
6761 | return new Float64Array(n);
|
6762 | }
|
6763 |
|
6764 | const ccwerrboundA = (3 + 16 * epsilon$3) * epsilon$3;
|
6765 | const ccwerrboundB = (2 + 12 * epsilon$3) * epsilon$3;
|
6766 | const ccwerrboundC = (9 + 64 * epsilon$3) * epsilon$3 * epsilon$3;
|
6767 |
|
6768 | const B = vec(4);
|
6769 | const C1 = vec(8);
|
6770 | const C2 = vec(12);
|
6771 | const D = vec(16);
|
6772 | const u = vec(4);
|
6773 |
|
6774 | function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
|
6775 | let acxtail, acytail, bcxtail, bcytail;
|
6776 | let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
|
6777 |
|
6778 | const acx = ax - cx;
|
6779 | const bcx = bx - cx;
|
6780 | const acy = ay - cy;
|
6781 | const bcy = by - cy;
|
6782 |
|
6783 | s1 = acx * bcy;
|
6784 | c = splitter * acx;
|
6785 | ahi = c - (c - acx);
|
6786 | alo = acx - ahi;
|
6787 | c = splitter * bcy;
|
6788 | bhi = c - (c - bcy);
|
6789 | blo = bcy - bhi;
|
6790 | s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
6791 | t1 = acy * bcx;
|
6792 | c = splitter * acy;
|
6793 | ahi = c - (c - acy);
|
6794 | alo = acy - ahi;
|
6795 | c = splitter * bcx;
|
6796 | bhi = c - (c - bcx);
|
6797 | blo = bcx - bhi;
|
6798 | t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
6799 | _i = s0 - t0;
|
6800 | bvirt = s0 - _i;
|
6801 | B[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
6802 | _j = s1 + _i;
|
6803 | bvirt = _j - s1;
|
6804 | _0 = s1 - (_j - bvirt) + (_i - bvirt);
|
6805 | _i = _0 - t1;
|
6806 | bvirt = _0 - _i;
|
6807 | B[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
6808 | u3 = _j + _i;
|
6809 | bvirt = u3 - _j;
|
6810 | B[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
6811 | B[3] = u3;
|
6812 |
|
6813 | let det = estimate(4, B);
|
6814 | let errbound = ccwerrboundB * detsum;
|
6815 | if (det >= errbound || -det >= errbound) {
|
6816 | return det;
|
6817 | }
|
6818 |
|
6819 | bvirt = ax - acx;
|
6820 | acxtail = ax - (acx + bvirt) + (bvirt - cx);
|
6821 | bvirt = bx - bcx;
|
6822 | bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
|
6823 | bvirt = ay - acy;
|
6824 | acytail = ay - (acy + bvirt) + (bvirt - cy);
|
6825 | bvirt = by - bcy;
|
6826 | bcytail = by - (bcy + bvirt) + (bvirt - cy);
|
6827 |
|
6828 | if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
|
6829 | return det;
|
6830 | }
|
6831 |
|
6832 | errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
|
6833 | det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
|
6834 | if (det >= errbound || -det >= errbound) return det;
|
6835 |
|
6836 | s1 = acxtail * bcy;
|
6837 | c = splitter * acxtail;
|
6838 | ahi = c - (c - acxtail);
|
6839 | alo = acxtail - ahi;
|
6840 | c = splitter * bcy;
|
6841 | bhi = c - (c - bcy);
|
6842 | blo = bcy - bhi;
|
6843 | s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
6844 | t1 = acytail * bcx;
|
6845 | c = splitter * acytail;
|
6846 | ahi = c - (c - acytail);
|
6847 | alo = acytail - ahi;
|
6848 | c = splitter * bcx;
|
6849 | bhi = c - (c - bcx);
|
6850 | blo = bcx - bhi;
|
6851 | t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
6852 | _i = s0 - t0;
|
6853 | bvirt = s0 - _i;
|
6854 | u[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
6855 | _j = s1 + _i;
|
6856 | bvirt = _j - s1;
|
6857 | _0 = s1 - (_j - bvirt) + (_i - bvirt);
|
6858 | _i = _0 - t1;
|
6859 | bvirt = _0 - _i;
|
6860 | u[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
6861 | u3 = _j + _i;
|
6862 | bvirt = u3 - _j;
|
6863 | u[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
6864 | u[3] = u3;
|
6865 | const C1len = sum$1(4, B, 4, u, C1);
|
6866 |
|
6867 | s1 = acx * bcytail;
|
6868 | c = splitter * acx;
|
6869 | ahi = c - (c - acx);
|
6870 | alo = acx - ahi;
|
6871 | c = splitter * bcytail;
|
6872 | bhi = c - (c - bcytail);
|
6873 | blo = bcytail - bhi;
|
6874 | s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
6875 | t1 = acy * bcxtail;
|
6876 | c = splitter * acy;
|
6877 | ahi = c - (c - acy);
|
6878 | alo = acy - ahi;
|
6879 | c = splitter * bcxtail;
|
6880 | bhi = c - (c - bcxtail);
|
6881 | blo = bcxtail - bhi;
|
6882 | t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
6883 | _i = s0 - t0;
|
6884 | bvirt = s0 - _i;
|
6885 | u[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
6886 | _j = s1 + _i;
|
6887 | bvirt = _j - s1;
|
6888 | _0 = s1 - (_j - bvirt) + (_i - bvirt);
|
6889 | _i = _0 - t1;
|
6890 | bvirt = _0 - _i;
|
6891 | u[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
6892 | u3 = _j + _i;
|
6893 | bvirt = u3 - _j;
|
6894 | u[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
6895 | u[3] = u3;
|
6896 | const C2len = sum$1(C1len, C1, 4, u, C2);
|
6897 |
|
6898 | s1 = acxtail * bcytail;
|
6899 | c = splitter * acxtail;
|
6900 | ahi = c - (c - acxtail);
|
6901 | alo = acxtail - ahi;
|
6902 | c = splitter * bcytail;
|
6903 | bhi = c - (c - bcytail);
|
6904 | blo = bcytail - bhi;
|
6905 | s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
6906 | t1 = acytail * bcxtail;
|
6907 | c = splitter * acytail;
|
6908 | ahi = c - (c - acytail);
|
6909 | alo = acytail - ahi;
|
6910 | c = splitter * bcxtail;
|
6911 | bhi = c - (c - bcxtail);
|
6912 | blo = bcxtail - bhi;
|
6913 | t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
6914 | _i = s0 - t0;
|
6915 | bvirt = s0 - _i;
|
6916 | u[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
6917 | _j = s1 + _i;
|
6918 | bvirt = _j - s1;
|
6919 | _0 = s1 - (_j - bvirt) + (_i - bvirt);
|
6920 | _i = _0 - t1;
|
6921 | bvirt = _0 - _i;
|
6922 | u[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
6923 | u3 = _j + _i;
|
6924 | bvirt = u3 - _j;
|
6925 | u[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
6926 | u[3] = u3;
|
6927 | const Dlen = sum$1(C2len, C2, 4, u, D);
|
6928 |
|
6929 | return D[Dlen - 1];
|
6930 | }
|
6931 |
|
6932 | function orient2d(ax, ay, bx, by, cx, cy) {
|
6933 | const detleft = (ay - cy) * (bx - cx);
|
6934 | const detright = (ax - cx) * (by - cy);
|
6935 | const det = detleft - detright;
|
6936 |
|
6937 | if (detleft === 0 || detright === 0 || (detleft > 0) !== (detright > 0)) return det;
|
6938 |
|
6939 | const detsum = Math.abs(detleft + detright);
|
6940 | if (Math.abs(det) >= ccwerrboundA * detsum) return det;
|
6941 |
|
6942 | return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
|
6943 | }
|
6944 |
|
6945 | const EPSILON = Math.pow(2, -52);
|
6946 | const EDGE_STACK = new Uint32Array(512);
|
6947 |
|
6948 | class Delaunator {
|
6949 |
|
6950 | static from(points, getX = defaultGetX, getY = defaultGetY) {
|
6951 | const n = points.length;
|
6952 | const coords = new Float64Array(n * 2);
|
6953 |
|
6954 | for (let i = 0; i < n; i++) {
|
6955 | const p = points[i];
|
6956 | coords[2 * i] = getX(p);
|
6957 | coords[2 * i + 1] = getY(p);
|
6958 | }
|
6959 |
|
6960 | return new Delaunator(coords);
|
6961 | }
|
6962 |
|
6963 | constructor(coords) {
|
6964 | const n = coords.length >> 1;
|
6965 | if (n > 0 && typeof coords[0] !== 'number') throw new Error('Expected coords to contain numbers.');
|
6966 |
|
6967 | this.coords = coords;
|
6968 |
|
6969 |
|
6970 | const maxTriangles = Math.max(2 * n - 5, 0);
|
6971 | this._triangles = new Uint32Array(maxTriangles * 3);
|
6972 | this._halfedges = new Int32Array(maxTriangles * 3);
|
6973 |
|
6974 |
|
6975 | this._hashSize = Math.ceil(Math.sqrt(n));
|
6976 | this._hullPrev = new Uint32Array(n);
|
6977 | this._hullNext = new Uint32Array(n);
|
6978 | this._hullTri = new Uint32Array(n);
|
6979 | this._hullHash = new Int32Array(this._hashSize).fill(-1);
|
6980 |
|
6981 |
|
6982 | this._ids = new Uint32Array(n);
|
6983 | this._dists = new Float64Array(n);
|
6984 |
|
6985 | this.update();
|
6986 | }
|
6987 |
|
6988 | update() {
|
6989 | const {coords, _hullPrev: hullPrev, _hullNext: hullNext, _hullTri: hullTri, _hullHash: hullHash} = this;
|
6990 | const n = coords.length >> 1;
|
6991 |
|
6992 |
|
6993 | let minX = Infinity;
|
6994 | let minY = Infinity;
|
6995 | let maxX = -Infinity;
|
6996 | let maxY = -Infinity;
|
6997 |
|
6998 | for (let i = 0; i < n; i++) {
|
6999 | const x = coords[2 * i];
|
7000 | const y = coords[2 * i + 1];
|
7001 | if (x < minX) minX = x;
|
7002 | if (y < minY) minY = y;
|
7003 | if (x > maxX) maxX = x;
|
7004 | if (y > maxY) maxY = y;
|
7005 | this._ids[i] = i;
|
7006 | }
|
7007 | const cx = (minX + maxX) / 2;
|
7008 | const cy = (minY + maxY) / 2;
|
7009 |
|
7010 | let minDist = Infinity;
|
7011 | let i0, i1, i2;
|
7012 |
|
7013 |
|
7014 | for (let i = 0; i < n; i++) {
|
7015 | const d = dist(cx, cy, coords[2 * i], coords[2 * i + 1]);
|
7016 | if (d < minDist) {
|
7017 | i0 = i;
|
7018 | minDist = d;
|
7019 | }
|
7020 | }
|
7021 | const i0x = coords[2 * i0];
|
7022 | const i0y = coords[2 * i0 + 1];
|
7023 |
|
7024 | minDist = Infinity;
|
7025 |
|
7026 |
|
7027 | for (let i = 0; i < n; i++) {
|
7028 | if (i === i0) continue;
|
7029 | const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
|
7030 | if (d < minDist && d > 0) {
|
7031 | i1 = i;
|
7032 | minDist = d;
|
7033 | }
|
7034 | }
|
7035 | let i1x = coords[2 * i1];
|
7036 | let i1y = coords[2 * i1 + 1];
|
7037 |
|
7038 | let minRadius = Infinity;
|
7039 |
|
7040 |
|
7041 | for (let i = 0; i < n; i++) {
|
7042 | if (i === i0 || i === i1) continue;
|
7043 | const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
|
7044 | if (r < minRadius) {
|
7045 | i2 = i;
|
7046 | minRadius = r;
|
7047 | }
|
7048 | }
|
7049 | let i2x = coords[2 * i2];
|
7050 | let i2y = coords[2 * i2 + 1];
|
7051 |
|
7052 | if (minRadius === Infinity) {
|
7053 |
|
7054 |
|
7055 | for (let i = 0; i < n; i++) {
|
7056 | this._dists[i] = (coords[2 * i] - coords[0]) || (coords[2 * i + 1] - coords[1]);
|
7057 | }
|
7058 | quicksort(this._ids, this._dists, 0, n - 1);
|
7059 | const hull = new Uint32Array(n);
|
7060 | let j = 0;
|
7061 | for (let i = 0, d0 = -Infinity; i < n; i++) {
|
7062 | const id = this._ids[i];
|
7063 | if (this._dists[id] > d0) {
|
7064 | hull[j++] = id;
|
7065 | d0 = this._dists[id];
|
7066 | }
|
7067 | }
|
7068 | this.hull = hull.subarray(0, j);
|
7069 | this.triangles = new Uint32Array(0);
|
7070 | this.halfedges = new Uint32Array(0);
|
7071 | return;
|
7072 | }
|
7073 |
|
7074 |
|
7075 | if (orient2d(i0x, i0y, i1x, i1y, i2x, i2y) < 0) {
|
7076 | const i = i1;
|
7077 | const x = i1x;
|
7078 | const y = i1y;
|
7079 | i1 = i2;
|
7080 | i1x = i2x;
|
7081 | i1y = i2y;
|
7082 | i2 = i;
|
7083 | i2x = x;
|
7084 | i2y = y;
|
7085 | }
|
7086 |
|
7087 | const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
|
7088 | this._cx = center.x;
|
7089 | this._cy = center.y;
|
7090 |
|
7091 | for (let i = 0; i < n; i++) {
|
7092 | this._dists[i] = dist(coords[2 * i], coords[2 * i + 1], center.x, center.y);
|
7093 | }
|
7094 |
|
7095 |
|
7096 | quicksort(this._ids, this._dists, 0, n - 1);
|
7097 |
|
7098 |
|
7099 | this._hullStart = i0;
|
7100 | let hullSize = 3;
|
7101 |
|
7102 | hullNext[i0] = hullPrev[i2] = i1;
|
7103 | hullNext[i1] = hullPrev[i0] = i2;
|
7104 | hullNext[i2] = hullPrev[i1] = i0;
|
7105 |
|
7106 | hullTri[i0] = 0;
|
7107 | hullTri[i1] = 1;
|
7108 | hullTri[i2] = 2;
|
7109 |
|
7110 | hullHash.fill(-1);
|
7111 | hullHash[this._hashKey(i0x, i0y)] = i0;
|
7112 | hullHash[this._hashKey(i1x, i1y)] = i1;
|
7113 | hullHash[this._hashKey(i2x, i2y)] = i2;
|
7114 |
|
7115 | this.trianglesLen = 0;
|
7116 | this._addTriangle(i0, i1, i2, -1, -1, -1);
|
7117 |
|
7118 | for (let k = 0, xp, yp; k < this._ids.length; k++) {
|
7119 | const i = this._ids[k];
|
7120 | const x = coords[2 * i];
|
7121 | const y = coords[2 * i + 1];
|
7122 |
|
7123 |
|
7124 | if (k > 0 && Math.abs(x - xp) <= EPSILON && Math.abs(y - yp) <= EPSILON) continue;
|
7125 | xp = x;
|
7126 | yp = y;
|
7127 |
|
7128 |
|
7129 | if (i === i0 || i === i1 || i === i2) continue;
|
7130 |
|
7131 |
|
7132 | let start = 0;
|
7133 | for (let j = 0, key = this._hashKey(x, y); j < this._hashSize; j++) {
|
7134 | start = hullHash[(key + j) % this._hashSize];
|
7135 | if (start !== -1 && start !== hullNext[start]) break;
|
7136 | }
|
7137 |
|
7138 | start = hullPrev[start];
|
7139 | let e = start, q;
|
7140 | while (q = hullNext[e], orient2d(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1]) >= 0) {
|
7141 | e = q;
|
7142 | if (e === start) {
|
7143 | e = -1;
|
7144 | break;
|
7145 | }
|
7146 | }
|
7147 | if (e === -1) continue;
|
7148 |
|
7149 |
|
7150 | let t = this._addTriangle(e, i, hullNext[e], -1, -1, hullTri[e]);
|
7151 |
|
7152 |
|
7153 | hullTri[i] = this._legalize(t + 2);
|
7154 | hullTri[e] = t;
|
7155 | hullSize++;
|
7156 |
|
7157 |
|
7158 | let n = hullNext[e];
|
7159 | while (q = hullNext[n], orient2d(x, y, coords[2 * n], coords[2 * n + 1], coords[2 * q], coords[2 * q + 1]) < 0) {
|
7160 | t = this._addTriangle(n, i, q, hullTri[i], -1, hullTri[n]);
|
7161 | hullTri[i] = this._legalize(t + 2);
|
7162 | hullNext[n] = n;
|
7163 | hullSize--;
|
7164 | n = q;
|
7165 | }
|
7166 |
|
7167 |
|
7168 | if (e === start) {
|
7169 | while (q = hullPrev[e], orient2d(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1]) < 0) {
|
7170 | t = this._addTriangle(q, i, e, -1, hullTri[e], hullTri[q]);
|
7171 | this._legalize(t + 2);
|
7172 | hullTri[q] = t;
|
7173 | hullNext[e] = e;
|
7174 | hullSize--;
|
7175 | e = q;
|
7176 | }
|
7177 | }
|
7178 |
|
7179 |
|
7180 | this._hullStart = hullPrev[i] = e;
|
7181 | hullNext[e] = hullPrev[n] = i;
|
7182 | hullNext[i] = n;
|
7183 |
|
7184 |
|
7185 | hullHash[this._hashKey(x, y)] = i;
|
7186 | hullHash[this._hashKey(coords[2 * e], coords[2 * e + 1])] = e;
|
7187 | }
|
7188 |
|
7189 | this.hull = new Uint32Array(hullSize);
|
7190 | for (let i = 0, e = this._hullStart; i < hullSize; i++) {
|
7191 | this.hull[i] = e;
|
7192 | e = hullNext[e];
|
7193 | }
|
7194 |
|
7195 |
|
7196 | this.triangles = this._triangles.subarray(0, this.trianglesLen);
|
7197 | this.halfedges = this._halfedges.subarray(0, this.trianglesLen);
|
7198 | }
|
7199 |
|
7200 | _hashKey(x, y) {
|
7201 | return Math.floor(pseudoAngle(x - this._cx, y - this._cy) * this._hashSize) % this._hashSize;
|
7202 | }
|
7203 |
|
7204 | _legalize(a) {
|
7205 | const {_triangles: triangles, _halfedges: halfedges, coords} = this;
|
7206 |
|
7207 | let i = 0;
|
7208 | let ar = 0;
|
7209 |
|
7210 |
|
7211 | while (true) {
|
7212 | const b = halfedges[a];
|
7213 |
|
7214 | |
7215 |
|
7216 |
|
7217 |
|
7218 |
|
7219 |
|
7220 |
|
7221 |
|
7222 |
|
7223 |
|
7224 |
|
7225 |
|
7226 |
|
7227 |
|
7228 |
|
7229 | const a0 = a - a % 3;
|
7230 | ar = a0 + (a + 2) % 3;
|
7231 |
|
7232 | if (b === -1) {
|
7233 | if (i === 0) break;
|
7234 | a = EDGE_STACK[--i];
|
7235 | continue;
|
7236 | }
|
7237 |
|
7238 | const b0 = b - b % 3;
|
7239 | const al = a0 + (a + 1) % 3;
|
7240 | const bl = b0 + (b + 2) % 3;
|
7241 |
|
7242 | const p0 = triangles[ar];
|
7243 | const pr = triangles[a];
|
7244 | const pl = triangles[al];
|
7245 | const p1 = triangles[bl];
|
7246 |
|
7247 | const illegal = inCircle(
|
7248 | coords[2 * p0], coords[2 * p0 + 1],
|
7249 | coords[2 * pr], coords[2 * pr + 1],
|
7250 | coords[2 * pl], coords[2 * pl + 1],
|
7251 | coords[2 * p1], coords[2 * p1 + 1]);
|
7252 |
|
7253 | if (illegal) {
|
7254 | triangles[a] = p1;
|
7255 | triangles[b] = p0;
|
7256 |
|
7257 | const hbl = halfedges[bl];
|
7258 |
|
7259 |
|
7260 | if (hbl === -1) {
|
7261 | let e = this._hullStart;
|
7262 | do {
|
7263 | if (this._hullTri[e] === bl) {
|
7264 | this._hullTri[e] = a;
|
7265 | break;
|
7266 | }
|
7267 | e = this._hullPrev[e];
|
7268 | } while (e !== this._hullStart);
|
7269 | }
|
7270 | this._link(a, hbl);
|
7271 | this._link(b, halfedges[ar]);
|
7272 | this._link(ar, bl);
|
7273 |
|
7274 | const br = b0 + (b + 1) % 3;
|
7275 |
|
7276 |
|
7277 | if (i < EDGE_STACK.length) {
|
7278 | EDGE_STACK[i++] = br;
|
7279 | }
|
7280 | } else {
|
7281 | if (i === 0) break;
|
7282 | a = EDGE_STACK[--i];
|
7283 | }
|
7284 | }
|
7285 |
|
7286 | return ar;
|
7287 | }
|
7288 |
|
7289 | _link(a, b) {
|
7290 | this._halfedges[a] = b;
|
7291 | if (b !== -1) this._halfedges[b] = a;
|
7292 | }
|
7293 |
|
7294 |
|
7295 | _addTriangle(i0, i1, i2, a, b, c) {
|
7296 | const t = this.trianglesLen;
|
7297 |
|
7298 | this._triangles[t] = i0;
|
7299 | this._triangles[t + 1] = i1;
|
7300 | this._triangles[t + 2] = i2;
|
7301 |
|
7302 | this._link(t, a);
|
7303 | this._link(t + 1, b);
|
7304 | this._link(t + 2, c);
|
7305 |
|
7306 | this.trianglesLen += 3;
|
7307 |
|
7308 | return t;
|
7309 | }
|
7310 | }
|
7311 |
|
7312 |
|
7313 | function pseudoAngle(dx, dy) {
|
7314 | const p = dx / (Math.abs(dx) + Math.abs(dy));
|
7315 | return (dy > 0 ? 3 - p : 1 + p) / 4;
|
7316 | }
|
7317 |
|
7318 | function dist(ax, ay, bx, by) {
|
7319 | const dx = ax - bx;
|
7320 | const dy = ay - by;
|
7321 | return dx * dx + dy * dy;
|
7322 | }
|
7323 |
|
7324 | function inCircle(ax, ay, bx, by, cx, cy, px, py) {
|
7325 | const dx = ax - px;
|
7326 | const dy = ay - py;
|
7327 | const ex = bx - px;
|
7328 | const ey = by - py;
|
7329 | const fx = cx - px;
|
7330 | const fy = cy - py;
|
7331 |
|
7332 | const ap = dx * dx + dy * dy;
|
7333 | const bp = ex * ex + ey * ey;
|
7334 | const cp = fx * fx + fy * fy;
|
7335 |
|
7336 | return dx * (ey * cp - bp * fy) -
|
7337 | dy * (ex * cp - bp * fx) +
|
7338 | ap * (ex * fy - ey * fx) < 0;
|
7339 | }
|
7340 |
|
7341 | function circumradius(ax, ay, bx, by, cx, cy) {
|
7342 | const dx = bx - ax;
|
7343 | const dy = by - ay;
|
7344 | const ex = cx - ax;
|
7345 | const ey = cy - ay;
|
7346 |
|
7347 | const bl = dx * dx + dy * dy;
|
7348 | const cl = ex * ex + ey * ey;
|
7349 | const d = 0.5 / (dx * ey - dy * ex);
|
7350 |
|
7351 | const x = (ey * bl - dy * cl) * d;
|
7352 | const y = (dx * cl - ex * bl) * d;
|
7353 |
|
7354 | return x * x + y * y;
|
7355 | }
|
7356 |
|
7357 | function circumcenter(ax, ay, bx, by, cx, cy) {
|
7358 | const dx = bx - ax;
|
7359 | const dy = by - ay;
|
7360 | const ex = cx - ax;
|
7361 | const ey = cy - ay;
|
7362 |
|
7363 | const bl = dx * dx + dy * dy;
|
7364 | const cl = ex * ex + ey * ey;
|
7365 | const d = 0.5 / (dx * ey - dy * ex);
|
7366 |
|
7367 | const x = ax + (ey * bl - dy * cl) * d;
|
7368 | const y = ay + (dx * cl - ex * bl) * d;
|
7369 |
|
7370 | return {x, y};
|
7371 | }
|
7372 |
|
7373 | function quicksort(ids, dists, left, right) {
|
7374 | if (right - left <= 20) {
|
7375 | for (let i = left + 1; i <= right; i++) {
|
7376 | const temp = ids[i];
|
7377 | const tempDist = dists[temp];
|
7378 | let j = i - 1;
|
7379 | while (j >= left && dists[ids[j]] > tempDist) ids[j + 1] = ids[j--];
|
7380 | ids[j + 1] = temp;
|
7381 | }
|
7382 | } else {
|
7383 | const median = (left + right) >> 1;
|
7384 | let i = left + 1;
|
7385 | let j = right;
|
7386 | swap(ids, median, i);
|
7387 | if (dists[ids[left]] > dists[ids[right]]) swap(ids, left, right);
|
7388 | if (dists[ids[i]] > dists[ids[right]]) swap(ids, i, right);
|
7389 | if (dists[ids[left]] > dists[ids[i]]) swap(ids, left, i);
|
7390 |
|
7391 | const temp = ids[i];
|
7392 | const tempDist = dists[temp];
|
7393 | while (true) {
|
7394 | do i++; while (dists[ids[i]] < tempDist);
|
7395 | do j--; while (dists[ids[j]] > tempDist);
|
7396 | if (j < i) break;
|
7397 | swap(ids, i, j);
|
7398 | }
|
7399 | ids[left + 1] = ids[j];
|
7400 | ids[j] = temp;
|
7401 |
|
7402 | if (right - i + 1 >= j - left) {
|
7403 | quicksort(ids, dists, i, right);
|
7404 | quicksort(ids, dists, left, j - 1);
|
7405 | } else {
|
7406 | quicksort(ids, dists, left, j - 1);
|
7407 | quicksort(ids, dists, i, right);
|
7408 | }
|
7409 | }
|
7410 | }
|
7411 |
|
7412 | function swap(arr, i, j) {
|
7413 | const tmp = arr[i];
|
7414 | arr[i] = arr[j];
|
7415 | arr[j] = tmp;
|
7416 | }
|
7417 |
|
7418 | function defaultGetX(p) {
|
7419 | return p[0];
|
7420 | }
|
7421 | function defaultGetY(p) {
|
7422 | return p[1];
|
7423 | }
|
7424 |
|
7425 | const epsilon$2 = 1e-6;
|
7426 |
|
7427 | class Path {
|
7428 | constructor() {
|
7429 | this._x0 = this._y0 =
|
7430 | this._x1 = this._y1 = null;
|
7431 | this._ = "";
|
7432 | }
|
7433 | moveTo(x, y) {
|
7434 | this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
|
7435 | }
|
7436 | closePath() {
|
7437 | if (this._x1 !== null) {
|
7438 | this._x1 = this._x0, this._y1 = this._y0;
|
7439 | this._ += "Z";
|
7440 | }
|
7441 | }
|
7442 | lineTo(x, y) {
|
7443 | this._ += `L${this._x1 = +x},${this._y1 = +y}`;
|
7444 | }
|
7445 | arc(x, y, r) {
|
7446 | x = +x, y = +y, r = +r;
|
7447 | const x0 = x + r;
|
7448 | const y0 = y;
|
7449 | if (r < 0) throw new Error("negative radius");
|
7450 | if (this._x1 === null) this._ += `M${x0},${y0}`;
|
7451 | else if (Math.abs(this._x1 - x0) > epsilon$2 || Math.abs(this._y1 - y0) > epsilon$2) this._ += "L" + x0 + "," + y0;
|
7452 | if (!r) return;
|
7453 | this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`;
|
7454 | }
|
7455 | rect(x, y, w, h) {
|
7456 | this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`;
|
7457 | }
|
7458 | value() {
|
7459 | return this._ || null;
|
7460 | }
|
7461 | }
|
7462 |
|
7463 | class Polygon {
|
7464 | constructor() {
|
7465 | this._ = [];
|
7466 | }
|
7467 | moveTo(x, y) {
|
7468 | this._.push([x, y]);
|
7469 | }
|
7470 | closePath() {
|
7471 | this._.push(this._[0].slice());
|
7472 | }
|
7473 | lineTo(x, y) {
|
7474 | this._.push([x, y]);
|
7475 | }
|
7476 | value() {
|
7477 | return this._.length ? this._ : null;
|
7478 | }
|
7479 | }
|
7480 |
|
7481 | class Voronoi {
|
7482 | constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) {
|
7483 | if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds");
|
7484 | this.delaunay = delaunay;
|
7485 | this._circumcenters = new Float64Array(delaunay.points.length * 2);
|
7486 | this.vectors = new Float64Array(delaunay.points.length * 2);
|
7487 | this.xmax = xmax, this.xmin = xmin;
|
7488 | this.ymax = ymax, this.ymin = ymin;
|
7489 | this._init();
|
7490 | }
|
7491 | update() {
|
7492 | this.delaunay.update();
|
7493 | this._init();
|
7494 | return this;
|
7495 | }
|
7496 | _init() {
|
7497 | const {delaunay: {points, hull, triangles}, vectors} = this;
|
7498 |
|
7499 |
|
7500 | const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2);
|
7501 | for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
|
7502 | const t1 = triangles[i] * 2;
|
7503 | const t2 = triangles[i + 1] * 2;
|
7504 | const t3 = triangles[i + 2] * 2;
|
7505 | const x1 = points[t1];
|
7506 | const y1 = points[t1 + 1];
|
7507 | const x2 = points[t2];
|
7508 | const y2 = points[t2 + 1];
|
7509 | const x3 = points[t3];
|
7510 | const y3 = points[t3 + 1];
|
7511 |
|
7512 | const dx = x2 - x1;
|
7513 | const dy = y2 - y1;
|
7514 | const ex = x3 - x1;
|
7515 | const ey = y3 - y1;
|
7516 | const ab = (dx * ey - dy * ex) * 2;
|
7517 |
|
7518 | if (Math.abs(ab) < 1e-9) {
|
7519 |
|
7520 |
|
7521 |
|
7522 |
|
7523 |
|
7524 | let a = 1e9;
|
7525 |
|
7526 |
|
7527 |
|
7528 | const r = triangles[0] * 2;
|
7529 | a *= Math.sign((points[r] - x1) * ey - (points[r + 1] - y1) * ex);
|
7530 | x = (x1 + x3) / 2 - a * ey;
|
7531 | y = (y1 + y3) / 2 + a * ex;
|
7532 | } else {
|
7533 | const d = 1 / ab;
|
7534 | const bl = dx * dx + dy * dy;
|
7535 | const cl = ex * ex + ey * ey;
|
7536 | x = x1 + (ey * bl - dy * cl) * d;
|
7537 | y = y1 + (dx * cl - ex * bl) * d;
|
7538 | }
|
7539 | circumcenters[j] = x;
|
7540 | circumcenters[j + 1] = y;
|
7541 | }
|
7542 |
|
7543 |
|
7544 | let h = hull[hull.length - 1];
|
7545 | let p0, p1 = h * 4;
|
7546 | let x0, x1 = points[2 * h];
|
7547 | let y0, y1 = points[2 * h + 1];
|
7548 | vectors.fill(0);
|
7549 | for (let i = 0; i < hull.length; ++i) {
|
7550 | h = hull[i];
|
7551 | p0 = p1, x0 = x1, y0 = y1;
|
7552 | p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1];
|
7553 | vectors[p0 + 2] = vectors[p1] = y0 - y1;
|
7554 | vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
|
7555 | }
|
7556 | }
|
7557 | render(context) {
|
7558 | const buffer = context == null ? context = new Path : undefined;
|
7559 | const {delaunay: {halfedges, inedges, hull}, circumcenters, vectors} = this;
|
7560 | if (hull.length <= 1) return null;
|
7561 | for (let i = 0, n = halfedges.length; i < n; ++i) {
|
7562 | const j = halfedges[i];
|
7563 | if (j < i) continue;
|
7564 | const ti = Math.floor(i / 3) * 2;
|
7565 | const tj = Math.floor(j / 3) * 2;
|
7566 | const xi = circumcenters[ti];
|
7567 | const yi = circumcenters[ti + 1];
|
7568 | const xj = circumcenters[tj];
|
7569 | const yj = circumcenters[tj + 1];
|
7570 | this._renderSegment(xi, yi, xj, yj, context);
|
7571 | }
|
7572 | let h0, h1 = hull[hull.length - 1];
|
7573 | for (let i = 0; i < hull.length; ++i) {
|
7574 | h0 = h1, h1 = hull[i];
|
7575 | const t = Math.floor(inedges[h1] / 3) * 2;
|
7576 | const x = circumcenters[t];
|
7577 | const y = circumcenters[t + 1];
|
7578 | const v = h0 * 4;
|
7579 | const p = this._project(x, y, vectors[v + 2], vectors[v + 3]);
|
7580 | if (p) this._renderSegment(x, y, p[0], p[1], context);
|
7581 | }
|
7582 | return buffer && buffer.value();
|
7583 | }
|
7584 | renderBounds(context) {
|
7585 | const buffer = context == null ? context = new Path : undefined;
|
7586 | context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin);
|
7587 | return buffer && buffer.value();
|
7588 | }
|
7589 | renderCell(i, context) {
|
7590 | const buffer = context == null ? context = new Path : undefined;
|
7591 | const points = this._clip(i);
|
7592 | if (points === null || !points.length) return;
|
7593 | context.moveTo(points[0], points[1]);
|
7594 | let n = points.length;
|
7595 | while (points[0] === points[n-2] && points[1] === points[n-1] && n > 1) n -= 2;
|
7596 | for (let i = 2; i < n; i += 2) {
|
7597 | if (points[i] !== points[i-2] || points[i+1] !== points[i-1])
|
7598 | context.lineTo(points[i], points[i + 1]);
|
7599 | }
|
7600 | context.closePath();
|
7601 | return buffer && buffer.value();
|
7602 | }
|
7603 | *cellPolygons() {
|
7604 | const {delaunay: {points}} = this;
|
7605 | for (let i = 0, n = points.length / 2; i < n; ++i) {
|
7606 | const cell = this.cellPolygon(i);
|
7607 | if (cell) cell.index = i, yield cell;
|
7608 | }
|
7609 | }
|
7610 | cellPolygon(i) {
|
7611 | const polygon = new Polygon;
|
7612 | this.renderCell(i, polygon);
|
7613 | return polygon.value();
|
7614 | }
|
7615 | _renderSegment(x0, y0, x1, y1, context) {
|
7616 | let S;
|
7617 | const c0 = this._regioncode(x0, y0);
|
7618 | const c1 = this._regioncode(x1, y1);
|
7619 | if (c0 === 0 && c1 === 0) {
|
7620 | context.moveTo(x0, y0);
|
7621 | context.lineTo(x1, y1);
|
7622 | } else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) {
|
7623 | context.moveTo(S[0], S[1]);
|
7624 | context.lineTo(S[2], S[3]);
|
7625 | }
|
7626 | }
|
7627 | contains(i, x, y) {
|
7628 | if ((x = +x, x !== x) || (y = +y, y !== y)) return false;
|
7629 | return this.delaunay._step(i, x, y) === i;
|
7630 | }
|
7631 | *neighbors(i) {
|
7632 | const ci = this._clip(i);
|
7633 | if (ci) for (const j of this.delaunay.neighbors(i)) {
|
7634 | const cj = this._clip(j);
|
7635 |
|
7636 | if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) {
|
7637 | for (let aj = 0, lj = cj.length; aj < lj; aj += 2) {
|
7638 | if (ci[ai] == cj[aj]
|
7639 | && ci[ai + 1] == cj[aj + 1]
|
7640 | && ci[(ai + 2) % li] == cj[(aj + lj - 2) % lj]
|
7641 | && ci[(ai + 3) % li] == cj[(aj + lj - 1) % lj]
|
7642 | ) {
|
7643 | yield j;
|
7644 | break loop;
|
7645 | }
|
7646 | }
|
7647 | }
|
7648 | }
|
7649 | }
|
7650 | _cell(i) {
|
7651 | const {circumcenters, delaunay: {inedges, halfedges, triangles}} = this;
|
7652 | const e0 = inedges[i];
|
7653 | if (e0 === -1) return null;
|
7654 | const points = [];
|
7655 | let e = e0;
|
7656 | do {
|
7657 | const t = Math.floor(e / 3);
|
7658 | points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]);
|
7659 | e = e % 3 === 2 ? e - 2 : e + 1;
|
7660 | if (triangles[e] !== i) break;
|
7661 | e = halfedges[e];
|
7662 | } while (e !== e0 && e !== -1);
|
7663 | return points;
|
7664 | }
|
7665 | _clip(i) {
|
7666 |
|
7667 | if (i === 0 && this.delaunay.hull.length === 1) {
|
7668 | return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
|
7669 | }
|
7670 | const points = this._cell(i);
|
7671 | if (points === null) return null;
|
7672 | const {vectors: V} = this;
|
7673 | const v = i * 4;
|
7674 | return V[v] || V[v + 1]
|
7675 | ? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3])
|
7676 | : this._clipFinite(i, points);
|
7677 | }
|
7678 | _clipFinite(i, points) {
|
7679 | const n = points.length;
|
7680 | let P = null;
|
7681 | let x0, y0, x1 = points[n - 2], y1 = points[n - 1];
|
7682 | let c0, c1 = this._regioncode(x1, y1);
|
7683 | let e0, e1 = 0;
|
7684 | for (let j = 0; j < n; j += 2) {
|
7685 | x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1];
|
7686 | c0 = c1, c1 = this._regioncode(x1, y1);
|
7687 | if (c0 === 0 && c1 === 0) {
|
7688 | e0 = e1, e1 = 0;
|
7689 | if (P) P.push(x1, y1);
|
7690 | else P = [x1, y1];
|
7691 | } else {
|
7692 | let S, sx0, sy0, sx1, sy1;
|
7693 | if (c0 === 0) {
|
7694 | if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue;
|
7695 | [sx0, sy0, sx1, sy1] = S;
|
7696 | } else {
|
7697 | if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue;
|
7698 | [sx1, sy1, sx0, sy0] = S;
|
7699 | e0 = e1, e1 = this._edgecode(sx0, sy0);
|
7700 | if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
7701 | if (P) P.push(sx0, sy0);
|
7702 | else P = [sx0, sy0];
|
7703 | }
|
7704 | e0 = e1, e1 = this._edgecode(sx1, sy1);
|
7705 | if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
7706 | if (P) P.push(sx1, sy1);
|
7707 | else P = [sx1, sy1];
|
7708 | }
|
7709 | }
|
7710 | if (P) {
|
7711 | e0 = e1, e1 = this._edgecode(P[0], P[1]);
|
7712 | if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
7713 | } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
|
7714 | return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
|
7715 | }
|
7716 | return P;
|
7717 | }
|
7718 | _clipSegment(x0, y0, x1, y1, c0, c1) {
|
7719 | while (true) {
|
7720 | if (c0 === 0 && c1 === 0) return [x0, y0, x1, y1];
|
7721 | if (c0 & c1) return null;
|
7722 | let x, y, c = c0 || c1;
|
7723 | if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax;
|
7724 | else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin;
|
7725 | else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax;
|
7726 | else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin;
|
7727 | if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0);
|
7728 | else x1 = x, y1 = y, c1 = this._regioncode(x1, y1);
|
7729 | }
|
7730 | }
|
7731 | _clipInfinite(i, points, vx0, vy0, vxn, vyn) {
|
7732 | let P = Array.from(points), p;
|
7733 | if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]);
|
7734 | if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]);
|
7735 | if (P = this._clipFinite(i, P)) {
|
7736 | for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) {
|
7737 | c0 = c1, c1 = this._edgecode(P[j], P[j + 1]);
|
7738 | if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length;
|
7739 | }
|
7740 | } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
|
7741 | P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax];
|
7742 | }
|
7743 | return P;
|
7744 | }
|
7745 | _edge(i, e0, e1, P, j) {
|
7746 | while (e0 !== e1) {
|
7747 | let x, y;
|
7748 | switch (e0) {
|
7749 | case 0b0101: e0 = 0b0100; continue;
|
7750 | case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break;
|
7751 | case 0b0110: e0 = 0b0010; continue;
|
7752 | case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break;
|
7753 | case 0b1010: e0 = 0b1000; continue;
|
7754 | case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break;
|
7755 | case 0b1001: e0 = 0b0001; continue;
|
7756 | case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break;
|
7757 | }
|
7758 |
|
7759 |
|
7760 | if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) {
|
7761 | P.splice(j, 0, x, y), j += 2;
|
7762 | }
|
7763 | }
|
7764 | if (P.length > 4) {
|
7765 | for (let i = 0; i < P.length; i+= 2) {
|
7766 | const j = (i + 2) % P.length, k = (i + 4) % P.length;
|
7767 | if (P[i] === P[j] && P[j] === P[k]
|
7768 | || P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1])
|
7769 | P.splice(j, 2), i -= 2;
|
7770 | }
|
7771 | }
|
7772 | return j;
|
7773 | }
|
7774 | _project(x0, y0, vx, vy) {
|
7775 | let t = Infinity, c, x, y;
|
7776 | if (vy < 0) {
|
7777 | if (y0 <= this.ymin) return null;
|
7778 | if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx;
|
7779 | } else if (vy > 0) {
|
7780 | if (y0 >= this.ymax) return null;
|
7781 | if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx;
|
7782 | }
|
7783 | if (vx > 0) {
|
7784 | if (x0 >= this.xmax) return null;
|
7785 | if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy;
|
7786 | } else if (vx < 0) {
|
7787 | if (x0 <= this.xmin) return null;
|
7788 | if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy;
|
7789 | }
|
7790 | return [x, y];
|
7791 | }
|
7792 | _edgecode(x, y) {
|
7793 | return (x === this.xmin ? 0b0001
|
7794 | : x === this.xmax ? 0b0010 : 0b0000)
|
7795 | | (y === this.ymin ? 0b0100
|
7796 | : y === this.ymax ? 0b1000 : 0b0000);
|
7797 | }
|
7798 | _regioncode(x, y) {
|
7799 | return (x < this.xmin ? 0b0001
|
7800 | : x > this.xmax ? 0b0010 : 0b0000)
|
7801 | | (y < this.ymin ? 0b0100
|
7802 | : y > this.ymax ? 0b1000 : 0b0000);
|
7803 | }
|
7804 | }
|
7805 |
|
7806 | const tau$2 = 2 * Math.PI, pow$2 = Math.pow;
|
7807 |
|
7808 | function pointX(p) {
|
7809 | return p[0];
|
7810 | }
|
7811 |
|
7812 | function pointY(p) {
|
7813 | return p[1];
|
7814 | }
|
7815 |
|
7816 |
|
7817 | function collinear(d) {
|
7818 | const {triangles, coords} = d;
|
7819 | for (let i = 0; i < triangles.length; i += 3) {
|
7820 | const a = 2 * triangles[i],
|
7821 | b = 2 * triangles[i + 1],
|
7822 | c = 2 * triangles[i + 2],
|
7823 | cross = (coords[c] - coords[a]) * (coords[b + 1] - coords[a + 1])
|
7824 | - (coords[b] - coords[a]) * (coords[c + 1] - coords[a + 1]);
|
7825 | if (cross > 1e-10) return false;
|
7826 | }
|
7827 | return true;
|
7828 | }
|
7829 |
|
7830 | function jitter(x, y, r) {
|
7831 | return [x + Math.sin(x + y) * r, y + Math.cos(x - y) * r];
|
7832 | }
|
7833 |
|
7834 | class Delaunay {
|
7835 | static from(points, fx = pointX, fy = pointY, that) {
|
7836 | return new Delaunay("length" in points
|
7837 | ? flatArray(points, fx, fy, that)
|
7838 | : Float64Array.from(flatIterable(points, fx, fy, that)));
|
7839 | }
|
7840 | constructor(points) {
|
7841 | this._delaunator = new Delaunator(points);
|
7842 | this.inedges = new Int32Array(points.length / 2);
|
7843 | this._hullIndex = new Int32Array(points.length / 2);
|
7844 | this.points = this._delaunator.coords;
|
7845 | this._init();
|
7846 | }
|
7847 | update() {
|
7848 | this._delaunator.update();
|
7849 | this._init();
|
7850 | return this;
|
7851 | }
|
7852 | _init() {
|
7853 | const d = this._delaunator, points = this.points;
|
7854 |
|
7855 |
|
7856 | if (d.hull && d.hull.length > 2 && collinear(d)) {
|
7857 | this.collinear = Int32Array.from({length: points.length/2}, (_,i) => i)
|
7858 | .sort((i, j) => points[2 * i] - points[2 * j] || points[2 * i + 1] - points[2 * j + 1]);
|
7859 | const e = this.collinear[0], f = this.collinear[this.collinear.length - 1],
|
7860 | bounds = [ points[2 * e], points[2 * e + 1], points[2 * f], points[2 * f + 1] ],
|
7861 | r = 1e-8 * Math.hypot(bounds[3] - bounds[1], bounds[2] - bounds[0]);
|
7862 | for (let i = 0, n = points.length / 2; i < n; ++i) {
|
7863 | const p = jitter(points[2 * i], points[2 * i + 1], r);
|
7864 | points[2 * i] = p[0];
|
7865 | points[2 * i + 1] = p[1];
|
7866 | }
|
7867 | this._delaunator = new Delaunator(points);
|
7868 | } else {
|
7869 | delete this.collinear;
|
7870 | }
|
7871 |
|
7872 | const halfedges = this.halfedges = this._delaunator.halfedges;
|
7873 | const hull = this.hull = this._delaunator.hull;
|
7874 | const triangles = this.triangles = this._delaunator.triangles;
|
7875 | const inedges = this.inedges.fill(-1);
|
7876 | const hullIndex = this._hullIndex.fill(-1);
|
7877 |
|
7878 |
|
7879 |
|
7880 |
|
7881 | for (let e = 0, n = halfedges.length; e < n; ++e) {
|
7882 | const p = triangles[e % 3 === 2 ? e - 2 : e + 1];
|
7883 | if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e;
|
7884 | }
|
7885 | for (let i = 0, n = hull.length; i < n; ++i) {
|
7886 | hullIndex[hull[i]] = i;
|
7887 | }
|
7888 |
|
7889 |
|
7890 | if (hull.length <= 2 && hull.length > 0) {
|
7891 | this.triangles = new Int32Array(3).fill(-1);
|
7892 | this.halfedges = new Int32Array(3).fill(-1);
|
7893 | this.triangles[0] = hull[0];
|
7894 | inedges[hull[0]] = 1;
|
7895 | if (hull.length === 2) {
|
7896 | inedges[hull[1]] = 0;
|
7897 | this.triangles[1] = hull[1];
|
7898 | this.triangles[2] = hull[1];
|
7899 | }
|
7900 | }
|
7901 | }
|
7902 | voronoi(bounds) {
|
7903 | return new Voronoi(this, bounds);
|
7904 | }
|
7905 | *neighbors(i) {
|
7906 | const {inedges, hull, _hullIndex, halfedges, triangles, collinear} = this;
|
7907 |
|
7908 |
|
7909 | if (collinear) {
|
7910 | const l = collinear.indexOf(i);
|
7911 | if (l > 0) yield collinear[l - 1];
|
7912 | if (l < collinear.length - 1) yield collinear[l + 1];
|
7913 | return;
|
7914 | }
|
7915 |
|
7916 | const e0 = inedges[i];
|
7917 | if (e0 === -1) return;
|
7918 | let e = e0, p0 = -1;
|
7919 | do {
|
7920 | yield p0 = triangles[e];
|
7921 | e = e % 3 === 2 ? e - 2 : e + 1;
|
7922 | if (triangles[e] !== i) return;
|
7923 | e = halfedges[e];
|
7924 | if (e === -1) {
|
7925 | const p = hull[(_hullIndex[i] + 1) % hull.length];
|
7926 | if (p !== p0) yield p;
|
7927 | return;
|
7928 | }
|
7929 | } while (e !== e0);
|
7930 | }
|
7931 | find(x, y, i = 0) {
|
7932 | if ((x = +x, x !== x) || (y = +y, y !== y)) return -1;
|
7933 | const i0 = i;
|
7934 | let c;
|
7935 | while ((c = this._step(i, x, y)) >= 0 && c !== i && c !== i0) i = c;
|
7936 | return c;
|
7937 | }
|
7938 | _step(i, x, y) {
|
7939 | const {inedges, hull, _hullIndex, halfedges, triangles, points} = this;
|
7940 | if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1);
|
7941 | let c = i;
|
7942 | let dc = pow$2(x - points[i * 2], 2) + pow$2(y - points[i * 2 + 1], 2);
|
7943 | const e0 = inedges[i];
|
7944 | let e = e0;
|
7945 | do {
|
7946 | let t = triangles[e];
|
7947 | const dt = pow$2(x - points[t * 2], 2) + pow$2(y - points[t * 2 + 1], 2);
|
7948 | if (dt < dc) dc = dt, c = t;
|
7949 | e = e % 3 === 2 ? e - 2 : e + 1;
|
7950 | if (triangles[e] !== i) break;
|
7951 | e = halfedges[e];
|
7952 | if (e === -1) {
|
7953 | e = hull[(_hullIndex[i] + 1) % hull.length];
|
7954 | if (e !== t) {
|
7955 | if (pow$2(x - points[e * 2], 2) + pow$2(y - points[e * 2 + 1], 2) < dc) return e;
|
7956 | }
|
7957 | break;
|
7958 | }
|
7959 | } while (e !== e0);
|
7960 | return c;
|
7961 | }
|
7962 | render(context) {
|
7963 | const buffer = context == null ? context = new Path : undefined;
|
7964 | const {points, halfedges, triangles} = this;
|
7965 | for (let i = 0, n = halfedges.length; i < n; ++i) {
|
7966 | const j = halfedges[i];
|
7967 | if (j < i) continue;
|
7968 | const ti = triangles[i] * 2;
|
7969 | const tj = triangles[j] * 2;
|
7970 | context.moveTo(points[ti], points[ti + 1]);
|
7971 | context.lineTo(points[tj], points[tj + 1]);
|
7972 | }
|
7973 | this.renderHull(context);
|
7974 | return buffer && buffer.value();
|
7975 | }
|
7976 | renderPoints(context, r) {
|
7977 | if (r === undefined && (!context || typeof context.moveTo !== "function")) r = context, context = null;
|
7978 | r = r == undefined ? 2 : +r;
|
7979 | const buffer = context == null ? context = new Path : undefined;
|
7980 | const {points} = this;
|
7981 | for (let i = 0, n = points.length; i < n; i += 2) {
|
7982 | const x = points[i], y = points[i + 1];
|
7983 | context.moveTo(x + r, y);
|
7984 | context.arc(x, y, r, 0, tau$2);
|
7985 | }
|
7986 | return buffer && buffer.value();
|
7987 | }
|
7988 | renderHull(context) {
|
7989 | const buffer = context == null ? context = new Path : undefined;
|
7990 | const {hull, points} = this;
|
7991 | const h = hull[0] * 2, n = hull.length;
|
7992 | context.moveTo(points[h], points[h + 1]);
|
7993 | for (let i = 1; i < n; ++i) {
|
7994 | const h = 2 * hull[i];
|
7995 | context.lineTo(points[h], points[h + 1]);
|
7996 | }
|
7997 | context.closePath();
|
7998 | return buffer && buffer.value();
|
7999 | }
|
8000 | hullPolygon() {
|
8001 | const polygon = new Polygon;
|
8002 | this.renderHull(polygon);
|
8003 | return polygon.value();
|
8004 | }
|
8005 | renderTriangle(i, context) {
|
8006 | const buffer = context == null ? context = new Path : undefined;
|
8007 | const {points, triangles} = this;
|
8008 | const t0 = triangles[i *= 3] * 2;
|
8009 | const t1 = triangles[i + 1] * 2;
|
8010 | const t2 = triangles[i + 2] * 2;
|
8011 | context.moveTo(points[t0], points[t0 + 1]);
|
8012 | context.lineTo(points[t1], points[t1 + 1]);
|
8013 | context.lineTo(points[t2], points[t2 + 1]);
|
8014 | context.closePath();
|
8015 | return buffer && buffer.value();
|
8016 | }
|
8017 | *trianglePolygons() {
|
8018 | const {triangles} = this;
|
8019 | for (let i = 0, n = triangles.length / 3; i < n; ++i) {
|
8020 | yield this.trianglePolygon(i);
|
8021 | }
|
8022 | }
|
8023 | trianglePolygon(i) {
|
8024 | const polygon = new Polygon;
|
8025 | this.renderTriangle(i, polygon);
|
8026 | return polygon.value();
|
8027 | }
|
8028 | }
|
8029 |
|
8030 | function flatArray(points, fx, fy, that) {
|
8031 | const n = points.length;
|
8032 | const array = new Float64Array(n * 2);
|
8033 | for (let i = 0; i < n; ++i) {
|
8034 | const p = points[i];
|
8035 | array[i * 2] = fx.call(that, p, i, points);
|
8036 | array[i * 2 + 1] = fy.call(that, p, i, points);
|
8037 | }
|
8038 | return array;
|
8039 | }
|
8040 |
|
8041 | function* flatIterable(points, fx, fy, that) {
|
8042 | let i = 0;
|
8043 | for (const p of points) {
|
8044 | yield fx.call(that, p, i, points);
|
8045 | yield fy.call(that, p, i, points);
|
8046 | ++i;
|
8047 | }
|
8048 | }
|
8049 |
|
8050 | var EOL = {},
|
8051 | EOF = {},
|
8052 | QUOTE = 34,
|
8053 | NEWLINE = 10,
|
8054 | RETURN = 13;
|
8055 |
|
8056 | function objectConverter(columns) {
|
8057 | return new Function("d", "return {" + columns.map(function(name, i) {
|
8058 | return JSON.stringify(name) + ": d[" + i + "] || \"\"";
|
8059 | }).join(",") + "}");
|
8060 | }
|
8061 |
|
8062 | function customConverter(columns, f) {
|
8063 | var object = objectConverter(columns);
|
8064 | return function(row, i) {
|
8065 | return f(object(row), i, columns);
|
8066 | };
|
8067 | }
|
8068 |
|
8069 |
|
8070 | function inferColumns(rows) {
|
8071 | var columnSet = Object.create(null),
|
8072 | columns = [];
|
8073 |
|
8074 | rows.forEach(function(row) {
|
8075 | for (var column in row) {
|
8076 | if (!(column in columnSet)) {
|
8077 | columns.push(columnSet[column] = column);
|
8078 | }
|
8079 | }
|
8080 | });
|
8081 |
|
8082 | return columns;
|
8083 | }
|
8084 |
|
8085 | function pad$1(value, width) {
|
8086 | var s = value + "", length = s.length;
|
8087 | return length < width ? new Array(width - length + 1).join(0) + s : s;
|
8088 | }
|
8089 |
|
8090 | function formatYear$1(year) {
|
8091 | return year < 0 ? "-" + pad$1(-year, 6)
|
8092 | : year > 9999 ? "+" + pad$1(year, 6)
|
8093 | : pad$1(year, 4);
|
8094 | }
|
8095 |
|
8096 | function formatDate(date) {
|
8097 | var hours = date.getUTCHours(),
|
8098 | minutes = date.getUTCMinutes(),
|
8099 | seconds = date.getUTCSeconds(),
|
8100 | milliseconds = date.getUTCMilliseconds();
|
8101 | return isNaN(date) ? "Invalid Date"
|
8102 | : formatYear$1(date.getUTCFullYear()) + "-" + pad$1(date.getUTCMonth() + 1, 2) + "-" + pad$1(date.getUTCDate(), 2)
|
8103 | + (milliseconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "." + pad$1(milliseconds, 3) + "Z"
|
8104 | : seconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "Z"
|
8105 | : minutes || hours ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + "Z"
|
8106 | : "");
|
8107 | }
|
8108 |
|
8109 | function dsvFormat(delimiter) {
|
8110 | var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
|
8111 | DELIMITER = delimiter.charCodeAt(0);
|
8112 |
|
8113 | function parse(text, f) {
|
8114 | var convert, columns, rows = parseRows(text, function(row, i) {
|
8115 | if (convert) return convert(row, i - 1);
|
8116 | columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
|
8117 | });
|
8118 | rows.columns = columns || [];
|
8119 | return rows;
|
8120 | }
|
8121 |
|
8122 | function parseRows(text, f) {
|
8123 | var rows = [],
|
8124 | N = text.length,
|
8125 | I = 0,
|
8126 | n = 0,
|
8127 | t,
|
8128 | eof = N <= 0,
|
8129 | eol = false;
|
8130 |
|
8131 |
|
8132 | if (text.charCodeAt(N - 1) === NEWLINE) --N;
|
8133 | if (text.charCodeAt(N - 1) === RETURN) --N;
|
8134 |
|
8135 | function token() {
|
8136 | if (eof) return EOF;
|
8137 | if (eol) return eol = false, EOL;
|
8138 |
|
8139 |
|
8140 | var i, j = I, c;
|
8141 | if (text.charCodeAt(j) === QUOTE) {
|
8142 | while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
|
8143 | if ((i = I) >= N) eof = true;
|
8144 | else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
|
8145 | else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
|
8146 | return text.slice(j + 1, i - 1).replace(/""/g, "\"");
|
8147 | }
|
8148 |
|
8149 | // Find next delimiter or newline.
|
8150 | while (I < N) {
|
8151 | if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
|
8152 | else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
|
8153 | else if (c !== DELIMITER) continue;
|
8154 | return text.slice(j, i);
|
8155 | }
|
8156 |
|
8157 | // Return last token before EOF.
|
8158 | return eof = true, text.slice(j, N);
|
8159 | }
|
8160 |
|
8161 | while ((t = token()) !== EOF) {
|
8162 | var row = [];
|
8163 | while (t !== EOL && t !== EOF) row.push(t), t = token();
|
8164 | if (f && (row = f(row, n++)) == null) continue;
|
8165 | rows.push(row);
|
8166 | }
|
8167 |
|
8168 | return rows;
|
8169 | }
|
8170 |
|
8171 | function preformatBody(rows, columns) {
|
8172 | return rows.map(function(row) {
|
8173 | return columns.map(function(column) {
|
8174 | return formatValue(row[column]);
|
8175 | }).join(delimiter);
|
8176 | });
|
8177 | }
|
8178 |
|
8179 | function format(rows, columns) {
|
8180 | if (columns == null) columns = inferColumns(rows);
|
8181 | return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
|
8182 | }
|
8183 |
|
8184 | function formatBody(rows, columns) {
|
8185 | if (columns == null) columns = inferColumns(rows);
|
8186 | return preformatBody(rows, columns).join("\n");
|
8187 | }
|
8188 |
|
8189 | function formatRows(rows) {
|
8190 | return rows.map(formatRow).join("\n");
|
8191 | }
|
8192 |
|
8193 | function formatRow(row) {
|
8194 | return row.map(formatValue).join(delimiter);
|
8195 | }
|
8196 |
|
8197 | function formatValue(value) {
|
8198 | return value == null ? ""
|
8199 | : value instanceof Date ? formatDate(value)
|
8200 | : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
|
8201 | : value;
|
8202 | }
|
8203 |
|
8204 | return {
|
8205 | parse: parse,
|
8206 | parseRows: parseRows,
|
8207 | format: format,
|
8208 | formatBody: formatBody,
|
8209 | formatRows: formatRows,
|
8210 | formatRow: formatRow,
|
8211 | formatValue: formatValue
|
8212 | };
|
8213 | }
|
8214 |
|
8215 | var csv$1 = dsvFormat(",");
|
8216 |
|
8217 | var csvParse = csv$1.parse;
|
8218 | var csvParseRows = csv$1.parseRows;
|
8219 | var csvFormat = csv$1.format;
|
8220 | var csvFormatBody = csv$1.formatBody;
|
8221 | var csvFormatRows = csv$1.formatRows;
|
8222 | var csvFormatRow = csv$1.formatRow;
|
8223 | var csvFormatValue = csv$1.formatValue;
|
8224 |
|
8225 | var tsv$1 = dsvFormat("\t");
|
8226 |
|
8227 | var tsvParse = tsv$1.parse;
|
8228 | var tsvParseRows = tsv$1.parseRows;
|
8229 | var tsvFormat = tsv$1.format;
|
8230 | var tsvFormatBody = tsv$1.formatBody;
|
8231 | var tsvFormatRows = tsv$1.formatRows;
|
8232 | var tsvFormatRow = tsv$1.formatRow;
|
8233 | var tsvFormatValue = tsv$1.formatValue;
|
8234 |
|
8235 | function autoType(object) {
|
8236 | for (var key in object) {
|
8237 | var value = object[key].trim(), number, m;
|
8238 | if (!value) value = null;
|
8239 | else if (value === "true") value = true;
|
8240 | else if (value === "false") value = false;
|
8241 | else if (value === "NaN") value = NaN;
|
8242 | else if (!isNaN(number = +value)) value = number;
|
8243 | else if (m = value.match(/^([-+]\d{2})?\d{4}(-\d{2}(-\d{2})?)?(T\d{2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|[-+]\d{2}:\d{2})?)?$/)) {
|
8244 | if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
|
8245 | value = new Date(value);
|
8246 | }
|
8247 | else continue;
|
8248 | object[key] = value;
|
8249 | }
|
8250 | return object;
|
8251 | }
|
8252 |
|
8253 | // https://github.com/d3/d3-dsv/issues/45
|
8254 | const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
|
8255 |
|
8256 | function responseBlob(response) {
|
8257 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
8258 | return response.blob();
|
8259 | }
|
8260 |
|
8261 | function blob(input, init) {
|
8262 | return fetch(input, init).then(responseBlob);
|
8263 | }
|
8264 |
|
8265 | function responseArrayBuffer(response) {
|
8266 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
8267 | return response.arrayBuffer();
|
8268 | }
|
8269 |
|
8270 | function buffer(input, init) {
|
8271 | return fetch(input, init).then(responseArrayBuffer);
|
8272 | }
|
8273 |
|
8274 | function responseText(response) {
|
8275 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
8276 | return response.text();
|
8277 | }
|
8278 |
|
8279 | function text(input, init) {
|
8280 | return fetch(input, init).then(responseText);
|
8281 | }
|
8282 |
|
8283 | function dsvParse(parse) {
|
8284 | return function(input, init, row) {
|
8285 | if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
|
8286 | return text(input, init).then(function(response) {
|
8287 | return parse(response, row);
|
8288 | });
|
8289 | };
|
8290 | }
|
8291 |
|
8292 | function dsv(delimiter, input, init, row) {
|
8293 | if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
|
8294 | var format = dsvFormat(delimiter);
|
8295 | return text(input, init).then(function(response) {
|
8296 | return format.parse(response, row);
|
8297 | });
|
8298 | }
|
8299 |
|
8300 | var csv = dsvParse(csvParse);
|
8301 | var tsv = dsvParse(tsvParse);
|
8302 |
|
8303 | function image(input, init) {
|
8304 | return new Promise(function(resolve, reject) {
|
8305 | var image = new Image;
|
8306 | for (var key in init) image[key] = init[key];
|
8307 | image.onerror = reject;
|
8308 | image.onload = function() { resolve(image); };
|
8309 | image.src = input;
|
8310 | });
|
8311 | }
|
8312 |
|
8313 | function responseJson(response) {
|
8314 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
8315 | if (response.status === 204 || response.status === 205) return;
|
8316 | return response.json();
|
8317 | }
|
8318 |
|
8319 | function json(input, init) {
|
8320 | return fetch(input, init).then(responseJson);
|
8321 | }
|
8322 |
|
8323 | function parser(type) {
|
8324 | return (input, init) => text(input, init)
|
8325 | .then(text => (new DOMParser).parseFromString(text, type));
|
8326 | }
|
8327 |
|
8328 | var xml = parser("application/xml");
|
8329 |
|
8330 | var html = parser("text/html");
|
8331 |
|
8332 | var svg = parser("image/svg+xml");
|
8333 |
|
8334 | function center(x, y) {
|
8335 | var nodes, strength = 1;
|
8336 |
|
8337 | if (x == null) x = 0;
|
8338 | if (y == null) y = 0;
|
8339 |
|
8340 | function force() {
|
8341 | var i,
|
8342 | n = nodes.length,
|
8343 | node,
|
8344 | sx = 0,
|
8345 | sy = 0;
|
8346 |
|
8347 | for (i = 0; i < n; ++i) {
|
8348 | node = nodes[i], sx += node.x, sy += node.y;
|
8349 | }
|
8350 |
|
8351 | for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
|
8352 | node = nodes[i], node.x -= sx, node.y -= sy;
|
8353 | }
|
8354 | }
|
8355 |
|
8356 | force.initialize = function(_) {
|
8357 | nodes = _;
|
8358 | };
|
8359 |
|
8360 | force.x = function(_) {
|
8361 | return arguments.length ? (x = +_, force) : x;
|
8362 | };
|
8363 |
|
8364 | force.y = function(_) {
|
8365 | return arguments.length ? (y = +_, force) : y;
|
8366 | };
|
8367 |
|
8368 | force.strength = function(_) {
|
8369 | return arguments.length ? (strength = +_, force) : strength;
|
8370 | };
|
8371 |
|
8372 | return force;
|
8373 | }
|
8374 |
|
8375 | function tree_add(d) {
|
8376 | const x = +this._x.call(null, d),
|
8377 | y = +this._y.call(null, d);
|
8378 | return add(this.cover(x, y), x, y, d);
|
8379 | }
|
8380 |
|
8381 | function add(tree, x, y, d) {
|
8382 | if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
|
8383 |
|
8384 | var parent,
|
8385 | node = tree._root,
|
8386 | leaf = {data: d},
|
8387 | x0 = tree._x0,
|
8388 | y0 = tree._y0,
|
8389 | x1 = tree._x1,
|
8390 | y1 = tree._y1,
|
8391 | xm,
|
8392 | ym,
|
8393 | xp,
|
8394 | yp,
|
8395 | right,
|
8396 | bottom,
|
8397 | i,
|
8398 | j;
|
8399 |
|
8400 | // If the tree is empty, initialize the root as a leaf.
|
8401 | if (!node) return tree._root = leaf, tree;
|
8402 |
|
8403 | // Find the existing leaf for the new point, or add it.
|
8404 | while (node.length) {
|
8405 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
8406 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
8407 | if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
|
8408 | }
|
8409 |
|
8410 | // Is the new point is exactly coincident with the existing point?
|
8411 | xp = +tree._x.call(null, node.data);
|
8412 | yp = +tree._y.call(null, node.data);
|
8413 | if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
|
8414 |
|
8415 | // Otherwise, split the leaf node until the old and new point are separated.
|
8416 | do {
|
8417 | parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
|
8418 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
8419 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
8420 | } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
|
8421 | return parent[j] = node, parent[i] = leaf, tree;
|
8422 | }
|
8423 |
|
8424 | function addAll(data) {
|
8425 | var d, i, n = data.length,
|
8426 | x,
|
8427 | y,
|
8428 | xz = new Array(n),
|
8429 | yz = new Array(n),
|
8430 | x0 = Infinity,
|
8431 | y0 = Infinity,
|
8432 | x1 = -Infinity,
|
8433 | y1 = -Infinity;
|
8434 |
|
8435 | // Compute the points and their extent.
|
8436 | for (i = 0; i < n; ++i) {
|
8437 | if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
|
8438 | xz[i] = x;
|
8439 | yz[i] = y;
|
8440 | if (x < x0) x0 = x;
|
8441 | if (x > x1) x1 = x;
|
8442 | if (y < y0) y0 = y;
|
8443 | if (y > y1) y1 = y;
|
8444 | }
|
8445 |
|
8446 | // If there were no (valid) points, abort.
|
8447 | if (x0 > x1 || y0 > y1) return this;
|
8448 |
|
8449 | // Expand the tree to cover the new points.
|
8450 | this.cover(x0, y0).cover(x1, y1);
|
8451 |
|
8452 | // Add the new points.
|
8453 | for (i = 0; i < n; ++i) {
|
8454 | add(this, xz[i], yz[i], data[i]);
|
8455 | }
|
8456 |
|
8457 | return this;
|
8458 | }
|
8459 |
|
8460 | function tree_cover(x, y) {
|
8461 | if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
|
8462 |
|
8463 | var x0 = this._x0,
|
8464 | y0 = this._y0,
|
8465 | x1 = this._x1,
|
8466 | y1 = this._y1;
|
8467 |
|
8468 | // If the quadtree has no extent, initialize them.
|
8469 | // Integer extent are necessary so that if we later double the extent,
|
8470 | // the existing quadrant boundaries don’t change due to floating point error!
|
8471 | if (isNaN(x0)) {
|
8472 | x1 = (x0 = Math.floor(x)) + 1;
|
8473 | y1 = (y0 = Math.floor(y)) + 1;
|
8474 | }
|
8475 |
|
8476 | // Otherwise, double repeatedly to cover.
|
8477 | else {
|
8478 | var z = x1 - x0 || 1,
|
8479 | node = this._root,
|
8480 | parent,
|
8481 | i;
|
8482 |
|
8483 | while (x0 > x || x >= x1 || y0 > y || y >= y1) {
|
8484 | i = (y < y0) << 1 | (x < x0);
|
8485 | parent = new Array(4), parent[i] = node, node = parent, z *= 2;
|
8486 | switch (i) {
|
8487 | case 0: x1 = x0 + z, y1 = y0 + z; break;
|
8488 | case 1: x0 = x1 - z, y1 = y0 + z; break;
|
8489 | case 2: x1 = x0 + z, y0 = y1 - z; break;
|
8490 | case 3: x0 = x1 - z, y0 = y1 - z; break;
|
8491 | }
|
8492 | }
|
8493 |
|
8494 | if (this._root && this._root.length) this._root = node;
|
8495 | }
|
8496 |
|
8497 | this._x0 = x0;
|
8498 | this._y0 = y0;
|
8499 | this._x1 = x1;
|
8500 | this._y1 = y1;
|
8501 | return this;
|
8502 | }
|
8503 |
|
8504 | function tree_data() {
|
8505 | var data = [];
|
8506 | this.visit(function(node) {
|
8507 | if (!node.length) do data.push(node.data); while (node = node.next)
|
8508 | });
|
8509 | return data;
|
8510 | }
|
8511 |
|
8512 | function tree_extent(_) {
|
8513 | return arguments.length
|
8514 | ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
|
8515 | : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
|
8516 | }
|
8517 |
|
8518 | function Quad(node, x0, y0, x1, y1) {
|
8519 | this.node = node;
|
8520 | this.x0 = x0;
|
8521 | this.y0 = y0;
|
8522 | this.x1 = x1;
|
8523 | this.y1 = y1;
|
8524 | }
|
8525 |
|
8526 | function tree_find(x, y, radius) {
|
8527 | var data,
|
8528 | x0 = this._x0,
|
8529 | y0 = this._y0,
|
8530 | x1,
|
8531 | y1,
|
8532 | x2,
|
8533 | y2,
|
8534 | x3 = this._x1,
|
8535 | y3 = this._y1,
|
8536 | quads = [],
|
8537 | node = this._root,
|
8538 | q,
|
8539 | i;
|
8540 |
|
8541 | if (node) quads.push(new Quad(node, x0, y0, x3, y3));
|
8542 | if (radius == null) radius = Infinity;
|
8543 | else {
|
8544 | x0 = x - radius, y0 = y - radius;
|
8545 | x3 = x + radius, y3 = y + radius;
|
8546 | radius *= radius;
|
8547 | }
|
8548 |
|
8549 | while (q = quads.pop()) {
|
8550 |
|
8551 | // Stop searching if this quadrant can’t contain a closer node.
|
8552 | if (!(node = q.node)
|
8553 | || (x1 = q.x0) > x3
|
8554 | || (y1 = q.y0) > y3
|
8555 | || (x2 = q.x1) < x0
|
8556 | || (y2 = q.y1) < y0) continue;
|
8557 |
|
8558 | // Bisect the current quadrant.
|
8559 | if (node.length) {
|
8560 | var xm = (x1 + x2) / 2,
|
8561 | ym = (y1 + y2) / 2;
|
8562 |
|
8563 | quads.push(
|
8564 | new Quad(node[3], xm, ym, x2, y2),
|
8565 | new Quad(node[2], x1, ym, xm, y2),
|
8566 | new Quad(node[1], xm, y1, x2, ym),
|
8567 | new Quad(node[0], x1, y1, xm, ym)
|
8568 | );
|
8569 |
|
8570 | // Visit the closest quadrant first.
|
8571 | if (i = (y >= ym) << 1 | (x >= xm)) {
|
8572 | q = quads[quads.length - 1];
|
8573 | quads[quads.length - 1] = quads[quads.length - 1 - i];
|
8574 | quads[quads.length - 1 - i] = q;
|
8575 | }
|
8576 | }
|
8577 |
|
8578 | // Visit this point. (Visiting coincident points isn’t necessary!)
|
8579 | else {
|
8580 | var dx = x - +this._x.call(null, node.data),
|
8581 | dy = y - +this._y.call(null, node.data),
|
8582 | d2 = dx * dx + dy * dy;
|
8583 | if (d2 < radius) {
|
8584 | var d = Math.sqrt(radius = d2);
|
8585 | x0 = x - d, y0 = y - d;
|
8586 | x3 = x + d, y3 = y + d;
|
8587 | data = node.data;
|
8588 | }
|
8589 | }
|
8590 | }
|
8591 |
|
8592 | return data;
|
8593 | }
|
8594 |
|
8595 | function tree_remove(d) {
|
8596 | if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
|
8597 |
|
8598 | var parent,
|
8599 | node = this._root,
|
8600 | retainer,
|
8601 | previous,
|
8602 | next,
|
8603 | x0 = this._x0,
|
8604 | y0 = this._y0,
|
8605 | x1 = this._x1,
|
8606 | y1 = this._y1,
|
8607 | x,
|
8608 | y,
|
8609 | xm,
|
8610 | ym,
|
8611 | right,
|
8612 | bottom,
|
8613 | i,
|
8614 | j;
|
8615 |
|
8616 | // If the tree is empty, initialize the root as a leaf.
|
8617 | if (!node) return this;
|
8618 |
|
8619 | // Find the leaf node for the point.
|
8620 | // While descending, also retain the deepest parent with a non-removed sibling.
|
8621 | if (node.length) while (true) {
|
8622 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
8623 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
8624 | if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
|
8625 | if (!node.length) break;
|
8626 | if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
|
8627 | }
|
8628 |
|
8629 | // Find the point to remove.
|
8630 | while (node.data !== d) if (!(previous = node, node = node.next)) return this;
|
8631 | if (next = node.next) delete node.next;
|
8632 |
|
8633 | // If there are multiple coincident points, remove just the point.
|
8634 | if (previous) return (next ? previous.next = next : delete previous.next), this;
|
8635 |
|
8636 | // If this is the root point, remove it.
|
8637 | if (!parent) return this._root = next, this;
|
8638 |
|
8639 | // Remove this leaf.
|
8640 | next ? parent[i] = next : delete parent[i];
|
8641 |
|
8642 | // If the parent now contains exactly one leaf, collapse superfluous parents.
|
8643 | if ((node = parent[0] || parent[1] || parent[2] || parent[3])
|
8644 | && node === (parent[3] || parent[2] || parent[1] || parent[0])
|
8645 | && !node.length) {
|
8646 | if (retainer) retainer[j] = node;
|
8647 | else this._root = node;
|
8648 | }
|
8649 |
|
8650 | return this;
|
8651 | }
|
8652 |
|
8653 | function removeAll(data) {
|
8654 | for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
|
8655 | return this;
|
8656 | }
|
8657 |
|
8658 | function tree_root() {
|
8659 | return this._root;
|
8660 | }
|
8661 |
|
8662 | function tree_size() {
|
8663 | var size = 0;
|
8664 | this.visit(function(node) {
|
8665 | if (!node.length) do ++size; while (node = node.next)
|
8666 | });
|
8667 | return size;
|
8668 | }
|
8669 |
|
8670 | function tree_visit(callback) {
|
8671 | var quads = [], q, node = this._root, child, x0, y0, x1, y1;
|
8672 | if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
|
8673 | while (q = quads.pop()) {
|
8674 | if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
|
8675 | var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
8676 | if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
8677 | if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
8678 | if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
8679 | if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
8680 | }
|
8681 | }
|
8682 | return this;
|
8683 | }
|
8684 |
|
8685 | function tree_visitAfter(callback) {
|
8686 | var quads = [], next = [], q;
|
8687 | if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
|
8688 | while (q = quads.pop()) {
|
8689 | var node = q.node;
|
8690 | if (node.length) {
|
8691 | var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
8692 | if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
8693 | if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
8694 | if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
8695 | if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
8696 | }
|
8697 | next.push(q);
|
8698 | }
|
8699 | while (q = next.pop()) {
|
8700 | callback(q.node, q.x0, q.y0, q.x1, q.y1);
|
8701 | }
|
8702 | return this;
|
8703 | }
|
8704 |
|
8705 | function defaultX(d) {
|
8706 | return d[0];
|
8707 | }
|
8708 |
|
8709 | function tree_x(_) {
|
8710 | return arguments.length ? (this._x = _, this) : this._x;
|
8711 | }
|
8712 |
|
8713 | function defaultY(d) {
|
8714 | return d[1];
|
8715 | }
|
8716 |
|
8717 | function tree_y(_) {
|
8718 | return arguments.length ? (this._y = _, this) : this._y;
|
8719 | }
|
8720 |
|
8721 | function quadtree(nodes, x, y) {
|
8722 | var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
|
8723 | return nodes == null ? tree : tree.addAll(nodes);
|
8724 | }
|
8725 |
|
8726 | function Quadtree(x, y, x0, y0, x1, y1) {
|
8727 | this._x = x;
|
8728 | this._y = y;
|
8729 | this._x0 = x0;
|
8730 | this._y0 = y0;
|
8731 | this._x1 = x1;
|
8732 | this._y1 = y1;
|
8733 | this._root = undefined;
|
8734 | }
|
8735 |
|
8736 | function leaf_copy(leaf) {
|
8737 | var copy = {data: leaf.data}, next = copy;
|
8738 | while (leaf = leaf.next) next = next.next = {data: leaf.data};
|
8739 | return copy;
|
8740 | }
|
8741 |
|
8742 | var treeProto = quadtree.prototype = Quadtree.prototype;
|
8743 |
|
8744 | treeProto.copy = function() {
|
8745 | var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
|
8746 | node = this._root,
|
8747 | nodes,
|
8748 | child;
|
8749 |
|
8750 | if (!node) return copy;
|
8751 |
|
8752 | if (!node.length) return copy._root = leaf_copy(node), copy;
|
8753 |
|
8754 | nodes = [{source: node, target: copy._root = new Array(4)}];
|
8755 | while (node = nodes.pop()) {
|
8756 | for (var i = 0; i < 4; ++i) {
|
8757 | if (child = node.source[i]) {
|
8758 | if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
|
8759 | else node.target[i] = leaf_copy(child);
|
8760 | }
|
8761 | }
|
8762 | }
|
8763 |
|
8764 | return copy;
|
8765 | };
|
8766 |
|
8767 | treeProto.add = tree_add;
|
8768 | treeProto.addAll = addAll;
|
8769 | treeProto.cover = tree_cover;
|
8770 | treeProto.data = tree_data;
|
8771 | treeProto.extent = tree_extent;
|
8772 | treeProto.find = tree_find;
|
8773 | treeProto.remove = tree_remove;
|
8774 | treeProto.removeAll = removeAll;
|
8775 | treeProto.root = tree_root;
|
8776 | treeProto.size = tree_size;
|
8777 | treeProto.visit = tree_visit;
|
8778 | treeProto.visitAfter = tree_visitAfter;
|
8779 | treeProto.x = tree_x;
|
8780 | treeProto.y = tree_y;
|
8781 |
|
8782 | function constant$4(x) {
|
8783 | return function() {
|
8784 | return x;
|
8785 | };
|
8786 | }
|
8787 |
|
8788 | function jiggle(random) {
|
8789 | return (random() - 0.5) * 1e-6;
|
8790 | }
|
8791 |
|
8792 | function x$4(d) {
|
8793 | return d.x + d.vx;
|
8794 | }
|
8795 |
|
8796 | function y$3(d) {
|
8797 | return d.y + d.vy;
|
8798 | }
|
8799 |
|
8800 | function collide(radius) {
|
8801 | var nodes,
|
8802 | radii,
|
8803 | random,
|
8804 | strength = 1,
|
8805 | iterations = 1;
|
8806 |
|
8807 | if (typeof radius !== "function") radius = constant$4(radius == null ? 1 : +radius);
|
8808 |
|
8809 | function force() {
|
8810 | var i, n = nodes.length,
|
8811 | tree,
|
8812 | node,
|
8813 | xi,
|
8814 | yi,
|
8815 | ri,
|
8816 | ri2;
|
8817 |
|
8818 | for (var k = 0; k < iterations; ++k) {
|
8819 | tree = quadtree(nodes, x$4, y$3).visitAfter(prepare);
|
8820 | for (i = 0; i < n; ++i) {
|
8821 | node = nodes[i];
|
8822 | ri = radii[node.index], ri2 = ri * ri;
|
8823 | xi = node.x + node.vx;
|
8824 | yi = node.y + node.vy;
|
8825 | tree.visit(apply);
|
8826 | }
|
8827 | }
|
8828 |
|
8829 | function apply(quad, x0, y0, x1, y1) {
|
8830 | var data = quad.data, rj = quad.r, r = ri + rj;
|
8831 | if (data) {
|
8832 | if (data.index > node.index) {
|
8833 | var x = xi - data.x - data.vx,
|
8834 | y = yi - data.y - data.vy,
|
8835 | l = x * x + y * y;
|
8836 | if (l < r * r) {
|
8837 | if (x === 0) x = jiggle(random), l += x * x;
|
8838 | if (y === 0) y = jiggle(random), l += y * y;
|
8839 | l = (r - (l = Math.sqrt(l))) / l * strength;
|
8840 | node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
|
8841 | node.vy += (y *= l) * r;
|
8842 | data.vx -= x * (r = 1 - r);
|
8843 | data.vy -= y * r;
|
8844 | }
|
8845 | }
|
8846 | return;
|
8847 | }
|
8848 | return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
|
8849 | }
|
8850 | }
|
8851 |
|
8852 | function prepare(quad) {
|
8853 | if (quad.data) return quad.r = radii[quad.data.index];
|
8854 | for (var i = quad.r = 0; i < 4; ++i) {
|
8855 | if (quad[i] && quad[i].r > quad.r) {
|
8856 | quad.r = quad[i].r;
|
8857 | }
|
8858 | }
|
8859 | }
|
8860 |
|
8861 | function initialize() {
|
8862 | if (!nodes) return;
|
8863 | var i, n = nodes.length, node;
|
8864 | radii = new Array(n);
|
8865 | for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
|
8866 | }
|
8867 |
|
8868 | force.initialize = function(_nodes, _random) {
|
8869 | nodes = _nodes;
|
8870 | random = _random;
|
8871 | initialize();
|
8872 | };
|
8873 |
|
8874 | force.iterations = function(_) {
|
8875 | return arguments.length ? (iterations = +_, force) : iterations;
|
8876 | };
|
8877 |
|
8878 | force.strength = function(_) {
|
8879 | return arguments.length ? (strength = +_, force) : strength;
|
8880 | };
|
8881 |
|
8882 | force.radius = function(_) {
|
8883 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
|
8884 | };
|
8885 |
|
8886 | return force;
|
8887 | }
|
8888 |
|
8889 | function index$3(d) {
|
8890 | return d.index;
|
8891 | }
|
8892 |
|
8893 | function find(nodeById, nodeId) {
|
8894 | var node = nodeById.get(nodeId);
|
8895 | if (!node) throw new Error("node not found: " + nodeId);
|
8896 | return node;
|
8897 | }
|
8898 |
|
8899 | function link$2(links) {
|
8900 | var id = index$3,
|
8901 | strength = defaultStrength,
|
8902 | strengths,
|
8903 | distance = constant$4(30),
|
8904 | distances,
|
8905 | nodes,
|
8906 | count,
|
8907 | bias,
|
8908 | random,
|
8909 | iterations = 1;
|
8910 |
|
8911 | if (links == null) links = [];
|
8912 |
|
8913 | function defaultStrength(link) {
|
8914 | return 1 / Math.min(count[link.source.index], count[link.target.index]);
|
8915 | }
|
8916 |
|
8917 | function force(alpha) {
|
8918 | for (var k = 0, n = links.length; k < iterations; ++k) {
|
8919 | for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
|
8920 | link = links[i], source = link.source, target = link.target;
|
8921 | x = target.x + target.vx - source.x - source.vx || jiggle(random);
|
8922 | y = target.y + target.vy - source.y - source.vy || jiggle(random);
|
8923 | l = Math.sqrt(x * x + y * y);
|
8924 | l = (l - distances[i]) / l * alpha * strengths[i];
|
8925 | x *= l, y *= l;
|
8926 | target.vx -= x * (b = bias[i]);
|
8927 | target.vy -= y * b;
|
8928 | source.vx += x * (b = 1 - b);
|
8929 | source.vy += y * b;
|
8930 | }
|
8931 | }
|
8932 | }
|
8933 |
|
8934 | function initialize() {
|
8935 | if (!nodes) return;
|
8936 |
|
8937 | var i,
|
8938 | n = nodes.length,
|
8939 | m = links.length,
|
8940 | nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
|
8941 | link;
|
8942 |
|
8943 | for (i = 0, count = new Array(n); i < m; ++i) {
|
8944 | link = links[i], link.index = i;
|
8945 | if (typeof link.source !== "object") link.source = find(nodeById, link.source);
|
8946 | if (typeof link.target !== "object") link.target = find(nodeById, link.target);
|
8947 | count[link.source.index] = (count[link.source.index] || 0) + 1;
|
8948 | count[link.target.index] = (count[link.target.index] || 0) + 1;
|
8949 | }
|
8950 |
|
8951 | for (i = 0, bias = new Array(m); i < m; ++i) {
|
8952 | link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
|
8953 | }
|
8954 |
|
8955 | strengths = new Array(m), initializeStrength();
|
8956 | distances = new Array(m), initializeDistance();
|
8957 | }
|
8958 |
|
8959 | function initializeStrength() {
|
8960 | if (!nodes) return;
|
8961 |
|
8962 | for (var i = 0, n = links.length; i < n; ++i) {
|
8963 | strengths[i] = +strength(links[i], i, links);
|
8964 | }
|
8965 | }
|
8966 |
|
8967 | function initializeDistance() {
|
8968 | if (!nodes) return;
|
8969 |
|
8970 | for (var i = 0, n = links.length; i < n; ++i) {
|
8971 | distances[i] = +distance(links[i], i, links);
|
8972 | }
|
8973 | }
|
8974 |
|
8975 | force.initialize = function(_nodes, _random) {
|
8976 | nodes = _nodes;
|
8977 | random = _random;
|
8978 | initialize();
|
8979 | };
|
8980 |
|
8981 | force.links = function(_) {
|
8982 | return arguments.length ? (links = _, initialize(), force) : links;
|
8983 | };
|
8984 |
|
8985 | force.id = function(_) {
|
8986 | return arguments.length ? (id = _, force) : id;
|
8987 | };
|
8988 |
|
8989 | force.iterations = function(_) {
|
8990 | return arguments.length ? (iterations = +_, force) : iterations;
|
8991 | };
|
8992 |
|
8993 | force.strength = function(_) {
|
8994 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initializeStrength(), force) : strength;
|
8995 | };
|
8996 |
|
8997 | force.distance = function(_) {
|
8998 | return arguments.length ? (distance = typeof _ === "function" ? _ : constant$4(+_), initializeDistance(), force) : distance;
|
8999 | };
|
9000 |
|
9001 | return force;
|
9002 | }
|
9003 |
|
9004 | // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
|
9005 | const a$2 = 1664525;
|
9006 | const c$4 = 1013904223;
|
9007 | const m$1 = 4294967296; // 2^32
|
9008 |
|
9009 | function lcg$2() {
|
9010 | let s = 1;
|
9011 | return () => (s = (a$2 * s + c$4) % m$1) / m$1;
|
9012 | }
|
9013 |
|
9014 | function x$3(d) {
|
9015 | return d.x;
|
9016 | }
|
9017 |
|
9018 | function y$2(d) {
|
9019 | return d.y;
|
9020 | }
|
9021 |
|
9022 | var initialRadius = 10,
|
9023 | initialAngle = Math.PI * (3 - Math.sqrt(5));
|
9024 |
|
9025 | function simulation(nodes) {
|
9026 | var simulation,
|
9027 | alpha = 1,
|
9028 | alphaMin = 0.001,
|
9029 | alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
|
9030 | alphaTarget = 0,
|
9031 | velocityDecay = 0.6,
|
9032 | forces = new Map(),
|
9033 | stepper = timer(step),
|
9034 | event = dispatch("tick", "end"),
|
9035 | random = lcg$2();
|
9036 |
|
9037 | if (nodes == null) nodes = [];
|
9038 |
|
9039 | function step() {
|
9040 | tick();
|
9041 | event.call("tick", simulation);
|
9042 | if (alpha < alphaMin) {
|
9043 | stepper.stop();
|
9044 | event.call("end", simulation);
|
9045 | }
|
9046 | }
|
9047 |
|
9048 | function tick(iterations) {
|
9049 | var i, n = nodes.length, node;
|
9050 |
|
9051 | if (iterations === undefined) iterations = 1;
|
9052 |
|
9053 | for (var k = 0; k < iterations; ++k) {
|
9054 | alpha += (alphaTarget - alpha) * alphaDecay;
|
9055 |
|
9056 | forces.forEach(function(force) {
|
9057 | force(alpha);
|
9058 | });
|
9059 |
|
9060 | for (i = 0; i < n; ++i) {
|
9061 | node = nodes[i];
|
9062 | if (node.fx == null) node.x += node.vx *= velocityDecay;
|
9063 | else node.x = node.fx, node.vx = 0;
|
9064 | if (node.fy == null) node.y += node.vy *= velocityDecay;
|
9065 | else node.y = node.fy, node.vy = 0;
|
9066 | }
|
9067 | }
|
9068 |
|
9069 | return simulation;
|
9070 | }
|
9071 |
|
9072 | function initializeNodes() {
|
9073 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
9074 | node = nodes[i], node.index = i;
|
9075 | if (node.fx != null) node.x = node.fx;
|
9076 | if (node.fy != null) node.y = node.fy;
|
9077 | if (isNaN(node.x) || isNaN(node.y)) {
|
9078 | var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
|
9079 | node.x = radius * Math.cos(angle);
|
9080 | node.y = radius * Math.sin(angle);
|
9081 | }
|
9082 | if (isNaN(node.vx) || isNaN(node.vy)) {
|
9083 | node.vx = node.vy = 0;
|
9084 | }
|
9085 | }
|
9086 | }
|
9087 |
|
9088 | function initializeForce(force) {
|
9089 | if (force.initialize) force.initialize(nodes, random);
|
9090 | return force;
|
9091 | }
|
9092 |
|
9093 | initializeNodes();
|
9094 |
|
9095 | return simulation = {
|
9096 | tick: tick,
|
9097 |
|
9098 | restart: function() {
|
9099 | return stepper.restart(step), simulation;
|
9100 | },
|
9101 |
|
9102 | stop: function() {
|
9103 | return stepper.stop(), simulation;
|
9104 | },
|
9105 |
|
9106 | nodes: function(_) {
|
9107 | return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
|
9108 | },
|
9109 |
|
9110 | alpha: function(_) {
|
9111 | return arguments.length ? (alpha = +_, simulation) : alpha;
|
9112 | },
|
9113 |
|
9114 | alphaMin: function(_) {
|
9115 | return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
|
9116 | },
|
9117 |
|
9118 | alphaDecay: function(_) {
|
9119 | return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
|
9120 | },
|
9121 |
|
9122 | alphaTarget: function(_) {
|
9123 | return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
|
9124 | },
|
9125 |
|
9126 | velocityDecay: function(_) {
|
9127 | return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
|
9128 | },
|
9129 |
|
9130 | randomSource: function(_) {
|
9131 | return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
|
9132 | },
|
9133 |
|
9134 | force: function(name, _) {
|
9135 | return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
|
9136 | },
|
9137 |
|
9138 | find: function(x, y, radius) {
|
9139 | var i = 0,
|
9140 | n = nodes.length,
|
9141 | dx,
|
9142 | dy,
|
9143 | d2,
|
9144 | node,
|
9145 | closest;
|
9146 |
|
9147 | if (radius == null) radius = Infinity;
|
9148 | else radius *= radius;
|
9149 |
|
9150 | for (i = 0; i < n; ++i) {
|
9151 | node = nodes[i];
|
9152 | dx = x - node.x;
|
9153 | dy = y - node.y;
|
9154 | d2 = dx * dx + dy * dy;
|
9155 | if (d2 < radius) closest = node, radius = d2;
|
9156 | }
|
9157 |
|
9158 | return closest;
|
9159 | },
|
9160 |
|
9161 | on: function(name, _) {
|
9162 | return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
|
9163 | }
|
9164 | };
|
9165 | }
|
9166 |
|
9167 | function manyBody() {
|
9168 | var nodes,
|
9169 | node,
|
9170 | random,
|
9171 | alpha,
|
9172 | strength = constant$4(-30),
|
9173 | strengths,
|
9174 | distanceMin2 = 1,
|
9175 | distanceMax2 = Infinity,
|
9176 | theta2 = 0.81;
|
9177 |
|
9178 | function force(_) {
|
9179 | var i, n = nodes.length, tree = quadtree(nodes, x$3, y$2).visitAfter(accumulate);
|
9180 | for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
|
9181 | }
|
9182 |
|
9183 | function initialize() {
|
9184 | if (!nodes) return;
|
9185 | var i, n = nodes.length, node;
|
9186 | strengths = new Array(n);
|
9187 | for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
|
9188 | }
|
9189 |
|
9190 | function accumulate(quad) {
|
9191 | var strength = 0, q, c, weight = 0, x, y, i;
|
9192 |
|
9193 | // For internal nodes, accumulate forces from child quadrants.
|
9194 | if (quad.length) {
|
9195 | for (x = y = i = 0; i < 4; ++i) {
|
9196 | if ((q = quad[i]) && (c = Math.abs(q.value))) {
|
9197 | strength += q.value, weight += c, x += c * q.x, y += c * q.y;
|
9198 | }
|
9199 | }
|
9200 | quad.x = x / weight;
|
9201 | quad.y = y / weight;
|
9202 | }
|
9203 |
|
9204 | // For leaf nodes, accumulate forces from coincident quadrants.
|
9205 | else {
|
9206 | q = quad;
|
9207 | q.x = q.data.x;
|
9208 | q.y = q.data.y;
|
9209 | do strength += strengths[q.data.index];
|
9210 | while (q = q.next);
|
9211 | }
|
9212 |
|
9213 | quad.value = strength;
|
9214 | }
|
9215 |
|
9216 | function apply(quad, x1, _, x2) {
|
9217 | if (!quad.value) return true;
|
9218 |
|
9219 | var x = quad.x - node.x,
|
9220 | y = quad.y - node.y,
|
9221 | w = x2 - x1,
|
9222 | l = x * x + y * y;
|
9223 |
|
9224 | // Apply the Barnes-Hut approximation if possible.
|
9225 | // Limit forces for very close nodes; randomize direction if coincident.
|
9226 | if (w * w / theta2 < l) {
|
9227 | if (l < distanceMax2) {
|
9228 | if (x === 0) x = jiggle(random), l += x * x;
|
9229 | if (y === 0) y = jiggle(random), l += y * y;
|
9230 | if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
9231 | node.vx += x * quad.value * alpha / l;
|
9232 | node.vy += y * quad.value * alpha / l;
|
9233 | }
|
9234 | return true;
|
9235 | }
|
9236 |
|
9237 | // Otherwise, process points directly.
|
9238 | else if (quad.length || l >= distanceMax2) return;
|
9239 |
|
9240 | // Limit forces for very close nodes; randomize direction if coincident.
|
9241 | if (quad.data !== node || quad.next) {
|
9242 | if (x === 0) x = jiggle(random), l += x * x;
|
9243 | if (y === 0) y = jiggle(random), l += y * y;
|
9244 | if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
9245 | }
|
9246 |
|
9247 | do if (quad.data !== node) {
|
9248 | w = strengths[quad.data.index] * alpha / l;
|
9249 | node.vx += x * w;
|
9250 | node.vy += y * w;
|
9251 | } while (quad = quad.next);
|
9252 | }
|
9253 |
|
9254 | force.initialize = function(_nodes, _random) {
|
9255 | nodes = _nodes;
|
9256 | random = _random;
|
9257 | initialize();
|
9258 | };
|
9259 |
|
9260 | force.strength = function(_) {
|
9261 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
|
9262 | };
|
9263 |
|
9264 | force.distanceMin = function(_) {
|
9265 | return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
|
9266 | };
|
9267 |
|
9268 | force.distanceMax = function(_) {
|
9269 | return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
|
9270 | };
|
9271 |
|
9272 | force.theta = function(_) {
|
9273 | return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
|
9274 | };
|
9275 |
|
9276 | return force;
|
9277 | }
|
9278 |
|
9279 | function radial$1(radius, x, y) {
|
9280 | var nodes,
|
9281 | strength = constant$4(0.1),
|
9282 | strengths,
|
9283 | radiuses;
|
9284 |
|
9285 | if (typeof radius !== "function") radius = constant$4(+radius);
|
9286 | if (x == null) x = 0;
|
9287 | if (y == null) y = 0;
|
9288 |
|
9289 | function force(alpha) {
|
9290 | for (var i = 0, n = nodes.length; i < n; ++i) {
|
9291 | var node = nodes[i],
|
9292 | dx = node.x - x || 1e-6,
|
9293 | dy = node.y - y || 1e-6,
|
9294 | r = Math.sqrt(dx * dx + dy * dy),
|
9295 | k = (radiuses[i] - r) * strengths[i] * alpha / r;
|
9296 | node.vx += dx * k;
|
9297 | node.vy += dy * k;
|
9298 | }
|
9299 | }
|
9300 |
|
9301 | function initialize() {
|
9302 | if (!nodes) return;
|
9303 | var i, n = nodes.length;
|
9304 | strengths = new Array(n);
|
9305 | radiuses = new Array(n);
|
9306 | for (i = 0; i < n; ++i) {
|
9307 | radiuses[i] = +radius(nodes[i], i, nodes);
|
9308 | strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
|
9309 | }
|
9310 | }
|
9311 |
|
9312 | force.initialize = function(_) {
|
9313 | nodes = _, initialize();
|
9314 | };
|
9315 |
|
9316 | force.strength = function(_) {
|
9317 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
|
9318 | };
|
9319 |
|
9320 | force.radius = function(_) {
|
9321 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
|
9322 | };
|
9323 |
|
9324 | force.x = function(_) {
|
9325 | return arguments.length ? (x = +_, force) : x;
|
9326 | };
|
9327 |
|
9328 | force.y = function(_) {
|
9329 | return arguments.length ? (y = +_, force) : y;
|
9330 | };
|
9331 |
|
9332 | return force;
|
9333 | }
|
9334 |
|
9335 | function x$2(x) {
|
9336 | var strength = constant$4(0.1),
|
9337 | nodes,
|
9338 | strengths,
|
9339 | xz;
|
9340 |
|
9341 | if (typeof x !== "function") x = constant$4(x == null ? 0 : +x);
|
9342 |
|
9343 | function force(alpha) {
|
9344 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
9345 | node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
|
9346 | }
|
9347 | }
|
9348 |
|
9349 | function initialize() {
|
9350 | if (!nodes) return;
|
9351 | var i, n = nodes.length;
|
9352 | strengths = new Array(n);
|
9353 | xz = new Array(n);
|
9354 | for (i = 0; i < n; ++i) {
|
9355 | strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
9356 | }
|
9357 | }
|
9358 |
|
9359 | force.initialize = function(_) {
|
9360 | nodes = _;
|
9361 | initialize();
|
9362 | };
|
9363 |
|
9364 | force.strength = function(_) {
|
9365 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
|
9366 | };
|
9367 |
|
9368 | force.x = function(_) {
|
9369 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : x;
|
9370 | };
|
9371 |
|
9372 | return force;
|
9373 | }
|
9374 |
|
9375 | function y$1(y) {
|
9376 | var strength = constant$4(0.1),
|
9377 | nodes,
|
9378 | strengths,
|
9379 | yz;
|
9380 |
|
9381 | if (typeof y !== "function") y = constant$4(y == null ? 0 : +y);
|
9382 |
|
9383 | function force(alpha) {
|
9384 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
9385 | node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
|
9386 | }
|
9387 | }
|
9388 |
|
9389 | function initialize() {
|
9390 | if (!nodes) return;
|
9391 | var i, n = nodes.length;
|
9392 | strengths = new Array(n);
|
9393 | yz = new Array(n);
|
9394 | for (i = 0; i < n; ++i) {
|
9395 | strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
9396 | }
|
9397 | }
|
9398 |
|
9399 | force.initialize = function(_) {
|
9400 | nodes = _;
|
9401 | initialize();
|
9402 | };
|
9403 |
|
9404 | force.strength = function(_) {
|
9405 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
|
9406 | };
|
9407 |
|
9408 | force.y = function(_) {
|
9409 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : y;
|
9410 | };
|
9411 |
|
9412 | return force;
|
9413 | }
|
9414 |
|
9415 | function formatDecimal(x) {
|
9416 | return Math.abs(x = Math.round(x)) >= 1e21
|
9417 | ? x.toLocaleString("en").replace(/,/g, "")
|
9418 | : x.toString(10);
|
9419 | }
|
9420 |
|
9421 | // Computes the decimal coefficient and exponent of the specified number x with
|
9422 | // significant digits p, where x is positive and p is in [1, 21] or undefined.
|
9423 | // For example, formatDecimalParts(1.23) returns ["123", 0].
|
9424 | function formatDecimalParts(x, p) {
|
9425 | if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
|
9426 | var i, coefficient = x.slice(0, i);
|
9427 |
|
9428 | // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
|
9429 | // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
|
9430 | return [
|
9431 | coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
|
9432 | +x.slice(i + 1)
|
9433 | ];
|
9434 | }
|
9435 |
|
9436 | function exponent(x) {
|
9437 | return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
|
9438 | }
|
9439 |
|
9440 | function formatGroup(grouping, thousands) {
|
9441 | return function(value, width) {
|
9442 | var i = value.length,
|
9443 | t = [],
|
9444 | j = 0,
|
9445 | g = grouping[0],
|
9446 | length = 0;
|
9447 |
|
9448 | while (i > 0 && g > 0) {
|
9449 | if (length + g + 1 > width) g = Math.max(1, width - length);
|
9450 | t.push(value.substring(i -= g, i + g));
|
9451 | if ((length += g + 1) > width) break;
|
9452 | g = grouping[j = (j + 1) % grouping.length];
|
9453 | }
|
9454 |
|
9455 | return t.reverse().join(thousands);
|
9456 | };
|
9457 | }
|
9458 |
|
9459 | function formatNumerals(numerals) {
|
9460 | return function(value) {
|
9461 | return value.replace(/[0-9]/g, function(i) {
|
9462 | return numerals[+i];
|
9463 | });
|
9464 | };
|
9465 | }
|
9466 |
|
9467 | // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
|
9468 | var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
|
9469 |
|
9470 | function formatSpecifier(specifier) {
|
9471 | if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
|
9472 | var match;
|
9473 | return new FormatSpecifier({
|
9474 | fill: match[1],
|
9475 | align: match[2],
|
9476 | sign: match[3],
|
9477 | symbol: match[4],
|
9478 | zero: match[5],
|
9479 | width: match[6],
|
9480 | comma: match[7],
|
9481 | precision: match[8] && match[8].slice(1),
|
9482 | trim: match[9],
|
9483 | type: match[10]
|
9484 | });
|
9485 | }
|
9486 |
|
9487 | formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
|
9488 |
|
9489 | function FormatSpecifier(specifier) {
|
9490 | this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
|
9491 | this.align = specifier.align === undefined ? ">" : specifier.align + "";
|
9492 | this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
|
9493 | this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
|
9494 | this.zero = !!specifier.zero;
|
9495 | this.width = specifier.width === undefined ? undefined : +specifier.width;
|
9496 | this.comma = !!specifier.comma;
|
9497 | this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
|
9498 | this.trim = !!specifier.trim;
|
9499 | this.type = specifier.type === undefined ? "" : specifier.type + "";
|
9500 | }
|
9501 |
|
9502 | FormatSpecifier.prototype.toString = function() {
|
9503 | return this.fill
|
9504 | + this.align
|
9505 | + this.sign
|
9506 | + this.symbol
|
9507 | + (this.zero ? "0" : "")
|
9508 | + (this.width === undefined ? "" : Math.max(1, this.width | 0))
|
9509 | + (this.comma ? "," : "")
|
9510 | + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
|
9511 | + (this.trim ? "~" : "")
|
9512 | + this.type;
|
9513 | };
|
9514 |
|
9515 | // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
|
9516 | function formatTrim(s) {
|
9517 | out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
|
9518 | switch (s[i]) {
|
9519 | case ".": i0 = i1 = i; break;
|
9520 | case "0": if (i0 === 0) i0 = i; i1 = i; break;
|
9521 | default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
|
9522 | }
|
9523 | }
|
9524 | return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
|
9525 | }
|
9526 |
|
9527 | var prefixExponent;
|
9528 |
|
9529 | function formatPrefixAuto(x, p) {
|
9530 | var d = formatDecimalParts(x, p);
|
9531 | if (!d) return x + "";
|
9532 | var coefficient = d[0],
|
9533 | exponent = d[1],
|
9534 | i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
|
9535 | n = coefficient.length;
|
9536 | return i === n ? coefficient
|
9537 | : i > n ? coefficient + new Array(i - n + 1).join("0")
|
9538 | : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
|
9539 | : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
|
9540 | }
|
9541 |
|
9542 | function formatRounded(x, p) {
|
9543 | var d = formatDecimalParts(x, p);
|
9544 | if (!d) return x + "";
|
9545 | var coefficient = d[0],
|
9546 | exponent = d[1];
|
9547 | return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
|
9548 | : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
|
9549 | : coefficient + new Array(exponent - coefficient.length + 2).join("0");
|
9550 | }
|
9551 |
|
9552 | var formatTypes = {
|
9553 | "%": (x, p) => (x * 100).toFixed(p),
|
9554 | "b": (x) => Math.round(x).toString(2),
|
9555 | "c": (x) => x + "",
|
9556 | "d": formatDecimal,
|
9557 | "e": (x, p) => x.toExponential(p),
|
9558 | "f": (x, p) => x.toFixed(p),
|
9559 | "g": (x, p) => x.toPrecision(p),
|
9560 | "o": (x) => Math.round(x).toString(8),
|
9561 | "p": (x, p) => formatRounded(x * 100, p),
|
9562 | "r": formatRounded,
|
9563 | "s": formatPrefixAuto,
|
9564 | "X": (x) => Math.round(x).toString(16).toUpperCase(),
|
9565 | "x": (x) => Math.round(x).toString(16)
|
9566 | };
|
9567 |
|
9568 | function identity$6(x) {
|
9569 | return x;
|
9570 | }
|
9571 |
|
9572 | var map = Array.prototype.map,
|
9573 | prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
|
9574 |
|
9575 | function formatLocale$1(locale) {
|
9576 | var group = locale.grouping === undefined || locale.thousands === undefined ? identity$6 : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""),
|
9577 | currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
|
9578 | currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
|
9579 | decimal = locale.decimal === undefined ? "." : locale.decimal + "",
|
9580 | numerals = locale.numerals === undefined ? identity$6 : formatNumerals(map.call(locale.numerals, String)),
|
9581 | percent = locale.percent === undefined ? "%" : locale.percent + "",
|
9582 | minus = locale.minus === undefined ? "\u2212" : locale.minus + "",
|
9583 | nan = locale.nan === undefined ? "NaN" : locale.nan + "";
|
9584 |
|
9585 | function newFormat(specifier) {
|
9586 | specifier = formatSpecifier(specifier);
|
9587 |
|
9588 | var fill = specifier.fill,
|
9589 | align = specifier.align,
|
9590 | sign = specifier.sign,
|
9591 | symbol = specifier.symbol,
|
9592 | zero = specifier.zero,
|
9593 | width = specifier.width,
|
9594 | comma = specifier.comma,
|
9595 | precision = specifier.precision,
|
9596 | trim = specifier.trim,
|
9597 | type = specifier.type;
|
9598 |
|
9599 | // The "n" type is an alias for ",g".
|
9600 | if (type === "n") comma = true, type = "g";
|
9601 |
|
9602 | // The "" type, and any invalid type, is an alias for ".12~g".
|
9603 | else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
|
9604 |
|
9605 | // If zero fill is specified, padding goes after sign and before digits.
|
9606 | if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
|
9607 |
|
9608 | // Compute the prefix and suffix.
|
9609 | // For SI-prefix, the suffix is lazily computed.
|
9610 | var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
|
9611 | suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
|
9612 |
|
9613 | // What format function should we use?
|
9614 | // Is this an integer type?
|
9615 | // Can this type generate exponential notation?
|
9616 | var formatType = formatTypes[type],
|
9617 | maybeSuffix = /[defgprs%]/.test(type);
|
9618 |
|
9619 | // Set the default precision if not specified,
|
9620 | // or clamp the specified precision to the supported range.
|
9621 | // For significant precision, it must be in [1, 21].
|
9622 | // For fixed precision, it must be in [0, 20].
|
9623 | precision = precision === undefined ? 6
|
9624 | : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
|
9625 | : Math.max(0, Math.min(20, precision));
|
9626 |
|
9627 | function format(value) {
|
9628 | var valuePrefix = prefix,
|
9629 | valueSuffix = suffix,
|
9630 | i, n, c;
|
9631 |
|
9632 | if (type === "c") {
|
9633 | valueSuffix = formatType(value) + valueSuffix;
|
9634 | value = "";
|
9635 | } else {
|
9636 | value = +value;
|
9637 |
|
9638 | // Determine the sign. -0 is not less than 0, but 1 / -0 is!
|
9639 | var valueNegative = value < 0 || 1 / value < 0;
|
9640 |
|
9641 | // Perform the initial formatting.
|
9642 | value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
|
9643 |
|
9644 | // Trim insignificant zeros.
|
9645 | if (trim) value = formatTrim(value);
|
9646 |
|
9647 | // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
|
9648 | if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
|
9649 |
|
9650 | // Compute the prefix and suffix.
|
9651 | valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
|
9652 | valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
|
9653 |
|
9654 | // Break the formatted value into the integer “value” part that can be
|
9655 | // grouped, and fractional or exponential “suffix” part that is not.
|
9656 | if (maybeSuffix) {
|
9657 | i = -1, n = value.length;
|
9658 | while (++i < n) {
|
9659 | if (c = value.charCodeAt(i), 48 > c || c > 57) {
|
9660 | valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
|
9661 | value = value.slice(0, i);
|
9662 | break;
|
9663 | }
|
9664 | }
|
9665 | }
|
9666 | }
|
9667 |
|
9668 | // If the fill character is not "0", grouping is applied before padding.
|
9669 | if (comma && !zero) value = group(value, Infinity);
|
9670 |
|
9671 | // Compute the padding.
|
9672 | var length = valuePrefix.length + value.length + valueSuffix.length,
|
9673 | padding = length < width ? new Array(width - length + 1).join(fill) : "";
|
9674 |
|
9675 | // If the fill character is "0", grouping is applied after padding.
|
9676 | if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
|
9677 |
|
9678 | // Reconstruct the final output based on the desired alignment.
|
9679 | switch (align) {
|
9680 | case "<": value = valuePrefix + value + valueSuffix + padding; break;
|
9681 | case "=": value = valuePrefix + padding + value + valueSuffix; break;
|
9682 | case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
|
9683 | default: value = padding + valuePrefix + value + valueSuffix; break;
|
9684 | }
|
9685 |
|
9686 | return numerals(value);
|
9687 | }
|
9688 |
|
9689 | format.toString = function() {
|
9690 | return specifier + "";
|
9691 | };
|
9692 |
|
9693 | return format;
|
9694 | }
|
9695 |
|
9696 | function formatPrefix(specifier, value) {
|
9697 | var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
|
9698 | e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
|
9699 | k = Math.pow(10, -e),
|
9700 | prefix = prefixes[8 + e / 3];
|
9701 | return function(value) {
|
9702 | return f(k * value) + prefix;
|
9703 | };
|
9704 | }
|
9705 |
|
9706 | return {
|
9707 | format: newFormat,
|
9708 | formatPrefix: formatPrefix
|
9709 | };
|
9710 | }
|
9711 |
|
9712 | var locale$1;
|
9713 | exports.format = void 0;
|
9714 | exports.formatPrefix = void 0;
|
9715 |
|
9716 | defaultLocale$1({
|
9717 | thousands: ",",
|
9718 | grouping: [3],
|
9719 | currency: ["$", ""]
|
9720 | });
|
9721 |
|
9722 | function defaultLocale$1(definition) {
|
9723 | locale$1 = formatLocale$1(definition);
|
9724 | exports.format = locale$1.format;
|
9725 | exports.formatPrefix = locale$1.formatPrefix;
|
9726 | return locale$1;
|
9727 | }
|
9728 |
|
9729 | function precisionFixed(step) {
|
9730 | return Math.max(0, -exponent(Math.abs(step)));
|
9731 | }
|
9732 |
|
9733 | function precisionPrefix(step, value) {
|
9734 | return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
|
9735 | }
|
9736 |
|
9737 | function precisionRound(step, max) {
|
9738 | step = Math.abs(step), max = Math.abs(max) - step;
|
9739 | return Math.max(0, exponent(max) - exponent(step)) + 1;
|
9740 | }
|
9741 |
|
9742 | var epsilon$1 = 1e-6;
|
9743 | var epsilon2 = 1e-12;
|
9744 | var pi$1 = Math.PI;
|
9745 | var halfPi$1 = pi$1 / 2;
|
9746 | var quarterPi = pi$1 / 4;
|
9747 | var tau$1 = pi$1 * 2;
|
9748 |
|
9749 | var degrees = 180 / pi$1;
|
9750 | var radians = pi$1 / 180;
|
9751 |
|
9752 | var abs$1 = Math.abs;
|
9753 | var atan = Math.atan;
|
9754 | var atan2$1 = Math.atan2;
|
9755 | var cos$1 = Math.cos;
|
9756 | var ceil = Math.ceil;
|
9757 | var exp = Math.exp;
|
9758 | var hypot = Math.hypot;
|
9759 | var log$1 = Math.log;
|
9760 | var pow$1 = Math.pow;
|
9761 | var sin$1 = Math.sin;
|
9762 | var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
|
9763 | var sqrt$2 = Math.sqrt;
|
9764 | var tan = Math.tan;
|
9765 |
|
9766 | function acos$1(x) {
|
9767 | return x > 1 ? 0 : x < -1 ? pi$1 : Math.acos(x);
|
9768 | }
|
9769 |
|
9770 | function asin$1(x) {
|
9771 | return x > 1 ? halfPi$1 : x < -1 ? -halfPi$1 : Math.asin(x);
|
9772 | }
|
9773 |
|
9774 | function haversin(x) {
|
9775 | return (x = sin$1(x / 2)) * x;
|
9776 | }
|
9777 |
|
9778 | function noop$1() {}
|
9779 |
|
9780 | function streamGeometry(geometry, stream) {
|
9781 | if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
|
9782 | streamGeometryType[geometry.type](geometry, stream);
|
9783 | }
|
9784 | }
|
9785 |
|
9786 | var streamObjectType = {
|
9787 | Feature: function(object, stream) {
|
9788 | streamGeometry(object.geometry, stream);
|
9789 | },
|
9790 | FeatureCollection: function(object, stream) {
|
9791 | var features = object.features, i = -1, n = features.length;
|
9792 | while (++i < n) streamGeometry(features[i].geometry, stream);
|
9793 | }
|
9794 | };
|
9795 |
|
9796 | var streamGeometryType = {
|
9797 | Sphere: function(object, stream) {
|
9798 | stream.sphere();
|
9799 | },
|
9800 | Point: function(object, stream) {
|
9801 | object = object.coordinates;
|
9802 | stream.point(object[0], object[1], object[2]);
|
9803 | },
|
9804 | MultiPoint: function(object, stream) {
|
9805 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
9806 | while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
|
9807 | },
|
9808 | LineString: function(object, stream) {
|
9809 | streamLine(object.coordinates, stream, 0);
|
9810 | },
|
9811 | MultiLineString: function(object, stream) {
|
9812 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
9813 | while (++i < n) streamLine(coordinates[i], stream, 0);
|
9814 | },
|
9815 | Polygon: function(object, stream) {
|
9816 | streamPolygon(object.coordinates, stream);
|
9817 | },
|
9818 | MultiPolygon: function(object, stream) {
|
9819 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
9820 | while (++i < n) streamPolygon(coordinates[i], stream);
|
9821 | },
|
9822 | GeometryCollection: function(object, stream) {
|
9823 | var geometries = object.geometries, i = -1, n = geometries.length;
|
9824 | while (++i < n) streamGeometry(geometries[i], stream);
|
9825 | }
|
9826 | };
|
9827 |
|
9828 | function streamLine(coordinates, stream, closed) {
|
9829 | var i = -1, n = coordinates.length - closed, coordinate;
|
9830 | stream.lineStart();
|
9831 | while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
|
9832 | stream.lineEnd();
|
9833 | }
|
9834 |
|
9835 | function streamPolygon(coordinates, stream) {
|
9836 | var i = -1, n = coordinates.length;
|
9837 | stream.polygonStart();
|
9838 | while (++i < n) streamLine(coordinates[i], stream, 1);
|
9839 | stream.polygonEnd();
|
9840 | }
|
9841 |
|
9842 | function geoStream(object, stream) {
|
9843 | if (object && streamObjectType.hasOwnProperty(object.type)) {
|
9844 | streamObjectType[object.type](object, stream);
|
9845 | } else {
|
9846 | streamGeometry(object, stream);
|
9847 | }
|
9848 | }
|
9849 |
|
9850 | var areaRingSum$1 = new Adder();
|
9851 |
|
9852 | // hello?
|
9853 |
|
9854 | var areaSum$1 = new Adder(),
|
9855 | lambda00$2,
|
9856 | phi00$2,
|
9857 | lambda0$2,
|
9858 | cosPhi0$1,
|
9859 | sinPhi0$1;
|
9860 |
|
9861 | var areaStream$1 = {
|
9862 | point: noop$1,
|
9863 | lineStart: noop$1,
|
9864 | lineEnd: noop$1,
|
9865 | polygonStart: function() {
|
9866 | areaRingSum$1 = new Adder();
|
9867 | areaStream$1.lineStart = areaRingStart$1;
|
9868 | areaStream$1.lineEnd = areaRingEnd$1;
|
9869 | },
|
9870 | polygonEnd: function() {
|
9871 | var areaRing = +areaRingSum$1;
|
9872 | areaSum$1.add(areaRing < 0 ? tau$1 + areaRing : areaRing);
|
9873 | this.lineStart = this.lineEnd = this.point = noop$1;
|
9874 | },
|
9875 | sphere: function() {
|
9876 | areaSum$1.add(tau$1);
|
9877 | }
|
9878 | };
|
9879 |
|
9880 | function areaRingStart$1() {
|
9881 | areaStream$1.point = areaPointFirst$1;
|
9882 | }
|
9883 |
|
9884 | function areaRingEnd$1() {
|
9885 | areaPoint$1(lambda00$2, phi00$2);
|
9886 | }
|
9887 |
|
9888 | function areaPointFirst$1(lambda, phi) {
|
9889 | areaStream$1.point = areaPoint$1;
|
9890 | lambda00$2 = lambda, phi00$2 = phi;
|
9891 | lambda *= radians, phi *= radians;
|
9892 | lambda0$2 = lambda, cosPhi0$1 = cos$1(phi = phi / 2 + quarterPi), sinPhi0$1 = sin$1(phi);
|
9893 | }
|
9894 |
|
9895 | function areaPoint$1(lambda, phi) {
|
9896 | lambda *= radians, phi *= radians;
|
9897 | phi = phi / 2 + quarterPi; // half the angular distance from south pole
|
9898 |
|
9899 | // Spherical excess E for a spherical triangle with vertices: south pole,
|
9900 | // previous point, current point. Uses a formula derived from Cagnoli’s
|
9901 | // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
|
9902 | var dLambda = lambda - lambda0$2,
|
9903 | sdLambda = dLambda >= 0 ? 1 : -1,
|
9904 | adLambda = sdLambda * dLambda,
|
9905 | cosPhi = cos$1(phi),
|
9906 | sinPhi = sin$1(phi),
|
9907 | k = sinPhi0$1 * sinPhi,
|
9908 | u = cosPhi0$1 * cosPhi + k * cos$1(adLambda),
|
9909 | v = k * sdLambda * sin$1(adLambda);
|
9910 | areaRingSum$1.add(atan2$1(v, u));
|
9911 |
|
9912 | // Advance the previous points.
|
9913 | lambda0$2 = lambda, cosPhi0$1 = cosPhi, sinPhi0$1 = sinPhi;
|
9914 | }
|
9915 |
|
9916 | function area$2(object) {
|
9917 | areaSum$1 = new Adder();
|
9918 | geoStream(object, areaStream$1);
|
9919 | return areaSum$1 * 2;
|
9920 | }
|
9921 |
|
9922 | function spherical(cartesian) {
|
9923 | return [atan2$1(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
|
9924 | }
|
9925 |
|
9926 | function cartesian(spherical) {
|
9927 | var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
|
9928 | return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
|
9929 | }
|
9930 |
|
9931 | function cartesianDot(a, b) {
|
9932 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
9933 | }
|
9934 |
|
9935 | function cartesianCross(a, b) {
|
9936 | 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]];
|
9937 | }
|
9938 |
|
9939 | // TODO return a
|
9940 | function cartesianAddInPlace(a, b) {
|
9941 | a[0] += b[0], a[1] += b[1], a[2] += b[2];
|
9942 | }
|
9943 |
|
9944 | function cartesianScale(vector, k) {
|
9945 | return [vector[0] * k, vector[1] * k, vector[2] * k];
|
9946 | }
|
9947 |
|
9948 | // TODO return d
|
9949 | function cartesianNormalizeInPlace(d) {
|
9950 | var l = sqrt$2(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
|
9951 | d[0] /= l, d[1] /= l, d[2] /= l;
|
9952 | }
|
9953 |
|
9954 | var lambda0$1, phi0, lambda1, phi1, // bounds
|
9955 | lambda2, // previous lambda-coordinate
|
9956 | lambda00$1, phi00$1, // first point
|
9957 | p0, // previous 3D point
|
9958 | deltaSum,
|
9959 | ranges,
|
9960 | range;
|
9961 |
|
9962 | var boundsStream$2 = {
|
9963 | point: boundsPoint$1,
|
9964 | lineStart: boundsLineStart,
|
9965 | lineEnd: boundsLineEnd,
|
9966 | polygonStart: function() {
|
9967 | boundsStream$2.point = boundsRingPoint;
|
9968 | boundsStream$2.lineStart = boundsRingStart;
|
9969 | boundsStream$2.lineEnd = boundsRingEnd;
|
9970 | deltaSum = new Adder();
|
9971 | areaStream$1.polygonStart();
|
9972 | },
|
9973 | polygonEnd: function() {
|
9974 | areaStream$1.polygonEnd();
|
9975 | boundsStream$2.point = boundsPoint$1;
|
9976 | boundsStream$2.lineStart = boundsLineStart;
|
9977 | boundsStream$2.lineEnd = boundsLineEnd;
|
9978 | if (areaRingSum$1 < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
|
9979 | else if (deltaSum > epsilon$1) phi1 = 90;
|
9980 | else if (deltaSum < -epsilon$1) phi0 = -90;
|
9981 | range[0] = lambda0$1, range[1] = lambda1;
|
9982 | },
|
9983 | sphere: function() {
|
9984 | lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
|
9985 | }
|
9986 | };
|
9987 |
|
9988 | function boundsPoint$1(lambda, phi) {
|
9989 | ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
|
9990 | if (phi < phi0) phi0 = phi;
|
9991 | if (phi > phi1) phi1 = phi;
|
9992 | }
|
9993 |
|
9994 | function linePoint(lambda, phi) {
|
9995 | var p = cartesian([lambda * radians, phi * radians]);
|
9996 | if (p0) {
|
9997 | var normal = cartesianCross(p0, p),
|
9998 | equatorial = [normal[1], -normal[0], 0],
|
9999 | inflection = cartesianCross(equatorial, normal);
|
10000 | cartesianNormalizeInPlace(inflection);
|
10001 | inflection = spherical(inflection);
|
10002 | var delta = lambda - lambda2,
|
10003 | sign = delta > 0 ? 1 : -1,
|
10004 | lambdai = inflection[0] * degrees * sign,
|
10005 | phii,
|
10006 | antimeridian = abs$1(delta) > 180;
|
10007 | if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
|
10008 | phii = inflection[1] * degrees;
|
10009 | if (phii > phi1) phi1 = phii;
|
10010 | } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
|
10011 | phii = -inflection[1] * degrees;
|
10012 | if (phii < phi0) phi0 = phii;
|
10013 | } else {
|
10014 | if (phi < phi0) phi0 = phi;
|
10015 | if (phi > phi1) phi1 = phi;
|
10016 | }
|
10017 | if (antimeridian) {
|
10018 | if (lambda < lambda2) {
|
10019 | if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
|
10020 | } else {
|
10021 | if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
|
10022 | }
|
10023 | } else {
|
10024 | if (lambda1 >= lambda0$1) {
|
10025 | if (lambda < lambda0$1) lambda0$1 = lambda;
|
10026 | if (lambda > lambda1) lambda1 = lambda;
|
10027 | } else {
|
10028 | if (lambda > lambda2) {
|
10029 | if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
|
10030 | } else {
|
10031 | if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
|
10032 | }
|
10033 | }
|
10034 | }
|
10035 | } else {
|
10036 | ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
|
10037 | }
|
10038 | if (phi < phi0) phi0 = phi;
|
10039 | if (phi > phi1) phi1 = phi;
|
10040 | p0 = p, lambda2 = lambda;
|
10041 | }
|
10042 |
|
10043 | function boundsLineStart() {
|
10044 | boundsStream$2.point = linePoint;
|
10045 | }
|
10046 |
|
10047 | function boundsLineEnd() {
|
10048 | range[0] = lambda0$1, range[1] = lambda1;
|
10049 | boundsStream$2.point = boundsPoint$1;
|
10050 | p0 = null;
|
10051 | }
|
10052 |
|
10053 | function boundsRingPoint(lambda, phi) {
|
10054 | if (p0) {
|
10055 | var delta = lambda - lambda2;
|
10056 | deltaSum.add(abs$1(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
|
10057 | } else {
|
10058 | lambda00$1 = lambda, phi00$1 = phi;
|
10059 | }
|
10060 | areaStream$1.point(lambda, phi);
|
10061 | linePoint(lambda, phi);
|
10062 | }
|
10063 |
|
10064 | function boundsRingStart() {
|
10065 | areaStream$1.lineStart();
|
10066 | }
|
10067 |
|
10068 | function boundsRingEnd() {
|
10069 | boundsRingPoint(lambda00$1, phi00$1);
|
10070 | areaStream$1.lineEnd();
|
10071 | if (abs$1(deltaSum) > epsilon$1) lambda0$1 = -(lambda1 = 180);
|
10072 | range[0] = lambda0$1, range[1] = lambda1;
|
10073 | p0 = null;
|
10074 | }
|
10075 |
|
10076 | // Finds the left-right distance between two longitudes.
|
10077 | // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
|
10078 | // the distance between ±180° to be 360°.
|
10079 | function angle(lambda0, lambda1) {
|
10080 | return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
|
10081 | }
|
10082 |
|
10083 | function rangeCompare(a, b) {
|
10084 | return a[0] - b[0];
|
10085 | }
|
10086 |
|
10087 | function rangeContains(range, x) {
|
10088 | return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
|
10089 | }
|
10090 |
|
10091 | function bounds(feature) {
|
10092 | var i, n, a, b, merged, deltaMax, delta;
|
10093 |
|
10094 | phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
|
10095 | ranges = [];
|
10096 | geoStream(feature, boundsStream$2);
|
10097 |
|
10098 | // First, sort ranges by their minimum longitudes.
|
10099 | if (n = ranges.length) {
|
10100 | ranges.sort(rangeCompare);
|
10101 |
|
10102 | // Then, merge any ranges that overlap.
|
10103 | for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
|
10104 | b = ranges[i];
|
10105 | if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
|
10106 | if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
|
10107 | if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
|
10108 | } else {
|
10109 | merged.push(a = b);
|
10110 | }
|
10111 | }
|
10112 |
|
10113 | // Finally, find the largest gap between the merged ranges.
|
10114 | // The final bounding box will be the inverse of this gap.
|
10115 | for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
|
10116 | b = merged[i];
|
10117 | if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
|
10118 | }
|
10119 | }
|
10120 |
|
10121 | ranges = range = null;
|
10122 |
|
10123 | return lambda0$1 === Infinity || phi0 === Infinity
|
10124 | ? [[NaN, NaN], [NaN, NaN]]
|
10125 | : [[lambda0$1, phi0], [lambda1, phi1]];
|
10126 | }
|
10127 |
|
10128 | var W0, W1,
|
10129 | X0$1, Y0$1, Z0$1,
|
10130 | X1$1, Y1$1, Z1$1,
|
10131 | X2$1, Y2$1, Z2$1,
|
10132 | lambda00, phi00, // first point
|
10133 | x0$4, y0$4, z0; // previous point
|
10134 |
|
10135 | var centroidStream$1 = {
|
10136 | sphere: noop$1,
|
10137 | point: centroidPoint$1,
|
10138 | lineStart: centroidLineStart$1,
|
10139 | lineEnd: centroidLineEnd$1,
|
10140 | polygonStart: function() {
|
10141 | centroidStream$1.lineStart = centroidRingStart$1;
|
10142 | centroidStream$1.lineEnd = centroidRingEnd$1;
|
10143 | },
|
10144 | polygonEnd: function() {
|
10145 | centroidStream$1.lineStart = centroidLineStart$1;
|
10146 | centroidStream$1.lineEnd = centroidLineEnd$1;
|
10147 | }
|
10148 | };
|
10149 |
|
10150 | // Arithmetic mean of Cartesian vectors.
|
10151 | function centroidPoint$1(lambda, phi) {
|
10152 | lambda *= radians, phi *= radians;
|
10153 | var cosPhi = cos$1(phi);
|
10154 | centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
|
10155 | }
|
10156 |
|
10157 | function centroidPointCartesian(x, y, z) {
|
10158 | ++W0;
|
10159 | X0$1 += (x - X0$1) / W0;
|
10160 | Y0$1 += (y - Y0$1) / W0;
|
10161 | Z0$1 += (z - Z0$1) / W0;
|
10162 | }
|
10163 |
|
10164 | function centroidLineStart$1() {
|
10165 | centroidStream$1.point = centroidLinePointFirst;
|
10166 | }
|
10167 |
|
10168 | function centroidLinePointFirst(lambda, phi) {
|
10169 | lambda *= radians, phi *= radians;
|
10170 | var cosPhi = cos$1(phi);
|
10171 | x0$4 = cosPhi * cos$1(lambda);
|
10172 | y0$4 = cosPhi * sin$1(lambda);
|
10173 | z0 = sin$1(phi);
|
10174 | centroidStream$1.point = centroidLinePoint;
|
10175 | centroidPointCartesian(x0$4, y0$4, z0);
|
10176 | }
|
10177 |
|
10178 | function centroidLinePoint(lambda, phi) {
|
10179 | lambda *= radians, phi *= radians;
|
10180 | var cosPhi = cos$1(phi),
|
10181 | x = cosPhi * cos$1(lambda),
|
10182 | y = cosPhi * sin$1(lambda),
|
10183 | z = sin$1(phi),
|
10184 | w = atan2$1(sqrt$2((w = y0$4 * z - z0 * y) * w + (w = z0 * x - x0$4 * z) * w + (w = x0$4 * y - y0$4 * x) * w), x0$4 * x + y0$4 * y + z0 * z);
|
10185 | W1 += w;
|
10186 | X1$1 += w * (x0$4 + (x0$4 = x));
|
10187 | Y1$1 += w * (y0$4 + (y0$4 = y));
|
10188 | Z1$1 += w * (z0 + (z0 = z));
|
10189 | centroidPointCartesian(x0$4, y0$4, z0);
|
10190 | }
|
10191 |
|
10192 | function centroidLineEnd$1() {
|
10193 | centroidStream$1.point = centroidPoint$1;
|
10194 | }
|
10195 |
|
10196 | // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
|
10197 | // J. Applied Mechanics 42, 239 (1975).
|
10198 | function centroidRingStart$1() {
|
10199 | centroidStream$1.point = centroidRingPointFirst;
|
10200 | }
|
10201 |
|
10202 | function centroidRingEnd$1() {
|
10203 | centroidRingPoint(lambda00, phi00);
|
10204 | centroidStream$1.point = centroidPoint$1;
|
10205 | }
|
10206 |
|
10207 | function centroidRingPointFirst(lambda, phi) {
|
10208 | lambda00 = lambda, phi00 = phi;
|
10209 | lambda *= radians, phi *= radians;
|
10210 | centroidStream$1.point = centroidRingPoint;
|
10211 | var cosPhi = cos$1(phi);
|
10212 | x0$4 = cosPhi * cos$1(lambda);
|
10213 | y0$4 = cosPhi * sin$1(lambda);
|
10214 | z0 = sin$1(phi);
|
10215 | centroidPointCartesian(x0$4, y0$4, z0);
|
10216 | }
|
10217 |
|
10218 | function centroidRingPoint(lambda, phi) {
|
10219 | lambda *= radians, phi *= radians;
|
10220 | var cosPhi = cos$1(phi),
|
10221 | x = cosPhi * cos$1(lambda),
|
10222 | y = cosPhi * sin$1(lambda),
|
10223 | z = sin$1(phi),
|
10224 | cx = y0$4 * z - z0 * y,
|
10225 | cy = z0 * x - x0$4 * z,
|
10226 | cz = x0$4 * y - y0$4 * x,
|
10227 | m = hypot(cx, cy, cz),
|
10228 | w = asin$1(m), // line weight = angle
|
10229 | v = m && -w / m; // area weight multiplier
|
10230 | X2$1.add(v * cx);
|
10231 | Y2$1.add(v * cy);
|
10232 | Z2$1.add(v * cz);
|
10233 | W1 += w;
|
10234 | X1$1 += w * (x0$4 + (x0$4 = x));
|
10235 | Y1$1 += w * (y0$4 + (y0$4 = y));
|
10236 | Z1$1 += w * (z0 + (z0 = z));
|
10237 | centroidPointCartesian(x0$4, y0$4, z0);
|
10238 | }
|
10239 |
|
10240 | function centroid$1(object) {
|
10241 | W0 = W1 =
|
10242 | X0$1 = Y0$1 = Z0$1 =
|
10243 | X1$1 = Y1$1 = Z1$1 = 0;
|
10244 | X2$1 = new Adder();
|
10245 | Y2$1 = new Adder();
|
10246 | Z2$1 = new Adder();
|
10247 | geoStream(object, centroidStream$1);
|
10248 |
|
10249 | var x = +X2$1,
|
10250 | y = +Y2$1,
|
10251 | z = +Z2$1,
|
10252 | m = hypot(x, y, z);
|
10253 |
|
10254 | // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
|
10255 | if (m < epsilon2) {
|
10256 | x = X1$1, y = Y1$1, z = Z1$1;
|
10257 | // If the feature has zero length, fall back to arithmetic mean of point vectors.
|
10258 | if (W1 < epsilon$1) x = X0$1, y = Y0$1, z = Z0$1;
|
10259 | m = hypot(x, y, z);
|
10260 | // If the feature still has an undefined ccentroid, then return.
|
10261 | if (m < epsilon2) return [NaN, NaN];
|
10262 | }
|
10263 |
|
10264 | return [atan2$1(y, x) * degrees, asin$1(z / m) * degrees];
|
10265 | }
|
10266 |
|
10267 | function constant$3(x) {
|
10268 | return function() {
|
10269 | return x;
|
10270 | };
|
10271 | }
|
10272 |
|
10273 | function compose(a, b) {
|
10274 |
|
10275 | function compose(x, y) {
|
10276 | return x = a(x, y), b(x[0], x[1]);
|
10277 | }
|
10278 |
|
10279 | if (a.invert && b.invert) compose.invert = function(x, y) {
|
10280 | return x = b.invert(x, y), x && a.invert(x[0], x[1]);
|
10281 | };
|
10282 |
|
10283 | return compose;
|
10284 | }
|
10285 |
|
10286 | function rotationIdentity(lambda, phi) {
|
10287 | return [abs$1(lambda) > pi$1 ? lambda + Math.round(-lambda / tau$1) * tau$1 : lambda, phi];
|
10288 | }
|
10289 |
|
10290 | rotationIdentity.invert = rotationIdentity;
|
10291 |
|
10292 | function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
|
10293 | return (deltaLambda %= tau$1) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
|
10294 | : rotationLambda(deltaLambda))
|
10295 | : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
|
10296 | : rotationIdentity);
|
10297 | }
|
10298 |
|
10299 | function forwardRotationLambda(deltaLambda) {
|
10300 | return function(lambda, phi) {
|
10301 | return lambda += deltaLambda, [lambda > pi$1 ? lambda - tau$1 : lambda < -pi$1 ? lambda + tau$1 : lambda, phi];
|
10302 | };
|
10303 | }
|
10304 |
|
10305 | function rotationLambda(deltaLambda) {
|
10306 | var rotation = forwardRotationLambda(deltaLambda);
|
10307 | rotation.invert = forwardRotationLambda(-deltaLambda);
|
10308 | return rotation;
|
10309 | }
|
10310 |
|
10311 | function rotationPhiGamma(deltaPhi, deltaGamma) {
|
10312 | var cosDeltaPhi = cos$1(deltaPhi),
|
10313 | sinDeltaPhi = sin$1(deltaPhi),
|
10314 | cosDeltaGamma = cos$1(deltaGamma),
|
10315 | sinDeltaGamma = sin$1(deltaGamma);
|
10316 |
|
10317 | function rotation(lambda, phi) {
|
10318 | var cosPhi = cos$1(phi),
|
10319 | x = cos$1(lambda) * cosPhi,
|
10320 | y = sin$1(lambda) * cosPhi,
|
10321 | z = sin$1(phi),
|
10322 | k = z * cosDeltaPhi + x * sinDeltaPhi;
|
10323 | return [
|
10324 | atan2$1(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
|
10325 | asin$1(k * cosDeltaGamma + y * sinDeltaGamma)
|
10326 | ];
|
10327 | }
|
10328 |
|
10329 | rotation.invert = function(lambda, phi) {
|
10330 | var cosPhi = cos$1(phi),
|
10331 | x = cos$1(lambda) * cosPhi,
|
10332 | y = sin$1(lambda) * cosPhi,
|
10333 | z = sin$1(phi),
|
10334 | k = z * cosDeltaGamma - y * sinDeltaGamma;
|
10335 | return [
|
10336 | atan2$1(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
|
10337 | asin$1(k * cosDeltaPhi - x * sinDeltaPhi)
|
10338 | ];
|
10339 | };
|
10340 |
|
10341 | return rotation;
|
10342 | }
|
10343 |
|
10344 | function rotation(rotate) {
|
10345 | rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
|
10346 |
|
10347 | function forward(coordinates) {
|
10348 | coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
|
10349 | return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
|
10350 | }
|
10351 |
|
10352 | forward.invert = function(coordinates) {
|
10353 | coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
|
10354 | return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
|
10355 | };
|
10356 |
|
10357 | return forward;
|
10358 | }
|
10359 |
|
10360 | // Generates a circle centered at [0°, 0°], with a given radius and precision.
|
10361 | function circleStream(stream, radius, delta, direction, t0, t1) {
|
10362 | if (!delta) return;
|
10363 | var cosRadius = cos$1(radius),
|
10364 | sinRadius = sin$1(radius),
|
10365 | step = direction * delta;
|
10366 | if (t0 == null) {
|
10367 | t0 = radius + direction * tau$1;
|
10368 | t1 = radius - step / 2;
|
10369 | } else {
|
10370 | t0 = circleRadius(cosRadius, t0);
|
10371 | t1 = circleRadius(cosRadius, t1);
|
10372 | if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$1;
|
10373 | }
|
10374 | for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
|
10375 | point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
|
10376 | stream.point(point[0], point[1]);
|
10377 | }
|
10378 | }
|
10379 |
|
10380 | // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
|
10381 | function circleRadius(cosRadius, point) {
|
10382 | point = cartesian(point), point[0] -= cosRadius;
|
10383 | cartesianNormalizeInPlace(point);
|
10384 | var radius = acos$1(-point[1]);
|
10385 | return ((-point[2] < 0 ? -radius : radius) + tau$1 - epsilon$1) % tau$1;
|
10386 | }
|
10387 |
|
10388 | function circle$2() {
|
10389 | var center = constant$3([0, 0]),
|
10390 | radius = constant$3(90),
|
10391 | precision = constant$3(6),
|
10392 | ring,
|
10393 | rotate,
|
10394 | stream = {point: point};
|
10395 |
|
10396 | function point(x, y) {
|
10397 | ring.push(x = rotate(x, y));
|
10398 | x[0] *= degrees, x[1] *= degrees;
|
10399 | }
|
10400 |
|
10401 | function circle() {
|
10402 | var c = center.apply(this, arguments),
|
10403 | r = radius.apply(this, arguments) * radians,
|
10404 | p = precision.apply(this, arguments) * radians;
|
10405 | ring = [];
|
10406 | rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
|
10407 | circleStream(stream, r, p, 1);
|
10408 | c = {type: "Polygon", coordinates: [ring]};
|
10409 | ring = rotate = null;
|
10410 | return c;
|
10411 | }
|
10412 |
|
10413 | circle.center = function(_) {
|
10414 | return arguments.length ? (center = typeof _ === "function" ? _ : constant$3([+_[0], +_[1]]), circle) : center;
|
10415 | };
|
10416 |
|
10417 | circle.radius = function(_) {
|
10418 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$3(+_), circle) : radius;
|
10419 | };
|
10420 |
|
10421 | circle.precision = function(_) {
|
10422 | return arguments.length ? (precision = typeof _ === "function" ? _ : constant$3(+_), circle) : precision;
|
10423 | };
|
10424 |
|
10425 | return circle;
|
10426 | }
|
10427 |
|
10428 | function clipBuffer() {
|
10429 | var lines = [],
|
10430 | line;
|
10431 | return {
|
10432 | point: function(x, y, m) {
|
10433 | line.push([x, y, m]);
|
10434 | },
|
10435 | lineStart: function() {
|
10436 | lines.push(line = []);
|
10437 | },
|
10438 | lineEnd: noop$1,
|
10439 | rejoin: function() {
|
10440 | if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
|
10441 | },
|
10442 | result: function() {
|
10443 | var result = lines;
|
10444 | lines = [];
|
10445 | line = null;
|
10446 | return result;
|
10447 | }
|
10448 | };
|
10449 | }
|
10450 |
|
10451 | function pointEqual(a, b) {
|
10452 | return abs$1(a[0] - b[0]) < epsilon$1 && abs$1(a[1] - b[1]) < epsilon$1;
|
10453 | }
|
10454 |
|
10455 | function Intersection(point, points, other, entry) {
|
10456 | this.x = point;
|
10457 | this.z = points;
|
10458 | this.o = other; // another intersection
|
10459 | this.e = entry; // is an entry?
|
10460 | this.v = false; // visited
|
10461 | this.n = this.p = null; // next & previous
|
10462 | }
|
10463 |
|
10464 | // A generalized polygon clipping algorithm: given a polygon that has been cut
|
10465 | // into its visible line segments, and rejoins the segments by interpolating
|
10466 | // along the clip edge.
|
10467 | function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
|
10468 | var subject = [],
|
10469 | clip = [],
|
10470 | i,
|
10471 | n;
|
10472 |
|
10473 | segments.forEach(function(segment) {
|
10474 | if ((n = segment.length - 1) <= 0) return;
|
10475 | var n, p0 = segment[0], p1 = segment[n], x;
|
10476 |
|
10477 | if (pointEqual(p0, p1)) {
|
10478 | if (!p0[2] && !p1[2]) {
|
10479 | stream.lineStart();
|
10480 | for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
|
10481 | stream.lineEnd();
|
10482 | return;
|
10483 | }
|
10484 | // handle degenerate cases by moving the point
|
10485 | p1[0] += 2 * epsilon$1;
|
10486 | }
|
10487 |
|
10488 | subject.push(x = new Intersection(p0, segment, null, true));
|
10489 | clip.push(x.o = new Intersection(p0, null, x, false));
|
10490 | subject.push(x = new Intersection(p1, segment, null, false));
|
10491 | clip.push(x.o = new Intersection(p1, null, x, true));
|
10492 | });
|
10493 |
|
10494 | if (!subject.length) return;
|
10495 |
|
10496 | clip.sort(compareIntersection);
|
10497 | link$1(subject);
|
10498 | link$1(clip);
|
10499 |
|
10500 | for (i = 0, n = clip.length; i < n; ++i) {
|
10501 | clip[i].e = startInside = !startInside;
|
10502 | }
|
10503 |
|
10504 | var start = subject[0],
|
10505 | points,
|
10506 | point;
|
10507 |
|
10508 | while (1) {
|
10509 | // Find first unvisited intersection.
|
10510 | var current = start,
|
10511 | isSubject = true;
|
10512 | while (current.v) if ((current = current.n) === start) return;
|
10513 | points = current.z;
|
10514 | stream.lineStart();
|
10515 | do {
|
10516 | current.v = current.o.v = true;
|
10517 | if (current.e) {
|
10518 | if (isSubject) {
|
10519 | for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
|
10520 | } else {
|
10521 | interpolate(current.x, current.n.x, 1, stream);
|
10522 | }
|
10523 | current = current.n;
|
10524 | } else {
|
10525 | if (isSubject) {
|
10526 | points = current.p.z;
|
10527 | for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
|
10528 | } else {
|
10529 | interpolate(current.x, current.p.x, -1, stream);
|
10530 | }
|
10531 | current = current.p;
|
10532 | }
|
10533 | current = current.o;
|
10534 | points = current.z;
|
10535 | isSubject = !isSubject;
|
10536 | } while (!current.v);
|
10537 | stream.lineEnd();
|
10538 | }
|
10539 | }
|
10540 |
|
10541 | function link$1(array) {
|
10542 | if (!(n = array.length)) return;
|
10543 | var n,
|
10544 | i = 0,
|
10545 | a = array[0],
|
10546 | b;
|
10547 | while (++i < n) {
|
10548 | a.n = b = array[i];
|
10549 | b.p = a;
|
10550 | a = b;
|
10551 | }
|
10552 | a.n = b = array[0];
|
10553 | b.p = a;
|
10554 | }
|
10555 |
|
10556 | function longitude(point) {
|
10557 | return abs$1(point[0]) <= pi$1 ? point[0] : sign$1(point[0]) * ((abs$1(point[0]) + pi$1) % tau$1 - pi$1);
|
10558 | }
|
10559 |
|
10560 | function polygonContains(polygon, point) {
|
10561 | var lambda = longitude(point),
|
10562 | phi = point[1],
|
10563 | sinPhi = sin$1(phi),
|
10564 | normal = [sin$1(lambda), -cos$1(lambda), 0],
|
10565 | angle = 0,
|
10566 | winding = 0;
|
10567 |
|
10568 | var sum = new Adder();
|
10569 |
|
10570 | if (sinPhi === 1) phi = halfPi$1 + epsilon$1;
|
10571 | else if (sinPhi === -1) phi = -halfPi$1 - epsilon$1;
|
10572 |
|
10573 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
10574 | if (!(m = (ring = polygon[i]).length)) continue;
|
10575 | var ring,
|
10576 | m,
|
10577 | point0 = ring[m - 1],
|
10578 | lambda0 = longitude(point0),
|
10579 | phi0 = point0[1] / 2 + quarterPi,
|
10580 | sinPhi0 = sin$1(phi0),
|
10581 | cosPhi0 = cos$1(phi0);
|
10582 |
|
10583 | for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
|
10584 | var point1 = ring[j],
|
10585 | lambda1 = longitude(point1),
|
10586 | phi1 = point1[1] / 2 + quarterPi,
|
10587 | sinPhi1 = sin$1(phi1),
|
10588 | cosPhi1 = cos$1(phi1),
|
10589 | delta = lambda1 - lambda0,
|
10590 | sign = delta >= 0 ? 1 : -1,
|
10591 | absDelta = sign * delta,
|
10592 | antimeridian = absDelta > pi$1,
|
10593 | k = sinPhi0 * sinPhi1;
|
10594 |
|
10595 | sum.add(atan2$1(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
|
10596 | angle += antimeridian ? delta + sign * tau$1 : delta;
|
10597 |
|
10598 | // Are the longitudes either side of the point’s meridian (lambda),
|
10599 | // and are the latitudes smaller than the parallel (phi)?
|
10600 | if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
|
10601 | var arc = cartesianCross(cartesian(point0), cartesian(point1));
|
10602 | cartesianNormalizeInPlace(arc);
|
10603 | var intersection = cartesianCross(normal, arc);
|
10604 | cartesianNormalizeInPlace(intersection);
|
10605 | var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
|
10606 | if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
|
10607 | winding += antimeridian ^ delta >= 0 ? 1 : -1;
|
10608 | }
|
10609 | }
|
10610 | }
|
10611 | }
|
10612 |
|
10613 | // First, determine whether the South pole is inside or outside:
|
10614 | //
|
10615 | // It is inside if:
|
10616 | // * the polygon winds around it in a clockwise direction.
|
10617 | // * the polygon does not (cumulatively) wind around it, but has a negative
|
10618 | // (counter-clockwise) area.
|
10619 | //
|
10620 | // Second, count the (signed) number of times a segment crosses a lambda
|
10621 | // from the point to the South pole. If it is zero, then the point is the
|
10622 | // same side as the South pole.
|
10623 |
|
10624 | return (angle < -epsilon$1 || angle < epsilon$1 && sum < -epsilon2) ^ (winding & 1);
|
10625 | }
|
10626 |
|
10627 | function clip(pointVisible, clipLine, interpolate, start) {
|
10628 | return function(sink) {
|
10629 | var line = clipLine(sink),
|
10630 | ringBuffer = clipBuffer(),
|
10631 | ringSink = clipLine(ringBuffer),
|
10632 | polygonStarted = false,
|
10633 | polygon,
|
10634 | segments,
|
10635 | ring;
|
10636 |
|
10637 | var clip = {
|
10638 | point: point,
|
10639 | lineStart: lineStart,
|
10640 | lineEnd: lineEnd,
|
10641 | polygonStart: function() {
|
10642 | clip.point = pointRing;
|
10643 | clip.lineStart = ringStart;
|
10644 | clip.lineEnd = ringEnd;
|
10645 | segments = [];
|
10646 | polygon = [];
|
10647 | },
|
10648 | polygonEnd: function() {
|
10649 | clip.point = point;
|
10650 | clip.lineStart = lineStart;
|
10651 | clip.lineEnd = lineEnd;
|
10652 | segments = merge(segments);
|
10653 | var startInside = polygonContains(polygon, start);
|
10654 | if (segments.length) {
|
10655 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
10656 | clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
|
10657 | } else if (startInside) {
|
10658 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
10659 | sink.lineStart();
|
10660 | interpolate(null, null, 1, sink);
|
10661 | sink.lineEnd();
|
10662 | }
|
10663 | if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
|
10664 | segments = polygon = null;
|
10665 | },
|
10666 | sphere: function() {
|
10667 | sink.polygonStart();
|
10668 | sink.lineStart();
|
10669 | interpolate(null, null, 1, sink);
|
10670 | sink.lineEnd();
|
10671 | sink.polygonEnd();
|
10672 | }
|
10673 | };
|
10674 |
|
10675 | function point(lambda, phi) {
|
10676 | if (pointVisible(lambda, phi)) sink.point(lambda, phi);
|
10677 | }
|
10678 |
|
10679 | function pointLine(lambda, phi) {
|
10680 | line.point(lambda, phi);
|
10681 | }
|
10682 |
|
10683 | function lineStart() {
|
10684 | clip.point = pointLine;
|
10685 | line.lineStart();
|
10686 | }
|
10687 |
|
10688 | function lineEnd() {
|
10689 | clip.point = point;
|
10690 | line.lineEnd();
|
10691 | }
|
10692 |
|
10693 | function pointRing(lambda, phi) {
|
10694 | ring.push([lambda, phi]);
|
10695 | ringSink.point(lambda, phi);
|
10696 | }
|
10697 |
|
10698 | function ringStart() {
|
10699 | ringSink.lineStart();
|
10700 | ring = [];
|
10701 | }
|
10702 |
|
10703 | function ringEnd() {
|
10704 | pointRing(ring[0][0], ring[0][1]);
|
10705 | ringSink.lineEnd();
|
10706 |
|
10707 | var clean = ringSink.clean(),
|
10708 | ringSegments = ringBuffer.result(),
|
10709 | i, n = ringSegments.length, m,
|
10710 | segment,
|
10711 | point;
|
10712 |
|
10713 | ring.pop();
|
10714 | polygon.push(ring);
|
10715 | ring = null;
|
10716 |
|
10717 | if (!n) return;
|
10718 |
|
10719 | // No intersections.
|
10720 | if (clean & 1) {
|
10721 | segment = ringSegments[0];
|
10722 | if ((m = segment.length - 1) > 0) {
|
10723 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
10724 | sink.lineStart();
|
10725 | for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
|
10726 | sink.lineEnd();
|
10727 | }
|
10728 | return;
|
10729 | }
|
10730 |
|
10731 | // Rejoin connected segments.
|
10732 | // TODO reuse ringBuffer.rejoin()?
|
10733 | if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
|
10734 |
|
10735 | segments.push(ringSegments.filter(validSegment));
|
10736 | }
|
10737 |
|
10738 | return clip;
|
10739 | };
|
10740 | }
|
10741 |
|
10742 | function validSegment(segment) {
|
10743 | return segment.length > 1;
|
10744 | }
|
10745 |
|
10746 | // Intersections are sorted along the clip edge. For both antimeridian cutting
|
10747 | // and circle clipping, the same comparison is used.
|
10748 | function compareIntersection(a, b) {
|
10749 | return ((a = a.x)[0] < 0 ? a[1] - halfPi$1 - epsilon$1 : halfPi$1 - a[1])
|
10750 | - ((b = b.x)[0] < 0 ? b[1] - halfPi$1 - epsilon$1 : halfPi$1 - b[1]);
|
10751 | }
|
10752 |
|
10753 | var clipAntimeridian = clip(
|
10754 | function() { return true; },
|
10755 | clipAntimeridianLine,
|
10756 | clipAntimeridianInterpolate,
|
10757 | [-pi$1, -halfPi$1]
|
10758 | );
|
10759 |
|
10760 | // Takes a line and cuts into visible segments. Return values: 0 - there were
|
10761 | // intersections or the line was empty; 1 - no intersections; 2 - there were
|
10762 | // intersections, and the first and last segments should be rejoined.
|
10763 | function clipAntimeridianLine(stream) {
|
10764 | var lambda0 = NaN,
|
10765 | phi0 = NaN,
|
10766 | sign0 = NaN,
|
10767 | clean; // no intersections
|
10768 |
|
10769 | return {
|
10770 | lineStart: function() {
|
10771 | stream.lineStart();
|
10772 | clean = 1;
|
10773 | },
|
10774 | point: function(lambda1, phi1) {
|
10775 | var sign1 = lambda1 > 0 ? pi$1 : -pi$1,
|
10776 | delta = abs$1(lambda1 - lambda0);
|
10777 | if (abs$1(delta - pi$1) < epsilon$1) { // line crosses a pole
|
10778 | stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$1 : -halfPi$1);
|
10779 | stream.point(sign0, phi0);
|
10780 | stream.lineEnd();
|
10781 | stream.lineStart();
|
10782 | stream.point(sign1, phi0);
|
10783 | stream.point(lambda1, phi0);
|
10784 | clean = 0;
|
10785 | } else if (sign0 !== sign1 && delta >= pi$1) { // line crosses antimeridian
|
10786 | if (abs$1(lambda0 - sign0) < epsilon$1) lambda0 -= sign0 * epsilon$1; // handle degeneracies
|
10787 | if (abs$1(lambda1 - sign1) < epsilon$1) lambda1 -= sign1 * epsilon$1;
|
10788 | phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
|
10789 | stream.point(sign0, phi0);
|
10790 | stream.lineEnd();
|
10791 | stream.lineStart();
|
10792 | stream.point(sign1, phi0);
|
10793 | clean = 0;
|
10794 | }
|
10795 | stream.point(lambda0 = lambda1, phi0 = phi1);
|
10796 | sign0 = sign1;
|
10797 | },
|
10798 | lineEnd: function() {
|
10799 | stream.lineEnd();
|
10800 | lambda0 = phi0 = NaN;
|
10801 | },
|
10802 | clean: function() {
|
10803 | return 2 - clean; // if intersections, rejoin first and last segments
|
10804 | }
|
10805 | };
|
10806 | }
|
10807 |
|
10808 | function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
|
10809 | var cosPhi0,
|
10810 | cosPhi1,
|
10811 | sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
|
10812 | return abs$1(sinLambda0Lambda1) > epsilon$1
|
10813 | ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
|
10814 | - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
|
10815 | / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
|
10816 | : (phi0 + phi1) / 2;
|
10817 | }
|
10818 |
|
10819 | function clipAntimeridianInterpolate(from, to, direction, stream) {
|
10820 | var phi;
|
10821 | if (from == null) {
|
10822 | phi = direction * halfPi$1;
|
10823 | stream.point(-pi$1, phi);
|
10824 | stream.point(0, phi);
|
10825 | stream.point(pi$1, phi);
|
10826 | stream.point(pi$1, 0);
|
10827 | stream.point(pi$1, -phi);
|
10828 | stream.point(0, -phi);
|
10829 | stream.point(-pi$1, -phi);
|
10830 | stream.point(-pi$1, 0);
|
10831 | stream.point(-pi$1, phi);
|
10832 | } else if (abs$1(from[0] - to[0]) > epsilon$1) {
|
10833 | var lambda = from[0] < to[0] ? pi$1 : -pi$1;
|
10834 | phi = direction * lambda / 2;
|
10835 | stream.point(-lambda, phi);
|
10836 | stream.point(0, phi);
|
10837 | stream.point(lambda, phi);
|
10838 | } else {
|
10839 | stream.point(to[0], to[1]);
|
10840 | }
|
10841 | }
|
10842 |
|
10843 | function clipCircle(radius) {
|
10844 | var cr = cos$1(radius),
|
10845 | delta = 6 * radians,
|
10846 | smallRadius = cr > 0,
|
10847 | notHemisphere = abs$1(cr) > epsilon$1; // TODO optimise for this common case
|
10848 |
|
10849 | function interpolate(from, to, direction, stream) {
|
10850 | circleStream(stream, radius, delta, direction, from, to);
|
10851 | }
|
10852 |
|
10853 | function visible(lambda, phi) {
|
10854 | return cos$1(lambda) * cos$1(phi) > cr;
|
10855 | }
|
10856 |
|
10857 | // Takes a line and cuts into visible segments. Return values used for polygon
|
10858 | // clipping: 0 - there were intersections or the line was empty; 1 - no
|
10859 | // intersections 2 - there were intersections, and the first and last segments
|
10860 | // should be rejoined.
|
10861 | function clipLine(stream) {
|
10862 | var point0, // previous point
|
10863 | c0, // code for previous point
|
10864 | v0, // visibility of previous point
|
10865 | v00, // visibility of first point
|
10866 | clean; // no intersections
|
10867 | return {
|
10868 | lineStart: function() {
|
10869 | v00 = v0 = false;
|
10870 | clean = 1;
|
10871 | },
|
10872 | point: function(lambda, phi) {
|
10873 | var point1 = [lambda, phi],
|
10874 | point2,
|
10875 | v = visible(lambda, phi),
|
10876 | c = smallRadius
|
10877 | ? v ? 0 : code(lambda, phi)
|
10878 | : v ? code(lambda + (lambda < 0 ? pi$1 : -pi$1), phi) : 0;
|
10879 | if (!point0 && (v00 = v0 = v)) stream.lineStart();
|
10880 | if (v !== v0) {
|
10881 | point2 = intersect(point0, point1);
|
10882 | if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2))
|
10883 | point1[2] = 1;
|
10884 | }
|
10885 | if (v !== v0) {
|
10886 | clean = 0;
|
10887 | if (v) {
|
10888 | // outside going in
|
10889 | stream.lineStart();
|
10890 | point2 = intersect(point1, point0);
|
10891 | stream.point(point2[0], point2[1]);
|
10892 | } else {
|
10893 | // inside going out
|
10894 | point2 = intersect(point0, point1);
|
10895 | stream.point(point2[0], point2[1], 2);
|
10896 | stream.lineEnd();
|
10897 | }
|
10898 | point0 = point2;
|
10899 | } else if (notHemisphere && point0 && smallRadius ^ v) {
|
10900 | var t;
|
10901 | // If the codes for two points are different, or are both zero,
|
10902 | // and there this segment intersects with the small circle.
|
10903 | if (!(c & c0) && (t = intersect(point1, point0, true))) {
|
10904 | clean = 0;
|
10905 | if (smallRadius) {
|
10906 | stream.lineStart();
|
10907 | stream.point(t[0][0], t[0][1]);
|
10908 | stream.point(t[1][0], t[1][1]);
|
10909 | stream.lineEnd();
|
10910 | } else {
|
10911 | stream.point(t[1][0], t[1][1]);
|
10912 | stream.lineEnd();
|
10913 | stream.lineStart();
|
10914 | stream.point(t[0][0], t[0][1], 3);
|
10915 | }
|
10916 | }
|
10917 | }
|
10918 | if (v && (!point0 || !pointEqual(point0, point1))) {
|
10919 | stream.point(point1[0], point1[1]);
|
10920 | }
|
10921 | point0 = point1, v0 = v, c0 = c;
|
10922 | },
|
10923 | lineEnd: function() {
|
10924 | if (v0) stream.lineEnd();
|
10925 | point0 = null;
|
10926 | },
|
10927 | // Rejoin first and last segments if there were intersections and the first
|
10928 | // and last points were visible.
|
10929 | clean: function() {
|
10930 | return clean | ((v00 && v0) << 1);
|
10931 | }
|
10932 | };
|
10933 | }
|
10934 |
|
10935 | // Intersects the great circle between a and b with the clip circle.
|
10936 | function intersect(a, b, two) {
|
10937 | var pa = cartesian(a),
|
10938 | pb = cartesian(b);
|
10939 |
|
10940 | // We have two planes, n1.p = d1 and n2.p = d2.
|
10941 | // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
|
10942 | var n1 = [1, 0, 0], // normal
|
10943 | n2 = cartesianCross(pa, pb),
|
10944 | n2n2 = cartesianDot(n2, n2),
|
10945 | n1n2 = n2[0], // cartesianDot(n1, n2),
|
10946 | determinant = n2n2 - n1n2 * n1n2;
|
10947 |
|
10948 | // Two polar points.
|
10949 | if (!determinant) return !two && a;
|
10950 |
|
10951 | var c1 = cr * n2n2 / determinant,
|
10952 | c2 = -cr * n1n2 / determinant,
|
10953 | n1xn2 = cartesianCross(n1, n2),
|
10954 | A = cartesianScale(n1, c1),
|
10955 | B = cartesianScale(n2, c2);
|
10956 | cartesianAddInPlace(A, B);
|
10957 |
|
10958 | // Solve |p(t)|^2 = 1.
|
10959 | var u = n1xn2,
|
10960 | w = cartesianDot(A, u),
|
10961 | uu = cartesianDot(u, u),
|
10962 | t2 = w * w - uu * (cartesianDot(A, A) - 1);
|
10963 |
|
10964 | if (t2 < 0) return;
|
10965 |
|
10966 | var t = sqrt$2(t2),
|
10967 | q = cartesianScale(u, (-w - t) / uu);
|
10968 | cartesianAddInPlace(q, A);
|
10969 | q = spherical(q);
|
10970 |
|
10971 | if (!two) return q;
|
10972 |
|
10973 | // Two intersection points.
|
10974 | var lambda0 = a[0],
|
10975 | lambda1 = b[0],
|
10976 | phi0 = a[1],
|
10977 | phi1 = b[1],
|
10978 | z;
|
10979 |
|
10980 | if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
|
10981 |
|
10982 | var delta = lambda1 - lambda0,
|
10983 | polar = abs$1(delta - pi$1) < epsilon$1,
|
10984 | meridian = polar || delta < epsilon$1;
|
10985 |
|
10986 | if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
|
10987 |
|
10988 | // Check that the first point is between a and b.
|
10989 | if (meridian
|
10990 | ? polar
|
10991 | ? phi0 + phi1 > 0 ^ q[1] < (abs$1(q[0] - lambda0) < epsilon$1 ? phi0 : phi1)
|
10992 | : phi0 <= q[1] && q[1] <= phi1
|
10993 | : delta > pi$1 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
|
10994 | var q1 = cartesianScale(u, (-w + t) / uu);
|
10995 | cartesianAddInPlace(q1, A);
|
10996 | return [q, spherical(q1)];
|
10997 | }
|
10998 | }
|
10999 |
|
11000 | // Generates a 4-bit vector representing the location of a point relative to
|
11001 | // the small circle's bounding box.
|
11002 | function code(lambda, phi) {
|
11003 | var r = smallRadius ? radius : pi$1 - radius,
|
11004 | code = 0;
|
11005 | if (lambda < -r) code |= 1; // left
|
11006 | else if (lambda > r) code |= 2; // right
|
11007 | if (phi < -r) code |= 4; // below
|
11008 | else if (phi > r) code |= 8; // above
|
11009 | return code;
|
11010 | }
|
11011 |
|
11012 | return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$1, radius - pi$1]);
|
11013 | }
|
11014 |
|
11015 | function clipLine(a, b, x0, y0, x1, y1) {
|
11016 | var ax = a[0],
|
11017 | ay = a[1],
|
11018 | bx = b[0],
|
11019 | by = b[1],
|
11020 | t0 = 0,
|
11021 | t1 = 1,
|
11022 | dx = bx - ax,
|
11023 | dy = by - ay,
|
11024 | r;
|
11025 |
|
11026 | r = x0 - ax;
|
11027 | if (!dx && r > 0) return;
|
11028 | r /= dx;
|
11029 | if (dx < 0) {
|
11030 | if (r < t0) return;
|
11031 | if (r < t1) t1 = r;
|
11032 | } else if (dx > 0) {
|
11033 | if (r > t1) return;
|
11034 | if (r > t0) t0 = r;
|
11035 | }
|
11036 |
|
11037 | r = x1 - ax;
|
11038 | if (!dx && r < 0) return;
|
11039 | r /= dx;
|
11040 | if (dx < 0) {
|
11041 | if (r > t1) return;
|
11042 | if (r > t0) t0 = r;
|
11043 | } else if (dx > 0) {
|
11044 | if (r < t0) return;
|
11045 | if (r < t1) t1 = r;
|
11046 | }
|
11047 |
|
11048 | r = y0 - ay;
|
11049 | if (!dy && r > 0) return;
|
11050 | r /= dy;
|
11051 | if (dy < 0) {
|
11052 | if (r < t0) return;
|
11053 | if (r < t1) t1 = r;
|
11054 | } else if (dy > 0) {
|
11055 | if (r > t1) return;
|
11056 | if (r > t0) t0 = r;
|
11057 | }
|
11058 |
|
11059 | r = y1 - ay;
|
11060 | if (!dy && r < 0) return;
|
11061 | r /= dy;
|
11062 | if (dy < 0) {
|
11063 | if (r > t1) return;
|
11064 | if (r > t0) t0 = r;
|
11065 | } else if (dy > 0) {
|
11066 | if (r < t0) return;
|
11067 | if (r < t1) t1 = r;
|
11068 | }
|
11069 |
|
11070 | if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
|
11071 | if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
|
11072 | return true;
|
11073 | }
|
11074 |
|
11075 | var clipMax = 1e9, clipMin = -clipMax;
|
11076 |
|
11077 | // TODO Use d3-polygon’s polygonContains here for the ring check?
|
11078 | // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
|
11079 |
|
11080 | function clipRectangle(x0, y0, x1, y1) {
|
11081 |
|
11082 | function visible(x, y) {
|
11083 | return x0 <= x && x <= x1 && y0 <= y && y <= y1;
|
11084 | }
|
11085 |
|
11086 | function interpolate(from, to, direction, stream) {
|
11087 | var a = 0, a1 = 0;
|
11088 | if (from == null
|
11089 | || (a = corner(from, direction)) !== (a1 = corner(to, direction))
|
11090 | || comparePoint(from, to) < 0 ^ direction > 0) {
|
11091 | do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
|
11092 | while ((a = (a + direction + 4) % 4) !== a1);
|
11093 | } else {
|
11094 | stream.point(to[0], to[1]);
|
11095 | }
|
11096 | }
|
11097 |
|
11098 | function corner(p, direction) {
|
11099 | return abs$1(p[0] - x0) < epsilon$1 ? direction > 0 ? 0 : 3
|
11100 | : abs$1(p[0] - x1) < epsilon$1 ? direction > 0 ? 2 : 1
|
11101 | : abs$1(p[1] - y0) < epsilon$1 ? direction > 0 ? 1 : 0
|
11102 | : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
|
11103 | }
|
11104 |
|
11105 | function compareIntersection(a, b) {
|
11106 | return comparePoint(a.x, b.x);
|
11107 | }
|
11108 |
|
11109 | function comparePoint(a, b) {
|
11110 | var ca = corner(a, 1),
|
11111 | cb = corner(b, 1);
|
11112 | return ca !== cb ? ca - cb
|
11113 | : ca === 0 ? b[1] - a[1]
|
11114 | : ca === 1 ? a[0] - b[0]
|
11115 | : ca === 2 ? a[1] - b[1]
|
11116 | : b[0] - a[0];
|
11117 | }
|
11118 |
|
11119 | return function(stream) {
|
11120 | var activeStream = stream,
|
11121 | bufferStream = clipBuffer(),
|
11122 | segments,
|
11123 | polygon,
|
11124 | ring,
|
11125 | x__, y__, v__, // first point
|
11126 | x_, y_, v_, // previous point
|
11127 | first,
|
11128 | clean;
|
11129 |
|
11130 | var clipStream = {
|
11131 | point: point,
|
11132 | lineStart: lineStart,
|
11133 | lineEnd: lineEnd,
|
11134 | polygonStart: polygonStart,
|
11135 | polygonEnd: polygonEnd
|
11136 | };
|
11137 |
|
11138 | function point(x, y) {
|
11139 | if (visible(x, y)) activeStream.point(x, y);
|
11140 | }
|
11141 |
|
11142 | function polygonInside() {
|
11143 | var winding = 0;
|
11144 |
|
11145 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
11146 | for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
|
11147 | a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
|
11148 | if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
|
11149 | else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
|
11150 | }
|
11151 | }
|
11152 |
|
11153 | return winding;
|
11154 | }
|
11155 |
|
11156 | // Buffer geometry within a polygon and then clip it en masse.
|
11157 | function polygonStart() {
|
11158 | activeStream = bufferStream, segments = [], polygon = [], clean = true;
|
11159 | }
|
11160 |
|
11161 | function polygonEnd() {
|
11162 | var startInside = polygonInside(),
|
11163 | cleanInside = clean && startInside,
|
11164 | visible = (segments = merge(segments)).length;
|
11165 | if (cleanInside || visible) {
|
11166 | stream.polygonStart();
|
11167 | if (cleanInside) {
|
11168 | stream.lineStart();
|
11169 | interpolate(null, null, 1, stream);
|
11170 | stream.lineEnd();
|
11171 | }
|
11172 | if (visible) {
|
11173 | clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
|
11174 | }
|
11175 | stream.polygonEnd();
|
11176 | }
|
11177 | activeStream = stream, segments = polygon = ring = null;
|
11178 | }
|
11179 |
|
11180 | function lineStart() {
|
11181 | clipStream.point = linePoint;
|
11182 | if (polygon) polygon.push(ring = []);
|
11183 | first = true;
|
11184 | v_ = false;
|
11185 | x_ = y_ = NaN;
|
11186 | }
|
11187 |
|
11188 | // TODO rather than special-case polygons, simply handle them separately.
|
11189 | // Ideally, coincident intersection points should be jittered to avoid
|
11190 | // clipping issues.
|
11191 | function lineEnd() {
|
11192 | if (segments) {
|
11193 | linePoint(x__, y__);
|
11194 | if (v__ && v_) bufferStream.rejoin();
|
11195 | segments.push(bufferStream.result());
|
11196 | }
|
11197 | clipStream.point = point;
|
11198 | if (v_) activeStream.lineEnd();
|
11199 | }
|
11200 |
|
11201 | function linePoint(x, y) {
|
11202 | var v = visible(x, y);
|
11203 | if (polygon) ring.push([x, y]);
|
11204 | if (first) {
|
11205 | x__ = x, y__ = y, v__ = v;
|
11206 | first = false;
|
11207 | if (v) {
|
11208 | activeStream.lineStart();
|
11209 | activeStream.point(x, y);
|
11210 | }
|
11211 | } else {
|
11212 | if (v && v_) activeStream.point(x, y);
|
11213 | else {
|
11214 | var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
|
11215 | b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
|
11216 | if (clipLine(a, b, x0, y0, x1, y1)) {
|
11217 | if (!v_) {
|
11218 | activeStream.lineStart();
|
11219 | activeStream.point(a[0], a[1]);
|
11220 | }
|
11221 | activeStream.point(b[0], b[1]);
|
11222 | if (!v) activeStream.lineEnd();
|
11223 | clean = false;
|
11224 | } else if (v) {
|
11225 | activeStream.lineStart();
|
11226 | activeStream.point(x, y);
|
11227 | clean = false;
|
11228 | }
|
11229 | }
|
11230 | }
|
11231 | x_ = x, y_ = y, v_ = v;
|
11232 | }
|
11233 |
|
11234 | return clipStream;
|
11235 | };
|
11236 | }
|
11237 |
|
11238 | function extent() {
|
11239 | var x0 = 0,
|
11240 | y0 = 0,
|
11241 | x1 = 960,
|
11242 | y1 = 500,
|
11243 | cache,
|
11244 | cacheStream,
|
11245 | clip;
|
11246 |
|
11247 | return clip = {
|
11248 | stream: function(stream) {
|
11249 | return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
|
11250 | },
|
11251 | extent: function(_) {
|
11252 | return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
|
11253 | }
|
11254 | };
|
11255 | }
|
11256 |
|
11257 | var lengthSum$1,
|
11258 | lambda0,
|
11259 | sinPhi0,
|
11260 | cosPhi0;
|
11261 |
|
11262 | var lengthStream$1 = {
|
11263 | sphere: noop$1,
|
11264 | point: noop$1,
|
11265 | lineStart: lengthLineStart,
|
11266 | lineEnd: noop$1,
|
11267 | polygonStart: noop$1,
|
11268 | polygonEnd: noop$1
|
11269 | };
|
11270 |
|
11271 | function lengthLineStart() {
|
11272 | lengthStream$1.point = lengthPointFirst$1;
|
11273 | lengthStream$1.lineEnd = lengthLineEnd;
|
11274 | }
|
11275 |
|
11276 | function lengthLineEnd() {
|
11277 | lengthStream$1.point = lengthStream$1.lineEnd = noop$1;
|
11278 | }
|
11279 |
|
11280 | function lengthPointFirst$1(lambda, phi) {
|
11281 | lambda *= radians, phi *= radians;
|
11282 | lambda0 = lambda, sinPhi0 = sin$1(phi), cosPhi0 = cos$1(phi);
|
11283 | lengthStream$1.point = lengthPoint$1;
|
11284 | }
|
11285 |
|
11286 | function lengthPoint$1(lambda, phi) {
|
11287 | lambda *= radians, phi *= radians;
|
11288 | var sinPhi = sin$1(phi),
|
11289 | cosPhi = cos$1(phi),
|
11290 | delta = abs$1(lambda - lambda0),
|
11291 | cosDelta = cos$1(delta),
|
11292 | sinDelta = sin$1(delta),
|
11293 | x = cosPhi * sinDelta,
|
11294 | y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta,
|
11295 | z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta;
|
11296 | lengthSum$1.add(atan2$1(sqrt$2(x * x + y * y), z));
|
11297 | lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi;
|
11298 | }
|
11299 |
|
11300 | function length$1(object) {
|
11301 | lengthSum$1 = new Adder();
|
11302 | geoStream(object, lengthStream$1);
|
11303 | return +lengthSum$1;
|
11304 | }
|
11305 |
|
11306 | var coordinates = [null, null],
|
11307 | object = {type: "LineString", coordinates: coordinates};
|
11308 |
|
11309 | function distance(a, b) {
|
11310 | coordinates[0] = a;
|
11311 | coordinates[1] = b;
|
11312 | return length$1(object);
|
11313 | }
|
11314 |
|
11315 | var containsObjectType = {
|
11316 | Feature: function(object, point) {
|
11317 | return containsGeometry(object.geometry, point);
|
11318 | },
|
11319 | FeatureCollection: function(object, point) {
|
11320 | var features = object.features, i = -1, n = features.length;
|
11321 | while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
|
11322 | return false;
|
11323 | }
|
11324 | };
|
11325 |
|
11326 | var containsGeometryType = {
|
11327 | Sphere: function() {
|
11328 | return true;
|
11329 | },
|
11330 | Point: function(object, point) {
|
11331 | return containsPoint(object.coordinates, point);
|
11332 | },
|
11333 | MultiPoint: function(object, point) {
|
11334 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
11335 | while (++i < n) if (containsPoint(coordinates[i], point)) return true;
|
11336 | return false;
|
11337 | },
|
11338 | LineString: function(object, point) {
|
11339 | return containsLine(object.coordinates, point);
|
11340 | },
|
11341 | MultiLineString: function(object, point) {
|
11342 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
11343 | while (++i < n) if (containsLine(coordinates[i], point)) return true;
|
11344 | return false;
|
11345 | },
|
11346 | Polygon: function(object, point) {
|
11347 | return containsPolygon(object.coordinates, point);
|
11348 | },
|
11349 | MultiPolygon: function(object, point) {
|
11350 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
11351 | while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
|
11352 | return false;
|
11353 | },
|
11354 | GeometryCollection: function(object, point) {
|
11355 | var geometries = object.geometries, i = -1, n = geometries.length;
|
11356 | while (++i < n) if (containsGeometry(geometries[i], point)) return true;
|
11357 | return false;
|
11358 | }
|
11359 | };
|
11360 |
|
11361 | function containsGeometry(geometry, point) {
|
11362 | return geometry && containsGeometryType.hasOwnProperty(geometry.type)
|
11363 | ? containsGeometryType[geometry.type](geometry, point)
|
11364 | : false;
|
11365 | }
|
11366 |
|
11367 | function containsPoint(coordinates, point) {
|
11368 | return distance(coordinates, point) === 0;
|
11369 | }
|
11370 |
|
11371 | function containsLine(coordinates, point) {
|
11372 | var ao, bo, ab;
|
11373 | for (var i = 0, n = coordinates.length; i < n; i++) {
|
11374 | bo = distance(coordinates[i], point);
|
11375 | if (bo === 0) return true;
|
11376 | if (i > 0) {
|
11377 | ab = distance(coordinates[i], coordinates[i - 1]);
|
11378 | if (
|
11379 | ab > 0 &&
|
11380 | ao <= ab &&
|
11381 | bo <= ab &&
|
11382 | (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2 * ab
|
11383 | )
|
11384 | return true;
|
11385 | }
|
11386 | ao = bo;
|
11387 | }
|
11388 | return false;
|
11389 | }
|
11390 |
|
11391 | function containsPolygon(coordinates, point) {
|
11392 | return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
|
11393 | }
|
11394 |
|
11395 | function ringRadians(ring) {
|
11396 | return ring = ring.map(pointRadians), ring.pop(), ring;
|
11397 | }
|
11398 |
|
11399 | function pointRadians(point) {
|
11400 | return [point[0] * radians, point[1] * radians];
|
11401 | }
|
11402 |
|
11403 | function contains$1(object, point) {
|
11404 | return (object && containsObjectType.hasOwnProperty(object.type)
|
11405 | ? containsObjectType[object.type]
|
11406 | : containsGeometry)(object, point);
|
11407 | }
|
11408 |
|
11409 | function graticuleX(y0, y1, dy) {
|
11410 | var y = range$2(y0, y1 - epsilon$1, dy).concat(y1);
|
11411 | return function(x) { return y.map(function(y) { return [x, y]; }); };
|
11412 | }
|
11413 |
|
11414 | function graticuleY(x0, x1, dx) {
|
11415 | var x = range$2(x0, x1 - epsilon$1, dx).concat(x1);
|
11416 | return function(y) { return x.map(function(x) { return [x, y]; }); };
|
11417 | }
|
11418 |
|
11419 | function graticule() {
|
11420 | var x1, x0, X1, X0,
|
11421 | y1, y0, Y1, Y0,
|
11422 | dx = 10, dy = dx, DX = 90, DY = 360,
|
11423 | x, y, X, Y,
|
11424 | precision = 2.5;
|
11425 |
|
11426 | function graticule() {
|
11427 | return {type: "MultiLineString", coordinates: lines()};
|
11428 | }
|
11429 |
|
11430 | function lines() {
|
11431 | return range$2(ceil(X0 / DX) * DX, X1, DX).map(X)
|
11432 | .concat(range$2(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
|
11433 | .concat(range$2(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs$1(x % DX) > epsilon$1; }).map(x))
|
11434 | .concat(range$2(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs$1(y % DY) > epsilon$1; }).map(y));
|
11435 | }
|
11436 |
|
11437 | graticule.lines = function() {
|
11438 | return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
|
11439 | };
|
11440 |
|
11441 | graticule.outline = function() {
|
11442 | return {
|
11443 | type: "Polygon",
|
11444 | coordinates: [
|
11445 | X(X0).concat(
|
11446 | Y(Y1).slice(1),
|
11447 | X(X1).reverse().slice(1),
|
11448 | Y(Y0).reverse().slice(1))
|
11449 | ]
|
11450 | };
|
11451 | };
|
11452 |
|
11453 | graticule.extent = function(_) {
|
11454 | if (!arguments.length) return graticule.extentMinor();
|
11455 | return graticule.extentMajor(_).extentMinor(_);
|
11456 | };
|
11457 |
|
11458 | graticule.extentMajor = function(_) {
|
11459 | if (!arguments.length) return [[X0, Y0], [X1, Y1]];
|
11460 | X0 = +_[0][0], X1 = +_[1][0];
|
11461 | Y0 = +_[0][1], Y1 = +_[1][1];
|
11462 | if (X0 > X1) _ = X0, X0 = X1, X1 = _;
|
11463 | if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
|
11464 | return graticule.precision(precision);
|
11465 | };
|
11466 |
|
11467 | graticule.extentMinor = function(_) {
|
11468 | if (!arguments.length) return [[x0, y0], [x1, y1]];
|
11469 | x0 = +_[0][0], x1 = +_[1][0];
|
11470 | y0 = +_[0][1], y1 = +_[1][1];
|
11471 | if (x0 > x1) _ = x0, x0 = x1, x1 = _;
|
11472 | if (y0 > y1) _ = y0, y0 = y1, y1 = _;
|
11473 | return graticule.precision(precision);
|
11474 | };
|
11475 |
|
11476 | graticule.step = function(_) {
|
11477 | if (!arguments.length) return graticule.stepMinor();
|
11478 | return graticule.stepMajor(_).stepMinor(_);
|
11479 | };
|
11480 |
|
11481 | graticule.stepMajor = function(_) {
|
11482 | if (!arguments.length) return [DX, DY];
|
11483 | DX = +_[0], DY = +_[1];
|
11484 | return graticule;
|
11485 | };
|
11486 |
|
11487 | graticule.stepMinor = function(_) {
|
11488 | if (!arguments.length) return [dx, dy];
|
11489 | dx = +_[0], dy = +_[1];
|
11490 | return graticule;
|
11491 | };
|
11492 |
|
11493 | graticule.precision = function(_) {
|
11494 | if (!arguments.length) return precision;
|
11495 | precision = +_;
|
11496 | x = graticuleX(y0, y1, 90);
|
11497 | y = graticuleY(x0, x1, precision);
|
11498 | X = graticuleX(Y0, Y1, 90);
|
11499 | Y = graticuleY(X0, X1, precision);
|
11500 | return graticule;
|
11501 | };
|
11502 |
|
11503 | return graticule
|
11504 | .extentMajor([[-180, -90 + epsilon$1], [180, 90 - epsilon$1]])
|
11505 | .extentMinor([[-180, -80 - epsilon$1], [180, 80 + epsilon$1]]);
|
11506 | }
|
11507 |
|
11508 | function graticule10() {
|
11509 | return graticule()();
|
11510 | }
|
11511 |
|
11512 | function interpolate(a, b) {
|
11513 | var x0 = a[0] * radians,
|
11514 | y0 = a[1] * radians,
|
11515 | x1 = b[0] * radians,
|
11516 | y1 = b[1] * radians,
|
11517 | cy0 = cos$1(y0),
|
11518 | sy0 = sin$1(y0),
|
11519 | cy1 = cos$1(y1),
|
11520 | sy1 = sin$1(y1),
|
11521 | kx0 = cy0 * cos$1(x0),
|
11522 | ky0 = cy0 * sin$1(x0),
|
11523 | kx1 = cy1 * cos$1(x1),
|
11524 | ky1 = cy1 * sin$1(x1),
|
11525 | d = 2 * asin$1(sqrt$2(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
|
11526 | k = sin$1(d);
|
11527 |
|
11528 | var interpolate = d ? function(t) {
|
11529 | var B = sin$1(t *= d) / k,
|
11530 | A = sin$1(d - t) / k,
|
11531 | x = A * kx0 + B * kx1,
|
11532 | y = A * ky0 + B * ky1,
|
11533 | z = A * sy0 + B * sy1;
|
11534 | return [
|
11535 | atan2$1(y, x) * degrees,
|
11536 | atan2$1(z, sqrt$2(x * x + y * y)) * degrees
|
11537 | ];
|
11538 | } : function() {
|
11539 | return [x0 * degrees, y0 * degrees];
|
11540 | };
|
11541 |
|
11542 | interpolate.distance = d;
|
11543 |
|
11544 | return interpolate;
|
11545 | }
|
11546 |
|
11547 | var identity$5 = x => x;
|
11548 |
|
11549 | var areaSum = new Adder(),
|
11550 | areaRingSum = new Adder(),
|
11551 | x00$2,
|
11552 | y00$2,
|
11553 | x0$3,
|
11554 | y0$3;
|
11555 |
|
11556 | var areaStream = {
|
11557 | point: noop$1,
|
11558 | lineStart: noop$1,
|
11559 | lineEnd: noop$1,
|
11560 | polygonStart: function() {
|
11561 | areaStream.lineStart = areaRingStart;
|
11562 | areaStream.lineEnd = areaRingEnd;
|
11563 | },
|
11564 | polygonEnd: function() {
|
11565 | areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop$1;
|
11566 | areaSum.add(abs$1(areaRingSum));
|
11567 | areaRingSum = new Adder();
|
11568 | },
|
11569 | result: function() {
|
11570 | var area = areaSum / 2;
|
11571 | areaSum = new Adder();
|
11572 | return area;
|
11573 | }
|
11574 | };
|
11575 |
|
11576 | function areaRingStart() {
|
11577 | areaStream.point = areaPointFirst;
|
11578 | }
|
11579 |
|
11580 | function areaPointFirst(x, y) {
|
11581 | areaStream.point = areaPoint;
|
11582 | x00$2 = x0$3 = x, y00$2 = y0$3 = y;
|
11583 | }
|
11584 |
|
11585 | function areaPoint(x, y) {
|
11586 | areaRingSum.add(y0$3 * x - x0$3 * y);
|
11587 | x0$3 = x, y0$3 = y;
|
11588 | }
|
11589 |
|
11590 | function areaRingEnd() {
|
11591 | areaPoint(x00$2, y00$2);
|
11592 | }
|
11593 |
|
11594 | var pathArea = areaStream;
|
11595 |
|
11596 | var x0$2 = Infinity,
|
11597 | y0$2 = x0$2,
|
11598 | x1 = -x0$2,
|
11599 | y1 = x1;
|
11600 |
|
11601 | var boundsStream = {
|
11602 | point: boundsPoint,
|
11603 | lineStart: noop$1,
|
11604 | lineEnd: noop$1,
|
11605 | polygonStart: noop$1,
|
11606 | polygonEnd: noop$1,
|
11607 | result: function() {
|
11608 | var bounds = [[x0$2, y0$2], [x1, y1]];
|
11609 | x1 = y1 = -(y0$2 = x0$2 = Infinity);
|
11610 | return bounds;
|
11611 | }
|
11612 | };
|
11613 |
|
11614 | function boundsPoint(x, y) {
|
11615 | if (x < x0$2) x0$2 = x;
|
11616 | if (x > x1) x1 = x;
|
11617 | if (y < y0$2) y0$2 = y;
|
11618 | if (y > y1) y1 = y;
|
11619 | }
|
11620 |
|
11621 | var boundsStream$1 = boundsStream;
|
11622 |
|
11623 | // TODO Enforce positive area for exterior, negative area for interior?
|
11624 |
|
11625 | var X0 = 0,
|
11626 | Y0 = 0,
|
11627 | Z0 = 0,
|
11628 | X1 = 0,
|
11629 | Y1 = 0,
|
11630 | Z1 = 0,
|
11631 | X2 = 0,
|
11632 | Y2 = 0,
|
11633 | Z2 = 0,
|
11634 | x00$1,
|
11635 | y00$1,
|
11636 | x0$1,
|
11637 | y0$1;
|
11638 |
|
11639 | var centroidStream = {
|
11640 | point: centroidPoint,
|
11641 | lineStart: centroidLineStart,
|
11642 | lineEnd: centroidLineEnd,
|
11643 | polygonStart: function() {
|
11644 | centroidStream.lineStart = centroidRingStart;
|
11645 | centroidStream.lineEnd = centroidRingEnd;
|
11646 | },
|
11647 | polygonEnd: function() {
|
11648 | centroidStream.point = centroidPoint;
|
11649 | centroidStream.lineStart = centroidLineStart;
|
11650 | centroidStream.lineEnd = centroidLineEnd;
|
11651 | },
|
11652 | result: function() {
|
11653 | var centroid = Z2 ? [X2 / Z2, Y2 / Z2]
|
11654 | : Z1 ? [X1 / Z1, Y1 / Z1]
|
11655 | : Z0 ? [X0 / Z0, Y0 / Z0]
|
11656 | : [NaN, NaN];
|
11657 | X0 = Y0 = Z0 =
|
11658 | X1 = Y1 = Z1 =
|
11659 | X2 = Y2 = Z2 = 0;
|
11660 | return centroid;
|
11661 | }
|
11662 | };
|
11663 |
|
11664 | function centroidPoint(x, y) {
|
11665 | X0 += x;
|
11666 | Y0 += y;
|
11667 | ++Z0;
|
11668 | }
|
11669 |
|
11670 | function centroidLineStart() {
|
11671 | centroidStream.point = centroidPointFirstLine;
|
11672 | }
|
11673 |
|
11674 | function centroidPointFirstLine(x, y) {
|
11675 | centroidStream.point = centroidPointLine;
|
11676 | centroidPoint(x0$1 = x, y0$1 = y);
|
11677 | }
|
11678 |
|
11679 | function centroidPointLine(x, y) {
|
11680 | var dx = x - x0$1, dy = y - y0$1, z = sqrt$2(dx * dx + dy * dy);
|
11681 | X1 += z * (x0$1 + x) / 2;
|
11682 | Y1 += z * (y0$1 + y) / 2;
|
11683 | Z1 += z;
|
11684 | centroidPoint(x0$1 = x, y0$1 = y);
|
11685 | }
|
11686 |
|
11687 | function centroidLineEnd() {
|
11688 | centroidStream.point = centroidPoint;
|
11689 | }
|
11690 |
|
11691 | function centroidRingStart() {
|
11692 | centroidStream.point = centroidPointFirstRing;
|
11693 | }
|
11694 |
|
11695 | function centroidRingEnd() {
|
11696 | centroidPointRing(x00$1, y00$1);
|
11697 | }
|
11698 |
|
11699 | function centroidPointFirstRing(x, y) {
|
11700 | centroidStream.point = centroidPointRing;
|
11701 | centroidPoint(x00$1 = x0$1 = x, y00$1 = y0$1 = y);
|
11702 | }
|
11703 |
|
11704 | function centroidPointRing(x, y) {
|
11705 | var dx = x - x0$1,
|
11706 | dy = y - y0$1,
|
11707 | z = sqrt$2(dx * dx + dy * dy);
|
11708 |
|
11709 | X1 += z * (x0$1 + x) / 2;
|
11710 | Y1 += z * (y0$1 + y) / 2;
|
11711 | Z1 += z;
|
11712 |
|
11713 | z = y0$1 * x - x0$1 * y;
|
11714 | X2 += z * (x0$1 + x);
|
11715 | Y2 += z * (y0$1 + y);
|
11716 | Z2 += z * 3;
|
11717 | centroidPoint(x0$1 = x, y0$1 = y);
|
11718 | }
|
11719 |
|
11720 | var pathCentroid = centroidStream;
|
11721 |
|
11722 | function PathContext(context) {
|
11723 | this._context = context;
|
11724 | }
|
11725 |
|
11726 | PathContext.prototype = {
|
11727 | _radius: 4.5,
|
11728 | pointRadius: function(_) {
|
11729 | return this._radius = _, this;
|
11730 | },
|
11731 | polygonStart: function() {
|
11732 | this._line = 0;
|
11733 | },
|
11734 | polygonEnd: function() {
|
11735 | this._line = NaN;
|
11736 | },
|
11737 | lineStart: function() {
|
11738 | this._point = 0;
|
11739 | },
|
11740 | lineEnd: function() {
|
11741 | if (this._line === 0) this._context.closePath();
|
11742 | this._point = NaN;
|
11743 | },
|
11744 | point: function(x, y) {
|
11745 | switch (this._point) {
|
11746 | case 0: {
|
11747 | this._context.moveTo(x, y);
|
11748 | this._point = 1;
|
11749 | break;
|
11750 | }
|
11751 | case 1: {
|
11752 | this._context.lineTo(x, y);
|
11753 | break;
|
11754 | }
|
11755 | default: {
|
11756 | this._context.moveTo(x + this._radius, y);
|
11757 | this._context.arc(x, y, this._radius, 0, tau$1);
|
11758 | break;
|
11759 | }
|
11760 | }
|
11761 | },
|
11762 | result: noop$1
|
11763 | };
|
11764 |
|
11765 | var lengthSum = new Adder(),
|
11766 | lengthRing,
|
11767 | x00,
|
11768 | y00,
|
11769 | x0,
|
11770 | y0;
|
11771 |
|
11772 | var lengthStream = {
|
11773 | point: noop$1,
|
11774 | lineStart: function() {
|
11775 | lengthStream.point = lengthPointFirst;
|
11776 | },
|
11777 | lineEnd: function() {
|
11778 | if (lengthRing) lengthPoint(x00, y00);
|
11779 | lengthStream.point = noop$1;
|
11780 | },
|
11781 | polygonStart: function() {
|
11782 | lengthRing = true;
|
11783 | },
|
11784 | polygonEnd: function() {
|
11785 | lengthRing = null;
|
11786 | },
|
11787 | result: function() {
|
11788 | var length = +lengthSum;
|
11789 | lengthSum = new Adder();
|
11790 | return length;
|
11791 | }
|
11792 | };
|
11793 |
|
11794 | function lengthPointFirst(x, y) {
|
11795 | lengthStream.point = lengthPoint;
|
11796 | x00 = x0 = x, y00 = y0 = y;
|
11797 | }
|
11798 |
|
11799 | function lengthPoint(x, y) {
|
11800 | x0 -= x, y0 -= y;
|
11801 | lengthSum.add(sqrt$2(x0 * x0 + y0 * y0));
|
11802 | x0 = x, y0 = y;
|
11803 | }
|
11804 |
|
11805 | var pathMeasure = lengthStream;
|
11806 |
|
11807 | function PathString() {
|
11808 | this._string = [];
|
11809 | }
|
11810 |
|
11811 | PathString.prototype = {
|
11812 | _radius: 4.5,
|
11813 | _circle: circle$1(4.5),
|
11814 | pointRadius: function(_) {
|
11815 | if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
|
11816 | return this;
|
11817 | },
|
11818 | polygonStart: function() {
|
11819 | this._line = 0;
|
11820 | },
|
11821 | polygonEnd: function() {
|
11822 | this._line = NaN;
|
11823 | },
|
11824 | lineStart: function() {
|
11825 | this._point = 0;
|
11826 | },
|
11827 | lineEnd: function() {
|
11828 | if (this._line === 0) this._string.push("Z");
|
11829 | this._point = NaN;
|
11830 | },
|
11831 | point: function(x, y) {
|
11832 | switch (this._point) {
|
11833 | case 0: {
|
11834 | this._string.push("M", x, ",", y);
|
11835 | this._point = 1;
|
11836 | break;
|
11837 | }
|
11838 | case 1: {
|
11839 | this._string.push("L", x, ",", y);
|
11840 | break;
|
11841 | }
|
11842 | default: {
|
11843 | if (this._circle == null) this._circle = circle$1(this._radius);
|
11844 | this._string.push("M", x, ",", y, this._circle);
|
11845 | break;
|
11846 | }
|
11847 | }
|
11848 | },
|
11849 | result: function() {
|
11850 | if (this._string.length) {
|
11851 | var result = this._string.join("");
|
11852 | this._string = [];
|
11853 | return result;
|
11854 | } else {
|
11855 | return null;
|
11856 | }
|
11857 | }
|
11858 | };
|
11859 |
|
11860 | function circle$1(radius) {
|
11861 | return "m0," + radius
|
11862 | + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
|
11863 | + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
|
11864 | + "z";
|
11865 | }
|
11866 |
|
11867 | function index$2(projection, context) {
|
11868 | var pointRadius = 4.5,
|
11869 | projectionStream,
|
11870 | contextStream;
|
11871 |
|
11872 | function path(object) {
|
11873 | if (object) {
|
11874 | if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
|
11875 | geoStream(object, projectionStream(contextStream));
|
11876 | }
|
11877 | return contextStream.result();
|
11878 | }
|
11879 |
|
11880 | path.area = function(object) {
|
11881 | geoStream(object, projectionStream(pathArea));
|
11882 | return pathArea.result();
|
11883 | };
|
11884 |
|
11885 | path.measure = function(object) {
|
11886 | geoStream(object, projectionStream(pathMeasure));
|
11887 | return pathMeasure.result();
|
11888 | };
|
11889 |
|
11890 | path.bounds = function(object) {
|
11891 | geoStream(object, projectionStream(boundsStream$1));
|
11892 | return boundsStream$1.result();
|
11893 | };
|
11894 |
|
11895 | path.centroid = function(object) {
|
11896 | geoStream(object, projectionStream(pathCentroid));
|
11897 | return pathCentroid.result();
|
11898 | };
|
11899 |
|
11900 | path.projection = function(_) {
|
11901 | return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$5) : (projection = _).stream, path) : projection;
|
11902 | };
|
11903 |
|
11904 | path.context = function(_) {
|
11905 | if (!arguments.length) return context;
|
11906 | contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
|
11907 | if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
|
11908 | return path;
|
11909 | };
|
11910 |
|
11911 | path.pointRadius = function(_) {
|
11912 | if (!arguments.length) return pointRadius;
|
11913 | pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
|
11914 | return path;
|
11915 | };
|
11916 |
|
11917 | return path.projection(projection).context(context);
|
11918 | }
|
11919 |
|
11920 | function transform$1(methods) {
|
11921 | return {
|
11922 | stream: transformer$3(methods)
|
11923 | };
|
11924 | }
|
11925 |
|
11926 | function transformer$3(methods) {
|
11927 | return function(stream) {
|
11928 | var s = new TransformStream;
|
11929 | for (var key in methods) s[key] = methods[key];
|
11930 | s.stream = stream;
|
11931 | return s;
|
11932 | };
|
11933 | }
|
11934 |
|
11935 | function TransformStream() {}
|
11936 |
|
11937 | TransformStream.prototype = {
|
11938 | constructor: TransformStream,
|
11939 | point: function(x, y) { this.stream.point(x, y); },
|
11940 | sphere: function() { this.stream.sphere(); },
|
11941 | lineStart: function() { this.stream.lineStart(); },
|
11942 | lineEnd: function() { this.stream.lineEnd(); },
|
11943 | polygonStart: function() { this.stream.polygonStart(); },
|
11944 | polygonEnd: function() { this.stream.polygonEnd(); }
|
11945 | };
|
11946 |
|
11947 | function fit(projection, fitBounds, object) {
|
11948 | var clip = projection.clipExtent && projection.clipExtent();
|
11949 | projection.scale(150).translate([0, 0]);
|
11950 | if (clip != null) projection.clipExtent(null);
|
11951 | geoStream(object, projection.stream(boundsStream$1));
|
11952 | fitBounds(boundsStream$1.result());
|
11953 | if (clip != null) projection.clipExtent(clip);
|
11954 | return projection;
|
11955 | }
|
11956 |
|
11957 | function fitExtent(projection, extent, object) {
|
11958 | return fit(projection, function(b) {
|
11959 | var w = extent[1][0] - extent[0][0],
|
11960 | h = extent[1][1] - extent[0][1],
|
11961 | k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
|
11962 | x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
|
11963 | y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
|
11964 | projection.scale(150 * k).translate([x, y]);
|
11965 | }, object);
|
11966 | }
|
11967 |
|
11968 | function fitSize(projection, size, object) {
|
11969 | return fitExtent(projection, [[0, 0], size], object);
|
11970 | }
|
11971 |
|
11972 | function fitWidth(projection, width, object) {
|
11973 | return fit(projection, function(b) {
|
11974 | var w = +width,
|
11975 | k = w / (b[1][0] - b[0][0]),
|
11976 | x = (w - k * (b[1][0] + b[0][0])) / 2,
|
11977 | y = -k * b[0][1];
|
11978 | projection.scale(150 * k).translate([x, y]);
|
11979 | }, object);
|
11980 | }
|
11981 |
|
11982 | function fitHeight(projection, height, object) {
|
11983 | return fit(projection, function(b) {
|
11984 | var h = +height,
|
11985 | k = h / (b[1][1] - b[0][1]),
|
11986 | x = -k * b[0][0],
|
11987 | y = (h - k * (b[1][1] + b[0][1])) / 2;
|
11988 | projection.scale(150 * k).translate([x, y]);
|
11989 | }, object);
|
11990 | }
|
11991 |
|
11992 | var maxDepth = 16, // maximum depth of subdivision
|
11993 | cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
|
11994 |
|
11995 | function resample(project, delta2) {
|
11996 | return +delta2 ? resample$1(project, delta2) : resampleNone(project);
|
11997 | }
|
11998 |
|
11999 | function resampleNone(project) {
|
12000 | return transformer$3({
|
12001 | point: function(x, y) {
|
12002 | x = project(x, y);
|
12003 | this.stream.point(x[0], x[1]);
|
12004 | }
|
12005 | });
|
12006 | }
|
12007 |
|
12008 | function resample$1(project, delta2) {
|
12009 |
|
12010 | function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
|
12011 | var dx = x1 - x0,
|
12012 | dy = y1 - y0,
|
12013 | d2 = dx * dx + dy * dy;
|
12014 | if (d2 > 4 * delta2 && depth--) {
|
12015 | var a = a0 + a1,
|
12016 | b = b0 + b1,
|
12017 | c = c0 + c1,
|
12018 | m = sqrt$2(a * a + b * b + c * c),
|
12019 | phi2 = asin$1(c /= m),
|
12020 | lambda2 = abs$1(abs$1(c) - 1) < epsilon$1 || abs$1(lambda0 - lambda1) < epsilon$1 ? (lambda0 + lambda1) / 2 : atan2$1(b, a),
|
12021 | p = project(lambda2, phi2),
|
12022 | x2 = p[0],
|
12023 | y2 = p[1],
|
12024 | dx2 = x2 - x0,
|
12025 | dy2 = y2 - y0,
|
12026 | dz = dy * dx2 - dx * dy2;
|
12027 | if (dz * dz / d2 > delta2 // perpendicular projected distance
|
12028 | || abs$1((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
|
12029 | || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
|
12030 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
|
12031 | stream.point(x2, y2);
|
12032 | resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
|
12033 | }
|
12034 | }
|
12035 | }
|
12036 | return function(stream) {
|
12037 | var lambda00, x00, y00, a00, b00, c00, // first point
|
12038 | lambda0, x0, y0, a0, b0, c0; // previous point
|
12039 |
|
12040 | var resampleStream = {
|
12041 | point: point,
|
12042 | lineStart: lineStart,
|
12043 | lineEnd: lineEnd,
|
12044 | polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
|
12045 | polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
|
12046 | };
|
12047 |
|
12048 | function point(x, y) {
|
12049 | x = project(x, y);
|
12050 | stream.point(x[0], x[1]);
|
12051 | }
|
12052 |
|
12053 | function lineStart() {
|
12054 | x0 = NaN;
|
12055 | resampleStream.point = linePoint;
|
12056 | stream.lineStart();
|
12057 | }
|
12058 |
|
12059 | function linePoint(lambda, phi) {
|
12060 | var c = cartesian([lambda, phi]), p = project(lambda, phi);
|
12061 | 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);
|
12062 | stream.point(x0, y0);
|
12063 | }
|
12064 |
|
12065 | function lineEnd() {
|
12066 | resampleStream.point = point;
|
12067 | stream.lineEnd();
|
12068 | }
|
12069 |
|
12070 | function ringStart() {
|
12071 | lineStart();
|
12072 | resampleStream.point = ringPoint;
|
12073 | resampleStream.lineEnd = ringEnd;
|
12074 | }
|
12075 |
|
12076 | function ringPoint(lambda, phi) {
|
12077 | linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
|
12078 | resampleStream.point = linePoint;
|
12079 | }
|
12080 |
|
12081 | function ringEnd() {
|
12082 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
|
12083 | resampleStream.lineEnd = lineEnd;
|
12084 | lineEnd();
|
12085 | }
|
12086 |
|
12087 | return resampleStream;
|
12088 | };
|
12089 | }
|
12090 |
|
12091 | var transformRadians = transformer$3({
|
12092 | point: function(x, y) {
|
12093 | this.stream.point(x * radians, y * radians);
|
12094 | }
|
12095 | });
|
12096 |
|
12097 | function transformRotate(rotate) {
|
12098 | return transformer$3({
|
12099 | point: function(x, y) {
|
12100 | var r = rotate(x, y);
|
12101 | return this.stream.point(r[0], r[1]);
|
12102 | }
|
12103 | });
|
12104 | }
|
12105 |
|
12106 | function scaleTranslate(k, dx, dy, sx, sy) {
|
12107 | function transform(x, y) {
|
12108 | x *= sx; y *= sy;
|
12109 | return [dx + k * x, dy - k * y];
|
12110 | }
|
12111 | transform.invert = function(x, y) {
|
12112 | return [(x - dx) / k * sx, (dy - y) / k * sy];
|
12113 | };
|
12114 | return transform;
|
12115 | }
|
12116 |
|
12117 | function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {
|
12118 | if (!alpha) return scaleTranslate(k, dx, dy, sx, sy);
|
12119 | var cosAlpha = cos$1(alpha),
|
12120 | sinAlpha = sin$1(alpha),
|
12121 | a = cosAlpha * k,
|
12122 | b = sinAlpha * k,
|
12123 | ai = cosAlpha / k,
|
12124 | bi = sinAlpha / k,
|
12125 | ci = (sinAlpha * dy - cosAlpha * dx) / k,
|
12126 | fi = (sinAlpha * dx + cosAlpha * dy) / k;
|
12127 | function transform(x, y) {
|
12128 | x *= sx; y *= sy;
|
12129 | return [a * x - b * y + dx, dy - b * x - a * y];
|
12130 | }
|
12131 | transform.invert = function(x, y) {
|
12132 | return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];
|
12133 | };
|
12134 | return transform;
|
12135 | }
|
12136 |
|
12137 | function projection(project) {
|
12138 | return projectionMutator(function() { return project; })();
|
12139 | }
|
12140 |
|
12141 | function projectionMutator(projectAt) {
|
12142 | var project,
|
12143 | k = 150, // scale
|
12144 | x = 480, y = 250, // translate
|
12145 | lambda = 0, phi = 0, // center
|
12146 | deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
|
12147 | alpha = 0, // post-rotate angle
|
12148 | sx = 1, // reflectX
|
12149 | sy = 1, // reflectX
|
12150 | theta = null, preclip = clipAntimeridian, // pre-clip angle
|
12151 | x0 = null, y0, x1, y1, postclip = identity$5, // post-clip extent
|
12152 | delta2 = 0.5, // precision
|
12153 | projectResample,
|
12154 | projectTransform,
|
12155 | projectRotateTransform,
|
12156 | cache,
|
12157 | cacheStream;
|
12158 |
|
12159 | function projection(point) {
|
12160 | return projectRotateTransform(point[0] * radians, point[1] * radians);
|
12161 | }
|
12162 |
|
12163 | function invert(point) {
|
12164 | point = projectRotateTransform.invert(point[0], point[1]);
|
12165 | return point && [point[0] * degrees, point[1] * degrees];
|
12166 | }
|
12167 |
|
12168 | projection.stream = function(stream) {
|
12169 | return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
|
12170 | };
|
12171 |
|
12172 | projection.preclip = function(_) {
|
12173 | return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
|
12174 | };
|
12175 |
|
12176 | projection.postclip = function(_) {
|
12177 | return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
|
12178 | };
|
12179 |
|
12180 | projection.clipAngle = function(_) {
|
12181 | return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees;
|
12182 | };
|
12183 |
|
12184 | projection.clipExtent = function(_) {
|
12185 | return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
|
12186 | };
|
12187 |
|
12188 | projection.scale = function(_) {
|
12189 | return arguments.length ? (k = +_, recenter()) : k;
|
12190 | };
|
12191 |
|
12192 | projection.translate = function(_) {
|
12193 | return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
|
12194 | };
|
12195 |
|
12196 | projection.center = function(_) {
|
12197 | return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees];
|
12198 | };
|
12199 |
|
12200 | projection.rotate = function(_) {
|
12201 | return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees, deltaPhi * degrees, deltaGamma * degrees];
|
12202 | };
|
12203 |
|
12204 | projection.angle = function(_) {
|
12205 | return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees;
|
12206 | };
|
12207 |
|
12208 | projection.reflectX = function(_) {
|
12209 | return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;
|
12210 | };
|
12211 |
|
12212 | projection.reflectY = function(_) {
|
12213 | return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;
|
12214 | };
|
12215 |
|
12216 | projection.precision = function(_) {
|
12217 | return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$2(delta2);
|
12218 | };
|
12219 |
|
12220 | projection.fitExtent = function(extent, object) {
|
12221 | return fitExtent(projection, extent, object);
|
12222 | };
|
12223 |
|
12224 | projection.fitSize = function(size, object) {
|
12225 | return fitSize(projection, size, object);
|
12226 | };
|
12227 |
|
12228 | projection.fitWidth = function(width, object) {
|
12229 | return fitWidth(projection, width, object);
|
12230 | };
|
12231 |
|
12232 | projection.fitHeight = function(height, object) {
|
12233 | return fitHeight(projection, height, object);
|
12234 | };
|
12235 |
|
12236 | function recenter() {
|
12237 | var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),
|
12238 | transform = scaleTranslateRotate(k, x - center[0], y - center[1], sx, sy, alpha);
|
12239 | rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
|
12240 | projectTransform = compose(project, transform);
|
12241 | projectRotateTransform = compose(rotate, projectTransform);
|
12242 | projectResample = resample(projectTransform, delta2);
|
12243 | return reset();
|
12244 | }
|
12245 |
|
12246 | function reset() {
|
12247 | cache = cacheStream = null;
|
12248 | return projection;
|
12249 | }
|
12250 |
|
12251 | return function() {
|
12252 | project = projectAt.apply(this, arguments);
|
12253 | projection.invert = project.invert && invert;
|
12254 | return recenter();
|
12255 | };
|
12256 | }
|
12257 |
|
12258 | function conicProjection(projectAt) {
|
12259 | var phi0 = 0,
|
12260 | phi1 = pi$1 / 3,
|
12261 | m = projectionMutator(projectAt),
|
12262 | p = m(phi0, phi1);
|
12263 |
|
12264 | p.parallels = function(_) {
|
12265 | return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees, phi1 * degrees];
|
12266 | };
|
12267 |
|
12268 | return p;
|
12269 | }
|
12270 |
|
12271 | function cylindricalEqualAreaRaw(phi0) {
|
12272 | var cosPhi0 = cos$1(phi0);
|
12273 |
|
12274 | function forward(lambda, phi) {
|
12275 | return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
|
12276 | }
|
12277 |
|
12278 | forward.invert = function(x, y) {
|
12279 | return [x / cosPhi0, asin$1(y * cosPhi0)];
|
12280 | };
|
12281 |
|
12282 | return forward;
|
12283 | }
|
12284 |
|
12285 | function conicEqualAreaRaw(y0, y1) {
|
12286 | var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
|
12287 |
|
12288 | // Are the parallels symmetrical around the Equator?
|
12289 | if (abs$1(n) < epsilon$1) return cylindricalEqualAreaRaw(y0);
|
12290 |
|
12291 | var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt$2(c) / n;
|
12292 |
|
12293 | function project(x, y) {
|
12294 | var r = sqrt$2(c - 2 * n * sin$1(y)) / n;
|
12295 | return [r * sin$1(x *= n), r0 - r * cos$1(x)];
|
12296 | }
|
12297 |
|
12298 | project.invert = function(x, y) {
|
12299 | var r0y = r0 - y,
|
12300 | l = atan2$1(x, abs$1(r0y)) * sign$1(r0y);
|
12301 | if (r0y * n < 0)
|
12302 | l -= pi$1 * sign$1(x) * sign$1(r0y);
|
12303 | return [l / n, asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
|
12304 | };
|
12305 |
|
12306 | return project;
|
12307 | }
|
12308 |
|
12309 | function conicEqualArea() {
|
12310 | return conicProjection(conicEqualAreaRaw)
|
12311 | .scale(155.424)
|
12312 | .center([0, 33.6442]);
|
12313 | }
|
12314 |
|
12315 | function albers() {
|
12316 | return conicEqualArea()
|
12317 | .parallels([29.5, 45.5])
|
12318 | .scale(1070)
|
12319 | .translate([480, 250])
|
12320 | .rotate([96, 0])
|
12321 | .center([-0.6, 38.7]);
|
12322 | }
|
12323 |
|
12324 | // The projections must have mutually exclusive clip regions on the sphere,
|
12325 | // as this will avoid emitting interleaving lines and polygons.
|
12326 | function multiplex(streams) {
|
12327 | var n = streams.length;
|
12328 | return {
|
12329 | point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
|
12330 | sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
|
12331 | lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
|
12332 | lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
|
12333 | polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
|
12334 | polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
|
12335 | };
|
12336 | }
|
12337 |
|
12338 | // A composite projection for the United States, configured by default for
|
12339 | // 960×500. The projection also works quite well at 960×600 if you change the
|
12340 | // scale to 1285 and adjust the translate accordingly. The set of standard
|
12341 | // parallels for each region comes from USGS, which is published here:
|
12342 | // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
|
12343 | function albersUsa() {
|
12344 | var cache,
|
12345 | cacheStream,
|
12346 | lower48 = albers(), lower48Point,
|
12347 | alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
|
12348 | hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
|
12349 | point, pointStream = {point: function(x, y) { point = [x, y]; }};
|
12350 |
|
12351 | function albersUsa(coordinates) {
|
12352 | var x = coordinates[0], y = coordinates[1];
|
12353 | return point = null,
|
12354 | (lower48Point.point(x, y), point)
|
12355 | || (alaskaPoint.point(x, y), point)
|
12356 | || (hawaiiPoint.point(x, y), point);
|
12357 | }
|
12358 |
|
12359 | albersUsa.invert = function(coordinates) {
|
12360 | var k = lower48.scale(),
|
12361 | t = lower48.translate(),
|
12362 | x = (coordinates[0] - t[0]) / k,
|
12363 | y = (coordinates[1] - t[1]) / k;
|
12364 | return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
|
12365 | : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
|
12366 | : lower48).invert(coordinates);
|
12367 | };
|
12368 |
|
12369 | albersUsa.stream = function(stream) {
|
12370 | return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
|
12371 | };
|
12372 |
|
12373 | albersUsa.precision = function(_) {
|
12374 | if (!arguments.length) return lower48.precision();
|
12375 | lower48.precision(_), alaska.precision(_), hawaii.precision(_);
|
12376 | return reset();
|
12377 | };
|
12378 |
|
12379 | albersUsa.scale = function(_) {
|
12380 | if (!arguments.length) return lower48.scale();
|
12381 | lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
|
12382 | return albersUsa.translate(lower48.translate());
|
12383 | };
|
12384 |
|
12385 | albersUsa.translate = function(_) {
|
12386 | if (!arguments.length) return lower48.translate();
|
12387 | var k = lower48.scale(), x = +_[0], y = +_[1];
|
12388 |
|
12389 | lower48Point = lower48
|
12390 | .translate(_)
|
12391 | .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
|
12392 | .stream(pointStream);
|
12393 |
|
12394 | alaskaPoint = alaska
|
12395 | .translate([x - 0.307 * k, y + 0.201 * k])
|
12396 | .clipExtent([[x - 0.425 * k + epsilon$1, y + 0.120 * k + epsilon$1], [x - 0.214 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
|
12397 | .stream(pointStream);
|
12398 |
|
12399 | hawaiiPoint = hawaii
|
12400 | .translate([x - 0.205 * k, y + 0.212 * k])
|
12401 | .clipExtent([[x - 0.214 * k + epsilon$1, y + 0.166 * k + epsilon$1], [x - 0.115 * k - epsilon$1, y + 0.234 * k - epsilon$1]])
|
12402 | .stream(pointStream);
|
12403 |
|
12404 | return reset();
|
12405 | };
|
12406 |
|
12407 | albersUsa.fitExtent = function(extent, object) {
|
12408 | return fitExtent(albersUsa, extent, object);
|
12409 | };
|
12410 |
|
12411 | albersUsa.fitSize = function(size, object) {
|
12412 | return fitSize(albersUsa, size, object);
|
12413 | };
|
12414 |
|
12415 | albersUsa.fitWidth = function(width, object) {
|
12416 | return fitWidth(albersUsa, width, object);
|
12417 | };
|
12418 |
|
12419 | albersUsa.fitHeight = function(height, object) {
|
12420 | return fitHeight(albersUsa, height, object);
|
12421 | };
|
12422 |
|
12423 | function reset() {
|
12424 | cache = cacheStream = null;
|
12425 | return albersUsa;
|
12426 | }
|
12427 |
|
12428 | return albersUsa.scale(1070);
|
12429 | }
|
12430 |
|
12431 | function azimuthalRaw(scale) {
|
12432 | return function(x, y) {
|
12433 | var cx = cos$1(x),
|
12434 | cy = cos$1(y),
|
12435 | k = scale(cx * cy);
|
12436 | if (k === Infinity) return [2, 0];
|
12437 | return [
|
12438 | k * cy * sin$1(x),
|
12439 | k * sin$1(y)
|
12440 | ];
|
12441 | }
|
12442 | }
|
12443 |
|
12444 | function azimuthalInvert(angle) {
|
12445 | return function(x, y) {
|
12446 | var z = sqrt$2(x * x + y * y),
|
12447 | c = angle(z),
|
12448 | sc = sin$1(c),
|
12449 | cc = cos$1(c);
|
12450 | return [
|
12451 | atan2$1(x * sc, z * cc),
|
12452 | asin$1(z && y * sc / z)
|
12453 | ];
|
12454 | }
|
12455 | }
|
12456 |
|
12457 | var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
|
12458 | return sqrt$2(2 / (1 + cxcy));
|
12459 | });
|
12460 |
|
12461 | azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
|
12462 | return 2 * asin$1(z / 2);
|
12463 | });
|
12464 |
|
12465 | function azimuthalEqualArea() {
|
12466 | return projection(azimuthalEqualAreaRaw)
|
12467 | .scale(124.75)
|
12468 | .clipAngle(180 - 1e-3);
|
12469 | }
|
12470 |
|
12471 | var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
|
12472 | return (c = acos$1(c)) && c / sin$1(c);
|
12473 | });
|
12474 |
|
12475 | azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
|
12476 | return z;
|
12477 | });
|
12478 |
|
12479 | function azimuthalEquidistant() {
|
12480 | return projection(azimuthalEquidistantRaw)
|
12481 | .scale(79.4188)
|
12482 | .clipAngle(180 - 1e-3);
|
12483 | }
|
12484 |
|
12485 | function mercatorRaw(lambda, phi) {
|
12486 | return [lambda, log$1(tan((halfPi$1 + phi) / 2))];
|
12487 | }
|
12488 |
|
12489 | mercatorRaw.invert = function(x, y) {
|
12490 | return [x, 2 * atan(exp(y)) - halfPi$1];
|
12491 | };
|
12492 |
|
12493 | function mercator() {
|
12494 | return mercatorProjection(mercatorRaw)
|
12495 | .scale(961 / tau$1);
|
12496 | }
|
12497 |
|
12498 | function mercatorProjection(project) {
|
12499 | var m = projection(project),
|
12500 | center = m.center,
|
12501 | scale = m.scale,
|
12502 | translate = m.translate,
|
12503 | clipExtent = m.clipExtent,
|
12504 | x0 = null, y0, x1, y1; // clip extent
|
12505 |
|
12506 | m.scale = function(_) {
|
12507 | return arguments.length ? (scale(_), reclip()) : scale();
|
12508 | };
|
12509 |
|
12510 | m.translate = function(_) {
|
12511 | return arguments.length ? (translate(_), reclip()) : translate();
|
12512 | };
|
12513 |
|
12514 | m.center = function(_) {
|
12515 | return arguments.length ? (center(_), reclip()) : center();
|
12516 | };
|
12517 |
|
12518 | m.clipExtent = function(_) {
|
12519 | return arguments.length ? ((_ == null ? x0 = y0 = x1 = y1 = null : (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1])), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];
|
12520 | };
|
12521 |
|
12522 | function reclip() {
|
12523 | var k = pi$1 * scale(),
|
12524 | t = m(rotation(m.rotate()).invert([0, 0]));
|
12525 | return clipExtent(x0 == null
|
12526 | ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
|
12527 | ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
|
12528 | : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
|
12529 | }
|
12530 |
|
12531 | return reclip();
|
12532 | }
|
12533 |
|
12534 | function tany(y) {
|
12535 | return tan((halfPi$1 + y) / 2);
|
12536 | }
|
12537 |
|
12538 | function conicConformalRaw(y0, y1) {
|
12539 | var cy0 = cos$1(y0),
|
12540 | n = y0 === y1 ? sin$1(y0) : log$1(cy0 / cos$1(y1)) / log$1(tany(y1) / tany(y0)),
|
12541 | f = cy0 * pow$1(tany(y0), n) / n;
|
12542 |
|
12543 | if (!n) return mercatorRaw;
|
12544 |
|
12545 | function project(x, y) {
|
12546 | if (f > 0) { if (y < -halfPi$1 + epsilon$1) y = -halfPi$1 + epsilon$1; }
|
12547 | else { if (y > halfPi$1 - epsilon$1) y = halfPi$1 - epsilon$1; }
|
12548 | var r = f / pow$1(tany(y), n);
|
12549 | return [r * sin$1(n * x), f - r * cos$1(n * x)];
|
12550 | }
|
12551 |
|
12552 | project.invert = function(x, y) {
|
12553 | var fy = f - y, r = sign$1(n) * sqrt$2(x * x + fy * fy),
|
12554 | l = atan2$1(x, abs$1(fy)) * sign$1(fy);
|
12555 | if (fy * n < 0)
|
12556 | l -= pi$1 * sign$1(x) * sign$1(fy);
|
12557 | return [l / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$1];
|
12558 | };
|
12559 |
|
12560 | return project;
|
12561 | }
|
12562 |
|
12563 | function conicConformal() {
|
12564 | return conicProjection(conicConformalRaw)
|
12565 | .scale(109.5)
|
12566 | .parallels([30, 30]);
|
12567 | }
|
12568 |
|
12569 | function equirectangularRaw(lambda, phi) {
|
12570 | return [lambda, phi];
|
12571 | }
|
12572 |
|
12573 | equirectangularRaw.invert = equirectangularRaw;
|
12574 |
|
12575 | function equirectangular() {
|
12576 | return projection(equirectangularRaw)
|
12577 | .scale(152.63);
|
12578 | }
|
12579 |
|
12580 | function conicEquidistantRaw(y0, y1) {
|
12581 | var cy0 = cos$1(y0),
|
12582 | n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
|
12583 | g = cy0 / n + y0;
|
12584 |
|
12585 | if (abs$1(n) < epsilon$1) return equirectangularRaw;
|
12586 |
|
12587 | function project(x, y) {
|
12588 | var gy = g - y, nx = n * x;
|
12589 | return [gy * sin$1(nx), g - gy * cos$1(nx)];
|
12590 | }
|
12591 |
|
12592 | project.invert = function(x, y) {
|
12593 | var gy = g - y,
|
12594 | l = atan2$1(x, abs$1(gy)) * sign$1(gy);
|
12595 | if (gy * n < 0)
|
12596 | l -= pi$1 * sign$1(x) * sign$1(gy);
|
12597 | return [l / n, g - sign$1(n) * sqrt$2(x * x + gy * gy)];
|
12598 | };
|
12599 |
|
12600 | return project;
|
12601 | }
|
12602 |
|
12603 | function conicEquidistant() {
|
12604 | return conicProjection(conicEquidistantRaw)
|
12605 | .scale(131.154)
|
12606 | .center([0, 13.9389]);
|
12607 | }
|
12608 |
|
12609 | var A1 = 1.340264,
|
12610 | A2 = -0.081106,
|
12611 | A3 = 0.000893,
|
12612 | A4 = 0.003796,
|
12613 | M = sqrt$2(3) / 2,
|
12614 | iterations = 12;
|
12615 |
|
12616 | function equalEarthRaw(lambda, phi) {
|
12617 | var l = asin$1(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
|
12618 | return [
|
12619 | lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
|
12620 | l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
|
12621 | ];
|
12622 | }
|
12623 |
|
12624 | equalEarthRaw.invert = function(x, y) {
|
12625 | var l = y, l2 = l * l, l6 = l2 * l2 * l2;
|
12626 | for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
|
12627 | fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
|
12628 | fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
|
12629 | l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
|
12630 | if (abs$1(delta) < epsilon2) break;
|
12631 | }
|
12632 | return [
|
12633 | M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
|
12634 | asin$1(sin$1(l) / M)
|
12635 | ];
|
12636 | };
|
12637 |
|
12638 | function equalEarth() {
|
12639 | return projection(equalEarthRaw)
|
12640 | .scale(177.158);
|
12641 | }
|
12642 |
|
12643 | function gnomonicRaw(x, y) {
|
12644 | var cy = cos$1(y), k = cos$1(x) * cy;
|
12645 | return [cy * sin$1(x) / k, sin$1(y) / k];
|
12646 | }
|
12647 |
|
12648 | gnomonicRaw.invert = azimuthalInvert(atan);
|
12649 |
|
12650 | function gnomonic() {
|
12651 | return projection(gnomonicRaw)
|
12652 | .scale(144.049)
|
12653 | .clipAngle(60);
|
12654 | }
|
12655 |
|
12656 | function identity$4() {
|
12657 | var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect
|
12658 | alpha = 0, ca, sa, // angle
|
12659 | x0 = null, y0, x1, y1, // clip extent
|
12660 | kx = 1, ky = 1,
|
12661 | transform = transformer$3({
|
12662 | point: function(x, y) {
|
12663 | var p = projection([x, y]);
|
12664 | this.stream.point(p[0], p[1]);
|
12665 | }
|
12666 | }),
|
12667 | postclip = identity$5,
|
12668 | cache,
|
12669 | cacheStream;
|
12670 |
|
12671 | function reset() {
|
12672 | kx = k * sx;
|
12673 | ky = k * sy;
|
12674 | cache = cacheStream = null;
|
12675 | return projection;
|
12676 | }
|
12677 |
|
12678 | function projection (p) {
|
12679 | var x = p[0] * kx, y = p[1] * ky;
|
12680 | if (alpha) {
|
12681 | var t = y * ca - x * sa;
|
12682 | x = x * ca + y * sa;
|
12683 | y = t;
|
12684 | }
|
12685 | return [x + tx, y + ty];
|
12686 | }
|
12687 | projection.invert = function(p) {
|
12688 | var x = p[0] - tx, y = p[1] - ty;
|
12689 | if (alpha) {
|
12690 | var t = y * ca + x * sa;
|
12691 | x = x * ca - y * sa;
|
12692 | y = t;
|
12693 | }
|
12694 | return [x / kx, y / ky];
|
12695 | };
|
12696 | projection.stream = function(stream) {
|
12697 | return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
|
12698 | };
|
12699 | projection.postclip = function(_) {
|
12700 | return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
|
12701 | };
|
12702 | projection.clipExtent = function(_) {
|
12703 | return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
|
12704 | };
|
12705 | projection.scale = function(_) {
|
12706 | return arguments.length ? (k = +_, reset()) : k;
|
12707 | };
|
12708 | projection.translate = function(_) {
|
12709 | return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];
|
12710 | };
|
12711 | projection.angle = function(_) {
|
12712 | return arguments.length ? (alpha = _ % 360 * radians, sa = sin$1(alpha), ca = cos$1(alpha), reset()) : alpha * degrees;
|
12713 | };
|
12714 | projection.reflectX = function(_) {
|
12715 | return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;
|
12716 | };
|
12717 | projection.reflectY = function(_) {
|
12718 | return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;
|
12719 | };
|
12720 | projection.fitExtent = function(extent, object) {
|
12721 | return fitExtent(projection, extent, object);
|
12722 | };
|
12723 | projection.fitSize = function(size, object) {
|
12724 | return fitSize(projection, size, object);
|
12725 | };
|
12726 | projection.fitWidth = function(width, object) {
|
12727 | return fitWidth(projection, width, object);
|
12728 | };
|
12729 | projection.fitHeight = function(height, object) {
|
12730 | return fitHeight(projection, height, object);
|
12731 | };
|
12732 |
|
12733 | return projection;
|
12734 | }
|
12735 |
|
12736 | function naturalEarth1Raw(lambda, phi) {
|
12737 | var phi2 = phi * phi, phi4 = phi2 * phi2;
|
12738 | return [
|
12739 | lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
|
12740 | phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
|
12741 | ];
|
12742 | }
|
12743 |
|
12744 | naturalEarth1Raw.invert = function(x, y) {
|
12745 | var phi = y, i = 25, delta;
|
12746 | do {
|
12747 | var phi2 = phi * phi, phi4 = phi2 * phi2;
|
12748 | phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
|
12749 | (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
|
12750 | } while (abs$1(delta) > epsilon$1 && --i > 0);
|
12751 | return [
|
12752 | x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
|
12753 | phi
|
12754 | ];
|
12755 | };
|
12756 |
|
12757 | function naturalEarth1() {
|
12758 | return projection(naturalEarth1Raw)
|
12759 | .scale(175.295);
|
12760 | }
|
12761 |
|
12762 | function orthographicRaw(x, y) {
|
12763 | return [cos$1(y) * sin$1(x), sin$1(y)];
|
12764 | }
|
12765 |
|
12766 | orthographicRaw.invert = azimuthalInvert(asin$1);
|
12767 |
|
12768 | function orthographic() {
|
12769 | return projection(orthographicRaw)
|
12770 | .scale(249.5)
|
12771 | .clipAngle(90 + epsilon$1);
|
12772 | }
|
12773 |
|
12774 | function stereographicRaw(x, y) {
|
12775 | var cy = cos$1(y), k = 1 + cos$1(x) * cy;
|
12776 | return [cy * sin$1(x) / k, sin$1(y) / k];
|
12777 | }
|
12778 |
|
12779 | stereographicRaw.invert = azimuthalInvert(function(z) {
|
12780 | return 2 * atan(z);
|
12781 | });
|
12782 |
|
12783 | function stereographic() {
|
12784 | return projection(stereographicRaw)
|
12785 | .scale(250)
|
12786 | .clipAngle(142);
|
12787 | }
|
12788 |
|
12789 | function transverseMercatorRaw(lambda, phi) {
|
12790 | return [log$1(tan((halfPi$1 + phi) / 2)), -lambda];
|
12791 | }
|
12792 |
|
12793 | transverseMercatorRaw.invert = function(x, y) {
|
12794 | return [-y, 2 * atan(exp(x)) - halfPi$1];
|
12795 | };
|
12796 |
|
12797 | function transverseMercator() {
|
12798 | var m = mercatorProjection(transverseMercatorRaw),
|
12799 | center = m.center,
|
12800 | rotate = m.rotate;
|
12801 |
|
12802 | m.center = function(_) {
|
12803 | return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
|
12804 | };
|
12805 |
|
12806 | m.rotate = function(_) {
|
12807 | return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
|
12808 | };
|
12809 |
|
12810 | return rotate([0, 0, 90])
|
12811 | .scale(159.155);
|
12812 | }
|
12813 |
|
12814 | function defaultSeparation$1(a, b) {
|
12815 | return a.parent === b.parent ? 1 : 2;
|
12816 | }
|
12817 |
|
12818 | function meanX(children) {
|
12819 | return children.reduce(meanXReduce, 0) / children.length;
|
12820 | }
|
12821 |
|
12822 | function meanXReduce(x, c) {
|
12823 | return x + c.x;
|
12824 | }
|
12825 |
|
12826 | function maxY(children) {
|
12827 | return 1 + children.reduce(maxYReduce, 0);
|
12828 | }
|
12829 |
|
12830 | function maxYReduce(y, c) {
|
12831 | return Math.max(y, c.y);
|
12832 | }
|
12833 |
|
12834 | function leafLeft(node) {
|
12835 | var children;
|
12836 | while (children = node.children) node = children[0];
|
12837 | return node;
|
12838 | }
|
12839 |
|
12840 | function leafRight(node) {
|
12841 | var children;
|
12842 | while (children = node.children) node = children[children.length - 1];
|
12843 | return node;
|
12844 | }
|
12845 |
|
12846 | function cluster() {
|
12847 | var separation = defaultSeparation$1,
|
12848 | dx = 1,
|
12849 | dy = 1,
|
12850 | nodeSize = false;
|
12851 |
|
12852 | function cluster(root) {
|
12853 | var previousNode,
|
12854 | x = 0;
|
12855 |
|
12856 | // First walk, computing the initial x & y values.
|
12857 | root.eachAfter(function(node) {
|
12858 | var children = node.children;
|
12859 | if (children) {
|
12860 | node.x = meanX(children);
|
12861 | node.y = maxY(children);
|
12862 | } else {
|
12863 | node.x = previousNode ? x += separation(node, previousNode) : 0;
|
12864 | node.y = 0;
|
12865 | previousNode = node;
|
12866 | }
|
12867 | });
|
12868 |
|
12869 | var left = leafLeft(root),
|
12870 | right = leafRight(root),
|
12871 | x0 = left.x - separation(left, right) / 2,
|
12872 | x1 = right.x + separation(right, left) / 2;
|
12873 |
|
12874 | // Second walk, normalizing x & y to the desired size.
|
12875 | return root.eachAfter(nodeSize ? function(node) {
|
12876 | node.x = (node.x - root.x) * dx;
|
12877 | node.y = (root.y - node.y) * dy;
|
12878 | } : function(node) {
|
12879 | node.x = (node.x - x0) / (x1 - x0) * dx;
|
12880 | node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
|
12881 | });
|
12882 | }
|
12883 |
|
12884 | cluster.separation = function(x) {
|
12885 | return arguments.length ? (separation = x, cluster) : separation;
|
12886 | };
|
12887 |
|
12888 | cluster.size = function(x) {
|
12889 | return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
|
12890 | };
|
12891 |
|
12892 | cluster.nodeSize = function(x) {
|
12893 | return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
|
12894 | };
|
12895 |
|
12896 | return cluster;
|
12897 | }
|
12898 |
|
12899 | function count(node) {
|
12900 | var sum = 0,
|
12901 | children = node.children,
|
12902 | i = children && children.length;
|
12903 | if (!i) sum = 1;
|
12904 | else while (--i >= 0) sum += children[i].value;
|
12905 | node.value = sum;
|
12906 | }
|
12907 |
|
12908 | function node_count() {
|
12909 | return this.eachAfter(count);
|
12910 | }
|
12911 |
|
12912 | function node_each(callback, that) {
|
12913 | let index = -1;
|
12914 | for (const node of this) {
|
12915 | callback.call(that, node, ++index, this);
|
12916 | }
|
12917 | return this;
|
12918 | }
|
12919 |
|
12920 | function node_eachBefore(callback, that) {
|
12921 | var node = this, nodes = [node], children, i, index = -1;
|
12922 | while (node = nodes.pop()) {
|
12923 | callback.call(that, node, ++index, this);
|
12924 | if (children = node.children) {
|
12925 | for (i = children.length - 1; i >= 0; --i) {
|
12926 | nodes.push(children[i]);
|
12927 | }
|
12928 | }
|
12929 | }
|
12930 | return this;
|
12931 | }
|
12932 |
|
12933 | function node_eachAfter(callback, that) {
|
12934 | var node = this, nodes = [node], next = [], children, i, n, index = -1;
|
12935 | while (node = nodes.pop()) {
|
12936 | next.push(node);
|
12937 | if (children = node.children) {
|
12938 | for (i = 0, n = children.length; i < n; ++i) {
|
12939 | nodes.push(children[i]);
|
12940 | }
|
12941 | }
|
12942 | }
|
12943 | while (node = next.pop()) {
|
12944 | callback.call(that, node, ++index, this);
|
12945 | }
|
12946 | return this;
|
12947 | }
|
12948 |
|
12949 | function node_find(callback, that) {
|
12950 | let index = -1;
|
12951 | for (const node of this) {
|
12952 | if (callback.call(that, node, ++index, this)) {
|
12953 | return node;
|
12954 | }
|
12955 | }
|
12956 | }
|
12957 |
|
12958 | function node_sum(value) {
|
12959 | return this.eachAfter(function(node) {
|
12960 | var sum = +value(node.data) || 0,
|
12961 | children = node.children,
|
12962 | i = children && children.length;
|
12963 | while (--i >= 0) sum += children[i].value;
|
12964 | node.value = sum;
|
12965 | });
|
12966 | }
|
12967 |
|
12968 | function node_sort(compare) {
|
12969 | return this.eachBefore(function(node) {
|
12970 | if (node.children) {
|
12971 | node.children.sort(compare);
|
12972 | }
|
12973 | });
|
12974 | }
|
12975 |
|
12976 | function node_path(end) {
|
12977 | var start = this,
|
12978 | ancestor = leastCommonAncestor(start, end),
|
12979 | nodes = [start];
|
12980 | while (start !== ancestor) {
|
12981 | start = start.parent;
|
12982 | nodes.push(start);
|
12983 | }
|
12984 | var k = nodes.length;
|
12985 | while (end !== ancestor) {
|
12986 | nodes.splice(k, 0, end);
|
12987 | end = end.parent;
|
12988 | }
|
12989 | return nodes;
|
12990 | }
|
12991 |
|
12992 | function leastCommonAncestor(a, b) {
|
12993 | if (a === b) return a;
|
12994 | var aNodes = a.ancestors(),
|
12995 | bNodes = b.ancestors(),
|
12996 | c = null;
|
12997 | a = aNodes.pop();
|
12998 | b = bNodes.pop();
|
12999 | while (a === b) {
|
13000 | c = a;
|
13001 | a = aNodes.pop();
|
13002 | b = bNodes.pop();
|
13003 | }
|
13004 | return c;
|
13005 | }
|
13006 |
|
13007 | function node_ancestors() {
|
13008 | var node = this, nodes = [node];
|
13009 | while (node = node.parent) {
|
13010 | nodes.push(node);
|
13011 | }
|
13012 | return nodes;
|
13013 | }
|
13014 |
|
13015 | function node_descendants() {
|
13016 | return Array.from(this);
|
13017 | }
|
13018 |
|
13019 | function node_leaves() {
|
13020 | var leaves = [];
|
13021 | this.eachBefore(function(node) {
|
13022 | if (!node.children) {
|
13023 | leaves.push(node);
|
13024 | }
|
13025 | });
|
13026 | return leaves;
|
13027 | }
|
13028 |
|
13029 | function node_links() {
|
13030 | var root = this, links = [];
|
13031 | root.each(function(node) {
|
13032 | if (node !== root) { // Don’t include the root’s parent, if any.
|
13033 | links.push({source: node.parent, target: node});
|
13034 | }
|
13035 | });
|
13036 | return links;
|
13037 | }
|
13038 |
|
13039 | function* node_iterator() {
|
13040 | var node = this, current, next = [node], children, i, n;
|
13041 | do {
|
13042 | current = next.reverse(), next = [];
|
13043 | while (node = current.pop()) {
|
13044 | yield node;
|
13045 | if (children = node.children) {
|
13046 | for (i = 0, n = children.length; i < n; ++i) {
|
13047 | next.push(children[i]);
|
13048 | }
|
13049 | }
|
13050 | }
|
13051 | } while (next.length);
|
13052 | }
|
13053 |
|
13054 | function hierarchy(data, children) {
|
13055 | if (data instanceof Map) {
|
13056 | data = [undefined, data];
|
13057 | if (children === undefined) children = mapChildren;
|
13058 | } else if (children === undefined) {
|
13059 | children = objectChildren;
|
13060 | }
|
13061 |
|
13062 | var root = new Node$1(data),
|
13063 | node,
|
13064 | nodes = [root],
|
13065 | child,
|
13066 | childs,
|
13067 | i,
|
13068 | n;
|
13069 |
|
13070 | while (node = nodes.pop()) {
|
13071 | if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
|
13072 | node.children = childs;
|
13073 | for (i = n - 1; i >= 0; --i) {
|
13074 | nodes.push(child = childs[i] = new Node$1(childs[i]));
|
13075 | child.parent = node;
|
13076 | child.depth = node.depth + 1;
|
13077 | }
|
13078 | }
|
13079 | }
|
13080 |
|
13081 | return root.eachBefore(computeHeight);
|
13082 | }
|
13083 |
|
13084 | function node_copy() {
|
13085 | return hierarchy(this).eachBefore(copyData);
|
13086 | }
|
13087 |
|
13088 | function objectChildren(d) {
|
13089 | return d.children;
|
13090 | }
|
13091 |
|
13092 | function mapChildren(d) {
|
13093 | return Array.isArray(d) ? d[1] : null;
|
13094 | }
|
13095 |
|
13096 | function copyData(node) {
|
13097 | if (node.data.value !== undefined) node.value = node.data.value;
|
13098 | node.data = node.data.data;
|
13099 | }
|
13100 |
|
13101 | function computeHeight(node) {
|
13102 | var height = 0;
|
13103 | do node.height = height;
|
13104 | while ((node = node.parent) && (node.height < ++height));
|
13105 | }
|
13106 |
|
13107 | function Node$1(data) {
|
13108 | this.data = data;
|
13109 | this.depth =
|
13110 | this.height = 0;
|
13111 | this.parent = null;
|
13112 | }
|
13113 |
|
13114 | Node$1.prototype = hierarchy.prototype = {
|
13115 | constructor: Node$1,
|
13116 | count: node_count,
|
13117 | each: node_each,
|
13118 | eachAfter: node_eachAfter,
|
13119 | eachBefore: node_eachBefore,
|
13120 | find: node_find,
|
13121 | sum: node_sum,
|
13122 | sort: node_sort,
|
13123 | path: node_path,
|
13124 | ancestors: node_ancestors,
|
13125 | descendants: node_descendants,
|
13126 | leaves: node_leaves,
|
13127 | links: node_links,
|
13128 | copy: node_copy,
|
13129 | [Symbol.iterator]: node_iterator
|
13130 | };
|
13131 |
|
13132 | function optional(f) {
|
13133 | return f == null ? null : required(f);
|
13134 | }
|
13135 |
|
13136 | function required(f) {
|
13137 | if (typeof f !== "function") throw new Error;
|
13138 | return f;
|
13139 | }
|
13140 |
|
13141 | function constantZero() {
|
13142 | return 0;
|
13143 | }
|
13144 |
|
13145 | function constant$2(x) {
|
13146 | return function() {
|
13147 | return x;
|
13148 | };
|
13149 | }
|
13150 |
|
13151 | // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
|
13152 | const a$1 = 1664525;
|
13153 | const c$3 = 1013904223;
|
13154 | const m = 4294967296; // 2^32
|
13155 |
|
13156 | function lcg$1() {
|
13157 | let s = 1;
|
13158 | return () => (s = (a$1 * s + c$3) % m) / m;
|
13159 | }
|
13160 |
|
13161 | function array$1(x) {
|
13162 | return typeof x === "object" && "length" in x
|
13163 | ? x // Array, TypedArray, NodeList, array-like
|
13164 | : Array.from(x); // Map, Set, iterable, string, or anything else
|
13165 | }
|
13166 |
|
13167 | function shuffle(array, random) {
|
13168 | let m = array.length,
|
13169 | t,
|
13170 | i;
|
13171 |
|
13172 | while (m) {
|
13173 | i = random() * m-- | 0;
|
13174 | t = array[m];
|
13175 | array[m] = array[i];
|
13176 | array[i] = t;
|
13177 | }
|
13178 |
|
13179 | return array;
|
13180 | }
|
13181 |
|
13182 | function enclose(circles) {
|
13183 | return packEncloseRandom(circles, lcg$1());
|
13184 | }
|
13185 |
|
13186 | function packEncloseRandom(circles, random) {
|
13187 | var i = 0, n = (circles = shuffle(Array.from(circles), random)).length, B = [], p, e;
|
13188 |
|
13189 | while (i < n) {
|
13190 | p = circles[i];
|
13191 | if (e && enclosesWeak(e, p)) ++i;
|
13192 | else e = encloseBasis(B = extendBasis(B, p)), i = 0;
|
13193 | }
|
13194 |
|
13195 | return e;
|
13196 | }
|
13197 |
|
13198 | function extendBasis(B, p) {
|
13199 | var i, j;
|
13200 |
|
13201 | if (enclosesWeakAll(p, B)) return [p];
|
13202 |
|
13203 | // If we get here then B must have at least one element.
|
13204 | for (i = 0; i < B.length; ++i) {
|
13205 | if (enclosesNot(p, B[i])
|
13206 | && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
|
13207 | return [B[i], p];
|
13208 | }
|
13209 | }
|
13210 |
|
13211 | // If we get here then B must have at least two elements.
|
13212 | for (i = 0; i < B.length - 1; ++i) {
|
13213 | for (j = i + 1; j < B.length; ++j) {
|
13214 | if (enclosesNot(encloseBasis2(B[i], B[j]), p)
|
13215 | && enclosesNot(encloseBasis2(B[i], p), B[j])
|
13216 | && enclosesNot(encloseBasis2(B[j], p), B[i])
|
13217 | && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
|
13218 | return [B[i], B[j], p];
|
13219 | }
|
13220 | }
|
13221 | }
|
13222 |
|
13223 | // If we get here then something is very wrong.
|
13224 | throw new Error;
|
13225 | }
|
13226 |
|
13227 | function enclosesNot(a, b) {
|
13228 | var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
|
13229 | return dr < 0 || dr * dr < dx * dx + dy * dy;
|
13230 | }
|
13231 |
|
13232 | function enclosesWeak(a, b) {
|
13233 | var dr = a.r - b.r + Math.max(a.r, b.r, 1) * 1e-9, dx = b.x - a.x, dy = b.y - a.y;
|
13234 | return dr > 0 && dr * dr > dx * dx + dy * dy;
|
13235 | }
|
13236 |
|
13237 | function enclosesWeakAll(a, B) {
|
13238 | for (var i = 0; i < B.length; ++i) {
|
13239 | if (!enclosesWeak(a, B[i])) {
|
13240 | return false;
|
13241 | }
|
13242 | }
|
13243 | return true;
|
13244 | }
|
13245 |
|
13246 | function encloseBasis(B) {
|
13247 | switch (B.length) {
|
13248 | case 1: return encloseBasis1(B[0]);
|
13249 | case 2: return encloseBasis2(B[0], B[1]);
|
13250 | case 3: return encloseBasis3(B[0], B[1], B[2]);
|
13251 | }
|
13252 | }
|
13253 |
|
13254 | function encloseBasis1(a) {
|
13255 | return {
|
13256 | x: a.x,
|
13257 | y: a.y,
|
13258 | r: a.r
|
13259 | };
|
13260 | }
|
13261 |
|
13262 | function encloseBasis2(a, b) {
|
13263 | var x1 = a.x, y1 = a.y, r1 = a.r,
|
13264 | x2 = b.x, y2 = b.y, r2 = b.r,
|
13265 | x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
|
13266 | l = Math.sqrt(x21 * x21 + y21 * y21);
|
13267 | return {
|
13268 | x: (x1 + x2 + x21 / l * r21) / 2,
|
13269 | y: (y1 + y2 + y21 / l * r21) / 2,
|
13270 | r: (l + r1 + r2) / 2
|
13271 | };
|
13272 | }
|
13273 |
|
13274 | function encloseBasis3(a, b, c) {
|
13275 | var x1 = a.x, y1 = a.y, r1 = a.r,
|
13276 | x2 = b.x, y2 = b.y, r2 = b.r,
|
13277 | x3 = c.x, y3 = c.y, r3 = c.r,
|
13278 | a2 = x1 - x2,
|
13279 | a3 = x1 - x3,
|
13280 | b2 = y1 - y2,
|
13281 | b3 = y1 - y3,
|
13282 | c2 = r2 - r1,
|
13283 | c3 = r3 - r1,
|
13284 | d1 = x1 * x1 + y1 * y1 - r1 * r1,
|
13285 | d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
|
13286 | d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
|
13287 | ab = a3 * b2 - a2 * b3,
|
13288 | xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
|
13289 | xb = (b3 * c2 - b2 * c3) / ab,
|
13290 | ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
|
13291 | yb = (a2 * c3 - a3 * c2) / ab,
|
13292 | A = xb * xb + yb * yb - 1,
|
13293 | B = 2 * (r1 + xa * xb + ya * yb),
|
13294 | C = xa * xa + ya * ya - r1 * r1,
|
13295 | r = -(Math.abs(A) > 1e-6 ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
|
13296 | return {
|
13297 | x: x1 + xa + xb * r,
|
13298 | y: y1 + ya + yb * r,
|
13299 | r: r
|
13300 | };
|
13301 | }
|
13302 |
|
13303 | function place(b, a, c) {
|
13304 | var dx = b.x - a.x, x, a2,
|
13305 | dy = b.y - a.y, y, b2,
|
13306 | d2 = dx * dx + dy * dy;
|
13307 | if (d2) {
|
13308 | a2 = a.r + c.r, a2 *= a2;
|
13309 | b2 = b.r + c.r, b2 *= b2;
|
13310 | if (a2 > b2) {
|
13311 | x = (d2 + b2 - a2) / (2 * d2);
|
13312 | y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
|
13313 | c.x = b.x - x * dx - y * dy;
|
13314 | c.y = b.y - x * dy + y * dx;
|
13315 | } else {
|
13316 | x = (d2 + a2 - b2) / (2 * d2);
|
13317 | y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
|
13318 | c.x = a.x + x * dx - y * dy;
|
13319 | c.y = a.y + x * dy + y * dx;
|
13320 | }
|
13321 | } else {
|
13322 | c.x = a.x + c.r;
|
13323 | c.y = a.y;
|
13324 | }
|
13325 | }
|
13326 |
|
13327 | function intersects(a, b) {
|
13328 | var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
|
13329 | return dr > 0 && dr * dr > dx * dx + dy * dy;
|
13330 | }
|
13331 |
|
13332 | function score(node) {
|
13333 | var a = node._,
|
13334 | b = node.next._,
|
13335 | ab = a.r + b.r,
|
13336 | dx = (a.x * b.r + b.x * a.r) / ab,
|
13337 | dy = (a.y * b.r + b.y * a.r) / ab;
|
13338 | return dx * dx + dy * dy;
|
13339 | }
|
13340 |
|
13341 | function Node(circle) {
|
13342 | this._ = circle;
|
13343 | this.next = null;
|
13344 | this.previous = null;
|
13345 | }
|
13346 |
|
13347 | function packSiblingsRandom(circles, random) {
|
13348 | if (!(n = (circles = array$1(circles)).length)) return 0;
|
13349 |
|
13350 | var a, b, c, n, aa, ca, i, j, k, sj, sk;
|
13351 |
|
13352 | // Place the first circle.
|
13353 | a = circles[0], a.x = 0, a.y = 0;
|
13354 | if (!(n > 1)) return a.r;
|
13355 |
|
13356 | // Place the second circle.
|
13357 | b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
|
13358 | if (!(n > 2)) return a.r + b.r;
|
13359 |
|
13360 | // Place the third circle.
|
13361 | place(b, a, c = circles[2]);
|
13362 |
|
13363 | // Initialize the front-chain using the first three circles a, b and c.
|
13364 | a = new Node(a), b = new Node(b), c = new Node(c);
|
13365 | a.next = c.previous = b;
|
13366 | b.next = a.previous = c;
|
13367 | c.next = b.previous = a;
|
13368 |
|
13369 | // Attempt to place each remaining circle…
|
13370 | pack: for (i = 3; i < n; ++i) {
|
13371 | place(a._, b._, c = circles[i]), c = new Node(c);
|
13372 |
|
13373 | // Find the closest intersecting circle on the front-chain, if any.
|
13374 | // “Closeness” is determined by linear distance along the front-chain.
|
13375 | // “Ahead” or “behind” is likewise determined by linear distance.
|
13376 | j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
|
13377 | do {
|
13378 | if (sj <= sk) {
|
13379 | if (intersects(j._, c._)) {
|
13380 | b = j, a.next = b, b.previous = a, --i;
|
13381 | continue pack;
|
13382 | }
|
13383 | sj += j._.r, j = j.next;
|
13384 | } else {
|
13385 | if (intersects(k._, c._)) {
|
13386 | a = k, a.next = b, b.previous = a, --i;
|
13387 | continue pack;
|
13388 | }
|
13389 | sk += k._.r, k = k.previous;
|
13390 | }
|
13391 | } while (j !== k.next);
|
13392 |
|
13393 | // Success! Insert the new circle c between a and b.
|
13394 | c.previous = a, c.next = b, a.next = b.previous = b = c;
|
13395 |
|
13396 | // Compute the new closest circle pair to the centroid.
|
13397 | aa = score(a);
|
13398 | while ((c = c.next) !== b) {
|
13399 | if ((ca = score(c)) < aa) {
|
13400 | a = c, aa = ca;
|
13401 | }
|
13402 | }
|
13403 | b = a.next;
|
13404 | }
|
13405 |
|
13406 | // Compute the enclosing circle of the front chain.
|
13407 | a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = packEncloseRandom(a, random);
|
13408 |
|
13409 | // Translate the circles to put the enclosing circle around the origin.
|
13410 | for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
|
13411 |
|
13412 | return c.r;
|
13413 | }
|
13414 |
|
13415 | function siblings(circles) {
|
13416 | packSiblingsRandom(circles, lcg$1());
|
13417 | return circles;
|
13418 | }
|
13419 |
|
13420 | function defaultRadius(d) {
|
13421 | return Math.sqrt(d.value);
|
13422 | }
|
13423 |
|
13424 | function index$1() {
|
13425 | var radius = null,
|
13426 | dx = 1,
|
13427 | dy = 1,
|
13428 | padding = constantZero;
|
13429 |
|
13430 | function pack(root) {
|
13431 | const random = lcg$1();
|
13432 | root.x = dx / 2, root.y = dy / 2;
|
13433 | if (radius) {
|
13434 | root.eachBefore(radiusLeaf(radius))
|
13435 | .eachAfter(packChildrenRandom(padding, 0.5, random))
|
13436 | .eachBefore(translateChild(1));
|
13437 | } else {
|
13438 | root.eachBefore(radiusLeaf(defaultRadius))
|
13439 | .eachAfter(packChildrenRandom(constantZero, 1, random))
|
13440 | .eachAfter(packChildrenRandom(padding, root.r / Math.min(dx, dy), random))
|
13441 | .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
|
13442 | }
|
13443 | return root;
|
13444 | }
|
13445 |
|
13446 | pack.radius = function(x) {
|
13447 | return arguments.length ? (radius = optional(x), pack) : radius;
|
13448 | };
|
13449 |
|
13450 | pack.size = function(x) {
|
13451 | return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
|
13452 | };
|
13453 |
|
13454 | pack.padding = function(x) {
|
13455 | return arguments.length ? (padding = typeof x === "function" ? x : constant$2(+x), pack) : padding;
|
13456 | };
|
13457 |
|
13458 | return pack;
|
13459 | }
|
13460 |
|
13461 | function radiusLeaf(radius) {
|
13462 | return function(node) {
|
13463 | if (!node.children) {
|
13464 | node.r = Math.max(0, +radius(node) || 0);
|
13465 | }
|
13466 | };
|
13467 | }
|
13468 |
|
13469 | function packChildrenRandom(padding, k, random) {
|
13470 | return function(node) {
|
13471 | if (children = node.children) {
|
13472 | var children,
|
13473 | i,
|
13474 | n = children.length,
|
13475 | r = padding(node) * k || 0,
|
13476 | e;
|
13477 |
|
13478 | if (r) for (i = 0; i < n; ++i) children[i].r += r;
|
13479 | e = packSiblingsRandom(children, random);
|
13480 | if (r) for (i = 0; i < n; ++i) children[i].r -= r;
|
13481 | node.r = e + r;
|
13482 | }
|
13483 | };
|
13484 | }
|
13485 |
|
13486 | function translateChild(k) {
|
13487 | return function(node) {
|
13488 | var parent = node.parent;
|
13489 | node.r *= k;
|
13490 | if (parent) {
|
13491 | node.x = parent.x + k * node.x;
|
13492 | node.y = parent.y + k * node.y;
|
13493 | }
|
13494 | };
|
13495 | }
|
13496 |
|
13497 | function roundNode(node) {
|
13498 | node.x0 = Math.round(node.x0);
|
13499 | node.y0 = Math.round(node.y0);
|
13500 | node.x1 = Math.round(node.x1);
|
13501 | node.y1 = Math.round(node.y1);
|
13502 | }
|
13503 |
|
13504 | function treemapDice(parent, x0, y0, x1, y1) {
|
13505 | var nodes = parent.children,
|
13506 | node,
|
13507 | i = -1,
|
13508 | n = nodes.length,
|
13509 | k = parent.value && (x1 - x0) / parent.value;
|
13510 |
|
13511 | while (++i < n) {
|
13512 | node = nodes[i], node.y0 = y0, node.y1 = y1;
|
13513 | node.x0 = x0, node.x1 = x0 += node.value * k;
|
13514 | }
|
13515 | }
|
13516 |
|
13517 | function partition() {
|
13518 | var dx = 1,
|
13519 | dy = 1,
|
13520 | padding = 0,
|
13521 | round = false;
|
13522 |
|
13523 | function partition(root) {
|
13524 | var n = root.height + 1;
|
13525 | root.x0 =
|
13526 | root.y0 = padding;
|
13527 | root.x1 = dx;
|
13528 | root.y1 = dy / n;
|
13529 | root.eachBefore(positionNode(dy, n));
|
13530 | if (round) root.eachBefore(roundNode);
|
13531 | return root;
|
13532 | }
|
13533 |
|
13534 | function positionNode(dy, n) {
|
13535 | return function(node) {
|
13536 | if (node.children) {
|
13537 | treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
|
13538 | }
|
13539 | var x0 = node.x0,
|
13540 | y0 = node.y0,
|
13541 | x1 = node.x1 - padding,
|
13542 | y1 = node.y1 - padding;
|
13543 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
13544 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
13545 | node.x0 = x0;
|
13546 | node.y0 = y0;
|
13547 | node.x1 = x1;
|
13548 | node.y1 = y1;
|
13549 | };
|
13550 | }
|
13551 |
|
13552 | partition.round = function(x) {
|
13553 | return arguments.length ? (round = !!x, partition) : round;
|
13554 | };
|
13555 |
|
13556 | partition.size = function(x) {
|
13557 | return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
|
13558 | };
|
13559 |
|
13560 | partition.padding = function(x) {
|
13561 | return arguments.length ? (padding = +x, partition) : padding;
|
13562 | };
|
13563 |
|
13564 | return partition;
|
13565 | }
|
13566 |
|
13567 | var preroot = {depth: -1},
|
13568 | ambiguous = {},
|
13569 | imputed = {};
|
13570 |
|
13571 | function defaultId(d) {
|
13572 | return d.id;
|
13573 | }
|
13574 |
|
13575 | function defaultParentId(d) {
|
13576 | return d.parentId;
|
13577 | }
|
13578 |
|
13579 | function stratify() {
|
13580 | var id = defaultId,
|
13581 | parentId = defaultParentId,
|
13582 | path;
|
13583 |
|
13584 | function stratify(data) {
|
13585 | var nodes = Array.from(data),
|
13586 | currentId = id,
|
13587 | currentParentId = parentId,
|
13588 | n,
|
13589 | d,
|
13590 | i,
|
13591 | root,
|
13592 | parent,
|
13593 | node,
|
13594 | nodeId,
|
13595 | nodeKey,
|
13596 | nodeByKey = new Map;
|
13597 |
|
13598 | if (path != null) {
|
13599 | const I = nodes.map((d, i) => normalize$1(path(d, i, data)));
|
13600 | const P = I.map(parentof);
|
13601 | const S = new Set(I).add("");
|
13602 | for (const i of P) {
|
13603 | if (!S.has(i)) {
|
13604 | S.add(i);
|
13605 | I.push(i);
|
13606 | P.push(parentof(i));
|
13607 | nodes.push(imputed);
|
13608 | }
|
13609 | }
|
13610 | currentId = (_, i) => I[i];
|
13611 | currentParentId = (_, i) => P[i];
|
13612 | }
|
13613 |
|
13614 | for (i = 0, n = nodes.length; i < n; ++i) {
|
13615 | d = nodes[i], node = nodes[i] = new Node$1(d);
|
13616 | if ((nodeId = currentId(d, i, data)) != null && (nodeId += "")) {
|
13617 | nodeKey = node.id = nodeId;
|
13618 | nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
|
13619 | }
|
13620 | if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += "")) {
|
13621 | node.parent = nodeId;
|
13622 | }
|
13623 | }
|
13624 |
|
13625 | for (i = 0; i < n; ++i) {
|
13626 | node = nodes[i];
|
13627 | if (nodeId = node.parent) {
|
13628 | parent = nodeByKey.get(nodeId);
|
13629 | if (!parent) throw new Error("missing: " + nodeId);
|
13630 | if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
|
13631 | if (parent.children) parent.children.push(node);
|
13632 | else parent.children = [node];
|
13633 | node.parent = parent;
|
13634 | } else {
|
13635 | if (root) throw new Error("multiple roots");
|
13636 | root = node;
|
13637 | }
|
13638 | }
|
13639 |
|
13640 | if (!root) throw new Error("no root");
|
13641 |
|
13642 | // When imputing internal nodes, only introduce roots if needed.
|
13643 | // Then replace the imputed marker data with null.
|
13644 | if (path != null) {
|
13645 | while (root.data === imputed && root.children.length === 1) {
|
13646 | root = root.children[0], --n;
|
13647 | }
|
13648 | for (let i = nodes.length - 1; i >= 0; --i) {
|
13649 | node = nodes[i];
|
13650 | if (node.data !== imputed) break;
|
13651 | node.data = null;
|
13652 | }
|
13653 | }
|
13654 |
|
13655 | root.parent = preroot;
|
13656 | root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
|
13657 | root.parent = null;
|
13658 | if (n > 0) throw new Error("cycle");
|
13659 |
|
13660 | return root;
|
13661 | }
|
13662 |
|
13663 | stratify.id = function(x) {
|
13664 | return arguments.length ? (id = optional(x), stratify) : id;
|
13665 | };
|
13666 |
|
13667 | stratify.parentId = function(x) {
|
13668 | return arguments.length ? (parentId = optional(x), stratify) : parentId;
|
13669 | };
|
13670 |
|
13671 | stratify.path = function(x) {
|
13672 | return arguments.length ? (path = optional(x), stratify) : path;
|
13673 | };
|
13674 |
|
13675 | return stratify;
|
13676 | }
|
13677 |
|
13678 | // To normalize a path, we coerce to a string, strip the trailing slash if any
|
13679 | // (as long as the trailing slash is not immediately preceded by another slash),
|
13680 | // and add leading slash if missing.
|
13681 | function normalize$1(path) {
|
13682 | path = `${path}`;
|
13683 | let i = path.length;
|
13684 | if (slash(path, i - 1) && !slash(path, i - 2)) path = path.slice(0, -1);
|
13685 | return path[0] === "/" ? path : `/${path}`;
|
13686 | }
|
13687 |
|
13688 | // Walk backwards to find the first slash that is not the leading slash, e.g.:
|
13689 | // "/foo/bar" ⇥ "/foo", "/foo" ⇥ "/", "/" ↦ "". (The root is special-cased
|
13690 | // because the id of the root must be a truthy value.)
|
13691 | function parentof(path) {
|
13692 | let i = path.length;
|
13693 | if (i < 2) return "";
|
13694 | while (--i > 1) if (slash(path, i)) break;
|
13695 | return path.slice(0, i);
|
13696 | }
|
13697 |
|
13698 | // Slashes can be escaped; to determine whether a slash is a path delimiter, we
|
13699 | // count the number of preceding backslashes escaping the forward slash: an odd
|
13700 | // number indicates an escaped forward slash.
|
13701 | function slash(path, i) {
|
13702 | if (path[i] === "/") {
|
13703 | let k = 0;
|
13704 | while (i > 0 && path[--i] === "\\") ++k;
|
13705 | if ((k & 1) === 0) return true;
|
13706 | }
|
13707 | return false;
|
13708 | }
|
13709 |
|
13710 | function defaultSeparation(a, b) {
|
13711 | return a.parent === b.parent ? 1 : 2;
|
13712 | }
|
13713 |
|
13714 | // function radialSeparation(a, b) {
|
13715 | // return (a.parent === b.parent ? 1 : 2) / a.depth;
|
13716 | // }
|
13717 |
|
13718 | // This function is used to traverse the left contour of a subtree (or
|
13719 | // subforest). It returns the successor of v on this contour. This successor is
|
13720 | // either given by the leftmost child of v or by the thread of v. The function
|
13721 | // returns null if and only if v is on the highest level of its subtree.
|
13722 | function nextLeft(v) {
|
13723 | var children = v.children;
|
13724 | return children ? children[0] : v.t;
|
13725 | }
|
13726 |
|
13727 | // This function works analogously to nextLeft.
|
13728 | function nextRight(v) {
|
13729 | var children = v.children;
|
13730 | return children ? children[children.length - 1] : v.t;
|
13731 | }
|
13732 |
|
13733 | // Shifts the current subtree rooted at w+. This is done by increasing
|
13734 | // prelim(w+) and mod(w+) by shift.
|
13735 | function moveSubtree(wm, wp, shift) {
|
13736 | var change = shift / (wp.i - wm.i);
|
13737 | wp.c -= change;
|
13738 | wp.s += shift;
|
13739 | wm.c += change;
|
13740 | wp.z += shift;
|
13741 | wp.m += shift;
|
13742 | }
|
13743 |
|
13744 | // All other shifts, applied to the smaller subtrees between w- and w+, are
|
13745 | // performed by this function. To prepare the shifts, we have to adjust
|
13746 | // change(w+), shift(w+), and change(w-).
|
13747 | function executeShifts(v) {
|
13748 | var shift = 0,
|
13749 | change = 0,
|
13750 | children = v.children,
|
13751 | i = children.length,
|
13752 | w;
|
13753 | while (--i >= 0) {
|
13754 | w = children[i];
|
13755 | w.z += shift;
|
13756 | w.m += shift;
|
13757 | shift += w.s + (change += w.c);
|
13758 | }
|
13759 | }
|
13760 |
|
13761 | // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
|
13762 | // returns the specified (default) ancestor.
|
13763 | function nextAncestor(vim, v, ancestor) {
|
13764 | return vim.a.parent === v.parent ? vim.a : ancestor;
|
13765 | }
|
13766 |
|
13767 | function TreeNode(node, i) {
|
13768 | this._ = node;
|
13769 | this.parent = null;
|
13770 | this.children = null;
|
13771 | this.A = null; // default ancestor
|
13772 | this.a = this; // ancestor
|
13773 | this.z = 0; // prelim
|
13774 | this.m = 0; // mod
|
13775 | this.c = 0; // change
|
13776 | this.s = 0; // shift
|
13777 | this.t = null; // thread
|
13778 | this.i = i; // number
|
13779 | }
|
13780 |
|
13781 | TreeNode.prototype = Object.create(Node$1.prototype);
|
13782 |
|
13783 | function treeRoot(root) {
|
13784 | var tree = new TreeNode(root, 0),
|
13785 | node,
|
13786 | nodes = [tree],
|
13787 | child,
|
13788 | children,
|
13789 | i,
|
13790 | n;
|
13791 |
|
13792 | while (node = nodes.pop()) {
|
13793 | if (children = node._.children) {
|
13794 | node.children = new Array(n = children.length);
|
13795 | for (i = n - 1; i >= 0; --i) {
|
13796 | nodes.push(child = node.children[i] = new TreeNode(children[i], i));
|
13797 | child.parent = node;
|
13798 | }
|
13799 | }
|
13800 | }
|
13801 |
|
13802 | (tree.parent = new TreeNode(null, 0)).children = [tree];
|
13803 | return tree;
|
13804 | }
|
13805 |
|
13806 | // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
|
13807 | function tree() {
|
13808 | var separation = defaultSeparation,
|
13809 | dx = 1,
|
13810 | dy = 1,
|
13811 | nodeSize = null;
|
13812 |
|
13813 | function tree(root) {
|
13814 | var t = treeRoot(root);
|
13815 |
|
13816 | // Compute the layout using Buchheim et al.’s algorithm.
|
13817 | t.eachAfter(firstWalk), t.parent.m = -t.z;
|
13818 | t.eachBefore(secondWalk);
|
13819 |
|
13820 | // If a fixed node size is specified, scale x and y.
|
13821 | if (nodeSize) root.eachBefore(sizeNode);
|
13822 |
|
13823 | // If a fixed tree size is specified, scale x and y based on the extent.
|
13824 | // Compute the left-most, right-most, and depth-most nodes for extents.
|
13825 | else {
|
13826 | var left = root,
|
13827 | right = root,
|
13828 | bottom = root;
|
13829 | root.eachBefore(function(node) {
|
13830 | if (node.x < left.x) left = node;
|
13831 | if (node.x > right.x) right = node;
|
13832 | if (node.depth > bottom.depth) bottom = node;
|
13833 | });
|
13834 | var s = left === right ? 1 : separation(left, right) / 2,
|
13835 | tx = s - left.x,
|
13836 | kx = dx / (right.x + s + tx),
|
13837 | ky = dy / (bottom.depth || 1);
|
13838 | root.eachBefore(function(node) {
|
13839 | node.x = (node.x + tx) * kx;
|
13840 | node.y = node.depth * ky;
|
13841 | });
|
13842 | }
|
13843 |
|
13844 | return root;
|
13845 | }
|
13846 |
|
13847 | // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
|
13848 | // applied recursively to the children of v, as well as the function
|
13849 | // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
|
13850 | // node v is placed to the midpoint of its outermost children.
|
13851 | function firstWalk(v) {
|
13852 | var children = v.children,
|
13853 | siblings = v.parent.children,
|
13854 | w = v.i ? siblings[v.i - 1] : null;
|
13855 | if (children) {
|
13856 | executeShifts(v);
|
13857 | var midpoint = (children[0].z + children[children.length - 1].z) / 2;
|
13858 | if (w) {
|
13859 | v.z = w.z + separation(v._, w._);
|
13860 | v.m = v.z - midpoint;
|
13861 | } else {
|
13862 | v.z = midpoint;
|
13863 | }
|
13864 | } else if (w) {
|
13865 | v.z = w.z + separation(v._, w._);
|
13866 | }
|
13867 | v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
|
13868 | }
|
13869 |
|
13870 | // Computes all real x-coordinates by summing up the modifiers recursively.
|
13871 | function secondWalk(v) {
|
13872 | v._.x = v.z + v.parent.m;
|
13873 | v.m += v.parent.m;
|
13874 | }
|
13875 |
|
13876 | // The core of the algorithm. Here, a new subtree is combined with the
|
13877 | // previous subtrees. Threads are used to traverse the inside and outside
|
13878 | // contours of the left and right subtree up to the highest common level. The
|
13879 | // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
|
13880 | // superscript o means outside and i means inside, the subscript - means left
|
13881 | // subtree and + means right subtree. For summing up the modifiers along the
|
13882 | // contour, we use respective variables si+, si-, so-, and so+. Whenever two
|
13883 | // nodes of the inside contours conflict, we compute the left one of the
|
13884 | // greatest uncommon ancestors using the function ANCESTOR and call MOVE
|
13885 | // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
|
13886 | // Finally, we add a new thread (if necessary).
|
13887 | function apportion(v, w, ancestor) {
|
13888 | if (w) {
|
13889 | var vip = v,
|
13890 | vop = v,
|
13891 | vim = w,
|
13892 | vom = vip.parent.children[0],
|
13893 | sip = vip.m,
|
13894 | sop = vop.m,
|
13895 | sim = vim.m,
|
13896 | som = vom.m,
|
13897 | shift;
|
13898 | while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
|
13899 | vom = nextLeft(vom);
|
13900 | vop = nextRight(vop);
|
13901 | vop.a = v;
|
13902 | shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
|
13903 | if (shift > 0) {
|
13904 | moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
|
13905 | sip += shift;
|
13906 | sop += shift;
|
13907 | }
|
13908 | sim += vim.m;
|
13909 | sip += vip.m;
|
13910 | som += vom.m;
|
13911 | sop += vop.m;
|
13912 | }
|
13913 | if (vim && !nextRight(vop)) {
|
13914 | vop.t = vim;
|
13915 | vop.m += sim - sop;
|
13916 | }
|
13917 | if (vip && !nextLeft(vom)) {
|
13918 | vom.t = vip;
|
13919 | vom.m += sip - som;
|
13920 | ancestor = v;
|
13921 | }
|
13922 | }
|
13923 | return ancestor;
|
13924 | }
|
13925 |
|
13926 | function sizeNode(node) {
|
13927 | node.x *= dx;
|
13928 | node.y = node.depth * dy;
|
13929 | }
|
13930 |
|
13931 | tree.separation = function(x) {
|
13932 | return arguments.length ? (separation = x, tree) : separation;
|
13933 | };
|
13934 |
|
13935 | tree.size = function(x) {
|
13936 | return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
|
13937 | };
|
13938 |
|
13939 | tree.nodeSize = function(x) {
|
13940 | return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
|
13941 | };
|
13942 |
|
13943 | return tree;
|
13944 | }
|
13945 |
|
13946 | function treemapSlice(parent, x0, y0, x1, y1) {
|
13947 | var nodes = parent.children,
|
13948 | node,
|
13949 | i = -1,
|
13950 | n = nodes.length,
|
13951 | k = parent.value && (y1 - y0) / parent.value;
|
13952 |
|
13953 | while (++i < n) {
|
13954 | node = nodes[i], node.x0 = x0, node.x1 = x1;
|
13955 | node.y0 = y0, node.y1 = y0 += node.value * k;
|
13956 | }
|
13957 | }
|
13958 |
|
13959 | var phi = (1 + Math.sqrt(5)) / 2;
|
13960 |
|
13961 | function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
|
13962 | var rows = [],
|
13963 | nodes = parent.children,
|
13964 | row,
|
13965 | nodeValue,
|
13966 | i0 = 0,
|
13967 | i1 = 0,
|
13968 | n = nodes.length,
|
13969 | dx, dy,
|
13970 | value = parent.value,
|
13971 | sumValue,
|
13972 | minValue,
|
13973 | maxValue,
|
13974 | newRatio,
|
13975 | minRatio,
|
13976 | alpha,
|
13977 | beta;
|
13978 |
|
13979 | while (i0 < n) {
|
13980 | dx = x1 - x0, dy = y1 - y0;
|
13981 |
|
13982 | // Find the next non-empty node.
|
13983 | do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
|
13984 | minValue = maxValue = sumValue;
|
13985 | alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
|
13986 | beta = sumValue * sumValue * alpha;
|
13987 | minRatio = Math.max(maxValue / beta, beta / minValue);
|
13988 |
|
13989 | // Keep adding nodes while the aspect ratio maintains or improves.
|
13990 | for (; i1 < n; ++i1) {
|
13991 | sumValue += nodeValue = nodes[i1].value;
|
13992 | if (nodeValue < minValue) minValue = nodeValue;
|
13993 | if (nodeValue > maxValue) maxValue = nodeValue;
|
13994 | beta = sumValue * sumValue * alpha;
|
13995 | newRatio = Math.max(maxValue / beta, beta / minValue);
|
13996 | if (newRatio > minRatio) { sumValue -= nodeValue; break; }
|
13997 | minRatio = newRatio;
|
13998 | }
|
13999 |
|
14000 | // Position and record the row orientation.
|
14001 | rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
|
14002 | if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
|
14003 | else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
|
14004 | value -= sumValue, i0 = i1;
|
14005 | }
|
14006 |
|
14007 | return rows;
|
14008 | }
|
14009 |
|
14010 | var squarify = (function custom(ratio) {
|
14011 |
|
14012 | function squarify(parent, x0, y0, x1, y1) {
|
14013 | squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
14014 | }
|
14015 |
|
14016 | squarify.ratio = function(x) {
|
14017 | return custom((x = +x) > 1 ? x : 1);
|
14018 | };
|
14019 |
|
14020 | return squarify;
|
14021 | })(phi);
|
14022 |
|
14023 | function index() {
|
14024 | var tile = squarify,
|
14025 | round = false,
|
14026 | dx = 1,
|
14027 | dy = 1,
|
14028 | paddingStack = [0],
|
14029 | paddingInner = constantZero,
|
14030 | paddingTop = constantZero,
|
14031 | paddingRight = constantZero,
|
14032 | paddingBottom = constantZero,
|
14033 | paddingLeft = constantZero;
|
14034 |
|
14035 | function treemap(root) {
|
14036 | root.x0 =
|
14037 | root.y0 = 0;
|
14038 | root.x1 = dx;
|
14039 | root.y1 = dy;
|
14040 | root.eachBefore(positionNode);
|
14041 | paddingStack = [0];
|
14042 | if (round) root.eachBefore(roundNode);
|
14043 | return root;
|
14044 | }
|
14045 |
|
14046 | function positionNode(node) {
|
14047 | var p = paddingStack[node.depth],
|
14048 | x0 = node.x0 + p,
|
14049 | y0 = node.y0 + p,
|
14050 | x1 = node.x1 - p,
|
14051 | y1 = node.y1 - p;
|
14052 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
14053 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
14054 | node.x0 = x0;
|
14055 | node.y0 = y0;
|
14056 | node.x1 = x1;
|
14057 | node.y1 = y1;
|
14058 | if (node.children) {
|
14059 | p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
|
14060 | x0 += paddingLeft(node) - p;
|
14061 | y0 += paddingTop(node) - p;
|
14062 | x1 -= paddingRight(node) - p;
|
14063 | y1 -= paddingBottom(node) - p;
|
14064 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
14065 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
14066 | tile(node, x0, y0, x1, y1);
|
14067 | }
|
14068 | }
|
14069 |
|
14070 | treemap.round = function(x) {
|
14071 | return arguments.length ? (round = !!x, treemap) : round;
|
14072 | };
|
14073 |
|
14074 | treemap.size = function(x) {
|
14075 | return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
|
14076 | };
|
14077 |
|
14078 | treemap.tile = function(x) {
|
14079 | return arguments.length ? (tile = required(x), treemap) : tile;
|
14080 | };
|
14081 |
|
14082 | treemap.padding = function(x) {
|
14083 | return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
|
14084 | };
|
14085 |
|
14086 | treemap.paddingInner = function(x) {
|
14087 | return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$2(+x), treemap) : paddingInner;
|
14088 | };
|
14089 |
|
14090 | treemap.paddingOuter = function(x) {
|
14091 | return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
|
14092 | };
|
14093 |
|
14094 | treemap.paddingTop = function(x) {
|
14095 | return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$2(+x), treemap) : paddingTop;
|
14096 | };
|
14097 |
|
14098 | treemap.paddingRight = function(x) {
|
14099 | return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$2(+x), treemap) : paddingRight;
|
14100 | };
|
14101 |
|
14102 | treemap.paddingBottom = function(x) {
|
14103 | return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$2(+x), treemap) : paddingBottom;
|
14104 | };
|
14105 |
|
14106 | treemap.paddingLeft = function(x) {
|
14107 | return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$2(+x), treemap) : paddingLeft;
|
14108 | };
|
14109 |
|
14110 | return treemap;
|
14111 | }
|
14112 |
|
14113 | function binary(parent, x0, y0, x1, y1) {
|
14114 | var nodes = parent.children,
|
14115 | i, n = nodes.length,
|
14116 | sum, sums = new Array(n + 1);
|
14117 |
|
14118 | for (sums[0] = sum = i = 0; i < n; ++i) {
|
14119 | sums[i + 1] = sum += nodes[i].value;
|
14120 | }
|
14121 |
|
14122 | partition(0, n, parent.value, x0, y0, x1, y1);
|
14123 |
|
14124 | function partition(i, j, value, x0, y0, x1, y1) {
|
14125 | if (i >= j - 1) {
|
14126 | var node = nodes[i];
|
14127 | node.x0 = x0, node.y0 = y0;
|
14128 | node.x1 = x1, node.y1 = y1;
|
14129 | return;
|
14130 | }
|
14131 |
|
14132 | var valueOffset = sums[i],
|
14133 | valueTarget = (value / 2) + valueOffset,
|
14134 | k = i + 1,
|
14135 | hi = j - 1;
|
14136 |
|
14137 | while (k < hi) {
|
14138 | var mid = k + hi >>> 1;
|
14139 | if (sums[mid] < valueTarget) k = mid + 1;
|
14140 | else hi = mid;
|
14141 | }
|
14142 |
|
14143 | if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
|
14144 |
|
14145 | var valueLeft = sums[k] - valueOffset,
|
14146 | valueRight = value - valueLeft;
|
14147 |
|
14148 | if ((x1 - x0) > (y1 - y0)) {
|
14149 | var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
|
14150 | partition(i, k, valueLeft, x0, y0, xk, y1);
|
14151 | partition(k, j, valueRight, xk, y0, x1, y1);
|
14152 | } else {
|
14153 | var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
|
14154 | partition(i, k, valueLeft, x0, y0, x1, yk);
|
14155 | partition(k, j, valueRight, x0, yk, x1, y1);
|
14156 | }
|
14157 | }
|
14158 | }
|
14159 |
|
14160 | function sliceDice(parent, x0, y0, x1, y1) {
|
14161 | (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
|
14162 | }
|
14163 |
|
14164 | var resquarify = (function custom(ratio) {
|
14165 |
|
14166 | function resquarify(parent, x0, y0, x1, y1) {
|
14167 | if ((rows = parent._squarify) && (rows.ratio === ratio)) {
|
14168 | var rows,
|
14169 | row,
|
14170 | nodes,
|
14171 | i,
|
14172 | j = -1,
|
14173 | n,
|
14174 | m = rows.length,
|
14175 | value = parent.value;
|
14176 |
|
14177 | while (++j < m) {
|
14178 | row = rows[j], nodes = row.children;
|
14179 | for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
|
14180 | if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1);
|
14181 | else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1);
|
14182 | value -= row.value;
|
14183 | }
|
14184 | } else {
|
14185 | parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
14186 | rows.ratio = ratio;
|
14187 | }
|
14188 | }
|
14189 |
|
14190 | resquarify.ratio = function(x) {
|
14191 | return custom((x = +x) > 1 ? x : 1);
|
14192 | };
|
14193 |
|
14194 | return resquarify;
|
14195 | })(phi);
|
14196 |
|
14197 | function area$1(polygon) {
|
14198 | var i = -1,
|
14199 | n = polygon.length,
|
14200 | a,
|
14201 | b = polygon[n - 1],
|
14202 | area = 0;
|
14203 |
|
14204 | while (++i < n) {
|
14205 | a = b;
|
14206 | b = polygon[i];
|
14207 | area += a[1] * b[0] - a[0] * b[1];
|
14208 | }
|
14209 |
|
14210 | return area / 2;
|
14211 | }
|
14212 |
|
14213 | function centroid(polygon) {
|
14214 | var i = -1,
|
14215 | n = polygon.length,
|
14216 | x = 0,
|
14217 | y = 0,
|
14218 | a,
|
14219 | b = polygon[n - 1],
|
14220 | c,
|
14221 | k = 0;
|
14222 |
|
14223 | while (++i < n) {
|
14224 | a = b;
|
14225 | b = polygon[i];
|
14226 | k += c = a[0] * b[1] - b[0] * a[1];
|
14227 | x += (a[0] + b[0]) * c;
|
14228 | y += (a[1] + b[1]) * c;
|
14229 | }
|
14230 |
|
14231 | return k *= 3, [x / k, y / k];
|
14232 | }
|
14233 |
|
14234 | // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
|
14235 | // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
|
14236 | // right, +y is up). Returns a positive value if ABC is counter-clockwise,
|
14237 | // negative if clockwise, and zero if the points are collinear.
|
14238 | function cross$1(a, b, c) {
|
14239 | return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
14240 | }
|
14241 |
|
14242 | function lexicographicOrder(a, b) {
|
14243 | return a[0] - b[0] || a[1] - b[1];
|
14244 | }
|
14245 |
|
14246 | // Computes the upper convex hull per the monotone chain algorithm.
|
14247 | // Assumes points.length >= 3, is sorted by x, unique in y.
|
14248 | // Returns an array of indices into points in left-to-right order.
|
14249 | function computeUpperHullIndexes(points) {
|
14250 | const n = points.length,
|
14251 | indexes = [0, 1];
|
14252 | let size = 2, i;
|
14253 |
|
14254 | for (i = 2; i < n; ++i) {
|
14255 | while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
|
14256 | indexes[size++] = i;
|
14257 | }
|
14258 |
|
14259 | return indexes.slice(0, size); // remove popped points
|
14260 | }
|
14261 |
|
14262 | function hull(points) {
|
14263 | if ((n = points.length) < 3) return null;
|
14264 |
|
14265 | var i,
|
14266 | n,
|
14267 | sortedPoints = new Array(n),
|
14268 | flippedPoints = new Array(n);
|
14269 |
|
14270 | for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
|
14271 | sortedPoints.sort(lexicographicOrder);
|
14272 | for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
|
14273 |
|
14274 | var upperIndexes = computeUpperHullIndexes(sortedPoints),
|
14275 | lowerIndexes = computeUpperHullIndexes(flippedPoints);
|
14276 |
|
14277 | // Construct the hull polygon, removing possible duplicate endpoints.
|
14278 | var skipLeft = lowerIndexes[0] === upperIndexes[0],
|
14279 | skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
|
14280 | hull = [];
|
14281 |
|
14282 | // Add upper hull in right-to-l order.
|
14283 | // Then add lower hull in left-to-right order.
|
14284 | for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
|
14285 | for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
|
14286 |
|
14287 | return hull;
|
14288 | }
|
14289 |
|
14290 | function contains(polygon, point) {
|
14291 | var n = polygon.length,
|
14292 | p = polygon[n - 1],
|
14293 | x = point[0], y = point[1],
|
14294 | x0 = p[0], y0 = p[1],
|
14295 | x1, y1,
|
14296 | inside = false;
|
14297 |
|
14298 | for (var i = 0; i < n; ++i) {
|
14299 | p = polygon[i], x1 = p[0], y1 = p[1];
|
14300 | if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
|
14301 | x0 = x1, y0 = y1;
|
14302 | }
|
14303 |
|
14304 | return inside;
|
14305 | }
|
14306 |
|
14307 | function length(polygon) {
|
14308 | var i = -1,
|
14309 | n = polygon.length,
|
14310 | b = polygon[n - 1],
|
14311 | xa,
|
14312 | ya,
|
14313 | xb = b[0],
|
14314 | yb = b[1],
|
14315 | perimeter = 0;
|
14316 |
|
14317 | while (++i < n) {
|
14318 | xa = xb;
|
14319 | ya = yb;
|
14320 | b = polygon[i];
|
14321 | xb = b[0];
|
14322 | yb = b[1];
|
14323 | xa -= xb;
|
14324 | ya -= yb;
|
14325 | perimeter += Math.hypot(xa, ya);
|
14326 | }
|
14327 |
|
14328 | return perimeter;
|
14329 | }
|
14330 |
|
14331 | var defaultSource = Math.random;
|
14332 |
|
14333 | var uniform = (function sourceRandomUniform(source) {
|
14334 | function randomUniform(min, max) {
|
14335 | min = min == null ? 0 : +min;
|
14336 | max = max == null ? 1 : +max;
|
14337 | if (arguments.length === 1) max = min, min = 0;
|
14338 | else max -= min;
|
14339 | return function() {
|
14340 | return source() * max + min;
|
14341 | };
|
14342 | }
|
14343 |
|
14344 | randomUniform.source = sourceRandomUniform;
|
14345 |
|
14346 | return randomUniform;
|
14347 | })(defaultSource);
|
14348 |
|
14349 | var int = (function sourceRandomInt(source) {
|
14350 | function randomInt(min, max) {
|
14351 | if (arguments.length < 2) max = min, min = 0;
|
14352 | min = Math.floor(min);
|
14353 | max = Math.floor(max) - min;
|
14354 | return function() {
|
14355 | return Math.floor(source() * max + min);
|
14356 | };
|
14357 | }
|
14358 |
|
14359 | randomInt.source = sourceRandomInt;
|
14360 |
|
14361 | return randomInt;
|
14362 | })(defaultSource);
|
14363 |
|
14364 | var normal = (function sourceRandomNormal(source) {
|
14365 | function randomNormal(mu, sigma) {
|
14366 | var x, r;
|
14367 | mu = mu == null ? 0 : +mu;
|
14368 | sigma = sigma == null ? 1 : +sigma;
|
14369 | return function() {
|
14370 | var y;
|
14371 |
|
14372 | // If available, use the second previously-generated uniform random.
|
14373 | if (x != null) y = x, x = null;
|
14374 |
|
14375 | // Otherwise, generate a new x and y.
|
14376 | else do {
|
14377 | x = source() * 2 - 1;
|
14378 | y = source() * 2 - 1;
|
14379 | r = x * x + y * y;
|
14380 | } while (!r || r > 1);
|
14381 |
|
14382 | return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
|
14383 | };
|
14384 | }
|
14385 |
|
14386 | randomNormal.source = sourceRandomNormal;
|
14387 |
|
14388 | return randomNormal;
|
14389 | })(defaultSource);
|
14390 |
|
14391 | var logNormal = (function sourceRandomLogNormal(source) {
|
14392 | var N = normal.source(source);
|
14393 |
|
14394 | function randomLogNormal() {
|
14395 | var randomNormal = N.apply(this, arguments);
|
14396 | return function() {
|
14397 | return Math.exp(randomNormal());
|
14398 | };
|
14399 | }
|
14400 |
|
14401 | randomLogNormal.source = sourceRandomLogNormal;
|
14402 |
|
14403 | return randomLogNormal;
|
14404 | })(defaultSource);
|
14405 |
|
14406 | var irwinHall = (function sourceRandomIrwinHall(source) {
|
14407 | function randomIrwinHall(n) {
|
14408 | if ((n = +n) <= 0) return () => 0;
|
14409 | return function() {
|
14410 | for (var sum = 0, i = n; i > 1; --i) sum += source();
|
14411 | return sum + i * source();
|
14412 | };
|
14413 | }
|
14414 |
|
14415 | randomIrwinHall.source = sourceRandomIrwinHall;
|
14416 |
|
14417 | return randomIrwinHall;
|
14418 | })(defaultSource);
|
14419 |
|
14420 | var bates = (function sourceRandomBates(source) {
|
14421 | var I = irwinHall.source(source);
|
14422 |
|
14423 | function randomBates(n) {
|
14424 | // use limiting distribution at n === 0
|
14425 | if ((n = +n) === 0) return source;
|
14426 | var randomIrwinHall = I(n);
|
14427 | return function() {
|
14428 | return randomIrwinHall() / n;
|
14429 | };
|
14430 | }
|
14431 |
|
14432 | randomBates.source = sourceRandomBates;
|
14433 |
|
14434 | return randomBates;
|
14435 | })(defaultSource);
|
14436 |
|
14437 | var exponential = (function sourceRandomExponential(source) {
|
14438 | function randomExponential(lambda) {
|
14439 | return function() {
|
14440 | return -Math.log1p(-source()) / lambda;
|
14441 | };
|
14442 | }
|
14443 |
|
14444 | randomExponential.source = sourceRandomExponential;
|
14445 |
|
14446 | return randomExponential;
|
14447 | })(defaultSource);
|
14448 |
|
14449 | var pareto = (function sourceRandomPareto(source) {
|
14450 | function randomPareto(alpha) {
|
14451 | if ((alpha = +alpha) < 0) throw new RangeError("invalid alpha");
|
14452 | alpha = 1 / -alpha;
|
14453 | return function() {
|
14454 | return Math.pow(1 - source(), alpha);
|
14455 | };
|
14456 | }
|
14457 |
|
14458 | randomPareto.source = sourceRandomPareto;
|
14459 |
|
14460 | return randomPareto;
|
14461 | })(defaultSource);
|
14462 |
|
14463 | var bernoulli = (function sourceRandomBernoulli(source) {
|
14464 | function randomBernoulli(p) {
|
14465 | if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
|
14466 | return function() {
|
14467 | return Math.floor(source() + p);
|
14468 | };
|
14469 | }
|
14470 |
|
14471 | randomBernoulli.source = sourceRandomBernoulli;
|
14472 |
|
14473 | return randomBernoulli;
|
14474 | })(defaultSource);
|
14475 |
|
14476 | var geometric = (function sourceRandomGeometric(source) {
|
14477 | function randomGeometric(p) {
|
14478 | if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
|
14479 | if (p === 0) return () => Infinity;
|
14480 | if (p === 1) return () => 1;
|
14481 | p = Math.log1p(-p);
|
14482 | return function() {
|
14483 | return 1 + Math.floor(Math.log1p(-source()) / p);
|
14484 | };
|
14485 | }
|
14486 |
|
14487 | randomGeometric.source = sourceRandomGeometric;
|
14488 |
|
14489 | return randomGeometric;
|
14490 | })(defaultSource);
|
14491 |
|
14492 | var gamma = (function sourceRandomGamma(source) {
|
14493 | var randomNormal = normal.source(source)();
|
14494 |
|
14495 | function randomGamma(k, theta) {
|
14496 | if ((k = +k) < 0) throw new RangeError("invalid k");
|
14497 | // degenerate distribution if k === 0
|
14498 | if (k === 0) return () => 0;
|
14499 | theta = theta == null ? 1 : +theta;
|
14500 | // exponential distribution if k === 1
|
14501 | if (k === 1) return () => -Math.log1p(-source()) * theta;
|
14502 |
|
14503 | var d = (k < 1 ? k + 1 : k) - 1 / 3,
|
14504 | c = 1 / (3 * Math.sqrt(d)),
|
14505 | multiplier = k < 1 ? () => Math.pow(source(), 1 / k) : () => 1;
|
14506 | return function() {
|
14507 | do {
|
14508 | do {
|
14509 | var x = randomNormal(),
|
14510 | v = 1 + c * x;
|
14511 | } while (v <= 0);
|
14512 | v *= v * v;
|
14513 | var u = 1 - source();
|
14514 | } while (u >= 1 - 0.0331 * x * x * x * x && Math.log(u) >= 0.5 * x * x + d * (1 - v + Math.log(v)));
|
14515 | return d * v * multiplier() * theta;
|
14516 | };
|
14517 | }
|
14518 |
|
14519 | randomGamma.source = sourceRandomGamma;
|
14520 |
|
14521 | return randomGamma;
|
14522 | })(defaultSource);
|
14523 |
|
14524 | var beta = (function sourceRandomBeta(source) {
|
14525 | var G = gamma.source(source);
|
14526 |
|
14527 | function randomBeta(alpha, beta) {
|
14528 | var X = G(alpha),
|
14529 | Y = G(beta);
|
14530 | return function() {
|
14531 | var x = X();
|
14532 | return x === 0 ? 0 : x / (x + Y());
|
14533 | };
|
14534 | }
|
14535 |
|
14536 | randomBeta.source = sourceRandomBeta;
|
14537 |
|
14538 | return randomBeta;
|
14539 | })(defaultSource);
|
14540 |
|
14541 | var binomial = (function sourceRandomBinomial(source) {
|
14542 | var G = geometric.source(source),
|
14543 | B = beta.source(source);
|
14544 |
|
14545 | function randomBinomial(n, p) {
|
14546 | n = +n;
|
14547 | if ((p = +p) >= 1) return () => n;
|
14548 | if (p <= 0) return () => 0;
|
14549 | return function() {
|
14550 | var acc = 0, nn = n, pp = p;
|
14551 | while (nn * pp > 16 && nn * (1 - pp) > 16) {
|
14552 | var i = Math.floor((nn + 1) * pp),
|
14553 | y = B(i, nn - i + 1)();
|
14554 | if (y <= pp) {
|
14555 | acc += i;
|
14556 | nn -= i;
|
14557 | pp = (pp - y) / (1 - y);
|
14558 | } else {
|
14559 | nn = i - 1;
|
14560 | pp /= y;
|
14561 | }
|
14562 | }
|
14563 | var sign = pp < 0.5,
|
14564 | pFinal = sign ? pp : 1 - pp,
|
14565 | g = G(pFinal);
|
14566 | for (var s = g(), k = 0; s <= nn; ++k) s += g();
|
14567 | return acc + (sign ? k : nn - k);
|
14568 | };
|
14569 | }
|
14570 |
|
14571 | randomBinomial.source = sourceRandomBinomial;
|
14572 |
|
14573 | return randomBinomial;
|
14574 | })(defaultSource);
|
14575 |
|
14576 | var weibull = (function sourceRandomWeibull(source) {
|
14577 | function randomWeibull(k, a, b) {
|
14578 | var outerFunc;
|
14579 | if ((k = +k) === 0) {
|
14580 | outerFunc = x => -Math.log(x);
|
14581 | } else {
|
14582 | k = 1 / k;
|
14583 | outerFunc = x => Math.pow(x, k);
|
14584 | }
|
14585 | a = a == null ? 0 : +a;
|
14586 | b = b == null ? 1 : +b;
|
14587 | return function() {
|
14588 | return a + b * outerFunc(-Math.log1p(-source()));
|
14589 | };
|
14590 | }
|
14591 |
|
14592 | randomWeibull.source = sourceRandomWeibull;
|
14593 |
|
14594 | return randomWeibull;
|
14595 | })(defaultSource);
|
14596 |
|
14597 | var cauchy = (function sourceRandomCauchy(source) {
|
14598 | function randomCauchy(a, b) {
|
14599 | a = a == null ? 0 : +a;
|
14600 | b = b == null ? 1 : +b;
|
14601 | return function() {
|
14602 | return a + b * Math.tan(Math.PI * source());
|
14603 | };
|
14604 | }
|
14605 |
|
14606 | randomCauchy.source = sourceRandomCauchy;
|
14607 |
|
14608 | return randomCauchy;
|
14609 | })(defaultSource);
|
14610 |
|
14611 | var logistic = (function sourceRandomLogistic(source) {
|
14612 | function randomLogistic(a, b) {
|
14613 | a = a == null ? 0 : +a;
|
14614 | b = b == null ? 1 : +b;
|
14615 | return function() {
|
14616 | var u = source();
|
14617 | return a + b * Math.log(u / (1 - u));
|
14618 | };
|
14619 | }
|
14620 |
|
14621 | randomLogistic.source = sourceRandomLogistic;
|
14622 |
|
14623 | return randomLogistic;
|
14624 | })(defaultSource);
|
14625 |
|
14626 | var poisson = (function sourceRandomPoisson(source) {
|
14627 | var G = gamma.source(source),
|
14628 | B = binomial.source(source);
|
14629 |
|
14630 | function randomPoisson(lambda) {
|
14631 | return function() {
|
14632 | var acc = 0, l = lambda;
|
14633 | while (l > 16) {
|
14634 | var n = Math.floor(0.875 * l),
|
14635 | t = G(n)();
|
14636 | if (t > l) return acc + B(n - 1, l / t)();
|
14637 | acc += n;
|
14638 | l -= t;
|
14639 | }
|
14640 | for (var s = -Math.log1p(-source()), k = 0; s <= l; ++k) s -= Math.log1p(-source());
|
14641 | return acc + k;
|
14642 | };
|
14643 | }
|
14644 |
|
14645 | randomPoisson.source = sourceRandomPoisson;
|
14646 |
|
14647 | return randomPoisson;
|
14648 | })(defaultSource);
|
14649 |
|
14650 | // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
|
14651 | const mul = 0x19660D;
|
14652 | const inc = 0x3C6EF35F;
|
14653 | const eps = 1 / 0x100000000;
|
14654 |
|
14655 | function lcg(seed = Math.random()) {
|
14656 | let state = (0 <= seed && seed < 1 ? seed / eps : Math.abs(seed)) | 0;
|
14657 | return () => (state = mul * state + inc | 0, eps * (state >>> 0));
|
14658 | }
|
14659 |
|
14660 | function initRange(domain, range) {
|
14661 | switch (arguments.length) {
|
14662 | case 0: break;
|
14663 | case 1: this.range(domain); break;
|
14664 | default: this.range(range).domain(domain); break;
|
14665 | }
|
14666 | return this;
|
14667 | }
|
14668 |
|
14669 | function initInterpolator(domain, interpolator) {
|
14670 | switch (arguments.length) {
|
14671 | case 0: break;
|
14672 | case 1: {
|
14673 | if (typeof domain === "function") this.interpolator(domain);
|
14674 | else this.range(domain);
|
14675 | break;
|
14676 | }
|
14677 | default: {
|
14678 | this.domain(domain);
|
14679 | if (typeof interpolator === "function") this.interpolator(interpolator);
|
14680 | else this.range(interpolator);
|
14681 | break;
|
14682 | }
|
14683 | }
|
14684 | return this;
|
14685 | }
|
14686 |
|
14687 | const implicit = Symbol("implicit");
|
14688 |
|
14689 | function ordinal() {
|
14690 | var index = new InternMap(),
|
14691 | domain = [],
|
14692 | range = [],
|
14693 | unknown = implicit;
|
14694 |
|
14695 | function scale(d) {
|
14696 | let i = index.get(d);
|
14697 | if (i === undefined) {
|
14698 | if (unknown !== implicit) return unknown;
|
14699 | index.set(d, i = domain.push(d) - 1);
|
14700 | }
|
14701 | return range[i % range.length];
|
14702 | }
|
14703 |
|
14704 | scale.domain = function(_) {
|
14705 | if (!arguments.length) return domain.slice();
|
14706 | domain = [], index = new InternMap();
|
14707 | for (const value of _) {
|
14708 | if (index.has(value)) continue;
|
14709 | index.set(value, domain.push(value) - 1);
|
14710 | }
|
14711 | return scale;
|
14712 | };
|
14713 |
|
14714 | scale.range = function(_) {
|
14715 | return arguments.length ? (range = Array.from(_), scale) : range.slice();
|
14716 | };
|
14717 |
|
14718 | scale.unknown = function(_) {
|
14719 | return arguments.length ? (unknown = _, scale) : unknown;
|
14720 | };
|
14721 |
|
14722 | scale.copy = function() {
|
14723 | return ordinal(domain, range).unknown(unknown);
|
14724 | };
|
14725 |
|
14726 | initRange.apply(scale, arguments);
|
14727 |
|
14728 | return scale;
|
14729 | }
|
14730 |
|
14731 | function band() {
|
14732 | var scale = ordinal().unknown(undefined),
|
14733 | domain = scale.domain,
|
14734 | ordinalRange = scale.range,
|
14735 | r0 = 0,
|
14736 | r1 = 1,
|
14737 | step,
|
14738 | bandwidth,
|
14739 | round = false,
|
14740 | paddingInner = 0,
|
14741 | paddingOuter = 0,
|
14742 | align = 0.5;
|
14743 |
|
14744 | delete scale.unknown;
|
14745 |
|
14746 | function rescale() {
|
14747 | var n = domain().length,
|
14748 | reverse = r1 < r0,
|
14749 | start = reverse ? r1 : r0,
|
14750 | stop = reverse ? r0 : r1;
|
14751 | step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
|
14752 | if (round) step = Math.floor(step);
|
14753 | start += (stop - start - step * (n - paddingInner)) * align;
|
14754 | bandwidth = step * (1 - paddingInner);
|
14755 | if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
|
14756 | var values = range$2(n).map(function(i) { return start + step * i; });
|
14757 | return ordinalRange(reverse ? values.reverse() : values);
|
14758 | }
|
14759 |
|
14760 | scale.domain = function(_) {
|
14761 | return arguments.length ? (domain(_), rescale()) : domain();
|
14762 | };
|
14763 |
|
14764 | scale.range = function(_) {
|
14765 | return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
|
14766 | };
|
14767 |
|
14768 | scale.rangeRound = function(_) {
|
14769 | return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
|
14770 | };
|
14771 |
|
14772 | scale.bandwidth = function() {
|
14773 | return bandwidth;
|
14774 | };
|
14775 |
|
14776 | scale.step = function() {
|
14777 | return step;
|
14778 | };
|
14779 |
|
14780 | scale.round = function(_) {
|
14781 | return arguments.length ? (round = !!_, rescale()) : round;
|
14782 | };
|
14783 |
|
14784 | scale.padding = function(_) {
|
14785 | return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
|
14786 | };
|
14787 |
|
14788 | scale.paddingInner = function(_) {
|
14789 | return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
|
14790 | };
|
14791 |
|
14792 | scale.paddingOuter = function(_) {
|
14793 | return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
|
14794 | };
|
14795 |
|
14796 | scale.align = function(_) {
|
14797 | return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
|
14798 | };
|
14799 |
|
14800 | scale.copy = function() {
|
14801 | return band(domain(), [r0, r1])
|
14802 | .round(round)
|
14803 | .paddingInner(paddingInner)
|
14804 | .paddingOuter(paddingOuter)
|
14805 | .align(align);
|
14806 | };
|
14807 |
|
14808 | return initRange.apply(rescale(), arguments);
|
14809 | }
|
14810 |
|
14811 | function pointish(scale) {
|
14812 | var copy = scale.copy;
|
14813 |
|
14814 | scale.padding = scale.paddingOuter;
|
14815 | delete scale.paddingInner;
|
14816 | delete scale.paddingOuter;
|
14817 |
|
14818 | scale.copy = function() {
|
14819 | return pointish(copy());
|
14820 | };
|
14821 |
|
14822 | return scale;
|
14823 | }
|
14824 |
|
14825 | function point$4() {
|
14826 | return pointish(band.apply(null, arguments).paddingInner(1));
|
14827 | }
|
14828 |
|
14829 | function constants(x) {
|
14830 | return function() {
|
14831 | return x;
|
14832 | };
|
14833 | }
|
14834 |
|
14835 | function number$1(x) {
|
14836 | return +x;
|
14837 | }
|
14838 |
|
14839 | var unit = [0, 1];
|
14840 |
|
14841 | function identity$3(x) {
|
14842 | return x;
|
14843 | }
|
14844 |
|
14845 | function normalize(a, b) {
|
14846 | return (b -= (a = +a))
|
14847 | ? function(x) { return (x - a) / b; }
|
14848 | : constants(isNaN(b) ? NaN : 0.5);
|
14849 | }
|
14850 |
|
14851 | function clamper(a, b) {
|
14852 | var t;
|
14853 | if (a > b) t = a, a = b, b = t;
|
14854 | return function(x) { return Math.max(a, Math.min(b, x)); };
|
14855 | }
|
14856 |
|
14857 | // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
|
14858 | // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
|
14859 | function bimap(domain, range, interpolate) {
|
14860 | var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
|
14861 | if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
|
14862 | else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
|
14863 | return function(x) { return r0(d0(x)); };
|
14864 | }
|
14865 |
|
14866 | function polymap(domain, range, interpolate) {
|
14867 | var j = Math.min(domain.length, range.length) - 1,
|
14868 | d = new Array(j),
|
14869 | r = new Array(j),
|
14870 | i = -1;
|
14871 |
|
14872 | // Reverse descending domains.
|
14873 | if (domain[j] < domain[0]) {
|
14874 | domain = domain.slice().reverse();
|
14875 | range = range.slice().reverse();
|
14876 | }
|
14877 |
|
14878 | while (++i < j) {
|
14879 | d[i] = normalize(domain[i], domain[i + 1]);
|
14880 | r[i] = interpolate(range[i], range[i + 1]);
|
14881 | }
|
14882 |
|
14883 | return function(x) {
|
14884 | var i = bisect(domain, x, 1, j) - 1;
|
14885 | return r[i](d[i](x));
|
14886 | };
|
14887 | }
|
14888 |
|
14889 | function copy$1(source, target) {
|
14890 | return target
|
14891 | .domain(source.domain())
|
14892 | .range(source.range())
|
14893 | .interpolate(source.interpolate())
|
14894 | .clamp(source.clamp())
|
14895 | .unknown(source.unknown());
|
14896 | }
|
14897 |
|
14898 | function transformer$2() {
|
14899 | var domain = unit,
|
14900 | range = unit,
|
14901 | interpolate = interpolate$2,
|
14902 | transform,
|
14903 | untransform,
|
14904 | unknown,
|
14905 | clamp = identity$3,
|
14906 | piecewise,
|
14907 | output,
|
14908 | input;
|
14909 |
|
14910 | function rescale() {
|
14911 | var n = Math.min(domain.length, range.length);
|
14912 | if (clamp !== identity$3) clamp = clamper(domain[0], domain[n - 1]);
|
14913 | piecewise = n > 2 ? polymap : bimap;
|
14914 | output = input = null;
|
14915 | return scale;
|
14916 | }
|
14917 |
|
14918 | function scale(x) {
|
14919 | return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
|
14920 | }
|
14921 |
|
14922 | scale.invert = function(y) {
|
14923 | return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
|
14924 | };
|
14925 |
|
14926 | scale.domain = function(_) {
|
14927 | return arguments.length ? (domain = Array.from(_, number$1), rescale()) : domain.slice();
|
14928 | };
|
14929 |
|
14930 | scale.range = function(_) {
|
14931 | return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
|
14932 | };
|
14933 |
|
14934 | scale.rangeRound = function(_) {
|
14935 | return range = Array.from(_), interpolate = interpolateRound, rescale();
|
14936 | };
|
14937 |
|
14938 | scale.clamp = function(_) {
|
14939 | return arguments.length ? (clamp = _ ? true : identity$3, rescale()) : clamp !== identity$3;
|
14940 | };
|
14941 |
|
14942 | scale.interpolate = function(_) {
|
14943 | return arguments.length ? (interpolate = _, rescale()) : interpolate;
|
14944 | };
|
14945 |
|
14946 | scale.unknown = function(_) {
|
14947 | return arguments.length ? (unknown = _, scale) : unknown;
|
14948 | };
|
14949 |
|
14950 | return function(t, u) {
|
14951 | transform = t, untransform = u;
|
14952 | return rescale();
|
14953 | };
|
14954 | }
|
14955 |
|
14956 | function continuous() {
|
14957 | return transformer$2()(identity$3, identity$3);
|
14958 | }
|
14959 |
|
14960 | function tickFormat(start, stop, count, specifier) {
|
14961 | var step = tickStep(start, stop, count),
|
14962 | precision;
|
14963 | specifier = formatSpecifier(specifier == null ? ",f" : specifier);
|
14964 | switch (specifier.type) {
|
14965 | case "s": {
|
14966 | var value = Math.max(Math.abs(start), Math.abs(stop));
|
14967 | if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
|
14968 | return exports.formatPrefix(specifier, value);
|
14969 | }
|
14970 | case "":
|
14971 | case "e":
|
14972 | case "g":
|
14973 | case "p":
|
14974 | case "r": {
|
14975 | if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
|
14976 | break;
|
14977 | }
|
14978 | case "f":
|
14979 | case "%": {
|
14980 | if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
|
14981 | break;
|
14982 | }
|
14983 | }
|
14984 | return exports.format(specifier);
|
14985 | }
|
14986 |
|
14987 | function linearish(scale) {
|
14988 | var domain = scale.domain;
|
14989 |
|
14990 | scale.ticks = function(count) {
|
14991 | var d = domain();
|
14992 | return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
|
14993 | };
|
14994 |
|
14995 | scale.tickFormat = function(count, specifier) {
|
14996 | var d = domain();
|
14997 | return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
|
14998 | };
|
14999 |
|
15000 | scale.nice = function(count) {
|
15001 | if (count == null) count = 10;
|
15002 |
|
15003 | var d = domain();
|
15004 | var i0 = 0;
|
15005 | var i1 = d.length - 1;
|
15006 | var start = d[i0];
|
15007 | var stop = d[i1];
|
15008 | var prestep;
|
15009 | var step;
|
15010 | var maxIter = 10;
|
15011 |
|
15012 | if (stop < start) {
|
15013 | step = start, start = stop, stop = step;
|
15014 | step = i0, i0 = i1, i1 = step;
|
15015 | }
|
15016 |
|
15017 | while (maxIter-- > 0) {
|
15018 | step = tickIncrement(start, stop, count);
|
15019 | if (step === prestep) {
|
15020 | d[i0] = start;
|
15021 | d[i1] = stop;
|
15022 | return domain(d);
|
15023 | } else if (step > 0) {
|
15024 | start = Math.floor(start / step) * step;
|
15025 | stop = Math.ceil(stop / step) * step;
|
15026 | } else if (step < 0) {
|
15027 | start = Math.ceil(start * step) / step;
|
15028 | stop = Math.floor(stop * step) / step;
|
15029 | } else {
|
15030 | break;
|
15031 | }
|
15032 | prestep = step;
|
15033 | }
|
15034 |
|
15035 | return scale;
|
15036 | };
|
15037 |
|
15038 | return scale;
|
15039 | }
|
15040 |
|
15041 | function linear() {
|
15042 | var scale = continuous();
|
15043 |
|
15044 | scale.copy = function() {
|
15045 | return copy$1(scale, linear());
|
15046 | };
|
15047 |
|
15048 | initRange.apply(scale, arguments);
|
15049 |
|
15050 | return linearish(scale);
|
15051 | }
|
15052 |
|
15053 | function identity$2(domain) {
|
15054 | var unknown;
|
15055 |
|
15056 | function scale(x) {
|
15057 | return x == null || isNaN(x = +x) ? unknown : x;
|
15058 | }
|
15059 |
|
15060 | scale.invert = scale;
|
15061 |
|
15062 | scale.domain = scale.range = function(_) {
|
15063 | return arguments.length ? (domain = Array.from(_, number$1), scale) : domain.slice();
|
15064 | };
|
15065 |
|
15066 | scale.unknown = function(_) {
|
15067 | return arguments.length ? (unknown = _, scale) : unknown;
|
15068 | };
|
15069 |
|
15070 | scale.copy = function() {
|
15071 | return identity$2(domain).unknown(unknown);
|
15072 | };
|
15073 |
|
15074 | domain = arguments.length ? Array.from(domain, number$1) : [0, 1];
|
15075 |
|
15076 | return linearish(scale);
|
15077 | }
|
15078 |
|
15079 | function nice(domain, interval) {
|
15080 | domain = domain.slice();
|
15081 |
|
15082 | var i0 = 0,
|
15083 | i1 = domain.length - 1,
|
15084 | x0 = domain[i0],
|
15085 | x1 = domain[i1],
|
15086 | t;
|
15087 |
|
15088 | if (x1 < x0) {
|
15089 | t = i0, i0 = i1, i1 = t;
|
15090 | t = x0, x0 = x1, x1 = t;
|
15091 | }
|
15092 |
|
15093 | domain[i0] = interval.floor(x0);
|
15094 | domain[i1] = interval.ceil(x1);
|
15095 | return domain;
|
15096 | }
|
15097 |
|
15098 | function transformLog(x) {
|
15099 | return Math.log(x);
|
15100 | }
|
15101 |
|
15102 | function transformExp(x) {
|
15103 | return Math.exp(x);
|
15104 | }
|
15105 |
|
15106 | function transformLogn(x) {
|
15107 | return -Math.log(-x);
|
15108 | }
|
15109 |
|
15110 | function transformExpn(x) {
|
15111 | return -Math.exp(-x);
|
15112 | }
|
15113 |
|
15114 | function pow10(x) {
|
15115 | return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
|
15116 | }
|
15117 |
|
15118 | function powp(base) {
|
15119 | return base === 10 ? pow10
|
15120 | : base === Math.E ? Math.exp
|
15121 | : x => Math.pow(base, x);
|
15122 | }
|
15123 |
|
15124 | function logp(base) {
|
15125 | return base === Math.E ? Math.log
|
15126 | : base === 10 && Math.log10
|
15127 | || base === 2 && Math.log2
|
15128 | || (base = Math.log(base), x => Math.log(x) / base);
|
15129 | }
|
15130 |
|
15131 | function reflect(f) {
|
15132 | return (x, k) => -f(-x, k);
|
15133 | }
|
15134 |
|
15135 | function loggish(transform) {
|
15136 | const scale = transform(transformLog, transformExp);
|
15137 | const domain = scale.domain;
|
15138 | let base = 10;
|
15139 | let logs;
|
15140 | let pows;
|
15141 |
|
15142 | function rescale() {
|
15143 | logs = logp(base), pows = powp(base);
|
15144 | if (domain()[0] < 0) {
|
15145 | logs = reflect(logs), pows = reflect(pows);
|
15146 | transform(transformLogn, transformExpn);
|
15147 | } else {
|
15148 | transform(transformLog, transformExp);
|
15149 | }
|
15150 | return scale;
|
15151 | }
|
15152 |
|
15153 | scale.base = function(_) {
|
15154 | return arguments.length ? (base = +_, rescale()) : base;
|
15155 | };
|
15156 |
|
15157 | scale.domain = function(_) {
|
15158 | return arguments.length ? (domain(_), rescale()) : domain();
|
15159 | };
|
15160 |
|
15161 | scale.ticks = count => {
|
15162 | const d = domain();
|
15163 | let u = d[0];
|
15164 | let v = d[d.length - 1];
|
15165 | const r = v < u;
|
15166 |
|
15167 | if (r) ([u, v] = [v, u]);
|
15168 |
|
15169 | let i = logs(u);
|
15170 | let j = logs(v);
|
15171 | let k;
|
15172 | let t;
|
15173 | const n = count == null ? 10 : +count;
|
15174 | let z = [];
|
15175 |
|
15176 | if (!(base % 1) && j - i < n) {
|
15177 | i = Math.floor(i), j = Math.ceil(j);
|
15178 | if (u > 0) for (; i <= j; ++i) {
|
15179 | for (k = 1; k < base; ++k) {
|
15180 | t = i < 0 ? k / pows(-i) : k * pows(i);
|
15181 | if (t < u) continue;
|
15182 | if (t > v) break;
|
15183 | z.push(t);
|
15184 | }
|
15185 | } else for (; i <= j; ++i) {
|
15186 | for (k = base - 1; k >= 1; --k) {
|
15187 | t = i > 0 ? k / pows(-i) : k * pows(i);
|
15188 | if (t < u) continue;
|
15189 | if (t > v) break;
|
15190 | z.push(t);
|
15191 | }
|
15192 | }
|
15193 | if (z.length * 2 < n) z = ticks(u, v, n);
|
15194 | } else {
|
15195 | z = ticks(i, j, Math.min(j - i, n)).map(pows);
|
15196 | }
|
15197 | return r ? z.reverse() : z;
|
15198 | };
|
15199 |
|
15200 | scale.tickFormat = (count, specifier) => {
|
15201 | if (count == null) count = 10;
|
15202 | if (specifier == null) specifier = base === 10 ? "s" : ",";
|
15203 | if (typeof specifier !== "function") {
|
15204 | if (!(base % 1) && (specifier = formatSpecifier(specifier)).precision == null) specifier.trim = true;
|
15205 | specifier = exports.format(specifier);
|
15206 | }
|
15207 | if (count === Infinity) return specifier;
|
15208 | const k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
|
15209 | return d => {
|
15210 | let i = d / pows(Math.round(logs(d)));
|
15211 | if (i * base < base - 0.5) i *= base;
|
15212 | return i <= k ? specifier(d) : "";
|
15213 | };
|
15214 | };
|
15215 |
|
15216 | scale.nice = () => {
|
15217 | return domain(nice(domain(), {
|
15218 | floor: x => pows(Math.floor(logs(x))),
|
15219 | ceil: x => pows(Math.ceil(logs(x)))
|
15220 | }));
|
15221 | };
|
15222 |
|
15223 | return scale;
|
15224 | }
|
15225 |
|
15226 | function log() {
|
15227 | const scale = loggish(transformer$2()).domain([1, 10]);
|
15228 | scale.copy = () => copy$1(scale, log()).base(scale.base());
|
15229 | initRange.apply(scale, arguments);
|
15230 | return scale;
|
15231 | }
|
15232 |
|
15233 | function transformSymlog(c) {
|
15234 | return function(x) {
|
15235 | return Math.sign(x) * Math.log1p(Math.abs(x / c));
|
15236 | };
|
15237 | }
|
15238 |
|
15239 | function transformSymexp(c) {
|
15240 | return function(x) {
|
15241 | return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
|
15242 | };
|
15243 | }
|
15244 |
|
15245 | function symlogish(transform) {
|
15246 | var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
|
15247 |
|
15248 | scale.constant = function(_) {
|
15249 | return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
|
15250 | };
|
15251 |
|
15252 | return linearish(scale);
|
15253 | }
|
15254 |
|
15255 | function symlog() {
|
15256 | var scale = symlogish(transformer$2());
|
15257 |
|
15258 | scale.copy = function() {
|
15259 | return copy$1(scale, symlog()).constant(scale.constant());
|
15260 | };
|
15261 |
|
15262 | return initRange.apply(scale, arguments);
|
15263 | }
|
15264 |
|
15265 | function transformPow(exponent) {
|
15266 | return function(x) {
|
15267 | return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
|
15268 | };
|
15269 | }
|
15270 |
|
15271 | function transformSqrt(x) {
|
15272 | return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
|
15273 | }
|
15274 |
|
15275 | function transformSquare(x) {
|
15276 | return x < 0 ? -x * x : x * x;
|
15277 | }
|
15278 |
|
15279 | function powish(transform) {
|
15280 | var scale = transform(identity$3, identity$3),
|
15281 | exponent = 1;
|
15282 |
|
15283 | function rescale() {
|
15284 | return exponent === 1 ? transform(identity$3, identity$3)
|
15285 | : exponent === 0.5 ? transform(transformSqrt, transformSquare)
|
15286 | : transform(transformPow(exponent), transformPow(1 / exponent));
|
15287 | }
|
15288 |
|
15289 | scale.exponent = function(_) {
|
15290 | return arguments.length ? (exponent = +_, rescale()) : exponent;
|
15291 | };
|
15292 |
|
15293 | return linearish(scale);
|
15294 | }
|
15295 |
|
15296 | function pow() {
|
15297 | var scale = powish(transformer$2());
|
15298 |
|
15299 | scale.copy = function() {
|
15300 | return copy$1(scale, pow()).exponent(scale.exponent());
|
15301 | };
|
15302 |
|
15303 | initRange.apply(scale, arguments);
|
15304 |
|
15305 | return scale;
|
15306 | }
|
15307 |
|
15308 | function sqrt$1() {
|
15309 | return pow.apply(null, arguments).exponent(0.5);
|
15310 | }
|
15311 |
|
15312 | function square$1(x) {
|
15313 | return Math.sign(x) * x * x;
|
15314 | }
|
15315 |
|
15316 | function unsquare(x) {
|
15317 | return Math.sign(x) * Math.sqrt(Math.abs(x));
|
15318 | }
|
15319 |
|
15320 | function radial() {
|
15321 | var squared = continuous(),
|
15322 | range = [0, 1],
|
15323 | round = false,
|
15324 | unknown;
|
15325 |
|
15326 | function scale(x) {
|
15327 | var y = unsquare(squared(x));
|
15328 | return isNaN(y) ? unknown : round ? Math.round(y) : y;
|
15329 | }
|
15330 |
|
15331 | scale.invert = function(y) {
|
15332 | return squared.invert(square$1(y));
|
15333 | };
|
15334 |
|
15335 | scale.domain = function(_) {
|
15336 | return arguments.length ? (squared.domain(_), scale) : squared.domain();
|
15337 | };
|
15338 |
|
15339 | scale.range = function(_) {
|
15340 | return arguments.length ? (squared.range((range = Array.from(_, number$1)).map(square$1)), scale) : range.slice();
|
15341 | };
|
15342 |
|
15343 | scale.rangeRound = function(_) {
|
15344 | return scale.range(_).round(true);
|
15345 | };
|
15346 |
|
15347 | scale.round = function(_) {
|
15348 | return arguments.length ? (round = !!_, scale) : round;
|
15349 | };
|
15350 |
|
15351 | scale.clamp = function(_) {
|
15352 | return arguments.length ? (squared.clamp(_), scale) : squared.clamp();
|
15353 | };
|
15354 |
|
15355 | scale.unknown = function(_) {
|
15356 | return arguments.length ? (unknown = _, scale) : unknown;
|
15357 | };
|
15358 |
|
15359 | scale.copy = function() {
|
15360 | return radial(squared.domain(), range)
|
15361 | .round(round)
|
15362 | .clamp(squared.clamp())
|
15363 | .unknown(unknown);
|
15364 | };
|
15365 |
|
15366 | initRange.apply(scale, arguments);
|
15367 |
|
15368 | return linearish(scale);
|
15369 | }
|
15370 |
|
15371 | function quantile() {
|
15372 | var domain = [],
|
15373 | range = [],
|
15374 | thresholds = [],
|
15375 | unknown;
|
15376 |
|
15377 | function rescale() {
|
15378 | var i = 0, n = Math.max(1, range.length);
|
15379 | thresholds = new Array(n - 1);
|
15380 | while (++i < n) thresholds[i - 1] = quantileSorted(domain, i / n);
|
15381 | return scale;
|
15382 | }
|
15383 |
|
15384 | function scale(x) {
|
15385 | return x == null || isNaN(x = +x) ? unknown : range[bisect(thresholds, x)];
|
15386 | }
|
15387 |
|
15388 | scale.invertExtent = function(y) {
|
15389 | var i = range.indexOf(y);
|
15390 | return i < 0 ? [NaN, NaN] : [
|
15391 | i > 0 ? thresholds[i - 1] : domain[0],
|
15392 | i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
|
15393 | ];
|
15394 | };
|
15395 |
|
15396 | scale.domain = function(_) {
|
15397 | if (!arguments.length) return domain.slice();
|
15398 | domain = [];
|
15399 | for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
|
15400 | domain.sort(ascending$3);
|
15401 | return rescale();
|
15402 | };
|
15403 |
|
15404 | scale.range = function(_) {
|
15405 | return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
|
15406 | };
|
15407 |
|
15408 | scale.unknown = function(_) {
|
15409 | return arguments.length ? (unknown = _, scale) : unknown;
|
15410 | };
|
15411 |
|
15412 | scale.quantiles = function() {
|
15413 | return thresholds.slice();
|
15414 | };
|
15415 |
|
15416 | scale.copy = function() {
|
15417 | return quantile()
|
15418 | .domain(domain)
|
15419 | .range(range)
|
15420 | .unknown(unknown);
|
15421 | };
|
15422 |
|
15423 | return initRange.apply(scale, arguments);
|
15424 | }
|
15425 |
|
15426 | function quantize() {
|
15427 | var x0 = 0,
|
15428 | x1 = 1,
|
15429 | n = 1,
|
15430 | domain = [0.5],
|
15431 | range = [0, 1],
|
15432 | unknown;
|
15433 |
|
15434 | function scale(x) {
|
15435 | return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
|
15436 | }
|
15437 |
|
15438 | function rescale() {
|
15439 | var i = -1;
|
15440 | domain = new Array(n);
|
15441 | while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
|
15442 | return scale;
|
15443 | }
|
15444 |
|
15445 | scale.domain = function(_) {
|
15446 | return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
|
15447 | };
|
15448 |
|
15449 | scale.range = function(_) {
|
15450 | return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
|
15451 | };
|
15452 |
|
15453 | scale.invertExtent = function(y) {
|
15454 | var i = range.indexOf(y);
|
15455 | return i < 0 ? [NaN, NaN]
|
15456 | : i < 1 ? [x0, domain[0]]
|
15457 | : i >= n ? [domain[n - 1], x1]
|
15458 | : [domain[i - 1], domain[i]];
|
15459 | };
|
15460 |
|
15461 | scale.unknown = function(_) {
|
15462 | return arguments.length ? (unknown = _, scale) : scale;
|
15463 | };
|
15464 |
|
15465 | scale.thresholds = function() {
|
15466 | return domain.slice();
|
15467 | };
|
15468 |
|
15469 | scale.copy = function() {
|
15470 | return quantize()
|
15471 | .domain([x0, x1])
|
15472 | .range(range)
|
15473 | .unknown(unknown);
|
15474 | };
|
15475 |
|
15476 | return initRange.apply(linearish(scale), arguments);
|
15477 | }
|
15478 |
|
15479 | function threshold() {
|
15480 | var domain = [0.5],
|
15481 | range = [0, 1],
|
15482 | unknown,
|
15483 | n = 1;
|
15484 |
|
15485 | function scale(x) {
|
15486 | return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
|
15487 | }
|
15488 |
|
15489 | scale.domain = function(_) {
|
15490 | return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
|
15491 | };
|
15492 |
|
15493 | scale.range = function(_) {
|
15494 | return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
|
15495 | };
|
15496 |
|
15497 | scale.invertExtent = function(y) {
|
15498 | var i = range.indexOf(y);
|
15499 | return [domain[i - 1], domain[i]];
|
15500 | };
|
15501 |
|
15502 | scale.unknown = function(_) {
|
15503 | return arguments.length ? (unknown = _, scale) : unknown;
|
15504 | };
|
15505 |
|
15506 | scale.copy = function() {
|
15507 | return threshold()
|
15508 | .domain(domain)
|
15509 | .range(range)
|
15510 | .unknown(unknown);
|
15511 | };
|
15512 |
|
15513 | return initRange.apply(scale, arguments);
|
15514 | }
|
15515 |
|
15516 | var t0 = new Date,
|
15517 | t1 = new Date;
|
15518 |
|
15519 | function newInterval(floori, offseti, count, field) {
|
15520 |
|
15521 | function interval(date) {
|
15522 | return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
|
15523 | }
|
15524 |
|
15525 | interval.floor = function(date) {
|
15526 | return floori(date = new Date(+date)), date;
|
15527 | };
|
15528 |
|
15529 | interval.ceil = function(date) {
|
15530 | return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
|
15531 | };
|
15532 |
|
15533 | interval.round = function(date) {
|
15534 | var d0 = interval(date),
|
15535 | d1 = interval.ceil(date);
|
15536 | return date - d0 < d1 - date ? d0 : d1;
|
15537 | };
|
15538 |
|
15539 | interval.offset = function(date, step) {
|
15540 | return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
|
15541 | };
|
15542 |
|
15543 | interval.range = function(start, stop, step) {
|
15544 | var range = [], previous;
|
15545 | start = interval.ceil(start);
|
15546 | step = step == null ? 1 : Math.floor(step);
|
15547 | if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
|
15548 | do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
|
15549 | while (previous < start && start < stop);
|
15550 | return range;
|
15551 | };
|
15552 |
|
15553 | interval.filter = function(test) {
|
15554 | return newInterval(function(date) {
|
15555 | if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
|
15556 | }, function(date, step) {
|
15557 | if (date >= date) {
|
15558 | if (step < 0) while (++step <= 0) {
|
15559 | while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
|
15560 | } else while (--step >= 0) {
|
15561 | while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
|
15562 | }
|
15563 | }
|
15564 | });
|
15565 | };
|
15566 |
|
15567 | if (count) {
|
15568 | interval.count = function(start, end) {
|
15569 | t0.setTime(+start), t1.setTime(+end);
|
15570 | floori(t0), floori(t1);
|
15571 | return Math.floor(count(t0, t1));
|
15572 | };
|
15573 |
|
15574 | interval.every = function(step) {
|
15575 | step = Math.floor(step);
|
15576 | return !isFinite(step) || !(step > 0) ? null
|
15577 | : !(step > 1) ? interval
|
15578 | : interval.filter(field
|
15579 | ? function(d) { return field(d) % step === 0; }
|
15580 | : function(d) { return interval.count(0, d) % step === 0; });
|
15581 | };
|
15582 | }
|
15583 |
|
15584 | return interval;
|
15585 | }
|
15586 |
|
15587 | var millisecond = newInterval(function() {
|
15588 | // noop
|
15589 | }, function(date, step) {
|
15590 | date.setTime(+date + step);
|
15591 | }, function(start, end) {
|
15592 | return end - start;
|
15593 | });
|
15594 |
|
15595 | // An optimized implementation for this simple case.
|
15596 | millisecond.every = function(k) {
|
15597 | k = Math.floor(k);
|
15598 | if (!isFinite(k) || !(k > 0)) return null;
|
15599 | if (!(k > 1)) return millisecond;
|
15600 | return newInterval(function(date) {
|
15601 | date.setTime(Math.floor(date / k) * k);
|
15602 | }, function(date, step) {
|
15603 | date.setTime(+date + step * k);
|
15604 | }, function(start, end) {
|
15605 | return (end - start) / k;
|
15606 | });
|
15607 | };
|
15608 |
|
15609 | var millisecond$1 = millisecond;
|
15610 | var milliseconds = millisecond.range;
|
15611 |
|
15612 | const durationSecond = 1000;
|
15613 | const durationMinute = durationSecond * 60;
|
15614 | const durationHour = durationMinute * 60;
|
15615 | const durationDay = durationHour * 24;
|
15616 | const durationWeek = durationDay * 7;
|
15617 | const durationMonth = durationDay * 30;
|
15618 | const durationYear = durationDay * 365;
|
15619 |
|
15620 | var second = newInterval(function(date) {
|
15621 | date.setTime(date - date.getMilliseconds());
|
15622 | }, function(date, step) {
|
15623 | date.setTime(+date + step * durationSecond);
|
15624 | }, function(start, end) {
|
15625 | return (end - start) / durationSecond;
|
15626 | }, function(date) {
|
15627 | return date.getUTCSeconds();
|
15628 | });
|
15629 |
|
15630 | var utcSecond = second;
|
15631 | var seconds = second.range;
|
15632 |
|
15633 | var minute = newInterval(function(date) {
|
15634 | date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
|
15635 | }, function(date, step) {
|
15636 | date.setTime(+date + step * durationMinute);
|
15637 | }, function(start, end) {
|
15638 | return (end - start) / durationMinute;
|
15639 | }, function(date) {
|
15640 | return date.getMinutes();
|
15641 | });
|
15642 |
|
15643 | var timeMinute = minute;
|
15644 | var minutes = minute.range;
|
15645 |
|
15646 | var hour = newInterval(function(date) {
|
15647 | date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
|
15648 | }, function(date, step) {
|
15649 | date.setTime(+date + step * durationHour);
|
15650 | }, function(start, end) {
|
15651 | return (end - start) / durationHour;
|
15652 | }, function(date) {
|
15653 | return date.getHours();
|
15654 | });
|
15655 |
|
15656 | var timeHour = hour;
|
15657 | var hours = hour.range;
|
15658 |
|
15659 | var day = newInterval(
|
15660 | date => date.setHours(0, 0, 0, 0),
|
15661 | (date, step) => date.setDate(date.getDate() + step),
|
15662 | (start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay,
|
15663 | date => date.getDate() - 1
|
15664 | );
|
15665 |
|
15666 | var timeDay = day;
|
15667 | var days = day.range;
|
15668 |
|
15669 | function weekday(i) {
|
15670 | return newInterval(function(date) {
|
15671 | date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
|
15672 | date.setHours(0, 0, 0, 0);
|
15673 | }, function(date, step) {
|
15674 | date.setDate(date.getDate() + step * 7);
|
15675 | }, function(start, end) {
|
15676 | return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
|
15677 | });
|
15678 | }
|
15679 |
|
15680 | var sunday = weekday(0);
|
15681 | var monday = weekday(1);
|
15682 | var tuesday = weekday(2);
|
15683 | var wednesday = weekday(3);
|
15684 | var thursday = weekday(4);
|
15685 | var friday = weekday(5);
|
15686 | var saturday = weekday(6);
|
15687 |
|
15688 | var sundays = sunday.range;
|
15689 | var mondays = monday.range;
|
15690 | var tuesdays = tuesday.range;
|
15691 | var wednesdays = wednesday.range;
|
15692 | var thursdays = thursday.range;
|
15693 | var fridays = friday.range;
|
15694 | var saturdays = saturday.range;
|
15695 |
|
15696 | var month = newInterval(function(date) {
|
15697 | date.setDate(1);
|
15698 | date.setHours(0, 0, 0, 0);
|
15699 | }, function(date, step) {
|
15700 | date.setMonth(date.getMonth() + step);
|
15701 | }, function(start, end) {
|
15702 | return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
|
15703 | }, function(date) {
|
15704 | return date.getMonth();
|
15705 | });
|
15706 |
|
15707 | var timeMonth = month;
|
15708 | var months = month.range;
|
15709 |
|
15710 | var year = newInterval(function(date) {
|
15711 | date.setMonth(0, 1);
|
15712 | date.setHours(0, 0, 0, 0);
|
15713 | }, function(date, step) {
|
15714 | date.setFullYear(date.getFullYear() + step);
|
15715 | }, function(start, end) {
|
15716 | return end.getFullYear() - start.getFullYear();
|
15717 | }, function(date) {
|
15718 | return date.getFullYear();
|
15719 | });
|
15720 |
|
15721 | // An optimized implementation for this simple case.
|
15722 | year.every = function(k) {
|
15723 | return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
|
15724 | date.setFullYear(Math.floor(date.getFullYear() / k) * k);
|
15725 | date.setMonth(0, 1);
|
15726 | date.setHours(0, 0, 0, 0);
|
15727 | }, function(date, step) {
|
15728 | date.setFullYear(date.getFullYear() + step * k);
|
15729 | });
|
15730 | };
|
15731 |
|
15732 | var timeYear = year;
|
15733 | var years = year.range;
|
15734 |
|
15735 | var utcMinute = newInterval(function(date) {
|
15736 | date.setUTCSeconds(0, 0);
|
15737 | }, function(date, step) {
|
15738 | date.setTime(+date + step * durationMinute);
|
15739 | }, function(start, end) {
|
15740 | return (end - start) / durationMinute;
|
15741 | }, function(date) {
|
15742 | return date.getUTCMinutes();
|
15743 | });
|
15744 |
|
15745 | var utcMinute$1 = utcMinute;
|
15746 | var utcMinutes = utcMinute.range;
|
15747 |
|
15748 | var utcHour = newInterval(function(date) {
|
15749 | date.setUTCMinutes(0, 0, 0);
|
15750 | }, function(date, step) {
|
15751 | date.setTime(+date + step * durationHour);
|
15752 | }, function(start, end) {
|
15753 | return (end - start) / durationHour;
|
15754 | }, function(date) {
|
15755 | return date.getUTCHours();
|
15756 | });
|
15757 |
|
15758 | var utcHour$1 = utcHour;
|
15759 | var utcHours = utcHour.range;
|
15760 |
|
15761 | var utcDay = newInterval(function(date) {
|
15762 | date.setUTCHours(0, 0, 0, 0);
|
15763 | }, function(date, step) {
|
15764 | date.setUTCDate(date.getUTCDate() + step);
|
15765 | }, function(start, end) {
|
15766 | return (end - start) / durationDay;
|
15767 | }, function(date) {
|
15768 | return date.getUTCDate() - 1;
|
15769 | });
|
15770 |
|
15771 | var utcDay$1 = utcDay;
|
15772 | var utcDays = utcDay.range;
|
15773 |
|
15774 | function utcWeekday(i) {
|
15775 | return newInterval(function(date) {
|
15776 | date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
|
15777 | date.setUTCHours(0, 0, 0, 0);
|
15778 | }, function(date, step) {
|
15779 | date.setUTCDate(date.getUTCDate() + step * 7);
|
15780 | }, function(start, end) {
|
15781 | return (end - start) / durationWeek;
|
15782 | });
|
15783 | }
|
15784 |
|
15785 | var utcSunday = utcWeekday(0);
|
15786 | var utcMonday = utcWeekday(1);
|
15787 | var utcTuesday = utcWeekday(2);
|
15788 | var utcWednesday = utcWeekday(3);
|
15789 | var utcThursday = utcWeekday(4);
|
15790 | var utcFriday = utcWeekday(5);
|
15791 | var utcSaturday = utcWeekday(6);
|
15792 |
|
15793 | var utcSundays = utcSunday.range;
|
15794 | var utcMondays = utcMonday.range;
|
15795 | var utcTuesdays = utcTuesday.range;
|
15796 | var utcWednesdays = utcWednesday.range;
|
15797 | var utcThursdays = utcThursday.range;
|
15798 | var utcFridays = utcFriday.range;
|
15799 | var utcSaturdays = utcSaturday.range;
|
15800 |
|
15801 | var utcMonth = newInterval(function(date) {
|
15802 | date.setUTCDate(1);
|
15803 | date.setUTCHours(0, 0, 0, 0);
|
15804 | }, function(date, step) {
|
15805 | date.setUTCMonth(date.getUTCMonth() + step);
|
15806 | }, function(start, end) {
|
15807 | return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
|
15808 | }, function(date) {
|
15809 | return date.getUTCMonth();
|
15810 | });
|
15811 |
|
15812 | var utcMonth$1 = utcMonth;
|
15813 | var utcMonths = utcMonth.range;
|
15814 |
|
15815 | var utcYear = newInterval(function(date) {
|
15816 | date.setUTCMonth(0, 1);
|
15817 | date.setUTCHours(0, 0, 0, 0);
|
15818 | }, function(date, step) {
|
15819 | date.setUTCFullYear(date.getUTCFullYear() + step);
|
15820 | }, function(start, end) {
|
15821 | return end.getUTCFullYear() - start.getUTCFullYear();
|
15822 | }, function(date) {
|
15823 | return date.getUTCFullYear();
|
15824 | });
|
15825 |
|
15826 | // An optimized implementation for this simple case.
|
15827 | utcYear.every = function(k) {
|
15828 | return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
|
15829 | date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
|
15830 | date.setUTCMonth(0, 1);
|
15831 | date.setUTCHours(0, 0, 0, 0);
|
15832 | }, function(date, step) {
|
15833 | date.setUTCFullYear(date.getUTCFullYear() + step * k);
|
15834 | });
|
15835 | };
|
15836 |
|
15837 | var utcYear$1 = utcYear;
|
15838 | var utcYears = utcYear.range;
|
15839 |
|
15840 | function ticker(year, month, week, day, hour, minute) {
|
15841 |
|
15842 | const tickIntervals = [
|
15843 | [utcSecond, 1, durationSecond],
|
15844 | [utcSecond, 5, 5 * durationSecond],
|
15845 | [utcSecond, 15, 15 * durationSecond],
|
15846 | [utcSecond, 30, 30 * durationSecond],
|
15847 | [minute, 1, durationMinute],
|
15848 | [minute, 5, 5 * durationMinute],
|
15849 | [minute, 15, 15 * durationMinute],
|
15850 | [minute, 30, 30 * durationMinute],
|
15851 | [ hour, 1, durationHour ],
|
15852 | [ hour, 3, 3 * durationHour ],
|
15853 | [ hour, 6, 6 * durationHour ],
|
15854 | [ hour, 12, 12 * durationHour ],
|
15855 | [ day, 1, durationDay ],
|
15856 | [ day, 2, 2 * durationDay ],
|
15857 | [ week, 1, durationWeek ],
|
15858 | [ month, 1, durationMonth ],
|
15859 | [ month, 3, 3 * durationMonth ],
|
15860 | [ year, 1, durationYear ]
|
15861 | ];
|
15862 |
|
15863 | function ticks(start, stop, count) {
|
15864 | const reverse = stop < start;
|
15865 | if (reverse) [start, stop] = [stop, start];
|
15866 | const interval = count && typeof count.range === "function" ? count : tickInterval(start, stop, count);
|
15867 | const ticks = interval ? interval.range(start, +stop + 1) : []; // inclusive stop
|
15868 | return reverse ? ticks.reverse() : ticks;
|
15869 | }
|
15870 |
|
15871 | function tickInterval(start, stop, count) {
|
15872 | const target = Math.abs(stop - start) / count;
|
15873 | const i = bisector(([,, step]) => step).right(tickIntervals, target);
|
15874 | if (i === tickIntervals.length) return year.every(tickStep(start / durationYear, stop / durationYear, count));
|
15875 | if (i === 0) return millisecond$1.every(Math.max(tickStep(start, stop, count), 1));
|
15876 | const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
|
15877 | return t.every(step);
|
15878 | }
|
15879 |
|
15880 | return [ticks, tickInterval];
|
15881 | }
|
15882 |
|
15883 | const [utcTicks, utcTickInterval] = ticker(utcYear$1, utcMonth$1, utcSunday, utcDay$1, utcHour$1, utcMinute$1);
|
15884 | const [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, sunday, timeDay, timeHour, timeMinute);
|
15885 |
|
15886 | function localDate(d) {
|
15887 | if (0 <= d.y && d.y < 100) {
|
15888 | var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
|
15889 | date.setFullYear(d.y);
|
15890 | return date;
|
15891 | }
|
15892 | return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
|
15893 | }
|
15894 |
|
15895 | function utcDate(d) {
|
15896 | if (0 <= d.y && d.y < 100) {
|
15897 | var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
|
15898 | date.setUTCFullYear(d.y);
|
15899 | return date;
|
15900 | }
|
15901 | return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
|
15902 | }
|
15903 |
|
15904 | function newDate(y, m, d) {
|
15905 | return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
|
15906 | }
|
15907 |
|
15908 | function formatLocale(locale) {
|
15909 | var locale_dateTime = locale.dateTime,
|
15910 | locale_date = locale.date,
|
15911 | locale_time = locale.time,
|
15912 | locale_periods = locale.periods,
|
15913 | locale_weekdays = locale.days,
|
15914 | locale_shortWeekdays = locale.shortDays,
|
15915 | locale_months = locale.months,
|
15916 | locale_shortMonths = locale.shortMonths;
|
15917 |
|
15918 | var periodRe = formatRe(locale_periods),
|
15919 | periodLookup = formatLookup(locale_periods),
|
15920 | weekdayRe = formatRe(locale_weekdays),
|
15921 | weekdayLookup = formatLookup(locale_weekdays),
|
15922 | shortWeekdayRe = formatRe(locale_shortWeekdays),
|
15923 | shortWeekdayLookup = formatLookup(locale_shortWeekdays),
|
15924 | monthRe = formatRe(locale_months),
|
15925 | monthLookup = formatLookup(locale_months),
|
15926 | shortMonthRe = formatRe(locale_shortMonths),
|
15927 | shortMonthLookup = formatLookup(locale_shortMonths);
|
15928 |
|
15929 | var formats = {
|
15930 | "a": formatShortWeekday,
|
15931 | "A": formatWeekday,
|
15932 | "b": formatShortMonth,
|
15933 | "B": formatMonth,
|
15934 | "c": null,
|
15935 | "d": formatDayOfMonth,
|
15936 | "e": formatDayOfMonth,
|
15937 | "f": formatMicroseconds,
|
15938 | "g": formatYearISO,
|
15939 | "G": formatFullYearISO,
|
15940 | "H": formatHour24,
|
15941 | "I": formatHour12,
|
15942 | "j": formatDayOfYear,
|
15943 | "L": formatMilliseconds,
|
15944 | "m": formatMonthNumber,
|
15945 | "M": formatMinutes,
|
15946 | "p": formatPeriod,
|
15947 | "q": formatQuarter,
|
15948 | "Q": formatUnixTimestamp,
|
15949 | "s": formatUnixTimestampSeconds,
|
15950 | "S": formatSeconds,
|
15951 | "u": formatWeekdayNumberMonday,
|
15952 | "U": formatWeekNumberSunday,
|
15953 | "V": formatWeekNumberISO,
|
15954 | "w": formatWeekdayNumberSunday,
|
15955 | "W": formatWeekNumberMonday,
|
15956 | "x": null,
|
15957 | "X": null,
|
15958 | "y": formatYear,
|
15959 | "Y": formatFullYear,
|
15960 | "Z": formatZone,
|
15961 | "%": formatLiteralPercent
|
15962 | };
|
15963 |
|
15964 | var utcFormats = {
|
15965 | "a": formatUTCShortWeekday,
|
15966 | "A": formatUTCWeekday,
|
15967 | "b": formatUTCShortMonth,
|
15968 | "B": formatUTCMonth,
|
15969 | "c": null,
|
15970 | "d": formatUTCDayOfMonth,
|
15971 | "e": formatUTCDayOfMonth,
|
15972 | "f": formatUTCMicroseconds,
|
15973 | "g": formatUTCYearISO,
|
15974 | "G": formatUTCFullYearISO,
|
15975 | "H": formatUTCHour24,
|
15976 | "I": formatUTCHour12,
|
15977 | "j": formatUTCDayOfYear,
|
15978 | "L": formatUTCMilliseconds,
|
15979 | "m": formatUTCMonthNumber,
|
15980 | "M": formatUTCMinutes,
|
15981 | "p": formatUTCPeriod,
|
15982 | "q": formatUTCQuarter,
|
15983 | "Q": formatUnixTimestamp,
|
15984 | "s": formatUnixTimestampSeconds,
|
15985 | "S": formatUTCSeconds,
|
15986 | "u": formatUTCWeekdayNumberMonday,
|
15987 | "U": formatUTCWeekNumberSunday,
|
15988 | "V": formatUTCWeekNumberISO,
|
15989 | "w": formatUTCWeekdayNumberSunday,
|
15990 | "W": formatUTCWeekNumberMonday,
|
15991 | "x": null,
|
15992 | "X": null,
|
15993 | "y": formatUTCYear,
|
15994 | "Y": formatUTCFullYear,
|
15995 | "Z": formatUTCZone,
|
15996 | "%": formatLiteralPercent
|
15997 | };
|
15998 |
|
15999 | var parses = {
|
16000 | "a": parseShortWeekday,
|
16001 | "A": parseWeekday,
|
16002 | "b": parseShortMonth,
|
16003 | "B": parseMonth,
|
16004 | "c": parseLocaleDateTime,
|
16005 | "d": parseDayOfMonth,
|
16006 | "e": parseDayOfMonth,
|
16007 | "f": parseMicroseconds,
|
16008 | "g": parseYear,
|
16009 | "G": parseFullYear,
|
16010 | "H": parseHour24,
|
16011 | "I": parseHour24,
|
16012 | "j": parseDayOfYear,
|
16013 | "L": parseMilliseconds,
|
16014 | "m": parseMonthNumber,
|
16015 | "M": parseMinutes,
|
16016 | "p": parsePeriod,
|
16017 | "q": parseQuarter,
|
16018 | "Q": parseUnixTimestamp,
|
16019 | "s": parseUnixTimestampSeconds,
|
16020 | "S": parseSeconds,
|
16021 | "u": parseWeekdayNumberMonday,
|
16022 | "U": parseWeekNumberSunday,
|
16023 | "V": parseWeekNumberISO,
|
16024 | "w": parseWeekdayNumberSunday,
|
16025 | "W": parseWeekNumberMonday,
|
16026 | "x": parseLocaleDate,
|
16027 | "X": parseLocaleTime,
|
16028 | "y": parseYear,
|
16029 | "Y": parseFullYear,
|
16030 | "Z": parseZone,
|
16031 | "%": parseLiteralPercent
|
16032 | };
|
16033 |
|
16034 | // These recursive directive definitions must be deferred.
|
16035 | formats.x = newFormat(locale_date, formats);
|
16036 | formats.X = newFormat(locale_time, formats);
|
16037 | formats.c = newFormat(locale_dateTime, formats);
|
16038 | utcFormats.x = newFormat(locale_date, utcFormats);
|
16039 | utcFormats.X = newFormat(locale_time, utcFormats);
|
16040 | utcFormats.c = newFormat(locale_dateTime, utcFormats);
|
16041 |
|
16042 | function newFormat(specifier, formats) {
|
16043 | return function(date) {
|
16044 | var string = [],
|
16045 | i = -1,
|
16046 | j = 0,
|
16047 | n = specifier.length,
|
16048 | c,
|
16049 | pad,
|
16050 | format;
|
16051 |
|
16052 | if (!(date instanceof Date)) date = new Date(+date);
|
16053 |
|
16054 | while (++i < n) {
|
16055 | if (specifier.charCodeAt(i) === 37) {
|
16056 | string.push(specifier.slice(j, i));
|
16057 | if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
|
16058 | else pad = c === "e" ? " " : "0";
|
16059 | if (format = formats[c]) c = format(date, pad);
|
16060 | string.push(c);
|
16061 | j = i + 1;
|
16062 | }
|
16063 | }
|
16064 |
|
16065 | string.push(specifier.slice(j, i));
|
16066 | return string.join("");
|
16067 | };
|
16068 | }
|
16069 |
|
16070 | function newParse(specifier, Z) {
|
16071 | return function(string) {
|
16072 | var d = newDate(1900, undefined, 1),
|
16073 | i = parseSpecifier(d, specifier, string += "", 0),
|
16074 | week, day;
|
16075 | if (i != string.length) return null;
|
16076 |
|
16077 | // If a UNIX timestamp is specified, return it.
|
16078 | if ("Q" in d) return new Date(d.Q);
|
16079 | if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
|
16080 |
|
16081 | // If this is utcParse, never use the local timezone.
|
16082 | if (Z && !("Z" in d)) d.Z = 0;
|
16083 |
|
16084 | // The am-pm flag is 0 for AM, and 1 for PM.
|
16085 | if ("p" in d) d.H = d.H % 12 + d.p * 12;
|
16086 |
|
16087 | // If the month was not specified, inherit from the quarter.
|
16088 | if (d.m === undefined) d.m = "q" in d ? d.q : 0;
|
16089 |
|
16090 | // Convert day-of-week and week-of-year to day-of-year.
|
16091 | if ("V" in d) {
|
16092 | if (d.V < 1 || d.V > 53) return null;
|
16093 | if (!("w" in d)) d.w = 1;
|
16094 | if ("Z" in d) {
|
16095 | week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
|
16096 | week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
|
16097 | week = utcDay$1.offset(week, (d.V - 1) * 7);
|
16098 | d.y = week.getUTCFullYear();
|
16099 | d.m = week.getUTCMonth();
|
16100 | d.d = week.getUTCDate() + (d.w + 6) % 7;
|
16101 | } else {
|
16102 | week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
|
16103 | week = day > 4 || day === 0 ? monday.ceil(week) : monday(week);
|
16104 | week = timeDay.offset(week, (d.V - 1) * 7);
|
16105 | d.y = week.getFullYear();
|
16106 | d.m = week.getMonth();
|
16107 | d.d = week.getDate() + (d.w + 6) % 7;
|
16108 | }
|
16109 | } else if ("W" in d || "U" in d) {
|
16110 | if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
|
16111 | day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
|
16112 | d.m = 0;
|
16113 | d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
|
16114 | }
|
16115 |
|
16116 | // If a time zone is specified, all fields are interpreted as UTC and then
|
16117 | // offset according to the specified time zone.
|
16118 | if ("Z" in d) {
|
16119 | d.H += d.Z / 100 | 0;
|
16120 | d.M += d.Z % 100;
|
16121 | return utcDate(d);
|
16122 | }
|
16123 |
|
16124 | // Otherwise, all fields are in local time.
|
16125 | return localDate(d);
|
16126 | };
|
16127 | }
|
16128 |
|
16129 | function parseSpecifier(d, specifier, string, j) {
|
16130 | var i = 0,
|
16131 | n = specifier.length,
|
16132 | m = string.length,
|
16133 | c,
|
16134 | parse;
|
16135 |
|
16136 | while (i < n) {
|
16137 | if (j >= m) return -1;
|
16138 | c = specifier.charCodeAt(i++);
|
16139 | if (c === 37) {
|
16140 | c = specifier.charAt(i++);
|
16141 | parse = parses[c in pads ? specifier.charAt(i++) : c];
|
16142 | if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
|
16143 | } else if (c != string.charCodeAt(j++)) {
|
16144 | return -1;
|
16145 | }
|
16146 | }
|
16147 |
|
16148 | return j;
|
16149 | }
|
16150 |
|
16151 | function parsePeriod(d, string, i) {
|
16152 | var n = periodRe.exec(string.slice(i));
|
16153 | return n ? (d.p = periodLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16154 | }
|
16155 |
|
16156 | function parseShortWeekday(d, string, i) {
|
16157 | var n = shortWeekdayRe.exec(string.slice(i));
|
16158 | return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16159 | }
|
16160 |
|
16161 | function parseWeekday(d, string, i) {
|
16162 | var n = weekdayRe.exec(string.slice(i));
|
16163 | return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16164 | }
|
16165 |
|
16166 | function parseShortMonth(d, string, i) {
|
16167 | var n = shortMonthRe.exec(string.slice(i));
|
16168 | return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16169 | }
|
16170 |
|
16171 | function parseMonth(d, string, i) {
|
16172 | var n = monthRe.exec(string.slice(i));
|
16173 | return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16174 | }
|
16175 |
|
16176 | function parseLocaleDateTime(d, string, i) {
|
16177 | return parseSpecifier(d, locale_dateTime, string, i);
|
16178 | }
|
16179 |
|
16180 | function parseLocaleDate(d, string, i) {
|
16181 | return parseSpecifier(d, locale_date, string, i);
|
16182 | }
|
16183 |
|
16184 | function parseLocaleTime(d, string, i) {
|
16185 | return parseSpecifier(d, locale_time, string, i);
|
16186 | }
|
16187 |
|
16188 | function formatShortWeekday(d) {
|
16189 | return locale_shortWeekdays[d.getDay()];
|
16190 | }
|
16191 |
|
16192 | function formatWeekday(d) {
|
16193 | return locale_weekdays[d.getDay()];
|
16194 | }
|
16195 |
|
16196 | function formatShortMonth(d) {
|
16197 | return locale_shortMonths[d.getMonth()];
|
16198 | }
|
16199 |
|
16200 | function formatMonth(d) {
|
16201 | return locale_months[d.getMonth()];
|
16202 | }
|
16203 |
|
16204 | function formatPeriod(d) {
|
16205 | return locale_periods[+(d.getHours() >= 12)];
|
16206 | }
|
16207 |
|
16208 | function formatQuarter(d) {
|
16209 | return 1 + ~~(d.getMonth() / 3);
|
16210 | }
|
16211 |
|
16212 | function formatUTCShortWeekday(d) {
|
16213 | return locale_shortWeekdays[d.getUTCDay()];
|
16214 | }
|
16215 |
|
16216 | function formatUTCWeekday(d) {
|
16217 | return locale_weekdays[d.getUTCDay()];
|
16218 | }
|
16219 |
|
16220 | function formatUTCShortMonth(d) {
|
16221 | return locale_shortMonths[d.getUTCMonth()];
|
16222 | }
|
16223 |
|
16224 | function formatUTCMonth(d) {
|
16225 | return locale_months[d.getUTCMonth()];
|
16226 | }
|
16227 |
|
16228 | function formatUTCPeriod(d) {
|
16229 | return locale_periods[+(d.getUTCHours() >= 12)];
|
16230 | }
|
16231 |
|
16232 | function formatUTCQuarter(d) {
|
16233 | return 1 + ~~(d.getUTCMonth() / 3);
|
16234 | }
|
16235 |
|
16236 | return {
|
16237 | format: function(specifier) {
|
16238 | var f = newFormat(specifier += "", formats);
|
16239 | f.toString = function() { return specifier; };
|
16240 | return f;
|
16241 | },
|
16242 | parse: function(specifier) {
|
16243 | var p = newParse(specifier += "", false);
|
16244 | p.toString = function() { return specifier; };
|
16245 | return p;
|
16246 | },
|
16247 | utcFormat: function(specifier) {
|
16248 | var f = newFormat(specifier += "", utcFormats);
|
16249 | f.toString = function() { return specifier; };
|
16250 | return f;
|
16251 | },
|
16252 | utcParse: function(specifier) {
|
16253 | var p = newParse(specifier += "", true);
|
16254 | p.toString = function() { return specifier; };
|
16255 | return p;
|
16256 | }
|
16257 | };
|
16258 | }
|
16259 |
|
16260 | var pads = {"-": "", "_": " ", "0": "0"},
|
16261 | numberRe = /^\s*\d+/, // note: ignores next directive
|
16262 | percentRe = /^%/,
|
16263 | requoteRe = /[\\^$*+?|[\]().{}]/g;
|
16264 |
|
16265 | function pad(value, fill, width) {
|
16266 | var sign = value < 0 ? "-" : "",
|
16267 | string = (sign ? -value : value) + "",
|
16268 | length = string.length;
|
16269 | return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
|
16270 | }
|
16271 |
|
16272 | function requote(s) {
|
16273 | return s.replace(requoteRe, "\\$&");
|
16274 | }
|
16275 |
|
16276 | function formatRe(names) {
|
16277 | return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
|
16278 | }
|
16279 |
|
16280 | function formatLookup(names) {
|
16281 | return new Map(names.map((name, i) => [name.toLowerCase(), i]));
|
16282 | }
|
16283 |
|
16284 | function parseWeekdayNumberSunday(d, string, i) {
|
16285 | var n = numberRe.exec(string.slice(i, i + 1));
|
16286 | return n ? (d.w = +n[0], i + n[0].length) : -1;
|
16287 | }
|
16288 |
|
16289 | function parseWeekdayNumberMonday(d, string, i) {
|
16290 | var n = numberRe.exec(string.slice(i, i + 1));
|
16291 | return n ? (d.u = +n[0], i + n[0].length) : -1;
|
16292 | }
|
16293 |
|
16294 | function parseWeekNumberSunday(d, string, i) {
|
16295 | var n = numberRe.exec(string.slice(i, i + 2));
|
16296 | return n ? (d.U = +n[0], i + n[0].length) : -1;
|
16297 | }
|
16298 |
|
16299 | function parseWeekNumberISO(d, string, i) {
|
16300 | var n = numberRe.exec(string.slice(i, i + 2));
|
16301 | return n ? (d.V = +n[0], i + n[0].length) : -1;
|
16302 | }
|
16303 |
|
16304 | function parseWeekNumberMonday(d, string, i) {
|
16305 | var n = numberRe.exec(string.slice(i, i + 2));
|
16306 | return n ? (d.W = +n[0], i + n[0].length) : -1;
|
16307 | }
|
16308 |
|
16309 | function parseFullYear(d, string, i) {
|
16310 | var n = numberRe.exec(string.slice(i, i + 4));
|
16311 | return n ? (d.y = +n[0], i + n[0].length) : -1;
|
16312 | }
|
16313 |
|
16314 | function parseYear(d, string, i) {
|
16315 | var n = numberRe.exec(string.slice(i, i + 2));
|
16316 | return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
|
16317 | }
|
16318 |
|
16319 | function parseZone(d, string, i) {
|
16320 | var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
|
16321 | return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
|
16322 | }
|
16323 |
|
16324 | function parseQuarter(d, string, i) {
|
16325 | var n = numberRe.exec(string.slice(i, i + 1));
|
16326 | return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
|
16327 | }
|
16328 |
|
16329 | function parseMonthNumber(d, string, i) {
|
16330 | var n = numberRe.exec(string.slice(i, i + 2));
|
16331 | return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
|
16332 | }
|
16333 |
|
16334 | function parseDayOfMonth(d, string, i) {
|
16335 | var n = numberRe.exec(string.slice(i, i + 2));
|
16336 | return n ? (d.d = +n[0], i + n[0].length) : -1;
|
16337 | }
|
16338 |
|
16339 | function parseDayOfYear(d, string, i) {
|
16340 | var n = numberRe.exec(string.slice(i, i + 3));
|
16341 | return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
|
16342 | }
|
16343 |
|
16344 | function parseHour24(d, string, i) {
|
16345 | var n = numberRe.exec(string.slice(i, i + 2));
|
16346 | return n ? (d.H = +n[0], i + n[0].length) : -1;
|
16347 | }
|
16348 |
|
16349 | function parseMinutes(d, string, i) {
|
16350 | var n = numberRe.exec(string.slice(i, i + 2));
|
16351 | return n ? (d.M = +n[0], i + n[0].length) : -1;
|
16352 | }
|
16353 |
|
16354 | function parseSeconds(d, string, i) {
|
16355 | var n = numberRe.exec(string.slice(i, i + 2));
|
16356 | return n ? (d.S = +n[0], i + n[0].length) : -1;
|
16357 | }
|
16358 |
|
16359 | function parseMilliseconds(d, string, i) {
|
16360 | var n = numberRe.exec(string.slice(i, i + 3));
|
16361 | return n ? (d.L = +n[0], i + n[0].length) : -1;
|
16362 | }
|
16363 |
|
16364 | function parseMicroseconds(d, string, i) {
|
16365 | var n = numberRe.exec(string.slice(i, i + 6));
|
16366 | return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
|
16367 | }
|
16368 |
|
16369 | function parseLiteralPercent(d, string, i) {
|
16370 | var n = percentRe.exec(string.slice(i, i + 1));
|
16371 | return n ? i + n[0].length : -1;
|
16372 | }
|
16373 |
|
16374 | function parseUnixTimestamp(d, string, i) {
|
16375 | var n = numberRe.exec(string.slice(i));
|
16376 | return n ? (d.Q = +n[0], i + n[0].length) : -1;
|
16377 | }
|
16378 |
|
16379 | function parseUnixTimestampSeconds(d, string, i) {
|
16380 | var n = numberRe.exec(string.slice(i));
|
16381 | return n ? (d.s = +n[0], i + n[0].length) : -1;
|
16382 | }
|
16383 |
|
16384 | function formatDayOfMonth(d, p) {
|
16385 | return pad(d.getDate(), p, 2);
|
16386 | }
|
16387 |
|
16388 | function formatHour24(d, p) {
|
16389 | return pad(d.getHours(), p, 2);
|
16390 | }
|
16391 |
|
16392 | function formatHour12(d, p) {
|
16393 | return pad(d.getHours() % 12 || 12, p, 2);
|
16394 | }
|
16395 |
|
16396 | function formatDayOfYear(d, p) {
|
16397 | return pad(1 + timeDay.count(timeYear(d), d), p, 3);
|
16398 | }
|
16399 |
|
16400 | function formatMilliseconds(d, p) {
|
16401 | return pad(d.getMilliseconds(), p, 3);
|
16402 | }
|
16403 |
|
16404 | function formatMicroseconds(d, p) {
|
16405 | return formatMilliseconds(d, p) + "000";
|
16406 | }
|
16407 |
|
16408 | function formatMonthNumber(d, p) {
|
16409 | return pad(d.getMonth() + 1, p, 2);
|
16410 | }
|
16411 |
|
16412 | function formatMinutes(d, p) {
|
16413 | return pad(d.getMinutes(), p, 2);
|
16414 | }
|
16415 |
|
16416 | function formatSeconds(d, p) {
|
16417 | return pad(d.getSeconds(), p, 2);
|
16418 | }
|
16419 |
|
16420 | function formatWeekdayNumberMonday(d) {
|
16421 | var day = d.getDay();
|
16422 | return day === 0 ? 7 : day;
|
16423 | }
|
16424 |
|
16425 | function formatWeekNumberSunday(d, p) {
|
16426 | return pad(sunday.count(timeYear(d) - 1, d), p, 2);
|
16427 | }
|
16428 |
|
16429 | function dISO(d) {
|
16430 | var day = d.getDay();
|
16431 | return (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
|
16432 | }
|
16433 |
|
16434 | function formatWeekNumberISO(d, p) {
|
16435 | d = dISO(d);
|
16436 | return pad(thursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2);
|
16437 | }
|
16438 |
|
16439 | function formatWeekdayNumberSunday(d) {
|
16440 | return d.getDay();
|
16441 | }
|
16442 |
|
16443 | function formatWeekNumberMonday(d, p) {
|
16444 | return pad(monday.count(timeYear(d) - 1, d), p, 2);
|
16445 | }
|
16446 |
|
16447 | function formatYear(d, p) {
|
16448 | return pad(d.getFullYear() % 100, p, 2);
|
16449 | }
|
16450 |
|
16451 | function formatYearISO(d, p) {
|
16452 | d = dISO(d);
|
16453 | return pad(d.getFullYear() % 100, p, 2);
|
16454 | }
|
16455 |
|
16456 | function formatFullYear(d, p) {
|
16457 | return pad(d.getFullYear() % 10000, p, 4);
|
16458 | }
|
16459 |
|
16460 | function formatFullYearISO(d, p) {
|
16461 | var day = d.getDay();
|
16462 | d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
|
16463 | return pad(d.getFullYear() % 10000, p, 4);
|
16464 | }
|
16465 |
|
16466 | function formatZone(d) {
|
16467 | var z = d.getTimezoneOffset();
|
16468 | return (z > 0 ? "-" : (z *= -1, "+"))
|
16469 | + pad(z / 60 | 0, "0", 2)
|
16470 | + pad(z % 60, "0", 2);
|
16471 | }
|
16472 |
|
16473 | function formatUTCDayOfMonth(d, p) {
|
16474 | return pad(d.getUTCDate(), p, 2);
|
16475 | }
|
16476 |
|
16477 | function formatUTCHour24(d, p) {
|
16478 | return pad(d.getUTCHours(), p, 2);
|
16479 | }
|
16480 |
|
16481 | function formatUTCHour12(d, p) {
|
16482 | return pad(d.getUTCHours() % 12 || 12, p, 2);
|
16483 | }
|
16484 |
|
16485 | function formatUTCDayOfYear(d, p) {
|
16486 | return pad(1 + utcDay$1.count(utcYear$1(d), d), p, 3);
|
16487 | }
|
16488 |
|
16489 | function formatUTCMilliseconds(d, p) {
|
16490 | return pad(d.getUTCMilliseconds(), p, 3);
|
16491 | }
|
16492 |
|
16493 | function formatUTCMicroseconds(d, p) {
|
16494 | return formatUTCMilliseconds(d, p) + "000";
|
16495 | }
|
16496 |
|
16497 | function formatUTCMonthNumber(d, p) {
|
16498 | return pad(d.getUTCMonth() + 1, p, 2);
|
16499 | }
|
16500 |
|
16501 | function formatUTCMinutes(d, p) {
|
16502 | return pad(d.getUTCMinutes(), p, 2);
|
16503 | }
|
16504 |
|
16505 | function formatUTCSeconds(d, p) {
|
16506 | return pad(d.getUTCSeconds(), p, 2);
|
16507 | }
|
16508 |
|
16509 | function formatUTCWeekdayNumberMonday(d) {
|
16510 | var dow = d.getUTCDay();
|
16511 | return dow === 0 ? 7 : dow;
|
16512 | }
|
16513 |
|
16514 | function formatUTCWeekNumberSunday(d, p) {
|
16515 | return pad(utcSunday.count(utcYear$1(d) - 1, d), p, 2);
|
16516 | }
|
16517 |
|
16518 | function UTCdISO(d) {
|
16519 | var day = d.getUTCDay();
|
16520 | return (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
|
16521 | }
|
16522 |
|
16523 | function formatUTCWeekNumberISO(d, p) {
|
16524 | d = UTCdISO(d);
|
16525 | return pad(utcThursday.count(utcYear$1(d), d) + (utcYear$1(d).getUTCDay() === 4), p, 2);
|
16526 | }
|
16527 |
|
16528 | function formatUTCWeekdayNumberSunday(d) {
|
16529 | return d.getUTCDay();
|
16530 | }
|
16531 |
|
16532 | function formatUTCWeekNumberMonday(d, p) {
|
16533 | return pad(utcMonday.count(utcYear$1(d) - 1, d), p, 2);
|
16534 | }
|
16535 |
|
16536 | function formatUTCYear(d, p) {
|
16537 | return pad(d.getUTCFullYear() % 100, p, 2);
|
16538 | }
|
16539 |
|
16540 | function formatUTCYearISO(d, p) {
|
16541 | d = UTCdISO(d);
|
16542 | return pad(d.getUTCFullYear() % 100, p, 2);
|
16543 | }
|
16544 |
|
16545 | function formatUTCFullYear(d, p) {
|
16546 | return pad(d.getUTCFullYear() % 10000, p, 4);
|
16547 | }
|
16548 |
|
16549 | function formatUTCFullYearISO(d, p) {
|
16550 | var day = d.getUTCDay();
|
16551 | d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
|
16552 | return pad(d.getUTCFullYear() % 10000, p, 4);
|
16553 | }
|
16554 |
|
16555 | function formatUTCZone() {
|
16556 | return "+0000";
|
16557 | }
|
16558 |
|
16559 | function formatLiteralPercent() {
|
16560 | return "%";
|
16561 | }
|
16562 |
|
16563 | function formatUnixTimestamp(d) {
|
16564 | return +d;
|
16565 | }
|
16566 |
|
16567 | function formatUnixTimestampSeconds(d) {
|
16568 | return Math.floor(+d / 1000);
|
16569 | }
|
16570 |
|
16571 | var locale;
|
16572 | exports.timeFormat = void 0;
|
16573 | exports.timeParse = void 0;
|
16574 | exports.utcFormat = void 0;
|
16575 | exports.utcParse = void 0;
|
16576 |
|
16577 | defaultLocale({
|
16578 | dateTime: "%x, %X",
|
16579 | date: "%-m/%-d/%Y",
|
16580 | time: "%-I:%M:%S %p",
|
16581 | periods: ["AM", "PM"],
|
16582 | days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
16583 | shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
16584 | months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
16585 | shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
16586 | });
|
16587 |
|
16588 | function defaultLocale(definition) {
|
16589 | locale = formatLocale(definition);
|
16590 | exports.timeFormat = locale.format;
|
16591 | exports.timeParse = locale.parse;
|
16592 | exports.utcFormat = locale.utcFormat;
|
16593 | exports.utcParse = locale.utcParse;
|
16594 | return locale;
|
16595 | }
|
16596 |
|
16597 | var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
|
16598 |
|
16599 | function formatIsoNative(date) {
|
16600 | return date.toISOString();
|
16601 | }
|
16602 |
|
16603 | var formatIso = Date.prototype.toISOString
|
16604 | ? formatIsoNative
|
16605 | : exports.utcFormat(isoSpecifier);
|
16606 |
|
16607 | var formatIso$1 = formatIso;
|
16608 |
|
16609 | function parseIsoNative(string) {
|
16610 | var date = new Date(string);
|
16611 | return isNaN(date) ? null : date;
|
16612 | }
|
16613 |
|
16614 | var parseIso = +new Date("2000-01-01T00:00:00.000Z")
|
16615 | ? parseIsoNative
|
16616 | : exports.utcParse(isoSpecifier);
|
16617 |
|
16618 | var parseIso$1 = parseIso;
|
16619 |
|
16620 | function date(t) {
|
16621 | return new Date(t);
|
16622 | }
|
16623 |
|
16624 | function number(t) {
|
16625 | return t instanceof Date ? +t : +new Date(+t);
|
16626 | }
|
16627 |
|
16628 | function calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format) {
|
16629 | var scale = continuous(),
|
16630 | invert = scale.invert,
|
16631 | domain = scale.domain;
|
16632 |
|
16633 | var formatMillisecond = format(".%L"),
|
16634 | formatSecond = format(":%S"),
|
16635 | formatMinute = format("%I:%M"),
|
16636 | formatHour = format("%I %p"),
|
16637 | formatDay = format("%a %d"),
|
16638 | formatWeek = format("%b %d"),
|
16639 | formatMonth = format("%B"),
|
16640 | formatYear = format("%Y");
|
16641 |
|
16642 | function tickFormat(date) {
|
16643 | return (second(date) < date ? formatMillisecond
|
16644 | : minute(date) < date ? formatSecond
|
16645 | : hour(date) < date ? formatMinute
|
16646 | : day(date) < date ? formatHour
|
16647 | : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
|
16648 | : year(date) < date ? formatMonth
|
16649 | : formatYear)(date);
|
16650 | }
|
16651 |
|
16652 | scale.invert = function(y) {
|
16653 | return new Date(invert(y));
|
16654 | };
|
16655 |
|
16656 | scale.domain = function(_) {
|
16657 | return arguments.length ? domain(Array.from(_, number)) : domain().map(date);
|
16658 | };
|
16659 |
|
16660 | scale.ticks = function(interval) {
|
16661 | var d = domain();
|
16662 | return ticks(d[0], d[d.length - 1], interval == null ? 10 : interval);
|
16663 | };
|
16664 |
|
16665 | scale.tickFormat = function(count, specifier) {
|
16666 | return specifier == null ? tickFormat : format(specifier);
|
16667 | };
|
16668 |
|
16669 | scale.nice = function(interval) {
|
16670 | var d = domain();
|
16671 | if (!interval || typeof interval.range !== "function") interval = tickInterval(d[0], d[d.length - 1], interval == null ? 10 : interval);
|
16672 | return interval ? domain(nice(d, interval)) : scale;
|
16673 | };
|
16674 |
|
16675 | scale.copy = function() {
|
16676 | return copy$1(scale, calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format));
|
16677 | };
|
16678 |
|
16679 | return scale;
|
16680 | }
|
16681 |
|
16682 | function time() {
|
16683 | return initRange.apply(calendar(timeTicks, timeTickInterval, timeYear, timeMonth, sunday, timeDay, timeHour, timeMinute, utcSecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
|
16684 | }
|
16685 |
|
16686 | function utcTime() {
|
16687 | return initRange.apply(calendar(utcTicks, utcTickInterval, utcYear$1, utcMonth$1, utcSunday, utcDay$1, utcHour$1, utcMinute$1, utcSecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
|
16688 | }
|
16689 |
|
16690 | function transformer$1() {
|
16691 | var x0 = 0,
|
16692 | x1 = 1,
|
16693 | t0,
|
16694 | t1,
|
16695 | k10,
|
16696 | transform,
|
16697 | interpolator = identity$3,
|
16698 | clamp = false,
|
16699 | unknown;
|
16700 |
|
16701 | function scale(x) {
|
16702 | return x == null || isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
|
16703 | }
|
16704 |
|
16705 | scale.domain = function(_) {
|
16706 | return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
|
16707 | };
|
16708 |
|
16709 | scale.clamp = function(_) {
|
16710 | return arguments.length ? (clamp = !!_, scale) : clamp;
|
16711 | };
|
16712 |
|
16713 | scale.interpolator = function(_) {
|
16714 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
16715 | };
|
16716 |
|
16717 | function range(interpolate) {
|
16718 | return function(_) {
|
16719 | var r0, r1;
|
16720 | return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)];
|
16721 | };
|
16722 | }
|
16723 |
|
16724 | scale.range = range(interpolate$2);
|
16725 |
|
16726 | scale.rangeRound = range(interpolateRound);
|
16727 |
|
16728 | scale.unknown = function(_) {
|
16729 | return arguments.length ? (unknown = _, scale) : unknown;
|
16730 | };
|
16731 |
|
16732 | return function(t) {
|
16733 | transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
|
16734 | return scale;
|
16735 | };
|
16736 | }
|
16737 |
|
16738 | function copy(source, target) {
|
16739 | return target
|
16740 | .domain(source.domain())
|
16741 | .interpolator(source.interpolator())
|
16742 | .clamp(source.clamp())
|
16743 | .unknown(source.unknown());
|
16744 | }
|
16745 |
|
16746 | function sequential() {
|
16747 | var scale = linearish(transformer$1()(identity$3));
|
16748 |
|
16749 | scale.copy = function() {
|
16750 | return copy(scale, sequential());
|
16751 | };
|
16752 |
|
16753 | return initInterpolator.apply(scale, arguments);
|
16754 | }
|
16755 |
|
16756 | function sequentialLog() {
|
16757 | var scale = loggish(transformer$1()).domain([1, 10]);
|
16758 |
|
16759 | scale.copy = function() {
|
16760 | return copy(scale, sequentialLog()).base(scale.base());
|
16761 | };
|
16762 |
|
16763 | return initInterpolator.apply(scale, arguments);
|
16764 | }
|
16765 |
|
16766 | function sequentialSymlog() {
|
16767 | var scale = symlogish(transformer$1());
|
16768 |
|
16769 | scale.copy = function() {
|
16770 | return copy(scale, sequentialSymlog()).constant(scale.constant());
|
16771 | };
|
16772 |
|
16773 | return initInterpolator.apply(scale, arguments);
|
16774 | }
|
16775 |
|
16776 | function sequentialPow() {
|
16777 | var scale = powish(transformer$1());
|
16778 |
|
16779 | scale.copy = function() {
|
16780 | return copy(scale, sequentialPow()).exponent(scale.exponent());
|
16781 | };
|
16782 |
|
16783 | return initInterpolator.apply(scale, arguments);
|
16784 | }
|
16785 |
|
16786 | function sequentialSqrt() {
|
16787 | return sequentialPow.apply(null, arguments).exponent(0.5);
|
16788 | }
|
16789 |
|
16790 | function sequentialQuantile() {
|
16791 | var domain = [],
|
16792 | interpolator = identity$3;
|
16793 |
|
16794 | function scale(x) {
|
16795 | if (x != null && !isNaN(x = +x)) return interpolator((bisect(domain, x, 1) - 1) / (domain.length - 1));
|
16796 | }
|
16797 |
|
16798 | scale.domain = function(_) {
|
16799 | if (!arguments.length) return domain.slice();
|
16800 | domain = [];
|
16801 | for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
|
16802 | domain.sort(ascending$3);
|
16803 | return scale;
|
16804 | };
|
16805 |
|
16806 | scale.interpolator = function(_) {
|
16807 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
16808 | };
|
16809 |
|
16810 | scale.range = function() {
|
16811 | return domain.map((d, i) => interpolator(i / (domain.length - 1)));
|
16812 | };
|
16813 |
|
16814 | scale.quantiles = function(n) {
|
16815 | return Array.from({length: n + 1}, (_, i) => quantile$1(domain, i / n));
|
16816 | };
|
16817 |
|
16818 | scale.copy = function() {
|
16819 | return sequentialQuantile(interpolator).domain(domain);
|
16820 | };
|
16821 |
|
16822 | return initInterpolator.apply(scale, arguments);
|
16823 | }
|
16824 |
|
16825 | function transformer() {
|
16826 | var x0 = 0,
|
16827 | x1 = 0.5,
|
16828 | x2 = 1,
|
16829 | s = 1,
|
16830 | t0,
|
16831 | t1,
|
16832 | t2,
|
16833 | k10,
|
16834 | k21,
|
16835 | interpolator = identity$3,
|
16836 | transform,
|
16837 | clamp = false,
|
16838 | unknown;
|
16839 |
|
16840 | function scale(x) {
|
16841 | return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (s * x < s * t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
|
16842 | }
|
16843 |
|
16844 | scale.domain = function(_) {
|
16845 | return arguments.length ? ([x0, x1, x2] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), t2 = transform(x2 = +x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1, scale) : [x0, x1, x2];
|
16846 | };
|
16847 |
|
16848 | scale.clamp = function(_) {
|
16849 | return arguments.length ? (clamp = !!_, scale) : clamp;
|
16850 | };
|
16851 |
|
16852 | scale.interpolator = function(_) {
|
16853 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
16854 | };
|
16855 |
|
16856 | function range(interpolate) {
|
16857 | return function(_) {
|
16858 | var r0, r1, r2;
|
16859 | return arguments.length ? ([r0, r1, r2] = _, interpolator = piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)];
|
16860 | };
|
16861 | }
|
16862 |
|
16863 | scale.range = range(interpolate$2);
|
16864 |
|
16865 | scale.rangeRound = range(interpolateRound);
|
16866 |
|
16867 | scale.unknown = function(_) {
|
16868 | return arguments.length ? (unknown = _, scale) : unknown;
|
16869 | };
|
16870 |
|
16871 | return function(t) {
|
16872 | transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1;
|
16873 | return scale;
|
16874 | };
|
16875 | }
|
16876 |
|
16877 | function diverging$1() {
|
16878 | var scale = linearish(transformer()(identity$3));
|
16879 |
|
16880 | scale.copy = function() {
|
16881 | return copy(scale, diverging$1());
|
16882 | };
|
16883 |
|
16884 | return initInterpolator.apply(scale, arguments);
|
16885 | }
|
16886 |
|
16887 | function divergingLog() {
|
16888 | var scale = loggish(transformer()).domain([0.1, 1, 10]);
|
16889 |
|
16890 | scale.copy = function() {
|
16891 | return copy(scale, divergingLog()).base(scale.base());
|
16892 | };
|
16893 |
|
16894 | return initInterpolator.apply(scale, arguments);
|
16895 | }
|
16896 |
|
16897 | function divergingSymlog() {
|
16898 | var scale = symlogish(transformer());
|
16899 |
|
16900 | scale.copy = function() {
|
16901 | return copy(scale, divergingSymlog()).constant(scale.constant());
|
16902 | };
|
16903 |
|
16904 | return initInterpolator.apply(scale, arguments);
|
16905 | }
|
16906 |
|
16907 | function divergingPow() {
|
16908 | var scale = powish(transformer());
|
16909 |
|
16910 | scale.copy = function() {
|
16911 | return copy(scale, divergingPow()).exponent(scale.exponent());
|
16912 | };
|
16913 |
|
16914 | return initInterpolator.apply(scale, arguments);
|
16915 | }
|
16916 |
|
16917 | function divergingSqrt() {
|
16918 | return divergingPow.apply(null, arguments).exponent(0.5);
|
16919 | }
|
16920 |
|
16921 | function colors(specifier) {
|
16922 | var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
|
16923 | while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
|
16924 | return colors;
|
16925 | }
|
16926 |
|
16927 | var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
|
16928 |
|
16929 | var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
|
16930 |
|
16931 | var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
|
16932 |
|
16933 | var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
|
16934 |
|
16935 | var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
|
16936 |
|
16937 | var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
|
16938 |
|
16939 | var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
|
16940 |
|
16941 | var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
|
16942 |
|
16943 | var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
|
16944 |
|
16945 | var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
|
16946 |
|
16947 | var ramp$1 = scheme => rgbBasis(scheme[scheme.length - 1]);
|
16948 |
|
16949 | var scheme$q = new Array(3).concat(
|
16950 | "d8b365f5f5f55ab4ac",
|
16951 | "a6611adfc27d80cdc1018571",
|
16952 | "a6611adfc27df5f5f580cdc1018571",
|
16953 | "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
|
16954 | "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
|
16955 | "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
|
16956 | "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
|
16957 | "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
|
16958 | "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
|
16959 | ).map(colors);
|
16960 |
|
16961 | var BrBG = ramp$1(scheme$q);
|
16962 |
|
16963 | var scheme$p = new Array(3).concat(
|
16964 | "af8dc3f7f7f77fbf7b",
|
16965 | "7b3294c2a5cfa6dba0008837",
|
16966 | "7b3294c2a5cff7f7f7a6dba0008837",
|
16967 | "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
|
16968 | "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
|
16969 | "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
|
16970 | "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
|
16971 | "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
|
16972 | "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
|
16973 | ).map(colors);
|
16974 |
|
16975 | var PRGn = ramp$1(scheme$p);
|
16976 |
|
16977 | var scheme$o = new Array(3).concat(
|
16978 | "e9a3c9f7f7f7a1d76a",
|
16979 | "d01c8bf1b6dab8e1864dac26",
|
16980 | "d01c8bf1b6daf7f7f7b8e1864dac26",
|
16981 | "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
|
16982 | "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
|
16983 | "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
|
16984 | "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
|
16985 | "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
|
16986 | "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
|
16987 | ).map(colors);
|
16988 |
|
16989 | var PiYG = ramp$1(scheme$o);
|
16990 |
|
16991 | var scheme$n = new Array(3).concat(
|
16992 | "998ec3f7f7f7f1a340",
|
16993 | "5e3c99b2abd2fdb863e66101",
|
16994 | "5e3c99b2abd2f7f7f7fdb863e66101",
|
16995 | "542788998ec3d8daebfee0b6f1a340b35806",
|
16996 | "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
|
16997 | "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
|
16998 | "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
|
16999 | "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
|
17000 | "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
|
17001 | ).map(colors);
|
17002 |
|
17003 | var PuOr = ramp$1(scheme$n);
|
17004 |
|
17005 | var scheme$m = new Array(3).concat(
|
17006 | "ef8a62f7f7f767a9cf",
|
17007 | "ca0020f4a58292c5de0571b0",
|
17008 | "ca0020f4a582f7f7f792c5de0571b0",
|
17009 | "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
|
17010 | "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
|
17011 | "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
|
17012 | "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
|
17013 | "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
|
17014 | "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
|
17015 | ).map(colors);
|
17016 |
|
17017 | var RdBu = ramp$1(scheme$m);
|
17018 |
|
17019 | var scheme$l = new Array(3).concat(
|
17020 | "ef8a62ffffff999999",
|
17021 | "ca0020f4a582bababa404040",
|
17022 | "ca0020f4a582ffffffbababa404040",
|
17023 | "b2182bef8a62fddbc7e0e0e09999994d4d4d",
|
17024 | "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
|
17025 | "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
|
17026 | "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
|
17027 | "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
|
17028 | "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
|
17029 | ).map(colors);
|
17030 |
|
17031 | var RdGy = ramp$1(scheme$l);
|
17032 |
|
17033 | var scheme$k = new Array(3).concat(
|
17034 | "fc8d59ffffbf91bfdb",
|
17035 | "d7191cfdae61abd9e92c7bb6",
|
17036 | "d7191cfdae61ffffbfabd9e92c7bb6",
|
17037 | "d73027fc8d59fee090e0f3f891bfdb4575b4",
|
17038 | "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
|
17039 | "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
|
17040 | "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
|
17041 | "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
|
17042 | "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
|
17043 | ).map(colors);
|
17044 |
|
17045 | var RdYlBu = ramp$1(scheme$k);
|
17046 |
|
17047 | var scheme$j = new Array(3).concat(
|
17048 | "fc8d59ffffbf91cf60",
|
17049 | "d7191cfdae61a6d96a1a9641",
|
17050 | "d7191cfdae61ffffbfa6d96a1a9641",
|
17051 | "d73027fc8d59fee08bd9ef8b91cf601a9850",
|
17052 | "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
|
17053 | "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
|
17054 | "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
|
17055 | "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
|
17056 | "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
|
17057 | ).map(colors);
|
17058 |
|
17059 | var RdYlGn = ramp$1(scheme$j);
|
17060 |
|
17061 | var scheme$i = new Array(3).concat(
|
17062 | "fc8d59ffffbf99d594",
|
17063 | "d7191cfdae61abdda42b83ba",
|
17064 | "d7191cfdae61ffffbfabdda42b83ba",
|
17065 | "d53e4ffc8d59fee08be6f59899d5943288bd",
|
17066 | "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
|
17067 | "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
|
17068 | "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
|
17069 | "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
|
17070 | "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
|
17071 | ).map(colors);
|
17072 |
|
17073 | var Spectral = ramp$1(scheme$i);
|
17074 |
|
17075 | var scheme$h = new Array(3).concat(
|
17076 | "e5f5f999d8c92ca25f",
|
17077 | "edf8fbb2e2e266c2a4238b45",
|
17078 | "edf8fbb2e2e266c2a42ca25f006d2c",
|
17079 | "edf8fbccece699d8c966c2a42ca25f006d2c",
|
17080 | "edf8fbccece699d8c966c2a441ae76238b45005824",
|
17081 | "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
|
17082 | "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
|
17083 | ).map(colors);
|
17084 |
|
17085 | var BuGn = ramp$1(scheme$h);
|
17086 |
|
17087 | var scheme$g = new Array(3).concat(
|
17088 | "e0ecf49ebcda8856a7",
|
17089 | "edf8fbb3cde38c96c688419d",
|
17090 | "edf8fbb3cde38c96c68856a7810f7c",
|
17091 | "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
|
17092 | "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
|
17093 | "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
|
17094 | "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
|
17095 | ).map(colors);
|
17096 |
|
17097 | var BuPu = ramp$1(scheme$g);
|
17098 |
|
17099 | var scheme$f = new Array(3).concat(
|
17100 | "e0f3dba8ddb543a2ca",
|
17101 | "f0f9e8bae4bc7bccc42b8cbe",
|
17102 | "f0f9e8bae4bc7bccc443a2ca0868ac",
|
17103 | "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
|
17104 | "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
|
17105 | "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
|
17106 | "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
|
17107 | ).map(colors);
|
17108 |
|
17109 | var GnBu = ramp$1(scheme$f);
|
17110 |
|
17111 | var scheme$e = new Array(3).concat(
|
17112 | "fee8c8fdbb84e34a33",
|
17113 | "fef0d9fdcc8afc8d59d7301f",
|
17114 | "fef0d9fdcc8afc8d59e34a33b30000",
|
17115 | "fef0d9fdd49efdbb84fc8d59e34a33b30000",
|
17116 | "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
|
17117 | "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
|
17118 | "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
|
17119 | ).map(colors);
|
17120 |
|
17121 | var OrRd = ramp$1(scheme$e);
|
17122 |
|
17123 | var scheme$d = new Array(3).concat(
|
17124 | "ece2f0a6bddb1c9099",
|
17125 | "f6eff7bdc9e167a9cf02818a",
|
17126 | "f6eff7bdc9e167a9cf1c9099016c59",
|
17127 | "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
|
17128 | "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
|
17129 | "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
|
17130 | "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
|
17131 | ).map(colors);
|
17132 |
|
17133 | var PuBuGn = ramp$1(scheme$d);
|
17134 |
|
17135 | var scheme$c = new Array(3).concat(
|
17136 | "ece7f2a6bddb2b8cbe",
|
17137 | "f1eef6bdc9e174a9cf0570b0",
|
17138 | "f1eef6bdc9e174a9cf2b8cbe045a8d",
|
17139 | "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
|
17140 | "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
|
17141 | "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
|
17142 | "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
|
17143 | ).map(colors);
|
17144 |
|
17145 | var PuBu = ramp$1(scheme$c);
|
17146 |
|
17147 | var scheme$b = new Array(3).concat(
|
17148 | "e7e1efc994c7dd1c77",
|
17149 | "f1eef6d7b5d8df65b0ce1256",
|
17150 | "f1eef6d7b5d8df65b0dd1c77980043",
|
17151 | "f1eef6d4b9dac994c7df65b0dd1c77980043",
|
17152 | "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
|
17153 | "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
|
17154 | "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
|
17155 | ).map(colors);
|
17156 |
|
17157 | var PuRd = ramp$1(scheme$b);
|
17158 |
|
17159 | var scheme$a = new Array(3).concat(
|
17160 | "fde0ddfa9fb5c51b8a",
|
17161 | "feebe2fbb4b9f768a1ae017e",
|
17162 | "feebe2fbb4b9f768a1c51b8a7a0177",
|
17163 | "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
|
17164 | "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
|
17165 | "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
|
17166 | "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
|
17167 | ).map(colors);
|
17168 |
|
17169 | var RdPu = ramp$1(scheme$a);
|
17170 |
|
17171 | var scheme$9 = new Array(3).concat(
|
17172 | "edf8b17fcdbb2c7fb8",
|
17173 | "ffffcca1dab441b6c4225ea8",
|
17174 | "ffffcca1dab441b6c42c7fb8253494",
|
17175 | "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
|
17176 | "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
|
17177 | "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
|
17178 | "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
|
17179 | ).map(colors);
|
17180 |
|
17181 | var YlGnBu = ramp$1(scheme$9);
|
17182 |
|
17183 | var scheme$8 = new Array(3).concat(
|
17184 | "f7fcb9addd8e31a354",
|
17185 | "ffffccc2e69978c679238443",
|
17186 | "ffffccc2e69978c67931a354006837",
|
17187 | "ffffccd9f0a3addd8e78c67931a354006837",
|
17188 | "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
|
17189 | "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
|
17190 | "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
|
17191 | ).map(colors);
|
17192 |
|
17193 | var YlGn = ramp$1(scheme$8);
|
17194 |
|
17195 | var scheme$7 = new Array(3).concat(
|
17196 | "fff7bcfec44fd95f0e",
|
17197 | "ffffd4fed98efe9929cc4c02",
|
17198 | "ffffd4fed98efe9929d95f0e993404",
|
17199 | "ffffd4fee391fec44ffe9929d95f0e993404",
|
17200 | "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
|
17201 | "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
|
17202 | "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
|
17203 | ).map(colors);
|
17204 |
|
17205 | var YlOrBr = ramp$1(scheme$7);
|
17206 |
|
17207 | var scheme$6 = new Array(3).concat(
|
17208 | "ffeda0feb24cf03b20",
|
17209 | "ffffb2fecc5cfd8d3ce31a1c",
|
17210 | "ffffb2fecc5cfd8d3cf03b20bd0026",
|
17211 | "ffffb2fed976feb24cfd8d3cf03b20bd0026",
|
17212 | "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
|
17213 | "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
|
17214 | "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
|
17215 | ).map(colors);
|
17216 |
|
17217 | var YlOrRd = ramp$1(scheme$6);
|
17218 |
|
17219 | var scheme$5 = new Array(3).concat(
|
17220 | "deebf79ecae13182bd",
|
17221 | "eff3ffbdd7e76baed62171b5",
|
17222 | "eff3ffbdd7e76baed63182bd08519c",
|
17223 | "eff3ffc6dbef9ecae16baed63182bd08519c",
|
17224 | "eff3ffc6dbef9ecae16baed64292c62171b5084594",
|
17225 | "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
|
17226 | "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
|
17227 | ).map(colors);
|
17228 |
|
17229 | var Blues = ramp$1(scheme$5);
|
17230 |
|
17231 | var scheme$4 = new Array(3).concat(
|
17232 | "e5f5e0a1d99b31a354",
|
17233 | "edf8e9bae4b374c476238b45",
|
17234 | "edf8e9bae4b374c47631a354006d2c",
|
17235 | "edf8e9c7e9c0a1d99b74c47631a354006d2c",
|
17236 | "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
|
17237 | "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
|
17238 | "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
|
17239 | ).map(colors);
|
17240 |
|
17241 | var Greens = ramp$1(scheme$4);
|
17242 |
|
17243 | var scheme$3 = new Array(3).concat(
|
17244 | "f0f0f0bdbdbd636363",
|
17245 | "f7f7f7cccccc969696525252",
|
17246 | "f7f7f7cccccc969696636363252525",
|
17247 | "f7f7f7d9d9d9bdbdbd969696636363252525",
|
17248 | "f7f7f7d9d9d9bdbdbd969696737373525252252525",
|
17249 | "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
|
17250 | "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
|
17251 | ).map(colors);
|
17252 |
|
17253 | var Greys = ramp$1(scheme$3);
|
17254 |
|
17255 | var scheme$2 = new Array(3).concat(
|
17256 | "efedf5bcbddc756bb1",
|
17257 | "f2f0f7cbc9e29e9ac86a51a3",
|
17258 | "f2f0f7cbc9e29e9ac8756bb154278f",
|
17259 | "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
|
17260 | "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
|
17261 | "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
|
17262 | "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
|
17263 | ).map(colors);
|
17264 |
|
17265 | var Purples = ramp$1(scheme$2);
|
17266 |
|
17267 | var scheme$1 = new Array(3).concat(
|
17268 | "fee0d2fc9272de2d26",
|
17269 | "fee5d9fcae91fb6a4acb181d",
|
17270 | "fee5d9fcae91fb6a4ade2d26a50f15",
|
17271 | "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
|
17272 | "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
|
17273 | "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
|
17274 | "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
|
17275 | ).map(colors);
|
17276 |
|
17277 | var Reds = ramp$1(scheme$1);
|
17278 |
|
17279 | var scheme = new Array(3).concat(
|
17280 | "fee6cefdae6be6550d",
|
17281 | "feeddefdbe85fd8d3cd94701",
|
17282 | "feeddefdbe85fd8d3ce6550da63603",
|
17283 | "feeddefdd0a2fdae6bfd8d3ce6550da63603",
|
17284 | "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
|
17285 | "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
|
17286 | "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
|
17287 | ).map(colors);
|
17288 |
|
17289 | var Oranges = ramp$1(scheme);
|
17290 |
|
17291 | function cividis(t) {
|
17292 | t = Math.max(0, Math.min(1, t));
|
17293 | return "rgb("
|
17294 | + Math.max(0, Math.min(255, Math.round(-4.54 - t * (35.34 - t * (2381.73 - t * (6402.7 - t * (7024.72 - t * 2710.57))))))) + ", "
|
17295 | + Math.max(0, Math.min(255, Math.round(32.49 + t * (170.73 + t * (52.82 - t * (131.46 - t * (176.58 - t * 67.37))))))) + ", "
|
17296 | + Math.max(0, Math.min(255, Math.round(81.24 + t * (442.36 - t * (2482.43 - t * (6167.24 - t * (6614.94 - t * 2475.67)))))))
|
17297 | + ")";
|
17298 | }
|
17299 |
|
17300 | var cubehelix = cubehelixLong(cubehelix$3(300, 0.5, 0.0), cubehelix$3(-240, 0.5, 1.0));
|
17301 |
|
17302 | var warm = cubehelixLong(cubehelix$3(-100, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
|
17303 |
|
17304 | var cool = cubehelixLong(cubehelix$3(260, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
|
17305 |
|
17306 | var c$2 = cubehelix$3();
|
17307 |
|
17308 | function rainbow(t) {
|
17309 | if (t < 0 || t > 1) t -= Math.floor(t);
|
17310 | var ts = Math.abs(t - 0.5);
|
17311 | c$2.h = 360 * t - 100;
|
17312 | c$2.s = 1.5 - 1.5 * ts;
|
17313 | c$2.l = 0.8 - 0.9 * ts;
|
17314 | return c$2 + "";
|
17315 | }
|
17316 |
|
17317 | var c$1 = rgb(),
|
17318 | pi_1_3 = Math.PI / 3,
|
17319 | pi_2_3 = Math.PI * 2 / 3;
|
17320 |
|
17321 | function sinebow(t) {
|
17322 | var x;
|
17323 | t = (0.5 - t) * Math.PI;
|
17324 | c$1.r = 255 * (x = Math.sin(t)) * x;
|
17325 | c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
|
17326 | c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
|
17327 | return c$1 + "";
|
17328 | }
|
17329 |
|
17330 | function turbo(t) {
|
17331 | t = Math.max(0, Math.min(1, t));
|
17332 | return "rgb("
|
17333 | + Math.max(0, Math.min(255, Math.round(34.61 + t * (1172.33 - t * (10793.56 - t * (33300.12 - t * (38394.49 - t * 14825.05))))))) + ", "
|
17334 | + Math.max(0, Math.min(255, Math.round(23.31 + t * (557.33 + t * (1225.33 - t * (3574.96 - t * (1073.77 + t * 707.56))))))) + ", "
|
17335 | + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
|
17336 | + ")";
|
17337 | }
|
17338 |
|
17339 | function ramp(range) {
|
17340 | var n = range.length;
|
17341 | return function(t) {
|
17342 | return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
17343 | };
|
17344 | }
|
17345 |
|
17346 | var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
|
17347 |
|
17348 | var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
|
17349 |
|
17350 | var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
|
17351 |
|
17352 | var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
|
17353 |
|
17354 | function constant$1(x) {
|
17355 | return function constant() {
|
17356 | return x;
|
17357 | };
|
17358 | }
|
17359 |
|
17360 | const abs = Math.abs;
|
17361 | const atan2 = Math.atan2;
|
17362 | const cos = Math.cos;
|
17363 | const max = Math.max;
|
17364 | const min = Math.min;
|
17365 | const sin = Math.sin;
|
17366 | const sqrt = Math.sqrt;
|
17367 |
|
17368 | const epsilon = 1e-12;
|
17369 | const pi = Math.PI;
|
17370 | const halfPi = pi / 2;
|
17371 | const tau = 2 * pi;
|
17372 |
|
17373 | function acos(x) {
|
17374 | return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
|
17375 | }
|
17376 |
|
17377 | function asin(x) {
|
17378 | return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
|
17379 | }
|
17380 |
|
17381 | function arcInnerRadius(d) {
|
17382 | return d.innerRadius;
|
17383 | }
|
17384 |
|
17385 | function arcOuterRadius(d) {
|
17386 | return d.outerRadius;
|
17387 | }
|
17388 |
|
17389 | function arcStartAngle(d) {
|
17390 | return d.startAngle;
|
17391 | }
|
17392 |
|
17393 | function arcEndAngle(d) {
|
17394 | return d.endAngle;
|
17395 | }
|
17396 |
|
17397 | function arcPadAngle(d) {
|
17398 | return d && d.padAngle; // Note: optional!
|
17399 | }
|
17400 |
|
17401 | function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
|
17402 | var x10 = x1 - x0, y10 = y1 - y0,
|
17403 | x32 = x3 - x2, y32 = y3 - y2,
|
17404 | t = y32 * x10 - x32 * y10;
|
17405 | if (t * t < epsilon) return;
|
17406 | t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
|
17407 | return [x0 + t * x10, y0 + t * y10];
|
17408 | }
|
17409 |
|
17410 | // Compute perpendicular offset line of length rc.
|
17411 | // http://mathworld.wolfram.com/Circle-LineIntersection.html
|
17412 | function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
|
17413 | var x01 = x0 - x1,
|
17414 | y01 = y0 - y1,
|
17415 | lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),
|
17416 | ox = lo * y01,
|
17417 | oy = -lo * x01,
|
17418 | x11 = x0 + ox,
|
17419 | y11 = y0 + oy,
|
17420 | x10 = x1 + ox,
|
17421 | y10 = y1 + oy,
|
17422 | x00 = (x11 + x10) / 2,
|
17423 | y00 = (y11 + y10) / 2,
|
17424 | dx = x10 - x11,
|
17425 | dy = y10 - y11,
|
17426 | d2 = dx * dx + dy * dy,
|
17427 | r = r1 - rc,
|
17428 | D = x11 * y10 - x10 * y11,
|
17429 | d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),
|
17430 | cx0 = (D * dy - dx * d) / d2,
|
17431 | cy0 = (-D * dx - dy * d) / d2,
|
17432 | cx1 = (D * dy + dx * d) / d2,
|
17433 | cy1 = (-D * dx + dy * d) / d2,
|
17434 | dx0 = cx0 - x00,
|
17435 | dy0 = cy0 - y00,
|
17436 | dx1 = cx1 - x00,
|
17437 | dy1 = cy1 - y00;
|
17438 |
|
17439 | // Pick the closer of the two intersection points.
|
17440 | // TODO Is there a faster way to determine which intersection to use?
|
17441 | if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
|
17442 |
|
17443 | return {
|
17444 | cx: cx0,
|
17445 | cy: cy0,
|
17446 | x01: -ox,
|
17447 | y01: -oy,
|
17448 | x11: cx0 * (r1 / r - 1),
|
17449 | y11: cy0 * (r1 / r - 1)
|
17450 | };
|
17451 | }
|
17452 |
|
17453 | function arc() {
|
17454 | var innerRadius = arcInnerRadius,
|
17455 | outerRadius = arcOuterRadius,
|
17456 | cornerRadius = constant$1(0),
|
17457 | padRadius = null,
|
17458 | startAngle = arcStartAngle,
|
17459 | endAngle = arcEndAngle,
|
17460 | padAngle = arcPadAngle,
|
17461 | context = null;
|
17462 |
|
17463 | function arc() {
|
17464 | var buffer,
|
17465 | r,
|
17466 | r0 = +innerRadius.apply(this, arguments),
|
17467 | r1 = +outerRadius.apply(this, arguments),
|
17468 | a0 = startAngle.apply(this, arguments) - halfPi,
|
17469 | a1 = endAngle.apply(this, arguments) - halfPi,
|
17470 | da = abs(a1 - a0),
|
17471 | cw = a1 > a0;
|
17472 |
|
17473 | if (!context) context = buffer = path();
|
17474 |
|
17475 | // Ensure that the outer radius is always larger than the inner radius.
|
17476 | if (r1 < r0) r = r1, r1 = r0, r0 = r;
|
17477 |
|
17478 | // Is it a point?
|
17479 | if (!(r1 > epsilon)) context.moveTo(0, 0);
|
17480 |
|
17481 | // Or is it a circle or annulus?
|
17482 | else if (da > tau - epsilon) {
|
17483 | context.moveTo(r1 * cos(a0), r1 * sin(a0));
|
17484 | context.arc(0, 0, r1, a0, a1, !cw);
|
17485 | if (r0 > epsilon) {
|
17486 | context.moveTo(r0 * cos(a1), r0 * sin(a1));
|
17487 | context.arc(0, 0, r0, a1, a0, cw);
|
17488 | }
|
17489 | }
|
17490 |
|
17491 | // Or is it a circular or annular sector?
|
17492 | else {
|
17493 | var a01 = a0,
|
17494 | a11 = a1,
|
17495 | a00 = a0,
|
17496 | a10 = a1,
|
17497 | da0 = da,
|
17498 | da1 = da,
|
17499 | ap = padAngle.apply(this, arguments) / 2,
|
17500 | rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),
|
17501 | rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
|
17502 | rc0 = rc,
|
17503 | rc1 = rc,
|
17504 | t0,
|
17505 | t1;
|
17506 |
|
17507 | // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
|
17508 | if (rp > epsilon) {
|
17509 | var p0 = asin(rp / r0 * sin(ap)),
|
17510 | p1 = asin(rp / r1 * sin(ap));
|
17511 | if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
|
17512 | else da0 = 0, a00 = a10 = (a0 + a1) / 2;
|
17513 | if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
|
17514 | else da1 = 0, a01 = a11 = (a0 + a1) / 2;
|
17515 | }
|
17516 |
|
17517 | var x01 = r1 * cos(a01),
|
17518 | y01 = r1 * sin(a01),
|
17519 | x10 = r0 * cos(a10),
|
17520 | y10 = r0 * sin(a10);
|
17521 |
|
17522 | // Apply rounded corners?
|
17523 | if (rc > epsilon) {
|
17524 | var x11 = r1 * cos(a11),
|
17525 | y11 = r1 * sin(a11),
|
17526 | x00 = r0 * cos(a00),
|
17527 | y00 = r0 * sin(a00),
|
17528 | oc;
|
17529 |
|
17530 | // Restrict the corner radius according to the sector angle.
|
17531 | if (da < pi && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
|
17532 | var ax = x01 - oc[0],
|
17533 | ay = y01 - oc[1],
|
17534 | bx = x11 - oc[0],
|
17535 | by = y11 - oc[1],
|
17536 | kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),
|
17537 | lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
|
17538 | rc0 = min(rc, (r0 - lc) / (kc - 1));
|
17539 | rc1 = min(rc, (r1 - lc) / (kc + 1));
|
17540 | }
|
17541 | }
|
17542 |
|
17543 | // Is the sector collapsed to a line?
|
17544 | if (!(da1 > epsilon)) context.moveTo(x01, y01);
|
17545 |
|
17546 | // Does the sector’s outer ring have rounded corners?
|
17547 | else if (rc1 > epsilon) {
|
17548 | t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
|
17549 | t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
|
17550 |
|
17551 | context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
17552 |
|
17553 | // Have the corners merged?
|
17554 | if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
|
17555 |
|
17556 | // Otherwise, draw the two corners and the ring.
|
17557 | else {
|
17558 | context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
|
17559 | context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
|
17560 | context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
|
17561 | }
|
17562 | }
|
17563 |
|
17564 | // Or is the outer ring just a circular arc?
|
17565 | else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
|
17566 |
|
17567 | // Is there no inner ring, and it’s a circular sector?
|
17568 | // Or perhaps it’s an annular sector collapsed due to padding?
|
17569 | if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);
|
17570 |
|
17571 | // Does the sector’s inner ring (or point) have rounded corners?
|
17572 | else if (rc0 > epsilon) {
|
17573 | t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
|
17574 | t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
|
17575 |
|
17576 | context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
17577 |
|
17578 | // Have the corners merged?
|
17579 | if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
|
17580 |
|
17581 | // Otherwise, draw the two corners and the ring.
|
17582 | else {
|
17583 | context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
|
17584 | context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
|
17585 | context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
|
17586 | }
|
17587 | }
|
17588 |
|
17589 | // Or is the inner ring just a circular arc?
|
17590 | else context.arc(0, 0, r0, a10, a00, cw);
|
17591 | }
|
17592 |
|
17593 | context.closePath();
|
17594 |
|
17595 | if (buffer) return context = null, buffer + "" || null;
|
17596 | }
|
17597 |
|
17598 | arc.centroid = function() {
|
17599 | var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
|
17600 | a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
|
17601 | return [cos(a) * r, sin(a) * r];
|
17602 | };
|
17603 |
|
17604 | arc.innerRadius = function(_) {
|
17605 | return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : innerRadius;
|
17606 | };
|
17607 |
|
17608 | arc.outerRadius = function(_) {
|
17609 | return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : outerRadius;
|
17610 | };
|
17611 |
|
17612 | arc.cornerRadius = function(_) {
|
17613 | return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : cornerRadius;
|
17614 | };
|
17615 |
|
17616 | arc.padRadius = function(_) {
|
17617 | return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), arc) : padRadius;
|
17618 | };
|
17619 |
|
17620 | arc.startAngle = function(_) {
|
17621 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : startAngle;
|
17622 | };
|
17623 |
|
17624 | arc.endAngle = function(_) {
|
17625 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : endAngle;
|
17626 | };
|
17627 |
|
17628 | arc.padAngle = function(_) {
|
17629 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : padAngle;
|
17630 | };
|
17631 |
|
17632 | arc.context = function(_) {
|
17633 | return arguments.length ? ((context = _ == null ? null : _), arc) : context;
|
17634 | };
|
17635 |
|
17636 | return arc;
|
17637 | }
|
17638 |
|
17639 | var slice = Array.prototype.slice;
|
17640 |
|
17641 | function array(x) {
|
17642 | return typeof x === "object" && "length" in x
|
17643 | ? x // Array, TypedArray, NodeList, array-like
|
17644 | : Array.from(x); // Map, Set, iterable, string, or anything else
|
17645 | }
|
17646 |
|
17647 | function Linear(context) {
|
17648 | this._context = context;
|
17649 | }
|
17650 |
|
17651 | Linear.prototype = {
|
17652 | areaStart: function() {
|
17653 | this._line = 0;
|
17654 | },
|
17655 | areaEnd: function() {
|
17656 | this._line = NaN;
|
17657 | },
|
17658 | lineStart: function() {
|
17659 | this._point = 0;
|
17660 | },
|
17661 | lineEnd: function() {
|
17662 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
17663 | this._line = 1 - this._line;
|
17664 | },
|
17665 | point: function(x, y) {
|
17666 | x = +x, y = +y;
|
17667 | switch (this._point) {
|
17668 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
17669 | case 1: this._point = 2; // falls through
|
17670 | default: this._context.lineTo(x, y); break;
|
17671 | }
|
17672 | }
|
17673 | };
|
17674 |
|
17675 | function curveLinear(context) {
|
17676 | return new Linear(context);
|
17677 | }
|
17678 |
|
17679 | function x$1(p) {
|
17680 | return p[0];
|
17681 | }
|
17682 |
|
17683 | function y(p) {
|
17684 | return p[1];
|
17685 | }
|
17686 |
|
17687 | function line(x, y$1) {
|
17688 | var defined = constant$1(true),
|
17689 | context = null,
|
17690 | curve = curveLinear,
|
17691 | output = null;
|
17692 |
|
17693 | x = typeof x === "function" ? x : (x === undefined) ? x$1 : constant$1(x);
|
17694 | y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant$1(y$1);
|
17695 |
|
17696 | function line(data) {
|
17697 | var i,
|
17698 | n = (data = array(data)).length,
|
17699 | d,
|
17700 | defined0 = false,
|
17701 | buffer;
|
17702 |
|
17703 | if (context == null) output = curve(buffer = path());
|
17704 |
|
17705 | for (i = 0; i <= n; ++i) {
|
17706 | if (!(i < n && defined(d = data[i], i, data)) === defined0) {
|
17707 | if (defined0 = !defined0) output.lineStart();
|
17708 | else output.lineEnd();
|
17709 | }
|
17710 | if (defined0) output.point(+x(d, i, data), +y$1(d, i, data));
|
17711 | }
|
17712 |
|
17713 | if (buffer) return output = null, buffer + "" || null;
|
17714 | }
|
17715 |
|
17716 | line.x = function(_) {
|
17717 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$1(+_), line) : x;
|
17718 | };
|
17719 |
|
17720 | line.y = function(_) {
|
17721 | return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), line) : y$1;
|
17722 | };
|
17723 |
|
17724 | line.defined = function(_) {
|
17725 | return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), line) : defined;
|
17726 | };
|
17727 |
|
17728 | line.curve = function(_) {
|
17729 | return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
|
17730 | };
|
17731 |
|
17732 | line.context = function(_) {
|
17733 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
|
17734 | };
|
17735 |
|
17736 | return line;
|
17737 | }
|
17738 |
|
17739 | function area(x0, y0, y1) {
|
17740 | var x1 = null,
|
17741 | defined = constant$1(true),
|
17742 | context = null,
|
17743 | curve = curveLinear,
|
17744 | output = null;
|
17745 |
|
17746 | x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x$1 : constant$1(+x0);
|
17747 | y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant$1(0) : constant$1(+y0);
|
17748 | y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant$1(+y1);
|
17749 |
|
17750 | function area(data) {
|
17751 | var i,
|
17752 | j,
|
17753 | k,
|
17754 | n = (data = array(data)).length,
|
17755 | d,
|
17756 | defined0 = false,
|
17757 | buffer,
|
17758 | x0z = new Array(n),
|
17759 | y0z = new Array(n);
|
17760 |
|
17761 | if (context == null) output = curve(buffer = path());
|
17762 |
|
17763 | for (i = 0; i <= n; ++i) {
|
17764 | if (!(i < n && defined(d = data[i], i, data)) === defined0) {
|
17765 | if (defined0 = !defined0) {
|
17766 | j = i;
|
17767 | output.areaStart();
|
17768 | output.lineStart();
|
17769 | } else {
|
17770 | output.lineEnd();
|
17771 | output.lineStart();
|
17772 | for (k = i - 1; k >= j; --k) {
|
17773 | output.point(x0z[k], y0z[k]);
|
17774 | }
|
17775 | output.lineEnd();
|
17776 | output.areaEnd();
|
17777 | }
|
17778 | }
|
17779 | if (defined0) {
|
17780 | x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
|
17781 | output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
|
17782 | }
|
17783 | }
|
17784 |
|
17785 | if (buffer) return output = null, buffer + "" || null;
|
17786 | }
|
17787 |
|
17788 | function arealine() {
|
17789 | return line().defined(defined).curve(curve).context(context);
|
17790 | }
|
17791 |
|
17792 | area.x = function(_) {
|
17793 | return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), x1 = null, area) : x0;
|
17794 | };
|
17795 |
|
17796 | area.x0 = function(_) {
|
17797 | return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), area) : x0;
|
17798 | };
|
17799 |
|
17800 | area.x1 = function(_) {
|
17801 | return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : x1;
|
17802 | };
|
17803 |
|
17804 | area.y = function(_) {
|
17805 | return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), y1 = null, area) : y0;
|
17806 | };
|
17807 |
|
17808 | area.y0 = function(_) {
|
17809 | return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), area) : y0;
|
17810 | };
|
17811 |
|
17812 | area.y1 = function(_) {
|
17813 | return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : y1;
|
17814 | };
|
17815 |
|
17816 | area.lineX0 =
|
17817 | area.lineY0 = function() {
|
17818 | return arealine().x(x0).y(y0);
|
17819 | };
|
17820 |
|
17821 | area.lineY1 = function() {
|
17822 | return arealine().x(x0).y(y1);
|
17823 | };
|
17824 |
|
17825 | area.lineX1 = function() {
|
17826 | return arealine().x(x1).y(y0);
|
17827 | };
|
17828 |
|
17829 | area.defined = function(_) {
|
17830 | return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), area) : defined;
|
17831 | };
|
17832 |
|
17833 | area.curve = function(_) {
|
17834 | return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
|
17835 | };
|
17836 |
|
17837 | area.context = function(_) {
|
17838 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
|
17839 | };
|
17840 |
|
17841 | return area;
|
17842 | }
|
17843 |
|
17844 | function descending$1(a, b) {
|
17845 | return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
17846 | }
|
17847 |
|
17848 | function identity$1(d) {
|
17849 | return d;
|
17850 | }
|
17851 |
|
17852 | function pie() {
|
17853 | var value = identity$1,
|
17854 | sortValues = descending$1,
|
17855 | sort = null,
|
17856 | startAngle = constant$1(0),
|
17857 | endAngle = constant$1(tau),
|
17858 | padAngle = constant$1(0);
|
17859 |
|
17860 | function pie(data) {
|
17861 | var i,
|
17862 | n = (data = array(data)).length,
|
17863 | j,
|
17864 | k,
|
17865 | sum = 0,
|
17866 | index = new Array(n),
|
17867 | arcs = new Array(n),
|
17868 | a0 = +startAngle.apply(this, arguments),
|
17869 | da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),
|
17870 | a1,
|
17871 | p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
|
17872 | pa = p * (da < 0 ? -1 : 1),
|
17873 | v;
|
17874 |
|
17875 | for (i = 0; i < n; ++i) {
|
17876 | if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
|
17877 | sum += v;
|
17878 | }
|
17879 | }
|
17880 |
|
17881 | // Optionally sort the arcs by previously-computed values or by data.
|
17882 | if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
|
17883 | else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
|
17884 |
|
17885 | // Compute the arcs! They are stored in the original data's order.
|
17886 | for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
|
17887 | j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
|
17888 | data: data[j],
|
17889 | index: i,
|
17890 | value: v,
|
17891 | startAngle: a0,
|
17892 | endAngle: a1,
|
17893 | padAngle: p
|
17894 | };
|
17895 | }
|
17896 |
|
17897 | return arcs;
|
17898 | }
|
17899 |
|
17900 | pie.value = function(_) {
|
17901 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value;
|
17902 | };
|
17903 |
|
17904 | pie.sortValues = function(_) {
|
17905 | return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
|
17906 | };
|
17907 |
|
17908 | pie.sort = function(_) {
|
17909 | return arguments.length ? (sort = _, sortValues = null, pie) : sort;
|
17910 | };
|
17911 |
|
17912 | pie.startAngle = function(_) {
|
17913 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : startAngle;
|
17914 | };
|
17915 |
|
17916 | pie.endAngle = function(_) {
|
17917 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : endAngle;
|
17918 | };
|
17919 |
|
17920 | pie.padAngle = function(_) {
|
17921 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : padAngle;
|
17922 | };
|
17923 |
|
17924 | return pie;
|
17925 | }
|
17926 |
|
17927 | var curveRadialLinear = curveRadial(curveLinear);
|
17928 |
|
17929 | function Radial(curve) {
|
17930 | this._curve = curve;
|
17931 | }
|
17932 |
|
17933 | Radial.prototype = {
|
17934 | areaStart: function() {
|
17935 | this._curve.areaStart();
|
17936 | },
|
17937 | areaEnd: function() {
|
17938 | this._curve.areaEnd();
|
17939 | },
|
17940 | lineStart: function() {
|
17941 | this._curve.lineStart();
|
17942 | },
|
17943 | lineEnd: function() {
|
17944 | this._curve.lineEnd();
|
17945 | },
|
17946 | point: function(a, r) {
|
17947 | this._curve.point(r * Math.sin(a), r * -Math.cos(a));
|
17948 | }
|
17949 | };
|
17950 |
|
17951 | function curveRadial(curve) {
|
17952 |
|
17953 | function radial(context) {
|
17954 | return new Radial(curve(context));
|
17955 | }
|
17956 |
|
17957 | radial._curve = curve;
|
17958 |
|
17959 | return radial;
|
17960 | }
|
17961 |
|
17962 | function lineRadial(l) {
|
17963 | var c = l.curve;
|
17964 |
|
17965 | l.angle = l.x, delete l.x;
|
17966 | l.radius = l.y, delete l.y;
|
17967 |
|
17968 | l.curve = function(_) {
|
17969 | return arguments.length ? c(curveRadial(_)) : c()._curve;
|
17970 | };
|
17971 |
|
17972 | return l;
|
17973 | }
|
17974 |
|
17975 | function lineRadial$1() {
|
17976 | return lineRadial(line().curve(curveRadialLinear));
|
17977 | }
|
17978 |
|
17979 | function areaRadial() {
|
17980 | var a = area().curve(curveRadialLinear),
|
17981 | c = a.curve,
|
17982 | x0 = a.lineX0,
|
17983 | x1 = a.lineX1,
|
17984 | y0 = a.lineY0,
|
17985 | y1 = a.lineY1;
|
17986 |
|
17987 | a.angle = a.x, delete a.x;
|
17988 | a.startAngle = a.x0, delete a.x0;
|
17989 | a.endAngle = a.x1, delete a.x1;
|
17990 | a.radius = a.y, delete a.y;
|
17991 | a.innerRadius = a.y0, delete a.y0;
|
17992 | a.outerRadius = a.y1, delete a.y1;
|
17993 | a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
|
17994 | a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
|
17995 | a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
|
17996 | a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
|
17997 |
|
17998 | a.curve = function(_) {
|
17999 | return arguments.length ? c(curveRadial(_)) : c()._curve;
|
18000 | };
|
18001 |
|
18002 | return a;
|
18003 | }
|
18004 |
|
18005 | function pointRadial(x, y) {
|
18006 | return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
|
18007 | }
|
18008 |
|
18009 | class Bump {
|
18010 | constructor(context, x) {
|
18011 | this._context = context;
|
18012 | this._x = x;
|
18013 | }
|
18014 | areaStart() {
|
18015 | this._line = 0;
|
18016 | }
|
18017 | areaEnd() {
|
18018 | this._line = NaN;
|
18019 | }
|
18020 | lineStart() {
|
18021 | this._point = 0;
|
18022 | }
|
18023 | lineEnd() {
|
18024 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
18025 | this._line = 1 - this._line;
|
18026 | }
|
18027 | point(x, y) {
|
18028 | x = +x, y = +y;
|
18029 | switch (this._point) {
|
18030 | case 0: {
|
18031 | this._point = 1;
|
18032 | if (this._line) this._context.lineTo(x, y);
|
18033 | else this._context.moveTo(x, y);
|
18034 | break;
|
18035 | }
|
18036 | case 1: this._point = 2; // falls through
|
18037 | default: {
|
18038 | if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
|
18039 | else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
|
18040 | break;
|
18041 | }
|
18042 | }
|
18043 | this._x0 = x, this._y0 = y;
|
18044 | }
|
18045 | }
|
18046 |
|
18047 | class BumpRadial {
|
18048 | constructor(context) {
|
18049 | this._context = context;
|
18050 | }
|
18051 | lineStart() {
|
18052 | this._point = 0;
|
18053 | }
|
18054 | lineEnd() {}
|
18055 | point(x, y) {
|
18056 | x = +x, y = +y;
|
18057 | if (this._point++ === 0) {
|
18058 | this._x0 = x, this._y0 = y;
|
18059 | } else {
|
18060 | const p0 = pointRadial(this._x0, this._y0);
|
18061 | const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2);
|
18062 | const p2 = pointRadial(x, this._y0);
|
18063 | const p3 = pointRadial(x, y);
|
18064 | this._context.moveTo(...p0);
|
18065 | this._context.bezierCurveTo(...p1, ...p2, ...p3);
|
18066 | }
|
18067 | }
|
18068 | }
|
18069 |
|
18070 | function bumpX(context) {
|
18071 | return new Bump(context, true);
|
18072 | }
|
18073 |
|
18074 | function bumpY(context) {
|
18075 | return new Bump(context, false);
|
18076 | }
|
18077 |
|
18078 | function bumpRadial(context) {
|
18079 | return new BumpRadial(context);
|
18080 | }
|
18081 |
|
18082 | function linkSource(d) {
|
18083 | return d.source;
|
18084 | }
|
18085 |
|
18086 | function linkTarget(d) {
|
18087 | return d.target;
|
18088 | }
|
18089 |
|
18090 | function link(curve) {
|
18091 | let source = linkSource;
|
18092 | let target = linkTarget;
|
18093 | let x = x$1;
|
18094 | let y$1 = y;
|
18095 | let context = null;
|
18096 | let output = null;
|
18097 |
|
18098 | function link() {
|
18099 | let buffer;
|
18100 | const argv = slice.call(arguments);
|
18101 | const s = source.apply(this, argv);
|
18102 | const t = target.apply(this, argv);
|
18103 | if (context == null) output = curve(buffer = path());
|
18104 | output.lineStart();
|
18105 | argv[0] = s, output.point(+x.apply(this, argv), +y$1.apply(this, argv));
|
18106 | argv[0] = t, output.point(+x.apply(this, argv), +y$1.apply(this, argv));
|
18107 | output.lineEnd();
|
18108 | if (buffer) return output = null, buffer + "" || null;
|
18109 | }
|
18110 |
|
18111 | link.source = function(_) {
|
18112 | return arguments.length ? (source = _, link) : source;
|
18113 | };
|
18114 |
|
18115 | link.target = function(_) {
|
18116 | return arguments.length ? (target = _, link) : target;
|
18117 | };
|
18118 |
|
18119 | link.x = function(_) {
|
18120 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$1(+_), link) : x;
|
18121 | };
|
18122 |
|
18123 | link.y = function(_) {
|
18124 | return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), link) : y$1;
|
18125 | };
|
18126 |
|
18127 | link.context = function(_) {
|
18128 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), link) : context;
|
18129 | };
|
18130 |
|
18131 | return link;
|
18132 | }
|
18133 |
|
18134 | function linkHorizontal() {
|
18135 | return link(bumpX);
|
18136 | }
|
18137 |
|
18138 | function linkVertical() {
|
18139 | return link(bumpY);
|
18140 | }
|
18141 |
|
18142 | function linkRadial() {
|
18143 | const l = link(bumpRadial);
|
18144 | l.angle = l.x, delete l.x;
|
18145 | l.radius = l.y, delete l.y;
|
18146 | return l;
|
18147 | }
|
18148 |
|
18149 | const sqrt3$2 = sqrt(3);
|
18150 |
|
18151 | var asterisk = {
|
18152 | draw(context, size) {
|
18153 | const r = sqrt(size + min(size / 28, 0.75)) * 0.59436;
|
18154 | const t = r / 2;
|
18155 | const u = t * sqrt3$2;
|
18156 | context.moveTo(0, r);
|
18157 | context.lineTo(0, -r);
|
18158 | context.moveTo(-u, -t);
|
18159 | context.lineTo(u, t);
|
18160 | context.moveTo(-u, t);
|
18161 | context.lineTo(u, -t);
|
18162 | }
|
18163 | };
|
18164 |
|
18165 | var circle = {
|
18166 | draw(context, size) {
|
18167 | const r = sqrt(size / pi);
|
18168 | context.moveTo(r, 0);
|
18169 | context.arc(0, 0, r, 0, tau);
|
18170 | }
|
18171 | };
|
18172 |
|
18173 | var cross = {
|
18174 | draw(context, size) {
|
18175 | const r = sqrt(size / 5) / 2;
|
18176 | context.moveTo(-3 * r, -r);
|
18177 | context.lineTo(-r, -r);
|
18178 | context.lineTo(-r, -3 * r);
|
18179 | context.lineTo(r, -3 * r);
|
18180 | context.lineTo(r, -r);
|
18181 | context.lineTo(3 * r, -r);
|
18182 | context.lineTo(3 * r, r);
|
18183 | context.lineTo(r, r);
|
18184 | context.lineTo(r, 3 * r);
|
18185 | context.lineTo(-r, 3 * r);
|
18186 | context.lineTo(-r, r);
|
18187 | context.lineTo(-3 * r, r);
|
18188 | context.closePath();
|
18189 | }
|
18190 | };
|
18191 |
|
18192 | const tan30 = sqrt(1 / 3);
|
18193 | const tan30_2 = tan30 * 2;
|
18194 |
|
18195 | var diamond = {
|
18196 | draw(context, size) {
|
18197 | const y = sqrt(size / tan30_2);
|
18198 | const x = y * tan30;
|
18199 | context.moveTo(0, -y);
|
18200 | context.lineTo(x, 0);
|
18201 | context.lineTo(0, y);
|
18202 | context.lineTo(-x, 0);
|
18203 | context.closePath();
|
18204 | }
|
18205 | };
|
18206 |
|
18207 | var diamond2 = {
|
18208 | draw(context, size) {
|
18209 | const r = sqrt(size) * 0.62625;
|
18210 | context.moveTo(0, -r);
|
18211 | context.lineTo(r, 0);
|
18212 | context.lineTo(0, r);
|
18213 | context.lineTo(-r, 0);
|
18214 | context.closePath();
|
18215 | }
|
18216 | };
|
18217 |
|
18218 | var plus = {
|
18219 | draw(context, size) {
|
18220 | const r = sqrt(size - min(size / 7, 2)) * 0.87559;
|
18221 | context.moveTo(-r, 0);
|
18222 | context.lineTo(r, 0);
|
18223 | context.moveTo(0, r);
|
18224 | context.lineTo(0, -r);
|
18225 | }
|
18226 | };
|
18227 |
|
18228 | var square = {
|
18229 | draw(context, size) {
|
18230 | const w = sqrt(size);
|
18231 | const x = -w / 2;
|
18232 | context.rect(x, x, w, w);
|
18233 | }
|
18234 | };
|
18235 |
|
18236 | var square2 = {
|
18237 | draw(context, size) {
|
18238 | const r = sqrt(size) * 0.4431;
|
18239 | context.moveTo(r, r);
|
18240 | context.lineTo(r, -r);
|
18241 | context.lineTo(-r, -r);
|
18242 | context.lineTo(-r, r);
|
18243 | context.closePath();
|
18244 | }
|
18245 | };
|
18246 |
|
18247 | const ka = 0.89081309152928522810;
|
18248 | const kr = sin(pi / 10) / sin(7 * pi / 10);
|
18249 | const kx = sin(tau / 10) * kr;
|
18250 | const ky = -cos(tau / 10) * kr;
|
18251 |
|
18252 | var star = {
|
18253 | draw(context, size) {
|
18254 | const r = sqrt(size * ka);
|
18255 | const x = kx * r;
|
18256 | const y = ky * r;
|
18257 | context.moveTo(0, -r);
|
18258 | context.lineTo(x, y);
|
18259 | for (let i = 1; i < 5; ++i) {
|
18260 | const a = tau * i / 5;
|
18261 | const c = cos(a);
|
18262 | const s = sin(a);
|
18263 | context.lineTo(s * r, -c * r);
|
18264 | context.lineTo(c * x - s * y, s * x + c * y);
|
18265 | }
|
18266 | context.closePath();
|
18267 | }
|
18268 | };
|
18269 |
|
18270 | const sqrt3$1 = sqrt(3);
|
18271 |
|
18272 | var triangle = {
|
18273 | draw(context, size) {
|
18274 | const y = -sqrt(size / (sqrt3$1 * 3));
|
18275 | context.moveTo(0, y * 2);
|
18276 | context.lineTo(-sqrt3$1 * y, -y);
|
18277 | context.lineTo(sqrt3$1 * y, -y);
|
18278 | context.closePath();
|
18279 | }
|
18280 | };
|
18281 |
|
18282 | const sqrt3 = sqrt(3);
|
18283 |
|
18284 | var triangle2 = {
|
18285 | draw(context, size) {
|
18286 | const s = sqrt(size) * 0.6824;
|
18287 | const t = s / 2;
|
18288 | const u = (s * sqrt3) / 2; // cos(Math.PI / 6)
|
18289 | context.moveTo(0, -s);
|
18290 | context.lineTo(u, t);
|
18291 | context.lineTo(-u, t);
|
18292 | context.closePath();
|
18293 | }
|
18294 | };
|
18295 |
|
18296 | const c = -0.5;
|
18297 | const s = sqrt(3) / 2;
|
18298 | const k = 1 / sqrt(12);
|
18299 | const a = (k / 2 + 1) * 3;
|
18300 |
|
18301 | var wye = {
|
18302 | draw(context, size) {
|
18303 | const r = sqrt(size / a);
|
18304 | const x0 = r / 2, y0 = r * k;
|
18305 | const x1 = x0, y1 = r * k + r;
|
18306 | const x2 = -x1, y2 = y1;
|
18307 | context.moveTo(x0, y0);
|
18308 | context.lineTo(x1, y1);
|
18309 | context.lineTo(x2, y2);
|
18310 | context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
|
18311 | context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
|
18312 | context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
|
18313 | context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
|
18314 | context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
|
18315 | context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
|
18316 | context.closePath();
|
18317 | }
|
18318 | };
|
18319 |
|
18320 | var x = {
|
18321 | draw(context, size) {
|
18322 | const r = sqrt(size - min(size / 6, 1.7)) * 0.6189;
|
18323 | context.moveTo(-r, -r);
|
18324 | context.lineTo(r, r);
|
18325 | context.moveTo(-r, r);
|
18326 | context.lineTo(r, -r);
|
18327 | }
|
18328 | };
|
18329 |
|
18330 | // These symbols are designed to be filled.
|
18331 | const symbolsFill = [
|
18332 | circle,
|
18333 | cross,
|
18334 | diamond,
|
18335 | square,
|
18336 | star,
|
18337 | triangle,
|
18338 | wye
|
18339 | ];
|
18340 |
|
18341 | // These symbols are designed to be stroked (with a width of 1.5px and round caps).
|
18342 | const symbolsStroke = [
|
18343 | circle,
|
18344 | plus,
|
18345 | x,
|
18346 | triangle2,
|
18347 | asterisk,
|
18348 | square2,
|
18349 | diamond2
|
18350 | ];
|
18351 |
|
18352 | function Symbol$1(type, size) {
|
18353 | let context = null;
|
18354 |
|
18355 | type = typeof type === "function" ? type : constant$1(type || circle);
|
18356 | size = typeof size === "function" ? size : constant$1(size === undefined ? 64 : +size);
|
18357 |
|
18358 | function symbol() {
|
18359 | let buffer;
|
18360 | if (!context) context = buffer = path();
|
18361 | type.apply(this, arguments).draw(context, +size.apply(this, arguments));
|
18362 | if (buffer) return context = null, buffer + "" || null;
|
18363 | }
|
18364 |
|
18365 | symbol.type = function(_) {
|
18366 | return arguments.length ? (type = typeof _ === "function" ? _ : constant$1(_), symbol) : type;
|
18367 | };
|
18368 |
|
18369 | symbol.size = function(_) {
|
18370 | return arguments.length ? (size = typeof _ === "function" ? _ : constant$1(+_), symbol) : size;
|
18371 | };
|
18372 |
|
18373 | symbol.context = function(_) {
|
18374 | return arguments.length ? (context = _ == null ? null : _, symbol) : context;
|
18375 | };
|
18376 |
|
18377 | return symbol;
|
18378 | }
|
18379 |
|
18380 | function noop() {}
|
18381 |
|
18382 | function point$3(that, x, y) {
|
18383 | that._context.bezierCurveTo(
|
18384 | (2 * that._x0 + that._x1) / 3,
|
18385 | (2 * that._y0 + that._y1) / 3,
|
18386 | (that._x0 + 2 * that._x1) / 3,
|
18387 | (that._y0 + 2 * that._y1) / 3,
|
18388 | (that._x0 + 4 * that._x1 + x) / 6,
|
18389 | (that._y0 + 4 * that._y1 + y) / 6
|
18390 | );
|
18391 | }
|
18392 |
|
18393 | function Basis(context) {
|
18394 | this._context = context;
|
18395 | }
|
18396 |
|
18397 | Basis.prototype = {
|
18398 | areaStart: function() {
|
18399 | this._line = 0;
|
18400 | },
|
18401 | areaEnd: function() {
|
18402 | this._line = NaN;
|
18403 | },
|
18404 | lineStart: function() {
|
18405 | this._x0 = this._x1 =
|
18406 | this._y0 = this._y1 = NaN;
|
18407 | this._point = 0;
|
18408 | },
|
18409 | lineEnd: function() {
|
18410 | switch (this._point) {
|
18411 | case 3: point$3(this, this._x1, this._y1); // falls through
|
18412 | case 2: this._context.lineTo(this._x1, this._y1); break;
|
18413 | }
|
18414 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
18415 | this._line = 1 - this._line;
|
18416 | },
|
18417 | point: function(x, y) {
|
18418 | x = +x, y = +y;
|
18419 | switch (this._point) {
|
18420 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
18421 | case 1: this._point = 2; break;
|
18422 | case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through
|
18423 | default: point$3(this, x, y); break;
|
18424 | }
|
18425 | this._x0 = this._x1, this._x1 = x;
|
18426 | this._y0 = this._y1, this._y1 = y;
|
18427 | }
|
18428 | };
|
18429 |
|
18430 | function basis(context) {
|
18431 | return new Basis(context);
|
18432 | }
|
18433 |
|
18434 | function BasisClosed(context) {
|
18435 | this._context = context;
|
18436 | }
|
18437 |
|
18438 | BasisClosed.prototype = {
|
18439 | areaStart: noop,
|
18440 | areaEnd: noop,
|
18441 | lineStart: function() {
|
18442 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
|
18443 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
|
18444 | this._point = 0;
|
18445 | },
|
18446 | lineEnd: function() {
|
18447 | switch (this._point) {
|
18448 | case 1: {
|
18449 | this._context.moveTo(this._x2, this._y2);
|
18450 | this._context.closePath();
|
18451 | break;
|
18452 | }
|
18453 | case 2: {
|
18454 | this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
|
18455 | this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
|
18456 | this._context.closePath();
|
18457 | break;
|
18458 | }
|
18459 | case 3: {
|
18460 | this.point(this._x2, this._y2);
|
18461 | this.point(this._x3, this._y3);
|
18462 | this.point(this._x4, this._y4);
|
18463 | break;
|
18464 | }
|
18465 | }
|
18466 | },
|
18467 | point: function(x, y) {
|
18468 | x = +x, y = +y;
|
18469 | switch (this._point) {
|
18470 | case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
|
18471 | case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
|
18472 | 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;
|
18473 | default: point$3(this, x, y); break;
|
18474 | }
|
18475 | this._x0 = this._x1, this._x1 = x;
|
18476 | this._y0 = this._y1, this._y1 = y;
|
18477 | }
|
18478 | };
|
18479 |
|
18480 | function basisClosed(context) {
|
18481 | return new BasisClosed(context);
|
18482 | }
|
18483 |
|
18484 | function BasisOpen(context) {
|
18485 | this._context = context;
|
18486 | }
|
18487 |
|
18488 | BasisOpen.prototype = {
|
18489 | areaStart: function() {
|
18490 | this._line = 0;
|
18491 | },
|
18492 | areaEnd: function() {
|
18493 | this._line = NaN;
|
18494 | },
|
18495 | lineStart: function() {
|
18496 | this._x0 = this._x1 =
|
18497 | this._y0 = this._y1 = NaN;
|
18498 | this._point = 0;
|
18499 | },
|
18500 | lineEnd: function() {
|
18501 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
18502 | this._line = 1 - this._line;
|
18503 | },
|
18504 | point: function(x, y) {
|
18505 | x = +x, y = +y;
|
18506 | switch (this._point) {
|
18507 | case 0: this._point = 1; break;
|
18508 | case 1: this._point = 2; break;
|
18509 | 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;
|
18510 | case 3: this._point = 4; // falls through
|
18511 | default: point$3(this, x, y); break;
|
18512 | }
|
18513 | this._x0 = this._x1, this._x1 = x;
|
18514 | this._y0 = this._y1, this._y1 = y;
|
18515 | }
|
18516 | };
|
18517 |
|
18518 | function basisOpen(context) {
|
18519 | return new BasisOpen(context);
|
18520 | }
|
18521 |
|
18522 | function Bundle(context, beta) {
|
18523 | this._basis = new Basis(context);
|
18524 | this._beta = beta;
|
18525 | }
|
18526 |
|
18527 | Bundle.prototype = {
|
18528 | lineStart: function() {
|
18529 | this._x = [];
|
18530 | this._y = [];
|
18531 | this._basis.lineStart();
|
18532 | },
|
18533 | lineEnd: function() {
|
18534 | var x = this._x,
|
18535 | y = this._y,
|
18536 | j = x.length - 1;
|
18537 |
|
18538 | if (j > 0) {
|
18539 | var x0 = x[0],
|
18540 | y0 = y[0],
|
18541 | dx = x[j] - x0,
|
18542 | dy = y[j] - y0,
|
18543 | i = -1,
|
18544 | t;
|
18545 |
|
18546 | while (++i <= j) {
|
18547 | t = i / j;
|
18548 | this._basis.point(
|
18549 | this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
|
18550 | this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
|
18551 | );
|
18552 | }
|
18553 | }
|
18554 |
|
18555 | this._x = this._y = null;
|
18556 | this._basis.lineEnd();
|
18557 | },
|
18558 | point: function(x, y) {
|
18559 | this._x.push(+x);
|
18560 | this._y.push(+y);
|
18561 | }
|
18562 | };
|
18563 |
|
18564 | var bundle = (function custom(beta) {
|
18565 |
|
18566 | function bundle(context) {
|
18567 | return beta === 1 ? new Basis(context) : new Bundle(context, beta);
|
18568 | }
|
18569 |
|
18570 | bundle.beta = function(beta) {
|
18571 | return custom(+beta);
|
18572 | };
|
18573 |
|
18574 | return bundle;
|
18575 | })(0.85);
|
18576 |
|
18577 | function point$2(that, x, y) {
|
18578 | that._context.bezierCurveTo(
|
18579 | that._x1 + that._k * (that._x2 - that._x0),
|
18580 | that._y1 + that._k * (that._y2 - that._y0),
|
18581 | that._x2 + that._k * (that._x1 - x),
|
18582 | that._y2 + that._k * (that._y1 - y),
|
18583 | that._x2,
|
18584 | that._y2
|
18585 | );
|
18586 | }
|
18587 |
|
18588 | function Cardinal(context, tension) {
|
18589 | this._context = context;
|
18590 | this._k = (1 - tension) / 6;
|
18591 | }
|
18592 |
|
18593 | Cardinal.prototype = {
|
18594 | areaStart: function() {
|
18595 | this._line = 0;
|
18596 | },
|
18597 | areaEnd: function() {
|
18598 | this._line = NaN;
|
18599 | },
|
18600 | lineStart: function() {
|
18601 | this._x0 = this._x1 = this._x2 =
|
18602 | this._y0 = this._y1 = this._y2 = NaN;
|
18603 | this._point = 0;
|
18604 | },
|
18605 | lineEnd: function() {
|
18606 | switch (this._point) {
|
18607 | case 2: this._context.lineTo(this._x2, this._y2); break;
|
18608 | case 3: point$2(this, this._x1, this._y1); break;
|
18609 | }
|
18610 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
18611 | this._line = 1 - this._line;
|
18612 | },
|
18613 | point: function(x, y) {
|
18614 | x = +x, y = +y;
|
18615 | switch (this._point) {
|
18616 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
18617 | case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
|
18618 | case 2: this._point = 3; // falls through
|
18619 | default: point$2(this, x, y); break;
|
18620 | }
|
18621 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18622 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18623 | }
|
18624 | };
|
18625 |
|
18626 | var cardinal = (function custom(tension) {
|
18627 |
|
18628 | function cardinal(context) {
|
18629 | return new Cardinal(context, tension);
|
18630 | }
|
18631 |
|
18632 | cardinal.tension = function(tension) {
|
18633 | return custom(+tension);
|
18634 | };
|
18635 |
|
18636 | return cardinal;
|
18637 | })(0);
|
18638 |
|
18639 | function CardinalClosed(context, tension) {
|
18640 | this._context = context;
|
18641 | this._k = (1 - tension) / 6;
|
18642 | }
|
18643 |
|
18644 | CardinalClosed.prototype = {
|
18645 | areaStart: noop,
|
18646 | areaEnd: noop,
|
18647 | lineStart: function() {
|
18648 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
|
18649 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
|
18650 | this._point = 0;
|
18651 | },
|
18652 | lineEnd: function() {
|
18653 | switch (this._point) {
|
18654 | case 1: {
|
18655 | this._context.moveTo(this._x3, this._y3);
|
18656 | this._context.closePath();
|
18657 | break;
|
18658 | }
|
18659 | case 2: {
|
18660 | this._context.lineTo(this._x3, this._y3);
|
18661 | this._context.closePath();
|
18662 | break;
|
18663 | }
|
18664 | case 3: {
|
18665 | this.point(this._x3, this._y3);
|
18666 | this.point(this._x4, this._y4);
|
18667 | this.point(this._x5, this._y5);
|
18668 | break;
|
18669 | }
|
18670 | }
|
18671 | },
|
18672 | point: function(x, y) {
|
18673 | x = +x, y = +y;
|
18674 | switch (this._point) {
|
18675 | case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
|
18676 | case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
|
18677 | case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
|
18678 | default: point$2(this, x, y); break;
|
18679 | }
|
18680 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18681 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18682 | }
|
18683 | };
|
18684 |
|
18685 | var cardinalClosed = (function custom(tension) {
|
18686 |
|
18687 | function cardinal(context) {
|
18688 | return new CardinalClosed(context, tension);
|
18689 | }
|
18690 |
|
18691 | cardinal.tension = function(tension) {
|
18692 | return custom(+tension);
|
18693 | };
|
18694 |
|
18695 | return cardinal;
|
18696 | })(0);
|
18697 |
|
18698 | function CardinalOpen(context, tension) {
|
18699 | this._context = context;
|
18700 | this._k = (1 - tension) / 6;
|
18701 | }
|
18702 |
|
18703 | CardinalOpen.prototype = {
|
18704 | areaStart: function() {
|
18705 | this._line = 0;
|
18706 | },
|
18707 | areaEnd: function() {
|
18708 | this._line = NaN;
|
18709 | },
|
18710 | lineStart: function() {
|
18711 | this._x0 = this._x1 = this._x2 =
|
18712 | this._y0 = this._y1 = this._y2 = NaN;
|
18713 | this._point = 0;
|
18714 | },
|
18715 | lineEnd: function() {
|
18716 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
18717 | this._line = 1 - this._line;
|
18718 | },
|
18719 | point: function(x, y) {
|
18720 | x = +x, y = +y;
|
18721 | switch (this._point) {
|
18722 | case 0: this._point = 1; break;
|
18723 | case 1: this._point = 2; break;
|
18724 | case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
|
18725 | case 3: this._point = 4; // falls through
|
18726 | default: point$2(this, x, y); break;
|
18727 | }
|
18728 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18729 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18730 | }
|
18731 | };
|
18732 |
|
18733 | var cardinalOpen = (function custom(tension) {
|
18734 |
|
18735 | function cardinal(context) {
|
18736 | return new CardinalOpen(context, tension);
|
18737 | }
|
18738 |
|
18739 | cardinal.tension = function(tension) {
|
18740 | return custom(+tension);
|
18741 | };
|
18742 |
|
18743 | return cardinal;
|
18744 | })(0);
|
18745 |
|
18746 | function point$1(that, x, y) {
|
18747 | var x1 = that._x1,
|
18748 | y1 = that._y1,
|
18749 | x2 = that._x2,
|
18750 | y2 = that._y2;
|
18751 |
|
18752 | if (that._l01_a > epsilon) {
|
18753 | var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
|
18754 | n = 3 * that._l01_a * (that._l01_a + that._l12_a);
|
18755 | x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
|
18756 | y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
|
18757 | }
|
18758 |
|
18759 | if (that._l23_a > epsilon) {
|
18760 | var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
|
18761 | m = 3 * that._l23_a * (that._l23_a + that._l12_a);
|
18762 | x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
|
18763 | y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
|
18764 | }
|
18765 |
|
18766 | that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
|
18767 | }
|
18768 |
|
18769 | function CatmullRom(context, alpha) {
|
18770 | this._context = context;
|
18771 | this._alpha = alpha;
|
18772 | }
|
18773 |
|
18774 | CatmullRom.prototype = {
|
18775 | areaStart: function() {
|
18776 | this._line = 0;
|
18777 | },
|
18778 | areaEnd: function() {
|
18779 | this._line = NaN;
|
18780 | },
|
18781 | lineStart: function() {
|
18782 | this._x0 = this._x1 = this._x2 =
|
18783 | this._y0 = this._y1 = this._y2 = NaN;
|
18784 | this._l01_a = this._l12_a = this._l23_a =
|
18785 | this._l01_2a = this._l12_2a = this._l23_2a =
|
18786 | this._point = 0;
|
18787 | },
|
18788 | lineEnd: function() {
|
18789 | switch (this._point) {
|
18790 | case 2: this._context.lineTo(this._x2, this._y2); break;
|
18791 | case 3: this.point(this._x2, this._y2); break;
|
18792 | }
|
18793 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
18794 | this._line = 1 - this._line;
|
18795 | },
|
18796 | point: function(x, y) {
|
18797 | x = +x, y = +y;
|
18798 |
|
18799 | if (this._point) {
|
18800 | var x23 = this._x2 - x,
|
18801 | y23 = this._y2 - y;
|
18802 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
18803 | }
|
18804 |
|
18805 | switch (this._point) {
|
18806 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
18807 | case 1: this._point = 2; break;
|
18808 | case 2: this._point = 3; // falls through
|
18809 | default: point$1(this, x, y); break;
|
18810 | }
|
18811 |
|
18812 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
18813 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
18814 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18815 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18816 | }
|
18817 | };
|
18818 |
|
18819 | var catmullRom = (function custom(alpha) {
|
18820 |
|
18821 | function catmullRom(context) {
|
18822 | return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
|
18823 | }
|
18824 |
|
18825 | catmullRom.alpha = function(alpha) {
|
18826 | return custom(+alpha);
|
18827 | };
|
18828 |
|
18829 | return catmullRom;
|
18830 | })(0.5);
|
18831 |
|
18832 | function CatmullRomClosed(context, alpha) {
|
18833 | this._context = context;
|
18834 | this._alpha = alpha;
|
18835 | }
|
18836 |
|
18837 | CatmullRomClosed.prototype = {
|
18838 | areaStart: noop,
|
18839 | areaEnd: noop,
|
18840 | lineStart: function() {
|
18841 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
|
18842 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
|
18843 | this._l01_a = this._l12_a = this._l23_a =
|
18844 | this._l01_2a = this._l12_2a = this._l23_2a =
|
18845 | this._point = 0;
|
18846 | },
|
18847 | lineEnd: function() {
|
18848 | switch (this._point) {
|
18849 | case 1: {
|
18850 | this._context.moveTo(this._x3, this._y3);
|
18851 | this._context.closePath();
|
18852 | break;
|
18853 | }
|
18854 | case 2: {
|
18855 | this._context.lineTo(this._x3, this._y3);
|
18856 | this._context.closePath();
|
18857 | break;
|
18858 | }
|
18859 | case 3: {
|
18860 | this.point(this._x3, this._y3);
|
18861 | this.point(this._x4, this._y4);
|
18862 | this.point(this._x5, this._y5);
|
18863 | break;
|
18864 | }
|
18865 | }
|
18866 | },
|
18867 | point: function(x, y) {
|
18868 | x = +x, y = +y;
|
18869 |
|
18870 | if (this._point) {
|
18871 | var x23 = this._x2 - x,
|
18872 | y23 = this._y2 - y;
|
18873 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
18874 | }
|
18875 |
|
18876 | switch (this._point) {
|
18877 | case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
|
18878 | case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
|
18879 | case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
|
18880 | default: point$1(this, x, y); break;
|
18881 | }
|
18882 |
|
18883 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
18884 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
18885 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18886 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18887 | }
|
18888 | };
|
18889 |
|
18890 | var catmullRomClosed = (function custom(alpha) {
|
18891 |
|
18892 | function catmullRom(context) {
|
18893 | return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
|
18894 | }
|
18895 |
|
18896 | catmullRom.alpha = function(alpha) {
|
18897 | return custom(+alpha);
|
18898 | };
|
18899 |
|
18900 | return catmullRom;
|
18901 | })(0.5);
|
18902 |
|
18903 | function CatmullRomOpen(context, alpha) {
|
18904 | this._context = context;
|
18905 | this._alpha = alpha;
|
18906 | }
|
18907 |
|
18908 | CatmullRomOpen.prototype = {
|
18909 | areaStart: function() {
|
18910 | this._line = 0;
|
18911 | },
|
18912 | areaEnd: function() {
|
18913 | this._line = NaN;
|
18914 | },
|
18915 | lineStart: function() {
|
18916 | this._x0 = this._x1 = this._x2 =
|
18917 | this._y0 = this._y1 = this._y2 = NaN;
|
18918 | this._l01_a = this._l12_a = this._l23_a =
|
18919 | this._l01_2a = this._l12_2a = this._l23_2a =
|
18920 | this._point = 0;
|
18921 | },
|
18922 | lineEnd: function() {
|
18923 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
18924 | this._line = 1 - this._line;
|
18925 | },
|
18926 | point: function(x, y) {
|
18927 | x = +x, y = +y;
|
18928 |
|
18929 | if (this._point) {
|
18930 | var x23 = this._x2 - x,
|
18931 | y23 = this._y2 - y;
|
18932 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
18933 | }
|
18934 |
|
18935 | switch (this._point) {
|
18936 | case 0: this._point = 1; break;
|
18937 | case 1: this._point = 2; break;
|
18938 | case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
|
18939 | case 3: this._point = 4; // falls through
|
18940 | default: point$1(this, x, y); break;
|
18941 | }
|
18942 |
|
18943 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
18944 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
18945 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18946 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18947 | }
|
18948 | };
|
18949 |
|
18950 | var catmullRomOpen = (function custom(alpha) {
|
18951 |
|
18952 | function catmullRom(context) {
|
18953 | return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
|
18954 | }
|
18955 |
|
18956 | catmullRom.alpha = function(alpha) {
|
18957 | return custom(+alpha);
|
18958 | };
|
18959 |
|
18960 | return catmullRom;
|
18961 | })(0.5);
|
18962 |
|
18963 | function LinearClosed(context) {
|
18964 | this._context = context;
|
18965 | }
|
18966 |
|
18967 | LinearClosed.prototype = {
|
18968 | areaStart: noop,
|
18969 | areaEnd: noop,
|
18970 | lineStart: function() {
|
18971 | this._point = 0;
|
18972 | },
|
18973 | lineEnd: function() {
|
18974 | if (this._point) this._context.closePath();
|
18975 | },
|
18976 | point: function(x, y) {
|
18977 | x = +x, y = +y;
|
18978 | if (this._point) this._context.lineTo(x, y);
|
18979 | else this._point = 1, this._context.moveTo(x, y);
|
18980 | }
|
18981 | };
|
18982 |
|
18983 | function linearClosed(context) {
|
18984 | return new LinearClosed(context);
|
18985 | }
|
18986 |
|
18987 | function sign(x) {
|
18988 | return x < 0 ? -1 : 1;
|
18989 | }
|
18990 |
|
18991 | // Calculate the slopes of the tangents (Hermite-type interpolation) based on
|
18992 | // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
|
18993 | // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
|
18994 | // NOV(II), P. 443, 1990.
|
18995 | function slope3(that, x2, y2) {
|
18996 | var h0 = that._x1 - that._x0,
|
18997 | h1 = x2 - that._x1,
|
18998 | s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
|
18999 | s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
|
19000 | p = (s0 * h1 + s1 * h0) / (h0 + h1);
|
19001 | return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
|
19002 | }
|
19003 |
|
19004 | // Calculate a one-sided slope.
|
19005 | function slope2(that, t) {
|
19006 | var h = that._x1 - that._x0;
|
19007 | return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
|
19008 | }
|
19009 |
|
19010 | // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
|
19011 | // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
|
19012 | // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
|
19013 | function point(that, t0, t1) {
|
19014 | var x0 = that._x0,
|
19015 | y0 = that._y0,
|
19016 | x1 = that._x1,
|
19017 | y1 = that._y1,
|
19018 | dx = (x1 - x0) / 3;
|
19019 | that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
|
19020 | }
|
19021 |
|
19022 | function MonotoneX(context) {
|
19023 | this._context = context;
|
19024 | }
|
19025 |
|
19026 | MonotoneX.prototype = {
|
19027 | areaStart: function() {
|
19028 | this._line = 0;
|
19029 | },
|
19030 | areaEnd: function() {
|
19031 | this._line = NaN;
|
19032 | },
|
19033 | lineStart: function() {
|
19034 | this._x0 = this._x1 =
|
19035 | this._y0 = this._y1 =
|
19036 | this._t0 = NaN;
|
19037 | this._point = 0;
|
19038 | },
|
19039 | lineEnd: function() {
|
19040 | switch (this._point) {
|
19041 | case 2: this._context.lineTo(this._x1, this._y1); break;
|
19042 | case 3: point(this, this._t0, slope2(this, this._t0)); break;
|
19043 | }
|
19044 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
19045 | this._line = 1 - this._line;
|
19046 | },
|
19047 | point: function(x, y) {
|
19048 | var t1 = NaN;
|
19049 |
|
19050 | x = +x, y = +y;
|
19051 | if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
|
19052 | switch (this._point) {
|
19053 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
19054 | case 1: this._point = 2; break;
|
19055 | case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
|
19056 | default: point(this, this._t0, t1 = slope3(this, x, y)); break;
|
19057 | }
|
19058 |
|
19059 | this._x0 = this._x1, this._x1 = x;
|
19060 | this._y0 = this._y1, this._y1 = y;
|
19061 | this._t0 = t1;
|
19062 | }
|
19063 | };
|
19064 |
|
19065 | function MonotoneY(context) {
|
19066 | this._context = new ReflectContext(context);
|
19067 | }
|
19068 |
|
19069 | (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
|
19070 | MonotoneX.prototype.point.call(this, y, x);
|
19071 | };
|
19072 |
|
19073 | function ReflectContext(context) {
|
19074 | this._context = context;
|
19075 | }
|
19076 |
|
19077 | ReflectContext.prototype = {
|
19078 | moveTo: function(x, y) { this._context.moveTo(y, x); },
|
19079 | closePath: function() { this._context.closePath(); },
|
19080 | lineTo: function(x, y) { this._context.lineTo(y, x); },
|
19081 | bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
|
19082 | };
|
19083 |
|
19084 | function monotoneX(context) {
|
19085 | return new MonotoneX(context);
|
19086 | }
|
19087 |
|
19088 | function monotoneY(context) {
|
19089 | return new MonotoneY(context);
|
19090 | }
|
19091 |
|
19092 | function Natural(context) {
|
19093 | this._context = context;
|
19094 | }
|
19095 |
|
19096 | Natural.prototype = {
|
19097 | areaStart: function() {
|
19098 | this._line = 0;
|
19099 | },
|
19100 | areaEnd: function() {
|
19101 | this._line = NaN;
|
19102 | },
|
19103 | lineStart: function() {
|
19104 | this._x = [];
|
19105 | this._y = [];
|
19106 | },
|
19107 | lineEnd: function() {
|
19108 | var x = this._x,
|
19109 | y = this._y,
|
19110 | n = x.length;
|
19111 |
|
19112 | if (n) {
|
19113 | this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
|
19114 | if (n === 2) {
|
19115 | this._context.lineTo(x[1], y[1]);
|
19116 | } else {
|
19117 | var px = controlPoints(x),
|
19118 | py = controlPoints(y);
|
19119 | for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
|
19120 | this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
|
19121 | }
|
19122 | }
|
19123 | }
|
19124 |
|
19125 | if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
|
19126 | this._line = 1 - this._line;
|
19127 | this._x = this._y = null;
|
19128 | },
|
19129 | point: function(x, y) {
|
19130 | this._x.push(+x);
|
19131 | this._y.push(+y);
|
19132 | }
|
19133 | };
|
19134 |
|
19135 | // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
|
19136 | function controlPoints(x) {
|
19137 | var i,
|
19138 | n = x.length - 1,
|
19139 | m,
|
19140 | a = new Array(n),
|
19141 | b = new Array(n),
|
19142 | r = new Array(n);
|
19143 | a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
|
19144 | for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
|
19145 | a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
|
19146 | for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
|
19147 | a[n - 1] = r[n - 1] / b[n - 1];
|
19148 | for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
|
19149 | b[n - 1] = (x[n] + a[n - 1]) / 2;
|
19150 | for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
|
19151 | return [a, b];
|
19152 | }
|
19153 |
|
19154 | function natural(context) {
|
19155 | return new Natural(context);
|
19156 | }
|
19157 |
|
19158 | function Step(context, t) {
|
19159 | this._context = context;
|
19160 | this._t = t;
|
19161 | }
|
19162 |
|
19163 | Step.prototype = {
|
19164 | areaStart: function() {
|
19165 | this._line = 0;
|
19166 | },
|
19167 | areaEnd: function() {
|
19168 | this._line = NaN;
|
19169 | },
|
19170 | lineStart: function() {
|
19171 | this._x = this._y = NaN;
|
19172 | this._point = 0;
|
19173 | },
|
19174 | lineEnd: function() {
|
19175 | if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
|
19176 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
19177 | if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
|
19178 | },
|
19179 | point: function(x, y) {
|
19180 | x = +x, y = +y;
|
19181 | switch (this._point) {
|
19182 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
19183 | case 1: this._point = 2; // falls through
|
19184 | default: {
|
19185 | if (this._t <= 0) {
|
19186 | this._context.lineTo(this._x, y);
|
19187 | this._context.lineTo(x, y);
|
19188 | } else {
|
19189 | var x1 = this._x * (1 - this._t) + x * this._t;
|
19190 | this._context.lineTo(x1, this._y);
|
19191 | this._context.lineTo(x1, y);
|
19192 | }
|
19193 | break;
|
19194 | }
|
19195 | }
|
19196 | this._x = x, this._y = y;
|
19197 | }
|
19198 | };
|
19199 |
|
19200 | function step(context) {
|
19201 | return new Step(context, 0.5);
|
19202 | }
|
19203 |
|
19204 | function stepBefore(context) {
|
19205 | return new Step(context, 0);
|
19206 | }
|
19207 |
|
19208 | function stepAfter(context) {
|
19209 | return new Step(context, 1);
|
19210 | }
|
19211 |
|
19212 | function none$1(series, order) {
|
19213 | if (!((n = series.length) > 1)) return;
|
19214 | for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
|
19215 | s0 = s1, s1 = series[order[i]];
|
19216 | for (j = 0; j < m; ++j) {
|
19217 | s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
|
19218 | }
|
19219 | }
|
19220 | }
|
19221 |
|
19222 | function none(series) {
|
19223 | var n = series.length, o = new Array(n);
|
19224 | while (--n >= 0) o[n] = n;
|
19225 | return o;
|
19226 | }
|
19227 |
|
19228 | function stackValue(d, key) {
|
19229 | return d[key];
|
19230 | }
|
19231 |
|
19232 | function stackSeries(key) {
|
19233 | const series = [];
|
19234 | series.key = key;
|
19235 | return series;
|
19236 | }
|
19237 |
|
19238 | function stack() {
|
19239 | var keys = constant$1([]),
|
19240 | order = none,
|
19241 | offset = none$1,
|
19242 | value = stackValue;
|
19243 |
|
19244 | function stack(data) {
|
19245 | var sz = Array.from(keys.apply(this, arguments), stackSeries),
|
19246 | i, n = sz.length, j = -1,
|
19247 | oz;
|
19248 |
|
19249 | for (const d of data) {
|
19250 | for (i = 0, ++j; i < n; ++i) {
|
19251 | (sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
|
19252 | }
|
19253 | }
|
19254 |
|
19255 | for (i = 0, oz = array(order(sz)); i < n; ++i) {
|
19256 | sz[oz[i]].index = i;
|
19257 | }
|
19258 |
|
19259 | offset(sz, oz);
|
19260 | return sz;
|
19261 | }
|
19262 |
|
19263 | stack.keys = function(_) {
|
19264 | return arguments.length ? (keys = typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : keys;
|
19265 | };
|
19266 |
|
19267 | stack.value = function(_) {
|
19268 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), stack) : value;
|
19269 | };
|
19270 |
|
19271 | stack.order = function(_) {
|
19272 | return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : order;
|
19273 | };
|
19274 |
|
19275 | stack.offset = function(_) {
|
19276 | return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
|
19277 | };
|
19278 |
|
19279 | return stack;
|
19280 | }
|
19281 |
|
19282 | function expand(series, order) {
|
19283 | if (!((n = series.length) > 0)) return;
|
19284 | for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
|
19285 | for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
|
19286 | if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
|
19287 | }
|
19288 | none$1(series, order);
|
19289 | }
|
19290 |
|
19291 | function diverging(series, order) {
|
19292 | if (!((n = series.length) > 0)) return;
|
19293 | for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
|
19294 | for (yp = yn = 0, i = 0; i < n; ++i) {
|
19295 | if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
|
19296 | d[0] = yp, d[1] = yp += dy;
|
19297 | } else if (dy < 0) {
|
19298 | d[1] = yn, d[0] = yn += dy;
|
19299 | } else {
|
19300 | d[0] = 0, d[1] = dy;
|
19301 | }
|
19302 | }
|
19303 | }
|
19304 | }
|
19305 |
|
19306 | function silhouette(series, order) {
|
19307 | if (!((n = series.length) > 0)) return;
|
19308 | for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
|
19309 | for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
|
19310 | s0[j][1] += s0[j][0] = -y / 2;
|
19311 | }
|
19312 | none$1(series, order);
|
19313 | }
|
19314 |
|
19315 | function wiggle(series, order) {
|
19316 | if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
|
19317 | for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
|
19318 | for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
|
19319 | var si = series[order[i]],
|
19320 | sij0 = si[j][1] || 0,
|
19321 | sij1 = si[j - 1][1] || 0,
|
19322 | s3 = (sij0 - sij1) / 2;
|
19323 | for (var k = 0; k < i; ++k) {
|
19324 | var sk = series[order[k]],
|
19325 | skj0 = sk[j][1] || 0,
|
19326 | skj1 = sk[j - 1][1] || 0;
|
19327 | s3 += skj0 - skj1;
|
19328 | }
|
19329 | s1 += sij0, s2 += s3 * sij0;
|
19330 | }
|
19331 | s0[j - 1][1] += s0[j - 1][0] = y;
|
19332 | if (s1) y -= s2 / s1;
|
19333 | }
|
19334 | s0[j - 1][1] += s0[j - 1][0] = y;
|
19335 | none$1(series, order);
|
19336 | }
|
19337 |
|
19338 | function appearance(series) {
|
19339 | var peaks = series.map(peak);
|
19340 | return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
|
19341 | }
|
19342 |
|
19343 | function peak(series) {
|
19344 | var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
|
19345 | while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
|
19346 | return j;
|
19347 | }
|
19348 |
|
19349 | function ascending(series) {
|
19350 | var sums = series.map(sum);
|
19351 | return none(series).sort(function(a, b) { return sums[a] - sums[b]; });
|
19352 | }
|
19353 |
|
19354 | function sum(series) {
|
19355 | var s = 0, i = -1, n = series.length, v;
|
19356 | while (++i < n) if (v = +series[i][1]) s += v;
|
19357 | return s;
|
19358 | }
|
19359 |
|
19360 | function descending(series) {
|
19361 | return ascending(series).reverse();
|
19362 | }
|
19363 |
|
19364 | function insideOut(series) {
|
19365 | var n = series.length,
|
19366 | i,
|
19367 | j,
|
19368 | sums = series.map(sum),
|
19369 | order = appearance(series),
|
19370 | top = 0,
|
19371 | bottom = 0,
|
19372 | tops = [],
|
19373 | bottoms = [];
|
19374 |
|
19375 | for (i = 0; i < n; ++i) {
|
19376 | j = order[i];
|
19377 | if (top < bottom) {
|
19378 | top += sums[j];
|
19379 | tops.push(j);
|
19380 | } else {
|
19381 | bottom += sums[j];
|
19382 | bottoms.push(j);
|
19383 | }
|
19384 | }
|
19385 |
|
19386 | return bottoms.reverse().concat(tops);
|
19387 | }
|
19388 |
|
19389 | function reverse(series) {
|
19390 | return none(series).reverse();
|
19391 | }
|
19392 |
|
19393 | var constant = x => () => x;
|
19394 |
|
19395 | function ZoomEvent(type, {
|
19396 | sourceEvent,
|
19397 | target,
|
19398 | transform,
|
19399 | dispatch
|
19400 | }) {
|
19401 | Object.defineProperties(this, {
|
19402 | type: {value: type, enumerable: true, configurable: true},
|
19403 | sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
|
19404 | target: {value: target, enumerable: true, configurable: true},
|
19405 | transform: {value: transform, enumerable: true, configurable: true},
|
19406 | _: {value: dispatch}
|
19407 | });
|
19408 | }
|
19409 |
|
19410 | function Transform(k, x, y) {
|
19411 | this.k = k;
|
19412 | this.x = x;
|
19413 | this.y = y;
|
19414 | }
|
19415 |
|
19416 | Transform.prototype = {
|
19417 | constructor: Transform,
|
19418 | scale: function(k) {
|
19419 | return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
|
19420 | },
|
19421 | translate: function(x, y) {
|
19422 | return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
|
19423 | },
|
19424 | apply: function(point) {
|
19425 | return [point[0] * this.k + this.x, point[1] * this.k + this.y];
|
19426 | },
|
19427 | applyX: function(x) {
|
19428 | return x * this.k + this.x;
|
19429 | },
|
19430 | applyY: function(y) {
|
19431 | return y * this.k + this.y;
|
19432 | },
|
19433 | invert: function(location) {
|
19434 | return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
|
19435 | },
|
19436 | invertX: function(x) {
|
19437 | return (x - this.x) / this.k;
|
19438 | },
|
19439 | invertY: function(y) {
|
19440 | return (y - this.y) / this.k;
|
19441 | },
|
19442 | rescaleX: function(x) {
|
19443 | return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
|
19444 | },
|
19445 | rescaleY: function(y) {
|
19446 | return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
|
19447 | },
|
19448 | toString: function() {
|
19449 | return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
|
19450 | }
|
19451 | };
|
19452 |
|
19453 | var identity = new Transform(1, 0, 0);
|
19454 |
|
19455 | transform.prototype = Transform.prototype;
|
19456 |
|
19457 | function transform(node) {
|
19458 | while (!node.__zoom) if (!(node = node.parentNode)) return identity;
|
19459 | return node.__zoom;
|
19460 | }
|
19461 |
|
19462 | function nopropagation(event) {
|
19463 | event.stopImmediatePropagation();
|
19464 | }
|
19465 |
|
19466 | function noevent(event) {
|
19467 | event.preventDefault();
|
19468 | event.stopImmediatePropagation();
|
19469 | }
|
19470 |
|
19471 | // Ignore right-click, since that should open the context menu.
|
19472 | // except for pinch-to-zoom, which is sent as a wheel+ctrlKey event
|
19473 | function defaultFilter(event) {
|
19474 | return (!event.ctrlKey || event.type === 'wheel') && !event.button;
|
19475 | }
|
19476 |
|
19477 | function defaultExtent() {
|
19478 | var e = this;
|
19479 | if (e instanceof SVGElement) {
|
19480 | e = e.ownerSVGElement || e;
|
19481 | if (e.hasAttribute("viewBox")) {
|
19482 | e = e.viewBox.baseVal;
|
19483 | return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
|
19484 | }
|
19485 | return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
|
19486 | }
|
19487 | return [[0, 0], [e.clientWidth, e.clientHeight]];
|
19488 | }
|
19489 |
|
19490 | function defaultTransform() {
|
19491 | return this.__zoom || identity;
|
19492 | }
|
19493 |
|
19494 | function defaultWheelDelta(event) {
|
19495 | return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1);
|
19496 | }
|
19497 |
|
19498 | function defaultTouchable() {
|
19499 | return navigator.maxTouchPoints || ("ontouchstart" in this);
|
19500 | }
|
19501 |
|
19502 | function defaultConstrain(transform, extent, translateExtent) {
|
19503 | var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
|
19504 | dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
|
19505 | dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
|
19506 | dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
|
19507 | return transform.translate(
|
19508 | dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
|
19509 | dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
|
19510 | );
|
19511 | }
|
19512 |
|
19513 | function zoom() {
|
19514 | var filter = defaultFilter,
|
19515 | extent = defaultExtent,
|
19516 | constrain = defaultConstrain,
|
19517 | wheelDelta = defaultWheelDelta,
|
19518 | touchable = defaultTouchable,
|
19519 | scaleExtent = [0, Infinity],
|
19520 | translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
|
19521 | duration = 250,
|
19522 | interpolate = interpolateZoom,
|
19523 | listeners = dispatch("start", "zoom", "end"),
|
19524 | touchstarting,
|
19525 | touchfirst,
|
19526 | touchending,
|
19527 | touchDelay = 500,
|
19528 | wheelDelay = 150,
|
19529 | clickDistance2 = 0,
|
19530 | tapDistance = 10;
|
19531 |
|
19532 | function zoom(selection) {
|
19533 | selection
|
19534 | .property("__zoom", defaultTransform)
|
19535 | .on("wheel.zoom", wheeled, {passive: false})
|
19536 | .on("mousedown.zoom", mousedowned)
|
19537 | .on("dblclick.zoom", dblclicked)
|
19538 | .filter(touchable)
|
19539 | .on("touchstart.zoom", touchstarted)
|
19540 | .on("touchmove.zoom", touchmoved)
|
19541 | .on("touchend.zoom touchcancel.zoom", touchended)
|
19542 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
19543 | }
|
19544 |
|
19545 | zoom.transform = function(collection, transform, point, event) {
|
19546 | var selection = collection.selection ? collection.selection() : collection;
|
19547 | selection.property("__zoom", defaultTransform);
|
19548 | if (collection !== selection) {
|
19549 | schedule(collection, transform, point, event);
|
19550 | } else {
|
19551 | selection.interrupt().each(function() {
|
19552 | gesture(this, arguments)
|
19553 | .event(event)
|
19554 | .start()
|
19555 | .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
|
19556 | .end();
|
19557 | });
|
19558 | }
|
19559 | };
|
19560 |
|
19561 | zoom.scaleBy = function(selection, k, p, event) {
|
19562 | zoom.scaleTo(selection, function() {
|
19563 | var k0 = this.__zoom.k,
|
19564 | k1 = typeof k === "function" ? k.apply(this, arguments) : k;
|
19565 | return k0 * k1;
|
19566 | }, p, event);
|
19567 | };
|
19568 |
|
19569 | zoom.scaleTo = function(selection, k, p, event) {
|
19570 | zoom.transform(selection, function() {
|
19571 | var e = extent.apply(this, arguments),
|
19572 | t0 = this.__zoom,
|
19573 | p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
|
19574 | p1 = t0.invert(p0),
|
19575 | k1 = typeof k === "function" ? k.apply(this, arguments) : k;
|
19576 | return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
|
19577 | }, p, event);
|
19578 | };
|
19579 |
|
19580 | zoom.translateBy = function(selection, x, y, event) {
|
19581 | zoom.transform(selection, function() {
|
19582 | return constrain(this.__zoom.translate(
|
19583 | typeof x === "function" ? x.apply(this, arguments) : x,
|
19584 | typeof y === "function" ? y.apply(this, arguments) : y
|
19585 | ), extent.apply(this, arguments), translateExtent);
|
19586 | }, null, event);
|
19587 | };
|
19588 |
|
19589 | zoom.translateTo = function(selection, x, y, p, event) {
|
19590 | zoom.transform(selection, function() {
|
19591 | var e = extent.apply(this, arguments),
|
19592 | t = this.__zoom,
|
19593 | p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
|
19594 | return constrain(identity.translate(p0[0], p0[1]).scale(t.k).translate(
|
19595 | typeof x === "function" ? -x.apply(this, arguments) : -x,
|
19596 | typeof y === "function" ? -y.apply(this, arguments) : -y
|
19597 | ), e, translateExtent);
|
19598 | }, p, event);
|
19599 | };
|
19600 |
|
19601 | function scale(transform, k) {
|
19602 | k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
|
19603 | return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
|
19604 | }
|
19605 |
|
19606 | function translate(transform, p0, p1) {
|
19607 | var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
|
19608 | return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
|
19609 | }
|
19610 |
|
19611 | function centroid(extent) {
|
19612 | return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
|
19613 | }
|
19614 |
|
19615 | function schedule(transition, transform, point, event) {
|
19616 | transition
|
19617 | .on("start.zoom", function() { gesture(this, arguments).event(event).start(); })
|
19618 | .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).event(event).end(); })
|
19619 | .tween("zoom", function() {
|
19620 | var that = this,
|
19621 | args = arguments,
|
19622 | g = gesture(that, args).event(event),
|
19623 | e = extent.apply(that, args),
|
19624 | p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
|
19625 | w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
|
19626 | a = that.__zoom,
|
19627 | b = typeof transform === "function" ? transform.apply(that, args) : transform,
|
19628 | i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
|
19629 | return function(t) {
|
19630 | if (t === 1) t = b; // Avoid rounding error on end.
|
19631 | else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
|
19632 | g.zoom(null, t);
|
19633 | };
|
19634 | });
|
19635 | }
|
19636 |
|
19637 | function gesture(that, args, clean) {
|
19638 | return (!clean && that.__zooming) || new Gesture(that, args);
|
19639 | }
|
19640 |
|
19641 | function Gesture(that, args) {
|
19642 | this.that = that;
|
19643 | this.args = args;
|
19644 | this.active = 0;
|
19645 | this.sourceEvent = null;
|
19646 | this.extent = extent.apply(that, args);
|
19647 | this.taps = 0;
|
19648 | }
|
19649 |
|
19650 | Gesture.prototype = {
|
19651 | event: function(event) {
|
19652 | if (event) this.sourceEvent = event;
|
19653 | return this;
|
19654 | },
|
19655 | start: function() {
|
19656 | if (++this.active === 1) {
|
19657 | this.that.__zooming = this;
|
19658 | this.emit("start");
|
19659 | }
|
19660 | return this;
|
19661 | },
|
19662 | zoom: function(key, transform) {
|
19663 | if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
|
19664 | if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
|
19665 | if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
|
19666 | this.that.__zoom = transform;
|
19667 | this.emit("zoom");
|
19668 | return this;
|
19669 | },
|
19670 | end: function() {
|
19671 | if (--this.active === 0) {
|
19672 | delete this.that.__zooming;
|
19673 | this.emit("end");
|
19674 | }
|
19675 | return this;
|
19676 | },
|
19677 | emit: function(type) {
|
19678 | var d = select(this.that).datum();
|
19679 | listeners.call(
|
19680 | type,
|
19681 | this.that,
|
19682 | new ZoomEvent(type, {
|
19683 | sourceEvent: this.sourceEvent,
|
19684 | target: zoom,
|
19685 | type,
|
19686 | transform: this.that.__zoom,
|
19687 | dispatch: listeners
|
19688 | }),
|
19689 | d
|
19690 | );
|
19691 | }
|
19692 | };
|
19693 |
|
19694 | function wheeled(event, ...args) {
|
19695 | if (!filter.apply(this, arguments)) return;
|
19696 | var g = gesture(this, args).event(event),
|
19697 | t = this.__zoom,
|
19698 | k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
|
19699 | p = pointer(event);
|
19700 |
|
19701 | // If the mouse is in the same location as before, reuse it.
|
19702 | // If there were recent wheel events, reset the wheel idle timeout.
|
19703 | if (g.wheel) {
|
19704 | if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
|
19705 | g.mouse[1] = t.invert(g.mouse[0] = p);
|
19706 | }
|
19707 | clearTimeout(g.wheel);
|
19708 | }
|
19709 |
|
19710 | // If this wheel event won’t trigger a transform change, ignore it.
|
19711 | else if (t.k === k) return;
|
19712 |
|
19713 | // Otherwise, capture the mouse point and location at the start.
|
19714 | else {
|
19715 | g.mouse = [p, t.invert(p)];
|
19716 | interrupt(this);
|
19717 | g.start();
|
19718 | }
|
19719 |
|
19720 | noevent(event);
|
19721 | g.wheel = setTimeout(wheelidled, wheelDelay);
|
19722 | g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
|
19723 |
|
19724 | function wheelidled() {
|
19725 | g.wheel = null;
|
19726 | g.end();
|
19727 | }
|
19728 | }
|
19729 |
|
19730 | function mousedowned(event, ...args) {
|
19731 | if (touchending || !filter.apply(this, arguments)) return;
|
19732 | var currentTarget = event.currentTarget,
|
19733 | g = gesture(this, args, true).event(event),
|
19734 | v = select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
|
19735 | p = pointer(event, currentTarget),
|
19736 | x0 = event.clientX,
|
19737 | y0 = event.clientY;
|
19738 |
|
19739 | dragDisable(event.view);
|
19740 | nopropagation(event);
|
19741 | g.mouse = [p, this.__zoom.invert(p)];
|
19742 | interrupt(this);
|
19743 | g.start();
|
19744 |
|
19745 | function mousemoved(event) {
|
19746 | noevent(event);
|
19747 | if (!g.moved) {
|
19748 | var dx = event.clientX - x0, dy = event.clientY - y0;
|
19749 | g.moved = dx * dx + dy * dy > clickDistance2;
|
19750 | }
|
19751 | g.event(event)
|
19752 | .zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = pointer(event, currentTarget), g.mouse[1]), g.extent, translateExtent));
|
19753 | }
|
19754 |
|
19755 | function mouseupped(event) {
|
19756 | v.on("mousemove.zoom mouseup.zoom", null);
|
19757 | yesdrag(event.view, g.moved);
|
19758 | noevent(event);
|
19759 | g.event(event).end();
|
19760 | }
|
19761 | }
|
19762 |
|
19763 | function dblclicked(event, ...args) {
|
19764 | if (!filter.apply(this, arguments)) return;
|
19765 | var t0 = this.__zoom,
|
19766 | p0 = pointer(event.changedTouches ? event.changedTouches[0] : event, this),
|
19767 | p1 = t0.invert(p0),
|
19768 | k1 = t0.k * (event.shiftKey ? 0.5 : 2),
|
19769 | t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, args), translateExtent);
|
19770 |
|
19771 | noevent(event);
|
19772 | if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0, event);
|
19773 | else select(this).call(zoom.transform, t1, p0, event);
|
19774 | }
|
19775 |
|
19776 | function touchstarted(event, ...args) {
|
19777 | if (!filter.apply(this, arguments)) return;
|
19778 | var touches = event.touches,
|
19779 | n = touches.length,
|
19780 | g = gesture(this, args, event.changedTouches.length === n).event(event),
|
19781 | started, i, t, p;
|
19782 |
|
19783 | nopropagation(event);
|
19784 | for (i = 0; i < n; ++i) {
|
19785 | t = touches[i], p = pointer(t, this);
|
19786 | p = [p, this.__zoom.invert(p), t.identifier];
|
19787 | if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
|
19788 | else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
|
19789 | }
|
19790 |
|
19791 | if (touchstarting) touchstarting = clearTimeout(touchstarting);
|
19792 |
|
19793 | if (started) {
|
19794 | if (g.taps < 2) touchfirst = p[0], touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
|
19795 | interrupt(this);
|
19796 | g.start();
|
19797 | }
|
19798 | }
|
19799 |
|
19800 | function touchmoved(event, ...args) {
|
19801 | if (!this.__zooming) return;
|
19802 | var g = gesture(this, args).event(event),
|
19803 | touches = event.changedTouches,
|
19804 | n = touches.length, i, t, p, l;
|
19805 |
|
19806 | noevent(event);
|
19807 | for (i = 0; i < n; ++i) {
|
19808 | t = touches[i], p = pointer(t, this);
|
19809 | if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
|
19810 | else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
|
19811 | }
|
19812 | t = g.that.__zoom;
|
19813 | if (g.touch1) {
|
19814 | var p0 = g.touch0[0], l0 = g.touch0[1],
|
19815 | p1 = g.touch1[0], l1 = g.touch1[1],
|
19816 | dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
|
19817 | dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
|
19818 | t = scale(t, Math.sqrt(dp / dl));
|
19819 | p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
|
19820 | l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
|
19821 | }
|
19822 | else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
|
19823 | else return;
|
19824 |
|
19825 | g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
|
19826 | }
|
19827 |
|
19828 | function touchended(event, ...args) {
|
19829 | if (!this.__zooming) return;
|
19830 | var g = gesture(this, args).event(event),
|
19831 | touches = event.changedTouches,
|
19832 | n = touches.length, i, t;
|
19833 |
|
19834 | nopropagation(event);
|
19835 | if (touchending) clearTimeout(touchending);
|
19836 | touchending = setTimeout(function() { touchending = null; }, touchDelay);
|
19837 | for (i = 0; i < n; ++i) {
|
19838 | t = touches[i];
|
19839 | if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
|
19840 | else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
|
19841 | }
|
19842 | if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
|
19843 | if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
|
19844 | else {
|
19845 | g.end();
|
19846 | // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
|
19847 | if (g.taps === 2) {
|
19848 | t = pointer(t, this);
|
19849 | if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) {
|
19850 | var p = select(this).on("dblclick.zoom");
|
19851 | if (p) p.apply(this, arguments);
|
19852 | }
|
19853 | }
|
19854 | }
|
19855 | }
|
19856 |
|
19857 | zoom.wheelDelta = function(_) {
|
19858 | return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant(+_), zoom) : wheelDelta;
|
19859 | };
|
19860 |
|
19861 | zoom.filter = function(_) {
|
19862 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter;
|
19863 | };
|
19864 |
|
19865 | zoom.touchable = function(_) {
|
19866 | return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), zoom) : touchable;
|
19867 | };
|
19868 |
|
19869 | zoom.extent = function(_) {
|
19870 | return arguments.length ? (extent = typeof _ === "function" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
|
19871 | };
|
19872 |
|
19873 | zoom.scaleExtent = function(_) {
|
19874 | return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
|
19875 | };
|
19876 |
|
19877 | zoom.translateExtent = function(_) {
|
19878 | return arguments.length ? (translateExtent[0][0] = +_[0][0], translateExtent[1][0] = +_[1][0], translateExtent[0][1] = +_[0][1], translateExtent[1][1] = +_[1][1], zoom) : [[translateExtent[0][0], translateExtent[0][1]], [translateExtent[1][0], translateExtent[1][1]]];
|
19879 | };
|
19880 |
|
19881 | zoom.constrain = function(_) {
|
19882 | return arguments.length ? (constrain = _, zoom) : constrain;
|
19883 | };
|
19884 |
|
19885 | zoom.duration = function(_) {
|
19886 | return arguments.length ? (duration = +_, zoom) : duration;
|
19887 | };
|
19888 |
|
19889 | zoom.interpolate = function(_) {
|
19890 | return arguments.length ? (interpolate = _, zoom) : interpolate;
|
19891 | };
|
19892 |
|
19893 | zoom.on = function() {
|
19894 | var value = listeners.on.apply(listeners, arguments);
|
19895 | return value === listeners ? zoom : value;
|
19896 | };
|
19897 |
|
19898 | zoom.clickDistance = function(_) {
|
19899 | return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
|
19900 | };
|
19901 |
|
19902 | zoom.tapDistance = function(_) {
|
19903 | return arguments.length ? (tapDistance = +_, zoom) : tapDistance;
|
19904 | };
|
19905 |
|
19906 | return zoom;
|
19907 | }
|
19908 |
|
19909 | exports.Adder = Adder;
|
19910 | exports.Delaunay = Delaunay;
|
19911 | exports.FormatSpecifier = FormatSpecifier;
|
19912 | exports.InternMap = InternMap;
|
19913 | exports.InternSet = InternSet;
|
19914 | exports.Node = Node$1;
|
19915 | exports.Voronoi = Voronoi;
|
19916 | exports.ZoomTransform = Transform;
|
19917 | exports.active = active;
|
19918 | exports.arc = arc;
|
19919 | exports.area = area;
|
19920 | exports.areaRadial = areaRadial;
|
19921 | exports.ascending = ascending$3;
|
19922 | exports.autoType = autoType;
|
19923 | exports.axisBottom = axisBottom;
|
19924 | exports.axisLeft = axisLeft;
|
19925 | exports.axisRight = axisRight;
|
19926 | exports.axisTop = axisTop;
|
19927 | exports.bin = bin;
|
19928 | exports.bisect = bisect;
|
19929 | exports.bisectCenter = bisectCenter;
|
19930 | exports.bisectLeft = bisectLeft;
|
19931 | exports.bisectRight = bisectRight;
|
19932 | exports.bisector = bisector;
|
19933 | exports.blob = blob;
|
19934 | exports.blur = blur;
|
19935 | exports.blur2 = blur2;
|
19936 | exports.blurImage = blurImage;
|
19937 | exports.brush = brush;
|
19938 | exports.brushSelection = brushSelection;
|
19939 | exports.brushX = brushX;
|
19940 | exports.brushY = brushY;
|
19941 | exports.buffer = buffer;
|
19942 | exports.chord = chord;
|
19943 | exports.chordDirected = chordDirected;
|
19944 | exports.chordTranspose = chordTranspose;
|
19945 | exports.cluster = cluster;
|
19946 | exports.color = color;
|
19947 | exports.contourDensity = density;
|
19948 | exports.contours = Contours;
|
19949 | exports.count = count$1;
|
19950 | exports.create = create$1;
|
19951 | exports.creator = creator;
|
19952 | exports.cross = cross$2;
|
19953 | exports.csv = csv;
|
19954 | exports.csvFormat = csvFormat;
|
19955 | exports.csvFormatBody = csvFormatBody;
|
19956 | exports.csvFormatRow = csvFormatRow;
|
19957 | exports.csvFormatRows = csvFormatRows;
|
19958 | exports.csvFormatValue = csvFormatValue;
|
19959 | exports.csvParse = csvParse;
|
19960 | exports.csvParseRows = csvParseRows;
|
19961 | exports.cubehelix = cubehelix$3;
|
19962 | exports.cumsum = cumsum;
|
19963 | exports.curveBasis = basis;
|
19964 | exports.curveBasisClosed = basisClosed;
|
19965 | exports.curveBasisOpen = basisOpen;
|
19966 | exports.curveBumpX = bumpX;
|
19967 | exports.curveBumpY = bumpY;
|
19968 | exports.curveBundle = bundle;
|
19969 | exports.curveCardinal = cardinal;
|
19970 | exports.curveCardinalClosed = cardinalClosed;
|
19971 | exports.curveCardinalOpen = cardinalOpen;
|
19972 | exports.curveCatmullRom = catmullRom;
|
19973 | exports.curveCatmullRomClosed = catmullRomClosed;
|
19974 | exports.curveCatmullRomOpen = catmullRomOpen;
|
19975 | exports.curveLinear = curveLinear;
|
19976 | exports.curveLinearClosed = linearClosed;
|
19977 | exports.curveMonotoneX = monotoneX;
|
19978 | exports.curveMonotoneY = monotoneY;
|
19979 | exports.curveNatural = natural;
|
19980 | exports.curveStep = step;
|
19981 | exports.curveStepAfter = stepAfter;
|
19982 | exports.curveStepBefore = stepBefore;
|
19983 | exports.descending = descending$2;
|
19984 | exports.deviation = deviation;
|
19985 | exports.difference = difference;
|
19986 | exports.disjoint = disjoint;
|
19987 | exports.dispatch = dispatch;
|
19988 | exports.drag = drag;
|
19989 | exports.dragDisable = dragDisable;
|
19990 | exports.dragEnable = yesdrag;
|
19991 | exports.dsv = dsv;
|
19992 | exports.dsvFormat = dsvFormat;
|
19993 | exports.easeBack = backInOut;
|
19994 | exports.easeBackIn = backIn;
|
19995 | exports.easeBackInOut = backInOut;
|
19996 | exports.easeBackOut = backOut;
|
19997 | exports.easeBounce = bounceOut;
|
19998 | exports.easeBounceIn = bounceIn;
|
19999 | exports.easeBounceInOut = bounceInOut;
|
20000 | exports.easeBounceOut = bounceOut;
|
20001 | exports.easeCircle = circleInOut;
|
20002 | exports.easeCircleIn = circleIn;
|
20003 | exports.easeCircleInOut = circleInOut;
|
20004 | exports.easeCircleOut = circleOut;
|
20005 | exports.easeCubic = cubicInOut;
|
20006 | exports.easeCubicIn = cubicIn;
|
20007 | exports.easeCubicInOut = cubicInOut;
|
20008 | exports.easeCubicOut = cubicOut;
|
20009 | exports.easeElastic = elasticOut;
|
20010 | exports.easeElasticIn = elasticIn;
|
20011 | exports.easeElasticInOut = elasticInOut;
|
20012 | exports.easeElasticOut = elasticOut;
|
20013 | exports.easeExp = expInOut;
|
20014 | exports.easeExpIn = expIn;
|
20015 | exports.easeExpInOut = expInOut;
|
20016 | exports.easeExpOut = expOut;
|
20017 | exports.easeLinear = linear$1;
|
20018 | exports.easePoly = polyInOut;
|
20019 | exports.easePolyIn = polyIn;
|
20020 | exports.easePolyInOut = polyInOut;
|
20021 | exports.easePolyOut = polyOut;
|
20022 | exports.easeQuad = quadInOut;
|
20023 | exports.easeQuadIn = quadIn;
|
20024 | exports.easeQuadInOut = quadInOut;
|
20025 | exports.easeQuadOut = quadOut;
|
20026 | exports.easeSin = sinInOut;
|
20027 | exports.easeSinIn = sinIn;
|
20028 | exports.easeSinInOut = sinInOut;
|
20029 | exports.easeSinOut = sinOut;
|
20030 | exports.every = every;
|
20031 | exports.extent = extent$1;
|
20032 | exports.fcumsum = fcumsum;
|
20033 | exports.filter = filter$1;
|
20034 | exports.flatGroup = flatGroup;
|
20035 | exports.flatRollup = flatRollup;
|
20036 | exports.forceCenter = center;
|
20037 | exports.forceCollide = collide;
|
20038 | exports.forceLink = link$2;
|
20039 | exports.forceManyBody = manyBody;
|
20040 | exports.forceRadial = radial$1;
|
20041 | exports.forceSimulation = simulation;
|
20042 | exports.forceX = x$2;
|
20043 | exports.forceY = y$1;
|
20044 | exports.formatDefaultLocale = defaultLocale$1;
|
20045 | exports.formatLocale = formatLocale$1;
|
20046 | exports.formatSpecifier = formatSpecifier;
|
20047 | exports.fsum = fsum;
|
20048 | exports.geoAlbers = albers;
|
20049 | exports.geoAlbersUsa = albersUsa;
|
20050 | exports.geoArea = area$2;
|
20051 | exports.geoAzimuthalEqualArea = azimuthalEqualArea;
|
20052 | exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
|
20053 | exports.geoAzimuthalEquidistant = azimuthalEquidistant;
|
20054 | exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
|
20055 | exports.geoBounds = bounds;
|
20056 | exports.geoCentroid = centroid$1;
|
20057 | exports.geoCircle = circle$2;
|
20058 | exports.geoClipAntimeridian = clipAntimeridian;
|
20059 | exports.geoClipCircle = clipCircle;
|
20060 | exports.geoClipExtent = extent;
|
20061 | exports.geoClipRectangle = clipRectangle;
|
20062 | exports.geoConicConformal = conicConformal;
|
20063 | exports.geoConicConformalRaw = conicConformalRaw;
|
20064 | exports.geoConicEqualArea = conicEqualArea;
|
20065 | exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
|
20066 | exports.geoConicEquidistant = conicEquidistant;
|
20067 | exports.geoConicEquidistantRaw = conicEquidistantRaw;
|
20068 | exports.geoContains = contains$1;
|
20069 | exports.geoDistance = distance;
|
20070 | exports.geoEqualEarth = equalEarth;
|
20071 | exports.geoEqualEarthRaw = equalEarthRaw;
|
20072 | exports.geoEquirectangular = equirectangular;
|
20073 | exports.geoEquirectangularRaw = equirectangularRaw;
|
20074 | exports.geoGnomonic = gnomonic;
|
20075 | exports.geoGnomonicRaw = gnomonicRaw;
|
20076 | exports.geoGraticule = graticule;
|
20077 | exports.geoGraticule10 = graticule10;
|
20078 | exports.geoIdentity = identity$4;
|
20079 | exports.geoInterpolate = interpolate;
|
20080 | exports.geoLength = length$1;
|
20081 | exports.geoMercator = mercator;
|
20082 | exports.geoMercatorRaw = mercatorRaw;
|
20083 | exports.geoNaturalEarth1 = naturalEarth1;
|
20084 | exports.geoNaturalEarth1Raw = naturalEarth1Raw;
|
20085 | exports.geoOrthographic = orthographic;
|
20086 | exports.geoOrthographicRaw = orthographicRaw;
|
20087 | exports.geoPath = index$2;
|
20088 | exports.geoProjection = projection;
|
20089 | exports.geoProjectionMutator = projectionMutator;
|
20090 | exports.geoRotation = rotation;
|
20091 | exports.geoStereographic = stereographic;
|
20092 | exports.geoStereographicRaw = stereographicRaw;
|
20093 | exports.geoStream = geoStream;
|
20094 | exports.geoTransform = transform$1;
|
20095 | exports.geoTransverseMercator = transverseMercator;
|
20096 | exports.geoTransverseMercatorRaw = transverseMercatorRaw;
|
20097 | exports.gray = gray;
|
20098 | exports.greatest = greatest;
|
20099 | exports.greatestIndex = greatestIndex;
|
20100 | exports.group = group;
|
20101 | exports.groupSort = groupSort;
|
20102 | exports.groups = groups;
|
20103 | exports.hcl = hcl$2;
|
20104 | exports.hierarchy = hierarchy;
|
20105 | exports.histogram = bin;
|
20106 | exports.hsl = hsl$2;
|
20107 | exports.html = html;
|
20108 | exports.image = image;
|
20109 | exports.index = index$4;
|
20110 | exports.indexes = indexes;
|
20111 | exports.interpolate = interpolate$2;
|
20112 | exports.interpolateArray = array$3;
|
20113 | exports.interpolateBasis = basis$2;
|
20114 | exports.interpolateBasisClosed = basisClosed$1;
|
20115 | exports.interpolateBlues = Blues;
|
20116 | exports.interpolateBrBG = BrBG;
|
20117 | exports.interpolateBuGn = BuGn;
|
20118 | exports.interpolateBuPu = BuPu;
|
20119 | exports.interpolateCividis = cividis;
|
20120 | exports.interpolateCool = cool;
|
20121 | exports.interpolateCubehelix = cubehelix$2;
|
20122 | exports.interpolateCubehelixDefault = cubehelix;
|
20123 | exports.interpolateCubehelixLong = cubehelixLong;
|
20124 | exports.interpolateDate = date$1;
|
20125 | exports.interpolateDiscrete = discrete;
|
20126 | exports.interpolateGnBu = GnBu;
|
20127 | exports.interpolateGreens = Greens;
|
20128 | exports.interpolateGreys = Greys;
|
20129 | exports.interpolateHcl = hcl$1;
|
20130 | exports.interpolateHclLong = hclLong;
|
20131 | exports.interpolateHsl = hsl$1;
|
20132 | exports.interpolateHslLong = hslLong;
|
20133 | exports.interpolateHue = hue;
|
20134 | exports.interpolateInferno = inferno;
|
20135 | exports.interpolateLab = lab;
|
20136 | exports.interpolateMagma = magma;
|
20137 | exports.interpolateNumber = interpolateNumber;
|
20138 | exports.interpolateNumberArray = numberArray;
|
20139 | exports.interpolateObject = object$1;
|
20140 | exports.interpolateOrRd = OrRd;
|
20141 | exports.interpolateOranges = Oranges;
|
20142 | exports.interpolatePRGn = PRGn;
|
20143 | exports.interpolatePiYG = PiYG;
|
20144 | exports.interpolatePlasma = plasma;
|
20145 | exports.interpolatePuBu = PuBu;
|
20146 | exports.interpolatePuBuGn = PuBuGn;
|
20147 | exports.interpolatePuOr = PuOr;
|
20148 | exports.interpolatePuRd = PuRd;
|
20149 | exports.interpolatePurples = Purples;
|
20150 | exports.interpolateRainbow = rainbow;
|
20151 | exports.interpolateRdBu = RdBu;
|
20152 | exports.interpolateRdGy = RdGy;
|
20153 | exports.interpolateRdPu = RdPu;
|
20154 | exports.interpolateRdYlBu = RdYlBu;
|
20155 | exports.interpolateRdYlGn = RdYlGn;
|
20156 | exports.interpolateReds = Reds;
|
20157 | exports.interpolateRgb = interpolateRgb;
|
20158 | exports.interpolateRgbBasis = rgbBasis;
|
20159 | exports.interpolateRgbBasisClosed = rgbBasisClosed;
|
20160 | exports.interpolateRound = interpolateRound;
|
20161 | exports.interpolateSinebow = sinebow;
|
20162 | exports.interpolateSpectral = Spectral;
|
20163 | exports.interpolateString = interpolateString;
|
20164 | exports.interpolateTransformCss = interpolateTransformCss;
|
20165 | exports.interpolateTransformSvg = interpolateTransformSvg;
|
20166 | exports.interpolateTurbo = turbo;
|
20167 | exports.interpolateViridis = viridis;
|
20168 | exports.interpolateWarm = warm;
|
20169 | exports.interpolateYlGn = YlGn;
|
20170 | exports.interpolateYlGnBu = YlGnBu;
|
20171 | exports.interpolateYlOrBr = YlOrBr;
|
20172 | exports.interpolateYlOrRd = YlOrRd;
|
20173 | exports.interpolateZoom = interpolateZoom;
|
20174 | exports.interrupt = interrupt;
|
20175 | exports.intersection = intersection;
|
20176 | exports.interval = interval;
|
20177 | exports.isoFormat = formatIso$1;
|
20178 | exports.isoParse = parseIso$1;
|
20179 | exports.json = json;
|
20180 | exports.lab = lab$1;
|
20181 | exports.lch = lch;
|
20182 | exports.least = least;
|
20183 | exports.leastIndex = leastIndex;
|
20184 | exports.line = line;
|
20185 | exports.lineRadial = lineRadial$1;
|
20186 | exports.link = link;
|
20187 | exports.linkHorizontal = linkHorizontal;
|
20188 | exports.linkRadial = linkRadial;
|
20189 | exports.linkVertical = linkVertical;
|
20190 | exports.local = local$1;
|
20191 | exports.map = map$1;
|
20192 | exports.matcher = matcher;
|
20193 | exports.max = max$3;
|
20194 | exports.maxIndex = maxIndex;
|
20195 | exports.mean = mean;
|
20196 | exports.median = median;
|
20197 | exports.medianIndex = medianIndex;
|
20198 | exports.merge = merge;
|
20199 | exports.min = min$2;
|
20200 | exports.minIndex = minIndex;
|
20201 | exports.mode = mode;
|
20202 | exports.namespace = namespace;
|
20203 | exports.namespaces = namespaces;
|
20204 | exports.nice = nice$1;
|
20205 | exports.now = now;
|
20206 | exports.pack = index$1;
|
20207 | exports.packEnclose = enclose;
|
20208 | exports.packSiblings = siblings;
|
20209 | exports.pairs = pairs;
|
20210 | exports.partition = partition;
|
20211 | exports.path = path;
|
20212 | exports.permute = permute;
|
20213 | exports.pie = pie;
|
20214 | exports.piecewise = piecewise;
|
20215 | exports.pointRadial = pointRadial;
|
20216 | exports.pointer = pointer;
|
20217 | exports.pointers = pointers;
|
20218 | exports.polygonArea = area$1;
|
20219 | exports.polygonCentroid = centroid;
|
20220 | exports.polygonContains = contains;
|
20221 | exports.polygonHull = hull;
|
20222 | exports.polygonLength = length;
|
20223 | exports.precisionFixed = precisionFixed;
|
20224 | exports.precisionPrefix = precisionPrefix;
|
20225 | exports.precisionRound = precisionRound;
|
20226 | exports.quadtree = quadtree;
|
20227 | exports.quantile = quantile$1;
|
20228 | exports.quantileIndex = quantileIndex;
|
20229 | exports.quantileSorted = quantileSorted;
|
20230 | exports.quantize = quantize$1;
|
20231 | exports.quickselect = quickselect;
|
20232 | exports.radialArea = areaRadial;
|
20233 | exports.radialLine = lineRadial$1;
|
20234 | exports.randomBates = bates;
|
20235 | exports.randomBernoulli = bernoulli;
|
20236 | exports.randomBeta = beta;
|
20237 | exports.randomBinomial = binomial;
|
20238 | exports.randomCauchy = cauchy;
|
20239 | exports.randomExponential = exponential;
|
20240 | exports.randomGamma = gamma;
|
20241 | exports.randomGeometric = geometric;
|
20242 | exports.randomInt = int;
|
20243 | exports.randomIrwinHall = irwinHall;
|
20244 | exports.randomLcg = lcg;
|
20245 | exports.randomLogNormal = logNormal;
|
20246 | exports.randomLogistic = logistic;
|
20247 | exports.randomNormal = normal;
|
20248 | exports.randomPareto = pareto;
|
20249 | exports.randomPoisson = poisson;
|
20250 | exports.randomUniform = uniform;
|
20251 | exports.randomWeibull = weibull;
|
20252 | exports.range = range$2;
|
20253 | exports.rank = rank;
|
20254 | exports.reduce = reduce;
|
20255 | exports.reverse = reverse$1;
|
20256 | exports.rgb = rgb;
|
20257 | exports.ribbon = ribbon$1;
|
20258 | exports.ribbonArrow = ribbonArrow;
|
20259 | exports.rollup = rollup;
|
20260 | exports.rollups = rollups;
|
20261 | exports.scaleBand = band;
|
20262 | exports.scaleDiverging = diverging$1;
|
20263 | exports.scaleDivergingLog = divergingLog;
|
20264 | exports.scaleDivergingPow = divergingPow;
|
20265 | exports.scaleDivergingSqrt = divergingSqrt;
|
20266 | exports.scaleDivergingSymlog = divergingSymlog;
|
20267 | exports.scaleIdentity = identity$2;
|
20268 | exports.scaleImplicit = implicit;
|
20269 | exports.scaleLinear = linear;
|
20270 | exports.scaleLog = log;
|
20271 | exports.scaleOrdinal = ordinal;
|
20272 | exports.scalePoint = point$4;
|
20273 | exports.scalePow = pow;
|
20274 | exports.scaleQuantile = quantile;
|
20275 | exports.scaleQuantize = quantize;
|
20276 | exports.scaleRadial = radial;
|
20277 | exports.scaleSequential = sequential;
|
20278 | exports.scaleSequentialLog = sequentialLog;
|
20279 | exports.scaleSequentialPow = sequentialPow;
|
20280 | exports.scaleSequentialQuantile = sequentialQuantile;
|
20281 | exports.scaleSequentialSqrt = sequentialSqrt;
|
20282 | exports.scaleSequentialSymlog = sequentialSymlog;
|
20283 | exports.scaleSqrt = sqrt$1;
|
20284 | exports.scaleSymlog = symlog;
|
20285 | exports.scaleThreshold = threshold;
|
20286 | exports.scaleTime = time;
|
20287 | exports.scaleUtc = utcTime;
|
20288 | exports.scan = scan;
|
20289 | exports.schemeAccent = Accent;
|
20290 | exports.schemeBlues = scheme$5;
|
20291 | exports.schemeBrBG = scheme$q;
|
20292 | exports.schemeBuGn = scheme$h;
|
20293 | exports.schemeBuPu = scheme$g;
|
20294 | exports.schemeCategory10 = category10;
|
20295 | exports.schemeDark2 = Dark2;
|
20296 | exports.schemeGnBu = scheme$f;
|
20297 | exports.schemeGreens = scheme$4;
|
20298 | exports.schemeGreys = scheme$3;
|
20299 | exports.schemeOrRd = scheme$e;
|
20300 | exports.schemeOranges = scheme;
|
20301 | exports.schemePRGn = scheme$p;
|
20302 | exports.schemePaired = Paired;
|
20303 | exports.schemePastel1 = Pastel1;
|
20304 | exports.schemePastel2 = Pastel2;
|
20305 | exports.schemePiYG = scheme$o;
|
20306 | exports.schemePuBu = scheme$c;
|
20307 | exports.schemePuBuGn = scheme$d;
|
20308 | exports.schemePuOr = scheme$n;
|
20309 | exports.schemePuRd = scheme$b;
|
20310 | exports.schemePurples = scheme$2;
|
20311 | exports.schemeRdBu = scheme$m;
|
20312 | exports.schemeRdGy = scheme$l;
|
20313 | exports.schemeRdPu = scheme$a;
|
20314 | exports.schemeRdYlBu = scheme$k;
|
20315 | exports.schemeRdYlGn = scheme$j;
|
20316 | exports.schemeReds = scheme$1;
|
20317 | exports.schemeSet1 = Set1;
|
20318 | exports.schemeSet2 = Set2;
|
20319 | exports.schemeSet3 = Set3;
|
20320 | exports.schemeSpectral = scheme$i;
|
20321 | exports.schemeTableau10 = Tableau10;
|
20322 | exports.schemeYlGn = scheme$8;
|
20323 | exports.schemeYlGnBu = scheme$9;
|
20324 | exports.schemeYlOrBr = scheme$7;
|
20325 | exports.schemeYlOrRd = scheme$6;
|
20326 | exports.select = select;
|
20327 | exports.selectAll = selectAll;
|
20328 | exports.selection = selection;
|
20329 | exports.selector = selector;
|
20330 | exports.selectorAll = selectorAll;
|
20331 | exports.shuffle = shuffle$1;
|
20332 | exports.shuffler = shuffler;
|
20333 | exports.some = some;
|
20334 | exports.sort = sort;
|
20335 | exports.stack = stack;
|
20336 | exports.stackOffsetDiverging = diverging;
|
20337 | exports.stackOffsetExpand = expand;
|
20338 | exports.stackOffsetNone = none$1;
|
20339 | exports.stackOffsetSilhouette = silhouette;
|
20340 | exports.stackOffsetWiggle = wiggle;
|
20341 | exports.stackOrderAppearance = appearance;
|
20342 | exports.stackOrderAscending = ascending;
|
20343 | exports.stackOrderDescending = descending;
|
20344 | exports.stackOrderInsideOut = insideOut;
|
20345 | exports.stackOrderNone = none;
|
20346 | exports.stackOrderReverse = reverse;
|
20347 | exports.stratify = stratify;
|
20348 | exports.style = styleValue;
|
20349 | exports.subset = subset;
|
20350 | exports.sum = sum$2;
|
20351 | exports.superset = superset;
|
20352 | exports.svg = svg;
|
20353 | exports.symbol = Symbol$1;
|
20354 | exports.symbolAsterisk = asterisk;
|
20355 | exports.symbolCircle = circle;
|
20356 | exports.symbolCross = cross;
|
20357 | exports.symbolDiamond = diamond;
|
20358 | exports.symbolDiamond2 = diamond2;
|
20359 | exports.symbolPlus = plus;
|
20360 | exports.symbolSquare = square;
|
20361 | exports.symbolSquare2 = square2;
|
20362 | exports.symbolStar = star;
|
20363 | exports.symbolTriangle = triangle;
|
20364 | exports.symbolTriangle2 = triangle2;
|
20365 | exports.symbolWye = wye;
|
20366 | exports.symbolX = x;
|
20367 | exports.symbols = symbolsFill;
|
20368 | exports.symbolsFill = symbolsFill;
|
20369 | exports.symbolsStroke = symbolsStroke;
|
20370 | exports.text = text;
|
20371 | exports.thresholdFreedmanDiaconis = thresholdFreedmanDiaconis;
|
20372 | exports.thresholdScott = thresholdScott;
|
20373 | exports.thresholdSturges = thresholdSturges;
|
20374 | exports.tickFormat = tickFormat;
|
20375 | exports.tickIncrement = tickIncrement;
|
20376 | exports.tickStep = tickStep;
|
20377 | exports.ticks = ticks;
|
20378 | exports.timeDay = timeDay;
|
20379 | exports.timeDays = days;
|
20380 | exports.timeFormatDefaultLocale = defaultLocale;
|
20381 | exports.timeFormatLocale = formatLocale;
|
20382 | exports.timeFriday = friday;
|
20383 | exports.timeFridays = fridays;
|
20384 | exports.timeHour = timeHour;
|
20385 | exports.timeHours = hours;
|
20386 | exports.timeInterval = newInterval;
|
20387 | exports.timeMillisecond = millisecond$1;
|
20388 | exports.timeMilliseconds = milliseconds;
|
20389 | exports.timeMinute = timeMinute;
|
20390 | exports.timeMinutes = minutes;
|
20391 | exports.timeMonday = monday;
|
20392 | exports.timeMondays = mondays;
|
20393 | exports.timeMonth = timeMonth;
|
20394 | exports.timeMonths = months;
|
20395 | exports.timeSaturday = saturday;
|
20396 | exports.timeSaturdays = saturdays;
|
20397 | exports.timeSecond = utcSecond;
|
20398 | exports.timeSeconds = seconds;
|
20399 | exports.timeSunday = sunday;
|
20400 | exports.timeSundays = sundays;
|
20401 | exports.timeThursday = thursday;
|
20402 | exports.timeThursdays = thursdays;
|
20403 | exports.timeTickInterval = timeTickInterval;
|
20404 | exports.timeTicks = timeTicks;
|
20405 | exports.timeTuesday = tuesday;
|
20406 | exports.timeTuesdays = tuesdays;
|
20407 | exports.timeWednesday = wednesday;
|
20408 | exports.timeWednesdays = wednesdays;
|
20409 | exports.timeWeek = sunday;
|
20410 | exports.timeWeeks = sundays;
|
20411 | exports.timeYear = timeYear;
|
20412 | exports.timeYears = years;
|
20413 | exports.timeout = timeout;
|
20414 | exports.timer = timer;
|
20415 | exports.timerFlush = timerFlush;
|
20416 | exports.transition = transition;
|
20417 | exports.transpose = transpose;
|
20418 | exports.tree = tree;
|
20419 | exports.treemap = index;
|
20420 | exports.treemapBinary = binary;
|
20421 | exports.treemapDice = treemapDice;
|
20422 | exports.treemapResquarify = resquarify;
|
20423 | exports.treemapSlice = treemapSlice;
|
20424 | exports.treemapSliceDice = sliceDice;
|
20425 | exports.treemapSquarify = squarify;
|
20426 | exports.tsv = tsv;
|
20427 | exports.tsvFormat = tsvFormat;
|
20428 | exports.tsvFormatBody = tsvFormatBody;
|
20429 | exports.tsvFormatRow = tsvFormatRow;
|
20430 | exports.tsvFormatRows = tsvFormatRows;
|
20431 | exports.tsvFormatValue = tsvFormatValue;
|
20432 | exports.tsvParse = tsvParse;
|
20433 | exports.tsvParseRows = tsvParseRows;
|
20434 | exports.union = union;
|
20435 | exports.utcDay = utcDay$1;
|
20436 | exports.utcDays = utcDays;
|
20437 | exports.utcFriday = utcFriday;
|
20438 | exports.utcFridays = utcFridays;
|
20439 | exports.utcHour = utcHour$1;
|
20440 | exports.utcHours = utcHours;
|
20441 | exports.utcMillisecond = millisecond$1;
|
20442 | exports.utcMilliseconds = milliseconds;
|
20443 | exports.utcMinute = utcMinute$1;
|
20444 | exports.utcMinutes = utcMinutes;
|
20445 | exports.utcMonday = utcMonday;
|
20446 | exports.utcMondays = utcMondays;
|
20447 | exports.utcMonth = utcMonth$1;
|
20448 | exports.utcMonths = utcMonths;
|
20449 | exports.utcSaturday = utcSaturday;
|
20450 | exports.utcSaturdays = utcSaturdays;
|
20451 | exports.utcSecond = utcSecond;
|
20452 | exports.utcSeconds = seconds;
|
20453 | exports.utcSunday = utcSunday;
|
20454 | exports.utcSundays = utcSundays;
|
20455 | exports.utcThursday = utcThursday;
|
20456 | exports.utcThursdays = utcThursdays;
|
20457 | exports.utcTickInterval = utcTickInterval;
|
20458 | exports.utcTicks = utcTicks;
|
20459 | exports.utcTuesday = utcTuesday;
|
20460 | exports.utcTuesdays = utcTuesdays;
|
20461 | exports.utcWednesday = utcWednesday;
|
20462 | exports.utcWednesdays = utcWednesdays;
|
20463 | exports.utcWeek = utcSunday;
|
20464 | exports.utcWeeks = utcSundays;
|
20465 | exports.utcYear = utcYear$1;
|
20466 | exports.utcYears = utcYears;
|
20467 | exports.variance = variance;
|
20468 | exports.version = version;
|
20469 | exports.window = defaultView;
|
20470 | exports.xml = xml;
|
20471 | exports.zip = zip;
|
20472 | exports.zoom = zoom;
|
20473 | exports.zoomIdentity = identity;
|
20474 | exports.zoomTransform = transform;
|
20475 |
|
20476 | Object.defineProperty(exports, '__esModule', { value: true });
|
20477 |
|
20478 | }));
|
20479 |
|
\ | No newline at end of file |