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 = global || self, factory(global.d3 = global.d3 || {}));
|
6 | }(this, function (exports) { 'use strict';
|
7 |
|
8 | var version = "5.15.0";
|
9 |
|
10 | function ascending(a, b) {
|
11 | return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
12 | }
|
13 |
|
14 | function bisector(compare) {
|
15 | if (compare.length === 1) compare = ascendingComparator(compare);
|
16 | return {
|
17 | left: function(a, x, lo, hi) {
|
18 | if (lo == null) lo = 0;
|
19 | if (hi == null) hi = a.length;
|
20 | while (lo < hi) {
|
21 | var mid = lo + hi >>> 1;
|
22 | if (compare(a[mid], x) < 0) lo = mid + 1;
|
23 | else hi = mid;
|
24 | }
|
25 | return lo;
|
26 | },
|
27 | right: function(a, x, lo, hi) {
|
28 | if (lo == null) lo = 0;
|
29 | if (hi == null) hi = a.length;
|
30 | while (lo < hi) {
|
31 | var mid = lo + hi >>> 1;
|
32 | if (compare(a[mid], x) > 0) hi = mid;
|
33 | else lo = mid + 1;
|
34 | }
|
35 | return lo;
|
36 | }
|
37 | };
|
38 | }
|
39 |
|
40 | function ascendingComparator(f) {
|
41 | return function(d, x) {
|
42 | return ascending(f(d), x);
|
43 | };
|
44 | }
|
45 |
|
46 | var ascendingBisect = bisector(ascending);
|
47 | var bisectRight = ascendingBisect.right;
|
48 | var bisectLeft = ascendingBisect.left;
|
49 |
|
50 | function pairs(array, f) {
|
51 | if (f == null) f = pair;
|
52 | var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
|
53 | while (i < n) pairs[i] = f(p, p = array[++i]);
|
54 | return pairs;
|
55 | }
|
56 |
|
57 | function pair(a, b) {
|
58 | return [a, b];
|
59 | }
|
60 |
|
61 | function cross(values0, values1, reduce) {
|
62 | var n0 = values0.length,
|
63 | n1 = values1.length,
|
64 | values = new Array(n0 * n1),
|
65 | i0,
|
66 | i1,
|
67 | i,
|
68 | value0;
|
69 |
|
70 | if (reduce == null) reduce = pair;
|
71 |
|
72 | for (i0 = i = 0; i0 < n0; ++i0) {
|
73 | for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
|
74 | values[i] = reduce(value0, values1[i1]);
|
75 | }
|
76 | }
|
77 |
|
78 | return values;
|
79 | }
|
80 |
|
81 | function descending(a, b) {
|
82 | return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
83 | }
|
84 |
|
85 | function number(x) {
|
86 | return x === null ? NaN : +x;
|
87 | }
|
88 |
|
89 | function variance(values, valueof) {
|
90 | var n = values.length,
|
91 | m = 0,
|
92 | i = -1,
|
93 | mean = 0,
|
94 | value,
|
95 | delta,
|
96 | sum = 0;
|
97 |
|
98 | if (valueof == null) {
|
99 | while (++i < n) {
|
100 | if (!isNaN(value = number(values[i]))) {
|
101 | delta = value - mean;
|
102 | mean += delta / ++m;
|
103 | sum += delta * (value - mean);
|
104 | }
|
105 | }
|
106 | }
|
107 |
|
108 | else {
|
109 | while (++i < n) {
|
110 | if (!isNaN(value = number(valueof(values[i], i, values)))) {
|
111 | delta = value - mean;
|
112 | mean += delta / ++m;
|
113 | sum += delta * (value - mean);
|
114 | }
|
115 | }
|
116 | }
|
117 |
|
118 | if (m > 1) return sum / (m - 1);
|
119 | }
|
120 |
|
121 | function deviation(array, f) {
|
122 | var v = variance(array, f);
|
123 | return v ? Math.sqrt(v) : v;
|
124 | }
|
125 |
|
126 | function extent(values, valueof) {
|
127 | var n = values.length,
|
128 | i = -1,
|
129 | value,
|
130 | min,
|
131 | max;
|
132 |
|
133 | if (valueof == null) {
|
134 | while (++i < n) {
|
135 | if ((value = values[i]) != null && value >= value) {
|
136 | min = max = value;
|
137 | while (++i < n) {
|
138 | if ((value = values[i]) != null) {
|
139 | if (min > value) min = value;
|
140 | if (max < value) max = value;
|
141 | }
|
142 | }
|
143 | }
|
144 | }
|
145 | }
|
146 |
|
147 | else {
|
148 | while (++i < n) {
|
149 | if ((value = valueof(values[i], i, values)) != null && value >= value) {
|
150 | min = max = value;
|
151 | while (++i < n) {
|
152 | if ((value = valueof(values[i], i, values)) != null) {
|
153 | if (min > value) min = value;
|
154 | if (max < value) max = value;
|
155 | }
|
156 | }
|
157 | }
|
158 | }
|
159 | }
|
160 |
|
161 | return [min, max];
|
162 | }
|
163 |
|
164 | var array = Array.prototype;
|
165 |
|
166 | var slice = array.slice;
|
167 | var map = array.map;
|
168 |
|
169 | function constant(x) {
|
170 | return function() {
|
171 | return x;
|
172 | };
|
173 | }
|
174 |
|
175 | function identity(x) {
|
176 | return x;
|
177 | }
|
178 |
|
179 | function sequence(start, stop, step) {
|
180 | start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
|
181 |
|
182 | var i = -1,
|
183 | n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
|
184 | range = new Array(n);
|
185 |
|
186 | while (++i < n) {
|
187 | range[i] = start + i * step;
|
188 | }
|
189 |
|
190 | return range;
|
191 | }
|
192 |
|
193 | var e10 = Math.sqrt(50),
|
194 | e5 = Math.sqrt(10),
|
195 | e2 = Math.sqrt(2);
|
196 |
|
197 | function ticks(start, stop, count) {
|
198 | var reverse,
|
199 | i = -1,
|
200 | n,
|
201 | ticks,
|
202 | step;
|
203 |
|
204 | stop = +stop, start = +start, count = +count;
|
205 | if (start === stop && count > 0) return [start];
|
206 | if (reverse = stop < start) n = start, start = stop, stop = n;
|
207 | if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
|
208 |
|
209 | if (step > 0) {
|
210 | start = Math.ceil(start / step);
|
211 | stop = Math.floor(stop / step);
|
212 | ticks = new Array(n = Math.ceil(stop - start + 1));
|
213 | while (++i < n) ticks[i] = (start + i) * step;
|
214 | } else {
|
215 | start = Math.floor(start * step);
|
216 | stop = Math.ceil(stop * step);
|
217 | ticks = new Array(n = Math.ceil(start - stop + 1));
|
218 | while (++i < n) ticks[i] = (start - i) / step;
|
219 | }
|
220 |
|
221 | if (reverse) ticks.reverse();
|
222 |
|
223 | return ticks;
|
224 | }
|
225 |
|
226 | function tickIncrement(start, stop, count) {
|
227 | var step = (stop - start) / Math.max(0, count),
|
228 | power = Math.floor(Math.log(step) / Math.LN10),
|
229 | error = step / Math.pow(10, power);
|
230 | return power >= 0
|
231 | ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
|
232 | : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
|
233 | }
|
234 |
|
235 | function tickStep(start, stop, count) {
|
236 | var step0 = Math.abs(stop - start) / Math.max(0, count),
|
237 | step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
|
238 | error = step0 / step1;
|
239 | if (error >= e10) step1 *= 10;
|
240 | else if (error >= e5) step1 *= 5;
|
241 | else if (error >= e2) step1 *= 2;
|
242 | return stop < start ? -step1 : step1;
|
243 | }
|
244 |
|
245 | function thresholdSturges(values) {
|
246 | return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
|
247 | }
|
248 |
|
249 | function histogram() {
|
250 | var value = identity,
|
251 | domain = extent,
|
252 | threshold = thresholdSturges;
|
253 |
|
254 | function histogram(data) {
|
255 | var i,
|
256 | n = data.length,
|
257 | x,
|
258 | values = new Array(n);
|
259 |
|
260 | for (i = 0; i < n; ++i) {
|
261 | values[i] = value(data[i], i, data);
|
262 | }
|
263 |
|
264 | var xz = domain(values),
|
265 | x0 = xz[0],
|
266 | x1 = xz[1],
|
267 | tz = threshold(values, x0, x1);
|
268 |
|
269 |
|
270 | if (!Array.isArray(tz)) {
|
271 | tz = tickStep(x0, x1, tz);
|
272 | tz = sequence(Math.ceil(x0 / tz) * tz, x1, tz);
|
273 | }
|
274 |
|
275 |
|
276 | var m = tz.length;
|
277 | while (tz[0] <= x0) tz.shift(), --m;
|
278 | while (tz[m - 1] > x1) tz.pop(), --m;
|
279 |
|
280 | var bins = new Array(m + 1),
|
281 | bin;
|
282 |
|
283 |
|
284 | for (i = 0; i <= m; ++i) {
|
285 | bin = bins[i] = [];
|
286 | bin.x0 = i > 0 ? tz[i - 1] : x0;
|
287 | bin.x1 = i < m ? tz[i] : x1;
|
288 | }
|
289 |
|
290 |
|
291 | for (i = 0; i < n; ++i) {
|
292 | x = values[i];
|
293 | if (x0 <= x && x <= x1) {
|
294 | bins[bisectRight(tz, x, 0, m)].push(data[i]);
|
295 | }
|
296 | }
|
297 |
|
298 | return bins;
|
299 | }
|
300 |
|
301 | histogram.value = function(_) {
|
302 | return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
|
303 | };
|
304 |
|
305 | histogram.domain = function(_) {
|
306 | return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
|
307 | };
|
308 |
|
309 | histogram.thresholds = function(_) {
|
310 | return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
|
311 | };
|
312 |
|
313 | return histogram;
|
314 | }
|
315 |
|
316 | function threshold(values, p, valueof) {
|
317 | if (valueof == null) valueof = number;
|
318 | if (!(n = values.length)) return;
|
319 | if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
|
320 | if (p >= 1) return +valueof(values[n - 1], n - 1, values);
|
321 | var n,
|
322 | i = (n - 1) * p,
|
323 | i0 = Math.floor(i),
|
324 | value0 = +valueof(values[i0], i0, values),
|
325 | value1 = +valueof(values[i0 + 1], i0 + 1, values);
|
326 | return value0 + (value1 - value0) * (i - i0);
|
327 | }
|
328 |
|
329 | function freedmanDiaconis(values, min, max) {
|
330 | values = map.call(values, number).sort(ascending);
|
331 | return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
|
332 | }
|
333 |
|
334 | function scott(values, min, max) {
|
335 | return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
|
336 | }
|
337 |
|
338 | function max(values, valueof) {
|
339 | var n = values.length,
|
340 | i = -1,
|
341 | value,
|
342 | max;
|
343 |
|
344 | if (valueof == null) {
|
345 | while (++i < n) {
|
346 | if ((value = values[i]) != null && value >= value) {
|
347 | max = value;
|
348 | while (++i < n) {
|
349 | if ((value = values[i]) != null && value > max) {
|
350 | max = value;
|
351 | }
|
352 | }
|
353 | }
|
354 | }
|
355 | }
|
356 |
|
357 | else {
|
358 | while (++i < n) {
|
359 | if ((value = valueof(values[i], i, values)) != null && value >= value) {
|
360 | max = value;
|
361 | while (++i < n) {
|
362 | if ((value = valueof(values[i], i, values)) != null && value > max) {
|
363 | max = value;
|
364 | }
|
365 | }
|
366 | }
|
367 | }
|
368 | }
|
369 |
|
370 | return max;
|
371 | }
|
372 |
|
373 | function mean(values, valueof) {
|
374 | var n = values.length,
|
375 | m = n,
|
376 | i = -1,
|
377 | value,
|
378 | sum = 0;
|
379 |
|
380 | if (valueof == null) {
|
381 | while (++i < n) {
|
382 | if (!isNaN(value = number(values[i]))) sum += value;
|
383 | else --m;
|
384 | }
|
385 | }
|
386 |
|
387 | else {
|
388 | while (++i < n) {
|
389 | if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
|
390 | else --m;
|
391 | }
|
392 | }
|
393 |
|
394 | if (m) return sum / m;
|
395 | }
|
396 |
|
397 | function median(values, valueof) {
|
398 | var n = values.length,
|
399 | i = -1,
|
400 | value,
|
401 | numbers = [];
|
402 |
|
403 | if (valueof == null) {
|
404 | while (++i < n) {
|
405 | if (!isNaN(value = number(values[i]))) {
|
406 | numbers.push(value);
|
407 | }
|
408 | }
|
409 | }
|
410 |
|
411 | else {
|
412 | while (++i < n) {
|
413 | if (!isNaN(value = number(valueof(values[i], i, values)))) {
|
414 | numbers.push(value);
|
415 | }
|
416 | }
|
417 | }
|
418 |
|
419 | return threshold(numbers.sort(ascending), 0.5);
|
420 | }
|
421 |
|
422 | function merge(arrays) {
|
423 | var n = arrays.length,
|
424 | m,
|
425 | i = -1,
|
426 | j = 0,
|
427 | merged,
|
428 | array;
|
429 |
|
430 | while (++i < n) j += arrays[i].length;
|
431 | merged = new Array(j);
|
432 |
|
433 | while (--n >= 0) {
|
434 | array = arrays[n];
|
435 | m = array.length;
|
436 | while (--m >= 0) {
|
437 | merged[--j] = array[m];
|
438 | }
|
439 | }
|
440 |
|
441 | return merged;
|
442 | }
|
443 |
|
444 | function min(values, valueof) {
|
445 | var n = values.length,
|
446 | i = -1,
|
447 | value,
|
448 | min;
|
449 |
|
450 | if (valueof == null) {
|
451 | while (++i < n) {
|
452 | if ((value = values[i]) != null && value >= value) {
|
453 | min = value;
|
454 | while (++i < n) {
|
455 | if ((value = values[i]) != null && min > value) {
|
456 | min = value;
|
457 | }
|
458 | }
|
459 | }
|
460 | }
|
461 | }
|
462 |
|
463 | else {
|
464 | while (++i < n) {
|
465 | if ((value = valueof(values[i], i, values)) != null && value >= value) {
|
466 | min = value;
|
467 | while (++i < n) {
|
468 | if ((value = valueof(values[i], i, values)) != null && min > value) {
|
469 | min = value;
|
470 | }
|
471 | }
|
472 | }
|
473 | }
|
474 | }
|
475 |
|
476 | return min;
|
477 | }
|
478 |
|
479 | function permute(array, indexes) {
|
480 | var i = indexes.length, permutes = new Array(i);
|
481 | while (i--) permutes[i] = array[indexes[i]];
|
482 | return permutes;
|
483 | }
|
484 |
|
485 | function scan(values, compare) {
|
486 | if (!(n = values.length)) return;
|
487 | var n,
|
488 | i = 0,
|
489 | j = 0,
|
490 | xi,
|
491 | xj = values[j];
|
492 |
|
493 | if (compare == null) compare = ascending;
|
494 |
|
495 | while (++i < n) {
|
496 | if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
|
497 | xj = xi, j = i;
|
498 | }
|
499 | }
|
500 |
|
501 | if (compare(xj, xj) === 0) return j;
|
502 | }
|
503 |
|
504 | function shuffle(array, i0, i1) {
|
505 | var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
|
506 | t,
|
507 | i;
|
508 |
|
509 | while (m) {
|
510 | i = Math.random() * m-- | 0;
|
511 | t = array[m + i0];
|
512 | array[m + i0] = array[i + i0];
|
513 | array[i + i0] = t;
|
514 | }
|
515 |
|
516 | return array;
|
517 | }
|
518 |
|
519 | function sum(values, valueof) {
|
520 | var n = values.length,
|
521 | i = -1,
|
522 | value,
|
523 | sum = 0;
|
524 |
|
525 | if (valueof == null) {
|
526 | while (++i < n) {
|
527 | if (value = +values[i]) sum += value;
|
528 | }
|
529 | }
|
530 |
|
531 | else {
|
532 | while (++i < n) {
|
533 | if (value = +valueof(values[i], i, values)) sum += value;
|
534 | }
|
535 | }
|
536 |
|
537 | return sum;
|
538 | }
|
539 |
|
540 | function transpose(matrix) {
|
541 | if (!(n = matrix.length)) return [];
|
542 | for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
|
543 | for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
|
544 | row[j] = matrix[j][i];
|
545 | }
|
546 | }
|
547 | return transpose;
|
548 | }
|
549 |
|
550 | function length(d) {
|
551 | return d.length;
|
552 | }
|
553 |
|
554 | function zip() {
|
555 | return transpose(arguments);
|
556 | }
|
557 |
|
558 | var slice$1 = Array.prototype.slice;
|
559 |
|
560 | function identity$1(x) {
|
561 | return x;
|
562 | }
|
563 |
|
564 | var top = 1,
|
565 | right = 2,
|
566 | bottom = 3,
|
567 | left = 4,
|
568 | epsilon = 1e-6;
|
569 |
|
570 | function translateX(x) {
|
571 | return "translate(" + (x + 0.5) + ",0)";
|
572 | }
|
573 |
|
574 | function translateY(y) {
|
575 | return "translate(0," + (y + 0.5) + ")";
|
576 | }
|
577 |
|
578 | function number$1(scale) {
|
579 | return function(d) {
|
580 | return +scale(d);
|
581 | };
|
582 | }
|
583 |
|
584 | function center(scale) {
|
585 | var offset = Math.max(0, scale.bandwidth() - 1) / 2;
|
586 | if (scale.round()) offset = Math.round(offset);
|
587 | return function(d) {
|
588 | return +scale(d) + offset;
|
589 | };
|
590 | }
|
591 |
|
592 | function entering() {
|
593 | return !this.__axis;
|
594 | }
|
595 |
|
596 | function axis(orient, scale) {
|
597 | var tickArguments = [],
|
598 | tickValues = null,
|
599 | tickFormat = null,
|
600 | tickSizeInner = 6,
|
601 | tickSizeOuter = 6,
|
602 | tickPadding = 3,
|
603 | k = orient === top || orient === left ? -1 : 1,
|
604 | x = orient === left || orient === right ? "x" : "y",
|
605 | transform = orient === top || orient === bottom ? translateX : translateY;
|
606 |
|
607 | function axis(context) {
|
608 | var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
|
609 | format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
|
610 | spacing = Math.max(tickSizeInner, 0) + tickPadding,
|
611 | range = scale.range(),
|
612 | range0 = +range[0] + 0.5,
|
613 | range1 = +range[range.length - 1] + 0.5,
|
614 | position = (scale.bandwidth ? center : number$1)(scale.copy()),
|
615 | selection = context.selection ? context.selection() : context,
|
616 | path = selection.selectAll(".domain").data([null]),
|
617 | tick = selection.selectAll(".tick").data(values, scale).order(),
|
618 | tickExit = tick.exit(),
|
619 | tickEnter = tick.enter().append("g").attr("class", "tick"),
|
620 | line = tick.select("line"),
|
621 | text = tick.select("text");
|
622 |
|
623 | path = path.merge(path.enter().insert("path", ".tick")
|
624 | .attr("class", "domain")
|
625 | .attr("stroke", "currentColor"));
|
626 |
|
627 | tick = tick.merge(tickEnter);
|
628 |
|
629 | line = line.merge(tickEnter.append("line")
|
630 | .attr("stroke", "currentColor")
|
631 | .attr(x + "2", k * tickSizeInner));
|
632 |
|
633 | text = text.merge(tickEnter.append("text")
|
634 | .attr("fill", "currentColor")
|
635 | .attr(x, k * spacing)
|
636 | .attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
|
637 |
|
638 | if (context !== selection) {
|
639 | path = path.transition(context);
|
640 | tick = tick.transition(context);
|
641 | line = line.transition(context);
|
642 | text = text.transition(context);
|
643 |
|
644 | tickExit = tickExit.transition(context)
|
645 | .attr("opacity", epsilon)
|
646 | .attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
|
647 |
|
648 | tickEnter
|
649 | .attr("opacity", epsilon)
|
650 | .attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
|
651 | }
|
652 |
|
653 | tickExit.remove();
|
654 |
|
655 | path
|
656 | .attr("d", orient === left || orient == right
|
657 | ? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M0.5," + range0 + "V" + range1)
|
658 | : (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + ",0.5H" + range1));
|
659 |
|
660 | tick
|
661 | .attr("opacity", 1)
|
662 | .attr("transform", function(d) { return transform(position(d)); });
|
663 |
|
664 | line
|
665 | .attr(x + "2", k * tickSizeInner);
|
666 |
|
667 | text
|
668 | .attr(x, k * spacing)
|
669 | .text(format);
|
670 |
|
671 | selection.filter(entering)
|
672 | .attr("fill", "none")
|
673 | .attr("font-size", 10)
|
674 | .attr("font-family", "sans-serif")
|
675 | .attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
|
676 |
|
677 | selection
|
678 | .each(function() { this.__axis = position; });
|
679 | }
|
680 |
|
681 | axis.scale = function(_) {
|
682 | return arguments.length ? (scale = _, axis) : scale;
|
683 | };
|
684 |
|
685 | axis.ticks = function() {
|
686 | return tickArguments = slice$1.call(arguments), axis;
|
687 | };
|
688 |
|
689 | axis.tickArguments = function(_) {
|
690 | return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
|
691 | };
|
692 |
|
693 | axis.tickValues = function(_) {
|
694 | return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
|
695 | };
|
696 |
|
697 | axis.tickFormat = function(_) {
|
698 | return arguments.length ? (tickFormat = _, axis) : tickFormat;
|
699 | };
|
700 |
|
701 | axis.tickSize = function(_) {
|
702 | return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
|
703 | };
|
704 |
|
705 | axis.tickSizeInner = function(_) {
|
706 | return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
|
707 | };
|
708 |
|
709 | axis.tickSizeOuter = function(_) {
|
710 | return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
|
711 | };
|
712 |
|
713 | axis.tickPadding = function(_) {
|
714 | return arguments.length ? (tickPadding = +_, axis) : tickPadding;
|
715 | };
|
716 |
|
717 | return axis;
|
718 | }
|
719 |
|
720 | function axisTop(scale) {
|
721 | return axis(top, scale);
|
722 | }
|
723 |
|
724 | function axisRight(scale) {
|
725 | return axis(right, scale);
|
726 | }
|
727 |
|
728 | function axisBottom(scale) {
|
729 | return axis(bottom, scale);
|
730 | }
|
731 |
|
732 | function axisLeft(scale) {
|
733 | return axis(left, scale);
|
734 | }
|
735 |
|
736 | var noop = {value: function() {}};
|
737 |
|
738 | function dispatch() {
|
739 | for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
|
740 | if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
|
741 | _[t] = [];
|
742 | }
|
743 | return new Dispatch(_);
|
744 | }
|
745 |
|
746 | function Dispatch(_) {
|
747 | this._ = _;
|
748 | }
|
749 |
|
750 | function parseTypenames(typenames, types) {
|
751 | return typenames.trim().split(/^|\s+/).map(function(t) {
|
752 | var name = "", i = t.indexOf(".");
|
753 | if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
754 | if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
|
755 | return {type: t, name: name};
|
756 | });
|
757 | }
|
758 |
|
759 | Dispatch.prototype = dispatch.prototype = {
|
760 | constructor: Dispatch,
|
761 | on: function(typename, callback) {
|
762 | var _ = this._,
|
763 | T = parseTypenames(typename + "", _),
|
764 | t,
|
765 | i = -1,
|
766 | n = T.length;
|
767 |
|
768 |
|
769 | if (arguments.length < 2) {
|
770 | while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
|
771 | return;
|
772 | }
|
773 |
|
774 | // If a type was specified, set the callback for the given type and name.
|
775 | // Otherwise, if a null callback was specified, remove callbacks of the given name.
|
776 | if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
|
777 | while (++i < n) {
|
778 | if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
|
779 | else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
|
780 | }
|
781 |
|
782 | return this;
|
783 | },
|
784 | copy: function() {
|
785 | var copy = {}, _ = this._;
|
786 | for (var t in _) copy[t] = _[t].slice();
|
787 | return new Dispatch(copy);
|
788 | },
|
789 | call: function(type, that) {
|
790 | if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
|
791 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
792 | for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
793 | },
|
794 | apply: function(type, that, args) {
|
795 | if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
796 | for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
797 | }
|
798 | };
|
799 |
|
800 | function get(type, name) {
|
801 | for (var i = 0, n = type.length, c; i < n; ++i) {
|
802 | if ((c = type[i]).name === name) {
|
803 | return c.value;
|
804 | }
|
805 | }
|
806 | }
|
807 |
|
808 | function set(type, name, callback) {
|
809 | for (var i = 0, n = type.length; i < n; ++i) {
|
810 | if (type[i].name === name) {
|
811 | type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
|
812 | break;
|
813 | }
|
814 | }
|
815 | if (callback != null) type.push({name: name, value: callback});
|
816 | return type;
|
817 | }
|
818 |
|
819 | var xhtml = "http://www.w3.org/1999/xhtml";
|
820 |
|
821 | var namespaces = {
|
822 | svg: "http://www.w3.org/2000/svg",
|
823 | xhtml: xhtml,
|
824 | xlink: "http://www.w3.org/1999/xlink",
|
825 | xml: "http://www.w3.org/XML/1998/namespace",
|
826 | xmlns: "http://www.w3.org/2000/xmlns/"
|
827 | };
|
828 |
|
829 | function namespace(name) {
|
830 | var prefix = name += "", i = prefix.indexOf(":");
|
831 | if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
|
832 | return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
|
833 | }
|
834 |
|
835 | function creatorInherit(name) {
|
836 | return function() {
|
837 | var document = this.ownerDocument,
|
838 | uri = this.namespaceURI;
|
839 | return uri === xhtml && document.documentElement.namespaceURI === xhtml
|
840 | ? document.createElement(name)
|
841 | : document.createElementNS(uri, name);
|
842 | };
|
843 | }
|
844 |
|
845 | function creatorFixed(fullname) {
|
846 | return function() {
|
847 | return this.ownerDocument.createElementNS(fullname.space, fullname.local);
|
848 | };
|
849 | }
|
850 |
|
851 | function creator(name) {
|
852 | var fullname = namespace(name);
|
853 | return (fullname.local
|
854 | ? creatorFixed
|
855 | : creatorInherit)(fullname);
|
856 | }
|
857 |
|
858 | function none() {}
|
859 |
|
860 | function selector(selector) {
|
861 | return selector == null ? none : function() {
|
862 | return this.querySelector(selector);
|
863 | };
|
864 | }
|
865 |
|
866 | function selection_select(select) {
|
867 | if (typeof select !== "function") select = selector(select);
|
868 |
|
869 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
870 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
|
871 | if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
872 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
873 | subgroup[i] = subnode;
|
874 | }
|
875 | }
|
876 | }
|
877 |
|
878 | return new Selection(subgroups, this._parents);
|
879 | }
|
880 |
|
881 | function empty() {
|
882 | return [];
|
883 | }
|
884 |
|
885 | function selectorAll(selector) {
|
886 | return selector == null ? empty : function() {
|
887 | return this.querySelectorAll(selector);
|
888 | };
|
889 | }
|
890 |
|
891 | function selection_selectAll(select) {
|
892 | if (typeof select !== "function") select = selectorAll(select);
|
893 |
|
894 | for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
|
895 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
896 | if (node = group[i]) {
|
897 | subgroups.push(select.call(node, node.__data__, i, group));
|
898 | parents.push(node);
|
899 | }
|
900 | }
|
901 | }
|
902 |
|
903 | return new Selection(subgroups, parents);
|
904 | }
|
905 |
|
906 | function matcher(selector) {
|
907 | return function() {
|
908 | return this.matches(selector);
|
909 | };
|
910 | }
|
911 |
|
912 | function selection_filter(match) {
|
913 | if (typeof match !== "function") match = matcher(match);
|
914 |
|
915 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
916 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
|
917 | if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
918 | subgroup.push(node);
|
919 | }
|
920 | }
|
921 | }
|
922 |
|
923 | return new Selection(subgroups, this._parents);
|
924 | }
|
925 |
|
926 | function sparse(update) {
|
927 | return new Array(update.length);
|
928 | }
|
929 |
|
930 | function selection_enter() {
|
931 | return new Selection(this._enter || this._groups.map(sparse), this._parents);
|
932 | }
|
933 |
|
934 | function EnterNode(parent, datum) {
|
935 | this.ownerDocument = parent.ownerDocument;
|
936 | this.namespaceURI = parent.namespaceURI;
|
937 | this._next = null;
|
938 | this._parent = parent;
|
939 | this.__data__ = datum;
|
940 | }
|
941 |
|
942 | EnterNode.prototype = {
|
943 | constructor: EnterNode,
|
944 | appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
|
945 | insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
|
946 | querySelector: function(selector) { return this._parent.querySelector(selector); },
|
947 | querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
|
948 | };
|
949 |
|
950 | function constant$1(x) {
|
951 | return function() {
|
952 | return x;
|
953 | };
|
954 | }
|
955 |
|
956 | var keyPrefix = "$";
|
957 |
|
958 | function bindIndex(parent, group, enter, update, exit, data) {
|
959 | var i = 0,
|
960 | node,
|
961 | groupLength = group.length,
|
962 | dataLength = data.length;
|
963 |
|
964 |
|
965 |
|
966 |
|
967 | for (; i < dataLength; ++i) {
|
968 | if (node = group[i]) {
|
969 | node.__data__ = data[i];
|
970 | update[i] = node;
|
971 | } else {
|
972 | enter[i] = new EnterNode(parent, data[i]);
|
973 | }
|
974 | }
|
975 |
|
976 |
|
977 | for (; i < groupLength; ++i) {
|
978 | if (node = group[i]) {
|
979 | exit[i] = node;
|
980 | }
|
981 | }
|
982 | }
|
983 |
|
984 | function bindKey(parent, group, enter, update, exit, data, key) {
|
985 | var i,
|
986 | node,
|
987 | nodeByKeyValue = {},
|
988 | groupLength = group.length,
|
989 | dataLength = data.length,
|
990 | keyValues = new Array(groupLength),
|
991 | keyValue;
|
992 |
|
993 |
|
994 |
|
995 | for (i = 0; i < groupLength; ++i) {
|
996 | if (node = group[i]) {
|
997 | keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
|
998 | if (keyValue in nodeByKeyValue) {
|
999 | exit[i] = node;
|
1000 | } else {
|
1001 | nodeByKeyValue[keyValue] = node;
|
1002 | }
|
1003 | }
|
1004 | }
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 | for (i = 0; i < dataLength; ++i) {
|
1010 | keyValue = keyPrefix + key.call(parent, data[i], i, data);
|
1011 | if (node = nodeByKeyValue[keyValue]) {
|
1012 | update[i] = node;
|
1013 | node.__data__ = data[i];
|
1014 | nodeByKeyValue[keyValue] = null;
|
1015 | } else {
|
1016 | enter[i] = new EnterNode(parent, data[i]);
|
1017 | }
|
1018 | }
|
1019 |
|
1020 |
|
1021 | for (i = 0; i < groupLength; ++i) {
|
1022 | if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
|
1023 | exit[i] = node;
|
1024 | }
|
1025 | }
|
1026 | }
|
1027 |
|
1028 | function selection_data(value, key) {
|
1029 | if (!value) {
|
1030 | data = new Array(this.size()), j = -1;
|
1031 | this.each(function(d) { data[++j] = d; });
|
1032 | return data;
|
1033 | }
|
1034 |
|
1035 | var bind = key ? bindKey : bindIndex,
|
1036 | parents = this._parents,
|
1037 | groups = this._groups;
|
1038 |
|
1039 | if (typeof value !== "function") value = constant$1(value);
|
1040 |
|
1041 | for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
|
1042 | var parent = parents[j],
|
1043 | group = groups[j],
|
1044 | groupLength = group.length,
|
1045 | data = value.call(parent, parent && parent.__data__, j, parents),
|
1046 | dataLength = data.length,
|
1047 | enterGroup = enter[j] = new Array(dataLength),
|
1048 | updateGroup = update[j] = new Array(dataLength),
|
1049 | exitGroup = exit[j] = new Array(groupLength);
|
1050 |
|
1051 | bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 | for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
|
1057 | if (previous = enterGroup[i0]) {
|
1058 | if (i0 >= i1) i1 = i0 + 1;
|
1059 | while (!(next = updateGroup[i1]) && ++i1 < dataLength);
|
1060 | previous._next = next || null;
|
1061 | }
|
1062 | }
|
1063 | }
|
1064 |
|
1065 | update = new Selection(update, parents);
|
1066 | update._enter = enter;
|
1067 | update._exit = exit;
|
1068 | return update;
|
1069 | }
|
1070 |
|
1071 | function selection_exit() {
|
1072 | return new Selection(this._exit || this._groups.map(sparse), this._parents);
|
1073 | }
|
1074 |
|
1075 | function selection_join(onenter, onupdate, onexit) {
|
1076 | var enter = this.enter(), update = this, exit = this.exit();
|
1077 | enter = typeof onenter === "function" ? onenter(enter) : enter.append(onenter + "");
|
1078 | if (onupdate != null) update = onupdate(update);
|
1079 | if (onexit == null) exit.remove(); else onexit(exit);
|
1080 | return enter && update ? enter.merge(update).order() : update;
|
1081 | }
|
1082 |
|
1083 | function selection_merge(selection) {
|
1084 |
|
1085 | 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) {
|
1086 | for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
|
1087 | if (node = group0[i] || group1[i]) {
|
1088 | merge[i] = node;
|
1089 | }
|
1090 | }
|
1091 | }
|
1092 |
|
1093 | for (; j < m0; ++j) {
|
1094 | merges[j] = groups0[j];
|
1095 | }
|
1096 |
|
1097 | return new Selection(merges, this._parents);
|
1098 | }
|
1099 |
|
1100 | function selection_order() {
|
1101 |
|
1102 | for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
|
1103 | for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
|
1104 | if (node = group[i]) {
|
1105 | if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next);
|
1106 | next = node;
|
1107 | }
|
1108 | }
|
1109 | }
|
1110 |
|
1111 | return this;
|
1112 | }
|
1113 |
|
1114 | function selection_sort(compare) {
|
1115 | if (!compare) compare = ascending$1;
|
1116 |
|
1117 | function compareNode(a, b) {
|
1118 | return a && b ? compare(a.__data__, b.__data__) : !a - !b;
|
1119 | }
|
1120 |
|
1121 | for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
|
1122 | for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
|
1123 | if (node = group[i]) {
|
1124 | sortgroup[i] = node;
|
1125 | }
|
1126 | }
|
1127 | sortgroup.sort(compareNode);
|
1128 | }
|
1129 |
|
1130 | return new Selection(sortgroups, this._parents).order();
|
1131 | }
|
1132 |
|
1133 | function ascending$1(a, b) {
|
1134 | return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
1135 | }
|
1136 |
|
1137 | function selection_call() {
|
1138 | var callback = arguments[0];
|
1139 | arguments[0] = this;
|
1140 | callback.apply(null, arguments);
|
1141 | return this;
|
1142 | }
|
1143 |
|
1144 | function selection_nodes() {
|
1145 | var nodes = new Array(this.size()), i = -1;
|
1146 | this.each(function() { nodes[++i] = this; });
|
1147 | return nodes;
|
1148 | }
|
1149 |
|
1150 | function selection_node() {
|
1151 |
|
1152 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
1153 | for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
|
1154 | var node = group[i];
|
1155 | if (node) return node;
|
1156 | }
|
1157 | }
|
1158 |
|
1159 | return null;
|
1160 | }
|
1161 |
|
1162 | function selection_size() {
|
1163 | var size = 0;
|
1164 | this.each(function() { ++size; });
|
1165 | return size;
|
1166 | }
|
1167 |
|
1168 | function selection_empty() {
|
1169 | return !this.node();
|
1170 | }
|
1171 |
|
1172 | function selection_each(callback) {
|
1173 |
|
1174 | for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
|
1175 | for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
|
1176 | if (node = group[i]) callback.call(node, node.__data__, i, group);
|
1177 | }
|
1178 | }
|
1179 |
|
1180 | return this;
|
1181 | }
|
1182 |
|
1183 | function attrRemove(name) {
|
1184 | return function() {
|
1185 | this.removeAttribute(name);
|
1186 | };
|
1187 | }
|
1188 |
|
1189 | function attrRemoveNS(fullname) {
|
1190 | return function() {
|
1191 | this.removeAttributeNS(fullname.space, fullname.local);
|
1192 | };
|
1193 | }
|
1194 |
|
1195 | function attrConstant(name, value) {
|
1196 | return function() {
|
1197 | this.setAttribute(name, value);
|
1198 | };
|
1199 | }
|
1200 |
|
1201 | function attrConstantNS(fullname, value) {
|
1202 | return function() {
|
1203 | this.setAttributeNS(fullname.space, fullname.local, value);
|
1204 | };
|
1205 | }
|
1206 |
|
1207 | function attrFunction(name, value) {
|
1208 | return function() {
|
1209 | var v = value.apply(this, arguments);
|
1210 | if (v == null) this.removeAttribute(name);
|
1211 | else this.setAttribute(name, v);
|
1212 | };
|
1213 | }
|
1214 |
|
1215 | function attrFunctionNS(fullname, value) {
|
1216 | return function() {
|
1217 | var v = value.apply(this, arguments);
|
1218 | if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
|
1219 | else this.setAttributeNS(fullname.space, fullname.local, v);
|
1220 | };
|
1221 | }
|
1222 |
|
1223 | function selection_attr(name, value) {
|
1224 | var fullname = namespace(name);
|
1225 |
|
1226 | if (arguments.length < 2) {
|
1227 | var node = this.node();
|
1228 | return fullname.local
|
1229 | ? node.getAttributeNS(fullname.space, fullname.local)
|
1230 | : node.getAttribute(fullname);
|
1231 | }
|
1232 |
|
1233 | return this.each((value == null
|
1234 | ? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
|
1235 | ? (fullname.local ? attrFunctionNS : attrFunction)
|
1236 | : (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
|
1237 | }
|
1238 |
|
1239 | function defaultView(node) {
|
1240 | return (node.ownerDocument && node.ownerDocument.defaultView)
|
1241 | || (node.document && node)
|
1242 | || node.defaultView;
|
1243 | }
|
1244 |
|
1245 | function styleRemove(name) {
|
1246 | return function() {
|
1247 | this.style.removeProperty(name);
|
1248 | };
|
1249 | }
|
1250 |
|
1251 | function styleConstant(name, value, priority) {
|
1252 | return function() {
|
1253 | this.style.setProperty(name, value, priority);
|
1254 | };
|
1255 | }
|
1256 |
|
1257 | function styleFunction(name, value, priority) {
|
1258 | return function() {
|
1259 | var v = value.apply(this, arguments);
|
1260 | if (v == null) this.style.removeProperty(name);
|
1261 | else this.style.setProperty(name, v, priority);
|
1262 | };
|
1263 | }
|
1264 |
|
1265 | function selection_style(name, value, priority) {
|
1266 | return arguments.length > 1
|
1267 | ? this.each((value == null
|
1268 | ? styleRemove : typeof value === "function"
|
1269 | ? styleFunction
|
1270 | : styleConstant)(name, value, priority == null ? "" : priority))
|
1271 | : styleValue(this.node(), name);
|
1272 | }
|
1273 |
|
1274 | function styleValue(node, name) {
|
1275 | return node.style.getPropertyValue(name)
|
1276 | || defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
|
1277 | }
|
1278 |
|
1279 | function propertyRemove(name) {
|
1280 | return function() {
|
1281 | delete this[name];
|
1282 | };
|
1283 | }
|
1284 |
|
1285 | function propertyConstant(name, value) {
|
1286 | return function() {
|
1287 | this[name] = value;
|
1288 | };
|
1289 | }
|
1290 |
|
1291 | function propertyFunction(name, value) {
|
1292 | return function() {
|
1293 | var v = value.apply(this, arguments);
|
1294 | if (v == null) delete this[name];
|
1295 | else this[name] = v;
|
1296 | };
|
1297 | }
|
1298 |
|
1299 | function selection_property(name, value) {
|
1300 | return arguments.length > 1
|
1301 | ? this.each((value == null
|
1302 | ? propertyRemove : typeof value === "function"
|
1303 | ? propertyFunction
|
1304 | : propertyConstant)(name, value))
|
1305 | : this.node()[name];
|
1306 | }
|
1307 |
|
1308 | function classArray(string) {
|
1309 | return string.trim().split(/^|\s+/);
|
1310 | }
|
1311 |
|
1312 | function classList(node) {
|
1313 | return node.classList || new ClassList(node);
|
1314 | }
|
1315 |
|
1316 | function ClassList(node) {
|
1317 | this._node = node;
|
1318 | this._names = classArray(node.getAttribute("class") || "");
|
1319 | }
|
1320 |
|
1321 | ClassList.prototype = {
|
1322 | add: function(name) {
|
1323 | var i = this._names.indexOf(name);
|
1324 | if (i < 0) {
|
1325 | this._names.push(name);
|
1326 | this._node.setAttribute("class", this._names.join(" "));
|
1327 | }
|
1328 | },
|
1329 | remove: function(name) {
|
1330 | var i = this._names.indexOf(name);
|
1331 | if (i >= 0) {
|
1332 | this._names.splice(i, 1);
|
1333 | this._node.setAttribute("class", this._names.join(" "));
|
1334 | }
|
1335 | },
|
1336 | contains: function(name) {
|
1337 | return this._names.indexOf(name) >= 0;
|
1338 | }
|
1339 | };
|
1340 |
|
1341 | function classedAdd(node, names) {
|
1342 | var list = classList(node), i = -1, n = names.length;
|
1343 | while (++i < n) list.add(names[i]);
|
1344 | }
|
1345 |
|
1346 | function classedRemove(node, names) {
|
1347 | var list = classList(node), i = -1, n = names.length;
|
1348 | while (++i < n) list.remove(names[i]);
|
1349 | }
|
1350 |
|
1351 | function classedTrue(names) {
|
1352 | return function() {
|
1353 | classedAdd(this, names);
|
1354 | };
|
1355 | }
|
1356 |
|
1357 | function classedFalse(names) {
|
1358 | return function() {
|
1359 | classedRemove(this, names);
|
1360 | };
|
1361 | }
|
1362 |
|
1363 | function classedFunction(names, value) {
|
1364 | return function() {
|
1365 | (value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
|
1366 | };
|
1367 | }
|
1368 |
|
1369 | function selection_classed(name, value) {
|
1370 | var names = classArray(name + "");
|
1371 |
|
1372 | if (arguments.length < 2) {
|
1373 | var list = classList(this.node()), i = -1, n = names.length;
|
1374 | while (++i < n) if (!list.contains(names[i])) return false;
|
1375 | return true;
|
1376 | }
|
1377 |
|
1378 | return this.each((typeof value === "function"
|
1379 | ? classedFunction : value
|
1380 | ? classedTrue
|
1381 | : classedFalse)(names, value));
|
1382 | }
|
1383 |
|
1384 | function textRemove() {
|
1385 | this.textContent = "";
|
1386 | }
|
1387 |
|
1388 | function textConstant(value) {
|
1389 | return function() {
|
1390 | this.textContent = value;
|
1391 | };
|
1392 | }
|
1393 |
|
1394 | function textFunction(value) {
|
1395 | return function() {
|
1396 | var v = value.apply(this, arguments);
|
1397 | this.textContent = v == null ? "" : v;
|
1398 | };
|
1399 | }
|
1400 |
|
1401 | function selection_text(value) {
|
1402 | return arguments.length
|
1403 | ? this.each(value == null
|
1404 | ? textRemove : (typeof value === "function"
|
1405 | ? textFunction
|
1406 | : textConstant)(value))
|
1407 | : this.node().textContent;
|
1408 | }
|
1409 |
|
1410 | function htmlRemove() {
|
1411 | this.innerHTML = "";
|
1412 | }
|
1413 |
|
1414 | function htmlConstant(value) {
|
1415 | return function() {
|
1416 | this.innerHTML = value;
|
1417 | };
|
1418 | }
|
1419 |
|
1420 | function htmlFunction(value) {
|
1421 | return function() {
|
1422 | var v = value.apply(this, arguments);
|
1423 | this.innerHTML = v == null ? "" : v;
|
1424 | };
|
1425 | }
|
1426 |
|
1427 | function selection_html(value) {
|
1428 | return arguments.length
|
1429 | ? this.each(value == null
|
1430 | ? htmlRemove : (typeof value === "function"
|
1431 | ? htmlFunction
|
1432 | : htmlConstant)(value))
|
1433 | : this.node().innerHTML;
|
1434 | }
|
1435 |
|
1436 | function raise() {
|
1437 | if (this.nextSibling) this.parentNode.appendChild(this);
|
1438 | }
|
1439 |
|
1440 | function selection_raise() {
|
1441 | return this.each(raise);
|
1442 | }
|
1443 |
|
1444 | function lower() {
|
1445 | if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
|
1446 | }
|
1447 |
|
1448 | function selection_lower() {
|
1449 | return this.each(lower);
|
1450 | }
|
1451 |
|
1452 | function selection_append(name) {
|
1453 | var create = typeof name === "function" ? name : creator(name);
|
1454 | return this.select(function() {
|
1455 | return this.appendChild(create.apply(this, arguments));
|
1456 | });
|
1457 | }
|
1458 |
|
1459 | function constantNull() {
|
1460 | return null;
|
1461 | }
|
1462 |
|
1463 | function selection_insert(name, before) {
|
1464 | var create = typeof name === "function" ? name : creator(name),
|
1465 | select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
|
1466 | return this.select(function() {
|
1467 | return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
|
1468 | });
|
1469 | }
|
1470 |
|
1471 | function remove() {
|
1472 | var parent = this.parentNode;
|
1473 | if (parent) parent.removeChild(this);
|
1474 | }
|
1475 |
|
1476 | function selection_remove() {
|
1477 | return this.each(remove);
|
1478 | }
|
1479 |
|
1480 | function selection_cloneShallow() {
|
1481 | var clone = this.cloneNode(false), parent = this.parentNode;
|
1482 | return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
|
1483 | }
|
1484 |
|
1485 | function selection_cloneDeep() {
|
1486 | var clone = this.cloneNode(true), parent = this.parentNode;
|
1487 | return parent ? parent.insertBefore(clone, this.nextSibling) : clone;
|
1488 | }
|
1489 |
|
1490 | function selection_clone(deep) {
|
1491 | return this.select(deep ? selection_cloneDeep : selection_cloneShallow);
|
1492 | }
|
1493 |
|
1494 | function selection_datum(value) {
|
1495 | return arguments.length
|
1496 | ? this.property("__data__", value)
|
1497 | : this.node().__data__;
|
1498 | }
|
1499 |
|
1500 | var filterEvents = {};
|
1501 |
|
1502 | exports.event = null;
|
1503 |
|
1504 | if (typeof document !== "undefined") {
|
1505 | var element = document.documentElement;
|
1506 | if (!("onmouseenter" in element)) {
|
1507 | filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
|
1508 | }
|
1509 | }
|
1510 |
|
1511 | function filterContextListener(listener, index, group) {
|
1512 | listener = contextListener(listener, index, group);
|
1513 | return function(event) {
|
1514 | var related = event.relatedTarget;
|
1515 | if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
|
1516 | listener.call(this, event);
|
1517 | }
|
1518 | };
|
1519 | }
|
1520 |
|
1521 | function contextListener(listener, index, group) {
|
1522 | return function(event1) {
|
1523 | var event0 = exports.event;
|
1524 | exports.event = event1;
|
1525 | try {
|
1526 | listener.call(this, this.__data__, index, group);
|
1527 | } finally {
|
1528 | exports.event = event0;
|
1529 | }
|
1530 | };
|
1531 | }
|
1532 |
|
1533 | function parseTypenames$1(typenames) {
|
1534 | return typenames.trim().split(/^|\s+/).map(function(t) {
|
1535 | var name = "", i = t.indexOf(".");
|
1536 | if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
1537 | return {type: t, name: name};
|
1538 | });
|
1539 | }
|
1540 |
|
1541 | function onRemove(typename) {
|
1542 | return function() {
|
1543 | var on = this.__on;
|
1544 | if (!on) return;
|
1545 | for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
|
1546 | if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
|
1547 | this.removeEventListener(o.type, o.listener, o.capture);
|
1548 | } else {
|
1549 | on[++i] = o;
|
1550 | }
|
1551 | }
|
1552 | if (++i) on.length = i;
|
1553 | else delete this.__on;
|
1554 | };
|
1555 | }
|
1556 |
|
1557 | function onAdd(typename, value, capture) {
|
1558 | var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
|
1559 | return function(d, i, group) {
|
1560 | var on = this.__on, o, listener = wrap(value, i, group);
|
1561 | if (on) for (var j = 0, m = on.length; j < m; ++j) {
|
1562 | if ((o = on[j]).type === typename.type && o.name === typename.name) {
|
1563 | this.removeEventListener(o.type, o.listener, o.capture);
|
1564 | this.addEventListener(o.type, o.listener = listener, o.capture = capture);
|
1565 | o.value = value;
|
1566 | return;
|
1567 | }
|
1568 | }
|
1569 | this.addEventListener(typename.type, listener, capture);
|
1570 | o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
|
1571 | if (!on) this.__on = [o];
|
1572 | else on.push(o);
|
1573 | };
|
1574 | }
|
1575 |
|
1576 | function selection_on(typename, value, capture) {
|
1577 | var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
|
1578 |
|
1579 | if (arguments.length < 2) {
|
1580 | var on = this.node().__on;
|
1581 | if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
|
1582 | for (i = 0, o = on[j]; i < n; ++i) {
|
1583 | if ((t = typenames[i]).type === o.type && t.name === o.name) {
|
1584 | return o.value;
|
1585 | }
|
1586 | }
|
1587 | }
|
1588 | return;
|
1589 | }
|
1590 |
|
1591 | on = value ? onAdd : onRemove;
|
1592 | if (capture == null) capture = false;
|
1593 | for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
|
1594 | return this;
|
1595 | }
|
1596 |
|
1597 | function customEvent(event1, listener, that, args) {
|
1598 | var event0 = exports.event;
|
1599 | event1.sourceEvent = exports.event;
|
1600 | exports.event = event1;
|
1601 | try {
|
1602 | return listener.apply(that, args);
|
1603 | } finally {
|
1604 | exports.event = event0;
|
1605 | }
|
1606 | }
|
1607 |
|
1608 | function dispatchEvent(node, type, params) {
|
1609 | var window = defaultView(node),
|
1610 | event = window.CustomEvent;
|
1611 |
|
1612 | if (typeof event === "function") {
|
1613 | event = new event(type, params);
|
1614 | } else {
|
1615 | event = window.document.createEvent("Event");
|
1616 | if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
|
1617 | else event.initEvent(type, false, false);
|
1618 | }
|
1619 |
|
1620 | node.dispatchEvent(event);
|
1621 | }
|
1622 |
|
1623 | function dispatchConstant(type, params) {
|
1624 | return function() {
|
1625 | return dispatchEvent(this, type, params);
|
1626 | };
|
1627 | }
|
1628 |
|
1629 | function dispatchFunction(type, params) {
|
1630 | return function() {
|
1631 | return dispatchEvent(this, type, params.apply(this, arguments));
|
1632 | };
|
1633 | }
|
1634 |
|
1635 | function selection_dispatch(type, params) {
|
1636 | return this.each((typeof params === "function"
|
1637 | ? dispatchFunction
|
1638 | : dispatchConstant)(type, params));
|
1639 | }
|
1640 |
|
1641 | var root = [null];
|
1642 |
|
1643 | function Selection(groups, parents) {
|
1644 | this._groups = groups;
|
1645 | this._parents = parents;
|
1646 | }
|
1647 |
|
1648 | function selection() {
|
1649 | return new Selection([[document.documentElement]], root);
|
1650 | }
|
1651 |
|
1652 | Selection.prototype = selection.prototype = {
|
1653 | constructor: Selection,
|
1654 | select: selection_select,
|
1655 | selectAll: selection_selectAll,
|
1656 | filter: selection_filter,
|
1657 | data: selection_data,
|
1658 | enter: selection_enter,
|
1659 | exit: selection_exit,
|
1660 | join: selection_join,
|
1661 | merge: selection_merge,
|
1662 | order: selection_order,
|
1663 | sort: selection_sort,
|
1664 | call: selection_call,
|
1665 | nodes: selection_nodes,
|
1666 | node: selection_node,
|
1667 | size: selection_size,
|
1668 | empty: selection_empty,
|
1669 | each: selection_each,
|
1670 | attr: selection_attr,
|
1671 | style: selection_style,
|
1672 | property: selection_property,
|
1673 | classed: selection_classed,
|
1674 | text: selection_text,
|
1675 | html: selection_html,
|
1676 | raise: selection_raise,
|
1677 | lower: selection_lower,
|
1678 | append: selection_append,
|
1679 | insert: selection_insert,
|
1680 | remove: selection_remove,
|
1681 | clone: selection_clone,
|
1682 | datum: selection_datum,
|
1683 | on: selection_on,
|
1684 | dispatch: selection_dispatch
|
1685 | };
|
1686 |
|
1687 | function select(selector) {
|
1688 | return typeof selector === "string"
|
1689 | ? new Selection([[document.querySelector(selector)]], [document.documentElement])
|
1690 | : new Selection([[selector]], root);
|
1691 | }
|
1692 |
|
1693 | function create(name) {
|
1694 | return select(creator(name).call(document.documentElement));
|
1695 | }
|
1696 |
|
1697 | var nextId = 0;
|
1698 |
|
1699 | function local() {
|
1700 | return new Local;
|
1701 | }
|
1702 |
|
1703 | function Local() {
|
1704 | this._ = "@" + (++nextId).toString(36);
|
1705 | }
|
1706 |
|
1707 | Local.prototype = local.prototype = {
|
1708 | constructor: Local,
|
1709 | get: function(node) {
|
1710 | var id = this._;
|
1711 | while (!(id in node)) if (!(node = node.parentNode)) return;
|
1712 | return node[id];
|
1713 | },
|
1714 | set: function(node, value) {
|
1715 | return node[this._] = value;
|
1716 | },
|
1717 | remove: function(node) {
|
1718 | return this._ in node && delete node[this._];
|
1719 | },
|
1720 | toString: function() {
|
1721 | return this._;
|
1722 | }
|
1723 | };
|
1724 |
|
1725 | function sourceEvent() {
|
1726 | var current = exports.event, source;
|
1727 | while (source = current.sourceEvent) current = source;
|
1728 | return current;
|
1729 | }
|
1730 |
|
1731 | function point(node, event) {
|
1732 | var svg = node.ownerSVGElement || node;
|
1733 |
|
1734 | if (svg.createSVGPoint) {
|
1735 | var point = svg.createSVGPoint();
|
1736 | point.x = event.clientX, point.y = event.clientY;
|
1737 | point = point.matrixTransform(node.getScreenCTM().inverse());
|
1738 | return [point.x, point.y];
|
1739 | }
|
1740 |
|
1741 | var rect = node.getBoundingClientRect();
|
1742 | return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
|
1743 | }
|
1744 |
|
1745 | function mouse(node) {
|
1746 | var event = sourceEvent();
|
1747 | if (event.changedTouches) event = event.changedTouches[0];
|
1748 | return point(node, event);
|
1749 | }
|
1750 |
|
1751 | function selectAll(selector) {
|
1752 | return typeof selector === "string"
|
1753 | ? new Selection([document.querySelectorAll(selector)], [document.documentElement])
|
1754 | : new Selection([selector == null ? [] : selector], root);
|
1755 | }
|
1756 |
|
1757 | function touch(node, touches, identifier) {
|
1758 | if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
|
1759 |
|
1760 | for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
|
1761 | if ((touch = touches[i]).identifier === identifier) {
|
1762 | return point(node, touch);
|
1763 | }
|
1764 | }
|
1765 |
|
1766 | return null;
|
1767 | }
|
1768 |
|
1769 | function touches(node, touches) {
|
1770 | if (touches == null) touches = sourceEvent().touches;
|
1771 |
|
1772 | for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
|
1773 | points[i] = point(node, touches[i]);
|
1774 | }
|
1775 |
|
1776 | return points;
|
1777 | }
|
1778 |
|
1779 | function nopropagation() {
|
1780 | exports.event.stopImmediatePropagation();
|
1781 | }
|
1782 |
|
1783 | function noevent() {
|
1784 | exports.event.preventDefault();
|
1785 | exports.event.stopImmediatePropagation();
|
1786 | }
|
1787 |
|
1788 | function dragDisable(view) {
|
1789 | var root = view.document.documentElement,
|
1790 | selection = select(view).on("dragstart.drag", noevent, true);
|
1791 | if ("onselectstart" in root) {
|
1792 | selection.on("selectstart.drag", noevent, true);
|
1793 | } else {
|
1794 | root.__noselect = root.style.MozUserSelect;
|
1795 | root.style.MozUserSelect = "none";
|
1796 | }
|
1797 | }
|
1798 |
|
1799 | function yesdrag(view, noclick) {
|
1800 | var root = view.document.documentElement,
|
1801 | selection = select(view).on("dragstart.drag", null);
|
1802 | if (noclick) {
|
1803 | selection.on("click.drag", noevent, true);
|
1804 | setTimeout(function() { selection.on("click.drag", null); }, 0);
|
1805 | }
|
1806 | if ("onselectstart" in root) {
|
1807 | selection.on("selectstart.drag", null);
|
1808 | } else {
|
1809 | root.style.MozUserSelect = root.__noselect;
|
1810 | delete root.__noselect;
|
1811 | }
|
1812 | }
|
1813 |
|
1814 | function constant$2(x) {
|
1815 | return function() {
|
1816 | return x;
|
1817 | };
|
1818 | }
|
1819 |
|
1820 | function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
|
1821 | this.target = target;
|
1822 | this.type = type;
|
1823 | this.subject = subject;
|
1824 | this.identifier = id;
|
1825 | this.active = active;
|
1826 | this.x = x;
|
1827 | this.y = y;
|
1828 | this.dx = dx;
|
1829 | this.dy = dy;
|
1830 | this._ = dispatch;
|
1831 | }
|
1832 |
|
1833 | DragEvent.prototype.on = function() {
|
1834 | var value = this._.on.apply(this._, arguments);
|
1835 | return value === this._ ? this : value;
|
1836 | };
|
1837 |
|
1838 |
|
1839 | function defaultFilter() {
|
1840 | return !exports.event.ctrlKey && !exports.event.button;
|
1841 | }
|
1842 |
|
1843 | function defaultContainer() {
|
1844 | return this.parentNode;
|
1845 | }
|
1846 |
|
1847 | function defaultSubject(d) {
|
1848 | return d == null ? {x: exports.event.x, y: exports.event.y} : d;
|
1849 | }
|
1850 |
|
1851 | function defaultTouchable() {
|
1852 | return navigator.maxTouchPoints || ("ontouchstart" in this);
|
1853 | }
|
1854 |
|
1855 | function drag() {
|
1856 | var filter = defaultFilter,
|
1857 | container = defaultContainer,
|
1858 | subject = defaultSubject,
|
1859 | touchable = defaultTouchable,
|
1860 | gestures = {},
|
1861 | listeners = dispatch("start", "drag", "end"),
|
1862 | active = 0,
|
1863 | mousedownx,
|
1864 | mousedowny,
|
1865 | mousemoving,
|
1866 | touchending,
|
1867 | clickDistance2 = 0;
|
1868 |
|
1869 | function drag(selection) {
|
1870 | selection
|
1871 | .on("mousedown.drag", mousedowned)
|
1872 | .filter(touchable)
|
1873 | .on("touchstart.drag", touchstarted)
|
1874 | .on("touchmove.drag", touchmoved)
|
1875 | .on("touchend.drag touchcancel.drag", touchended)
|
1876 | .style("touch-action", "none")
|
1877 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
1878 | }
|
1879 |
|
1880 | function mousedowned() {
|
1881 | if (touchending || !filter.apply(this, arguments)) return;
|
1882 | var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
|
1883 | if (!gesture) return;
|
1884 | select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
|
1885 | dragDisable(exports.event.view);
|
1886 | nopropagation();
|
1887 | mousemoving = false;
|
1888 | mousedownx = exports.event.clientX;
|
1889 | mousedowny = exports.event.clientY;
|
1890 | gesture("start");
|
1891 | }
|
1892 |
|
1893 | function mousemoved() {
|
1894 | noevent();
|
1895 | if (!mousemoving) {
|
1896 | var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
|
1897 | mousemoving = dx * dx + dy * dy > clickDistance2;
|
1898 | }
|
1899 | gestures.mouse("drag");
|
1900 | }
|
1901 |
|
1902 | function mouseupped() {
|
1903 | select(exports.event.view).on("mousemove.drag mouseup.drag", null);
|
1904 | yesdrag(exports.event.view, mousemoving);
|
1905 | noevent();
|
1906 | gestures.mouse("end");
|
1907 | }
|
1908 |
|
1909 | function touchstarted() {
|
1910 | if (!filter.apply(this, arguments)) return;
|
1911 | var touches = exports.event.changedTouches,
|
1912 | c = container.apply(this, arguments),
|
1913 | n = touches.length, i, gesture;
|
1914 |
|
1915 | for (i = 0; i < n; ++i) {
|
1916 | if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
|
1917 | nopropagation();
|
1918 | gesture("start");
|
1919 | }
|
1920 | }
|
1921 | }
|
1922 |
|
1923 | function touchmoved() {
|
1924 | var touches = exports.event.changedTouches,
|
1925 | n = touches.length, i, gesture;
|
1926 |
|
1927 | for (i = 0; i < n; ++i) {
|
1928 | if (gesture = gestures[touches[i].identifier]) {
|
1929 | noevent();
|
1930 | gesture("drag");
|
1931 | }
|
1932 | }
|
1933 | }
|
1934 |
|
1935 | function touchended() {
|
1936 | var touches = exports.event.changedTouches,
|
1937 | n = touches.length, i, gesture;
|
1938 |
|
1939 | if (touchending) clearTimeout(touchending);
|
1940 | touchending = setTimeout(function() { touchending = null; }, 500);
|
1941 | for (i = 0; i < n; ++i) {
|
1942 | if (gesture = gestures[touches[i].identifier]) {
|
1943 | nopropagation();
|
1944 | gesture("end");
|
1945 | }
|
1946 | }
|
1947 | }
|
1948 |
|
1949 | function beforestart(id, container, point, that, args) {
|
1950 | var p = point(container, id), s, dx, dy,
|
1951 | sublisteners = listeners.copy();
|
1952 |
|
1953 | if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
|
1954 | if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
|
1955 | dx = s.x - p[0] || 0;
|
1956 | dy = s.y - p[1] || 0;
|
1957 | return true;
|
1958 | })) return;
|
1959 |
|
1960 | return function gesture(type) {
|
1961 | var p0 = p, n;
|
1962 | switch (type) {
|
1963 | case "start": gestures[id] = gesture, n = active++; break;
|
1964 | case "end": delete gestures[id], --active;
|
1965 | case "drag": p = point(container, id), n = active; break;
|
1966 | }
|
1967 | customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
|
1968 | };
|
1969 | }
|
1970 |
|
1971 | drag.filter = function(_) {
|
1972 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
|
1973 | };
|
1974 |
|
1975 | drag.container = function(_) {
|
1976 | return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
|
1977 | };
|
1978 |
|
1979 | drag.subject = function(_) {
|
1980 | return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
|
1981 | };
|
1982 |
|
1983 | drag.touchable = function(_) {
|
1984 | return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
|
1985 | };
|
1986 |
|
1987 | drag.on = function() {
|
1988 | var value = listeners.on.apply(listeners, arguments);
|
1989 | return value === listeners ? drag : value;
|
1990 | };
|
1991 |
|
1992 | drag.clickDistance = function(_) {
|
1993 | return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
|
1994 | };
|
1995 |
|
1996 | return drag;
|
1997 | }
|
1998 |
|
1999 | function define(constructor, factory, prototype) {
|
2000 | constructor.prototype = factory.prototype = prototype;
|
2001 | prototype.constructor = constructor;
|
2002 | }
|
2003 |
|
2004 | function extend(parent, definition) {
|
2005 | var prototype = Object.create(parent.prototype);
|
2006 | for (var key in definition) prototype[key] = definition[key];
|
2007 | return prototype;
|
2008 | }
|
2009 |
|
2010 | function Color() {}
|
2011 |
|
2012 | var darker = 0.7;
|
2013 | var brighter = 1 / darker;
|
2014 |
|
2015 | var reI = "\\s*([+-]?\\d+)\\s*",
|
2016 | reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
|
2017 | reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
|
2018 | reHex = /^#([0-9a-f]{3,8})$/,
|
2019 | reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
|
2020 | reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
|
2021 | reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
|
2022 | reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
|
2023 | reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
|
2024 | reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
|
2025 |
|
2026 | var named = {
|
2027 | aliceblue: 0xf0f8ff,
|
2028 | antiquewhite: 0xfaebd7,
|
2029 | aqua: 0x00ffff,
|
2030 | aquamarine: 0x7fffd4,
|
2031 | azure: 0xf0ffff,
|
2032 | beige: 0xf5f5dc,
|
2033 | bisque: 0xffe4c4,
|
2034 | black: 0x000000,
|
2035 | blanchedalmond: 0xffebcd,
|
2036 | blue: 0x0000ff,
|
2037 | blueviolet: 0x8a2be2,
|
2038 | brown: 0xa52a2a,
|
2039 | burlywood: 0xdeb887,
|
2040 | cadetblue: 0x5f9ea0,
|
2041 | chartreuse: 0x7fff00,
|
2042 | chocolate: 0xd2691e,
|
2043 | coral: 0xff7f50,
|
2044 | cornflowerblue: 0x6495ed,
|
2045 | cornsilk: 0xfff8dc,
|
2046 | crimson: 0xdc143c,
|
2047 | cyan: 0x00ffff,
|
2048 | darkblue: 0x00008b,
|
2049 | darkcyan: 0x008b8b,
|
2050 | darkgoldenrod: 0xb8860b,
|
2051 | darkgray: 0xa9a9a9,
|
2052 | darkgreen: 0x006400,
|
2053 | darkgrey: 0xa9a9a9,
|
2054 | darkkhaki: 0xbdb76b,
|
2055 | darkmagenta: 0x8b008b,
|
2056 | darkolivegreen: 0x556b2f,
|
2057 | darkorange: 0xff8c00,
|
2058 | darkorchid: 0x9932cc,
|
2059 | darkred: 0x8b0000,
|
2060 | darksalmon: 0xe9967a,
|
2061 | darkseagreen: 0x8fbc8f,
|
2062 | darkslateblue: 0x483d8b,
|
2063 | darkslategray: 0x2f4f4f,
|
2064 | darkslategrey: 0x2f4f4f,
|
2065 | darkturquoise: 0x00ced1,
|
2066 | darkviolet: 0x9400d3,
|
2067 | deeppink: 0xff1493,
|
2068 | deepskyblue: 0x00bfff,
|
2069 | dimgray: 0x696969,
|
2070 | dimgrey: 0x696969,
|
2071 | dodgerblue: 0x1e90ff,
|
2072 | firebrick: 0xb22222,
|
2073 | floralwhite: 0xfffaf0,
|
2074 | forestgreen: 0x228b22,
|
2075 | fuchsia: 0xff00ff,
|
2076 | gainsboro: 0xdcdcdc,
|
2077 | ghostwhite: 0xf8f8ff,
|
2078 | gold: 0xffd700,
|
2079 | goldenrod: 0xdaa520,
|
2080 | gray: 0x808080,
|
2081 | green: 0x008000,
|
2082 | greenyellow: 0xadff2f,
|
2083 | grey: 0x808080,
|
2084 | honeydew: 0xf0fff0,
|
2085 | hotpink: 0xff69b4,
|
2086 | indianred: 0xcd5c5c,
|
2087 | indigo: 0x4b0082,
|
2088 | ivory: 0xfffff0,
|
2089 | khaki: 0xf0e68c,
|
2090 | lavender: 0xe6e6fa,
|
2091 | lavenderblush: 0xfff0f5,
|
2092 | lawngreen: 0x7cfc00,
|
2093 | lemonchiffon: 0xfffacd,
|
2094 | lightblue: 0xadd8e6,
|
2095 | lightcoral: 0xf08080,
|
2096 | lightcyan: 0xe0ffff,
|
2097 | lightgoldenrodyellow: 0xfafad2,
|
2098 | lightgray: 0xd3d3d3,
|
2099 | lightgreen: 0x90ee90,
|
2100 | lightgrey: 0xd3d3d3,
|
2101 | lightpink: 0xffb6c1,
|
2102 | lightsalmon: 0xffa07a,
|
2103 | lightseagreen: 0x20b2aa,
|
2104 | lightskyblue: 0x87cefa,
|
2105 | lightslategray: 0x778899,
|
2106 | lightslategrey: 0x778899,
|
2107 | lightsteelblue: 0xb0c4de,
|
2108 | lightyellow: 0xffffe0,
|
2109 | lime: 0x00ff00,
|
2110 | limegreen: 0x32cd32,
|
2111 | linen: 0xfaf0e6,
|
2112 | magenta: 0xff00ff,
|
2113 | maroon: 0x800000,
|
2114 | mediumaquamarine: 0x66cdaa,
|
2115 | mediumblue: 0x0000cd,
|
2116 | mediumorchid: 0xba55d3,
|
2117 | mediumpurple: 0x9370db,
|
2118 | mediumseagreen: 0x3cb371,
|
2119 | mediumslateblue: 0x7b68ee,
|
2120 | mediumspringgreen: 0x00fa9a,
|
2121 | mediumturquoise: 0x48d1cc,
|
2122 | mediumvioletred: 0xc71585,
|
2123 | midnightblue: 0x191970,
|
2124 | mintcream: 0xf5fffa,
|
2125 | mistyrose: 0xffe4e1,
|
2126 | moccasin: 0xffe4b5,
|
2127 | navajowhite: 0xffdead,
|
2128 | navy: 0x000080,
|
2129 | oldlace: 0xfdf5e6,
|
2130 | olive: 0x808000,
|
2131 | olivedrab: 0x6b8e23,
|
2132 | orange: 0xffa500,
|
2133 | orangered: 0xff4500,
|
2134 | orchid: 0xda70d6,
|
2135 | palegoldenrod: 0xeee8aa,
|
2136 | palegreen: 0x98fb98,
|
2137 | paleturquoise: 0xafeeee,
|
2138 | palevioletred: 0xdb7093,
|
2139 | papayawhip: 0xffefd5,
|
2140 | peachpuff: 0xffdab9,
|
2141 | peru: 0xcd853f,
|
2142 | pink: 0xffc0cb,
|
2143 | plum: 0xdda0dd,
|
2144 | powderblue: 0xb0e0e6,
|
2145 | purple: 0x800080,
|
2146 | rebeccapurple: 0x663399,
|
2147 | red: 0xff0000,
|
2148 | rosybrown: 0xbc8f8f,
|
2149 | royalblue: 0x4169e1,
|
2150 | saddlebrown: 0x8b4513,
|
2151 | salmon: 0xfa8072,
|
2152 | sandybrown: 0xf4a460,
|
2153 | seagreen: 0x2e8b57,
|
2154 | seashell: 0xfff5ee,
|
2155 | sienna: 0xa0522d,
|
2156 | silver: 0xc0c0c0,
|
2157 | skyblue: 0x87ceeb,
|
2158 | slateblue: 0x6a5acd,
|
2159 | slategray: 0x708090,
|
2160 | slategrey: 0x708090,
|
2161 | snow: 0xfffafa,
|
2162 | springgreen: 0x00ff7f,
|
2163 | steelblue: 0x4682b4,
|
2164 | tan: 0xd2b48c,
|
2165 | teal: 0x008080,
|
2166 | thistle: 0xd8bfd8,
|
2167 | tomato: 0xff6347,
|
2168 | turquoise: 0x40e0d0,
|
2169 | violet: 0xee82ee,
|
2170 | wheat: 0xf5deb3,
|
2171 | white: 0xffffff,
|
2172 | whitesmoke: 0xf5f5f5,
|
2173 | yellow: 0xffff00,
|
2174 | yellowgreen: 0x9acd32
|
2175 | };
|
2176 |
|
2177 | define(Color, color, {
|
2178 | copy: function(channels) {
|
2179 | return Object.assign(new this.constructor, this, channels);
|
2180 | },
|
2181 | displayable: function() {
|
2182 | return this.rgb().displayable();
|
2183 | },
|
2184 | hex: color_formatHex,
|
2185 | formatHex: color_formatHex,
|
2186 | formatHsl: color_formatHsl,
|
2187 | formatRgb: color_formatRgb,
|
2188 | toString: color_formatRgb
|
2189 | });
|
2190 |
|
2191 | function color_formatHex() {
|
2192 | return this.rgb().formatHex();
|
2193 | }
|
2194 |
|
2195 | function color_formatHsl() {
|
2196 | return hslConvert(this).formatHsl();
|
2197 | }
|
2198 |
|
2199 | function color_formatRgb() {
|
2200 | return this.rgb().formatRgb();
|
2201 | }
|
2202 |
|
2203 | function color(format) {
|
2204 | var m, l;
|
2205 | format = (format + "").trim().toLowerCase();
|
2206 | return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m)
|
2207 | : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)
|
2208 | : l === 8 ? new Rgb(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff)
|
2209 | : l === 4 ? new Rgb((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff)
|
2210 | : null)
|
2211 | : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1)
|
2212 | : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1)
|
2213 | : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4])
|
2214 | : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4])
|
2215 | : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1)
|
2216 | : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4])
|
2217 | : named.hasOwnProperty(format) ? rgbn(named[format])
|
2218 | : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
|
2219 | : null;
|
2220 | }
|
2221 |
|
2222 | function rgbn(n) {
|
2223 | return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
|
2224 | }
|
2225 |
|
2226 | function rgba(r, g, b, a) {
|
2227 | if (a <= 0) r = g = b = NaN;
|
2228 | return new Rgb(r, g, b, a);
|
2229 | }
|
2230 |
|
2231 | function rgbConvert(o) {
|
2232 | if (!(o instanceof Color)) o = color(o);
|
2233 | if (!o) return new Rgb;
|
2234 | o = o.rgb();
|
2235 | return new Rgb(o.r, o.g, o.b, o.opacity);
|
2236 | }
|
2237 |
|
2238 | function rgb(r, g, b, opacity) {
|
2239 | return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
|
2240 | }
|
2241 |
|
2242 | function Rgb(r, g, b, opacity) {
|
2243 | this.r = +r;
|
2244 | this.g = +g;
|
2245 | this.b = +b;
|
2246 | this.opacity = +opacity;
|
2247 | }
|
2248 |
|
2249 | define(Rgb, rgb, extend(Color, {
|
2250 | brighter: function(k) {
|
2251 | k = k == null ? brighter : Math.pow(brighter, k);
|
2252 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
2253 | },
|
2254 | darker: function(k) {
|
2255 | k = k == null ? darker : Math.pow(darker, k);
|
2256 | return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
|
2257 | },
|
2258 | rgb: function() {
|
2259 | return this;
|
2260 | },
|
2261 | displayable: function() {
|
2262 | return (-0.5 <= this.r && this.r < 255.5)
|
2263 | && (-0.5 <= this.g && this.g < 255.5)
|
2264 | && (-0.5 <= this.b && this.b < 255.5)
|
2265 | && (0 <= this.opacity && this.opacity <= 1);
|
2266 | },
|
2267 | hex: rgb_formatHex,
|
2268 | formatHex: rgb_formatHex,
|
2269 | formatRgb: rgb_formatRgb,
|
2270 | toString: rgb_formatRgb
|
2271 | }));
|
2272 |
|
2273 | function rgb_formatHex() {
|
2274 | return "#" + hex(this.r) + hex(this.g) + hex(this.b);
|
2275 | }
|
2276 |
|
2277 | function rgb_formatRgb() {
|
2278 | var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
|
2279 | return (a === 1 ? "rgb(" : "rgba(")
|
2280 | + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
|
2281 | + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
|
2282 | + Math.max(0, Math.min(255, Math.round(this.b) || 0))
|
2283 | + (a === 1 ? ")" : ", " + a + ")");
|
2284 | }
|
2285 |
|
2286 | function hex(value) {
|
2287 | value = Math.max(0, Math.min(255, Math.round(value) || 0));
|
2288 | return (value < 16 ? "0" : "") + value.toString(16);
|
2289 | }
|
2290 |
|
2291 | function hsla(h, s, l, a) {
|
2292 | if (a <= 0) h = s = l = NaN;
|
2293 | else if (l <= 0 || l >= 1) h = s = NaN;
|
2294 | else if (s <= 0) h = NaN;
|
2295 | return new Hsl(h, s, l, a);
|
2296 | }
|
2297 |
|
2298 | function hslConvert(o) {
|
2299 | if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
|
2300 | if (!(o instanceof Color)) o = color(o);
|
2301 | if (!o) return new Hsl;
|
2302 | if (o instanceof Hsl) return o;
|
2303 | o = o.rgb();
|
2304 | var r = o.r / 255,
|
2305 | g = o.g / 255,
|
2306 | b = o.b / 255,
|
2307 | min = Math.min(r, g, b),
|
2308 | max = Math.max(r, g, b),
|
2309 | h = NaN,
|
2310 | s = max - min,
|
2311 | l = (max + min) / 2;
|
2312 | if (s) {
|
2313 | if (r === max) h = (g - b) / s + (g < b) * 6;
|
2314 | else if (g === max) h = (b - r) / s + 2;
|
2315 | else h = (r - g) / s + 4;
|
2316 | s /= l < 0.5 ? max + min : 2 - max - min;
|
2317 | h *= 60;
|
2318 | } else {
|
2319 | s = l > 0 && l < 1 ? 0 : h;
|
2320 | }
|
2321 | return new Hsl(h, s, l, o.opacity);
|
2322 | }
|
2323 |
|
2324 | function hsl(h, s, l, opacity) {
|
2325 | return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
|
2326 | }
|
2327 |
|
2328 | function Hsl(h, s, l, opacity) {
|
2329 | this.h = +h;
|
2330 | this.s = +s;
|
2331 | this.l = +l;
|
2332 | this.opacity = +opacity;
|
2333 | }
|
2334 |
|
2335 | define(Hsl, hsl, extend(Color, {
|
2336 | brighter: function(k) {
|
2337 | k = k == null ? brighter : Math.pow(brighter, k);
|
2338 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
2339 | },
|
2340 | darker: function(k) {
|
2341 | k = k == null ? darker : Math.pow(darker, k);
|
2342 | return new Hsl(this.h, this.s, this.l * k, this.opacity);
|
2343 | },
|
2344 | rgb: function() {
|
2345 | var h = this.h % 360 + (this.h < 0) * 360,
|
2346 | s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
|
2347 | l = this.l,
|
2348 | m2 = l + (l < 0.5 ? l : 1 - l) * s,
|
2349 | m1 = 2 * l - m2;
|
2350 | return new Rgb(
|
2351 | hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
|
2352 | hsl2rgb(h, m1, m2),
|
2353 | hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
|
2354 | this.opacity
|
2355 | );
|
2356 | },
|
2357 | displayable: function() {
|
2358 | return (0 <= this.s && this.s <= 1 || isNaN(this.s))
|
2359 | && (0 <= this.l && this.l <= 1)
|
2360 | && (0 <= this.opacity && this.opacity <= 1);
|
2361 | },
|
2362 | formatHsl: function() {
|
2363 | var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
|
2364 | return (a === 1 ? "hsl(" : "hsla(")
|
2365 | + (this.h || 0) + ", "
|
2366 | + (this.s || 0) * 100 + "%, "
|
2367 | + (this.l || 0) * 100 + "%"
|
2368 | + (a === 1 ? ")" : ", " + a + ")");
|
2369 | }
|
2370 | }));
|
2371 |
|
2372 |
|
2373 | function hsl2rgb(h, m1, m2) {
|
2374 | return (h < 60 ? m1 + (m2 - m1) * h / 60
|
2375 | : h < 180 ? m2
|
2376 | : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
|
2377 | : m1) * 255;
|
2378 | }
|
2379 |
|
2380 | var deg2rad = Math.PI / 180;
|
2381 | var rad2deg = 180 / Math.PI;
|
2382 |
|
2383 |
|
2384 | var K = 18,
|
2385 | Xn = 0.96422,
|
2386 | Yn = 1,
|
2387 | Zn = 0.82521,
|
2388 | t0 = 4 / 29,
|
2389 | t1 = 6 / 29,
|
2390 | t2 = 3 * t1 * t1,
|
2391 | t3 = t1 * t1 * t1;
|
2392 |
|
2393 | function labConvert(o) {
|
2394 | if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
|
2395 | if (o instanceof Hcl) return hcl2lab(o);
|
2396 | if (!(o instanceof Rgb)) o = rgbConvert(o);
|
2397 | var r = rgb2lrgb(o.r),
|
2398 | g = rgb2lrgb(o.g),
|
2399 | b = rgb2lrgb(o.b),
|
2400 | y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
|
2401 | if (r === g && g === b) x = z = y; else {
|
2402 | x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
|
2403 | z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
|
2404 | }
|
2405 | return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
|
2406 | }
|
2407 |
|
2408 | function gray(l, opacity) {
|
2409 | return new Lab(l, 0, 0, opacity == null ? 1 : opacity);
|
2410 | }
|
2411 |
|
2412 | function lab(l, a, b, opacity) {
|
2413 | return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
|
2414 | }
|
2415 |
|
2416 | function Lab(l, a, b, opacity) {
|
2417 | this.l = +l;
|
2418 | this.a = +a;
|
2419 | this.b = +b;
|
2420 | this.opacity = +opacity;
|
2421 | }
|
2422 |
|
2423 | define(Lab, lab, extend(Color, {
|
2424 | brighter: function(k) {
|
2425 | return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
|
2426 | },
|
2427 | darker: function(k) {
|
2428 | return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
|
2429 | },
|
2430 | rgb: function() {
|
2431 | var y = (this.l + 16) / 116,
|
2432 | x = isNaN(this.a) ? y : y + this.a / 500,
|
2433 | z = isNaN(this.b) ? y : y - this.b / 200;
|
2434 | x = Xn * lab2xyz(x);
|
2435 | y = Yn * lab2xyz(y);
|
2436 | z = Zn * lab2xyz(z);
|
2437 | return new Rgb(
|
2438 | lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
|
2439 | lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
|
2440 | lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
|
2441 | this.opacity
|
2442 | );
|
2443 | }
|
2444 | }));
|
2445 |
|
2446 | function xyz2lab(t) {
|
2447 | return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
|
2448 | }
|
2449 |
|
2450 | function lab2xyz(t) {
|
2451 | return t > t1 ? t * t * t : t2 * (t - t0);
|
2452 | }
|
2453 |
|
2454 | function lrgb2rgb(x) {
|
2455 | return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
|
2456 | }
|
2457 |
|
2458 | function rgb2lrgb(x) {
|
2459 | return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
|
2460 | }
|
2461 |
|
2462 | function hclConvert(o) {
|
2463 | if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
|
2464 | if (!(o instanceof Lab)) o = labConvert(o);
|
2465 | if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity);
|
2466 | var h = Math.atan2(o.b, o.a) * rad2deg;
|
2467 | return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
|
2468 | }
|
2469 |
|
2470 | function lch(l, c, h, opacity) {
|
2471 | return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
|
2472 | }
|
2473 |
|
2474 | function hcl(h, c, l, opacity) {
|
2475 | return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
|
2476 | }
|
2477 |
|
2478 | function Hcl(h, c, l, opacity) {
|
2479 | this.h = +h;
|
2480 | this.c = +c;
|
2481 | this.l = +l;
|
2482 | this.opacity = +opacity;
|
2483 | }
|
2484 |
|
2485 | function hcl2lab(o) {
|
2486 | if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
|
2487 | var h = o.h * deg2rad;
|
2488 | return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
|
2489 | }
|
2490 |
|
2491 | define(Hcl, hcl, extend(Color, {
|
2492 | brighter: function(k) {
|
2493 | return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
|
2494 | },
|
2495 | darker: function(k) {
|
2496 | return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
|
2497 | },
|
2498 | rgb: function() {
|
2499 | return hcl2lab(this).rgb();
|
2500 | }
|
2501 | }));
|
2502 |
|
2503 | var A = -0.14861,
|
2504 | B = +1.78277,
|
2505 | C = -0.29227,
|
2506 | D = -0.90649,
|
2507 | E = +1.97294,
|
2508 | ED = E * D,
|
2509 | EB = E * B,
|
2510 | BC_DA = B * C - D * A;
|
2511 |
|
2512 | function cubehelixConvert(o) {
|
2513 | if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
|
2514 | if (!(o instanceof Rgb)) o = rgbConvert(o);
|
2515 | var r = o.r / 255,
|
2516 | g = o.g / 255,
|
2517 | b = o.b / 255,
|
2518 | l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
|
2519 | bl = b - l,
|
2520 | k = (E * (g - l) - C * bl) / D,
|
2521 | s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)),
|
2522 | h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
|
2523 | return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
|
2524 | }
|
2525 |
|
2526 | function cubehelix(h, s, l, opacity) {
|
2527 | return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
|
2528 | }
|
2529 |
|
2530 | function Cubehelix(h, s, l, opacity) {
|
2531 | this.h = +h;
|
2532 | this.s = +s;
|
2533 | this.l = +l;
|
2534 | this.opacity = +opacity;
|
2535 | }
|
2536 |
|
2537 | define(Cubehelix, cubehelix, extend(Color, {
|
2538 | brighter: function(k) {
|
2539 | k = k == null ? brighter : Math.pow(brighter, k);
|
2540 | return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
|
2541 | },
|
2542 | darker: function(k) {
|
2543 | k = k == null ? darker : Math.pow(darker, k);
|
2544 | return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
|
2545 | },
|
2546 | rgb: function() {
|
2547 | var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
|
2548 | l = +this.l,
|
2549 | a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
|
2550 | cosh = Math.cos(h),
|
2551 | sinh = Math.sin(h);
|
2552 | return new Rgb(
|
2553 | 255 * (l + a * (A * cosh + B * sinh)),
|
2554 | 255 * (l + a * (C * cosh + D * sinh)),
|
2555 | 255 * (l + a * (E * cosh)),
|
2556 | this.opacity
|
2557 | );
|
2558 | }
|
2559 | }));
|
2560 |
|
2561 | function basis(t1, v0, v1, v2, v3) {
|
2562 | var t2 = t1 * t1, t3 = t2 * t1;
|
2563 | return ((1 - 3 * t1 + 3 * t2 - t3) * v0
|
2564 | + (4 - 6 * t2 + 3 * t3) * v1
|
2565 | + (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2
|
2566 | + t3 * v3) / 6;
|
2567 | }
|
2568 |
|
2569 | function basis$1(values) {
|
2570 | var n = values.length - 1;
|
2571 | return function(t) {
|
2572 | var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n),
|
2573 | v1 = values[i],
|
2574 | v2 = values[i + 1],
|
2575 | v0 = i > 0 ? values[i - 1] : 2 * v1 - v2,
|
2576 | v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1;
|
2577 | return basis((t - i / n) * n, v0, v1, v2, v3);
|
2578 | };
|
2579 | }
|
2580 |
|
2581 | function basisClosed(values) {
|
2582 | var n = values.length;
|
2583 | return function(t) {
|
2584 | var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n),
|
2585 | v0 = values[(i + n - 1) % n],
|
2586 | v1 = values[i % n],
|
2587 | v2 = values[(i + 1) % n],
|
2588 | v3 = values[(i + 2) % n];
|
2589 | return basis((t - i / n) * n, v0, v1, v2, v3);
|
2590 | };
|
2591 | }
|
2592 |
|
2593 | function constant$3(x) {
|
2594 | return function() {
|
2595 | return x;
|
2596 | };
|
2597 | }
|
2598 |
|
2599 | function linear(a, d) {
|
2600 | return function(t) {
|
2601 | return a + t * d;
|
2602 | };
|
2603 | }
|
2604 |
|
2605 | function exponential(a, b, y) {
|
2606 | return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) {
|
2607 | return Math.pow(a + t * b, y);
|
2608 | };
|
2609 | }
|
2610 |
|
2611 | function hue(a, b) {
|
2612 | var d = b - a;
|
2613 | return d ? linear(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$3(isNaN(a) ? b : a);
|
2614 | }
|
2615 |
|
2616 | function gamma(y) {
|
2617 | return (y = +y) === 1 ? nogamma : function(a, b) {
|
2618 | return b - a ? exponential(a, b, y) : constant$3(isNaN(a) ? b : a);
|
2619 | };
|
2620 | }
|
2621 |
|
2622 | function nogamma(a, b) {
|
2623 | var d = b - a;
|
2624 | return d ? linear(a, d) : constant$3(isNaN(a) ? b : a);
|
2625 | }
|
2626 |
|
2627 | var interpolateRgb = (function rgbGamma(y) {
|
2628 | var color = gamma(y);
|
2629 |
|
2630 | function rgb$1(start, end) {
|
2631 | var r = color((start = rgb(start)).r, (end = rgb(end)).r),
|
2632 | g = color(start.g, end.g),
|
2633 | b = color(start.b, end.b),
|
2634 | opacity = nogamma(start.opacity, end.opacity);
|
2635 | return function(t) {
|
2636 | start.r = r(t);
|
2637 | start.g = g(t);
|
2638 | start.b = b(t);
|
2639 | start.opacity = opacity(t);
|
2640 | return start + "";
|
2641 | };
|
2642 | }
|
2643 |
|
2644 | rgb$1.gamma = rgbGamma;
|
2645 |
|
2646 | return rgb$1;
|
2647 | })(1);
|
2648 |
|
2649 | function rgbSpline(spline) {
|
2650 | return function(colors) {
|
2651 | var n = colors.length,
|
2652 | r = new Array(n),
|
2653 | g = new Array(n),
|
2654 | b = new Array(n),
|
2655 | i, color;
|
2656 | for (i = 0; i < n; ++i) {
|
2657 | color = rgb(colors[i]);
|
2658 | r[i] = color.r || 0;
|
2659 | g[i] = color.g || 0;
|
2660 | b[i] = color.b || 0;
|
2661 | }
|
2662 | r = spline(r);
|
2663 | g = spline(g);
|
2664 | b = spline(b);
|
2665 | color.opacity = 1;
|
2666 | return function(t) {
|
2667 | color.r = r(t);
|
2668 | color.g = g(t);
|
2669 | color.b = b(t);
|
2670 | return color + "";
|
2671 | };
|
2672 | };
|
2673 | }
|
2674 |
|
2675 | var rgbBasis = rgbSpline(basis$1);
|
2676 | var rgbBasisClosed = rgbSpline(basisClosed);
|
2677 |
|
2678 | function numberArray(a, b) {
|
2679 | if (!b) b = [];
|
2680 | var n = a ? Math.min(b.length, a.length) : 0,
|
2681 | c = b.slice(),
|
2682 | i;
|
2683 | return function(t) {
|
2684 | for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
|
2685 | return c;
|
2686 | };
|
2687 | }
|
2688 |
|
2689 | function isNumberArray(x) {
|
2690 | return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
2691 | }
|
2692 |
|
2693 | function array$1(a, b) {
|
2694 | return (isNumberArray(b) ? numberArray : genericArray)(a, b);
|
2695 | }
|
2696 |
|
2697 | function genericArray(a, b) {
|
2698 | var nb = b ? b.length : 0,
|
2699 | na = a ? Math.min(nb, a.length) : 0,
|
2700 | x = new Array(na),
|
2701 | c = new Array(nb),
|
2702 | i;
|
2703 |
|
2704 | for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
|
2705 | for (; i < nb; ++i) c[i] = b[i];
|
2706 |
|
2707 | return function(t) {
|
2708 | for (i = 0; i < na; ++i) c[i] = x[i](t);
|
2709 | return c;
|
2710 | };
|
2711 | }
|
2712 |
|
2713 | function date(a, b) {
|
2714 | var d = new Date;
|
2715 | return a = +a, b = +b, function(t) {
|
2716 | return d.setTime(a * (1 - t) + b * t), d;
|
2717 | };
|
2718 | }
|
2719 |
|
2720 | function interpolateNumber(a, b) {
|
2721 | return a = +a, b = +b, function(t) {
|
2722 | return a * (1 - t) + b * t;
|
2723 | };
|
2724 | }
|
2725 |
|
2726 | function object(a, b) {
|
2727 | var i = {},
|
2728 | c = {},
|
2729 | k;
|
2730 |
|
2731 | if (a === null || typeof a !== "object") a = {};
|
2732 | if (b === null || typeof b !== "object") b = {};
|
2733 |
|
2734 | for (k in b) {
|
2735 | if (k in a) {
|
2736 | i[k] = interpolateValue(a[k], b[k]);
|
2737 | } else {
|
2738 | c[k] = b[k];
|
2739 | }
|
2740 | }
|
2741 |
|
2742 | return function(t) {
|
2743 | for (k in i) c[k] = i[k](t);
|
2744 | return c;
|
2745 | };
|
2746 | }
|
2747 |
|
2748 | var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
|
2749 | reB = new RegExp(reA.source, "g");
|
2750 |
|
2751 | function zero(b) {
|
2752 | return function() {
|
2753 | return b;
|
2754 | };
|
2755 | }
|
2756 |
|
2757 | function one(b) {
|
2758 | return function(t) {
|
2759 | return b(t) + "";
|
2760 | };
|
2761 | }
|
2762 |
|
2763 | function interpolateString(a, b) {
|
2764 | var bi = reA.lastIndex = reB.lastIndex = 0,
|
2765 | am,
|
2766 | bm,
|
2767 | bs,
|
2768 | i = -1,
|
2769 | s = [],
|
2770 | q = [];
|
2771 |
|
2772 |
|
2773 | a = a + "", b = b + "";
|
2774 |
|
2775 |
|
2776 | while ((am = reA.exec(a))
|
2777 | && (bm = reB.exec(b))) {
|
2778 | if ((bs = bm.index) > bi) {
|
2779 | bs = b.slice(bi, bs);
|
2780 | if (s[i]) s[i] += bs;
|
2781 | else s[++i] = bs;
|
2782 | }
|
2783 | if ((am = am[0]) === (bm = bm[0])) {
|
2784 | if (s[i]) s[i] += bm;
|
2785 | else s[++i] = bm;
|
2786 | } else {
|
2787 | s[++i] = null;
|
2788 | q.push({i: i, x: interpolateNumber(am, bm)});
|
2789 | }
|
2790 | bi = reB.lastIndex;
|
2791 | }
|
2792 |
|
2793 |
|
2794 | if (bi < b.length) {
|
2795 | bs = b.slice(bi);
|
2796 | if (s[i]) s[i] += bs;
|
2797 | else s[++i] = bs;
|
2798 | }
|
2799 |
|
2800 |
|
2801 |
|
2802 | return s.length < 2 ? (q[0]
|
2803 | ? one(q[0].x)
|
2804 | : zero(b))
|
2805 | : (b = q.length, function(t) {
|
2806 | for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
|
2807 | return s.join("");
|
2808 | });
|
2809 | }
|
2810 |
|
2811 | function interpolateValue(a, b) {
|
2812 | var t = typeof b, c;
|
2813 | return b == null || t === "boolean" ? constant$3(b)
|
2814 | : (t === "number" ? interpolateNumber
|
2815 | : t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
|
2816 | : b instanceof color ? interpolateRgb
|
2817 | : b instanceof Date ? date
|
2818 | : isNumberArray(b) ? numberArray
|
2819 | : Array.isArray(b) ? genericArray
|
2820 | : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
|
2821 | : interpolateNumber)(a, b);
|
2822 | }
|
2823 |
|
2824 | function discrete(range) {
|
2825 | var n = range.length;
|
2826 | return function(t) {
|
2827 | return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
2828 | };
|
2829 | }
|
2830 |
|
2831 | function hue$1(a, b) {
|
2832 | var i = hue(+a, +b);
|
2833 | return function(t) {
|
2834 | var x = i(t);
|
2835 | return x - 360 * Math.floor(x / 360);
|
2836 | };
|
2837 | }
|
2838 |
|
2839 | function interpolateRound(a, b) {
|
2840 | return a = +a, b = +b, function(t) {
|
2841 | return Math.round(a * (1 - t) + b * t);
|
2842 | };
|
2843 | }
|
2844 |
|
2845 | var degrees = 180 / Math.PI;
|
2846 |
|
2847 | var identity$2 = {
|
2848 | translateX: 0,
|
2849 | translateY: 0,
|
2850 | rotate: 0,
|
2851 | skewX: 0,
|
2852 | scaleX: 1,
|
2853 | scaleY: 1
|
2854 | };
|
2855 |
|
2856 | function decompose(a, b, c, d, e, f) {
|
2857 | var scaleX, scaleY, skewX;
|
2858 | if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX;
|
2859 | if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX;
|
2860 | if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY;
|
2861 | if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX;
|
2862 | return {
|
2863 | translateX: e,
|
2864 | translateY: f,
|
2865 | rotate: Math.atan2(b, a) * degrees,
|
2866 | skewX: Math.atan(skewX) * degrees,
|
2867 | scaleX: scaleX,
|
2868 | scaleY: scaleY
|
2869 | };
|
2870 | }
|
2871 |
|
2872 | var cssNode,
|
2873 | cssRoot,
|
2874 | cssView,
|
2875 | svgNode;
|
2876 |
|
2877 | function parseCss(value) {
|
2878 | if (value === "none") return identity$2;
|
2879 | if (!cssNode) cssNode = document.createElement("DIV"), cssRoot = document.documentElement, cssView = document.defaultView;
|
2880 | cssNode.style.transform = value;
|
2881 | value = cssView.getComputedStyle(cssRoot.appendChild(cssNode), null).getPropertyValue("transform");
|
2882 | cssRoot.removeChild(cssNode);
|
2883 | value = value.slice(7, -1).split(",");
|
2884 | return decompose(+value[0], +value[1], +value[2], +value[3], +value[4], +value[5]);
|
2885 | }
|
2886 |
|
2887 | function parseSvg(value) {
|
2888 | if (value == null) return identity$2;
|
2889 | if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
2890 | svgNode.setAttribute("transform", value);
|
2891 | if (!(value = svgNode.transform.baseVal.consolidate())) return identity$2;
|
2892 | value = value.matrix;
|
2893 | return decompose(value.a, value.b, value.c, value.d, value.e, value.f);
|
2894 | }
|
2895 |
|
2896 | function interpolateTransform(parse, pxComma, pxParen, degParen) {
|
2897 |
|
2898 | function pop(s) {
|
2899 | return s.length ? s.pop() + " " : "";
|
2900 | }
|
2901 |
|
2902 | function translate(xa, ya, xb, yb, s, q) {
|
2903 | if (xa !== xb || ya !== yb) {
|
2904 | var i = s.push("translate(", null, pxComma, null, pxParen);
|
2905 | q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
|
2906 | } else if (xb || yb) {
|
2907 | s.push("translate(" + xb + pxComma + yb + pxParen);
|
2908 | }
|
2909 | }
|
2910 |
|
2911 | function rotate(a, b, s, q) {
|
2912 | if (a !== b) {
|
2913 | if (a - b > 180) b += 360; else if (b - a > 180) a += 360;
|
2914 | q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)});
|
2915 | } else if (b) {
|
2916 | s.push(pop(s) + "rotate(" + b + degParen);
|
2917 | }
|
2918 | }
|
2919 |
|
2920 | function skewX(a, b, s, q) {
|
2921 | if (a !== b) {
|
2922 | q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)});
|
2923 | } else if (b) {
|
2924 | s.push(pop(s) + "skewX(" + b + degParen);
|
2925 | }
|
2926 | }
|
2927 |
|
2928 | function scale(xa, ya, xb, yb, s, q) {
|
2929 | if (xa !== xb || ya !== yb) {
|
2930 | var i = s.push(pop(s) + "scale(", null, ",", null, ")");
|
2931 | q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)});
|
2932 | } else if (xb !== 1 || yb !== 1) {
|
2933 | s.push(pop(s) + "scale(" + xb + "," + yb + ")");
|
2934 | }
|
2935 | }
|
2936 |
|
2937 | return function(a, b) {
|
2938 | var s = [],
|
2939 | q = [];
|
2940 | a = parse(a), b = parse(b);
|
2941 | translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q);
|
2942 | rotate(a.rotate, b.rotate, s, q);
|
2943 | skewX(a.skewX, b.skewX, s, q);
|
2944 | scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q);
|
2945 | a = b = null;
|
2946 | return function(t) {
|
2947 | var i = -1, n = q.length, o;
|
2948 | while (++i < n) s[(o = q[i]).i] = o.x(t);
|
2949 | return s.join("");
|
2950 | };
|
2951 | };
|
2952 | }
|
2953 |
|
2954 | var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)");
|
2955 | var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")");
|
2956 |
|
2957 | var rho = Math.SQRT2,
|
2958 | rho2 = 2,
|
2959 | rho4 = 4,
|
2960 | epsilon2 = 1e-12;
|
2961 |
|
2962 | function cosh(x) {
|
2963 | return ((x = Math.exp(x)) + 1 / x) / 2;
|
2964 | }
|
2965 |
|
2966 | function sinh(x) {
|
2967 | return ((x = Math.exp(x)) - 1 / x) / 2;
|
2968 | }
|
2969 |
|
2970 | function tanh(x) {
|
2971 | return ((x = Math.exp(2 * x)) - 1) / (x + 1);
|
2972 | }
|
2973 |
|
2974 |
|
2975 |
|
2976 | function interpolateZoom(p0, p1) {
|
2977 | var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
|
2978 | ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
|
2979 | dx = ux1 - ux0,
|
2980 | dy = uy1 - uy0,
|
2981 | d2 = dx * dx + dy * dy,
|
2982 | i,
|
2983 | S;
|
2984 |
|
2985 |
|
2986 | if (d2 < epsilon2) {
|
2987 | S = Math.log(w1 / w0) / rho;
|
2988 | i = function(t) {
|
2989 | return [
|
2990 | ux0 + t * dx,
|
2991 | uy0 + t * dy,
|
2992 | w0 * Math.exp(rho * t * S)
|
2993 | ];
|
2994 | };
|
2995 | }
|
2996 |
|
2997 |
|
2998 | else {
|
2999 | var d1 = Math.sqrt(d2),
|
3000 | b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
|
3001 | b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
|
3002 | r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
|
3003 | r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
|
3004 | S = (r1 - r0) / rho;
|
3005 | i = function(t) {
|
3006 | var s = t * S,
|
3007 | coshr0 = cosh(r0),
|
3008 | u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
|
3009 | return [
|
3010 | ux0 + u * dx,
|
3011 | uy0 + u * dy,
|
3012 | w0 * coshr0 / cosh(rho * s + r0)
|
3013 | ];
|
3014 | };
|
3015 | }
|
3016 |
|
3017 | i.duration = S * 1000;
|
3018 |
|
3019 | return i;
|
3020 | }
|
3021 |
|
3022 | function hsl$1(hue) {
|
3023 | return function(start, end) {
|
3024 | var h = hue((start = hsl(start)).h, (end = hsl(end)).h),
|
3025 | s = nogamma(start.s, end.s),
|
3026 | l = nogamma(start.l, end.l),
|
3027 | opacity = nogamma(start.opacity, end.opacity);
|
3028 | return function(t) {
|
3029 | start.h = h(t);
|
3030 | start.s = s(t);
|
3031 | start.l = l(t);
|
3032 | start.opacity = opacity(t);
|
3033 | return start + "";
|
3034 | };
|
3035 | }
|
3036 | }
|
3037 |
|
3038 | var hsl$2 = hsl$1(hue);
|
3039 | var hslLong = hsl$1(nogamma);
|
3040 |
|
3041 | function lab$1(start, end) {
|
3042 | var l = nogamma((start = lab(start)).l, (end = lab(end)).l),
|
3043 | a = nogamma(start.a, end.a),
|
3044 | b = nogamma(start.b, end.b),
|
3045 | opacity = nogamma(start.opacity, end.opacity);
|
3046 | return function(t) {
|
3047 | start.l = l(t);
|
3048 | start.a = a(t);
|
3049 | start.b = b(t);
|
3050 | start.opacity = opacity(t);
|
3051 | return start + "";
|
3052 | };
|
3053 | }
|
3054 |
|
3055 | function hcl$1(hue) {
|
3056 | return function(start, end) {
|
3057 | var h = hue((start = hcl(start)).h, (end = hcl(end)).h),
|
3058 | c = nogamma(start.c, end.c),
|
3059 | l = nogamma(start.l, end.l),
|
3060 | opacity = nogamma(start.opacity, end.opacity);
|
3061 | return function(t) {
|
3062 | start.h = h(t);
|
3063 | start.c = c(t);
|
3064 | start.l = l(t);
|
3065 | start.opacity = opacity(t);
|
3066 | return start + "";
|
3067 | };
|
3068 | }
|
3069 | }
|
3070 |
|
3071 | var hcl$2 = hcl$1(hue);
|
3072 | var hclLong = hcl$1(nogamma);
|
3073 |
|
3074 | function cubehelix$1(hue) {
|
3075 | return (function cubehelixGamma(y) {
|
3076 | y = +y;
|
3077 |
|
3078 | function cubehelix$1(start, end) {
|
3079 | var h = hue((start = cubehelix(start)).h, (end = cubehelix(end)).h),
|
3080 | s = nogamma(start.s, end.s),
|
3081 | l = nogamma(start.l, end.l),
|
3082 | opacity = nogamma(start.opacity, end.opacity);
|
3083 | return function(t) {
|
3084 | start.h = h(t);
|
3085 | start.s = s(t);
|
3086 | start.l = l(Math.pow(t, y));
|
3087 | start.opacity = opacity(t);
|
3088 | return start + "";
|
3089 | };
|
3090 | }
|
3091 |
|
3092 | cubehelix$1.gamma = cubehelixGamma;
|
3093 |
|
3094 | return cubehelix$1;
|
3095 | })(1);
|
3096 | }
|
3097 |
|
3098 | var cubehelix$2 = cubehelix$1(hue);
|
3099 | var cubehelixLong = cubehelix$1(nogamma);
|
3100 |
|
3101 | function piecewise(interpolate, values) {
|
3102 | var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
|
3103 | while (i < n) I[i] = interpolate(v, v = values[++i]);
|
3104 | return function(t) {
|
3105 | var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
|
3106 | return I[i](t - i);
|
3107 | };
|
3108 | }
|
3109 |
|
3110 | function quantize(interpolator, n) {
|
3111 | var samples = new Array(n);
|
3112 | for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1));
|
3113 | return samples;
|
3114 | }
|
3115 |
|
3116 | var frame = 0,
|
3117 | timeout = 0,
|
3118 | interval = 0,
|
3119 | pokeDelay = 1000,
|
3120 | taskHead,
|
3121 | taskTail,
|
3122 | clockLast = 0,
|
3123 | clockNow = 0,
|
3124 | clockSkew = 0,
|
3125 | clock = typeof performance === "object" && performance.now ? performance : Date,
|
3126 | setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
|
3127 |
|
3128 | function now() {
|
3129 | return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
|
3130 | }
|
3131 |
|
3132 | function clearNow() {
|
3133 | clockNow = 0;
|
3134 | }
|
3135 |
|
3136 | function Timer() {
|
3137 | this._call =
|
3138 | this._time =
|
3139 | this._next = null;
|
3140 | }
|
3141 |
|
3142 | Timer.prototype = timer.prototype = {
|
3143 | constructor: Timer,
|
3144 | restart: function(callback, delay, time) {
|
3145 | if (typeof callback !== "function") throw new TypeError("callback is not a function");
|
3146 | time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
|
3147 | if (!this._next && taskTail !== this) {
|
3148 | if (taskTail) taskTail._next = this;
|
3149 | else taskHead = this;
|
3150 | taskTail = this;
|
3151 | }
|
3152 | this._call = callback;
|
3153 | this._time = time;
|
3154 | sleep();
|
3155 | },
|
3156 | stop: function() {
|
3157 | if (this._call) {
|
3158 | this._call = null;
|
3159 | this._time = Infinity;
|
3160 | sleep();
|
3161 | }
|
3162 | }
|
3163 | };
|
3164 |
|
3165 | function timer(callback, delay, time) {
|
3166 | var t = new Timer;
|
3167 | t.restart(callback, delay, time);
|
3168 | return t;
|
3169 | }
|
3170 |
|
3171 | function timerFlush() {
|
3172 | now();
|
3173 | ++frame;
|
3174 | var t = taskHead, e;
|
3175 | while (t) {
|
3176 | if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
|
3177 | t = t._next;
|
3178 | }
|
3179 | --frame;
|
3180 | }
|
3181 |
|
3182 | function wake() {
|
3183 | clockNow = (clockLast = clock.now()) + clockSkew;
|
3184 | frame = timeout = 0;
|
3185 | try {
|
3186 | timerFlush();
|
3187 | } finally {
|
3188 | frame = 0;
|
3189 | nap();
|
3190 | clockNow = 0;
|
3191 | }
|
3192 | }
|
3193 |
|
3194 | function poke() {
|
3195 | var now = clock.now(), delay = now - clockLast;
|
3196 | if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
|
3197 | }
|
3198 |
|
3199 | function nap() {
|
3200 | var t0, t1 = taskHead, t2, time = Infinity;
|
3201 | while (t1) {
|
3202 | if (t1._call) {
|
3203 | if (time > t1._time) time = t1._time;
|
3204 | t0 = t1, t1 = t1._next;
|
3205 | } else {
|
3206 | t2 = t1._next, t1._next = null;
|
3207 | t1 = t0 ? t0._next = t2 : taskHead = t2;
|
3208 | }
|
3209 | }
|
3210 | taskTail = t0;
|
3211 | sleep(time);
|
3212 | }
|
3213 |
|
3214 | function sleep(time) {
|
3215 | if (frame) return;
|
3216 | if (timeout) timeout = clearTimeout(timeout);
|
3217 | var delay = time - clockNow;
|
3218 | if (delay > 24) {
|
3219 | if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
|
3220 | if (interval) interval = clearInterval(interval);
|
3221 | } else {
|
3222 | if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
|
3223 | frame = 1, setFrame(wake);
|
3224 | }
|
3225 | }
|
3226 |
|
3227 | function timeout$1(callback, delay, time) {
|
3228 | var t = new Timer;
|
3229 | delay = delay == null ? 0 : +delay;
|
3230 | t.restart(function(elapsed) {
|
3231 | t.stop();
|
3232 | callback(elapsed + delay);
|
3233 | }, delay, time);
|
3234 | return t;
|
3235 | }
|
3236 |
|
3237 | function interval$1(callback, delay, time) {
|
3238 | var t = new Timer, total = delay;
|
3239 | if (delay == null) return t.restart(callback, delay, time), t;
|
3240 | delay = +delay, time = time == null ? now() : +time;
|
3241 | t.restart(function tick(elapsed) {
|
3242 | elapsed += total;
|
3243 | t.restart(tick, total += delay, time);
|
3244 | callback(elapsed);
|
3245 | }, delay, time);
|
3246 | return t;
|
3247 | }
|
3248 |
|
3249 | var emptyOn = dispatch("start", "end", "cancel", "interrupt");
|
3250 | var emptyTween = [];
|
3251 |
|
3252 | var CREATED = 0;
|
3253 | var SCHEDULED = 1;
|
3254 | var STARTING = 2;
|
3255 | var STARTED = 3;
|
3256 | var RUNNING = 4;
|
3257 | var ENDING = 5;
|
3258 | var ENDED = 6;
|
3259 |
|
3260 | function schedule(node, name, id, index, group, timing) {
|
3261 | var schedules = node.__transition;
|
3262 | if (!schedules) node.__transition = {};
|
3263 | else if (id in schedules) return;
|
3264 | create$1(node, id, {
|
3265 | name: name,
|
3266 | index: index,
|
3267 | group: group,
|
3268 | on: emptyOn,
|
3269 | tween: emptyTween,
|
3270 | time: timing.time,
|
3271 | delay: timing.delay,
|
3272 | duration: timing.duration,
|
3273 | ease: timing.ease,
|
3274 | timer: null,
|
3275 | state: CREATED
|
3276 | });
|
3277 | }
|
3278 |
|
3279 | function init(node, id) {
|
3280 | var schedule = get$1(node, id);
|
3281 | if (schedule.state > CREATED) throw new Error("too late; already scheduled");
|
3282 | return schedule;
|
3283 | }
|
3284 |
|
3285 | function set$1(node, id) {
|
3286 | var schedule = get$1(node, id);
|
3287 | if (schedule.state > STARTED) throw new Error("too late; already running");
|
3288 | return schedule;
|
3289 | }
|
3290 |
|
3291 | function get$1(node, id) {
|
3292 | var schedule = node.__transition;
|
3293 | if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
|
3294 | return schedule;
|
3295 | }
|
3296 |
|
3297 | function create$1(node, id, self) {
|
3298 | var schedules = node.__transition,
|
3299 | tween;
|
3300 |
|
3301 |
|
3302 |
|
3303 | schedules[id] = self;
|
3304 | self.timer = timer(schedule, 0, self.time);
|
3305 |
|
3306 | function schedule(elapsed) {
|
3307 | self.state = SCHEDULED;
|
3308 | self.timer.restart(start, self.delay, self.time);
|
3309 |
|
3310 |
|
3311 | if (self.delay <= elapsed) start(elapsed - self.delay);
|
3312 | }
|
3313 |
|
3314 | function start(elapsed) {
|
3315 | var i, j, n, o;
|
3316 |
|
3317 |
|
3318 | if (self.state !== SCHEDULED) return stop();
|
3319 |
|
3320 | for (i in schedules) {
|
3321 | o = schedules[i];
|
3322 | if (o.name !== self.name) continue;
|
3323 |
|
3324 |
|
3325 |
|
3326 |
|
3327 | if (o.state === STARTED) return timeout$1(start);
|
3328 |
|
3329 |
|
3330 | if (o.state === RUNNING) {
|
3331 | o.state = ENDED;
|
3332 | o.timer.stop();
|
3333 | o.on.call("interrupt", node, node.__data__, o.index, o.group);
|
3334 | delete schedules[i];
|
3335 | }
|
3336 |
|
3337 |
|
3338 | else if (+i < id) {
|
3339 | o.state = ENDED;
|
3340 | o.timer.stop();
|
3341 | o.on.call("cancel", node, node.__data__, o.index, o.group);
|
3342 | delete schedules[i];
|
3343 | }
|
3344 | }
|
3345 |
|
3346 |
|
3347 |
|
3348 |
|
3349 |
|
3350 | timeout$1(function() {
|
3351 | if (self.state === STARTED) {
|
3352 | self.state = RUNNING;
|
3353 | self.timer.restart(tick, self.delay, self.time);
|
3354 | tick(elapsed);
|
3355 | }
|
3356 | });
|
3357 |
|
3358 |
|
3359 |
|
3360 | self.state = STARTING;
|
3361 | self.on.call("start", node, node.__data__, self.index, self.group);
|
3362 | if (self.state !== STARTING) return;
|
3363 | self.state = STARTED;
|
3364 |
|
3365 |
|
3366 | tween = new Array(n = self.tween.length);
|
3367 | for (i = 0, j = -1; i < n; ++i) {
|
3368 | if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
|
3369 | tween[++j] = o;
|
3370 | }
|
3371 | }
|
3372 | tween.length = j + 1;
|
3373 | }
|
3374 |
|
3375 | function tick(elapsed) {
|
3376 | var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
|
3377 | i = -1,
|
3378 | n = tween.length;
|
3379 |
|
3380 | while (++i < n) {
|
3381 | tween[i].call(node, t);
|
3382 | }
|
3383 |
|
3384 |
|
3385 | if (self.state === ENDING) {
|
3386 | self.on.call("end", node, node.__data__, self.index, self.group);
|
3387 | stop();
|
3388 | }
|
3389 | }
|
3390 |
|
3391 | function stop() {
|
3392 | self.state = ENDED;
|
3393 | self.timer.stop();
|
3394 | delete schedules[id];
|
3395 | for (var i in schedules) return;
|
3396 | delete node.__transition;
|
3397 | }
|
3398 | }
|
3399 |
|
3400 | function interrupt(node, name) {
|
3401 | var schedules = node.__transition,
|
3402 | schedule,
|
3403 | active,
|
3404 | empty = true,
|
3405 | i;
|
3406 |
|
3407 | if (!schedules) return;
|
3408 |
|
3409 | name = name == null ? null : name + "";
|
3410 |
|
3411 | for (i in schedules) {
|
3412 | if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
|
3413 | active = schedule.state > STARTING && schedule.state < ENDING;
|
3414 | schedule.state = ENDED;
|
3415 | schedule.timer.stop();
|
3416 | schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
|
3417 | delete schedules[i];
|
3418 | }
|
3419 |
|
3420 | if (empty) delete node.__transition;
|
3421 | }
|
3422 |
|
3423 | function selection_interrupt(name) {
|
3424 | return this.each(function() {
|
3425 | interrupt(this, name);
|
3426 | });
|
3427 | }
|
3428 |
|
3429 | function tweenRemove(id, name) {
|
3430 | var tween0, tween1;
|
3431 | return function() {
|
3432 | var schedule = set$1(this, id),
|
3433 | tween = schedule.tween;
|
3434 |
|
3435 | // If this node shared tween with the previous node,
|
3436 | // just assign the updated shared tween and we’re done!
|
3437 | // Otherwise, copy-on-write.
|
3438 | if (tween !== tween0) {
|
3439 | tween1 = tween0 = tween;
|
3440 | for (var i = 0, n = tween1.length; i < n; ++i) {
|
3441 | if (tween1[i].name === name) {
|
3442 | tween1 = tween1.slice();
|
3443 | tween1.splice(i, 1);
|
3444 | break;
|
3445 | }
|
3446 | }
|
3447 | }
|
3448 |
|
3449 | schedule.tween = tween1;
|
3450 | };
|
3451 | }
|
3452 |
|
3453 | function tweenFunction(id, name, value) {
|
3454 | var tween0, tween1;
|
3455 | if (typeof value !== "function") throw new Error;
|
3456 | return function() {
|
3457 | var schedule = set$1(this, id),
|
3458 | tween = schedule.tween;
|
3459 |
|
3460 | // If this node shared tween with the previous node,
|
3461 | // just assign the updated shared tween and we’re done!
|
3462 | // Otherwise, copy-on-write.
|
3463 | if (tween !== tween0) {
|
3464 | tween1 = (tween0 = tween).slice();
|
3465 | for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
|
3466 | if (tween1[i].name === name) {
|
3467 | tween1[i] = t;
|
3468 | break;
|
3469 | }
|
3470 | }
|
3471 | if (i === n) tween1.push(t);
|
3472 | }
|
3473 |
|
3474 | schedule.tween = tween1;
|
3475 | };
|
3476 | }
|
3477 |
|
3478 | function transition_tween(name, value) {
|
3479 | var id = this._id;
|
3480 |
|
3481 | name += "";
|
3482 |
|
3483 | if (arguments.length < 2) {
|
3484 | var tween = get$1(this.node(), id).tween;
|
3485 | for (var i = 0, n = tween.length, t; i < n; ++i) {
|
3486 | if ((t = tween[i]).name === name) {
|
3487 | return t.value;
|
3488 | }
|
3489 | }
|
3490 | return null;
|
3491 | }
|
3492 |
|
3493 | return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
|
3494 | }
|
3495 |
|
3496 | function tweenValue(transition, name, value) {
|
3497 | var id = transition._id;
|
3498 |
|
3499 | transition.each(function() {
|
3500 | var schedule = set$1(this, id);
|
3501 | (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
|
3502 | });
|
3503 |
|
3504 | return function(node) {
|
3505 | return get$1(node, id).value[name];
|
3506 | };
|
3507 | }
|
3508 |
|
3509 | function interpolate(a, b) {
|
3510 | var c;
|
3511 | return (typeof b === "number" ? interpolateNumber
|
3512 | : b instanceof color ? interpolateRgb
|
3513 | : (c = color(b)) ? (b = c, interpolateRgb)
|
3514 | : interpolateString)(a, b);
|
3515 | }
|
3516 |
|
3517 | function attrRemove$1(name) {
|
3518 | return function() {
|
3519 | this.removeAttribute(name);
|
3520 | };
|
3521 | }
|
3522 |
|
3523 | function attrRemoveNS$1(fullname) {
|
3524 | return function() {
|
3525 | this.removeAttributeNS(fullname.space, fullname.local);
|
3526 | };
|
3527 | }
|
3528 |
|
3529 | function attrConstant$1(name, interpolate, value1) {
|
3530 | var string00,
|
3531 | string1 = value1 + "",
|
3532 | interpolate0;
|
3533 | return function() {
|
3534 | var string0 = this.getAttribute(name);
|
3535 | return string0 === string1 ? null
|
3536 | : string0 === string00 ? interpolate0
|
3537 | : interpolate0 = interpolate(string00 = string0, value1);
|
3538 | };
|
3539 | }
|
3540 |
|
3541 | function attrConstantNS$1(fullname, interpolate, value1) {
|
3542 | var string00,
|
3543 | string1 = value1 + "",
|
3544 | interpolate0;
|
3545 | return function() {
|
3546 | var string0 = this.getAttributeNS(fullname.space, fullname.local);
|
3547 | return string0 === string1 ? null
|
3548 | : string0 === string00 ? interpolate0
|
3549 | : interpolate0 = interpolate(string00 = string0, value1);
|
3550 | };
|
3551 | }
|
3552 |
|
3553 | function attrFunction$1(name, interpolate, value) {
|
3554 | var string00,
|
3555 | string10,
|
3556 | interpolate0;
|
3557 | return function() {
|
3558 | var string0, value1 = value(this), string1;
|
3559 | if (value1 == null) return void this.removeAttribute(name);
|
3560 | string0 = this.getAttribute(name);
|
3561 | string1 = value1 + "";
|
3562 | return string0 === string1 ? null
|
3563 | : string0 === string00 && string1 === string10 ? interpolate0
|
3564 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
3565 | };
|
3566 | }
|
3567 |
|
3568 | function attrFunctionNS$1(fullname, interpolate, value) {
|
3569 | var string00,
|
3570 | string10,
|
3571 | interpolate0;
|
3572 | return function() {
|
3573 | var string0, value1 = value(this), string1;
|
3574 | if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
|
3575 | string0 = this.getAttributeNS(fullname.space, fullname.local);
|
3576 | string1 = value1 + "";
|
3577 | return string0 === string1 ? null
|
3578 | : string0 === string00 && string1 === string10 ? interpolate0
|
3579 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
3580 | };
|
3581 | }
|
3582 |
|
3583 | function transition_attr(name, value) {
|
3584 | var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate;
|
3585 | return this.attrTween(name, typeof value === "function"
|
3586 | ? (fullname.local ? attrFunctionNS$1 : attrFunction$1)(fullname, i, tweenValue(this, "attr." + name, value))
|
3587 | : value == null ? (fullname.local ? attrRemoveNS$1 : attrRemove$1)(fullname)
|
3588 | : (fullname.local ? attrConstantNS$1 : attrConstant$1)(fullname, i, value));
|
3589 | }
|
3590 |
|
3591 | function attrInterpolate(name, i) {
|
3592 | return function(t) {
|
3593 | this.setAttribute(name, i.call(this, t));
|
3594 | };
|
3595 | }
|
3596 |
|
3597 | function attrInterpolateNS(fullname, i) {
|
3598 | return function(t) {
|
3599 | this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
|
3600 | };
|
3601 | }
|
3602 |
|
3603 | function attrTweenNS(fullname, value) {
|
3604 | var t0, i0;
|
3605 | function tween() {
|
3606 | var i = value.apply(this, arguments);
|
3607 | if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
|
3608 | return t0;
|
3609 | }
|
3610 | tween._value = value;
|
3611 | return tween;
|
3612 | }
|
3613 |
|
3614 | function attrTween(name, value) {
|
3615 | var t0, i0;
|
3616 | function tween() {
|
3617 | var i = value.apply(this, arguments);
|
3618 | if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
|
3619 | return t0;
|
3620 | }
|
3621 | tween._value = value;
|
3622 | return tween;
|
3623 | }
|
3624 |
|
3625 | function transition_attrTween(name, value) {
|
3626 | var key = "attr." + name;
|
3627 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
3628 | if (value == null) return this.tween(key, null);
|
3629 | if (typeof value !== "function") throw new Error;
|
3630 | var fullname = namespace(name);
|
3631 | return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
|
3632 | }
|
3633 |
|
3634 | function delayFunction(id, value) {
|
3635 | return function() {
|
3636 | init(this, id).delay = +value.apply(this, arguments);
|
3637 | };
|
3638 | }
|
3639 |
|
3640 | function delayConstant(id, value) {
|
3641 | return value = +value, function() {
|
3642 | init(this, id).delay = value;
|
3643 | };
|
3644 | }
|
3645 |
|
3646 | function transition_delay(value) {
|
3647 | var id = this._id;
|
3648 |
|
3649 | return arguments.length
|
3650 | ? this.each((typeof value === "function"
|
3651 | ? delayFunction
|
3652 | : delayConstant)(id, value))
|
3653 | : get$1(this.node(), id).delay;
|
3654 | }
|
3655 |
|
3656 | function durationFunction(id, value) {
|
3657 | return function() {
|
3658 | set$1(this, id).duration = +value.apply(this, arguments);
|
3659 | };
|
3660 | }
|
3661 |
|
3662 | function durationConstant(id, value) {
|
3663 | return value = +value, function() {
|
3664 | set$1(this, id).duration = value;
|
3665 | };
|
3666 | }
|
3667 |
|
3668 | function transition_duration(value) {
|
3669 | var id = this._id;
|
3670 |
|
3671 | return arguments.length
|
3672 | ? this.each((typeof value === "function"
|
3673 | ? durationFunction
|
3674 | : durationConstant)(id, value))
|
3675 | : get$1(this.node(), id).duration;
|
3676 | }
|
3677 |
|
3678 | function easeConstant(id, value) {
|
3679 | if (typeof value !== "function") throw new Error;
|
3680 | return function() {
|
3681 | set$1(this, id).ease = value;
|
3682 | };
|
3683 | }
|
3684 |
|
3685 | function transition_ease(value) {
|
3686 | var id = this._id;
|
3687 |
|
3688 | return arguments.length
|
3689 | ? this.each(easeConstant(id, value))
|
3690 | : get$1(this.node(), id).ease;
|
3691 | }
|
3692 |
|
3693 | function transition_filter(match) {
|
3694 | if (typeof match !== "function") match = matcher(match);
|
3695 |
|
3696 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
3697 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
|
3698 | if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
3699 | subgroup.push(node);
|
3700 | }
|
3701 | }
|
3702 | }
|
3703 |
|
3704 | return new Transition(subgroups, this._parents, this._name, this._id);
|
3705 | }
|
3706 |
|
3707 | function transition_merge(transition) {
|
3708 | if (transition._id !== this._id) throw new Error;
|
3709 |
|
3710 | 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) {
|
3711 | for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
|
3712 | if (node = group0[i] || group1[i]) {
|
3713 | merge[i] = node;
|
3714 | }
|
3715 | }
|
3716 | }
|
3717 |
|
3718 | for (; j < m0; ++j) {
|
3719 | merges[j] = groups0[j];
|
3720 | }
|
3721 |
|
3722 | return new Transition(merges, this._parents, this._name, this._id);
|
3723 | }
|
3724 |
|
3725 | function start(name) {
|
3726 | return (name + "").trim().split(/^|\s+/).every(function(t) {
|
3727 | var i = t.indexOf(".");
|
3728 | if (i >= 0) t = t.slice(0, i);
|
3729 | return !t || t === "start";
|
3730 | });
|
3731 | }
|
3732 |
|
3733 | function onFunction(id, name, listener) {
|
3734 | var on0, on1, sit = start(name) ? init : set$1;
|
3735 | return function() {
|
3736 | var schedule = sit(this, id),
|
3737 | on = schedule.on;
|
3738 |
|
3739 |
|
3740 |
|
3741 |
|
3742 | if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
|
3743 |
|
3744 | schedule.on = on1;
|
3745 | };
|
3746 | }
|
3747 |
|
3748 | function transition_on(name, listener) {
|
3749 | var id = this._id;
|
3750 |
|
3751 | return arguments.length < 2
|
3752 | ? get$1(this.node(), id).on.on(name)
|
3753 | : this.each(onFunction(id, name, listener));
|
3754 | }
|
3755 |
|
3756 | function removeFunction(id) {
|
3757 | return function() {
|
3758 | var parent = this.parentNode;
|
3759 | for (var i in this.__transition) if (+i !== id) return;
|
3760 | if (parent) parent.removeChild(this);
|
3761 | };
|
3762 | }
|
3763 |
|
3764 | function transition_remove() {
|
3765 | return this.on("end.remove", removeFunction(this._id));
|
3766 | }
|
3767 |
|
3768 | function transition_select(select) {
|
3769 | var name = this._name,
|
3770 | id = this._id;
|
3771 |
|
3772 | if (typeof select !== "function") select = selector(select);
|
3773 |
|
3774 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
3775 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
|
3776 | if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
3777 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
3778 | subgroup[i] = subnode;
|
3779 | schedule(subgroup[i], name, id, i, subgroup, get$1(node, id));
|
3780 | }
|
3781 | }
|
3782 | }
|
3783 |
|
3784 | return new Transition(subgroups, this._parents, name, id);
|
3785 | }
|
3786 |
|
3787 | function transition_selectAll(select) {
|
3788 | var name = this._name,
|
3789 | id = this._id;
|
3790 |
|
3791 | if (typeof select !== "function") select = selectorAll(select);
|
3792 |
|
3793 | for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
|
3794 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
3795 | if (node = group[i]) {
|
3796 | for (var children = select.call(node, node.__data__, i, group), child, inherit = get$1(node, id), k = 0, l = children.length; k < l; ++k) {
|
3797 | if (child = children[k]) {
|
3798 | schedule(child, name, id, k, children, inherit);
|
3799 | }
|
3800 | }
|
3801 | subgroups.push(children);
|
3802 | parents.push(node);
|
3803 | }
|
3804 | }
|
3805 | }
|
3806 |
|
3807 | return new Transition(subgroups, parents, name, id);
|
3808 | }
|
3809 |
|
3810 | var Selection$1 = selection.prototype.constructor;
|
3811 |
|
3812 | function transition_selection() {
|
3813 | return new Selection$1(this._groups, this._parents);
|
3814 | }
|
3815 |
|
3816 | function styleNull(name, interpolate) {
|
3817 | var string00,
|
3818 | string10,
|
3819 | interpolate0;
|
3820 | return function() {
|
3821 | var string0 = styleValue(this, name),
|
3822 | string1 = (this.style.removeProperty(name), styleValue(this, name));
|
3823 | return string0 === string1 ? null
|
3824 | : string0 === string00 && string1 === string10 ? interpolate0
|
3825 | : interpolate0 = interpolate(string00 = string0, string10 = string1);
|
3826 | };
|
3827 | }
|
3828 |
|
3829 | function styleRemove$1(name) {
|
3830 | return function() {
|
3831 | this.style.removeProperty(name);
|
3832 | };
|
3833 | }
|
3834 |
|
3835 | function styleConstant$1(name, interpolate, value1) {
|
3836 | var string00,
|
3837 | string1 = value1 + "",
|
3838 | interpolate0;
|
3839 | return function() {
|
3840 | var string0 = styleValue(this, name);
|
3841 | return string0 === string1 ? null
|
3842 | : string0 === string00 ? interpolate0
|
3843 | : interpolate0 = interpolate(string00 = string0, value1);
|
3844 | };
|
3845 | }
|
3846 |
|
3847 | function styleFunction$1(name, interpolate, value) {
|
3848 | var string00,
|
3849 | string10,
|
3850 | interpolate0;
|
3851 | return function() {
|
3852 | var string0 = styleValue(this, name),
|
3853 | value1 = value(this),
|
3854 | string1 = value1 + "";
|
3855 | if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
|
3856 | return string0 === string1 ? null
|
3857 | : string0 === string00 && string1 === string10 ? interpolate0
|
3858 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
3859 | };
|
3860 | }
|
3861 |
|
3862 | function styleMaybeRemove(id, name) {
|
3863 | var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
|
3864 | return function() {
|
3865 | var schedule = set$1(this, id),
|
3866 | on = schedule.on,
|
3867 | listener = schedule.value[key] == null ? remove || (remove = styleRemove$1(name)) : undefined;
|
3868 |
|
3869 | // If this node shared a dispatch with the previous node,
|
3870 | // just assign the updated shared dispatch and we’re done!
|
3871 | // Otherwise, copy-on-write.
|
3872 | if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
|
3873 |
|
3874 | schedule.on = on1;
|
3875 | };
|
3876 | }
|
3877 |
|
3878 | function transition_style(name, value, priority) {
|
3879 | var i = (name += "") === "transform" ? interpolateTransformCss : interpolate;
|
3880 | return value == null ? this
|
3881 | .styleTween(name, styleNull(name, i))
|
3882 | .on("end.style." + name, styleRemove$1(name))
|
3883 | : typeof value === "function" ? this
|
3884 | .styleTween(name, styleFunction$1(name, i, tweenValue(this, "style." + name, value)))
|
3885 | .each(styleMaybeRemove(this._id, name))
|
3886 | : this
|
3887 | .styleTween(name, styleConstant$1(name, i, value), priority)
|
3888 | .on("end.style." + name, null);
|
3889 | }
|
3890 |
|
3891 | function styleInterpolate(name, i, priority) {
|
3892 | return function(t) {
|
3893 | this.style.setProperty(name, i.call(this, t), priority);
|
3894 | };
|
3895 | }
|
3896 |
|
3897 | function styleTween(name, value, priority) {
|
3898 | var t, i0;
|
3899 | function tween() {
|
3900 | var i = value.apply(this, arguments);
|
3901 | if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
|
3902 | return t;
|
3903 | }
|
3904 | tween._value = value;
|
3905 | return tween;
|
3906 | }
|
3907 |
|
3908 | function transition_styleTween(name, value, priority) {
|
3909 | var key = "style." + (name += "");
|
3910 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
3911 | if (value == null) return this.tween(key, null);
|
3912 | if (typeof value !== "function") throw new Error;
|
3913 | return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
|
3914 | }
|
3915 |
|
3916 | function textConstant$1(value) {
|
3917 | return function() {
|
3918 | this.textContent = value;
|
3919 | };
|
3920 | }
|
3921 |
|
3922 | function textFunction$1(value) {
|
3923 | return function() {
|
3924 | var value1 = value(this);
|
3925 | this.textContent = value1 == null ? "" : value1;
|
3926 | };
|
3927 | }
|
3928 |
|
3929 | function transition_text(value) {
|
3930 | return this.tween("text", typeof value === "function"
|
3931 | ? textFunction$1(tweenValue(this, "text", value))
|
3932 | : textConstant$1(value == null ? "" : value + ""));
|
3933 | }
|
3934 |
|
3935 | function textInterpolate(i) {
|
3936 | return function(t) {
|
3937 | this.textContent = i.call(this, t);
|
3938 | };
|
3939 | }
|
3940 |
|
3941 | function textTween(value) {
|
3942 | var t0, i0;
|
3943 | function tween() {
|
3944 | var i = value.apply(this, arguments);
|
3945 | if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
|
3946 | return t0;
|
3947 | }
|
3948 | tween._value = value;
|
3949 | return tween;
|
3950 | }
|
3951 |
|
3952 | function transition_textTween(value) {
|
3953 | var key = "text";
|
3954 | if (arguments.length < 1) return (key = this.tween(key)) && key._value;
|
3955 | if (value == null) return this.tween(key, null);
|
3956 | if (typeof value !== "function") throw new Error;
|
3957 | return this.tween(key, textTween(value));
|
3958 | }
|
3959 |
|
3960 | function transition_transition() {
|
3961 | var name = this._name,
|
3962 | id0 = this._id,
|
3963 | id1 = newId();
|
3964 |
|
3965 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
3966 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
3967 | if (node = group[i]) {
|
3968 | var inherit = get$1(node, id0);
|
3969 | schedule(node, name, id1, i, group, {
|
3970 | time: inherit.time + inherit.delay + inherit.duration,
|
3971 | delay: 0,
|
3972 | duration: inherit.duration,
|
3973 | ease: inherit.ease
|
3974 | });
|
3975 | }
|
3976 | }
|
3977 | }
|
3978 |
|
3979 | return new Transition(groups, this._parents, name, id1);
|
3980 | }
|
3981 |
|
3982 | function transition_end() {
|
3983 | var on0, on1, that = this, id = that._id, size = that.size();
|
3984 | return new Promise(function(resolve, reject) {
|
3985 | var cancel = {value: reject},
|
3986 | end = {value: function() { if (--size === 0) resolve(); }};
|
3987 |
|
3988 | that.each(function() {
|
3989 | var schedule = set$1(this, id),
|
3990 | on = schedule.on;
|
3991 |
|
3992 | // If this node shared a dispatch with the previous node,
|
3993 | // just assign the updated shared dispatch and we’re done!
|
3994 | // Otherwise, copy-on-write.
|
3995 | if (on !== on0) {
|
3996 | on1 = (on0 = on).copy();
|
3997 | on1._.cancel.push(cancel);
|
3998 | on1._.interrupt.push(cancel);
|
3999 | on1._.end.push(end);
|
4000 | }
|
4001 |
|
4002 | schedule.on = on1;
|
4003 | });
|
4004 | });
|
4005 | }
|
4006 |
|
4007 | var id = 0;
|
4008 |
|
4009 | function Transition(groups, parents, name, id) {
|
4010 | this._groups = groups;
|
4011 | this._parents = parents;
|
4012 | this._name = name;
|
4013 | this._id = id;
|
4014 | }
|
4015 |
|
4016 | function transition(name) {
|
4017 | return selection().transition(name);
|
4018 | }
|
4019 |
|
4020 | function newId() {
|
4021 | return ++id;
|
4022 | }
|
4023 |
|
4024 | var selection_prototype = selection.prototype;
|
4025 |
|
4026 | Transition.prototype = transition.prototype = {
|
4027 | constructor: Transition,
|
4028 | select: transition_select,
|
4029 | selectAll: transition_selectAll,
|
4030 | filter: transition_filter,
|
4031 | merge: transition_merge,
|
4032 | selection: transition_selection,
|
4033 | transition: transition_transition,
|
4034 | call: selection_prototype.call,
|
4035 | nodes: selection_prototype.nodes,
|
4036 | node: selection_prototype.node,
|
4037 | size: selection_prototype.size,
|
4038 | empty: selection_prototype.empty,
|
4039 | each: selection_prototype.each,
|
4040 | on: transition_on,
|
4041 | attr: transition_attr,
|
4042 | attrTween: transition_attrTween,
|
4043 | style: transition_style,
|
4044 | styleTween: transition_styleTween,
|
4045 | text: transition_text,
|
4046 | textTween: transition_textTween,
|
4047 | remove: transition_remove,
|
4048 | tween: transition_tween,
|
4049 | delay: transition_delay,
|
4050 | duration: transition_duration,
|
4051 | ease: transition_ease,
|
4052 | end: transition_end
|
4053 | };
|
4054 |
|
4055 | function linear$1(t) {
|
4056 | return +t;
|
4057 | }
|
4058 |
|
4059 | function quadIn(t) {
|
4060 | return t * t;
|
4061 | }
|
4062 |
|
4063 | function quadOut(t) {
|
4064 | return t * (2 - t);
|
4065 | }
|
4066 |
|
4067 | function quadInOut(t) {
|
4068 | return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
|
4069 | }
|
4070 |
|
4071 | function cubicIn(t) {
|
4072 | return t * t * t;
|
4073 | }
|
4074 |
|
4075 | function cubicOut(t) {
|
4076 | return --t * t * t + 1;
|
4077 | }
|
4078 |
|
4079 | function cubicInOut(t) {
|
4080 | return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2;
|
4081 | }
|
4082 |
|
4083 | var exponent = 3;
|
4084 |
|
4085 | var polyIn = (function custom(e) {
|
4086 | e = +e;
|
4087 |
|
4088 | function polyIn(t) {
|
4089 | return Math.pow(t, e);
|
4090 | }
|
4091 |
|
4092 | polyIn.exponent = custom;
|
4093 |
|
4094 | return polyIn;
|
4095 | })(exponent);
|
4096 |
|
4097 | var polyOut = (function custom(e) {
|
4098 | e = +e;
|
4099 |
|
4100 | function polyOut(t) {
|
4101 | return 1 - Math.pow(1 - t, e);
|
4102 | }
|
4103 |
|
4104 | polyOut.exponent = custom;
|
4105 |
|
4106 | return polyOut;
|
4107 | })(exponent);
|
4108 |
|
4109 | var polyInOut = (function custom(e) {
|
4110 | e = +e;
|
4111 |
|
4112 | function polyInOut(t) {
|
4113 | return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2;
|
4114 | }
|
4115 |
|
4116 | polyInOut.exponent = custom;
|
4117 |
|
4118 | return polyInOut;
|
4119 | })(exponent);
|
4120 |
|
4121 | var pi = Math.PI,
|
4122 | halfPi = pi / 2;
|
4123 |
|
4124 | function sinIn(t) {
|
4125 | return 1 - Math.cos(t * halfPi);
|
4126 | }
|
4127 |
|
4128 | function sinOut(t) {
|
4129 | return Math.sin(t * halfPi);
|
4130 | }
|
4131 |
|
4132 | function sinInOut(t) {
|
4133 | return (1 - Math.cos(pi * t)) / 2;
|
4134 | }
|
4135 |
|
4136 | function expIn(t) {
|
4137 | return Math.pow(2, 10 * t - 10);
|
4138 | }
|
4139 |
|
4140 | function expOut(t) {
|
4141 | return 1 - Math.pow(2, -10 * t);
|
4142 | }
|
4143 |
|
4144 | function expInOut(t) {
|
4145 | return ((t *= 2) <= 1 ? Math.pow(2, 10 * t - 10) : 2 - Math.pow(2, 10 - 10 * t)) / 2;
|
4146 | }
|
4147 |
|
4148 | function circleIn(t) {
|
4149 | return 1 - Math.sqrt(1 - t * t);
|
4150 | }
|
4151 |
|
4152 | function circleOut(t) {
|
4153 | return Math.sqrt(1 - --t * t);
|
4154 | }
|
4155 |
|
4156 | function circleInOut(t) {
|
4157 | return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2;
|
4158 | }
|
4159 |
|
4160 | var b1 = 4 / 11,
|
4161 | b2 = 6 / 11,
|
4162 | b3 = 8 / 11,
|
4163 | b4 = 3 / 4,
|
4164 | b5 = 9 / 11,
|
4165 | b6 = 10 / 11,
|
4166 | b7 = 15 / 16,
|
4167 | b8 = 21 / 22,
|
4168 | b9 = 63 / 64,
|
4169 | b0 = 1 / b1 / b1;
|
4170 |
|
4171 | function bounceIn(t) {
|
4172 | return 1 - bounceOut(1 - t);
|
4173 | }
|
4174 |
|
4175 | function bounceOut(t) {
|
4176 | 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;
|
4177 | }
|
4178 |
|
4179 | function bounceInOut(t) {
|
4180 | return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2;
|
4181 | }
|
4182 |
|
4183 | var overshoot = 1.70158;
|
4184 |
|
4185 | var backIn = (function custom(s) {
|
4186 | s = +s;
|
4187 |
|
4188 | function backIn(t) {
|
4189 | return t * t * ((s + 1) * t - s);
|
4190 | }
|
4191 |
|
4192 | backIn.overshoot = custom;
|
4193 |
|
4194 | return backIn;
|
4195 | })(overshoot);
|
4196 |
|
4197 | var backOut = (function custom(s) {
|
4198 | s = +s;
|
4199 |
|
4200 | function backOut(t) {
|
4201 | return --t * t * ((s + 1) * t + s) + 1;
|
4202 | }
|
4203 |
|
4204 | backOut.overshoot = custom;
|
4205 |
|
4206 | return backOut;
|
4207 | })(overshoot);
|
4208 |
|
4209 | var backInOut = (function custom(s) {
|
4210 | s = +s;
|
4211 |
|
4212 | function backInOut(t) {
|
4213 | return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2;
|
4214 | }
|
4215 |
|
4216 | backInOut.overshoot = custom;
|
4217 |
|
4218 | return backInOut;
|
4219 | })(overshoot);
|
4220 |
|
4221 | var tau = 2 * Math.PI,
|
4222 | amplitude = 1,
|
4223 | period = 0.3;
|
4224 |
|
4225 | var elasticIn = (function custom(a, p) {
|
4226 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
|
4227 |
|
4228 | function elasticIn(t) {
|
4229 | return a * Math.pow(2, 10 * --t) * Math.sin((s - t) / p);
|
4230 | }
|
4231 |
|
4232 | elasticIn.amplitude = function(a) { return custom(a, p * tau); };
|
4233 | elasticIn.period = function(p) { return custom(a, p); };
|
4234 |
|
4235 | return elasticIn;
|
4236 | })(amplitude, period);
|
4237 |
|
4238 | var elasticOut = (function custom(a, p) {
|
4239 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
|
4240 |
|
4241 | function elasticOut(t) {
|
4242 | return 1 - a * Math.pow(2, -10 * (t = +t)) * Math.sin((t + s) / p);
|
4243 | }
|
4244 |
|
4245 | elasticOut.amplitude = function(a) { return custom(a, p * tau); };
|
4246 | elasticOut.period = function(p) { return custom(a, p); };
|
4247 |
|
4248 | return elasticOut;
|
4249 | })(amplitude, period);
|
4250 |
|
4251 | var elasticInOut = (function custom(a, p) {
|
4252 | var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau);
|
4253 |
|
4254 | function elasticInOut(t) {
|
4255 | return ((t = t * 2 - 1) < 0
|
4256 | ? a * Math.pow(2, 10 * t) * Math.sin((s - t) / p)
|
4257 | : 2 - a * Math.pow(2, -10 * t) * Math.sin((s + t) / p)) / 2;
|
4258 | }
|
4259 |
|
4260 | elasticInOut.amplitude = function(a) { return custom(a, p * tau); };
|
4261 | elasticInOut.period = function(p) { return custom(a, p); };
|
4262 |
|
4263 | return elasticInOut;
|
4264 | })(amplitude, period);
|
4265 |
|
4266 | var defaultTiming = {
|
4267 | time: null,
|
4268 | delay: 0,
|
4269 | duration: 250,
|
4270 | ease: cubicInOut
|
4271 | };
|
4272 |
|
4273 | function inherit(node, id) {
|
4274 | var timing;
|
4275 | while (!(timing = node.__transition) || !(timing = timing[id])) {
|
4276 | if (!(node = node.parentNode)) {
|
4277 | return defaultTiming.time = now(), defaultTiming;
|
4278 | }
|
4279 | }
|
4280 | return timing;
|
4281 | }
|
4282 |
|
4283 | function selection_transition(name) {
|
4284 | var id,
|
4285 | timing;
|
4286 |
|
4287 | if (name instanceof Transition) {
|
4288 | id = name._id, name = name._name;
|
4289 | } else {
|
4290 | id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + "";
|
4291 | }
|
4292 |
|
4293 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
4294 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
4295 | if (node = group[i]) {
|
4296 | schedule(node, name, id, i, group, timing || inherit(node, id));
|
4297 | }
|
4298 | }
|
4299 | }
|
4300 |
|
4301 | return new Transition(groups, this._parents, name, id);
|
4302 | }
|
4303 |
|
4304 | selection.prototype.interrupt = selection_interrupt;
|
4305 | selection.prototype.transition = selection_transition;
|
4306 |
|
4307 | var root$1 = [null];
|
4308 |
|
4309 | function active(node, name) {
|
4310 | var schedules = node.__transition,
|
4311 | schedule,
|
4312 | i;
|
4313 |
|
4314 | if (schedules) {
|
4315 | name = name == null ? null : name + "";
|
4316 | for (i in schedules) {
|
4317 | if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
|
4318 | return new Transition([[node]], root$1, name, +i);
|
4319 | }
|
4320 | }
|
4321 | }
|
4322 |
|
4323 | return null;
|
4324 | }
|
4325 |
|
4326 | function constant$4(x) {
|
4327 | return function() {
|
4328 | return x;
|
4329 | };
|
4330 | }
|
4331 |
|
4332 | function BrushEvent(target, type, selection) {
|
4333 | this.target = target;
|
4334 | this.type = type;
|
4335 | this.selection = selection;
|
4336 | }
|
4337 |
|
4338 | function nopropagation$1() {
|
4339 | exports.event.stopImmediatePropagation();
|
4340 | }
|
4341 |
|
4342 | function noevent$1() {
|
4343 | exports.event.preventDefault();
|
4344 | exports.event.stopImmediatePropagation();
|
4345 | }
|
4346 |
|
4347 | var MODE_DRAG = {name: "drag"},
|
4348 | MODE_SPACE = {name: "space"},
|
4349 | MODE_HANDLE = {name: "handle"},
|
4350 | MODE_CENTER = {name: "center"};
|
4351 |
|
4352 | function number1(e) {
|
4353 | return [+e[0], +e[1]];
|
4354 | }
|
4355 |
|
4356 | function number2(e) {
|
4357 | return [number1(e[0]), number1(e[1])];
|
4358 | }
|
4359 |
|
4360 | function toucher(identifier) {
|
4361 | return function(target) {
|
4362 | return touch(target, exports.event.touches, identifier);
|
4363 | };
|
4364 | }
|
4365 |
|
4366 | var X = {
|
4367 | name: "x",
|
4368 | handles: ["w", "e"].map(type),
|
4369 | input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; },
|
4370 | output: function(xy) { return xy && [xy[0][0], xy[1][0]]; }
|
4371 | };
|
4372 |
|
4373 | var Y = {
|
4374 | name: "y",
|
4375 | handles: ["n", "s"].map(type),
|
4376 | input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; },
|
4377 | output: function(xy) { return xy && [xy[0][1], xy[1][1]]; }
|
4378 | };
|
4379 |
|
4380 | var XY = {
|
4381 | name: "xy",
|
4382 | handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type),
|
4383 | input: function(xy) { return xy == null ? null : number2(xy); },
|
4384 | output: function(xy) { return xy; }
|
4385 | };
|
4386 |
|
4387 | var cursors = {
|
4388 | overlay: "crosshair",
|
4389 | selection: "move",
|
4390 | n: "ns-resize",
|
4391 | e: "ew-resize",
|
4392 | s: "ns-resize",
|
4393 | w: "ew-resize",
|
4394 | nw: "nwse-resize",
|
4395 | ne: "nesw-resize",
|
4396 | se: "nwse-resize",
|
4397 | sw: "nesw-resize"
|
4398 | };
|
4399 |
|
4400 | var flipX = {
|
4401 | e: "w",
|
4402 | w: "e",
|
4403 | nw: "ne",
|
4404 | ne: "nw",
|
4405 | se: "sw",
|
4406 | sw: "se"
|
4407 | };
|
4408 |
|
4409 | var flipY = {
|
4410 | n: "s",
|
4411 | s: "n",
|
4412 | nw: "sw",
|
4413 | ne: "se",
|
4414 | se: "ne",
|
4415 | sw: "nw"
|
4416 | };
|
4417 |
|
4418 | var signsX = {
|
4419 | overlay: +1,
|
4420 | selection: +1,
|
4421 | n: null,
|
4422 | e: +1,
|
4423 | s: null,
|
4424 | w: -1,
|
4425 | nw: -1,
|
4426 | ne: +1,
|
4427 | se: +1,
|
4428 | sw: -1
|
4429 | };
|
4430 |
|
4431 | var signsY = {
|
4432 | overlay: +1,
|
4433 | selection: +1,
|
4434 | n: -1,
|
4435 | e: null,
|
4436 | s: +1,
|
4437 | w: null,
|
4438 | nw: -1,
|
4439 | ne: -1,
|
4440 | se: +1,
|
4441 | sw: +1
|
4442 | };
|
4443 |
|
4444 | function type(t) {
|
4445 | return {type: t};
|
4446 | }
|
4447 |
|
4448 |
|
4449 | function defaultFilter$1() {
|
4450 | return !exports.event.ctrlKey && !exports.event.button;
|
4451 | }
|
4452 |
|
4453 | function defaultExtent() {
|
4454 | var svg = this.ownerSVGElement || this;
|
4455 | if (svg.hasAttribute("viewBox")) {
|
4456 | svg = svg.viewBox.baseVal;
|
4457 | return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]];
|
4458 | }
|
4459 | return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]];
|
4460 | }
|
4461 |
|
4462 | function defaultTouchable$1() {
|
4463 | return navigator.maxTouchPoints || ("ontouchstart" in this);
|
4464 | }
|
4465 |
|
4466 |
|
4467 | function local$1(node) {
|
4468 | while (!node.__brush) if (!(node = node.parentNode)) return;
|
4469 | return node.__brush;
|
4470 | }
|
4471 |
|
4472 | function empty$1(extent) {
|
4473 | return extent[0][0] === extent[1][0]
|
4474 | || extent[0][1] === extent[1][1];
|
4475 | }
|
4476 |
|
4477 | function brushSelection(node) {
|
4478 | var state = node.__brush;
|
4479 | return state ? state.dim.output(state.selection) : null;
|
4480 | }
|
4481 |
|
4482 | function brushX() {
|
4483 | return brush$1(X);
|
4484 | }
|
4485 |
|
4486 | function brushY() {
|
4487 | return brush$1(Y);
|
4488 | }
|
4489 |
|
4490 | function brush() {
|
4491 | return brush$1(XY);
|
4492 | }
|
4493 |
|
4494 | function brush$1(dim) {
|
4495 | var extent = defaultExtent,
|
4496 | filter = defaultFilter$1,
|
4497 | touchable = defaultTouchable$1,
|
4498 | keys = true,
|
4499 | listeners = dispatch("start", "brush", "end"),
|
4500 | handleSize = 6,
|
4501 | touchending;
|
4502 |
|
4503 | function brush(group) {
|
4504 | var overlay = group
|
4505 | .property("__brush", initialize)
|
4506 | .selectAll(".overlay")
|
4507 | .data([type("overlay")]);
|
4508 |
|
4509 | overlay.enter().append("rect")
|
4510 | .attr("class", "overlay")
|
4511 | .attr("pointer-events", "all")
|
4512 | .attr("cursor", cursors.overlay)
|
4513 | .merge(overlay)
|
4514 | .each(function() {
|
4515 | var extent = local$1(this).extent;
|
4516 | select(this)
|
4517 | .attr("x", extent[0][0])
|
4518 | .attr("y", extent[0][1])
|
4519 | .attr("width", extent[1][0] - extent[0][0])
|
4520 | .attr("height", extent[1][1] - extent[0][1]);
|
4521 | });
|
4522 |
|
4523 | group.selectAll(".selection")
|
4524 | .data([type("selection")])
|
4525 | .enter().append("rect")
|
4526 | .attr("class", "selection")
|
4527 | .attr("cursor", cursors.selection)
|
4528 | .attr("fill", "#777")
|
4529 | .attr("fill-opacity", 0.3)
|
4530 | .attr("stroke", "#fff")
|
4531 | .attr("shape-rendering", "crispEdges");
|
4532 |
|
4533 | var handle = group.selectAll(".handle")
|
4534 | .data(dim.handles, function(d) { return d.type; });
|
4535 |
|
4536 | handle.exit().remove();
|
4537 |
|
4538 | handle.enter().append("rect")
|
4539 | .attr("class", function(d) { return "handle handle--" + d.type; })
|
4540 | .attr("cursor", function(d) { return cursors[d.type]; });
|
4541 |
|
4542 | group
|
4543 | .each(redraw)
|
4544 | .attr("fill", "none")
|
4545 | .attr("pointer-events", "all")
|
4546 | .on("mousedown.brush", started)
|
4547 | .filter(touchable)
|
4548 | .on("touchstart.brush", started)
|
4549 | .on("touchmove.brush", touchmoved)
|
4550 | .on("touchend.brush touchcancel.brush", touchended)
|
4551 | .style("touch-action", "none")
|
4552 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
4553 | }
|
4554 |
|
4555 | brush.move = function(group, selection) {
|
4556 | if (group.selection) {
|
4557 | group
|
4558 | .on("start.brush", function() { emitter(this, arguments).beforestart().start(); })
|
4559 | .on("interrupt.brush end.brush", function() { emitter(this, arguments).end(); })
|
4560 | .tween("brush", function() {
|
4561 | var that = this,
|
4562 | state = that.__brush,
|
4563 | emit = emitter(that, arguments),
|
4564 | selection0 = state.selection,
|
4565 | selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent),
|
4566 | i = interpolateValue(selection0, selection1);
|
4567 |
|
4568 | function tween(t) {
|
4569 | state.selection = t === 1 && selection1 === null ? null : i(t);
|
4570 | redraw.call(that);
|
4571 | emit.brush();
|
4572 | }
|
4573 |
|
4574 | return selection0 !== null && selection1 !== null ? tween : tween(1);
|
4575 | });
|
4576 | } else {
|
4577 | group
|
4578 | .each(function() {
|
4579 | var that = this,
|
4580 | args = arguments,
|
4581 | state = that.__brush,
|
4582 | selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent),
|
4583 | emit = emitter(that, args).beforestart();
|
4584 |
|
4585 | interrupt(that);
|
4586 | state.selection = selection1 === null ? null : selection1;
|
4587 | redraw.call(that);
|
4588 | emit.start().brush().end();
|
4589 | });
|
4590 | }
|
4591 | };
|
4592 |
|
4593 | brush.clear = function(group) {
|
4594 | brush.move(group, null);
|
4595 | };
|
4596 |
|
4597 | function redraw() {
|
4598 | var group = select(this),
|
4599 | selection = local$1(this).selection;
|
4600 |
|
4601 | if (selection) {
|
4602 | group.selectAll(".selection")
|
4603 | .style("display", null)
|
4604 | .attr("x", selection[0][0])
|
4605 | .attr("y", selection[0][1])
|
4606 | .attr("width", selection[1][0] - selection[0][0])
|
4607 | .attr("height", selection[1][1] - selection[0][1]);
|
4608 |
|
4609 | group.selectAll(".handle")
|
4610 | .style("display", null)
|
4611 | .attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; })
|
4612 | .attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; })
|
4613 | .attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; })
|
4614 | .attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; });
|
4615 | }
|
4616 |
|
4617 | else {
|
4618 | group.selectAll(".selection,.handle")
|
4619 | .style("display", "none")
|
4620 | .attr("x", null)
|
4621 | .attr("y", null)
|
4622 | .attr("width", null)
|
4623 | .attr("height", null);
|
4624 | }
|
4625 | }
|
4626 |
|
4627 | function emitter(that, args, clean) {
|
4628 | return (!clean && that.__brush.emitter) || new Emitter(that, args);
|
4629 | }
|
4630 |
|
4631 | function Emitter(that, args) {
|
4632 | this.that = that;
|
4633 | this.args = args;
|
4634 | this.state = that.__brush;
|
4635 | this.active = 0;
|
4636 | }
|
4637 |
|
4638 | Emitter.prototype = {
|
4639 | beforestart: function() {
|
4640 | if (++this.active === 1) this.state.emitter = this, this.starting = true;
|
4641 | return this;
|
4642 | },
|
4643 | start: function() {
|
4644 | if (this.starting) this.starting = false, this.emit("start");
|
4645 | else this.emit("brush");
|
4646 | return this;
|
4647 | },
|
4648 | brush: function() {
|
4649 | this.emit("brush");
|
4650 | return this;
|
4651 | },
|
4652 | end: function() {
|
4653 | if (--this.active === 0) delete this.state.emitter, this.emit("end");
|
4654 | return this;
|
4655 | },
|
4656 | emit: function(type) {
|
4657 | customEvent(new BrushEvent(brush, type, dim.output(this.state.selection)), listeners.apply, listeners, [type, this.that, this.args]);
|
4658 | }
|
4659 | };
|
4660 |
|
4661 | function started() {
|
4662 | if (touchending && !exports.event.touches) return;
|
4663 | if (!filter.apply(this, arguments)) return;
|
4664 |
|
4665 | var that = this,
|
4666 | type = exports.event.target.__data__.type,
|
4667 | mode = (keys && exports.event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && exports.event.altKey ? MODE_CENTER : MODE_HANDLE),
|
4668 | signX = dim === Y ? null : signsX[type],
|
4669 | signY = dim === X ? null : signsY[type],
|
4670 | state = local$1(that),
|
4671 | extent = state.extent,
|
4672 | selection = state.selection,
|
4673 | W = extent[0][0], w0, w1,
|
4674 | N = extent[0][1], n0, n1,
|
4675 | E = extent[1][0], e0, e1,
|
4676 | S = extent[1][1], s0, s1,
|
4677 | dx = 0,
|
4678 | dy = 0,
|
4679 | moving,
|
4680 | shifting = signX && signY && keys && exports.event.shiftKey,
|
4681 | lockX,
|
4682 | lockY,
|
4683 | pointer = exports.event.touches ? toucher(exports.event.changedTouches[0].identifier) : mouse,
|
4684 | point0 = pointer(that),
|
4685 | point = point0,
|
4686 | emit = emitter(that, arguments, true).beforestart();
|
4687 |
|
4688 | if (type === "overlay") {
|
4689 | if (selection) moving = true;
|
4690 | state.selection = selection = [
|
4691 | [w0 = dim === Y ? W : point0[0], n0 = dim === X ? N : point0[1]],
|
4692 | [e0 = dim === Y ? E : w0, s0 = dim === X ? S : n0]
|
4693 | ];
|
4694 | } else {
|
4695 | w0 = selection[0][0];
|
4696 | n0 = selection[0][1];
|
4697 | e0 = selection[1][0];
|
4698 | s0 = selection[1][1];
|
4699 | }
|
4700 |
|
4701 | w1 = w0;
|
4702 | n1 = n0;
|
4703 | e1 = e0;
|
4704 | s1 = s0;
|
4705 |
|
4706 | var group = select(that)
|
4707 | .attr("pointer-events", "none");
|
4708 |
|
4709 | var overlay = group.selectAll(".overlay")
|
4710 | .attr("cursor", cursors[type]);
|
4711 |
|
4712 | if (exports.event.touches) {
|
4713 | emit.moved = moved;
|
4714 | emit.ended = ended;
|
4715 | } else {
|
4716 | var view = select(exports.event.view)
|
4717 | .on("mousemove.brush", moved, true)
|
4718 | .on("mouseup.brush", ended, true);
|
4719 | if (keys) view
|
4720 | .on("keydown.brush", keydowned, true)
|
4721 | .on("keyup.brush", keyupped, true);
|
4722 |
|
4723 | dragDisable(exports.event.view);
|
4724 | }
|
4725 |
|
4726 | nopropagation$1();
|
4727 | interrupt(that);
|
4728 | redraw.call(that);
|
4729 | emit.start();
|
4730 |
|
4731 | function moved() {
|
4732 | var point1 = pointer(that);
|
4733 | if (shifting && !lockX && !lockY) {
|
4734 | if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
|
4735 | else lockX = true;
|
4736 | }
|
4737 | point = point1;
|
4738 | moving = true;
|
4739 | noevent$1();
|
4740 | move();
|
4741 | }
|
4742 |
|
4743 | function move() {
|
4744 | var t;
|
4745 |
|
4746 | dx = point[0] - point0[0];
|
4747 | dy = point[1] - point0[1];
|
4748 |
|
4749 | switch (mode) {
|
4750 | case MODE_SPACE:
|
4751 | case MODE_DRAG: {
|
4752 | if (signX) dx = Math.max(W - w0, Math.min(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx;
|
4753 | if (signY) dy = Math.max(N - n0, Math.min(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy;
|
4754 | break;
|
4755 | }
|
4756 | case MODE_HANDLE: {
|
4757 | if (signX < 0) dx = Math.max(W - w0, Math.min(E - w0, dx)), w1 = w0 + dx, e1 = e0;
|
4758 | else if (signX > 0) dx = Math.max(W - e0, Math.min(E - e0, dx)), w1 = w0, e1 = e0 + dx;
|
4759 | if (signY < 0) dy = Math.max(N - n0, Math.min(S - n0, dy)), n1 = n0 + dy, s1 = s0;
|
4760 | else if (signY > 0) dy = Math.max(N - s0, Math.min(S - s0, dy)), n1 = n0, s1 = s0 + dy;
|
4761 | break;
|
4762 | }
|
4763 | case MODE_CENTER: {
|
4764 | if (signX) w1 = Math.max(W, Math.min(E, w0 - dx * signX)), e1 = Math.max(W, Math.min(E, e0 + dx * signX));
|
4765 | if (signY) n1 = Math.max(N, Math.min(S, n0 - dy * signY)), s1 = Math.max(N, Math.min(S, s0 + dy * signY));
|
4766 | break;
|
4767 | }
|
4768 | }
|
4769 |
|
4770 | if (e1 < w1) {
|
4771 | signX *= -1;
|
4772 | t = w0, w0 = e0, e0 = t;
|
4773 | t = w1, w1 = e1, e1 = t;
|
4774 | if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]);
|
4775 | }
|
4776 |
|
4777 | if (s1 < n1) {
|
4778 | signY *= -1;
|
4779 | t = n0, n0 = s0, s0 = t;
|
4780 | t = n1, n1 = s1, s1 = t;
|
4781 | if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]);
|
4782 | }
|
4783 |
|
4784 | if (state.selection) selection = state.selection;
|
4785 | if (lockX) w1 = selection[0][0], e1 = selection[1][0];
|
4786 | if (lockY) n1 = selection[0][1], s1 = selection[1][1];
|
4787 |
|
4788 | if (selection[0][0] !== w1
|
4789 | || selection[0][1] !== n1
|
4790 | || selection[1][0] !== e1
|
4791 | || selection[1][1] !== s1) {
|
4792 | state.selection = [[w1, n1], [e1, s1]];
|
4793 | redraw.call(that);
|
4794 | emit.brush();
|
4795 | }
|
4796 | }
|
4797 |
|
4798 | function ended() {
|
4799 | nopropagation$1();
|
4800 | if (exports.event.touches) {
|
4801 | if (exports.event.touches.length) return;
|
4802 | if (touchending) clearTimeout(touchending);
|
4803 | touchending = setTimeout(function() { touchending = null; }, 500);
|
4804 | } else {
|
4805 | yesdrag(exports.event.view, moving);
|
4806 | view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null);
|
4807 | }
|
4808 | group.attr("pointer-events", "all");
|
4809 | overlay.attr("cursor", cursors.overlay);
|
4810 | if (state.selection) selection = state.selection;
|
4811 | if (empty$1(selection)) state.selection = null, redraw.call(that);
|
4812 | emit.end();
|
4813 | }
|
4814 |
|
4815 | function keydowned() {
|
4816 | switch (exports.event.keyCode) {
|
4817 | case 16: {
|
4818 | shifting = signX && signY;
|
4819 | break;
|
4820 | }
|
4821 | case 18: {
|
4822 | if (mode === MODE_HANDLE) {
|
4823 | if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
|
4824 | if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
|
4825 | mode = MODE_CENTER;
|
4826 | move();
|
4827 | }
|
4828 | break;
|
4829 | }
|
4830 | case 32: {
|
4831 | if (mode === MODE_HANDLE || mode === MODE_CENTER) {
|
4832 | if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx;
|
4833 | if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy;
|
4834 | mode = MODE_SPACE;
|
4835 | overlay.attr("cursor", cursors.selection);
|
4836 | move();
|
4837 | }
|
4838 | break;
|
4839 | }
|
4840 | default: return;
|
4841 | }
|
4842 | noevent$1();
|
4843 | }
|
4844 |
|
4845 | function keyupped() {
|
4846 | switch (exports.event.keyCode) {
|
4847 | case 16: {
|
4848 | if (shifting) {
|
4849 | lockX = lockY = shifting = false;
|
4850 | move();
|
4851 | }
|
4852 | break;
|
4853 | }
|
4854 | case 18: {
|
4855 | if (mode === MODE_CENTER) {
|
4856 | if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
|
4857 | if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
|
4858 | mode = MODE_HANDLE;
|
4859 | move();
|
4860 | }
|
4861 | break;
|
4862 | }
|
4863 | case 32: {
|
4864 | if (mode === MODE_SPACE) {
|
4865 | if (exports.event.altKey) {
|
4866 | if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX;
|
4867 | if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY;
|
4868 | mode = MODE_CENTER;
|
4869 | } else {
|
4870 | if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1;
|
4871 | if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1;
|
4872 | mode = MODE_HANDLE;
|
4873 | }
|
4874 | overlay.attr("cursor", cursors[type]);
|
4875 | move();
|
4876 | }
|
4877 | break;
|
4878 | }
|
4879 | default: return;
|
4880 | }
|
4881 | noevent$1();
|
4882 | }
|
4883 | }
|
4884 |
|
4885 | function touchmoved() {
|
4886 | emitter(this, arguments).moved();
|
4887 | }
|
4888 |
|
4889 | function touchended() {
|
4890 | emitter(this, arguments).ended();
|
4891 | }
|
4892 |
|
4893 | function initialize() {
|
4894 | var state = this.__brush || {selection: null};
|
4895 | state.extent = number2(extent.apply(this, arguments));
|
4896 | state.dim = dim;
|
4897 | return state;
|
4898 | }
|
4899 |
|
4900 | brush.extent = function(_) {
|
4901 | return arguments.length ? (extent = typeof _ === "function" ? _ : constant$4(number2(_)), brush) : extent;
|
4902 | };
|
4903 |
|
4904 | brush.filter = function(_) {
|
4905 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$4(!!_), brush) : filter;
|
4906 | };
|
4907 |
|
4908 | brush.touchable = function(_) {
|
4909 | return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$4(!!_), brush) : touchable;
|
4910 | };
|
4911 |
|
4912 | brush.handleSize = function(_) {
|
4913 | return arguments.length ? (handleSize = +_, brush) : handleSize;
|
4914 | };
|
4915 |
|
4916 | brush.keyModifiers = function(_) {
|
4917 | return arguments.length ? (keys = !!_, brush) : keys;
|
4918 | };
|
4919 |
|
4920 | brush.on = function() {
|
4921 | var value = listeners.on.apply(listeners, arguments);
|
4922 | return value === listeners ? brush : value;
|
4923 | };
|
4924 |
|
4925 | return brush;
|
4926 | }
|
4927 |
|
4928 | var cos = Math.cos;
|
4929 | var sin = Math.sin;
|
4930 | var pi$1 = Math.PI;
|
4931 | var halfPi$1 = pi$1 / 2;
|
4932 | var tau$1 = pi$1 * 2;
|
4933 | var max$1 = Math.max;
|
4934 |
|
4935 | function compareValue(compare) {
|
4936 | return function(a, b) {
|
4937 | return compare(
|
4938 | a.source.value + a.target.value,
|
4939 | b.source.value + b.target.value
|
4940 | );
|
4941 | };
|
4942 | }
|
4943 |
|
4944 | function chord() {
|
4945 | var padAngle = 0,
|
4946 | sortGroups = null,
|
4947 | sortSubgroups = null,
|
4948 | sortChords = null;
|
4949 |
|
4950 | function chord(matrix) {
|
4951 | var n = matrix.length,
|
4952 | groupSums = [],
|
4953 | groupIndex = sequence(n),
|
4954 | subgroupIndex = [],
|
4955 | chords = [],
|
4956 | groups = chords.groups = new Array(n),
|
4957 | subgroups = new Array(n * n),
|
4958 | k,
|
4959 | x,
|
4960 | x0,
|
4961 | dx,
|
4962 | i,
|
4963 | j;
|
4964 |
|
4965 |
|
4966 | k = 0, i = -1; while (++i < n) {
|
4967 | x = 0, j = -1; while (++j < n) {
|
4968 | x += matrix[i][j];
|
4969 | }
|
4970 | groupSums.push(x);
|
4971 | subgroupIndex.push(sequence(n));
|
4972 | k += x;
|
4973 | }
|
4974 |
|
4975 |
|
4976 | if (sortGroups) groupIndex.sort(function(a, b) {
|
4977 | return sortGroups(groupSums[a], groupSums[b]);
|
4978 | });
|
4979 |
|
4980 |
|
4981 | if (sortSubgroups) subgroupIndex.forEach(function(d, i) {
|
4982 | d.sort(function(a, b) {
|
4983 | return sortSubgroups(matrix[i][a], matrix[i][b]);
|
4984 | });
|
4985 | });
|
4986 |
|
4987 |
|
4988 |
|
4989 |
|
4990 | k = max$1(0, tau$1 - padAngle * n) / k;
|
4991 | dx = k ? padAngle : tau$1 / n;
|
4992 |
|
4993 |
|
4994 |
|
4995 | x = 0, i = -1; while (++i < n) {
|
4996 | x0 = x, j = -1; while (++j < n) {
|
4997 | var di = groupIndex[i],
|
4998 | dj = subgroupIndex[di][j],
|
4999 | v = matrix[di][dj],
|
5000 | a0 = x,
|
5001 | a1 = x += v * k;
|
5002 | subgroups[dj * n + di] = {
|
5003 | index: di,
|
5004 | subindex: dj,
|
5005 | startAngle: a0,
|
5006 | endAngle: a1,
|
5007 | value: v
|
5008 | };
|
5009 | }
|
5010 | groups[di] = {
|
5011 | index: di,
|
5012 | startAngle: x0,
|
5013 | endAngle: x,
|
5014 | value: groupSums[di]
|
5015 | };
|
5016 | x += dx;
|
5017 | }
|
5018 |
|
5019 |
|
5020 | i = -1; while (++i < n) {
|
5021 | j = i - 1; while (++j < n) {
|
5022 | var source = subgroups[j * n + i],
|
5023 | target = subgroups[i * n + j];
|
5024 | if (source.value || target.value) {
|
5025 | chords.push(source.value < target.value
|
5026 | ? {source: target, target: source}
|
5027 | : {source: source, target: target});
|
5028 | }
|
5029 | }
|
5030 | }
|
5031 |
|
5032 | return sortChords ? chords.sort(sortChords) : chords;
|
5033 | }
|
5034 |
|
5035 | chord.padAngle = function(_) {
|
5036 | return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle;
|
5037 | };
|
5038 |
|
5039 | chord.sortGroups = function(_) {
|
5040 | return arguments.length ? (sortGroups = _, chord) : sortGroups;
|
5041 | };
|
5042 |
|
5043 | chord.sortSubgroups = function(_) {
|
5044 | return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups;
|
5045 | };
|
5046 |
|
5047 | chord.sortChords = function(_) {
|
5048 | return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._;
|
5049 | };
|
5050 |
|
5051 | return chord;
|
5052 | }
|
5053 |
|
5054 | var slice$2 = Array.prototype.slice;
|
5055 |
|
5056 | function constant$5(x) {
|
5057 | return function() {
|
5058 | return x;
|
5059 | };
|
5060 | }
|
5061 |
|
5062 | var pi$2 = Math.PI,
|
5063 | tau$2 = 2 * pi$2,
|
5064 | epsilon$1 = 1e-6,
|
5065 | tauEpsilon = tau$2 - epsilon$1;
|
5066 |
|
5067 | function Path() {
|
5068 | this._x0 = this._y0 =
|
5069 | this._x1 = this._y1 = null;
|
5070 | this._ = "";
|
5071 | }
|
5072 |
|
5073 | function path() {
|
5074 | return new Path;
|
5075 | }
|
5076 |
|
5077 | Path.prototype = path.prototype = {
|
5078 | constructor: Path,
|
5079 | moveTo: function(x, y) {
|
5080 | this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y);
|
5081 | },
|
5082 | closePath: function() {
|
5083 | if (this._x1 !== null) {
|
5084 | this._x1 = this._x0, this._y1 = this._y0;
|
5085 | this._ += "Z";
|
5086 | }
|
5087 | },
|
5088 | lineTo: function(x, y) {
|
5089 | this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y);
|
5090 | },
|
5091 | quadraticCurveTo: function(x1, y1, x, y) {
|
5092 | this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
5093 | },
|
5094 | bezierCurveTo: function(x1, y1, x2, y2, x, y) {
|
5095 | this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y);
|
5096 | },
|
5097 | arcTo: function(x1, y1, x2, y2, r) {
|
5098 | x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
|
5099 | var x0 = this._x1,
|
5100 | y0 = this._y1,
|
5101 | x21 = x2 - x1,
|
5102 | y21 = y2 - y1,
|
5103 | x01 = x0 - x1,
|
5104 | y01 = y0 - y1,
|
5105 | l01_2 = x01 * x01 + y01 * y01;
|
5106 |
|
5107 |
|
5108 | if (r < 0) throw new Error("negative radius: " + r);
|
5109 |
|
5110 |
|
5111 | if (this._x1 === null) {
|
5112 | this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1);
|
5113 | }
|
5114 |
|
5115 |
|
5116 | else if (!(l01_2 > epsilon$1));
|
5117 |
|
5118 |
|
5119 |
|
5120 |
|
5121 | else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$1) || !r) {
|
5122 | this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1);
|
5123 | }
|
5124 |
|
5125 |
|
5126 | else {
|
5127 | var x20 = x2 - x0,
|
5128 | y20 = y2 - y0,
|
5129 | l21_2 = x21 * x21 + y21 * y21,
|
5130 | l20_2 = x20 * x20 + y20 * y20,
|
5131 | l21 = Math.sqrt(l21_2),
|
5132 | l01 = Math.sqrt(l01_2),
|
5133 | l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
|
5134 | t01 = l / l01,
|
5135 | t21 = l / l21;
|
5136 |
|
5137 |
|
5138 | if (Math.abs(t01 - 1) > epsilon$1) {
|
5139 | this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01);
|
5140 | }
|
5141 |
|
5142 | this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21);
|
5143 | }
|
5144 | },
|
5145 | arc: function(x, y, r, a0, a1, ccw) {
|
5146 | x = +x, y = +y, r = +r, ccw = !!ccw;
|
5147 | var dx = r * Math.cos(a0),
|
5148 | dy = r * Math.sin(a0),
|
5149 | x0 = x + dx,
|
5150 | y0 = y + dy,
|
5151 | cw = 1 ^ ccw,
|
5152 | da = ccw ? a0 - a1 : a1 - a0;
|
5153 |
|
5154 |
|
5155 | if (r < 0) throw new Error("negative radius: " + r);
|
5156 |
|
5157 |
|
5158 | if (this._x1 === null) {
|
5159 | this._ += "M" + x0 + "," + y0;
|
5160 | }
|
5161 |
|
5162 |
|
5163 | else if (Math.abs(this._x1 - x0) > epsilon$1 || Math.abs(this._y1 - y0) > epsilon$1) {
|
5164 | this._ += "L" + x0 + "," + y0;
|
5165 | }
|
5166 |
|
5167 |
|
5168 | if (!r) return;
|
5169 |
|
5170 |
|
5171 | if (da < 0) da = da % tau$2 + tau$2;
|
5172 |
|
5173 |
|
5174 | if (da > tauEpsilon) {
|
5175 | this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0);
|
5176 | }
|
5177 |
|
5178 |
|
5179 | else if (da > epsilon$1) {
|
5180 | this._ += "A" + r + "," + r + ",0," + (+(da >= pi$2)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1));
|
5181 | }
|
5182 | },
|
5183 | rect: function(x, y, w, h) {
|
5184 | this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z";
|
5185 | },
|
5186 | toString: function() {
|
5187 | return this._;
|
5188 | }
|
5189 | };
|
5190 |
|
5191 | function defaultSource(d) {
|
5192 | return d.source;
|
5193 | }
|
5194 |
|
5195 | function defaultTarget(d) {
|
5196 | return d.target;
|
5197 | }
|
5198 |
|
5199 | function defaultRadius(d) {
|
5200 | return d.radius;
|
5201 | }
|
5202 |
|
5203 | function defaultStartAngle(d) {
|
5204 | return d.startAngle;
|
5205 | }
|
5206 |
|
5207 | function defaultEndAngle(d) {
|
5208 | return d.endAngle;
|
5209 | }
|
5210 |
|
5211 | function ribbon() {
|
5212 | var source = defaultSource,
|
5213 | target = defaultTarget,
|
5214 | radius = defaultRadius,
|
5215 | startAngle = defaultStartAngle,
|
5216 | endAngle = defaultEndAngle,
|
5217 | context = null;
|
5218 |
|
5219 | function ribbon() {
|
5220 | var buffer,
|
5221 | argv = slice$2.call(arguments),
|
5222 | s = source.apply(this, argv),
|
5223 | t = target.apply(this, argv),
|
5224 | sr = +radius.apply(this, (argv[0] = s, argv)),
|
5225 | sa0 = startAngle.apply(this, argv) - halfPi$1,
|
5226 | sa1 = endAngle.apply(this, argv) - halfPi$1,
|
5227 | sx0 = sr * cos(sa0),
|
5228 | sy0 = sr * sin(sa0),
|
5229 | tr = +radius.apply(this, (argv[0] = t, argv)),
|
5230 | ta0 = startAngle.apply(this, argv) - halfPi$1,
|
5231 | ta1 = endAngle.apply(this, argv) - halfPi$1;
|
5232 |
|
5233 | if (!context) context = buffer = path();
|
5234 |
|
5235 | context.moveTo(sx0, sy0);
|
5236 | context.arc(0, 0, sr, sa0, sa1);
|
5237 | if (sa0 !== ta0 || sa1 !== ta1) {
|
5238 | context.quadraticCurveTo(0, 0, tr * cos(ta0), tr * sin(ta0));
|
5239 | context.arc(0, 0, tr, ta0, ta1);
|
5240 | }
|
5241 | context.quadraticCurveTo(0, 0, sx0, sy0);
|
5242 | context.closePath();
|
5243 |
|
5244 | if (buffer) return context = null, buffer + "" || null;
|
5245 | }
|
5246 |
|
5247 | ribbon.radius = function(_) {
|
5248 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$5(+_), ribbon) : radius;
|
5249 | };
|
5250 |
|
5251 | ribbon.startAngle = function(_) {
|
5252 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : startAngle;
|
5253 | };
|
5254 |
|
5255 | ribbon.endAngle = function(_) {
|
5256 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$5(+_), ribbon) : endAngle;
|
5257 | };
|
5258 |
|
5259 | ribbon.source = function(_) {
|
5260 | return arguments.length ? (source = _, ribbon) : source;
|
5261 | };
|
5262 |
|
5263 | ribbon.target = function(_) {
|
5264 | return arguments.length ? (target = _, ribbon) : target;
|
5265 | };
|
5266 |
|
5267 | ribbon.context = function(_) {
|
5268 | return arguments.length ? ((context = _ == null ? null : _), ribbon) : context;
|
5269 | };
|
5270 |
|
5271 | return ribbon;
|
5272 | }
|
5273 |
|
5274 | var prefix = "$";
|
5275 |
|
5276 | function Map() {}
|
5277 |
|
5278 | Map.prototype = map$1.prototype = {
|
5279 | constructor: Map,
|
5280 | has: function(key) {
|
5281 | return (prefix + key) in this;
|
5282 | },
|
5283 | get: function(key) {
|
5284 | return this[prefix + key];
|
5285 | },
|
5286 | set: function(key, value) {
|
5287 | this[prefix + key] = value;
|
5288 | return this;
|
5289 | },
|
5290 | remove: function(key) {
|
5291 | var property = prefix + key;
|
5292 | return property in this && delete this[property];
|
5293 | },
|
5294 | clear: function() {
|
5295 | for (var property in this) if (property[0] === prefix) delete this[property];
|
5296 | },
|
5297 | keys: function() {
|
5298 | var keys = [];
|
5299 | for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
|
5300 | return keys;
|
5301 | },
|
5302 | values: function() {
|
5303 | var values = [];
|
5304 | for (var property in this) if (property[0] === prefix) values.push(this[property]);
|
5305 | return values;
|
5306 | },
|
5307 | entries: function() {
|
5308 | var entries = [];
|
5309 | for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
|
5310 | return entries;
|
5311 | },
|
5312 | size: function() {
|
5313 | var size = 0;
|
5314 | for (var property in this) if (property[0] === prefix) ++size;
|
5315 | return size;
|
5316 | },
|
5317 | empty: function() {
|
5318 | for (var property in this) if (property[0] === prefix) return false;
|
5319 | return true;
|
5320 | },
|
5321 | each: function(f) {
|
5322 | for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
|
5323 | }
|
5324 | };
|
5325 |
|
5326 | function map$1(object, f) {
|
5327 | var map = new Map;
|
5328 |
|
5329 |
|
5330 | if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
|
5331 |
|
5332 |
|
5333 | else if (Array.isArray(object)) {
|
5334 | var i = -1,
|
5335 | n = object.length,
|
5336 | o;
|
5337 |
|
5338 | if (f == null) while (++i < n) map.set(i, object[i]);
|
5339 | else while (++i < n) map.set(f(o = object[i], i, object), o);
|
5340 | }
|
5341 |
|
5342 |
|
5343 | else if (object) for (var key in object) map.set(key, object[key]);
|
5344 |
|
5345 | return map;
|
5346 | }
|
5347 |
|
5348 | function nest() {
|
5349 | var keys = [],
|
5350 | sortKeys = [],
|
5351 | sortValues,
|
5352 | rollup,
|
5353 | nest;
|
5354 |
|
5355 | function apply(array, depth, createResult, setResult) {
|
5356 | if (depth >= keys.length) {
|
5357 | if (sortValues != null) array.sort(sortValues);
|
5358 | return rollup != null ? rollup(array) : array;
|
5359 | }
|
5360 |
|
5361 | var i = -1,
|
5362 | n = array.length,
|
5363 | key = keys[depth++],
|
5364 | keyValue,
|
5365 | value,
|
5366 | valuesByKey = map$1(),
|
5367 | values,
|
5368 | result = createResult();
|
5369 |
|
5370 | while (++i < n) {
|
5371 | if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
|
5372 | values.push(value);
|
5373 | } else {
|
5374 | valuesByKey.set(keyValue, [value]);
|
5375 | }
|
5376 | }
|
5377 |
|
5378 | valuesByKey.each(function(values, key) {
|
5379 | setResult(result, key, apply(values, depth, createResult, setResult));
|
5380 | });
|
5381 |
|
5382 | return result;
|
5383 | }
|
5384 |
|
5385 | function entries(map, depth) {
|
5386 | if (++depth > keys.length) return map;
|
5387 | var array, sortKey = sortKeys[depth - 1];
|
5388 | if (rollup != null && depth >= keys.length) array = map.entries();
|
5389 | else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
|
5390 | return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
|
5391 | }
|
5392 |
|
5393 | return nest = {
|
5394 | object: function(array) { return apply(array, 0, createObject, setObject); },
|
5395 | map: function(array) { return apply(array, 0, createMap, setMap); },
|
5396 | entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
|
5397 | key: function(d) { keys.push(d); return nest; },
|
5398 | sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
|
5399 | sortValues: function(order) { sortValues = order; return nest; },
|
5400 | rollup: function(f) { rollup = f; return nest; }
|
5401 | };
|
5402 | }
|
5403 |
|
5404 | function createObject() {
|
5405 | return {};
|
5406 | }
|
5407 |
|
5408 | function setObject(object, key, value) {
|
5409 | object[key] = value;
|
5410 | }
|
5411 |
|
5412 | function createMap() {
|
5413 | return map$1();
|
5414 | }
|
5415 |
|
5416 | function setMap(map, key, value) {
|
5417 | map.set(key, value);
|
5418 | }
|
5419 |
|
5420 | function Set() {}
|
5421 |
|
5422 | var proto = map$1.prototype;
|
5423 |
|
5424 | Set.prototype = set$2.prototype = {
|
5425 | constructor: Set,
|
5426 | has: proto.has,
|
5427 | add: function(value) {
|
5428 | value += "";
|
5429 | this[prefix + value] = value;
|
5430 | return this;
|
5431 | },
|
5432 | remove: proto.remove,
|
5433 | clear: proto.clear,
|
5434 | values: proto.keys,
|
5435 | size: proto.size,
|
5436 | empty: proto.empty,
|
5437 | each: proto.each
|
5438 | };
|
5439 |
|
5440 | function set$2(object, f) {
|
5441 | var set = new Set;
|
5442 |
|
5443 | // Copy constructor.
|
5444 | if (object instanceof Set) object.each(function(value) { set.add(value); });
|
5445 |
|
5446 | // Otherwise, assume it’s an array.
|
5447 | else if (object) {
|
5448 | var i = -1, n = object.length;
|
5449 | if (f == null) while (++i < n) set.add(object[i]);
|
5450 | else while (++i < n) set.add(f(object[i], i, object));
|
5451 | }
|
5452 |
|
5453 | return set;
|
5454 | }
|
5455 |
|
5456 | function keys(map) {
|
5457 | var keys = [];
|
5458 | for (var key in map) keys.push(key);
|
5459 | return keys;
|
5460 | }
|
5461 |
|
5462 | function values(map) {
|
5463 | var values = [];
|
5464 | for (var key in map) values.push(map[key]);
|
5465 | return values;
|
5466 | }
|
5467 |
|
5468 | function entries(map) {
|
5469 | var entries = [];
|
5470 | for (var key in map) entries.push({key: key, value: map[key]});
|
5471 | return entries;
|
5472 | }
|
5473 |
|
5474 | var array$2 = Array.prototype;
|
5475 |
|
5476 | var slice$3 = array$2.slice;
|
5477 |
|
5478 | function ascending$2(a, b) {
|
5479 | return a - b;
|
5480 | }
|
5481 |
|
5482 | function area(ring) {
|
5483 | var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
|
5484 | while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
|
5485 | return area;
|
5486 | }
|
5487 |
|
5488 | function constant$6(x) {
|
5489 | return function() {
|
5490 | return x;
|
5491 | };
|
5492 | }
|
5493 |
|
5494 | function contains(ring, hole) {
|
5495 | var i = -1, n = hole.length, c;
|
5496 | while (++i < n) if (c = ringContains(ring, hole[i])) return c;
|
5497 | return 0;
|
5498 | }
|
5499 |
|
5500 | function ringContains(ring, point) {
|
5501 | var x = point[0], y = point[1], contains = -1;
|
5502 | for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
|
5503 | var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
|
5504 | if (segmentContains(pi, pj, point)) return 0;
|
5505 | if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
|
5506 | }
|
5507 | return contains;
|
5508 | }
|
5509 |
|
5510 | function segmentContains(a, b, c) {
|
5511 | var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
|
5512 | }
|
5513 |
|
5514 | function collinear(a, b, c) {
|
5515 | return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
|
5516 | }
|
5517 |
|
5518 | function within(p, q, r) {
|
5519 | return p <= q && q <= r || r <= q && q <= p;
|
5520 | }
|
5521 |
|
5522 | function noop$1() {}
|
5523 |
|
5524 | var cases = [
|
5525 | [],
|
5526 | [[[1.0, 1.5], [0.5, 1.0]]],
|
5527 | [[[1.5, 1.0], [1.0, 1.5]]],
|
5528 | [[[1.5, 1.0], [0.5, 1.0]]],
|
5529 | [[[1.0, 0.5], [1.5, 1.0]]],
|
5530 | [[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
|
5531 | [[[1.0, 0.5], [1.0, 1.5]]],
|
5532 | [[[1.0, 0.5], [0.5, 1.0]]],
|
5533 | [[[0.5, 1.0], [1.0, 0.5]]],
|
5534 | [[[1.0, 1.5], [1.0, 0.5]]],
|
5535 | [[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
|
5536 | [[[1.5, 1.0], [1.0, 0.5]]],
|
5537 | [[[0.5, 1.0], [1.5, 1.0]]],
|
5538 | [[[1.0, 1.5], [1.5, 1.0]]],
|
5539 | [[[0.5, 1.0], [1.0, 1.5]]],
|
5540 | []
|
5541 | ];
|
5542 |
|
5543 | function contours() {
|
5544 | var dx = 1,
|
5545 | dy = 1,
|
5546 | threshold = thresholdSturges,
|
5547 | smooth = smoothLinear;
|
5548 |
|
5549 | function contours(values) {
|
5550 | var tz = threshold(values);
|
5551 |
|
5552 |
|
5553 | if (!Array.isArray(tz)) {
|
5554 | var domain = extent(values), start = domain[0], stop = domain[1];
|
5555 | tz = tickStep(start, stop, tz);
|
5556 | tz = sequence(Math.floor(start / tz) * tz, Math.floor(stop / tz) * tz, tz);
|
5557 | } else {
|
5558 | tz = tz.slice().sort(ascending$2);
|
5559 | }
|
5560 |
|
5561 | return tz.map(function(value) {
|
5562 | return contour(values, value);
|
5563 | });
|
5564 | }
|
5565 |
|
5566 |
|
5567 |
|
5568 | function contour(values, value) {
|
5569 | var polygons = [],
|
5570 | holes = [];
|
5571 |
|
5572 | isorings(values, value, function(ring) {
|
5573 | smooth(ring, values, value);
|
5574 | if (area(ring) > 0) polygons.push([ring]);
|
5575 | else holes.push(ring);
|
5576 | });
|
5577 |
|
5578 | holes.forEach(function(hole) {
|
5579 | for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
|
5580 | if (contains((polygon = polygons[i])[0], hole) !== -1) {
|
5581 | polygon.push(hole);
|
5582 | return;
|
5583 | }
|
5584 | }
|
5585 | });
|
5586 |
|
5587 | return {
|
5588 | type: "MultiPolygon",
|
5589 | value: value,
|
5590 | coordinates: polygons
|
5591 | };
|
5592 | }
|
5593 |
|
5594 |
|
5595 |
|
5596 | function isorings(values, value, callback) {
|
5597 | var fragmentByStart = new Array,
|
5598 | fragmentByEnd = new Array,
|
5599 | x, y, t0, t1, t2, t3;
|
5600 |
|
5601 |
|
5602 | x = y = -1;
|
5603 | t1 = values[0] >= value;
|
5604 | cases[t1 << 1].forEach(stitch);
|
5605 | while (++x < dx - 1) {
|
5606 | t0 = t1, t1 = values[x + 1] >= value;
|
5607 | cases[t0 | t1 << 1].forEach(stitch);
|
5608 | }
|
5609 | cases[t1 << 0].forEach(stitch);
|
5610 |
|
5611 |
|
5612 | while (++y < dy - 1) {
|
5613 | x = -1;
|
5614 | t1 = values[y * dx + dx] >= value;
|
5615 | t2 = values[y * dx] >= value;
|
5616 | cases[t1 << 1 | t2 << 2].forEach(stitch);
|
5617 | while (++x < dx - 1) {
|
5618 | t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
|
5619 | t3 = t2, t2 = values[y * dx + x + 1] >= value;
|
5620 | cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
|
5621 | }
|
5622 | cases[t1 | t2 << 3].forEach(stitch);
|
5623 | }
|
5624 |
|
5625 |
|
5626 | x = -1;
|
5627 | t2 = values[y * dx] >= value;
|
5628 | cases[t2 << 2].forEach(stitch);
|
5629 | while (++x < dx - 1) {
|
5630 | t3 = t2, t2 = values[y * dx + x + 1] >= value;
|
5631 | cases[t2 << 2 | t3 << 3].forEach(stitch);
|
5632 | }
|
5633 | cases[t2 << 3].forEach(stitch);
|
5634 |
|
5635 | function stitch(line) {
|
5636 | var start = [line[0][0] + x, line[0][1] + y],
|
5637 | end = [line[1][0] + x, line[1][1] + y],
|
5638 | startIndex = index(start),
|
5639 | endIndex = index(end),
|
5640 | f, g;
|
5641 | if (f = fragmentByEnd[startIndex]) {
|
5642 | if (g = fragmentByStart[endIndex]) {
|
5643 | delete fragmentByEnd[f.end];
|
5644 | delete fragmentByStart[g.start];
|
5645 | if (f === g) {
|
5646 | f.ring.push(end);
|
5647 | callback(f.ring);
|
5648 | } else {
|
5649 | fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
|
5650 | }
|
5651 | } else {
|
5652 | delete fragmentByEnd[f.end];
|
5653 | f.ring.push(end);
|
5654 | fragmentByEnd[f.end = endIndex] = f;
|
5655 | }
|
5656 | } else if (f = fragmentByStart[endIndex]) {
|
5657 | if (g = fragmentByEnd[startIndex]) {
|
5658 | delete fragmentByStart[f.start];
|
5659 | delete fragmentByEnd[g.end];
|
5660 | if (f === g) {
|
5661 | f.ring.push(end);
|
5662 | callback(f.ring);
|
5663 | } else {
|
5664 | fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
|
5665 | }
|
5666 | } else {
|
5667 | delete fragmentByStart[f.start];
|
5668 | f.ring.unshift(start);
|
5669 | fragmentByStart[f.start = startIndex] = f;
|
5670 | }
|
5671 | } else {
|
5672 | fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
|
5673 | }
|
5674 | }
|
5675 | }
|
5676 |
|
5677 | function index(point) {
|
5678 | return point[0] * 2 + point[1] * (dx + 1) * 4;
|
5679 | }
|
5680 |
|
5681 | function smoothLinear(ring, values, value) {
|
5682 | ring.forEach(function(point) {
|
5683 | var x = point[0],
|
5684 | y = point[1],
|
5685 | xt = x | 0,
|
5686 | yt = y | 0,
|
5687 | v0,
|
5688 | v1 = values[yt * dx + xt];
|
5689 | if (x > 0 && x < dx && xt === x) {
|
5690 | v0 = values[yt * dx + xt - 1];
|
5691 | point[0] = x + (value - v0) / (v1 - v0) - 0.5;
|
5692 | }
|
5693 | if (y > 0 && y < dy && yt === y) {
|
5694 | v0 = values[(yt - 1) * dx + xt];
|
5695 | point[1] = y + (value - v0) / (v1 - v0) - 0.5;
|
5696 | }
|
5697 | });
|
5698 | }
|
5699 |
|
5700 | contours.contour = contour;
|
5701 |
|
5702 | contours.size = function(_) {
|
5703 | if (!arguments.length) return [dx, dy];
|
5704 | var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
|
5705 | if (!(_0 > 0) || !(_1 > 0)) throw new Error("invalid size");
|
5706 | return dx = _0, dy = _1, contours;
|
5707 | };
|
5708 |
|
5709 | contours.thresholds = function(_) {
|
5710 | return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), contours) : threshold;
|
5711 | };
|
5712 |
|
5713 | contours.smooth = function(_) {
|
5714 | return arguments.length ? (smooth = _ ? smoothLinear : noop$1, contours) : smooth === smoothLinear;
|
5715 | };
|
5716 |
|
5717 | return contours;
|
5718 | }
|
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 | function blurX(source, target, r) {
|
5724 | var n = source.width,
|
5725 | m = source.height,
|
5726 | w = (r << 1) + 1;
|
5727 | for (var j = 0; j < m; ++j) {
|
5728 | for (var i = 0, sr = 0; i < n + r; ++i) {
|
5729 | if (i < n) {
|
5730 | sr += source.data[i + j * n];
|
5731 | }
|
5732 | if (i >= r) {
|
5733 | if (i >= w) {
|
5734 | sr -= source.data[i - w + j * n];
|
5735 | }
|
5736 | target.data[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
|
5737 | }
|
5738 | }
|
5739 | }
|
5740 | }
|
5741 |
|
5742 |
|
5743 |
|
5744 |
|
5745 | function blurY(source, target, r) {
|
5746 | var n = source.width,
|
5747 | m = source.height,
|
5748 | w = (r << 1) + 1;
|
5749 | for (var i = 0; i < n; ++i) {
|
5750 | for (var j = 0, sr = 0; j < m + r; ++j) {
|
5751 | if (j < m) {
|
5752 | sr += source.data[i + j * n];
|
5753 | }
|
5754 | if (j >= r) {
|
5755 | if (j >= w) {
|
5756 | sr -= source.data[i + (j - w) * n];
|
5757 | }
|
5758 | target.data[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
|
5759 | }
|
5760 | }
|
5761 | }
|
5762 | }
|
5763 |
|
5764 | function defaultX(d) {
|
5765 | return d[0];
|
5766 | }
|
5767 |
|
5768 | function defaultY(d) {
|
5769 | return d[1];
|
5770 | }
|
5771 |
|
5772 | function defaultWeight() {
|
5773 | return 1;
|
5774 | }
|
5775 |
|
5776 | function density() {
|
5777 | var x = defaultX,
|
5778 | y = defaultY,
|
5779 | weight = defaultWeight,
|
5780 | dx = 960,
|
5781 | dy = 500,
|
5782 | r = 20,
|
5783 | k = 2,
|
5784 | o = r * 3,
|
5785 | n = (dx + o * 2) >> k,
|
5786 | m = (dy + o * 2) >> k,
|
5787 | threshold = constant$6(20);
|
5788 |
|
5789 | function density(data) {
|
5790 | var values0 = new Float32Array(n * m),
|
5791 | values1 = new Float32Array(n * m);
|
5792 |
|
5793 | data.forEach(function(d, i, data) {
|
5794 | var xi = (+x(d, i, data) + o) >> k,
|
5795 | yi = (+y(d, i, data) + o) >> k,
|
5796 | wi = +weight(d, i, data);
|
5797 | if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
|
5798 | values0[xi + yi * n] += wi;
|
5799 | }
|
5800 | });
|
5801 |
|
5802 |
|
5803 | blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
|
5804 | blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
|
5805 | blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
|
5806 | blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
|
5807 | blurX({width: n, height: m, data: values0}, {width: n, height: m, data: values1}, r >> k);
|
5808 | blurY({width: n, height: m, data: values1}, {width: n, height: m, data: values0}, r >> k);
|
5809 |
|
5810 | var tz = threshold(values0);
|
5811 |
|
5812 |
|
5813 | if (!Array.isArray(tz)) {
|
5814 | var stop = max(values0);
|
5815 | tz = tickStep(0, stop, tz);
|
5816 | tz = sequence(0, Math.floor(stop / tz) * tz, tz);
|
5817 | tz.shift();
|
5818 | }
|
5819 |
|
5820 | return contours()
|
5821 | .thresholds(tz)
|
5822 | .size([n, m])
|
5823 | (values0)
|
5824 | .map(transform);
|
5825 | }
|
5826 |
|
5827 | function transform(geometry) {
|
5828 | geometry.value *= Math.pow(2, -2 * k);
|
5829 | geometry.coordinates.forEach(transformPolygon);
|
5830 | return geometry;
|
5831 | }
|
5832 |
|
5833 | function transformPolygon(coordinates) {
|
5834 | coordinates.forEach(transformRing);
|
5835 | }
|
5836 |
|
5837 | function transformRing(coordinates) {
|
5838 | coordinates.forEach(transformPoint);
|
5839 | }
|
5840 |
|
5841 |
|
5842 | function transformPoint(coordinates) {
|
5843 | coordinates[0] = coordinates[0] * Math.pow(2, k) - o;
|
5844 | coordinates[1] = coordinates[1] * Math.pow(2, k) - o;
|
5845 | }
|
5846 |
|
5847 | function resize() {
|
5848 | o = r * 3;
|
5849 | n = (dx + o * 2) >> k;
|
5850 | m = (dy + o * 2) >> k;
|
5851 | return density;
|
5852 | }
|
5853 |
|
5854 | density.x = function(_) {
|
5855 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$6(+_), density) : x;
|
5856 | };
|
5857 |
|
5858 | density.y = function(_) {
|
5859 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$6(+_), density) : y;
|
5860 | };
|
5861 |
|
5862 | density.weight = function(_) {
|
5863 | return arguments.length ? (weight = typeof _ === "function" ? _ : constant$6(+_), density) : weight;
|
5864 | };
|
5865 |
|
5866 | density.size = function(_) {
|
5867 | if (!arguments.length) return [dx, dy];
|
5868 | var _0 = Math.ceil(_[0]), _1 = Math.ceil(_[1]);
|
5869 | if (!(_0 >= 0) && !(_0 >= 0)) throw new Error("invalid size");
|
5870 | return dx = _0, dy = _1, resize();
|
5871 | };
|
5872 |
|
5873 | density.cellSize = function(_) {
|
5874 | if (!arguments.length) return 1 << k;
|
5875 | if (!((_ = +_) >= 1)) throw new Error("invalid cell size");
|
5876 | return k = Math.floor(Math.log(_) / Math.LN2), resize();
|
5877 | };
|
5878 |
|
5879 | density.thresholds = function(_) {
|
5880 | return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$6(slice$3.call(_)) : constant$6(_), density) : threshold;
|
5881 | };
|
5882 |
|
5883 | density.bandwidth = function(_) {
|
5884 | if (!arguments.length) return Math.sqrt(r * (r + 1));
|
5885 | if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth");
|
5886 | return r = Math.round((Math.sqrt(4 * _ * _ + 1) - 1) / 2), resize();
|
5887 | };
|
5888 |
|
5889 | return density;
|
5890 | }
|
5891 |
|
5892 | var EOL = {},
|
5893 | EOF = {},
|
5894 | QUOTE = 34,
|
5895 | NEWLINE = 10,
|
5896 | RETURN = 13;
|
5897 |
|
5898 | function objectConverter(columns) {
|
5899 | return new Function("d", "return {" + columns.map(function(name, i) {
|
5900 | return JSON.stringify(name) + ": d[" + i + "] || \"\"";
|
5901 | }).join(",") + "}");
|
5902 | }
|
5903 |
|
5904 | function customConverter(columns, f) {
|
5905 | var object = objectConverter(columns);
|
5906 | return function(row, i) {
|
5907 | return f(object(row), i, columns);
|
5908 | };
|
5909 | }
|
5910 |
|
5911 |
|
5912 | function inferColumns(rows) {
|
5913 | var columnSet = Object.create(null),
|
5914 | columns = [];
|
5915 |
|
5916 | rows.forEach(function(row) {
|
5917 | for (var column in row) {
|
5918 | if (!(column in columnSet)) {
|
5919 | columns.push(columnSet[column] = column);
|
5920 | }
|
5921 | }
|
5922 | });
|
5923 |
|
5924 | return columns;
|
5925 | }
|
5926 |
|
5927 | function pad(value, width) {
|
5928 | var s = value + "", length = s.length;
|
5929 | return length < width ? new Array(width - length + 1).join(0) + s : s;
|
5930 | }
|
5931 |
|
5932 | function formatYear(year) {
|
5933 | return year < 0 ? "-" + pad(-year, 6)
|
5934 | : year > 9999 ? "+" + pad(year, 6)
|
5935 | : pad(year, 4);
|
5936 | }
|
5937 |
|
5938 | function formatDate(date) {
|
5939 | var hours = date.getUTCHours(),
|
5940 | minutes = date.getUTCMinutes(),
|
5941 | seconds = date.getUTCSeconds(),
|
5942 | milliseconds = date.getUTCMilliseconds();
|
5943 | return isNaN(date) ? "Invalid Date"
|
5944 | : formatYear(date.getUTCFullYear()) + "-" + pad(date.getUTCMonth() + 1, 2) + "-" + pad(date.getUTCDate(), 2)
|
5945 | + (milliseconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "." + pad(milliseconds, 3) + "Z"
|
5946 | : seconds ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + ":" + pad(seconds, 2) + "Z"
|
5947 | : minutes || hours ? "T" + pad(hours, 2) + ":" + pad(minutes, 2) + "Z"
|
5948 | : "");
|
5949 | }
|
5950 |
|
5951 | function dsvFormat(delimiter) {
|
5952 | var reFormat = new RegExp("[\"" + delimiter + "\n\r]"),
|
5953 | DELIMITER = delimiter.charCodeAt(0);
|
5954 |
|
5955 | function parse(text, f) {
|
5956 | var convert, columns, rows = parseRows(text, function(row, i) {
|
5957 | if (convert) return convert(row, i - 1);
|
5958 | columns = row, convert = f ? customConverter(row, f) : objectConverter(row);
|
5959 | });
|
5960 | rows.columns = columns || [];
|
5961 | return rows;
|
5962 | }
|
5963 |
|
5964 | function parseRows(text, f) {
|
5965 | var rows = [],
|
5966 | N = text.length,
|
5967 | I = 0,
|
5968 | n = 0,
|
5969 | t,
|
5970 | eof = N <= 0,
|
5971 | eol = false;
|
5972 |
|
5973 |
|
5974 | if (text.charCodeAt(N - 1) === NEWLINE) --N;
|
5975 | if (text.charCodeAt(N - 1) === RETURN) --N;
|
5976 |
|
5977 | function token() {
|
5978 | if (eof) return EOF;
|
5979 | if (eol) return eol = false, EOL;
|
5980 |
|
5981 |
|
5982 | var i, j = I, c;
|
5983 | if (text.charCodeAt(j) === QUOTE) {
|
5984 | while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE);
|
5985 | if ((i = I) >= N) eof = true;
|
5986 | else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true;
|
5987 | else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
|
5988 | return text.slice(j + 1, i - 1).replace(/""/g, "\"");
|
5989 | }
|
5990 |
|
5991 | // Find next delimiter or newline.
|
5992 | while (I < N) {
|
5993 | if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true;
|
5994 | else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; }
|
5995 | else if (c !== DELIMITER) continue;
|
5996 | return text.slice(j, i);
|
5997 | }
|
5998 |
|
5999 | // Return last token before EOF.
|
6000 | return eof = true, text.slice(j, N);
|
6001 | }
|
6002 |
|
6003 | while ((t = token()) !== EOF) {
|
6004 | var row = [];
|
6005 | while (t !== EOL && t !== EOF) row.push(t), t = token();
|
6006 | if (f && (row = f(row, n++)) == null) continue;
|
6007 | rows.push(row);
|
6008 | }
|
6009 |
|
6010 | return rows;
|
6011 | }
|
6012 |
|
6013 | function preformatBody(rows, columns) {
|
6014 | return rows.map(function(row) {
|
6015 | return columns.map(function(column) {
|
6016 | return formatValue(row[column]);
|
6017 | }).join(delimiter);
|
6018 | });
|
6019 | }
|
6020 |
|
6021 | function format(rows, columns) {
|
6022 | if (columns == null) columns = inferColumns(rows);
|
6023 | return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n");
|
6024 | }
|
6025 |
|
6026 | function formatBody(rows, columns) {
|
6027 | if (columns == null) columns = inferColumns(rows);
|
6028 | return preformatBody(rows, columns).join("\n");
|
6029 | }
|
6030 |
|
6031 | function formatRows(rows) {
|
6032 | return rows.map(formatRow).join("\n");
|
6033 | }
|
6034 |
|
6035 | function formatRow(row) {
|
6036 | return row.map(formatValue).join(delimiter);
|
6037 | }
|
6038 |
|
6039 | function formatValue(value) {
|
6040 | return value == null ? ""
|
6041 | : value instanceof Date ? formatDate(value)
|
6042 | : reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\""
|
6043 | : value;
|
6044 | }
|
6045 |
|
6046 | return {
|
6047 | parse: parse,
|
6048 | parseRows: parseRows,
|
6049 | format: format,
|
6050 | formatBody: formatBody,
|
6051 | formatRows: formatRows,
|
6052 | formatRow: formatRow,
|
6053 | formatValue: formatValue
|
6054 | };
|
6055 | }
|
6056 |
|
6057 | var csv = dsvFormat(",");
|
6058 |
|
6059 | var csvParse = csv.parse;
|
6060 | var csvParseRows = csv.parseRows;
|
6061 | var csvFormat = csv.format;
|
6062 | var csvFormatBody = csv.formatBody;
|
6063 | var csvFormatRows = csv.formatRows;
|
6064 | var csvFormatRow = csv.formatRow;
|
6065 | var csvFormatValue = csv.formatValue;
|
6066 |
|
6067 | var tsv = dsvFormat("\t");
|
6068 |
|
6069 | var tsvParse = tsv.parse;
|
6070 | var tsvParseRows = tsv.parseRows;
|
6071 | var tsvFormat = tsv.format;
|
6072 | var tsvFormatBody = tsv.formatBody;
|
6073 | var tsvFormatRows = tsv.formatRows;
|
6074 | var tsvFormatRow = tsv.formatRow;
|
6075 | var tsvFormatValue = tsv.formatValue;
|
6076 |
|
6077 | function autoType(object) {
|
6078 | for (var key in object) {
|
6079 | var value = object[key].trim(), number, m;
|
6080 | if (!value) value = null;
|
6081 | else if (value === "true") value = true;
|
6082 | else if (value === "false") value = false;
|
6083 | else if (value === "NaN") value = NaN;
|
6084 | else if (!isNaN(number = +value)) value = number;
|
6085 | 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})?)?$/)) {
|
6086 | if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " ");
|
6087 | value = new Date(value);
|
6088 | }
|
6089 | else continue;
|
6090 | object[key] = value;
|
6091 | }
|
6092 | return object;
|
6093 | }
|
6094 |
|
6095 | // https://github.com/d3/d3-dsv/issues/45
|
6096 | var fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours();
|
6097 |
|
6098 | function responseBlob(response) {
|
6099 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
6100 | return response.blob();
|
6101 | }
|
6102 |
|
6103 | function blob(input, init) {
|
6104 | return fetch(input, init).then(responseBlob);
|
6105 | }
|
6106 |
|
6107 | function responseArrayBuffer(response) {
|
6108 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
6109 | return response.arrayBuffer();
|
6110 | }
|
6111 |
|
6112 | function buffer(input, init) {
|
6113 | return fetch(input, init).then(responseArrayBuffer);
|
6114 | }
|
6115 |
|
6116 | function responseText(response) {
|
6117 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
6118 | return response.text();
|
6119 | }
|
6120 |
|
6121 | function text(input, init) {
|
6122 | return fetch(input, init).then(responseText);
|
6123 | }
|
6124 |
|
6125 | function dsvParse(parse) {
|
6126 | return function(input, init, row) {
|
6127 | if (arguments.length === 2 && typeof init === "function") row = init, init = undefined;
|
6128 | return text(input, init).then(function(response) {
|
6129 | return parse(response, row);
|
6130 | });
|
6131 | };
|
6132 | }
|
6133 |
|
6134 | function dsv(delimiter, input, init, row) {
|
6135 | if (arguments.length === 3 && typeof init === "function") row = init, init = undefined;
|
6136 | var format = dsvFormat(delimiter);
|
6137 | return text(input, init).then(function(response) {
|
6138 | return format.parse(response, row);
|
6139 | });
|
6140 | }
|
6141 |
|
6142 | var csv$1 = dsvParse(csvParse);
|
6143 | var tsv$1 = dsvParse(tsvParse);
|
6144 |
|
6145 | function image(input, init) {
|
6146 | return new Promise(function(resolve, reject) {
|
6147 | var image = new Image;
|
6148 | for (var key in init) image[key] = init[key];
|
6149 | image.onerror = reject;
|
6150 | image.onload = function() { resolve(image); };
|
6151 | image.src = input;
|
6152 | });
|
6153 | }
|
6154 |
|
6155 | function responseJson(response) {
|
6156 | if (!response.ok) throw new Error(response.status + " " + response.statusText);
|
6157 | return response.json();
|
6158 | }
|
6159 |
|
6160 | function json(input, init) {
|
6161 | return fetch(input, init).then(responseJson);
|
6162 | }
|
6163 |
|
6164 | function parser(type) {
|
6165 | return function(input, init) {
|
6166 | return text(input, init).then(function(text) {
|
6167 | return (new DOMParser).parseFromString(text, type);
|
6168 | });
|
6169 | };
|
6170 | }
|
6171 |
|
6172 | var xml = parser("application/xml");
|
6173 |
|
6174 | var html = parser("text/html");
|
6175 |
|
6176 | var svg = parser("image/svg+xml");
|
6177 |
|
6178 | function center$1(x, y) {
|
6179 | var nodes;
|
6180 |
|
6181 | if (x == null) x = 0;
|
6182 | if (y == null) y = 0;
|
6183 |
|
6184 | function force() {
|
6185 | var i,
|
6186 | n = nodes.length,
|
6187 | node,
|
6188 | sx = 0,
|
6189 | sy = 0;
|
6190 |
|
6191 | for (i = 0; i < n; ++i) {
|
6192 | node = nodes[i], sx += node.x, sy += node.y;
|
6193 | }
|
6194 |
|
6195 | for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
|
6196 | node = nodes[i], node.x -= sx, node.y -= sy;
|
6197 | }
|
6198 | }
|
6199 |
|
6200 | force.initialize = function(_) {
|
6201 | nodes = _;
|
6202 | };
|
6203 |
|
6204 | force.x = function(_) {
|
6205 | return arguments.length ? (x = +_, force) : x;
|
6206 | };
|
6207 |
|
6208 | force.y = function(_) {
|
6209 | return arguments.length ? (y = +_, force) : y;
|
6210 | };
|
6211 |
|
6212 | return force;
|
6213 | }
|
6214 |
|
6215 | function constant$7(x) {
|
6216 | return function() {
|
6217 | return x;
|
6218 | };
|
6219 | }
|
6220 |
|
6221 | function jiggle() {
|
6222 | return (Math.random() - 0.5) * 1e-6;
|
6223 | }
|
6224 |
|
6225 | function tree_add(d) {
|
6226 | var x = +this._x.call(null, d),
|
6227 | y = +this._y.call(null, d);
|
6228 | return add(this.cover(x, y), x, y, d);
|
6229 | }
|
6230 |
|
6231 | function add(tree, x, y, d) {
|
6232 | if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
|
6233 |
|
6234 | var parent,
|
6235 | node = tree._root,
|
6236 | leaf = {data: d},
|
6237 | x0 = tree._x0,
|
6238 | y0 = tree._y0,
|
6239 | x1 = tree._x1,
|
6240 | y1 = tree._y1,
|
6241 | xm,
|
6242 | ym,
|
6243 | xp,
|
6244 | yp,
|
6245 | right,
|
6246 | bottom,
|
6247 | i,
|
6248 | j;
|
6249 |
|
6250 | // If the tree is empty, initialize the root as a leaf.
|
6251 | if (!node) return tree._root = leaf, tree;
|
6252 |
|
6253 | // Find the existing leaf for the new point, or add it.
|
6254 | while (node.length) {
|
6255 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
6256 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
6257 | if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
|
6258 | }
|
6259 |
|
6260 | // Is the new point is exactly coincident with the existing point?
|
6261 | xp = +tree._x.call(null, node.data);
|
6262 | yp = +tree._y.call(null, node.data);
|
6263 | if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
|
6264 |
|
6265 | // Otherwise, split the leaf node until the old and new point are separated.
|
6266 | do {
|
6267 | parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
|
6268 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
6269 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
6270 | } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
|
6271 | return parent[j] = node, parent[i] = leaf, tree;
|
6272 | }
|
6273 |
|
6274 | function addAll(data) {
|
6275 | var d, i, n = data.length,
|
6276 | x,
|
6277 | y,
|
6278 | xz = new Array(n),
|
6279 | yz = new Array(n),
|
6280 | x0 = Infinity,
|
6281 | y0 = Infinity,
|
6282 | x1 = -Infinity,
|
6283 | y1 = -Infinity;
|
6284 |
|
6285 | // Compute the points and their extent.
|
6286 | for (i = 0; i < n; ++i) {
|
6287 | if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
|
6288 | xz[i] = x;
|
6289 | yz[i] = y;
|
6290 | if (x < x0) x0 = x;
|
6291 | if (x > x1) x1 = x;
|
6292 | if (y < y0) y0 = y;
|
6293 | if (y > y1) y1 = y;
|
6294 | }
|
6295 |
|
6296 | // If there were no (valid) points, abort.
|
6297 | if (x0 > x1 || y0 > y1) return this;
|
6298 |
|
6299 | // Expand the tree to cover the new points.
|
6300 | this.cover(x0, y0).cover(x1, y1);
|
6301 |
|
6302 | // Add the new points.
|
6303 | for (i = 0; i < n; ++i) {
|
6304 | add(this, xz[i], yz[i], data[i]);
|
6305 | }
|
6306 |
|
6307 | return this;
|
6308 | }
|
6309 |
|
6310 | function tree_cover(x, y) {
|
6311 | if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
|
6312 |
|
6313 | var x0 = this._x0,
|
6314 | y0 = this._y0,
|
6315 | x1 = this._x1,
|
6316 | y1 = this._y1;
|
6317 |
|
6318 | // If the quadtree has no extent, initialize them.
|
6319 | // Integer extent are necessary so that if we later double the extent,
|
6320 | // the existing quadrant boundaries don’t change due to floating point error!
|
6321 | if (isNaN(x0)) {
|
6322 | x1 = (x0 = Math.floor(x)) + 1;
|
6323 | y1 = (y0 = Math.floor(y)) + 1;
|
6324 | }
|
6325 |
|
6326 | // Otherwise, double repeatedly to cover.
|
6327 | else {
|
6328 | var z = x1 - x0,
|
6329 | node = this._root,
|
6330 | parent,
|
6331 | i;
|
6332 |
|
6333 | while (x0 > x || x >= x1 || y0 > y || y >= y1) {
|
6334 | i = (y < y0) << 1 | (x < x0);
|
6335 | parent = new Array(4), parent[i] = node, node = parent, z *= 2;
|
6336 | switch (i) {
|
6337 | case 0: x1 = x0 + z, y1 = y0 + z; break;
|
6338 | case 1: x0 = x1 - z, y1 = y0 + z; break;
|
6339 | case 2: x1 = x0 + z, y0 = y1 - z; break;
|
6340 | case 3: x0 = x1 - z, y0 = y1 - z; break;
|
6341 | }
|
6342 | }
|
6343 |
|
6344 | if (this._root && this._root.length) this._root = node;
|
6345 | }
|
6346 |
|
6347 | this._x0 = x0;
|
6348 | this._y0 = y0;
|
6349 | this._x1 = x1;
|
6350 | this._y1 = y1;
|
6351 | return this;
|
6352 | }
|
6353 |
|
6354 | function tree_data() {
|
6355 | var data = [];
|
6356 | this.visit(function(node) {
|
6357 | if (!node.length) do data.push(node.data); while (node = node.next)
|
6358 | });
|
6359 | return data;
|
6360 | }
|
6361 |
|
6362 | function tree_extent(_) {
|
6363 | return arguments.length
|
6364 | ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
|
6365 | : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
|
6366 | }
|
6367 |
|
6368 | function Quad(node, x0, y0, x1, y1) {
|
6369 | this.node = node;
|
6370 | this.x0 = x0;
|
6371 | this.y0 = y0;
|
6372 | this.x1 = x1;
|
6373 | this.y1 = y1;
|
6374 | }
|
6375 |
|
6376 | function tree_find(x, y, radius) {
|
6377 | var data,
|
6378 | x0 = this._x0,
|
6379 | y0 = this._y0,
|
6380 | x1,
|
6381 | y1,
|
6382 | x2,
|
6383 | y2,
|
6384 | x3 = this._x1,
|
6385 | y3 = this._y1,
|
6386 | quads = [],
|
6387 | node = this._root,
|
6388 | q,
|
6389 | i;
|
6390 |
|
6391 | if (node) quads.push(new Quad(node, x0, y0, x3, y3));
|
6392 | if (radius == null) radius = Infinity;
|
6393 | else {
|
6394 | x0 = x - radius, y0 = y - radius;
|
6395 | x3 = x + radius, y3 = y + radius;
|
6396 | radius *= radius;
|
6397 | }
|
6398 |
|
6399 | while (q = quads.pop()) {
|
6400 |
|
6401 | // Stop searching if this quadrant can’t contain a closer node.
|
6402 | if (!(node = q.node)
|
6403 | || (x1 = q.x0) > x3
|
6404 | || (y1 = q.y0) > y3
|
6405 | || (x2 = q.x1) < x0
|
6406 | || (y2 = q.y1) < y0) continue;
|
6407 |
|
6408 | // Bisect the current quadrant.
|
6409 | if (node.length) {
|
6410 | var xm = (x1 + x2) / 2,
|
6411 | ym = (y1 + y2) / 2;
|
6412 |
|
6413 | quads.push(
|
6414 | new Quad(node[3], xm, ym, x2, y2),
|
6415 | new Quad(node[2], x1, ym, xm, y2),
|
6416 | new Quad(node[1], xm, y1, x2, ym),
|
6417 | new Quad(node[0], x1, y1, xm, ym)
|
6418 | );
|
6419 |
|
6420 | // Visit the closest quadrant first.
|
6421 | if (i = (y >= ym) << 1 | (x >= xm)) {
|
6422 | q = quads[quads.length - 1];
|
6423 | quads[quads.length - 1] = quads[quads.length - 1 - i];
|
6424 | quads[quads.length - 1 - i] = q;
|
6425 | }
|
6426 | }
|
6427 |
|
6428 | // Visit this point. (Visiting coincident points isn’t necessary!)
|
6429 | else {
|
6430 | var dx = x - +this._x.call(null, node.data),
|
6431 | dy = y - +this._y.call(null, node.data),
|
6432 | d2 = dx * dx + dy * dy;
|
6433 | if (d2 < radius) {
|
6434 | var d = Math.sqrt(radius = d2);
|
6435 | x0 = x - d, y0 = y - d;
|
6436 | x3 = x + d, y3 = y + d;
|
6437 | data = node.data;
|
6438 | }
|
6439 | }
|
6440 | }
|
6441 |
|
6442 | return data;
|
6443 | }
|
6444 |
|
6445 | function tree_remove(d) {
|
6446 | if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
|
6447 |
|
6448 | var parent,
|
6449 | node = this._root,
|
6450 | retainer,
|
6451 | previous,
|
6452 | next,
|
6453 | x0 = this._x0,
|
6454 | y0 = this._y0,
|
6455 | x1 = this._x1,
|
6456 | y1 = this._y1,
|
6457 | x,
|
6458 | y,
|
6459 | xm,
|
6460 | ym,
|
6461 | right,
|
6462 | bottom,
|
6463 | i,
|
6464 | j;
|
6465 |
|
6466 | // If the tree is empty, initialize the root as a leaf.
|
6467 | if (!node) return this;
|
6468 |
|
6469 | // Find the leaf node for the point.
|
6470 | // While descending, also retain the deepest parent with a non-removed sibling.
|
6471 | if (node.length) while (true) {
|
6472 | if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
6473 | if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
6474 | if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
|
6475 | if (!node.length) break;
|
6476 | if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
|
6477 | }
|
6478 |
|
6479 | // Find the point to remove.
|
6480 | while (node.data !== d) if (!(previous = node, node = node.next)) return this;
|
6481 | if (next = node.next) delete node.next;
|
6482 |
|
6483 | // If there are multiple coincident points, remove just the point.
|
6484 | if (previous) return (next ? previous.next = next : delete previous.next), this;
|
6485 |
|
6486 | // If this is the root point, remove it.
|
6487 | if (!parent) return this._root = next, this;
|
6488 |
|
6489 | // Remove this leaf.
|
6490 | next ? parent[i] = next : delete parent[i];
|
6491 |
|
6492 | // If the parent now contains exactly one leaf, collapse superfluous parents.
|
6493 | if ((node = parent[0] || parent[1] || parent[2] || parent[3])
|
6494 | && node === (parent[3] || parent[2] || parent[1] || parent[0])
|
6495 | && !node.length) {
|
6496 | if (retainer) retainer[j] = node;
|
6497 | else this._root = node;
|
6498 | }
|
6499 |
|
6500 | return this;
|
6501 | }
|
6502 |
|
6503 | function removeAll(data) {
|
6504 | for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
|
6505 | return this;
|
6506 | }
|
6507 |
|
6508 | function tree_root() {
|
6509 | return this._root;
|
6510 | }
|
6511 |
|
6512 | function tree_size() {
|
6513 | var size = 0;
|
6514 | this.visit(function(node) {
|
6515 | if (!node.length) do ++size; while (node = node.next)
|
6516 | });
|
6517 | return size;
|
6518 | }
|
6519 |
|
6520 | function tree_visit(callback) {
|
6521 | var quads = [], q, node = this._root, child, x0, y0, x1, y1;
|
6522 | if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
|
6523 | while (q = quads.pop()) {
|
6524 | if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
|
6525 | var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
6526 | if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
6527 | if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
6528 | if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
6529 | if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
6530 | }
|
6531 | }
|
6532 | return this;
|
6533 | }
|
6534 |
|
6535 | function tree_visitAfter(callback) {
|
6536 | var quads = [], next = [], q;
|
6537 | if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
|
6538 | while (q = quads.pop()) {
|
6539 | var node = q.node;
|
6540 | if (node.length) {
|
6541 | var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
6542 | if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
6543 | if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
6544 | if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
6545 | if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
6546 | }
|
6547 | next.push(q);
|
6548 | }
|
6549 | while (q = next.pop()) {
|
6550 | callback(q.node, q.x0, q.y0, q.x1, q.y1);
|
6551 | }
|
6552 | return this;
|
6553 | }
|
6554 |
|
6555 | function defaultX$1(d) {
|
6556 | return d[0];
|
6557 | }
|
6558 |
|
6559 | function tree_x(_) {
|
6560 | return arguments.length ? (this._x = _, this) : this._x;
|
6561 | }
|
6562 |
|
6563 | function defaultY$1(d) {
|
6564 | return d[1];
|
6565 | }
|
6566 |
|
6567 | function tree_y(_) {
|
6568 | return arguments.length ? (this._y = _, this) : this._y;
|
6569 | }
|
6570 |
|
6571 | function quadtree(nodes, x, y) {
|
6572 | var tree = new Quadtree(x == null ? defaultX$1 : x, y == null ? defaultY$1 : y, NaN, NaN, NaN, NaN);
|
6573 | return nodes == null ? tree : tree.addAll(nodes);
|
6574 | }
|
6575 |
|
6576 | function Quadtree(x, y, x0, y0, x1, y1) {
|
6577 | this._x = x;
|
6578 | this._y = y;
|
6579 | this._x0 = x0;
|
6580 | this._y0 = y0;
|
6581 | this._x1 = x1;
|
6582 | this._y1 = y1;
|
6583 | this._root = undefined;
|
6584 | }
|
6585 |
|
6586 | function leaf_copy(leaf) {
|
6587 | var copy = {data: leaf.data}, next = copy;
|
6588 | while (leaf = leaf.next) next = next.next = {data: leaf.data};
|
6589 | return copy;
|
6590 | }
|
6591 |
|
6592 | var treeProto = quadtree.prototype = Quadtree.prototype;
|
6593 |
|
6594 | treeProto.copy = function() {
|
6595 | var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
|
6596 | node = this._root,
|
6597 | nodes,
|
6598 | child;
|
6599 |
|
6600 | if (!node) return copy;
|
6601 |
|
6602 | if (!node.length) return copy._root = leaf_copy(node), copy;
|
6603 |
|
6604 | nodes = [{source: node, target: copy._root = new Array(4)}];
|
6605 | while (node = nodes.pop()) {
|
6606 | for (var i = 0; i < 4; ++i) {
|
6607 | if (child = node.source[i]) {
|
6608 | if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
|
6609 | else node.target[i] = leaf_copy(child);
|
6610 | }
|
6611 | }
|
6612 | }
|
6613 |
|
6614 | return copy;
|
6615 | };
|
6616 |
|
6617 | treeProto.add = tree_add;
|
6618 | treeProto.addAll = addAll;
|
6619 | treeProto.cover = tree_cover;
|
6620 | treeProto.data = tree_data;
|
6621 | treeProto.extent = tree_extent;
|
6622 | treeProto.find = tree_find;
|
6623 | treeProto.remove = tree_remove;
|
6624 | treeProto.removeAll = removeAll;
|
6625 | treeProto.root = tree_root;
|
6626 | treeProto.size = tree_size;
|
6627 | treeProto.visit = tree_visit;
|
6628 | treeProto.visitAfter = tree_visitAfter;
|
6629 | treeProto.x = tree_x;
|
6630 | treeProto.y = tree_y;
|
6631 |
|
6632 | function x(d) {
|
6633 | return d.x + d.vx;
|
6634 | }
|
6635 |
|
6636 | function y(d) {
|
6637 | return d.y + d.vy;
|
6638 | }
|
6639 |
|
6640 | function collide(radius) {
|
6641 | var nodes,
|
6642 | radii,
|
6643 | strength = 1,
|
6644 | iterations = 1;
|
6645 |
|
6646 | if (typeof radius !== "function") radius = constant$7(radius == null ? 1 : +radius);
|
6647 |
|
6648 | function force() {
|
6649 | var i, n = nodes.length,
|
6650 | tree,
|
6651 | node,
|
6652 | xi,
|
6653 | yi,
|
6654 | ri,
|
6655 | ri2;
|
6656 |
|
6657 | for (var k = 0; k < iterations; ++k) {
|
6658 | tree = quadtree(nodes, x, y).visitAfter(prepare);
|
6659 | for (i = 0; i < n; ++i) {
|
6660 | node = nodes[i];
|
6661 | ri = radii[node.index], ri2 = ri * ri;
|
6662 | xi = node.x + node.vx;
|
6663 | yi = node.y + node.vy;
|
6664 | tree.visit(apply);
|
6665 | }
|
6666 | }
|
6667 |
|
6668 | function apply(quad, x0, y0, x1, y1) {
|
6669 | var data = quad.data, rj = quad.r, r = ri + rj;
|
6670 | if (data) {
|
6671 | if (data.index > node.index) {
|
6672 | var x = xi - data.x - data.vx,
|
6673 | y = yi - data.y - data.vy,
|
6674 | l = x * x + y * y;
|
6675 | if (l < r * r) {
|
6676 | if (x === 0) x = jiggle(), l += x * x;
|
6677 | if (y === 0) y = jiggle(), l += y * y;
|
6678 | l = (r - (l = Math.sqrt(l))) / l * strength;
|
6679 | node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
|
6680 | node.vy += (y *= l) * r;
|
6681 | data.vx -= x * (r = 1 - r);
|
6682 | data.vy -= y * r;
|
6683 | }
|
6684 | }
|
6685 | return;
|
6686 | }
|
6687 | return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
|
6688 | }
|
6689 | }
|
6690 |
|
6691 | function prepare(quad) {
|
6692 | if (quad.data) return quad.r = radii[quad.data.index];
|
6693 | for (var i = quad.r = 0; i < 4; ++i) {
|
6694 | if (quad[i] && quad[i].r > quad.r) {
|
6695 | quad.r = quad[i].r;
|
6696 | }
|
6697 | }
|
6698 | }
|
6699 |
|
6700 | function initialize() {
|
6701 | if (!nodes) return;
|
6702 | var i, n = nodes.length, node;
|
6703 | radii = new Array(n);
|
6704 | for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes);
|
6705 | }
|
6706 |
|
6707 | force.initialize = function(_) {
|
6708 | nodes = _;
|
6709 | initialize();
|
6710 | };
|
6711 |
|
6712 | force.iterations = function(_) {
|
6713 | return arguments.length ? (iterations = +_, force) : iterations;
|
6714 | };
|
6715 |
|
6716 | force.strength = function(_) {
|
6717 | return arguments.length ? (strength = +_, force) : strength;
|
6718 | };
|
6719 |
|
6720 | force.radius = function(_) {
|
6721 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
|
6722 | };
|
6723 |
|
6724 | return force;
|
6725 | }
|
6726 |
|
6727 | function index(d) {
|
6728 | return d.index;
|
6729 | }
|
6730 |
|
6731 | function find(nodeById, nodeId) {
|
6732 | var node = nodeById.get(nodeId);
|
6733 | if (!node) throw new Error("missing: " + nodeId);
|
6734 | return node;
|
6735 | }
|
6736 |
|
6737 | function link(links) {
|
6738 | var id = index,
|
6739 | strength = defaultStrength,
|
6740 | strengths,
|
6741 | distance = constant$7(30),
|
6742 | distances,
|
6743 | nodes,
|
6744 | count,
|
6745 | bias,
|
6746 | iterations = 1;
|
6747 |
|
6748 | if (links == null) links = [];
|
6749 |
|
6750 | function defaultStrength(link) {
|
6751 | return 1 / Math.min(count[link.source.index], count[link.target.index]);
|
6752 | }
|
6753 |
|
6754 | function force(alpha) {
|
6755 | for (var k = 0, n = links.length; k < iterations; ++k) {
|
6756 | for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
|
6757 | link = links[i], source = link.source, target = link.target;
|
6758 | x = target.x + target.vx - source.x - source.vx || jiggle();
|
6759 | y = target.y + target.vy - source.y - source.vy || jiggle();
|
6760 | l = Math.sqrt(x * x + y * y);
|
6761 | l = (l - distances[i]) / l * alpha * strengths[i];
|
6762 | x *= l, y *= l;
|
6763 | target.vx -= x * (b = bias[i]);
|
6764 | target.vy -= y * b;
|
6765 | source.vx += x * (b = 1 - b);
|
6766 | source.vy += y * b;
|
6767 | }
|
6768 | }
|
6769 | }
|
6770 |
|
6771 | function initialize() {
|
6772 | if (!nodes) return;
|
6773 |
|
6774 | var i,
|
6775 | n = nodes.length,
|
6776 | m = links.length,
|
6777 | nodeById = map$1(nodes, id),
|
6778 | link;
|
6779 |
|
6780 | for (i = 0, count = new Array(n); i < m; ++i) {
|
6781 | link = links[i], link.index = i;
|
6782 | if (typeof link.source !== "object") link.source = find(nodeById, link.source);
|
6783 | if (typeof link.target !== "object") link.target = find(nodeById, link.target);
|
6784 | count[link.source.index] = (count[link.source.index] || 0) + 1;
|
6785 | count[link.target.index] = (count[link.target.index] || 0) + 1;
|
6786 | }
|
6787 |
|
6788 | for (i = 0, bias = new Array(m); i < m; ++i) {
|
6789 | link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
|
6790 | }
|
6791 |
|
6792 | strengths = new Array(m), initializeStrength();
|
6793 | distances = new Array(m), initializeDistance();
|
6794 | }
|
6795 |
|
6796 | function initializeStrength() {
|
6797 | if (!nodes) return;
|
6798 |
|
6799 | for (var i = 0, n = links.length; i < n; ++i) {
|
6800 | strengths[i] = +strength(links[i], i, links);
|
6801 | }
|
6802 | }
|
6803 |
|
6804 | function initializeDistance() {
|
6805 | if (!nodes) return;
|
6806 |
|
6807 | for (var i = 0, n = links.length; i < n; ++i) {
|
6808 | distances[i] = +distance(links[i], i, links);
|
6809 | }
|
6810 | }
|
6811 |
|
6812 | force.initialize = function(_) {
|
6813 | nodes = _;
|
6814 | initialize();
|
6815 | };
|
6816 |
|
6817 | force.links = function(_) {
|
6818 | return arguments.length ? (links = _, initialize(), force) : links;
|
6819 | };
|
6820 |
|
6821 | force.id = function(_) {
|
6822 | return arguments.length ? (id = _, force) : id;
|
6823 | };
|
6824 |
|
6825 | force.iterations = function(_) {
|
6826 | return arguments.length ? (iterations = +_, force) : iterations;
|
6827 | };
|
6828 |
|
6829 | force.strength = function(_) {
|
6830 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initializeStrength(), force) : strength;
|
6831 | };
|
6832 |
|
6833 | force.distance = function(_) {
|
6834 | return arguments.length ? (distance = typeof _ === "function" ? _ : constant$7(+_), initializeDistance(), force) : distance;
|
6835 | };
|
6836 |
|
6837 | return force;
|
6838 | }
|
6839 |
|
6840 | function x$1(d) {
|
6841 | return d.x;
|
6842 | }
|
6843 |
|
6844 | function y$1(d) {
|
6845 | return d.y;
|
6846 | }
|
6847 |
|
6848 | var initialRadius = 10,
|
6849 | initialAngle = Math.PI * (3 - Math.sqrt(5));
|
6850 |
|
6851 | function simulation(nodes) {
|
6852 | var simulation,
|
6853 | alpha = 1,
|
6854 | alphaMin = 0.001,
|
6855 | alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
|
6856 | alphaTarget = 0,
|
6857 | velocityDecay = 0.6,
|
6858 | forces = map$1(),
|
6859 | stepper = timer(step),
|
6860 | event = dispatch("tick", "end");
|
6861 |
|
6862 | if (nodes == null) nodes = [];
|
6863 |
|
6864 | function step() {
|
6865 | tick();
|
6866 | event.call("tick", simulation);
|
6867 | if (alpha < alphaMin) {
|
6868 | stepper.stop();
|
6869 | event.call("end", simulation);
|
6870 | }
|
6871 | }
|
6872 |
|
6873 | function tick(iterations) {
|
6874 | var i, n = nodes.length, node;
|
6875 |
|
6876 | if (iterations === undefined) iterations = 1;
|
6877 |
|
6878 | for (var k = 0; k < iterations; ++k) {
|
6879 | alpha += (alphaTarget - alpha) * alphaDecay;
|
6880 |
|
6881 | forces.each(function (force) {
|
6882 | force(alpha);
|
6883 | });
|
6884 |
|
6885 | for (i = 0; i < n; ++i) {
|
6886 | node = nodes[i];
|
6887 | if (node.fx == null) node.x += node.vx *= velocityDecay;
|
6888 | else node.x = node.fx, node.vx = 0;
|
6889 | if (node.fy == null) node.y += node.vy *= velocityDecay;
|
6890 | else node.y = node.fy, node.vy = 0;
|
6891 | }
|
6892 | }
|
6893 |
|
6894 | return simulation;
|
6895 | }
|
6896 |
|
6897 | function initializeNodes() {
|
6898 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
6899 | node = nodes[i], node.index = i;
|
6900 | if (node.fx != null) node.x = node.fx;
|
6901 | if (node.fy != null) node.y = node.fy;
|
6902 | if (isNaN(node.x) || isNaN(node.y)) {
|
6903 | var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
|
6904 | node.x = radius * Math.cos(angle);
|
6905 | node.y = radius * Math.sin(angle);
|
6906 | }
|
6907 | if (isNaN(node.vx) || isNaN(node.vy)) {
|
6908 | node.vx = node.vy = 0;
|
6909 | }
|
6910 | }
|
6911 | }
|
6912 |
|
6913 | function initializeForce(force) {
|
6914 | if (force.initialize) force.initialize(nodes);
|
6915 | return force;
|
6916 | }
|
6917 |
|
6918 | initializeNodes();
|
6919 |
|
6920 | return simulation = {
|
6921 | tick: tick,
|
6922 |
|
6923 | restart: function() {
|
6924 | return stepper.restart(step), simulation;
|
6925 | },
|
6926 |
|
6927 | stop: function() {
|
6928 | return stepper.stop(), simulation;
|
6929 | },
|
6930 |
|
6931 | nodes: function(_) {
|
6932 | return arguments.length ? (nodes = _, initializeNodes(), forces.each(initializeForce), simulation) : nodes;
|
6933 | },
|
6934 |
|
6935 | alpha: function(_) {
|
6936 | return arguments.length ? (alpha = +_, simulation) : alpha;
|
6937 | },
|
6938 |
|
6939 | alphaMin: function(_) {
|
6940 | return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
|
6941 | },
|
6942 |
|
6943 | alphaDecay: function(_) {
|
6944 | return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
|
6945 | },
|
6946 |
|
6947 | alphaTarget: function(_) {
|
6948 | return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
|
6949 | },
|
6950 |
|
6951 | velocityDecay: function(_) {
|
6952 | return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
|
6953 | },
|
6954 |
|
6955 | force: function(name, _) {
|
6956 | return arguments.length > 1 ? ((_ == null ? forces.remove(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
|
6957 | },
|
6958 |
|
6959 | find: function(x, y, radius) {
|
6960 | var i = 0,
|
6961 | n = nodes.length,
|
6962 | dx,
|
6963 | dy,
|
6964 | d2,
|
6965 | node,
|
6966 | closest;
|
6967 |
|
6968 | if (radius == null) radius = Infinity;
|
6969 | else radius *= radius;
|
6970 |
|
6971 | for (i = 0; i < n; ++i) {
|
6972 | node = nodes[i];
|
6973 | dx = x - node.x;
|
6974 | dy = y - node.y;
|
6975 | d2 = dx * dx + dy * dy;
|
6976 | if (d2 < radius) closest = node, radius = d2;
|
6977 | }
|
6978 |
|
6979 | return closest;
|
6980 | },
|
6981 |
|
6982 | on: function(name, _) {
|
6983 | return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
|
6984 | }
|
6985 | };
|
6986 | }
|
6987 |
|
6988 | function manyBody() {
|
6989 | var nodes,
|
6990 | node,
|
6991 | alpha,
|
6992 | strength = constant$7(-30),
|
6993 | strengths,
|
6994 | distanceMin2 = 1,
|
6995 | distanceMax2 = Infinity,
|
6996 | theta2 = 0.81;
|
6997 |
|
6998 | function force(_) {
|
6999 | var i, n = nodes.length, tree = quadtree(nodes, x$1, y$1).visitAfter(accumulate);
|
7000 | for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
|
7001 | }
|
7002 |
|
7003 | function initialize() {
|
7004 | if (!nodes) return;
|
7005 | var i, n = nodes.length, node;
|
7006 | strengths = new Array(n);
|
7007 | for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes);
|
7008 | }
|
7009 |
|
7010 | function accumulate(quad) {
|
7011 | var strength = 0, q, c, weight = 0, x, y, i;
|
7012 |
|
7013 | // For internal nodes, accumulate forces from child quadrants.
|
7014 | if (quad.length) {
|
7015 | for (x = y = i = 0; i < 4; ++i) {
|
7016 | if ((q = quad[i]) && (c = Math.abs(q.value))) {
|
7017 | strength += q.value, weight += c, x += c * q.x, y += c * q.y;
|
7018 | }
|
7019 | }
|
7020 | quad.x = x / weight;
|
7021 | quad.y = y / weight;
|
7022 | }
|
7023 |
|
7024 | // For leaf nodes, accumulate forces from coincident quadrants.
|
7025 | else {
|
7026 | q = quad;
|
7027 | q.x = q.data.x;
|
7028 | q.y = q.data.y;
|
7029 | do strength += strengths[q.data.index];
|
7030 | while (q = q.next);
|
7031 | }
|
7032 |
|
7033 | quad.value = strength;
|
7034 | }
|
7035 |
|
7036 | function apply(quad, x1, _, x2) {
|
7037 | if (!quad.value) return true;
|
7038 |
|
7039 | var x = quad.x - node.x,
|
7040 | y = quad.y - node.y,
|
7041 | w = x2 - x1,
|
7042 | l = x * x + y * y;
|
7043 |
|
7044 | // Apply the Barnes-Hut approximation if possible.
|
7045 | // Limit forces for very close nodes; randomize direction if coincident.
|
7046 | if (w * w / theta2 < l) {
|
7047 | if (l < distanceMax2) {
|
7048 | if (x === 0) x = jiggle(), l += x * x;
|
7049 | if (y === 0) y = jiggle(), l += y * y;
|
7050 | if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
7051 | node.vx += x * quad.value * alpha / l;
|
7052 | node.vy += y * quad.value * alpha / l;
|
7053 | }
|
7054 | return true;
|
7055 | }
|
7056 |
|
7057 | // Otherwise, process points directly.
|
7058 | else if (quad.length || l >= distanceMax2) return;
|
7059 |
|
7060 | // Limit forces for very close nodes; randomize direction if coincident.
|
7061 | if (quad.data !== node || quad.next) {
|
7062 | if (x === 0) x = jiggle(), l += x * x;
|
7063 | if (y === 0) y = jiggle(), l += y * y;
|
7064 | if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
7065 | }
|
7066 |
|
7067 | do if (quad.data !== node) {
|
7068 | w = strengths[quad.data.index] * alpha / l;
|
7069 | node.vx += x * w;
|
7070 | node.vy += y * w;
|
7071 | } while (quad = quad.next);
|
7072 | }
|
7073 |
|
7074 | force.initialize = function(_) {
|
7075 | nodes = _;
|
7076 | initialize();
|
7077 | };
|
7078 |
|
7079 | force.strength = function(_) {
|
7080 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
|
7081 | };
|
7082 |
|
7083 | force.distanceMin = function(_) {
|
7084 | return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
|
7085 | };
|
7086 |
|
7087 | force.distanceMax = function(_) {
|
7088 | return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
|
7089 | };
|
7090 |
|
7091 | force.theta = function(_) {
|
7092 | return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
|
7093 | };
|
7094 |
|
7095 | return force;
|
7096 | }
|
7097 |
|
7098 | function radial(radius, x, y) {
|
7099 | var nodes,
|
7100 | strength = constant$7(0.1),
|
7101 | strengths,
|
7102 | radiuses;
|
7103 |
|
7104 | if (typeof radius !== "function") radius = constant$7(+radius);
|
7105 | if (x == null) x = 0;
|
7106 | if (y == null) y = 0;
|
7107 |
|
7108 | function force(alpha) {
|
7109 | for (var i = 0, n = nodes.length; i < n; ++i) {
|
7110 | var node = nodes[i],
|
7111 | dx = node.x - x || 1e-6,
|
7112 | dy = node.y - y || 1e-6,
|
7113 | r = Math.sqrt(dx * dx + dy * dy),
|
7114 | k = (radiuses[i] - r) * strengths[i] * alpha / r;
|
7115 | node.vx += dx * k;
|
7116 | node.vy += dy * k;
|
7117 | }
|
7118 | }
|
7119 |
|
7120 | function initialize() {
|
7121 | if (!nodes) return;
|
7122 | var i, n = nodes.length;
|
7123 | strengths = new Array(n);
|
7124 | radiuses = new Array(n);
|
7125 | for (i = 0; i < n; ++i) {
|
7126 | radiuses[i] = +radius(nodes[i], i, nodes);
|
7127 | strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes);
|
7128 | }
|
7129 | }
|
7130 |
|
7131 | force.initialize = function(_) {
|
7132 | nodes = _, initialize();
|
7133 | };
|
7134 |
|
7135 | force.strength = function(_) {
|
7136 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
|
7137 | };
|
7138 |
|
7139 | force.radius = function(_) {
|
7140 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : radius;
|
7141 | };
|
7142 |
|
7143 | force.x = function(_) {
|
7144 | return arguments.length ? (x = +_, force) : x;
|
7145 | };
|
7146 |
|
7147 | force.y = function(_) {
|
7148 | return arguments.length ? (y = +_, force) : y;
|
7149 | };
|
7150 |
|
7151 | return force;
|
7152 | }
|
7153 |
|
7154 | function x$2(x) {
|
7155 | var strength = constant$7(0.1),
|
7156 | nodes,
|
7157 | strengths,
|
7158 | xz;
|
7159 |
|
7160 | if (typeof x !== "function") x = constant$7(x == null ? 0 : +x);
|
7161 |
|
7162 | function force(alpha) {
|
7163 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
7164 | node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
|
7165 | }
|
7166 | }
|
7167 |
|
7168 | function initialize() {
|
7169 | if (!nodes) return;
|
7170 | var i, n = nodes.length;
|
7171 | strengths = new Array(n);
|
7172 | xz = new Array(n);
|
7173 | for (i = 0; i < n; ++i) {
|
7174 | strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
7175 | }
|
7176 | }
|
7177 |
|
7178 | force.initialize = function(_) {
|
7179 | nodes = _;
|
7180 | initialize();
|
7181 | };
|
7182 |
|
7183 | force.strength = function(_) {
|
7184 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
|
7185 | };
|
7186 |
|
7187 | force.x = function(_) {
|
7188 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : x;
|
7189 | };
|
7190 |
|
7191 | return force;
|
7192 | }
|
7193 |
|
7194 | function y$2(y) {
|
7195 | var strength = constant$7(0.1),
|
7196 | nodes,
|
7197 | strengths,
|
7198 | yz;
|
7199 |
|
7200 | if (typeof y !== "function") y = constant$7(y == null ? 0 : +y);
|
7201 |
|
7202 | function force(alpha) {
|
7203 | for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
7204 | node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
|
7205 | }
|
7206 | }
|
7207 |
|
7208 | function initialize() {
|
7209 | if (!nodes) return;
|
7210 | var i, n = nodes.length;
|
7211 | strengths = new Array(n);
|
7212 | yz = new Array(n);
|
7213 | for (i = 0; i < n; ++i) {
|
7214 | strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
7215 | }
|
7216 | }
|
7217 |
|
7218 | force.initialize = function(_) {
|
7219 | nodes = _;
|
7220 | initialize();
|
7221 | };
|
7222 |
|
7223 | force.strength = function(_) {
|
7224 | return arguments.length ? (strength = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : strength;
|
7225 | };
|
7226 |
|
7227 | force.y = function(_) {
|
7228 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$7(+_), initialize(), force) : y;
|
7229 | };
|
7230 |
|
7231 | return force;
|
7232 | }
|
7233 |
|
7234 | // Computes the decimal coefficient and exponent of the specified number x with
|
7235 | // significant digits p, where x is positive and p is in [1, 21] or undefined.
|
7236 | // For example, formatDecimal(1.23) returns ["123", 0].
|
7237 | function formatDecimal(x, p) {
|
7238 | if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
|
7239 | var i, coefficient = x.slice(0, i);
|
7240 |
|
7241 | // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
|
7242 | // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
|
7243 | return [
|
7244 | coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
|
7245 | +x.slice(i + 1)
|
7246 | ];
|
7247 | }
|
7248 |
|
7249 | function exponent$1(x) {
|
7250 | return x = formatDecimal(Math.abs(x)), x ? x[1] : NaN;
|
7251 | }
|
7252 |
|
7253 | function formatGroup(grouping, thousands) {
|
7254 | return function(value, width) {
|
7255 | var i = value.length,
|
7256 | t = [],
|
7257 | j = 0,
|
7258 | g = grouping[0],
|
7259 | length = 0;
|
7260 |
|
7261 | while (i > 0 && g > 0) {
|
7262 | if (length + g + 1 > width) g = Math.max(1, width - length);
|
7263 | t.push(value.substring(i -= g, i + g));
|
7264 | if ((length += g + 1) > width) break;
|
7265 | g = grouping[j = (j + 1) % grouping.length];
|
7266 | }
|
7267 |
|
7268 | return t.reverse().join(thousands);
|
7269 | };
|
7270 | }
|
7271 |
|
7272 | function formatNumerals(numerals) {
|
7273 | return function(value) {
|
7274 | return value.replace(/[0-9]/g, function(i) {
|
7275 | return numerals[+i];
|
7276 | });
|
7277 | };
|
7278 | }
|
7279 |
|
7280 | // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
|
7281 | var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
|
7282 |
|
7283 | function formatSpecifier(specifier) {
|
7284 | if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
|
7285 | var match;
|
7286 | return new FormatSpecifier({
|
7287 | fill: match[1],
|
7288 | align: match[2],
|
7289 | sign: match[3],
|
7290 | symbol: match[4],
|
7291 | zero: match[5],
|
7292 | width: match[6],
|
7293 | comma: match[7],
|
7294 | precision: match[8] && match[8].slice(1),
|
7295 | trim: match[9],
|
7296 | type: match[10]
|
7297 | });
|
7298 | }
|
7299 |
|
7300 | formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
|
7301 |
|
7302 | function FormatSpecifier(specifier) {
|
7303 | this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
|
7304 | this.align = specifier.align === undefined ? ">" : specifier.align + "";
|
7305 | this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
|
7306 | this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
|
7307 | this.zero = !!specifier.zero;
|
7308 | this.width = specifier.width === undefined ? undefined : +specifier.width;
|
7309 | this.comma = !!specifier.comma;
|
7310 | this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
|
7311 | this.trim = !!specifier.trim;
|
7312 | this.type = specifier.type === undefined ? "" : specifier.type + "";
|
7313 | }
|
7314 |
|
7315 | FormatSpecifier.prototype.toString = function() {
|
7316 | return this.fill
|
7317 | + this.align
|
7318 | + this.sign
|
7319 | + this.symbol
|
7320 | + (this.zero ? "0" : "")
|
7321 | + (this.width === undefined ? "" : Math.max(1, this.width | 0))
|
7322 | + (this.comma ? "," : "")
|
7323 | + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
|
7324 | + (this.trim ? "~" : "")
|
7325 | + this.type;
|
7326 | };
|
7327 |
|
7328 | // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
|
7329 | function formatTrim(s) {
|
7330 | out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
|
7331 | switch (s[i]) {
|
7332 | case ".": i0 = i1 = i; break;
|
7333 | case "0": if (i0 === 0) i0 = i; i1 = i; break;
|
7334 | default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
|
7335 | }
|
7336 | }
|
7337 | return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
|
7338 | }
|
7339 |
|
7340 | var prefixExponent;
|
7341 |
|
7342 | function formatPrefixAuto(x, p) {
|
7343 | var d = formatDecimal(x, p);
|
7344 | if (!d) return x + "";
|
7345 | var coefficient = d[0],
|
7346 | exponent = d[1],
|
7347 | i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
|
7348 | n = coefficient.length;
|
7349 | return i === n ? coefficient
|
7350 | : i > n ? coefficient + new Array(i - n + 1).join("0")
|
7351 | : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
|
7352 | : "0." + new Array(1 - i).join("0") + formatDecimal(x, Math.max(0, p + i - 1))[0]; // less than 1y!
|
7353 | }
|
7354 |
|
7355 | function formatRounded(x, p) {
|
7356 | var d = formatDecimal(x, p);
|
7357 | if (!d) return x + "";
|
7358 | var coefficient = d[0],
|
7359 | exponent = d[1];
|
7360 | return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
|
7361 | : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
|
7362 | : coefficient + new Array(exponent - coefficient.length + 2).join("0");
|
7363 | }
|
7364 |
|
7365 | var formatTypes = {
|
7366 | "%": function(x, p) { return (x * 100).toFixed(p); },
|
7367 | "b": function(x) { return Math.round(x).toString(2); },
|
7368 | "c": function(x) { return x + ""; },
|
7369 | "d": function(x) { return Math.round(x).toString(10); },
|
7370 | "e": function(x, p) { return x.toExponential(p); },
|
7371 | "f": function(x, p) { return x.toFixed(p); },
|
7372 | "g": function(x, p) { return x.toPrecision(p); },
|
7373 | "o": function(x) { return Math.round(x).toString(8); },
|
7374 | "p": function(x, p) { return formatRounded(x * 100, p); },
|
7375 | "r": formatRounded,
|
7376 | "s": formatPrefixAuto,
|
7377 | "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
|
7378 | "x": function(x) { return Math.round(x).toString(16); }
|
7379 | };
|
7380 |
|
7381 | function identity$3(x) {
|
7382 | return x;
|
7383 | }
|
7384 |
|
7385 | var map$2 = Array.prototype.map,
|
7386 | prefixes = ["y","z","a","f","p","n","\xB5","m","","k","M","G","T","P","E","Z","Y"];
|
7387 |
|
7388 | function formatLocale(locale) {
|
7389 | var group = locale.grouping === undefined || locale.thousands === undefined ? identity$3 : formatGroup(map$2.call(locale.grouping, Number), locale.thousands + ""),
|
7390 | currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
|
7391 | currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
|
7392 | decimal = locale.decimal === undefined ? "." : locale.decimal + "",
|
7393 | numerals = locale.numerals === undefined ? identity$3 : formatNumerals(map$2.call(locale.numerals, String)),
|
7394 | percent = locale.percent === undefined ? "%" : locale.percent + "",
|
7395 | minus = locale.minus === undefined ? "-" : locale.minus + "",
|
7396 | nan = locale.nan === undefined ? "NaN" : locale.nan + "";
|
7397 |
|
7398 | function newFormat(specifier) {
|
7399 | specifier = formatSpecifier(specifier);
|
7400 |
|
7401 | var fill = specifier.fill,
|
7402 | align = specifier.align,
|
7403 | sign = specifier.sign,
|
7404 | symbol = specifier.symbol,
|
7405 | zero = specifier.zero,
|
7406 | width = specifier.width,
|
7407 | comma = specifier.comma,
|
7408 | precision = specifier.precision,
|
7409 | trim = specifier.trim,
|
7410 | type = specifier.type;
|
7411 |
|
7412 | // The "n" type is an alias for ",g".
|
7413 | if (type === "n") comma = true, type = "g";
|
7414 |
|
7415 | // The "" type, and any invalid type, is an alias for ".12~g".
|
7416 | else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
|
7417 |
|
7418 | // If zero fill is specified, padding goes after sign and before digits.
|
7419 | if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
|
7420 |
|
7421 | // Compute the prefix and suffix.
|
7422 | // For SI-prefix, the suffix is lazily computed.
|
7423 | var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
|
7424 | suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
|
7425 |
|
7426 | // What format function should we use?
|
7427 | // Is this an integer type?
|
7428 | // Can this type generate exponential notation?
|
7429 | var formatType = formatTypes[type],
|
7430 | maybeSuffix = /[defgprs%]/.test(type);
|
7431 |
|
7432 | // Set the default precision if not specified,
|
7433 | // or clamp the specified precision to the supported range.
|
7434 | // For significant precision, it must be in [1, 21].
|
7435 | // For fixed precision, it must be in [0, 20].
|
7436 | precision = precision === undefined ? 6
|
7437 | : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
|
7438 | : Math.max(0, Math.min(20, precision));
|
7439 |
|
7440 | function format(value) {
|
7441 | var valuePrefix = prefix,
|
7442 | valueSuffix = suffix,
|
7443 | i, n, c;
|
7444 |
|
7445 | if (type === "c") {
|
7446 | valueSuffix = formatType(value) + valueSuffix;
|
7447 | value = "";
|
7448 | } else {
|
7449 | value = +value;
|
7450 |
|
7451 | // Perform the initial formatting.
|
7452 | var valueNegative = value < 0;
|
7453 | value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
|
7454 |
|
7455 | // Trim insignificant zeros.
|
7456 | if (trim) value = formatTrim(value);
|
7457 |
|
7458 | // If a negative value rounds to zero during formatting, treat as positive.
|
7459 | if (valueNegative && +value === 0) valueNegative = false;
|
7460 |
|
7461 | // Compute the prefix and suffix.
|
7462 | valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
|
7463 |
|
7464 | valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
|
7465 |
|
7466 | // Break the formatted value into the integer “value” part that can be
|
7467 | // grouped, and fractional or exponential “suffix” part that is not.
|
7468 | if (maybeSuffix) {
|
7469 | i = -1, n = value.length;
|
7470 | while (++i < n) {
|
7471 | if (c = value.charCodeAt(i), 48 > c || c > 57) {
|
7472 | valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
|
7473 | value = value.slice(0, i);
|
7474 | break;
|
7475 | }
|
7476 | }
|
7477 | }
|
7478 | }
|
7479 |
|
7480 | // If the fill character is not "0", grouping is applied before padding.
|
7481 | if (comma && !zero) value = group(value, Infinity);
|
7482 |
|
7483 | // Compute the padding.
|
7484 | var length = valuePrefix.length + value.length + valueSuffix.length,
|
7485 | padding = length < width ? new Array(width - length + 1).join(fill) : "";
|
7486 |
|
7487 | // If the fill character is "0", grouping is applied after padding.
|
7488 | if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
|
7489 |
|
7490 | // Reconstruct the final output based on the desired alignment.
|
7491 | switch (align) {
|
7492 | case "<": value = valuePrefix + value + valueSuffix + padding; break;
|
7493 | case "=": value = valuePrefix + padding + value + valueSuffix; break;
|
7494 | case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
|
7495 | default: value = padding + valuePrefix + value + valueSuffix; break;
|
7496 | }
|
7497 |
|
7498 | return numerals(value);
|
7499 | }
|
7500 |
|
7501 | format.toString = function() {
|
7502 | return specifier + "";
|
7503 | };
|
7504 |
|
7505 | return format;
|
7506 | }
|
7507 |
|
7508 | function formatPrefix(specifier, value) {
|
7509 | var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
|
7510 | e = Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3,
|
7511 | k = Math.pow(10, -e),
|
7512 | prefix = prefixes[8 + e / 3];
|
7513 | return function(value) {
|
7514 | return f(k * value) + prefix;
|
7515 | };
|
7516 | }
|
7517 |
|
7518 | return {
|
7519 | format: newFormat,
|
7520 | formatPrefix: formatPrefix
|
7521 | };
|
7522 | }
|
7523 |
|
7524 | var locale;
|
7525 |
|
7526 | defaultLocale({
|
7527 | decimal: ".",
|
7528 | thousands: ",",
|
7529 | grouping: [3],
|
7530 | currency: ["$", ""],
|
7531 | minus: "-"
|
7532 | });
|
7533 |
|
7534 | function defaultLocale(definition) {
|
7535 | locale = formatLocale(definition);
|
7536 | exports.format = locale.format;
|
7537 | exports.formatPrefix = locale.formatPrefix;
|
7538 | return locale;
|
7539 | }
|
7540 |
|
7541 | function precisionFixed(step) {
|
7542 | return Math.max(0, -exponent$1(Math.abs(step)));
|
7543 | }
|
7544 |
|
7545 | function precisionPrefix(step, value) {
|
7546 | return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent$1(value) / 3))) * 3 - exponent$1(Math.abs(step)));
|
7547 | }
|
7548 |
|
7549 | function precisionRound(step, max) {
|
7550 | step = Math.abs(step), max = Math.abs(max) - step;
|
7551 | return Math.max(0, exponent$1(max) - exponent$1(step)) + 1;
|
7552 | }
|
7553 |
|
7554 | // Adds floating point numbers with twice the normal precision.
|
7555 | // Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
|
7556 | // Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
|
7557 | // 305–363 (1997).
|
7558 | // Code adapted from GeographicLib by Charles F. F. Karney,
|
7559 | // http://geographiclib.sourceforge.net/
|
7560 |
|
7561 | function adder() {
|
7562 | return new Adder;
|
7563 | }
|
7564 |
|
7565 | function Adder() {
|
7566 | this.reset();
|
7567 | }
|
7568 |
|
7569 | Adder.prototype = {
|
7570 | constructor: Adder,
|
7571 | reset: function() {
|
7572 | this.s = // rounded value
|
7573 | this.t = 0; // exact error
|
7574 | },
|
7575 | add: function(y) {
|
7576 | add$1(temp, y, this.t);
|
7577 | add$1(this, temp.s, this.s);
|
7578 | if (this.s) this.t += temp.t;
|
7579 | else this.s = temp.t;
|
7580 | },
|
7581 | valueOf: function() {
|
7582 | return this.s;
|
7583 | }
|
7584 | };
|
7585 |
|
7586 | var temp = new Adder;
|
7587 |
|
7588 | function add$1(adder, a, b) {
|
7589 | var x = adder.s = a + b,
|
7590 | bv = x - a,
|
7591 | av = x - bv;
|
7592 | adder.t = (a - av) + (b - bv);
|
7593 | }
|
7594 |
|
7595 | var epsilon$2 = 1e-6;
|
7596 | var epsilon2$1 = 1e-12;
|
7597 | var pi$3 = Math.PI;
|
7598 | var halfPi$2 = pi$3 / 2;
|
7599 | var quarterPi = pi$3 / 4;
|
7600 | var tau$3 = pi$3 * 2;
|
7601 |
|
7602 | var degrees$1 = 180 / pi$3;
|
7603 | var radians = pi$3 / 180;
|
7604 |
|
7605 | var abs = Math.abs;
|
7606 | var atan = Math.atan;
|
7607 | var atan2 = Math.atan2;
|
7608 | var cos$1 = Math.cos;
|
7609 | var ceil = Math.ceil;
|
7610 | var exp = Math.exp;
|
7611 | var log = Math.log;
|
7612 | var pow = Math.pow;
|
7613 | var sin$1 = Math.sin;
|
7614 | var sign = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; };
|
7615 | var sqrt = Math.sqrt;
|
7616 | var tan = Math.tan;
|
7617 |
|
7618 | function acos(x) {
|
7619 | return x > 1 ? 0 : x < -1 ? pi$3 : Math.acos(x);
|
7620 | }
|
7621 |
|
7622 | function asin(x) {
|
7623 | return x > 1 ? halfPi$2 : x < -1 ? -halfPi$2 : Math.asin(x);
|
7624 | }
|
7625 |
|
7626 | function haversin(x) {
|
7627 | return (x = sin$1(x / 2)) * x;
|
7628 | }
|
7629 |
|
7630 | function noop$2() {}
|
7631 |
|
7632 | function streamGeometry(geometry, stream) {
|
7633 | if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
|
7634 | streamGeometryType[geometry.type](geometry, stream);
|
7635 | }
|
7636 | }
|
7637 |
|
7638 | var streamObjectType = {
|
7639 | Feature: function(object, stream) {
|
7640 | streamGeometry(object.geometry, stream);
|
7641 | },
|
7642 | FeatureCollection: function(object, stream) {
|
7643 | var features = object.features, i = -1, n = features.length;
|
7644 | while (++i < n) streamGeometry(features[i].geometry, stream);
|
7645 | }
|
7646 | };
|
7647 |
|
7648 | var streamGeometryType = {
|
7649 | Sphere: function(object, stream) {
|
7650 | stream.sphere();
|
7651 | },
|
7652 | Point: function(object, stream) {
|
7653 | object = object.coordinates;
|
7654 | stream.point(object[0], object[1], object[2]);
|
7655 | },
|
7656 | MultiPoint: function(object, stream) {
|
7657 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
7658 | while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
|
7659 | },
|
7660 | LineString: function(object, stream) {
|
7661 | streamLine(object.coordinates, stream, 0);
|
7662 | },
|
7663 | MultiLineString: function(object, stream) {
|
7664 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
7665 | while (++i < n) streamLine(coordinates[i], stream, 0);
|
7666 | },
|
7667 | Polygon: function(object, stream) {
|
7668 | streamPolygon(object.coordinates, stream);
|
7669 | },
|
7670 | MultiPolygon: function(object, stream) {
|
7671 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
7672 | while (++i < n) streamPolygon(coordinates[i], stream);
|
7673 | },
|
7674 | GeometryCollection: function(object, stream) {
|
7675 | var geometries = object.geometries, i = -1, n = geometries.length;
|
7676 | while (++i < n) streamGeometry(geometries[i], stream);
|
7677 | }
|
7678 | };
|
7679 |
|
7680 | function streamLine(coordinates, stream, closed) {
|
7681 | var i = -1, n = coordinates.length - closed, coordinate;
|
7682 | stream.lineStart();
|
7683 | while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
|
7684 | stream.lineEnd();
|
7685 | }
|
7686 |
|
7687 | function streamPolygon(coordinates, stream) {
|
7688 | var i = -1, n = coordinates.length;
|
7689 | stream.polygonStart();
|
7690 | while (++i < n) streamLine(coordinates[i], stream, 1);
|
7691 | stream.polygonEnd();
|
7692 | }
|
7693 |
|
7694 | function geoStream(object, stream) {
|
7695 | if (object && streamObjectType.hasOwnProperty(object.type)) {
|
7696 | streamObjectType[object.type](object, stream);
|
7697 | } else {
|
7698 | streamGeometry(object, stream);
|
7699 | }
|
7700 | }
|
7701 |
|
7702 | var areaRingSum = adder();
|
7703 |
|
7704 | var areaSum = adder(),
|
7705 | lambda00,
|
7706 | phi00,
|
7707 | lambda0,
|
7708 | cosPhi0,
|
7709 | sinPhi0;
|
7710 |
|
7711 | var areaStream = {
|
7712 | point: noop$2,
|
7713 | lineStart: noop$2,
|
7714 | lineEnd: noop$2,
|
7715 | polygonStart: function() {
|
7716 | areaRingSum.reset();
|
7717 | areaStream.lineStart = areaRingStart;
|
7718 | areaStream.lineEnd = areaRingEnd;
|
7719 | },
|
7720 | polygonEnd: function() {
|
7721 | var areaRing = +areaRingSum;
|
7722 | areaSum.add(areaRing < 0 ? tau$3 + areaRing : areaRing);
|
7723 | this.lineStart = this.lineEnd = this.point = noop$2;
|
7724 | },
|
7725 | sphere: function() {
|
7726 | areaSum.add(tau$3);
|
7727 | }
|
7728 | };
|
7729 |
|
7730 | function areaRingStart() {
|
7731 | areaStream.point = areaPointFirst;
|
7732 | }
|
7733 |
|
7734 | function areaRingEnd() {
|
7735 | areaPoint(lambda00, phi00);
|
7736 | }
|
7737 |
|
7738 | function areaPointFirst(lambda, phi) {
|
7739 | areaStream.point = areaPoint;
|
7740 | lambda00 = lambda, phi00 = phi;
|
7741 | lambda *= radians, phi *= radians;
|
7742 | lambda0 = lambda, cosPhi0 = cos$1(phi = phi / 2 + quarterPi), sinPhi0 = sin$1(phi);
|
7743 | }
|
7744 |
|
7745 | function areaPoint(lambda, phi) {
|
7746 | lambda *= radians, phi *= radians;
|
7747 | phi = phi / 2 + quarterPi; // half the angular distance from south pole
|
7748 |
|
7749 | // Spherical excess E for a spherical triangle with vertices: south pole,
|
7750 | // previous point, current point. Uses a formula derived from Cagnoli’s
|
7751 | // theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2).
|
7752 | var dLambda = lambda - lambda0,
|
7753 | sdLambda = dLambda >= 0 ? 1 : -1,
|
7754 | adLambda = sdLambda * dLambda,
|
7755 | cosPhi = cos$1(phi),
|
7756 | sinPhi = sin$1(phi),
|
7757 | k = sinPhi0 * sinPhi,
|
7758 | u = cosPhi0 * cosPhi + k * cos$1(adLambda),
|
7759 | v = k * sdLambda * sin$1(adLambda);
|
7760 | areaRingSum.add(atan2(v, u));
|
7761 |
|
7762 | // Advance the previous points.
|
7763 | lambda0 = lambda, cosPhi0 = cosPhi, sinPhi0 = sinPhi;
|
7764 | }
|
7765 |
|
7766 | function area$1(object) {
|
7767 | areaSum.reset();
|
7768 | geoStream(object, areaStream);
|
7769 | return areaSum * 2;
|
7770 | }
|
7771 |
|
7772 | function spherical(cartesian) {
|
7773 | return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
|
7774 | }
|
7775 |
|
7776 | function cartesian(spherical) {
|
7777 | var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi);
|
7778 | return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)];
|
7779 | }
|
7780 |
|
7781 | function cartesianDot(a, b) {
|
7782 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
7783 | }
|
7784 |
|
7785 | function cartesianCross(a, b) {
|
7786 | 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]];
|
7787 | }
|
7788 |
|
7789 | // TODO return a
|
7790 | function cartesianAddInPlace(a, b) {
|
7791 | a[0] += b[0], a[1] += b[1], a[2] += b[2];
|
7792 | }
|
7793 |
|
7794 | function cartesianScale(vector, k) {
|
7795 | return [vector[0] * k, vector[1] * k, vector[2] * k];
|
7796 | }
|
7797 |
|
7798 | // TODO return d
|
7799 | function cartesianNormalizeInPlace(d) {
|
7800 | var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
|
7801 | d[0] /= l, d[1] /= l, d[2] /= l;
|
7802 | }
|
7803 |
|
7804 | var lambda0$1, phi0, lambda1, phi1, // bounds
|
7805 | lambda2, // previous lambda-coordinate
|
7806 | lambda00$1, phi00$1, // first point
|
7807 | p0, // previous 3D point
|
7808 | deltaSum = adder(),
|
7809 | ranges,
|
7810 | range;
|
7811 |
|
7812 | var boundsStream = {
|
7813 | point: boundsPoint,
|
7814 | lineStart: boundsLineStart,
|
7815 | lineEnd: boundsLineEnd,
|
7816 | polygonStart: function() {
|
7817 | boundsStream.point = boundsRingPoint;
|
7818 | boundsStream.lineStart = boundsRingStart;
|
7819 | boundsStream.lineEnd = boundsRingEnd;
|
7820 | deltaSum.reset();
|
7821 | areaStream.polygonStart();
|
7822 | },
|
7823 | polygonEnd: function() {
|
7824 | areaStream.polygonEnd();
|
7825 | boundsStream.point = boundsPoint;
|
7826 | boundsStream.lineStart = boundsLineStart;
|
7827 | boundsStream.lineEnd = boundsLineEnd;
|
7828 | if (areaRingSum < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
|
7829 | else if (deltaSum > epsilon$2) phi1 = 90;
|
7830 | else if (deltaSum < -epsilon$2) phi0 = -90;
|
7831 | range[0] = lambda0$1, range[1] = lambda1;
|
7832 | },
|
7833 | sphere: function() {
|
7834 | lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90);
|
7835 | }
|
7836 | };
|
7837 |
|
7838 | function boundsPoint(lambda, phi) {
|
7839 | ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
|
7840 | if (phi < phi0) phi0 = phi;
|
7841 | if (phi > phi1) phi1 = phi;
|
7842 | }
|
7843 |
|
7844 | function linePoint(lambda, phi) {
|
7845 | var p = cartesian([lambda * radians, phi * radians]);
|
7846 | if (p0) {
|
7847 | var normal = cartesianCross(p0, p),
|
7848 | equatorial = [normal[1], -normal[0], 0],
|
7849 | inflection = cartesianCross(equatorial, normal);
|
7850 | cartesianNormalizeInPlace(inflection);
|
7851 | inflection = spherical(inflection);
|
7852 | var delta = lambda - lambda2,
|
7853 | sign = delta > 0 ? 1 : -1,
|
7854 | lambdai = inflection[0] * degrees$1 * sign,
|
7855 | phii,
|
7856 | antimeridian = abs(delta) > 180;
|
7857 | if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
|
7858 | phii = inflection[1] * degrees$1;
|
7859 | if (phii > phi1) phi1 = phii;
|
7860 | } else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) {
|
7861 | phii = -inflection[1] * degrees$1;
|
7862 | if (phii < phi0) phi0 = phii;
|
7863 | } else {
|
7864 | if (phi < phi0) phi0 = phi;
|
7865 | if (phi > phi1) phi1 = phi;
|
7866 | }
|
7867 | if (antimeridian) {
|
7868 | if (lambda < lambda2) {
|
7869 | if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
|
7870 | } else {
|
7871 | if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
|
7872 | }
|
7873 | } else {
|
7874 | if (lambda1 >= lambda0$1) {
|
7875 | if (lambda < lambda0$1) lambda0$1 = lambda;
|
7876 | if (lambda > lambda1) lambda1 = lambda;
|
7877 | } else {
|
7878 | if (lambda > lambda2) {
|
7879 | if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda;
|
7880 | } else {
|
7881 | if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda;
|
7882 | }
|
7883 | }
|
7884 | }
|
7885 | } else {
|
7886 | ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]);
|
7887 | }
|
7888 | if (phi < phi0) phi0 = phi;
|
7889 | if (phi > phi1) phi1 = phi;
|
7890 | p0 = p, lambda2 = lambda;
|
7891 | }
|
7892 |
|
7893 | function boundsLineStart() {
|
7894 | boundsStream.point = linePoint;
|
7895 | }
|
7896 |
|
7897 | function boundsLineEnd() {
|
7898 | range[0] = lambda0$1, range[1] = lambda1;
|
7899 | boundsStream.point = boundsPoint;
|
7900 | p0 = null;
|
7901 | }
|
7902 |
|
7903 | function boundsRingPoint(lambda, phi) {
|
7904 | if (p0) {
|
7905 | var delta = lambda - lambda2;
|
7906 | deltaSum.add(abs(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta);
|
7907 | } else {
|
7908 | lambda00$1 = lambda, phi00$1 = phi;
|
7909 | }
|
7910 | areaStream.point(lambda, phi);
|
7911 | linePoint(lambda, phi);
|
7912 | }
|
7913 |
|
7914 | function boundsRingStart() {
|
7915 | areaStream.lineStart();
|
7916 | }
|
7917 |
|
7918 | function boundsRingEnd() {
|
7919 | boundsRingPoint(lambda00$1, phi00$1);
|
7920 | areaStream.lineEnd();
|
7921 | if (abs(deltaSum) > epsilon$2) lambda0$1 = -(lambda1 = 180);
|
7922 | range[0] = lambda0$1, range[1] = lambda1;
|
7923 | p0 = null;
|
7924 | }
|
7925 |
|
7926 | // Finds the left-right distance between two longitudes.
|
7927 | // This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want
|
7928 | // the distance between ±180° to be 360°.
|
7929 | function angle(lambda0, lambda1) {
|
7930 | return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1;
|
7931 | }
|
7932 |
|
7933 | function rangeCompare(a, b) {
|
7934 | return a[0] - b[0];
|
7935 | }
|
7936 |
|
7937 | function rangeContains(range, x) {
|
7938 | return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
|
7939 | }
|
7940 |
|
7941 | function bounds(feature) {
|
7942 | var i, n, a, b, merged, deltaMax, delta;
|
7943 |
|
7944 | phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity);
|
7945 | ranges = [];
|
7946 | geoStream(feature, boundsStream);
|
7947 |
|
7948 | // First, sort ranges by their minimum longitudes.
|
7949 | if (n = ranges.length) {
|
7950 | ranges.sort(rangeCompare);
|
7951 |
|
7952 | // Then, merge any ranges that overlap.
|
7953 | for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) {
|
7954 | b = ranges[i];
|
7955 | if (rangeContains(a, b[0]) || rangeContains(a, b[1])) {
|
7956 | if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
|
7957 | if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
|
7958 | } else {
|
7959 | merged.push(a = b);
|
7960 | }
|
7961 | }
|
7962 |
|
7963 | // Finally, find the largest gap between the merged ranges.
|
7964 | // The final bounding box will be the inverse of this gap.
|
7965 | for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) {
|
7966 | b = merged[i];
|
7967 | if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1];
|
7968 | }
|
7969 | }
|
7970 |
|
7971 | ranges = range = null;
|
7972 |
|
7973 | return lambda0$1 === Infinity || phi0 === Infinity
|
7974 | ? [[NaN, NaN], [NaN, NaN]]
|
7975 | : [[lambda0$1, phi0], [lambda1, phi1]];
|
7976 | }
|
7977 |
|
7978 | var W0, W1,
|
7979 | X0, Y0, Z0,
|
7980 | X1, Y1, Z1,
|
7981 | X2, Y2, Z2,
|
7982 | lambda00$2, phi00$2, // first point
|
7983 | x0, y0, z0; // previous point
|
7984 |
|
7985 | var centroidStream = {
|
7986 | sphere: noop$2,
|
7987 | point: centroidPoint,
|
7988 | lineStart: centroidLineStart,
|
7989 | lineEnd: centroidLineEnd,
|
7990 | polygonStart: function() {
|
7991 | centroidStream.lineStart = centroidRingStart;
|
7992 | centroidStream.lineEnd = centroidRingEnd;
|
7993 | },
|
7994 | polygonEnd: function() {
|
7995 | centroidStream.lineStart = centroidLineStart;
|
7996 | centroidStream.lineEnd = centroidLineEnd;
|
7997 | }
|
7998 | };
|
7999 |
|
8000 | // Arithmetic mean of Cartesian vectors.
|
8001 | function centroidPoint(lambda, phi) {
|
8002 | lambda *= radians, phi *= radians;
|
8003 | var cosPhi = cos$1(phi);
|
8004 | centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi));
|
8005 | }
|
8006 |
|
8007 | function centroidPointCartesian(x, y, z) {
|
8008 | ++W0;
|
8009 | X0 += (x - X0) / W0;
|
8010 | Y0 += (y - Y0) / W0;
|
8011 | Z0 += (z - Z0) / W0;
|
8012 | }
|
8013 |
|
8014 | function centroidLineStart() {
|
8015 | centroidStream.point = centroidLinePointFirst;
|
8016 | }
|
8017 |
|
8018 | function centroidLinePointFirst(lambda, phi) {
|
8019 | lambda *= radians, phi *= radians;
|
8020 | var cosPhi = cos$1(phi);
|
8021 | x0 = cosPhi * cos$1(lambda);
|
8022 | y0 = cosPhi * sin$1(lambda);
|
8023 | z0 = sin$1(phi);
|
8024 | centroidStream.point = centroidLinePoint;
|
8025 | centroidPointCartesian(x0, y0, z0);
|
8026 | }
|
8027 |
|
8028 | function centroidLinePoint(lambda, phi) {
|
8029 | lambda *= radians, phi *= radians;
|
8030 | var cosPhi = cos$1(phi),
|
8031 | x = cosPhi * cos$1(lambda),
|
8032 | y = cosPhi * sin$1(lambda),
|
8033 | z = sin$1(phi),
|
8034 | w = atan2(sqrt((w = y0 * z - z0 * y) * w + (w = z0 * x - x0 * z) * w + (w = x0 * y - y0 * x) * w), x0 * x + y0 * y + z0 * z);
|
8035 | W1 += w;
|
8036 | X1 += w * (x0 + (x0 = x));
|
8037 | Y1 += w * (y0 + (y0 = y));
|
8038 | Z1 += w * (z0 + (z0 = z));
|
8039 | centroidPointCartesian(x0, y0, z0);
|
8040 | }
|
8041 |
|
8042 | function centroidLineEnd() {
|
8043 | centroidStream.point = centroidPoint;
|
8044 | }
|
8045 |
|
8046 | // See J. E. Brock, The Inertia Tensor for a Spherical Triangle,
|
8047 | // J. Applied Mechanics 42, 239 (1975).
|
8048 | function centroidRingStart() {
|
8049 | centroidStream.point = centroidRingPointFirst;
|
8050 | }
|
8051 |
|
8052 | function centroidRingEnd() {
|
8053 | centroidRingPoint(lambda00$2, phi00$2);
|
8054 | centroidStream.point = centroidPoint;
|
8055 | }
|
8056 |
|
8057 | function centroidRingPointFirst(lambda, phi) {
|
8058 | lambda00$2 = lambda, phi00$2 = phi;
|
8059 | lambda *= radians, phi *= radians;
|
8060 | centroidStream.point = centroidRingPoint;
|
8061 | var cosPhi = cos$1(phi);
|
8062 | x0 = cosPhi * cos$1(lambda);
|
8063 | y0 = cosPhi * sin$1(lambda);
|
8064 | z0 = sin$1(phi);
|
8065 | centroidPointCartesian(x0, y0, z0);
|
8066 | }
|
8067 |
|
8068 | function centroidRingPoint(lambda, phi) {
|
8069 | lambda *= radians, phi *= radians;
|
8070 | var cosPhi = cos$1(phi),
|
8071 | x = cosPhi * cos$1(lambda),
|
8072 | y = cosPhi * sin$1(lambda),
|
8073 | z = sin$1(phi),
|
8074 | cx = y0 * z - z0 * y,
|
8075 | cy = z0 * x - x0 * z,
|
8076 | cz = x0 * y - y0 * x,
|
8077 | m = sqrt(cx * cx + cy * cy + cz * cz),
|
8078 | w = asin(m), // line weight = angle
|
8079 | v = m && -w / m; // area weight multiplier
|
8080 | X2 += v * cx;
|
8081 | Y2 += v * cy;
|
8082 | Z2 += v * cz;
|
8083 | W1 += w;
|
8084 | X1 += w * (x0 + (x0 = x));
|
8085 | Y1 += w * (y0 + (y0 = y));
|
8086 | Z1 += w * (z0 + (z0 = z));
|
8087 | centroidPointCartesian(x0, y0, z0);
|
8088 | }
|
8089 |
|
8090 | function centroid(object) {
|
8091 | W0 = W1 =
|
8092 | X0 = Y0 = Z0 =
|
8093 | X1 = Y1 = Z1 =
|
8094 | X2 = Y2 = Z2 = 0;
|
8095 | geoStream(object, centroidStream);
|
8096 |
|
8097 | var x = X2,
|
8098 | y = Y2,
|
8099 | z = Z2,
|
8100 | m = x * x + y * y + z * z;
|
8101 |
|
8102 | // If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid.
|
8103 | if (m < epsilon2$1) {
|
8104 | x = X1, y = Y1, z = Z1;
|
8105 | // If the feature has zero length, fall back to arithmetic mean of point vectors.
|
8106 | if (W1 < epsilon$2) x = X0, y = Y0, z = Z0;
|
8107 | m = x * x + y * y + z * z;
|
8108 | // If the feature still has an undefined ccentroid, then return.
|
8109 | if (m < epsilon2$1) return [NaN, NaN];
|
8110 | }
|
8111 |
|
8112 | return [atan2(y, x) * degrees$1, asin(z / sqrt(m)) * degrees$1];
|
8113 | }
|
8114 |
|
8115 | function constant$8(x) {
|
8116 | return function() {
|
8117 | return x;
|
8118 | };
|
8119 | }
|
8120 |
|
8121 | function compose(a, b) {
|
8122 |
|
8123 | function compose(x, y) {
|
8124 | return x = a(x, y), b(x[0], x[1]);
|
8125 | }
|
8126 |
|
8127 | if (a.invert && b.invert) compose.invert = function(x, y) {
|
8128 | return x = b.invert(x, y), x && a.invert(x[0], x[1]);
|
8129 | };
|
8130 |
|
8131 | return compose;
|
8132 | }
|
8133 |
|
8134 | function rotationIdentity(lambda, phi) {
|
8135 | return [abs(lambda) > pi$3 ? lambda + Math.round(-lambda / tau$3) * tau$3 : lambda, phi];
|
8136 | }
|
8137 |
|
8138 | rotationIdentity.invert = rotationIdentity;
|
8139 |
|
8140 | function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
|
8141 | return (deltaLambda %= tau$3) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
|
8142 | : rotationLambda(deltaLambda))
|
8143 | : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
|
8144 | : rotationIdentity);
|
8145 | }
|
8146 |
|
8147 | function forwardRotationLambda(deltaLambda) {
|
8148 | return function(lambda, phi) {
|
8149 | return lambda += deltaLambda, [lambda > pi$3 ? lambda - tau$3 : lambda < -pi$3 ? lambda + tau$3 : lambda, phi];
|
8150 | };
|
8151 | }
|
8152 |
|
8153 | function rotationLambda(deltaLambda) {
|
8154 | var rotation = forwardRotationLambda(deltaLambda);
|
8155 | rotation.invert = forwardRotationLambda(-deltaLambda);
|
8156 | return rotation;
|
8157 | }
|
8158 |
|
8159 | function rotationPhiGamma(deltaPhi, deltaGamma) {
|
8160 | var cosDeltaPhi = cos$1(deltaPhi),
|
8161 | sinDeltaPhi = sin$1(deltaPhi),
|
8162 | cosDeltaGamma = cos$1(deltaGamma),
|
8163 | sinDeltaGamma = sin$1(deltaGamma);
|
8164 |
|
8165 | function rotation(lambda, phi) {
|
8166 | var cosPhi = cos$1(phi),
|
8167 | x = cos$1(lambda) * cosPhi,
|
8168 | y = sin$1(lambda) * cosPhi,
|
8169 | z = sin$1(phi),
|
8170 | k = z * cosDeltaPhi + x * sinDeltaPhi;
|
8171 | return [
|
8172 | atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
|
8173 | asin(k * cosDeltaGamma + y * sinDeltaGamma)
|
8174 | ];
|
8175 | }
|
8176 |
|
8177 | rotation.invert = function(lambda, phi) {
|
8178 | var cosPhi = cos$1(phi),
|
8179 | x = cos$1(lambda) * cosPhi,
|
8180 | y = sin$1(lambda) * cosPhi,
|
8181 | z = sin$1(phi),
|
8182 | k = z * cosDeltaGamma - y * sinDeltaGamma;
|
8183 | return [
|
8184 | atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
|
8185 | asin(k * cosDeltaPhi - x * sinDeltaPhi)
|
8186 | ];
|
8187 | };
|
8188 |
|
8189 | return rotation;
|
8190 | }
|
8191 |
|
8192 | function rotation(rotate) {
|
8193 | rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
|
8194 |
|
8195 | function forward(coordinates) {
|
8196 | coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
|
8197 | return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
|
8198 | }
|
8199 |
|
8200 | forward.invert = function(coordinates) {
|
8201 | coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
|
8202 | return coordinates[0] *= degrees$1, coordinates[1] *= degrees$1, coordinates;
|
8203 | };
|
8204 |
|
8205 | return forward;
|
8206 | }
|
8207 |
|
8208 | // Generates a circle centered at [0°, 0°], with a given radius and precision.
|
8209 | function circleStream(stream, radius, delta, direction, t0, t1) {
|
8210 | if (!delta) return;
|
8211 | var cosRadius = cos$1(radius),
|
8212 | sinRadius = sin$1(radius),
|
8213 | step = direction * delta;
|
8214 | if (t0 == null) {
|
8215 | t0 = radius + direction * tau$3;
|
8216 | t1 = radius - step / 2;
|
8217 | } else {
|
8218 | t0 = circleRadius(cosRadius, t0);
|
8219 | t1 = circleRadius(cosRadius, t1);
|
8220 | if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$3;
|
8221 | }
|
8222 | for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
|
8223 | point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]);
|
8224 | stream.point(point[0], point[1]);
|
8225 | }
|
8226 | }
|
8227 |
|
8228 | // Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0].
|
8229 | function circleRadius(cosRadius, point) {
|
8230 | point = cartesian(point), point[0] -= cosRadius;
|
8231 | cartesianNormalizeInPlace(point);
|
8232 | var radius = acos(-point[1]);
|
8233 | return ((-point[2] < 0 ? -radius : radius) + tau$3 - epsilon$2) % tau$3;
|
8234 | }
|
8235 |
|
8236 | function circle() {
|
8237 | var center = constant$8([0, 0]),
|
8238 | radius = constant$8(90),
|
8239 | precision = constant$8(6),
|
8240 | ring,
|
8241 | rotate,
|
8242 | stream = {point: point};
|
8243 |
|
8244 | function point(x, y) {
|
8245 | ring.push(x = rotate(x, y));
|
8246 | x[0] *= degrees$1, x[1] *= degrees$1;
|
8247 | }
|
8248 |
|
8249 | function circle() {
|
8250 | var c = center.apply(this, arguments),
|
8251 | r = radius.apply(this, arguments) * radians,
|
8252 | p = precision.apply(this, arguments) * radians;
|
8253 | ring = [];
|
8254 | rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert;
|
8255 | circleStream(stream, r, p, 1);
|
8256 | c = {type: "Polygon", coordinates: [ring]};
|
8257 | ring = rotate = null;
|
8258 | return c;
|
8259 | }
|
8260 |
|
8261 | circle.center = function(_) {
|
8262 | return arguments.length ? (center = typeof _ === "function" ? _ : constant$8([+_[0], +_[1]]), circle) : center;
|
8263 | };
|
8264 |
|
8265 | circle.radius = function(_) {
|
8266 | return arguments.length ? (radius = typeof _ === "function" ? _ : constant$8(+_), circle) : radius;
|
8267 | };
|
8268 |
|
8269 | circle.precision = function(_) {
|
8270 | return arguments.length ? (precision = typeof _ === "function" ? _ : constant$8(+_), circle) : precision;
|
8271 | };
|
8272 |
|
8273 | return circle;
|
8274 | }
|
8275 |
|
8276 | function clipBuffer() {
|
8277 | var lines = [],
|
8278 | line;
|
8279 | return {
|
8280 | point: function(x, y) {
|
8281 | line.push([x, y]);
|
8282 | },
|
8283 | lineStart: function() {
|
8284 | lines.push(line = []);
|
8285 | },
|
8286 | lineEnd: noop$2,
|
8287 | rejoin: function() {
|
8288 | if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
|
8289 | },
|
8290 | result: function() {
|
8291 | var result = lines;
|
8292 | lines = [];
|
8293 | line = null;
|
8294 | return result;
|
8295 | }
|
8296 | };
|
8297 | }
|
8298 |
|
8299 | function pointEqual(a, b) {
|
8300 | return abs(a[0] - b[0]) < epsilon$2 && abs(a[1] - b[1]) < epsilon$2;
|
8301 | }
|
8302 |
|
8303 | function Intersection(point, points, other, entry) {
|
8304 | this.x = point;
|
8305 | this.z = points;
|
8306 | this.o = other; // another intersection
|
8307 | this.e = entry; // is an entry?
|
8308 | this.v = false; // visited
|
8309 | this.n = this.p = null; // next & previous
|
8310 | }
|
8311 |
|
8312 | // A generalized polygon clipping algorithm: given a polygon that has been cut
|
8313 | // into its visible line segments, and rejoins the segments by interpolating
|
8314 | // along the clip edge.
|
8315 | function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) {
|
8316 | var subject = [],
|
8317 | clip = [],
|
8318 | i,
|
8319 | n;
|
8320 |
|
8321 | segments.forEach(function(segment) {
|
8322 | if ((n = segment.length - 1) <= 0) return;
|
8323 | var n, p0 = segment[0], p1 = segment[n], x;
|
8324 |
|
8325 | // If the first and last points of a segment are coincident, then treat as a
|
8326 | // closed ring. TODO if all rings are closed, then the winding order of the
|
8327 | // exterior ring should be checked.
|
8328 | if (pointEqual(p0, p1)) {
|
8329 | stream.lineStart();
|
8330 | for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
|
8331 | stream.lineEnd();
|
8332 | return;
|
8333 | }
|
8334 |
|
8335 | subject.push(x = new Intersection(p0, segment, null, true));
|
8336 | clip.push(x.o = new Intersection(p0, null, x, false));
|
8337 | subject.push(x = new Intersection(p1, segment, null, false));
|
8338 | clip.push(x.o = new Intersection(p1, null, x, true));
|
8339 | });
|
8340 |
|
8341 | if (!subject.length) return;
|
8342 |
|
8343 | clip.sort(compareIntersection);
|
8344 | link$1(subject);
|
8345 | link$1(clip);
|
8346 |
|
8347 | for (i = 0, n = clip.length; i < n; ++i) {
|
8348 | clip[i].e = startInside = !startInside;
|
8349 | }
|
8350 |
|
8351 | var start = subject[0],
|
8352 | points,
|
8353 | point;
|
8354 |
|
8355 | while (1) {
|
8356 | // Find first unvisited intersection.
|
8357 | var current = start,
|
8358 | isSubject = true;
|
8359 | while (current.v) if ((current = current.n) === start) return;
|
8360 | points = current.z;
|
8361 | stream.lineStart();
|
8362 | do {
|
8363 | current.v = current.o.v = true;
|
8364 | if (current.e) {
|
8365 | if (isSubject) {
|
8366 | for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
|
8367 | } else {
|
8368 | interpolate(current.x, current.n.x, 1, stream);
|
8369 | }
|
8370 | current = current.n;
|
8371 | } else {
|
8372 | if (isSubject) {
|
8373 | points = current.p.z;
|
8374 | for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
|
8375 | } else {
|
8376 | interpolate(current.x, current.p.x, -1, stream);
|
8377 | }
|
8378 | current = current.p;
|
8379 | }
|
8380 | current = current.o;
|
8381 | points = current.z;
|
8382 | isSubject = !isSubject;
|
8383 | } while (!current.v);
|
8384 | stream.lineEnd();
|
8385 | }
|
8386 | }
|
8387 |
|
8388 | function link$1(array) {
|
8389 | if (!(n = array.length)) return;
|
8390 | var n,
|
8391 | i = 0,
|
8392 | a = array[0],
|
8393 | b;
|
8394 | while (++i < n) {
|
8395 | a.n = b = array[i];
|
8396 | b.p = a;
|
8397 | a = b;
|
8398 | }
|
8399 | a.n = b = array[0];
|
8400 | b.p = a;
|
8401 | }
|
8402 |
|
8403 | var sum$1 = adder();
|
8404 |
|
8405 | function longitude(point) {
|
8406 | if (abs(point[0]) <= pi$3)
|
8407 | return point[0];
|
8408 | else
|
8409 | return sign(point[0]) * ((abs(point[0]) + pi$3) % tau$3 - pi$3);
|
8410 | }
|
8411 |
|
8412 | function polygonContains(polygon, point) {
|
8413 | var lambda = longitude(point),
|
8414 | phi = point[1],
|
8415 | sinPhi = sin$1(phi),
|
8416 | normal = [sin$1(lambda), -cos$1(lambda), 0],
|
8417 | angle = 0,
|
8418 | winding = 0;
|
8419 |
|
8420 | sum$1.reset();
|
8421 |
|
8422 | if (sinPhi === 1) phi = halfPi$2 + epsilon$2;
|
8423 | else if (sinPhi === -1) phi = -halfPi$2 - epsilon$2;
|
8424 |
|
8425 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
8426 | if (!(m = (ring = polygon[i]).length)) continue;
|
8427 | var ring,
|
8428 | m,
|
8429 | point0 = ring[m - 1],
|
8430 | lambda0 = longitude(point0),
|
8431 | phi0 = point0[1] / 2 + quarterPi,
|
8432 | sinPhi0 = sin$1(phi0),
|
8433 | cosPhi0 = cos$1(phi0);
|
8434 |
|
8435 | for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
|
8436 | var point1 = ring[j],
|
8437 | lambda1 = longitude(point1),
|
8438 | phi1 = point1[1] / 2 + quarterPi,
|
8439 | sinPhi1 = sin$1(phi1),
|
8440 | cosPhi1 = cos$1(phi1),
|
8441 | delta = lambda1 - lambda0,
|
8442 | sign = delta >= 0 ? 1 : -1,
|
8443 | absDelta = sign * delta,
|
8444 | antimeridian = absDelta > pi$3,
|
8445 | k = sinPhi0 * sinPhi1;
|
8446 |
|
8447 | sum$1.add(atan2(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta)));
|
8448 | angle += antimeridian ? delta + sign * tau$3 : delta;
|
8449 |
|
8450 | // Are the longitudes either side of the point’s meridian (lambda),
|
8451 | // and are the latitudes smaller than the parallel (phi)?
|
8452 | if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
|
8453 | var arc = cartesianCross(cartesian(point0), cartesian(point1));
|
8454 | cartesianNormalizeInPlace(arc);
|
8455 | var intersection = cartesianCross(normal, arc);
|
8456 | cartesianNormalizeInPlace(intersection);
|
8457 | var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
|
8458 | if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
|
8459 | winding += antimeridian ^ delta >= 0 ? 1 : -1;
|
8460 | }
|
8461 | }
|
8462 | }
|
8463 | }
|
8464 |
|
8465 | // First, determine whether the South pole is inside or outside:
|
8466 | //
|
8467 | // It is inside if:
|
8468 | // * the polygon winds around it in a clockwise direction.
|
8469 | // * the polygon does not (cumulatively) wind around it, but has a negative
|
8470 | // (counter-clockwise) area.
|
8471 | //
|
8472 | // Second, count the (signed) number of times a segment crosses a lambda
|
8473 | // from the point to the South pole. If it is zero, then the point is the
|
8474 | // same side as the South pole.
|
8475 |
|
8476 | return (angle < -epsilon$2 || angle < epsilon$2 && sum$1 < -epsilon$2) ^ (winding & 1);
|
8477 | }
|
8478 |
|
8479 | function clip(pointVisible, clipLine, interpolate, start) {
|
8480 | return function(sink) {
|
8481 | var line = clipLine(sink),
|
8482 | ringBuffer = clipBuffer(),
|
8483 | ringSink = clipLine(ringBuffer),
|
8484 | polygonStarted = false,
|
8485 | polygon,
|
8486 | segments,
|
8487 | ring;
|
8488 |
|
8489 | var clip = {
|
8490 | point: point,
|
8491 | lineStart: lineStart,
|
8492 | lineEnd: lineEnd,
|
8493 | polygonStart: function() {
|
8494 | clip.point = pointRing;
|
8495 | clip.lineStart = ringStart;
|
8496 | clip.lineEnd = ringEnd;
|
8497 | segments = [];
|
8498 | polygon = [];
|
8499 | },
|
8500 | polygonEnd: function() {
|
8501 | clip.point = point;
|
8502 | clip.lineStart = lineStart;
|
8503 | clip.lineEnd = lineEnd;
|
8504 | segments = merge(segments);
|
8505 | var startInside = polygonContains(polygon, start);
|
8506 | if (segments.length) {
|
8507 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
8508 | clipRejoin(segments, compareIntersection, startInside, interpolate, sink);
|
8509 | } else if (startInside) {
|
8510 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
8511 | sink.lineStart();
|
8512 | interpolate(null, null, 1, sink);
|
8513 | sink.lineEnd();
|
8514 | }
|
8515 | if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
|
8516 | segments = polygon = null;
|
8517 | },
|
8518 | sphere: function() {
|
8519 | sink.polygonStart();
|
8520 | sink.lineStart();
|
8521 | interpolate(null, null, 1, sink);
|
8522 | sink.lineEnd();
|
8523 | sink.polygonEnd();
|
8524 | }
|
8525 | };
|
8526 |
|
8527 | function point(lambda, phi) {
|
8528 | if (pointVisible(lambda, phi)) sink.point(lambda, phi);
|
8529 | }
|
8530 |
|
8531 | function pointLine(lambda, phi) {
|
8532 | line.point(lambda, phi);
|
8533 | }
|
8534 |
|
8535 | function lineStart() {
|
8536 | clip.point = pointLine;
|
8537 | line.lineStart();
|
8538 | }
|
8539 |
|
8540 | function lineEnd() {
|
8541 | clip.point = point;
|
8542 | line.lineEnd();
|
8543 | }
|
8544 |
|
8545 | function pointRing(lambda, phi) {
|
8546 | ring.push([lambda, phi]);
|
8547 | ringSink.point(lambda, phi);
|
8548 | }
|
8549 |
|
8550 | function ringStart() {
|
8551 | ringSink.lineStart();
|
8552 | ring = [];
|
8553 | }
|
8554 |
|
8555 | function ringEnd() {
|
8556 | pointRing(ring[0][0], ring[0][1]);
|
8557 | ringSink.lineEnd();
|
8558 |
|
8559 | var clean = ringSink.clean(),
|
8560 | ringSegments = ringBuffer.result(),
|
8561 | i, n = ringSegments.length, m,
|
8562 | segment,
|
8563 | point;
|
8564 |
|
8565 | ring.pop();
|
8566 | polygon.push(ring);
|
8567 | ring = null;
|
8568 |
|
8569 | if (!n) return;
|
8570 |
|
8571 | // No intersections.
|
8572 | if (clean & 1) {
|
8573 | segment = ringSegments[0];
|
8574 | if ((m = segment.length - 1) > 0) {
|
8575 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
8576 | sink.lineStart();
|
8577 | for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
|
8578 | sink.lineEnd();
|
8579 | }
|
8580 | return;
|
8581 | }
|
8582 |
|
8583 | // Rejoin connected segments.
|
8584 | // TODO reuse ringBuffer.rejoin()?
|
8585 | if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
|
8586 |
|
8587 | segments.push(ringSegments.filter(validSegment));
|
8588 | }
|
8589 |
|
8590 | return clip;
|
8591 | };
|
8592 | }
|
8593 |
|
8594 | function validSegment(segment) {
|
8595 | return segment.length > 1;
|
8596 | }
|
8597 |
|
8598 | // Intersections are sorted along the clip edge. For both antimeridian cutting
|
8599 | // and circle clipping, the same comparison is used.
|
8600 | function compareIntersection(a, b) {
|
8601 | return ((a = a.x)[0] < 0 ? a[1] - halfPi$2 - epsilon$2 : halfPi$2 - a[1])
|
8602 | - ((b = b.x)[0] < 0 ? b[1] - halfPi$2 - epsilon$2 : halfPi$2 - b[1]);
|
8603 | }
|
8604 |
|
8605 | var clipAntimeridian = clip(
|
8606 | function() { return true; },
|
8607 | clipAntimeridianLine,
|
8608 | clipAntimeridianInterpolate,
|
8609 | [-pi$3, -halfPi$2]
|
8610 | );
|
8611 |
|
8612 | // Takes a line and cuts into visible segments. Return values: 0 - there were
|
8613 | // intersections or the line was empty; 1 - no intersections; 2 - there were
|
8614 | // intersections, and the first and last segments should be rejoined.
|
8615 | function clipAntimeridianLine(stream) {
|
8616 | var lambda0 = NaN,
|
8617 | phi0 = NaN,
|
8618 | sign0 = NaN,
|
8619 | clean; // no intersections
|
8620 |
|
8621 | return {
|
8622 | lineStart: function() {
|
8623 | stream.lineStart();
|
8624 | clean = 1;
|
8625 | },
|
8626 | point: function(lambda1, phi1) {
|
8627 | var sign1 = lambda1 > 0 ? pi$3 : -pi$3,
|
8628 | delta = abs(lambda1 - lambda0);
|
8629 | if (abs(delta - pi$3) < epsilon$2) { // line crosses a pole
|
8630 | stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$2 : -halfPi$2);
|
8631 | stream.point(sign0, phi0);
|
8632 | stream.lineEnd();
|
8633 | stream.lineStart();
|
8634 | stream.point(sign1, phi0);
|
8635 | stream.point(lambda1, phi0);
|
8636 | clean = 0;
|
8637 | } else if (sign0 !== sign1 && delta >= pi$3) { // line crosses antimeridian
|
8638 | if (abs(lambda0 - sign0) < epsilon$2) lambda0 -= sign0 * epsilon$2; // handle degeneracies
|
8639 | if (abs(lambda1 - sign1) < epsilon$2) lambda1 -= sign1 * epsilon$2;
|
8640 | phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
|
8641 | stream.point(sign0, phi0);
|
8642 | stream.lineEnd();
|
8643 | stream.lineStart();
|
8644 | stream.point(sign1, phi0);
|
8645 | clean = 0;
|
8646 | }
|
8647 | stream.point(lambda0 = lambda1, phi0 = phi1);
|
8648 | sign0 = sign1;
|
8649 | },
|
8650 | lineEnd: function() {
|
8651 | stream.lineEnd();
|
8652 | lambda0 = phi0 = NaN;
|
8653 | },
|
8654 | clean: function() {
|
8655 | return 2 - clean; // if intersections, rejoin first and last segments
|
8656 | }
|
8657 | };
|
8658 | }
|
8659 |
|
8660 | function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
|
8661 | var cosPhi0,
|
8662 | cosPhi1,
|
8663 | sinLambda0Lambda1 = sin$1(lambda0 - lambda1);
|
8664 | return abs(sinLambda0Lambda1) > epsilon$2
|
8665 | ? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1)
|
8666 | - sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0))
|
8667 | / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
|
8668 | : (phi0 + phi1) / 2;
|
8669 | }
|
8670 |
|
8671 | function clipAntimeridianInterpolate(from, to, direction, stream) {
|
8672 | var phi;
|
8673 | if (from == null) {
|
8674 | phi = direction * halfPi$2;
|
8675 | stream.point(-pi$3, phi);
|
8676 | stream.point(0, phi);
|
8677 | stream.point(pi$3, phi);
|
8678 | stream.point(pi$3, 0);
|
8679 | stream.point(pi$3, -phi);
|
8680 | stream.point(0, -phi);
|
8681 | stream.point(-pi$3, -phi);
|
8682 | stream.point(-pi$3, 0);
|
8683 | stream.point(-pi$3, phi);
|
8684 | } else if (abs(from[0] - to[0]) > epsilon$2) {
|
8685 | var lambda = from[0] < to[0] ? pi$3 : -pi$3;
|
8686 | phi = direction * lambda / 2;
|
8687 | stream.point(-lambda, phi);
|
8688 | stream.point(0, phi);
|
8689 | stream.point(lambda, phi);
|
8690 | } else {
|
8691 | stream.point(to[0], to[1]);
|
8692 | }
|
8693 | }
|
8694 |
|
8695 | function clipCircle(radius) {
|
8696 | var cr = cos$1(radius),
|
8697 | delta = 6 * radians,
|
8698 | smallRadius = cr > 0,
|
8699 | notHemisphere = abs(cr) > epsilon$2; // TODO optimise for this common case
|
8700 |
|
8701 | function interpolate(from, to, direction, stream) {
|
8702 | circleStream(stream, radius, delta, direction, from, to);
|
8703 | }
|
8704 |
|
8705 | function visible(lambda, phi) {
|
8706 | return cos$1(lambda) * cos$1(phi) > cr;
|
8707 | }
|
8708 |
|
8709 | // Takes a line and cuts into visible segments. Return values used for polygon
|
8710 | // clipping: 0 - there were intersections or the line was empty; 1 - no
|
8711 | // intersections 2 - there were intersections, and the first and last segments
|
8712 | // should be rejoined.
|
8713 | function clipLine(stream) {
|
8714 | var point0, // previous point
|
8715 | c0, // code for previous point
|
8716 | v0, // visibility of previous point
|
8717 | v00, // visibility of first point
|
8718 | clean; // no intersections
|
8719 | return {
|
8720 | lineStart: function() {
|
8721 | v00 = v0 = false;
|
8722 | clean = 1;
|
8723 | },
|
8724 | point: function(lambda, phi) {
|
8725 | var point1 = [lambda, phi],
|
8726 | point2,
|
8727 | v = visible(lambda, phi),
|
8728 | c = smallRadius
|
8729 | ? v ? 0 : code(lambda, phi)
|
8730 | : v ? code(lambda + (lambda < 0 ? pi$3 : -pi$3), phi) : 0;
|
8731 | if (!point0 && (v00 = v0 = v)) stream.lineStart();
|
8732 | // Handle degeneracies.
|
8733 | // TODO ignore if not clipping polygons.
|
8734 | if (v !== v0) {
|
8735 | point2 = intersect(point0, point1);
|
8736 | if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
|
8737 | point1[0] += epsilon$2;
|
8738 | point1[1] += epsilon$2;
|
8739 | v = visible(point1[0], point1[1]);
|
8740 | }
|
8741 | }
|
8742 | if (v !== v0) {
|
8743 | clean = 0;
|
8744 | if (v) {
|
8745 | // outside going in
|
8746 | stream.lineStart();
|
8747 | point2 = intersect(point1, point0);
|
8748 | stream.point(point2[0], point2[1]);
|
8749 | } else {
|
8750 | // inside going out
|
8751 | point2 = intersect(point0, point1);
|
8752 | stream.point(point2[0], point2[1]);
|
8753 | stream.lineEnd();
|
8754 | }
|
8755 | point0 = point2;
|
8756 | } else if (notHemisphere && point0 && smallRadius ^ v) {
|
8757 | var t;
|
8758 | // If the codes for two points are different, or are both zero,
|
8759 | // and there this segment intersects with the small circle.
|
8760 | if (!(c & c0) && (t = intersect(point1, point0, true))) {
|
8761 | clean = 0;
|
8762 | if (smallRadius) {
|
8763 | stream.lineStart();
|
8764 | stream.point(t[0][0], t[0][1]);
|
8765 | stream.point(t[1][0], t[1][1]);
|
8766 | stream.lineEnd();
|
8767 | } else {
|
8768 | stream.point(t[1][0], t[1][1]);
|
8769 | stream.lineEnd();
|
8770 | stream.lineStart();
|
8771 | stream.point(t[0][0], t[0][1]);
|
8772 | }
|
8773 | }
|
8774 | }
|
8775 | if (v && (!point0 || !pointEqual(point0, point1))) {
|
8776 | stream.point(point1[0], point1[1]);
|
8777 | }
|
8778 | point0 = point1, v0 = v, c0 = c;
|
8779 | },
|
8780 | lineEnd: function() {
|
8781 | if (v0) stream.lineEnd();
|
8782 | point0 = null;
|
8783 | },
|
8784 | // Rejoin first and last segments if there were intersections and the first
|
8785 | // and last points were visible.
|
8786 | clean: function() {
|
8787 | return clean | ((v00 && v0) << 1);
|
8788 | }
|
8789 | };
|
8790 | }
|
8791 |
|
8792 | // Intersects the great circle between a and b with the clip circle.
|
8793 | function intersect(a, b, two) {
|
8794 | var pa = cartesian(a),
|
8795 | pb = cartesian(b);
|
8796 |
|
8797 | // We have two planes, n1.p = d1 and n2.p = d2.
|
8798 | // Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2).
|
8799 | var n1 = [1, 0, 0], // normal
|
8800 | n2 = cartesianCross(pa, pb),
|
8801 | n2n2 = cartesianDot(n2, n2),
|
8802 | n1n2 = n2[0], // cartesianDot(n1, n2),
|
8803 | determinant = n2n2 - n1n2 * n1n2;
|
8804 |
|
8805 | // Two polar points.
|
8806 | if (!determinant) return !two && a;
|
8807 |
|
8808 | var c1 = cr * n2n2 / determinant,
|
8809 | c2 = -cr * n1n2 / determinant,
|
8810 | n1xn2 = cartesianCross(n1, n2),
|
8811 | A = cartesianScale(n1, c1),
|
8812 | B = cartesianScale(n2, c2);
|
8813 | cartesianAddInPlace(A, B);
|
8814 |
|
8815 | // Solve |p(t)|^2 = 1.
|
8816 | var u = n1xn2,
|
8817 | w = cartesianDot(A, u),
|
8818 | uu = cartesianDot(u, u),
|
8819 | t2 = w * w - uu * (cartesianDot(A, A) - 1);
|
8820 |
|
8821 | if (t2 < 0) return;
|
8822 |
|
8823 | var t = sqrt(t2),
|
8824 | q = cartesianScale(u, (-w - t) / uu);
|
8825 | cartesianAddInPlace(q, A);
|
8826 | q = spherical(q);
|
8827 |
|
8828 | if (!two) return q;
|
8829 |
|
8830 | // Two intersection points.
|
8831 | var lambda0 = a[0],
|
8832 | lambda1 = b[0],
|
8833 | phi0 = a[1],
|
8834 | phi1 = b[1],
|
8835 | z;
|
8836 |
|
8837 | if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
|
8838 |
|
8839 | var delta = lambda1 - lambda0,
|
8840 | polar = abs(delta - pi$3) < epsilon$2,
|
8841 | meridian = polar || delta < epsilon$2;
|
8842 |
|
8843 | if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
|
8844 |
|
8845 | // Check that the first point is between a and b.
|
8846 | if (meridian
|
8847 | ? polar
|
8848 | ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$2 ? phi0 : phi1)
|
8849 | : phi0 <= q[1] && q[1] <= phi1
|
8850 | : delta > pi$3 ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
|
8851 | var q1 = cartesianScale(u, (-w + t) / uu);
|
8852 | cartesianAddInPlace(q1, A);
|
8853 | return [q, spherical(q1)];
|
8854 | }
|
8855 | }
|
8856 |
|
8857 | // Generates a 4-bit vector representing the location of a point relative to
|
8858 | // the small circle's bounding box.
|
8859 | function code(lambda, phi) {
|
8860 | var r = smallRadius ? radius : pi$3 - radius,
|
8861 | code = 0;
|
8862 | if (lambda < -r) code |= 1; // left
|
8863 | else if (lambda > r) code |= 2; // right
|
8864 | if (phi < -r) code |= 4; // below
|
8865 | else if (phi > r) code |= 8; // above
|
8866 | return code;
|
8867 | }
|
8868 |
|
8869 | return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$3, radius - pi$3]);
|
8870 | }
|
8871 |
|
8872 | function clipLine(a, b, x0, y0, x1, y1) {
|
8873 | var ax = a[0],
|
8874 | ay = a[1],
|
8875 | bx = b[0],
|
8876 | by = b[1],
|
8877 | t0 = 0,
|
8878 | t1 = 1,
|
8879 | dx = bx - ax,
|
8880 | dy = by - ay,
|
8881 | r;
|
8882 |
|
8883 | r = x0 - ax;
|
8884 | if (!dx && r > 0) return;
|
8885 | r /= dx;
|
8886 | if (dx < 0) {
|
8887 | if (r < t0) return;
|
8888 | if (r < t1) t1 = r;
|
8889 | } else if (dx > 0) {
|
8890 | if (r > t1) return;
|
8891 | if (r > t0) t0 = r;
|
8892 | }
|
8893 |
|
8894 | r = x1 - ax;
|
8895 | if (!dx && r < 0) return;
|
8896 | r /= dx;
|
8897 | if (dx < 0) {
|
8898 | if (r > t1) return;
|
8899 | if (r > t0) t0 = r;
|
8900 | } else if (dx > 0) {
|
8901 | if (r < t0) return;
|
8902 | if (r < t1) t1 = r;
|
8903 | }
|
8904 |
|
8905 | r = y0 - ay;
|
8906 | if (!dy && r > 0) return;
|
8907 | r /= dy;
|
8908 | if (dy < 0) {
|
8909 | if (r < t0) return;
|
8910 | if (r < t1) t1 = r;
|
8911 | } else if (dy > 0) {
|
8912 | if (r > t1) return;
|
8913 | if (r > t0) t0 = r;
|
8914 | }
|
8915 |
|
8916 | r = y1 - ay;
|
8917 | if (!dy && r < 0) return;
|
8918 | r /= dy;
|
8919 | if (dy < 0) {
|
8920 | if (r > t1) return;
|
8921 | if (r > t0) t0 = r;
|
8922 | } else if (dy > 0) {
|
8923 | if (r < t0) return;
|
8924 | if (r < t1) t1 = r;
|
8925 | }
|
8926 |
|
8927 | if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
|
8928 | if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
|
8929 | return true;
|
8930 | }
|
8931 |
|
8932 | var clipMax = 1e9, clipMin = -clipMax;
|
8933 |
|
8934 | // TODO Use d3-polygon’s polygonContains here for the ring check?
|
8935 | // TODO Eliminate duplicate buffering in clipBuffer and polygon.push?
|
8936 |
|
8937 | function clipRectangle(x0, y0, x1, y1) {
|
8938 |
|
8939 | function visible(x, y) {
|
8940 | return x0 <= x && x <= x1 && y0 <= y && y <= y1;
|
8941 | }
|
8942 |
|
8943 | function interpolate(from, to, direction, stream) {
|
8944 | var a = 0, a1 = 0;
|
8945 | if (from == null
|
8946 | || (a = corner(from, direction)) !== (a1 = corner(to, direction))
|
8947 | || comparePoint(from, to) < 0 ^ direction > 0) {
|
8948 | do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
|
8949 | while ((a = (a + direction + 4) % 4) !== a1);
|
8950 | } else {
|
8951 | stream.point(to[0], to[1]);
|
8952 | }
|
8953 | }
|
8954 |
|
8955 | function corner(p, direction) {
|
8956 | return abs(p[0] - x0) < epsilon$2 ? direction > 0 ? 0 : 3
|
8957 | : abs(p[0] - x1) < epsilon$2 ? direction > 0 ? 2 : 1
|
8958 | : abs(p[1] - y0) < epsilon$2 ? direction > 0 ? 1 : 0
|
8959 | : direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon
|
8960 | }
|
8961 |
|
8962 | function compareIntersection(a, b) {
|
8963 | return comparePoint(a.x, b.x);
|
8964 | }
|
8965 |
|
8966 | function comparePoint(a, b) {
|
8967 | var ca = corner(a, 1),
|
8968 | cb = corner(b, 1);
|
8969 | return ca !== cb ? ca - cb
|
8970 | : ca === 0 ? b[1] - a[1]
|
8971 | : ca === 1 ? a[0] - b[0]
|
8972 | : ca === 2 ? a[1] - b[1]
|
8973 | : b[0] - a[0];
|
8974 | }
|
8975 |
|
8976 | return function(stream) {
|
8977 | var activeStream = stream,
|
8978 | bufferStream = clipBuffer(),
|
8979 | segments,
|
8980 | polygon,
|
8981 | ring,
|
8982 | x__, y__, v__, // first point
|
8983 | x_, y_, v_, // previous point
|
8984 | first,
|
8985 | clean;
|
8986 |
|
8987 | var clipStream = {
|
8988 | point: point,
|
8989 | lineStart: lineStart,
|
8990 | lineEnd: lineEnd,
|
8991 | polygonStart: polygonStart,
|
8992 | polygonEnd: polygonEnd
|
8993 | };
|
8994 |
|
8995 | function point(x, y) {
|
8996 | if (visible(x, y)) activeStream.point(x, y);
|
8997 | }
|
8998 |
|
8999 | function polygonInside() {
|
9000 | var winding = 0;
|
9001 |
|
9002 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
9003 | for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
|
9004 | a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
|
9005 | if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
|
9006 | else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
|
9007 | }
|
9008 | }
|
9009 |
|
9010 | return winding;
|
9011 | }
|
9012 |
|
9013 | // Buffer geometry within a polygon and then clip it en masse.
|
9014 | function polygonStart() {
|
9015 | activeStream = bufferStream, segments = [], polygon = [], clean = true;
|
9016 | }
|
9017 |
|
9018 | function polygonEnd() {
|
9019 | var startInside = polygonInside(),
|
9020 | cleanInside = clean && startInside,
|
9021 | visible = (segments = merge(segments)).length;
|
9022 | if (cleanInside || visible) {
|
9023 | stream.polygonStart();
|
9024 | if (cleanInside) {
|
9025 | stream.lineStart();
|
9026 | interpolate(null, null, 1, stream);
|
9027 | stream.lineEnd();
|
9028 | }
|
9029 | if (visible) {
|
9030 | clipRejoin(segments, compareIntersection, startInside, interpolate, stream);
|
9031 | }
|
9032 | stream.polygonEnd();
|
9033 | }
|
9034 | activeStream = stream, segments = polygon = ring = null;
|
9035 | }
|
9036 |
|
9037 | function lineStart() {
|
9038 | clipStream.point = linePoint;
|
9039 | if (polygon) polygon.push(ring = []);
|
9040 | first = true;
|
9041 | v_ = false;
|
9042 | x_ = y_ = NaN;
|
9043 | }
|
9044 |
|
9045 | // TODO rather than special-case polygons, simply handle them separately.
|
9046 | // Ideally, coincident intersection points should be jittered to avoid
|
9047 | // clipping issues.
|
9048 | function lineEnd() {
|
9049 | if (segments) {
|
9050 | linePoint(x__, y__);
|
9051 | if (v__ && v_) bufferStream.rejoin();
|
9052 | segments.push(bufferStream.result());
|
9053 | }
|
9054 | clipStream.point = point;
|
9055 | if (v_) activeStream.lineEnd();
|
9056 | }
|
9057 |
|
9058 | function linePoint(x, y) {
|
9059 | var v = visible(x, y);
|
9060 | if (polygon) ring.push([x, y]);
|
9061 | if (first) {
|
9062 | x__ = x, y__ = y, v__ = v;
|
9063 | first = false;
|
9064 | if (v) {
|
9065 | activeStream.lineStart();
|
9066 | activeStream.point(x, y);
|
9067 | }
|
9068 | } else {
|
9069 | if (v && v_) activeStream.point(x, y);
|
9070 | else {
|
9071 | var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
|
9072 | b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
|
9073 | if (clipLine(a, b, x0, y0, x1, y1)) {
|
9074 | if (!v_) {
|
9075 | activeStream.lineStart();
|
9076 | activeStream.point(a[0], a[1]);
|
9077 | }
|
9078 | activeStream.point(b[0], b[1]);
|
9079 | if (!v) activeStream.lineEnd();
|
9080 | clean = false;
|
9081 | } else if (v) {
|
9082 | activeStream.lineStart();
|
9083 | activeStream.point(x, y);
|
9084 | clean = false;
|
9085 | }
|
9086 | }
|
9087 | }
|
9088 | x_ = x, y_ = y, v_ = v;
|
9089 | }
|
9090 |
|
9091 | return clipStream;
|
9092 | };
|
9093 | }
|
9094 |
|
9095 | function extent$1() {
|
9096 | var x0 = 0,
|
9097 | y0 = 0,
|
9098 | x1 = 960,
|
9099 | y1 = 500,
|
9100 | cache,
|
9101 | cacheStream,
|
9102 | clip;
|
9103 |
|
9104 | return clip = {
|
9105 | stream: function(stream) {
|
9106 | return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream);
|
9107 | },
|
9108 | extent: function(_) {
|
9109 | return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]];
|
9110 | }
|
9111 | };
|
9112 | }
|
9113 |
|
9114 | var lengthSum = adder(),
|
9115 | lambda0$2,
|
9116 | sinPhi0$1,
|
9117 | cosPhi0$1;
|
9118 |
|
9119 | var lengthStream = {
|
9120 | sphere: noop$2,
|
9121 | point: noop$2,
|
9122 | lineStart: lengthLineStart,
|
9123 | lineEnd: noop$2,
|
9124 | polygonStart: noop$2,
|
9125 | polygonEnd: noop$2
|
9126 | };
|
9127 |
|
9128 | function lengthLineStart() {
|
9129 | lengthStream.point = lengthPointFirst;
|
9130 | lengthStream.lineEnd = lengthLineEnd;
|
9131 | }
|
9132 |
|
9133 | function lengthLineEnd() {
|
9134 | lengthStream.point = lengthStream.lineEnd = noop$2;
|
9135 | }
|
9136 |
|
9137 | function lengthPointFirst(lambda, phi) {
|
9138 | lambda *= radians, phi *= radians;
|
9139 | lambda0$2 = lambda, sinPhi0$1 = sin$1(phi), cosPhi0$1 = cos$1(phi);
|
9140 | lengthStream.point = lengthPoint;
|
9141 | }
|
9142 |
|
9143 | function lengthPoint(lambda, phi) {
|
9144 | lambda *= radians, phi *= radians;
|
9145 | var sinPhi = sin$1(phi),
|
9146 | cosPhi = cos$1(phi),
|
9147 | delta = abs(lambda - lambda0$2),
|
9148 | cosDelta = cos$1(delta),
|
9149 | sinDelta = sin$1(delta),
|
9150 | x = cosPhi * sinDelta,
|
9151 | y = cosPhi0$1 * sinPhi - sinPhi0$1 * cosPhi * cosDelta,
|
9152 | z = sinPhi0$1 * sinPhi + cosPhi0$1 * cosPhi * cosDelta;
|
9153 | lengthSum.add(atan2(sqrt(x * x + y * y), z));
|
9154 | lambda0$2 = lambda, sinPhi0$1 = sinPhi, cosPhi0$1 = cosPhi;
|
9155 | }
|
9156 |
|
9157 | function length$1(object) {
|
9158 | lengthSum.reset();
|
9159 | geoStream(object, lengthStream);
|
9160 | return +lengthSum;
|
9161 | }
|
9162 |
|
9163 | var coordinates = [null, null],
|
9164 | object$1 = {type: "LineString", coordinates: coordinates};
|
9165 |
|
9166 | function distance(a, b) {
|
9167 | coordinates[0] = a;
|
9168 | coordinates[1] = b;
|
9169 | return length$1(object$1);
|
9170 | }
|
9171 |
|
9172 | var containsObjectType = {
|
9173 | Feature: function(object, point) {
|
9174 | return containsGeometry(object.geometry, point);
|
9175 | },
|
9176 | FeatureCollection: function(object, point) {
|
9177 | var features = object.features, i = -1, n = features.length;
|
9178 | while (++i < n) if (containsGeometry(features[i].geometry, point)) return true;
|
9179 | return false;
|
9180 | }
|
9181 | };
|
9182 |
|
9183 | var containsGeometryType = {
|
9184 | Sphere: function() {
|
9185 | return true;
|
9186 | },
|
9187 | Point: function(object, point) {
|
9188 | return containsPoint(object.coordinates, point);
|
9189 | },
|
9190 | MultiPoint: function(object, point) {
|
9191 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
9192 | while (++i < n) if (containsPoint(coordinates[i], point)) return true;
|
9193 | return false;
|
9194 | },
|
9195 | LineString: function(object, point) {
|
9196 | return containsLine(object.coordinates, point);
|
9197 | },
|
9198 | MultiLineString: function(object, point) {
|
9199 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
9200 | while (++i < n) if (containsLine(coordinates[i], point)) return true;
|
9201 | return false;
|
9202 | },
|
9203 | Polygon: function(object, point) {
|
9204 | return containsPolygon(object.coordinates, point);
|
9205 | },
|
9206 | MultiPolygon: function(object, point) {
|
9207 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
9208 | while (++i < n) if (containsPolygon(coordinates[i], point)) return true;
|
9209 | return false;
|
9210 | },
|
9211 | GeometryCollection: function(object, point) {
|
9212 | var geometries = object.geometries, i = -1, n = geometries.length;
|
9213 | while (++i < n) if (containsGeometry(geometries[i], point)) return true;
|
9214 | return false;
|
9215 | }
|
9216 | };
|
9217 |
|
9218 | function containsGeometry(geometry, point) {
|
9219 | return geometry && containsGeometryType.hasOwnProperty(geometry.type)
|
9220 | ? containsGeometryType[geometry.type](geometry, point)
|
9221 | : false;
|
9222 | }
|
9223 |
|
9224 | function containsPoint(coordinates, point) {
|
9225 | return distance(coordinates, point) === 0;
|
9226 | }
|
9227 |
|
9228 | function containsLine(coordinates, point) {
|
9229 | var ao, bo, ab;
|
9230 | for (var i = 0, n = coordinates.length; i < n; i++) {
|
9231 | bo = distance(coordinates[i], point);
|
9232 | if (bo === 0) return true;
|
9233 | if (i > 0) {
|
9234 | ab = distance(coordinates[i], coordinates[i - 1]);
|
9235 | if (
|
9236 | ab > 0 &&
|
9237 | ao <= ab &&
|
9238 | bo <= ab &&
|
9239 | (ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2$1 * ab
|
9240 | )
|
9241 | return true;
|
9242 | }
|
9243 | ao = bo;
|
9244 | }
|
9245 | return false;
|
9246 | }
|
9247 |
|
9248 | function containsPolygon(coordinates, point) {
|
9249 | return !!polygonContains(coordinates.map(ringRadians), pointRadians(point));
|
9250 | }
|
9251 |
|
9252 | function ringRadians(ring) {
|
9253 | return ring = ring.map(pointRadians), ring.pop(), ring;
|
9254 | }
|
9255 |
|
9256 | function pointRadians(point) {
|
9257 | return [point[0] * radians, point[1] * radians];
|
9258 | }
|
9259 |
|
9260 | function contains$1(object, point) {
|
9261 | return (object && containsObjectType.hasOwnProperty(object.type)
|
9262 | ? containsObjectType[object.type]
|
9263 | : containsGeometry)(object, point);
|
9264 | }
|
9265 |
|
9266 | function graticuleX(y0, y1, dy) {
|
9267 | var y = sequence(y0, y1 - epsilon$2, dy).concat(y1);
|
9268 | return function(x) { return y.map(function(y) { return [x, y]; }); };
|
9269 | }
|
9270 |
|
9271 | function graticuleY(x0, x1, dx) {
|
9272 | var x = sequence(x0, x1 - epsilon$2, dx).concat(x1);
|
9273 | return function(y) { return x.map(function(x) { return [x, y]; }); };
|
9274 | }
|
9275 |
|
9276 | function graticule() {
|
9277 | var x1, x0, X1, X0,
|
9278 | y1, y0, Y1, Y0,
|
9279 | dx = 10, dy = dx, DX = 90, DY = 360,
|
9280 | x, y, X, Y,
|
9281 | precision = 2.5;
|
9282 |
|
9283 | function graticule() {
|
9284 | return {type: "MultiLineString", coordinates: lines()};
|
9285 | }
|
9286 |
|
9287 | function lines() {
|
9288 | return sequence(ceil(X0 / DX) * DX, X1, DX).map(X)
|
9289 | .concat(sequence(ceil(Y0 / DY) * DY, Y1, DY).map(Y))
|
9290 | .concat(sequence(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs(x % DX) > epsilon$2; }).map(x))
|
9291 | .concat(sequence(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs(y % DY) > epsilon$2; }).map(y));
|
9292 | }
|
9293 |
|
9294 | graticule.lines = function() {
|
9295 | return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; });
|
9296 | };
|
9297 |
|
9298 | graticule.outline = function() {
|
9299 | return {
|
9300 | type: "Polygon",
|
9301 | coordinates: [
|
9302 | X(X0).concat(
|
9303 | Y(Y1).slice(1),
|
9304 | X(X1).reverse().slice(1),
|
9305 | Y(Y0).reverse().slice(1))
|
9306 | ]
|
9307 | };
|
9308 | };
|
9309 |
|
9310 | graticule.extent = function(_) {
|
9311 | if (!arguments.length) return graticule.extentMinor();
|
9312 | return graticule.extentMajor(_).extentMinor(_);
|
9313 | };
|
9314 |
|
9315 | graticule.extentMajor = function(_) {
|
9316 | if (!arguments.length) return [[X0, Y0], [X1, Y1]];
|
9317 | X0 = +_[0][0], X1 = +_[1][0];
|
9318 | Y0 = +_[0][1], Y1 = +_[1][1];
|
9319 | if (X0 > X1) _ = X0, X0 = X1, X1 = _;
|
9320 | if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
|
9321 | return graticule.precision(precision);
|
9322 | };
|
9323 |
|
9324 | graticule.extentMinor = function(_) {
|
9325 | if (!arguments.length) return [[x0, y0], [x1, y1]];
|
9326 | x0 = +_[0][0], x1 = +_[1][0];
|
9327 | y0 = +_[0][1], y1 = +_[1][1];
|
9328 | if (x0 > x1) _ = x0, x0 = x1, x1 = _;
|
9329 | if (y0 > y1) _ = y0, y0 = y1, y1 = _;
|
9330 | return graticule.precision(precision);
|
9331 | };
|
9332 |
|
9333 | graticule.step = function(_) {
|
9334 | if (!arguments.length) return graticule.stepMinor();
|
9335 | return graticule.stepMajor(_).stepMinor(_);
|
9336 | };
|
9337 |
|
9338 | graticule.stepMajor = function(_) {
|
9339 | if (!arguments.length) return [DX, DY];
|
9340 | DX = +_[0], DY = +_[1];
|
9341 | return graticule;
|
9342 | };
|
9343 |
|
9344 | graticule.stepMinor = function(_) {
|
9345 | if (!arguments.length) return [dx, dy];
|
9346 | dx = +_[0], dy = +_[1];
|
9347 | return graticule;
|
9348 | };
|
9349 |
|
9350 | graticule.precision = function(_) {
|
9351 | if (!arguments.length) return precision;
|
9352 | precision = +_;
|
9353 | x = graticuleX(y0, y1, 90);
|
9354 | y = graticuleY(x0, x1, precision);
|
9355 | X = graticuleX(Y0, Y1, 90);
|
9356 | Y = graticuleY(X0, X1, precision);
|
9357 | return graticule;
|
9358 | };
|
9359 |
|
9360 | return graticule
|
9361 | .extentMajor([[-180, -90 + epsilon$2], [180, 90 - epsilon$2]])
|
9362 | .extentMinor([[-180, -80 - epsilon$2], [180, 80 + epsilon$2]]);
|
9363 | }
|
9364 |
|
9365 | function graticule10() {
|
9366 | return graticule()();
|
9367 | }
|
9368 |
|
9369 | function interpolate$1(a, b) {
|
9370 | var x0 = a[0] * radians,
|
9371 | y0 = a[1] * radians,
|
9372 | x1 = b[0] * radians,
|
9373 | y1 = b[1] * radians,
|
9374 | cy0 = cos$1(y0),
|
9375 | sy0 = sin$1(y0),
|
9376 | cy1 = cos$1(y1),
|
9377 | sy1 = sin$1(y1),
|
9378 | kx0 = cy0 * cos$1(x0),
|
9379 | ky0 = cy0 * sin$1(x0),
|
9380 | kx1 = cy1 * cos$1(x1),
|
9381 | ky1 = cy1 * sin$1(x1),
|
9382 | d = 2 * asin(sqrt(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))),
|
9383 | k = sin$1(d);
|
9384 |
|
9385 | var interpolate = d ? function(t) {
|
9386 | var B = sin$1(t *= d) / k,
|
9387 | A = sin$1(d - t) / k,
|
9388 | x = A * kx0 + B * kx1,
|
9389 | y = A * ky0 + B * ky1,
|
9390 | z = A * sy0 + B * sy1;
|
9391 | return [
|
9392 | atan2(y, x) * degrees$1,
|
9393 | atan2(z, sqrt(x * x + y * y)) * degrees$1
|
9394 | ];
|
9395 | } : function() {
|
9396 | return [x0 * degrees$1, y0 * degrees$1];
|
9397 | };
|
9398 |
|
9399 | interpolate.distance = d;
|
9400 |
|
9401 | return interpolate;
|
9402 | }
|
9403 |
|
9404 | function identity$4(x) {
|
9405 | return x;
|
9406 | }
|
9407 |
|
9408 | var areaSum$1 = adder(),
|
9409 | areaRingSum$1 = adder(),
|
9410 | x00,
|
9411 | y00,
|
9412 | x0$1,
|
9413 | y0$1;
|
9414 |
|
9415 | var areaStream$1 = {
|
9416 | point: noop$2,
|
9417 | lineStart: noop$2,
|
9418 | lineEnd: noop$2,
|
9419 | polygonStart: function() {
|
9420 | areaStream$1.lineStart = areaRingStart$1;
|
9421 | areaStream$1.lineEnd = areaRingEnd$1;
|
9422 | },
|
9423 | polygonEnd: function() {
|
9424 | areaStream$1.lineStart = areaStream$1.lineEnd = areaStream$1.point = noop$2;
|
9425 | areaSum$1.add(abs(areaRingSum$1));
|
9426 | areaRingSum$1.reset();
|
9427 | },
|
9428 | result: function() {
|
9429 | var area = areaSum$1 / 2;
|
9430 | areaSum$1.reset();
|
9431 | return area;
|
9432 | }
|
9433 | };
|
9434 |
|
9435 | function areaRingStart$1() {
|
9436 | areaStream$1.point = areaPointFirst$1;
|
9437 | }
|
9438 |
|
9439 | function areaPointFirst$1(x, y) {
|
9440 | areaStream$1.point = areaPoint$1;
|
9441 | x00 = x0$1 = x, y00 = y0$1 = y;
|
9442 | }
|
9443 |
|
9444 | function areaPoint$1(x, y) {
|
9445 | areaRingSum$1.add(y0$1 * x - x0$1 * y);
|
9446 | x0$1 = x, y0$1 = y;
|
9447 | }
|
9448 |
|
9449 | function areaRingEnd$1() {
|
9450 | areaPoint$1(x00, y00);
|
9451 | }
|
9452 |
|
9453 | var x0$2 = Infinity,
|
9454 | y0$2 = x0$2,
|
9455 | x1 = -x0$2,
|
9456 | y1 = x1;
|
9457 |
|
9458 | var boundsStream$1 = {
|
9459 | point: boundsPoint$1,
|
9460 | lineStart: noop$2,
|
9461 | lineEnd: noop$2,
|
9462 | polygonStart: noop$2,
|
9463 | polygonEnd: noop$2,
|
9464 | result: function() {
|
9465 | var bounds = [[x0$2, y0$2], [x1, y1]];
|
9466 | x1 = y1 = -(y0$2 = x0$2 = Infinity);
|
9467 | return bounds;
|
9468 | }
|
9469 | };
|
9470 |
|
9471 | function boundsPoint$1(x, y) {
|
9472 | if (x < x0$2) x0$2 = x;
|
9473 | if (x > x1) x1 = x;
|
9474 | if (y < y0$2) y0$2 = y;
|
9475 | if (y > y1) y1 = y;
|
9476 | }
|
9477 |
|
9478 | // TODO Enforce positive area for exterior, negative area for interior?
|
9479 |
|
9480 | var X0$1 = 0,
|
9481 | Y0$1 = 0,
|
9482 | Z0$1 = 0,
|
9483 | X1$1 = 0,
|
9484 | Y1$1 = 0,
|
9485 | Z1$1 = 0,
|
9486 | X2$1 = 0,
|
9487 | Y2$1 = 0,
|
9488 | Z2$1 = 0,
|
9489 | x00$1,
|
9490 | y00$1,
|
9491 | x0$3,
|
9492 | y0$3;
|
9493 |
|
9494 | var centroidStream$1 = {
|
9495 | point: centroidPoint$1,
|
9496 | lineStart: centroidLineStart$1,
|
9497 | lineEnd: centroidLineEnd$1,
|
9498 | polygonStart: function() {
|
9499 | centroidStream$1.lineStart = centroidRingStart$1;
|
9500 | centroidStream$1.lineEnd = centroidRingEnd$1;
|
9501 | },
|
9502 | polygonEnd: function() {
|
9503 | centroidStream$1.point = centroidPoint$1;
|
9504 | centroidStream$1.lineStart = centroidLineStart$1;
|
9505 | centroidStream$1.lineEnd = centroidLineEnd$1;
|
9506 | },
|
9507 | result: function() {
|
9508 | var centroid = Z2$1 ? [X2$1 / Z2$1, Y2$1 / Z2$1]
|
9509 | : Z1$1 ? [X1$1 / Z1$1, Y1$1 / Z1$1]
|
9510 | : Z0$1 ? [X0$1 / Z0$1, Y0$1 / Z0$1]
|
9511 | : [NaN, NaN];
|
9512 | X0$1 = Y0$1 = Z0$1 =
|
9513 | X1$1 = Y1$1 = Z1$1 =
|
9514 | X2$1 = Y2$1 = Z2$1 = 0;
|
9515 | return centroid;
|
9516 | }
|
9517 | };
|
9518 |
|
9519 | function centroidPoint$1(x, y) {
|
9520 | X0$1 += x;
|
9521 | Y0$1 += y;
|
9522 | ++Z0$1;
|
9523 | }
|
9524 |
|
9525 | function centroidLineStart$1() {
|
9526 | centroidStream$1.point = centroidPointFirstLine;
|
9527 | }
|
9528 |
|
9529 | function centroidPointFirstLine(x, y) {
|
9530 | centroidStream$1.point = centroidPointLine;
|
9531 | centroidPoint$1(x0$3 = x, y0$3 = y);
|
9532 | }
|
9533 |
|
9534 | function centroidPointLine(x, y) {
|
9535 | var dx = x - x0$3, dy = y - y0$3, z = sqrt(dx * dx + dy * dy);
|
9536 | X1$1 += z * (x0$3 + x) / 2;
|
9537 | Y1$1 += z * (y0$3 + y) / 2;
|
9538 | Z1$1 += z;
|
9539 | centroidPoint$1(x0$3 = x, y0$3 = y);
|
9540 | }
|
9541 |
|
9542 | function centroidLineEnd$1() {
|
9543 | centroidStream$1.point = centroidPoint$1;
|
9544 | }
|
9545 |
|
9546 | function centroidRingStart$1() {
|
9547 | centroidStream$1.point = centroidPointFirstRing;
|
9548 | }
|
9549 |
|
9550 | function centroidRingEnd$1() {
|
9551 | centroidPointRing(x00$1, y00$1);
|
9552 | }
|
9553 |
|
9554 | function centroidPointFirstRing(x, y) {
|
9555 | centroidStream$1.point = centroidPointRing;
|
9556 | centroidPoint$1(x00$1 = x0$3 = x, y00$1 = y0$3 = y);
|
9557 | }
|
9558 |
|
9559 | function centroidPointRing(x, y) {
|
9560 | var dx = x - x0$3,
|
9561 | dy = y - y0$3,
|
9562 | z = sqrt(dx * dx + dy * dy);
|
9563 |
|
9564 | X1$1 += z * (x0$3 + x) / 2;
|
9565 | Y1$1 += z * (y0$3 + y) / 2;
|
9566 | Z1$1 += z;
|
9567 |
|
9568 | z = y0$3 * x - x0$3 * y;
|
9569 | X2$1 += z * (x0$3 + x);
|
9570 | Y2$1 += z * (y0$3 + y);
|
9571 | Z2$1 += z * 3;
|
9572 | centroidPoint$1(x0$3 = x, y0$3 = y);
|
9573 | }
|
9574 |
|
9575 | function PathContext(context) {
|
9576 | this._context = context;
|
9577 | }
|
9578 |
|
9579 | PathContext.prototype = {
|
9580 | _radius: 4.5,
|
9581 | pointRadius: function(_) {
|
9582 | return this._radius = _, this;
|
9583 | },
|
9584 | polygonStart: function() {
|
9585 | this._line = 0;
|
9586 | },
|
9587 | polygonEnd: function() {
|
9588 | this._line = NaN;
|
9589 | },
|
9590 | lineStart: function() {
|
9591 | this._point = 0;
|
9592 | },
|
9593 | lineEnd: function() {
|
9594 | if (this._line === 0) this._context.closePath();
|
9595 | this._point = NaN;
|
9596 | },
|
9597 | point: function(x, y) {
|
9598 | switch (this._point) {
|
9599 | case 0: {
|
9600 | this._context.moveTo(x, y);
|
9601 | this._point = 1;
|
9602 | break;
|
9603 | }
|
9604 | case 1: {
|
9605 | this._context.lineTo(x, y);
|
9606 | break;
|
9607 | }
|
9608 | default: {
|
9609 | this._context.moveTo(x + this._radius, y);
|
9610 | this._context.arc(x, y, this._radius, 0, tau$3);
|
9611 | break;
|
9612 | }
|
9613 | }
|
9614 | },
|
9615 | result: noop$2
|
9616 | };
|
9617 |
|
9618 | var lengthSum$1 = adder(),
|
9619 | lengthRing,
|
9620 | x00$2,
|
9621 | y00$2,
|
9622 | x0$4,
|
9623 | y0$4;
|
9624 |
|
9625 | var lengthStream$1 = {
|
9626 | point: noop$2,
|
9627 | lineStart: function() {
|
9628 | lengthStream$1.point = lengthPointFirst$1;
|
9629 | },
|
9630 | lineEnd: function() {
|
9631 | if (lengthRing) lengthPoint$1(x00$2, y00$2);
|
9632 | lengthStream$1.point = noop$2;
|
9633 | },
|
9634 | polygonStart: function() {
|
9635 | lengthRing = true;
|
9636 | },
|
9637 | polygonEnd: function() {
|
9638 | lengthRing = null;
|
9639 | },
|
9640 | result: function() {
|
9641 | var length = +lengthSum$1;
|
9642 | lengthSum$1.reset();
|
9643 | return length;
|
9644 | }
|
9645 | };
|
9646 |
|
9647 | function lengthPointFirst$1(x, y) {
|
9648 | lengthStream$1.point = lengthPoint$1;
|
9649 | x00$2 = x0$4 = x, y00$2 = y0$4 = y;
|
9650 | }
|
9651 |
|
9652 | function lengthPoint$1(x, y) {
|
9653 | x0$4 -= x, y0$4 -= y;
|
9654 | lengthSum$1.add(sqrt(x0$4 * x0$4 + y0$4 * y0$4));
|
9655 | x0$4 = x, y0$4 = y;
|
9656 | }
|
9657 |
|
9658 | function PathString() {
|
9659 | this._string = [];
|
9660 | }
|
9661 |
|
9662 | PathString.prototype = {
|
9663 | _radius: 4.5,
|
9664 | _circle: circle$1(4.5),
|
9665 | pointRadius: function(_) {
|
9666 | if ((_ = +_) !== this._radius) this._radius = _, this._circle = null;
|
9667 | return this;
|
9668 | },
|
9669 | polygonStart: function() {
|
9670 | this._line = 0;
|
9671 | },
|
9672 | polygonEnd: function() {
|
9673 | this._line = NaN;
|
9674 | },
|
9675 | lineStart: function() {
|
9676 | this._point = 0;
|
9677 | },
|
9678 | lineEnd: function() {
|
9679 | if (this._line === 0) this._string.push("Z");
|
9680 | this._point = NaN;
|
9681 | },
|
9682 | point: function(x, y) {
|
9683 | switch (this._point) {
|
9684 | case 0: {
|
9685 | this._string.push("M", x, ",", y);
|
9686 | this._point = 1;
|
9687 | break;
|
9688 | }
|
9689 | case 1: {
|
9690 | this._string.push("L", x, ",", y);
|
9691 | break;
|
9692 | }
|
9693 | default: {
|
9694 | if (this._circle == null) this._circle = circle$1(this._radius);
|
9695 | this._string.push("M", x, ",", y, this._circle);
|
9696 | break;
|
9697 | }
|
9698 | }
|
9699 | },
|
9700 | result: function() {
|
9701 | if (this._string.length) {
|
9702 | var result = this._string.join("");
|
9703 | this._string = [];
|
9704 | return result;
|
9705 | } else {
|
9706 | return null;
|
9707 | }
|
9708 | }
|
9709 | };
|
9710 |
|
9711 | function circle$1(radius) {
|
9712 | return "m0," + radius
|
9713 | + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius
|
9714 | + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius
|
9715 | + "z";
|
9716 | }
|
9717 |
|
9718 | function index$1(projection, context) {
|
9719 | var pointRadius = 4.5,
|
9720 | projectionStream,
|
9721 | contextStream;
|
9722 |
|
9723 | function path(object) {
|
9724 | if (object) {
|
9725 | if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
|
9726 | geoStream(object, projectionStream(contextStream));
|
9727 | }
|
9728 | return contextStream.result();
|
9729 | }
|
9730 |
|
9731 | path.area = function(object) {
|
9732 | geoStream(object, projectionStream(areaStream$1));
|
9733 | return areaStream$1.result();
|
9734 | };
|
9735 |
|
9736 | path.measure = function(object) {
|
9737 | geoStream(object, projectionStream(lengthStream$1));
|
9738 | return lengthStream$1.result();
|
9739 | };
|
9740 |
|
9741 | path.bounds = function(object) {
|
9742 | geoStream(object, projectionStream(boundsStream$1));
|
9743 | return boundsStream$1.result();
|
9744 | };
|
9745 |
|
9746 | path.centroid = function(object) {
|
9747 | geoStream(object, projectionStream(centroidStream$1));
|
9748 | return centroidStream$1.result();
|
9749 | };
|
9750 |
|
9751 | path.projection = function(_) {
|
9752 | return arguments.length ? (projectionStream = _ == null ? (projection = null, identity$4) : (projection = _).stream, path) : projection;
|
9753 | };
|
9754 |
|
9755 | path.context = function(_) {
|
9756 | if (!arguments.length) return context;
|
9757 | contextStream = _ == null ? (context = null, new PathString) : new PathContext(context = _);
|
9758 | if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
|
9759 | return path;
|
9760 | };
|
9761 |
|
9762 | path.pointRadius = function(_) {
|
9763 | if (!arguments.length) return pointRadius;
|
9764 | pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
|
9765 | return path;
|
9766 | };
|
9767 |
|
9768 | return path.projection(projection).context(context);
|
9769 | }
|
9770 |
|
9771 | function transform(methods) {
|
9772 | return {
|
9773 | stream: transformer(methods)
|
9774 | };
|
9775 | }
|
9776 |
|
9777 | function transformer(methods) {
|
9778 | return function(stream) {
|
9779 | var s = new TransformStream;
|
9780 | for (var key in methods) s[key] = methods[key];
|
9781 | s.stream = stream;
|
9782 | return s;
|
9783 | };
|
9784 | }
|
9785 |
|
9786 | function TransformStream() {}
|
9787 |
|
9788 | TransformStream.prototype = {
|
9789 | constructor: TransformStream,
|
9790 | point: function(x, y) { this.stream.point(x, y); },
|
9791 | sphere: function() { this.stream.sphere(); },
|
9792 | lineStart: function() { this.stream.lineStart(); },
|
9793 | lineEnd: function() { this.stream.lineEnd(); },
|
9794 | polygonStart: function() { this.stream.polygonStart(); },
|
9795 | polygonEnd: function() { this.stream.polygonEnd(); }
|
9796 | };
|
9797 |
|
9798 | function fit(projection, fitBounds, object) {
|
9799 | var clip = projection.clipExtent && projection.clipExtent();
|
9800 | projection.scale(150).translate([0, 0]);
|
9801 | if (clip != null) projection.clipExtent(null);
|
9802 | geoStream(object, projection.stream(boundsStream$1));
|
9803 | fitBounds(boundsStream$1.result());
|
9804 | if (clip != null) projection.clipExtent(clip);
|
9805 | return projection;
|
9806 | }
|
9807 |
|
9808 | function fitExtent(projection, extent, object) {
|
9809 | return fit(projection, function(b) {
|
9810 | var w = extent[1][0] - extent[0][0],
|
9811 | h = extent[1][1] - extent[0][1],
|
9812 | k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
|
9813 | x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
|
9814 | y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
|
9815 | projection.scale(150 * k).translate([x, y]);
|
9816 | }, object);
|
9817 | }
|
9818 |
|
9819 | function fitSize(projection, size, object) {
|
9820 | return fitExtent(projection, [[0, 0], size], object);
|
9821 | }
|
9822 |
|
9823 | function fitWidth(projection, width, object) {
|
9824 | return fit(projection, function(b) {
|
9825 | var w = +width,
|
9826 | k = w / (b[1][0] - b[0][0]),
|
9827 | x = (w - k * (b[1][0] + b[0][0])) / 2,
|
9828 | y = -k * b[0][1];
|
9829 | projection.scale(150 * k).translate([x, y]);
|
9830 | }, object);
|
9831 | }
|
9832 |
|
9833 | function fitHeight(projection, height, object) {
|
9834 | return fit(projection, function(b) {
|
9835 | var h = +height,
|
9836 | k = h / (b[1][1] - b[0][1]),
|
9837 | x = -k * b[0][0],
|
9838 | y = (h - k * (b[1][1] + b[0][1])) / 2;
|
9839 | projection.scale(150 * k).translate([x, y]);
|
9840 | }, object);
|
9841 | }
|
9842 |
|
9843 | var maxDepth = 16, // maximum depth of subdivision
|
9844 | cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance)
|
9845 |
|
9846 | function resample(project, delta2) {
|
9847 | return +delta2 ? resample$1(project, delta2) : resampleNone(project);
|
9848 | }
|
9849 |
|
9850 | function resampleNone(project) {
|
9851 | return transformer({
|
9852 | point: function(x, y) {
|
9853 | x = project(x, y);
|
9854 | this.stream.point(x[0], x[1]);
|
9855 | }
|
9856 | });
|
9857 | }
|
9858 |
|
9859 | function resample$1(project, delta2) {
|
9860 |
|
9861 | function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
|
9862 | var dx = x1 - x0,
|
9863 | dy = y1 - y0,
|
9864 | d2 = dx * dx + dy * dy;
|
9865 | if (d2 > 4 * delta2 && depth--) {
|
9866 | var a = a0 + a1,
|
9867 | b = b0 + b1,
|
9868 | c = c0 + c1,
|
9869 | m = sqrt(a * a + b * b + c * c),
|
9870 | phi2 = asin(c /= m),
|
9871 | lambda2 = abs(abs(c) - 1) < epsilon$2 || abs(lambda0 - lambda1) < epsilon$2 ? (lambda0 + lambda1) / 2 : atan2(b, a),
|
9872 | p = project(lambda2, phi2),
|
9873 | x2 = p[0],
|
9874 | y2 = p[1],
|
9875 | dx2 = x2 - x0,
|
9876 | dy2 = y2 - y0,
|
9877 | dz = dy * dx2 - dx * dy2;
|
9878 | if (dz * dz / d2 > delta2 // perpendicular projected distance
|
9879 | || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
|
9880 | || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
|
9881 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
|
9882 | stream.point(x2, y2);
|
9883 | resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
|
9884 | }
|
9885 | }
|
9886 | }
|
9887 | return function(stream) {
|
9888 | var lambda00, x00, y00, a00, b00, c00, // first point
|
9889 | lambda0, x0, y0, a0, b0, c0; // previous point
|
9890 |
|
9891 | var resampleStream = {
|
9892 | point: point,
|
9893 | lineStart: lineStart,
|
9894 | lineEnd: lineEnd,
|
9895 | polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
|
9896 | polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
|
9897 | };
|
9898 |
|
9899 | function point(x, y) {
|
9900 | x = project(x, y);
|
9901 | stream.point(x[0], x[1]);
|
9902 | }
|
9903 |
|
9904 | function lineStart() {
|
9905 | x0 = NaN;
|
9906 | resampleStream.point = linePoint;
|
9907 | stream.lineStart();
|
9908 | }
|
9909 |
|
9910 | function linePoint(lambda, phi) {
|
9911 | var c = cartesian([lambda, phi]), p = project(lambda, phi);
|
9912 | 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);
|
9913 | stream.point(x0, y0);
|
9914 | }
|
9915 |
|
9916 | function lineEnd() {
|
9917 | resampleStream.point = point;
|
9918 | stream.lineEnd();
|
9919 | }
|
9920 |
|
9921 | function ringStart() {
|
9922 | lineStart();
|
9923 | resampleStream.point = ringPoint;
|
9924 | resampleStream.lineEnd = ringEnd;
|
9925 | }
|
9926 |
|
9927 | function ringPoint(lambda, phi) {
|
9928 | linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
|
9929 | resampleStream.point = linePoint;
|
9930 | }
|
9931 |
|
9932 | function ringEnd() {
|
9933 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
|
9934 | resampleStream.lineEnd = lineEnd;
|
9935 | lineEnd();
|
9936 | }
|
9937 |
|
9938 | return resampleStream;
|
9939 | };
|
9940 | }
|
9941 |
|
9942 | var transformRadians = transformer({
|
9943 | point: function(x, y) {
|
9944 | this.stream.point(x * radians, y * radians);
|
9945 | }
|
9946 | });
|
9947 |
|
9948 | function transformRotate(rotate) {
|
9949 | return transformer({
|
9950 | point: function(x, y) {
|
9951 | var r = rotate(x, y);
|
9952 | return this.stream.point(r[0], r[1]);
|
9953 | }
|
9954 | });
|
9955 | }
|
9956 |
|
9957 | function scaleTranslate(k, dx, dy) {
|
9958 | function transform(x, y) {
|
9959 | return [dx + k * x, dy - k * y];
|
9960 | }
|
9961 | transform.invert = function(x, y) {
|
9962 | return [(x - dx) / k, (dy - y) / k];
|
9963 | };
|
9964 | return transform;
|
9965 | }
|
9966 |
|
9967 | function scaleTranslateRotate(k, dx, dy, alpha) {
|
9968 | var cosAlpha = cos$1(alpha),
|
9969 | sinAlpha = sin$1(alpha),
|
9970 | a = cosAlpha * k,
|
9971 | b = sinAlpha * k,
|
9972 | ai = cosAlpha / k,
|
9973 | bi = sinAlpha / k,
|
9974 | ci = (sinAlpha * dy - cosAlpha * dx) / k,
|
9975 | fi = (sinAlpha * dx + cosAlpha * dy) / k;
|
9976 | function transform(x, y) {
|
9977 | return [a * x - b * y + dx, dy - b * x - a * y];
|
9978 | }
|
9979 | transform.invert = function(x, y) {
|
9980 | return [ai * x - bi * y + ci, fi - bi * x - ai * y];
|
9981 | };
|
9982 | return transform;
|
9983 | }
|
9984 |
|
9985 | function projection(project) {
|
9986 | return projectionMutator(function() { return project; })();
|
9987 | }
|
9988 |
|
9989 | function projectionMutator(projectAt) {
|
9990 | var project,
|
9991 | k = 150, // scale
|
9992 | x = 480, y = 250, // translate
|
9993 | lambda = 0, phi = 0, // center
|
9994 | deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate
|
9995 | alpha = 0, // post-rotate
|
9996 | theta = null, preclip = clipAntimeridian, // pre-clip angle
|
9997 | x0 = null, y0, x1, y1, postclip = identity$4, // post-clip extent
|
9998 | delta2 = 0.5, // precision
|
9999 | projectResample,
|
10000 | projectTransform,
|
10001 | projectRotateTransform,
|
10002 | cache,
|
10003 | cacheStream;
|
10004 |
|
10005 | function projection(point) {
|
10006 | return projectRotateTransform(point[0] * radians, point[1] * radians);
|
10007 | }
|
10008 |
|
10009 | function invert(point) {
|
10010 | point = projectRotateTransform.invert(point[0], point[1]);
|
10011 | return point && [point[0] * degrees$1, point[1] * degrees$1];
|
10012 | }
|
10013 |
|
10014 | projection.stream = function(stream) {
|
10015 | return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream)))));
|
10016 | };
|
10017 |
|
10018 | projection.preclip = function(_) {
|
10019 | return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip;
|
10020 | };
|
10021 |
|
10022 | projection.postclip = function(_) {
|
10023 | return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
|
10024 | };
|
10025 |
|
10026 | projection.clipAngle = function(_) {
|
10027 | return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees$1;
|
10028 | };
|
10029 |
|
10030 | projection.clipExtent = function(_) {
|
10031 | return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
|
10032 | };
|
10033 |
|
10034 | projection.scale = function(_) {
|
10035 | return arguments.length ? (k = +_, recenter()) : k;
|
10036 | };
|
10037 |
|
10038 | projection.translate = function(_) {
|
10039 | return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
|
10040 | };
|
10041 |
|
10042 | projection.center = function(_) {
|
10043 | return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees$1, phi * degrees$1];
|
10044 | };
|
10045 |
|
10046 | projection.rotate = function(_) {
|
10047 | return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees$1, deltaPhi * degrees$1, deltaGamma * degrees$1];
|
10048 | };
|
10049 |
|
10050 | projection.angle = function(_) {
|
10051 | return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees$1;
|
10052 | };
|
10053 |
|
10054 | projection.precision = function(_) {
|
10055 | return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
|
10056 | };
|
10057 |
|
10058 | projection.fitExtent = function(extent, object) {
|
10059 | return fitExtent(projection, extent, object);
|
10060 | };
|
10061 |
|
10062 | projection.fitSize = function(size, object) {
|
10063 | return fitSize(projection, size, object);
|
10064 | };
|
10065 |
|
10066 | projection.fitWidth = function(width, object) {
|
10067 | return fitWidth(projection, width, object);
|
10068 | };
|
10069 |
|
10070 | projection.fitHeight = function(height, object) {
|
10071 | return fitHeight(projection, height, object);
|
10072 | };
|
10073 |
|
10074 | function recenter() {
|
10075 | var center = scaleTranslateRotate(k, 0, 0, alpha).apply(null, project(lambda, phi)),
|
10076 | transform = (alpha ? scaleTranslateRotate : scaleTranslate)(k, x - center[0], y - center[1], alpha);
|
10077 | rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma);
|
10078 | projectTransform = compose(project, transform);
|
10079 | projectRotateTransform = compose(rotate, projectTransform);
|
10080 | projectResample = resample(projectTransform, delta2);
|
10081 | return reset();
|
10082 | }
|
10083 |
|
10084 | function reset() {
|
10085 | cache = cacheStream = null;
|
10086 | return projection;
|
10087 | }
|
10088 |
|
10089 | return function() {
|
10090 | project = projectAt.apply(this, arguments);
|
10091 | projection.invert = project.invert && invert;
|
10092 | return recenter();
|
10093 | };
|
10094 | }
|
10095 |
|
10096 | function conicProjection(projectAt) {
|
10097 | var phi0 = 0,
|
10098 | phi1 = pi$3 / 3,
|
10099 | m = projectionMutator(projectAt),
|
10100 | p = m(phi0, phi1);
|
10101 |
|
10102 | p.parallels = function(_) {
|
10103 | return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees$1, phi1 * degrees$1];
|
10104 | };
|
10105 |
|
10106 | return p;
|
10107 | }
|
10108 |
|
10109 | function cylindricalEqualAreaRaw(phi0) {
|
10110 | var cosPhi0 = cos$1(phi0);
|
10111 |
|
10112 | function forward(lambda, phi) {
|
10113 | return [lambda * cosPhi0, sin$1(phi) / cosPhi0];
|
10114 | }
|
10115 |
|
10116 | forward.invert = function(x, y) {
|
10117 | return [x / cosPhi0, asin(y * cosPhi0)];
|
10118 | };
|
10119 |
|
10120 | return forward;
|
10121 | }
|
10122 |
|
10123 | function conicEqualAreaRaw(y0, y1) {
|
10124 | var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2;
|
10125 |
|
10126 | // Are the parallels symmetrical around the Equator?
|
10127 | if (abs(n) < epsilon$2) return cylindricalEqualAreaRaw(y0);
|
10128 |
|
10129 | var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt(c) / n;
|
10130 |
|
10131 | function project(x, y) {
|
10132 | var r = sqrt(c - 2 * n * sin$1(y)) / n;
|
10133 | return [r * sin$1(x *= n), r0 - r * cos$1(x)];
|
10134 | }
|
10135 |
|
10136 | project.invert = function(x, y) {
|
10137 | var r0y = r0 - y;
|
10138 | return [atan2(x, abs(r0y)) / n * sign(r0y), asin((c - (x * x + r0y * r0y) * n * n) / (2 * n))];
|
10139 | };
|
10140 |
|
10141 | return project;
|
10142 | }
|
10143 |
|
10144 | function conicEqualArea() {
|
10145 | return conicProjection(conicEqualAreaRaw)
|
10146 | .scale(155.424)
|
10147 | .center([0, 33.6442]);
|
10148 | }
|
10149 |
|
10150 | function albers() {
|
10151 | return conicEqualArea()
|
10152 | .parallels([29.5, 45.5])
|
10153 | .scale(1070)
|
10154 | .translate([480, 250])
|
10155 | .rotate([96, 0])
|
10156 | .center([-0.6, 38.7]);
|
10157 | }
|
10158 |
|
10159 | // The projections must have mutually exclusive clip regions on the sphere,
|
10160 | // as this will avoid emitting interleaving lines and polygons.
|
10161 | function multiplex(streams) {
|
10162 | var n = streams.length;
|
10163 | return {
|
10164 | point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
|
10165 | sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
|
10166 | lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
|
10167 | lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
|
10168 | polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
|
10169 | polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
|
10170 | };
|
10171 | }
|
10172 |
|
10173 | // A composite projection for the United States, configured by default for
|
10174 | // 960×500. The projection also works quite well at 960×600 if you change the
|
10175 | // scale to 1285 and adjust the translate accordingly. The set of standard
|
10176 | // parallels for each region comes from USGS, which is published here:
|
10177 | // http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
|
10178 | function albersUsa() {
|
10179 | var cache,
|
10180 | cacheStream,
|
10181 | lower48 = albers(), lower48Point,
|
10182 | alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
|
10183 | hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
|
10184 | point, pointStream = {point: function(x, y) { point = [x, y]; }};
|
10185 |
|
10186 | function albersUsa(coordinates) {
|
10187 | var x = coordinates[0], y = coordinates[1];
|
10188 | return point = null,
|
10189 | (lower48Point.point(x, y), point)
|
10190 | || (alaskaPoint.point(x, y), point)
|
10191 | || (hawaiiPoint.point(x, y), point);
|
10192 | }
|
10193 |
|
10194 | albersUsa.invert = function(coordinates) {
|
10195 | var k = lower48.scale(),
|
10196 | t = lower48.translate(),
|
10197 | x = (coordinates[0] - t[0]) / k,
|
10198 | y = (coordinates[1] - t[1]) / k;
|
10199 | return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
|
10200 | : y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
|
10201 | : lower48).invert(coordinates);
|
10202 | };
|
10203 |
|
10204 | albersUsa.stream = function(stream) {
|
10205 | return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
|
10206 | };
|
10207 |
|
10208 | albersUsa.precision = function(_) {
|
10209 | if (!arguments.length) return lower48.precision();
|
10210 | lower48.precision(_), alaska.precision(_), hawaii.precision(_);
|
10211 | return reset();
|
10212 | };
|
10213 |
|
10214 | albersUsa.scale = function(_) {
|
10215 | if (!arguments.length) return lower48.scale();
|
10216 | lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
|
10217 | return albersUsa.translate(lower48.translate());
|
10218 | };
|
10219 |
|
10220 | albersUsa.translate = function(_) {
|
10221 | if (!arguments.length) return lower48.translate();
|
10222 | var k = lower48.scale(), x = +_[0], y = +_[1];
|
10223 |
|
10224 | lower48Point = lower48
|
10225 | .translate(_)
|
10226 | .clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
|
10227 | .stream(pointStream);
|
10228 |
|
10229 | alaskaPoint = alaska
|
10230 | .translate([x - 0.307 * k, y + 0.201 * k])
|
10231 | .clipExtent([[x - 0.425 * k + epsilon$2, y + 0.120 * k + epsilon$2], [x - 0.214 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
|
10232 | .stream(pointStream);
|
10233 |
|
10234 | hawaiiPoint = hawaii
|
10235 | .translate([x - 0.205 * k, y + 0.212 * k])
|
10236 | .clipExtent([[x - 0.214 * k + epsilon$2, y + 0.166 * k + epsilon$2], [x - 0.115 * k - epsilon$2, y + 0.234 * k - epsilon$2]])
|
10237 | .stream(pointStream);
|
10238 |
|
10239 | return reset();
|
10240 | };
|
10241 |
|
10242 | albersUsa.fitExtent = function(extent, object) {
|
10243 | return fitExtent(albersUsa, extent, object);
|
10244 | };
|
10245 |
|
10246 | albersUsa.fitSize = function(size, object) {
|
10247 | return fitSize(albersUsa, size, object);
|
10248 | };
|
10249 |
|
10250 | albersUsa.fitWidth = function(width, object) {
|
10251 | return fitWidth(albersUsa, width, object);
|
10252 | };
|
10253 |
|
10254 | albersUsa.fitHeight = function(height, object) {
|
10255 | return fitHeight(albersUsa, height, object);
|
10256 | };
|
10257 |
|
10258 | function reset() {
|
10259 | cache = cacheStream = null;
|
10260 | return albersUsa;
|
10261 | }
|
10262 |
|
10263 | return albersUsa.scale(1070);
|
10264 | }
|
10265 |
|
10266 | function azimuthalRaw(scale) {
|
10267 | return function(x, y) {
|
10268 | var cx = cos$1(x),
|
10269 | cy = cos$1(y),
|
10270 | k = scale(cx * cy);
|
10271 | return [
|
10272 | k * cy * sin$1(x),
|
10273 | k * sin$1(y)
|
10274 | ];
|
10275 | }
|
10276 | }
|
10277 |
|
10278 | function azimuthalInvert(angle) {
|
10279 | return function(x, y) {
|
10280 | var z = sqrt(x * x + y * y),
|
10281 | c = angle(z),
|
10282 | sc = sin$1(c),
|
10283 | cc = cos$1(c);
|
10284 | return [
|
10285 | atan2(x * sc, z * cc),
|
10286 | asin(z && y * sc / z)
|
10287 | ];
|
10288 | }
|
10289 | }
|
10290 |
|
10291 | var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) {
|
10292 | return sqrt(2 / (1 + cxcy));
|
10293 | });
|
10294 |
|
10295 | azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) {
|
10296 | return 2 * asin(z / 2);
|
10297 | });
|
10298 |
|
10299 | function azimuthalEqualArea() {
|
10300 | return projection(azimuthalEqualAreaRaw)
|
10301 | .scale(124.75)
|
10302 | .clipAngle(180 - 1e-3);
|
10303 | }
|
10304 |
|
10305 | var azimuthalEquidistantRaw = azimuthalRaw(function(c) {
|
10306 | return (c = acos(c)) && c / sin$1(c);
|
10307 | });
|
10308 |
|
10309 | azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) {
|
10310 | return z;
|
10311 | });
|
10312 |
|
10313 | function azimuthalEquidistant() {
|
10314 | return projection(azimuthalEquidistantRaw)
|
10315 | .scale(79.4188)
|
10316 | .clipAngle(180 - 1e-3);
|
10317 | }
|
10318 |
|
10319 | function mercatorRaw(lambda, phi) {
|
10320 | return [lambda, log(tan((halfPi$2 + phi) / 2))];
|
10321 | }
|
10322 |
|
10323 | mercatorRaw.invert = function(x, y) {
|
10324 | return [x, 2 * atan(exp(y)) - halfPi$2];
|
10325 | };
|
10326 |
|
10327 | function mercator() {
|
10328 | return mercatorProjection(mercatorRaw)
|
10329 | .scale(961 / tau$3);
|
10330 | }
|
10331 |
|
10332 | function mercatorProjection(project) {
|
10333 | var m = projection(project),
|
10334 | center = m.center,
|
10335 | scale = m.scale,
|
10336 | translate = m.translate,
|
10337 | clipExtent = m.clipExtent,
|
10338 | x0 = null, y0, x1, y1; // clip extent
|
10339 |
|
10340 | m.scale = function(_) {
|
10341 | return arguments.length ? (scale(_), reclip()) : scale();
|
10342 | };
|
10343 |
|
10344 | m.translate = function(_) {
|
10345 | return arguments.length ? (translate(_), reclip()) : translate();
|
10346 | };
|
10347 |
|
10348 | m.center = function(_) {
|
10349 | return arguments.length ? (center(_), reclip()) : center();
|
10350 | };
|
10351 |
|
10352 | m.clipExtent = function(_) {
|
10353 | 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]];
|
10354 | };
|
10355 |
|
10356 | function reclip() {
|
10357 | var k = pi$3 * scale(),
|
10358 | t = m(rotation(m.rotate()).invert([0, 0]));
|
10359 | return clipExtent(x0 == null
|
10360 | ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
|
10361 | ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
|
10362 | : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
|
10363 | }
|
10364 |
|
10365 | return reclip();
|
10366 | }
|
10367 |
|
10368 | function tany(y) {
|
10369 | return tan((halfPi$2 + y) / 2);
|
10370 | }
|
10371 |
|
10372 | function conicConformalRaw(y0, y1) {
|
10373 | var cy0 = cos$1(y0),
|
10374 | n = y0 === y1 ? sin$1(y0) : log(cy0 / cos$1(y1)) / log(tany(y1) / tany(y0)),
|
10375 | f = cy0 * pow(tany(y0), n) / n;
|
10376 |
|
10377 | if (!n) return mercatorRaw;
|
10378 |
|
10379 | function project(x, y) {
|
10380 | if (f > 0) { if (y < -halfPi$2 + epsilon$2) y = -halfPi$2 + epsilon$2; }
|
10381 | else { if (y > halfPi$2 - epsilon$2) y = halfPi$2 - epsilon$2; }
|
10382 | var r = f / pow(tany(y), n);
|
10383 | return [r * sin$1(n * x), f - r * cos$1(n * x)];
|
10384 | }
|
10385 |
|
10386 | project.invert = function(x, y) {
|
10387 | var fy = f - y, r = sign(n) * sqrt(x * x + fy * fy);
|
10388 | return [atan2(x, abs(fy)) / n * sign(fy), 2 * atan(pow(f / r, 1 / n)) - halfPi$2];
|
10389 | };
|
10390 |
|
10391 | return project;
|
10392 | }
|
10393 |
|
10394 | function conicConformal() {
|
10395 | return conicProjection(conicConformalRaw)
|
10396 | .scale(109.5)
|
10397 | .parallels([30, 30]);
|
10398 | }
|
10399 |
|
10400 | function equirectangularRaw(lambda, phi) {
|
10401 | return [lambda, phi];
|
10402 | }
|
10403 |
|
10404 | equirectangularRaw.invert = equirectangularRaw;
|
10405 |
|
10406 | function equirectangular() {
|
10407 | return projection(equirectangularRaw)
|
10408 | .scale(152.63);
|
10409 | }
|
10410 |
|
10411 | function conicEquidistantRaw(y0, y1) {
|
10412 | var cy0 = cos$1(y0),
|
10413 | n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0),
|
10414 | g = cy0 / n + y0;
|
10415 |
|
10416 | if (abs(n) < epsilon$2) return equirectangularRaw;
|
10417 |
|
10418 | function project(x, y) {
|
10419 | var gy = g - y, nx = n * x;
|
10420 | return [gy * sin$1(nx), g - gy * cos$1(nx)];
|
10421 | }
|
10422 |
|
10423 | project.invert = function(x, y) {
|
10424 | var gy = g - y;
|
10425 | return [atan2(x, abs(gy)) / n * sign(gy), g - sign(n) * sqrt(x * x + gy * gy)];
|
10426 | };
|
10427 |
|
10428 | return project;
|
10429 | }
|
10430 |
|
10431 | function conicEquidistant() {
|
10432 | return conicProjection(conicEquidistantRaw)
|
10433 | .scale(131.154)
|
10434 | .center([0, 13.9389]);
|
10435 | }
|
10436 |
|
10437 | var A1 = 1.340264,
|
10438 | A2 = -0.081106,
|
10439 | A3 = 0.000893,
|
10440 | A4 = 0.003796,
|
10441 | M = sqrt(3) / 2,
|
10442 | iterations = 12;
|
10443 |
|
10444 | function equalEarthRaw(lambda, phi) {
|
10445 | var l = asin(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2;
|
10446 | return [
|
10447 | lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))),
|
10448 | l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2))
|
10449 | ];
|
10450 | }
|
10451 |
|
10452 | equalEarthRaw.invert = function(x, y) {
|
10453 | var l = y, l2 = l * l, l6 = l2 * l2 * l2;
|
10454 | for (var i = 0, delta, fy, fpy; i < iterations; ++i) {
|
10455 | fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y;
|
10456 | fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2);
|
10457 | l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2;
|
10458 | if (abs(delta) < epsilon2$1) break;
|
10459 | }
|
10460 | return [
|
10461 | M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l),
|
10462 | asin(sin$1(l) / M)
|
10463 | ];
|
10464 | };
|
10465 |
|
10466 | function equalEarth() {
|
10467 | return projection(equalEarthRaw)
|
10468 | .scale(177.158);
|
10469 | }
|
10470 |
|
10471 | function gnomonicRaw(x, y) {
|
10472 | var cy = cos$1(y), k = cos$1(x) * cy;
|
10473 | return [cy * sin$1(x) / k, sin$1(y) / k];
|
10474 | }
|
10475 |
|
10476 | gnomonicRaw.invert = azimuthalInvert(atan);
|
10477 |
|
10478 | function gnomonic() {
|
10479 | return projection(gnomonicRaw)
|
10480 | .scale(144.049)
|
10481 | .clipAngle(60);
|
10482 | }
|
10483 |
|
10484 | function scaleTranslate$1(kx, ky, tx, ty) {
|
10485 | return kx === 1 && ky === 1 && tx === 0 && ty === 0 ? identity$4 : transformer({
|
10486 | point: function(x, y) {
|
10487 | this.stream.point(x * kx + tx, y * ky + ty);
|
10488 | }
|
10489 | });
|
10490 | }
|
10491 |
|
10492 | function identity$5() {
|
10493 | var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, transform = identity$4, // scale, translate and reflect
|
10494 | x0 = null, y0, x1, y1, // clip extent
|
10495 | postclip = identity$4,
|
10496 | cache,
|
10497 | cacheStream,
|
10498 | projection;
|
10499 |
|
10500 | function reset() {
|
10501 | cache = cacheStream = null;
|
10502 | return projection;
|
10503 | }
|
10504 |
|
10505 | return projection = {
|
10506 | stream: function(stream) {
|
10507 | return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream));
|
10508 | },
|
10509 | postclip: function(_) {
|
10510 | return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip;
|
10511 | },
|
10512 | clipExtent: function(_) {
|
10513 | return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$4) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
|
10514 | },
|
10515 | scale: function(_) {
|
10516 | return arguments.length ? (transform = scaleTranslate$1((k = +_) * sx, k * sy, tx, ty), reset()) : k;
|
10517 | },
|
10518 | translate: function(_) {
|
10519 | return arguments.length ? (transform = scaleTranslate$1(k * sx, k * sy, tx = +_[0], ty = +_[1]), reset()) : [tx, ty];
|
10520 | },
|
10521 | reflectX: function(_) {
|
10522 | return arguments.length ? (transform = scaleTranslate$1(k * (sx = _ ? -1 : 1), k * sy, tx, ty), reset()) : sx < 0;
|
10523 | },
|
10524 | reflectY: function(_) {
|
10525 | return arguments.length ? (transform = scaleTranslate$1(k * sx, k * (sy = _ ? -1 : 1), tx, ty), reset()) : sy < 0;
|
10526 | },
|
10527 | fitExtent: function(extent, object) {
|
10528 | return fitExtent(projection, extent, object);
|
10529 | },
|
10530 | fitSize: function(size, object) {
|
10531 | return fitSize(projection, size, object);
|
10532 | },
|
10533 | fitWidth: function(width, object) {
|
10534 | return fitWidth(projection, width, object);
|
10535 | },
|
10536 | fitHeight: function(height, object) {
|
10537 | return fitHeight(projection, height, object);
|
10538 | }
|
10539 | };
|
10540 | }
|
10541 |
|
10542 | function naturalEarth1Raw(lambda, phi) {
|
10543 | var phi2 = phi * phi, phi4 = phi2 * phi2;
|
10544 | return [
|
10545 | lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))),
|
10546 | phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4)))
|
10547 | ];
|
10548 | }
|
10549 |
|
10550 | naturalEarth1Raw.invert = function(x, y) {
|
10551 | var phi = y, i = 25, delta;
|
10552 | do {
|
10553 | var phi2 = phi * phi, phi4 = phi2 * phi2;
|
10554 | phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) /
|
10555 | (1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4)));
|
10556 | } while (abs(delta) > epsilon$2 && --i > 0);
|
10557 | return [
|
10558 | x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))),
|
10559 | phi
|
10560 | ];
|
10561 | };
|
10562 |
|
10563 | function naturalEarth1() {
|
10564 | return projection(naturalEarth1Raw)
|
10565 | .scale(175.295);
|
10566 | }
|
10567 |
|
10568 | function orthographicRaw(x, y) {
|
10569 | return [cos$1(y) * sin$1(x), sin$1(y)];
|
10570 | }
|
10571 |
|
10572 | orthographicRaw.invert = azimuthalInvert(asin);
|
10573 |
|
10574 | function orthographic() {
|
10575 | return projection(orthographicRaw)
|
10576 | .scale(249.5)
|
10577 | .clipAngle(90 + epsilon$2);
|
10578 | }
|
10579 |
|
10580 | function stereographicRaw(x, y) {
|
10581 | var cy = cos$1(y), k = 1 + cos$1(x) * cy;
|
10582 | return [cy * sin$1(x) / k, sin$1(y) / k];
|
10583 | }
|
10584 |
|
10585 | stereographicRaw.invert = azimuthalInvert(function(z) {
|
10586 | return 2 * atan(z);
|
10587 | });
|
10588 |
|
10589 | function stereographic() {
|
10590 | return projection(stereographicRaw)
|
10591 | .scale(250)
|
10592 | .clipAngle(142);
|
10593 | }
|
10594 |
|
10595 | function transverseMercatorRaw(lambda, phi) {
|
10596 | return [log(tan((halfPi$2 + phi) / 2)), -lambda];
|
10597 | }
|
10598 |
|
10599 | transverseMercatorRaw.invert = function(x, y) {
|
10600 | return [-y, 2 * atan(exp(x)) - halfPi$2];
|
10601 | };
|
10602 |
|
10603 | function transverseMercator() {
|
10604 | var m = mercatorProjection(transverseMercatorRaw),
|
10605 | center = m.center,
|
10606 | rotate = m.rotate;
|
10607 |
|
10608 | m.center = function(_) {
|
10609 | return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
|
10610 | };
|
10611 |
|
10612 | m.rotate = function(_) {
|
10613 | return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
|
10614 | };
|
10615 |
|
10616 | return rotate([0, 0, 90])
|
10617 | .scale(159.155);
|
10618 | }
|
10619 |
|
10620 | function defaultSeparation(a, b) {
|
10621 | return a.parent === b.parent ? 1 : 2;
|
10622 | }
|
10623 |
|
10624 | function meanX(children) {
|
10625 | return children.reduce(meanXReduce, 0) / children.length;
|
10626 | }
|
10627 |
|
10628 | function meanXReduce(x, c) {
|
10629 | return x + c.x;
|
10630 | }
|
10631 |
|
10632 | function maxY(children) {
|
10633 | return 1 + children.reduce(maxYReduce, 0);
|
10634 | }
|
10635 |
|
10636 | function maxYReduce(y, c) {
|
10637 | return Math.max(y, c.y);
|
10638 | }
|
10639 |
|
10640 | function leafLeft(node) {
|
10641 | var children;
|
10642 | while (children = node.children) node = children[0];
|
10643 | return node;
|
10644 | }
|
10645 |
|
10646 | function leafRight(node) {
|
10647 | var children;
|
10648 | while (children = node.children) node = children[children.length - 1];
|
10649 | return node;
|
10650 | }
|
10651 |
|
10652 | function cluster() {
|
10653 | var separation = defaultSeparation,
|
10654 | dx = 1,
|
10655 | dy = 1,
|
10656 | nodeSize = false;
|
10657 |
|
10658 | function cluster(root) {
|
10659 | var previousNode,
|
10660 | x = 0;
|
10661 |
|
10662 | // First walk, computing the initial x & y values.
|
10663 | root.eachAfter(function(node) {
|
10664 | var children = node.children;
|
10665 | if (children) {
|
10666 | node.x = meanX(children);
|
10667 | node.y = maxY(children);
|
10668 | } else {
|
10669 | node.x = previousNode ? x += separation(node, previousNode) : 0;
|
10670 | node.y = 0;
|
10671 | previousNode = node;
|
10672 | }
|
10673 | });
|
10674 |
|
10675 | var left = leafLeft(root),
|
10676 | right = leafRight(root),
|
10677 | x0 = left.x - separation(left, right) / 2,
|
10678 | x1 = right.x + separation(right, left) / 2;
|
10679 |
|
10680 | // Second walk, normalizing x & y to the desired size.
|
10681 | return root.eachAfter(nodeSize ? function(node) {
|
10682 | node.x = (node.x - root.x) * dx;
|
10683 | node.y = (root.y - node.y) * dy;
|
10684 | } : function(node) {
|
10685 | node.x = (node.x - x0) / (x1 - x0) * dx;
|
10686 | node.y = (1 - (root.y ? node.y / root.y : 1)) * dy;
|
10687 | });
|
10688 | }
|
10689 |
|
10690 | cluster.separation = function(x) {
|
10691 | return arguments.length ? (separation = x, cluster) : separation;
|
10692 | };
|
10693 |
|
10694 | cluster.size = function(x) {
|
10695 | return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]);
|
10696 | };
|
10697 |
|
10698 | cluster.nodeSize = function(x) {
|
10699 | return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null);
|
10700 | };
|
10701 |
|
10702 | return cluster;
|
10703 | }
|
10704 |
|
10705 | function count(node) {
|
10706 | var sum = 0,
|
10707 | children = node.children,
|
10708 | i = children && children.length;
|
10709 | if (!i) sum = 1;
|
10710 | else while (--i >= 0) sum += children[i].value;
|
10711 | node.value = sum;
|
10712 | }
|
10713 |
|
10714 | function node_count() {
|
10715 | return this.eachAfter(count);
|
10716 | }
|
10717 |
|
10718 | function node_each(callback) {
|
10719 | var node = this, current, next = [node], children, i, n;
|
10720 | do {
|
10721 | current = next.reverse(), next = [];
|
10722 | while (node = current.pop()) {
|
10723 | callback(node), children = node.children;
|
10724 | if (children) for (i = 0, n = children.length; i < n; ++i) {
|
10725 | next.push(children[i]);
|
10726 | }
|
10727 | }
|
10728 | } while (next.length);
|
10729 | return this;
|
10730 | }
|
10731 |
|
10732 | function node_eachBefore(callback) {
|
10733 | var node = this, nodes = [node], children, i;
|
10734 | while (node = nodes.pop()) {
|
10735 | callback(node), children = node.children;
|
10736 | if (children) for (i = children.length - 1; i >= 0; --i) {
|
10737 | nodes.push(children[i]);
|
10738 | }
|
10739 | }
|
10740 | return this;
|
10741 | }
|
10742 |
|
10743 | function node_eachAfter(callback) {
|
10744 | var node = this, nodes = [node], next = [], children, i, n;
|
10745 | while (node = nodes.pop()) {
|
10746 | next.push(node), children = node.children;
|
10747 | if (children) for (i = 0, n = children.length; i < n; ++i) {
|
10748 | nodes.push(children[i]);
|
10749 | }
|
10750 | }
|
10751 | while (node = next.pop()) {
|
10752 | callback(node);
|
10753 | }
|
10754 | return this;
|
10755 | }
|
10756 |
|
10757 | function node_sum(value) {
|
10758 | return this.eachAfter(function(node) {
|
10759 | var sum = +value(node.data) || 0,
|
10760 | children = node.children,
|
10761 | i = children && children.length;
|
10762 | while (--i >= 0) sum += children[i].value;
|
10763 | node.value = sum;
|
10764 | });
|
10765 | }
|
10766 |
|
10767 | function node_sort(compare) {
|
10768 | return this.eachBefore(function(node) {
|
10769 | if (node.children) {
|
10770 | node.children.sort(compare);
|
10771 | }
|
10772 | });
|
10773 | }
|
10774 |
|
10775 | function node_path(end) {
|
10776 | var start = this,
|
10777 | ancestor = leastCommonAncestor(start, end),
|
10778 | nodes = [start];
|
10779 | while (start !== ancestor) {
|
10780 | start = start.parent;
|
10781 | nodes.push(start);
|
10782 | }
|
10783 | var k = nodes.length;
|
10784 | while (end !== ancestor) {
|
10785 | nodes.splice(k, 0, end);
|
10786 | end = end.parent;
|
10787 | }
|
10788 | return nodes;
|
10789 | }
|
10790 |
|
10791 | function leastCommonAncestor(a, b) {
|
10792 | if (a === b) return a;
|
10793 | var aNodes = a.ancestors(),
|
10794 | bNodes = b.ancestors(),
|
10795 | c = null;
|
10796 | a = aNodes.pop();
|
10797 | b = bNodes.pop();
|
10798 | while (a === b) {
|
10799 | c = a;
|
10800 | a = aNodes.pop();
|
10801 | b = bNodes.pop();
|
10802 | }
|
10803 | return c;
|
10804 | }
|
10805 |
|
10806 | function node_ancestors() {
|
10807 | var node = this, nodes = [node];
|
10808 | while (node = node.parent) {
|
10809 | nodes.push(node);
|
10810 | }
|
10811 | return nodes;
|
10812 | }
|
10813 |
|
10814 | function node_descendants() {
|
10815 | var nodes = [];
|
10816 | this.each(function(node) {
|
10817 | nodes.push(node);
|
10818 | });
|
10819 | return nodes;
|
10820 | }
|
10821 |
|
10822 | function node_leaves() {
|
10823 | var leaves = [];
|
10824 | this.eachBefore(function(node) {
|
10825 | if (!node.children) {
|
10826 | leaves.push(node);
|
10827 | }
|
10828 | });
|
10829 | return leaves;
|
10830 | }
|
10831 |
|
10832 | function node_links() {
|
10833 | var root = this, links = [];
|
10834 | root.each(function(node) {
|
10835 | if (node !== root) { // Don’t include the root’s parent, if any.
|
10836 | links.push({source: node.parent, target: node});
|
10837 | }
|
10838 | });
|
10839 | return links;
|
10840 | }
|
10841 |
|
10842 | function hierarchy(data, children) {
|
10843 | var root = new Node(data),
|
10844 | valued = +data.value && (root.value = data.value),
|
10845 | node,
|
10846 | nodes = [root],
|
10847 | child,
|
10848 | childs,
|
10849 | i,
|
10850 | n;
|
10851 |
|
10852 | if (children == null) children = defaultChildren;
|
10853 |
|
10854 | while (node = nodes.pop()) {
|
10855 | if (valued) node.value = +node.data.value;
|
10856 | if ((childs = children(node.data)) && (n = childs.length)) {
|
10857 | node.children = new Array(n);
|
10858 | for (i = n - 1; i >= 0; --i) {
|
10859 | nodes.push(child = node.children[i] = new Node(childs[i]));
|
10860 | child.parent = node;
|
10861 | child.depth = node.depth + 1;
|
10862 | }
|
10863 | }
|
10864 | }
|
10865 |
|
10866 | return root.eachBefore(computeHeight);
|
10867 | }
|
10868 |
|
10869 | function node_copy() {
|
10870 | return hierarchy(this).eachBefore(copyData);
|
10871 | }
|
10872 |
|
10873 | function defaultChildren(d) {
|
10874 | return d.children;
|
10875 | }
|
10876 |
|
10877 | function copyData(node) {
|
10878 | node.data = node.data.data;
|
10879 | }
|
10880 |
|
10881 | function computeHeight(node) {
|
10882 | var height = 0;
|
10883 | do node.height = height;
|
10884 | while ((node = node.parent) && (node.height < ++height));
|
10885 | }
|
10886 |
|
10887 | function Node(data) {
|
10888 | this.data = data;
|
10889 | this.depth =
|
10890 | this.height = 0;
|
10891 | this.parent = null;
|
10892 | }
|
10893 |
|
10894 | Node.prototype = hierarchy.prototype = {
|
10895 | constructor: Node,
|
10896 | count: node_count,
|
10897 | each: node_each,
|
10898 | eachAfter: node_eachAfter,
|
10899 | eachBefore: node_eachBefore,
|
10900 | sum: node_sum,
|
10901 | sort: node_sort,
|
10902 | path: node_path,
|
10903 | ancestors: node_ancestors,
|
10904 | descendants: node_descendants,
|
10905 | leaves: node_leaves,
|
10906 | links: node_links,
|
10907 | copy: node_copy
|
10908 | };
|
10909 |
|
10910 | var slice$4 = Array.prototype.slice;
|
10911 |
|
10912 | function shuffle$1(array) {
|
10913 | var m = array.length,
|
10914 | t,
|
10915 | i;
|
10916 |
|
10917 | while (m) {
|
10918 | i = Math.random() * m-- | 0;
|
10919 | t = array[m];
|
10920 | array[m] = array[i];
|
10921 | array[i] = t;
|
10922 | }
|
10923 |
|
10924 | return array;
|
10925 | }
|
10926 |
|
10927 | function enclose(circles) {
|
10928 | var i = 0, n = (circles = shuffle$1(slice$4.call(circles))).length, B = [], p, e;
|
10929 |
|
10930 | while (i < n) {
|
10931 | p = circles[i];
|
10932 | if (e && enclosesWeak(e, p)) ++i;
|
10933 | else e = encloseBasis(B = extendBasis(B, p)), i = 0;
|
10934 | }
|
10935 |
|
10936 | return e;
|
10937 | }
|
10938 |
|
10939 | function extendBasis(B, p) {
|
10940 | var i, j;
|
10941 |
|
10942 | if (enclosesWeakAll(p, B)) return [p];
|
10943 |
|
10944 | // If we get here then B must have at least one element.
|
10945 | for (i = 0; i < B.length; ++i) {
|
10946 | if (enclosesNot(p, B[i])
|
10947 | && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
|
10948 | return [B[i], p];
|
10949 | }
|
10950 | }
|
10951 |
|
10952 | // If we get here then B must have at least two elements.
|
10953 | for (i = 0; i < B.length - 1; ++i) {
|
10954 | for (j = i + 1; j < B.length; ++j) {
|
10955 | if (enclosesNot(encloseBasis2(B[i], B[j]), p)
|
10956 | && enclosesNot(encloseBasis2(B[i], p), B[j])
|
10957 | && enclosesNot(encloseBasis2(B[j], p), B[i])
|
10958 | && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
|
10959 | return [B[i], B[j], p];
|
10960 | }
|
10961 | }
|
10962 | }
|
10963 |
|
10964 | // If we get here then something is very wrong.
|
10965 | throw new Error;
|
10966 | }
|
10967 |
|
10968 | function enclosesNot(a, b) {
|
10969 | var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
|
10970 | return dr < 0 || dr * dr < dx * dx + dy * dy;
|
10971 | }
|
10972 |
|
10973 | function enclosesWeak(a, b) {
|
10974 | var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
|
10975 | return dr > 0 && dr * dr > dx * dx + dy * dy;
|
10976 | }
|
10977 |
|
10978 | function enclosesWeakAll(a, B) {
|
10979 | for (var i = 0; i < B.length; ++i) {
|
10980 | if (!enclosesWeak(a, B[i])) {
|
10981 | return false;
|
10982 | }
|
10983 | }
|
10984 | return true;
|
10985 | }
|
10986 |
|
10987 | function encloseBasis(B) {
|
10988 | switch (B.length) {
|
10989 | case 1: return encloseBasis1(B[0]);
|
10990 | case 2: return encloseBasis2(B[0], B[1]);
|
10991 | case 3: return encloseBasis3(B[0], B[1], B[2]);
|
10992 | }
|
10993 | }
|
10994 |
|
10995 | function encloseBasis1(a) {
|
10996 | return {
|
10997 | x: a.x,
|
10998 | y: a.y,
|
10999 | r: a.r
|
11000 | };
|
11001 | }
|
11002 |
|
11003 | function encloseBasis2(a, b) {
|
11004 | var x1 = a.x, y1 = a.y, r1 = a.r,
|
11005 | x2 = b.x, y2 = b.y, r2 = b.r,
|
11006 | x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
|
11007 | l = Math.sqrt(x21 * x21 + y21 * y21);
|
11008 | return {
|
11009 | x: (x1 + x2 + x21 / l * r21) / 2,
|
11010 | y: (y1 + y2 + y21 / l * r21) / 2,
|
11011 | r: (l + r1 + r2) / 2
|
11012 | };
|
11013 | }
|
11014 |
|
11015 | function encloseBasis3(a, b, c) {
|
11016 | var x1 = a.x, y1 = a.y, r1 = a.r,
|
11017 | x2 = b.x, y2 = b.y, r2 = b.r,
|
11018 | x3 = c.x, y3 = c.y, r3 = c.r,
|
11019 | a2 = x1 - x2,
|
11020 | a3 = x1 - x3,
|
11021 | b2 = y1 - y2,
|
11022 | b3 = y1 - y3,
|
11023 | c2 = r2 - r1,
|
11024 | c3 = r3 - r1,
|
11025 | d1 = x1 * x1 + y1 * y1 - r1 * r1,
|
11026 | d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
|
11027 | d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
|
11028 | ab = a3 * b2 - a2 * b3,
|
11029 | xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
|
11030 | xb = (b3 * c2 - b2 * c3) / ab,
|
11031 | ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
|
11032 | yb = (a2 * c3 - a3 * c2) / ab,
|
11033 | A = xb * xb + yb * yb - 1,
|
11034 | B = 2 * (r1 + xa * xb + ya * yb),
|
11035 | C = xa * xa + ya * ya - r1 * r1,
|
11036 | r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
|
11037 | return {
|
11038 | x: x1 + xa + xb * r,
|
11039 | y: y1 + ya + yb * r,
|
11040 | r: r
|
11041 | };
|
11042 | }
|
11043 |
|
11044 | function place(b, a, c) {
|
11045 | var dx = b.x - a.x, x, a2,
|
11046 | dy = b.y - a.y, y, b2,
|
11047 | d2 = dx * dx + dy * dy;
|
11048 | if (d2) {
|
11049 | a2 = a.r + c.r, a2 *= a2;
|
11050 | b2 = b.r + c.r, b2 *= b2;
|
11051 | if (a2 > b2) {
|
11052 | x = (d2 + b2 - a2) / (2 * d2);
|
11053 | y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
|
11054 | c.x = b.x - x * dx - y * dy;
|
11055 | c.y = b.y - x * dy + y * dx;
|
11056 | } else {
|
11057 | x = (d2 + a2 - b2) / (2 * d2);
|
11058 | y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
|
11059 | c.x = a.x + x * dx - y * dy;
|
11060 | c.y = a.y + x * dy + y * dx;
|
11061 | }
|
11062 | } else {
|
11063 | c.x = a.x + c.r;
|
11064 | c.y = a.y;
|
11065 | }
|
11066 | }
|
11067 |
|
11068 | function intersects(a, b) {
|
11069 | var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
|
11070 | return dr > 0 && dr * dr > dx * dx + dy * dy;
|
11071 | }
|
11072 |
|
11073 | function score(node) {
|
11074 | var a = node._,
|
11075 | b = node.next._,
|
11076 | ab = a.r + b.r,
|
11077 | dx = (a.x * b.r + b.x * a.r) / ab,
|
11078 | dy = (a.y * b.r + b.y * a.r) / ab;
|
11079 | return dx * dx + dy * dy;
|
11080 | }
|
11081 |
|
11082 | function Node$1(circle) {
|
11083 | this._ = circle;
|
11084 | this.next = null;
|
11085 | this.previous = null;
|
11086 | }
|
11087 |
|
11088 | function packEnclose(circles) {
|
11089 | if (!(n = circles.length)) return 0;
|
11090 |
|
11091 | var a, b, c, n, aa, ca, i, j, k, sj, sk;
|
11092 |
|
11093 | // Place the first circle.
|
11094 | a = circles[0], a.x = 0, a.y = 0;
|
11095 | if (!(n > 1)) return a.r;
|
11096 |
|
11097 | // Place the second circle.
|
11098 | b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0;
|
11099 | if (!(n > 2)) return a.r + b.r;
|
11100 |
|
11101 | // Place the third circle.
|
11102 | place(b, a, c = circles[2]);
|
11103 |
|
11104 | // Initialize the front-chain using the first three circles a, b and c.
|
11105 | a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
|
11106 | a.next = c.previous = b;
|
11107 | b.next = a.previous = c;
|
11108 | c.next = b.previous = a;
|
11109 |
|
11110 | // Attempt to place each remaining circle…
|
11111 | pack: for (i = 3; i < n; ++i) {
|
11112 | place(a._, b._, c = circles[i]), c = new Node$1(c);
|
11113 |
|
11114 | // Find the closest intersecting circle on the front-chain, if any.
|
11115 | // “Closeness” is determined by linear distance along the front-chain.
|
11116 | // “Ahead” or “behind” is likewise determined by linear distance.
|
11117 | j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
|
11118 | do {
|
11119 | if (sj <= sk) {
|
11120 | if (intersects(j._, c._)) {
|
11121 | b = j, a.next = b, b.previous = a, --i;
|
11122 | continue pack;
|
11123 | }
|
11124 | sj += j._.r, j = j.next;
|
11125 | } else {
|
11126 | if (intersects(k._, c._)) {
|
11127 | a = k, a.next = b, b.previous = a, --i;
|
11128 | continue pack;
|
11129 | }
|
11130 | sk += k._.r, k = k.previous;
|
11131 | }
|
11132 | } while (j !== k.next);
|
11133 |
|
11134 | // Success! Insert the new circle c between a and b.
|
11135 | c.previous = a, c.next = b, a.next = b.previous = b = c;
|
11136 |
|
11137 | // Compute the new closest circle pair to the centroid.
|
11138 | aa = score(a);
|
11139 | while ((c = c.next) !== b) {
|
11140 | if ((ca = score(c)) < aa) {
|
11141 | a = c, aa = ca;
|
11142 | }
|
11143 | }
|
11144 | b = a.next;
|
11145 | }
|
11146 |
|
11147 | // Compute the enclosing circle of the front chain.
|
11148 | a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = enclose(a);
|
11149 |
|
11150 | // Translate the circles to put the enclosing circle around the origin.
|
11151 | for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y;
|
11152 |
|
11153 | return c.r;
|
11154 | }
|
11155 |
|
11156 | function siblings(circles) {
|
11157 | packEnclose(circles);
|
11158 | return circles;
|
11159 | }
|
11160 |
|
11161 | function optional(f) {
|
11162 | return f == null ? null : required(f);
|
11163 | }
|
11164 |
|
11165 | function required(f) {
|
11166 | if (typeof f !== "function") throw new Error;
|
11167 | return f;
|
11168 | }
|
11169 |
|
11170 | function constantZero() {
|
11171 | return 0;
|
11172 | }
|
11173 |
|
11174 | function constant$9(x) {
|
11175 | return function() {
|
11176 | return x;
|
11177 | };
|
11178 | }
|
11179 |
|
11180 | function defaultRadius$1(d) {
|
11181 | return Math.sqrt(d.value);
|
11182 | }
|
11183 |
|
11184 | function index$2() {
|
11185 | var radius = null,
|
11186 | dx = 1,
|
11187 | dy = 1,
|
11188 | padding = constantZero;
|
11189 |
|
11190 | function pack(root) {
|
11191 | root.x = dx / 2, root.y = dy / 2;
|
11192 | if (radius) {
|
11193 | root.eachBefore(radiusLeaf(radius))
|
11194 | .eachAfter(packChildren(padding, 0.5))
|
11195 | .eachBefore(translateChild(1));
|
11196 | } else {
|
11197 | root.eachBefore(radiusLeaf(defaultRadius$1))
|
11198 | .eachAfter(packChildren(constantZero, 1))
|
11199 | .eachAfter(packChildren(padding, root.r / Math.min(dx, dy)))
|
11200 | .eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r)));
|
11201 | }
|
11202 | return root;
|
11203 | }
|
11204 |
|
11205 | pack.radius = function(x) {
|
11206 | return arguments.length ? (radius = optional(x), pack) : radius;
|
11207 | };
|
11208 |
|
11209 | pack.size = function(x) {
|
11210 | return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy];
|
11211 | };
|
11212 |
|
11213 | pack.padding = function(x) {
|
11214 | return arguments.length ? (padding = typeof x === "function" ? x : constant$9(+x), pack) : padding;
|
11215 | };
|
11216 |
|
11217 | return pack;
|
11218 | }
|
11219 |
|
11220 | function radiusLeaf(radius) {
|
11221 | return function(node) {
|
11222 | if (!node.children) {
|
11223 | node.r = Math.max(0, +radius(node) || 0);
|
11224 | }
|
11225 | };
|
11226 | }
|
11227 |
|
11228 | function packChildren(padding, k) {
|
11229 | return function(node) {
|
11230 | if (children = node.children) {
|
11231 | var children,
|
11232 | i,
|
11233 | n = children.length,
|
11234 | r = padding(node) * k || 0,
|
11235 | e;
|
11236 |
|
11237 | if (r) for (i = 0; i < n; ++i) children[i].r += r;
|
11238 | e = packEnclose(children);
|
11239 | if (r) for (i = 0; i < n; ++i) children[i].r -= r;
|
11240 | node.r = e + r;
|
11241 | }
|
11242 | };
|
11243 | }
|
11244 |
|
11245 | function translateChild(k) {
|
11246 | return function(node) {
|
11247 | var parent = node.parent;
|
11248 | node.r *= k;
|
11249 | if (parent) {
|
11250 | node.x = parent.x + k * node.x;
|
11251 | node.y = parent.y + k * node.y;
|
11252 | }
|
11253 | };
|
11254 | }
|
11255 |
|
11256 | function roundNode(node) {
|
11257 | node.x0 = Math.round(node.x0);
|
11258 | node.y0 = Math.round(node.y0);
|
11259 | node.x1 = Math.round(node.x1);
|
11260 | node.y1 = Math.round(node.y1);
|
11261 | }
|
11262 |
|
11263 | function treemapDice(parent, x0, y0, x1, y1) {
|
11264 | var nodes = parent.children,
|
11265 | node,
|
11266 | i = -1,
|
11267 | n = nodes.length,
|
11268 | k = parent.value && (x1 - x0) / parent.value;
|
11269 |
|
11270 | while (++i < n) {
|
11271 | node = nodes[i], node.y0 = y0, node.y1 = y1;
|
11272 | node.x0 = x0, node.x1 = x0 += node.value * k;
|
11273 | }
|
11274 | }
|
11275 |
|
11276 | function partition() {
|
11277 | var dx = 1,
|
11278 | dy = 1,
|
11279 | padding = 0,
|
11280 | round = false;
|
11281 |
|
11282 | function partition(root) {
|
11283 | var n = root.height + 1;
|
11284 | root.x0 =
|
11285 | root.y0 = padding;
|
11286 | root.x1 = dx;
|
11287 | root.y1 = dy / n;
|
11288 | root.eachBefore(positionNode(dy, n));
|
11289 | if (round) root.eachBefore(roundNode);
|
11290 | return root;
|
11291 | }
|
11292 |
|
11293 | function positionNode(dy, n) {
|
11294 | return function(node) {
|
11295 | if (node.children) {
|
11296 | treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
|
11297 | }
|
11298 | var x0 = node.x0,
|
11299 | y0 = node.y0,
|
11300 | x1 = node.x1 - padding,
|
11301 | y1 = node.y1 - padding;
|
11302 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
11303 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
11304 | node.x0 = x0;
|
11305 | node.y0 = y0;
|
11306 | node.x1 = x1;
|
11307 | node.y1 = y1;
|
11308 | };
|
11309 | }
|
11310 |
|
11311 | partition.round = function(x) {
|
11312 | return arguments.length ? (round = !!x, partition) : round;
|
11313 | };
|
11314 |
|
11315 | partition.size = function(x) {
|
11316 | return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
|
11317 | };
|
11318 |
|
11319 | partition.padding = function(x) {
|
11320 | return arguments.length ? (padding = +x, partition) : padding;
|
11321 | };
|
11322 |
|
11323 | return partition;
|
11324 | }
|
11325 |
|
11326 | var keyPrefix$1 = "$", // Protect against keys like “__proto__”.
|
11327 | preroot = {depth: -1},
|
11328 | ambiguous = {};
|
11329 |
|
11330 | function defaultId(d) {
|
11331 | return d.id;
|
11332 | }
|
11333 |
|
11334 | function defaultParentId(d) {
|
11335 | return d.parentId;
|
11336 | }
|
11337 |
|
11338 | function stratify() {
|
11339 | var id = defaultId,
|
11340 | parentId = defaultParentId;
|
11341 |
|
11342 | function stratify(data) {
|
11343 | var d,
|
11344 | i,
|
11345 | n = data.length,
|
11346 | root,
|
11347 | parent,
|
11348 | node,
|
11349 | nodes = new Array(n),
|
11350 | nodeId,
|
11351 | nodeKey,
|
11352 | nodeByKey = {};
|
11353 |
|
11354 | for (i = 0; i < n; ++i) {
|
11355 | d = data[i], node = nodes[i] = new Node(d);
|
11356 | if ((nodeId = id(d, i, data)) != null && (nodeId += "")) {
|
11357 | nodeKey = keyPrefix$1 + (node.id = nodeId);
|
11358 | nodeByKey[nodeKey] = nodeKey in nodeByKey ? ambiguous : node;
|
11359 | }
|
11360 | }
|
11361 |
|
11362 | for (i = 0; i < n; ++i) {
|
11363 | node = nodes[i], nodeId = parentId(data[i], i, data);
|
11364 | if (nodeId == null || !(nodeId += "")) {
|
11365 | if (root) throw new Error("multiple roots");
|
11366 | root = node;
|
11367 | } else {
|
11368 | parent = nodeByKey[keyPrefix$1 + nodeId];
|
11369 | if (!parent) throw new Error("missing: " + nodeId);
|
11370 | if (parent === ambiguous) throw new Error("ambiguous: " + nodeId);
|
11371 | if (parent.children) parent.children.push(node);
|
11372 | else parent.children = [node];
|
11373 | node.parent = parent;
|
11374 | }
|
11375 | }
|
11376 |
|
11377 | if (!root) throw new Error("no root");
|
11378 | root.parent = preroot;
|
11379 | root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight);
|
11380 | root.parent = null;
|
11381 | if (n > 0) throw new Error("cycle");
|
11382 |
|
11383 | return root;
|
11384 | }
|
11385 |
|
11386 | stratify.id = function(x) {
|
11387 | return arguments.length ? (id = required(x), stratify) : id;
|
11388 | };
|
11389 |
|
11390 | stratify.parentId = function(x) {
|
11391 | return arguments.length ? (parentId = required(x), stratify) : parentId;
|
11392 | };
|
11393 |
|
11394 | return stratify;
|
11395 | }
|
11396 |
|
11397 | function defaultSeparation$1(a, b) {
|
11398 | return a.parent === b.parent ? 1 : 2;
|
11399 | }
|
11400 |
|
11401 | // function radialSeparation(a, b) {
|
11402 | // return (a.parent === b.parent ? 1 : 2) / a.depth;
|
11403 | // }
|
11404 |
|
11405 | // This function is used to traverse the left contour of a subtree (or
|
11406 | // subforest). It returns the successor of v on this contour. This successor is
|
11407 | // either given by the leftmost child of v or by the thread of v. The function
|
11408 | // returns null if and only if v is on the highest level of its subtree.
|
11409 | function nextLeft(v) {
|
11410 | var children = v.children;
|
11411 | return children ? children[0] : v.t;
|
11412 | }
|
11413 |
|
11414 | // This function works analogously to nextLeft.
|
11415 | function nextRight(v) {
|
11416 | var children = v.children;
|
11417 | return children ? children[children.length - 1] : v.t;
|
11418 | }
|
11419 |
|
11420 | // Shifts the current subtree rooted at w+. This is done by increasing
|
11421 | // prelim(w+) and mod(w+) by shift.
|
11422 | function moveSubtree(wm, wp, shift) {
|
11423 | var change = shift / (wp.i - wm.i);
|
11424 | wp.c -= change;
|
11425 | wp.s += shift;
|
11426 | wm.c += change;
|
11427 | wp.z += shift;
|
11428 | wp.m += shift;
|
11429 | }
|
11430 |
|
11431 | // All other shifts, applied to the smaller subtrees between w- and w+, are
|
11432 | // performed by this function. To prepare the shifts, we have to adjust
|
11433 | // change(w+), shift(w+), and change(w-).
|
11434 | function executeShifts(v) {
|
11435 | var shift = 0,
|
11436 | change = 0,
|
11437 | children = v.children,
|
11438 | i = children.length,
|
11439 | w;
|
11440 | while (--i >= 0) {
|
11441 | w = children[i];
|
11442 | w.z += shift;
|
11443 | w.m += shift;
|
11444 | shift += w.s + (change += w.c);
|
11445 | }
|
11446 | }
|
11447 |
|
11448 | // If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise,
|
11449 | // returns the specified (default) ancestor.
|
11450 | function nextAncestor(vim, v, ancestor) {
|
11451 | return vim.a.parent === v.parent ? vim.a : ancestor;
|
11452 | }
|
11453 |
|
11454 | function TreeNode(node, i) {
|
11455 | this._ = node;
|
11456 | this.parent = null;
|
11457 | this.children = null;
|
11458 | this.A = null; // default ancestor
|
11459 | this.a = this; // ancestor
|
11460 | this.z = 0; // prelim
|
11461 | this.m = 0; // mod
|
11462 | this.c = 0; // change
|
11463 | this.s = 0; // shift
|
11464 | this.t = null; // thread
|
11465 | this.i = i; // number
|
11466 | }
|
11467 |
|
11468 | TreeNode.prototype = Object.create(Node.prototype);
|
11469 |
|
11470 | function treeRoot(root) {
|
11471 | var tree = new TreeNode(root, 0),
|
11472 | node,
|
11473 | nodes = [tree],
|
11474 | child,
|
11475 | children,
|
11476 | i,
|
11477 | n;
|
11478 |
|
11479 | while (node = nodes.pop()) {
|
11480 | if (children = node._.children) {
|
11481 | node.children = new Array(n = children.length);
|
11482 | for (i = n - 1; i >= 0; --i) {
|
11483 | nodes.push(child = node.children[i] = new TreeNode(children[i], i));
|
11484 | child.parent = node;
|
11485 | }
|
11486 | }
|
11487 | }
|
11488 |
|
11489 | (tree.parent = new TreeNode(null, 0)).children = [tree];
|
11490 | return tree;
|
11491 | }
|
11492 |
|
11493 | // Node-link tree diagram using the Reingold-Tilford "tidy" algorithm
|
11494 | function tree() {
|
11495 | var separation = defaultSeparation$1,
|
11496 | dx = 1,
|
11497 | dy = 1,
|
11498 | nodeSize = null;
|
11499 |
|
11500 | function tree(root) {
|
11501 | var t = treeRoot(root);
|
11502 |
|
11503 | // Compute the layout using Buchheim et al.’s algorithm.
|
11504 | t.eachAfter(firstWalk), t.parent.m = -t.z;
|
11505 | t.eachBefore(secondWalk);
|
11506 |
|
11507 | // If a fixed node size is specified, scale x and y.
|
11508 | if (nodeSize) root.eachBefore(sizeNode);
|
11509 |
|
11510 | // If a fixed tree size is specified, scale x and y based on the extent.
|
11511 | // Compute the left-most, right-most, and depth-most nodes for extents.
|
11512 | else {
|
11513 | var left = root,
|
11514 | right = root,
|
11515 | bottom = root;
|
11516 | root.eachBefore(function(node) {
|
11517 | if (node.x < left.x) left = node;
|
11518 | if (node.x > right.x) right = node;
|
11519 | if (node.depth > bottom.depth) bottom = node;
|
11520 | });
|
11521 | var s = left === right ? 1 : separation(left, right) / 2,
|
11522 | tx = s - left.x,
|
11523 | kx = dx / (right.x + s + tx),
|
11524 | ky = dy / (bottom.depth || 1);
|
11525 | root.eachBefore(function(node) {
|
11526 | node.x = (node.x + tx) * kx;
|
11527 | node.y = node.depth * ky;
|
11528 | });
|
11529 | }
|
11530 |
|
11531 | return root;
|
11532 | }
|
11533 |
|
11534 | // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is
|
11535 | // applied recursively to the children of v, as well as the function
|
11536 | // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the
|
11537 | // node v is placed to the midpoint of its outermost children.
|
11538 | function firstWalk(v) {
|
11539 | var children = v.children,
|
11540 | siblings = v.parent.children,
|
11541 | w = v.i ? siblings[v.i - 1] : null;
|
11542 | if (children) {
|
11543 | executeShifts(v);
|
11544 | var midpoint = (children[0].z + children[children.length - 1].z) / 2;
|
11545 | if (w) {
|
11546 | v.z = w.z + separation(v._, w._);
|
11547 | v.m = v.z - midpoint;
|
11548 | } else {
|
11549 | v.z = midpoint;
|
11550 | }
|
11551 | } else if (w) {
|
11552 | v.z = w.z + separation(v._, w._);
|
11553 | }
|
11554 | v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
|
11555 | }
|
11556 |
|
11557 | // Computes all real x-coordinates by summing up the modifiers recursively.
|
11558 | function secondWalk(v) {
|
11559 | v._.x = v.z + v.parent.m;
|
11560 | v.m += v.parent.m;
|
11561 | }
|
11562 |
|
11563 | // The core of the algorithm. Here, a new subtree is combined with the
|
11564 | // previous subtrees. Threads are used to traverse the inside and outside
|
11565 | // contours of the left and right subtree up to the highest common level. The
|
11566 | // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the
|
11567 | // superscript o means outside and i means inside, the subscript - means left
|
11568 | // subtree and + means right subtree. For summing up the modifiers along the
|
11569 | // contour, we use respective variables si+, si-, so-, and so+. Whenever two
|
11570 | // nodes of the inside contours conflict, we compute the left one of the
|
11571 | // greatest uncommon ancestors using the function ANCESTOR and call MOVE
|
11572 | // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees.
|
11573 | // Finally, we add a new thread (if necessary).
|
11574 | function apportion(v, w, ancestor) {
|
11575 | if (w) {
|
11576 | var vip = v,
|
11577 | vop = v,
|
11578 | vim = w,
|
11579 | vom = vip.parent.children[0],
|
11580 | sip = vip.m,
|
11581 | sop = vop.m,
|
11582 | sim = vim.m,
|
11583 | som = vom.m,
|
11584 | shift;
|
11585 | while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) {
|
11586 | vom = nextLeft(vom);
|
11587 | vop = nextRight(vop);
|
11588 | vop.a = v;
|
11589 | shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
|
11590 | if (shift > 0) {
|
11591 | moveSubtree(nextAncestor(vim, v, ancestor), v, shift);
|
11592 | sip += shift;
|
11593 | sop += shift;
|
11594 | }
|
11595 | sim += vim.m;
|
11596 | sip += vip.m;
|
11597 | som += vom.m;
|
11598 | sop += vop.m;
|
11599 | }
|
11600 | if (vim && !nextRight(vop)) {
|
11601 | vop.t = vim;
|
11602 | vop.m += sim - sop;
|
11603 | }
|
11604 | if (vip && !nextLeft(vom)) {
|
11605 | vom.t = vip;
|
11606 | vom.m += sip - som;
|
11607 | ancestor = v;
|
11608 | }
|
11609 | }
|
11610 | return ancestor;
|
11611 | }
|
11612 |
|
11613 | function sizeNode(node) {
|
11614 | node.x *= dx;
|
11615 | node.y = node.depth * dy;
|
11616 | }
|
11617 |
|
11618 | tree.separation = function(x) {
|
11619 | return arguments.length ? (separation = x, tree) : separation;
|
11620 | };
|
11621 |
|
11622 | tree.size = function(x) {
|
11623 | return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]);
|
11624 | };
|
11625 |
|
11626 | tree.nodeSize = function(x) {
|
11627 | return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null);
|
11628 | };
|
11629 |
|
11630 | return tree;
|
11631 | }
|
11632 |
|
11633 | function treemapSlice(parent, x0, y0, x1, y1) {
|
11634 | var nodes = parent.children,
|
11635 | node,
|
11636 | i = -1,
|
11637 | n = nodes.length,
|
11638 | k = parent.value && (y1 - y0) / parent.value;
|
11639 |
|
11640 | while (++i < n) {
|
11641 | node = nodes[i], node.x0 = x0, node.x1 = x1;
|
11642 | node.y0 = y0, node.y1 = y0 += node.value * k;
|
11643 | }
|
11644 | }
|
11645 |
|
11646 | var phi = (1 + Math.sqrt(5)) / 2;
|
11647 |
|
11648 | function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
|
11649 | var rows = [],
|
11650 | nodes = parent.children,
|
11651 | row,
|
11652 | nodeValue,
|
11653 | i0 = 0,
|
11654 | i1 = 0,
|
11655 | n = nodes.length,
|
11656 | dx, dy,
|
11657 | value = parent.value,
|
11658 | sumValue,
|
11659 | minValue,
|
11660 | maxValue,
|
11661 | newRatio,
|
11662 | minRatio,
|
11663 | alpha,
|
11664 | beta;
|
11665 |
|
11666 | while (i0 < n) {
|
11667 | dx = x1 - x0, dy = y1 - y0;
|
11668 |
|
11669 | // Find the next non-empty node.
|
11670 | do sumValue = nodes[i1++].value; while (!sumValue && i1 < n);
|
11671 | minValue = maxValue = sumValue;
|
11672 | alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
|
11673 | beta = sumValue * sumValue * alpha;
|
11674 | minRatio = Math.max(maxValue / beta, beta / minValue);
|
11675 |
|
11676 | // Keep adding nodes while the aspect ratio maintains or improves.
|
11677 | for (; i1 < n; ++i1) {
|
11678 | sumValue += nodeValue = nodes[i1].value;
|
11679 | if (nodeValue < minValue) minValue = nodeValue;
|
11680 | if (nodeValue > maxValue) maxValue = nodeValue;
|
11681 | beta = sumValue * sumValue * alpha;
|
11682 | newRatio = Math.max(maxValue / beta, beta / minValue);
|
11683 | if (newRatio > minRatio) { sumValue -= nodeValue; break; }
|
11684 | minRatio = newRatio;
|
11685 | }
|
11686 |
|
11687 | // Position and record the row orientation.
|
11688 | rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)});
|
11689 | if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);
|
11690 | else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
|
11691 | value -= sumValue, i0 = i1;
|
11692 | }
|
11693 |
|
11694 | return rows;
|
11695 | }
|
11696 |
|
11697 | var squarify = (function custom(ratio) {
|
11698 |
|
11699 | function squarify(parent, x0, y0, x1, y1) {
|
11700 | squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
11701 | }
|
11702 |
|
11703 | squarify.ratio = function(x) {
|
11704 | return custom((x = +x) > 1 ? x : 1);
|
11705 | };
|
11706 |
|
11707 | return squarify;
|
11708 | })(phi);
|
11709 |
|
11710 | function index$3() {
|
11711 | var tile = squarify,
|
11712 | round = false,
|
11713 | dx = 1,
|
11714 | dy = 1,
|
11715 | paddingStack = [0],
|
11716 | paddingInner = constantZero,
|
11717 | paddingTop = constantZero,
|
11718 | paddingRight = constantZero,
|
11719 | paddingBottom = constantZero,
|
11720 | paddingLeft = constantZero;
|
11721 |
|
11722 | function treemap(root) {
|
11723 | root.x0 =
|
11724 | root.y0 = 0;
|
11725 | root.x1 = dx;
|
11726 | root.y1 = dy;
|
11727 | root.eachBefore(positionNode);
|
11728 | paddingStack = [0];
|
11729 | if (round) root.eachBefore(roundNode);
|
11730 | return root;
|
11731 | }
|
11732 |
|
11733 | function positionNode(node) {
|
11734 | var p = paddingStack[node.depth],
|
11735 | x0 = node.x0 + p,
|
11736 | y0 = node.y0 + p,
|
11737 | x1 = node.x1 - p,
|
11738 | y1 = node.y1 - p;
|
11739 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
11740 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
11741 | node.x0 = x0;
|
11742 | node.y0 = y0;
|
11743 | node.x1 = x1;
|
11744 | node.y1 = y1;
|
11745 | if (node.children) {
|
11746 | p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
|
11747 | x0 += paddingLeft(node) - p;
|
11748 | y0 += paddingTop(node) - p;
|
11749 | x1 -= paddingRight(node) - p;
|
11750 | y1 -= paddingBottom(node) - p;
|
11751 | if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
|
11752 | if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
|
11753 | tile(node, x0, y0, x1, y1);
|
11754 | }
|
11755 | }
|
11756 |
|
11757 | treemap.round = function(x) {
|
11758 | return arguments.length ? (round = !!x, treemap) : round;
|
11759 | };
|
11760 |
|
11761 | treemap.size = function(x) {
|
11762 | return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
|
11763 | };
|
11764 |
|
11765 | treemap.tile = function(x) {
|
11766 | return arguments.length ? (tile = required(x), treemap) : tile;
|
11767 | };
|
11768 |
|
11769 | treemap.padding = function(x) {
|
11770 | return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
|
11771 | };
|
11772 |
|
11773 | treemap.paddingInner = function(x) {
|
11774 | return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$9(+x), treemap) : paddingInner;
|
11775 | };
|
11776 |
|
11777 | treemap.paddingOuter = function(x) {
|
11778 | return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
|
11779 | };
|
11780 |
|
11781 | treemap.paddingTop = function(x) {
|
11782 | return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$9(+x), treemap) : paddingTop;
|
11783 | };
|
11784 |
|
11785 | treemap.paddingRight = function(x) {
|
11786 | return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$9(+x), treemap) : paddingRight;
|
11787 | };
|
11788 |
|
11789 | treemap.paddingBottom = function(x) {
|
11790 | return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$9(+x), treemap) : paddingBottom;
|
11791 | };
|
11792 |
|
11793 | treemap.paddingLeft = function(x) {
|
11794 | return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$9(+x), treemap) : paddingLeft;
|
11795 | };
|
11796 |
|
11797 | return treemap;
|
11798 | }
|
11799 |
|
11800 | function binary(parent, x0, y0, x1, y1) {
|
11801 | var nodes = parent.children,
|
11802 | i, n = nodes.length,
|
11803 | sum, sums = new Array(n + 1);
|
11804 |
|
11805 | for (sums[0] = sum = i = 0; i < n; ++i) {
|
11806 | sums[i + 1] = sum += nodes[i].value;
|
11807 | }
|
11808 |
|
11809 | partition(0, n, parent.value, x0, y0, x1, y1);
|
11810 |
|
11811 | function partition(i, j, value, x0, y0, x1, y1) {
|
11812 | if (i >= j - 1) {
|
11813 | var node = nodes[i];
|
11814 | node.x0 = x0, node.y0 = y0;
|
11815 | node.x1 = x1, node.y1 = y1;
|
11816 | return;
|
11817 | }
|
11818 |
|
11819 | var valueOffset = sums[i],
|
11820 | valueTarget = (value / 2) + valueOffset,
|
11821 | k = i + 1,
|
11822 | hi = j - 1;
|
11823 |
|
11824 | while (k < hi) {
|
11825 | var mid = k + hi >>> 1;
|
11826 | if (sums[mid] < valueTarget) k = mid + 1;
|
11827 | else hi = mid;
|
11828 | }
|
11829 |
|
11830 | if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k;
|
11831 |
|
11832 | var valueLeft = sums[k] - valueOffset,
|
11833 | valueRight = value - valueLeft;
|
11834 |
|
11835 | if ((x1 - x0) > (y1 - y0)) {
|
11836 | var xk = (x0 * valueRight + x1 * valueLeft) / value;
|
11837 | partition(i, k, valueLeft, x0, y0, xk, y1);
|
11838 | partition(k, j, valueRight, xk, y0, x1, y1);
|
11839 | } else {
|
11840 | var yk = (y0 * valueRight + y1 * valueLeft) / value;
|
11841 | partition(i, k, valueLeft, x0, y0, x1, yk);
|
11842 | partition(k, j, valueRight, x0, yk, x1, y1);
|
11843 | }
|
11844 | }
|
11845 | }
|
11846 |
|
11847 | function sliceDice(parent, x0, y0, x1, y1) {
|
11848 | (parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1);
|
11849 | }
|
11850 |
|
11851 | var resquarify = (function custom(ratio) {
|
11852 |
|
11853 | function resquarify(parent, x0, y0, x1, y1) {
|
11854 | if ((rows = parent._squarify) && (rows.ratio === ratio)) {
|
11855 | var rows,
|
11856 | row,
|
11857 | nodes,
|
11858 | i,
|
11859 | j = -1,
|
11860 | n,
|
11861 | m = rows.length,
|
11862 | value = parent.value;
|
11863 |
|
11864 | while (++j < m) {
|
11865 | row = rows[j], nodes = row.children;
|
11866 | for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value;
|
11867 | if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
|
11868 | else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);
|
11869 | value -= row.value;
|
11870 | }
|
11871 | } else {
|
11872 | parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1);
|
11873 | rows.ratio = ratio;
|
11874 | }
|
11875 | }
|
11876 |
|
11877 | resquarify.ratio = function(x) {
|
11878 | return custom((x = +x) > 1 ? x : 1);
|
11879 | };
|
11880 |
|
11881 | return resquarify;
|
11882 | })(phi);
|
11883 |
|
11884 | function area$2(polygon) {
|
11885 | var i = -1,
|
11886 | n = polygon.length,
|
11887 | a,
|
11888 | b = polygon[n - 1],
|
11889 | area = 0;
|
11890 |
|
11891 | while (++i < n) {
|
11892 | a = b;
|
11893 | b = polygon[i];
|
11894 | area += a[1] * b[0] - a[0] * b[1];
|
11895 | }
|
11896 |
|
11897 | return area / 2;
|
11898 | }
|
11899 |
|
11900 | function centroid$1(polygon) {
|
11901 | var i = -1,
|
11902 | n = polygon.length,
|
11903 | x = 0,
|
11904 | y = 0,
|
11905 | a,
|
11906 | b = polygon[n - 1],
|
11907 | c,
|
11908 | k = 0;
|
11909 |
|
11910 | while (++i < n) {
|
11911 | a = b;
|
11912 | b = polygon[i];
|
11913 | k += c = a[0] * b[1] - b[0] * a[1];
|
11914 | x += (a[0] + b[0]) * c;
|
11915 | y += (a[1] + b[1]) * c;
|
11916 | }
|
11917 |
|
11918 | return k *= 3, [x / k, y / k];
|
11919 | }
|
11920 |
|
11921 | // Returns the 2D cross product of AB and AC vectors, i.e., the z-component of
|
11922 | // the 3D cross product in a quadrant I Cartesian coordinate system (+x is
|
11923 | // right, +y is up). Returns a positive value if ABC is counter-clockwise,
|
11924 | // negative if clockwise, and zero if the points are collinear.
|
11925 | function cross$1(a, b, c) {
|
11926 | return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
11927 | }
|
11928 |
|
11929 | function lexicographicOrder(a, b) {
|
11930 | return a[0] - b[0] || a[1] - b[1];
|
11931 | }
|
11932 |
|
11933 | // Computes the upper convex hull per the monotone chain algorithm.
|
11934 | // Assumes points.length >= 3, is sorted by x, unique in y.
|
11935 | // Returns an array of indices into points in left-to-right order.
|
11936 | function computeUpperHullIndexes(points) {
|
11937 | var n = points.length,
|
11938 | indexes = [0, 1],
|
11939 | size = 2;
|
11940 |
|
11941 | for (var i = 2; i < n; ++i) {
|
11942 | while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size;
|
11943 | indexes[size++] = i;
|
11944 | }
|
11945 |
|
11946 | return indexes.slice(0, size); // remove popped points
|
11947 | }
|
11948 |
|
11949 | function hull(points) {
|
11950 | if ((n = points.length) < 3) return null;
|
11951 |
|
11952 | var i,
|
11953 | n,
|
11954 | sortedPoints = new Array(n),
|
11955 | flippedPoints = new Array(n);
|
11956 |
|
11957 | for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
|
11958 | sortedPoints.sort(lexicographicOrder);
|
11959 | for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
|
11960 |
|
11961 | var upperIndexes = computeUpperHullIndexes(sortedPoints),
|
11962 | lowerIndexes = computeUpperHullIndexes(flippedPoints);
|
11963 |
|
11964 | // Construct the hull polygon, removing possible duplicate endpoints.
|
11965 | var skipLeft = lowerIndexes[0] === upperIndexes[0],
|
11966 | skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
|
11967 | hull = [];
|
11968 |
|
11969 | // Add upper hull in right-to-l order.
|
11970 | // Then add lower hull in left-to-right order.
|
11971 | for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
|
11972 | for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
|
11973 |
|
11974 | return hull;
|
11975 | }
|
11976 |
|
11977 | function contains$2(polygon, point) {
|
11978 | var n = polygon.length,
|
11979 | p = polygon[n - 1],
|
11980 | x = point[0], y = point[1],
|
11981 | x0 = p[0], y0 = p[1],
|
11982 | x1, y1,
|
11983 | inside = false;
|
11984 |
|
11985 | for (var i = 0; i < n; ++i) {
|
11986 | p = polygon[i], x1 = p[0], y1 = p[1];
|
11987 | if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;
|
11988 | x0 = x1, y0 = y1;
|
11989 | }
|
11990 |
|
11991 | return inside;
|
11992 | }
|
11993 |
|
11994 | function length$2(polygon) {
|
11995 | var i = -1,
|
11996 | n = polygon.length,
|
11997 | b = polygon[n - 1],
|
11998 | xa,
|
11999 | ya,
|
12000 | xb = b[0],
|
12001 | yb = b[1],
|
12002 | perimeter = 0;
|
12003 |
|
12004 | while (++i < n) {
|
12005 | xa = xb;
|
12006 | ya = yb;
|
12007 | b = polygon[i];
|
12008 | xb = b[0];
|
12009 | yb = b[1];
|
12010 | xa -= xb;
|
12011 | ya -= yb;
|
12012 | perimeter += Math.sqrt(xa * xa + ya * ya);
|
12013 | }
|
12014 |
|
12015 | return perimeter;
|
12016 | }
|
12017 |
|
12018 | function defaultSource$1() {
|
12019 | return Math.random();
|
12020 | }
|
12021 |
|
12022 | var uniform = (function sourceRandomUniform(source) {
|
12023 | function randomUniform(min, max) {
|
12024 | min = min == null ? 0 : +min;
|
12025 | max = max == null ? 1 : +max;
|
12026 | if (arguments.length === 1) max = min, min = 0;
|
12027 | else max -= min;
|
12028 | return function() {
|
12029 | return source() * max + min;
|
12030 | };
|
12031 | }
|
12032 |
|
12033 | randomUniform.source = sourceRandomUniform;
|
12034 |
|
12035 | return randomUniform;
|
12036 | })(defaultSource$1);
|
12037 |
|
12038 | var normal = (function sourceRandomNormal(source) {
|
12039 | function randomNormal(mu, sigma) {
|
12040 | var x, r;
|
12041 | mu = mu == null ? 0 : +mu;
|
12042 | sigma = sigma == null ? 1 : +sigma;
|
12043 | return function() {
|
12044 | var y;
|
12045 |
|
12046 | // If available, use the second previously-generated uniform random.
|
12047 | if (x != null) y = x, x = null;
|
12048 |
|
12049 | // Otherwise, generate a new x and y.
|
12050 | else do {
|
12051 | x = source() * 2 - 1;
|
12052 | y = source() * 2 - 1;
|
12053 | r = x * x + y * y;
|
12054 | } while (!r || r > 1);
|
12055 |
|
12056 | return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
|
12057 | };
|
12058 | }
|
12059 |
|
12060 | randomNormal.source = sourceRandomNormal;
|
12061 |
|
12062 | return randomNormal;
|
12063 | })(defaultSource$1);
|
12064 |
|
12065 | var logNormal = (function sourceRandomLogNormal(source) {
|
12066 | function randomLogNormal() {
|
12067 | var randomNormal = normal.source(source).apply(this, arguments);
|
12068 | return function() {
|
12069 | return Math.exp(randomNormal());
|
12070 | };
|
12071 | }
|
12072 |
|
12073 | randomLogNormal.source = sourceRandomLogNormal;
|
12074 |
|
12075 | return randomLogNormal;
|
12076 | })(defaultSource$1);
|
12077 |
|
12078 | var irwinHall = (function sourceRandomIrwinHall(source) {
|
12079 | function randomIrwinHall(n) {
|
12080 | return function() {
|
12081 | for (var sum = 0, i = 0; i < n; ++i) sum += source();
|
12082 | return sum;
|
12083 | };
|
12084 | }
|
12085 |
|
12086 | randomIrwinHall.source = sourceRandomIrwinHall;
|
12087 |
|
12088 | return randomIrwinHall;
|
12089 | })(defaultSource$1);
|
12090 |
|
12091 | var bates = (function sourceRandomBates(source) {
|
12092 | function randomBates(n) {
|
12093 | var randomIrwinHall = irwinHall.source(source)(n);
|
12094 | return function() {
|
12095 | return randomIrwinHall() / n;
|
12096 | };
|
12097 | }
|
12098 |
|
12099 | randomBates.source = sourceRandomBates;
|
12100 |
|
12101 | return randomBates;
|
12102 | })(defaultSource$1);
|
12103 |
|
12104 | var exponential$1 = (function sourceRandomExponential(source) {
|
12105 | function randomExponential(lambda) {
|
12106 | return function() {
|
12107 | return -Math.log(1 - source()) / lambda;
|
12108 | };
|
12109 | }
|
12110 |
|
12111 | randomExponential.source = sourceRandomExponential;
|
12112 |
|
12113 | return randomExponential;
|
12114 | })(defaultSource$1);
|
12115 |
|
12116 | function initRange(domain, range) {
|
12117 | switch (arguments.length) {
|
12118 | case 0: break;
|
12119 | case 1: this.range(domain); break;
|
12120 | default: this.range(range).domain(domain); break;
|
12121 | }
|
12122 | return this;
|
12123 | }
|
12124 |
|
12125 | function initInterpolator(domain, interpolator) {
|
12126 | switch (arguments.length) {
|
12127 | case 0: break;
|
12128 | case 1: this.interpolator(domain); break;
|
12129 | default: this.interpolator(interpolator).domain(domain); break;
|
12130 | }
|
12131 | return this;
|
12132 | }
|
12133 |
|
12134 | var array$3 = Array.prototype;
|
12135 |
|
12136 | var map$3 = array$3.map;
|
12137 | var slice$5 = array$3.slice;
|
12138 |
|
12139 | var implicit = {name: "implicit"};
|
12140 |
|
12141 | function ordinal() {
|
12142 | var index = map$1(),
|
12143 | domain = [],
|
12144 | range = [],
|
12145 | unknown = implicit;
|
12146 |
|
12147 | function scale(d) {
|
12148 | var key = d + "", i = index.get(key);
|
12149 | if (!i) {
|
12150 | if (unknown !== implicit) return unknown;
|
12151 | index.set(key, i = domain.push(d));
|
12152 | }
|
12153 | return range[(i - 1) % range.length];
|
12154 | }
|
12155 |
|
12156 | scale.domain = function(_) {
|
12157 | if (!arguments.length) return domain.slice();
|
12158 | domain = [], index = map$1();
|
12159 | var i = -1, n = _.length, d, key;
|
12160 | while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
|
12161 | return scale;
|
12162 | };
|
12163 |
|
12164 | scale.range = function(_) {
|
12165 | return arguments.length ? (range = slice$5.call(_), scale) : range.slice();
|
12166 | };
|
12167 |
|
12168 | scale.unknown = function(_) {
|
12169 | return arguments.length ? (unknown = _, scale) : unknown;
|
12170 | };
|
12171 |
|
12172 | scale.copy = function() {
|
12173 | return ordinal(domain, range).unknown(unknown);
|
12174 | };
|
12175 |
|
12176 | initRange.apply(scale, arguments);
|
12177 |
|
12178 | return scale;
|
12179 | }
|
12180 |
|
12181 | function band() {
|
12182 | var scale = ordinal().unknown(undefined),
|
12183 | domain = scale.domain,
|
12184 | ordinalRange = scale.range,
|
12185 | range = [0, 1],
|
12186 | step,
|
12187 | bandwidth,
|
12188 | round = false,
|
12189 | paddingInner = 0,
|
12190 | paddingOuter = 0,
|
12191 | align = 0.5;
|
12192 |
|
12193 | delete scale.unknown;
|
12194 |
|
12195 | function rescale() {
|
12196 | var n = domain().length,
|
12197 | reverse = range[1] < range[0],
|
12198 | start = range[reverse - 0],
|
12199 | stop = range[1 - reverse];
|
12200 | step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
|
12201 | if (round) step = Math.floor(step);
|
12202 | start += (stop - start - step * (n - paddingInner)) * align;
|
12203 | bandwidth = step * (1 - paddingInner);
|
12204 | if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
|
12205 | var values = sequence(n).map(function(i) { return start + step * i; });
|
12206 | return ordinalRange(reverse ? values.reverse() : values);
|
12207 | }
|
12208 |
|
12209 | scale.domain = function(_) {
|
12210 | return arguments.length ? (domain(_), rescale()) : domain();
|
12211 | };
|
12212 |
|
12213 | scale.range = function(_) {
|
12214 | return arguments.length ? (range = [+_[0], +_[1]], rescale()) : range.slice();
|
12215 | };
|
12216 |
|
12217 | scale.rangeRound = function(_) {
|
12218 | return range = [+_[0], +_[1]], round = true, rescale();
|
12219 | };
|
12220 |
|
12221 | scale.bandwidth = function() {
|
12222 | return bandwidth;
|
12223 | };
|
12224 |
|
12225 | scale.step = function() {
|
12226 | return step;
|
12227 | };
|
12228 |
|
12229 | scale.round = function(_) {
|
12230 | return arguments.length ? (round = !!_, rescale()) : round;
|
12231 | };
|
12232 |
|
12233 | scale.padding = function(_) {
|
12234 | return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
|
12235 | };
|
12236 |
|
12237 | scale.paddingInner = function(_) {
|
12238 | return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
|
12239 | };
|
12240 |
|
12241 | scale.paddingOuter = function(_) {
|
12242 | return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
|
12243 | };
|
12244 |
|
12245 | scale.align = function(_) {
|
12246 | return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
|
12247 | };
|
12248 |
|
12249 | scale.copy = function() {
|
12250 | return band(domain(), range)
|
12251 | .round(round)
|
12252 | .paddingInner(paddingInner)
|
12253 | .paddingOuter(paddingOuter)
|
12254 | .align(align);
|
12255 | };
|
12256 |
|
12257 | return initRange.apply(rescale(), arguments);
|
12258 | }
|
12259 |
|
12260 | function pointish(scale) {
|
12261 | var copy = scale.copy;
|
12262 |
|
12263 | scale.padding = scale.paddingOuter;
|
12264 | delete scale.paddingInner;
|
12265 | delete scale.paddingOuter;
|
12266 |
|
12267 | scale.copy = function() {
|
12268 | return pointish(copy());
|
12269 | };
|
12270 |
|
12271 | return scale;
|
12272 | }
|
12273 |
|
12274 | function point$1() {
|
12275 | return pointish(band.apply(null, arguments).paddingInner(1));
|
12276 | }
|
12277 |
|
12278 | function constant$a(x) {
|
12279 | return function() {
|
12280 | return x;
|
12281 | };
|
12282 | }
|
12283 |
|
12284 | function number$2(x) {
|
12285 | return +x;
|
12286 | }
|
12287 |
|
12288 | var unit = [0, 1];
|
12289 |
|
12290 | function identity$6(x) {
|
12291 | return x;
|
12292 | }
|
12293 |
|
12294 | function normalize(a, b) {
|
12295 | return (b -= (a = +a))
|
12296 | ? function(x) { return (x - a) / b; }
|
12297 | : constant$a(isNaN(b) ? NaN : 0.5);
|
12298 | }
|
12299 |
|
12300 | function clamper(domain) {
|
12301 | var a = domain[0], b = domain[domain.length - 1], t;
|
12302 | if (a > b) t = a, a = b, b = t;
|
12303 | return function(x) { return Math.max(a, Math.min(b, x)); };
|
12304 | }
|
12305 |
|
12306 | // normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
|
12307 | // interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
|
12308 | function bimap(domain, range, interpolate) {
|
12309 | var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
|
12310 | if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
|
12311 | else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
|
12312 | return function(x) { return r0(d0(x)); };
|
12313 | }
|
12314 |
|
12315 | function polymap(domain, range, interpolate) {
|
12316 | var j = Math.min(domain.length, range.length) - 1,
|
12317 | d = new Array(j),
|
12318 | r = new Array(j),
|
12319 | i = -1;
|
12320 |
|
12321 | // Reverse descending domains.
|
12322 | if (domain[j] < domain[0]) {
|
12323 | domain = domain.slice().reverse();
|
12324 | range = range.slice().reverse();
|
12325 | }
|
12326 |
|
12327 | while (++i < j) {
|
12328 | d[i] = normalize(domain[i], domain[i + 1]);
|
12329 | r[i] = interpolate(range[i], range[i + 1]);
|
12330 | }
|
12331 |
|
12332 | return function(x) {
|
12333 | var i = bisectRight(domain, x, 1, j) - 1;
|
12334 | return r[i](d[i](x));
|
12335 | };
|
12336 | }
|
12337 |
|
12338 | function copy(source, target) {
|
12339 | return target
|
12340 | .domain(source.domain())
|
12341 | .range(source.range())
|
12342 | .interpolate(source.interpolate())
|
12343 | .clamp(source.clamp())
|
12344 | .unknown(source.unknown());
|
12345 | }
|
12346 |
|
12347 | function transformer$1() {
|
12348 | var domain = unit,
|
12349 | range = unit,
|
12350 | interpolate = interpolateValue,
|
12351 | transform,
|
12352 | untransform,
|
12353 | unknown,
|
12354 | clamp = identity$6,
|
12355 | piecewise,
|
12356 | output,
|
12357 | input;
|
12358 |
|
12359 | function rescale() {
|
12360 | piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
|
12361 | output = input = null;
|
12362 | return scale;
|
12363 | }
|
12364 |
|
12365 | function scale(x) {
|
12366 | return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
|
12367 | }
|
12368 |
|
12369 | scale.invert = function(y) {
|
12370 | return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
|
12371 | };
|
12372 |
|
12373 | scale.domain = function(_) {
|
12374 | return arguments.length ? (domain = map$3.call(_, number$2), clamp === identity$6 || (clamp = clamper(domain)), rescale()) : domain.slice();
|
12375 | };
|
12376 |
|
12377 | scale.range = function(_) {
|
12378 | return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
|
12379 | };
|
12380 |
|
12381 | scale.rangeRound = function(_) {
|
12382 | return range = slice$5.call(_), interpolate = interpolateRound, rescale();
|
12383 | };
|
12384 |
|
12385 | scale.clamp = function(_) {
|
12386 | return arguments.length ? (clamp = _ ? clamper(domain) : identity$6, scale) : clamp !== identity$6;
|
12387 | };
|
12388 |
|
12389 | scale.interpolate = function(_) {
|
12390 | return arguments.length ? (interpolate = _, rescale()) : interpolate;
|
12391 | };
|
12392 |
|
12393 | scale.unknown = function(_) {
|
12394 | return arguments.length ? (unknown = _, scale) : unknown;
|
12395 | };
|
12396 |
|
12397 | return function(t, u) {
|
12398 | transform = t, untransform = u;
|
12399 | return rescale();
|
12400 | };
|
12401 | }
|
12402 |
|
12403 | function continuous(transform, untransform) {
|
12404 | return transformer$1()(transform, untransform);
|
12405 | }
|
12406 |
|
12407 | function tickFormat(start, stop, count, specifier) {
|
12408 | var step = tickStep(start, stop, count),
|
12409 | precision;
|
12410 | specifier = formatSpecifier(specifier == null ? ",f" : specifier);
|
12411 | switch (specifier.type) {
|
12412 | case "s": {
|
12413 | var value = Math.max(Math.abs(start), Math.abs(stop));
|
12414 | if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
|
12415 | return exports.formatPrefix(specifier, value);
|
12416 | }
|
12417 | case "":
|
12418 | case "e":
|
12419 | case "g":
|
12420 | case "p":
|
12421 | case "r": {
|
12422 | if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
|
12423 | break;
|
12424 | }
|
12425 | case "f":
|
12426 | case "%": {
|
12427 | if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
|
12428 | break;
|
12429 | }
|
12430 | }
|
12431 | return exports.format(specifier);
|
12432 | }
|
12433 |
|
12434 | function linearish(scale) {
|
12435 | var domain = scale.domain;
|
12436 |
|
12437 | scale.ticks = function(count) {
|
12438 | var d = domain();
|
12439 | return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
|
12440 | };
|
12441 |
|
12442 | scale.tickFormat = function(count, specifier) {
|
12443 | var d = domain();
|
12444 | return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
|
12445 | };
|
12446 |
|
12447 | scale.nice = function(count) {
|
12448 | if (count == null) count = 10;
|
12449 |
|
12450 | var d = domain(),
|
12451 | i0 = 0,
|
12452 | i1 = d.length - 1,
|
12453 | start = d[i0],
|
12454 | stop = d[i1],
|
12455 | step;
|
12456 |
|
12457 | if (stop < start) {
|
12458 | step = start, start = stop, stop = step;
|
12459 | step = i0, i0 = i1, i1 = step;
|
12460 | }
|
12461 |
|
12462 | step = tickIncrement(start, stop, count);
|
12463 |
|
12464 | if (step > 0) {
|
12465 | start = Math.floor(start / step) * step;
|
12466 | stop = Math.ceil(stop / step) * step;
|
12467 | step = tickIncrement(start, stop, count);
|
12468 | } else if (step < 0) {
|
12469 | start = Math.ceil(start * step) / step;
|
12470 | stop = Math.floor(stop * step) / step;
|
12471 | step = tickIncrement(start, stop, count);
|
12472 | }
|
12473 |
|
12474 | if (step > 0) {
|
12475 | d[i0] = Math.floor(start / step) * step;
|
12476 | d[i1] = Math.ceil(stop / step) * step;
|
12477 | domain(d);
|
12478 | } else if (step < 0) {
|
12479 | d[i0] = Math.ceil(start * step) / step;
|
12480 | d[i1] = Math.floor(stop * step) / step;
|
12481 | domain(d);
|
12482 | }
|
12483 |
|
12484 | return scale;
|
12485 | };
|
12486 |
|
12487 | return scale;
|
12488 | }
|
12489 |
|
12490 | function linear$2() {
|
12491 | var scale = continuous(identity$6, identity$6);
|
12492 |
|
12493 | scale.copy = function() {
|
12494 | return copy(scale, linear$2());
|
12495 | };
|
12496 |
|
12497 | initRange.apply(scale, arguments);
|
12498 |
|
12499 | return linearish(scale);
|
12500 | }
|
12501 |
|
12502 | function identity$7(domain) {
|
12503 | var unknown;
|
12504 |
|
12505 | function scale(x) {
|
12506 | return isNaN(x = +x) ? unknown : x;
|
12507 | }
|
12508 |
|
12509 | scale.invert = scale;
|
12510 |
|
12511 | scale.domain = scale.range = function(_) {
|
12512 | return arguments.length ? (domain = map$3.call(_, number$2), scale) : domain.slice();
|
12513 | };
|
12514 |
|
12515 | scale.unknown = function(_) {
|
12516 | return arguments.length ? (unknown = _, scale) : unknown;
|
12517 | };
|
12518 |
|
12519 | scale.copy = function() {
|
12520 | return identity$7(domain).unknown(unknown);
|
12521 | };
|
12522 |
|
12523 | domain = arguments.length ? map$3.call(domain, number$2) : [0, 1];
|
12524 |
|
12525 | return linearish(scale);
|
12526 | }
|
12527 |
|
12528 | function nice(domain, interval) {
|
12529 | domain = domain.slice();
|
12530 |
|
12531 | var i0 = 0,
|
12532 | i1 = domain.length - 1,
|
12533 | x0 = domain[i0],
|
12534 | x1 = domain[i1],
|
12535 | t;
|
12536 |
|
12537 | if (x1 < x0) {
|
12538 | t = i0, i0 = i1, i1 = t;
|
12539 | t = x0, x0 = x1, x1 = t;
|
12540 | }
|
12541 |
|
12542 | domain[i0] = interval.floor(x0);
|
12543 | domain[i1] = interval.ceil(x1);
|
12544 | return domain;
|
12545 | }
|
12546 |
|
12547 | function transformLog(x) {
|
12548 | return Math.log(x);
|
12549 | }
|
12550 |
|
12551 | function transformExp(x) {
|
12552 | return Math.exp(x);
|
12553 | }
|
12554 |
|
12555 | function transformLogn(x) {
|
12556 | return -Math.log(-x);
|
12557 | }
|
12558 |
|
12559 | function transformExpn(x) {
|
12560 | return -Math.exp(-x);
|
12561 | }
|
12562 |
|
12563 | function pow10(x) {
|
12564 | return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
|
12565 | }
|
12566 |
|
12567 | function powp(base) {
|
12568 | return base === 10 ? pow10
|
12569 | : base === Math.E ? Math.exp
|
12570 | : function(x) { return Math.pow(base, x); };
|
12571 | }
|
12572 |
|
12573 | function logp(base) {
|
12574 | return base === Math.E ? Math.log
|
12575 | : base === 10 && Math.log10
|
12576 | || base === 2 && Math.log2
|
12577 | || (base = Math.log(base), function(x) { return Math.log(x) / base; });
|
12578 | }
|
12579 |
|
12580 | function reflect(f) {
|
12581 | return function(x) {
|
12582 | return -f(-x);
|
12583 | };
|
12584 | }
|
12585 |
|
12586 | function loggish(transform) {
|
12587 | var scale = transform(transformLog, transformExp),
|
12588 | domain = scale.domain,
|
12589 | base = 10,
|
12590 | logs,
|
12591 | pows;
|
12592 |
|
12593 | function rescale() {
|
12594 | logs = logp(base), pows = powp(base);
|
12595 | if (domain()[0] < 0) {
|
12596 | logs = reflect(logs), pows = reflect(pows);
|
12597 | transform(transformLogn, transformExpn);
|
12598 | } else {
|
12599 | transform(transformLog, transformExp);
|
12600 | }
|
12601 | return scale;
|
12602 | }
|
12603 |
|
12604 | scale.base = function(_) {
|
12605 | return arguments.length ? (base = +_, rescale()) : base;
|
12606 | };
|
12607 |
|
12608 | scale.domain = function(_) {
|
12609 | return arguments.length ? (domain(_), rescale()) : domain();
|
12610 | };
|
12611 |
|
12612 | scale.ticks = function(count) {
|
12613 | var d = domain(),
|
12614 | u = d[0],
|
12615 | v = d[d.length - 1],
|
12616 | r;
|
12617 |
|
12618 | if (r = v < u) i = u, u = v, v = i;
|
12619 |
|
12620 | var i = logs(u),
|
12621 | j = logs(v),
|
12622 | p,
|
12623 | k,
|
12624 | t,
|
12625 | n = count == null ? 10 : +count,
|
12626 | z = [];
|
12627 |
|
12628 | if (!(base % 1) && j - i < n) {
|
12629 | i = Math.round(i) - 1, j = Math.round(j) + 1;
|
12630 | if (u > 0) for (; i < j; ++i) {
|
12631 | for (k = 1, p = pows(i); k < base; ++k) {
|
12632 | t = p * k;
|
12633 | if (t < u) continue;
|
12634 | if (t > v) break;
|
12635 | z.push(t);
|
12636 | }
|
12637 | } else for (; i < j; ++i) {
|
12638 | for (k = base - 1, p = pows(i); k >= 1; --k) {
|
12639 | t = p * k;
|
12640 | if (t < u) continue;
|
12641 | if (t > v) break;
|
12642 | z.push(t);
|
12643 | }
|
12644 | }
|
12645 | } else {
|
12646 | z = ticks(i, j, Math.min(j - i, n)).map(pows);
|
12647 | }
|
12648 |
|
12649 | return r ? z.reverse() : z;
|
12650 | };
|
12651 |
|
12652 | scale.tickFormat = function(count, specifier) {
|
12653 | if (specifier == null) specifier = base === 10 ? ".0e" : ",";
|
12654 | if (typeof specifier !== "function") specifier = exports.format(specifier);
|
12655 | if (count === Infinity) return specifier;
|
12656 | if (count == null) count = 10;
|
12657 | var k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate?
|
12658 | return function(d) {
|
12659 | var i = d / pows(Math.round(logs(d)));
|
12660 | if (i * base < base - 0.5) i *= base;
|
12661 | return i <= k ? specifier(d) : "";
|
12662 | };
|
12663 | };
|
12664 |
|
12665 | scale.nice = function() {
|
12666 | return domain(nice(domain(), {
|
12667 | floor: function(x) { return pows(Math.floor(logs(x))); },
|
12668 | ceil: function(x) { return pows(Math.ceil(logs(x))); }
|
12669 | }));
|
12670 | };
|
12671 |
|
12672 | return scale;
|
12673 | }
|
12674 |
|
12675 | function log$1() {
|
12676 | var scale = loggish(transformer$1()).domain([1, 10]);
|
12677 |
|
12678 | scale.copy = function() {
|
12679 | return copy(scale, log$1()).base(scale.base());
|
12680 | };
|
12681 |
|
12682 | initRange.apply(scale, arguments);
|
12683 |
|
12684 | return scale;
|
12685 | }
|
12686 |
|
12687 | function transformSymlog(c) {
|
12688 | return function(x) {
|
12689 | return Math.sign(x) * Math.log1p(Math.abs(x / c));
|
12690 | };
|
12691 | }
|
12692 |
|
12693 | function transformSymexp(c) {
|
12694 | return function(x) {
|
12695 | return Math.sign(x) * Math.expm1(Math.abs(x)) * c;
|
12696 | };
|
12697 | }
|
12698 |
|
12699 | function symlogish(transform) {
|
12700 | var c = 1, scale = transform(transformSymlog(c), transformSymexp(c));
|
12701 |
|
12702 | scale.constant = function(_) {
|
12703 | return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c;
|
12704 | };
|
12705 |
|
12706 | return linearish(scale);
|
12707 | }
|
12708 |
|
12709 | function symlog() {
|
12710 | var scale = symlogish(transformer$1());
|
12711 |
|
12712 | scale.copy = function() {
|
12713 | return copy(scale, symlog()).constant(scale.constant());
|
12714 | };
|
12715 |
|
12716 | return initRange.apply(scale, arguments);
|
12717 | }
|
12718 |
|
12719 | function transformPow(exponent) {
|
12720 | return function(x) {
|
12721 | return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent);
|
12722 | };
|
12723 | }
|
12724 |
|
12725 | function transformSqrt(x) {
|
12726 | return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x);
|
12727 | }
|
12728 |
|
12729 | function transformSquare(x) {
|
12730 | return x < 0 ? -x * x : x * x;
|
12731 | }
|
12732 |
|
12733 | function powish(transform) {
|
12734 | var scale = transform(identity$6, identity$6),
|
12735 | exponent = 1;
|
12736 |
|
12737 | function rescale() {
|
12738 | return exponent === 1 ? transform(identity$6, identity$6)
|
12739 | : exponent === 0.5 ? transform(transformSqrt, transformSquare)
|
12740 | : transform(transformPow(exponent), transformPow(1 / exponent));
|
12741 | }
|
12742 |
|
12743 | scale.exponent = function(_) {
|
12744 | return arguments.length ? (exponent = +_, rescale()) : exponent;
|
12745 | };
|
12746 |
|
12747 | return linearish(scale);
|
12748 | }
|
12749 |
|
12750 | function pow$1() {
|
12751 | var scale = powish(transformer$1());
|
12752 |
|
12753 | scale.copy = function() {
|
12754 | return copy(scale, pow$1()).exponent(scale.exponent());
|
12755 | };
|
12756 |
|
12757 | initRange.apply(scale, arguments);
|
12758 |
|
12759 | return scale;
|
12760 | }
|
12761 |
|
12762 | function sqrt$1() {
|
12763 | return pow$1.apply(null, arguments).exponent(0.5);
|
12764 | }
|
12765 |
|
12766 | function quantile() {
|
12767 | var domain = [],
|
12768 | range = [],
|
12769 | thresholds = [],
|
12770 | unknown;
|
12771 |
|
12772 | function rescale() {
|
12773 | var i = 0, n = Math.max(1, range.length);
|
12774 | thresholds = new Array(n - 1);
|
12775 | while (++i < n) thresholds[i - 1] = threshold(domain, i / n);
|
12776 | return scale;
|
12777 | }
|
12778 |
|
12779 | function scale(x) {
|
12780 | return isNaN(x = +x) ? unknown : range[bisectRight(thresholds, x)];
|
12781 | }
|
12782 |
|
12783 | scale.invertExtent = function(y) {
|
12784 | var i = range.indexOf(y);
|
12785 | return i < 0 ? [NaN, NaN] : [
|
12786 | i > 0 ? thresholds[i - 1] : domain[0],
|
12787 | i < thresholds.length ? thresholds[i] : domain[domain.length - 1]
|
12788 | ];
|
12789 | };
|
12790 |
|
12791 | scale.domain = function(_) {
|
12792 | if (!arguments.length) return domain.slice();
|
12793 | domain = [];
|
12794 | for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
|
12795 | domain.sort(ascending);
|
12796 | return rescale();
|
12797 | };
|
12798 |
|
12799 | scale.range = function(_) {
|
12800 | return arguments.length ? (range = slice$5.call(_), rescale()) : range.slice();
|
12801 | };
|
12802 |
|
12803 | scale.unknown = function(_) {
|
12804 | return arguments.length ? (unknown = _, scale) : unknown;
|
12805 | };
|
12806 |
|
12807 | scale.quantiles = function() {
|
12808 | return thresholds.slice();
|
12809 | };
|
12810 |
|
12811 | scale.copy = function() {
|
12812 | return quantile()
|
12813 | .domain(domain)
|
12814 | .range(range)
|
12815 | .unknown(unknown);
|
12816 | };
|
12817 |
|
12818 | return initRange.apply(scale, arguments);
|
12819 | }
|
12820 |
|
12821 | function quantize$1() {
|
12822 | var x0 = 0,
|
12823 | x1 = 1,
|
12824 | n = 1,
|
12825 | domain = [0.5],
|
12826 | range = [0, 1],
|
12827 | unknown;
|
12828 |
|
12829 | function scale(x) {
|
12830 | return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
|
12831 | }
|
12832 |
|
12833 | function rescale() {
|
12834 | var i = -1;
|
12835 | domain = new Array(n);
|
12836 | while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1);
|
12837 | return scale;
|
12838 | }
|
12839 |
|
12840 | scale.domain = function(_) {
|
12841 | return arguments.length ? (x0 = +_[0], x1 = +_[1], rescale()) : [x0, x1];
|
12842 | };
|
12843 |
|
12844 | scale.range = function(_) {
|
12845 | return arguments.length ? (n = (range = slice$5.call(_)).length - 1, rescale()) : range.slice();
|
12846 | };
|
12847 |
|
12848 | scale.invertExtent = function(y) {
|
12849 | var i = range.indexOf(y);
|
12850 | return i < 0 ? [NaN, NaN]
|
12851 | : i < 1 ? [x0, domain[0]]
|
12852 | : i >= n ? [domain[n - 1], x1]
|
12853 | : [domain[i - 1], domain[i]];
|
12854 | };
|
12855 |
|
12856 | scale.unknown = function(_) {
|
12857 | return arguments.length ? (unknown = _, scale) : scale;
|
12858 | };
|
12859 |
|
12860 | scale.thresholds = function() {
|
12861 | return domain.slice();
|
12862 | };
|
12863 |
|
12864 | scale.copy = function() {
|
12865 | return quantize$1()
|
12866 | .domain([x0, x1])
|
12867 | .range(range)
|
12868 | .unknown(unknown);
|
12869 | };
|
12870 |
|
12871 | return initRange.apply(linearish(scale), arguments);
|
12872 | }
|
12873 |
|
12874 | function threshold$1() {
|
12875 | var domain = [0.5],
|
12876 | range = [0, 1],
|
12877 | unknown,
|
12878 | n = 1;
|
12879 |
|
12880 | function scale(x) {
|
12881 | return x <= x ? range[bisectRight(domain, x, 0, n)] : unknown;
|
12882 | }
|
12883 |
|
12884 | scale.domain = function(_) {
|
12885 | return arguments.length ? (domain = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice();
|
12886 | };
|
12887 |
|
12888 | scale.range = function(_) {
|
12889 | return arguments.length ? (range = slice$5.call(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice();
|
12890 | };
|
12891 |
|
12892 | scale.invertExtent = function(y) {
|
12893 | var i = range.indexOf(y);
|
12894 | return [domain[i - 1], domain[i]];
|
12895 | };
|
12896 |
|
12897 | scale.unknown = function(_) {
|
12898 | return arguments.length ? (unknown = _, scale) : unknown;
|
12899 | };
|
12900 |
|
12901 | scale.copy = function() {
|
12902 | return threshold$1()
|
12903 | .domain(domain)
|
12904 | .range(range)
|
12905 | .unknown(unknown);
|
12906 | };
|
12907 |
|
12908 | return initRange.apply(scale, arguments);
|
12909 | }
|
12910 |
|
12911 | var t0$1 = new Date,
|
12912 | t1$1 = new Date;
|
12913 |
|
12914 | function newInterval(floori, offseti, count, field) {
|
12915 |
|
12916 | function interval(date) {
|
12917 | return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
|
12918 | }
|
12919 |
|
12920 | interval.floor = function(date) {
|
12921 | return floori(date = new Date(+date)), date;
|
12922 | };
|
12923 |
|
12924 | interval.ceil = function(date) {
|
12925 | return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
|
12926 | };
|
12927 |
|
12928 | interval.round = function(date) {
|
12929 | var d0 = interval(date),
|
12930 | d1 = interval.ceil(date);
|
12931 | return date - d0 < d1 - date ? d0 : d1;
|
12932 | };
|
12933 |
|
12934 | interval.offset = function(date, step) {
|
12935 | return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
|
12936 | };
|
12937 |
|
12938 | interval.range = function(start, stop, step) {
|
12939 | var range = [], previous;
|
12940 | start = interval.ceil(start);
|
12941 | step = step == null ? 1 : Math.floor(step);
|
12942 | if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
|
12943 | do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
|
12944 | while (previous < start && start < stop);
|
12945 | return range;
|
12946 | };
|
12947 |
|
12948 | interval.filter = function(test) {
|
12949 | return newInterval(function(date) {
|
12950 | if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
|
12951 | }, function(date, step) {
|
12952 | if (date >= date) {
|
12953 | if (step < 0) while (++step <= 0) {
|
12954 | while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
|
12955 | } else while (--step >= 0) {
|
12956 | while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
|
12957 | }
|
12958 | }
|
12959 | });
|
12960 | };
|
12961 |
|
12962 | if (count) {
|
12963 | interval.count = function(start, end) {
|
12964 | t0$1.setTime(+start), t1$1.setTime(+end);
|
12965 | floori(t0$1), floori(t1$1);
|
12966 | return Math.floor(count(t0$1, t1$1));
|
12967 | };
|
12968 |
|
12969 | interval.every = function(step) {
|
12970 | step = Math.floor(step);
|
12971 | return !isFinite(step) || !(step > 0) ? null
|
12972 | : !(step > 1) ? interval
|
12973 | : interval.filter(field
|
12974 | ? function(d) { return field(d) % step === 0; }
|
12975 | : function(d) { return interval.count(0, d) % step === 0; });
|
12976 | };
|
12977 | }
|
12978 |
|
12979 | return interval;
|
12980 | }
|
12981 |
|
12982 | var millisecond = newInterval(function() {
|
12983 | // noop
|
12984 | }, function(date, step) {
|
12985 | date.setTime(+date + step);
|
12986 | }, function(start, end) {
|
12987 | return end - start;
|
12988 | });
|
12989 |
|
12990 | // An optimized implementation for this simple case.
|
12991 | millisecond.every = function(k) {
|
12992 | k = Math.floor(k);
|
12993 | if (!isFinite(k) || !(k > 0)) return null;
|
12994 | if (!(k > 1)) return millisecond;
|
12995 | return newInterval(function(date) {
|
12996 | date.setTime(Math.floor(date / k) * k);
|
12997 | }, function(date, step) {
|
12998 | date.setTime(+date + step * k);
|
12999 | }, function(start, end) {
|
13000 | return (end - start) / k;
|
13001 | });
|
13002 | };
|
13003 | var milliseconds = millisecond.range;
|
13004 |
|
13005 | var durationSecond = 1e3;
|
13006 | var durationMinute = 6e4;
|
13007 | var durationHour = 36e5;
|
13008 | var durationDay = 864e5;
|
13009 | var durationWeek = 6048e5;
|
13010 |
|
13011 | var second = newInterval(function(date) {
|
13012 | date.setTime(date - date.getMilliseconds());
|
13013 | }, function(date, step) {
|
13014 | date.setTime(+date + step * durationSecond);
|
13015 | }, function(start, end) {
|
13016 | return (end - start) / durationSecond;
|
13017 | }, function(date) {
|
13018 | return date.getUTCSeconds();
|
13019 | });
|
13020 | var seconds = second.range;
|
13021 |
|
13022 | var minute = newInterval(function(date) {
|
13023 | date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond);
|
13024 | }, function(date, step) {
|
13025 | date.setTime(+date + step * durationMinute);
|
13026 | }, function(start, end) {
|
13027 | return (end - start) / durationMinute;
|
13028 | }, function(date) {
|
13029 | return date.getMinutes();
|
13030 | });
|
13031 | var minutes = minute.range;
|
13032 |
|
13033 | var hour = newInterval(function(date) {
|
13034 | date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute);
|
13035 | }, function(date, step) {
|
13036 | date.setTime(+date + step * durationHour);
|
13037 | }, function(start, end) {
|
13038 | return (end - start) / durationHour;
|
13039 | }, function(date) {
|
13040 | return date.getHours();
|
13041 | });
|
13042 | var hours = hour.range;
|
13043 |
|
13044 | var day = newInterval(function(date) {
|
13045 | date.setHours(0, 0, 0, 0);
|
13046 | }, function(date, step) {
|
13047 | date.setDate(date.getDate() + step);
|
13048 | }, function(start, end) {
|
13049 | return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
|
13050 | }, function(date) {
|
13051 | return date.getDate() - 1;
|
13052 | });
|
13053 | var days = day.range;
|
13054 |
|
13055 | function weekday(i) {
|
13056 | return newInterval(function(date) {
|
13057 | date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
|
13058 | date.setHours(0, 0, 0, 0);
|
13059 | }, function(date, step) {
|
13060 | date.setDate(date.getDate() + step * 7);
|
13061 | }, function(start, end) {
|
13062 | return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
|
13063 | });
|
13064 | }
|
13065 |
|
13066 | var sunday = weekday(0);
|
13067 | var monday = weekday(1);
|
13068 | var tuesday = weekday(2);
|
13069 | var wednesday = weekday(3);
|
13070 | var thursday = weekday(4);
|
13071 | var friday = weekday(5);
|
13072 | var saturday = weekday(6);
|
13073 |
|
13074 | var sundays = sunday.range;
|
13075 | var mondays = monday.range;
|
13076 | var tuesdays = tuesday.range;
|
13077 | var wednesdays = wednesday.range;
|
13078 | var thursdays = thursday.range;
|
13079 | var fridays = friday.range;
|
13080 | var saturdays = saturday.range;
|
13081 |
|
13082 | var month = newInterval(function(date) {
|
13083 | date.setDate(1);
|
13084 | date.setHours(0, 0, 0, 0);
|
13085 | }, function(date, step) {
|
13086 | date.setMonth(date.getMonth() + step);
|
13087 | }, function(start, end) {
|
13088 | return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
|
13089 | }, function(date) {
|
13090 | return date.getMonth();
|
13091 | });
|
13092 | var months = month.range;
|
13093 |
|
13094 | var year = newInterval(function(date) {
|
13095 | date.setMonth(0, 1);
|
13096 | date.setHours(0, 0, 0, 0);
|
13097 | }, function(date, step) {
|
13098 | date.setFullYear(date.getFullYear() + step);
|
13099 | }, function(start, end) {
|
13100 | return end.getFullYear() - start.getFullYear();
|
13101 | }, function(date) {
|
13102 | return date.getFullYear();
|
13103 | });
|
13104 |
|
13105 | // An optimized implementation for this simple case.
|
13106 | year.every = function(k) {
|
13107 | return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
|
13108 | date.setFullYear(Math.floor(date.getFullYear() / k) * k);
|
13109 | date.setMonth(0, 1);
|
13110 | date.setHours(0, 0, 0, 0);
|
13111 | }, function(date, step) {
|
13112 | date.setFullYear(date.getFullYear() + step * k);
|
13113 | });
|
13114 | };
|
13115 | var years = year.range;
|
13116 |
|
13117 | var utcMinute = newInterval(function(date) {
|
13118 | date.setUTCSeconds(0, 0);
|
13119 | }, function(date, step) {
|
13120 | date.setTime(+date + step * durationMinute);
|
13121 | }, function(start, end) {
|
13122 | return (end - start) / durationMinute;
|
13123 | }, function(date) {
|
13124 | return date.getUTCMinutes();
|
13125 | });
|
13126 | var utcMinutes = utcMinute.range;
|
13127 |
|
13128 | var utcHour = newInterval(function(date) {
|
13129 | date.setUTCMinutes(0, 0, 0);
|
13130 | }, function(date, step) {
|
13131 | date.setTime(+date + step * durationHour);
|
13132 | }, function(start, end) {
|
13133 | return (end - start) / durationHour;
|
13134 | }, function(date) {
|
13135 | return date.getUTCHours();
|
13136 | });
|
13137 | var utcHours = utcHour.range;
|
13138 |
|
13139 | var utcDay = newInterval(function(date) {
|
13140 | date.setUTCHours(0, 0, 0, 0);
|
13141 | }, function(date, step) {
|
13142 | date.setUTCDate(date.getUTCDate() + step);
|
13143 | }, function(start, end) {
|
13144 | return (end - start) / durationDay;
|
13145 | }, function(date) {
|
13146 | return date.getUTCDate() - 1;
|
13147 | });
|
13148 | var utcDays = utcDay.range;
|
13149 |
|
13150 | function utcWeekday(i) {
|
13151 | return newInterval(function(date) {
|
13152 | date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
|
13153 | date.setUTCHours(0, 0, 0, 0);
|
13154 | }, function(date, step) {
|
13155 | date.setUTCDate(date.getUTCDate() + step * 7);
|
13156 | }, function(start, end) {
|
13157 | return (end - start) / durationWeek;
|
13158 | });
|
13159 | }
|
13160 |
|
13161 | var utcSunday = utcWeekday(0);
|
13162 | var utcMonday = utcWeekday(1);
|
13163 | var utcTuesday = utcWeekday(2);
|
13164 | var utcWednesday = utcWeekday(3);
|
13165 | var utcThursday = utcWeekday(4);
|
13166 | var utcFriday = utcWeekday(5);
|
13167 | var utcSaturday = utcWeekday(6);
|
13168 |
|
13169 | var utcSundays = utcSunday.range;
|
13170 | var utcMondays = utcMonday.range;
|
13171 | var utcTuesdays = utcTuesday.range;
|
13172 | var utcWednesdays = utcWednesday.range;
|
13173 | var utcThursdays = utcThursday.range;
|
13174 | var utcFridays = utcFriday.range;
|
13175 | var utcSaturdays = utcSaturday.range;
|
13176 |
|
13177 | var utcMonth = newInterval(function(date) {
|
13178 | date.setUTCDate(1);
|
13179 | date.setUTCHours(0, 0, 0, 0);
|
13180 | }, function(date, step) {
|
13181 | date.setUTCMonth(date.getUTCMonth() + step);
|
13182 | }, function(start, end) {
|
13183 | return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
|
13184 | }, function(date) {
|
13185 | return date.getUTCMonth();
|
13186 | });
|
13187 | var utcMonths = utcMonth.range;
|
13188 |
|
13189 | var utcYear = newInterval(function(date) {
|
13190 | date.setUTCMonth(0, 1);
|
13191 | date.setUTCHours(0, 0, 0, 0);
|
13192 | }, function(date, step) {
|
13193 | date.setUTCFullYear(date.getUTCFullYear() + step);
|
13194 | }, function(start, end) {
|
13195 | return end.getUTCFullYear() - start.getUTCFullYear();
|
13196 | }, function(date) {
|
13197 | return date.getUTCFullYear();
|
13198 | });
|
13199 |
|
13200 | // An optimized implementation for this simple case.
|
13201 | utcYear.every = function(k) {
|
13202 | return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
|
13203 | date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
|
13204 | date.setUTCMonth(0, 1);
|
13205 | date.setUTCHours(0, 0, 0, 0);
|
13206 | }, function(date, step) {
|
13207 | date.setUTCFullYear(date.getUTCFullYear() + step * k);
|
13208 | });
|
13209 | };
|
13210 | var utcYears = utcYear.range;
|
13211 |
|
13212 | function localDate(d) {
|
13213 | if (0 <= d.y && d.y < 100) {
|
13214 | var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
|
13215 | date.setFullYear(d.y);
|
13216 | return date;
|
13217 | }
|
13218 | return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
|
13219 | }
|
13220 |
|
13221 | function utcDate(d) {
|
13222 | if (0 <= d.y && d.y < 100) {
|
13223 | var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
|
13224 | date.setUTCFullYear(d.y);
|
13225 | return date;
|
13226 | }
|
13227 | return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
|
13228 | }
|
13229 |
|
13230 | function newDate(y, m, d) {
|
13231 | return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
|
13232 | }
|
13233 |
|
13234 | function formatLocale$1(locale) {
|
13235 | var locale_dateTime = locale.dateTime,
|
13236 | locale_date = locale.date,
|
13237 | locale_time = locale.time,
|
13238 | locale_periods = locale.periods,
|
13239 | locale_weekdays = locale.days,
|
13240 | locale_shortWeekdays = locale.shortDays,
|
13241 | locale_months = locale.months,
|
13242 | locale_shortMonths = locale.shortMonths;
|
13243 |
|
13244 | var periodRe = formatRe(locale_periods),
|
13245 | periodLookup = formatLookup(locale_periods),
|
13246 | weekdayRe = formatRe(locale_weekdays),
|
13247 | weekdayLookup = formatLookup(locale_weekdays),
|
13248 | shortWeekdayRe = formatRe(locale_shortWeekdays),
|
13249 | shortWeekdayLookup = formatLookup(locale_shortWeekdays),
|
13250 | monthRe = formatRe(locale_months),
|
13251 | monthLookup = formatLookup(locale_months),
|
13252 | shortMonthRe = formatRe(locale_shortMonths),
|
13253 | shortMonthLookup = formatLookup(locale_shortMonths);
|
13254 |
|
13255 | var formats = {
|
13256 | "a": formatShortWeekday,
|
13257 | "A": formatWeekday,
|
13258 | "b": formatShortMonth,
|
13259 | "B": formatMonth,
|
13260 | "c": null,
|
13261 | "d": formatDayOfMonth,
|
13262 | "e": formatDayOfMonth,
|
13263 | "f": formatMicroseconds,
|
13264 | "H": formatHour24,
|
13265 | "I": formatHour12,
|
13266 | "j": formatDayOfYear,
|
13267 | "L": formatMilliseconds,
|
13268 | "m": formatMonthNumber,
|
13269 | "M": formatMinutes,
|
13270 | "p": formatPeriod,
|
13271 | "q": formatQuarter,
|
13272 | "Q": formatUnixTimestamp,
|
13273 | "s": formatUnixTimestampSeconds,
|
13274 | "S": formatSeconds,
|
13275 | "u": formatWeekdayNumberMonday,
|
13276 | "U": formatWeekNumberSunday,
|
13277 | "V": formatWeekNumberISO,
|
13278 | "w": formatWeekdayNumberSunday,
|
13279 | "W": formatWeekNumberMonday,
|
13280 | "x": null,
|
13281 | "X": null,
|
13282 | "y": formatYear$1,
|
13283 | "Y": formatFullYear,
|
13284 | "Z": formatZone,
|
13285 | "%": formatLiteralPercent
|
13286 | };
|
13287 |
|
13288 | var utcFormats = {
|
13289 | "a": formatUTCShortWeekday,
|
13290 | "A": formatUTCWeekday,
|
13291 | "b": formatUTCShortMonth,
|
13292 | "B": formatUTCMonth,
|
13293 | "c": null,
|
13294 | "d": formatUTCDayOfMonth,
|
13295 | "e": formatUTCDayOfMonth,
|
13296 | "f": formatUTCMicroseconds,
|
13297 | "H": formatUTCHour24,
|
13298 | "I": formatUTCHour12,
|
13299 | "j": formatUTCDayOfYear,
|
13300 | "L": formatUTCMilliseconds,
|
13301 | "m": formatUTCMonthNumber,
|
13302 | "M": formatUTCMinutes,
|
13303 | "p": formatUTCPeriod,
|
13304 | "q": formatUTCQuarter,
|
13305 | "Q": formatUnixTimestamp,
|
13306 | "s": formatUnixTimestampSeconds,
|
13307 | "S": formatUTCSeconds,
|
13308 | "u": formatUTCWeekdayNumberMonday,
|
13309 | "U": formatUTCWeekNumberSunday,
|
13310 | "V": formatUTCWeekNumberISO,
|
13311 | "w": formatUTCWeekdayNumberSunday,
|
13312 | "W": formatUTCWeekNumberMonday,
|
13313 | "x": null,
|
13314 | "X": null,
|
13315 | "y": formatUTCYear,
|
13316 | "Y": formatUTCFullYear,
|
13317 | "Z": formatUTCZone,
|
13318 | "%": formatLiteralPercent
|
13319 | };
|
13320 |
|
13321 | var parses = {
|
13322 | "a": parseShortWeekday,
|
13323 | "A": parseWeekday,
|
13324 | "b": parseShortMonth,
|
13325 | "B": parseMonth,
|
13326 | "c": parseLocaleDateTime,
|
13327 | "d": parseDayOfMonth,
|
13328 | "e": parseDayOfMonth,
|
13329 | "f": parseMicroseconds,
|
13330 | "H": parseHour24,
|
13331 | "I": parseHour24,
|
13332 | "j": parseDayOfYear,
|
13333 | "L": parseMilliseconds,
|
13334 | "m": parseMonthNumber,
|
13335 | "M": parseMinutes,
|
13336 | "p": parsePeriod,
|
13337 | "q": parseQuarter,
|
13338 | "Q": parseUnixTimestamp,
|
13339 | "s": parseUnixTimestampSeconds,
|
13340 | "S": parseSeconds,
|
13341 | "u": parseWeekdayNumberMonday,
|
13342 | "U": parseWeekNumberSunday,
|
13343 | "V": parseWeekNumberISO,
|
13344 | "w": parseWeekdayNumberSunday,
|
13345 | "W": parseWeekNumberMonday,
|
13346 | "x": parseLocaleDate,
|
13347 | "X": parseLocaleTime,
|
13348 | "y": parseYear,
|
13349 | "Y": parseFullYear,
|
13350 | "Z": parseZone,
|
13351 | "%": parseLiteralPercent
|
13352 | };
|
13353 |
|
13354 | // These recursive directive definitions must be deferred.
|
13355 | formats.x = newFormat(locale_date, formats);
|
13356 | formats.X = newFormat(locale_time, formats);
|
13357 | formats.c = newFormat(locale_dateTime, formats);
|
13358 | utcFormats.x = newFormat(locale_date, utcFormats);
|
13359 | utcFormats.X = newFormat(locale_time, utcFormats);
|
13360 | utcFormats.c = newFormat(locale_dateTime, utcFormats);
|
13361 |
|
13362 | function newFormat(specifier, formats) {
|
13363 | return function(date) {
|
13364 | var string = [],
|
13365 | i = -1,
|
13366 | j = 0,
|
13367 | n = specifier.length,
|
13368 | c,
|
13369 | pad,
|
13370 | format;
|
13371 |
|
13372 | if (!(date instanceof Date)) date = new Date(+date);
|
13373 |
|
13374 | while (++i < n) {
|
13375 | if (specifier.charCodeAt(i) === 37) {
|
13376 | string.push(specifier.slice(j, i));
|
13377 | if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
|
13378 | else pad = c === "e" ? " " : "0";
|
13379 | if (format = formats[c]) c = format(date, pad);
|
13380 | string.push(c);
|
13381 | j = i + 1;
|
13382 | }
|
13383 | }
|
13384 |
|
13385 | string.push(specifier.slice(j, i));
|
13386 | return string.join("");
|
13387 | };
|
13388 | }
|
13389 |
|
13390 | function newParse(specifier, Z) {
|
13391 | return function(string) {
|
13392 | var d = newDate(1900, undefined, 1),
|
13393 | i = parseSpecifier(d, specifier, string += "", 0),
|
13394 | week, day$1;
|
13395 | if (i != string.length) return null;
|
13396 |
|
13397 | // If a UNIX timestamp is specified, return it.
|
13398 | if ("Q" in d) return new Date(d.Q);
|
13399 | if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
|
13400 |
|
13401 | // If this is utcParse, never use the local timezone.
|
13402 | if (Z && !("Z" in d)) d.Z = 0;
|
13403 |
|
13404 | // The am-pm flag is 0 for AM, and 1 for PM.
|
13405 | if ("p" in d) d.H = d.H % 12 + d.p * 12;
|
13406 |
|
13407 | // If the month was not specified, inherit from the quarter.
|
13408 | if (d.m === undefined) d.m = "q" in d ? d.q : 0;
|
13409 |
|
13410 | // Convert day-of-week and week-of-year to day-of-year.
|
13411 | if ("V" in d) {
|
13412 | if (d.V < 1 || d.V > 53) return null;
|
13413 | if (!("w" in d)) d.w = 1;
|
13414 | if ("Z" in d) {
|
13415 | week = utcDate(newDate(d.y, 0, 1)), day$1 = week.getUTCDay();
|
13416 | week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
|
13417 | week = utcDay.offset(week, (d.V - 1) * 7);
|
13418 | d.y = week.getUTCFullYear();
|
13419 | d.m = week.getUTCMonth();
|
13420 | d.d = week.getUTCDate() + (d.w + 6) % 7;
|
13421 | } else {
|
13422 | week = localDate(newDate(d.y, 0, 1)), day$1 = week.getDay();
|
13423 | week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
|
13424 | week = day.offset(week, (d.V - 1) * 7);
|
13425 | d.y = week.getFullYear();
|
13426 | d.m = week.getMonth();
|
13427 | d.d = week.getDate() + (d.w + 6) % 7;
|
13428 | }
|
13429 | } else if ("W" in d || "U" in d) {
|
13430 | if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
|
13431 | day$1 = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
|
13432 | d.m = 0;
|
13433 | d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$1 + 5) % 7 : d.w + d.U * 7 - (day$1 + 6) % 7;
|
13434 | }
|
13435 |
|
13436 | // If a time zone is specified, all fields are interpreted as UTC and then
|
13437 | // offset according to the specified time zone.
|
13438 | if ("Z" in d) {
|
13439 | d.H += d.Z / 100 | 0;
|
13440 | d.M += d.Z % 100;
|
13441 | return utcDate(d);
|
13442 | }
|
13443 |
|
13444 | // Otherwise, all fields are in local time.
|
13445 | return localDate(d);
|
13446 | };
|
13447 | }
|
13448 |
|
13449 | function parseSpecifier(d, specifier, string, j) {
|
13450 | var i = 0,
|
13451 | n = specifier.length,
|
13452 | m = string.length,
|
13453 | c,
|
13454 | parse;
|
13455 |
|
13456 | while (i < n) {
|
13457 | if (j >= m) return -1;
|
13458 | c = specifier.charCodeAt(i++);
|
13459 | if (c === 37) {
|
13460 | c = specifier.charAt(i++);
|
13461 | parse = parses[c in pads ? specifier.charAt(i++) : c];
|
13462 | if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
|
13463 | } else if (c != string.charCodeAt(j++)) {
|
13464 | return -1;
|
13465 | }
|
13466 | }
|
13467 |
|
13468 | return j;
|
13469 | }
|
13470 |
|
13471 | function parsePeriod(d, string, i) {
|
13472 | var n = periodRe.exec(string.slice(i));
|
13473 | return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
13474 | }
|
13475 |
|
13476 | function parseShortWeekday(d, string, i) {
|
13477 | var n = shortWeekdayRe.exec(string.slice(i));
|
13478 | return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
13479 | }
|
13480 |
|
13481 | function parseWeekday(d, string, i) {
|
13482 | var n = weekdayRe.exec(string.slice(i));
|
13483 | return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
13484 | }
|
13485 |
|
13486 | function parseShortMonth(d, string, i) {
|
13487 | var n = shortMonthRe.exec(string.slice(i));
|
13488 | return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
13489 | }
|
13490 |
|
13491 | function parseMonth(d, string, i) {
|
13492 | var n = monthRe.exec(string.slice(i));
|
13493 | return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
13494 | }
|
13495 |
|
13496 | function parseLocaleDateTime(d, string, i) {
|
13497 | return parseSpecifier(d, locale_dateTime, string, i);
|
13498 | }
|
13499 |
|
13500 | function parseLocaleDate(d, string, i) {
|
13501 | return parseSpecifier(d, locale_date, string, i);
|
13502 | }
|
13503 |
|
13504 | function parseLocaleTime(d, string, i) {
|
13505 | return parseSpecifier(d, locale_time, string, i);
|
13506 | }
|
13507 |
|
13508 | function formatShortWeekday(d) {
|
13509 | return locale_shortWeekdays[d.getDay()];
|
13510 | }
|
13511 |
|
13512 | function formatWeekday(d) {
|
13513 | return locale_weekdays[d.getDay()];
|
13514 | }
|
13515 |
|
13516 | function formatShortMonth(d) {
|
13517 | return locale_shortMonths[d.getMonth()];
|
13518 | }
|
13519 |
|
13520 | function formatMonth(d) {
|
13521 | return locale_months[d.getMonth()];
|
13522 | }
|
13523 |
|
13524 | function formatPeriod(d) {
|
13525 | return locale_periods[+(d.getHours() >= 12)];
|
13526 | }
|
13527 |
|
13528 | function formatQuarter(d) {
|
13529 | return 1 + ~~(d.getMonth() / 3);
|
13530 | }
|
13531 |
|
13532 | function formatUTCShortWeekday(d) {
|
13533 | return locale_shortWeekdays[d.getUTCDay()];
|
13534 | }
|
13535 |
|
13536 | function formatUTCWeekday(d) {
|
13537 | return locale_weekdays[d.getUTCDay()];
|
13538 | }
|
13539 |
|
13540 | function formatUTCShortMonth(d) {
|
13541 | return locale_shortMonths[d.getUTCMonth()];
|
13542 | }
|
13543 |
|
13544 | function formatUTCMonth(d) {
|
13545 | return locale_months[d.getUTCMonth()];
|
13546 | }
|
13547 |
|
13548 | function formatUTCPeriod(d) {
|
13549 | return locale_periods[+(d.getUTCHours() >= 12)];
|
13550 | }
|
13551 |
|
13552 | function formatUTCQuarter(d) {
|
13553 | return 1 + ~~(d.getUTCMonth() / 3);
|
13554 | }
|
13555 |
|
13556 | return {
|
13557 | format: function(specifier) {
|
13558 | var f = newFormat(specifier += "", formats);
|
13559 | f.toString = function() { return specifier; };
|
13560 | return f;
|
13561 | },
|
13562 | parse: function(specifier) {
|
13563 | var p = newParse(specifier += "", false);
|
13564 | p.toString = function() { return specifier; };
|
13565 | return p;
|
13566 | },
|
13567 | utcFormat: function(specifier) {
|
13568 | var f = newFormat(specifier += "", utcFormats);
|
13569 | f.toString = function() { return specifier; };
|
13570 | return f;
|
13571 | },
|
13572 | utcParse: function(specifier) {
|
13573 | var p = newParse(specifier += "", true);
|
13574 | p.toString = function() { return specifier; };
|
13575 | return p;
|
13576 | }
|
13577 | };
|
13578 | }
|
13579 |
|
13580 | var pads = {"-": "", "_": " ", "0": "0"},
|
13581 | numberRe = /^\s*\d+/, // note: ignores next directive
|
13582 | percentRe = /^%/,
|
13583 | requoteRe = /[\\^$*+?|[\]().{}]/g;
|
13584 |
|
13585 | function pad$1(value, fill, width) {
|
13586 | var sign = value < 0 ? "-" : "",
|
13587 | string = (sign ? -value : value) + "",
|
13588 | length = string.length;
|
13589 | return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
|
13590 | }
|
13591 |
|
13592 | function requote(s) {
|
13593 | return s.replace(requoteRe, "\\$&");
|
13594 | }
|
13595 |
|
13596 | function formatRe(names) {
|
13597 | return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
|
13598 | }
|
13599 |
|
13600 | function formatLookup(names) {
|
13601 | var map = {}, i = -1, n = names.length;
|
13602 | while (++i < n) map[names[i].toLowerCase()] = i;
|
13603 | return map;
|
13604 | }
|
13605 |
|
13606 | function parseWeekdayNumberSunday(d, string, i) {
|
13607 | var n = numberRe.exec(string.slice(i, i + 1));
|
13608 | return n ? (d.w = +n[0], i + n[0].length) : -1;
|
13609 | }
|
13610 |
|
13611 | function parseWeekdayNumberMonday(d, string, i) {
|
13612 | var n = numberRe.exec(string.slice(i, i + 1));
|
13613 | return n ? (d.u = +n[0], i + n[0].length) : -1;
|
13614 | }
|
13615 |
|
13616 | function parseWeekNumberSunday(d, string, i) {
|
13617 | var n = numberRe.exec(string.slice(i, i + 2));
|
13618 | return n ? (d.U = +n[0], i + n[0].length) : -1;
|
13619 | }
|
13620 |
|
13621 | function parseWeekNumberISO(d, string, i) {
|
13622 | var n = numberRe.exec(string.slice(i, i + 2));
|
13623 | return n ? (d.V = +n[0], i + n[0].length) : -1;
|
13624 | }
|
13625 |
|
13626 | function parseWeekNumberMonday(d, string, i) {
|
13627 | var n = numberRe.exec(string.slice(i, i + 2));
|
13628 | return n ? (d.W = +n[0], i + n[0].length) : -1;
|
13629 | }
|
13630 |
|
13631 | function parseFullYear(d, string, i) {
|
13632 | var n = numberRe.exec(string.slice(i, i + 4));
|
13633 | return n ? (d.y = +n[0], i + n[0].length) : -1;
|
13634 | }
|
13635 |
|
13636 | function parseYear(d, string, i) {
|
13637 | var n = numberRe.exec(string.slice(i, i + 2));
|
13638 | return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
|
13639 | }
|
13640 |
|
13641 | function parseZone(d, string, i) {
|
13642 | var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
|
13643 | return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
|
13644 | }
|
13645 |
|
13646 | function parseQuarter(d, string, i) {
|
13647 | var n = numberRe.exec(string.slice(i, i + 1));
|
13648 | return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
|
13649 | }
|
13650 |
|
13651 | function parseMonthNumber(d, string, i) {
|
13652 | var n = numberRe.exec(string.slice(i, i + 2));
|
13653 | return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
|
13654 | }
|
13655 |
|
13656 | function parseDayOfMonth(d, string, i) {
|
13657 | var n = numberRe.exec(string.slice(i, i + 2));
|
13658 | return n ? (d.d = +n[0], i + n[0].length) : -1;
|
13659 | }
|
13660 |
|
13661 | function parseDayOfYear(d, string, i) {
|
13662 | var n = numberRe.exec(string.slice(i, i + 3));
|
13663 | return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
|
13664 | }
|
13665 |
|
13666 | function parseHour24(d, string, i) {
|
13667 | var n = numberRe.exec(string.slice(i, i + 2));
|
13668 | return n ? (d.H = +n[0], i + n[0].length) : -1;
|
13669 | }
|
13670 |
|
13671 | function parseMinutes(d, string, i) {
|
13672 | var n = numberRe.exec(string.slice(i, i + 2));
|
13673 | return n ? (d.M = +n[0], i + n[0].length) : -1;
|
13674 | }
|
13675 |
|
13676 | function parseSeconds(d, string, i) {
|
13677 | var n = numberRe.exec(string.slice(i, i + 2));
|
13678 | return n ? (d.S = +n[0], i + n[0].length) : -1;
|
13679 | }
|
13680 |
|
13681 | function parseMilliseconds(d, string, i) {
|
13682 | var n = numberRe.exec(string.slice(i, i + 3));
|
13683 | return n ? (d.L = +n[0], i + n[0].length) : -1;
|
13684 | }
|
13685 |
|
13686 | function parseMicroseconds(d, string, i) {
|
13687 | var n = numberRe.exec(string.slice(i, i + 6));
|
13688 | return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
|
13689 | }
|
13690 |
|
13691 | function parseLiteralPercent(d, string, i) {
|
13692 | var n = percentRe.exec(string.slice(i, i + 1));
|
13693 | return n ? i + n[0].length : -1;
|
13694 | }
|
13695 |
|
13696 | function parseUnixTimestamp(d, string, i) {
|
13697 | var n = numberRe.exec(string.slice(i));
|
13698 | return n ? (d.Q = +n[0], i + n[0].length) : -1;
|
13699 | }
|
13700 |
|
13701 | function parseUnixTimestampSeconds(d, string, i) {
|
13702 | var n = numberRe.exec(string.slice(i));
|
13703 | return n ? (d.s = +n[0], i + n[0].length) : -1;
|
13704 | }
|
13705 |
|
13706 | function formatDayOfMonth(d, p) {
|
13707 | return pad$1(d.getDate(), p, 2);
|
13708 | }
|
13709 |
|
13710 | function formatHour24(d, p) {
|
13711 | return pad$1(d.getHours(), p, 2);
|
13712 | }
|
13713 |
|
13714 | function formatHour12(d, p) {
|
13715 | return pad$1(d.getHours() % 12 || 12, p, 2);
|
13716 | }
|
13717 |
|
13718 | function formatDayOfYear(d, p) {
|
13719 | return pad$1(1 + day.count(year(d), d), p, 3);
|
13720 | }
|
13721 |
|
13722 | function formatMilliseconds(d, p) {
|
13723 | return pad$1(d.getMilliseconds(), p, 3);
|
13724 | }
|
13725 |
|
13726 | function formatMicroseconds(d, p) {
|
13727 | return formatMilliseconds(d, p) + "000";
|
13728 | }
|
13729 |
|
13730 | function formatMonthNumber(d, p) {
|
13731 | return pad$1(d.getMonth() + 1, p, 2);
|
13732 | }
|
13733 |
|
13734 | function formatMinutes(d, p) {
|
13735 | return pad$1(d.getMinutes(), p, 2);
|
13736 | }
|
13737 |
|
13738 | function formatSeconds(d, p) {
|
13739 | return pad$1(d.getSeconds(), p, 2);
|
13740 | }
|
13741 |
|
13742 | function formatWeekdayNumberMonday(d) {
|
13743 | var day = d.getDay();
|
13744 | return day === 0 ? 7 : day;
|
13745 | }
|
13746 |
|
13747 | function formatWeekNumberSunday(d, p) {
|
13748 | return pad$1(sunday.count(year(d) - 1, d), p, 2);
|
13749 | }
|
13750 |
|
13751 | function formatWeekNumberISO(d, p) {
|
13752 | var day = d.getDay();
|
13753 | d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
|
13754 | return pad$1(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
|
13755 | }
|
13756 |
|
13757 | function formatWeekdayNumberSunday(d) {
|
13758 | return d.getDay();
|
13759 | }
|
13760 |
|
13761 | function formatWeekNumberMonday(d, p) {
|
13762 | return pad$1(monday.count(year(d) - 1, d), p, 2);
|
13763 | }
|
13764 |
|
13765 | function formatYear$1(d, p) {
|
13766 | return pad$1(d.getFullYear() % 100, p, 2);
|
13767 | }
|
13768 |
|
13769 | function formatFullYear(d, p) {
|
13770 | return pad$1(d.getFullYear() % 10000, p, 4);
|
13771 | }
|
13772 |
|
13773 | function formatZone(d) {
|
13774 | var z = d.getTimezoneOffset();
|
13775 | return (z > 0 ? "-" : (z *= -1, "+"))
|
13776 | + pad$1(z / 60 | 0, "0", 2)
|
13777 | + pad$1(z % 60, "0", 2);
|
13778 | }
|
13779 |
|
13780 | function formatUTCDayOfMonth(d, p) {
|
13781 | return pad$1(d.getUTCDate(), p, 2);
|
13782 | }
|
13783 |
|
13784 | function formatUTCHour24(d, p) {
|
13785 | return pad$1(d.getUTCHours(), p, 2);
|
13786 | }
|
13787 |
|
13788 | function formatUTCHour12(d, p) {
|
13789 | return pad$1(d.getUTCHours() % 12 || 12, p, 2);
|
13790 | }
|
13791 |
|
13792 | function formatUTCDayOfYear(d, p) {
|
13793 | return pad$1(1 + utcDay.count(utcYear(d), d), p, 3);
|
13794 | }
|
13795 |
|
13796 | function formatUTCMilliseconds(d, p) {
|
13797 | return pad$1(d.getUTCMilliseconds(), p, 3);
|
13798 | }
|
13799 |
|
13800 | function formatUTCMicroseconds(d, p) {
|
13801 | return formatUTCMilliseconds(d, p) + "000";
|
13802 | }
|
13803 |
|
13804 | function formatUTCMonthNumber(d, p) {
|
13805 | return pad$1(d.getUTCMonth() + 1, p, 2);
|
13806 | }
|
13807 |
|
13808 | function formatUTCMinutes(d, p) {
|
13809 | return pad$1(d.getUTCMinutes(), p, 2);
|
13810 | }
|
13811 |
|
13812 | function formatUTCSeconds(d, p) {
|
13813 | return pad$1(d.getUTCSeconds(), p, 2);
|
13814 | }
|
13815 |
|
13816 | function formatUTCWeekdayNumberMonday(d) {
|
13817 | var dow = d.getUTCDay();
|
13818 | return dow === 0 ? 7 : dow;
|
13819 | }
|
13820 |
|
13821 | function formatUTCWeekNumberSunday(d, p) {
|
13822 | return pad$1(utcSunday.count(utcYear(d) - 1, d), p, 2);
|
13823 | }
|
13824 |
|
13825 | function formatUTCWeekNumberISO(d, p) {
|
13826 | var day = d.getUTCDay();
|
13827 | d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
|
13828 | return pad$1(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
|
13829 | }
|
13830 |
|
13831 | function formatUTCWeekdayNumberSunday(d) {
|
13832 | return d.getUTCDay();
|
13833 | }
|
13834 |
|
13835 | function formatUTCWeekNumberMonday(d, p) {
|
13836 | return pad$1(utcMonday.count(utcYear(d) - 1, d), p, 2);
|
13837 | }
|
13838 |
|
13839 | function formatUTCYear(d, p) {
|
13840 | return pad$1(d.getUTCFullYear() % 100, p, 2);
|
13841 | }
|
13842 |
|
13843 | function formatUTCFullYear(d, p) {
|
13844 | return pad$1(d.getUTCFullYear() % 10000, p, 4);
|
13845 | }
|
13846 |
|
13847 | function formatUTCZone() {
|
13848 | return "+0000";
|
13849 | }
|
13850 |
|
13851 | function formatLiteralPercent() {
|
13852 | return "%";
|
13853 | }
|
13854 |
|
13855 | function formatUnixTimestamp(d) {
|
13856 | return +d;
|
13857 | }
|
13858 |
|
13859 | function formatUnixTimestampSeconds(d) {
|
13860 | return Math.floor(+d / 1000);
|
13861 | }
|
13862 |
|
13863 | var locale$1;
|
13864 |
|
13865 | defaultLocale$1({
|
13866 | dateTime: "%x, %X",
|
13867 | date: "%-m/%-d/%Y",
|
13868 | time: "%-I:%M:%S %p",
|
13869 | periods: ["AM", "PM"],
|
13870 | days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
13871 | shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
13872 | months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
13873 | shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
13874 | });
|
13875 |
|
13876 | function defaultLocale$1(definition) {
|
13877 | locale$1 = formatLocale$1(definition);
|
13878 | exports.timeFormat = locale$1.format;
|
13879 | exports.timeParse = locale$1.parse;
|
13880 | exports.utcFormat = locale$1.utcFormat;
|
13881 | exports.utcParse = locale$1.utcParse;
|
13882 | return locale$1;
|
13883 | }
|
13884 |
|
13885 | var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
|
13886 |
|
13887 | function formatIsoNative(date) {
|
13888 | return date.toISOString();
|
13889 | }
|
13890 |
|
13891 | var formatIso = Date.prototype.toISOString
|
13892 | ? formatIsoNative
|
13893 | : exports.utcFormat(isoSpecifier);
|
13894 |
|
13895 | function parseIsoNative(string) {
|
13896 | var date = new Date(string);
|
13897 | return isNaN(date) ? null : date;
|
13898 | }
|
13899 |
|
13900 | var parseIso = +new Date("2000-01-01T00:00:00.000Z")
|
13901 | ? parseIsoNative
|
13902 | : exports.utcParse(isoSpecifier);
|
13903 |
|
13904 | var durationSecond$1 = 1000,
|
13905 | durationMinute$1 = durationSecond$1 * 60,
|
13906 | durationHour$1 = durationMinute$1 * 60,
|
13907 | durationDay$1 = durationHour$1 * 24,
|
13908 | durationWeek$1 = durationDay$1 * 7,
|
13909 | durationMonth = durationDay$1 * 30,
|
13910 | durationYear = durationDay$1 * 365;
|
13911 |
|
13912 | function date$1(t) {
|
13913 | return new Date(t);
|
13914 | }
|
13915 |
|
13916 | function number$3(t) {
|
13917 | return t instanceof Date ? +t : +new Date(+t);
|
13918 | }
|
13919 |
|
13920 | function calendar(year, month, week, day, hour, minute, second, millisecond, format) {
|
13921 | var scale = continuous(identity$6, identity$6),
|
13922 | invert = scale.invert,
|
13923 | domain = scale.domain;
|
13924 |
|
13925 | var formatMillisecond = format(".%L"),
|
13926 | formatSecond = format(":%S"),
|
13927 | formatMinute = format("%I:%M"),
|
13928 | formatHour = format("%I %p"),
|
13929 | formatDay = format("%a %d"),
|
13930 | formatWeek = format("%b %d"),
|
13931 | formatMonth = format("%B"),
|
13932 | formatYear = format("%Y");
|
13933 |
|
13934 | var tickIntervals = [
|
13935 | [second, 1, durationSecond$1],
|
13936 | [second, 5, 5 * durationSecond$1],
|
13937 | [second, 15, 15 * durationSecond$1],
|
13938 | [second, 30, 30 * durationSecond$1],
|
13939 | [minute, 1, durationMinute$1],
|
13940 | [minute, 5, 5 * durationMinute$1],
|
13941 | [minute, 15, 15 * durationMinute$1],
|
13942 | [minute, 30, 30 * durationMinute$1],
|
13943 | [ hour, 1, durationHour$1 ],
|
13944 | [ hour, 3, 3 * durationHour$1 ],
|
13945 | [ hour, 6, 6 * durationHour$1 ],
|
13946 | [ hour, 12, 12 * durationHour$1 ],
|
13947 | [ day, 1, durationDay$1 ],
|
13948 | [ day, 2, 2 * durationDay$1 ],
|
13949 | [ week, 1, durationWeek$1 ],
|
13950 | [ month, 1, durationMonth ],
|
13951 | [ month, 3, 3 * durationMonth ],
|
13952 | [ year, 1, durationYear ]
|
13953 | ];
|
13954 |
|
13955 | function tickFormat(date) {
|
13956 | return (second(date) < date ? formatMillisecond
|
13957 | : minute(date) < date ? formatSecond
|
13958 | : hour(date) < date ? formatMinute
|
13959 | : day(date) < date ? formatHour
|
13960 | : month(date) < date ? (week(date) < date ? formatDay : formatWeek)
|
13961 | : year(date) < date ? formatMonth
|
13962 | : formatYear)(date);
|
13963 | }
|
13964 |
|
13965 | function tickInterval(interval, start, stop, step) {
|
13966 | if (interval == null) interval = 10;
|
13967 |
|
13968 | // If a desired tick count is specified, pick a reasonable tick interval
|
13969 | // based on the extent of the domain and a rough estimate of tick size.
|
13970 | // Otherwise, assume interval is already a time interval and use it.
|
13971 | if (typeof interval === "number") {
|
13972 | var target = Math.abs(stop - start) / interval,
|
13973 | i = bisector(function(i) { return i[2]; }).right(tickIntervals, target);
|
13974 | if (i === tickIntervals.length) {
|
13975 | step = tickStep(start / durationYear, stop / durationYear, interval);
|
13976 | interval = year;
|
13977 | } else if (i) {
|
13978 | i = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
|
13979 | step = i[1];
|
13980 | interval = i[0];
|
13981 | } else {
|
13982 | step = Math.max(tickStep(start, stop, interval), 1);
|
13983 | interval = millisecond;
|
13984 | }
|
13985 | }
|
13986 |
|
13987 | return step == null ? interval : interval.every(step);
|
13988 | }
|
13989 |
|
13990 | scale.invert = function(y) {
|
13991 | return new Date(invert(y));
|
13992 | };
|
13993 |
|
13994 | scale.domain = function(_) {
|
13995 | return arguments.length ? domain(map$3.call(_, number$3)) : domain().map(date$1);
|
13996 | };
|
13997 |
|
13998 | scale.ticks = function(interval, step) {
|
13999 | var d = domain(),
|
14000 | t0 = d[0],
|
14001 | t1 = d[d.length - 1],
|
14002 | r = t1 < t0,
|
14003 | t;
|
14004 | if (r) t = t0, t0 = t1, t1 = t;
|
14005 | t = tickInterval(interval, t0, t1, step);
|
14006 | t = t ? t.range(t0, t1 + 1) : []; // inclusive stop
|
14007 | return r ? t.reverse() : t;
|
14008 | };
|
14009 |
|
14010 | scale.tickFormat = function(count, specifier) {
|
14011 | return specifier == null ? tickFormat : format(specifier);
|
14012 | };
|
14013 |
|
14014 | scale.nice = function(interval, step) {
|
14015 | var d = domain();
|
14016 | return (interval = tickInterval(interval, d[0], d[d.length - 1], step))
|
14017 | ? domain(nice(d, interval))
|
14018 | : scale;
|
14019 | };
|
14020 |
|
14021 | scale.copy = function() {
|
14022 | return copy(scale, calendar(year, month, week, day, hour, minute, second, millisecond, format));
|
14023 | };
|
14024 |
|
14025 | return scale;
|
14026 | }
|
14027 |
|
14028 | function time() {
|
14029 | return initRange.apply(calendar(year, month, sunday, day, hour, minute, second, millisecond, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments);
|
14030 | }
|
14031 |
|
14032 | function utcTime() {
|
14033 | return initRange.apply(calendar(utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, millisecond, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments);
|
14034 | }
|
14035 |
|
14036 | function transformer$2() {
|
14037 | var x0 = 0,
|
14038 | x1 = 1,
|
14039 | t0,
|
14040 | t1,
|
14041 | k10,
|
14042 | transform,
|
14043 | interpolator = identity$6,
|
14044 | clamp = false,
|
14045 | unknown;
|
14046 |
|
14047 | function scale(x) {
|
14048 | return isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x));
|
14049 | }
|
14050 |
|
14051 | scale.domain = function(_) {
|
14052 | return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1];
|
14053 | };
|
14054 |
|
14055 | scale.clamp = function(_) {
|
14056 | return arguments.length ? (clamp = !!_, scale) : clamp;
|
14057 | };
|
14058 |
|
14059 | scale.interpolator = function(_) {
|
14060 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
14061 | };
|
14062 |
|
14063 | scale.unknown = function(_) {
|
14064 | return arguments.length ? (unknown = _, scale) : unknown;
|
14065 | };
|
14066 |
|
14067 | return function(t) {
|
14068 | transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0);
|
14069 | return scale;
|
14070 | };
|
14071 | }
|
14072 |
|
14073 | function copy$1(source, target) {
|
14074 | return target
|
14075 | .domain(source.domain())
|
14076 | .interpolator(source.interpolator())
|
14077 | .clamp(source.clamp())
|
14078 | .unknown(source.unknown());
|
14079 | }
|
14080 |
|
14081 | function sequential() {
|
14082 | var scale = linearish(transformer$2()(identity$6));
|
14083 |
|
14084 | scale.copy = function() {
|
14085 | return copy$1(scale, sequential());
|
14086 | };
|
14087 |
|
14088 | return initInterpolator.apply(scale, arguments);
|
14089 | }
|
14090 |
|
14091 | function sequentialLog() {
|
14092 | var scale = loggish(transformer$2()).domain([1, 10]);
|
14093 |
|
14094 | scale.copy = function() {
|
14095 | return copy$1(scale, sequentialLog()).base(scale.base());
|
14096 | };
|
14097 |
|
14098 | return initInterpolator.apply(scale, arguments);
|
14099 | }
|
14100 |
|
14101 | function sequentialSymlog() {
|
14102 | var scale = symlogish(transformer$2());
|
14103 |
|
14104 | scale.copy = function() {
|
14105 | return copy$1(scale, sequentialSymlog()).constant(scale.constant());
|
14106 | };
|
14107 |
|
14108 | return initInterpolator.apply(scale, arguments);
|
14109 | }
|
14110 |
|
14111 | function sequentialPow() {
|
14112 | var scale = powish(transformer$2());
|
14113 |
|
14114 | scale.copy = function() {
|
14115 | return copy$1(scale, sequentialPow()).exponent(scale.exponent());
|
14116 | };
|
14117 |
|
14118 | return initInterpolator.apply(scale, arguments);
|
14119 | }
|
14120 |
|
14121 | function sequentialSqrt() {
|
14122 | return sequentialPow.apply(null, arguments).exponent(0.5);
|
14123 | }
|
14124 |
|
14125 | function sequentialQuantile() {
|
14126 | var domain = [],
|
14127 | interpolator = identity$6;
|
14128 |
|
14129 | function scale(x) {
|
14130 | if (!isNaN(x = +x)) return interpolator((bisectRight(domain, x) - 1) / (domain.length - 1));
|
14131 | }
|
14132 |
|
14133 | scale.domain = function(_) {
|
14134 | if (!arguments.length) return domain.slice();
|
14135 | domain = [];
|
14136 | for (var i = 0, n = _.length, d; i < n; ++i) if (d = _[i], d != null && !isNaN(d = +d)) domain.push(d);
|
14137 | domain.sort(ascending);
|
14138 | return scale;
|
14139 | };
|
14140 |
|
14141 | scale.interpolator = function(_) {
|
14142 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
14143 | };
|
14144 |
|
14145 | scale.copy = function() {
|
14146 | return sequentialQuantile(interpolator).domain(domain);
|
14147 | };
|
14148 |
|
14149 | return initInterpolator.apply(scale, arguments);
|
14150 | }
|
14151 |
|
14152 | function transformer$3() {
|
14153 | var x0 = 0,
|
14154 | x1 = 0.5,
|
14155 | x2 = 1,
|
14156 | t0,
|
14157 | t1,
|
14158 | t2,
|
14159 | k10,
|
14160 | k21,
|
14161 | interpolator = identity$6,
|
14162 | transform,
|
14163 | clamp = false,
|
14164 | unknown;
|
14165 |
|
14166 | function scale(x) {
|
14167 | return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (x < t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x));
|
14168 | }
|
14169 |
|
14170 | scale.domain = function(_) {
|
14171 | return arguments.length ? (t0 = transform(x0 = +_[0]), t1 = transform(x1 = +_[1]), t2 = transform(x2 = +_[2]), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), scale) : [x0, x1, x2];
|
14172 | };
|
14173 |
|
14174 | scale.clamp = function(_) {
|
14175 | return arguments.length ? (clamp = !!_, scale) : clamp;
|
14176 | };
|
14177 |
|
14178 | scale.interpolator = function(_) {
|
14179 | return arguments.length ? (interpolator = _, scale) : interpolator;
|
14180 | };
|
14181 |
|
14182 | scale.unknown = function(_) {
|
14183 | return arguments.length ? (unknown = _, scale) : unknown;
|
14184 | };
|
14185 |
|
14186 | return function(t) {
|
14187 | 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);
|
14188 | return scale;
|
14189 | };
|
14190 | }
|
14191 |
|
14192 | function diverging() {
|
14193 | var scale = linearish(transformer$3()(identity$6));
|
14194 |
|
14195 | scale.copy = function() {
|
14196 | return copy$1(scale, diverging());
|
14197 | };
|
14198 |
|
14199 | return initInterpolator.apply(scale, arguments);
|
14200 | }
|
14201 |
|
14202 | function divergingLog() {
|
14203 | var scale = loggish(transformer$3()).domain([0.1, 1, 10]);
|
14204 |
|
14205 | scale.copy = function() {
|
14206 | return copy$1(scale, divergingLog()).base(scale.base());
|
14207 | };
|
14208 |
|
14209 | return initInterpolator.apply(scale, arguments);
|
14210 | }
|
14211 |
|
14212 | function divergingSymlog() {
|
14213 | var scale = symlogish(transformer$3());
|
14214 |
|
14215 | scale.copy = function() {
|
14216 | return copy$1(scale, divergingSymlog()).constant(scale.constant());
|
14217 | };
|
14218 |
|
14219 | return initInterpolator.apply(scale, arguments);
|
14220 | }
|
14221 |
|
14222 | function divergingPow() {
|
14223 | var scale = powish(transformer$3());
|
14224 |
|
14225 | scale.copy = function() {
|
14226 | return copy$1(scale, divergingPow()).exponent(scale.exponent());
|
14227 | };
|
14228 |
|
14229 | return initInterpolator.apply(scale, arguments);
|
14230 | }
|
14231 |
|
14232 | function divergingSqrt() {
|
14233 | return divergingPow.apply(null, arguments).exponent(0.5);
|
14234 | }
|
14235 |
|
14236 | function colors(specifier) {
|
14237 | var n = specifier.length / 6 | 0, colors = new Array(n), i = 0;
|
14238 | while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6);
|
14239 | return colors;
|
14240 | }
|
14241 |
|
14242 | var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf");
|
14243 |
|
14244 | var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");
|
14245 |
|
14246 | var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666");
|
14247 |
|
14248 | var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");
|
14249 |
|
14250 | var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2");
|
14251 |
|
14252 | var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc");
|
14253 |
|
14254 | var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999");
|
14255 |
|
14256 | var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3");
|
14257 |
|
14258 | var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f");
|
14259 |
|
14260 | var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab");
|
14261 |
|
14262 | function ramp(scheme) {
|
14263 | return rgbBasis(scheme[scheme.length - 1]);
|
14264 | }
|
14265 |
|
14266 | var scheme = new Array(3).concat(
|
14267 | "d8b365f5f5f55ab4ac",
|
14268 | "a6611adfc27d80cdc1018571",
|
14269 | "a6611adfc27df5f5f580cdc1018571",
|
14270 | "8c510ad8b365f6e8c3c7eae55ab4ac01665e",
|
14271 | "8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e",
|
14272 | "8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e",
|
14273 | "8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e",
|
14274 | "5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30",
|
14275 | "5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30"
|
14276 | ).map(colors);
|
14277 |
|
14278 | var BrBG = ramp(scheme);
|
14279 |
|
14280 | var scheme$1 = new Array(3).concat(
|
14281 | "af8dc3f7f7f77fbf7b",
|
14282 | "7b3294c2a5cfa6dba0008837",
|
14283 | "7b3294c2a5cff7f7f7a6dba0008837",
|
14284 | "762a83af8dc3e7d4e8d9f0d37fbf7b1b7837",
|
14285 | "762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837",
|
14286 | "762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837",
|
14287 | "762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837",
|
14288 | "40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b",
|
14289 | "40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b"
|
14290 | ).map(colors);
|
14291 |
|
14292 | var PRGn = ramp(scheme$1);
|
14293 |
|
14294 | var scheme$2 = new Array(3).concat(
|
14295 | "e9a3c9f7f7f7a1d76a",
|
14296 | "d01c8bf1b6dab8e1864dac26",
|
14297 | "d01c8bf1b6daf7f7f7b8e1864dac26",
|
14298 | "c51b7de9a3c9fde0efe6f5d0a1d76a4d9221",
|
14299 | "c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221",
|
14300 | "c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221",
|
14301 | "c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221",
|
14302 | "8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419",
|
14303 | "8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419"
|
14304 | ).map(colors);
|
14305 |
|
14306 | var PiYG = ramp(scheme$2);
|
14307 |
|
14308 | var scheme$3 = new Array(3).concat(
|
14309 | "998ec3f7f7f7f1a340",
|
14310 | "5e3c99b2abd2fdb863e66101",
|
14311 | "5e3c99b2abd2f7f7f7fdb863e66101",
|
14312 | "542788998ec3d8daebfee0b6f1a340b35806",
|
14313 | "542788998ec3d8daebf7f7f7fee0b6f1a340b35806",
|
14314 | "5427888073acb2abd2d8daebfee0b6fdb863e08214b35806",
|
14315 | "5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806",
|
14316 | "2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08",
|
14317 | "2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08"
|
14318 | ).map(colors);
|
14319 |
|
14320 | var PuOr = ramp(scheme$3);
|
14321 |
|
14322 | var scheme$4 = new Array(3).concat(
|
14323 | "ef8a62f7f7f767a9cf",
|
14324 | "ca0020f4a58292c5de0571b0",
|
14325 | "ca0020f4a582f7f7f792c5de0571b0",
|
14326 | "b2182bef8a62fddbc7d1e5f067a9cf2166ac",
|
14327 | "b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac",
|
14328 | "b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac",
|
14329 | "b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac",
|
14330 | "67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061",
|
14331 | "67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061"
|
14332 | ).map(colors);
|
14333 |
|
14334 | var RdBu = ramp(scheme$4);
|
14335 |
|
14336 | var scheme$5 = new Array(3).concat(
|
14337 | "ef8a62ffffff999999",
|
14338 | "ca0020f4a582bababa404040",
|
14339 | "ca0020f4a582ffffffbababa404040",
|
14340 | "b2182bef8a62fddbc7e0e0e09999994d4d4d",
|
14341 | "b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d",
|
14342 | "b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d",
|
14343 | "b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d",
|
14344 | "67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a",
|
14345 | "67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a"
|
14346 | ).map(colors);
|
14347 |
|
14348 | var RdGy = ramp(scheme$5);
|
14349 |
|
14350 | var scheme$6 = new Array(3).concat(
|
14351 | "fc8d59ffffbf91bfdb",
|
14352 | "d7191cfdae61abd9e92c7bb6",
|
14353 | "d7191cfdae61ffffbfabd9e92c7bb6",
|
14354 | "d73027fc8d59fee090e0f3f891bfdb4575b4",
|
14355 | "d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4",
|
14356 | "d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4",
|
14357 | "d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4",
|
14358 | "a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695",
|
14359 | "a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695"
|
14360 | ).map(colors);
|
14361 |
|
14362 | var RdYlBu = ramp(scheme$6);
|
14363 |
|
14364 | var scheme$7 = new Array(3).concat(
|
14365 | "fc8d59ffffbf91cf60",
|
14366 | "d7191cfdae61a6d96a1a9641",
|
14367 | "d7191cfdae61ffffbfa6d96a1a9641",
|
14368 | "d73027fc8d59fee08bd9ef8b91cf601a9850",
|
14369 | "d73027fc8d59fee08bffffbfd9ef8b91cf601a9850",
|
14370 | "d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850",
|
14371 | "d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850",
|
14372 | "a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837",
|
14373 | "a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837"
|
14374 | ).map(colors);
|
14375 |
|
14376 | var RdYlGn = ramp(scheme$7);
|
14377 |
|
14378 | var scheme$8 = new Array(3).concat(
|
14379 | "fc8d59ffffbf99d594",
|
14380 | "d7191cfdae61abdda42b83ba",
|
14381 | "d7191cfdae61ffffbfabdda42b83ba",
|
14382 | "d53e4ffc8d59fee08be6f59899d5943288bd",
|
14383 | "d53e4ffc8d59fee08bffffbfe6f59899d5943288bd",
|
14384 | "d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd",
|
14385 | "d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd",
|
14386 | "9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2",
|
14387 | "9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2"
|
14388 | ).map(colors);
|
14389 |
|
14390 | var Spectral = ramp(scheme$8);
|
14391 |
|
14392 | var scheme$9 = new Array(3).concat(
|
14393 | "e5f5f999d8c92ca25f",
|
14394 | "edf8fbb2e2e266c2a4238b45",
|
14395 | "edf8fbb2e2e266c2a42ca25f006d2c",
|
14396 | "edf8fbccece699d8c966c2a42ca25f006d2c",
|
14397 | "edf8fbccece699d8c966c2a441ae76238b45005824",
|
14398 | "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824",
|
14399 | "f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b"
|
14400 | ).map(colors);
|
14401 |
|
14402 | var BuGn = ramp(scheme$9);
|
14403 |
|
14404 | var scheme$a = new Array(3).concat(
|
14405 | "e0ecf49ebcda8856a7",
|
14406 | "edf8fbb3cde38c96c688419d",
|
14407 | "edf8fbb3cde38c96c68856a7810f7c",
|
14408 | "edf8fbbfd3e69ebcda8c96c68856a7810f7c",
|
14409 | "edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b",
|
14410 | "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b",
|
14411 | "f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b"
|
14412 | ).map(colors);
|
14413 |
|
14414 | var BuPu = ramp(scheme$a);
|
14415 |
|
14416 | var scheme$b = new Array(3).concat(
|
14417 | "e0f3dba8ddb543a2ca",
|
14418 | "f0f9e8bae4bc7bccc42b8cbe",
|
14419 | "f0f9e8bae4bc7bccc443a2ca0868ac",
|
14420 | "f0f9e8ccebc5a8ddb57bccc443a2ca0868ac",
|
14421 | "f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e",
|
14422 | "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e",
|
14423 | "f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081"
|
14424 | ).map(colors);
|
14425 |
|
14426 | var GnBu = ramp(scheme$b);
|
14427 |
|
14428 | var scheme$c = new Array(3).concat(
|
14429 | "fee8c8fdbb84e34a33",
|
14430 | "fef0d9fdcc8afc8d59d7301f",
|
14431 | "fef0d9fdcc8afc8d59e34a33b30000",
|
14432 | "fef0d9fdd49efdbb84fc8d59e34a33b30000",
|
14433 | "fef0d9fdd49efdbb84fc8d59ef6548d7301f990000",
|
14434 | "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000",
|
14435 | "fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000"
|
14436 | ).map(colors);
|
14437 |
|
14438 | var OrRd = ramp(scheme$c);
|
14439 |
|
14440 | var scheme$d = new Array(3).concat(
|
14441 | "ece2f0a6bddb1c9099",
|
14442 | "f6eff7bdc9e167a9cf02818a",
|
14443 | "f6eff7bdc9e167a9cf1c9099016c59",
|
14444 | "f6eff7d0d1e6a6bddb67a9cf1c9099016c59",
|
14445 | "f6eff7d0d1e6a6bddb67a9cf3690c002818a016450",
|
14446 | "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450",
|
14447 | "fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636"
|
14448 | ).map(colors);
|
14449 |
|
14450 | var PuBuGn = ramp(scheme$d);
|
14451 |
|
14452 | var scheme$e = new Array(3).concat(
|
14453 | "ece7f2a6bddb2b8cbe",
|
14454 | "f1eef6bdc9e174a9cf0570b0",
|
14455 | "f1eef6bdc9e174a9cf2b8cbe045a8d",
|
14456 | "f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d",
|
14457 | "f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b",
|
14458 | "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b",
|
14459 | "fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858"
|
14460 | ).map(colors);
|
14461 |
|
14462 | var PuBu = ramp(scheme$e);
|
14463 |
|
14464 | var scheme$f = new Array(3).concat(
|
14465 | "e7e1efc994c7dd1c77",
|
14466 | "f1eef6d7b5d8df65b0ce1256",
|
14467 | "f1eef6d7b5d8df65b0dd1c77980043",
|
14468 | "f1eef6d4b9dac994c7df65b0dd1c77980043",
|
14469 | "f1eef6d4b9dac994c7df65b0e7298ace125691003f",
|
14470 | "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f",
|
14471 | "f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f"
|
14472 | ).map(colors);
|
14473 |
|
14474 | var PuRd = ramp(scheme$f);
|
14475 |
|
14476 | var scheme$g = new Array(3).concat(
|
14477 | "fde0ddfa9fb5c51b8a",
|
14478 | "feebe2fbb4b9f768a1ae017e",
|
14479 | "feebe2fbb4b9f768a1c51b8a7a0177",
|
14480 | "feebe2fcc5c0fa9fb5f768a1c51b8a7a0177",
|
14481 | "feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177",
|
14482 | "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177",
|
14483 | "fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a"
|
14484 | ).map(colors);
|
14485 |
|
14486 | var RdPu = ramp(scheme$g);
|
14487 |
|
14488 | var scheme$h = new Array(3).concat(
|
14489 | "edf8b17fcdbb2c7fb8",
|
14490 | "ffffcca1dab441b6c4225ea8",
|
14491 | "ffffcca1dab441b6c42c7fb8253494",
|
14492 | "ffffccc7e9b47fcdbb41b6c42c7fb8253494",
|
14493 | "ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84",
|
14494 | "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84",
|
14495 | "ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58"
|
14496 | ).map(colors);
|
14497 |
|
14498 | var YlGnBu = ramp(scheme$h);
|
14499 |
|
14500 | var scheme$i = new Array(3).concat(
|
14501 | "f7fcb9addd8e31a354",
|
14502 | "ffffccc2e69978c679238443",
|
14503 | "ffffccc2e69978c67931a354006837",
|
14504 | "ffffccd9f0a3addd8e78c67931a354006837",
|
14505 | "ffffccd9f0a3addd8e78c67941ab5d238443005a32",
|
14506 | "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32",
|
14507 | "ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529"
|
14508 | ).map(colors);
|
14509 |
|
14510 | var YlGn = ramp(scheme$i);
|
14511 |
|
14512 | var scheme$j = new Array(3).concat(
|
14513 | "fff7bcfec44fd95f0e",
|
14514 | "ffffd4fed98efe9929cc4c02",
|
14515 | "ffffd4fed98efe9929d95f0e993404",
|
14516 | "ffffd4fee391fec44ffe9929d95f0e993404",
|
14517 | "ffffd4fee391fec44ffe9929ec7014cc4c028c2d04",
|
14518 | "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04",
|
14519 | "ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506"
|
14520 | ).map(colors);
|
14521 |
|
14522 | var YlOrBr = ramp(scheme$j);
|
14523 |
|
14524 | var scheme$k = new Array(3).concat(
|
14525 | "ffeda0feb24cf03b20",
|
14526 | "ffffb2fecc5cfd8d3ce31a1c",
|
14527 | "ffffb2fecc5cfd8d3cf03b20bd0026",
|
14528 | "ffffb2fed976feb24cfd8d3cf03b20bd0026",
|
14529 | "ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026",
|
14530 | "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026",
|
14531 | "ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026"
|
14532 | ).map(colors);
|
14533 |
|
14534 | var YlOrRd = ramp(scheme$k);
|
14535 |
|
14536 | var scheme$l = new Array(3).concat(
|
14537 | "deebf79ecae13182bd",
|
14538 | "eff3ffbdd7e76baed62171b5",
|
14539 | "eff3ffbdd7e76baed63182bd08519c",
|
14540 | "eff3ffc6dbef9ecae16baed63182bd08519c",
|
14541 | "eff3ffc6dbef9ecae16baed64292c62171b5084594",
|
14542 | "f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594",
|
14543 | "f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b"
|
14544 | ).map(colors);
|
14545 |
|
14546 | var Blues = ramp(scheme$l);
|
14547 |
|
14548 | var scheme$m = new Array(3).concat(
|
14549 | "e5f5e0a1d99b31a354",
|
14550 | "edf8e9bae4b374c476238b45",
|
14551 | "edf8e9bae4b374c47631a354006d2c",
|
14552 | "edf8e9c7e9c0a1d99b74c47631a354006d2c",
|
14553 | "edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32",
|
14554 | "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32",
|
14555 | "f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b"
|
14556 | ).map(colors);
|
14557 |
|
14558 | var Greens = ramp(scheme$m);
|
14559 |
|
14560 | var scheme$n = new Array(3).concat(
|
14561 | "f0f0f0bdbdbd636363",
|
14562 | "f7f7f7cccccc969696525252",
|
14563 | "f7f7f7cccccc969696636363252525",
|
14564 | "f7f7f7d9d9d9bdbdbd969696636363252525",
|
14565 | "f7f7f7d9d9d9bdbdbd969696737373525252252525",
|
14566 | "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525",
|
14567 | "fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000"
|
14568 | ).map(colors);
|
14569 |
|
14570 | var Greys = ramp(scheme$n);
|
14571 |
|
14572 | var scheme$o = new Array(3).concat(
|
14573 | "efedf5bcbddc756bb1",
|
14574 | "f2f0f7cbc9e29e9ac86a51a3",
|
14575 | "f2f0f7cbc9e29e9ac8756bb154278f",
|
14576 | "f2f0f7dadaebbcbddc9e9ac8756bb154278f",
|
14577 | "f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486",
|
14578 | "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486",
|
14579 | "fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d"
|
14580 | ).map(colors);
|
14581 |
|
14582 | var Purples = ramp(scheme$o);
|
14583 |
|
14584 | var scheme$p = new Array(3).concat(
|
14585 | "fee0d2fc9272de2d26",
|
14586 | "fee5d9fcae91fb6a4acb181d",
|
14587 | "fee5d9fcae91fb6a4ade2d26a50f15",
|
14588 | "fee5d9fcbba1fc9272fb6a4ade2d26a50f15",
|
14589 | "fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d",
|
14590 | "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d",
|
14591 | "fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d"
|
14592 | ).map(colors);
|
14593 |
|
14594 | var Reds = ramp(scheme$p);
|
14595 |
|
14596 | var scheme$q = new Array(3).concat(
|
14597 | "fee6cefdae6be6550d",
|
14598 | "feeddefdbe85fd8d3cd94701",
|
14599 | "feeddefdbe85fd8d3ce6550da63603",
|
14600 | "feeddefdd0a2fdae6bfd8d3ce6550da63603",
|
14601 | "feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04",
|
14602 | "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04",
|
14603 | "fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704"
|
14604 | ).map(colors);
|
14605 |
|
14606 | var Oranges = ramp(scheme$q);
|
14607 |
|
14608 | function cividis(t) {
|
14609 | t = Math.max(0, Math.min(1, t));
|
14610 | return "rgb("
|
14611 | + 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))))))) + ", "
|
14612 | + 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))))))) + ", "
|
14613 | + 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)))))))
|
14614 | + ")";
|
14615 | }
|
14616 |
|
14617 | var cubehelix$3 = cubehelixLong(cubehelix(300, 0.5, 0.0), cubehelix(-240, 0.5, 1.0));
|
14618 |
|
14619 | var warm = cubehelixLong(cubehelix(-100, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
|
14620 |
|
14621 | var cool = cubehelixLong(cubehelix(260, 0.75, 0.35), cubehelix(80, 1.50, 0.8));
|
14622 |
|
14623 | var c = cubehelix();
|
14624 |
|
14625 | function rainbow(t) {
|
14626 | if (t < 0 || t > 1) t -= Math.floor(t);
|
14627 | var ts = Math.abs(t - 0.5);
|
14628 | c.h = 360 * t - 100;
|
14629 | c.s = 1.5 - 1.5 * ts;
|
14630 | c.l = 0.8 - 0.9 * ts;
|
14631 | return c + "";
|
14632 | }
|
14633 |
|
14634 | var c$1 = rgb(),
|
14635 | pi_1_3 = Math.PI / 3,
|
14636 | pi_2_3 = Math.PI * 2 / 3;
|
14637 |
|
14638 | function sinebow(t) {
|
14639 | var x;
|
14640 | t = (0.5 - t) * Math.PI;
|
14641 | c$1.r = 255 * (x = Math.sin(t)) * x;
|
14642 | c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x;
|
14643 | c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x;
|
14644 | return c$1 + "";
|
14645 | }
|
14646 |
|
14647 | function turbo(t) {
|
14648 | t = Math.max(0, Math.min(1, t));
|
14649 | return "rgb("
|
14650 | + 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))))))) + ", "
|
14651 | + 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))))))) + ", "
|
14652 | + Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66)))))))
|
14653 | + ")";
|
14654 | }
|
14655 |
|
14656 | function ramp$1(range) {
|
14657 | var n = range.length;
|
14658 | return function(t) {
|
14659 | return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
|
14660 | };
|
14661 | }
|
14662 |
|
14663 | var viridis = ramp$1(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));
|
14664 |
|
14665 | var magma = ramp$1(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));
|
14666 |
|
14667 | var inferno = ramp$1(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));
|
14668 |
|
14669 | var plasma = ramp$1(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));
|
14670 |
|
14671 | function constant$b(x) {
|
14672 | return function constant() {
|
14673 | return x;
|
14674 | };
|
14675 | }
|
14676 |
|
14677 | var abs$1 = Math.abs;
|
14678 | var atan2$1 = Math.atan2;
|
14679 | var cos$2 = Math.cos;
|
14680 | var max$2 = Math.max;
|
14681 | var min$1 = Math.min;
|
14682 | var sin$2 = Math.sin;
|
14683 | var sqrt$2 = Math.sqrt;
|
14684 |
|
14685 | var epsilon$3 = 1e-12;
|
14686 | var pi$4 = Math.PI;
|
14687 | var halfPi$3 = pi$4 / 2;
|
14688 | var tau$4 = 2 * pi$4;
|
14689 |
|
14690 | function acos$1(x) {
|
14691 | return x > 1 ? 0 : x < -1 ? pi$4 : Math.acos(x);
|
14692 | }
|
14693 |
|
14694 | function asin$1(x) {
|
14695 | return x >= 1 ? halfPi$3 : x <= -1 ? -halfPi$3 : Math.asin(x);
|
14696 | }
|
14697 |
|
14698 | function arcInnerRadius(d) {
|
14699 | return d.innerRadius;
|
14700 | }
|
14701 |
|
14702 | function arcOuterRadius(d) {
|
14703 | return d.outerRadius;
|
14704 | }
|
14705 |
|
14706 | function arcStartAngle(d) {
|
14707 | return d.startAngle;
|
14708 | }
|
14709 |
|
14710 | function arcEndAngle(d) {
|
14711 | return d.endAngle;
|
14712 | }
|
14713 |
|
14714 | function arcPadAngle(d) {
|
14715 | return d && d.padAngle; // Note: optional!
|
14716 | }
|
14717 |
|
14718 | function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
|
14719 | var x10 = x1 - x0, y10 = y1 - y0,
|
14720 | x32 = x3 - x2, y32 = y3 - y2,
|
14721 | t = y32 * x10 - x32 * y10;
|
14722 | if (t * t < epsilon$3) return;
|
14723 | t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
|
14724 | return [x0 + t * x10, y0 + t * y10];
|
14725 | }
|
14726 |
|
14727 | // Compute perpendicular offset line of length rc.
|
14728 | // http://mathworld.wolfram.com/Circle-LineIntersection.html
|
14729 | function cornerTangents(x0, y0, x1, y1, r1, rc, cw) {
|
14730 | var x01 = x0 - x1,
|
14731 | y01 = y0 - y1,
|
14732 | lo = (cw ? rc : -rc) / sqrt$2(x01 * x01 + y01 * y01),
|
14733 | ox = lo * y01,
|
14734 | oy = -lo * x01,
|
14735 | x11 = x0 + ox,
|
14736 | y11 = y0 + oy,
|
14737 | x10 = x1 + ox,
|
14738 | y10 = y1 + oy,
|
14739 | x00 = (x11 + x10) / 2,
|
14740 | y00 = (y11 + y10) / 2,
|
14741 | dx = x10 - x11,
|
14742 | dy = y10 - y11,
|
14743 | d2 = dx * dx + dy * dy,
|
14744 | r = r1 - rc,
|
14745 | D = x11 * y10 - x10 * y11,
|
14746 | d = (dy < 0 ? -1 : 1) * sqrt$2(max$2(0, r * r * d2 - D * D)),
|
14747 | cx0 = (D * dy - dx * d) / d2,
|
14748 | cy0 = (-D * dx - dy * d) / d2,
|
14749 | cx1 = (D * dy + dx * d) / d2,
|
14750 | cy1 = (-D * dx + dy * d) / d2,
|
14751 | dx0 = cx0 - x00,
|
14752 | dy0 = cy0 - y00,
|
14753 | dx1 = cx1 - x00,
|
14754 | dy1 = cy1 - y00;
|
14755 |
|
14756 | // Pick the closer of the two intersection points.
|
14757 | // TODO Is there a faster way to determine which intersection to use?
|
14758 | if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
|
14759 |
|
14760 | return {
|
14761 | cx: cx0,
|
14762 | cy: cy0,
|
14763 | x01: -ox,
|
14764 | y01: -oy,
|
14765 | x11: cx0 * (r1 / r - 1),
|
14766 | y11: cy0 * (r1 / r - 1)
|
14767 | };
|
14768 | }
|
14769 |
|
14770 | function arc() {
|
14771 | var innerRadius = arcInnerRadius,
|
14772 | outerRadius = arcOuterRadius,
|
14773 | cornerRadius = constant$b(0),
|
14774 | padRadius = null,
|
14775 | startAngle = arcStartAngle,
|
14776 | endAngle = arcEndAngle,
|
14777 | padAngle = arcPadAngle,
|
14778 | context = null;
|
14779 |
|
14780 | function arc() {
|
14781 | var buffer,
|
14782 | r,
|
14783 | r0 = +innerRadius.apply(this, arguments),
|
14784 | r1 = +outerRadius.apply(this, arguments),
|
14785 | a0 = startAngle.apply(this, arguments) - halfPi$3,
|
14786 | a1 = endAngle.apply(this, arguments) - halfPi$3,
|
14787 | da = abs$1(a1 - a0),
|
14788 | cw = a1 > a0;
|
14789 |
|
14790 | if (!context) context = buffer = path();
|
14791 |
|
14792 | // Ensure that the outer radius is always larger than the inner radius.
|
14793 | if (r1 < r0) r = r1, r1 = r0, r0 = r;
|
14794 |
|
14795 | // Is it a point?
|
14796 | if (!(r1 > epsilon$3)) context.moveTo(0, 0);
|
14797 |
|
14798 | // Or is it a circle or annulus?
|
14799 | else if (da > tau$4 - epsilon$3) {
|
14800 | context.moveTo(r1 * cos$2(a0), r1 * sin$2(a0));
|
14801 | context.arc(0, 0, r1, a0, a1, !cw);
|
14802 | if (r0 > epsilon$3) {
|
14803 | context.moveTo(r0 * cos$2(a1), r0 * sin$2(a1));
|
14804 | context.arc(0, 0, r0, a1, a0, cw);
|
14805 | }
|
14806 | }
|
14807 |
|
14808 | // Or is it a circular or annular sector?
|
14809 | else {
|
14810 | var a01 = a0,
|
14811 | a11 = a1,
|
14812 | a00 = a0,
|
14813 | a10 = a1,
|
14814 | da0 = da,
|
14815 | da1 = da,
|
14816 | ap = padAngle.apply(this, arguments) / 2,
|
14817 | rp = (ap > epsilon$3) && (padRadius ? +padRadius.apply(this, arguments) : sqrt$2(r0 * r0 + r1 * r1)),
|
14818 | rc = min$1(abs$1(r1 - r0) / 2, +cornerRadius.apply(this, arguments)),
|
14819 | rc0 = rc,
|
14820 | rc1 = rc,
|
14821 | t0,
|
14822 | t1;
|
14823 |
|
14824 | // Apply padding? Note that since r1 ≥ r0, da1 ≥ da0.
|
14825 | if (rp > epsilon$3) {
|
14826 | var p0 = asin$1(rp / r0 * sin$2(ap)),
|
14827 | p1 = asin$1(rp / r1 * sin$2(ap));
|
14828 | if ((da0 -= p0 * 2) > epsilon$3) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0;
|
14829 | else da0 = 0, a00 = a10 = (a0 + a1) / 2;
|
14830 | if ((da1 -= p1 * 2) > epsilon$3) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1;
|
14831 | else da1 = 0, a01 = a11 = (a0 + a1) / 2;
|
14832 | }
|
14833 |
|
14834 | var x01 = r1 * cos$2(a01),
|
14835 | y01 = r1 * sin$2(a01),
|
14836 | x10 = r0 * cos$2(a10),
|
14837 | y10 = r0 * sin$2(a10);
|
14838 |
|
14839 | // Apply rounded corners?
|
14840 | if (rc > epsilon$3) {
|
14841 | var x11 = r1 * cos$2(a11),
|
14842 | y11 = r1 * sin$2(a11),
|
14843 | x00 = r0 * cos$2(a00),
|
14844 | y00 = r0 * sin$2(a00),
|
14845 | oc;
|
14846 |
|
14847 | // Restrict the corner radius according to the sector angle.
|
14848 | if (da < pi$4 && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
|
14849 | var ax = x01 - oc[0],
|
14850 | ay = y01 - oc[1],
|
14851 | bx = x11 - oc[0],
|
14852 | by = y11 - oc[1],
|
14853 | kc = 1 / sin$2(acos$1((ax * bx + ay * by) / (sqrt$2(ax * ax + ay * ay) * sqrt$2(bx * bx + by * by))) / 2),
|
14854 | lc = sqrt$2(oc[0] * oc[0] + oc[1] * oc[1]);
|
14855 | rc0 = min$1(rc, (r0 - lc) / (kc - 1));
|
14856 | rc1 = min$1(rc, (r1 - lc) / (kc + 1));
|
14857 | }
|
14858 | }
|
14859 |
|
14860 | // Is the sector collapsed to a line?
|
14861 | if (!(da1 > epsilon$3)) context.moveTo(x01, y01);
|
14862 |
|
14863 | // Does the sector’s outer ring have rounded corners?
|
14864 | else if (rc1 > epsilon$3) {
|
14865 | t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw);
|
14866 | t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw);
|
14867 |
|
14868 | context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
14869 |
|
14870 | // Have the corners merged?
|
14871 | if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
|
14872 |
|
14873 | // Otherwise, draw the two corners and the ring.
|
14874 | else {
|
14875 | context.arc(t0.cx, t0.cy, rc1, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
|
14876 | context.arc(0, 0, r1, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), !cw);
|
14877 | context.arc(t1.cx, t1.cy, rc1, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
|
14878 | }
|
14879 | }
|
14880 |
|
14881 | // Or is the outer ring just a circular arc?
|
14882 | else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw);
|
14883 |
|
14884 | // Is there no inner ring, and it’s a circular sector?
|
14885 | // Or perhaps it’s an annular sector collapsed due to padding?
|
14886 | if (!(r0 > epsilon$3) || !(da0 > epsilon$3)) context.lineTo(x10, y10);
|
14887 |
|
14888 | // Does the sector’s inner ring (or point) have rounded corners?
|
14889 | else if (rc0 > epsilon$3) {
|
14890 | t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw);
|
14891 | t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw);
|
14892 |
|
14893 | context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01);
|
14894 |
|
14895 | // Have the corners merged?
|
14896 | if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t1.y01, t1.x01), !cw);
|
14897 |
|
14898 | // Otherwise, draw the two corners and the ring.
|
14899 | else {
|
14900 | context.arc(t0.cx, t0.cy, rc0, atan2$1(t0.y01, t0.x01), atan2$1(t0.y11, t0.x11), !cw);
|
14901 | context.arc(0, 0, r0, atan2$1(t0.cy + t0.y11, t0.cx + t0.x11), atan2$1(t1.cy + t1.y11, t1.cx + t1.x11), cw);
|
14902 | context.arc(t1.cx, t1.cy, rc0, atan2$1(t1.y11, t1.x11), atan2$1(t1.y01, t1.x01), !cw);
|
14903 | }
|
14904 | }
|
14905 |
|
14906 | // Or is the inner ring just a circular arc?
|
14907 | else context.arc(0, 0, r0, a10, a00, cw);
|
14908 | }
|
14909 |
|
14910 | context.closePath();
|
14911 |
|
14912 | if (buffer) return context = null, buffer + "" || null;
|
14913 | }
|
14914 |
|
14915 | arc.centroid = function() {
|
14916 | var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2,
|
14917 | a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi$4 / 2;
|
14918 | return [cos$2(a) * r, sin$2(a) * r];
|
14919 | };
|
14920 |
|
14921 | arc.innerRadius = function(_) {
|
14922 | return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : innerRadius;
|
14923 | };
|
14924 |
|
14925 | arc.outerRadius = function(_) {
|
14926 | return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : outerRadius;
|
14927 | };
|
14928 |
|
14929 | arc.cornerRadius = function(_) {
|
14930 | return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$b(+_), arc) : cornerRadius;
|
14931 | };
|
14932 |
|
14933 | arc.padRadius = function(_) {
|
14934 | return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), arc) : padRadius;
|
14935 | };
|
14936 |
|
14937 | arc.startAngle = function(_) {
|
14938 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : startAngle;
|
14939 | };
|
14940 |
|
14941 | arc.endAngle = function(_) {
|
14942 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : endAngle;
|
14943 | };
|
14944 |
|
14945 | arc.padAngle = function(_) {
|
14946 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), arc) : padAngle;
|
14947 | };
|
14948 |
|
14949 | arc.context = function(_) {
|
14950 | return arguments.length ? ((context = _ == null ? null : _), arc) : context;
|
14951 | };
|
14952 |
|
14953 | return arc;
|
14954 | }
|
14955 |
|
14956 | function Linear(context) {
|
14957 | this._context = context;
|
14958 | }
|
14959 |
|
14960 | Linear.prototype = {
|
14961 | areaStart: function() {
|
14962 | this._line = 0;
|
14963 | },
|
14964 | areaEnd: function() {
|
14965 | this._line = NaN;
|
14966 | },
|
14967 | lineStart: function() {
|
14968 | this._point = 0;
|
14969 | },
|
14970 | lineEnd: function() {
|
14971 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
14972 | this._line = 1 - this._line;
|
14973 | },
|
14974 | point: function(x, y) {
|
14975 | x = +x, y = +y;
|
14976 | switch (this._point) {
|
14977 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
14978 | case 1: this._point = 2; // proceed
|
14979 | default: this._context.lineTo(x, y); break;
|
14980 | }
|
14981 | }
|
14982 | };
|
14983 |
|
14984 | function curveLinear(context) {
|
14985 | return new Linear(context);
|
14986 | }
|
14987 |
|
14988 | function x$3(p) {
|
14989 | return p[0];
|
14990 | }
|
14991 |
|
14992 | function y$3(p) {
|
14993 | return p[1];
|
14994 | }
|
14995 |
|
14996 | function line() {
|
14997 | var x = x$3,
|
14998 | y = y$3,
|
14999 | defined = constant$b(true),
|
15000 | context = null,
|
15001 | curve = curveLinear,
|
15002 | output = null;
|
15003 |
|
15004 | function line(data) {
|
15005 | var i,
|
15006 | n = data.length,
|
15007 | d,
|
15008 | defined0 = false,
|
15009 | buffer;
|
15010 |
|
15011 | if (context == null) output = curve(buffer = path());
|
15012 |
|
15013 | for (i = 0; i <= n; ++i) {
|
15014 | if (!(i < n && defined(d = data[i], i, data)) === defined0) {
|
15015 | if (defined0 = !defined0) output.lineStart();
|
15016 | else output.lineEnd();
|
15017 | }
|
15018 | if (defined0) output.point(+x(d, i, data), +y(d, i, data));
|
15019 | }
|
15020 |
|
15021 | if (buffer) return output = null, buffer + "" || null;
|
15022 | }
|
15023 |
|
15024 | line.x = function(_) {
|
15025 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), line) : x;
|
15026 | };
|
15027 |
|
15028 | line.y = function(_) {
|
15029 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), line) : y;
|
15030 | };
|
15031 |
|
15032 | line.defined = function(_) {
|
15033 | return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), line) : defined;
|
15034 | };
|
15035 |
|
15036 | line.curve = function(_) {
|
15037 | return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve;
|
15038 | };
|
15039 |
|
15040 | line.context = function(_) {
|
15041 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context;
|
15042 | };
|
15043 |
|
15044 | return line;
|
15045 | }
|
15046 |
|
15047 | function area$3() {
|
15048 | var x0 = x$3,
|
15049 | x1 = null,
|
15050 | y0 = constant$b(0),
|
15051 | y1 = y$3,
|
15052 | defined = constant$b(true),
|
15053 | context = null,
|
15054 | curve = curveLinear,
|
15055 | output = null;
|
15056 |
|
15057 | function area(data) {
|
15058 | var i,
|
15059 | j,
|
15060 | k,
|
15061 | n = data.length,
|
15062 | d,
|
15063 | defined0 = false,
|
15064 | buffer,
|
15065 | x0z = new Array(n),
|
15066 | y0z = new Array(n);
|
15067 |
|
15068 | if (context == null) output = curve(buffer = path());
|
15069 |
|
15070 | for (i = 0; i <= n; ++i) {
|
15071 | if (!(i < n && defined(d = data[i], i, data)) === defined0) {
|
15072 | if (defined0 = !defined0) {
|
15073 | j = i;
|
15074 | output.areaStart();
|
15075 | output.lineStart();
|
15076 | } else {
|
15077 | output.lineEnd();
|
15078 | output.lineStart();
|
15079 | for (k = i - 1; k >= j; --k) {
|
15080 | output.point(x0z[k], y0z[k]);
|
15081 | }
|
15082 | output.lineEnd();
|
15083 | output.areaEnd();
|
15084 | }
|
15085 | }
|
15086 | if (defined0) {
|
15087 | x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data);
|
15088 | output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]);
|
15089 | }
|
15090 | }
|
15091 |
|
15092 | if (buffer) return output = null, buffer + "" || null;
|
15093 | }
|
15094 |
|
15095 | function arealine() {
|
15096 | return line().defined(defined).curve(curve).context(context);
|
15097 | }
|
15098 |
|
15099 | area.x = function(_) {
|
15100 | return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), x1 = null, area) : x0;
|
15101 | };
|
15102 |
|
15103 | area.x0 = function(_) {
|
15104 | return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$b(+_), area) : x0;
|
15105 | };
|
15106 |
|
15107 | area.x1 = function(_) {
|
15108 | return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : x1;
|
15109 | };
|
15110 |
|
15111 | area.y = function(_) {
|
15112 | return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), y1 = null, area) : y0;
|
15113 | };
|
15114 |
|
15115 | area.y0 = function(_) {
|
15116 | return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$b(+_), area) : y0;
|
15117 | };
|
15118 |
|
15119 | area.y1 = function(_) {
|
15120 | return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$b(+_), area) : y1;
|
15121 | };
|
15122 |
|
15123 | area.lineX0 =
|
15124 | area.lineY0 = function() {
|
15125 | return arealine().x(x0).y(y0);
|
15126 | };
|
15127 |
|
15128 | area.lineY1 = function() {
|
15129 | return arealine().x(x0).y(y1);
|
15130 | };
|
15131 |
|
15132 | area.lineX1 = function() {
|
15133 | return arealine().x(x1).y(y0);
|
15134 | };
|
15135 |
|
15136 | area.defined = function(_) {
|
15137 | return arguments.length ? (defined = typeof _ === "function" ? _ : constant$b(!!_), area) : defined;
|
15138 | };
|
15139 |
|
15140 | area.curve = function(_) {
|
15141 | return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve;
|
15142 | };
|
15143 |
|
15144 | area.context = function(_) {
|
15145 | return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context;
|
15146 | };
|
15147 |
|
15148 | return area;
|
15149 | }
|
15150 |
|
15151 | function descending$1(a, b) {
|
15152 | return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
15153 | }
|
15154 |
|
15155 | function identity$8(d) {
|
15156 | return d;
|
15157 | }
|
15158 |
|
15159 | function pie() {
|
15160 | var value = identity$8,
|
15161 | sortValues = descending$1,
|
15162 | sort = null,
|
15163 | startAngle = constant$b(0),
|
15164 | endAngle = constant$b(tau$4),
|
15165 | padAngle = constant$b(0);
|
15166 |
|
15167 | function pie(data) {
|
15168 | var i,
|
15169 | n = data.length,
|
15170 | j,
|
15171 | k,
|
15172 | sum = 0,
|
15173 | index = new Array(n),
|
15174 | arcs = new Array(n),
|
15175 | a0 = +startAngle.apply(this, arguments),
|
15176 | da = Math.min(tau$4, Math.max(-tau$4, endAngle.apply(this, arguments) - a0)),
|
15177 | a1,
|
15178 | p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)),
|
15179 | pa = p * (da < 0 ? -1 : 1),
|
15180 | v;
|
15181 |
|
15182 | for (i = 0; i < n; ++i) {
|
15183 | if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) {
|
15184 | sum += v;
|
15185 | }
|
15186 | }
|
15187 |
|
15188 | // Optionally sort the arcs by previously-computed values or by data.
|
15189 | if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); });
|
15190 | else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); });
|
15191 |
|
15192 | // Compute the arcs! They are stored in the original data's order.
|
15193 | for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) {
|
15194 | j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = {
|
15195 | data: data[j],
|
15196 | index: i,
|
15197 | value: v,
|
15198 | startAngle: a0,
|
15199 | endAngle: a1,
|
15200 | padAngle: p
|
15201 | };
|
15202 | }
|
15203 |
|
15204 | return arcs;
|
15205 | }
|
15206 |
|
15207 | pie.value = function(_) {
|
15208 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), pie) : value;
|
15209 | };
|
15210 |
|
15211 | pie.sortValues = function(_) {
|
15212 | return arguments.length ? (sortValues = _, sort = null, pie) : sortValues;
|
15213 | };
|
15214 |
|
15215 | pie.sort = function(_) {
|
15216 | return arguments.length ? (sort = _, sortValues = null, pie) : sort;
|
15217 | };
|
15218 |
|
15219 | pie.startAngle = function(_) {
|
15220 | return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : startAngle;
|
15221 | };
|
15222 |
|
15223 | pie.endAngle = function(_) {
|
15224 | return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : endAngle;
|
15225 | };
|
15226 |
|
15227 | pie.padAngle = function(_) {
|
15228 | return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$b(+_), pie) : padAngle;
|
15229 | };
|
15230 |
|
15231 | return pie;
|
15232 | }
|
15233 |
|
15234 | var curveRadialLinear = curveRadial(curveLinear);
|
15235 |
|
15236 | function Radial(curve) {
|
15237 | this._curve = curve;
|
15238 | }
|
15239 |
|
15240 | Radial.prototype = {
|
15241 | areaStart: function() {
|
15242 | this._curve.areaStart();
|
15243 | },
|
15244 | areaEnd: function() {
|
15245 | this._curve.areaEnd();
|
15246 | },
|
15247 | lineStart: function() {
|
15248 | this._curve.lineStart();
|
15249 | },
|
15250 | lineEnd: function() {
|
15251 | this._curve.lineEnd();
|
15252 | },
|
15253 | point: function(a, r) {
|
15254 | this._curve.point(r * Math.sin(a), r * -Math.cos(a));
|
15255 | }
|
15256 | };
|
15257 |
|
15258 | function curveRadial(curve) {
|
15259 |
|
15260 | function radial(context) {
|
15261 | return new Radial(curve(context));
|
15262 | }
|
15263 |
|
15264 | radial._curve = curve;
|
15265 |
|
15266 | return radial;
|
15267 | }
|
15268 |
|
15269 | function lineRadial(l) {
|
15270 | var c = l.curve;
|
15271 |
|
15272 | l.angle = l.x, delete l.x;
|
15273 | l.radius = l.y, delete l.y;
|
15274 |
|
15275 | l.curve = function(_) {
|
15276 | return arguments.length ? c(curveRadial(_)) : c()._curve;
|
15277 | };
|
15278 |
|
15279 | return l;
|
15280 | }
|
15281 |
|
15282 | function lineRadial$1() {
|
15283 | return lineRadial(line().curve(curveRadialLinear));
|
15284 | }
|
15285 |
|
15286 | function areaRadial() {
|
15287 | var a = area$3().curve(curveRadialLinear),
|
15288 | c = a.curve,
|
15289 | x0 = a.lineX0,
|
15290 | x1 = a.lineX1,
|
15291 | y0 = a.lineY0,
|
15292 | y1 = a.lineY1;
|
15293 |
|
15294 | a.angle = a.x, delete a.x;
|
15295 | a.startAngle = a.x0, delete a.x0;
|
15296 | a.endAngle = a.x1, delete a.x1;
|
15297 | a.radius = a.y, delete a.y;
|
15298 | a.innerRadius = a.y0, delete a.y0;
|
15299 | a.outerRadius = a.y1, delete a.y1;
|
15300 | a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0;
|
15301 | a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1;
|
15302 | a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0;
|
15303 | a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1;
|
15304 |
|
15305 | a.curve = function(_) {
|
15306 | return arguments.length ? c(curveRadial(_)) : c()._curve;
|
15307 | };
|
15308 |
|
15309 | return a;
|
15310 | }
|
15311 |
|
15312 | function pointRadial(x, y) {
|
15313 | return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)];
|
15314 | }
|
15315 |
|
15316 | var slice$6 = Array.prototype.slice;
|
15317 |
|
15318 | function linkSource(d) {
|
15319 | return d.source;
|
15320 | }
|
15321 |
|
15322 | function linkTarget(d) {
|
15323 | return d.target;
|
15324 | }
|
15325 |
|
15326 | function link$2(curve) {
|
15327 | var source = linkSource,
|
15328 | target = linkTarget,
|
15329 | x = x$3,
|
15330 | y = y$3,
|
15331 | context = null;
|
15332 |
|
15333 | function link() {
|
15334 | var buffer, argv = slice$6.call(arguments), s = source.apply(this, argv), t = target.apply(this, argv);
|
15335 | if (!context) context = buffer = path();
|
15336 | curve(context, +x.apply(this, (argv[0] = s, argv)), +y.apply(this, argv), +x.apply(this, (argv[0] = t, argv)), +y.apply(this, argv));
|
15337 | if (buffer) return context = null, buffer + "" || null;
|
15338 | }
|
15339 |
|
15340 | link.source = function(_) {
|
15341 | return arguments.length ? (source = _, link) : source;
|
15342 | };
|
15343 |
|
15344 | link.target = function(_) {
|
15345 | return arguments.length ? (target = _, link) : target;
|
15346 | };
|
15347 |
|
15348 | link.x = function(_) {
|
15349 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$b(+_), link) : x;
|
15350 | };
|
15351 |
|
15352 | link.y = function(_) {
|
15353 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$b(+_), link) : y;
|
15354 | };
|
15355 |
|
15356 | link.context = function(_) {
|
15357 | return arguments.length ? ((context = _ == null ? null : _), link) : context;
|
15358 | };
|
15359 |
|
15360 | return link;
|
15361 | }
|
15362 |
|
15363 | function curveHorizontal(context, x0, y0, x1, y1) {
|
15364 | context.moveTo(x0, y0);
|
15365 | context.bezierCurveTo(x0 = (x0 + x1) / 2, y0, x0, y1, x1, y1);
|
15366 | }
|
15367 |
|
15368 | function curveVertical(context, x0, y0, x1, y1) {
|
15369 | context.moveTo(x0, y0);
|
15370 | context.bezierCurveTo(x0, y0 = (y0 + y1) / 2, x1, y0, x1, y1);
|
15371 | }
|
15372 |
|
15373 | function curveRadial$1(context, x0, y0, x1, y1) {
|
15374 | var p0 = pointRadial(x0, y0),
|
15375 | p1 = pointRadial(x0, y0 = (y0 + y1) / 2),
|
15376 | p2 = pointRadial(x1, y0),
|
15377 | p3 = pointRadial(x1, y1);
|
15378 | context.moveTo(p0[0], p0[1]);
|
15379 | context.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
|
15380 | }
|
15381 |
|
15382 | function linkHorizontal() {
|
15383 | return link$2(curveHorizontal);
|
15384 | }
|
15385 |
|
15386 | function linkVertical() {
|
15387 | return link$2(curveVertical);
|
15388 | }
|
15389 |
|
15390 | function linkRadial() {
|
15391 | var l = link$2(curveRadial$1);
|
15392 | l.angle = l.x, delete l.x;
|
15393 | l.radius = l.y, delete l.y;
|
15394 | return l;
|
15395 | }
|
15396 |
|
15397 | var circle$2 = {
|
15398 | draw: function(context, size) {
|
15399 | var r = Math.sqrt(size / pi$4);
|
15400 | context.moveTo(r, 0);
|
15401 | context.arc(0, 0, r, 0, tau$4);
|
15402 | }
|
15403 | };
|
15404 |
|
15405 | var cross$2 = {
|
15406 | draw: function(context, size) {
|
15407 | var r = Math.sqrt(size / 5) / 2;
|
15408 | context.moveTo(-3 * r, -r);
|
15409 | context.lineTo(-r, -r);
|
15410 | context.lineTo(-r, -3 * r);
|
15411 | context.lineTo(r, -3 * r);
|
15412 | context.lineTo(r, -r);
|
15413 | context.lineTo(3 * r, -r);
|
15414 | context.lineTo(3 * r, r);
|
15415 | context.lineTo(r, r);
|
15416 | context.lineTo(r, 3 * r);
|
15417 | context.lineTo(-r, 3 * r);
|
15418 | context.lineTo(-r, r);
|
15419 | context.lineTo(-3 * r, r);
|
15420 | context.closePath();
|
15421 | }
|
15422 | };
|
15423 |
|
15424 | var tan30 = Math.sqrt(1 / 3),
|
15425 | tan30_2 = tan30 * 2;
|
15426 |
|
15427 | var diamond = {
|
15428 | draw: function(context, size) {
|
15429 | var y = Math.sqrt(size / tan30_2),
|
15430 | x = y * tan30;
|
15431 | context.moveTo(0, -y);
|
15432 | context.lineTo(x, 0);
|
15433 | context.lineTo(0, y);
|
15434 | context.lineTo(-x, 0);
|
15435 | context.closePath();
|
15436 | }
|
15437 | };
|
15438 |
|
15439 | var ka = 0.89081309152928522810,
|
15440 | kr = Math.sin(pi$4 / 10) / Math.sin(7 * pi$4 / 10),
|
15441 | kx = Math.sin(tau$4 / 10) * kr,
|
15442 | ky = -Math.cos(tau$4 / 10) * kr;
|
15443 |
|
15444 | var star = {
|
15445 | draw: function(context, size) {
|
15446 | var r = Math.sqrt(size * ka),
|
15447 | x = kx * r,
|
15448 | y = ky * r;
|
15449 | context.moveTo(0, -r);
|
15450 | context.lineTo(x, y);
|
15451 | for (var i = 1; i < 5; ++i) {
|
15452 | var a = tau$4 * i / 5,
|
15453 | c = Math.cos(a),
|
15454 | s = Math.sin(a);
|
15455 | context.lineTo(s * r, -c * r);
|
15456 | context.lineTo(c * x - s * y, s * x + c * y);
|
15457 | }
|
15458 | context.closePath();
|
15459 | }
|
15460 | };
|
15461 |
|
15462 | var square = {
|
15463 | draw: function(context, size) {
|
15464 | var w = Math.sqrt(size),
|
15465 | x = -w / 2;
|
15466 | context.rect(x, x, w, w);
|
15467 | }
|
15468 | };
|
15469 |
|
15470 | var sqrt3 = Math.sqrt(3);
|
15471 |
|
15472 | var triangle = {
|
15473 | draw: function(context, size) {
|
15474 | var y = -Math.sqrt(size / (sqrt3 * 3));
|
15475 | context.moveTo(0, y * 2);
|
15476 | context.lineTo(-sqrt3 * y, -y);
|
15477 | context.lineTo(sqrt3 * y, -y);
|
15478 | context.closePath();
|
15479 | }
|
15480 | };
|
15481 |
|
15482 | var c$2 = -0.5,
|
15483 | s = Math.sqrt(3) / 2,
|
15484 | k = 1 / Math.sqrt(12),
|
15485 | a = (k / 2 + 1) * 3;
|
15486 |
|
15487 | var wye = {
|
15488 | draw: function(context, size) {
|
15489 | var r = Math.sqrt(size / a),
|
15490 | x0 = r / 2,
|
15491 | y0 = r * k,
|
15492 | x1 = x0,
|
15493 | y1 = r * k + r,
|
15494 | x2 = -x1,
|
15495 | y2 = y1;
|
15496 | context.moveTo(x0, y0);
|
15497 | context.lineTo(x1, y1);
|
15498 | context.lineTo(x2, y2);
|
15499 | context.lineTo(c$2 * x0 - s * y0, s * x0 + c$2 * y0);
|
15500 | context.lineTo(c$2 * x1 - s * y1, s * x1 + c$2 * y1);
|
15501 | context.lineTo(c$2 * x2 - s * y2, s * x2 + c$2 * y2);
|
15502 | context.lineTo(c$2 * x0 + s * y0, c$2 * y0 - s * x0);
|
15503 | context.lineTo(c$2 * x1 + s * y1, c$2 * y1 - s * x1);
|
15504 | context.lineTo(c$2 * x2 + s * y2, c$2 * y2 - s * x2);
|
15505 | context.closePath();
|
15506 | }
|
15507 | };
|
15508 |
|
15509 | var symbols = [
|
15510 | circle$2,
|
15511 | cross$2,
|
15512 | diamond,
|
15513 | square,
|
15514 | star,
|
15515 | triangle,
|
15516 | wye
|
15517 | ];
|
15518 |
|
15519 | function symbol() {
|
15520 | var type = constant$b(circle$2),
|
15521 | size = constant$b(64),
|
15522 | context = null;
|
15523 |
|
15524 | function symbol() {
|
15525 | var buffer;
|
15526 | if (!context) context = buffer = path();
|
15527 | type.apply(this, arguments).draw(context, +size.apply(this, arguments));
|
15528 | if (buffer) return context = null, buffer + "" || null;
|
15529 | }
|
15530 |
|
15531 | symbol.type = function(_) {
|
15532 | return arguments.length ? (type = typeof _ === "function" ? _ : constant$b(_), symbol) : type;
|
15533 | };
|
15534 |
|
15535 | symbol.size = function(_) {
|
15536 | return arguments.length ? (size = typeof _ === "function" ? _ : constant$b(+_), symbol) : size;
|
15537 | };
|
15538 |
|
15539 | symbol.context = function(_) {
|
15540 | return arguments.length ? (context = _ == null ? null : _, symbol) : context;
|
15541 | };
|
15542 |
|
15543 | return symbol;
|
15544 | }
|
15545 |
|
15546 | function noop$3() {}
|
15547 |
|
15548 | function point$2(that, x, y) {
|
15549 | that._context.bezierCurveTo(
|
15550 | (2 * that._x0 + that._x1) / 3,
|
15551 | (2 * that._y0 + that._y1) / 3,
|
15552 | (that._x0 + 2 * that._x1) / 3,
|
15553 | (that._y0 + 2 * that._y1) / 3,
|
15554 | (that._x0 + 4 * that._x1 + x) / 6,
|
15555 | (that._y0 + 4 * that._y1 + y) / 6
|
15556 | );
|
15557 | }
|
15558 |
|
15559 | function Basis(context) {
|
15560 | this._context = context;
|
15561 | }
|
15562 |
|
15563 | Basis.prototype = {
|
15564 | areaStart: function() {
|
15565 | this._line = 0;
|
15566 | },
|
15567 | areaEnd: function() {
|
15568 | this._line = NaN;
|
15569 | },
|
15570 | lineStart: function() {
|
15571 | this._x0 = this._x1 =
|
15572 | this._y0 = this._y1 = NaN;
|
15573 | this._point = 0;
|
15574 | },
|
15575 | lineEnd: function() {
|
15576 | switch (this._point) {
|
15577 | case 3: point$2(this, this._x1, this._y1); // proceed
|
15578 | case 2: this._context.lineTo(this._x1, this._y1); break;
|
15579 | }
|
15580 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
15581 | this._line = 1 - this._line;
|
15582 | },
|
15583 | point: function(x, y) {
|
15584 | x = +x, y = +y;
|
15585 | switch (this._point) {
|
15586 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
15587 | case 1: this._point = 2; break;
|
15588 | case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // proceed
|
15589 | default: point$2(this, x, y); break;
|
15590 | }
|
15591 | this._x0 = this._x1, this._x1 = x;
|
15592 | this._y0 = this._y1, this._y1 = y;
|
15593 | }
|
15594 | };
|
15595 |
|
15596 | function basis$2(context) {
|
15597 | return new Basis(context);
|
15598 | }
|
15599 |
|
15600 | function BasisClosed(context) {
|
15601 | this._context = context;
|
15602 | }
|
15603 |
|
15604 | BasisClosed.prototype = {
|
15605 | areaStart: noop$3,
|
15606 | areaEnd: noop$3,
|
15607 | lineStart: function() {
|
15608 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 =
|
15609 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN;
|
15610 | this._point = 0;
|
15611 | },
|
15612 | lineEnd: function() {
|
15613 | switch (this._point) {
|
15614 | case 1: {
|
15615 | this._context.moveTo(this._x2, this._y2);
|
15616 | this._context.closePath();
|
15617 | break;
|
15618 | }
|
15619 | case 2: {
|
15620 | this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3);
|
15621 | this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3);
|
15622 | this._context.closePath();
|
15623 | break;
|
15624 | }
|
15625 | case 3: {
|
15626 | this.point(this._x2, this._y2);
|
15627 | this.point(this._x3, this._y3);
|
15628 | this.point(this._x4, this._y4);
|
15629 | break;
|
15630 | }
|
15631 | }
|
15632 | },
|
15633 | point: function(x, y) {
|
15634 | x = +x, y = +y;
|
15635 | switch (this._point) {
|
15636 | case 0: this._point = 1; this._x2 = x, this._y2 = y; break;
|
15637 | case 1: this._point = 2; this._x3 = x, this._y3 = y; break;
|
15638 | 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;
|
15639 | default: point$2(this, x, y); break;
|
15640 | }
|
15641 | this._x0 = this._x1, this._x1 = x;
|
15642 | this._y0 = this._y1, this._y1 = y;
|
15643 | }
|
15644 | };
|
15645 |
|
15646 | function basisClosed$1(context) {
|
15647 | return new BasisClosed(context);
|
15648 | }
|
15649 |
|
15650 | function BasisOpen(context) {
|
15651 | this._context = context;
|
15652 | }
|
15653 |
|
15654 | BasisOpen.prototype = {
|
15655 | areaStart: function() {
|
15656 | this._line = 0;
|
15657 | },
|
15658 | areaEnd: function() {
|
15659 | this._line = NaN;
|
15660 | },
|
15661 | lineStart: function() {
|
15662 | this._x0 = this._x1 =
|
15663 | this._y0 = this._y1 = NaN;
|
15664 | this._point = 0;
|
15665 | },
|
15666 | lineEnd: function() {
|
15667 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
15668 | this._line = 1 - this._line;
|
15669 | },
|
15670 | point: function(x, y) {
|
15671 | x = +x, y = +y;
|
15672 | switch (this._point) {
|
15673 | case 0: this._point = 1; break;
|
15674 | case 1: this._point = 2; break;
|
15675 | 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;
|
15676 | case 3: this._point = 4; // proceed
|
15677 | default: point$2(this, x, y); break;
|
15678 | }
|
15679 | this._x0 = this._x1, this._x1 = x;
|
15680 | this._y0 = this._y1, this._y1 = y;
|
15681 | }
|
15682 | };
|
15683 |
|
15684 | function basisOpen(context) {
|
15685 | return new BasisOpen(context);
|
15686 | }
|
15687 |
|
15688 | function Bundle(context, beta) {
|
15689 | this._basis = new Basis(context);
|
15690 | this._beta = beta;
|
15691 | }
|
15692 |
|
15693 | Bundle.prototype = {
|
15694 | lineStart: function() {
|
15695 | this._x = [];
|
15696 | this._y = [];
|
15697 | this._basis.lineStart();
|
15698 | },
|
15699 | lineEnd: function() {
|
15700 | var x = this._x,
|
15701 | y = this._y,
|
15702 | j = x.length - 1;
|
15703 |
|
15704 | if (j > 0) {
|
15705 | var x0 = x[0],
|
15706 | y0 = y[0],
|
15707 | dx = x[j] - x0,
|
15708 | dy = y[j] - y0,
|
15709 | i = -1,
|
15710 | t;
|
15711 |
|
15712 | while (++i <= j) {
|
15713 | t = i / j;
|
15714 | this._basis.point(
|
15715 | this._beta * x[i] + (1 - this._beta) * (x0 + t * dx),
|
15716 | this._beta * y[i] + (1 - this._beta) * (y0 + t * dy)
|
15717 | );
|
15718 | }
|
15719 | }
|
15720 |
|
15721 | this._x = this._y = null;
|
15722 | this._basis.lineEnd();
|
15723 | },
|
15724 | point: function(x, y) {
|
15725 | this._x.push(+x);
|
15726 | this._y.push(+y);
|
15727 | }
|
15728 | };
|
15729 |
|
15730 | var bundle = (function custom(beta) {
|
15731 |
|
15732 | function bundle(context) {
|
15733 | return beta === 1 ? new Basis(context) : new Bundle(context, beta);
|
15734 | }
|
15735 |
|
15736 | bundle.beta = function(beta) {
|
15737 | return custom(+beta);
|
15738 | };
|
15739 |
|
15740 | return bundle;
|
15741 | })(0.85);
|
15742 |
|
15743 | function point$3(that, x, y) {
|
15744 | that._context.bezierCurveTo(
|
15745 | that._x1 + that._k * (that._x2 - that._x0),
|
15746 | that._y1 + that._k * (that._y2 - that._y0),
|
15747 | that._x2 + that._k * (that._x1 - x),
|
15748 | that._y2 + that._k * (that._y1 - y),
|
15749 | that._x2,
|
15750 | that._y2
|
15751 | );
|
15752 | }
|
15753 |
|
15754 | function Cardinal(context, tension) {
|
15755 | this._context = context;
|
15756 | this._k = (1 - tension) / 6;
|
15757 | }
|
15758 |
|
15759 | Cardinal.prototype = {
|
15760 | areaStart: function() {
|
15761 | this._line = 0;
|
15762 | },
|
15763 | areaEnd: function() {
|
15764 | this._line = NaN;
|
15765 | },
|
15766 | lineStart: function() {
|
15767 | this._x0 = this._x1 = this._x2 =
|
15768 | this._y0 = this._y1 = this._y2 = NaN;
|
15769 | this._point = 0;
|
15770 | },
|
15771 | lineEnd: function() {
|
15772 | switch (this._point) {
|
15773 | case 2: this._context.lineTo(this._x2, this._y2); break;
|
15774 | case 3: point$3(this, this._x1, this._y1); break;
|
15775 | }
|
15776 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
15777 | this._line = 1 - this._line;
|
15778 | },
|
15779 | point: function(x, y) {
|
15780 | x = +x, y = +y;
|
15781 | switch (this._point) {
|
15782 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
15783 | case 1: this._point = 2; this._x1 = x, this._y1 = y; break;
|
15784 | case 2: this._point = 3; // proceed
|
15785 | default: point$3(this, x, y); break;
|
15786 | }
|
15787 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
15788 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
15789 | }
|
15790 | };
|
15791 |
|
15792 | var cardinal = (function custom(tension) {
|
15793 |
|
15794 | function cardinal(context) {
|
15795 | return new Cardinal(context, tension);
|
15796 | }
|
15797 |
|
15798 | cardinal.tension = function(tension) {
|
15799 | return custom(+tension);
|
15800 | };
|
15801 |
|
15802 | return cardinal;
|
15803 | })(0);
|
15804 |
|
15805 | function CardinalClosed(context, tension) {
|
15806 | this._context = context;
|
15807 | this._k = (1 - tension) / 6;
|
15808 | }
|
15809 |
|
15810 | CardinalClosed.prototype = {
|
15811 | areaStart: noop$3,
|
15812 | areaEnd: noop$3,
|
15813 | lineStart: function() {
|
15814 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
|
15815 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
|
15816 | this._point = 0;
|
15817 | },
|
15818 | lineEnd: function() {
|
15819 | switch (this._point) {
|
15820 | case 1: {
|
15821 | this._context.moveTo(this._x3, this._y3);
|
15822 | this._context.closePath();
|
15823 | break;
|
15824 | }
|
15825 | case 2: {
|
15826 | this._context.lineTo(this._x3, this._y3);
|
15827 | this._context.closePath();
|
15828 | break;
|
15829 | }
|
15830 | case 3: {
|
15831 | this.point(this._x3, this._y3);
|
15832 | this.point(this._x4, this._y4);
|
15833 | this.point(this._x5, this._y5);
|
15834 | break;
|
15835 | }
|
15836 | }
|
15837 | },
|
15838 | point: function(x, y) {
|
15839 | x = +x, y = +y;
|
15840 | switch (this._point) {
|
15841 | case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
|
15842 | case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
|
15843 | case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
|
15844 | default: point$3(this, x, y); break;
|
15845 | }
|
15846 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
15847 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
15848 | }
|
15849 | };
|
15850 |
|
15851 | var cardinalClosed = (function custom(tension) {
|
15852 |
|
15853 | function cardinal(context) {
|
15854 | return new CardinalClosed(context, tension);
|
15855 | }
|
15856 |
|
15857 | cardinal.tension = function(tension) {
|
15858 | return custom(+tension);
|
15859 | };
|
15860 |
|
15861 | return cardinal;
|
15862 | })(0);
|
15863 |
|
15864 | function CardinalOpen(context, tension) {
|
15865 | this._context = context;
|
15866 | this._k = (1 - tension) / 6;
|
15867 | }
|
15868 |
|
15869 | CardinalOpen.prototype = {
|
15870 | areaStart: function() {
|
15871 | this._line = 0;
|
15872 | },
|
15873 | areaEnd: function() {
|
15874 | this._line = NaN;
|
15875 | },
|
15876 | lineStart: function() {
|
15877 | this._x0 = this._x1 = this._x2 =
|
15878 | this._y0 = this._y1 = this._y2 = NaN;
|
15879 | this._point = 0;
|
15880 | },
|
15881 | lineEnd: function() {
|
15882 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
15883 | this._line = 1 - this._line;
|
15884 | },
|
15885 | point: function(x, y) {
|
15886 | x = +x, y = +y;
|
15887 | switch (this._point) {
|
15888 | case 0: this._point = 1; break;
|
15889 | case 1: this._point = 2; break;
|
15890 | case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
|
15891 | case 3: this._point = 4; // proceed
|
15892 | default: point$3(this, x, y); break;
|
15893 | }
|
15894 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
15895 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
15896 | }
|
15897 | };
|
15898 |
|
15899 | var cardinalOpen = (function custom(tension) {
|
15900 |
|
15901 | function cardinal(context) {
|
15902 | return new CardinalOpen(context, tension);
|
15903 | }
|
15904 |
|
15905 | cardinal.tension = function(tension) {
|
15906 | return custom(+tension);
|
15907 | };
|
15908 |
|
15909 | return cardinal;
|
15910 | })(0);
|
15911 |
|
15912 | function point$4(that, x, y) {
|
15913 | var x1 = that._x1,
|
15914 | y1 = that._y1,
|
15915 | x2 = that._x2,
|
15916 | y2 = that._y2;
|
15917 |
|
15918 | if (that._l01_a > epsilon$3) {
|
15919 | var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a,
|
15920 | n = 3 * that._l01_a * (that._l01_a + that._l12_a);
|
15921 | x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n;
|
15922 | y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n;
|
15923 | }
|
15924 |
|
15925 | if (that._l23_a > epsilon$3) {
|
15926 | var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a,
|
15927 | m = 3 * that._l23_a * (that._l23_a + that._l12_a);
|
15928 | x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m;
|
15929 | y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m;
|
15930 | }
|
15931 |
|
15932 | that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2);
|
15933 | }
|
15934 |
|
15935 | function CatmullRom(context, alpha) {
|
15936 | this._context = context;
|
15937 | this._alpha = alpha;
|
15938 | }
|
15939 |
|
15940 | CatmullRom.prototype = {
|
15941 | areaStart: function() {
|
15942 | this._line = 0;
|
15943 | },
|
15944 | areaEnd: function() {
|
15945 | this._line = NaN;
|
15946 | },
|
15947 | lineStart: function() {
|
15948 | this._x0 = this._x1 = this._x2 =
|
15949 | this._y0 = this._y1 = this._y2 = NaN;
|
15950 | this._l01_a = this._l12_a = this._l23_a =
|
15951 | this._l01_2a = this._l12_2a = this._l23_2a =
|
15952 | this._point = 0;
|
15953 | },
|
15954 | lineEnd: function() {
|
15955 | switch (this._point) {
|
15956 | case 2: this._context.lineTo(this._x2, this._y2); break;
|
15957 | case 3: this.point(this._x2, this._y2); break;
|
15958 | }
|
15959 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
15960 | this._line = 1 - this._line;
|
15961 | },
|
15962 | point: function(x, y) {
|
15963 | x = +x, y = +y;
|
15964 |
|
15965 | if (this._point) {
|
15966 | var x23 = this._x2 - x,
|
15967 | y23 = this._y2 - y;
|
15968 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
15969 | }
|
15970 |
|
15971 | switch (this._point) {
|
15972 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
15973 | case 1: this._point = 2; break;
|
15974 | case 2: this._point = 3; // proceed
|
15975 | default: point$4(this, x, y); break;
|
15976 | }
|
15977 |
|
15978 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
15979 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
15980 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
15981 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
15982 | }
|
15983 | };
|
15984 |
|
15985 | var catmullRom = (function custom(alpha) {
|
15986 |
|
15987 | function catmullRom(context) {
|
15988 | return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0);
|
15989 | }
|
15990 |
|
15991 | catmullRom.alpha = function(alpha) {
|
15992 | return custom(+alpha);
|
15993 | };
|
15994 |
|
15995 | return catmullRom;
|
15996 | })(0.5);
|
15997 |
|
15998 | function CatmullRomClosed(context, alpha) {
|
15999 | this._context = context;
|
16000 | this._alpha = alpha;
|
16001 | }
|
16002 |
|
16003 | CatmullRomClosed.prototype = {
|
16004 | areaStart: noop$3,
|
16005 | areaEnd: noop$3,
|
16006 | lineStart: function() {
|
16007 | this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 =
|
16008 | this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN;
|
16009 | this._l01_a = this._l12_a = this._l23_a =
|
16010 | this._l01_2a = this._l12_2a = this._l23_2a =
|
16011 | this._point = 0;
|
16012 | },
|
16013 | lineEnd: function() {
|
16014 | switch (this._point) {
|
16015 | case 1: {
|
16016 | this._context.moveTo(this._x3, this._y3);
|
16017 | this._context.closePath();
|
16018 | break;
|
16019 | }
|
16020 | case 2: {
|
16021 | this._context.lineTo(this._x3, this._y3);
|
16022 | this._context.closePath();
|
16023 | break;
|
16024 | }
|
16025 | case 3: {
|
16026 | this.point(this._x3, this._y3);
|
16027 | this.point(this._x4, this._y4);
|
16028 | this.point(this._x5, this._y5);
|
16029 | break;
|
16030 | }
|
16031 | }
|
16032 | },
|
16033 | point: function(x, y) {
|
16034 | x = +x, y = +y;
|
16035 |
|
16036 | if (this._point) {
|
16037 | var x23 = this._x2 - x,
|
16038 | y23 = this._y2 - y;
|
16039 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
16040 | }
|
16041 |
|
16042 | switch (this._point) {
|
16043 | case 0: this._point = 1; this._x3 = x, this._y3 = y; break;
|
16044 | case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break;
|
16045 | case 2: this._point = 3; this._x5 = x, this._y5 = y; break;
|
16046 | default: point$4(this, x, y); break;
|
16047 | }
|
16048 |
|
16049 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
16050 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
16051 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
16052 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
16053 | }
|
16054 | };
|
16055 |
|
16056 | var catmullRomClosed = (function custom(alpha) {
|
16057 |
|
16058 | function catmullRom(context) {
|
16059 | return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0);
|
16060 | }
|
16061 |
|
16062 | catmullRom.alpha = function(alpha) {
|
16063 | return custom(+alpha);
|
16064 | };
|
16065 |
|
16066 | return catmullRom;
|
16067 | })(0.5);
|
16068 |
|
16069 | function CatmullRomOpen(context, alpha) {
|
16070 | this._context = context;
|
16071 | this._alpha = alpha;
|
16072 | }
|
16073 |
|
16074 | CatmullRomOpen.prototype = {
|
16075 | areaStart: function() {
|
16076 | this._line = 0;
|
16077 | },
|
16078 | areaEnd: function() {
|
16079 | this._line = NaN;
|
16080 | },
|
16081 | lineStart: function() {
|
16082 | this._x0 = this._x1 = this._x2 =
|
16083 | this._y0 = this._y1 = this._y2 = NaN;
|
16084 | this._l01_a = this._l12_a = this._l23_a =
|
16085 | this._l01_2a = this._l12_2a = this._l23_2a =
|
16086 | this._point = 0;
|
16087 | },
|
16088 | lineEnd: function() {
|
16089 | if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath();
|
16090 | this._line = 1 - this._line;
|
16091 | },
|
16092 | point: function(x, y) {
|
16093 | x = +x, y = +y;
|
16094 |
|
16095 | if (this._point) {
|
16096 | var x23 = this._x2 - x,
|
16097 | y23 = this._y2 - y;
|
16098 | this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha));
|
16099 | }
|
16100 |
|
16101 | switch (this._point) {
|
16102 | case 0: this._point = 1; break;
|
16103 | case 1: this._point = 2; break;
|
16104 | case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break;
|
16105 | case 3: this._point = 4; // proceed
|
16106 | default: point$4(this, x, y); break;
|
16107 | }
|
16108 |
|
16109 | this._l01_a = this._l12_a, this._l12_a = this._l23_a;
|
16110 | this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a;
|
16111 | this._x0 = this._x1, this._x1 = this._x2, this._x2 = x;
|
16112 | this._y0 = this._y1, this._y1 = this._y2, this._y2 = y;
|
16113 | }
|
16114 | };
|
16115 |
|
16116 | var catmullRomOpen = (function custom(alpha) {
|
16117 |
|
16118 | function catmullRom(context) {
|
16119 | return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0);
|
16120 | }
|
16121 |
|
16122 | catmullRom.alpha = function(alpha) {
|
16123 | return custom(+alpha);
|
16124 | };
|
16125 |
|
16126 | return catmullRom;
|
16127 | })(0.5);
|
16128 |
|
16129 | function LinearClosed(context) {
|
16130 | this._context = context;
|
16131 | }
|
16132 |
|
16133 | LinearClosed.prototype = {
|
16134 | areaStart: noop$3,
|
16135 | areaEnd: noop$3,
|
16136 | lineStart: function() {
|
16137 | this._point = 0;
|
16138 | },
|
16139 | lineEnd: function() {
|
16140 | if (this._point) this._context.closePath();
|
16141 | },
|
16142 | point: function(x, y) {
|
16143 | x = +x, y = +y;
|
16144 | if (this._point) this._context.lineTo(x, y);
|
16145 | else this._point = 1, this._context.moveTo(x, y);
|
16146 | }
|
16147 | };
|
16148 |
|
16149 | function linearClosed(context) {
|
16150 | return new LinearClosed(context);
|
16151 | }
|
16152 |
|
16153 | function sign$1(x) {
|
16154 | return x < 0 ? -1 : 1;
|
16155 | }
|
16156 |
|
16157 | // Calculate the slopes of the tangents (Hermite-type interpolation) based on
|
16158 | // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
|
16159 | // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
|
16160 | // NOV(II), P. 443, 1990.
|
16161 | function slope3(that, x2, y2) {
|
16162 | var h0 = that._x1 - that._x0,
|
16163 | h1 = x2 - that._x1,
|
16164 | s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
|
16165 | s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
|
16166 | p = (s0 * h1 + s1 * h0) / (h0 + h1);
|
16167 | return (sign$1(s0) + sign$1(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
|
16168 | }
|
16169 |
|
16170 | // Calculate a one-sided slope.
|
16171 | function slope2(that, t) {
|
16172 | var h = that._x1 - that._x0;
|
16173 | return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
|
16174 | }
|
16175 |
|
16176 | // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
|
16177 | // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
|
16178 | // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
|
16179 | function point$5(that, t0, t1) {
|
16180 | var x0 = that._x0,
|
16181 | y0 = that._y0,
|
16182 | x1 = that._x1,
|
16183 | y1 = that._y1,
|
16184 | dx = (x1 - x0) / 3;
|
16185 | that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
|
16186 | }
|
16187 |
|
16188 | function MonotoneX(context) {
|
16189 | this._context = context;
|
16190 | }
|
16191 |
|
16192 | MonotoneX.prototype = {
|
16193 | areaStart: function() {
|
16194 | this._line = 0;
|
16195 | },
|
16196 | areaEnd: function() {
|
16197 | this._line = NaN;
|
16198 | },
|
16199 | lineStart: function() {
|
16200 | this._x0 = this._x1 =
|
16201 | this._y0 = this._y1 =
|
16202 | this._t0 = NaN;
|
16203 | this._point = 0;
|
16204 | },
|
16205 | lineEnd: function() {
|
16206 | switch (this._point) {
|
16207 | case 2: this._context.lineTo(this._x1, this._y1); break;
|
16208 | case 3: point$5(this, this._t0, slope2(this, this._t0)); break;
|
16209 | }
|
16210 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
16211 | this._line = 1 - this._line;
|
16212 | },
|
16213 | point: function(x, y) {
|
16214 | var t1 = NaN;
|
16215 |
|
16216 | x = +x, y = +y;
|
16217 | if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
|
16218 | switch (this._point) {
|
16219 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
16220 | case 1: this._point = 2; break;
|
16221 | case 2: this._point = 3; point$5(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
|
16222 | default: point$5(this, this._t0, t1 = slope3(this, x, y)); break;
|
16223 | }
|
16224 |
|
16225 | this._x0 = this._x1, this._x1 = x;
|
16226 | this._y0 = this._y1, this._y1 = y;
|
16227 | this._t0 = t1;
|
16228 | }
|
16229 | };
|
16230 |
|
16231 | function MonotoneY(context) {
|
16232 | this._context = new ReflectContext(context);
|
16233 | }
|
16234 |
|
16235 | (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
|
16236 | MonotoneX.prototype.point.call(this, y, x);
|
16237 | };
|
16238 |
|
16239 | function ReflectContext(context) {
|
16240 | this._context = context;
|
16241 | }
|
16242 |
|
16243 | ReflectContext.prototype = {
|
16244 | moveTo: function(x, y) { this._context.moveTo(y, x); },
|
16245 | closePath: function() { this._context.closePath(); },
|
16246 | lineTo: function(x, y) { this._context.lineTo(y, x); },
|
16247 | bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
|
16248 | };
|
16249 |
|
16250 | function monotoneX(context) {
|
16251 | return new MonotoneX(context);
|
16252 | }
|
16253 |
|
16254 | function monotoneY(context) {
|
16255 | return new MonotoneY(context);
|
16256 | }
|
16257 |
|
16258 | function Natural(context) {
|
16259 | this._context = context;
|
16260 | }
|
16261 |
|
16262 | Natural.prototype = {
|
16263 | areaStart: function() {
|
16264 | this._line = 0;
|
16265 | },
|
16266 | areaEnd: function() {
|
16267 | this._line = NaN;
|
16268 | },
|
16269 | lineStart: function() {
|
16270 | this._x = [];
|
16271 | this._y = [];
|
16272 | },
|
16273 | lineEnd: function() {
|
16274 | var x = this._x,
|
16275 | y = this._y,
|
16276 | n = x.length;
|
16277 |
|
16278 | if (n) {
|
16279 | this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]);
|
16280 | if (n === 2) {
|
16281 | this._context.lineTo(x[1], y[1]);
|
16282 | } else {
|
16283 | var px = controlPoints(x),
|
16284 | py = controlPoints(y);
|
16285 | for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) {
|
16286 | this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]);
|
16287 | }
|
16288 | }
|
16289 | }
|
16290 |
|
16291 | if (this._line || (this._line !== 0 && n === 1)) this._context.closePath();
|
16292 | this._line = 1 - this._line;
|
16293 | this._x = this._y = null;
|
16294 | },
|
16295 | point: function(x, y) {
|
16296 | this._x.push(+x);
|
16297 | this._y.push(+y);
|
16298 | }
|
16299 | };
|
16300 |
|
16301 | // See https://www.particleincell.com/2012/bezier-splines/ for derivation.
|
16302 | function controlPoints(x) {
|
16303 | var i,
|
16304 | n = x.length - 1,
|
16305 | m,
|
16306 | a = new Array(n),
|
16307 | b = new Array(n),
|
16308 | r = new Array(n);
|
16309 | a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1];
|
16310 | for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1];
|
16311 | a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n];
|
16312 | for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1];
|
16313 | a[n - 1] = r[n - 1] / b[n - 1];
|
16314 | for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i];
|
16315 | b[n - 1] = (x[n] + a[n - 1]) / 2;
|
16316 | for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1];
|
16317 | return [a, b];
|
16318 | }
|
16319 |
|
16320 | function natural(context) {
|
16321 | return new Natural(context);
|
16322 | }
|
16323 |
|
16324 | function Step(context, t) {
|
16325 | this._context = context;
|
16326 | this._t = t;
|
16327 | }
|
16328 |
|
16329 | Step.prototype = {
|
16330 | areaStart: function() {
|
16331 | this._line = 0;
|
16332 | },
|
16333 | areaEnd: function() {
|
16334 | this._line = NaN;
|
16335 | },
|
16336 | lineStart: function() {
|
16337 | this._x = this._y = NaN;
|
16338 | this._point = 0;
|
16339 | },
|
16340 | lineEnd: function() {
|
16341 | if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y);
|
16342 | if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
|
16343 | if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line;
|
16344 | },
|
16345 | point: function(x, y) {
|
16346 | x = +x, y = +y;
|
16347 | switch (this._point) {
|
16348 | case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
|
16349 | case 1: this._point = 2; // proceed
|
16350 | default: {
|
16351 | if (this._t <= 0) {
|
16352 | this._context.lineTo(this._x, y);
|
16353 | this._context.lineTo(x, y);
|
16354 | } else {
|
16355 | var x1 = this._x * (1 - this._t) + x * this._t;
|
16356 | this._context.lineTo(x1, this._y);
|
16357 | this._context.lineTo(x1, y);
|
16358 | }
|
16359 | break;
|
16360 | }
|
16361 | }
|
16362 | this._x = x, this._y = y;
|
16363 | }
|
16364 | };
|
16365 |
|
16366 | function step(context) {
|
16367 | return new Step(context, 0.5);
|
16368 | }
|
16369 |
|
16370 | function stepBefore(context) {
|
16371 | return new Step(context, 0);
|
16372 | }
|
16373 |
|
16374 | function stepAfter(context) {
|
16375 | return new Step(context, 1);
|
16376 | }
|
16377 |
|
16378 | function none$1(series, order) {
|
16379 | if (!((n = series.length) > 1)) return;
|
16380 | for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) {
|
16381 | s0 = s1, s1 = series[order[i]];
|
16382 | for (j = 0; j < m; ++j) {
|
16383 | s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1];
|
16384 | }
|
16385 | }
|
16386 | }
|
16387 |
|
16388 | function none$2(series) {
|
16389 | var n = series.length, o = new Array(n);
|
16390 | while (--n >= 0) o[n] = n;
|
16391 | return o;
|
16392 | }
|
16393 |
|
16394 | function stackValue(d, key) {
|
16395 | return d[key];
|
16396 | }
|
16397 |
|
16398 | function stack() {
|
16399 | var keys = constant$b([]),
|
16400 | order = none$2,
|
16401 | offset = none$1,
|
16402 | value = stackValue;
|
16403 |
|
16404 | function stack(data) {
|
16405 | var kz = keys.apply(this, arguments),
|
16406 | i,
|
16407 | m = data.length,
|
16408 | n = kz.length,
|
16409 | sz = new Array(n),
|
16410 | oz;
|
16411 |
|
16412 | for (i = 0; i < n; ++i) {
|
16413 | for (var ki = kz[i], si = sz[i] = new Array(m), j = 0, sij; j < m; ++j) {
|
16414 | si[j] = sij = [0, +value(data[j], ki, j, data)];
|
16415 | sij.data = data[j];
|
16416 | }
|
16417 | si.key = ki;
|
16418 | }
|
16419 |
|
16420 | for (i = 0, oz = order(sz); i < n; ++i) {
|
16421 | sz[oz[i]].index = i;
|
16422 | }
|
16423 |
|
16424 | offset(sz, oz);
|
16425 | return sz;
|
16426 | }
|
16427 |
|
16428 | stack.keys = function(_) {
|
16429 | return arguments.length ? (keys = typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : keys;
|
16430 | };
|
16431 |
|
16432 | stack.value = function(_) {
|
16433 | return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(+_), stack) : value;
|
16434 | };
|
16435 |
|
16436 | stack.order = function(_) {
|
16437 | return arguments.length ? (order = _ == null ? none$2 : typeof _ === "function" ? _ : constant$b(slice$6.call(_)), stack) : order;
|
16438 | };
|
16439 |
|
16440 | stack.offset = function(_) {
|
16441 | return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset;
|
16442 | };
|
16443 |
|
16444 | return stack;
|
16445 | }
|
16446 |
|
16447 | function expand(series, order) {
|
16448 | if (!((n = series.length) > 0)) return;
|
16449 | for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) {
|
16450 | for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0;
|
16451 | if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y;
|
16452 | }
|
16453 | none$1(series, order);
|
16454 | }
|
16455 |
|
16456 | function diverging$1(series, order) {
|
16457 | if (!((n = series.length) > 0)) return;
|
16458 | for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) {
|
16459 | for (yp = yn = 0, i = 0; i < n; ++i) {
|
16460 | if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) {
|
16461 | d[0] = yp, d[1] = yp += dy;
|
16462 | } else if (dy < 0) {
|
16463 | d[1] = yn, d[0] = yn += dy;
|
16464 | } else {
|
16465 | d[0] = 0, d[1] = dy;
|
16466 | }
|
16467 | }
|
16468 | }
|
16469 | }
|
16470 |
|
16471 | function silhouette(series, order) {
|
16472 | if (!((n = series.length) > 0)) return;
|
16473 | for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) {
|
16474 | for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0;
|
16475 | s0[j][1] += s0[j][0] = -y / 2;
|
16476 | }
|
16477 | none$1(series, order);
|
16478 | }
|
16479 |
|
16480 | function wiggle(series, order) {
|
16481 | if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return;
|
16482 | for (var y = 0, j = 1, s0, m, n; j < m; ++j) {
|
16483 | for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) {
|
16484 | var si = series[order[i]],
|
16485 | sij0 = si[j][1] || 0,
|
16486 | sij1 = si[j - 1][1] || 0,
|
16487 | s3 = (sij0 - sij1) / 2;
|
16488 | for (var k = 0; k < i; ++k) {
|
16489 | var sk = series[order[k]],
|
16490 | skj0 = sk[j][1] || 0,
|
16491 | skj1 = sk[j - 1][1] || 0;
|
16492 | s3 += skj0 - skj1;
|
16493 | }
|
16494 | s1 += sij0, s2 += s3 * sij0;
|
16495 | }
|
16496 | s0[j - 1][1] += s0[j - 1][0] = y;
|
16497 | if (s1) y -= s2 / s1;
|
16498 | }
|
16499 | s0[j - 1][1] += s0[j - 1][0] = y;
|
16500 | none$1(series, order);
|
16501 | }
|
16502 |
|
16503 | function appearance(series) {
|
16504 | var peaks = series.map(peak);
|
16505 | return none$2(series).sort(function(a, b) { return peaks[a] - peaks[b]; });
|
16506 | }
|
16507 |
|
16508 | function peak(series) {
|
16509 | var i = -1, j = 0, n = series.length, vi, vj = -Infinity;
|
16510 | while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i;
|
16511 | return j;
|
16512 | }
|
16513 |
|
16514 | function ascending$3(series) {
|
16515 | var sums = series.map(sum$2);
|
16516 | return none$2(series).sort(function(a, b) { return sums[a] - sums[b]; });
|
16517 | }
|
16518 |
|
16519 | function sum$2(series) {
|
16520 | var s = 0, i = -1, n = series.length, v;
|
16521 | while (++i < n) if (v = +series[i][1]) s += v;
|
16522 | return s;
|
16523 | }
|
16524 |
|
16525 | function descending$2(series) {
|
16526 | return ascending$3(series).reverse();
|
16527 | }
|
16528 |
|
16529 | function insideOut(series) {
|
16530 | var n = series.length,
|
16531 | i,
|
16532 | j,
|
16533 | sums = series.map(sum$2),
|
16534 | order = appearance(series),
|
16535 | top = 0,
|
16536 | bottom = 0,
|
16537 | tops = [],
|
16538 | bottoms = [];
|
16539 |
|
16540 | for (i = 0; i < n; ++i) {
|
16541 | j = order[i];
|
16542 | if (top < bottom) {
|
16543 | top += sums[j];
|
16544 | tops.push(j);
|
16545 | } else {
|
16546 | bottom += sums[j];
|
16547 | bottoms.push(j);
|
16548 | }
|
16549 | }
|
16550 |
|
16551 | return bottoms.reverse().concat(tops);
|
16552 | }
|
16553 |
|
16554 | function reverse(series) {
|
16555 | return none$2(series).reverse();
|
16556 | }
|
16557 |
|
16558 | function constant$c(x) {
|
16559 | return function() {
|
16560 | return x;
|
16561 | };
|
16562 | }
|
16563 |
|
16564 | function x$4(d) {
|
16565 | return d[0];
|
16566 | }
|
16567 |
|
16568 | function y$4(d) {
|
16569 | return d[1];
|
16570 | }
|
16571 |
|
16572 | function RedBlackTree() {
|
16573 | this._ = null; // root node
|
16574 | }
|
16575 |
|
16576 | function RedBlackNode(node) {
|
16577 | node.U = // parent node
|
16578 | node.C = // color - true for red, false for black
|
16579 | node.L = // left node
|
16580 | node.R = // right node
|
16581 | node.P = // previous node
|
16582 | node.N = null; // next node
|
16583 | }
|
16584 |
|
16585 | RedBlackTree.prototype = {
|
16586 | constructor: RedBlackTree,
|
16587 |
|
16588 | insert: function(after, node) {
|
16589 | var parent, grandpa, uncle;
|
16590 |
|
16591 | if (after) {
|
16592 | node.P = after;
|
16593 | node.N = after.N;
|
16594 | if (after.N) after.N.P = node;
|
16595 | after.N = node;
|
16596 | if (after.R) {
|
16597 | after = after.R;
|
16598 | while (after.L) after = after.L;
|
16599 | after.L = node;
|
16600 | } else {
|
16601 | after.R = node;
|
16602 | }
|
16603 | parent = after;
|
16604 | } else if (this._) {
|
16605 | after = RedBlackFirst(this._);
|
16606 | node.P = null;
|
16607 | node.N = after;
|
16608 | after.P = after.L = node;
|
16609 | parent = after;
|
16610 | } else {
|
16611 | node.P = node.N = null;
|
16612 | this._ = node;
|
16613 | parent = null;
|
16614 | }
|
16615 | node.L = node.R = null;
|
16616 | node.U = parent;
|
16617 | node.C = true;
|
16618 |
|
16619 | after = node;
|
16620 | while (parent && parent.C) {
|
16621 | grandpa = parent.U;
|
16622 | if (parent === grandpa.L) {
|
16623 | uncle = grandpa.R;
|
16624 | if (uncle && uncle.C) {
|
16625 | parent.C = uncle.C = false;
|
16626 | grandpa.C = true;
|
16627 | after = grandpa;
|
16628 | } else {
|
16629 | if (after === parent.R) {
|
16630 | RedBlackRotateLeft(this, parent);
|
16631 | after = parent;
|
16632 | parent = after.U;
|
16633 | }
|
16634 | parent.C = false;
|
16635 | grandpa.C = true;
|
16636 | RedBlackRotateRight(this, grandpa);
|
16637 | }
|
16638 | } else {
|
16639 | uncle = grandpa.L;
|
16640 | if (uncle && uncle.C) {
|
16641 | parent.C = uncle.C = false;
|
16642 | grandpa.C = true;
|
16643 | after = grandpa;
|
16644 | } else {
|
16645 | if (after === parent.L) {
|
16646 | RedBlackRotateRight(this, parent);
|
16647 | after = parent;
|
16648 | parent = after.U;
|
16649 | }
|
16650 | parent.C = false;
|
16651 | grandpa.C = true;
|
16652 | RedBlackRotateLeft(this, grandpa);
|
16653 | }
|
16654 | }
|
16655 | parent = after.U;
|
16656 | }
|
16657 | this._.C = false;
|
16658 | },
|
16659 |
|
16660 | remove: function(node) {
|
16661 | if (node.N) node.N.P = node.P;
|
16662 | if (node.P) node.P.N = node.N;
|
16663 | node.N = node.P = null;
|
16664 |
|
16665 | var parent = node.U,
|
16666 | sibling,
|
16667 | left = node.L,
|
16668 | right = node.R,
|
16669 | next,
|
16670 | red;
|
16671 |
|
16672 | if (!left) next = right;
|
16673 | else if (!right) next = left;
|
16674 | else next = RedBlackFirst(right);
|
16675 |
|
16676 | if (parent) {
|
16677 | if (parent.L === node) parent.L = next;
|
16678 | else parent.R = next;
|
16679 | } else {
|
16680 | this._ = next;
|
16681 | }
|
16682 |
|
16683 | if (left && right) {
|
16684 | red = next.C;
|
16685 | next.C = node.C;
|
16686 | next.L = left;
|
16687 | left.U = next;
|
16688 | if (next !== right) {
|
16689 | parent = next.U;
|
16690 | next.U = node.U;
|
16691 | node = next.R;
|
16692 | parent.L = node;
|
16693 | next.R = right;
|
16694 | right.U = next;
|
16695 | } else {
|
16696 | next.U = parent;
|
16697 | parent = next;
|
16698 | node = next.R;
|
16699 | }
|
16700 | } else {
|
16701 | red = node.C;
|
16702 | node = next;
|
16703 | }
|
16704 |
|
16705 | if (node) node.U = parent;
|
16706 | if (red) return;
|
16707 | if (node && node.C) { node.C = false; return; }
|
16708 |
|
16709 | do {
|
16710 | if (node === this._) break;
|
16711 | if (node === parent.L) {
|
16712 | sibling = parent.R;
|
16713 | if (sibling.C) {
|
16714 | sibling.C = false;
|
16715 | parent.C = true;
|
16716 | RedBlackRotateLeft(this, parent);
|
16717 | sibling = parent.R;
|
16718 | }
|
16719 | if ((sibling.L && sibling.L.C)
|
16720 | || (sibling.R && sibling.R.C)) {
|
16721 | if (!sibling.R || !sibling.R.C) {
|
16722 | sibling.L.C = false;
|
16723 | sibling.C = true;
|
16724 | RedBlackRotateRight(this, sibling);
|
16725 | sibling = parent.R;
|
16726 | }
|
16727 | sibling.C = parent.C;
|
16728 | parent.C = sibling.R.C = false;
|
16729 | RedBlackRotateLeft(this, parent);
|
16730 | node = this._;
|
16731 | break;
|
16732 | }
|
16733 | } else {
|
16734 | sibling = parent.L;
|
16735 | if (sibling.C) {
|
16736 | sibling.C = false;
|
16737 | parent.C = true;
|
16738 | RedBlackRotateRight(this, parent);
|
16739 | sibling = parent.L;
|
16740 | }
|
16741 | if ((sibling.L && sibling.L.C)
|
16742 | || (sibling.R && sibling.R.C)) {
|
16743 | if (!sibling.L || !sibling.L.C) {
|
16744 | sibling.R.C = false;
|
16745 | sibling.C = true;
|
16746 | RedBlackRotateLeft(this, sibling);
|
16747 | sibling = parent.L;
|
16748 | }
|
16749 | sibling.C = parent.C;
|
16750 | parent.C = sibling.L.C = false;
|
16751 | RedBlackRotateRight(this, parent);
|
16752 | node = this._;
|
16753 | break;
|
16754 | }
|
16755 | }
|
16756 | sibling.C = true;
|
16757 | node = parent;
|
16758 | parent = parent.U;
|
16759 | } while (!node.C);
|
16760 |
|
16761 | if (node) node.C = false;
|
16762 | }
|
16763 | };
|
16764 |
|
16765 | function RedBlackRotateLeft(tree, node) {
|
16766 | var p = node,
|
16767 | q = node.R,
|
16768 | parent = p.U;
|
16769 |
|
16770 | if (parent) {
|
16771 | if (parent.L === p) parent.L = q;
|
16772 | else parent.R = q;
|
16773 | } else {
|
16774 | tree._ = q;
|
16775 | }
|
16776 |
|
16777 | q.U = parent;
|
16778 | p.U = q;
|
16779 | p.R = q.L;
|
16780 | if (p.R) p.R.U = p;
|
16781 | q.L = p;
|
16782 | }
|
16783 |
|
16784 | function RedBlackRotateRight(tree, node) {
|
16785 | var p = node,
|
16786 | q = node.L,
|
16787 | parent = p.U;
|
16788 |
|
16789 | if (parent) {
|
16790 | if (parent.L === p) parent.L = q;
|
16791 | else parent.R = q;
|
16792 | } else {
|
16793 | tree._ = q;
|
16794 | }
|
16795 |
|
16796 | q.U = parent;
|
16797 | p.U = q;
|
16798 | p.L = q.R;
|
16799 | if (p.L) p.L.U = p;
|
16800 | q.R = p;
|
16801 | }
|
16802 |
|
16803 | function RedBlackFirst(node) {
|
16804 | while (node.L) node = node.L;
|
16805 | return node;
|
16806 | }
|
16807 |
|
16808 | function createEdge(left, right, v0, v1) {
|
16809 | var edge = [null, null],
|
16810 | index = edges.push(edge) - 1;
|
16811 | edge.left = left;
|
16812 | edge.right = right;
|
16813 | if (v0) setEdgeEnd(edge, left, right, v0);
|
16814 | if (v1) setEdgeEnd(edge, right, left, v1);
|
16815 | cells[left.index].halfedges.push(index);
|
16816 | cells[right.index].halfedges.push(index);
|
16817 | return edge;
|
16818 | }
|
16819 |
|
16820 | function createBorderEdge(left, v0, v1) {
|
16821 | var edge = [v0, v1];
|
16822 | edge.left = left;
|
16823 | return edge;
|
16824 | }
|
16825 |
|
16826 | function setEdgeEnd(edge, left, right, vertex) {
|
16827 | if (!edge[0] && !edge[1]) {
|
16828 | edge[0] = vertex;
|
16829 | edge.left = left;
|
16830 | edge.right = right;
|
16831 | } else if (edge.left === right) {
|
16832 | edge[1] = vertex;
|
16833 | } else {
|
16834 | edge[0] = vertex;
|
16835 | }
|
16836 | }
|
16837 |
|
16838 | // Liang–Barsky line clipping.
|
16839 | function clipEdge(edge, x0, y0, x1, y1) {
|
16840 | var a = edge[0],
|
16841 | b = edge[1],
|
16842 | ax = a[0],
|
16843 | ay = a[1],
|
16844 | bx = b[0],
|
16845 | by = b[1],
|
16846 | t0 = 0,
|
16847 | t1 = 1,
|
16848 | dx = bx - ax,
|
16849 | dy = by - ay,
|
16850 | r;
|
16851 |
|
16852 | r = x0 - ax;
|
16853 | if (!dx && r > 0) return;
|
16854 | r /= dx;
|
16855 | if (dx < 0) {
|
16856 | if (r < t0) return;
|
16857 | if (r < t1) t1 = r;
|
16858 | } else if (dx > 0) {
|
16859 | if (r > t1) return;
|
16860 | if (r > t0) t0 = r;
|
16861 | }
|
16862 |
|
16863 | r = x1 - ax;
|
16864 | if (!dx && r < 0) return;
|
16865 | r /= dx;
|
16866 | if (dx < 0) {
|
16867 | if (r > t1) return;
|
16868 | if (r > t0) t0 = r;
|
16869 | } else if (dx > 0) {
|
16870 | if (r < t0) return;
|
16871 | if (r < t1) t1 = r;
|
16872 | }
|
16873 |
|
16874 | r = y0 - ay;
|
16875 | if (!dy && r > 0) return;
|
16876 | r /= dy;
|
16877 | if (dy < 0) {
|
16878 | if (r < t0) return;
|
16879 | if (r < t1) t1 = r;
|
16880 | } else if (dy > 0) {
|
16881 | if (r > t1) return;
|
16882 | if (r > t0) t0 = r;
|
16883 | }
|
16884 |
|
16885 | r = y1 - ay;
|
16886 | if (!dy && r < 0) return;
|
16887 | r /= dy;
|
16888 | if (dy < 0) {
|
16889 | if (r > t1) return;
|
16890 | if (r > t0) t0 = r;
|
16891 | } else if (dy > 0) {
|
16892 | if (r < t0) return;
|
16893 | if (r < t1) t1 = r;
|
16894 | }
|
16895 |
|
16896 | if (!(t0 > 0) && !(t1 < 1)) return true; // TODO Better check?
|
16897 |
|
16898 | if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
|
16899 | if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
|
16900 | return true;
|
16901 | }
|
16902 |
|
16903 | function connectEdge(edge, x0, y0, x1, y1) {
|
16904 | var v1 = edge[1];
|
16905 | if (v1) return true;
|
16906 |
|
16907 | var v0 = edge[0],
|
16908 | left = edge.left,
|
16909 | right = edge.right,
|
16910 | lx = left[0],
|
16911 | ly = left[1],
|
16912 | rx = right[0],
|
16913 | ry = right[1],
|
16914 | fx = (lx + rx) / 2,
|
16915 | fy = (ly + ry) / 2,
|
16916 | fm,
|
16917 | fb;
|
16918 |
|
16919 | if (ry === ly) {
|
16920 | if (fx < x0 || fx >= x1) return;
|
16921 | if (lx > rx) {
|
16922 | if (!v0) v0 = [fx, y0];
|
16923 | else if (v0[1] >= y1) return;
|
16924 | v1 = [fx, y1];
|
16925 | } else {
|
16926 | if (!v0) v0 = [fx, y1];
|
16927 | else if (v0[1] < y0) return;
|
16928 | v1 = [fx, y0];
|
16929 | }
|
16930 | } else {
|
16931 | fm = (lx - rx) / (ry - ly);
|
16932 | fb = fy - fm * fx;
|
16933 | if (fm < -1 || fm > 1) {
|
16934 | if (lx > rx) {
|
16935 | if (!v0) v0 = [(y0 - fb) / fm, y0];
|
16936 | else if (v0[1] >= y1) return;
|
16937 | v1 = [(y1 - fb) / fm, y1];
|
16938 | } else {
|
16939 | if (!v0) v0 = [(y1 - fb) / fm, y1];
|
16940 | else if (v0[1] < y0) return;
|
16941 | v1 = [(y0 - fb) / fm, y0];
|
16942 | }
|
16943 | } else {
|
16944 | if (ly < ry) {
|
16945 | if (!v0) v0 = [x0, fm * x0 + fb];
|
16946 | else if (v0[0] >= x1) return;
|
16947 | v1 = [x1, fm * x1 + fb];
|
16948 | } else {
|
16949 | if (!v0) v0 = [x1, fm * x1 + fb];
|
16950 | else if (v0[0] < x0) return;
|
16951 | v1 = [x0, fm * x0 + fb];
|
16952 | }
|
16953 | }
|
16954 | }
|
16955 |
|
16956 | edge[0] = v0;
|
16957 | edge[1] = v1;
|
16958 | return true;
|
16959 | }
|
16960 |
|
16961 | function clipEdges(x0, y0, x1, y1) {
|
16962 | var i = edges.length,
|
16963 | edge;
|
16964 |
|
16965 | while (i--) {
|
16966 | if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
|
16967 | || !clipEdge(edge, x0, y0, x1, y1)
|
16968 | || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon$4
|
16969 | || Math.abs(edge[0][1] - edge[1][1]) > epsilon$4)) {
|
16970 | delete edges[i];
|
16971 | }
|
16972 | }
|
16973 | }
|
16974 |
|
16975 | function createCell(site) {
|
16976 | return cells[site.index] = {
|
16977 | site: site,
|
16978 | halfedges: []
|
16979 | };
|
16980 | }
|
16981 |
|
16982 | function cellHalfedgeAngle(cell, edge) {
|
16983 | var site = cell.site,
|
16984 | va = edge.left,
|
16985 | vb = edge.right;
|
16986 | if (site === vb) vb = va, va = site;
|
16987 | if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
|
16988 | if (site === va) va = edge[1], vb = edge[0];
|
16989 | else va = edge[0], vb = edge[1];
|
16990 | return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
|
16991 | }
|
16992 |
|
16993 | function cellHalfedgeStart(cell, edge) {
|
16994 | return edge[+(edge.left !== cell.site)];
|
16995 | }
|
16996 |
|
16997 | function cellHalfedgeEnd(cell, edge) {
|
16998 | return edge[+(edge.left === cell.site)];
|
16999 | }
|
17000 |
|
17001 | function sortCellHalfedges() {
|
17002 | for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
|
17003 | if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
|
17004 | var index = new Array(m),
|
17005 | array = new Array(m);
|
17006 | for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
|
17007 | index.sort(function(i, j) { return array[j] - array[i]; });
|
17008 | for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
|
17009 | for (j = 0; j < m; ++j) halfedges[j] = array[j];
|
17010 | }
|
17011 | }
|
17012 | }
|
17013 |
|
17014 | function clipCells(x0, y0, x1, y1) {
|
17015 | var nCells = cells.length,
|
17016 | iCell,
|
17017 | cell,
|
17018 | site,
|
17019 | iHalfedge,
|
17020 | halfedges,
|
17021 | nHalfedges,
|
17022 | start,
|
17023 | startX,
|
17024 | startY,
|
17025 | end,
|
17026 | endX,
|
17027 | endY,
|
17028 | cover = true;
|
17029 |
|
17030 | for (iCell = 0; iCell < nCells; ++iCell) {
|
17031 | if (cell = cells[iCell]) {
|
17032 | site = cell.site;
|
17033 | halfedges = cell.halfedges;
|
17034 | iHalfedge = halfedges.length;
|
17035 |
|
17036 | // Remove any dangling clipped edges.
|
17037 | while (iHalfedge--) {
|
17038 | if (!edges[halfedges[iHalfedge]]) {
|
17039 | halfedges.splice(iHalfedge, 1);
|
17040 | }
|
17041 | }
|
17042 |
|
17043 | // Insert any border edges as necessary.
|
17044 | iHalfedge = 0, nHalfedges = halfedges.length;
|
17045 | while (iHalfedge < nHalfedges) {
|
17046 | end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
|
17047 | start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
|
17048 | if (Math.abs(endX - startX) > epsilon$4 || Math.abs(endY - startY) > epsilon$4) {
|
17049 | halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
|
17050 | Math.abs(endX - x0) < epsilon$4 && y1 - endY > epsilon$4 ? [x0, Math.abs(startX - x0) < epsilon$4 ? startY : y1]
|
17051 | : Math.abs(endY - y1) < epsilon$4 && x1 - endX > epsilon$4 ? [Math.abs(startY - y1) < epsilon$4 ? startX : x1, y1]
|
17052 | : Math.abs(endX - x1) < epsilon$4 && endY - y0 > epsilon$4 ? [x1, Math.abs(startX - x1) < epsilon$4 ? startY : y0]
|
17053 | : Math.abs(endY - y0) < epsilon$4 && endX - x0 > epsilon$4 ? [Math.abs(startY - y0) < epsilon$4 ? startX : x0, y0]
|
17054 | : null)) - 1);
|
17055 | ++nHalfedges;
|
17056 | }
|
17057 | }
|
17058 |
|
17059 | if (nHalfedges) cover = false;
|
17060 | }
|
17061 | }
|
17062 |
|
17063 | // If there weren’t any edges, have the closest site cover the extent.
|
17064 | // It doesn’t matter which corner of the extent we measure!
|
17065 | if (cover) {
|
17066 | var dx, dy, d2, dc = Infinity;
|
17067 |
|
17068 | for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
|
17069 | if (cell = cells[iCell]) {
|
17070 | site = cell.site;
|
17071 | dx = site[0] - x0;
|
17072 | dy = site[1] - y0;
|
17073 | d2 = dx * dx + dy * dy;
|
17074 | if (d2 < dc) dc = d2, cover = cell;
|
17075 | }
|
17076 | }
|
17077 |
|
17078 | if (cover) {
|
17079 | var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
|
17080 | cover.halfedges.push(
|
17081 | edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
|
17082 | edges.push(createBorderEdge(site, v01, v11)) - 1,
|
17083 | edges.push(createBorderEdge(site, v11, v10)) - 1,
|
17084 | edges.push(createBorderEdge(site, v10, v00)) - 1
|
17085 | );
|
17086 | }
|
17087 | }
|
17088 |
|
17089 | // Lastly delete any cells with no edges; these were entirely clipped.
|
17090 | for (iCell = 0; iCell < nCells; ++iCell) {
|
17091 | if (cell = cells[iCell]) {
|
17092 | if (!cell.halfedges.length) {
|
17093 | delete cells[iCell];
|
17094 | }
|
17095 | }
|
17096 | }
|
17097 | }
|
17098 |
|
17099 | var circlePool = [];
|
17100 |
|
17101 | var firstCircle;
|
17102 |
|
17103 | function Circle() {
|
17104 | RedBlackNode(this);
|
17105 | this.x =
|
17106 | this.y =
|
17107 | this.arc =
|
17108 | this.site =
|
17109 | this.cy = null;
|
17110 | }
|
17111 |
|
17112 | function attachCircle(arc) {
|
17113 | var lArc = arc.P,
|
17114 | rArc = arc.N;
|
17115 |
|
17116 | if (!lArc || !rArc) return;
|
17117 |
|
17118 | var lSite = lArc.site,
|
17119 | cSite = arc.site,
|
17120 | rSite = rArc.site;
|
17121 |
|
17122 | if (lSite === rSite) return;
|
17123 |
|
17124 | var bx = cSite[0],
|
17125 | by = cSite[1],
|
17126 | ax = lSite[0] - bx,
|
17127 | ay = lSite[1] - by,
|
17128 | cx = rSite[0] - bx,
|
17129 | cy = rSite[1] - by;
|
17130 |
|
17131 | var d = 2 * (ax * cy - ay * cx);
|
17132 | if (d >= -epsilon2$2) return;
|
17133 |
|
17134 | var ha = ax * ax + ay * ay,
|
17135 | hc = cx * cx + cy * cy,
|
17136 | x = (cy * ha - ay * hc) / d,
|
17137 | y = (ax * hc - cx * ha) / d;
|
17138 |
|
17139 | var circle = circlePool.pop() || new Circle;
|
17140 | circle.arc = arc;
|
17141 | circle.site = cSite;
|
17142 | circle.x = x + bx;
|
17143 | circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y); // y bottom
|
17144 |
|
17145 | arc.circle = circle;
|
17146 |
|
17147 | var before = null,
|
17148 | node = circles._;
|
17149 |
|
17150 | while (node) {
|
17151 | if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
|
17152 | if (node.L) node = node.L;
|
17153 | else { before = node.P; break; }
|
17154 | } else {
|
17155 | if (node.R) node = node.R;
|
17156 | else { before = node; break; }
|
17157 | }
|
17158 | }
|
17159 |
|
17160 | circles.insert(before, circle);
|
17161 | if (!before) firstCircle = circle;
|
17162 | }
|
17163 |
|
17164 | function detachCircle(arc) {
|
17165 | var circle = arc.circle;
|
17166 | if (circle) {
|
17167 | if (!circle.P) firstCircle = circle.N;
|
17168 | circles.remove(circle);
|
17169 | circlePool.push(circle);
|
17170 | RedBlackNode(circle);
|
17171 | arc.circle = null;
|
17172 | }
|
17173 | }
|
17174 |
|
17175 | var beachPool = [];
|
17176 |
|
17177 | function Beach() {
|
17178 | RedBlackNode(this);
|
17179 | this.edge =
|
17180 | this.site =
|
17181 | this.circle = null;
|
17182 | }
|
17183 |
|
17184 | function createBeach(site) {
|
17185 | var beach = beachPool.pop() || new Beach;
|
17186 | beach.site = site;
|
17187 | return beach;
|
17188 | }
|
17189 |
|
17190 | function detachBeach(beach) {
|
17191 | detachCircle(beach);
|
17192 | beaches.remove(beach);
|
17193 | beachPool.push(beach);
|
17194 | RedBlackNode(beach);
|
17195 | }
|
17196 |
|
17197 | function removeBeach(beach) {
|
17198 | var circle = beach.circle,
|
17199 | x = circle.x,
|
17200 | y = circle.cy,
|
17201 | vertex = [x, y],
|
17202 | previous = beach.P,
|
17203 | next = beach.N,
|
17204 | disappearing = [beach];
|
17205 |
|
17206 | detachBeach(beach);
|
17207 |
|
17208 | var lArc = previous;
|
17209 | while (lArc.circle
|
17210 | && Math.abs(x - lArc.circle.x) < epsilon$4
|
17211 | && Math.abs(y - lArc.circle.cy) < epsilon$4) {
|
17212 | previous = lArc.P;
|
17213 | disappearing.unshift(lArc);
|
17214 | detachBeach(lArc);
|
17215 | lArc = previous;
|
17216 | }
|
17217 |
|
17218 | disappearing.unshift(lArc);
|
17219 | detachCircle(lArc);
|
17220 |
|
17221 | var rArc = next;
|
17222 | while (rArc.circle
|
17223 | && Math.abs(x - rArc.circle.x) < epsilon$4
|
17224 | && Math.abs(y - rArc.circle.cy) < epsilon$4) {
|
17225 | next = rArc.N;
|
17226 | disappearing.push(rArc);
|
17227 | detachBeach(rArc);
|
17228 | rArc = next;
|
17229 | }
|
17230 |
|
17231 | disappearing.push(rArc);
|
17232 | detachCircle(rArc);
|
17233 |
|
17234 | var nArcs = disappearing.length,
|
17235 | iArc;
|
17236 | for (iArc = 1; iArc < nArcs; ++iArc) {
|
17237 | rArc = disappearing[iArc];
|
17238 | lArc = disappearing[iArc - 1];
|
17239 | setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
|
17240 | }
|
17241 |
|
17242 | lArc = disappearing[0];
|
17243 | rArc = disappearing[nArcs - 1];
|
17244 | rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
|
17245 |
|
17246 | attachCircle(lArc);
|
17247 | attachCircle(rArc);
|
17248 | }
|
17249 |
|
17250 | function addBeach(site) {
|
17251 | var x = site[0],
|
17252 | directrix = site[1],
|
17253 | lArc,
|
17254 | rArc,
|
17255 | dxl,
|
17256 | dxr,
|
17257 | node = beaches._;
|
17258 |
|
17259 | while (node) {
|
17260 | dxl = leftBreakPoint(node, directrix) - x;
|
17261 | if (dxl > epsilon$4) node = node.L; else {
|
17262 | dxr = x - rightBreakPoint(node, directrix);
|
17263 | if (dxr > epsilon$4) {
|
17264 | if (!node.R) {
|
17265 | lArc = node;
|
17266 | break;
|
17267 | }
|
17268 | node = node.R;
|
17269 | } else {
|
17270 | if (dxl > -epsilon$4) {
|
17271 | lArc = node.P;
|
17272 | rArc = node;
|
17273 | } else if (dxr > -epsilon$4) {
|
17274 | lArc = node;
|
17275 | rArc = node.N;
|
17276 | } else {
|
17277 | lArc = rArc = node;
|
17278 | }
|
17279 | break;
|
17280 | }
|
17281 | }
|
17282 | }
|
17283 |
|
17284 | createCell(site);
|
17285 | var newArc = createBeach(site);
|
17286 | beaches.insert(lArc, newArc);
|
17287 |
|
17288 | if (!lArc && !rArc) return;
|
17289 |
|
17290 | if (lArc === rArc) {
|
17291 | detachCircle(lArc);
|
17292 | rArc = createBeach(lArc.site);
|
17293 | beaches.insert(newArc, rArc);
|
17294 | newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
|
17295 | attachCircle(lArc);
|
17296 | attachCircle(rArc);
|
17297 | return;
|
17298 | }
|
17299 |
|
17300 | if (!rArc) { // && lArc
|
17301 | newArc.edge = createEdge(lArc.site, newArc.site);
|
17302 | return;
|
17303 | }
|
17304 |
|
17305 | // else lArc !== rArc
|
17306 | detachCircle(lArc);
|
17307 | detachCircle(rArc);
|
17308 |
|
17309 | var lSite = lArc.site,
|
17310 | ax = lSite[0],
|
17311 | ay = lSite[1],
|
17312 | bx = site[0] - ax,
|
17313 | by = site[1] - ay,
|
17314 | rSite = rArc.site,
|
17315 | cx = rSite[0] - ax,
|
17316 | cy = rSite[1] - ay,
|
17317 | d = 2 * (bx * cy - by * cx),
|
17318 | hb = bx * bx + by * by,
|
17319 | hc = cx * cx + cy * cy,
|
17320 | vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
|
17321 |
|
17322 | setEdgeEnd(rArc.edge, lSite, rSite, vertex);
|
17323 | newArc.edge = createEdge(lSite, site, null, vertex);
|
17324 | rArc.edge = createEdge(site, rSite, null, vertex);
|
17325 | attachCircle(lArc);
|
17326 | attachCircle(rArc);
|
17327 | }
|
17328 |
|
17329 | function leftBreakPoint(arc, directrix) {
|
17330 | var site = arc.site,
|
17331 | rfocx = site[0],
|
17332 | rfocy = site[1],
|
17333 | pby2 = rfocy - directrix;
|
17334 |
|
17335 | if (!pby2) return rfocx;
|
17336 |
|
17337 | var lArc = arc.P;
|
17338 | if (!lArc) return -Infinity;
|
17339 |
|
17340 | site = lArc.site;
|
17341 | var lfocx = site[0],
|
17342 | lfocy = site[1],
|
17343 | plby2 = lfocy - directrix;
|
17344 |
|
17345 | if (!plby2) return lfocx;
|
17346 |
|
17347 | var hl = lfocx - rfocx,
|
17348 | aby2 = 1 / pby2 - 1 / plby2,
|
17349 | b = hl / plby2;
|
17350 |
|
17351 | if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
|
17352 |
|
17353 | return (rfocx + lfocx) / 2;
|
17354 | }
|
17355 |
|
17356 | function rightBreakPoint(arc, directrix) {
|
17357 | var rArc = arc.N;
|
17358 | if (rArc) return leftBreakPoint(rArc, directrix);
|
17359 | var site = arc.site;
|
17360 | return site[1] === directrix ? site[0] : Infinity;
|
17361 | }
|
17362 |
|
17363 | var epsilon$4 = 1e-6;
|
17364 | var epsilon2$2 = 1e-12;
|
17365 | var beaches;
|
17366 | var cells;
|
17367 | var circles;
|
17368 | var edges;
|
17369 |
|
17370 | function triangleArea(a, b, c) {
|
17371 | return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
|
17372 | }
|
17373 |
|
17374 | function lexicographic(a, b) {
|
17375 | return b[1] - a[1]
|
17376 | || b[0] - a[0];
|
17377 | }
|
17378 |
|
17379 | function Diagram(sites, extent) {
|
17380 | var site = sites.sort(lexicographic).pop(),
|
17381 | x,
|
17382 | y,
|
17383 | circle;
|
17384 |
|
17385 | edges = [];
|
17386 | cells = new Array(sites.length);
|
17387 | beaches = new RedBlackTree;
|
17388 | circles = new RedBlackTree;
|
17389 |
|
17390 | while (true) {
|
17391 | circle = firstCircle;
|
17392 | if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
|
17393 | if (site[0] !== x || site[1] !== y) {
|
17394 | addBeach(site);
|
17395 | x = site[0], y = site[1];
|
17396 | }
|
17397 | site = sites.pop();
|
17398 | } else if (circle) {
|
17399 | removeBeach(circle.arc);
|
17400 | } else {
|
17401 | break;
|
17402 | }
|
17403 | }
|
17404 |
|
17405 | sortCellHalfedges();
|
17406 |
|
17407 | if (extent) {
|
17408 | var x0 = +extent[0][0],
|
17409 | y0 = +extent[0][1],
|
17410 | x1 = +extent[1][0],
|
17411 | y1 = +extent[1][1];
|
17412 | clipEdges(x0, y0, x1, y1);
|
17413 | clipCells(x0, y0, x1, y1);
|
17414 | }
|
17415 |
|
17416 | this.edges = edges;
|
17417 | this.cells = cells;
|
17418 |
|
17419 | beaches =
|
17420 | circles =
|
17421 | edges =
|
17422 | cells = null;
|
17423 | }
|
17424 |
|
17425 | Diagram.prototype = {
|
17426 | constructor: Diagram,
|
17427 |
|
17428 | polygons: function() {
|
17429 | var edges = this.edges;
|
17430 |
|
17431 | return this.cells.map(function(cell) {
|
17432 | var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
|
17433 | polygon.data = cell.site.data;
|
17434 | return polygon;
|
17435 | });
|
17436 | },
|
17437 |
|
17438 | triangles: function() {
|
17439 | var triangles = [],
|
17440 | edges = this.edges;
|
17441 |
|
17442 | this.cells.forEach(function(cell, i) {
|
17443 | if (!(m = (halfedges = cell.halfedges).length)) return;
|
17444 | var site = cell.site,
|
17445 | halfedges,
|
17446 | j = -1,
|
17447 | m,
|
17448 | s0,
|
17449 | e1 = edges[halfedges[m - 1]],
|
17450 | s1 = e1.left === site ? e1.right : e1.left;
|
17451 |
|
17452 | while (++j < m) {
|
17453 | s0 = s1;
|
17454 | e1 = edges[halfedges[j]];
|
17455 | s1 = e1.left === site ? e1.right : e1.left;
|
17456 | if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
|
17457 | triangles.push([site.data, s0.data, s1.data]);
|
17458 | }
|
17459 | }
|
17460 | });
|
17461 |
|
17462 | return triangles;
|
17463 | },
|
17464 |
|
17465 | links: function() {
|
17466 | return this.edges.filter(function(edge) {
|
17467 | return edge.right;
|
17468 | }).map(function(edge) {
|
17469 | return {
|
17470 | source: edge.left.data,
|
17471 | target: edge.right.data
|
17472 | };
|
17473 | });
|
17474 | },
|
17475 |
|
17476 | find: function(x, y, radius) {
|
17477 | var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
|
17478 |
|
17479 | // Use the previously-found cell, or start with an arbitrary one.
|
17480 | while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
|
17481 | var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
|
17482 |
|
17483 | // Traverse the half-edges to find a closer cell, if any.
|
17484 | do {
|
17485 | cell = that.cells[i0 = i1], i1 = null;
|
17486 | cell.halfedges.forEach(function(e) {
|
17487 | var edge = that.edges[e], v = edge.left;
|
17488 | if ((v === cell.site || !v) && !(v = edge.right)) return;
|
17489 | var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
|
17490 | if (v2 < d2) d2 = v2, i1 = v.index;
|
17491 | });
|
17492 | } while (i1 !== null);
|
17493 |
|
17494 | that._found = i0;
|
17495 |
|
17496 | return radius == null || d2 <= radius * radius ? cell.site : null;
|
17497 | }
|
17498 | };
|
17499 |
|
17500 | function voronoi() {
|
17501 | var x = x$4,
|
17502 | y = y$4,
|
17503 | extent = null;
|
17504 |
|
17505 | function voronoi(data) {
|
17506 | return new Diagram(data.map(function(d, i) {
|
17507 | var s = [Math.round(x(d, i, data) / epsilon$4) * epsilon$4, Math.round(y(d, i, data) / epsilon$4) * epsilon$4];
|
17508 | s.index = i;
|
17509 | s.data = d;
|
17510 | return s;
|
17511 | }), extent);
|
17512 | }
|
17513 |
|
17514 | voronoi.polygons = function(data) {
|
17515 | return voronoi(data).polygons();
|
17516 | };
|
17517 |
|
17518 | voronoi.links = function(data) {
|
17519 | return voronoi(data).links();
|
17520 | };
|
17521 |
|
17522 | voronoi.triangles = function(data) {
|
17523 | return voronoi(data).triangles();
|
17524 | };
|
17525 |
|
17526 | voronoi.x = function(_) {
|
17527 | return arguments.length ? (x = typeof _ === "function" ? _ : constant$c(+_), voronoi) : x;
|
17528 | };
|
17529 |
|
17530 | voronoi.y = function(_) {
|
17531 | return arguments.length ? (y = typeof _ === "function" ? _ : constant$c(+_), voronoi) : y;
|
17532 | };
|
17533 |
|
17534 | voronoi.extent = function(_) {
|
17535 | return arguments.length ? (extent = _ == null ? null : [[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]], voronoi) : extent && [[extent[0][0], extent[0][1]], [extent[1][0], extent[1][1]]];
|
17536 | };
|
17537 |
|
17538 | voronoi.size = function(_) {
|
17539 | return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
|
17540 | };
|
17541 |
|
17542 | return voronoi;
|
17543 | }
|
17544 |
|
17545 | function constant$d(x) {
|
17546 | return function() {
|
17547 | return x;
|
17548 | };
|
17549 | }
|
17550 |
|
17551 | function ZoomEvent(target, type, transform) {
|
17552 | this.target = target;
|
17553 | this.type = type;
|
17554 | this.transform = transform;
|
17555 | }
|
17556 |
|
17557 | function Transform(k, x, y) {
|
17558 | this.k = k;
|
17559 | this.x = x;
|
17560 | this.y = y;
|
17561 | }
|
17562 |
|
17563 | Transform.prototype = {
|
17564 | constructor: Transform,
|
17565 | scale: function(k) {
|
17566 | return k === 1 ? this : new Transform(this.k * k, this.x, this.y);
|
17567 | },
|
17568 | translate: function(x, y) {
|
17569 | return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y);
|
17570 | },
|
17571 | apply: function(point) {
|
17572 | return [point[0] * this.k + this.x, point[1] * this.k + this.y];
|
17573 | },
|
17574 | applyX: function(x) {
|
17575 | return x * this.k + this.x;
|
17576 | },
|
17577 | applyY: function(y) {
|
17578 | return y * this.k + this.y;
|
17579 | },
|
17580 | invert: function(location) {
|
17581 | return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k];
|
17582 | },
|
17583 | invertX: function(x) {
|
17584 | return (x - this.x) / this.k;
|
17585 | },
|
17586 | invertY: function(y) {
|
17587 | return (y - this.y) / this.k;
|
17588 | },
|
17589 | rescaleX: function(x) {
|
17590 | return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x));
|
17591 | },
|
17592 | rescaleY: function(y) {
|
17593 | return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y));
|
17594 | },
|
17595 | toString: function() {
|
17596 | return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")";
|
17597 | }
|
17598 | };
|
17599 |
|
17600 | var identity$9 = new Transform(1, 0, 0);
|
17601 |
|
17602 | transform$1.prototype = Transform.prototype;
|
17603 |
|
17604 | function transform$1(node) {
|
17605 | while (!node.__zoom) if (!(node = node.parentNode)) return identity$9;
|
17606 | return node.__zoom;
|
17607 | }
|
17608 |
|
17609 | function nopropagation$2() {
|
17610 | exports.event.stopImmediatePropagation();
|
17611 | }
|
17612 |
|
17613 | function noevent$2() {
|
17614 | exports.event.preventDefault();
|
17615 | exports.event.stopImmediatePropagation();
|
17616 | }
|
17617 |
|
17618 | // Ignore right-click, since that should open the context menu.
|
17619 | function defaultFilter$2() {
|
17620 | return !exports.event.ctrlKey && !exports.event.button;
|
17621 | }
|
17622 |
|
17623 | function defaultExtent$1() {
|
17624 | var e = this;
|
17625 | if (e instanceof SVGElement) {
|
17626 | e = e.ownerSVGElement || e;
|
17627 | if (e.hasAttribute("viewBox")) {
|
17628 | e = e.viewBox.baseVal;
|
17629 | return [[e.x, e.y], [e.x + e.width, e.y + e.height]];
|
17630 | }
|
17631 | return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]];
|
17632 | }
|
17633 | return [[0, 0], [e.clientWidth, e.clientHeight]];
|
17634 | }
|
17635 |
|
17636 | function defaultTransform() {
|
17637 | return this.__zoom || identity$9;
|
17638 | }
|
17639 |
|
17640 | function defaultWheelDelta() {
|
17641 | return -exports.event.deltaY * (exports.event.deltaMode === 1 ? 0.05 : exports.event.deltaMode ? 1 : 0.002);
|
17642 | }
|
17643 |
|
17644 | function defaultTouchable$2() {
|
17645 | return navigator.maxTouchPoints || ("ontouchstart" in this);
|
17646 | }
|
17647 |
|
17648 | function defaultConstrain(transform, extent, translateExtent) {
|
17649 | var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0],
|
17650 | dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0],
|
17651 | dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1],
|
17652 | dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1];
|
17653 | return transform.translate(
|
17654 | dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1),
|
17655 | dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1)
|
17656 | );
|
17657 | }
|
17658 |
|
17659 | function zoom() {
|
17660 | var filter = defaultFilter$2,
|
17661 | extent = defaultExtent$1,
|
17662 | constrain = defaultConstrain,
|
17663 | wheelDelta = defaultWheelDelta,
|
17664 | touchable = defaultTouchable$2,
|
17665 | scaleExtent = [0, Infinity],
|
17666 | translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]],
|
17667 | duration = 250,
|
17668 | interpolate = interpolateZoom,
|
17669 | listeners = dispatch("start", "zoom", "end"),
|
17670 | touchstarting,
|
17671 | touchending,
|
17672 | touchDelay = 500,
|
17673 | wheelDelay = 150,
|
17674 | clickDistance2 = 0;
|
17675 |
|
17676 | function zoom(selection) {
|
17677 | selection
|
17678 | .property("__zoom", defaultTransform)
|
17679 | .on("wheel.zoom", wheeled)
|
17680 | .on("mousedown.zoom", mousedowned)
|
17681 | .on("dblclick.zoom", dblclicked)
|
17682 | .filter(touchable)
|
17683 | .on("touchstart.zoom", touchstarted)
|
17684 | .on("touchmove.zoom", touchmoved)
|
17685 | .on("touchend.zoom touchcancel.zoom", touchended)
|
17686 | .style("touch-action", "none")
|
17687 | .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
|
17688 | }
|
17689 |
|
17690 | zoom.transform = function(collection, transform, point) {
|
17691 | var selection = collection.selection ? collection.selection() : collection;
|
17692 | selection.property("__zoom", defaultTransform);
|
17693 | if (collection !== selection) {
|
17694 | schedule(collection, transform, point);
|
17695 | } else {
|
17696 | selection.interrupt().each(function() {
|
17697 | gesture(this, arguments)
|
17698 | .start()
|
17699 | .zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform)
|
17700 | .end();
|
17701 | });
|
17702 | }
|
17703 | };
|
17704 |
|
17705 | zoom.scaleBy = function(selection, k, p) {
|
17706 | zoom.scaleTo(selection, function() {
|
17707 | var k0 = this.__zoom.k,
|
17708 | k1 = typeof k === "function" ? k.apply(this, arguments) : k;
|
17709 | return k0 * k1;
|
17710 | }, p);
|
17711 | };
|
17712 |
|
17713 | zoom.scaleTo = function(selection, k, p) {
|
17714 | zoom.transform(selection, function() {
|
17715 | var e = extent.apply(this, arguments),
|
17716 | t0 = this.__zoom,
|
17717 | p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p,
|
17718 | p1 = t0.invert(p0),
|
17719 | k1 = typeof k === "function" ? k.apply(this, arguments) : k;
|
17720 | return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent);
|
17721 | }, p);
|
17722 | };
|
17723 |
|
17724 | zoom.translateBy = function(selection, x, y) {
|
17725 | zoom.transform(selection, function() {
|
17726 | return constrain(this.__zoom.translate(
|
17727 | typeof x === "function" ? x.apply(this, arguments) : x,
|
17728 | typeof y === "function" ? y.apply(this, arguments) : y
|
17729 | ), extent.apply(this, arguments), translateExtent);
|
17730 | });
|
17731 | };
|
17732 |
|
17733 | zoom.translateTo = function(selection, x, y, p) {
|
17734 | zoom.transform(selection, function() {
|
17735 | var e = extent.apply(this, arguments),
|
17736 | t = this.__zoom,
|
17737 | p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p;
|
17738 | return constrain(identity$9.translate(p0[0], p0[1]).scale(t.k).translate(
|
17739 | typeof x === "function" ? -x.apply(this, arguments) : -x,
|
17740 | typeof y === "function" ? -y.apply(this, arguments) : -y
|
17741 | ), e, translateExtent);
|
17742 | }, p);
|
17743 | };
|
17744 |
|
17745 | function scale(transform, k) {
|
17746 | k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k));
|
17747 | return k === transform.k ? transform : new Transform(k, transform.x, transform.y);
|
17748 | }
|
17749 |
|
17750 | function translate(transform, p0, p1) {
|
17751 | var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k;
|
17752 | return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y);
|
17753 | }
|
17754 |
|
17755 | function centroid(extent) {
|
17756 | return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2];
|
17757 | }
|
17758 |
|
17759 | function schedule(transition, transform, point) {
|
17760 | transition
|
17761 | .on("start.zoom", function() { gesture(this, arguments).start(); })
|
17762 | .on("interrupt.zoom end.zoom", function() { gesture(this, arguments).end(); })
|
17763 | .tween("zoom", function() {
|
17764 | var that = this,
|
17765 | args = arguments,
|
17766 | g = gesture(that, args),
|
17767 | e = extent.apply(that, args),
|
17768 | p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point,
|
17769 | w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]),
|
17770 | a = that.__zoom,
|
17771 | b = typeof transform === "function" ? transform.apply(that, args) : transform,
|
17772 | i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
|
17773 | return function(t) {
|
17774 | if (t === 1) t = b; // Avoid rounding error on end.
|
17775 | else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); }
|
17776 | g.zoom(null, t);
|
17777 | };
|
17778 | });
|
17779 | }
|
17780 |
|
17781 | function gesture(that, args, clean) {
|
17782 | return (!clean && that.__zooming) || new Gesture(that, args);
|
17783 | }
|
17784 |
|
17785 | function Gesture(that, args) {
|
17786 | this.that = that;
|
17787 | this.args = args;
|
17788 | this.active = 0;
|
17789 | this.extent = extent.apply(that, args);
|
17790 | this.taps = 0;
|
17791 | }
|
17792 |
|
17793 | Gesture.prototype = {
|
17794 | start: function() {
|
17795 | if (++this.active === 1) {
|
17796 | this.that.__zooming = this;
|
17797 | this.emit("start");
|
17798 | }
|
17799 | return this;
|
17800 | },
|
17801 | zoom: function(key, transform) {
|
17802 | if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]);
|
17803 | if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]);
|
17804 | if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]);
|
17805 | this.that.__zoom = transform;
|
17806 | this.emit("zoom");
|
17807 | return this;
|
17808 | },
|
17809 | end: function() {
|
17810 | if (--this.active === 0) {
|
17811 | delete this.that.__zooming;
|
17812 | this.emit("end");
|
17813 | }
|
17814 | return this;
|
17815 | },
|
17816 | emit: function(type) {
|
17817 | customEvent(new ZoomEvent(zoom, type, this.that.__zoom), listeners.apply, listeners, [type, this.that, this.args]);
|
17818 | }
|
17819 | };
|
17820 |
|
17821 | function wheeled() {
|
17822 | if (!filter.apply(this, arguments)) return;
|
17823 | var g = gesture(this, arguments),
|
17824 | t = this.__zoom,
|
17825 | k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))),
|
17826 | p = mouse(this);
|
17827 |
|
17828 | // If the mouse is in the same location as before, reuse it.
|
17829 | // If there were recent wheel events, reset the wheel idle timeout.
|
17830 | if (g.wheel) {
|
17831 | if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) {
|
17832 | g.mouse[1] = t.invert(g.mouse[0] = p);
|
17833 | }
|
17834 | clearTimeout(g.wheel);
|
17835 | }
|
17836 |
|
17837 | // If this wheel event won’t trigger a transform change, ignore it.
|
17838 | else if (t.k === k) return;
|
17839 |
|
17840 | // Otherwise, capture the mouse point and location at the start.
|
17841 | else {
|
17842 | g.mouse = [p, t.invert(p)];
|
17843 | interrupt(this);
|
17844 | g.start();
|
17845 | }
|
17846 |
|
17847 | noevent$2();
|
17848 | g.wheel = setTimeout(wheelidled, wheelDelay);
|
17849 | g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent));
|
17850 |
|
17851 | function wheelidled() {
|
17852 | g.wheel = null;
|
17853 | g.end();
|
17854 | }
|
17855 | }
|
17856 |
|
17857 | function mousedowned() {
|
17858 | if (touchending || !filter.apply(this, arguments)) return;
|
17859 | var g = gesture(this, arguments, true),
|
17860 | v = select(exports.event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true),
|
17861 | p = mouse(this),
|
17862 | x0 = exports.event.clientX,
|
17863 | y0 = exports.event.clientY;
|
17864 |
|
17865 | dragDisable(exports.event.view);
|
17866 | nopropagation$2();
|
17867 | g.mouse = [p, this.__zoom.invert(p)];
|
17868 | interrupt(this);
|
17869 | g.start();
|
17870 |
|
17871 | function mousemoved() {
|
17872 | noevent$2();
|
17873 | if (!g.moved) {
|
17874 | var dx = exports.event.clientX - x0, dy = exports.event.clientY - y0;
|
17875 | g.moved = dx * dx + dy * dy > clickDistance2;
|
17876 | }
|
17877 | g.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = mouse(g.that), g.mouse[1]), g.extent, translateExtent));
|
17878 | }
|
17879 |
|
17880 | function mouseupped() {
|
17881 | v.on("mousemove.zoom mouseup.zoom", null);
|
17882 | yesdrag(exports.event.view, g.moved);
|
17883 | noevent$2();
|
17884 | g.end();
|
17885 | }
|
17886 | }
|
17887 |
|
17888 | function dblclicked() {
|
17889 | if (!filter.apply(this, arguments)) return;
|
17890 | var t0 = this.__zoom,
|
17891 | p0 = mouse(this),
|
17892 | p1 = t0.invert(p0),
|
17893 | k1 = t0.k * (exports.event.shiftKey ? 0.5 : 2),
|
17894 | t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, arguments), translateExtent);
|
17895 |
|
17896 | noevent$2();
|
17897 | if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0);
|
17898 | else select(this).call(zoom.transform, t1);
|
17899 | }
|
17900 |
|
17901 | function touchstarted() {
|
17902 | if (!filter.apply(this, arguments)) return;
|
17903 | var touches = exports.event.touches,
|
17904 | n = touches.length,
|
17905 | g = gesture(this, arguments, exports.event.changedTouches.length === n),
|
17906 | started, i, t, p;
|
17907 |
|
17908 | nopropagation$2();
|
17909 | for (i = 0; i < n; ++i) {
|
17910 | t = touches[i], p = touch(this, touches, t.identifier);
|
17911 | p = [p, this.__zoom.invert(p), t.identifier];
|
17912 | if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting;
|
17913 | else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0;
|
17914 | }
|
17915 |
|
17916 | if (touchstarting) touchstarting = clearTimeout(touchstarting);
|
17917 |
|
17918 | if (started) {
|
17919 | if (g.taps < 2) touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay);
|
17920 | interrupt(this);
|
17921 | g.start();
|
17922 | }
|
17923 | }
|
17924 |
|
17925 | function touchmoved() {
|
17926 | if (!this.__zooming) return;
|
17927 | var g = gesture(this, arguments),
|
17928 | touches = exports.event.changedTouches,
|
17929 | n = touches.length, i, t, p, l;
|
17930 |
|
17931 | noevent$2();
|
17932 | if (touchstarting) touchstarting = clearTimeout(touchstarting);
|
17933 | g.taps = 0;
|
17934 | for (i = 0; i < n; ++i) {
|
17935 | t = touches[i], p = touch(this, touches, t.identifier);
|
17936 | if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p;
|
17937 | else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p;
|
17938 | }
|
17939 | t = g.that.__zoom;
|
17940 | if (g.touch1) {
|
17941 | var p0 = g.touch0[0], l0 = g.touch0[1],
|
17942 | p1 = g.touch1[0], l1 = g.touch1[1],
|
17943 | dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp,
|
17944 | dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl;
|
17945 | t = scale(t, Math.sqrt(dp / dl));
|
17946 | p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2];
|
17947 | l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2];
|
17948 | }
|
17949 | else if (g.touch0) p = g.touch0[0], l = g.touch0[1];
|
17950 | else return;
|
17951 | g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent));
|
17952 | }
|
17953 |
|
17954 | function touchended() {
|
17955 | if (!this.__zooming) return;
|
17956 | var g = gesture(this, arguments),
|
17957 | touches = exports.event.changedTouches,
|
17958 | n = touches.length, i, t;
|
17959 |
|
17960 | nopropagation$2();
|
17961 | if (touchending) clearTimeout(touchending);
|
17962 | touchending = setTimeout(function() { touchending = null; }, touchDelay);
|
17963 | for (i = 0; i < n; ++i) {
|
17964 | t = touches[i];
|
17965 | if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0;
|
17966 | else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1;
|
17967 | }
|
17968 | if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1;
|
17969 | if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]);
|
17970 | else {
|
17971 | g.end();
|
17972 | // If this was a dbltap, reroute to the (optional) dblclick.zoom handler.
|
17973 | if (g.taps === 2) {
|
17974 | var p = select(this).on("dblclick.zoom");
|
17975 | if (p) p.apply(this, arguments);
|
17976 | }
|
17977 | }
|
17978 | }
|
17979 |
|
17980 | zoom.wheelDelta = function(_) {
|
17981 | return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant$d(+_), zoom) : wheelDelta;
|
17982 | };
|
17983 |
|
17984 | zoom.filter = function(_) {
|
17985 | return arguments.length ? (filter = typeof _ === "function" ? _ : constant$d(!!_), zoom) : filter;
|
17986 | };
|
17987 |
|
17988 | zoom.touchable = function(_) {
|
17989 | return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$d(!!_), zoom) : touchable;
|
17990 | };
|
17991 |
|
17992 | zoom.extent = function(_) {
|
17993 | return arguments.length ? (extent = typeof _ === "function" ? _ : constant$d([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent;
|
17994 | };
|
17995 |
|
17996 | zoom.scaleExtent = function(_) {
|
17997 | return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]];
|
17998 | };
|
17999 |
|
18000 | zoom.translateExtent = function(_) {
|
18001 | 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]]];
|
18002 | };
|
18003 |
|
18004 | zoom.constrain = function(_) {
|
18005 | return arguments.length ? (constrain = _, zoom) : constrain;
|
18006 | };
|
18007 |
|
18008 | zoom.duration = function(_) {
|
18009 | return arguments.length ? (duration = +_, zoom) : duration;
|
18010 | };
|
18011 |
|
18012 | zoom.interpolate = function(_) {
|
18013 | return arguments.length ? (interpolate = _, zoom) : interpolate;
|
18014 | };
|
18015 |
|
18016 | zoom.on = function() {
|
18017 | var value = listeners.on.apply(listeners, arguments);
|
18018 | return value === listeners ? zoom : value;
|
18019 | };
|
18020 |
|
18021 | zoom.clickDistance = function(_) {
|
18022 | return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2);
|
18023 | };
|
18024 |
|
18025 | return zoom;
|
18026 | }
|
18027 |
|
18028 | exports.FormatSpecifier = FormatSpecifier;
|
18029 | exports.active = active;
|
18030 | exports.arc = arc;
|
18031 | exports.area = area$3;
|
18032 | exports.areaRadial = areaRadial;
|
18033 | exports.ascending = ascending;
|
18034 | exports.autoType = autoType;
|
18035 | exports.axisBottom = axisBottom;
|
18036 | exports.axisLeft = axisLeft;
|
18037 | exports.axisRight = axisRight;
|
18038 | exports.axisTop = axisTop;
|
18039 | exports.bisect = bisectRight;
|
18040 | exports.bisectLeft = bisectLeft;
|
18041 | exports.bisectRight = bisectRight;
|
18042 | exports.bisector = bisector;
|
18043 | exports.blob = blob;
|
18044 | exports.brush = brush;
|
18045 | exports.brushSelection = brushSelection;
|
18046 | exports.brushX = brushX;
|
18047 | exports.brushY = brushY;
|
18048 | exports.buffer = buffer;
|
18049 | exports.chord = chord;
|
18050 | exports.clientPoint = point;
|
18051 | exports.cluster = cluster;
|
18052 | exports.color = color;
|
18053 | exports.contourDensity = density;
|
18054 | exports.contours = contours;
|
18055 | exports.create = create;
|
18056 | exports.creator = creator;
|
18057 | exports.cross = cross;
|
18058 | exports.csv = csv$1;
|
18059 | exports.csvFormat = csvFormat;
|
18060 | exports.csvFormatBody = csvFormatBody;
|
18061 | exports.csvFormatRow = csvFormatRow;
|
18062 | exports.csvFormatRows = csvFormatRows;
|
18063 | exports.csvFormatValue = csvFormatValue;
|
18064 | exports.csvParse = csvParse;
|
18065 | exports.csvParseRows = csvParseRows;
|
18066 | exports.cubehelix = cubehelix;
|
18067 | exports.curveBasis = basis$2;
|
18068 | exports.curveBasisClosed = basisClosed$1;
|
18069 | exports.curveBasisOpen = basisOpen;
|
18070 | exports.curveBundle = bundle;
|
18071 | exports.curveCardinal = cardinal;
|
18072 | exports.curveCardinalClosed = cardinalClosed;
|
18073 | exports.curveCardinalOpen = cardinalOpen;
|
18074 | exports.curveCatmullRom = catmullRom;
|
18075 | exports.curveCatmullRomClosed = catmullRomClosed;
|
18076 | exports.curveCatmullRomOpen = catmullRomOpen;
|
18077 | exports.curveLinear = curveLinear;
|
18078 | exports.curveLinearClosed = linearClosed;
|
18079 | exports.curveMonotoneX = monotoneX;
|
18080 | exports.curveMonotoneY = monotoneY;
|
18081 | exports.curveNatural = natural;
|
18082 | exports.curveStep = step;
|
18083 | exports.curveStepAfter = stepAfter;
|
18084 | exports.curveStepBefore = stepBefore;
|
18085 | exports.customEvent = customEvent;
|
18086 | exports.descending = descending;
|
18087 | exports.deviation = deviation;
|
18088 | exports.dispatch = dispatch;
|
18089 | exports.drag = drag;
|
18090 | exports.dragDisable = dragDisable;
|
18091 | exports.dragEnable = yesdrag;
|
18092 | exports.dsv = dsv;
|
18093 | exports.dsvFormat = dsvFormat;
|
18094 | exports.easeBack = backInOut;
|
18095 | exports.easeBackIn = backIn;
|
18096 | exports.easeBackInOut = backInOut;
|
18097 | exports.easeBackOut = backOut;
|
18098 | exports.easeBounce = bounceOut;
|
18099 | exports.easeBounceIn = bounceIn;
|
18100 | exports.easeBounceInOut = bounceInOut;
|
18101 | exports.easeBounceOut = bounceOut;
|
18102 | exports.easeCircle = circleInOut;
|
18103 | exports.easeCircleIn = circleIn;
|
18104 | exports.easeCircleInOut = circleInOut;
|
18105 | exports.easeCircleOut = circleOut;
|
18106 | exports.easeCubic = cubicInOut;
|
18107 | exports.easeCubicIn = cubicIn;
|
18108 | exports.easeCubicInOut = cubicInOut;
|
18109 | exports.easeCubicOut = cubicOut;
|
18110 | exports.easeElastic = elasticOut;
|
18111 | exports.easeElasticIn = elasticIn;
|
18112 | exports.easeElasticInOut = elasticInOut;
|
18113 | exports.easeElasticOut = elasticOut;
|
18114 | exports.easeExp = expInOut;
|
18115 | exports.easeExpIn = expIn;
|
18116 | exports.easeExpInOut = expInOut;
|
18117 | exports.easeExpOut = expOut;
|
18118 | exports.easeLinear = linear$1;
|
18119 | exports.easePoly = polyInOut;
|
18120 | exports.easePolyIn = polyIn;
|
18121 | exports.easePolyInOut = polyInOut;
|
18122 | exports.easePolyOut = polyOut;
|
18123 | exports.easeQuad = quadInOut;
|
18124 | exports.easeQuadIn = quadIn;
|
18125 | exports.easeQuadInOut = quadInOut;
|
18126 | exports.easeQuadOut = quadOut;
|
18127 | exports.easeSin = sinInOut;
|
18128 | exports.easeSinIn = sinIn;
|
18129 | exports.easeSinInOut = sinInOut;
|
18130 | exports.easeSinOut = sinOut;
|
18131 | exports.entries = entries;
|
18132 | exports.extent = extent;
|
18133 | exports.forceCenter = center$1;
|
18134 | exports.forceCollide = collide;
|
18135 | exports.forceLink = link;
|
18136 | exports.forceManyBody = manyBody;
|
18137 | exports.forceRadial = radial;
|
18138 | exports.forceSimulation = simulation;
|
18139 | exports.forceX = x$2;
|
18140 | exports.forceY = y$2;
|
18141 | exports.formatDefaultLocale = defaultLocale;
|
18142 | exports.formatLocale = formatLocale;
|
18143 | exports.formatSpecifier = formatSpecifier;
|
18144 | exports.geoAlbers = albers;
|
18145 | exports.geoAlbersUsa = albersUsa;
|
18146 | exports.geoArea = area$1;
|
18147 | exports.geoAzimuthalEqualArea = azimuthalEqualArea;
|
18148 | exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw;
|
18149 | exports.geoAzimuthalEquidistant = azimuthalEquidistant;
|
18150 | exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw;
|
18151 | exports.geoBounds = bounds;
|
18152 | exports.geoCentroid = centroid;
|
18153 | exports.geoCircle = circle;
|
18154 | exports.geoClipAntimeridian = clipAntimeridian;
|
18155 | exports.geoClipCircle = clipCircle;
|
18156 | exports.geoClipExtent = extent$1;
|
18157 | exports.geoClipRectangle = clipRectangle;
|
18158 | exports.geoConicConformal = conicConformal;
|
18159 | exports.geoConicConformalRaw = conicConformalRaw;
|
18160 | exports.geoConicEqualArea = conicEqualArea;
|
18161 | exports.geoConicEqualAreaRaw = conicEqualAreaRaw;
|
18162 | exports.geoConicEquidistant = conicEquidistant;
|
18163 | exports.geoConicEquidistantRaw = conicEquidistantRaw;
|
18164 | exports.geoContains = contains$1;
|
18165 | exports.geoDistance = distance;
|
18166 | exports.geoEqualEarth = equalEarth;
|
18167 | exports.geoEqualEarthRaw = equalEarthRaw;
|
18168 | exports.geoEquirectangular = equirectangular;
|
18169 | exports.geoEquirectangularRaw = equirectangularRaw;
|
18170 | exports.geoGnomonic = gnomonic;
|
18171 | exports.geoGnomonicRaw = gnomonicRaw;
|
18172 | exports.geoGraticule = graticule;
|
18173 | exports.geoGraticule10 = graticule10;
|
18174 | exports.geoIdentity = identity$5;
|
18175 | exports.geoInterpolate = interpolate$1;
|
18176 | exports.geoLength = length$1;
|
18177 | exports.geoMercator = mercator;
|
18178 | exports.geoMercatorRaw = mercatorRaw;
|
18179 | exports.geoNaturalEarth1 = naturalEarth1;
|
18180 | exports.geoNaturalEarth1Raw = naturalEarth1Raw;
|
18181 | exports.geoOrthographic = orthographic;
|
18182 | exports.geoOrthographicRaw = orthographicRaw;
|
18183 | exports.geoPath = index$1;
|
18184 | exports.geoProjection = projection;
|
18185 | exports.geoProjectionMutator = projectionMutator;
|
18186 | exports.geoRotation = rotation;
|
18187 | exports.geoStereographic = stereographic;
|
18188 | exports.geoStereographicRaw = stereographicRaw;
|
18189 | exports.geoStream = geoStream;
|
18190 | exports.geoTransform = transform;
|
18191 | exports.geoTransverseMercator = transverseMercator;
|
18192 | exports.geoTransverseMercatorRaw = transverseMercatorRaw;
|
18193 | exports.gray = gray;
|
18194 | exports.hcl = hcl;
|
18195 | exports.hierarchy = hierarchy;
|
18196 | exports.histogram = histogram;
|
18197 | exports.hsl = hsl;
|
18198 | exports.html = html;
|
18199 | exports.image = image;
|
18200 | exports.interpolate = interpolateValue;
|
18201 | exports.interpolateArray = array$1;
|
18202 | exports.interpolateBasis = basis$1;
|
18203 | exports.interpolateBasisClosed = basisClosed;
|
18204 | exports.interpolateBlues = Blues;
|
18205 | exports.interpolateBrBG = BrBG;
|
18206 | exports.interpolateBuGn = BuGn;
|
18207 | exports.interpolateBuPu = BuPu;
|
18208 | exports.interpolateCividis = cividis;
|
18209 | exports.interpolateCool = cool;
|
18210 | exports.interpolateCubehelix = cubehelix$2;
|
18211 | exports.interpolateCubehelixDefault = cubehelix$3;
|
18212 | exports.interpolateCubehelixLong = cubehelixLong;
|
18213 | exports.interpolateDate = date;
|
18214 | exports.interpolateDiscrete = discrete;
|
18215 | exports.interpolateGnBu = GnBu;
|
18216 | exports.interpolateGreens = Greens;
|
18217 | exports.interpolateGreys = Greys;
|
18218 | exports.interpolateHcl = hcl$2;
|
18219 | exports.interpolateHclLong = hclLong;
|
18220 | exports.interpolateHsl = hsl$2;
|
18221 | exports.interpolateHslLong = hslLong;
|
18222 | exports.interpolateHue = hue$1;
|
18223 | exports.interpolateInferno = inferno;
|
18224 | exports.interpolateLab = lab$1;
|
18225 | exports.interpolateMagma = magma;
|
18226 | exports.interpolateNumber = interpolateNumber;
|
18227 | exports.interpolateNumberArray = numberArray;
|
18228 | exports.interpolateObject = object;
|
18229 | exports.interpolateOrRd = OrRd;
|
18230 | exports.interpolateOranges = Oranges;
|
18231 | exports.interpolatePRGn = PRGn;
|
18232 | exports.interpolatePiYG = PiYG;
|
18233 | exports.interpolatePlasma = plasma;
|
18234 | exports.interpolatePuBu = PuBu;
|
18235 | exports.interpolatePuBuGn = PuBuGn;
|
18236 | exports.interpolatePuOr = PuOr;
|
18237 | exports.interpolatePuRd = PuRd;
|
18238 | exports.interpolatePurples = Purples;
|
18239 | exports.interpolateRainbow = rainbow;
|
18240 | exports.interpolateRdBu = RdBu;
|
18241 | exports.interpolateRdGy = RdGy;
|
18242 | exports.interpolateRdPu = RdPu;
|
18243 | exports.interpolateRdYlBu = RdYlBu;
|
18244 | exports.interpolateRdYlGn = RdYlGn;
|
18245 | exports.interpolateReds = Reds;
|
18246 | exports.interpolateRgb = interpolateRgb;
|
18247 | exports.interpolateRgbBasis = rgbBasis;
|
18248 | exports.interpolateRgbBasisClosed = rgbBasisClosed;
|
18249 | exports.interpolateRound = interpolateRound;
|
18250 | exports.interpolateSinebow = sinebow;
|
18251 | exports.interpolateSpectral = Spectral;
|
18252 | exports.interpolateString = interpolateString;
|
18253 | exports.interpolateTransformCss = interpolateTransformCss;
|
18254 | exports.interpolateTransformSvg = interpolateTransformSvg;
|
18255 | exports.interpolateTurbo = turbo;
|
18256 | exports.interpolateViridis = viridis;
|
18257 | exports.interpolateWarm = warm;
|
18258 | exports.interpolateYlGn = YlGn;
|
18259 | exports.interpolateYlGnBu = YlGnBu;
|
18260 | exports.interpolateYlOrBr = YlOrBr;
|
18261 | exports.interpolateYlOrRd = YlOrRd;
|
18262 | exports.interpolateZoom = interpolateZoom;
|
18263 | exports.interrupt = interrupt;
|
18264 | exports.interval = interval$1;
|
18265 | exports.isoFormat = formatIso;
|
18266 | exports.isoParse = parseIso;
|
18267 | exports.json = json;
|
18268 | exports.keys = keys;
|
18269 | exports.lab = lab;
|
18270 | exports.lch = lch;
|
18271 | exports.line = line;
|
18272 | exports.lineRadial = lineRadial$1;
|
18273 | exports.linkHorizontal = linkHorizontal;
|
18274 | exports.linkRadial = linkRadial;
|
18275 | exports.linkVertical = linkVertical;
|
18276 | exports.local = local;
|
18277 | exports.map = map$1;
|
18278 | exports.matcher = matcher;
|
18279 | exports.max = max;
|
18280 | exports.mean = mean;
|
18281 | exports.median = median;
|
18282 | exports.merge = merge;
|
18283 | exports.min = min;
|
18284 | exports.mouse = mouse;
|
18285 | exports.namespace = namespace;
|
18286 | exports.namespaces = namespaces;
|
18287 | exports.nest = nest;
|
18288 | exports.now = now;
|
18289 | exports.pack = index$2;
|
18290 | exports.packEnclose = enclose;
|
18291 | exports.packSiblings = siblings;
|
18292 | exports.pairs = pairs;
|
18293 | exports.partition = partition;
|
18294 | exports.path = path;
|
18295 | exports.permute = permute;
|
18296 | exports.pie = pie;
|
18297 | exports.piecewise = piecewise;
|
18298 | exports.pointRadial = pointRadial;
|
18299 | exports.polygonArea = area$2;
|
18300 | exports.polygonCentroid = centroid$1;
|
18301 | exports.polygonContains = contains$2;
|
18302 | exports.polygonHull = hull;
|
18303 | exports.polygonLength = length$2;
|
18304 | exports.precisionFixed = precisionFixed;
|
18305 | exports.precisionPrefix = precisionPrefix;
|
18306 | exports.precisionRound = precisionRound;
|
18307 | exports.quadtree = quadtree;
|
18308 | exports.quantile = threshold;
|
18309 | exports.quantize = quantize;
|
18310 | exports.radialArea = areaRadial;
|
18311 | exports.radialLine = lineRadial$1;
|
18312 | exports.randomBates = bates;
|
18313 | exports.randomExponential = exponential$1;
|
18314 | exports.randomIrwinHall = irwinHall;
|
18315 | exports.randomLogNormal = logNormal;
|
18316 | exports.randomNormal = normal;
|
18317 | exports.randomUniform = uniform;
|
18318 | exports.range = sequence;
|
18319 | exports.rgb = rgb;
|
18320 | exports.ribbon = ribbon;
|
18321 | exports.scaleBand = band;
|
18322 | exports.scaleDiverging = diverging;
|
18323 | exports.scaleDivergingLog = divergingLog;
|
18324 | exports.scaleDivergingPow = divergingPow;
|
18325 | exports.scaleDivergingSqrt = divergingSqrt;
|
18326 | exports.scaleDivergingSymlog = divergingSymlog;
|
18327 | exports.scaleIdentity = identity$7;
|
18328 | exports.scaleImplicit = implicit;
|
18329 | exports.scaleLinear = linear$2;
|
18330 | exports.scaleLog = log$1;
|
18331 | exports.scaleOrdinal = ordinal;
|
18332 | exports.scalePoint = point$1;
|
18333 | exports.scalePow = pow$1;
|
18334 | exports.scaleQuantile = quantile;
|
18335 | exports.scaleQuantize = quantize$1;
|
18336 | exports.scaleSequential = sequential;
|
18337 | exports.scaleSequentialLog = sequentialLog;
|
18338 | exports.scaleSequentialPow = sequentialPow;
|
18339 | exports.scaleSequentialQuantile = sequentialQuantile;
|
18340 | exports.scaleSequentialSqrt = sequentialSqrt;
|
18341 | exports.scaleSequentialSymlog = sequentialSymlog;
|
18342 | exports.scaleSqrt = sqrt$1;
|
18343 | exports.scaleSymlog = symlog;
|
18344 | exports.scaleThreshold = threshold$1;
|
18345 | exports.scaleTime = time;
|
18346 | exports.scaleUtc = utcTime;
|
18347 | exports.scan = scan;
|
18348 | exports.schemeAccent = Accent;
|
18349 | exports.schemeBlues = scheme$l;
|
18350 | exports.schemeBrBG = scheme;
|
18351 | exports.schemeBuGn = scheme$9;
|
18352 | exports.schemeBuPu = scheme$a;
|
18353 | exports.schemeCategory10 = category10;
|
18354 | exports.schemeDark2 = Dark2;
|
18355 | exports.schemeGnBu = scheme$b;
|
18356 | exports.schemeGreens = scheme$m;
|
18357 | exports.schemeGreys = scheme$n;
|
18358 | exports.schemeOrRd = scheme$c;
|
18359 | exports.schemeOranges = scheme$q;
|
18360 | exports.schemePRGn = scheme$1;
|
18361 | exports.schemePaired = Paired;
|
18362 | exports.schemePastel1 = Pastel1;
|
18363 | exports.schemePastel2 = Pastel2;
|
18364 | exports.schemePiYG = scheme$2;
|
18365 | exports.schemePuBu = scheme$e;
|
18366 | exports.schemePuBuGn = scheme$d;
|
18367 | exports.schemePuOr = scheme$3;
|
18368 | exports.schemePuRd = scheme$f;
|
18369 | exports.schemePurples = scheme$o;
|
18370 | exports.schemeRdBu = scheme$4;
|
18371 | exports.schemeRdGy = scheme$5;
|
18372 | exports.schemeRdPu = scheme$g;
|
18373 | exports.schemeRdYlBu = scheme$6;
|
18374 | exports.schemeRdYlGn = scheme$7;
|
18375 | exports.schemeReds = scheme$p;
|
18376 | exports.schemeSet1 = Set1;
|
18377 | exports.schemeSet2 = Set2;
|
18378 | exports.schemeSet3 = Set3;
|
18379 | exports.schemeSpectral = scheme$8;
|
18380 | exports.schemeTableau10 = Tableau10;
|
18381 | exports.schemeYlGn = scheme$i;
|
18382 | exports.schemeYlGnBu = scheme$h;
|
18383 | exports.schemeYlOrBr = scheme$j;
|
18384 | exports.schemeYlOrRd = scheme$k;
|
18385 | exports.select = select;
|
18386 | exports.selectAll = selectAll;
|
18387 | exports.selection = selection;
|
18388 | exports.selector = selector;
|
18389 | exports.selectorAll = selectorAll;
|
18390 | exports.set = set$2;
|
18391 | exports.shuffle = shuffle;
|
18392 | exports.stack = stack;
|
18393 | exports.stackOffsetDiverging = diverging$1;
|
18394 | exports.stackOffsetExpand = expand;
|
18395 | exports.stackOffsetNone = none$1;
|
18396 | exports.stackOffsetSilhouette = silhouette;
|
18397 | exports.stackOffsetWiggle = wiggle;
|
18398 | exports.stackOrderAppearance = appearance;
|
18399 | exports.stackOrderAscending = ascending$3;
|
18400 | exports.stackOrderDescending = descending$2;
|
18401 | exports.stackOrderInsideOut = insideOut;
|
18402 | exports.stackOrderNone = none$2;
|
18403 | exports.stackOrderReverse = reverse;
|
18404 | exports.stratify = stratify;
|
18405 | exports.style = styleValue;
|
18406 | exports.sum = sum;
|
18407 | exports.svg = svg;
|
18408 | exports.symbol = symbol;
|
18409 | exports.symbolCircle = circle$2;
|
18410 | exports.symbolCross = cross$2;
|
18411 | exports.symbolDiamond = diamond;
|
18412 | exports.symbolSquare = square;
|
18413 | exports.symbolStar = star;
|
18414 | exports.symbolTriangle = triangle;
|
18415 | exports.symbolWye = wye;
|
18416 | exports.symbols = symbols;
|
18417 | exports.text = text;
|
18418 | exports.thresholdFreedmanDiaconis = freedmanDiaconis;
|
18419 | exports.thresholdScott = scott;
|
18420 | exports.thresholdSturges = thresholdSturges;
|
18421 | exports.tickFormat = tickFormat;
|
18422 | exports.tickIncrement = tickIncrement;
|
18423 | exports.tickStep = tickStep;
|
18424 | exports.ticks = ticks;
|
18425 | exports.timeDay = day;
|
18426 | exports.timeDays = days;
|
18427 | exports.timeFormatDefaultLocale = defaultLocale$1;
|
18428 | exports.timeFormatLocale = formatLocale$1;
|
18429 | exports.timeFriday = friday;
|
18430 | exports.timeFridays = fridays;
|
18431 | exports.timeHour = hour;
|
18432 | exports.timeHours = hours;
|
18433 | exports.timeInterval = newInterval;
|
18434 | exports.timeMillisecond = millisecond;
|
18435 | exports.timeMilliseconds = milliseconds;
|
18436 | exports.timeMinute = minute;
|
18437 | exports.timeMinutes = minutes;
|
18438 | exports.timeMonday = monday;
|
18439 | exports.timeMondays = mondays;
|
18440 | exports.timeMonth = month;
|
18441 | exports.timeMonths = months;
|
18442 | exports.timeSaturday = saturday;
|
18443 | exports.timeSaturdays = saturdays;
|
18444 | exports.timeSecond = second;
|
18445 | exports.timeSeconds = seconds;
|
18446 | exports.timeSunday = sunday;
|
18447 | exports.timeSundays = sundays;
|
18448 | exports.timeThursday = thursday;
|
18449 | exports.timeThursdays = thursdays;
|
18450 | exports.timeTuesday = tuesday;
|
18451 | exports.timeTuesdays = tuesdays;
|
18452 | exports.timeWednesday = wednesday;
|
18453 | exports.timeWednesdays = wednesdays;
|
18454 | exports.timeWeek = sunday;
|
18455 | exports.timeWeeks = sundays;
|
18456 | exports.timeYear = year;
|
18457 | exports.timeYears = years;
|
18458 | exports.timeout = timeout$1;
|
18459 | exports.timer = timer;
|
18460 | exports.timerFlush = timerFlush;
|
18461 | exports.touch = touch;
|
18462 | exports.touches = touches;
|
18463 | exports.transition = transition;
|
18464 | exports.transpose = transpose;
|
18465 | exports.tree = tree;
|
18466 | exports.treemap = index$3;
|
18467 | exports.treemapBinary = binary;
|
18468 | exports.treemapDice = treemapDice;
|
18469 | exports.treemapResquarify = resquarify;
|
18470 | exports.treemapSlice = treemapSlice;
|
18471 | exports.treemapSliceDice = sliceDice;
|
18472 | exports.treemapSquarify = squarify;
|
18473 | exports.tsv = tsv$1;
|
18474 | exports.tsvFormat = tsvFormat;
|
18475 | exports.tsvFormatBody = tsvFormatBody;
|
18476 | exports.tsvFormatRow = tsvFormatRow;
|
18477 | exports.tsvFormatRows = tsvFormatRows;
|
18478 | exports.tsvFormatValue = tsvFormatValue;
|
18479 | exports.tsvParse = tsvParse;
|
18480 | exports.tsvParseRows = tsvParseRows;
|
18481 | exports.utcDay = utcDay;
|
18482 | exports.utcDays = utcDays;
|
18483 | exports.utcFriday = utcFriday;
|
18484 | exports.utcFridays = utcFridays;
|
18485 | exports.utcHour = utcHour;
|
18486 | exports.utcHours = utcHours;
|
18487 | exports.utcMillisecond = millisecond;
|
18488 | exports.utcMilliseconds = milliseconds;
|
18489 | exports.utcMinute = utcMinute;
|
18490 | exports.utcMinutes = utcMinutes;
|
18491 | exports.utcMonday = utcMonday;
|
18492 | exports.utcMondays = utcMondays;
|
18493 | exports.utcMonth = utcMonth;
|
18494 | exports.utcMonths = utcMonths;
|
18495 | exports.utcSaturday = utcSaturday;
|
18496 | exports.utcSaturdays = utcSaturdays;
|
18497 | exports.utcSecond = second;
|
18498 | exports.utcSeconds = seconds;
|
18499 | exports.utcSunday = utcSunday;
|
18500 | exports.utcSundays = utcSundays;
|
18501 | exports.utcThursday = utcThursday;
|
18502 | exports.utcThursdays = utcThursdays;
|
18503 | exports.utcTuesday = utcTuesday;
|
18504 | exports.utcTuesdays = utcTuesdays;
|
18505 | exports.utcWednesday = utcWednesday;
|
18506 | exports.utcWednesdays = utcWednesdays;
|
18507 | exports.utcWeek = utcSunday;
|
18508 | exports.utcWeeks = utcSundays;
|
18509 | exports.utcYear = utcYear;
|
18510 | exports.utcYears = utcYears;
|
18511 | exports.values = values;
|
18512 | exports.variance = variance;
|
18513 | exports.version = version;
|
18514 | exports.voronoi = voronoi;
|
18515 | exports.window = defaultView;
|
18516 | exports.xml = xml;
|
18517 | exports.zip = zip;
|
18518 | exports.zoom = zoom;
|
18519 | exports.zoomIdentity = identity$9;
|
18520 | exports.zoomTransform = transform$1;
|
18521 |
|
18522 | Object.defineProperty(exports, '__esModule', { value: true });
|
18523 |
|
18524 | }));
|
18525 |
|
\ | No newline at end of file |