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.8.3";
|
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 | const e10 = Math.sqrt(50),
|
596 | e5 = Math.sqrt(10),
|
597 | e2 = Math.sqrt(2);
|
598 |
|
599 | function tickSpec(start, stop, count) {
|
600 | const step = (stop - start) / Math.max(0, count),
|
601 | power = Math.floor(Math.log10(step)),
|
602 | error = step / Math.pow(10, power),
|
603 | factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
|
604 | let i1, i2, inc;
|
605 | if (power < 0) {
|
606 | inc = Math.pow(10, -power) / factor;
|
607 | i1 = Math.round(start * inc);
|
608 | i2 = Math.round(stop * inc);
|
609 | if (i1 / inc < start) ++i1;
|
610 | if (i2 / inc > stop) --i2;
|
611 | inc = -inc;
|
612 | } else {
|
613 | inc = Math.pow(10, power) * factor;
|
614 | i1 = Math.round(start / inc);
|
615 | i2 = Math.round(stop / inc);
|
616 | if (i1 * inc < start) ++i1;
|
617 | if (i2 * inc > stop) --i2;
|
618 | }
|
619 | if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2);
|
620 | return [i1, i2, inc];
|
621 | }
|
622 |
|
623 | function ticks(start, stop, count) {
|
624 | stop = +stop, start = +start, count = +count;
|
625 | if (!(count > 0)) return [];
|
626 | if (start === stop) return [start];
|
627 | const reverse = stop < start, [i1, i2, inc] = reverse ? tickSpec(stop, start, count) : tickSpec(start, stop, count);
|
628 | if (!(i2 >= i1)) return [];
|
629 | const n = i2 - i1 + 1, ticks = new Array(n);
|
630 | if (reverse) {
|
631 | if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) / -inc;
|
632 | else for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) * inc;
|
633 | } else {
|
634 | if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) / -inc;
|
635 | else for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) * inc;
|
636 | }
|
637 | return ticks;
|
638 | }
|
639 |
|
640 | function tickIncrement(start, stop, count) {
|
641 | stop = +stop, start = +start, count = +count;
|
642 | return tickSpec(start, stop, count)[2];
|
643 | }
|
644 |
|
645 | function tickStep(start, stop, count) {
|
646 | stop = +stop, start = +start, count = +count;
|
647 | const reverse = stop < start, inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count);
|
648 | return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc);
|
649 | }
|
650 |
|
651 | function nice$1(start, stop, count) {
|
652 | let prestep;
|
653 | while (true) {
|
654 | const step = tickIncrement(start, stop, count);
|
655 | if (step === prestep || step === 0 || !isFinite(step)) {
|
656 | return [start, stop];
|
657 | } else if (step > 0) {
|
658 | start = Math.floor(start / step) * step;
|
659 | stop = Math.ceil(stop / step) * step;
|
660 | } else if (step < 0) {
|
661 | start = Math.ceil(start * step) / step;
|
662 | stop = Math.floor(stop * step) / step;
|
663 | }
|
664 | prestep = step;
|
665 | }
|
666 | }
|
667 |
|
668 | function thresholdSturges(values) {
|
669 | return Math.max(1, Math.ceil(Math.log(count$1(values)) / Math.LN2) + 1);
|
670 | }
|
671 |
|
672 | function bin() {
|
673 | var value = identity$9,
|
674 | domain = extent$1,
|
675 | threshold = thresholdSturges;
|
676 |
|
677 | function histogram(data) {
|
678 | if (!Array.isArray(data)) data = Array.from(data);
|
679 |
|
680 | var i,
|
681 | n = data.length,
|
682 | x,
|
683 | step,
|
684 | values = new Array(n);
|
685 |
|
686 | for (i = 0; i < n; ++i) {
|
687 | values[i] = value(data[i], i, data);
|
688 | }
|
689 |
|
690 | var xz = domain(values),
|
691 | x0 = xz[0],
|
692 | x1 = xz[1],
|
693 | tz = threshold(values, x0, x1);
|
694 |
|
695 |
|
696 |
|
697 | if (!Array.isArray(tz)) {
|
698 | const max = x1, tn = +tz;
|
699 | if (domain === extent$1) [x0, x1] = nice$1(x0, x1, tn);
|
700 | tz = ticks(x0, x1, tn);
|
701 |
|
702 |
|
703 |
|
704 |
|
705 | if (tz[0] <= x0) step = tickIncrement(x0, x1, tn);
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 | if (tz[tz.length - 1] >= x1) {
|
715 | if (max >= x1 && domain === extent$1) {
|
716 | const step = tickIncrement(x0, x1, tn);
|
717 | if (isFinite(step)) {
|
718 | if (step > 0) {
|
719 | x1 = (Math.floor(x1 / step) + 1) * step;
|
720 | } else if (step < 0) {
|
721 | x1 = (Math.ceil(x1 * -step) + 1) / -step;
|
722 | }
|
723 | }
|
724 | } else {
|
725 | tz.pop();
|
726 | }
|
727 | }
|
728 | }
|
729 |
|
730 |
|
731 |
|
732 | var m = tz.length, a = 0, b = m;
|
733 | while (tz[a] <= x0) ++a;
|
734 | while (tz[b - 1] > x1) --b;
|
735 | if (a || b < m) tz = tz.slice(a, b), m = b - a;
|
736 |
|
737 | var bins = new Array(m + 1),
|
738 | bin;
|
739 |
|
740 |
|
741 | for (i = 0; i <= m; ++i) {
|
742 | bin = bins[i] = [];
|
743 | bin.x0 = i > 0 ? tz[i - 1] : x0;
|
744 | bin.x1 = i < m ? tz[i] : x1;
|
745 | }
|
746 |
|
747 |
|
748 | if (isFinite(step)) {
|
749 | if (step > 0) {
|
750 | for (i = 0; i < n; ++i) {
|
751 | if ((x = values[i]) != null && x0 <= x && x <= x1) {
|
752 | bins[Math.min(m, Math.floor((x - x0) / step))].push(data[i]);
|
753 | }
|
754 | }
|
755 | } else if (step < 0) {
|
756 | for (i = 0; i < n; ++i) {
|
757 | if ((x = values[i]) != null && x0 <= x && x <= x1) {
|
758 | const j = Math.floor((x0 - x) * step);
|
759 | bins[Math.min(m, j + (tz[j] <= x))].push(data[i]);
|
760 | }
|
761 | }
|
762 | }
|
763 | } else {
|
764 | for (i = 0; i < n; ++i) {
|
765 | if ((x = values[i]) != null && x0 <= x && x <= x1) {
|
766 | bins[bisect(tz, x, 0, m)].push(data[i]);
|
767 | }
|
768 | }
|
769 | }
|
770 |
|
771 | return bins;
|
772 | }
|
773 |
|
774 | histogram.value = function(_) {
|
775 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(_), histogram) : value;
|
776 | };
|
777 |
|
778 | histogram.domain = function(_) {
|
779 | return arguments.length ? (domain = typeof _ === "function" ? _ : constant$b([_[0], _[1]]), histogram) : domain;
|
780 | };
|
781 |
|
782 | histogram.thresholds = function(_) {
|
783 | return arguments.length ? (threshold = typeof _ === "function" ? _ : constant$b(Array.isArray(_) ? slice$3.call(_) : _), histogram) : threshold;
|
784 | };
|
785 |
|
786 | return histogram;
|
787 | }
|
788 |
|
789 | function max$3(values, valueof) {
|
790 | let max;
|
791 | if (valueof === undefined) {
|
792 | for (const value of values) {
|
793 | if (value != null
|
794 | && (max < value || (max === undefined && value >= value))) {
|
795 | max = value;
|
796 | }
|
797 | }
|
798 | } else {
|
799 | let index = -1;
|
800 | for (let value of values) {
|
801 | if ((value = valueof(value, ++index, values)) != null
|
802 | && (max < value || (max === undefined && value >= value))) {
|
803 | max = value;
|
804 | }
|
805 | }
|
806 | }
|
807 | return max;
|
808 | }
|
809 |
|
810 | function maxIndex(values, valueof) {
|
811 | let max;
|
812 | let maxIndex = -1;
|
813 | let index = -1;
|
814 | if (valueof === undefined) {
|
815 | for (const value of values) {
|
816 | ++index;
|
817 | if (value != null
|
818 | && (max < value || (max === undefined && value >= value))) {
|
819 | max = value, maxIndex = index;
|
820 | }
|
821 | }
|
822 | } else {
|
823 | for (let value of values) {
|
824 | if ((value = valueof(value, ++index, values)) != null
|
825 | && (max < value || (max === undefined && value >= value))) {
|
826 | max = value, maxIndex = index;
|
827 | }
|
828 | }
|
829 | }
|
830 | return maxIndex;
|
831 | }
|
832 |
|
833 | function min$2(values, valueof) {
|
834 | let min;
|
835 | if (valueof === undefined) {
|
836 | for (const value of values) {
|
837 | if (value != null
|
838 | && (min > value || (min === undefined && value >= value))) {
|
839 | min = value;
|
840 | }
|
841 | }
|
842 | } else {
|
843 | let index = -1;
|
844 | for (let value of values) {
|
845 | if ((value = valueof(value, ++index, values)) != null
|
846 | && (min > value || (min === undefined && value >= value))) {
|
847 | min = value;
|
848 | }
|
849 | }
|
850 | }
|
851 | return min;
|
852 | }
|
853 |
|
854 | function minIndex(values, valueof) {
|
855 | let min;
|
856 | let minIndex = -1;
|
857 | let index = -1;
|
858 | if (valueof === undefined) {
|
859 | for (const value of values) {
|
860 | ++index;
|
861 | if (value != null
|
862 | && (min > value || (min === undefined && value >= value))) {
|
863 | min = value, minIndex = index;
|
864 | }
|
865 | }
|
866 | } else {
|
867 | for (let value of values) {
|
868 | if ((value = valueof(value, ++index, values)) != null
|
869 | && (min > value || (min === undefined && value >= value))) {
|
870 | min = value, minIndex = index;
|
871 | }
|
872 | }
|
873 | }
|
874 | return minIndex;
|
875 | }
|
876 |
|
877 |
|
878 |
|
879 | function quickselect(array, k, left = 0, right = Infinity, compare) {
|
880 | k = Math.floor(k);
|
881 | left = Math.floor(Math.max(0, left));
|
882 | right = Math.floor(Math.min(array.length - 1, right));
|
883 |
|
884 | if (!(left <= k && k <= right)) return array;
|
885 |
|
886 | compare = compare === undefined ? ascendingDefined : compareDefined(compare);
|
887 |
|
888 | while (right > left) {
|
889 | if (right - left > 600) {
|
890 | const n = right - left + 1;
|
891 | const m = k - left + 1;
|
892 | const z = Math.log(n);
|
893 | const s = 0.5 * Math.exp(2 * z / 3);
|
894 | const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
|
895 | const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
|
896 | const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
|
897 | quickselect(array, k, newLeft, newRight, compare);
|
898 | }
|
899 |
|
900 | const t = array[k];
|
901 | let i = left;
|
902 | let j = right;
|
903 |
|
904 | swap$1(array, left, k);
|
905 | if (compare(array[right], t) > 0) swap$1(array, left, right);
|
906 |
|
907 | while (i < j) {
|
908 | swap$1(array, i, j), ++i, --j;
|
909 | while (compare(array[i], t) < 0) ++i;
|
910 | while (compare(array[j], t) > 0) --j;
|
911 | }
|
912 |
|
913 | if (compare(array[left], t) === 0) swap$1(array, left, j);
|
914 | else ++j, swap$1(array, j, right);
|
915 |
|
916 | if (j <= k) left = j + 1;
|
917 | if (k <= j) right = j - 1;
|
918 | }
|
919 |
|
920 | return array;
|
921 | }
|
922 |
|
923 | function swap$1(array, i, j) {
|
924 | const t = array[i];
|
925 | array[i] = array[j];
|
926 | array[j] = t;
|
927 | }
|
928 |
|
929 | function greatest(values, compare = ascending$3) {
|
930 | let max;
|
931 | let defined = false;
|
932 | if (compare.length === 1) {
|
933 | let maxValue;
|
934 | for (const element of values) {
|
935 | const value = compare(element);
|
936 | if (defined
|
937 | ? ascending$3(value, maxValue) > 0
|
938 | : ascending$3(value, value) === 0) {
|
939 | max = element;
|
940 | maxValue = value;
|
941 | defined = true;
|
942 | }
|
943 | }
|
944 | } else {
|
945 | for (const value of values) {
|
946 | if (defined
|
947 | ? compare(value, max) > 0
|
948 | : compare(value, value) === 0) {
|
949 | max = value;
|
950 | defined = true;
|
951 | }
|
952 | }
|
953 | }
|
954 | return max;
|
955 | }
|
956 |
|
957 | function quantile$1(values, p, valueof) {
|
958 | values = Float64Array.from(numbers(values, valueof));
|
959 | if (!(n = values.length) || isNaN(p = +p)) return;
|
960 | if (p <= 0 || n < 2) return min$2(values);
|
961 | if (p >= 1) return max$3(values);
|
962 | var n,
|
963 | i = (n - 1) * p,
|
964 | i0 = Math.floor(i),
|
965 | value0 = max$3(quickselect(values, i0).subarray(0, i0 + 1)),
|
966 | value1 = min$2(values.subarray(i0 + 1));
|
967 | return value0 + (value1 - value0) * (i - i0);
|
968 | }
|
969 |
|
970 | function quantileSorted(values, p, valueof = number$3) {
|
971 | if (!(n = values.length) || isNaN(p = +p)) return;
|
972 | if (p <= 0 || n < 2) return +valueof(values[0], 0, values);
|
973 | if (p >= 1) return +valueof(values[n - 1], n - 1, values);
|
974 | var n,
|
975 | i = (n - 1) * p,
|
976 | i0 = Math.floor(i),
|
977 | value0 = +valueof(values[i0], i0, values),
|
978 | value1 = +valueof(values[i0 + 1], i0 + 1, values);
|
979 | return value0 + (value1 - value0) * (i - i0);
|
980 | }
|
981 |
|
982 | function quantileIndex(values, p, valueof) {
|
983 | values = Float64Array.from(numbers(values, valueof));
|
984 | if (!(n = values.length) || isNaN(p = +p)) return;
|
985 | if (p <= 0 || n < 2) return minIndex(values);
|
986 | if (p >= 1) return maxIndex(values);
|
987 | var n,
|
988 | i = Math.floor((n - 1) * p),
|
989 | order = (i, j) => ascendingDefined(values[i], values[j]),
|
990 | index = quickselect(Uint32Array.from(values, (_, i) => i), i, 0, n - 1, order);
|
991 | return greatest(index.subarray(0, i + 1), i => values[i]);
|
992 | }
|
993 |
|
994 | function thresholdFreedmanDiaconis(values, min, max) {
|
995 | const c = count$1(values), d = quantile$1(values, 0.75) - quantile$1(values, 0.25);
|
996 | return c && d ? Math.ceil((max - min) / (2 * d * Math.pow(c, -1 / 3))) : 1;
|
997 | }
|
998 |
|
999 | function thresholdScott(values, min, max) {
|
1000 | const c = count$1(values), d = deviation(values);
|
1001 | return c && d ? Math.ceil((max - min) * Math.cbrt(c) / (3.49 * d)) : 1;
|
1002 | }
|
1003 |
|
1004 | function mean(values, valueof) {
|
1005 | let count = 0;
|
1006 | let sum = 0;
|
1007 | if (valueof === undefined) {
|
1008 | for (let value of values) {
|
1009 | if (value != null && (value = +value) >= value) {
|
1010 | ++count, sum += value;
|
1011 | }
|
1012 | }
|
1013 | } else {
|
1014 | let index = -1;
|
1015 | for (let value of values) {
|
1016 | if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
|
1017 | ++count, sum += value;
|
1018 | }
|
1019 | }
|
1020 | }
|
1021 | if (count) return sum / count;
|
1022 | }
|
1023 |
|
1024 | function median(values, valueof) {
|
1025 | return quantile$1(values, 0.5, valueof);
|
1026 | }
|
1027 |
|
1028 | function medianIndex(values, valueof) {
|
1029 | return quantileIndex(values, 0.5, valueof);
|
1030 | }
|
1031 |
|
1032 | function* flatten(arrays) {
|
1033 | for (const array of arrays) {
|
1034 | yield* array;
|
1035 | }
|
1036 | }
|
1037 |
|
1038 | function merge(arrays) {
|
1039 | return Array.from(flatten(arrays));
|
1040 | }
|
1041 |
|
1042 | function mode(values, valueof) {
|
1043 | const counts = new InternMap();
|
1044 | if (valueof === undefined) {
|
1045 | for (let value of values) {
|
1046 | if (value != null && value >= value) {
|
1047 | counts.set(value, (counts.get(value) || 0) + 1);
|
1048 | }
|
1049 | }
|
1050 | } else {
|
1051 | let index = -1;
|
1052 | for (let value of values) {
|
1053 | if ((value = valueof(value, ++index, values)) != null && value >= value) {
|
1054 | counts.set(value, (counts.get(value) || 0) + 1);
|
1055 | }
|
1056 | }
|
1057 | }
|
1058 | let modeValue;
|
1059 | let modeCount = 0;
|
1060 | for (const [value, count] of counts) {
|
1061 | if (count > modeCount) {
|
1062 | modeCount = count;
|
1063 | modeValue = value;
|
1064 | }
|
1065 | }
|
1066 | return modeValue;
|
1067 | }
|
1068 |
|
1069 | function pairs(values, pairof = pair) {
|
1070 | const pairs = [];
|
1071 | let previous;
|
1072 | let first = false;
|
1073 | for (const value of values) {
|
1074 | if (first) pairs.push(pairof(previous, value));
|
1075 | previous = value;
|
1076 | first = true;
|
1077 | }
|
1078 | return pairs;
|
1079 | }
|
1080 |
|
1081 | function pair(a, b) {
|
1082 | return [a, b];
|
1083 | }
|
1084 |
|
1085 | function range$2(start, stop, step) {
|
1086 | start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
|
1087 |
|
1088 | var i = -1,
|
1089 | n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
|
1090 | range = new Array(n);
|
1091 |
|
1092 | while (++i < n) {
|
1093 | range[i] = start + i * step;
|
1094 | }
|
1095 |
|
1096 | return range;
|
1097 | }
|
1098 |
|
1099 | function rank(values, valueof = ascending$3) {
|
1100 | if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
|
1101 | let V = Array.from(values);
|
1102 | const R = new Float64Array(V.length);
|
1103 | if (valueof.length !== 2) V = V.map(valueof), valueof = ascending$3;
|
1104 | const compareIndex = (i, j) => valueof(V[i], V[j]);
|
1105 | let k, r;
|
1106 | values = Uint32Array.from(V, (_, i) => i);
|
1107 |
|
1108 | values.sort(valueof === ascending$3 ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex));
|
1109 | values.forEach((j, i) => {
|
1110 | const c = compareIndex(j, k === undefined ? j : k);
|
1111 | if (c >= 0) {
|
1112 | if (k === undefined || c > 0) k = j, r = i;
|
1113 | R[j] = r;
|
1114 | } else {
|
1115 | R[j] = NaN;
|
1116 | }
|
1117 | });
|
1118 | return R;
|
1119 | }
|
1120 |
|
1121 | function least(values, compare = ascending$3) {
|
1122 | let min;
|
1123 | let defined = false;
|
1124 | if (compare.length === 1) {
|
1125 | let minValue;
|
1126 | for (const element of values) {
|
1127 | const value = compare(element);
|
1128 | if (defined
|
1129 | ? ascending$3(value, minValue) < 0
|
1130 | : ascending$3(value, value) === 0) {
|
1131 | min = element;
|
1132 | minValue = value;
|
1133 | defined = true;
|
1134 | }
|
1135 | }
|
1136 | } else {
|
1137 | for (const value of values) {
|
1138 | if (defined
|
1139 | ? compare(value, min) < 0
|
1140 | : compare(value, value) === 0) {
|
1141 | min = value;
|
1142 | defined = true;
|
1143 | }
|
1144 | }
|
1145 | }
|
1146 | return min;
|
1147 | }
|
1148 |
|
1149 | function leastIndex(values, compare = ascending$3) {
|
1150 | if (compare.length === 1) return minIndex(values, compare);
|
1151 | let minValue;
|
1152 | let min = -1;
|
1153 | let index = -1;
|
1154 | for (const value of values) {
|
1155 | ++index;
|
1156 | if (min < 0
|
1157 | ? compare(value, value) === 0
|
1158 | : compare(value, minValue) < 0) {
|
1159 | minValue = value;
|
1160 | min = index;
|
1161 | }
|
1162 | }
|
1163 | return min;
|
1164 | }
|
1165 |
|
1166 | function greatestIndex(values, compare = ascending$3) {
|
1167 | if (compare.length === 1) return maxIndex(values, compare);
|
1168 | let maxValue;
|
1169 | let max = -1;
|
1170 | let index = -1;
|
1171 | for (const value of values) {
|
1172 | ++index;
|
1173 | if (max < 0
|
1174 | ? compare(value, value) === 0
|
1175 | : compare(value, maxValue) > 0) {
|
1176 | maxValue = value;
|
1177 | max = index;
|
1178 | }
|
1179 | }
|
1180 | return max;
|
1181 | }
|
1182 |
|
1183 | function scan(values, compare) {
|
1184 | const index = leastIndex(values, compare);
|
1185 | return index < 0 ? undefined : index;
|
1186 | }
|
1187 |
|
1188 | var shuffle$1 = shuffler(Math.random);
|
1189 |
|
1190 | function shuffler(random) {
|
1191 | return function shuffle(array, i0 = 0, i1 = array.length) {
|
1192 | let m = i1 - (i0 = +i0);
|
1193 | while (m) {
|
1194 | const i = random() * m-- | 0, t = array[m + i0];
|
1195 | array[m + i0] = array[i + i0];
|
1196 | array[i + i0] = t;
|
1197 | }
|
1198 | return array;
|
1199 | };
|
1200 | }
|
1201 |
|
1202 | function sum$2(values, valueof) {
|
1203 | let sum = 0;
|
1204 | if (valueof === undefined) {
|
1205 | for (let value of values) {
|
1206 | if (value = +value) {
|
1207 | sum += value;
|
1208 | }
|
1209 | }
|
1210 | } else {
|
1211 | let index = -1;
|
1212 | for (let value of values) {
|
1213 | if (value = +valueof(value, ++index, values)) {
|
1214 | sum += value;
|
1215 | }
|
1216 | }
|
1217 | }
|
1218 | return sum;
|
1219 | }
|
1220 |
|
1221 | function transpose(matrix) {
|
1222 | if (!(n = matrix.length)) return [];
|
1223 | for (var i = -1, m = min$2(matrix, length$2), transpose = new Array(m); ++i < m;) {
|
1224 | for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
|
1225 | row[j] = matrix[j][i];
|
1226 | }
|
1227 | }
|
1228 | return transpose;
|
1229 | }
|
1230 |
|
1231 | function length$2(d) {
|
1232 | return d.length;
|
1233 | }
|
1234 |
|
1235 | function zip() {
|
1236 | return transpose(arguments);
|
1237 | }
|
1238 |
|
1239 | function every(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 false;
|
1245 | }
|
1246 | }
|
1247 | return true;
|
1248 | }
|
1249 |
|
1250 | function some(values, test) {
|
1251 | if (typeof test !== "function") throw new TypeError("test is not a function");
|
1252 | let index = -1;
|
1253 | for (const value of values) {
|
1254 | if (test(value, ++index, values)) {
|
1255 | return true;
|
1256 | }
|
1257 | }
|
1258 | return false;
|
1259 | }
|
1260 |
|
1261 | function filter$1(values, test) {
|
1262 | if (typeof test !== "function") throw new TypeError("test is not a function");
|
1263 | const array = [];
|
1264 | let index = -1;
|
1265 | for (const value of values) {
|
1266 | if (test(value, ++index, values)) {
|
1267 | array.push(value);
|
1268 | }
|
1269 | }
|
1270 | return array;
|
1271 | }
|
1272 |
|
1273 | function map$1(values, mapper) {
|
1274 | if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
|
1275 | if (typeof mapper !== "function") throw new TypeError("mapper is not a function");
|
1276 | return Array.from(values, (value, index) => mapper(value, index, values));
|
1277 | }
|
1278 |
|
1279 | function reduce(values, reducer, value) {
|
1280 | if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
|
1281 | const iterator = values[Symbol.iterator]();
|
1282 | let done, next, index = -1;
|
1283 | if (arguments.length < 3) {
|
1284 | ({done, value} = iterator.next());
|
1285 | if (done) return;
|
1286 | ++index;
|
1287 | }
|
1288 | while (({done, value: next} = iterator.next()), !done) {
|
1289 | value = reducer(value, next, ++index, values);
|
1290 | }
|
1291 | return value;
|
1292 | }
|
1293 |
|
1294 | function reverse$1(values) {
|
1295 | if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
|
1296 | return Array.from(values).reverse();
|
1297 | }
|
1298 |
|
1299 | function difference(values, ...others) {
|
1300 | values = new InternSet(values);
|
1301 | for (const other of others) {
|
1302 | for (const value of other) {
|
1303 | values.delete(value);
|
1304 | }
|
1305 | }
|
1306 | return values;
|
1307 | }
|
1308 |
|
1309 | function disjoint(values, other) {
|
1310 | const iterator = other[Symbol.iterator](), set = new InternSet();
|
1311 | for (const v of values) {
|
1312 | if (set.has(v)) return false;
|
1313 | let value, done;
|
1314 | while (({value, done} = iterator.next())) {
|
1315 | if (done) break;
|
1316 | if (Object.is(v, value)) return false;
|
1317 | set.add(value);
|
1318 | }
|
1319 | }
|
1320 | return true;
|
1321 | }
|
1322 |
|
1323 | function intersection(values, ...others) {
|
1324 | values = new InternSet(values);
|
1325 | others = others.map(set$2);
|
1326 | out: for (const value of values) {
|
1327 | for (const other of others) {
|
1328 | if (!other.has(value)) {
|
1329 | values.delete(value);
|
1330 | continue out;
|
1331 | }
|
1332 | }
|
1333 | }
|
1334 | return values;
|
1335 | }
|
1336 |
|
1337 | function set$2(values) {
|
1338 | return values instanceof InternSet ? values : new InternSet(values);
|
1339 | }
|
1340 |
|
1341 | function superset(values, other) {
|
1342 | const iterator = values[Symbol.iterator](), set = new Set();
|
1343 | for (const o of other) {
|
1344 | const io = intern(o);
|
1345 | if (set.has(io)) continue;
|
1346 | let value, done;
|
1347 | while (({value, done} = iterator.next())) {
|
1348 | if (done) return false;
|
1349 | const ivalue = intern(value);
|
1350 | set.add(ivalue);
|
1351 | if (Object.is(io, ivalue)) break;
|
1352 | }
|
1353 | }
|
1354 | return true;
|
1355 | }
|
1356 |
|
1357 | function intern(value) {
|
1358 | return value !== null && typeof value === "object" ? value.valueOf() : value;
|
1359 | }
|
1360 |
|
1361 | function subset(values, other) {
|
1362 | return superset(other, values);
|
1363 | }
|
1364 |
|
1365 | function union(...others) {
|
1366 | const set = new InternSet();
|
1367 | for (const other of others) {
|
1368 | for (const o of other) {
|
1369 | set.add(o);
|
1370 | }
|
1371 | }
|
1372 | return set;
|
1373 | }
|
1374 |
|
1375 | function identity$8(x) {
|
1376 | return x;
|
1377 | }
|
1378 |
|
1379 | var top = 1,
|
1380 | right = 2,
|
1381 | bottom = 3,
|
1382 | left = 4,
|
1383 | epsilon$6 = 1e-6;
|
1384 |
|
1385 | function translateX(x) {
|
1386 | return "translate(" + x + ",0)";
|
1387 | }
|
1388 |
|
1389 | function translateY(y) {
|
1390 | return "translate(0," + y + ")";
|
1391 | }
|
1392 |
|
1393 | function number$2(scale) {
|
1394 | return d => +scale(d);
|
1395 | }
|
1396 |
|
1397 | function center$1(scale, offset) {
|
1398 | offset = Math.max(0, scale.bandwidth() - offset * 2) / 2;
|
1399 | if (scale.round()) offset = Math.round(offset);
|
1400 | return d => +scale(d) + offset;
|
1401 | }
|
1402 |
|
1403 | function entering() {
|
1404 | return !this.__axis;
|
1405 | }
|
1406 |
|
1407 | function axis(orient, scale) {
|
1408 | var tickArguments = [],
|
1409 | tickValues = null,
|
1410 | tickFormat = null,
|
1411 | tickSizeInner = 6,
|
1412 | tickSizeOuter = 6,
|
1413 | tickPadding = 3,
|
1414 | offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5,
|
1415 | k = orient === top || orient === left ? -1 : 1,
|
1416 | x = orient === left || orient === right ? "x" : "y",
|
1417 | transform = orient === top || orient === bottom ? translateX : translateY;
|
1418 |
|
1419 | function axis(context) {
|
1420 | var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
|
1421 | format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$8) : tickFormat,
|
1422 | spacing = Math.max(tickSizeInner, 0) + tickPadding,
|
1423 | range = scale.range(),
|
1424 | range0 = +range[0] + offset,
|
1425 | range1 = +range[range.length - 1] + offset,
|
1426 | position = (scale.bandwidth ? center$1 : number$2)(scale.copy(), offset),
|
1427 | selection = context.selection ? context.selection() : context,
|
1428 | path = selection.selectAll(".domain").data([null]),
|
1429 | tick = selection.selectAll(".tick").data(values, scale).order(),
|
1430 | tickExit = tick.exit(),
|
1431 | tickEnter = tick.enter().append("g").attr("class", "tick"),
|
1432 | line = tick.select("line"),
|
1433 | text = tick.select("text");
|
1434 |
|
1435 | path = path.merge(path.enter().insert("path", ".tick")
|
1436 | .attr("class", "domain")
|
1437 | .attr("stroke", "currentColor"));
|
1438 |
|
1439 | tick = tick.merge(tickEnter);
|
1440 |
|
1441 | line = line.merge(tickEnter.append("line")
|
1442 | .attr("stroke", "currentColor")
|
1443 | .attr(x + "2", k * tickSizeInner));
|
1444 |
|
1445 | text = text.merge(tickEnter.append("text")
|
1446 | .attr("fill", "currentColor")
|
1447 | .attr(x, k * spacing)
|
1448 | .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
|
1449 |
|
1450 | if (context !== selection) {
|
1451 | path = path.transition(context);
|
1452 | tick = tick.transition(context);
|
1453 | line = line.transition(context);
|
1454 | text = text.transition(context);
|
1455 |
|
1456 | tickExit = tickExit.transition(context)
|
1457 | .attr("opacity", epsilon$6)
|
1458 | .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform"); });
|
1459 |
|
1460 | tickEnter
|
1461 | .attr("opacity", epsilon$6)
|
1462 | .attr("transform", function(d) { var p = this.parentNode.__axis; return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset); });
|
1463 | }
|
1464 |
|
1465 | tickExit.remove();
|
1466 |
|
1467 | path
|
1468 | .attr("d", orient === left || orient === right
|
1469 | ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1)
|
1470 | : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1));
|
1471 |
|
1472 | tick
|
1473 | .attr("opacity", 1)
|
1474 | .attr("transform", function(d) { return transform(position(d) + offset); });
|
1475 |
|
1476 | line
|
1477 | .attr(x + "2", k * tickSizeInner);
|
1478 |
|
1479 | text
|
1480 | .attr(x, k * spacing)
|
1481 | .text(format);
|
1482 |
|
1483 | selection.filter(entering)
|
1484 | .attr("fill", "none")
|
1485 | .attr("font-size", 10)
|
1486 | .attr("font-family", "sans-serif")
|
1487 | .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
|
1488 |
|
1489 | selection
|
1490 | .each(function() { this.__axis = position; });
|
1491 | }
|
1492 |
|
1493 | axis.scale = function(_) {
|
1494 | return arguments.length ? (scale = _, axis) : scale;
|
1495 | };
|
1496 |
|
1497 | axis.ticks = function() {
|
1498 | return tickArguments = Array.from(arguments), axis;
|
1499 | };
|
1500 |
|
1501 | axis.tickArguments = function(_) {
|
1502 | return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice();
|
1503 | };
|
1504 |
|
1505 | axis.tickValues = function(_) {
|
1506 | return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice();
|
1507 | };
|
1508 |
|
1509 | axis.tickFormat = function(_) {
|
1510 | return arguments.length ? (tickFormat = _, axis) : tickFormat;
|
1511 | };
|
1512 |
|
1513 | axis.tickSize = function(_) {
|
1514 | return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
|
1515 | };
|
1516 |
|
1517 | axis.tickSizeInner = function(_) {
|
1518 | return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
|
1519 | };
|
1520 |
|
1521 | axis.tickSizeOuter = function(_) {
|
1522 | return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
|
1523 | };
|
1524 |
|
1525 | axis.tickPadding = function(_) {
|
1526 | return arguments.length ? (tickPadding = +_, axis) : tickPadding;
|
1527 | };
|
1528 |
|
1529 | axis.offset = function(_) {
|
1530 | return arguments.length ? (offset = +_, axis) : offset;
|
1531 | };
|
1532 |
|
1533 | return axis;
|
1534 | }
|
1535 |
|
1536 | function axisTop(scale) {
|
1537 | return axis(top, scale);
|
1538 | }
|
1539 |
|
1540 | function axisRight(scale) {
|
1541 | return axis(right, scale);
|
1542 | }
|
1543 |
|
1544 | function axisBottom(scale) {
|
1545 | return axis(bottom, scale);
|
1546 | }
|
1547 |
|
1548 | function axisLeft(scale) {
|
1549 | return axis(left, scale);
|
1550 | }
|
1551 |
|
1552 | var noop$3 = {value: () => {}};
|
1553 |
|
1554 | function dispatch() {
|
1555 | for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
|
1556 | if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
|
1557 | _[t] = [];
|
1558 | }
|
1559 | return new Dispatch(_);
|
1560 | }
|
1561 |
|
1562 | function Dispatch(_) {
|
1563 | this._ = _;
|
1564 | }
|
1565 |
|
1566 | function parseTypenames$1(typenames, types) {
|
1567 | return typenames.trim().split(/^|\s+/).map(function(t) {
|
1568 | var name = "", i = t.indexOf(".");
|
1569 | if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
1570 | if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
|
1571 | return {type: t, name: name};
|
1572 | });
|
1573 | }
|
1574 |
|
1575 | Dispatch.prototype = dispatch.prototype = {
|
1576 | constructor: Dispatch,
|
1577 | on: function(typename, callback) {
|
1578 | var _ = this._,
|
1579 | T = parseTypenames$1(typename + "", _),
|
1580 | t,
|
1581 | i = -1,
|
1582 | n = T.length;
|
1583 |
|
1584 |
|
1585 | if (arguments.length < 2) {
|
1586 | while (++i < n) if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t;
|
1587 | return;
|
1588 | }
|
1589 |
|
1590 | // If a type was specified, set the callback for the given type and name.
|
1591 | // Otherwise, if a null callback was specified, remove callbacks of the given name.
|
1592 | if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
|
1593 | while (++i < n) {
|
1594 | if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback);
|
1595 | else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null);
|
1596 | }
|
1597 |
|
1598 | return this;
|
1599 | },
|
1600 | copy: function() {
|
1601 | var copy = {}, _ = this._;
|
1602 | for (var t in _) copy[t] = _[t].slice();
|
1603 | return new Dispatch(copy);
|
1604 | },
|
1605 | call: function(type, that) {
|
1606 | if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
|
1607 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
1608 | for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
1609 | },
|
1610 | apply: function(type, that, args) {
|
1611 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
1612 | for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
1613 | }
|
1614 | };
|
1615 |
|
1616 | function get$1(type, name) {
|
1617 | for (var i = 0, n = type.length, c; i < n; ++i) {
|
1618 | if ((c = type[i]).name === name) {
|
1619 | return c.value;
|
1620 | }
|
1621 | }
|
1622 | }
|
1623 |
|
1624 | function set$1(type, name, callback) {
|
1625 | for (var i = 0, n = type.length; i < n; ++i) {
|
1626 | if (type[i].name === name) {
|
1627 | type[i] = noop$3, type = type.slice(0, i).concat(type.slice(i + 1));
|
1628 | break;
|
1629 | }
|
1630 | }
|
1631 | if (callback != null) type.push({name: name, value: callback});
|
1632 | return type;
|
1633 | }
|
1634 |
|
1635 | var xhtml = "http://www.w3.org/1999/xhtml";
|
1636 |
|
1637 | var namespaces = {
|
1638 | svg: "http://www.w3.org/2000/svg",
|
1639 | xhtml: xhtml,
|
1640 | xlink: "http://www.w3.org/1999/xlink",
|
1641 | xml: "http://www.w3.org/XML/1998/namespace",
|
1642 | xmlns: "http://www.w3.org/2000/xmlns/"
|
1643 | };
|
1644 |
|
1645 | function namespace(name) {
|
1646 | var prefix = name += "", i = prefix.indexOf(":");
|
1647 | if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
|
1648 | return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
|
1649 | }
|
1650 |
|
1651 | function creatorInherit(name) {
|
1652 | return function() {
|
1653 | var document = this.ownerDocument,
|
1654 | uri = this.namespaceURI;
|
1655 | return uri === xhtml && document.documentElement.namespaceURI === xhtml
|
1656 | ? document.createElement(name)
|
1657 | : document.createElementNS(uri, name);
|
1658 | };
|
1659 | }
|
1660 |
|
1661 | function creatorFixed(fullname) {
|
1662 | return function() {
|
1663 | return this.ownerDocument.createElementNS(fullname.space, fullname.local);
|
1664 | };
|
1665 | }
|
1666 |
|
1667 | function creator(name) {
|
1668 | var fullname = namespace(name);
|
1669 | return (fullname.local
|
1670 | ? creatorFixed
|
1671 | : creatorInherit)(fullname);
|
1672 | }
|
1673 |
|
1674 | function none$2() {}
|
1675 |
|
1676 | function selector(selector) {
|
1677 | return selector == null ? none$2 : function() {
|
1678 | return this.querySelector(selector);
|
1679 | };
|
1680 | }
|
1681 |
|
1682 | function selection_select(select) {
|
1683 | if (typeof select !== "function") select = selector(select);
|
1684 |
|
1685 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
1686 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
|
1687 | if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
1688 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
1689 | subgroup[i] = subnode;
|
1690 | }
|
1691 | }
|
1692 | }
|
1693 |
|
1694 | return new Selection$1(subgroups, this._parents);
|
1695 | }
|
1696 |
|
1697 |
|
1698 |
|
1699 |
|
1700 |
|
1701 |
|
1702 |
|
1703 | function array$4(x) {
|
1704 | return x == null ? [] : Array.isArray(x) ? x : Array.from(x);
|
1705 | }
|
1706 |
|
1707 | function empty$1() {
|
1708 | return [];
|
1709 | }
|
1710 |
|
1711 | function selectorAll(selector) {
|
1712 | return selector == null ? empty$1 : function() {
|
1713 | return this.querySelectorAll(selector);
|
1714 | };
|
1715 | }
|
1716 |
|
1717 | function arrayAll(select) {
|
1718 | return function() {
|
1719 | return array$4(select.apply(this, arguments));
|
1720 | };
|
1721 | }
|
1722 |
|
1723 | function selection_selectAll(select) {
|
1724 | if (typeof select === "function") select = arrayAll(select);
|
1725 | else select = selectorAll(select);
|
1726 |
|
1727 | for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
|
1728 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
1729 | if (node = group[i]) {
|
1730 | subgroups.push(select.call(node, node.__data__, i, group));
|
1731 | parents.push(node);
|
1732 | }
|
1733 | }
|
1734 | }
|
1735 |
|
1736 | return new Selection$1(subgroups, parents);
|
1737 | }
|
1738 |
|
1739 | function matcher(selector) {
|
1740 | return function() {
|
1741 | return this.matches(selector);
|
1742 | };
|
1743 | }
|
1744 |
|
1745 | function childMatcher(selector) {
|
1746 | return function(node) {
|
1747 | return node.matches(selector);
|
1748 | };
|
1749 | }
|
1750 |
|
1751 | var find$1 = Array.prototype.find;
|
1752 |
|
1753 | function childFind(match) {
|
1754 | return function() {
|
1755 | return find$1.call(this.children, match);
|
1756 | };
|
1757 | }
|
1758 |
|
1759 | function childFirst() {
|
1760 | return this.firstElementChild;
|
1761 | }
|
1762 |
|
1763 | function selection_selectChild(match) {
|
1764 | return this.select(match == null ? childFirst
|
1765 | : childFind(typeof match === "function" ? match : childMatcher(match)));
|
1766 | }
|
1767 |
|
1768 | var filter = Array.prototype.filter;
|
1769 |
|
1770 | function children() {
|
1771 | return Array.from(this.children);
|
1772 | }
|
1773 |
|
1774 | function childrenFilter(match) {
|
1775 | return function() {
|
1776 | return filter.call(this.children, match);
|
1777 | };
|
1778 | }
|
1779 |
|
1780 | function selection_selectChildren(match) {
|
1781 | return this.selectAll(match == null ? children
|
1782 | : childrenFilter(typeof match === "function" ? match : childMatcher(match)));
|
1783 | }
|
1784 |
|
1785 | function selection_filter(match) {
|
1786 | if (typeof match !== "function") match = matcher(match);
|
1787 |
|
1788 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
1789 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
|
1790 | if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
1791 | subgroup.push(node);
|
1792 | }
|
1793 | }
|
1794 | }
|
1795 |
|
1796 | return new Selection$1(subgroups, this._parents);
|
1797 | }
|
1798 |
|
1799 | function sparse(update) {
|
1800 | return new Array(update.length);
|
1801 | }
|
1802 |
|
1803 | function selection_enter() {
|
1804 | return new Selection$1(this._enter || this._groups.map(sparse), this._parents);
|
1805 | }
|
1806 |
|
1807 | function EnterNode(parent, datum) {
|
1808 | this.ownerDocument = parent.ownerDocument;
|
1809 | this.namespaceURI = parent.namespaceURI;
|
1810 | this._next = null;
|
1811 | this._parent = parent;
|
1812 | this.__data__ = datum;
|
1813 | }
|
1814 |
|
1815 | EnterNode.prototype = {
|
1816 | constructor: EnterNode,
|
1817 | appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
|
1818 | insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
|
1819 | querySelector: function(selector) { return this._parent.querySelector(selector); },
|
1820 | querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
|
1821 | };
|
1822 |
|
1823 | function constant$a(x) {
|
1824 | return function() {
|
1825 | return x;
|
1826 | };
|
1827 | }
|
1828 |
|
1829 | function bindIndex(parent, group, enter, update, exit, data) {
|
1830 | var i = 0,
|
1831 | node,
|
1832 | groupLength = group.length,
|
1833 | dataLength = data.length;
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 | for (; i < dataLength; ++i) {
|
1839 | if (node = group[i]) {
|
1840 | node.__data__ = data[i];
|
1841 | update[i] = node;
|
1842 | } else {
|
1843 | enter[i] = new EnterNode(parent, data[i]);
|
1844 | }
|
1845 | }
|
1846 |
|
1847 |
|
1848 | for (; i < groupLength; ++i) {
|
1849 | if (node = group[i]) {
|
1850 | exit[i] = node;
|
1851 | }
|
1852 | }
|
1853 | }
|
1854 |
|
1855 | function bindKey(parent, group, enter, update, exit, data, key) {
|
1856 | var i,
|
1857 | node,
|
1858 | nodeByKeyValue = new Map,
|
1859 | groupLength = group.length,
|
1860 | dataLength = data.length,
|
1861 | keyValues = new Array(groupLength),
|
1862 | keyValue;
|
1863 |
|
1864 |
|
1865 |
|
1866 | for (i = 0; i < groupLength; ++i) {
|
1867 | if (node = group[i]) {
|
1868 | keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + "";
|
1869 | if (nodeByKeyValue.has(keyValue)) {
|
1870 | exit[i] = node;
|
1871 | } else {
|
1872 | nodeByKeyValue.set(keyValue, node);
|
1873 | }
|
1874 | }
|
1875 | }
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 | for (i = 0; i < dataLength; ++i) {
|
1881 | keyValue = key.call(parent, data[i], i, data) + "";
|
1882 | if (node = nodeByKeyValue.get(keyValue)) {
|
1883 | update[i] = node;
|
1884 | node.__data__ = data[i];
|
1885 | nodeByKeyValue.delete(keyValue);
|
1886 | } else {
|
1887 | enter[i] = new EnterNode(parent, data[i]);
|
1888 | }
|
1889 | }
|
1890 |
|
1891 |
|
1892 | for (i = 0; i < groupLength; ++i) {
|
1893 | if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) {
|
1894 | exit[i] = node;
|
1895 | }
|
1896 | }
|
1897 | }
|
1898 |
|
1899 | function datum(node) {
|
1900 | return node.__data__;
|
1901 | }
|
1902 |
|
1903 | function selection_data(value, key) {
|
1904 | if (!arguments.length) return Array.from(this, datum);
|
1905 |
|
1906 | var bind = key ? bindKey : bindIndex,
|
1907 | parents = this._parents,
|
1908 | groups = this._groups;
|
1909 |
|
1910 | if (typeof value !== "function") value = constant$a(value);
|
1911 |
|
1912 | for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
|
1913 | var parent = parents[j],
|
1914 | group = groups[j],
|
1915 | groupLength = group.length,
|
1916 | data = arraylike(value.call(parent, parent && parent.__data__, j, parents)),
|
1917 | dataLength = data.length,
|
1918 | enterGroup = enter[j] = new Array(dataLength),
|
1919 | updateGroup = update[j] = new Array(dataLength),
|
1920 | exitGroup = exit[j] = new Array(groupLength);
|
1921 |
|
1922 | bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 | for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
|
1928 | if (previous = enterGroup[i0]) {
|
1929 | if (i0 >= i1) i1 = i0 + 1;
|
1930 | while (!(next = updateGroup[i1]) && ++i1 < dataLength);
|
1931 | previous._next = next || null;
|
1932 | }
|
1933 | }
|
1934 | }
|
1935 |
|
1936 | update = new Selection$1(update, parents);
|
1937 | update._enter = enter;
|
1938 | update._exit = exit;
|
1939 | return update;
|
1940 | }
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 | function arraylike(data) {
|
1949 | return typeof data === "object" && "length" in data
|
1950 | ? data
|
1951 | : Array.from(data);
|
1952 | }
|
1953 |
|
1954 | function selection_exit() {
|
1955 | return new Selection$1(this._exit || this._groups.map(sparse), this._parents);
|
1956 | }
|
1957 |
|
1958 | function selection_join(onenter, onupdate, onexit) {
|
1959 | var enter = this.enter(), update = this, exit = this.exit();
|
1960 | if (typeof onenter === "function") {
|
1961 | enter = onenter(enter);
|
1962 | if (enter) enter = enter.selection();
|
1963 | } else {
|
1964 | enter = enter.append(onenter + "");
|
1965 | }
|
1966 | if (onupdate != null) {
|
1967 | update = onupdate(update);
|
1968 | if (update) update = update.selection();
|
1969 | }
|
1970 | if (onexit == null) exit.remove(); else onexit(exit);
|
1971 | return enter && update ? enter.merge(update).order() : update;
|
1972 | }
|
1973 |
|
1974 | function selection_merge(context) {
|
1975 | var selection = context.selection ? context.selection() : context;
|
1976 |
|
1977 | 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) {
|
1978 | for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
|
1979 | if (node = group0[i] || group1[i]) {
|
1980 | merge[i] = node;
|
1981 | }
|
1982 | }
|
1983 | }
|
1984 |
|
1985 | for (; j < m0; ++j) {
|
1986 | merges[j] = groups0[j];
|
1987 | }
|
1988 |
|
1989 | return new Selection$1(merges, this._parents);
|
1990 | }
|
1991 |
|
1992 | function selection_order() {
|
1993 |
|
1994 | for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
|
1995 | for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
|
1996 | if (node = group[i]) {
|
1997 | if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
|
1998 | next = node;
|
1999 | }
|
2000 | }
|
2001 | }
|
2002 |
|
2003 | return this;
|
2004 | }
|
2005 |
|
2006 | function selection_sort(compare) {
|
2007 | if (!compare) compare = ascending$2;
|
2008 |
|
2009 | function compareNode(a, b) {
|
2010 | return a && b ? compare(a.__data__, b.__data__) : !a - !b;
|
2011 | }
|
2012 |
|
2013 | for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
|
2014 | for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
|
2015 | if (node = group[i]) {
|
2016 | sortgroup[i] = node;
|
2017 | }
|
2018 | }
|
2019 | sortgroup.sort(compareNode);
|
2020 | }
|
2021 |
|
2022 | return new Selection$1(sortgroups, this._parents).order();
|
2023 | }
|
2024 |
|
2025 | function ascending$2(a, b) {
|
2026 | return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
2027 | }
|
2028 |
|
2029 | function selection_call() {
|
2030 | var callback = arguments[0];
|
2031 | arguments[0] = this;
|
2032 | callback.apply(null, arguments);
|
2033 | return this;
|
2034 | }
|
2035 |
|
2036 | function selection_nodes() {
|
2037 | return Array.from(this);
|
2038 | }
|
2039 |
|
2040 | function selection_node() {
|
2041 |
|
2042 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
2043 | for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
|
2044 | var node = group[i];
|
2045 | if (node) return node;
|
2046 | }
|
2047 | }
|
2048 |
|
2049 | return null;
|
2050 | }
|
2051 |
|
2052 | function selection_size() {
|
2053 | let size = 0;
|
2054 | for (const node of this) ++size;
|
2055 | return size;
|
2056 | }
|
2057 |
|
2058 | function selection_empty() {
|
2059 | return !this.node();
|
2060 | }
|
2061 |
|
2062 | function selection_each(callback) {
|
2063 |
|
2064 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
2065 | for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
|
2066 | if (node = group[i]) callback.call(node, node.__data__, i, group);
|
2067 | }
|
2068 | }
|
2069 |
|
2070 | return this;
|
2071 | }
|
2072 |
|
2073 | function attrRemove$1(name) {
|
2074 | return function() {
|
2075 | this.removeAttribute(name);
|
2076 | };
|
2077 | }
|
2078 |
|
2079 | function attrRemoveNS$1(fullname) {
|
2080 | return function() {
|
2081 | this.removeAttributeNS(fullname.space, fullname.local);
|
2082 | };
|
2083 | }
|
2084 |
|
2085 | function attrConstant$1(name, value) {
|
2086 | return function() {
|
2087 | this.setAttribute(name, value);
|
2088 | };
|
2089 | }
|
2090 |
|
2091 | function attrConstantNS$1(fullname, value) {
|
2092 | return function() {
|
2093 | this.setAttributeNS(fullname.space, fullname.local, value);
|
2094 | };
|
2095 | }
|
2096 |
|
2097 | function attrFunction$1(name, value) {
|
2098 | return function() {
|
2099 | var v = value.apply(this, arguments);
|
2100 | if (v == null) this.removeAttribute(name);
|
2101 | else this.setAttribute(name, v);
|
2102 | };
|
2103 | }
|
2104 |
|
2105 | function attrFunctionNS$1(fullname, value) {
|
2106 | return function() {
|
2107 | var v = value.apply(this, arguments);
|
2108 | if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
|
2109 | else this.setAttributeNS(fullname.space, fullname.local, v);
|
2110 | };
|
2111 | }
|
2112 |
|
2113 | function selection_attr(name, value) {
|
2114 | var fullname = namespace(name);
|
2115 |
|
2116 | if (arguments.length < 2) {
|
2117 | var node = this.node();
|
2118 | return fullname.local
|
2119 | ? node.getAttributeNS(fullname.space, fullname.local)
|
2120 | : node.getAttribute(fullname);
|
2121 | }
|
2122 |
|
2123 | return this.each((value == null
|
2124 | ? (fullname.local ? attrRemoveNS$1 : attrRemove$1) : (typeof value === "function"
|
2125 | ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)
|
2126 | : (fullname.local ? attrConstantNS$1 : attrConstant$1)))(fullname, value));
|
2127 | }
|
2128 |
|
2129 | function defaultView(node) {
|
2130 | return (node.ownerDocument && node.ownerDocument.defaultView)
|
2131 | || (node.document && node)
|
2132 | || node.defaultView;
|
2133 | }
|
2134 |
|
2135 | function styleRemove$1(name) {
|
2136 | return function() {
|
2137 | this.style.removeProperty(name);
|
2138 | };
|
2139 | }
|
2140 |
|
2141 | function styleConstant$1(name, value, priority) {
|
2142 | return function() {
|
2143 | this.style.setProperty(name, value, priority);
|
2144 | };
|
2145 | }
|
2146 |
|
2147 | function styleFunction$1(name, value, priority) {
|
2148 | return function() {
|
2149 | var v = value.apply(this, arguments);
|
2150 | if (v == null) this.style.removeProperty(name);
|
2151 | else this.style.setProperty(name, v, priority);
|
2152 | };
|
2153 | }
|
2154 |
|
2155 | function selection_style(name, value, priority) {
|
2156 | return arguments.length > 1
|
2157 | ? this.each((value == null
|
2158 | ? styleRemove$1 : typeof value === "function"
|
2159 | ? styleFunction$1
|
2160 | : styleConstant$1)(name, value, priority == null ? "" : priority))
|
2161 | : styleValue(this.node(), name);
|
2162 | }
|
2163 |
|
2164 | function styleValue(node, name) {
|
2165 | return node.style.getPropertyValue(name)
|
2166 | || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
|
2167 | }
|
2168 |
|
2169 | function propertyRemove(name) {
|
2170 | return function() {
|
2171 | delete this[name];
|
2172 | };
|
2173 | }
|
2174 |
|
2175 | function propertyConstant(name, value) {
|
2176 | return function() {
|
2177 | this[name] = value;
|
2178 | };
|
2179 | }
|
2180 |
|
2181 | function propertyFunction(name, value) {
|
2182 | return function() {
|
2183 | var v = value.apply(this, arguments);
|
2184 | if (v == null) delete this[name];
|
2185 | else this[name] = v;
|
2186 | };
|
2187 | }
|
2188 |
|
2189 | function selection_property(name, value) {
|
2190 | return arguments.length > 1
|
2191 | ? this.each((value == null
|
2192 | ? propertyRemove : typeof value === "function"
|
2193 | ? propertyFunction
|
2194 | : propertyConstant)(name, value))
|
2195 | : this.node()[name];
|
2196 | }
|
2197 |
|
2198 | function classArray(string) {
|
2199 | return string.trim().split(/^|\s+/);
|
2200 | }
|
2201 |
|
2202 | function classList(node) {
|
2203 | return node.classList || new ClassList(node);
|
2204 | }
|
2205 |
|
2206 | function ClassList(node) {
|
2207 | this._node = node;
|
2208 | this._names = classArray(node.getAttribute("class") || "");
|
2209 | }
|
2210 |
|
2211 | ClassList.prototype = {
|
2212 | add: function(name) {
|
2213 | var i = this._names.indexOf(name);
|
2214 | if (i < 0) {
|
2215 | this._names.push(name);
|
2216 | this._node.setAttribute("class", this._names.join(" "));
|
2217 | }
|
2218 | },
|
2219 | remove: function(name) {
|
2220 | var i = this._names.indexOf(name);
|
2221 | if (i >= 0) {
|
2222 | this._names.splice(i, 1);
|
2223 | this._node.setAttribute("class", this._names.join(" "));
|
2224 | }
|
2225 | },
|
2226 | contains: function(name) {
|
2227 | return this._names.indexOf(name) >= 0;
|
2228 | }
|
2229 | };
|
2230 |
|
2231 | function classedAdd(node, names) {
|
2232 | var list = classList(node), i = -1, n = names.length;
|
2233 | while (++i < n) list.add(names[i]);
|
2234 | }
|
2235 |
|
2236 | function classedRemove(node, names) {
|
2237 | var list = classList(node), i = -1, n = names.length;
|
2238 | while (++i < n) list.remove(names[i]);
|
2239 | }
|
2240 |
|
2241 | function classedTrue(names) {
|
2242 | return function() {
|
2243 | classedAdd(this, names);
|
2244 | };
|
2245 | }
|
2246 |
|
2247 | function classedFalse(names) {
|
2248 | return function() {
|
2249 | classedRemove(this, names);
|
2250 | };
|
2251 | }
|
2252 |
|
2253 | function classedFunction(names, value) {
|
2254 | return function() {
|
2255 | (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
|
2256 | };
|
2257 | }
|
2258 |
|
2259 | function selection_classed(name, value) {
|
2260 | var names = classArray(name + "");
|
2261 |
|
2262 | if (arguments.length < 2) {
|
2263 | var list = classList(this.node()), i = -1, n = names.length;
|
2264 | while (++i < n) if (!list.contains(names[i])) return false;
|
2265 | return true;
|
2266 | }
|
2267 |
|
2268 | return this.each((typeof value === "function"
|
2269 | ? classedFunction : value
|
2270 | ? classedTrue
|
2271 | : classedFalse)(names, value));
|
2272 | }
|
2273 |
|
2274 | function textRemove() {
|
2275 | this.textContent = "";
|
2276 | }
|
2277 |
|
2278 | function textConstant$1(value) {
|
2279 | return function() {
|
2280 | this.textContent = value;
|
2281 | };
|
2282 | }
|
2283 |
|
2284 | function textFunction$1(value) {
|
2285 | return function() {
|
2286 | var v = value.apply(this, arguments);
|
2287 | this.textContent = v == null ? "" : v;
|
2288 | };
|
2289 | }
|
2290 |
|
2291 | function selection_text(value) {
|
2292 | return arguments.length
|
2293 | ? this.each(value == null
|
2294 | ? textRemove : (typeof value === "function"
|
2295 | ? textFunction$1
|
2296 | : textConstant$1)(value))
|
2297 | : this.node().textContent;
|
2298 | }
|
2299 |
|
2300 | function htmlRemove() {
|
2301 | this.innerHTML = "";
|
2302 | }
|
2303 |
|
2304 | function htmlConstant(value) {
|
2305 | return function() {
|
2306 | this.innerHTML = value;
|
2307 | };
|
2308 | }
|
2309 |
|
2310 | function htmlFunction(value) {
|
2311 | return function() {
|
2312 | var v = value.apply(this, arguments);
|
2313 | this.innerHTML = v == null ? "" : v;
|
2314 | };
|
2315 | }
|
2316 |
|
2317 | function selection_html(value) {
|
2318 | return arguments.length
|
2319 | ? this.each(value == null
|
2320 | ? htmlRemove : (typeof value === "function"
|
2321 | ? htmlFunction
|
2322 | : htmlConstant)(value))
|
2323 | : this.node().innerHTML;
|
2324 | }
|
2325 |
|
2326 | function raise() {
|
2327 | if (this.nextSibling) this.parentNode.appendChild(this);
|
2328 | }
|
2329 |
|
2330 | function selection_raise() {
|
2331 | return this.each(raise);
|
2332 | }
|
2333 |
|
2334 | function lower() {
|
2335 | if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
|
2336 | }
|
2337 |
|
2338 | function selection_lower() {
|
2339 | return this.each(lower);
|
2340 | }
|
2341 |
|
2342 | function selection_append(name) {
|
2343 | var create = typeof name === "function" ? name : creator(name);
|
2344 | return this.select(function() {
|
2345 | return this.appendChild(create.apply(this, arguments));
|
2346 | });
|
2347 | }
|
2348 |
|
2349 | function constantNull() {
|
2350 | return null;
|
2351 | }
|
2352 |
|
2353 | function selection_insert(name, before) {
|
2354 | var create = typeof name === "function" ? name : creator(name),
|
2355 | select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
|
2356 | return this.select(function() {
|
2357 | return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
|
2358 | });
|
2359 | }
|
2360 |
|
2361 | function remove() {
|
2362 | var parent = this.parentNode;
|
2363 | if (parent) parent.removeChild(this);
|
2364 | }
|
2365 |
|
2366 | function selection_remove() {
|
2367 | return this.each(remove);
|
2368 | }
|
2369 |
|
2370 | function selection_cloneShallow() {
|
2371 | var clone = this.cloneNode(false), parent = this.parentNode;
|
2372 | return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
|
2373 | }
|
2374 |
|
2375 | function selection_cloneDeep() {
|
2376 | var clone = this.cloneNode(true), parent = this.parentNode;
|
2377 | return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
|
2378 | }
|
2379 |
|
2380 | function selection_clone(deep) {
|
2381 | return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
|
2382 | }
|
2383 |
|
2384 | function selection_datum(value) {
|
2385 | return arguments.length
|
2386 | ? this.property("__data__", value)
|
2387 | : this.node().__data__;
|
2388 | }
|
2389 |
|
2390 | function contextListener(listener) {
|
2391 | return function(event) {
|
2392 | listener.call(this, event, this.__data__);
|
2393 | };
|
2394 | }
|
2395 |
|
2396 | function parseTypenames(typenames) {
|
2397 | return typenames.trim().split(/^|\s+/).map(function(t) {
|
2398 | var name = "", i = t.indexOf(".");
|
2399 | if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
2400 | return {type: t, name: name};
|
2401 | });
|
2402 | }
|
2403 |
|
2404 | function onRemove(typename) {
|
2405 | return function() {
|
2406 | var on = this.__on;
|
2407 | if (!on) return;
|
2408 | for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
|
2409 | if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
|
2410 | this.removeEventListener(o.type, o.listener, o.options);
|
2411 | } else {
|
2412 | on[++i] = o;
|
2413 | }
|
2414 | }
|
2415 | if (++i) on.length = i;
|
2416 | else delete this.__on;
|
2417 | };
|
2418 | }
|
2419 |
|
2420 | function onAdd(typename, value, options) {
|
2421 | return function() {
|
2422 | var on = this.__on, o, listener = contextListener(value);
|
2423 | if (on) for (var j = 0, m = on.length; j < m; ++j) {
|
2424 | if ((o = on[j]).type === typename.type && o.name === typename.name) {
|
2425 | this.removeEventListener(o.type, o.listener, o.options);
|
2426 | this.addEventListener(o.type, o.listener = listener, o.options = options);
|
2427 | o.value = value;
|
2428 | return;
|
2429 | }
|
2430 | }
|
2431 | this.addEventListener(typename.type, listener, options);
|
2432 | o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options};
|
2433 | if (!on) this.__on = [o];
|
2434 | else on.push(o);
|
2435 | };
|
2436 | }
|
2437 |
|
2438 | function selection_on(typename, value, options) {
|
2439 | var typenames = parseTypenames(typename + ""), i, n = typenames.length, t;
|
2440 |
|
2441 | if (arguments.length < 2) {
|
2442 | var on = this.node().__on;
|
2443 | if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
|
2444 | for (i = 0, o = on[j]; i < n; ++i) {
|
2445 | if ((t = typenames[i]).type === o.type && t.name === o.name) {
|
2446 | return o.value;
|
2447 | }
|
2448 | }
|
2449 | }
|
2450 | return;
|
2451 | }
|
2452 |
|
2453 | on = value ? onAdd : onRemove;
|
2454 | for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options));
|
2455 | return this;
|
2456 | }
|
2457 |
|
2458 | function dispatchEvent(node, type, params) {
|
2459 | var window = defaultView(node),
|
2460 | event = window.CustomEvent;
|
2461 |
|
2462 | if (typeof event === "function") {
|
2463 | event = new event(type, params);
|
2464 | } else {
|
2465 | event = window.document.createEvent("Event");
|
2466 | if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
|
2467 | else event.initEvent(type, false, false);
|
2468 | }
|
2469 |
|
2470 | node.dispatchEvent(event);
|
2471 | }
|
2472 |
|
2473 | function dispatchConstant(type, params) {
|
2474 | return function() {
|
2475 | return dispatchEvent(this, type, params);
|
2476 | };
|
2477 | }
|
2478 |
|
2479 | function dispatchFunction(type, params) {
|
2480 | return function() {
|
2481 | return dispatchEvent(this, type, params.apply(this, arguments));
|
2482 | };
|
2483 | }
|
2484 |
|
2485 | function selection_dispatch(type, params) {
|
2486 | return this.each((typeof params === "function"
|
2487 | ? dispatchFunction
|
2488 | : dispatchConstant)(type, params));
|
2489 | }
|
2490 |
|
2491 | function* selection_iterator() {
|
2492 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
2493 | for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
|
2494 | if (node = group[i]) yield node;
|
2495 | }
|
2496 | }
|
2497 | }
|
2498 |
|
2499 | var root$1 = [null];
|
2500 |
|
2501 | function Selection$1(groups, parents) {
|
2502 | this._groups = groups;
|
2503 | this._parents = parents;
|
2504 | }
|
2505 |
|
2506 | function selection() {
|
2507 | return new Selection$1([[document.documentElement]], root$1);
|
2508 | }
|
2509 |
|
2510 | function selection_selection() {
|
2511 | return this;
|
2512 | }
|
2513 |
|
2514 | Selection$1.prototype = selection.prototype = {
|
2515 | constructor: Selection$1,
|
2516 | select: selection_select,
|
2517 | selectAll: selection_selectAll,
|
2518 | selectChild: selection_selectChild,
|
2519 | selectChildren: selection_selectChildren,
|
2520 | filter: selection_filter,
|
2521 | data: selection_data,
|
2522 | enter: selection_enter,
|
2523 | exit: selection_exit,
|
2524 | join: selection_join,
|
2525 | merge: selection_merge,
|
2526 | selection: selection_selection,
|
2527 | order: selection_order,
|
2528 | sort: selection_sort,
|
2529 | call: selection_call,
|
2530 | nodes: selection_nodes,
|
2531 | node: selection_node,
|
2532 | size: selection_size,
|
2533 | empty: selection_empty,
|
2534 | each: selection_each,
|
2535 | attr: selection_attr,
|
2536 | style: selection_style,
|
2537 | property: selection_property,
|
2538 | classed: selection_classed,
|
2539 | text: selection_text,
|
2540 | html: selection_html,
|
2541 | raise: selection_raise,
|
2542 | lower: selection_lower,
|
2543 | append: selection_append,
|
2544 | insert: selection_insert,
|
2545 | remove: selection_remove,
|
2546 | clone: selection_clone,
|
2547 | datum: selection_datum,
|
2548 | on: selection_on,
|
2549 | dispatch: selection_dispatch,
|
2550 | [Symbol.iterator]: selection_iterator
|
2551 | };
|
2552 |
|
2553 | function select(selector) {
|
2554 | return typeof selector === "string"
|
2555 | ? new Selection$1([[document.querySelector(selector)]], [document.documentElement])
|
2556 | : new Selection$1([[selector]], root$1);
|
2557 | }
|
2558 |
|
2559 | function create$1(name) {
|
2560 | return select(creator(name).call(document.documentElement));
|
2561 | }
|
2562 |
|
2563 | var nextId = 0;
|
2564 |
|
2565 | function local$1() {
|
2566 | return new Local;
|
2567 | }
|
2568 |
|
2569 | function Local() {
|
2570 | this._ = "@" + (++nextId).toString(36);
|
2571 | }
|
2572 |
|
2573 | Local.prototype = local$1.prototype = {
|
2574 | constructor: Local,
|
2575 | get: function(node) {
|
2576 | var id = this._;
|
2577 | while (!(id in node)) if (!(node = node.parentNode)) return;
|
2578 | return node[id];
|
2579 | },
|
2580 | set: function(node, value) {
|
2581 | return node[this._] = value;
|
2582 | },
|
2583 | remove: function(node) {
|
2584 | return this._ in node && delete node[this._];
|
2585 | },
|
2586 | toString: function() {
|
2587 | return this._;
|
2588 | }
|
2589 | };
|
2590 |
|
2591 | function sourceEvent(event) {
|
2592 | let sourceEvent;
|
2593 | while (sourceEvent = event.sourceEvent) event = sourceEvent;
|
2594 | return event;
|
2595 | }
|
2596 |
|
2597 | function pointer(event, node) {
|
2598 | event = sourceEvent(event);
|
2599 | if (node === undefined) node = event.currentTarget;
|
2600 | if (node) {
|
2601 | var svg = node.ownerSVGElement || node;
|
2602 | if (svg.createSVGPoint) {
|
2603 | var point = svg.createSVGPoint();
|
2604 | point.x = event.clientX, point.y = event.clientY;
|
2605 | point = point.matrixTransform(node.getScreenCTM().inverse());
|
2606 | return [point.x, point.y];
|
2607 | }
|
2608 | if (node.getBoundingClientRect) {
|
2609 | var rect = node.getBoundingClientRect();
|
2610 | return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
|
2611 | }
|
2612 | }
|
2613 | return [event.pageX, event.pageY];
|
2614 | }
|
2615 |
|
2616 | function pointers(events, node) {
|
2617 | if (events.target) {
|
2618 | events = sourceEvent(events);
|
2619 | if (node === undefined) node = events.currentTarget;
|
2620 | events = events.touches || [events];
|
2621 | }
|
2622 | return Array.from(events, event => pointer(event, node));
|
2623 | }
|
2624 |
|
2625 | function selectAll(selector) {
|
2626 | return typeof selector === "string"
|
2627 | ? new Selection$1([document.querySelectorAll(selector)], [document.documentElement])
|
2628 | : new Selection$1([array$4(selector)], root$1);
|
2629 | }
|
2630 |
|
2631 |
|
2632 |
|
2633 | const nonpassive = {passive: false};
|
2634 | const nonpassivecapture = {capture: true, passive: false};
|
2635 |
|
2636 | function nopropagation$2(event) {
|
2637 | event.stopImmediatePropagation();
|
2638 | }
|
2639 |
|
2640 | function noevent$2(event) {
|
2641 | event.preventDefault();
|
2642 | event.stopImmediatePropagation();
|
2643 | }
|
2644 |
|
2645 | function dragDisable(view) {
|
2646 | var root = view.document.documentElement,
|
2647 | selection = select(view).on("dragstart.drag", noevent$2, nonpassivecapture);
|
2648 | if ("onselectstart" in root) {
|
2649 | selection.on("selectstart.drag", noevent$2, nonpassivecapture);
|
2650 | } else {
|
2651 | root.__noselect = root.style.MozUserSelect;
|
2652 | root.style.MozUserSelect = "none";
|
2653 | }
|
2654 | }
|
2655 |
|
2656 | function yesdrag(view, noclick) {
|
2657 | var root = view.document.documentElement,
|
2658 | selection = select(view).on("dragstart.drag", null);
|
2659 | if (noclick) {
|
2660 | selection.on("click.drag", noevent$2, nonpassivecapture);
|
2661 | setTimeout(function() { selection.on("click.drag", null); }, 0);
|
2662 | }
|
2663 | if ("onselectstart" in root) {
|
2664 | selection.on("selectstart.drag", null);
|
2665 | } else {
|
2666 | root.style.MozUserSelect = root.__noselect;
|
2667 | delete root.__noselect;
|
2668 | }
|
2669 | }
|
2670 |
|
2671 | var constant$9 = x => () => x;
|
2672 |
|
2673 | function DragEvent(type, {
|
2674 | sourceEvent,
|
2675 | subject,
|
2676 | target,
|
2677 | identifier,
|
2678 | active,
|
2679 | x, y, dx, dy,
|
2680 | dispatch
|
2681 | }) {
|
2682 | Object.defineProperties(this, {
|
2683 | type: {value: type, enumerable: true, configurable: true},
|
2684 | sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
|
2685 | subject: {value: subject, enumerable: true, configurable: true},
|
2686 | target: {value: target, enumerable: true, configurable: true},
|
2687 | identifier: {value: identifier, enumerable: true, configurable: true},
|
2688 | active: {value: active, enumerable: true, configurable: true},
|
2689 | x: {value: x, enumerable: true, configurable: true},
|
2690 | y: {value: y, enumerable: true, configurable: true},
|
2691 | dx: {value: dx, enumerable: true, configurable: true},
|
2692 | dy: {value: dy, enumerable: true, configurable: true},
|
2693 | _: {value: dispatch}
|
2694 | });
|
2695 | }
|
2696 |
|
2697 | DragEvent.prototype.on = function() {
|
2698 | var value = this._.on.apply(this._, arguments);
|
2699 | return value === this._ ? this : value;
|
2700 | };
|
2701 |
|
2702 |
|
2703 | function defaultFilter$2(event) {
|
2704 | return !event.ctrlKey && !event.button;
|
2705 | }
|
2706 |
|
2707 | function defaultContainer() {
|
2708 | return this.parentNode;
|
2709 | }
|
2710 |
|
2711 | function defaultSubject(event, d) {
|
2712 | return d == null ? {x: event.x, y: event.y} : d;
|
2713 | }
|
2714 |
|
2715 | function defaultTouchable$2() {
|
2716 | return navigator.maxTouchPoints || ("ontouchstart" in this);
|
2717 | }
|
2718 |
|
2719 | function drag() {
|
2720 | var filter = defaultFilter$2,
|
2721 | container = defaultContainer,
|
2722 | subject = defaultSubject,
|
2723 | touchable = defaultTouchable$2,
|
2724 | gestures = {},
|
2725 | listeners = dispatch("start", "drag", "end"),
|
2726 | active = 0,
|
2727 | mousedownx,
|
2728 | mousedowny,
|
2729 | mousemoving,
|
2730 | touchending,
|
2731 | clickDistance2 = 0;
|
2732 |
|
2733 | function drag(selection) {
|
2734 | selection
|
2735 | .on("mousedown.drag", mousedowned)
|
2736 | .filter(touchable)
|
2737 | .on("touchstart.drag", touchstarted)
|
2738 | .on("touchmove.drag", touchmoved, nonpassive)
|
2739 | .on("touchend.drag touchcancel.drag", touchended)
|
2740 | .style("touch-action", "none")
|
2741 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
2742 | }
|
2743 |
|
2744 | function mousedowned(event, d) {
|
2745 | if (touchending || !filter.call(this, event, d)) return;
|
2746 | var gesture = beforestart(this, container.call(this, event, d), event, d, "mouse");
|
2747 | if (!gesture) return;
|
2748 | select(event.view)
|
2749 | .on("mousemove.drag", mousemoved, nonpassivecapture)
|
2750 | .on("mouseup.drag", mouseupped, nonpassivecapture);
|
2751 | dragDisable(event.view);
|
2752 | nopropagation$2(event);
|
2753 | mousemoving = false;
|
2754 | mousedownx = event.clientX;
|
2755 | mousedowny = event.clientY;
|
2756 | gesture("start", event);
|
2757 | }
|
2758 |
|
2759 | function mousemoved(event) {
|
2760 | noevent$2(event);
|
2761 | if (!mousemoving) {
|
2762 | var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny;
|
2763 | mousemoving = dx * dx + dy * dy > clickDistance2;
|
2764 | }
|
2765 | gestures.mouse("drag", event);
|
2766 | }
|
2767 |
|
2768 | function mouseupped(event) {
|
2769 | select(event.view).on("mousemove.drag mouseup.drag", null);
|
2770 | yesdrag(event.view, mousemoving);
|
2771 | noevent$2(event);
|
2772 | gestures.mouse("end", event);
|
2773 | }
|
2774 |
|
2775 | function touchstarted(event, d) {
|
2776 | if (!filter.call(this, event, d)) return;
|
2777 | var touches = event.changedTouches,
|
2778 | c = container.call(this, event, d),
|
2779 | n = touches.length, i, gesture;
|
2780 |
|
2781 | for (i = 0; i < n; ++i) {
|
2782 | if (gesture = beforestart(this, c, event, d, touches[i].identifier, touches[i])) {
|
2783 | nopropagation$2(event);
|
2784 | gesture("start", event, touches[i]);
|
2785 | }
|
2786 | }
|
2787 | }
|
2788 |
|
2789 | function touchmoved(event) {
|
2790 | var touches = event.changedTouches,
|
2791 | n = touches.length, i, gesture;
|
2792 |
|
2793 | for (i = 0; i < n; ++i) {
|
2794 | if (gesture = gestures[touches[i].identifier]) {
|
2795 | noevent$2(event);
|
2796 | gesture("drag", event, touches[i]);
|
2797 | }
|
2798 | }
|
2799 | }
|
2800 |
|
2801 | function touchended(event) {
|
2802 | var touches = event.changedTouches,
|
2803 | n = touches.length, i, gesture;
|
2804 |
|
2805 | if (touchending) clearTimeout(touchending);
|
2806 | touchending = setTimeout(function() { touchending = null; }, 500);
|
2807 | for (i = 0; i < n; ++i) {
|
2808 | if (gesture = gestures[touches[i].identifier]) {
|
2809 | nopropagation$2(event);
|
2810 | gesture("end", event, touches[i]);
|
2811 | }
|
2812 | }
|
2813 | }
|
2814 |
|
2815 | function beforestart(that, container, event, d, identifier, touch) {
|
2816 | var dispatch = listeners.copy(),
|
2817 | p = pointer(touch || event, container), dx, dy,
|
2818 | s;
|
2819 |
|
2820 | if ((s = subject.call(that, new DragEvent("beforestart", {
|
2821 | sourceEvent: event,
|
2822 | target: drag,
|
2823 | identifier,
|
2824 | active,
|
2825 | x: p[0],
|
2826 | y: p[1],
|
2827 | dx: 0,
|
2828 | dy: 0,
|
2829 | dispatch
|
2830 | }), d)) == null) return;
|
2831 |
|
2832 | dx = s.x - p[0] || 0;
|
2833 | dy = s.y - p[1] || 0;
|
2834 |
|
2835 | return function gesture(type, event, touch) {
|
2836 | var p0 = p, n;
|
2837 | switch (type) {
|
2838 | case "start": gestures[identifier] = gesture, n = active++; break;
|
2839 | case "end": delete gestures[identifier], --active;
|
2840 | case "drag": p = pointer(touch || event, container), n = active; break;
|
2841 | }
|
2842 | dispatch.call(
|
2843 | type,
|
2844 | that,
|
2845 | new DragEvent(type, {
|
2846 | sourceEvent: event,
|
2847 | subject: s,
|
2848 | target: drag,
|
2849 | identifier,
|
2850 | active: n,
|
2851 | x: p[0] + dx,
|
2852 | y: p[1] + dy,
|
2853 | dx: p[0] - p0[0],
|
2854 | dy: p[1] - p0[1],
|
2855 | dispatch
|
2856 | }),
|
2857 | d
|
2858 | );
|
2859 | };
|
2860 | }
|
2861 |
|
2862 | drag.filter = function(_) {
|
2863 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), drag) : filter;
|
2864 | };
|
2865 |
|
2866 | drag.container = function(_) {
|
2867 | return arguments.length ? (container = typeof _ === "function" ? _ : constant$9(_), drag) : container;
|
2868 | };
|
2869 |
|
2870 | drag.subject = function(_) {
|
2871 | return arguments.length ? (subject = typeof _ === "function" ? _ : constant$9(_), drag) : subject;
|
2872 | };
|
2873 |
|
2874 | drag.touchable = function(_) {
|
2875 | return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$9(!!_), drag) : touchable;
|
2876 | };
|
2877 |
|
2878 | drag.on = function() {
|
2879 | var value = listeners.on.apply(listeners, arguments);
|
2880 | return value === listeners ? drag : value;
|
2881 | };
|
2882 |
|
2883 | drag.clickDistance = function(_) {
|
2884 | return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
|
2885 | };
|
2886 |
|
2887 | return drag;
|
2888 | }
|
2889 |
|
2890 | function define(constructor, factory, prototype) {
|
2891 | constructor.prototype = factory.prototype = prototype;
|
2892 | prototype.constructor = constructor;
|
2893 | }
|
2894 |
|
2895 | function extend(parent, definition) {
|
2896 | var prototype = Object.create(parent.prototype);
|
2897 | for (var key in definition) prototype[key] = definition[key];
|
2898 | return prototype;
|
2899 | }
|
2900 |
|
2901 | function Color() {}
|
2902 |
|
2903 | var darker = 0.7;
|
2904 | var brighter = 1 / darker;
|
2905 |
|
2906 | var reI = "\\s*([+-]?\\d+)\\s*",
|
2907 | reN = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",
|
2908 | reP = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
|
2909 | reHex = /^#([0-9a-f]{3,8})$/,
|
2910 | reRgbInteger = new RegExp(`^rgb\\(${reI},${reI},${reI}\\)$`),
|
2911 | reRgbPercent = new RegExp(`^rgb\\(${reP},${reP},${reP}\\)$`),
|
2912 | reRgbaInteger = new RegExp(`^rgba\\(${reI},${reI},${reI},${reN}\\)$`),
|
2913 | reRgbaPercent = new RegExp(`^rgba\\(${reP},${reP},${reP},${reN}\\)$`),
|
2914 | reHslPercent = new RegExp(`^hsl\\(${reN},${reP},${reP}\\)$`),
|
2915 | reHslaPercent = new RegExp(`^hsla\\(${reN},${reP},${reP},${reN}\\)$`);
|
2916 |
|
2917 | var named = {
|
2918 | aliceblue: 0xf0f8ff,
|
2919 | antiquewhite: 0xfaebd7,
|
2920 | aqua: 0x00ffff,
|
2921 | aquamarine: 0x7fffd4,
|
2922 | azure: 0xf0ffff,
|
2923 | beige: 0xf5f5dc,
|
2924 | bisque: 0xffe4c4,
|
2925 | black: 0x000000,
|
2926 | blanchedalmond: 0xffebcd,
|
2927 | blue: 0x0000ff,
|
2928 | blueviolet: 0x8a2be2,
|
2929 | brown: 0xa52a2a,
|
2930 | burlywood: 0xdeb887,
|
2931 | cadetblue: 0x5f9ea0,
|
2932 | chartreuse: 0x7fff00,
|
2933 | chocolate: 0xd2691e,
|
2934 | coral: 0xff7f50,
|
2935 | cornflowerblue: 0x6495ed,
|
2936 | cornsilk: 0xfff8dc,
|
2937 | crimson: 0xdc143c,
|
2938 | cyan: 0x00ffff,
|
2939 | darkblue: 0x00008b,
|
2940 | darkcyan: 0x008b8b,
|
2941 | darkgoldenrod: 0xb8860b,
|
2942 | darkgray: 0xa9a9a9,
|
2943 | darkgreen: 0x006400,
|
2944 | darkgrey: 0xa9a9a9,
|
2945 | darkkhaki: 0xbdb76b,
|
2946 | darkmagenta: 0x8b008b,
|
2947 | darkolivegreen: 0x556b2f,
|
2948 | darkorange: 0xff8c00,
|
2949 | darkorchid: 0x9932cc,
|
2950 | darkred: 0x8b0000,
|
2951 | darksalmon: 0xe9967a,
|
2952 | darkseagreen: 0x8fbc8f,
|
2953 | darkslateblue: 0x483d8b,
|
2954 | darkslategray: 0x2f4f4f,
|
2955 | darkslategrey: 0x2f4f4f,
|
2956 | darkturquoise: 0x00ced1,
|
2957 | darkviolet: 0x9400d3,
|
2958 | deeppink: 0xff1493,
|
2959 | deepskyblue: 0x00bfff,
|
2960 | dimgray: 0x696969,
|
2961 | dimgrey: 0x696969,
|
2962 | dodgerblue: 0x1e90ff,
|
2963 | firebrick: 0xb22222,
|
2964 | floralwhite: 0xfffaf0,
|
2965 | forestgreen: 0x228b22,
|
2966 | fuchsia: 0xff00ff,
|
2967 | gainsboro: 0xdcdcdc,
|
2968 | ghostwhite: 0xf8f8ff,
|
2969 | gold: 0xffd700,
|
2970 | goldenrod: 0xdaa520,
|
2971 | gray: 0x808080,
|
2972 | green: 0x008000,
|
2973 | greenyellow: 0xadff2f,
|
2974 | grey: 0x808080,
|
2975 | honeydew: 0xf0fff0,
|
2976 | hotpink: 0xff69b4,
|
2977 | indianred: 0xcd5c5c,
|
2978 | indigo: 0x4b0082,
|
2979 | ivory: 0xfffff0,
|
2980 | khaki: 0xf0e68c,
|
2981 | lavender: 0xe6e6fa,
|
2982 | lavenderblush: 0xfff0f5,
|
2983 | lawngreen: 0x7cfc00,
|
2984 | lemonchiffon: 0xfffacd,
|
2985 | lightblue: 0xadd8e6,
|
2986 | lightcoral: 0xf08080,
|
2987 | lightcyan: 0xe0ffff,
|
2988 | lightgoldenrodyellow: 0xfafad2,
|
2989 | lightgray: 0xd3d3d3,
|
2990 | lightgreen: 0x90ee90,
|
2991 | lightgrey: 0xd3d3d3,
|
2992 | lightpink: 0xffb6c1,
|
2993 | lightsalmon: 0xffa07a,
|
2994 | lightseagreen: 0x20b2aa,
|
2995 | lightskyblue: 0x87cefa,
|
2996 | lightslategray: 0x778899,
|
2997 | lightslategrey: 0x778899,
|
2998 | lightsteelblue: 0xb0c4de,
|
2999 | lightyellow: 0xffffe0,
|
3000 | lime: 0x00ff00,
|
3001 | limegreen: 0x32cd32,
|
3002 | linen: 0xfaf0e6,
|
3003 | magenta: 0xff00ff,
|
3004 | maroon: 0x800000,
|
3005 | mediumaquamarine: 0x66cdaa,
|
3006 | mediumblue: 0x0000cd,
|
3007 | mediumorchid: 0xba55d3,
|
3008 | mediumpurple: 0x9370db,
|
3009 | mediumseagreen: 0x3cb371,
|
3010 | mediumslateblue: 0x7b68ee,
|
3011 | mediumspringgreen: 0x00fa9a,
|
3012 | mediumturquoise: 0x48d1cc,
|
3013 | mediumvioletred: 0xc71585,
|
3014 | midnightblue: 0x191970,
|
3015 | mintcream: 0xf5fffa,
|
3016 | mistyrose: 0xffe4e1,
|
3017 | moccasin: 0xffe4b5,
|
3018 | navajowhite: 0xffdead,
|
3019 | navy: 0x000080,
|
3020 | oldlace: 0xfdf5e6,
|
3021 | olive: 0x808000,
|
3022 | olivedrab: 0x6b8e23,
|
3023 | orange: 0xffa500,
|
3024 | orangered: 0xff4500,
|
3025 | orchid: 0xda70d6,
|
3026 | palegoldenrod: 0xeee8aa,
|
3027 | palegreen: 0x98fb98,
|
3028 | paleturquoise: 0xafeeee,
|
3029 | palevioletred: 0xdb7093,
|
3030 | papayawhip: 0xffefd5,
|
3031 | peachpuff: 0xffdab9,
|
3032 | peru: 0xcd853f,
|
3033 | pink: 0xffc0cb,
|
3034 | plum: 0xdda0dd,
|
3035 | powderblue: 0xb0e0e6,
|
3036 | purple: 0x800080,
|
3037 | rebeccapurple: 0x663399,
|
3038 | red: 0xff0000,
|
3039 | rosybrown: 0xbc8f8f,
|
3040 | royalblue: 0x4169e1,
|
3041 | saddlebrown: 0x8b4513,
|
3042 | salmon: 0xfa8072,
|
3043 | sandybrown: 0xf4a460,
|
3044 | seagreen: 0x2e8b57,
|
3045 | seashell: 0xfff5ee,
|
3046 | sienna: 0xa0522d,
|
3047 | silver: 0xc0c0c0,
|
3048 | skyblue: 0x87ceeb,
|
3049 | slateblue: 0x6a5acd,
|
3050 | slategray: 0x708090,
|
3051 | slategrey: 0x708090,
|
3052 | snow: 0xfffafa,
|
3053 | springgreen: 0x00ff7f,
|
3054 | steelblue: 0x4682b4,
|
3055 | tan: 0xd2b48c,
|
3056 | teal: 0x008080,
|
3057 | thistle: 0xd8bfd8,
|
3058 | tomato: 0xff6347,
|
3059 | turquoise: 0x40e0d0,
|
3060 | violet: 0xee82ee,
|
3061 | wheat: 0xf5deb3,
|
3062 | white: 0xffffff,
|
3063 | whitesmoke: 0xf5f5f5,
|
3064 | yellow: 0xffff00,
|
3065 | yellowgreen: 0x9acd32
|
3066 | };
|
3067 |
|
3068 | define(Color, color, {
|
3069 | copy(channels) {
|
3070 | return Object.assign(new this.constructor, this, channels);
|
3071 | },
|
3072 | displayable() {
|
3073 | return this.rgb().displayable();
|
3074 | },
|
3075 | hex: color_formatHex,
|
3076 | formatHex: color_formatHex,
|
3077 | formatHex8: color_formatHex8,
|
3078 | formatHsl: color_formatHsl,
|
3079 | formatRgb: color_formatRgb,
|
3080 | toString: color_formatRgb
|
3081 | });
|
3082 |
|
3083 | function color_formatHex() {
|
3084 | return this.rgb().formatHex();
|
3085 | }
|
3086 |
|
3087 | function color_formatHex8() {
|
3088 | return this.rgb().formatHex8();
|
3089 | }
|
3090 |
|
3091 | function color_formatHsl() {
|
3092 | return hslConvert(this).formatHsl();
|
3093 | }
|
3094 |
|
3095 | function color_formatRgb() {
|
3096 | return this.rgb().formatRgb();
|
3097 | }
|
3098 |
|
3099 | function color(format) {
|
3100 | var m, l;
|
3101 | format = (format + "").trim().toLowerCase();
|
3102 | return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m)
|
3103 | : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)
|
3104 | : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff)
|
3105 | : 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)
|
3106 | : null)
|
3107 | : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1)
|
3108 | : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1)
|
3109 | : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4])
|
3110 | : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4])
|
3111 | : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1)
|
3112 | : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4])
|
3113 | : named.hasOwnProperty(format) ? rgbn(named[format])
|
3114 | : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
|
3115 | : null;
|
3116 | }
|
3117 |
|
3118 | function rgbn(n) {
|
3119 | return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
|
3120 | }
|
3121 |
|
3122 | function rgba(r, g, b, a) {
|
3123 | if (a <= 0) r = g = b = NaN;
|
3124 | return new Rgb(r, g, b, a);
|
3125 | }
|
3126 |
|
3127 | function rgbConvert(o) {
|
3128 | if (!(o instanceof Color)) o = color(o);
|
3129 | if (!o) return new Rgb;
|
3130 | o = o.rgb();
|
3131 | return new Rgb(o.r, o.g, o.b, o.opacity);
|
3132 | }
|
3133 |
|
3134 | function rgb(r, g, b, opacity) {
|
3135 | return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
|
3136 | }
|
3137 |
|
3138 | function Rgb(r, g, b, opacity) {
|
3139 | this.r = +r;
|
3140 | this.g = +g;
|
3141 | this.b = +b;
|
3142 | this.opacity = +opacity;
|
3143 | }
|
3144 |
|
3145 | define(Rgb, rgb, extend(Color, {
|
3146 | brighter(k) {
|
3147 | k = k == null ? brighter : Math.pow(brighter, k);
|
3148 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
3149 | },
|
3150 | darker(k) {
|
3151 | k = k == null ? darker : Math.pow(darker, k);
|
3152 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
3153 | },
|
3154 | rgb() {
|
3155 | return this;
|
3156 | },
|
3157 | clamp() {
|
3158 | return new Rgb(clampi(this.r), clampi(this.g), clampi(this.b), clampa(this.opacity));
|
3159 | },
|
3160 | displayable() {
|
3161 | return (-0.5 <= this.r && this.r < 255.5)
|
3162 | && (-0.5 <= this.g && this.g < 255.5)
|
3163 | && (-0.5 <= this.b && this.b < 255.5)
|
3164 | && (0 <= this.opacity && this.opacity <= 1);
|
3165 | },
|
3166 | hex: rgb_formatHex,
|
3167 | formatHex: rgb_formatHex,
|
3168 | formatHex8: rgb_formatHex8,
|
3169 | formatRgb: rgb_formatRgb,
|
3170 | toString: rgb_formatRgb
|
3171 | }));
|
3172 |
|
3173 | function rgb_formatHex() {
|
3174 | return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}`;
|
3175 | }
|
3176 |
|
3177 | function rgb_formatHex8() {
|
3178 | return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}${hex((isNaN(this.opacity) ? 1 : this.opacity) * 255)}`;
|
3179 | }
|
3180 |
|
3181 | function rgb_formatRgb() {
|
3182 | const a = clampa(this.opacity);
|
3183 | return `${a === 1 ? "rgb(" : "rgba("}${clampi(this.r)}, ${clampi(this.g)}, ${clampi(this.b)}${a === 1 ? ")" : `, ${a})`}`;
|
3184 | }
|
3185 |
|
3186 | function clampa(opacity) {
|
3187 | return isNaN(opacity) ? 1 : Math.max(0, Math.min(1, opacity));
|
3188 | }
|
3189 |
|
3190 | function clampi(value) {
|
3191 | return Math.max(0, Math.min(255, Math.round(value) || 0));
|
3192 | }
|
3193 |
|
3194 | function hex(value) {
|
3195 | value = clampi(value);
|
3196 | return (value < 16 ? "0" : "") + value.toString(16);
|
3197 | }
|
3198 |
|
3199 | function hsla(h, s, l, a) {
|
3200 | if (a <= 0) h = s = l = NaN;
|
3201 | else if (l <= 0 || l >= 1) h = s = NaN;
|
3202 | else if (s <= 0) h = NaN;
|
3203 | return new Hsl(h, s, l, a);
|
3204 | }
|
3205 |
|
3206 | function hslConvert(o) {
|
3207 | if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
|
3208 | if (!(o instanceof Color)) o = color(o);
|
3209 | if (!o) return new Hsl;
|
3210 | if (o instanceof Hsl) return o;
|
3211 | o = o.rgb();
|
3212 | var r = o.r / 255,
|
3213 | g = o.g / 255,
|
3214 | b = o.b / 255,
|
3215 | min = Math.min(r, g, b),
|
3216 | max = Math.max(r, g, b),
|
3217 | h = NaN,
|
3218 | s = max - min,
|
3219 | l = (max + min) / 2;
|
3220 | if (s) {
|
3221 | if (r === max) h = (g - b) / s + (g < b) * 6;
|
3222 | else if (g === max) h = (b - r) / s + 2;
|
3223 | else h = (r - g) / s + 4;
|
3224 | s /= l < 0.5 ? max + min : 2 - max - min;
|
3225 | h *= 60;
|
3226 | } else {
|
3227 | s = l > 0 && l < 1 ? 0 : h;
|
3228 | }
|
3229 | return new Hsl(h, s, l, o.opacity);
|
3230 | }
|
3231 |
|
3232 | function hsl$2(h, s, l, opacity) {
|
3233 | return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
|
3234 | }
|
3235 |
|
3236 | function Hsl(h, s, l, opacity) {
|
3237 | this.h = +h;
|
3238 | this.s = +s;
|
3239 | this.l = +l;
|
3240 | this.opacity = +opacity;
|
3241 | }
|
3242 |
|
3243 | define(Hsl, hsl$2, extend(Color, {
|
3244 | brighter(k) {
|
3245 | k = k == null ? brighter : Math.pow(brighter, k);
|
3246 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
3247 | },
|
3248 | darker(k) {
|
3249 | k = k == null ? darker : Math.pow(darker, k);
|
3250 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
3251 | },
|
3252 | rgb() {
|
3253 | var h = this.h % 360 + (this.h < 0) * 360,
|
3254 | s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
|
3255 | l = this.l,
|
3256 | m2 = l + (l < 0.5 ? l : 1 - l) * s,
|
3257 | m1 = 2 * l - m2;
|
3258 | return new Rgb(
|
3259 | hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
|
3260 | hsl2rgb(h, m1, m2),
|
3261 | hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
|
3262 | this.opacity
|
3263 | );
|
3264 | },
|
3265 | clamp() {
|
3266 | return new Hsl(clamph(this.h), clampt(this.s), clampt(this.l), clampa(this.opacity));
|
3267 | },
|
3268 | displayable() {
|
3269 | return (0 <= this.s && this.s <= 1 || isNaN(this.s))
|
3270 | && (0 <= this.l && this.l <= 1)
|
3271 | && (0 <= this.opacity && this.opacity <= 1);
|
3272 | },
|
3273 | formatHsl() {
|
3274 | const a = clampa(this.opacity);
|
3275 | return `${a === 1 ? "hsl(" : "hsla("}${clamph(this.h)}, ${clampt(this.s) * 100}%, ${clampt(this.l) * 100}%${a === 1 ? ")" : `, ${a})`}`;
|
3276 | }
|
3277 | }));
|
3278 |
|
3279 | function clamph(value) {
|
3280 | value = (value || 0) % 360;
|
3281 | return value < 0 ? value + 360 : value;
|
3282 | }
|
3283 |
|
3284 | function clampt(value) {
|
3285 | return Math.max(0, Math.min(1, value || 0));
|
3286 | }
|
3287 |
|
3288 |
|
3289 | function hsl2rgb(h, m1, m2) {
|
3290 | return (h < 60 ? m1 + (m2 - m1) * h / 60
|
3291 | : h < 180 ? m2
|
3292 | : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
|
3293 | : m1) * 255;
|
3294 | }
|
3295 |
|
3296 | const radians$1 = Math.PI / 180;
|
3297 | const degrees$2 = 180 / Math.PI;
|
3298 |
|
3299 |
|
3300 | const K = 18,
|
3301 | Xn = 0.96422,
|
3302 | Yn = 1,
|
3303 | Zn = 0.82521,
|
3304 | t0$1 = 4 / 29,
|
3305 | t1$1 = 6 / 29,
|
3306 | t2 = 3 * t1$1 * t1$1,
|
3307 | t3 = t1$1 * t1$1 * t1$1;
|
3308 |
|
3309 | function labConvert(o) {
|
3310 | if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
|
3311 | if (o instanceof Hcl) return hcl2lab(o);
|
3312 | if (!(o instanceof Rgb)) o = rgbConvert(o);
|
3313 | var r = rgb2lrgb(o.r),
|
3314 | g = rgb2lrgb(o.g),
|
3315 | b = rgb2lrgb(o.b),
|
3316 | y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
|
3317 | if (r === g && g === b) x = z = y; else {
|
3318 | x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
|
3319 | z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
|
3320 | }
|
3321 | return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
|
3322 | }
|
3323 |
|
3324 | function gray(l, opacity) {
|
3325 | return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
|
3326 | }
|
3327 |
|
3328 | function lab$1(l, a, b, opacity) {
|
3329 | return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
|
3330 | }
|
3331 |
|
3332 | function Lab(l, a, b, opacity) {
|
3333 | this.l = +l;
|
3334 | this.a = +a;
|
3335 | this.b = +b;
|
3336 | this.opacity = +opacity;
|
3337 | }
|
3338 |
|
3339 | define(Lab, lab$1, extend(Color, {
|
3340 | brighter(k) {
|
3341 | return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
|
3342 | },
|
3343 | darker(k) {
|
3344 | return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
|
3345 | },
|
3346 | rgb() {
|
3347 | var y = (this.l + 16) / 116,
|
3348 | x = isNaN(this.a) ? y : y + this.a / 500,
|
3349 | z = isNaN(this.b) ? y : y - this.b / 200;
|
3350 | x = Xn * lab2xyz(x);
|
3351 | y = Yn * lab2xyz(y);
|
3352 | z = Zn * lab2xyz(z);
|
3353 | return new Rgb(
|
3354 | lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
|
3355 | lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
|
3356 | lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
|
3357 | this.opacity
|
3358 | );
|
3359 | }
|
3360 | }));
|
3361 |
|
3362 | function xyz2lab(t) {
|
3363 | return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0$1;
|
3364 | }
|
3365 |
|
3366 | function lab2xyz(t) {
|
3367 | return t > t1$1 ? t * t * t : t2 * (t - t0$1);
|
3368 | }
|
3369 |
|
3370 | function lrgb2rgb(x) {
|
3371 | return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
|
3372 | }
|
3373 |
|
3374 | function rgb2lrgb(x) {
|
3375 | return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
|
3376 | }
|
3377 |
|
3378 | function hclConvert(o) {
|
3379 | if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
|
3380 | if (!(o instanceof Lab)) o = labConvert(o);
|
3381 | if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
|
3382 | var h = Math.atan2(o.b, o.a) * degrees$2;
|
3383 | return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
|
3384 | }
|
3385 |
|
3386 | function lch(l, c, h, opacity) {
|
3387 | return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
|
3388 | }
|
3389 |
|
3390 | function hcl$2(h, c, l, opacity) {
|
3391 | return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
|
3392 | }
|
3393 |
|
3394 | function Hcl(h, c, l, opacity) {
|
3395 | this.h = +h;
|
3396 | this.c = +c;
|
3397 | this.l = +l;
|
3398 | this.opacity = +opacity;
|
3399 | }
|
3400 |
|
3401 | function hcl2lab(o) {
|
3402 | if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
|
3403 | var h = o.h * radians$1;
|
3404 | return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
|
3405 | }
|
3406 |
|
3407 | define(Hcl, hcl$2, extend(Color, {
|
3408 | brighter(k) {
|
3409 | return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
|
3410 | },
|
3411 | darker(k) {
|
3412 | return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
|
3413 | },
|
3414 | rgb() {
|
3415 | return hcl2lab(this).rgb();
|
3416 | }
|
3417 | }));
|
3418 |
|
3419 | var A = -0.14861,
|
3420 | B$1 = +1.78277,
|
3421 | C = -0.29227,
|
3422 | D$1 = -0.90649,
|
3423 | E = +1.97294,
|
3424 | ED = E * D$1,
|
3425 | EB = E * B$1,
|
3426 | BC_DA = B$1 * C - D$1 * A;
|
3427 |
|
3428 | function cubehelixConvert(o) {
|
3429 | if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
|
3430 | if (!(o instanceof Rgb)) o = rgbConvert(o);
|
3431 | var r = o.r / 255,
|
3432 | g = o.g / 255,
|
3433 | b = o.b / 255,
|
3434 | l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
|
3435 | bl = b - l,
|
3436 | k = (E * (g - l) - C * bl) / D$1,
|
3437 | s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)),
|
3438 | h = s ? Math.atan2(k, bl) * degrees$2 - 120 : NaN;
|
3439 | return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
|
3440 | }
|
3441 |
|
3442 | function cubehelix$3(h, s, l, opacity) {
|
3443 | return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
|
3444 | }
|
3445 |
|
3446 | function Cubehelix(h, s, l, opacity) {
|
3447 | this.h = +h;
|
3448 | this.s = +s;
|
3449 | this.l = +l;
|
3450 | this.opacity = +opacity;
|
3451 | }
|
3452 |
|
3453 | define(Cubehelix, cubehelix$3, extend(Color, {
|
3454 | brighter(k) {
|
3455 | k = k == null ? brighter : Math.pow(brighter, k);
|
3456 | return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
|
3457 | },
|
3458 | darker(k) {
|
3459 | k = k == null ? darker : Math.pow(darker, k);
|
3460 | return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
|
3461 | },
|
3462 | rgb() {
|
3463 | var h = isNaN(this.h) ? 0 : (this.h + 120) * radians$1,
|
3464 | l = +this.l,
|
3465 | a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
|
3466 | cosh = Math.cos(h),
|
3467 | sinh = Math.sin(h);
|
3468 | return new Rgb(
|
3469 | 255 * (l + a * (A * cosh + B$1 * sinh)),
|
3470 | 255 * (l + a * (C * cosh + D$1 * sinh)),
|
3471 | 255 * (l + a * (E * cosh)),
|
3472 | this.opacity
|
3473 | );
|
3474 | }
|
3475 | }));
|
3476 |
|
3477 | function basis$1(t1, v0, v1, v2, v3) {
|
3478 | var t2 = t1 * t1, t3 = t2 * t1;
|
3479 | return ((1 - 3 * t1 + 3 * t2 - t3) * v0
|
3480 | + (4 - 6 * t2 + 3 * t3) * v1
|
3481 | + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
|
3482 | + t3 * v3) / 6;
|
3483 | }
|
3484 |
|
3485 | function basis$2(values) {
|
3486 | var n = values.length - 1;
|
3487 | return function(t) {
|
3488 | var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
|
3489 | v1 = values[i],
|
3490 | v2 = values[i + 1],
|
3491 | v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
|
3492 | v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
|
3493 | return basis$1((t - i / n) * n, v0, v1, v2, v3);
|
3494 | };
|
3495 | }
|
3496 |
|
3497 | function basisClosed$1(values) {
|
3498 | var n = values.length;
|
3499 | return function(t) {
|
3500 | var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
|
3501 | v0 = values[(i + n - 1) % n],
|
3502 | v1 = values[i % n],
|
3503 | v2 = values[(i + 1) % n],
|
3504 | v3 = values[(i + 2) % n];
|
3505 | return basis$1((t - i / n) * n, v0, v1, v2, v3);
|
3506 | };
|
3507 | }
|
3508 |
|
3509 | var constant$8 = x => () => x;
|
3510 |
|
3511 | function linear$2(a, d) {
|
3512 | return function(t) {
|
3513 | return a + t * d;
|
3514 | };
|
3515 | }
|
3516 |
|
3517 | function exponential$1(a, b, y) {
|
3518 | return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
|
3519 | return Math.pow(a + t * b, y);
|
3520 | };
|
3521 | }
|
3522 |
|
3523 | function hue$1(a, b) {
|
3524 | var d = b - a;
|
3525 | return d ? linear$2(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$8(isNaN(a) ? b : a);
|
3526 | }
|
3527 |
|
3528 | function gamma$1(y) {
|
3529 | return (y = +y) === 1 ? nogamma : function(a, b) {
|
3530 | return b - a ? exponential$1(a, b, y) : constant$8(isNaN(a) ? b : a);
|
3531 | };
|
3532 | }
|
3533 |
|
3534 | function nogamma(a, b) {
|
3535 | var d = b - a;
|
3536 | return d ? linear$2(a, d) : constant$8(isNaN(a) ? b : a);
|
3537 | }
|
3538 |
|
3539 | var interpolateRgb = (function rgbGamma(y) {
|
3540 | var color = gamma$1(y);
|
3541 |
|
3542 | function rgb$1(start, end) {
|
3543 | var r = color((start = rgb(start)).r, (end = rgb(end)).r),
|
3544 | g = color(start.g, end.g),
|
3545 | b = color(start.b, end.b),
|
3546 | opacity = nogamma(start.opacity, end.opacity);
|
3547 | return function(t) {
|
3548 | start.r = r(t);
|
3549 | start.g = g(t);
|
3550 | start.b = b(t);
|
3551 | start.opacity = opacity(t);
|
3552 | return start + "";
|
3553 | };
|
3554 | }
|
3555 |
|
3556 | rgb$1.gamma = rgbGamma;
|
3557 |
|
3558 | return rgb$1;
|
3559 | })(1);
|
3560 |
|
3561 | function rgbSpline(spline) {
|
3562 | return function(colors) {
|
3563 | var n = colors.length,
|
3564 | r = new Array(n),
|
3565 | g = new Array(n),
|
3566 | b = new Array(n),
|
3567 | i, color;
|
3568 | for (i = 0; i < n; ++i) {
|
3569 | color = rgb(colors[i]);
|
3570 | r[i] = color.r || 0;
|
3571 | g[i] = color.g || 0;
|
3572 | b[i] = color.b || 0;
|
3573 | }
|
3574 | r = spline(r);
|
3575 | g = spline(g);
|
3576 | b = spline(b);
|
3577 | color.opacity = 1;
|
3578 | return function(t) {
|
3579 | color.r = r(t);
|
3580 | color.g = g(t);
|
3581 | color.b = b(t);
|
3582 | return color + "";
|
3583 | };
|
3584 | };
|
3585 | }
|
3586 |
|
3587 | var rgbBasis = rgbSpline(basis$2);
|
3588 | var rgbBasisClosed = rgbSpline(basisClosed$1);
|
3589 |
|
3590 | function numberArray(a, b) {
|
3591 | if (!b) b = [];
|
3592 | var n = a ? Math.min(b.length, a.length) : 0,
|
3593 | c = b.slice(),
|
3594 | i;
|
3595 | return function(t) {
|
3596 | for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
|
3597 | return c;
|
3598 | };
|
3599 | }
|
3600 |
|
3601 | function isNumberArray(x) {
|
3602 | return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
3603 | }
|
3604 |
|
3605 | function array$3(a, b) {
|
3606 | return (isNumberArray(b) ? numberArray : genericArray)(a, b);
|
3607 | }
|
3608 |
|
3609 | function genericArray(a, b) {
|
3610 | var nb = b ? b.length : 0,
|
3611 | na = a ? Math.min(nb, a.length) : 0,
|
3612 | x = new Array(na),
|
3613 | c = new Array(nb),
|
3614 | i;
|
3615 |
|
3616 | for (i = 0; i < na; ++i) x[i] = interpolate$2(a[i], b[i]);
|
3617 | for (; i < nb; ++i) c[i] = b[i];
|
3618 |
|
3619 | return function(t) {
|
3620 | for (i = 0; i < na; ++i) c[i] = x[i](t);
|
3621 | return c;
|
3622 | };
|
3623 | }
|
3624 |
|
3625 | function date$1(a, b) {
|
3626 | var d = new Date;
|
3627 | return a = +a, b = +b, function(t) {
|
3628 | return d.setTime(a * (1 - t) + b * t), d;
|
3629 | };
|
3630 | }
|
3631 |
|
3632 | function interpolateNumber(a, b) {
|
3633 | return a = +a, b = +b, function(t) {
|
3634 | return a * (1 - t) + b * t;
|
3635 | };
|
3636 | }
|
3637 |
|
3638 | function object$1(a, b) {
|
3639 | var i = {},
|
3640 | c = {},
|
3641 | k;
|
3642 |
|
3643 | if (a === null || typeof a !== "object") a = {};
|
3644 | if (b === null || typeof b !== "object") b = {};
|
3645 |
|
3646 | for (k in b) {
|
3647 | if (k in a) {
|
3648 | i[k] = interpolate$2(a[k], b[k]);
|
3649 | } else {
|
3650 | c[k] = b[k];
|
3651 | }
|
3652 | }
|
3653 |
|
3654 | return function(t) {
|
3655 | for (k in i) c[k] = i[k](t);
|
3656 | return c;
|
3657 | };
|
3658 | }
|
3659 |
|
3660 | var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
|
3661 | reB = new RegExp(reA.source, "g");
|
3662 |
|
3663 | function zero(b) {
|
3664 | return function() {
|
3665 | return b;
|
3666 | };
|
3667 | }
|
3668 |
|
3669 | function one(b) {
|
3670 | return function(t) {
|
3671 | return b(t) + "";
|
3672 | };
|
3673 | }
|
3674 |
|
3675 | function interpolateString(a, b) {
|
3676 | var bi = reA.lastIndex = reB.lastIndex = 0,
|
3677 | am,
|
3678 | bm,
|
3679 | bs,
|
3680 | i = -1,
|
3681 | s = [],
|
3682 | q = [];
|
3683 |
|
3684 |
|
3685 | a = a + "", b = b + "";
|
3686 |
|
3687 |
|
3688 | while ((am = reA.exec(a))
|
3689 | && (bm = reB.exec(b))) {
|
3690 | if ((bs = bm.index) > bi) {
|
3691 | bs = b.slice(bi, bs);
|
3692 | if (s[i]) s[i] += bs;
|
3693 | else s[++i] = bs;
|
3694 | }
|
3695 | if ((am = am[0]) === (bm = bm[0])) {
|
3696 | if (s[i]) s[i] += bm;
|
3697 | else s[++i] = bm;
|
3698 | } else {
|
3699 | s[++i] = null;
|
3700 | q.push({i: i, x: interpolateNumber(am, bm)});
|
3701 | }
|
3702 | bi = reB.lastIndex;
|
3703 | }
|
3704 |
|
3705 |
|
3706 | if (bi < b.length) {
|
3707 | bs = b.slice(bi);
|
3708 | if (s[i]) s[i] += bs;
|
3709 | else s[++i] = bs;
|
3710 | }
|
3711 |
|
3712 |
|
3713 |
|
3714 | return s.length < 2 ? (q[0]
|
3715 | ? one(q[0].x)
|
3716 | : zero(b))
|
3717 | : (b = q.length, function(t) {
|
3718 | for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
|
3719 | return s.join("");
|
3720 | });
|
3721 | }
|
3722 |
|
3723 | function interpolate$2(a, b) {
|
3724 | var t = typeof b, c;
|
3725 | return b == null || t === "boolean" ? constant$8(b)
|
3726 | : (t === "number" ? interpolateNumber
|
3727 | : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
|
3728 | : b instanceof color ? interpolateRgb
|
3729 | : b instanceof Date ? date$1
|
3730 | : isNumberArray(b) ? numberArray
|
3731 | : Array.isArray(b) ? genericArray
|
3732 | : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object$1
|
3733 | : interpolateNumber)(a, b);
|
3734 | }
|
3735 |
|
3736 | function discrete(range) {
|
3737 | var n = range.length;
|
3738 | return function(t) {
|
3739 | return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
3740 | };
|
3741 | }
|
3742 |
|
3743 | function hue(a, b) {
|
3744 | var i = hue$1(+a, +b);
|
3745 | return function(t) {
|
3746 | var x = i(t);
|
3747 | return x - 360 * Math.floor(x / 360);
|
3748 | };
|
3749 | }
|
3750 |
|
3751 | function interpolateRound(a, b) {
|
3752 | return a = +a, b = +b, function(t) {
|
3753 | return Math.round(a * (1 - t) + b * t);
|
3754 | };
|
3755 | }
|
3756 |
|
3757 | var degrees$1 = 180 / Math.PI;
|
3758 |
|
3759 | var identity$7 = {
|
3760 | translateX: 0,
|
3761 | translateY: 0,
|
3762 | rotate: 0,
|
3763 | skewX: 0,
|
3764 | scaleX: 1,
|
3765 | scaleY: 1
|
3766 | };
|
3767 |
|
3768 | function decompose(a, b, c, d, e, f) {
|
3769 | var scaleX, scaleY, skewX;
|
3770 | if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
|
3771 | if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
|
3772 | if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
|
3773 | if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
|
3774 | return {
|
3775 | translateX: e,
|
3776 | translateY: f,
|
3777 | rotate: Math.atan2(b, a) * degrees$1,
|
3778 | skewX: Math.atan(skewX) * degrees$1,
|
3779 | scaleX: scaleX,
|
3780 | scaleY: scaleY
|
3781 | };
|
3782 | }
|
3783 |
|
3784 | var svgNode;
|
3785 |
|
3786 |
|
3787 | function parseCss(value) {
|
3788 | const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + "");
|
3789 | return m.isIdentity ? identity$7 : decompose(m.a, m.b, m.c, m.d, m.e, m.f);
|
3790 | }
|
3791 |
|
3792 | function parseSvg(value) {
|
3793 | if (value == null) return identity$7;
|
3794 | if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
3795 | svgNode.setAttribute("transform", value);
|
3796 | if (!(value = svgNode.transform.baseVal.consolidate())) return identity$7;
|
3797 | value = value.matrix;
|
3798 | return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
|
3799 | }
|
3800 |
|
3801 | function interpolateTransform(parse, pxComma, pxParen, degParen) {
|
3802 |
|
3803 | function pop(s) {
|
3804 | return s.length ? s.pop() + " " : "";
|
3805 | }
|
3806 |
|
3807 | function translate(xa, ya, xb, yb, s, q) {
|
3808 | if (xa !== xb || ya !== yb) {
|
3809 | var i = s.push("translate(", null, pxComma, null, pxParen);
|
3810 | q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
|
3811 | } else if (xb || yb) {
|
3812 | s.push("translate(" + xb + pxComma + yb + pxParen);
|
3813 | }
|
3814 | }
|
3815 |
|
3816 | function rotate(a, b, s, q) {
|
3817 | if (a !== b) {
|
3818 | if (a - b > 180) b += 360; else if (b - a > 180) a += 360;
|
3819 | q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
|
3820 | } else if (b) {
|
3821 | s.push(pop(s) + "rotate(" + b + degParen);
|
3822 | }
|
3823 | }
|
3824 |
|
3825 | function skewX(a, b, s, q) {
|
3826 | if (a !== b) {
|
3827 | q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
|
3828 | } else if (b) {
|
3829 | s.push(pop(s) + "skewX(" + b + degParen);
|
3830 | }
|
3831 | }
|
3832 |
|
3833 | function scale(xa, ya, xb, yb, s, q) {
|
3834 | if (xa !== xb || ya !== yb) {
|
3835 | var i = s.push(pop(s) + "scale(", null, ",", null, ")");
|
3836 | q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
|
3837 | } else if (xb !== 1 || yb !== 1) {
|
3838 | s.push(pop(s) + "scale(" + xb + "," + yb + ")");
|
3839 | }
|
3840 | }
|
3841 |
|
3842 | return function(a, b) {
|
3843 | var s = [],
|
3844 | q = [];
|
3845 | a = parse(a), b = parse(b);
|
3846 | translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
|
3847 | rotate(a.rotate, b.rotate, s, q);
|
3848 | skewX(a.skewX, b.skewX, s, q);
|
3849 | scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
|
3850 | a = b = null;
|
3851 | return function(t) {
|
3852 | var i = -1, n = q.length, o;
|
3853 | while (++i < n) s[(o = q[i]).i] = o.x(t);
|
3854 | return s.join("");
|
3855 | };
|
3856 | };
|
3857 | }
|
3858 |
|
3859 | var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
|
3860 | var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
|
3861 |
|
3862 | var epsilon2$1 = 1e-12;
|
3863 |
|
3864 | function cosh(x) {
|
3865 | return ((x = Math.exp(x)) + 1 / x) / 2;
|
3866 | }
|
3867 |
|
3868 | function sinh(x) {
|
3869 | return ((x = Math.exp(x)) - 1 / x) / 2;
|
3870 | }
|
3871 |
|
3872 | function tanh(x) {
|
3873 | return ((x = Math.exp(2 * x)) - 1) / (x + 1);
|
3874 | }
|
3875 |
|
3876 | var interpolateZoom = (function zoomRho(rho, rho2, rho4) {
|
3877 |
|
3878 |
|
3879 |
|
3880 | function zoom(p0, p1) {
|
3881 | var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
|
3882 | ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
|
3883 | dx = ux1 - ux0,
|
3884 | dy = uy1 - uy0,
|
3885 | d2 = dx * dx + dy * dy,
|
3886 | i,
|
3887 | S;
|
3888 |
|
3889 |
|
3890 | if (d2 < epsilon2$1) {
|
3891 | S = Math.log(w1 / w0) / rho;
|
3892 | i = function(t) {
|
3893 | return [
|
3894 | ux0 + t * dx,
|
3895 | uy0 + t * dy,
|
3896 | w0 * Math.exp(rho * t * S)
|
3897 | ];
|
3898 | };
|
3899 | }
|
3900 |
|
3901 |
|
3902 | else {
|
3903 | var d1 = Math.sqrt(d2),
|
3904 | b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
|
3905 | b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
|
3906 | r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
|
3907 | r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
|
3908 | S = (r1 - r0) / rho;
|
3909 | i = function(t) {
|
3910 | var s = t * S,
|
3911 | coshr0 = cosh(r0),
|
3912 | u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
|
3913 | return [
|
3914 | ux0 + u * dx,
|
3915 | uy0 + u * dy,
|
3916 | w0 * coshr0 / cosh(rho * s + r0)
|
3917 | ];
|
3918 | };
|
3919 | }
|
3920 |
|
3921 | i.duration = S * 1000 * rho / Math.SQRT2;
|
3922 |
|
3923 | return i;
|
3924 | }
|
3925 |
|
3926 | zoom.rho = function(_) {
|
3927 | var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
|
3928 | return zoomRho(_1, _2, _4);
|
3929 | };
|
3930 |
|
3931 | return zoom;
|
3932 | })(Math.SQRT2, 2, 4);
|
3933 |
|
3934 | function hsl(hue) {
|
3935 | return function(start, end) {
|
3936 | var h = hue((start = hsl$2(start)).h, (end = hsl$2(end)).h),
|
3937 | s = nogamma(start.s, end.s),
|
3938 | l = nogamma(start.l, end.l),
|
3939 | opacity = nogamma(start.opacity, end.opacity);
|
3940 | return function(t) {
|
3941 | start.h = h(t);
|
3942 | start.s = s(t);
|
3943 | start.l = l(t);
|
3944 | start.opacity = opacity(t);
|
3945 | return start + "";
|
3946 | };
|
3947 | }
|
3948 | }
|
3949 |
|
3950 | var hsl$1 = hsl(hue$1);
|
3951 | var hslLong = hsl(nogamma);
|
3952 |
|
3953 | function lab(start, end) {
|
3954 | var l = nogamma((start = lab$1(start)).l, (end = lab$1(end)).l),
|
3955 | a = nogamma(start.a, end.a),
|
3956 | b = nogamma(start.b, end.b),
|
3957 | opacity = nogamma(start.opacity, end.opacity);
|
3958 | return function(t) {
|
3959 | start.l = l(t);
|
3960 | start.a = a(t);
|
3961 | start.b = b(t);
|
3962 | start.opacity = opacity(t);
|
3963 | return start + "";
|
3964 | };
|
3965 | }
|
3966 |
|
3967 | function hcl(hue) {
|
3968 | return function(start, end) {
|
3969 | var h = hue((start = hcl$2(start)).h, (end = hcl$2(end)).h),
|
3970 | c = nogamma(start.c, end.c),
|
3971 | l = nogamma(start.l, end.l),
|
3972 | opacity = nogamma(start.opacity, end.opacity);
|
3973 | return function(t) {
|
3974 | start.h = h(t);
|
3975 | start.c = c(t);
|
3976 | start.l = l(t);
|
3977 | start.opacity = opacity(t);
|
3978 | return start + "";
|
3979 | };
|
3980 | }
|
3981 | }
|
3982 |
|
3983 | var hcl$1 = hcl(hue$1);
|
3984 | var hclLong = hcl(nogamma);
|
3985 |
|
3986 | function cubehelix$1(hue) {
|
3987 | return (function cubehelixGamma(y) {
|
3988 | y = +y;
|
3989 |
|
3990 | function cubehelix(start, end) {
|
3991 | var h = hue((start = cubehelix$3(start)).h, (end = cubehelix$3(end)).h),
|
3992 | s = nogamma(start.s, end.s),
|
3993 | l = nogamma(start.l, end.l),
|
3994 | opacity = nogamma(start.opacity, end.opacity);
|
3995 | return function(t) {
|
3996 | start.h = h(t);
|
3997 | start.s = s(t);
|
3998 | start.l = l(Math.pow(t, y));
|
3999 | start.opacity = opacity(t);
|
4000 | return start + "";
|
4001 | };
|
4002 | }
|
4003 |
|
4004 | cubehelix.gamma = cubehelixGamma;
|
4005 |
|
4006 | return cubehelix;
|
4007 | })(1);
|
4008 | }
|
4009 |
|
4010 | var cubehelix$2 = cubehelix$1(hue$1);
|
4011 | var cubehelixLong = cubehelix$1(nogamma);
|
4012 |
|
4013 | function piecewise(interpolate, values) {
|
4014 | if (values === undefined) values = interpolate, interpolate = interpolate$2;
|
4015 | var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
|
4016 | while (i < n) I[i] = interpolate(v, v = values[++i]);
|
4017 | return function(t) {
|
4018 | var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
|
4019 | return I[i](t - i);
|
4020 | };
|
4021 | }
|
4022 |
|
4023 | function quantize$1(interpolator, n) {
|
4024 | var samples = new Array(n);
|
4025 | for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
|
4026 | return samples;
|
4027 | }
|
4028 |
|
4029 | var frame = 0,
|
4030 | timeout$1 = 0,
|
4031 | interval$1 = 0,
|
4032 | pokeDelay = 1000,
|
4033 | taskHead,
|
4034 | taskTail,
|
4035 | clockLast = 0,
|
4036 | clockNow = 0,
|
4037 | clockSkew = 0,
|
4038 | clock = typeof performance === "object" && performance.now ? performance : Date,
|
4039 | setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
|
4040 |
|
4041 | function now() {
|
4042 | return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
|
4043 | }
|
4044 |
|
4045 | function clearNow() {
|
4046 | clockNow = 0;
|
4047 | }
|
4048 |
|
4049 | function Timer() {
|
4050 | this._call =
|
4051 | this._time =
|
4052 | this._next = null;
|
4053 | }
|
4054 |
|
4055 | Timer.prototype = timer.prototype = {
|
4056 | constructor: Timer,
|
4057 | restart: function(callback, delay, time) {
|
4058 | if (typeof callback !== "function") throw new TypeError("callback is not a function");
|
4059 | time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
|
4060 | if (!this._next && taskTail !== this) {
|
4061 | if (taskTail) taskTail._next = this;
|
4062 | else taskHead = this;
|
4063 | taskTail = this;
|
4064 | }
|
4065 | this._call = callback;
|
4066 | this._time = time;
|
4067 | sleep();
|
4068 | },
|
4069 | stop: function() {
|
4070 | if (this._call) {
|
4071 | this._call = null;
|
4072 | this._time = Infinity;
|
4073 | sleep();
|
4074 | }
|
4075 | }
|
4076 | };
|
4077 |
|
4078 | function timer(callback, delay, time) {
|
4079 | var t = new Timer;
|
4080 | t.restart(callback, delay, time);
|
4081 | return t;
|
4082 | }
|
4083 |
|
4084 | function timerFlush() {
|
4085 | now();
|
4086 | ++frame;
|
4087 | var t = taskHead, e;
|
4088 | while (t) {
|
4089 | if ((e = clockNow - t._time) >= 0) t._call.call(undefined, e);
|
4090 | t = t._next;
|
4091 | }
|
4092 | --frame;
|
4093 | }
|
4094 |
|
4095 | function wake() {
|
4096 | clockNow = (clockLast = clock.now()) + clockSkew;
|
4097 | frame = timeout$1 = 0;
|
4098 | try {
|
4099 | timerFlush();
|
4100 | } finally {
|
4101 | frame = 0;
|
4102 | nap();
|
4103 | clockNow = 0;
|
4104 | }
|
4105 | }
|
4106 |
|
4107 | function poke() {
|
4108 | var now = clock.now(), delay = now - clockLast;
|
4109 | if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
|
4110 | }
|
4111 |
|
4112 | function nap() {
|
4113 | var t0, t1 = taskHead, t2, time = Infinity;
|
4114 | while (t1) {
|
4115 | if (t1._call) {
|
4116 | if (time > t1._time) time = t1._time;
|
4117 | t0 = t1, t1 = t1._next;
|
4118 | } else {
|
4119 | t2 = t1._next, t1._next = null;
|
4120 | t1 = t0 ? t0._next = t2 : taskHead = t2;
|
4121 | }
|
4122 | }
|
4123 | taskTail = t0;
|
4124 | sleep(time);
|
4125 | }
|
4126 |
|
4127 | function sleep(time) {
|
4128 | if (frame) return;
|
4129 | if (timeout$1) timeout$1 = clearTimeout(timeout$1);
|
4130 | var delay = time - clockNow;
|
4131 | if (delay > 24) {
|
4132 | if (time < Infinity) timeout$1 = setTimeout(wake, time - clock.now() - clockSkew);
|
4133 | if (interval$1) interval$1 = clearInterval(interval$1);
|
4134 | } else {
|
4135 | if (!interval$1) clockLast = clock.now(), interval$1 = setInterval(poke, pokeDelay);
|
4136 | frame = 1, setFrame(wake);
|
4137 | }
|
4138 | }
|
4139 |
|
4140 | function timeout(callback, delay, time) {
|
4141 | var t = new Timer;
|
4142 | delay = delay == null ? 0 : +delay;
|
4143 | t.restart(elapsed => {
|
4144 | t.stop();
|
4145 | callback(elapsed + delay);
|
4146 | }, delay, time);
|
4147 | return t;
|
4148 | }
|
4149 |
|
4150 | function interval(callback, delay, time) {
|
4151 | var t = new Timer, total = delay;
|
4152 | if (delay == null) return t.restart(callback, delay, time), t;
|
4153 | t._restart = t.restart;
|
4154 | t.restart = function(callback, delay, time) {
|
4155 | delay = +delay, time = time == null ? now() : +time;
|
4156 | t._restart(function tick(elapsed) {
|
4157 | elapsed += total;
|
4158 | t._restart(tick, total += delay, time);
|
4159 | callback(elapsed);
|
4160 | }, delay, time);
|
4161 | };
|
4162 | t.restart(callback, delay, time);
|
4163 | return t;
|
4164 | }
|
4165 |
|
4166 | var emptyOn = dispatch("start", "end", "cancel", "interrupt");
|
4167 | var emptyTween = [];
|
4168 |
|
4169 | var CREATED = 0;
|
4170 | var SCHEDULED = 1;
|
4171 | var STARTING = 2;
|
4172 | var STARTED = 3;
|
4173 | var RUNNING = 4;
|
4174 | var ENDING = 5;
|
4175 | var ENDED = 6;
|
4176 |
|
4177 | function schedule(node, name, id, index, group, timing) {
|
4178 | var schedules = node.__transition;
|
4179 | if (!schedules) node.__transition = {};
|
4180 | else if (id in schedules) return;
|
4181 | create(node, id, {
|
4182 | name: name,
|
4183 | index: index,
|
4184 | group: group,
|
4185 | on: emptyOn,
|
4186 | tween: emptyTween,
|
4187 | time: timing.time,
|
4188 | delay: timing.delay,
|
4189 | duration: timing.duration,
|
4190 | ease: timing.ease,
|
4191 | timer: null,
|
4192 | state: CREATED
|
4193 | });
|
4194 | }
|
4195 |
|
4196 | function init(node, id) {
|
4197 | var schedule = get(node, id);
|
4198 | if (schedule.state > CREATED) throw new Error("too late; already scheduled");
|
4199 | return schedule;
|
4200 | }
|
4201 |
|
4202 | function set(node, id) {
|
4203 | var schedule = get(node, id);
|
4204 | if (schedule.state > STARTED) throw new Error("too late; already running");
|
4205 | return schedule;
|
4206 | }
|
4207 |
|
4208 | function get(node, id) {
|
4209 | var schedule = node.__transition;
|
4210 | if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
|
4211 | return schedule;
|
4212 | }
|
4213 |
|
4214 | function create(node, id, self) {
|
4215 | var schedules = node.__transition,
|
4216 | tween;
|
4217 |
|
4218 |
|
4219 |
|
4220 | schedules[id] = self;
|
4221 | self.timer = timer(schedule, 0, self.time);
|
4222 |
|
4223 | function schedule(elapsed) {
|
4224 | self.state = SCHEDULED;
|
4225 | self.timer.restart(start, self.delay, self.time);
|
4226 |
|
4227 |
|
4228 | if (self.delay <= elapsed) start(elapsed - self.delay);
|
4229 | }
|
4230 |
|
4231 | function start(elapsed) {
|
4232 | var i, j, n, o;
|
4233 |
|
4234 |
|
4235 | if (self.state !== SCHEDULED) return stop();
|
4236 |
|
4237 | for (i in schedules) {
|
4238 | o = schedules[i];
|
4239 | if (o.name !== self.name) continue;
|
4240 |
|
4241 |
|
4242 |
|
4243 |
|
4244 | if (o.state === STARTED) return timeout(start);
|
4245 |
|
4246 |
|
4247 | if (o.state === RUNNING) {
|
4248 | o.state = ENDED;
|
4249 | o.timer.stop();
|
4250 | o.on.call("interrupt", node, node.__data__, o.index, o.group);
|
4251 | delete schedules[i];
|
4252 | }
|
4253 |
|
4254 |
|
4255 | else if (+i < id) {
|
4256 | o.state = ENDED;
|
4257 | o.timer.stop();
|
4258 | o.on.call("cancel", node, node.__data__, o.index, o.group);
|
4259 | delete schedules[i];
|
4260 | }
|
4261 | }
|
4262 |
|
4263 |
|
4264 |
|
4265 |
|
4266 |
|
4267 | timeout(function() {
|
4268 | if (self.state === STARTED) {
|
4269 | self.state = RUNNING;
|
4270 | self.timer.restart(tick, self.delay, self.time);
|
4271 | tick(elapsed);
|
4272 | }
|
4273 | });
|
4274 |
|
4275 |
|
4276 |
|
4277 | self.state = STARTING;
|
4278 | self.on.call("start", node, node.__data__, self.index, self.group);
|
4279 | if (self.state !== STARTING) return;
|
4280 | self.state = STARTED;
|
4281 |
|
4282 |
|
4283 | tween = new Array(n = self.tween.length);
|
4284 | for (i = 0, j = -1; i < n; ++i) {
|
4285 | if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
|
4286 | tween[++j] = o;
|
4287 | }
|
4288 | }
|
4289 | tween.length = j + 1;
|
4290 | }
|
4291 |
|
4292 | function tick(elapsed) {
|
4293 | var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
|
4294 | i = -1,
|
4295 | n = tween.length;
|
4296 |
|
4297 | while (++i < n) {
|
4298 | tween[i].call(node, t);
|
4299 | }
|
4300 |
|
4301 |
|
4302 | if (self.state === ENDING) {
|
4303 | self.on.call("end", node, node.__data__, self.index, self.group);
|
4304 | stop();
|
4305 | }
|
4306 | }
|
4307 |
|
4308 | function stop() {
|
4309 | self.state = ENDED;
|
4310 | self.timer.stop();
|
4311 | delete schedules[id];
|
4312 | for (var i in schedules) return;
|
4313 | delete node.__transition;
|
4314 | }
|
4315 | }
|
4316 |
|
4317 | function interrupt(node, name) {
|
4318 | var schedules = node.__transition,
|
4319 | schedule,
|
4320 | active,
|
4321 | empty = true,
|
4322 | i;
|
4323 |
|
4324 | if (!schedules) return;
|
4325 |
|
4326 | name = name == null ? null : name + "";
|
4327 |
|
4328 | for (i in schedules) {
|
4329 | if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
|
4330 | active = schedule.state > STARTING && schedule.state < ENDING;
|
4331 | schedule.state = ENDED;
|
4332 | schedule.timer.stop();
|
4333 | schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
|
4334 | delete schedules[i];
|
4335 | }
|
4336 |
|
4337 | if (empty) delete node.__transition;
|
4338 | }
|
4339 |
|
4340 | function selection_interrupt(name) {
|
4341 | return this.each(function() {
|
4342 | interrupt(this, name);
|
4343 | });
|
4344 | }
|
4345 |
|
4346 | function tweenRemove(id, name) {
|
4347 | var tween0, tween1;
|
4348 | return function() {
|
4349 | var schedule = set(this, id),
|
4350 | tween = schedule.tween;
|
4351 |
|
4352 | // If this node shared tween with the previous node,
|
4353 | // just assign the updated shared tween and we’re done!
|
4354 | // Otherwise, copy-on-write.
|
4355 | if (tween !== tween0) {
|
4356 | tween1 = tween0 = tween;
|
4357 | for (var i = 0, n = tween1.length; i < n; ++i) {
|
4358 | if (tween1[i].name === name) {
|
4359 | tween1 = tween1.slice();
|
4360 | tween1.splice(i, 1);
|
4361 | break;
|
4362 | }
|
4363 | }
|
4364 | }
|
4365 |
|
4366 | schedule.tween = tween1;
|
4367 | };
|
4368 | }
|
4369 |
|
4370 | function tweenFunction(id, name, value) {
|
4371 | var tween0, tween1;
|
4372 | if (typeof value !== "function") throw new Error;
|
4373 | return function() {
|
4374 | var schedule = set(this, id),
|
4375 | tween = schedule.tween;
|
4376 |
|
4377 | // If this node shared tween with the previous node,
|
4378 | // just assign the updated shared tween and we’re done!
|
4379 | // Otherwise, copy-on-write.
|
4380 | if (tween !== tween0) {
|
4381 | tween1 = (tween0 = tween).slice();
|
4382 | for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
|
4383 | if (tween1[i].name === name) {
|
4384 | tween1[i] = t;
|
4385 | break;
|
4386 | }
|
4387 | }
|
4388 | if (i === n) tween1.push(t);
|
4389 | }
|
4390 |
|
4391 | schedule.tween = tween1;
|
4392 | };
|
4393 | }
|
4394 |
|
4395 | function transition_tween(name, value) {
|
4396 | var id = this._id;
|
4397 |
|
4398 | name += "";
|
4399 |
|
4400 | if (arguments.length < 2) {
|
4401 | var tween = get(this.node(), id).tween;
|
4402 | for (var i = 0, n = tween.length, t; i < n; ++i) {
|
4403 | if ((t = tween[i]).name === name) {
|
4404 | return t.value;
|
4405 | }
|
4406 | }
|
4407 | return null;
|
4408 | }
|
4409 |
|
4410 | return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
|
4411 | }
|
4412 |
|
4413 | function tweenValue(transition, name, value) {
|
4414 | var id = transition._id;
|
4415 |
|
4416 | transition.each(function() {
|
4417 | var schedule = set(this, id);
|
4418 | (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
|
4419 | });
|
4420 |
|
4421 | return function(node) {
|
4422 | return get(node, id).value[name];
|
4423 | };
|
4424 | }
|
4425 |
|
4426 | function interpolate$1(a, b) {
|
4427 | var c;
|
4428 | return (typeof b === "number" ? interpolateNumber
|
4429 | : b instanceof color ? interpolateRgb
|
4430 | : (c = color(b)) ? (b = c, interpolateRgb)
|
4431 | : interpolateString)(a, b);
|
4432 | }
|
4433 |
|
4434 | function attrRemove(name) {
|
4435 | return function() {
|
4436 | this.removeAttribute(name);
|
4437 | };
|
4438 | }
|
4439 |
|
4440 | function attrRemoveNS(fullname) {
|
4441 | return function() {
|
4442 | this.removeAttributeNS(fullname.space, fullname.local);
|
4443 | };
|
4444 | }
|
4445 |
|
4446 | function attrConstant(name, interpolate, value1) {
|
4447 | var string00,
|
4448 | string1 = value1 + "",
|
4449 | interpolate0;
|
4450 | return function() {
|
4451 | var string0 = this.getAttribute(name);
|
4452 | return string0 === string1 ? null
|
4453 | : string0 === string00 ? interpolate0
|
4454 | : interpolate0 = interpolate(string00 = string0, value1);
|
4455 | };
|
4456 | }
|
4457 |
|
4458 | function attrConstantNS(fullname, interpolate, value1) {
|
4459 | var string00,
|
4460 | string1 = value1 + "",
|
4461 | interpolate0;
|
4462 | return function() {
|
4463 | var string0 = this.getAttributeNS(fullname.space, fullname.local);
|
4464 | return string0 === string1 ? null
|
4465 | : string0 === string00 ? interpolate0
|
4466 | : interpolate0 = interpolate(string00 = string0, value1);
|
4467 | };
|
4468 | }
|
4469 |
|
4470 | function attrFunction(name, interpolate, value) {
|
4471 | var string00,
|
4472 | string10,
|
4473 | interpolate0;
|
4474 | return function() {
|
4475 | var string0, value1 = value(this), string1;
|
4476 | if (value1 == null) return void this.removeAttribute(name);
|
4477 | string0 = this.getAttribute(name);
|
4478 | string1 = value1 + "";
|
4479 | return string0 === string1 ? null
|
4480 | : string0 === string00 && string1 === string10 ? interpolate0
|
4481 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
4482 | };
|
4483 | }
|
4484 |
|
4485 | function attrFunctionNS(fullname, interpolate, value) {
|
4486 | var string00,
|
4487 | string10,
|
4488 | interpolate0;
|
4489 | return function() {
|
4490 | var string0, value1 = value(this), string1;
|
4491 | if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
|
4492 | string0 = this.getAttributeNS(fullname.space, fullname.local);
|
4493 | string1 = value1 + "";
|
4494 | return string0 === string1 ? null
|
4495 | : string0 === string00 && string1 === string10 ? interpolate0
|
4496 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
4497 | };
|
4498 | }
|
4499 |
|
4500 | function transition_attr(name, value) {
|
4501 | var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1;
|
4502 | return this.attrTween(name, typeof value === "function"
|
4503 | ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value))
|
4504 | : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname)
|
4505 | : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value));
|
4506 | }
|
4507 |
|
4508 | function attrInterpolate(name, i) {
|
4509 | return function(t) {
|
4510 | this.setAttribute(name, i.call(this, t));
|
4511 | };
|
4512 | }
|
4513 |
|
4514 | function attrInterpolateNS(fullname, i) {
|
4515 | return function(t) {
|
4516 | this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
|
4517 | };
|
4518 | }
|
4519 |
|
4520 | function attrTweenNS(fullname, value) {
|
4521 | var t0, i0;
|
4522 | function tween() {
|
4523 | var i = value.apply(this, arguments);
|
4524 | if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
|
4525 | return t0;
|
4526 | }
|
4527 | tween._value = value;
|
4528 | return tween;
|
4529 | }
|
4530 |
|
4531 | function attrTween(name, value) {
|
4532 | var t0, i0;
|
4533 | function tween() {
|
4534 | var i = value.apply(this, arguments);
|
4535 | if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
|
4536 | return t0;
|
4537 | }
|
4538 | tween._value = value;
|
4539 | return tween;
|
4540 | }
|
4541 |
|
4542 | function transition_attrTween(name, value) {
|
4543 | var key = "attr." + name;
|
4544 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
4545 | if (value == null) return this.tween(key, null);
|
4546 | if (typeof value !== "function") throw new Error;
|
4547 | var fullname = namespace(name);
|
4548 | return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
|
4549 | }
|
4550 |
|
4551 | function delayFunction(id, value) {
|
4552 | return function() {
|
4553 | init(this, id).delay = +value.apply(this, arguments);
|
4554 | };
|
4555 | }
|
4556 |
|
4557 | function delayConstant(id, value) {
|
4558 | return value = +value, function() {
|
4559 | init(this, id).delay = value;
|
4560 | };
|
4561 | }
|
4562 |
|
4563 | function transition_delay(value) {
|
4564 | var id = this._id;
|
4565 |
|
4566 | return arguments.length
|
4567 | ? this.each((typeof value === "function"
|
4568 | ? delayFunction
|
4569 | : delayConstant)(id, value))
|
4570 | : get(this.node(), id).delay;
|
4571 | }
|
4572 |
|
4573 | function durationFunction(id, value) {
|
4574 | return function() {
|
4575 | set(this, id).duration = +value.apply(this, arguments);
|
4576 | };
|
4577 | }
|
4578 |
|
4579 | function durationConstant(id, value) {
|
4580 | return value = +value, function() {
|
4581 | set(this, id).duration = value;
|
4582 | };
|
4583 | }
|
4584 |
|
4585 | function transition_duration(value) {
|
4586 | var id = this._id;
|
4587 |
|
4588 | return arguments.length
|
4589 | ? this.each((typeof value === "function"
|
4590 | ? durationFunction
|
4591 | : durationConstant)(id, value))
|
4592 | : get(this.node(), id).duration;
|
4593 | }
|
4594 |
|
4595 | function easeConstant(id, value) {
|
4596 | if (typeof value !== "function") throw new Error;
|
4597 | return function() {
|
4598 | set(this, id).ease = value;
|
4599 | };
|
4600 | }
|
4601 |
|
4602 | function transition_ease(value) {
|
4603 | var id = this._id;
|
4604 |
|
4605 | return arguments.length
|
4606 | ? this.each(easeConstant(id, value))
|
4607 | : get(this.node(), id).ease;
|
4608 | }
|
4609 |
|
4610 | function easeVarying(id, value) {
|
4611 | return function() {
|
4612 | var v = value.apply(this, arguments);
|
4613 | if (typeof v !== "function") throw new Error;
|
4614 | set(this, id).ease = v;
|
4615 | };
|
4616 | }
|
4617 |
|
4618 | function transition_easeVarying(value) {
|
4619 | if (typeof value !== "function") throw new Error;
|
4620 | return this.each(easeVarying(this._id, value));
|
4621 | }
|
4622 |
|
4623 | function transition_filter(match) {
|
4624 | if (typeof match !== "function") match = matcher(match);
|
4625 |
|
4626 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
4627 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
|
4628 | if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
4629 | subgroup.push(node);
|
4630 | }
|
4631 | }
|
4632 | }
|
4633 |
|
4634 | return new Transition(subgroups, this._parents, this._name, this._id);
|
4635 | }
|
4636 |
|
4637 | function transition_merge(transition) {
|
4638 | if (transition._id !== this._id) throw new Error;
|
4639 |
|
4640 | 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) {
|
4641 | for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
|
4642 | if (node = group0[i] || group1[i]) {
|
4643 | merge[i] = node;
|
4644 | }
|
4645 | }
|
4646 | }
|
4647 |
|
4648 | for (; j < m0; ++j) {
|
4649 | merges[j] = groups0[j];
|
4650 | }
|
4651 |
|
4652 | return new Transition(merges, this._parents, this._name, this._id);
|
4653 | }
|
4654 |
|
4655 | function start(name) {
|
4656 | return (name + "").trim().split(/^|\s+/).every(function(t) {
|
4657 | var i = t.indexOf(".");
|
4658 | if (i >= 0) t = t.slice(0, i);
|
4659 | return !t || t === "start";
|
4660 | });
|
4661 | }
|
4662 |
|
4663 | function onFunction(id, name, listener) {
|
4664 | var on0, on1, sit = start(name) ? init : set;
|
4665 | return function() {
|
4666 | var schedule = sit(this, id),
|
4667 | on = schedule.on;
|
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 | if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
|
4673 |
|
4674 | schedule.on = on1;
|
4675 | };
|
4676 | }
|
4677 |
|
4678 | function transition_on(name, listener) {
|
4679 | var id = this._id;
|
4680 |
|
4681 | return arguments.length < 2
|
4682 | ? get(this.node(), id).on.on(name)
|
4683 | : this.each(onFunction(id, name, listener));
|
4684 | }
|
4685 |
|
4686 | function removeFunction(id) {
|
4687 | return function() {
|
4688 | var parent = this.parentNode;
|
4689 | for (var i in this.__transition) if (+i !== id) return;
|
4690 | if (parent) parent.removeChild(this);
|
4691 | };
|
4692 | }
|
4693 |
|
4694 | function transition_remove() {
|
4695 | return this.on("end.remove", removeFunction(this._id));
|
4696 | }
|
4697 |
|
4698 | function transition_select(select) {
|
4699 | var name = this._name,
|
4700 | id = this._id;
|
4701 |
|
4702 | if (typeof select !== "function") select = selector(select);
|
4703 |
|
4704 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
4705 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
|
4706 | if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
4707 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
4708 | subgroup[i] = subnode;
|
4709 | schedule(subgroup[i], name, id, i, subgroup, get(node, id));
|
4710 | }
|
4711 | }
|
4712 | }
|
4713 |
|
4714 | return new Transition(subgroups, this._parents, name, id);
|
4715 | }
|
4716 |
|
4717 | function transition_selectAll(select) {
|
4718 | var name = this._name,
|
4719 | id = this._id;
|
4720 |
|
4721 | if (typeof select !== "function") select = selectorAll(select);
|
4722 |
|
4723 | for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
|
4724 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
4725 | if (node = group[i]) {
|
4726 | for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) {
|
4727 | if (child = children[k]) {
|
4728 | schedule(child, name, id, k, children, inherit);
|
4729 | }
|
4730 | }
|
4731 | subgroups.push(children);
|
4732 | parents.push(node);
|
4733 | }
|
4734 | }
|
4735 | }
|
4736 |
|
4737 | return new Transition(subgroups, parents, name, id);
|
4738 | }
|
4739 |
|
4740 | var Selection = selection.prototype.constructor;
|
4741 |
|
4742 | function transition_selection() {
|
4743 | return new Selection(this._groups, this._parents);
|
4744 | }
|
4745 |
|
4746 | function styleNull(name, interpolate) {
|
4747 | var string00,
|
4748 | string10,
|
4749 | interpolate0;
|
4750 | return function() {
|
4751 | var string0 = styleValue(this, name),
|
4752 | string1 = (this.style.removeProperty(name), styleValue(this, name));
|
4753 | return string0 === string1 ? null
|
4754 | : string0 === string00 && string1 === string10 ? interpolate0
|
4755 | : interpolate0 = interpolate(string00 = string0, string10 = string1);
|
4756 | };
|
4757 | }
|
4758 |
|
4759 | function styleRemove(name) {
|
4760 | return function() {
|
4761 | this.style.removeProperty(name);
|
4762 | };
|
4763 | }
|
4764 |
|
4765 | function styleConstant(name, interpolate, value1) {
|
4766 | var string00,
|
4767 | string1 = value1 + "",
|
4768 | interpolate0;
|
4769 | return function() {
|
4770 | var string0 = styleValue(this, name);
|
4771 | return string0 === string1 ? null
|
4772 | : string0 === string00 ? interpolate0
|
4773 | : interpolate0 = interpolate(string00 = string0, value1);
|
4774 | };
|
4775 | }
|
4776 |
|
4777 | function styleFunction(name, interpolate, value) {
|
4778 | var string00,
|
4779 | string10,
|
4780 | interpolate0;
|
4781 | return function() {
|
4782 | var string0 = styleValue(this, name),
|
4783 | value1 = value(this),
|
4784 | string1 = value1 + "";
|
4785 | if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
|
4786 | return string0 === string1 ? null
|
4787 | : string0 === string00 && string1 === string10 ? interpolate0
|
4788 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
4789 | };
|
4790 | }
|
4791 |
|
4792 | function styleMaybeRemove(id, name) {
|
4793 | var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
|
4794 | return function() {
|
4795 | var schedule = set(this, id),
|
4796 | on = schedule.on,
|
4797 | listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;
|
4798 |
|
4799 | // If this node shared a dispatch with the previous node,
|
4800 | // just assign the updated shared dispatch and we’re done!
|
4801 | // Otherwise, copy-on-write.
|
4802 | if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
|
4803 |
|
4804 | schedule.on = on1;
|
4805 | };
|
4806 | }
|
4807 |
|
4808 | function transition_style(name, value, priority) {
|
4809 | var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1;
|
4810 | return value == null ? this
|
4811 | .styleTween(name, styleNull(name, i))
|
4812 | .on("end.style." + name, styleRemove(name))
|
4813 | : typeof value === "function" ? this
|
4814 | .styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value)))
|
4815 | .each(styleMaybeRemove(this._id, name))
|
4816 | : this
|
4817 | .styleTween(name, styleConstant(name, i, value), priority)
|
4818 | .on("end.style." + name, null);
|
4819 | }
|
4820 |
|
4821 | function styleInterpolate(name, i, priority) {
|
4822 | return function(t) {
|
4823 | this.style.setProperty(name, i.call(this, t), priority);
|
4824 | };
|
4825 | }
|
4826 |
|
4827 | function styleTween(name, value, priority) {
|
4828 | var t, i0;
|
4829 | function tween() {
|
4830 | var i = value.apply(this, arguments);
|
4831 | if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
|
4832 | return t;
|
4833 | }
|
4834 | tween._value = value;
|
4835 | return tween;
|
4836 | }
|
4837 |
|
4838 | function transition_styleTween(name, value, priority) {
|
4839 | var key = "style." + (name += "");
|
4840 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
4841 | if (value == null) return this.tween(key, null);
|
4842 | if (typeof value !== "function") throw new Error;
|
4843 | return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
|
4844 | }
|
4845 |
|
4846 | function textConstant(value) {
|
4847 | return function() {
|
4848 | this.textContent = value;
|
4849 | };
|
4850 | }
|
4851 |
|
4852 | function textFunction(value) {
|
4853 | return function() {
|
4854 | var value1 = value(this);
|
4855 | this.textContent = value1 == null ? "" : value1;
|
4856 | };
|
4857 | }
|
4858 |
|
4859 | function transition_text(value) {
|
4860 | return this.tween("text", typeof value === "function"
|
4861 | ? textFunction(tweenValue(this, "text", value))
|
4862 | : textConstant(value == null ? "" : value + ""));
|
4863 | }
|
4864 |
|
4865 | function textInterpolate(i) {
|
4866 | return function(t) {
|
4867 | this.textContent = i.call(this, t);
|
4868 | };
|
4869 | }
|
4870 |
|
4871 | function textTween(value) {
|
4872 | var t0, i0;
|
4873 | function tween() {
|
4874 | var i = value.apply(this, arguments);
|
4875 | if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
|
4876 | return t0;
|
4877 | }
|
4878 | tween._value = value;
|
4879 | return tween;
|
4880 | }
|
4881 |
|
4882 | function transition_textTween(value) {
|
4883 | var key = "text";
|
4884 | if (arguments.length < 1) return (key = this.tween(key)) && key._value;
|
4885 | if (value == null) return this.tween(key, null);
|
4886 | if (typeof value !== "function") throw new Error;
|
4887 | return this.tween(key, textTween(value));
|
4888 | }
|
4889 |
|
4890 | function transition_transition() {
|
4891 | var name = this._name,
|
4892 | id0 = this._id,
|
4893 | id1 = newId();
|
4894 |
|
4895 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
4896 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
4897 | if (node = group[i]) {
|
4898 | var inherit = get(node, id0);
|
4899 | schedule(node, name, id1, i, group, {
|
4900 | time: inherit.time + inherit.delay + inherit.duration,
|
4901 | delay: 0,
|
4902 | duration: inherit.duration,
|
4903 | ease: inherit.ease
|
4904 | });
|
4905 | }
|
4906 | }
|
4907 | }
|
4908 |
|
4909 | return new Transition(groups, this._parents, name, id1);
|
4910 | }
|
4911 |
|
4912 | function transition_end() {
|
4913 | var on0, on1, that = this, id = that._id, size = that.size();
|
4914 | return new Promise(function(resolve, reject) {
|
4915 | var cancel = {value: reject},
|
4916 | end = {value: function() { if (--size === 0) resolve(); }};
|
4917 |
|
4918 | that.each(function() {
|
4919 | var schedule = set(this, id),
|
4920 | on = schedule.on;
|
4921 |
|
4922 | // If this node shared a dispatch with the previous node,
|
4923 | // just assign the updated shared dispatch and we’re done!
|
4924 | // Otherwise, copy-on-write.
|
4925 | if (on !== on0) {
|
4926 | on1 = (on0 = on).copy();
|
4927 | on1._.cancel.push(cancel);
|
4928 | on1._.interrupt.push(cancel);
|
4929 | on1._.end.push(end);
|
4930 | }
|
4931 |
|
4932 | schedule.on = on1;
|
4933 | });
|
4934 |
|
4935 |
|
4936 | if (size === 0) resolve();
|
4937 | });
|
4938 | }
|
4939 |
|
4940 | var id = 0;
|
4941 |
|
4942 | function Transition(groups, parents, name, id) {
|
4943 | this._groups = groups;
|
4944 | this._parents = parents;
|
4945 | this._name = name;
|
4946 | this._id = id;
|
4947 | }
|
4948 |
|
4949 | function transition(name) {
|
4950 | return selection().transition(name);
|
4951 | }
|
4952 |
|
4953 | function newId() {
|
4954 | return ++id;
|
4955 | }
|
4956 |
|
4957 | var selection_prototype = selection.prototype;
|
4958 |
|
4959 | Transition.prototype = transition.prototype = {
|
4960 | constructor: Transition,
|
4961 | select: transition_select,
|
4962 | selectAll: transition_selectAll,
|
4963 | selectChild: selection_prototype.selectChild,
|
4964 | selectChildren: selection_prototype.selectChildren,
|
4965 | filter: transition_filter,
|
4966 | merge: transition_merge,
|
4967 | selection: transition_selection,
|
4968 | transition: transition_transition,
|
4969 | call: selection_prototype.call,
|
4970 | nodes: selection_prototype.nodes,
|
4971 | node: selection_prototype.node,
|
4972 | size: selection_prototype.size,
|
4973 | empty: selection_prototype.empty,
|
4974 | each: selection_prototype.each,
|
4975 | on: transition_on,
|
4976 | attr: transition_attr,
|
4977 | attrTween: transition_attrTween,
|
4978 | style: transition_style,
|
4979 | styleTween: transition_styleTween,
|
4980 | text: transition_text,
|
4981 | textTween: transition_textTween,
|
4982 | remove: transition_remove,
|
4983 | tween: transition_tween,
|
4984 | delay: transition_delay,
|
4985 | duration: transition_duration,
|
4986 | ease: transition_ease,
|
4987 | easeVarying: transition_easeVarying,
|
4988 | end: transition_end,
|
4989 | [Symbol.iterator]: selection_prototype[Symbol.iterator]
|
4990 | };
|
4991 |
|
4992 | const linear$1 = t => +t;
|
4993 |
|
4994 | function quadIn(t) {
|
4995 | return t * t;
|
4996 | }
|
4997 |
|
4998 | function quadOut(t) {
|
4999 | return t * (2 - t);
|
5000 | }
|
5001 |
|
5002 | function quadInOut(t) {
|
5003 | return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
|
5004 | }
|
5005 |
|
5006 | function cubicIn(t) {
|
5007 | return t * t * t;
|
5008 | }
|
5009 |
|
5010 | function cubicOut(t) {
|
5011 | return --t * t * t + 1;
|
5012 | }
|
5013 |
|
5014 | function cubicInOut(t) {
|
5015 | return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
|
5016 | }
|
5017 |
|
5018 | var exponent$1 = 3;
|
5019 |
|
5020 | var polyIn = (function custom(e) {
|
5021 | e = +e;
|
5022 |
|
5023 | function polyIn(t) {
|
5024 | return Math.pow(t, e);
|
5025 | }
|
5026 |
|
5027 | polyIn.exponent = custom;
|
5028 |
|
5029 | return polyIn;
|
5030 | })(exponent$1);
|
5031 |
|
5032 | var polyOut = (function custom(e) {
|
5033 | e = +e;
|
5034 |
|
5035 | function polyOut(t) {
|
5036 | return 1 - Math.pow(1 - t, e);
|
5037 | }
|
5038 |
|
5039 | polyOut.exponent = custom;
|
5040 |
|
5041 | return polyOut;
|
5042 | })(exponent$1);
|
5043 |
|
5044 | var polyInOut = (function custom(e) {
|
5045 | e = +e;
|
5046 |
|
5047 | function polyInOut(t) {
|
5048 | return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
|
5049 | }
|
5050 |
|
5051 | polyInOut.exponent = custom;
|
5052 |
|
5053 | return polyInOut;
|
5054 | })(exponent$1);
|
5055 |
|
5056 | var pi$4 = Math.PI,
|
5057 | halfPi$3 = pi$4 / 2;
|
5058 |
|
5059 | function sinIn(t) {
|
5060 | return (+t === 1) ? 1 : 1 - Math.cos(t * halfPi$3);
|
5061 | }
|
5062 |
|
5063 | function sinOut(t) {
|
5064 | return Math.sin(t * halfPi$3);
|
5065 | }
|
5066 |
|
5067 | function sinInOut(t) {
|
5068 | return (1 - Math.cos(pi$4 * t)) / 2;
|
5069 | }
|
5070 |
|
5071 |
|
5072 | function tpmt(x) {
|
5073 | return (Math.pow(2, -10 * x) - 0.0009765625) * 1.0009775171065494;
|
5074 | }
|
5075 |
|
5076 | function expIn(t) {
|
5077 | return tpmt(1 - +t);
|
5078 | }
|
5079 |
|
5080 | function expOut(t) {
|
5081 | return 1 - tpmt(t);
|
5082 | }
|
5083 |
|
5084 | function expInOut(t) {
|
5085 | return ((t *= 2) <= 1 ? tpmt(1 - t) : 2 - tpmt(t - 1)) / 2;
|
5086 | }
|
5087 |
|
5088 | function circleIn(t) {
|
5089 | return 1 - Math.sqrt(1 - t * t);
|
5090 | }
|
5091 |
|
5092 | function circleOut(t) {
|
5093 | return Math.sqrt(1 - --t * t);
|
5094 | }
|
5095 |
|
5096 | function circleInOut(t) {
|
5097 | return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
|
5098 | }
|
5099 |
|
5100 | var b1 = 4 / 11,
|
5101 | b2 = 6 / 11,
|
5102 | b3 = 8 / 11,
|
5103 | b4 = 3 / 4,
|
5104 | b5 = 9 / 11,
|
5105 | b6 = 10 / 11,
|
5106 | b7 = 15 / 16,
|
5107 | b8 = 21 / 22,
|
5108 | b9 = 63 / 64,
|
5109 | b0 = 1 / b1 / b1;
|
5110 |
|
5111 | function bounceIn(t) {
|
5112 | return 1 - bounceOut(1 - t);
|
5113 | }
|
5114 |
|
5115 | function bounceOut(t) {
|
5116 | 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;
|
5117 | }
|
5118 |
|
5119 | function bounceInOut(t) {
|
5120 | return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
|
5121 | }
|
5122 |
|
5123 | var overshoot = 1.70158;
|
5124 |
|
5125 | var backIn = (function custom(s) {
|
5126 | s = +s;
|
5127 |
|
5128 | function backIn(t) {
|
5129 | return (t = +t) * t * (s * (t - 1) + t);
|
5130 | }
|
5131 |
|
5132 | backIn.overshoot = custom;
|
5133 |
|
5134 | return backIn;
|
5135 | })(overshoot);
|
5136 |
|
5137 | var backOut = (function custom(s) {
|
5138 | s = +s;
|
5139 |
|
5140 | function backOut(t) {
|
5141 | return --t * t * ((t + 1) * s + t) + 1;
|
5142 | }
|
5143 |
|
5144 | backOut.overshoot = custom;
|
5145 |
|
5146 | return backOut;
|
5147 | })(overshoot);
|
5148 |
|
5149 | var backInOut = (function custom(s) {
|
5150 | s = +s;
|
5151 |
|
5152 | function backInOut(t) {
|
5153 | return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
|
5154 | }
|
5155 |
|
5156 | backInOut.overshoot = custom;
|
5157 |
|
5158 | return backInOut;
|
5159 | })(overshoot);
|
5160 |
|
5161 | var tau$5 = 2 * Math.PI,
|
5162 | amplitude = 1,
|
5163 | period = 0.3;
|
5164 |
|
5165 | var elasticIn = (function custom(a, p) {
|
5166 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
|
5167 |
|
5168 | function elasticIn(t) {
|
5169 | return a * tpmt(-(--t)) * Math.sin((s - t) / p);
|
5170 | }
|
5171 |
|
5172 | elasticIn.amplitude = function(a) { return custom(a, p * tau$5); };
|
5173 | elasticIn.period = function(p) { return custom(a, p); };
|
5174 |
|
5175 | return elasticIn;
|
5176 | })(amplitude, period);
|
5177 |
|
5178 | var elasticOut = (function custom(a, p) {
|
5179 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
|
5180 |
|
5181 | function elasticOut(t) {
|
5182 | return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p);
|
5183 | }
|
5184 |
|
5185 | elasticOut.amplitude = function(a) { return custom(a, p * tau$5); };
|
5186 | elasticOut.period = function(p) { return custom(a, p); };
|
5187 |
|
5188 | return elasticOut;
|
5189 | })(amplitude, period);
|
5190 |
|
5191 | var elasticInOut = (function custom(a, p) {
|
5192 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5);
|
5193 |
|
5194 | function elasticInOut(t) {
|
5195 | return ((t = t * 2 - 1) < 0
|
5196 | ? a * tpmt(-t) * Math.sin((s - t) / p)
|
5197 | : 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2;
|
5198 | }
|
5199 |
|
5200 | elasticInOut.amplitude = function(a) { return custom(a, p * tau$5); };
|
5201 | elasticInOut.period = function(p) { return custom(a, p); };
|
5202 |
|
5203 | return elasticInOut;
|
5204 | })(amplitude, period);
|
5205 |
|
5206 | var defaultTiming = {
|
5207 | time: null,
|
5208 | delay: 0,
|
5209 | duration: 250,
|
5210 | ease: cubicInOut
|
5211 | };
|
5212 |
|
5213 | function inherit(node, id) {
|
5214 | var timing;
|
5215 | while (!(timing = node.__transition) || !(timing = timing[id])) {
|
5216 | if (!(node = node.parentNode)) {
|
5217 | throw new Error(`transition ${id} not found`);
|
5218 | }
|
5219 | }
|
5220 | return timing;
|
5221 | }
|
5222 |
|
5223 | function selection_transition(name) {
|
5224 | var id,
|
5225 | timing;
|
5226 |
|
5227 | if (name instanceof Transition) {
|
5228 | id = name._id, name = name._name;
|
5229 | } else {
|
5230 | id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
|
5231 | }
|
5232 |
|
5233 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
5234 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
5235 | if (node = group[i]) {
|
5236 | schedule(node, name, id, i, group, timing || inherit(node, id));
|
5237 | }
|
5238 | }
|
5239 | }
|
5240 |
|
5241 | return new Transition(groups, this._parents, name, id);
|
5242 | }
|
5243 |
|
5244 | selection.prototype.interrupt = selection_interrupt;
|
5245 | selection.prototype.transition = selection_transition;
|
5246 |
|
5247 | var root = [null];
|
5248 |
|
5249 | function active(node, name) {
|
5250 | var schedules = node.__transition,
|
5251 | schedule,
|
5252 | i;
|
5253 |
|
5254 | if (schedules) {
|
5255 | name = name == null ? null : name + "";
|
5256 | for (i in schedules) {
|
5257 | if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
|
5258 | return new Transition([[node]], root, name, +i);
|
5259 | }
|
5260 | }
|
5261 | }
|
5262 |
|
5263 | return null;
|
5264 | }
|
5265 |
|
5266 | var constant$7 = x => () => x;
|
5267 |
|
5268 | function BrushEvent(type, {
|
5269 | sourceEvent,
|
5270 | target,
|
5271 | selection,
|
5272 | mode,
|
5273 | dispatch
|
5274 | }) {
|
5275 | Object.defineProperties(this, {
|
5276 | type: {value: type, enumerable: true, configurable: true},
|
5277 | sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
|
5278 | target: {value: target, enumerable: true, configurable: true},
|
5279 | selection: {value: selection, enumerable: true, configurable: true},
|
5280 | mode: {value: mode, enumerable: true, configurable: true},
|
5281 | _: {value: dispatch}
|
5282 | });
|
5283 | }
|
5284 |
|
5285 | function nopropagation$1(event) {
|
5286 | event.stopImmediatePropagation();
|
5287 | }
|
5288 |
|
5289 | function noevent$1(event) {
|
5290 | event.preventDefault();
|
5291 | event.stopImmediatePropagation();
|
5292 | }
|
5293 |
|
5294 | var MODE_DRAG = {name: "drag"},
|
5295 | MODE_SPACE = {name: "space"},
|
5296 | MODE_HANDLE = {name: "handle"},
|
5297 | MODE_CENTER = {name: "center"};
|
5298 |
|
5299 | const {abs: abs$3, max: max$2, min: min$1} = Math;
|
5300 |
|
5301 | function number1(e) {
|
5302 | return [+e[0], +e[1]];
|
5303 | }
|
5304 |
|
5305 | function number2(e) {
|
5306 | return [number1(e[0]), number1(e[1])];
|
5307 | }
|
5308 |
|
5309 | var X = {
|
5310 | name: "x",
|
5311 | handles: ["w", "e"].map(type),
|
5312 | input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
|
5313 | output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
|
5314 | };
|
5315 |
|
5316 | var Y = {
|
5317 | name: "y",
|
5318 | handles: ["n", "s"].map(type),
|
5319 | input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
|
5320 | output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
|
5321 | };
|
5322 |
|
5323 | var XY = {
|
5324 | name: "xy",
|
5325 | handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
|
5326 | input: function(xy) { return xy == null ? null : number2(xy); },
|
5327 | output: function(xy) { return xy; }
|
5328 | };
|
5329 |
|
5330 | var cursors = {
|
5331 | overlay: "crosshair",
|
5332 | selection: "move",
|
5333 | n: "ns-resize",
|
5334 | e: "ew-resize",
|
5335 | s: "ns-resize",
|
5336 | w: "ew-resize",
|
5337 | nw: "nwse-resize",
|
5338 | ne: "nesw-resize",
|
5339 | se: "nwse-resize",
|
5340 | sw: "nesw-resize"
|
5341 | };
|
5342 |
|
5343 | var flipX = {
|
5344 | e: "w",
|
5345 | w: "e",
|
5346 | nw: "ne",
|
5347 | ne: "nw",
|
5348 | se: "sw",
|
5349 | sw: "se"
|
5350 | };
|
5351 |
|
5352 | var flipY = {
|
5353 | n: "s",
|
5354 | s: "n",
|
5355 | nw: "sw",
|
5356 | ne: "se",
|
5357 | se: "ne",
|
5358 | sw: "nw"
|
5359 | };
|
5360 |
|
5361 | var signsX = {
|
5362 | overlay: +1,
|
5363 | selection: +1,
|
5364 | n: null,
|
5365 | e: +1,
|
5366 | s: null,
|
5367 | w: -1,
|
5368 | nw: -1,
|
5369 | ne: +1,
|
5370 | se: +1,
|
5371 | sw: -1
|
5372 | };
|
5373 |
|
5374 | var signsY = {
|
5375 | overlay: +1,
|
5376 | selection: +1,
|
5377 | n: -1,
|
5378 | e: null,
|
5379 | s: +1,
|
5380 | w: null,
|
5381 | nw: -1,
|
5382 | ne: -1,
|
5383 | se: +1,
|
5384 | sw: +1
|
5385 | };
|
5386 |
|
5387 | function type(t) {
|
5388 | return {type: t};
|
5389 | }
|
5390 |
|
5391 |
|
5392 | function defaultFilter$1(event) {
|
5393 | return !event.ctrlKey && !event.button;
|
5394 | }
|
5395 |
|
5396 | function defaultExtent$1() {
|
5397 | var svg = this.ownerSVGElement || this;
|
5398 | if (svg.hasAttribute("viewBox")) {
|
5399 | svg = svg.viewBox.baseVal;
|
5400 | return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
|
5401 | }
|
5402 | return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
|
5403 | }
|
5404 |
|
5405 | function defaultTouchable$1() {
|
5406 | return navigator.maxTouchPoints || ("ontouchstart" in this);
|
5407 | }
|
5408 |
|
5409 |
|
5410 | function local(node) {
|
5411 | while (!node.__brush) if (!(node = node.parentNode)) return;
|
5412 | return node.__brush;
|
5413 | }
|
5414 |
|
5415 | function empty(extent) {
|
5416 | return extent[0][0] === extent[1][0]
|
5417 | || extent[0][1] === extent[1][1];
|
5418 | }
|
5419 |
|
5420 | function brushSelection(node) {
|
5421 | var state = node.__brush;
|
5422 | return state ? state.dim.output(state.selection) : null;
|
5423 | }
|
5424 |
|
5425 | function brushX() {
|
5426 | return brush$1(X);
|
5427 | }
|
5428 |
|
5429 | function brushY() {
|
5430 | return brush$1(Y);
|
5431 | }
|
5432 |
|
5433 | function brush() {
|
5434 | return brush$1(XY);
|
5435 | }
|
5436 |
|
5437 | function brush$1(dim) {
|
5438 | var extent = defaultExtent$1,
|
5439 | filter = defaultFilter$1,
|
5440 | touchable = defaultTouchable$1,
|
5441 | keys = true,
|
5442 | listeners = dispatch("start", "brush", "end"),
|
5443 | handleSize = 6,
|
5444 | touchending;
|
5445 |
|
5446 | function brush(group) {
|
5447 | var overlay = group
|
5448 | .property("__brush", initialize)
|
5449 | .selectAll(".overlay")
|
5450 | .data([type("overlay")]);
|
5451 |
|
5452 | overlay.enter().append("rect")
|
5453 | .attr("class", "overlay")
|
5454 | .attr("pointer-events", "all")
|
5455 | .attr("cursor", cursors.overlay)
|
5456 | .merge(overlay)
|
5457 | .each(function() {
|
5458 | var extent = local(this).extent;
|
5459 | select(this)
|
5460 | .attr("x", extent[0][0])
|
5461 | .attr("y", extent[0][1])
|
5462 | .attr("width", extent[1][0] - extent[0][0])
|
5463 | .attr("height", extent[1][1] - extent[0][1]);
|
5464 | });
|
5465 |
|
5466 | group.selectAll(".selection")
|
5467 | .data([type("selection")])
|
5468 | .enter().append("rect")
|
5469 | .attr("class", "selection")
|
5470 | .attr("cursor", cursors.selection)
|
5471 | .attr("fill", "#777")
|
5472 | .attr("fill-opacity", 0.3)
|
5473 | .attr("stroke", "#fff")
|
5474 | .attr("shape-rendering", "crispEdges");
|
5475 |
|
5476 | var handle = group.selectAll(".handle")
|
5477 | .data(dim.handles, function(d) { return d.type; });
|
5478 |
|
5479 | handle.exit().remove();
|
5480 |
|
5481 | handle.enter().append("rect")
|
5482 | .attr("class", function(d) { return "handle handle--" + d.type; })
|
5483 | .attr("cursor", function(d) { return cursors[d.type]; });
|
5484 |
|
5485 | group
|
5486 | .each(redraw)
|
5487 | .attr("fill", "none")
|
5488 | .attr("pointer-events", "all")
|
5489 | .on("mousedown.brush", started)
|
5490 | .filter(touchable)
|
5491 | .on("touchstart.brush", started)
|
5492 | .on("touchmove.brush", touchmoved)
|
5493 | .on("touchend.brush touchcancel.brush", touchended)
|
5494 | .style("touch-action", "none")
|
5495 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
5496 | }
|
5497 |
|
5498 | brush.move = function(group, selection, event) {
|
5499 | if (group.tween) {
|
5500 | group
|
5501 | .on("start.brush", function(event) { emitter(this, arguments).beforestart().start(event); })
|
5502 | .on("interrupt.brush end.brush", function(event) { emitter(this, arguments).end(event); })
|
5503 | .tween("brush", function() {
|
5504 | var that = this,
|
5505 | state = that.__brush,
|
5506 | emit = emitter(that, arguments),
|
5507 | selection0 = state.selection,
|
5508 | selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
|
5509 | i = interpolate$2(selection0, selection1);
|
5510 |
|
5511 | function tween(t) {
|
5512 | state.selection = t === 1 && selection1 === null ? null : i(t);
|
5513 | redraw.call(that);
|
5514 | emit.brush();
|
5515 | }
|
5516 |
|
5517 | return selection0 !== null && selection1 !== null ? tween : tween(1);
|
5518 | });
|
5519 | } else {
|
5520 | group
|
5521 | .each(function() {
|
5522 | var that = this,
|
5523 | args = arguments,
|
5524 | state = that.__brush,
|
5525 | selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
|
5526 | emit = emitter(that, args).beforestart();
|
5527 |
|
5528 | interrupt(that);
|
5529 | state.selection = selection1 === null ? null : selection1;
|
5530 | redraw.call(that);
|
5531 | emit.start(event).brush(event).end(event);
|
5532 | });
|
5533 | }
|
5534 | };
|
5535 |
|
5536 | brush.clear = function(group, event) {
|
5537 | brush.move(group, null, event);
|
5538 | };
|
5539 |
|
5540 | function redraw() {
|
5541 | var group = select(this),
|
5542 | selection = local(this).selection;
|
5543 |
|
5544 | if (selection) {
|
5545 | group.selectAll(".selection")
|
5546 | .style("display", null)
|
5547 | .attr("x", selection[0][0])
|
5548 | .attr("y", selection[0][1])
|
5549 | .attr("width", selection[1][0] - selection[0][0])
|
5550 | .attr("height", selection[1][1] - selection[0][1]);
|
5551 |
|
5552 | group.selectAll(".handle")
|
5553 | .style("display", null)
|
5554 | .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
|
5555 | .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
|
5556 | .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
|
5557 | .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
|
5558 | }
|
5559 |
|
5560 | else {
|
5561 | group.selectAll(".selection,.handle")
|
5562 | .style("display", "none")
|
5563 | .attr("x", null)
|
5564 | .attr("y", null)
|
5565 | .attr("width", null)
|
5566 | .attr("height", null);
|
5567 | }
|
5568 | }
|
5569 |
|
5570 | function emitter(that, args, clean) {
|
5571 | var emit = that.__brush.emitter;
|
5572 | return emit && (!clean || !emit.clean) ? emit : new Emitter(that, args, clean);
|
5573 | }
|
5574 |
|
5575 | function Emitter(that, args, clean) {
|
5576 | this.that = that;
|
5577 | this.args = args;
|
5578 | this.state = that.__brush;
|
5579 | this.active = 0;
|
5580 | this.clean = clean;
|
5581 | }
|
5582 |
|
5583 | Emitter.prototype = {
|
5584 | beforestart: function() {
|
5585 | if (++this.active === 1) this.state.emitter = this, this.starting = true;
|
5586 | return this;
|
5587 | },
|
5588 | start: function(event, mode) {
|
5589 | if (this.starting) this.starting = false, this.emit("start", event, mode);
|
5590 | else this.emit("brush", event);
|
5591 | return this;
|
5592 | },
|
5593 | brush: function(event, mode) {
|
5594 | this.emit("brush", event, mode);
|
5595 | return this;
|
5596 | },
|
5597 | end: function(event, mode) {
|
5598 | if (--this.active === 0) delete this.state.emitter, this.emit("end", event, mode);
|
5599 | return this;
|
5600 | },
|
5601 | emit: function(type, event, mode) {
|
5602 | var d = select(this.that).datum();
|
5603 | listeners.call(
|
5604 | type,
|
5605 | this.that,
|
5606 | new BrushEvent(type, {
|
5607 | sourceEvent: event,
|
5608 | target: brush,
|
5609 | selection: dim.output(this.state.selection),
|
5610 | mode,
|
5611 | dispatch: listeners
|
5612 | }),
|
5613 | d
|
5614 | );
|
5615 | }
|
5616 | };
|
5617 |
|
5618 | function started(event) {
|
5619 | if (touchending && !event.touches) return;
|
5620 | if (!filter.apply(this, arguments)) return;
|
5621 |
|
5622 | var that = this,
|
5623 | type = event.target.__data__.type,
|
5624 | mode = (keys && event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && event.altKey ? MODE_CENTER : MODE_HANDLE),
|
5625 | signX = dim === Y ? null : signsX[type],
|
5626 | signY = dim === X ? null : signsY[type],
|
5627 | state = local(that),
|
5628 | extent = state.extent,
|
5629 | selection = state.selection,
|
5630 | W = extent[0][0], w0, w1,
|
5631 | N = extent[0][1], n0, n1,
|
5632 | E = extent[1][0], e0, e1,
|
5633 | S = extent[1][1], s0, s1,
|
5634 | dx = 0,
|
5635 | dy = 0,
|
5636 | moving,
|
5637 | shifting = signX && signY && keys && event.shiftKey,
|
5638 | lockX,
|
5639 | lockY,
|
5640 | points = Array.from(event.touches || [event], t => {
|
5641 | const i = t.identifier;
|
5642 | t = pointer(t, that);
|
5643 | t.point0 = t.slice();
|
5644 | t.identifier = i;
|
5645 | return t;
|
5646 | });
|
5647 |
|
5648 | interrupt(that);
|
5649 | var emit = emitter(that, arguments, true).beforestart();
|
5650 |
|
5651 | if (type === "overlay") {
|
5652 | if (selection) moving = true;
|
5653 | const pts = [points[0], points[1] || points[0]];
|
5654 | state.selection = selection = [[
|
5655 | w0 = dim === Y ? W : min$1(pts[0][0], pts[1][0]),
|
5656 | n0 = dim === X ? N : min$1(pts[0][1], pts[1][1])
|
5657 | ], [
|
5658 | e0 = dim === Y ? E : max$2(pts[0][0], pts[1][0]),
|
5659 | s0 = dim === X ? S : max$2(pts[0][1], pts[1][1])
|
5660 | ]];
|
5661 | if (points.length > 1) move(event);
|
5662 | } else {
|
5663 | w0 = selection[0][0];
|
5664 | n0 = selection[0][1];
|
5665 | e0 = selection[1][0];
|
5666 | s0 = selection[1][1];
|
5667 | }
|
5668 |
|
5669 | w1 = w0;
|
5670 | n1 = n0;
|
5671 | e1 = e0;
|
5672 | s1 = s0;
|
5673 |
|
5674 | var group = select(that)
|
5675 | .attr("pointer-events", "none");
|
5676 |
|
5677 | var overlay = group.selectAll(".overlay")
|
5678 | .attr("cursor", cursors[type]);
|
5679 |
|
5680 | if (event.touches) {
|
5681 | emit.moved = moved;
|
5682 | emit.ended = ended;
|
5683 | } else {
|
5684 | var view = select(event.view)
|
5685 | .on("mousemove.brush", moved, true)
|
5686 | .on("mouseup.brush", ended, true);
|
5687 | if (keys) view
|
5688 | .on("keydown.brush", keydowned, true)
|
5689 | .on("keyup.brush", keyupped, true);
|
5690 |
|
5691 | dragDisable(event.view);
|
5692 | }
|
5693 |
|
5694 | redraw.call(that);
|
5695 | emit.start(event, mode.name);
|
5696 |
|
5697 | function moved(event) {
|
5698 | for (const p of event.changedTouches || [event]) {
|
5699 | for (const d of points)
|
5700 | if (d.identifier === p.identifier) d.cur = pointer(p, that);
|
5701 | }
|
5702 | if (shifting && !lockX && !lockY && points.length === 1) {
|
5703 | const point = points[0];
|
5704 | if (abs$3(point.cur[0] - point[0]) > abs$3(point.cur[1] - point[1]))
|
5705 | lockY = true;
|
5706 | else
|
5707 | lockX = true;
|
5708 | }
|
5709 | for (const point of points)
|
5710 | if (point.cur) point[0] = point.cur[0], point[1] = point.cur[1];
|
5711 | moving = true;
|
5712 | noevent$1(event);
|
5713 | move(event);
|
5714 | }
|
5715 |
|
5716 | function move(event) {
|
5717 | const point = points[0], point0 = point.point0;
|
5718 | var t;
|
5719 |
|
5720 | dx = point[0] - point0[0];
|
5721 | dy = point[1] - point0[1];
|
5722 |
|
5723 | switch (mode) {
|
5724 | case MODE_SPACE:
|
5725 | case MODE_DRAG: {
|
5726 | if (signX) dx = max$2(W - w0, min$1(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
|
5727 | if (signY) dy = max$2(N - n0, min$1(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
|
5728 | break;
|
5729 | }
|
5730 | case MODE_HANDLE: {
|
5731 | if (points[1]) {
|
5732 | if (signX) w1 = max$2(W, min$1(E, points[0][0])), e1 = max$2(W, min$1(E, points[1][0])), signX = 1;
|
5733 | if (signY) n1 = max$2(N, min$1(S, points[0][1])), s1 = max$2(N, min$1(S, points[1][1])), signY = 1;
|
5734 | } else {
|
5735 | if (signX < 0) dx = max$2(W - w0, min$1(E - w0, dx)), w1 = w0 + dx, e1 = e0;
|
5736 | else if (signX > 0) dx = max$2(W - e0, min$1(E - e0, dx)), w1 = w0, e1 = e0 + dx;
|
5737 | if (signY < 0) dy = max$2(N - n0, min$1(S - n0, dy)), n1 = n0 + dy, s1 = s0;
|
5738 | else if (signY > 0) dy = max$2(N - s0, min$1(S - s0, dy)), n1 = n0, s1 = s0 + dy;
|
5739 | }
|
5740 | break;
|
5741 | }
|
5742 | case MODE_CENTER: {
|
5743 | if (signX) w1 = max$2(W, min$1(E, w0 - dx * signX)), e1 = max$2(W, min$1(E, e0 + dx * signX));
|
5744 | if (signY) n1 = max$2(N, min$1(S, n0 - dy * signY)), s1 = max$2(N, min$1(S, s0 + dy * signY));
|
5745 | break;
|
5746 | }
|
5747 | }
|
5748 |
|
5749 | if (e1 < w1) {
|
5750 | signX *= -1;
|
5751 | t = w0, w0 = e0, e0 = t;
|
5752 | t = w1, w1 = e1, e1 = t;
|
5753 | if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
|
5754 | }
|
5755 |
|
5756 | if (s1 < n1) {
|
5757 | signY *= -1;
|
5758 | t = n0, n0 = s0, s0 = t;
|
5759 | t = n1, n1 = s1, s1 = t;
|
5760 | if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
|
5761 | }
|
5762 |
|
5763 | if (state.selection) selection = state.selection;
|
5764 | if (lockX) w1 = selection[0][0], e1 = selection[1][0];
|
5765 | if (lockY) n1 = selection[0][1], s1 = selection[1][1];
|
5766 |
|
5767 | if (selection[0][0] !== w1
|
5768 | || selection[0][1] !== n1
|
5769 | || selection[1][0] !== e1
|
5770 | || selection[1][1] !== s1) {
|
5771 | state.selection = [[w1, n1], [e1, s1]];
|
5772 | redraw.call(that);
|
5773 | emit.brush(event, mode.name);
|
5774 | }
|
5775 | }
|
5776 |
|
5777 | function ended(event) {
|
5778 | nopropagation$1(event);
|
5779 | if (event.touches) {
|
5780 | if (event.touches.length) return;
|
5781 | if (touchending) clearTimeout(touchending);
|
5782 | touchending = setTimeout(function() { touchending = null; }, 500);
|
5783 | } else {
|
5784 | yesdrag(event.view, moving);
|
5785 | view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
|
5786 | }
|
5787 | group.attr("pointer-events", "all");
|
5788 | overlay.attr("cursor", cursors.overlay);
|
5789 | if (state.selection) selection = state.selection;
|
5790 | if (empty(selection)) state.selection = null, redraw.call(that);
|
5791 | emit.end(event, mode.name);
|
5792 | }
|
5793 |
|
5794 | function keydowned(event) {
|
5795 | switch (event.keyCode) {
|
5796 | case 16: {
|
5797 | shifting = signX && signY;
|
5798 | break;
|
5799 | }
|
5800 | case 18: {
|
5801 | if (mode === MODE_HANDLE) {
|
5802 | if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
|
5803 | if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
|
5804 | mode = MODE_CENTER;
|
5805 | move(event);
|
5806 | }
|
5807 | break;
|
5808 | }
|
5809 | case 32: {
|
5810 | if (mode === MODE_HANDLE || mode === MODE_CENTER) {
|
5811 | if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
|
5812 | if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
|
5813 | mode = MODE_SPACE;
|
5814 | overlay.attr("cursor", cursors.selection);
|
5815 | move(event);
|
5816 | }
|
5817 | break;
|
5818 | }
|
5819 | default: return;
|
5820 | }
|
5821 | noevent$1(event);
|
5822 | }
|
5823 |
|
5824 | function keyupped(event) {
|
5825 | switch (event.keyCode) {
|
5826 | case 16: {
|
5827 | if (shifting) {
|
5828 | lockX = lockY = shifting = false;
|
5829 | move(event);
|
5830 | }
|
5831 | break;
|
5832 | }
|
5833 | case 18: {
|
5834 | if (mode === MODE_CENTER) {
|
5835 | if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
|
5836 | if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
|
5837 | mode = MODE_HANDLE;
|
5838 | move(event);
|
5839 | }
|
5840 | break;
|
5841 | }
|
5842 | case 32: {
|
5843 | if (mode === MODE_SPACE) {
|
5844 | if (event.altKey) {
|
5845 | if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
|
5846 | if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
|
5847 | mode = MODE_CENTER;
|
5848 | } else {
|
5849 | if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
|
5850 | if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
|
5851 | mode = MODE_HANDLE;
|
5852 | }
|
5853 | overlay.attr("cursor", cursors[type]);
|
5854 | move(event);
|
5855 | }
|
5856 | break;
|
5857 | }
|
5858 | default: return;
|
5859 | }
|
5860 | noevent$1(event);
|
5861 | }
|
5862 | }
|
5863 |
|
5864 | function touchmoved(event) {
|
5865 | emitter(this, arguments).moved(event);
|
5866 | }
|
5867 |
|
5868 | function touchended(event) {
|
5869 | emitter(this, arguments).ended(event);
|
5870 | }
|
5871 |
|
5872 | function initialize() {
|
5873 | var state = this.__brush || {selection: null};
|
5874 | state.extent = number2(extent.apply(this, arguments));
|
5875 | state.dim = dim;
|
5876 | return state;
|
5877 | }
|
5878 |
|
5879 | brush.extent = function(_) {
|
5880 | return arguments.length ? (extent = typeof _ === "function" ? _ : constant$7(number2(_)), brush) : extent;
|
5881 | };
|
5882 |
|
5883 | brush.filter = function(_) {
|
5884 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), brush) : filter;
|
5885 | };
|
5886 |
|
5887 | brush.touchable = function(_) {
|
5888 | return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$7(!!_), brush) : touchable;
|
5889 | };
|
5890 |
|
5891 | brush.handleSize = function(_) {
|
5892 | return arguments.length ? (handleSize = +_, brush) : handleSize;
|
5893 | };
|
5894 |
|
5895 | brush.keyModifiers = function(_) {
|
5896 | return arguments.length ? (keys = !!_, brush) : keys;
|
5897 | };
|
5898 |
|
5899 | brush.on = function() {
|
5900 | var value = listeners.on.apply(listeners, arguments);
|
5901 | return value === listeners ? brush : value;
|
5902 | };
|
5903 |
|
5904 | return brush;
|
5905 | }
|
5906 |
|
5907 | var abs$2 = Math.abs;
|
5908 | var cos$2 = Math.cos;
|
5909 | var sin$2 = Math.sin;
|
5910 | var pi$3 = Math.PI;
|
5911 | var halfPi$2 = pi$3 / 2;
|
5912 | var tau$4 = pi$3 * 2;
|
5913 | var max$1 = Math.max;
|
5914 | var epsilon$5 = 1e-12;
|
5915 |
|
5916 | function range$1(i, j) {
|
5917 | return Array.from({length: j - i}, (_, k) => i + k);
|
5918 | }
|
5919 |
|
5920 | function compareValue(compare) {
|
5921 | return function(a, b) {
|
5922 | return compare(
|
5923 | a.source.value + a.target.value,
|
5924 | b.source.value + b.target.value
|
5925 | );
|
5926 | };
|
5927 | }
|
5928 |
|
5929 | function chord() {
|
5930 | return chord$1(false, false);
|
5931 | }
|
5932 |
|
5933 | function chordTranspose() {
|
5934 | return chord$1(false, true);
|
5935 | }
|
5936 |
|
5937 | function chordDirected() {
|
5938 | return chord$1(true, false);
|
5939 | }
|
5940 |
|
5941 | function chord$1(directed, transpose) {
|
5942 | var padAngle = 0,
|
5943 | sortGroups = null,
|
5944 | sortSubgroups = null,
|
5945 | sortChords = null;
|
5946 |
|
5947 | function chord(matrix) {
|
5948 | var n = matrix.length,
|
5949 | groupSums = new Array(n),
|
5950 | groupIndex = range$1(0, n),
|
5951 | chords = new Array(n * n),
|
5952 | groups = new Array(n),
|
5953 | k = 0, dx;
|
5954 |
|
5955 | matrix = Float64Array.from({length: n * n}, transpose
|
5956 | ? (_, i) => matrix[i % n][i / n | 0]
|
5957 | : (_, i) => matrix[i / n | 0][i % n]);
|
5958 |
|
5959 |
|
5960 | for (let i = 0; i < n; ++i) {
|
5961 | let x = 0;
|
5962 | for (let j = 0; j < n; ++j) x += matrix[i * n + j] + directed * matrix[j * n + i];
|
5963 | k += groupSums[i] = x;
|
5964 | }
|
5965 | k = max$1(0, tau$4 - padAngle * n) / k;
|
5966 | dx = k ? padAngle : tau$4 / n;
|
5967 |
|
5968 |
|
5969 | {
|
5970 | let x = 0;
|
5971 | if (sortGroups) groupIndex.sort((a, b) => sortGroups(groupSums[a], groupSums[b]));
|
5972 | for (const i of groupIndex) {
|
5973 | const x0 = x;
|
5974 | if (directed) {
|
5975 | const subgroupIndex = range$1(~n + 1, n).filter(j => j < 0 ? matrix[~j * n + i] : matrix[i * n + j]);
|
5976 | 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]));
|
5977 | for (const j of subgroupIndex) {
|
5978 | if (j < 0) {
|
5979 | const chord = chords[~j * n + i] || (chords[~j * n + i] = {source: null, target: null});
|
5980 | chord.target = {index: i, startAngle: x, endAngle: x += matrix[~j * n + i] * k, value: matrix[~j * n + i]};
|
5981 | } else {
|
5982 | const 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 | }
|
5985 | }
|
5986 | groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
|
5987 | } else {
|
5988 | const subgroupIndex = range$1(0, n).filter(j => matrix[i * n + j] || matrix[j * n + i]);
|
5989 | if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(matrix[i * n + a], matrix[i * n + b]));
|
5990 | for (const j of subgroupIndex) {
|
5991 | let chord;
|
5992 | if (i < j) {
|
5993 | chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null});
|
5994 | chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
|
5995 | } else {
|
5996 | chord = chords[j * n + i] || (chords[j * n + i] = {source: null, target: null});
|
5997 | chord.target = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]};
|
5998 | if (i === j) chord.source = chord.target;
|
5999 | }
|
6000 | if (chord.source && chord.target && chord.source.value < chord.target.value) {
|
6001 | const source = chord.source;
|
6002 | chord.source = chord.target;
|
6003 | chord.target = source;
|
6004 | }
|
6005 | }
|
6006 | groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]};
|
6007 | }
|
6008 | x += dx;
|
6009 | }
|
6010 | }
|
6011 |
|
6012 |
|
6013 | chords = Object.values(chords);
|
6014 | chords.groups = groups;
|
6015 | return sortChords ? chords.sort(sortChords) : chords;
|
6016 | }
|
6017 |
|
6018 | chord.padAngle = function(_) {
|
6019 | return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
|
6020 | };
|
6021 |
|
6022 | chord.sortGroups = function(_) {
|
6023 | return arguments.length ? (sortGroups = _, chord) : sortGroups;
|
6024 | };
|
6025 |
|
6026 | chord.sortSubgroups = function(_) {
|
6027 | return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
|
6028 | };
|
6029 |
|
6030 | chord.sortChords = function(_) {
|
6031 | return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
|
6032 | };
|
6033 |
|
6034 | return chord;
|
6035 | }
|
6036 |
|
6037 | const pi$2 = Math.PI,
|
6038 | tau$3 = 2 * pi$2,
|
6039 | epsilon$4 = 1e-6,
|
6040 | tauEpsilon = tau$3 - epsilon$4;
|
6041 |
|
6042 | function append$1(strings) {
|
6043 | this._ += strings[0];
|
6044 | for (let i = 1, n = strings.length; i < n; ++i) {
|
6045 | this._ += arguments[i] + strings[i];
|
6046 | }
|
6047 | }
|
6048 |
|
6049 | function appendRound$1(digits) {
|
6050 | let d = Math.floor(digits);
|
6051 | if (!(d >= 0)) throw new Error(`invalid digits: ${digits}`);
|
6052 | if (d > 15) return append$1;
|
6053 | const k = 10 ** d;
|
6054 | return function(strings) {
|
6055 | this._ += strings[0];
|
6056 | for (let i = 1, n = strings.length; i < n; ++i) {
|
6057 | this._ += Math.round(arguments[i] * k) / k + strings[i];
|
6058 | }
|
6059 | };
|
6060 | }
|
6061 |
|
6062 | let Path$1 = class Path {
|
6063 | constructor(digits) {
|
6064 | this._x0 = this._y0 =
|
6065 | this._x1 = this._y1 = null;
|
6066 | this._ = "";
|
6067 | this._append = digits == null ? append$1 : appendRound$1(digits);
|
6068 | }
|
6069 | moveTo(x, y) {
|
6070 | this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
|
6071 | }
|
6072 | closePath() {
|
6073 | if (this._x1 !== null) {
|
6074 | this._x1 = this._x0, this._y1 = this._y0;
|
6075 | this._append`Z`;
|
6076 | }
|
6077 | }
|
6078 | lineTo(x, y) {
|
6079 | this._append`L${this._x1 = +x},${this._y1 = +y}`;
|
6080 | }
|
6081 | quadraticCurveTo(x1, y1, x, y) {
|
6082 | this._append`Q${+x1},${+y1},${this._x1 = +x},${this._y1 = +y}`;
|
6083 | }
|
6084 | bezierCurveTo(x1, y1, x2, y2, x, y) {
|
6085 | this._append`C${+x1},${+y1},${+x2},${+y2},${this._x1 = +x},${this._y1 = +y}`;
|
6086 | }
|
6087 | arcTo(x1, y1, x2, y2, r) {
|
6088 | x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
|
6089 |
|
6090 |
|
6091 | if (r < 0) throw new Error(`negative radius: ${r}`);
|
6092 |
|
6093 | let x0 = this._x1,
|
6094 | y0 = this._y1,
|
6095 | x21 = x2 - x1,
|
6096 | y21 = y2 - y1,
|
6097 | x01 = x0 - x1,
|
6098 | y01 = y0 - y1,
|
6099 | l01_2 = x01 * x01 + y01 * y01;
|
6100 |
|
6101 |
|
6102 | if (this._x1 === null) {
|
6103 | this._append`M${this._x1 = x1},${this._y1 = y1}`;
|
6104 | }
|
6105 |
|
6106 |
|
6107 | else if (!(l01_2 > epsilon$4));
|
6108 |
|
6109 |
|
6110 |
|
6111 |
|
6112 | else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$4) || !r) {
|
6113 | this._append`L${this._x1 = x1},${this._y1 = y1}`;
|
6114 | }
|
6115 |
|
6116 |
|
6117 | else {
|
6118 | let x20 = x2 - x0,
|
6119 | y20 = y2 - y0,
|
6120 | l21_2 = x21 * x21 + y21 * y21,
|
6121 | l20_2 = x20 * x20 + y20 * y20,
|
6122 | l21 = Math.sqrt(l21_2),
|
6123 | l01 = Math.sqrt(l01_2),
|
6124 | l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
|
6125 | t01 = l / l01,
|
6126 | t21 = l / l21;
|
6127 |
|
6128 |
|
6129 | if (Math.abs(t01 - 1) > epsilon$4) {
|
6130 | this._append`L${x1 + t01 * x01},${y1 + t01 * y01}`;
|
6131 | }
|
6132 |
|
6133 | this._append`A${r},${r},0,0,${+(y01 * x20 > x01 * y20)},${this._x1 = x1 + t21 * x21},${this._y1 = y1 + t21 * y21}`;
|
6134 | }
|
6135 | }
|
6136 | arc(x, y, r, a0, a1, ccw) {
|
6137 | x = +x, y = +y, r = +r, ccw = !!ccw;
|
6138 |
|
6139 |
|
6140 | if (r < 0) throw new Error(`negative radius: ${r}`);
|
6141 |
|
6142 | let dx = r * Math.cos(a0),
|
6143 | dy = r * Math.sin(a0),
|
6144 | x0 = x + dx,
|
6145 | y0 = y + dy,
|
6146 | cw = 1 ^ ccw,
|
6147 | da = ccw ? a0 - a1 : a1 - a0;
|
6148 |
|
6149 |
|
6150 | if (this._x1 === null) {
|
6151 | this._append`M${x0},${y0}`;
|
6152 | }
|
6153 |
|
6154 |
|
6155 | else if (Math.abs(this._x1 - x0) > epsilon$4 || Math.abs(this._y1 - y0) > epsilon$4) {
|
6156 | this._append`L${x0},${y0}`;
|
6157 | }
|
6158 |
|
6159 |
|
6160 | if (!r) return;
|
6161 |
|
6162 |
|
6163 | if (da < 0) da = da % tau$3 + tau$3;
|
6164 |
|
6165 |
|
6166 | if (da > tauEpsilon) {
|
6167 | this._append`A${r},${r},0,1,${cw},${x - dx},${y - dy}A${r},${r},0,1,${cw},${this._x1 = x0},${this._y1 = y0}`;
|
6168 | }
|
6169 |
|
6170 |
|
6171 | else if (da > epsilon$4) {
|
6172 | this._append`A${r},${r},0,${+(da >= pi$2)},${cw},${this._x1 = x + r * Math.cos(a1)},${this._y1 = y + r * Math.sin(a1)}`;
|
6173 | }
|
6174 | }
|
6175 | rect(x, y, w, h) {
|
6176 | this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${w = +w}v${+h}h${-w}Z`;
|
6177 | }
|
6178 | toString() {
|
6179 | return this._;
|
6180 | }
|
6181 | };
|
6182 |
|
6183 | function path() {
|
6184 | return new Path$1;
|
6185 | }
|
6186 |
|
6187 |
|
6188 | path.prototype = Path$1.prototype;
|
6189 |
|
6190 | function pathRound(digits = 3) {
|
6191 | return new Path$1(+digits);
|
6192 | }
|
6193 |
|
6194 | var slice$2 = Array.prototype.slice;
|
6195 |
|
6196 | function constant$6(x) {
|
6197 | return function() {
|
6198 | return x;
|
6199 | };
|
6200 | }
|
6201 |
|
6202 | function defaultSource$1(d) {
|
6203 | return d.source;
|
6204 | }
|
6205 |
|
6206 | function defaultTarget(d) {
|
6207 | return d.target;
|
6208 | }
|
6209 |
|
6210 | function defaultRadius$1(d) {
|
6211 | return d.radius;
|
6212 | }
|
6213 |
|
6214 | function defaultStartAngle(d) {
|
6215 | return d.startAngle;
|
6216 | }
|
6217 |
|
6218 | function defaultEndAngle(d) {
|
6219 | return d.endAngle;
|
6220 | }
|
6221 |
|
6222 | function defaultPadAngle() {
|
6223 | return 0;
|
6224 | }
|
6225 |
|
6226 | function defaultArrowheadRadius() {
|
6227 | return 10;
|
6228 | }
|
6229 |
|
6230 | function ribbon(headRadius) {
|
6231 | var source = defaultSource$1,
|
6232 | target = defaultTarget,
|
6233 | sourceRadius = defaultRadius$1,
|
6234 | targetRadius = defaultRadius$1,
|
6235 | startAngle = defaultStartAngle,
|
6236 | endAngle = defaultEndAngle,
|
6237 | padAngle = defaultPadAngle,
|
6238 | context = null;
|
6239 |
|
6240 | function ribbon() {
|
6241 | var buffer,
|
6242 | s = source.apply(this, arguments),
|
6243 | t = target.apply(this, arguments),
|
6244 | ap = padAngle.apply(this, arguments) / 2,
|
6245 | argv = slice$2.call(arguments),
|
6246 | sr = +sourceRadius.apply(this, (argv[0] = s, argv)),
|
6247 | sa0 = startAngle.apply(this, argv) - halfPi$2,
|
6248 | sa1 = endAngle.apply(this, argv) - halfPi$2,
|
6249 | tr = +targetRadius.apply(this, (argv[0] = t, argv)),
|
6250 | ta0 = startAngle.apply(this, argv) - halfPi$2,
|
6251 | ta1 = endAngle.apply(this, argv) - halfPi$2;
|
6252 |
|
6253 | if (!context) context = buffer = path();
|
6254 |
|
6255 | if (ap > epsilon$5) {
|
6256 | if (abs$2(sa1 - sa0) > ap * 2 + epsilon$5) sa1 > sa0 ? (sa0 += ap, sa1 -= ap) : (sa0 -= ap, sa1 += ap);
|
6257 | else sa0 = sa1 = (sa0 + sa1) / 2;
|
6258 | if (abs$2(ta1 - ta0) > ap * 2 + epsilon$5) ta1 > ta0 ? (ta0 += ap, ta1 -= ap) : (ta0 -= ap, ta1 += ap);
|
6259 | else ta0 = ta1 = (ta0 + ta1) / 2;
|
6260 | }
|
6261 |
|
6262 | context.moveTo(sr * cos$2(sa0), sr * sin$2(sa0));
|
6263 | context.arc(0, 0, sr, sa0, sa1);
|
6264 | if (sa0 !== ta0 || sa1 !== ta1) {
|
6265 | if (headRadius) {
|
6266 | var hr = +headRadius.apply(this, arguments), tr2 = tr - hr, ta2 = (ta0 + ta1) / 2;
|
6267 | context.quadraticCurveTo(0, 0, tr2 * cos$2(ta0), tr2 * sin$2(ta0));
|
6268 | context.lineTo(tr * cos$2(ta2), tr * sin$2(ta2));
|
6269 | context.lineTo(tr2 * cos$2(ta1), tr2 * sin$2(ta1));
|
6270 | } else {
|
6271 | context.quadraticCurveTo(0, 0, tr * cos$2(ta0), tr * sin$2(ta0));
|
6272 | context.arc(0, 0, tr, ta0, ta1);
|
6273 | }
|
6274 | }
|
6275 | context.quadraticCurveTo(0, 0, sr * cos$2(sa0), sr * sin$2(sa0));
|
6276 | context.closePath();
|
6277 |
|
6278 | if (buffer) return context = null, buffer + "" || null;
|
6279 | }
|
6280 |
|
6281 | if (headRadius) ribbon.headRadius = function(_) {
|
6282 | return arguments.length ? (headRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : headRadius;
|
6283 | };
|
6284 |
|
6285 | ribbon.radius = function(_) {
|
6286 | return arguments.length ? (sourceRadius = targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
|
6287 | };
|
6288 |
|
6289 | ribbon.sourceRadius = function(_) {
|
6290 | return arguments.length ? (sourceRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius;
|
6291 | };
|
6292 |
|
6293 | ribbon.targetRadius = function(_) {
|
6294 | return arguments.length ? (targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : targetRadius;
|
6295 | };
|
6296 |
|
6297 | ribbon.startAngle = function(_) {
|
6298 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : startAngle;
|
6299 | };
|
6300 |
|
6301 | ribbon.endAngle = function(_) {
|
6302 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : endAngle;
|
6303 | };
|
6304 |
|
6305 | ribbon.padAngle = function(_) {
|
6306 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : padAngle;
|
6307 | };
|
6308 |
|
6309 | ribbon.source = function(_) {
|
6310 | return arguments.length ? (source = _, ribbon) : source;
|
6311 | };
|
6312 |
|
6313 | ribbon.target = function(_) {
|
6314 | return arguments.length ? (target = _, ribbon) : target;
|
6315 | };
|
6316 |
|
6317 | ribbon.context = function(_) {
|
6318 | return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
|
6319 | };
|
6320 |
|
6321 | return ribbon;
|
6322 | }
|
6323 |
|
6324 | function ribbon$1() {
|
6325 | return ribbon();
|
6326 | }
|
6327 |
|
6328 | function ribbonArrow() {
|
6329 | return ribbon(defaultArrowheadRadius);
|
6330 | }
|
6331 |
|
6332 | var array$2 = Array.prototype;
|
6333 |
|
6334 | var slice$1 = array$2.slice;
|
6335 |
|
6336 | function ascending$1(a, b) {
|
6337 | return a - b;
|
6338 | }
|
6339 |
|
6340 | function area$3(ring) {
|
6341 | var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
|
6342 | while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
|
6343 | return area;
|
6344 | }
|
6345 |
|
6346 | var constant$5 = x => () => x;
|
6347 |
|
6348 | function contains$2(ring, hole) {
|
6349 | var i = -1, n = hole.length, c;
|
6350 | while (++i < n) if (c = ringContains(ring, hole[i])) return c;
|
6351 | return 0;
|
6352 | }
|
6353 |
|
6354 | function ringContains(ring, point) {
|
6355 | var x = point[0], y = point[1], contains = -1;
|
6356 | for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
|
6357 | var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
|
6358 | if (segmentContains(pi, pj, point)) return 0;
|
6359 | if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
|
6360 | }
|
6361 | return contains;
|
6362 | }
|
6363 |
|
6364 | function segmentContains(a, b, c) {
|
6365 | var i; return collinear$1(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
|
6366 | }
|
6367 |
|
6368 | function collinear$1(a, b, c) {
|
6369 | return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
|
6370 | }
|
6371 |
|
6372 | function within(p, q, r) {
|
6373 | return p <= q && q <= r || r <= q && q <= p;
|
6374 | }
|
6375 |
|
6376 | function noop$2() {}
|
6377 |
|
6378 | var cases = [
|
6379 | [],
|
6380 | [[[1.0, 1.5], [0.5, 1.0]]],
|
6381 | [[[1.5, 1.0], [1.0, 1.5]]],
|
6382 | [[[1.5, 1.0], [0.5, 1.0]]],
|
6383 | [[[1.0, 0.5], [1.5, 1.0]]],
|
6384 | [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
|
6385 | [[[1.0, 0.5], [1.0, 1.5]]],
|
6386 | [[[1.0, 0.5], [0.5, 1.0]]],
|
6387 | [[[0.5, 1.0], [1.0, 0.5]]],
|
6388 | [[[1.0, 1.5], [1.0, 0.5]]],
|
6389 | [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
|
6390 | [[[1.5, 1.0], [1.0, 0.5]]],
|
6391 | [[[0.5, 1.0], [1.5, 1.0]]],
|
6392 | [[[1.0, 1.5], [1.5, 1.0]]],
|
6393 | [[[0.5, 1.0], [1.0, 1.5]]],
|
6394 | []
|
6395 | ];
|
6396 |
|
6397 | function Contours() {
|
6398 | var dx = 1,
|
6399 | dy = 1,
|
6400 | threshold = thresholdSturges,
|
6401 | smooth = smoothLinear;
|
6402 |
|
6403 | function contours(values) {
|
6404 | var tz = threshold(values);
|
6405 |
|
6406 |
|
6407 | if (!Array.isArray(tz)) {
|
6408 | const e = extent$1(values, finite);
|
6409 | tz = ticks(...nice$1(e[0], e[1], tz), tz);
|
6410 | while (tz[tz.length - 1] >= e[1]) tz.pop();
|
6411 | while (tz[1] < e[0]) tz.shift();
|
6412 | } else {
|
6413 | tz = tz.slice().sort(ascending$1);
|
6414 | }
|
6415 |
|
6416 | return tz.map(value => contour(values, value));
|
6417 | }
|
6418 |
|
6419 |
|
6420 |
|
6421 | function contour(values, value) {
|
6422 | const v = value == null ? NaN : +value;
|
6423 | if (isNaN(v)) throw new Error(`invalid value: ${value}`);
|
6424 |
|
6425 | var polygons = [],
|
6426 | holes = [];
|
6427 |
|
6428 | isorings(values, v, function(ring) {
|
6429 | smooth(ring, values, v);
|
6430 | if (area$3(ring) > 0) polygons.push([ring]);
|
6431 | else holes.push(ring);
|
6432 | });
|
6433 |
|
6434 | holes.forEach(function(hole) {
|
6435 | for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
|
6436 | if (contains$2((polygon = polygons[i])[0], hole) !== -1) {
|
6437 | polygon.push(hole);
|
6438 | return;
|
6439 | }
|
6440 | }
|
6441 | });
|
6442 |
|
6443 | return {
|
6444 | type: "MultiPolygon",
|
6445 | value: value,
|
6446 | coordinates: polygons
|
6447 | };
|
6448 | }
|
6449 |
|
6450 |
|
6451 |
|
6452 | function isorings(values, value, callback) {
|
6453 | var fragmentByStart = new Array,
|
6454 | fragmentByEnd = new Array,
|
6455 | x, y, t0, t1, t2, t3;
|
6456 |
|
6457 |
|
6458 | x = y = -1;
|
6459 | t1 = above(values[0], value);
|
6460 | cases[t1 << 1].forEach(stitch);
|
6461 | while (++x < dx - 1) {
|
6462 | t0 = t1, t1 = above(values[x + 1], value);
|
6463 | cases[t0 | t1 << 1].forEach(stitch);
|
6464 | }
|
6465 | cases[t1 << 0].forEach(stitch);
|
6466 |
|
6467 |
|
6468 | while (++y < dy - 1) {
|
6469 | x = -1;
|
6470 | t1 = above(values[y * dx + dx], value);
|
6471 | t2 = above(values[y * dx], value);
|
6472 | cases[t1 << 1 | t2 << 2].forEach(stitch);
|
6473 | while (++x < dx - 1) {
|
6474 | t0 = t1, t1 = above(values[y * dx + dx + x + 1], value);
|
6475 | t3 = t2, t2 = above(values[y * dx + x + 1], value);
|
6476 | cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
|
6477 | }
|
6478 | cases[t1 | t2 << 3].forEach(stitch);
|
6479 | }
|
6480 |
|
6481 |
|
6482 | x = -1;
|
6483 | t2 = values[y * dx] >= value;
|
6484 | cases[t2 << 2].forEach(stitch);
|
6485 | while (++x < dx - 1) {
|
6486 | t3 = t2, t2 = above(values[y * dx + x + 1], value);
|
6487 | cases[t2 << 2 | t3 << 3].forEach(stitch);
|
6488 | }
|
6489 | cases[t2 << 3].forEach(stitch);
|
6490 |
|
6491 | function stitch(line) {
|
6492 | var start = [line[0][0] + x, line[0][1] + y],
|
6493 | end = [line[1][0] + x, line[1][1] + y],
|
6494 | startIndex = index(start),
|
6495 | endIndex = index(end),
|
6496 | f, g;
|
6497 | if (f = fragmentByEnd[startIndex]) {
|
6498 | if (g = fragmentByStart[endIndex]) {
|
6499 | delete fragmentByEnd[f.end];
|
6500 | delete fragmentByStart[g.start];
|
6501 | if (f === g) {
|
6502 | f.ring.push(end);
|
6503 | callback(f.ring);
|
6504 | } else {
|
6505 | fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
|
6506 | }
|
6507 | } else {
|
6508 | delete fragmentByEnd[f.end];
|
6509 | f.ring.push(end);
|
6510 | fragmentByEnd[f.end = endIndex] = f;
|
6511 | }
|
6512 | } else if (f = fragmentByStart[endIndex]) {
|
6513 | if (g = fragmentByEnd[startIndex]) {
|
6514 | delete fragmentByStart[f.start];
|
6515 | delete fragmentByEnd[g.end];
|
6516 | if (f === g) {
|
6517 | f.ring.push(end);
|
6518 | callback(f.ring);
|
6519 | } else {
|
6520 | fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
|
6521 | }
|
6522 | } else {
|
6523 | delete fragmentByStart[f.start];
|
6524 | f.ring.unshift(start);
|
6525 | fragmentByStart[f.start = startIndex] = f;
|
6526 | }
|
6527 | } else {
|
6528 | fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
|
6529 | }
|
6530 | }
|
6531 | }
|
6532 |
|
6533 | function index(point) {
|
6534 | return point[0] * 2 + point[1] * (dx + 1) * 4;
|
6535 | }
|
6536 |
|
6537 | function smoothLinear(ring, values, value) {
|
6538 | ring.forEach(function(point) {
|
6539 | var x = point[0],
|
6540 | y = point[1],
|
6541 | xt = x | 0,
|
6542 | yt = y | 0,
|
6543 | v1 = valid(values[yt * dx + xt]);
|
6544 | if (x > 0 && x < dx && xt === x) {
|
6545 | point[0] = smooth1(x, valid(values[yt * dx + xt - 1]), v1, value);
|
6546 | }
|
6547 | if (y > 0 && y < dy && yt === y) {
|
6548 | point[1] = smooth1(y, valid(values[(yt - 1) * dx + xt]), v1, value);
|
6549 | }
|
6550 | });
|
6551 | }
|
6552 |
|
6553 | contours.contour = contour;
|
6554 |
|
6555 | contours.size = function(_) {
|
6556 | if (!arguments.length) return [dx, dy];
|
6557 | var _0 = Math.floor(_[0]), _1 = Math.floor(_[1]);
|
6558 | if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
|
6559 | return dx = _0, dy = _1, contours;
|
6560 | };
|
6561 |
|
6562 | contours.thresholds = function(_) {
|
6563 | return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), contours) : threshold;
|
6564 | };
|
6565 |
|
6566 | contours.smooth = function(_) {
|
6567 | return arguments.length ? (smooth = _ ? smoothLinear : noop$2, contours) : smooth === smoothLinear;
|
6568 | };
|
6569 |
|
6570 | return contours;
|
6571 | }
|
6572 |
|
6573 |
|
6574 | function finite(x) {
|
6575 | return isFinite(x) ? x : NaN;
|
6576 | }
|
6577 |
|
6578 |
|
6579 |
|
6580 | function above(x, value) {
|
6581 | return x == null ? false : +x >= value;
|
6582 | }
|
6583 |
|
6584 |
|
6585 | function valid(v) {
|
6586 | return v == null || isNaN(v = +v) ? -Infinity : v;
|
6587 | }
|
6588 |
|
6589 | function smooth1(x, v0, v1, value) {
|
6590 | const a = value - v0;
|
6591 | const b = v1 - v0;
|
6592 | const d = isFinite(a) || isFinite(b) ? a / b : Math.sign(a) / Math.sign(b);
|
6593 | return isNaN(d) ? x : x + d - 0.5;
|
6594 | }
|
6595 |
|
6596 | function defaultX$1(d) {
|
6597 | return d[0];
|
6598 | }
|
6599 |
|
6600 | function defaultY$1(d) {
|
6601 | return d[1];
|
6602 | }
|
6603 |
|
6604 | function defaultWeight() {
|
6605 | return 1;
|
6606 | }
|
6607 |
|
6608 | function density() {
|
6609 | var x = defaultX$1,
|
6610 | y = defaultY$1,
|
6611 | weight = defaultWeight,
|
6612 | dx = 960,
|
6613 | dy = 500,
|
6614 | r = 20,
|
6615 | k = 2,
|
6616 | o = r * 3,
|
6617 | n = (dx + o * 2) >> k,
|
6618 | m = (dy + o * 2) >> k,
|
6619 | threshold = constant$5(20);
|
6620 |
|
6621 | function grid(data) {
|
6622 | var values = new Float32Array(n * m),
|
6623 | pow2k = Math.pow(2, -k),
|
6624 | i = -1;
|
6625 |
|
6626 | for (const d of data) {
|
6627 | var xi = (x(d, ++i, data) + o) * pow2k,
|
6628 | yi = (y(d, i, data) + o) * pow2k,
|
6629 | wi = +weight(d, i, data);
|
6630 | if (wi && xi >= 0 && xi < n && yi >= 0 && yi < m) {
|
6631 | var x0 = Math.floor(xi),
|
6632 | y0 = Math.floor(yi),
|
6633 | xt = xi - x0 - 0.5,
|
6634 | yt = yi - y0 - 0.5;
|
6635 | values[x0 + y0 * n] += (1 - xt) * (1 - yt) * wi;
|
6636 | values[x0 + 1 + y0 * n] += xt * (1 - yt) * wi;
|
6637 | values[x0 + 1 + (y0 + 1) * n] += xt * yt * wi;
|
6638 | values[x0 + (y0 + 1) * n] += (1 - xt) * yt * wi;
|
6639 | }
|
6640 | }
|
6641 |
|
6642 | blur2({data: values, width: n, height: m}, r * pow2k);
|
6643 | return values;
|
6644 | }
|
6645 |
|
6646 | function density(data) {
|
6647 | var values = grid(data),
|
6648 | tz = threshold(values),
|
6649 | pow4k = Math.pow(2, 2 * k);
|
6650 |
|
6651 |
|
6652 | if (!Array.isArray(tz)) {
|
6653 | tz = ticks(Number.MIN_VALUE, max$3(values) / pow4k, tz);
|
6654 | }
|
6655 |
|
6656 | return Contours()
|
6657 | .size([n, m])
|
6658 | .thresholds(tz.map(d => d * pow4k))
|
6659 | (values)
|
6660 | .map((c, i) => (c.value = +tz[i], transform(c)));
|
6661 | }
|
6662 |
|
6663 | density.contours = function(data) {
|
6664 | var values = grid(data),
|
6665 | contours = Contours().size([n, m]),
|
6666 | pow4k = Math.pow(2, 2 * k),
|
6667 | contour = value => {
|
6668 | value = +value;
|
6669 | var c = transform(contours.contour(values, value * pow4k));
|
6670 | c.value = value;
|
6671 | return c;
|
6672 | };
|
6673 | Object.defineProperty(contour, "max", {get: () => max$3(values) / pow4k});
|
6674 | return contour;
|
6675 | };
|
6676 |
|
6677 | function transform(geometry) {
|
6678 | geometry.coordinates.forEach(transformPolygon);
|
6679 | return geometry;
|
6680 | }
|
6681 |
|
6682 | function transformPolygon(coordinates) {
|
6683 | coordinates.forEach(transformRing);
|
6684 | }
|
6685 |
|
6686 | function transformRing(coordinates) {
|
6687 | coordinates.forEach(transformPoint);
|
6688 | }
|
6689 |
|
6690 |
|
6691 | function transformPoint(coordinates) {
|
6692 | coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
|
6693 | coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
|
6694 | }
|
6695 |
|
6696 | function resize() {
|
6697 | o = r * 3;
|
6698 | n = (dx + o * 2) >> k;
|
6699 | m = (dy + o * 2) >> k;
|
6700 | return density;
|
6701 | }
|
6702 |
|
6703 | density.x = function(_) {
|
6704 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$5(+_), density) : x;
|
6705 | };
|
6706 |
|
6707 | density.y = function(_) {
|
6708 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$5(+_), density) : y;
|
6709 | };
|
6710 |
|
6711 | density.weight = function(_) {
|
6712 | return arguments.length ? (weight = typeof _ === "function" ? _ : constant$5(+_), density) : weight;
|
6713 | };
|
6714 |
|
6715 | density.size = function(_) {
|
6716 | if (!arguments.length) return [dx, dy];
|
6717 | var _0 = +_[0], _1 = +_[1];
|
6718 | if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size");
|
6719 | return dx = _0, dy = _1, resize();
|
6720 | };
|
6721 |
|
6722 | density.cellSize = function(_) {
|
6723 | if (!arguments.length) return 1 << k;
|
6724 | if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
|
6725 | return k = Math.floor(Math.log(_) / Math.LN2), resize();
|
6726 | };
|
6727 |
|
6728 | density.thresholds = function(_) {
|
6729 | return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), density) : threshold;
|
6730 | };
|
6731 |
|
6732 | density.bandwidth = function(_) {
|
6733 | if (!arguments.length) return Math.sqrt(r * (r + 1));
|
6734 | if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
|
6735 | return r = (Math.sqrt(4 * _ * _ + 1) - 1) / 2, resize();
|
6736 | };
|
6737 |
|
6738 | return density;
|
6739 | }
|
6740 |
|
6741 | const epsilon$3 = 1.1102230246251565e-16;
|
6742 | const splitter = 134217729;
|
6743 | const resulterrbound = (3 + 8 * epsilon$3) * epsilon$3;
|
6744 |
|
6745 |
|
6746 | function sum$1(elen, e, flen, f, h) {
|
6747 | let Q, Qnew, hh, bvirt;
|
6748 | let enow = e[0];
|
6749 | let fnow = f[0];
|
6750 | let eindex = 0;
|
6751 | let findex = 0;
|
6752 | if ((fnow > enow) === (fnow > -enow)) {
|
6753 | Q = enow;
|
6754 | enow = e[++eindex];
|
6755 | } else {
|
6756 | Q = fnow;
|
6757 | fnow = f[++findex];
|
6758 | }
|
6759 | let hindex = 0;
|
6760 | if (eindex < elen && findex < flen) {
|
6761 | if ((fnow > enow) === (fnow > -enow)) {
|
6762 | Qnew = enow + Q;
|
6763 | hh = Q - (Qnew - enow);
|
6764 | enow = e[++eindex];
|
6765 | } else {
|
6766 | Qnew = fnow + Q;
|
6767 | hh = Q - (Qnew - fnow);
|
6768 | fnow = f[++findex];
|
6769 | }
|
6770 | Q = Qnew;
|
6771 | if (hh !== 0) {
|
6772 | h[hindex++] = hh;
|
6773 | }
|
6774 | while (eindex < elen && findex < flen) {
|
6775 | if ((fnow > enow) === (fnow > -enow)) {
|
6776 | Qnew = Q + enow;
|
6777 | bvirt = Qnew - Q;
|
6778 | hh = Q - (Qnew - bvirt) + (enow - bvirt);
|
6779 | enow = e[++eindex];
|
6780 | } else {
|
6781 | Qnew = Q + fnow;
|
6782 | bvirt = Qnew - Q;
|
6783 | hh = Q - (Qnew - bvirt) + (fnow - bvirt);
|
6784 | fnow = f[++findex];
|
6785 | }
|
6786 | Q = Qnew;
|
6787 | if (hh !== 0) {
|
6788 | h[hindex++] = hh;
|
6789 | }
|
6790 | }
|
6791 | }
|
6792 | while (eindex < elen) {
|
6793 | Qnew = Q + enow;
|
6794 | bvirt = Qnew - Q;
|
6795 | hh = Q - (Qnew - bvirt) + (enow - bvirt);
|
6796 | enow = e[++eindex];
|
6797 | Q = Qnew;
|
6798 | if (hh !== 0) {
|
6799 | h[hindex++] = hh;
|
6800 | }
|
6801 | }
|
6802 | while (findex < flen) {
|
6803 | Qnew = Q + fnow;
|
6804 | bvirt = Qnew - Q;
|
6805 | hh = Q - (Qnew - bvirt) + (fnow - bvirt);
|
6806 | fnow = f[++findex];
|
6807 | Q = Qnew;
|
6808 | if (hh !== 0) {
|
6809 | h[hindex++] = hh;
|
6810 | }
|
6811 | }
|
6812 | if (Q !== 0 || hindex === 0) {
|
6813 | h[hindex++] = Q;
|
6814 | }
|
6815 | return hindex;
|
6816 | }
|
6817 |
|
6818 | function estimate(elen, e) {
|
6819 | let Q = e[0];
|
6820 | for (let i = 1; i < elen; i++) Q += e[i];
|
6821 | return Q;
|
6822 | }
|
6823 |
|
6824 | function vec(n) {
|
6825 | return new Float64Array(n);
|
6826 | }
|
6827 |
|
6828 | const ccwerrboundA = (3 + 16 * epsilon$3) * epsilon$3;
|
6829 | const ccwerrboundB = (2 + 12 * epsilon$3) * epsilon$3;
|
6830 | const ccwerrboundC = (9 + 64 * epsilon$3) * epsilon$3 * epsilon$3;
|
6831 |
|
6832 | const B = vec(4);
|
6833 | const C1 = vec(8);
|
6834 | const C2 = vec(12);
|
6835 | const D = vec(16);
|
6836 | const u = vec(4);
|
6837 |
|
6838 | function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
|
6839 | let acxtail, acytail, bcxtail, bcytail;
|
6840 | let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
|
6841 |
|
6842 | const acx = ax - cx;
|
6843 | const bcx = bx - cx;
|
6844 | const acy = ay - cy;
|
6845 | const bcy = by - cy;
|
6846 |
|
6847 | s1 = acx * bcy;
|
6848 | c = splitter * acx;
|
6849 | ahi = c - (c - acx);
|
6850 | alo = acx - ahi;
|
6851 | c = splitter * bcy;
|
6852 | bhi = c - (c - bcy);
|
6853 | blo = bcy - bhi;
|
6854 | s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
6855 | t1 = acy * bcx;
|
6856 | c = splitter * acy;
|
6857 | ahi = c - (c - acy);
|
6858 | alo = acy - ahi;
|
6859 | c = splitter * bcx;
|
6860 | bhi = c - (c - bcx);
|
6861 | blo = bcx - bhi;
|
6862 | t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
6863 | _i = s0 - t0;
|
6864 | bvirt = s0 - _i;
|
6865 | B[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
6866 | _j = s1 + _i;
|
6867 | bvirt = _j - s1;
|
6868 | _0 = s1 - (_j - bvirt) + (_i - bvirt);
|
6869 | _i = _0 - t1;
|
6870 | bvirt = _0 - _i;
|
6871 | B[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
6872 | u3 = _j + _i;
|
6873 | bvirt = u3 - _j;
|
6874 | B[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
6875 | B[3] = u3;
|
6876 |
|
6877 | let det = estimate(4, B);
|
6878 | let errbound = ccwerrboundB * detsum;
|
6879 | if (det >= errbound || -det >= errbound) {
|
6880 | return det;
|
6881 | }
|
6882 |
|
6883 | bvirt = ax - acx;
|
6884 | acxtail = ax - (acx + bvirt) + (bvirt - cx);
|
6885 | bvirt = bx - bcx;
|
6886 | bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
|
6887 | bvirt = ay - acy;
|
6888 | acytail = ay - (acy + bvirt) + (bvirt - cy);
|
6889 | bvirt = by - bcy;
|
6890 | bcytail = by - (bcy + bvirt) + (bvirt - cy);
|
6891 |
|
6892 | if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
|
6893 | return det;
|
6894 | }
|
6895 |
|
6896 | errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
|
6897 | det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
|
6898 | if (det >= errbound || -det >= errbound) return det;
|
6899 |
|
6900 | s1 = acxtail * bcy;
|
6901 | c = splitter * acxtail;
|
6902 | ahi = c - (c - acxtail);
|
6903 | alo = acxtail - ahi;
|
6904 | c = splitter * bcy;
|
6905 | bhi = c - (c - bcy);
|
6906 | blo = bcy - bhi;
|
6907 | s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
6908 | t1 = acytail * bcx;
|
6909 | c = splitter * acytail;
|
6910 | ahi = c - (c - acytail);
|
6911 | alo = acytail - ahi;
|
6912 | c = splitter * bcx;
|
6913 | bhi = c - (c - bcx);
|
6914 | blo = bcx - bhi;
|
6915 | t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
6916 | _i = s0 - t0;
|
6917 | bvirt = s0 - _i;
|
6918 | u[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
6919 | _j = s1 + _i;
|
6920 | bvirt = _j - s1;
|
6921 | _0 = s1 - (_j - bvirt) + (_i - bvirt);
|
6922 | _i = _0 - t1;
|
6923 | bvirt = _0 - _i;
|
6924 | u[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
6925 | u3 = _j + _i;
|
6926 | bvirt = u3 - _j;
|
6927 | u[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
6928 | u[3] = u3;
|
6929 | const C1len = sum$1(4, B, 4, u, C1);
|
6930 |
|
6931 | s1 = acx * bcytail;
|
6932 | c = splitter * acx;
|
6933 | ahi = c - (c - acx);
|
6934 | alo = acx - ahi;
|
6935 | c = splitter * bcytail;
|
6936 | bhi = c - (c - bcytail);
|
6937 | blo = bcytail - bhi;
|
6938 | s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
6939 | t1 = acy * bcxtail;
|
6940 | c = splitter * acy;
|
6941 | ahi = c - (c - acy);
|
6942 | alo = acy - ahi;
|
6943 | c = splitter * bcxtail;
|
6944 | bhi = c - (c - bcxtail);
|
6945 | blo = bcxtail - bhi;
|
6946 | t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
6947 | _i = s0 - t0;
|
6948 | bvirt = s0 - _i;
|
6949 | u[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
6950 | _j = s1 + _i;
|
6951 | bvirt = _j - s1;
|
6952 | _0 = s1 - (_j - bvirt) + (_i - bvirt);
|
6953 | _i = _0 - t1;
|
6954 | bvirt = _0 - _i;
|
6955 | u[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
6956 | u3 = _j + _i;
|
6957 | bvirt = u3 - _j;
|
6958 | u[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
6959 | u[3] = u3;
|
6960 | const C2len = sum$1(C1len, C1, 4, u, C2);
|
6961 |
|
6962 | s1 = acxtail * bcytail;
|
6963 | c = splitter * acxtail;
|
6964 | ahi = c - (c - acxtail);
|
6965 | alo = acxtail - ahi;
|
6966 | c = splitter * bcytail;
|
6967 | bhi = c - (c - bcytail);
|
6968 | blo = bcytail - bhi;
|
6969 | s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
6970 | t1 = acytail * bcxtail;
|
6971 | c = splitter * acytail;
|
6972 | ahi = c - (c - acytail);
|
6973 | alo = acytail - ahi;
|
6974 | c = splitter * bcxtail;
|
6975 | bhi = c - (c - bcxtail);
|
6976 | blo = bcxtail - bhi;
|
6977 | t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
6978 | _i = s0 - t0;
|
6979 | bvirt = s0 - _i;
|
6980 | u[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
6981 | _j = s1 + _i;
|
6982 | bvirt = _j - s1;
|
6983 | _0 = s1 - (_j - bvirt) + (_i - bvirt);
|
6984 | _i = _0 - t1;
|
6985 | bvirt = _0 - _i;
|
6986 | u[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
6987 | u3 = _j + _i;
|
6988 | bvirt = u3 - _j;
|
6989 | u[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
6990 | u[3] = u3;
|
6991 | const Dlen = sum$1(C2len, C2, 4, u, D);
|
6992 |
|
6993 | return D[Dlen - 1];
|
6994 | }
|
6995 |
|
6996 | function orient2d(ax, ay, bx, by, cx, cy) {
|
6997 | const detleft = (ay - cy) * (bx - cx);
|
6998 | const detright = (ax - cx) * (by - cy);
|
6999 | const det = detleft - detright;
|
7000 |
|
7001 | if (detleft === 0 || detright === 0 || (detleft > 0) !== (detright > 0)) return det;
|
7002 |
|
7003 | const detsum = Math.abs(detleft + detright);
|
7004 | if (Math.abs(det) >= ccwerrboundA * detsum) return det;
|
7005 |
|
7006 | return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
|
7007 | }
|
7008 |
|
7009 | const EPSILON = Math.pow(2, -52);
|
7010 | const EDGE_STACK = new Uint32Array(512);
|
7011 |
|
7012 | class Delaunator {
|
7013 |
|
7014 | static from(points, getX = defaultGetX, getY = defaultGetY) {
|
7015 | const n = points.length;
|
7016 | const coords = new Float64Array(n * 2);
|
7017 |
|
7018 | for (let i = 0; i < n; i++) {
|
7019 | const p = points[i];
|
7020 | coords[2 * i] = getX(p);
|
7021 | coords[2 * i + 1] = getY(p);
|
7022 | }
|
7023 |
|
7024 | return new Delaunator(coords);
|
7025 | }
|
7026 |
|
7027 | constructor(coords) {
|
7028 | const n = coords.length >> 1;
|
7029 | if (n > 0 && typeof coords[0] !== 'number') throw new Error('Expected coords to contain numbers.');
|
7030 |
|
7031 | this.coords = coords;
|
7032 |
|
7033 |
|
7034 | const maxTriangles = Math.max(2 * n - 5, 0);
|
7035 | this._triangles = new Uint32Array(maxTriangles * 3);
|
7036 | this._halfedges = new Int32Array(maxTriangles * 3);
|
7037 |
|
7038 |
|
7039 | this._hashSize = Math.ceil(Math.sqrt(n));
|
7040 | this._hullPrev = new Uint32Array(n);
|
7041 | this._hullNext = new Uint32Array(n);
|
7042 | this._hullTri = new Uint32Array(n);
|
7043 | this._hullHash = new Int32Array(this._hashSize).fill(-1);
|
7044 |
|
7045 |
|
7046 | this._ids = new Uint32Array(n);
|
7047 | this._dists = new Float64Array(n);
|
7048 |
|
7049 | this.update();
|
7050 | }
|
7051 |
|
7052 | update() {
|
7053 | const {coords, _hullPrev: hullPrev, _hullNext: hullNext, _hullTri: hullTri, _hullHash: hullHash} = this;
|
7054 | const n = coords.length >> 1;
|
7055 |
|
7056 |
|
7057 | let minX = Infinity;
|
7058 | let minY = Infinity;
|
7059 | let maxX = -Infinity;
|
7060 | let maxY = -Infinity;
|
7061 |
|
7062 | for (let i = 0; i < n; i++) {
|
7063 | const x = coords[2 * i];
|
7064 | const y = coords[2 * i + 1];
|
7065 | if (x < minX) minX = x;
|
7066 | if (y < minY) minY = y;
|
7067 | if (x > maxX) maxX = x;
|
7068 | if (y > maxY) maxY = y;
|
7069 | this._ids[i] = i;
|
7070 | }
|
7071 | const cx = (minX + maxX) / 2;
|
7072 | const cy = (minY + maxY) / 2;
|
7073 |
|
7074 | let minDist = Infinity;
|
7075 | let i0, i1, i2;
|
7076 |
|
7077 |
|
7078 | for (let i = 0; i < n; i++) {
|
7079 | const d = dist(cx, cy, coords[2 * i], coords[2 * i + 1]);
|
7080 | if (d < minDist) {
|
7081 | i0 = i;
|
7082 | minDist = d;
|
7083 | }
|
7084 | }
|
7085 | const i0x = coords[2 * i0];
|
7086 | const i0y = coords[2 * i0 + 1];
|
7087 |
|
7088 | minDist = Infinity;
|
7089 |
|
7090 |
|
7091 | for (let i = 0; i < n; i++) {
|
7092 | if (i === i0) continue;
|
7093 | const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
|
7094 | if (d < minDist && d > 0) {
|
7095 | i1 = i;
|
7096 | minDist = d;
|
7097 | }
|
7098 | }
|
7099 | let i1x = coords[2 * i1];
|
7100 | let i1y = coords[2 * i1 + 1];
|
7101 |
|
7102 | let minRadius = Infinity;
|
7103 |
|
7104 |
|
7105 | for (let i = 0; i < n; i++) {
|
7106 | if (i === i0 || i === i1) continue;
|
7107 | const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
|
7108 | if (r < minRadius) {
|
7109 | i2 = i;
|
7110 | minRadius = r;
|
7111 | }
|
7112 | }
|
7113 | let i2x = coords[2 * i2];
|
7114 | let i2y = coords[2 * i2 + 1];
|
7115 |
|
7116 | if (minRadius === Infinity) {
|
7117 |
|
7118 |
|
7119 | for (let i = 0; i < n; i++) {
|
7120 | this._dists[i] = (coords[2 * i] - coords[0]) || (coords[2 * i + 1] - coords[1]);
|
7121 | }
|
7122 | quicksort(this._ids, this._dists, 0, n - 1);
|
7123 | const hull = new Uint32Array(n);
|
7124 | let j = 0;
|
7125 | for (let i = 0, d0 = -Infinity; i < n; i++) {
|
7126 | const id = this._ids[i];
|
7127 | if (this._dists[id] > d0) {
|
7128 | hull[j++] = id;
|
7129 | d0 = this._dists[id];
|
7130 | }
|
7131 | }
|
7132 | this.hull = hull.subarray(0, j);
|
7133 | this.triangles = new Uint32Array(0);
|
7134 | this.halfedges = new Uint32Array(0);
|
7135 | return;
|
7136 | }
|
7137 |
|
7138 |
|
7139 | if (orient2d(i0x, i0y, i1x, i1y, i2x, i2y) < 0) {
|
7140 | const i = i1;
|
7141 | const x = i1x;
|
7142 | const y = i1y;
|
7143 | i1 = i2;
|
7144 | i1x = i2x;
|
7145 | i1y = i2y;
|
7146 | i2 = i;
|
7147 | i2x = x;
|
7148 | i2y = y;
|
7149 | }
|
7150 |
|
7151 | const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
|
7152 | this._cx = center.x;
|
7153 | this._cy = center.y;
|
7154 |
|
7155 | for (let i = 0; i < n; i++) {
|
7156 | this._dists[i] = dist(coords[2 * i], coords[2 * i + 1], center.x, center.y);
|
7157 | }
|
7158 |
|
7159 |
|
7160 | quicksort(this._ids, this._dists, 0, n - 1);
|
7161 |
|
7162 |
|
7163 | this._hullStart = i0;
|
7164 | let hullSize = 3;
|
7165 |
|
7166 | hullNext[i0] = hullPrev[i2] = i1;
|
7167 | hullNext[i1] = hullPrev[i0] = i2;
|
7168 | hullNext[i2] = hullPrev[i1] = i0;
|
7169 |
|
7170 | hullTri[i0] = 0;
|
7171 | hullTri[i1] = 1;
|
7172 | hullTri[i2] = 2;
|
7173 |
|
7174 | hullHash.fill(-1);
|
7175 | hullHash[this._hashKey(i0x, i0y)] = i0;
|
7176 | hullHash[this._hashKey(i1x, i1y)] = i1;
|
7177 | hullHash[this._hashKey(i2x, i2y)] = i2;
|
7178 |
|
7179 | this.trianglesLen = 0;
|
7180 | this._addTriangle(i0, i1, i2, -1, -1, -1);
|
7181 |
|
7182 | for (let k = 0, xp, yp; k < this._ids.length; k++) {
|
7183 | const i = this._ids[k];
|
7184 | const x = coords[2 * i];
|
7185 | const y = coords[2 * i + 1];
|
7186 |
|
7187 |
|
7188 | if (k > 0 && Math.abs(x - xp) <= EPSILON && Math.abs(y - yp) <= EPSILON) continue;
|
7189 | xp = x;
|
7190 | yp = y;
|
7191 |
|
7192 |
|
7193 | if (i === i0 || i === i1 || i === i2) continue;
|
7194 |
|
7195 |
|
7196 | let start = 0;
|
7197 | for (let j = 0, key = this._hashKey(x, y); j < this._hashSize; j++) {
|
7198 | start = hullHash[(key + j) % this._hashSize];
|
7199 | if (start !== -1 && start !== hullNext[start]) break;
|
7200 | }
|
7201 |
|
7202 | start = hullPrev[start];
|
7203 | let e = start, q;
|
7204 | while (q = hullNext[e], orient2d(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1]) >= 0) {
|
7205 | e = q;
|
7206 | if (e === start) {
|
7207 | e = -1;
|
7208 | break;
|
7209 | }
|
7210 | }
|
7211 | if (e === -1) continue;
|
7212 |
|
7213 |
|
7214 | let t = this._addTriangle(e, i, hullNext[e], -1, -1, hullTri[e]);
|
7215 |
|
7216 |
|
7217 | hullTri[i] = this._legalize(t + 2);
|
7218 | hullTri[e] = t;
|
7219 | hullSize++;
|
7220 |
|
7221 |
|
7222 | let n = hullNext[e];
|
7223 | while (q = hullNext[n], orient2d(x, y, coords[2 * n], coords[2 * n + 1], coords[2 * q], coords[2 * q + 1]) < 0) {
|
7224 | t = this._addTriangle(n, i, q, hullTri[i], -1, hullTri[n]);
|
7225 | hullTri[i] = this._legalize(t + 2);
|
7226 | hullNext[n] = n;
|
7227 | hullSize--;
|
7228 | n = q;
|
7229 | }
|
7230 |
|
7231 |
|
7232 | if (e === start) {
|
7233 | while (q = hullPrev[e], orient2d(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1]) < 0) {
|
7234 | t = this._addTriangle(q, i, e, -1, hullTri[e], hullTri[q]);
|
7235 | this._legalize(t + 2);
|
7236 | hullTri[q] = t;
|
7237 | hullNext[e] = e;
|
7238 | hullSize--;
|
7239 | e = q;
|
7240 | }
|
7241 | }
|
7242 |
|
7243 |
|
7244 | this._hullStart = hullPrev[i] = e;
|
7245 | hullNext[e] = hullPrev[n] = i;
|
7246 | hullNext[i] = n;
|
7247 |
|
7248 |
|
7249 | hullHash[this._hashKey(x, y)] = i;
|
7250 | hullHash[this._hashKey(coords[2 * e], coords[2 * e + 1])] = e;
|
7251 | }
|
7252 |
|
7253 | this.hull = new Uint32Array(hullSize);
|
7254 | for (let i = 0, e = this._hullStart; i < hullSize; i++) {
|
7255 | this.hull[i] = e;
|
7256 | e = hullNext[e];
|
7257 | }
|
7258 |
|
7259 |
|
7260 | this.triangles = this._triangles.subarray(0, this.trianglesLen);
|
7261 | this.halfedges = this._halfedges.subarray(0, this.trianglesLen);
|
7262 | }
|
7263 |
|
7264 | _hashKey(x, y) {
|
7265 | return Math.floor(pseudoAngle(x - this._cx, y - this._cy) * this._hashSize) % this._hashSize;
|
7266 | }
|
7267 |
|
7268 | _legalize(a) {
|
7269 | const {_triangles: triangles, _halfedges: halfedges, coords} = this;
|
7270 |
|
7271 | let i = 0;
|
7272 | let ar = 0;
|
7273 |
|
7274 |
|
7275 | while (true) {
|
7276 | const b = halfedges[a];
|
7277 |
|
7278 | |
7279 |
|
7280 |
|
7281 |
|
7282 |
|
7283 |
|
7284 |
|
7285 |
|
7286 |
|
7287 |
|
7288 |
|
7289 |
|
7290 |
|
7291 |
|
7292 |
|
7293 | const a0 = a - a % 3;
|
7294 | ar = a0 + (a + 2) % 3;
|
7295 |
|
7296 | if (b === -1) {
|
7297 | if (i === 0) break;
|
7298 | a = EDGE_STACK[--i];
|
7299 | continue;
|
7300 | }
|
7301 |
|
7302 | const b0 = b - b % 3;
|
7303 | const al = a0 + (a + 1) % 3;
|
7304 | const bl = b0 + (b + 2) % 3;
|
7305 |
|
7306 | const p0 = triangles[ar];
|
7307 | const pr = triangles[a];
|
7308 | const pl = triangles[al];
|
7309 | const p1 = triangles[bl];
|
7310 |
|
7311 | const illegal = inCircle(
|
7312 | coords[2 * p0], coords[2 * p0 + 1],
|
7313 | coords[2 * pr], coords[2 * pr + 1],
|
7314 | coords[2 * pl], coords[2 * pl + 1],
|
7315 | coords[2 * p1], coords[2 * p1 + 1]);
|
7316 |
|
7317 | if (illegal) {
|
7318 | triangles[a] = p1;
|
7319 | triangles[b] = p0;
|
7320 |
|
7321 | const hbl = halfedges[bl];
|
7322 |
|
7323 |
|
7324 | if (hbl === -1) {
|
7325 | let e = this._hullStart;
|
7326 | do {
|
7327 | if (this._hullTri[e] === bl) {
|
7328 | this._hullTri[e] = a;
|
7329 | break;
|
7330 | }
|
7331 | e = this._hullPrev[e];
|
7332 | } while (e !== this._hullStart);
|
7333 | }
|
7334 | this._link(a, hbl);
|
7335 | this._link(b, halfedges[ar]);
|
7336 | this._link(ar, bl);
|
7337 |
|
7338 | const br = b0 + (b + 1) % 3;
|
7339 |
|
7340 |
|
7341 | if (i < EDGE_STACK.length) {
|
7342 | EDGE_STACK[i++] = br;
|
7343 | }
|
7344 | } else {
|
7345 | if (i === 0) break;
|
7346 | a = EDGE_STACK[--i];
|
7347 | }
|
7348 | }
|
7349 |
|
7350 | return ar;
|
7351 | }
|
7352 |
|
7353 | _link(a, b) {
|
7354 | this._halfedges[a] = b;
|
7355 | if (b !== -1) this._halfedges[b] = a;
|
7356 | }
|
7357 |
|
7358 |
|
7359 | _addTriangle(i0, i1, i2, a, b, c) {
|
7360 | const t = this.trianglesLen;
|
7361 |
|
7362 | this._triangles[t] = i0;
|
7363 | this._triangles[t + 1] = i1;
|
7364 | this._triangles[t + 2] = i2;
|
7365 |
|
7366 | this._link(t, a);
|
7367 | this._link(t + 1, b);
|
7368 | this._link(t + 2, c);
|
7369 |
|
7370 | this.trianglesLen += 3;
|
7371 |
|
7372 | return t;
|
7373 | }
|
7374 | }
|
7375 |
|
7376 |
|
7377 | function pseudoAngle(dx, dy) {
|
7378 | const p = dx / (Math.abs(dx) + Math.abs(dy));
|
7379 | return (dy > 0 ? 3 - p : 1 + p) / 4;
|
7380 | }
|
7381 |
|
7382 | function dist(ax, ay, bx, by) {
|
7383 | const dx = ax - bx;
|
7384 | const dy = ay - by;
|
7385 | return dx * dx + dy * dy;
|
7386 | }
|
7387 |
|
7388 | function inCircle(ax, ay, bx, by, cx, cy, px, py) {
|
7389 | const dx = ax - px;
|
7390 | const dy = ay - py;
|
7391 | const ex = bx - px;
|
7392 | const ey = by - py;
|
7393 | const fx = cx - px;
|
7394 | const fy = cy - py;
|
7395 |
|
7396 | const ap = dx * dx + dy * dy;
|
7397 | const bp = ex * ex + ey * ey;
|
7398 | const cp = fx * fx + fy * fy;
|
7399 |
|
7400 | return dx * (ey * cp - bp * fy) -
|
7401 | dy * (ex * cp - bp * fx) +
|
7402 | ap * (ex * fy - ey * fx) < 0;
|
7403 | }
|
7404 |
|
7405 | function circumradius(ax, ay, bx, by, cx, cy) {
|
7406 | const dx = bx - ax;
|
7407 | const dy = by - ay;
|
7408 | const ex = cx - ax;
|
7409 | const ey = cy - ay;
|
7410 |
|
7411 | const bl = dx * dx + dy * dy;
|
7412 | const cl = ex * ex + ey * ey;
|
7413 | const d = 0.5 / (dx * ey - dy * ex);
|
7414 |
|
7415 | const x = (ey * bl - dy * cl) * d;
|
7416 | const y = (dx * cl - ex * bl) * d;
|
7417 |
|
7418 | return x * x + y * y;
|
7419 | }
|
7420 |
|
7421 | function circumcenter(ax, ay, bx, by, cx, cy) {
|
7422 | const dx = bx - ax;
|
7423 | const dy = by - ay;
|
7424 | const ex = cx - ax;
|
7425 | const ey = cy - ay;
|
7426 |
|
7427 | const bl = dx * dx + dy * dy;
|
7428 | const cl = ex * ex + ey * ey;
|
7429 | const d = 0.5 / (dx * ey - dy * ex);
|
7430 |
|
7431 | const x = ax + (ey * bl - dy * cl) * d;
|
7432 | const y = ay + (dx * cl - ex * bl) * d;
|
7433 |
|
7434 | return {x, y};
|
7435 | }
|
7436 |
|
7437 | function quicksort(ids, dists, left, right) {
|
7438 | if (right - left <= 20) {
|
7439 | for (let i = left + 1; i <= right; i++) {
|
7440 | const temp = ids[i];
|
7441 | const tempDist = dists[temp];
|
7442 | let j = i - 1;
|
7443 | while (j >= left && dists[ids[j]] > tempDist) ids[j + 1] = ids[j--];
|
7444 | ids[j + 1] = temp;
|
7445 | }
|
7446 | } else {
|
7447 | const median = (left + right) >> 1;
|
7448 | let i = left + 1;
|
7449 | let j = right;
|
7450 | swap(ids, median, i);
|
7451 | if (dists[ids[left]] > dists[ids[right]]) swap(ids, left, right);
|
7452 | if (dists[ids[i]] > dists[ids[right]]) swap(ids, i, right);
|
7453 | if (dists[ids[left]] > dists[ids[i]]) swap(ids, left, i);
|
7454 |
|
7455 | const temp = ids[i];
|
7456 | const tempDist = dists[temp];
|
7457 | while (true) {
|
7458 | do i++; while (dists[ids[i]] < tempDist);
|
7459 | do j--; while (dists[ids[j]] > tempDist);
|
7460 | if (j < i) break;
|
7461 | swap(ids, i, j);
|
7462 | }
|
7463 | ids[left + 1] = ids[j];
|
7464 | ids[j] = temp;
|
7465 |
|
7466 | if (right - i + 1 >= j - left) {
|
7467 | quicksort(ids, dists, i, right);
|
7468 | quicksort(ids, dists, left, j - 1);
|
7469 | } else {
|
7470 | quicksort(ids, dists, left, j - 1);
|
7471 | quicksort(ids, dists, i, right);
|
7472 | }
|
7473 | }
|
7474 | }
|
7475 |
|
7476 | function swap(arr, i, j) {
|
7477 | const tmp = arr[i];
|
7478 | arr[i] = arr[j];
|
7479 | arr[j] = tmp;
|
7480 | }
|
7481 |
|
7482 | function defaultGetX(p) {
|
7483 | return p[0];
|
7484 | }
|
7485 | function defaultGetY(p) {
|
7486 | return p[1];
|
7487 | }
|
7488 |
|
7489 | const epsilon$2 = 1e-6;
|
7490 |
|
7491 | class Path {
|
7492 | constructor() {
|
7493 | this._x0 = this._y0 =
|
7494 | this._x1 = this._y1 = null;
|
7495 | this._ = "";
|
7496 | }
|
7497 | moveTo(x, y) {
|
7498 | this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
|
7499 | }
|
7500 | closePath() {
|
7501 | if (this._x1 !== null) {
|
7502 | this._x1 = this._x0, this._y1 = this._y0;
|
7503 | this._ += "Z";
|
7504 | }
|
7505 | }
|
7506 | lineTo(x, y) {
|
7507 | this._ += `L${this._x1 = +x},${this._y1 = +y}`;
|
7508 | }
|
7509 | arc(x, y, r) {
|
7510 | x = +x, y = +y, r = +r;
|
7511 | const x0 = x + r;
|
7512 | const y0 = y;
|
7513 | if (r < 0) throw new Error("negative radius");
|
7514 | if (this._x1 === null) this._ += `M${x0},${y0}`;
|
7515 | else if (Math.abs(this._x1 - x0) > epsilon$2 || Math.abs(this._y1 - y0) > epsilon$2) this._ += "L" + x0 + "," + y0;
|
7516 | if (!r) return;
|
7517 | this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`;
|
7518 | }
|
7519 | rect(x, y, w, h) {
|
7520 | this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`;
|
7521 | }
|
7522 | value() {
|
7523 | return this._ || null;
|
7524 | }
|
7525 | }
|
7526 |
|
7527 | class Polygon {
|
7528 | constructor() {
|
7529 | this._ = [];
|
7530 | }
|
7531 | moveTo(x, y) {
|
7532 | this._.push([x, y]);
|
7533 | }
|
7534 | closePath() {
|
7535 | this._.push(this._[0].slice());
|
7536 | }
|
7537 | lineTo(x, y) {
|
7538 | this._.push([x, y]);
|
7539 | }
|
7540 | value() {
|
7541 | return this._.length ? this._ : null;
|
7542 | }
|
7543 | }
|
7544 |
|
7545 | class Voronoi {
|
7546 | constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) {
|
7547 | if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds");
|
7548 | this.delaunay = delaunay;
|
7549 | this._circumcenters = new Float64Array(delaunay.points.length * 2);
|
7550 | this.vectors = new Float64Array(delaunay.points.length * 2);
|
7551 | this.xmax = xmax, this.xmin = xmin;
|
7552 | this.ymax = ymax, this.ymin = ymin;
|
7553 | this._init();
|
7554 | }
|
7555 | update() {
|
7556 | this.delaunay.update();
|
7557 | this._init();
|
7558 | return this;
|
7559 | }
|
7560 | _init() {
|
7561 | const {delaunay: {points, hull, triangles}, vectors} = this;
|
7562 |
|
7563 |
|
7564 | const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2);
|
7565 | for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
|
7566 | const t1 = triangles[i] * 2;
|
7567 | const t2 = triangles[i + 1] * 2;
|
7568 | const t3 = triangles[i + 2] * 2;
|
7569 | const x1 = points[t1];
|
7570 | const y1 = points[t1 + 1];
|
7571 | const x2 = points[t2];
|
7572 | const y2 = points[t2 + 1];
|
7573 | const x3 = points[t3];
|
7574 | const y3 = points[t3 + 1];
|
7575 |
|
7576 | const dx = x2 - x1;
|
7577 | const dy = y2 - y1;
|
7578 | const ex = x3 - x1;
|
7579 | const ey = y3 - y1;
|
7580 | const ab = (dx * ey - dy * ex) * 2;
|
7581 |
|
7582 | if (Math.abs(ab) < 1e-9) {
|
7583 |
|
7584 |
|
7585 |
|
7586 |
|
7587 |
|
7588 | let a = 1e9;
|
7589 |
|
7590 |
|
7591 |
|
7592 | const r = triangles[0] * 2;
|
7593 | a *= Math.sign((points[r] - x1) * ey - (points[r + 1] - y1) * ex);
|
7594 | x = (x1 + x3) / 2 - a * ey;
|
7595 | y = (y1 + y3) / 2 + a * ex;
|
7596 | } else {
|
7597 | const d = 1 / ab;
|
7598 | const bl = dx * dx + dy * dy;
|
7599 | const cl = ex * ex + ey * ey;
|
7600 | x = x1 + (ey * bl - dy * cl) * d;
|
7601 | y = y1 + (dx * cl - ex * bl) * d;
|
7602 | }
|
7603 | circumcenters[j] = x;
|
7604 | circumcenters[j + 1] = y;
|
7605 | }
|
7606 |
|
7607 |
|
7608 | let h = hull[hull.length - 1];
|
7609 | let p0, p1 = h * 4;
|
7610 | let x0, x1 = points[2 * h];
|
7611 | let y0, y1 = points[2 * h + 1];
|
7612 | vectors.fill(0);
|
7613 | for (let i = 0; i < hull.length; ++i) {
|
7614 | h = hull[i];
|
7615 | p0 = p1, x0 = x1, y0 = y1;
|
7616 | p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1];
|
7617 | vectors[p0 + 2] = vectors[p1] = y0 - y1;
|
7618 | vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
|
7619 | }
|
7620 | }
|
7621 | render(context) {
|
7622 | const buffer = context == null ? context = new Path : undefined;
|
7623 | const {delaunay: {halfedges, inedges, hull}, circumcenters, vectors} = this;
|
7624 | if (hull.length <= 1) return null;
|
7625 | for (let i = 0, n = halfedges.length; i < n; ++i) {
|
7626 | const j = halfedges[i];
|
7627 | if (j < i) continue;
|
7628 | const ti = Math.floor(i / 3) * 2;
|
7629 | const tj = Math.floor(j / 3) * 2;
|
7630 | const xi = circumcenters[ti];
|
7631 | const yi = circumcenters[ti + 1];
|
7632 | const xj = circumcenters[tj];
|
7633 | const yj = circumcenters[tj + 1];
|
7634 | this._renderSegment(xi, yi, xj, yj, context);
|
7635 | }
|
7636 | let h0, h1 = hull[hull.length - 1];
|
7637 | for (let i = 0; i < hull.length; ++i) {
|
7638 | h0 = h1, h1 = hull[i];
|
7639 | const t = Math.floor(inedges[h1] / 3) * 2;
|
7640 | const x = circumcenters[t];
|
7641 | const y = circumcenters[t + 1];
|
7642 | const v = h0 * 4;
|
7643 | const p = this._project(x, y, vectors[v + 2], vectors[v + 3]);
|
7644 | if (p) this._renderSegment(x, y, p[0], p[1], context);
|
7645 | }
|
7646 | return buffer && buffer.value();
|
7647 | }
|
7648 | renderBounds(context) {
|
7649 | const buffer = context == null ? context = new Path : undefined;
|
7650 | context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin);
|
7651 | return buffer && buffer.value();
|
7652 | }
|
7653 | renderCell(i, context) {
|
7654 | const buffer = context == null ? context = new Path : undefined;
|
7655 | const points = this._clip(i);
|
7656 | if (points === null || !points.length) return;
|
7657 | context.moveTo(points[0], points[1]);
|
7658 | let n = points.length;
|
7659 | while (points[0] === points[n-2] && points[1] === points[n-1] && n > 1) n -= 2;
|
7660 | for (let i = 2; i < n; i += 2) {
|
7661 | if (points[i] !== points[i-2] || points[i+1] !== points[i-1])
|
7662 | context.lineTo(points[i], points[i + 1]);
|
7663 | }
|
7664 | context.closePath();
|
7665 | return buffer && buffer.value();
|
7666 | }
|
7667 | *cellPolygons() {
|
7668 | const {delaunay: {points}} = this;
|
7669 | for (let i = 0, n = points.length / 2; i < n; ++i) {
|
7670 | const cell = this.cellPolygon(i);
|
7671 | if (cell) cell.index = i, yield cell;
|
7672 | }
|
7673 | }
|
7674 | cellPolygon(i) {
|
7675 | const polygon = new Polygon;
|
7676 | this.renderCell(i, polygon);
|
7677 | return polygon.value();
|
7678 | }
|
7679 | _renderSegment(x0, y0, x1, y1, context) {
|
7680 | let S;
|
7681 | const c0 = this._regioncode(x0, y0);
|
7682 | const c1 = this._regioncode(x1, y1);
|
7683 | if (c0 === 0 && c1 === 0) {
|
7684 | context.moveTo(x0, y0);
|
7685 | context.lineTo(x1, y1);
|
7686 | } else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) {
|
7687 | context.moveTo(S[0], S[1]);
|
7688 | context.lineTo(S[2], S[3]);
|
7689 | }
|
7690 | }
|
7691 | contains(i, x, y) {
|
7692 | if ((x = +x, x !== x) || (y = +y, y !== y)) return false;
|
7693 | return this.delaunay._step(i, x, y) === i;
|
7694 | }
|
7695 | *neighbors(i) {
|
7696 | const ci = this._clip(i);
|
7697 | if (ci) for (const j of this.delaunay.neighbors(i)) {
|
7698 | const cj = this._clip(j);
|
7699 |
|
7700 | if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) {
|
7701 | for (let aj = 0, lj = cj.length; aj < lj; aj += 2) {
|
7702 | if (ci[ai] === cj[aj]
|
7703 | && ci[ai + 1] === cj[aj + 1]
|
7704 | && ci[(ai + 2) % li] === cj[(aj + lj - 2) % lj]
|
7705 | && ci[(ai + 3) % li] === cj[(aj + lj - 1) % lj]) {
|
7706 | yield j;
|
7707 | break loop;
|
7708 | }
|
7709 | }
|
7710 | }
|
7711 | }
|
7712 | }
|
7713 | _cell(i) {
|
7714 | const {circumcenters, delaunay: {inedges, halfedges, triangles}} = this;
|
7715 | const e0 = inedges[i];
|
7716 | if (e0 === -1) return null;
|
7717 | const points = [];
|
7718 | let e = e0;
|
7719 | do {
|
7720 | const t = Math.floor(e / 3);
|
7721 | points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]);
|
7722 | e = e % 3 === 2 ? e - 2 : e + 1;
|
7723 | if (triangles[e] !== i) break;
|
7724 | e = halfedges[e];
|
7725 | } while (e !== e0 && e !== -1);
|
7726 | return points;
|
7727 | }
|
7728 | _clip(i) {
|
7729 |
|
7730 | if (i === 0 && this.delaunay.hull.length === 1) {
|
7731 | return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
|
7732 | }
|
7733 | const points = this._cell(i);
|
7734 | if (points === null) return null;
|
7735 | const {vectors: V} = this;
|
7736 | const v = i * 4;
|
7737 | return this._simplify(V[v] || V[v + 1]
|
7738 | ? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3])
|
7739 | : this._clipFinite(i, points));
|
7740 | }
|
7741 | _clipFinite(i, points) {
|
7742 | const n = points.length;
|
7743 | let P = null;
|
7744 | let x0, y0, x1 = points[n - 2], y1 = points[n - 1];
|
7745 | let c0, c1 = this._regioncode(x1, y1);
|
7746 | let e0, e1 = 0;
|
7747 | for (let j = 0; j < n; j += 2) {
|
7748 | x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1];
|
7749 | c0 = c1, c1 = this._regioncode(x1, y1);
|
7750 | if (c0 === 0 && c1 === 0) {
|
7751 | e0 = e1, e1 = 0;
|
7752 | if (P) P.push(x1, y1);
|
7753 | else P = [x1, y1];
|
7754 | } else {
|
7755 | let S, sx0, sy0, sx1, sy1;
|
7756 | if (c0 === 0) {
|
7757 | if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue;
|
7758 | [sx0, sy0, sx1, sy1] = S;
|
7759 | } else {
|
7760 | if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue;
|
7761 | [sx1, sy1, sx0, sy0] = S;
|
7762 | e0 = e1, e1 = this._edgecode(sx0, sy0);
|
7763 | if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
7764 | if (P) P.push(sx0, sy0);
|
7765 | else P = [sx0, sy0];
|
7766 | }
|
7767 | e0 = e1, e1 = this._edgecode(sx1, sy1);
|
7768 | if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
7769 | if (P) P.push(sx1, sy1);
|
7770 | else P = [sx1, sy1];
|
7771 | }
|
7772 | }
|
7773 | if (P) {
|
7774 | e0 = e1, e1 = this._edgecode(P[0], P[1]);
|
7775 | if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
7776 | } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
|
7777 | return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
|
7778 | }
|
7779 | return P;
|
7780 | }
|
7781 | _clipSegment(x0, y0, x1, y1, c0, c1) {
|
7782 |
|
7783 | const flip = c0 < c1;
|
7784 | if (flip) [x0, y0, x1, y1, c0, c1] = [x1, y1, x0, y0, c1, c0];
|
7785 | while (true) {
|
7786 | if (c0 === 0 && c1 === 0) return flip ? [x1, y1, x0, y0] : [x0, y0, x1, y1];
|
7787 | if (c0 & c1) return null;
|
7788 | let x, y, c = c0 || c1;
|
7789 | if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax;
|
7790 | else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin;
|
7791 | else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax;
|
7792 | else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin;
|
7793 | if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0);
|
7794 | else x1 = x, y1 = y, c1 = this._regioncode(x1, y1);
|
7795 | }
|
7796 | }
|
7797 | _clipInfinite(i, points, vx0, vy0, vxn, vyn) {
|
7798 | let P = Array.from(points), p;
|
7799 | if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]);
|
7800 | if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]);
|
7801 | if (P = this._clipFinite(i, P)) {
|
7802 | for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) {
|
7803 | c0 = c1, c1 = this._edgecode(P[j], P[j + 1]);
|
7804 | if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length;
|
7805 | }
|
7806 | } else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
|
7807 | P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax];
|
7808 | }
|
7809 | return P;
|
7810 | }
|
7811 | _edge(i, e0, e1, P, j) {
|
7812 | while (e0 !== e1) {
|
7813 | let x, y;
|
7814 | switch (e0) {
|
7815 | case 0b0101: e0 = 0b0100; continue;
|
7816 | case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break;
|
7817 | case 0b0110: e0 = 0b0010; continue;
|
7818 | case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break;
|
7819 | case 0b1010: e0 = 0b1000; continue;
|
7820 | case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break;
|
7821 | case 0b1001: e0 = 0b0001; continue;
|
7822 | case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break;
|
7823 | }
|
7824 |
|
7825 |
|
7826 | if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) {
|
7827 | P.splice(j, 0, x, y), j += 2;
|
7828 | }
|
7829 | }
|
7830 | return j;
|
7831 | }
|
7832 | _project(x0, y0, vx, vy) {
|
7833 | let t = Infinity, c, x, y;
|
7834 | if (vy < 0) {
|
7835 | if (y0 <= this.ymin) return null;
|
7836 | if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx;
|
7837 | } else if (vy > 0) {
|
7838 | if (y0 >= this.ymax) return null;
|
7839 | if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx;
|
7840 | }
|
7841 | if (vx > 0) {
|
7842 | if (x0 >= this.xmax) return null;
|
7843 | if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy;
|
7844 | } else if (vx < 0) {
|
7845 | if (x0 <= this.xmin) return null;
|
7846 | if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy;
|
7847 | }
|
7848 | return [x, y];
|
7849 | }
|
7850 | _edgecode(x, y) {
|
7851 | return (x === this.xmin ? 0b0001
|
7852 | : x === this.xmax ? 0b0010 : 0b0000)
|
7853 | | (y === this.ymin ? 0b0100
|
7854 | : y === this.ymax ? 0b1000 : 0b0000);
|
7855 | }
|
7856 | _regioncode(x, y) {
|
7857 | return (x < this.xmin ? 0b0001
|
7858 | : x > this.xmax ? 0b0010 : 0b0000)
|
7859 | | (y < this.ymin ? 0b0100
|
7860 | : y > this.ymax ? 0b1000 : 0b0000);
|
7861 | }
|
7862 | _simplify(P) {
|
7863 | if (P && P.length > 4) {
|
7864 | for (let i = 0; i < P.length; i+= 2) {
|
7865 | const j = (i + 2) % P.length, k = (i + 4) % P.length;
|
7866 | if (P[i] === P[j] && P[j] === P[k] || P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1]) {
|
7867 | P.splice(j, 2), i -= 2;
|
7868 | }
|
7869 | }
|
7870 | if (!P.length) P = null;
|
7871 | }
|
7872 | return P;
|
7873 | }
|
7874 | }
|
7875 |
|
7876 | const tau$2 = 2 * Math.PI, pow$2 = Math.pow;
|
7877 |
|
7878 | function pointX(p) {
|
7879 | return p[0];
|
7880 | }
|
7881 |
|
7882 | function pointY(p) {
|
7883 | return p[1];
|
7884 | }
|
7885 |
|
7886 |
|
7887 | function collinear(d) {
|
7888 | const {triangles, coords} = d;
|
7889 | for (let i = 0; i < triangles.length; i += 3) {
|
7890 | const a = 2 * triangles[i],
|
7891 | b = 2 * triangles[i + 1],
|
7892 | c = 2 * triangles[i + 2],
|
7893 | cross = (coords[c] - coords[a]) * (coords[b + 1] - coords[a + 1])
|
7894 | - (coords[b] - coords[a]) * (coords[c + 1] - coords[a + 1]);
|
7895 | if (cross > 1e-10) return false;
|
7896 | }
|
7897 | return true;
|
7898 | }
|
7899 |
|
7900 | function jitter(x, y, r) {
|
7901 | return [x + Math.sin(x + y) * r, y + Math.cos(x - y) * r];
|
7902 | }
|
7903 |
|
7904 | class Delaunay {
|
7905 | static from(points, fx = pointX, fy = pointY, that) {
|
7906 | return new Delaunay("length" in points
|
7907 | ? flatArray(points, fx, fy, that)
|
7908 | : Float64Array.from(flatIterable(points, fx, fy, that)));
|
7909 | }
|
7910 | constructor(points) {
|
7911 | this._delaunator = new Delaunator(points);
|
7912 | this.inedges = new Int32Array(points.length / 2);
|
7913 | this._hullIndex = new Int32Array(points.length / 2);
|
7914 | this.points = this._delaunator.coords;
|
7915 | this._init();
|
7916 | }
|
7917 | update() {
|
7918 | this._delaunator.update();
|
7919 | this._init();
|
7920 | return this;
|
7921 | }
|
7922 | _init() {
|
7923 | const d = this._delaunator, points = this.points;
|
7924 |
|
7925 |
|
7926 | if (d.hull && d.hull.length > 2 && collinear(d)) {
|
7927 | this.collinear = Int32Array.from({length: points.length/2}, (_,i) => i)
|
7928 | .sort((i, j) => points[2 * i] - points[2 * j] || points[2 * i + 1] - points[2 * j + 1]);
|
7929 | const e = this.collinear[0], f = this.collinear[this.collinear.length - 1],
|
7930 | bounds = [ points[2 * e], points[2 * e + 1], points[2 * f], points[2 * f + 1] ],
|
7931 | r = 1e-8 * Math.hypot(bounds[3] - bounds[1], bounds[2] - bounds[0]);
|
7932 | for (let i = 0, n = points.length / 2; i < n; ++i) {
|
7933 | const p = jitter(points[2 * i], points[2 * i + 1], r);
|
7934 | points[2 * i] = p[0];
|
7935 | points[2 * i + 1] = p[1];
|
7936 | }
|
7937 | this._delaunator = new Delaunator(points);
|
7938 | } else {
|
7939 | delete this.collinear;
|
7940 | }
|
7941 |
|
7942 | const halfedges = this.halfedges = this._delaunator.halfedges;
|
7943 | const hull = this.hull = this._delaunator.hull;
|
7944 | const triangles = this.triangles = this._delaunator.triangles;
|
7945 | const inedges = this.inedges.fill(-1);
|
7946 | const hullIndex = this._hullIndex.fill(-1);
|
7947 |
|
7948 |
|
7949 |
|
7950 |
|
7951 | for (let e = 0, n = halfedges.length; e < n; ++e) {
|
7952 | const p = triangles[e % 3 === 2 ? e - 2 : e + 1];
|
7953 | if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e;
|
7954 | }
|
7955 | for (let i = 0, n = hull.length; i < n; ++i) {
|
7956 | hullIndex[hull[i]] = i;
|
7957 | }
|
7958 |
|
7959 |
|
7960 | if (hull.length <= 2 && hull.length > 0) {
|
7961 | this.triangles = new Int32Array(3).fill(-1);
|
7962 | this.halfedges = new Int32Array(3).fill(-1);
|
7963 | this.triangles[0] = hull[0];
|
7964 | inedges[hull[0]] = 1;
|
7965 | if (hull.length === 2) {
|
7966 | inedges[hull[1]] = 0;
|
7967 | this.triangles[1] = hull[1];
|
7968 | this.triangles[2] = hull[1];
|
7969 | }
|
7970 | }
|
7971 | }
|
7972 | voronoi(bounds) {
|
7973 | return new Voronoi(this, bounds);
|
7974 | }
|
7975 | *neighbors(i) {
|
7976 | const {inedges, hull, _hullIndex, halfedges, triangles, collinear} = this;
|
7977 |
|
7978 |
|
7979 | if (collinear) {
|
7980 | const l = collinear.indexOf(i);
|
7981 | if (l > 0) yield collinear[l - 1];
|
7982 | if (l < collinear.length - 1) yield collinear[l + 1];
|
7983 | return;
|
7984 | }
|
7985 |
|
7986 | const e0 = inedges[i];
|
7987 | if (e0 === -1) return;
|
7988 | let e = e0, p0 = -1;
|
7989 | do {
|
7990 | yield p0 = triangles[e];
|
7991 | e = e % 3 === 2 ? e - 2 : e + 1;
|
7992 | if (triangles[e] !== i) return;
|
7993 | e = halfedges[e];
|
7994 | if (e === -1) {
|
7995 | const p = hull[(_hullIndex[i] + 1) % hull.length];
|
7996 | if (p !== p0) yield p;
|
7997 | return;
|
7998 | }
|
7999 | } while (e !== e0);
|
8000 | }
|
8001 | find(x, y, i = 0) {
|
8002 | if ((x = +x, x !== x) || (y = +y, y !== y)) return -1;
|
8003 | const i0 = i;
|
8004 | let c;
|
8005 | while ((c = this._step(i, x, y)) >= 0 && c !== i && c !== i0) i = c;
|
8006 | return c;
|
8007 | }
|
8008 | _step(i, x, y) {
|
8009 | const {inedges, hull, _hullIndex, halfedges, triangles, points} = this;
|
8010 | if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1);
|
8011 | let c = i;
|
8012 | let dc = pow$2(x - points[i * 2], 2) + pow$2(y - points[i * 2 + 1], 2);
|
8013 | const e0 = inedges[i];
|
8014 | let e = e0;
|
8015 | do {
|
8016 | let t = triangles[e];
|
8017 | const dt = pow$2(x - points[t * 2], 2) + pow$2(y - points[t * 2 + 1], 2);
|
8018 | if (dt < dc) dc = dt, c = t;
|
8019 | e = e % 3 === 2 ? e - 2 : e + 1;
|
8020 | if (triangles[e] !== i) break;
|
8021 | e = halfedges[e];
|
8022 | if (e === -1) {
|
8023 | e = hull[(_hullIndex[i] + 1) % hull.length];
|
8024 | if (e !== t) {
|
8025 | if (pow$2(x - points[e * 2], 2) + pow$2(y - points[e * 2 + 1], 2) < dc) return e;
|
8026 | }
|
8027 | break;
|
8028 | }
|
8029 | } while (e !== e0);
|
8030 | return c;
|
8031 | }
|
8032 | render(context) {
|
8033 | const buffer = context == null ? context = new Path : undefined;
|
8034 | const {points, halfedges, triangles} = this;
|
8035 | for (let i = 0, n = halfedges.length; i < n; ++i) {
|
8036 | const j = halfedges[i];
|
8037 | if (j < i) continue;
|
8038 | const ti = triangles[i] * 2;
|
8039 | const tj = triangles[j] * 2;
|
8040 | context.moveTo(points[ti], points[ti + 1]);
|
8041 | context.lineTo(points[tj], points[tj + 1]);
|
8042 | }
|
8043 | this.renderHull(context);
|
8044 | return buffer && buffer.value();
|
8045 | }
|
8046 | renderPoints(context, r) {
|
8047 | if (r === undefined && (!context || typeof context.moveTo !== "function")) r = context, context = null;
|
8048 | r = r == undefined ? 2 : +r;
|
8049 | const buffer = context == null ? context = new Path : undefined;
|
8050 | const {points} = this;
|
8051 | for (let i = 0, n = points.length; i < n; i += 2) {
|
8052 | const x = points[i], y = points[i + 1];
|
8053 | context.moveTo(x + r, y);
|
8054 | context.arc(x, y, r, 0, tau$2);
|
8055 | }
|
8056 | return buffer && buffer.value();
|
8057 | }
|
8058 | renderHull(context) {
|
8059 | const buffer = context == null ? context = new Path : undefined;
|
8060 | const {hull, points} = this;
|
8061 | const h = hull[0] * 2, n = hull.length;
|
8062 | context.moveTo(points[h], points[h + 1]);
|
8063 | for (let i = 1; i < n; ++i) {
|
8064 | const h = 2 * hull[i];
|
8065 | context.lineTo(points[h], points[h + 1]);
|
8066 | }
|
8067 | context.closePath();
|
8068 | return buffer && buffer.value();
|
8069 | }
|
8070 | hullPolygon() {
|
8071 | const polygon = new Polygon;
|
8072 | this.renderHull(polygon);
|
8073 | return polygon.value();
|
8074 | }
|
8075 | renderTriangle(i, context) {
|
8076 | const buffer = context == null ? context = new Path : undefined;
|
8077 | const {points, triangles} = this;
|
8078 | const t0 = triangles[i *= 3] * 2;
|
8079 | const t1 = triangles[i + 1] * 2;
|
8080 | const t2 = triangles[i + 2] * 2;
|
8081 | context.moveTo(points[t0], points[t0 + 1]);
|
8082 | context.lineTo(points[t1], points[t1 + 1]);
|
8083 | context.lineTo(points[t2], points[t2 + 1]);
|
8084 | context.closePath();
|
8085 | return buffer && buffer.value();
|
8086 | }
|
8087 | *trianglePolygons() {
|
8088 | const {triangles} = this;
|
8089 | for (let i = 0, n = triangles.length / 3; i < n; ++i) {
|
8090 | yield this.trianglePolygon(i);
|
8091 | }
|
8092 | }
|
8093 | trianglePolygon(i) {
|
8094 | const polygon = new Polygon;
|
8095 | this.renderTriangle(i, polygon);
|
8096 | return polygon.value();
|
8097 | }
|
8098 | }
|
8099 |
|
8100 | function flatArray(points, fx, fy, that) {
|
8101 | const n = points.length;
|
8102 | const array = new Float64Array(n * 2);
|
8103 | for (let i = 0; i < n; ++i) {
|
8104 | const p = points[i];
|
8105 | array[i * 2] = fx.call(that, p, i, points);
|
8106 | array[i * 2 + 1] = fy.call(that, p, i, points);
|
8107 | }
|
8108 | return array;
|
8109 | }
|
8110 |
|
8111 | function* flatIterable(points, fx, fy, that) {
|
8112 | let i = 0;
|
8113 | for (const p of points) {
|
8114 | yield fx.call(that, p, i, points);
|
8115 | yield fy.call(that, p, i, points);
|
8116 | ++i;
|
8117 | }
|
8118 | }
|
8119 |
|
8120 | var EOL = {},
|
8121 | EOF = {},
|
8122 | QUOTE = 34,
|
8123 | NEWLINE = 10,
|
8124 | RETURN = 13;
|
8125 |
|
8126 | function objectConverter(columns) {
|
8127 | return new Function("d", "return {" + columns.map(function(name, i) {
|
8128 | return JSON.stringify(name) + ": d[" + i + "] || \"\"";
|
8129 | }).join(",") + "}");
|
8130 | }
|
8131 |
|
8132 | function customConverter(columns, f) {
|
8133 | var object = objectConverter(columns);
|
8134 | return function(row, i) {
|
8135 | return f(object(row), i, columns);
|
8136 | };
|
8137 | }
|
8138 |
|
8139 |
|
8140 | function inferColumns(rows) {
|
8141 | var columnSet = Object.create(null),
|
8142 | columns = [];
|
8143 |
|
8144 | rows.forEach(function(row) {
|
8145 | for (var column in row) {
|
8146 | if (!(column in columnSet)) {
|
8147 | columns.push(columnSet[column] = column);
|
8148 | }
|
8149 | }
|
8150 | });
|
8151 |
|
8152 | return columns;
|
8153 | }
|
8154 |
|
8155 | function pad$1(value, width) {
|
8156 | var s = value + "", length = s.length;
|
8157 | return length < width ? new Array(width - length + 1).join(0) + s : s;
|
8158 | }
|
8159 |
|
8160 | function formatYear$1(year) {
|
8161 | return year < 0 ? "-" + pad$1(-year, 6)
|
8162 | : year > 9999 ? "+" + pad$1(year, 6)
|
8163 | : pad$1(year, 4);
|
8164 | }
|
8165 |
|
8166 | function formatDate(date) {
|
8167 | var hours = date.getUTCHours(),
|
8168 | minutes = date.getUTCMinutes(),
|
8169 | seconds = date.getUTCSeconds(),
|
8170 | milliseconds = date.getUTCMilliseconds();
|
8171 | return isNaN(date) ? "Invalid Date"
|
8172 | : formatYear$1(date.getUTCFullYear()) + "-" + pad$1(date.getUTCMonth() + 1, 2) + "-" + pad$1(date.getUTCDate(), 2)
|
8173 | + (milliseconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "." + pad$1(milliseconds, 3) + "Z"
|
8174 | : seconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "Z"
|
8175 | : minutes || hours ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + "Z"
|
8176 | : "");
|
8177 | }
|
8178 |
|
8179 | function dsvFormat(delimiter) {
|
8180 | var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
|
8181 | DELIMITER = delimiter.charCodeAt(0);
|
8182 |
|
8183 | function parse(text, f) {
|
8184 | var convert, columns, rows = parseRows(text, function(row, i) {
|
8185 | if (convert) return convert(row, i - 1);
|
8186 | columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
|
8187 | });
|
8188 | rows.columns = columns || [];
|
8189 | return rows;
|
8190 | }
|
8191 |
|
8192 | function parseRows(text, f) {
|
8193 | var rows = [],
|
8194 | N = text.length,
|
8195 | I = 0,
|
8196 | n = 0,
|
8197 | t,
|
8198 | eof = N <= 0,
|
8199 | eol = false;
|
8200 |
|
8201 |
|
8202 | if (text.charCodeAt(N - 1) === NEWLINE) --N;
|
8203 | if (text.charCodeAt(N - 1) === RETURN) --N;
|
8204 |
|
8205 | function token() {
|
8206 | if (eof) return EOF;
|
8207 | if (eol) return eol = false, EOL;
|
8208 |
|
8209 |
|
8210 | var i, j = I, c;
|
8211 | if (text.charCodeAt(j) === QUOTE) {
|
8212 | while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
|
8213 | if ((i = I) >= N) eof = true;
|
8214 | else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
|
8215 | else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
|
8216 | return text.slice(j + 1, i - 1).replace(/""/g, "\"");
|
8217 | }
|
8218 |
|
8219 | // Find next delimiter or newline.
|
8220 | while (I < N) {
|
8221 | if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
|
8222 | else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
|
8223 | else if (c !== DELIMITER) continue;
|
8224 | return text.slice(j, i);
|
8225 | }
|
8226 |
|
8227 | // Return last token before EOF.
|
8228 | return eof = true, text.slice(j, N);
|
8229 | }
|
8230 |
|
8231 | while ((t = token()) !== EOF) {
|
8232 | var row = [];
|
8233 | while (t !== EOL && t !== EOF) row.push(t), t = token();
|
8234 | if (f && (row = f(row, n++)) == null) continue;
|
8235 | rows.push(row);
|
8236 | }
|
8237 |
|
8238 | return rows;
|
8239 | }
|
8240 |
|
8241 | function preformatBody(rows, columns) {
|
8242 | return rows.map(function(row) {
|
8243 | return columns.map(function(column) {
|
8244 | return formatValue(row[column]);
|
8245 | }).join(delimiter);
|
8246 | });
|
8247 | }
|
8248 |
|
8249 | function format(rows, columns) {
|
8250 | if (columns == null) columns = inferColumns(rows);
|
8251 | return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
|
8252 | }
|
8253 |
|
8254 | function formatBody(rows, columns) {
|
8255 | if (columns == null) columns = inferColumns(rows);
|
8256 | return preformatBody(rows, columns).join("\n");
|
8257 | }
|
8258 |
|
8259 | function formatRows(rows) {
|
8260 | return rows.map(formatRow).join("\n");
|
8261 | }
|
8262 |
|
8263 | function formatRow(row) {
|
8264 | return row.map(formatValue).join(delimiter);
|
8265 | }
|
8266 |
|
8267 | function formatValue(value) {
|
8268 | return value == null ? ""
|
8269 | : value instanceof Date ? formatDate(value)
|
8270 | : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
|
8271 | : value;
|
8272 | }
|
8273 |
|
8274 | return {
|
8275 | parse: parse,
|
8276 | parseRows: parseRows,
|
8277 | format: format,
|
8278 | formatBody: formatBody,
|
8279 | formatRows: formatRows,
|
8280 | formatRow: formatRow,
|
8281 | formatValue: formatValue
|
8282 | };
|
8283 | }
|
8284 |
|
8285 | var csv$1 = dsvFormat(",");
|
8286 |
|
8287 | var csvParse = csv$1.parse;
|
8288 | var csvParseRows = csv$1.parseRows;
|
8289 | var csvFormat = csv$1.format;
|
8290 | var csvFormatBody = csv$1.formatBody;
|
8291 | var csvFormatRows = csv$1.formatRows;
|
8292 | var csvFormatRow = csv$1.formatRow;
|
8293 | var csvFormatValue = csv$1.formatValue;
|
8294 |
|
8295 | var tsv$1 = dsvFormat("\t");
|
8296 |
|
8297 | var tsvParse = tsv$1.parse;
|
8298 | var tsvParseRows = tsv$1.parseRows;
|
8299 | var tsvFormat = tsv$1.format;
|
8300 | var tsvFormatBody = tsv$1.formatBody;
|
8301 | var tsvFormatRows = tsv$1.formatRows;
|
8302 | var tsvFormatRow = tsv$1.formatRow;
|
8303 | var tsvFormatValue = tsv$1.formatValue;
|
8304 |
|
8305 | function autoType(object) {
|
8306 | for (var key in object) {
|
8307 | var value = object[key].trim(), number, m;
|
8308 | if (!value) value = null;
|
8309 | else if (value === "true") value = true;
|
8310 | else if (value === "false") value = false;
|
8311 | else if (value === "NaN") value = NaN;
|
8312 | else if (!isNaN(number = +value)) value = number;
|
8313 | 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})?)?$/)) {
|
8314 | if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
|
8315 | value = new Date(value);
|
8316 | }
|
8317 | else continue;
|
8318 | object[key] = value;
|
8319 | }
|
8320 | return object;
|
8321 | }
|
8322 |
|
8323 | // https://github.com/d3/d3-dsv/issues/45
|
8324 | const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
|
8325 |
|
8326 | function responseBlob(response) {
|
8327 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
8328 | return response.blob();
|
8329 | }
|
8330 |
|
8331 | function blob(input, init) {
|
8332 | return fetch(input, init).then(responseBlob);
|
8333 | }
|
8334 |
|
8335 | function responseArrayBuffer(response) {
|
8336 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
8337 | return response.arrayBuffer();
|
8338 | }
|
8339 |
|
8340 | function buffer(input, init) {
|
8341 | return fetch(input, init).then(responseArrayBuffer);
|
8342 | }
|
8343 |
|
8344 | function responseText(response) {
|
8345 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
8346 | return response.text();
|
8347 | }
|
8348 |
|
8349 | function text(input, init) {
|
8350 | return fetch(input, init).then(responseText);
|
8351 | }
|
8352 |
|
8353 | function dsvParse(parse) {
|
8354 | return function(input, init, row) {
|
8355 | if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
|
8356 | return text(input, init).then(function(response) {
|
8357 | return parse(response, row);
|
8358 | });
|
8359 | };
|
8360 | }
|
8361 |
|
8362 | function dsv(delimiter, input, init, row) {
|
8363 | if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
|
8364 | var format = dsvFormat(delimiter);
|
8365 | return text(input, init).then(function(response) {
|
8366 | return format.parse(response, row);
|
8367 | });
|
8368 | }
|
8369 |
|
8370 | var csv = dsvParse(csvParse);
|
8371 | var tsv = dsvParse(tsvParse);
|
8372 |
|
8373 | function image(input, init) {
|
8374 | return new Promise(function(resolve, reject) {
|
8375 | var image = new Image;
|
8376 | for (var key in init) image[key] = init[key];
|
8377 | image.onerror = reject;
|
8378 | image.onload = function() { resolve(image); };
|
8379 | image.src = input;
|
8380 | });
|
8381 | }
|
8382 |
|
8383 | function responseJson(response) {
|
8384 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
8385 | if (response.status === 204 || response.status === 205) return;
|
8386 | return response.json();
|
8387 | }
|
8388 |
|
8389 | function json(input, init) {
|
8390 | return fetch(input, init).then(responseJson);
|
8391 | }
|
8392 |
|
8393 | function parser(type) {
|
8394 | return (input, init) => text(input, init)
|
8395 | .then(text => (new DOMParser).parseFromString(text, type));
|
8396 | }
|
8397 |
|
8398 | var xml = parser("application/xml");
|
8399 |
|
8400 | var html = parser("text/html");
|
8401 |
|
8402 | var svg = parser("image/svg+xml");
|
8403 |
|
8404 | function center(x, y) {
|
8405 | var nodes, strength = 1;
|
8406 |
|
8407 | if (x == null) x = 0;
|
8408 | if (y == null) y = 0;
|
8409 |
|
8410 | function force() {
|
8411 | var i,
|
8412 | n = nodes.length,
|
8413 | node,
|
8414 | sx = 0,
|
8415 | sy = 0;
|
8416 |
|
8417 | for (i = 0; i < n; ++i) {
|
8418 | node = nodes[i], sx += node.x, sy += node.y;
|
8419 | }
|
8420 |
|
8421 | for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) {
|
8422 | node = nodes[i], node.x -= sx, node.y -= sy;
|
8423 | }
|
8424 | }
|
8425 |
|
8426 | force.initialize = function(_) {
|
8427 | nodes = _;
|
8428 | };
|
8429 |
|
8430 | force.x = function(_) {
|
8431 | return arguments.length ? (x = +_, force) : x;
|
8432 | };
|
8433 |
|
8434 | force.y = function(_) {
|
8435 | return arguments.length ? (y = +_, force) : y;
|
8436 | };
|
8437 |
|
8438 | force.strength = function(_) {
|
8439 | return arguments.length ? (strength = +_, force) : strength;
|
8440 | };
|
8441 |
|
8442 | return force;
|
8443 | }
|
8444 |
|
8445 | function tree_add(d) {
|
8446 | const x = +this._x.call(null, d),
|
8447 | y = +this._y.call(null, d);
|
8448 | return add(this.cover(x, y), x, y, d);
|
8449 | }
|
8450 |
|
8451 | function add(tree, x, y, d) {
|
8452 | if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
|
8453 |
|
8454 | var parent,
|
8455 | node = tree._root,
|
8456 | leaf = {data: d},
|
8457 | x0 = tree._x0,
|
8458 | y0 = tree._y0,
|
8459 | x1 = tree._x1,
|
8460 | y1 = tree._y1,
|
8461 | xm,
|
8462 | ym,
|
8463 | xp,
|
8464 | yp,
|
8465 | right,
|
8466 | bottom,
|
8467 | i,
|
8468 | j;
|
8469 |
|
8470 | // If the tree is empty, initialize the root as a leaf.
|
8471 | if (!node) return tree._root = leaf, tree;
|
8472 |
|
8473 | // Find the existing leaf for the new point, or add it.
|
8474 | while (node.length) {
|
8475 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
8476 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
8477 | if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
|
8478 | }
|
8479 |
|
8480 | // Is the new point is exactly coincident with the existing point?
|
8481 | xp = +tree._x.call(null, node.data);
|
8482 | yp = +tree._y.call(null, node.data);
|
8483 | if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
|
8484 |
|
8485 | // Otherwise, split the leaf node until the old and new point are separated.
|
8486 | do {
|
8487 | parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
|
8488 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
8489 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
8490 | } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
|
8491 | return parent[j] = node, parent[i] = leaf, tree;
|
8492 | }
|
8493 |
|
8494 | function addAll(data) {
|
8495 | var d, i, n = data.length,
|
8496 | x,
|
8497 | y,
|
8498 | xz = new Array(n),
|
8499 | yz = new Array(n),
|
8500 | x0 = Infinity,
|
8501 | y0 = Infinity,
|
8502 | x1 = -Infinity,
|
8503 | y1 = -Infinity;
|
8504 |
|
8505 | // Compute the points and their extent.
|
8506 | for (i = 0; i < n; ++i) {
|
8507 | if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
|
8508 | xz[i] = x;
|
8509 | yz[i] = y;
|
8510 | if (x < x0) x0 = x;
|
8511 | if (x > x1) x1 = x;
|
8512 | if (y < y0) y0 = y;
|
8513 | if (y > y1) y1 = y;
|
8514 | }
|
8515 |
|
8516 | // If there were no (valid) points, abort.
|
8517 | if (x0 > x1 || y0 > y1) return this;
|
8518 |
|
8519 | // Expand the tree to cover the new points.
|
8520 | this.cover(x0, y0).cover(x1, y1);
|
8521 |
|
8522 | // Add the new points.
|
8523 | for (i = 0; i < n; ++i) {
|
8524 | add(this, xz[i], yz[i], data[i]);
|
8525 | }
|
8526 |
|
8527 | return this;
|
8528 | }
|
8529 |
|
8530 | function tree_cover(x, y) {
|
8531 | if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
|
8532 |
|
8533 | var x0 = this._x0,
|
8534 | y0 = this._y0,
|
8535 | x1 = this._x1,
|
8536 | y1 = this._y1;
|
8537 |
|
8538 | // If the quadtree has no extent, initialize them.
|
8539 | // Integer extent are necessary so that if we later double the extent,
|
8540 | // the existing quadrant boundaries don’t change due to floating point error!
|
8541 | if (isNaN(x0)) {
|
8542 | x1 = (x0 = Math.floor(x)) + 1;
|
8543 | y1 = (y0 = Math.floor(y)) + 1;
|
8544 | }
|
8545 |
|
8546 | // Otherwise, double repeatedly to cover.
|
8547 | else {
|
8548 | var z = x1 - x0 || 1,
|
8549 | node = this._root,
|
8550 | parent,
|
8551 | i;
|
8552 |
|
8553 | while (x0 > x || x >= x1 || y0 > y || y >= y1) {
|
8554 | i = (y < y0) << 1 | (x < x0);
|
8555 | parent = new Array(4), parent[i] = node, node = parent, z *= 2;
|
8556 | switch (i) {
|
8557 | case 0: x1 = x0 + z, y1 = y0 + z; break;
|
8558 | case 1: x0 = x1 - z, y1 = y0 + z; break;
|
8559 | case 2: x1 = x0 + z, y0 = y1 - z; break;
|
8560 | case 3: x0 = x1 - z, y0 = y1 - z; break;
|
8561 | }
|
8562 | }
|
8563 |
|
8564 | if (this._root && this._root.length) this._root = node;
|
8565 | }
|
8566 |
|
8567 | this._x0 = x0;
|
8568 | this._y0 = y0;
|
8569 | this._x1 = x1;
|
8570 | this._y1 = y1;
|
8571 | return this;
|
8572 | }
|
8573 |
|
8574 | function tree_data() {
|
8575 | var data = [];
|
8576 | this.visit(function(node) {
|
8577 | if (!node.length) do data.push(node.data); while (node = node.next)
|
8578 | });
|
8579 | return data;
|
8580 | }
|
8581 |
|
8582 | function tree_extent(_) {
|
8583 | return arguments.length
|
8584 | ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
|
8585 | : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
|
8586 | }
|
8587 |
|
8588 | function Quad(node, x0, y0, x1, y1) {
|
8589 | this.node = node;
|
8590 | this.x0 = x0;
|
8591 | this.y0 = y0;
|
8592 | this.x1 = x1;
|
8593 | this.y1 = y1;
|
8594 | }
|
8595 |
|
8596 | function tree_find(x, y, radius) {
|
8597 | var data,
|
8598 | x0 = this._x0,
|
8599 | y0 = this._y0,
|
8600 | x1,
|
8601 | y1,
|
8602 | x2,
|
8603 | y2,
|
8604 | x3 = this._x1,
|
8605 | y3 = this._y1,
|
8606 | quads = [],
|
8607 | node = this._root,
|
8608 | q,
|
8609 | i;
|
8610 |
|
8611 | if (node) quads.push(new Quad(node, x0, y0, x3, y3));
|
8612 | if (radius == null) radius = Infinity;
|
8613 | else {
|
8614 | x0 = x - radius, y0 = y - radius;
|
8615 | x3 = x + radius, y3 = y + radius;
|
8616 | radius *= radius;
|
8617 | }
|
8618 |
|
8619 | while (q = quads.pop()) {
|
8620 |
|
8621 | // Stop searching if this quadrant can’t contain a closer node.
|
8622 | if (!(node = q.node)
|
8623 | || (x1 = q.x0) > x3
|
8624 | || (y1 = q.y0) > y3
|
8625 | || (x2 = q.x1) < x0
|
8626 | || (y2 = q.y1) < y0) continue;
|
8627 |
|
8628 | // Bisect the current quadrant.
|
8629 | if (node.length) {
|
8630 | var xm = (x1 + x2) / 2,
|
8631 | ym = (y1 + y2) / 2;
|
8632 |
|
8633 | quads.push(
|
8634 | new Quad(node[3], xm, ym, x2, y2),
|
8635 | new Quad(node[2], x1, ym, xm, y2),
|
8636 | new Quad(node[1], xm, y1, x2, ym),
|
8637 | new Quad(node[0], x1, y1, xm, ym)
|
8638 | );
|
8639 |
|
8640 | // Visit the closest quadrant first.
|
8641 | if (i = (y >= ym) << 1 | (x >= xm)) {
|
8642 | q = quads[quads.length - 1];
|
8643 | quads[quads.length - 1] = quads[quads.length - 1 - i];
|
8644 | quads[quads.length - 1 - i] = q;
|
8645 | }
|
8646 | }
|
8647 |
|
8648 | // Visit this point. (Visiting coincident points isn’t necessary!)
|
8649 | else {
|
8650 | var dx = x - +this._x.call(null, node.data),
|
8651 | dy = y - +this._y.call(null, node.data),
|
8652 | d2 = dx * dx + dy * dy;
|
8653 | if (d2 < radius) {
|
8654 | var d = Math.sqrt(radius = d2);
|
8655 | x0 = x - d, y0 = y - d;
|
8656 | x3 = x + d, y3 = y + d;
|
8657 | data = node.data;
|
8658 | }
|
8659 | }
|
8660 | }
|
8661 |
|
8662 | return data;
|
8663 | }
|
8664 |
|
8665 | function tree_remove(d) {
|
8666 | if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
|
8667 |
|
8668 | var parent,
|
8669 | node = this._root,
|
8670 | retainer,
|
8671 | previous,
|
8672 | next,
|
8673 | x0 = this._x0,
|
8674 | y0 = this._y0,
|
8675 | x1 = this._x1,
|
8676 | y1 = this._y1,
|
8677 | x,
|
8678 | y,
|
8679 | xm,
|
8680 | ym,
|
8681 | right,
|
8682 | bottom,
|
8683 | i,
|
8684 | j;
|
8685 |
|
8686 | // If the tree is empty, initialize the root as a leaf.
|
8687 | if (!node) return this;
|
8688 |
|
8689 | // Find the leaf node for the point.
|
8690 | // While descending, also retain the deepest parent with a non-removed sibling.
|
8691 | if (node.length) while (true) {
|
8692 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
8693 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
8694 | if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
|
8695 | if (!node.length) break;
|
8696 | if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
|
8697 | }
|
8698 |
|
8699 | // Find the point to remove.
|
8700 | while (node.data !== d) if (!(previous = node, node = node.next)) return this;
|
8701 | if (next = node.next) delete node.next;
|
8702 |
|
8703 | // If there are multiple coincident points, remove just the point.
|
8704 | if (previous) return (next ? previous.next = next : delete previous.next), this;
|
8705 |
|
8706 | // If this is the root point, remove it.
|
8707 | if (!parent) return this._root = next, this;
|
8708 |
|
8709 | // Remove this leaf.
|
8710 | next ? parent[i] = next : delete parent[i];
|
8711 |
|
8712 | // If the parent now contains exactly one leaf, collapse superfluous parents.
|
8713 | if ((node = parent[0] || parent[1] || parent[2] || parent[3])
|
8714 | && node === (parent[3] || parent[2] || parent[1] || parent[0])
|
8715 | && !node.length) {
|
8716 | if (retainer) retainer[j] = node;
|
8717 | else this._root = node;
|
8718 | }
|
8719 |
|
8720 | return this;
|
8721 | }
|
8722 |
|
8723 | function removeAll(data) {
|
8724 | for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
|
8725 | return this;
|
8726 | }
|
8727 |
|
8728 | function tree_root() {
|
8729 | return this._root;
|
8730 | }
|
8731 |
|
8732 | function tree_size() {
|
8733 | var size = 0;
|
8734 | this.visit(function(node) {
|
8735 | if (!node.length) do ++size; while (node = node.next)
|
8736 | });
|
8737 | return size;
|
8738 | }
|
8739 |
|
8740 | function tree_visit(callback) {
|
8741 | var quads = [], q, node = this._root, child, x0, y0, x1, y1;
|
8742 | if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
|
8743 | while (q = quads.pop()) {
|
8744 | if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
|
8745 | var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
8746 | if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
8747 | if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
8748 | if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
8749 | if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
8750 | }
|
8751 | }
|
8752 | return this;
|
8753 | }
|
8754 |
|
8755 | function tree_visitAfter(callback) {
|
8756 | var quads = [], next = [], q;
|
8757 | if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
|
8758 | while (q = quads.pop()) {
|
8759 | var node = q.node;
|
8760 | if (node.length) {
|
8761 | var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
8762 | if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
8763 | if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
8764 | if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
8765 | if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
8766 | }
|
8767 | next.push(q);
|
8768 | }
|
8769 | while (q = next.pop()) {
|
8770 | callback(q.node, q.x0, q.y0, q.x1, q.y1);
|
8771 | }
|
8772 | return this;
|
8773 | }
|
8774 |
|
8775 | function defaultX(d) {
|
8776 | return d[0];
|
8777 | }
|
8778 |
|
8779 | function tree_x(_) {
|
8780 | return arguments.length ? (this._x = _, this) : this._x;
|
8781 | }
|
8782 |
|
8783 | function defaultY(d) {
|
8784 | return d[1];
|
8785 | }
|
8786 |
|
8787 | function tree_y(_) {
|
8788 | return arguments.length ? (this._y = _, this) : this._y;
|
8789 | }
|
8790 |
|
8791 | function quadtree(nodes, x, y) {
|
8792 | var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
|
8793 | return nodes == null ? tree : tree.addAll(nodes);
|
8794 | }
|
8795 |
|
8796 | function Quadtree(x, y, x0, y0, x1, y1) {
|
8797 | this._x = x;
|
8798 | this._y = y;
|
8799 | this._x0 = x0;
|
8800 | this._y0 = y0;
|
8801 | this._x1 = x1;
|
8802 | this._y1 = y1;
|
8803 | this._root = undefined;
|
8804 | }
|
8805 |
|
8806 | function leaf_copy(leaf) {
|
8807 | var copy = {data: leaf.data}, next = copy;
|
8808 | while (leaf = leaf.next) next = next.next = {data: leaf.data};
|
8809 | return copy;
|
8810 | }
|
8811 |
|
8812 | var treeProto = quadtree.prototype = Quadtree.prototype;
|
8813 |
|
8814 | treeProto.copy = function() {
|
8815 | var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
|
8816 | node = this._root,
|
8817 | nodes,
|
8818 | child;
|
8819 |
|
8820 | if (!node) return copy;
|
8821 |
|
8822 | if (!node.length) return copy._root = leaf_copy(node), copy;
|
8823 |
|
8824 | nodes = [{source: node, target: copy._root = new Array(4)}];
|
8825 | while (node = nodes.pop()) {
|
8826 | for (var i = 0; i < 4; ++i) {
|
8827 | if (child = node.source[i]) {
|
8828 | if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
|
8829 | else node.target[i] = leaf_copy(child);
|
8830 | }
|
8831 | }
|
8832 | }
|
8833 |
|
8834 | return copy;
|
8835 | };
|
8836 |
|
8837 | treeProto.add = tree_add;
|
8838 | treeProto.addAll = addAll;
|
8839 | treeProto.cover = tree_cover;
|
8840 | treeProto.data = tree_data;
|
8841 | treeProto.extent = tree_extent;
|
8842 | treeProto.find = tree_find;
|
8843 | treeProto.remove = tree_remove;
|
8844 | treeProto.removeAll = removeAll;
|
8845 | treeProto.root = tree_root;
|
8846 | treeProto.size = tree_size;
|
8847 | treeProto.visit = tree_visit;
|
8848 | treeProto.visitAfter = tree_visitAfter;
|
8849 | treeProto.x = tree_x;
|
8850 | treeProto.y = tree_y;
|
8851 |
|
8852 | function constant$4(x) {
|
8853 | return function() {
|
8854 | return x;
|
8855 | };
|
8856 | }
|
8857 |
|
8858 | function jiggle(random) {
|
8859 | return (random() - 0.5) * 1e-6;
|
8860 | }
|
8861 |
|
8862 | function x$3(d) {
|
8863 | return d.x + d.vx;
|
8864 | }
|
8865 |
|
8866 | function y$3(d) {
|
8867 | return d.y + d.vy;
|
8868 | }
|
8869 |
|
8870 | function collide(radius) {
|
8871 | var nodes,
|
8872 | radii,
|
8873 | random,
|
8874 | strength = 1,
|
8875 | iterations = 1;
|
8876 |
|
8877 | if (typeof radius !== "function") radius = constant$4(radius == null ? 1 : +radius);
|
8878 |
|
8879 | function force() {
|
8880 | var i, n = nodes.length,
|
8881 | tree,
|
8882 | node,
|
8883 | xi,
|
8884 | yi,
|
8885 | ri,
|
8886 | ri2;
|
8887 |
|
8888 | for (var k = 0; k < iterations; ++k) {
|
8889 | tree = quadtree(nodes, x$3, y$3).visitAfter(prepare);
|
8890 | for (i = 0; i < n; ++i) {
|
8891 | node = nodes[i];
|
8892 | ri = radii[node.index], ri2 = ri * ri;
|
8893 | xi = node.x + node.vx;
|
8894 | yi = node.y + node.vy;
|
8895 | tree.visit(apply);
|
8896 | }
|
8897 | }
|
8898 |
|
8899 | function apply(quad, x0, y0, x1, y1) {
|
8900 | var data = quad.data, rj = quad.r, r = ri + rj;
|
8901 | if (data) {
|
8902 | if (data.index > node.index) {
|
8903 | var x = xi - data.x - data.vx,
|
8904 | y = yi - data.y - data.vy,
|
8905 | l = x * x + y * y;
|
8906 | if (l < r * r) {
|
8907 | if (x === 0) x = jiggle(random), l += x * x;
|
8908 | if (y === 0) y = jiggle(random), l += y * y;
|
8909 | l = (r - (l = Math.sqrt(l))) / l * strength;
|
8910 | node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
|
8911 | node.vy += (y *= l) * r;
|
8912 | data.vx -= x * (r = 1 - r);
|
8913 | data.vy -= y * r;
|
8914 | }
|
8915 | }
|
8916 | return;
|
8917 | }
|
8918 | return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
|
8919 | }
|
8920 | }
|
8921 |
|
8922 | function prepare(quad) {
|
8923 | if (quad.data) return quad.r = radii[quad.data.index];
|
8924 | for (var i = quad.r = 0; i < 4; ++i) {
|
8925 | if (quad[i] && quad[i].r > quad.r) {
|
8926 | quad.r = quad[i].r;
|
8927 | }
|
8928 | }
|
8929 | }
|
8930 |
|
8931 | function initialize() {
|
8932 | if (!nodes) return;
|
8933 | var i, n = nodes.length, node;
|
8934 | radii = new Array(n);
|
8935 | for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
|
8936 | }
|
8937 |
|
8938 | force.initialize = function(_nodes, _random) {
|
8939 | nodes = _nodes;
|
8940 | random = _random;
|
8941 | initialize();
|
8942 | };
|
8943 |
|
8944 | force.iterations = function(_) {
|
8945 | return arguments.length ? (iterations = +_, force) : iterations;
|
8946 | };
|
8947 |
|
8948 | force.strength = function(_) {
|
8949 | return arguments.length ? (strength = +_, force) : strength;
|
8950 | };
|
8951 |
|
8952 | force.radius = function(_) {
|
8953 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
|
8954 | };
|
8955 |
|
8956 | return force;
|
8957 | }
|
8958 |
|
8959 | function index$3(d) {
|
8960 | return d.index;
|
8961 | }
|
8962 |
|
8963 | function find(nodeById, nodeId) {
|
8964 | var node = nodeById.get(nodeId);
|
8965 | if (!node) throw new Error("node not found: " + nodeId);
|
8966 | return node;
|
8967 | }
|
8968 |
|
8969 | function link$2(links) {
|
8970 | var id = index$3,
|
8971 | strength = defaultStrength,
|
8972 | strengths,
|
8973 | distance = constant$4(30),
|
8974 | distances,
|
8975 | nodes,
|
8976 | count,
|
8977 | bias,
|
8978 | random,
|
8979 | iterations = 1;
|
8980 |
|
8981 | if (links == null) links = [];
|
8982 |
|
8983 | function defaultStrength(link) {
|
8984 | return 1 / Math.min(count[link.source.index], count[link.target.index]);
|
8985 | }
|
8986 |
|
8987 | function force(alpha) {
|
8988 | for (var k = 0, n = links.length; k < iterations; ++k) {
|
8989 | for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
|
8990 | link = links[i], source = link.source, target = link.target;
|
8991 | x = target.x + target.vx - source.x - source.vx || jiggle(random);
|
8992 | y = target.y + target.vy - source.y - source.vy || jiggle(random);
|
8993 | l = Math.sqrt(x * x + y * y);
|
8994 | l = (l - distances[i]) / l * alpha * strengths[i];
|
8995 | x *= l, y *= l;
|
8996 | target.vx -= x * (b = bias[i]);
|
8997 | target.vy -= y * b;
|
8998 | source.vx += x * (b = 1 - b);
|
8999 | source.vy += y * b;
|
9000 | }
|
9001 | }
|
9002 | }
|
9003 |
|
9004 | function initialize() {
|
9005 | if (!nodes) return;
|
9006 |
|
9007 | var i,
|
9008 | n = nodes.length,
|
9009 | m = links.length,
|
9010 | nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])),
|
9011 | link;
|
9012 |
|
9013 | for (i = 0, count = new Array(n); i < m; ++i) {
|
9014 | link = links[i], link.index = i;
|
9015 | if (typeof link.source !== "object") link.source = find(nodeById, link.source);
|
9016 | if (typeof link.target !== "object") link.target = find(nodeById, link.target);
|
9017 | count[link.source.index] = (count[link.source.index] || 0) + 1;
|
9018 | count[link.target.index] = (count[link.target.index] || 0) + 1;
|
9019 | }
|
9020 |
|
9021 | for (i = 0, bias = new Array(m); i < m; ++i) {
|
9022 | link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
|
9023 | }
|
9024 |
|
9025 | strengths = new Array(m), initializeStrength();
|
9026 | distances = new Array(m), initializeDistance();
|
9027 | }
|
9028 |
|
9029 | function initializeStrength() {
|
9030 | if (!nodes) return;
|
9031 |
|
9032 | for (var i = 0, n = links.length; i < n; ++i) {
|
9033 | strengths[i] = +strength(links[i], i, links);
|
9034 | }
|
9035 | }
|
9036 |
|
9037 | function initializeDistance() {
|
9038 | if (!nodes) return;
|
9039 |
|
9040 | for (var i = 0, n = links.length; i < n; ++i) {
|
9041 | distances[i] = +distance(links[i], i, links);
|
9042 | }
|
9043 | }
|
9044 |
|
9045 | force.initialize = function(_nodes, _random) {
|
9046 | nodes = _nodes;
|
9047 | random = _random;
|
9048 | initialize();
|
9049 | };
|
9050 |
|
9051 | force.links = function(_) {
|
9052 | return arguments.length ? (links = _, initialize(), force) : links;
|
9053 | };
|
9054 |
|
9055 | force.id = function(_) {
|
9056 | return arguments.length ? (id = _, force) : id;
|
9057 | };
|
9058 |
|
9059 | force.iterations = function(_) {
|
9060 | return arguments.length ? (iterations = +_, force) : iterations;
|
9061 | };
|
9062 |
|
9063 | force.strength = function(_) {
|
9064 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initializeStrength(), force) : strength;
|
9065 | };
|
9066 |
|
9067 | force.distance = function(_) {
|
9068 | return arguments.length ? (distance = typeof _ === "function" ? _ : constant$4(+_), initializeDistance(), force) : distance;
|
9069 | };
|
9070 |
|
9071 | return force;
|
9072 | }
|
9073 |
|
9074 | // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
|
9075 | const a$2 = 1664525;
|
9076 | const c$4 = 1013904223;
|
9077 | const m$1 = 4294967296; // 2^32
|
9078 |
|
9079 | function lcg$2() {
|
9080 | let s = 1;
|
9081 | return () => (s = (a$2 * s + c$4) % m$1) / m$1;
|
9082 | }
|
9083 |
|
9084 | function x$2(d) {
|
9085 | return d.x;
|
9086 | }
|
9087 |
|
9088 | function y$2(d) {
|
9089 | return d.y;
|
9090 | }
|
9091 |
|
9092 | var initialRadius = 10,
|
9093 | initialAngle = Math.PI * (3 - Math.sqrt(5));
|
9094 |
|
9095 | function simulation(nodes) {
|
9096 | var simulation,
|
9097 | alpha = 1,
|
9098 | alphaMin = 0.001,
|
9099 | alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
|
9100 | alphaTarget = 0,
|
9101 | velocityDecay = 0.6,
|
9102 | forces = new Map(),
|
9103 | stepper = timer(step),
|
9104 | event = dispatch("tick", "end"),
|
9105 | random = lcg$2();
|
9106 |
|
9107 | if (nodes == null) nodes = [];
|
9108 |
|
9109 | function step() {
|
9110 | tick();
|
9111 | event.call("tick", simulation);
|
9112 | if (alpha < alphaMin) {
|
9113 | stepper.stop();
|
9114 | event.call("end", simulation);
|
9115 | }
|
9116 | }
|
9117 |
|
9118 | function tick(iterations) {
|
9119 | var i, n = nodes.length, node;
|
9120 |
|
9121 | if (iterations === undefined) iterations = 1;
|
9122 |
|
9123 | for (var k = 0; k < iterations; ++k) {
|
9124 | alpha += (alphaTarget - alpha) * alphaDecay;
|
9125 |
|
9126 | forces.forEach(function(force) {
|
9127 | force(alpha);
|
9128 | });
|
9129 |
|
9130 | for (i = 0; i < n; ++i) {
|
9131 | node = nodes[i];
|
9132 | if (node.fx == null) node.x += node.vx *= velocityDecay;
|
9133 | else node.x = node.fx, node.vx = 0;
|
9134 | if (node.fy == null) node.y += node.vy *= velocityDecay;
|
9135 | else node.y = node.fy, node.vy = 0;
|
9136 | }
|
9137 | }
|
9138 |
|
9139 | return simulation;
|
9140 | }
|
9141 |
|
9142 | function initializeNodes() {
|
9143 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
9144 | node = nodes[i], node.index = i;
|
9145 | if (node.fx != null) node.x = node.fx;
|
9146 | if (node.fy != null) node.y = node.fy;
|
9147 | if (isNaN(node.x) || isNaN(node.y)) {
|
9148 | var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
|
9149 | node.x = radius * Math.cos(angle);
|
9150 | node.y = radius * Math.sin(angle);
|
9151 | }
|
9152 | if (isNaN(node.vx) || isNaN(node.vy)) {
|
9153 | node.vx = node.vy = 0;
|
9154 | }
|
9155 | }
|
9156 | }
|
9157 |
|
9158 | function initializeForce(force) {
|
9159 | if (force.initialize) force.initialize(nodes, random);
|
9160 | return force;
|
9161 | }
|
9162 |
|
9163 | initializeNodes();
|
9164 |
|
9165 | return simulation = {
|
9166 | tick: tick,
|
9167 |
|
9168 | restart: function() {
|
9169 | return stepper.restart(step), simulation;
|
9170 | },
|
9171 |
|
9172 | stop: function() {
|
9173 | return stepper.stop(), simulation;
|
9174 | },
|
9175 |
|
9176 | nodes: function(_) {
|
9177 | return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
|
9178 | },
|
9179 |
|
9180 | alpha: function(_) {
|
9181 | return arguments.length ? (alpha = +_, simulation) : alpha;
|
9182 | },
|
9183 |
|
9184 | alphaMin: function(_) {
|
9185 | return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
|
9186 | },
|
9187 |
|
9188 | alphaDecay: function(_) {
|
9189 | return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
|
9190 | },
|
9191 |
|
9192 | alphaTarget: function(_) {
|
9193 | return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
|
9194 | },
|
9195 |
|
9196 | velocityDecay: function(_) {
|
9197 | return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
|
9198 | },
|
9199 |
|
9200 | randomSource: function(_) {
|
9201 | return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
|
9202 | },
|
9203 |
|
9204 | force: function(name, _) {
|
9205 | return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
|
9206 | },
|
9207 |
|
9208 | find: function(x, y, radius) {
|
9209 | var i = 0,
|
9210 | n = nodes.length,
|
9211 | dx,
|
9212 | dy,
|
9213 | d2,
|
9214 | node,
|
9215 | closest;
|
9216 |
|
9217 | if (radius == null) radius = Infinity;
|
9218 | else radius *= radius;
|
9219 |
|
9220 | for (i = 0; i < n; ++i) {
|
9221 | node = nodes[i];
|
9222 | dx = x - node.x;
|
9223 | dy = y - node.y;
|
9224 | d2 = dx * dx + dy * dy;
|
9225 | if (d2 < radius) closest = node, radius = d2;
|
9226 | }
|
9227 |
|
9228 | return closest;
|
9229 | },
|
9230 |
|
9231 | on: function(name, _) {
|
9232 | return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
|
9233 | }
|
9234 | };
|
9235 | }
|
9236 |
|
9237 | function manyBody() {
|
9238 | var nodes,
|
9239 | node,
|
9240 | random,
|
9241 | alpha,
|
9242 | strength = constant$4(-30),
|
9243 | strengths,
|
9244 | distanceMin2 = 1,
|
9245 | distanceMax2 = Infinity,
|
9246 | theta2 = 0.81;
|
9247 |
|
9248 | function force(_) {
|
9249 | var i, n = nodes.length, tree = quadtree(nodes, x$2, y$2).visitAfter(accumulate);
|
9250 | for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
|
9251 | }
|
9252 |
|
9253 | function initialize() {
|
9254 | if (!nodes) return;
|
9255 | var i, n = nodes.length, node;
|
9256 | strengths = new Array(n);
|
9257 | for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
|
9258 | }
|
9259 |
|
9260 | function accumulate(quad) {
|
9261 | var strength = 0, q, c, weight = 0, x, y, i;
|
9262 |
|
9263 | // For internal nodes, accumulate forces from child quadrants.
|
9264 | if (quad.length) {
|
9265 | for (x = y = i = 0; i < 4; ++i) {
|
9266 | if ((q = quad[i]) && (c = Math.abs(q.value))) {
|
9267 | strength += q.value, weight += c, x += c * q.x, y += c * q.y;
|
9268 | }
|
9269 | }
|
9270 | quad.x = x / weight;
|
9271 | quad.y = y / weight;
|
9272 | }
|
9273 |
|
9274 | // For leaf nodes, accumulate forces from coincident quadrants.
|
9275 | else {
|
9276 | q = quad;
|
9277 | q.x = q.data.x;
|
9278 | q.y = q.data.y;
|
9279 | do strength += strengths[q.data.index];
|
9280 | while (q = q.next);
|
9281 | }
|
9282 |
|
9283 | quad.value = strength;
|
9284 | }
|
9285 |
|
9286 | function apply(quad, x1, _, x2) {
|
9287 | if (!quad.value) return true;
|
9288 |
|
9289 | var x = quad.x - node.x,
|
9290 | y = quad.y - node.y,
|
9291 | w = x2 - x1,
|
9292 | l = x * x + y * y;
|
9293 |
|
9294 | // Apply the Barnes-Hut approximation if possible.
|
9295 | // Limit forces for very close nodes; randomize direction if coincident.
|
9296 | if (w * w / theta2 < l) {
|
9297 | if (l < distanceMax2) {
|
9298 | if (x === 0) x = jiggle(random), l += x * x;
|
9299 | if (y === 0) y = jiggle(random), l += y * y;
|
9300 | if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
9301 | node.vx += x * quad.value * alpha / l;
|
9302 | node.vy += y * quad.value * alpha / l;
|
9303 | }
|
9304 | return true;
|
9305 | }
|
9306 |
|
9307 | // Otherwise, process points directly.
|
9308 | else if (quad.length || l >= distanceMax2) return;
|
9309 |
|
9310 | // Limit forces for very close nodes; randomize direction if coincident.
|
9311 | if (quad.data !== node || quad.next) {
|
9312 | if (x === 0) x = jiggle(random), l += x * x;
|
9313 | if (y === 0) y = jiggle(random), l += y * y;
|
9314 | if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
9315 | }
|
9316 |
|
9317 | do if (quad.data !== node) {
|
9318 | w = strengths[quad.data.index] * alpha / l;
|
9319 | node.vx += x * w;
|
9320 | node.vy += y * w;
|
9321 | } while (quad = quad.next);
|
9322 | }
|
9323 |
|
9324 | force.initialize = function(_nodes, _random) {
|
9325 | nodes = _nodes;
|
9326 | random = _random;
|
9327 | initialize();
|
9328 | };
|
9329 |
|
9330 | force.strength = function(_) {
|
9331 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
|
9332 | };
|
9333 |
|
9334 | force.distanceMin = function(_) {
|
9335 | return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
|
9336 | };
|
9337 |
|
9338 | force.distanceMax = function(_) {
|
9339 | return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
|
9340 | };
|
9341 |
|
9342 | force.theta = function(_) {
|
9343 | return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
|
9344 | };
|
9345 |
|
9346 | return force;
|
9347 | }
|
9348 |
|
9349 | function radial$1(radius, x, y) {
|
9350 | var nodes,
|
9351 | strength = constant$4(0.1),
|
9352 | strengths,
|
9353 | radiuses;
|
9354 |
|
9355 | if (typeof radius !== "function") radius = constant$4(+radius);
|
9356 | if (x == null) x = 0;
|
9357 | if (y == null) y = 0;
|
9358 |
|
9359 | function force(alpha) {
|
9360 | for (var i = 0, n = nodes.length; i < n; ++i) {
|
9361 | var node = nodes[i],
|
9362 | dx = node.x - x || 1e-6,
|
9363 | dy = node.y - y || 1e-6,
|
9364 | r = Math.sqrt(dx * dx + dy * dy),
|
9365 | k = (radiuses[i] - r) * strengths[i] * alpha / r;
|
9366 | node.vx += dx * k;
|
9367 | node.vy += dy * k;
|
9368 | }
|
9369 | }
|
9370 |
|
9371 | function initialize() {
|
9372 | if (!nodes) return;
|
9373 | var i, n = nodes.length;
|
9374 | strengths = new Array(n);
|
9375 | radiuses = new Array(n);
|
9376 | for (i = 0; i < n; ++i) {
|
9377 | radiuses[i] = +radius(nodes[i], i, nodes);
|
9378 | strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
|
9379 | }
|
9380 | }
|
9381 |
|
9382 | force.initialize = function(_) {
|
9383 | nodes = _, initialize();
|
9384 | };
|
9385 |
|
9386 | force.strength = function(_) {
|
9387 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
|
9388 | };
|
9389 |
|
9390 | force.radius = function(_) {
|
9391 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius;
|
9392 | };
|
9393 |
|
9394 | force.x = function(_) {
|
9395 | return arguments.length ? (x = +_, force) : x;
|
9396 | };
|
9397 |
|
9398 | force.y = function(_) {
|
9399 | return arguments.length ? (y = +_, force) : y;
|
9400 | };
|
9401 |
|
9402 | return force;
|
9403 | }
|
9404 |
|
9405 | function x$1(x) {
|
9406 | var strength = constant$4(0.1),
|
9407 | nodes,
|
9408 | strengths,
|
9409 | xz;
|
9410 |
|
9411 | if (typeof x !== "function") x = constant$4(x == null ? 0 : +x);
|
9412 |
|
9413 | function force(alpha) {
|
9414 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
9415 | node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
|
9416 | }
|
9417 | }
|
9418 |
|
9419 | function initialize() {
|
9420 | if (!nodes) return;
|
9421 | var i, n = nodes.length;
|
9422 | strengths = new Array(n);
|
9423 | xz = new Array(n);
|
9424 | for (i = 0; i < n; ++i) {
|
9425 | strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
9426 | }
|
9427 | }
|
9428 |
|
9429 | force.initialize = function(_) {
|
9430 | nodes = _;
|
9431 | initialize();
|
9432 | };
|
9433 |
|
9434 | force.strength = function(_) {
|
9435 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
|
9436 | };
|
9437 |
|
9438 | force.x = function(_) {
|
9439 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : x;
|
9440 | };
|
9441 |
|
9442 | return force;
|
9443 | }
|
9444 |
|
9445 | function y$1(y) {
|
9446 | var strength = constant$4(0.1),
|
9447 | nodes,
|
9448 | strengths,
|
9449 | yz;
|
9450 |
|
9451 | if (typeof y !== "function") y = constant$4(y == null ? 0 : +y);
|
9452 |
|
9453 | function force(alpha) {
|
9454 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
9455 | node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
|
9456 | }
|
9457 | }
|
9458 |
|
9459 | function initialize() {
|
9460 | if (!nodes) return;
|
9461 | var i, n = nodes.length;
|
9462 | strengths = new Array(n);
|
9463 | yz = new Array(n);
|
9464 | for (i = 0; i < n; ++i) {
|
9465 | strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
9466 | }
|
9467 | }
|
9468 |
|
9469 | force.initialize = function(_) {
|
9470 | nodes = _;
|
9471 | initialize();
|
9472 | };
|
9473 |
|
9474 | force.strength = function(_) {
|
9475 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength;
|
9476 | };
|
9477 |
|
9478 | force.y = function(_) {
|
9479 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : y;
|
9480 | };
|
9481 |
|
9482 | return force;
|
9483 | }
|
9484 |
|
9485 | function formatDecimal(x) {
|
9486 | return Math.abs(x = Math.round(x)) >= 1e21
|
9487 | ? x.toLocaleString("en").replace(/,/g, "")
|
9488 | : x.toString(10);
|
9489 | }
|
9490 |
|
9491 | // Computes the decimal coefficient and exponent of the specified number x with
|
9492 | // significant digits p, where x is positive and p is in [1, 21] or undefined.
|
9493 | // For example, formatDecimalParts(1.23) returns ["123", 0].
|
9494 | function formatDecimalParts(x, p) {
|
9495 | if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
|
9496 | var i, coefficient = x.slice(0, i);
|
9497 |
|
9498 | // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
|
9499 | // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
|
9500 | return [
|
9501 | coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
|
9502 | +x.slice(i + 1)
|
9503 | ];
|
9504 | }
|
9505 |
|
9506 | function exponent(x) {
|
9507 | return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
|
9508 | }
|
9509 |
|
9510 | function formatGroup(grouping, thousands) {
|
9511 | return function(value, width) {
|
9512 | var i = value.length,
|
9513 | t = [],
|
9514 | j = 0,
|
9515 | g = grouping[0],
|
9516 | length = 0;
|
9517 |
|
9518 | while (i > 0 && g > 0) {
|
9519 | if (length + g + 1 > width) g = Math.max(1, width - length);
|
9520 | t.push(value.substring(i -= g, i + g));
|
9521 | if ((length += g + 1) > width) break;
|
9522 | g = grouping[j = (j + 1) % grouping.length];
|
9523 | }
|
9524 |
|
9525 | return t.reverse().join(thousands);
|
9526 | };
|
9527 | }
|
9528 |
|
9529 | function formatNumerals(numerals) {
|
9530 | return function(value) {
|
9531 | return value.replace(/[0-9]/g, function(i) {
|
9532 | return numerals[+i];
|
9533 | });
|
9534 | };
|
9535 | }
|
9536 |
|
9537 | // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
|
9538 | var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
|
9539 |
|
9540 | function formatSpecifier(specifier) {
|
9541 | if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
|
9542 | var match;
|
9543 | return new FormatSpecifier({
|
9544 | fill: match[1],
|
9545 | align: match[2],
|
9546 | sign: match[3],
|
9547 | symbol: match[4],
|
9548 | zero: match[5],
|
9549 | width: match[6],
|
9550 | comma: match[7],
|
9551 | precision: match[8] && match[8].slice(1),
|
9552 | trim: match[9],
|
9553 | type: match[10]
|
9554 | });
|
9555 | }
|
9556 |
|
9557 | formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
|
9558 |
|
9559 | function FormatSpecifier(specifier) {
|
9560 | this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
|
9561 | this.align = specifier.align === undefined ? ">" : specifier.align + "";
|
9562 | this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
|
9563 | this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
|
9564 | this.zero = !!specifier.zero;
|
9565 | this.width = specifier.width === undefined ? undefined : +specifier.width;
|
9566 | this.comma = !!specifier.comma;
|
9567 | this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
|
9568 | this.trim = !!specifier.trim;
|
9569 | this.type = specifier.type === undefined ? "" : specifier.type + "";
|
9570 | }
|
9571 |
|
9572 | FormatSpecifier.prototype.toString = function() {
|
9573 | return this.fill
|
9574 | + this.align
|
9575 | + this.sign
|
9576 | + this.symbol
|
9577 | + (this.zero ? "0" : "")
|
9578 | + (this.width === undefined ? "" : Math.max(1, this.width | 0))
|
9579 | + (this.comma ? "," : "")
|
9580 | + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
|
9581 | + (this.trim ? "~" : "")
|
9582 | + this.type;
|
9583 | };
|
9584 |
|
9585 | // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
|
9586 | function formatTrim(s) {
|
9587 | out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
|
9588 | switch (s[i]) {
|
9589 | case ".": i0 = i1 = i; break;
|
9590 | case "0": if (i0 === 0) i0 = i; i1 = i; break;
|
9591 | default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
|
9592 | }
|
9593 | }
|
9594 | return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
|
9595 | }
|
9596 |
|
9597 | var prefixExponent;
|
9598 |
|
9599 | function formatPrefixAuto(x, p) {
|
9600 | var d = formatDecimalParts(x, p);
|
9601 | if (!d) return x + "";
|
9602 | var coefficient = d[0],
|
9603 | exponent = d[1],
|
9604 | i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
|
9605 | n = coefficient.length;
|
9606 | return i === n ? coefficient
|
9607 | : i > n ? coefficient + new Array(i - n + 1).join("0")
|
9608 | : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
|
9609 | : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
|
9610 | }
|
9611 |
|
9612 | function formatRounded(x, p) {
|
9613 | var d = formatDecimalParts(x, p);
|
9614 | if (!d) return x + "";
|
9615 | var coefficient = d[0],
|
9616 | exponent = d[1];
|
9617 | return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
|
9618 | : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
|
9619 | : coefficient + new Array(exponent - coefficient.length + 2).join("0");
|
9620 | }
|
9621 |
|
9622 | var formatTypes = {
|
9623 | "%": (x, p) => (x * 100).toFixed(p),
|
9624 | "b": (x) => Math.round(x).toString(2),
|
9625 | "c": (x) => x + "",
|
9626 | "d": formatDecimal,
|
9627 | "e": (x, p) => x.toExponential(p),
|
9628 | "f": (x, p) => x.toFixed(p),
|
9629 | "g": (x, p) => x.toPrecision(p),
|
9630 | "o": (x) => Math.round(x).toString(8),
|
9631 | "p": (x, p) => formatRounded(x * 100, p),
|
9632 | "r": formatRounded,
|
9633 | "s": formatPrefixAuto,
|
9634 | "X": (x) => Math.round(x).toString(16).toUpperCase(),
|
9635 | "x": (x) => Math.round(x).toString(16)
|
9636 | };
|
9637 |
|
9638 | function identity$6(x) {
|
9639 | return x;
|
9640 | }
|
9641 |
|
9642 | var map = Array.prototype.map,
|
9643 | prefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];
|
9644 |
|
9645 | function formatLocale$1(locale) {
|
9646 | var group = locale.grouping === undefined || locale.thousands === undefined ? identity$6 : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""),
|
9647 | currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
|
9648 | currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
|
9649 | decimal = locale.decimal === undefined ? "." : locale.decimal + "",
|
9650 | numerals = locale.numerals === undefined ? identity$6 : formatNumerals(map.call(locale.numerals, String)),
|
9651 | percent = locale.percent === undefined ? "%" : locale.percent + "",
|
9652 | minus = locale.minus === undefined ? "−" : locale.minus + "",
|
9653 | nan = locale.nan === undefined ? "NaN" : locale.nan + "";
|
9654 |
|
9655 | function newFormat(specifier) {
|
9656 | specifier = formatSpecifier(specifier);
|
9657 |
|
9658 | var fill = specifier.fill,
|
9659 | align = specifier.align,
|
9660 | sign = specifier.sign,
|
9661 | symbol = specifier.symbol,
|
9662 | zero = specifier.zero,
|
9663 | width = specifier.width,
|
9664 | comma = specifier.comma,
|
9665 | precision = specifier.precision,
|
9666 | trim = specifier.trim,
|
9667 | type = specifier.type;
|
9668 |
|
9669 | // The "n" type is an alias for ",g".
|
9670 | if (type === "n") comma = true, type = "g";
|
9671 |
|
9672 | // The "" type, and any invalid type, is an alias for ".12~g".
|
9673 | else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
|
9674 |
|
9675 | // If zero fill is specified, padding goes after sign and before digits.
|
9676 | if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
|
9677 |
|
9678 | // Compute the prefix and suffix.
|
9679 | // For SI-prefix, the suffix is lazily computed.
|
9680 | var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
|
9681 | suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
|
9682 |
|
9683 | // What format function should we use?
|
9684 | // Is this an integer type?
|
9685 | // Can this type generate exponential notation?
|
9686 | var formatType = formatTypes[type],
|
9687 | maybeSuffix = /[defgprs%]/.test(type);
|
9688 |
|
9689 | // Set the default precision if not specified,
|
9690 | // or clamp the specified precision to the supported range.
|
9691 | // For significant precision, it must be in [1, 21].
|
9692 | // For fixed precision, it must be in [0, 20].
|
9693 | precision = precision === undefined ? 6
|
9694 | : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
|
9695 | : Math.max(0, Math.min(20, precision));
|
9696 |
|
9697 | function format(value) {
|
9698 | var valuePrefix = prefix,
|
9699 | valueSuffix = suffix,
|
9700 | i, n, c;
|
9701 |
|
9702 | if (type === "c") {
|
9703 | valueSuffix = formatType(value) + valueSuffix;
|
9704 | value = "";
|
9705 | } else {
|
9706 | value = +value;
|
9707 |
|
9708 | // Determine the sign. -0 is not less than 0, but 1 / -0 is!
|
9709 | var valueNegative = value < 0 || 1 / value < 0;
|
9710 |
|
9711 | // Perform the initial formatting.
|
9712 | value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
|
9713 |
|
9714 | // Trim insignificant zeros.
|
9715 | if (trim) value = formatTrim(value);
|
9716 |
|
9717 | // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
|
9718 | if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
|
9719 |
|
9720 | // Compute the prefix and suffix.
|
9721 | valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
|
9722 | valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
|
9723 |
|
9724 | // Break the formatted value into the integer “value” part that can be
|
9725 | // grouped, and fractional or exponential “suffix” part that is not.
|
9726 | if (maybeSuffix) {
|
9727 | i = -1, n = value.length;
|
9728 | while (++i < n) {
|
9729 | if (c = value.charCodeAt(i), 48 > c || c > 57) {
|
9730 | valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
|
9731 | value = value.slice(0, i);
|
9732 | break;
|
9733 | }
|
9734 | }
|
9735 | }
|
9736 | }
|
9737 |
|
9738 | // If the fill character is not "0", grouping is applied before padding.
|
9739 | if (comma && !zero) value = group(value, Infinity);
|
9740 |
|
9741 | // Compute the padding.
|
9742 | var length = valuePrefix.length + value.length + valueSuffix.length,
|
9743 | padding = length < width ? new Array(width - length + 1).join(fill) : "";
|
9744 |
|
9745 | // If the fill character is "0", grouping is applied after padding.
|
9746 | if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
|
9747 |
|
9748 | // Reconstruct the final output based on the desired alignment.
|
9749 | switch (align) {
|
9750 | case "<": value = valuePrefix + value + valueSuffix + padding; break;
|
9751 | case "=": value = valuePrefix + padding + value + valueSuffix; break;
|
9752 | case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
|
9753 | default: value = padding + valuePrefix + value + valueSuffix; break;
|
9754 | }
|
9755 |
|
9756 | return numerals(value);
|
9757 | }
|
9758 |
|
9759 | format.toString = function() {
|
9760 | return specifier + "";
|
9761 | };
|
9762 |
|
9763 | return format;
|
9764 | }
|
9765 |
|
9766 | function formatPrefix(specifier, value) {
|
9767 | var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
|
9768 | e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
|
9769 | k = Math.pow(10, -e),
|
9770 | prefix = prefixes[8 + e / 3];
|
9771 | return function(value) {
|
9772 | return f(k * value) + prefix;
|
9773 | };
|
9774 | }
|
9775 |
|
9776 | return {
|
9777 | format: newFormat,
|
9778 | formatPrefix: formatPrefix
|
9779 | };
|
9780 | }
|
9781 |
|
9782 | var locale$1;
|
9783 | exports.format = void 0;
|
9784 | exports.formatPrefix = void 0;
|
9785 |
|
9786 | defaultLocale$1({
|
9787 | thousands: ",",
|
9788 | grouping: [3],
|
9789 | currency: ["$", ""]
|
9790 | });
|
9791 |
|
9792 | function defaultLocale$1(definition) {
|
9793 | locale$1 = formatLocale$1(definition);
|
9794 | exports.format = locale$1.format;
|
9795 | exports.formatPrefix = locale$1.formatPrefix;
|
9796 | return locale$1;
|
9797 | }
|
9798 |
|
9799 | function precisionFixed(step) {
|
9800 | return Math.max(0, -exponent(Math.abs(step)));
|
9801 | }
|
9802 |
|
9803 | function precisionPrefix(step, value) {
|
9804 | return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
|
9805 | }
|
9806 |
|
9807 | function precisionRound(step, max) {
|
9808 | step = Math.abs(step), max = Math.abs(max) - step;
|
9809 | return Math.max(0, exponent(max) - exponent(step)) + 1;
|
9810 | }
|
9811 |
|
9812 | var epsilon$1 = 1e-6;
|
9813 | var epsilon2 = 1e-12;
|
9814 | var pi$1 = Math.PI;
|
9815 | var halfPi$1 = pi$1 / 2;
|
9816 | var quarterPi = pi$1 / 4;
|
9817 | var tau$1 = pi$1 * 2;
|
9818 |
|
9819 | var degrees = 180 / pi$1;
|
9820 | var radians = pi$1 / 180;
|
9821 |
|
9822 | var abs$1 = Math.abs;
|
9823 | var atan = Math.atan;
|
9824 | var atan2$1 = Math.atan2;
|
9825 | var cos$1 = Math.cos;
|
9826 | var ceil = Math.ceil;
|
9827 | var exp = Math.exp;
|
9828 | var hypot = Math.hypot;
|
9829 | var log$1 = Math.log;
|
9830 | var pow$1 = Math.pow;
|
9831 | var sin$1 = Math.sin;
|
9832 | var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
|
9833 | var sqrt$2 = Math.sqrt;
|
9834 | var tan = Math.tan;
|
9835 |
|
9836 | function acos$1(x) {
|
9837 | return x > 1 ? 0 : x < -1 ? pi$1 : Math.acos(x);
|
9838 | }
|
9839 |
|
9840 | function asin$1(x) {
|
9841 | return x > 1 ? halfPi$1 : x < -1 ? -halfPi$1 : Math.asin(x);
|
9842 | }
|
9843 |
|
9844 | function haversin(x) {
|
9845 | return (x = sin$1(x / 2)) * x;
|
9846 | }
|
9847 |
|
9848 | function noop$1() {}
|
9849 |
|
9850 | function streamGeometry(geometry, stream) {
|
9851 | if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
|
9852 | streamGeometryType[geometry.type](geometry, stream);
|
9853 | }
|
9854 | }
|
9855 |
|
9856 | var streamObjectType = {
|
9857 | Feature: function(object, stream) {
|
9858 | streamGeometry(object.geometry, stream);
|
9859 | },
|
9860 | FeatureCollection: function(object, stream) {
|
9861 | var features = object.features, i = -1, n = features.length;
|
9862 | while (++i < n) streamGeometry(features[i].geometry, stream);
|
9863 | }
|
9864 | };
|
9865 |
|
9866 | var streamGeometryType = {
|
9867 | Sphere: function(object, stream) {
|
9868 | stream.sphere();
|
9869 | },
|
9870 | Point: function(object, stream) {
|
9871 | object = object.coordinates;
|
9872 | stream.point(object[0], object[1], object[2]);
|
9873 | },
|
9874 | MultiPoint: function(object, stream) {
|
9875 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
9876 | while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
|
9877 | },
|
9878 | LineString: function(object, stream) {
|
9879 | streamLine(object.coordinates, stream, 0);
|
9880 | },
|
9881 | MultiLineString: function(object, stream) {
|
9882 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
9883 | while (++i < n) streamLine(coordinates[i], stream, 0);
|
9884 | },
|
9885 | Polygon: function(object, stream) {
|
9886 | streamPolygon(object.coordinates, stream);
|
9887 | },
|
9888 | MultiPolygon: function(object, stream) {
|
9889 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
9890 | while (++i < n) streamPolygon(coordinates[i], stream);
|
9891 | },
|
9892 | GeometryCollection: function(object, stream) {
|
9893 | var geometries = object.geometries, i = -1, n = geometries.length;
|
9894 | while (++i < n) streamGeometry(geometries[i], stream);
|
9895 | }
|
9896 | };
|
9897 |
|
9898 | function streamLine(coordinates, stream, closed) {
|
9899 | var i = -1, n = coordinates.length - closed, coordinate;
|
9900 | stream.lineStart();
|
9901 | while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
|
9902 | stream.lineEnd();
|
9903 | }
|
9904 |
|
9905 | function streamPolygon(coordinates, stream) {
|
9906 | var i = -1, n = coordinates.length;
|
9907 | stream.polygonStart();
|
9908 | while (++i < n) streamLine(coordinates[i], stream, 1);
|
9909 | stream.polygonEnd();
|
9910 | }
|
9911 |
|
9912 | function geoStream(object, stream) {
|
9913 | if (object && streamObjectType.hasOwnProperty(object.type)) {
|
9914 | streamObjectType[object.type](object, stream);
|
9915 | } else {
|
9916 | streamGeometry(object, stream);
|
9917 | }
|
9918 | }
|
9919 |
|
9920 | var areaRingSum$1 = new Adder();
|
9921 |
|
9922 | // hello?
|
9923 |
|
9924 | var areaSum$1 = new Adder(),
|
9925 | lambda00$2,
|
9926 | phi00$2,
|
9927 | lambda0$2,
|
9928 | cosPhi0$1,
|
9929 | sinPhi0$1;
|
9930 |
|
9931 | var areaStream$1 = {
|
9932 | point: noop$1,
|
9933 | lineStart: noop$1,
|
9934 | lineEnd: noop$1,
|
9935 | polygonStart: function() {
|
9936 | areaRingSum$1 = new Adder();
|
9937 | areaStream$1.lineStart = areaRingStart$1;
|
9938 | areaStream$1.lineEnd = areaRingEnd$1;
|
9939 | },
|
9940 | polygonEnd: function() {
|
9941 | var areaRing = +areaRingSum$1;
|
9942 | areaSum$1.add(areaRing < 0 ? tau$1 + areaRing : areaRing);
|
9943 | this.lineStart = this.lineEnd = this.point = noop$1;
|
9944 | },
|
9945 | sphere: function() {
|
9946 | areaSum$1.add(tau$1);
|
9947 | }
|
9948 | };
|
9949 |
|
9950 | function areaRingStart$1() {
|
9951 | areaStream$1.point = areaPointFirst$1;
|
9952 | }
|
9953 |
|
9954 | function areaRingEnd$1() {
|
9955 | areaPoint$1(lambda00$2, phi00$2);
|
9956 | }
|
9957 |
|
9958 | function areaPointFirst$1(lambda, phi) {
|
9959 | areaStream$1.point = areaPoint$1;
|
9960 | lambda00$2 = lambda, phi00$2 = phi;
|
9961 | lambda *= radians, phi *= radians;
|
9962 | lambda0$2 = lambda, cosPhi0$1 = cos$1(phi = phi / 2 + quarterPi), sinPhi0$1 = sin$1(phi);
|
9963 | }
|
9964 |
|
9965 | function areaPoint$1(lambda, phi) {
|
9966 | lambda *= radians, phi *= radians;
|
9967 | phi = phi / 2 + quarterPi; // half the angular distance from south pole
|
9968 |
|
9969 | // Spherical excess E for a spherical triangle with vertices: south pole,
|
9970 | // previous point, current point. Uses a formula derived from Cagnoli’s
|
9971 | // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
|
9972 | var dLambda = lambda - lambda0$2,
|
9973 | sdLambda = dLambda >= 0 ? 1 : -1,
|
9974 | adLambda = sdLambda * dLambda,
|
9975 | cosPhi = cos$1(phi),
|
9976 | sinPhi = sin$1(phi),
|
9977 | k = sinPhi0$1 * sinPhi,
|
9978 | u = cosPhi0$1 * cosPhi + k * cos$1(adLambda),
|
9979 | v = k * sdLambda * sin$1(adLambda);
|
9980 | areaRingSum$1.add(atan2$1(v, u));
|
9981 |
|
9982 | // Advance the previous points.
|
9983 | lambda0$2 = lambda, cosPhi0$1 = cosPhi, sinPhi0$1 = sinPhi;
|
9984 | }
|
9985 |
|
9986 | function area$2(object) {
|
9987 | areaSum$1 = new Adder();
|
9988 | geoStream(object, areaStream$1);
|
9989 | return areaSum$1 * 2;
|
9990 | }
|
9991 |
|
9992 | function spherical(cartesian) {
|
9993 | return [atan2$1(cartesian[1], cartesian[0]), asin$1(cartesian[2])];
|
9994 | }
|
9995 |
|
9996 | function cartesian(spherical) {
|
9997 | var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
|
9998 | return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
|
9999 | }
|
10000 |
|
10001 | function cartesianDot(a, b) {
|
10002 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
10003 | }
|
10004 |
|
10005 | function cartesianCross(a, b) {
|
10006 | 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]];
|
10007 | }
|
10008 |
|
10009 | // TODO return a
|
10010 | function cartesianAddInPlace(a, b) {
|
10011 | a[0] += b[0], a[1] += b[1], a[2] += b[2];
|
10012 | }
|
10013 |
|
10014 | function cartesianScale(vector, k) {
|
10015 | return [vector[0] * k, vector[1] * k, vector[2] * k];
|
10016 | }
|
10017 |
|
10018 | // TODO return d
|
10019 | function cartesianNormalizeInPlace(d) {
|
10020 | var l = sqrt$2(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
|
10021 | d[0] /= l, d[1] /= l, d[2] /= l;
|
10022 | }
|
10023 |
|
10024 | var lambda0$1, phi0, lambda1, phi1, // bounds
|
10025 | lambda2, // previous lambda-coordinate
|
10026 | lambda00$1, phi00$1, // first point
|
10027 | p0, // previous 3D point
|
10028 | deltaSum,
|
10029 | ranges,
|
10030 | range;
|
10031 |
|
10032 | var boundsStream$2 = {
|
10033 | point: boundsPoint$1,
|
10034 | lineStart: boundsLineStart,
|
10035 | lineEnd: boundsLineEnd,
|
10036 | polygonStart: function() {
|
10037 | boundsStream$2.point = boundsRingPoint;
|
10038 | boundsStream$2.lineStart = boundsRingStart;
|
10039 | boundsStream$2.lineEnd = boundsRingEnd;
|
10040 | deltaSum = new Adder();
|
10041 | areaStream$1.polygonStart();
|
10042 | },
|
10043 | polygonEnd: function() {
|
10044 | areaStream$1.polygonEnd();
|
10045 | boundsStream$2.point = boundsPoint$1;
|
10046 | boundsStream$2.lineStart = boundsLineStart;
|
10047 | boundsStream$2.lineEnd = boundsLineEnd;
|
10048 | if (areaRingSum$1 < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
|
10049 | else if (deltaSum > epsilon$1) phi1 = 90;
|
10050 | else if (deltaSum < -epsilon$1) phi0 = -90;
|
10051 | range[0] = lambda0$1, range[1] = lambda1;
|
10052 | },
|
10053 | sphere: function() {
|
10054 | lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
|
10055 | }
|
10056 | };
|
10057 |
|
10058 | function boundsPoint$1(lambda, phi) {
|
10059 | ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
|
10060 | if (phi < phi0) phi0 = phi;
|
10061 | if (phi > phi1) phi1 = phi;
|
10062 | }
|
10063 |
|
10064 | function linePoint(lambda, phi) {
|
10065 | var p = cartesian([lambda * radians, phi * radians]);
|
10066 | if (p0) {
|
10067 | var normal = cartesianCross(p0, p),
|
10068 | equatorial = [normal[1], -normal[0], 0],
|
10069 | inflection = cartesianCross(equatorial, normal);
|
10070 | cartesianNormalizeInPlace(inflection);
|
10071 | inflection = spherical(inflection);
|
10072 | var delta = lambda - lambda2,
|
10073 | sign = delta > 0 ? 1 : -1,
|
10074 | lambdai = inflection[0] * degrees * sign,
|
10075 | phii,
|
10076 | antimeridian = abs$1(delta) > 180;
|
10077 | if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
|
10078 | phii = inflection[1] * degrees;
|
10079 | if (phii > phi1) phi1 = phii;
|
10080 | } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
|
10081 | phii = -inflection[1] * degrees;
|
10082 | if (phii < phi0) phi0 = phii;
|
10083 | } else {
|
10084 | if (phi < phi0) phi0 = phi;
|
10085 | if (phi > phi1) phi1 = phi;
|
10086 | }
|
10087 | if (antimeridian) {
|
10088 | if (lambda < lambda2) {
|
10089 | if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
|
10090 | } else {
|
10091 | if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
|
10092 | }
|
10093 | } else {
|
10094 | if (lambda1 >= lambda0$1) {
|
10095 | if (lambda < lambda0$1) lambda0$1 = lambda;
|
10096 | if (lambda > lambda1) lambda1 = lambda;
|
10097 | } else {
|
10098 | if (lambda > lambda2) {
|
10099 | if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
|
10100 | } else {
|
10101 | if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
|
10102 | }
|
10103 | }
|
10104 | }
|
10105 | } else {
|
10106 | ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
|
10107 | }
|
10108 | if (phi < phi0) phi0 = phi;
|
10109 | if (phi > phi1) phi1 = phi;
|
10110 | p0 = p, lambda2 = lambda;
|
10111 | }
|
10112 |
|
10113 | function boundsLineStart() {
|
10114 | boundsStream$2.point = linePoint;
|
10115 | }
|
10116 |
|
10117 | function boundsLineEnd() {
|
10118 | range[0] = lambda0$1, range[1] = lambda1;
|
10119 | boundsStream$2.point = boundsPoint$1;
|
10120 | p0 = null;
|
10121 | }
|
10122 |
|
10123 | function boundsRingPoint(lambda, phi) {
|
10124 | if (p0) {
|
10125 | var delta = lambda - lambda2;
|
10126 | deltaSum.add(abs$1(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
|
10127 | } else {
|
10128 | lambda00$1 = lambda, phi00$1 = phi;
|
10129 | }
|
10130 | areaStream$1.point(lambda, phi);
|
10131 | linePoint(lambda, phi);
|
10132 | }
|
10133 |
|
10134 | function boundsRingStart() {
|
10135 | areaStream$1.lineStart();
|
10136 | }
|
10137 |
|
10138 | function boundsRingEnd() {
|
10139 | boundsRingPoint(lambda00$1, phi00$1);
|
10140 | areaStream$1.lineEnd();
|
10141 | if (abs$1(deltaSum) > epsilon$1) lambda0$1 = -(lambda1 = 180);
|
10142 | range[0] = lambda0$1, range[1] = lambda1;
|
10143 | p0 = null;
|
10144 | }
|
10145 |
|
10146 | // Finds the left-right distance between two longitudes.
|
10147 | // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
|
10148 | // the distance between ±180° to be 360°.
|
10149 | function angle(lambda0, lambda1) {
|
10150 | return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
|
10151 | }
|
10152 |
|
10153 | function rangeCompare(a, b) {
|
10154 | return a[0] - b[0];
|
10155 | }
|
10156 |
|
10157 | function rangeContains(range, x) {
|
10158 | return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
|
10159 | }
|
10160 |
|
10161 | function bounds(feature) {
|
10162 | var i, n, a, b, merged, deltaMax, delta;
|
10163 |
|
10164 | phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
|
10165 | ranges = [];
|
10166 | geoStream(feature, boundsStream$2);
|
10167 |
|
10168 | // First, sort ranges by their minimum longitudes.
|
10169 | if (n = ranges.length) {
|
10170 | ranges.sort(rangeCompare);
|
10171 |
|
10172 | // Then, merge any ranges that overlap.
|
10173 | for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
|
10174 | b = ranges[i];
|
10175 | if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
|
10176 | if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
|
10177 | if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
|
10178 | } else {
|
10179 | merged.push(a = b);
|
10180 | }
|
10181 | }
|
10182 |
|
10183 | // Finally, find the largest gap between the merged ranges.
|
10184 | // The final bounding box will be the inverse of this gap.
|
10185 | for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
|
10186 | b = merged[i];
|
10187 | if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
|
10188 | }
|
10189 | }
|
10190 |
|
10191 | ranges = range = null;
|
10192 |
|
10193 | return lambda0$1 === Infinity || phi0 === Infinity
|
10194 | ? [[NaN, NaN], [NaN, NaN]]
|
10195 | : [[lambda0$1, phi0], [lambda1, phi1]];
|
10196 | }
|
10197 |
|
10198 | var W0, W1,
|
10199 | X0$1, Y0$1, Z0$1,
|
10200 | X1$1, Y1$1, Z1$1,
|
10201 | X2$1, Y2$1, Z2$1,
|
10202 | lambda00, phi00, // first point
|
10203 | x0$4, y0$4, z0; // previous point
|
10204 |
|
10205 | var centroidStream$1 = {
|
10206 | sphere: noop$1,
|
10207 | point: centroidPoint$1,
|
10208 | lineStart: centroidLineStart$1,
|
10209 | lineEnd: centroidLineEnd$1,
|
10210 | polygonStart: function() {
|
10211 | centroidStream$1.lineStart = centroidRingStart$1;
|
10212 | centroidStream$1.lineEnd = centroidRingEnd$1;
|
10213 | },
|
10214 | polygonEnd: function() {
|
10215 | centroidStream$1.lineStart = centroidLineStart$1;
|
10216 | centroidStream$1.lineEnd = centroidLineEnd$1;
|
10217 | }
|
10218 | };
|
10219 |
|
10220 | // Arithmetic mean of Cartesian vectors.
|
10221 | function centroidPoint$1(lambda, phi) {
|
10222 | lambda *= radians, phi *= radians;
|
10223 | var cosPhi = cos$1(phi);
|
10224 | centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
|
10225 | }
|
10226 |
|
10227 | function centroidPointCartesian(x, y, z) {
|
10228 | ++W0;
|
10229 | X0$1 += (x - X0$1) / W0;
|
10230 | Y0$1 += (y - Y0$1) / W0;
|
10231 | Z0$1 += (z - Z0$1) / W0;
|
10232 | }
|
10233 |
|
10234 | function centroidLineStart$1() {
|
10235 | centroidStream$1.point = centroidLinePointFirst;
|
10236 | }
|
10237 |
|
10238 | function centroidLinePointFirst(lambda, phi) {
|
10239 | lambda *= radians, phi *= radians;
|
10240 | var cosPhi = cos$1(phi);
|
10241 | x0$4 = cosPhi * cos$1(lambda);
|
10242 | y0$4 = cosPhi * sin$1(lambda);
|
10243 | z0 = sin$1(phi);
|
10244 | centroidStream$1.point = centroidLinePoint;
|
10245 | centroidPointCartesian(x0$4, y0$4, z0);
|
10246 | }
|
10247 |
|
10248 | function centroidLinePoint(lambda, phi) {
|
10249 | lambda *= radians, phi *= radians;
|
10250 | var cosPhi = cos$1(phi),
|
10251 | x = cosPhi * cos$1(lambda),
|
10252 | y = cosPhi * sin$1(lambda),
|
10253 | z = sin$1(phi),
|
10254 | 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);
|
10255 | W1 += w;
|
10256 | X1$1 += w * (x0$4 + (x0$4 = x));
|
10257 | Y1$1 += w * (y0$4 + (y0$4 = y));
|
10258 | Z1$1 += w * (z0 + (z0 = z));
|
10259 | centroidPointCartesian(x0$4, y0$4, z0);
|
10260 | }
|
10261 |
|
10262 | function centroidLineEnd$1() {
|
10263 | centroidStream$1.point = centroidPoint$1;
|
10264 | }
|
10265 |
|
10266 | // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
|
10267 | // J. Applied Mechanics 42, 239 (1975).
|
10268 | function centroidRingStart$1() {
|
10269 | centroidStream$1.point = centroidRingPointFirst;
|
10270 | }
|
10271 |
|
10272 | function centroidRingEnd$1() {
|
10273 | centroidRingPoint(lambda00, phi00);
|
10274 | centroidStream$1.point = centroidPoint$1;
|
10275 | }
|
10276 |
|
10277 | function centroidRingPointFirst(lambda, phi) {
|
10278 | lambda00 = lambda, phi00 = phi;
|
10279 | lambda *= radians, phi *= radians;
|
10280 | centroidStream$1.point = centroidRingPoint;
|
10281 | var cosPhi = cos$1(phi);
|
10282 | x0$4 = cosPhi * cos$1(lambda);
|
10283 | y0$4 = cosPhi * sin$1(lambda);
|
10284 | z0 = sin$1(phi);
|
10285 | centroidPointCartesian(x0$4, y0$4, z0);
|
10286 | }
|
10287 |
|
10288 | function centroidRingPoint(lambda, phi) {
|
10289 | lambda *= radians, phi *= radians;
|
10290 | var cosPhi = cos$1(phi),
|
10291 | x = cosPhi * cos$1(lambda),
|
10292 | y = cosPhi * sin$1(lambda),
|
10293 | z = sin$1(phi),
|
10294 | cx = y0$4 * z - z0 * y,
|
10295 | cy = z0 * x - x0$4 * z,
|
10296 | cz = x0$4 * y - y0$4 * x,
|
10297 | m = hypot(cx, cy, cz),
|
10298 | w = asin$1(m), // line weight = angle
|
10299 | v = m && -w / m; // area weight multiplier
|
10300 | X2$1.add(v * cx);
|
10301 | Y2$1.add(v * cy);
|
10302 | Z2$1.add(v * cz);
|
10303 | W1 += w;
|
10304 | X1$1 += w * (x0$4 + (x0$4 = x));
|
10305 | Y1$1 += w * (y0$4 + (y0$4 = y));
|
10306 | Z1$1 += w * (z0 + (z0 = z));
|
10307 | centroidPointCartesian(x0$4, y0$4, z0);
|
10308 | }
|
10309 |
|
10310 | function centroid$1(object) {
|
10311 | W0 = W1 =
|
10312 | X0$1 = Y0$1 = Z0$1 =
|
10313 | X1$1 = Y1$1 = Z1$1 = 0;
|
10314 | X2$1 = new Adder();
|
10315 | Y2$1 = new Adder();
|
10316 | Z2$1 = new Adder();
|
10317 | geoStream(object, centroidStream$1);
|
10318 |
|
10319 | var x = +X2$1,
|
10320 | y = +Y2$1,
|
10321 | z = +Z2$1,
|
10322 | m = hypot(x, y, z);
|
10323 |
|
10324 | // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
|
10325 | if (m < epsilon2) {
|
10326 | x = X1$1, y = Y1$1, z = Z1$1;
|
10327 | // If the feature has zero length, fall back to arithmetic mean of point vectors.
|
10328 | if (W1 < epsilon$1) x = X0$1, y = Y0$1, z = Z0$1;
|
10329 | m = hypot(x, y, z);
|
10330 | // If the feature still has an undefined ccentroid, then return.
|
10331 | if (m < epsilon2) return [NaN, NaN];
|
10332 | }
|
10333 |
|
10334 | return [atan2$1(y, x) * degrees, asin$1(z / m) * degrees];
|
10335 | }
|
10336 |
|
10337 | function constant$3(x) {
|
10338 | return function() {
|
10339 | return x;
|
10340 | };
|
10341 | }
|
10342 |
|
10343 | function compose(a, b) {
|
10344 |
|
10345 | function compose(x, y) {
|
10346 | return x = a(x, y), b(x[0], x[1]);
|
10347 | }
|
10348 |
|
10349 | if (a.invert && b.invert) compose.invert = function(x, y) {
|
10350 | return x = b.invert(x, y), x && a.invert(x[0], x[1]);
|
10351 | };
|
10352 |
|
10353 | return compose;
|
10354 | }
|
10355 |
|
10356 | function rotationIdentity(lambda, phi) {
|
10357 | if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1;
|
10358 | return [lambda, phi];
|
10359 | }
|
10360 |
|
10361 | rotationIdentity.invert = rotationIdentity;
|
10362 |
|
10363 | function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
|
10364 | return (deltaLambda %= tau$1) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
|
10365 | : rotationLambda(deltaLambda))
|
10366 | : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
|
10367 | : rotationIdentity);
|
10368 | }
|
10369 |
|
10370 | function forwardRotationLambda(deltaLambda) {
|
10371 | return function(lambda, phi) {
|
10372 | lambda += deltaLambda;
|
10373 | if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1;
|
10374 | return [lambda, phi];
|
10375 | };
|
10376 | }
|
10377 |
|
10378 | function rotationLambda(deltaLambda) {
|
10379 | var rotation = forwardRotationLambda(deltaLambda);
|
10380 | rotation.invert = forwardRotationLambda(-deltaLambda);
|
10381 | return rotation;
|
10382 | }
|
10383 |
|
10384 | function rotationPhiGamma(deltaPhi, deltaGamma) {
|
10385 | var cosDeltaPhi = cos$1(deltaPhi),
|
10386 | sinDeltaPhi = sin$1(deltaPhi),
|
10387 | cosDeltaGamma = cos$1(deltaGamma),
|
10388 | sinDeltaGamma = sin$1(deltaGamma);
|
10389 |
|
10390 | function rotation(lambda, phi) {
|
10391 | var cosPhi = cos$1(phi),
|
10392 | x = cos$1(lambda) * cosPhi,
|
10393 | y = sin$1(lambda) * cosPhi,
|
10394 | z = sin$1(phi),
|
10395 | k = z * cosDeltaPhi + x * sinDeltaPhi;
|
10396 | return [
|
10397 | atan2$1(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
|
10398 | asin$1(k * cosDeltaGamma + y * sinDeltaGamma)
|
10399 | ];
|
10400 | }
|
10401 |
|
10402 | rotation.invert = function(lambda, phi) {
|
10403 | var cosPhi = cos$1(phi),
|
10404 | x = cos$1(lambda) * cosPhi,
|
10405 | y = sin$1(lambda) * cosPhi,
|
10406 | z = sin$1(phi),
|
10407 | k = z * cosDeltaGamma - y * sinDeltaGamma;
|
10408 | return [
|
10409 | atan2$1(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
|
10410 | asin$1(k * cosDeltaPhi - x * sinDeltaPhi)
|
10411 | ];
|
10412 | };
|
10413 |
|
10414 | return rotation;
|
10415 | }
|
10416 |
|
10417 | function rotation(rotate) {
|
10418 | rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
|
10419 |
|
10420 | function forward(coordinates) {
|
10421 | coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
|
10422 | return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
|
10423 | }
|
10424 |
|
10425 | forward.invert = function(coordinates) {
|
10426 | coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
|
10427 | return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
|
10428 | };
|
10429 |
|
10430 | return forward;
|
10431 | }
|
10432 |
|
10433 | // Generates a circle centered at [0°, 0°], with a given radius and precision.
|
10434 | function circleStream(stream, radius, delta, direction, t0, t1) {
|
10435 | if (!delta) return;
|
10436 | var cosRadius = cos$1(radius),
|
10437 | sinRadius = sin$1(radius),
|
10438 | step = direction * delta;
|
10439 | if (t0 == null) {
|
10440 | t0 = radius + direction * tau$1;
|
10441 | t1 = radius - step / 2;
|
10442 | } else {
|
10443 | t0 = circleRadius(cosRadius, t0);
|
10444 | t1 = circleRadius(cosRadius, t1);
|
10445 | if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$1;
|
10446 | }
|
10447 | for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
|
10448 | point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
|
10449 | stream.point(point[0], point[1]);
|
10450 | }
|
10451 | }
|
10452 |
|
10453 | // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
|
10454 | function circleRadius(cosRadius, point) {
|
10455 | point = cartesian(point), point[0] -= cosRadius;
|
10456 | cartesianNormalizeInPlace(point);
|
10457 | var radius = acos$1(-point[1]);
|
10458 | return ((-point[2] < 0 ? -radius : radius) + tau$1 - epsilon$1) % tau$1;
|
10459 | }
|
10460 |
|
10461 | function circle$1() {
|
10462 | var center = constant$3([0, 0]),
|
10463 | radius = constant$3(90),
|
10464 | precision = constant$3(6),
|
10465 | ring,
|
10466 | rotate,
|
10467 | stream = {point: point};
|
10468 |
|
10469 | function point(x, y) {
|
10470 | ring.push(x = rotate(x, y));
|
10471 | x[0] *= degrees, x[1] *= degrees;
|
10472 | }
|
10473 |
|
10474 | function circle() {
|
10475 | var c = center.apply(this, arguments),
|
10476 | r = radius.apply(this, arguments) * radians,
|
10477 | p = precision.apply(this, arguments) * radians;
|
10478 | ring = [];
|
10479 | rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
|
10480 | circleStream(stream, r, p, 1);
|
10481 | c = {type: "Polygon", coordinates: [ring]};
|
10482 | ring = rotate = null;
|
10483 | return c;
|
10484 | }
|
10485 |
|
10486 | circle.center = function(_) {
|
10487 | return arguments.length ? (center = typeof _ === "function" ? _ : constant$3([+_[0], +_[1]]), circle) : center;
|
10488 | };
|
10489 |
|
10490 | circle.radius = function(_) {
|
10491 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$3(+_), circle) : radius;
|
10492 | };
|
10493 |
|
10494 | circle.precision = function(_) {
|
10495 | return arguments.length ? (precision = typeof _ === "function" ? _ : constant$3(+_), circle) : precision;
|
10496 | };
|
10497 |
|
10498 | return circle;
|
10499 | }
|
10500 |
|
10501 | function clipBuffer() {
|
10502 | var lines = [],
|
10503 | line;
|
10504 | return {
|
10505 | point: function(x, y, m) {
|
10506 | line.push([x, y, m]);
|
10507 | },
|
10508 | lineStart: function() {
|
10509 | lines.push(line = []);
|
10510 | },
|
10511 | lineEnd: noop$1,
|
10512 | rejoin: function() {
|
10513 | if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
|
10514 | },
|
10515 | result: function() {
|
10516 | var result = lines;
|
10517 | lines = [];
|
10518 | line = null;
|
10519 | return result;
|
10520 | }
|
10521 | };
|
10522 | }
|
10523 |
|
10524 | function pointEqual(a, b) {
|
10525 | return abs$1(a[0] - b[0]) < epsilon$1 && abs$1(a[1] - b[1]) < epsilon$1;
|
10526 | }
|
10527 |
|
10528 | function Intersection(point, points, other, entry) {
|
10529 | this.x = point;
|
10530 | this.z = points;
|
10531 | this.o = other; // another intersection
|
10532 | this.e = entry; // is an entry?
|
10533 | this.v = false; // visited
|
10534 | this.n = this.p = null; // next & previous
|
10535 | }
|
10536 |
|
10537 | // A generalized polygon clipping algorithm: given a polygon that has been cut
|
10538 | // into its visible line segments, and rejoins the segments by interpolating
|
10539 | // along the clip edge.
|
10540 | function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
|
10541 | var subject = [],
|
10542 | clip = [],
|
10543 | i,
|
10544 | n;
|
10545 |
|
10546 | segments.forEach(function(segment) {
|
10547 | if ((n = segment.length - 1) <= 0) return;
|
10548 | var n, p0 = segment[0], p1 = segment[n], x;
|
10549 |
|
10550 | if (pointEqual(p0, p1)) {
|
10551 | if (!p0[2] && !p1[2]) {
|
10552 | stream.lineStart();
|
10553 | for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
|
10554 | stream.lineEnd();
|
10555 | return;
|
10556 | }
|
10557 | // handle degenerate cases by moving the point
|
10558 | p1[0] += 2 * epsilon$1;
|
10559 | }
|
10560 |
|
10561 | subject.push(x = new Intersection(p0, segment, null, true));
|
10562 | clip.push(x.o = new Intersection(p0, null, x, false));
|
10563 | subject.push(x = new Intersection(p1, segment, null, false));
|
10564 | clip.push(x.o = new Intersection(p1, null, x, true));
|
10565 | });
|
10566 |
|
10567 | if (!subject.length) return;
|
10568 |
|
10569 | clip.sort(compareIntersection);
|
10570 | link$1(subject);
|
10571 | link$1(clip);
|
10572 |
|
10573 | for (i = 0, n = clip.length; i < n; ++i) {
|
10574 | clip[i].e = startInside = !startInside;
|
10575 | }
|
10576 |
|
10577 | var start = subject[0],
|
10578 | points,
|
10579 | point;
|
10580 |
|
10581 | while (1) {
|
10582 | // Find first unvisited intersection.
|
10583 | var current = start,
|
10584 | isSubject = true;
|
10585 | while (current.v) if ((current = current.n) === start) return;
|
10586 | points = current.z;
|
10587 | stream.lineStart();
|
10588 | do {
|
10589 | current.v = current.o.v = true;
|
10590 | if (current.e) {
|
10591 | if (isSubject) {
|
10592 | for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
|
10593 | } else {
|
10594 | interpolate(current.x, current.n.x, 1, stream);
|
10595 | }
|
10596 | current = current.n;
|
10597 | } else {
|
10598 | if (isSubject) {
|
10599 | points = current.p.z;
|
10600 | for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
|
10601 | } else {
|
10602 | interpolate(current.x, current.p.x, -1, stream);
|
10603 | }
|
10604 | current = current.p;
|
10605 | }
|
10606 | current = current.o;
|
10607 | points = current.z;
|
10608 | isSubject = !isSubject;
|
10609 | } while (!current.v);
|
10610 | stream.lineEnd();
|
10611 | }
|
10612 | }
|
10613 |
|
10614 | function link$1(array) {
|
10615 | if (!(n = array.length)) return;
|
10616 | var n,
|
10617 | i = 0,
|
10618 | a = array[0],
|
10619 | b;
|
10620 | while (++i < n) {
|
10621 | a.n = b = array[i];
|
10622 | b.p = a;
|
10623 | a = b;
|
10624 | }
|
10625 | a.n = b = array[0];
|
10626 | b.p = a;
|
10627 | }
|
10628 |
|
10629 | function longitude(point) {
|
10630 | return abs$1(point[0]) <= pi$1 ? point[0] : sign$1(point[0]) * ((abs$1(point[0]) + pi$1) % tau$1 - pi$1);
|
10631 | }
|
10632 |
|
10633 | function polygonContains(polygon, point) {
|
10634 | var lambda = longitude(point),
|
10635 | phi = point[1],
|
10636 | sinPhi = sin$1(phi),
|
10637 | normal = [sin$1(lambda), -cos$1(lambda), 0],
|
10638 | angle = 0,
|
10639 | winding = 0;
|
10640 |
|
10641 | var sum = new Adder();
|
10642 |
|
10643 | if (sinPhi === 1) phi = halfPi$1 + epsilon$1;
|
10644 | else if (sinPhi === -1) phi = -halfPi$1 - epsilon$1;
|
10645 |
|
10646 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
10647 | if (!(m = (ring = polygon[i]).length)) continue;
|
10648 | var ring,
|
10649 | m,
|
10650 | point0 = ring[m - 1],
|
10651 | lambda0 = longitude(point0),
|
10652 | phi0 = point0[1] / 2 + quarterPi,
|
10653 | sinPhi0 = sin$1(phi0),
|
10654 | cosPhi0 = cos$1(phi0);
|
10655 |
|
10656 | for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
|
10657 | var point1 = ring[j],
|
10658 | lambda1 = longitude(point1),
|
10659 | phi1 = point1[1] / 2 + quarterPi,
|
10660 | sinPhi1 = sin$1(phi1),
|
10661 | cosPhi1 = cos$1(phi1),
|
10662 | delta = lambda1 - lambda0,
|
10663 | sign = delta >= 0 ? 1 : -1,
|
10664 | absDelta = sign * delta,
|
10665 | antimeridian = absDelta > pi$1,
|
10666 | k = sinPhi0 * sinPhi1;
|
10667 |
|
10668 | sum.add(atan2$1(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
|
10669 | angle += antimeridian ? delta + sign * tau$1 : delta;
|
10670 |
|
10671 | // Are the longitudes either side of the point’s meridian (lambda),
|
10672 | // and are the latitudes smaller than the parallel (phi)?
|
10673 | if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
|
10674 | var arc = cartesianCross(cartesian(point0), cartesian(point1));
|
10675 | cartesianNormalizeInPlace(arc);
|
10676 | var intersection = cartesianCross(normal, arc);
|
10677 | cartesianNormalizeInPlace(intersection);
|
10678 | var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]);
|
10679 | if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
|
10680 | winding += antimeridian ^ delta >= 0 ? 1 : -1;
|
10681 | }
|
10682 | }
|
10683 | }
|
10684 | }
|
10685 |
|
10686 | // First, determine whether the South pole is inside or outside:
|
10687 | //
|
10688 | // It is inside if:
|
10689 | // * the polygon winds around it in a clockwise direction.
|
10690 | // * the polygon does not (cumulatively) wind around it, but has a negative
|
10691 | // (counter-clockwise) area.
|
10692 | //
|
10693 | // Second, count the (signed) number of times a segment crosses a lambda
|
10694 | // from the point to the South pole. If it is zero, then the point is the
|
10695 | // same side as the South pole.
|
10696 |
|
10697 | return (angle < -epsilon$1 || angle < epsilon$1 && sum < -epsilon2) ^ (winding & 1);
|
10698 | }
|
10699 |
|
10700 | function clip(pointVisible, clipLine, interpolate, start) {
|
10701 | return function(sink) {
|
10702 | var line = clipLine(sink),
|
10703 | ringBuffer = clipBuffer(),
|
10704 | ringSink = clipLine(ringBuffer),
|
10705 | polygonStarted = false,
|
10706 | polygon,
|
10707 | segments,
|
10708 | ring;
|
10709 |
|
10710 | var clip = {
|
10711 | point: point,
|
10712 | lineStart: lineStart,
|
10713 | lineEnd: lineEnd,
|
10714 | polygonStart: function() {
|
10715 | clip.point = pointRing;
|
10716 | clip.lineStart = ringStart;
|
10717 | clip.lineEnd = ringEnd;
|
10718 | segments = [];
|
10719 | polygon = [];
|
10720 | },
|
10721 | polygonEnd: function() {
|
10722 | clip.point = point;
|
10723 | clip.lineStart = lineStart;
|
10724 | clip.lineEnd = lineEnd;
|
10725 | segments = merge(segments);
|
10726 | var startInside = polygonContains(polygon, start);
|
10727 | if (segments.length) {
|
10728 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
10729 | clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
|
10730 | } else if (startInside) {
|
10731 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
10732 | sink.lineStart();
|
10733 | interpolate(null, null, 1, sink);
|
10734 | sink.lineEnd();
|
10735 | }
|
10736 | if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
|
10737 | segments = polygon = null;
|
10738 | },
|
10739 | sphere: function() {
|
10740 | sink.polygonStart();
|
10741 | sink.lineStart();
|
10742 | interpolate(null, null, 1, sink);
|
10743 | sink.lineEnd();
|
10744 | sink.polygonEnd();
|
10745 | }
|
10746 | };
|
10747 |
|
10748 | function point(lambda, phi) {
|
10749 | if (pointVisible(lambda, phi)) sink.point(lambda, phi);
|
10750 | }
|
10751 |
|
10752 | function pointLine(lambda, phi) {
|
10753 | line.point(lambda, phi);
|
10754 | }
|
10755 |
|
10756 | function lineStart() {
|
10757 | clip.point = pointLine;
|
10758 | line.lineStart();
|
10759 | }
|
10760 |
|
10761 | function lineEnd() {
|
10762 | clip.point = point;
|
10763 | line.lineEnd();
|
10764 | }
|
10765 |
|
10766 | function pointRing(lambda, phi) {
|
10767 | ring.push([lambda, phi]);
|
10768 | ringSink.point(lambda, phi);
|
10769 | }
|
10770 |
|
10771 | function ringStart() {
|
10772 | ringSink.lineStart();
|
10773 | ring = [];
|
10774 | }
|
10775 |
|
10776 | function ringEnd() {
|
10777 | pointRing(ring[0][0], ring[0][1]);
|
10778 | ringSink.lineEnd();
|
10779 |
|
10780 | var clean = ringSink.clean(),
|
10781 | ringSegments = ringBuffer.result(),
|
10782 | i, n = ringSegments.length, m,
|
10783 | segment,
|
10784 | point;
|
10785 |
|
10786 | ring.pop();
|
10787 | polygon.push(ring);
|
10788 | ring = null;
|
10789 |
|
10790 | if (!n) return;
|
10791 |
|
10792 | // No intersections.
|
10793 | if (clean & 1) {
|
10794 | segment = ringSegments[0];
|
10795 | if ((m = segment.length - 1) > 0) {
|
10796 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
10797 | sink.lineStart();
|
10798 | for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
|
10799 | sink.lineEnd();
|
10800 | }
|
10801 | return;
|
10802 | }
|
10803 |
|
10804 | // Rejoin connected segments.
|
10805 | // TODO reuse ringBuffer.rejoin()?
|
10806 | if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
|
10807 |
|
10808 | segments.push(ringSegments.filter(validSegment));
|
10809 | }
|
10810 |
|
10811 | return clip;
|
10812 | };
|
10813 | }
|
10814 |
|
10815 | function validSegment(segment) {
|
10816 | return segment.length > 1;
|
10817 | }
|
10818 |
|
10819 | // Intersections are sorted along the clip edge. For both antimeridian cutting
|
10820 | // and circle clipping, the same comparison is used.
|
10821 | function compareIntersection(a, b) {
|
10822 | return ((a = a.x)[0] < 0 ? a[1] - halfPi$1 - epsilon$1 : halfPi$1 - a[1])
|
10823 | - ((b = b.x)[0] < 0 ? b[1] - halfPi$1 - epsilon$1 : halfPi$1 - b[1]);
|
10824 | }
|
10825 |
|
10826 | var clipAntimeridian = clip(
|
10827 | function() { return true; },
|
10828 | clipAntimeridianLine,
|
10829 | clipAntimeridianInterpolate,
|
10830 | [-pi$1, -halfPi$1]
|
10831 | );
|
10832 |
|
10833 | // Takes a line and cuts into visible segments. Return values: 0 - there were
|
10834 | // intersections or the line was empty; 1 - no intersections; 2 - there were
|
10835 | // intersections, and the first and last segments should be rejoined.
|
10836 | function clipAntimeridianLine(stream) {
|
10837 | var lambda0 = NaN,
|
10838 | phi0 = NaN,
|
10839 | sign0 = NaN,
|
10840 | clean; // no intersections
|
10841 |
|
10842 | return {
|
10843 | lineStart: function() {
|
10844 | stream.lineStart();
|
10845 | clean = 1;
|
10846 | },
|
10847 | point: function(lambda1, phi1) {
|
10848 | var sign1 = lambda1 > 0 ? pi$1 : -pi$1,
|
10849 | delta = abs$1(lambda1 - lambda0);
|
10850 | if (abs$1(delta - pi$1) < epsilon$1) { // line crosses a pole
|
10851 | stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$1 : -halfPi$1);
|
10852 | stream.point(sign0, phi0);
|
10853 | stream.lineEnd();
|
10854 | stream.lineStart();
|
10855 | stream.point(sign1, phi0);
|
10856 | stream.point(lambda1, phi0);
|
10857 | clean = 0;
|
10858 | } else if (sign0 !== sign1 && delta >= pi$1) { // line crosses antimeridian
|
10859 | if (abs$1(lambda0 - sign0) < epsilon$1) lambda0 -= sign0 * epsilon$1; // handle degeneracies
|
10860 | if (abs$1(lambda1 - sign1) < epsilon$1) lambda1 -= sign1 * epsilon$1;
|
10861 | phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
|
10862 | stream.point(sign0, phi0);
|
10863 | stream.lineEnd();
|
10864 | stream.lineStart();
|
10865 | stream.point(sign1, phi0);
|
10866 | clean = 0;
|
10867 | }
|
10868 | stream.point(lambda0 = lambda1, phi0 = phi1);
|
10869 | sign0 = sign1;
|
10870 | },
|
10871 | lineEnd: function() {
|
10872 | stream.lineEnd();
|
10873 | lambda0 = phi0 = NaN;
|
10874 | },
|
10875 | clean: function() {
|
10876 | return 2 - clean; // if intersections, rejoin first and last segments
|
10877 | }
|
10878 | };
|
10879 | }
|
10880 |
|
10881 | function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
|
10882 | var cosPhi0,
|
10883 | cosPhi1,
|
10884 | sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
|
10885 | return abs$1(sinLambda0Lambda1) > epsilon$1
|
10886 | ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
|
10887 | - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
|
10888 | / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
|
10889 | : (phi0 + phi1) / 2;
|
10890 | }
|
10891 |
|
10892 | function clipAntimeridianInterpolate(from, to, direction, stream) {
|
10893 | var phi;
|
10894 | if (from == null) {
|
10895 | phi = direction * halfPi$1;
|
10896 | stream.point(-pi$1, phi);
|
10897 | stream.point(0, phi);
|
10898 | stream.point(pi$1, phi);
|
10899 | stream.point(pi$1, 0);
|
10900 | stream.point(pi$1, -phi);
|
10901 | stream.point(0, -phi);
|
10902 | stream.point(-pi$1, -phi);
|
10903 | stream.point(-pi$1, 0);
|
10904 | stream.point(-pi$1, phi);
|
10905 | } else if (abs$1(from[0] - to[0]) > epsilon$1) {
|
10906 | var lambda = from[0] < to[0] ? pi$1 : -pi$1;
|
10907 | phi = direction * lambda / 2;
|
10908 | stream.point(-lambda, phi);
|
10909 | stream.point(0, phi);
|
10910 | stream.point(lambda, phi);
|
10911 | } else {
|
10912 | stream.point(to[0], to[1]);
|
10913 | }
|
10914 | }
|
10915 |
|
10916 | function clipCircle(radius) {
|
10917 | var cr = cos$1(radius),
|
10918 | delta = 6 * radians,
|
10919 | smallRadius = cr > 0,
|
10920 | notHemisphere = abs$1(cr) > epsilon$1; // TODO optimise for this common case
|
10921 |
|
10922 | function interpolate(from, to, direction, stream) {
|
10923 | circleStream(stream, radius, delta, direction, from, to);
|
10924 | }
|
10925 |
|
10926 | function visible(lambda, phi) {
|
10927 | return cos$1(lambda) * cos$1(phi) > cr;
|
10928 | }
|
10929 |
|
10930 | // Takes a line and cuts into visible segments. Return values used for polygon
|
10931 | // clipping: 0 - there were intersections or the line was empty; 1 - no
|
10932 | // intersections 2 - there were intersections, and the first and last segments
|
10933 | // should be rejoined.
|
10934 | function clipLine(stream) {
|
10935 | var point0, // previous point
|
10936 | c0, // code for previous point
|
10937 | v0, // visibility of previous point
|
10938 | v00, // visibility of first point
|
10939 | clean; // no intersections
|
10940 | return {
|
10941 | lineStart: function() {
|
10942 | v00 = v0 = false;
|
10943 | clean = 1;
|
10944 | },
|
10945 | point: function(lambda, phi) {
|
10946 | var point1 = [lambda, phi],
|
10947 | point2,
|
10948 | v = visible(lambda, phi),
|
10949 | c = smallRadius
|
10950 | ? v ? 0 : code(lambda, phi)
|
10951 | : v ? code(lambda + (lambda < 0 ? pi$1 : -pi$1), phi) : 0;
|
10952 | if (!point0 && (v00 = v0 = v)) stream.lineStart();
|
10953 | if (v !== v0) {
|
10954 | point2 = intersect(point0, point1);
|
10955 | if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2))
|
10956 | point1[2] = 1;
|
10957 | }
|
10958 | if (v !== v0) {
|
10959 | clean = 0;
|
10960 | if (v) {
|
10961 | // outside going in
|
10962 | stream.lineStart();
|
10963 | point2 = intersect(point1, point0);
|
10964 | stream.point(point2[0], point2[1]);
|
10965 | } else {
|
10966 | // inside going out
|
10967 | point2 = intersect(point0, point1);
|
10968 | stream.point(point2[0], point2[1], 2);
|
10969 | stream.lineEnd();
|
10970 | }
|
10971 | point0 = point2;
|
10972 | } else if (notHemisphere && point0 && smallRadius ^ v) {
|
10973 | var t;
|
10974 | // If the codes for two points are different, or are both zero,
|
10975 | // and there this segment intersects with the small circle.
|
10976 | if (!(c & c0) && (t = intersect(point1, point0, true))) {
|
10977 | clean = 0;
|
10978 | if (smallRadius) {
|
10979 | stream.lineStart();
|
10980 | stream.point(t[0][0], t[0][1]);
|
10981 | stream.point(t[1][0], t[1][1]);
|
10982 | stream.lineEnd();
|
10983 | } else {
|
10984 | stream.point(t[1][0], t[1][1]);
|
10985 | stream.lineEnd();
|
10986 | stream.lineStart();
|
10987 | stream.point(t[0][0], t[0][1], 3);
|
10988 | }
|
10989 | }
|
10990 | }
|
10991 | if (v && (!point0 || !pointEqual(point0, point1))) {
|
10992 | stream.point(point1[0], point1[1]);
|
10993 | }
|
10994 | point0 = point1, v0 = v, c0 = c;
|
10995 | },
|
10996 | lineEnd: function() {
|
10997 | if (v0) stream.lineEnd();
|
10998 | point0 = null;
|
10999 | },
|
11000 | // Rejoin first and last segments if there were intersections and the first
|
11001 | // and last points were visible.
|
11002 | clean: function() {
|
11003 | return clean | ((v00 && v0) << 1);
|
11004 | }
|
11005 | };
|
11006 | }
|
11007 |
|
11008 | // Intersects the great circle between a and b with the clip circle.
|
11009 | function intersect(a, b, two) {
|
11010 | var pa = cartesian(a),
|
11011 | pb = cartesian(b);
|
11012 |
|
11013 | // We have two planes, n1.p = d1 and n2.p = d2.
|
11014 | // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
|
11015 | var n1 = [1, 0, 0], // normal
|
11016 | n2 = cartesianCross(pa, pb),
|
11017 | n2n2 = cartesianDot(n2, n2),
|
11018 | n1n2 = n2[0], // cartesianDot(n1, n2),
|
11019 | determinant = n2n2 - n1n2 * n1n2;
|
11020 |
|
11021 | // Two polar points.
|
11022 | if (!determinant) return !two && a;
|
11023 |
|
11024 | var c1 = cr * n2n2 / determinant,
|
11025 | c2 = -cr * n1n2 / determinant,
|
11026 | n1xn2 = cartesianCross(n1, n2),
|
11027 | A = cartesianScale(n1, c1),
|
11028 | B = cartesianScale(n2, c2);
|
11029 | cartesianAddInPlace(A, B);
|
11030 |
|
11031 | // Solve |p(t)|^2 = 1.
|
11032 | var u = n1xn2,
|
11033 | w = cartesianDot(A, u),
|
11034 | uu = cartesianDot(u, u),
|
11035 | t2 = w * w - uu * (cartesianDot(A, A) - 1);
|
11036 |
|
11037 | if (t2 < 0) return;
|
11038 |
|
11039 | var t = sqrt$2(t2),
|
11040 | q = cartesianScale(u, (-w - t) / uu);
|
11041 | cartesianAddInPlace(q, A);
|
11042 | q = spherical(q);
|
11043 |
|
11044 | if (!two) return q;
|
11045 |
|
11046 | // Two intersection points.
|
11047 | var lambda0 = a[0],
|
11048 | lambda1 = b[0],
|
11049 | phi0 = a[1],
|
11050 | phi1 = b[1],
|
11051 | z;
|
11052 |
|
11053 | if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
|
11054 |
|
11055 | var delta = lambda1 - lambda0,
|
11056 | polar = abs$1(delta - pi$1) < epsilon$1,
|
11057 | meridian = polar || delta < epsilon$1;
|
11058 |
|
11059 | if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
|
11060 |
|
11061 | // Check that the first point is between a and b.
|
11062 | if (meridian
|
11063 | ? polar
|
11064 | ? phi0 + phi1 > 0 ^ q[1] < (abs$1(q[0] - lambda0) < epsilon$1 ? phi0 : phi1)
|
11065 | : phi0 <= q[1] && q[1] <= phi1
|
11066 | : delta > pi$1 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
|
11067 | var q1 = cartesianScale(u, (-w + t) / uu);
|
11068 | cartesianAddInPlace(q1, A);
|
11069 | return [q, spherical(q1)];
|
11070 | }
|
11071 | }
|
11072 |
|
11073 | // Generates a 4-bit vector representing the location of a point relative to
|
11074 | // the small circle's bounding box.
|
11075 | function code(lambda, phi) {
|
11076 | var r = smallRadius ? radius : pi$1 - radius,
|
11077 | code = 0;
|
11078 | if (lambda < -r) code |= 1; // left
|
11079 | else if (lambda > r) code |= 2; // right
|
11080 | if (phi < -r) code |= 4; // below
|
11081 | else if (phi > r) code |= 8; // above
|
11082 | return code;
|
11083 | }
|
11084 |
|
11085 | return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$1, radius - pi$1]);
|
11086 | }
|
11087 |
|
11088 | function clipLine(a, b, x0, y0, x1, y1) {
|
11089 | var ax = a[0],
|
11090 | ay = a[1],
|
11091 | bx = b[0],
|
11092 | by = b[1],
|
11093 | t0 = 0,
|
11094 | t1 = 1,
|
11095 | dx = bx - ax,
|
11096 | dy = by - ay,
|
11097 | r;
|
11098 |
|
11099 | r = x0 - ax;
|
11100 | if (!dx && r > 0) return;
|
11101 | r /= dx;
|
11102 | if (dx < 0) {
|
11103 | if (r < t0) return;
|
11104 | if (r < t1) t1 = r;
|
11105 | } else if (dx > 0) {
|
11106 | if (r > t1) return;
|
11107 | if (r > t0) t0 = r;
|
11108 | }
|
11109 |
|
11110 | r = x1 - ax;
|
11111 | if (!dx && r < 0) return;
|
11112 | r /= dx;
|
11113 | if (dx < 0) {
|
11114 | if (r > t1) return;
|
11115 | if (r > t0) t0 = r;
|
11116 | } else if (dx > 0) {
|
11117 | if (r < t0) return;
|
11118 | if (r < t1) t1 = r;
|
11119 | }
|
11120 |
|
11121 | r = y0 - ay;
|
11122 | if (!dy && r > 0) return;
|
11123 | r /= dy;
|
11124 | if (dy < 0) {
|
11125 | if (r < t0) return;
|
11126 | if (r < t1) t1 = r;
|
11127 | } else if (dy > 0) {
|
11128 | if (r > t1) return;
|
11129 | if (r > t0) t0 = r;
|
11130 | }
|
11131 |
|
11132 | r = y1 - ay;
|
11133 | if (!dy && r < 0) return;
|
11134 | r /= dy;
|
11135 | if (dy < 0) {
|
11136 | if (r > t1) return;
|
11137 | if (r > t0) t0 = r;
|
11138 | } else if (dy > 0) {
|
11139 | if (r < t0) return;
|
11140 | if (r < t1) t1 = r;
|
11141 | }
|
11142 |
|
11143 | if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
|
11144 | if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
|
11145 | return true;
|
11146 | }
|
11147 |
|
11148 | var clipMax = 1e9, clipMin = -clipMax;
|
11149 |
|
11150 | // TODO Use d3-polygon’s polygonContains here for the ring check?
|
11151 | // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
|
11152 |
|
11153 | function clipRectangle(x0, y0, x1, y1) {
|
11154 |
|
11155 | function visible(x, y) {
|
11156 | return x0 <= x && x <= x1 && y0 <= y && y <= y1;
|
11157 | }
|
11158 |
|
11159 | function interpolate(from, to, direction, stream) {
|
11160 | var a = 0, a1 = 0;
|
11161 | if (from == null
|
11162 | || (a = corner(from, direction)) !== (a1 = corner(to, direction))
|
11163 | || comparePoint(from, to) < 0 ^ direction > 0) {
|
11164 | do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
|
11165 | while ((a = (a + direction + 4) % 4) !== a1);
|
11166 | } else {
|
11167 | stream.point(to[0], to[1]);
|
11168 | }
|
11169 | }
|
11170 |
|
11171 | function corner(p, direction) {
|
11172 | return abs$1(p[0] - x0) < epsilon$1 ? direction > 0 ? 0 : 3
|
11173 | : abs$1(p[0] - x1) < epsilon$1 ? direction > 0 ? 2 : 1
|
11174 | : abs$1(p[1] - y0) < epsilon$1 ? direction > 0 ? 1 : 0
|
11175 | : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
|
11176 | }
|
11177 |
|
11178 | function compareIntersection(a, b) {
|
11179 | return comparePoint(a.x, b.x);
|
11180 | }
|
11181 |
|
11182 | function comparePoint(a, b) {
|
11183 | var ca = corner(a, 1),
|
11184 | cb = corner(b, 1);
|
11185 | return ca !== cb ? ca - cb
|
11186 | : ca === 0 ? b[1] - a[1]
|
11187 | : ca === 1 ? a[0] - b[0]
|
11188 | : ca === 2 ? a[1] - b[1]
|
11189 | : b[0] - a[0];
|
11190 | }
|
11191 |
|
11192 | return function(stream) {
|
11193 | var activeStream = stream,
|
11194 | bufferStream = clipBuffer(),
|
11195 | segments,
|
11196 | polygon,
|
11197 | ring,
|
11198 | x__, y__, v__, // first point
|
11199 | x_, y_, v_, // previous point
|
11200 | first,
|
11201 | clean;
|
11202 |
|
11203 | var clipStream = {
|
11204 | point: point,
|
11205 | lineStart: lineStart,
|
11206 | lineEnd: lineEnd,
|
11207 | polygonStart: polygonStart,
|
11208 | polygonEnd: polygonEnd
|
11209 | };
|
11210 |
|
11211 | function point(x, y) {
|
11212 | if (visible(x, y)) activeStream.point(x, y);
|
11213 | }
|
11214 |
|
11215 | function polygonInside() {
|
11216 | var winding = 0;
|
11217 |
|
11218 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
11219 | for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
|
11220 | a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
|
11221 | if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
|
11222 | else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
|
11223 | }
|
11224 | }
|
11225 |
|
11226 | return winding;
|
11227 | }
|
11228 |
|
11229 | // Buffer geometry within a polygon and then clip it en masse.
|
11230 | function polygonStart() {
|
11231 | activeStream = bufferStream, segments = [], polygon = [], clean = true;
|
11232 | }
|
11233 |
|
11234 | function polygonEnd() {
|
11235 | var startInside = polygonInside(),
|
11236 | cleanInside = clean && startInside,
|
11237 | visible = (segments = merge(segments)).length;
|
11238 | if (cleanInside || visible) {
|
11239 | stream.polygonStart();
|
11240 | if (cleanInside) {
|
11241 | stream.lineStart();
|
11242 | interpolate(null, null, 1, stream);
|
11243 | stream.lineEnd();
|
11244 | }
|
11245 | if (visible) {
|
11246 | clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
|
11247 | }
|
11248 | stream.polygonEnd();
|
11249 | }
|
11250 | activeStream = stream, segments = polygon = ring = null;
|
11251 | }
|
11252 |
|
11253 | function lineStart() {
|
11254 | clipStream.point = linePoint;
|
11255 | if (polygon) polygon.push(ring = []);
|
11256 | first = true;
|
11257 | v_ = false;
|
11258 | x_ = y_ = NaN;
|
11259 | }
|
11260 |
|
11261 | // TODO rather than special-case polygons, simply handle them separately.
|
11262 | // Ideally, coincident intersection points should be jittered to avoid
|
11263 | // clipping issues.
|
11264 | function lineEnd() {
|
11265 | if (segments) {
|
11266 | linePoint(x__, y__);
|
11267 | if (v__ && v_) bufferStream.rejoin();
|
11268 | segments.push(bufferStream.result());
|
11269 | }
|
11270 | clipStream.point = point;
|
11271 | if (v_) activeStream.lineEnd();
|
11272 | }
|
11273 |
|
11274 | function linePoint(x, y) {
|
11275 | var v = visible(x, y);
|
11276 | if (polygon) ring.push([x, y]);
|
11277 | if (first) {
|
11278 | x__ = x, y__ = y, v__ = v;
|
11279 | first = false;
|
11280 | if (v) {
|
11281 | activeStream.lineStart();
|
11282 | activeStream.point(x, y);
|
11283 | }
|
11284 | } else {
|
11285 | if (v && v_) activeStream.point(x, y);
|
11286 | else {
|
11287 | var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
|
11288 | b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
|
11289 | if (clipLine(a, b, x0, y0, x1, y1)) {
|
11290 | if (!v_) {
|
11291 | activeStream.lineStart();
|
11292 | activeStream.point(a[0], a[1]);
|
11293 | }
|
11294 | activeStream.point(b[0], b[1]);
|
11295 | if (!v) activeStream.lineEnd();
|
11296 | clean = false;
|
11297 | } else if (v) {
|
11298 | activeStream.lineStart();
|
11299 | activeStream.point(x, y);
|
11300 | clean = false;
|
11301 | }
|
11302 | }
|
11303 | }
|
11304 | x_ = x, y_ = y, v_ = v;
|
11305 | }
|
11306 |
|
11307 | return clipStream;
|
11308 | };
|
11309 | }
|
11310 |
|
11311 | function extent() {
|
11312 | var x0 = 0,
|
11313 | y0 = 0,
|
11314 | x1 = 960,
|
11315 | y1 = 500,
|
11316 | cache,
|
11317 | cacheStream,
|
11318 | clip;
|
11319 |
|
11320 | return clip = {
|
11321 | stream: function(stream) {
|
11322 | return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
|
11323 | },
|
11324 | extent: function(_) {
|
11325 | return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
|
11326 | }
|
11327 | };
|
11328 | }
|
11329 |
|
11330 | var lengthSum$1,
|
11331 | lambda0,
|
11332 | sinPhi0,
|
11333 | cosPhi0;
|
11334 |
|
11335 | var lengthStream$1 = {
|
11336 | sphere: noop$1,
|
11337 | point: noop$1,
|
11338 | lineStart: lengthLineStart,
|
11339 | lineEnd: noop$1,
|
11340 | polygonStart: noop$1,
|
11341 | polygonEnd: noop$1
|
11342 | };
|
11343 |
|
11344 | function lengthLineStart() {
|
11345 | lengthStream$1.point = lengthPointFirst$1;
|
11346 | lengthStream$1.lineEnd = lengthLineEnd;
|
11347 | }
|
11348 |
|
11349 | function lengthLineEnd() {
|
11350 | lengthStream$1.point = lengthStream$1.lineEnd = noop$1;
|
11351 | }
|
11352 |
|
11353 | function lengthPointFirst$1(lambda, phi) {
|
11354 | lambda *= radians, phi *= radians;
|
11355 | lambda0 = lambda, sinPhi0 = sin$1(phi), cosPhi0 = cos$1(phi);
|
11356 | lengthStream$1.point = lengthPoint$1;
|
11357 | }
|
11358 |
|
11359 | function lengthPoint$1(lambda, phi) {
|
11360 | lambda *= radians, phi *= radians;
|
11361 | var sinPhi = sin$1(phi),
|
11362 | cosPhi = cos$1(phi),
|
11363 | delta = abs$1(lambda - lambda0),
|
11364 | cosDelta = cos$1(delta),
|
11365 | sinDelta = sin$1(delta),
|
11366 | x = cosPhi * sinDelta,
|
11367 | y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta,
|
11368 | z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta;
|
11369 | lengthSum$1.add(atan2$1(sqrt$2(x * x + y * y), z));
|
11370 | lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi;
|
11371 | }
|
11372 |
|
11373 | function length$1(object) {
|
11374 | lengthSum$1 = new Adder();
|
11375 | geoStream(object, lengthStream$1);
|
11376 | return +lengthSum$1;
|
11377 | }
|
11378 |
|
11379 | var coordinates = [null, null],
|
11380 | object = {type: "LineString", coordinates: coordinates};
|
11381 |
|
11382 | function distance(a, b) {
|
11383 | coordinates[0] = a;
|
11384 | coordinates[1] = b;
|
11385 | return length$1(object);
|
11386 | }
|
11387 |
|
11388 | var containsObjectType = {
|
11389 | Feature: function(object, point) {
|
11390 | return containsGeometry(object.geometry, point);
|
11391 | },
|
11392 | FeatureCollection: function(object, point) {
|
11393 | var features = object.features, i = -1, n = features.length;
|
11394 | while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
|
11395 | return false;
|
11396 | }
|
11397 | };
|
11398 |
|
11399 | var containsGeometryType = {
|
11400 | Sphere: function() {
|
11401 | return true;
|
11402 | },
|
11403 | Point: function(object, point) {
|
11404 | return containsPoint(object.coordinates, point);
|
11405 | },
|
11406 | MultiPoint: function(object, point) {
|
11407 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
11408 | while (++i < n) if (containsPoint(coordinates[i], point)) return true;
|
11409 | return false;
|
11410 | },
|
11411 | LineString: function(object, point) {
|
11412 | return containsLine(object.coordinates, point);
|
11413 | },
|
11414 | MultiLineString: function(object, point) {
|
11415 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
11416 | while (++i < n) if (containsLine(coordinates[i], point)) return true;
|
11417 | return false;
|
11418 | },
|
11419 | Polygon: function(object, point) {
|
11420 | return containsPolygon(object.coordinates, point);
|
11421 | },
|
11422 | MultiPolygon: function(object, point) {
|
11423 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
11424 | while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
|
11425 | return false;
|
11426 | },
|
11427 | GeometryCollection: function(object, point) {
|
11428 | var geometries = object.geometries, i = -1, n = geometries.length;
|
11429 | while (++i < n) if (containsGeometry(geometries[i], point)) return true;
|
11430 | return false;
|
11431 | }
|
11432 | };
|
11433 |
|
11434 | function containsGeometry(geometry, point) {
|
11435 | return geometry && containsGeometryType.hasOwnProperty(geometry.type)
|
11436 | ? containsGeometryType[geometry.type](geometry, point)
|
11437 | : false;
|
11438 | }
|
11439 |
|
11440 | function containsPoint(coordinates, point) {
|
11441 | return distance(coordinates, point) === 0;
|
11442 | }
|
11443 |
|
11444 | function containsLine(coordinates, point) {
|
11445 | var ao, bo, ab;
|
11446 | for (var i = 0, n = coordinates.length; i < n; i++) {
|
11447 | bo = distance(coordinates[i], point);
|
11448 | if (bo === 0) return true;
|
11449 | if (i > 0) {
|
11450 | ab = distance(coordinates[i], coordinates[i - 1]);
|
11451 | if (
|
11452 | ab > 0 &&
|
11453 | ao <= ab &&
|
11454 | bo <= ab &&
|
11455 | (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2 * ab
|
11456 | )
|
11457 | return true;
|
11458 | }
|
11459 | ao = bo;
|
11460 | }
|
11461 | return false;
|
11462 | }
|
11463 |
|
11464 | function containsPolygon(coordinates, point) {
|
11465 | return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
|
11466 | }
|
11467 |
|
11468 | function ringRadians(ring) {
|
11469 | return ring = ring.map(pointRadians), ring.pop(), ring;
|
11470 | }
|
11471 |
|
11472 | function pointRadians(point) {
|
11473 | return [point[0] * radians, point[1] * radians];
|
11474 | }
|
11475 |
|
11476 | function contains$1(object, point) {
|
11477 | return (object && containsObjectType.hasOwnProperty(object.type)
|
11478 | ? containsObjectType[object.type]
|
11479 | : containsGeometry)(object, point);
|
11480 | }
|
11481 |
|
11482 | function graticuleX(y0, y1, dy) {
|
11483 | var y = range$2(y0, y1 - epsilon$1, dy).concat(y1);
|
11484 | return function(x) { return y.map(function(y) { return [x, y]; }); };
|
11485 | }
|
11486 |
|
11487 | function graticuleY(x0, x1, dx) {
|
11488 | var x = range$2(x0, x1 - epsilon$1, dx).concat(x1);
|
11489 | return function(y) { return x.map(function(x) { return [x, y]; }); };
|
11490 | }
|
11491 |
|
11492 | function graticule() {
|
11493 | var x1, x0, X1, X0,
|
11494 | y1, y0, Y1, Y0,
|
11495 | dx = 10, dy = dx, DX = 90, DY = 360,
|
11496 | x, y, X, Y,
|
11497 | precision = 2.5;
|
11498 |
|
11499 | function graticule() {
|
11500 | return {type: "MultiLineString", coordinates: lines()};
|
11501 | }
|
11502 |
|
11503 | function lines() {
|
11504 | return range$2(ceil(X0 / DX) * DX, X1, DX).map(X)
|
11505 | .concat(range$2(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
|
11506 | .concat(range$2(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs$1(x % DX) > epsilon$1; }).map(x))
|
11507 | .concat(range$2(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs$1(y % DY) > epsilon$1; }).map(y));
|
11508 | }
|
11509 |
|
11510 | graticule.lines = function() {
|
11511 | return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
|
11512 | };
|
11513 |
|
11514 | graticule.outline = function() {
|
11515 | return {
|
11516 | type: "Polygon",
|
11517 | coordinates: [
|
11518 | X(X0).concat(
|
11519 | Y(Y1).slice(1),
|
11520 | X(X1).reverse().slice(1),
|
11521 | Y(Y0).reverse().slice(1))
|
11522 | ]
|
11523 | };
|
11524 | };
|
11525 |
|
11526 | graticule.extent = function(_) {
|
11527 | if (!arguments.length) return graticule.extentMinor();
|
11528 | return graticule.extentMajor(_).extentMinor(_);
|
11529 | };
|
11530 |
|
11531 | graticule.extentMajor = function(_) {
|
11532 | if (!arguments.length) return [[X0, Y0], [X1, Y1]];
|
11533 | X0 = +_[0][0], X1 = +_[1][0];
|
11534 | Y0 = +_[0][1], Y1 = +_[1][1];
|
11535 | if (X0 > X1) _ = X0, X0 = X1, X1 = _;
|
11536 | if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
|
11537 | return graticule.precision(precision);
|
11538 | };
|
11539 |
|
11540 | graticule.extentMinor = function(_) {
|
11541 | if (!arguments.length) return [[x0, y0], [x1, y1]];
|
11542 | x0 = +_[0][0], x1 = +_[1][0];
|
11543 | y0 = +_[0][1], y1 = +_[1][1];
|
11544 | if (x0 > x1) _ = x0, x0 = x1, x1 = _;
|
11545 | if (y0 > y1) _ = y0, y0 = y1, y1 = _;
|
11546 | return graticule.precision(precision);
|
11547 | };
|
11548 |
|
11549 | graticule.step = function(_) {
|
11550 | if (!arguments.length) return graticule.stepMinor();
|
11551 | return graticule.stepMajor(_).stepMinor(_);
|
11552 | };
|
11553 |
|
11554 | graticule.stepMajor = function(_) {
|
11555 | if (!arguments.length) return [DX, DY];
|
11556 | DX = +_[0], DY = +_[1];
|
11557 | return graticule;
|
11558 | };
|
11559 |
|
11560 | graticule.stepMinor = function(_) {
|
11561 | if (!arguments.length) return [dx, dy];
|
11562 | dx = +_[0], dy = +_[1];
|
11563 | return graticule;
|
11564 | };
|
11565 |
|
11566 | graticule.precision = function(_) {
|
11567 | if (!arguments.length) return precision;
|
11568 | precision = +_;
|
11569 | x = graticuleX(y0, y1, 90);
|
11570 | y = graticuleY(x0, x1, precision);
|
11571 | X = graticuleX(Y0, Y1, 90);
|
11572 | Y = graticuleY(X0, X1, precision);
|
11573 | return graticule;
|
11574 | };
|
11575 |
|
11576 | return graticule
|
11577 | .extentMajor([[-180, -90 + epsilon$1], [180, 90 - epsilon$1]])
|
11578 | .extentMinor([[-180, -80 - epsilon$1], [180, 80 + epsilon$1]]);
|
11579 | }
|
11580 |
|
11581 | function graticule10() {
|
11582 | return graticule()();
|
11583 | }
|
11584 |
|
11585 | function interpolate(a, b) {
|
11586 | var x0 = a[0] * radians,
|
11587 | y0 = a[1] * radians,
|
11588 | x1 = b[0] * radians,
|
11589 | y1 = b[1] * radians,
|
11590 | cy0 = cos$1(y0),
|
11591 | sy0 = sin$1(y0),
|
11592 | cy1 = cos$1(y1),
|
11593 | sy1 = sin$1(y1),
|
11594 | kx0 = cy0 * cos$1(x0),
|
11595 | ky0 = cy0 * sin$1(x0),
|
11596 | kx1 = cy1 * cos$1(x1),
|
11597 | ky1 = cy1 * sin$1(x1),
|
11598 | d = 2 * asin$1(sqrt$2(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
|
11599 | k = sin$1(d);
|
11600 |
|
11601 | var interpolate = d ? function(t) {
|
11602 | var B = sin$1(t *= d) / k,
|
11603 | A = sin$1(d - t) / k,
|
11604 | x = A * kx0 + B * kx1,
|
11605 | y = A * ky0 + B * ky1,
|
11606 | z = A * sy0 + B * sy1;
|
11607 | return [
|
11608 | atan2$1(y, x) * degrees,
|
11609 | atan2$1(z, sqrt$2(x * x + y * y)) * degrees
|
11610 | ];
|
11611 | } : function() {
|
11612 | return [x0 * degrees, y0 * degrees];
|
11613 | };
|
11614 |
|
11615 | interpolate.distance = d;
|
11616 |
|
11617 | return interpolate;
|
11618 | }
|
11619 |
|
11620 | var identity$5 = x => x;
|
11621 |
|
11622 | var areaSum = new Adder(),
|
11623 | areaRingSum = new Adder(),
|
11624 | x00$2,
|
11625 | y00$2,
|
11626 | x0$3,
|
11627 | y0$3;
|
11628 |
|
11629 | var areaStream = {
|
11630 | point: noop$1,
|
11631 | lineStart: noop$1,
|
11632 | lineEnd: noop$1,
|
11633 | polygonStart: function() {
|
11634 | areaStream.lineStart = areaRingStart;
|
11635 | areaStream.lineEnd = areaRingEnd;
|
11636 | },
|
11637 | polygonEnd: function() {
|
11638 | areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop$1;
|
11639 | areaSum.add(abs$1(areaRingSum));
|
11640 | areaRingSum = new Adder();
|
11641 | },
|
11642 | result: function() {
|
11643 | var area = areaSum / 2;
|
11644 | areaSum = new Adder();
|
11645 | return area;
|
11646 | }
|
11647 | };
|
11648 |
|
11649 | function areaRingStart() {
|
11650 | areaStream.point = areaPointFirst;
|
11651 | }
|
11652 |
|
11653 | function areaPointFirst(x, y) {
|
11654 | areaStream.point = areaPoint;
|
11655 | x00$2 = x0$3 = x, y00$2 = y0$3 = y;
|
11656 | }
|
11657 |
|
11658 | function areaPoint(x, y) {
|
11659 | areaRingSum.add(y0$3 * x - x0$3 * y);
|
11660 | x0$3 = x, y0$3 = y;
|
11661 | }
|
11662 |
|
11663 | function areaRingEnd() {
|
11664 | areaPoint(x00$2, y00$2);
|
11665 | }
|
11666 |
|
11667 | var pathArea = areaStream;
|
11668 |
|
11669 | var x0$2 = Infinity,
|
11670 | y0$2 = x0$2,
|
11671 | x1 = -x0$2,
|
11672 | y1 = x1;
|
11673 |
|
11674 | var boundsStream = {
|
11675 | point: boundsPoint,
|
11676 | lineStart: noop$1,
|
11677 | lineEnd: noop$1,
|
11678 | polygonStart: noop$1,
|
11679 | polygonEnd: noop$1,
|
11680 | result: function() {
|
11681 | var bounds = [[x0$2, y0$2], [x1, y1]];
|
11682 | x1 = y1 = -(y0$2 = x0$2 = Infinity);
|
11683 | return bounds;
|
11684 | }
|
11685 | };
|
11686 |
|
11687 | function boundsPoint(x, y) {
|
11688 | if (x < x0$2) x0$2 = x;
|
11689 | if (x > x1) x1 = x;
|
11690 | if (y < y0$2) y0$2 = y;
|
11691 | if (y > y1) y1 = y;
|
11692 | }
|
11693 |
|
11694 | var boundsStream$1 = boundsStream;
|
11695 |
|
11696 | // TODO Enforce positive area for exterior, negative area for interior?
|
11697 |
|
11698 | var X0 = 0,
|
11699 | Y0 = 0,
|
11700 | Z0 = 0,
|
11701 | X1 = 0,
|
11702 | Y1 = 0,
|
11703 | Z1 = 0,
|
11704 | X2 = 0,
|
11705 | Y2 = 0,
|
11706 | Z2 = 0,
|
11707 | x00$1,
|
11708 | y00$1,
|
11709 | x0$1,
|
11710 | y0$1;
|
11711 |
|
11712 | var centroidStream = {
|
11713 | point: centroidPoint,
|
11714 | lineStart: centroidLineStart,
|
11715 | lineEnd: centroidLineEnd,
|
11716 | polygonStart: function() {
|
11717 | centroidStream.lineStart = centroidRingStart;
|
11718 | centroidStream.lineEnd = centroidRingEnd;
|
11719 | },
|
11720 | polygonEnd: function() {
|
11721 | centroidStream.point = centroidPoint;
|
11722 | centroidStream.lineStart = centroidLineStart;
|
11723 | centroidStream.lineEnd = centroidLineEnd;
|
11724 | },
|
11725 | result: function() {
|
11726 | var centroid = Z2 ? [X2 / Z2, Y2 / Z2]
|
11727 | : Z1 ? [X1 / Z1, Y1 / Z1]
|
11728 | : Z0 ? [X0 / Z0, Y0 / Z0]
|
11729 | : [NaN, NaN];
|
11730 | X0 = Y0 = Z0 =
|
11731 | X1 = Y1 = Z1 =
|
11732 | X2 = Y2 = Z2 = 0;
|
11733 | return centroid;
|
11734 | }
|
11735 | };
|
11736 |
|
11737 | function centroidPoint(x, y) {
|
11738 | X0 += x;
|
11739 | Y0 += y;
|
11740 | ++Z0;
|
11741 | }
|
11742 |
|
11743 | function centroidLineStart() {
|
11744 | centroidStream.point = centroidPointFirstLine;
|
11745 | }
|
11746 |
|
11747 | function centroidPointFirstLine(x, y) {
|
11748 | centroidStream.point = centroidPointLine;
|
11749 | centroidPoint(x0$1 = x, y0$1 = y);
|
11750 | }
|
11751 |
|
11752 | function centroidPointLine(x, y) {
|
11753 | var dx = x - x0$1, dy = y - y0$1, z = sqrt$2(dx * dx + dy * dy);
|
11754 | X1 += z * (x0$1 + x) / 2;
|
11755 | Y1 += z * (y0$1 + y) / 2;
|
11756 | Z1 += z;
|
11757 | centroidPoint(x0$1 = x, y0$1 = y);
|
11758 | }
|
11759 |
|
11760 | function centroidLineEnd() {
|
11761 | centroidStream.point = centroidPoint;
|
11762 | }
|
11763 |
|
11764 | function centroidRingStart() {
|
11765 | centroidStream.point = centroidPointFirstRing;
|
11766 | }
|
11767 |
|
11768 | function centroidRingEnd() {
|
11769 | centroidPointRing(x00$1, y00$1);
|
11770 | }
|
11771 |
|
11772 | function centroidPointFirstRing(x, y) {
|
11773 | centroidStream.point = centroidPointRing;
|
11774 | centroidPoint(x00$1 = x0$1 = x, y00$1 = y0$1 = y);
|
11775 | }
|
11776 |
|
11777 | function centroidPointRing(x, y) {
|
11778 | var dx = x - x0$1,
|
11779 | dy = y - y0$1,
|
11780 | z = sqrt$2(dx * dx + dy * dy);
|
11781 |
|
11782 | X1 += z * (x0$1 + x) / 2;
|
11783 | Y1 += z * (y0$1 + y) / 2;
|
11784 | Z1 += z;
|
11785 |
|
11786 | z = y0$1 * x - x0$1 * y;
|
11787 | X2 += z * (x0$1 + x);
|
11788 | Y2 += z * (y0$1 + y);
|
11789 | Z2 += z * 3;
|
11790 | centroidPoint(x0$1 = x, y0$1 = y);
|
11791 | }
|
11792 |
|
11793 | var pathCentroid = centroidStream;
|
11794 |
|
11795 | function PathContext(context) {
|
11796 | this._context = context;
|
11797 | }
|
11798 |
|
11799 | PathContext.prototype = {
|
11800 | _radius: 4.5,
|
11801 | pointRadius: function(_) {
|
11802 | return this._radius = _, this;
|
11803 | },
|
11804 | polygonStart: function() {
|
11805 | this._line = 0;
|
11806 | },
|
11807 | polygonEnd: function() {
|
11808 | this._line = NaN;
|
11809 | },
|
11810 | lineStart: function() {
|
11811 | this._point = 0;
|
11812 | },
|
11813 | lineEnd: function() {
|
11814 | if (this._line === 0) this._context.closePath();
|
11815 | this._point = NaN;
|
11816 | },
|
11817 | point: function(x, y) {
|
11818 | switch (this._point) {
|
11819 | case 0: {
|
11820 | this._context.moveTo(x, y);
|
11821 | this._point = 1;
|
11822 | break;
|
11823 | }
|
11824 | case 1: {
|
11825 | this._context.lineTo(x, y);
|
11826 | break;
|
11827 | }
|
11828 | default: {
|
11829 | this._context.moveTo(x + this._radius, y);
|
11830 | this._context.arc(x, y, this._radius, 0, tau$1);
|
11831 | break;
|
11832 | }
|
11833 | }
|
11834 | },
|
11835 | result: noop$1
|
11836 | };
|
11837 |
|
11838 | var lengthSum = new Adder(),
|
11839 | lengthRing,
|
11840 | x00,
|
11841 | y00,
|
11842 | x0,
|
11843 | y0;
|
11844 |
|
11845 | var lengthStream = {
|
11846 | point: noop$1,
|
11847 | lineStart: function() {
|
11848 | lengthStream.point = lengthPointFirst;
|
11849 | },
|
11850 | lineEnd: function() {
|
11851 | if (lengthRing) lengthPoint(x00, y00);
|
11852 | lengthStream.point = noop$1;
|
11853 | },
|
11854 | polygonStart: function() {
|
11855 | lengthRing = true;
|
11856 | },
|
11857 | polygonEnd: function() {
|
11858 | lengthRing = null;
|
11859 | },
|
11860 | result: function() {
|
11861 | var length = +lengthSum;
|
11862 | lengthSum = new Adder();
|
11863 | return length;
|
11864 | }
|
11865 | };
|
11866 |
|
11867 | function lengthPointFirst(x, y) {
|
11868 | lengthStream.point = lengthPoint;
|
11869 | x00 = x0 = x, y00 = y0 = y;
|
11870 | }
|
11871 |
|
11872 | function lengthPoint(x, y) {
|
11873 | x0 -= x, y0 -= y;
|
11874 | lengthSum.add(sqrt$2(x0 * x0 + y0 * y0));
|
11875 | x0 = x, y0 = y;
|
11876 | }
|
11877 |
|
11878 | var pathMeasure = lengthStream;
|
11879 |
|
11880 | // Simple caching for constant-radius points.
|
11881 | let cacheDigits, cacheAppend, cacheRadius, cacheCircle;
|
11882 |
|
11883 | class PathString {
|
11884 | constructor(digits) {
|
11885 | this._append = digits == null ? append : appendRound(digits);
|
11886 | this._radius = 4.5;
|
11887 | this._ = "";
|
11888 | }
|
11889 | pointRadius(_) {
|
11890 | this._radius = +_;
|
11891 | return this;
|
11892 | }
|
11893 | polygonStart() {
|
11894 | this._line = 0;
|
11895 | }
|
11896 | polygonEnd() {
|
11897 | this._line = NaN;
|
11898 | }
|
11899 | lineStart() {
|
11900 | this._point = 0;
|
11901 | }
|
11902 | lineEnd() {
|
11903 | if (this._line === 0) this._ += "Z";
|
11904 | this._point = NaN;
|
11905 | }
|
11906 | point(x, y) {
|
11907 | switch (this._point) {
|
11908 | case 0: {
|
11909 | this._append`M${x},${y}`;
|
11910 | this._point = 1;
|
11911 | break;
|
11912 | }
|
11913 | case 1: {
|
11914 | this._append`L${x},${y}`;
|
11915 | break;
|
11916 | }
|
11917 | default: {
|
11918 | this._append`M${x},${y}`;
|
11919 | if (this._radius !== cacheRadius || this._append !== cacheAppend) {
|
11920 | const r = this._radius;
|
11921 | const s = this._;
|
11922 | this._ = ""; // stash the old string so we can cache the circle path fragment
|
11923 | this._append`m0,${r}a${r},${r} 0 1,1 0,${-2 * r}a${r},${r} 0 1,1 0,${2 * r}z`;
|
11924 | cacheRadius = r;
|
11925 | cacheAppend = this._append;
|
11926 | cacheCircle = this._;
|
11927 | this._ = s;
|
11928 | }
|
11929 | this._ += cacheCircle;
|
11930 | break;
|
11931 | }
|
11932 | }
|
11933 | }
|
11934 | result() {
|
11935 | const result = this._;
|
11936 | this._ = "";
|
11937 | return result.length ? result : null;
|
11938 | }
|
11939 | }
|
11940 |
|
11941 | function append(strings) {
|
11942 | let i = 1;
|
11943 | this._ += strings[0];
|
11944 | for (const j = strings.length; i < j; ++i) {
|
11945 | this._ += arguments[i] + strings[i];
|
11946 | }
|
11947 | }
|
11948 |
|
11949 | function appendRound(digits) {
|
11950 | const d = Math.floor(digits);
|
11951 | if (!(d >= 0)) throw new RangeError(`invalid digits: ${digits}`);
|
11952 | if (d > 15) return append;
|
11953 | if (d !== cacheDigits) {
|
11954 | const k = 10 ** d;
|
11955 | cacheDigits = d;
|
11956 | cacheAppend = function append(strings) {
|
11957 | let i = 1;
|
11958 | this._ += strings[0];
|
11959 | for (const j = strings.length; i < j; ++i) {
|
11960 | this._ += Math.round(arguments[i] * k) / k + strings[i];
|
11961 | }
|
11962 | };
|
11963 | }
|
11964 | return cacheAppend;
|
11965 | }
|
11966 |
|
11967 | function index$2(projection, context) {
|
11968 | let digits = 3,
|
11969 | pointRadius = 4.5,
|
11970 | projectionStream,
|
11971 | contextStream;
|
11972 |
|
11973 | function path(object) {
|
11974 | if (object) {
|
11975 | if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
|
11976 | geoStream(object, projectionStream(contextStream));
|
11977 | }
|
11978 | return contextStream.result();
|
11979 | }
|
11980 |
|
11981 | path.area = function(object) {
|
11982 | geoStream(object, projectionStream(pathArea));
|
11983 | return pathArea.result();
|
11984 | };
|
11985 |
|
11986 | path.measure = function(object) {
|
11987 | geoStream(object, projectionStream(pathMeasure));
|
11988 | return pathMeasure.result();
|
11989 | };
|
11990 |
|
11991 | path.bounds = function(object) {
|
11992 | geoStream(object, projectionStream(boundsStream$1));
|
11993 | return boundsStream$1.result();
|
11994 | };
|
11995 |
|
11996 | path.centroid = function(object) {
|
11997 | geoStream(object, projectionStream(pathCentroid));
|
11998 | return pathCentroid.result();
|
11999 | };
|
12000 |
|
12001 | path.projection = function(_) {
|
12002 | if (!arguments.length) return projection;
|
12003 | projectionStream = _ == null ? (projection = null, identity$5) : (projection = _).stream;
|
12004 | return path;
|
12005 | };
|
12006 |
|
12007 | path.context = function(_) {
|
12008 | if (!arguments.length) return context;
|
12009 | contextStream = _ == null ? (context = null, new PathString(digits)) : new PathContext(context = _);
|
12010 | if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
|
12011 | return path;
|
12012 | };
|
12013 |
|
12014 | path.pointRadius = function(_) {
|
12015 | if (!arguments.length) return pointRadius;
|
12016 | pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
|
12017 | return path;
|
12018 | };
|
12019 |
|
12020 | path.digits = function(_) {
|
12021 | if (!arguments.length) return digits;
|
12022 | if (_ == null) digits = null;
|
12023 | else {
|
12024 | const d = Math.floor(_);
|
12025 | if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
|
12026 | digits = d;
|
12027 | }
|
12028 | if (context === null) contextStream = new PathString(digits);
|
12029 | return path;
|
12030 | };
|
12031 |
|
12032 | return path.projection(projection).digits(digits).context(context);
|
12033 | }
|
12034 |
|
12035 | function transform$1(methods) {
|
12036 | return {
|
12037 | stream: transformer$3(methods)
|
12038 | };
|
12039 | }
|
12040 |
|
12041 | function transformer$3(methods) {
|
12042 | return function(stream) {
|
12043 | var s = new TransformStream;
|
12044 | for (var key in methods) s[key] = methods[key];
|
12045 | s.stream = stream;
|
12046 | return s;
|
12047 | };
|
12048 | }
|
12049 |
|
12050 | function TransformStream() {}
|
12051 |
|
12052 | TransformStream.prototype = {
|
12053 | constructor: TransformStream,
|
12054 | point: function(x, y) { this.stream.point(x, y); },
|
12055 | sphere: function() { this.stream.sphere(); },
|
12056 | lineStart: function() { this.stream.lineStart(); },
|
12057 | lineEnd: function() { this.stream.lineEnd(); },
|
12058 | polygonStart: function() { this.stream.polygonStart(); },
|
12059 | polygonEnd: function() { this.stream.polygonEnd(); }
|
12060 | };
|
12061 |
|
12062 | function fit(projection, fitBounds, object) {
|
12063 | var clip = projection.clipExtent && projection.clipExtent();
|
12064 | projection.scale(150).translate([0, 0]);
|
12065 | if (clip != null) projection.clipExtent(null);
|
12066 | geoStream(object, projection.stream(boundsStream$1));
|
12067 | fitBounds(boundsStream$1.result());
|
12068 | if (clip != null) projection.clipExtent(clip);
|
12069 | return projection;
|
12070 | }
|
12071 |
|
12072 | function fitExtent(projection, extent, object) {
|
12073 | return fit(projection, function(b) {
|
12074 | var w = extent[1][0] - extent[0][0],
|
12075 | h = extent[1][1] - extent[0][1],
|
12076 | k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
|
12077 | x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
|
12078 | y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
|
12079 | projection.scale(150 * k).translate([x, y]);
|
12080 | }, object);
|
12081 | }
|
12082 |
|
12083 | function fitSize(projection, size, object) {
|
12084 | return fitExtent(projection, [[0, 0], size], object);
|
12085 | }
|
12086 |
|
12087 | function fitWidth(projection, width, object) {
|
12088 | return fit(projection, function(b) {
|
12089 | var w = +width,
|
12090 | k = w / (b[1][0] - b[0][0]),
|
12091 | x = (w - k * (b[1][0] + b[0][0])) / 2,
|
12092 | y = -k * b[0][1];
|
12093 | projection.scale(150 * k).translate([x, y]);
|
12094 | }, object);
|
12095 | }
|
12096 |
|
12097 | function fitHeight(projection, height, object) {
|
12098 | return fit(projection, function(b) {
|
12099 | var h = +height,
|
12100 | k = h / (b[1][1] - b[0][1]),
|
12101 | x = -k * b[0][0],
|
12102 | y = (h - k * (b[1][1] + b[0][1])) / 2;
|
12103 | projection.scale(150 * k).translate([x, y]);
|
12104 | }, object);
|
12105 | }
|
12106 |
|
12107 | var maxDepth = 16, // maximum depth of subdivision
|
12108 | cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
|
12109 |
|
12110 | function resample(project, delta2) {
|
12111 | return +delta2 ? resample$1(project, delta2) : resampleNone(project);
|
12112 | }
|
12113 |
|
12114 | function resampleNone(project) {
|
12115 | return transformer$3({
|
12116 | point: function(x, y) {
|
12117 | x = project(x, y);
|
12118 | this.stream.point(x[0], x[1]);
|
12119 | }
|
12120 | });
|
12121 | }
|
12122 |
|
12123 | function resample$1(project, delta2) {
|
12124 |
|
12125 | function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
|
12126 | var dx = x1 - x0,
|
12127 | dy = y1 - y0,
|
12128 | d2 = dx * dx + dy * dy;
|
12129 | if (d2 > 4 * delta2 && depth--) {
|
12130 | var a = a0 + a1,
|
12131 | b = b0 + b1,
|
12132 | c = c0 + c1,
|
12133 | m = sqrt$2(a * a + b * b + c * c),
|
12134 | phi2 = asin$1(c /= m),
|
12135 | lambda2 = abs$1(abs$1(c) - 1) < epsilon$1 || abs$1(lambda0 - lambda1) < epsilon$1 ? (lambda0 + lambda1) / 2 : atan2$1(b, a),
|
12136 | p = project(lambda2, phi2),
|
12137 | x2 = p[0],
|
12138 | y2 = p[1],
|
12139 | dx2 = x2 - x0,
|
12140 | dy2 = y2 - y0,
|
12141 | dz = dy * dx2 - dx * dy2;
|
12142 | if (dz * dz / d2 > delta2 // perpendicular projected distance
|
12143 | || abs$1((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
|
12144 | || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
|
12145 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
|
12146 | stream.point(x2, y2);
|
12147 | resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
|
12148 | }
|
12149 | }
|
12150 | }
|
12151 | return function(stream) {
|
12152 | var lambda00, x00, y00, a00, b00, c00, // first point
|
12153 | lambda0, x0, y0, a0, b0, c0; // previous point
|
12154 |
|
12155 | var resampleStream = {
|
12156 | point: point,
|
12157 | lineStart: lineStart,
|
12158 | lineEnd: lineEnd,
|
12159 | polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
|
12160 | polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
|
12161 | };
|
12162 |
|
12163 | function point(x, y) {
|
12164 | x = project(x, y);
|
12165 | stream.point(x[0], x[1]);
|
12166 | }
|
12167 |
|
12168 | function lineStart() {
|
12169 | x0 = NaN;
|
12170 | resampleStream.point = linePoint;
|
12171 | stream.lineStart();
|
12172 | }
|
12173 |
|
12174 | function linePoint(lambda, phi) {
|
12175 | var c = cartesian([lambda, phi]), p = project(lambda, phi);
|
12176 | 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);
|
12177 | stream.point(x0, y0);
|
12178 | }
|
12179 |
|
12180 | function lineEnd() {
|
12181 | resampleStream.point = point;
|
12182 | stream.lineEnd();
|
12183 | }
|
12184 |
|
12185 | function ringStart() {
|
12186 | lineStart();
|
12187 | resampleStream.point = ringPoint;
|
12188 | resampleStream.lineEnd = ringEnd;
|
12189 | }
|
12190 |
|
12191 | function ringPoint(lambda, phi) {
|
12192 | linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
|
12193 | resampleStream.point = linePoint;
|
12194 | }
|
12195 |
|
12196 | function ringEnd() {
|
12197 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
|
12198 | resampleStream.lineEnd = lineEnd;
|
12199 | lineEnd();
|
12200 | }
|
12201 |
|
12202 | return resampleStream;
|
12203 | };
|
12204 | }
|
12205 |
|
12206 | var transformRadians = transformer$3({
|
12207 | point: function(x, y) {
|
12208 | this.stream.point(x * radians, y * radians);
|
12209 | }
|
12210 | });
|
12211 |
|
12212 | function transformRotate(rotate) {
|
12213 | return transformer$3({
|
12214 | point: function(x, y) {
|
12215 | var r = rotate(x, y);
|
12216 | return this.stream.point(r[0], r[1]);
|
12217 | }
|
12218 | });
|
12219 | }
|
12220 |
|
12221 | function scaleTranslate(k, dx, dy, sx, sy) {
|
12222 | function transform(x, y) {
|
12223 | x *= sx; y *= sy;
|
12224 | return [dx + k * x, dy - k * y];
|
12225 | }
|
12226 | transform.invert = function(x, y) {
|
12227 | return [(x - dx) / k * sx, (dy - y) / k * sy];
|
12228 | };
|
12229 | return transform;
|
12230 | }
|
12231 |
|
12232 | function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) {
|
12233 | if (!alpha) return scaleTranslate(k, dx, dy, sx, sy);
|
12234 | var cosAlpha = cos$1(alpha),
|
12235 | sinAlpha = sin$1(alpha),
|
12236 | a = cosAlpha * k,
|
12237 | b = sinAlpha * k,
|
12238 | ai = cosAlpha / k,
|
12239 | bi = sinAlpha / k,
|
12240 | ci = (sinAlpha * dy - cosAlpha * dx) / k,
|
12241 | fi = (sinAlpha * dx + cosAlpha * dy) / k;
|
12242 | function transform(x, y) {
|
12243 | x *= sx; y *= sy;
|
12244 | return [a * x - b * y + dx, dy - b * x - a * y];
|
12245 | }
|
12246 | transform.invert = function(x, y) {
|
12247 | return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)];
|
12248 | };
|
12249 | return transform;
|
12250 | }
|
12251 |
|
12252 | function projection(project) {
|
12253 | return projectionMutator(function() { return project; })();
|
12254 | }
|
12255 |
|
12256 | function projectionMutator(projectAt) {
|
12257 | var project,
|
12258 | k = 150, // scale
|
12259 | x = 480, y = 250, // translate
|
12260 | lambda = 0, phi = 0, // center
|
12261 | deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
|
12262 | alpha = 0, // post-rotate angle
|
12263 | sx = 1, // reflectX
|
12264 | sy = 1, // reflectX
|
12265 | theta = null, preclip = clipAntimeridian, // pre-clip angle
|
12266 | x0 = null, y0, x1, y1, postclip = identity$5, // post-clip extent
|
12267 | delta2 = 0.5, // precision
|
12268 | projectResample,
|
12269 | projectTransform,
|
12270 | projectRotateTransform,
|
12271 | cache,
|
12272 | cacheStream;
|
12273 |
|
12274 | function projection(point) {
|
12275 | return projectRotateTransform(point[0] * radians, point[1] * radians);
|
12276 | }
|
12277 |
|
12278 | function invert(point) {
|
12279 | point = projectRotateTransform.invert(point[0], point[1]);
|
12280 | return point && [point[0] * degrees, point[1] * degrees];
|
12281 | }
|
12282 |
|
12283 | projection.stream = function(stream) {
|
12284 | return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
|
12285 | };
|
12286 |
|
12287 | projection.preclip = function(_) {
|
12288 | return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
|
12289 | };
|
12290 |
|
12291 | projection.postclip = function(_) {
|
12292 | return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
|
12293 | };
|
12294 |
|
12295 | projection.clipAngle = function(_) {
|
12296 | return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees;
|
12297 | };
|
12298 |
|
12299 | projection.clipExtent = function(_) {
|
12300 | 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]];
|
12301 | };
|
12302 |
|
12303 | projection.scale = function(_) {
|
12304 | return arguments.length ? (k = +_, recenter()) : k;
|
12305 | };
|
12306 |
|
12307 | projection.translate = function(_) {
|
12308 | return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
|
12309 | };
|
12310 |
|
12311 | projection.center = function(_) {
|
12312 | return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees];
|
12313 | };
|
12314 |
|
12315 | projection.rotate = function(_) {
|
12316 | 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];
|
12317 | };
|
12318 |
|
12319 | projection.angle = function(_) {
|
12320 | return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees;
|
12321 | };
|
12322 |
|
12323 | projection.reflectX = function(_) {
|
12324 | return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0;
|
12325 | };
|
12326 |
|
12327 | projection.reflectY = function(_) {
|
12328 | return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0;
|
12329 | };
|
12330 |
|
12331 | projection.precision = function(_) {
|
12332 | return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$2(delta2);
|
12333 | };
|
12334 |
|
12335 | projection.fitExtent = function(extent, object) {
|
12336 | return fitExtent(projection, extent, object);
|
12337 | };
|
12338 |
|
12339 | projection.fitSize = function(size, object) {
|
12340 | return fitSize(projection, size, object);
|
12341 | };
|
12342 |
|
12343 | projection.fitWidth = function(width, object) {
|
12344 | return fitWidth(projection, width, object);
|
12345 | };
|
12346 |
|
12347 | projection.fitHeight = function(height, object) {
|
12348 | return fitHeight(projection, height, object);
|
12349 | };
|
12350 |
|
12351 | function recenter() {
|
12352 | var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)),
|
12353 | transform = scaleTranslateRotate(k, x - center[0], y - center[1], sx, sy, alpha);
|
12354 | rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
|
12355 | projectTransform = compose(project, transform);
|
12356 | projectRotateTransform = compose(rotate, projectTransform);
|
12357 | projectResample = resample(projectTransform, delta2);
|
12358 | return reset();
|
12359 | }
|
12360 |
|
12361 | function reset() {
|
12362 | cache = cacheStream = null;
|
12363 | return projection;
|
12364 | }
|
12365 |
|
12366 | return function() {
|
12367 | project = projectAt.apply(this, arguments);
|
12368 | projection.invert = project.invert && invert;
|
12369 | return recenter();
|
12370 | };
|
12371 | }
|
12372 |
|
12373 | function conicProjection(projectAt) {
|
12374 | var phi0 = 0,
|
12375 | phi1 = pi$1 / 3,
|
12376 | m = projectionMutator(projectAt),
|
12377 | p = m(phi0, phi1);
|
12378 |
|
12379 | p.parallels = function(_) {
|
12380 | return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees, phi1 * degrees];
|
12381 | };
|
12382 |
|
12383 | return p;
|
12384 | }
|
12385 |
|
12386 | function cylindricalEqualAreaRaw(phi0) {
|
12387 | var cosPhi0 = cos$1(phi0);
|
12388 |
|
12389 | function forward(lambda, phi) {
|
12390 | return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
|
12391 | }
|
12392 |
|
12393 | forward.invert = function(x, y) {
|
12394 | return [x / cosPhi0, asin$1(y * cosPhi0)];
|
12395 | };
|
12396 |
|
12397 | return forward;
|
12398 | }
|
12399 |
|
12400 | function conicEqualAreaRaw(y0, y1) {
|
12401 | var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
|
12402 |
|
12403 | // Are the parallels symmetrical around the Equator?
|
12404 | if (abs$1(n) < epsilon$1) return cylindricalEqualAreaRaw(y0);
|
12405 |
|
12406 | var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt$2(c) / n;
|
12407 |
|
12408 | function project(x, y) {
|
12409 | var r = sqrt$2(c - 2 * n * sin$1(y)) / n;
|
12410 | return [r * sin$1(x *= n), r0 - r * cos$1(x)];
|
12411 | }
|
12412 |
|
12413 | project.invert = function(x, y) {
|
12414 | var r0y = r0 - y,
|
12415 | l = atan2$1(x, abs$1(r0y)) * sign$1(r0y);
|
12416 | if (r0y * n < 0)
|
12417 | l -= pi$1 * sign$1(x) * sign$1(r0y);
|
12418 | return [l / n, asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
|
12419 | };
|
12420 |
|
12421 | return project;
|
12422 | }
|
12423 |
|
12424 | function conicEqualArea() {
|
12425 | return conicProjection(conicEqualAreaRaw)
|
12426 | .scale(155.424)
|
12427 | .center([0, 33.6442]);
|
12428 | }
|
12429 |
|
12430 | function albers() {
|
12431 | return conicEqualArea()
|
12432 | .parallels([29.5, 45.5])
|
12433 | .scale(1070)
|
12434 | .translate([480, 250])
|
12435 | .rotate([96, 0])
|
12436 | .center([-0.6, 38.7]);
|
12437 | }
|
12438 |
|
12439 | // The projections must have mutually exclusive clip regions on the sphere,
|
12440 | // as this will avoid emitting interleaving lines and polygons.
|
12441 | function multiplex(streams) {
|
12442 | var n = streams.length;
|
12443 | return {
|
12444 | point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
|
12445 | sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
|
12446 | lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
|
12447 | lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
|
12448 | polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
|
12449 | polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
|
12450 | };
|
12451 | }
|
12452 |
|
12453 | // A composite projection for the United States, configured by default for
|
12454 | // 960×500. The projection also works quite well at 960×600 if you change the
|
12455 | // scale to 1285 and adjust the translate accordingly. The set of standard
|
12456 | // parallels for each region comes from USGS, which is published here:
|
12457 | // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
|
12458 | function albersUsa() {
|
12459 | var cache,
|
12460 | cacheStream,
|
12461 | lower48 = albers(), lower48Point,
|
12462 | alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
|
12463 | hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
|
12464 | point, pointStream = {point: function(x, y) { point = [x, y]; }};
|
12465 |
|
12466 | function albersUsa(coordinates) {
|
12467 | var x = coordinates[0], y = coordinates[1];
|
12468 | return point = null,
|
12469 | (lower48Point.point(x, y), point)
|
12470 | || (alaskaPoint.point(x, y), point)
|
12471 | || (hawaiiPoint.point(x, y), point);
|
12472 | }
|
12473 |
|
12474 | albersUsa.invert = function(coordinates) {
|
12475 | var k = lower48.scale(),
|
12476 | t = lower48.translate(),
|
12477 | x = (coordinates[0] - t[0]) / k,
|
12478 | y = (coordinates[1] - t[1]) / k;
|
12479 | return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
|
12480 | : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
|
12481 | : lower48).invert(coordinates);
|
12482 | };
|
12483 |
|
12484 | albersUsa.stream = function(stream) {
|
12485 | return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
|
12486 | };
|
12487 |
|
12488 | albersUsa.precision = function(_) {
|
12489 | if (!arguments.length) return lower48.precision();
|
12490 | lower48.precision(_), alaska.precision(_), hawaii.precision(_);
|
12491 | return reset();
|
12492 | };
|
12493 |
|
12494 | albersUsa.scale = function(_) {
|
12495 | if (!arguments.length) return lower48.scale();
|
12496 | lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
|
12497 | return albersUsa.translate(lower48.translate());
|
12498 | };
|
12499 |
|
12500 | albersUsa.translate = function(_) {
|
12501 | if (!arguments.length) return lower48.translate();
|
12502 | var k = lower48.scale(), x = +_[0], y = +_[1];
|
12503 |
|
12504 | lower48Point = lower48
|
12505 | .translate(_)
|
12506 | .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
|
12507 | .stream(pointStream);
|
12508 |
|
12509 | alaskaPoint = alaska
|
12510 | .translate([x - 0.307 * k, y + 0.201 * k])
|
12511 | .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]])
|
12512 | .stream(pointStream);
|
12513 |
|
12514 | hawaiiPoint = hawaii
|
12515 | .translate([x - 0.205 * k, y + 0.212 * k])
|
12516 | .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]])
|
12517 | .stream(pointStream);
|
12518 |
|
12519 | return reset();
|
12520 | };
|
12521 |
|
12522 | albersUsa.fitExtent = function(extent, object) {
|
12523 | return fitExtent(albersUsa, extent, object);
|
12524 | };
|
12525 |
|
12526 | albersUsa.fitSize = function(size, object) {
|
12527 | return fitSize(albersUsa, size, object);
|
12528 | };
|
12529 |
|
12530 | albersUsa.fitWidth = function(width, object) {
|
12531 | return fitWidth(albersUsa, width, object);
|
12532 | };
|
12533 |
|
12534 | albersUsa.fitHeight = function(height, object) {
|
12535 | return fitHeight(albersUsa, height, object);
|
12536 | };
|
12537 |
|
12538 | function reset() {
|
12539 | cache = cacheStream = null;
|
12540 | return albersUsa;
|
12541 | }
|
12542 |
|
12543 | return albersUsa.scale(1070);
|
12544 | }
|
12545 |
|
12546 | function azimuthalRaw(scale) {
|
12547 | return function(x, y) {
|
12548 | var cx = cos$1(x),
|
12549 | cy = cos$1(y),
|
12550 | k = scale(cx * cy);
|
12551 | if (k === Infinity) return [2, 0];
|
12552 | return [
|
12553 | k * cy * sin$1(x),
|
12554 | k * sin$1(y)
|
12555 | ];
|
12556 | }
|
12557 | }
|
12558 |
|
12559 | function azimuthalInvert(angle) {
|
12560 | return function(x, y) {
|
12561 | var z = sqrt$2(x * x + y * y),
|
12562 | c = angle(z),
|
12563 | sc = sin$1(c),
|
12564 | cc = cos$1(c);
|
12565 | return [
|
12566 | atan2$1(x * sc, z * cc),
|
12567 | asin$1(z && y * sc / z)
|
12568 | ];
|
12569 | }
|
12570 | }
|
12571 |
|
12572 | var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
|
12573 | return sqrt$2(2 / (1 + cxcy));
|
12574 | });
|
12575 |
|
12576 | azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
|
12577 | return 2 * asin$1(z / 2);
|
12578 | });
|
12579 |
|
12580 | function azimuthalEqualArea() {
|
12581 | return projection(azimuthalEqualAreaRaw)
|
12582 | .scale(124.75)
|
12583 | .clipAngle(180 - 1e-3);
|
12584 | }
|
12585 |
|
12586 | var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
|
12587 | return (c = acos$1(c)) && c / sin$1(c);
|
12588 | });
|
12589 |
|
12590 | azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
|
12591 | return z;
|
12592 | });
|
12593 |
|
12594 | function azimuthalEquidistant() {
|
12595 | return projection(azimuthalEquidistantRaw)
|
12596 | .scale(79.4188)
|
12597 | .clipAngle(180 - 1e-3);
|
12598 | }
|
12599 |
|
12600 | function mercatorRaw(lambda, phi) {
|
12601 | return [lambda, log$1(tan((halfPi$1 + phi) / 2))];
|
12602 | }
|
12603 |
|
12604 | mercatorRaw.invert = function(x, y) {
|
12605 | return [x, 2 * atan(exp(y)) - halfPi$1];
|
12606 | };
|
12607 |
|
12608 | function mercator() {
|
12609 | return mercatorProjection(mercatorRaw)
|
12610 | .scale(961 / tau$1);
|
12611 | }
|
12612 |
|
12613 | function mercatorProjection(project) {
|
12614 | var m = projection(project),
|
12615 | center = m.center,
|
12616 | scale = m.scale,
|
12617 | translate = m.translate,
|
12618 | clipExtent = m.clipExtent,
|
12619 | x0 = null, y0, x1, y1; // clip extent
|
12620 |
|
12621 | m.scale = function(_) {
|
12622 | return arguments.length ? (scale(_), reclip()) : scale();
|
12623 | };
|
12624 |
|
12625 | m.translate = function(_) {
|
12626 | return arguments.length ? (translate(_), reclip()) : translate();
|
12627 | };
|
12628 |
|
12629 | m.center = function(_) {
|
12630 | return arguments.length ? (center(_), reclip()) : center();
|
12631 | };
|
12632 |
|
12633 | m.clipExtent = function(_) {
|
12634 | 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]];
|
12635 | };
|
12636 |
|
12637 | function reclip() {
|
12638 | var k = pi$1 * scale(),
|
12639 | t = m(rotation(m.rotate()).invert([0, 0]));
|
12640 | return clipExtent(x0 == null
|
12641 | ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
|
12642 | ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
|
12643 | : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
|
12644 | }
|
12645 |
|
12646 | return reclip();
|
12647 | }
|
12648 |
|
12649 | function tany(y) {
|
12650 | return tan((halfPi$1 + y) / 2);
|
12651 | }
|
12652 |
|
12653 | function conicConformalRaw(y0, y1) {
|
12654 | var cy0 = cos$1(y0),
|
12655 | n = y0 === y1 ? sin$1(y0) : log$1(cy0 / cos$1(y1)) / log$1(tany(y1) / tany(y0)),
|
12656 | f = cy0 * pow$1(tany(y0), n) / n;
|
12657 |
|
12658 | if (!n) return mercatorRaw;
|
12659 |
|
12660 | function project(x, y) {
|
12661 | if (f > 0) { if (y < -halfPi$1 + epsilon$1) y = -halfPi$1 + epsilon$1; }
|
12662 | else { if (y > halfPi$1 - epsilon$1) y = halfPi$1 - epsilon$1; }
|
12663 | var r = f / pow$1(tany(y), n);
|
12664 | return [r * sin$1(n * x), f - r * cos$1(n * x)];
|
12665 | }
|
12666 |
|
12667 | project.invert = function(x, y) {
|
12668 | var fy = f - y, r = sign$1(n) * sqrt$2(x * x + fy * fy),
|
12669 | l = atan2$1(x, abs$1(fy)) * sign$1(fy);
|
12670 | if (fy * n < 0)
|
12671 | l -= pi$1 * sign$1(x) * sign$1(fy);
|
12672 | return [l / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$1];
|
12673 | };
|
12674 |
|
12675 | return project;
|
12676 | }
|
12677 |
|
12678 | function conicConformal() {
|
12679 | return conicProjection(conicConformalRaw)
|
12680 | .scale(109.5)
|
12681 | .parallels([30, 30]);
|
12682 | }
|
12683 |
|
12684 | function equirectangularRaw(lambda, phi) {
|
12685 | return [lambda, phi];
|
12686 | }
|
12687 |
|
12688 | equirectangularRaw.invert = equirectangularRaw;
|
12689 |
|
12690 | function equirectangular() {
|
12691 | return projection(equirectangularRaw)
|
12692 | .scale(152.63);
|
12693 | }
|
12694 |
|
12695 | function conicEquidistantRaw(y0, y1) {
|
12696 | var cy0 = cos$1(y0),
|
12697 | n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
|
12698 | g = cy0 / n + y0;
|
12699 |
|
12700 | if (abs$1(n) < epsilon$1) return equirectangularRaw;
|
12701 |
|
12702 | function project(x, y) {
|
12703 | var gy = g - y, nx = n * x;
|
12704 | return [gy * sin$1(nx), g - gy * cos$1(nx)];
|
12705 | }
|
12706 |
|
12707 | project.invert = function(x, y) {
|
12708 | var gy = g - y,
|
12709 | l = atan2$1(x, abs$1(gy)) * sign$1(gy);
|
12710 | if (gy * n < 0)
|
12711 | l -= pi$1 * sign$1(x) * sign$1(gy);
|
12712 | return [l / n, g - sign$1(n) * sqrt$2(x * x + gy * gy)];
|
12713 | };
|
12714 |
|
12715 | return project;
|
12716 | }
|
12717 |
|
12718 | function conicEquidistant() {
|
12719 | return conicProjection(conicEquidistantRaw)
|
12720 | .scale(131.154)
|
12721 | .center([0, 13.9389]);
|
12722 | }
|
12723 |
|
12724 | var A1 = 1.340264,
|
12725 | A2 = -0.081106,
|
12726 | A3 = 0.000893,
|
12727 | A4 = 0.003796,
|
12728 | M = sqrt$2(3) / 2,
|
12729 | iterations = 12;
|
12730 |
|
12731 | function equalEarthRaw(lambda, phi) {
|
12732 | var l = asin$1(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
|
12733 | return [
|
12734 | lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
|
12735 | l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
|
12736 | ];
|
12737 | }
|
12738 |
|
12739 | equalEarthRaw.invert = function(x, y) {
|
12740 | var l = y, l2 = l * l, l6 = l2 * l2 * l2;
|
12741 | for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
|
12742 | fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
|
12743 | fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
|
12744 | l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
|
12745 | if (abs$1(delta) < epsilon2) break;
|
12746 | }
|
12747 | return [
|
12748 | M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
|
12749 | asin$1(sin$1(l) / M)
|
12750 | ];
|
12751 | };
|
12752 |
|
12753 | function equalEarth() {
|
12754 | return projection(equalEarthRaw)
|
12755 | .scale(177.158);
|
12756 | }
|
12757 |
|
12758 | function gnomonicRaw(x, y) {
|
12759 | var cy = cos$1(y), k = cos$1(x) * cy;
|
12760 | return [cy * sin$1(x) / k, sin$1(y) / k];
|
12761 | }
|
12762 |
|
12763 | gnomonicRaw.invert = azimuthalInvert(atan);
|
12764 |
|
12765 | function gnomonic() {
|
12766 | return projection(gnomonicRaw)
|
12767 | .scale(144.049)
|
12768 | .clipAngle(60);
|
12769 | }
|
12770 |
|
12771 | function identity$4() {
|
12772 | var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect
|
12773 | alpha = 0, ca, sa, // angle
|
12774 | x0 = null, y0, x1, y1, // clip extent
|
12775 | kx = 1, ky = 1,
|
12776 | transform = transformer$3({
|
12777 | point: function(x, y) {
|
12778 | var p = projection([x, y]);
|
12779 | this.stream.point(p[0], p[1]);
|
12780 | }
|
12781 | }),
|
12782 | postclip = identity$5,
|
12783 | cache,
|
12784 | cacheStream;
|
12785 |
|
12786 | function reset() {
|
12787 | kx = k * sx;
|
12788 | ky = k * sy;
|
12789 | cache = cacheStream = null;
|
12790 | return projection;
|
12791 | }
|
12792 |
|
12793 | function projection (p) {
|
12794 | var x = p[0] * kx, y = p[1] * ky;
|
12795 | if (alpha) {
|
12796 | var t = y * ca - x * sa;
|
12797 | x = x * ca + y * sa;
|
12798 | y = t;
|
12799 | }
|
12800 | return [x + tx, y + ty];
|
12801 | }
|
12802 | projection.invert = function(p) {
|
12803 | var x = p[0] - tx, y = p[1] - ty;
|
12804 | if (alpha) {
|
12805 | var t = y * ca + x * sa;
|
12806 | x = x * ca - y * sa;
|
12807 | y = t;
|
12808 | }
|
12809 | return [x / kx, y / ky];
|
12810 | };
|
12811 | projection.stream = function(stream) {
|
12812 | return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
|
12813 | };
|
12814 | projection.postclip = function(_) {
|
12815 | return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
|
12816 | };
|
12817 | projection.clipExtent = function(_) {
|
12818 | 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]];
|
12819 | };
|
12820 | projection.scale = function(_) {
|
12821 | return arguments.length ? (k = +_, reset()) : k;
|
12822 | };
|
12823 | projection.translate = function(_) {
|
12824 | return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty];
|
12825 | };
|
12826 | projection.angle = function(_) {
|
12827 | return arguments.length ? (alpha = _ % 360 * radians, sa = sin$1(alpha), ca = cos$1(alpha), reset()) : alpha * degrees;
|
12828 | };
|
12829 | projection.reflectX = function(_) {
|
12830 | return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0;
|
12831 | };
|
12832 | projection.reflectY = function(_) {
|
12833 | return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0;
|
12834 | };
|
12835 | projection.fitExtent = function(extent, object) {
|
12836 | return fitExtent(projection, extent, object);
|
12837 | };
|
12838 | projection.fitSize = function(size, object) {
|
12839 | return fitSize(projection, size, object);
|
12840 | };
|
12841 | projection.fitWidth = function(width, object) {
|
12842 | return fitWidth(projection, width, object);
|
12843 | };
|
12844 | projection.fitHeight = function(height, object) {
|
12845 | return fitHeight(projection, height, object);
|
12846 | };
|
12847 |
|
12848 | return projection;
|
12849 | }
|
12850 |
|
12851 | function naturalEarth1Raw(lambda, phi) {
|
12852 | var phi2 = phi * phi, phi4 = phi2 * phi2;
|
12853 | return [
|
12854 | lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
|
12855 | phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
|
12856 | ];
|
12857 | }
|
12858 |
|
12859 | naturalEarth1Raw.invert = function(x, y) {
|
12860 | var phi = y, i = 25, delta;
|
12861 | do {
|
12862 | var phi2 = phi * phi, phi4 = phi2 * phi2;
|
12863 | phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
|
12864 | (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
|
12865 | } while (abs$1(delta) > epsilon$1 && --i > 0);
|
12866 | return [
|
12867 | x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
|
12868 | phi
|
12869 | ];
|
12870 | };
|
12871 |
|
12872 | function naturalEarth1() {
|
12873 | return projection(naturalEarth1Raw)
|
12874 | .scale(175.295);
|
12875 | }
|
12876 |
|
12877 | function orthographicRaw(x, y) {
|
12878 | return [cos$1(y) * sin$1(x), sin$1(y)];
|
12879 | }
|
12880 |
|
12881 | orthographicRaw.invert = azimuthalInvert(asin$1);
|
12882 |
|
12883 | function orthographic() {
|
12884 | return projection(orthographicRaw)
|
12885 | .scale(249.5)
|
12886 | .clipAngle(90 + epsilon$1);
|
12887 | }
|
12888 |
|
12889 | function stereographicRaw(x, y) {
|
12890 | var cy = cos$1(y), k = 1 + cos$1(x) * cy;
|
12891 | return [cy * sin$1(x) / k, sin$1(y) / k];
|
12892 | }
|
12893 |
|
12894 | stereographicRaw.invert = azimuthalInvert(function(z) {
|
12895 | return 2 * atan(z);
|
12896 | });
|
12897 |
|
12898 | function stereographic() {
|
12899 | return projection(stereographicRaw)
|
12900 | .scale(250)
|
12901 | .clipAngle(142);
|
12902 | }
|
12903 |
|
12904 | function transverseMercatorRaw(lambda, phi) {
|
12905 | return [log$1(tan((halfPi$1 + phi) / 2)), -lambda];
|
12906 | }
|
12907 |
|
12908 | transverseMercatorRaw.invert = function(x, y) {
|
12909 | return [-y, 2 * atan(exp(x)) - halfPi$1];
|
12910 | };
|
12911 |
|
12912 | function transverseMercator() {
|
12913 | var m = mercatorProjection(transverseMercatorRaw),
|
12914 | center = m.center,
|
12915 | rotate = m.rotate;
|
12916 |
|
12917 | m.center = function(_) {
|
12918 | return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
|
12919 | };
|
12920 |
|
12921 | m.rotate = function(_) {
|
12922 | return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
|
12923 | };
|
12924 |
|
12925 | return rotate([0, 0, 90])
|
12926 | .scale(159.155);
|
12927 | }
|
12928 |
|
12929 | function defaultSeparation$1(a, b) {
|
12930 | return a.parent === b.parent ? 1 : 2;
|
12931 | }
|
12932 |
|
12933 | function meanX(children) {
|
12934 | return children.reduce(meanXReduce, 0) / children.length;
|
12935 | }
|
12936 |
|
12937 | function meanXReduce(x, c) {
|
12938 | return x + c.x;
|
12939 | }
|
12940 |
|
12941 | function maxY(children) {
|
12942 | return 1 + children.reduce(maxYReduce, 0);
|
12943 | }
|
12944 |
|
12945 | function maxYReduce(y, c) {
|
12946 | return Math.max(y, c.y);
|
12947 | }
|
12948 |
|
12949 | function leafLeft(node) {
|
12950 | var children;
|
12951 | while (children = node.children) node = children[0];
|
12952 | return node;
|
12953 | }
|
12954 |
|
12955 | function leafRight(node) {
|
12956 | var children;
|
12957 | while (children = node.children) node = children[children.length - 1];
|
12958 | return node;
|
12959 | }
|
12960 |
|
12961 | function cluster() {
|
12962 | var separation = defaultSeparation$1,
|
12963 | dx = 1,
|
12964 | dy = 1,
|
12965 | nodeSize = false;
|
12966 |
|
12967 | function cluster(root) {
|
12968 | var previousNode,
|
12969 | x = 0;
|
12970 |
|
12971 | // First walk, computing the initial x & y values.
|
12972 | root.eachAfter(function(node) {
|
12973 | var children = node.children;
|
12974 | if (children) {
|
12975 | node.x = meanX(children);
|
12976 | node.y = maxY(children);
|
12977 | } else {
|
12978 | node.x = previousNode ? x += separation(node, previousNode) : 0;
|
12979 | node.y = 0;
|
12980 | previousNode = node;
|
12981 | }
|
12982 | });
|
12983 |
|
12984 | var left = leafLeft(root),
|
12985 | right = leafRight(root),
|
12986 | x0 = left.x - separation(left, right) / 2,
|
12987 | x1 = right.x + separation(right, left) / 2;
|
12988 |
|
12989 | // Second walk, normalizing x & y to the desired size.
|
12990 | return root.eachAfter(nodeSize ? function(node) {
|
12991 | node.x = (node.x - root.x) * dx;
|
12992 | node.y = (root.y - node.y) * dy;
|
12993 | } : function(node) {
|
12994 | node.x = (node.x - x0) / (x1 - x0) * dx;
|
12995 | node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
|
12996 | });
|
12997 | }
|
12998 |
|
12999 | cluster.separation = function(x) {
|
13000 | return arguments.length ? (separation = x, cluster) : separation;
|
13001 | };
|
13002 |
|
13003 | cluster.size = function(x) {
|
13004 | return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
|
13005 | };
|
13006 |
|
13007 | cluster.nodeSize = function(x) {
|
13008 | return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
|
13009 | };
|
13010 |
|
13011 | return cluster;
|
13012 | }
|
13013 |
|
13014 | function count(node) {
|
13015 | var sum = 0,
|
13016 | children = node.children,
|
13017 | i = children && children.length;
|
13018 | if (!i) sum = 1;
|
13019 | else while (--i >= 0) sum += children[i].value;
|
13020 | node.value = sum;
|
13021 | }
|
13022 |
|
13023 | function node_count() {
|
13024 | return this.eachAfter(count);
|
13025 | }
|
13026 |
|
13027 | function node_each(callback, that) {
|
13028 | let index = -1;
|
13029 | for (const node of this) {
|
13030 | callback.call(that, node, ++index, this);
|
13031 | }
|
13032 | return this;
|
13033 | }
|
13034 |
|
13035 | function node_eachBefore(callback, that) {
|
13036 | var node = this, nodes = [node], children, i, index = -1;
|
13037 | while (node = nodes.pop()) {
|
13038 | callback.call(that, node, ++index, this);
|
13039 | if (children = node.children) {
|
13040 | for (i = children.length - 1; i >= 0; --i) {
|
13041 | nodes.push(children[i]);
|
13042 | }
|
13043 | }
|
13044 | }
|
13045 | return this;
|
13046 | }
|
13047 |
|
13048 | function node_eachAfter(callback, that) {
|
13049 | var node = this, nodes = [node], next = [], children, i, n, index = -1;
|
13050 | while (node = nodes.pop()) {
|
13051 | next.push(node);
|
13052 | if (children = node.children) {
|
13053 | for (i = 0, n = children.length; i < n; ++i) {
|
13054 | nodes.push(children[i]);
|
13055 | }
|
13056 | }
|
13057 | }
|
13058 | while (node = next.pop()) {
|
13059 | callback.call(that, node, ++index, this);
|
13060 | }
|
13061 | return this;
|
13062 | }
|
13063 |
|
13064 | function node_find(callback, that) {
|
13065 | let index = -1;
|
13066 | for (const node of this) {
|
13067 | if (callback.call(that, node, ++index, this)) {
|
13068 | return node;
|
13069 | }
|
13070 | }
|
13071 | }
|
13072 |
|
13073 | function node_sum(value) {
|
13074 | return this.eachAfter(function(node) {
|
13075 | var sum = +value(node.data) || 0,
|
13076 | children = node.children,
|
13077 | i = children && children.length;
|
13078 | while (--i >= 0) sum += children[i].value;
|
13079 | node.value = sum;
|
13080 | });
|
13081 | }
|
13082 |
|
13083 | function node_sort(compare) {
|
13084 | return this.eachBefore(function(node) {
|
13085 | if (node.children) {
|
13086 | node.children.sort(compare);
|
13087 | }
|
13088 | });
|
13089 | }
|
13090 |
|
13091 | function node_path(end) {
|
13092 | var start = this,
|
13093 | ancestor = leastCommonAncestor(start, end),
|
13094 | nodes = [start];
|
13095 | while (start !== ancestor) {
|
13096 | start = start.parent;
|
13097 | nodes.push(start);
|
13098 | }
|
13099 | var k = nodes.length;
|
13100 | while (end !== ancestor) {
|
13101 | nodes.splice(k, 0, end);
|
13102 | end = end.parent;
|
13103 | }
|
13104 | return nodes;
|
13105 | }
|
13106 |
|
13107 | function leastCommonAncestor(a, b) {
|
13108 | if (a === b) return a;
|
13109 | var aNodes = a.ancestors(),
|
13110 | bNodes = b.ancestors(),
|
13111 | c = null;
|
13112 | a = aNodes.pop();
|
13113 | b = bNodes.pop();
|
13114 | while (a === b) {
|
13115 | c = a;
|
13116 | a = aNodes.pop();
|
13117 | b = bNodes.pop();
|
13118 | }
|
13119 | return c;
|
13120 | }
|
13121 |
|
13122 | function node_ancestors() {
|
13123 | var node = this, nodes = [node];
|
13124 | while (node = node.parent) {
|
13125 | nodes.push(node);
|
13126 | }
|
13127 | return nodes;
|
13128 | }
|
13129 |
|
13130 | function node_descendants() {
|
13131 | return Array.from(this);
|
13132 | }
|
13133 |
|
13134 | function node_leaves() {
|
13135 | var leaves = [];
|
13136 | this.eachBefore(function(node) {
|
13137 | if (!node.children) {
|
13138 | leaves.push(node);
|
13139 | }
|
13140 | });
|
13141 | return leaves;
|
13142 | }
|
13143 |
|
13144 | function node_links() {
|
13145 | var root = this, links = [];
|
13146 | root.each(function(node) {
|
13147 | if (node !== root) { // Don’t include the root’s parent, if any.
|
13148 | links.push({source: node.parent, target: node});
|
13149 | }
|
13150 | });
|
13151 | return links;
|
13152 | }
|
13153 |
|
13154 | function* node_iterator() {
|
13155 | var node = this, current, next = [node], children, i, n;
|
13156 | do {
|
13157 | current = next.reverse(), next = [];
|
13158 | while (node = current.pop()) {
|
13159 | yield node;
|
13160 | if (children = node.children) {
|
13161 | for (i = 0, n = children.length; i < n; ++i) {
|
13162 | next.push(children[i]);
|
13163 | }
|
13164 | }
|
13165 | }
|
13166 | } while (next.length);
|
13167 | }
|
13168 |
|
13169 | function hierarchy(data, children) {
|
13170 | if (data instanceof Map) {
|
13171 | data = [undefined, data];
|
13172 | if (children === undefined) children = mapChildren;
|
13173 | } else if (children === undefined) {
|
13174 | children = objectChildren;
|
13175 | }
|
13176 |
|
13177 | var root = new Node$1(data),
|
13178 | node,
|
13179 | nodes = [root],
|
13180 | child,
|
13181 | childs,
|
13182 | i,
|
13183 | n;
|
13184 |
|
13185 | while (node = nodes.pop()) {
|
13186 | if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
|
13187 | node.children = childs;
|
13188 | for (i = n - 1; i >= 0; --i) {
|
13189 | nodes.push(child = childs[i] = new Node$1(childs[i]));
|
13190 | child.parent = node;
|
13191 | child.depth = node.depth + 1;
|
13192 | }
|
13193 | }
|
13194 | }
|
13195 |
|
13196 | return root.eachBefore(computeHeight);
|
13197 | }
|
13198 |
|
13199 | function node_copy() {
|
13200 | return hierarchy(this).eachBefore(copyData);
|
13201 | }
|
13202 |
|
13203 | function objectChildren(d) {
|
13204 | return d.children;
|
13205 | }
|
13206 |
|
13207 | function mapChildren(d) {
|
13208 | return Array.isArray(d) ? d[1] : null;
|
13209 | }
|
13210 |
|
13211 | function copyData(node) {
|
13212 | if (node.data.value !== undefined) node.value = node.data.value;
|
13213 | node.data = node.data.data;
|
13214 | }
|
13215 |
|
13216 | function computeHeight(node) {
|
13217 | var height = 0;
|
13218 | do node.height = height;
|
13219 | while ((node = node.parent) && (node.height < ++height));
|
13220 | }
|
13221 |
|
13222 | function Node$1(data) {
|
13223 | this.data = data;
|
13224 | this.depth =
|
13225 | this.height = 0;
|
13226 | this.parent = null;
|
13227 | }
|
13228 |
|
13229 | Node$1.prototype = hierarchy.prototype = {
|
13230 | constructor: Node$1,
|
13231 | count: node_count,
|
13232 | each: node_each,
|
13233 | eachAfter: node_eachAfter,
|
13234 | eachBefore: node_eachBefore,
|
13235 | find: node_find,
|
13236 | sum: node_sum,
|
13237 | sort: node_sort,
|
13238 | path: node_path,
|
13239 | ancestors: node_ancestors,
|
13240 | descendants: node_descendants,
|
13241 | leaves: node_leaves,
|
13242 | links: node_links,
|
13243 | copy: node_copy,
|
13244 | [Symbol.iterator]: node_iterator
|
13245 | };
|
13246 |
|
13247 | function optional(f) {
|
13248 | return f == null ? null : required(f);
|
13249 | }
|
13250 |
|
13251 | function required(f) {
|
13252 | if (typeof f !== "function") throw new Error;
|
13253 | return f;
|
13254 | }
|
13255 |
|
13256 | function constantZero() {
|
13257 | return 0;
|
13258 | }
|
13259 |
|
13260 | function constant$2(x) {
|
13261 | return function() {
|
13262 | return x;
|
13263 | };
|
13264 | }
|
13265 |
|
13266 | // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
|
13267 | const a$1 = 1664525;
|
13268 | const c$3 = 1013904223;
|
13269 | const m = 4294967296; // 2^32
|
13270 |
|
13271 | function lcg$1() {
|
13272 | let s = 1;
|
13273 | return () => (s = (a$1 * s + c$3) % m) / m;
|
13274 | }
|
13275 |
|
13276 | function array$1(x) {
|
13277 | return typeof x === "object" && "length" in x
|
13278 | ? x // Array, TypedArray, NodeList, array-like
|
13279 | : Array.from(x); // Map, Set, iterable, string, or anything else
|
13280 | }
|
13281 |
|
13282 | function shuffle(array, random) {
|
13283 | let m = array.length,
|
13284 | t,
|
13285 | i;
|
13286 |
|
13287 | while (m) {
|
13288 | i = random() * m-- | 0;
|
13289 | t = array[m];
|
13290 | array[m] = array[i];
|
13291 | array[i] = t;
|
13292 | }
|
13293 |
|
13294 | return array;
|
13295 | }
|
13296 |
|
13297 | function enclose(circles) {
|
13298 | return packEncloseRandom(circles, lcg$1());
|
13299 | }
|
13300 |
|
13301 | function packEncloseRandom(circles, random) {
|
13302 | var i = 0, n = (circles = shuffle(Array.from(circles), random)).length, B = [], p, e;
|
13303 |
|
13304 | while (i < n) {
|
13305 | p = circles[i];
|
13306 | if (e && enclosesWeak(e, p)) ++i;
|
13307 | else e = encloseBasis(B = extendBasis(B, p)), i = 0;
|
13308 | }
|
13309 |
|
13310 | return e;
|
13311 | }
|
13312 |
|
13313 | function extendBasis(B, p) {
|
13314 | var i, j;
|
13315 |
|
13316 | if (enclosesWeakAll(p, B)) return [p];
|
13317 |
|
13318 | // If we get here then B must have at least one element.
|
13319 | for (i = 0; i < B.length; ++i) {
|
13320 | if (enclosesNot(p, B[i])
|
13321 | && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
|
13322 | return [B[i], p];
|
13323 | }
|
13324 | }
|
13325 |
|
13326 | // If we get here then B must have at least two elements.
|
13327 | for (i = 0; i < B.length - 1; ++i) {
|
13328 | for (j = i + 1; j < B.length; ++j) {
|
13329 | if (enclosesNot(encloseBasis2(B[i], B[j]), p)
|
13330 | && enclosesNot(encloseBasis2(B[i], p), B[j])
|
13331 | && enclosesNot(encloseBasis2(B[j], p), B[i])
|
13332 | && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
|
13333 | return [B[i], B[j], p];
|
13334 | }
|
13335 | }
|
13336 | }
|
13337 |
|
13338 | // If we get here then something is very wrong.
|
13339 | throw new Error;
|
13340 | }
|
13341 |
|
13342 | function enclosesNot(a, b) {
|
13343 | var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
|
13344 | return dr < 0 || dr * dr < dx * dx + dy * dy;
|
13345 | }
|
13346 |
|
13347 | function enclosesWeak(a, b) {
|
13348 | 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;
|
13349 | return dr > 0 && dr * dr > dx * dx + dy * dy;
|
13350 | }
|
13351 |
|
13352 | function enclosesWeakAll(a, B) {
|
13353 | for (var i = 0; i < B.length; ++i) {
|
13354 | if (!enclosesWeak(a, B[i])) {
|
13355 | return false;
|
13356 | }
|
13357 | }
|
13358 | return true;
|
13359 | }
|
13360 |
|
13361 | function encloseBasis(B) {
|
13362 | switch (B.length) {
|
13363 | case 1: return encloseBasis1(B[0]);
|
13364 | case 2: return encloseBasis2(B[0], B[1]);
|
13365 | case 3: return encloseBasis3(B[0], B[1], B[2]);
|
13366 | }
|
13367 | }
|
13368 |
|
13369 | function encloseBasis1(a) {
|
13370 | return {
|
13371 | x: a.x,
|
13372 | y: a.y,
|
13373 | r: a.r
|
13374 | };
|
13375 | }
|
13376 |
|
13377 | function encloseBasis2(a, b) {
|
13378 | var x1 = a.x, y1 = a.y, r1 = a.r,
|
13379 | x2 = b.x, y2 = b.y, r2 = b.r,
|
13380 | x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
|
13381 | l = Math.sqrt(x21 * x21 + y21 * y21);
|
13382 | return {
|
13383 | x: (x1 + x2 + x21 / l * r21) / 2,
|
13384 | y: (y1 + y2 + y21 / l * r21) / 2,
|
13385 | r: (l + r1 + r2) / 2
|
13386 | };
|
13387 | }
|
13388 |
|
13389 | function encloseBasis3(a, b, c) {
|
13390 | var x1 = a.x, y1 = a.y, r1 = a.r,
|
13391 | x2 = b.x, y2 = b.y, r2 = b.r,
|
13392 | x3 = c.x, y3 = c.y, r3 = c.r,
|
13393 | a2 = x1 - x2,
|
13394 | a3 = x1 - x3,
|
13395 | b2 = y1 - y2,
|
13396 | b3 = y1 - y3,
|
13397 | c2 = r2 - r1,
|
13398 | c3 = r3 - r1,
|
13399 | d1 = x1 * x1 + y1 * y1 - r1 * r1,
|
13400 | d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
|
13401 | d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
|
13402 | ab = a3 * b2 - a2 * b3,
|
13403 | xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
|
13404 | xb = (b3 * c2 - b2 * c3) / ab,
|
13405 | ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
|
13406 | yb = (a2 * c3 - a3 * c2) / ab,
|
13407 | A = xb * xb + yb * yb - 1,
|
13408 | B = 2 * (r1 + xa * xb + ya * yb),
|
13409 | C = xa * xa + ya * ya - r1 * r1,
|
13410 | r = -(Math.abs(A) > 1e-6 ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
|
13411 | return {
|
13412 | x: x1 + xa + xb * r,
|
13413 | y: y1 + ya + yb * r,
|
13414 | r: r
|
13415 | };
|
13416 | }
|
13417 |
|
13418 | function place(b, a, c) {
|
13419 | var dx = b.x - a.x, x, a2,
|
13420 | dy = b.y - a.y, y, b2,
|
13421 | d2 = dx * dx + dy * dy;
|
13422 | if (d2) {
|
13423 | a2 = a.r + c.r, a2 *= a2;
|
13424 | b2 = b.r + c.r, b2 *= b2;
|
13425 | if (a2 > b2) {
|
13426 | x = (d2 + b2 - a2) / (2 * d2);
|
13427 | y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
|
13428 | c.x = b.x - x * dx - y * dy;
|
13429 | c.y = b.y - x * dy + y * dx;
|
13430 | } else {
|
13431 | x = (d2 + a2 - b2) / (2 * d2);
|
13432 | y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
|
13433 | c.x = a.x + x * dx - y * dy;
|
13434 | c.y = a.y + x * dy + y * dx;
|
13435 | }
|
13436 | } else {
|
13437 | c.x = a.x + c.r;
|
13438 | c.y = a.y;
|
13439 | }
|
13440 | }
|
13441 |
|
13442 | function intersects(a, b) {
|
13443 | var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
|
13444 | return dr > 0 && dr * dr > dx * dx + dy * dy;
|
13445 | }
|
13446 |
|
13447 | function score(node) {
|
13448 | var a = node._,
|
13449 | b = node.next._,
|
13450 | ab = a.r + b.r,
|
13451 | dx = (a.x * b.r + b.x * a.r) / ab,
|
13452 | dy = (a.y * b.r + b.y * a.r) / ab;
|
13453 | return dx * dx + dy * dy;
|
13454 | }
|
13455 |
|
13456 | function Node(circle) {
|
13457 | this._ = circle;
|
13458 | this.next = null;
|
13459 | this.previous = null;
|
13460 | }
|
13461 |
|
13462 | function packSiblingsRandom(circles, random) {
|
13463 | if (!(n = (circles = array$1(circles)).length)) return 0;
|
13464 |
|
13465 | var a, b, c, n, aa, ca, i, j, k, sj, sk;
|
13466 |
|
13467 | // Place the first circle.
|
13468 | a = circles[0], a.x = 0, a.y = 0;
|
13469 | if (!(n > 1)) return a.r;
|
13470 |
|
13471 | // Place the second circle.
|
13472 | b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
|
13473 | if (!(n > 2)) return a.r + b.r;
|
13474 |
|
13475 | // Place the third circle.
|
13476 | place(b, a, c = circles[2]);
|
13477 |
|
13478 | // Initialize the front-chain using the first three circles a, b and c.
|
13479 | a = new Node(a), b = new Node(b), c = new Node(c);
|
13480 | a.next = c.previous = b;
|
13481 | b.next = a.previous = c;
|
13482 | c.next = b.previous = a;
|
13483 |
|
13484 | // Attempt to place each remaining circle…
|
13485 | pack: for (i = 3; i < n; ++i) {
|
13486 | place(a._, b._, c = circles[i]), c = new Node(c);
|
13487 |
|
13488 | // Find the closest intersecting circle on the front-chain, if any.
|
13489 | // “Closeness” is determined by linear distance along the front-chain.
|
13490 | // “Ahead” or “behind” is likewise determined by linear distance.
|
13491 | j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
|
13492 | do {
|
13493 | if (sj <= sk) {
|
13494 | if (intersects(j._, c._)) {
|
13495 | b = j, a.next = b, b.previous = a, --i;
|
13496 | continue pack;
|
13497 | }
|
13498 | sj += j._.r, j = j.next;
|
13499 | } else {
|
13500 | if (intersects(k._, c._)) {
|
13501 | a = k, a.next = b, b.previous = a, --i;
|
13502 | continue pack;
|
13503 | }
|
13504 | sk += k._.r, k = k.previous;
|
13505 | }
|
13506 | } while (j !== k.next);
|
13507 |
|
13508 | // Success! Insert the new circle c between a and b.
|
13509 | c.previous = a, c.next = b, a.next = b.previous = b = c;
|
13510 |
|
13511 | // Compute the new closest circle pair to the centroid.
|
13512 | aa = score(a);
|
13513 | while ((c = c.next) !== b) {
|
13514 | if ((ca = score(c)) < aa) {
|
13515 | a = c, aa = ca;
|
13516 | }
|
13517 | }
|
13518 | b = a.next;
|
13519 | }
|
13520 |
|
13521 | // Compute the enclosing circle of the front chain.
|
13522 | a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = packEncloseRandom(a, random);
|
13523 |
|
13524 | // Translate the circles to put the enclosing circle around the origin.
|
13525 | for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
|
13526 |
|
13527 | return c.r;
|
13528 | }
|
13529 |
|
13530 | function siblings(circles) {
|
13531 | packSiblingsRandom(circles, lcg$1());
|
13532 | return circles;
|
13533 | }
|
13534 |
|
13535 | function defaultRadius(d) {
|
13536 | return Math.sqrt(d.value);
|
13537 | }
|
13538 |
|
13539 | function index$1() {
|
13540 | var radius = null,
|
13541 | dx = 1,
|
13542 | dy = 1,
|
13543 | padding = constantZero;
|
13544 |
|
13545 | function pack(root) {
|
13546 | const random = lcg$1();
|
13547 | root.x = dx / 2, root.y = dy / 2;
|
13548 | if (radius) {
|
13549 | root.eachBefore(radiusLeaf(radius))
|
13550 | .eachAfter(packChildrenRandom(padding, 0.5, random))
|
13551 | .eachBefore(translateChild(1));
|
13552 | } else {
|
13553 | root.eachBefore(radiusLeaf(defaultRadius))
|
13554 | .eachAfter(packChildrenRandom(constantZero, 1, random))
|
13555 | .eachAfter(packChildrenRandom(padding, root.r / Math.min(dx, dy), random))
|
13556 | .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
|
13557 | }
|
13558 | return root;
|
13559 | }
|
13560 |
|
13561 | pack.radius = function(x) {
|
13562 | return arguments.length ? (radius = optional(x), pack) : radius;
|
13563 | };
|
13564 |
|
13565 | pack.size = function(x) {
|
13566 | return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
|
13567 | };
|
13568 |
|
13569 | pack.padding = function(x) {
|
13570 | return arguments.length ? (padding = typeof x === "function" ? x : constant$2(+x), pack) : padding;
|
13571 | };
|
13572 |
|
13573 | return pack;
|
13574 | }
|
13575 |
|
13576 | function radiusLeaf(radius) {
|
13577 | return function(node) {
|
13578 | if (!node.children) {
|
13579 | node.r = Math.max(0, +radius(node) || 0);
|
13580 | }
|
13581 | };
|
13582 | }
|
13583 |
|
13584 | function packChildrenRandom(padding, k, random) {
|
13585 | return function(node) {
|
13586 | if (children = node.children) {
|
13587 | var children,
|
13588 | i,
|
13589 | n = children.length,
|
13590 | r = padding(node) * k || 0,
|
13591 | e;
|
13592 |
|
13593 | if (r) for (i = 0; i < n; ++i) children[i].r += r;
|
13594 | e = packSiblingsRandom(children, random);
|
13595 | if (r) for (i = 0; i < n; ++i) children[i].r -= r;
|
13596 | node.r = e + r;
|
13597 | }
|
13598 | };
|
13599 | }
|
13600 |
|
13601 | function translateChild(k) {
|
13602 | return function(node) {
|
13603 | var parent = node.parent;
|
13604 | node.r *= k;
|
13605 | if (parent) {
|
13606 | node.x = parent.x + k * node.x;
|
13607 | node.y = parent.y + k * node.y;
|
13608 | }
|
13609 | };
|
13610 | }
|
13611 |
|
13612 | function roundNode(node) {
|
13613 | node.x0 = Math.round(node.x0);
|
13614 | node.y0 = Math.round(node.y0);
|
13615 | node.x1 = Math.round(node.x1);
|
13616 | node.y1 = Math.round(node.y1);
|
13617 | }
|
13618 |
|
13619 | function treemapDice(parent, x0, y0, x1, y1) {
|
13620 | var nodes = parent.children,
|
13621 | node,
|
13622 | i = -1,
|
13623 | n = nodes.length,
|
13624 | k = parent.value && (x1 - x0) / parent.value;
|
13625 |
|
13626 | while (++i < n) {
|
13627 | node = nodes[i], node.y0 = y0, node.y1 = y1;
|
13628 | node.x0 = x0, node.x1 = x0 += node.value * k;
|
13629 | }
|
13630 | }
|
13631 |
|
13632 | function partition() {
|
13633 | var dx = 1,
|
13634 | dy = 1,
|
13635 | padding = 0,
|
13636 | round = false;
|
13637 |
|
13638 | function partition(root) {
|
13639 | var n = root.height + 1;
|
13640 | root.x0 =
|
13641 | root.y0 = padding;
|
13642 | root.x1 = dx;
|
13643 | root.y1 = dy / n;
|
13644 | root.eachBefore(positionNode(dy, n));
|
13645 | if (round) root.eachBefore(roundNode);
|
13646 | return root;
|
13647 | }
|
13648 |
|
13649 | function positionNode(dy, n) {
|
13650 | return function(node) {
|
13651 | if (node.children) {
|
13652 | treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
|
13653 | }
|
13654 | var x0 = node.x0,
|
13655 | y0 = node.y0,
|
13656 | x1 = node.x1 - padding,
|
13657 | y1 = node.y1 - padding;
|
13658 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
13659 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
13660 | node.x0 = x0;
|
13661 | node.y0 = y0;
|
13662 | node.x1 = x1;
|
13663 | node.y1 = y1;
|
13664 | };
|
13665 | }
|
13666 |
|
13667 | partition.round = function(x) {
|
13668 | return arguments.length ? (round = !!x, partition) : round;
|
13669 | };
|
13670 |
|
13671 | partition.size = function(x) {
|
13672 | return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
|
13673 | };
|
13674 |
|
13675 | partition.padding = function(x) {
|
13676 | return arguments.length ? (padding = +x, partition) : padding;
|
13677 | };
|
13678 |
|
13679 | return partition;
|
13680 | }
|
13681 |
|
13682 | var preroot = {depth: -1},
|
13683 | ambiguous = {},
|
13684 | imputed = {};
|
13685 |
|
13686 | function defaultId(d) {
|
13687 | return d.id;
|
13688 | }
|
13689 |
|
13690 | function defaultParentId(d) {
|
13691 | return d.parentId;
|
13692 | }
|
13693 |
|
13694 | function stratify() {
|
13695 | var id = defaultId,
|
13696 | parentId = defaultParentId,
|
13697 | path;
|
13698 |
|
13699 | function stratify(data) {
|
13700 | var nodes = Array.from(data),
|
13701 | currentId = id,
|
13702 | currentParentId = parentId,
|
13703 | n,
|
13704 | d,
|
13705 | i,
|
13706 | root,
|
13707 | parent,
|
13708 | node,
|
13709 | nodeId,
|
13710 | nodeKey,
|
13711 | nodeByKey = new Map;
|
13712 |
|
13713 | if (path != null) {
|
13714 | const I = nodes.map((d, i) => normalize$1(path(d, i, data)));
|
13715 | const P = I.map(parentof);
|
13716 | const S = new Set(I).add("");
|
13717 | for (const i of P) {
|
13718 | if (!S.has(i)) {
|
13719 | S.add(i);
|
13720 | I.push(i);
|
13721 | P.push(parentof(i));
|
13722 | nodes.push(imputed);
|
13723 | }
|
13724 | }
|
13725 | currentId = (_, i) => I[i];
|
13726 | currentParentId = (_, i) => P[i];
|
13727 | }
|
13728 |
|
13729 | for (i = 0, n = nodes.length; i < n; ++i) {
|
13730 | d = nodes[i], node = nodes[i] = new Node$1(d);
|
13731 | if ((nodeId = currentId(d, i, data)) != null && (nodeId += "")) {
|
13732 | nodeKey = node.id = nodeId;
|
13733 | nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node);
|
13734 | }
|
13735 | if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += "")) {
|
13736 | node.parent = nodeId;
|
13737 | }
|
13738 | }
|
13739 |
|
13740 | for (i = 0; i < n; ++i) {
|
13741 | node = nodes[i];
|
13742 | if (nodeId = node.parent) {
|
13743 | parent = nodeByKey.get(nodeId);
|
13744 | if (!parent) throw new Error("missing: " + nodeId);
|
13745 | if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
|
13746 | if (parent.children) parent.children.push(node);
|
13747 | else parent.children = [node];
|
13748 | node.parent = parent;
|
13749 | } else {
|
13750 | if (root) throw new Error("multiple roots");
|
13751 | root = node;
|
13752 | }
|
13753 | }
|
13754 |
|
13755 | if (!root) throw new Error("no root");
|
13756 |
|
13757 | // When imputing internal nodes, only introduce roots if needed.
|
13758 | // Then replace the imputed marker data with null.
|
13759 | if (path != null) {
|
13760 | while (root.data === imputed && root.children.length === 1) {
|
13761 | root = root.children[0], --n;
|
13762 | }
|
13763 | for (let i = nodes.length - 1; i >= 0; --i) {
|
13764 | node = nodes[i];
|
13765 | if (node.data !== imputed) break;
|
13766 | node.data = null;
|
13767 | }
|
13768 | }
|
13769 |
|
13770 | root.parent = preroot;
|
13771 | root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
|
13772 | root.parent = null;
|
13773 | if (n > 0) throw new Error("cycle");
|
13774 |
|
13775 | return root;
|
13776 | }
|
13777 |
|
13778 | stratify.id = function(x) {
|
13779 | return arguments.length ? (id = optional(x), stratify) : id;
|
13780 | };
|
13781 |
|
13782 | stratify.parentId = function(x) {
|
13783 | return arguments.length ? (parentId = optional(x), stratify) : parentId;
|
13784 | };
|
13785 |
|
13786 | stratify.path = function(x) {
|
13787 | return arguments.length ? (path = optional(x), stratify) : path;
|
13788 | };
|
13789 |
|
13790 | return stratify;
|
13791 | }
|
13792 |
|
13793 | // To normalize a path, we coerce to a string, strip the trailing slash if any
|
13794 | // (as long as the trailing slash is not immediately preceded by another slash),
|
13795 | // and add leading slash if missing.
|
13796 | function normalize$1(path) {
|
13797 | path = `${path}`;
|
13798 | let i = path.length;
|
13799 | if (slash(path, i - 1) && !slash(path, i - 2)) path = path.slice(0, -1);
|
13800 | return path[0] === "/" ? path : `/${path}`;
|
13801 | }
|
13802 |
|
13803 | // Walk backwards to find the first slash that is not the leading slash, e.g.:
|
13804 | // "/foo/bar" ⇥ "/foo", "/foo" ⇥ "/", "/" ↦ "". (The root is special-cased
|
13805 | // because the id of the root must be a truthy value.)
|
13806 | function parentof(path) {
|
13807 | let i = path.length;
|
13808 | if (i < 2) return "";
|
13809 | while (--i > 1) if (slash(path, i)) break;
|
13810 | return path.slice(0, i);
|
13811 | }
|
13812 |
|
13813 | // Slashes can be escaped; to determine whether a slash is a path delimiter, we
|
13814 | // count the number of preceding backslashes escaping the forward slash: an odd
|
13815 | // number indicates an escaped forward slash.
|
13816 | function slash(path, i) {
|
13817 | if (path[i] === "/") {
|
13818 | let k = 0;
|
13819 | while (i > 0 && path[--i] === "\\") ++k;
|
13820 | if ((k & 1) === 0) return true;
|
13821 | }
|
13822 | return false;
|
13823 | }
|
13824 |
|
13825 | function defaultSeparation(a, b) {
|
13826 | return a.parent === b.parent ? 1 : 2;
|
13827 | }
|
13828 |
|
13829 | // function radialSeparation(a, b) {
|
13830 | // return (a.parent === b.parent ? 1 : 2) / a.depth;
|
13831 | // }
|
13832 |
|
13833 | // This function is used to traverse the left contour of a subtree (or
|
13834 | // subforest). It returns the successor of v on this contour. This successor is
|
13835 | // either given by the leftmost child of v or by the thread of v. The function
|
13836 | // returns null if and only if v is on the highest level of its subtree.
|
13837 | function nextLeft(v) {
|
13838 | var children = v.children;
|
13839 | return children ? children[0] : v.t;
|
13840 | }
|
13841 |
|
13842 | // This function works analogously to nextLeft.
|
13843 | function nextRight(v) {
|
13844 | var children = v.children;
|
13845 | return children ? children[children.length - 1] : v.t;
|
13846 | }
|
13847 |
|
13848 | // Shifts the current subtree rooted at w+. This is done by increasing
|
13849 | // prelim(w+) and mod(w+) by shift.
|
13850 | function moveSubtree(wm, wp, shift) {
|
13851 | var change = shift / (wp.i - wm.i);
|
13852 | wp.c -= change;
|
13853 | wp.s += shift;
|
13854 | wm.c += change;
|
13855 | wp.z += shift;
|
13856 | wp.m += shift;
|
13857 | }
|
13858 |
|
13859 | // All other shifts, applied to the smaller subtrees between w- and w+, are
|
13860 | // performed by this function. To prepare the shifts, we have to adjust
|
13861 | // change(w+), shift(w+), and change(w-).
|
13862 | function executeShifts(v) {
|
13863 | var shift = 0,
|
13864 | change = 0,
|
13865 | children = v.children,
|
13866 | i = children.length,
|
13867 | w;
|
13868 | while (--i >= 0) {
|
13869 | w = children[i];
|
13870 | w.z += shift;
|
13871 | w.m += shift;
|
13872 | shift += w.s + (change += w.c);
|
13873 | }
|
13874 | }
|
13875 |
|
13876 | // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
|
13877 | // returns the specified (default) ancestor.
|
13878 | function nextAncestor(vim, v, ancestor) {
|
13879 | return vim.a.parent === v.parent ? vim.a : ancestor;
|
13880 | }
|
13881 |
|
13882 | function TreeNode(node, i) {
|
13883 | this._ = node;
|
13884 | this.parent = null;
|
13885 | this.children = null;
|
13886 | this.A = null; // default ancestor
|
13887 | this.a = this; // ancestor
|
13888 | this.z = 0; // prelim
|
13889 | this.m = 0; // mod
|
13890 | this.c = 0; // change
|
13891 | this.s = 0; // shift
|
13892 | this.t = null; // thread
|
13893 | this.i = i; // number
|
13894 | }
|
13895 |
|
13896 | TreeNode.prototype = Object.create(Node$1.prototype);
|
13897 |
|
13898 | function treeRoot(root) {
|
13899 | var tree = new TreeNode(root, 0),
|
13900 | node,
|
13901 | nodes = [tree],
|
13902 | child,
|
13903 | children,
|
13904 | i,
|
13905 | n;
|
13906 |
|
13907 | while (node = nodes.pop()) {
|
13908 | if (children = node._.children) {
|
13909 | node.children = new Array(n = children.length);
|
13910 | for (i = n - 1; i >= 0; --i) {
|
13911 | nodes.push(child = node.children[i] = new TreeNode(children[i], i));
|
13912 | child.parent = node;
|
13913 | }
|
13914 | }
|
13915 | }
|
13916 |
|
13917 | (tree.parent = new TreeNode(null, 0)).children = [tree];
|
13918 | return tree;
|
13919 | }
|
13920 |
|
13921 | // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
|
13922 | function tree() {
|
13923 | var separation = defaultSeparation,
|
13924 | dx = 1,
|
13925 | dy = 1,
|
13926 | nodeSize = null;
|
13927 |
|
13928 | function tree(root) {
|
13929 | var t = treeRoot(root);
|
13930 |
|
13931 | // Compute the layout using Buchheim et al.’s algorithm.
|
13932 | t.eachAfter(firstWalk), t.parent.m = -t.z;
|
13933 | t.eachBefore(secondWalk);
|
13934 |
|
13935 | // If a fixed node size is specified, scale x and y.
|
13936 | if (nodeSize) root.eachBefore(sizeNode);
|
13937 |
|
13938 | // If a fixed tree size is specified, scale x and y based on the extent.
|
13939 | // Compute the left-most, right-most, and depth-most nodes for extents.
|
13940 | else {
|
13941 | var left = root,
|
13942 | right = root,
|
13943 | bottom = root;
|
13944 | root.eachBefore(function(node) {
|
13945 | if (node.x < left.x) left = node;
|
13946 | if (node.x > right.x) right = node;
|
13947 | if (node.depth > bottom.depth) bottom = node;
|
13948 | });
|
13949 | var s = left === right ? 1 : separation(left, right) / 2,
|
13950 | tx = s - left.x,
|
13951 | kx = dx / (right.x + s + tx),
|
13952 | ky = dy / (bottom.depth || 1);
|
13953 | root.eachBefore(function(node) {
|
13954 | node.x = (node.x + tx) * kx;
|
13955 | node.y = node.depth * ky;
|
13956 | });
|
13957 | }
|
13958 |
|
13959 | return root;
|
13960 | }
|
13961 |
|
13962 | // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
|
13963 | // applied recursively to the children of v, as well as the function
|
13964 | // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
|
13965 | // node v is placed to the midpoint of its outermost children.
|
13966 | function firstWalk(v) {
|
13967 | var children = v.children,
|
13968 | siblings = v.parent.children,
|
13969 | w = v.i ? siblings[v.i - 1] : null;
|
13970 | if (children) {
|
13971 | executeShifts(v);
|
13972 | var midpoint = (children[0].z + children[children.length - 1].z) / 2;
|
13973 | if (w) {
|
13974 | v.z = w.z + separation(v._, w._);
|
13975 | v.m = v.z - midpoint;
|
13976 | } else {
|
13977 | v.z = midpoint;
|
13978 | }
|
13979 | } else if (w) {
|
13980 | v.z = w.z + separation(v._, w._);
|
13981 | }
|
13982 | v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
|
13983 | }
|
13984 |
|
13985 | // Computes all real x-coordinates by summing up the modifiers recursively.
|
13986 | function secondWalk(v) {
|
13987 | v._.x = v.z + v.parent.m;
|
13988 | v.m += v.parent.m;
|
13989 | }
|
13990 |
|
13991 | // The core of the algorithm. Here, a new subtree is combined with the
|
13992 | // previous subtrees. Threads are used to traverse the inside and outside
|
13993 | // contours of the left and right subtree up to the highest common level. The
|
13994 | // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
|
13995 | // superscript o means outside and i means inside, the subscript - means left
|
13996 | // subtree and + means right subtree. For summing up the modifiers along the
|
13997 | // contour, we use respective variables si+, si-, so-, and so+. Whenever two
|
13998 | // nodes of the inside contours conflict, we compute the left one of the
|
13999 | // greatest uncommon ancestors using the function ANCESTOR and call MOVE
|
14000 | // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
|
14001 | // Finally, we add a new thread (if necessary).
|
14002 | function apportion(v, w, ancestor) {
|
14003 | if (w) {
|
14004 | var vip = v,
|
14005 | vop = v,
|
14006 | vim = w,
|
14007 | vom = vip.parent.children[0],
|
14008 | sip = vip.m,
|
14009 | sop = vop.m,
|
14010 | sim = vim.m,
|
14011 | som = vom.m,
|
14012 | shift;
|
14013 | while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
|
14014 | vom = nextLeft(vom);
|
14015 | vop = nextRight(vop);
|
14016 | vop.a = v;
|
14017 | shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
|
14018 | if (shift > 0) {
|
14019 | moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
|
14020 | sip += shift;
|
14021 | sop += shift;
|
14022 | }
|
14023 | sim += vim.m;
|
14024 | sip += vip.m;
|
14025 | som += vom.m;
|
14026 | sop += vop.m;
|
14027 | }
|
14028 | if (vim && !nextRight(vop)) {
|
14029 | vop.t = vim;
|
14030 | vop.m += sim - sop;
|
14031 | }
|
14032 | if (vip && !nextLeft(vom)) {
|
14033 | vom.t = vip;
|
14034 | vom.m += sip - som;
|
14035 | ancestor = v;
|
14036 | }
|
14037 | }
|
14038 | return ancestor;
|
14039 | }
|
14040 |
|
14041 | function sizeNode(node) {
|
14042 | node.x *= dx;
|
14043 | node.y = node.depth * dy;
|
14044 | }
|
14045 |
|
14046 | tree.separation = function(x) {
|
14047 | return arguments.length ? (separation = x, tree) : separation;
|
14048 | };
|
14049 |
|
14050 | tree.size = function(x) {
|
14051 | return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
|
14052 | };
|
14053 |
|
14054 | tree.nodeSize = function(x) {
|
14055 | return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
|
14056 | };
|
14057 |
|
14058 | return tree;
|
14059 | }
|
14060 |
|
14061 | function treemapSlice(parent, x0, y0, x1, y1) {
|
14062 | var nodes = parent.children,
|
14063 | node,
|
14064 | i = -1,
|
14065 | n = nodes.length,
|
14066 | k = parent.value && (y1 - y0) / parent.value;
|
14067 |
|
14068 | while (++i < n) {
|
14069 | node = nodes[i], node.x0 = x0, node.x1 = x1;
|
14070 | node.y0 = y0, node.y1 = y0 += node.value * k;
|
14071 | }
|
14072 | }
|
14073 |
|
14074 | var phi = (1 + Math.sqrt(5)) / 2;
|
14075 |
|
14076 | function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
|
14077 | var rows = [],
|
14078 | nodes = parent.children,
|
14079 | row,
|
14080 | nodeValue,
|
14081 | i0 = 0,
|
14082 | i1 = 0,
|
14083 | n = nodes.length,
|
14084 | dx, dy,
|
14085 | value = parent.value,
|
14086 | sumValue,
|
14087 | minValue,
|
14088 | maxValue,
|
14089 | newRatio,
|
14090 | minRatio,
|
14091 | alpha,
|
14092 | beta;
|
14093 |
|
14094 | while (i0 < n) {
|
14095 | dx = x1 - x0, dy = y1 - y0;
|
14096 |
|
14097 | // Find the next non-empty node.
|
14098 | do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
|
14099 | minValue = maxValue = sumValue;
|
14100 | alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
|
14101 | beta = sumValue * sumValue * alpha;
|
14102 | minRatio = Math.max(maxValue / beta, beta / minValue);
|
14103 |
|
14104 | // Keep adding nodes while the aspect ratio maintains or improves.
|
14105 | for (; i1 < n; ++i1) {
|
14106 | sumValue += nodeValue = nodes[i1].value;
|
14107 | if (nodeValue < minValue) minValue = nodeValue;
|
14108 | if (nodeValue > maxValue) maxValue = nodeValue;
|
14109 | beta = sumValue * sumValue * alpha;
|
14110 | newRatio = Math.max(maxValue / beta, beta / minValue);
|
14111 | if (newRatio > minRatio) { sumValue -= nodeValue; break; }
|
14112 | minRatio = newRatio;
|
14113 | }
|
14114 |
|
14115 | // Position and record the row orientation.
|
14116 | rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
|
14117 | if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
|
14118 | else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
|
14119 | value -= sumValue, i0 = i1;
|
14120 | }
|
14121 |
|
14122 | return rows;
|
14123 | }
|
14124 |
|
14125 | var squarify = (function custom(ratio) {
|
14126 |
|
14127 | function squarify(parent, x0, y0, x1, y1) {
|
14128 | squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
14129 | }
|
14130 |
|
14131 | squarify.ratio = function(x) {
|
14132 | return custom((x = +x) > 1 ? x : 1);
|
14133 | };
|
14134 |
|
14135 | return squarify;
|
14136 | })(phi);
|
14137 |
|
14138 | function index() {
|
14139 | var tile = squarify,
|
14140 | round = false,
|
14141 | dx = 1,
|
14142 | dy = 1,
|
14143 | paddingStack = [0],
|
14144 | paddingInner = constantZero,
|
14145 | paddingTop = constantZero,
|
14146 | paddingRight = constantZero,
|
14147 | paddingBottom = constantZero,
|
14148 | paddingLeft = constantZero;
|
14149 |
|
14150 | function treemap(root) {
|
14151 | root.x0 =
|
14152 | root.y0 = 0;
|
14153 | root.x1 = dx;
|
14154 | root.y1 = dy;
|
14155 | root.eachBefore(positionNode);
|
14156 | paddingStack = [0];
|
14157 | if (round) root.eachBefore(roundNode);
|
14158 | return root;
|
14159 | }
|
14160 |
|
14161 | function positionNode(node) {
|
14162 | var p = paddingStack[node.depth],
|
14163 | x0 = node.x0 + p,
|
14164 | y0 = node.y0 + p,
|
14165 | x1 = node.x1 - p,
|
14166 | y1 = node.y1 - p;
|
14167 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
14168 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
14169 | node.x0 = x0;
|
14170 | node.y0 = y0;
|
14171 | node.x1 = x1;
|
14172 | node.y1 = y1;
|
14173 | if (node.children) {
|
14174 | p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
|
14175 | x0 += paddingLeft(node) - p;
|
14176 | y0 += paddingTop(node) - p;
|
14177 | x1 -= paddingRight(node) - p;
|
14178 | y1 -= paddingBottom(node) - p;
|
14179 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
14180 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
14181 | tile(node, x0, y0, x1, y1);
|
14182 | }
|
14183 | }
|
14184 |
|
14185 | treemap.round = function(x) {
|
14186 | return arguments.length ? (round = !!x, treemap) : round;
|
14187 | };
|
14188 |
|
14189 | treemap.size = function(x) {
|
14190 | return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
|
14191 | };
|
14192 |
|
14193 | treemap.tile = function(x) {
|
14194 | return arguments.length ? (tile = required(x), treemap) : tile;
|
14195 | };
|
14196 |
|
14197 | treemap.padding = function(x) {
|
14198 | return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
|
14199 | };
|
14200 |
|
14201 | treemap.paddingInner = function(x) {
|
14202 | return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$2(+x), treemap) : paddingInner;
|
14203 | };
|
14204 |
|
14205 | treemap.paddingOuter = function(x) {
|
14206 | return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
|
14207 | };
|
14208 |
|
14209 | treemap.paddingTop = function(x) {
|
14210 | return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$2(+x), treemap) : paddingTop;
|
14211 | };
|
14212 |
|
14213 | treemap.paddingRight = function(x) {
|
14214 | return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$2(+x), treemap) : paddingRight;
|
14215 | };
|
14216 |
|
14217 | treemap.paddingBottom = function(x) {
|
14218 | return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$2(+x), treemap) : paddingBottom;
|
14219 | };
|
14220 |
|
14221 | treemap.paddingLeft = function(x) {
|
14222 | return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$2(+x), treemap) : paddingLeft;
|
14223 | };
|
14224 |
|
14225 | return treemap;
|
14226 | }
|
14227 |
|
14228 | function binary(parent, x0, y0, x1, y1) {
|
14229 | var nodes = parent.children,
|
14230 | i, n = nodes.length,
|
14231 | sum, sums = new Array(n + 1);
|
14232 |
|
14233 | for (sums[0] = sum = i = 0; i < n; ++i) {
|
14234 | sums[i + 1] = sum += nodes[i].value;
|
14235 | }
|
14236 |
|
14237 | partition(0, n, parent.value, x0, y0, x1, y1);
|
14238 |
|
14239 | function partition(i, j, value, x0, y0, x1, y1) {
|
14240 | if (i >= j - 1) {
|
14241 | var node = nodes[i];
|
14242 | node.x0 = x0, node.y0 = y0;
|
14243 | node.x1 = x1, node.y1 = y1;
|
14244 | return;
|
14245 | }
|
14246 |
|
14247 | var valueOffset = sums[i],
|
14248 | valueTarget = (value / 2) + valueOffset,
|
14249 | k = i + 1,
|
14250 | hi = j - 1;
|
14251 |
|
14252 | while (k < hi) {
|
14253 | var mid = k + hi >>> 1;
|
14254 | if (sums[mid] < valueTarget) k = mid + 1;
|
14255 | else hi = mid;
|
14256 | }
|
14257 |
|
14258 | if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
|
14259 |
|
14260 | var valueLeft = sums[k] - valueOffset,
|
14261 | valueRight = value - valueLeft;
|
14262 |
|
14263 | if ((x1 - x0) > (y1 - y0)) {
|
14264 | var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
|
14265 | partition(i, k, valueLeft, x0, y0, xk, y1);
|
14266 | partition(k, j, valueRight, xk, y0, x1, y1);
|
14267 | } else {
|
14268 | var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
|
14269 | partition(i, k, valueLeft, x0, y0, x1, yk);
|
14270 | partition(k, j, valueRight, x0, yk, x1, y1);
|
14271 | }
|
14272 | }
|
14273 | }
|
14274 |
|
14275 | function sliceDice(parent, x0, y0, x1, y1) {
|
14276 | (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
|
14277 | }
|
14278 |
|
14279 | var resquarify = (function custom(ratio) {
|
14280 |
|
14281 | function resquarify(parent, x0, y0, x1, y1) {
|
14282 | if ((rows = parent._squarify) && (rows.ratio === ratio)) {
|
14283 | var rows,
|
14284 | row,
|
14285 | nodes,
|
14286 | i,
|
14287 | j = -1,
|
14288 | n,
|
14289 | m = rows.length,
|
14290 | value = parent.value;
|
14291 |
|
14292 | while (++j < m) {
|
14293 | row = rows[j], nodes = row.children;
|
14294 | for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
|
14295 | if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1);
|
14296 | else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1);
|
14297 | value -= row.value;
|
14298 | }
|
14299 | } else {
|
14300 | parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
14301 | rows.ratio = ratio;
|
14302 | }
|
14303 | }
|
14304 |
|
14305 | resquarify.ratio = function(x) {
|
14306 | return custom((x = +x) > 1 ? x : 1);
|
14307 | };
|
14308 |
|
14309 | return resquarify;
|
14310 | })(phi);
|
14311 |
|
14312 | function area$1(polygon) {
|
14313 | var i = -1,
|
14314 | n = polygon.length,
|
14315 | a,
|
14316 | b = polygon[n - 1],
|
14317 | area = 0;
|
14318 |
|
14319 | while (++i < n) {
|
14320 | a = b;
|
14321 | b = polygon[i];
|
14322 | area += a[1] * b[0] - a[0] * b[1];
|
14323 | }
|
14324 |
|
14325 | return area / 2;
|
14326 | }
|
14327 |
|
14328 | function centroid(polygon) {
|
14329 | var i = -1,
|
14330 | n = polygon.length,
|
14331 | x = 0,
|
14332 | y = 0,
|
14333 | a,
|
14334 | b = polygon[n - 1],
|
14335 | c,
|
14336 | k = 0;
|
14337 |
|
14338 | while (++i < n) {
|
14339 | a = b;
|
14340 | b = polygon[i];
|
14341 | k += c = a[0] * b[1] - b[0] * a[1];
|
14342 | x += (a[0] + b[0]) * c;
|
14343 | y += (a[1] + b[1]) * c;
|
14344 | }
|
14345 |
|
14346 | return k *= 3, [x / k, y / k];
|
14347 | }
|
14348 |
|
14349 | // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
|
14350 | // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
|
14351 | // right, +y is up). Returns a positive value if ABC is counter-clockwise,
|
14352 | // negative if clockwise, and zero if the points are collinear.
|
14353 | function cross$1(a, b, c) {
|
14354 | return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
14355 | }
|
14356 |
|
14357 | function lexicographicOrder(a, b) {
|
14358 | return a[0] - b[0] || a[1] - b[1];
|
14359 | }
|
14360 |
|
14361 | // Computes the upper convex hull per the monotone chain algorithm.
|
14362 | // Assumes points.length >= 3, is sorted by x, unique in y.
|
14363 | // Returns an array of indices into points in left-to-right order.
|
14364 | function computeUpperHullIndexes(points) {
|
14365 | const n = points.length,
|
14366 | indexes = [0, 1];
|
14367 | let size = 2, i;
|
14368 |
|
14369 | for (i = 2; i < n; ++i) {
|
14370 | while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
|
14371 | indexes[size++] = i;
|
14372 | }
|
14373 |
|
14374 | return indexes.slice(0, size); // remove popped points
|
14375 | }
|
14376 |
|
14377 | function hull(points) {
|
14378 | if ((n = points.length) < 3) return null;
|
14379 |
|
14380 | var i,
|
14381 | n,
|
14382 | sortedPoints = new Array(n),
|
14383 | flippedPoints = new Array(n);
|
14384 |
|
14385 | for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
|
14386 | sortedPoints.sort(lexicographicOrder);
|
14387 | for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
|
14388 |
|
14389 | var upperIndexes = computeUpperHullIndexes(sortedPoints),
|
14390 | lowerIndexes = computeUpperHullIndexes(flippedPoints);
|
14391 |
|
14392 | // Construct the hull polygon, removing possible duplicate endpoints.
|
14393 | var skipLeft = lowerIndexes[0] === upperIndexes[0],
|
14394 | skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
|
14395 | hull = [];
|
14396 |
|
14397 | // Add upper hull in right-to-l order.
|
14398 | // Then add lower hull in left-to-right order.
|
14399 | for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
|
14400 | for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
|
14401 |
|
14402 | return hull;
|
14403 | }
|
14404 |
|
14405 | function contains(polygon, point) {
|
14406 | var n = polygon.length,
|
14407 | p = polygon[n - 1],
|
14408 | x = point[0], y = point[1],
|
14409 | x0 = p[0], y0 = p[1],
|
14410 | x1, y1,
|
14411 | inside = false;
|
14412 |
|
14413 | for (var i = 0; i < n; ++i) {
|
14414 | p = polygon[i], x1 = p[0], y1 = p[1];
|
14415 | if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
|
14416 | x0 = x1, y0 = y1;
|
14417 | }
|
14418 |
|
14419 | return inside;
|
14420 | }
|
14421 |
|
14422 | function length(polygon) {
|
14423 | var i = -1,
|
14424 | n = polygon.length,
|
14425 | b = polygon[n - 1],
|
14426 | xa,
|
14427 | ya,
|
14428 | xb = b[0],
|
14429 | yb = b[1],
|
14430 | perimeter = 0;
|
14431 |
|
14432 | while (++i < n) {
|
14433 | xa = xb;
|
14434 | ya = yb;
|
14435 | b = polygon[i];
|
14436 | xb = b[0];
|
14437 | yb = b[1];
|
14438 | xa -= xb;
|
14439 | ya -= yb;
|
14440 | perimeter += Math.hypot(xa, ya);
|
14441 | }
|
14442 |
|
14443 | return perimeter;
|
14444 | }
|
14445 |
|
14446 | var defaultSource = Math.random;
|
14447 |
|
14448 | var uniform = (function sourceRandomUniform(source) {
|
14449 | function randomUniform(min, max) {
|
14450 | min = min == null ? 0 : +min;
|
14451 | max = max == null ? 1 : +max;
|
14452 | if (arguments.length === 1) max = min, min = 0;
|
14453 | else max -= min;
|
14454 | return function() {
|
14455 | return source() * max + min;
|
14456 | };
|
14457 | }
|
14458 |
|
14459 | randomUniform.source = sourceRandomUniform;
|
14460 |
|
14461 | return randomUniform;
|
14462 | })(defaultSource);
|
14463 |
|
14464 | var int = (function sourceRandomInt(source) {
|
14465 | function randomInt(min, max) {
|
14466 | if (arguments.length < 2) max = min, min = 0;
|
14467 | min = Math.floor(min);
|
14468 | max = Math.floor(max) - min;
|
14469 | return function() {
|
14470 | return Math.floor(source() * max + min);
|
14471 | };
|
14472 | }
|
14473 |
|
14474 | randomInt.source = sourceRandomInt;
|
14475 |
|
14476 | return randomInt;
|
14477 | })(defaultSource);
|
14478 |
|
14479 | var normal = (function sourceRandomNormal(source) {
|
14480 | function randomNormal(mu, sigma) {
|
14481 | var x, r;
|
14482 | mu = mu == null ? 0 : +mu;
|
14483 | sigma = sigma == null ? 1 : +sigma;
|
14484 | return function() {
|
14485 | var y;
|
14486 |
|
14487 | // If available, use the second previously-generated uniform random.
|
14488 | if (x != null) y = x, x = null;
|
14489 |
|
14490 | // Otherwise, generate a new x and y.
|
14491 | else do {
|
14492 | x = source() * 2 - 1;
|
14493 | y = source() * 2 - 1;
|
14494 | r = x * x + y * y;
|
14495 | } while (!r || r > 1);
|
14496 |
|
14497 | return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
|
14498 | };
|
14499 | }
|
14500 |
|
14501 | randomNormal.source = sourceRandomNormal;
|
14502 |
|
14503 | return randomNormal;
|
14504 | })(defaultSource);
|
14505 |
|
14506 | var logNormal = (function sourceRandomLogNormal(source) {
|
14507 | var N = normal.source(source);
|
14508 |
|
14509 | function randomLogNormal() {
|
14510 | var randomNormal = N.apply(this, arguments);
|
14511 | return function() {
|
14512 | return Math.exp(randomNormal());
|
14513 | };
|
14514 | }
|
14515 |
|
14516 | randomLogNormal.source = sourceRandomLogNormal;
|
14517 |
|
14518 | return randomLogNormal;
|
14519 | })(defaultSource);
|
14520 |
|
14521 | var irwinHall = (function sourceRandomIrwinHall(source) {
|
14522 | function randomIrwinHall(n) {
|
14523 | if ((n = +n) <= 0) return () => 0;
|
14524 | return function() {
|
14525 | for (var sum = 0, i = n; i > 1; --i) sum += source();
|
14526 | return sum + i * source();
|
14527 | };
|
14528 | }
|
14529 |
|
14530 | randomIrwinHall.source = sourceRandomIrwinHall;
|
14531 |
|
14532 | return randomIrwinHall;
|
14533 | })(defaultSource);
|
14534 |
|
14535 | var bates = (function sourceRandomBates(source) {
|
14536 | var I = irwinHall.source(source);
|
14537 |
|
14538 | function randomBates(n) {
|
14539 | // use limiting distribution at n === 0
|
14540 | if ((n = +n) === 0) return source;
|
14541 | var randomIrwinHall = I(n);
|
14542 | return function() {
|
14543 | return randomIrwinHall() / n;
|
14544 | };
|
14545 | }
|
14546 |
|
14547 | randomBates.source = sourceRandomBates;
|
14548 |
|
14549 | return randomBates;
|
14550 | })(defaultSource);
|
14551 |
|
14552 | var exponential = (function sourceRandomExponential(source) {
|
14553 | function randomExponential(lambda) {
|
14554 | return function() {
|
14555 | return -Math.log1p(-source()) / lambda;
|
14556 | };
|
14557 | }
|
14558 |
|
14559 | randomExponential.source = sourceRandomExponential;
|
14560 |
|
14561 | return randomExponential;
|
14562 | })(defaultSource);
|
14563 |
|
14564 | var pareto = (function sourceRandomPareto(source) {
|
14565 | function randomPareto(alpha) {
|
14566 | if ((alpha = +alpha) < 0) throw new RangeError("invalid alpha");
|
14567 | alpha = 1 / -alpha;
|
14568 | return function() {
|
14569 | return Math.pow(1 - source(), alpha);
|
14570 | };
|
14571 | }
|
14572 |
|
14573 | randomPareto.source = sourceRandomPareto;
|
14574 |
|
14575 | return randomPareto;
|
14576 | })(defaultSource);
|
14577 |
|
14578 | var bernoulli = (function sourceRandomBernoulli(source) {
|
14579 | function randomBernoulli(p) {
|
14580 | if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
|
14581 | return function() {
|
14582 | return Math.floor(source() + p);
|
14583 | };
|
14584 | }
|
14585 |
|
14586 | randomBernoulli.source = sourceRandomBernoulli;
|
14587 |
|
14588 | return randomBernoulli;
|
14589 | })(defaultSource);
|
14590 |
|
14591 | var geometric = (function sourceRandomGeometric(source) {
|
14592 | function randomGeometric(p) {
|
14593 | if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
|
14594 | if (p === 0) return () => Infinity;
|
14595 | if (p === 1) return () => 1;
|
14596 | p = Math.log1p(-p);
|
14597 | return function() {
|
14598 | return 1 + Math.floor(Math.log1p(-source()) / p);
|
14599 | };
|
14600 | }
|
14601 |
|
14602 | randomGeometric.source = sourceRandomGeometric;
|
14603 |
|
14604 | return randomGeometric;
|
14605 | })(defaultSource);
|
14606 |
|
14607 | var gamma = (function sourceRandomGamma(source) {
|
14608 | var randomNormal = normal.source(source)();
|
14609 |
|
14610 | function randomGamma(k, theta) {
|
14611 | if ((k = +k) < 0) throw new RangeError("invalid k");
|
14612 | // degenerate distribution if k === 0
|
14613 | if (k === 0) return () => 0;
|
14614 | theta = theta == null ? 1 : +theta;
|
14615 | // exponential distribution if k === 1
|
14616 | if (k === 1) return () => -Math.log1p(-source()) * theta;
|
14617 |
|
14618 | var d = (k < 1 ? k + 1 : k) - 1 / 3,
|
14619 | c = 1 / (3 * Math.sqrt(d)),
|
14620 | multiplier = k < 1 ? () => Math.pow(source(), 1 / k) : () => 1;
|
14621 | return function() {
|
14622 | do {
|
14623 | do {
|
14624 | var x = randomNormal(),
|
14625 | v = 1 + c * x;
|
14626 | } while (v <= 0);
|
14627 | v *= v * v;
|
14628 | var u = 1 - source();
|
14629 | } while (u >= 1 - 0.0331 * x * x * x * x && Math.log(u) >= 0.5 * x * x + d * (1 - v + Math.log(v)));
|
14630 | return d * v * multiplier() * theta;
|
14631 | };
|
14632 | }
|
14633 |
|
14634 | randomGamma.source = sourceRandomGamma;
|
14635 |
|
14636 | return randomGamma;
|
14637 | })(defaultSource);
|
14638 |
|
14639 | var beta = (function sourceRandomBeta(source) {
|
14640 | var G = gamma.source(source);
|
14641 |
|
14642 | function randomBeta(alpha, beta) {
|
14643 | var X = G(alpha),
|
14644 | Y = G(beta);
|
14645 | return function() {
|
14646 | var x = X();
|
14647 | return x === 0 ? 0 : x / (x + Y());
|
14648 | };
|
14649 | }
|
14650 |
|
14651 | randomBeta.source = sourceRandomBeta;
|
14652 |
|
14653 | return randomBeta;
|
14654 | })(defaultSource);
|
14655 |
|
14656 | var binomial = (function sourceRandomBinomial(source) {
|
14657 | var G = geometric.source(source),
|
14658 | B = beta.source(source);
|
14659 |
|
14660 | function randomBinomial(n, p) {
|
14661 | n = +n;
|
14662 | if ((p = +p) >= 1) return () => n;
|
14663 | if (p <= 0) return () => 0;
|
14664 | return function() {
|
14665 | var acc = 0, nn = n, pp = p;
|
14666 | while (nn * pp > 16 && nn * (1 - pp) > 16) {
|
14667 | var i = Math.floor((nn + 1) * pp),
|
14668 | y = B(i, nn - i + 1)();
|
14669 | if (y <= pp) {
|
14670 | acc += i;
|
14671 | nn -= i;
|
14672 | pp = (pp - y) / (1 - y);
|
14673 | } else {
|
14674 | nn = i - 1;
|
14675 | pp /= y;
|
14676 | }
|
14677 | }
|
14678 | var sign = pp < 0.5,
|
14679 | pFinal = sign ? pp : 1 - pp,
|
14680 | g = G(pFinal);
|
14681 | for (var s = g(), k = 0; s <= nn; ++k) s += g();
|
14682 | return acc + (sign ? k : nn - k);
|
14683 | };
|
14684 | }
|
14685 |
|
14686 | randomBinomial.source = sourceRandomBinomial;
|
14687 |
|
14688 | return randomBinomial;
|
14689 | })(defaultSource);
|
14690 |
|
14691 | var weibull = (function sourceRandomWeibull(source) {
|
14692 | function randomWeibull(k, a, b) {
|
14693 | var outerFunc;
|
14694 | if ((k = +k) === 0) {
|
14695 | outerFunc = x => -Math.log(x);
|
14696 | } else {
|
14697 | k = 1 / k;
|
14698 | outerFunc = x => Math.pow(x, k);
|
14699 | }
|
14700 | a = a == null ? 0 : +a;
|
14701 | b = b == null ? 1 : +b;
|
14702 | return function() {
|
14703 | return a + b * outerFunc(-Math.log1p(-source()));
|
14704 | };
|
14705 | }
|
14706 |
|
14707 | randomWeibull.source = sourceRandomWeibull;
|
14708 |
|
14709 | return randomWeibull;
|
14710 | })(defaultSource);
|
14711 |
|
14712 | var cauchy = (function sourceRandomCauchy(source) {
|
14713 | function randomCauchy(a, b) {
|
14714 | a = a == null ? 0 : +a;
|
14715 | b = b == null ? 1 : +b;
|
14716 | return function() {
|
14717 | return a + b * Math.tan(Math.PI * source());
|
14718 | };
|
14719 | }
|
14720 |
|
14721 | randomCauchy.source = sourceRandomCauchy;
|
14722 |
|
14723 | return randomCauchy;
|
14724 | })(defaultSource);
|
14725 |
|
14726 | var logistic = (function sourceRandomLogistic(source) {
|
14727 | function randomLogistic(a, b) {
|
14728 | a = a == null ? 0 : +a;
|
14729 | b = b == null ? 1 : +b;
|
14730 | return function() {
|
14731 | var u = source();
|
14732 | return a + b * Math.log(u / (1 - u));
|
14733 | };
|
14734 | }
|
14735 |
|
14736 | randomLogistic.source = sourceRandomLogistic;
|
14737 |
|
14738 | return randomLogistic;
|
14739 | })(defaultSource);
|
14740 |
|
14741 | var poisson = (function sourceRandomPoisson(source) {
|
14742 | var G = gamma.source(source),
|
14743 | B = binomial.source(source);
|
14744 |
|
14745 | function randomPoisson(lambda) {
|
14746 | return function() {
|
14747 | var acc = 0, l = lambda;
|
14748 | while (l > 16) {
|
14749 | var n = Math.floor(0.875 * l),
|
14750 | t = G(n)();
|
14751 | if (t > l) return acc + B(n - 1, l / t)();
|
14752 | acc += n;
|
14753 | l -= t;
|
14754 | }
|
14755 | for (var s = -Math.log1p(-source()), k = 0; s <= l; ++k) s -= Math.log1p(-source());
|
14756 | return acc + k;
|
14757 | };
|
14758 | }
|
14759 |
|
14760 | randomPoisson.source = sourceRandomPoisson;
|
14761 |
|
14762 | return randomPoisson;
|
14763 | })(defaultSource);
|
14764 |
|
14765 | // https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
|
14766 | const mul = 0x19660D;
|
14767 | const inc = 0x3C6EF35F;
|
14768 | const eps = 1 / 0x100000000;
|
14769 |
|
14770 | function lcg(seed = Math.random()) {
|
14771 | let state = (0 <= seed && seed < 1 ? seed / eps : Math.abs(seed)) | 0;
|
14772 | return () => (state = mul * state + inc | 0, eps * (state >>> 0));
|
14773 | }
|
14774 |
|
14775 | function initRange(domain, range) {
|
14776 | switch (arguments.length) {
|
14777 | case 0: break;
|
14778 | case 1: this.range(domain); break;
|
14779 | default: this.range(range).domain(domain); break;
|
14780 | }
|
14781 | return this;
|
14782 | }
|
14783 |
|
14784 | function initInterpolator(domain, interpolator) {
|
14785 | switch (arguments.length) {
|
14786 | case 0: break;
|
14787 | case 1: {
|
14788 | if (typeof domain === "function") this.interpolator(domain);
|
14789 | else this.range(domain);
|
14790 | break;
|
14791 | }
|
14792 | default: {
|
14793 | this.domain(domain);
|
14794 | if (typeof interpolator === "function") this.interpolator(interpolator);
|
14795 | else this.range(interpolator);
|
14796 | break;
|
14797 | }
|
14798 | }
|
14799 | return this;
|
14800 | }
|
14801 |
|
14802 | const implicit = Symbol("implicit");
|
14803 |
|
14804 | function ordinal() {
|
14805 | var index = new InternMap(),
|
14806 | domain = [],
|
14807 | range = [],
|
14808 | unknown = implicit;
|
14809 |
|
14810 | function scale(d) {
|
14811 | let i = index.get(d);
|
14812 | if (i === undefined) {
|
14813 | if (unknown !== implicit) return unknown;
|
14814 | index.set(d, i = domain.push(d) - 1);
|
14815 | }
|
14816 | return range[i % range.length];
|
14817 | }
|
14818 |
|
14819 | scale.domain = function(_) {
|
14820 | if (!arguments.length) return domain.slice();
|
14821 | domain = [], index = new InternMap();
|
14822 | for (const value of _) {
|
14823 | if (index.has(value)) continue;
|
14824 | index.set(value, domain.push(value) - 1);
|
14825 | }
|
14826 | return scale;
|
14827 | };
|
14828 |
|
14829 | scale.range = function(_) {
|
14830 | return arguments.length ? (range = Array.from(_), scale) : range.slice();
|
14831 | };
|
14832 |
|
14833 | scale.unknown = function(_) {
|
14834 | return arguments.length ? (unknown = _, scale) : unknown;
|
14835 | };
|
14836 |
|
14837 | scale.copy = function() {
|
14838 | return ordinal(domain, range).unknown(unknown);
|
14839 | };
|
14840 |
|
14841 | initRange.apply(scale, arguments);
|
14842 |
|
14843 | return scale;
|
14844 | }
|
14845 |
|
14846 | function band() {
|
14847 | var scale = ordinal().unknown(undefined),
|
14848 | domain = scale.domain,
|
14849 | ordinalRange = scale.range,
|
14850 | r0 = 0,
|
14851 | r1 = 1,
|
14852 | step,
|
14853 | bandwidth,
|
14854 | round = false,
|
14855 | paddingInner = 0,
|
14856 | paddingOuter = 0,
|
14857 | align = 0.5;
|
14858 |
|
14859 | delete scale.unknown;
|
14860 |
|
14861 | function rescale() {
|
14862 | var n = domain().length,
|
14863 | reverse = r1 < r0,
|
14864 | start = reverse ? r1 : r0,
|
14865 | stop = reverse ? r0 : r1;
|
14866 | step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
|
14867 | if (round) step = Math.floor(step);
|
14868 | start += (stop - start - step * (n - paddingInner)) * align;
|
14869 | bandwidth = step * (1 - paddingInner);
|
14870 | if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
|
14871 | var values = range$2(n).map(function(i) { return start + step * i; });
|
14872 | return ordinalRange(reverse ? values.reverse() : values);
|
14873 | }
|
14874 |
|
14875 | scale.domain = function(_) {
|
14876 | return arguments.length ? (domain(_), rescale()) : domain();
|
14877 | };
|
14878 |
|
14879 | scale.range = function(_) {
|
14880 | return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1];
|
14881 | };
|
14882 |
|
14883 | scale.rangeRound = function(_) {
|
14884 | return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale();
|
14885 | };
|
14886 |
|
14887 | scale.bandwidth = function() {
|
14888 | return bandwidth;
|
14889 | };
|
14890 |
|
14891 | scale.step = function() {
|
14892 | return step;
|
14893 | };
|
14894 |
|
14895 | scale.round = function(_) {
|
14896 | return arguments.length ? (round = !!_, rescale()) : round;
|
14897 | };
|
14898 |
|
14899 | scale.padding = function(_) {
|
14900 | return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
|
14901 | };
|
14902 |
|
14903 | scale.paddingInner = function(_) {
|
14904 | return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
|
14905 | };
|
14906 |
|
14907 | scale.paddingOuter = function(_) {
|
14908 | return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
|
14909 | };
|
14910 |
|
14911 | scale.align = function(_) {
|
14912 | return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
|
14913 | };
|
14914 |
|
14915 | scale.copy = function() {
|
14916 | return band(domain(), [r0, r1])
|
14917 | .round(round)
|
14918 | .paddingInner(paddingInner)
|
14919 | .paddingOuter(paddingOuter)
|
14920 | .align(align);
|
14921 | };
|
14922 |
|
14923 | return initRange.apply(rescale(), arguments);
|
14924 | }
|
14925 |
|
14926 | function pointish(scale) {
|
14927 | var copy = scale.copy;
|
14928 |
|
14929 | scale.padding = scale.paddingOuter;
|
14930 | delete scale.paddingInner;
|
14931 | delete scale.paddingOuter;
|
14932 |
|
14933 | scale.copy = function() {
|
14934 | return pointish(copy());
|
14935 | };
|
14936 |
|
14937 | return scale;
|
14938 | }
|
14939 |
|
14940 | function point$4() {
|
14941 | return pointish(band.apply(null, arguments).paddingInner(1));
|
14942 | }
|
14943 |
|
14944 | function constants(x) {
|
14945 | return function() {
|
14946 | return x;
|
14947 | };
|
14948 | }
|
14949 |
|
14950 | function number$1(x) {
|
14951 | return +x;
|
14952 | }
|
14953 |
|
14954 | var unit = [0, 1];
|
14955 |
|
14956 | function identity$3(x) {
|
14957 | return x;
|
14958 | }
|
14959 |
|
14960 | function normalize(a, b) {
|
14961 | return (b -= (a = +a))
|
14962 | ? function(x) { return (x - a) / b; }
|
14963 | : constants(isNaN(b) ? NaN : 0.5);
|
14964 | }
|
14965 |
|
14966 | function clamper(a, b) {
|
14967 | var t;
|
14968 | if (a > b) t = a, a = b, b = t;
|
14969 | return function(x) { return Math.max(a, Math.min(b, x)); };
|
14970 | }
|
14971 |
|
14972 | // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
|
14973 | // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
|
14974 | function bimap(domain, range, interpolate) {
|
14975 | var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
|
14976 | if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
|
14977 | else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
|
14978 | return function(x) { return r0(d0(x)); };
|
14979 | }
|
14980 |
|
14981 | function polymap(domain, range, interpolate) {
|
14982 | var j = Math.min(domain.length, range.length) - 1,
|
14983 | d = new Array(j),
|
14984 | r = new Array(j),
|
14985 | i = -1;
|
14986 |
|
14987 | // Reverse descending domains.
|
14988 | if (domain[j] < domain[0]) {
|
14989 | domain = domain.slice().reverse();
|
14990 | range = range.slice().reverse();
|
14991 | }
|
14992 |
|
14993 | while (++i < j) {
|
14994 | d[i] = normalize(domain[i], domain[i + 1]);
|
14995 | r[i] = interpolate(range[i], range[i + 1]);
|
14996 | }
|
14997 |
|
14998 | return function(x) {
|
14999 | var i = bisect(domain, x, 1, j) - 1;
|
15000 | return r[i](d[i](x));
|
15001 | };
|
15002 | }
|
15003 |
|
15004 | function copy$1(source, target) {
|
15005 | return target
|
15006 | .domain(source.domain())
|
15007 | .range(source.range())
|
15008 | .interpolate(source.interpolate())
|
15009 | .clamp(source.clamp())
|
15010 | .unknown(source.unknown());
|
15011 | }
|
15012 |
|
15013 | function transformer$2() {
|
15014 | var domain = unit,
|
15015 | range = unit,
|
15016 | interpolate = interpolate$2,
|
15017 | transform,
|
15018 | untransform,
|
15019 | unknown,
|
15020 | clamp = identity$3,
|
15021 | piecewise,
|
15022 | output,
|
15023 | input;
|
15024 |
|
15025 | function rescale() {
|
15026 | var n = Math.min(domain.length, range.length);
|
15027 | if (clamp !== identity$3) clamp = clamper(domain[0], domain[n - 1]);
|
15028 | piecewise = n > 2 ? polymap : bimap;
|
15029 | output = input = null;
|
15030 | return scale;
|
15031 | }
|
15032 |
|
15033 | function scale(x) {
|
15034 | return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
|
15035 | }
|
15036 |
|
15037 | scale.invert = function(y) {
|
15038 | return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
|
15039 | };
|
15040 |
|
15041 | scale.domain = function(_) {
|
15042 | return arguments.length ? (domain = Array.from(_, number$1), rescale()) : domain.slice();
|
15043 | };
|
15044 |
|
15045 | scale.range = function(_) {
|
15046 | return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
|
15047 | };
|
15048 |
|
15049 | scale.rangeRound = function(_) {
|
15050 | return range = Array.from(_), interpolate = interpolateRound, rescale();
|
15051 | };
|
15052 |
|
15053 | scale.clamp = function(_) {
|
15054 | return arguments.length ? (clamp = _ ? true : identity$3, rescale()) : clamp !== identity$3;
|
15055 | };
|
15056 |
|
15057 | scale.interpolate = function(_) {
|
15058 | return arguments.length ? (interpolate = _, rescale()) : interpolate;
|
15059 | };
|
15060 |
|
15061 | scale.unknown = function(_) {
|
15062 | return arguments.length ? (unknown = _, scale) : unknown;
|
15063 | };
|
15064 |
|
15065 | return function(t, u) {
|
15066 | transform = t, untransform = u;
|
15067 | return rescale();
|
15068 | };
|
15069 | }
|
15070 |
|
15071 | function continuous() {
|
15072 | return transformer$2()(identity$3, identity$3);
|
15073 | }
|
15074 |
|
15075 | function tickFormat(start, stop, count, specifier) {
|
15076 | var step = tickStep(start, stop, count),
|
15077 | precision;
|
15078 | specifier = formatSpecifier(specifier == null ? ",f" : specifier);
|
15079 | switch (specifier.type) {
|
15080 | case "s": {
|
15081 | var value = Math.max(Math.abs(start), Math.abs(stop));
|
15082 | if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
|
15083 | return exports.formatPrefix(specifier, value);
|
15084 | }
|
15085 | case "":
|
15086 | case "e":
|
15087 | case "g":
|
15088 | case "p":
|
15089 | case "r": {
|
15090 | if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
|
15091 | break;
|
15092 | }
|
15093 | case "f":
|
15094 | case "%": {
|
15095 | if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
|
15096 | break;
|
15097 | }
|
15098 | }
|
15099 | return exports.format(specifier);
|
15100 | }
|
15101 |
|
15102 | function linearish(scale) {
|
15103 | var domain = scale.domain;
|
15104 |
|
15105 | scale.ticks = function(count) {
|
15106 | var d = domain();
|
15107 | return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
|
15108 | };
|
15109 |
|
15110 | scale.tickFormat = function(count, specifier) {
|
15111 | var d = domain();
|
15112 | return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
|
15113 | };
|
15114 |
|
15115 | scale.nice = function(count) {
|
15116 | if (count == null) count = 10;
|
15117 |
|
15118 | var d = domain();
|
15119 | var i0 = 0;
|
15120 | var i1 = d.length - 1;
|
15121 | var start = d[i0];
|
15122 | var stop = d[i1];
|
15123 | var prestep;
|
15124 | var step;
|
15125 | var maxIter = 10;
|
15126 |
|
15127 | if (stop < start) {
|
15128 | step = start, start = stop, stop = step;
|
15129 | step = i0, i0 = i1, i1 = step;
|
15130 | }
|
15131 |
|
15132 | while (maxIter-- > 0) {
|
15133 | step = tickIncrement(start, stop, count);
|
15134 | if (step === prestep) {
|
15135 | d[i0] = start;
|
15136 | d[i1] = stop;
|
15137 | return domain(d);
|
15138 | } else if (step > 0) {
|
15139 | start = Math.floor(start / step) * step;
|
15140 | stop = Math.ceil(stop / step) * step;
|
15141 | } else if (step < 0) {
|
15142 | start = Math.ceil(start * step) / step;
|
15143 | stop = Math.floor(stop * step) / step;
|
15144 | } else {
|
15145 | break;
|
15146 | }
|
15147 | prestep = step;
|
15148 | }
|
15149 |
|
15150 | return scale;
|
15151 | };
|
15152 |
|
15153 | return scale;
|
15154 | }
|
15155 |
|
15156 | function linear() {
|
15157 | var scale = continuous();
|
15158 |
|
15159 | scale.copy = function() {
|
15160 | return copy$1(scale, linear());
|
15161 | };
|
15162 |
|
15163 | initRange.apply(scale, arguments);
|
15164 |
|
15165 | return linearish(scale);
|
15166 | }
|
15167 |
|
15168 | function identity$2(domain) {
|
15169 | var unknown;
|
15170 |
|
15171 | function scale(x) {
|
15172 | return x == null || isNaN(x = +x) ? unknown : x;
|
15173 | }
|
15174 |
|
15175 | scale.invert = scale;
|
15176 |
|
15177 | scale.domain = scale.range = function(_) {
|
15178 | return arguments.length ? (domain = Array.from(_, number$1), scale) : domain.slice();
|
15179 | };
|
15180 |
|
15181 | scale.unknown = function(_) {
|
15182 | return arguments.length ? (unknown = _, scale) : unknown;
|
15183 | };
|
15184 |
|
15185 | scale.copy = function() {
|
15186 | return identity$2(domain).unknown(unknown);
|
15187 | };
|
15188 |
|
15189 | domain = arguments.length ? Array.from(domain, number$1) : [0, 1];
|
15190 |
|
15191 | return linearish(scale);
|
15192 | }
|
15193 |
|
15194 | function nice(domain, interval) {
|
15195 | domain = domain.slice();
|
15196 |
|
15197 | var i0 = 0,
|
15198 | i1 = domain.length - 1,
|
15199 | x0 = domain[i0],
|
15200 | x1 = domain[i1],
|
15201 | t;
|
15202 |
|
15203 | if (x1 < x0) {
|
15204 | t = i0, i0 = i1, i1 = t;
|
15205 | t = x0, x0 = x1, x1 = t;
|
15206 | }
|
15207 |
|
15208 | domain[i0] = interval.floor(x0);
|
15209 | domain[i1] = interval.ceil(x1);
|
15210 | return domain;
|
15211 | }
|
15212 |
|
15213 | function transformLog(x) {
|
15214 | return Math.log(x);
|
15215 | }
|
15216 |
|
15217 | function transformExp(x) {
|
15218 | return Math.exp(x);
|
15219 | }
|
15220 |
|
15221 | function transformLogn(x) {
|
15222 | return -Math.log(-x);
|
15223 | }
|
15224 |
|
15225 | function transformExpn(x) {
|
15226 | return -Math.exp(-x);
|
15227 | }
|
15228 |
|
15229 | function pow10(x) {
|
15230 | return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
|
15231 | }
|
15232 |
|
15233 | function powp(base) {
|
15234 | return base === 10 ? pow10
|
15235 | : base === Math.E ? Math.exp
|
15236 | : x => Math.pow(base, x);
|
15237 | }
|
15238 |
|
15239 | function logp(base) {
|
15240 | return base === Math.E ? Math.log
|
15241 | : base === 10 && Math.log10
|
15242 | || base === 2 && Math.log2
|
15243 | || (base = Math.log(base), x => Math.log(x) / base);
|
15244 | }
|
15245 |
|
15246 | function reflect(f) {
|
15247 | return (x, k) => -f(-x, k);
|
15248 | }
|
15249 |
|
15250 | function loggish(transform) {
|
15251 | const scale = transform(transformLog, transformExp);
|
15252 | const domain = scale.domain;
|
15253 | let base = 10;
|
15254 | let logs;
|
15255 | let pows;
|
15256 |
|
15257 | function rescale() {
|
15258 | logs = logp(base), pows = powp(base);
|
15259 | if (domain()[0] < 0) {
|
15260 | logs = reflect(logs), pows = reflect(pows);
|
15261 | transform(transformLogn, transformExpn);
|
15262 | } else {
|
15263 | transform(transformLog, transformExp);
|
15264 | }
|
15265 | return scale;
|
15266 | }
|
15267 |
|
15268 | scale.base = function(_) {
|
15269 | return arguments.length ? (base = +_, rescale()) : base;
|
15270 | };
|
15271 |
|
15272 | scale.domain = function(_) {
|
15273 | return arguments.length ? (domain(_), rescale()) : domain();
|
15274 | };
|
15275 |
|
15276 | scale.ticks = count => {
|
15277 | const d = domain();
|
15278 | let u = d[0];
|
15279 | let v = d[d.length - 1];
|
15280 | const r = v < u;
|
15281 |
|
15282 | if (r) ([u, v] = [v, u]);
|
15283 |
|
15284 | let i = logs(u);
|
15285 | let j = logs(v);
|
15286 | let k;
|
15287 | let t;
|
15288 | const n = count == null ? 10 : +count;
|
15289 | let z = [];
|
15290 |
|
15291 | if (!(base % 1) && j - i < n) {
|
15292 | i = Math.floor(i), j = Math.ceil(j);
|
15293 | if (u > 0) for (; i <= j; ++i) {
|
15294 | for (k = 1; k < base; ++k) {
|
15295 | t = i < 0 ? k / pows(-i) : k * pows(i);
|
15296 | if (t < u) continue;
|
15297 | if (t > v) break;
|
15298 | z.push(t);
|
15299 | }
|
15300 | } else for (; i <= j; ++i) {
|
15301 | for (k = base - 1; k >= 1; --k) {
|
15302 | t = i > 0 ? k / pows(-i) : k * pows(i);
|
15303 | if (t < u) continue;
|
15304 | if (t > v) break;
|
15305 | z.push(t);
|
15306 | }
|
15307 | }
|
15308 | if (z.length * 2 < n) z = ticks(u, v, n);
|
15309 | } else {
|
15310 | z = ticks(i, j, Math.min(j - i, n)).map(pows);
|
15311 | }
|
15312 | return r ? z.reverse() : z;
|
15313 | };
|
15314 |
|
15315 | scale.tickFormat = (count, specifier) => {
|
15316 | if (count == null) count = 10;
|
15317 | if (specifier == null) specifier = base === 10 ? "s" : ",";
|
15318 | if (typeof specifier !== "function") {
|
15319 | if (!(base % 1) && (specifier = formatSpecifier(specifier)).precision == null) specifier.trim = true;
|
15320 | specifier = exports.format(specifier);
|
15321 | }
|
15322 | if (count === Infinity) return specifier;
|
15323 | const k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
|
15324 | return d => {
|
15325 | let i = d / pows(Math.round(logs(d)));
|
15326 | if (i * base < base - 0.5) i *= base;
|
15327 | return i <= k ? specifier(d) : "";
|
15328 | };
|
15329 | };
|
15330 |
|
15331 | scale.nice = () => {
|
15332 | return domain(nice(domain(), {
|
15333 | floor: x => pows(Math.floor(logs(x))),
|
15334 | ceil: x => pows(Math.ceil(logs(x)))
|
15335 | }));
|
15336 | };
|
15337 |
|
15338 | return scale;
|
15339 | }
|
15340 |
|
15341 | function log() {
|
15342 | const scale = loggish(transformer$2()).domain([1, 10]);
|
15343 | scale.copy = () => copy$1(scale, log()).base(scale.base());
|
15344 | initRange.apply(scale, arguments);
|
15345 | return scale;
|
15346 | }
|
15347 |
|
15348 | function transformSymlog(c) {
|
15349 | return function(x) {
|
15350 | return Math.sign(x) * Math.log1p(Math.abs(x / c));
|
15351 | };
|
15352 | }
|
15353 |
|
15354 | function transformSymexp(c) {
|
15355 | return function(x) {
|
15356 | return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
|
15357 | };
|
15358 | }
|
15359 |
|
15360 | function symlogish(transform) {
|
15361 | var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
|
15362 |
|
15363 | scale.constant = function(_) {
|
15364 | return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
|
15365 | };
|
15366 |
|
15367 | return linearish(scale);
|
15368 | }
|
15369 |
|
15370 | function symlog() {
|
15371 | var scale = symlogish(transformer$2());
|
15372 |
|
15373 | scale.copy = function() {
|
15374 | return copy$1(scale, symlog()).constant(scale.constant());
|
15375 | };
|
15376 |
|
15377 | return initRange.apply(scale, arguments);
|
15378 | }
|
15379 |
|
15380 | function transformPow(exponent) {
|
15381 | return function(x) {
|
15382 | return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
|
15383 | };
|
15384 | }
|
15385 |
|
15386 | function transformSqrt(x) {
|
15387 | return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
|
15388 | }
|
15389 |
|
15390 | function transformSquare(x) {
|
15391 | return x < 0 ? -x * x : x * x;
|
15392 | }
|
15393 |
|
15394 | function powish(transform) {
|
15395 | var scale = transform(identity$3, identity$3),
|
15396 | exponent = 1;
|
15397 |
|
15398 | function rescale() {
|
15399 | return exponent === 1 ? transform(identity$3, identity$3)
|
15400 | : exponent === 0.5 ? transform(transformSqrt, transformSquare)
|
15401 | : transform(transformPow(exponent), transformPow(1 / exponent));
|
15402 | }
|
15403 |
|
15404 | scale.exponent = function(_) {
|
15405 | return arguments.length ? (exponent = +_, rescale()) : exponent;
|
15406 | };
|
15407 |
|
15408 | return linearish(scale);
|
15409 | }
|
15410 |
|
15411 | function pow() {
|
15412 | var scale = powish(transformer$2());
|
15413 |
|
15414 | scale.copy = function() {
|
15415 | return copy$1(scale, pow()).exponent(scale.exponent());
|
15416 | };
|
15417 |
|
15418 | initRange.apply(scale, arguments);
|
15419 |
|
15420 | return scale;
|
15421 | }
|
15422 |
|
15423 | function sqrt$1() {
|
15424 | return pow.apply(null, arguments).exponent(0.5);
|
15425 | }
|
15426 |
|
15427 | function square$1(x) {
|
15428 | return Math.sign(x) * x * x;
|
15429 | }
|
15430 |
|
15431 | function unsquare(x) {
|
15432 | return Math.sign(x) * Math.sqrt(Math.abs(x));
|
15433 | }
|
15434 |
|
15435 | function radial() {
|
15436 | var squared = continuous(),
|
15437 | range = [0, 1],
|
15438 | round = false,
|
15439 | unknown;
|
15440 |
|
15441 | function scale(x) {
|
15442 | var y = unsquare(squared(x));
|
15443 | return isNaN(y) ? unknown : round ? Math.round(y) : y;
|
15444 | }
|
15445 |
|
15446 | scale.invert = function(y) {
|
15447 | return squared.invert(square$1(y));
|
15448 | };
|
15449 |
|
15450 | scale.domain = function(_) {
|
15451 | return arguments.length ? (squared.domain(_), scale) : squared.domain();
|
15452 | };
|
15453 |
|
15454 | scale.range = function(_) {
|
15455 | return arguments.length ? (squared.range((range = Array.from(_, number$1)).map(square$1)), scale) : range.slice();
|
15456 | };
|
15457 |
|
15458 | scale.rangeRound = function(_) {
|
15459 | return scale.range(_).round(true);
|
15460 | };
|
15461 |
|
15462 | scale.round = function(_) {
|
15463 | return arguments.length ? (round = !!_, scale) : round;
|
15464 | };
|
15465 |
|
15466 | scale.clamp = function(_) {
|
15467 | return arguments.length ? (squared.clamp(_), scale) : squared.clamp();
|
15468 | };
|
15469 |
|
15470 | scale.unknown = function(_) {
|
15471 | return arguments.length ? (unknown = _, scale) : unknown;
|
15472 | };
|
15473 |
|
15474 | scale.copy = function() {
|
15475 | return radial(squared.domain(), range)
|
15476 | .round(round)
|
15477 | .clamp(squared.clamp())
|
15478 | .unknown(unknown);
|
15479 | };
|
15480 |
|
15481 | initRange.apply(scale, arguments);
|
15482 |
|
15483 | return linearish(scale);
|
15484 | }
|
15485 |
|
15486 | function quantile() {
|
15487 | var domain = [],
|
15488 | range = [],
|
15489 | thresholds = [],
|
15490 | unknown;
|
15491 |
|
15492 | function rescale() {
|
15493 | var i = 0, n = Math.max(1, range.length);
|
15494 | thresholds = new Array(n - 1);
|
15495 | while (++i < n) thresholds[i - 1] = quantileSorted(domain, i / n);
|
15496 | return scale;
|
15497 | }
|
15498 |
|
15499 | function scale(x) {
|
15500 | return x == null || isNaN(x = +x) ? unknown : range[bisect(thresholds, x)];
|
15501 | }
|
15502 |
|
15503 | scale.invertExtent = function(y) {
|
15504 | var i = range.indexOf(y);
|
15505 | return i < 0 ? [NaN, NaN] : [
|
15506 | i > 0 ? thresholds[i - 1] : domain[0],
|
15507 | i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
|
15508 | ];
|
15509 | };
|
15510 |
|
15511 | scale.domain = function(_) {
|
15512 | if (!arguments.length) return domain.slice();
|
15513 | domain = [];
|
15514 | for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
|
15515 | domain.sort(ascending$3);
|
15516 | return rescale();
|
15517 | };
|
15518 |
|
15519 | scale.range = function(_) {
|
15520 | return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
|
15521 | };
|
15522 |
|
15523 | scale.unknown = function(_) {
|
15524 | return arguments.length ? (unknown = _, scale) : unknown;
|
15525 | };
|
15526 |
|
15527 | scale.quantiles = function() {
|
15528 | return thresholds.slice();
|
15529 | };
|
15530 |
|
15531 | scale.copy = function() {
|
15532 | return quantile()
|
15533 | .domain(domain)
|
15534 | .range(range)
|
15535 | .unknown(unknown);
|
15536 | };
|
15537 |
|
15538 | return initRange.apply(scale, arguments);
|
15539 | }
|
15540 |
|
15541 | function quantize() {
|
15542 | var x0 = 0,
|
15543 | x1 = 1,
|
15544 | n = 1,
|
15545 | domain = [0.5],
|
15546 | range = [0, 1],
|
15547 | unknown;
|
15548 |
|
15549 | function scale(x) {
|
15550 | return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
|
15551 | }
|
15552 |
|
15553 | function rescale() {
|
15554 | var i = -1;
|
15555 | domain = new Array(n);
|
15556 | while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
|
15557 | return scale;
|
15558 | }
|
15559 |
|
15560 | scale.domain = function(_) {
|
15561 | return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1];
|
15562 | };
|
15563 |
|
15564 | scale.range = function(_) {
|
15565 | return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice();
|
15566 | };
|
15567 |
|
15568 | scale.invertExtent = function(y) {
|
15569 | var i = range.indexOf(y);
|
15570 | return i < 0 ? [NaN, NaN]
|
15571 | : i < 1 ? [x0, domain[0]]
|
15572 | : i >= n ? [domain[n - 1], x1]
|
15573 | : [domain[i - 1], domain[i]];
|
15574 | };
|
15575 |
|
15576 | scale.unknown = function(_) {
|
15577 | return arguments.length ? (unknown = _, scale) : scale;
|
15578 | };
|
15579 |
|
15580 | scale.thresholds = function() {
|
15581 | return domain.slice();
|
15582 | };
|
15583 |
|
15584 | scale.copy = function() {
|
15585 | return quantize()
|
15586 | .domain([x0, x1])
|
15587 | .range(range)
|
15588 | .unknown(unknown);
|
15589 | };
|
15590 |
|
15591 | return initRange.apply(linearish(scale), arguments);
|
15592 | }
|
15593 |
|
15594 | function threshold() {
|
15595 | var domain = [0.5],
|
15596 | range = [0, 1],
|
15597 | unknown,
|
15598 | n = 1;
|
15599 |
|
15600 | function scale(x) {
|
15601 | return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown;
|
15602 | }
|
15603 |
|
15604 | scale.domain = function(_) {
|
15605 | return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
|
15606 | };
|
15607 |
|
15608 | scale.range = function(_) {
|
15609 | return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
|
15610 | };
|
15611 |
|
15612 | scale.invertExtent = function(y) {
|
15613 | var i = range.indexOf(y);
|
15614 | return [domain[i - 1], domain[i]];
|
15615 | };
|
15616 |
|
15617 | scale.unknown = function(_) {
|
15618 | return arguments.length ? (unknown = _, scale) : unknown;
|
15619 | };
|
15620 |
|
15621 | scale.copy = function() {
|
15622 | return threshold()
|
15623 | .domain(domain)
|
15624 | .range(range)
|
15625 | .unknown(unknown);
|
15626 | };
|
15627 |
|
15628 | return initRange.apply(scale, arguments);
|
15629 | }
|
15630 |
|
15631 | const t0 = new Date, t1 = new Date;
|
15632 |
|
15633 | function timeInterval(floori, offseti, count, field) {
|
15634 |
|
15635 | function interval(date) {
|
15636 | return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
|
15637 | }
|
15638 |
|
15639 | interval.floor = (date) => {
|
15640 | return floori(date = new Date(+date)), date;
|
15641 | };
|
15642 |
|
15643 | interval.ceil = (date) => {
|
15644 | return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
|
15645 | };
|
15646 |
|
15647 | interval.round = (date) => {
|
15648 | const d0 = interval(date), d1 = interval.ceil(date);
|
15649 | return date - d0 < d1 - date ? d0 : d1;
|
15650 | };
|
15651 |
|
15652 | interval.offset = (date, step) => {
|
15653 | return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
|
15654 | };
|
15655 |
|
15656 | interval.range = (start, stop, step) => {
|
15657 | const range = [];
|
15658 | start = interval.ceil(start);
|
15659 | step = step == null ? 1 : Math.floor(step);
|
15660 | if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
|
15661 | let previous;
|
15662 | do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
|
15663 | while (previous < start && start < stop);
|
15664 | return range;
|
15665 | };
|
15666 |
|
15667 | interval.filter = (test) => {
|
15668 | return timeInterval((date) => {
|
15669 | if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
|
15670 | }, (date, step) => {
|
15671 | if (date >= date) {
|
15672 | if (step < 0) while (++step <= 0) {
|
15673 | while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
|
15674 | } else while (--step >= 0) {
|
15675 | while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
|
15676 | }
|
15677 | }
|
15678 | });
|
15679 | };
|
15680 |
|
15681 | if (count) {
|
15682 | interval.count = (start, end) => {
|
15683 | t0.setTime(+start), t1.setTime(+end);
|
15684 | floori(t0), floori(t1);
|
15685 | return Math.floor(count(t0, t1));
|
15686 | };
|
15687 |
|
15688 | interval.every = (step) => {
|
15689 | step = Math.floor(step);
|
15690 | return !isFinite(step) || !(step > 0) ? null
|
15691 | : !(step > 1) ? interval
|
15692 | : interval.filter(field
|
15693 | ? (d) => field(d) % step === 0
|
15694 | : (d) => interval.count(0, d) % step === 0);
|
15695 | };
|
15696 | }
|
15697 |
|
15698 | return interval;
|
15699 | }
|
15700 |
|
15701 | const millisecond = timeInterval(() => {
|
15702 | // noop
|
15703 | }, (date, step) => {
|
15704 | date.setTime(+date + step);
|
15705 | }, (start, end) => {
|
15706 | return end - start;
|
15707 | });
|
15708 |
|
15709 | // An optimized implementation for this simple case.
|
15710 | millisecond.every = (k) => {
|
15711 | k = Math.floor(k);
|
15712 | if (!isFinite(k) || !(k > 0)) return null;
|
15713 | if (!(k > 1)) return millisecond;
|
15714 | return timeInterval((date) => {
|
15715 | date.setTime(Math.floor(date / k) * k);
|
15716 | }, (date, step) => {
|
15717 | date.setTime(+date + step * k);
|
15718 | }, (start, end) => {
|
15719 | return (end - start) / k;
|
15720 | });
|
15721 | };
|
15722 |
|
15723 | const milliseconds = millisecond.range;
|
15724 |
|
15725 | const durationSecond = 1000;
|
15726 | const durationMinute = durationSecond * 60;
|
15727 | const durationHour = durationMinute * 60;
|
15728 | const durationDay = durationHour * 24;
|
15729 | const durationWeek = durationDay * 7;
|
15730 | const durationMonth = durationDay * 30;
|
15731 | const durationYear = durationDay * 365;
|
15732 |
|
15733 | const second = timeInterval((date) => {
|
15734 | date.setTime(date - date.getMilliseconds());
|
15735 | }, (date, step) => {
|
15736 | date.setTime(+date + step * durationSecond);
|
15737 | }, (start, end) => {
|
15738 | return (end - start) / durationSecond;
|
15739 | }, (date) => {
|
15740 | return date.getUTCSeconds();
|
15741 | });
|
15742 |
|
15743 | const seconds = second.range;
|
15744 |
|
15745 | const timeMinute = timeInterval((date) => {
|
15746 | date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
|
15747 | }, (date, step) => {
|
15748 | date.setTime(+date + step * durationMinute);
|
15749 | }, (start, end) => {
|
15750 | return (end - start) / durationMinute;
|
15751 | }, (date) => {
|
15752 | return date.getMinutes();
|
15753 | });
|
15754 |
|
15755 | const timeMinutes = timeMinute.range;
|
15756 |
|
15757 | const utcMinute = timeInterval((date) => {
|
15758 | date.setUTCSeconds(0, 0);
|
15759 | }, (date, step) => {
|
15760 | date.setTime(+date + step * durationMinute);
|
15761 | }, (start, end) => {
|
15762 | return (end - start) / durationMinute;
|
15763 | }, (date) => {
|
15764 | return date.getUTCMinutes();
|
15765 | });
|
15766 |
|
15767 | const utcMinutes = utcMinute.range;
|
15768 |
|
15769 | const timeHour = timeInterval((date) => {
|
15770 | date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
|
15771 | }, (date, step) => {
|
15772 | date.setTime(+date + step * durationHour);
|
15773 | }, (start, end) => {
|
15774 | return (end - start) / durationHour;
|
15775 | }, (date) => {
|
15776 | return date.getHours();
|
15777 | });
|
15778 |
|
15779 | const timeHours = timeHour.range;
|
15780 |
|
15781 | const utcHour = timeInterval((date) => {
|
15782 | date.setUTCMinutes(0, 0, 0);
|
15783 | }, (date, step) => {
|
15784 | date.setTime(+date + step * durationHour);
|
15785 | }, (start, end) => {
|
15786 | return (end - start) / durationHour;
|
15787 | }, (date) => {
|
15788 | return date.getUTCHours();
|
15789 | });
|
15790 |
|
15791 | const utcHours = utcHour.range;
|
15792 |
|
15793 | const timeDay = timeInterval(
|
15794 | date => date.setHours(0, 0, 0, 0),
|
15795 | (date, step) => date.setDate(date.getDate() + step),
|
15796 | (start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay,
|
15797 | date => date.getDate() - 1
|
15798 | );
|
15799 |
|
15800 | const timeDays = timeDay.range;
|
15801 |
|
15802 | const utcDay = timeInterval((date) => {
|
15803 | date.setUTCHours(0, 0, 0, 0);
|
15804 | }, (date, step) => {
|
15805 | date.setUTCDate(date.getUTCDate() + step);
|
15806 | }, (start, end) => {
|
15807 | return (end - start) / durationDay;
|
15808 | }, (date) => {
|
15809 | return date.getUTCDate() - 1;
|
15810 | });
|
15811 |
|
15812 | const utcDays = utcDay.range;
|
15813 |
|
15814 | const unixDay = timeInterval((date) => {
|
15815 | date.setUTCHours(0, 0, 0, 0);
|
15816 | }, (date, step) => {
|
15817 | date.setUTCDate(date.getUTCDate() + step);
|
15818 | }, (start, end) => {
|
15819 | return (end - start) / durationDay;
|
15820 | }, (date) => {
|
15821 | return Math.floor(date / durationDay);
|
15822 | });
|
15823 |
|
15824 | const unixDays = unixDay.range;
|
15825 |
|
15826 | function timeWeekday(i) {
|
15827 | return timeInterval((date) => {
|
15828 | date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
|
15829 | date.setHours(0, 0, 0, 0);
|
15830 | }, (date, step) => {
|
15831 | date.setDate(date.getDate() + step * 7);
|
15832 | }, (start, end) => {
|
15833 | return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
|
15834 | });
|
15835 | }
|
15836 |
|
15837 | const timeSunday = timeWeekday(0);
|
15838 | const timeMonday = timeWeekday(1);
|
15839 | const timeTuesday = timeWeekday(2);
|
15840 | const timeWednesday = timeWeekday(3);
|
15841 | const timeThursday = timeWeekday(4);
|
15842 | const timeFriday = timeWeekday(5);
|
15843 | const timeSaturday = timeWeekday(6);
|
15844 |
|
15845 | const timeSundays = timeSunday.range;
|
15846 | const timeMondays = timeMonday.range;
|
15847 | const timeTuesdays = timeTuesday.range;
|
15848 | const timeWednesdays = timeWednesday.range;
|
15849 | const timeThursdays = timeThursday.range;
|
15850 | const timeFridays = timeFriday.range;
|
15851 | const timeSaturdays = timeSaturday.range;
|
15852 |
|
15853 | function utcWeekday(i) {
|
15854 | return timeInterval((date) => {
|
15855 | date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
|
15856 | date.setUTCHours(0, 0, 0, 0);
|
15857 | }, (date, step) => {
|
15858 | date.setUTCDate(date.getUTCDate() + step * 7);
|
15859 | }, (start, end) => {
|
15860 | return (end - start) / durationWeek;
|
15861 | });
|
15862 | }
|
15863 |
|
15864 | const utcSunday = utcWeekday(0);
|
15865 | const utcMonday = utcWeekday(1);
|
15866 | const utcTuesday = utcWeekday(2);
|
15867 | const utcWednesday = utcWeekday(3);
|
15868 | const utcThursday = utcWeekday(4);
|
15869 | const utcFriday = utcWeekday(5);
|
15870 | const utcSaturday = utcWeekday(6);
|
15871 |
|
15872 | const utcSundays = utcSunday.range;
|
15873 | const utcMondays = utcMonday.range;
|
15874 | const utcTuesdays = utcTuesday.range;
|
15875 | const utcWednesdays = utcWednesday.range;
|
15876 | const utcThursdays = utcThursday.range;
|
15877 | const utcFridays = utcFriday.range;
|
15878 | const utcSaturdays = utcSaturday.range;
|
15879 |
|
15880 | const timeMonth = timeInterval((date) => {
|
15881 | date.setDate(1);
|
15882 | date.setHours(0, 0, 0, 0);
|
15883 | }, (date, step) => {
|
15884 | date.setMonth(date.getMonth() + step);
|
15885 | }, (start, end) => {
|
15886 | return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
|
15887 | }, (date) => {
|
15888 | return date.getMonth();
|
15889 | });
|
15890 |
|
15891 | const timeMonths = timeMonth.range;
|
15892 |
|
15893 | const utcMonth = timeInterval((date) => {
|
15894 | date.setUTCDate(1);
|
15895 | date.setUTCHours(0, 0, 0, 0);
|
15896 | }, (date, step) => {
|
15897 | date.setUTCMonth(date.getUTCMonth() + step);
|
15898 | }, (start, end) => {
|
15899 | return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
|
15900 | }, (date) => {
|
15901 | return date.getUTCMonth();
|
15902 | });
|
15903 |
|
15904 | const utcMonths = utcMonth.range;
|
15905 |
|
15906 | const timeYear = timeInterval((date) => {
|
15907 | date.setMonth(0, 1);
|
15908 | date.setHours(0, 0, 0, 0);
|
15909 | }, (date, step) => {
|
15910 | date.setFullYear(date.getFullYear() + step);
|
15911 | }, (start, end) => {
|
15912 | return end.getFullYear() - start.getFullYear();
|
15913 | }, (date) => {
|
15914 | return date.getFullYear();
|
15915 | });
|
15916 |
|
15917 | // An optimized implementation for this simple case.
|
15918 | timeYear.every = (k) => {
|
15919 | return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
|
15920 | date.setFullYear(Math.floor(date.getFullYear() / k) * k);
|
15921 | date.setMonth(0, 1);
|
15922 | date.setHours(0, 0, 0, 0);
|
15923 | }, (date, step) => {
|
15924 | date.setFullYear(date.getFullYear() + step * k);
|
15925 | });
|
15926 | };
|
15927 |
|
15928 | const timeYears = timeYear.range;
|
15929 |
|
15930 | const utcYear = timeInterval((date) => {
|
15931 | date.setUTCMonth(0, 1);
|
15932 | date.setUTCHours(0, 0, 0, 0);
|
15933 | }, (date, step) => {
|
15934 | date.setUTCFullYear(date.getUTCFullYear() + step);
|
15935 | }, (start, end) => {
|
15936 | return end.getUTCFullYear() - start.getUTCFullYear();
|
15937 | }, (date) => {
|
15938 | return date.getUTCFullYear();
|
15939 | });
|
15940 |
|
15941 | // An optimized implementation for this simple case.
|
15942 | utcYear.every = (k) => {
|
15943 | return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => {
|
15944 | date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
|
15945 | date.setUTCMonth(0, 1);
|
15946 | date.setUTCHours(0, 0, 0, 0);
|
15947 | }, (date, step) => {
|
15948 | date.setUTCFullYear(date.getUTCFullYear() + step * k);
|
15949 | });
|
15950 | };
|
15951 |
|
15952 | const utcYears = utcYear.range;
|
15953 |
|
15954 | function ticker(year, month, week, day, hour, minute) {
|
15955 |
|
15956 | const tickIntervals = [
|
15957 | [second, 1, durationSecond],
|
15958 | [second, 5, 5 * durationSecond],
|
15959 | [second, 15, 15 * durationSecond],
|
15960 | [second, 30, 30 * durationSecond],
|
15961 | [minute, 1, durationMinute],
|
15962 | [minute, 5, 5 * durationMinute],
|
15963 | [minute, 15, 15 * durationMinute],
|
15964 | [minute, 30, 30 * durationMinute],
|
15965 | [ hour, 1, durationHour ],
|
15966 | [ hour, 3, 3 * durationHour ],
|
15967 | [ hour, 6, 6 * durationHour ],
|
15968 | [ hour, 12, 12 * durationHour ],
|
15969 | [ day, 1, durationDay ],
|
15970 | [ day, 2, 2 * durationDay ],
|
15971 | [ week, 1, durationWeek ],
|
15972 | [ month, 1, durationMonth ],
|
15973 | [ month, 3, 3 * durationMonth ],
|
15974 | [ year, 1, durationYear ]
|
15975 | ];
|
15976 |
|
15977 | function ticks(start, stop, count) {
|
15978 | const reverse = stop < start;
|
15979 | if (reverse) [start, stop] = [stop, start];
|
15980 | const interval = count && typeof count.range === "function" ? count : tickInterval(start, stop, count);
|
15981 | const ticks = interval ? interval.range(start, +stop + 1) : []; // inclusive stop
|
15982 | return reverse ? ticks.reverse() : ticks;
|
15983 | }
|
15984 |
|
15985 | function tickInterval(start, stop, count) {
|
15986 | const target = Math.abs(stop - start) / count;
|
15987 | const i = bisector(([,, step]) => step).right(tickIntervals, target);
|
15988 | if (i === tickIntervals.length) return year.every(tickStep(start / durationYear, stop / durationYear, count));
|
15989 | if (i === 0) return millisecond.every(Math.max(tickStep(start, stop, count), 1));
|
15990 | const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
|
15991 | return t.every(step);
|
15992 | }
|
15993 |
|
15994 | return [ticks, tickInterval];
|
15995 | }
|
15996 |
|
15997 | const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute);
|
15998 | const [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);
|
15999 |
|
16000 | function localDate(d) {
|
16001 | if (0 <= d.y && d.y < 100) {
|
16002 | var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
|
16003 | date.setFullYear(d.y);
|
16004 | return date;
|
16005 | }
|
16006 | return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
|
16007 | }
|
16008 |
|
16009 | function utcDate(d) {
|
16010 | if (0 <= d.y && d.y < 100) {
|
16011 | var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
|
16012 | date.setUTCFullYear(d.y);
|
16013 | return date;
|
16014 | }
|
16015 | return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
|
16016 | }
|
16017 |
|
16018 | function newDate(y, m, d) {
|
16019 | return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
|
16020 | }
|
16021 |
|
16022 | function formatLocale(locale) {
|
16023 | var locale_dateTime = locale.dateTime,
|
16024 | locale_date = locale.date,
|
16025 | locale_time = locale.time,
|
16026 | locale_periods = locale.periods,
|
16027 | locale_weekdays = locale.days,
|
16028 | locale_shortWeekdays = locale.shortDays,
|
16029 | locale_months = locale.months,
|
16030 | locale_shortMonths = locale.shortMonths;
|
16031 |
|
16032 | var periodRe = formatRe(locale_periods),
|
16033 | periodLookup = formatLookup(locale_periods),
|
16034 | weekdayRe = formatRe(locale_weekdays),
|
16035 | weekdayLookup = formatLookup(locale_weekdays),
|
16036 | shortWeekdayRe = formatRe(locale_shortWeekdays),
|
16037 | shortWeekdayLookup = formatLookup(locale_shortWeekdays),
|
16038 | monthRe = formatRe(locale_months),
|
16039 | monthLookup = formatLookup(locale_months),
|
16040 | shortMonthRe = formatRe(locale_shortMonths),
|
16041 | shortMonthLookup = formatLookup(locale_shortMonths);
|
16042 |
|
16043 | var formats = {
|
16044 | "a": formatShortWeekday,
|
16045 | "A": formatWeekday,
|
16046 | "b": formatShortMonth,
|
16047 | "B": formatMonth,
|
16048 | "c": null,
|
16049 | "d": formatDayOfMonth,
|
16050 | "e": formatDayOfMonth,
|
16051 | "f": formatMicroseconds,
|
16052 | "g": formatYearISO,
|
16053 | "G": formatFullYearISO,
|
16054 | "H": formatHour24,
|
16055 | "I": formatHour12,
|
16056 | "j": formatDayOfYear,
|
16057 | "L": formatMilliseconds,
|
16058 | "m": formatMonthNumber,
|
16059 | "M": formatMinutes,
|
16060 | "p": formatPeriod,
|
16061 | "q": formatQuarter,
|
16062 | "Q": formatUnixTimestamp,
|
16063 | "s": formatUnixTimestampSeconds,
|
16064 | "S": formatSeconds,
|
16065 | "u": formatWeekdayNumberMonday,
|
16066 | "U": formatWeekNumberSunday,
|
16067 | "V": formatWeekNumberISO,
|
16068 | "w": formatWeekdayNumberSunday,
|
16069 | "W": formatWeekNumberMonday,
|
16070 | "x": null,
|
16071 | "X": null,
|
16072 | "y": formatYear,
|
16073 | "Y": formatFullYear,
|
16074 | "Z": formatZone,
|
16075 | "%": formatLiteralPercent
|
16076 | };
|
16077 |
|
16078 | var utcFormats = {
|
16079 | "a": formatUTCShortWeekday,
|
16080 | "A": formatUTCWeekday,
|
16081 | "b": formatUTCShortMonth,
|
16082 | "B": formatUTCMonth,
|
16083 | "c": null,
|
16084 | "d": formatUTCDayOfMonth,
|
16085 | "e": formatUTCDayOfMonth,
|
16086 | "f": formatUTCMicroseconds,
|
16087 | "g": formatUTCYearISO,
|
16088 | "G": formatUTCFullYearISO,
|
16089 | "H": formatUTCHour24,
|
16090 | "I": formatUTCHour12,
|
16091 | "j": formatUTCDayOfYear,
|
16092 | "L": formatUTCMilliseconds,
|
16093 | "m": formatUTCMonthNumber,
|
16094 | "M": formatUTCMinutes,
|
16095 | "p": formatUTCPeriod,
|
16096 | "q": formatUTCQuarter,
|
16097 | "Q": formatUnixTimestamp,
|
16098 | "s": formatUnixTimestampSeconds,
|
16099 | "S": formatUTCSeconds,
|
16100 | "u": formatUTCWeekdayNumberMonday,
|
16101 | "U": formatUTCWeekNumberSunday,
|
16102 | "V": formatUTCWeekNumberISO,
|
16103 | "w": formatUTCWeekdayNumberSunday,
|
16104 | "W": formatUTCWeekNumberMonday,
|
16105 | "x": null,
|
16106 | "X": null,
|
16107 | "y": formatUTCYear,
|
16108 | "Y": formatUTCFullYear,
|
16109 | "Z": formatUTCZone,
|
16110 | "%": formatLiteralPercent
|
16111 | };
|
16112 |
|
16113 | var parses = {
|
16114 | "a": parseShortWeekday,
|
16115 | "A": parseWeekday,
|
16116 | "b": parseShortMonth,
|
16117 | "B": parseMonth,
|
16118 | "c": parseLocaleDateTime,
|
16119 | "d": parseDayOfMonth,
|
16120 | "e": parseDayOfMonth,
|
16121 | "f": parseMicroseconds,
|
16122 | "g": parseYear,
|
16123 | "G": parseFullYear,
|
16124 | "H": parseHour24,
|
16125 | "I": parseHour24,
|
16126 | "j": parseDayOfYear,
|
16127 | "L": parseMilliseconds,
|
16128 | "m": parseMonthNumber,
|
16129 | "M": parseMinutes,
|
16130 | "p": parsePeriod,
|
16131 | "q": parseQuarter,
|
16132 | "Q": parseUnixTimestamp,
|
16133 | "s": parseUnixTimestampSeconds,
|
16134 | "S": parseSeconds,
|
16135 | "u": parseWeekdayNumberMonday,
|
16136 | "U": parseWeekNumberSunday,
|
16137 | "V": parseWeekNumberISO,
|
16138 | "w": parseWeekdayNumberSunday,
|
16139 | "W": parseWeekNumberMonday,
|
16140 | "x": parseLocaleDate,
|
16141 | "X": parseLocaleTime,
|
16142 | "y": parseYear,
|
16143 | "Y": parseFullYear,
|
16144 | "Z": parseZone,
|
16145 | "%": parseLiteralPercent
|
16146 | };
|
16147 |
|
16148 | // These recursive directive definitions must be deferred.
|
16149 | formats.x = newFormat(locale_date, formats);
|
16150 | formats.X = newFormat(locale_time, formats);
|
16151 | formats.c = newFormat(locale_dateTime, formats);
|
16152 | utcFormats.x = newFormat(locale_date, utcFormats);
|
16153 | utcFormats.X = newFormat(locale_time, utcFormats);
|
16154 | utcFormats.c = newFormat(locale_dateTime, utcFormats);
|
16155 |
|
16156 | function newFormat(specifier, formats) {
|
16157 | return function(date) {
|
16158 | var string = [],
|
16159 | i = -1,
|
16160 | j = 0,
|
16161 | n = specifier.length,
|
16162 | c,
|
16163 | pad,
|
16164 | format;
|
16165 |
|
16166 | if (!(date instanceof Date)) date = new Date(+date);
|
16167 |
|
16168 | while (++i < n) {
|
16169 | if (specifier.charCodeAt(i) === 37) {
|
16170 | string.push(specifier.slice(j, i));
|
16171 | if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
|
16172 | else pad = c === "e" ? " " : "0";
|
16173 | if (format = formats[c]) c = format(date, pad);
|
16174 | string.push(c);
|
16175 | j = i + 1;
|
16176 | }
|
16177 | }
|
16178 |
|
16179 | string.push(specifier.slice(j, i));
|
16180 | return string.join("");
|
16181 | };
|
16182 | }
|
16183 |
|
16184 | function newParse(specifier, Z) {
|
16185 | return function(string) {
|
16186 | var d = newDate(1900, undefined, 1),
|
16187 | i = parseSpecifier(d, specifier, string += "", 0),
|
16188 | week, day;
|
16189 | if (i != string.length) return null;
|
16190 |
|
16191 | // If a UNIX timestamp is specified, return it.
|
16192 | if ("Q" in d) return new Date(d.Q);
|
16193 | if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
|
16194 |
|
16195 | // If this is utcParse, never use the local timezone.
|
16196 | if (Z && !("Z" in d)) d.Z = 0;
|
16197 |
|
16198 | // The am-pm flag is 0 for AM, and 1 for PM.
|
16199 | if ("p" in d) d.H = d.H % 12 + d.p * 12;
|
16200 |
|
16201 | // If the month was not specified, inherit from the quarter.
|
16202 | if (d.m === undefined) d.m = "q" in d ? d.q : 0;
|
16203 |
|
16204 | // Convert day-of-week and week-of-year to day-of-year.
|
16205 | if ("V" in d) {
|
16206 | if (d.V < 1 || d.V > 53) return null;
|
16207 | if (!("w" in d)) d.w = 1;
|
16208 | if ("Z" in d) {
|
16209 | week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
|
16210 | week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
|
16211 | week = utcDay.offset(week, (d.V - 1) * 7);
|
16212 | d.y = week.getUTCFullYear();
|
16213 | d.m = week.getUTCMonth();
|
16214 | d.d = week.getUTCDate() + (d.w + 6) % 7;
|
16215 | } else {
|
16216 | week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
|
16217 | week = day > 4 || day === 0 ? timeMonday.ceil(week) : timeMonday(week);
|
16218 | week = timeDay.offset(week, (d.V - 1) * 7);
|
16219 | d.y = week.getFullYear();
|
16220 | d.m = week.getMonth();
|
16221 | d.d = week.getDate() + (d.w + 6) % 7;
|
16222 | }
|
16223 | } else if ("W" in d || "U" in d) {
|
16224 | if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
|
16225 | day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
|
16226 | d.m = 0;
|
16227 | d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
|
16228 | }
|
16229 |
|
16230 | // If a time zone is specified, all fields are interpreted as UTC and then
|
16231 | // offset according to the specified time zone.
|
16232 | if ("Z" in d) {
|
16233 | d.H += d.Z / 100 | 0;
|
16234 | d.M += d.Z % 100;
|
16235 | return utcDate(d);
|
16236 | }
|
16237 |
|
16238 | // Otherwise, all fields are in local time.
|
16239 | return localDate(d);
|
16240 | };
|
16241 | }
|
16242 |
|
16243 | function parseSpecifier(d, specifier, string, j) {
|
16244 | var i = 0,
|
16245 | n = specifier.length,
|
16246 | m = string.length,
|
16247 | c,
|
16248 | parse;
|
16249 |
|
16250 | while (i < n) {
|
16251 | if (j >= m) return -1;
|
16252 | c = specifier.charCodeAt(i++);
|
16253 | if (c === 37) {
|
16254 | c = specifier.charAt(i++);
|
16255 | parse = parses[c in pads ? specifier.charAt(i++) : c];
|
16256 | if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
|
16257 | } else if (c != string.charCodeAt(j++)) {
|
16258 | return -1;
|
16259 | }
|
16260 | }
|
16261 |
|
16262 | return j;
|
16263 | }
|
16264 |
|
16265 | function parsePeriod(d, string, i) {
|
16266 | var n = periodRe.exec(string.slice(i));
|
16267 | return n ? (d.p = periodLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16268 | }
|
16269 |
|
16270 | function parseShortWeekday(d, string, i) {
|
16271 | var n = shortWeekdayRe.exec(string.slice(i));
|
16272 | return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16273 | }
|
16274 |
|
16275 | function parseWeekday(d, string, i) {
|
16276 | var n = weekdayRe.exec(string.slice(i));
|
16277 | return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16278 | }
|
16279 |
|
16280 | function parseShortMonth(d, string, i) {
|
16281 | var n = shortMonthRe.exec(string.slice(i));
|
16282 | return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16283 | }
|
16284 |
|
16285 | function parseMonth(d, string, i) {
|
16286 | var n = monthRe.exec(string.slice(i));
|
16287 | return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
|
16288 | }
|
16289 |
|
16290 | function parseLocaleDateTime(d, string, i) {
|
16291 | return parseSpecifier(d, locale_dateTime, string, i);
|
16292 | }
|
16293 |
|
16294 | function parseLocaleDate(d, string, i) {
|
16295 | return parseSpecifier(d, locale_date, string, i);
|
16296 | }
|
16297 |
|
16298 | function parseLocaleTime(d, string, i) {
|
16299 | return parseSpecifier(d, locale_time, string, i);
|
16300 | }
|
16301 |
|
16302 | function formatShortWeekday(d) {
|
16303 | return locale_shortWeekdays[d.getDay()];
|
16304 | }
|
16305 |
|
16306 | function formatWeekday(d) {
|
16307 | return locale_weekdays[d.getDay()];
|
16308 | }
|
16309 |
|
16310 | function formatShortMonth(d) {
|
16311 | return locale_shortMonths[d.getMonth()];
|
16312 | }
|
16313 |
|
16314 | function formatMonth(d) {
|
16315 | return locale_months[d.getMonth()];
|
16316 | }
|
16317 |
|
16318 | function formatPeriod(d) {
|
16319 | return locale_periods[+(d.getHours() >= 12)];
|
16320 | }
|
16321 |
|
16322 | function formatQuarter(d) {
|
16323 | return 1 + ~~(d.getMonth() / 3);
|
16324 | }
|
16325 |
|
16326 | function formatUTCShortWeekday(d) {
|
16327 | return locale_shortWeekdays[d.getUTCDay()];
|
16328 | }
|
16329 |
|
16330 | function formatUTCWeekday(d) {
|
16331 | return locale_weekdays[d.getUTCDay()];
|
16332 | }
|
16333 |
|
16334 | function formatUTCShortMonth(d) {
|
16335 | return locale_shortMonths[d.getUTCMonth()];
|
16336 | }
|
16337 |
|
16338 | function formatUTCMonth(d) {
|
16339 | return locale_months[d.getUTCMonth()];
|
16340 | }
|
16341 |
|
16342 | function formatUTCPeriod(d) {
|
16343 | return locale_periods[+(d.getUTCHours() >= 12)];
|
16344 | }
|
16345 |
|
16346 | function formatUTCQuarter(d) {
|
16347 | return 1 + ~~(d.getUTCMonth() / 3);
|
16348 | }
|
16349 |
|
16350 | return {
|
16351 | format: function(specifier) {
|
16352 | var f = newFormat(specifier += "", formats);
|
16353 | f.toString = function() { return specifier; };
|
16354 | return f;
|
16355 | },
|
16356 | parse: function(specifier) {
|
16357 | var p = newParse(specifier += "", false);
|
16358 | p.toString = function() { return specifier; };
|
16359 | return p;
|
16360 | },
|
16361 | utcFormat: function(specifier) {
|
16362 | var f = newFormat(specifier += "", utcFormats);
|
16363 | f.toString = function() { return specifier; };
|
16364 | return f;
|
16365 | },
|
16366 | utcParse: function(specifier) {
|
16367 | var p = newParse(specifier += "", true);
|
16368 | p.toString = function() { return specifier; };
|
16369 | return p;
|
16370 | }
|
16371 | };
|
16372 | }
|
16373 |
|
16374 | var pads = {"-": "", "_": " ", "0": "0"},
|
16375 | numberRe = /^\s*\d+/, // note: ignores next directive
|
16376 | percentRe = /^%/,
|
16377 | requoteRe = /[\\^$*+?|[\]().{}]/g;
|
16378 |
|
16379 | function pad(value, fill, width) {
|
16380 | var sign = value < 0 ? "-" : "",
|
16381 | string = (sign ? -value : value) + "",
|
16382 | length = string.length;
|
16383 | return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
|
16384 | }
|
16385 |
|
16386 | function requote(s) {
|
16387 | return s.replace(requoteRe, "\\$&");
|
16388 | }
|
16389 |
|
16390 | function formatRe(names) {
|
16391 | return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
|
16392 | }
|
16393 |
|
16394 | function formatLookup(names) {
|
16395 | return new Map(names.map((name, i) => [name.toLowerCase(), i]));
|
16396 | }
|
16397 |
|
16398 | function parseWeekdayNumberSunday(d, string, i) {
|
16399 | var n = numberRe.exec(string.slice(i, i + 1));
|
16400 | return n ? (d.w = +n[0], i + n[0].length) : -1;
|
16401 | }
|
16402 |
|
16403 | function parseWeekdayNumberMonday(d, string, i) {
|
16404 | var n = numberRe.exec(string.slice(i, i + 1));
|
16405 | return n ? (d.u = +n[0], i + n[0].length) : -1;
|
16406 | }
|
16407 |
|
16408 | function parseWeekNumberSunday(d, string, i) {
|
16409 | var n = numberRe.exec(string.slice(i, i + 2));
|
16410 | return n ? (d.U = +n[0], i + n[0].length) : -1;
|
16411 | }
|
16412 |
|
16413 | function parseWeekNumberISO(d, string, i) {
|
16414 | var n = numberRe.exec(string.slice(i, i + 2));
|
16415 | return n ? (d.V = +n[0], i + n[0].length) : -1;
|
16416 | }
|
16417 |
|
16418 | function parseWeekNumberMonday(d, string, i) {
|
16419 | var n = numberRe.exec(string.slice(i, i + 2));
|
16420 | return n ? (d.W = +n[0], i + n[0].length) : -1;
|
16421 | }
|
16422 |
|
16423 | function parseFullYear(d, string, i) {
|
16424 | var n = numberRe.exec(string.slice(i, i + 4));
|
16425 | return n ? (d.y = +n[0], i + n[0].length) : -1;
|
16426 | }
|
16427 |
|
16428 | function parseYear(d, string, i) {
|
16429 | var n = numberRe.exec(string.slice(i, i + 2));
|
16430 | return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
|
16431 | }
|
16432 |
|
16433 | function parseZone(d, string, i) {
|
16434 | var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
|
16435 | return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
|
16436 | }
|
16437 |
|
16438 | function parseQuarter(d, string, i) {
|
16439 | var n = numberRe.exec(string.slice(i, i + 1));
|
16440 | return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
|
16441 | }
|
16442 |
|
16443 | function parseMonthNumber(d, string, i) {
|
16444 | var n = numberRe.exec(string.slice(i, i + 2));
|
16445 | return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
|
16446 | }
|
16447 |
|
16448 | function parseDayOfMonth(d, string, i) {
|
16449 | var n = numberRe.exec(string.slice(i, i + 2));
|
16450 | return n ? (d.d = +n[0], i + n[0].length) : -1;
|
16451 | }
|
16452 |
|
16453 | function parseDayOfYear(d, string, i) {
|
16454 | var n = numberRe.exec(string.slice(i, i + 3));
|
16455 | return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
|
16456 | }
|
16457 |
|
16458 | function parseHour24(d, string, i) {
|
16459 | var n = numberRe.exec(string.slice(i, i + 2));
|
16460 | return n ? (d.H = +n[0], i + n[0].length) : -1;
|
16461 | }
|
16462 |
|
16463 | function parseMinutes(d, string, i) {
|
16464 | var n = numberRe.exec(string.slice(i, i + 2));
|
16465 | return n ? (d.M = +n[0], i + n[0].length) : -1;
|
16466 | }
|
16467 |
|
16468 | function parseSeconds(d, string, i) {
|
16469 | var n = numberRe.exec(string.slice(i, i + 2));
|
16470 | return n ? (d.S = +n[0], i + n[0].length) : -1;
|
16471 | }
|
16472 |
|
16473 | function parseMilliseconds(d, string, i) {
|
16474 | var n = numberRe.exec(string.slice(i, i + 3));
|
16475 | return n ? (d.L = +n[0], i + n[0].length) : -1;
|
16476 | }
|
16477 |
|
16478 | function parseMicroseconds(d, string, i) {
|
16479 | var n = numberRe.exec(string.slice(i, i + 6));
|
16480 | return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
|
16481 | }
|
16482 |
|
16483 | function parseLiteralPercent(d, string, i) {
|
16484 | var n = percentRe.exec(string.slice(i, i + 1));
|
16485 | return n ? i + n[0].length : -1;
|
16486 | }
|
16487 |
|
16488 | function parseUnixTimestamp(d, string, i) {
|
16489 | var n = numberRe.exec(string.slice(i));
|
16490 | return n ? (d.Q = +n[0], i + n[0].length) : -1;
|
16491 | }
|
16492 |
|
16493 | function parseUnixTimestampSeconds(d, string, i) {
|
16494 | var n = numberRe.exec(string.slice(i));
|
16495 | return n ? (d.s = +n[0], i + n[0].length) : -1;
|
16496 | }
|
16497 |
|
16498 | function formatDayOfMonth(d, p) {
|
16499 | return pad(d.getDate(), p, 2);
|
16500 | }
|
16501 |
|
16502 | function formatHour24(d, p) {
|
16503 | return pad(d.getHours(), p, 2);
|
16504 | }
|
16505 |
|
16506 | function formatHour12(d, p) {
|
16507 | return pad(d.getHours() % 12 || 12, p, 2);
|
16508 | }
|
16509 |
|
16510 | function formatDayOfYear(d, p) {
|
16511 | return pad(1 + timeDay.count(timeYear(d), d), p, 3);
|
16512 | }
|
16513 |
|
16514 | function formatMilliseconds(d, p) {
|
16515 | return pad(d.getMilliseconds(), p, 3);
|
16516 | }
|
16517 |
|
16518 | function formatMicroseconds(d, p) {
|
16519 | return formatMilliseconds(d, p) + "000";
|
16520 | }
|
16521 |
|
16522 | function formatMonthNumber(d, p) {
|
16523 | return pad(d.getMonth() + 1, p, 2);
|
16524 | }
|
16525 |
|
16526 | function formatMinutes(d, p) {
|
16527 | return pad(d.getMinutes(), p, 2);
|
16528 | }
|
16529 |
|
16530 | function formatSeconds(d, p) {
|
16531 | return pad(d.getSeconds(), p, 2);
|
16532 | }
|
16533 |
|
16534 | function formatWeekdayNumberMonday(d) {
|
16535 | var day = d.getDay();
|
16536 | return day === 0 ? 7 : day;
|
16537 | }
|
16538 |
|
16539 | function formatWeekNumberSunday(d, p) {
|
16540 | return pad(timeSunday.count(timeYear(d) - 1, d), p, 2);
|
16541 | }
|
16542 |
|
16543 | function dISO(d) {
|
16544 | var day = d.getDay();
|
16545 | return (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d);
|
16546 | }
|
16547 |
|
16548 | function formatWeekNumberISO(d, p) {
|
16549 | d = dISO(d);
|
16550 | return pad(timeThursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2);
|
16551 | }
|
16552 |
|
16553 | function formatWeekdayNumberSunday(d) {
|
16554 | return d.getDay();
|
16555 | }
|
16556 |
|
16557 | function formatWeekNumberMonday(d, p) {
|
16558 | return pad(timeMonday.count(timeYear(d) - 1, d), p, 2);
|
16559 | }
|
16560 |
|
16561 | function formatYear(d, p) {
|
16562 | return pad(d.getFullYear() % 100, p, 2);
|
16563 | }
|
16564 |
|
16565 | function formatYearISO(d, p) {
|
16566 | d = dISO(d);
|
16567 | return pad(d.getFullYear() % 100, p, 2);
|
16568 | }
|
16569 |
|
16570 | function formatFullYear(d, p) {
|
16571 | return pad(d.getFullYear() % 10000, p, 4);
|
16572 | }
|
16573 |
|
16574 | function formatFullYearISO(d, p) {
|
16575 | var day = d.getDay();
|
16576 | d = (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d);
|
16577 | return pad(d.getFullYear() % 10000, p, 4);
|
16578 | }
|
16579 |
|
16580 | function formatZone(d) {
|
16581 | var z = d.getTimezoneOffset();
|
16582 | return (z > 0 ? "-" : (z *= -1, "+"))
|
16583 | + pad(z / 60 | 0, "0", 2)
|
16584 | + pad(z % 60, "0", 2);
|
16585 | }
|
16586 |
|
16587 | function formatUTCDayOfMonth(d, p) {
|
16588 | return pad(d.getUTCDate(), p, 2);
|
16589 | }
|
16590 |
|
16591 | function formatUTCHour24(d, p) {
|
16592 | return pad(d.getUTCHours(), p, 2);
|
16593 | }
|
16594 |
|
16595 | function formatUTCHour12(d, p) {
|
16596 | return pad(d.getUTCHours() % 12 || 12, p, 2);
|
16597 | }
|
16598 |
|
16599 | function formatUTCDayOfYear(d, p) {
|
16600 | return pad(1 + utcDay.count(utcYear(d), d), p, 3);
|
16601 | }
|
16602 |
|
16603 | function formatUTCMilliseconds(d, p) {
|
16604 | return pad(d.getUTCMilliseconds(), p, 3);
|
16605 | }
|
16606 |
|
16607 | function formatUTCMicroseconds(d, p) {
|
16608 | return formatUTCMilliseconds(d, p) + "000";
|
16609 | }
|
16610 |
|
16611 | function formatUTCMonthNumber(d, p) {
|
16612 | return pad(d.getUTCMonth() + 1, p, 2);
|
16613 | }
|
16614 |
|
16615 | function formatUTCMinutes(d, p) {
|
16616 | return pad(d.getUTCMinutes(), p, 2);
|
16617 | }
|
16618 |
|
16619 | function formatUTCSeconds(d, p) {
|
16620 | return pad(d.getUTCSeconds(), p, 2);
|
16621 | }
|
16622 |
|
16623 | function formatUTCWeekdayNumberMonday(d) {
|
16624 | var dow = d.getUTCDay();
|
16625 | return dow === 0 ? 7 : dow;
|
16626 | }
|
16627 |
|
16628 | function formatUTCWeekNumberSunday(d, p) {
|
16629 | return pad(utcSunday.count(utcYear(d) - 1, d), p, 2);
|
16630 | }
|
16631 |
|
16632 | function UTCdISO(d) {
|
16633 | var day = d.getUTCDay();
|
16634 | return (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
|
16635 | }
|
16636 |
|
16637 | function formatUTCWeekNumberISO(d, p) {
|
16638 | d = UTCdISO(d);
|
16639 | return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
|
16640 | }
|
16641 |
|
16642 | function formatUTCWeekdayNumberSunday(d) {
|
16643 | return d.getUTCDay();
|
16644 | }
|
16645 |
|
16646 | function formatUTCWeekNumberMonday(d, p) {
|
16647 | return pad(utcMonday.count(utcYear(d) - 1, d), p, 2);
|
16648 | }
|
16649 |
|
16650 | function formatUTCYear(d, p) {
|
16651 | return pad(d.getUTCFullYear() % 100, p, 2);
|
16652 | }
|
16653 |
|
16654 | function formatUTCYearISO(d, p) {
|
16655 | d = UTCdISO(d);
|
16656 | return pad(d.getUTCFullYear() % 100, p, 2);
|
16657 | }
|
16658 |
|
16659 | function formatUTCFullYear(d, p) {
|
16660 | return pad(d.getUTCFullYear() % 10000, p, 4);
|
16661 | }
|
16662 |
|
16663 | function formatUTCFullYearISO(d, p) {
|
16664 | var day = d.getUTCDay();
|
16665 | d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
|
16666 | return pad(d.getUTCFullYear() % 10000, p, 4);
|
16667 | }
|
16668 |
|
16669 | function formatUTCZone() {
|
16670 | return "+0000";
|
16671 | }
|
16672 |
|
16673 | function formatLiteralPercent() {
|
16674 | return "%";
|
16675 | }
|
16676 |
|
16677 | function formatUnixTimestamp(d) {
|
16678 | return +d;
|
16679 | }
|
16680 |
|
16681 | function formatUnixTimestampSeconds(d) {
|
16682 | return Math.floor(+d / 1000);
|
16683 | }
|
16684 |
|
16685 | var locale;
|
16686 | exports.timeFormat = void 0;
|
16687 | exports.timeParse = void 0;
|
16688 | exports.utcFormat = void 0;
|
16689 | exports.utcParse = void 0;
|
16690 |
|
16691 | defaultLocale({
|
16692 | dateTime: "%x, %X",
|
16693 | date: "%-m/%-d/%Y",
|
16694 | time: "%-I:%M:%S %p",
|
16695 | periods: ["AM", "PM"],
|
16696 | days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
16697 | shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
16698 | months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
16699 | shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
16700 | });
|
16701 |
|
16702 | function defaultLocale(definition) {
|
16703 | locale = formatLocale(definition);
|
16704 | exports.timeFormat = locale.format;
|
16705 | exports.timeParse = locale.parse;
|
16706 | exports.utcFormat = locale.utcFormat;
|
16707 | exports.utcParse = locale.utcParse;
|
16708 | return locale;
|
16709 | }
|
16710 |
|
16711 | var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
|
16712 |
|
16713 | function formatIsoNative(date) {
|
16714 | return date.toISOString();
|
16715 | }
|
16716 |
|
16717 | var formatIso = Date.prototype.toISOString
|
16718 | ? formatIsoNative
|
16719 | : exports.utcFormat(isoSpecifier);
|
16720 |
|
16721 | var formatIso$1 = formatIso;
|
16722 |
|
16723 | function parseIsoNative(string) {
|
16724 | var date = new Date(string);
|
16725 | return isNaN(date) ? null : date;
|
16726 | }
|
16727 |
|
16728 | var parseIso = +new Date("2000-01-01T00:00:00.000Z")
|
16729 | ? parseIsoNative
|
16730 | : exports.utcParse(isoSpecifier);
|
16731 |
|
16732 | var parseIso$1 = parseIso;
|
16733 |
|
16734 | function date(t) {
|
16735 | return new Date(t);
|
16736 | }
|
16737 |
|
16738 | function number(t) {
|
16739 | return t instanceof Date ? +t : +new Date(+t);
|
16740 | }
|
16741 |
|
16742 | function calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format) {
|
16743 | var scale = continuous(),
|
16744 | invert = scale.invert,
|
16745 | domain = scale.domain;
|
16746 |
|
16747 | var formatMillisecond = format(".%L"),
|
16748 | formatSecond = format(":%S"),
|
16749 | formatMinute = format("%I:%M"),
|
16750 | formatHour = format("%I %p"),
|
16751 | formatDay = format("%a %d"),
|
16752 | formatWeek = format("%b %d"),
|
16753 | formatMonth = format("%B"),
|
16754 | formatYear = format("%Y");
|
16755 |
|
16756 | function tickFormat(date) {
|
16757 | return (second(date) < date ? formatMillisecond
|
16758 | : minute(date) < date ? formatSecond
|
16759 | : hour(date) < date ? formatMinute
|
16760 | : day(date) < date ? formatHour
|
16761 | : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
|
16762 | : year(date) < date ? formatMonth
|
16763 | : formatYear)(date);
|
16764 | }
|
16765 |
|
16766 | scale.invert = function(y) {
|
16767 | return new Date(invert(y));
|
16768 | };
|
16769 |
|
16770 | scale.domain = function(_) {
|
16771 | return arguments.length ? domain(Array.from(_, number)) : domain().map(date);
|
16772 | };
|
16773 |
|
16774 | scale.ticks = function(interval) {
|
16775 | var d = domain();
|
16776 | return ticks(d[0], d[d.length - 1], interval == null ? 10 : interval);
|
16777 | };
|
16778 |
|
16779 | scale.tickFormat = function(count, specifier) {
|
16780 | return specifier == null ? tickFormat : format(specifier);
|
16781 | };
|
16782 |
|
16783 | scale.nice = function(interval) {
|
16784 | var d = domain();
|
16785 | if (!interval || typeof interval.range !== "function") interval = tickInterval(d[0], d[d.length - 1], interval == null ? 10 : interval);
|
16786 | return interval ? domain(nice(d, interval)) : scale;
|
16787 | };
|
16788 |
|
16789 | scale.copy = function() {
|
16790 | return copy$1(scale, calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format));
|
16791 | };
|
16792 |
|
16793 | return scale;
|
16794 | }
|
16795 |
|
16796 | function time() {
|
16797 | return initRange.apply(calendar(timeTicks, timeTickInterval, timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute, second, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
|
16798 | }
|
16799 |
|
16800 | function utcTime() {
|
16801 | return initRange.apply(calendar(utcTicks, utcTickInterval, utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
|
16802 | }
|
16803 |
|
16804 | function transformer$1() {
|
16805 | var x0 = 0,
|
16806 | x1 = 1,
|
16807 | t0,
|
16808 | t1,
|
16809 | k10,
|
16810 | transform,
|
16811 | interpolator = identity$3,
|
16812 | clamp = false,
|
16813 | unknown;
|
16814 |
|
16815 | function scale(x) {
|
16816 | 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));
|
16817 | }
|
16818 |
|
16819 | scale.domain = function(_) {
|
16820 | return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
|
16821 | };
|
16822 |
|
16823 | scale.clamp = function(_) {
|
16824 | return arguments.length ? (clamp = !!_, scale) : clamp;
|
16825 | };
|
16826 |
|
16827 | scale.interpolator = function(_) {
|
16828 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
16829 | };
|
16830 |
|
16831 | function range(interpolate) {
|
16832 | return function(_) {
|
16833 | var r0, r1;
|
16834 | return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)];
|
16835 | };
|
16836 | }
|
16837 |
|
16838 | scale.range = range(interpolate$2);
|
16839 |
|
16840 | scale.rangeRound = range(interpolateRound);
|
16841 |
|
16842 | scale.unknown = function(_) {
|
16843 | return arguments.length ? (unknown = _, scale) : unknown;
|
16844 | };
|
16845 |
|
16846 | return function(t) {
|
16847 | transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
|
16848 | return scale;
|
16849 | };
|
16850 | }
|
16851 |
|
16852 | function copy(source, target) {
|
16853 | return target
|
16854 | .domain(source.domain())
|
16855 | .interpolator(source.interpolator())
|
16856 | .clamp(source.clamp())
|
16857 | .unknown(source.unknown());
|
16858 | }
|
16859 |
|
16860 | function sequential() {
|
16861 | var scale = linearish(transformer$1()(identity$3));
|
16862 |
|
16863 | scale.copy = function() {
|
16864 | return copy(scale, sequential());
|
16865 | };
|
16866 |
|
16867 | return initInterpolator.apply(scale, arguments);
|
16868 | }
|
16869 |
|
16870 | function sequentialLog() {
|
16871 | var scale = loggish(transformer$1()).domain([1, 10]);
|
16872 |
|
16873 | scale.copy = function() {
|
16874 | return copy(scale, sequentialLog()).base(scale.base());
|
16875 | };
|
16876 |
|
16877 | return initInterpolator.apply(scale, arguments);
|
16878 | }
|
16879 |
|
16880 | function sequentialSymlog() {
|
16881 | var scale = symlogish(transformer$1());
|
16882 |
|
16883 | scale.copy = function() {
|
16884 | return copy(scale, sequentialSymlog()).constant(scale.constant());
|
16885 | };
|
16886 |
|
16887 | return initInterpolator.apply(scale, arguments);
|
16888 | }
|
16889 |
|
16890 | function sequentialPow() {
|
16891 | var scale = powish(transformer$1());
|
16892 |
|
16893 | scale.copy = function() {
|
16894 | return copy(scale, sequentialPow()).exponent(scale.exponent());
|
16895 | };
|
16896 |
|
16897 | return initInterpolator.apply(scale, arguments);
|
16898 | }
|
16899 |
|
16900 | function sequentialSqrt() {
|
16901 | return sequentialPow.apply(null, arguments).exponent(0.5);
|
16902 | }
|
16903 |
|
16904 | function sequentialQuantile() {
|
16905 | var domain = [],
|
16906 | interpolator = identity$3;
|
16907 |
|
16908 | function scale(x) {
|
16909 | if (x != null && !isNaN(x = +x)) return interpolator((bisect(domain, x, 1) - 1) / (domain.length - 1));
|
16910 | }
|
16911 |
|
16912 | scale.domain = function(_) {
|
16913 | if (!arguments.length) return domain.slice();
|
16914 | domain = [];
|
16915 | for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d);
|
16916 | domain.sort(ascending$3);
|
16917 | return scale;
|
16918 | };
|
16919 |
|
16920 | scale.interpolator = function(_) {
|
16921 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
16922 | };
|
16923 |
|
16924 | scale.range = function() {
|
16925 | return domain.map((d, i) => interpolator(i / (domain.length - 1)));
|
16926 | };
|
16927 |
|
16928 | scale.quantiles = function(n) {
|
16929 | return Array.from({length: n + 1}, (_, i) => quantile$1(domain, i / n));
|
16930 | };
|
16931 |
|
16932 | scale.copy = function() {
|
16933 | return sequentialQuantile(interpolator).domain(domain);
|
16934 | };
|
16935 |
|
16936 | return initInterpolator.apply(scale, arguments);
|
16937 | }
|
16938 |
|
16939 | function transformer() {
|
16940 | var x0 = 0,
|
16941 | x1 = 0.5,
|
16942 | x2 = 1,
|
16943 | s = 1,
|
16944 | t0,
|
16945 | t1,
|
16946 | t2,
|
16947 | k10,
|
16948 | k21,
|
16949 | interpolator = identity$3,
|
16950 | transform,
|
16951 | clamp = false,
|
16952 | unknown;
|
16953 |
|
16954 | function scale(x) {
|
16955 | 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));
|
16956 | }
|
16957 |
|
16958 | scale.domain = function(_) {
|
16959 | 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];
|
16960 | };
|
16961 |
|
16962 | scale.clamp = function(_) {
|
16963 | return arguments.length ? (clamp = !!_, scale) : clamp;
|
16964 | };
|
16965 |
|
16966 | scale.interpolator = function(_) {
|
16967 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
16968 | };
|
16969 |
|
16970 | function range(interpolate) {
|
16971 | return function(_) {
|
16972 | var r0, r1, r2;
|
16973 | return arguments.length ? ([r0, r1, r2] = _, interpolator = piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)];
|
16974 | };
|
16975 | }
|
16976 |
|
16977 | scale.range = range(interpolate$2);
|
16978 |
|
16979 | scale.rangeRound = range(interpolateRound);
|
16980 |
|
16981 | scale.unknown = function(_) {
|
16982 | return arguments.length ? (unknown = _, scale) : unknown;
|
16983 | };
|
16984 |
|
16985 | return function(t) {
|
16986 | 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;
|
16987 | return scale;
|
16988 | };
|
16989 | }
|
16990 |
|
16991 | function diverging$1() {
|
16992 | var scale = linearish(transformer()(identity$3));
|
16993 |
|
16994 | scale.copy = function() {
|
16995 | return copy(scale, diverging$1());
|
16996 | };
|
16997 |
|
16998 | return initInterpolator.apply(scale, arguments);
|
16999 | }
|
17000 |
|
17001 | function divergingLog() {
|
17002 | var scale = loggish(transformer()).domain([0.1, 1, 10]);
|
17003 |
|
17004 | scale.copy = function() {
|
17005 | return copy(scale, divergingLog()).base(scale.base());
|
17006 | };
|
17007 |
|
17008 | return initInterpolator.apply(scale, arguments);
|
17009 | }
|
17010 |
|
17011 | function divergingSymlog() {
|
17012 | var scale = symlogish(transformer());
|
17013 |
|
17014 | scale.copy = function() {
|
17015 | return copy(scale, divergingSymlog()).constant(scale.constant());
|
17016 | };
|
17017 |
|
17018 | return initInterpolator.apply(scale, arguments);
|
17019 | }
|
17020 |
|
17021 | function divergingPow() {
|
17022 | var scale = powish(transformer());
|
17023 |
|
17024 | scale.copy = function() {
|
17025 | return copy(scale, divergingPow()).exponent(scale.exponent());
|
17026 | };
|
17027 |
|
17028 | return initInterpolator.apply(scale, arguments);
|
17029 | }
|
17030 |
|
17031 | function divergingSqrt() {
|
17032 | return divergingPow.apply(null, arguments).exponent(0.5);
|
17033 | }
|
17034 |
|
17035 | function colors(specifier) {
|
17036 | var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
|
17037 | while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
|
17038 | return colors;
|
17039 | }
|
17040 |
|
17041 | var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
|
17042 |
|
17043 | var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
|
17044 |
|
17045 | var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
|
17046 |
|
17047 | var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
|
17048 |
|
17049 | var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
|
17050 |
|
17051 | var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
|
17052 |
|
17053 | var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
|
17054 |
|
17055 | var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
|
17056 |
|
17057 | var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
|
17058 |
|
17059 | var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
|
17060 |
|
17061 | var ramp$1 = scheme => rgbBasis(scheme[scheme.length - 1]);
|
17062 |
|
17063 | var scheme$q = new Array(3).concat(
|
17064 | "d8b365f5f5f55ab4ac",
|
17065 | "a6611adfc27d80cdc1018571",
|
17066 | "a6611adfc27df5f5f580cdc1018571",
|
17067 | "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
|
17068 | "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
|
17069 | "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
|
17070 | "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
|
17071 | "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
|
17072 | "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
|
17073 | ).map(colors);
|
17074 |
|
17075 | var BrBG = ramp$1(scheme$q);
|
17076 |
|
17077 | var scheme$p = new Array(3).concat(
|
17078 | "af8dc3f7f7f77fbf7b",
|
17079 | "7b3294c2a5cfa6dba0008837",
|
17080 | "7b3294c2a5cff7f7f7a6dba0008837",
|
17081 | "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
|
17082 | "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
|
17083 | "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
|
17084 | "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
|
17085 | "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
|
17086 | "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
|
17087 | ).map(colors);
|
17088 |
|
17089 | var PRGn = ramp$1(scheme$p);
|
17090 |
|
17091 | var scheme$o = new Array(3).concat(
|
17092 | "e9a3c9f7f7f7a1d76a",
|
17093 | "d01c8bf1b6dab8e1864dac26",
|
17094 | "d01c8bf1b6daf7f7f7b8e1864dac26",
|
17095 | "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
|
17096 | "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
|
17097 | "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
|
17098 | "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
|
17099 | "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
|
17100 | "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
|
17101 | ).map(colors);
|
17102 |
|
17103 | var PiYG = ramp$1(scheme$o);
|
17104 |
|
17105 | var scheme$n = new Array(3).concat(
|
17106 | "998ec3f7f7f7f1a340",
|
17107 | "5e3c99b2abd2fdb863e66101",
|
17108 | "5e3c99b2abd2f7f7f7fdb863e66101",
|
17109 | "542788998ec3d8daebfee0b6f1a340b35806",
|
17110 | "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
|
17111 | "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
|
17112 | "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
|
17113 | "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
|
17114 | "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
|
17115 | ).map(colors);
|
17116 |
|
17117 | var PuOr = ramp$1(scheme$n);
|
17118 |
|
17119 | var scheme$m = new Array(3).concat(
|
17120 | "ef8a62f7f7f767a9cf",
|
17121 | "ca0020f4a58292c5de0571b0",
|
17122 | "ca0020f4a582f7f7f792c5de0571b0",
|
17123 | "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
|
17124 | "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
|
17125 | "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
|
17126 | "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
|
17127 | "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
|
17128 | "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
|
17129 | ).map(colors);
|
17130 |
|
17131 | var RdBu = ramp$1(scheme$m);
|
17132 |
|
17133 | var scheme$l = new Array(3).concat(
|
17134 | "ef8a62ffffff999999",
|
17135 | "ca0020f4a582bababa404040",
|
17136 | "ca0020f4a582ffffffbababa404040",
|
17137 | "b2182bef8a62fddbc7e0e0e09999994d4d4d",
|
17138 | "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
|
17139 | "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
|
17140 | "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
|
17141 | "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
|
17142 | "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
|
17143 | ).map(colors);
|
17144 |
|
17145 | var RdGy = ramp$1(scheme$l);
|
17146 |
|
17147 | var scheme$k = new Array(3).concat(
|
17148 | "fc8d59ffffbf91bfdb",
|
17149 | "d7191cfdae61abd9e92c7bb6",
|
17150 | "d7191cfdae61ffffbfabd9e92c7bb6",
|
17151 | "d73027fc8d59fee090e0f3f891bfdb4575b4",
|
17152 | "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
|
17153 | "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
|
17154 | "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
|
17155 | "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
|
17156 | "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
|
17157 | ).map(colors);
|
17158 |
|
17159 | var RdYlBu = ramp$1(scheme$k);
|
17160 |
|
17161 | var scheme$j = new Array(3).concat(
|
17162 | "fc8d59ffffbf91cf60",
|
17163 | "d7191cfdae61a6d96a1a9641",
|
17164 | "d7191cfdae61ffffbfa6d96a1a9641",
|
17165 | "d73027fc8d59fee08bd9ef8b91cf601a9850",
|
17166 | "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
|
17167 | "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
|
17168 | "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
|
17169 | "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
|
17170 | "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
|
17171 | ).map(colors);
|
17172 |
|
17173 | var RdYlGn = ramp$1(scheme$j);
|
17174 |
|
17175 | var scheme$i = new Array(3).concat(
|
17176 | "fc8d59ffffbf99d594",
|
17177 | "d7191cfdae61abdda42b83ba",
|
17178 | "d7191cfdae61ffffbfabdda42b83ba",
|
17179 | "d53e4ffc8d59fee08be6f59899d5943288bd",
|
17180 | "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
|
17181 | "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
|
17182 | "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
|
17183 | "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
|
17184 | "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
|
17185 | ).map(colors);
|
17186 |
|
17187 | var Spectral = ramp$1(scheme$i);
|
17188 |
|
17189 | var scheme$h = new Array(3).concat(
|
17190 | "e5f5f999d8c92ca25f",
|
17191 | "edf8fbb2e2e266c2a4238b45",
|
17192 | "edf8fbb2e2e266c2a42ca25f006d2c",
|
17193 | "edf8fbccece699d8c966c2a42ca25f006d2c",
|
17194 | "edf8fbccece699d8c966c2a441ae76238b45005824",
|
17195 | "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
|
17196 | "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
|
17197 | ).map(colors);
|
17198 |
|
17199 | var BuGn = ramp$1(scheme$h);
|
17200 |
|
17201 | var scheme$g = new Array(3).concat(
|
17202 | "e0ecf49ebcda8856a7",
|
17203 | "edf8fbb3cde38c96c688419d",
|
17204 | "edf8fbb3cde38c96c68856a7810f7c",
|
17205 | "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
|
17206 | "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
|
17207 | "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
|
17208 | "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
|
17209 | ).map(colors);
|
17210 |
|
17211 | var BuPu = ramp$1(scheme$g);
|
17212 |
|
17213 | var scheme$f = new Array(3).concat(
|
17214 | "e0f3dba8ddb543a2ca",
|
17215 | "f0f9e8bae4bc7bccc42b8cbe",
|
17216 | "f0f9e8bae4bc7bccc443a2ca0868ac",
|
17217 | "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
|
17218 | "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
|
17219 | "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
|
17220 | "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
|
17221 | ).map(colors);
|
17222 |
|
17223 | var GnBu = ramp$1(scheme$f);
|
17224 |
|
17225 | var scheme$e = new Array(3).concat(
|
17226 | "fee8c8fdbb84e34a33",
|
17227 | "fef0d9fdcc8afc8d59d7301f",
|
17228 | "fef0d9fdcc8afc8d59e34a33b30000",
|
17229 | "fef0d9fdd49efdbb84fc8d59e34a33b30000",
|
17230 | "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
|
17231 | "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
|
17232 | "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
|
17233 | ).map(colors);
|
17234 |
|
17235 | var OrRd = ramp$1(scheme$e);
|
17236 |
|
17237 | var scheme$d = new Array(3).concat(
|
17238 | "ece2f0a6bddb1c9099",
|
17239 | "f6eff7bdc9e167a9cf02818a",
|
17240 | "f6eff7bdc9e167a9cf1c9099016c59",
|
17241 | "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
|
17242 | "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
|
17243 | "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
|
17244 | "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
|
17245 | ).map(colors);
|
17246 |
|
17247 | var PuBuGn = ramp$1(scheme$d);
|
17248 |
|
17249 | var scheme$c = new Array(3).concat(
|
17250 | "ece7f2a6bddb2b8cbe",
|
17251 | "f1eef6bdc9e174a9cf0570b0",
|
17252 | "f1eef6bdc9e174a9cf2b8cbe045a8d",
|
17253 | "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
|
17254 | "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
|
17255 | "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
|
17256 | "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
|
17257 | ).map(colors);
|
17258 |
|
17259 | var PuBu = ramp$1(scheme$c);
|
17260 |
|
17261 | var scheme$b = new Array(3).concat(
|
17262 | "e7e1efc994c7dd1c77",
|
17263 | "f1eef6d7b5d8df65b0ce1256",
|
17264 | "f1eef6d7b5d8df65b0dd1c77980043",
|
17265 | "f1eef6d4b9dac994c7df65b0dd1c77980043",
|
17266 | "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
|
17267 | "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
|
17268 | "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
|
17269 | ).map(colors);
|
17270 |
|
17271 | var PuRd = ramp$1(scheme$b);
|
17272 |
|
17273 | var scheme$a = new Array(3).concat(
|
17274 | "fde0ddfa9fb5c51b8a",
|
17275 | "feebe2fbb4b9f768a1ae017e",
|
17276 | "feebe2fbb4b9f768a1c51b8a7a0177",
|
17277 | "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
|
17278 | "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
|
17279 | "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
|
17280 | "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
|
17281 | ).map(colors);
|
17282 |
|
17283 | var RdPu = ramp$1(scheme$a);
|
17284 |
|
17285 | var scheme$9 = new Array(3).concat(
|
17286 | "edf8b17fcdbb2c7fb8",
|
17287 | "ffffcca1dab441b6c4225ea8",
|
17288 | "ffffcca1dab441b6c42c7fb8253494",
|
17289 | "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
|
17290 | "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
|
17291 | "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
|
17292 | "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
|
17293 | ).map(colors);
|
17294 |
|
17295 | var YlGnBu = ramp$1(scheme$9);
|
17296 |
|
17297 | var scheme$8 = new Array(3).concat(
|
17298 | "f7fcb9addd8e31a354",
|
17299 | "ffffccc2e69978c679238443",
|
17300 | "ffffccc2e69978c67931a354006837",
|
17301 | "ffffccd9f0a3addd8e78c67931a354006837",
|
17302 | "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
|
17303 | "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
|
17304 | "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
|
17305 | ).map(colors);
|
17306 |
|
17307 | var YlGn = ramp$1(scheme$8);
|
17308 |
|
17309 | var scheme$7 = new Array(3).concat(
|
17310 | "fff7bcfec44fd95f0e",
|
17311 | "ffffd4fed98efe9929cc4c02",
|
17312 | "ffffd4fed98efe9929d95f0e993404",
|
17313 | "ffffd4fee391fec44ffe9929d95f0e993404",
|
17314 | "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
|
17315 | "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
|
17316 | "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
|
17317 | ).map(colors);
|
17318 |
|
17319 | var YlOrBr = ramp$1(scheme$7);
|
17320 |
|
17321 | var scheme$6 = new Array(3).concat(
|
17322 | "ffeda0feb24cf03b20",
|
17323 | "ffffb2fecc5cfd8d3ce31a1c",
|
17324 | "ffffb2fecc5cfd8d3cf03b20bd0026",
|
17325 | "ffffb2fed976feb24cfd8d3cf03b20bd0026",
|
17326 | "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
|
17327 | "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
|
17328 | "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
|
17329 | ).map(colors);
|
17330 |
|
17331 | var YlOrRd = ramp$1(scheme$6);
|
17332 |
|
17333 | var scheme$5 = new Array(3).concat(
|
17334 | "deebf79ecae13182bd",
|
17335 | "eff3ffbdd7e76baed62171b5",
|
17336 | "eff3ffbdd7e76baed63182bd08519c",
|
17337 | "eff3ffc6dbef9ecae16baed63182bd08519c",
|
17338 | "eff3ffc6dbef9ecae16baed64292c62171b5084594",
|
17339 | "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
|
17340 | "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
|
17341 | ).map(colors);
|
17342 |
|
17343 | var Blues = ramp$1(scheme$5);
|
17344 |
|
17345 | var scheme$4 = new Array(3).concat(
|
17346 | "e5f5e0a1d99b31a354",
|
17347 | "edf8e9bae4b374c476238b45",
|
17348 | "edf8e9bae4b374c47631a354006d2c",
|
17349 | "edf8e9c7e9c0a1d99b74c47631a354006d2c",
|
17350 | "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
|
17351 | "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
|
17352 | "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
|
17353 | ).map(colors);
|
17354 |
|
17355 | var Greens = ramp$1(scheme$4);
|
17356 |
|
17357 | var scheme$3 = new Array(3).concat(
|
17358 | "f0f0f0bdbdbd636363",
|
17359 | "f7f7f7cccccc969696525252",
|
17360 | "f7f7f7cccccc969696636363252525",
|
17361 | "f7f7f7d9d9d9bdbdbd969696636363252525",
|
17362 | "f7f7f7d9d9d9bdbdbd969696737373525252252525",
|
17363 | "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
|
17364 | "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
|
17365 | ).map(colors);
|
17366 |
|
17367 | var Greys = ramp$1(scheme$3);
|
17368 |
|
17369 | var scheme$2 = new Array(3).concat(
|
17370 | "efedf5bcbddc756bb1",
|
17371 | "f2f0f7cbc9e29e9ac86a51a3",
|
17372 | "f2f0f7cbc9e29e9ac8756bb154278f",
|
17373 | "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
|
17374 | "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
|
17375 | "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
|
17376 | "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
|
17377 | ).map(colors);
|
17378 |
|
17379 | var Purples = ramp$1(scheme$2);
|
17380 |
|
17381 | var scheme$1 = new Array(3).concat(
|
17382 | "fee0d2fc9272de2d26",
|
17383 | "fee5d9fcae91fb6a4acb181d",
|
17384 | "fee5d9fcae91fb6a4ade2d26a50f15",
|
17385 | "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
|
17386 | "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
|
17387 | "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
|
17388 | "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
|
17389 | ).map(colors);
|
17390 |
|
17391 | var Reds = ramp$1(scheme$1);
|
17392 |
|
17393 | var scheme = new Array(3).concat(
|
17394 | "fee6cefdae6be6550d",
|
17395 | "feeddefdbe85fd8d3cd94701",
|
17396 | "feeddefdbe85fd8d3ce6550da63603",
|
17397 | "feeddefdd0a2fdae6bfd8d3ce6550da63603",
|
17398 | "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
|
17399 | "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
|
17400 | "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
|
17401 | ).map(colors);
|
17402 |
|
17403 | var Oranges = ramp$1(scheme);
|
17404 |
|
17405 | function cividis(t) {
|
17406 | t = Math.max(0, Math.min(1, t));
|
17407 | return "rgb("
|
17408 | + 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))))))) + ", "
|
17409 | + 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))))))) + ", "
|
17410 | + 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)))))))
|
17411 | + ")";
|
17412 | }
|
17413 |
|
17414 | var cubehelix = cubehelixLong(cubehelix$3(300, 0.5, 0.0), cubehelix$3(-240, 0.5, 1.0));
|
17415 |
|
17416 | var warm = cubehelixLong(cubehelix$3(-100, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
|
17417 |
|
17418 | var cool = cubehelixLong(cubehelix$3(260, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8));
|
17419 |
|
17420 | var c$2 = cubehelix$3();
|
17421 |
|
17422 | function rainbow(t) {
|
17423 | if (t < 0 || t > 1) t -= Math.floor(t);
|
17424 | var ts = Math.abs(t - 0.5);
|
17425 | c$2.h = 360 * t - 100;
|
17426 | c$2.s = 1.5 - 1.5 * ts;
|
17427 | c$2.l = 0.8 - 0.9 * ts;
|
17428 | return c$2 + "";
|
17429 | }
|
17430 |
|
17431 | var c$1 = rgb(),
|
17432 | pi_1_3 = Math.PI / 3,
|
17433 | pi_2_3 = Math.PI * 2 / 3;
|
17434 |
|
17435 | function sinebow(t) {
|
17436 | var x;
|
17437 | t = (0.5 - t) * Math.PI;
|
17438 | c$1.r = 255 * (x = Math.sin(t)) * x;
|
17439 | c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
|
17440 | c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
|
17441 | return c$1 + "";
|
17442 | }
|
17443 |
|
17444 | function turbo(t) {
|
17445 | t = Math.max(0, Math.min(1, t));
|
17446 | return "rgb("
|
17447 | + 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))))))) + ", "
|
17448 | + 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))))))) + ", "
|
17449 | + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
|
17450 | + ")";
|
17451 | }
|
17452 |
|
17453 | function ramp(range) {
|
17454 | var n = range.length;
|
17455 | return function(t) {
|
17456 | return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
17457 | };
|
17458 | }
|
17459 |
|
17460 | var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
|
17461 |
|
17462 | var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
|
17463 |
|
17464 | var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
|
17465 |
|
17466 | var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
|
17467 |
|
17468 | function constant$1(x) {
|
17469 | return function constant() {
|
17470 | return x;
|
17471 | };
|
17472 | }
|
17473 |
|
17474 | const abs = Math.abs;
|
17475 | const atan2 = Math.atan2;
|
17476 | const cos = Math.cos;
|
17477 | const max = Math.max;
|
17478 | const min = Math.min;
|
17479 | const sin = Math.sin;
|
17480 | const sqrt = Math.sqrt;
|
17481 |
|
17482 | const epsilon = 1e-12;
|
17483 | const pi = Math.PI;
|
17484 | const halfPi = pi / 2;
|
17485 | const tau = 2 * pi;
|
17486 |
|
17487 | function acos(x) {
|
17488 | return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
|
17489 | }
|
17490 |
|
17491 | function asin(x) {
|
17492 | return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x);
|
17493 | }
|
17494 |
|
17495 | function withPath(shape) {
|
17496 | let digits = 3;
|
17497 |
|
17498 | shape.digits = function(_) {
|
17499 | if (!arguments.length) return digits;
|
17500 | if (_ == null) {
|
17501 | digits = null;
|
17502 | } else {
|
17503 | const d = Math.floor(_);
|
17504 | if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`);
|
17505 | digits = d;
|
17506 | }
|
17507 | return shape;
|
17508 | };
|
17509 |
|
17510 | return () => new Path$1(digits);
|
17511 | }
|
17512 |
|
17513 | function arcInnerRadius(d) {
|
17514 | return d.innerRadius;
|
17515 | }
|
17516 |
|
17517 | function arcOuterRadius(d) {
|
17518 | return d.outerRadius;
|
17519 | }
|
17520 |
|
17521 | function arcStartAngle(d) {
|
17522 | return d.startAngle;
|
17523 | }
|
17524 |
|
17525 | function arcEndAngle(d) {
|
17526 | return d.endAngle;
|
17527 | }
|
17528 |
|
17529 | function arcPadAngle(d) {
|
17530 | return d && d.padAngle; // Note: optional!
|
17531 | }
|
17532 |
|
17533 | function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
|
17534 | var x10 = x1 - x0, y10 = y1 - y0,
|
17535 | x32 = x3 - x2, y32 = y3 - y2,
|
17536 | t = y32 * x10 - x32 * y10;
|
17537 | if (t * t < epsilon) return;
|
17538 | t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
|
17539 | return [x0 + t * x10, y0 + t * y10];
|
17540 | }
|
17541 |
|
17542 | // Compute perpendicular offset line of length rc.
|
17543 | // http://mathworld.wolfram.com/Circle-LineIntersection.html
|
17544 | function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
|
17545 | var x01 = x0 - x1,
|
17546 | y01 = y0 - y1,
|
17547 | lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01),
|
17548 | ox = lo * y01,
|
17549 | oy = -lo * x01,
|
17550 | x11 = x0 + ox,
|
17551 | y11 = y0 + oy,
|
17552 | x10 = x1 + ox,
|
17553 | y10 = y1 + oy,
|
17554 | x00 = (x11 + x10) / 2,
|
17555 | y00 = (y11 + y10) / 2,
|
17556 | dx = x10 - x11,
|
17557 | dy = y10 - y11,
|
17558 | d2 = dx * dx + dy * dy,
|
17559 | r = r1 - rc,
|
17560 | D = x11 * y10 - x10 * y11,
|
17561 | d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)),
|
17562 | cx0 = (D * dy - dx * d) / d2,
|
17563 | cy0 = (-D * dx - dy * d) / d2,
|
17564 | cx1 = (D * dy + dx * d) / d2,
|
17565 | cy1 = (-D * dx + dy * d) / d2,
|
17566 | dx0 = cx0 - x00,
|
17567 | dy0 = cy0 - y00,
|
17568 | dx1 = cx1 - x00,
|
17569 | dy1 = cy1 - y00;
|
17570 |
|
17571 | // Pick the closer of the two intersection points.
|
17572 | // TODO Is there a faster way to determine which intersection to use?
|
17573 | if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
|
17574 |
|
17575 | return {
|
17576 | cx: cx0,
|
17577 | cy: cy0,
|
17578 | x01: -ox,
|
17579 | y01: -oy,
|
17580 | x11: cx0 * (r1 / r - 1),
|
17581 | y11: cy0 * (r1 / r - 1)
|
17582 | };
|
17583 | }
|
17584 |
|
17585 | function arc() {
|
17586 | var innerRadius = arcInnerRadius,
|
17587 | outerRadius = arcOuterRadius,
|
17588 | cornerRadius = constant$1(0),
|
17589 | padRadius = null,
|
17590 | startAngle = arcStartAngle,
|
17591 | endAngle = arcEndAngle,
|
17592 | padAngle = arcPadAngle,
|
17593 | context = null,
|
17594 | path = withPath(arc);
|
17595 |
|
17596 | function arc() {
|
17597 | var buffer,
|
17598 | r,
|
17599 | r0 = +innerRadius.apply(this, arguments),
|
17600 | r1 = +outerRadius.apply(this, arguments),
|
17601 | a0 = startAngle.apply(this, arguments) - halfPi,
|
17602 | a1 = endAngle.apply(this, arguments) - halfPi,
|
17603 | da = abs(a1 - a0),
|
17604 | cw = a1 > a0;
|
17605 |
|
17606 | if (!context) context = buffer = path();
|
17607 |
|
17608 | // Ensure that the outer radius is always larger than the inner radius.
|
17609 | if (r1 < r0) r = r1, r1 = r0, r0 = r;
|
17610 |
|
17611 | // Is it a point?
|
17612 | if (!(r1 > epsilon)) context.moveTo(0, 0);
|
17613 |
|
17614 | // Or is it a circle or annulus?
|
17615 | else if (da > tau - epsilon) {
|
17616 | context.moveTo(r1 * cos(a0), r1 * sin(a0));
|
17617 | context.arc(0, 0, r1, a0, a1, !cw);
|
17618 | if (r0 > epsilon) {
|
17619 | context.moveTo(r0 * cos(a1), r0 * sin(a1));
|
17620 | context.arc(0, 0, r0, a1, a0, cw);
|
17621 | }
|
17622 | }
|
17623 |
|
17624 | // Or is it a circular or annular sector?
|
17625 | else {
|
17626 | var a01 = a0,
|
17627 | a11 = a1,
|
17628 | a00 = a0,
|
17629 | a10 = a1,
|
17630 | da0 = da,
|
17631 | da1 = da,
|
17632 | ap = padAngle.apply(this, arguments) / 2,
|
17633 | rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)),
|
17634 | rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
|
17635 | rc0 = rc,
|
17636 | rc1 = rc,
|
17637 | t0,
|
17638 | t1;
|
17639 |
|
17640 | // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
|
17641 | if (rp > epsilon) {
|
17642 | var p0 = asin(rp / r0 * sin(ap)),
|
17643 | p1 = asin(rp / r1 * sin(ap));
|
17644 | if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
|
17645 | else da0 = 0, a00 = a10 = (a0 + a1) / 2;
|
17646 | if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
|
17647 | else da1 = 0, a01 = a11 = (a0 + a1) / 2;
|
17648 | }
|
17649 |
|
17650 | var x01 = r1 * cos(a01),
|
17651 | y01 = r1 * sin(a01),
|
17652 | x10 = r0 * cos(a10),
|
17653 | y10 = r0 * sin(a10);
|
17654 |
|
17655 | // Apply rounded corners?
|
17656 | if (rc > epsilon) {
|
17657 | var x11 = r1 * cos(a11),
|
17658 | y11 = r1 * sin(a11),
|
17659 | x00 = r0 * cos(a00),
|
17660 | y00 = r0 * sin(a00),
|
17661 | oc;
|
17662 |
|
17663 | // Restrict the corner radius according to the sector angle. If this
|
17664 | // intersection fails, it’s probably because the arc is too small, so
|
17665 | // disable the corner radius entirely.
|
17666 | if (da < pi) {
|
17667 | if (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10)) {
|
17668 | var ax = x01 - oc[0],
|
17669 | ay = y01 - oc[1],
|
17670 | bx = x11 - oc[0],
|
17671 | by = y11 - oc[1],
|
17672 | kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2),
|
17673 | lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
|
17674 | rc0 = min(rc, (r0 - lc) / (kc - 1));
|
17675 | rc1 = min(rc, (r1 - lc) / (kc + 1));
|
17676 | } else {
|
17677 | rc0 = rc1 = 0;
|
17678 | }
|
17679 | }
|
17680 | }
|
17681 |
|
17682 | // Is the sector collapsed to a line?
|
17683 | if (!(da1 > epsilon)) context.moveTo(x01, y01);
|
17684 |
|
17685 | // Does the sector’s outer ring have rounded corners?
|
17686 | else if (rc1 > epsilon) {
|
17687 | t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
|
17688 | t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
|
17689 |
|
17690 | context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
17691 |
|
17692 | // Have the corners merged?
|
17693 | if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
|
17694 |
|
17695 | // Otherwise, draw the two corners and the ring.
|
17696 | else {
|
17697 | context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
|
17698 | context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
|
17699 | context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
|
17700 | }
|
17701 | }
|
17702 |
|
17703 | // Or is the outer ring just a circular arc?
|
17704 | else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
|
17705 |
|
17706 | // Is there no inner ring, and it’s a circular sector?
|
17707 | // Or perhaps it’s an annular sector collapsed due to padding?
|
17708 | if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10);
|
17709 |
|
17710 | // Does the sector’s inner ring (or point) have rounded corners?
|
17711 | else if (rc0 > epsilon) {
|
17712 | t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
|
17713 | t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
|
17714 |
|
17715 | context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
17716 |
|
17717 | // Have the corners merged?
|
17718 | if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw);
|
17719 |
|
17720 | // Otherwise, draw the two corners and the ring.
|
17721 | else {
|
17722 | context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw);
|
17723 | context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw);
|
17724 | context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw);
|
17725 | }
|
17726 | }
|
17727 |
|
17728 | // Or is the inner ring just a circular arc?
|
17729 | else context.arc(0, 0, r0, a10, a00, cw);
|
17730 | }
|
17731 |
|
17732 | context.closePath();
|
17733 |
|
17734 | if (buffer) return context = null, buffer + "" || null;
|
17735 | }
|
17736 |
|
17737 | arc.centroid = function() {
|
17738 | var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
|
17739 | a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2;
|
17740 | return [cos(a) * r, sin(a) * r];
|
17741 | };
|
17742 |
|
17743 | arc.innerRadius = function(_) {
|
17744 | return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : innerRadius;
|
17745 | };
|
17746 |
|
17747 | arc.outerRadius = function(_) {
|
17748 | return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : outerRadius;
|
17749 | };
|
17750 |
|
17751 | arc.cornerRadius = function(_) {
|
17752 | return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : cornerRadius;
|
17753 | };
|
17754 |
|
17755 | arc.padRadius = function(_) {
|
17756 | return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), arc) : padRadius;
|
17757 | };
|
17758 |
|
17759 | arc.startAngle = function(_) {
|
17760 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : startAngle;
|
17761 | };
|
17762 |
|
17763 | arc.endAngle = function(_) {
|
17764 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : endAngle;
|
17765 | };
|
17766 |
|
17767 | arc.padAngle = function(_) {
|
17768 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : padAngle;
|
17769 | };
|
17770 |
|
17771 | arc.context = function(_) {
|
17772 | return arguments.length ? ((context = _ == null ? null : _), arc) : context;
|
17773 | };
|
17774 |
|
17775 | return arc;
|
17776 | }
|
17777 |
|
17778 | var slice = Array.prototype.slice;
|
17779 |
|
17780 | function array(x) {
|
17781 | return typeof x === "object" && "length" in x
|
17782 | ? x // Array, TypedArray, NodeList, array-like
|
17783 | : Array.from(x); // Map, Set, iterable, string, or anything else
|
17784 | }
|
17785 |
|
17786 | function Linear(context) {
|
17787 | this._context = context;
|
17788 | }
|
17789 |
|
17790 | Linear.prototype = {
|
17791 | areaStart: function() {
|
17792 | this._line = 0;
|
17793 | },
|
17794 | areaEnd: function() {
|
17795 | this._line = NaN;
|
17796 | },
|
17797 | lineStart: function() {
|
17798 | this._point = 0;
|
17799 | },
|
17800 | lineEnd: function() {
|
17801 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
17802 | this._line = 1 - this._line;
|
17803 | },
|
17804 | point: function(x, y) {
|
17805 | x = +x, y = +y;
|
17806 | switch (this._point) {
|
17807 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
17808 | case 1: this._point = 2; // falls through
|
17809 | default: this._context.lineTo(x, y); break;
|
17810 | }
|
17811 | }
|
17812 | };
|
17813 |
|
17814 | function curveLinear(context) {
|
17815 | return new Linear(context);
|
17816 | }
|
17817 |
|
17818 | function x(p) {
|
17819 | return p[0];
|
17820 | }
|
17821 |
|
17822 | function y(p) {
|
17823 | return p[1];
|
17824 | }
|
17825 |
|
17826 | function line(x$1, y$1) {
|
17827 | var defined = constant$1(true),
|
17828 | context = null,
|
17829 | curve = curveLinear,
|
17830 | output = null,
|
17831 | path = withPath(line);
|
17832 |
|
17833 | x$1 = typeof x$1 === "function" ? x$1 : (x$1 === undefined) ? x : constant$1(x$1);
|
17834 | y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant$1(y$1);
|
17835 |
|
17836 | function line(data) {
|
17837 | var i,
|
17838 | n = (data = array(data)).length,
|
17839 | d,
|
17840 | defined0 = false,
|
17841 | buffer;
|
17842 |
|
17843 | if (context == null) output = curve(buffer = path());
|
17844 |
|
17845 | for (i = 0; i <= n; ++i) {
|
17846 | if (!(i < n && defined(d = data[i], i, data)) === defined0) {
|
17847 | if (defined0 = !defined0) output.lineStart();
|
17848 | else output.lineEnd();
|
17849 | }
|
17850 | if (defined0) output.point(+x$1(d, i, data), +y$1(d, i, data));
|
17851 | }
|
17852 |
|
17853 | if (buffer) return output = null, buffer + "" || null;
|
17854 | }
|
17855 |
|
17856 | line.x = function(_) {
|
17857 | return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), line) : x$1;
|
17858 | };
|
17859 |
|
17860 | line.y = function(_) {
|
17861 | return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), line) : y$1;
|
17862 | };
|
17863 |
|
17864 | line.defined = function(_) {
|
17865 | return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), line) : defined;
|
17866 | };
|
17867 |
|
17868 | line.curve = function(_) {
|
17869 | return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
|
17870 | };
|
17871 |
|
17872 | line.context = function(_) {
|
17873 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
|
17874 | };
|
17875 |
|
17876 | return line;
|
17877 | }
|
17878 |
|
17879 | function area(x0, y0, y1) {
|
17880 | var x1 = null,
|
17881 | defined = constant$1(true),
|
17882 | context = null,
|
17883 | curve = curveLinear,
|
17884 | output = null,
|
17885 | path = withPath(area);
|
17886 |
|
17887 | x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x : constant$1(+x0);
|
17888 | y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant$1(0) : constant$1(+y0);
|
17889 | y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant$1(+y1);
|
17890 |
|
17891 | function area(data) {
|
17892 | var i,
|
17893 | j,
|
17894 | k,
|
17895 | n = (data = array(data)).length,
|
17896 | d,
|
17897 | defined0 = false,
|
17898 | buffer,
|
17899 | x0z = new Array(n),
|
17900 | y0z = new Array(n);
|
17901 |
|
17902 | if (context == null) output = curve(buffer = path());
|
17903 |
|
17904 | for (i = 0; i <= n; ++i) {
|
17905 | if (!(i < n && defined(d = data[i], i, data)) === defined0) {
|
17906 | if (defined0 = !defined0) {
|
17907 | j = i;
|
17908 | output.areaStart();
|
17909 | output.lineStart();
|
17910 | } else {
|
17911 | output.lineEnd();
|
17912 | output.lineStart();
|
17913 | for (k = i - 1; k >= j; --k) {
|
17914 | output.point(x0z[k], y0z[k]);
|
17915 | }
|
17916 | output.lineEnd();
|
17917 | output.areaEnd();
|
17918 | }
|
17919 | }
|
17920 | if (defined0) {
|
17921 | x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
|
17922 | output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
|
17923 | }
|
17924 | }
|
17925 |
|
17926 | if (buffer) return output = null, buffer + "" || null;
|
17927 | }
|
17928 |
|
17929 | function arealine() {
|
17930 | return line().defined(defined).curve(curve).context(context);
|
17931 | }
|
17932 |
|
17933 | area.x = function(_) {
|
17934 | return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), x1 = null, area) : x0;
|
17935 | };
|
17936 |
|
17937 | area.x0 = function(_) {
|
17938 | return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), area) : x0;
|
17939 | };
|
17940 |
|
17941 | area.x1 = function(_) {
|
17942 | return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : x1;
|
17943 | };
|
17944 |
|
17945 | area.y = function(_) {
|
17946 | return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), y1 = null, area) : y0;
|
17947 | };
|
17948 |
|
17949 | area.y0 = function(_) {
|
17950 | return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), area) : y0;
|
17951 | };
|
17952 |
|
17953 | area.y1 = function(_) {
|
17954 | return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : y1;
|
17955 | };
|
17956 |
|
17957 | area.lineX0 =
|
17958 | area.lineY0 = function() {
|
17959 | return arealine().x(x0).y(y0);
|
17960 | };
|
17961 |
|
17962 | area.lineY1 = function() {
|
17963 | return arealine().x(x0).y(y1);
|
17964 | };
|
17965 |
|
17966 | area.lineX1 = function() {
|
17967 | return arealine().x(x1).y(y0);
|
17968 | };
|
17969 |
|
17970 | area.defined = function(_) {
|
17971 | return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), area) : defined;
|
17972 | };
|
17973 |
|
17974 | area.curve = function(_) {
|
17975 | return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
|
17976 | };
|
17977 |
|
17978 | area.context = function(_) {
|
17979 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
|
17980 | };
|
17981 |
|
17982 | return area;
|
17983 | }
|
17984 |
|
17985 | function descending$1(a, b) {
|
17986 | return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
17987 | }
|
17988 |
|
17989 | function identity$1(d) {
|
17990 | return d;
|
17991 | }
|
17992 |
|
17993 | function pie() {
|
17994 | var value = identity$1,
|
17995 | sortValues = descending$1,
|
17996 | sort = null,
|
17997 | startAngle = constant$1(0),
|
17998 | endAngle = constant$1(tau),
|
17999 | padAngle = constant$1(0);
|
18000 |
|
18001 | function pie(data) {
|
18002 | var i,
|
18003 | n = (data = array(data)).length,
|
18004 | j,
|
18005 | k,
|
18006 | sum = 0,
|
18007 | index = new Array(n),
|
18008 | arcs = new Array(n),
|
18009 | a0 = +startAngle.apply(this, arguments),
|
18010 | da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)),
|
18011 | a1,
|
18012 | p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
|
18013 | pa = p * (da < 0 ? -1 : 1),
|
18014 | v;
|
18015 |
|
18016 | for (i = 0; i < n; ++i) {
|
18017 | if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
|
18018 | sum += v;
|
18019 | }
|
18020 | }
|
18021 |
|
18022 | // Optionally sort the arcs by previously-computed values or by data.
|
18023 | if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
|
18024 | else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
|
18025 |
|
18026 | // Compute the arcs! They are stored in the original data's order.
|
18027 | for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
|
18028 | j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
|
18029 | data: data[j],
|
18030 | index: i,
|
18031 | value: v,
|
18032 | startAngle: a0,
|
18033 | endAngle: a1,
|
18034 | padAngle: p
|
18035 | };
|
18036 | }
|
18037 |
|
18038 | return arcs;
|
18039 | }
|
18040 |
|
18041 | pie.value = function(_) {
|
18042 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value;
|
18043 | };
|
18044 |
|
18045 | pie.sortValues = function(_) {
|
18046 | return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
|
18047 | };
|
18048 |
|
18049 | pie.sort = function(_) {
|
18050 | return arguments.length ? (sort = _, sortValues = null, pie) : sort;
|
18051 | };
|
18052 |
|
18053 | pie.startAngle = function(_) {
|
18054 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : startAngle;
|
18055 | };
|
18056 |
|
18057 | pie.endAngle = function(_) {
|
18058 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : endAngle;
|
18059 | };
|
18060 |
|
18061 | pie.padAngle = function(_) {
|
18062 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : padAngle;
|
18063 | };
|
18064 |
|
18065 | return pie;
|
18066 | }
|
18067 |
|
18068 | var curveRadialLinear = curveRadial(curveLinear);
|
18069 |
|
18070 | function Radial(curve) {
|
18071 | this._curve = curve;
|
18072 | }
|
18073 |
|
18074 | Radial.prototype = {
|
18075 | areaStart: function() {
|
18076 | this._curve.areaStart();
|
18077 | },
|
18078 | areaEnd: function() {
|
18079 | this._curve.areaEnd();
|
18080 | },
|
18081 | lineStart: function() {
|
18082 | this._curve.lineStart();
|
18083 | },
|
18084 | lineEnd: function() {
|
18085 | this._curve.lineEnd();
|
18086 | },
|
18087 | point: function(a, r) {
|
18088 | this._curve.point(r * Math.sin(a), r * -Math.cos(a));
|
18089 | }
|
18090 | };
|
18091 |
|
18092 | function curveRadial(curve) {
|
18093 |
|
18094 | function radial(context) {
|
18095 | return new Radial(curve(context));
|
18096 | }
|
18097 |
|
18098 | radial._curve = curve;
|
18099 |
|
18100 | return radial;
|
18101 | }
|
18102 |
|
18103 | function lineRadial(l) {
|
18104 | var c = l.curve;
|
18105 |
|
18106 | l.angle = l.x, delete l.x;
|
18107 | l.radius = l.y, delete l.y;
|
18108 |
|
18109 | l.curve = function(_) {
|
18110 | return arguments.length ? c(curveRadial(_)) : c()._curve;
|
18111 | };
|
18112 |
|
18113 | return l;
|
18114 | }
|
18115 |
|
18116 | function lineRadial$1() {
|
18117 | return lineRadial(line().curve(curveRadialLinear));
|
18118 | }
|
18119 |
|
18120 | function areaRadial() {
|
18121 | var a = area().curve(curveRadialLinear),
|
18122 | c = a.curve,
|
18123 | x0 = a.lineX0,
|
18124 | x1 = a.lineX1,
|
18125 | y0 = a.lineY0,
|
18126 | y1 = a.lineY1;
|
18127 |
|
18128 | a.angle = a.x, delete a.x;
|
18129 | a.startAngle = a.x0, delete a.x0;
|
18130 | a.endAngle = a.x1, delete a.x1;
|
18131 | a.radius = a.y, delete a.y;
|
18132 | a.innerRadius = a.y0, delete a.y0;
|
18133 | a.outerRadius = a.y1, delete a.y1;
|
18134 | a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
|
18135 | a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
|
18136 | a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
|
18137 | a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
|
18138 |
|
18139 | a.curve = function(_) {
|
18140 | return arguments.length ? c(curveRadial(_)) : c()._curve;
|
18141 | };
|
18142 |
|
18143 | return a;
|
18144 | }
|
18145 |
|
18146 | function pointRadial(x, y) {
|
18147 | return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
|
18148 | }
|
18149 |
|
18150 | class Bump {
|
18151 | constructor(context, x) {
|
18152 | this._context = context;
|
18153 | this._x = x;
|
18154 | }
|
18155 | areaStart() {
|
18156 | this._line = 0;
|
18157 | }
|
18158 | areaEnd() {
|
18159 | this._line = NaN;
|
18160 | }
|
18161 | lineStart() {
|
18162 | this._point = 0;
|
18163 | }
|
18164 | lineEnd() {
|
18165 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
18166 | this._line = 1 - this._line;
|
18167 | }
|
18168 | point(x, y) {
|
18169 | x = +x, y = +y;
|
18170 | switch (this._point) {
|
18171 | case 0: {
|
18172 | this._point = 1;
|
18173 | if (this._line) this._context.lineTo(x, y);
|
18174 | else this._context.moveTo(x, y);
|
18175 | break;
|
18176 | }
|
18177 | case 1: this._point = 2; // falls through
|
18178 | default: {
|
18179 | if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y);
|
18180 | else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y);
|
18181 | break;
|
18182 | }
|
18183 | }
|
18184 | this._x0 = x, this._y0 = y;
|
18185 | }
|
18186 | }
|
18187 |
|
18188 | class BumpRadial {
|
18189 | constructor(context) {
|
18190 | this._context = context;
|
18191 | }
|
18192 | lineStart() {
|
18193 | this._point = 0;
|
18194 | }
|
18195 | lineEnd() {}
|
18196 | point(x, y) {
|
18197 | x = +x, y = +y;
|
18198 | if (this._point === 0) {
|
18199 | this._point = 1;
|
18200 | } else {
|
18201 | const p0 = pointRadial(this._x0, this._y0);
|
18202 | const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2);
|
18203 | const p2 = pointRadial(x, this._y0);
|
18204 | const p3 = pointRadial(x, y);
|
18205 | this._context.moveTo(...p0);
|
18206 | this._context.bezierCurveTo(...p1, ...p2, ...p3);
|
18207 | }
|
18208 | this._x0 = x, this._y0 = y;
|
18209 | }
|
18210 | }
|
18211 |
|
18212 | function bumpX(context) {
|
18213 | return new Bump(context, true);
|
18214 | }
|
18215 |
|
18216 | function bumpY(context) {
|
18217 | return new Bump(context, false);
|
18218 | }
|
18219 |
|
18220 | function bumpRadial(context) {
|
18221 | return new BumpRadial(context);
|
18222 | }
|
18223 |
|
18224 | function linkSource(d) {
|
18225 | return d.source;
|
18226 | }
|
18227 |
|
18228 | function linkTarget(d) {
|
18229 | return d.target;
|
18230 | }
|
18231 |
|
18232 | function link(curve) {
|
18233 | let source = linkSource,
|
18234 | target = linkTarget,
|
18235 | x$1 = x,
|
18236 | y$1 = y,
|
18237 | context = null,
|
18238 | output = null,
|
18239 | path = withPath(link);
|
18240 |
|
18241 | function link() {
|
18242 | let buffer;
|
18243 | const argv = slice.call(arguments);
|
18244 | const s = source.apply(this, argv);
|
18245 | const t = target.apply(this, argv);
|
18246 | if (context == null) output = curve(buffer = path());
|
18247 | output.lineStart();
|
18248 | argv[0] = s, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
|
18249 | argv[0] = t, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv));
|
18250 | output.lineEnd();
|
18251 | if (buffer) return output = null, buffer + "" || null;
|
18252 | }
|
18253 |
|
18254 | link.source = function(_) {
|
18255 | return arguments.length ? (source = _, link) : source;
|
18256 | };
|
18257 |
|
18258 | link.target = function(_) {
|
18259 | return arguments.length ? (target = _, link) : target;
|
18260 | };
|
18261 |
|
18262 | link.x = function(_) {
|
18263 | return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), link) : x$1;
|
18264 | };
|
18265 |
|
18266 | link.y = function(_) {
|
18267 | return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), link) : y$1;
|
18268 | };
|
18269 |
|
18270 | link.context = function(_) {
|
18271 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), link) : context;
|
18272 | };
|
18273 |
|
18274 | return link;
|
18275 | }
|
18276 |
|
18277 | function linkHorizontal() {
|
18278 | return link(bumpX);
|
18279 | }
|
18280 |
|
18281 | function linkVertical() {
|
18282 | return link(bumpY);
|
18283 | }
|
18284 |
|
18285 | function linkRadial() {
|
18286 | const l = link(bumpRadial);
|
18287 | l.angle = l.x, delete l.x;
|
18288 | l.radius = l.y, delete l.y;
|
18289 | return l;
|
18290 | }
|
18291 |
|
18292 | const sqrt3$2 = sqrt(3);
|
18293 |
|
18294 | var asterisk = {
|
18295 | draw(context, size) {
|
18296 | const r = sqrt(size + min(size / 28, 0.75)) * 0.59436;
|
18297 | const t = r / 2;
|
18298 | const u = t * sqrt3$2;
|
18299 | context.moveTo(0, r);
|
18300 | context.lineTo(0, -r);
|
18301 | context.moveTo(-u, -t);
|
18302 | context.lineTo(u, t);
|
18303 | context.moveTo(-u, t);
|
18304 | context.lineTo(u, -t);
|
18305 | }
|
18306 | };
|
18307 |
|
18308 | var circle = {
|
18309 | draw(context, size) {
|
18310 | const r = sqrt(size / pi);
|
18311 | context.moveTo(r, 0);
|
18312 | context.arc(0, 0, r, 0, tau);
|
18313 | }
|
18314 | };
|
18315 |
|
18316 | var cross = {
|
18317 | draw(context, size) {
|
18318 | const r = sqrt(size / 5) / 2;
|
18319 | context.moveTo(-3 * r, -r);
|
18320 | context.lineTo(-r, -r);
|
18321 | context.lineTo(-r, -3 * r);
|
18322 | context.lineTo(r, -3 * r);
|
18323 | context.lineTo(r, -r);
|
18324 | context.lineTo(3 * r, -r);
|
18325 | context.lineTo(3 * r, r);
|
18326 | context.lineTo(r, r);
|
18327 | context.lineTo(r, 3 * r);
|
18328 | context.lineTo(-r, 3 * r);
|
18329 | context.lineTo(-r, r);
|
18330 | context.lineTo(-3 * r, r);
|
18331 | context.closePath();
|
18332 | }
|
18333 | };
|
18334 |
|
18335 | const tan30 = sqrt(1 / 3);
|
18336 | const tan30_2 = tan30 * 2;
|
18337 |
|
18338 | var diamond = {
|
18339 | draw(context, size) {
|
18340 | const y = sqrt(size / tan30_2);
|
18341 | const x = y * tan30;
|
18342 | context.moveTo(0, -y);
|
18343 | context.lineTo(x, 0);
|
18344 | context.lineTo(0, y);
|
18345 | context.lineTo(-x, 0);
|
18346 | context.closePath();
|
18347 | }
|
18348 | };
|
18349 |
|
18350 | var diamond2 = {
|
18351 | draw(context, size) {
|
18352 | const r = sqrt(size) * 0.62625;
|
18353 | context.moveTo(0, -r);
|
18354 | context.lineTo(r, 0);
|
18355 | context.lineTo(0, r);
|
18356 | context.lineTo(-r, 0);
|
18357 | context.closePath();
|
18358 | }
|
18359 | };
|
18360 |
|
18361 | var plus = {
|
18362 | draw(context, size) {
|
18363 | const r = sqrt(size - min(size / 7, 2)) * 0.87559;
|
18364 | context.moveTo(-r, 0);
|
18365 | context.lineTo(r, 0);
|
18366 | context.moveTo(0, r);
|
18367 | context.lineTo(0, -r);
|
18368 | }
|
18369 | };
|
18370 |
|
18371 | var square = {
|
18372 | draw(context, size) {
|
18373 | const w = sqrt(size);
|
18374 | const x = -w / 2;
|
18375 | context.rect(x, x, w, w);
|
18376 | }
|
18377 | };
|
18378 |
|
18379 | var square2 = {
|
18380 | draw(context, size) {
|
18381 | const r = sqrt(size) * 0.4431;
|
18382 | context.moveTo(r, r);
|
18383 | context.lineTo(r, -r);
|
18384 | context.lineTo(-r, -r);
|
18385 | context.lineTo(-r, r);
|
18386 | context.closePath();
|
18387 | }
|
18388 | };
|
18389 |
|
18390 | const ka = 0.89081309152928522810;
|
18391 | const kr = sin(pi / 10) / sin(7 * pi / 10);
|
18392 | const kx = sin(tau / 10) * kr;
|
18393 | const ky = -cos(tau / 10) * kr;
|
18394 |
|
18395 | var star = {
|
18396 | draw(context, size) {
|
18397 | const r = sqrt(size * ka);
|
18398 | const x = kx * r;
|
18399 | const y = ky * r;
|
18400 | context.moveTo(0, -r);
|
18401 | context.lineTo(x, y);
|
18402 | for (let i = 1; i < 5; ++i) {
|
18403 | const a = tau * i / 5;
|
18404 | const c = cos(a);
|
18405 | const s = sin(a);
|
18406 | context.lineTo(s * r, -c * r);
|
18407 | context.lineTo(c * x - s * y, s * x + c * y);
|
18408 | }
|
18409 | context.closePath();
|
18410 | }
|
18411 | };
|
18412 |
|
18413 | const sqrt3$1 = sqrt(3);
|
18414 |
|
18415 | var triangle = {
|
18416 | draw(context, size) {
|
18417 | const y = -sqrt(size / (sqrt3$1 * 3));
|
18418 | context.moveTo(0, y * 2);
|
18419 | context.lineTo(-sqrt3$1 * y, -y);
|
18420 | context.lineTo(sqrt3$1 * y, -y);
|
18421 | context.closePath();
|
18422 | }
|
18423 | };
|
18424 |
|
18425 | const sqrt3 = sqrt(3);
|
18426 |
|
18427 | var triangle2 = {
|
18428 | draw(context, size) {
|
18429 | const s = sqrt(size) * 0.6824;
|
18430 | const t = s / 2;
|
18431 | const u = (s * sqrt3) / 2; // cos(Math.PI / 6)
|
18432 | context.moveTo(0, -s);
|
18433 | context.lineTo(u, t);
|
18434 | context.lineTo(-u, t);
|
18435 | context.closePath();
|
18436 | }
|
18437 | };
|
18438 |
|
18439 | const c = -0.5;
|
18440 | const s = sqrt(3) / 2;
|
18441 | const k = 1 / sqrt(12);
|
18442 | const a = (k / 2 + 1) * 3;
|
18443 |
|
18444 | var wye = {
|
18445 | draw(context, size) {
|
18446 | const r = sqrt(size / a);
|
18447 | const x0 = r / 2, y0 = r * k;
|
18448 | const x1 = x0, y1 = r * k + r;
|
18449 | const x2 = -x1, y2 = y1;
|
18450 | context.moveTo(x0, y0);
|
18451 | context.lineTo(x1, y1);
|
18452 | context.lineTo(x2, y2);
|
18453 | context.lineTo(c * x0 - s * y0, s * x0 + c * y0);
|
18454 | context.lineTo(c * x1 - s * y1, s * x1 + c * y1);
|
18455 | context.lineTo(c * x2 - s * y2, s * x2 + c * y2);
|
18456 | context.lineTo(c * x0 + s * y0, c * y0 - s * x0);
|
18457 | context.lineTo(c * x1 + s * y1, c * y1 - s * x1);
|
18458 | context.lineTo(c * x2 + s * y2, c * y2 - s * x2);
|
18459 | context.closePath();
|
18460 | }
|
18461 | };
|
18462 |
|
18463 | var times = {
|
18464 | draw(context, size) {
|
18465 | const r = sqrt(size - min(size / 6, 1.7)) * 0.6189;
|
18466 | context.moveTo(-r, -r);
|
18467 | context.lineTo(r, r);
|
18468 | context.moveTo(-r, r);
|
18469 | context.lineTo(r, -r);
|
18470 | }
|
18471 | };
|
18472 |
|
18473 | // These symbols are designed to be filled.
|
18474 | const symbolsFill = [
|
18475 | circle,
|
18476 | cross,
|
18477 | diamond,
|
18478 | square,
|
18479 | star,
|
18480 | triangle,
|
18481 | wye
|
18482 | ];
|
18483 |
|
18484 | // These symbols are designed to be stroked (with a width of 1.5px and round caps).
|
18485 | const symbolsStroke = [
|
18486 | circle,
|
18487 | plus,
|
18488 | times,
|
18489 | triangle2,
|
18490 | asterisk,
|
18491 | square2,
|
18492 | diamond2
|
18493 | ];
|
18494 |
|
18495 | function Symbol$1(type, size) {
|
18496 | let context = null,
|
18497 | path = withPath(symbol);
|
18498 |
|
18499 | type = typeof type === "function" ? type : constant$1(type || circle);
|
18500 | size = typeof size === "function" ? size : constant$1(size === undefined ? 64 : +size);
|
18501 |
|
18502 | function symbol() {
|
18503 | let buffer;
|
18504 | if (!context) context = buffer = path();
|
18505 | type.apply(this, arguments).draw(context, +size.apply(this, arguments));
|
18506 | if (buffer) return context = null, buffer + "" || null;
|
18507 | }
|
18508 |
|
18509 | symbol.type = function(_) {
|
18510 | return arguments.length ? (type = typeof _ === "function" ? _ : constant$1(_), symbol) : type;
|
18511 | };
|
18512 |
|
18513 | symbol.size = function(_) {
|
18514 | return arguments.length ? (size = typeof _ === "function" ? _ : constant$1(+_), symbol) : size;
|
18515 | };
|
18516 |
|
18517 | symbol.context = function(_) {
|
18518 | return arguments.length ? (context = _ == null ? null : _, symbol) : context;
|
18519 | };
|
18520 |
|
18521 | return symbol;
|
18522 | }
|
18523 |
|
18524 | function noop() {}
|
18525 |
|
18526 | function point$3(that, x, y) {
|
18527 | that._context.bezierCurveTo(
|
18528 | (2 * that._x0 + that._x1) / 3,
|
18529 | (2 * that._y0 + that._y1) / 3,
|
18530 | (that._x0 + 2 * that._x1) / 3,
|
18531 | (that._y0 + 2 * that._y1) / 3,
|
18532 | (that._x0 + 4 * that._x1 + x) / 6,
|
18533 | (that._y0 + 4 * that._y1 + y) / 6
|
18534 | );
|
18535 | }
|
18536 |
|
18537 | function Basis(context) {
|
18538 | this._context = context;
|
18539 | }
|
18540 |
|
18541 | Basis.prototype = {
|
18542 | areaStart: function() {
|
18543 | this._line = 0;
|
18544 | },
|
18545 | areaEnd: function() {
|
18546 | this._line = NaN;
|
18547 | },
|
18548 | lineStart: function() {
|
18549 | this._x0 = this._x1 =
|
18550 | this._y0 = this._y1 = NaN;
|
18551 | this._point = 0;
|
18552 | },
|
18553 | lineEnd: function() {
|
18554 | switch (this._point) {
|
18555 | case 3: point$3(this, this._x1, this._y1); // falls through
|
18556 | case 2: this._context.lineTo(this._x1, this._y1); break;
|
18557 | }
|
18558 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
18559 | this._line = 1 - this._line;
|
18560 | },
|
18561 | point: function(x, y) {
|
18562 | x = +x, y = +y;
|
18563 | switch (this._point) {
|
18564 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
18565 | case 1: this._point = 2; break;
|
18566 | case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through
|
18567 | default: point$3(this, x, y); break;
|
18568 | }
|
18569 | this._x0 = this._x1, this._x1 = x;
|
18570 | this._y0 = this._y1, this._y1 = y;
|
18571 | }
|
18572 | };
|
18573 |
|
18574 | function basis(context) {
|
18575 | return new Basis(context);
|
18576 | }
|
18577 |
|
18578 | function BasisClosed(context) {
|
18579 | this._context = context;
|
18580 | }
|
18581 |
|
18582 | BasisClosed.prototype = {
|
18583 | areaStart: noop,
|
18584 | areaEnd: noop,
|
18585 | lineStart: function() {
|
18586 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
|
18587 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
|
18588 | this._point = 0;
|
18589 | },
|
18590 | lineEnd: function() {
|
18591 | switch (this._point) {
|
18592 | case 1: {
|
18593 | this._context.moveTo(this._x2, this._y2);
|
18594 | this._context.closePath();
|
18595 | break;
|
18596 | }
|
18597 | case 2: {
|
18598 | this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
|
18599 | this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
|
18600 | this._context.closePath();
|
18601 | break;
|
18602 | }
|
18603 | case 3: {
|
18604 | this.point(this._x2, this._y2);
|
18605 | this.point(this._x3, this._y3);
|
18606 | this.point(this._x4, this._y4);
|
18607 | break;
|
18608 | }
|
18609 | }
|
18610 | },
|
18611 | point: function(x, y) {
|
18612 | x = +x, y = +y;
|
18613 | switch (this._point) {
|
18614 | case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
|
18615 | case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
|
18616 | 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;
|
18617 | default: point$3(this, x, y); break;
|
18618 | }
|
18619 | this._x0 = this._x1, this._x1 = x;
|
18620 | this._y0 = this._y1, this._y1 = y;
|
18621 | }
|
18622 | };
|
18623 |
|
18624 | function basisClosed(context) {
|
18625 | return new BasisClosed(context);
|
18626 | }
|
18627 |
|
18628 | function BasisOpen(context) {
|
18629 | this._context = context;
|
18630 | }
|
18631 |
|
18632 | BasisOpen.prototype = {
|
18633 | areaStart: function() {
|
18634 | this._line = 0;
|
18635 | },
|
18636 | areaEnd: function() {
|
18637 | this._line = NaN;
|
18638 | },
|
18639 | lineStart: function() {
|
18640 | this._x0 = this._x1 =
|
18641 | this._y0 = this._y1 = NaN;
|
18642 | this._point = 0;
|
18643 | },
|
18644 | lineEnd: function() {
|
18645 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
18646 | this._line = 1 - this._line;
|
18647 | },
|
18648 | point: function(x, y) {
|
18649 | x = +x, y = +y;
|
18650 | switch (this._point) {
|
18651 | case 0: this._point = 1; break;
|
18652 | case 1: this._point = 2; break;
|
18653 | 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;
|
18654 | case 3: this._point = 4; // falls through
|
18655 | default: point$3(this, x, y); break;
|
18656 | }
|
18657 | this._x0 = this._x1, this._x1 = x;
|
18658 | this._y0 = this._y1, this._y1 = y;
|
18659 | }
|
18660 | };
|
18661 |
|
18662 | function basisOpen(context) {
|
18663 | return new BasisOpen(context);
|
18664 | }
|
18665 |
|
18666 | function Bundle(context, beta) {
|
18667 | this._basis = new Basis(context);
|
18668 | this._beta = beta;
|
18669 | }
|
18670 |
|
18671 | Bundle.prototype = {
|
18672 | lineStart: function() {
|
18673 | this._x = [];
|
18674 | this._y = [];
|
18675 | this._basis.lineStart();
|
18676 | },
|
18677 | lineEnd: function() {
|
18678 | var x = this._x,
|
18679 | y = this._y,
|
18680 | j = x.length - 1;
|
18681 |
|
18682 | if (j > 0) {
|
18683 | var x0 = x[0],
|
18684 | y0 = y[0],
|
18685 | dx = x[j] - x0,
|
18686 | dy = y[j] - y0,
|
18687 | i = -1,
|
18688 | t;
|
18689 |
|
18690 | while (++i <= j) {
|
18691 | t = i / j;
|
18692 | this._basis.point(
|
18693 | this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
|
18694 | this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
|
18695 | );
|
18696 | }
|
18697 | }
|
18698 |
|
18699 | this._x = this._y = null;
|
18700 | this._basis.lineEnd();
|
18701 | },
|
18702 | point: function(x, y) {
|
18703 | this._x.push(+x);
|
18704 | this._y.push(+y);
|
18705 | }
|
18706 | };
|
18707 |
|
18708 | var bundle = (function custom(beta) {
|
18709 |
|
18710 | function bundle(context) {
|
18711 | return beta === 1 ? new Basis(context) : new Bundle(context, beta);
|
18712 | }
|
18713 |
|
18714 | bundle.beta = function(beta) {
|
18715 | return custom(+beta);
|
18716 | };
|
18717 |
|
18718 | return bundle;
|
18719 | })(0.85);
|
18720 |
|
18721 | function point$2(that, x, y) {
|
18722 | that._context.bezierCurveTo(
|
18723 | that._x1 + that._k * (that._x2 - that._x0),
|
18724 | that._y1 + that._k * (that._y2 - that._y0),
|
18725 | that._x2 + that._k * (that._x1 - x),
|
18726 | that._y2 + that._k * (that._y1 - y),
|
18727 | that._x2,
|
18728 | that._y2
|
18729 | );
|
18730 | }
|
18731 |
|
18732 | function Cardinal(context, tension) {
|
18733 | this._context = context;
|
18734 | this._k = (1 - tension) / 6;
|
18735 | }
|
18736 |
|
18737 | Cardinal.prototype = {
|
18738 | areaStart: function() {
|
18739 | this._line = 0;
|
18740 | },
|
18741 | areaEnd: function() {
|
18742 | this._line = NaN;
|
18743 | },
|
18744 | lineStart: function() {
|
18745 | this._x0 = this._x1 = this._x2 =
|
18746 | this._y0 = this._y1 = this._y2 = NaN;
|
18747 | this._point = 0;
|
18748 | },
|
18749 | lineEnd: function() {
|
18750 | switch (this._point) {
|
18751 | case 2: this._context.lineTo(this._x2, this._y2); break;
|
18752 | case 3: point$2(this, this._x1, this._y1); break;
|
18753 | }
|
18754 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
18755 | this._line = 1 - this._line;
|
18756 | },
|
18757 | point: function(x, y) {
|
18758 | x = +x, y = +y;
|
18759 | switch (this._point) {
|
18760 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
18761 | case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
|
18762 | case 2: this._point = 3; // falls through
|
18763 | default: point$2(this, x, y); break;
|
18764 | }
|
18765 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18766 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18767 | }
|
18768 | };
|
18769 |
|
18770 | var cardinal = (function custom(tension) {
|
18771 |
|
18772 | function cardinal(context) {
|
18773 | return new Cardinal(context, tension);
|
18774 | }
|
18775 |
|
18776 | cardinal.tension = function(tension) {
|
18777 | return custom(+tension);
|
18778 | };
|
18779 |
|
18780 | return cardinal;
|
18781 | })(0);
|
18782 |
|
18783 | function CardinalClosed(context, tension) {
|
18784 | this._context = context;
|
18785 | this._k = (1 - tension) / 6;
|
18786 | }
|
18787 |
|
18788 | CardinalClosed.prototype = {
|
18789 | areaStart: noop,
|
18790 | areaEnd: noop,
|
18791 | lineStart: function() {
|
18792 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
|
18793 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
|
18794 | this._point = 0;
|
18795 | },
|
18796 | lineEnd: function() {
|
18797 | switch (this._point) {
|
18798 | case 1: {
|
18799 | this._context.moveTo(this._x3, this._y3);
|
18800 | this._context.closePath();
|
18801 | break;
|
18802 | }
|
18803 | case 2: {
|
18804 | this._context.lineTo(this._x3, this._y3);
|
18805 | this._context.closePath();
|
18806 | break;
|
18807 | }
|
18808 | case 3: {
|
18809 | this.point(this._x3, this._y3);
|
18810 | this.point(this._x4, this._y4);
|
18811 | this.point(this._x5, this._y5);
|
18812 | break;
|
18813 | }
|
18814 | }
|
18815 | },
|
18816 | point: function(x, y) {
|
18817 | x = +x, y = +y;
|
18818 | switch (this._point) {
|
18819 | case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
|
18820 | case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
|
18821 | case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
|
18822 | default: point$2(this, x, y); break;
|
18823 | }
|
18824 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18825 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18826 | }
|
18827 | };
|
18828 |
|
18829 | var cardinalClosed = (function custom(tension) {
|
18830 |
|
18831 | function cardinal(context) {
|
18832 | return new CardinalClosed(context, tension);
|
18833 | }
|
18834 |
|
18835 | cardinal.tension = function(tension) {
|
18836 | return custom(+tension);
|
18837 | };
|
18838 |
|
18839 | return cardinal;
|
18840 | })(0);
|
18841 |
|
18842 | function CardinalOpen(context, tension) {
|
18843 | this._context = context;
|
18844 | this._k = (1 - tension) / 6;
|
18845 | }
|
18846 |
|
18847 | CardinalOpen.prototype = {
|
18848 | areaStart: function() {
|
18849 | this._line = 0;
|
18850 | },
|
18851 | areaEnd: function() {
|
18852 | this._line = NaN;
|
18853 | },
|
18854 | lineStart: function() {
|
18855 | this._x0 = this._x1 = this._x2 =
|
18856 | this._y0 = this._y1 = this._y2 = NaN;
|
18857 | this._point = 0;
|
18858 | },
|
18859 | lineEnd: function() {
|
18860 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
18861 | this._line = 1 - this._line;
|
18862 | },
|
18863 | point: function(x, y) {
|
18864 | x = +x, y = +y;
|
18865 | switch (this._point) {
|
18866 | case 0: this._point = 1; break;
|
18867 | case 1: this._point = 2; break;
|
18868 | case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
|
18869 | case 3: this._point = 4; // falls through
|
18870 | default: point$2(this, x, y); break;
|
18871 | }
|
18872 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18873 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18874 | }
|
18875 | };
|
18876 |
|
18877 | var cardinalOpen = (function custom(tension) {
|
18878 |
|
18879 | function cardinal(context) {
|
18880 | return new CardinalOpen(context, tension);
|
18881 | }
|
18882 |
|
18883 | cardinal.tension = function(tension) {
|
18884 | return custom(+tension);
|
18885 | };
|
18886 |
|
18887 | return cardinal;
|
18888 | })(0);
|
18889 |
|
18890 | function point$1(that, x, y) {
|
18891 | var x1 = that._x1,
|
18892 | y1 = that._y1,
|
18893 | x2 = that._x2,
|
18894 | y2 = that._y2;
|
18895 |
|
18896 | if (that._l01_a > epsilon) {
|
18897 | var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
|
18898 | n = 3 * that._l01_a * (that._l01_a + that._l12_a);
|
18899 | x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
|
18900 | y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
|
18901 | }
|
18902 |
|
18903 | if (that._l23_a > epsilon) {
|
18904 | var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
|
18905 | m = 3 * that._l23_a * (that._l23_a + that._l12_a);
|
18906 | x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
|
18907 | y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
|
18908 | }
|
18909 |
|
18910 | that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
|
18911 | }
|
18912 |
|
18913 | function CatmullRom(context, alpha) {
|
18914 | this._context = context;
|
18915 | this._alpha = alpha;
|
18916 | }
|
18917 |
|
18918 | CatmullRom.prototype = {
|
18919 | areaStart: function() {
|
18920 | this._line = 0;
|
18921 | },
|
18922 | areaEnd: function() {
|
18923 | this._line = NaN;
|
18924 | },
|
18925 | lineStart: function() {
|
18926 | this._x0 = this._x1 = this._x2 =
|
18927 | this._y0 = this._y1 = this._y2 = NaN;
|
18928 | this._l01_a = this._l12_a = this._l23_a =
|
18929 | this._l01_2a = this._l12_2a = this._l23_2a =
|
18930 | this._point = 0;
|
18931 | },
|
18932 | lineEnd: function() {
|
18933 | switch (this._point) {
|
18934 | case 2: this._context.lineTo(this._x2, this._y2); break;
|
18935 | case 3: this.point(this._x2, this._y2); break;
|
18936 | }
|
18937 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
18938 | this._line = 1 - this._line;
|
18939 | },
|
18940 | point: function(x, y) {
|
18941 | x = +x, y = +y;
|
18942 |
|
18943 | if (this._point) {
|
18944 | var x23 = this._x2 - x,
|
18945 | y23 = this._y2 - y;
|
18946 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
18947 | }
|
18948 |
|
18949 | switch (this._point) {
|
18950 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
18951 | case 1: this._point = 2; break;
|
18952 | case 2: this._point = 3; // falls through
|
18953 | default: point$1(this, x, y); break;
|
18954 | }
|
18955 |
|
18956 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
18957 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
18958 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
18959 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
18960 | }
|
18961 | };
|
18962 |
|
18963 | var catmullRom = (function custom(alpha) {
|
18964 |
|
18965 | function catmullRom(context) {
|
18966 | return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
|
18967 | }
|
18968 |
|
18969 | catmullRom.alpha = function(alpha) {
|
18970 | return custom(+alpha);
|
18971 | };
|
18972 |
|
18973 | return catmullRom;
|
18974 | })(0.5);
|
18975 |
|
18976 | function CatmullRomClosed(context, alpha) {
|
18977 | this._context = context;
|
18978 | this._alpha = alpha;
|
18979 | }
|
18980 |
|
18981 | CatmullRomClosed.prototype = {
|
18982 | areaStart: noop,
|
18983 | areaEnd: noop,
|
18984 | lineStart: function() {
|
18985 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
|
18986 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
|
18987 | this._l01_a = this._l12_a = this._l23_a =
|
18988 | this._l01_2a = this._l12_2a = this._l23_2a =
|
18989 | this._point = 0;
|
18990 | },
|
18991 | lineEnd: function() {
|
18992 | switch (this._point) {
|
18993 | case 1: {
|
18994 | this._context.moveTo(this._x3, this._y3);
|
18995 | this._context.closePath();
|
18996 | break;
|
18997 | }
|
18998 | case 2: {
|
18999 | this._context.lineTo(this._x3, this._y3);
|
19000 | this._context.closePath();
|
19001 | break;
|
19002 | }
|
19003 | case 3: {
|
19004 | this.point(this._x3, this._y3);
|
19005 | this.point(this._x4, this._y4);
|
19006 | this.point(this._x5, this._y5);
|
19007 | break;
|
19008 | }
|
19009 | }
|
19010 | },
|
19011 | point: function(x, y) {
|
19012 | x = +x, y = +y;
|
19013 |
|
19014 | if (this._point) {
|
19015 | var x23 = this._x2 - x,
|
19016 | y23 = this._y2 - y;
|
19017 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
19018 | }
|
19019 |
|
19020 | switch (this._point) {
|
19021 | case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
|
19022 | case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
|
19023 | case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
|
19024 | default: point$1(this, x, y); break;
|
19025 | }
|
19026 |
|
19027 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
19028 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
19029 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
19030 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
19031 | }
|
19032 | };
|
19033 |
|
19034 | var catmullRomClosed = (function custom(alpha) {
|
19035 |
|
19036 | function catmullRom(context) {
|
19037 | return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
|
19038 | }
|
19039 |
|
19040 | catmullRom.alpha = function(alpha) {
|
19041 | return custom(+alpha);
|
19042 | };
|
19043 |
|
19044 | return catmullRom;
|
19045 | })(0.5);
|
19046 |
|
19047 | function CatmullRomOpen(context, alpha) {
|
19048 | this._context = context;
|
19049 | this._alpha = alpha;
|
19050 | }
|
19051 |
|
19052 | CatmullRomOpen.prototype = {
|
19053 | areaStart: function() {
|
19054 | this._line = 0;
|
19055 | },
|
19056 | areaEnd: function() {
|
19057 | this._line = NaN;
|
19058 | },
|
19059 | lineStart: function() {
|
19060 | this._x0 = this._x1 = this._x2 =
|
19061 | this._y0 = this._y1 = this._y2 = NaN;
|
19062 | this._l01_a = this._l12_a = this._l23_a =
|
19063 | this._l01_2a = this._l12_2a = this._l23_2a =
|
19064 | this._point = 0;
|
19065 | },
|
19066 | lineEnd: function() {
|
19067 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
19068 | this._line = 1 - this._line;
|
19069 | },
|
19070 | point: function(x, y) {
|
19071 | x = +x, y = +y;
|
19072 |
|
19073 | if (this._point) {
|
19074 | var x23 = this._x2 - x,
|
19075 | y23 = this._y2 - y;
|
19076 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
19077 | }
|
19078 |
|
19079 | switch (this._point) {
|
19080 | case 0: this._point = 1; break;
|
19081 | case 1: this._point = 2; break;
|
19082 | case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
|
19083 | case 3: this._point = 4; // falls through
|
19084 | default: point$1(this, x, y); break;
|
19085 | }
|
19086 |
|
19087 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
19088 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
19089 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
19090 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
19091 | }
|
19092 | };
|
19093 |
|
19094 | var catmullRomOpen = (function custom(alpha) {
|
19095 |
|
19096 | function catmullRom(context) {
|
19097 | return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
|
19098 | }
|
19099 |
|
19100 | catmullRom.alpha = function(alpha) {
|
19101 | return custom(+alpha);
|
19102 | };
|
19103 |
|
19104 | return catmullRom;
|
19105 | })(0.5);
|
19106 |
|
19107 | function LinearClosed(context) {
|
19108 | this._context = context;
|
19109 | }
|
19110 |
|
19111 | LinearClosed.prototype = {
|
19112 | areaStart: noop,
|
19113 | areaEnd: noop,
|
19114 | lineStart: function() {
|
19115 | this._point = 0;
|
19116 | },
|
19117 | lineEnd: function() {
|
19118 | if (this._point) this._context.closePath();
|
19119 | },
|
19120 | point: function(x, y) {
|
19121 | x = +x, y = +y;
|
19122 | if (this._point) this._context.lineTo(x, y);
|
19123 | else this._point = 1, this._context.moveTo(x, y);
|
19124 | }
|
19125 | };
|
19126 |
|
19127 | function linearClosed(context) {
|
19128 | return new LinearClosed(context);
|
19129 | }
|
19130 |
|
19131 | function sign(x) {
|
19132 | return x < 0 ? -1 : 1;
|
19133 | }
|
19134 |
|
19135 | // Calculate the slopes of the tangents (Hermite-type interpolation) based on
|
19136 | // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
|
19137 | // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
|
19138 | // NOV(II), P. 443, 1990.
|
19139 | function slope3(that, x2, y2) {
|
19140 | var h0 = that._x1 - that._x0,
|
19141 | h1 = x2 - that._x1,
|
19142 | s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
|
19143 | s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
|
19144 | p = (s0 * h1 + s1 * h0) / (h0 + h1);
|
19145 | return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
|
19146 | }
|
19147 |
|
19148 | // Calculate a one-sided slope.
|
19149 | function slope2(that, t) {
|
19150 | var h = that._x1 - that._x0;
|
19151 | return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
|
19152 | }
|
19153 |
|
19154 | // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
|
19155 | // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
|
19156 | // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
|
19157 | function point(that, t0, t1) {
|
19158 | var x0 = that._x0,
|
19159 | y0 = that._y0,
|
19160 | x1 = that._x1,
|
19161 | y1 = that._y1,
|
19162 | dx = (x1 - x0) / 3;
|
19163 | that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
|
19164 | }
|
19165 |
|
19166 | function MonotoneX(context) {
|
19167 | this._context = context;
|
19168 | }
|
19169 |
|
19170 | MonotoneX.prototype = {
|
19171 | areaStart: function() {
|
19172 | this._line = 0;
|
19173 | },
|
19174 | areaEnd: function() {
|
19175 | this._line = NaN;
|
19176 | },
|
19177 | lineStart: function() {
|
19178 | this._x0 = this._x1 =
|
19179 | this._y0 = this._y1 =
|
19180 | this._t0 = NaN;
|
19181 | this._point = 0;
|
19182 | },
|
19183 | lineEnd: function() {
|
19184 | switch (this._point) {
|
19185 | case 2: this._context.lineTo(this._x1, this._y1); break;
|
19186 | case 3: point(this, this._t0, slope2(this, this._t0)); break;
|
19187 | }
|
19188 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
19189 | this._line = 1 - this._line;
|
19190 | },
|
19191 | point: function(x, y) {
|
19192 | var t1 = NaN;
|
19193 |
|
19194 | x = +x, y = +y;
|
19195 | if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
|
19196 | switch (this._point) {
|
19197 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
19198 | case 1: this._point = 2; break;
|
19199 | case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
|
19200 | default: point(this, this._t0, t1 = slope3(this, x, y)); break;
|
19201 | }
|
19202 |
|
19203 | this._x0 = this._x1, this._x1 = x;
|
19204 | this._y0 = this._y1, this._y1 = y;
|
19205 | this._t0 = t1;
|
19206 | }
|
19207 | };
|
19208 |
|
19209 | function MonotoneY(context) {
|
19210 | this._context = new ReflectContext(context);
|
19211 | }
|
19212 |
|
19213 | (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
|
19214 | MonotoneX.prototype.point.call(this, y, x);
|
19215 | };
|
19216 |
|
19217 | function ReflectContext(context) {
|
19218 | this._context = context;
|
19219 | }
|
19220 |
|
19221 | ReflectContext.prototype = {
|
19222 | moveTo: function(x, y) { this._context.moveTo(y, x); },
|
19223 | closePath: function() { this._context.closePath(); },
|
19224 | lineTo: function(x, y) { this._context.lineTo(y, x); },
|
19225 | bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
|
19226 | };
|
19227 |
|
19228 | function monotoneX(context) {
|
19229 | return new MonotoneX(context);
|
19230 | }
|
19231 |
|
19232 | function monotoneY(context) {
|
19233 | return new MonotoneY(context);
|
19234 | }
|
19235 |
|
19236 | function Natural(context) {
|
19237 | this._context = context;
|
19238 | }
|
19239 |
|
19240 | Natural.prototype = {
|
19241 | areaStart: function() {
|
19242 | this._line = 0;
|
19243 | },
|
19244 | areaEnd: function() {
|
19245 | this._line = NaN;
|
19246 | },
|
19247 | lineStart: function() {
|
19248 | this._x = [];
|
19249 | this._y = [];
|
19250 | },
|
19251 | lineEnd: function() {
|
19252 | var x = this._x,
|
19253 | y = this._y,
|
19254 | n = x.length;
|
19255 |
|
19256 | if (n) {
|
19257 | this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
|
19258 | if (n === 2) {
|
19259 | this._context.lineTo(x[1], y[1]);
|
19260 | } else {
|
19261 | var px = controlPoints(x),
|
19262 | py = controlPoints(y);
|
19263 | for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
|
19264 | this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
|
19265 | }
|
19266 | }
|
19267 | }
|
19268 |
|
19269 | if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
|
19270 | this._line = 1 - this._line;
|
19271 | this._x = this._y = null;
|
19272 | },
|
19273 | point: function(x, y) {
|
19274 | this._x.push(+x);
|
19275 | this._y.push(+y);
|
19276 | }
|
19277 | };
|
19278 |
|
19279 | // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
|
19280 | function controlPoints(x) {
|
19281 | var i,
|
19282 | n = x.length - 1,
|
19283 | m,
|
19284 | a = new Array(n),
|
19285 | b = new Array(n),
|
19286 | r = new Array(n);
|
19287 | a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
|
19288 | for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
|
19289 | a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
|
19290 | for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
|
19291 | a[n - 1] = r[n - 1] / b[n - 1];
|
19292 | for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
|
19293 | b[n - 1] = (x[n] + a[n - 1]) / 2;
|
19294 | for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
|
19295 | return [a, b];
|
19296 | }
|
19297 |
|
19298 | function natural(context) {
|
19299 | return new Natural(context);
|
19300 | }
|
19301 |
|
19302 | function Step(context, t) {
|
19303 | this._context = context;
|
19304 | this._t = t;
|
19305 | }
|
19306 |
|
19307 | Step.prototype = {
|
19308 | areaStart: function() {
|
19309 | this._line = 0;
|
19310 | },
|
19311 | areaEnd: function() {
|
19312 | this._line = NaN;
|
19313 | },
|
19314 | lineStart: function() {
|
19315 | this._x = this._y = NaN;
|
19316 | this._point = 0;
|
19317 | },
|
19318 | lineEnd: function() {
|
19319 | if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
|
19320 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
19321 | if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
|
19322 | },
|
19323 | point: function(x, y) {
|
19324 | x = +x, y = +y;
|
19325 | switch (this._point) {
|
19326 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
19327 | case 1: this._point = 2; // falls through
|
19328 | default: {
|
19329 | if (this._t <= 0) {
|
19330 | this._context.lineTo(this._x, y);
|
19331 | this._context.lineTo(x, y);
|
19332 | } else {
|
19333 | var x1 = this._x * (1 - this._t) + x * this._t;
|
19334 | this._context.lineTo(x1, this._y);
|
19335 | this._context.lineTo(x1, y);
|
19336 | }
|
19337 | break;
|
19338 | }
|
19339 | }
|
19340 | this._x = x, this._y = y;
|
19341 | }
|
19342 | };
|
19343 |
|
19344 | function step(context) {
|
19345 | return new Step(context, 0.5);
|
19346 | }
|
19347 |
|
19348 | function stepBefore(context) {
|
19349 | return new Step(context, 0);
|
19350 | }
|
19351 |
|
19352 | function stepAfter(context) {
|
19353 | return new Step(context, 1);
|
19354 | }
|
19355 |
|
19356 | function none$1(series, order) {
|
19357 | if (!((n = series.length) > 1)) return;
|
19358 | for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
|
19359 | s0 = s1, s1 = series[order[i]];
|
19360 | for (j = 0; j < m; ++j) {
|
19361 | s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
|
19362 | }
|
19363 | }
|
19364 | }
|
19365 |
|
19366 | function none(series) {
|
19367 | var n = series.length, o = new Array(n);
|
19368 | while (--n >= 0) o[n] = n;
|
19369 | return o;
|
19370 | }
|
19371 |
|
19372 | function stackValue(d, key) {
|
19373 | return d[key];
|
19374 | }
|
19375 |
|
19376 | function stackSeries(key) {
|
19377 | const series = [];
|
19378 | series.key = key;
|
19379 | return series;
|
19380 | }
|
19381 |
|
19382 | function stack() {
|
19383 | var keys = constant$1([]),
|
19384 | order = none,
|
19385 | offset = none$1,
|
19386 | value = stackValue;
|
19387 |
|
19388 | function stack(data) {
|
19389 | var sz = Array.from(keys.apply(this, arguments), stackSeries),
|
19390 | i, n = sz.length, j = -1,
|
19391 | oz;
|
19392 |
|
19393 | for (const d of data) {
|
19394 | for (i = 0, ++j; i < n; ++i) {
|
19395 | (sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d;
|
19396 | }
|
19397 | }
|
19398 |
|
19399 | for (i = 0, oz = array(order(sz)); i < n; ++i) {
|
19400 | sz[oz[i]].index = i;
|
19401 | }
|
19402 |
|
19403 | offset(sz, oz);
|
19404 | return sz;
|
19405 | }
|
19406 |
|
19407 | stack.keys = function(_) {
|
19408 | return arguments.length ? (keys = typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : keys;
|
19409 | };
|
19410 |
|
19411 | stack.value = function(_) {
|
19412 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), stack) : value;
|
19413 | };
|
19414 |
|
19415 | stack.order = function(_) {
|
19416 | return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : order;
|
19417 | };
|
19418 |
|
19419 | stack.offset = function(_) {
|
19420 | return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
|
19421 | };
|
19422 |
|
19423 | return stack;
|
19424 | }
|
19425 |
|
19426 | function expand(series, order) {
|
19427 | if (!((n = series.length) > 0)) return;
|
19428 | for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
|
19429 | for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
|
19430 | if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
|
19431 | }
|
19432 | none$1(series, order);
|
19433 | }
|
19434 |
|
19435 | function diverging(series, order) {
|
19436 | if (!((n = series.length) > 0)) return;
|
19437 | for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
|
19438 | for (yp = yn = 0, i = 0; i < n; ++i) {
|
19439 | if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
|
19440 | d[0] = yp, d[1] = yp += dy;
|
19441 | } else if (dy < 0) {
|
19442 | d[1] = yn, d[0] = yn += dy;
|
19443 | } else {
|
19444 | d[0] = 0, d[1] = dy;
|
19445 | }
|
19446 | }
|
19447 | }
|
19448 | }
|
19449 |
|
19450 | function silhouette(series, order) {
|
19451 | if (!((n = series.length) > 0)) return;
|
19452 | for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
|
19453 | for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
|
19454 | s0[j][1] += s0[j][0] = -y / 2;
|
19455 | }
|
19456 | none$1(series, order);
|
19457 | }
|
19458 |
|
19459 | function wiggle(series, order) {
|
19460 | if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
|
19461 | for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
|
19462 | for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
|
19463 | var si = series[order[i]],
|
19464 | sij0 = si[j][1] || 0,
|
19465 | sij1 = si[j - 1][1] || 0,
|
19466 | s3 = (sij0 - sij1) / 2;
|
19467 | for (var k = 0; k < i; ++k) {
|
19468 | var sk = series[order[k]],
|
19469 | skj0 = sk[j][1] || 0,
|
19470 | skj1 = sk[j - 1][1] || 0;
|
19471 | s3 += skj0 - skj1;
|
19472 | }
|
19473 | s1 += sij0, s2 += s3 * sij0;
|
19474 | }
|
19475 | s0[j - 1][1] += s0[j - 1][0] = y;
|
19476 | if (s1) y -= s2 / s1;
|
19477 | }
|
19478 | s0[j - 1][1] += s0[j - 1][0] = y;
|
19479 | none$1(series, order);
|
19480 | }
|
19481 |
|
19482 | function appearance(series) {
|
19483 | var peaks = series.map(peak);
|
19484 | return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
|
19485 | }
|
19486 |
|
19487 | function peak(series) {
|
19488 | var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
|
19489 | while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
|
19490 | return j;
|
19491 | }
|
19492 |
|
19493 | function ascending(series) {
|
19494 | var sums = series.map(sum);
|
19495 | return none(series).sort(function(a, b) { return sums[a] - sums[b]; });
|
19496 | }
|
19497 |
|
19498 | function sum(series) {
|
19499 | var s = 0, i = -1, n = series.length, v;
|
19500 | while (++i < n) if (v = +series[i][1]) s += v;
|
19501 | return s;
|
19502 | }
|
19503 |
|
19504 | function descending(series) {
|
19505 | return ascending(series).reverse();
|
19506 | }
|
19507 |
|
19508 | function insideOut(series) {
|
19509 | var n = series.length,
|
19510 | i,
|
19511 | j,
|
19512 | sums = series.map(sum),
|
19513 | order = appearance(series),
|
19514 | top = 0,
|
19515 | bottom = 0,
|
19516 | tops = [],
|
19517 | bottoms = [];
|
19518 |
|
19519 | for (i = 0; i < n; ++i) {
|
19520 | j = order[i];
|
19521 | if (top < bottom) {
|
19522 | top += sums[j];
|
19523 | tops.push(j);
|
19524 | } else {
|
19525 | bottom += sums[j];
|
19526 | bottoms.push(j);
|
19527 | }
|
19528 | }
|
19529 |
|
19530 | return bottoms.reverse().concat(tops);
|
19531 | }
|
19532 |
|
19533 | function reverse(series) {
|
19534 | return none(series).reverse();
|
19535 | }
|
19536 |
|
19537 | var constant = x => () => x;
|
19538 |
|
19539 | function ZoomEvent(type, {
|
19540 | sourceEvent,
|
19541 | target,
|
19542 | transform,
|
19543 | dispatch
|
19544 | }) {
|
19545 | Object.defineProperties(this, {
|
19546 | type: {value: type, enumerable: true, configurable: true},
|
19547 | sourceEvent: {value: sourceEvent, enumerable: true, configurable: true},
|
19548 | target: {value: target, enumerable: true, configurable: true},
|
19549 | transform: {value: transform, enumerable: true, configurable: true},
|
19550 | _: {value: dispatch}
|
19551 | });
|
19552 | }
|
19553 |
|
19554 | function Transform(k, x, y) {
|
19555 | this.k = k;
|
19556 | this.x = x;
|
19557 | this.y = y;
|
19558 | }
|
19559 |
|
19560 | Transform.prototype = {
|
19561 | constructor: Transform,
|
19562 | scale: function(k) {
|
19563 | return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
|
19564 | },
|
19565 | translate: function(x, y) {
|
19566 | return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
|
19567 | },
|
19568 | apply: function(point) {
|
19569 | return [point[0] * this.k + this.x, point[1] * this.k + this.y];
|
19570 | },
|
19571 | applyX: function(x) {
|
19572 | return x * this.k + this.x;
|
19573 | },
|
19574 | applyY: function(y) {
|
19575 | return y * this.k + this.y;
|
19576 | },
|
19577 | invert: function(location) {
|
19578 | return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
|
19579 | },
|
19580 | invertX: function(x) {
|
19581 | return (x - this.x) / this.k;
|
19582 | },
|
19583 | invertY: function(y) {
|
19584 | return (y - this.y) / this.k;
|
19585 | },
|
19586 | rescaleX: function(x) {
|
19587 | return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
|
19588 | },
|
19589 | rescaleY: function(y) {
|
19590 | return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
|
19591 | },
|
19592 | toString: function() {
|
19593 | return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
|
19594 | }
|
19595 | };
|
19596 |
|
19597 | var identity = new Transform(1, 0, 0);
|
19598 |
|
19599 | transform.prototype = Transform.prototype;
|
19600 |
|
19601 | function transform(node) {
|
19602 | while (!node.__zoom) if (!(node = node.parentNode)) return identity;
|
19603 | return node.__zoom;
|
19604 | }
|
19605 |
|
19606 | function nopropagation(event) {
|
19607 | event.stopImmediatePropagation();
|
19608 | }
|
19609 |
|
19610 | function noevent(event) {
|
19611 | event.preventDefault();
|
19612 | event.stopImmediatePropagation();
|
19613 | }
|
19614 |
|
19615 | // Ignore right-click, since that should open the context menu.
|
19616 | // except for pinch-to-zoom, which is sent as a wheel+ctrlKey event
|
19617 | function defaultFilter(event) {
|
19618 | return (!event.ctrlKey || event.type === 'wheel') && !event.button;
|
19619 | }
|
19620 |
|
19621 | function defaultExtent() {
|
19622 | var e = this;
|
19623 | if (e instanceof SVGElement) {
|
19624 | e = e.ownerSVGElement || e;
|
19625 | if (e.hasAttribute("viewBox")) {
|
19626 | e = e.viewBox.baseVal;
|
19627 | return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
|
19628 | }
|
19629 | return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
|
19630 | }
|
19631 | return [[0, 0], [e.clientWidth, e.clientHeight]];
|
19632 | }
|
19633 |
|
19634 | function defaultTransform() {
|
19635 | return this.__zoom || identity;
|
19636 | }
|
19637 |
|
19638 | function defaultWheelDelta(event) {
|
19639 | return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1);
|
19640 | }
|
19641 |
|
19642 | function defaultTouchable() {
|
19643 | return navigator.maxTouchPoints || ("ontouchstart" in this);
|
19644 | }
|
19645 |
|
19646 | function defaultConstrain(transform, extent, translateExtent) {
|
19647 | var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
|
19648 | dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
|
19649 | dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
|
19650 | dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
|
19651 | return transform.translate(
|
19652 | dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
|
19653 | dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
|
19654 | );
|
19655 | }
|
19656 |
|
19657 | function zoom() {
|
19658 | var filter = defaultFilter,
|
19659 | extent = defaultExtent,
|
19660 | constrain = defaultConstrain,
|
19661 | wheelDelta = defaultWheelDelta,
|
19662 | touchable = defaultTouchable,
|
19663 | scaleExtent = [0, Infinity],
|
19664 | translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
|
19665 | duration = 250,
|
19666 | interpolate = interpolateZoom,
|
19667 | listeners = dispatch("start", "zoom", "end"),
|
19668 | touchstarting,
|
19669 | touchfirst,
|
19670 | touchending,
|
19671 | touchDelay = 500,
|
19672 | wheelDelay = 150,
|
19673 | clickDistance2 = 0,
|
19674 | tapDistance = 10;
|
19675 |
|
19676 | function zoom(selection) {
|
19677 | selection
|
19678 | .property("__zoom", defaultTransform)
|
19679 | .on("wheel.zoom", wheeled, {passive: false})
|
19680 | .on("mousedown.zoom", mousedowned)
|
19681 | .on("dblclick.zoom", dblclicked)
|
19682 | .filter(touchable)
|
19683 | .on("touchstart.zoom", touchstarted)
|
19684 | .on("touchmove.zoom", touchmoved)
|
19685 | .on("touchend.zoom touchcancel.zoom", touchended)
|
19686 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
19687 | }
|
19688 |
|
19689 | zoom.transform = function(collection, transform, point, event) {
|
19690 | var selection = collection.selection ? collection.selection() : collection;
|
19691 | selection.property("__zoom", defaultTransform);
|
19692 | if (collection !== selection) {
|
19693 | schedule(collection, transform, point, event);
|
19694 | } else {
|
19695 | selection.interrupt().each(function() {
|
19696 | gesture(this, arguments)
|
19697 | .event(event)
|
19698 | .start()
|
19699 | .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
|
19700 | .end();
|
19701 | });
|
19702 | }
|
19703 | };
|
19704 |
|
19705 | zoom.scaleBy = function(selection, k, p, event) {
|
19706 | zoom.scaleTo(selection, function() {
|
19707 | var k0 = this.__zoom.k,
|
19708 | k1 = typeof k === "function" ? k.apply(this, arguments) : k;
|
19709 | return k0 * k1;
|
19710 | }, p, event);
|
19711 | };
|
19712 |
|
19713 | zoom.scaleTo = function(selection, k, p, event) {
|
19714 | zoom.transform(selection, function() {
|
19715 | var e = extent.apply(this, arguments),
|
19716 | t0 = this.__zoom,
|
19717 | p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
|
19718 | p1 = t0.invert(p0),
|
19719 | k1 = typeof k === "function" ? k.apply(this, arguments) : k;
|
19720 | return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
|
19721 | }, p, event);
|
19722 | };
|
19723 |
|
19724 | zoom.translateBy = function(selection, x, y, event) {
|
19725 | zoom.transform(selection, function() {
|
19726 | return constrain(this.__zoom.translate(
|
19727 | typeof x === "function" ? x.apply(this, arguments) : x,
|
19728 | typeof y === "function" ? y.apply(this, arguments) : y
|
19729 | ), extent.apply(this, arguments), translateExtent);
|
19730 | }, null, event);
|
19731 | };
|
19732 |
|
19733 | zoom.translateTo = function(selection, x, y, p, event) {
|
19734 | zoom.transform(selection, function() {
|
19735 | var e = extent.apply(this, arguments),
|
19736 | t = this.__zoom,
|
19737 | p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
|
19738 | return constrain(identity.translate(p0[0], p0[1]).scale(t.k).translate(
|
19739 | typeof x === "function" ? -x.apply(this, arguments) : -x,
|
19740 | typeof y === "function" ? -y.apply(this, arguments) : -y
|
19741 | ), e, translateExtent);
|
19742 | }, p, event);
|
19743 | };
|
19744 |
|
19745 | function scale(transform, k) {
|
19746 | k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
|
19747 | return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
|
19748 | }
|
19749 |
|
19750 | function translate(transform, p0, p1) {
|
19751 | var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
|
19752 | return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
|
19753 | }
|
19754 |
|
19755 | function centroid(extent) {
|
19756 | return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
|
19757 | }
|
19758 |
|
19759 | function schedule(transition, transform, point, event) {
|
19760 | transition
|
19761 | .on("start.zoom", function() { gesture(this, arguments).event(event).start(); })
|
19762 | .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).event(event).end(); })
|
19763 | .tween("zoom", function() {
|
19764 | var that = this,
|
19765 | args = arguments,
|
19766 | g = gesture(that, args).event(event),
|
19767 | e = extent.apply(that, args),
|
19768 | p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
|
19769 | w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
|
19770 | a = that.__zoom,
|
19771 | b = typeof transform === "function" ? transform.apply(that, args) : transform,
|
19772 | i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
|
19773 | return function(t) {
|
19774 | if (t === 1) t = b; // Avoid rounding error on end.
|
19775 | else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
|
19776 | g.zoom(null, t);
|
19777 | };
|
19778 | });
|
19779 | }
|
19780 |
|
19781 | function gesture(that, args, clean) {
|
19782 | return (!clean && that.__zooming) || new Gesture(that, args);
|
19783 | }
|
19784 |
|
19785 | function Gesture(that, args) {
|
19786 | this.that = that;
|
19787 | this.args = args;
|
19788 | this.active = 0;
|
19789 | this.sourceEvent = null;
|
19790 | this.extent = extent.apply(that, args);
|
19791 | this.taps = 0;
|
19792 | }
|
19793 |
|
19794 | Gesture.prototype = {
|
19795 | event: function(event) {
|
19796 | if (event) this.sourceEvent = event;
|
19797 | return this;
|
19798 | },
|
19799 | start: function() {
|
19800 | if (++this.active === 1) {
|
19801 | this.that.__zooming = this;
|
19802 | this.emit("start");
|
19803 | }
|
19804 | return this;
|
19805 | },
|
19806 | zoom: function(key, transform) {
|
19807 | if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
|
19808 | if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
|
19809 | if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
|
19810 | this.that.__zoom = transform;
|
19811 | this.emit("zoom");
|
19812 | return this;
|
19813 | },
|
19814 | end: function() {
|
19815 | if (--this.active === 0) {
|
19816 | delete this.that.__zooming;
|
19817 | this.emit("end");
|
19818 | }
|
19819 | return this;
|
19820 | },
|
19821 | emit: function(type) {
|
19822 | var d = select(this.that).datum();
|
19823 | listeners.call(
|
19824 | type,
|
19825 | this.that,
|
19826 | new ZoomEvent(type, {
|
19827 | sourceEvent: this.sourceEvent,
|
19828 | target: zoom,
|
19829 | type,
|
19830 | transform: this.that.__zoom,
|
19831 | dispatch: listeners
|
19832 | }),
|
19833 | d
|
19834 | );
|
19835 | }
|
19836 | };
|
19837 |
|
19838 | function wheeled(event, ...args) {
|
19839 | if (!filter.apply(this, arguments)) return;
|
19840 | var g = gesture(this, args).event(event),
|
19841 | t = this.__zoom,
|
19842 | k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
|
19843 | p = pointer(event);
|
19844 |
|
19845 | // If the mouse is in the same location as before, reuse it.
|
19846 | // If there were recent wheel events, reset the wheel idle timeout.
|
19847 | if (g.wheel) {
|
19848 | if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
|
19849 | g.mouse[1] = t.invert(g.mouse[0] = p);
|
19850 | }
|
19851 | clearTimeout(g.wheel);
|
19852 | }
|
19853 |
|
19854 | // If this wheel event won’t trigger a transform change, ignore it.
|
19855 | else if (t.k === k) return;
|
19856 |
|
19857 | // Otherwise, capture the mouse point and location at the start.
|
19858 | else {
|
19859 | g.mouse = [p, t.invert(p)];
|
19860 | interrupt(this);
|
19861 | g.start();
|
19862 | }
|
19863 |
|
19864 | noevent(event);
|
19865 | g.wheel = setTimeout(wheelidled, wheelDelay);
|
19866 | g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
|
19867 |
|
19868 | function wheelidled() {
|
19869 | g.wheel = null;
|
19870 | g.end();
|
19871 | }
|
19872 | }
|
19873 |
|
19874 | function mousedowned(event, ...args) {
|
19875 | if (touchending || !filter.apply(this, arguments)) return;
|
19876 | var currentTarget = event.currentTarget,
|
19877 | g = gesture(this, args, true).event(event),
|
19878 | v = select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
|
19879 | p = pointer(event, currentTarget),
|
19880 | x0 = event.clientX,
|
19881 | y0 = event.clientY;
|
19882 |
|
19883 | dragDisable(event.view);
|
19884 | nopropagation(event);
|
19885 | g.mouse = [p, this.__zoom.invert(p)];
|
19886 | interrupt(this);
|
19887 | g.start();
|
19888 |
|
19889 | function mousemoved(event) {
|
19890 | noevent(event);
|
19891 | if (!g.moved) {
|
19892 | var dx = event.clientX - x0, dy = event.clientY - y0;
|
19893 | g.moved = dx * dx + dy * dy > clickDistance2;
|
19894 | }
|
19895 | g.event(event)
|
19896 | .zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = pointer(event, currentTarget), g.mouse[1]), g.extent, translateExtent));
|
19897 | }
|
19898 |
|
19899 | function mouseupped(event) {
|
19900 | v.on("mousemove.zoom mouseup.zoom", null);
|
19901 | yesdrag(event.view, g.moved);
|
19902 | noevent(event);
|
19903 | g.event(event).end();
|
19904 | }
|
19905 | }
|
19906 |
|
19907 | function dblclicked(event, ...args) {
|
19908 | if (!filter.apply(this, arguments)) return;
|
19909 | var t0 = this.__zoom,
|
19910 | p0 = pointer(event.changedTouches ? event.changedTouches[0] : event, this),
|
19911 | p1 = t0.invert(p0),
|
19912 | k1 = t0.k * (event.shiftKey ? 0.5 : 2),
|
19913 | t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, args), translateExtent);
|
19914 |
|
19915 | noevent(event);
|
19916 | if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0, event);
|
19917 | else select(this).call(zoom.transform, t1, p0, event);
|
19918 | }
|
19919 |
|
19920 | function touchstarted(event, ...args) {
|
19921 | if (!filter.apply(this, arguments)) return;
|
19922 | var touches = event.touches,
|
19923 | n = touches.length,
|
19924 | g = gesture(this, args, event.changedTouches.length === n).event(event),
|
19925 | started, i, t, p;
|
19926 |
|
19927 | nopropagation(event);
|
19928 | for (i = 0; i < n; ++i) {
|
19929 | t = touches[i], p = pointer(t, this);
|
19930 | p = [p, this.__zoom.invert(p), t.identifier];
|
19931 | if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
|
19932 | else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
|
19933 | }
|
19934 |
|
19935 | if (touchstarting) touchstarting = clearTimeout(touchstarting);
|
19936 |
|
19937 | if (started) {
|
19938 | if (g.taps < 2) touchfirst = p[0], touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
|
19939 | interrupt(this);
|
19940 | g.start();
|
19941 | }
|
19942 | }
|
19943 |
|
19944 | function touchmoved(event, ...args) {
|
19945 | if (!this.__zooming) return;
|
19946 | var g = gesture(this, args).event(event),
|
19947 | touches = event.changedTouches,
|
19948 | n = touches.length, i, t, p, l;
|
19949 |
|
19950 | noevent(event);
|
19951 | for (i = 0; i < n; ++i) {
|
19952 | t = touches[i], p = pointer(t, this);
|
19953 | if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
|
19954 | else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
|
19955 | }
|
19956 | t = g.that.__zoom;
|
19957 | if (g.touch1) {
|
19958 | var p0 = g.touch0[0], l0 = g.touch0[1],
|
19959 | p1 = g.touch1[0], l1 = g.touch1[1],
|
19960 | dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
|
19961 | dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
|
19962 | t = scale(t, Math.sqrt(dp / dl));
|
19963 | p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
|
19964 | l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
|
19965 | }
|
19966 | else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
|
19967 | else return;
|
19968 |
|
19969 | g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
|
19970 | }
|
19971 |
|
19972 | function touchended(event, ...args) {
|
19973 | if (!this.__zooming) return;
|
19974 | var g = gesture(this, args).event(event),
|
19975 | touches = event.changedTouches,
|
19976 | n = touches.length, i, t;
|
19977 |
|
19978 | nopropagation(event);
|
19979 | if (touchending) clearTimeout(touchending);
|
19980 | touchending = setTimeout(function() { touchending = null; }, touchDelay);
|
19981 | for (i = 0; i < n; ++i) {
|
19982 | t = touches[i];
|
19983 | if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
|
19984 | else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
|
19985 | }
|
19986 | if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
|
19987 | if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
|
19988 | else {
|
19989 | g.end();
|
19990 | // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
|
19991 | if (g.taps === 2) {
|
19992 | t = pointer(t, this);
|
19993 | if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) {
|
19994 | var p = select(this).on("dblclick.zoom");
|
19995 | if (p) p.apply(this, arguments);
|
19996 | }
|
19997 | }
|
19998 | }
|
19999 | }
|
20000 |
|
20001 | zoom.wheelDelta = function(_) {
|
20002 | return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant(+_), zoom) : wheelDelta;
|
20003 | };
|
20004 |
|
20005 | zoom.filter = function(_) {
|
20006 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter;
|
20007 | };
|
20008 |
|
20009 | zoom.touchable = function(_) {
|
20010 | return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), zoom) : touchable;
|
20011 | };
|
20012 |
|
20013 | zoom.extent = function(_) {
|
20014 | return arguments.length ? (extent = typeof _ === "function" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
|
20015 | };
|
20016 |
|
20017 | zoom.scaleExtent = function(_) {
|
20018 | return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
|
20019 | };
|
20020 |
|
20021 | zoom.translateExtent = function(_) {
|
20022 | 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]]];
|
20023 | };
|
20024 |
|
20025 | zoom.constrain = function(_) {
|
20026 | return arguments.length ? (constrain = _, zoom) : constrain;
|
20027 | };
|
20028 |
|
20029 | zoom.duration = function(_) {
|
20030 | return arguments.length ? (duration = +_, zoom) : duration;
|
20031 | };
|
20032 |
|
20033 | zoom.interpolate = function(_) {
|
20034 | return arguments.length ? (interpolate = _, zoom) : interpolate;
|
20035 | };
|
20036 |
|
20037 | zoom.on = function() {
|
20038 | var value = listeners.on.apply(listeners, arguments);
|
20039 | return value === listeners ? zoom : value;
|
20040 | };
|
20041 |
|
20042 | zoom.clickDistance = function(_) {
|
20043 | return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
|
20044 | };
|
20045 |
|
20046 | zoom.tapDistance = function(_) {
|
20047 | return arguments.length ? (tapDistance = +_, zoom) : tapDistance;
|
20048 | };
|
20049 |
|
20050 | return zoom;
|
20051 | }
|
20052 |
|
20053 | exports.Adder = Adder;
|
20054 | exports.Delaunay = Delaunay;
|
20055 | exports.FormatSpecifier = FormatSpecifier;
|
20056 | exports.InternMap = InternMap;
|
20057 | exports.InternSet = InternSet;
|
20058 | exports.Node = Node$1;
|
20059 | exports.Path = Path$1;
|
20060 | exports.Voronoi = Voronoi;
|
20061 | exports.ZoomTransform = Transform;
|
20062 | exports.active = active;
|
20063 | exports.arc = arc;
|
20064 | exports.area = area;
|
20065 | exports.areaRadial = areaRadial;
|
20066 | exports.ascending = ascending$3;
|
20067 | exports.autoType = autoType;
|
20068 | exports.axisBottom = axisBottom;
|
20069 | exports.axisLeft = axisLeft;
|
20070 | exports.axisRight = axisRight;
|
20071 | exports.axisTop = axisTop;
|
20072 | exports.bin = bin;
|
20073 | exports.bisect = bisect;
|
20074 | exports.bisectCenter = bisectCenter;
|
20075 | exports.bisectLeft = bisectLeft;
|
20076 | exports.bisectRight = bisectRight;
|
20077 | exports.bisector = bisector;
|
20078 | exports.blob = blob;
|
20079 | exports.blur = blur;
|
20080 | exports.blur2 = blur2;
|
20081 | exports.blurImage = blurImage;
|
20082 | exports.brush = brush;
|
20083 | exports.brushSelection = brushSelection;
|
20084 | exports.brushX = brushX;
|
20085 | exports.brushY = brushY;
|
20086 | exports.buffer = buffer;
|
20087 | exports.chord = chord;
|
20088 | exports.chordDirected = chordDirected;
|
20089 | exports.chordTranspose = chordTranspose;
|
20090 | exports.cluster = cluster;
|
20091 | exports.color = color;
|
20092 | exports.contourDensity = density;
|
20093 | exports.contours = Contours;
|
20094 | exports.count = count$1;
|
20095 | exports.create = create$1;
|
20096 | exports.creator = creator;
|
20097 | exports.cross = cross$2;
|
20098 | exports.csv = csv;
|
20099 | exports.csvFormat = csvFormat;
|
20100 | exports.csvFormatBody = csvFormatBody;
|
20101 | exports.csvFormatRow = csvFormatRow;
|
20102 | exports.csvFormatRows = csvFormatRows;
|
20103 | exports.csvFormatValue = csvFormatValue;
|
20104 | exports.csvParse = csvParse;
|
20105 | exports.csvParseRows = csvParseRows;
|
20106 | exports.cubehelix = cubehelix$3;
|
20107 | exports.cumsum = cumsum;
|
20108 | exports.curveBasis = basis;
|
20109 | exports.curveBasisClosed = basisClosed;
|
20110 | exports.curveBasisOpen = basisOpen;
|
20111 | exports.curveBumpX = bumpX;
|
20112 | exports.curveBumpY = bumpY;
|
20113 | exports.curveBundle = bundle;
|
20114 | exports.curveCardinal = cardinal;
|
20115 | exports.curveCardinalClosed = cardinalClosed;
|
20116 | exports.curveCardinalOpen = cardinalOpen;
|
20117 | exports.curveCatmullRom = catmullRom;
|
20118 | exports.curveCatmullRomClosed = catmullRomClosed;
|
20119 | exports.curveCatmullRomOpen = catmullRomOpen;
|
20120 | exports.curveLinear = curveLinear;
|
20121 | exports.curveLinearClosed = linearClosed;
|
20122 | exports.curveMonotoneX = monotoneX;
|
20123 | exports.curveMonotoneY = monotoneY;
|
20124 | exports.curveNatural = natural;
|
20125 | exports.curveStep = step;
|
20126 | exports.curveStepAfter = stepAfter;
|
20127 | exports.curveStepBefore = stepBefore;
|
20128 | exports.descending = descending$2;
|
20129 | exports.deviation = deviation;
|
20130 | exports.difference = difference;
|
20131 | exports.disjoint = disjoint;
|
20132 | exports.dispatch = dispatch;
|
20133 | exports.drag = drag;
|
20134 | exports.dragDisable = dragDisable;
|
20135 | exports.dragEnable = yesdrag;
|
20136 | exports.dsv = dsv;
|
20137 | exports.dsvFormat = dsvFormat;
|
20138 | exports.easeBack = backInOut;
|
20139 | exports.easeBackIn = backIn;
|
20140 | exports.easeBackInOut = backInOut;
|
20141 | exports.easeBackOut = backOut;
|
20142 | exports.easeBounce = bounceOut;
|
20143 | exports.easeBounceIn = bounceIn;
|
20144 | exports.easeBounceInOut = bounceInOut;
|
20145 | exports.easeBounceOut = bounceOut;
|
20146 | exports.easeCircle = circleInOut;
|
20147 | exports.easeCircleIn = circleIn;
|
20148 | exports.easeCircleInOut = circleInOut;
|
20149 | exports.easeCircleOut = circleOut;
|
20150 | exports.easeCubic = cubicInOut;
|
20151 | exports.easeCubicIn = cubicIn;
|
20152 | exports.easeCubicInOut = cubicInOut;
|
20153 | exports.easeCubicOut = cubicOut;
|
20154 | exports.easeElastic = elasticOut;
|
20155 | exports.easeElasticIn = elasticIn;
|
20156 | exports.easeElasticInOut = elasticInOut;
|
20157 | exports.easeElasticOut = elasticOut;
|
20158 | exports.easeExp = expInOut;
|
20159 | exports.easeExpIn = expIn;
|
20160 | exports.easeExpInOut = expInOut;
|
20161 | exports.easeExpOut = expOut;
|
20162 | exports.easeLinear = linear$1;
|
20163 | exports.easePoly = polyInOut;
|
20164 | exports.easePolyIn = polyIn;
|
20165 | exports.easePolyInOut = polyInOut;
|
20166 | exports.easePolyOut = polyOut;
|
20167 | exports.easeQuad = quadInOut;
|
20168 | exports.easeQuadIn = quadIn;
|
20169 | exports.easeQuadInOut = quadInOut;
|
20170 | exports.easeQuadOut = quadOut;
|
20171 | exports.easeSin = sinInOut;
|
20172 | exports.easeSinIn = sinIn;
|
20173 | exports.easeSinInOut = sinInOut;
|
20174 | exports.easeSinOut = sinOut;
|
20175 | exports.every = every;
|
20176 | exports.extent = extent$1;
|
20177 | exports.fcumsum = fcumsum;
|
20178 | exports.filter = filter$1;
|
20179 | exports.flatGroup = flatGroup;
|
20180 | exports.flatRollup = flatRollup;
|
20181 | exports.forceCenter = center;
|
20182 | exports.forceCollide = collide;
|
20183 | exports.forceLink = link$2;
|
20184 | exports.forceManyBody = manyBody;
|
20185 | exports.forceRadial = radial$1;
|
20186 | exports.forceSimulation = simulation;
|
20187 | exports.forceX = x$1;
|
20188 | exports.forceY = y$1;
|
20189 | exports.formatDefaultLocale = defaultLocale$1;
|
20190 | exports.formatLocale = formatLocale$1;
|
20191 | exports.formatSpecifier = formatSpecifier;
|
20192 | exports.fsum = fsum;
|
20193 | exports.geoAlbers = albers;
|
20194 | exports.geoAlbersUsa = albersUsa;
|
20195 | exports.geoArea = area$2;
|
20196 | exports.geoAzimuthalEqualArea = azimuthalEqualArea;
|
20197 | exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
|
20198 | exports.geoAzimuthalEquidistant = azimuthalEquidistant;
|
20199 | exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
|
20200 | exports.geoBounds = bounds;
|
20201 | exports.geoCentroid = centroid$1;
|
20202 | exports.geoCircle = circle$1;
|
20203 | exports.geoClipAntimeridian = clipAntimeridian;
|
20204 | exports.geoClipCircle = clipCircle;
|
20205 | exports.geoClipExtent = extent;
|
20206 | exports.geoClipRectangle = clipRectangle;
|
20207 | exports.geoConicConformal = conicConformal;
|
20208 | exports.geoConicConformalRaw = conicConformalRaw;
|
20209 | exports.geoConicEqualArea = conicEqualArea;
|
20210 | exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
|
20211 | exports.geoConicEquidistant = conicEquidistant;
|
20212 | exports.geoConicEquidistantRaw = conicEquidistantRaw;
|
20213 | exports.geoContains = contains$1;
|
20214 | exports.geoDistance = distance;
|
20215 | exports.geoEqualEarth = equalEarth;
|
20216 | exports.geoEqualEarthRaw = equalEarthRaw;
|
20217 | exports.geoEquirectangular = equirectangular;
|
20218 | exports.geoEquirectangularRaw = equirectangularRaw;
|
20219 | exports.geoGnomonic = gnomonic;
|
20220 | exports.geoGnomonicRaw = gnomonicRaw;
|
20221 | exports.geoGraticule = graticule;
|
20222 | exports.geoGraticule10 = graticule10;
|
20223 | exports.geoIdentity = identity$4;
|
20224 | exports.geoInterpolate = interpolate;
|
20225 | exports.geoLength = length$1;
|
20226 | exports.geoMercator = mercator;
|
20227 | exports.geoMercatorRaw = mercatorRaw;
|
20228 | exports.geoNaturalEarth1 = naturalEarth1;
|
20229 | exports.geoNaturalEarth1Raw = naturalEarth1Raw;
|
20230 | exports.geoOrthographic = orthographic;
|
20231 | exports.geoOrthographicRaw = orthographicRaw;
|
20232 | exports.geoPath = index$2;
|
20233 | exports.geoProjection = projection;
|
20234 | exports.geoProjectionMutator = projectionMutator;
|
20235 | exports.geoRotation = rotation;
|
20236 | exports.geoStereographic = stereographic;
|
20237 | exports.geoStereographicRaw = stereographicRaw;
|
20238 | exports.geoStream = geoStream;
|
20239 | exports.geoTransform = transform$1;
|
20240 | exports.geoTransverseMercator = transverseMercator;
|
20241 | exports.geoTransverseMercatorRaw = transverseMercatorRaw;
|
20242 | exports.gray = gray;
|
20243 | exports.greatest = greatest;
|
20244 | exports.greatestIndex = greatestIndex;
|
20245 | exports.group = group;
|
20246 | exports.groupSort = groupSort;
|
20247 | exports.groups = groups;
|
20248 | exports.hcl = hcl$2;
|
20249 | exports.hierarchy = hierarchy;
|
20250 | exports.histogram = bin;
|
20251 | exports.hsl = hsl$2;
|
20252 | exports.html = html;
|
20253 | exports.image = image;
|
20254 | exports.index = index$4;
|
20255 | exports.indexes = indexes;
|
20256 | exports.interpolate = interpolate$2;
|
20257 | exports.interpolateArray = array$3;
|
20258 | exports.interpolateBasis = basis$2;
|
20259 | exports.interpolateBasisClosed = basisClosed$1;
|
20260 | exports.interpolateBlues = Blues;
|
20261 | exports.interpolateBrBG = BrBG;
|
20262 | exports.interpolateBuGn = BuGn;
|
20263 | exports.interpolateBuPu = BuPu;
|
20264 | exports.interpolateCividis = cividis;
|
20265 | exports.interpolateCool = cool;
|
20266 | exports.interpolateCubehelix = cubehelix$2;
|
20267 | exports.interpolateCubehelixDefault = cubehelix;
|
20268 | exports.interpolateCubehelixLong = cubehelixLong;
|
20269 | exports.interpolateDate = date$1;
|
20270 | exports.interpolateDiscrete = discrete;
|
20271 | exports.interpolateGnBu = GnBu;
|
20272 | exports.interpolateGreens = Greens;
|
20273 | exports.interpolateGreys = Greys;
|
20274 | exports.interpolateHcl = hcl$1;
|
20275 | exports.interpolateHclLong = hclLong;
|
20276 | exports.interpolateHsl = hsl$1;
|
20277 | exports.interpolateHslLong = hslLong;
|
20278 | exports.interpolateHue = hue;
|
20279 | exports.interpolateInferno = inferno;
|
20280 | exports.interpolateLab = lab;
|
20281 | exports.interpolateMagma = magma;
|
20282 | exports.interpolateNumber = interpolateNumber;
|
20283 | exports.interpolateNumberArray = numberArray;
|
20284 | exports.interpolateObject = object$1;
|
20285 | exports.interpolateOrRd = OrRd;
|
20286 | exports.interpolateOranges = Oranges;
|
20287 | exports.interpolatePRGn = PRGn;
|
20288 | exports.interpolatePiYG = PiYG;
|
20289 | exports.interpolatePlasma = plasma;
|
20290 | exports.interpolatePuBu = PuBu;
|
20291 | exports.interpolatePuBuGn = PuBuGn;
|
20292 | exports.interpolatePuOr = PuOr;
|
20293 | exports.interpolatePuRd = PuRd;
|
20294 | exports.interpolatePurples = Purples;
|
20295 | exports.interpolateRainbow = rainbow;
|
20296 | exports.interpolateRdBu = RdBu;
|
20297 | exports.interpolateRdGy = RdGy;
|
20298 | exports.interpolateRdPu = RdPu;
|
20299 | exports.interpolateRdYlBu = RdYlBu;
|
20300 | exports.interpolateRdYlGn = RdYlGn;
|
20301 | exports.interpolateReds = Reds;
|
20302 | exports.interpolateRgb = interpolateRgb;
|
20303 | exports.interpolateRgbBasis = rgbBasis;
|
20304 | exports.interpolateRgbBasisClosed = rgbBasisClosed;
|
20305 | exports.interpolateRound = interpolateRound;
|
20306 | exports.interpolateSinebow = sinebow;
|
20307 | exports.interpolateSpectral = Spectral;
|
20308 | exports.interpolateString = interpolateString;
|
20309 | exports.interpolateTransformCss = interpolateTransformCss;
|
20310 | exports.interpolateTransformSvg = interpolateTransformSvg;
|
20311 | exports.interpolateTurbo = turbo;
|
20312 | exports.interpolateViridis = viridis;
|
20313 | exports.interpolateWarm = warm;
|
20314 | exports.interpolateYlGn = YlGn;
|
20315 | exports.interpolateYlGnBu = YlGnBu;
|
20316 | exports.interpolateYlOrBr = YlOrBr;
|
20317 | exports.interpolateYlOrRd = YlOrRd;
|
20318 | exports.interpolateZoom = interpolateZoom;
|
20319 | exports.interrupt = interrupt;
|
20320 | exports.intersection = intersection;
|
20321 | exports.interval = interval;
|
20322 | exports.isoFormat = formatIso$1;
|
20323 | exports.isoParse = parseIso$1;
|
20324 | exports.json = json;
|
20325 | exports.lab = lab$1;
|
20326 | exports.lch = lch;
|
20327 | exports.least = least;
|
20328 | exports.leastIndex = leastIndex;
|
20329 | exports.line = line;
|
20330 | exports.lineRadial = lineRadial$1;
|
20331 | exports.link = link;
|
20332 | exports.linkHorizontal = linkHorizontal;
|
20333 | exports.linkRadial = linkRadial;
|
20334 | exports.linkVertical = linkVertical;
|
20335 | exports.local = local$1;
|
20336 | exports.map = map$1;
|
20337 | exports.matcher = matcher;
|
20338 | exports.max = max$3;
|
20339 | exports.maxIndex = maxIndex;
|
20340 | exports.mean = mean;
|
20341 | exports.median = median;
|
20342 | exports.medianIndex = medianIndex;
|
20343 | exports.merge = merge;
|
20344 | exports.min = min$2;
|
20345 | exports.minIndex = minIndex;
|
20346 | exports.mode = mode;
|
20347 | exports.namespace = namespace;
|
20348 | exports.namespaces = namespaces;
|
20349 | exports.nice = nice$1;
|
20350 | exports.now = now;
|
20351 | exports.pack = index$1;
|
20352 | exports.packEnclose = enclose;
|
20353 | exports.packSiblings = siblings;
|
20354 | exports.pairs = pairs;
|
20355 | exports.partition = partition;
|
20356 | exports.path = path;
|
20357 | exports.pathRound = pathRound;
|
20358 | exports.permute = permute;
|
20359 | exports.pie = pie;
|
20360 | exports.piecewise = piecewise;
|
20361 | exports.pointRadial = pointRadial;
|
20362 | exports.pointer = pointer;
|
20363 | exports.pointers = pointers;
|
20364 | exports.polygonArea = area$1;
|
20365 | exports.polygonCentroid = centroid;
|
20366 | exports.polygonContains = contains;
|
20367 | exports.polygonHull = hull;
|
20368 | exports.polygonLength = length;
|
20369 | exports.precisionFixed = precisionFixed;
|
20370 | exports.precisionPrefix = precisionPrefix;
|
20371 | exports.precisionRound = precisionRound;
|
20372 | exports.quadtree = quadtree;
|
20373 | exports.quantile = quantile$1;
|
20374 | exports.quantileIndex = quantileIndex;
|
20375 | exports.quantileSorted = quantileSorted;
|
20376 | exports.quantize = quantize$1;
|
20377 | exports.quickselect = quickselect;
|
20378 | exports.radialArea = areaRadial;
|
20379 | exports.radialLine = lineRadial$1;
|
20380 | exports.randomBates = bates;
|
20381 | exports.randomBernoulli = bernoulli;
|
20382 | exports.randomBeta = beta;
|
20383 | exports.randomBinomial = binomial;
|
20384 | exports.randomCauchy = cauchy;
|
20385 | exports.randomExponential = exponential;
|
20386 | exports.randomGamma = gamma;
|
20387 | exports.randomGeometric = geometric;
|
20388 | exports.randomInt = int;
|
20389 | exports.randomIrwinHall = irwinHall;
|
20390 | exports.randomLcg = lcg;
|
20391 | exports.randomLogNormal = logNormal;
|
20392 | exports.randomLogistic = logistic;
|
20393 | exports.randomNormal = normal;
|
20394 | exports.randomPareto = pareto;
|
20395 | exports.randomPoisson = poisson;
|
20396 | exports.randomUniform = uniform;
|
20397 | exports.randomWeibull = weibull;
|
20398 | exports.range = range$2;
|
20399 | exports.rank = rank;
|
20400 | exports.reduce = reduce;
|
20401 | exports.reverse = reverse$1;
|
20402 | exports.rgb = rgb;
|
20403 | exports.ribbon = ribbon$1;
|
20404 | exports.ribbonArrow = ribbonArrow;
|
20405 | exports.rollup = rollup;
|
20406 | exports.rollups = rollups;
|
20407 | exports.scaleBand = band;
|
20408 | exports.scaleDiverging = diverging$1;
|
20409 | exports.scaleDivergingLog = divergingLog;
|
20410 | exports.scaleDivergingPow = divergingPow;
|
20411 | exports.scaleDivergingSqrt = divergingSqrt;
|
20412 | exports.scaleDivergingSymlog = divergingSymlog;
|
20413 | exports.scaleIdentity = identity$2;
|
20414 | exports.scaleImplicit = implicit;
|
20415 | exports.scaleLinear = linear;
|
20416 | exports.scaleLog = log;
|
20417 | exports.scaleOrdinal = ordinal;
|
20418 | exports.scalePoint = point$4;
|
20419 | exports.scalePow = pow;
|
20420 | exports.scaleQuantile = quantile;
|
20421 | exports.scaleQuantize = quantize;
|
20422 | exports.scaleRadial = radial;
|
20423 | exports.scaleSequential = sequential;
|
20424 | exports.scaleSequentialLog = sequentialLog;
|
20425 | exports.scaleSequentialPow = sequentialPow;
|
20426 | exports.scaleSequentialQuantile = sequentialQuantile;
|
20427 | exports.scaleSequentialSqrt = sequentialSqrt;
|
20428 | exports.scaleSequentialSymlog = sequentialSymlog;
|
20429 | exports.scaleSqrt = sqrt$1;
|
20430 | exports.scaleSymlog = symlog;
|
20431 | exports.scaleThreshold = threshold;
|
20432 | exports.scaleTime = time;
|
20433 | exports.scaleUtc = utcTime;
|
20434 | exports.scan = scan;
|
20435 | exports.schemeAccent = Accent;
|
20436 | exports.schemeBlues = scheme$5;
|
20437 | exports.schemeBrBG = scheme$q;
|
20438 | exports.schemeBuGn = scheme$h;
|
20439 | exports.schemeBuPu = scheme$g;
|
20440 | exports.schemeCategory10 = category10;
|
20441 | exports.schemeDark2 = Dark2;
|
20442 | exports.schemeGnBu = scheme$f;
|
20443 | exports.schemeGreens = scheme$4;
|
20444 | exports.schemeGreys = scheme$3;
|
20445 | exports.schemeOrRd = scheme$e;
|
20446 | exports.schemeOranges = scheme;
|
20447 | exports.schemePRGn = scheme$p;
|
20448 | exports.schemePaired = Paired;
|
20449 | exports.schemePastel1 = Pastel1;
|
20450 | exports.schemePastel2 = Pastel2;
|
20451 | exports.schemePiYG = scheme$o;
|
20452 | exports.schemePuBu = scheme$c;
|
20453 | exports.schemePuBuGn = scheme$d;
|
20454 | exports.schemePuOr = scheme$n;
|
20455 | exports.schemePuRd = scheme$b;
|
20456 | exports.schemePurples = scheme$2;
|
20457 | exports.schemeRdBu = scheme$m;
|
20458 | exports.schemeRdGy = scheme$l;
|
20459 | exports.schemeRdPu = scheme$a;
|
20460 | exports.schemeRdYlBu = scheme$k;
|
20461 | exports.schemeRdYlGn = scheme$j;
|
20462 | exports.schemeReds = scheme$1;
|
20463 | exports.schemeSet1 = Set1;
|
20464 | exports.schemeSet2 = Set2;
|
20465 | exports.schemeSet3 = Set3;
|
20466 | exports.schemeSpectral = scheme$i;
|
20467 | exports.schemeTableau10 = Tableau10;
|
20468 | exports.schemeYlGn = scheme$8;
|
20469 | exports.schemeYlGnBu = scheme$9;
|
20470 | exports.schemeYlOrBr = scheme$7;
|
20471 | exports.schemeYlOrRd = scheme$6;
|
20472 | exports.select = select;
|
20473 | exports.selectAll = selectAll;
|
20474 | exports.selection = selection;
|
20475 | exports.selector = selector;
|
20476 | exports.selectorAll = selectorAll;
|
20477 | exports.shuffle = shuffle$1;
|
20478 | exports.shuffler = shuffler;
|
20479 | exports.some = some;
|
20480 | exports.sort = sort;
|
20481 | exports.stack = stack;
|
20482 | exports.stackOffsetDiverging = diverging;
|
20483 | exports.stackOffsetExpand = expand;
|
20484 | exports.stackOffsetNone = none$1;
|
20485 | exports.stackOffsetSilhouette = silhouette;
|
20486 | exports.stackOffsetWiggle = wiggle;
|
20487 | exports.stackOrderAppearance = appearance;
|
20488 | exports.stackOrderAscending = ascending;
|
20489 | exports.stackOrderDescending = descending;
|
20490 | exports.stackOrderInsideOut = insideOut;
|
20491 | exports.stackOrderNone = none;
|
20492 | exports.stackOrderReverse = reverse;
|
20493 | exports.stratify = stratify;
|
20494 | exports.style = styleValue;
|
20495 | exports.subset = subset;
|
20496 | exports.sum = sum$2;
|
20497 | exports.superset = superset;
|
20498 | exports.svg = svg;
|
20499 | exports.symbol = Symbol$1;
|
20500 | exports.symbolAsterisk = asterisk;
|
20501 | exports.symbolCircle = circle;
|
20502 | exports.symbolCross = cross;
|
20503 | exports.symbolDiamond = diamond;
|
20504 | exports.symbolDiamond2 = diamond2;
|
20505 | exports.symbolPlus = plus;
|
20506 | exports.symbolSquare = square;
|
20507 | exports.symbolSquare2 = square2;
|
20508 | exports.symbolStar = star;
|
20509 | exports.symbolTimes = times;
|
20510 | exports.symbolTriangle = triangle;
|
20511 | exports.symbolTriangle2 = triangle2;
|
20512 | exports.symbolWye = wye;
|
20513 | exports.symbolX = times;
|
20514 | exports.symbols = symbolsFill;
|
20515 | exports.symbolsFill = symbolsFill;
|
20516 | exports.symbolsStroke = symbolsStroke;
|
20517 | exports.text = text;
|
20518 | exports.thresholdFreedmanDiaconis = thresholdFreedmanDiaconis;
|
20519 | exports.thresholdScott = thresholdScott;
|
20520 | exports.thresholdSturges = thresholdSturges;
|
20521 | exports.tickFormat = tickFormat;
|
20522 | exports.tickIncrement = tickIncrement;
|
20523 | exports.tickStep = tickStep;
|
20524 | exports.ticks = ticks;
|
20525 | exports.timeDay = timeDay;
|
20526 | exports.timeDays = timeDays;
|
20527 | exports.timeFormatDefaultLocale = defaultLocale;
|
20528 | exports.timeFormatLocale = formatLocale;
|
20529 | exports.timeFriday = timeFriday;
|
20530 | exports.timeFridays = timeFridays;
|
20531 | exports.timeHour = timeHour;
|
20532 | exports.timeHours = timeHours;
|
20533 | exports.timeInterval = timeInterval;
|
20534 | exports.timeMillisecond = millisecond;
|
20535 | exports.timeMilliseconds = milliseconds;
|
20536 | exports.timeMinute = timeMinute;
|
20537 | exports.timeMinutes = timeMinutes;
|
20538 | exports.timeMonday = timeMonday;
|
20539 | exports.timeMondays = timeMondays;
|
20540 | exports.timeMonth = timeMonth;
|
20541 | exports.timeMonths = timeMonths;
|
20542 | exports.timeSaturday = timeSaturday;
|
20543 | exports.timeSaturdays = timeSaturdays;
|
20544 | exports.timeSecond = second;
|
20545 | exports.timeSeconds = seconds;
|
20546 | exports.timeSunday = timeSunday;
|
20547 | exports.timeSundays = timeSundays;
|
20548 | exports.timeThursday = timeThursday;
|
20549 | exports.timeThursdays = timeThursdays;
|
20550 | exports.timeTickInterval = timeTickInterval;
|
20551 | exports.timeTicks = timeTicks;
|
20552 | exports.timeTuesday = timeTuesday;
|
20553 | exports.timeTuesdays = timeTuesdays;
|
20554 | exports.timeWednesday = timeWednesday;
|
20555 | exports.timeWednesdays = timeWednesdays;
|
20556 | exports.timeWeek = timeSunday;
|
20557 | exports.timeWeeks = timeSundays;
|
20558 | exports.timeYear = timeYear;
|
20559 | exports.timeYears = timeYears;
|
20560 | exports.timeout = timeout;
|
20561 | exports.timer = timer;
|
20562 | exports.timerFlush = timerFlush;
|
20563 | exports.transition = transition;
|
20564 | exports.transpose = transpose;
|
20565 | exports.tree = tree;
|
20566 | exports.treemap = index;
|
20567 | exports.treemapBinary = binary;
|
20568 | exports.treemapDice = treemapDice;
|
20569 | exports.treemapResquarify = resquarify;
|
20570 | exports.treemapSlice = treemapSlice;
|
20571 | exports.treemapSliceDice = sliceDice;
|
20572 | exports.treemapSquarify = squarify;
|
20573 | exports.tsv = tsv;
|
20574 | exports.tsvFormat = tsvFormat;
|
20575 | exports.tsvFormatBody = tsvFormatBody;
|
20576 | exports.tsvFormatRow = tsvFormatRow;
|
20577 | exports.tsvFormatRows = tsvFormatRows;
|
20578 | exports.tsvFormatValue = tsvFormatValue;
|
20579 | exports.tsvParse = tsvParse;
|
20580 | exports.tsvParseRows = tsvParseRows;
|
20581 | exports.union = union;
|
20582 | exports.unixDay = unixDay;
|
20583 | exports.unixDays = unixDays;
|
20584 | exports.utcDay = utcDay;
|
20585 | exports.utcDays = utcDays;
|
20586 | exports.utcFriday = utcFriday;
|
20587 | exports.utcFridays = utcFridays;
|
20588 | exports.utcHour = utcHour;
|
20589 | exports.utcHours = utcHours;
|
20590 | exports.utcMillisecond = millisecond;
|
20591 | exports.utcMilliseconds = milliseconds;
|
20592 | exports.utcMinute = utcMinute;
|
20593 | exports.utcMinutes = utcMinutes;
|
20594 | exports.utcMonday = utcMonday;
|
20595 | exports.utcMondays = utcMondays;
|
20596 | exports.utcMonth = utcMonth;
|
20597 | exports.utcMonths = utcMonths;
|
20598 | exports.utcSaturday = utcSaturday;
|
20599 | exports.utcSaturdays = utcSaturdays;
|
20600 | exports.utcSecond = second;
|
20601 | exports.utcSeconds = seconds;
|
20602 | exports.utcSunday = utcSunday;
|
20603 | exports.utcSundays = utcSundays;
|
20604 | exports.utcThursday = utcThursday;
|
20605 | exports.utcThursdays = utcThursdays;
|
20606 | exports.utcTickInterval = utcTickInterval;
|
20607 | exports.utcTicks = utcTicks;
|
20608 | exports.utcTuesday = utcTuesday;
|
20609 | exports.utcTuesdays = utcTuesdays;
|
20610 | exports.utcWednesday = utcWednesday;
|
20611 | exports.utcWednesdays = utcWednesdays;
|
20612 | exports.utcWeek = utcSunday;
|
20613 | exports.utcWeeks = utcSundays;
|
20614 | exports.utcYear = utcYear;
|
20615 | exports.utcYears = utcYears;
|
20616 | exports.variance = variance;
|
20617 | exports.version = version;
|
20618 | exports.window = defaultView;
|
20619 | exports.xml = xml;
|
20620 | exports.zip = zip;
|
20621 | exports.zoom = zoom;
|
20622 | exports.zoomIdentity = identity;
|
20623 | exports.zoomTransform = transform;
|
20624 |
|
20625 | }));
|
20626 |
|
\ | No newline at end of file |