| 1 |
// https://d3js.org v7.9.0 Copyright 2010-2023 Mike Bostock |
| 2 |
(function (global, factory) { |
| 3 |
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : |
| 4 |
typeof define === 'function' && define.icinga ? define(['exports'], factory) : |
| 5 |
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {})); |
| 6 |
})(this, (function (exports) { 'use strict'; |
| 7 |
|
| 8 |
var version = "7.9.0"; |
| 9 |
|
| 10 |
function ascending$3(a, b) { |
| 11 |
return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; |
| 12 |
} |
| 13 |
|
| 14 |
function descending$2(a, b) { |
| 15 |
return a == null || b == null ? NaN |
| 16 |
: b < a ? -1 |
| 17 |
: b > a ? 1 |
| 18 |
: b >= a ? 0 |
| 19 |
: NaN; |
| 20 |
} |
| 21 |
|
| 22 |
function bisector(f) { |
| 23 |
let compare1, compare2, delta; |
| 24 |
|
| 25 |
// If an accessor is specified, promote it to a comparator. In this case we |
| 26 |
// can test whether the search value is (self-) comparable. We can’t do this |
| 27 |
// for a comparator (except for specific, known comparators) because we can’t |
| 28 |
// tell if the comparator is symmetric, and an asymmetric comparator can’t be |
| 29 |
// used to test whether a single value is comparable. |
| 30 |
if (f.length !== 2) { |
| 31 |
compare1 = ascending$3; |
| 32 |
compare2 = (d, x) => ascending$3(f(d), x); |
| 33 |
delta = (d, x) => f(d) - x; |
| 34 |
} else { |
| 35 |
compare1 = f === ascending$3 || f === descending$2 ? f : zero$1; |
| 36 |
compare2 = f; |
| 37 |
delta = f; |
| 38 |
} |
| 39 |
|
| 40 |
function left(a, x, lo = 0, hi = a.length) { |
| 41 |
if (lo < hi) { |
| 42 |
if (compare1(x, x) !== 0) return hi; |
| 43 |
do { |
| 44 |
const mid = (lo + hi) >>> 1; |
| 45 |
if (compare2(a[mid], x) < 0) lo = mid + 1; |
| 46 |
else hi = mid; |
| 47 |
} while (lo < hi); |
| 48 |
} |
| 49 |
return lo; |
| 50 |
} |
| 51 |
|
| 52 |
function right(a, x, lo = 0, hi = a.length) { |
| 53 |
if (lo < hi) { |
| 54 |
if (compare1(x, x) !== 0) return hi; |
| 55 |
do { |
| 56 |
const mid = (lo + hi) >>> 1; |
| 57 |
if (compare2(a[mid], x) <= 0) lo = mid + 1; |
| 58 |
else hi = mid; |
| 59 |
} while (lo < hi); |
| 60 |
} |
| 61 |
return lo; |
| 62 |
} |
| 63 |
|
| 64 |
function center(a, x, lo = 0, hi = a.length) { |
| 65 |
const i = left(a, x, lo, hi - 1); |
| 66 |
return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i; |
| 67 |
} |
| 68 |
|
| 69 |
return {left, center, right}; |
| 70 |
} |
| 71 |
|
| 72 |
function zero$1() { |
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
function number$3(x) { |
| 77 |
return x === null ? NaN : +x; |
| 78 |
} |
| 79 |
|
| 80 |
function* numbers(values, valueof) { |
| 81 |
if (valueof === undefined) { |
| 82 |
for (let value of values) { |
| 83 |
if (value != null && (value = +value) >= value) { |
| 84 |
yield value; |
| 85 |
} |
| 86 |
} |
| 87 |
} else { |
| 88 |
let index = -1; |
| 89 |
for (let value of values) { |
| 90 |
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) { |
| 91 |
yield value; |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
const ascendingBisect = bisector(ascending$3); |
| 98 |
const bisectRight = ascendingBisect.right; |
| 99 |
const bisectLeft = ascendingBisect.left; |
| 100 |
const bisectCenter = bisector(number$3).center; |
| 101 |
var bisect = bisectRight; |
| 102 |
|
| 103 |
function blur(values, r) { |
| 104 |
if (!((r = +r) >= 0)) throw new RangeError("invalid r"); |
| 105 |
let length = values.length; |
| 106 |
if (!((length = Math.floor(length)) >= 0)) throw new RangeError("invalid length"); |
| 107 |
if (!length || !r) return values; |
| 108 |
const blur = blurf(r); |
| 109 |
const temp = values.slice(); |
| 110 |
blur(values, temp, 0, length, 1); |
| 111 |
blur(temp, values, 0, length, 1); |
| 112 |
blur(values, temp, 0, length, 1); |
| 113 |
return values; |
| 114 |
} |
| 115 |
|
| 116 |
const blur2 = Blur2(blurf); |
| 117 |
|
| 118 |
const blurImage = Blur2(blurfImage); |
| 119 |
|
| 120 |
function Blur2(blur) { |
| 121 |
return function(data, rx, ry = rx) { |
| 122 |
if (!((rx = +rx) >= 0)) throw new RangeError("invalid rx"); |
| 123 |
if (!((ry = +ry) >= 0)) throw new RangeError("invalid ry"); |
| 124 |
let {data: values, width, height} = data; |
| 125 |
if (!((width = Math.floor(width)) >= 0)) throw new RangeError("invalid width"); |
| 126 |
if (!((height = Math.floor(height !== undefined ? height : values.length / width)) >= 0)) throw new RangeError("invalid height"); |
| 127 |
if (!width || !height || (!rx && !ry)) return data; |
| 128 |
const blurx = rx && blur(rx); |
| 129 |
const blury = ry && blur(ry); |
| 130 |
const temp = values.slice(); |
| 131 |
if (blurx && blury) { |
| 132 |
blurh(blurx, temp, values, width, height); |
| 133 |
blurh(blurx, values, temp, width, height); |
| 134 |
blurh(blurx, temp, values, width, height); |
| 135 |
blurv(blury, values, temp, width, height); |
| 136 |
blurv(blury, temp, values, width, height); |
| 137 |
blurv(blury, values, temp, width, height); |
| 138 |
} else if (blurx) { |
| 139 |
blurh(blurx, values, temp, width, height); |
| 140 |
blurh(blurx, temp, values, width, height); |
| 141 |
blurh(blurx, values, temp, width, height); |
| 142 |
} else if (blury) { |
| 143 |
blurv(blury, values, temp, width, height); |
| 144 |
blurv(blury, temp, values, width, height); |
| 145 |
blurv(blury, values, temp, width, height); |
| 146 |
} |
| 147 |
return data; |
| 148 |
}; |
| 149 |
} |
| 150 |
|
| 151 |
function blurh(blur, T, S, w, h) { |
| 152 |
for (let y = 0, n = w * h; y < n;) { |
| 153 |
blur(T, S, y, y += w, 1); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
function blurv(blur, T, S, w, h) { |
| 158 |
for (let x = 0, n = w * h; x < w; ++x) { |
| 159 |
blur(T, S, x, x + n, w); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
function blurfImage(radius) { |
| 164 |
const blur = blurf(radius); |
| 165 |
return (T, S, start, stop, step) => { |
| 166 |
start <<= 2, stop <<= 2, step <<= 2; |
| 167 |
blur(T, S, start + 0, stop + 0, step); |
| 168 |
blur(T, S, start + 1, stop + 1, step); |
| 169 |
blur(T, S, start + 2, stop + 2, step); |
| 170 |
blur(T, S, start + 3, stop + 3, step); |
| 171 |
}; |
| 172 |
} |
| 173 |
|
| 174 |
// Given a target array T, a source array S, sets each value T[i] to the average |
| 175 |
// of {S[i - r], …, S[i], …, S[i + r]}, where r = ⌊radius⌋, start <= i < stop, |
| 176 |
// for each i, i + step, i + 2 * step, etc., and where S[j] is clamped between |
| 177 |
// S[start] (inclusive) and S[stop] (exclusive). If the given radius is not an |
| 178 |
// integer, S[i - r - 1] and S[i + r + 1] are added to the sum, each weighted |
| 179 |
// according to r - ⌊radius⌋. |
| 180 |
function blurf(radius) { |
| 181 |
const radius0 = Math.floor(radius); |
| 182 |
if (radius0 === radius) return bluri(radius); |
| 183 |
const t = radius - radius0; |
| 184 |
const w = 2 * radius + 1; |
| 185 |
return (T, S, start, stop, step) => { // stop must be aligned! |
| 186 |
if (!((stop -= step) >= start)) return; // inclusive stop |
| 187 |
let sum = radius0 * S[start]; |
| 188 |
const s0 = step * radius0; |
| 189 |
const s1 = s0 + step; |
| 190 |
for (let i = start, j = start + s0; i < j; i += step) { |
| 191 |
sum += S[Math.min(stop, i)]; |
| 192 |
} |
| 193 |
for (let i = start, j = stop; i <= j; i += step) { |
| 194 |
sum += S[Math.min(stop, i + s0)]; |
| 195 |
T[i] = (sum + t * (S[Math.max(start, i - s1)] + S[Math.min(stop, i + s1)])) / w; |
| 196 |
sum -= S[Math.max(start, i - s0)]; |
| 197 |
} |
| 198 |
}; |
| 199 |
} |
| 200 |
|
| 201 |
// Like blurf, but optimized for integer radius. |
| 202 |
function bluri(radius) { |
| 203 |
const w = 2 * radius + 1; |
| 204 |
return (T, S, start, stop, step) => { // stop must be aligned! |
| 205 |
if (!((stop -= step) >= start)) return; // inclusive stop |
| 206 |
let sum = radius * S[start]; |
| 207 |
const s = step * radius; |
| 208 |
for (let i = start, j = start + s; i < j; i += step) { |
| 209 |
sum += S[Math.min(stop, i)]; |
| 210 |
} |
| 211 |
for (let i = start, j = stop; i <= j; i += step) { |
| 212 |
sum += S[Math.min(stop, i + s)]; |
| 213 |
T[i] = sum / w; |
| 214 |
sum -= S[Math.max(start, i - s)]; |
| 215 |
} |
| 216 |
}; |
| 217 |
} |
| 218 |
|
| 219 |
function count$1(values, valueof) { |
| 220 |
let count = 0; |
| 221 |
if (valueof === undefined) { |
| 222 |
for (let value of values) { |
| 223 |
if (value != null && (value = +value) >= value) { |
| 224 |
++count; |
| 225 |
} |
| 226 |
} |
| 227 |
} else { |
| 228 |
let index = -1; |
| 229 |
for (let value of values) { |
| 230 |
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) { |
| 231 |
++count; |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
return count; |
| 236 |
} |
| 237 |
|
| 238 |
function length$3(array) { |
| 239 |
return array.length | 0; |
| 240 |
} |
| 241 |
|
| 242 |
function empty$2(length) { |
| 243 |
return !(length > 0); |
| 244 |
} |
| 245 |
|
| 246 |
function arrayify(values) { |
| 247 |
return typeof values !== "object" || "length" in values ? values : Array.from(values); |
| 248 |
} |
| 249 |
|
| 250 |
function reducer(reduce) { |
| 251 |
return values => reduce(...values); |
| 252 |
} |
| 253 |
|
| 254 |
function cross$2(...values) { |
| 255 |
const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop()); |
| 256 |
values = values.map(arrayify); |
| 257 |
const lengths = values.map(length$3); |
| 258 |
const j = values.length - 1; |
| 259 |
const index = new Array(j + 1).fill(0); |
| 260 |
const product = []; |
| 261 |
if (j < 0 || lengths.some(empty$2)) return product; |
| 262 |
while (true) { |
| 263 |
product.push(index.map((j, i) => values[i][j])); |
| 264 |
let i = j; |
| 265 |
while (++index[i] === lengths[i]) { |
| 266 |
if (i === 0) return reduce ? product.map(reduce) : product; |
| 267 |
index[i--] = 0; |
| 268 |
} |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
function cumsum(values, valueof) { |
| 273 |
var sum = 0, index = 0; |
| 274 |
return Float64Array.from(values, valueof === undefined |
| 275 |
? v => (sum += +v || 0) |
| 276 |
: v => (sum += +valueof(v, index++, values) || 0)); |
| 277 |
} |
| 278 |
|
| 279 |
function variance(values, valueof) { |
| 280 |
let count = 0; |
| 281 |
let delta; |
| 282 |
let mean = 0; |
| 283 |
let sum = 0; |
| 284 |
if (valueof === undefined) { |
| 285 |
for (let value of values) { |
| 286 |
if (value != null && (value = +value) >= value) { |
| 287 |
delta = value - mean; |
| 288 |
mean += delta / ++count; |
| 289 |
sum += delta * (value - mean); |
| 290 |
} |
| 291 |
} |
| 292 |
} else { |
| 293 |
let index = -1; |
| 294 |
for (let value of values) { |
| 295 |
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) { |
| 296 |
delta = value - mean; |
| 297 |
mean += delta / ++count; |
| 298 |
sum += delta * (value - mean); |
| 299 |
} |
| 300 |
} |
| 301 |
} |
| 302 |
if (count > 1) return sum / (count - 1); |
| 303 |
} |
| 304 |
|
| 305 |
function deviation(values, valueof) { |
| 306 |
const v = variance(values, valueof); |
| 307 |
return v ? Math.sqrt(v) : v; |
| 308 |
} |
| 309 |
|
| 310 |
function extent$1(values, valueof) { |
| 311 |
let min; |
| 312 |
let max; |
| 313 |
if (valueof === undefined) { |
| 314 |
for (const value of values) { |
| 315 |
if (value != null) { |
| 316 |
if (min === undefined) { |
| 317 |
if (value >= value) min = max = value; |
| 318 |
} else { |
| 319 |
if (min > value) min = value; |
| 320 |
if (max < value) max = value; |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
} else { |
| 325 |
let index = -1; |
| 326 |
for (let value of values) { |
| 327 |
if ((value = valueof(value, ++index, values)) != null) { |
| 328 |
if (min === undefined) { |
| 329 |
if (value >= value) min = max = value; |
| 330 |
} else { |
| 331 |
if (min > value) min = value; |
| 332 |
if (max < value) max = value; |
| 333 |
} |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
return [min, max]; |
| 338 |
} |
| 339 |
|
| 340 |
// https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Modules/mathmodule.c#L1423 |
| 341 |
class Adder { |
| 342 |
constructor() { |
| 343 |
this._partials = new Float64Array(32); |
| 344 |
this._n = 0; |
| 345 |
} |
| 346 |
add(x) { |
| 347 |
const p = this._partials; |
| 348 |
let i = 0; |
| 349 |
for (let j = 0; j < this._n && j < 32; j++) { |
| 350 |
const y = p[j], |
| 351 |
hi = x + y, |
| 352 |
lo = Math.abs(x) < Math.abs(y) ? x - (hi - y) : y - (hi - x); |
| 353 |
if (lo) p[i++] = lo; |
| 354 |
x = hi; |
| 355 |
} |
| 356 |
p[i] = x; |
| 357 |
this._n = i + 1; |
| 358 |
return this; |
| 359 |
} |
| 360 |
valueOf() { |
| 361 |
const p = this._partials; |
| 362 |
let n = this._n, x, y, lo, hi = 0; |
| 363 |
if (n > 0) { |
| 364 |
hi = p[--n]; |
| 365 |
while (n > 0) { |
| 366 |
x = hi; |
| 367 |
y = p[--n]; |
| 368 |
hi = x + y; |
| 369 |
lo = y - (hi - x); |
| 370 |
if (lo) break; |
| 371 |
} |
| 372 |
if (n > 0 && ((lo < 0 && p[n - 1] < 0) || (lo > 0 && p[n - 1] > 0))) { |
| 373 |
y = lo * 2; |
| 374 |
x = hi + y; |
| 375 |
if (y == x - hi) hi = x; |
| 376 |
} |
| 377 |
} |
| 378 |
return hi; |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
function fsum(values, valueof) { |
| 383 |
const adder = new Adder(); |
| 384 |
if (valueof === undefined) { |
| 385 |
for (let value of values) { |
| 386 |
if (value = +value) { |
| 387 |
adder.add(value); |
| 388 |
} |
| 389 |
} |
| 390 |
} else { |
| 391 |
let index = -1; |
| 392 |
for (let value of values) { |
| 393 |
if (value = +valueof(value, ++index, values)) { |
| 394 |
adder.add(value); |
| 395 |
} |
| 396 |
} |
| 397 |
} |
| 398 |
return +adder; |
| 399 |
} |
| 400 |
|
| 401 |
function fcumsum(values, valueof) { |
| 402 |
const adder = new Adder(); |
| 403 |
let index = -1; |
| 404 |
return Float64Array.from(values, valueof === undefined |
| 405 |
? v => adder.add(+v || 0) |
| 406 |
: v => adder.add(+valueof(v, ++index, values) || 0) |
| 407 |
); |
| 408 |
} |
| 409 |
|
| 410 |
class InternMap extends Map { |
| 411 |
constructor(entries, key = keyof) { |
| 412 |
super(); |
| 413 |
Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}}); |
| 414 |
if (entries != null) for (const [key, value] of entries) this.set(key, value); |
| 415 |
} |
| 416 |
get(key) { |
| 417 |
return super.get(intern_get(this, key)); |
| 418 |
} |
| 419 |
has(key) { |
| 420 |
return super.has(intern_get(this, key)); |
| 421 |
} |
| 422 |
set(key, value) { |
| 423 |
return super.set(intern_set(this, key), value); |
| 424 |
} |
| 425 |
delete(key) { |
| 426 |
return super.delete(intern_delete(this, key)); |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
class InternSet extends Set { |
| 431 |
constructor(values, key = keyof) { |
| 432 |
super(); |
| 433 |
Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}}); |
| 434 |
if (values != null) for (const value of values) this.add(value); |
| 435 |
} |
| 436 |
has(value) { |
| 437 |
return super.has(intern_get(this, value)); |
| 438 |
} |
| 439 |
add(value) { |
| 440 |
return super.add(intern_set(this, value)); |
| 441 |
} |
| 442 |
delete(value) { |
| 443 |
return super.delete(intern_delete(this, value)); |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
function intern_get({_intern, _key}, value) { |
| 448 |
const key = _key(value); |
| 449 |
return _intern.has(key) ? _intern.get(key) : value; |
| 450 |
} |
| 451 |
|
| 452 |
function intern_set({_intern, _key}, value) { |
| 453 |
const key = _key(value); |
| 454 |
if (_intern.has(key)) return _intern.get(key); |
| 455 |
_intern.set(key, value); |
| 456 |
return value; |
| 457 |
} |
| 458 |
|
| 459 |
function intern_delete({_intern, _key}, value) { |
| 460 |
const key = _key(value); |
| 461 |
if (_intern.has(key)) { |
| 462 |
value = _intern.get(key); |
| 463 |
_intern.delete(key); |
| 464 |
} |
| 465 |
return value; |
| 466 |
} |
| 467 |
|
| 468 |
function keyof(value) { |
| 469 |
return value !== null && typeof value === "object" ? value.valueOf() : value; |
| 470 |
} |
| 471 |
|
| 472 |
function identity$9(x) { |
| 473 |
return x; |
| 474 |
} |
| 475 |
|
| 476 |
function group(values, ...keys) { |
| 477 |
return nest(values, identity$9, identity$9, keys); |
| 478 |
} |
| 479 |
|
| 480 |
function groups(values, ...keys) { |
| 481 |
return nest(values, Array.from, identity$9, keys); |
| 482 |
} |
| 483 |
|
| 484 |
function flatten$1(groups, keys) { |
| 485 |
for (let i = 1, n = keys.length; i < n; ++i) { |
| 486 |
groups = groups.flatMap(g => g.pop().map(([key, value]) => [...g, key, value])); |
| 487 |
} |
| 488 |
return groups; |
| 489 |
} |
| 490 |
|
| 491 |
function flatGroup(values, ...keys) { |
| 492 |
return flatten$1(groups(values, ...keys), keys); |
| 493 |
} |
| 494 |
|
| 495 |
function flatRollup(values, reduce, ...keys) { |
| 496 |
return flatten$1(rollups(values, reduce, ...keys), keys); |
| 497 |
} |
| 498 |
|
| 499 |
function rollup(values, reduce, ...keys) { |
| 500 |
return nest(values, identity$9, reduce, keys); |
| 501 |
} |
| 502 |
|
| 503 |
function rollups(values, reduce, ...keys) { |
| 504 |
return nest(values, Array.from, reduce, keys); |
| 505 |
} |
| 506 |
|
| 507 |
function index$4(values, ...keys) { |
| 508 |
return nest(values, identity$9, unique, keys); |
| 509 |
} |
| 510 |
|
| 511 |
function indexes(values, ...keys) { |
| 512 |
return nest(values, Array.from, unique, keys); |
| 513 |
} |
| 514 |
|
| 515 |
function unique(values) { |
| 516 |
if (values.length !== 1) throw new Error("duplicate key"); |
| 517 |
return values[0]; |
| 518 |
} |
| 519 |
|
| 520 |
function nest(values, map, reduce, keys) { |
| 521 |
return (function regroup(values, i) { |
| 522 |
if (i >= keys.length) return reduce(values); |
| 523 |
const groups = new InternMap(); |
| 524 |
const keyof = keys[i++]; |
| 525 |
let index = -1; |
| 526 |
for (const value of values) { |
| 527 |
const key = keyof(value, ++index, values); |
| 528 |
const group = groups.get(key); |
| 529 |
if (group) group.push(value); |
| 530 |
else groups.set(key, [value]); |
| 531 |
} |
| 532 |
for (const [key, values] of groups) { |
| 533 |
groups.set(key, regroup(values, i)); |
| 534 |
} |
| 535 |
return map(groups); |
| 536 |
})(values, 0); |
| 537 |
} |
| 538 |
|
| 539 |
function permute(source, keys) { |
| 540 |
return Array.from(keys, key => source[key]); |
| 541 |
} |
| 542 |
|
| 543 |
function sort(values, ...F) { |
| 544 |
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable"); |
| 545 |
values = Array.from(values); |
| 546 |
let [f] = F; |
| 547 |
if ((f && f.length !== 2) || F.length > 1) { |
| 548 |
const index = Uint32Array.from(values, (d, i) => i); |
| 549 |
if (F.length > 1) { |
| 550 |
F = F.map(f => values.map(f)); |
| 551 |
index.sort((i, j) => { |
| 552 |
for (const f of F) { |
| 553 |
const c = ascendingDefined(f[i], f[j]); |
| 554 |
if (c) return c; |
| 555 |
} |
| 556 |
}); |
| 557 |
} else { |
| 558 |
f = values.map(f); |
| 559 |
index.sort((i, j) => ascendingDefined(f[i], f[j])); |
| 560 |
} |
| 561 |
return permute(values, index); |
| 562 |
} |
| 563 |
return values.sort(compareDefined(f)); |
| 564 |
} |
| 565 |
|
| 566 |
function compareDefined(compare = ascending$3) { |
| 567 |
if (compare === ascending$3) return ascendingDefined; |
| 568 |
if (typeof compare !== "function") throw new TypeError("compare is not a function"); |
| 569 |
return (a, b) => { |
| 570 |
const x = compare(a, b); |
| 571 |
if (x || x === 0) return x; |
| 572 |
return (compare(b, b) === 0) - (compare(a, a) === 0); |
| 573 |
}; |
| 574 |
} |
| 575 |
|
| 576 |
function ascendingDefined(a, b) { |
| 577 |
return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0); |
| 578 |
} |
| 579 |
|
| 580 |
function groupSort(values, reduce, key) { |
| 581 |
return (reduce.length !== 2 |
| 582 |
? sort(rollup(values, reduce, key), (([ak, av], [bk, bv]) => ascending$3(av, bv) || ascending$3(ak, bk))) |
| 583 |
: sort(group(values, key), (([ak, av], [bk, bv]) => reduce(av, bv) || ascending$3(ak, bk)))) |
| 584 |
.map(([key]) => key); |
| 585 |
} |
| 586 |
|
| 587 |
var array$5 = Array.prototype; |
| 588 |
|
| 589 |
var slice$3 = array$5.slice; |
| 590 |
|
| 591 |
function constant$b(x) { |
| 592 |
return () => x; |
| 593 |
} |
| 594 |
|
| 595 |
const e10 = Math.sqrt(50), |
| 596 |
e5 = Math.sqrt(10), |
| 597 |
e2 = Math.sqrt(2); |
| 598 |
|
| 599 |
function tickSpec(start, stop, count) { |
| 600 |
const step = (stop - start) / Math.max(0, count), |
| 601 |
power = Math.floor(Math.log10(step)), |
| 602 |
error = step / Math.pow(10, power), |
| 603 |
factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1; |
| 604 |
let i1, i2, inc; |
| 605 |
if (power < 0) { |
| 606 |
inc = Math.pow(10, -power) / factor; |
| 607 |
i1 = Math.round(start * inc); |
| 608 |
i2 = Math.round(stop * inc); |
| 609 |
if (i1 / inc < start) ++i1; |
| 610 |
if (i2 / inc > stop) --i2; |
| 611 |
inc = -inc; |
| 612 |
} else { |
| 613 |
inc = Math.pow(10, power) * factor; |
| 614 |
i1 = Math.round(start / inc); |
| 615 |
i2 = Math.round(stop / inc); |
| 616 |
if (i1 * inc < start) ++i1; |
| 617 |
if (i2 * inc > stop) --i2; |
| 618 |
} |
| 619 |
if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2); |
| 620 |
return [i1, i2, inc]; |
| 621 |
} |
| 622 |
|
| 623 |
function ticks(start, stop, count) { |
| 624 |
stop = +stop, start = +start, count = +count; |
| 625 |
if (!(count > 0)) return []; |
| 626 |
if (start === stop) return [start]; |
| 627 |
const reverse = stop < start, [i1, i2, inc] = reverse ? tickSpec(stop, start, count) : tickSpec(start, stop, count); |
| 628 |
if (!(i2 >= i1)) return []; |
| 629 |
const n = i2 - i1 + 1, ticks = new Array(n); |
| 630 |
if (reverse) { |
| 631 |
if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) / -inc; |
| 632 |
else for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) * inc; |
| 633 |
} else { |
| 634 |
if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) / -inc; |
| 635 |
else for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) * inc; |
| 636 |
} |
| 637 |
return ticks; |
| 638 |
} |
| 639 |
|
| 640 |
function tickIncrement(start, stop, count) { |
| 641 |
stop = +stop, start = +start, count = +count; |
| 642 |
return tickSpec(start, stop, count)[2]; |
| 643 |
} |
| 644 |
|
| 645 |
function tickStep(start, stop, count) { |
| 646 |
stop = +stop, start = +start, count = +count; |
| 647 |
const reverse = stop < start, inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count); |
| 648 |
return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc); |
| 649 |
} |
| 650 |
|
| 651 |
function nice$1(start, stop, count) { |
| 652 |
let prestep; |
| 653 |
while (true) { |
| 654 |
const step = tickIncrement(start, stop, count); |
| 655 |
if (step === prestep || step === 0 || !isFinite(step)) { |
| 656 |
return [start, stop]; |
| 657 |
} else if (step > 0) { |
| 658 |
start = Math.floor(start / step) * step; |
| 659 |
stop = Math.ceil(stop / step) * step; |
| 660 |
} else if (step < 0) { |
| 661 |
start = Math.ceil(start * step) / step; |
| 662 |
stop = Math.floor(stop * step) / step; |
| 663 |
} |
| 664 |
prestep = step; |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
function thresholdSturges(values) { |
| 669 |
return Math.max(1, Math.ceil(Math.log(count$1(values)) / Math.LN2) + 1); |
| 670 |
} |
| 671 |
|
| 672 |
function bin() { |
| 673 |
var value = identity$9, |
| 674 |
domain = extent$1, |
| 675 |
threshold = thresholdSturges; |
| 676 |
|
| 677 |
function histogram(data) { |
| 678 |
if (!Array.isArray(data)) data = Array.from(data); |
| 679 |
|
| 680 |
var i, |
| 681 |
n = data.length, |
| 682 |
x, |
| 683 |
step, |
| 684 |
values = new Array(n); |
| 685 |
|
| 686 |
for (i = 0; i < n; ++i) { |
| 687 |
values[i] = value(data[i], i, data); |
| 688 |
} |
| 689 |
|
| 690 |
var xz = domain(values), |
| 691 |
x0 = xz[0], |
| 692 |
x1 = xz[1], |
| 693 |
tz = threshold(values, x0, x1); |
| 694 |
|
| 695 |
// Convert number of thresholds into uniform thresholds, and nice the |
| 696 |
// default domain accordingly. |
| 697 |
if (!Array.isArray(tz)) { |
| 698 |
const max = x1, tn = +tz; |
| 699 |
if (domain === extent$1) [x0, x1] = nice$1(x0, x1, tn); |
| 700 |
tz = ticks(x0, x1, tn); |
| 701 |
|
| 702 |
// If the domain is aligned with the first tick (which it will by |
| 703 |
// default), then we can use quantization rather than bisection to bin |
| 704 |
// values, which is substantially faster. |
| 705 |
if (tz[0] <= x0) step = tickIncrement(x0, x1, tn); |
| 706 |
|
| 707 |
// If the last threshold is coincident with the domain’s upper bound, the |
| 708 |
// last bin will be zero-width. If the default domain is used, and this |
| 709 |
// last threshold is coincident with the maximum input value, we can |
| 710 |
// extend the niced upper bound by one tick to ensure uniform bin widths; |
| 711 |
// otherwise, we simply remove the last threshold. Note that we don’t |
| 712 |
// coerce values or the domain to numbers, and thus must be careful to |
| 713 |
// compare order (>=) rather than strict equality (===)! |
| 714 |
if (tz[tz.length - 1] >= x1) { |
| 715 |
if (max >= x1 && domain === extent$1) { |
| 716 |
const step = tickIncrement(x0, x1, tn); |
| 717 |
if (isFinite(step)) { |
| 718 |
if (step > 0) { |
| 719 |
x1 = (Math.floor(x1 / step) + 1) * step; |
| 720 |
} else if (step < 0) { |
| 721 |
x1 = (Math.ceil(x1 * -step) + 1) / -step; |
| 722 |
} |
| 723 |
} |
| 724 |
} else { |
| 725 |
tz.pop(); |
| 726 |
} |
| 727 |
} |
| 728 |
} |
| 729 |
|
| 730 |
// Remove any thresholds outside the domain. |
| 731 |
// Be careful not to mutate an array owned by the user! |
| 732 |
var m = tz.length, a = 0, b = m; |
| 733 |
while (tz[a] <= x0) ++a; |
| 734 |
while (tz[b - 1] > x1) --b; |
| 735 |
if (a || b < m) tz = tz.slice(a, b), m = b - a; |
| 736 |
|
| 737 |
var bins = new Array(m + 1), |
| 738 |
bin; |
| 739 |
|
| 740 |
// Initialize bins. |
| 741 |
for (i = 0; i <= m; ++i) { |
| 742 |
bin = bins[i] = []; |
| 743 |
bin.x0 = i > 0 ? tz[i - 1] : x0; |
| 744 |
bin.x1 = i < m ? tz[i] : x1; |
| 745 |
} |
| 746 |
|
| 747 |
// Assign data to bins by value, ignoring any outside the domain. |
| 748 |
if (isFinite(step)) { |
| 749 |
if (step > 0) { |
| 750 |
for (i = 0; i < n; ++i) { |
| 751 |
if ((x = values[i]) != null && x0 <= x && x <= x1) { |
| 752 |
bins[Math.min(m, Math.floor((x - x0) / step))].push(data[i]); |
| 753 |
} |
| 754 |
} |
| 755 |
} else if (step < 0) { |
| 756 |
for (i = 0; i < n; ++i) { |
| 757 |
if ((x = values[i]) != null && x0 <= x && x <= x1) { |
| 758 |
const j = Math.floor((x0 - x) * step); |
| 759 |
bins[Math.min(m, j + (tz[j] <= x))].push(data[i]); // handle off-by-one due to rounding |
| 760 |
} |
| 761 |
} |
| 762 |
} |
| 763 |
} else { |
| 764 |
for (i = 0; i < n; ++i) { |
| 765 |
if ((x = values[i]) != null && x0 <= x && x <= x1) { |
| 766 |
bins[bisect(tz, x, 0, m)].push(data[i]); |
| 767 |
} |
| 768 |
} |
| 769 |
} |
| 770 |
|
| 771 |
return bins; |
| 772 |
} |
| 773 |
|
| 774 |
histogram.value = function(_) { |
| 775 |
return arguments.length ? (value = typeof _ === "function" ? _ : constant$b(_), histogram) : value; |
| 776 |
}; |
| 777 |
|
| 778 |
histogram.domain = function(_) { |
| 779 |
return arguments.length ? (domain = typeof _ === "function" ? _ : constant$b([_[0], _[1]]), histogram) : domain; |
| 780 |
}; |
| 781 |
|
| 782 |
histogram.thresholds = function(_) { |
| 783 |
return arguments.length ? (threshold = typeof _ === "function" ? _ : constant$b(Array.isArray(_) ? slice$3.call(_) : _), histogram) : threshold; |
| 784 |
}; |
| 785 |
|
| 786 |
return histogram; |
| 787 |
} |
| 788 |
|
| 789 |
function max$3(values, valueof) { |
| 790 |
let max; |
| 791 |
if (valueof === undefined) { |
| 792 |
for (const value of values) { |
| 793 |
if (value != null |
| 794 |
&& (max < value || (max === undefined && value >= value))) { |
| 795 |
max = value; |
| 796 |
} |
| 797 |
} |
| 798 |
} else { |
| 799 |
let index = -1; |
| 800 |
for (let value of values) { |
| 801 |
if ((value = valueof(value, ++index, values)) != null |
| 802 |
&& (max < value || (max === undefined && value >= value))) { |
| 803 |
max = value; |
| 804 |
} |
| 805 |
} |
| 806 |
} |
| 807 |
return max; |
| 808 |
} |
| 809 |
|
| 810 |
function maxIndex(values, valueof) { |
| 811 |
let max; |
| 812 |
let maxIndex = -1; |
| 813 |
let index = -1; |
| 814 |
if (valueof === undefined) { |
| 815 |
for (const value of values) { |
| 816 |
++index; |
| 817 |
if (value != null |
| 818 |
&& (max < value || (max === undefined && value >= value))) { |
| 819 |
max = value, maxIndex = index; |
| 820 |
} |
| 821 |
} |
| 822 |
} else { |
| 823 |
for (let value of values) { |
| 824 |
if ((value = valueof(value, ++index, values)) != null |
| 825 |
&& (max < value || (max === undefined && value >= value))) { |
| 826 |
max = value, maxIndex = index; |
| 827 |
} |
| 828 |
} |
| 829 |
} |
| 830 |
return maxIndex; |
| 831 |
} |
| 832 |
|
| 833 |
function min$2(values, valueof) { |
| 834 |
let min; |
| 835 |
if (valueof === undefined) { |
| 836 |
for (const value of values) { |
| 837 |
if (value != null |
| 838 |
&& (min > value || (min === undefined && value >= value))) { |
| 839 |
min = value; |
| 840 |
} |
| 841 |
} |
| 842 |
} else { |
| 843 |
let index = -1; |
| 844 |
for (let value of values) { |
| 845 |
if ((value = valueof(value, ++index, values)) != null |
| 846 |
&& (min > value || (min === undefined && value >= value))) { |
| 847 |
min = value; |
| 848 |
} |
| 849 |
} |
| 850 |
} |
| 851 |
return min; |
| 852 |
} |
| 853 |
|
| 854 |
function minIndex(values, valueof) { |
| 855 |
let min; |
| 856 |
let minIndex = -1; |
| 857 |
let index = -1; |
| 858 |
if (valueof === undefined) { |
| 859 |
for (const value of values) { |
| 860 |
++index; |
| 861 |
if (value != null |
| 862 |
&& (min > value || (min === undefined && value >= value))) { |
| 863 |
min = value, minIndex = index; |
| 864 |
} |
| 865 |
} |
| 866 |
} else { |
| 867 |
for (let value of values) { |
| 868 |
if ((value = valueof(value, ++index, values)) != null |
| 869 |
&& (min > value || (min === undefined && value >= value))) { |
| 870 |
min = value, minIndex = index; |
| 871 |
} |
| 872 |
} |
| 873 |
} |
| 874 |
return minIndex; |
| 875 |
} |
| 876 |
|
| 877 |
// Based on https://github.com/mourner/quickselect |
| 878 |
// ISC license, Copyright 2018 Vladimir Agafonkin. |
| 879 |
function quickselect(array, k, left = 0, right = Infinity, compare) { |
| 880 |
k = Math.floor(k); |
| 881 |
left = Math.floor(Math.max(0, left)); |
| 882 |
right = Math.floor(Math.min(array.length - 1, right)); |
| 883 |
|
| 884 |
if (!(left <= k && k <= right)) return array; |
| 885 |
|
| 886 |
compare = compare === undefined ? ascendingDefined : compareDefined(compare); |
| 887 |
|
| 888 |
while (right > left) { |
| 889 |
if (right - left > 600) { |
| 890 |
const n = right - left + 1; |
| 891 |
const m = k - left + 1; |
| 892 |
const z = Math.log(n); |
| 893 |
const s = 0.5 * Math.exp(2 * z / 3); |
| 894 |
const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1); |
| 895 |
const newLeft = Math.max(left, Math.floor(k - m * s / n + sd)); |
| 896 |
const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd)); |
| 897 |
quickselect(array, k, newLeft, newRight, compare); |
| 898 |
} |
| 899 |
|
| 900 |
const t = array[k]; |
| 901 |
let i = left; |
| 902 |
let j = right; |
| 903 |
|
| 904 |
swap$1(array, left, k); |
| 905 |
if (compare(array[right], t) > 0) swap$1(array, left, right); |
| 906 |
|
| 907 |
while (i < j) { |
| 908 |
swap$1(array, i, j), ++i, --j; |
| 909 |
while (compare(array[i], t) < 0) ++i; |
| 910 |
while (compare(array[j], t) > 0) --j; |
| 911 |
} |
| 912 |
|
| 913 |
if (compare(array[left], t) === 0) swap$1(array, left, j); |
| 914 |
else ++j, swap$1(array, j, right); |
| 915 |
|
| 916 |
if (j <= k) left = j + 1; |
| 917 |
if (k <= j) right = j - 1; |
| 918 |
} |
| 919 |
|
| 920 |
return array; |
| 921 |
} |
| 922 |
|
| 923 |
function swap$1(array, i, j) { |
| 924 |
const t = array[i]; |
| 925 |
array[i] = array[j]; |
| 926 |
array[j] = t; |
| 927 |
} |
| 928 |
|
| 929 |
function greatest(values, compare = ascending$3) { |
| 930 |
let max; |
| 931 |
let defined = false; |
| 932 |
if (compare.length === 1) { |
| 933 |
let maxValue; |
| 934 |
for (const element of values) { |
| 935 |
const value = compare(element); |
| 936 |
if (defined |
| 937 |
? ascending$3(value, maxValue) > 0 |
| 938 |
: ascending$3(value, value) === 0) { |
| 939 |
max = element; |
| 940 |
maxValue = value; |
| 941 |
defined = true; |
| 942 |
} |
| 943 |
} |
| 944 |
} else { |
| 945 |
for (const value of values) { |
| 946 |
if (defined |
| 947 |
? compare(value, max) > 0 |
| 948 |
: compare(value, value) === 0) { |
| 949 |
max = value; |
| 950 |
defined = true; |
| 951 |
} |
| 952 |
} |
| 953 |
} |
| 954 |
return max; |
| 955 |
} |
| 956 |
|
| 957 |
function quantile$1(values, p, valueof) { |
| 958 |
values = Float64Array.from(numbers(values, valueof)); |
| 959 |
if (!(n = values.length) || isNaN(p = +p)) return; |
| 960 |
if (p <= 0 || n < 2) return min$2(values); |
| 961 |
if (p >= 1) return max$3(values); |
| 962 |
var n, |
| 963 |
i = (n - 1) * p, |
| 964 |
i0 = Math.floor(i), |
| 965 |
value0 = max$3(quickselect(values, i0).subarray(0, i0 + 1)), |
| 966 |
value1 = min$2(values.subarray(i0 + 1)); |
| 967 |
return value0 + (value1 - value0) * (i - i0); |
| 968 |
} |
| 969 |
|
| 970 |
function quantileSorted(values, p, valueof = number$3) { |
| 971 |
if (!(n = values.length) || isNaN(p = +p)) return; |
| 972 |
if (p <= 0 || n < 2) return +valueof(values[0], 0, values); |
| 973 |
if (p >= 1) return +valueof(values[n - 1], n - 1, values); |
| 974 |
var n, |
| 975 |
i = (n - 1) * p, |
| 976 |
i0 = Math.floor(i), |
| 977 |
value0 = +valueof(values[i0], i0, values), |
| 978 |
value1 = +valueof(values[i0 + 1], i0 + 1, values); |
| 979 |
return value0 + (value1 - value0) * (i - i0); |
| 980 |
} |
| 981 |
|
| 982 |
function quantileIndex(values, p, valueof = number$3) { |
| 983 |
if (isNaN(p = +p)) return; |
| 984 |
numbers = Float64Array.from(values, (_, i) => number$3(valueof(values[i], i, values))); |
| 985 |
if (p <= 0) return minIndex(numbers); |
| 986 |
if (p >= 1) return maxIndex(numbers); |
| 987 |
var numbers, |
| 988 |
index = Uint32Array.from(values, (_, i) => i), |
| 989 |
j = numbers.length - 1, |
| 990 |
i = Math.floor(j * p); |
| 991 |
quickselect(index, i, 0, j, (i, j) => ascendingDefined(numbers[i], numbers[j])); |
| 992 |
i = greatest(index.subarray(0, i + 1), (i) => numbers[i]); |
| 993 |
return i >= 0 ? i : -1; |
| 994 |
} |
| 995 |
|
| 996 |
function thresholdFreedmanDiaconis(values, min, max) { |
| 997 |
const c = count$1(values), d = quantile$1(values, 0.75) - quantile$1(values, 0.25); |
| 998 |
return c && d ? Math.ceil((max - min) / (2 * d * Math.pow(c, -1 / 3))) : 1; |
| 999 |
} |
| 1000 |
|
| 1001 |
function thresholdScott(values, min, max) { |
| 1002 |
const c = count$1(values), d = deviation(values); |
| 1003 |
return c && d ? Math.ceil((max - min) * Math.cbrt(c) / (3.49 * d)) : 1; |
| 1004 |
} |
| 1005 |
|
| 1006 |
function mean(values, valueof) { |
| 1007 |
let count = 0; |
| 1008 |
let sum = 0; |
| 1009 |
if (valueof === undefined) { |
| 1010 |
for (let value of values) { |
| 1011 |
if (value != null && (value = +value) >= value) { |
| 1012 |
++count, sum += value; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
} else { |
| 1016 |
let index = -1; |
| 1017 |
for (let value of values) { |
| 1018 |
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) { |
| 1019 |
++count, sum += value; |
| 1020 |
} |
| 1021 |
} |
| 1022 |
} |
| 1023 |
if (count) return sum / count; |
| 1024 |
} |
| 1025 |
|
| 1026 |
function median(values, valueof) { |
| 1027 |
return quantile$1(values, 0.5, valueof); |
| 1028 |
} |
| 1029 |
|
| 1030 |
function medianIndex(values, valueof) { |
| 1031 |
return quantileIndex(values, 0.5, valueof); |
| 1032 |
} |
| 1033 |
|
| 1034 |
function* flatten(arrays) { |
| 1035 |
for (const array of arrays) { |
| 1036 |
yield* array; |
| 1037 |
} |
| 1038 |
} |
| 1039 |
|
| 1040 |
function merge(arrays) { |
| 1041 |
return Array.from(flatten(arrays)); |
| 1042 |
} |
| 1043 |
|
| 1044 |
function mode(values, valueof) { |
| 1045 |
const counts = new InternMap(); |
| 1046 |
if (valueof === undefined) { |
| 1047 |
for (let value of values) { |
| 1048 |
if (value != null && value >= value) { |
| 1049 |
counts.set(value, (counts.get(value) || 0) + 1); |
| 1050 |
} |
| 1051 |
} |
| 1052 |
} else { |
| 1053 |
let index = -1; |
| 1054 |
for (let value of values) { |
| 1055 |
if ((value = valueof(value, ++index, values)) != null && value >= value) { |
| 1056 |
counts.set(value, (counts.get(value) || 0) + 1); |
| 1057 |
} |
| 1058 |
} |
| 1059 |
} |
| 1060 |
let modeValue; |
| 1061 |
let modeCount = 0; |
| 1062 |
for (const [value, count] of counts) { |
| 1063 |
if (count > modeCount) { |
| 1064 |
modeCount = count; |
| 1065 |
modeValue = value; |
| 1066 |
} |
| 1067 |
} |
| 1068 |
return modeValue; |
| 1069 |
} |
| 1070 |
|
| 1071 |
function pairs(values, pairof = pair) { |
| 1072 |
const pairs = []; |
| 1073 |
let previous; |
| 1074 |
let first = false; |
| 1075 |
for (const value of values) { |
| 1076 |
if (first) pairs.push(pairof(previous, value)); |
| 1077 |
previous = value; |
| 1078 |
first = true; |
| 1079 |
} |
| 1080 |
return pairs; |
| 1081 |
} |
| 1082 |
|
| 1083 |
function pair(a, b) { |
| 1084 |
return [a, b]; |
| 1085 |
} |
| 1086 |
|
| 1087 |
function range$2(start, stop, step) { |
| 1088 |
start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step; |
| 1089 |
|
| 1090 |
var i = -1, |
| 1091 |
n = Math.max(0, Math.ceil((stop - start) / step)) | 0, |
| 1092 |
range = new Array(n); |
| 1093 |
|
| 1094 |
while (++i < n) { |
| 1095 |
range[i] = start + i * step; |
| 1096 |
} |
| 1097 |
|
| 1098 |
return range; |
| 1099 |
} |
| 1100 |
|
| 1101 |
function rank(values, valueof = ascending$3) { |
| 1102 |
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable"); |
| 1103 |
let V = Array.from(values); |
| 1104 |
const R = new Float64Array(V.length); |
| 1105 |
if (valueof.length !== 2) V = V.map(valueof), valueof = ascending$3; |
| 1106 |
const compareIndex = (i, j) => valueof(V[i], V[j]); |
| 1107 |
let k, r; |
| 1108 |
values = Uint32Array.from(V, (_, i) => i); |
| 1109 |
// Risky chaining due to Safari 14 https://github.com/d3/d3-array/issues/123 |
| 1110 |
values.sort(valueof === ascending$3 ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex)); |
| 1111 |
values.forEach((j, i) => { |
| 1112 |
const c = compareIndex(j, k === undefined ? j : k); |
| 1113 |
if (c >= 0) { |
| 1114 |
if (k === undefined || c > 0) k = j, r = i; |
| 1115 |
R[j] = r; |
| 1116 |
} else { |
| 1117 |
R[j] = NaN; |
| 1118 |
} |
| 1119 |
}); |
| 1120 |
return R; |
| 1121 |
} |
| 1122 |
|
| 1123 |
function least(values, compare = ascending$3) { |
| 1124 |
let min; |
| 1125 |
let defined = false; |
| 1126 |
if (compare.length === 1) { |
| 1127 |
let minValue; |
| 1128 |
for (const element of values) { |
| 1129 |
const value = compare(element); |
| 1130 |
if (defined |
| 1131 |
? ascending$3(value, minValue) < 0 |
| 1132 |
: ascending$3(value, value) === 0) { |
| 1133 |
min = element; |
| 1134 |
minValue = value; |
| 1135 |
defined = true; |
| 1136 |
} |
| 1137 |
} |
| 1138 |
} else { |
| 1139 |
for (const value of values) { |
| 1140 |
if (defined |
| 1141 |
? compare(value, min) < 0 |
| 1142 |
: compare(value, value) === 0) { |
| 1143 |
min = value; |
| 1144 |
defined = true; |
| 1145 |
} |
| 1146 |
} |
| 1147 |
} |
| 1148 |
return min; |
| 1149 |
} |
| 1150 |
|
| 1151 |
function leastIndex(values, compare = ascending$3) { |
| 1152 |
if (compare.length === 1) return minIndex(values, compare); |
| 1153 |
let minValue; |
| 1154 |
let min = -1; |
| 1155 |
let index = -1; |
| 1156 |
for (const value of values) { |
| 1157 |
++index; |
| 1158 |
if (min < 0 |
| 1159 |
? compare(value, value) === 0 |
| 1160 |
: compare(value, minValue) < 0) { |
| 1161 |
minValue = value; |
| 1162 |
min = index; |
| 1163 |
} |
| 1164 |
} |
| 1165 |
return min; |
| 1166 |
} |
| 1167 |
|
| 1168 |
function greatestIndex(values, compare = ascending$3) { |
| 1169 |
if (compare.length === 1) return maxIndex(values, compare); |
| 1170 |
let maxValue; |
| 1171 |
let max = -1; |
| 1172 |
let index = -1; |
| 1173 |
for (const value of values) { |
| 1174 |
++index; |
| 1175 |
if (max < 0 |
| 1176 |
? compare(value, value) === 0 |
| 1177 |
: compare(value, maxValue) > 0) { |
| 1178 |
maxValue = value; |
| 1179 |
max = index; |
| 1180 |
} |
| 1181 |
} |
| 1182 |
return max; |
| 1183 |
} |
| 1184 |
|
| 1185 |
function scan(values, compare) { |
| 1186 |
const index = leastIndex(values, compare); |
| 1187 |
return index < 0 ? undefined : index; |
| 1188 |
} |
| 1189 |
|
| 1190 |
var shuffle$1 = shuffler(Math.random); |
| 1191 |
|
| 1192 |
function shuffler(random) { |
| 1193 |
return function shuffle(array, i0 = 0, i1 = array.length) { |
| 1194 |
let m = i1 - (i0 = +i0); |
| 1195 |
while (m) { |
| 1196 |
const i = random() * m-- | 0, t = array[m + i0]; |
| 1197 |
array[m + i0] = array[i + i0]; |
| 1198 |
array[i + i0] = t; |
| 1199 |
} |
| 1200 |
return array; |
| 1201 |
}; |
| 1202 |
} |
| 1203 |
|
| 1204 |
function sum$2(values, valueof) { |
| 1205 |
let sum = 0; |
| 1206 |
if (valueof === undefined) { |
| 1207 |
for (let value of values) { |
| 1208 |
if (value = +value) { |
| 1209 |
sum += value; |
| 1210 |
} |
| 1211 |
} |
| 1212 |
} else { |
| 1213 |
let index = -1; |
| 1214 |
for (let value of values) { |
| 1215 |
if (value = +valueof(value, ++index, values)) { |
| 1216 |
sum += value; |
| 1217 |
} |
| 1218 |
} |
| 1219 |
} |
| 1220 |
return sum; |
| 1221 |
} |
| 1222 |
|
| 1223 |
function transpose(matrix) { |
| 1224 |
if (!(n = matrix.length)) return []; |
| 1225 |
for (var i = -1, m = min$2(matrix, length$2), transpose = new Array(m); ++i < m;) { |
| 1226 |
for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) { |
| 1227 |
row[j] = matrix[j][i]; |
| 1228 |
} |
| 1229 |
} |
| 1230 |
return transpose; |
| 1231 |
} |
| 1232 |
|
| 1233 |
function length$2(d) { |
| 1234 |
return d.length; |
| 1235 |
} |
| 1236 |
|
| 1237 |
function zip() { |
| 1238 |
return transpose(arguments); |
| 1239 |
} |
| 1240 |
|
| 1241 |
function every(values, test) { |
| 1242 |
if (typeof test !== "function") throw new TypeError("test is not a function"); |
| 1243 |
let index = -1; |
| 1244 |
for (const value of values) { |
| 1245 |
if (!test(value, ++index, values)) { |
| 1246 |
return false; |
| 1247 |
} |
| 1248 |
} |
| 1249 |
return true; |
| 1250 |
} |
| 1251 |
|
| 1252 |
function some(values, test) { |
| 1253 |
if (typeof test !== "function") throw new TypeError("test is not a function"); |
| 1254 |
let index = -1; |
| 1255 |
for (const value of values) { |
| 1256 |
if (test(value, ++index, values)) { |
| 1257 |
return true; |
| 1258 |
} |
| 1259 |
} |
| 1260 |
return false; |
| 1261 |
} |
| 1262 |
|
| 1263 |
function filter$1(values, test) { |
| 1264 |
if (typeof test !== "function") throw new TypeError("test is not a function"); |
| 1265 |
const array = []; |
| 1266 |
let index = -1; |
| 1267 |
for (const value of values) { |
| 1268 |
if (test(value, ++index, values)) { |
| 1269 |
array.push(value); |
| 1270 |
} |
| 1271 |
} |
| 1272 |
return array; |
| 1273 |
} |
| 1274 |
|
| 1275 |
function map$1(values, mapper) { |
| 1276 |
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable"); |
| 1277 |
if (typeof mapper !== "function") throw new TypeError("mapper is not a function"); |
| 1278 |
return Array.from(values, (value, index) => mapper(value, index, values)); |
| 1279 |
} |
| 1280 |
|
| 1281 |
function reduce(values, reducer, value) { |
| 1282 |
if (typeof reducer !== "function") throw new TypeError("reducer is not a function"); |
| 1283 |
const iterator = values[Symbol.iterator](); |
| 1284 |
let done, next, index = -1; |
| 1285 |
if (arguments.length < 3) { |
| 1286 |
({done, value} = iterator.next()); |
| 1287 |
if (done) return; |
| 1288 |
++index; |
| 1289 |
} |
| 1290 |
while (({done, value: next} = iterator.next()), !done) { |
| 1291 |
value = reducer(value, next, ++index, values); |
| 1292 |
} |
| 1293 |
return value; |
| 1294 |
} |
| 1295 |
|
| 1296 |
function reverse$1(values) { |
| 1297 |
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable"); |
| 1298 |
return Array.from(values).reverse(); |
| 1299 |
} |
| 1300 |
|
| 1301 |
function difference(values, ...others) { |
| 1302 |
values = new InternSet(values); |
| 1303 |
for (const other of others) { |
| 1304 |
for (const value of other) { |
| 1305 |
values.delete(value); |
| 1306 |
} |
| 1307 |
} |
| 1308 |
return values; |
| 1309 |
} |
| 1310 |
|
| 1311 |
function disjoint(values, other) { |
| 1312 |
const iterator = other[Symbol.iterator](), set = new InternSet(); |
| 1313 |
for (const v of values) { |
| 1314 |
if (set.has(v)) return false; |
| 1315 |
let value, done; |
| 1316 |
while (({value, done} = iterator.next())) { |
| 1317 |
if (done) break; |
| 1318 |
if (Object.is(v, value)) return false; |
| 1319 |
set.add(value); |
| 1320 |
} |
| 1321 |
} |
| 1322 |
return true; |
| 1323 |
} |
| 1324 |
|
| 1325 |
function intersection(values, ...others) { |
| 1326 |
values = new InternSet(values); |
| 1327 |
others = others.map(set$2); |
| 1328 |
out: for (const value of values) { |
| 1329 |
for (const other of others) { |
| 1330 |
if (!other.has(value)) { |
| 1331 |
values.delete(value); |
| 1332 |
continue out; |
| 1333 |
} |
| 1334 |
} |
| 1335 |
} |
| 1336 |
return values; |
| 1337 |
} |
| 1338 |
|
| 1339 |
function set$2(values) { |
| 1340 |
return values instanceof InternSet ? values : new InternSet(values); |
| 1341 |
} |
| 1342 |
|
| 1343 |
function superset(values, other) { |
| 1344 |
const iterator = values[Symbol.iterator](), set = new Set(); |
| 1345 |
for (const o of other) { |
| 1346 |
const io = intern(o); |
| 1347 |
if (set.has(io)) continue; |
| 1348 |
let value, done; |
| 1349 |
while (({value, done} = iterator.next())) { |
| 1350 |
if (done) return false; |
| 1351 |
const ivalue = intern(value); |
| 1352 |
set.add(ivalue); |
| 1353 |
if (Object.is(io, ivalue)) break; |
| 1354 |
} |
| 1355 |
} |
| 1356 |
return true; |
| 1357 |
} |
| 1358 |
|
| 1359 |
function intern(value) { |
| 1360 |
return value !== null && typeof value === "object" ? value.valueOf() : value; |
| 1361 |
} |
| 1362 |
|
| 1363 |
function subset(values, other) { |
| 1364 |
return superset(other, values); |
| 1365 |
} |
| 1366 |
|
| 1367 |
function union(...others) { |
| 1368 |
const set = new InternSet(); |
| 1369 |
for (const other of others) { |
| 1370 |
for (const o of other) { |
| 1371 |
set.add(o); |
| 1372 |
} |
| 1373 |
} |
| 1374 |
return set; |
| 1375 |
} |
| 1376 |
|
| 1377 |
function identity$8(x) { |
| 1378 |
return x; |
| 1379 |
} |
| 1380 |
|
| 1381 |
var top = 1, |
| 1382 |
right = 2, |
| 1383 |
bottom = 3, |
| 1384 |
left = 4, |
| 1385 |
epsilon$6 = 1e-6; |
| 1386 |
|
| 1387 |
function translateX(x) { |
| 1388 |
return "translate(" + x + ",0)"; |
| 1389 |
} |
| 1390 |
|
| 1391 |
function translateY(y) { |
| 1392 |
return "translate(0," + y + ")"; |
| 1393 |
} |
| 1394 |
|
| 1395 |
function number$2(scale) { |
| 1396 |
return d => +scale(d); |
| 1397 |
} |
| 1398 |
|
| 1399 |
function center$1(scale, offset) { |
| 1400 |
offset = Math.max(0, scale.bandwidth() - offset * 2) / 2; |
| 1401 |
if (scale.round()) offset = Math.round(offset); |
| 1402 |
return d => +scale(d) + offset; |
| 1403 |
} |
| 1404 |
|
| 1405 |
function entering() { |
| 1406 |
return !this.__axis; |
| 1407 |
} |
| 1408 |
|
| 1409 |
function axis(orient, scale) { |
| 1410 |
var tickArguments = [], |
| 1411 |
tickValues = null, |
| 1412 |
tickFormat = null, |
| 1413 |
tickSizeInner = 6, |
| 1414 |
tickSizeOuter = 6, |
| 1415 |
tickPadding = 3, |
| 1416 |
offset = typeof window !== "undefined" && window.devicePixelRatio > 1 ? 0 : 0.5, |
| 1417 |
k = orient === top || orient === left ? -1 : 1, |
| 1418 |
x = orient === left || orient === right ? "x" : "y", |
| 1419 |
transform = orient === top || orient === bottom ? translateX : translateY; |
| 1420 |
|
| 1421 |
function axis(context) { |
| 1422 |
var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues, |
| 1423 |
format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$8) : tickFormat, |
| 1424 |
spacing = Math.max(tickSizeInner, 0) + tickPadding, |
| 1425 |
range = scale.range(), |
| 1426 |
range0 = +range[0] + offset, |
| 1427 |
range1 = +range[range.length - 1] + offset, |
| 1428 |
position = (scale.bandwidth ? center$1 : number$2)(scale.copy(), offset), |
| 1429 |
selection = context.selection ? context.selection() : context, |
| 1430 |
path = selection.selectAll(".domain").data([null]), |
| 1431 |
tick = selection.selectAll(".tick").data(values, scale).order(), |
| 1432 |
tickExit = tick.exit(), |
| 1433 |
tickEnter = tick.enter().append("g").attr("class", "tick"), |
| 1434 |
line = tick.select("line"), |
| 1435 |
text = tick.select("text"); |
| 1436 |
|
| 1437 |
path = path.merge(path.enter().insert("path", ".tick") |
| 1438 |
.attr("class", "domain") |
| 1439 |
.attr("stroke", "currentColor")); |
| 1440 |
|
| 1441 |
tick = tick.merge(tickEnter); |
| 1442 |
|
| 1443 |
line = line.merge(tickEnter.append("line") |
| 1444 |
.attr("stroke", "currentColor") |
| 1445 |
.attr(x + "2", k * tickSizeInner)); |
| 1446 |
|
| 1447 |
text = text.merge(tickEnter.append("text") |
| 1448 |
.attr("fill", "currentColor") |
| 1449 |
.attr(x, k * spacing) |
| 1450 |
.attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em")); |
| 1451 |
|
| 1452 |
if (context !== selection) { |
| 1453 |
path = path.transition(context); |
| 1454 |
tick = tick.transition(context); |
| 1455 |
line = line.transition(context); |
| 1456 |
text = text.transition(context); |
| 1457 |
|
| 1458 |
tickExit = tickExit.transition(context) |
| 1459 |
.attr("opacity", epsilon$6) |
| 1460 |
.attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d + offset) : this.getAttribute("transform"); }); |
| 1461 |
|
| 1462 |
tickEnter |
| 1463 |
.attr("opacity", epsilon$6) |
| 1464 |
.attr("transform", function(d) { var p = this.parentNode.__axis; return transform((p && isFinite(p = p(d)) ? p : position(d)) + offset); }); |
| 1465 |
} |
| 1466 |
|
| 1467 |
tickExit.remove(); |
| 1468 |
|
| 1469 |
path |
| 1470 |
.attr("d", orient === left || orient === right |
| 1471 |
? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H" + offset + "V" + range1 + "H" + k * tickSizeOuter : "M" + offset + "," + range0 + "V" + range1) |
| 1472 |
: (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V" + offset + "H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + "," + offset + "H" + range1)); |
| 1473 |
|
| 1474 |
tick |
| 1475 |
.attr("opacity", 1) |
| 1476 |
.attr("transform", function(d) { return transform(position(d) + offset); }); |
| 1477 |
|
| 1478 |
line |
| 1479 |
.attr(x + "2", k * tickSizeInner); |
| 1480 |
|
| 1481 |
text |
| 1482 |
.attr(x, k * spacing) |
| 1483 |
.text(format); |
| 1484 |
|
| 1485 |
selection.filter(entering) |
| 1486 |
.attr("fill", "none") |
| 1487 |
.attr("font-size", 10) |
| 1488 |
.attr("font-family", "sans-serif") |
| 1489 |
.attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle"); |
| 1490 |
|
| 1491 |
selection |
| 1492 |
.each(function() { this.__axis = position; }); |
| 1493 |
} |
| 1494 |
|
| 1495 |
axis.scale = function(_) { |
| 1496 |
return arguments.length ? (scale = _, axis) : scale; |
| 1497 |
}; |
| 1498 |
|
| 1499 |
axis.ticks = function() { |
| 1500 |
return tickArguments = Array.from(arguments), axis; |
| 1501 |
}; |
| 1502 |
|
| 1503 |
axis.tickArguments = function(_) { |
| 1504 |
return arguments.length ? (tickArguments = _ == null ? [] : Array.from(_), axis) : tickArguments.slice(); |
| 1505 |
}; |
| 1506 |
|
| 1507 |
axis.tickValues = function(_) { |
| 1508 |
return arguments.length ? (tickValues = _ == null ? null : Array.from(_), axis) : tickValues && tickValues.slice(); |
| 1509 |
}; |
| 1510 |
|
| 1511 |
axis.tickFormat = function(_) { |
| 1512 |
return arguments.length ? (tickFormat = _, axis) : tickFormat; |
| 1513 |
}; |
| 1514 |
|
| 1515 |
axis.tickSize = function(_) { |
| 1516 |
return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner; |
| 1517 |
}; |
| 1518 |
|
| 1519 |
axis.tickSizeInner = function(_) { |
| 1520 |
return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner; |
| 1521 |
}; |
| 1522 |
|
| 1523 |
axis.tickSizeOuter = function(_) { |
| 1524 |
return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter; |
| 1525 |
}; |
| 1526 |
|
| 1527 |
axis.tickPadding = function(_) { |
| 1528 |
return arguments.length ? (tickPadding = +_, axis) : tickPadding; |
| 1529 |
}; |
| 1530 |
|
| 1531 |
axis.offset = function(_) { |
| 1532 |
return arguments.length ? (offset = +_, axis) : offset; |
| 1533 |
}; |
| 1534 |
|
| 1535 |
return axis; |
| 1536 |
} |
| 1537 |
|
| 1538 |
function axisTop(scale) { |
| 1539 |
return axis(top, scale); |
| 1540 |
} |
| 1541 |
|
| 1542 |
function axisRight(scale) { |
| 1543 |
return axis(right, scale); |
| 1544 |
} |
| 1545 |
|
| 1546 |
function axisBottom(scale) { |
| 1547 |
return axis(bottom, scale); |
| 1548 |
} |
| 1549 |
|
| 1550 |
function axisLeft(scale) { |
| 1551 |
return axis(left, scale); |
| 1552 |
} |
| 1553 |
|
| 1554 |
var noop$3 = {value: () => {}}; |
| 1555 |
|
| 1556 |
function dispatch() { |
| 1557 |
for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) { |
| 1558 |
if (!(t = arguments[i] + "") || (t in _) || /[\s.]/.test(t)) throw new Error("illegal type: " + t); |
| 1559 |
_[t] = []; |
| 1560 |
} |
| 1561 |
return new Dispatch(_); |
| 1562 |
} |
| 1563 |
|
| 1564 |
function Dispatch(_) { |
| 1565 |
this._ = _; |
| 1566 |
} |
| 1567 |
|
| 1568 |
function parseTypenames$1(typenames, types) { |
| 1569 |
return typenames.trim().split(/^|\s+/).map(function(t) { |
| 1570 |
var name = "", i = t.indexOf("."); |
| 1571 |
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i); |
| 1572 |
if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t); |
| 1573 |
return {type: t, name: name}; |
| 1574 |
}); |
| 1575 |
} |
| 1576 |
|
| 1577 |
Dispatch.prototype = dispatch.prototype = { |
| 1578 |
constructor: Dispatch, |
| 1579 |
on: function(typename, callback) { |
| 1580 |
var _ = this._, |
| 1581 |
T = parseTypenames$1(typename + "", _), |
| 1582 |
t, |
| 1583 |
i = -1, |
| 1584 |
n = T.length; |
| 1585 |
|
| 1586 |
// If no callback was specified, return the callback of the given type and name. |
| 1587 |
if (arguments.length < 2) { |
| 1588 |
while (++i < n) if ((t = (typename = T[i]).type) && (t = get$1(_[t], typename.name))) return t; |
| 1589 |
return; |
| 1590 |
} |
| 1591 |
|
| 1592 |
// If a type was specified, set the callback for the given type and name. |
| 1593 |
// Otherwise, if a null callback was specified, remove callbacks of the given name. |
| 1594 |
if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback); |
| 1595 |
while (++i < n) { |
| 1596 |
if (t = (typename = T[i]).type) _[t] = set$1(_[t], typename.name, callback); |
| 1597 |
else if (callback == null) for (t in _) _[t] = set$1(_[t], typename.name, null); |
| 1598 |
} |
| 1599 |
|
| 1600 |
return this; |
| 1601 |
}, |
| 1602 |
copy: function() { |
| 1603 |
var copy = {}, _ = this._; |
| 1604 |
for (var t in _) copy[t] = _[t].slice(); |
| 1605 |
return new Dispatch(copy); |
| 1606 |
}, |
| 1607 |
call: function(type, that) { |
| 1608 |
if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2]; |
| 1609 |
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type); |
| 1610 |
for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args); |
| 1611 |
}, |
| 1612 |
apply: function(type, that, args) { |
| 1613 |
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type); |
| 1614 |
for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args); |
| 1615 |
} |
| 1616 |
}; |
| 1617 |
|
| 1618 |
function get$1(type, name) { |
| 1619 |
for (var i = 0, n = type.length, c; i < n; ++i) { |
| 1620 |
if ((c = type[i]).name === name) { |
| 1621 |
return c.value; |
| 1622 |
} |
| 1623 |
} |
| 1624 |
} |
| 1625 |
|
| 1626 |
function set$1(type, name, callback) { |
| 1627 |
for (var i = 0, n = type.length; i < n; ++i) { |
| 1628 |
if (type[i].name === name) { |
| 1629 |
type[i] = noop$3, type = type.slice(0, i).concat(type.slice(i + 1)); |
| 1630 |
break; |
| 1631 |
} |
| 1632 |
} |
| 1633 |
if (callback != null) type.push({name: name, value: callback}); |
| 1634 |
return type; |
| 1635 |
} |
| 1636 |
|
| 1637 |
var xhtml = "http://www.w3.org/1999/xhtml"; |
| 1638 |
|
| 1639 |
var namespaces = { |
| 1640 |
svg: "http://www.w3.org/2000/svg", |
| 1641 |
xhtml: xhtml, |
| 1642 |
xlink: "http://www.w3.org/1999/xlink", |
| 1643 |
xml: "http://www.w3.org/XML/1998/namespace", |
| 1644 |
xmlns: "http://www.w3.org/2000/xmlns/" |
| 1645 |
}; |
| 1646 |
|
| 1647 |
function namespace(name) { |
| 1648 |
var prefix = name += "", i = prefix.indexOf(":"); |
| 1649 |
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1); |
| 1650 |
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name; // eslint-disable-line no-prototype-builtins |
| 1651 |
} |
| 1652 |
|
| 1653 |
function creatorInherit(name) { |
| 1654 |
return function() { |
| 1655 |
var document = this.ownerDocument, |
| 1656 |
uri = this.namespaceURI; |
| 1657 |
return uri === xhtml && document.documentElement.namespaceURI === xhtml |
| 1658 |
? document.createElement(name) |
| 1659 |
: document.createElementNS(uri, name); |
| 1660 |
}; |
| 1661 |
} |
| 1662 |
|
| 1663 |
function creatorFixed(fullname) { |
| 1664 |
return function() { |
| 1665 |
return this.ownerDocument.createElementNS(fullname.space, fullname.local); |
| 1666 |
}; |
| 1667 |
} |
| 1668 |
|
| 1669 |
function creator(name) { |
| 1670 |
var fullname = namespace(name); |
| 1671 |
return (fullname.local |
| 1672 |
? creatorFixed |
| 1673 |
: creatorInherit)(fullname); |
| 1674 |
} |
| 1675 |
|
| 1676 |
function none$2() {} |
| 1677 |
|
| 1678 |
function selector(selector) { |
| 1679 |
return selector == null ? none$2 : function() { |
| 1680 |
return this.querySelector(selector); |
| 1681 |
}; |
| 1682 |
} |
| 1683 |
|
| 1684 |
function selection_select(select) { |
| 1685 |
if (typeof select !== "function") select = selector(select); |
| 1686 |
|
| 1687 |
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { |
| 1688 |
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) { |
| 1689 |
if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) { |
| 1690 |
if ("__data__" in node) subnode.__data__ = node.__data__; |
| 1691 |
subgroup[i] = subnode; |
| 1692 |
} |
| 1693 |
} |
| 1694 |
} |
| 1695 |
|
| 1696 |
return new Selection$1(subgroups, this._parents); |
| 1697 |
} |
| 1698 |
|
| 1699 |
// Given something array like (or null), returns something that is strictly an |
| 1700 |
// array. This is used to ensure that array-like objects passed to d3.selectAll |
| 1701 |
// or selection.selectAll are converted into proper arrays when creating a |
| 1702 |
// selection; we don’t ever want to create a selection backed by a live |
| 1703 |
// HTMLCollection or NodeList. However, note that selection.selectAll will use a |
| 1704 |
// static NodeList as a group, since it safely derived from querySelectorAll. |
| 1705 |
function array$4(x) { |
| 1706 |
return x == null ? [] : Array.isArray(x) ? x : Array.from(x); |
| 1707 |
} |
| 1708 |
|
| 1709 |
function empty$1() { |
| 1710 |
return []; |
| 1711 |
} |
| 1712 |
|
| 1713 |
function selectorAll(selector) { |
| 1714 |
return selector == null ? empty$1 : function() { |
| 1715 |
return this.querySelectorAll(selector); |
| 1716 |
}; |
| 1717 |
} |
| 1718 |
|
| 1719 |
function arrayAll(select) { |
| 1720 |
return function() { |
| 1721 |
return array$4(select.apply(this, arguments)); |
| 1722 |
}; |
| 1723 |
} |
| 1724 |
|
| 1725 |
function selection_selectAll(select) { |
| 1726 |
if (typeof select === "function") select = arrayAll(select); |
| 1727 |
else select = selectorAll(select); |
| 1728 |
|
| 1729 |
for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) { |
| 1730 |
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { |
| 1731 |
if (node = group[i]) { |
| 1732 |
subgroups.push(select.call(node, node.__data__, i, group)); |
| 1733 |
parents.push(node); |
| 1734 |
} |
| 1735 |
} |
| 1736 |
} |
| 1737 |
|
| 1738 |
return new Selection$1(subgroups, parents); |
| 1739 |
} |
| 1740 |
|
| 1741 |
function matcher(selector) { |
| 1742 |
return function() { |
| 1743 |
return this.matches(selector); |
| 1744 |
}; |
| 1745 |
} |
| 1746 |
|
| 1747 |
function childMatcher(selector) { |
| 1748 |
return function(node) { |
| 1749 |
return node.matches(selector); |
| 1750 |
}; |
| 1751 |
} |
| 1752 |
|
| 1753 |
var find$1 = Array.prototype.find; |
| 1754 |
|
| 1755 |
function childFind(match) { |
| 1756 |
return function() { |
| 1757 |
return find$1.call(this.children, match); |
| 1758 |
}; |
| 1759 |
} |
| 1760 |
|
| 1761 |
function childFirst() { |
| 1762 |
return this.firstElementChild; |
| 1763 |
} |
| 1764 |
|
| 1765 |
function selection_selectChild(match) { |
| 1766 |
return this.select(match == null ? childFirst |
| 1767 |
: childFind(typeof match === "function" ? match : childMatcher(match))); |
| 1768 |
} |
| 1769 |
|
| 1770 |
var filter = Array.prototype.filter; |
| 1771 |
|
| 1772 |
function children() { |
| 1773 |
return Array.from(this.children); |
| 1774 |
} |
| 1775 |
|
| 1776 |
function childrenFilter(match) { |
| 1777 |
return function() { |
| 1778 |
return filter.call(this.children, match); |
| 1779 |
}; |
| 1780 |
} |
| 1781 |
|
| 1782 |
function selection_selectChildren(match) { |
| 1783 |
return this.selectAll(match == null ? children |
| 1784 |
: childrenFilter(typeof match === "function" ? match : childMatcher(match))); |
| 1785 |
} |
| 1786 |
|
| 1787 |
function selection_filter(match) { |
| 1788 |
if (typeof match !== "function") match = matcher(match); |
| 1789 |
|
| 1790 |
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { |
| 1791 |
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) { |
| 1792 |
if ((node = group[i]) && match.call(node, node.__data__, i, group)) { |
| 1793 |
subgroup.push(node); |
| 1794 |
} |
| 1795 |
} |
| 1796 |
} |
| 1797 |
|
| 1798 |
return new Selection$1(subgroups, this._parents); |
| 1799 |
} |
| 1800 |
|
| 1801 |
function sparse(update) { |
| 1802 |
return new Array(update.length); |
| 1803 |
} |
| 1804 |
|
| 1805 |
function selection_enter() { |
| 1806 |
return new Selection$1(this._enter || this._groups.map(sparse), this._parents); |
| 1807 |
} |
| 1808 |
|
| 1809 |
function EnterNode(parent, datum) { |
| 1810 |
this.ownerDocument = parent.ownerDocument; |
| 1811 |
this.namespaceURI = parent.namespaceURI; |
| 1812 |
this._next = null; |
| 1813 |
this._parent = parent; |
| 1814 |
this.__data__ = datum; |
| 1815 |
} |
| 1816 |
|
| 1817 |
EnterNode.prototype = { |
| 1818 |
constructor: EnterNode, |
| 1819 |
appendChild: function(child) { return this._parent.insertBefore(child, this._next); }, |
| 1820 |
insertBefore: function(child, next) { return this._parent.insertBefore(child, next); }, |
| 1821 |
querySelector: function(selector) { return this._parent.querySelector(selector); }, |
| 1822 |
querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); } |
| 1823 |
}; |
| 1824 |
|
| 1825 |
function constant$a(x) { |
| 1826 |
return function() { |
| 1827 |
return x; |
| 1828 |
}; |
| 1829 |
} |
| 1830 |
|
| 1831 |
function bindIndex(parent, group, enter, update, exit, data) { |
| 1832 |
var i = 0, |
| 1833 |
node, |
| 1834 |
groupLength = group.length, |
| 1835 |
dataLength = data.length; |
| 1836 |
|
| 1837 |
// Put any non-null nodes that fit into update. |
| 1838 |
// Put any null nodes into enter. |
| 1839 |
// Put any remaining data into enter. |
| 1840 |
for (; i < dataLength; ++i) { |
| 1841 |
if (node = group[i]) { |
| 1842 |
node.__data__ = data[i]; |
| 1843 |
update[i] = node; |
| 1844 |
} else { |
| 1845 |
enter[i] = new EnterNode(parent, data[i]); |
| 1846 |
} |
| 1847 |
} |
| 1848 |
|
| 1849 |
// Put any non-null nodes that don’t fit into exit. |
| 1850 |
for (; i < groupLength; ++i) { |
| 1851 |
if (node = group[i]) { |
| 1852 |
exit[i] = node; |
| 1853 |
} |
| 1854 |
} |
| 1855 |
} |
| 1856 |
|
| 1857 |
function bindKey(parent, group, enter, update, exit, data, key) { |
| 1858 |
var i, |
| 1859 |
node, |
| 1860 |
nodeByKeyValue = new Map, |
| 1861 |
groupLength = group.length, |
| 1862 |
dataLength = data.length, |
| 1863 |
keyValues = new Array(groupLength), |
| 1864 |
keyValue; |
| 1865 |
|
| 1866 |
// Compute the key for each node. |
| 1867 |
// If multiple nodes have the same key, the duplicates are added to exit. |
| 1868 |
for (i = 0; i < groupLength; ++i) { |
| 1869 |
if (node = group[i]) { |
| 1870 |
keyValues[i] = keyValue = key.call(node, node.__data__, i, group) + ""; |
| 1871 |
if (nodeByKeyValue.has(keyValue)) { |
| 1872 |
exit[i] = node; |
| 1873 |
} else { |
| 1874 |
nodeByKeyValue.set(keyValue, node); |
| 1875 |
} |
| 1876 |
} |
| 1877 |
} |
| 1878 |
|
| 1879 |
// Compute the key for each datum. |
| 1880 |
// If there a node associated with this key, join and add it to update. |
| 1881 |
// If there is not (or the key is a duplicate), add it to enter. |
| 1882 |
for (i = 0; i < dataLength; ++i) { |
| 1883 |
keyValue = key.call(parent, data[i], i, data) + ""; |
| 1884 |
if (node = nodeByKeyValue.get(keyValue)) { |
| 1885 |
update[i] = node; |
| 1886 |
node.__data__ = data[i]; |
| 1887 |
nodeByKeyValue.delete(keyValue); |
| 1888 |
} else { |
| 1889 |
enter[i] = new EnterNode(parent, data[i]); |
| 1890 |
} |
| 1891 |
} |
| 1892 |
|
| 1893 |
// Add any remaining nodes that were not bound to data to exit. |
| 1894 |
for (i = 0; i < groupLength; ++i) { |
| 1895 |
if ((node = group[i]) && (nodeByKeyValue.get(keyValues[i]) === node)) { |
| 1896 |
exit[i] = node; |
| 1897 |
} |
| 1898 |
} |
| 1899 |
} |
| 1900 |
|
| 1901 |
function datum(node) { |
| 1902 |
return node.__data__; |
| 1903 |
} |
| 1904 |
|
| 1905 |
function selection_data(value, key) { |
| 1906 |
if (!arguments.length) return Array.from(this, datum); |
| 1907 |
|
| 1908 |
var bind = key ? bindKey : bindIndex, |
| 1909 |
parents = this._parents, |
| 1910 |
groups = this._groups; |
| 1911 |
|
| 1912 |
if (typeof value !== "function") value = constant$a(value); |
| 1913 |
|
| 1914 |
for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) { |
| 1915 |
var parent = parents[j], |
| 1916 |
group = groups[j], |
| 1917 |
groupLength = group.length, |
| 1918 |
data = arraylike(value.call(parent, parent && parent.__data__, j, parents)), |
| 1919 |
dataLength = data.length, |
| 1920 |
enterGroup = enter[j] = new Array(dataLength), |
| 1921 |
updateGroup = update[j] = new Array(dataLength), |
| 1922 |
exitGroup = exit[j] = new Array(groupLength); |
| 1923 |
|
| 1924 |
bind(parent, group, enterGroup, updateGroup, exitGroup, data, key); |
| 1925 |
|
| 1926 |
// Now connect the enter nodes to their following update node, such that |
| 1927 |
// appendChild can insert the materialized enter node before this node, |
| 1928 |
// rather than at the end of the parent node. |
| 1929 |
for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) { |
| 1930 |
if (previous = enterGroup[i0]) { |
| 1931 |
if (i0 >= i1) i1 = i0 + 1; |
| 1932 |
while (!(next = updateGroup[i1]) && ++i1 < dataLength); |
| 1933 |
previous._next = next || null; |
| 1934 |
} |
| 1935 |
} |
| 1936 |
} |
| 1937 |
|
| 1938 |
update = new Selection$1(update, parents); |
| 1939 |
update._enter = enter; |
| 1940 |
update._exit = exit; |
| 1941 |
return update; |
| 1942 |
} |
| 1943 |
|
| 1944 |
// Given some data, this returns an array-like view of it: an object that |
| 1945 |
// exposes a length property and allows numeric indexing. Note that unlike |
| 1946 |
// selectAll, this isn’t worried about “live” collections because the resulting |
| 1947 |
// array will only be used briefly while data is being bound. (It is possible to |
| 1948 |
// cause the data to change while iterating by using a key function, but please |
| 1949 |
// don’t; we’d rather avoid a gratuitous copy.) |
| 1950 |
function arraylike(data) { |
| 1951 |
return typeof data === "object" && "length" in data |
| 1952 |
? data // Array, TypedArray, NodeList, array-like |
| 1953 |
: Array.from(data); // Map, Set, iterable, string, or anything else |
| 1954 |
} |
| 1955 |
|
| 1956 |
function selection_exit() { |
| 1957 |
return new Selection$1(this._exit || this._groups.map(sparse), this._parents); |
| 1958 |
} |
| 1959 |
|
| 1960 |
function selection_join(onenter, onupdate, onexit) { |
| 1961 |
var enter = this.enter(), update = this, exit = this.exit(); |
| 1962 |
if (typeof onenter === "function") { |
| 1963 |
enter = onenter(enter); |
| 1964 |
if (enter) enter = enter.selection(); |
| 1965 |
} else { |
| 1966 |
enter = enter.append(onenter + ""); |
| 1967 |
} |
| 1968 |
if (onupdate != null) { |
| 1969 |
update = onupdate(update); |
| 1970 |
if (update) update = update.selection(); |
| 1971 |
} |
| 1972 |
if (onexit == null) exit.remove(); else onexit(exit); |
| 1973 |
return enter && update ? enter.merge(update).order() : update; |
| 1974 |
} |
| 1975 |
|
| 1976 |
function selection_merge(context) { |
| 1977 |
var selection = context.selection ? context.selection() : context; |
| 1978 |
|
| 1979 |
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) { |
| 1980 |
for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) { |
| 1981 |
if (node = group0[i] || group1[i]) { |
| 1982 |
merge[i] = node; |
| 1983 |
} |
| 1984 |
} |
| 1985 |
} |
| 1986 |
|
| 1987 |
for (; j < m0; ++j) { |
| 1988 |
merges[j] = groups0[j]; |
| 1989 |
} |
| 1990 |
|
| 1991 |
return new Selection$1(merges, this._parents); |
| 1992 |
} |
| 1993 |
|
| 1994 |
function selection_order() { |
| 1995 |
|
| 1996 |
for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) { |
| 1997 |
for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) { |
| 1998 |
if (node = group[i]) { |
| 1999 |
if (next && node.compareDocumentPosition(next) ^ 4) next.parentNode.insertBefore(node, next); |
| 2000 |
next = node; |
| 2001 |
} |
| 2002 |
} |
| 2003 |
} |
| 2004 |
|
| 2005 |
return this; |
| 2006 |
} |
| 2007 |
|
| 2008 |
function selection_sort(compare) { |
| 2009 |
if (!compare) compare = ascending$2; |
| 2010 |
|
| 2011 |
function compareNode(a, b) { |
| 2012 |
return a && b ? compare(a.__data__, b.__data__) : !a - !b; |
| 2013 |
} |
| 2014 |
|
| 2015 |
for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) { |
| 2016 |
for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) { |
| 2017 |
if (node = group[i]) { |
| 2018 |
sortgroup[i] = node; |
| 2019 |
} |
| 2020 |
} |
| 2021 |
sortgroup.sort(compareNode); |
| 2022 |
} |
| 2023 |
|
| 2024 |
return new Selection$1(sortgroups, this._parents).order(); |
| 2025 |
} |
| 2026 |
|
| 2027 |
function ascending$2(a, b) { |
| 2028 |
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; |
| 2029 |
} |
| 2030 |
|
| 2031 |
function selection_call() { |
| 2032 |
var callback = arguments[0]; |
| 2033 |
arguments[0] = this; |
| 2034 |
callback.apply(null, arguments); |
| 2035 |
return this; |
| 2036 |
} |
| 2037 |
|
| 2038 |
function selection_nodes() { |
| 2039 |
return Array.from(this); |
| 2040 |
} |
| 2041 |
|
| 2042 |
function selection_node() { |
| 2043 |
|
| 2044 |
for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) { |
| 2045 |
for (var group = groups[j], i = 0, n = group.length; i < n; ++i) { |
| 2046 |
var node = group[i]; |
| 2047 |
if (node) return node; |
| 2048 |
} |
| 2049 |
} |
| 2050 |
|
| 2051 |
return null; |
| 2052 |
} |
| 2053 |
|
| 2054 |
function selection_size() { |
| 2055 |
let size = 0; |
| 2056 |
for (const node of this) ++size; // eslint-disable-line no-unused-vars |
| 2057 |
return size; |
| 2058 |
} |
| 2059 |
|
| 2060 |
function selection_empty() { |
| 2061 |
return !this.node(); |
| 2062 |
} |
| 2063 |
|
| 2064 |
function selection_each(callback) { |
| 2065 |
|
| 2066 |
for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) { |
| 2067 |
for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) { |
| 2068 |
if (node = group[i]) callback.call(node, node.__data__, i, group); |
| 2069 |
} |
| 2070 |
} |
| 2071 |
|
| 2072 |
return this; |
| 2073 |
} |
| 2074 |
|
| 2075 |
function attrRemove$1(name) { |
| 2076 |
return function() { |
| 2077 |
this.removeAttribute(name); |
| 2078 |
}; |
| 2079 |
} |
| 2080 |
|
| 2081 |
function attrRemoveNS$1(fullname) { |
| 2082 |
return function() { |
| 2083 |
this.removeAttributeNS(fullname.space, fullname.local); |
| 2084 |
}; |
| 2085 |
} |
| 2086 |
|
| 2087 |
function attrConstant$1(name, value) { |
| 2088 |
return function() { |
| 2089 |
this.setAttribute(name, value); |
| 2090 |
}; |
| 2091 |
} |
| 2092 |
|
| 2093 |
function attrConstantNS$1(fullname, value) { |
| 2094 |
return function() { |
| 2095 |
this.setAttributeNS(fullname.space, fullname.local, value); |
| 2096 |
}; |
| 2097 |
} |
| 2098 |
|
| 2099 |
function attrFunction$1(name, value) { |
| 2100 |
return function() { |
| 2101 |
var v = value.apply(this, arguments); |
| 2102 |
if (v == null) this.removeAttribute(name); |
| 2103 |
else this.setAttribute(name, v); |
| 2104 |
}; |
| 2105 |
} |
| 2106 |
|
| 2107 |
function attrFunctionNS$1(fullname, value) { |
| 2108 |
return function() { |
| 2109 |
var v = value.apply(this, arguments); |
| 2110 |
if (v == null) this.removeAttributeNS(fullname.space, fullname.local); |
| 2111 |
else this.setAttributeNS(fullname.space, fullname.local, v); |
| 2112 |
}; |
| 2113 |
} |
| 2114 |
|
| 2115 |
function selection_attr(name, value) { |
| 2116 |
var fullname = namespace(name); |
| 2117 |
|
| 2118 |
if (arguments.length < 2) { |
| 2119 |
var node = this.node(); |
| 2120 |
return fullname.local |
| 2121 |
? node.getAttributeNS(fullname.space, fullname.local) |
| 2122 |
: node.getAttribute(fullname); |
| 2123 |
} |
| 2124 |
|
| 2125 |
return this.each((value == null |
| 2126 |
? (fullname.local ? attrRemoveNS$1 : attrRemove$1) : (typeof value === "function" |
| 2127 |
? (fullname.local ? attrFunctionNS$1 : attrFunction$1) |
| 2128 |
: (fullname.local ? attrConstantNS$1 : attrConstant$1)))(fullname, value)); |
| 2129 |
} |
| 2130 |
|
| 2131 |
function defaultView(node) { |
| 2132 |
return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node |
| 2133 |
|| (node.document && node) // node is a Window |
| 2134 |
|| node.defaultView; // node is a Document |
| 2135 |
} |
| 2136 |
|
| 2137 |
function styleRemove$1(name) { |
| 2138 |
return function() { |
| 2139 |
this.style.removeProperty(name); |
| 2140 |
}; |
| 2141 |
} |
| 2142 |
|
| 2143 |
function styleConstant$1(name, value, priority) { |
| 2144 |
return function() { |
| 2145 |
this.style.setProperty(name, value, priority); |
| 2146 |
}; |
| 2147 |
} |
| 2148 |
|
| 2149 |
function styleFunction$1(name, value, priority) { |
| 2150 |
return function() { |
| 2151 |
var v = value.apply(this, arguments); |
| 2152 |
if (v == null) this.style.removeProperty(name); |
| 2153 |
else this.style.setProperty(name, v, priority); |
| 2154 |
}; |
| 2155 |
} |
| 2156 |
|
| 2157 |
function selection_style(name, value, priority) { |
| 2158 |
return arguments.length > 1 |
| 2159 |
? this.each((value == null |
| 2160 |
? styleRemove$1 : typeof value === "function" |
| 2161 |
? styleFunction$1 |
| 2162 |
: styleConstant$1)(name, value, priority == null ? "" : priority)) |
| 2163 |
: styleValue(this.node(), name); |
| 2164 |
} |
| 2165 |
|
| 2166 |
function styleValue(node, name) { |
| 2167 |
return node.style.getPropertyValue(name) |
| 2168 |
|| defaultView(node).getComputedStyle(node, null).getPropertyValue(name); |
| 2169 |
} |
| 2170 |
|
| 2171 |
function propertyRemove(name) { |
| 2172 |
return function() { |
| 2173 |
delete this[name]; |
| 2174 |
}; |
| 2175 |
} |
| 2176 |
|
| 2177 |
function propertyConstant(name, value) { |
| 2178 |
return function() { |
| 2179 |
this[name] = value; |
| 2180 |
}; |
| 2181 |
} |
| 2182 |
|
| 2183 |
function propertyFunction(name, value) { |
| 2184 |
return function() { |
| 2185 |
var v = value.apply(this, arguments); |
| 2186 |
if (v == null) delete this[name]; |
| 2187 |
else this[name] = v; |
| 2188 |
}; |
| 2189 |
} |
| 2190 |
|
| 2191 |
function selection_property(name, value) { |
| 2192 |
return arguments.length > 1 |
| 2193 |
? this.each((value == null |
| 2194 |
? propertyRemove : typeof value === "function" |
| 2195 |
? propertyFunction |
| 2196 |
: propertyConstant)(name, value)) |
| 2197 |
: this.node()[name]; |
| 2198 |
} |
| 2199 |
|
| 2200 |
function classArray(string) { |
| 2201 |
return string.trim().split(/^|\s+/); |
| 2202 |
} |
| 2203 |
|
| 2204 |
function classList(node) { |
| 2205 |
return node.classList || new ClassList(node); |
| 2206 |
} |
| 2207 |
|
| 2208 |
function ClassList(node) { |
| 2209 |
this._node = node; |
| 2210 |
this._names = classArray(node.getAttribute("class") || ""); |
| 2211 |
} |
| 2212 |
|
| 2213 |
ClassList.prototype = { |
| 2214 |
add: function(name) { |
| 2215 |
var i = this._names.indexOf(name); |
| 2216 |
if (i < 0) { |
| 2217 |
this._names.push(name); |
| 2218 |
this._node.setAttribute("class", this._names.join(" ")); |
| 2219 |
} |
| 2220 |
}, |
| 2221 |
remove: function(name) { |
| 2222 |
var i = this._names.indexOf(name); |
| 2223 |
if (i >= 0) { |
| 2224 |
this._names.splice(i, 1); |
| 2225 |
this._node.setAttribute("class", this._names.join(" ")); |
| 2226 |
} |
| 2227 |
}, |
| 2228 |
contains: function(name) { |
| 2229 |
return this._names.indexOf(name) >= 0; |
| 2230 |
} |
| 2231 |
}; |
| 2232 |
|
| 2233 |
function classedAdd(node, names) { |
| 2234 |
var list = classList(node), i = -1, n = names.length; |
| 2235 |
while (++i < n) list.add(names[i]); |
| 2236 |
} |
| 2237 |
|
| 2238 |
function classedRemove(node, names) { |
| 2239 |
var list = classList(node), i = -1, n = names.length; |
| 2240 |
while (++i < n) list.remove(names[i]); |
| 2241 |
} |
| 2242 |
|
| 2243 |
function classedTrue(names) { |
| 2244 |
return function() { |
| 2245 |
classedAdd(this, names); |
| 2246 |
}; |
| 2247 |
} |
| 2248 |
|
| 2249 |
function classedFalse(names) { |
| 2250 |
return function() { |
| 2251 |
classedRemove(this, names); |
| 2252 |
}; |
| 2253 |
} |
| 2254 |
|
| 2255 |
function classedFunction(names, value) { |
| 2256 |
return function() { |
| 2257 |
(value.apply(this, arguments) ? classedAdd : classedRemove)(this, names); |
| 2258 |
}; |
| 2259 |
} |
| 2260 |
|
| 2261 |
function selection_classed(name, value) { |
| 2262 |
var names = classArray(name + ""); |
| 2263 |
|
| 2264 |
if (arguments.length < 2) { |
| 2265 |
var list = classList(this.node()), i = -1, n = names.length; |
| 2266 |
while (++i < n) if (!list.contains(names[i])) return false; |
| 2267 |
return true; |
| 2268 |
} |
| 2269 |
|
| 2270 |
return this.each((typeof value === "function" |
| 2271 |
? classedFunction : value |
| 2272 |
? classedTrue |
| 2273 |
: classedFalse)(names, value)); |
| 2274 |
} |
| 2275 |
|
| 2276 |
function textRemove() { |
| 2277 |
this.textContent = ""; |
| 2278 |
} |
| 2279 |
|
| 2280 |
function textConstant$1(value) { |
| 2281 |
return function() { |
| 2282 |
this.textContent = value; |
| 2283 |
}; |
| 2284 |
} |
| 2285 |
|
| 2286 |
function textFunction$1(value) { |
| 2287 |
return function() { |
| 2288 |
var v = value.apply(this, arguments); |
| 2289 |
this.textContent = v == null ? "" : v; |
| 2290 |
}; |
| 2291 |
} |
| 2292 |
|
| 2293 |
function selection_text(value) { |
| 2294 |
return arguments.length |
| 2295 |
? this.each(value == null |
| 2296 |
? textRemove : (typeof value === "function" |
| 2297 |
? textFunction$1 |
| 2298 |
: textConstant$1)(value)) |
| 2299 |
: this.node().textContent; |
| 2300 |
} |
| 2301 |
|
| 2302 |
function htmlRemove() { |
| 2303 |
this.innerHTML = ""; |
| 2304 |
} |
| 2305 |
|
| 2306 |
function htmlConstant(value) { |
| 2307 |
return function() { |
| 2308 |
this.innerHTML = value; |
| 2309 |
}; |
| 2310 |
} |
| 2311 |
|
| 2312 |
function htmlFunction(value) { |
| 2313 |
return function() { |
| 2314 |
var v = value.apply(this, arguments); |
| 2315 |
this.innerHTML = v == null ? "" : v; |
| 2316 |
}; |
| 2317 |
} |
| 2318 |
|
| 2319 |
function selection_html(value) { |
| 2320 |
return arguments.length |
| 2321 |
? this.each(value == null |
| 2322 |
? htmlRemove : (typeof value === "function" |
| 2323 |
? htmlFunction |
| 2324 |
: htmlConstant)(value)) |
| 2325 |
: this.node().innerHTML; |
| 2326 |
} |
| 2327 |
|
| 2328 |
function raise() { |
| 2329 |
if (this.nextSibling) this.parentNode.appendChild(this); |
| 2330 |
} |
| 2331 |
|
| 2332 |
function selection_raise() { |
| 2333 |
return this.each(raise); |
| 2334 |
} |
| 2335 |
|
| 2336 |
function lower() { |
| 2337 |
if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild); |
| 2338 |
} |
| 2339 |
|
| 2340 |
function selection_lower() { |
| 2341 |
return this.each(lower); |
| 2342 |
} |
| 2343 |
|
| 2344 |
function selection_append(name) { |
| 2345 |
var create = typeof name === "function" ? name : creator(name); |
| 2346 |
return this.select(function() { |
| 2347 |
return this.appendChild(create.apply(this, arguments)); |
| 2348 |
}); |
| 2349 |
} |
| 2350 |
|
| 2351 |
function constantNull() { |
| 2352 |
return null; |
| 2353 |
} |
| 2354 |
|
| 2355 |
function selection_insert(name, before) { |
| 2356 |
var create = typeof name === "function" ? name : creator(name), |
| 2357 |
select = before == null ? constantNull : typeof before === "function" ? before : selector(before); |
| 2358 |
return this.select(function() { |
| 2359 |
return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null); |
| 2360 |
}); |
| 2361 |
} |
| 2362 |
|
| 2363 |
function remove() { |
| 2364 |
var parent = this.parentNode; |
| 2365 |
if (parent) parent.removeChild(this); |
| 2366 |
} |
| 2367 |
|
| 2368 |
function selection_remove() { |
| 2369 |
return this.each(remove); |
| 2370 |
} |
| 2371 |
|
| 2372 |
function selection_cloneShallow() { |
| 2373 |
var clone = this.cloneNode(false), parent = this.parentNode; |
| 2374 |
return parent ? parent.insertBefore(clone, this.nextSibling) : clone; |
| 2375 |
} |
| 2376 |
|
| 2377 |
function selection_cloneDeep() { |
| 2378 |
var clone = this.cloneNode(true), parent = this.parentNode; |
| 2379 |
return parent ? parent.insertBefore(clone, this.nextSibling) : clone; |
| 2380 |
} |
| 2381 |
|
| 2382 |
function selection_clone(deep) { |
| 2383 |
return this.select(deep ? selection_cloneDeep : selection_cloneShallow); |
| 2384 |
} |
| 2385 |
|
| 2386 |
function selection_datum(value) { |
| 2387 |
return arguments.length |
| 2388 |
? this.property("__data__", value) |
| 2389 |
: this.node().__data__; |
| 2390 |
} |
| 2391 |
|
| 2392 |
function contextListener(listener) { |
| 2393 |
return function(event) { |
| 2394 |
listener.call(this, event, this.__data__); |
| 2395 |
}; |
| 2396 |
} |
| 2397 |
|
| 2398 |
function parseTypenames(typenames) { |
| 2399 |
return typenames.trim().split(/^|\s+/).map(function(t) { |
| 2400 |
var name = "", i = t.indexOf("."); |
| 2401 |
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i); |
| 2402 |
return {type: t, name: name}; |
| 2403 |
}); |
| 2404 |
} |
| 2405 |
|
| 2406 |
function onRemove(typename) { |
| 2407 |
return function() { |
| 2408 |
var on = this.__on; |
| 2409 |
if (!on) return; |
| 2410 |
for (var j = 0, i = -1, m = on.length, o; j < m; ++j) { |
| 2411 |
if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) { |
| 2412 |
this.removeEventListener(o.type, o.listener, o.options); |
| 2413 |
} else { |
| 2414 |
on[++i] = o; |
| 2415 |
} |
| 2416 |
} |
| 2417 |
if (++i) on.length = i; |
| 2418 |
else delete this.__on; |
| 2419 |
}; |
| 2420 |
} |
| 2421 |
|
| 2422 |
function onAdd(typename, value, options) { |
| 2423 |
return function() { |
| 2424 |
var on = this.__on, o, listener = contextListener(value); |
| 2425 |
if (on) for (var j = 0, m = on.length; j < m; ++j) { |
| 2426 |
if ((o = on[j]).type === typename.type && o.name === typename.name) { |
| 2427 |
this.removeEventListener(o.type, o.listener, o.options); |
| 2428 |
this.addEventListener(o.type, o.listener = listener, o.options = options); |
| 2429 |
o.value = value; |
| 2430 |
return; |
| 2431 |
} |
| 2432 |
} |
| 2433 |
this.addEventListener(typename.type, listener, options); |
| 2434 |
o = {type: typename.type, name: typename.name, value: value, listener: listener, options: options}; |
| 2435 |
if (!on) this.__on = [o]; |
| 2436 |
else on.push(o); |
| 2437 |
}; |
| 2438 |
} |
| 2439 |
|
| 2440 |
function selection_on(typename, value, options) { |
| 2441 |
var typenames = parseTypenames(typename + ""), i, n = typenames.length, t; |
| 2442 |
|
| 2443 |
if (arguments.length < 2) { |
| 2444 |
var on = this.node().__on; |
| 2445 |
if (on) for (var j = 0, m = on.length, o; j < m; ++j) { |
| 2446 |
for (i = 0, o = on[j]; i < n; ++i) { |
| 2447 |
if ((t = typenames[i]).type === o.type && t.name === o.name) { |
| 2448 |
return o.value; |
| 2449 |
} |
| 2450 |
} |
| 2451 |
} |
| 2452 |
return; |
| 2453 |
} |
| 2454 |
|
| 2455 |
on = value ? onAdd : onRemove; |
| 2456 |
for (i = 0; i < n; ++i) this.each(on(typenames[i], value, options)); |
| 2457 |
return this; |
| 2458 |
} |
| 2459 |
|
| 2460 |
function dispatchEvent(node, type, params) { |
| 2461 |
var window = defaultView(node), |
| 2462 |
event = window.CustomEvent; |
| 2463 |
|
| 2464 |
if (typeof event === "function") { |
| 2465 |
event = new event(type, params); |
| 2466 |
} else { |
| 2467 |
event = window.document.createEvent("Event"); |
| 2468 |
if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail; |
| 2469 |
else event.initEvent(type, false, false); |
| 2470 |
} |
| 2471 |
|
| 2472 |
node.dispatchEvent(event); |
| 2473 |
} |
| 2474 |
|
| 2475 |
function dispatchConstant(type, params) { |
| 2476 |
return function() { |
| 2477 |
return dispatchEvent(this, type, params); |
| 2478 |
}; |
| 2479 |
} |
| 2480 |
|
| 2481 |
function dispatchFunction(type, params) { |
| 2482 |
return function() { |
| 2483 |
return dispatchEvent(this, type, params.apply(this, arguments)); |
| 2484 |
}; |
| 2485 |
} |
| 2486 |
|
| 2487 |
function selection_dispatch(type, params) { |
| 2488 |
return this.each((typeof params === "function" |
| 2489 |
? dispatchFunction |
| 2490 |
: dispatchConstant)(type, params)); |
| 2491 |
} |
| 2492 |
|
| 2493 |
function* selection_iterator() { |
| 2494 |
for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) { |
| 2495 |
for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) { |
| 2496 |
if (node = group[i]) yield node; |
| 2497 |
} |
| 2498 |
} |
| 2499 |
} |
| 2500 |
|
| 2501 |
var root$1 = [null]; |
| 2502 |
|
| 2503 |
function Selection$1(groups, parents) { |
| 2504 |
this._groups = groups; |
| 2505 |
this._parents = parents; |
| 2506 |
} |
| 2507 |
|
| 2508 |
function selection() { |
| 2509 |
return new Selection$1([[document.documentElement]], root$1); |
| 2510 |
} |
| 2511 |
|
| 2512 |
function selection_selection() { |
| 2513 |
return this; |
| 2514 |
} |
| 2515 |
|
| 2516 |
Selection$1.prototype = selection.prototype = { |
| 2517 |
constructor: Selection$1, |
| 2518 |
select: selection_select, |
| 2519 |
selectAll: selection_selectAll, |
| 2520 |
selectChild: selection_selectChild, |
| 2521 |
selectChildren: selection_selectChildren, |
| 2522 |
filter: selection_filter, |
| 2523 |
data: selection_data, |
| 2524 |
enter: selection_enter, |
| 2525 |
exit: selection_exit, |
| 2526 |
join: selection_join, |
| 2527 |
merge: selection_merge, |
| 2528 |
selection: selection_selection, |
| 2529 |
order: selection_order, |
| 2530 |
sort: selection_sort, |
| 2531 |
call: selection_call, |
| 2532 |
nodes: selection_nodes, |
| 2533 |
node: selection_node, |
| 2534 |
size: selection_size, |
| 2535 |
empty: selection_empty, |
| 2536 |
each: selection_each, |
| 2537 |
attr: selection_attr, |
| 2538 |
style: selection_style, |
| 2539 |
property: selection_property, |
| 2540 |
classed: selection_classed, |
| 2541 |
text: selection_text, |
| 2542 |
html: selection_html, |
| 2543 |
raise: selection_raise, |
| 2544 |
lower: selection_lower, |
| 2545 |
append: selection_append, |
| 2546 |
insert: selection_insert, |
| 2547 |
remove: selection_remove, |
| 2548 |
clone: selection_clone, |
| 2549 |
datum: selection_datum, |
| 2550 |
on: selection_on, |
| 2551 |
dispatch: selection_dispatch, |
| 2552 |
[Symbol.iterator]: selection_iterator |
| 2553 |
}; |
| 2554 |
|
| 2555 |
function select(selector) { |
| 2556 |
return typeof selector === "string" |
| 2557 |
? new Selection$1([[document.querySelector(selector)]], [document.documentElement]) |
| 2558 |
: new Selection$1([[selector]], root$1); |
| 2559 |
} |
| 2560 |
|
| 2561 |
function create$1(name) { |
| 2562 |
return select(creator(name).call(document.documentElement)); |
| 2563 |
} |
| 2564 |
|
| 2565 |
var nextId = 0; |
| 2566 |
|
| 2567 |
function local$1() { |
| 2568 |
return new Local; |
| 2569 |
} |
| 2570 |
|
| 2571 |
function Local() { |
| 2572 |
this._ = "@" + (++nextId).toString(36); |
| 2573 |
} |
| 2574 |
|
| 2575 |
Local.prototype = local$1.prototype = { |
| 2576 |
constructor: Local, |
| 2577 |
get: function(node) { |
| 2578 |
var id = this._; |
| 2579 |
while (!(id in node)) if (!(node = node.parentNode)) return; |
| 2580 |
return node[id]; |
| 2581 |
}, |
| 2582 |
set: function(node, value) { |
| 2583 |
return node[this._] = value; |
| 2584 |
}, |
| 2585 |
remove: function(node) { |
| 2586 |
return this._ in node && delete node[this._]; |
| 2587 |
}, |
| 2588 |
toString: function() { |
| 2589 |
return this._; |
| 2590 |
} |
| 2591 |
}; |
| 2592 |
|
| 2593 |
function sourceEvent(event) { |
| 2594 |
let sourceEvent; |
| 2595 |
while (sourceEvent = event.sourceEvent) event = sourceEvent; |
| 2596 |
return event; |
| 2597 |
} |
| 2598 |
|
| 2599 |
function pointer(event, node) { |
| 2600 |
event = sourceEvent(event); |
| 2601 |
if (node === undefined) node = event.currentTarget; |
| 2602 |
if (node) { |
| 2603 |
var svg = node.ownerSVGElement || node; |
| 2604 |
if (svg.createSVGPoint) { |
| 2605 |
var point = svg.createSVGPoint(); |
| 2606 |
point.x = event.clientX, point.y = event.clientY; |
| 2607 |
point = point.matrixTransform(node.getScreenCTM().inverse()); |
| 2608 |
return [point.x, point.y]; |
| 2609 |
} |
| 2610 |
if (node.getBoundingClientRect) { |
| 2611 |
var rect = node.getBoundingClientRect(); |
| 2612 |
return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop]; |
| 2613 |
} |
| 2614 |
} |
| 2615 |
return [event.pageX, event.pageY]; |
| 2616 |
} |
| 2617 |
|
| 2618 |
function pointers(events, node) { |
| 2619 |
if (events.target) { // i.e., instanceof Event, not TouchList or iterable |
| 2620 |
events = sourceEvent(events); |
| 2621 |
if (node === undefined) node = events.currentTarget; |
| 2622 |
events = events.touches || [events]; |
| 2623 |
} |
| 2624 |
return Array.from(events, event => pointer(event, node)); |
| 2625 |
} |
| 2626 |
|
| 2627 |
function selectAll(selector) { |
| 2628 |
return typeof selector === "string" |
| 2629 |
? new Selection$1([document.querySelectorAll(selector)], [document.documentElement]) |
| 2630 |
: new Selection$1([array$4(selector)], root$1); |
| 2631 |
} |
| 2632 |
|
| 2633 |
// These are typically used in conjunction with noevent to ensure that we can |
| 2634 |
// preventDefault on the event. |
| 2635 |
const nonpassive = {passive: false}; |
| 2636 |
const nonpassivecapture = {capture: true, passive: false}; |
| 2637 |
|
| 2638 |
function nopropagation$2(event) { |
| 2639 |
event.stopImmediatePropagation(); |
| 2640 |
} |
| 2641 |
|
| 2642 |
function noevent$2(event) { |
| 2643 |
event.preventDefault(); |
| 2644 |
event.stopImmediatePropagation(); |
| 2645 |
} |
| 2646 |
|
| 2647 |
function dragDisable(view) { |
| 2648 |
var root = view.document.documentElement, |
| 2649 |
selection = select(view).on("dragstart.drag", noevent$2, nonpassivecapture); |
| 2650 |
if ("onselectstart" in root) { |
| 2651 |
selection.on("selectstart.drag", noevent$2, nonpassivecapture); |
| 2652 |
} else { |
| 2653 |
root.__noselect = root.style.MozUserSelect; |
| 2654 |
root.style.MozUserSelect = "none"; |
| 2655 |
} |
| 2656 |
} |
| 2657 |
|
| 2658 |
function yesdrag(view, noclick) { |
| 2659 |
var root = view.document.documentElement, |
| 2660 |
selection = select(view).on("dragstart.drag", null); |
| 2661 |
if (noclick) { |
| 2662 |
selection.on("click.drag", noevent$2, nonpassivecapture); |
| 2663 |
setTimeout(function() { selection.on("click.drag", null); }, 0); |
| 2664 |
} |
| 2665 |
if ("onselectstart" in root) { |
| 2666 |
selection.on("selectstart.drag", null); |
| 2667 |
} else { |
| 2668 |
root.style.MozUserSelect = root.__noselect; |
| 2669 |
delete root.__noselect; |
| 2670 |
} |
| 2671 |
} |
| 2672 |
|
| 2673 |
var constant$9 = x => () => x; |
| 2674 |
|
| 2675 |
function DragEvent(type, { |
| 2676 |
sourceEvent, |
| 2677 |
subject, |
| 2678 |
target, |
| 2679 |
identifier, |
| 2680 |
active, |
| 2681 |
x, y, dx, dy, |
| 2682 |
dispatch |
| 2683 |
}) { |
| 2684 |
Object.defineProperties(this, { |
| 2685 |
type: {value: type, enumerable: true, configurable: true}, |
| 2686 |
sourceEvent: {value: sourceEvent, enumerable: true, configurable: true}, |
| 2687 |
subject: {value: subject, enumerable: true, configurable: true}, |
| 2688 |
target: {value: target, enumerable: true, configurable: true}, |
| 2689 |
identifier: {value: identifier, enumerable: true, configurable: true}, |
| 2690 |
active: {value: active, enumerable: true, configurable: true}, |
| 2691 |
x: {value: x, enumerable: true, configurable: true}, |
| 2692 |
y: {value: y, enumerable: true, configurable: true}, |
| 2693 |
dx: {value: dx, enumerable: true, configurable: true}, |
| 2694 |
dy: {value: dy, enumerable: true, configurable: true}, |
| 2695 |
_: {value: dispatch} |
| 2696 |
}); |
| 2697 |
} |
| 2698 |
|
| 2699 |
DragEvent.prototype.on = function() { |
| 2700 |
var value = this._.on.apply(this._, arguments); |
| 2701 |
return value === this._ ? this : value; |
| 2702 |
}; |
| 2703 |
|
| 2704 |
// Ignore right-click, since that should open the context menu. |
| 2705 |
function defaultFilter$2(event) { |
| 2706 |
return !event.ctrlKey && !event.button; |
| 2707 |
} |
| 2708 |
|
| 2709 |
function defaultContainer() { |
| 2710 |
return this.parentNode; |
| 2711 |
} |
| 2712 |
|
| 2713 |
function defaultSubject(event, d) { |
| 2714 |
return d == null ? {x: event.x, y: event.y} : d; |
| 2715 |
} |
| 2716 |
|
| 2717 |
function defaultTouchable$2() { |
| 2718 |
return navigator.maxTouchPoints || ("ontouchstart" in this); |
| 2719 |
} |
| 2720 |
|
| 2721 |
function drag() { |
| 2722 |
var filter = defaultFilter$2, |
| 2723 |
container = defaultContainer, |
| 2724 |
subject = defaultSubject, |
| 2725 |
touchable = defaultTouchable$2, |
| 2726 |
gestures = {}, |
| 2727 |
listeners = dispatch("start", "drag", "end"), |
| 2728 |
active = 0, |
| 2729 |
mousedownx, |
| 2730 |
mousedowny, |
| 2731 |
mousemoving, |
| 2732 |
touchending, |
| 2733 |
clickDistance2 = 0; |
| 2734 |
|
| 2735 |
function drag(selection) { |
| 2736 |
selection |
| 2737 |
.on("mousedown.drag", mousedowned) |
| 2738 |
.filter(touchable) |
| 2739 |
.on("touchstart.drag", touchstarted) |
| 2740 |
.on("touchmove.drag", touchmoved, nonpassive) |
| 2741 |
.on("touchend.drag touchcancel.drag", touchended) |
| 2742 |
.style("touch-action", "none") |
| 2743 |
.style("-webkit-tap-highlight-color", "rgba(0,0,0,0)"); |
| 2744 |
} |
| 2745 |
|
| 2746 |
function mousedowned(event, d) { |
| 2747 |
if (touchending || !filter.call(this, event, d)) return; |
| 2748 |
var gesture = beforestart(this, container.call(this, event, d), event, d, "mouse"); |
| 2749 |
if (!gesture) return; |
| 2750 |
select(event.view) |
| 2751 |
.on("mousemove.drag", mousemoved, nonpassivecapture) |
| 2752 |
.on("mouseup.drag", mouseupped, nonpassivecapture); |
| 2753 |
dragDisable(event.view); |
| 2754 |
nopropagation$2(event); |
| 2755 |
mousemoving = false; |
| 2756 |
mousedownx = event.clientX; |
| 2757 |
mousedowny = event.clientY; |
| 2758 |
gesture("start", event); |
| 2759 |
} |
| 2760 |
|
| 2761 |
function mousemoved(event) { |
| 2762 |
noevent$2(event); |
| 2763 |
if (!mousemoving) { |
| 2764 |
var dx = event.clientX - mousedownx, dy = event.clientY - mousedowny; |
| 2765 |
mousemoving = dx * dx + dy * dy > clickDistance2; |
| 2766 |
} |
| 2767 |
gestures.mouse("drag", event); |
| 2768 |
} |
| 2769 |
|
| 2770 |
function mouseupped(event) { |
| 2771 |
select(event.view).on("mousemove.drag mouseup.drag", null); |
| 2772 |
yesdrag(event.view, mousemoving); |
| 2773 |
noevent$2(event); |
| 2774 |
gestures.mouse("end", event); |
| 2775 |
} |
| 2776 |
|
| 2777 |
function touchstarted(event, d) { |
| 2778 |
if (!filter.call(this, event, d)) return; |
| 2779 |
var touches = event.changedTouches, |
| 2780 |
c = container.call(this, event, d), |
| 2781 |
n = touches.length, i, gesture; |
| 2782 |
|
| 2783 |
for (i = 0; i < n; ++i) { |
| 2784 |
if (gesture = beforestart(this, c, event, d, touches[i].identifier, touches[i])) { |
| 2785 |
nopropagation$2(event); |
| 2786 |
gesture("start", event, touches[i]); |
| 2787 |
} |
| 2788 |
} |
| 2789 |
} |
| 2790 |
|
| 2791 |
function touchmoved(event) { |
| 2792 |
var touches = event.changedTouches, |
| 2793 |
n = touches.length, i, gesture; |
| 2794 |
|
| 2795 |
for (i = 0; i < n; ++i) { |
| 2796 |
if (gesture = gestures[touches[i].identifier]) { |
| 2797 |
noevent$2(event); |
| 2798 |
gesture("drag", event, touches[i]); |
| 2799 |
} |
| 2800 |
} |
| 2801 |
} |
| 2802 |
|
| 2803 |
function touchended(event) { |
| 2804 |
var touches = event.changedTouches, |
| 2805 |
n = touches.length, i, gesture; |
| 2806 |
|
| 2807 |
if (touchending) clearTimeout(touchending); |
| 2808 |
touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed! |
| 2809 |
for (i = 0; i < n; ++i) { |
| 2810 |
if (gesture = gestures[touches[i].identifier]) { |
| 2811 |
nopropagation$2(event); |
| 2812 |
gesture("end", event, touches[i]); |
| 2813 |
} |
| 2814 |
} |
| 2815 |
} |
| 2816 |
|
| 2817 |
function beforestart(that, container, event, d, identifier, touch) { |
| 2818 |
var dispatch = listeners.copy(), |
| 2819 |
p = pointer(touch || event, container), dx, dy, |
| 2820 |
s; |
| 2821 |
|
| 2822 |
if ((s = subject.call(that, new DragEvent("beforestart", { |
| 2823 |
sourceEvent: event, |
| 2824 |
target: drag, |
| 2825 |
identifier, |
| 2826 |
active, |
| 2827 |
x: p[0], |
| 2828 |
y: p[1], |
| 2829 |
dx: 0, |
| 2830 |
dy: 0, |
| 2831 |
dispatch |
| 2832 |
}), d)) == null) return; |
| 2833 |
|
| 2834 |
dx = s.x - p[0] || 0; |
| 2835 |
dy = s.y - p[1] || 0; |
| 2836 |
|
| 2837 |
return function gesture(type, event, touch) { |
| 2838 |
var p0 = p, n; |
| 2839 |
switch (type) { |
| 2840 |
case "start": gestures[identifier] = gesture, n = active++; break; |
| 2841 |
case "end": delete gestures[identifier], --active; // falls through |
| 2842 |
case "drag": p = pointer(touch || event, container), n = active; break; |
| 2843 |
} |
| 2844 |
dispatch.call( |
| 2845 |
type, |
| 2846 |
that, |
| 2847 |
new DragEvent(type, { |
| 2848 |
sourceEvent: event, |
| 2849 |
subject: s, |
| 2850 |
target: drag, |
| 2851 |
identifier, |
| 2852 |
active: n, |
| 2853 |
x: p[0] + dx, |
| 2854 |
y: p[1] + dy, |
| 2855 |
dx: p[0] - p0[0], |
| 2856 |
dy: p[1] - p0[1], |
| 2857 |
dispatch |
| 2858 |
}), |
| 2859 |
d |
| 2860 |
); |
| 2861 |
}; |
| 2862 |
} |
| 2863 |
|
| 2864 |
drag.filter = function(_) { |
| 2865 |
return arguments.length ? (filter = typeof _ === "function" ? _ : constant$9(!!_), drag) : filter; |
| 2866 |
}; |
| 2867 |
|
| 2868 |
drag.container = function(_) { |
| 2869 |
return arguments.length ? (container = typeof _ === "function" ? _ : constant$9(_), drag) : container; |
| 2870 |
}; |
| 2871 |
|
| 2872 |
drag.subject = function(_) { |
| 2873 |
return arguments.length ? (subject = typeof _ === "function" ? _ : constant$9(_), drag) : subject; |
| 2874 |
}; |
| 2875 |
|
| 2876 |
drag.touchable = function(_) { |
| 2877 |
return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$9(!!_), drag) : touchable; |
| 2878 |
}; |
| 2879 |
|
| 2880 |
drag.on = function() { |
| 2881 |
var value = listeners.on.apply(listeners, arguments); |
| 2882 |
return value === listeners ? drag : value; |
| 2883 |
}; |
| 2884 |
|
| 2885 |
drag.clickDistance = function(_) { |
| 2886 |
return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2); |
| 2887 |
}; |
| 2888 |
|
| 2889 |
return drag; |
| 2890 |
} |
| 2891 |
|
| 2892 |
function define(constructor, factory, prototype) { |
| 2893 |
constructor.prototype = factory.prototype = prototype; |
| 2894 |
prototype.constructor = constructor; |
| 2895 |
} |
| 2896 |
|
| 2897 |
function extend(parent, definition) { |
| 2898 |
var prototype = Object.create(parent.prototype); |
| 2899 |
for (var key in definition) prototype[key] = definition[key]; |
| 2900 |
return prototype; |
| 2901 |
} |
| 2902 |
|
| 2903 |
function Color() {} |
| 2904 |
|
| 2905 |
var darker = 0.7; |
| 2906 |
var brighter = 1 / darker; |
| 2907 |
|
| 2908 |
var reI = "\\s*([+-]?\\d+)\\s*", |
| 2909 |
reN = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*", |
| 2910 |
reP = "\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*", |
| 2911 |
reHex = /^#([0-9a-f]{3,8})$/, |
| 2912 |
reRgbInteger = new RegExp(`^rgb\\(${reI},${reI},${reI}\\)$`), |
| 2913 |
reRgbPercent = new RegExp(`^rgb\\(${reP},${reP},${reP}\\)$`), |
| 2914 |
reRgbaInteger = new RegExp(`^rgba\\(${reI},${reI},${reI},${reN}\\)$`), |
| 2915 |
reRgbaPercent = new RegExp(`^rgba\\(${reP},${reP},${reP},${reN}\\)$`), |
| 2916 |
reHslPercent = new RegExp(`^hsl\\(${reN},${reP},${reP}\\)$`), |
| 2917 |
reHslaPercent = new RegExp(`^hsla\\(${reN},${reP},${reP},${reN}\\)$`); |
| 2918 |
|
| 2919 |
var named = { |
| 2920 |
aliceblue: 0xf0f8ff, |
| 2921 |
antiquewhite: 0xfaebd7, |
| 2922 |
aqua: 0x00ffff, |
| 2923 |
aquamarine: 0x7fffd4, |
| 2924 |
azure: 0xf0ffff, |
| 2925 |
beige: 0xf5f5dc, |
| 2926 |
bisque: 0xffe4c4, |
| 2927 |
black: 0x000000, |
| 2928 |
blanchedalmond: 0xffebcd, |
| 2929 |
blue: 0x0000ff, |
| 2930 |
blueviolet: 0x8a2be2, |
| 2931 |
brown: 0xa52a2a, |
| 2932 |
burlywood: 0xdeb887, |
| 2933 |
cadetblue: 0x5f9ea0, |
| 2934 |
chartreuse: 0x7fff00, |
| 2935 |
chocolate: 0xd2691e, |
| 2936 |
coral: 0xff7f50, |
| 2937 |
cornflowerblue: 0x6495ed, |
| 2938 |
cornsilk: 0xfff8dc, |
| 2939 |
crimson: 0xdc143c, |
| 2940 |
cyan: 0x00ffff, |
| 2941 |
darkblue: 0x00008b, |
| 2942 |
darkcyan: 0x008b8b, |
| 2943 |
darkgoldenrod: 0xb8860b, |
| 2944 |
darkgray: 0xa9a9a9, |
| 2945 |
darkgreen: 0x006400, |
| 2946 |
darkgrey: 0xa9a9a9, |
| 2947 |
darkkhaki: 0xbdb76b, |
| 2948 |
darkmagenta: 0x8b008b, |
| 2949 |
darkolivegreen: 0x556b2f, |
| 2950 |
darkorange: 0xff8c00, |
| 2951 |
darkorchid: 0x9932cc, |
| 2952 |
darkred: 0x8b0000, |
| 2953 |
darksalmon: 0xe9967a, |
| 2954 |
darkseagreen: 0x8fbc8f, |
| 2955 |
darkslateblue: 0x483d8b, |
| 2956 |
darkslategray: 0x2f4f4f, |
| 2957 |
darkslategrey: 0x2f4f4f, |
| 2958 |
darkturquoise: 0x00ced1, |
| 2959 |
darkviolet: 0x9400d3, |
| 2960 |
deeppink: 0xff1493, |
| 2961 |
deepskyblue: 0x00bfff, |
| 2962 |
dimgray: 0x696969, |
| 2963 |
dimgrey: 0x696969, |
| 2964 |
dodgerblue: 0x1e90ff, |
| 2965 |
firebrick: 0xb22222, |
| 2966 |
floralwhite: 0xfffaf0, |
| 2967 |
forestgreen: 0x228b22, |
| 2968 |
fuchsia: 0xff00ff, |
| 2969 |
gainsboro: 0xdcdcdc, |
| 2970 |
ghostwhite: 0xf8f8ff, |
| 2971 |
gold: 0xffd700, |
| 2972 |
goldenrod: 0xdaa520, |
| 2973 |
gray: 0x808080, |
| 2974 |
green: 0x008000, |
| 2975 |
greenyellow: 0xadff2f, |
| 2976 |
grey: 0x808080, |
| 2977 |
honeydew: 0xf0fff0, |
| 2978 |
hotpink: 0xff69b4, |
| 2979 |
indianred: 0xcd5c5c, |
| 2980 |
indigo: 0x4b0082, |
| 2981 |
ivory: 0xfffff0, |
| 2982 |
khaki: 0xf0e68c, |
| 2983 |
lavender: 0xe6e6fa, |
| 2984 |
lavenderblush: 0xfff0f5, |
| 2985 |
lawngreen: 0x7cfc00, |
| 2986 |
lemonchiffon: 0xfffacd, |
| 2987 |
lightblue: 0xadd8e6, |
| 2988 |
lightcoral: 0xf08080, |
| 2989 |
lightcyan: 0xe0ffff, |
| 2990 |
lightgoldenrodyellow: 0xfafad2, |
| 2991 |
lightgray: 0xd3d3d3, |
| 2992 |
lightgreen: 0x90ee90, |
| 2993 |
lightgrey: 0xd3d3d3, |
| 2994 |
lightpink: 0xffb6c1, |
| 2995 |
lightsalmon: 0xffa07a, |
| 2996 |
lightseagreen: 0x20b2aa, |
| 2997 |
lightskyblue: 0x87cefa, |
| 2998 |
lightslategray: 0x778899, |
| 2999 |
lightslategrey: 0x778899, |
| 3000 |
lightsteelblue: 0xb0c4de, |
| 3001 |
lightyellow: 0xffffe0, |
| 3002 |
lime: 0x00ff00, |
| 3003 |
limegreen: 0x32cd32, |
| 3004 |
linen: 0xfaf0e6, |
| 3005 |
magenta: 0xff00ff, |
| 3006 |
maroon: 0x800000, |
| 3007 |
mediumaquamarine: 0x66cdaa, |
| 3008 |
mediumblue: 0x0000cd, |
| 3009 |
mediumorchid: 0xba55d3, |
| 3010 |
mediumpurple: 0x9370db, |
| 3011 |
mediumseagreen: 0x3cb371, |
| 3012 |
mediumslateblue: 0x7b68ee, |
| 3013 |
mediumspringgreen: 0x00fa9a, |
| 3014 |
mediumturquoise: 0x48d1cc, |
| 3015 |
mediumvioletred: 0xc71585, |
| 3016 |
midnightblue: 0x191970, |
| 3017 |
mintcream: 0xf5fffa, |
| 3018 |
mistyrose: 0xffe4e1, |
| 3019 |
moccasin: 0xffe4b5, |
| 3020 |
navajowhite: 0xffdead, |
| 3021 |
navy: 0x000080, |
| 3022 |
oldlace: 0xfdf5e6, |
| 3023 |
olive: 0x808000, |
| 3024 |
olivedrab: 0x6b8e23, |
| 3025 |
orange: 0xffa500, |
| 3026 |
orangered: 0xff4500, |
| 3027 |
orchid: 0xda70d6, |
| 3028 |
palegoldenrod: 0xeee8aa, |
| 3029 |
palegreen: 0x98fb98, |
| 3030 |
paleturquoise: 0xafeeee, |
| 3031 |
palevioletred: 0xdb7093, |
| 3032 |
papayawhip: 0xffefd5, |
| 3033 |
peachpuff: 0xffdab9, |
| 3034 |
peru: 0xcd853f, |
| 3035 |
pink: 0xffc0cb, |
| 3036 |
plum: 0xdda0dd, |
| 3037 |
powderblue: 0xb0e0e6, |
| 3038 |
purple: 0x800080, |
| 3039 |
rebeccapurple: 0x663399, |
| 3040 |
red: 0xff0000, |
| 3041 |
rosybrown: 0xbc8f8f, |
| 3042 |
royalblue: 0x4169e1, |
| 3043 |
saddlebrown: 0x8b4513, |
| 3044 |
salmon: 0xfa8072, |
| 3045 |
sandybrown: 0xf4a460, |
| 3046 |
seagreen: 0x2e8b57, |
| 3047 |
seashell: 0xfff5ee, |
| 3048 |
sienna: 0xa0522d, |
| 3049 |
silver: 0xc0c0c0, |
| 3050 |
skyblue: 0x87ceeb, |
| 3051 |
slateblue: 0x6a5acd, |
| 3052 |
slategray: 0x708090, |
| 3053 |
slategrey: 0x708090, |
| 3054 |
snow: 0xfffafa, |
| 3055 |
springgreen: 0x00ff7f, |
| 3056 |
steelblue: 0x4682b4, |
| 3057 |
tan: 0xd2b48c, |
| 3058 |
teal: 0x008080, |
| 3059 |
thistle: 0xd8bfd8, |
| 3060 |
tomato: 0xff6347, |
| 3061 |
turquoise: 0x40e0d0, |
| 3062 |
violet: 0xee82ee, |
| 3063 |
wheat: 0xf5deb3, |
| 3064 |
white: 0xffffff, |
| 3065 |
whitesmoke: 0xf5f5f5, |
| 3066 |
yellow: 0xffff00, |
| 3067 |
yellowgreen: 0x9acd32 |
| 3068 |
}; |
| 3069 |
|
| 3070 |
define(Color, color, { |
| 3071 |
copy(channels) { |
| 3072 |
return Object.assign(new this.constructor, this, channels); |
| 3073 |
}, |
| 3074 |
displayable() { |
| 3075 |
return this.rgb().displayable(); |
| 3076 |
}, |
| 3077 |
hex: color_formatHex, // Deprecated! Use color.formatHex. |
| 3078 |
formatHex: color_formatHex, |
| 3079 |
formatHex8: color_formatHex8, |
| 3080 |
formatHsl: color_formatHsl, |
| 3081 |
formatRgb: color_formatRgb, |
| 3082 |
toString: color_formatRgb |
| 3083 |
}); |
| 3084 |
|
| 3085 |
function color_formatHex() { |
| 3086 |
return this.rgb().formatHex(); |
| 3087 |
} |
| 3088 |
|
| 3089 |
function color_formatHex8() { |
| 3090 |
return this.rgb().formatHex8(); |
| 3091 |
} |
| 3092 |
|
| 3093 |
function color_formatHsl() { |
| 3094 |
return hslConvert(this).formatHsl(); |
| 3095 |
} |
| 3096 |
|
| 3097 |
function color_formatRgb() { |
| 3098 |
return this.rgb().formatRgb(); |
| 3099 |
} |
| 3100 |
|
| 3101 |
function color(format) { |
| 3102 |
var m, l; |
| 3103 |
format = (format + "").trim().toLowerCase(); |
| 3104 |
return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000 |
| 3105 |
: l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) // #f00 |
| 3106 |
: l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000 |
| 3107 |
: l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) // #f000 |
| 3108 |
: null) // invalid hex |
| 3109 |
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0) |
| 3110 |
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%) |
| 3111 |
: (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1) |
| 3112 |
: (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1) |
| 3113 |
: (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%) |
| 3114 |
: (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1) |
| 3115 |
: named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins |
| 3116 |
: format === "transparent" ? new Rgb(NaN, NaN, NaN, 0) |
| 3117 |
: null; |
| 3118 |
} |
| 3119 |
|
| 3120 |
function rgbn(n) { |
| 3121 |
return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1); |
| 3122 |
} |
| 3123 |
|
| 3124 |
function rgba(r, g, b, a) { |
| 3125 |
if (a <= 0) r = g = b = NaN; |
| 3126 |
return new Rgb(r, g, b, a); |
| 3127 |
} |
| 3128 |
|
| 3129 |
function rgbConvert(o) { |
| 3130 |
if (!(o instanceof Color)) o = color(o); |
| 3131 |
if (!o) return new Rgb; |
| 3132 |
o = o.rgb(); |
| 3133 |
return new Rgb(o.r, o.g, o.b, o.opacity); |
| 3134 |
} |
| 3135 |
|
| 3136 |
function rgb(r, g, b, opacity) { |
| 3137 |
return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity); |
| 3138 |
} |
| 3139 |
|
| 3140 |
function Rgb(r, g, b, opacity) { |
| 3141 |
this.r = +r; |
| 3142 |
this.g = +g; |
| 3143 |
this.b = +b; |
| 3144 |
this.opacity = +opacity; |
| 3145 |
} |
| 3146 |
|
| 3147 |
define(Rgb, rgb, extend(Color, { |
| 3148 |
brighter(k) { |
| 3149 |
k = k == null ? brighter : Math.pow(brighter, k); |
| 3150 |
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity); |
| 3151 |
}, |
| 3152 |
darker(k) { |
| 3153 |
k = k == null ? darker : Math.pow(darker, k); |
| 3154 |
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity); |
| 3155 |
}, |
| 3156 |
rgb() { |
| 3157 |
return this; |
| 3158 |
}, |
| 3159 |
clamp() { |
| 3160 |
return new Rgb(clampi(this.r), clampi(this.g), clampi(this.b), clampa(this.opacity)); |
| 3161 |
}, |
| 3162 |
displayable() { |
| 3163 |
return (-0.5 <= this.r && this.r < 255.5) |
| 3164 |
&& (-0.5 <= this.g && this.g < 255.5) |
| 3165 |
&& (-0.5 <= this.b && this.b < 255.5) |
| 3166 |
&& (0 <= this.opacity && this.opacity <= 1); |
| 3167 |
}, |
| 3168 |
hex: rgb_formatHex, // Deprecated! Use color.formatHex. |
| 3169 |
formatHex: rgb_formatHex, |
| 3170 |
formatHex8: rgb_formatHex8, |
| 3171 |
formatRgb: rgb_formatRgb, |
| 3172 |
toString: rgb_formatRgb |
| 3173 |
})); |
| 3174 |
|
| 3175 |
function rgb_formatHex() { |
| 3176 |
return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}`; |
| 3177 |
} |
| 3178 |
|
| 3179 |
function rgb_formatHex8() { |
| 3180 |
return `#${hex(this.r)}${hex(this.g)}${hex(this.b)}${hex((isNaN(this.opacity) ? 1 : this.opacity) * 255)}`; |
| 3181 |
} |
| 3182 |
|
| 3183 |
function rgb_formatRgb() { |
| 3184 |
const a = clampa(this.opacity); |
| 3185 |
return `${a === 1 ? "rgb(" : "rgba("}${clampi(this.r)}, ${clampi(this.g)}, ${clampi(this.b)}${a === 1 ? ")" : `, ${a})`}`; |
| 3186 |
} |
| 3187 |
|
| 3188 |
function clampa(opacity) { |
| 3189 |
return isNaN(opacity) ? 1 : Math.max(0, Math.min(1, opacity)); |
| 3190 |
} |
| 3191 |
|
| 3192 |
function clampi(value) { |
| 3193 |
return Math.max(0, Math.min(255, Math.round(value) || 0)); |
| 3194 |
} |
| 3195 |
|
| 3196 |
function hex(value) { |
| 3197 |
value = clampi(value); |
| 3198 |
return (value < 16 ? "0" : "") + value.toString(16); |
| 3199 |
} |
| 3200 |
|
| 3201 |
function hsla(h, s, l, a) { |
| 3202 |
if (a <= 0) h = s = l = NaN; |
| 3203 |
else if (l <= 0 || l >= 1) h = s = NaN; |
| 3204 |
else if (s <= 0) h = NaN; |
| 3205 |
return new Hsl(h, s, l, a); |
| 3206 |
} |
| 3207 |
|
| 3208 |
function hslConvert(o) { |
| 3209 |
if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity); |
| 3210 |
if (!(o instanceof Color)) o = color(o); |
| 3211 |
if (!o) return new Hsl; |
| 3212 |
if (o instanceof Hsl) return o; |
| 3213 |
o = o.rgb(); |
| 3214 |
var r = o.r / 255, |
| 3215 |
g = o.g / 255, |
| 3216 |
b = o.b / 255, |
| 3217 |
min = Math.min(r, g, b), |
| 3218 |
max = Math.max(r, g, b), |
| 3219 |
h = NaN, |
| 3220 |
s = max - min, |
| 3221 |
l = (max + min) / 2; |
| 3222 |
if (s) { |
| 3223 |
if (r === max) h = (g - b) / s + (g < b) * 6; |
| 3224 |
else if (g === max) h = (b - r) / s + 2; |
| 3225 |
else h = (r - g) / s + 4; |
| 3226 |
s /= l < 0.5 ? max + min : 2 - max - min; |
| 3227 |
h *= 60; |
| 3228 |
} else { |
| 3229 |
s = l > 0 && l < 1 ? 0 : h; |
| 3230 |
} |
| 3231 |
return new Hsl(h, s, l, o.opacity); |
| 3232 |
} |
| 3233 |
|
| 3234 |
function hsl$2(h, s, l, opacity) { |
| 3235 |
return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity); |
| 3236 |
} |
| 3237 |
|
| 3238 |
function Hsl(h, s, l, opacity) { |
| 3239 |
this.h = +h; |
| 3240 |
this.s = +s; |
| 3241 |
this.l = +l; |
| 3242 |
this.opacity = +opacity; |
| 3243 |
} |
| 3244 |
|
| 3245 |
define(Hsl, hsl$2, extend(Color, { |
| 3246 |
brighter(k) { |
| 3247 |
k = k == null ? brighter : Math.pow(brighter, k); |
| 3248 |
return new Hsl(this.h, this.s, this.l * k, this.opacity); |
| 3249 |
}, |
| 3250 |
darker(k) { |
| 3251 |
k = k == null ? darker : Math.pow(darker, k); |
| 3252 |
return new Hsl(this.h, this.s, this.l * k, this.opacity); |
| 3253 |
}, |
| 3254 |
rgb() { |
| 3255 |
var h = this.h % 360 + (this.h < 0) * 360, |
| 3256 |
s = isNaN(h) || isNaN(this.s) ? 0 : this.s, |
| 3257 |
l = this.l, |
| 3258 |
m2 = l + (l < 0.5 ? l : 1 - l) * s, |
| 3259 |
m1 = 2 * l - m2; |
| 3260 |
return new Rgb( |
| 3261 |
hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2), |
| 3262 |
hsl2rgb(h, m1, m2), |
| 3263 |
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2), |
| 3264 |
this.opacity |
| 3265 |
); |
| 3266 |
}, |
| 3267 |
clamp() { |
| 3268 |
return new Hsl(clamph(this.h), clampt(this.s), clampt(this.l), clampa(this.opacity)); |
| 3269 |
}, |
| 3270 |
displayable() { |
| 3271 |
return (0 <= this.s && this.s <= 1 || isNaN(this.s)) |
| 3272 |
&& (0 <= this.l && this.l <= 1) |
| 3273 |
&& (0 <= this.opacity && this.opacity <= 1); |
| 3274 |
}, |
| 3275 |
formatHsl() { |
| 3276 |
const a = clampa(this.opacity); |
| 3277 |
return `${a === 1 ? "hsl(" : "hsla("}${clamph(this.h)}, ${clampt(this.s) * 100}%, ${clampt(this.l) * 100}%${a === 1 ? ")" : `, ${a})`}`; |
| 3278 |
} |
| 3279 |
})); |
| 3280 |
|
| 3281 |
function clamph(value) { |
| 3282 |
value = (value || 0) % 360; |
| 3283 |
return value < 0 ? value + 360 : value; |
| 3284 |
} |
| 3285 |
|
| 3286 |
function clampt(value) { |
| 3287 |
return Math.max(0, Math.min(1, value || 0)); |
| 3288 |
} |
| 3289 |
|
| 3290 |
/* From FvD 13.37, CSS Color Module Level 3 */ |
| 3291 |
function hsl2rgb(h, m1, m2) { |
| 3292 |
return (h < 60 ? m1 + (m2 - m1) * h / 60 |
| 3293 |
: h < 180 ? m2 |
| 3294 |
: h < 240 ? m1 + (m2 - m1) * (240 - h) / 60 |
| 3295 |
: m1) * 255; |
| 3296 |
} |
| 3297 |
|
| 3298 |
const radians$1 = Math.PI / 180; |
| 3299 |
const degrees$2 = 180 / Math.PI; |
| 3300 |
|
| 3301 |
// https://observablehq.com/@mbostock/lab-and-rgb |
| 3302 |
const K = 18, |
| 3303 |
Xn = 0.96422, |
| 3304 |
Yn = 1, |
| 3305 |
Zn = 0.82521, |
| 3306 |
t0$1 = 4 / 29, |
| 3307 |
t1$1 = 6 / 29, |
| 3308 |
t2 = 3 * t1$1 * t1$1, |
| 3309 |
t3 = t1$1 * t1$1 * t1$1; |
| 3310 |
|
| 3311 |
function labConvert(o) { |
| 3312 |
if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity); |
| 3313 |
if (o instanceof Hcl) return hcl2lab(o); |
| 3314 |
if (!(o instanceof Rgb)) o = rgbConvert(o); |
| 3315 |
var r = rgb2lrgb(o.r), |
| 3316 |
g = rgb2lrgb(o.g), |
| 3317 |
b = rgb2lrgb(o.b), |
| 3318 |
y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z; |
| 3319 |
if (r === g && g === b) x = z = y; else { |
| 3320 |
x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn); |
| 3321 |
z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn); |
| 3322 |
} |
| 3323 |
return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity); |
| 3324 |
} |
| 3325 |
|
| 3326 |
function gray(l, opacity) { |
| 3327 |
return new Lab(l, 0, 0, opacity == null ? 1 : opacity); |
| 3328 |
} |
| 3329 |
|
| 3330 |
function lab$1(l, a, b, opacity) { |
| 3331 |
return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity); |
| 3332 |
} |
| 3333 |
|
| 3334 |
function Lab(l, a, b, opacity) { |
| 3335 |
this.l = +l; |
| 3336 |
this.a = +a; |
| 3337 |
this.b = +b; |
| 3338 |
this.opacity = +opacity; |
| 3339 |
} |
| 3340 |
|
| 3341 |
define(Lab, lab$1, extend(Color, { |
| 3342 |
brighter(k) { |
| 3343 |
return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity); |
| 3344 |
}, |
| 3345 |
darker(k) { |
| 3346 |
return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity); |
| 3347 |
}, |
| 3348 |
rgb() { |
| 3349 |
var y = (this.l + 16) / 116, |
| 3350 |
x = isNaN(this.a) ? y : y + this.a / 500, |
| 3351 |
z = isNaN(this.b) ? y : y - this.b / 200; |
| 3352 |
x = Xn * lab2xyz(x); |
| 3353 |
y = Yn * lab2xyz(y); |
| 3354 |
z = Zn * lab2xyz(z); |
| 3355 |
return new Rgb( |
| 3356 |
lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z), |
| 3357 |
lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z), |
| 3358 |
lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z), |
| 3359 |
this.opacity |
| 3360 |
); |
| 3361 |
} |
| 3362 |
})); |
| 3363 |
|
| 3364 |
function xyz2lab(t) { |
| 3365 |
return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0$1; |
| 3366 |
} |
| 3367 |
|
| 3368 |
function lab2xyz(t) { |
| 3369 |
return t > t1$1 ? t * t * t : t2 * (t - t0$1); |
| 3370 |
} |
| 3371 |
|
| 3372 |
function lrgb2rgb(x) { |
| 3373 |
return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055); |
| 3374 |
} |
| 3375 |
|
| 3376 |
function rgb2lrgb(x) { |
| 3377 |
return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4); |
| 3378 |
} |
| 3379 |
|
| 3380 |
function hclConvert(o) { |
| 3381 |
if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity); |
| 3382 |
if (!(o instanceof Lab)) o = labConvert(o); |
| 3383 |
if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity); |
| 3384 |
var h = Math.atan2(o.b, o.a) * degrees$2; |
| 3385 |
return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity); |
| 3386 |
} |
| 3387 |
|
| 3388 |
function lch(l, c, h, opacity) { |
| 3389 |
return arguments.length === 1 ? hclConvert(l) : new Hcl(h, c, l, opacity == null ? 1 : opacity); |
| 3390 |
} |
| 3391 |
|
| 3392 |
function hcl$2(h, c, l, opacity) { |
| 3393 |
return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity); |
| 3394 |
} |
| 3395 |
|
| 3396 |
function Hcl(h, c, l, opacity) { |
| 3397 |
this.h = +h; |
| 3398 |
this.c = +c; |
| 3399 |
this.l = +l; |
| 3400 |
this.opacity = +opacity; |
| 3401 |
} |
| 3402 |
|
| 3403 |
function hcl2lab(o) { |
| 3404 |
if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity); |
| 3405 |
var h = o.h * radians$1; |
| 3406 |
return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity); |
| 3407 |
} |
| 3408 |
|
| 3409 |
define(Hcl, hcl$2, extend(Color, { |
| 3410 |
brighter(k) { |
| 3411 |
return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity); |
| 3412 |
}, |
| 3413 |
darker(k) { |
| 3414 |
return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity); |
| 3415 |
}, |
| 3416 |
rgb() { |
| 3417 |
return hcl2lab(this).rgb(); |
| 3418 |
} |
| 3419 |
})); |
| 3420 |
|
| 3421 |
var A = -0.14861, |
| 3422 |
B$1 = +1.78277, |
| 3423 |
C = -0.29227, |
| 3424 |
D$1 = -0.90649, |
| 3425 |
E = +1.97294, |
| 3426 |
ED = E * D$1, |
| 3427 |
EB = E * B$1, |
| 3428 |
BC_DA = B$1 * C - D$1 * A; |
| 3429 |
|
| 3430 |
function cubehelixConvert(o) { |
| 3431 |
if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity); |
| 3432 |
if (!(o instanceof Rgb)) o = rgbConvert(o); |
| 3433 |
var r = o.r / 255, |
| 3434 |
g = o.g / 255, |
| 3435 |
b = o.b / 255, |
| 3436 |
l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB), |
| 3437 |
bl = b - l, |
| 3438 |
k = (E * (g - l) - C * bl) / D$1, |
| 3439 |
s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1 |
| 3440 |
h = s ? Math.atan2(k, bl) * degrees$2 - 120 : NaN; |
| 3441 |
return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); |
| 3442 |
} |
| 3443 |
|
| 3444 |
function cubehelix$3(h, s, l, opacity) { |
| 3445 |
return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity); |
| 3446 |
} |
| 3447 |
|
| 3448 |
function Cubehelix(h, s, l, opacity) { |
| 3449 |
this.h = +h; |
| 3450 |
this.s = +s; |
| 3451 |
this.l = +l; |
| 3452 |
this.opacity = +opacity; |
| 3453 |
} |
| 3454 |
|
| 3455 |
define(Cubehelix, cubehelix$3, extend(Color, { |
| 3456 |
brighter(k) { |
| 3457 |
k = k == null ? brighter : Math.pow(brighter, k); |
| 3458 |
return new Cubehelix(this.h, this.s, this.l * k, this.opacity); |
| 3459 |
}, |
| 3460 |
darker(k) { |
| 3461 |
k = k == null ? darker : Math.pow(darker, k); |
| 3462 |
return new Cubehelix(this.h, this.s, this.l * k, this.opacity); |
| 3463 |
}, |
| 3464 |
rgb() { |
| 3465 |
var h = isNaN(this.h) ? 0 : (this.h + 120) * radians$1, |
| 3466 |
l = +this.l, |
| 3467 |
a = isNaN(this.s) ? 0 : this.s * l * (1 - l), |
| 3468 |
cosh = Math.cos(h), |
| 3469 |
sinh = Math.sin(h); |
| 3470 |
return new Rgb( |
| 3471 |
255 * (l + a * (A * cosh + B$1 * sinh)), |
| 3472 |
255 * (l + a * (C * cosh + D$1 * sinh)), |
| 3473 |
255 * (l + a * (E * cosh)), |
| 3474 |
this.opacity |
| 3475 |
); |
| 3476 |
} |
| 3477 |
})); |
| 3478 |
|
| 3479 |
function basis$1(t1, v0, v1, v2, v3) { |
| 3480 |
var t2 = t1 * t1, t3 = t2 * t1; |
| 3481 |
return ((1 - 3 * t1 + 3 * t2 - t3) * v0 |
| 3482 |
+ (4 - 6 * t2 + 3 * t3) * v1 |
| 3483 |
+ (1 + 3 * t1 + 3 * t2 - 3 * t3) * v2 |
| 3484 |
+ t3 * v3) / 6; |
| 3485 |
} |
| 3486 |
|
| 3487 |
function basis$2(values) { |
| 3488 |
var n = values.length - 1; |
| 3489 |
return function(t) { |
| 3490 |
var i = t <= 0 ? (t = 0) : t >= 1 ? (t = 1, n - 1) : Math.floor(t * n), |
| 3491 |
v1 = values[i], |
| 3492 |
v2 = values[i + 1], |
| 3493 |
v0 = i > 0 ? values[i - 1] : 2 * v1 - v2, |
| 3494 |
v3 = i < n - 1 ? values[i + 2] : 2 * v2 - v1; |
| 3495 |
return basis$1((t - i / n) * n, v0, v1, v2, v3); |
| 3496 |
}; |
| 3497 |
} |
| 3498 |
|
| 3499 |
function basisClosed$1(values) { |
| 3500 |
var n = values.length; |
| 3501 |
return function(t) { |
| 3502 |
var i = Math.floor(((t %= 1) < 0 ? ++t : t) * n), |
| 3503 |
v0 = values[(i + n - 1) % n], |
| 3504 |
v1 = values[i % n], |
| 3505 |
v2 = values[(i + 1) % n], |
| 3506 |
v3 = values[(i + 2) % n]; |
| 3507 |
return basis$1((t - i / n) * n, v0, v1, v2, v3); |
| 3508 |
}; |
| 3509 |
} |
| 3510 |
|
| 3511 |
var constant$8 = x => () => x; |
| 3512 |
|
| 3513 |
function linear$2(a, d) { |
| 3514 |
return function(t) { |
| 3515 |
return a + t * d; |
| 3516 |
}; |
| 3517 |
} |
| 3518 |
|
| 3519 |
function exponential$1(a, b, y) { |
| 3520 |
return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function(t) { |
| 3521 |
return Math.pow(a + t * b, y); |
| 3522 |
}; |
| 3523 |
} |
| 3524 |
|
| 3525 |
function hue$1(a, b) { |
| 3526 |
var d = b - a; |
| 3527 |
return d ? linear$2(a, d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d) : constant$8(isNaN(a) ? b : a); |
| 3528 |
} |
| 3529 |
|
| 3530 |
function gamma$1(y) { |
| 3531 |
return (y = +y) === 1 ? nogamma : function(a, b) { |
| 3532 |
return b - a ? exponential$1(a, b, y) : constant$8(isNaN(a) ? b : a); |
| 3533 |
}; |
| 3534 |
} |
| 3535 |
|
| 3536 |
function nogamma(a, b) { |
| 3537 |
var d = b - a; |
| 3538 |
return d ? linear$2(a, d) : constant$8(isNaN(a) ? b : a); |
| 3539 |
} |
| 3540 |
|
| 3541 |
var interpolateRgb = (function rgbGamma(y) { |
| 3542 |
var color = gamma$1(y); |
| 3543 |
|
| 3544 |
function rgb$1(start, end) { |
| 3545 |
var r = color((start = rgb(start)).r, (end = rgb(end)).r), |
| 3546 |
g = color(start.g, end.g), |
| 3547 |
b = color(start.b, end.b), |
| 3548 |
opacity = nogamma(start.opacity, end.opacity); |
| 3549 |
return function(t) { |
| 3550 |
start.r = r(t); |
| 3551 |
start.g = g(t); |
| 3552 |
start.b = b(t); |
| 3553 |
start.opacity = opacity(t); |
| 3554 |
return start + ""; |
| 3555 |
}; |
| 3556 |
} |
| 3557 |
|
| 3558 |
rgb$1.gamma = rgbGamma; |
| 3559 |
|
| 3560 |
return rgb$1; |
| 3561 |
})(1); |
| 3562 |
|
| 3563 |
function rgbSpline(spline) { |
| 3564 |
return function(colors) { |
| 3565 |
var n = colors.length, |
| 3566 |
r = new Array(n), |
| 3567 |
g = new Array(n), |
| 3568 |
b = new Array(n), |
| 3569 |
i, color; |
| 3570 |
for (i = 0; i < n; ++i) { |
| 3571 |
color = rgb(colors[i]); |
| 3572 |
r[i] = color.r || 0; |
| 3573 |
g[i] = color.g || 0; |
| 3574 |
b[i] = color.b || 0; |
| 3575 |
} |
| 3576 |
r = spline(r); |
| 3577 |
g = spline(g); |
| 3578 |
b = spline(b); |
| 3579 |
color.opacity = 1; |
| 3580 |
return function(t) { |
| 3581 |
color.r = r(t); |
| 3582 |
color.g = g(t); |
| 3583 |
color.b = b(t); |
| 3584 |
return color + ""; |
| 3585 |
}; |
| 3586 |
}; |
| 3587 |
} |
| 3588 |
|
| 3589 |
var rgbBasis = rgbSpline(basis$2); |
| 3590 |
var rgbBasisClosed = rgbSpline(basisClosed$1); |
| 3591 |
|
| 3592 |
function numberArray(a, b) { |
| 3593 |
if (!b) b = []; |
| 3594 |
var n = a ? Math.min(b.length, a.length) : 0, |
| 3595 |
c = b.slice(), |
| 3596 |
i; |
| 3597 |
return function(t) { |
| 3598 |
for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t; |
| 3599 |
return c; |
| 3600 |
}; |
| 3601 |
} |
| 3602 |
|
| 3603 |
function isNumberArray(x) { |
| 3604 |
return ArrayBuffer.isView(x) && !(x instanceof DataView); |
| 3605 |
} |
| 3606 |
|
| 3607 |
function array$3(a, b) { |
| 3608 |
return (isNumberArray(b) ? numberArray : genericArray)(a, b); |
| 3609 |
} |
| 3610 |
|
| 3611 |
function genericArray(a, b) { |
| 3612 |
var nb = b ? b.length : 0, |
| 3613 |
na = a ? Math.min(nb, a.length) : 0, |
| 3614 |
x = new Array(na), |
| 3615 |
c = new Array(nb), |
| 3616 |
i; |
| 3617 |
|
| 3618 |
for (i = 0; i < na; ++i) x[i] = interpolate$2(a[i], b[i]); |
| 3619 |
for (; i < nb; ++i) c[i] = b[i]; |
| 3620 |
|
| 3621 |
return function(t) { |
| 3622 |
for (i = 0; i < na; ++i) c[i] = x[i](t); |
| 3623 |
return c; |
| 3624 |
}; |
| 3625 |
} |
| 3626 |
|
| 3627 |
function date$1(a, b) { |
| 3628 |
var d = new Date; |
| 3629 |
return a = +a, b = +b, function(t) { |
| 3630 |
return d.setTime(a * (1 - t) + b * t), d; |
| 3631 |
}; |
| 3632 |
} |
| 3633 |
|
| 3634 |
function interpolateNumber(a, b) { |
| 3635 |
return a = +a, b = +b, function(t) { |
| 3636 |
return a * (1 - t) + b * t; |
| 3637 |
}; |
| 3638 |
} |
| 3639 |
|
| 3640 |
function object$1(a, b) { |
| 3641 |
var i = {}, |
| 3642 |
c = {}, |
| 3643 |
k; |
| 3644 |
|
| 3645 |
if (a === null || typeof a !== "object") a = {}; |
| 3646 |
if (b === null || typeof b !== "object") b = {}; |
| 3647 |
|
| 3648 |
for (k in b) { |
| 3649 |
if (k in a) { |
| 3650 |
i[k] = interpolate$2(a[k], b[k]); |
| 3651 |
} else { |
| 3652 |
c[k] = b[k]; |
| 3653 |
} |
| 3654 |
} |
| 3655 |
|
| 3656 |
return function(t) { |
| 3657 |
for (k in i) c[k] = i[k](t); |
| 3658 |
return c; |
| 3659 |
}; |
| 3660 |
} |
| 3661 |
|
| 3662 |
var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, |
| 3663 |
reB = new RegExp(reA.source, "g"); |
| 3664 |
|
| 3665 |
function zero(b) { |
| 3666 |
return function() { |
| 3667 |
return b; |
| 3668 |
}; |
| 3669 |
} |
| 3670 |
|
| 3671 |
function one(b) { |
| 3672 |
return function(t) { |
| 3673 |
return b(t) + ""; |
| 3674 |
}; |
| 3675 |
} |
| 3676 |
|
| 3677 |
function interpolateString(a, b) { |
| 3678 |
var bi = reA.lastIndex = reB.lastIndex = 0, // scan index for next number in b |
| 3679 |
am, // current match in a |
| 3680 |
bm, // current match in b |
| 3681 |
bs, // string preceding current number in b, if any |
| 3682 |
i = -1, // index in s |
| 3683 |
s = [], // string constants and placeholders |
| 3684 |
q = []; // number interpolators |
| 3685 |
|
| 3686 |
// Coerce inputs to strings. |
| 3687 |
a = a + "", b = b + ""; |
| 3688 |
|
| 3689 |
// Interpolate pairs of numbers in a & b. |
| 3690 |
while ((am = reA.exec(a)) |
| 3691 |
&& (bm = reB.exec(b))) { |
| 3692 |
if ((bs = bm.index) > bi) { // a string precedes the next number in b |
| 3693 |
bs = b.slice(bi, bs); |
| 3694 |
if (s[i]) s[i] += bs; // coalesce with previous string |
| 3695 |
else s[++i] = bs; |
| 3696 |
} |
| 3697 |
if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match |
| 3698 |
if (s[i]) s[i] += bm; // coalesce with previous string |
| 3699 |
else s[++i] = bm; |
| 3700 |
} else { // interpolate non-matching numbers |
| 3701 |
s[++i] = null; |
| 3702 |
q.push({i: i, x: interpolateNumber(am, bm)}); |
| 3703 |
} |
| 3704 |
bi = reB.lastIndex; |
| 3705 |
} |
| 3706 |
|
| 3707 |
// Add remains of b. |
| 3708 |
if (bi < b.length) { |
| 3709 |
bs = b.slice(bi); |
| 3710 |
if (s[i]) s[i] += bs; // coalesce with previous string |
| 3711 |
else s[++i] = bs; |
| 3712 |
} |
| 3713 |
|
| 3714 |
// Special optimization for only a single match. |
| 3715 |
// Otherwise, interpolate each of the numbers and rejoin the string. |
| 3716 |
return s.length < 2 ? (q[0] |
| 3717 |
? one(q[0].x) |
| 3718 |
: zero(b)) |
| 3719 |
: (b = q.length, function(t) { |
| 3720 |
for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t); |
| 3721 |
return s.join(""); |
| 3722 |
}); |
| 3723 |
} |
| 3724 |
|
| 3725 |
function interpolate$2(a, b) { |
| 3726 |
var t = typeof b, c; |
| 3727 |
return b == null || t === "boolean" ? constant$8(b) |
| 3728 |
: (t === "number" ? interpolateNumber |
| 3729 |
: t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString) |
| 3730 |
: b instanceof color ? interpolateRgb |
| 3731 |
: b instanceof Date ? date$1 |
| 3732 |
: isNumberArray(b) ? numberArray |
| 3733 |
: Array.isArray(b) ? genericArray |
| 3734 |
: typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object$1 |
| 3735 |
: interpolateNumber)(a, b); |
| 3736 |
} |
| 3737 |
|
| 3738 |
function discrete(range) { |
| 3739 |
var n = range.length; |
| 3740 |
return function(t) { |
| 3741 |
return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))]; |
| 3742 |
}; |
| 3743 |
} |
| 3744 |
|
| 3745 |
function hue(a, b) { |
| 3746 |
var i = hue$1(+a, +b); |
| 3747 |
return function(t) { |
| 3748 |
var x = i(t); |
| 3749 |
return x - 360 * Math.floor(x / 360); |
| 3750 |
}; |
| 3751 |
} |
| 3752 |
|
| 3753 |
function interpolateRound(a, b) { |
| 3754 |
return a = +a, b = +b, function(t) { |
| 3755 |
return Math.round(a * (1 - t) + b * t); |
| 3756 |
}; |
| 3757 |
} |
| 3758 |
|
| 3759 |
var degrees$1 = 180 / Math.PI; |
| 3760 |
|
| 3761 |
var identity$7 = { |
| 3762 |
translateX: 0, |
| 3763 |
translateY: 0, |
| 3764 |
rotate: 0, |
| 3765 |
skewX: 0, |
| 3766 |
scaleX: 1, |
| 3767 |
scaleY: 1 |
| 3768 |
}; |
| 3769 |
|
| 3770 |
function decompose(a, b, c, d, e, f) { |
| 3771 |
var scaleX, scaleY, skewX; |
| 3772 |
if (scaleX = Math.sqrt(a * a + b * b)) a /= scaleX, b /= scaleX; |
| 3773 |
if (skewX = a * c + b * d) c -= a * skewX, d -= b * skewX; |
| 3774 |
if (scaleY = Math.sqrt(c * c + d * d)) c /= scaleY, d /= scaleY, skewX /= scaleY; |
| 3775 |
if (a * d < b * c) a = -a, b = -b, skewX = -skewX, scaleX = -scaleX; |
| 3776 |
return { |
| 3777 |
translateX: e, |
| 3778 |
translateY: f, |
| 3779 |
rotate: Math.atan2(b, a) * degrees$1, |
| 3780 |
skewX: Math.atan(skewX) * degrees$1, |
| 3781 |
scaleX: scaleX, |
| 3782 |
scaleY: scaleY |
| 3783 |
}; |
| 3784 |
} |
| 3785 |
|
| 3786 |
var svgNode; |
| 3787 |
|
| 3788 |
/* eslint-disable no-undef */ |
| 3789 |
function parseCss(value) { |
| 3790 |
const m = new (typeof DOMMatrix === "function" ? DOMMatrix : WebKitCSSMatrix)(value + ""); |
| 3791 |
return m.isIdentity ? identity$7 : decompose(m.a, m.b, m.c, m.d, m.e, m.f); |
| 3792 |
} |
| 3793 |
|
| 3794 |
function parseSvg(value) { |
| 3795 |
if (value == null) return identity$7; |
| 3796 |
if (!svgNode) svgNode = document.createElementNS("http://www.w3.org/2000/svg", "g"); |
| 3797 |
svgNode.setAttribute("transform", value); |
| 3798 |
if (!(value = svgNode.transform.baseVal.consolidate())) return identity$7; |
| 3799 |
value = value.matrix; |
| 3800 |
return decompose(value.a, value.b, value.c, value.d, value.e, value.f); |
| 3801 |
} |
| 3802 |
|
| 3803 |
function interpolateTransform(parse, pxComma, pxParen, degParen) { |
| 3804 |
|
| 3805 |
function pop(s) { |
| 3806 |
return s.length ? s.pop() + " " : ""; |
| 3807 |
} |
| 3808 |
|
| 3809 |
function translate(xa, ya, xb, yb, s, q) { |
| 3810 |
if (xa !== xb || ya !== yb) { |
| 3811 |
var i = s.push("translate(", null, pxComma, null, pxParen); |
| 3812 |
q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)}); |
| 3813 |
} else if (xb || yb) { |
| 3814 |
s.push("translate(" + xb + pxComma + yb + pxParen); |
| 3815 |
} |
| 3816 |
} |
| 3817 |
|
| 3818 |
function rotate(a, b, s, q) { |
| 3819 |
if (a !== b) { |
| 3820 |
if (a - b > 180) b += 360; else if (b - a > 180) a += 360; // shortest path |
| 3821 |
q.push({i: s.push(pop(s) + "rotate(", null, degParen) - 2, x: interpolateNumber(a, b)}); |
| 3822 |
} else if (b) { |
| 3823 |
s.push(pop(s) + "rotate(" + b + degParen); |
| 3824 |
} |
| 3825 |
} |
| 3826 |
|
| 3827 |
function skewX(a, b, s, q) { |
| 3828 |
if (a !== b) { |
| 3829 |
q.push({i: s.push(pop(s) + "skewX(", null, degParen) - 2, x: interpolateNumber(a, b)}); |
| 3830 |
} else if (b) { |
| 3831 |
s.push(pop(s) + "skewX(" + b + degParen); |
| 3832 |
} |
| 3833 |
} |
| 3834 |
|
| 3835 |
function scale(xa, ya, xb, yb, s, q) { |
| 3836 |
if (xa !== xb || ya !== yb) { |
| 3837 |
var i = s.push(pop(s) + "scale(", null, ",", null, ")"); |
| 3838 |
q.push({i: i - 4, x: interpolateNumber(xa, xb)}, {i: i - 2, x: interpolateNumber(ya, yb)}); |
| 3839 |
} else if (xb !== 1 || yb !== 1) { |
| 3840 |
s.push(pop(s) + "scale(" + xb + "," + yb + ")"); |
| 3841 |
} |
| 3842 |
} |
| 3843 |
|
| 3844 |
return function(a, b) { |
| 3845 |
var s = [], // string constants and placeholders |
| 3846 |
q = []; // number interpolators |
| 3847 |
a = parse(a), b = parse(b); |
| 3848 |
translate(a.translateX, a.translateY, b.translateX, b.translateY, s, q); |
| 3849 |
rotate(a.rotate, b.rotate, s, q); |
| 3850 |
skewX(a.skewX, b.skewX, s, q); |
| 3851 |
scale(a.scaleX, a.scaleY, b.scaleX, b.scaleY, s, q); |
| 3852 |
a = b = null; // gc |
| 3853 |
return function(t) { |
| 3854 |
var i = -1, n = q.length, o; |
| 3855 |
while (++i < n) s[(o = q[i]).i] = o.x(t); |
| 3856 |
return s.join(""); |
| 3857 |
}; |
| 3858 |
}; |
| 3859 |
} |
| 3860 |
|
| 3861 |
var interpolateTransformCss = interpolateTransform(parseCss, "px, ", "px)", "deg)"); |
| 3862 |
var interpolateTransformSvg = interpolateTransform(parseSvg, ", ", ")", ")"); |
| 3863 |
|
| 3864 |
var epsilon2$1 = 1e-12; |
| 3865 |
|
| 3866 |
function cosh(x) { |
| 3867 |
return ((x = Math.exp(x)) + 1 / x) / 2; |
| 3868 |
} |
| 3869 |
|
| 3870 |
function sinh(x) { |
| 3871 |
return ((x = Math.exp(x)) - 1 / x) / 2; |
| 3872 |
} |
| 3873 |
|
| 3874 |
function tanh(x) { |
| 3875 |
return ((x = Math.exp(2 * x)) - 1) / (x + 1); |
| 3876 |
} |
| 3877 |
|
| 3878 |
var interpolateZoom = (function zoomRho(rho, rho2, rho4) { |
| 3879 |
|
| 3880 |
// p0 = [ux0, uy0, w0] |
| 3881 |
// p1 = [ux1, uy1, w1] |
| 3882 |
function zoom(p0, p1) { |
| 3883 |
var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], |
| 3884 |
ux1 = p1[0], uy1 = p1[1], w1 = p1[2], |
| 3885 |
dx = ux1 - ux0, |
| 3886 |
dy = uy1 - uy0, |
| 3887 |
d2 = dx * dx + dy * dy, |
| 3888 |
i, |
| 3889 |
S; |
| 3890 |
|
| 3891 |
// Special case for u0 ≅ u1. |
| 3892 |
if (d2 < epsilon2$1) { |
| 3893 |
S = Math.log(w1 / w0) / rho; |
| 3894 |
i = function(t) { |
| 3895 |
return [ |
| 3896 |
ux0 + t * dx, |
| 3897 |
uy0 + t * dy, |
| 3898 |
w0 * Math.exp(rho * t * S) |
| 3899 |
]; |
| 3900 |
}; |
| 3901 |
} |
| 3902 |
|
| 3903 |
// General case. |
| 3904 |
else { |
| 3905 |
var d1 = Math.sqrt(d2), |
| 3906 |
b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1), |
| 3907 |
b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1), |
| 3908 |
r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), |
| 3909 |
r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1); |
| 3910 |
S = (r1 - r0) / rho; |
| 3911 |
i = function(t) { |
| 3912 |
var s = t * S, |
| 3913 |
coshr0 = cosh(r0), |
| 3914 |
u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0)); |
| 3915 |
return [ |
| 3916 |
ux0 + u * dx, |
| 3917 |
uy0 + u * dy, |
| 3918 |
w0 * coshr0 / cosh(rho * s + r0) |
| 3919 |
]; |
| 3920 |
}; |
| 3921 |
} |
| 3922 |
|
| 3923 |
i.duration = S * 1000 * rho / Math.SQRT2; |
| 3924 |
|
| 3925 |
return i; |
| 3926 |
} |
| 3927 |
|
| 3928 |
zoom.rho = function(_) { |
| 3929 |
var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2; |
| 3930 |
return zoomRho(_1, _2, _4); |
| 3931 |
}; |
| 3932 |
|
| 3933 |
return zoom; |
| 3934 |
})(Math.SQRT2, 2, 4); |
| 3935 |
|
| 3936 |
function hsl(hue) { |
| 3937 |
return function(start, end) { |
| 3938 |
var h = hue((start = hsl$2(start)).h, (end = hsl$2(end)).h), |
| 3939 |
s = nogamma(start.s, end.s), |
| 3940 |
l = nogamma(start.l, end.l), |
| 3941 |
opacity = nogamma(start.opacity, end.opacity); |
| 3942 |
return function(t) { |
| 3943 |
start.h = h(t); |
| 3944 |
start.s = s(t); |
| 3945 |
start.l = l(t); |
| 3946 |
start.opacity = opacity(t); |
| 3947 |
return start + ""; |
| 3948 |
}; |
| 3949 |
} |
| 3950 |
} |
| 3951 |
|
| 3952 |
var hsl$1 = hsl(hue$1); |
| 3953 |
var hslLong = hsl(nogamma); |
| 3954 |
|
| 3955 |
function lab(start, end) { |
| 3956 |
var l = nogamma((start = lab$1(start)).l, (end = lab$1(end)).l), |
| 3957 |
a = nogamma(start.a, end.a), |
| 3958 |
b = nogamma(start.b, end.b), |
| 3959 |
opacity = nogamma(start.opacity, end.opacity); |
| 3960 |
return function(t) { |
| 3961 |
start.l = l(t); |
| 3962 |
start.a = a(t); |
| 3963 |
start.b = b(t); |
| 3964 |
start.opacity = opacity(t); |
| 3965 |
return start + ""; |
| 3966 |
}; |
| 3967 |
} |
| 3968 |
|
| 3969 |
function hcl(hue) { |
| 3970 |
return function(start, end) { |
| 3971 |
var h = hue((start = hcl$2(start)).h, (end = hcl$2(end)).h), |
| 3972 |
c = nogamma(start.c, end.c), |
| 3973 |
l = nogamma(start.l, end.l), |
| 3974 |
opacity = nogamma(start.opacity, end.opacity); |
| 3975 |
return function(t) { |
| 3976 |
start.h = h(t); |
| 3977 |
start.c = c(t); |
| 3978 |
start.l = l(t); |
| 3979 |
start.opacity = opacity(t); |
| 3980 |
return start + ""; |
| 3981 |
}; |
| 3982 |
} |
| 3983 |
} |
| 3984 |
|
| 3985 |
var hcl$1 = hcl(hue$1); |
| 3986 |
var hclLong = hcl(nogamma); |
| 3987 |
|
| 3988 |
function cubehelix$1(hue) { |
| 3989 |
return (function cubehelixGamma(y) { |
| 3990 |
y = +y; |
| 3991 |
|
| 3992 |
function cubehelix(start, end) { |
| 3993 |
var h = hue((start = cubehelix$3(start)).h, (end = cubehelix$3(end)).h), |
| 3994 |
s = nogamma(start.s, end.s), |
| 3995 |
l = nogamma(start.l, end.l), |
| 3996 |
opacity = nogamma(start.opacity, end.opacity); |
| 3997 |
return function(t) { |
| 3998 |
start.h = h(t); |
| 3999 |
start.s = s(t); |
| 4000 |
start.l = l(Math.pow(t, y)); |
| 4001 |
start.opacity = opacity(t); |
| 4002 |
return start + ""; |
| 4003 |
}; |
| 4004 |
} |
| 4005 |
|
| 4006 |
cubehelix.gamma = cubehelixGamma; |
| 4007 |
|
| 4008 |
return cubehelix; |
| 4009 |
})(1); |
| 4010 |
} |
| 4011 |
|
| 4012 |
var cubehelix$2 = cubehelix$1(hue$1); |
| 4013 |
var cubehelixLong = cubehelix$1(nogamma); |
| 4014 |
|
| 4015 |
function piecewise(interpolate, values) { |
| 4016 |
if (values === undefined) values = interpolate, interpolate = interpolate$2; |
| 4017 |
var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n); |
| 4018 |
while (i < n) I[i] = interpolate(v, v = values[++i]); |
| 4019 |
return function(t) { |
| 4020 |
var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n))); |
| 4021 |
return I[i](t - i); |
| 4022 |
}; |
| 4023 |
} |
| 4024 |
|
| 4025 |
function quantize$1(interpolator, n) { |
| 4026 |
var samples = new Array(n); |
| 4027 |
for (var i = 0; i < n; ++i) samples[i] = interpolator(i / (n - 1)); |
| 4028 |
return samples; |
| 4029 |
} |
| 4030 |
|
| 4031 |
var frame = 0, // is an animation frame pending? |
| 4032 |
timeout$1 = 0, // is a timeout pending? |
| 4033 |
interval$1 = 0, // are any timers active? |
| 4034 |
pokeDelay = 1000, // how frequently we check for clock skew |
| 4035 |
taskHead, |
| 4036 |
taskTail, |
| 4037 |
clockLast = 0, |
| 4038 |
clockNow = 0, |
| 4039 |
clockSkew = 0, |
| 4040 |
clock = typeof performance === "object" && performance.now ? performance : Date, |
| 4041 |
setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); }; |
| 4042 |
|
| 4043 |
function now() { |
| 4044 |
return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew); |
| 4045 |
} |
| 4046 |
|
| 4047 |
function clearNow() { |
| 4048 |
clockNow = 0; |
| 4049 |
} |
| 4050 |
|
| 4051 |
function Timer() { |
| 4052 |
this._call = |
| 4053 |
this._time = |
| 4054 |
this._next = null; |
| 4055 |
} |
| 4056 |
|
| 4057 |
Timer.prototype = timer.prototype = { |
| 4058 |
constructor: Timer, |
| 4059 |
restart: function(callback, delay, time) { |
| 4060 |
if (typeof callback !== "function") throw new TypeError("callback is not a function"); |
| 4061 |
time = (time == null ? now() : +time) + (delay == null ? 0 : +delay); |
| 4062 |
if (!this._next && taskTail !== this) { |
| 4063 |
if (taskTail) taskTail._next = this; |
| 4064 |
else taskHead = this; |
| 4065 |
taskTail = this; |
| 4066 |
} |
| 4067 |
this._call = callback; |
| 4068 |
this._time = time; |
| 4069 |
sleep(); |
| 4070 |
}, |
| 4071 |
stop: function() { |
| 4072 |
if (this._call) { |
| 4073 |
this._call = null; |
| 4074 |
this._time = Infinity; |
| 4075 |
sleep(); |
| 4076 |
} |
| 4077 |
} |
| 4078 |
}; |
| 4079 |
|
| 4080 |
function timer(callback, delay, time) { |
| 4081 |
var t = new Timer; |
| 4082 |
t.restart(callback, delay, time); |
| 4083 |
return t; |
| 4084 |
} |
| 4085 |
|
| 4086 |
function timerFlush() { |
| 4087 |
now(); // Get the current time, if not already set. |
| 4088 |
++frame; // Pretend we’ve set an alarm, if we haven’t already. |
| 4089 |
var t = taskHead, e; |
| 4090 |
while (t) { |
| 4091 |
if ((e = clockNow - t._time) >= 0) t._call.call(undefined, e); |
| 4092 |
t = t._next; |
| 4093 |
} |
| 4094 |
--frame; |
| 4095 |
} |
| 4096 |
|
| 4097 |
function wake() { |
| 4098 |
clockNow = (clockLast = clock.now()) + clockSkew; |
| 4099 |
frame = timeout$1 = 0; |
| 4100 |
try { |
| 4101 |
timerFlush(); |
| 4102 |
} finally { |
| 4103 |
frame = 0; |
| 4104 |
nap(); |
| 4105 |
clockNow = 0; |
| 4106 |
} |
| 4107 |
} |
| 4108 |
|
| 4109 |
function poke() { |
| 4110 |
var now = clock.now(), delay = now - clockLast; |
| 4111 |
if (delay > pokeDelay) clockSkew -= delay, clockLast = now; |
| 4112 |
} |
| 4113 |
|
| 4114 |
function nap() { |
| 4115 |
var t0, t1 = taskHead, t2, time = Infinity; |
| 4116 |
while (t1) { |
| 4117 |
if (t1._call) { |
| 4118 |
if (time > t1._time) time = t1._time; |
| 4119 |
t0 = t1, t1 = t1._next; |
| 4120 |
} else { |
| 4121 |
t2 = t1._next, t1._next = null; |
| 4122 |
t1 = t0 ? t0._next = t2 : taskHead = t2; |
| 4123 |
} |
| 4124 |
} |
| 4125 |
taskTail = t0; |
| 4126 |
sleep(time); |
| 4127 |
} |
| 4128 |
|
| 4129 |
function sleep(time) { |
| 4130 |
if (frame) return; // Soonest alarm already set, or will be. |
| 4131 |
if (timeout$1) timeout$1 = clearTimeout(timeout$1); |
| 4132 |
var delay = time - clockNow; // Strictly less than if we recomputed clockNow. |
| 4133 |
if (delay > 24) { |
| 4134 |
if (time < Infinity) timeout$1 = setTimeout(wake, time - clock.now() - clockSkew); |
| 4135 |
if (interval$1) interval$1 = clearInterval(interval$1); |
| 4136 |
} else { |
| 4137 |
if (!interval$1) clockLast = clock.now(), interval$1 = setInterval(poke, pokeDelay); |
| 4138 |
frame = 1, setFrame(wake); |
| 4139 |
} |
| 4140 |
} |
| 4141 |
|
| 4142 |
function timeout(callback, delay, time) { |
| 4143 |
var t = new Timer; |
| 4144 |
delay = delay == null ? 0 : +delay; |
| 4145 |
t.restart(elapsed => { |
| 4146 |
t.stop(); |
| 4147 |
callback(elapsed + delay); |
| 4148 |
}, delay, time); |
| 4149 |
return t; |
| 4150 |
} |
| 4151 |
|
| 4152 |
function interval(callback, delay, time) { |
| 4153 |
var t = new Timer, total = delay; |
| 4154 |
if (delay == null) return t.restart(callback, delay, time), t; |
| 4155 |
t._restart = t.restart; |
| 4156 |
t.restart = function(callback, delay, time) { |
| 4157 |
delay = +delay, time = time == null ? now() : +time; |
| 4158 |
t._restart(function tick(elapsed) { |
| 4159 |
elapsed += total; |
| 4160 |
t._restart(tick, total += delay, time); |
| 4161 |
callback(elapsed); |
| 4162 |
}, delay, time); |
| 4163 |
}; |
| 4164 |
t.restart(callback, delay, time); |
| 4165 |
return t; |
| 4166 |
} |
| 4167 |
|
| 4168 |
var emptyOn = dispatch("start", "end", "cancel", "interrupt"); |
| 4169 |
var emptyTween = []; |
| 4170 |
|
| 4171 |
var CREATED = 0; |
| 4172 |
var SCHEDULED = 1; |
| 4173 |
var STARTING = 2; |
| 4174 |
var STARTED = 3; |
| 4175 |
var RUNNING = 4; |
| 4176 |
var ENDING = 5; |
| 4177 |
var ENDED = 6; |
| 4178 |
|
| 4179 |
function schedule(node, name, id, index, group, timing) { |
| 4180 |
var schedules = node.__transition; |
| 4181 |
if (!schedules) node.__transition = {}; |
| 4182 |
else if (id in schedules) return; |
| 4183 |
create(node, id, { |
| 4184 |
name: name, |
| 4185 |
index: index, // For context during callback. |
| 4186 |
group: group, // For context during callback. |
| 4187 |
on: emptyOn, |
| 4188 |
tween: emptyTween, |
| 4189 |
time: timing.time, |
| 4190 |
delay: timing.delay, |
| 4191 |
duration: timing.duration, |
| 4192 |
ease: timing.ease, |
| 4193 |
timer: null, |
| 4194 |
state: CREATED |
| 4195 |
}); |
| 4196 |
} |
| 4197 |
|
| 4198 |
function init(node, id) { |
| 4199 |
var schedule = get(node, id); |
| 4200 |
if (schedule.state > CREATED) throw new Error("too late; already scheduled"); |
| 4201 |
return schedule; |
| 4202 |
} |
| 4203 |
|
| 4204 |
function set(node, id) { |
| 4205 |
var schedule = get(node, id); |
| 4206 |
if (schedule.state > STARTED) throw new Error("too late; already running"); |
| 4207 |
return schedule; |
| 4208 |
} |
| 4209 |
|
| 4210 |
function get(node, id) { |
| 4211 |
var schedule = node.__transition; |
| 4212 |
if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found"); |
| 4213 |
return schedule; |
| 4214 |
} |
| 4215 |
|
| 4216 |
function create(node, id, self) { |
| 4217 |
var schedules = node.__transition, |
| 4218 |
tween; |
| 4219 |
|
| 4220 |
// Initialize the self timer when the transition is created. |
| 4221 |
// Note the actual delay is not known until the first callback! |
| 4222 |
schedules[id] = self; |
| 4223 |
self.timer = timer(schedule, 0, self.time); |
| 4224 |
|
| 4225 |
function schedule(elapsed) { |
| 4226 |
self.state = SCHEDULED; |
| 4227 |
self.timer.restart(start, self.delay, self.time); |
| 4228 |
|
| 4229 |
// If the elapsed delay is less than our first sleep, start immediately. |
| 4230 |
if (self.delay <= elapsed) start(elapsed - self.delay); |
| 4231 |
} |
| 4232 |
|
| 4233 |
function start(elapsed) { |
| 4234 |
var i, j, n, o; |
| 4235 |
|
| 4236 |
// If the state is not SCHEDULED, then we previously errored on start. |
| 4237 |
if (self.state !== SCHEDULED) return stop(); |
| 4238 |
|
| 4239 |
for (i in schedules) { |
| 4240 |
o = schedules[i]; |
| 4241 |
if (o.name !== self.name) continue; |
| 4242 |
|
| 4243 |
// While this element already has a starting transition during this frame, |
| 4244 |
// defer starting an interrupting transition until that transition has a |
| 4245 |
// chance to tick (and possibly end); see d3/d3-transition#54! |
| 4246 |
if (o.state === STARTED) return timeout(start); |
| 4247 |
|
| 4248 |
// Interrupt the active transition, if any. |
| 4249 |
if (o.state === RUNNING) { |
| 4250 |
o.state = ENDED; |
| 4251 |
o.timer.stop(); |
| 4252 |
o.on.call("interrupt", node, node.__data__, o.index, o.group); |
| 4253 |
delete schedules[i]; |
| 4254 |
} |
| 4255 |
|
| 4256 |
// Cancel any pre-empted transitions. |
| 4257 |
else if (+i < id) { |
| 4258 |
o.state = ENDED; |
| 4259 |
o.timer.stop(); |
| 4260 |
o.on.call("cancel", node, node.__data__, o.index, o.group); |
| 4261 |
delete schedules[i]; |
| 4262 |
} |
| 4263 |
} |
| 4264 |
|
| 4265 |
// Defer the first tick to end of the current frame; see d3/d3#1576. |
| 4266 |
// Note the transition may be canceled after start and before the first tick! |
| 4267 |
// Note this must be scheduled before the start event; see d3/d3-transition#16! |
| 4268 |
// Assuming this is successful, subsequent callbacks go straight to tick. |
| 4269 |
timeout(function() { |
| 4270 |
if (self.state === STARTED) { |
| 4271 |
self.state = RUNNING; |
| 4272 |
self.timer.restart(tick, self.delay, self.time); |
| 4273 |
tick(elapsed); |
| 4274 |
} |
| 4275 |
}); |
| 4276 |
|
| 4277 |
// Dispatch the start event. |
| 4278 |
// Note this must be done before the tween are initialized. |
| 4279 |
self.state = STARTING; |
| 4280 |
self.on.call("start", node, node.__data__, self.index, self.group); |
| 4281 |
if (self.state !== STARTING) return; // interrupted |
| 4282 |
self.state = STARTED; |
| 4283 |
|
| 4284 |
// Initialize the tween, deleting null tween. |
| 4285 |
tween = new Array(n = self.tween.length); |
| 4286 |
for (i = 0, j = -1; i < n; ++i) { |
| 4287 |
if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) { |
| 4288 |
tween[++j] = o; |
| 4289 |
} |
| 4290 |
} |
| 4291 |
tween.length = j + 1; |
| 4292 |
} |
| 4293 |
|
| 4294 |
function tick(elapsed) { |
| 4295 |
var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1), |
| 4296 |
i = -1, |
| 4297 |
n = tween.length; |
| 4298 |
|
| 4299 |
while (++i < n) { |
| 4300 |
tween[i].call(node, t); |
| 4301 |
} |
| 4302 |
|
| 4303 |
// Dispatch the end event. |
| 4304 |
if (self.state === ENDING) { |
| 4305 |
self.on.call("end", node, node.__data__, self.index, self.group); |
| 4306 |
stop(); |
| 4307 |
} |
| 4308 |
} |
| 4309 |
|
| 4310 |
function stop() { |
| 4311 |
self.state = ENDED; |
| 4312 |
self.timer.stop(); |
| 4313 |
delete schedules[id]; |
| 4314 |
for (var i in schedules) return; // eslint-disable-line no-unused-vars |
| 4315 |
delete node.__transition; |
| 4316 |
} |
| 4317 |
} |
| 4318 |
|
| 4319 |
function interrupt(node, name) { |
| 4320 |
var schedules = node.__transition, |
| 4321 |
schedule, |
| 4322 |
active, |
| 4323 |
empty = true, |
| 4324 |
i; |
| 4325 |
|
| 4326 |
if (!schedules) return; |
| 4327 |
|
| 4328 |
name = name == null ? null : name + ""; |
| 4329 |
|
| 4330 |
for (i in schedules) { |
| 4331 |
if ((schedule = schedules[i]).name !== name) { empty = false; continue; } |
| 4332 |
active = schedule.state > STARTING && schedule.state < ENDING; |
| 4333 |
schedule.state = ENDED; |
| 4334 |
schedule.timer.stop(); |
| 4335 |
schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group); |
| 4336 |
delete schedules[i]; |
| 4337 |
} |
| 4338 |
|
| 4339 |
if (empty) delete node.__transition; |
| 4340 |
} |
| 4341 |
|
| 4342 |
function selection_interrupt(name) { |
| 4343 |
return this.each(function() { |
| 4344 |
interrupt(this, name); |
| 4345 |
}); |
| 4346 |
} |
| 4347 |
|
| 4348 |
function tweenRemove(id, name) { |
| 4349 |
var tween0, tween1; |
| 4350 |
return function() { |
| 4351 |
var schedule = set(this, id), |
| 4352 |
tween = schedule.tween; |
| 4353 |
|
| 4354 |
// If this node shared tween with the previous node, |
| 4355 |
// just assign the updated shared tween and we’re done! |
| 4356 |
// Otherwise, copy-on-write. |
| 4357 |
if (tween !== tween0) { |
| 4358 |
tween1 = tween0 = tween; |
| 4359 |
for (var i = 0, n = tween1.length; i < n; ++i) { |
| 4360 |
if (tween1[i].name === name) { |
| 4361 |
tween1 = tween1.slice(); |
| 4362 |
tween1.splice(i, 1); |
| 4363 |
break; |
| 4364 |
} |
| 4365 |
} |
| 4366 |
} |
| 4367 |
|
| 4368 |
schedule.tween = tween1; |
| 4369 |
}; |
| 4370 |
} |
| 4371 |
|
| 4372 |
function tweenFunction(id, name, value) { |
| 4373 |
var tween0, tween1; |
| 4374 |
if (typeof value !== "function") throw new Error; |
| 4375 |
return function() { |
| 4376 |
var schedule = set(this, id), |
| 4377 |
tween = schedule.tween; |
| 4378 |
|
| 4379 |
// If this node shared tween with the previous node, |
| 4380 |
// just assign the updated shared tween and we’re done! |
| 4381 |
// Otherwise, copy-on-write. |
| 4382 |
if (tween !== tween0) { |
| 4383 |
tween1 = (tween0 = tween).slice(); |
| 4384 |
for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) { |
| 4385 |
if (tween1[i].name === name) { |
| 4386 |
tween1[i] = t; |
| 4387 |
break; |
| 4388 |
} |
| 4389 |
} |
| 4390 |
if (i === n) tween1.push(t); |
| 4391 |
} |
| 4392 |
|
| 4393 |
schedule.tween = tween1; |
| 4394 |
}; |
| 4395 |
} |
| 4396 |
|
| 4397 |
function transition_tween(name, value) { |
| 4398 |
var id = this._id; |
| 4399 |
|
| 4400 |
name += ""; |
| 4401 |
|
| 4402 |
if (arguments.length < 2) { |
| 4403 |
var tween = get(this.node(), id).tween; |
| 4404 |
for (var i = 0, n = tween.length, t; i < n; ++i) { |
| 4405 |
if ((t = tween[i]).name === name) { |
| 4406 |
return t.value; |
| 4407 |
} |
| 4408 |
} |
| 4409 |
return null; |
| 4410 |
} |
| 4411 |
|
| 4412 |
return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value)); |
| 4413 |
} |
| 4414 |
|
| 4415 |
function tweenValue(transition, name, value) { |
| 4416 |
var id = transition._id; |
| 4417 |
|
| 4418 |
transition.each(function() { |
| 4419 |
var schedule = set(this, id); |
| 4420 |
(schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments); |
| 4421 |
}); |
| 4422 |
|
| 4423 |
return function(node) { |
| 4424 |
return get(node, id).value[name]; |
| 4425 |
}; |
| 4426 |
} |
| 4427 |
|
| 4428 |
function interpolate$1(a, b) { |
| 4429 |
var c; |
| 4430 |
return (typeof b === "number" ? interpolateNumber |
| 4431 |
: b instanceof color ? interpolateRgb |
| 4432 |
: (c = color(b)) ? (b = c, interpolateRgb) |
| 4433 |
: interpolateString)(a, b); |
| 4434 |
} |
| 4435 |
|
| 4436 |
function attrRemove(name) { |
| 4437 |
return function() { |
| 4438 |
this.removeAttribute(name); |
| 4439 |
}; |
| 4440 |
} |
| 4441 |
|
| 4442 |
function attrRemoveNS(fullname) { |
| 4443 |
return function() { |
| 4444 |
this.removeAttributeNS(fullname.space, fullname.local); |
| 4445 |
}; |
| 4446 |
} |
| 4447 |
|
| 4448 |
function attrConstant(name, interpolate, value1) { |
| 4449 |
var string00, |
| 4450 |
string1 = value1 + "", |
| 4451 |
interpolate0; |
| 4452 |
return function() { |
| 4453 |
var string0 = this.getAttribute(name); |
| 4454 |
return string0 === string1 ? null |
| 4455 |
: string0 === string00 ? interpolate0 |
| 4456 |
: interpolate0 = interpolate(string00 = string0, value1); |
| 4457 |
}; |
| 4458 |
} |
| 4459 |
|
| 4460 |
function attrConstantNS(fullname, interpolate, value1) { |
| 4461 |
var string00, |
| 4462 |
string1 = value1 + "", |
| 4463 |
interpolate0; |
| 4464 |
return function() { |
| 4465 |
var string0 = this.getAttributeNS(fullname.space, fullname.local); |
| 4466 |
return string0 === string1 ? null |
| 4467 |
: string0 === string00 ? interpolate0 |
| 4468 |
: interpolate0 = interpolate(string00 = string0, value1); |
| 4469 |
}; |
| 4470 |
} |
| 4471 |
|
| 4472 |
function attrFunction(name, interpolate, value) { |
| 4473 |
var string00, |
| 4474 |
string10, |
| 4475 |
interpolate0; |
| 4476 |
return function() { |
| 4477 |
var string0, value1 = value(this), string1; |
| 4478 |
if (value1 == null) return void this.removeAttribute(name); |
| 4479 |
string0 = this.getAttribute(name); |
| 4480 |
string1 = value1 + ""; |
| 4481 |
return string0 === string1 ? null |
| 4482 |
: string0 === string00 && string1 === string10 ? interpolate0 |
| 4483 |
: (string10 = string1, interpolate0 = interpolate(string00 = string0, value1)); |
| 4484 |
}; |
| 4485 |
} |
| 4486 |
|
| 4487 |
function attrFunctionNS(fullname, interpolate, value) { |
| 4488 |
var string00, |
| 4489 |
string10, |
| 4490 |
interpolate0; |
| 4491 |
return function() { |
| 4492 |
var string0, value1 = value(this), string1; |
| 4493 |
if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local); |
| 4494 |
string0 = this.getAttributeNS(fullname.space, fullname.local); |
| 4495 |
string1 = value1 + ""; |
| 4496 |
return string0 === string1 ? null |
| 4497 |
: string0 === string00 && string1 === string10 ? interpolate0 |
| 4498 |
: (string10 = string1, interpolate0 = interpolate(string00 = string0, value1)); |
| 4499 |
}; |
| 4500 |
} |
| 4501 |
|
| 4502 |
function transition_attr(name, value) { |
| 4503 |
var fullname = namespace(name), i = fullname === "transform" ? interpolateTransformSvg : interpolate$1; |
| 4504 |
return this.attrTween(name, typeof value === "function" |
| 4505 |
? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value)) |
| 4506 |
: value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname) |
| 4507 |
: (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value)); |
| 4508 |
} |
| 4509 |
|
| 4510 |
function attrInterpolate(name, i) { |
| 4511 |
return function(t) { |
| 4512 |
this.setAttribute(name, i.call(this, t)); |
| 4513 |
}; |
| 4514 |
} |
| 4515 |
|
| 4516 |
function attrInterpolateNS(fullname, i) { |
| 4517 |
return function(t) { |
| 4518 |
this.setAttributeNS(fullname.space, fullname.local, i.call(this, t)); |
| 4519 |
}; |
| 4520 |
} |
| 4521 |
|
| 4522 |
function attrTweenNS(fullname, value) { |
| 4523 |
var t0, i0; |
| 4524 |
function tween() { |
| 4525 |
var i = value.apply(this, arguments); |
| 4526 |
if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i); |
| 4527 |
return t0; |
| 4528 |
} |
| 4529 |
tween._value = value; |
| 4530 |
return tween; |
| 4531 |
} |
| 4532 |
|
| 4533 |
function attrTween(name, value) { |
| 4534 |
var t0, i0; |
| 4535 |
function tween() { |
| 4536 |
var i = value.apply(this, arguments); |
| 4537 |
if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i); |
| 4538 |
return t0; |
| 4539 |
} |
| 4540 |
tween._value = value; |
| 4541 |
return tween; |
| 4542 |
} |
| 4543 |
|
| 4544 |
function transition_attrTween(name, value) { |
| 4545 |
var key = "attr." + name; |
| 4546 |
if (arguments.length < 2) return (key = this.tween(key)) && key._value; |
| 4547 |
if (value == null) return this.tween(key, null); |
| 4548 |
if (typeof value !== "function") throw new Error; |
| 4549 |
var fullname = namespace(name); |
| 4550 |
return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value)); |
| 4551 |
} |
| 4552 |
|
| 4553 |
function delayFunction(id, value) { |
| 4554 |
return function() { |
| 4555 |
init(this, id).delay = +value.apply(this, arguments); |
| 4556 |
}; |
| 4557 |
} |
| 4558 |
|
| 4559 |
function delayConstant(id, value) { |
| 4560 |
return value = +value, function() { |
| 4561 |
init(this, id).delay = value; |
| 4562 |
}; |
| 4563 |
} |
| 4564 |
|
| 4565 |
function transition_delay(value) { |
| 4566 |
var id = this._id; |
| 4567 |
|
| 4568 |
return arguments.length |
| 4569 |
? this.each((typeof value === "function" |
| 4570 |
? delayFunction |
| 4571 |
: delayConstant)(id, value)) |
| 4572 |
: get(this.node(), id).delay; |
| 4573 |
} |
| 4574 |
|
| 4575 |
function durationFunction(id, value) { |
| 4576 |
return function() { |
| 4577 |
set(this, id).duration = +value.apply(this, arguments); |
| 4578 |
}; |
| 4579 |
} |
| 4580 |
|
| 4581 |
function durationConstant(id, value) { |
| 4582 |
return value = +value, function() { |
| 4583 |
set(this, id).duration = value; |
| 4584 |
}; |
| 4585 |
} |
| 4586 |
|
| 4587 |
function transition_duration(value) { |
| 4588 |
var id = this._id; |
| 4589 |
|
| 4590 |
return arguments.length |
| 4591 |
? this.each((typeof value === "function" |
| 4592 |
? durationFunction |
| 4593 |
: durationConstant)(id, value)) |
| 4594 |
: get(this.node(), id).duration; |
| 4595 |
} |
| 4596 |
|
| 4597 |
function easeConstant(id, value) { |
| 4598 |
if (typeof value !== "function") throw new Error; |
| 4599 |
return function() { |
| 4600 |
set(this, id).ease = value; |
| 4601 |
}; |
| 4602 |
} |
| 4603 |
|
| 4604 |
function transition_ease(value) { |
| 4605 |
var id = this._id; |
| 4606 |
|
| 4607 |
return arguments.length |
| 4608 |
? this.each(easeConstant(id, value)) |
| 4609 |
: get(this.node(), id).ease; |
| 4610 |
} |
| 4611 |
|
| 4612 |
function easeVarying(id, value) { |
| 4613 |
return function() { |
| 4614 |
var v = value.apply(this, arguments); |
| 4615 |
if (typeof v !== "function") throw new Error; |
| 4616 |
set(this, id).ease = v; |
| 4617 |
}; |
| 4618 |
} |
| 4619 |
|
| 4620 |
function transition_easeVarying(value) { |
| 4621 |
if (typeof value !== "function") throw new Error; |
| 4622 |
return this.each(easeVarying(this._id, value)); |
| 4623 |
} |
| 4624 |
|
| 4625 |
function transition_filter(match) { |
| 4626 |
if (typeof match !== "function") match = matcher(match); |
| 4627 |
|
| 4628 |
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { |
| 4629 |
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) { |
| 4630 |
if ((node = group[i]) && match.call(node, node.__data__, i, group)) { |
| 4631 |
subgroup.push(node); |
| 4632 |
} |
| 4633 |
} |
| 4634 |
} |
| 4635 |
|
| 4636 |
return new Transition(subgroups, this._parents, this._name, this._id); |
| 4637 |
} |
| 4638 |
|
| 4639 |
function transition_merge(transition) { |
| 4640 |
if (transition._id !== this._id) throw new Error; |
| 4641 |
|
| 4642 |
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) { |
| 4643 |
for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) { |
| 4644 |
if (node = group0[i] || group1[i]) { |
| 4645 |
merge[i] = node; |
| 4646 |
} |
| 4647 |
} |
| 4648 |
} |
| 4649 |
|
| 4650 |
for (; j < m0; ++j) { |
| 4651 |
merges[j] = groups0[j]; |
| 4652 |
} |
| 4653 |
|
| 4654 |
return new Transition(merges, this._parents, this._name, this._id); |
| 4655 |
} |
| 4656 |
|
| 4657 |
function start(name) { |
| 4658 |
return (name + "").trim().split(/^|\s+/).every(function(t) { |
| 4659 |
var i = t.indexOf("."); |
| 4660 |
if (i >= 0) t = t.slice(0, i); |
| 4661 |
return !t || t === "start"; |
| 4662 |
}); |
| 4663 |
} |
| 4664 |
|
| 4665 |
function onFunction(id, name, listener) { |
| 4666 |
var on0, on1, sit = start(name) ? init : set; |
| 4667 |
return function() { |
| 4668 |
var schedule = sit(this, id), |
| 4669 |
on = schedule.on; |
| 4670 |
|
| 4671 |
// If this node shared a dispatch with the previous node, |
| 4672 |
// just assign the updated shared dispatch and we’re done! |
| 4673 |
// Otherwise, copy-on-write. |
| 4674 |
if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener); |
| 4675 |
|
| 4676 |
schedule.on = on1; |
| 4677 |
}; |
| 4678 |
} |
| 4679 |
|
| 4680 |
function transition_on(name, listener) { |
| 4681 |
var id = this._id; |
| 4682 |
|
| 4683 |
return arguments.length < 2 |
| 4684 |
? get(this.node(), id).on.on(name) |
| 4685 |
: this.each(onFunction(id, name, listener)); |
| 4686 |
} |
| 4687 |
|
| 4688 |
function removeFunction(id) { |
| 4689 |
return function() { |
| 4690 |
var parent = this.parentNode; |
| 4691 |
for (var i in this.__transition) if (+i !== id) return; |
| 4692 |
if (parent) parent.removeChild(this); |
| 4693 |
}; |
| 4694 |
} |
| 4695 |
|
| 4696 |
function transition_remove() { |
| 4697 |
return this.on("end.remove", removeFunction(this._id)); |
| 4698 |
} |
| 4699 |
|
| 4700 |
function transition_select(select) { |
| 4701 |
var name = this._name, |
| 4702 |
id = this._id; |
| 4703 |
|
| 4704 |
if (typeof select !== "function") select = selector(select); |
| 4705 |
|
| 4706 |
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) { |
| 4707 |
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) { |
| 4708 |
if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) { |
| 4709 |
if ("__data__" in node) subnode.__data__ = node.__data__; |
| 4710 |
subgroup[i] = subnode; |
| 4711 |
schedule(subgroup[i], name, id, i, subgroup, get(node, id)); |
| 4712 |
} |
| 4713 |
} |
| 4714 |
} |
| 4715 |
|
| 4716 |
return new Transition(subgroups, this._parents, name, id); |
| 4717 |
} |
| 4718 |
|
| 4719 |
function transition_selectAll(select) { |
| 4720 |
var name = this._name, |
| 4721 |
id = this._id; |
| 4722 |
|
| 4723 |
if (typeof select !== "function") select = selectorAll(select); |
| 4724 |
|
| 4725 |
for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) { |
| 4726 |
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { |
| 4727 |
if (node = group[i]) { |
| 4728 |
for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) { |
| 4729 |
if (child = children[k]) { |
| 4730 |
schedule(child, name, id, k, children, inherit); |
| 4731 |
} |
| 4732 |
} |
| 4733 |
subgroups.push(children); |
| 4734 |
parents.push(node); |
| 4735 |
} |
| 4736 |
} |
| 4737 |
} |
| 4738 |
|
| 4739 |
return new Transition(subgroups, parents, name, id); |
| 4740 |
} |
| 4741 |
|
| 4742 |
var Selection = selection.prototype.constructor; |
| 4743 |
|
| 4744 |
function transition_selection() { |
| 4745 |
return new Selection(this._groups, this._parents); |
| 4746 |
} |
| 4747 |
|
| 4748 |
function styleNull(name, interpolate) { |
| 4749 |
var string00, |
| 4750 |
string10, |
| 4751 |
interpolate0; |
| 4752 |
return function() { |
| 4753 |
var string0 = styleValue(this, name), |
| 4754 |
string1 = (this.style.removeProperty(name), styleValue(this, name)); |
| 4755 |
return string0 === string1 ? null |
| 4756 |
: string0 === string00 && string1 === string10 ? interpolate0 |
| 4757 |
: interpolate0 = interpolate(string00 = string0, string10 = string1); |
| 4758 |
}; |
| 4759 |
} |
| 4760 |
|
| 4761 |
function styleRemove(name) { |
| 4762 |
return function() { |
| 4763 |
this.style.removeProperty(name); |
| 4764 |
}; |
| 4765 |
} |
| 4766 |
|
| 4767 |
function styleConstant(name, interpolate, value1) { |
| 4768 |
var string00, |
| 4769 |
string1 = value1 + "", |
| 4770 |
interpolate0; |
| 4771 |
return function() { |
| 4772 |
var string0 = styleValue(this, name); |
| 4773 |
return string0 === string1 ? null |
| 4774 |
: string0 === string00 ? interpolate0 |
| 4775 |
: interpolate0 = interpolate(string00 = string0, value1); |
| 4776 |
}; |
| 4777 |
} |
| 4778 |
|
| 4779 |
function styleFunction(name, interpolate, value) { |
| 4780 |
var string00, |
| 4781 |
string10, |
| 4782 |
interpolate0; |
| 4783 |
return function() { |
| 4784 |
var string0 = styleValue(this, name), |
| 4785 |
value1 = value(this), |
| 4786 |
string1 = value1 + ""; |
| 4787 |
if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name)); |
| 4788 |
return string0 === string1 ? null |
| 4789 |
: string0 === string00 && string1 === string10 ? interpolate0 |
| 4790 |
: (string10 = string1, interpolate0 = interpolate(string00 = string0, value1)); |
| 4791 |
}; |
| 4792 |
} |
| 4793 |
|
| 4794 |
function styleMaybeRemove(id, name) { |
| 4795 |
var on0, on1, listener0, key = "style." + name, event = "end." + key, remove; |
| 4796 |
return function() { |
| 4797 |
var schedule = set(this, id), |
| 4798 |
on = schedule.on, |
| 4799 |
listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined; |
| 4800 |
|
| 4801 |
// If this node shared a dispatch with the previous node, |
| 4802 |
// just assign the updated shared dispatch and we’re done! |
| 4803 |
// Otherwise, copy-on-write. |
| 4804 |
if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener); |
| 4805 |
|
| 4806 |
schedule.on = on1; |
| 4807 |
}; |
| 4808 |
} |
| 4809 |
|
| 4810 |
function transition_style(name, value, priority) { |
| 4811 |
var i = (name += "") === "transform" ? interpolateTransformCss : interpolate$1; |
| 4812 |
return value == null ? this |
| 4813 |
.styleTween(name, styleNull(name, i)) |
| 4814 |
.on("end.style." + name, styleRemove(name)) |
| 4815 |
: typeof value === "function" ? this |
| 4816 |
.styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value))) |
| 4817 |
.each(styleMaybeRemove(this._id, name)) |
| 4818 |
: this |
| 4819 |
.styleTween(name, styleConstant(name, i, value), priority) |
| 4820 |
.on("end.style." + name, null); |
| 4821 |
} |
| 4822 |
|
| 4823 |
function styleInterpolate(name, i, priority) { |
| 4824 |
return function(t) { |
| 4825 |
this.style.setProperty(name, i.call(this, t), priority); |
| 4826 |
}; |
| 4827 |
} |
| 4828 |
|
| 4829 |
function styleTween(name, value, priority) { |
| 4830 |
var t, i0; |
| 4831 |
function tween() { |
| 4832 |
var i = value.apply(this, arguments); |
| 4833 |
if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority); |
| 4834 |
return t; |
| 4835 |
} |
| 4836 |
tween._value = value; |
| 4837 |
return tween; |
| 4838 |
} |
| 4839 |
|
| 4840 |
function transition_styleTween(name, value, priority) { |
| 4841 |
var key = "style." + (name += ""); |
| 4842 |
if (arguments.length < 2) return (key = this.tween(key)) && key._value; |
| 4843 |
if (value == null) return this.tween(key, null); |
| 4844 |
if (typeof value !== "function") throw new Error; |
| 4845 |
return this.tween(key, styleTween(name, value, priority == null ? "" : priority)); |
| 4846 |
} |
| 4847 |
|
| 4848 |
function textConstant(value) { |
| 4849 |
return function() { |
| 4850 |
this.textContent = value; |
| 4851 |
}; |
| 4852 |
} |
| 4853 |
|
| 4854 |
function textFunction(value) { |
| 4855 |
return function() { |
| 4856 |
var value1 = value(this); |
| 4857 |
this.textContent = value1 == null ? "" : value1; |
| 4858 |
}; |
| 4859 |
} |
| 4860 |
|
| 4861 |
function transition_text(value) { |
| 4862 |
return this.tween("text", typeof value === "function" |
| 4863 |
? textFunction(tweenValue(this, "text", value)) |
| 4864 |
: textConstant(value == null ? "" : value + "")); |
| 4865 |
} |
| 4866 |
|
| 4867 |
function textInterpolate(i) { |
| 4868 |
return function(t) { |
| 4869 |
this.textContent = i.call(this, t); |
| 4870 |
}; |
| 4871 |
} |
| 4872 |
|
| 4873 |
function textTween(value) { |
| 4874 |
var t0, i0; |
| 4875 |
function tween() { |
| 4876 |
var i = value.apply(this, arguments); |
| 4877 |
if (i !== i0) t0 = (i0 = i) && textInterpolate(i); |
| 4878 |
return t0; |
| 4879 |
} |
| 4880 |
tween._value = value; |
| 4881 |
return tween; |
| 4882 |
} |
| 4883 |
|
| 4884 |
function transition_textTween(value) { |
| 4885 |
var key = "text"; |
| 4886 |
if (arguments.length < 1) return (key = this.tween(key)) && key._value; |
| 4887 |
if (value == null) return this.tween(key, null); |
| 4888 |
if (typeof value !== "function") throw new Error; |
| 4889 |
return this.tween(key, textTween(value)); |
| 4890 |
} |
| 4891 |
|
| 4892 |
function transition_transition() { |
| 4893 |
var name = this._name, |
| 4894 |
id0 = this._id, |
| 4895 |
id1 = newId(); |
| 4896 |
|
| 4897 |
for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) { |
| 4898 |
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { |
| 4899 |
if (node = group[i]) { |
| 4900 |
var inherit = get(node, id0); |
| 4901 |
schedule(node, name, id1, i, group, { |
| 4902 |
time: inherit.time + inherit.delay + inherit.duration, |
| 4903 |
delay: 0, |
| 4904 |
duration: inherit.duration, |
| 4905 |
ease: inherit.ease |
| 4906 |
}); |
| 4907 |
} |
| 4908 |
} |
| 4909 |
} |
| 4910 |
|
| 4911 |
return new Transition(groups, this._parents, name, id1); |
| 4912 |
} |
| 4913 |
|
| 4914 |
function transition_end() { |
| 4915 |
var on0, on1, that = this, id = that._id, size = that.size(); |
| 4916 |
return new Promise(function(resolve, reject) { |
| 4917 |
var cancel = {value: reject}, |
| 4918 |
end = {value: function() { if (--size === 0) resolve(); }}; |
| 4919 |
|
| 4920 |
that.each(function() { |
| 4921 |
var schedule = set(this, id), |
| 4922 |
on = schedule.on; |
| 4923 |
|
| 4924 |
// If this node shared a dispatch with the previous node, |
| 4925 |
// just assign the updated shared dispatch and we’re done! |
| 4926 |
// Otherwise, copy-on-write. |
| 4927 |
if (on !== on0) { |
| 4928 |
on1 = (on0 = on).copy(); |
| 4929 |
on1._.cancel.push(cancel); |
| 4930 |
on1._.interrupt.push(cancel); |
| 4931 |
on1._.end.push(end); |
| 4932 |
} |
| 4933 |
|
| 4934 |
schedule.on = on1; |
| 4935 |
}); |
| 4936 |
|
| 4937 |
// The selection was empty, resolve end immediately |
| 4938 |
if (size === 0) resolve(); |
| 4939 |
}); |
| 4940 |
} |
| 4941 |
|
| 4942 |
var id = 0; |
| 4943 |
|
| 4944 |
function Transition(groups, parents, name, id) { |
| 4945 |
this._groups = groups; |
| 4946 |
this._parents = parents; |
| 4947 |
this._name = name; |
| 4948 |
this._id = id; |
| 4949 |
} |
| 4950 |
|
| 4951 |
function transition(name) { |
| 4952 |
return selection().transition(name); |
| 4953 |
} |
| 4954 |
|
| 4955 |
function newId() { |
| 4956 |
return ++id; |
| 4957 |
} |
| 4958 |
|
| 4959 |
var selection_prototype = selection.prototype; |
| 4960 |
|
| 4961 |
Transition.prototype = transition.prototype = { |
| 4962 |
constructor: Transition, |
| 4963 |
select: transition_select, |
| 4964 |
selectAll: transition_selectAll, |
| 4965 |
selectChild: selection_prototype.selectChild, |
| 4966 |
selectChildren: selection_prototype.selectChildren, |
| 4967 |
filter: transition_filter, |
| 4968 |
merge: transition_merge, |
| 4969 |
selection: transition_selection, |
| 4970 |
transition: transition_transition, |
| 4971 |
call: selection_prototype.call, |
| 4972 |
nodes: selection_prototype.nodes, |
| 4973 |
node: selection_prototype.node, |
| 4974 |
size: selection_prototype.size, |
| 4975 |
empty: selection_prototype.empty, |
| 4976 |
each: selection_prototype.each, |
| 4977 |
on: transition_on, |
| 4978 |
attr: transition_attr, |
| 4979 |
attrTween: transition_attrTween, |
| 4980 |
style: transition_style, |
| 4981 |
styleTween: transition_styleTween, |
| 4982 |
text: transition_text, |
| 4983 |
textTween: transition_textTween, |
| 4984 |
remove: transition_remove, |
| 4985 |
tween: transition_tween, |
| 4986 |
delay: transition_delay, |
| 4987 |
duration: transition_duration, |
| 4988 |
ease: transition_ease, |
| 4989 |
easeVarying: transition_easeVarying, |
| 4990 |
end: transition_end, |
| 4991 |
[Symbol.iterator]: selection_prototype[Symbol.iterator] |
| 4992 |
}; |
| 4993 |
|
| 4994 |
const linear$1 = t => +t; |
| 4995 |
|
| 4996 |
function quadIn(t) { |
| 4997 |
return t * t; |
| 4998 |
} |
| 4999 |
|
| 5000 |
function quadOut(t) { |
| 5001 |
return t * (2 - t); |
| 5002 |
} |
| 5003 |
|
| 5004 |
function quadInOut(t) { |
| 5005 |
return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2; |
| 5006 |
} |
| 5007 |
|
| 5008 |
function cubicIn(t) { |
| 5009 |
return t * t * t; |
| 5010 |
} |
| 5011 |
|
| 5012 |
function cubicOut(t) { |
| 5013 |
return --t * t * t + 1; |
| 5014 |
} |
| 5015 |
|
| 5016 |
function cubicInOut(t) { |
| 5017 |
return ((t *= 2) <= 1 ? t * t * t : (t -= 2) * t * t + 2) / 2; |
| 5018 |
} |
| 5019 |
|
| 5020 |
var exponent$1 = 3; |
| 5021 |
|
| 5022 |
var polyIn = (function custom(e) { |
| 5023 |
e = +e; |
| 5024 |
|
| 5025 |
function polyIn(t) { |
| 5026 |
return Math.pow(t, e); |
| 5027 |
} |
| 5028 |
|
| 5029 |
polyIn.exponent = custom; |
| 5030 |
|
| 5031 |
return polyIn; |
| 5032 |
})(exponent$1); |
| 5033 |
|
| 5034 |
var polyOut = (function custom(e) { |
| 5035 |
e = +e; |
| 5036 |
|
| 5037 |
function polyOut(t) { |
| 5038 |
return 1 - Math.pow(1 - t, e); |
| 5039 |
} |
| 5040 |
|
| 5041 |
polyOut.exponent = custom; |
| 5042 |
|
| 5043 |
return polyOut; |
| 5044 |
})(exponent$1); |
| 5045 |
|
| 5046 |
var polyInOut = (function custom(e) { |
| 5047 |
e = +e; |
| 5048 |
|
| 5049 |
function polyInOut(t) { |
| 5050 |
return ((t *= 2) <= 1 ? Math.pow(t, e) : 2 - Math.pow(2 - t, e)) / 2; |
| 5051 |
} |
| 5052 |
|
| 5053 |
polyInOut.exponent = custom; |
| 5054 |
|
| 5055 |
return polyInOut; |
| 5056 |
})(exponent$1); |
| 5057 |
|
| 5058 |
var pi$4 = Math.PI, |
| 5059 |
halfPi$3 = pi$4 / 2; |
| 5060 |
|
| 5061 |
function sinIn(t) { |
| 5062 |
return (+t === 1) ? 1 : 1 - Math.cos(t * halfPi$3); |
| 5063 |
} |
| 5064 |
|
| 5065 |
function sinOut(t) { |
| 5066 |
return Math.sin(t * halfPi$3); |
| 5067 |
} |
| 5068 |
|
| 5069 |
function sinInOut(t) { |
| 5070 |
return (1 - Math.cos(pi$4 * t)) / 2; |
| 5071 |
} |
| 5072 |
|
| 5073 |
// tpmt is two power minus ten times t scaled to [0,1] |
| 5074 |
function tpmt(x) { |
| 5075 |
return (Math.pow(2, -10 * x) - 0.0009765625) * 1.0009775171065494; |
| 5076 |
} |
| 5077 |
|
| 5078 |
function expIn(t) { |
| 5079 |
return tpmt(1 - +t); |
| 5080 |
} |
| 5081 |
|
| 5082 |
function expOut(t) { |
| 5083 |
return 1 - tpmt(t); |
| 5084 |
} |
| 5085 |
|
| 5086 |
function expInOut(t) { |
| 5087 |
return ((t *= 2) <= 1 ? tpmt(1 - t) : 2 - tpmt(t - 1)) / 2; |
| 5088 |
} |
| 5089 |
|
| 5090 |
function circleIn(t) { |
| 5091 |
return 1 - Math.sqrt(1 - t * t); |
| 5092 |
} |
| 5093 |
|
| 5094 |
function circleOut(t) { |
| 5095 |
return Math.sqrt(1 - --t * t); |
| 5096 |
} |
| 5097 |
|
| 5098 |
function circleInOut(t) { |
| 5099 |
return ((t *= 2) <= 1 ? 1 - Math.sqrt(1 - t * t) : Math.sqrt(1 - (t -= 2) * t) + 1) / 2; |
| 5100 |
} |
| 5101 |
|
| 5102 |
var b1 = 4 / 11, |
| 5103 |
b2 = 6 / 11, |
| 5104 |
b3 = 8 / 11, |
| 5105 |
b4 = 3 / 4, |
| 5106 |
b5 = 9 / 11, |
| 5107 |
b6 = 10 / 11, |
| 5108 |
b7 = 15 / 16, |
| 5109 |
b8 = 21 / 22, |
| 5110 |
b9 = 63 / 64, |
| 5111 |
b0 = 1 / b1 / b1; |
| 5112 |
|
| 5113 |
function bounceIn(t) { |
| 5114 |
return 1 - bounceOut(1 - t); |
| 5115 |
} |
| 5116 |
|
| 5117 |
function bounceOut(t) { |
| 5118 |
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; |
| 5119 |
} |
| 5120 |
|
| 5121 |
function bounceInOut(t) { |
| 5122 |
return ((t *= 2) <= 1 ? 1 - bounceOut(1 - t) : bounceOut(t - 1) + 1) / 2; |
| 5123 |
} |
| 5124 |
|
| 5125 |
var overshoot = 1.70158; |
| 5126 |
|
| 5127 |
var backIn = (function custom(s) { |
| 5128 |
s = +s; |
| 5129 |
|
| 5130 |
function backIn(t) { |
| 5131 |
return (t = +t) * t * (s * (t - 1) + t); |
| 5132 |
} |
| 5133 |
|
| 5134 |
backIn.overshoot = custom; |
| 5135 |
|
| 5136 |
return backIn; |
| 5137 |
})(overshoot); |
| 5138 |
|
| 5139 |
var backOut = (function custom(s) { |
| 5140 |
s = +s; |
| 5141 |
|
| 5142 |
function backOut(t) { |
| 5143 |
return --t * t * ((t + 1) * s + t) + 1; |
| 5144 |
} |
| 5145 |
|
| 5146 |
backOut.overshoot = custom; |
| 5147 |
|
| 5148 |
return backOut; |
| 5149 |
})(overshoot); |
| 5150 |
|
| 5151 |
var backInOut = (function custom(s) { |
| 5152 |
s = +s; |
| 5153 |
|
| 5154 |
function backInOut(t) { |
| 5155 |
return ((t *= 2) < 1 ? t * t * ((s + 1) * t - s) : (t -= 2) * t * ((s + 1) * t + s) + 2) / 2; |
| 5156 |
} |
| 5157 |
|
| 5158 |
backInOut.overshoot = custom; |
| 5159 |
|
| 5160 |
return backInOut; |
| 5161 |
})(overshoot); |
| 5162 |
|
| 5163 |
var tau$5 = 2 * Math.PI, |
| 5164 |
amplitude = 1, |
| 5165 |
period = 0.3; |
| 5166 |
|
| 5167 |
var elasticIn = (function custom(a, p) { |
| 5168 |
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5); |
| 5169 |
|
| 5170 |
function elasticIn(t) { |
| 5171 |
return a * tpmt(-(--t)) * Math.sin((s - t) / p); |
| 5172 |
} |
| 5173 |
|
| 5174 |
elasticIn.amplitude = function(a) { return custom(a, p * tau$5); }; |
| 5175 |
elasticIn.period = function(p) { return custom(a, p); }; |
| 5176 |
|
| 5177 |
return elasticIn; |
| 5178 |
})(amplitude, period); |
| 5179 |
|
| 5180 |
var elasticOut = (function custom(a, p) { |
| 5181 |
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5); |
| 5182 |
|
| 5183 |
function elasticOut(t) { |
| 5184 |
return 1 - a * tpmt(t = +t) * Math.sin((t + s) / p); |
| 5185 |
} |
| 5186 |
|
| 5187 |
elasticOut.amplitude = function(a) { return custom(a, p * tau$5); }; |
| 5188 |
elasticOut.period = function(p) { return custom(a, p); }; |
| 5189 |
|
| 5190 |
return elasticOut; |
| 5191 |
})(amplitude, period); |
| 5192 |
|
| 5193 |
var elasticInOut = (function custom(a, p) { |
| 5194 |
var s = Math.asin(1 / (a = Math.max(1, a))) * (p /= tau$5); |
| 5195 |
|
| 5196 |
function elasticInOut(t) { |
| 5197 |
return ((t = t * 2 - 1) < 0 |
| 5198 |
? a * tpmt(-t) * Math.sin((s - t) / p) |
| 5199 |
: 2 - a * tpmt(t) * Math.sin((s + t) / p)) / 2; |
| 5200 |
} |
| 5201 |
|
| 5202 |
elasticInOut.amplitude = function(a) { return custom(a, p * tau$5); }; |
| 5203 |
elasticInOut.period = function(p) { return custom(a, p); }; |
| 5204 |
|
| 5205 |
return elasticInOut; |
| 5206 |
})(amplitude, period); |
| 5207 |
|
| 5208 |
var defaultTiming = { |
| 5209 |
time: null, // Set on use. |
| 5210 |
delay: 0, |
| 5211 |
duration: 250, |
| 5212 |
ease: cubicInOut |
| 5213 |
}; |
| 5214 |
|
| 5215 |
function inherit(node, id) { |
| 5216 |
var timing; |
| 5217 |
while (!(timing = node.__transition) || !(timing = timing[id])) { |
| 5218 |
if (!(node = node.parentNode)) { |
| 5219 |
throw new Error(`transition ${id} not found`); |
| 5220 |
} |
| 5221 |
} |
| 5222 |
return timing; |
| 5223 |
} |
| 5224 |
|
| 5225 |
function selection_transition(name) { |
| 5226 |
var id, |
| 5227 |
timing; |
| 5228 |
|
| 5229 |
if (name instanceof Transition) { |
| 5230 |
id = name._id, name = name._name; |
| 5231 |
} else { |
| 5232 |
id = newId(), (timing = defaultTiming).time = now(), name = name == null ? null : name + ""; |
| 5233 |
} |
| 5234 |
|
| 5235 |
for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) { |
| 5236 |
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) { |
| 5237 |
if (node = group[i]) { |
| 5238 |
schedule(node, name, id, i, group, timing || inherit(node, id)); |
| 5239 |
} |
| 5240 |
} |
| 5241 |
} |
| 5242 |
|
| 5243 |
return new Transition(groups, this._parents, name, id); |
| 5244 |
} |
| 5245 |
|
| 5246 |
selection.prototype.interrupt = selection_interrupt; |
| 5247 |
selection.prototype.transition = selection_transition; |
| 5248 |
|
| 5249 |
var root = [null]; |
| 5250 |
|
| 5251 |
function active(node, name) { |
| 5252 |
var schedules = node.__transition, |
| 5253 |
schedule, |
| 5254 |
i; |
| 5255 |
|
| 5256 |
if (schedules) { |
| 5257 |
name = name == null ? null : name + ""; |
| 5258 |
for (i in schedules) { |
| 5259 |
if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) { |
| 5260 |
return new Transition([[node]], root, name, +i); |
| 5261 |
} |
| 5262 |
} |
| 5263 |
} |
| 5264 |
|
| 5265 |
return null; |
| 5266 |
} |
| 5267 |
|
| 5268 |
var constant$7 = x => () => x; |
| 5269 |
|
| 5270 |
function BrushEvent(type, { |
| 5271 |
sourceEvent, |
| 5272 |
target, |
| 5273 |
selection, |
| 5274 |
mode, |
| 5275 |
dispatch |
| 5276 |
}) { |
| 5277 |
Object.defineProperties(this, { |
| 5278 |
type: {value: type, enumerable: true, configurable: true}, |
| 5279 |
sourceEvent: {value: sourceEvent, enumerable: true, configurable: true}, |
| 5280 |
target: {value: target, enumerable: true, configurable: true}, |
| 5281 |
selection: {value: selection, enumerable: true, configurable: true}, |
| 5282 |
mode: {value: mode, enumerable: true, configurable: true}, |
| 5283 |
_: {value: dispatch} |
| 5284 |
}); |
| 5285 |
} |
| 5286 |
|
| 5287 |
function nopropagation$1(event) { |
| 5288 |
event.stopImmediatePropagation(); |
| 5289 |
} |
| 5290 |
|
| 5291 |
function noevent$1(event) { |
| 5292 |
event.preventDefault(); |
| 5293 |
event.stopImmediatePropagation(); |
| 5294 |
} |
| 5295 |
|
| 5296 |
var MODE_DRAG = {name: "drag"}, |
| 5297 |
MODE_SPACE = {name: "space"}, |
| 5298 |
MODE_HANDLE = {name: "handle"}, |
| 5299 |
MODE_CENTER = {name: "center"}; |
| 5300 |
|
| 5301 |
const {abs: abs$3, max: max$2, min: min$1} = Math; |
| 5302 |
|
| 5303 |
function number1(e) { |
| 5304 |
return [+e[0], +e[1]]; |
| 5305 |
} |
| 5306 |
|
| 5307 |
function number2(e) { |
| 5308 |
return [number1(e[0]), number1(e[1])]; |
| 5309 |
} |
| 5310 |
|
| 5311 |
var X = { |
| 5312 |
name: "x", |
| 5313 |
handles: ["w", "e"].map(type), |
| 5314 |
input: function(x, e) { return x == null ? null : [[+x[0], e[0][1]], [+x[1], e[1][1]]]; }, |
| 5315 |
output: function(xy) { return xy && [xy[0][0], xy[1][0]]; } |
| 5316 |
}; |
| 5317 |
|
| 5318 |
var Y = { |
| 5319 |
name: "y", |
| 5320 |
handles: ["n", "s"].map(type), |
| 5321 |
input: function(y, e) { return y == null ? null : [[e[0][0], +y[0]], [e[1][0], +y[1]]]; }, |
| 5322 |
output: function(xy) { return xy && [xy[0][1], xy[1][1]]; } |
| 5323 |
}; |
| 5324 |
|
| 5325 |
var XY = { |
| 5326 |
name: "xy", |
| 5327 |
handles: ["n", "w", "e", "s", "nw", "ne", "sw", "se"].map(type), |
| 5328 |
input: function(xy) { return xy == null ? null : number2(xy); }, |
| 5329 |
output: function(xy) { return xy; } |
| 5330 |
}; |
| 5331 |
|
| 5332 |
var cursors = { |
| 5333 |
overlay: "crosshair", |
| 5334 |
selection: "move", |
| 5335 |
n: "ns-resize", |
| 5336 |
e: "ew-resize", |
| 5337 |
s: "ns-resize", |
| 5338 |
w: "ew-resize", |
| 5339 |
nw: "nwse-resize", |
| 5340 |
ne: "nesw-resize", |
| 5341 |
se: "nwse-resize", |
| 5342 |
sw: "nesw-resize" |
| 5343 |
}; |
| 5344 |
|
| 5345 |
var flipX = { |
| 5346 |
e: "w", |
| 5347 |
w: "e", |
| 5348 |
nw: "ne", |
| 5349 |
ne: "nw", |
| 5350 |
se: "sw", |
| 5351 |
sw: "se" |
| 5352 |
}; |
| 5353 |
|
| 5354 |
var flipY = { |
| 5355 |
n: "s", |
| 5356 |
s: "n", |
| 5357 |
nw: "sw", |
| 5358 |
ne: "se", |
| 5359 |
se: "ne", |
| 5360 |
sw: "nw" |
| 5361 |
}; |
| 5362 |
|
| 5363 |
var signsX = { |
| 5364 |
overlay: +1, |
| 5365 |
selection: +1, |
| 5366 |
n: null, |
| 5367 |
e: +1, |
| 5368 |
s: null, |
| 5369 |
w: -1, |
| 5370 |
nw: -1, |
| 5371 |
ne: +1, |
| 5372 |
se: +1, |
| 5373 |
sw: -1 |
| 5374 |
}; |
| 5375 |
|
| 5376 |
var signsY = { |
| 5377 |
overlay: +1, |
| 5378 |
selection: +1, |
| 5379 |
n: -1, |
| 5380 |
e: null, |
| 5381 |
s: +1, |
| 5382 |
w: null, |
| 5383 |
nw: -1, |
| 5384 |
ne: -1, |
| 5385 |
se: +1, |
| 5386 |
sw: +1 |
| 5387 |
}; |
| 5388 |
|
| 5389 |
function type(t) { |
| 5390 |
return {type: t}; |
| 5391 |
} |
| 5392 |
|
| 5393 |
// Ignore right-click, since that should open the context menu. |
| 5394 |
function defaultFilter$1(event) { |
| 5395 |
return !event.ctrlKey && !event.button; |
| 5396 |
} |
| 5397 |
|
| 5398 |
function defaultExtent$1() { |
| 5399 |
var svg = this.ownerSVGElement || this; |
| 5400 |
if (svg.hasAttribute("viewBox")) { |
| 5401 |
svg = svg.viewBox.baseVal; |
| 5402 |
return [[svg.x, svg.y], [svg.x + svg.width, svg.y + svg.height]]; |
| 5403 |
} |
| 5404 |
return [[0, 0], [svg.width.baseVal.value, svg.height.baseVal.value]]; |
| 5405 |
} |
| 5406 |
|
| 5407 |
function defaultTouchable$1() { |
| 5408 |
return navigator.maxTouchPoints || ("ontouchstart" in this); |
| 5409 |
} |
| 5410 |
|
| 5411 |
// Like d3.local, but with the name “__brush” rather than auto-generated. |
| 5412 |
function local(node) { |
| 5413 |
while (!node.__brush) if (!(node = node.parentNode)) return; |
| 5414 |
return node.__brush; |
| 5415 |
} |
| 5416 |
|
| 5417 |
function empty(extent) { |
| 5418 |
return extent[0][0] === extent[1][0] |
| 5419 |
|| extent[0][1] === extent[1][1]; |
| 5420 |
} |
| 5421 |
|
| 5422 |
function brushSelection(node) { |
| 5423 |
var state = node.__brush; |
| 5424 |
return state ? state.dim.output(state.selection) : null; |
| 5425 |
} |
| 5426 |
|
| 5427 |
function brushX() { |
| 5428 |
return brush$1(X); |
| 5429 |
} |
| 5430 |
|
| 5431 |
function brushY() { |
| 5432 |
return brush$1(Y); |
| 5433 |
} |
| 5434 |
|
| 5435 |
function brush() { |
| 5436 |
return brush$1(XY); |
| 5437 |
} |
| 5438 |
|
| 5439 |
function brush$1(dim) { |
| 5440 |
var extent = defaultExtent$1, |
| 5441 |
filter = defaultFilter$1, |
| 5442 |
touchable = defaultTouchable$1, |
| 5443 |
keys = true, |
| 5444 |
listeners = dispatch("start", "brush", "end"), |
| 5445 |
handleSize = 6, |
| 5446 |
touchending; |
| 5447 |
|
| 5448 |
function brush(group) { |
| 5449 |
var overlay = group |
| 5450 |
.property("__brush", initialize) |
| 5451 |
.selectAll(".overlay") |
| 5452 |
.data([type("overlay")]); |
| 5453 |
|
| 5454 |
overlay.enter().append("rect") |
| 5455 |
.attr("class", "overlay") |
| 5456 |
.attr("pointer-events", "all") |
| 5457 |
.attr("cursor", cursors.overlay) |
| 5458 |
.merge(overlay) |
| 5459 |
.each(function() { |
| 5460 |
var extent = local(this).extent; |
| 5461 |
select(this) |
| 5462 |
.attr("x", extent[0][0]) |
| 5463 |
.attr("y", extent[0][1]) |
| 5464 |
.attr("width", extent[1][0] - extent[0][0]) |
| 5465 |
.attr("height", extent[1][1] - extent[0][1]); |
| 5466 |
}); |
| 5467 |
|
| 5468 |
group.selectAll(".selection") |
| 5469 |
.data([type("selection")]) |
| 5470 |
.enter().append("rect") |
| 5471 |
.attr("class", "selection") |
| 5472 |
.attr("cursor", cursors.selection) |
| 5473 |
.attr("fill", "#777") |
| 5474 |
.attr("fill-opacity", 0.3) |
| 5475 |
.attr("stroke", "#fff") |
| 5476 |
.attr("shape-rendering", "crispEdges"); |
| 5477 |
|
| 5478 |
var handle = group.selectAll(".handle") |
| 5479 |
.data(dim.handles, function(d) { return d.type; }); |
| 5480 |
|
| 5481 |
handle.exit().remove(); |
| 5482 |
|
| 5483 |
handle.enter().append("rect") |
| 5484 |
.attr("class", function(d) { return "handle handle--" + d.type; }) |
| 5485 |
.attr("cursor", function(d) { return cursors[d.type]; }); |
| 5486 |
|
| 5487 |
group |
| 5488 |
.each(redraw) |
| 5489 |
.attr("fill", "none") |
| 5490 |
.attr("pointer-events", "all") |
| 5491 |
.on("mousedown.brush", started) |
| 5492 |
.filter(touchable) |
| 5493 |
.on("touchstart.brush", started) |
| 5494 |
.on("touchmove.brush", touchmoved) |
| 5495 |
.on("touchend.brush touchcancel.brush", touchended) |
| 5496 |
.style("touch-action", "none") |
| 5497 |
.style("-webkit-tap-highlight-color", "rgba(0,0,0,0)"); |
| 5498 |
} |
| 5499 |
|
| 5500 |
brush.move = function(group, selection, event) { |
| 5501 |
if (group.tween) { |
| 5502 |
group |
| 5503 |
.on("start.brush", function(event) { emitter(this, arguments).beforestart().start(event); }) |
| 5504 |
.on("interrupt.brush end.brush", function(event) { emitter(this, arguments).end(event); }) |
| 5505 |
.tween("brush", function() { |
| 5506 |
var that = this, |
| 5507 |
state = that.__brush, |
| 5508 |
emit = emitter(that, arguments), |
| 5509 |
selection0 = state.selection, |
| 5510 |
selection1 = dim.input(typeof selection === "function" ? selection.apply(this, arguments) : selection, state.extent), |
| 5511 |
i = interpolate$2(selection0, selection1); |
| 5512 |
|
| 5513 |
function tween(t) { |
| 5514 |
state.selection = t === 1 && selection1 === null ? null : i(t); |
| 5515 |
redraw.call(that); |
| 5516 |
emit.brush(); |
| 5517 |
} |
| 5518 |
|
| 5519 |
return selection0 !== null && selection1 !== null ? tween : tween(1); |
| 5520 |
}); |
| 5521 |
} else { |
| 5522 |
group |
| 5523 |
.each(function() { |
| 5524 |
var that = this, |
| 5525 |
args = arguments, |
| 5526 |
state = that.__brush, |
| 5527 |
selection1 = dim.input(typeof selection === "function" ? selection.apply(that, args) : selection, state.extent), |
| 5528 |
emit = emitter(that, args).beforestart(); |
| 5529 |
|
| 5530 |
interrupt(that); |
| 5531 |
state.selection = selection1 === null ? null : selection1; |
| 5532 |
redraw.call(that); |
| 5533 |
emit.start(event).brush(event).end(event); |
| 5534 |
}); |
| 5535 |
} |
| 5536 |
}; |
| 5537 |
|
| 5538 |
brush.clear = function(group, event) { |
| 5539 |
brush.move(group, null, event); |
| 5540 |
}; |
| 5541 |
|
| 5542 |
function redraw() { |
| 5543 |
var group = select(this), |
| 5544 |
selection = local(this).selection; |
| 5545 |
|
| 5546 |
if (selection) { |
| 5547 |
group.selectAll(".selection") |
| 5548 |
.style("display", null) |
| 5549 |
.attr("x", selection[0][0]) |
| 5550 |
.attr("y", selection[0][1]) |
| 5551 |
.attr("width", selection[1][0] - selection[0][0]) |
| 5552 |
.attr("height", selection[1][1] - selection[0][1]); |
| 5553 |
|
| 5554 |
group.selectAll(".handle") |
| 5555 |
.style("display", null) |
| 5556 |
.attr("x", function(d) { return d.type[d.type.length - 1] === "e" ? selection[1][0] - handleSize / 2 : selection[0][0] - handleSize / 2; }) |
| 5557 |
.attr("y", function(d) { return d.type[0] === "s" ? selection[1][1] - handleSize / 2 : selection[0][1] - handleSize / 2; }) |
| 5558 |
.attr("width", function(d) { return d.type === "n" || d.type === "s" ? selection[1][0] - selection[0][0] + handleSize : handleSize; }) |
| 5559 |
.attr("height", function(d) { return d.type === "e" || d.type === "w" ? selection[1][1] - selection[0][1] + handleSize : handleSize; }); |
| 5560 |
} |
| 5561 |
|
| 5562 |
else { |
| 5563 |
group.selectAll(".selection,.handle") |
| 5564 |
.style("display", "none") |
| 5565 |
.attr("x", null) |
| 5566 |
.attr("y", null) |
| 5567 |
.attr("width", null) |
| 5568 |
.attr("height", null); |
| 5569 |
} |
| 5570 |
} |
| 5571 |
|
| 5572 |
function emitter(that, args, clean) { |
| 5573 |
var emit = that.__brush.emitter; |
| 5574 |
return emit && (!clean || !emit.clean) ? emit : new Emitter(that, args, clean); |
| 5575 |
} |
| 5576 |
|
| 5577 |
function Emitter(that, args, clean) { |
| 5578 |
this.that = that; |
| 5579 |
this.args = args; |
| 5580 |
this.state = that.__brush; |
| 5581 |
this.active = 0; |
| 5582 |
this.clean = clean; |
| 5583 |
} |
| 5584 |
|
| 5585 |
Emitter.prototype = { |
| 5586 |
beforestart: function() { |
| 5587 |
if (++this.active === 1) this.state.emitter = this, this.starting = true; |
| 5588 |
return this; |
| 5589 |
}, |
| 5590 |
start: function(event, mode) { |
| 5591 |
if (this.starting) this.starting = false, this.emit("start", event, mode); |
| 5592 |
else this.emit("brush", event); |
| 5593 |
return this; |
| 5594 |
}, |
| 5595 |
brush: function(event, mode) { |
| 5596 |
this.emit("brush", event, mode); |
| 5597 |
return this; |
| 5598 |
}, |
| 5599 |
end: function(event, mode) { |
| 5600 |
if (--this.active === 0) delete this.state.emitter, this.emit("end", event, mode); |
| 5601 |
return this; |
| 5602 |
}, |
| 5603 |
emit: function(type, event, mode) { |
| 5604 |
var d = select(this.that).datum(); |
| 5605 |
listeners.call( |
| 5606 |
type, |
| 5607 |
this.that, |
| 5608 |
new BrushEvent(type, { |
| 5609 |
sourceEvent: event, |
| 5610 |
target: brush, |
| 5611 |
selection: dim.output(this.state.selection), |
| 5612 |
mode, |
| 5613 |
dispatch: listeners |
| 5614 |
}), |
| 5615 |
d |
| 5616 |
); |
| 5617 |
} |
| 5618 |
}; |
| 5619 |
|
| 5620 |
function started(event) { |
| 5621 |
if (touchending && !event.touches) return; |
| 5622 |
if (!filter.apply(this, arguments)) return; |
| 5623 |
|
| 5624 |
var that = this, |
| 5625 |
type = event.target.__data__.type, |
| 5626 |
mode = (keys && event.metaKey ? type = "overlay" : type) === "selection" ? MODE_DRAG : (keys && event.altKey ? MODE_CENTER : MODE_HANDLE), |
| 5627 |
signX = dim === Y ? null : signsX[type], |
| 5628 |
signY = dim === X ? null : signsY[type], |
| 5629 |
state = local(that), |
| 5630 |
extent = state.extent, |
| 5631 |
selection = state.selection, |
| 5632 |
W = extent[0][0], w0, w1, |
| 5633 |
N = extent[0][1], n0, n1, |
| 5634 |
E = extent[1][0], e0, e1, |
| 5635 |
S = extent[1][1], s0, s1, |
| 5636 |
dx = 0, |
| 5637 |
dy = 0, |
| 5638 |
moving, |
| 5639 |
shifting = signX && signY && keys && event.shiftKey, |
| 5640 |
lockX, |
| 5641 |
lockY, |
| 5642 |
points = Array.from(event.touches || [event], t => { |
| 5643 |
const i = t.identifier; |
| 5644 |
t = pointer(t, that); |
| 5645 |
t.point0 = t.slice(); |
| 5646 |
t.identifier = i; |
| 5647 |
return t; |
| 5648 |
}); |
| 5649 |
|
| 5650 |
interrupt(that); |
| 5651 |
var emit = emitter(that, arguments, true).beforestart(); |
| 5652 |
|
| 5653 |
if (type === "overlay") { |
| 5654 |
if (selection) moving = true; |
| 5655 |
const pts = [points[0], points[1] || points[0]]; |
| 5656 |
state.selection = selection = [[ |
| 5657 |
w0 = dim === Y ? W : min$1(pts[0][0], pts[1][0]), |
| 5658 |
n0 = dim === X ? N : min$1(pts[0][1], pts[1][1]) |
| 5659 |
], [ |
| 5660 |
e0 = dim === Y ? E : max$2(pts[0][0], pts[1][0]), |
| 5661 |
s0 = dim === X ? S : max$2(pts[0][1], pts[1][1]) |
| 5662 |
]]; |
| 5663 |
if (points.length > 1) move(event); |
| 5664 |
} else { |
| 5665 |
w0 = selection[0][0]; |
| 5666 |
n0 = selection[0][1]; |
| 5667 |
e0 = selection[1][0]; |
| 5668 |
s0 = selection[1][1]; |
| 5669 |
} |
| 5670 |
|
| 5671 |
w1 = w0; |
| 5672 |
n1 = n0; |
| 5673 |
e1 = e0; |
| 5674 |
s1 = s0; |
| 5675 |
|
| 5676 |
var group = select(that) |
| 5677 |
.attr("pointer-events", "none"); |
| 5678 |
|
| 5679 |
var overlay = group.selectAll(".overlay") |
| 5680 |
.attr("cursor", cursors[type]); |
| 5681 |
|
| 5682 |
if (event.touches) { |
| 5683 |
emit.moved = moved; |
| 5684 |
emit.ended = ended; |
| 5685 |
} else { |
| 5686 |
var view = select(event.view) |
| 5687 |
.on("mousemove.brush", moved, true) |
| 5688 |
.on("mouseup.brush", ended, true); |
| 5689 |
if (keys) view |
| 5690 |
.on("keydown.brush", keydowned, true) |
| 5691 |
.on("keyup.brush", keyupped, true); |
| 5692 |
|
| 5693 |
dragDisable(event.view); |
| 5694 |
} |
| 5695 |
|
| 5696 |
redraw.call(that); |
| 5697 |
emit.start(event, mode.name); |
| 5698 |
|
| 5699 |
function moved(event) { |
| 5700 |
for (const p of event.changedTouches || [event]) { |
| 5701 |
for (const d of points) |
| 5702 |
if (d.identifier === p.identifier) d.cur = pointer(p, that); |
| 5703 |
} |
| 5704 |
if (shifting && !lockX && !lockY && points.length === 1) { |
| 5705 |
const point = points[0]; |
| 5706 |
if (abs$3(point.cur[0] - point[0]) > abs$3(point.cur[1] - point[1])) |
| 5707 |
lockY = true; |
| 5708 |
else |
| 5709 |
lockX = true; |
| 5710 |
} |
| 5711 |
for (const point of points) |
| 5712 |
if (point.cur) point[0] = point.cur[0], point[1] = point.cur[1]; |
| 5713 |
moving = true; |
| 5714 |
noevent$1(event); |
| 5715 |
move(event); |
| 5716 |
} |
| 5717 |
|
| 5718 |
function move(event) { |
| 5719 |
const point = points[0], point0 = point.point0; |
| 5720 |
var t; |
| 5721 |
|
| 5722 |
dx = point[0] - point0[0]; |
| 5723 |
dy = point[1] - point0[1]; |
| 5724 |
|
| 5725 |
switch (mode) { |
| 5726 |
case MODE_SPACE: |
| 5727 |
case MODE_DRAG: { |
| 5728 |
if (signX) dx = max$2(W - w0, min$1(E - e0, dx)), w1 = w0 + dx, e1 = e0 + dx; |
| 5729 |
if (signY) dy = max$2(N - n0, min$1(S - s0, dy)), n1 = n0 + dy, s1 = s0 + dy; |
| 5730 |
break; |
| 5731 |
} |
| 5732 |
case MODE_HANDLE: { |
| 5733 |
if (points[1]) { |
| 5734 |
if (signX) w1 = max$2(W, min$1(E, points[0][0])), e1 = max$2(W, min$1(E, points[1][0])), signX = 1; |
| 5735 |
if (signY) n1 = max$2(N, min$1(S, points[0][1])), s1 = max$2(N, min$1(S, points[1][1])), signY = 1; |
| 5736 |
} else { |
| 5737 |
if (signX < 0) dx = max$2(W - w0, min$1(E - w0, dx)), w1 = w0 + dx, e1 = e0; |
| 5738 |
else if (signX > 0) dx = max$2(W - e0, min$1(E - e0, dx)), w1 = w0, e1 = e0 + dx; |
| 5739 |
if (signY < 0) dy = max$2(N - n0, min$1(S - n0, dy)), n1 = n0 + dy, s1 = s0; |
| 5740 |
else if (signY > 0) dy = max$2(N - s0, min$1(S - s0, dy)), n1 = n0, s1 = s0 + dy; |
| 5741 |
} |
| 5742 |
break; |
| 5743 |
} |
| 5744 |
case MODE_CENTER: { |
| 5745 |
if (signX) w1 = max$2(W, min$1(E, w0 - dx * signX)), e1 = max$2(W, min$1(E, e0 + dx * signX)); |
| 5746 |
if (signY) n1 = max$2(N, min$1(S, n0 - dy * signY)), s1 = max$2(N, min$1(S, s0 + dy * signY)); |
| 5747 |
break; |
| 5748 |
} |
| 5749 |
} |
| 5750 |
|
| 5751 |
if (e1 < w1) { |
| 5752 |
signX *= -1; |
| 5753 |
t = w0, w0 = e0, e0 = t; |
| 5754 |
t = w1, w1 = e1, e1 = t; |
| 5755 |
if (type in flipX) overlay.attr("cursor", cursors[type = flipX[type]]); |
| 5756 |
} |
| 5757 |
|
| 5758 |
if (s1 < n1) { |
| 5759 |
signY *= -1; |
| 5760 |
t = n0, n0 = s0, s0 = t; |
| 5761 |
t = n1, n1 = s1, s1 = t; |
| 5762 |
if (type in flipY) overlay.attr("cursor", cursors[type = flipY[type]]); |
| 5763 |
} |
| 5764 |
|
| 5765 |
if (state.selection) selection = state.selection; // May be set by brush.move! |
| 5766 |
if (lockX) w1 = selection[0][0], e1 = selection[1][0]; |
| 5767 |
if (lockY) n1 = selection[0][1], s1 = selection[1][1]; |
| 5768 |
|
| 5769 |
if (selection[0][0] !== w1 |
| 5770 |
|| selection[0][1] !== n1 |
| 5771 |
|| selection[1][0] !== e1 |
| 5772 |
|| selection[1][1] !== s1) { |
| 5773 |
state.selection = [[w1, n1], [e1, s1]]; |
| 5774 |
redraw.call(that); |
| 5775 |
emit.brush(event, mode.name); |
| 5776 |
} |
| 5777 |
} |
| 5778 |
|
| 5779 |
function ended(event) { |
| 5780 |
nopropagation$1(event); |
| 5781 |
if (event.touches) { |
| 5782 |
if (event.touches.length) return; |
| 5783 |
if (touchending) clearTimeout(touchending); |
| 5784 |
touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed! |
| 5785 |
} else { |
| 5786 |
yesdrag(event.view, moving); |
| 5787 |
view.on("keydown.brush keyup.brush mousemove.brush mouseup.brush", null); |
| 5788 |
} |
| 5789 |
group.attr("pointer-events", "all"); |
| 5790 |
overlay.attr("cursor", cursors.overlay); |
| 5791 |
if (state.selection) selection = state.selection; // May be set by brush.move (on start)! |
| 5792 |
if (empty(selection)) state.selection = null, redraw.call(that); |
| 5793 |
emit.end(event, mode.name); |
| 5794 |
} |
| 5795 |
|
| 5796 |
function keydowned(event) { |
| 5797 |
switch (event.keyCode) { |
| 5798 |
case 16: { // SHIFT |
| 5799 |
shifting = signX && signY; |
| 5800 |
break; |
| 5801 |
} |
| 5802 |
case 18: { // ALT |
| 5803 |
if (mode === MODE_HANDLE) { |
| 5804 |
if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX; |
| 5805 |
if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY; |
| 5806 |
mode = MODE_CENTER; |
| 5807 |
move(event); |
| 5808 |
} |
| 5809 |
break; |
| 5810 |
} |
| 5811 |
case 32: { // SPACE; takes priority over ALT |
| 5812 |
if (mode === MODE_HANDLE || mode === MODE_CENTER) { |
| 5813 |
if (signX < 0) e0 = e1 - dx; else if (signX > 0) w0 = w1 - dx; |
| 5814 |
if (signY < 0) s0 = s1 - dy; else if (signY > 0) n0 = n1 - dy; |
| 5815 |
mode = MODE_SPACE; |
| 5816 |
overlay.attr("cursor", cursors.selection); |
| 5817 |
move(event); |
| 5818 |
} |
| 5819 |
break; |
| 5820 |
} |
| 5821 |
default: return; |
| 5822 |
} |
| 5823 |
noevent$1(event); |
| 5824 |
} |
| 5825 |
|
| 5826 |
function keyupped(event) { |
| 5827 |
switch (event.keyCode) { |
| 5828 |
case 16: { // SHIFT |
| 5829 |
if (shifting) { |
| 5830 |
lockX = lockY = shifting = false; |
| 5831 |
move(event); |
| 5832 |
} |
| 5833 |
break; |
| 5834 |
} |
| 5835 |
case 18: { // ALT |
| 5836 |
if (mode === MODE_CENTER) { |
| 5837 |
if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1; |
| 5838 |
if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1; |
| 5839 |
mode = MODE_HANDLE; |
| 5840 |
move(event); |
| 5841 |
} |
| 5842 |
break; |
| 5843 |
} |
| 5844 |
case 32: { // SPACE |
| 5845 |
if (mode === MODE_SPACE) { |
| 5846 |
if (event.altKey) { |
| 5847 |
if (signX) e0 = e1 - dx * signX, w0 = w1 + dx * signX; |
| 5848 |
if (signY) s0 = s1 - dy * signY, n0 = n1 + dy * signY; |
| 5849 |
mode = MODE_CENTER; |
| 5850 |
} else { |
| 5851 |
if (signX < 0) e0 = e1; else if (signX > 0) w0 = w1; |
| 5852 |
if (signY < 0) s0 = s1; else if (signY > 0) n0 = n1; |
| 5853 |
mode = MODE_HANDLE; |
| 5854 |
} |
| 5855 |
overlay.attr("cursor", cursors[type]); |
| 5856 |
move(event); |
| 5857 |
} |
| 5858 |
break; |
| 5859 |
} |
| 5860 |
default: return; |
| 5861 |
} |
| 5862 |
noevent$1(event); |
| 5863 |
} |
| 5864 |
} |
| 5865 |
|
| 5866 |
function touchmoved(event) { |
| 5867 |
emitter(this, arguments).moved(event); |
| 5868 |
} |
| 5869 |
|
| 5870 |
function touchended(event) { |
| 5871 |
emitter(this, arguments).ended(event); |
| 5872 |
} |
| 5873 |
|
| 5874 |
function initialize() { |
| 5875 |
var state = this.__brush || {selection: null}; |
| 5876 |
state.extent = number2(extent.apply(this, arguments)); |
| 5877 |
state.dim = dim; |
| 5878 |
return state; |
| 5879 |
} |
| 5880 |
|
| 5881 |
brush.extent = function(_) { |
| 5882 |
return arguments.length ? (extent = typeof _ === "function" ? _ : constant$7(number2(_)), brush) : extent; |
| 5883 |
}; |
| 5884 |
|
| 5885 |
brush.filter = function(_) { |
| 5886 |
return arguments.length ? (filter = typeof _ === "function" ? _ : constant$7(!!_), brush) : filter; |
| 5887 |
}; |
| 5888 |
|
| 5889 |
brush.touchable = function(_) { |
| 5890 |
return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$7(!!_), brush) : touchable; |
| 5891 |
}; |
| 5892 |
|
| 5893 |
brush.handleSize = function(_) { |
| 5894 |
return arguments.length ? (handleSize = +_, brush) : handleSize; |
| 5895 |
}; |
| 5896 |
|
| 5897 |
brush.keyModifiers = function(_) { |
| 5898 |
return arguments.length ? (keys = !!_, brush) : keys; |
| 5899 |
}; |
| 5900 |
|
| 5901 |
brush.on = function() { |
| 5902 |
var value = listeners.on.apply(listeners, arguments); |
| 5903 |
return value === listeners ? brush : value; |
| 5904 |
}; |
| 5905 |
|
| 5906 |
return brush; |
| 5907 |
} |
| 5908 |
|
| 5909 |
var abs$2 = Math.abs; |
| 5910 |
var cos$2 = Math.cos; |
| 5911 |
var sin$2 = Math.sin; |
| 5912 |
var pi$3 = Math.PI; |
| 5913 |
var halfPi$2 = pi$3 / 2; |
| 5914 |
var tau$4 = pi$3 * 2; |
| 5915 |
var max$1 = Math.max; |
| 5916 |
var epsilon$5 = 1e-12; |
| 5917 |
|
| 5918 |
function range$1(i, j) { |
| 5919 |
return Array.from({length: j - i}, (_, k) => i + k); |
| 5920 |
} |
| 5921 |
|
| 5922 |
function compareValue(compare) { |
| 5923 |
return function(a, b) { |
| 5924 |
return compare( |
| 5925 |
a.source.value + a.target.value, |
| 5926 |
b.source.value + b.target.value |
| 5927 |
); |
| 5928 |
}; |
| 5929 |
} |
| 5930 |
|
| 5931 |
function chord() { |
| 5932 |
return chord$1(false, false); |
| 5933 |
} |
| 5934 |
|
| 5935 |
function chordTranspose() { |
| 5936 |
return chord$1(false, true); |
| 5937 |
} |
| 5938 |
|
| 5939 |
function chordDirected() { |
| 5940 |
return chord$1(true, false); |
| 5941 |
} |
| 5942 |
|
| 5943 |
function chord$1(directed, transpose) { |
| 5944 |
var padAngle = 0, |
| 5945 |
sortGroups = null, |
| 5946 |
sortSubgroups = null, |
| 5947 |
sortChords = null; |
| 5948 |
|
| 5949 |
function chord(matrix) { |
| 5950 |
var n = matrix.length, |
| 5951 |
groupSums = new Array(n), |
| 5952 |
groupIndex = range$1(0, n), |
| 5953 |
chords = new Array(n * n), |
| 5954 |
groups = new Array(n), |
| 5955 |
k = 0, dx; |
| 5956 |
|
| 5957 |
matrix = Float64Array.from({length: n * n}, transpose |
| 5958 |
? (_, i) => matrix[i % n][i / n | 0] |
| 5959 |
: (_, i) => matrix[i / n | 0][i % n]); |
| 5960 |
|
| 5961 |
// Compute the scaling factor from value to angle in [0, 2pi]. |
| 5962 |
for (let i = 0; i < n; ++i) { |
| 5963 |
let x = 0; |
| 5964 |
for (let j = 0; j < n; ++j) x += matrix[i * n + j] + directed * matrix[j * n + i]; |
| 5965 |
k += groupSums[i] = x; |
| 5966 |
} |
| 5967 |
k = max$1(0, tau$4 - padAngle * n) / k; |
| 5968 |
dx = k ? padAngle : tau$4 / n; |
| 5969 |
|
| 5970 |
// Compute the angles for each group and constituent chord. |
| 5971 |
{ |
| 5972 |
let x = 0; |
| 5973 |
if (sortGroups) groupIndex.sort((a, b) => sortGroups(groupSums[a], groupSums[b])); |
| 5974 |
for (const i of groupIndex) { |
| 5975 |
const x0 = x; |
| 5976 |
if (directed) { |
| 5977 |
const subgroupIndex = range$1(~n + 1, n).filter(j => j < 0 ? matrix[~j * n + i] : matrix[i * n + j]); |
| 5978 |
if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(a < 0 ? -matrix[~a * n + i] : matrix[i * n + a], b < 0 ? -matrix[~b * n + i] : matrix[i * n + b])); |
| 5979 |
for (const j of subgroupIndex) { |
| 5980 |
if (j < 0) { |
| 5981 |
const chord = chords[~j * n + i] || (chords[~j * n + i] = {source: null, target: null}); |
| 5982 |
chord.target = {index: i, startAngle: x, endAngle: x += matrix[~j * n + i] * k, value: matrix[~j * n + i]}; |
| 5983 |
} else { |
| 5984 |
const chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null}); |
| 5985 |
chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]}; |
| 5986 |
} |
| 5987 |
} |
| 5988 |
groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]}; |
| 5989 |
} else { |
| 5990 |
const subgroupIndex = range$1(0, n).filter(j => matrix[i * n + j] || matrix[j * n + i]); |
| 5991 |
if (sortSubgroups) subgroupIndex.sort((a, b) => sortSubgroups(matrix[i * n + a], matrix[i * n + b])); |
| 5992 |
for (const j of subgroupIndex) { |
| 5993 |
let chord; |
| 5994 |
if (i < j) { |
| 5995 |
chord = chords[i * n + j] || (chords[i * n + j] = {source: null, target: null}); |
| 5996 |
chord.source = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]}; |
| 5997 |
} else { |
| 5998 |
chord = chords[j * n + i] || (chords[j * n + i] = {source: null, target: null}); |
| 5999 |
chord.target = {index: i, startAngle: x, endAngle: x += matrix[i * n + j] * k, value: matrix[i * n + j]}; |
| 6000 |
if (i === j) chord.source = chord.target; |
| 6001 |
} |
| 6002 |
if (chord.source && chord.target && chord.source.value < chord.target.value) { |
| 6003 |
const source = chord.source; |
| 6004 |
chord.source = chord.target; |
| 6005 |
chord.target = source; |
| 6006 |
} |
| 6007 |
} |
| 6008 |
groups[i] = {index: i, startAngle: x0, endAngle: x, value: groupSums[i]}; |
| 6009 |
} |
| 6010 |
x += dx; |
| 6011 |
} |
| 6012 |
} |
| 6013 |
|
| 6014 |
// Remove empty chords. |
| 6015 |
chords = Object.values(chords); |
| 6016 |
chords.groups = groups; |
| 6017 |
return sortChords ? chords.sort(sortChords) : chords; |
| 6018 |
} |
| 6019 |
|
| 6020 |
chord.padAngle = function(_) { |
| 6021 |
return arguments.length ? (padAngle = max$1(0, _), chord) : padAngle; |
| 6022 |
}; |
| 6023 |
|
| 6024 |
chord.sortGroups = function(_) { |
| 6025 |
return arguments.length ? (sortGroups = _, chord) : sortGroups; |
| 6026 |
}; |
| 6027 |
|
| 6028 |
chord.sortSubgroups = function(_) { |
| 6029 |
return arguments.length ? (sortSubgroups = _, chord) : sortSubgroups; |
| 6030 |
}; |
| 6031 |
|
| 6032 |
chord.sortChords = function(_) { |
| 6033 |
return arguments.length ? (_ == null ? sortChords = null : (sortChords = compareValue(_))._ = _, chord) : sortChords && sortChords._; |
| 6034 |
}; |
| 6035 |
|
| 6036 |
return chord; |
| 6037 |
} |
| 6038 |
|
| 6039 |
const pi$2 = Math.PI, |
| 6040 |
tau$3 = 2 * pi$2, |
| 6041 |
epsilon$4 = 1e-6, |
| 6042 |
tauEpsilon = tau$3 - epsilon$4; |
| 6043 |
|
| 6044 |
function append$1(strings) { |
| 6045 |
this._ += strings[0]; |
| 6046 |
for (let i = 1, n = strings.length; i < n; ++i) { |
| 6047 |
this._ += arguments[i] + strings[i]; |
| 6048 |
} |
| 6049 |
} |
| 6050 |
|
| 6051 |
function appendRound$1(digits) { |
| 6052 |
let d = Math.floor(digits); |
| 6053 |
if (!(d >= 0)) throw new Error(`invalid digits: ${digits}`); |
| 6054 |
if (d > 15) return append$1; |
| 6055 |
const k = 10 ** d; |
| 6056 |
return function(strings) { |
| 6057 |
this._ += strings[0]; |
| 6058 |
for (let i = 1, n = strings.length; i < n; ++i) { |
| 6059 |
this._ += Math.round(arguments[i] * k) / k + strings[i]; |
| 6060 |
} |
| 6061 |
}; |
| 6062 |
} |
| 6063 |
|
| 6064 |
let Path$1 = class Path { |
| 6065 |
constructor(digits) { |
| 6066 |
this._x0 = this._y0 = // start of current subpath |
| 6067 |
this._x1 = this._y1 = null; // end of current subpath |
| 6068 |
this._ = ""; |
| 6069 |
this._append = digits == null ? append$1 : appendRound$1(digits); |
| 6070 |
} |
| 6071 |
moveTo(x, y) { |
| 6072 |
this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`; |
| 6073 |
} |
| 6074 |
closePath() { |
| 6075 |
if (this._x1 !== null) { |
| 6076 |
this._x1 = this._x0, this._y1 = this._y0; |
| 6077 |
this._append`Z`; |
| 6078 |
} |
| 6079 |
} |
| 6080 |
lineTo(x, y) { |
| 6081 |
this._append`L${this._x1 = +x},${this._y1 = +y}`; |
| 6082 |
} |
| 6083 |
quadraticCurveTo(x1, y1, x, y) { |
| 6084 |
this._append`Q${+x1},${+y1},${this._x1 = +x},${this._y1 = +y}`; |
| 6085 |
} |
| 6086 |
bezierCurveTo(x1, y1, x2, y2, x, y) { |
| 6087 |
this._append`C${+x1},${+y1},${+x2},${+y2},${this._x1 = +x},${this._y1 = +y}`; |
| 6088 |
} |
| 6089 |
arcTo(x1, y1, x2, y2, r) { |
| 6090 |
x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r; |
| 6091 |
|
| 6092 |
// Is the radius negative? Error. |
| 6093 |
if (r < 0) throw new Error(`negative radius: ${r}`); |
| 6094 |
|
| 6095 |
let x0 = this._x1, |
| 6096 |
y0 = this._y1, |
| 6097 |
x21 = x2 - x1, |
| 6098 |
y21 = y2 - y1, |
| 6099 |
x01 = x0 - x1, |
| 6100 |
y01 = y0 - y1, |
| 6101 |
l01_2 = x01 * x01 + y01 * y01; |
| 6102 |
|
| 6103 |
// Is this path empty? Move to (x1,y1). |
| 6104 |
if (this._x1 === null) { |
| 6105 |
this._append`M${this._x1 = x1},${this._y1 = y1}`; |
| 6106 |
} |
| 6107 |
|
| 6108 |
// Or, is (x1,y1) coincident with (x0,y0)? Do nothing. |
| 6109 |
else if (!(l01_2 > epsilon$4)); |
| 6110 |
|
| 6111 |
// Or, are (x0,y0), (x1,y1) and (x2,y2) collinear? |
| 6112 |
// Equivalently, is (x1,y1) coincident with (x2,y2)? |
| 6113 |
// Or, is the radius zero? Line to (x1,y1). |
| 6114 |
else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$4) || !r) { |
| 6115 |
this._append`L${this._x1 = x1},${this._y1 = y1}`; |
| 6116 |
} |
| 6117 |
|
| 6118 |
// Otherwise, draw an arc! |
| 6119 |
else { |
| 6120 |
let x20 = x2 - x0, |
| 6121 |
y20 = y2 - y0, |
| 6122 |
l21_2 = x21 * x21 + y21 * y21, |
| 6123 |
l20_2 = x20 * x20 + y20 * y20, |
| 6124 |
l21 = Math.sqrt(l21_2), |
| 6125 |
l01 = Math.sqrt(l01_2), |
| 6126 |
l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2), |
| 6127 |
t01 = l / l01, |
| 6128 |
t21 = l / l21; |
| 6129 |
|
| 6130 |
// If the start tangent is not coincident with (x0,y0), line to. |
| 6131 |
if (Math.abs(t01 - 1) > epsilon$4) { |
| 6132 |
this._append`L${x1 + t01 * x01},${y1 + t01 * y01}`; |
| 6133 |
} |
| 6134 |
|
| 6135 |
this._append`A${r},${r},0,0,${+(y01 * x20 > x01 * y20)},${this._x1 = x1 + t21 * x21},${this._y1 = y1 + t21 * y21}`; |
| 6136 |
} |
| 6137 |
} |
| 6138 |
arc(x, y, r, a0, a1, ccw) { |
| 6139 |
x = +x, y = +y, r = +r, ccw = !!ccw; |
| 6140 |
|
| 6141 |
// Is the radius negative? Error. |
| 6142 |
if (r < 0) throw new Error(`negative radius: ${r}`); |
| 6143 |
|
| 6144 |
let dx = r * Math.cos(a0), |
| 6145 |
dy = r * Math.sin(a0), |
| 6146 |
x0 = x + dx, |
| 6147 |
y0 = y + dy, |
| 6148 |
cw = 1 ^ ccw, |
| 6149 |
da = ccw ? a0 - a1 : a1 - a0; |
| 6150 |
|
| 6151 |
// Is this path empty? Move to (x0,y0). |
| 6152 |
if (this._x1 === null) { |
| 6153 |
this._append`M${x0},${y0}`; |
| 6154 |
} |
| 6155 |
|
| 6156 |
// Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0). |
| 6157 |
else if (Math.abs(this._x1 - x0) > epsilon$4 || Math.abs(this._y1 - y0) > epsilon$4) { |
| 6158 |
this._append`L${x0},${y0}`; |
| 6159 |
} |
| 6160 |
|
| 6161 |
// Is this arc empty? We’re done. |
| 6162 |
if (!r) return; |
| 6163 |
|
| 6164 |
// Does the angle go the wrong way? Flip the direction. |
| 6165 |
if (da < 0) da = da % tau$3 + tau$3; |
| 6166 |
|
| 6167 |
// Is this a complete circle? Draw two arcs to complete the circle. |
| 6168 |
if (da > tauEpsilon) { |
| 6169 |
this._append`A${r},${r},0,1,${cw},${x - dx},${y - dy}A${r},${r},0,1,${cw},${this._x1 = x0},${this._y1 = y0}`; |
| 6170 |
} |
| 6171 |
|
| 6172 |
// Is this arc non-empty? Draw an arc! |
| 6173 |
else if (da > epsilon$4) { |
| 6174 |
this._append`A${r},${r},0,${+(da >= pi$2)},${cw},${this._x1 = x + r * Math.cos(a1)},${this._y1 = y + r * Math.sin(a1)}`; |
| 6175 |
} |
| 6176 |
} |
| 6177 |
rect(x, y, w, h) { |
| 6178 |
this._append`M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${w = +w}v${+h}h${-w}Z`; |
| 6179 |
} |
| 6180 |
toString() { |
| 6181 |
return this._; |
| 6182 |
} |
| 6183 |
}; |
| 6184 |
|
| 6185 |
function path() { |
| 6186 |
return new Path$1; |
| 6187 |
} |
| 6188 |
|
| 6189 |
// Allow instanceof d3.path |
| 6190 |
path.prototype = Path$1.prototype; |
| 6191 |
|
| 6192 |
function pathRound(digits = 3) { |
| 6193 |
return new Path$1(+digits); |
| 6194 |
} |
| 6195 |
|
| 6196 |
var slice$2 = Array.prototype.slice; |
| 6197 |
|
| 6198 |
function constant$6(x) { |
| 6199 |
return function() { |
| 6200 |
return x; |
| 6201 |
}; |
| 6202 |
} |
| 6203 |
|
| 6204 |
function defaultSource$1(d) { |
| 6205 |
return d.source; |
| 6206 |
} |
| 6207 |
|
| 6208 |
function defaultTarget(d) { |
| 6209 |
return d.target; |
| 6210 |
} |
| 6211 |
|
| 6212 |
function defaultRadius$1(d) { |
| 6213 |
return d.radius; |
| 6214 |
} |
| 6215 |
|
| 6216 |
function defaultStartAngle(d) { |
| 6217 |
return d.startAngle; |
| 6218 |
} |
| 6219 |
|
| 6220 |
function defaultEndAngle(d) { |
| 6221 |
return d.endAngle; |
| 6222 |
} |
| 6223 |
|
| 6224 |
function defaultPadAngle() { |
| 6225 |
return 0; |
| 6226 |
} |
| 6227 |
|
| 6228 |
function defaultArrowheadRadius() { |
| 6229 |
return 10; |
| 6230 |
} |
| 6231 |
|
| 6232 |
function ribbon(headRadius) { |
| 6233 |
var source = defaultSource$1, |
| 6234 |
target = defaultTarget, |
| 6235 |
sourceRadius = defaultRadius$1, |
| 6236 |
targetRadius = defaultRadius$1, |
| 6237 |
startAngle = defaultStartAngle, |
| 6238 |
endAngle = defaultEndAngle, |
| 6239 |
padAngle = defaultPadAngle, |
| 6240 |
context = null; |
| 6241 |
|
| 6242 |
function ribbon() { |
| 6243 |
var buffer, |
| 6244 |
s = source.apply(this, arguments), |
| 6245 |
t = target.apply(this, arguments), |
| 6246 |
ap = padAngle.apply(this, arguments) / 2, |
| 6247 |
argv = slice$2.call(arguments), |
| 6248 |
sr = +sourceRadius.apply(this, (argv[0] = s, argv)), |
| 6249 |
sa0 = startAngle.apply(this, argv) - halfPi$2, |
| 6250 |
sa1 = endAngle.apply(this, argv) - halfPi$2, |
| 6251 |
tr = +targetRadius.apply(this, (argv[0] = t, argv)), |
| 6252 |
ta0 = startAngle.apply(this, argv) - halfPi$2, |
| 6253 |
ta1 = endAngle.apply(this, argv) - halfPi$2; |
| 6254 |
|
| 6255 |
if (!context) context = buffer = path(); |
| 6256 |
|
| 6257 |
if (ap > epsilon$5) { |
| 6258 |
if (abs$2(sa1 - sa0) > ap * 2 + epsilon$5) sa1 > sa0 ? (sa0 += ap, sa1 -= ap) : (sa0 -= ap, sa1 += ap); |
| 6259 |
else sa0 = sa1 = (sa0 + sa1) / 2; |
| 6260 |
if (abs$2(ta1 - ta0) > ap * 2 + epsilon$5) ta1 > ta0 ? (ta0 += ap, ta1 -= ap) : (ta0 -= ap, ta1 += ap); |
| 6261 |
else ta0 = ta1 = (ta0 + ta1) / 2; |
| 6262 |
} |
| 6263 |
|
| 6264 |
context.moveTo(sr * cos$2(sa0), sr * sin$2(sa0)); |
| 6265 |
context.arc(0, 0, sr, sa0, sa1); |
| 6266 |
if (sa0 !== ta0 || sa1 !== ta1) { |
| 6267 |
if (headRadius) { |
| 6268 |
var hr = +headRadius.apply(this, arguments), tr2 = tr - hr, ta2 = (ta0 + ta1) / 2; |
| 6269 |
context.quadraticCurveTo(0, 0, tr2 * cos$2(ta0), tr2 * sin$2(ta0)); |
| 6270 |
context.lineTo(tr * cos$2(ta2), tr * sin$2(ta2)); |
| 6271 |
context.lineTo(tr2 * cos$2(ta1), tr2 * sin$2(ta1)); |
| 6272 |
} else { |
| 6273 |
context.quadraticCurveTo(0, 0, tr * cos$2(ta0), tr * sin$2(ta0)); |
| 6274 |
context.arc(0, 0, tr, ta0, ta1); |
| 6275 |
} |
| 6276 |
} |
| 6277 |
context.quadraticCurveTo(0, 0, sr * cos$2(sa0), sr * sin$2(sa0)); |
| 6278 |
context.closePath(); |
| 6279 |
|
| 6280 |
if (buffer) return context = null, buffer + "" || null; |
| 6281 |
} |
| 6282 |
|
| 6283 |
if (headRadius) ribbon.headRadius = function(_) { |
| 6284 |
return arguments.length ? (headRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : headRadius; |
| 6285 |
}; |
| 6286 |
|
| 6287 |
ribbon.radius = function(_) { |
| 6288 |
return arguments.length ? (sourceRadius = targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius; |
| 6289 |
}; |
| 6290 |
|
| 6291 |
ribbon.sourceRadius = function(_) { |
| 6292 |
return arguments.length ? (sourceRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : sourceRadius; |
| 6293 |
}; |
| 6294 |
|
| 6295 |
ribbon.targetRadius = function(_) { |
| 6296 |
return arguments.length ? (targetRadius = typeof _ === "function" ? _ : constant$6(+_), ribbon) : targetRadius; |
| 6297 |
}; |
| 6298 |
|
| 6299 |
ribbon.startAngle = function(_) { |
| 6300 |
return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : startAngle; |
| 6301 |
}; |
| 6302 |
|
| 6303 |
ribbon.endAngle = function(_) { |
| 6304 |
return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : endAngle; |
| 6305 |
}; |
| 6306 |
|
| 6307 |
ribbon.padAngle = function(_) { |
| 6308 |
return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$6(+_), ribbon) : padAngle; |
| 6309 |
}; |
| 6310 |
|
| 6311 |
ribbon.source = function(_) { |
| 6312 |
return arguments.length ? (source = _, ribbon) : source; |
| 6313 |
}; |
| 6314 |
|
| 6315 |
ribbon.target = function(_) { |
| 6316 |
return arguments.length ? (target = _, ribbon) : target; |
| 6317 |
}; |
| 6318 |
|
| 6319 |
ribbon.context = function(_) { |
| 6320 |
return arguments.length ? ((context = _ == null ? null : _), ribbon) : context; |
| 6321 |
}; |
| 6322 |
|
| 6323 |
return ribbon; |
| 6324 |
} |
| 6325 |
|
| 6326 |
function ribbon$1() { |
| 6327 |
return ribbon(); |
| 6328 |
} |
| 6329 |
|
| 6330 |
function ribbonArrow() { |
| 6331 |
return ribbon(defaultArrowheadRadius); |
| 6332 |
} |
| 6333 |
|
| 6334 |
var array$2 = Array.prototype; |
| 6335 |
|
| 6336 |
var slice$1 = array$2.slice; |
| 6337 |
|
| 6338 |
function ascending$1(a, b) { |
| 6339 |
return a - b; |
| 6340 |
} |
| 6341 |
|
| 6342 |
function area$3(ring) { |
| 6343 |
var i = 0, n = ring.length, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1]; |
| 6344 |
while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1]; |
| 6345 |
return area; |
| 6346 |
} |
| 6347 |
|
| 6348 |
var constant$5 = x => () => x; |
| 6349 |
|
| 6350 |
function contains$2(ring, hole) { |
| 6351 |
var i = -1, n = hole.length, c; |
| 6352 |
while (++i < n) if (c = ringContains(ring, hole[i])) return c; |
| 6353 |
return 0; |
| 6354 |
} |
| 6355 |
|
| 6356 |
function ringContains(ring, point) { |
| 6357 |
var x = point[0], y = point[1], contains = -1; |
| 6358 |
for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) { |
| 6359 |
var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1]; |
| 6360 |
if (segmentContains(pi, pj, point)) return 0; |
| 6361 |
if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains; |
| 6362 |
} |
| 6363 |
return contains; |
| 6364 |
} |
| 6365 |
|
| 6366 |
function segmentContains(a, b, c) { |
| 6367 |
var i; return collinear$1(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]); |
| 6368 |
} |
| 6369 |
|
| 6370 |
function collinear$1(a, b, c) { |
| 6371 |
return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]); |
| 6372 |
} |
| 6373 |
|
| 6374 |
function within(p, q, r) { |
| 6375 |
return p <= q && q <= r || r <= q && q <= p; |
| 6376 |
} |
| 6377 |
|
| 6378 |
function noop$2() {} |
| 6379 |
|
| 6380 |
var cases = [ |
| 6381 |
[], |
| 6382 |
[[[1.0, 1.5], [0.5, 1.0]]], |
| 6383 |
[[[1.5, 1.0], [1.0, 1.5]]], |
| 6384 |
[[[1.5, 1.0], [0.5, 1.0]]], |
| 6385 |
[[[1.0, 0.5], [1.5, 1.0]]], |
| 6386 |
[[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]], |
| 6387 |
[[[1.0, 0.5], [1.0, 1.5]]], |
| 6388 |
[[[1.0, 0.5], [0.5, 1.0]]], |
| 6389 |
[[[0.5, 1.0], [1.0, 0.5]]], |
| 6390 |
[[[1.0, 1.5], [1.0, 0.5]]], |
| 6391 |
[[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]], |
| 6392 |
[[[1.5, 1.0], [1.0, 0.5]]], |
| 6393 |
[[[0.5, 1.0], [1.5, 1.0]]], |
| 6394 |
[[[1.0, 1.5], [1.5, 1.0]]], |
| 6395 |
[[[0.5, 1.0], [1.0, 1.5]]], |
| 6396 |
[] |
| 6397 |
]; |
| 6398 |
|
| 6399 |
function Contours() { |
| 6400 |
var dx = 1, |
| 6401 |
dy = 1, |
| 6402 |
threshold = thresholdSturges, |
| 6403 |
smooth = smoothLinear; |
| 6404 |
|
| 6405 |
function contours(values) { |
| 6406 |
var tz = threshold(values); |
| 6407 |
|
| 6408 |
// Convert number of thresholds into uniform thresholds. |
| 6409 |
if (!Array.isArray(tz)) { |
| 6410 |
const e = extent$1(values, finite); |
| 6411 |
tz = ticks(...nice$1(e[0], e[1], tz), tz); |
| 6412 |
while (tz[tz.length - 1] >= e[1]) tz.pop(); |
| 6413 |
while (tz[1] < e[0]) tz.shift(); |
| 6414 |
} else { |
| 6415 |
tz = tz.slice().sort(ascending$1); |
| 6416 |
} |
| 6417 |
|
| 6418 |
return tz.map(value => contour(values, value)); |
| 6419 |
} |
| 6420 |
|
| 6421 |
// Accumulate, smooth contour rings, assign holes to exterior rings. |
| 6422 |
// Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js |
| 6423 |
function contour(values, value) { |
| 6424 |
const v = value == null ? NaN : +value; |
| 6425 |
if (isNaN(v)) throw new Error(`invalid value: ${value}`); |
| 6426 |
|
| 6427 |
var polygons = [], |
| 6428 |
holes = []; |
| 6429 |
|
| 6430 |
isorings(values, v, function(ring) { |
| 6431 |
smooth(ring, values, v); |
| 6432 |
if (area$3(ring) > 0) polygons.push([ring]); |
| 6433 |
else holes.push(ring); |
| 6434 |
}); |
| 6435 |
|
| 6436 |
holes.forEach(function(hole) { |
| 6437 |
for (var i = 0, n = polygons.length, polygon; i < n; ++i) { |
| 6438 |
if (contains$2((polygon = polygons[i])[0], hole) !== -1) { |
| 6439 |
polygon.push(hole); |
| 6440 |
return; |
| 6441 |
} |
| 6442 |
} |
| 6443 |
}); |
| 6444 |
|
| 6445 |
return { |
| 6446 |
type: "MultiPolygon", |
| 6447 |
value: value, |
| 6448 |
coordinates: polygons |
| 6449 |
}; |
| 6450 |
} |
| 6451 |
|
| 6452 |
// Marching squares with isolines stitched into rings. |
| 6453 |
// Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js |
| 6454 |
function isorings(values, value, callback) { |
| 6455 |
var fragmentByStart = new Array, |
| 6456 |
fragmentByEnd = new Array, |
| 6457 |
x, y, t0, t1, t2, t3; |
| 6458 |
|
| 6459 |
// Special case for the first row (y = -1, t2 = t3 = 0). |
| 6460 |
x = y = -1; |
| 6461 |
t1 = above(values[0], value); |
| 6462 |
cases[t1 << 1].forEach(stitch); |
| 6463 |
while (++x < dx - 1) { |
| 6464 |
t0 = t1, t1 = above(values[x + 1], value); |
| 6465 |
cases[t0 | t1 << 1].forEach(stitch); |
| 6466 |
} |
| 6467 |
cases[t1 << 0].forEach(stitch); |
| 6468 |
|
| 6469 |
// General case for the intermediate rows. |
| 6470 |
while (++y < dy - 1) { |
| 6471 |
x = -1; |
| 6472 |
t1 = above(values[y * dx + dx], value); |
| 6473 |
t2 = above(values[y * dx], value); |
| 6474 |
cases[t1 << 1 | t2 << 2].forEach(stitch); |
| 6475 |
while (++x < dx - 1) { |
| 6476 |
t0 = t1, t1 = above(values[y * dx + dx + x + 1], value); |
| 6477 |
t3 = t2, t2 = above(values[y * dx + x + 1], value); |
| 6478 |
cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch); |
| 6479 |
} |
| 6480 |
cases[t1 | t2 << 3].forEach(stitch); |
| 6481 |
} |
| 6482 |
|
| 6483 |
// Special case for the last row (y = dy - 1, t0 = t1 = 0). |
| 6484 |
x = -1; |
| 6485 |
t2 = values[y * dx] >= value; |
| 6486 |
cases[t2 << 2].forEach(stitch); |
| 6487 |
while (++x < dx - 1) { |
| 6488 |
t3 = t2, t2 = above(values[y * dx + x + 1], value); |
| 6489 |
cases[t2 << 2 | t3 << 3].forEach(stitch); |
| 6490 |
} |
| 6491 |
cases[t2 << 3].forEach(stitch); |
| 6492 |
|
| 6493 |
function stitch(line) { |
| 6494 |
var start = [line[0][0] + x, line[0][1] + y], |
| 6495 |
end = [line[1][0] + x, line[1][1] + y], |
| 6496 |
startIndex = index(start), |
| 6497 |
endIndex = index(end), |
| 6498 |
f, g; |
| 6499 |
if (f = fragmentByEnd[startIndex]) { |
| 6500 |
if (g = fragmentByStart[endIndex]) { |
| 6501 |
delete fragmentByEnd[f.end]; |
| 6502 |
delete fragmentByStart[g.start]; |
| 6503 |
if (f === g) { |
| 6504 |
f.ring.push(end); |
| 6505 |
callback(f.ring); |
| 6506 |
} else { |
| 6507 |
fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)}; |
| 6508 |
} |
| 6509 |
} else { |
| 6510 |
delete fragmentByEnd[f.end]; |
| 6511 |
f.ring.push(end); |
| 6512 |
fragmentByEnd[f.end = endIndex] = f; |
| 6513 |
} |
| 6514 |
} else if (f = fragmentByStart[endIndex]) { |
| 6515 |
if (g = fragmentByEnd[startIndex]) { |
| 6516 |
delete fragmentByStart[f.start]; |
| 6517 |
delete fragmentByEnd[g.end]; |
| 6518 |
if (f === g) { |
| 6519 |
f.ring.push(end); |
| 6520 |
callback(f.ring); |
| 6521 |
} else { |
| 6522 |
fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)}; |
| 6523 |
} |
| 6524 |
} else { |
| 6525 |
delete fragmentByStart[f.start]; |
| 6526 |
f.ring.unshift(start); |
| 6527 |
fragmentByStart[f.start = startIndex] = f; |
| 6528 |
} |
| 6529 |
} else { |
| 6530 |
fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]}; |
| 6531 |
} |
| 6532 |
} |
| 6533 |
} |
| 6534 |
|
| 6535 |
function index(point) { |
| 6536 |
return point[0] * 2 + point[1] * (dx + 1) * 4; |
| 6537 |
} |
| 6538 |
|
| 6539 |
function smoothLinear(ring, values, value) { |
| 6540 |
ring.forEach(function(point) { |
| 6541 |
var x = point[0], |
| 6542 |
y = point[1], |
| 6543 |
xt = x | 0, |
| 6544 |
yt = y | 0, |
| 6545 |
v1 = valid(values[yt * dx + xt]); |
| 6546 |
if (x > 0 && x < dx && xt === x) { |
| 6547 |
point[0] = smooth1(x, valid(values[yt * dx + xt - 1]), v1, value); |
| 6548 |
} |
| 6549 |
if (y > 0 && y < dy && yt === y) { |
| 6550 |
point[1] = smooth1(y, valid(values[(yt - 1) * dx + xt]), v1, value); |
| 6551 |
} |
| 6552 |
}); |
| 6553 |
} |
| 6554 |
|
| 6555 |
contours.contour = contour; |
| 6556 |
|
| 6557 |
contours.size = function(_) { |
| 6558 |
if (!arguments.length) return [dx, dy]; |
| 6559 |
var _0 = Math.floor(_[0]), _1 = Math.floor(_[1]); |
| 6560 |
if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size"); |
| 6561 |
return dx = _0, dy = _1, contours; |
| 6562 |
}; |
| 6563 |
|
| 6564 |
contours.thresholds = function(_) { |
| 6565 |
return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), contours) : threshold; |
| 6566 |
}; |
| 6567 |
|
| 6568 |
contours.smooth = function(_) { |
| 6569 |
return arguments.length ? (smooth = _ ? smoothLinear : noop$2, contours) : smooth === smoothLinear; |
| 6570 |
}; |
| 6571 |
|
| 6572 |
return contours; |
| 6573 |
} |
| 6574 |
|
| 6575 |
// When computing the extent, ignore infinite values (as well as invalid ones). |
| 6576 |
function finite(x) { |
| 6577 |
return isFinite(x) ? x : NaN; |
| 6578 |
} |
| 6579 |
|
| 6580 |
// Is the (possibly invalid) x greater than or equal to the (known valid) value? |
| 6581 |
// Treat any invalid value as below negative infinity. |
| 6582 |
function above(x, value) { |
| 6583 |
return x == null ? false : +x >= value; |
| 6584 |
} |
| 6585 |
|
| 6586 |
// During smoothing, treat any invalid value as negative infinity. |
| 6587 |
function valid(v) { |
| 6588 |
return v == null || isNaN(v = +v) ? -Infinity : v; |
| 6589 |
} |
| 6590 |
|
| 6591 |
function smooth1(x, v0, v1, value) { |
| 6592 |
const a = value - v0; |
| 6593 |
const b = v1 - v0; |
| 6594 |
const d = isFinite(a) || isFinite(b) ? a / b : Math.sign(a) / Math.sign(b); |
| 6595 |
return isNaN(d) ? x : x + d - 0.5; |
| 6596 |
} |
| 6597 |
|
| 6598 |
function defaultX$1(d) { |
| 6599 |
return d[0]; |
| 6600 |
} |
| 6601 |
|
| 6602 |
function defaultY$1(d) { |
| 6603 |
return d[1]; |
| 6604 |
} |
| 6605 |
|
| 6606 |
function defaultWeight() { |
| 6607 |
return 1; |
| 6608 |
} |
| 6609 |
|
| 6610 |
function density() { |
| 6611 |
var x = defaultX$1, |
| 6612 |
y = defaultY$1, |
| 6613 |
weight = defaultWeight, |
| 6614 |
dx = 960, |
| 6615 |
dy = 500, |
| 6616 |
r = 20, // blur radius |
| 6617 |
k = 2, // log2(grid cell size) |
| 6618 |
o = r * 3, // grid offset, to pad for blur |
| 6619 |
n = (dx + o * 2) >> k, // grid width |
| 6620 |
m = (dy + o * 2) >> k, // grid height |
| 6621 |
threshold = constant$5(20); |
| 6622 |
|
| 6623 |
function grid(data) { |
| 6624 |
var values = new Float32Array(n * m), |
| 6625 |
pow2k = Math.pow(2, -k), |
| 6626 |
i = -1; |
| 6627 |
|
| 6628 |
for (const d of data) { |
| 6629 |
var xi = (x(d, ++i, data) + o) * pow2k, |
| 6630 |
yi = (y(d, i, data) + o) * pow2k, |
| 6631 |
wi = +weight(d, i, data); |
| 6632 |
if (wi && xi >= 0 && xi < n && yi >= 0 && yi < m) { |
| 6633 |
var x0 = Math.floor(xi), |
| 6634 |
y0 = Math.floor(yi), |
| 6635 |
xt = xi - x0 - 0.5, |
| 6636 |
yt = yi - y0 - 0.5; |
| 6637 |
values[x0 + y0 * n] += (1 - xt) * (1 - yt) * wi; |
| 6638 |
values[x0 + 1 + y0 * n] += xt * (1 - yt) * wi; |
| 6639 |
values[x0 + 1 + (y0 + 1) * n] += xt * yt * wi; |
| 6640 |
values[x0 + (y0 + 1) * n] += (1 - xt) * yt * wi; |
| 6641 |
} |
| 6642 |
} |
| 6643 |
|
| 6644 |
blur2({data: values, width: n, height: m}, r * pow2k); |
| 6645 |
return values; |
| 6646 |
} |
| 6647 |
|
| 6648 |
function density(data) { |
| 6649 |
var values = grid(data), |
| 6650 |
tz = threshold(values), |
| 6651 |
pow4k = Math.pow(2, 2 * k); |
| 6652 |
|
| 6653 |
// Convert number of thresholds into uniform thresholds. |
| 6654 |
if (!Array.isArray(tz)) { |
| 6655 |
tz = ticks(Number.MIN_VALUE, max$3(values) / pow4k, tz); |
| 6656 |
} |
| 6657 |
|
| 6658 |
return Contours() |
| 6659 |
.size([n, m]) |
| 6660 |
.thresholds(tz.map(d => d * pow4k)) |
| 6661 |
(values) |
| 6662 |
.map((c, i) => (c.value = +tz[i], transform(c))); |
| 6663 |
} |
| 6664 |
|
| 6665 |
density.contours = function(data) { |
| 6666 |
var values = grid(data), |
| 6667 |
contours = Contours().size([n, m]), |
| 6668 |
pow4k = Math.pow(2, 2 * k), |
| 6669 |
contour = value => { |
| 6670 |
value = +value; |
| 6671 |
var c = transform(contours.contour(values, value * pow4k)); |
| 6672 |
c.value = value; // preserve exact threshold value |
| 6673 |
return c; |
| 6674 |
}; |
| 6675 |
Object.defineProperty(contour, "max", {get: () => max$3(values) / pow4k}); |
| 6676 |
return contour; |
| 6677 |
}; |
| 6678 |
|
| 6679 |
function transform(geometry) { |
| 6680 |
geometry.coordinates.forEach(transformPolygon); |
| 6681 |
return geometry; |
| 6682 |
} |
| 6683 |
|
| 6684 |
function transformPolygon(coordinates) { |
| 6685 |
coordinates.forEach(transformRing); |
| 6686 |
} |
| 6687 |
|
| 6688 |
function transformRing(coordinates) { |
| 6689 |
coordinates.forEach(transformPoint); |
| 6690 |
} |
| 6691 |
|
| 6692 |
// TODO Optimize. |
| 6693 |
function transformPoint(coordinates) { |
| 6694 |
coordinates[0] = coordinates[0] * Math.pow(2, k) - o; |
| 6695 |
coordinates[1] = coordinates[1] * Math.pow(2, k) - o; |
| 6696 |
} |
| 6697 |
|
| 6698 |
function resize() { |
| 6699 |
o = r * 3; |
| 6700 |
n = (dx + o * 2) >> k; |
| 6701 |
m = (dy + o * 2) >> k; |
| 6702 |
return density; |
| 6703 |
} |
| 6704 |
|
| 6705 |
density.x = function(_) { |
| 6706 |
return arguments.length ? (x = typeof _ === "function" ? _ : constant$5(+_), density) : x; |
| 6707 |
}; |
| 6708 |
|
| 6709 |
density.y = function(_) { |
| 6710 |
return arguments.length ? (y = typeof _ === "function" ? _ : constant$5(+_), density) : y; |
| 6711 |
}; |
| 6712 |
|
| 6713 |
density.weight = function(_) { |
| 6714 |
return arguments.length ? (weight = typeof _ === "function" ? _ : constant$5(+_), density) : weight; |
| 6715 |
}; |
| 6716 |
|
| 6717 |
density.size = function(_) { |
| 6718 |
if (!arguments.length) return [dx, dy]; |
| 6719 |
var _0 = +_[0], _1 = +_[1]; |
| 6720 |
if (!(_0 >= 0 && _1 >= 0)) throw new Error("invalid size"); |
| 6721 |
return dx = _0, dy = _1, resize(); |
| 6722 |
}; |
| 6723 |
|
| 6724 |
density.cellSize = function(_) { |
| 6725 |
if (!arguments.length) return 1 << k; |
| 6726 |
if (!((_ = +_) >= 1)) throw new Error("invalid cell size"); |
| 6727 |
return k = Math.floor(Math.log(_) / Math.LN2), resize(); |
| 6728 |
}; |
| 6729 |
|
| 6730 |
density.thresholds = function(_) { |
| 6731 |
return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant$5(slice$1.call(_)) : constant$5(_), density) : threshold; |
| 6732 |
}; |
| 6733 |
|
| 6734 |
density.bandwidth = function(_) { |
| 6735 |
if (!arguments.length) return Math.sqrt(r * (r + 1)); |
| 6736 |
if (!((_ = +_) >= 0)) throw new Error("invalid bandwidth"); |
| 6737 |
return r = (Math.sqrt(4 * _ * _ + 1) - 1) / 2, resize(); |
| 6738 |
}; |
| 6739 |
|
| 6740 |
return density; |
| 6741 |
} |
| 6742 |
|
| 6743 |
const epsilon$3 = 1.1102230246251565e-16; |
| 6744 |
const splitter = 134217729; |
| 6745 |
const resulterrbound = (3 + 8 * epsilon$3) * epsilon$3; |
| 6746 |
|
| 6747 |
// fast_expansion_sum_zeroelim routine from oritinal code |
| 6748 |
function sum$1(elen, e, flen, f, h) { |
| 6749 |
let Q, Qnew, hh, bvirt; |
| 6750 |
let enow = e[0]; |
| 6751 |
let fnow = f[0]; |
| 6752 |
let eindex = 0; |
| 6753 |
let findex = 0; |
| 6754 |
if ((fnow > enow) === (fnow > -enow)) { |
| 6755 |
Q = enow; |
| 6756 |
enow = e[++eindex]; |
| 6757 |
} else { |
| 6758 |
Q = fnow; |
| 6759 |
fnow = f[++findex]; |
| 6760 |
} |
| 6761 |
let hindex = 0; |
| 6762 |
if (eindex < elen && findex < flen) { |
| 6763 |
if ((fnow > enow) === (fnow > -enow)) { |
| 6764 |
Qnew = enow + Q; |
| 6765 |
hh = Q - (Qnew - enow); |
| 6766 |
enow = e[++eindex]; |
| 6767 |
} else { |
| 6768 |
Qnew = fnow + Q; |
| 6769 |
hh = Q - (Qnew - fnow); |
| 6770 |
fnow = f[++findex]; |
| 6771 |
} |
| 6772 |
Q = Qnew; |
| 6773 |
if (hh !== 0) { |
| 6774 |
h[hindex++] = hh; |
| 6775 |
} |
| 6776 |
while (eindex < elen && findex < flen) { |
| 6777 |
if ((fnow > enow) === (fnow > -enow)) { |
| 6778 |
Qnew = Q + enow; |
| 6779 |
bvirt = Qnew - Q; |
| 6780 |
hh = Q - (Qnew - bvirt) + (enow - bvirt); |
| 6781 |
enow = e[++eindex]; |
| 6782 |
} else { |
| 6783 |
Qnew = Q + fnow; |
| 6784 |
bvirt = Qnew - Q; |
| 6785 |
hh = Q - (Qnew - bvirt) + (fnow - bvirt); |
| 6786 |
fnow = f[++findex]; |
| 6787 |
} |
| 6788 |
Q = Qnew; |
| 6789 |
if (hh !== 0) { |
| 6790 |
h[hindex++] = hh; |
| 6791 |
} |
| 6792 |
} |
| 6793 |
} |
| 6794 |
while (eindex < elen) { |
| 6795 |
Qnew = Q + enow; |
| 6796 |
bvirt = Qnew - Q; |
| 6797 |
hh = Q - (Qnew - bvirt) + (enow - bvirt); |
| 6798 |
enow = e[++eindex]; |
| 6799 |
Q = Qnew; |
| 6800 |
if (hh !== 0) { |
| 6801 |
h[hindex++] = hh; |
| 6802 |
} |
| 6803 |
} |
| 6804 |
while (findex < flen) { |
| 6805 |
Qnew = Q + fnow; |
| 6806 |
bvirt = Qnew - Q; |
| 6807 |
hh = Q - (Qnew - bvirt) + (fnow - bvirt); |
| 6808 |
fnow = f[++findex]; |
| 6809 |
Q = Qnew; |
| 6810 |
if (hh !== 0) { |
| 6811 |
h[hindex++] = hh; |
| 6812 |
} |
| 6813 |
} |
| 6814 |
if (Q !== 0 || hindex === 0) { |
| 6815 |
h[hindex++] = Q; |
| 6816 |
} |
| 6817 |
return hindex; |
| 6818 |
} |
| 6819 |
|
| 6820 |
function estimate(elen, e) { |
| 6821 |
let Q = e[0]; |
| 6822 |
for (let i = 1; i < elen; i++) Q += e[i]; |
| 6823 |
return Q; |
| 6824 |
} |
| 6825 |
|
| 6826 |
function vec(n) { |
| 6827 |
return new Float64Array(n); |
| 6828 |
} |
| 6829 |
|
| 6830 |
const ccwerrboundA = (3 + 16 * epsilon$3) * epsilon$3; |
| 6831 |
const ccwerrboundB = (2 + 12 * epsilon$3) * epsilon$3; |
| 6832 |
const ccwerrboundC = (9 + 64 * epsilon$3) * epsilon$3 * epsilon$3; |
| 6833 |
|
| 6834 |
const B = vec(4); |
| 6835 |
const C1 = vec(8); |
| 6836 |
const C2 = vec(12); |
| 6837 |
const D = vec(16); |
| 6838 |
const u = vec(4); |
| 6839 |
|
| 6840 |
function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) { |
| 6841 |
let acxtail, acytail, bcxtail, bcytail; |
| 6842 |
let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3; |
| 6843 |
|
| 6844 |
const acx = ax - cx; |
| 6845 |
const bcx = bx - cx; |
| 6846 |
const acy = ay - cy; |
| 6847 |
const bcy = by - cy; |
| 6848 |
|
| 6849 |
s1 = acx * bcy; |
| 6850 |
c = splitter * acx; |
| 6851 |
ahi = c - (c - acx); |
| 6852 |
alo = acx - ahi; |
| 6853 |
c = splitter * bcy; |
| 6854 |
bhi = c - (c - bcy); |
| 6855 |
blo = bcy - bhi; |
| 6856 |
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo); |
| 6857 |
t1 = acy * bcx; |
| 6858 |
c = splitter * acy; |
| 6859 |
ahi = c - (c - acy); |
| 6860 |
alo = acy - ahi; |
| 6861 |
c = splitter * bcx; |
| 6862 |
bhi = c - (c - bcx); |
| 6863 |
blo = bcx - bhi; |
| 6864 |
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo); |
| 6865 |
_i = s0 - t0; |
| 6866 |
bvirt = s0 - _i; |
| 6867 |
B[0] = s0 - (_i + bvirt) + (bvirt - t0); |
| 6868 |
_j = s1 + _i; |
| 6869 |
bvirt = _j - s1; |
| 6870 |
_0 = s1 - (_j - bvirt) + (_i - bvirt); |
| 6871 |
_i = _0 - t1; |
| 6872 |
bvirt = _0 - _i; |
| 6873 |
B[1] = _0 - (_i + bvirt) + (bvirt - t1); |
| 6874 |
u3 = _j + _i; |
| 6875 |
bvirt = u3 - _j; |
| 6876 |
B[2] = _j - (u3 - bvirt) + (_i - bvirt); |
| 6877 |
B[3] = u3; |
| 6878 |
|
| 6879 |
let det = estimate(4, B); |
| 6880 |
let errbound = ccwerrboundB * detsum; |
| 6881 |
if (det >= errbound || -det >= errbound) { |
| 6882 |
return det; |
| 6883 |
} |
| 6884 |
|
| 6885 |
bvirt = ax - acx; |
| 6886 |
acxtail = ax - (acx + bvirt) + (bvirt - cx); |
| 6887 |
bvirt = bx - bcx; |
| 6888 |
bcxtail = bx - (bcx + bvirt) + (bvirt - cx); |
| 6889 |
bvirt = ay - acy; |
| 6890 |
acytail = ay - (acy + bvirt) + (bvirt - cy); |
| 6891 |
bvirt = by - bcy; |
| 6892 |
bcytail = by - (bcy + bvirt) + (bvirt - cy); |
| 6893 |
|
| 6894 |
if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) { |
| 6895 |
return det; |
| 6896 |
} |
| 6897 |
|
| 6898 |
errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det); |
| 6899 |
det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail); |
| 6900 |
if (det >= errbound || -det >= errbound) return det; |
| 6901 |
|
| 6902 |
s1 = acxtail * bcy; |
| 6903 |
c = splitter * acxtail; |
| 6904 |
ahi = c - (c - acxtail); |
| 6905 |
alo = acxtail - ahi; |
| 6906 |
c = splitter * bcy; |
| 6907 |
bhi = c - (c - bcy); |
| 6908 |
blo = bcy - bhi; |
| 6909 |
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo); |
| 6910 |
t1 = acytail * bcx; |
| 6911 |
c = splitter * acytail; |
| 6912 |
ahi = c - (c - acytail); |
| 6913 |
alo = acytail - ahi; |
| 6914 |
c = splitter * bcx; |
| 6915 |
bhi = c - (c - bcx); |
| 6916 |
blo = bcx - bhi; |
| 6917 |
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo); |
| 6918 |
_i = s0 - t0; |
| 6919 |
bvirt = s0 - _i; |
| 6920 |
u[0] = s0 - (_i + bvirt) + (bvirt - t0); |
| 6921 |
_j = s1 + _i; |
| 6922 |
bvirt = _j - s1; |
| 6923 |
_0 = s1 - (_j - bvirt) + (_i - bvirt); |
| 6924 |
_i = _0 - t1; |
| 6925 |
bvirt = _0 - _i; |
| 6926 |
u[1] = _0 - (_i + bvirt) + (bvirt - t1); |
| 6927 |
u3 = _j + _i; |
| 6928 |
bvirt = u3 - _j; |
| 6929 |
u[2] = _j - (u3 - bvirt) + (_i - bvirt); |
| 6930 |
u[3] = u3; |
| 6931 |
const C1len = sum$1(4, B, 4, u, C1); |
| 6932 |
|
| 6933 |
s1 = acx * bcytail; |
| 6934 |
c = splitter * acx; |
| 6935 |
ahi = c - (c - acx); |
| 6936 |
alo = acx - ahi; |
| 6937 |
c = splitter * bcytail; |
| 6938 |
bhi = c - (c - bcytail); |
| 6939 |
blo = bcytail - bhi; |
| 6940 |
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo); |
| 6941 |
t1 = acy * bcxtail; |
| 6942 |
c = splitter * acy; |
| 6943 |
ahi = c - (c - acy); |
| 6944 |
alo = acy - ahi; |
| 6945 |
c = splitter * bcxtail; |
| 6946 |
bhi = c - (c - bcxtail); |
| 6947 |
blo = bcxtail - bhi; |
| 6948 |
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo); |
| 6949 |
_i = s0 - t0; |
| 6950 |
bvirt = s0 - _i; |
| 6951 |
u[0] = s0 - (_i + bvirt) + (bvirt - t0); |
| 6952 |
_j = s1 + _i; |
| 6953 |
bvirt = _j - s1; |
| 6954 |
_0 = s1 - (_j - bvirt) + (_i - bvirt); |
| 6955 |
_i = _0 - t1; |
| 6956 |
bvirt = _0 - _i; |
| 6957 |
u[1] = _0 - (_i + bvirt) + (bvirt - t1); |
| 6958 |
u3 = _j + _i; |
| 6959 |
bvirt = u3 - _j; |
| 6960 |
u[2] = _j - (u3 - bvirt) + (_i - bvirt); |
| 6961 |
u[3] = u3; |
| 6962 |
const C2len = sum$1(C1len, C1, 4, u, C2); |
| 6963 |
|
| 6964 |
s1 = acxtail * bcytail; |
| 6965 |
c = splitter * acxtail; |
| 6966 |
ahi = c - (c - acxtail); |
| 6967 |
alo = acxtail - ahi; |
| 6968 |
c = splitter * bcytail; |
| 6969 |
bhi = c - (c - bcytail); |
| 6970 |
blo = bcytail - bhi; |
| 6971 |
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo); |
| 6972 |
t1 = acytail * bcxtail; |
| 6973 |
c = splitter * acytail; |
| 6974 |
ahi = c - (c - acytail); |
| 6975 |
alo = acytail - ahi; |
| 6976 |
c = splitter * bcxtail; |
| 6977 |
bhi = c - (c - bcxtail); |
| 6978 |
blo = bcxtail - bhi; |
| 6979 |
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo); |
| 6980 |
_i = s0 - t0; |
| 6981 |
bvirt = s0 - _i; |
| 6982 |
u[0] = s0 - (_i + bvirt) + (bvirt - t0); |
| 6983 |
_j = s1 + _i; |
| 6984 |
bvirt = _j - s1; |
| 6985 |
_0 = s1 - (_j - bvirt) + (_i - bvirt); |
| 6986 |
_i = _0 - t1; |
| 6987 |
bvirt = _0 - _i; |
| 6988 |
u[1] = _0 - (_i + bvirt) + (bvirt - t1); |
| 6989 |
u3 = _j + _i; |
| 6990 |
bvirt = u3 - _j; |
| 6991 |
u[2] = _j - (u3 - bvirt) + (_i - bvirt); |
| 6992 |
u[3] = u3; |
| 6993 |
const Dlen = sum$1(C2len, C2, 4, u, D); |
| 6994 |
|
| 6995 |
return D[Dlen - 1]; |
| 6996 |
} |
| 6997 |
|
| 6998 |
function orient2d(ax, ay, bx, by, cx, cy) { |
| 6999 |
const detleft = (ay - cy) * (bx - cx); |
| 7000 |
const detright = (ax - cx) * (by - cy); |
| 7001 |
const det = detleft - detright; |
| 7002 |
|
| 7003 |
const detsum = Math.abs(detleft + detright); |
| 7004 |
if (Math.abs(det) >= ccwerrboundA * detsum) return det; |
| 7005 |
|
| 7006 |
return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum); |
| 7007 |
} |
| 7008 |
|
| 7009 |
const EPSILON = Math.pow(2, -52); |
| 7010 |
const EDGE_STACK = new Uint32Array(512); |
| 7011 |
|
| 7012 |
class Delaunator { |
| 7013 |
|
| 7014 |
static from(points, getX = defaultGetX, getY = defaultGetY) { |
| 7015 |
const n = points.length; |
| 7016 |
const coords = new Float64Array(n * 2); |
| 7017 |
|
| 7018 |
for (let i = 0; i < n; i++) { |
| 7019 |
const p = points[i]; |
| 7020 |
coords[2 * i] = getX(p); |
| 7021 |
coords[2 * i + 1] = getY(p); |
| 7022 |
} |
| 7023 |
|
| 7024 |
return new Delaunator(coords); |
| 7025 |
} |
| 7026 |
|
| 7027 |
constructor(coords) { |
| 7028 |
const n = coords.length >> 1; |
| 7029 |
if (n > 0 && typeof coords[0] !== 'number') throw new Error('Expected coords to contain numbers.'); |
| 7030 |
|
| 7031 |
this.coords = coords; |
| 7032 |
|
| 7033 |
// arrays that will store the triangulation graph |
| 7034 |
const maxTriangles = Math.max(2 * n - 5, 0); |
| 7035 |
this._triangles = new Uint32Array(maxTriangles * 3); |
| 7036 |
this._halfedges = new Int32Array(maxTriangles * 3); |
| 7037 |
|
| 7038 |
// temporary arrays for tracking the edges of the advancing convex hull |
| 7039 |
this._hashSize = Math.ceil(Math.sqrt(n)); |
| 7040 |
this._hullPrev = new Uint32Array(n); // edge to prev edge |
| 7041 |
this._hullNext = new Uint32Array(n); // edge to next edge |
| 7042 |
this._hullTri = new Uint32Array(n); // edge to adjacent triangle |
| 7043 |
this._hullHash = new Int32Array(this._hashSize); // angular edge hash |
| 7044 |
|
| 7045 |
// temporary arrays for sorting points |
| 7046 |
this._ids = new Uint32Array(n); |
| 7047 |
this._dists = new Float64Array(n); |
| 7048 |
|
| 7049 |
this.update(); |
| 7050 |
} |
| 7051 |
|
| 7052 |
update() { |
| 7053 |
const {coords, _hullPrev: hullPrev, _hullNext: hullNext, _hullTri: hullTri, _hullHash: hullHash} = this; |
| 7054 |
const n = coords.length >> 1; |
| 7055 |
|
| 7056 |
// populate an array of point indices; calculate input data bbox |
| 7057 |
let minX = Infinity; |
| 7058 |
let minY = Infinity; |
| 7059 |
let maxX = -Infinity; |
| 7060 |
let maxY = -Infinity; |
| 7061 |
|
| 7062 |
for (let i = 0; i < n; i++) { |
| 7063 |
const x = coords[2 * i]; |
| 7064 |
const y = coords[2 * i + 1]; |
| 7065 |
if (x < minX) minX = x; |
| 7066 |
if (y < minY) minY = y; |
| 7067 |
if (x > maxX) maxX = x; |
| 7068 |
if (y > maxY) maxY = y; |
| 7069 |
this._ids[i] = i; |
| 7070 |
} |
| 7071 |
const cx = (minX + maxX) / 2; |
| 7072 |
const cy = (minY + maxY) / 2; |
| 7073 |
|
| 7074 |
let i0, i1, i2; |
| 7075 |
|
| 7076 |
// pick a seed point close to the center |
| 7077 |
for (let i = 0, minDist = Infinity; i < n; i++) { |
| 7078 |
const d = dist(cx, cy, coords[2 * i], coords[2 * i + 1]); |
| 7079 |
if (d < minDist) { |
| 7080 |
i0 = i; |
| 7081 |
minDist = d; |
| 7082 |
} |
| 7083 |
} |
| 7084 |
const i0x = coords[2 * i0]; |
| 7085 |
const i0y = coords[2 * i0 + 1]; |
| 7086 |
|
| 7087 |
// find the point closest to the seed |
| 7088 |
for (let i = 0, minDist = Infinity; i < n; i++) { |
| 7089 |
if (i === i0) continue; |
| 7090 |
const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]); |
| 7091 |
if (d < minDist && d > 0) { |
| 7092 |
i1 = i; |
| 7093 |
minDist = d; |
| 7094 |
} |
| 7095 |
} |
| 7096 |
let i1x = coords[2 * i1]; |
| 7097 |
let i1y = coords[2 * i1 + 1]; |
| 7098 |
|
| 7099 |
let minRadius = Infinity; |
| 7100 |
|
| 7101 |
// find the third point which forms the smallest circumcircle with the first two |
| 7102 |
for (let i = 0; i < n; i++) { |
| 7103 |
if (i === i0 || i === i1) continue; |
| 7104 |
const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]); |
| 7105 |
if (r < minRadius) { |
| 7106 |
i2 = i; |
| 7107 |
minRadius = r; |
| 7108 |
} |
| 7109 |
} |
| 7110 |
let i2x = coords[2 * i2]; |
| 7111 |
let i2y = coords[2 * i2 + 1]; |
| 7112 |
|
| 7113 |
if (minRadius === Infinity) { |
| 7114 |
// order collinear points by dx (or dy if all x are identical) |
| 7115 |
// and return the list as a hull |
| 7116 |
for (let i = 0; i < n; i++) { |
| 7117 |
this._dists[i] = (coords[2 * i] - coords[0]) || (coords[2 * i + 1] - coords[1]); |
| 7118 |
} |
| 7119 |
quicksort(this._ids, this._dists, 0, n - 1); |
| 7120 |
const hull = new Uint32Array(n); |
| 7121 |
let j = 0; |
| 7122 |
for (let i = 0, d0 = -Infinity; i < n; i++) { |
| 7123 |
const id = this._ids[i]; |
| 7124 |
const d = this._dists[id]; |
| 7125 |
if (d > d0) { |
| 7126 |
hull[j++] = id; |
| 7127 |
d0 = d; |
| 7128 |
} |
| 7129 |
} |
| 7130 |
this.hull = hull.subarray(0, j); |
| 7131 |
this.triangles = new Uint32Array(0); |
| 7132 |
this.halfedges = new Uint32Array(0); |
| 7133 |
return; |
| 7134 |
} |
| 7135 |
|
| 7136 |
// swap the order of the seed points for counter-clockwise orientation |
| 7137 |
if (orient2d(i0x, i0y, i1x, i1y, i2x, i2y) < 0) { |
| 7138 |
const i = i1; |
| 7139 |
const x = i1x; |
| 7140 |
const y = i1y; |
| 7141 |
i1 = i2; |
| 7142 |
i1x = i2x; |
| 7143 |
i1y = i2y; |
| 7144 |
i2 = i; |
| 7145 |
i2x = x; |
| 7146 |
i2y = y; |
| 7147 |
} |
| 7148 |
|
| 7149 |
const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y); |
| 7150 |
this._cx = center.x; |
| 7151 |
this._cy = center.y; |
| 7152 |
|
| 7153 |
for (let i = 0; i < n; i++) { |
| 7154 |
this._dists[i] = dist(coords[2 * i], coords[2 * i + 1], center.x, center.y); |
| 7155 |
} |
| 7156 |
|
| 7157 |
// sort the points by distance from the seed triangle circumcenter |
| 7158 |
quicksort(this._ids, this._dists, 0, n - 1); |
| 7159 |
|
| 7160 |
// set up the seed triangle as the starting hull |
| 7161 |
this._hullStart = i0; |
| 7162 |
let hullSize = 3; |
| 7163 |
|
| 7164 |
hullNext[i0] = hullPrev[i2] = i1; |
| 7165 |
hullNext[i1] = hullPrev[i0] = i2; |
| 7166 |
hullNext[i2] = hullPrev[i1] = i0; |
| 7167 |
|
| 7168 |
hullTri[i0] = 0; |
| 7169 |
hullTri[i1] = 1; |
| 7170 |
hullTri[i2] = 2; |
| 7171 |
|
| 7172 |
hullHash.fill(-1); |
| 7173 |
hullHash[this._hashKey(i0x, i0y)] = i0; |
| 7174 |
hullHash[this._hashKey(i1x, i1y)] = i1; |
| 7175 |
hullHash[this._hashKey(i2x, i2y)] = i2; |
| 7176 |
|
| 7177 |
this.trianglesLen = 0; |
| 7178 |
this._addTriangle(i0, i1, i2, -1, -1, -1); |
| 7179 |
|
| 7180 |
for (let k = 0, xp, yp; k < this._ids.length; k++) { |
| 7181 |
const i = this._ids[k]; |
| 7182 |
const x = coords[2 * i]; |
| 7183 |
const y = coords[2 * i + 1]; |
| 7184 |
|
| 7185 |
// skip near-duplicate points |
| 7186 |
if (k > 0 && Math.abs(x - xp) <= EPSILON && Math.abs(y - yp) <= EPSILON) continue; |
| 7187 |
xp = x; |
| 7188 |
yp = y; |
| 7189 |
|
| 7190 |
// skip seed triangle points |
| 7191 |
if (i === i0 || i === i1 || i === i2) continue; |
| 7192 |
|
| 7193 |
// find a visible edge on the convex hull using edge hash |
| 7194 |
let start = 0; |
| 7195 |
for (let j = 0, key = this._hashKey(x, y); j < this._hashSize; j++) { |
| 7196 |
start = hullHash[(key + j) % this._hashSize]; |
| 7197 |
if (start !== -1 && start !== hullNext[start]) break; |
| 7198 |
} |
| 7199 |
|
| 7200 |
start = hullPrev[start]; |
| 7201 |
let e = start, q; |
| 7202 |
while (q = hullNext[e], orient2d(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1]) >= 0) { |
| 7203 |
e = q; |
| 7204 |
if (e === start) { |
| 7205 |
e = -1; |
| 7206 |
break; |
| 7207 |
} |
| 7208 |
} |
| 7209 |
if (e === -1) continue; // likely a near-duplicate point; skip it |
| 7210 |
|
| 7211 |
// add the first triangle from the point |
| 7212 |
let t = this._addTriangle(e, i, hullNext[e], -1, -1, hullTri[e]); |
| 7213 |
|
| 7214 |
// recursively flip triangles from the point until they satisfy the Delaunay condition |
| 7215 |
hullTri[i] = this._legalize(t + 2); |
| 7216 |
hullTri[e] = t; // keep track of boundary triangles on the hull |
| 7217 |
hullSize++; |
| 7218 |
|
| 7219 |
// walk forward through the hull, adding more triangles and flipping recursively |
| 7220 |
let n = hullNext[e]; |
| 7221 |
while (q = hullNext[n], orient2d(x, y, coords[2 * n], coords[2 * n + 1], coords[2 * q], coords[2 * q + 1]) < 0) { |
| 7222 |
t = this._addTriangle(n, i, q, hullTri[i], -1, hullTri[n]); |
| 7223 |
hullTri[i] = this._legalize(t + 2); |
| 7224 |
hullNext[n] = n; // mark as removed |
| 7225 |
hullSize--; |
| 7226 |
n = q; |
| 7227 |
} |
| 7228 |
|
| 7229 |
// walk backward from the other side, adding more triangles and flipping |
| 7230 |
if (e === start) { |
| 7231 |
while (q = hullPrev[e], orient2d(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1]) < 0) { |
| 7232 |
t = this._addTriangle(q, i, e, -1, hullTri[e], hullTri[q]); |
| 7233 |
this._legalize(t + 2); |
| 7234 |
hullTri[q] = t; |
| 7235 |
hullNext[e] = e; // mark as removed |
| 7236 |
hullSize--; |
| 7237 |
e = q; |
| 7238 |
} |
| 7239 |
} |
| 7240 |
|
| 7241 |
// update the hull indices |
| 7242 |
this._hullStart = hullPrev[i] = e; |
| 7243 |
hullNext[e] = hullPrev[n] = i; |
| 7244 |
hullNext[i] = n; |
| 7245 |
|
| 7246 |
// save the two new edges in the hash table |
| 7247 |
hullHash[this._hashKey(x, y)] = i; |
| 7248 |
hullHash[this._hashKey(coords[2 * e], coords[2 * e + 1])] = e; |
| 7249 |
} |
| 7250 |
|
| 7251 |
this.hull = new Uint32Array(hullSize); |
| 7252 |
for (let i = 0, e = this._hullStart; i < hullSize; i++) { |
| 7253 |
this.hull[i] = e; |
| 7254 |
e = hullNext[e]; |
| 7255 |
} |
| 7256 |
|
| 7257 |
// trim typed triangle mesh arrays |
| 7258 |
this.triangles = this._triangles.subarray(0, this.trianglesLen); |
| 7259 |
this.halfedges = this._halfedges.subarray(0, this.trianglesLen); |
| 7260 |
} |
| 7261 |
|
| 7262 |
_hashKey(x, y) { |
| 7263 |
return Math.floor(pseudoAngle(x - this._cx, y - this._cy) * this._hashSize) % this._hashSize; |
| 7264 |
} |
| 7265 |
|
| 7266 |
_legalize(a) { |
| 7267 |
const {_triangles: triangles, _halfedges: halfedges, coords} = this; |
| 7268 |
|
| 7269 |
let i = 0; |
| 7270 |
let ar = 0; |
| 7271 |
|
| 7272 |
// recursion eliminated with a fixed-size stack |
| 7273 |
while (true) { |
| 7274 |
const b = halfedges[a]; |
| 7275 |
|
| 7276 |
/* if the pair of triangles doesn't satisfy the Delaunay condition |
| 7277 |
* (p1 is inside the circumcircle of [p0, pl, pr]), flip them, |
| 7278 |
* then do the same check/flip recursively for the new pair of triangles |
| 7279 |
* |
| 7280 |
* pl pl |
| 7281 |
* /||\ / \ |
| 7282 |
* al/ || \bl al/ \a |
| 7283 |
* / || \ / \ |
| 7284 |
* / a||b \ flip /___ar___\ |
| 7285 |
* p0\ || /p1 => p0\---bl---/p1 |
| 7286 |
* \ || / \ / |
| 7287 |
* ar\ || /br b\ /br |
| 7288 |
* \||/ \ / |
| 7289 |
* pr pr |
| 7290 |
*/ |
| 7291 |
const a0 = a - a % 3; |
| 7292 |
ar = a0 + (a + 2) % 3; |
| 7293 |
|
| 7294 |
if (b === -1) { // convex hull edge |
| 7295 |
if (i === 0) break; |
| 7296 |
a = EDGE_STACK[--i]; |
| 7297 |
continue; |
| 7298 |
} |
| 7299 |
|
| 7300 |
const b0 = b - b % 3; |
| 7301 |
const al = a0 + (a + 1) % 3; |
| 7302 |
const bl = b0 + (b + 2) % 3; |
| 7303 |
|
| 7304 |
const p0 = triangles[ar]; |
| 7305 |
const pr = triangles[a]; |
| 7306 |
const pl = triangles[al]; |
| 7307 |
const p1 = triangles[bl]; |
| 7308 |
|
| 7309 |
const illegal = inCircle( |
| 7310 |
coords[2 * p0], coords[2 * p0 + 1], |
| 7311 |
coords[2 * pr], coords[2 * pr + 1], |
| 7312 |
coords[2 * pl], coords[2 * pl + 1], |
| 7313 |
coords[2 * p1], coords[2 * p1 + 1]); |
| 7314 |
|
| 7315 |
if (illegal) { |
| 7316 |
triangles[a] = p1; |
| 7317 |
triangles[b] = p0; |
| 7318 |
|
| 7319 |
const hbl = halfedges[bl]; |
| 7320 |
|
| 7321 |
// edge swapped on the other side of the hull (rare); fix the halfedge reference |
| 7322 |
if (hbl === -1) { |
| 7323 |
let e = this._hullStart; |
| 7324 |
do { |
| 7325 |
if (this._hullTri[e] === bl) { |
| 7326 |
this._hullTri[e] = a; |
| 7327 |
break; |
| 7328 |
} |
| 7329 |
e = this._hullPrev[e]; |
| 7330 |
} while (e !== this._hullStart); |
| 7331 |
} |
| 7332 |
this._link(a, hbl); |
| 7333 |
this._link(b, halfedges[ar]); |
| 7334 |
this._link(ar, bl); |
| 7335 |
|
| 7336 |
const br = b0 + (b + 1) % 3; |
| 7337 |
|
| 7338 |
// don't worry about hitting the cap: it can only happen on extremely degenerate input |
| 7339 |
if (i < EDGE_STACK.length) { |
| 7340 |
EDGE_STACK[i++] = br; |
| 7341 |
} |
| 7342 |
} else { |
| 7343 |
if (i === 0) break; |
| 7344 |
a = EDGE_STACK[--i]; |
| 7345 |
} |
| 7346 |
} |
| 7347 |
|
| 7348 |
return ar; |
| 7349 |
} |
| 7350 |
|
| 7351 |
_link(a, b) { |
| 7352 |
this._halfedges[a] = b; |
| 7353 |
if (b !== -1) this._halfedges[b] = a; |
| 7354 |
} |
| 7355 |
|
| 7356 |
// add a new triangle given vertex indices and adjacent half-edge ids |
| 7357 |
_addTriangle(i0, i1, i2, a, b, c) { |
| 7358 |
const t = this.trianglesLen; |
| 7359 |
|
| 7360 |
this._triangles[t] = i0; |
| 7361 |
this._triangles[t + 1] = i1; |
| 7362 |
this._triangles[t + 2] = i2; |
| 7363 |
|
| 7364 |
this._link(t, a); |
| 7365 |
this._link(t + 1, b); |
| 7366 |
this._link(t + 2, c); |
| 7367 |
|
| 7368 |
this.trianglesLen += 3; |
| 7369 |
|
| 7370 |
return t; |
| 7371 |
} |
| 7372 |
} |
| 7373 |
|
| 7374 |
// monotonically increases with real angle, but doesn't need expensive trigonometry |
| 7375 |
function pseudoAngle(dx, dy) { |
| 7376 |
const p = dx / (Math.abs(dx) + Math.abs(dy)); |
| 7377 |
return (dy > 0 ? 3 - p : 1 + p) / 4; // [0..1] |
| 7378 |
} |
| 7379 |
|
| 7380 |
function dist(ax, ay, bx, by) { |
| 7381 |
const dx = ax - bx; |
| 7382 |
const dy = ay - by; |
| 7383 |
return dx * dx + dy * dy; |
| 7384 |
} |
| 7385 |
|
| 7386 |
function inCircle(ax, ay, bx, by, cx, cy, px, py) { |
| 7387 |
const dx = ax - px; |
| 7388 |
const dy = ay - py; |
| 7389 |
const ex = bx - px; |
| 7390 |
const ey = by - py; |
| 7391 |
const fx = cx - px; |
| 7392 |
const fy = cy - py; |
| 7393 |
|
| 7394 |
const ap = dx * dx + dy * dy; |
| 7395 |
const bp = ex * ex + ey * ey; |
| 7396 |
const cp = fx * fx + fy * fy; |
| 7397 |
|
| 7398 |
return dx * (ey * cp - bp * fy) - |
| 7399 |
dy * (ex * cp - bp * fx) + |
| 7400 |
ap * (ex * fy - ey * fx) < 0; |
| 7401 |
} |
| 7402 |
|
| 7403 |
function circumradius(ax, ay, bx, by, cx, cy) { |
| 7404 |
const dx = bx - ax; |
| 7405 |
const dy = by - ay; |
| 7406 |
const ex = cx - ax; |
| 7407 |
const ey = cy - ay; |
| 7408 |
|
| 7409 |
const bl = dx * dx + dy * dy; |
| 7410 |
const cl = ex * ex + ey * ey; |
| 7411 |
const d = 0.5 / (dx * ey - dy * ex); |
| 7412 |
|
| 7413 |
const x = (ey * bl - dy * cl) * d; |
| 7414 |
const y = (dx * cl - ex * bl) * d; |
| 7415 |
|
| 7416 |
return x * x + y * y; |
| 7417 |
} |
| 7418 |
|
| 7419 |
function circumcenter(ax, ay, bx, by, cx, cy) { |
| 7420 |
const dx = bx - ax; |
| 7421 |
const dy = by - ay; |
| 7422 |
const ex = cx - ax; |
| 7423 |
const ey = cy - ay; |
| 7424 |
|
| 7425 |
const bl = dx * dx + dy * dy; |
| 7426 |
const cl = ex * ex + ey * ey; |
| 7427 |
const d = 0.5 / (dx * ey - dy * ex); |
| 7428 |
|
| 7429 |
const x = ax + (ey * bl - dy * cl) * d; |
| 7430 |
const y = ay + (dx * cl - ex * bl) * d; |
| 7431 |
|
| 7432 |
return {x, y}; |
| 7433 |
} |
| 7434 |
|
| 7435 |
function quicksort(ids, dists, left, right) { |
| 7436 |
if (right - left <= 20) { |
| 7437 |
for (let i = left + 1; i <= right; i++) { |
| 7438 |
const temp = ids[i]; |
| 7439 |
const tempDist = dists[temp]; |
| 7440 |
let j = i - 1; |
| 7441 |
while (j >= left && dists[ids[j]] > tempDist) ids[j + 1] = ids[j--]; |
| 7442 |
ids[j + 1] = temp; |
| 7443 |
} |
| 7444 |
} else { |
| 7445 |
const median = (left + right) >> 1; |
| 7446 |
let i = left + 1; |
| 7447 |
let j = right; |
| 7448 |
swap(ids, median, i); |
| 7449 |
if (dists[ids[left]] > dists[ids[right]]) swap(ids, left, right); |
| 7450 |
if (dists[ids[i]] > dists[ids[right]]) swap(ids, i, right); |
| 7451 |
if (dists[ids[left]] > dists[ids[i]]) swap(ids, left, i); |
| 7452 |
|
| 7453 |
const temp = ids[i]; |
| 7454 |
const tempDist = dists[temp]; |
| 7455 |
while (true) { |
| 7456 |
do i++; while (dists[ids[i]] < tempDist); |
| 7457 |
do j--; while (dists[ids[j]] > tempDist); |
| 7458 |
if (j < i) break; |
| 7459 |
swap(ids, i, j); |
| 7460 |
} |
| 7461 |
ids[left + 1] = ids[j]; |
| 7462 |
ids[j] = temp; |
| 7463 |
|
| 7464 |
if (right - i + 1 >= j - left) { |
| 7465 |
quicksort(ids, dists, i, right); |
| 7466 |
quicksort(ids, dists, left, j - 1); |
| 7467 |
} else { |
| 7468 |
quicksort(ids, dists, left, j - 1); |
| 7469 |
quicksort(ids, dists, i, right); |
| 7470 |
} |
| 7471 |
} |
| 7472 |
} |
| 7473 |
|
| 7474 |
function swap(arr, i, j) { |
| 7475 |
const tmp = arr[i]; |
| 7476 |
arr[i] = arr[j]; |
| 7477 |
arr[j] = tmp; |
| 7478 |
} |
| 7479 |
|
| 7480 |
function defaultGetX(p) { |
| 7481 |
return p[0]; |
| 7482 |
} |
| 7483 |
function defaultGetY(p) { |
| 7484 |
return p[1]; |
| 7485 |
} |
| 7486 |
|
| 7487 |
const epsilon$2 = 1e-6; |
| 7488 |
|
| 7489 |
class Path { |
| 7490 |
constructor() { |
| 7491 |
this._x0 = this._y0 = // start of current subpath |
| 7492 |
this._x1 = this._y1 = null; // end of current subpath |
| 7493 |
this._ = ""; |
| 7494 |
} |
| 7495 |
moveTo(x, y) { |
| 7496 |
this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`; |
| 7497 |
} |
| 7498 |
closePath() { |
| 7499 |
if (this._x1 !== null) { |
| 7500 |
this._x1 = this._x0, this._y1 = this._y0; |
| 7501 |
this._ += "Z"; |
| 7502 |
} |
| 7503 |
} |
| 7504 |
lineTo(x, y) { |
| 7505 |
this._ += `L${this._x1 = +x},${this._y1 = +y}`; |
| 7506 |
} |
| 7507 |
arc(x, y, r) { |
| 7508 |
x = +x, y = +y, r = +r; |
| 7509 |
const x0 = x + r; |
| 7510 |
const y0 = y; |
| 7511 |
if (r < 0) throw new Error("negative radius"); |
| 7512 |
if (this._x1 === null) this._ += `M${x0},${y0}`; |
| 7513 |
else if (Math.abs(this._x1 - x0) > epsilon$2 || Math.abs(this._y1 - y0) > epsilon$2) this._ += "L" + x0 + "," + y0; |
| 7514 |
if (!r) return; |
| 7515 |
this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`; |
| 7516 |
} |
| 7517 |
rect(x, y, w, h) { |
| 7518 |
this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`; |
| 7519 |
} |
| 7520 |
value() { |
| 7521 |
return this._ || null; |
| 7522 |
} |
| 7523 |
} |
| 7524 |
|
| 7525 |
class Polygon { |
| 7526 |
constructor() { |
| 7527 |
this._ = []; |
| 7528 |
} |
| 7529 |
moveTo(x, y) { |
| 7530 |
this._.push([x, y]); |
| 7531 |
} |
| 7532 |
closePath() { |
| 7533 |
this._.push(this._[0].slice()); |
| 7534 |
} |
| 7535 |
lineTo(x, y) { |
| 7536 |
this._.push([x, y]); |
| 7537 |
} |
| 7538 |
value() { |
| 7539 |
return this._.length ? this._ : null; |
| 7540 |
} |
| 7541 |
} |
| 7542 |
|
| 7543 |
class Voronoi { |
| 7544 |
constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) { |
| 7545 |
if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds"); |
| 7546 |
this.delaunay = delaunay; |
| 7547 |
this._circumcenters = new Float64Array(delaunay.points.length * 2); |
| 7548 |
this.vectors = new Float64Array(delaunay.points.length * 2); |
| 7549 |
this.xmax = xmax, this.xmin = xmin; |
| 7550 |
this.ymax = ymax, this.ymin = ymin; |
| 7551 |
this._init(); |
| 7552 |
} |
| 7553 |
update() { |
| 7554 |
this.delaunay.update(); |
| 7555 |
this._init(); |
| 7556 |
return this; |
| 7557 |
} |
| 7558 |
_init() { |
| 7559 |
const {delaunay: {points, hull, triangles}, vectors} = this; |
| 7560 |
let bx, by; // lazily computed barycenter of the hull |
| 7561 |
|
| 7562 |
// Compute circumcenters. |
| 7563 |
const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2); |
| 7564 |
for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) { |
| 7565 |
const t1 = triangles[i] * 2; |
| 7566 |
const t2 = triangles[i + 1] * 2; |
| 7567 |
const t3 = triangles[i + 2] * 2; |
| 7568 |
const x1 = points[t1]; |
| 7569 |
const y1 = points[t1 + 1]; |
| 7570 |
const x2 = points[t2]; |
| 7571 |
const y2 = points[t2 + 1]; |
| 7572 |
const x3 = points[t3]; |
| 7573 |
const y3 = points[t3 + 1]; |
| 7574 |
|
| 7575 |
const dx = x2 - x1; |
| 7576 |
const dy = y2 - y1; |
| 7577 |
const ex = x3 - x1; |
| 7578 |
const ey = y3 - y1; |
| 7579 |
const ab = (dx * ey - dy * ex) * 2; |
| 7580 |
|
| 7581 |
if (Math.abs(ab) < 1e-9) { |
| 7582 |
// For a degenerate triangle, the circumcenter is at the infinity, in a |
| 7583 |
// direction orthogonal to the halfedge and away from the “center” of |
| 7584 |
// the diagram <bx, by>, defined as the hull’s barycenter. |
| 7585 |
if (bx === undefined) { |
| 7586 |
bx = by = 0; |
| 7587 |
for (const i of hull) bx += points[i * 2], by += points[i * 2 + 1]; |
| 7588 |
bx /= hull.length, by /= hull.length; |
| 7589 |
} |
| 7590 |
const a = 1e9 * Math.sign((bx - x1) * ey - (by - y1) * ex); |
| 7591 |
x = (x1 + x3) / 2 - a * ey; |
| 7592 |
y = (y1 + y3) / 2 + a * ex; |
| 7593 |
} else { |
| 7594 |
const d = 1 / ab; |
| 7595 |
const bl = dx * dx + dy * dy; |
| 7596 |
const cl = ex * ex + ey * ey; |
| 7597 |
x = x1 + (ey * bl - dy * cl) * d; |
| 7598 |
y = y1 + (dx * cl - ex * bl) * d; |
| 7599 |
} |
| 7600 |
circumcenters[j] = x; |
| 7601 |
circumcenters[j + 1] = y; |
| 7602 |
} |
| 7603 |
|
| 7604 |
// Compute exterior cell rays. |
| 7605 |
let h = hull[hull.length - 1]; |
| 7606 |
let p0, p1 = h * 4; |
| 7607 |
let x0, x1 = points[2 * h]; |
| 7608 |
let y0, y1 = points[2 * h + 1]; |
| 7609 |
vectors.fill(0); |
| 7610 |
for (let i = 0; i < hull.length; ++i) { |
| 7611 |
h = hull[i]; |
| 7612 |
p0 = p1, x0 = x1, y0 = y1; |
| 7613 |
p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1]; |
| 7614 |
vectors[p0 + 2] = vectors[p1] = y0 - y1; |
| 7615 |
vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0; |
| 7616 |
} |
| 7617 |
} |
| 7618 |
render(context) { |
| 7619 |
const buffer = context == null ? context = new Path : undefined; |
| 7620 |
const {delaunay: {halfedges, inedges, hull}, circumcenters, vectors} = this; |
| 7621 |
if (hull.length <= 1) return null; |
| 7622 |
for (let i = 0, n = halfedges.length; i < n; ++i) { |
| 7623 |
const j = halfedges[i]; |
| 7624 |
if (j < i) continue; |
| 7625 |
const ti = Math.floor(i / 3) * 2; |
| 7626 |
const tj = Math.floor(j / 3) * 2; |
| 7627 |
const xi = circumcenters[ti]; |
| 7628 |
const yi = circumcenters[ti + 1]; |
| 7629 |
const xj = circumcenters[tj]; |
| 7630 |
const yj = circumcenters[tj + 1]; |
| 7631 |
this._renderSegment(xi, yi, xj, yj, context); |
| 7632 |
} |
| 7633 |
let h0, h1 = hull[hull.length - 1]; |
| 7634 |
for (let i = 0; i < hull.length; ++i) { |
| 7635 |
h0 = h1, h1 = hull[i]; |
| 7636 |
const t = Math.floor(inedges[h1] / 3) * 2; |
| 7637 |
const x = circumcenters[t]; |
| 7638 |
const y = circumcenters[t + 1]; |
| 7639 |
const v = h0 * 4; |
| 7640 |
const p = this._project(x, y, vectors[v + 2], vectors[v + 3]); |
| 7641 |
if (p) this._renderSegment(x, y, p[0], p[1], context); |
| 7642 |
} |
| 7643 |
return buffer && buffer.value(); |
| 7644 |
} |
| 7645 |
renderBounds(context) { |
| 7646 |
const buffer = context == null ? context = new Path : undefined; |
| 7647 |
context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin); |
| 7648 |
return buffer && buffer.value(); |
| 7649 |
} |
| 7650 |
renderCell(i, context) { |
| 7651 |
const buffer = context == null ? context = new Path : undefined; |
| 7652 |
const points = this._clip(i); |
| 7653 |
if (points === null || !points.length) return; |
| 7654 |
context.moveTo(points[0], points[1]); |
| 7655 |
let n = points.length; |
| 7656 |
while (points[0] === points[n-2] && points[1] === points[n-1] && n > 1) n -= 2; |
| 7657 |
for (let i = 2; i < n; i += 2) { |
| 7658 |
if (points[i] !== points[i-2] || points[i+1] !== points[i-1]) |
| 7659 |
context.lineTo(points[i], points[i + 1]); |
| 7660 |
} |
| 7661 |
context.closePath(); |
| 7662 |
return buffer && buffer.value(); |
| 7663 |
} |
| 7664 |
*cellPolygons() { |
| 7665 |
const {delaunay: {points}} = this; |
| 7666 |
for (let i = 0, n = points.length / 2; i < n; ++i) { |
| 7667 |
const cell = this.cellPolygon(i); |
| 7668 |
if (cell) cell.index = i, yield cell; |
| 7669 |
} |
| 7670 |
} |
| 7671 |
cellPolygon(i) { |
| 7672 |
const polygon = new Polygon; |
| 7673 |
this.renderCell(i, polygon); |
| 7674 |
return polygon.value(); |
| 7675 |
} |
| 7676 |
_renderSegment(x0, y0, x1, y1, context) { |
| 7677 |
let S; |
| 7678 |
const c0 = this._regioncode(x0, y0); |
| 7679 |
const c1 = this._regioncode(x1, y1); |
| 7680 |
if (c0 === 0 && c1 === 0) { |
| 7681 |
context.moveTo(x0, y0); |
| 7682 |
context.lineTo(x1, y1); |
| 7683 |
} else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) { |
| 7684 |
context.moveTo(S[0], S[1]); |
| 7685 |
context.lineTo(S[2], S[3]); |
| 7686 |
} |
| 7687 |
} |
| 7688 |
contains(i, x, y) { |
| 7689 |
if ((x = +x, x !== x) || (y = +y, y !== y)) return false; |
| 7690 |
return this.delaunay._step(i, x, y) === i; |
| 7691 |
} |
| 7692 |
*neighbors(i) { |
| 7693 |
const ci = this._clip(i); |
| 7694 |
if (ci) for (const j of this.delaunay.neighbors(i)) { |
| 7695 |
const cj = this._clip(j); |
| 7696 |
// find the common edge |
| 7697 |
if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) { |
| 7698 |
for (let aj = 0, lj = cj.length; aj < lj; aj += 2) { |
| 7699 |
if (ci[ai] === cj[aj] |
| 7700 |
&& ci[ai + 1] === cj[aj + 1] |
| 7701 |
&& ci[(ai + 2) % li] === cj[(aj + lj - 2) % lj] |
| 7702 |
&& ci[(ai + 3) % li] === cj[(aj + lj - 1) % lj]) { |
| 7703 |
yield j; |
| 7704 |
break loop; |
| 7705 |
} |
| 7706 |
} |
| 7707 |
} |
| 7708 |
} |
| 7709 |
} |
| 7710 |
_cell(i) { |
| 7711 |
const {circumcenters, delaunay: {inedges, halfedges, triangles}} = this; |
| 7712 |
const e0 = inedges[i]; |
| 7713 |
if (e0 === -1) return null; // coincident point |
| 7714 |
const points = []; |
| 7715 |
let e = e0; |
| 7716 |
do { |
| 7717 |
const t = Math.floor(e / 3); |
| 7718 |
points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]); |
| 7719 |
e = e % 3 === 2 ? e - 2 : e + 1; |
| 7720 |
if (triangles[e] !== i) break; // bad triangulation |
| 7721 |
e = halfedges[e]; |
| 7722 |
} while (e !== e0 && e !== -1); |
| 7723 |
return points; |
| 7724 |
} |
| 7725 |
_clip(i) { |
| 7726 |
// degenerate case (1 valid point: return the box) |
| 7727 |
if (i === 0 && this.delaunay.hull.length === 1) { |
| 7728 |
return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin]; |
| 7729 |
} |
| 7730 |
const points = this._cell(i); |
| 7731 |
if (points === null) return null; |
| 7732 |
const {vectors: V} = this; |
| 7733 |
const v = i * 4; |
| 7734 |
return this._simplify(V[v] || V[v + 1] |
| 7735 |
? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3]) |
| 7736 |
: this._clipFinite(i, points)); |
| 7737 |
} |
| 7738 |
_clipFinite(i, points) { |
| 7739 |
const n = points.length; |
| 7740 |
let P = null; |
| 7741 |
let x0, y0, x1 = points[n - 2], y1 = points[n - 1]; |
| 7742 |
let c0, c1 = this._regioncode(x1, y1); |
| 7743 |
let e0, e1 = 0; |
| 7744 |
for (let j = 0; j < n; j += 2) { |
| 7745 |
x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1]; |
| 7746 |
c0 = c1, c1 = this._regioncode(x1, y1); |
| 7747 |
if (c0 === 0 && c1 === 0) { |
| 7748 |
e0 = e1, e1 = 0; |
| 7749 |
if (P) P.push(x1, y1); |
| 7750 |
else P = [x1, y1]; |
| 7751 |
} else { |
| 7752 |
let S, sx0, sy0, sx1, sy1; |
| 7753 |
if (c0 === 0) { |
| 7754 |
if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue; |
| 7755 |
[sx0, sy0, sx1, sy1] = S; |
| 7756 |
} else { |
| 7757 |
if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue; |
| 7758 |
[sx1, sy1, sx0, sy0] = S; |
| 7759 |
e0 = e1, e1 = this._edgecode(sx0, sy0); |
| 7760 |
if (e0 && e1) this._edge(i, e0, e1, P, P.length); |
| 7761 |
if (P) P.push(sx0, sy0); |
| 7762 |
else P = [sx0, sy0]; |
| 7763 |
} |
| 7764 |
e0 = e1, e1 = this._edgecode(sx1, sy1); |
| 7765 |
if (e0 && e1) this._edge(i, e0, e1, P, P.length); |
| 7766 |
if (P) P.push(sx1, sy1); |
| 7767 |
else P = [sx1, sy1]; |
| 7768 |
} |
| 7769 |
} |
| 7770 |
if (P) { |
| 7771 |
e0 = e1, e1 = this._edgecode(P[0], P[1]); |
| 7772 |
if (e0 && e1) this._edge(i, e0, e1, P, P.length); |
| 7773 |
} else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) { |
| 7774 |
return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin]; |
| 7775 |
} |
| 7776 |
return P; |
| 7777 |
} |
| 7778 |
_clipSegment(x0, y0, x1, y1, c0, c1) { |
| 7779 |
// for more robustness, always consider the segment in the same order |
| 7780 |
const flip = c0 < c1; |
| 7781 |
if (flip) [x0, y0, x1, y1, c0, c1] = [x1, y1, x0, y0, c1, c0]; |
| 7782 |
while (true) { |
| 7783 |
if (c0 === 0 && c1 === 0) return flip ? [x1, y1, x0, y0] : [x0, y0, x1, y1]; |
| 7784 |
if (c0 & c1) return null; |
| 7785 |
let x, y, c = c0 || c1; |
| 7786 |
if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax; |
| 7787 |
else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin; |
| 7788 |
else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax; |
| 7789 |
else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin; |
| 7790 |
if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0); |
| 7791 |
else x1 = x, y1 = y, c1 = this._regioncode(x1, y1); |
| 7792 |
} |
| 7793 |
} |
| 7794 |
_clipInfinite(i, points, vx0, vy0, vxn, vyn) { |
| 7795 |
let P = Array.from(points), p; |
| 7796 |
if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]); |
| 7797 |
if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]); |
| 7798 |
if (P = this._clipFinite(i, P)) { |
| 7799 |
for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) { |
| 7800 |
c0 = c1, c1 = this._edgecode(P[j], P[j + 1]); |
| 7801 |
if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length; |
| 7802 |
} |
| 7803 |
} else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) { |
| 7804 |
P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax]; |
| 7805 |
} |
| 7806 |
return P; |
| 7807 |
} |
| 7808 |
_edge(i, e0, e1, P, j) { |
| 7809 |
while (e0 !== e1) { |
| 7810 |
let x, y; |
| 7811 |
switch (e0) { |
| 7812 |
case 0b0101: e0 = 0b0100; continue; // top-left |
| 7813 |
case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break; // top |
| 7814 |
case 0b0110: e0 = 0b0010; continue; // top-right |
| 7815 |
case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break; // right |
| 7816 |
case 0b1010: e0 = 0b1000; continue; // bottom-right |
| 7817 |
case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break; // bottom |
| 7818 |
case 0b1001: e0 = 0b0001; continue; // bottom-left |
| 7819 |
case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break; // left |
| 7820 |
} |
| 7821 |
// Note: this implicitly checks for out of bounds: if P[j] or P[j+1] are |
| 7822 |
// undefined, the conditional statement will be executed. |
| 7823 |
if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) { |
| 7824 |
P.splice(j, 0, x, y), j += 2; |
| 7825 |
} |
| 7826 |
} |
| 7827 |
return j; |
| 7828 |
} |
| 7829 |
_project(x0, y0, vx, vy) { |
| 7830 |
let t = Infinity, c, x, y; |
| 7831 |
if (vy < 0) { // top |
| 7832 |
if (y0 <= this.ymin) return null; |
| 7833 |
if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx; |
| 7834 |
} else if (vy > 0) { // bottom |
| 7835 |
if (y0 >= this.ymax) return null; |
| 7836 |
if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx; |
| 7837 |
} |
| 7838 |
if (vx > 0) { // right |
| 7839 |
if (x0 >= this.xmax) return null; |
| 7840 |
if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy; |
| 7841 |
} else if (vx < 0) { // left |
| 7842 |
if (x0 <= this.xmin) return null; |
| 7843 |
if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy; |
| 7844 |
} |
| 7845 |
return [x, y]; |
| 7846 |
} |
| 7847 |
_edgecode(x, y) { |
| 7848 |
return (x === this.xmin ? 0b0001 |
| 7849 |
: x === this.xmax ? 0b0010 : 0b0000) |
| 7850 |
| (y === this.ymin ? 0b0100 |
| 7851 |
: y === this.ymax ? 0b1000 : 0b0000); |
| 7852 |
} |
| 7853 |
_regioncode(x, y) { |
| 7854 |
return (x < this.xmin ? 0b0001 |
| 7855 |
: x > this.xmax ? 0b0010 : 0b0000) |
| 7856 |
| (y < this.ymin ? 0b0100 |
| 7857 |
: y > this.ymax ? 0b1000 : 0b0000); |
| 7858 |
} |
| 7859 |
_simplify(P) { |
| 7860 |
if (P && P.length > 4) { |
| 7861 |
for (let i = 0; i < P.length; i+= 2) { |
| 7862 |
const j = (i + 2) % P.length, k = (i + 4) % P.length; |
| 7863 |
if (P[i] === P[j] && P[j] === P[k] || P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1]) { |
| 7864 |
P.splice(j, 2), i -= 2; |
| 7865 |
} |
| 7866 |
} |
| 7867 |
if (!P.length) P = null; |
| 7868 |
} |
| 7869 |
return P; |
| 7870 |
} |
| 7871 |
} |
| 7872 |
|
| 7873 |
const tau$2 = 2 * Math.PI, pow$2 = Math.pow; |
| 7874 |
|
| 7875 |
function pointX(p) { |
| 7876 |
return p[0]; |
| 7877 |
} |
| 7878 |
|
| 7879 |
function pointY(p) { |
| 7880 |
return p[1]; |
| 7881 |
} |
| 7882 |
|
| 7883 |
// A triangulation is collinear if all its triangles have a non-null area |
| 7884 |
function collinear(d) { |
| 7885 |
const {triangles, coords} = d; |
| 7886 |
for (let i = 0; i < triangles.length; i += 3) { |
| 7887 |
const a = 2 * triangles[i], |
| 7888 |
b = 2 * triangles[i + 1], |
| 7889 |
c = 2 * triangles[i + 2], |
| 7890 |
cross = (coords[c] - coords[a]) * (coords[b + 1] - coords[a + 1]) |
| 7891 |
- (coords[b] - coords[a]) * (coords[c + 1] - coords[a + 1]); |
| 7892 |
if (cross > 1e-10) return false; |
| 7893 |
} |
| 7894 |
return true; |
| 7895 |
} |
| 7896 |
|
| 7897 |
function jitter(x, y, r) { |
| 7898 |
return [x + Math.sin(x + y) * r, y + Math.cos(x - y) * r]; |
| 7899 |
} |
| 7900 |
|
| 7901 |
class Delaunay { |
| 7902 |
static from(points, fx = pointX, fy = pointY, that) { |
| 7903 |
return new Delaunay("length" in points |
| 7904 |
? flatArray(points, fx, fy, that) |
| 7905 |
: Float64Array.from(flatIterable(points, fx, fy, that))); |
| 7906 |
} |
| 7907 |
constructor(points) { |
| 7908 |
this._delaunator = new Delaunator(points); |
| 7909 |
this.inedges = new Int32Array(points.length / 2); |
| 7910 |
this._hullIndex = new Int32Array(points.length / 2); |
| 7911 |
this.points = this._delaunator.coords; |
| 7912 |
this._init(); |
| 7913 |
} |
| 7914 |
update() { |
| 7915 |
this._delaunator.update(); |
| 7916 |
this._init(); |
| 7917 |
return this; |
| 7918 |
} |
| 7919 |
_init() { |
| 7920 |
const d = this._delaunator, points = this.points; |
| 7921 |
|
| 7922 |
// check for collinear |
| 7923 |
if (d.hull && d.hull.length > 2 && collinear(d)) { |
| 7924 |
this.collinear = Int32Array.from({length: points.length/2}, (_,i) => i) |
| 7925 |
.sort((i, j) => points[2 * i] - points[2 * j] || points[2 * i + 1] - points[2 * j + 1]); // for exact neighbors |
| 7926 |
const e = this.collinear[0], f = this.collinear[this.collinear.length - 1], |
| 7927 |
bounds = [ points[2 * e], points[2 * e + 1], points[2 * f], points[2 * f + 1] ], |
| 7928 |
r = 1e-8 * Math.hypot(bounds[3] - bounds[1], bounds[2] - bounds[0]); |
| 7929 |
for (let i = 0, n = points.length / 2; i < n; ++i) { |
| 7930 |
const p = jitter(points[2 * i], points[2 * i + 1], r); |
| 7931 |
points[2 * i] = p[0]; |
| 7932 |
points[2 * i + 1] = p[1]; |
| 7933 |
} |
| 7934 |
this._delaunator = new Delaunator(points); |
| 7935 |
} else { |
| 7936 |
delete this.collinear; |
| 7937 |
} |
| 7938 |
|
| 7939 |
const halfedges = this.halfedges = this._delaunator.halfedges; |
| 7940 |
const hull = this.hull = this._delaunator.hull; |
| 7941 |
const triangles = this.triangles = this._delaunator.triangles; |
| 7942 |
const inedges = this.inedges.fill(-1); |
| 7943 |
const hullIndex = this._hullIndex.fill(-1); |
| 7944 |
|
| 7945 |
// Compute an index from each point to an (arbitrary) incoming halfedge |
| 7946 |
// Used to give the first neighbor of each point; for this reason, |
| 7947 |
// on the hull we give priority to exterior halfedges |
| 7948 |
for (let e = 0, n = halfedges.length; e < n; ++e) { |
| 7949 |
const p = triangles[e % 3 === 2 ? e - 2 : e + 1]; |
| 7950 |
if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e; |
| 7951 |
} |
| 7952 |
for (let i = 0, n = hull.length; i < n; ++i) { |
| 7953 |
hullIndex[hull[i]] = i; |
| 7954 |
} |
| 7955 |
|
| 7956 |
// degenerate case: 1 or 2 (distinct) points |
| 7957 |
if (hull.length <= 2 && hull.length > 0) { |
| 7958 |
this.triangles = new Int32Array(3).fill(-1); |
| 7959 |
this.halfedges = new Int32Array(3).fill(-1); |
| 7960 |
this.triangles[0] = hull[0]; |
| 7961 |
inedges[hull[0]] = 1; |
| 7962 |
if (hull.length === 2) { |
| 7963 |
inedges[hull[1]] = 0; |
| 7964 |
this.triangles[1] = hull[1]; |
| 7965 |
this.triangles[2] = hull[1]; |
| 7966 |
} |
| 7967 |
} |
| 7968 |
} |
| 7969 |
voronoi(bounds) { |
| 7970 |
return new Voronoi(this, bounds); |
| 7971 |
} |
| 7972 |
*neighbors(i) { |
| 7973 |
const {inedges, hull, _hullIndex, halfedges, triangles, collinear} = this; |
| 7974 |
|
| 7975 |
// degenerate case with several collinear points |
| 7976 |
if (collinear) { |
| 7977 |
const l = collinear.indexOf(i); |
| 7978 |
if (l > 0) yield collinear[l - 1]; |
| 7979 |
if (l < collinear.length - 1) yield collinear[l + 1]; |
| 7980 |
return; |
| 7981 |
} |
| 7982 |
|
| 7983 |
const e0 = inedges[i]; |
| 7984 |
if (e0 === -1) return; // coincident point |
| 7985 |
let e = e0, p0 = -1; |
| 7986 |
do { |
| 7987 |
yield p0 = triangles[e]; |
| 7988 |
e = e % 3 === 2 ? e - 2 : e + 1; |
| 7989 |
if (triangles[e] !== i) return; // bad triangulation |
| 7990 |
e = halfedges[e]; |
| 7991 |
if (e === -1) { |
| 7992 |
const p = hull[(_hullIndex[i] + 1) % hull.length]; |
| 7993 |
if (p !== p0) yield p; |
| 7994 |
return; |
| 7995 |
} |
| 7996 |
} while (e !== e0); |
| 7997 |
} |
| 7998 |
find(x, y, i = 0) { |
| 7999 |
if ((x = +x, x !== x) || (y = +y, y !== y)) return -1; |
| 8000 |
const i0 = i; |
| 8001 |
let c; |
| 8002 |
while ((c = this._step(i, x, y)) >= 0 && c !== i && c !== i0) i = c; |
| 8003 |
return c; |
| 8004 |
} |
| 8005 |
_step(i, x, y) { |
| 8006 |
const {inedges, hull, _hullIndex, halfedges, triangles, points} = this; |
| 8007 |
if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1); |
| 8008 |
let c = i; |
| 8009 |
let dc = pow$2(x - points[i * 2], 2) + pow$2(y - points[i * 2 + 1], 2); |
| 8010 |
const e0 = inedges[i]; |
| 8011 |
let e = e0; |
| 8012 |
do { |
| 8013 |
let t = triangles[e]; |
| 8014 |
const dt = pow$2(x - points[t * 2], 2) + pow$2(y - points[t * 2 + 1], 2); |
| 8015 |
if (dt < dc) dc = dt, c = t; |
| 8016 |
e = e % 3 === 2 ? e - 2 : e + 1; |
| 8017 |
if (triangles[e] !== i) break; // bad triangulation |
| 8018 |
e = halfedges[e]; |
| 8019 |
if (e === -1) { |
| 8020 |
e = hull[(_hullIndex[i] + 1) % hull.length]; |
| 8021 |
if (e !== t) { |
| 8022 |
if (pow$2(x - points[e * 2], 2) + pow$2(y - points[e * 2 + 1], 2) < dc) return e; |
| 8023 |
} |
| 8024 |
break; |
| 8025 |
} |
| 8026 |
} while (e !== e0); |
| 8027 |
return c; |
| 8028 |
} |
| 8029 |
render(context) { |
| 8030 |
const buffer = context == null ? context = new Path : undefined; |
| 8031 |
const {points, halfedges, triangles} = this; |
| 8032 |
for (let i = 0, n = halfedges.length; i < n; ++i) { |
| 8033 |
const j = halfedges[i]; |
| 8034 |
if (j < i) continue; |
| 8035 |
const ti = triangles[i] * 2; |
| 8036 |
const tj = triangles[j] * 2; |
| 8037 |
context.moveTo(points[ti], points[ti + 1]); |
| 8038 |
context.lineTo(points[tj], points[tj + 1]); |
| 8039 |
} |
| 8040 |
this.renderHull(context); |
| 8041 |
return buffer && buffer.value(); |
| 8042 |
} |
| 8043 |
renderPoints(context, r) { |
| 8044 |
if (r === undefined && (!context || typeof context.moveTo !== "function")) r = context, context = null; |
| 8045 |
r = r == undefined ? 2 : +r; |
| 8046 |
const buffer = context == null ? context = new Path : undefined; |
| 8047 |
const {points} = this; |
| 8048 |
for (let i = 0, n = points.length; i < n; i += 2) { |
| 8049 |
const x = points[i], y = points[i + 1]; |
| 8050 |
context.moveTo(x + r, y); |
| 8051 |
context.arc(x, y, r, 0, tau$2); |
| 8052 |
} |
| 8053 |
return buffer && buffer.value(); |
| 8054 |
} |
| 8055 |
renderHull(context) { |
| 8056 |
const buffer = context == null ? context = new Path : undefined; |
| 8057 |
const {hull, points} = this; |
| 8058 |
const h = hull[0] * 2, n = hull.length; |
| 8059 |
context.moveTo(points[h], points[h + 1]); |
| 8060 |
for (let i = 1; i < n; ++i) { |
| 8061 |
const h = 2 * hull[i]; |
| 8062 |
context.lineTo(points[h], points[h + 1]); |
| 8063 |
} |
| 8064 |
context.closePath(); |
| 8065 |
return buffer && buffer.value(); |
| 8066 |
} |
| 8067 |
hullPolygon() { |
| 8068 |
const polygon = new Polygon; |
| 8069 |
this.renderHull(polygon); |
| 8070 |
return polygon.value(); |
| 8071 |
} |
| 8072 |
renderTriangle(i, context) { |
| 8073 |
const buffer = context == null ? context = new Path : undefined; |
| 8074 |
const {points, triangles} = this; |
| 8075 |
const t0 = triangles[i *= 3] * 2; |
| 8076 |
const t1 = triangles[i + 1] * 2; |
| 8077 |
const t2 = triangles[i + 2] * 2; |
| 8078 |
context.moveTo(points[t0], points[t0 + 1]); |
| 8079 |
context.lineTo(points[t1], points[t1 + 1]); |
| 8080 |
context.lineTo(points[t2], points[t2 + 1]); |
| 8081 |
context.closePath(); |
| 8082 |
return buffer && buffer.value(); |
| 8083 |
} |
| 8084 |
*trianglePolygons() { |
| 8085 |
const {triangles} = this; |
| 8086 |
for (let i = 0, n = triangles.length / 3; i < n; ++i) { |
| 8087 |
yield this.trianglePolygon(i); |
| 8088 |
} |
| 8089 |
} |
| 8090 |
trianglePolygon(i) { |
| 8091 |
const polygon = new Polygon; |
| 8092 |
this.renderTriangle(i, polygon); |
| 8093 |
return polygon.value(); |
| 8094 |
} |
| 8095 |
} |
| 8096 |
|
| 8097 |
function flatArray(points, fx, fy, that) { |
| 8098 |
const n = points.length; |
| 8099 |
const array = new Float64Array(n * 2); |
| 8100 |
for (let i = 0; i < n; ++i) { |
| 8101 |
const p = points[i]; |
| 8102 |
array[i * 2] = fx.call(that, p, i, points); |
| 8103 |
array[i * 2 + 1] = fy.call(that, p, i, points); |
| 8104 |
} |
| 8105 |
return array; |
| 8106 |
} |
| 8107 |
|
| 8108 |
function* flatIterable(points, fx, fy, that) { |
| 8109 |
let i = 0; |
| 8110 |
for (const p of points) { |
| 8111 |
yield fx.call(that, p, i, points); |
| 8112 |
yield fy.call(that, p, i, points); |
| 8113 |
++i; |
| 8114 |
} |
| 8115 |
} |
| 8116 |
|
| 8117 |
var EOL = {}, |
| 8118 |
EOF = {}, |
| 8119 |
QUOTE = 34, |
| 8120 |
NEWLINE = 10, |
| 8121 |
RETURN = 13; |
| 8122 |
|
| 8123 |
function objectConverter(columns) { |
| 8124 |
return new Function("d", "return {" + columns.map(function(name, i) { |
| 8125 |
return JSON.stringify(name) + ": d[" + i + "] || \"\""; |
| 8126 |
}).join(",") + "}"); |
| 8127 |
} |
| 8128 |
|
| 8129 |
function customConverter(columns, f) { |
| 8130 |
var object = objectConverter(columns); |
| 8131 |
return function(row, i) { |
| 8132 |
return f(object(row), i, columns); |
| 8133 |
}; |
| 8134 |
} |
| 8135 |
|
| 8136 |
// Compute unique columns in order of discovery. |
| 8137 |
function inferColumns(rows) { |
| 8138 |
var columnSet = Object.create(null), |
| 8139 |
columns = []; |
| 8140 |
|
| 8141 |
rows.forEach(function(row) { |
| 8142 |
for (var column in row) { |
| 8143 |
if (!(column in columnSet)) { |
| 8144 |
columns.push(columnSet[column] = column); |
| 8145 |
} |
| 8146 |
} |
| 8147 |
}); |
| 8148 |
|
| 8149 |
return columns; |
| 8150 |
} |
| 8151 |
|
| 8152 |
function pad$1(value, width) { |
| 8153 |
var s = value + "", length = s.length; |
| 8154 |
return length < width ? new Array(width - length + 1).join(0) + s : s; |
| 8155 |
} |
| 8156 |
|
| 8157 |
function formatYear$1(year) { |
| 8158 |
return year < 0 ? "-" + pad$1(-year, 6) |
| 8159 |
: year > 9999 ? "+" + pad$1(year, 6) |
| 8160 |
: pad$1(year, 4); |
| 8161 |
} |
| 8162 |
|
| 8163 |
function formatDate(date) { |
| 8164 |
var hours = date.getUTCHours(), |
| 8165 |
minutes = date.getUTCMinutes(), |
| 8166 |
seconds = date.getUTCSeconds(), |
| 8167 |
milliseconds = date.getUTCMilliseconds(); |
| 8168 |
return isNaN(date) ? "Invalid Date" |
| 8169 |
: formatYear$1(date.getUTCFullYear()) + "-" + pad$1(date.getUTCMonth() + 1, 2) + "-" + pad$1(date.getUTCDate(), 2) |
| 8170 |
+ (milliseconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "." + pad$1(milliseconds, 3) + "Z" |
| 8171 |
: seconds ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + ":" + pad$1(seconds, 2) + "Z" |
| 8172 |
: minutes || hours ? "T" + pad$1(hours, 2) + ":" + pad$1(minutes, 2) + "Z" |
| 8173 |
: ""); |
| 8174 |
} |
| 8175 |
|
| 8176 |
function dsvFormat(delimiter) { |
| 8177 |
var reFormat = new RegExp("[\"" + delimiter + "\n\r]"), |
| 8178 |
DELIMITER = delimiter.charCodeAt(0); |
| 8179 |
|
| 8180 |
function parse(text, f) { |
| 8181 |
var convert, columns, rows = parseRows(text, function(row, i) { |
| 8182 |
if (convert) return convert(row, i - 1); |
| 8183 |
columns = row, convert = f ? customConverter(row, f) : objectConverter(row); |
| 8184 |
}); |
| 8185 |
rows.columns = columns || []; |
| 8186 |
return rows; |
| 8187 |
} |
| 8188 |
|
| 8189 |
function parseRows(text, f) { |
| 8190 |
var rows = [], // output rows |
| 8191 |
N = text.length, |
| 8192 |
I = 0, // current character index |
| 8193 |
n = 0, // current line number |
| 8194 |
t, // current token |
| 8195 |
eof = N <= 0, // current token followed by EOF? |
| 8196 |
eol = false; // current token followed by EOL? |
| 8197 |
|
| 8198 |
// Strip the trailing newline. |
| 8199 |
if (text.charCodeAt(N - 1) === NEWLINE) --N; |
| 8200 |
if (text.charCodeAt(N - 1) === RETURN) --N; |
| 8201 |
|
| 8202 |
function token() { |
| 8203 |
if (eof) return EOF; |
| 8204 |
if (eol) return eol = false, EOL; |
| 8205 |
|
| 8206 |
// Unescape quotes. |
| 8207 |
var i, j = I, c; |
| 8208 |
if (text.charCodeAt(j) === QUOTE) { |
| 8209 |
while (I++ < N && text.charCodeAt(I) !== QUOTE || text.charCodeAt(++I) === QUOTE); |
| 8210 |
if ((i = I) >= N) eof = true; |
| 8211 |
else if ((c = text.charCodeAt(I++)) === NEWLINE) eol = true; |
| 8212 |
else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; } |
| 8213 |
return text.slice(j + 1, i - 1).replace(/""/g, "\""); |
| 8214 |
} |
| 8215 |
|
| 8216 |
// Find next delimiter or newline. |
| 8217 |
while (I < N) { |
| 8218 |
if ((c = text.charCodeAt(i = I++)) === NEWLINE) eol = true; |
| 8219 |
else if (c === RETURN) { eol = true; if (text.charCodeAt(I) === NEWLINE) ++I; } |
| 8220 |
else if (c !== DELIMITER) continue; |
| 8221 |
return text.slice(j, i); |
| 8222 |
} |
| 8223 |
|
| 8224 |
// Return last token before EOF. |
| 8225 |
return eof = true, text.slice(j, N); |
| 8226 |
} |
| 8227 |
|
| 8228 |
while ((t = token()) !== EOF) { |
| 8229 |
var row = []; |
| 8230 |
while (t !== EOL && t !== EOF) row.push(t), t = token(); |
| 8231 |
if (f && (row = f(row, n++)) == null) continue; |
| 8232 |
rows.push(row); |
| 8233 |
} |
| 8234 |
|
| 8235 |
return rows; |
| 8236 |
} |
| 8237 |
|
| 8238 |
function preformatBody(rows, columns) { |
| 8239 |
return rows.map(function(row) { |
| 8240 |
return columns.map(function(column) { |
| 8241 |
return formatValue(row[column]); |
| 8242 |
}).join(delimiter); |
| 8243 |
}); |
| 8244 |
} |
| 8245 |
|
| 8246 |
function format(rows, columns) { |
| 8247 |
if (columns == null) columns = inferColumns(rows); |
| 8248 |
return [columns.map(formatValue).join(delimiter)].concat(preformatBody(rows, columns)).join("\n"); |
| 8249 |
} |
| 8250 |
|
| 8251 |
function formatBody(rows, columns) { |
| 8252 |
if (columns == null) columns = inferColumns(rows); |
| 8253 |
return preformatBody(rows, columns).join("\n"); |
| 8254 |
} |
| 8255 |
|
| 8256 |
function formatRows(rows) { |
| 8257 |
return rows.map(formatRow).join("\n"); |
| 8258 |
} |
| 8259 |
|
| 8260 |
function formatRow(row) { |
| 8261 |
return row.map(formatValue).join(delimiter); |
| 8262 |
} |
| 8263 |
|
| 8264 |
function formatValue(value) { |
| 8265 |
return value == null ? "" |
| 8266 |
: value instanceof Date ? formatDate(value) |
| 8267 |
: reFormat.test(value += "") ? "\"" + value.replace(/"/g, "\"\"") + "\"" |
| 8268 |
: value; |
| 8269 |
} |
| 8270 |
|
| 8271 |
return { |
| 8272 |
parse: parse, |
| 8273 |
parseRows: parseRows, |
| 8274 |
format: format, |
| 8275 |
formatBody: formatBody, |
| 8276 |
formatRows: formatRows, |
| 8277 |
formatRow: formatRow, |
| 8278 |
formatValue: formatValue |
| 8279 |
}; |
| 8280 |
} |
| 8281 |
|
| 8282 |
var csv$1 = dsvFormat(","); |
| 8283 |
|
| 8284 |
var csvParse = csv$1.parse; |
| 8285 |
var csvParseRows = csv$1.parseRows; |
| 8286 |
var csvFormat = csv$1.format; |
| 8287 |
var csvFormatBody = csv$1.formatBody; |
| 8288 |
var csvFormatRows = csv$1.formatRows; |
| 8289 |
var csvFormatRow = csv$1.formatRow; |
| 8290 |
var csvFormatValue = csv$1.formatValue; |
| 8291 |
|
| 8292 |
var tsv$1 = dsvFormat("\t"); |
| 8293 |
|
| 8294 |
var tsvParse = tsv$1.parse; |
| 8295 |
var tsvParseRows = tsv$1.parseRows; |
| 8296 |
var tsvFormat = tsv$1.format; |
| 8297 |
var tsvFormatBody = tsv$1.formatBody; |
| 8298 |
var tsvFormatRows = tsv$1.formatRows; |
| 8299 |
var tsvFormatRow = tsv$1.formatRow; |
| 8300 |
var tsvFormatValue = tsv$1.formatValue; |
| 8301 |
|
| 8302 |
function autoType(object) { |
| 8303 |
for (var key in object) { |
| 8304 |
var value = object[key].trim(), number, m; |
| 8305 |
if (!value) value = null; |
| 8306 |
else if (value === "true") value = true; |
| 8307 |
else if (value === "false") value = false; |
| 8308 |
else if (value === "NaN") value = NaN; |
| 8309 |
else if (!isNaN(number = +value)) value = number; |
| 8310 |
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})?)?$/)) { |
| 8311 |
if (fixtz && !!m[4] && !m[7]) value = value.replace(/-/g, "/").replace(/T/, " "); |
| 8312 |
value = new Date(value); |
| 8313 |
} |
| 8314 |
else continue; |
| 8315 |
object[key] = value; |
| 8316 |
} |
| 8317 |
return object; |
| 8318 |
} |
| 8319 |
|
| 8320 |
// https://github.com/d3/d3-dsv/issues/45 |
| 8321 |
const fixtz = new Date("2019-01-01T00:00").getHours() || new Date("2019-07-01T00:00").getHours(); |
| 8322 |
|
| 8323 |
function responseBlob(response) { |
| 8324 |
if (!response.ok) throw new Error(response.status + " " + response.statusText); |
| 8325 |
return response.blob(); |
| 8326 |
} |
| 8327 |
|
| 8328 |
function blob(input, init) { |
| 8329 |
return fetch(input, init).then(responseBlob); |
| 8330 |
} |
| 8331 |
|
| 8332 |
function responseArrayBuffer(response) { |
| 8333 |
if (!response.ok) throw new Error(response.status + " " + response.statusText); |
| 8334 |
return response.arrayBuffer(); |
| 8335 |
} |
| 8336 |
|
| 8337 |
function buffer(input, init) { |
| 8338 |
return fetch(input, init).then(responseArrayBuffer); |
| 8339 |
} |
| 8340 |
|
| 8341 |
function responseText(response) { |
| 8342 |
if (!response.ok) throw new Error(response.status + " " + response.statusText); |
| 8343 |
return response.text(); |
| 8344 |
} |
| 8345 |
|
| 8346 |
function text(input, init) { |
| 8347 |
return fetch(input, init).then(responseText); |
| 8348 |
} |
| 8349 |
|
| 8350 |
function dsvParse(parse) { |
| 8351 |
return function(input, init, row) { |
| 8352 |
if (arguments.length === 2 && typeof init === "function") row = init, init = undefined; |
| 8353 |
return text(input, init).then(function(response) { |
| 8354 |
return parse(response, row); |
| 8355 |
}); |
| 8356 |
}; |
| 8357 |
} |
| 8358 |
|
| 8359 |
function dsv(delimiter, input, init, row) { |
| 8360 |
if (arguments.length === 3 && typeof init === "function") row = init, init = undefined; |
| 8361 |
var format = dsvFormat(delimiter); |
| 8362 |
return text(input, init).then(function(response) { |
| 8363 |
return format.parse(response, row); |
| 8364 |
}); |
| 8365 |
} |
| 8366 |
|
| 8367 |
var csv = dsvParse(csvParse); |
| 8368 |
var tsv = dsvParse(tsvParse); |
| 8369 |
|
| 8370 |
function image(input, init) { |
| 8371 |
return new Promise(function(resolve, reject) { |
| 8372 |
var image = new Image; |
| 8373 |
for (var key in init) image[key] = init[key]; |
| 8374 |
image.onerror = reject; |
| 8375 |
image.onload = function() { resolve(image); }; |
| 8376 |
image.src = input; |
| 8377 |
}); |
| 8378 |
} |
| 8379 |
|
| 8380 |
function responseJson(response) { |
| 8381 |
if (!response.ok) throw new Error(response.status + " " + response.statusText); |
| 8382 |
if (response.status === 204 || response.status === 205) return; |
| 8383 |
return response.json(); |
| 8384 |
} |
| 8385 |
|
| 8386 |
function json(input, init) { |
| 8387 |
return fetch(input, init).then(responseJson); |
| 8388 |
} |
| 8389 |
|
| 8390 |
function parser(type) { |
| 8391 |
return (input, init) => text(input, init) |
| 8392 |
.then(text => (new DOMParser).parseFromString(text, type)); |
| 8393 |
} |
| 8394 |
|
| 8395 |
var xml = parser("application/xml"); |
| 8396 |
|
| 8397 |
var html = parser("text/html"); |
| 8398 |
|
| 8399 |
var svg = parser("image/svg+xml"); |
| 8400 |
|
| 8401 |
function center(x, y) { |
| 8402 |
var nodes, strength = 1; |
| 8403 |
|
| 8404 |
if (x == null) x = 0; |
| 8405 |
if (y == null) y = 0; |
| 8406 |
|
| 8407 |
function force() { |
| 8408 |
var i, |
| 8409 |
n = nodes.length, |
| 8410 |
node, |
| 8411 |
sx = 0, |
| 8412 |
sy = 0; |
| 8413 |
|
| 8414 |
for (i = 0; i < n; ++i) { |
| 8415 |
node = nodes[i], sx += node.x, sy += node.y; |
| 8416 |
} |
| 8417 |
|
| 8418 |
for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0; i < n; ++i) { |
| 8419 |
node = nodes[i], node.x -= sx, node.y -= sy; |
| 8420 |
} |
| 8421 |
} |
| 8422 |
|
| 8423 |
force.initialize = function(_) { |
| 8424 |
nodes = _; |
| 8425 |
}; |
| 8426 |
|
| 8427 |
force.x = function(_) { |
| 8428 |
return arguments.length ? (x = +_, force) : x; |
| 8429 |
}; |
| 8430 |
|
| 8431 |
force.y = function(_) { |
| 8432 |
return arguments.length ? (y = +_, force) : y; |
| 8433 |
}; |
| 8434 |
|
| 8435 |
force.strength = function(_) { |
| 8436 |
return arguments.length ? (strength = +_, force) : strength; |
| 8437 |
}; |
| 8438 |
|
| 8439 |
return force; |
| 8440 |
} |
| 8441 |
|
| 8442 |
function tree_add(d) { |
| 8443 |
const x = +this._x.call(null, d), |
| 8444 |
y = +this._y.call(null, d); |
| 8445 |
return add(this.cover(x, y), x, y, d); |
| 8446 |
} |
| 8447 |
|
| 8448 |
function add(tree, x, y, d) { |
| 8449 |
if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points |
| 8450 |
|
| 8451 |
var parent, |
| 8452 |
node = tree._root, |
| 8453 |
leaf = {data: d}, |
| 8454 |
x0 = tree._x0, |
| 8455 |
y0 = tree._y0, |
| 8456 |
x1 = tree._x1, |
| 8457 |
y1 = tree._y1, |
| 8458 |
xm, |
| 8459 |
ym, |
| 8460 |
xp, |
| 8461 |
yp, |
| 8462 |
right, |
| 8463 |
bottom, |
| 8464 |
i, |
| 8465 |
j; |
| 8466 |
|
| 8467 |
// If the tree is empty, initialize the root as a leaf. |
| 8468 |
if (!node) return tree._root = leaf, tree; |
| 8469 |
|
| 8470 |
// Find the existing leaf for the new point, or add it. |
| 8471 |
while (node.length) { |
| 8472 |
if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; |
| 8473 |
if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; |
| 8474 |
if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree; |
| 8475 |
} |
| 8476 |
|
| 8477 |
// Is the new point is exactly coincident with the existing point? |
| 8478 |
xp = +tree._x.call(null, node.data); |
| 8479 |
yp = +tree._y.call(null, node.data); |
| 8480 |
if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree; |
| 8481 |
|
| 8482 |
// Otherwise, split the leaf node until the old and new point are separated. |
| 8483 |
do { |
| 8484 |
parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4); |
| 8485 |
if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; |
| 8486 |
if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; |
| 8487 |
} while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm))); |
| 8488 |
return parent[j] = node, parent[i] = leaf, tree; |
| 8489 |
} |
| 8490 |
|
| 8491 |
function addAll(data) { |
| 8492 |
var d, i, n = data.length, |
| 8493 |
x, |
| 8494 |
y, |
| 8495 |
xz = new Array(n), |
| 8496 |
yz = new Array(n), |
| 8497 |
x0 = Infinity, |
| 8498 |
y0 = Infinity, |
| 8499 |
x1 = -Infinity, |
| 8500 |
y1 = -Infinity; |
| 8501 |
|
| 8502 |
// Compute the points and their extent. |
| 8503 |
for (i = 0; i < n; ++i) { |
| 8504 |
if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue; |
| 8505 |
xz[i] = x; |
| 8506 |
yz[i] = y; |
| 8507 |
if (x < x0) x0 = x; |
| 8508 |
if (x > x1) x1 = x; |
| 8509 |
if (y < y0) y0 = y; |
| 8510 |
if (y > y1) y1 = y; |
| 8511 |
} |
| 8512 |
|
| 8513 |
// If there were no (valid) points, abort. |
| 8514 |
if (x0 > x1 || y0 > y1) return this; |
| 8515 |
|
| 8516 |
// Expand the tree to cover the new points. |
| 8517 |
this.cover(x0, y0).cover(x1, y1); |
| 8518 |
|
| 8519 |
// Add the new points. |
| 8520 |
for (i = 0; i < n; ++i) { |
| 8521 |
add(this, xz[i], yz[i], data[i]); |
| 8522 |
} |
| 8523 |
|
| 8524 |
return this; |
| 8525 |
} |
| 8526 |
|
| 8527 |
function tree_cover(x, y) { |
| 8528 |
if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points |
| 8529 |
|
| 8530 |
var x0 = this._x0, |
| 8531 |
y0 = this._y0, |
| 8532 |
x1 = this._x1, |
| 8533 |
y1 = this._y1; |
| 8534 |
|
| 8535 |
// If the quadtree has no extent, initialize them. |
| 8536 |
// Integer extent are necessary so that if we later double the extent, |
| 8537 |
// the existing quadrant boundaries don’t change due to floating point error! |
| 8538 |
if (isNaN(x0)) { |
| 8539 |
x1 = (x0 = Math.floor(x)) + 1; |
| 8540 |
y1 = (y0 = Math.floor(y)) + 1; |
| 8541 |
} |
| 8542 |
|
| 8543 |
// Otherwise, double repeatedly to cover. |
| 8544 |
else { |
| 8545 |
var z = x1 - x0 || 1, |
| 8546 |
node = this._root, |
| 8547 |
parent, |
| 8548 |
i; |
| 8549 |
|
| 8550 |
while (x0 > x || x >= x1 || y0 > y || y >= y1) { |
| 8551 |
i = (y < y0) << 1 | (x < x0); |
| 8552 |
parent = new Array(4), parent[i] = node, node = parent, z *= 2; |
| 8553 |
switch (i) { |
| 8554 |
case 0: x1 = x0 + z, y1 = y0 + z; break; |
| 8555 |
case 1: x0 = x1 - z, y1 = y0 + z; break; |
| 8556 |
case 2: x1 = x0 + z, y0 = y1 - z; break; |
| 8557 |
case 3: x0 = x1 - z, y0 = y1 - z; break; |
| 8558 |
} |
| 8559 |
} |
| 8560 |
|
| 8561 |
if (this._root && this._root.length) this._root = node; |
| 8562 |
} |
| 8563 |
|
| 8564 |
this._x0 = x0; |
| 8565 |
this._y0 = y0; |
| 8566 |
this._x1 = x1; |
| 8567 |
this._y1 = y1; |
| 8568 |
return this; |
| 8569 |
} |
| 8570 |
|
| 8571 |
function tree_data() { |
| 8572 |
var data = []; |
| 8573 |
this.visit(function(node) { |
| 8574 |
if (!node.length) do data.push(node.data); while (node = node.next) |
| 8575 |
}); |
| 8576 |
return data; |
| 8577 |
} |
| 8578 |
|
| 8579 |
function tree_extent(_) { |
| 8580 |
return arguments.length |
| 8581 |
? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1]) |
| 8582 |
: isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]]; |
| 8583 |
} |
| 8584 |
|
| 8585 |
function Quad(node, x0, y0, x1, y1) { |
| 8586 |
this.node = node; |
| 8587 |
this.x0 = x0; |
| 8588 |
this.y0 = y0; |
| 8589 |
this.x1 = x1; |
| 8590 |
this.y1 = y1; |
| 8591 |
} |
| 8592 |
|
| 8593 |
function tree_find(x, y, radius) { |
| 8594 |
var data, |
| 8595 |
x0 = this._x0, |
| 8596 |
y0 = this._y0, |
| 8597 |
x1, |
| 8598 |
y1, |
| 8599 |
x2, |
| 8600 |
y2, |
| 8601 |
x3 = this._x1, |
| 8602 |
y3 = this._y1, |
| 8603 |
quads = [], |
| 8604 |
node = this._root, |
| 8605 |
q, |
| 8606 |
i; |
| 8607 |
|
| 8608 |
if (node) quads.push(new Quad(node, x0, y0, x3, y3)); |
| 8609 |
if (radius == null) radius = Infinity; |
| 8610 |
else { |
| 8611 |
x0 = x - radius, y0 = y - radius; |
| 8612 |
x3 = x + radius, y3 = y + radius; |
| 8613 |
radius *= radius; |
| 8614 |
} |
| 8615 |
|
| 8616 |
while (q = quads.pop()) { |
| 8617 |
|
| 8618 |
// Stop searching if this quadrant can’t contain a closer node. |
| 8619 |
if (!(node = q.node) |
| 8620 |
|| (x1 = q.x0) > x3 |
| 8621 |
|| (y1 = q.y0) > y3 |
| 8622 |
|| (x2 = q.x1) < x0 |
| 8623 |
|| (y2 = q.y1) < y0) continue; |
| 8624 |
|
| 8625 |
// Bisect the current quadrant. |
| 8626 |
if (node.length) { |
| 8627 |
var xm = (x1 + x2) / 2, |
| 8628 |
ym = (y1 + y2) / 2; |
| 8629 |
|
| 8630 |
quads.push( |
| 8631 |
new Quad(node[3], xm, ym, x2, y2), |
| 8632 |
new Quad(node[2], x1, ym, xm, y2), |
| 8633 |
new Quad(node[1], xm, y1, x2, ym), |
| 8634 |
new Quad(node[0], x1, y1, xm, ym) |
| 8635 |
); |
| 8636 |
|
| 8637 |
// Visit the closest quadrant first. |
| 8638 |
if (i = (y >= ym) << 1 | (x >= xm)) { |
| 8639 |
q = quads[quads.length - 1]; |
| 8640 |
quads[quads.length - 1] = quads[quads.length - 1 - i]; |
| 8641 |
quads[quads.length - 1 - i] = q; |
| 8642 |
} |
| 8643 |
} |
| 8644 |
|
| 8645 |
// Visit this point. (Visiting coincident points isn’t necessary!) |
| 8646 |
else { |
| 8647 |
var dx = x - +this._x.call(null, node.data), |
| 8648 |
dy = y - +this._y.call(null, node.data), |
| 8649 |
d2 = dx * dx + dy * dy; |
| 8650 |
if (d2 < radius) { |
| 8651 |
var d = Math.sqrt(radius = d2); |
| 8652 |
x0 = x - d, y0 = y - d; |
| 8653 |
x3 = x + d, y3 = y + d; |
| 8654 |
data = node.data; |
| 8655 |
} |
| 8656 |
} |
| 8657 |
} |
| 8658 |
|
| 8659 |
return data; |
| 8660 |
} |
| 8661 |
|
| 8662 |
function tree_remove(d) { |
| 8663 |
if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points |
| 8664 |
|
| 8665 |
var parent, |
| 8666 |
node = this._root, |
| 8667 |
retainer, |
| 8668 |
previous, |
| 8669 |
next, |
| 8670 |
x0 = this._x0, |
| 8671 |
y0 = this._y0, |
| 8672 |
x1 = this._x1, |
| 8673 |
y1 = this._y1, |
| 8674 |
x, |
| 8675 |
y, |
| 8676 |
xm, |
| 8677 |
ym, |
| 8678 |
right, |
| 8679 |
bottom, |
| 8680 |
i, |
| 8681 |
j; |
| 8682 |
|
| 8683 |
// If the tree is empty, initialize the root as a leaf. |
| 8684 |
if (!node) return this; |
| 8685 |
|
| 8686 |
// Find the leaf node for the point. |
| 8687 |
// While descending, also retain the deepest parent with a non-removed sibling. |
| 8688 |
if (node.length) while (true) { |
| 8689 |
if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; |
| 8690 |
if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; |
| 8691 |
if (!(parent = node, node = node[i = bottom << 1 | right])) return this; |
| 8692 |
if (!node.length) break; |
| 8693 |
if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i; |
| 8694 |
} |
| 8695 |
|
| 8696 |
// Find the point to remove. |
| 8697 |
while (node.data !== d) if (!(previous = node, node = node.next)) return this; |
| 8698 |
if (next = node.next) delete node.next; |
| 8699 |
|
| 8700 |
// If there are multiple coincident points, remove just the point. |
| 8701 |
if (previous) return (next ? previous.next = next : delete previous.next), this; |
| 8702 |
|
| 8703 |
// If this is the root point, remove it. |
| 8704 |
if (!parent) return this._root = next, this; |
| 8705 |
|
| 8706 |
// Remove this leaf. |
| 8707 |
next ? parent[i] = next : delete parent[i]; |
| 8708 |
|
| 8709 |
// If the parent now contains exactly one leaf, collapse superfluous parents. |
| 8710 |
if ((node = parent[0] || parent[1] || parent[2] || parent[3]) |
| 8711 |
&& node === (parent[3] || parent[2] || parent[1] || parent[0]) |
| 8712 |
&& !node.length) { |
| 8713 |
if (retainer) retainer[j] = node; |
| 8714 |
else this._root = node; |
| 8715 |
} |
| 8716 |
|
| 8717 |
return this; |
| 8718 |
} |
| 8719 |
|
| 8720 |
function removeAll(data) { |
| 8721 |
for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]); |
| 8722 |
return this; |
| 8723 |
} |
| 8724 |
|
| 8725 |
function tree_root() { |
| 8726 |
return this._root; |
| 8727 |
} |
| 8728 |
|
| 8729 |
function tree_size() { |
| 8730 |
var size = 0; |
| 8731 |
this.visit(function(node) { |
| 8732 |
if (!node.length) do ++size; while (node = node.next) |
| 8733 |
}); |
| 8734 |
return size; |
| 8735 |
} |
| 8736 |
|
| 8737 |
function tree_visit(callback) { |
| 8738 |
var quads = [], q, node = this._root, child, x0, y0, x1, y1; |
| 8739 |
if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1)); |
| 8740 |
while (q = quads.pop()) { |
| 8741 |
if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) { |
| 8742 |
var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2; |
| 8743 |
if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1)); |
| 8744 |
if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1)); |
| 8745 |
if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym)); |
| 8746 |
if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym)); |
| 8747 |
} |
| 8748 |
} |
| 8749 |
return this; |
| 8750 |
} |
| 8751 |
|
| 8752 |
function tree_visitAfter(callback) { |
| 8753 |
var quads = [], next = [], q; |
| 8754 |
if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1)); |
| 8755 |
while (q = quads.pop()) { |
| 8756 |
var node = q.node; |
| 8757 |
if (node.length) { |
| 8758 |
var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2; |
| 8759 |
if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym)); |
| 8760 |
if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym)); |
| 8761 |
if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1)); |
| 8762 |
if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1)); |
| 8763 |
} |
| 8764 |
next.push(q); |
| 8765 |
} |
| 8766 |
while (q = next.pop()) { |
| 8767 |
callback(q.node, q.x0, q.y0, q.x1, q.y1); |
| 8768 |
} |
| 8769 |
return this; |
| 8770 |
} |
| 8771 |
|
| 8772 |
function defaultX(d) { |
| 8773 |
return d[0]; |
| 8774 |
} |
| 8775 |
|
| 8776 |
function tree_x(_) { |
| 8777 |
return arguments.length ? (this._x = _, this) : this._x; |
| 8778 |
} |
| 8779 |
|
| 8780 |
function defaultY(d) { |
| 8781 |
return d[1]; |
| 8782 |
} |
| 8783 |
|
| 8784 |
function tree_y(_) { |
| 8785 |
return arguments.length ? (this._y = _, this) : this._y; |
| 8786 |
} |
| 8787 |
|
| 8788 |
function quadtree(nodes, x, y) { |
| 8789 |
var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN); |
| 8790 |
return nodes == null ? tree : tree.addAll(nodes); |
| 8791 |
} |
| 8792 |
|
| 8793 |
function Quadtree(x, y, x0, y0, x1, y1) { |
| 8794 |
this._x = x; |
| 8795 |
this._y = y; |
| 8796 |
this._x0 = x0; |
| 8797 |
this._y0 = y0; |
| 8798 |
this._x1 = x1; |
| 8799 |
this._y1 = y1; |
| 8800 |
this._root = undefined; |
| 8801 |
} |
| 8802 |
|
| 8803 |
function leaf_copy(leaf) { |
| 8804 |
var copy = {data: leaf.data}, next = copy; |
| 8805 |
while (leaf = leaf.next) next = next.next = {data: leaf.data}; |
| 8806 |
return copy; |
| 8807 |
} |
| 8808 |
|
| 8809 |
var treeProto = quadtree.prototype = Quadtree.prototype; |
| 8810 |
|
| 8811 |
treeProto.copy = function() { |
| 8812 |
var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1), |
| 8813 |
node = this._root, |
| 8814 |
nodes, |
| 8815 |
child; |
| 8816 |
|
| 8817 |
if (!node) return copy; |
| 8818 |
|
| 8819 |
if (!node.length) return copy._root = leaf_copy(node), copy; |
| 8820 |
|
| 8821 |
nodes = [{source: node, target: copy._root = new Array(4)}]; |
| 8822 |
while (node = nodes.pop()) { |
| 8823 |
for (var i = 0; i < 4; ++i) { |
| 8824 |
if (child = node.source[i]) { |
| 8825 |
if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)}); |
| 8826 |
else node.target[i] = leaf_copy(child); |
| 8827 |
} |
| 8828 |
} |
| 8829 |
} |
| 8830 |
|
| 8831 |
return copy; |
| 8832 |
}; |
| 8833 |
|
| 8834 |
treeProto.add = tree_add; |
| 8835 |
treeProto.addAll = addAll; |
| 8836 |
treeProto.cover = tree_cover; |
| 8837 |
treeProto.data = tree_data; |
| 8838 |
treeProto.extent = tree_extent; |
| 8839 |
treeProto.find = tree_find; |
| 8840 |
treeProto.remove = tree_remove; |
| 8841 |
treeProto.removeAll = removeAll; |
| 8842 |
treeProto.root = tree_root; |
| 8843 |
treeProto.size = tree_size; |
| 8844 |
treeProto.visit = tree_visit; |
| 8845 |
treeProto.visitAfter = tree_visitAfter; |
| 8846 |
treeProto.x = tree_x; |
| 8847 |
treeProto.y = tree_y; |
| 8848 |
|
| 8849 |
function constant$4(x) { |
| 8850 |
return function() { |
| 8851 |
return x; |
| 8852 |
}; |
| 8853 |
} |
| 8854 |
|
| 8855 |
function jiggle(random) { |
| 8856 |
return (random() - 0.5) * 1e-6; |
| 8857 |
} |
| 8858 |
|
| 8859 |
function x$3(d) { |
| 8860 |
return d.x + d.vx; |
| 8861 |
} |
| 8862 |
|
| 8863 |
function y$3(d) { |
| 8864 |
return d.y + d.vy; |
| 8865 |
} |
| 8866 |
|
| 8867 |
function collide(radius) { |
| 8868 |
var nodes, |
| 8869 |
radii, |
| 8870 |
random, |
| 8871 |
strength = 1, |
| 8872 |
iterations = 1; |
| 8873 |
|
| 8874 |
if (typeof radius !== "function") radius = constant$4(radius == null ? 1 : +radius); |
| 8875 |
|
| 8876 |
function force() { |
| 8877 |
var i, n = nodes.length, |
| 8878 |
tree, |
| 8879 |
node, |
| 8880 |
xi, |
| 8881 |
yi, |
| 8882 |
ri, |
| 8883 |
ri2; |
| 8884 |
|
| 8885 |
for (var k = 0; k < iterations; ++k) { |
| 8886 |
tree = quadtree(nodes, x$3, y$3).visitAfter(prepare); |
| 8887 |
for (i = 0; i < n; ++i) { |
| 8888 |
node = nodes[i]; |
| 8889 |
ri = radii[node.index], ri2 = ri * ri; |
| 8890 |
xi = node.x + node.vx; |
| 8891 |
yi = node.y + node.vy; |
| 8892 |
tree.visit(apply); |
| 8893 |
} |
| 8894 |
} |
| 8895 |
|
| 8896 |
function apply(quad, x0, y0, x1, y1) { |
| 8897 |
var data = quad.data, rj = quad.r, r = ri + rj; |
| 8898 |
if (data) { |
| 8899 |
if (data.index > node.index) { |
| 8900 |
var x = xi - data.x - data.vx, |
| 8901 |
y = yi - data.y - data.vy, |
| 8902 |
l = x * x + y * y; |
| 8903 |
if (l < r * r) { |
| 8904 |
if (x === 0) x = jiggle(random), l += x * x; |
| 8905 |
if (y === 0) y = jiggle(random), l += y * y; |
| 8906 |
l = (r - (l = Math.sqrt(l))) / l * strength; |
| 8907 |
node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj)); |
| 8908 |
node.vy += (y *= l) * r; |
| 8909 |
data.vx -= x * (r = 1 - r); |
| 8910 |
data.vy -= y * r; |
| 8911 |
} |
| 8912 |
} |
| 8913 |
return; |
| 8914 |
} |
| 8915 |
return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r; |
| 8916 |
} |
| 8917 |
} |
| 8918 |
|
| 8919 |
function prepare(quad) { |
| 8920 |
if (quad.data) return quad.r = radii[quad.data.index]; |
| 8921 |
for (var i = quad.r = 0; i < 4; ++i) { |
| 8922 |
if (quad[i] && quad[i].r > quad.r) { |
| 8923 |
quad.r = quad[i].r; |
| 8924 |
} |
| 8925 |
} |
| 8926 |
} |
| 8927 |
|
| 8928 |
function initialize() { |
| 8929 |
if (!nodes) return; |
| 8930 |
var i, n = nodes.length, node; |
| 8931 |
radii = new Array(n); |
| 8932 |
for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes); |
| 8933 |
} |
| 8934 |
|
| 8935 |
force.initialize = function(_nodes, _random) { |
| 8936 |
nodes = _nodes; |
| 8937 |
random = _random; |
| 8938 |
initialize(); |
| 8939 |
}; |
| 8940 |
|
| 8941 |
force.iterations = function(_) { |
| 8942 |
return arguments.length ? (iterations = +_, force) : iterations; |
| 8943 |
}; |
| 8944 |
|
| 8945 |
force.strength = function(_) { |
| 8946 |
return arguments.length ? (strength = +_, force) : strength; |
| 8947 |
}; |
| 8948 |
|
| 8949 |
force.radius = function(_) { |
| 8950 |
return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius; |
| 8951 |
}; |
| 8952 |
|
| 8953 |
return force; |
| 8954 |
} |
| 8955 |
|
| 8956 |
function index$3(d) { |
| 8957 |
return d.index; |
| 8958 |
} |
| 8959 |
|
| 8960 |
function find(nodeById, nodeId) { |
| 8961 |
var node = nodeById.get(nodeId); |
| 8962 |
if (!node) throw new Error("node not found: " + nodeId); |
| 8963 |
return node; |
| 8964 |
} |
| 8965 |
|
| 8966 |
function link$2(links) { |
| 8967 |
var id = index$3, |
| 8968 |
strength = defaultStrength, |
| 8969 |
strengths, |
| 8970 |
distance = constant$4(30), |
| 8971 |
distances, |
| 8972 |
nodes, |
| 8973 |
count, |
| 8974 |
bias, |
| 8975 |
random, |
| 8976 |
iterations = 1; |
| 8977 |
|
| 8978 |
if (links == null) links = []; |
| 8979 |
|
| 8980 |
function defaultStrength(link) { |
| 8981 |
return 1 / Math.min(count[link.source.index], count[link.target.index]); |
| 8982 |
} |
| 8983 |
|
| 8984 |
function force(alpha) { |
| 8985 |
for (var k = 0, n = links.length; k < iterations; ++k) { |
| 8986 |
for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) { |
| 8987 |
link = links[i], source = link.source, target = link.target; |
| 8988 |
x = target.x + target.vx - source.x - source.vx || jiggle(random); |
| 8989 |
y = target.y + target.vy - source.y - source.vy || jiggle(random); |
| 8990 |
l = Math.sqrt(x * x + y * y); |
| 8991 |
l = (l - distances[i]) / l * alpha * strengths[i]; |
| 8992 |
x *= l, y *= l; |
| 8993 |
target.vx -= x * (b = bias[i]); |
| 8994 |
target.vy -= y * b; |
| 8995 |
source.vx += x * (b = 1 - b); |
| 8996 |
source.vy += y * b; |
| 8997 |
} |
| 8998 |
} |
| 8999 |
} |
| 9000 |
|
| 9001 |
function initialize() { |
| 9002 |
if (!nodes) return; |
| 9003 |
|
| 9004 |
var i, |
| 9005 |
n = nodes.length, |
| 9006 |
m = links.length, |
| 9007 |
nodeById = new Map(nodes.map((d, i) => [id(d, i, nodes), d])), |
| 9008 |
link; |
| 9009 |
|
| 9010 |
for (i = 0, count = new Array(n); i < m; ++i) { |
| 9011 |
link = links[i], link.index = i; |
| 9012 |
if (typeof link.source !== "object") link.source = find(nodeById, link.source); |
| 9013 |
if (typeof link.target !== "object") link.target = find(nodeById, link.target); |
| 9014 |
count[link.source.index] = (count[link.source.index] || 0) + 1; |
| 9015 |
count[link.target.index] = (count[link.target.index] || 0) + 1; |
| 9016 |
} |
| 9017 |
|
| 9018 |
for (i = 0, bias = new Array(m); i < m; ++i) { |
| 9019 |
link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]); |
| 9020 |
} |
| 9021 |
|
| 9022 |
strengths = new Array(m), initializeStrength(); |
| 9023 |
distances = new Array(m), initializeDistance(); |
| 9024 |
} |
| 9025 |
|
| 9026 |
function initializeStrength() { |
| 9027 |
if (!nodes) return; |
| 9028 |
|
| 9029 |
for (var i = 0, n = links.length; i < n; ++i) { |
| 9030 |
strengths[i] = +strength(links[i], i, links); |
| 9031 |
} |
| 9032 |
} |
| 9033 |
|
| 9034 |
function initializeDistance() { |
| 9035 |
if (!nodes) return; |
| 9036 |
|
| 9037 |
for (var i = 0, n = links.length; i < n; ++i) { |
| 9038 |
distances[i] = +distance(links[i], i, links); |
| 9039 |
} |
| 9040 |
} |
| 9041 |
|
| 9042 |
force.initialize = function(_nodes, _random) { |
| 9043 |
nodes = _nodes; |
| 9044 |
random = _random; |
| 9045 |
initialize(); |
| 9046 |
}; |
| 9047 |
|
| 9048 |
force.links = function(_) { |
| 9049 |
return arguments.length ? (links = _, initialize(), force) : links; |
| 9050 |
}; |
| 9051 |
|
| 9052 |
force.id = function(_) { |
| 9053 |
return arguments.length ? (id = _, force) : id; |
| 9054 |
}; |
| 9055 |
|
| 9056 |
force.iterations = function(_) { |
| 9057 |
return arguments.length ? (iterations = +_, force) : iterations; |
| 9058 |
}; |
| 9059 |
|
| 9060 |
force.strength = function(_) { |
| 9061 |
return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initializeStrength(), force) : strength; |
| 9062 |
}; |
| 9063 |
|
| 9064 |
force.distance = function(_) { |
| 9065 |
return arguments.length ? (distance = typeof _ === "function" ? _ : constant$4(+_), initializeDistance(), force) : distance; |
| 9066 |
}; |
| 9067 |
|
| 9068 |
return force; |
| 9069 |
} |
| 9070 |
|
| 9071 |
// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use |
| 9072 |
const a$2 = 1664525; |
| 9073 |
const c$4 = 1013904223; |
| 9074 |
const m$1 = 4294967296; // 2^32 |
| 9075 |
|
| 9076 |
function lcg$2() { |
| 9077 |
let s = 1; |
| 9078 |
return () => (s = (a$2 * s + c$4) % m$1) / m$1; |
| 9079 |
} |
| 9080 |
|
| 9081 |
function x$2(d) { |
| 9082 |
return d.x; |
| 9083 |
} |
| 9084 |
|
| 9085 |
function y$2(d) { |
| 9086 |
return d.y; |
| 9087 |
} |
| 9088 |
|
| 9089 |
var initialRadius = 10, |
| 9090 |
initialAngle = Math.PI * (3 - Math.sqrt(5)); |
| 9091 |
|
| 9092 |
function simulation(nodes) { |
| 9093 |
var simulation, |
| 9094 |
alpha = 1, |
| 9095 |
alphaMin = 0.001, |
| 9096 |
alphaDecay = 1 - Math.pow(alphaMin, 1 / 300), |
| 9097 |
alphaTarget = 0, |
| 9098 |
velocityDecay = 0.6, |
| 9099 |
forces = new Map(), |
| 9100 |
stepper = timer(step), |
| 9101 |
event = dispatch("tick", "end"), |
| 9102 |
random = lcg$2(); |
| 9103 |
|
| 9104 |
if (nodes == null) nodes = []; |
| 9105 |
|
| 9106 |
function step() { |
| 9107 |
tick(); |
| 9108 |
event.call("tick", simulation); |
| 9109 |
if (alpha < alphaMin) { |
| 9110 |
stepper.stop(); |
| 9111 |
event.call("end", simulation); |
| 9112 |
} |
| 9113 |
} |
| 9114 |
|
| 9115 |
function tick(iterations) { |
| 9116 |
var i, n = nodes.length, node; |
| 9117 |
|
| 9118 |
if (iterations === undefined) iterations = 1; |
| 9119 |
|
| 9120 |
for (var k = 0; k < iterations; ++k) { |
| 9121 |
alpha += (alphaTarget - alpha) * alphaDecay; |
| 9122 |
|
| 9123 |
forces.forEach(function(force) { |
| 9124 |
force(alpha); |
| 9125 |
}); |
| 9126 |
|
| 9127 |
for (i = 0; i < n; ++i) { |
| 9128 |
node = nodes[i]; |
| 9129 |
if (node.fx == null) node.x += node.vx *= velocityDecay; |
| 9130 |
else node.x = node.fx, node.vx = 0; |
| 9131 |
if (node.fy == null) node.y += node.vy *= velocityDecay; |
| 9132 |
else node.y = node.fy, node.vy = 0; |
| 9133 |
} |
| 9134 |
} |
| 9135 |
|
| 9136 |
return simulation; |
| 9137 |
} |
| 9138 |
|
| 9139 |
function initializeNodes() { |
| 9140 |
for (var i = 0, n = nodes.length, node; i < n; ++i) { |
| 9141 |
node = nodes[i], node.index = i; |
| 9142 |
if (node.fx != null) node.x = node.fx; |
| 9143 |
if (node.fy != null) node.y = node.fy; |
| 9144 |
if (isNaN(node.x) || isNaN(node.y)) { |
| 9145 |
var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle; |
| 9146 |
node.x = radius * Math.cos(angle); |
| 9147 |
node.y = radius * Math.sin(angle); |
| 9148 |
} |
| 9149 |
if (isNaN(node.vx) || isNaN(node.vy)) { |
| 9150 |
node.vx = node.vy = 0; |
| 9151 |
} |
| 9152 |
} |
| 9153 |
} |
| 9154 |
|
| 9155 |
function initializeForce(force) { |
| 9156 |
if (force.initialize) force.initialize(nodes, random); |
| 9157 |
return force; |
| 9158 |
} |
| 9159 |
|
| 9160 |
initializeNodes(); |
| 9161 |
|
| 9162 |
return simulation = { |
| 9163 |
tick: tick, |
| 9164 |
|
| 9165 |
restart: function() { |
| 9166 |
return stepper.restart(step), simulation; |
| 9167 |
}, |
| 9168 |
|
| 9169 |
stop: function() { |
| 9170 |
return stepper.stop(), simulation; |
| 9171 |
}, |
| 9172 |
|
| 9173 |
nodes: function(_) { |
| 9174 |
return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes; |
| 9175 |
}, |
| 9176 |
|
| 9177 |
alpha: function(_) { |
| 9178 |
return arguments.length ? (alpha = +_, simulation) : alpha; |
| 9179 |
}, |
| 9180 |
|
| 9181 |
alphaMin: function(_) { |
| 9182 |
return arguments.length ? (alphaMin = +_, simulation) : alphaMin; |
| 9183 |
}, |
| 9184 |
|
| 9185 |
alphaDecay: function(_) { |
| 9186 |
return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay; |
| 9187 |
}, |
| 9188 |
|
| 9189 |
alphaTarget: function(_) { |
| 9190 |
return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget; |
| 9191 |
}, |
| 9192 |
|
| 9193 |
velocityDecay: function(_) { |
| 9194 |
return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay; |
| 9195 |
}, |
| 9196 |
|
| 9197 |
randomSource: function(_) { |
| 9198 |
return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random; |
| 9199 |
}, |
| 9200 |
|
| 9201 |
force: function(name, _) { |
| 9202 |
return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name); |
| 9203 |
}, |
| 9204 |
|
| 9205 |
find: function(x, y, radius) { |
| 9206 |
var i = 0, |
| 9207 |
n = nodes.length, |
| 9208 |
dx, |
| 9209 |
dy, |
| 9210 |
d2, |
| 9211 |
node, |
| 9212 |
closest; |
| 9213 |
|
| 9214 |
if (radius == null) radius = Infinity; |
| 9215 |
else radius *= radius; |
| 9216 |
|
| 9217 |
for (i = 0; i < n; ++i) { |
| 9218 |
node = nodes[i]; |
| 9219 |
dx = x - node.x; |
| 9220 |
dy = y - node.y; |
| 9221 |
d2 = dx * dx + dy * dy; |
| 9222 |
if (d2 < radius) closest = node, radius = d2; |
| 9223 |
} |
| 9224 |
|
| 9225 |
return closest; |
| 9226 |
}, |
| 9227 |
|
| 9228 |
on: function(name, _) { |
| 9229 |
return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name); |
| 9230 |
} |
| 9231 |
}; |
| 9232 |
} |
| 9233 |
|
| 9234 |
function manyBody() { |
| 9235 |
var nodes, |
| 9236 |
node, |
| 9237 |
random, |
| 9238 |
alpha, |
| 9239 |
strength = constant$4(-30), |
| 9240 |
strengths, |
| 9241 |
distanceMin2 = 1, |
| 9242 |
distanceMax2 = Infinity, |
| 9243 |
theta2 = 0.81; |
| 9244 |
|
| 9245 |
function force(_) { |
| 9246 |
var i, n = nodes.length, tree = quadtree(nodes, x$2, y$2).visitAfter(accumulate); |
| 9247 |
for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply); |
| 9248 |
} |
| 9249 |
|
| 9250 |
function initialize() { |
| 9251 |
if (!nodes) return; |
| 9252 |
var i, n = nodes.length, node; |
| 9253 |
strengths = new Array(n); |
| 9254 |
for (i = 0; i < n; ++i) node = nodes[i], strengths[node.index] = +strength(node, i, nodes); |
| 9255 |
} |
| 9256 |
|
| 9257 |
function accumulate(quad) { |
| 9258 |
var strength = 0, q, c, weight = 0, x, y, i; |
| 9259 |
|
| 9260 |
// For internal nodes, accumulate forces from child quadrants. |
| 9261 |
if (quad.length) { |
| 9262 |
for (x = y = i = 0; i < 4; ++i) { |
| 9263 |
if ((q = quad[i]) && (c = Math.abs(q.value))) { |
| 9264 |
strength += q.value, weight += c, x += c * q.x, y += c * q.y; |
| 9265 |
} |
| 9266 |
} |
| 9267 |
quad.x = x / weight; |
| 9268 |
quad.y = y / weight; |
| 9269 |
} |
| 9270 |
|
| 9271 |
// For leaf nodes, accumulate forces from coincident quadrants. |
| 9272 |
else { |
| 9273 |
q = quad; |
| 9274 |
q.x = q.data.x; |
| 9275 |
q.y = q.data.y; |
| 9276 |
do strength += strengths[q.data.index]; |
| 9277 |
while (q = q.next); |
| 9278 |
} |
| 9279 |
|
| 9280 |
quad.value = strength; |
| 9281 |
} |
| 9282 |
|
| 9283 |
function apply(quad, x1, _, x2) { |
| 9284 |
if (!quad.value) return true; |
| 9285 |
|
| 9286 |
var x = quad.x - node.x, |
| 9287 |
y = quad.y - node.y, |
| 9288 |
w = x2 - x1, |
| 9289 |
l = x * x + y * y; |
| 9290 |
|
| 9291 |
// Apply the Barnes-Hut approximation if possible. |
| 9292 |
// Limit forces for very close nodes; randomize direction if coincident. |
| 9293 |
if (w * w / theta2 < l) { |
| 9294 |
if (l < distanceMax2) { |
| 9295 |
if (x === 0) x = jiggle(random), l += x * x; |
| 9296 |
if (y === 0) y = jiggle(random), l += y * y; |
| 9297 |
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); |
| 9298 |
node.vx += x * quad.value * alpha / l; |
| 9299 |
node.vy += y * quad.value * alpha / l; |
| 9300 |
} |
| 9301 |
return true; |
| 9302 |
} |
| 9303 |
|
| 9304 |
// Otherwise, process points directly. |
| 9305 |
else if (quad.length || l >= distanceMax2) return; |
| 9306 |
|
| 9307 |
// Limit forces for very close nodes; randomize direction if coincident. |
| 9308 |
if (quad.data !== node || quad.next) { |
| 9309 |
if (x === 0) x = jiggle(random), l += x * x; |
| 9310 |
if (y === 0) y = jiggle(random), l += y * y; |
| 9311 |
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); |
| 9312 |
} |
| 9313 |
|
| 9314 |
do if (quad.data !== node) { |
| 9315 |
w = strengths[quad.data.index] * alpha / l; |
| 9316 |
node.vx += x * w; |
| 9317 |
node.vy += y * w; |
| 9318 |
} while (quad = quad.next); |
| 9319 |
} |
| 9320 |
|
| 9321 |
force.initialize = function(_nodes, _random) { |
| 9322 |
nodes = _nodes; |
| 9323 |
random = _random; |
| 9324 |
initialize(); |
| 9325 |
}; |
| 9326 |
|
| 9327 |
force.strength = function(_) { |
| 9328 |
return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength; |
| 9329 |
}; |
| 9330 |
|
| 9331 |
force.distanceMin = function(_) { |
| 9332 |
return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2); |
| 9333 |
}; |
| 9334 |
|
| 9335 |
force.distanceMax = function(_) { |
| 9336 |
return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2); |
| 9337 |
}; |
| 9338 |
|
| 9339 |
force.theta = function(_) { |
| 9340 |
return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2); |
| 9341 |
}; |
| 9342 |
|
| 9343 |
return force; |
| 9344 |
} |
| 9345 |
|
| 9346 |
function radial$1(radius, x, y) { |
| 9347 |
var nodes, |
| 9348 |
strength = constant$4(0.1), |
| 9349 |
strengths, |
| 9350 |
radiuses; |
| 9351 |
|
| 9352 |
if (typeof radius !== "function") radius = constant$4(+radius); |
| 9353 |
if (x == null) x = 0; |
| 9354 |
if (y == null) y = 0; |
| 9355 |
|
| 9356 |
function force(alpha) { |
| 9357 |
for (var i = 0, n = nodes.length; i < n; ++i) { |
| 9358 |
var node = nodes[i], |
| 9359 |
dx = node.x - x || 1e-6, |
| 9360 |
dy = node.y - y || 1e-6, |
| 9361 |
r = Math.sqrt(dx * dx + dy * dy), |
| 9362 |
k = (radiuses[i] - r) * strengths[i] * alpha / r; |
| 9363 |
node.vx += dx * k; |
| 9364 |
node.vy += dy * k; |
| 9365 |
} |
| 9366 |
} |
| 9367 |
|
| 9368 |
function initialize() { |
| 9369 |
if (!nodes) return; |
| 9370 |
var i, n = nodes.length; |
| 9371 |
strengths = new Array(n); |
| 9372 |
radiuses = new Array(n); |
| 9373 |
for (i = 0; i < n; ++i) { |
| 9374 |
radiuses[i] = +radius(nodes[i], i, nodes); |
| 9375 |
strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes); |
| 9376 |
} |
| 9377 |
} |
| 9378 |
|
| 9379 |
force.initialize = function(_) { |
| 9380 |
nodes = _, initialize(); |
| 9381 |
}; |
| 9382 |
|
| 9383 |
force.strength = function(_) { |
| 9384 |
return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength; |
| 9385 |
}; |
| 9386 |
|
| 9387 |
force.radius = function(_) { |
| 9388 |
return arguments.length ? (radius = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : radius; |
| 9389 |
}; |
| 9390 |
|
| 9391 |
force.x = function(_) { |
| 9392 |
return arguments.length ? (x = +_, force) : x; |
| 9393 |
}; |
| 9394 |
|
| 9395 |
force.y = function(_) { |
| 9396 |
return arguments.length ? (y = +_, force) : y; |
| 9397 |
}; |
| 9398 |
|
| 9399 |
return force; |
| 9400 |
} |
| 9401 |
|
| 9402 |
function x$1(x) { |
| 9403 |
var strength = constant$4(0.1), |
| 9404 |
nodes, |
| 9405 |
strengths, |
| 9406 |
xz; |
| 9407 |
|
| 9408 |
if (typeof x !== "function") x = constant$4(x == null ? 0 : +x); |
| 9409 |
|
| 9410 |
function force(alpha) { |
| 9411 |
for (var i = 0, n = nodes.length, node; i < n; ++i) { |
| 9412 |
node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha; |
| 9413 |
} |
| 9414 |
} |
| 9415 |
|
| 9416 |
function initialize() { |
| 9417 |
if (!nodes) return; |
| 9418 |
var i, n = nodes.length; |
| 9419 |
strengths = new Array(n); |
| 9420 |
xz = new Array(n); |
| 9421 |
for (i = 0; i < n; ++i) { |
| 9422 |
strengths[i] = isNaN(xz[i] = +x(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes); |
| 9423 |
} |
| 9424 |
} |
| 9425 |
|
| 9426 |
force.initialize = function(_) { |
| 9427 |
nodes = _; |
| 9428 |
initialize(); |
| 9429 |
}; |
| 9430 |
|
| 9431 |
force.strength = function(_) { |
| 9432 |
return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength; |
| 9433 |
}; |
| 9434 |
|
| 9435 |
force.x = function(_) { |
| 9436 |
return arguments.length ? (x = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : x; |
| 9437 |
}; |
| 9438 |
|
| 9439 |
return force; |
| 9440 |
} |
| 9441 |
|
| 9442 |
function y$1(y) { |
| 9443 |
var strength = constant$4(0.1), |
| 9444 |
nodes, |
| 9445 |
strengths, |
| 9446 |
yz; |
| 9447 |
|
| 9448 |
if (typeof y !== "function") y = constant$4(y == null ? 0 : +y); |
| 9449 |
|
| 9450 |
function force(alpha) { |
| 9451 |
for (var i = 0, n = nodes.length, node; i < n; ++i) { |
| 9452 |
node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha; |
| 9453 |
} |
| 9454 |
} |
| 9455 |
|
| 9456 |
function initialize() { |
| 9457 |
if (!nodes) return; |
| 9458 |
var i, n = nodes.length; |
| 9459 |
strengths = new Array(n); |
| 9460 |
yz = new Array(n); |
| 9461 |
for (i = 0; i < n; ++i) { |
| 9462 |
strengths[i] = isNaN(yz[i] = +y(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes); |
| 9463 |
} |
| 9464 |
} |
| 9465 |
|
| 9466 |
force.initialize = function(_) { |
| 9467 |
nodes = _; |
| 9468 |
initialize(); |
| 9469 |
}; |
| 9470 |
|
| 9471 |
force.strength = function(_) { |
| 9472 |
return arguments.length ? (strength = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : strength; |
| 9473 |
}; |
| 9474 |
|
| 9475 |
force.y = function(_) { |
| 9476 |
return arguments.length ? (y = typeof _ === "function" ? _ : constant$4(+_), initialize(), force) : y; |
| 9477 |
}; |
| 9478 |
|
| 9479 |
return force; |
| 9480 |
} |
| 9481 |
|
| 9482 |
function formatDecimal(x) { |
| 9483 |
return Math.abs(x = Math.round(x)) >= 1e21 |
| 9484 |
? x.toLocaleString("en").replace(/,/g, "") |
| 9485 |
: x.toString(10); |
| 9486 |
} |
| 9487 |
|
| 9488 |
// Computes the decimal coefficient and exponent of the specified number x with |
| 9489 |
// significant digits p, where x is positive and p is in [1, 21] or undefined. |
| 9490 |
// For example, formatDecimalParts(1.23) returns ["123", 0]. |
| 9491 |
function formatDecimalParts(x, p) { |
| 9492 |
if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity |
| 9493 |
var i, coefficient = x.slice(0, i); |
| 9494 |
|
| 9495 |
// The string returned by toExponential either has the form \d\.\d+e[-+]\d+ |
| 9496 |
// (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3). |
| 9497 |
return [ |
| 9498 |
coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient, |
| 9499 |
+x.slice(i + 1) |
| 9500 |
]; |
| 9501 |
} |
| 9502 |
|
| 9503 |
function exponent(x) { |
| 9504 |
return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN; |
| 9505 |
} |
| 9506 |
|
| 9507 |
function formatGroup(grouping, thousands) { |
| 9508 |
return function(value, width) { |
| 9509 |
var i = value.length, |
| 9510 |
t = [], |
| 9511 |
j = 0, |
| 9512 |
g = grouping[0], |
| 9513 |
length = 0; |
| 9514 |
|
| 9515 |
while (i > 0 && g > 0) { |
| 9516 |
if (length + g + 1 > width) g = Math.max(1, width - length); |
| 9517 |
t.push(value.substring(i -= g, i + g)); |
| 9518 |
if ((length += g + 1) > width) break; |
| 9519 |
g = grouping[j = (j + 1) % grouping.length]; |
| 9520 |
} |
| 9521 |
|
| 9522 |
return t.reverse().join(thousands); |
| 9523 |
}; |
| 9524 |
} |
| 9525 |
|
| 9526 |
function formatNumerals(numerals) { |
| 9527 |
return function(value) { |
| 9528 |
return value.replace(/[0-9]/g, function(i) { |
| 9529 |
return numerals[+i]; |
| 9530 |
}); |
| 9531 |
}; |
| 9532 |
} |
| 9533 |
|
| 9534 |
// [[fill]align][sign][symbol][0][width][,][.precision][~][type] |
| 9535 |
var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i; |
| 9536 |
|
| 9537 |
function formatSpecifier(specifier) { |
| 9538 |
if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier); |
| 9539 |
var match; |
| 9540 |
return new FormatSpecifier({ |
| 9541 |
fill: match[1], |
| 9542 |
align: match[2], |
| 9543 |
sign: match[3], |
| 9544 |
symbol: match[4], |
| 9545 |
zero: match[5], |
| 9546 |
width: match[6], |
| 9547 |
comma: match[7], |
| 9548 |
precision: match[8] && match[8].slice(1), |
| 9549 |
trim: match[9], |
| 9550 |
type: match[10] |
| 9551 |
}); |
| 9552 |
} |
| 9553 |
|
| 9554 |
formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof |
| 9555 |
|
| 9556 |
function FormatSpecifier(specifier) { |
| 9557 |
this.fill = specifier.fill === undefined ? " " : specifier.fill + ""; |
| 9558 |
this.align = specifier.align === undefined ? ">" : specifier.align + ""; |
| 9559 |
this.sign = specifier.sign === undefined ? "-" : specifier.sign + ""; |
| 9560 |
this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + ""; |
| 9561 |
this.zero = !!specifier.zero; |
| 9562 |
this.width = specifier.width === undefined ? undefined : +specifier.width; |
| 9563 |
this.comma = !!specifier.comma; |
| 9564 |
this.precision = specifier.precision === undefined ? undefined : +specifier.precision; |
| 9565 |
this.trim = !!specifier.trim; |
| 9566 |
this.type = specifier.type === undefined ? "" : specifier.type + ""; |
| 9567 |
} |
| 9568 |
|
| 9569 |
FormatSpecifier.prototype.toString = function() { |
| 9570 |
return this.fill |
| 9571 |
+ this.align |
| 9572 |
+ this.sign |
| 9573 |
+ this.symbol |
| 9574 |
+ (this.zero ? "0" : "") |
| 9575 |
+ (this.width === undefined ? "" : Math.max(1, this.width | 0)) |
| 9576 |
+ (this.comma ? "," : "") |
| 9577 |
+ (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0)) |
| 9578 |
+ (this.trim ? "~" : "") |
| 9579 |
+ this.type; |
| 9580 |
}; |
| 9581 |
|
| 9582 |
// Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k. |
| 9583 |
function formatTrim(s) { |
| 9584 |
out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) { |
| 9585 |
switch (s[i]) { |
| 9586 |
case ".": i0 = i1 = i; break; |
| 9587 |
case "0": if (i0 === 0) i0 = i; i1 = i; break; |
| 9588 |
default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break; |
| 9589 |
} |
| 9590 |
} |
| 9591 |
return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s; |
| 9592 |
} |
| 9593 |
|
| 9594 |
var prefixExponent; |
| 9595 |
|
| 9596 |
function formatPrefixAuto(x, p) { |
| 9597 |
var d = formatDecimalParts(x, p); |
| 9598 |
if (!d) return x + ""; |
| 9599 |
var coefficient = d[0], |
| 9600 |
exponent = d[1], |
| 9601 |
i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1, |
| 9602 |
n = coefficient.length; |
| 9603 |
return i === n ? coefficient |
| 9604 |
: i > n ? coefficient + new Array(i - n + 1).join("0") |
| 9605 |
: i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i) |
| 9606 |
: "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y! |
| 9607 |
} |
| 9608 |
|
| 9609 |
function formatRounded(x, p) { |
| 9610 |
var d = formatDecimalParts(x, p); |
| 9611 |
if (!d) return x + ""; |
| 9612 |
var coefficient = d[0], |
| 9613 |
exponent = d[1]; |
| 9614 |
return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient |
| 9615 |
: coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1) |
| 9616 |
: coefficient + new Array(exponent - coefficient.length + 2).join("0"); |
| 9617 |
} |
| 9618 |
|
| 9619 |
var formatTypes = { |
| 9620 |
"%": (x, p) => (x * 100).toFixed(p), |
| 9621 |
"b": (x) => Math.round(x).toString(2), |
| 9622 |
"c": (x) => x + "", |
| 9623 |
"d": formatDecimal, |
| 9624 |
"e": (x, p) => x.toExponential(p), |
| 9625 |
"f": (x, p) => x.toFixed(p), |
| 9626 |
"g": (x, p) => x.toPrecision(p), |
| 9627 |
"o": (x) => Math.round(x).toString(8), |
| 9628 |
"p": (x, p) => formatRounded(x * 100, p), |
| 9629 |
"r": formatRounded, |
| 9630 |
"s": formatPrefixAuto, |
| 9631 |
"X": (x) => Math.round(x).toString(16).toUpperCase(), |
| 9632 |
"x": (x) => Math.round(x).toString(16) |
| 9633 |
}; |
| 9634 |
|
| 9635 |
function identity$6(x) { |
| 9636 |
return x; |
| 9637 |
} |
| 9638 |
|
| 9639 |
var map = Array.prototype.map, |
| 9640 |
prefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"]; |
| 9641 |
|
| 9642 |
function formatLocale$1(locale) { |
| 9643 |
var group = locale.grouping === undefined || locale.thousands === undefined ? identity$6 : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""), |
| 9644 |
currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "", |
| 9645 |
currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "", |
| 9646 |
decimal = locale.decimal === undefined ? "." : locale.decimal + "", |
| 9647 |
numerals = locale.numerals === undefined ? identity$6 : formatNumerals(map.call(locale.numerals, String)), |
| 9648 |
percent = locale.percent === undefined ? "%" : locale.percent + "", |
| 9649 |
minus = locale.minus === undefined ? "−" : locale.minus + "", |
| 9650 |
nan = locale.nan === undefined ? "NaN" : locale.nan + ""; |
| 9651 |
|
| 9652 |
function newFormat(specifier) { |
| 9653 |
specifier = formatSpecifier(specifier); |
| 9654 |
|
| 9655 |
var fill = specifier.fill, |
| 9656 |
align = specifier.align, |
| 9657 |
sign = specifier.sign, |
| 9658 |
symbol = specifier.symbol, |
| 9659 |
zero = specifier.zero, |
| 9660 |
width = specifier.width, |
| 9661 |
comma = specifier.comma, |
| 9662 |
precision = specifier.precision, |
| 9663 |
trim = specifier.trim, |
| 9664 |
type = specifier.type; |
| 9665 |
|
| 9666 |
// The "n" type is an alias for ",g". |
| 9667 |
if (type === "n") comma = true, type = "g"; |
| 9668 |
|
| 9669 |
// The "" type, and any invalid type, is an alias for ".12~g". |
| 9670 |
else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g"; |
| 9671 |
|
| 9672 |
// If zero fill is specified, padding goes after sign and before digits. |
| 9673 |
if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "="; |
| 9674 |
|
| 9675 |
// Compute the prefix and suffix. |
| 9676 |
// For SI-prefix, the suffix is lazily computed. |
| 9677 |
var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "", |
| 9678 |
suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : ""; |
| 9679 |
|
| 9680 |
// What format function should we use? |
| 9681 |
// Is this an integer type? |
| 9682 |
// Can this type generate exponential notation? |
| 9683 |
var formatType = formatTypes[type], |
| 9684 |
maybeSuffix = /[defgprs%]/.test(type); |
| 9685 |
|
| 9686 |
// Set the default precision if not specified, |
| 9687 |
// or clamp the specified precision to the supported range. |
| 9688 |
// For significant precision, it must be in [1, 21]. |
| 9689 |
// For fixed precision, it must be in [0, 20]. |
| 9690 |
precision = precision === undefined ? 6 |
| 9691 |
: /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision)) |
| 9692 |
: Math.max(0, Math.min(20, precision)); |
| 9693 |
|
| 9694 |
function format(value) { |
| 9695 |
var valuePrefix = prefix, |
| 9696 |
valueSuffix = suffix, |
| 9697 |
i, n, c; |
| 9698 |
|
| 9699 |
if (type === "c") { |
| 9700 |
valueSuffix = formatType(value) + valueSuffix; |
| 9701 |
value = ""; |
| 9702 |
} else { |
| 9703 |
value = +value; |
| 9704 |
|
| 9705 |
// Determine the sign. -0 is not less than 0, but 1 / -0 is! |
| 9706 |
var valueNegative = value < 0 || 1 / value < 0; |
| 9707 |
|
| 9708 |
// Perform the initial formatting. |
| 9709 |
value = isNaN(value) ? nan : formatType(Math.abs(value), precision); |
| 9710 |
|
| 9711 |
// Trim insignificant zeros. |
| 9712 |
if (trim) value = formatTrim(value); |
| 9713 |
|
| 9714 |
// If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign. |
| 9715 |
if (valueNegative && +value === 0 && sign !== "+") valueNegative = false; |
| 9716 |
|
| 9717 |
// Compute the prefix and suffix. |
| 9718 |
valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix; |
| 9719 |
valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : ""); |
| 9720 |
|
| 9721 |
// Break the formatted value into the integer “value” part that can be |
| 9722 |
// grouped, and fractional or exponential “suffix” part that is not. |
| 9723 |
if (maybeSuffix) { |
| 9724 |
i = -1, n = value.length; |
| 9725 |
while (++i < n) { |
| 9726 |
if (c = value.charCodeAt(i), 48 > c || c > 57) { |
| 9727 |
valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix; |
| 9728 |
value = value.slice(0, i); |
| 9729 |
break; |
| 9730 |
} |
| 9731 |
} |
| 9732 |
} |
| 9733 |
} |
| 9734 |
|
| 9735 |
// If the fill character is not "0", grouping is applied before padding. |
| 9736 |
if (comma && !zero) value = group(value, Infinity); |
| 9737 |
|
| 9738 |
// Compute the padding. |
| 9739 |
var length = valuePrefix.length + value.length + valueSuffix.length, |
| 9740 |
padding = length < width ? new Array(width - length + 1).join(fill) : ""; |
| 9741 |
|
| 9742 |
// If the fill character is "0", grouping is applied after padding. |
| 9743 |
if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = ""; |
| 9744 |
|
| 9745 |
// Reconstruct the final output based on the desired alignment. |
| 9746 |
switch (align) { |
| 9747 |
case "<": value = valuePrefix + value + valueSuffix + padding; break; |
| 9748 |
case "=": value = valuePrefix + padding + value + valueSuffix; break; |
| 9749 |
case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break; |
| 9750 |
default: value = padding + valuePrefix + value + valueSuffix; break; |
| 9751 |
} |
| 9752 |
|
| 9753 |
return numerals(value); |
| 9754 |
} |
| 9755 |
|
| 9756 |
format.toString = function() { |
| 9757 |
return specifier + ""; |
| 9758 |
}; |
| 9759 |
|
| 9760 |
return format; |
| 9761 |
} |
| 9762 |
|
| 9763 |
function formatPrefix(specifier, value) { |
| 9764 |
var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)), |
| 9765 |
e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3, |
| 9766 |
k = Math.pow(10, -e), |
| 9767 |
prefix = prefixes[8 + e / 3]; |
| 9768 |
return function(value) { |
| 9769 |
return f(k * value) + prefix; |
| 9770 |
}; |
| 9771 |
} |
| 9772 |
|
| 9773 |
return { |
| 9774 |
format: newFormat, |
| 9775 |
formatPrefix: formatPrefix |
| 9776 |
}; |
| 9777 |
} |
| 9778 |
|
| 9779 |
var locale$1; |
| 9780 |
exports.format = void 0; |
| 9781 |
exports.formatPrefix = void 0; |
| 9782 |
|
| 9783 |
defaultLocale$1({ |
| 9784 |
thousands: ",", |
| 9785 |
grouping: [3], |
| 9786 |
currency: ["$", ""] |
| 9787 |
}); |
| 9788 |
|
| 9789 |
function defaultLocale$1(definition) { |
| 9790 |
locale$1 = formatLocale$1(definition); |
| 9791 |
exports.format = locale$1.format; |
| 9792 |
exports.formatPrefix = locale$1.formatPrefix; |
| 9793 |
return locale$1; |
| 9794 |
} |
| 9795 |
|
| 9796 |
function precisionFixed(step) { |
| 9797 |
return Math.max(0, -exponent(Math.abs(step))); |
| 9798 |
} |
| 9799 |
|
| 9800 |
function precisionPrefix(step, value) { |
| 9801 |
return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step))); |
| 9802 |
} |
| 9803 |
|
| 9804 |
function precisionRound(step, max) { |
| 9805 |
step = Math.abs(step), max = Math.abs(max) - step; |
| 9806 |
return Math.max(0, exponent(max) - exponent(step)) + 1; |
| 9807 |
} |
| 9808 |
|
| 9809 |
var epsilon$1 = 1e-6; |
| 9810 |
var epsilon2 = 1e-12; |
| 9811 |
var pi$1 = Math.PI; |
| 9812 |
var halfPi$1 = pi$1 / 2; |
| 9813 |
var quarterPi = pi$1 / 4; |
| 9814 |
var tau$1 = pi$1 * 2; |
| 9815 |
|
| 9816 |
var degrees = 180 / pi$1; |
| 9817 |
var radians = pi$1 / 180; |
| 9818 |
|
| 9819 |
var abs$1 = Math.abs; |
| 9820 |
var atan = Math.atan; |
| 9821 |
var atan2$1 = Math.atan2; |
| 9822 |
var cos$1 = Math.cos; |
| 9823 |
var ceil = Math.ceil; |
| 9824 |
var exp = Math.exp; |
| 9825 |
var hypot = Math.hypot; |
| 9826 |
var log$1 = Math.log; |
| 9827 |
var pow$1 = Math.pow; |
| 9828 |
var sin$1 = Math.sin; |
| 9829 |
var sign$1 = Math.sign || function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; }; |
| 9830 |
var sqrt$2 = Math.sqrt; |
| 9831 |
var tan = Math.tan; |
| 9832 |
|
| 9833 |
function acos$1(x) { |
| 9834 |
return x > 1 ? 0 : x < -1 ? pi$1 : Math.acos(x); |
| 9835 |
} |
| 9836 |
|
| 9837 |
function asin$1(x) { |
| 9838 |
return x > 1 ? halfPi$1 : x < -1 ? -halfPi$1 : Math.asin(x); |
| 9839 |
} |
| 9840 |
|
| 9841 |
function haversin(x) { |
| 9842 |
return (x = sin$1(x / 2)) * x; |
| 9843 |
} |
| 9844 |
|
| 9845 |
function noop$1() {} |
| 9846 |
|
| 9847 |
function streamGeometry(geometry, stream) { |
| 9848 |
if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) { |
| 9849 |
streamGeometryType[geometry.type](geometry, stream); |
| 9850 |
} |
| 9851 |
} |
| 9852 |
|
| 9853 |
var streamObjectType = { |
| 9854 |
Feature: function(object, stream) { |
| 9855 |
streamGeometry(object.geometry, stream); |
| 9856 |
}, |
| 9857 |
FeatureCollection: function(object, stream) { |
| 9858 |
var features = object.features, i = -1, n = features.length; |
| 9859 |
while (++i < n) streamGeometry(features[i].geometry, stream); |
| 9860 |
} |
| 9861 |
}; |
| 9862 |
|
| 9863 |
var streamGeometryType = { |
| 9864 |
Sphere: function(object, stream) { |
| 9865 |
stream.sphere(); |
| 9866 |
}, |
| 9867 |
Point: function(object, stream) { |
| 9868 |
object = object.coordinates; |
| 9869 |
stream.point(object[0], object[1], object[2]); |
| 9870 |
}, |
| 9871 |
MultiPoint: function(object, stream) { |
| 9872 |
var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 9873 |
while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]); |
| 9874 |
}, |
| 9875 |
LineString: function(object, stream) { |
| 9876 |
streamLine(object.coordinates, stream, 0); |
| 9877 |
}, |
| 9878 |
MultiLineString: function(object, stream) { |
| 9879 |
var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 9880 |
while (++i < n) streamLine(coordinates[i], stream, 0); |
| 9881 |
}, |
| 9882 |
Polygon: function(object, stream) { |
| 9883 |
streamPolygon(object.coordinates, stream); |
| 9884 |
}, |
| 9885 |
MultiPolygon: function(object, stream) { |
| 9886 |
var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 9887 |
while (++i < n) streamPolygon(coordinates[i], stream); |
| 9888 |
}, |
| 9889 |
GeometryCollection: function(object, stream) { |
| 9890 |
var geometries = object.geometries, i = -1, n = geometries.length; |
| 9891 |
while (++i < n) streamGeometry(geometries[i], stream); |
| 9892 |
} |
| 9893 |
}; |
| 9894 |
|
| 9895 |
function streamLine(coordinates, stream, closed) { |
| 9896 |
var i = -1, n = coordinates.length - closed, coordinate; |
| 9897 |
stream.lineStart(); |
| 9898 |
while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]); |
| 9899 |
stream.lineEnd(); |
| 9900 |
} |
| 9901 |
|
| 9902 |
function streamPolygon(coordinates, stream) { |
| 9903 |
var i = -1, n = coordinates.length; |
| 9904 |
stream.polygonStart(); |
| 9905 |
while (++i < n) streamLine(coordinates[i], stream, 1); |
| 9906 |
stream.polygonEnd(); |
| 9907 |
} |
| 9908 |
|
| 9909 |
function geoStream(object, stream) { |
| 9910 |
if (object && streamObjectType.hasOwnProperty(object.type)) { |
| 9911 |
streamObjectType[object.type](object, stream); |
| 9912 |
} else { |
| 9913 |
streamGeometry(object, stream); |
| 9914 |
} |
| 9915 |
} |
| 9916 |
|
| 9917 |
var areaRingSum$1 = new Adder(); |
| 9918 |
|
| 9919 |
// hello? |
| 9920 |
|
| 9921 |
var areaSum$1 = new Adder(), |
| 9922 |
lambda00$2, |
| 9923 |
phi00$2, |
| 9924 |
lambda0$2, |
| 9925 |
cosPhi0$1, |
| 9926 |
sinPhi0$1; |
| 9927 |
|
| 9928 |
var areaStream$1 = { |
| 9929 |
point: noop$1, |
| 9930 |
lineStart: noop$1, |
| 9931 |
lineEnd: noop$1, |
| 9932 |
polygonStart: function() { |
| 9933 |
areaRingSum$1 = new Adder(); |
| 9934 |
areaStream$1.lineStart = areaRingStart$1; |
| 9935 |
areaStream$1.lineEnd = areaRingEnd$1; |
| 9936 |
}, |
| 9937 |
polygonEnd: function() { |
| 9938 |
var areaRing = +areaRingSum$1; |
| 9939 |
areaSum$1.add(areaRing < 0 ? tau$1 + areaRing : areaRing); |
| 9940 |
this.lineStart = this.lineEnd = this.point = noop$1; |
| 9941 |
}, |
| 9942 |
sphere: function() { |
| 9943 |
areaSum$1.add(tau$1); |
| 9944 |
} |
| 9945 |
}; |
| 9946 |
|
| 9947 |
function areaRingStart$1() { |
| 9948 |
areaStream$1.point = areaPointFirst$1; |
| 9949 |
} |
| 9950 |
|
| 9951 |
function areaRingEnd$1() { |
| 9952 |
areaPoint$1(lambda00$2, phi00$2); |
| 9953 |
} |
| 9954 |
|
| 9955 |
function areaPointFirst$1(lambda, phi) { |
| 9956 |
areaStream$1.point = areaPoint$1; |
| 9957 |
lambda00$2 = lambda, phi00$2 = phi; |
| 9958 |
lambda *= radians, phi *= radians; |
| 9959 |
lambda0$2 = lambda, cosPhi0$1 = cos$1(phi = phi / 2 + quarterPi), sinPhi0$1 = sin$1(phi); |
| 9960 |
} |
| 9961 |
|
| 9962 |
function areaPoint$1(lambda, phi) { |
| 9963 |
lambda *= radians, phi *= radians; |
| 9964 |
phi = phi / 2 + quarterPi; // half the angular distance from south pole |
| 9965 |
|
| 9966 |
// Spherical excess E for a spherical triangle with vertices: south pole, |
| 9967 |
// previous point, current point. Uses a formula derived from Cagnoli’s |
| 9968 |
// theorem. See Todhunter, Spherical Trig. (1871), Sec. 103, Eq. (2). |
| 9969 |
var dLambda = lambda - lambda0$2, |
| 9970 |
sdLambda = dLambda >= 0 ? 1 : -1, |
| 9971 |
adLambda = sdLambda * dLambda, |
| 9972 |
cosPhi = cos$1(phi), |
| 9973 |
sinPhi = sin$1(phi), |
| 9974 |
k = sinPhi0$1 * sinPhi, |
| 9975 |
u = cosPhi0$1 * cosPhi + k * cos$1(adLambda), |
| 9976 |
v = k * sdLambda * sin$1(adLambda); |
| 9977 |
areaRingSum$1.add(atan2$1(v, u)); |
| 9978 |
|
| 9979 |
// Advance the previous points. |
| 9980 |
lambda0$2 = lambda, cosPhi0$1 = cosPhi, sinPhi0$1 = sinPhi; |
| 9981 |
} |
| 9982 |
|
| 9983 |
function area$2(object) { |
| 9984 |
areaSum$1 = new Adder(); |
| 9985 |
geoStream(object, areaStream$1); |
| 9986 |
return areaSum$1 * 2; |
| 9987 |
} |
| 9988 |
|
| 9989 |
function spherical(cartesian) { |
| 9990 |
return [atan2$1(cartesian[1], cartesian[0]), asin$1(cartesian[2])]; |
| 9991 |
} |
| 9992 |
|
| 9993 |
function cartesian(spherical) { |
| 9994 |
var lambda = spherical[0], phi = spherical[1], cosPhi = cos$1(phi); |
| 9995 |
return [cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)]; |
| 9996 |
} |
| 9997 |
|
| 9998 |
function cartesianDot(a, b) { |
| 9999 |
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; |
| 10000 |
} |
| 10001 |
|
| 10002 |
function cartesianCross(a, b) { |
| 10003 |
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]]; |
| 10004 |
} |
| 10005 |
|
| 10006 |
// TODO return a |
| 10007 |
function cartesianAddInPlace(a, b) { |
| 10008 |
a[0] += b[0], a[1] += b[1], a[2] += b[2]; |
| 10009 |
} |
| 10010 |
|
| 10011 |
function cartesianScale(vector, k) { |
| 10012 |
return [vector[0] * k, vector[1] * k, vector[2] * k]; |
| 10013 |
} |
| 10014 |
|
| 10015 |
// TODO return d |
| 10016 |
function cartesianNormalizeInPlace(d) { |
| 10017 |
var l = sqrt$2(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]); |
| 10018 |
d[0] /= l, d[1] /= l, d[2] /= l; |
| 10019 |
} |
| 10020 |
|
| 10021 |
var lambda0$1, phi0, lambda1, phi1, // bounds |
| 10022 |
lambda2, // previous lambda-coordinate |
| 10023 |
lambda00$1, phi00$1, // first point |
| 10024 |
p0, // previous 3D point |
| 10025 |
deltaSum, |
| 10026 |
ranges, |
| 10027 |
range; |
| 10028 |
|
| 10029 |
var boundsStream$2 = { |
| 10030 |
point: boundsPoint$1, |
| 10031 |
lineStart: boundsLineStart, |
| 10032 |
lineEnd: boundsLineEnd, |
| 10033 |
polygonStart: function() { |
| 10034 |
boundsStream$2.point = boundsRingPoint; |
| 10035 |
boundsStream$2.lineStart = boundsRingStart; |
| 10036 |
boundsStream$2.lineEnd = boundsRingEnd; |
| 10037 |
deltaSum = new Adder(); |
| 10038 |
areaStream$1.polygonStart(); |
| 10039 |
}, |
| 10040 |
polygonEnd: function() { |
| 10041 |
areaStream$1.polygonEnd(); |
| 10042 |
boundsStream$2.point = boundsPoint$1; |
| 10043 |
boundsStream$2.lineStart = boundsLineStart; |
| 10044 |
boundsStream$2.lineEnd = boundsLineEnd; |
| 10045 |
if (areaRingSum$1 < 0) lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90); |
| 10046 |
else if (deltaSum > epsilon$1) phi1 = 90; |
| 10047 |
else if (deltaSum < -epsilon$1) phi0 = -90; |
| 10048 |
range[0] = lambda0$1, range[1] = lambda1; |
| 10049 |
}, |
| 10050 |
sphere: function() { |
| 10051 |
lambda0$1 = -(lambda1 = 180), phi0 = -(phi1 = 90); |
| 10052 |
} |
| 10053 |
}; |
| 10054 |
|
| 10055 |
function boundsPoint$1(lambda, phi) { |
| 10056 |
ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]); |
| 10057 |
if (phi < phi0) phi0 = phi; |
| 10058 |
if (phi > phi1) phi1 = phi; |
| 10059 |
} |
| 10060 |
|
| 10061 |
function linePoint(lambda, phi) { |
| 10062 |
var p = cartesian([lambda * radians, phi * radians]); |
| 10063 |
if (p0) { |
| 10064 |
var normal = cartesianCross(p0, p), |
| 10065 |
equatorial = [normal[1], -normal[0], 0], |
| 10066 |
inflection = cartesianCross(equatorial, normal); |
| 10067 |
cartesianNormalizeInPlace(inflection); |
| 10068 |
inflection = spherical(inflection); |
| 10069 |
var delta = lambda - lambda2, |
| 10070 |
sign = delta > 0 ? 1 : -1, |
| 10071 |
lambdai = inflection[0] * degrees * sign, |
| 10072 |
phii, |
| 10073 |
antimeridian = abs$1(delta) > 180; |
| 10074 |
if (antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) { |
| 10075 |
phii = inflection[1] * degrees; |
| 10076 |
if (phii > phi1) phi1 = phii; |
| 10077 |
} else if (lambdai = (lambdai + 360) % 360 - 180, antimeridian ^ (sign * lambda2 < lambdai && lambdai < sign * lambda)) { |
| 10078 |
phii = -inflection[1] * degrees; |
| 10079 |
if (phii < phi0) phi0 = phii; |
| 10080 |
} else { |
| 10081 |
if (phi < phi0) phi0 = phi; |
| 10082 |
if (phi > phi1) phi1 = phi; |
| 10083 |
} |
| 10084 |
if (antimeridian) { |
| 10085 |
if (lambda < lambda2) { |
| 10086 |
if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda; |
| 10087 |
} else { |
| 10088 |
if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda; |
| 10089 |
} |
| 10090 |
} else { |
| 10091 |
if (lambda1 >= lambda0$1) { |
| 10092 |
if (lambda < lambda0$1) lambda0$1 = lambda; |
| 10093 |
if (lambda > lambda1) lambda1 = lambda; |
| 10094 |
} else { |
| 10095 |
if (lambda > lambda2) { |
| 10096 |
if (angle(lambda0$1, lambda) > angle(lambda0$1, lambda1)) lambda1 = lambda; |
| 10097 |
} else { |
| 10098 |
if (angle(lambda, lambda1) > angle(lambda0$1, lambda1)) lambda0$1 = lambda; |
| 10099 |
} |
| 10100 |
} |
| 10101 |
} |
| 10102 |
} else { |
| 10103 |
ranges.push(range = [lambda0$1 = lambda, lambda1 = lambda]); |
| 10104 |
} |
| 10105 |
if (phi < phi0) phi0 = phi; |
| 10106 |
if (phi > phi1) phi1 = phi; |
| 10107 |
p0 = p, lambda2 = lambda; |
| 10108 |
} |
| 10109 |
|
| 10110 |
function boundsLineStart() { |
| 10111 |
boundsStream$2.point = linePoint; |
| 10112 |
} |
| 10113 |
|
| 10114 |
function boundsLineEnd() { |
| 10115 |
range[0] = lambda0$1, range[1] = lambda1; |
| 10116 |
boundsStream$2.point = boundsPoint$1; |
| 10117 |
p0 = null; |
| 10118 |
} |
| 10119 |
|
| 10120 |
function boundsRingPoint(lambda, phi) { |
| 10121 |
if (p0) { |
| 10122 |
var delta = lambda - lambda2; |
| 10123 |
deltaSum.add(abs$1(delta) > 180 ? delta + (delta > 0 ? 360 : -360) : delta); |
| 10124 |
} else { |
| 10125 |
lambda00$1 = lambda, phi00$1 = phi; |
| 10126 |
} |
| 10127 |
areaStream$1.point(lambda, phi); |
| 10128 |
linePoint(lambda, phi); |
| 10129 |
} |
| 10130 |
|
| 10131 |
function boundsRingStart() { |
| 10132 |
areaStream$1.lineStart(); |
| 10133 |
} |
| 10134 |
|
| 10135 |
function boundsRingEnd() { |
| 10136 |
boundsRingPoint(lambda00$1, phi00$1); |
| 10137 |
areaStream$1.lineEnd(); |
| 10138 |
if (abs$1(deltaSum) > epsilon$1) lambda0$1 = -(lambda1 = 180); |
| 10139 |
range[0] = lambda0$1, range[1] = lambda1; |
| 10140 |
p0 = null; |
| 10141 |
} |
| 10142 |
|
| 10143 |
// Finds the left-right distance between two longitudes. |
| 10144 |
// This is almost the same as (lambda1 - lambda0 + 360°) % 360°, except that we want |
| 10145 |
// the distance between ±180° to be 360°. |
| 10146 |
function angle(lambda0, lambda1) { |
| 10147 |
return (lambda1 -= lambda0) < 0 ? lambda1 + 360 : lambda1; |
| 10148 |
} |
| 10149 |
|
| 10150 |
function rangeCompare(a, b) { |
| 10151 |
return a[0] - b[0]; |
| 10152 |
} |
| 10153 |
|
| 10154 |
function rangeContains(range, x) { |
| 10155 |
return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x; |
| 10156 |
} |
| 10157 |
|
| 10158 |
function bounds(feature) { |
| 10159 |
var i, n, a, b, merged, deltaMax, delta; |
| 10160 |
|
| 10161 |
phi1 = lambda1 = -(lambda0$1 = phi0 = Infinity); |
| 10162 |
ranges = []; |
| 10163 |
geoStream(feature, boundsStream$2); |
| 10164 |
|
| 10165 |
// First, sort ranges by their minimum longitudes. |
| 10166 |
if (n = ranges.length) { |
| 10167 |
ranges.sort(rangeCompare); |
| 10168 |
|
| 10169 |
// Then, merge any ranges that overlap. |
| 10170 |
for (i = 1, a = ranges[0], merged = [a]; i < n; ++i) { |
| 10171 |
b = ranges[i]; |
| 10172 |
if (rangeContains(a, b[0]) || rangeContains(a, b[1])) { |
| 10173 |
if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1]; |
| 10174 |
if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0]; |
| 10175 |
} else { |
| 10176 |
merged.push(a = b); |
| 10177 |
} |
| 10178 |
} |
| 10179 |
|
| 10180 |
// Finally, find the largest gap between the merged ranges. |
| 10181 |
// The final bounding box will be the inverse of this gap. |
| 10182 |
for (deltaMax = -Infinity, n = merged.length - 1, i = 0, a = merged[n]; i <= n; a = b, ++i) { |
| 10183 |
b = merged[i]; |
| 10184 |
if ((delta = angle(a[1], b[0])) > deltaMax) deltaMax = delta, lambda0$1 = b[0], lambda1 = a[1]; |
| 10185 |
} |
| 10186 |
} |
| 10187 |
|
| 10188 |
ranges = range = null; |
| 10189 |
|
| 10190 |
return lambda0$1 === Infinity || phi0 === Infinity |
| 10191 |
? [[NaN, NaN], [NaN, NaN]] |
| 10192 |
: [[lambda0$1, phi0], [lambda1, phi1]]; |
| 10193 |
} |
| 10194 |
|
| 10195 |
var W0, W1, |
| 10196 |
X0$1, Y0$1, Z0$1, |
| 10197 |
X1$1, Y1$1, Z1$1, |
| 10198 |
X2$1, Y2$1, Z2$1, |
| 10199 |
lambda00, phi00, // first point |
| 10200 |
x0$4, y0$4, z0; // previous point |
| 10201 |
|
| 10202 |
var centroidStream$1 = { |
| 10203 |
sphere: noop$1, |
| 10204 |
point: centroidPoint$1, |
| 10205 |
lineStart: centroidLineStart$1, |
| 10206 |
lineEnd: centroidLineEnd$1, |
| 10207 |
polygonStart: function() { |
| 10208 |
centroidStream$1.lineStart = centroidRingStart$1; |
| 10209 |
centroidStream$1.lineEnd = centroidRingEnd$1; |
| 10210 |
}, |
| 10211 |
polygonEnd: function() { |
| 10212 |
centroidStream$1.lineStart = centroidLineStart$1; |
| 10213 |
centroidStream$1.lineEnd = centroidLineEnd$1; |
| 10214 |
} |
| 10215 |
}; |
| 10216 |
|
| 10217 |
// Arithmetic mean of Cartesian vectors. |
| 10218 |
function centroidPoint$1(lambda, phi) { |
| 10219 |
lambda *= radians, phi *= radians; |
| 10220 |
var cosPhi = cos$1(phi); |
| 10221 |
centroidPointCartesian(cosPhi * cos$1(lambda), cosPhi * sin$1(lambda), sin$1(phi)); |
| 10222 |
} |
| 10223 |
|
| 10224 |
function centroidPointCartesian(x, y, z) { |
| 10225 |
++W0; |
| 10226 |
X0$1 += (x - X0$1) / W0; |
| 10227 |
Y0$1 += (y - Y0$1) / W0; |
| 10228 |
Z0$1 += (z - Z0$1) / W0; |
| 10229 |
} |
| 10230 |
|
| 10231 |
function centroidLineStart$1() { |
| 10232 |
centroidStream$1.point = centroidLinePointFirst; |
| 10233 |
} |
| 10234 |
|
| 10235 |
function centroidLinePointFirst(lambda, phi) { |
| 10236 |
lambda *= radians, phi *= radians; |
| 10237 |
var cosPhi = cos$1(phi); |
| 10238 |
x0$4 = cosPhi * cos$1(lambda); |
| 10239 |
y0$4 = cosPhi * sin$1(lambda); |
| 10240 |
z0 = sin$1(phi); |
| 10241 |
centroidStream$1.point = centroidLinePoint; |
| 10242 |
centroidPointCartesian(x0$4, y0$4, z0); |
| 10243 |
} |
| 10244 |
|
| 10245 |
function centroidLinePoint(lambda, phi) { |
| 10246 |
lambda *= radians, phi *= radians; |
| 10247 |
var cosPhi = cos$1(phi), |
| 10248 |
x = cosPhi * cos$1(lambda), |
| 10249 |
y = cosPhi * sin$1(lambda), |
| 10250 |
z = sin$1(phi), |
| 10251 |
w = atan2$1(sqrt$2((w = y0$4 * z - z0 * y) * w + (w = z0 * x - x0$4 * z) * w + (w = x0$4 * y - y0$4 * x) * w), x0$4 * x + y0$4 * y + z0 * z); |
| 10252 |
W1 += w; |
| 10253 |
X1$1 += w * (x0$4 + (x0$4 = x)); |
| 10254 |
Y1$1 += w * (y0$4 + (y0$4 = y)); |
| 10255 |
Z1$1 += w * (z0 + (z0 = z)); |
| 10256 |
centroidPointCartesian(x0$4, y0$4, z0); |
| 10257 |
} |
| 10258 |
|
| 10259 |
function centroidLineEnd$1() { |
| 10260 |
centroidStream$1.point = centroidPoint$1; |
| 10261 |
} |
| 10262 |
|
| 10263 |
// See J. E. Brock, The Inertia Tensor for a Spherical Triangle, |
| 10264 |
// J. Applied Mechanics 42, 239 (1975). |
| 10265 |
function centroidRingStart$1() { |
| 10266 |
centroidStream$1.point = centroidRingPointFirst; |
| 10267 |
} |
| 10268 |
|
| 10269 |
function centroidRingEnd$1() { |
| 10270 |
centroidRingPoint(lambda00, phi00); |
| 10271 |
centroidStream$1.point = centroidPoint$1; |
| 10272 |
} |
| 10273 |
|
| 10274 |
function centroidRingPointFirst(lambda, phi) { |
| 10275 |
lambda00 = lambda, phi00 = phi; |
| 10276 |
lambda *= radians, phi *= radians; |
| 10277 |
centroidStream$1.point = centroidRingPoint; |
| 10278 |
var cosPhi = cos$1(phi); |
| 10279 |
x0$4 = cosPhi * cos$1(lambda); |
| 10280 |
y0$4 = cosPhi * sin$1(lambda); |
| 10281 |
z0 = sin$1(phi); |
| 10282 |
centroidPointCartesian(x0$4, y0$4, z0); |
| 10283 |
} |
| 10284 |
|
| 10285 |
function centroidRingPoint(lambda, phi) { |
| 10286 |
lambda *= radians, phi *= radians; |
| 10287 |
var cosPhi = cos$1(phi), |
| 10288 |
x = cosPhi * cos$1(lambda), |
| 10289 |
y = cosPhi * sin$1(lambda), |
| 10290 |
z = sin$1(phi), |
| 10291 |
cx = y0$4 * z - z0 * y, |
| 10292 |
cy = z0 * x - x0$4 * z, |
| 10293 |
cz = x0$4 * y - y0$4 * x, |
| 10294 |
m = hypot(cx, cy, cz), |
| 10295 |
w = asin$1(m), // line weight = angle |
| 10296 |
v = m && -w / m; // area weight multiplier |
| 10297 |
X2$1.add(v * cx); |
| 10298 |
Y2$1.add(v * cy); |
| 10299 |
Z2$1.add(v * cz); |
| 10300 |
W1 += w; |
| 10301 |
X1$1 += w * (x0$4 + (x0$4 = x)); |
| 10302 |
Y1$1 += w * (y0$4 + (y0$4 = y)); |
| 10303 |
Z1$1 += w * (z0 + (z0 = z)); |
| 10304 |
centroidPointCartesian(x0$4, y0$4, z0); |
| 10305 |
} |
| 10306 |
|
| 10307 |
function centroid$1(object) { |
| 10308 |
W0 = W1 = |
| 10309 |
X0$1 = Y0$1 = Z0$1 = |
| 10310 |
X1$1 = Y1$1 = Z1$1 = 0; |
| 10311 |
X2$1 = new Adder(); |
| 10312 |
Y2$1 = new Adder(); |
| 10313 |
Z2$1 = new Adder(); |
| 10314 |
geoStream(object, centroidStream$1); |
| 10315 |
|
| 10316 |
var x = +X2$1, |
| 10317 |
y = +Y2$1, |
| 10318 |
z = +Z2$1, |
| 10319 |
m = hypot(x, y, z); |
| 10320 |
|
| 10321 |
// If the area-weighted ccentroid is undefined, fall back to length-weighted ccentroid. |
| 10322 |
if (m < epsilon2) { |
| 10323 |
x = X1$1, y = Y1$1, z = Z1$1; |
| 10324 |
// If the feature has zero length, fall back to arithmetic mean of point vectors. |
| 10325 |
if (W1 < epsilon$1) x = X0$1, y = Y0$1, z = Z0$1; |
| 10326 |
m = hypot(x, y, z); |
| 10327 |
// If the feature still has an undefined ccentroid, then return. |
| 10328 |
if (m < epsilon2) return [NaN, NaN]; |
| 10329 |
} |
| 10330 |
|
| 10331 |
return [atan2$1(y, x) * degrees, asin$1(z / m) * degrees]; |
| 10332 |
} |
| 10333 |
|
| 10334 |
function constant$3(x) { |
| 10335 |
return function() { |
| 10336 |
return x; |
| 10337 |
}; |
| 10338 |
} |
| 10339 |
|
| 10340 |
function compose(a, b) { |
| 10341 |
|
| 10342 |
function compose(x, y) { |
| 10343 |
return x = a(x, y), b(x[0], x[1]); |
| 10344 |
} |
| 10345 |
|
| 10346 |
if (a.invert && b.invert) compose.invert = function(x, y) { |
| 10347 |
return x = b.invert(x, y), x && a.invert(x[0], x[1]); |
| 10348 |
}; |
| 10349 |
|
| 10350 |
return compose; |
| 10351 |
} |
| 10352 |
|
| 10353 |
function rotationIdentity(lambda, phi) { |
| 10354 |
if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1; |
| 10355 |
return [lambda, phi]; |
| 10356 |
} |
| 10357 |
|
| 10358 |
rotationIdentity.invert = rotationIdentity; |
| 10359 |
|
| 10360 |
function rotateRadians(deltaLambda, deltaPhi, deltaGamma) { |
| 10361 |
return (deltaLambda %= tau$1) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma)) |
| 10362 |
: rotationLambda(deltaLambda)) |
| 10363 |
: (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma) |
| 10364 |
: rotationIdentity); |
| 10365 |
} |
| 10366 |
|
| 10367 |
function forwardRotationLambda(deltaLambda) { |
| 10368 |
return function(lambda, phi) { |
| 10369 |
lambda += deltaLambda; |
| 10370 |
if (abs$1(lambda) > pi$1) lambda -= Math.round(lambda / tau$1) * tau$1; |
| 10371 |
return [lambda, phi]; |
| 10372 |
}; |
| 10373 |
} |
| 10374 |
|
| 10375 |
function rotationLambda(deltaLambda) { |
| 10376 |
var rotation = forwardRotationLambda(deltaLambda); |
| 10377 |
rotation.invert = forwardRotationLambda(-deltaLambda); |
| 10378 |
return rotation; |
| 10379 |
} |
| 10380 |
|
| 10381 |
function rotationPhiGamma(deltaPhi, deltaGamma) { |
| 10382 |
var cosDeltaPhi = cos$1(deltaPhi), |
| 10383 |
sinDeltaPhi = sin$1(deltaPhi), |
| 10384 |
cosDeltaGamma = cos$1(deltaGamma), |
| 10385 |
sinDeltaGamma = sin$1(deltaGamma); |
| 10386 |
|
| 10387 |
function rotation(lambda, phi) { |
| 10388 |
var cosPhi = cos$1(phi), |
| 10389 |
x = cos$1(lambda) * cosPhi, |
| 10390 |
y = sin$1(lambda) * cosPhi, |
| 10391 |
z = sin$1(phi), |
| 10392 |
k = z * cosDeltaPhi + x * sinDeltaPhi; |
| 10393 |
return [ |
| 10394 |
atan2$1(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi), |
| 10395 |
asin$1(k * cosDeltaGamma + y * sinDeltaGamma) |
| 10396 |
]; |
| 10397 |
} |
| 10398 |
|
| 10399 |
rotation.invert = function(lambda, phi) { |
| 10400 |
var cosPhi = cos$1(phi), |
| 10401 |
x = cos$1(lambda) * cosPhi, |
| 10402 |
y = sin$1(lambda) * cosPhi, |
| 10403 |
z = sin$1(phi), |
| 10404 |
k = z * cosDeltaGamma - y * sinDeltaGamma; |
| 10405 |
return [ |
| 10406 |
atan2$1(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi), |
| 10407 |
asin$1(k * cosDeltaPhi - x * sinDeltaPhi) |
| 10408 |
]; |
| 10409 |
}; |
| 10410 |
|
| 10411 |
return rotation; |
| 10412 |
} |
| 10413 |
|
| 10414 |
function rotation(rotate) { |
| 10415 |
rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0); |
| 10416 |
|
| 10417 |
function forward(coordinates) { |
| 10418 |
coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians); |
| 10419 |
return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates; |
| 10420 |
} |
| 10421 |
|
| 10422 |
forward.invert = function(coordinates) { |
| 10423 |
coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians); |
| 10424 |
return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates; |
| 10425 |
}; |
| 10426 |
|
| 10427 |
return forward; |
| 10428 |
} |
| 10429 |
|
| 10430 |
// Generates a circle centered at [0°, 0°], with a given radius and precision. |
| 10431 |
function circleStream(stream, radius, delta, direction, t0, t1) { |
| 10432 |
if (!delta) return; |
| 10433 |
var cosRadius = cos$1(radius), |
| 10434 |
sinRadius = sin$1(radius), |
| 10435 |
step = direction * delta; |
| 10436 |
if (t0 == null) { |
| 10437 |
t0 = radius + direction * tau$1; |
| 10438 |
t1 = radius - step / 2; |
| 10439 |
} else { |
| 10440 |
t0 = circleRadius(cosRadius, t0); |
| 10441 |
t1 = circleRadius(cosRadius, t1); |
| 10442 |
if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau$1; |
| 10443 |
} |
| 10444 |
for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) { |
| 10445 |
point = spherical([cosRadius, -sinRadius * cos$1(t), -sinRadius * sin$1(t)]); |
| 10446 |
stream.point(point[0], point[1]); |
| 10447 |
} |
| 10448 |
} |
| 10449 |
|
| 10450 |
// Returns the signed angle of a cartesian point relative to [cosRadius, 0, 0]. |
| 10451 |
function circleRadius(cosRadius, point) { |
| 10452 |
point = cartesian(point), point[0] -= cosRadius; |
| 10453 |
cartesianNormalizeInPlace(point); |
| 10454 |
var radius = acos$1(-point[1]); |
| 10455 |
return ((-point[2] < 0 ? -radius : radius) + tau$1 - epsilon$1) % tau$1; |
| 10456 |
} |
| 10457 |
|
| 10458 |
function circle$1() { |
| 10459 |
var center = constant$3([0, 0]), |
| 10460 |
radius = constant$3(90), |
| 10461 |
precision = constant$3(2), |
| 10462 |
ring, |
| 10463 |
rotate, |
| 10464 |
stream = {point: point}; |
| 10465 |
|
| 10466 |
function point(x, y) { |
| 10467 |
ring.push(x = rotate(x, y)); |
| 10468 |
x[0] *= degrees, x[1] *= degrees; |
| 10469 |
} |
| 10470 |
|
| 10471 |
function circle() { |
| 10472 |
var c = center.apply(this, arguments), |
| 10473 |
r = radius.apply(this, arguments) * radians, |
| 10474 |
p = precision.apply(this, arguments) * radians; |
| 10475 |
ring = []; |
| 10476 |
rotate = rotateRadians(-c[0] * radians, -c[1] * radians, 0).invert; |
| 10477 |
circleStream(stream, r, p, 1); |
| 10478 |
c = {type: "Polygon", coordinates: [ring]}; |
| 10479 |
ring = rotate = null; |
| 10480 |
return c; |
| 10481 |
} |
| 10482 |
|
| 10483 |
circle.center = function(_) { |
| 10484 |
return arguments.length ? (center = typeof _ === "function" ? _ : constant$3([+_[0], +_[1]]), circle) : center; |
| 10485 |
}; |
| 10486 |
|
| 10487 |
circle.radius = function(_) { |
| 10488 |
return arguments.length ? (radius = typeof _ === "function" ? _ : constant$3(+_), circle) : radius; |
| 10489 |
}; |
| 10490 |
|
| 10491 |
circle.precision = function(_) { |
| 10492 |
return arguments.length ? (precision = typeof _ === "function" ? _ : constant$3(+_), circle) : precision; |
| 10493 |
}; |
| 10494 |
|
| 10495 |
return circle; |
| 10496 |
} |
| 10497 |
|
| 10498 |
function clipBuffer() { |
| 10499 |
var lines = [], |
| 10500 |
line; |
| 10501 |
return { |
| 10502 |
point: function(x, y, m) { |
| 10503 |
line.push([x, y, m]); |
| 10504 |
}, |
| 10505 |
lineStart: function() { |
| 10506 |
lines.push(line = []); |
| 10507 |
}, |
| 10508 |
lineEnd: noop$1, |
| 10509 |
rejoin: function() { |
| 10510 |
if (lines.length > 1) lines.push(lines.pop().concat(lines.shift())); |
| 10511 |
}, |
| 10512 |
result: function() { |
| 10513 |
var result = lines; |
| 10514 |
lines = []; |
| 10515 |
line = null; |
| 10516 |
return result; |
| 10517 |
} |
| 10518 |
}; |
| 10519 |
} |
| 10520 |
|
| 10521 |
function pointEqual(a, b) { |
| 10522 |
return abs$1(a[0] - b[0]) < epsilon$1 && abs$1(a[1] - b[1]) < epsilon$1; |
| 10523 |
} |
| 10524 |
|
| 10525 |
function Intersection(point, points, other, entry) { |
| 10526 |
this.x = point; |
| 10527 |
this.z = points; |
| 10528 |
this.o = other; // another intersection |
| 10529 |
this.e = entry; // is an entry? |
| 10530 |
this.v = false; // visited |
| 10531 |
this.n = this.p = null; // next & previous |
| 10532 |
} |
| 10533 |
|
| 10534 |
// A generalized polygon clipping algorithm: given a polygon that has been cut |
| 10535 |
// into its visible line segments, and rejoins the segments by interpolating |
| 10536 |
// along the clip edge. |
| 10537 |
function clipRejoin(segments, compareIntersection, startInside, interpolate, stream) { |
| 10538 |
var subject = [], |
| 10539 |
clip = [], |
| 10540 |
i, |
| 10541 |
n; |
| 10542 |
|
| 10543 |
segments.forEach(function(segment) { |
| 10544 |
if ((n = segment.length - 1) <= 0) return; |
| 10545 |
var n, p0 = segment[0], p1 = segment[n], x; |
| 10546 |
|
| 10547 |
if (pointEqual(p0, p1)) { |
| 10548 |
if (!p0[2] && !p1[2]) { |
| 10549 |
stream.lineStart(); |
| 10550 |
for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]); |
| 10551 |
stream.lineEnd(); |
| 10552 |
return; |
| 10553 |
} |
| 10554 |
// handle degenerate cases by moving the point |
| 10555 |
p1[0] += 2 * epsilon$1; |
| 10556 |
} |
| 10557 |
|
| 10558 |
subject.push(x = new Intersection(p0, segment, null, true)); |
| 10559 |
clip.push(x.o = new Intersection(p0, null, x, false)); |
| 10560 |
subject.push(x = new Intersection(p1, segment, null, false)); |
| 10561 |
clip.push(x.o = new Intersection(p1, null, x, true)); |
| 10562 |
}); |
| 10563 |
|
| 10564 |
if (!subject.length) return; |
| 10565 |
|
| 10566 |
clip.sort(compareIntersection); |
| 10567 |
link$1(subject); |
| 10568 |
link$1(clip); |
| 10569 |
|
| 10570 |
for (i = 0, n = clip.length; i < n; ++i) { |
| 10571 |
clip[i].e = startInside = !startInside; |
| 10572 |
} |
| 10573 |
|
| 10574 |
var start = subject[0], |
| 10575 |
points, |
| 10576 |
point; |
| 10577 |
|
| 10578 |
while (1) { |
| 10579 |
// Find first unvisited intersection. |
| 10580 |
var current = start, |
| 10581 |
isSubject = true; |
| 10582 |
while (current.v) if ((current = current.n) === start) return; |
| 10583 |
points = current.z; |
| 10584 |
stream.lineStart(); |
| 10585 |
do { |
| 10586 |
current.v = current.o.v = true; |
| 10587 |
if (current.e) { |
| 10588 |
if (isSubject) { |
| 10589 |
for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]); |
| 10590 |
} else { |
| 10591 |
interpolate(current.x, current.n.x, 1, stream); |
| 10592 |
} |
| 10593 |
current = current.n; |
| 10594 |
} else { |
| 10595 |
if (isSubject) { |
| 10596 |
points = current.p.z; |
| 10597 |
for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]); |
| 10598 |
} else { |
| 10599 |
interpolate(current.x, current.p.x, -1, stream); |
| 10600 |
} |
| 10601 |
current = current.p; |
| 10602 |
} |
| 10603 |
current = current.o; |
| 10604 |
points = current.z; |
| 10605 |
isSubject = !isSubject; |
| 10606 |
} while (!current.v); |
| 10607 |
stream.lineEnd(); |
| 10608 |
} |
| 10609 |
} |
| 10610 |
|
| 10611 |
function link$1(array) { |
| 10612 |
if (!(n = array.length)) return; |
| 10613 |
var n, |
| 10614 |
i = 0, |
| 10615 |
a = array[0], |
| 10616 |
b; |
| 10617 |
while (++i < n) { |
| 10618 |
a.n = b = array[i]; |
| 10619 |
b.p = a; |
| 10620 |
a = b; |
| 10621 |
} |
| 10622 |
a.n = b = array[0]; |
| 10623 |
b.p = a; |
| 10624 |
} |
| 10625 |
|
| 10626 |
function longitude(point) { |
| 10627 |
return abs$1(point[0]) <= pi$1 ? point[0] : sign$1(point[0]) * ((abs$1(point[0]) + pi$1) % tau$1 - pi$1); |
| 10628 |
} |
| 10629 |
|
| 10630 |
function polygonContains(polygon, point) { |
| 10631 |
var lambda = longitude(point), |
| 10632 |
phi = point[1], |
| 10633 |
sinPhi = sin$1(phi), |
| 10634 |
normal = [sin$1(lambda), -cos$1(lambda), 0], |
| 10635 |
angle = 0, |
| 10636 |
winding = 0; |
| 10637 |
|
| 10638 |
var sum = new Adder(); |
| 10639 |
|
| 10640 |
if (sinPhi === 1) phi = halfPi$1 + epsilon$1; |
| 10641 |
else if (sinPhi === -1) phi = -halfPi$1 - epsilon$1; |
| 10642 |
|
| 10643 |
for (var i = 0, n = polygon.length; i < n; ++i) { |
| 10644 |
if (!(m = (ring = polygon[i]).length)) continue; |
| 10645 |
var ring, |
| 10646 |
m, |
| 10647 |
point0 = ring[m - 1], |
| 10648 |
lambda0 = longitude(point0), |
| 10649 |
phi0 = point0[1] / 2 + quarterPi, |
| 10650 |
sinPhi0 = sin$1(phi0), |
| 10651 |
cosPhi0 = cos$1(phi0); |
| 10652 |
|
| 10653 |
for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) { |
| 10654 |
var point1 = ring[j], |
| 10655 |
lambda1 = longitude(point1), |
| 10656 |
phi1 = point1[1] / 2 + quarterPi, |
| 10657 |
sinPhi1 = sin$1(phi1), |
| 10658 |
cosPhi1 = cos$1(phi1), |
| 10659 |
delta = lambda1 - lambda0, |
| 10660 |
sign = delta >= 0 ? 1 : -1, |
| 10661 |
absDelta = sign * delta, |
| 10662 |
antimeridian = absDelta > pi$1, |
| 10663 |
k = sinPhi0 * sinPhi1; |
| 10664 |
|
| 10665 |
sum.add(atan2$1(k * sign * sin$1(absDelta), cosPhi0 * cosPhi1 + k * cos$1(absDelta))); |
| 10666 |
angle += antimeridian ? delta + sign * tau$1 : delta; |
| 10667 |
|
| 10668 |
// Are the longitudes either side of the point’s meridian (lambda), |
| 10669 |
// and are the latitudes smaller than the parallel (phi)? |
| 10670 |
if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) { |
| 10671 |
var arc = cartesianCross(cartesian(point0), cartesian(point1)); |
| 10672 |
cartesianNormalizeInPlace(arc); |
| 10673 |
var intersection = cartesianCross(normal, arc); |
| 10674 |
cartesianNormalizeInPlace(intersection); |
| 10675 |
var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin$1(intersection[2]); |
| 10676 |
if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) { |
| 10677 |
winding += antimeridian ^ delta >= 0 ? 1 : -1; |
| 10678 |
} |
| 10679 |
} |
| 10680 |
} |
| 10681 |
} |
| 10682 |
|
| 10683 |
// First, determine whether the South pole is inside or outside: |
| 10684 |
// |
| 10685 |
// It is inside if: |
| 10686 |
// * the polygon winds around it in a clockwise direction. |
| 10687 |
// * the polygon does not (cumulatively) wind around it, but has a negative |
| 10688 |
// (counter-clockwise) area. |
| 10689 |
// |
| 10690 |
// Second, count the (signed) number of times a segment crosses a lambda |
| 10691 |
// from the point to the South pole. If it is zero, then the point is the |
| 10692 |
// same side as the South pole. |
| 10693 |
|
| 10694 |
return (angle < -epsilon$1 || angle < epsilon$1 && sum < -epsilon2) ^ (winding & 1); |
| 10695 |
} |
| 10696 |
|
| 10697 |
function clip(pointVisible, clipLine, interpolate, start) { |
| 10698 |
return function(sink) { |
| 10699 |
var line = clipLine(sink), |
| 10700 |
ringBuffer = clipBuffer(), |
| 10701 |
ringSink = clipLine(ringBuffer), |
| 10702 |
polygonStarted = false, |
| 10703 |
polygon, |
| 10704 |
segments, |
| 10705 |
ring; |
| 10706 |
|
| 10707 |
var clip = { |
| 10708 |
point: point, |
| 10709 |
lineStart: lineStart, |
| 10710 |
lineEnd: lineEnd, |
| 10711 |
polygonStart: function() { |
| 10712 |
clip.point = pointRing; |
| 10713 |
clip.lineStart = ringStart; |
| 10714 |
clip.lineEnd = ringEnd; |
| 10715 |
segments = []; |
| 10716 |
polygon = []; |
| 10717 |
}, |
| 10718 |
polygonEnd: function() { |
| 10719 |
clip.point = point; |
| 10720 |
clip.lineStart = lineStart; |
| 10721 |
clip.lineEnd = lineEnd; |
| 10722 |
segments = merge(segments); |
| 10723 |
var startInside = polygonContains(polygon, start); |
| 10724 |
if (segments.length) { |
| 10725 |
if (!polygonStarted) sink.polygonStart(), polygonStarted = true; |
| 10726 |
clipRejoin(segments, compareIntersection, startInside, interpolate, sink); |
| 10727 |
} else if (startInside) { |
| 10728 |
if (!polygonStarted) sink.polygonStart(), polygonStarted = true; |
| 10729 |
sink.lineStart(); |
| 10730 |
interpolate(null, null, 1, sink); |
| 10731 |
sink.lineEnd(); |
| 10732 |
} |
| 10733 |
if (polygonStarted) sink.polygonEnd(), polygonStarted = false; |
| 10734 |
segments = polygon = null; |
| 10735 |
}, |
| 10736 |
sphere: function() { |
| 10737 |
sink.polygonStart(); |
| 10738 |
sink.lineStart(); |
| 10739 |
interpolate(null, null, 1, sink); |
| 10740 |
sink.lineEnd(); |
| 10741 |
sink.polygonEnd(); |
| 10742 |
} |
| 10743 |
}; |
| 10744 |
|
| 10745 |
function point(lambda, phi) { |
| 10746 |
if (pointVisible(lambda, phi)) sink.point(lambda, phi); |
| 10747 |
} |
| 10748 |
|
| 10749 |
function pointLine(lambda, phi) { |
| 10750 |
line.point(lambda, phi); |
| 10751 |
} |
| 10752 |
|
| 10753 |
function lineStart() { |
| 10754 |
clip.point = pointLine; |
| 10755 |
line.lineStart(); |
| 10756 |
} |
| 10757 |
|
| 10758 |
function lineEnd() { |
| 10759 |
clip.point = point; |
| 10760 |
line.lineEnd(); |
| 10761 |
} |
| 10762 |
|
| 10763 |
function pointRing(lambda, phi) { |
| 10764 |
ring.push([lambda, phi]); |
| 10765 |
ringSink.point(lambda, phi); |
| 10766 |
} |
| 10767 |
|
| 10768 |
function ringStart() { |
| 10769 |
ringSink.lineStart(); |
| 10770 |
ring = []; |
| 10771 |
} |
| 10772 |
|
| 10773 |
function ringEnd() { |
| 10774 |
pointRing(ring[0][0], ring[0][1]); |
| 10775 |
ringSink.lineEnd(); |
| 10776 |
|
| 10777 |
var clean = ringSink.clean(), |
| 10778 |
ringSegments = ringBuffer.result(), |
| 10779 |
i, n = ringSegments.length, m, |
| 10780 |
segment, |
| 10781 |
point; |
| 10782 |
|
| 10783 |
ring.pop(); |
| 10784 |
polygon.push(ring); |
| 10785 |
ring = null; |
| 10786 |
|
| 10787 |
if (!n) return; |
| 10788 |
|
| 10789 |
// No intersections. |
| 10790 |
if (clean & 1) { |
| 10791 |
segment = ringSegments[0]; |
| 10792 |
if ((m = segment.length - 1) > 0) { |
| 10793 |
if (!polygonStarted) sink.polygonStart(), polygonStarted = true; |
| 10794 |
sink.lineStart(); |
| 10795 |
for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]); |
| 10796 |
sink.lineEnd(); |
| 10797 |
} |
| 10798 |
return; |
| 10799 |
} |
| 10800 |
|
| 10801 |
// Rejoin connected segments. |
| 10802 |
// TODO reuse ringBuffer.rejoin()? |
| 10803 |
if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift())); |
| 10804 |
|
| 10805 |
segments.push(ringSegments.filter(validSegment)); |
| 10806 |
} |
| 10807 |
|
| 10808 |
return clip; |
| 10809 |
}; |
| 10810 |
} |
| 10811 |
|
| 10812 |
function validSegment(segment) { |
| 10813 |
return segment.length > 1; |
| 10814 |
} |
| 10815 |
|
| 10816 |
// Intersections are sorted along the clip edge. For both antimeridian cutting |
| 10817 |
// and circle clipping, the same comparison is used. |
| 10818 |
function compareIntersection(a, b) { |
| 10819 |
return ((a = a.x)[0] < 0 ? a[1] - halfPi$1 - epsilon$1 : halfPi$1 - a[1]) |
| 10820 |
- ((b = b.x)[0] < 0 ? b[1] - halfPi$1 - epsilon$1 : halfPi$1 - b[1]); |
| 10821 |
} |
| 10822 |
|
| 10823 |
var clipAntimeridian = clip( |
| 10824 |
function() { return true; }, |
| 10825 |
clipAntimeridianLine, |
| 10826 |
clipAntimeridianInterpolate, |
| 10827 |
[-pi$1, -halfPi$1] |
| 10828 |
); |
| 10829 |
|
| 10830 |
// Takes a line and cuts into visible segments. Return values: 0 - there were |
| 10831 |
// intersections or the line was empty; 1 - no intersections; 2 - there were |
| 10832 |
// intersections, and the first and last segments should be rejoined. |
| 10833 |
function clipAntimeridianLine(stream) { |
| 10834 |
var lambda0 = NaN, |
| 10835 |
phi0 = NaN, |
| 10836 |
sign0 = NaN, |
| 10837 |
clean; // no intersections |
| 10838 |
|
| 10839 |
return { |
| 10840 |
lineStart: function() { |
| 10841 |
stream.lineStart(); |
| 10842 |
clean = 1; |
| 10843 |
}, |
| 10844 |
point: function(lambda1, phi1) { |
| 10845 |
var sign1 = lambda1 > 0 ? pi$1 : -pi$1, |
| 10846 |
delta = abs$1(lambda1 - lambda0); |
| 10847 |
if (abs$1(delta - pi$1) < epsilon$1) { // line crosses a pole |
| 10848 |
stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi$1 : -halfPi$1); |
| 10849 |
stream.point(sign0, phi0); |
| 10850 |
stream.lineEnd(); |
| 10851 |
stream.lineStart(); |
| 10852 |
stream.point(sign1, phi0); |
| 10853 |
stream.point(lambda1, phi0); |
| 10854 |
clean = 0; |
| 10855 |
} else if (sign0 !== sign1 && delta >= pi$1) { // line crosses antimeridian |
| 10856 |
if (abs$1(lambda0 - sign0) < epsilon$1) lambda0 -= sign0 * epsilon$1; // handle degeneracies |
| 10857 |
if (abs$1(lambda1 - sign1) < epsilon$1) lambda1 -= sign1 * epsilon$1; |
| 10858 |
phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1); |
| 10859 |
stream.point(sign0, phi0); |
| 10860 |
stream.lineEnd(); |
| 10861 |
stream.lineStart(); |
| 10862 |
stream.point(sign1, phi0); |
| 10863 |
clean = 0; |
| 10864 |
} |
| 10865 |
stream.point(lambda0 = lambda1, phi0 = phi1); |
| 10866 |
sign0 = sign1; |
| 10867 |
}, |
| 10868 |
lineEnd: function() { |
| 10869 |
stream.lineEnd(); |
| 10870 |
lambda0 = phi0 = NaN; |
| 10871 |
}, |
| 10872 |
clean: function() { |
| 10873 |
return 2 - clean; // if intersections, rejoin first and last segments |
| 10874 |
} |
| 10875 |
}; |
| 10876 |
} |
| 10877 |
|
| 10878 |
function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) { |
| 10879 |
var cosPhi0, |
| 10880 |
cosPhi1, |
| 10881 |
sinLambda0Lambda1 = sin$1(lambda0 - lambda1); |
| 10882 |
return abs$1(sinLambda0Lambda1) > epsilon$1 |
| 10883 |
? atan((sin$1(phi0) * (cosPhi1 = cos$1(phi1)) * sin$1(lambda1) |
| 10884 |
- sin$1(phi1) * (cosPhi0 = cos$1(phi0)) * sin$1(lambda0)) |
| 10885 |
/ (cosPhi0 * cosPhi1 * sinLambda0Lambda1)) |
| 10886 |
: (phi0 + phi1) / 2; |
| 10887 |
} |
| 10888 |
|
| 10889 |
function clipAntimeridianInterpolate(from, to, direction, stream) { |
| 10890 |
var phi; |
| 10891 |
if (from == null) { |
| 10892 |
phi = direction * halfPi$1; |
| 10893 |
stream.point(-pi$1, phi); |
| 10894 |
stream.point(0, phi); |
| 10895 |
stream.point(pi$1, phi); |
| 10896 |
stream.point(pi$1, 0); |
| 10897 |
stream.point(pi$1, -phi); |
| 10898 |
stream.point(0, -phi); |
| 10899 |
stream.point(-pi$1, -phi); |
| 10900 |
stream.point(-pi$1, 0); |
| 10901 |
stream.point(-pi$1, phi); |
| 10902 |
} else if (abs$1(from[0] - to[0]) > epsilon$1) { |
| 10903 |
var lambda = from[0] < to[0] ? pi$1 : -pi$1; |
| 10904 |
phi = direction * lambda / 2; |
| 10905 |
stream.point(-lambda, phi); |
| 10906 |
stream.point(0, phi); |
| 10907 |
stream.point(lambda, phi); |
| 10908 |
} else { |
| 10909 |
stream.point(to[0], to[1]); |
| 10910 |
} |
| 10911 |
} |
| 10912 |
|
| 10913 |
function clipCircle(radius) { |
| 10914 |
var cr = cos$1(radius), |
| 10915 |
delta = 2 * radians, |
| 10916 |
smallRadius = cr > 0, |
| 10917 |
notHemisphere = abs$1(cr) > epsilon$1; // TODO optimise for this common case |
| 10918 |
|
| 10919 |
function interpolate(from, to, direction, stream) { |
| 10920 |
circleStream(stream, radius, delta, direction, from, to); |
| 10921 |
} |
| 10922 |
|
| 10923 |
function visible(lambda, phi) { |
| 10924 |
return cos$1(lambda) * cos$1(phi) > cr; |
| 10925 |
} |
| 10926 |
|
| 10927 |
// Takes a line and cuts into visible segments. Return values used for polygon |
| 10928 |
// clipping: 0 - there were intersections or the line was empty; 1 - no |
| 10929 |
// intersections 2 - there were intersections, and the first and last segments |
| 10930 |
// should be rejoined. |
| 10931 |
function clipLine(stream) { |
| 10932 |
var point0, // previous point |
| 10933 |
c0, // code for previous point |
| 10934 |
v0, // visibility of previous point |
| 10935 |
v00, // visibility of first point |
| 10936 |
clean; // no intersections |
| 10937 |
return { |
| 10938 |
lineStart: function() { |
| 10939 |
v00 = v0 = false; |
| 10940 |
clean = 1; |
| 10941 |
}, |
| 10942 |
point: function(lambda, phi) { |
| 10943 |
var point1 = [lambda, phi], |
| 10944 |
point2, |
| 10945 |
v = visible(lambda, phi), |
| 10946 |
c = smallRadius |
| 10947 |
? v ? 0 : code(lambda, phi) |
| 10948 |
: v ? code(lambda + (lambda < 0 ? pi$1 : -pi$1), phi) : 0; |
| 10949 |
if (!point0 && (v00 = v0 = v)) stream.lineStart(); |
| 10950 |
if (v !== v0) { |
| 10951 |
point2 = intersect(point0, point1); |
| 10952 |
if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) |
| 10953 |
point1[2] = 1; |
| 10954 |
} |
| 10955 |
if (v !== v0) { |
| 10956 |
clean = 0; |
| 10957 |
if (v) { |
| 10958 |
// outside going in |
| 10959 |
stream.lineStart(); |
| 10960 |
point2 = intersect(point1, point0); |
| 10961 |
stream.point(point2[0], point2[1]); |
| 10962 |
} else { |
| 10963 |
// inside going out |
| 10964 |
point2 = intersect(point0, point1); |
| 10965 |
stream.point(point2[0], point2[1], 2); |
| 10966 |
stream.lineEnd(); |
| 10967 |
} |
| 10968 |
point0 = point2; |
| 10969 |
} else if (notHemisphere && point0 && smallRadius ^ v) { |
| 10970 |
var t; |
| 10971 |
// If the codes for two points are different, or are both zero, |
| 10972 |
// and there this segment intersects with the small circle. |
| 10973 |
if (!(c & c0) && (t = intersect(point1, point0, true))) { |
| 10974 |
clean = 0; |
| 10975 |
if (smallRadius) { |
| 10976 |
stream.lineStart(); |
| 10977 |
stream.point(t[0][0], t[0][1]); |
| 10978 |
stream.point(t[1][0], t[1][1]); |
| 10979 |
stream.lineEnd(); |
| 10980 |
} else { |
| 10981 |
stream.point(t[1][0], t[1][1]); |
| 10982 |
stream.lineEnd(); |
| 10983 |
stream.lineStart(); |
| 10984 |
stream.point(t[0][0], t[0][1], 3); |
| 10985 |
} |
| 10986 |
} |
| 10987 |
} |
| 10988 |
if (v && (!point0 || !pointEqual(point0, point1))) { |
| 10989 |
stream.point(point1[0], point1[1]); |
| 10990 |
} |
| 10991 |
point0 = point1, v0 = v, c0 = c; |
| 10992 |
}, |
| 10993 |
lineEnd: function() { |
| 10994 |
if (v0) stream.lineEnd(); |
| 10995 |
point0 = null; |
| 10996 |
}, |
| 10997 |
// Rejoin first and last segments if there were intersections and the first |
| 10998 |
// and last points were visible. |
| 10999 |
clean: function() { |
| 11000 |
return clean | ((v00 && v0) << 1); |
| 11001 |
} |
| 11002 |
}; |
| 11003 |
} |
| 11004 |
|
| 11005 |
// Intersects the great circle between a and b with the clip circle. |
| 11006 |
function intersect(a, b, two) { |
| 11007 |
var pa = cartesian(a), |
| 11008 |
pb = cartesian(b); |
| 11009 |
|
| 11010 |
// We have two planes, n1.p = d1 and n2.p = d2. |
| 11011 |
// Find intersection line p(t) = c1 n1 + c2 n2 + t (n1 ⨯ n2). |
| 11012 |
var n1 = [1, 0, 0], // normal |
| 11013 |
n2 = cartesianCross(pa, pb), |
| 11014 |
n2n2 = cartesianDot(n2, n2), |
| 11015 |
n1n2 = n2[0], // cartesianDot(n1, n2), |
| 11016 |
determinant = n2n2 - n1n2 * n1n2; |
| 11017 |
|
| 11018 |
// Two polar points. |
| 11019 |
if (!determinant) return !two && a; |
| 11020 |
|
| 11021 |
var c1 = cr * n2n2 / determinant, |
| 11022 |
c2 = -cr * n1n2 / determinant, |
| 11023 |
n1xn2 = cartesianCross(n1, n2), |
| 11024 |
A = cartesianScale(n1, c1), |
| 11025 |
B = cartesianScale(n2, c2); |
| 11026 |
cartesianAddInPlace(A, B); |
| 11027 |
|
| 11028 |
// Solve |p(t)|^2 = 1. |
| 11029 |
var u = n1xn2, |
| 11030 |
w = cartesianDot(A, u), |
| 11031 |
uu = cartesianDot(u, u), |
| 11032 |
t2 = w * w - uu * (cartesianDot(A, A) - 1); |
| 11033 |
|
| 11034 |
if (t2 < 0) return; |
| 11035 |
|
| 11036 |
var t = sqrt$2(t2), |
| 11037 |
q = cartesianScale(u, (-w - t) / uu); |
| 11038 |
cartesianAddInPlace(q, A); |
| 11039 |
q = spherical(q); |
| 11040 |
|
| 11041 |
if (!two) return q; |
| 11042 |
|
| 11043 |
// Two intersection points. |
| 11044 |
var lambda0 = a[0], |
| 11045 |
lambda1 = b[0], |
| 11046 |
phi0 = a[1], |
| 11047 |
phi1 = b[1], |
| 11048 |
z; |
| 11049 |
|
| 11050 |
if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z; |
| 11051 |
|
| 11052 |
var delta = lambda1 - lambda0, |
| 11053 |
polar = abs$1(delta - pi$1) < epsilon$1, |
| 11054 |
meridian = polar || delta < epsilon$1; |
| 11055 |
|
| 11056 |
if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z; |
| 11057 |
|
| 11058 |
// Check that the first point is between a and b. |
| 11059 |
if (meridian |
| 11060 |
? polar |
| 11061 |
? phi0 + phi1 > 0 ^ q[1] < (abs$1(q[0] - lambda0) < epsilon$1 ? phi0 : phi1) |
| 11062 |
: phi0 <= q[1] && q[1] <= phi1 |
| 11063 |
: delta > pi$1 ^ (lambda0 <= q[0] && q[0] <= lambda1)) { |
| 11064 |
var q1 = cartesianScale(u, (-w + t) / uu); |
| 11065 |
cartesianAddInPlace(q1, A); |
| 11066 |
return [q, spherical(q1)]; |
| 11067 |
} |
| 11068 |
} |
| 11069 |
|
| 11070 |
// Generates a 4-bit vector representing the location of a point relative to |
| 11071 |
// the small circle's bounding box. |
| 11072 |
function code(lambda, phi) { |
| 11073 |
var r = smallRadius ? radius : pi$1 - radius, |
| 11074 |
code = 0; |
| 11075 |
if (lambda < -r) code |= 1; // left |
| 11076 |
else if (lambda > r) code |= 2; // right |
| 11077 |
if (phi < -r) code |= 4; // below |
| 11078 |
else if (phi > r) code |= 8; // above |
| 11079 |
return code; |
| 11080 |
} |
| 11081 |
|
| 11082 |
return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi$1, radius - pi$1]); |
| 11083 |
} |
| 11084 |
|
| 11085 |
function clipLine(a, b, x0, y0, x1, y1) { |
| 11086 |
var ax = a[0], |
| 11087 |
ay = a[1], |
| 11088 |
bx = b[0], |
| 11089 |
by = b[1], |
| 11090 |
t0 = 0, |
| 11091 |
t1 = 1, |
| 11092 |
dx = bx - ax, |
| 11093 |
dy = by - ay, |
| 11094 |
r; |
| 11095 |
|
| 11096 |
r = x0 - ax; |
| 11097 |
if (!dx && r > 0) return; |
| 11098 |
r /= dx; |
| 11099 |
if (dx < 0) { |
| 11100 |
if (r < t0) return; |
| 11101 |
if (r < t1) t1 = r; |
| 11102 |
} else if (dx > 0) { |
| 11103 |
if (r > t1) return; |
| 11104 |
if (r > t0) t0 = r; |
| 11105 |
} |
| 11106 |
|
| 11107 |
r = x1 - ax; |
| 11108 |
if (!dx && r < 0) return; |
| 11109 |
r /= dx; |
| 11110 |
if (dx < 0) { |
| 11111 |
if (r > t1) return; |
| 11112 |
if (r > t0) t0 = r; |
| 11113 |
} else if (dx > 0) { |
| 11114 |
if (r < t0) return; |
| 11115 |
if (r < t1) t1 = r; |
| 11116 |
} |
| 11117 |
|
| 11118 |
r = y0 - ay; |
| 11119 |
if (!dy && r > 0) return; |
| 11120 |
r /= dy; |
| 11121 |
if (dy < 0) { |
| 11122 |
if (r < t0) return; |
| 11123 |
if (r < t1) t1 = r; |
| 11124 |
} else if (dy > 0) { |
| 11125 |
if (r > t1) return; |
| 11126 |
if (r > t0) t0 = r; |
| 11127 |
} |
| 11128 |
|
| 11129 |
r = y1 - ay; |
| 11130 |
if (!dy && r < 0) return; |
| 11131 |
r /= dy; |
| 11132 |
if (dy < 0) { |
| 11133 |
if (r > t1) return; |
| 11134 |
if (r > t0) t0 = r; |
| 11135 |
} else if (dy > 0) { |
| 11136 |
if (r < t0) return; |
| 11137 |
if (r < t1) t1 = r; |
| 11138 |
} |
| 11139 |
|
| 11140 |
if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy; |
| 11141 |
if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy; |
| 11142 |
return true; |
| 11143 |
} |
| 11144 |
|
| 11145 |
var clipMax = 1e9, clipMin = -clipMax; |
| 11146 |
|
| 11147 |
// TODO Use d3-polygon’s polygonContains here for the ring check? |
| 11148 |
// TODO Eliminate duplicate buffering in clipBuffer and polygon.push? |
| 11149 |
|
| 11150 |
function clipRectangle(x0, y0, x1, y1) { |
| 11151 |
|
| 11152 |
function visible(x, y) { |
| 11153 |
return x0 <= x && x <= x1 && y0 <= y && y <= y1; |
| 11154 |
} |
| 11155 |
|
| 11156 |
function interpolate(from, to, direction, stream) { |
| 11157 |
var a = 0, a1 = 0; |
| 11158 |
if (from == null |
| 11159 |
|| (a = corner(from, direction)) !== (a1 = corner(to, direction)) |
| 11160 |
|| comparePoint(from, to) < 0 ^ direction > 0) { |
| 11161 |
do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0); |
| 11162 |
while ((a = (a + direction + 4) % 4) !== a1); |
| 11163 |
} else { |
| 11164 |
stream.point(to[0], to[1]); |
| 11165 |
} |
| 11166 |
} |
| 11167 |
|
| 11168 |
function corner(p, direction) { |
| 11169 |
return abs$1(p[0] - x0) < epsilon$1 ? direction > 0 ? 0 : 3 |
| 11170 |
: abs$1(p[0] - x1) < epsilon$1 ? direction > 0 ? 2 : 1 |
| 11171 |
: abs$1(p[1] - y0) < epsilon$1 ? direction > 0 ? 1 : 0 |
| 11172 |
: direction > 0 ? 3 : 2; // abs(p[1] - y1) < epsilon |
| 11173 |
} |
| 11174 |
|
| 11175 |
function compareIntersection(a, b) { |
| 11176 |
return comparePoint(a.x, b.x); |
| 11177 |
} |
| 11178 |
|
| 11179 |
function comparePoint(a, b) { |
| 11180 |
var ca = corner(a, 1), |
| 11181 |
cb = corner(b, 1); |
| 11182 |
return ca !== cb ? ca - cb |
| 11183 |
: ca === 0 ? b[1] - a[1] |
| 11184 |
: ca === 1 ? a[0] - b[0] |
| 11185 |
: ca === 2 ? a[1] - b[1] |
| 11186 |
: b[0] - a[0]; |
| 11187 |
} |
| 11188 |
|
| 11189 |
return function(stream) { |
| 11190 |
var activeStream = stream, |
| 11191 |
bufferStream = clipBuffer(), |
| 11192 |
segments, |
| 11193 |
polygon, |
| 11194 |
ring, |
| 11195 |
x__, y__, v__, // first point |
| 11196 |
x_, y_, v_, // previous point |
| 11197 |
first, |
| 11198 |
clean; |
| 11199 |
|
| 11200 |
var clipStream = { |
| 11201 |
point: point, |
| 11202 |
lineStart: lineStart, |
| 11203 |
lineEnd: lineEnd, |
| 11204 |
polygonStart: polygonStart, |
| 11205 |
polygonEnd: polygonEnd |
| 11206 |
}; |
| 11207 |
|
| 11208 |
function point(x, y) { |
| 11209 |
if (visible(x, y)) activeStream.point(x, y); |
| 11210 |
} |
| 11211 |
|
| 11212 |
function polygonInside() { |
| 11213 |
var winding = 0; |
| 11214 |
|
| 11215 |
for (var i = 0, n = polygon.length; i < n; ++i) { |
| 11216 |
for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) { |
| 11217 |
a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1]; |
| 11218 |
if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; } |
| 11219 |
else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; } |
| 11220 |
} |
| 11221 |
} |
| 11222 |
|
| 11223 |
return winding; |
| 11224 |
} |
| 11225 |
|
| 11226 |
// Buffer geometry within a polygon and then clip it en masse. |
| 11227 |
function polygonStart() { |
| 11228 |
activeStream = bufferStream, segments = [], polygon = [], clean = true; |
| 11229 |
} |
| 11230 |
|
| 11231 |
function polygonEnd() { |
| 11232 |
var startInside = polygonInside(), |
| 11233 |
cleanInside = clean && startInside, |
| 11234 |
visible = (segments = merge(segments)).length; |
| 11235 |
if (cleanInside || visible) { |
| 11236 |
stream.polygonStart(); |
| 11237 |
if (cleanInside) { |
| 11238 |
stream.lineStart(); |
| 11239 |
interpolate(null, null, 1, stream); |
| 11240 |
stream.lineEnd(); |
| 11241 |
} |
| 11242 |
if (visible) { |
| 11243 |
clipRejoin(segments, compareIntersection, startInside, interpolate, stream); |
| 11244 |
} |
| 11245 |
stream.polygonEnd(); |
| 11246 |
} |
| 11247 |
activeStream = stream, segments = polygon = ring = null; |
| 11248 |
} |
| 11249 |
|
| 11250 |
function lineStart() { |
| 11251 |
clipStream.point = linePoint; |
| 11252 |
if (polygon) polygon.push(ring = []); |
| 11253 |
first = true; |
| 11254 |
v_ = false; |
| 11255 |
x_ = y_ = NaN; |
| 11256 |
} |
| 11257 |
|
| 11258 |
// TODO rather than special-case polygons, simply handle them separately. |
| 11259 |
// Ideally, coincident intersection points should be jittered to avoid |
| 11260 |
// clipping issues. |
| 11261 |
function lineEnd() { |
| 11262 |
if (segments) { |
| 11263 |
linePoint(x__, y__); |
| 11264 |
if (v__ && v_) bufferStream.rejoin(); |
| 11265 |
segments.push(bufferStream.result()); |
| 11266 |
} |
| 11267 |
clipStream.point = point; |
| 11268 |
if (v_) activeStream.lineEnd(); |
| 11269 |
} |
| 11270 |
|
| 11271 |
function linePoint(x, y) { |
| 11272 |
var v = visible(x, y); |
| 11273 |
if (polygon) ring.push([x, y]); |
| 11274 |
if (first) { |
| 11275 |
x__ = x, y__ = y, v__ = v; |
| 11276 |
first = false; |
| 11277 |
if (v) { |
| 11278 |
activeStream.lineStart(); |
| 11279 |
activeStream.point(x, y); |
| 11280 |
} |
| 11281 |
} else { |
| 11282 |
if (v && v_) activeStream.point(x, y); |
| 11283 |
else { |
| 11284 |
var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))], |
| 11285 |
b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))]; |
| 11286 |
if (clipLine(a, b, x0, y0, x1, y1)) { |
| 11287 |
if (!v_) { |
| 11288 |
activeStream.lineStart(); |
| 11289 |
activeStream.point(a[0], a[1]); |
| 11290 |
} |
| 11291 |
activeStream.point(b[0], b[1]); |
| 11292 |
if (!v) activeStream.lineEnd(); |
| 11293 |
clean = false; |
| 11294 |
} else if (v) { |
| 11295 |
activeStream.lineStart(); |
| 11296 |
activeStream.point(x, y); |
| 11297 |
clean = false; |
| 11298 |
} |
| 11299 |
} |
| 11300 |
} |
| 11301 |
x_ = x, y_ = y, v_ = v; |
| 11302 |
} |
| 11303 |
|
| 11304 |
return clipStream; |
| 11305 |
}; |
| 11306 |
} |
| 11307 |
|
| 11308 |
function extent() { |
| 11309 |
var x0 = 0, |
| 11310 |
y0 = 0, |
| 11311 |
x1 = 960, |
| 11312 |
y1 = 500, |
| 11313 |
cache, |
| 11314 |
cacheStream, |
| 11315 |
clip; |
| 11316 |
|
| 11317 |
return clip = { |
| 11318 |
stream: function(stream) { |
| 11319 |
return cache && cacheStream === stream ? cache : cache = clipRectangle(x0, y0, x1, y1)(cacheStream = stream); |
| 11320 |
}, |
| 11321 |
extent: function(_) { |
| 11322 |
return arguments.length ? (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1], cache = cacheStream = null, clip) : [[x0, y0], [x1, y1]]; |
| 11323 |
} |
| 11324 |
}; |
| 11325 |
} |
| 11326 |
|
| 11327 |
var lengthSum$1, |
| 11328 |
lambda0, |
| 11329 |
sinPhi0, |
| 11330 |
cosPhi0; |
| 11331 |
|
| 11332 |
var lengthStream$1 = { |
| 11333 |
sphere: noop$1, |
| 11334 |
point: noop$1, |
| 11335 |
lineStart: lengthLineStart, |
| 11336 |
lineEnd: noop$1, |
| 11337 |
polygonStart: noop$1, |
| 11338 |
polygonEnd: noop$1 |
| 11339 |
}; |
| 11340 |
|
| 11341 |
function lengthLineStart() { |
| 11342 |
lengthStream$1.point = lengthPointFirst$1; |
| 11343 |
lengthStream$1.lineEnd = lengthLineEnd; |
| 11344 |
} |
| 11345 |
|
| 11346 |
function lengthLineEnd() { |
| 11347 |
lengthStream$1.point = lengthStream$1.lineEnd = noop$1; |
| 11348 |
} |
| 11349 |
|
| 11350 |
function lengthPointFirst$1(lambda, phi) { |
| 11351 |
lambda *= radians, phi *= radians; |
| 11352 |
lambda0 = lambda, sinPhi0 = sin$1(phi), cosPhi0 = cos$1(phi); |
| 11353 |
lengthStream$1.point = lengthPoint$1; |
| 11354 |
} |
| 11355 |
|
| 11356 |
function lengthPoint$1(lambda, phi) { |
| 11357 |
lambda *= radians, phi *= radians; |
| 11358 |
var sinPhi = sin$1(phi), |
| 11359 |
cosPhi = cos$1(phi), |
| 11360 |
delta = abs$1(lambda - lambda0), |
| 11361 |
cosDelta = cos$1(delta), |
| 11362 |
sinDelta = sin$1(delta), |
| 11363 |
x = cosPhi * sinDelta, |
| 11364 |
y = cosPhi0 * sinPhi - sinPhi0 * cosPhi * cosDelta, |
| 11365 |
z = sinPhi0 * sinPhi + cosPhi0 * cosPhi * cosDelta; |
| 11366 |
lengthSum$1.add(atan2$1(sqrt$2(x * x + y * y), z)); |
| 11367 |
lambda0 = lambda, sinPhi0 = sinPhi, cosPhi0 = cosPhi; |
| 11368 |
} |
| 11369 |
|
| 11370 |
function length$1(object) { |
| 11371 |
lengthSum$1 = new Adder(); |
| 11372 |
geoStream(object, lengthStream$1); |
| 11373 |
return +lengthSum$1; |
| 11374 |
} |
| 11375 |
|
| 11376 |
var coordinates = [null, null], |
| 11377 |
object = {type: "LineString", coordinates: coordinates}; |
| 11378 |
|
| 11379 |
function distance(a, b) { |
| 11380 |
coordinates[0] = a; |
| 11381 |
coordinates[1] = b; |
| 11382 |
return length$1(object); |
| 11383 |
} |
| 11384 |
|
| 11385 |
var containsObjectType = { |
| 11386 |
Feature: function(object, point) { |
| 11387 |
return containsGeometry(object.geometry, point); |
| 11388 |
}, |
| 11389 |
FeatureCollection: function(object, point) { |
| 11390 |
var features = object.features, i = -1, n = features.length; |
| 11391 |
while (++i < n) if (containsGeometry(features[i].geometry, point)) return true; |
| 11392 |
return false; |
| 11393 |
} |
| 11394 |
}; |
| 11395 |
|
| 11396 |
var containsGeometryType = { |
| 11397 |
Sphere: function() { |
| 11398 |
return true; |
| 11399 |
}, |
| 11400 |
Point: function(object, point) { |
| 11401 |
return containsPoint(object.coordinates, point); |
| 11402 |
}, |
| 11403 |
MultiPoint: function(object, point) { |
| 11404 |
var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 11405 |
while (++i < n) if (containsPoint(coordinates[i], point)) return true; |
| 11406 |
return false; |
| 11407 |
}, |
| 11408 |
LineString: function(object, point) { |
| 11409 |
return containsLine(object.coordinates, point); |
| 11410 |
}, |
| 11411 |
MultiLineString: function(object, point) { |
| 11412 |
var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 11413 |
while (++i < n) if (containsLine(coordinates[i], point)) return true; |
| 11414 |
return false; |
| 11415 |
}, |
| 11416 |
Polygon: function(object, point) { |
| 11417 |
return containsPolygon(object.coordinates, point); |
| 11418 |
}, |
| 11419 |
MultiPolygon: function(object, point) { |
| 11420 |
var coordinates = object.coordinates, i = -1, n = coordinates.length; |
| 11421 |
while (++i < n) if (containsPolygon(coordinates[i], point)) return true; |
| 11422 |
return false; |
| 11423 |
}, |
| 11424 |
GeometryCollection: function(object, point) { |
| 11425 |
var geometries = object.geometries, i = -1, n = geometries.length; |
| 11426 |
while (++i < n) if (containsGeometry(geometries[i], point)) return true; |
| 11427 |
return false; |
| 11428 |
} |
| 11429 |
}; |
| 11430 |
|
| 11431 |
function containsGeometry(geometry, point) { |
| 11432 |
return geometry && containsGeometryType.hasOwnProperty(geometry.type) |
| 11433 |
? containsGeometryType[geometry.type](geometry, point) |
| 11434 |
: false; |
| 11435 |
} |
| 11436 |
|
| 11437 |
function containsPoint(coordinates, point) { |
| 11438 |
return distance(coordinates, point) === 0; |
| 11439 |
} |
| 11440 |
|
| 11441 |
function containsLine(coordinates, point) { |
| 11442 |
var ao, bo, ab; |
| 11443 |
for (var i = 0, n = coordinates.length; i < n; i++) { |
| 11444 |
bo = distance(coordinates[i], point); |
| 11445 |
if (bo === 0) return true; |
| 11446 |
if (i > 0) { |
| 11447 |
ab = distance(coordinates[i], coordinates[i - 1]); |
| 11448 |
if ( |
| 11449 |
ab > 0 && |
| 11450 |
ao <= ab && |
| 11451 |
bo <= ab && |
| 11452 |
(ao + bo - ab) * (1 - Math.pow((ao - bo) / ab, 2)) < epsilon2 * ab |
| 11453 |
) |
| 11454 |
return true; |
| 11455 |
} |
| 11456 |
ao = bo; |
| 11457 |
} |
| 11458 |
return false; |
| 11459 |
} |
| 11460 |
|
| 11461 |
function containsPolygon(coordinates, point) { |
| 11462 |
return !!polygonContains(coordinates.map(ringRadians), pointRadians(point)); |
| 11463 |
} |
| 11464 |
|
| 11465 |
function ringRadians(ring) { |
| 11466 |
return ring = ring.map(pointRadians), ring.pop(), ring; |
| 11467 |
} |
| 11468 |
|
| 11469 |
function pointRadians(point) { |
| 11470 |
return [point[0] * radians, point[1] * radians]; |
| 11471 |
} |
| 11472 |
|
| 11473 |
function contains$1(object, point) { |
| 11474 |
return (object && containsObjectType.hasOwnProperty(object.type) |
| 11475 |
? containsObjectType[object.type] |
| 11476 |
: containsGeometry)(object, point); |
| 11477 |
} |
| 11478 |
|
| 11479 |
function graticuleX(y0, y1, dy) { |
| 11480 |
var y = range$2(y0, y1 - epsilon$1, dy).concat(y1); |
| 11481 |
return function(x) { return y.map(function(y) { return [x, y]; }); }; |
| 11482 |
} |
| 11483 |
|
| 11484 |
function graticuleY(x0, x1, dx) { |
| 11485 |
var x = range$2(x0, x1 - epsilon$1, dx).concat(x1); |
| 11486 |
return function(y) { return x.map(function(x) { return [x, y]; }); }; |
| 11487 |
} |
| 11488 |
|
| 11489 |
function graticule() { |
| 11490 |
var x1, x0, X1, X0, |
| 11491 |
y1, y0, Y1, Y0, |
| 11492 |
dx = 10, dy = dx, DX = 90, DY = 360, |
| 11493 |
x, y, X, Y, |
| 11494 |
precision = 2.5; |
| 11495 |
|
| 11496 |
function graticule() { |
| 11497 |
return {type: "MultiLineString", coordinates: lines()}; |
| 11498 |
} |
| 11499 |
|
| 11500 |
function lines() { |
| 11501 |
return range$2(ceil(X0 / DX) * DX, X1, DX).map(X) |
| 11502 |
.concat(range$2(ceil(Y0 / DY) * DY, Y1, DY).map(Y)) |
| 11503 |
.concat(range$2(ceil(x0 / dx) * dx, x1, dx).filter(function(x) { return abs$1(x % DX) > epsilon$1; }).map(x)) |
| 11504 |
.concat(range$2(ceil(y0 / dy) * dy, y1, dy).filter(function(y) { return abs$1(y % DY) > epsilon$1; }).map(y)); |
| 11505 |
} |
| 11506 |
|
| 11507 |
graticule.lines = function() { |
| 11508 |
return lines().map(function(coordinates) { return {type: "LineString", coordinates: coordinates}; }); |
| 11509 |
}; |
| 11510 |
|
| 11511 |
graticule.outline = function() { |
| 11512 |
return { |
| 11513 |
type: "Polygon", |
| 11514 |
coordinates: [ |
| 11515 |
X(X0).concat( |
| 11516 |
Y(Y1).slice(1), |
| 11517 |
X(X1).reverse().slice(1), |
| 11518 |
Y(Y0).reverse().slice(1)) |
| 11519 |
] |
| 11520 |
}; |
| 11521 |
}; |
| 11522 |
|
| 11523 |
graticule.extent = function(_) { |
| 11524 |
if (!arguments.length) return graticule.extentMinor(); |
| 11525 |
return graticule.extentMajor(_).extentMinor(_); |
| 11526 |
}; |
| 11527 |
|
| 11528 |
graticule.extentMajor = function(_) { |
| 11529 |
if (!arguments.length) return [[X0, Y0], [X1, Y1]]; |
| 11530 |
X0 = +_[0][0], X1 = +_[1][0]; |
| 11531 |
Y0 = +_[0][1], Y1 = +_[1][1]; |
| 11532 |
if (X0 > X1) _ = X0, X0 = X1, X1 = _; |
| 11533 |
if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _; |
| 11534 |
return graticule.precision(precision); |
| 11535 |
}; |
| 11536 |
|
| 11537 |
graticule.extentMinor = function(_) { |
| 11538 |
if (!arguments.length) return [[x0, y0], [x1, y1]]; |
| 11539 |
x0 = +_[0][0], x1 = +_[1][0]; |
| 11540 |
y0 = +_[0][1], y1 = +_[1][1]; |
| 11541 |
if (x0 > x1) _ = x0, x0 = x1, x1 = _; |
| 11542 |
if (y0 > y1) _ = y0, y0 = y1, y1 = _; |
| 11543 |
return graticule.precision(precision); |
| 11544 |
}; |
| 11545 |
|
| 11546 |
graticule.step = function(_) { |
| 11547 |
if (!arguments.length) return graticule.stepMinor(); |
| 11548 |
return graticule.stepMajor(_).stepMinor(_); |
| 11549 |
}; |
| 11550 |
|
| 11551 |
graticule.stepMajor = function(_) { |
| 11552 |
if (!arguments.length) return [DX, DY]; |
| 11553 |
DX = +_[0], DY = +_[1]; |
| 11554 |
return graticule; |
| 11555 |
}; |
| 11556 |
|
| 11557 |
graticule.stepMinor = function(_) { |
| 11558 |
if (!arguments.length) return [dx, dy]; |
| 11559 |
dx = +_[0], dy = +_[1]; |
| 11560 |
return graticule; |
| 11561 |
}; |
| 11562 |
|
| 11563 |
graticule.precision = function(_) { |
| 11564 |
if (!arguments.length) return precision; |
| 11565 |
precision = +_; |
| 11566 |
x = graticuleX(y0, y1, 90); |
| 11567 |
y = graticuleY(x0, x1, precision); |
| 11568 |
X = graticuleX(Y0, Y1, 90); |
| 11569 |
Y = graticuleY(X0, X1, precision); |
| 11570 |
return graticule; |
| 11571 |
}; |
| 11572 |
|
| 11573 |
return graticule |
| 11574 |
.extentMajor([[-180, -90 + epsilon$1], [180, 90 - epsilon$1]]) |
| 11575 |
.extentMinor([[-180, -80 - epsilon$1], [180, 80 + epsilon$1]]); |
| 11576 |
} |
| 11577 |
|
| 11578 |
function graticule10() { |
| 11579 |
return graticule()(); |
| 11580 |
} |
| 11581 |
|
| 11582 |
function interpolate(a, b) { |
| 11583 |
var x0 = a[0] * radians, |
| 11584 |
y0 = a[1] * radians, |
| 11585 |
x1 = b[0] * radians, |
| 11586 |
y1 = b[1] * radians, |
| 11587 |
cy0 = cos$1(y0), |
| 11588 |
sy0 = sin$1(y0), |
| 11589 |
cy1 = cos$1(y1), |
| 11590 |
sy1 = sin$1(y1), |
| 11591 |
kx0 = cy0 * cos$1(x0), |
| 11592 |
ky0 = cy0 * sin$1(x0), |
| 11593 |
kx1 = cy1 * cos$1(x1), |
| 11594 |
ky1 = cy1 * sin$1(x1), |
| 11595 |
d = 2 * asin$1(sqrt$2(haversin(y1 - y0) + cy0 * cy1 * haversin(x1 - x0))), |
| 11596 |
k = sin$1(d); |
| 11597 |
|
| 11598 |
var interpolate = d ? function(t) { |
| 11599 |
var B = sin$1(t *= d) / k, |
| 11600 |
A = sin$1(d - t) / k, |
| 11601 |
x = A * kx0 + B * kx1, |
| 11602 |
y = A * ky0 + B * ky1, |
| 11603 |
z = A * sy0 + B * sy1; |
| 11604 |
return [ |
| 11605 |
atan2$1(y, x) * degrees, |
| 11606 |
atan2$1(z, sqrt$2(x * x + y * y)) * degrees |
| 11607 |
]; |
| 11608 |
} : function() { |
| 11609 |
return [x0 * degrees, y0 * degrees]; |
| 11610 |
}; |
| 11611 |
|
| 11612 |
interpolate.distance = d; |
| 11613 |
|
| 11614 |
return interpolate; |
| 11615 |
} |
| 11616 |
|
| 11617 |
var identity$5 = x => x; |
| 11618 |
|
| 11619 |
var areaSum = new Adder(), |
| 11620 |
areaRingSum = new Adder(), |
| 11621 |
x00$2, |
| 11622 |
y00$2, |
| 11623 |
x0$3, |
| 11624 |
y0$3; |
| 11625 |
|
| 11626 |
var areaStream = { |
| 11627 |
point: noop$1, |
| 11628 |
lineStart: noop$1, |
| 11629 |
lineEnd: noop$1, |
| 11630 |
polygonStart: function() { |
| 11631 |
areaStream.lineStart = areaRingStart; |
| 11632 |
areaStream.lineEnd = areaRingEnd; |
| 11633 |
}, |
| 11634 |
polygonEnd: function() { |
| 11635 |
areaStream.lineStart = areaStream.lineEnd = areaStream.point = noop$1; |
| 11636 |
areaSum.add(abs$1(areaRingSum)); |
| 11637 |
areaRingSum = new Adder(); |
| 11638 |
}, |
| 11639 |
result: function() { |
| 11640 |
var area = areaSum / 2; |
| 11641 |
areaSum = new Adder(); |
| 11642 |
return area; |
| 11643 |
} |
| 11644 |
}; |
| 11645 |
|
| 11646 |
function areaRingStart() { |
| 11647 |
areaStream.point = areaPointFirst; |
| 11648 |
} |
| 11649 |
|
| 11650 |
function areaPointFirst(x, y) { |
| 11651 |
areaStream.point = areaPoint; |
| 11652 |
x00$2 = x0$3 = x, y00$2 = y0$3 = y; |
| 11653 |
} |
| 11654 |
|
| 11655 |
function areaPoint(x, y) { |
| 11656 |
areaRingSum.add(y0$3 * x - x0$3 * y); |
| 11657 |
x0$3 = x, y0$3 = y; |
| 11658 |
} |
| 11659 |
|
| 11660 |
function areaRingEnd() { |
| 11661 |
areaPoint(x00$2, y00$2); |
| 11662 |
} |
| 11663 |
|
| 11664 |
var pathArea = areaStream; |
| 11665 |
|
| 11666 |
var x0$2 = Infinity, |
| 11667 |
y0$2 = x0$2, |
| 11668 |
x1 = -x0$2, |
| 11669 |
y1 = x1; |
| 11670 |
|
| 11671 |
var boundsStream = { |
| 11672 |
point: boundsPoint, |
| 11673 |
lineStart: noop$1, |
| 11674 |
lineEnd: noop$1, |
| 11675 |
polygonStart: noop$1, |
| 11676 |
polygonEnd: noop$1, |
| 11677 |
result: function() { |
| 11678 |
var bounds = [[x0$2, y0$2], [x1, y1]]; |
| 11679 |
x1 = y1 = -(y0$2 = x0$2 = Infinity); |
| 11680 |
return bounds; |
| 11681 |
} |
| 11682 |
}; |
| 11683 |
|
| 11684 |
function boundsPoint(x, y) { |
| 11685 |
if (x < x0$2) x0$2 = x; |
| 11686 |
if (x > x1) x1 = x; |
| 11687 |
if (y < y0$2) y0$2 = y; |
| 11688 |
if (y > y1) y1 = y; |
| 11689 |
} |
| 11690 |
|
| 11691 |
var boundsStream$1 = boundsStream; |
| 11692 |
|
| 11693 |
// TODO Enforce positive area for exterior, negative area for interior? |
| 11694 |
|
| 11695 |
var X0 = 0, |
| 11696 |
Y0 = 0, |
| 11697 |
Z0 = 0, |
| 11698 |
X1 = 0, |
| 11699 |
Y1 = 0, |
| 11700 |
Z1 = 0, |
| 11701 |
X2 = 0, |
| 11702 |
Y2 = 0, |
| 11703 |
Z2 = 0, |
| 11704 |
x00$1, |
| 11705 |
y00$1, |
| 11706 |
x0$1, |
| 11707 |
y0$1; |
| 11708 |
|
| 11709 |
var centroidStream = { |
| 11710 |
point: centroidPoint, |
| 11711 |
lineStart: centroidLineStart, |
| 11712 |
lineEnd: centroidLineEnd, |
| 11713 |
polygonStart: function() { |
| 11714 |
centroidStream.lineStart = centroidRingStart; |
| 11715 |
centroidStream.lineEnd = centroidRingEnd; |
| 11716 |
}, |
| 11717 |
polygonEnd: function() { |
| 11718 |
centroidStream.point = centroidPoint; |
| 11719 |
centroidStream.lineStart = centroidLineStart; |
| 11720 |
centroidStream.lineEnd = centroidLineEnd; |
| 11721 |
}, |
| 11722 |
result: function() { |
| 11723 |
var centroid = Z2 ? [X2 / Z2, Y2 / Z2] |
| 11724 |
: Z1 ? [X1 / Z1, Y1 / Z1] |
| 11725 |
: Z0 ? [X0 / Z0, Y0 / Z0] |
| 11726 |
: [NaN, NaN]; |
| 11727 |
X0 = Y0 = Z0 = |
| 11728 |
X1 = Y1 = Z1 = |
| 11729 |
X2 = Y2 = Z2 = 0; |
| 11730 |
return centroid; |
| 11731 |
} |
| 11732 |
}; |
| 11733 |
|
| 11734 |
function centroidPoint(x, y) { |
| 11735 |
X0 += x; |
| 11736 |
Y0 += y; |
| 11737 |
++Z0; |
| 11738 |
} |
| 11739 |
|
| 11740 |
function centroidLineStart() { |
| 11741 |
centroidStream.point = centroidPointFirstLine; |
| 11742 |
} |
| 11743 |
|
| 11744 |
function centroidPointFirstLine(x, y) { |
| 11745 |
centroidStream.point = centroidPointLine; |
| 11746 |
centroidPoint(x0$1 = x, y0$1 = y); |
| 11747 |
} |
| 11748 |
|
| 11749 |
function centroidPointLine(x, y) { |
| 11750 |
var dx = x - x0$1, dy = y - y0$1, z = sqrt$2(dx * dx + dy * dy); |
| 11751 |
X1 += z * (x0$1 + x) / 2; |
| 11752 |
Y1 += z * (y0$1 + y) / 2; |
| 11753 |
Z1 += z; |
| 11754 |
centroidPoint(x0$1 = x, y0$1 = y); |
| 11755 |
} |
| 11756 |
|
| 11757 |
function centroidLineEnd() { |
| 11758 |
centroidStream.point = centroidPoint; |
| 11759 |
} |
| 11760 |
|
| 11761 |
function centroidRingStart() { |
| 11762 |
centroidStream.point = centroidPointFirstRing; |
| 11763 |
} |
| 11764 |
|
| 11765 |
function centroidRingEnd() { |
| 11766 |
centroidPointRing(x00$1, y00$1); |
| 11767 |
} |
| 11768 |
|
| 11769 |
function centroidPointFirstRing(x, y) { |
| 11770 |
centroidStream.point = centroidPointRing; |
| 11771 |
centroidPoint(x00$1 = x0$1 = x, y00$1 = y0$1 = y); |
| 11772 |
} |
| 11773 |
|
| 11774 |
function centroidPointRing(x, y) { |
| 11775 |
var dx = x - x0$1, |
| 11776 |
dy = y - y0$1, |
| 11777 |
z = sqrt$2(dx * dx + dy * dy); |
| 11778 |
|
| 11779 |
X1 += z * (x0$1 + x) / 2; |
| 11780 |
Y1 += z * (y0$1 + y) / 2; |
| 11781 |
Z1 += z; |
| 11782 |
|
| 11783 |
z = y0$1 * x - x0$1 * y; |
| 11784 |
X2 += z * (x0$1 + x); |
| 11785 |
Y2 += z * (y0$1 + y); |
| 11786 |
Z2 += z * 3; |
| 11787 |
centroidPoint(x0$1 = x, y0$1 = y); |
| 11788 |
} |
| 11789 |
|
| 11790 |
var pathCentroid = centroidStream; |
| 11791 |
|
| 11792 |
function PathContext(context) { |
| 11793 |
this._context = context; |
| 11794 |
} |
| 11795 |
|
| 11796 |
PathContext.prototype = { |
| 11797 |
_radius: 4.5, |
| 11798 |
pointRadius: function(_) { |
| 11799 |
return this._radius = _, this; |
| 11800 |
}, |
| 11801 |
polygonStart: function() { |
| 11802 |
this._line = 0; |
| 11803 |
}, |
| 11804 |
polygonEnd: function() { |
| 11805 |
this._line = NaN; |
| 11806 |
}, |
| 11807 |
lineStart: function() { |
| 11808 |
this._point = 0; |
| 11809 |
}, |
| 11810 |
lineEnd: function() { |
| 11811 |
if (this._line === 0) this._context.closePath(); |
| 11812 |
this._point = NaN; |
| 11813 |
}, |
| 11814 |
point: function(x, y) { |
| 11815 |
switch (this._point) { |
| 11816 |
case 0: { |
| 11817 |
this._context.moveTo(x, y); |
| 11818 |
this._point = 1; |
| 11819 |
break; |
| 11820 |
} |
| 11821 |
case 1: { |
| 11822 |
this._context.lineTo(x, y); |
| 11823 |
break; |
| 11824 |
} |
| 11825 |
default: { |
| 11826 |
this._context.moveTo(x + this._radius, y); |
| 11827 |
this._context.arc(x, y, this._radius, 0, tau$1); |
| 11828 |
break; |
| 11829 |
} |
| 11830 |
} |
| 11831 |
}, |
| 11832 |
result: noop$1 |
| 11833 |
}; |
| 11834 |
|
| 11835 |
var lengthSum = new Adder(), |
| 11836 |
lengthRing, |
| 11837 |
x00, |
| 11838 |
y00, |
| 11839 |
x0, |
| 11840 |
y0; |
| 11841 |
|
| 11842 |
var lengthStream = { |
| 11843 |
point: noop$1, |
| 11844 |
lineStart: function() { |
| 11845 |
lengthStream.point = lengthPointFirst; |
| 11846 |
}, |
| 11847 |
lineEnd: function() { |
| 11848 |
if (lengthRing) lengthPoint(x00, y00); |
| 11849 |
lengthStream.point = noop$1; |
| 11850 |
}, |
| 11851 |
polygonStart: function() { |
| 11852 |
lengthRing = true; |
| 11853 |
}, |
| 11854 |
polygonEnd: function() { |
| 11855 |
lengthRing = null; |
| 11856 |
}, |
| 11857 |
result: function() { |
| 11858 |
var length = +lengthSum; |
| 11859 |
lengthSum = new Adder(); |
| 11860 |
return length; |
| 11861 |
} |
| 11862 |
}; |
| 11863 |
|
| 11864 |
function lengthPointFirst(x, y) { |
| 11865 |
lengthStream.point = lengthPoint; |
| 11866 |
x00 = x0 = x, y00 = y0 = y; |
| 11867 |
} |
| 11868 |
|
| 11869 |
function lengthPoint(x, y) { |
| 11870 |
x0 -= x, y0 -= y; |
| 11871 |
lengthSum.add(sqrt$2(x0 * x0 + y0 * y0)); |
| 11872 |
x0 = x, y0 = y; |
| 11873 |
} |
| 11874 |
|
| 11875 |
var pathMeasure = lengthStream; |
| 11876 |
|
| 11877 |
// Simple caching for constant-radius points. |
| 11878 |
let cacheDigits, cacheAppend, cacheRadius, cacheCircle; |
| 11879 |
|
| 11880 |
class PathString { |
| 11881 |
constructor(digits) { |
| 11882 |
this._append = digits == null ? append : appendRound(digits); |
| 11883 |
this._radius = 4.5; |
| 11884 |
this._ = ""; |
| 11885 |
} |
| 11886 |
pointRadius(_) { |
| 11887 |
this._radius = +_; |
| 11888 |
return this; |
| 11889 |
} |
| 11890 |
polygonStart() { |
| 11891 |
this._line = 0; |
| 11892 |
} |
| 11893 |
polygonEnd() { |
| 11894 |
this._line = NaN; |
| 11895 |
} |
| 11896 |
lineStart() { |
| 11897 |
this._point = 0; |
| 11898 |
} |
| 11899 |
lineEnd() { |
| 11900 |
if (this._line === 0) this._ += "Z"; |
| 11901 |
this._point = NaN; |
| 11902 |
} |
| 11903 |
point(x, y) { |
| 11904 |
switch (this._point) { |
| 11905 |
case 0: { |
| 11906 |
this._append`M${x},${y}`; |
| 11907 |
this._point = 1; |
| 11908 |
break; |
| 11909 |
} |
| 11910 |
case 1: { |
| 11911 |
this._append`L${x},${y}`; |
| 11912 |
break; |
| 11913 |
} |
| 11914 |
default: { |
| 11915 |
this._append`M${x},${y}`; |
| 11916 |
if (this._radius !== cacheRadius || this._append !== cacheAppend) { |
| 11917 |
const r = this._radius; |
| 11918 |
const s = this._; |
| 11919 |
this._ = ""; // stash the old string so we can cache the circle path fragment |
| 11920 |
this._append`m0,${r}a${r},${r} 0 1,1 0,${-2 * r}a${r},${r} 0 1,1 0,${2 * r}z`; |
| 11921 |
cacheRadius = r; |
| 11922 |
cacheAppend = this._append; |
| 11923 |
cacheCircle = this._; |
| 11924 |
this._ = s; |
| 11925 |
} |
| 11926 |
this._ += cacheCircle; |
| 11927 |
break; |
| 11928 |
} |
| 11929 |
} |
| 11930 |
} |
| 11931 |
result() { |
| 11932 |
const result = this._; |
| 11933 |
this._ = ""; |
| 11934 |
return result.length ? result : null; |
| 11935 |
} |
| 11936 |
} |
| 11937 |
|
| 11938 |
function append(strings) { |
| 11939 |
let i = 1; |
| 11940 |
this._ += strings[0]; |
| 11941 |
for (const j = strings.length; i < j; ++i) { |
| 11942 |
this._ += arguments[i] + strings[i]; |
| 11943 |
} |
| 11944 |
} |
| 11945 |
|
| 11946 |
function appendRound(digits) { |
| 11947 |
const d = Math.floor(digits); |
| 11948 |
if (!(d >= 0)) throw new RangeError(`invalid digits: ${digits}`); |
| 11949 |
if (d > 15) return append; |
| 11950 |
if (d !== cacheDigits) { |
| 11951 |
const k = 10 ** d; |
| 11952 |
cacheDigits = d; |
| 11953 |
cacheAppend = function append(strings) { |
| 11954 |
let i = 1; |
| 11955 |
this._ += strings[0]; |
| 11956 |
for (const j = strings.length; i < j; ++i) { |
| 11957 |
this._ += Math.round(arguments[i] * k) / k + strings[i]; |
| 11958 |
} |
| 11959 |
}; |
| 11960 |
} |
| 11961 |
return cacheAppend; |
| 11962 |
} |
| 11963 |
|
| 11964 |
function index$2(projection, context) { |
| 11965 |
let digits = 3, |
| 11966 |
pointRadius = 4.5, |
| 11967 |
projectionStream, |
| 11968 |
contextStream; |
| 11969 |
|
| 11970 |
function path(object) { |
| 11971 |
if (object) { |
| 11972 |
if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments)); |
| 11973 |
geoStream(object, projectionStream(contextStream)); |
| 11974 |
} |
| 11975 |
return contextStream.result(); |
| 11976 |
} |
| 11977 |
|
| 11978 |
path.area = function(object) { |
| 11979 |
geoStream(object, projectionStream(pathArea)); |
| 11980 |
return pathArea.result(); |
| 11981 |
}; |
| 11982 |
|
| 11983 |
path.measure = function(object) { |
| 11984 |
geoStream(object, projectionStream(pathMeasure)); |
| 11985 |
return pathMeasure.result(); |
| 11986 |
}; |
| 11987 |
|
| 11988 |
path.bounds = function(object) { |
| 11989 |
geoStream(object, projectionStream(boundsStream$1)); |
| 11990 |
return boundsStream$1.result(); |
| 11991 |
}; |
| 11992 |
|
| 11993 |
path.centroid = function(object) { |
| 11994 |
geoStream(object, projectionStream(pathCentroid)); |
| 11995 |
return pathCentroid.result(); |
| 11996 |
}; |
| 11997 |
|
| 11998 |
path.projection = function(_) { |
| 11999 |
if (!arguments.length) return projection; |
| 12000 |
projectionStream = _ == null ? (projection = null, identity$5) : (projection = _).stream; |
| 12001 |
return path; |
| 12002 |
}; |
| 12003 |
|
| 12004 |
path.context = function(_) { |
| 12005 |
if (!arguments.length) return context; |
| 12006 |
contextStream = _ == null ? (context = null, new PathString(digits)) : new PathContext(context = _); |
| 12007 |
if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius); |
| 12008 |
return path; |
| 12009 |
}; |
| 12010 |
|
| 12011 |
path.pointRadius = function(_) { |
| 12012 |
if (!arguments.length) return pointRadius; |
| 12013 |
pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_); |
| 12014 |
return path; |
| 12015 |
}; |
| 12016 |
|
| 12017 |
path.digits = function(_) { |
| 12018 |
if (!arguments.length) return digits; |
| 12019 |
if (_ == null) digits = null; |
| 12020 |
else { |
| 12021 |
const d = Math.floor(_); |
| 12022 |
if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`); |
| 12023 |
digits = d; |
| 12024 |
} |
| 12025 |
if (context === null) contextStream = new PathString(digits); |
| 12026 |
return path; |
| 12027 |
}; |
| 12028 |
|
| 12029 |
return path.projection(projection).digits(digits).context(context); |
| 12030 |
} |
| 12031 |
|
| 12032 |
function transform$1(methods) { |
| 12033 |
return { |
| 12034 |
stream: transformer$3(methods) |
| 12035 |
}; |
| 12036 |
} |
| 12037 |
|
| 12038 |
function transformer$3(methods) { |
| 12039 |
return function(stream) { |
| 12040 |
var s = new TransformStream; |
| 12041 |
for (var key in methods) s[key] = methods[key]; |
| 12042 |
s.stream = stream; |
| 12043 |
return s; |
| 12044 |
}; |
| 12045 |
} |
| 12046 |
|
| 12047 |
function TransformStream() {} |
| 12048 |
|
| 12049 |
TransformStream.prototype = { |
| 12050 |
constructor: TransformStream, |
| 12051 |
point: function(x, y) { this.stream.point(x, y); }, |
| 12052 |
sphere: function() { this.stream.sphere(); }, |
| 12053 |
lineStart: function() { this.stream.lineStart(); }, |
| 12054 |
lineEnd: function() { this.stream.lineEnd(); }, |
| 12055 |
polygonStart: function() { this.stream.polygonStart(); }, |
| 12056 |
polygonEnd: function() { this.stream.polygonEnd(); } |
| 12057 |
}; |
| 12058 |
|
| 12059 |
function fit(projection, fitBounds, object) { |
| 12060 |
var clip = projection.clipExtent && projection.clipExtent(); |
| 12061 |
projection.scale(150).translate([0, 0]); |
| 12062 |
if (clip != null) projection.clipExtent(null); |
| 12063 |
geoStream(object, projection.stream(boundsStream$1)); |
| 12064 |
fitBounds(boundsStream$1.result()); |
| 12065 |
if (clip != null) projection.clipExtent(clip); |
| 12066 |
return projection; |
| 12067 |
} |
| 12068 |
|
| 12069 |
function fitExtent(projection, extent, object) { |
| 12070 |
return fit(projection, function(b) { |
| 12071 |
var w = extent[1][0] - extent[0][0], |
| 12072 |
h = extent[1][1] - extent[0][1], |
| 12073 |
k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])), |
| 12074 |
x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2, |
| 12075 |
y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2; |
| 12076 |
projection.scale(150 * k).translate([x, y]); |
| 12077 |
}, object); |
| 12078 |
} |
| 12079 |
|
| 12080 |
function fitSize(projection, size, object) { |
| 12081 |
return fitExtent(projection, [[0, 0], size], object); |
| 12082 |
} |
| 12083 |
|
| 12084 |
function fitWidth(projection, width, object) { |
| 12085 |
return fit(projection, function(b) { |
| 12086 |
var w = +width, |
| 12087 |
k = w / (b[1][0] - b[0][0]), |
| 12088 |
x = (w - k * (b[1][0] + b[0][0])) / 2, |
| 12089 |
y = -k * b[0][1]; |
| 12090 |
projection.scale(150 * k).translate([x, y]); |
| 12091 |
}, object); |
| 12092 |
} |
| 12093 |
|
| 12094 |
function fitHeight(projection, height, object) { |
| 12095 |
return fit(projection, function(b) { |
| 12096 |
var h = +height, |
| 12097 |
k = h / (b[1][1] - b[0][1]), |
| 12098 |
x = -k * b[0][0], |
| 12099 |
y = (h - k * (b[1][1] + b[0][1])) / 2; |
| 12100 |
projection.scale(150 * k).translate([x, y]); |
| 12101 |
}, object); |
| 12102 |
} |
| 12103 |
|
| 12104 |
var maxDepth = 16, // maximum depth of subdivision |
| 12105 |
cosMinDistance = cos$1(30 * radians); // cos(minimum angular distance) |
| 12106 |
|
| 12107 |
function resample(project, delta2) { |
| 12108 |
return +delta2 ? resample$1(project, delta2) : resampleNone(project); |
| 12109 |
} |
| 12110 |
|
| 12111 |
function resampleNone(project) { |
| 12112 |
return transformer$3({ |
| 12113 |
point: function(x, y) { |
| 12114 |
x = project(x, y); |
| 12115 |
this.stream.point(x[0], x[1]); |
| 12116 |
} |
| 12117 |
}); |
| 12118 |
} |
| 12119 |
|
| 12120 |
function resample$1(project, delta2) { |
| 12121 |
|
| 12122 |
function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) { |
| 12123 |
var dx = x1 - x0, |
| 12124 |
dy = y1 - y0, |
| 12125 |
d2 = dx * dx + dy * dy; |
| 12126 |
if (d2 > 4 * delta2 && depth--) { |
| 12127 |
var a = a0 + a1, |
| 12128 |
b = b0 + b1, |
| 12129 |
c = c0 + c1, |
| 12130 |
m = sqrt$2(a * a + b * b + c * c), |
| 12131 |
phi2 = asin$1(c /= m), |
| 12132 |
lambda2 = abs$1(abs$1(c) - 1) < epsilon$1 || abs$1(lambda0 - lambda1) < epsilon$1 ? (lambda0 + lambda1) / 2 : atan2$1(b, a), |
| 12133 |
p = project(lambda2, phi2), |
| 12134 |
x2 = p[0], |
| 12135 |
y2 = p[1], |
| 12136 |
dx2 = x2 - x0, |
| 12137 |
dy2 = y2 - y0, |
| 12138 |
dz = dy * dx2 - dx * dy2; |
| 12139 |
if (dz * dz / d2 > delta2 // perpendicular projected distance |
| 12140 |
|| abs$1((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end |
| 12141 |
|| a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance |
| 12142 |
resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream); |
| 12143 |
stream.point(x2, y2); |
| 12144 |
resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream); |
| 12145 |
} |
| 12146 |
} |
| 12147 |
} |
| 12148 |
return function(stream) { |
| 12149 |
var lambda00, x00, y00, a00, b00, c00, // first point |
| 12150 |
lambda0, x0, y0, a0, b0, c0; // previous point |
| 12151 |
|
| 12152 |
var resampleStream = { |
| 12153 |
point: point, |
| 12154 |
lineStart: lineStart, |
| 12155 |
lineEnd: lineEnd, |
| 12156 |
polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; }, |
| 12157 |
polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; } |
| 12158 |
}; |
| 12159 |
|
| 12160 |
function point(x, y) { |
| 12161 |
x = project(x, y); |
| 12162 |
stream.point(x[0], x[1]); |
| 12163 |
} |
| 12164 |
|
| 12165 |
function lineStart() { |
| 12166 |
x0 = NaN; |
| 12167 |
resampleStream.point = linePoint; |
| 12168 |
stream.lineStart(); |
| 12169 |
} |
| 12170 |
|
| 12171 |
function linePoint(lambda, phi) { |
| 12172 |
var c = cartesian([lambda, phi]), p = project(lambda, phi); |
| 12173 |
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); |
| 12174 |
stream.point(x0, y0); |
| 12175 |
} |
| 12176 |
|
| 12177 |
function lineEnd() { |
| 12178 |
resampleStream.point = point; |
| 12179 |
stream.lineEnd(); |
| 12180 |
} |
| 12181 |
|
| 12182 |
function ringStart() { |
| 12183 |
lineStart(); |
| 12184 |
resampleStream.point = ringPoint; |
| 12185 |
resampleStream.lineEnd = ringEnd; |
| 12186 |
} |
| 12187 |
|
| 12188 |
function ringPoint(lambda, phi) { |
| 12189 |
linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0; |
| 12190 |
resampleStream.point = linePoint; |
| 12191 |
} |
| 12192 |
|
| 12193 |
function ringEnd() { |
| 12194 |
resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream); |
| 12195 |
resampleStream.lineEnd = lineEnd; |
| 12196 |
lineEnd(); |
| 12197 |
} |
| 12198 |
|
| 12199 |
return resampleStream; |
| 12200 |
}; |
| 12201 |
} |
| 12202 |
|
| 12203 |
var transformRadians = transformer$3({ |
| 12204 |
point: function(x, y) { |
| 12205 |
this.stream.point(x * radians, y * radians); |
| 12206 |
} |
| 12207 |
}); |
| 12208 |
|
| 12209 |
function transformRotate(rotate) { |
| 12210 |
return transformer$3({ |
| 12211 |
point: function(x, y) { |
| 12212 |
var r = rotate(x, y); |
| 12213 |
return this.stream.point(r[0], r[1]); |
| 12214 |
} |
| 12215 |
}); |
| 12216 |
} |
| 12217 |
|
| 12218 |
function scaleTranslate(k, dx, dy, sx, sy) { |
| 12219 |
function transform(x, y) { |
| 12220 |
x *= sx; y *= sy; |
| 12221 |
return [dx + k * x, dy - k * y]; |
| 12222 |
} |
| 12223 |
transform.invert = function(x, y) { |
| 12224 |
return [(x - dx) / k * sx, (dy - y) / k * sy]; |
| 12225 |
}; |
| 12226 |
return transform; |
| 12227 |
} |
| 12228 |
|
| 12229 |
function scaleTranslateRotate(k, dx, dy, sx, sy, alpha) { |
| 12230 |
if (!alpha) return scaleTranslate(k, dx, dy, sx, sy); |
| 12231 |
var cosAlpha = cos$1(alpha), |
| 12232 |
sinAlpha = sin$1(alpha), |
| 12233 |
a = cosAlpha * k, |
| 12234 |
b = sinAlpha * k, |
| 12235 |
ai = cosAlpha / k, |
| 12236 |
bi = sinAlpha / k, |
| 12237 |
ci = (sinAlpha * dy - cosAlpha * dx) / k, |
| 12238 |
fi = (sinAlpha * dx + cosAlpha * dy) / k; |
| 12239 |
function transform(x, y) { |
| 12240 |
x *= sx; y *= sy; |
| 12241 |
return [a * x - b * y + dx, dy - b * x - a * y]; |
| 12242 |
} |
| 12243 |
transform.invert = function(x, y) { |
| 12244 |
return [sx * (ai * x - bi * y + ci), sy * (fi - bi * x - ai * y)]; |
| 12245 |
}; |
| 12246 |
return transform; |
| 12247 |
} |
| 12248 |
|
| 12249 |
function projection(project) { |
| 12250 |
return projectionMutator(function() { return project; })(); |
| 12251 |
} |
| 12252 |
|
| 12253 |
function projectionMutator(projectAt) { |
| 12254 |
var project, |
| 12255 |
k = 150, // scale |
| 12256 |
x = 480, y = 250, // translate |
| 12257 |
lambda = 0, phi = 0, // center |
| 12258 |
deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, // pre-rotate |
| 12259 |
alpha = 0, // post-rotate angle |
| 12260 |
sx = 1, // reflectX |
| 12261 |
sy = 1, // reflectX |
| 12262 |
theta = null, preclip = clipAntimeridian, // pre-clip angle |
| 12263 |
x0 = null, y0, x1, y1, postclip = identity$5, // post-clip extent |
| 12264 |
delta2 = 0.5, // precision |
| 12265 |
projectResample, |
| 12266 |
projectTransform, |
| 12267 |
projectRotateTransform, |
| 12268 |
cache, |
| 12269 |
cacheStream; |
| 12270 |
|
| 12271 |
function projection(point) { |
| 12272 |
return projectRotateTransform(point[0] * radians, point[1] * radians); |
| 12273 |
} |
| 12274 |
|
| 12275 |
function invert(point) { |
| 12276 |
point = projectRotateTransform.invert(point[0], point[1]); |
| 12277 |
return point && [point[0] * degrees, point[1] * degrees]; |
| 12278 |
} |
| 12279 |
|
| 12280 |
projection.stream = function(stream) { |
| 12281 |
return cache && cacheStream === stream ? cache : cache = transformRadians(transformRotate(rotate)(preclip(projectResample(postclip(cacheStream = stream))))); |
| 12282 |
}; |
| 12283 |
|
| 12284 |
projection.preclip = function(_) { |
| 12285 |
return arguments.length ? (preclip = _, theta = undefined, reset()) : preclip; |
| 12286 |
}; |
| 12287 |
|
| 12288 |
projection.postclip = function(_) { |
| 12289 |
return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip; |
| 12290 |
}; |
| 12291 |
|
| 12292 |
projection.clipAngle = function(_) { |
| 12293 |
return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees; |
| 12294 |
}; |
| 12295 |
|
| 12296 |
projection.clipExtent = function(_) { |
| 12297 |
return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]]; |
| 12298 |
}; |
| 12299 |
|
| 12300 |
projection.scale = function(_) { |
| 12301 |
return arguments.length ? (k = +_, recenter()) : k; |
| 12302 |
}; |
| 12303 |
|
| 12304 |
projection.translate = function(_) { |
| 12305 |
return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y]; |
| 12306 |
}; |
| 12307 |
|
| 12308 |
projection.center = function(_) { |
| 12309 |
return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees]; |
| 12310 |
}; |
| 12311 |
|
| 12312 |
projection.rotate = function(_) { |
| 12313 |
return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees, deltaPhi * degrees, deltaGamma * degrees]; |
| 12314 |
}; |
| 12315 |
|
| 12316 |
projection.angle = function(_) { |
| 12317 |
return arguments.length ? (alpha = _ % 360 * radians, recenter()) : alpha * degrees; |
| 12318 |
}; |
| 12319 |
|
| 12320 |
projection.reflectX = function(_) { |
| 12321 |
return arguments.length ? (sx = _ ? -1 : 1, recenter()) : sx < 0; |
| 12322 |
}; |
| 12323 |
|
| 12324 |
projection.reflectY = function(_) { |
| 12325 |
return arguments.length ? (sy = _ ? -1 : 1, recenter()) : sy < 0; |
| 12326 |
}; |
| 12327 |
|
| 12328 |
projection.precision = function(_) { |
| 12329 |
return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt$2(delta2); |
| 12330 |
}; |
| 12331 |
|
| 12332 |
projection.fitExtent = function(extent, object) { |
| 12333 |
return fitExtent(projection, extent, object); |
| 12334 |
}; |
| 12335 |
|
| 12336 |
projection.fitSize = function(size, object) { |
| 12337 |
return fitSize(projection, size, object); |
| 12338 |
}; |
| 12339 |
|
| 12340 |
projection.fitWidth = function(width, object) { |
| 12341 |
return fitWidth(projection, width, object); |
| 12342 |
}; |
| 12343 |
|
| 12344 |
projection.fitHeight = function(height, object) { |
| 12345 |
return fitHeight(projection, height, object); |
| 12346 |
}; |
| 12347 |
|
| 12348 |
function recenter() { |
| 12349 |
var center = scaleTranslateRotate(k, 0, 0, sx, sy, alpha).apply(null, project(lambda, phi)), |
| 12350 |
transform = scaleTranslateRotate(k, x - center[0], y - center[1], sx, sy, alpha); |
| 12351 |
rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma); |
| 12352 |
projectTransform = compose(project, transform); |
| 12353 |
projectRotateTransform = compose(rotate, projectTransform); |
| 12354 |
projectResample = resample(projectTransform, delta2); |
| 12355 |
return reset(); |
| 12356 |
} |
| 12357 |
|
| 12358 |
function reset() { |
| 12359 |
cache = cacheStream = null; |
| 12360 |
return projection; |
| 12361 |
} |
| 12362 |
|
| 12363 |
return function() { |
| 12364 |
project = projectAt.apply(this, arguments); |
| 12365 |
projection.invert = project.invert && invert; |
| 12366 |
return recenter(); |
| 12367 |
}; |
| 12368 |
} |
| 12369 |
|
| 12370 |
function conicProjection(projectAt) { |
| 12371 |
var phi0 = 0, |
| 12372 |
phi1 = pi$1 / 3, |
| 12373 |
m = projectionMutator(projectAt), |
| 12374 |
p = m(phi0, phi1); |
| 12375 |
|
| 12376 |
p.parallels = function(_) { |
| 12377 |
return arguments.length ? m(phi0 = _[0] * radians, phi1 = _[1] * radians) : [phi0 * degrees, phi1 * degrees]; |
| 12378 |
}; |
| 12379 |
|
| 12380 |
return p; |
| 12381 |
} |
| 12382 |
|
| 12383 |
function cylindricalEqualAreaRaw(phi0) { |
| 12384 |
var cosPhi0 = cos$1(phi0); |
| 12385 |
|
| 12386 |
function forward(lambda, phi) { |
| 12387 |
return [lambda * cosPhi0, sin$1(phi) / cosPhi0]; |
| 12388 |
} |
| 12389 |
|
| 12390 |
forward.invert = function(x, y) { |
| 12391 |
return [x / cosPhi0, asin$1(y * cosPhi0)]; |
| 12392 |
}; |
| 12393 |
|
| 12394 |
return forward; |
| 12395 |
} |
| 12396 |
|
| 12397 |
function conicEqualAreaRaw(y0, y1) { |
| 12398 |
var sy0 = sin$1(y0), n = (sy0 + sin$1(y1)) / 2; |
| 12399 |
|
| 12400 |
// Are the parallels symmetrical around the Equator? |
| 12401 |
if (abs$1(n) < epsilon$1) return cylindricalEqualAreaRaw(y0); |
| 12402 |
|
| 12403 |
var c = 1 + sy0 * (2 * n - sy0), r0 = sqrt$2(c) / n; |
| 12404 |
|
| 12405 |
function project(x, y) { |
| 12406 |
var r = sqrt$2(c - 2 * n * sin$1(y)) / n; |
| 12407 |
return [r * sin$1(x *= n), r0 - r * cos$1(x)]; |
| 12408 |
} |
| 12409 |
|
| 12410 |
project.invert = function(x, y) { |
| 12411 |
var r0y = r0 - y, |
| 12412 |
l = atan2$1(x, abs$1(r0y)) * sign$1(r0y); |
| 12413 |
if (r0y * n < 0) |
| 12414 |
l -= pi$1 * sign$1(x) * sign$1(r0y); |
| 12415 |
return [l / n, asin$1((c - (x * x + r0y * r0y) * n * n) / (2 * n))]; |
| 12416 |
}; |
| 12417 |
|
| 12418 |
return project; |
| 12419 |
} |
| 12420 |
|
| 12421 |
function conicEqualArea() { |
| 12422 |
return conicProjection(conicEqualAreaRaw) |
| 12423 |
.scale(155.424) |
| 12424 |
.center([0, 33.6442]); |
| 12425 |
} |
| 12426 |
|
| 12427 |
function albers() { |
| 12428 |
return conicEqualArea() |
| 12429 |
.parallels([29.5, 45.5]) |
| 12430 |
.scale(1070) |
| 12431 |
.translate([480, 250]) |
| 12432 |
.rotate([96, 0]) |
| 12433 |
.center([-0.6, 38.7]); |
| 12434 |
} |
| 12435 |
|
| 12436 |
// The projections must have mutually exclusive clip regions on the sphere, |
| 12437 |
// as this will avoid emitting interleaving lines and polygons. |
| 12438 |
function multiplex(streams) { |
| 12439 |
var n = streams.length; |
| 12440 |
return { |
| 12441 |
point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); }, |
| 12442 |
sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); }, |
| 12443 |
lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); }, |
| 12444 |
lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); }, |
| 12445 |
polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); }, |
| 12446 |
polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); } |
| 12447 |
}; |
| 12448 |
} |
| 12449 |
|
| 12450 |
// A composite projection for the United States, configured by default for |
| 12451 |
// 960×500. The projection also works quite well at 960×600 if you change the |
| 12452 |
// scale to 1285 and adjust the translate accordingly. The set of standard |
| 12453 |
// parallels for each region comes from USGS, which is published here: |
| 12454 |
// http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers |
| 12455 |
function albersUsa() { |
| 12456 |
var cache, |
| 12457 |
cacheStream, |
| 12458 |
lower48 = albers(), lower48Point, |
| 12459 |
alaska = conicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338 |
| 12460 |
hawaii = conicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007 |
| 12461 |
point, pointStream = {point: function(x, y) { point = [x, y]; }}; |
| 12462 |
|
| 12463 |
function albersUsa(coordinates) { |
| 12464 |
var x = coordinates[0], y = coordinates[1]; |
| 12465 |
return point = null, |
| 12466 |
(lower48Point.point(x, y), point) |
| 12467 |
|| (alaskaPoint.point(x, y), point) |
| 12468 |
|| (hawaiiPoint.point(x, y), point); |
| 12469 |
} |
| 12470 |
|
| 12471 |
albersUsa.invert = function(coordinates) { |
| 12472 |
var k = lower48.scale(), |
| 12473 |
t = lower48.translate(), |
| 12474 |
x = (coordinates[0] - t[0]) / k, |
| 12475 |
y = (coordinates[1] - t[1]) / k; |
| 12476 |
return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska |
| 12477 |
: y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii |
| 12478 |
: lower48).invert(coordinates); |
| 12479 |
}; |
| 12480 |
|
| 12481 |
albersUsa.stream = function(stream) { |
| 12482 |
return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]); |
| 12483 |
}; |
| 12484 |
|
| 12485 |
albersUsa.precision = function(_) { |
| 12486 |
if (!arguments.length) return lower48.precision(); |
| 12487 |
lower48.precision(_), alaska.precision(_), hawaii.precision(_); |
| 12488 |
return reset(); |
| 12489 |
}; |
| 12490 |
|
| 12491 |
albersUsa.scale = function(_) { |
| 12492 |
if (!arguments.length) return lower48.scale(); |
| 12493 |
lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_); |
| 12494 |
return albersUsa.translate(lower48.translate()); |
| 12495 |
}; |
| 12496 |
|
| 12497 |
albersUsa.translate = function(_) { |
| 12498 |
if (!arguments.length) return lower48.translate(); |
| 12499 |
var k = lower48.scale(), x = +_[0], y = +_[1]; |
| 12500 |
|
| 12501 |
lower48Point = lower48 |
| 12502 |
.translate(_) |
| 12503 |
.clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]]) |
| 12504 |
.stream(pointStream); |
| 12505 |
|
| 12506 |
alaskaPoint = alaska |
| 12507 |
.translate([x - 0.307 * k, y + 0.201 * k]) |
| 12508 |
.clipExtent([[x - 0.425 * k + epsilon$1, y + 0.120 * k + epsilon$1], [x - 0.214 * k - epsilon$1, y + 0.234 * k - epsilon$1]]) |
| 12509 |
.stream(pointStream); |
| 12510 |
|
| 12511 |
hawaiiPoint = hawaii |
| 12512 |
.translate([x - 0.205 * k, y + 0.212 * k]) |
| 12513 |
.clipExtent([[x - 0.214 * k + epsilon$1, y + 0.166 * k + epsilon$1], [x - 0.115 * k - epsilon$1, y + 0.234 * k - epsilon$1]]) |
| 12514 |
.stream(pointStream); |
| 12515 |
|
| 12516 |
return reset(); |
| 12517 |
}; |
| 12518 |
|
| 12519 |
albersUsa.fitExtent = function(extent, object) { |
| 12520 |
return fitExtent(albersUsa, extent, object); |
| 12521 |
}; |
| 12522 |
|
| 12523 |
albersUsa.fitSize = function(size, object) { |
| 12524 |
return fitSize(albersUsa, size, object); |
| 12525 |
}; |
| 12526 |
|
| 12527 |
albersUsa.fitWidth = function(width, object) { |
| 12528 |
return fitWidth(albersUsa, width, object); |
| 12529 |
}; |
| 12530 |
|
| 12531 |
albersUsa.fitHeight = function(height, object) { |
| 12532 |
return fitHeight(albersUsa, height, object); |
| 12533 |
}; |
| 12534 |
|
| 12535 |
function reset() { |
| 12536 |
cache = cacheStream = null; |
| 12537 |
return albersUsa; |
| 12538 |
} |
| 12539 |
|
| 12540 |
return albersUsa.scale(1070); |
| 12541 |
} |
| 12542 |
|
| 12543 |
function azimuthalRaw(scale) { |
| 12544 |
return function(x, y) { |
| 12545 |
var cx = cos$1(x), |
| 12546 |
cy = cos$1(y), |
| 12547 |
k = scale(cx * cy); |
| 12548 |
if (k === Infinity) return [2, 0]; |
| 12549 |
return [ |
| 12550 |
k * cy * sin$1(x), |
| 12551 |
k * sin$1(y) |
| 12552 |
]; |
| 12553 |
} |
| 12554 |
} |
| 12555 |
|
| 12556 |
function azimuthalInvert(angle) { |
| 12557 |
return function(x, y) { |
| 12558 |
var z = sqrt$2(x * x + y * y), |
| 12559 |
c = angle(z), |
| 12560 |
sc = sin$1(c), |
| 12561 |
cc = cos$1(c); |
| 12562 |
return [ |
| 12563 |
atan2$1(x * sc, z * cc), |
| 12564 |
asin$1(z && y * sc / z) |
| 12565 |
]; |
| 12566 |
} |
| 12567 |
} |
| 12568 |
|
| 12569 |
var azimuthalEqualAreaRaw = azimuthalRaw(function(cxcy) { |
| 12570 |
return sqrt$2(2 / (1 + cxcy)); |
| 12571 |
}); |
| 12572 |
|
| 12573 |
azimuthalEqualAreaRaw.invert = azimuthalInvert(function(z) { |
| 12574 |
return 2 * asin$1(z / 2); |
| 12575 |
}); |
| 12576 |
|
| 12577 |
function azimuthalEqualArea() { |
| 12578 |
return projection(azimuthalEqualAreaRaw) |
| 12579 |
.scale(124.75) |
| 12580 |
.clipAngle(180 - 1e-3); |
| 12581 |
} |
| 12582 |
|
| 12583 |
var azimuthalEquidistantRaw = azimuthalRaw(function(c) { |
| 12584 |
return (c = acos$1(c)) && c / sin$1(c); |
| 12585 |
}); |
| 12586 |
|
| 12587 |
azimuthalEquidistantRaw.invert = azimuthalInvert(function(z) { |
| 12588 |
return z; |
| 12589 |
}); |
| 12590 |
|
| 12591 |
function azimuthalEquidistant() { |
| 12592 |
return projection(azimuthalEquidistantRaw) |
| 12593 |
.scale(79.4188) |
| 12594 |
.clipAngle(180 - 1e-3); |
| 12595 |
} |
| 12596 |
|
| 12597 |
function mercatorRaw(lambda, phi) { |
| 12598 |
return [lambda, log$1(tan((halfPi$1 + phi) / 2))]; |
| 12599 |
} |
| 12600 |
|
| 12601 |
mercatorRaw.invert = function(x, y) { |
| 12602 |
return [x, 2 * atan(exp(y)) - halfPi$1]; |
| 12603 |
}; |
| 12604 |
|
| 12605 |
function mercator() { |
| 12606 |
return mercatorProjection(mercatorRaw) |
| 12607 |
.scale(961 / tau$1); |
| 12608 |
} |
| 12609 |
|
| 12610 |
function mercatorProjection(project) { |
| 12611 |
var m = projection(project), |
| 12612 |
center = m.center, |
| 12613 |
scale = m.scale, |
| 12614 |
translate = m.translate, |
| 12615 |
clipExtent = m.clipExtent, |
| 12616 |
x0 = null, y0, x1, y1; // clip extent |
| 12617 |
|
| 12618 |
m.scale = function(_) { |
| 12619 |
return arguments.length ? (scale(_), reclip()) : scale(); |
| 12620 |
}; |
| 12621 |
|
| 12622 |
m.translate = function(_) { |
| 12623 |
return arguments.length ? (translate(_), reclip()) : translate(); |
| 12624 |
}; |
| 12625 |
|
| 12626 |
m.center = function(_) { |
| 12627 |
return arguments.length ? (center(_), reclip()) : center(); |
| 12628 |
}; |
| 12629 |
|
| 12630 |
m.clipExtent = function(_) { |
| 12631 |
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]]; |
| 12632 |
}; |
| 12633 |
|
| 12634 |
function reclip() { |
| 12635 |
var k = pi$1 * scale(), |
| 12636 |
t = m(rotation(m.rotate()).invert([0, 0])); |
| 12637 |
return clipExtent(x0 == null |
| 12638 |
? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw |
| 12639 |
? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]] |
| 12640 |
: [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]); |
| 12641 |
} |
| 12642 |
|
| 12643 |
return reclip(); |
| 12644 |
} |
| 12645 |
|
| 12646 |
function tany(y) { |
| 12647 |
return tan((halfPi$1 + y) / 2); |
| 12648 |
} |
| 12649 |
|
| 12650 |
function conicConformalRaw(y0, y1) { |
| 12651 |
var cy0 = cos$1(y0), |
| 12652 |
n = y0 === y1 ? sin$1(y0) : log$1(cy0 / cos$1(y1)) / log$1(tany(y1) / tany(y0)), |
| 12653 |
f = cy0 * pow$1(tany(y0), n) / n; |
| 12654 |
|
| 12655 |
if (!n) return mercatorRaw; |
| 12656 |
|
| 12657 |
function project(x, y) { |
| 12658 |
if (f > 0) { if (y < -halfPi$1 + epsilon$1) y = -halfPi$1 + epsilon$1; } |
| 12659 |
else { if (y > halfPi$1 - epsilon$1) y = halfPi$1 - epsilon$1; } |
| 12660 |
var r = f / pow$1(tany(y), n); |
| 12661 |
return [r * sin$1(n * x), f - r * cos$1(n * x)]; |
| 12662 |
} |
| 12663 |
|
| 12664 |
project.invert = function(x, y) { |
| 12665 |
var fy = f - y, r = sign$1(n) * sqrt$2(x * x + fy * fy), |
| 12666 |
l = atan2$1(x, abs$1(fy)) * sign$1(fy); |
| 12667 |
if (fy * n < 0) |
| 12668 |
l -= pi$1 * sign$1(x) * sign$1(fy); |
| 12669 |
return [l / n, 2 * atan(pow$1(f / r, 1 / n)) - halfPi$1]; |
| 12670 |
}; |
| 12671 |
|
| 12672 |
return project; |
| 12673 |
} |
| 12674 |
|
| 12675 |
function conicConformal() { |
| 12676 |
return conicProjection(conicConformalRaw) |
| 12677 |
.scale(109.5) |
| 12678 |
.parallels([30, 30]); |
| 12679 |
} |
| 12680 |
|
| 12681 |
function equirectangularRaw(lambda, phi) { |
| 12682 |
return [lambda, phi]; |
| 12683 |
} |
| 12684 |
|
| 12685 |
equirectangularRaw.invert = equirectangularRaw; |
| 12686 |
|
| 12687 |
function equirectangular() { |
| 12688 |
return projection(equirectangularRaw) |
| 12689 |
.scale(152.63); |
| 12690 |
} |
| 12691 |
|
| 12692 |
function conicEquidistantRaw(y0, y1) { |
| 12693 |
var cy0 = cos$1(y0), |
| 12694 |
n = y0 === y1 ? sin$1(y0) : (cy0 - cos$1(y1)) / (y1 - y0), |
| 12695 |
g = cy0 / n + y0; |
| 12696 |
|
| 12697 |
if (abs$1(n) < epsilon$1) return equirectangularRaw; |
| 12698 |
|
| 12699 |
function project(x, y) { |
| 12700 |
var gy = g - y, nx = n * x; |
| 12701 |
return [gy * sin$1(nx), g - gy * cos$1(nx)]; |
| 12702 |
} |
| 12703 |
|
| 12704 |
project.invert = function(x, y) { |
| 12705 |
var gy = g - y, |
| 12706 |
l = atan2$1(x, abs$1(gy)) * sign$1(gy); |
| 12707 |
if (gy * n < 0) |
| 12708 |
l -= pi$1 * sign$1(x) * sign$1(gy); |
| 12709 |
return [l / n, g - sign$1(n) * sqrt$2(x * x + gy * gy)]; |
| 12710 |
}; |
| 12711 |
|
| 12712 |
return project; |
| 12713 |
} |
| 12714 |
|
| 12715 |
function conicEquidistant() { |
| 12716 |
return conicProjection(conicEquidistantRaw) |
| 12717 |
.scale(131.154) |
| 12718 |
.center([0, 13.9389]); |
| 12719 |
} |
| 12720 |
|
| 12721 |
var A1 = 1.340264, |
| 12722 |
A2 = -0.081106, |
| 12723 |
A3 = 0.000893, |
| 12724 |
A4 = 0.003796, |
| 12725 |
M = sqrt$2(3) / 2, |
| 12726 |
iterations = 12; |
| 12727 |
|
| 12728 |
function equalEarthRaw(lambda, phi) { |
| 12729 |
var l = asin$1(M * sin$1(phi)), l2 = l * l, l6 = l2 * l2 * l2; |
| 12730 |
return [ |
| 12731 |
lambda * cos$1(l) / (M * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2))), |
| 12732 |
l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) |
| 12733 |
]; |
| 12734 |
} |
| 12735 |
|
| 12736 |
equalEarthRaw.invert = function(x, y) { |
| 12737 |
var l = y, l2 = l * l, l6 = l2 * l2 * l2; |
| 12738 |
for (var i = 0, delta, fy, fpy; i < iterations; ++i) { |
| 12739 |
fy = l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y; |
| 12740 |
fpy = A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2); |
| 12741 |
l -= delta = fy / fpy, l2 = l * l, l6 = l2 * l2 * l2; |
| 12742 |
if (abs$1(delta) < epsilon2) break; |
| 12743 |
} |
| 12744 |
return [ |
| 12745 |
M * x * (A1 + 3 * A2 * l2 + l6 * (7 * A3 + 9 * A4 * l2)) / cos$1(l), |
| 12746 |
asin$1(sin$1(l) / M) |
| 12747 |
]; |
| 12748 |
}; |
| 12749 |
|
| 12750 |
function equalEarth() { |
| 12751 |
return projection(equalEarthRaw) |
| 12752 |
.scale(177.158); |
| 12753 |
} |
| 12754 |
|
| 12755 |
function gnomonicRaw(x, y) { |
| 12756 |
var cy = cos$1(y), k = cos$1(x) * cy; |
| 12757 |
return [cy * sin$1(x) / k, sin$1(y) / k]; |
| 12758 |
} |
| 12759 |
|
| 12760 |
gnomonicRaw.invert = azimuthalInvert(atan); |
| 12761 |
|
| 12762 |
function gnomonic() { |
| 12763 |
return projection(gnomonicRaw) |
| 12764 |
.scale(144.049) |
| 12765 |
.clipAngle(60); |
| 12766 |
} |
| 12767 |
|
| 12768 |
function identity$4() { |
| 12769 |
var k = 1, tx = 0, ty = 0, sx = 1, sy = 1, // scale, translate and reflect |
| 12770 |
alpha = 0, ca, sa, // angle |
| 12771 |
x0 = null, y0, x1, y1, // clip extent |
| 12772 |
kx = 1, ky = 1, |
| 12773 |
transform = transformer$3({ |
| 12774 |
point: function(x, y) { |
| 12775 |
var p = projection([x, y]); |
| 12776 |
this.stream.point(p[0], p[1]); |
| 12777 |
} |
| 12778 |
}), |
| 12779 |
postclip = identity$5, |
| 12780 |
cache, |
| 12781 |
cacheStream; |
| 12782 |
|
| 12783 |
function reset() { |
| 12784 |
kx = k * sx; |
| 12785 |
ky = k * sy; |
| 12786 |
cache = cacheStream = null; |
| 12787 |
return projection; |
| 12788 |
} |
| 12789 |
|
| 12790 |
function projection (p) { |
| 12791 |
var x = p[0] * kx, y = p[1] * ky; |
| 12792 |
if (alpha) { |
| 12793 |
var t = y * ca - x * sa; |
| 12794 |
x = x * ca + y * sa; |
| 12795 |
y = t; |
| 12796 |
} |
| 12797 |
return [x + tx, y + ty]; |
| 12798 |
} |
| 12799 |
projection.invert = function(p) { |
| 12800 |
var x = p[0] - tx, y = p[1] - ty; |
| 12801 |
if (alpha) { |
| 12802 |
var t = y * ca + x * sa; |
| 12803 |
x = x * ca - y * sa; |
| 12804 |
y = t; |
| 12805 |
} |
| 12806 |
return [x / kx, y / ky]; |
| 12807 |
}; |
| 12808 |
projection.stream = function(stream) { |
| 12809 |
return cache && cacheStream === stream ? cache : cache = transform(postclip(cacheStream = stream)); |
| 12810 |
}; |
| 12811 |
projection.postclip = function(_) { |
| 12812 |
return arguments.length ? (postclip = _, x0 = y0 = x1 = y1 = null, reset()) : postclip; |
| 12813 |
}; |
| 12814 |
projection.clipExtent = function(_) { |
| 12815 |
return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$5) : clipRectangle(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]]; |
| 12816 |
}; |
| 12817 |
projection.scale = function(_) { |
| 12818 |
return arguments.length ? (k = +_, reset()) : k; |
| 12819 |
}; |
| 12820 |
projection.translate = function(_) { |
| 12821 |
return arguments.length ? (tx = +_[0], ty = +_[1], reset()) : [tx, ty]; |
| 12822 |
}; |
| 12823 |
projection.angle = function(_) { |
| 12824 |
return arguments.length ? (alpha = _ % 360 * radians, sa = sin$1(alpha), ca = cos$1(alpha), reset()) : alpha * degrees; |
| 12825 |
}; |
| 12826 |
projection.reflectX = function(_) { |
| 12827 |
return arguments.length ? (sx = _ ? -1 : 1, reset()) : sx < 0; |
| 12828 |
}; |
| 12829 |
projection.reflectY = function(_) { |
| 12830 |
return arguments.length ? (sy = _ ? -1 : 1, reset()) : sy < 0; |
| 12831 |
}; |
| 12832 |
projection.fitExtent = function(extent, object) { |
| 12833 |
return fitExtent(projection, extent, object); |
| 12834 |
}; |
| 12835 |
projection.fitSize = function(size, object) { |
| 12836 |
return fitSize(projection, size, object); |
| 12837 |
}; |
| 12838 |
projection.fitWidth = function(width, object) { |
| 12839 |
return fitWidth(projection, width, object); |
| 12840 |
}; |
| 12841 |
projection.fitHeight = function(height, object) { |
| 12842 |
return fitHeight(projection, height, object); |
| 12843 |
}; |
| 12844 |
|
| 12845 |
return projection; |
| 12846 |
} |
| 12847 |
|
| 12848 |
function naturalEarth1Raw(lambda, phi) { |
| 12849 |
var phi2 = phi * phi, phi4 = phi2 * phi2; |
| 12850 |
return [ |
| 12851 |
lambda * (0.8707 - 0.131979 * phi2 + phi4 * (-0.013791 + phi4 * (0.003971 * phi2 - 0.001529 * phi4))), |
| 12852 |
phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) |
| 12853 |
]; |
| 12854 |
} |
| 12855 |
|
| 12856 |
naturalEarth1Raw.invert = function(x, y) { |
| 12857 |
var phi = y, i = 25, delta; |
| 12858 |
do { |
| 12859 |
var phi2 = phi * phi, phi4 = phi2 * phi2; |
| 12860 |
phi -= delta = (phi * (1.007226 + phi2 * (0.015085 + phi4 * (-0.044475 + 0.028874 * phi2 - 0.005916 * phi4))) - y) / |
| 12861 |
(1.007226 + phi2 * (0.015085 * 3 + phi4 * (-0.044475 * 7 + 0.028874 * 9 * phi2 - 0.005916 * 11 * phi4))); |
| 12862 |
} while (abs$1(delta) > epsilon$1 && --i > 0); |
| 12863 |
return [ |
| 12864 |
x / (0.8707 + (phi2 = phi * phi) * (-0.131979 + phi2 * (-0.013791 + phi2 * phi2 * phi2 * (0.003971 - 0.001529 * phi2)))), |
| 12865 |
phi |
| 12866 |
]; |
| 12867 |
}; |
| 12868 |
|
| 12869 |
function naturalEarth1() { |
| 12870 |
return projection(naturalEarth1Raw) |
| 12871 |
.scale(175.295); |
| 12872 |
} |
| 12873 |
|
| 12874 |
function orthographicRaw(x, y) { |
| 12875 |
return [cos$1(y) * sin$1(x), sin$1(y)]; |
| 12876 |
} |
| 12877 |
|
| 12878 |
orthographicRaw.invert = azimuthalInvert(asin$1); |
| 12879 |
|
| 12880 |
function orthographic() { |
| 12881 |
return projection(orthographicRaw) |
| 12882 |
.scale(249.5) |
| 12883 |
.clipAngle(90 + epsilon$1); |
| 12884 |
} |
| 12885 |
|
| 12886 |
function stereographicRaw(x, y) { |
| 12887 |
var cy = cos$1(y), k = 1 + cos$1(x) * cy; |
| 12888 |
return [cy * sin$1(x) / k, sin$1(y) / k]; |
| 12889 |
} |
| 12890 |
|
| 12891 |
stereographicRaw.invert = azimuthalInvert(function(z) { |
| 12892 |
return 2 * atan(z); |
| 12893 |
}); |
| 12894 |
|
| 12895 |
function stereographic() { |
| 12896 |
return projection(stereographicRaw) |
| 12897 |
.scale(250) |
| 12898 |
.clipAngle(142); |
| 12899 |
} |
| 12900 |
|
| 12901 |
function transverseMercatorRaw(lambda, phi) { |
| 12902 |
return [log$1(tan((halfPi$1 + phi) / 2)), -lambda]; |
| 12903 |
} |
| 12904 |
|
| 12905 |
transverseMercatorRaw.invert = function(x, y) { |
| 12906 |
return [-y, 2 * atan(exp(x)) - halfPi$1]; |
| 12907 |
}; |
| 12908 |
|
| 12909 |
function transverseMercator() { |
| 12910 |
var m = mercatorProjection(transverseMercatorRaw), |
| 12911 |
center = m.center, |
| 12912 |
rotate = m.rotate; |
| 12913 |
|
| 12914 |
m.center = function(_) { |
| 12915 |
return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]); |
| 12916 |
}; |
| 12917 |
|
| 12918 |
m.rotate = function(_) { |
| 12919 |
return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]); |
| 12920 |
}; |
| 12921 |
|
| 12922 |
return rotate([0, 0, 90]) |
| 12923 |
.scale(159.155); |
| 12924 |
} |
| 12925 |
|
| 12926 |
function defaultSeparation$1(a, b) { |
| 12927 |
return a.parent === b.parent ? 1 : 2; |
| 12928 |
} |
| 12929 |
|
| 12930 |
function meanX(children) { |
| 12931 |
return children.reduce(meanXReduce, 0) / children.length; |
| 12932 |
} |
| 12933 |
|
| 12934 |
function meanXReduce(x, c) { |
| 12935 |
return x + c.x; |
| 12936 |
} |
| 12937 |
|
| 12938 |
function maxY(children) { |
| 12939 |
return 1 + children.reduce(maxYReduce, 0); |
| 12940 |
} |
| 12941 |
|
| 12942 |
function maxYReduce(y, c) { |
| 12943 |
return Math.max(y, c.y); |
| 12944 |
} |
| 12945 |
|
| 12946 |
function leafLeft(node) { |
| 12947 |
var children; |
| 12948 |
while (children = node.children) node = children[0]; |
| 12949 |
return node; |
| 12950 |
} |
| 12951 |
|
| 12952 |
function leafRight(node) { |
| 12953 |
var children; |
| 12954 |
while (children = node.children) node = children[children.length - 1]; |
| 12955 |
return node; |
| 12956 |
} |
| 12957 |
|
| 12958 |
function cluster() { |
| 12959 |
var separation = defaultSeparation$1, |
| 12960 |
dx = 1, |
| 12961 |
dy = 1, |
| 12962 |
nodeSize = false; |
| 12963 |
|
| 12964 |
function cluster(root) { |
| 12965 |
var previousNode, |
| 12966 |
x = 0; |
| 12967 |
|
| 12968 |
// First walk, computing the initial x & y values. |
| 12969 |
root.eachAfter(function(node) { |
| 12970 |
var children = node.children; |
| 12971 |
if (children) { |
| 12972 |
node.x = meanX(children); |
| 12973 |
node.y = maxY(children); |
| 12974 |
} else { |
| 12975 |
node.x = previousNode ? x += separation(node, previousNode) : 0; |
| 12976 |
node.y = 0; |
| 12977 |
previousNode = node; |
| 12978 |
} |
| 12979 |
}); |
| 12980 |
|
| 12981 |
var left = leafLeft(root), |
| 12982 |
right = leafRight(root), |
| 12983 |
x0 = left.x - separation(left, right) / 2, |
| 12984 |
x1 = right.x + separation(right, left) / 2; |
| 12985 |
|
| 12986 |
// Second walk, normalizing x & y to the desired size. |
| 12987 |
return root.eachAfter(nodeSize ? function(node) { |
| 12988 |
node.x = (node.x - root.x) * dx; |
| 12989 |
node.y = (root.y - node.y) * dy; |
| 12990 |
} : function(node) { |
| 12991 |
node.x = (node.x - x0) / (x1 - x0) * dx; |
| 12992 |
node.y = (1 - (root.y ? node.y / root.y : 1)) * dy; |
| 12993 |
}); |
| 12994 |
} |
| 12995 |
|
| 12996 |
cluster.separation = function(x) { |
| 12997 |
return arguments.length ? (separation = x, cluster) : separation; |
| 12998 |
}; |
| 12999 |
|
| 13000 |
cluster.size = function(x) { |
| 13001 |
return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? null : [dx, dy]); |
| 13002 |
}; |
| 13003 |
|
| 13004 |
cluster.nodeSize = function(x) { |
| 13005 |
return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], cluster) : (nodeSize ? [dx, dy] : null); |
| 13006 |
}; |
| 13007 |
|
| 13008 |
return cluster; |
| 13009 |
} |
| 13010 |
|
| 13011 |
function count(node) { |
| 13012 |
var sum = 0, |
| 13013 |
children = node.children, |
| 13014 |
i = children && children.length; |
| 13015 |
if (!i) sum = 1; |
| 13016 |
else while (--i >= 0) sum += children[i].value; |
| 13017 |
node.value = sum; |
| 13018 |
} |
| 13019 |
|
| 13020 |
function node_count() { |
| 13021 |
return this.eachAfter(count); |
| 13022 |
} |
| 13023 |
|
| 13024 |
function node_each(callback, that) { |
| 13025 |
let index = -1; |
| 13026 |
for (const node of this) { |
| 13027 |
callback.call(that, node, ++index, this); |
| 13028 |
} |
| 13029 |
return this; |
| 13030 |
} |
| 13031 |
|
| 13032 |
function node_eachBefore(callback, that) { |
| 13033 |
var node = this, nodes = [node], children, i, index = -1; |
| 13034 |
while (node = nodes.pop()) { |
| 13035 |
callback.call(that, node, ++index, this); |
| 13036 |
if (children = node.children) { |
| 13037 |
for (i = children.length - 1; i >= 0; --i) { |
| 13038 |
nodes.push(children[i]); |
| 13039 |
} |
| 13040 |
} |
| 13041 |
} |
| 13042 |
return this; |
| 13043 |
} |
| 13044 |
|
| 13045 |
function node_eachAfter(callback, that) { |
| 13046 |
var node = this, nodes = [node], next = [], children, i, n, index = -1; |
| 13047 |
while (node = nodes.pop()) { |
| 13048 |
next.push(node); |
| 13049 |
if (children = node.children) { |
| 13050 |
for (i = 0, n = children.length; i < n; ++i) { |
| 13051 |
nodes.push(children[i]); |
| 13052 |
} |
| 13053 |
} |
| 13054 |
} |
| 13055 |
while (node = next.pop()) { |
| 13056 |
callback.call(that, node, ++index, this); |
| 13057 |
} |
| 13058 |
return this; |
| 13059 |
} |
| 13060 |
|
| 13061 |
function node_find(callback, that) { |
| 13062 |
let index = -1; |
| 13063 |
for (const node of this) { |
| 13064 |
if (callback.call(that, node, ++index, this)) { |
| 13065 |
return node; |
| 13066 |
} |
| 13067 |
} |
| 13068 |
} |
| 13069 |
|
| 13070 |
function node_sum(value) { |
| 13071 |
return this.eachAfter(function(node) { |
| 13072 |
var sum = +value(node.data) || 0, |
| 13073 |
children = node.children, |
| 13074 |
i = children && children.length; |
| 13075 |
while (--i >= 0) sum += children[i].value; |
| 13076 |
node.value = sum; |
| 13077 |
}); |
| 13078 |
} |
| 13079 |
|
| 13080 |
function node_sort(compare) { |
| 13081 |
return this.eachBefore(function(node) { |
| 13082 |
if (node.children) { |
| 13083 |
node.children.sort(compare); |
| 13084 |
} |
| 13085 |
}); |
| 13086 |
} |
| 13087 |
|
| 13088 |
function node_path(end) { |
| 13089 |
var start = this, |
| 13090 |
ancestor = leastCommonAncestor(start, end), |
| 13091 |
nodes = [start]; |
| 13092 |
while (start !== ancestor) { |
| 13093 |
start = start.parent; |
| 13094 |
nodes.push(start); |
| 13095 |
} |
| 13096 |
var k = nodes.length; |
| 13097 |
while (end !== ancestor) { |
| 13098 |
nodes.splice(k, 0, end); |
| 13099 |
end = end.parent; |
| 13100 |
} |
| 13101 |
return nodes; |
| 13102 |
} |
| 13103 |
|
| 13104 |
function leastCommonAncestor(a, b) { |
| 13105 |
if (a === b) return a; |
| 13106 |
var aNodes = a.ancestors(), |
| 13107 |
bNodes = b.ancestors(), |
| 13108 |
c = null; |
| 13109 |
a = aNodes.pop(); |
| 13110 |
b = bNodes.pop(); |
| 13111 |
while (a === b) { |
| 13112 |
c = a; |
| 13113 |
a = aNodes.pop(); |
| 13114 |
b = bNodes.pop(); |
| 13115 |
} |
| 13116 |
return c; |
| 13117 |
} |
| 13118 |
|
| 13119 |
function node_ancestors() { |
| 13120 |
var node = this, nodes = [node]; |
| 13121 |
while (node = node.parent) { |
| 13122 |
nodes.push(node); |
| 13123 |
} |
| 13124 |
return nodes; |
| 13125 |
} |
| 13126 |
|
| 13127 |
function node_descendants() { |
| 13128 |
return Array.from(this); |
| 13129 |
} |
| 13130 |
|
| 13131 |
function node_leaves() { |
| 13132 |
var leaves = []; |
| 13133 |
this.eachBefore(function(node) { |
| 13134 |
if (!node.children) { |
| 13135 |
leaves.push(node); |
| 13136 |
} |
| 13137 |
}); |
| 13138 |
return leaves; |
| 13139 |
} |
| 13140 |
|
| 13141 |
function node_links() { |
| 13142 |
var root = this, links = []; |
| 13143 |
root.each(function(node) { |
| 13144 |
if (node !== root) { // Don’t include the root’s parent, if any. |
| 13145 |
links.push({source: node.parent, target: node}); |
| 13146 |
} |
| 13147 |
}); |
| 13148 |
return links; |
| 13149 |
} |
| 13150 |
|
| 13151 |
function* node_iterator() { |
| 13152 |
var node = this, current, next = [node], children, i, n; |
| 13153 |
do { |
| 13154 |
current = next.reverse(), next = []; |
| 13155 |
while (node = current.pop()) { |
| 13156 |
yield node; |
| 13157 |
if (children = node.children) { |
| 13158 |
for (i = 0, n = children.length; i < n; ++i) { |
| 13159 |
next.push(children[i]); |
| 13160 |
} |
| 13161 |
} |
| 13162 |
} |
| 13163 |
} while (next.length); |
| 13164 |
} |
| 13165 |
|
| 13166 |
function hierarchy(data, children) { |
| 13167 |
if (data instanceof Map) { |
| 13168 |
data = [undefined, data]; |
| 13169 |
if (children === undefined) children = mapChildren; |
| 13170 |
} else if (children === undefined) { |
| 13171 |
children = objectChildren; |
| 13172 |
} |
| 13173 |
|
| 13174 |
var root = new Node$1(data), |
| 13175 |
node, |
| 13176 |
nodes = [root], |
| 13177 |
child, |
| 13178 |
childs, |
| 13179 |
i, |
| 13180 |
n; |
| 13181 |
|
| 13182 |
while (node = nodes.pop()) { |
| 13183 |
if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) { |
| 13184 |
node.children = childs; |
| 13185 |
for (i = n - 1; i >= 0; --i) { |
| 13186 |
nodes.push(child = childs[i] = new Node$1(childs[i])); |
| 13187 |
child.parent = node; |
| 13188 |
child.depth = node.depth + 1; |
| 13189 |
} |
| 13190 |
} |
| 13191 |
} |
| 13192 |
|
| 13193 |
return root.eachBefore(computeHeight); |
| 13194 |
} |
| 13195 |
|
| 13196 |
function node_copy() { |
| 13197 |
return hierarchy(this).eachBefore(copyData); |
| 13198 |
} |
| 13199 |
|
| 13200 |
function objectChildren(d) { |
| 13201 |
return d.children; |
| 13202 |
} |
| 13203 |
|
| 13204 |
function mapChildren(d) { |
| 13205 |
return Array.isArray(d) ? d[1] : null; |
| 13206 |
} |
| 13207 |
|
| 13208 |
function copyData(node) { |
| 13209 |
if (node.data.value !== undefined) node.value = node.data.value; |
| 13210 |
node.data = node.data.data; |
| 13211 |
} |
| 13212 |
|
| 13213 |
function computeHeight(node) { |
| 13214 |
var height = 0; |
| 13215 |
do node.height = height; |
| 13216 |
while ((node = node.parent) && (node.height < ++height)); |
| 13217 |
} |
| 13218 |
|
| 13219 |
function Node$1(data) { |
| 13220 |
this.data = data; |
| 13221 |
this.depth = |
| 13222 |
this.height = 0; |
| 13223 |
this.parent = null; |
| 13224 |
} |
| 13225 |
|
| 13226 |
Node$1.prototype = hierarchy.prototype = { |
| 13227 |
constructor: Node$1, |
| 13228 |
count: node_count, |
| 13229 |
each: node_each, |
| 13230 |
eachAfter: node_eachAfter, |
| 13231 |
eachBefore: node_eachBefore, |
| 13232 |
find: node_find, |
| 13233 |
sum: node_sum, |
| 13234 |
sort: node_sort, |
| 13235 |
path: node_path, |
| 13236 |
ancestors: node_ancestors, |
| 13237 |
descendants: node_descendants, |
| 13238 |
leaves: node_leaves, |
| 13239 |
links: node_links, |
| 13240 |
copy: node_copy, |
| 13241 |
[Symbol.iterator]: node_iterator |
| 13242 |
}; |
| 13243 |
|
| 13244 |
function optional(f) { |
| 13245 |
return f == null ? null : required(f); |
| 13246 |
} |
| 13247 |
|
| 13248 |
function required(f) { |
| 13249 |
if (typeof f !== "function") throw new Error; |
| 13250 |
return f; |
| 13251 |
} |
| 13252 |
|
| 13253 |
function constantZero() { |
| 13254 |
return 0; |
| 13255 |
} |
| 13256 |
|
| 13257 |
function constant$2(x) { |
| 13258 |
return function() { |
| 13259 |
return x; |
| 13260 |
}; |
| 13261 |
} |
| 13262 |
|
| 13263 |
// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use |
| 13264 |
const a$1 = 1664525; |
| 13265 |
const c$3 = 1013904223; |
| 13266 |
const m = 4294967296; // 2^32 |
| 13267 |
|
| 13268 |
function lcg$1() { |
| 13269 |
let s = 1; |
| 13270 |
return () => (s = (a$1 * s + c$3) % m) / m; |
| 13271 |
} |
| 13272 |
|
| 13273 |
function array$1(x) { |
| 13274 |
return typeof x === "object" && "length" in x |
| 13275 |
? x // Array, TypedArray, NodeList, array-like |
| 13276 |
: Array.from(x); // Map, Set, iterable, string, or anything else |
| 13277 |
} |
| 13278 |
|
| 13279 |
function shuffle(array, random) { |
| 13280 |
let m = array.length, |
| 13281 |
t, |
| 13282 |
i; |
| 13283 |
|
| 13284 |
while (m) { |
| 13285 |
i = random() * m-- | 0; |
| 13286 |
t = array[m]; |
| 13287 |
array[m] = array[i]; |
| 13288 |
array[i] = t; |
| 13289 |
} |
| 13290 |
|
| 13291 |
return array; |
| 13292 |
} |
| 13293 |
|
| 13294 |
function enclose(circles) { |
| 13295 |
return packEncloseRandom(circles, lcg$1()); |
| 13296 |
} |
| 13297 |
|
| 13298 |
function packEncloseRandom(circles, random) { |
| 13299 |
var i = 0, n = (circles = shuffle(Array.from(circles), random)).length, B = [], p, e; |
| 13300 |
|
| 13301 |
while (i < n) { |
| 13302 |
p = circles[i]; |
| 13303 |
if (e && enclosesWeak(e, p)) ++i; |
| 13304 |
else e = encloseBasis(B = extendBasis(B, p)), i = 0; |
| 13305 |
} |
| 13306 |
|
| 13307 |
return e; |
| 13308 |
} |
| 13309 |
|
| 13310 |
function extendBasis(B, p) { |
| 13311 |
var i, j; |
| 13312 |
|
| 13313 |
if (enclosesWeakAll(p, B)) return [p]; |
| 13314 |
|
| 13315 |
// If we get here then B must have at least one element. |
| 13316 |
for (i = 0; i < B.length; ++i) { |
| 13317 |
if (enclosesNot(p, B[i]) |
| 13318 |
&& enclosesWeakAll(encloseBasis2(B[i], p), B)) { |
| 13319 |
return [B[i], p]; |
| 13320 |
} |
| 13321 |
} |
| 13322 |
|
| 13323 |
// If we get here then B must have at least two elements. |
| 13324 |
for (i = 0; i < B.length - 1; ++i) { |
| 13325 |
for (j = i + 1; j < B.length; ++j) { |
| 13326 |
if (enclosesNot(encloseBasis2(B[i], B[j]), p) |
| 13327 |
&& enclosesNot(encloseBasis2(B[i], p), B[j]) |
| 13328 |
&& enclosesNot(encloseBasis2(B[j], p), B[i]) |
| 13329 |
&& enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) { |
| 13330 |
return [B[i], B[j], p]; |
| 13331 |
} |
| 13332 |
} |
| 13333 |
} |
| 13334 |
|
| 13335 |
// If we get here then something is very wrong. |
| 13336 |
throw new Error; |
| 13337 |
} |
| 13338 |
|
| 13339 |
function enclosesNot(a, b) { |
| 13340 |
var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y; |
| 13341 |
return dr < 0 || dr * dr < dx * dx + dy * dy; |
| 13342 |
} |
| 13343 |
|
| 13344 |
function enclosesWeak(a, b) { |
| 13345 |
var dr = a.r - b.r + Math.max(a.r, b.r, 1) * 1e-9, dx = b.x - a.x, dy = b.y - a.y; |
| 13346 |
return dr > 0 && dr * dr > dx * dx + dy * dy; |
| 13347 |
} |
| 13348 |
|
| 13349 |
function enclosesWeakAll(a, B) { |
| 13350 |
for (var i = 0; i < B.length; ++i) { |
| 13351 |
if (!enclosesWeak(a, B[i])) { |
| 13352 |
return false; |
| 13353 |
} |
| 13354 |
} |
| 13355 |
return true; |
| 13356 |
} |
| 13357 |
|
| 13358 |
function encloseBasis(B) { |
| 13359 |
switch (B.length) { |
| 13360 |
case 1: return encloseBasis1(B[0]); |
| 13361 |
case 2: return encloseBasis2(B[0], B[1]); |
| 13362 |
case 3: return encloseBasis3(B[0], B[1], B[2]); |
| 13363 |
} |
| 13364 |
} |
| 13365 |
|
| 13366 |
function encloseBasis1(a) { |
| 13367 |
return { |
| 13368 |
x: a.x, |
| 13369 |
y: a.y, |
| 13370 |
r: a.r |
| 13371 |
}; |
| 13372 |
} |
| 13373 |
|
| 13374 |
function encloseBasis2(a, b) { |
| 13375 |
var x1 = a.x, y1 = a.y, r1 = a.r, |
| 13376 |
x2 = b.x, y2 = b.y, r2 = b.r, |
| 13377 |
x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1, |
| 13378 |
l = Math.sqrt(x21 * x21 + y21 * y21); |
| 13379 |
return { |
| 13380 |
x: (x1 + x2 + x21 / l * r21) / 2, |
| 13381 |
y: (y1 + y2 + y21 / l * r21) / 2, |
| 13382 |
r: (l + r1 + r2) / 2 |
| 13383 |
}; |
| 13384 |
} |
| 13385 |
|
| 13386 |
function encloseBasis3(a, b, c) { |
| 13387 |
var x1 = a.x, y1 = a.y, r1 = a.r, |
| 13388 |
x2 = b.x, y2 = b.y, r2 = b.r, |
| 13389 |
x3 = c.x, y3 = c.y, r3 = c.r, |
| 13390 |
a2 = x1 - x2, |
| 13391 |
a3 = x1 - x3, |
| 13392 |
b2 = y1 - y2, |
| 13393 |
b3 = y1 - y3, |
| 13394 |
c2 = r2 - r1, |
| 13395 |
c3 = r3 - r1, |
| 13396 |
d1 = x1 * x1 + y1 * y1 - r1 * r1, |
| 13397 |
d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2, |
| 13398 |
d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3, |
| 13399 |
ab = a3 * b2 - a2 * b3, |
| 13400 |
xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1, |
| 13401 |
xb = (b3 * c2 - b2 * c3) / ab, |
| 13402 |
ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1, |
| 13403 |
yb = (a2 * c3 - a3 * c2) / ab, |
| 13404 |
A = xb * xb + yb * yb - 1, |
| 13405 |
B = 2 * (r1 + xa * xb + ya * yb), |
| 13406 |
C = xa * xa + ya * ya - r1 * r1, |
| 13407 |
r = -(Math.abs(A) > 1e-6 ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B); |
| 13408 |
return { |
| 13409 |
x: x1 + xa + xb * r, |
| 13410 |
y: y1 + ya + yb * r, |
| 13411 |
r: r |
| 13412 |
}; |
| 13413 |
} |
| 13414 |
|
| 13415 |
function place(b, a, c) { |
| 13416 |
var dx = b.x - a.x, x, a2, |
| 13417 |
dy = b.y - a.y, y, b2, |
| 13418 |
d2 = dx * dx + dy * dy; |
| 13419 |
if (d2) { |
| 13420 |
a2 = a.r + c.r, a2 *= a2; |
| 13421 |
b2 = b.r + c.r, b2 *= b2; |
| 13422 |
if (a2 > b2) { |
| 13423 |
x = (d2 + b2 - a2) / (2 * d2); |
| 13424 |
y = Math.sqrt(Math.max(0, b2 / d2 - x * x)); |
| 13425 |
c.x = b.x - x * dx - y * dy; |
| 13426 |
c.y = b.y - x * dy + y * dx; |
| 13427 |
} else { |
| 13428 |
x = (d2 + a2 - b2) / (2 * d2); |
| 13429 |
y = Math.sqrt(Math.max(0, a2 / d2 - x * x)); |
| 13430 |
c.x = a.x + x * dx - y * dy; |
| 13431 |
c.y = a.y + x * dy + y * dx; |
| 13432 |
} |
| 13433 |
} else { |
| 13434 |
c.x = a.x + c.r; |
| 13435 |
c.y = a.y; |
| 13436 |
} |
| 13437 |
} |
| 13438 |
|
| 13439 |
function intersects(a, b) { |
| 13440 |
var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y; |
| 13441 |
return dr > 0 && dr * dr > dx * dx + dy * dy; |
| 13442 |
} |
| 13443 |
|
| 13444 |
function score(node) { |
| 13445 |
var a = node._, |
| 13446 |
b = node.next._, |
| 13447 |
ab = a.r + b.r, |
| 13448 |
dx = (a.x * b.r + b.x * a.r) / ab, |
| 13449 |
dy = (a.y * b.r + b.y * a.r) / ab; |
| 13450 |
return dx * dx + dy * dy; |
| 13451 |
} |
| 13452 |
|
| 13453 |
function Node(circle) { |
| 13454 |
this._ = circle; |
| 13455 |
this.next = null; |
| 13456 |
this.previous = null; |
| 13457 |
} |
| 13458 |
|
| 13459 |
function packSiblingsRandom(circles, random) { |
| 13460 |
if (!(n = (circles = array$1(circles)).length)) return 0; |
| 13461 |
|
| 13462 |
var a, b, c, n, aa, ca, i, j, k, sj, sk; |
| 13463 |
|
| 13464 |
// Place the first circle. |
| 13465 |
a = circles[0], a.x = 0, a.y = 0; |
| 13466 |
if (!(n > 1)) return a.r; |
| 13467 |
|
| 13468 |
// Place the second circle. |
| 13469 |
b = circles[1], a.x = -b.r, b.x = a.r, b.y = 0; |
| 13470 |
if (!(n > 2)) return a.r + b.r; |
| 13471 |
|
| 13472 |
// Place the third circle. |
| 13473 |
place(b, a, c = circles[2]); |
| 13474 |
|
| 13475 |
// Initialize the front-chain using the first three circles a, b and c. |
| 13476 |
a = new Node(a), b = new Node(b), c = new Node(c); |
| 13477 |
a.next = c.previous = b; |
| 13478 |
b.next = a.previous = c; |
| 13479 |
c.next = b.previous = a; |
| 13480 |
|
| 13481 |
// Attempt to place each remaining circle… |
| 13482 |
pack: for (i = 3; i < n; ++i) { |
| 13483 |
place(a._, b._, c = circles[i]), c = new Node(c); |
| 13484 |
|
| 13485 |
// Find the closest intersecting circle on the front-chain, if any. |
| 13486 |
// “Closeness” is determined by linear distance along the front-chain. |
| 13487 |
// “Ahead” or “behind” is likewise determined by linear distance. |
| 13488 |
j = b.next, k = a.previous, sj = b._.r, sk = a._.r; |
| 13489 |
do { |
| 13490 |
if (sj <= sk) { |
| 13491 |
if (intersects(j._, c._)) { |
| 13492 |
b = j, a.next = b, b.previous = a, --i; |
| 13493 |
continue pack; |
| 13494 |
} |
| 13495 |
sj += j._.r, j = j.next; |
| 13496 |
} else { |
| 13497 |
if (intersects(k._, c._)) { |
| 13498 |
a = k, a.next = b, b.previous = a, --i; |
| 13499 |
continue pack; |
| 13500 |
} |
| 13501 |
sk += k._.r, k = k.previous; |
| 13502 |
} |
| 13503 |
} while (j !== k.next); |
| 13504 |
|
| 13505 |
// Success! Insert the new circle c between a and b. |
| 13506 |
c.previous = a, c.next = b, a.next = b.previous = b = c; |
| 13507 |
|
| 13508 |
// Compute the new closest circle pair to the centroid. |
| 13509 |
aa = score(a); |
| 13510 |
while ((c = c.next) !== b) { |
| 13511 |
if ((ca = score(c)) < aa) { |
| 13512 |
a = c, aa = ca; |
| 13513 |
} |
| 13514 |
} |
| 13515 |
b = a.next; |
| 13516 |
} |
| 13517 |
|
| 13518 |
// Compute the enclosing circle of the front chain. |
| 13519 |
a = [b._], c = b; while ((c = c.next) !== b) a.push(c._); c = packEncloseRandom(a, random); |
| 13520 |
|
| 13521 |
// Translate the circles to put the enclosing circle around the origin. |
| 13522 |
for (i = 0; i < n; ++i) a = circles[i], a.x -= c.x, a.y -= c.y; |
| 13523 |
|
| 13524 |
return c.r; |
| 13525 |
} |
| 13526 |
|
| 13527 |
function siblings(circles) { |
| 13528 |
packSiblingsRandom(circles, lcg$1()); |
| 13529 |
return circles; |
| 13530 |
} |
| 13531 |
|
| 13532 |
function defaultRadius(d) { |
| 13533 |
return Math.sqrt(d.value); |
| 13534 |
} |
| 13535 |
|
| 13536 |
function index$1() { |
| 13537 |
var radius = null, |
| 13538 |
dx = 1, |
| 13539 |
dy = 1, |
| 13540 |
padding = constantZero; |
| 13541 |
|
| 13542 |
function pack(root) { |
| 13543 |
const random = lcg$1(); |
| 13544 |
root.x = dx / 2, root.y = dy / 2; |
| 13545 |
if (radius) { |
| 13546 |
root.eachBefore(radiusLeaf(radius)) |
| 13547 |
.eachAfter(packChildrenRandom(padding, 0.5, random)) |
| 13548 |
.eachBefore(translateChild(1)); |
| 13549 |
} else { |
| 13550 |
root.eachBefore(radiusLeaf(defaultRadius)) |
| 13551 |
.eachAfter(packChildrenRandom(constantZero, 1, random)) |
| 13552 |
.eachAfter(packChildrenRandom(padding, root.r / Math.min(dx, dy), random)) |
| 13553 |
.eachBefore(translateChild(Math.min(dx, dy) / (2 * root.r))); |
| 13554 |
} |
| 13555 |
return root; |
| 13556 |
} |
| 13557 |
|
| 13558 |
pack.radius = function(x) { |
| 13559 |
return arguments.length ? (radius = optional(x), pack) : radius; |
| 13560 |
}; |
| 13561 |
|
| 13562 |
pack.size = function(x) { |
| 13563 |
return arguments.length ? (dx = +x[0], dy = +x[1], pack) : [dx, dy]; |
| 13564 |
}; |
| 13565 |
|
| 13566 |
pack.padding = function(x) { |
| 13567 |
return arguments.length ? (padding = typeof x === "function" ? x : constant$2(+x), pack) : padding; |
| 13568 |
}; |
| 13569 |
|
| 13570 |
return pack; |
| 13571 |
} |
| 13572 |
|
| 13573 |
function radiusLeaf(radius) { |
| 13574 |
return function(node) { |
| 13575 |
if (!node.children) { |
| 13576 |
node.r = Math.max(0, +radius(node) || 0); |
| 13577 |
} |
| 13578 |
}; |
| 13579 |
} |
| 13580 |
|
| 13581 |
function packChildrenRandom(padding, k, random) { |
| 13582 |
return function(node) { |
| 13583 |
if (children = node.children) { |
| 13584 |
var children, |
| 13585 |
i, |
| 13586 |
n = children.length, |
| 13587 |
r = padding(node) * k || 0, |
| 13588 |
e; |
| 13589 |
|
| 13590 |
if (r) for (i = 0; i < n; ++i) children[i].r += r; |
| 13591 |
e = packSiblingsRandom(children, random); |
| 13592 |
if (r) for (i = 0; i < n; ++i) children[i].r -= r; |
| 13593 |
node.r = e + r; |
| 13594 |
} |
| 13595 |
}; |
| 13596 |
} |
| 13597 |
|
| 13598 |
function translateChild(k) { |
| 13599 |
return function(node) { |
| 13600 |
var parent = node.parent; |
| 13601 |
node.r *= k; |
| 13602 |
if (parent) { |
| 13603 |
node.x = parent.x + k * node.x; |
| 13604 |
node.y = parent.y + k * node.y; |
| 13605 |
} |
| 13606 |
}; |
| 13607 |
} |
| 13608 |
|
| 13609 |
function roundNode(node) { |
| 13610 |
node.x0 = Math.round(node.x0); |
| 13611 |
node.y0 = Math.round(node.y0); |
| 13612 |
node.x1 = Math.round(node.x1); |
| 13613 |
node.y1 = Math.round(node.y1); |
| 13614 |
} |
| 13615 |
|
| 13616 |
function treemapDice(parent, x0, y0, x1, y1) { |
| 13617 |
var nodes = parent.children, |
| 13618 |
node, |
| 13619 |
i = -1, |
| 13620 |
n = nodes.length, |
| 13621 |
k = parent.value && (x1 - x0) / parent.value; |
| 13622 |
|
| 13623 |
while (++i < n) { |
| 13624 |
node = nodes[i], node.y0 = y0, node.y1 = y1; |
| 13625 |
node.x0 = x0, node.x1 = x0 += node.value * k; |
| 13626 |
} |
| 13627 |
} |
| 13628 |
|
| 13629 |
function partition() { |
| 13630 |
var dx = 1, |
| 13631 |
dy = 1, |
| 13632 |
padding = 0, |
| 13633 |
round = false; |
| 13634 |
|
| 13635 |
function partition(root) { |
| 13636 |
var n = root.height + 1; |
| 13637 |
root.x0 = |
| 13638 |
root.y0 = padding; |
| 13639 |
root.x1 = dx; |
| 13640 |
root.y1 = dy / n; |
| 13641 |
root.eachBefore(positionNode(dy, n)); |
| 13642 |
if (round) root.eachBefore(roundNode); |
| 13643 |
return root; |
| 13644 |
} |
| 13645 |
|
| 13646 |
function positionNode(dy, n) { |
| 13647 |
return function(node) { |
| 13648 |
if (node.children) { |
| 13649 |
treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n); |
| 13650 |
} |
| 13651 |
var x0 = node.x0, |
| 13652 |
y0 = node.y0, |
| 13653 |
x1 = node.x1 - padding, |
| 13654 |
y1 = node.y1 - padding; |
| 13655 |
if (x1 < x0) x0 = x1 = (x0 + x1) / 2; |
| 13656 |
if (y1 < y0) y0 = y1 = (y0 + y1) / 2; |
| 13657 |
node.x0 = x0; |
| 13658 |
node.y0 = y0; |
| 13659 |
node.x1 = x1; |
| 13660 |
node.y1 = y1; |
| 13661 |
}; |
| 13662 |
} |
| 13663 |
|
| 13664 |
partition.round = function(x) { |
| 13665 |
return arguments.length ? (round = !!x, partition) : round; |
| 13666 |
}; |
| 13667 |
|
| 13668 |
partition.size = function(x) { |
| 13669 |
return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy]; |
| 13670 |
}; |
| 13671 |
|
| 13672 |
partition.padding = function(x) { |
| 13673 |
return arguments.length ? (padding = +x, partition) : padding; |
| 13674 |
}; |
| 13675 |
|
| 13676 |
return partition; |
| 13677 |
} |
| 13678 |
|
| 13679 |
var preroot = {depth: -1}, |
| 13680 |
ambiguous = {}, |
| 13681 |
imputed = {}; |
| 13682 |
|
| 13683 |
function defaultId(d) { |
| 13684 |
return d.id; |
| 13685 |
} |
| 13686 |
|
| 13687 |
function defaultParentId(d) { |
| 13688 |
return d.parentId; |
| 13689 |
} |
| 13690 |
|
| 13691 |
function stratify() { |
| 13692 |
var id = defaultId, |
| 13693 |
parentId = defaultParentId, |
| 13694 |
path; |
| 13695 |
|
| 13696 |
function stratify(data) { |
| 13697 |
var nodes = Array.from(data), |
| 13698 |
currentId = id, |
| 13699 |
currentParentId = parentId, |
| 13700 |
n, |
| 13701 |
d, |
| 13702 |
i, |
| 13703 |
root, |
| 13704 |
parent, |
| 13705 |
node, |
| 13706 |
nodeId, |
| 13707 |
nodeKey, |
| 13708 |
nodeByKey = new Map; |
| 13709 |
|
| 13710 |
if (path != null) { |
| 13711 |
const I = nodes.map((d, i) => normalize$1(path(d, i, data))); |
| 13712 |
const P = I.map(parentof); |
| 13713 |
const S = new Set(I).add(""); |
| 13714 |
for (const i of P) { |
| 13715 |
if (!S.has(i)) { |
| 13716 |
S.add(i); |
| 13717 |
I.push(i); |
| 13718 |
P.push(parentof(i)); |
| 13719 |
nodes.push(imputed); |
| 13720 |
} |
| 13721 |
} |
| 13722 |
currentId = (_, i) => I[i]; |
| 13723 |
currentParentId = (_, i) => P[i]; |
| 13724 |
} |
| 13725 |
|
| 13726 |
for (i = 0, n = nodes.length; i < n; ++i) { |
| 13727 |
d = nodes[i], node = nodes[i] = new Node$1(d); |
| 13728 |
if ((nodeId = currentId(d, i, data)) != null && (nodeId += "")) { |
| 13729 |
nodeKey = node.id = nodeId; |
| 13730 |
nodeByKey.set(nodeKey, nodeByKey.has(nodeKey) ? ambiguous : node); |
| 13731 |
} |
| 13732 |
if ((nodeId = currentParentId(d, i, data)) != null && (nodeId += "")) { |
| 13733 |
node.parent = nodeId; |
| 13734 |
} |
| 13735 |
} |
| 13736 |
|
| 13737 |
for (i = 0; i < n; ++i) { |
| 13738 |
node = nodes[i]; |
| 13739 |
if (nodeId = node.parent) { |
| 13740 |
parent = nodeByKey.get(nodeId); |
| 13741 |
if (!parent) throw new Error("missing: " + nodeId); |
| 13742 |
if (parent === ambiguous) throw new Error("ambiguous: " + nodeId); |
| 13743 |
if (parent.children) parent.children.push(node); |
| 13744 |
else parent.children = [node]; |
| 13745 |
node.parent = parent; |
| 13746 |
} else { |
| 13747 |
if (root) throw new Error("multiple roots"); |
| 13748 |
root = node; |
| 13749 |
} |
| 13750 |
} |
| 13751 |
|
| 13752 |
if (!root) throw new Error("no root"); |
| 13753 |
|
| 13754 |
// When imputing internal nodes, only introduce roots if needed. |
| 13755 |
// Then replace the imputed marker data with null. |
| 13756 |
if (path != null) { |
| 13757 |
while (root.data === imputed && root.children.length === 1) { |
| 13758 |
root = root.children[0], --n; |
| 13759 |
} |
| 13760 |
for (let i = nodes.length - 1; i >= 0; --i) { |
| 13761 |
node = nodes[i]; |
| 13762 |
if (node.data !== imputed) break; |
| 13763 |
node.data = null; |
| 13764 |
} |
| 13765 |
} |
| 13766 |
|
| 13767 |
root.parent = preroot; |
| 13768 |
root.eachBefore(function(node) { node.depth = node.parent.depth + 1; --n; }).eachBefore(computeHeight); |
| 13769 |
root.parent = null; |
| 13770 |
if (n > 0) throw new Error("cycle"); |
| 13771 |
|
| 13772 |
return root; |
| 13773 |
} |
| 13774 |
|
| 13775 |
stratify.id = function(x) { |
| 13776 |
return arguments.length ? (id = optional(x), stratify) : id; |
| 13777 |
}; |
| 13778 |
|
| 13779 |
stratify.parentId = function(x) { |
| 13780 |
return arguments.length ? (parentId = optional(x), stratify) : parentId; |
| 13781 |
}; |
| 13782 |
|
| 13783 |
stratify.path = function(x) { |
| 13784 |
return arguments.length ? (path = optional(x), stratify) : path; |
| 13785 |
}; |
| 13786 |
|
| 13787 |
return stratify; |
| 13788 |
} |
| 13789 |
|
| 13790 |
// To normalize a path, we coerce to a string, strip the trailing slash if any |
| 13791 |
// (as long as the trailing slash is not immediately preceded by another slash), |
| 13792 |
// and add leading slash if missing. |
| 13793 |
function normalize$1(path) { |
| 13794 |
path = `${path}`; |
| 13795 |
let i = path.length; |
| 13796 |
if (slash(path, i - 1) && !slash(path, i - 2)) path = path.slice(0, -1); |
| 13797 |
return path[0] === "/" ? path : `/${path}`; |
| 13798 |
} |
| 13799 |
|
| 13800 |
// Walk backwards to find the first slash that is not the leading slash, e.g.: |
| 13801 |
// "/foo/bar" ⇥ "/foo", "/foo" ⇥ "/", "/" ↦ "". (The root is special-cased |
| 13802 |
// because the id of the root must be a truthy value.) |
| 13803 |
function parentof(path) { |
| 13804 |
let i = path.length; |
| 13805 |
if (i < 2) return ""; |
| 13806 |
while (--i > 1) if (slash(path, i)) break; |
| 13807 |
return path.slice(0, i); |
| 13808 |
} |
| 13809 |
|
| 13810 |
// Slashes can be escaped; to determine whether a slash is a path delimiter, we |
| 13811 |
// count the number of preceding backslashes escaping the forward slash: an odd |
| 13812 |
// number indicates an escaped forward slash. |
| 13813 |
function slash(path, i) { |
| 13814 |
if (path[i] === "/") { |
| 13815 |
let k = 0; |
| 13816 |
while (i > 0 && path[--i] === "\\") ++k; |
| 13817 |
if ((k & 1) === 0) return true; |
| 13818 |
} |
| 13819 |
return false; |
| 13820 |
} |
| 13821 |
|
| 13822 |
function defaultSeparation(a, b) { |
| 13823 |
return a.parent === b.parent ? 1 : 2; |
| 13824 |
} |
| 13825 |
|
| 13826 |
// function radialSeparation(a, b) { |
| 13827 |
// return (a.parent === b.parent ? 1 : 2) / a.depth; |
| 13828 |
// } |
| 13829 |
|
| 13830 |
// This function is used to traverse the left contour of a subtree (or |
| 13831 |
// subforest). It returns the successor of v on this contour. This successor is |
| 13832 |
// either given by the leftmost child of v or by the thread of v. The function |
| 13833 |
// returns null if and only if v is on the highest level of its subtree. |
| 13834 |
function nextLeft(v) { |
| 13835 |
var children = v.children; |
| 13836 |
return children ? children[0] : v.t; |
| 13837 |
} |
| 13838 |
|
| 13839 |
// This function works analogously to nextLeft. |
| 13840 |
function nextRight(v) { |
| 13841 |
var children = v.children; |
| 13842 |
return children ? children[children.length - 1] : v.t; |
| 13843 |
} |
| 13844 |
|
| 13845 |
// Shifts the current subtree rooted at w+. This is done by increasing |
| 13846 |
// prelim(w+) and mod(w+) by shift. |
| 13847 |
function moveSubtree(wm, wp, shift) { |
| 13848 |
var change = shift / (wp.i - wm.i); |
| 13849 |
wp.c -= change; |
| 13850 |
wp.s += shift; |
| 13851 |
wm.c += change; |
| 13852 |
wp.z += shift; |
| 13853 |
wp.m += shift; |
| 13854 |
} |
| 13855 |
|
| 13856 |
// All other shifts, applied to the smaller subtrees between w- and w+, are |
| 13857 |
// performed by this function. To prepare the shifts, we have to adjust |
| 13858 |
// change(w+), shift(w+), and change(w-). |
| 13859 |
function executeShifts(v) { |
| 13860 |
var shift = 0, |
| 13861 |
change = 0, |
| 13862 |
children = v.children, |
| 13863 |
i = children.length, |
| 13864 |
w; |
| 13865 |
while (--i >= 0) { |
| 13866 |
w = children[i]; |
| 13867 |
w.z += shift; |
| 13868 |
w.m += shift; |
| 13869 |
shift += w.s + (change += w.c); |
| 13870 |
} |
| 13871 |
} |
| 13872 |
|
| 13873 |
// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise, |
| 13874 |
// returns the specified (default) ancestor. |
| 13875 |
function nextAncestor(vim, v, ancestor) { |
| 13876 |
return vim.a.parent === v.parent ? vim.a : ancestor; |
| 13877 |
} |
| 13878 |
|
| 13879 |
function TreeNode(node, i) { |
| 13880 |
this._ = node; |
| 13881 |
this.parent = null; |
| 13882 |
this.children = null; |
| 13883 |
this.A = null; // default ancestor |
| 13884 |
this.a = this; // ancestor |
| 13885 |
this.z = 0; // prelim |
| 13886 |
this.m = 0; // mod |
| 13887 |
this.c = 0; // change |
| 13888 |
this.s = 0; // shift |
| 13889 |
this.t = null; // thread |
| 13890 |
this.i = i; // number |
| 13891 |
} |
| 13892 |
|
| 13893 |
TreeNode.prototype = Object.create(Node$1.prototype); |
| 13894 |
|
| 13895 |
function treeRoot(root) { |
| 13896 |
var tree = new TreeNode(root, 0), |
| 13897 |
node, |
| 13898 |
nodes = [tree], |
| 13899 |
child, |
| 13900 |
children, |
| 13901 |
i, |
| 13902 |
n; |
| 13903 |
|
| 13904 |
while (node = nodes.pop()) { |
| 13905 |
if (children = node._.children) { |
| 13906 |
node.children = new Array(n = children.length); |
| 13907 |
for (i = n - 1; i >= 0; --i) { |
| 13908 |
nodes.push(child = node.children[i] = new TreeNode(children[i], i)); |
| 13909 |
child.parent = node; |
| 13910 |
} |
| 13911 |
} |
| 13912 |
} |
| 13913 |
|
| 13914 |
(tree.parent = new TreeNode(null, 0)).children = [tree]; |
| 13915 |
return tree; |
| 13916 |
} |
| 13917 |
|
| 13918 |
// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm |
| 13919 |
function tree() { |
| 13920 |
var separation = defaultSeparation, |
| 13921 |
dx = 1, |
| 13922 |
dy = 1, |
| 13923 |
nodeSize = null; |
| 13924 |
|
| 13925 |
function tree(root) { |
| 13926 |
var t = treeRoot(root); |
| 13927 |
|
| 13928 |
// Compute the layout using Buchheim et al.’s algorithm. |
| 13929 |
t.eachAfter(firstWalk), t.parent.m = -t.z; |
| 13930 |
t.eachBefore(secondWalk); |
| 13931 |
|
| 13932 |
// If a fixed node size is specified, scale x and y. |
| 13933 |
if (nodeSize) root.eachBefore(sizeNode); |
| 13934 |
|
| 13935 |
// If a fixed tree size is specified, scale x and y based on the extent. |
| 13936 |
// Compute the left-most, right-most, and depth-most nodes for extents. |
| 13937 |
else { |
| 13938 |
var left = root, |
| 13939 |
right = root, |
| 13940 |
bottom = root; |
| 13941 |
root.eachBefore(function(node) { |
| 13942 |
if (node.x < left.x) left = node; |
| 13943 |
if (node.x > right.x) right = node; |
| 13944 |
if (node.depth > bottom.depth) bottom = node; |
| 13945 |
}); |
| 13946 |
var s = left === right ? 1 : separation(left, right) / 2, |
| 13947 |
tx = s - left.x, |
| 13948 |
kx = dx / (right.x + s + tx), |
| 13949 |
ky = dy / (bottom.depth || 1); |
| 13950 |
root.eachBefore(function(node) { |
| 13951 |
node.x = (node.x + tx) * kx; |
| 13952 |
node.y = node.depth * ky; |
| 13953 |
}); |
| 13954 |
} |
| 13955 |
|
| 13956 |
return root; |
| 13957 |
} |
| 13958 |
|
| 13959 |
// Computes a preliminary x-coordinate for v. Before that, FIRST WALK is |
| 13960 |
// applied recursively to the children of v, as well as the function |
| 13961 |
// APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the |
| 13962 |
// node v is placed to the midpoint of its outermost children. |
| 13963 |
function firstWalk(v) { |
| 13964 |
var children = v.children, |
| 13965 |
siblings = v.parent.children, |
| 13966 |
w = v.i ? siblings[v.i - 1] : null; |
| 13967 |
if (children) { |
| 13968 |
executeShifts(v); |
| 13969 |
var midpoint = (children[0].z + children[children.length - 1].z) / 2; |
| 13970 |
if (w) { |
| 13971 |
v.z = w.z + separation(v._, w._); |
| 13972 |
v.m = v.z - midpoint; |
| 13973 |
} else { |
| 13974 |
v.z = midpoint; |
| 13975 |
} |
| 13976 |
} else if (w) { |
| 13977 |
v.z = w.z + separation(v._, w._); |
| 13978 |
} |
| 13979 |
v.parent.A = apportion(v, w, v.parent.A || siblings[0]); |
| 13980 |
} |
| 13981 |
|
| 13982 |
// Computes all real x-coordinates by summing up the modifiers recursively. |
| 13983 |
function secondWalk(v) { |
| 13984 |
v._.x = v.z + v.parent.m; |
| 13985 |
v.m += v.parent.m; |
| 13986 |
} |
| 13987 |
|
| 13988 |
// The core of the algorithm. Here, a new subtree is combined with the |
| 13989 |
// previous subtrees. Threads are used to traverse the inside and outside |
| 13990 |
// contours of the left and right subtree up to the highest common level. The |
| 13991 |
// vertices used for the traversals are vi+, vi-, vo-, and vo+, where the |
| 13992 |
// superscript o means outside and i means inside, the subscript - means left |
| 13993 |
// subtree and + means right subtree. For summing up the modifiers along the |
| 13994 |
// contour, we use respective variables si+, si-, so-, and so+. Whenever two |
| 13995 |
// nodes of the inside contours conflict, we compute the left one of the |
| 13996 |
// greatest uncommon ancestors using the function ANCESTOR and call MOVE |
| 13997 |
// SUBTREE to shift the subtree and prepare the shifts of smaller subtrees. |
| 13998 |
// Finally, we add a new thread (if necessary). |
| 13999 |
function apportion(v, w, ancestor) { |
| 14000 |
if (w) { |
| 14001 |
var vip = v, |
| 14002 |
vop = v, |
| 14003 |
vim = w, |
| 14004 |
vom = vip.parent.children[0], |
| 14005 |
sip = vip.m, |
| 14006 |
sop = vop.m, |
| 14007 |
sim = vim.m, |
| 14008 |
som = vom.m, |
| 14009 |
shift; |
| 14010 |
while (vim = nextRight(vim), vip = nextLeft(vip), vim && vip) { |
| 14011 |
vom = nextLeft(vom); |
| 14012 |
vop = nextRight(vop); |
| 14013 |
vop.a = v; |
| 14014 |
shift = vim.z + sim - vip.z - sip + separation(vim._, vip._); |
| 14015 |
if (shift > 0) { |
| 14016 |
moveSubtree(nextAncestor(vim, v, ancestor), v, shift); |
| 14017 |
sip += shift; |
| 14018 |
sop += shift; |
| 14019 |
} |
| 14020 |
sim += vim.m; |
| 14021 |
sip += vip.m; |
| 14022 |
som += vom.m; |
| 14023 |
sop += vop.m; |
| 14024 |
} |
| 14025 |
if (vim && !nextRight(vop)) { |
| 14026 |
vop.t = vim; |
| 14027 |
vop.m += sim - sop; |
| 14028 |
} |
| 14029 |
if (vip && !nextLeft(vom)) { |
| 14030 |
vom.t = vip; |
| 14031 |
vom.m += sip - som; |
| 14032 |
ancestor = v; |
| 14033 |
} |
| 14034 |
} |
| 14035 |
return ancestor; |
| 14036 |
} |
| 14037 |
|
| 14038 |
function sizeNode(node) { |
| 14039 |
node.x *= dx; |
| 14040 |
node.y = node.depth * dy; |
| 14041 |
} |
| 14042 |
|
| 14043 |
tree.separation = function(x) { |
| 14044 |
return arguments.length ? (separation = x, tree) : separation; |
| 14045 |
}; |
| 14046 |
|
| 14047 |
tree.size = function(x) { |
| 14048 |
return arguments.length ? (nodeSize = false, dx = +x[0], dy = +x[1], tree) : (nodeSize ? null : [dx, dy]); |
| 14049 |
}; |
| 14050 |
|
| 14051 |
tree.nodeSize = function(x) { |
| 14052 |
return arguments.length ? (nodeSize = true, dx = +x[0], dy = +x[1], tree) : (nodeSize ? [dx, dy] : null); |
| 14053 |
}; |
| 14054 |
|
| 14055 |
return tree; |
| 14056 |
} |
| 14057 |
|
| 14058 |
function treemapSlice(parent, x0, y0, x1, y1) { |
| 14059 |
var nodes = parent.children, |
| 14060 |
node, |
| 14061 |
i = -1, |
| 14062 |
n = nodes.length, |
| 14063 |
k = parent.value && (y1 - y0) / parent.value; |
| 14064 |
|
| 14065 |
while (++i < n) { |
| 14066 |
node = nodes[i], node.x0 = x0, node.x1 = x1; |
| 14067 |
node.y0 = y0, node.y1 = y0 += node.value * k; |
| 14068 |
} |
| 14069 |
} |
| 14070 |
|
| 14071 |
var phi = (1 + Math.sqrt(5)) / 2; |
| 14072 |
|
| 14073 |
function squarifyRatio(ratio, parent, x0, y0, x1, y1) { |
| 14074 |
var rows = [], |
| 14075 |
nodes = parent.children, |
| 14076 |
row, |
| 14077 |
nodeValue, |
| 14078 |
i0 = 0, |
| 14079 |
i1 = 0, |
| 14080 |
n = nodes.length, |
| 14081 |
dx, dy, |
| 14082 |
value = parent.value, |
| 14083 |
sumValue, |
| 14084 |
minValue, |
| 14085 |
maxValue, |
| 14086 |
newRatio, |
| 14087 |
minRatio, |
| 14088 |
alpha, |
| 14089 |
beta; |
| 14090 |
|
| 14091 |
while (i0 < n) { |
| 14092 |
dx = x1 - x0, dy = y1 - y0; |
| 14093 |
|
| 14094 |
// Find the next non-empty node. |
| 14095 |
do sumValue = nodes[i1++].value; while (!sumValue && i1 < n); |
| 14096 |
minValue = maxValue = sumValue; |
| 14097 |
alpha = Math.max(dy / dx, dx / dy) / (value * ratio); |
| 14098 |
beta = sumValue * sumValue * alpha; |
| 14099 |
minRatio = Math.max(maxValue / beta, beta / minValue); |
| 14100 |
|
| 14101 |
// Keep adding nodes while the aspect ratio maintains or improves. |
| 14102 |
for (; i1 < n; ++i1) { |
| 14103 |
sumValue += nodeValue = nodes[i1].value; |
| 14104 |
if (nodeValue < minValue) minValue = nodeValue; |
| 14105 |
if (nodeValue > maxValue) maxValue = nodeValue; |
| 14106 |
beta = sumValue * sumValue * alpha; |
| 14107 |
newRatio = Math.max(maxValue / beta, beta / minValue); |
| 14108 |
if (newRatio > minRatio) { sumValue -= nodeValue; break; } |
| 14109 |
minRatio = newRatio; |
| 14110 |
} |
| 14111 |
|
| 14112 |
// Position and record the row orientation. |
| 14113 |
rows.push(row = {value: sumValue, dice: dx < dy, children: nodes.slice(i0, i1)}); |
| 14114 |
if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1); |
| 14115 |
else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1); |
| 14116 |
value -= sumValue, i0 = i1; |
| 14117 |
} |
| 14118 |
|
| 14119 |
return rows; |
| 14120 |
} |
| 14121 |
|
| 14122 |
var squarify = (function custom(ratio) { |
| 14123 |
|
| 14124 |
function squarify(parent, x0, y0, x1, y1) { |
| 14125 |
squarifyRatio(ratio, parent, x0, y0, x1, y1); |
| 14126 |
} |
| 14127 |
|
| 14128 |
squarify.ratio = function(x) { |
| 14129 |
return custom((x = +x) > 1 ? x : 1); |
| 14130 |
}; |
| 14131 |
|
| 14132 |
return squarify; |
| 14133 |
})(phi); |
| 14134 |
|
| 14135 |
function index() { |
| 14136 |
var tile = squarify, |
| 14137 |
round = false, |
| 14138 |
dx = 1, |
| 14139 |
dy = 1, |
| 14140 |
paddingStack = [0], |
| 14141 |
paddingInner = constantZero, |
| 14142 |
paddingTop = constantZero, |
| 14143 |
paddingRight = constantZero, |
| 14144 |
paddingBottom = constantZero, |
| 14145 |
paddingLeft = constantZero; |
| 14146 |
|
| 14147 |
function treemap(root) { |
| 14148 |
root.x0 = |
| 14149 |
root.y0 = 0; |
| 14150 |
root.x1 = dx; |
| 14151 |
root.y1 = dy; |
| 14152 |
root.eachBefore(positionNode); |
| 14153 |
paddingStack = [0]; |
| 14154 |
if (round) root.eachBefore(roundNode); |
| 14155 |
return root; |
| 14156 |
} |
| 14157 |
|
| 14158 |
function positionNode(node) { |
| 14159 |
var p = paddingStack[node.depth], |
| 14160 |
x0 = node.x0 + p, |
| 14161 |
y0 = node.y0 + p, |
| 14162 |
x1 = node.x1 - p, |
| 14163 |
y1 = node.y1 - p; |
| 14164 |
if (x1 < x0) x0 = x1 = (x0 + x1) / 2; |
| 14165 |
if (y1 < y0) y0 = y1 = (y0 + y1) / 2; |
| 14166 |
node.x0 = x0; |
| 14167 |
node.y0 = y0; |
| 14168 |
node.x1 = x1; |
| 14169 |
node.y1 = y1; |
| 14170 |
if (node.children) { |
| 14171 |
p = paddingStack[node.depth + 1] = paddingInner(node) / 2; |
| 14172 |
x0 += paddingLeft(node) - p; |
| 14173 |
y0 += paddingTop(node) - p; |
| 14174 |
x1 -= paddingRight(node) - p; |
| 14175 |
y1 -= paddingBottom(node) - p; |
| 14176 |
if (x1 < x0) x0 = x1 = (x0 + x1) / 2; |
| 14177 |
if (y1 < y0) y0 = y1 = (y0 + y1) / 2; |
| 14178 |
tile(node, x0, y0, x1, y1); |
| 14179 |
} |
| 14180 |
} |
| 14181 |
|
| 14182 |
treemap.round = function(x) { |
| 14183 |
return arguments.length ? (round = !!x, treemap) : round; |
| 14184 |
}; |
| 14185 |
|
| 14186 |
treemap.size = function(x) { |
| 14187 |
return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy]; |
| 14188 |
}; |
| 14189 |
|
| 14190 |
treemap.tile = function(x) { |
| 14191 |
return arguments.length ? (tile = required(x), treemap) : tile; |
| 14192 |
}; |
| 14193 |
|
| 14194 |
treemap.padding = function(x) { |
| 14195 |
return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner(); |
| 14196 |
}; |
| 14197 |
|
| 14198 |
treemap.paddingInner = function(x) { |
| 14199 |
return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$2(+x), treemap) : paddingInner; |
| 14200 |
}; |
| 14201 |
|
| 14202 |
treemap.paddingOuter = function(x) { |
| 14203 |
return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop(); |
| 14204 |
}; |
| 14205 |
|
| 14206 |
treemap.paddingTop = function(x) { |
| 14207 |
return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$2(+x), treemap) : paddingTop; |
| 14208 |
}; |
| 14209 |
|
| 14210 |
treemap.paddingRight = function(x) { |
| 14211 |
return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$2(+x), treemap) : paddingRight; |
| 14212 |
}; |
| 14213 |
|
| 14214 |
treemap.paddingBottom = function(x) { |
| 14215 |
return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$2(+x), treemap) : paddingBottom; |
| 14216 |
}; |
| 14217 |
|
| 14218 |
treemap.paddingLeft = function(x) { |
| 14219 |
return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$2(+x), treemap) : paddingLeft; |
| 14220 |
}; |
| 14221 |
|
| 14222 |
return treemap; |
| 14223 |
} |
| 14224 |
|
| 14225 |
function binary(parent, x0, y0, x1, y1) { |
| 14226 |
var nodes = parent.children, |
| 14227 |
i, n = nodes.length, |
| 14228 |
sum, sums = new Array(n + 1); |
| 14229 |
|
| 14230 |
for (sums[0] = sum = i = 0; i < n; ++i) { |
| 14231 |
sums[i + 1] = sum += nodes[i].value; |
| 14232 |
} |
| 14233 |
|
| 14234 |
partition(0, n, parent.value, x0, y0, x1, y1); |
| 14235 |
|
| 14236 |
function partition(i, j, value, x0, y0, x1, y1) { |
| 14237 |
if (i >= j - 1) { |
| 14238 |
var node = nodes[i]; |
| 14239 |
node.x0 = x0, node.y0 = y0; |
| 14240 |
node.x1 = x1, node.y1 = y1; |
| 14241 |
return; |
| 14242 |
} |
| 14243 |
|
| 14244 |
var valueOffset = sums[i], |
| 14245 |
valueTarget = (value / 2) + valueOffset, |
| 14246 |
k = i + 1, |
| 14247 |
hi = j - 1; |
| 14248 |
|
| 14249 |
while (k < hi) { |
| 14250 |
var mid = k + hi >>> 1; |
| 14251 |
if (sums[mid] < valueTarget) k = mid + 1; |
| 14252 |
else hi = mid; |
| 14253 |
} |
| 14254 |
|
| 14255 |
if ((valueTarget - sums[k - 1]) < (sums[k] - valueTarget) && i + 1 < k) --k; |
| 14256 |
|
| 14257 |
var valueLeft = sums[k] - valueOffset, |
| 14258 |
valueRight = value - valueLeft; |
| 14259 |
|
| 14260 |
if ((x1 - x0) > (y1 - y0)) { |
| 14261 |
var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1; |
| 14262 |
partition(i, k, valueLeft, x0, y0, xk, y1); |
| 14263 |
partition(k, j, valueRight, xk, y0, x1, y1); |
| 14264 |
} else { |
| 14265 |
var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1; |
| 14266 |
partition(i, k, valueLeft, x0, y0, x1, yk); |
| 14267 |
partition(k, j, valueRight, x0, yk, x1, y1); |
| 14268 |
} |
| 14269 |
} |
| 14270 |
} |
| 14271 |
|
| 14272 |
function sliceDice(parent, x0, y0, x1, y1) { |
| 14273 |
(parent.depth & 1 ? treemapSlice : treemapDice)(parent, x0, y0, x1, y1); |
| 14274 |
} |
| 14275 |
|
| 14276 |
var resquarify = (function custom(ratio) { |
| 14277 |
|
| 14278 |
function resquarify(parent, x0, y0, x1, y1) { |
| 14279 |
if ((rows = parent._squarify) && (rows.ratio === ratio)) { |
| 14280 |
var rows, |
| 14281 |
row, |
| 14282 |
nodes, |
| 14283 |
i, |
| 14284 |
j = -1, |
| 14285 |
n, |
| 14286 |
m = rows.length, |
| 14287 |
value = parent.value; |
| 14288 |
|
| 14289 |
while (++j < m) { |
| 14290 |
row = rows[j], nodes = row.children; |
| 14291 |
for (i = row.value = 0, n = nodes.length; i < n; ++i) row.value += nodes[i].value; |
| 14292 |
if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += (y1 - y0) * row.value / value : y1); |
| 14293 |
else treemapSlice(row, x0, y0, value ? x0 += (x1 - x0) * row.value / value : x1, y1); |
| 14294 |
value -= row.value; |
| 14295 |
} |
| 14296 |
} else { |
| 14297 |
parent._squarify = rows = squarifyRatio(ratio, parent, x0, y0, x1, y1); |
| 14298 |
rows.ratio = ratio; |
| 14299 |
} |
| 14300 |
} |
| 14301 |
|
| 14302 |
resquarify.ratio = function(x) { |
| 14303 |
return custom((x = +x) > 1 ? x : 1); |
| 14304 |
}; |
| 14305 |
|
| 14306 |
return resquarify; |
| 14307 |
})(phi); |
| 14308 |
|
| 14309 |
function area$1(polygon) { |
| 14310 |
var i = -1, |
| 14311 |
n = polygon.length, |
| 14312 |
a, |
| 14313 |
b = polygon[n - 1], |
| 14314 |
area = 0; |
| 14315 |
|
| 14316 |
while (++i < n) { |
| 14317 |
a = b; |
| 14318 |
b = polygon[i]; |
| 14319 |
area += a[1] * b[0] - a[0] * b[1]; |
| 14320 |
} |
| 14321 |
|
| 14322 |
return area / 2; |
| 14323 |
} |
| 14324 |
|
| 14325 |
function centroid(polygon) { |
| 14326 |
var i = -1, |
| 14327 |
n = polygon.length, |
| 14328 |
x = 0, |
| 14329 |
y = 0, |
| 14330 |
a, |
| 14331 |
b = polygon[n - 1], |
| 14332 |
c, |
| 14333 |
k = 0; |
| 14334 |
|
| 14335 |
while (++i < n) { |
| 14336 |
a = b; |
| 14337 |
b = polygon[i]; |
| 14338 |
k += c = a[0] * b[1] - b[0] * a[1]; |
| 14339 |
x += (a[0] + b[0]) * c; |
| 14340 |
y += (a[1] + b[1]) * c; |
| 14341 |
} |
| 14342 |
|
| 14343 |
return k *= 3, [x / k, y / k]; |
| 14344 |
} |
| 14345 |
|
| 14346 |
// Returns the 2D cross product of AB and AC vectors, i.e., the z-component of |
| 14347 |
// the 3D cross product in a quadrant I Cartesian coordinate system (+x is |
| 14348 |
// right, +y is up). Returns a positive value if ABC is counter-clockwise, |
| 14349 |
// negative if clockwise, and zero if the points are collinear. |
| 14350 |
function cross$1(a, b, c) { |
| 14351 |
return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]); |
| 14352 |
} |
| 14353 |
|
| 14354 |
function lexicographicOrder(a, b) { |
| 14355 |
return a[0] - b[0] || a[1] - b[1]; |
| 14356 |
} |
| 14357 |
|
| 14358 |
// Computes the upper convex hull per the monotone chain algorithm. |
| 14359 |
// Assumes points.length >= 3, is sorted by x, unique in y. |
| 14360 |
// Returns an array of indices into points in left-to-right order. |
| 14361 |
function computeUpperHullIndexes(points) { |
| 14362 |
const n = points.length, |
| 14363 |
indexes = [0, 1]; |
| 14364 |
let size = 2, i; |
| 14365 |
|
| 14366 |
for (i = 2; i < n; ++i) { |
| 14367 |
while (size > 1 && cross$1(points[indexes[size - 2]], points[indexes[size - 1]], points[i]) <= 0) --size; |
| 14368 |
indexes[size++] = i; |
| 14369 |
} |
| 14370 |
|
| 14371 |
return indexes.slice(0, size); // remove popped points |
| 14372 |
} |
| 14373 |
|
| 14374 |
function hull(points) { |
| 14375 |
if ((n = points.length) < 3) return null; |
| 14376 |
|
| 14377 |
var i, |
| 14378 |
n, |
| 14379 |
sortedPoints = new Array(n), |
| 14380 |
flippedPoints = new Array(n); |
| 14381 |
|
| 14382 |
for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i]; |
| 14383 |
sortedPoints.sort(lexicographicOrder); |
| 14384 |
for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]]; |
| 14385 |
|
| 14386 |
var upperIndexes = computeUpperHullIndexes(sortedPoints), |
| 14387 |
lowerIndexes = computeUpperHullIndexes(flippedPoints); |
| 14388 |
|
| 14389 |
// Construct the hull polygon, removing possible duplicate endpoints. |
| 14390 |
var skipLeft = lowerIndexes[0] === upperIndexes[0], |
| 14391 |
skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1], |
| 14392 |
hull = []; |
| 14393 |
|
| 14394 |
// Add upper hull in right-to-l order. |
| 14395 |
// Then add lower hull in left-to-right order. |
| 14396 |
for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]); |
| 14397 |
for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]); |
| 14398 |
|
| 14399 |
return hull; |
| 14400 |
} |
| 14401 |
|
| 14402 |
function contains(polygon, point) { |
| 14403 |
var n = polygon.length, |
| 14404 |
p = polygon[n - 1], |
| 14405 |
x = point[0], y = point[1], |
| 14406 |
x0 = p[0], y0 = p[1], |
| 14407 |
x1, y1, |
| 14408 |
inside = false; |
| 14409 |
|
| 14410 |
for (var i = 0; i < n; ++i) { |
| 14411 |
p = polygon[i], x1 = p[0], y1 = p[1]; |
| 14412 |
if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside; |
| 14413 |
x0 = x1, y0 = y1; |
| 14414 |
} |
| 14415 |
|
| 14416 |
return inside; |
| 14417 |
} |
| 14418 |
|
| 14419 |
function length(polygon) { |
| 14420 |
var i = -1, |
| 14421 |
n = polygon.length, |
| 14422 |
b = polygon[n - 1], |
| 14423 |
xa, |
| 14424 |
ya, |
| 14425 |
xb = b[0], |
| 14426 |
yb = b[1], |
| 14427 |
perimeter = 0; |
| 14428 |
|
| 14429 |
while (++i < n) { |
| 14430 |
xa = xb; |
| 14431 |
ya = yb; |
| 14432 |
b = polygon[i]; |
| 14433 |
xb = b[0]; |
| 14434 |
yb = b[1]; |
| 14435 |
xa -= xb; |
| 14436 |
ya -= yb; |
| 14437 |
perimeter += Math.hypot(xa, ya); |
| 14438 |
} |
| 14439 |
|
| 14440 |
return perimeter; |
| 14441 |
} |
| 14442 |
|
| 14443 |
var defaultSource = Math.random; |
| 14444 |
|
| 14445 |
var uniform = (function sourceRandomUniform(source) { |
| 14446 |
function randomUniform(min, max) { |
| 14447 |
min = min == null ? 0 : +min; |
| 14448 |
max = max == null ? 1 : +max; |
| 14449 |
if (arguments.length === 1) max = min, min = 0; |
| 14450 |
else max -= min; |
| 14451 |
return function() { |
| 14452 |
return source() * max + min; |
| 14453 |
}; |
| 14454 |
} |
| 14455 |
|
| 14456 |
randomUniform.source = sourceRandomUniform; |
| 14457 |
|
| 14458 |
return randomUniform; |
| 14459 |
})(defaultSource); |
| 14460 |
|
| 14461 |
var int = (function sourceRandomInt(source) { |
| 14462 |
function randomInt(min, max) { |
| 14463 |
if (arguments.length < 2) max = min, min = 0; |
| 14464 |
min = Math.floor(min); |
| 14465 |
max = Math.floor(max) - min; |
| 14466 |
return function() { |
| 14467 |
return Math.floor(source() * max + min); |
| 14468 |
}; |
| 14469 |
} |
| 14470 |
|
| 14471 |
randomInt.source = sourceRandomInt; |
| 14472 |
|
| 14473 |
return randomInt; |
| 14474 |
})(defaultSource); |
| 14475 |
|
| 14476 |
var normal = (function sourceRandomNormal(source) { |
| 14477 |
function randomNormal(mu, sigma) { |
| 14478 |
var x, r; |
| 14479 |
mu = mu == null ? 0 : +mu; |
| 14480 |
sigma = sigma == null ? 1 : +sigma; |
| 14481 |
return function() { |
| 14482 |
var y; |
| 14483 |
|
| 14484 |
// If available, use the second previously-generated uniform random. |
| 14485 |
if (x != null) y = x, x = null; |
| 14486 |
|
| 14487 |
// Otherwise, generate a new x and y. |
| 14488 |
else do { |
| 14489 |
x = source() * 2 - 1; |
| 14490 |
y = source() * 2 - 1; |
| 14491 |
r = x * x + y * y; |
| 14492 |
} while (!r || r > 1); |
| 14493 |
|
| 14494 |
return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r); |
| 14495 |
}; |
| 14496 |
} |
| 14497 |
|
| 14498 |
randomNormal.source = sourceRandomNormal; |
| 14499 |
|
| 14500 |
return randomNormal; |
| 14501 |
})(defaultSource); |
| 14502 |
|
| 14503 |
var logNormal = (function sourceRandomLogNormal(source) { |
| 14504 |
var N = normal.source(source); |
| 14505 |
|
| 14506 |
function randomLogNormal() { |
| 14507 |
var randomNormal = N.apply(this, arguments); |
| 14508 |
return function() { |
| 14509 |
return Math.exp(randomNormal()); |
| 14510 |
}; |
| 14511 |
} |
| 14512 |
|
| 14513 |
randomLogNormal.source = sourceRandomLogNormal; |
| 14514 |
|
| 14515 |
return randomLogNormal; |
| 14516 |
})(defaultSource); |
| 14517 |
|
| 14518 |
var irwinHall = (function sourceRandomIrwinHall(source) { |
| 14519 |
function randomIrwinHall(n) { |
| 14520 |
if ((n = +n) <= 0) return () => 0; |
| 14521 |
return function() { |
| 14522 |
for (var sum = 0, i = n; i > 1; --i) sum += source(); |
| 14523 |
return sum + i * source(); |
| 14524 |
}; |
| 14525 |
} |
| 14526 |
|
| 14527 |
randomIrwinHall.source = sourceRandomIrwinHall; |
| 14528 |
|
| 14529 |
return randomIrwinHall; |
| 14530 |
})(defaultSource); |
| 14531 |
|
| 14532 |
var bates = (function sourceRandomBates(source) { |
| 14533 |
var I = irwinHall.source(source); |
| 14534 |
|
| 14535 |
function randomBates(n) { |
| 14536 |
// use limiting distribution at n === 0 |
| 14537 |
if ((n = +n) === 0) return source; |
| 14538 |
var randomIrwinHall = I(n); |
| 14539 |
return function() { |
| 14540 |
return randomIrwinHall() / n; |
| 14541 |
}; |
| 14542 |
} |
| 14543 |
|
| 14544 |
randomBates.source = sourceRandomBates; |
| 14545 |
|
| 14546 |
return randomBates; |
| 14547 |
})(defaultSource); |
| 14548 |
|
| 14549 |
var exponential = (function sourceRandomExponential(source) { |
| 14550 |
function randomExponential(lambda) { |
| 14551 |
return function() { |
| 14552 |
return -Math.log1p(-source()) / lambda; |
| 14553 |
}; |
| 14554 |
} |
| 14555 |
|
| 14556 |
randomExponential.source = sourceRandomExponential; |
| 14557 |
|
| 14558 |
return randomExponential; |
| 14559 |
})(defaultSource); |
| 14560 |
|
| 14561 |
var pareto = (function sourceRandomPareto(source) { |
| 14562 |
function randomPareto(alpha) { |
| 14563 |
if ((alpha = +alpha) < 0) throw new RangeError("invalid alpha"); |
| 14564 |
alpha = 1 / -alpha; |
| 14565 |
return function() { |
| 14566 |
return Math.pow(1 - source(), alpha); |
| 14567 |
}; |
| 14568 |
} |
| 14569 |
|
| 14570 |
randomPareto.source = sourceRandomPareto; |
| 14571 |
|
| 14572 |
return randomPareto; |
| 14573 |
})(defaultSource); |
| 14574 |
|
| 14575 |
var bernoulli = (function sourceRandomBernoulli(source) { |
| 14576 |
function randomBernoulli(p) { |
| 14577 |
if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p"); |
| 14578 |
return function() { |
| 14579 |
return Math.floor(source() + p); |
| 14580 |
}; |
| 14581 |
} |
| 14582 |
|
| 14583 |
randomBernoulli.source = sourceRandomBernoulli; |
| 14584 |
|
| 14585 |
return randomBernoulli; |
| 14586 |
})(defaultSource); |
| 14587 |
|
| 14588 |
var geometric = (function sourceRandomGeometric(source) { |
| 14589 |
function randomGeometric(p) { |
| 14590 |
if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p"); |
| 14591 |
if (p === 0) return () => Infinity; |
| 14592 |
if (p === 1) return () => 1; |
| 14593 |
p = Math.log1p(-p); |
| 14594 |
return function() { |
| 14595 |
return 1 + Math.floor(Math.log1p(-source()) / p); |
| 14596 |
}; |
| 14597 |
} |
| 14598 |
|
| 14599 |
randomGeometric.source = sourceRandomGeometric; |
| 14600 |
|
| 14601 |
return randomGeometric; |
| 14602 |
})(defaultSource); |
| 14603 |
|
| 14604 |
var gamma = (function sourceRandomGamma(source) { |
| 14605 |
var randomNormal = normal.source(source)(); |
| 14606 |
|
| 14607 |
function randomGamma(k, theta) { |
| 14608 |
if ((k = +k) < 0) throw new RangeError("invalid k"); |
| 14609 |
// degenerate distribution if k === 0 |
| 14610 |
if (k === 0) return () => 0; |
| 14611 |
theta = theta == null ? 1 : +theta; |
| 14612 |
// exponential distribution if k === 1 |
| 14613 |
if (k === 1) return () => -Math.log1p(-source()) * theta; |
| 14614 |
|
| 14615 |
var d = (k < 1 ? k + 1 : k) - 1 / 3, |
| 14616 |
c = 1 / (3 * Math.sqrt(d)), |
| 14617 |
multiplier = k < 1 ? () => Math.pow(source(), 1 / k) : () => 1; |
| 14618 |
return function() { |
| 14619 |
do { |
| 14620 |
do { |
| 14621 |
var x = randomNormal(), |
| 14622 |
v = 1 + c * x; |
| 14623 |
} while (v <= 0); |
| 14624 |
v *= v * v; |
| 14625 |
var u = 1 - source(); |
| 14626 |
} while (u >= 1 - 0.0331 * x * x * x * x && Math.log(u) >= 0.5 * x * x + d * (1 - v + Math.log(v))); |
| 14627 |
return d * v * multiplier() * theta; |
| 14628 |
}; |
| 14629 |
} |
| 14630 |
|
| 14631 |
randomGamma.source = sourceRandomGamma; |
| 14632 |
|
| 14633 |
return randomGamma; |
| 14634 |
})(defaultSource); |
| 14635 |
|
| 14636 |
var beta = (function sourceRandomBeta(source) { |
| 14637 |
var G = gamma.source(source); |
| 14638 |
|
| 14639 |
function randomBeta(alpha, beta) { |
| 14640 |
var X = G(alpha), |
| 14641 |
Y = G(beta); |
| 14642 |
return function() { |
| 14643 |
var x = X(); |
| 14644 |
return x === 0 ? 0 : x / (x + Y()); |
| 14645 |
}; |
| 14646 |
} |
| 14647 |
|
| 14648 |
randomBeta.source = sourceRandomBeta; |
| 14649 |
|
| 14650 |
return randomBeta; |
| 14651 |
})(defaultSource); |
| 14652 |
|
| 14653 |
var binomial = (function sourceRandomBinomial(source) { |
| 14654 |
var G = geometric.source(source), |
| 14655 |
B = beta.source(source); |
| 14656 |
|
| 14657 |
function randomBinomial(n, p) { |
| 14658 |
n = +n; |
| 14659 |
if ((p = +p) >= 1) return () => n; |
| 14660 |
if (p <= 0) return () => 0; |
| 14661 |
return function() { |
| 14662 |
var acc = 0, nn = n, pp = p; |
| 14663 |
while (nn * pp > 16 && nn * (1 - pp) > 16) { |
| 14664 |
var i = Math.floor((nn + 1) * pp), |
| 14665 |
y = B(i, nn - i + 1)(); |
| 14666 |
if (y <= pp) { |
| 14667 |
acc += i; |
| 14668 |
nn -= i; |
| 14669 |
pp = (pp - y) / (1 - y); |
| 14670 |
} else { |
| 14671 |
nn = i - 1; |
| 14672 |
pp /= y; |
| 14673 |
} |
| 14674 |
} |
| 14675 |
var sign = pp < 0.5, |
| 14676 |
pFinal = sign ? pp : 1 - pp, |
| 14677 |
g = G(pFinal); |
| 14678 |
for (var s = g(), k = 0; s <= nn; ++k) s += g(); |
| 14679 |
return acc + (sign ? k : nn - k); |
| 14680 |
}; |
| 14681 |
} |
| 14682 |
|
| 14683 |
randomBinomial.source = sourceRandomBinomial; |
| 14684 |
|
| 14685 |
return randomBinomial; |
| 14686 |
})(defaultSource); |
| 14687 |
|
| 14688 |
var weibull = (function sourceRandomWeibull(source) { |
| 14689 |
function randomWeibull(k, a, b) { |
| 14690 |
var outerFunc; |
| 14691 |
if ((k = +k) === 0) { |
| 14692 |
outerFunc = x => -Math.log(x); |
| 14693 |
} else { |
| 14694 |
k = 1 / k; |
| 14695 |
outerFunc = x => Math.pow(x, k); |
| 14696 |
} |
| 14697 |
a = a == null ? 0 : +a; |
| 14698 |
b = b == null ? 1 : +b; |
| 14699 |
return function() { |
| 14700 |
return a + b * outerFunc(-Math.log1p(-source())); |
| 14701 |
}; |
| 14702 |
} |
| 14703 |
|
| 14704 |
randomWeibull.source = sourceRandomWeibull; |
| 14705 |
|
| 14706 |
return randomWeibull; |
| 14707 |
})(defaultSource); |
| 14708 |
|
| 14709 |
var cauchy = (function sourceRandomCauchy(source) { |
| 14710 |
function randomCauchy(a, b) { |
| 14711 |
a = a == null ? 0 : +a; |
| 14712 |
b = b == null ? 1 : +b; |
| 14713 |
return function() { |
| 14714 |
return a + b * Math.tan(Math.PI * source()); |
| 14715 |
}; |
| 14716 |
} |
| 14717 |
|
| 14718 |
randomCauchy.source = sourceRandomCauchy; |
| 14719 |
|
| 14720 |
return randomCauchy; |
| 14721 |
})(defaultSource); |
| 14722 |
|
| 14723 |
var logistic = (function sourceRandomLogistic(source) { |
| 14724 |
function randomLogistic(a, b) { |
| 14725 |
a = a == null ? 0 : +a; |
| 14726 |
b = b == null ? 1 : +b; |
| 14727 |
return function() { |
| 14728 |
var u = source(); |
| 14729 |
return a + b * Math.log(u / (1 - u)); |
| 14730 |
}; |
| 14731 |
} |
| 14732 |
|
| 14733 |
randomLogistic.source = sourceRandomLogistic; |
| 14734 |
|
| 14735 |
return randomLogistic; |
| 14736 |
})(defaultSource); |
| 14737 |
|
| 14738 |
var poisson = (function sourceRandomPoisson(source) { |
| 14739 |
var G = gamma.source(source), |
| 14740 |
B = binomial.source(source); |
| 14741 |
|
| 14742 |
function randomPoisson(lambda) { |
| 14743 |
return function() { |
| 14744 |
var acc = 0, l = lambda; |
| 14745 |
while (l > 16) { |
| 14746 |
var n = Math.floor(0.875 * l), |
| 14747 |
t = G(n)(); |
| 14748 |
if (t > l) return acc + B(n - 1, l / t)(); |
| 14749 |
acc += n; |
| 14750 |
l -= t; |
| 14751 |
} |
| 14752 |
for (var s = -Math.log1p(-source()), k = 0; s <= l; ++k) s -= Math.log1p(-source()); |
| 14753 |
return acc + k; |
| 14754 |
}; |
| 14755 |
} |
| 14756 |
|
| 14757 |
randomPoisson.source = sourceRandomPoisson; |
| 14758 |
|
| 14759 |
return randomPoisson; |
| 14760 |
})(defaultSource); |
| 14761 |
|
| 14762 |
// https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use |
| 14763 |
const mul = 0x19660D; |
| 14764 |
const inc = 0x3C6EF35F; |
| 14765 |
const eps = 1 / 0x100000000; |
| 14766 |
|
| 14767 |
function lcg(seed = Math.random()) { |
| 14768 |
let state = (0 <= seed && seed < 1 ? seed / eps : Math.abs(seed)) | 0; |
| 14769 |
return () => (state = mul * state + inc | 0, eps * (state >>> 0)); |
| 14770 |
} |
| 14771 |
|
| 14772 |
function initRange(domain, range) { |
| 14773 |
switch (arguments.length) { |
| 14774 |
case 0: break; |
| 14775 |
case 1: this.range(domain); break; |
| 14776 |
default: this.range(range).domain(domain); break; |
| 14777 |
} |
| 14778 |
return this; |
| 14779 |
} |
| 14780 |
|
| 14781 |
function initInterpolator(domain, interpolator) { |
| 14782 |
switch (arguments.length) { |
| 14783 |
case 0: break; |
| 14784 |
case 1: { |
| 14785 |
if (typeof domain === "function") this.interpolator(domain); |
| 14786 |
else this.range(domain); |
| 14787 |
break; |
| 14788 |
} |
| 14789 |
default: { |
| 14790 |
this.domain(domain); |
| 14791 |
if (typeof interpolator === "function") this.interpolator(interpolator); |
| 14792 |
else this.range(interpolator); |
| 14793 |
break; |
| 14794 |
} |
| 14795 |
} |
| 14796 |
return this; |
| 14797 |
} |
| 14798 |
|
| 14799 |
const implicit = Symbol("implicit"); |
| 14800 |
|
| 14801 |
function ordinal() { |
| 14802 |
var index = new InternMap(), |
| 14803 |
domain = [], |
| 14804 |
range = [], |
| 14805 |
unknown = implicit; |
| 14806 |
|
| 14807 |
function scale(d) { |
| 14808 |
let i = index.get(d); |
| 14809 |
if (i === undefined) { |
| 14810 |
if (unknown !== implicit) return unknown; |
| 14811 |
index.set(d, i = domain.push(d) - 1); |
| 14812 |
} |
| 14813 |
return range[i % range.length]; |
| 14814 |
} |
| 14815 |
|
| 14816 |
scale.domain = function(_) { |
| 14817 |
if (!arguments.length) return domain.slice(); |
| 14818 |
domain = [], index = new InternMap(); |
| 14819 |
for (const value of _) { |
| 14820 |
if (index.has(value)) continue; |
| 14821 |
index.set(value, domain.push(value) - 1); |
| 14822 |
} |
| 14823 |
return scale; |
| 14824 |
}; |
| 14825 |
|
| 14826 |
scale.range = function(_) { |
| 14827 |
return arguments.length ? (range = Array.from(_), scale) : range.slice(); |
| 14828 |
}; |
| 14829 |
|
| 14830 |
scale.unknown = function(_) { |
| 14831 |
return arguments.length ? (unknown = _, scale) : unknown; |
| 14832 |
}; |
| 14833 |
|
| 14834 |
scale.copy = function() { |
| 14835 |
return ordinal(domain, range).unknown(unknown); |
| 14836 |
}; |
| 14837 |
|
| 14838 |
initRange.apply(scale, arguments); |
| 14839 |
|
| 14840 |
return scale; |
| 14841 |
} |
| 14842 |
|
| 14843 |
function band() { |
| 14844 |
var scale = ordinal().unknown(undefined), |
| 14845 |
domain = scale.domain, |
| 14846 |
ordinalRange = scale.range, |
| 14847 |
r0 = 0, |
| 14848 |
r1 = 1, |
| 14849 |
step, |
| 14850 |
bandwidth, |
| 14851 |
round = false, |
| 14852 |
paddingInner = 0, |
| 14853 |
paddingOuter = 0, |
| 14854 |
align = 0.5; |
| 14855 |
|
| 14856 |
delete scale.unknown; |
| 14857 |
|
| 14858 |
function rescale() { |
| 14859 |
var n = domain().length, |
| 14860 |
reverse = r1 < r0, |
| 14861 |
start = reverse ? r1 : r0, |
| 14862 |
stop = reverse ? r0 : r1; |
| 14863 |
step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2); |
| 14864 |
if (round) step = Math.floor(step); |
| 14865 |
start += (stop - start - step * (n - paddingInner)) * align; |
| 14866 |
bandwidth = step * (1 - paddingInner); |
| 14867 |
if (round) start = Math.round(start), bandwidth = Math.round(bandwidth); |
| 14868 |
var values = range$2(n).map(function(i) { return start + step * i; }); |
| 14869 |
return ordinalRange(reverse ? values.reverse() : values); |
| 14870 |
} |
| 14871 |
|
| 14872 |
scale.domain = function(_) { |
| 14873 |
return arguments.length ? (domain(_), rescale()) : domain(); |
| 14874 |
}; |
| 14875 |
|
| 14876 |
scale.range = function(_) { |
| 14877 |
return arguments.length ? ([r0, r1] = _, r0 = +r0, r1 = +r1, rescale()) : [r0, r1]; |
| 14878 |
}; |
| 14879 |
|
| 14880 |
scale.rangeRound = function(_) { |
| 14881 |
return [r0, r1] = _, r0 = +r0, r1 = +r1, round = true, rescale(); |
| 14882 |
}; |
| 14883 |
|
| 14884 |
scale.bandwidth = function() { |
| 14885 |
return bandwidth; |
| 14886 |
}; |
| 14887 |
|
| 14888 |
scale.step = function() { |
| 14889 |
return step; |
| 14890 |
}; |
| 14891 |
|
| 14892 |
scale.round = function(_) { |
| 14893 |
return arguments.length ? (round = !!_, rescale()) : round; |
| 14894 |
}; |
| 14895 |
|
| 14896 |
scale.padding = function(_) { |
| 14897 |
return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner; |
| 14898 |
}; |
| 14899 |
|
| 14900 |
scale.paddingInner = function(_) { |
| 14901 |
return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner; |
| 14902 |
}; |
| 14903 |
|
| 14904 |
scale.paddingOuter = function(_) { |
| 14905 |
return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter; |
| 14906 |
}; |
| 14907 |
|
| 14908 |
scale.align = function(_) { |
| 14909 |
return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align; |
| 14910 |
}; |
| 14911 |
|
| 14912 |
scale.copy = function() { |
| 14913 |
return band(domain(), [r0, r1]) |
| 14914 |
.round(round) |
| 14915 |
.paddingInner(paddingInner) |
| 14916 |
.paddingOuter(paddingOuter) |
| 14917 |
.align(align); |
| 14918 |
}; |
| 14919 |
|
| 14920 |
return initRange.apply(rescale(), arguments); |
| 14921 |
} |
| 14922 |
|
| 14923 |
function pointish(scale) { |
| 14924 |
var copy = scale.copy; |
| 14925 |
|
| 14926 |
scale.padding = scale.paddingOuter; |
| 14927 |
delete scale.paddingInner; |
| 14928 |
delete scale.paddingOuter; |
| 14929 |
|
| 14930 |
scale.copy = function() { |
| 14931 |
return pointish(copy()); |
| 14932 |
}; |
| 14933 |
|
| 14934 |
return scale; |
| 14935 |
} |
| 14936 |
|
| 14937 |
function point$4() { |
| 14938 |
return pointish(band.apply(null, arguments).paddingInner(1)); |
| 14939 |
} |
| 14940 |
|
| 14941 |
function constants(x) { |
| 14942 |
return function() { |
| 14943 |
return x; |
| 14944 |
}; |
| 14945 |
} |
| 14946 |
|
| 14947 |
function number$1(x) { |
| 14948 |
return +x; |
| 14949 |
} |
| 14950 |
|
| 14951 |
var unit = [0, 1]; |
| 14952 |
|
| 14953 |
function identity$3(x) { |
| 14954 |
return x; |
| 14955 |
} |
| 14956 |
|
| 14957 |
function normalize(a, b) { |
| 14958 |
return (b -= (a = +a)) |
| 14959 |
? function(x) { return (x - a) / b; } |
| 14960 |
: constants(isNaN(b) ? NaN : 0.5); |
| 14961 |
} |
| 14962 |
|
| 14963 |
function clamper(a, b) { |
| 14964 |
var t; |
| 14965 |
if (a > b) t = a, a = b, b = t; |
| 14966 |
return function(x) { return Math.max(a, Math.min(b, x)); }; |
| 14967 |
} |
| 14968 |
|
| 14969 |
// normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1]. |
| 14970 |
// interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b]. |
| 14971 |
function bimap(domain, range, interpolate) { |
| 14972 |
var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1]; |
| 14973 |
if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0); |
| 14974 |
else d0 = normalize(d0, d1), r0 = interpolate(r0, r1); |
| 14975 |
return function(x) { return r0(d0(x)); }; |
| 14976 |
} |
| 14977 |
|
| 14978 |
function polymap(domain, range, interpolate) { |
| 14979 |
var j = Math.min(domain.length, range.length) - 1, |
| 14980 |
d = new Array(j), |
| 14981 |
r = new Array(j), |
| 14982 |
i = -1; |
| 14983 |
|
| 14984 |
// Reverse descending domains. |
| 14985 |
if (domain[j] < domain[0]) { |
| 14986 |
domain = domain.slice().reverse(); |
| 14987 |
range = range.slice().reverse(); |
| 14988 |
} |
| 14989 |
|
| 14990 |
while (++i < j) { |
| 14991 |
d[i] = normalize(domain[i], domain[i + 1]); |
| 14992 |
r[i] = interpolate(range[i], range[i + 1]); |
| 14993 |
} |
| 14994 |
|
| 14995 |
return function(x) { |
| 14996 |
var i = bisect(domain, x, 1, j) - 1; |
| 14997 |
return r[i](d[i](x)); |
| 14998 |
}; |
| 14999 |
} |
| 15000 |
|
| 15001 |
function copy$1(source, target) { |
| 15002 |
return target |
| 15003 |
.domain(source.domain()) |
| 15004 |
.range(source.range()) |
| 15005 |
.interpolate(source.interpolate()) |
| 15006 |
.clamp(source.clamp()) |
| 15007 |
.unknown(source.unknown()); |
| 15008 |
} |
| 15009 |
|
| 15010 |
function transformer$2() { |
| 15011 |
var domain = unit, |
| 15012 |
range = unit, |
| 15013 |
interpolate = interpolate$2, |
| 15014 |
transform, |
| 15015 |
untransform, |
| 15016 |
unknown, |
| 15017 |
clamp = identity$3, |
| 15018 |
piecewise, |
| 15019 |
output, |
| 15020 |
input; |
| 15021 |
|
| 15022 |
function rescale() { |
| 15023 |
var n = Math.min(domain.length, range.length); |
| 15024 |
if (clamp !== identity$3) clamp = clamper(domain[0], domain[n - 1]); |
| 15025 |
piecewise = n > 2 ? polymap : bimap; |
| 15026 |
output = input = null; |
| 15027 |
return scale; |
| 15028 |
} |
| 15029 |
|
| 15030 |
function scale(x) { |
| 15031 |
return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x))); |
| 15032 |
} |
| 15033 |
|
| 15034 |
scale.invert = function(y) { |
| 15035 |
return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y))); |
| 15036 |
}; |
| 15037 |
|
| 15038 |
scale.domain = function(_) { |
| 15039 |
return arguments.length ? (domain = Array.from(_, number$1), rescale()) : domain.slice(); |
| 15040 |
}; |
| 15041 |
|
| 15042 |
scale.range = function(_) { |
| 15043 |
return arguments.length ? (range = Array.from(_), rescale()) : range.slice(); |
| 15044 |
}; |
| 15045 |
|
| 15046 |
scale.rangeRound = function(_) { |
| 15047 |
return range = Array.from(_), interpolate = interpolateRound, rescale(); |
| 15048 |
}; |
| 15049 |
|
| 15050 |
scale.clamp = function(_) { |
| 15051 |
return arguments.length ? (clamp = _ ? true : identity$3, rescale()) : clamp !== identity$3; |
| 15052 |
}; |
| 15053 |
|
| 15054 |
scale.interpolate = function(_) { |
| 15055 |
return arguments.length ? (interpolate = _, rescale()) : interpolate; |
| 15056 |
}; |
| 15057 |
|
| 15058 |
scale.unknown = function(_) { |
| 15059 |
return arguments.length ? (unknown = _, scale) : unknown; |
| 15060 |
}; |
| 15061 |
|
| 15062 |
return function(t, u) { |
| 15063 |
transform = t, untransform = u; |
| 15064 |
return rescale(); |
| 15065 |
}; |
| 15066 |
} |
| 15067 |
|
| 15068 |
function continuous() { |
| 15069 |
return transformer$2()(identity$3, identity$3); |
| 15070 |
} |
| 15071 |
|
| 15072 |
function tickFormat(start, stop, count, specifier) { |
| 15073 |
var step = tickStep(start, stop, count), |
| 15074 |
precision; |
| 15075 |
specifier = formatSpecifier(specifier == null ? ",f" : specifier); |
| 15076 |
switch (specifier.type) { |
| 15077 |
case "s": { |
| 15078 |
var value = Math.max(Math.abs(start), Math.abs(stop)); |
| 15079 |
if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision; |
| 15080 |
return exports.formatPrefix(specifier, value); |
| 15081 |
} |
| 15082 |
case "": |
| 15083 |
case "e": |
| 15084 |
case "g": |
| 15085 |
case "p": |
| 15086 |
case "r": { |
| 15087 |
if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e"); |
| 15088 |
break; |
| 15089 |
} |
| 15090 |
case "f": |
| 15091 |
case "%": { |
| 15092 |
if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2; |
| 15093 |
break; |
| 15094 |
} |
| 15095 |
} |
| 15096 |
return exports.format(specifier); |
| 15097 |
} |
| 15098 |
|
| 15099 |
function linearish(scale) { |
| 15100 |
var domain = scale.domain; |
| 15101 |
|
| 15102 |
scale.ticks = function(count) { |
| 15103 |
var d = domain(); |
| 15104 |
return ticks(d[0], d[d.length - 1], count == null ? 10 : count); |
| 15105 |
}; |
| 15106 |
|
| 15107 |
scale.tickFormat = function(count, specifier) { |
| 15108 |
var d = domain(); |
| 15109 |
return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier); |
| 15110 |
}; |
| 15111 |
|
| 15112 |
scale.nice = function(count) { |
| 15113 |
if (count == null) count = 10; |
| 15114 |
|
| 15115 |
var d = domain(); |
| 15116 |
var i0 = 0; |
| 15117 |
var i1 = d.length - 1; |
| 15118 |
var start = d[i0]; |
| 15119 |
var stop = d[i1]; |
| 15120 |
var prestep; |
| 15121 |
var step; |
| 15122 |
var maxIter = 10; |
| 15123 |
|
| 15124 |
if (stop < start) { |
| 15125 |
step = start, start = stop, stop = step; |
| 15126 |
step = i0, i0 = i1, i1 = step; |
| 15127 |
} |
| 15128 |
|
| 15129 |
while (maxIter-- > 0) { |
| 15130 |
step = tickIncrement(start, stop, count); |
| 15131 |
if (step === prestep) { |
| 15132 |
d[i0] = start; |
| 15133 |
d[i1] = stop; |
| 15134 |
return domain(d); |
| 15135 |
} else if (step > 0) { |
| 15136 |
start = Math.floor(start / step) * step; |
| 15137 |
stop = Math.ceil(stop / step) * step; |
| 15138 |
} else if (step < 0) { |
| 15139 |
start = Math.ceil(start * step) / step; |
| 15140 |
stop = Math.floor(stop * step) / step; |
| 15141 |
} else { |
| 15142 |
break; |
| 15143 |
} |
| 15144 |
prestep = step; |
| 15145 |
} |
| 15146 |
|
| 15147 |
return scale; |
| 15148 |
}; |
| 15149 |
|
| 15150 |
return scale; |
| 15151 |
} |
| 15152 |
|
| 15153 |
function linear() { |
| 15154 |
var scale = continuous(); |
| 15155 |
|
| 15156 |
scale.copy = function() { |
| 15157 |
return copy$1(scale, linear()); |
| 15158 |
}; |
| 15159 |
|
| 15160 |
initRange.apply(scale, arguments); |
| 15161 |
|
| 15162 |
return linearish(scale); |
| 15163 |
} |
| 15164 |
|
| 15165 |
function identity$2(domain) { |
| 15166 |
var unknown; |
| 15167 |
|
| 15168 |
function scale(x) { |
| 15169 |
return x == null || isNaN(x = +x) ? unknown : x; |
| 15170 |
} |
| 15171 |
|
| 15172 |
scale.invert = scale; |
| 15173 |
|
| 15174 |
scale.domain = scale.range = function(_) { |
| 15175 |
return arguments.length ? (domain = Array.from(_, number$1), scale) : domain.slice(); |
| 15176 |
}; |
| 15177 |
|
| 15178 |
scale.unknown = function(_) { |
| 15179 |
return arguments.length ? (unknown = _, scale) : unknown; |
| 15180 |
}; |
| 15181 |
|
| 15182 |
scale.copy = function() { |
| 15183 |
return identity$2(domain).unknown(unknown); |
| 15184 |
}; |
| 15185 |
|
| 15186 |
domain = arguments.length ? Array.from(domain, number$1) : [0, 1]; |
| 15187 |
|
| 15188 |
return linearish(scale); |
| 15189 |
} |
| 15190 |
|
| 15191 |
function nice(domain, interval) { |
| 15192 |
domain = domain.slice(); |
| 15193 |
|
| 15194 |
var i0 = 0, |
| 15195 |
i1 = domain.length - 1, |
| 15196 |
x0 = domain[i0], |
| 15197 |
x1 = domain[i1], |
| 15198 |
t; |
| 15199 |
|
| 15200 |
if (x1 < x0) { |
| 15201 |
t = i0, i0 = i1, i1 = t; |
| 15202 |
t = x0, x0 = x1, x1 = t; |
| 15203 |
} |
| 15204 |
|
| 15205 |
domain[i0] = interval.floor(x0); |
| 15206 |
domain[i1] = interval.ceil(x1); |
| 15207 |
return domain; |
| 15208 |
} |
| 15209 |
|
| 15210 |
function transformLog(x) { |
| 15211 |
return Math.log(x); |
| 15212 |
} |
| 15213 |
|
| 15214 |
function transformExp(x) { |
| 15215 |
return Math.exp(x); |
| 15216 |
} |
| 15217 |
|
| 15218 |
function transformLogn(x) { |
| 15219 |
return -Math.log(-x); |
| 15220 |
} |
| 15221 |
|
| 15222 |
function transformExpn(x) { |
| 15223 |
return -Math.exp(-x); |
| 15224 |
} |
| 15225 |
|
| 15226 |
function pow10(x) { |
| 15227 |
return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x; |
| 15228 |
} |
| 15229 |
|
| 15230 |
function powp(base) { |
| 15231 |
return base === 10 ? pow10 |
| 15232 |
: base === Math.E ? Math.exp |
| 15233 |
: x => Math.pow(base, x); |
| 15234 |
} |
| 15235 |
|
| 15236 |
function logp(base) { |
| 15237 |
return base === Math.E ? Math.log |
| 15238 |
: base === 10 && Math.log10 |
| 15239 |
|| base === 2 && Math.log2 |
| 15240 |
|| (base = Math.log(base), x => Math.log(x) / base); |
| 15241 |
} |
| 15242 |
|
| 15243 |
function reflect(f) { |
| 15244 |
return (x, k) => -f(-x, k); |
| 15245 |
} |
| 15246 |
|
| 15247 |
function loggish(transform) { |
| 15248 |
const scale = transform(transformLog, transformExp); |
| 15249 |
const domain = scale.domain; |
| 15250 |
let base = 10; |
| 15251 |
let logs; |
| 15252 |
let pows; |
| 15253 |
|
| 15254 |
function rescale() { |
| 15255 |
logs = logp(base), pows = powp(base); |
| 15256 |
if (domain()[0] < 0) { |
| 15257 |
logs = reflect(logs), pows = reflect(pows); |
| 15258 |
transform(transformLogn, transformExpn); |
| 15259 |
} else { |
| 15260 |
transform(transformLog, transformExp); |
| 15261 |
} |
| 15262 |
return scale; |
| 15263 |
} |
| 15264 |
|
| 15265 |
scale.base = function(_) { |
| 15266 |
return arguments.length ? (base = +_, rescale()) : base; |
| 15267 |
}; |
| 15268 |
|
| 15269 |
scale.domain = function(_) { |
| 15270 |
return arguments.length ? (domain(_), rescale()) : domain(); |
| 15271 |
}; |
| 15272 |
|
| 15273 |
scale.ticks = count => { |
| 15274 |
const d = domain(); |
| 15275 |
let u = d[0]; |
| 15276 |
let v = d[d.length - 1]; |
| 15277 |
const r = v < u; |
| 15278 |
|
| 15279 |
if (r) ([u, v] = [v, u]); |
| 15280 |
|
| 15281 |
let i = logs(u); |
| 15282 |
let j = logs(v); |
| 15283 |
let k; |
| 15284 |
let t; |
| 15285 |
const n = count == null ? 10 : +count; |
| 15286 |
let z = []; |
| 15287 |
|
| 15288 |
if (!(base % 1) && j - i < n) { |
| 15289 |
i = Math.floor(i), j = Math.ceil(j); |
| 15290 |
if (u > 0) for (; i <= j; ++i) { |
| 15291 |
for (k = 1; k < base; ++k) { |
| 15292 |
t = i < 0 ? k / pows(-i) : k * pows(i); |
| 15293 |
if (t < u) continue; |
| 15294 |
if (t > v) break; |
| 15295 |
z.push(t); |
| 15296 |
} |
| 15297 |
} else for (; i <= j; ++i) { |
| 15298 |
for (k = base - 1; k >= 1; --k) { |
| 15299 |
t = i > 0 ? k / pows(-i) : k * pows(i); |
| 15300 |
if (t < u) continue; |
| 15301 |
if (t > v) break; |
| 15302 |
z.push(t); |
| 15303 |
} |
| 15304 |
} |
| 15305 |
if (z.length * 2 < n) z = ticks(u, v, n); |
| 15306 |
} else { |
| 15307 |
z = ticks(i, j, Math.min(j - i, n)).map(pows); |
| 15308 |
} |
| 15309 |
return r ? z.reverse() : z; |
| 15310 |
}; |
| 15311 |
|
| 15312 |
scale.tickFormat = (count, specifier) => { |
| 15313 |
if (count == null) count = 10; |
| 15314 |
if (specifier == null) specifier = base === 10 ? "s" : ","; |
| 15315 |
if (typeof specifier !== "function") { |
| 15316 |
if (!(base % 1) && (specifier = formatSpecifier(specifier)).precision == null) specifier.trim = true; |
| 15317 |
specifier = exports.format(specifier); |
| 15318 |
} |
| 15319 |
if (count === Infinity) return specifier; |
| 15320 |
const k = Math.max(1, base * count / scale.ticks().length); // TODO fast estimate? |
| 15321 |
return d => { |
| 15322 |
let i = d / pows(Math.round(logs(d))); |
| 15323 |
if (i * base < base - 0.5) i *= base; |
| 15324 |
return i <= k ? specifier(d) : ""; |
| 15325 |
}; |
| 15326 |
}; |
| 15327 |
|
| 15328 |
scale.nice = () => { |
| 15329 |
return domain(nice(domain(), { |
| 15330 |
floor: x => pows(Math.floor(logs(x))), |
| 15331 |
ceil: x => pows(Math.ceil(logs(x))) |
| 15332 |
})); |
| 15333 |
}; |
| 15334 |
|
| 15335 |
return scale; |
| 15336 |
} |
| 15337 |
|
| 15338 |
function log() { |
| 15339 |
const scale = loggish(transformer$2()).domain([1, 10]); |
| 15340 |
scale.copy = () => copy$1(scale, log()).base(scale.base()); |
| 15341 |
initRange.apply(scale, arguments); |
| 15342 |
return scale; |
| 15343 |
} |
| 15344 |
|
| 15345 |
function transformSymlog(c) { |
| 15346 |
return function(x) { |
| 15347 |
return Math.sign(x) * Math.log1p(Math.abs(x / c)); |
| 15348 |
}; |
| 15349 |
} |
| 15350 |
|
| 15351 |
function transformSymexp(c) { |
| 15352 |
return function(x) { |
| 15353 |
return Math.sign(x) * Math.expm1(Math.abs(x)) * c; |
| 15354 |
}; |
| 15355 |
} |
| 15356 |
|
| 15357 |
function symlogish(transform) { |
| 15358 |
var c = 1, scale = transform(transformSymlog(c), transformSymexp(c)); |
| 15359 |
|
| 15360 |
scale.constant = function(_) { |
| 15361 |
return arguments.length ? transform(transformSymlog(c = +_), transformSymexp(c)) : c; |
| 15362 |
}; |
| 15363 |
|
| 15364 |
return linearish(scale); |
| 15365 |
} |
| 15366 |
|
| 15367 |
function symlog() { |
| 15368 |
var scale = symlogish(transformer$2()); |
| 15369 |
|
| 15370 |
scale.copy = function() { |
| 15371 |
return copy$1(scale, symlog()).constant(scale.constant()); |
| 15372 |
}; |
| 15373 |
|
| 15374 |
return initRange.apply(scale, arguments); |
| 15375 |
} |
| 15376 |
|
| 15377 |
function transformPow(exponent) { |
| 15378 |
return function(x) { |
| 15379 |
return x < 0 ? -Math.pow(-x, exponent) : Math.pow(x, exponent); |
| 15380 |
}; |
| 15381 |
} |
| 15382 |
|
| 15383 |
function transformSqrt(x) { |
| 15384 |
return x < 0 ? -Math.sqrt(-x) : Math.sqrt(x); |
| 15385 |
} |
| 15386 |
|
| 15387 |
function transformSquare(x) { |
| 15388 |
return x < 0 ? -x * x : x * x; |
| 15389 |
} |
| 15390 |
|
| 15391 |
function powish(transform) { |
| 15392 |
var scale = transform(identity$3, identity$3), |
| 15393 |
exponent = 1; |
| 15394 |
|
| 15395 |
function rescale() { |
| 15396 |
return exponent === 1 ? transform(identity$3, identity$3) |
| 15397 |
: exponent === 0.5 ? transform(transformSqrt, transformSquare) |
| 15398 |
: transform(transformPow(exponent), transformPow(1 / exponent)); |
| 15399 |
} |
| 15400 |
|
| 15401 |
scale.exponent = function(_) { |
| 15402 |
return arguments.length ? (exponent = +_, rescale()) : exponent; |
| 15403 |
}; |
| 15404 |
|
| 15405 |
return linearish(scale); |
| 15406 |
} |
| 15407 |
|
| 15408 |
function pow() { |
| 15409 |
var scale = powish(transformer$2()); |
| 15410 |
|
| 15411 |
scale.copy = function() { |
| 15412 |
return copy$1(scale, pow()).exponent(scale.exponent()); |
| 15413 |
}; |
| 15414 |
|
| 15415 |
initRange.apply(scale, arguments); |
| 15416 |
|
| 15417 |
return scale; |
| 15418 |
} |
| 15419 |
|
| 15420 |
function sqrt$1() { |
| 15421 |
return pow.apply(null, arguments).exponent(0.5); |
| 15422 |
} |
| 15423 |
|
| 15424 |
function square$1(x) { |
| 15425 |
return Math.sign(x) * x * x; |
| 15426 |
} |
| 15427 |
|
| 15428 |
function unsquare(x) { |
| 15429 |
return Math.sign(x) * Math.sqrt(Math.abs(x)); |
| 15430 |
} |
| 15431 |
|
| 15432 |
function radial() { |
| 15433 |
var squared = continuous(), |
| 15434 |
range = [0, 1], |
| 15435 |
round = false, |
| 15436 |
unknown; |
| 15437 |
|
| 15438 |
function scale(x) { |
| 15439 |
var y = unsquare(squared(x)); |
| 15440 |
return isNaN(y) ? unknown : round ? Math.round(y) : y; |
| 15441 |
} |
| 15442 |
|
| 15443 |
scale.invert = function(y) { |
| 15444 |
return squared.invert(square$1(y)); |
| 15445 |
}; |
| 15446 |
|
| 15447 |
scale.domain = function(_) { |
| 15448 |
return arguments.length ? (squared.domain(_), scale) : squared.domain(); |
| 15449 |
}; |
| 15450 |
|
| 15451 |
scale.range = function(_) { |
| 15452 |
return arguments.length ? (squared.range((range = Array.from(_, number$1)).map(square$1)), scale) : range.slice(); |
| 15453 |
}; |
| 15454 |
|
| 15455 |
scale.rangeRound = function(_) { |
| 15456 |
return scale.range(_).round(true); |
| 15457 |
}; |
| 15458 |
|
| 15459 |
scale.round = function(_) { |
| 15460 |
return arguments.length ? (round = !!_, scale) : round; |
| 15461 |
}; |
| 15462 |
|
| 15463 |
scale.clamp = function(_) { |
| 15464 |
return arguments.length ? (squared.clamp(_), scale) : squared.clamp(); |
| 15465 |
}; |
| 15466 |
|
| 15467 |
scale.unknown = function(_) { |
| 15468 |
return arguments.length ? (unknown = _, scale) : unknown; |
| 15469 |
}; |
| 15470 |
|
| 15471 |
scale.copy = function() { |
| 15472 |
return radial(squared.domain(), range) |
| 15473 |
.round(round) |
| 15474 |
.clamp(squared.clamp()) |
| 15475 |
.unknown(unknown); |
| 15476 |
}; |
| 15477 |
|
| 15478 |
initRange.apply(scale, arguments); |
| 15479 |
|
| 15480 |
return linearish(scale); |
| 15481 |
} |
| 15482 |
|
| 15483 |
function quantile() { |
| 15484 |
var domain = [], |
| 15485 |
range = [], |
| 15486 |
thresholds = [], |
| 15487 |
unknown; |
| 15488 |
|
| 15489 |
function rescale() { |
| 15490 |
var i = 0, n = Math.max(1, range.length); |
| 15491 |
thresholds = new Array(n - 1); |
| 15492 |
while (++i < n) thresholds[i - 1] = quantileSorted(domain, i / n); |
| 15493 |
return scale; |
| 15494 |
} |
| 15495 |
|
| 15496 |
function scale(x) { |
| 15497 |
return x == null || isNaN(x = +x) ? unknown : range[bisect(thresholds, x)]; |
| 15498 |
} |
| 15499 |
|
| 15500 |
scale.invertExtent = function(y) { |
| 15501 |
var i = range.indexOf(y); |
| 15502 |
return i < 0 ? [NaN, NaN] : [ |
| 15503 |
i > 0 ? thresholds[i - 1] : domain[0], |
| 15504 |
i < thresholds.length ? thresholds[i] : domain[domain.length - 1] |
| 15505 |
]; |
| 15506 |
}; |
| 15507 |
|
| 15508 |
scale.domain = function(_) { |
| 15509 |
if (!arguments.length) return domain.slice(); |
| 15510 |
domain = []; |
| 15511 |
for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d); |
| 15512 |
domain.sort(ascending$3); |
| 15513 |
return rescale(); |
| 15514 |
}; |
| 15515 |
|
| 15516 |
scale.range = function(_) { |
| 15517 |
return arguments.length ? (range = Array.from(_), rescale()) : range.slice(); |
| 15518 |
}; |
| 15519 |
|
| 15520 |
scale.unknown = function(_) { |
| 15521 |
return arguments.length ? (unknown = _, scale) : unknown; |
| 15522 |
}; |
| 15523 |
|
| 15524 |
scale.quantiles = function() { |
| 15525 |
return thresholds.slice(); |
| 15526 |
}; |
| 15527 |
|
| 15528 |
scale.copy = function() { |
| 15529 |
return quantile() |
| 15530 |
.domain(domain) |
| 15531 |
.range(range) |
| 15532 |
.unknown(unknown); |
| 15533 |
}; |
| 15534 |
|
| 15535 |
return initRange.apply(scale, arguments); |
| 15536 |
} |
| 15537 |
|
| 15538 |
function quantize() { |
| 15539 |
var x0 = 0, |
| 15540 |
x1 = 1, |
| 15541 |
n = 1, |
| 15542 |
domain = [0.5], |
| 15543 |
range = [0, 1], |
| 15544 |
unknown; |
| 15545 |
|
| 15546 |
function scale(x) { |
| 15547 |
return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown; |
| 15548 |
} |
| 15549 |
|
| 15550 |
function rescale() { |
| 15551 |
var i = -1; |
| 15552 |
domain = new Array(n); |
| 15553 |
while (++i < n) domain[i] = ((i + 1) * x1 - (i - n) * x0) / (n + 1); |
| 15554 |
return scale; |
| 15555 |
} |
| 15556 |
|
| 15557 |
scale.domain = function(_) { |
| 15558 |
return arguments.length ? ([x0, x1] = _, x0 = +x0, x1 = +x1, rescale()) : [x0, x1]; |
| 15559 |
}; |
| 15560 |
|
| 15561 |
scale.range = function(_) { |
| 15562 |
return arguments.length ? (n = (range = Array.from(_)).length - 1, rescale()) : range.slice(); |
| 15563 |
}; |
| 15564 |
|
| 15565 |
scale.invertExtent = function(y) { |
| 15566 |
var i = range.indexOf(y); |
| 15567 |
return i < 0 ? [NaN, NaN] |
| 15568 |
: i < 1 ? [x0, domain[0]] |
| 15569 |
: i >= n ? [domain[n - 1], x1] |
| 15570 |
: [domain[i - 1], domain[i]]; |
| 15571 |
}; |
| 15572 |
|
| 15573 |
scale.unknown = function(_) { |
| 15574 |
return arguments.length ? (unknown = _, scale) : scale; |
| 15575 |
}; |
| 15576 |
|
| 15577 |
scale.thresholds = function() { |
| 15578 |
return domain.slice(); |
| 15579 |
}; |
| 15580 |
|
| 15581 |
scale.copy = function() { |
| 15582 |
return quantize() |
| 15583 |
.domain([x0, x1]) |
| 15584 |
.range(range) |
| 15585 |
.unknown(unknown); |
| 15586 |
}; |
| 15587 |
|
| 15588 |
return initRange.apply(linearish(scale), arguments); |
| 15589 |
} |
| 15590 |
|
| 15591 |
function threshold() { |
| 15592 |
var domain = [0.5], |
| 15593 |
range = [0, 1], |
| 15594 |
unknown, |
| 15595 |
n = 1; |
| 15596 |
|
| 15597 |
function scale(x) { |
| 15598 |
return x != null && x <= x ? range[bisect(domain, x, 0, n)] : unknown; |
| 15599 |
} |
| 15600 |
|
| 15601 |
scale.domain = function(_) { |
| 15602 |
return arguments.length ? (domain = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : domain.slice(); |
| 15603 |
}; |
| 15604 |
|
| 15605 |
scale.range = function(_) { |
| 15606 |
return arguments.length ? (range = Array.from(_), n = Math.min(domain.length, range.length - 1), scale) : range.slice(); |
| 15607 |
}; |
| 15608 |
|
| 15609 |
scale.invertExtent = function(y) { |
| 15610 |
var i = range.indexOf(y); |
| 15611 |
return [domain[i - 1], domain[i]]; |
| 15612 |
}; |
| 15613 |
|
| 15614 |
scale.unknown = function(_) { |
| 15615 |
return arguments.length ? (unknown = _, scale) : unknown; |
| 15616 |
}; |
| 15617 |
|
| 15618 |
scale.copy = function() { |
| 15619 |
return threshold() |
| 15620 |
.domain(domain) |
| 15621 |
.range(range) |
| 15622 |
.unknown(unknown); |
| 15623 |
}; |
| 15624 |
|
| 15625 |
return initRange.apply(scale, arguments); |
| 15626 |
} |
| 15627 |
|
| 15628 |
const t0 = new Date, t1 = new Date; |
| 15629 |
|
| 15630 |
function timeInterval(floori, offseti, count, field) { |
| 15631 |
|
| 15632 |
function interval(date) { |
| 15633 |
return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date; |
| 15634 |
} |
| 15635 |
|
| 15636 |
interval.floor = (date) => { |
| 15637 |
return floori(date = new Date(+date)), date; |
| 15638 |
}; |
| 15639 |
|
| 15640 |
interval.ceil = (date) => { |
| 15641 |
return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date; |
| 15642 |
}; |
| 15643 |
|
| 15644 |
interval.round = (date) => { |
| 15645 |
const d0 = interval(date), d1 = interval.ceil(date); |
| 15646 |
return date - d0 < d1 - date ? d0 : d1; |
| 15647 |
}; |
| 15648 |
|
| 15649 |
interval.offset = (date, step) => { |
| 15650 |
return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date; |
| 15651 |
}; |
| 15652 |
|
| 15653 |
interval.range = (start, stop, step) => { |
| 15654 |
const range = []; |
| 15655 |
start = interval.ceil(start); |
| 15656 |
step = step == null ? 1 : Math.floor(step); |
| 15657 |
if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date |
| 15658 |
let previous; |
| 15659 |
do range.push(previous = new Date(+start)), offseti(start, step), floori(start); |
| 15660 |
while (previous < start && start < stop); |
| 15661 |
return range; |
| 15662 |
}; |
| 15663 |
|
| 15664 |
interval.filter = (test) => { |
| 15665 |
return timeInterval((date) => { |
| 15666 |
if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1); |
| 15667 |
}, (date, step) => { |
| 15668 |
if (date >= date) { |
| 15669 |
if (step < 0) while (++step <= 0) { |
| 15670 |
while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty |
| 15671 |
} else while (--step >= 0) { |
| 15672 |
while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty |
| 15673 |
} |
| 15674 |
} |
| 15675 |
}); |
| 15676 |
}; |
| 15677 |
|
| 15678 |
if (count) { |
| 15679 |
interval.count = (start, end) => { |
| 15680 |
t0.setTime(+start), t1.setTime(+end); |
| 15681 |
floori(t0), floori(t1); |
| 15682 |
return Math.floor(count(t0, t1)); |
| 15683 |
}; |
| 15684 |
|
| 15685 |
interval.every = (step) => { |
| 15686 |
step = Math.floor(step); |
| 15687 |
return !isFinite(step) || !(step > 0) ? null |
| 15688 |
: !(step > 1) ? interval |
| 15689 |
: interval.filter(field |
| 15690 |
? (d) => field(d) % step === 0 |
| 15691 |
: (d) => interval.count(0, d) % step === 0); |
| 15692 |
}; |
| 15693 |
} |
| 15694 |
|
| 15695 |
return interval; |
| 15696 |
} |
| 15697 |
|
| 15698 |
const millisecond = timeInterval(() => { |
| 15699 |
// noop |
| 15700 |
}, (date, step) => { |
| 15701 |
date.setTime(+date + step); |
| 15702 |
}, (start, end) => { |
| 15703 |
return end - start; |
| 15704 |
}); |
| 15705 |
|
| 15706 |
// An optimized implementation for this simple case. |
| 15707 |
millisecond.every = (k) => { |
| 15708 |
k = Math.floor(k); |
| 15709 |
if (!isFinite(k) || !(k > 0)) return null; |
| 15710 |
if (!(k > 1)) return millisecond; |
| 15711 |
return timeInterval((date) => { |
| 15712 |
date.setTime(Math.floor(date / k) * k); |
| 15713 |
}, (date, step) => { |
| 15714 |
date.setTime(+date + step * k); |
| 15715 |
}, (start, end) => { |
| 15716 |
return (end - start) / k; |
| 15717 |
}); |
| 15718 |
}; |
| 15719 |
|
| 15720 |
const milliseconds = millisecond.range; |
| 15721 |
|
| 15722 |
const durationSecond = 1000; |
| 15723 |
const durationMinute = durationSecond * 60; |
| 15724 |
const durationHour = durationMinute * 60; |
| 15725 |
const durationDay = durationHour * 24; |
| 15726 |
const durationWeek = durationDay * 7; |
| 15727 |
const durationMonth = durationDay * 30; |
| 15728 |
const durationYear = durationDay * 365; |
| 15729 |
|
| 15730 |
const second = timeInterval((date) => { |
| 15731 |
date.setTime(date - date.getMilliseconds()); |
| 15732 |
}, (date, step) => { |
| 15733 |
date.setTime(+date + step * durationSecond); |
| 15734 |
}, (start, end) => { |
| 15735 |
return (end - start) / durationSecond; |
| 15736 |
}, (date) => { |
| 15737 |
return date.getUTCSeconds(); |
| 15738 |
}); |
| 15739 |
|
| 15740 |
const seconds = second.range; |
| 15741 |
|
| 15742 |
const timeMinute = timeInterval((date) => { |
| 15743 |
date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond); |
| 15744 |
}, (date, step) => { |
| 15745 |
date.setTime(+date + step * durationMinute); |
| 15746 |
}, (start, end) => { |
| 15747 |
return (end - start) / durationMinute; |
| 15748 |
}, (date) => { |
| 15749 |
return date.getMinutes(); |
| 15750 |
}); |
| 15751 |
|
| 15752 |
const timeMinutes = timeMinute.range; |
| 15753 |
|
| 15754 |
const utcMinute = timeInterval((date) => { |
| 15755 |
date.setUTCSeconds(0, 0); |
| 15756 |
}, (date, step) => { |
| 15757 |
date.setTime(+date + step * durationMinute); |
| 15758 |
}, (start, end) => { |
| 15759 |
return (end - start) / durationMinute; |
| 15760 |
}, (date) => { |
| 15761 |
return date.getUTCMinutes(); |
| 15762 |
}); |
| 15763 |
|
| 15764 |
const utcMinutes = utcMinute.range; |
| 15765 |
|
| 15766 |
const timeHour = timeInterval((date) => { |
| 15767 |
date.setTime(date - date.getMilliseconds() - date.getSeconds() * durationSecond - date.getMinutes() * durationMinute); |
| 15768 |
}, (date, step) => { |
| 15769 |
date.setTime(+date + step * durationHour); |
| 15770 |
}, (start, end) => { |
| 15771 |
return (end - start) / durationHour; |
| 15772 |
}, (date) => { |
| 15773 |
return date.getHours(); |
| 15774 |
}); |
| 15775 |
|
| 15776 |
const timeHours = timeHour.range; |
| 15777 |
|
| 15778 |
const utcHour = timeInterval((date) => { |
| 15779 |
date.setUTCMinutes(0, 0, 0); |
| 15780 |
}, (date, step) => { |
| 15781 |
date.setTime(+date + step * durationHour); |
| 15782 |
}, (start, end) => { |
| 15783 |
return (end - start) / durationHour; |
| 15784 |
}, (date) => { |
| 15785 |
return date.getUTCHours(); |
| 15786 |
}); |
| 15787 |
|
| 15788 |
const utcHours = utcHour.range; |
| 15789 |
|
| 15790 |
const timeDay = timeInterval( |
| 15791 |
date => date.setHours(0, 0, 0, 0), |
| 15792 |
(date, step) => date.setDate(date.getDate() + step), |
| 15793 |
(start, end) => (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay, |
| 15794 |
date => date.getDate() - 1 |
| 15795 |
); |
| 15796 |
|
| 15797 |
const timeDays = timeDay.range; |
| 15798 |
|
| 15799 |
const utcDay = timeInterval((date) => { |
| 15800 |
date.setUTCHours(0, 0, 0, 0); |
| 15801 |
}, (date, step) => { |
| 15802 |
date.setUTCDate(date.getUTCDate() + step); |
| 15803 |
}, (start, end) => { |
| 15804 |
return (end - start) / durationDay; |
| 15805 |
}, (date) => { |
| 15806 |
return date.getUTCDate() - 1; |
| 15807 |
}); |
| 15808 |
|
| 15809 |
const utcDays = utcDay.range; |
| 15810 |
|
| 15811 |
const unixDay = timeInterval((date) => { |
| 15812 |
date.setUTCHours(0, 0, 0, 0); |
| 15813 |
}, (date, step) => { |
| 15814 |
date.setUTCDate(date.getUTCDate() + step); |
| 15815 |
}, (start, end) => { |
| 15816 |
return (end - start) / durationDay; |
| 15817 |
}, (date) => { |
| 15818 |
return Math.floor(date / durationDay); |
| 15819 |
}); |
| 15820 |
|
| 15821 |
const unixDays = unixDay.range; |
| 15822 |
|
| 15823 |
function timeWeekday(i) { |
| 15824 |
return timeInterval((date) => { |
| 15825 |
date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7); |
| 15826 |
date.setHours(0, 0, 0, 0); |
| 15827 |
}, (date, step) => { |
| 15828 |
date.setDate(date.getDate() + step * 7); |
| 15829 |
}, (start, end) => { |
| 15830 |
return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek; |
| 15831 |
}); |
| 15832 |
} |
| 15833 |
|
| 15834 |
const timeSunday = timeWeekday(0); |
| 15835 |
const timeMonday = timeWeekday(1); |
| 15836 |
const timeTuesday = timeWeekday(2); |
| 15837 |
const timeWednesday = timeWeekday(3); |
| 15838 |
const timeThursday = timeWeekday(4); |
| 15839 |
const timeFriday = timeWeekday(5); |
| 15840 |
const timeSaturday = timeWeekday(6); |
| 15841 |
|
| 15842 |
const timeSundays = timeSunday.range; |
| 15843 |
const timeMondays = timeMonday.range; |
| 15844 |
const timeTuesdays = timeTuesday.range; |
| 15845 |
const timeWednesdays = timeWednesday.range; |
| 15846 |
const timeThursdays = timeThursday.range; |
| 15847 |
const timeFridays = timeFriday.range; |
| 15848 |
const timeSaturdays = timeSaturday.range; |
| 15849 |
|
| 15850 |
function utcWeekday(i) { |
| 15851 |
return timeInterval((date) => { |
| 15852 |
date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7); |
| 15853 |
date.setUTCHours(0, 0, 0, 0); |
| 15854 |
}, (date, step) => { |
| 15855 |
date.setUTCDate(date.getUTCDate() + step * 7); |
| 15856 |
}, (start, end) => { |
| 15857 |
return (end - start) / durationWeek; |
| 15858 |
}); |
| 15859 |
} |
| 15860 |
|
| 15861 |
const utcSunday = utcWeekday(0); |
| 15862 |
const utcMonday = utcWeekday(1); |
| 15863 |
const utcTuesday = utcWeekday(2); |
| 15864 |
const utcWednesday = utcWeekday(3); |
| 15865 |
const utcThursday = utcWeekday(4); |
| 15866 |
const utcFriday = utcWeekday(5); |
| 15867 |
const utcSaturday = utcWeekday(6); |
| 15868 |
|
| 15869 |
const utcSundays = utcSunday.range; |
| 15870 |
const utcMondays = utcMonday.range; |
| 15871 |
const utcTuesdays = utcTuesday.range; |
| 15872 |
const utcWednesdays = utcWednesday.range; |
| 15873 |
const utcThursdays = utcThursday.range; |
| 15874 |
const utcFridays = utcFriday.range; |
| 15875 |
const utcSaturdays = utcSaturday.range; |
| 15876 |
|
| 15877 |
const timeMonth = timeInterval((date) => { |
| 15878 |
date.setDate(1); |
| 15879 |
date.setHours(0, 0, 0, 0); |
| 15880 |
}, (date, step) => { |
| 15881 |
date.setMonth(date.getMonth() + step); |
| 15882 |
}, (start, end) => { |
| 15883 |
return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12; |
| 15884 |
}, (date) => { |
| 15885 |
return date.getMonth(); |
| 15886 |
}); |
| 15887 |
|
| 15888 |
const timeMonths = timeMonth.range; |
| 15889 |
|
| 15890 |
const utcMonth = timeInterval((date) => { |
| 15891 |
date.setUTCDate(1); |
| 15892 |
date.setUTCHours(0, 0, 0, 0); |
| 15893 |
}, (date, step) => { |
| 15894 |
date.setUTCMonth(date.getUTCMonth() + step); |
| 15895 |
}, (start, end) => { |
| 15896 |
return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12; |
| 15897 |
}, (date) => { |
| 15898 |
return date.getUTCMonth(); |
| 15899 |
}); |
| 15900 |
|
| 15901 |
const utcMonths = utcMonth.range; |
| 15902 |
|
| 15903 |
const timeYear = timeInterval((date) => { |
| 15904 |
date.setMonth(0, 1); |
| 15905 |
date.setHours(0, 0, 0, 0); |
| 15906 |
}, (date, step) => { |
| 15907 |
date.setFullYear(date.getFullYear() + step); |
| 15908 |
}, (start, end) => { |
| 15909 |
return end.getFullYear() - start.getFullYear(); |
| 15910 |
}, (date) => { |
| 15911 |
return date.getFullYear(); |
| 15912 |
}); |
| 15913 |
|
| 15914 |
// An optimized implementation for this simple case. |
| 15915 |
timeYear.every = (k) => { |
| 15916 |
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => { |
| 15917 |
date.setFullYear(Math.floor(date.getFullYear() / k) * k); |
| 15918 |
date.setMonth(0, 1); |
| 15919 |
date.setHours(0, 0, 0, 0); |
| 15920 |
}, (date, step) => { |
| 15921 |
date.setFullYear(date.getFullYear() + step * k); |
| 15922 |
}); |
| 15923 |
}; |
| 15924 |
|
| 15925 |
const timeYears = timeYear.range; |
| 15926 |
|
| 15927 |
const utcYear = timeInterval((date) => { |
| 15928 |
date.setUTCMonth(0, 1); |
| 15929 |
date.setUTCHours(0, 0, 0, 0); |
| 15930 |
}, (date, step) => { |
| 15931 |
date.setUTCFullYear(date.getUTCFullYear() + step); |
| 15932 |
}, (start, end) => { |
| 15933 |
return end.getUTCFullYear() - start.getUTCFullYear(); |
| 15934 |
}, (date) => { |
| 15935 |
return date.getUTCFullYear(); |
| 15936 |
}); |
| 15937 |
|
| 15938 |
// An optimized implementation for this simple case. |
| 15939 |
utcYear.every = (k) => { |
| 15940 |
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : timeInterval((date) => { |
| 15941 |
date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k); |
| 15942 |
date.setUTCMonth(0, 1); |
| 15943 |
date.setUTCHours(0, 0, 0, 0); |
| 15944 |
}, (date, step) => { |
| 15945 |
date.setUTCFullYear(date.getUTCFullYear() + step * k); |
| 15946 |
}); |
| 15947 |
}; |
| 15948 |
|
| 15949 |
const utcYears = utcYear.range; |
| 15950 |
|
| 15951 |
function ticker(year, month, week, day, hour, minute) { |
| 15952 |
|
| 15953 |
const tickIntervals = [ |
| 15954 |
[second, 1, durationSecond], |
| 15955 |
[second, 5, 5 * durationSecond], |
| 15956 |
[second, 15, 15 * durationSecond], |
| 15957 |
[second, 30, 30 * durationSecond], |
| 15958 |
[minute, 1, durationMinute], |
| 15959 |
[minute, 5, 5 * durationMinute], |
| 15960 |
[minute, 15, 15 * durationMinute], |
| 15961 |
[minute, 30, 30 * durationMinute], |
| 15962 |
[ hour, 1, durationHour ], |
| 15963 |
[ hour, 3, 3 * durationHour ], |
| 15964 |
[ hour, 6, 6 * durationHour ], |
| 15965 |
[ hour, 12, 12 * durationHour ], |
| 15966 |
[ day, 1, durationDay ], |
| 15967 |
[ day, 2, 2 * durationDay ], |
| 15968 |
[ week, 1, durationWeek ], |
| 15969 |
[ month, 1, durationMonth ], |
| 15970 |
[ month, 3, 3 * durationMonth ], |
| 15971 |
[ year, 1, durationYear ] |
| 15972 |
]; |
| 15973 |
|
| 15974 |
function ticks(start, stop, count) { |
| 15975 |
const reverse = stop < start; |
| 15976 |
if (reverse) [start, stop] = [stop, start]; |
| 15977 |
const interval = count && typeof count.range === "function" ? count : tickInterval(start, stop, count); |
| 15978 |
const ticks = interval ? interval.range(start, +stop + 1) : []; // inclusive stop |
| 15979 |
return reverse ? ticks.reverse() : ticks; |
| 15980 |
} |
| 15981 |
|
| 15982 |
function tickInterval(start, stop, count) { |
| 15983 |
const target = Math.abs(stop - start) / count; |
| 15984 |
const i = bisector(([,, step]) => step).right(tickIntervals, target); |
| 15985 |
if (i === tickIntervals.length) return year.every(tickStep(start / durationYear, stop / durationYear, count)); |
| 15986 |
if (i === 0) return millisecond.every(Math.max(tickStep(start, stop, count), 1)); |
| 15987 |
const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i]; |
| 15988 |
return t.every(step); |
| 15989 |
} |
| 15990 |
|
| 15991 |
return [ticks, tickInterval]; |
| 15992 |
} |
| 15993 |
|
| 15994 |
const [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute); |
| 15995 |
const [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute); |
| 15996 |
|
| 15997 |
function localDate(d) { |
| 15998 |
if (0 <= d.y && d.y < 100) { |
| 15999 |
var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L); |
| 16000 |
date.setFullYear(d.y); |
| 16001 |
return date; |
| 16002 |
} |
| 16003 |
return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L); |
| 16004 |
} |
| 16005 |
|
| 16006 |
function utcDate(d) { |
| 16007 |
if (0 <= d.y && d.y < 100) { |
| 16008 |
var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L)); |
| 16009 |
date.setUTCFullYear(d.y); |
| 16010 |
return date; |
| 16011 |
} |
| 16012 |
return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L)); |
| 16013 |
} |
| 16014 |
|
| 16015 |
function newDate(y, m, d) { |
| 16016 |
return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0}; |
| 16017 |
} |
| 16018 |
|
| 16019 |
function formatLocale(locale) { |
| 16020 |
var locale_dateTime = locale.dateTime, |
| 16021 |
locale_date = locale.date, |
| 16022 |
locale_time = locale.time, |
| 16023 |
locale_periods = locale.periods, |
| 16024 |
locale_weekdays = locale.days, |
| 16025 |
locale_shortWeekdays = locale.shortDays, |
| 16026 |
locale_months = locale.months, |
| 16027 |
locale_shortMonths = locale.shortMonths; |
| 16028 |
|
| 16029 |
var periodRe = formatRe(locale_periods), |
| 16030 |
periodLookup = formatLookup(locale_periods), |
| 16031 |
weekdayRe = formatRe(locale_weekdays), |
| 16032 |
weekdayLookup = formatLookup(locale_weekdays), |
| 16033 |
shortWeekdayRe = formatRe(locale_shortWeekdays), |
| 16034 |
shortWeekdayLookup = formatLookup(locale_shortWeekdays), |
| 16035 |
monthRe = formatRe(locale_months), |
| 16036 |
monthLookup = formatLookup(locale_months), |
| 16037 |
shortMonthRe = formatRe(locale_shortMonths), |
| 16038 |
shortMonthLookup = formatLookup(locale_shortMonths); |
| 16039 |
|
| 16040 |
var formats = { |
| 16041 |
"a": formatShortWeekday, |
| 16042 |
"A": formatWeekday, |
| 16043 |
"b": formatShortMonth, |
| 16044 |
"B": formatMonth, |
| 16045 |
"c": null, |
| 16046 |
"d": formatDayOfMonth, |
| 16047 |
"e": formatDayOfMonth, |
| 16048 |
"f": formatMicroseconds, |
| 16049 |
"g": formatYearISO, |
| 16050 |
"G": formatFullYearISO, |
| 16051 |
"H": formatHour24, |
| 16052 |
"I": formatHour12, |
| 16053 |
"j": formatDayOfYear, |
| 16054 |
"L": formatMilliseconds, |
| 16055 |
"m": formatMonthNumber, |
| 16056 |
"M": formatMinutes, |
| 16057 |
"p": formatPeriod, |
| 16058 |
"q": formatQuarter, |
| 16059 |
"Q": formatUnixTimestamp, |
| 16060 |
"s": formatUnixTimestampSeconds, |
| 16061 |
"S": formatSeconds, |
| 16062 |
"u": formatWeekdayNumberMonday, |
| 16063 |
"U": formatWeekNumberSunday, |
| 16064 |
"V": formatWeekNumberISO, |
| 16065 |
"w": formatWeekdayNumberSunday, |
| 16066 |
"W": formatWeekNumberMonday, |
| 16067 |
"x": null, |
| 16068 |
"X": null, |
| 16069 |
"y": formatYear, |
| 16070 |
"Y": formatFullYear, |
| 16071 |
"Z": formatZone, |
| 16072 |
"%": formatLiteralPercent |
| 16073 |
}; |
| 16074 |
|
| 16075 |
var utcFormats = { |
| 16076 |
"a": formatUTCShortWeekday, |
| 16077 |
"A": formatUTCWeekday, |
| 16078 |
"b": formatUTCShortMonth, |
| 16079 |
"B": formatUTCMonth, |
| 16080 |
"c": null, |
| 16081 |
"d": formatUTCDayOfMonth, |
| 16082 |
"e": formatUTCDayOfMonth, |
| 16083 |
"f": formatUTCMicroseconds, |
| 16084 |
"g": formatUTCYearISO, |
| 16085 |
"G": formatUTCFullYearISO, |
| 16086 |
"H": formatUTCHour24, |
| 16087 |
"I": formatUTCHour12, |
| 16088 |
"j": formatUTCDayOfYear, |
| 16089 |
"L": formatUTCMilliseconds, |
| 16090 |
"m": formatUTCMonthNumber, |
| 16091 |
"M": formatUTCMinutes, |
| 16092 |
"p": formatUTCPeriod, |
| 16093 |
"q": formatUTCQuarter, |
| 16094 |
"Q": formatUnixTimestamp, |
| 16095 |
"s": formatUnixTimestampSeconds, |
| 16096 |
"S": formatUTCSeconds, |
| 16097 |
"u": formatUTCWeekdayNumberMonday, |
| 16098 |
"U": formatUTCWeekNumberSunday, |
| 16099 |
"V": formatUTCWeekNumberISO, |
| 16100 |
"w": formatUTCWeekdayNumberSunday, |
| 16101 |
"W": formatUTCWeekNumberMonday, |
| 16102 |
"x": null, |
| 16103 |
"X": null, |
| 16104 |
"y": formatUTCYear, |
| 16105 |
"Y": formatUTCFullYear, |
| 16106 |
"Z": formatUTCZone, |
| 16107 |
"%": formatLiteralPercent |
| 16108 |
}; |
| 16109 |
|
| 16110 |
var parses = { |
| 16111 |
"a": parseShortWeekday, |
| 16112 |
"A": parseWeekday, |
| 16113 |
"b": parseShortMonth, |
| 16114 |
"B": parseMonth, |
| 16115 |
"c": parseLocaleDateTime, |
| 16116 |
"d": parseDayOfMonth, |
| 16117 |
"e": parseDayOfMonth, |
| 16118 |
"f": parseMicroseconds, |
| 16119 |
"g": parseYear, |
| 16120 |
"G": parseFullYear, |
| 16121 |
"H": parseHour24, |
| 16122 |
"I": parseHour24, |
| 16123 |
"j": parseDayOfYear, |
| 16124 |
"L": parseMilliseconds, |
| 16125 |
"m": parseMonthNumber, |
| 16126 |
"M": parseMinutes, |
| 16127 |
"p": parsePeriod, |
| 16128 |
"q": parseQuarter, |
| 16129 |
"Q": parseUnixTimestamp, |
| 16130 |
"s": parseUnixTimestampSeconds, |
| 16131 |
"S": parseSeconds, |
| 16132 |
"u": parseWeekdayNumberMonday, |
| 16133 |
"U": parseWeekNumberSunday, |
| 16134 |
"V": parseWeekNumberISO, |
| 16135 |
"w": parseWeekdayNumberSunday, |
| 16136 |
"W": parseWeekNumberMonday, |
| 16137 |
"x": parseLocaleDate, |
| 16138 |
"X": parseLocaleTime, |
| 16139 |
"y": parseYear, |
| 16140 |
"Y": parseFullYear, |
| 16141 |
"Z": parseZone, |
| 16142 |
"%": parseLiteralPercent |
| 16143 |
}; |
| 16144 |
|
| 16145 |
// These recursive directive definitions must be deferred. |
| 16146 |
formats.x = newFormat(locale_date, formats); |
| 16147 |
formats.X = newFormat(locale_time, formats); |
| 16148 |
formats.c = newFormat(locale_dateTime, formats); |
| 16149 |
utcFormats.x = newFormat(locale_date, utcFormats); |
| 16150 |
utcFormats.X = newFormat(locale_time, utcFormats); |
| 16151 |
utcFormats.c = newFormat(locale_dateTime, utcFormats); |
| 16152 |
|
| 16153 |
function newFormat(specifier, formats) { |
| 16154 |
return function(date) { |
| 16155 |
var string = [], |
| 16156 |
i = -1, |
| 16157 |
j = 0, |
| 16158 |
n = specifier.length, |
| 16159 |
c, |
| 16160 |
pad, |
| 16161 |
format; |
| 16162 |
|
| 16163 |
if (!(date instanceof Date)) date = new Date(+date); |
| 16164 |
|
| 16165 |
while (++i < n) { |
| 16166 |
if (specifier.charCodeAt(i) === 37) { |
| 16167 |
string.push(specifier.slice(j, i)); |
| 16168 |
if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i); |
| 16169 |
else pad = c === "e" ? " " : "0"; |
| 16170 |
if (format = formats[c]) c = format(date, pad); |
| 16171 |
string.push(c); |
| 16172 |
j = i + 1; |
| 16173 |
} |
| 16174 |
} |
| 16175 |
|
| 16176 |
string.push(specifier.slice(j, i)); |
| 16177 |
return string.join(""); |
| 16178 |
}; |
| 16179 |
} |
| 16180 |
|
| 16181 |
function newParse(specifier, Z) { |
| 16182 |
return function(string) { |
| 16183 |
var d = newDate(1900, undefined, 1), |
| 16184 |
i = parseSpecifier(d, specifier, string += "", 0), |
| 16185 |
week, day; |
| 16186 |
if (i != string.length) return null; |
| 16187 |
|
| 16188 |
// If a UNIX timestamp is specified, return it. |
| 16189 |
if ("Q" in d) return new Date(d.Q); |
| 16190 |
if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0)); |
| 16191 |
|
| 16192 |
// If this is utcParse, never use the local timezone. |
| 16193 |
if (Z && !("Z" in d)) d.Z = 0; |
| 16194 |
|
| 16195 |
// The am-pm flag is 0 for AM, and 1 for PM. |
| 16196 |
if ("p" in d) d.H = d.H % 12 + d.p * 12; |
| 16197 |
|
| 16198 |
// If the month was not specified, inherit from the quarter. |
| 16199 |
if (d.m === undefined) d.m = "q" in d ? d.q : 0; |
| 16200 |
|
| 16201 |
// Convert day-of-week and week-of-year to day-of-year. |
| 16202 |
if ("V" in d) { |
| 16203 |
if (d.V < 1 || d.V > 53) return null; |
| 16204 |
if (!("w" in d)) d.w = 1; |
| 16205 |
if ("Z" in d) { |
| 16206 |
week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay(); |
| 16207 |
week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week); |
| 16208 |
week = utcDay.offset(week, (d.V - 1) * 7); |
| 16209 |
d.y = week.getUTCFullYear(); |
| 16210 |
d.m = week.getUTCMonth(); |
| 16211 |
d.d = week.getUTCDate() + (d.w + 6) % 7; |
| 16212 |
} else { |
| 16213 |
week = localDate(newDate(d.y, 0, 1)), day = week.getDay(); |
| 16214 |
week = day > 4 || day === 0 ? timeMonday.ceil(week) : timeMonday(week); |
| 16215 |
week = timeDay.offset(week, (d.V - 1) * 7); |
| 16216 |
d.y = week.getFullYear(); |
| 16217 |
d.m = week.getMonth(); |
| 16218 |
d.d = week.getDate() + (d.w + 6) % 7; |
| 16219 |
} |
| 16220 |
} else if ("W" in d || "U" in d) { |
| 16221 |
if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0; |
| 16222 |
day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay(); |
| 16223 |
d.m = 0; |
| 16224 |
d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7; |
| 16225 |
} |
| 16226 |
|
| 16227 |
// If a time zone is specified, all fields are interpreted as UTC and then |
| 16228 |
// offset according to the specified time zone. |
| 16229 |
if ("Z" in d) { |
| 16230 |
d.H += d.Z / 100 | 0; |
| 16231 |
d.M += d.Z % 100; |
| 16232 |
return utcDate(d); |
| 16233 |
} |
| 16234 |
|
| 16235 |
// Otherwise, all fields are in local time. |
| 16236 |
return localDate(d); |
| 16237 |
}; |
| 16238 |
} |
| 16239 |
|
| 16240 |
function parseSpecifier(d, specifier, string, j) { |
| 16241 |
var i = 0, |
| 16242 |
n = specifier.length, |
| 16243 |
m = string.length, |
| 16244 |
c, |
| 16245 |
parse; |
| 16246 |
|
| 16247 |
while (i < n) { |
| 16248 |
if (j >= m) return -1; |
| 16249 |
c = specifier.charCodeAt(i++); |
| 16250 |
if (c === 37) { |
| 16251 |
c = specifier.charAt(i++); |
| 16252 |
parse = parses[c in pads ? specifier.charAt(i++) : c]; |
| 16253 |
if (!parse || ((j = parse(d, string, j)) < 0)) return -1; |
| 16254 |
} else if (c != string.charCodeAt(j++)) { |
| 16255 |
return -1; |
| 16256 |
} |
| 16257 |
} |
| 16258 |
|
| 16259 |
return j; |
| 16260 |
} |
| 16261 |
|
| 16262 |
function parsePeriod(d, string, i) { |
| 16263 |
var n = periodRe.exec(string.slice(i)); |
| 16264 |
return n ? (d.p = periodLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; |
| 16265 |
} |
| 16266 |
|
| 16267 |
function parseShortWeekday(d, string, i) { |
| 16268 |
var n = shortWeekdayRe.exec(string.slice(i)); |
| 16269 |
return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; |
| 16270 |
} |
| 16271 |
|
| 16272 |
function parseWeekday(d, string, i) { |
| 16273 |
var n = weekdayRe.exec(string.slice(i)); |
| 16274 |
return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; |
| 16275 |
} |
| 16276 |
|
| 16277 |
function parseShortMonth(d, string, i) { |
| 16278 |
var n = shortMonthRe.exec(string.slice(i)); |
| 16279 |
return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; |
| 16280 |
} |
| 16281 |
|
| 16282 |
function parseMonth(d, string, i) { |
| 16283 |
var n = monthRe.exec(string.slice(i)); |
| 16284 |
return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1; |
| 16285 |
} |
| 16286 |
|
| 16287 |
function parseLocaleDateTime(d, string, i) { |
| 16288 |
return parseSpecifier(d, locale_dateTime, string, i); |
| 16289 |
} |
| 16290 |
|
| 16291 |
function parseLocaleDate(d, string, i) { |
| 16292 |
return parseSpecifier(d, locale_date, string, i); |
| 16293 |
} |
| 16294 |
|
| 16295 |
function parseLocaleTime(d, string, i) { |
| 16296 |
return parseSpecifier(d, locale_time, string, i); |
| 16297 |
} |
| 16298 |
|
| 16299 |
function formatShortWeekday(d) { |
| 16300 |
return locale_shortWeekdays[d.getDay()]; |
| 16301 |
} |
| 16302 |
|
| 16303 |
function formatWeekday(d) { |
| 16304 |
return locale_weekdays[d.getDay()]; |
| 16305 |
} |
| 16306 |
|
| 16307 |
function formatShortMonth(d) { |
| 16308 |
return locale_shortMonths[d.getMonth()]; |
| 16309 |
} |
| 16310 |
|
| 16311 |
function formatMonth(d) { |
| 16312 |
return locale_months[d.getMonth()]; |
| 16313 |
} |
| 16314 |
|
| 16315 |
function formatPeriod(d) { |
| 16316 |
return locale_periods[+(d.getHours() >= 12)]; |
| 16317 |
} |
| 16318 |
|
| 16319 |
function formatQuarter(d) { |
| 16320 |
return 1 + ~~(d.getMonth() / 3); |
| 16321 |
} |
| 16322 |
|
| 16323 |
function formatUTCShortWeekday(d) { |
| 16324 |
return locale_shortWeekdays[d.getUTCDay()]; |
| 16325 |
} |
| 16326 |
|
| 16327 |
function formatUTCWeekday(d) { |
| 16328 |
return locale_weekdays[d.getUTCDay()]; |
| 16329 |
} |
| 16330 |
|
| 16331 |
function formatUTCShortMonth(d) { |
| 16332 |
return locale_shortMonths[d.getUTCMonth()]; |
| 16333 |
} |
| 16334 |
|
| 16335 |
function formatUTCMonth(d) { |
| 16336 |
return locale_months[d.getUTCMonth()]; |
| 16337 |
} |
| 16338 |
|
| 16339 |
function formatUTCPeriod(d) { |
| 16340 |
return locale_periods[+(d.getUTCHours() >= 12)]; |
| 16341 |
} |
| 16342 |
|
| 16343 |
function formatUTCQuarter(d) { |
| 16344 |
return 1 + ~~(d.getUTCMonth() / 3); |
| 16345 |
} |
| 16346 |
|
| 16347 |
return { |
| 16348 |
format: function(specifier) { |
| 16349 |
var f = newFormat(specifier += "", formats); |
| 16350 |
f.toString = function() { return specifier; }; |
| 16351 |
return f; |
| 16352 |
}, |
| 16353 |
parse: function(specifier) { |
| 16354 |
var p = newParse(specifier += "", false); |
| 16355 |
p.toString = function() { return specifier; }; |
| 16356 |
return p; |
| 16357 |
}, |
| 16358 |
utcFormat: function(specifier) { |
| 16359 |
var f = newFormat(specifier += "", utcFormats); |
| 16360 |
f.toString = function() { return specifier; }; |
| 16361 |
return f; |
| 16362 |
}, |
| 16363 |
utcParse: function(specifier) { |
| 16364 |
var p = newParse(specifier += "", true); |
| 16365 |
p.toString = function() { return specifier; }; |
| 16366 |
return p; |
| 16367 |
} |
| 16368 |
}; |
| 16369 |
} |
| 16370 |
|
| 16371 |
var pads = {"-": "", "_": " ", "0": "0"}, |
| 16372 |
numberRe = /^\s*\d+/, // note: ignores next directive |
| 16373 |
percentRe = /^%/, |
| 16374 |
requoteRe = /[\\^$*+?|[\]().{}]/g; |
| 16375 |
|
| 16376 |
function pad(value, fill, width) { |
| 16377 |
var sign = value < 0 ? "-" : "", |
| 16378 |
string = (sign ? -value : value) + "", |
| 16379 |
length = string.length; |
| 16380 |
return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string); |
| 16381 |
} |
| 16382 |
|
| 16383 |
function requote(s) { |
| 16384 |
return s.replace(requoteRe, "\\$&"); |
| 16385 |
} |
| 16386 |
|
| 16387 |
function formatRe(names) { |
| 16388 |
return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i"); |
| 16389 |
} |
| 16390 |
|
| 16391 |
function formatLookup(names) { |
| 16392 |
return new Map(names.map((name, i) => [name.toLowerCase(), i])); |
| 16393 |
} |
| 16394 |
|
| 16395 |
function parseWeekdayNumberSunday(d, string, i) { |
| 16396 |
var n = numberRe.exec(string.slice(i, i + 1)); |
| 16397 |
return n ? (d.w = +n[0], i + n[0].length) : -1; |
| 16398 |
} |
| 16399 |
|
| 16400 |
function parseWeekdayNumberMonday(d, string, i) { |
| 16401 |
var n = numberRe.exec(string.slice(i, i + 1)); |
| 16402 |
return n ? (d.u = +n[0], i + n[0].length) : -1; |
| 16403 |
} |
| 16404 |
|
| 16405 |
function parseWeekNumberSunday(d, string, i) { |
| 16406 |
var n = numberRe.exec(string.slice(i, i + 2)); |
| 16407 |
return n ? (d.U = +n[0], i + n[0].length) : -1; |
| 16408 |
} |
| 16409 |
|
| 16410 |
function parseWeekNumberISO(d, string, i) { |
| 16411 |
var n = numberRe.exec(string.slice(i, i + 2)); |
| 16412 |
return n ? (d.V = +n[0], i + n[0].length) : -1; |
| 16413 |
} |
| 16414 |
|
| 16415 |
function parseWeekNumberMonday(d, string, i) { |
| 16416 |
var n = numberRe.exec(string.slice(i, i + 2)); |
| 16417 |
return n ? (d.W = +n[0], i + n[0].length) : -1; |
| 16418 |
} |
| 16419 |
|
| 16420 |
function parseFullYear(d, string, i) { |
| 16421 |
var n = numberRe.exec(string.slice(i, i + 4)); |
| 16422 |
return n ? (d.y = +n[0], i + n[0].length) : -1; |
| 16423 |
} |
| 16424 |
|
| 16425 |
function parseYear(d, string, i) { |
| 16426 |
var n = numberRe.exec(string.slice(i, i + 2)); |
| 16427 |
return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1; |
| 16428 |
} |
| 16429 |
|
| 16430 |
function parseZone(d, string, i) { |
| 16431 |
var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6)); |
| 16432 |
return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1; |
| 16433 |
} |
| 16434 |
|
| 16435 |
function parseQuarter(d, string, i) { |
| 16436 |
var n = numberRe.exec(string.slice(i, i + 1)); |
| 16437 |
return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1; |
| 16438 |
} |
| 16439 |
|
| 16440 |
function parseMonthNumber(d, string, i) { |
| 16441 |
var n = numberRe.exec(string.slice(i, i + 2)); |
| 16442 |
return n ? (d.m = n[0] - 1, i + n[0].length) : -1; |
| 16443 |
} |
| 16444 |
|
| 16445 |
function parseDayOfMonth(d, string, i) { |
| 16446 |
var n = numberRe.exec(string.slice(i, i + 2)); |
| 16447 |
return n ? (d.d = +n[0], i + n[0].length) : -1; |
| 16448 |
} |
| 16449 |
|
| 16450 |
function parseDayOfYear(d, string, i) { |
| 16451 |
var n = numberRe.exec(string.slice(i, i + 3)); |
| 16452 |
return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1; |
| 16453 |
} |
| 16454 |
|
| 16455 |
function parseHour24(d, string, i) { |
| 16456 |
var n = numberRe.exec(string.slice(i, i + 2)); |
| 16457 |
return n ? (d.H = +n[0], i + n[0].length) : -1; |
| 16458 |
} |
| 16459 |
|
| 16460 |
function parseMinutes(d, string, i) { |
| 16461 |
var n = numberRe.exec(string.slice(i, i + 2)); |
| 16462 |
return n ? (d.M = +n[0], i + n[0].length) : -1; |
| 16463 |
} |
| 16464 |
|
| 16465 |
function parseSeconds(d, string, i) { |
| 16466 |
var n = numberRe.exec(string.slice(i, i + 2)); |
| 16467 |
return n ? (d.S = +n[0], i + n[0].length) : -1; |
| 16468 |
} |
| 16469 |
|
| 16470 |
function parseMilliseconds(d, string, i) { |
| 16471 |
var n = numberRe.exec(string.slice(i, i + 3)); |
| 16472 |
return n ? (d.L = +n[0], i + n[0].length) : -1; |
| 16473 |
} |
| 16474 |
|
| 16475 |
function parseMicroseconds(d, string, i) { |
| 16476 |
var n = numberRe.exec(string.slice(i, i + 6)); |
| 16477 |
return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1; |
| 16478 |
} |
| 16479 |
|
| 16480 |
function parseLiteralPercent(d, string, i) { |
| 16481 |
var n = percentRe.exec(string.slice(i, i + 1)); |
| 16482 |
return n ? i + n[0].length : -1; |
| 16483 |
} |
| 16484 |
|
| 16485 |
function parseUnixTimestamp(d, string, i) { |
| 16486 |
var n = numberRe.exec(string.slice(i)); |
| 16487 |
return n ? (d.Q = +n[0], i + n[0].length) : -1; |
| 16488 |
} |
| 16489 |
|
| 16490 |
function parseUnixTimestampSeconds(d, string, i) { |
| 16491 |
var n = numberRe.exec(string.slice(i)); |
| 16492 |
return n ? (d.s = +n[0], i + n[0].length) : -1; |
| 16493 |
} |
| 16494 |
|
| 16495 |
function formatDayOfMonth(d, p) { |
| 16496 |
return pad(d.getDate(), p, 2); |
| 16497 |
} |
| 16498 |
|
| 16499 |
function formatHour24(d, p) { |
| 16500 |
return pad(d.getHours(), p, 2); |
| 16501 |
} |
| 16502 |
|
| 16503 |
function formatHour12(d, p) { |
| 16504 |
return pad(d.getHours() % 12 || 12, p, 2); |
| 16505 |
} |
| 16506 |
|
| 16507 |
function formatDayOfYear(d, p) { |
| 16508 |
return pad(1 + timeDay.count(timeYear(d), d), p, 3); |
| 16509 |
} |
| 16510 |
|
| 16511 |
function formatMilliseconds(d, p) { |
| 16512 |
return pad(d.getMilliseconds(), p, 3); |
| 16513 |
} |
| 16514 |
|
| 16515 |
function formatMicroseconds(d, p) { |
| 16516 |
return formatMilliseconds(d, p) + "000"; |
| 16517 |
} |
| 16518 |
|
| 16519 |
function formatMonthNumber(d, p) { |
| 16520 |
return pad(d.getMonth() + 1, p, 2); |
| 16521 |
} |
| 16522 |
|
| 16523 |
function formatMinutes(d, p) { |
| 16524 |
return pad(d.getMinutes(), p, 2); |
| 16525 |
} |
| 16526 |
|
| 16527 |
function formatSeconds(d, p) { |
| 16528 |
return pad(d.getSeconds(), p, 2); |
| 16529 |
} |
| 16530 |
|
| 16531 |
function formatWeekdayNumberMonday(d) { |
| 16532 |
var day = d.getDay(); |
| 16533 |
return day === 0 ? 7 : day; |
| 16534 |
} |
| 16535 |
|
| 16536 |
function formatWeekNumberSunday(d, p) { |
| 16537 |
return pad(timeSunday.count(timeYear(d) - 1, d), p, 2); |
| 16538 |
} |
| 16539 |
|
| 16540 |
function dISO(d) { |
| 16541 |
var day = d.getDay(); |
| 16542 |
return (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d); |
| 16543 |
} |
| 16544 |
|
| 16545 |
function formatWeekNumberISO(d, p) { |
| 16546 |
d = dISO(d); |
| 16547 |
return pad(timeThursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2); |
| 16548 |
} |
| 16549 |
|
| 16550 |
function formatWeekdayNumberSunday(d) { |
| 16551 |
return d.getDay(); |
| 16552 |
} |
| 16553 |
|
| 16554 |
function formatWeekNumberMonday(d, p) { |
| 16555 |
return pad(timeMonday.count(timeYear(d) - 1, d), p, 2); |
| 16556 |
} |
| 16557 |
|
| 16558 |
function formatYear(d, p) { |
| 16559 |
return pad(d.getFullYear() % 100, p, 2); |
| 16560 |
} |
| 16561 |
|
| 16562 |
function formatYearISO(d, p) { |
| 16563 |
d = dISO(d); |
| 16564 |
return pad(d.getFullYear() % 100, p, 2); |
| 16565 |
} |
| 16566 |
|
| 16567 |
function formatFullYear(d, p) { |
| 16568 |
return pad(d.getFullYear() % 10000, p, 4); |
| 16569 |
} |
| 16570 |
|
| 16571 |
function formatFullYearISO(d, p) { |
| 16572 |
var day = d.getDay(); |
| 16573 |
d = (day >= 4 || day === 0) ? timeThursday(d) : timeThursday.ceil(d); |
| 16574 |
return pad(d.getFullYear() % 10000, p, 4); |
| 16575 |
} |
| 16576 |
|
| 16577 |
function formatZone(d) { |
| 16578 |
var z = d.getTimezoneOffset(); |
| 16579 |
return (z > 0 ? "-" : (z *= -1, "+")) |
| 16580 |
+ pad(z / 60 | 0, "0", 2) |
| 16581 |
+ pad(z % 60, "0", 2); |
| 16582 |
} |
| 16583 |
|
| 16584 |
function formatUTCDayOfMonth(d, p) { |
| 16585 |
return pad(d.getUTCDate(), p, 2); |
| 16586 |
} |
| 16587 |
|
| 16588 |
function formatUTCHour24(d, p) { |
| 16589 |
return pad(d.getUTCHours(), p, 2); |
| 16590 |
} |
| 16591 |
|
| 16592 |
function formatUTCHour12(d, p) { |
| 16593 |
return pad(d.getUTCHours() % 12 || 12, p, 2); |
| 16594 |
} |
| 16595 |
|
| 16596 |
function formatUTCDayOfYear(d, p) { |
| 16597 |
return pad(1 + utcDay.count(utcYear(d), d), p, 3); |
| 16598 |
} |
| 16599 |
|
| 16600 |
function formatUTCMilliseconds(d, p) { |
| 16601 |
return pad(d.getUTCMilliseconds(), p, 3); |
| 16602 |
} |
| 16603 |
|
| 16604 |
function formatUTCMicroseconds(d, p) { |
| 16605 |
return formatUTCMilliseconds(d, p) + "000"; |
| 16606 |
} |
| 16607 |
|
| 16608 |
function formatUTCMonthNumber(d, p) { |
| 16609 |
return pad(d.getUTCMonth() + 1, p, 2); |
| 16610 |
} |
| 16611 |
|
| 16612 |
function formatUTCMinutes(d, p) { |
| 16613 |
return pad(d.getUTCMinutes(), p, 2); |
| 16614 |
} |
| 16615 |
|
| 16616 |
function formatUTCSeconds(d, p) { |
| 16617 |
return pad(d.getUTCSeconds(), p, 2); |
| 16618 |
} |
| 16619 |
|
| 16620 |
function formatUTCWeekdayNumberMonday(d) { |
| 16621 |
var dow = d.getUTCDay(); |
| 16622 |
return dow === 0 ? 7 : dow; |
| 16623 |
} |
| 16624 |
|
| 16625 |
function formatUTCWeekNumberSunday(d, p) { |
| 16626 |
return pad(utcSunday.count(utcYear(d) - 1, d), p, 2); |
| 16627 |
} |
| 16628 |
|
| 16629 |
function UTCdISO(d) { |
| 16630 |
var day = d.getUTCDay(); |
| 16631 |
return (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d); |
| 16632 |
} |
| 16633 |
|
| 16634 |
function formatUTCWeekNumberISO(d, p) { |
| 16635 |
d = UTCdISO(d); |
| 16636 |
return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2); |
| 16637 |
} |
| 16638 |
|
| 16639 |
function formatUTCWeekdayNumberSunday(d) { |
| 16640 |
return d.getUTCDay(); |
| 16641 |
} |
| 16642 |
|
| 16643 |
function formatUTCWeekNumberMonday(d, p) { |
| 16644 |
return pad(utcMonday.count(utcYear(d) - 1, d), p, 2); |
| 16645 |
} |
| 16646 |
|
| 16647 |
function formatUTCYear(d, p) { |
| 16648 |
return pad(d.getUTCFullYear() % 100, p, 2); |
| 16649 |
} |
| 16650 |
|
| 16651 |
function formatUTCYearISO(d, p) { |
| 16652 |
d = UTCdISO(d); |
| 16653 |
return pad(d.getUTCFullYear() % 100, p, 2); |
| 16654 |
} |
| 16655 |
|
| 16656 |
function formatUTCFullYear(d, p) { |
| 16657 |
return pad(d.getUTCFullYear() % 10000, p, 4); |
| 16658 |
} |
| 16659 |
|
| 16660 |
function formatUTCFullYearISO(d, p) { |
| 16661 |
var day = d.getUTCDay(); |
| 16662 |
d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d); |
| 16663 |
return pad(d.getUTCFullYear() % 10000, p, 4); |
| 16664 |
} |
| 16665 |
|
| 16666 |
function formatUTCZone() { |
| 16667 |
return "+0000"; |
| 16668 |
} |
| 16669 |
|
| 16670 |
function formatLiteralPercent() { |
| 16671 |
return "%"; |
| 16672 |
} |
| 16673 |
|
| 16674 |
function formatUnixTimestamp(d) { |
| 16675 |
return +d; |
| 16676 |
} |
| 16677 |
|
| 16678 |
function formatUnixTimestampSeconds(d) { |
| 16679 |
return Math.floor(+d / 1000); |
| 16680 |
} |
| 16681 |
|
| 16682 |
var locale; |
| 16683 |
exports.timeFormat = void 0; |
| 16684 |
exports.timeParse = void 0; |
| 16685 |
exports.utcFormat = void 0; |
| 16686 |
exports.utcParse = void 0; |
| 16687 |
|
| 16688 |
defaultLocale({ |
| 16689 |
dateTime: "%x, %X", |
| 16690 |
date: "%-m/%-d/%Y", |
| 16691 |
time: "%-I:%M:%S %p", |
| 16692 |
periods: ["AM", "PM"], |
| 16693 |
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], |
| 16694 |
shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], |
| 16695 |
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], |
| 16696 |
shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] |
| 16697 |
}); |
| 16698 |
|
| 16699 |
function defaultLocale(definition) { |
| 16700 |
locale = formatLocale(definition); |
| 16701 |
exports.timeFormat = locale.format; |
| 16702 |
exports.timeParse = locale.parse; |
| 16703 |
exports.utcFormat = locale.utcFormat; |
| 16704 |
exports.utcParse = locale.utcParse; |
| 16705 |
return locale; |
| 16706 |
} |
| 16707 |
|
| 16708 |
var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ"; |
| 16709 |
|
| 16710 |
function formatIsoNative(date) { |
| 16711 |
return date.toISOString(); |
| 16712 |
} |
| 16713 |
|
| 16714 |
var formatIso = Date.prototype.toISOString |
| 16715 |
? formatIsoNative |
| 16716 |
: exports.utcFormat(isoSpecifier); |
| 16717 |
|
| 16718 |
var formatIso$1 = formatIso; |
| 16719 |
|
| 16720 |
function parseIsoNative(string) { |
| 16721 |
var date = new Date(string); |
| 16722 |
return isNaN(date) ? null : date; |
| 16723 |
} |
| 16724 |
|
| 16725 |
var parseIso = +new Date("2000-01-01T00:00:00.000Z") |
| 16726 |
? parseIsoNative |
| 16727 |
: exports.utcParse(isoSpecifier); |
| 16728 |
|
| 16729 |
var parseIso$1 = parseIso; |
| 16730 |
|
| 16731 |
function date(t) { |
| 16732 |
return new Date(t); |
| 16733 |
} |
| 16734 |
|
| 16735 |
function number(t) { |
| 16736 |
return t instanceof Date ? +t : +new Date(+t); |
| 16737 |
} |
| 16738 |
|
| 16739 |
function calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format) { |
| 16740 |
var scale = continuous(), |
| 16741 |
invert = scale.invert, |
| 16742 |
domain = scale.domain; |
| 16743 |
|
| 16744 |
var formatMillisecond = format(".%L"), |
| 16745 |
formatSecond = format(":%S"), |
| 16746 |
formatMinute = format("%I:%M"), |
| 16747 |
formatHour = format("%I %p"), |
| 16748 |
formatDay = format("%a %d"), |
| 16749 |
formatWeek = format("%b %d"), |
| 16750 |
formatMonth = format("%B"), |
| 16751 |
formatYear = format("%Y"); |
| 16752 |
|
| 16753 |
function tickFormat(date) { |
| 16754 |
return (second(date) < date ? formatMillisecond |
| 16755 |
: minute(date) < date ? formatSecond |
| 16756 |
: hour(date) < date ? formatMinute |
| 16757 |
: day(date) < date ? formatHour |
| 16758 |
: month(date) < date ? (week(date) < date ? formatDay : formatWeek) |
| 16759 |
: year(date) < date ? formatMonth |
| 16760 |
: formatYear)(date); |
| 16761 |
} |
| 16762 |
|
| 16763 |
scale.invert = function(y) { |
| 16764 |
return new Date(invert(y)); |
| 16765 |
}; |
| 16766 |
|
| 16767 |
scale.domain = function(_) { |
| 16768 |
return arguments.length ? domain(Array.from(_, number)) : domain().map(date); |
| 16769 |
}; |
| 16770 |
|
| 16771 |
scale.ticks = function(interval) { |
| 16772 |
var d = domain(); |
| 16773 |
return ticks(d[0], d[d.length - 1], interval == null ? 10 : interval); |
| 16774 |
}; |
| 16775 |
|
| 16776 |
scale.tickFormat = function(count, specifier) { |
| 16777 |
return specifier == null ? tickFormat : format(specifier); |
| 16778 |
}; |
| 16779 |
|
| 16780 |
scale.nice = function(interval) { |
| 16781 |
var d = domain(); |
| 16782 |
if (!interval || typeof interval.range !== "function") interval = tickInterval(d[0], d[d.length - 1], interval == null ? 10 : interval); |
| 16783 |
return interval ? domain(nice(d, interval)) : scale; |
| 16784 |
}; |
| 16785 |
|
| 16786 |
scale.copy = function() { |
| 16787 |
return copy$1(scale, calendar(ticks, tickInterval, year, month, week, day, hour, minute, second, format)); |
| 16788 |
}; |
| 16789 |
|
| 16790 |
return scale; |
| 16791 |
} |
| 16792 |
|
| 16793 |
function time() { |
| 16794 |
return initRange.apply(calendar(timeTicks, timeTickInterval, timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute, second, exports.timeFormat).domain([new Date(2000, 0, 1), new Date(2000, 0, 2)]), arguments); |
| 16795 |
} |
| 16796 |
|
| 16797 |
function utcTime() { |
| 16798 |
return initRange.apply(calendar(utcTicks, utcTickInterval, utcYear, utcMonth, utcSunday, utcDay, utcHour, utcMinute, second, exports.utcFormat).domain([Date.UTC(2000, 0, 1), Date.UTC(2000, 0, 2)]), arguments); |
| 16799 |
} |
| 16800 |
|
| 16801 |
function transformer$1() { |
| 16802 |
var x0 = 0, |
| 16803 |
x1 = 1, |
| 16804 |
t0, |
| 16805 |
t1, |
| 16806 |
k10, |
| 16807 |
transform, |
| 16808 |
interpolator = identity$3, |
| 16809 |
clamp = false, |
| 16810 |
unknown; |
| 16811 |
|
| 16812 |
function scale(x) { |
| 16813 |
return x == null || isNaN(x = +x) ? unknown : interpolator(k10 === 0 ? 0.5 : (x = (transform(x) - t0) * k10, clamp ? Math.max(0, Math.min(1, x)) : x)); |
| 16814 |
} |
| 16815 |
|
| 16816 |
scale.domain = function(_) { |
| 16817 |
return arguments.length ? ([x0, x1] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0), scale) : [x0, x1]; |
| 16818 |
}; |
| 16819 |
|
| 16820 |
scale.clamp = function(_) { |
| 16821 |
return arguments.length ? (clamp = !!_, scale) : clamp; |
| 16822 |
}; |
| 16823 |
|
| 16824 |
scale.interpolator = function(_) { |
| 16825 |
return arguments.length ? (interpolator = _, scale) : interpolator; |
| 16826 |
}; |
| 16827 |
|
| 16828 |
function range(interpolate) { |
| 16829 |
return function(_) { |
| 16830 |
var r0, r1; |
| 16831 |
return arguments.length ? ([r0, r1] = _, interpolator = interpolate(r0, r1), scale) : [interpolator(0), interpolator(1)]; |
| 16832 |
}; |
| 16833 |
} |
| 16834 |
|
| 16835 |
scale.range = range(interpolate$2); |
| 16836 |
|
| 16837 |
scale.rangeRound = range(interpolateRound); |
| 16838 |
|
| 16839 |
scale.unknown = function(_) { |
| 16840 |
return arguments.length ? (unknown = _, scale) : unknown; |
| 16841 |
}; |
| 16842 |
|
| 16843 |
return function(t) { |
| 16844 |
transform = t, t0 = t(x0), t1 = t(x1), k10 = t0 === t1 ? 0 : 1 / (t1 - t0); |
| 16845 |
return scale; |
| 16846 |
}; |
| 16847 |
} |
| 16848 |
|
| 16849 |
function copy(source, target) { |
| 16850 |
return target |
| 16851 |
.domain(source.domain()) |
| 16852 |
.interpolator(source.interpolator()) |
| 16853 |
.clamp(source.clamp()) |
| 16854 |
.unknown(source.unknown()); |
| 16855 |
} |
| 16856 |
|
| 16857 |
function sequential() { |
| 16858 |
var scale = linearish(transformer$1()(identity$3)); |
| 16859 |
|
| 16860 |
scale.copy = function() { |
| 16861 |
return copy(scale, sequential()); |
| 16862 |
}; |
| 16863 |
|
| 16864 |
return initInterpolator.apply(scale, arguments); |
| 16865 |
} |
| 16866 |
|
| 16867 |
function sequentialLog() { |
| 16868 |
var scale = loggish(transformer$1()).domain([1, 10]); |
| 16869 |
|
| 16870 |
scale.copy = function() { |
| 16871 |
return copy(scale, sequentialLog()).base(scale.base()); |
| 16872 |
}; |
| 16873 |
|
| 16874 |
return initInterpolator.apply(scale, arguments); |
| 16875 |
} |
| 16876 |
|
| 16877 |
function sequentialSymlog() { |
| 16878 |
var scale = symlogish(transformer$1()); |
| 16879 |
|
| 16880 |
scale.copy = function() { |
| 16881 |
return copy(scale, sequentialSymlog()).constant(scale.constant()); |
| 16882 |
}; |
| 16883 |
|
| 16884 |
return initInterpolator.apply(scale, arguments); |
| 16885 |
} |
| 16886 |
|
| 16887 |
function sequentialPow() { |
| 16888 |
var scale = powish(transformer$1()); |
| 16889 |
|
| 16890 |
scale.copy = function() { |
| 16891 |
return copy(scale, sequentialPow()).exponent(scale.exponent()); |
| 16892 |
}; |
| 16893 |
|
| 16894 |
return initInterpolator.apply(scale, arguments); |
| 16895 |
} |
| 16896 |
|
| 16897 |
function sequentialSqrt() { |
| 16898 |
return sequentialPow.apply(null, arguments).exponent(0.5); |
| 16899 |
} |
| 16900 |
|
| 16901 |
function sequentialQuantile() { |
| 16902 |
var domain = [], |
| 16903 |
interpolator = identity$3; |
| 16904 |
|
| 16905 |
function scale(x) { |
| 16906 |
if (x != null && !isNaN(x = +x)) return interpolator((bisect(domain, x, 1) - 1) / (domain.length - 1)); |
| 16907 |
} |
| 16908 |
|
| 16909 |
scale.domain = function(_) { |
| 16910 |
if (!arguments.length) return domain.slice(); |
| 16911 |
domain = []; |
| 16912 |
for (let d of _) if (d != null && !isNaN(d = +d)) domain.push(d); |
| 16913 |
domain.sort(ascending$3); |
| 16914 |
return scale; |
| 16915 |
}; |
| 16916 |
|
| 16917 |
scale.interpolator = function(_) { |
| 16918 |
return arguments.length ? (interpolator = _, scale) : interpolator; |
| 16919 |
}; |
| 16920 |
|
| 16921 |
scale.range = function() { |
| 16922 |
return domain.map((d, i) => interpolator(i / (domain.length - 1))); |
| 16923 |
}; |
| 16924 |
|
| 16925 |
scale.quantiles = function(n) { |
| 16926 |
return Array.from({length: n + 1}, (_, i) => quantile$1(domain, i / n)); |
| 16927 |
}; |
| 16928 |
|
| 16929 |
scale.copy = function() { |
| 16930 |
return sequentialQuantile(interpolator).domain(domain); |
| 16931 |
}; |
| 16932 |
|
| 16933 |
return initInterpolator.apply(scale, arguments); |
| 16934 |
} |
| 16935 |
|
| 16936 |
function transformer() { |
| 16937 |
var x0 = 0, |
| 16938 |
x1 = 0.5, |
| 16939 |
x2 = 1, |
| 16940 |
s = 1, |
| 16941 |
t0, |
| 16942 |
t1, |
| 16943 |
t2, |
| 16944 |
k10, |
| 16945 |
k21, |
| 16946 |
interpolator = identity$3, |
| 16947 |
transform, |
| 16948 |
clamp = false, |
| 16949 |
unknown; |
| 16950 |
|
| 16951 |
function scale(x) { |
| 16952 |
return isNaN(x = +x) ? unknown : (x = 0.5 + ((x = +transform(x)) - t1) * (s * x < s * t1 ? k10 : k21), interpolator(clamp ? Math.max(0, Math.min(1, x)) : x)); |
| 16953 |
} |
| 16954 |
|
| 16955 |
scale.domain = function(_) { |
| 16956 |
return arguments.length ? ([x0, x1, x2] = _, t0 = transform(x0 = +x0), t1 = transform(x1 = +x1), t2 = transform(x2 = +x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1, scale) : [x0, x1, x2]; |
| 16957 |
}; |
| 16958 |
|
| 16959 |
scale.clamp = function(_) { |
| 16960 |
return arguments.length ? (clamp = !!_, scale) : clamp; |
| 16961 |
}; |
| 16962 |
|
| 16963 |
scale.interpolator = function(_) { |
| 16964 |
return arguments.length ? (interpolator = _, scale) : interpolator; |
| 16965 |
}; |
| 16966 |
|
| 16967 |
function range(interpolate) { |
| 16968 |
return function(_) { |
| 16969 |
var r0, r1, r2; |
| 16970 |
return arguments.length ? ([r0, r1, r2] = _, interpolator = piecewise(interpolate, [r0, r1, r2]), scale) : [interpolator(0), interpolator(0.5), interpolator(1)]; |
| 16971 |
}; |
| 16972 |
} |
| 16973 |
|
| 16974 |
scale.range = range(interpolate$2); |
| 16975 |
|
| 16976 |
scale.rangeRound = range(interpolateRound); |
| 16977 |
|
| 16978 |
scale.unknown = function(_) { |
| 16979 |
return arguments.length ? (unknown = _, scale) : unknown; |
| 16980 |
}; |
| 16981 |
|
| 16982 |
return function(t) { |
| 16983 |
transform = t, t0 = t(x0), t1 = t(x1), t2 = t(x2), k10 = t0 === t1 ? 0 : 0.5 / (t1 - t0), k21 = t1 === t2 ? 0 : 0.5 / (t2 - t1), s = t1 < t0 ? -1 : 1; |
| 16984 |
return scale; |
| 16985 |
}; |
| 16986 |
} |
| 16987 |
|
| 16988 |
function diverging$1() { |
| 16989 |
var scale = linearish(transformer()(identity$3)); |
| 16990 |
|
| 16991 |
scale.copy = function() { |
| 16992 |
return copy(scale, diverging$1()); |
| 16993 |
}; |
| 16994 |
|
| 16995 |
return initInterpolator.apply(scale, arguments); |
| 16996 |
} |
| 16997 |
|
| 16998 |
function divergingLog() { |
| 16999 |
var scale = loggish(transformer()).domain([0.1, 1, 10]); |
| 17000 |
|
| 17001 |
scale.copy = function() { |
| 17002 |
return copy(scale, divergingLog()).base(scale.base()); |
| 17003 |
}; |
| 17004 |
|
| 17005 |
return initInterpolator.apply(scale, arguments); |
| 17006 |
} |
| 17007 |
|
| 17008 |
function divergingSymlog() { |
| 17009 |
var scale = symlogish(transformer()); |
| 17010 |
|
| 17011 |
scale.copy = function() { |
| 17012 |
return copy(scale, divergingSymlog()).constant(scale.constant()); |
| 17013 |
}; |
| 17014 |
|
| 17015 |
return initInterpolator.apply(scale, arguments); |
| 17016 |
} |
| 17017 |
|
| 17018 |
function divergingPow() { |
| 17019 |
var scale = powish(transformer()); |
| 17020 |
|
| 17021 |
scale.copy = function() { |
| 17022 |
return copy(scale, divergingPow()).exponent(scale.exponent()); |
| 17023 |
}; |
| 17024 |
|
| 17025 |
return initInterpolator.apply(scale, arguments); |
| 17026 |
} |
| 17027 |
|
| 17028 |
function divergingSqrt() { |
| 17029 |
return divergingPow.apply(null, arguments).exponent(0.5); |
| 17030 |
} |
| 17031 |
|
| 17032 |
function colors(specifier) { |
| 17033 |
var n = specifier.length / 6 | 0, colors = new Array(n), i = 0; |
| 17034 |
while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6); |
| 17035 |
return colors; |
| 17036 |
} |
| 17037 |
|
| 17038 |
var category10 = colors("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf"); |
| 17039 |
|
| 17040 |
var Accent = colors("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666"); |
| 17041 |
|
| 17042 |
var Dark2 = colors("1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666"); |
| 17043 |
|
| 17044 |
var observable10 = colors("4269d0efb118ff725c6cc5b03ca951ff8ab7a463f297bbf59c6b4e9498a0"); |
| 17045 |
|
| 17046 |
var Paired = colors("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928"); |
| 17047 |
|
| 17048 |
var Pastel1 = colors("fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2"); |
| 17049 |
|
| 17050 |
var Pastel2 = colors("b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc"); |
| 17051 |
|
| 17052 |
var Set1 = colors("e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999"); |
| 17053 |
|
| 17054 |
var Set2 = colors("66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3"); |
| 17055 |
|
| 17056 |
var Set3 = colors("8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"); |
| 17057 |
|
| 17058 |
var Tableau10 = colors("4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab"); |
| 17059 |
|
| 17060 |
var ramp$1 = scheme => rgbBasis(scheme[scheme.length - 1]); |
| 17061 |
|
| 17062 |
var scheme$q = new Array(3).concat( |
| 17063 |
"d8b365f5f5f55ab4ac", |
| 17064 |
"a6611adfc27d80cdc1018571", |
| 17065 |
"a6611adfc27df5f5f580cdc1018571", |
| 17066 |
"8c510ad8b365f6e8c3c7eae55ab4ac01665e", |
| 17067 |
"8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e", |
| 17068 |
"8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e", |
| 17069 |
"8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e", |
| 17070 |
"5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30", |
| 17071 |
"5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30" |
| 17072 |
).map(colors); |
| 17073 |
|
| 17074 |
var BrBG = ramp$1(scheme$q); |
| 17075 |
|
| 17076 |
var scheme$p = new Array(3).concat( |
| 17077 |
"af8dc3f7f7f77fbf7b", |
| 17078 |
"7b3294c2a5cfa6dba0008837", |
| 17079 |
"7b3294c2a5cff7f7f7a6dba0008837", |
| 17080 |
"762a83af8dc3e7d4e8d9f0d37fbf7b1b7837", |
| 17081 |
"762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837", |
| 17082 |
"762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837", |
| 17083 |
"762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837", |
| 17084 |
"40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b", |
| 17085 |
"40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b" |
| 17086 |
).map(colors); |
| 17087 |
|
| 17088 |
var PRGn = ramp$1(scheme$p); |
| 17089 |
|
| 17090 |
var scheme$o = new Array(3).concat( |
| 17091 |
"e9a3c9f7f7f7a1d76a", |
| 17092 |
"d01c8bf1b6dab8e1864dac26", |
| 17093 |
"d01c8bf1b6daf7f7f7b8e1864dac26", |
| 17094 |
"c51b7de9a3c9fde0efe6f5d0a1d76a4d9221", |
| 17095 |
"c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221", |
| 17096 |
"c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221", |
| 17097 |
"c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221", |
| 17098 |
"8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419", |
| 17099 |
"8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419" |
| 17100 |
).map(colors); |
| 17101 |
|
| 17102 |
var PiYG = ramp$1(scheme$o); |
| 17103 |
|
| 17104 |
var scheme$n = new Array(3).concat( |
| 17105 |
"998ec3f7f7f7f1a340", |
| 17106 |
"5e3c99b2abd2fdb863e66101", |
| 17107 |
"5e3c99b2abd2f7f7f7fdb863e66101", |
| 17108 |
"542788998ec3d8daebfee0b6f1a340b35806", |
| 17109 |
"542788998ec3d8daebf7f7f7fee0b6f1a340b35806", |
| 17110 |
"5427888073acb2abd2d8daebfee0b6fdb863e08214b35806", |
| 17111 |
"5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806", |
| 17112 |
"2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08", |
| 17113 |
"2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08" |
| 17114 |
).map(colors); |
| 17115 |
|
| 17116 |
var PuOr = ramp$1(scheme$n); |
| 17117 |
|
| 17118 |
var scheme$m = new Array(3).concat( |
| 17119 |
"ef8a62f7f7f767a9cf", |
| 17120 |
"ca0020f4a58292c5de0571b0", |
| 17121 |
"ca0020f4a582f7f7f792c5de0571b0", |
| 17122 |
"b2182bef8a62fddbc7d1e5f067a9cf2166ac", |
| 17123 |
"b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac", |
| 17124 |
"b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac", |
| 17125 |
"b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac", |
| 17126 |
"67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061", |
| 17127 |
"67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061" |
| 17128 |
).map(colors); |
| 17129 |
|
| 17130 |
var RdBu = ramp$1(scheme$m); |
| 17131 |
|
| 17132 |
var scheme$l = new Array(3).concat( |
| 17133 |
"ef8a62ffffff999999", |
| 17134 |
"ca0020f4a582bababa404040", |
| 17135 |
"ca0020f4a582ffffffbababa404040", |
| 17136 |
"b2182bef8a62fddbc7e0e0e09999994d4d4d", |
| 17137 |
"b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d", |
| 17138 |
"b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d", |
| 17139 |
"b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d", |
| 17140 |
"67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a", |
| 17141 |
"67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a" |
| 17142 |
).map(colors); |
| 17143 |
|
| 17144 |
var RdGy = ramp$1(scheme$l); |
| 17145 |
|
| 17146 |
var scheme$k = new Array(3).concat( |
| 17147 |
"fc8d59ffffbf91bfdb", |
| 17148 |
"d7191cfdae61abd9e92c7bb6", |
| 17149 |
"d7191cfdae61ffffbfabd9e92c7bb6", |
| 17150 |
"d73027fc8d59fee090e0f3f891bfdb4575b4", |
| 17151 |
"d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4", |
| 17152 |
"d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4", |
| 17153 |
"d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4", |
| 17154 |
"a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695", |
| 17155 |
"a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695" |
| 17156 |
).map(colors); |
| 17157 |
|
| 17158 |
var RdYlBu = ramp$1(scheme$k); |
| 17159 |
|
| 17160 |
var scheme$j = new Array(3).concat( |
| 17161 |
"fc8d59ffffbf91cf60", |
| 17162 |
"d7191cfdae61a6d96a1a9641", |
| 17163 |
"d7191cfdae61ffffbfa6d96a1a9641", |
| 17164 |
"d73027fc8d59fee08bd9ef8b91cf601a9850", |
| 17165 |
"d73027fc8d59fee08bffffbfd9ef8b91cf601a9850", |
| 17166 |
"d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850", |
| 17167 |
"d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850", |
| 17168 |
"a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837", |
| 17169 |
"a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837" |
| 17170 |
).map(colors); |
| 17171 |
|
| 17172 |
var RdYlGn = ramp$1(scheme$j); |
| 17173 |
|
| 17174 |
var scheme$i = new Array(3).concat( |
| 17175 |
"fc8d59ffffbf99d594", |
| 17176 |
"d7191cfdae61abdda42b83ba", |
| 17177 |
"d7191cfdae61ffffbfabdda42b83ba", |
| 17178 |
"d53e4ffc8d59fee08be6f59899d5943288bd", |
| 17179 |
"d53e4ffc8d59fee08bffffbfe6f59899d5943288bd", |
| 17180 |
"d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd", |
| 17181 |
"d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd", |
| 17182 |
"9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2", |
| 17183 |
"9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2" |
| 17184 |
).map(colors); |
| 17185 |
|
| 17186 |
var Spectral = ramp$1(scheme$i); |
| 17187 |
|
| 17188 |
var scheme$h = new Array(3).concat( |
| 17189 |
"e5f5f999d8c92ca25f", |
| 17190 |
"edf8fbb2e2e266c2a4238b45", |
| 17191 |
"edf8fbb2e2e266c2a42ca25f006d2c", |
| 17192 |
"edf8fbccece699d8c966c2a42ca25f006d2c", |
| 17193 |
"edf8fbccece699d8c966c2a441ae76238b45005824", |
| 17194 |
"f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824", |
| 17195 |
"f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b" |
| 17196 |
).map(colors); |
| 17197 |
|
| 17198 |
var BuGn = ramp$1(scheme$h); |
| 17199 |
|
| 17200 |
var scheme$g = new Array(3).concat( |
| 17201 |
"e0ecf49ebcda8856a7", |
| 17202 |
"edf8fbb3cde38c96c688419d", |
| 17203 |
"edf8fbb3cde38c96c68856a7810f7c", |
| 17204 |
"edf8fbbfd3e69ebcda8c96c68856a7810f7c", |
| 17205 |
"edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b", |
| 17206 |
"f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b", |
| 17207 |
"f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b" |
| 17208 |
).map(colors); |
| 17209 |
|
| 17210 |
var BuPu = ramp$1(scheme$g); |
| 17211 |
|
| 17212 |
var scheme$f = new Array(3).concat( |
| 17213 |
"e0f3dba8ddb543a2ca", |
| 17214 |
"f0f9e8bae4bc7bccc42b8cbe", |
| 17215 |
"f0f9e8bae4bc7bccc443a2ca0868ac", |
| 17216 |
"f0f9e8ccebc5a8ddb57bccc443a2ca0868ac", |
| 17217 |
"f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e", |
| 17218 |
"f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e", |
| 17219 |
"f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081" |
| 17220 |
).map(colors); |
| 17221 |
|
| 17222 |
var GnBu = ramp$1(scheme$f); |
| 17223 |
|
| 17224 |
var scheme$e = new Array(3).concat( |
| 17225 |
"fee8c8fdbb84e34a33", |
| 17226 |
"fef0d9fdcc8afc8d59d7301f", |
| 17227 |
"fef0d9fdcc8afc8d59e34a33b30000", |
| 17228 |
"fef0d9fdd49efdbb84fc8d59e34a33b30000", |
| 17229 |
"fef0d9fdd49efdbb84fc8d59ef6548d7301f990000", |
| 17230 |
"fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000", |
| 17231 |
"fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000" |
| 17232 |
).map(colors); |
| 17233 |
|
| 17234 |
var OrRd = ramp$1(scheme$e); |
| 17235 |
|
| 17236 |
var scheme$d = new Array(3).concat( |
| 17237 |
"ece2f0a6bddb1c9099", |
| 17238 |
"f6eff7bdc9e167a9cf02818a", |
| 17239 |
"f6eff7bdc9e167a9cf1c9099016c59", |
| 17240 |
"f6eff7d0d1e6a6bddb67a9cf1c9099016c59", |
| 17241 |
"f6eff7d0d1e6a6bddb67a9cf3690c002818a016450", |
| 17242 |
"fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450", |
| 17243 |
"fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636" |
| 17244 |
).map(colors); |
| 17245 |
|
| 17246 |
var PuBuGn = ramp$1(scheme$d); |
| 17247 |
|
| 17248 |
var scheme$c = new Array(3).concat( |
| 17249 |
"ece7f2a6bddb2b8cbe", |
| 17250 |
"f1eef6bdc9e174a9cf0570b0", |
| 17251 |
"f1eef6bdc9e174a9cf2b8cbe045a8d", |
| 17252 |
"f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d", |
| 17253 |
"f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b", |
| 17254 |
"fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b", |
| 17255 |
"fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858" |
| 17256 |
).map(colors); |
| 17257 |
|
| 17258 |
var PuBu = ramp$1(scheme$c); |
| 17259 |
|
| 17260 |
var scheme$b = new Array(3).concat( |
| 17261 |
"e7e1efc994c7dd1c77", |
| 17262 |
"f1eef6d7b5d8df65b0ce1256", |
| 17263 |
"f1eef6d7b5d8df65b0dd1c77980043", |
| 17264 |
"f1eef6d4b9dac994c7df65b0dd1c77980043", |
| 17265 |
"f1eef6d4b9dac994c7df65b0e7298ace125691003f", |
| 17266 |
"f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f", |
| 17267 |
"f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f" |
| 17268 |
).map(colors); |
| 17269 |
|
| 17270 |
var PuRd = ramp$1(scheme$b); |
| 17271 |
|
| 17272 |
var scheme$a = new Array(3).concat( |
| 17273 |
"fde0ddfa9fb5c51b8a", |
| 17274 |
"feebe2fbb4b9f768a1ae017e", |
| 17275 |
"feebe2fbb4b9f768a1c51b8a7a0177", |
| 17276 |
"feebe2fcc5c0fa9fb5f768a1c51b8a7a0177", |
| 17277 |
"feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177", |
| 17278 |
"fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177", |
| 17279 |
"fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a" |
| 17280 |
).map(colors); |
| 17281 |
|
| 17282 |
var RdPu = ramp$1(scheme$a); |
| 17283 |
|
| 17284 |
var scheme$9 = new Array(3).concat( |
| 17285 |
"edf8b17fcdbb2c7fb8", |
| 17286 |
"ffffcca1dab441b6c4225ea8", |
| 17287 |
"ffffcca1dab441b6c42c7fb8253494", |
| 17288 |
"ffffccc7e9b47fcdbb41b6c42c7fb8253494", |
| 17289 |
"ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84", |
| 17290 |
"ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84", |
| 17291 |
"ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58" |
| 17292 |
).map(colors); |
| 17293 |
|
| 17294 |
var YlGnBu = ramp$1(scheme$9); |
| 17295 |
|
| 17296 |
var scheme$8 = new Array(3).concat( |
| 17297 |
"f7fcb9addd8e31a354", |
| 17298 |
"ffffccc2e69978c679238443", |
| 17299 |
"ffffccc2e69978c67931a354006837", |
| 17300 |
"ffffccd9f0a3addd8e78c67931a354006837", |
| 17301 |
"ffffccd9f0a3addd8e78c67941ab5d238443005a32", |
| 17302 |
"ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32", |
| 17303 |
"ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529" |
| 17304 |
).map(colors); |
| 17305 |
|
| 17306 |
var YlGn = ramp$1(scheme$8); |
| 17307 |
|
| 17308 |
var scheme$7 = new Array(3).concat( |
| 17309 |
"fff7bcfec44fd95f0e", |
| 17310 |
"ffffd4fed98efe9929cc4c02", |
| 17311 |
"ffffd4fed98efe9929d95f0e993404", |
| 17312 |
"ffffd4fee391fec44ffe9929d95f0e993404", |
| 17313 |
"ffffd4fee391fec44ffe9929ec7014cc4c028c2d04", |
| 17314 |
"ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04", |
| 17315 |
"ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506" |
| 17316 |
).map(colors); |
| 17317 |
|
| 17318 |
var YlOrBr = ramp$1(scheme$7); |
| 17319 |
|
| 17320 |
var scheme$6 = new Array(3).concat( |
| 17321 |
"ffeda0feb24cf03b20", |
| 17322 |
"ffffb2fecc5cfd8d3ce31a1c", |
| 17323 |
"ffffb2fecc5cfd8d3cf03b20bd0026", |
| 17324 |
"ffffb2fed976feb24cfd8d3cf03b20bd0026", |
| 17325 |
"ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026", |
| 17326 |
"ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026", |
| 17327 |
"ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026" |
| 17328 |
).map(colors); |
| 17329 |
|
| 17330 |
var YlOrRd = ramp$1(scheme$6); |
| 17331 |
|
| 17332 |
var scheme$5 = new Array(3).concat( |
| 17333 |
"deebf79ecae13182bd", |
| 17334 |
"eff3ffbdd7e76baed62171b5", |
| 17335 |
"eff3ffbdd7e76baed63182bd08519c", |
| 17336 |
"eff3ffc6dbef9ecae16baed63182bd08519c", |
| 17337 |
"eff3ffc6dbef9ecae16baed64292c62171b5084594", |
| 17338 |
"f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594", |
| 17339 |
"f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b" |
| 17340 |
).map(colors); |
| 17341 |
|
| 17342 |
var Blues = ramp$1(scheme$5); |
| 17343 |
|
| 17344 |
var scheme$4 = new Array(3).concat( |
| 17345 |
"e5f5e0a1d99b31a354", |
| 17346 |
"edf8e9bae4b374c476238b45", |
| 17347 |
"edf8e9bae4b374c47631a354006d2c", |
| 17348 |
"edf8e9c7e9c0a1d99b74c47631a354006d2c", |
| 17349 |
"edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32", |
| 17350 |
"f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32", |
| 17351 |
"f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b" |
| 17352 |
).map(colors); |
| 17353 |
|
| 17354 |
var Greens = ramp$1(scheme$4); |
| 17355 |
|
| 17356 |
var scheme$3 = new Array(3).concat( |
| 17357 |
"f0f0f0bdbdbd636363", |
| 17358 |
"f7f7f7cccccc969696525252", |
| 17359 |
"f7f7f7cccccc969696636363252525", |
| 17360 |
"f7f7f7d9d9d9bdbdbd969696636363252525", |
| 17361 |
"f7f7f7d9d9d9bdbdbd969696737373525252252525", |
| 17362 |
"fffffff0f0f0d9d9d9bdbdbd969696737373525252252525", |
| 17363 |
"fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000" |
| 17364 |
).map(colors); |
| 17365 |
|
| 17366 |
var Greys = ramp$1(scheme$3); |
| 17367 |
|
| 17368 |
var scheme$2 = new Array(3).concat( |
| 17369 |
"efedf5bcbddc756bb1", |
| 17370 |
"f2f0f7cbc9e29e9ac86a51a3", |
| 17371 |
"f2f0f7cbc9e29e9ac8756bb154278f", |
| 17372 |
"f2f0f7dadaebbcbddc9e9ac8756bb154278f", |
| 17373 |
"f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486", |
| 17374 |
"fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486", |
| 17375 |
"fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d" |
| 17376 |
).map(colors); |
| 17377 |
|
| 17378 |
var Purples = ramp$1(scheme$2); |
| 17379 |
|
| 17380 |
var scheme$1 = new Array(3).concat( |
| 17381 |
"fee0d2fc9272de2d26", |
| 17382 |
"fee5d9fcae91fb6a4acb181d", |
| 17383 |
"fee5d9fcae91fb6a4ade2d26a50f15", |
| 17384 |
"fee5d9fcbba1fc9272fb6a4ade2d26a50f15", |
| 17385 |
"fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d", |
| 17386 |
"fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d", |
| 17387 |
"fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d" |
| 17388 |
).map(colors); |
| 17389 |
|
| 17390 |
var Reds = ramp$1(scheme$1); |
| 17391 |
|
| 17392 |
var scheme = new Array(3).concat( |
| 17393 |
"fee6cefdae6be6550d", |
| 17394 |
"feeddefdbe85fd8d3cd94701", |
| 17395 |
"feeddefdbe85fd8d3ce6550da63603", |
| 17396 |
"feeddefdd0a2fdae6bfd8d3ce6550da63603", |
| 17397 |
"feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04", |
| 17398 |
"fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04", |
| 17399 |
"fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704" |
| 17400 |
).map(colors); |
| 17401 |
|
| 17402 |
var Oranges = ramp$1(scheme); |
| 17403 |
|
| 17404 |
function cividis(t) { |
| 17405 |
t = Math.max(0, Math.min(1, t)); |
| 17406 |
return "rgb(" |
| 17407 |
+ 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))))))) + ", " |
| 17408 |
+ 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))))))) + ", " |
| 17409 |
+ 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))))))) |
| 17410 |
+ ")"; |
| 17411 |
} |
| 17412 |
|
| 17413 |
var cubehelix = cubehelixLong(cubehelix$3(300, 0.5, 0.0), cubehelix$3(-240, 0.5, 1.0)); |
| 17414 |
|
| 17415 |
var warm = cubehelixLong(cubehelix$3(-100, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8)); |
| 17416 |
|
| 17417 |
var cool = cubehelixLong(cubehelix$3(260, 0.75, 0.35), cubehelix$3(80, 1.50, 0.8)); |
| 17418 |
|
| 17419 |
var c$2 = cubehelix$3(); |
| 17420 |
|
| 17421 |
function rainbow(t) { |
| 17422 |
if (t < 0 || t > 1) t -= Math.floor(t); |
| 17423 |
var ts = Math.abs(t - 0.5); |
| 17424 |
c$2.h = 360 * t - 100; |
| 17425 |
c$2.s = 1.5 - 1.5 * ts; |
| 17426 |
c$2.l = 0.8 - 0.9 * ts; |
| 17427 |
return c$2 + ""; |
| 17428 |
} |
| 17429 |
|
| 17430 |
var c$1 = rgb(), |
| 17431 |
pi_1_3 = Math.PI / 3, |
| 17432 |
pi_2_3 = Math.PI * 2 / 3; |
| 17433 |
|
| 17434 |
function sinebow(t) { |
| 17435 |
var x; |
| 17436 |
t = (0.5 - t) * Math.PI; |
| 17437 |
c$1.r = 255 * (x = Math.sin(t)) * x; |
| 17438 |
c$1.g = 255 * (x = Math.sin(t + pi_1_3)) * x; |
| 17439 |
c$1.b = 255 * (x = Math.sin(t + pi_2_3)) * x; |
| 17440 |
return c$1 + ""; |
| 17441 |
} |
| 17442 |
|
| 17443 |
function turbo(t) { |
| 17444 |
t = Math.max(0, Math.min(1, t)); |
| 17445 |
return "rgb(" |
| 17446 |
+ 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))))))) + ", " |
| 17447 |
+ 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))))))) + ", " |
| 17448 |
+ Math.max(0, Math.min(255, Math.round(27.2 + t * (3211.1 - t * (15327.97 - t * (27814 - t * (22569.18 - t * 6838.66))))))) |
| 17449 |
+ ")"; |
| 17450 |
} |
| 17451 |
|
| 17452 |
function ramp(range) { |
| 17453 |
var n = range.length; |
| 17454 |
return function(t) { |
| 17455 |
return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))]; |
| 17456 |
}; |
| 17457 |
} |
| 17458 |
|
| 17459 |
var viridis = ramp(colors("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725")); |
| 17460 |
|
| 17461 |
var magma = ramp(colors("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")); |
| 17462 |
|
| 17463 |
var inferno = ramp(colors("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")); |
| 17464 |
|
| 17465 |
var plasma = ramp(colors("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921")); |
| 17466 |
|
| 17467 |
function constant$1(x) { |
| 17468 |
return function constant() { |
| 17469 |
return x; |
| 17470 |
}; |
| 17471 |
} |
| 17472 |
|
| 17473 |
const abs = Math.abs; |
| 17474 |
const atan2 = Math.atan2; |
| 17475 |
const cos = Math.cos; |
| 17476 |
const max = Math.max; |
| 17477 |
const min = Math.min; |
| 17478 |
const sin = Math.sin; |
| 17479 |
const sqrt = Math.sqrt; |
| 17480 |
|
| 17481 |
const epsilon = 1e-12; |
| 17482 |
const pi = Math.PI; |
| 17483 |
const halfPi = pi / 2; |
| 17484 |
const tau = 2 * pi; |
| 17485 |
|
| 17486 |
function acos(x) { |
| 17487 |
return x > 1 ? 0 : x < -1 ? pi : Math.acos(x); |
| 17488 |
} |
| 17489 |
|
| 17490 |
function asin(x) { |
| 17491 |
return x >= 1 ? halfPi : x <= -1 ? -halfPi : Math.asin(x); |
| 17492 |
} |
| 17493 |
|
| 17494 |
function withPath(shape) { |
| 17495 |
let digits = 3; |
| 17496 |
|
| 17497 |
shape.digits = function(_) { |
| 17498 |
if (!arguments.length) return digits; |
| 17499 |
if (_ == null) { |
| 17500 |
digits = null; |
| 17501 |
} else { |
| 17502 |
const d = Math.floor(_); |
| 17503 |
if (!(d >= 0)) throw new RangeError(`invalid digits: ${_}`); |
| 17504 |
digits = d; |
| 17505 |
} |
| 17506 |
return shape; |
| 17507 |
}; |
| 17508 |
|
| 17509 |
return () => new Path$1(digits); |
| 17510 |
} |
| 17511 |
|
| 17512 |
function arcInnerRadius(d) { |
| 17513 |
return d.innerRadius; |
| 17514 |
} |
| 17515 |
|
| 17516 |
function arcOuterRadius(d) { |
| 17517 |
return d.outerRadius; |
| 17518 |
} |
| 17519 |
|
| 17520 |
function arcStartAngle(d) { |
| 17521 |
return d.startAngle; |
| 17522 |
} |
| 17523 |
|
| 17524 |
function arcEndAngle(d) { |
| 17525 |
return d.endAngle; |
| 17526 |
} |
| 17527 |
|
| 17528 |
function arcPadAngle(d) { |
| 17529 |
return d && d.padAngle; // Note: optional! |
| 17530 |
} |
| 17531 |
|
| 17532 |
function intersect(x0, y0, x1, y1, x2, y2, x3, y3) { |
| 17533 |
var x10 = x1 - x0, y10 = y1 - y0, |
| 17534 |
x32 = x3 - x2, y32 = y3 - y2, |
| 17535 |
t = y32 * x10 - x32 * y10; |
| 17536 |
if (t * t < epsilon) return; |
| 17537 |
t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t; |
| 17538 |
return [x0 + t * x10, y0 + t * y10]; |
| 17539 |
} |
| 17540 |
|
| 17541 |
// Compute perpendicular offset line of length rc. |
| 17542 |
// http://mathworld.wolfram.com/Circle-LineIntersection.html |
| 17543 |
function cornerTangents(x0, y0, x1, y1, r1, rc, cw) { |
| 17544 |
var x01 = x0 - x1, |
| 17545 |
y01 = y0 - y1, |
| 17546 |
lo = (cw ? rc : -rc) / sqrt(x01 * x01 + y01 * y01), |
| 17547 |
ox = lo * y01, |
| 17548 |
oy = -lo * x01, |
| 17549 |
x11 = x0 + ox, |
| 17550 |
y11 = y0 + oy, |
| 17551 |
x10 = x1 + ox, |
| 17552 |
y10 = y1 + oy, |
| 17553 |
x00 = (x11 + x10) / 2, |
| 17554 |
y00 = (y11 + y10) / 2, |
| 17555 |
dx = x10 - x11, |
| 17556 |
dy = y10 - y11, |
| 17557 |
d2 = dx * dx + dy * dy, |
| 17558 |
r = r1 - rc, |
| 17559 |
D = x11 * y10 - x10 * y11, |
| 17560 |
d = (dy < 0 ? -1 : 1) * sqrt(max(0, r * r * d2 - D * D)), |
| 17561 |
cx0 = (D * dy - dx * d) / d2, |
| 17562 |
cy0 = (-D * dx - dy * d) / d2, |
| 17563 |
cx1 = (D * dy + dx * d) / d2, |
| 17564 |
cy1 = (-D * dx + dy * d) / d2, |
| 17565 |
dx0 = cx0 - x00, |
| 17566 |
dy0 = cy0 - y00, |
| 17567 |
dx1 = cx1 - x00, |
| 17568 |
dy1 = cy1 - y00; |
| 17569 |
|
| 17570 |
// Pick the closer of the two intersection points. |
| 17571 |
// TODO Is there a faster way to determine which intersection to use? |
| 17572 |
if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1; |
| 17573 |
|
| 17574 |
return { |
| 17575 |
cx: cx0, |
| 17576 |
cy: cy0, |
| 17577 |
x01: -ox, |
| 17578 |
y01: -oy, |
| 17579 |
x11: cx0 * (r1 / r - 1), |
| 17580 |
y11: cy0 * (r1 / r - 1) |
| 17581 |
}; |
| 17582 |
} |
| 17583 |
|
| 17584 |
function arc() { |
| 17585 |
var innerRadius = arcInnerRadius, |
| 17586 |
outerRadius = arcOuterRadius, |
| 17587 |
cornerRadius = constant$1(0), |
| 17588 |
padRadius = null, |
| 17589 |
startAngle = arcStartAngle, |
| 17590 |
endAngle = arcEndAngle, |
| 17591 |
padAngle = arcPadAngle, |
| 17592 |
context = null, |
| 17593 |
path = withPath(arc); |
| 17594 |
|
| 17595 |
function arc() { |
| 17596 |
var buffer, |
| 17597 |
r, |
| 17598 |
r0 = +innerRadius.apply(this, arguments), |
| 17599 |
r1 = +outerRadius.apply(this, arguments), |
| 17600 |
a0 = startAngle.apply(this, arguments) - halfPi, |
| 17601 |
a1 = endAngle.apply(this, arguments) - halfPi, |
| 17602 |
da = abs(a1 - a0), |
| 17603 |
cw = a1 > a0; |
| 17604 |
|
| 17605 |
if (!context) context = buffer = path(); |
| 17606 |
|
| 17607 |
// Ensure that the outer radius is always larger than the inner radius. |
| 17608 |
if (r1 < r0) r = r1, r1 = r0, r0 = r; |
| 17609 |
|
| 17610 |
// Is it a point? |
| 17611 |
if (!(r1 > epsilon)) context.moveTo(0, 0); |
| 17612 |
|
| 17613 |
// Or is it a circle or annulus? |
| 17614 |
else if (da > tau - epsilon) { |
| 17615 |
context.moveTo(r1 * cos(a0), r1 * sin(a0)); |
| 17616 |
context.arc(0, 0, r1, a0, a1, !cw); |
| 17617 |
if (r0 > epsilon) { |
| 17618 |
context.moveTo(r0 * cos(a1), r0 * sin(a1)); |
| 17619 |
context.arc(0, 0, r0, a1, a0, cw); |
| 17620 |
} |
| 17621 |
} |
| 17622 |
|
| 17623 |
// Or is it a circular or annular sector? |
| 17624 |
else { |
| 17625 |
var a01 = a0, |
| 17626 |
a11 = a1, |
| 17627 |
a00 = a0, |
| 17628 |
a10 = a1, |
| 17629 |
da0 = da, |
| 17630 |
da1 = da, |
| 17631 |
ap = padAngle.apply(this, arguments) / 2, |
| 17632 |
rp = (ap > epsilon) && (padRadius ? +padRadius.apply(this, arguments) : sqrt(r0 * r0 + r1 * r1)), |
| 17633 |
rc = min(abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments)), |
| 17634 |
rc0 = rc, |
| 17635 |
rc1 = rc, |
| 17636 |
t0, |
| 17637 |
t1; |
| 17638 |
|
| 17639 |
// Apply padding? Note that since r1 ≥ r0, da1 ≥ da0. |
| 17640 |
if (rp > epsilon) { |
| 17641 |
var p0 = asin(rp / r0 * sin(ap)), |
| 17642 |
p1 = asin(rp / r1 * sin(ap)); |
| 17643 |
if ((da0 -= p0 * 2) > epsilon) p0 *= (cw ? 1 : -1), a00 += p0, a10 -= p0; |
| 17644 |
else da0 = 0, a00 = a10 = (a0 + a1) / 2; |
| 17645 |
if ((da1 -= p1 * 2) > epsilon) p1 *= (cw ? 1 : -1), a01 += p1, a11 -= p1; |
| 17646 |
else da1 = 0, a01 = a11 = (a0 + a1) / 2; |
| 17647 |
} |
| 17648 |
|
| 17649 |
var x01 = r1 * cos(a01), |
| 17650 |
y01 = r1 * sin(a01), |
| 17651 |
x10 = r0 * cos(a10), |
| 17652 |
y10 = r0 * sin(a10); |
| 17653 |
|
| 17654 |
// Apply rounded corners? |
| 17655 |
if (rc > epsilon) { |
| 17656 |
var x11 = r1 * cos(a11), |
| 17657 |
y11 = r1 * sin(a11), |
| 17658 |
x00 = r0 * cos(a00), |
| 17659 |
y00 = r0 * sin(a00), |
| 17660 |
oc; |
| 17661 |
|
| 17662 |
// Restrict the corner radius according to the sector angle. If this |
| 17663 |
// intersection fails, it’s probably because the arc is too small, so |
| 17664 |
// disable the corner radius entirely. |
| 17665 |
if (da < pi) { |
| 17666 |
if (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10)) { |
| 17667 |
var ax = x01 - oc[0], |
| 17668 |
ay = y01 - oc[1], |
| 17669 |
bx = x11 - oc[0], |
| 17670 |
by = y11 - oc[1], |
| 17671 |
kc = 1 / sin(acos((ax * bx + ay * by) / (sqrt(ax * ax + ay * ay) * sqrt(bx * bx + by * by))) / 2), |
| 17672 |
lc = sqrt(oc[0] * oc[0] + oc[1] * oc[1]); |
| 17673 |
rc0 = min(rc, (r0 - lc) / (kc - 1)); |
| 17674 |
rc1 = min(rc, (r1 - lc) / (kc + 1)); |
| 17675 |
} else { |
| 17676 |
rc0 = rc1 = 0; |
| 17677 |
} |
| 17678 |
} |
| 17679 |
} |
| 17680 |
|
| 17681 |
// Is the sector collapsed to a line? |
| 17682 |
if (!(da1 > epsilon)) context.moveTo(x01, y01); |
| 17683 |
|
| 17684 |
// Does the sector’s outer ring have rounded corners? |
| 17685 |
else if (rc1 > epsilon) { |
| 17686 |
t0 = cornerTangents(x00, y00, x01, y01, r1, rc1, cw); |
| 17687 |
t1 = cornerTangents(x11, y11, x10, y10, r1, rc1, cw); |
| 17688 |
|
| 17689 |
context.moveTo(t0.cx + t0.x01, t0.cy + t0.y01); |
| 17690 |
|
| 17691 |
// Have the corners merged? |
| 17692 |
if (rc1 < rc) context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw); |
| 17693 |
|
| 17694 |
// Otherwise, draw the two corners and the ring. |
| 17695 |
else { |
| 17696 |
context.arc(t0.cx, t0.cy, rc1, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw); |
| 17697 |
context.arc(0, 0, r1, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), !cw); |
| 17698 |
context.arc(t1.cx, t1.cy, rc1, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw); |
| 17699 |
} |
| 17700 |
} |
| 17701 |
|
| 17702 |
// Or is the outer ring just a circular arc? |
| 17703 |
else context.moveTo(x01, y01), context.arc(0, 0, r1, a01, a11, !cw); |
| 17704 |
|
| 17705 |
// Is there no inner ring, and it’s a circular sector? |
| 17706 |
// Or perhaps it’s an annular sector collapsed due to padding? |
| 17707 |
if (!(r0 > epsilon) || !(da0 > epsilon)) context.lineTo(x10, y10); |
| 17708 |
|
| 17709 |
// Does the sector’s inner ring (or point) have rounded corners? |
| 17710 |
else if (rc0 > epsilon) { |
| 17711 |
t0 = cornerTangents(x10, y10, x11, y11, r0, -rc0, cw); |
| 17712 |
t1 = cornerTangents(x01, y01, x00, y00, r0, -rc0, cw); |
| 17713 |
|
| 17714 |
context.lineTo(t0.cx + t0.x01, t0.cy + t0.y01); |
| 17715 |
|
| 17716 |
// Have the corners merged? |
| 17717 |
if (rc0 < rc) context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t1.y01, t1.x01), !cw); |
| 17718 |
|
| 17719 |
// Otherwise, draw the two corners and the ring. |
| 17720 |
else { |
| 17721 |
context.arc(t0.cx, t0.cy, rc0, atan2(t0.y01, t0.x01), atan2(t0.y11, t0.x11), !cw); |
| 17722 |
context.arc(0, 0, r0, atan2(t0.cy + t0.y11, t0.cx + t0.x11), atan2(t1.cy + t1.y11, t1.cx + t1.x11), cw); |
| 17723 |
context.arc(t1.cx, t1.cy, rc0, atan2(t1.y11, t1.x11), atan2(t1.y01, t1.x01), !cw); |
| 17724 |
} |
| 17725 |
} |
| 17726 |
|
| 17727 |
// Or is the inner ring just a circular arc? |
| 17728 |
else context.arc(0, 0, r0, a10, a00, cw); |
| 17729 |
} |
| 17730 |
|
| 17731 |
context.closePath(); |
| 17732 |
|
| 17733 |
if (buffer) return context = null, buffer + "" || null; |
| 17734 |
} |
| 17735 |
|
| 17736 |
arc.centroid = function() { |
| 17737 |
var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, |
| 17738 |
a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - pi / 2; |
| 17739 |
return [cos(a) * r, sin(a) * r]; |
| 17740 |
}; |
| 17741 |
|
| 17742 |
arc.innerRadius = function(_) { |
| 17743 |
return arguments.length ? (innerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : innerRadius; |
| 17744 |
}; |
| 17745 |
|
| 17746 |
arc.outerRadius = function(_) { |
| 17747 |
return arguments.length ? (outerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : outerRadius; |
| 17748 |
}; |
| 17749 |
|
| 17750 |
arc.cornerRadius = function(_) { |
| 17751 |
return arguments.length ? (cornerRadius = typeof _ === "function" ? _ : constant$1(+_), arc) : cornerRadius; |
| 17752 |
}; |
| 17753 |
|
| 17754 |
arc.padRadius = function(_) { |
| 17755 |
return arguments.length ? (padRadius = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), arc) : padRadius; |
| 17756 |
}; |
| 17757 |
|
| 17758 |
arc.startAngle = function(_) { |
| 17759 |
return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : startAngle; |
| 17760 |
}; |
| 17761 |
|
| 17762 |
arc.endAngle = function(_) { |
| 17763 |
return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : endAngle; |
| 17764 |
}; |
| 17765 |
|
| 17766 |
arc.padAngle = function(_) { |
| 17767 |
return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), arc) : padAngle; |
| 17768 |
}; |
| 17769 |
|
| 17770 |
arc.context = function(_) { |
| 17771 |
return arguments.length ? ((context = _ == null ? null : _), arc) : context; |
| 17772 |
}; |
| 17773 |
|
| 17774 |
return arc; |
| 17775 |
} |
| 17776 |
|
| 17777 |
var slice = Array.prototype.slice; |
| 17778 |
|
| 17779 |
function array(x) { |
| 17780 |
return typeof x === "object" && "length" in x |
| 17781 |
? x // Array, TypedArray, NodeList, array-like |
| 17782 |
: Array.from(x); // Map, Set, iterable, string, or anything else |
| 17783 |
} |
| 17784 |
|
| 17785 |
function Linear(context) { |
| 17786 |
this._context = context; |
| 17787 |
} |
| 17788 |
|
| 17789 |
Linear.prototype = { |
| 17790 |
areaStart: function() { |
| 17791 |
this._line = 0; |
| 17792 |
}, |
| 17793 |
areaEnd: function() { |
| 17794 |
this._line = NaN; |
| 17795 |
}, |
| 17796 |
lineStart: function() { |
| 17797 |
this._point = 0; |
| 17798 |
}, |
| 17799 |
lineEnd: function() { |
| 17800 |
if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath(); |
| 17801 |
this._line = 1 - this._line; |
| 17802 |
}, |
| 17803 |
point: function(x, y) { |
| 17804 |
x = +x, y = +y; |
| 17805 |
switch (this._point) { |
| 17806 |
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break; |
| 17807 |
case 1: this._point = 2; // falls through |
| 17808 |
default: this._context.lineTo(x, y); break; |
| 17809 |
} |
| 17810 |
} |
| 17811 |
}; |
| 17812 |
|
| 17813 |
function curveLinear(context) { |
| 17814 |
return new Linear(context); |
| 17815 |
} |
| 17816 |
|
| 17817 |
function x(p) { |
| 17818 |
return p[0]; |
| 17819 |
} |
| 17820 |
|
| 17821 |
function y(p) { |
| 17822 |
return p[1]; |
| 17823 |
} |
| 17824 |
|
| 17825 |
function line(x$1, y$1) { |
| 17826 |
var defined = constant$1(true), |
| 17827 |
context = null, |
| 17828 |
curve = curveLinear, |
| 17829 |
output = null, |
| 17830 |
path = withPath(line); |
| 17831 |
|
| 17832 |
x$1 = typeof x$1 === "function" ? x$1 : (x$1 === undefined) ? x : constant$1(x$1); |
| 17833 |
y$1 = typeof y$1 === "function" ? y$1 : (y$1 === undefined) ? y : constant$1(y$1); |
| 17834 |
|
| 17835 |
function line(data) { |
| 17836 |
var i, |
| 17837 |
n = (data = array(data)).length, |
| 17838 |
d, |
| 17839 |
defined0 = false, |
| 17840 |
buffer; |
| 17841 |
|
| 17842 |
if (context == null) output = curve(buffer = path()); |
| 17843 |
|
| 17844 |
for (i = 0; i <= n; ++i) { |
| 17845 |
if (!(i < n && defined(d = data[i], i, data)) === defined0) { |
| 17846 |
if (defined0 = !defined0) output.lineStart(); |
| 17847 |
else output.lineEnd(); |
| 17848 |
} |
| 17849 |
if (defined0) output.point(+x$1(d, i, data), +y$1(d, i, data)); |
| 17850 |
} |
| 17851 |
|
| 17852 |
if (buffer) return output = null, buffer + "" || null; |
| 17853 |
} |
| 17854 |
|
| 17855 |
line.x = function(_) { |
| 17856 |
return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), line) : x$1; |
| 17857 |
}; |
| 17858 |
|
| 17859 |
line.y = function(_) { |
| 17860 |
return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), line) : y$1; |
| 17861 |
}; |
| 17862 |
|
| 17863 |
line.defined = function(_) { |
| 17864 |
return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), line) : defined; |
| 17865 |
}; |
| 17866 |
|
| 17867 |
line.curve = function(_) { |
| 17868 |
return arguments.length ? (curve = _, context != null && (output = curve(context)), line) : curve; |
| 17869 |
}; |
| 17870 |
|
| 17871 |
line.context = function(_) { |
| 17872 |
return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), line) : context; |
| 17873 |
}; |
| 17874 |
|
| 17875 |
return line; |
| 17876 |
} |
| 17877 |
|
| 17878 |
function area(x0, y0, y1) { |
| 17879 |
var x1 = null, |
| 17880 |
defined = constant$1(true), |
| 17881 |
context = null, |
| 17882 |
curve = curveLinear, |
| 17883 |
output = null, |
| 17884 |
path = withPath(area); |
| 17885 |
|
| 17886 |
x0 = typeof x0 === "function" ? x0 : (x0 === undefined) ? x : constant$1(+x0); |
| 17887 |
y0 = typeof y0 === "function" ? y0 : (y0 === undefined) ? constant$1(0) : constant$1(+y0); |
| 17888 |
y1 = typeof y1 === "function" ? y1 : (y1 === undefined) ? y : constant$1(+y1); |
| 17889 |
|
| 17890 |
function area(data) { |
| 17891 |
var i, |
| 17892 |
j, |
| 17893 |
k, |
| 17894 |
n = (data = array(data)).length, |
| 17895 |
d, |
| 17896 |
defined0 = false, |
| 17897 |
buffer, |
| 17898 |
x0z = new Array(n), |
| 17899 |
y0z = new Array(n); |
| 17900 |
|
| 17901 |
if (context == null) output = curve(buffer = path()); |
| 17902 |
|
| 17903 |
for (i = 0; i <= n; ++i) { |
| 17904 |
if (!(i < n && defined(d = data[i], i, data)) === defined0) { |
| 17905 |
if (defined0 = !defined0) { |
| 17906 |
j = i; |
| 17907 |
output.areaStart(); |
| 17908 |
output.lineStart(); |
| 17909 |
} else { |
| 17910 |
output.lineEnd(); |
| 17911 |
output.lineStart(); |
| 17912 |
for (k = i - 1; k >= j; --k) { |
| 17913 |
output.point(x0z[k], y0z[k]); |
| 17914 |
} |
| 17915 |
output.lineEnd(); |
| 17916 |
output.areaEnd(); |
| 17917 |
} |
| 17918 |
} |
| 17919 |
if (defined0) { |
| 17920 |
x0z[i] = +x0(d, i, data), y0z[i] = +y0(d, i, data); |
| 17921 |
output.point(x1 ? +x1(d, i, data) : x0z[i], y1 ? +y1(d, i, data) : y0z[i]); |
| 17922 |
} |
| 17923 |
} |
| 17924 |
|
| 17925 |
if (buffer) return output = null, buffer + "" || null; |
| 17926 |
} |
| 17927 |
|
| 17928 |
function arealine() { |
| 17929 |
return line().defined(defined).curve(curve).context(context); |
| 17930 |
} |
| 17931 |
|
| 17932 |
area.x = function(_) { |
| 17933 |
return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), x1 = null, area) : x0; |
| 17934 |
}; |
| 17935 |
|
| 17936 |
area.x0 = function(_) { |
| 17937 |
return arguments.length ? (x0 = typeof _ === "function" ? _ : constant$1(+_), area) : x0; |
| 17938 |
}; |
| 17939 |
|
| 17940 |
area.x1 = function(_) { |
| 17941 |
return arguments.length ? (x1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : x1; |
| 17942 |
}; |
| 17943 |
|
| 17944 |
area.y = function(_) { |
| 17945 |
return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), y1 = null, area) : y0; |
| 17946 |
}; |
| 17947 |
|
| 17948 |
area.y0 = function(_) { |
| 17949 |
return arguments.length ? (y0 = typeof _ === "function" ? _ : constant$1(+_), area) : y0; |
| 17950 |
}; |
| 17951 |
|
| 17952 |
area.y1 = function(_) { |
| 17953 |
return arguments.length ? (y1 = _ == null ? null : typeof _ === "function" ? _ : constant$1(+_), area) : y1; |
| 17954 |
}; |
| 17955 |
|
| 17956 |
area.lineX0 = |
| 17957 |
area.lineY0 = function() { |
| 17958 |
return arealine().x(x0).y(y0); |
| 17959 |
}; |
| 17960 |
|
| 17961 |
area.lineY1 = function() { |
| 17962 |
return arealine().x(x0).y(y1); |
| 17963 |
}; |
| 17964 |
|
| 17965 |
area.lineX1 = function() { |
| 17966 |
return arealine().x(x1).y(y0); |
| 17967 |
}; |
| 17968 |
|
| 17969 |
area.defined = function(_) { |
| 17970 |
return arguments.length ? (defined = typeof _ === "function" ? _ : constant$1(!!_), area) : defined; |
| 17971 |
}; |
| 17972 |
|
| 17973 |
area.curve = function(_) { |
| 17974 |
return arguments.length ? (curve = _, context != null && (output = curve(context)), area) : curve; |
| 17975 |
}; |
| 17976 |
|
| 17977 |
area.context = function(_) { |
| 17978 |
return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), area) : context; |
| 17979 |
}; |
| 17980 |
|
| 17981 |
return area; |
| 17982 |
} |
| 17983 |
|
| 17984 |
function descending$1(a, b) { |
| 17985 |
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN; |
| 17986 |
} |
| 17987 |
|
| 17988 |
function identity$1(d) { |
| 17989 |
return d; |
| 17990 |
} |
| 17991 |
|
| 17992 |
function pie() { |
| 17993 |
var value = identity$1, |
| 17994 |
sortValues = descending$1, |
| 17995 |
sort = null, |
| 17996 |
startAngle = constant$1(0), |
| 17997 |
endAngle = constant$1(tau), |
| 17998 |
padAngle = constant$1(0); |
| 17999 |
|
| 18000 |
function pie(data) { |
| 18001 |
var i, |
| 18002 |
n = (data = array(data)).length, |
| 18003 |
j, |
| 18004 |
k, |
| 18005 |
sum = 0, |
| 18006 |
index = new Array(n), |
| 18007 |
arcs = new Array(n), |
| 18008 |
a0 = +startAngle.apply(this, arguments), |
| 18009 |
da = Math.min(tau, Math.max(-tau, endAngle.apply(this, arguments) - a0)), |
| 18010 |
a1, |
| 18011 |
p = Math.min(Math.abs(da) / n, padAngle.apply(this, arguments)), |
| 18012 |
pa = p * (da < 0 ? -1 : 1), |
| 18013 |
v; |
| 18014 |
|
| 18015 |
for (i = 0; i < n; ++i) { |
| 18016 |
if ((v = arcs[index[i] = i] = +value(data[i], i, data)) > 0) { |
| 18017 |
sum += v; |
| 18018 |
} |
| 18019 |
} |
| 18020 |
|
| 18021 |
// Optionally sort the arcs by previously-computed values or by data. |
| 18022 |
if (sortValues != null) index.sort(function(i, j) { return sortValues(arcs[i], arcs[j]); }); |
| 18023 |
else if (sort != null) index.sort(function(i, j) { return sort(data[i], data[j]); }); |
| 18024 |
|
| 18025 |
// Compute the arcs! They are stored in the original data's order. |
| 18026 |
for (i = 0, k = sum ? (da - n * pa) / sum : 0; i < n; ++i, a0 = a1) { |
| 18027 |
j = index[i], v = arcs[j], a1 = a0 + (v > 0 ? v * k : 0) + pa, arcs[j] = { |
| 18028 |
data: data[j], |
| 18029 |
index: i, |
| 18030 |
value: v, |
| 18031 |
startAngle: a0, |
| 18032 |
endAngle: a1, |
| 18033 |
padAngle: p |
| 18034 |
}; |
| 18035 |
} |
| 18036 |
|
| 18037 |
return arcs; |
| 18038 |
} |
| 18039 |
|
| 18040 |
pie.value = function(_) { |
| 18041 |
return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), pie) : value; |
| 18042 |
}; |
| 18043 |
|
| 18044 |
pie.sortValues = function(_) { |
| 18045 |
return arguments.length ? (sortValues = _, sort = null, pie) : sortValues; |
| 18046 |
}; |
| 18047 |
|
| 18048 |
pie.sort = function(_) { |
| 18049 |
return arguments.length ? (sort = _, sortValues = null, pie) : sort; |
| 18050 |
}; |
| 18051 |
|
| 18052 |
pie.startAngle = function(_) { |
| 18053 |
return arguments.length ? (startAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : startAngle; |
| 18054 |
}; |
| 18055 |
|
| 18056 |
pie.endAngle = function(_) { |
| 18057 |
return arguments.length ? (endAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : endAngle; |
| 18058 |
}; |
| 18059 |
|
| 18060 |
pie.padAngle = function(_) { |
| 18061 |
return arguments.length ? (padAngle = typeof _ === "function" ? _ : constant$1(+_), pie) : padAngle; |
| 18062 |
}; |
| 18063 |
|
| 18064 |
return pie; |
| 18065 |
} |
| 18066 |
|
| 18067 |
var curveRadialLinear = curveRadial(curveLinear); |
| 18068 |
|
| 18069 |
function Radial(curve) { |
| 18070 |
this._curve = curve; |
| 18071 |
} |
| 18072 |
|
| 18073 |
Radial.prototype = { |
| 18074 |
areaStart: function() { |
| 18075 |
this._curve.areaStart(); |
| 18076 |
}, |
| 18077 |
areaEnd: function() { |
| 18078 |
this._curve.areaEnd(); |
| 18079 |
}, |
| 18080 |
lineStart: function() { |
| 18081 |
this._curve.lineStart(); |
| 18082 |
}, |
| 18083 |
lineEnd: function() { |
| 18084 |
this._curve.lineEnd(); |
| 18085 |
}, |
| 18086 |
point: function(a, r) { |
| 18087 |
this._curve.point(r * Math.sin(a), r * -Math.cos(a)); |
| 18088 |
} |
| 18089 |
}; |
| 18090 |
|
| 18091 |
function curveRadial(curve) { |
| 18092 |
|
| 18093 |
function radial(context) { |
| 18094 |
return new Radial(curve(context)); |
| 18095 |
} |
| 18096 |
|
| 18097 |
radial._curve = curve; |
| 18098 |
|
| 18099 |
return radial; |
| 18100 |
} |
| 18101 |
|
| 18102 |
function lineRadial(l) { |
| 18103 |
var c = l.curve; |
| 18104 |
|
| 18105 |
l.angle = l.x, delete l.x; |
| 18106 |
l.radius = l.y, delete l.y; |
| 18107 |
|
| 18108 |
l.curve = function(_) { |
| 18109 |
return arguments.length ? c(curveRadial(_)) : c()._curve; |
| 18110 |
}; |
| 18111 |
|
| 18112 |
return l; |
| 18113 |
} |
| 18114 |
|
| 18115 |
function lineRadial$1() { |
| 18116 |
return lineRadial(line().curve(curveRadialLinear)); |
| 18117 |
} |
| 18118 |
|
| 18119 |
function areaRadial() { |
| 18120 |
var a = area().curve(curveRadialLinear), |
| 18121 |
c = a.curve, |
| 18122 |
x0 = a.lineX0, |
| 18123 |
x1 = a.lineX1, |
| 18124 |
y0 = a.lineY0, |
| 18125 |
y1 = a.lineY1; |
| 18126 |
|
| 18127 |
a.angle = a.x, delete a.x; |
| 18128 |
a.startAngle = a.x0, delete a.x0; |
| 18129 |
a.endAngle = a.x1, delete a.x1; |
| 18130 |
a.radius = a.y, delete a.y; |
| 18131 |
a.innerRadius = a.y0, delete a.y0; |
| 18132 |
a.outerRadius = a.y1, delete a.y1; |
| 18133 |
a.lineStartAngle = function() { return lineRadial(x0()); }, delete a.lineX0; |
| 18134 |
a.lineEndAngle = function() { return lineRadial(x1()); }, delete a.lineX1; |
| 18135 |
a.lineInnerRadius = function() { return lineRadial(y0()); }, delete a.lineY0; |
| 18136 |
a.lineOuterRadius = function() { return lineRadial(y1()); }, delete a.lineY1; |
| 18137 |
|
| 18138 |
a.curve = function(_) { |
| 18139 |
return arguments.length ? c(curveRadial(_)) : c()._curve; |
| 18140 |
}; |
| 18141 |
|
| 18142 |
return a; |
| 18143 |
} |
| 18144 |
|
| 18145 |
function pointRadial(x, y) { |
| 18146 |
return [(y = +y) * Math.cos(x -= Math.PI / 2), y * Math.sin(x)]; |
| 18147 |
} |
| 18148 |
|
| 18149 |
class Bump { |
| 18150 |
constructor(context, x) { |
| 18151 |
this._context = context; |
| 18152 |
this._x = x; |
| 18153 |
} |
| 18154 |
areaStart() { |
| 18155 |
this._line = 0; |
| 18156 |
} |
| 18157 |
areaEnd() { |
| 18158 |
this._line = NaN; |
| 18159 |
} |
| 18160 |
lineStart() { |
| 18161 |
this._point = 0; |
| 18162 |
} |
| 18163 |
lineEnd() { |
| 18164 |
if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath(); |
| 18165 |
this._line = 1 - this._line; |
| 18166 |
} |
| 18167 |
point(x, y) { |
| 18168 |
x = +x, y = +y; |
| 18169 |
switch (this._point) { |
| 18170 |
case 0: { |
| 18171 |
this._point = 1; |
| 18172 |
if (this._line) this._context.lineTo(x, y); |
| 18173 |
else this._context.moveTo(x, y); |
| 18174 |
break; |
| 18175 |
} |
| 18176 |
case 1: this._point = 2; // falls through |
| 18177 |
default: { |
| 18178 |
if (this._x) this._context.bezierCurveTo(this._x0 = (this._x0 + x) / 2, this._y0, this._x0, y, x, y); |
| 18179 |
else this._context.bezierCurveTo(this._x0, this._y0 = (this._y0 + y) / 2, x, this._y0, x, y); |
| 18180 |
break; |
| 18181 |
} |
| 18182 |
} |
| 18183 |
this._x0 = x, this._y0 = y; |
| 18184 |
} |
| 18185 |
} |
| 18186 |
|
| 18187 |
class BumpRadial { |
| 18188 |
constructor(context) { |
| 18189 |
this._context = context; |
| 18190 |
} |
| 18191 |
lineStart() { |
| 18192 |
this._point = 0; |
| 18193 |
} |
| 18194 |
lineEnd() {} |
| 18195 |
point(x, y) { |
| 18196 |
x = +x, y = +y; |
| 18197 |
if (this._point === 0) { |
| 18198 |
this._point = 1; |
| 18199 |
} else { |
| 18200 |
const p0 = pointRadial(this._x0, this._y0); |
| 18201 |
const p1 = pointRadial(this._x0, this._y0 = (this._y0 + y) / 2); |
| 18202 |
const p2 = pointRadial(x, this._y0); |
| 18203 |
const p3 = pointRadial(x, y); |
| 18204 |
this._context.moveTo(...p0); |
| 18205 |
this._context.bezierCurveTo(...p1, ...p2, ...p3); |
| 18206 |
} |
| 18207 |
this._x0 = x, this._y0 = y; |
| 18208 |
} |
| 18209 |
} |
| 18210 |
|
| 18211 |
function bumpX(context) { |
| 18212 |
return new Bump(context, true); |
| 18213 |
} |
| 18214 |
|
| 18215 |
function bumpY(context) { |
| 18216 |
return new Bump(context, false); |
| 18217 |
} |
| 18218 |
|
| 18219 |
function bumpRadial(context) { |
| 18220 |
return new BumpRadial(context); |
| 18221 |
} |
| 18222 |
|
| 18223 |
function linkSource(d) { |
| 18224 |
return d.source; |
| 18225 |
} |
| 18226 |
|
| 18227 |
function linkTarget(d) { |
| 18228 |
return d.target; |
| 18229 |
} |
| 18230 |
|
| 18231 |
function link(curve) { |
| 18232 |
let source = linkSource, |
| 18233 |
target = linkTarget, |
| 18234 |
x$1 = x, |
| 18235 |
y$1 = y, |
| 18236 |
context = null, |
| 18237 |
output = null, |
| 18238 |
path = withPath(link); |
| 18239 |
|
| 18240 |
function link() { |
| 18241 |
let buffer; |
| 18242 |
const argv = slice.call(arguments); |
| 18243 |
const s = source.apply(this, argv); |
| 18244 |
const t = target.apply(this, argv); |
| 18245 |
if (context == null) output = curve(buffer = path()); |
| 18246 |
output.lineStart(); |
| 18247 |
argv[0] = s, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv)); |
| 18248 |
argv[0] = t, output.point(+x$1.apply(this, argv), +y$1.apply(this, argv)); |
| 18249 |
output.lineEnd(); |
| 18250 |
if (buffer) return output = null, buffer + "" || null; |
| 18251 |
} |
| 18252 |
|
| 18253 |
link.source = function(_) { |
| 18254 |
return arguments.length ? (source = _, link) : source; |
| 18255 |
}; |
| 18256 |
|
| 18257 |
link.target = function(_) { |
| 18258 |
return arguments.length ? (target = _, link) : target; |
| 18259 |
}; |
| 18260 |
|
| 18261 |
link.x = function(_) { |
| 18262 |
return arguments.length ? (x$1 = typeof _ === "function" ? _ : constant$1(+_), link) : x$1; |
| 18263 |
}; |
| 18264 |
|
| 18265 |
link.y = function(_) { |
| 18266 |
return arguments.length ? (y$1 = typeof _ === "function" ? _ : constant$1(+_), link) : y$1; |
| 18267 |
}; |
| 18268 |
|
| 18269 |
link.context = function(_) { |
| 18270 |
return arguments.length ? (_ == null ? context = output = null : output = curve(context = _), link) : context; |
| 18271 |
}; |
| 18272 |
|
| 18273 |
return link; |
| 18274 |
} |
| 18275 |
|
| 18276 |
function linkHorizontal() { |
| 18277 |
return link(bumpX); |
| 18278 |
} |
| 18279 |
|
| 18280 |
function linkVertical() { |
| 18281 |
return link(bumpY); |
| 18282 |
} |
| 18283 |
|
| 18284 |
function linkRadial() { |
| 18285 |
const l = link(bumpRadial); |
| 18286 |
l.angle = l.x, delete l.x; |
| 18287 |
l.radius = l.y, delete l.y; |
| 18288 |
return l; |
| 18289 |
} |
| 18290 |
|
| 18291 |
const sqrt3$2 = sqrt(3); |
| 18292 |
|
| 18293 |
var asterisk = { |
| 18294 |
draw(context, size) { |
| 18295 |
const r = sqrt(size + min(size / 28, 0.75)) * 0.59436; |
| 18296 |
const t = r / 2; |
| 18297 |
const u = t * sqrt3$2; |
| 18298 |
context.moveTo(0, r); |
| 18299 |
context.lineTo(0, -r); |
| 18300 |
context.moveTo(-u, -t); |
| 18301 |
context.lineTo(u, t); |
| 18302 |
context.moveTo(-u, t); |
| 18303 |
context.lineTo(u, -t); |
| 18304 |
} |
| 18305 |
}; |
| 18306 |
|
| 18307 |
var circle = { |
| 18308 |
draw(context, size) { |
| 18309 |
const r = sqrt(size / pi); |
| 18310 |
context.moveTo(r, 0); |
| 18311 |
context.arc(0, 0, r, 0, tau); |
| 18312 |
} |
| 18313 |
}; |
| 18314 |
|
| 18315 |
var cross = { |
| 18316 |
draw(context, size) { |
| 18317 |
const r = sqrt(size / 5) / 2; |
| 18318 |
context.moveTo(-3 * r, -r); |
| 18319 |
context.lineTo(-r, -r); |
| 18320 |
context.lineTo(-r, -3 * r); |
| 18321 |
context.lineTo(r, -3 * r); |
| 18322 |
context.lineTo(r, -r); |
| 18323 |
context.lineTo(3 * r, -r); |
| 18324 |
context.lineTo(3 * r, r); |
| 18325 |
context.lineTo(r, r); |
| 18326 |
context.lineTo(r, 3 * r); |
| 18327 |
context.lineTo(-r, 3 * r); |
| 18328 |
context.lineTo(-r, r); |
| 18329 |
context.lineTo(-3 * r, r); |
| 18330 |
context.closePath(); |
| 18331 |
} |
| 18332 |
}; |
| 18333 |
|
| 18334 |
const tan30 = sqrt(1 / 3); |
| 18335 |
const tan30_2 = tan30 * 2; |
| 18336 |
|
| 18337 |
var diamond = { |
| 18338 |
draw(context, size) { |
| 18339 |
const y = sqrt(size / tan30_2); |
| 18340 |
const x = y * tan30; |
| 18341 |
context.moveTo(0, -y); |
| 18342 |
context.lineTo(x, 0); |
| 18343 |
context.lineTo(0, y); |
| 18344 |
context.lineTo(-x, 0); |
| 18345 |
context.closePath(); |
| 18346 |
} |
| 18347 |
}; |
| 18348 |
|
| 18349 |
var diamond2 = { |
| 18350 |
draw(context, size) { |
| 18351 |
const r = sqrt(size) * 0.62625; |
| 18352 |
context.moveTo(0, -r); |
| 18353 |
context.lineTo(r, 0); |
| 18354 |
context.lineTo(0, r); |
| 18355 |
context.lineTo(-r, 0); |
| 18356 |
context.closePath(); |
| 18357 |
} |
| 18358 |
}; |
| 18359 |
|
| 18360 |
var plus = { |
| 18361 |
draw(context, size) { |
| 18362 |
const r = sqrt(size - min(size / 7, 2)) * 0.87559; |
| 18363 |
context.moveTo(-r, 0); |
| 18364 |
context.lineTo(r, 0); |
| 18365 |
context.moveTo(0, r); |
| 18366 |
context.lineTo(0, -r); |
| 18367 |
} |
| 18368 |
}; |
| 18369 |
|
| 18370 |
var square = { |
| 18371 |
draw(context, size) { |
| 18372 |
const w = sqrt(size); |
| 18373 |
const x = -w / 2; |
| 18374 |
context.rect(x, x, w, w); |
| 18375 |
} |
| 18376 |
}; |
| 18377 |
|
| 18378 |
var square2 = { |
| 18379 |
draw(context, size) { |
| 18380 |
const r = sqrt(size) * 0.4431; |
| 18381 |
context.moveTo(r, r); |
| 18382 |
context.lineTo(r, -r); |
| 18383 |
context.lineTo(-r, -r); |
| 18384 |
context.lineTo(-r, r); |
| 18385 |
context.closePath(); |
| 18386 |
} |
| 18387 |
}; |
| 18388 |
|
| 18389 |
const ka = 0.89081309152928522810; |
| 18390 |
const kr = sin(pi / 10) / sin(7 * pi / 10); |
| 18391 |
const kx = sin(tau / 10) * kr; |
| 18392 |
const ky = -cos(tau / 10) * kr; |
| 18393 |
|
| 18394 |
var star = { |
| 18395 |
draw(context, size) { |
| 18396 |
const r = sqrt(size * ka); |
| 18397 |
const x = kx * r; |
| 18398 |
const y = ky * r; |
| 18399 |
context.moveTo(0, -r); |
| 18400 |
context.lineTo(x, y); |
| 18401 |
for (let i = 1; i < 5; ++i) { |
| 18402 |
const a = tau * i / 5; |
| 18403 |
const c = cos(a); |
| 18404 |
const s = sin(a); |
| 18405 |
context.lineTo(s * r, -c * r); |
| 18406 |
context.lineTo(c * x - s * y, s * x + c * y); |
| 18407 |
} |
| 18408 |
context.closePath(); |
| 18409 |
} |
| 18410 |
}; |
| 18411 |
|
| 18412 |
const sqrt3$1 = sqrt(3); |
| 18413 |
|
| 18414 |
var triangle = { |
| 18415 |
draw(context, size) { |
| 18416 |
const y = -sqrt(size / (sqrt3$1 * 3)); |
| 18417 |
context.moveTo(0, y * 2); |
| 18418 |
context.lineTo(-sqrt3$1 * y, -y); |
| 18419 |
context.lineTo(sqrt3$1 * y, -y); |
| 18420 |
context.closePath(); |
| 18421 |
} |
| 18422 |
}; |
| 18423 |
|
| 18424 |
const sqrt3 = sqrt(3); |
| 18425 |
|
| 18426 |
var triangle2 = { |
| 18427 |
draw(context, size) { |
| 18428 |
const s = sqrt(size) * 0.6824; |
| 18429 |
const t = s / 2; |
| 18430 |
const u = (s * sqrt3) / 2; // cos(Math.PI / 6) |
| 18431 |
context.moveTo(0, -s); |
| 18432 |
context.lineTo(u, t); |
| 18433 |
context.lineTo(-u, t); |
| 18434 |
context.closePath(); |
| 18435 |
} |
| 18436 |
}; |
| 18437 |
|
| 18438 |
const c = -0.5; |
| 18439 |
const s = sqrt(3) / 2; |
| 18440 |
const k = 1 / sqrt(12); |
| 18441 |
const a = (k / 2 + 1) * 3; |
| 18442 |
|
| 18443 |
var wye = { |
| 18444 |
draw(context, size) { |
| 18445 |
const r = sqrt(size / a); |
| 18446 |
const x0 = r / 2, y0 = r * k; |
| 18447 |
const x1 = x0, y1 = r * k + r; |
| 18448 |
const x2 = -x1, y2 = y1; |
| 18449 |
context.moveTo(x0, y0); |
| 18450 |
context.lineTo(x1, y1); |
| 18451 |
context.lineTo(x2, y2); |
| 18452 |
context.lineTo(c * x0 - s * y0, s * x0 + c * y0); |
| 18453 |
context.lineTo(c * x1 - s * y1, s * x1 + c * y1); |
| 18454 |
context.lineTo(c * x2 - s * y2, s * x2 + c * y2); |
| 18455 |
context.lineTo(c * x0 + s * y0, c * y0 - s * x0); |
| 18456 |
context.lineTo(c * x1 + s * y1, c * y1 - s * x1); |
| 18457 |
context.lineTo(c * x2 + s * y2, c * y2 - s * x2); |
| 18458 |
context.closePath(); |
| 18459 |
} |
| 18460 |
}; |
| 18461 |
|
| 18462 |
var times = { |
| 18463 |
draw(context, size) { |
| 18464 |
const r = sqrt(size - min(size / 6, 1.7)) * 0.6189; |
| 18465 |
context.moveTo(-r, -r); |
| 18466 |
context.lineTo(r, r); |
| 18467 |
context.moveTo(-r, r); |
| 18468 |
context.lineTo(r, -r); |
| 18469 |
} |
| 18470 |
}; |
| 18471 |
|
| 18472 |
// These symbols are designed to be filled. |
| 18473 |
const symbolsFill = [ |
| 18474 |
circle, |
| 18475 |
cross, |
| 18476 |
diamond, |
| 18477 |
square, |
| 18478 |
star, |
| 18479 |
triangle, |
| 18480 |
wye |
| 18481 |
]; |
| 18482 |
|
| 18483 |
// These symbols are designed to be stroked (with a width of 1.5px and round caps). |
| 18484 |
const symbolsStroke = [ |
| 18485 |
circle, |
| 18486 |
plus, |
| 18487 |
times, |
| 18488 |
triangle2, |
| 18489 |
asterisk, |
| 18490 |
square2, |
| 18491 |
diamond2 |
| 18492 |
]; |
| 18493 |
|
| 18494 |
function Symbol$1(type, size) { |
| 18495 |
let context = null, |
| 18496 |
path = withPath(symbol); |
| 18497 |
|
| 18498 |
type = typeof type === "function" ? type : constant$1(type || circle); |
| 18499 |
size = typeof size === "function" ? size : constant$1(size === undefined ? 64 : +size); |
| 18500 |
|
| 18501 |
function symbol() { |
| 18502 |
let buffer; |
| 18503 |
if (!context) context = buffer = path(); |
| 18504 |
type.apply(this, arguments).draw(context, +size.apply(this, arguments)); |
| 18505 |
if (buffer) return context = null, buffer + "" || null; |
| 18506 |
} |
| 18507 |
|
| 18508 |
symbol.type = function(_) { |
| 18509 |
return arguments.length ? (type = typeof _ === "function" ? _ : constant$1(_), symbol) : type; |
| 18510 |
}; |
| 18511 |
|
| 18512 |
symbol.size = function(_) { |
| 18513 |
return arguments.length ? (size = typeof _ === "function" ? _ : constant$1(+_), symbol) : size; |
| 18514 |
}; |
| 18515 |
|
| 18516 |
symbol.context = function(_) { |
| 18517 |
return arguments.length ? (context = _ == null ? null : _, symbol) : context; |
| 18518 |
}; |
| 18519 |
|
| 18520 |
return symbol; |
| 18521 |
} |
| 18522 |
|
| 18523 |
function noop() {} |
| 18524 |
|
| 18525 |
function point$3(that, x, y) { |
| 18526 |
that._context.bezierCurveTo( |
| 18527 |
(2 * that._x0 + that._x1) / 3, |
| 18528 |
(2 * that._y0 + that._y1) / 3, |
| 18529 |
(that._x0 + 2 * that._x1) / 3, |
| 18530 |
(that._y0 + 2 * that._y1) / 3, |
| 18531 |
(that._x0 + 4 * that._x1 + x) / 6, |
| 18532 |
(that._y0 + 4 * that._y1 + y) / 6 |
| 18533 |
); |
| 18534 |
} |
| 18535 |
|
| 18536 |
function Basis(context) { |
| 18537 |
this._context = context; |
| 18538 |
} |
| 18539 |
|
| 18540 |
Basis.prototype = { |
| 18541 |
areaStart: function() { |
| 18542 |
this._line = 0; |
| 18543 |
}, |
| 18544 |
areaEnd: function() { |
| 18545 |
this._line = NaN; |
| 18546 |
}, |
| 18547 |
lineStart: function() { |
| 18548 |
this._x0 = this._x1 = |
| 18549 |
this._y0 = this._y1 = NaN; |
| 18550 |
this._point = 0; |
| 18551 |
}, |
| 18552 |
lineEnd: function() { |
| 18553 |
switch (this._point) { |
| 18554 |
case 3: point$3(this, this._x1, this._y1); // falls through |
| 18555 |
case 2: this._context.lineTo(this._x1, this._y1); break; |
| 18556 |
} |
| 18557 |
if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath(); |
| 18558 |
this._line = 1 - this._line; |
| 18559 |
}, |
| 18560 |
point: function(x, y) { |
| 18561 |
x = +x, y = +y; |
| 18562 |
switch (this._point) { |
| 18563 |
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break; |
| 18564 |
case 1: this._point = 2; break; |
| 18565 |
case 2: this._point = 3; this._context.lineTo((5 * this._x0 + this._x1) / 6, (5 * this._y0 + this._y1) / 6); // falls through |
| 18566 |
default: point$3(this, x, y); break; |
| 18567 |
} |
| 18568 |
this._x0 = this._x1, this._x1 = x; |
| 18569 |
this._y0 = this._y1, this._y1 = y; |
| 18570 |
} |
| 18571 |
}; |
| 18572 |
|
| 18573 |
function basis(context) { |
| 18574 |
return new Basis(context); |
| 18575 |
} |
| 18576 |
|
| 18577 |
function BasisClosed(context) { |
| 18578 |
this._context = context; |
| 18579 |
} |
| 18580 |
|
| 18581 |
BasisClosed.prototype = { |
| 18582 |
areaStart: noop, |
| 18583 |
areaEnd: noop, |
| 18584 |
lineStart: function() { |
| 18585 |
this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = |
| 18586 |
this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = NaN; |
| 18587 |
this._point = 0; |
| 18588 |
}, |
| 18589 |
lineEnd: function() { |
| 18590 |
switch (this._point) { |
| 18591 |
case 1: { |
| 18592 |
this._context.moveTo(this._x2, this._y2); |
| 18593 |
this._context.closePath(); |
| 18594 |
break; |
| 18595 |
} |
| 18596 |
case 2: { |
| 18597 |
this._context.moveTo((this._x2 + 2 * this._x3) / 3, (this._y2 + 2 * this._y3) / 3); |
| 18598 |
this._context.lineTo((this._x3 + 2 * this._x2) / 3, (this._y3 + 2 * this._y2) / 3); |
| 18599 |
this._context.closePath(); |
| 18600 |
break; |
| 18601 |
} |
| 18602 |
case 3: { |
| 18603 |
this.point(this._x2, this._y2); |
| 18604 |
this.point(this._x3, this._y3); |
| 18605 |
this.point(this._x4, this._y4); |
| 18606 |
break; |
| 18607 |
} |
| 18608 |
} |
| 18609 |
}, |
| 18610 |
point: function(x, y) { |
| 18611 |
x = +x, y = +y; |
| 18612 |
switch (this._point) { |
| 18613 |
case 0: this._point = 1; this._x2 = x, this._y2 = y; break; |
| 18614 |
case 1: this._point = 2; this._x3 = x, this._y3 = y; break; |
| 18615 |
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; |
| 18616 |
default: point$3(this, x, y); break; |
| 18617 |
} |
| 18618 |
this._x0 = this._x1, this._x1 = x; |
| 18619 |
this._y0 = this._y1, this._y1 = y; |
| 18620 |
} |
| 18621 |
}; |
| 18622 |
|
| 18623 |
function basisClosed(context) { |
| 18624 |
return new BasisClosed(context); |
| 18625 |
} |
| 18626 |
|
| 18627 |
function BasisOpen(context) { |
| 18628 |
this._context = context; |
| 18629 |
} |
| 18630 |
|
| 18631 |
BasisOpen.prototype = { |
| 18632 |
areaStart: function() { |
| 18633 |
this._line = 0; |
| 18634 |
}, |
| 18635 |
areaEnd: function() { |
| 18636 |
this._line = NaN; |
| 18637 |
}, |
| 18638 |
lineStart: function() { |
| 18639 |
this._x0 = this._x1 = |
| 18640 |
this._y0 = this._y1 = NaN; |
| 18641 |
this._point = 0; |
| 18642 |
}, |
| 18643 |
lineEnd: function() { |
| 18644 |
if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath(); |
| 18645 |
this._line = 1 - this._line; |
| 18646 |
}, |
| 18647 |
point: function(x, y) { |
| 18648 |
x = +x, y = +y; |
| 18649 |
switch (this._point) { |
| 18650 |
case 0: this._point = 1; break; |
| 18651 |
case 1: this._point = 2; break; |
| 18652 |
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; |
| 18653 |
case 3: this._point = 4; // falls through |
| 18654 |
default: point$3(this, x, y); break; |
| 18655 |
} |
| 18656 |
this._x0 = this._x1, this._x1 = x; |
| 18657 |
this._y0 = this._y1, this._y1 = y; |
| 18658 |
} |
| 18659 |
}; |
| 18660 |
|
| 18661 |
function basisOpen(context) { |
| 18662 |
return new BasisOpen(context); |
| 18663 |
} |
| 18664 |
|
| 18665 |
function Bundle(context, beta) { |
| 18666 |
this._basis = new Basis(context); |
| 18667 |
this._beta = beta; |
| 18668 |
} |
| 18669 |
|
| 18670 |
Bundle.prototype = { |
| 18671 |
lineStart: function() { |
| 18672 |
this._x = []; |
| 18673 |
this._y = []; |
| 18674 |
this._basis.lineStart(); |
| 18675 |
}, |
| 18676 |
lineEnd: function() { |
| 18677 |
var x = this._x, |
| 18678 |
y = this._y, |
| 18679 |
j = x.length - 1; |
| 18680 |
|
| 18681 |
if (j > 0) { |
| 18682 |
var x0 = x[0], |
| 18683 |
y0 = y[0], |
| 18684 |
dx = x[j] - x0, |
| 18685 |
dy = y[j] - y0, |
| 18686 |
i = -1, |
| 18687 |
t; |
| 18688 |
|
| 18689 |
while (++i <= j) { |
| 18690 |
t = i / j; |
| 18691 |
this._basis.point( |
| 18692 |
this._beta * x[i] + (1 - this._beta) * (x0 + t * dx), |
| 18693 |
this._beta * y[i] + (1 - this._beta) * (y0 + t * dy) |
| 18694 |
); |
| 18695 |
} |
| 18696 |
} |
| 18697 |
|
| 18698 |
this._x = this._y = null; |
| 18699 |
this._basis.lineEnd(); |
| 18700 |
}, |
| 18701 |
point: function(x, y) { |
| 18702 |
this._x.push(+x); |
| 18703 |
this._y.push(+y); |
| 18704 |
} |
| 18705 |
}; |
| 18706 |
|
| 18707 |
var bundle = (function custom(beta) { |
| 18708 |
|
| 18709 |
function bundle(context) { |
| 18710 |
return beta === 1 ? new Basis(context) : new Bundle(context, beta); |
| 18711 |
} |
| 18712 |
|
| 18713 |
bundle.beta = function(beta) { |
| 18714 |
return custom(+beta); |
| 18715 |
}; |
| 18716 |
|
| 18717 |
return bundle; |
| 18718 |
})(0.85); |
| 18719 |
|
| 18720 |
function point$2(that, x, y) { |
| 18721 |
that._context.bezierCurveTo( |
| 18722 |
that._x1 + that._k * (that._x2 - that._x0), |
| 18723 |
that._y1 + that._k * (that._y2 - that._y0), |
| 18724 |
that._x2 + that._k * (that._x1 - x), |
| 18725 |
that._y2 + that._k * (that._y1 - y), |
| 18726 |
that._x2, |
| 18727 |
that._y2 |
| 18728 |
); |
| 18729 |
} |
| 18730 |
|
| 18731 |
function Cardinal(context, tension) { |
| 18732 |
this._context = context; |
| 18733 |
this._k = (1 - tension) / 6; |
| 18734 |
} |
| 18735 |
|
| 18736 |
Cardinal.prototype = { |
| 18737 |
areaStart: function() { |
| 18738 |
this._line = 0; |
| 18739 |
}, |
| 18740 |
areaEnd: function() { |
| 18741 |
this._line = NaN; |
| 18742 |
}, |
| 18743 |
lineStart: function() { |
| 18744 |
this._x0 = this._x1 = this._x2 = |
| 18745 |
this._y0 = this._y1 = this._y2 = NaN; |
| 18746 |
this._point = 0; |
| 18747 |
}, |
| 18748 |
lineEnd: function() { |
| 18749 |
switch (this._point) { |
| 18750 |
case 2: this._context.lineTo(this._x2, this._y2); break; |
| 18751 |
case 3: point$2(this, this._x1, this._y1); break; |
| 18752 |
} |
| 18753 |
if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath(); |
| 18754 |
this._line = 1 - this._line; |
| 18755 |
}, |
| 18756 |
point: function(x, y) { |
| 18757 |
x = +x, y = +y; |
| 18758 |
switch (this._point) { |
| 18759 |
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break; |
| 18760 |
case 1: this._point = 2; this._x1 = x, this._y1 = y; break; |
| 18761 |
case 2: this._point = 3; // falls through |
| 18762 |
default: point$2(this, x, y); break; |
| 18763 |
} |
| 18764 |
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x; |
| 18765 |
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y; |
| 18766 |
} |
| 18767 |
}; |
| 18768 |
|
| 18769 |
var cardinal = (function custom(tension) { |
| 18770 |
|
| 18771 |
function cardinal(context) { |
| 18772 |
return new Cardinal(context, tension); |
| 18773 |
} |
| 18774 |
|
| 18775 |
cardinal.tension = function(tension) { |
| 18776 |
return custom(+tension); |
| 18777 |
}; |
| 18778 |
|
| 18779 |
return cardinal; |
| 18780 |
})(0); |
| 18781 |
|
| 18782 |
function CardinalClosed(context, tension) { |
| 18783 |
this._context = context; |
| 18784 |
this._k = (1 - tension) / 6; |
| 18785 |
} |
| 18786 |
|
| 18787 |
CardinalClosed.prototype = { |
| 18788 |
areaStart: noop, |
| 18789 |
areaEnd: noop, |
| 18790 |
lineStart: function() { |
| 18791 |
this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 = |
| 18792 |
this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN; |
| 18793 |
this._point = 0; |
| 18794 |
}, |
| 18795 |
lineEnd: function() { |
| 18796 |
switch (this._point) { |
| 18797 |
case 1: { |
| 18798 |
this._context.moveTo(this._x3, this._y3); |
| 18799 |
this._context.closePath(); |
| 18800 |
break; |
| 18801 |
} |
| 18802 |
case 2: { |
| 18803 |
this._context.lineTo(this._x3, this._y3); |
| 18804 |
this._context.closePath(); |
| 18805 |
break; |
| 18806 |
} |
| 18807 |
case 3: { |
| 18808 |
this.point(this._x3, this._y3); |
| 18809 |
this.point(this._x4, this._y4); |
| 18810 |
this.point(this._x5, this._y5); |
| 18811 |
break; |
| 18812 |
} |
| 18813 |
} |
| 18814 |
}, |
| 18815 |
point: function(x, y) { |
| 18816 |
x = +x, y = +y; |
| 18817 |
switch (this._point) { |
| 18818 |
case 0: this._point = 1; this._x3 = x, this._y3 = y; break; |
| 18819 |
case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break; |
| 18820 |
case 2: this._point = 3; this._x5 = x, this._y5 = y; break; |
| 18821 |
default: point$2(this, x, y); break; |
| 18822 |
} |
| 18823 |
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x; |
| 18824 |
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y; |
| 18825 |
} |
| 18826 |
}; |
| 18827 |
|
| 18828 |
var cardinalClosed = (function custom(tension) { |
| 18829 |
|
| 18830 |
function cardinal(context) { |
| 18831 |
return new CardinalClosed(context, tension); |
| 18832 |
} |
| 18833 |
|
| 18834 |
cardinal.tension = function(tension) { |
| 18835 |
return custom(+tension); |
| 18836 |
}; |
| 18837 |
|
| 18838 |
return cardinal; |
| 18839 |
})(0); |
| 18840 |
|
| 18841 |
function CardinalOpen(context, tension) { |
| 18842 |
this._context = context; |
| 18843 |
this._k = (1 - tension) / 6; |
| 18844 |
} |
| 18845 |
|
| 18846 |
CardinalOpen.prototype = { |
| 18847 |
areaStart: function() { |
| 18848 |
this._line = 0; |
| 18849 |
}, |
| 18850 |
areaEnd: function() { |
| 18851 |
this._line = NaN; |
| 18852 |
}, |
| 18853 |
lineStart: function() { |
| 18854 |
this._x0 = this._x1 = this._x2 = |
| 18855 |
this._y0 = this._y1 = this._y2 = NaN; |
| 18856 |
this._point = 0; |
| 18857 |
}, |
| 18858 |
lineEnd: function() { |
| 18859 |
if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath(); |
| 18860 |
this._line = 1 - this._line; |
| 18861 |
}, |
| 18862 |
point: function(x, y) { |
| 18863 |
x = +x, y = +y; |
| 18864 |
switch (this._point) { |
| 18865 |
case 0: this._point = 1; break; |
| 18866 |
case 1: this._point = 2; break; |
| 18867 |
case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break; |
| 18868 |
case 3: this._point = 4; // falls through |
| 18869 |
default: point$2(this, x, y); break; |
| 18870 |
} |
| 18871 |
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x; |
| 18872 |
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y; |
| 18873 |
} |
| 18874 |
}; |
| 18875 |
|
| 18876 |
var cardinalOpen = (function custom(tension) { |
| 18877 |
|
| 18878 |
function cardinal(context) { |
| 18879 |
return new CardinalOpen(context, tension); |
| 18880 |
} |
| 18881 |
|
| 18882 |
cardinal.tension = function(tension) { |
| 18883 |
return custom(+tension); |
| 18884 |
}; |
| 18885 |
|
| 18886 |
return cardinal; |
| 18887 |
})(0); |
| 18888 |
|
| 18889 |
function point$1(that, x, y) { |
| 18890 |
var x1 = that._x1, |
| 18891 |
y1 = that._y1, |
| 18892 |
x2 = that._x2, |
| 18893 |
y2 = that._y2; |
| 18894 |
|
| 18895 |
if (that._l01_a > epsilon) { |
| 18896 |
var a = 2 * that._l01_2a + 3 * that._l01_a * that._l12_a + that._l12_2a, |
| 18897 |
n = 3 * that._l01_a * (that._l01_a + that._l12_a); |
| 18898 |
x1 = (x1 * a - that._x0 * that._l12_2a + that._x2 * that._l01_2a) / n; |
| 18899 |
y1 = (y1 * a - that._y0 * that._l12_2a + that._y2 * that._l01_2a) / n; |
| 18900 |
} |
| 18901 |
|
| 18902 |
if (that._l23_a > epsilon) { |
| 18903 |
var b = 2 * that._l23_2a + 3 * that._l23_a * that._l12_a + that._l12_2a, |
| 18904 |
m = 3 * that._l23_a * (that._l23_a + that._l12_a); |
| 18905 |
x2 = (x2 * b + that._x1 * that._l23_2a - x * that._l12_2a) / m; |
| 18906 |
y2 = (y2 * b + that._y1 * that._l23_2a - y * that._l12_2a) / m; |
| 18907 |
} |
| 18908 |
|
| 18909 |
that._context.bezierCurveTo(x1, y1, x2, y2, that._x2, that._y2); |
| 18910 |
} |
| 18911 |
|
| 18912 |
function CatmullRom(context, alpha) { |
| 18913 |
this._context = context; |
| 18914 |
this._alpha = alpha; |
| 18915 |
} |
| 18916 |
|
| 18917 |
CatmullRom.prototype = { |
| 18918 |
areaStart: function() { |
| 18919 |
this._line = 0; |
| 18920 |
}, |
| 18921 |
areaEnd: function() { |
| 18922 |
this._line = NaN; |
| 18923 |
}, |
| 18924 |
lineStart: function() { |
| 18925 |
this._x0 = this._x1 = this._x2 = |
| 18926 |
this._y0 = this._y1 = this._y2 = NaN; |
| 18927 |
this._l01_a = this._l12_a = this._l23_a = |
| 18928 |
this._l01_2a = this._l12_2a = this._l23_2a = |
| 18929 |
this._point = 0; |
| 18930 |
}, |
| 18931 |
lineEnd: function() { |
| 18932 |
switch (this._point) { |
| 18933 |
case 2: this._context.lineTo(this._x2, this._y2); break; |
| 18934 |
case 3: this.point(this._x2, this._y2); break; |
| 18935 |
} |
| 18936 |
if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath(); |
| 18937 |
this._line = 1 - this._line; |
| 18938 |
}, |
| 18939 |
point: function(x, y) { |
| 18940 |
x = +x, y = +y; |
| 18941 |
|
| 18942 |
if (this._point) { |
| 18943 |
var x23 = this._x2 - x, |
| 18944 |
y23 = this._y2 - y; |
| 18945 |
this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha)); |
| 18946 |
} |
| 18947 |
|
| 18948 |
switch (this._point) { |
| 18949 |
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break; |
| 18950 |
case 1: this._point = 2; break; |
| 18951 |
case 2: this._point = 3; // falls through |
| 18952 |
default: point$1(this, x, y); break; |
| 18953 |
} |
| 18954 |
|
| 18955 |
this._l01_a = this._l12_a, this._l12_a = this._l23_a; |
| 18956 |
this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a; |
| 18957 |
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x; |
| 18958 |
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y; |
| 18959 |
} |
| 18960 |
}; |
| 18961 |
|
| 18962 |
var catmullRom = (function custom(alpha) { |
| 18963 |
|
| 18964 |
function catmullRom(context) { |
| 18965 |
return alpha ? new CatmullRom(context, alpha) : new Cardinal(context, 0); |
| 18966 |
} |
| 18967 |
|
| 18968 |
catmullRom.alpha = function(alpha) { |
| 18969 |
return custom(+alpha); |
| 18970 |
}; |
| 18971 |
|
| 18972 |
return catmullRom; |
| 18973 |
})(0.5); |
| 18974 |
|
| 18975 |
function CatmullRomClosed(context, alpha) { |
| 18976 |
this._context = context; |
| 18977 |
this._alpha = alpha; |
| 18978 |
} |
| 18979 |
|
| 18980 |
CatmullRomClosed.prototype = { |
| 18981 |
areaStart: noop, |
| 18982 |
areaEnd: noop, |
| 18983 |
lineStart: function() { |
| 18984 |
this._x0 = this._x1 = this._x2 = this._x3 = this._x4 = this._x5 = |
| 18985 |
this._y0 = this._y1 = this._y2 = this._y3 = this._y4 = this._y5 = NaN; |
| 18986 |
this._l01_a = this._l12_a = this._l23_a = |
| 18987 |
this._l01_2a = this._l12_2a = this._l23_2a = |
| 18988 |
this._point = 0; |
| 18989 |
}, |
| 18990 |
lineEnd: function() { |
| 18991 |
switch (this._point) { |
| 18992 |
case 1: { |
| 18993 |
this._context.moveTo(this._x3, this._y3); |
| 18994 |
this._context.closePath(); |
| 18995 |
break; |
| 18996 |
} |
| 18997 |
case 2: { |
| 18998 |
this._context.lineTo(this._x3, this._y3); |
| 18999 |
this._context.closePath(); |
| 19000 |
break; |
| 19001 |
} |
| 19002 |
case 3: { |
| 19003 |
this.point(this._x3, this._y3); |
| 19004 |
this.point(this._x4, this._y4); |
| 19005 |
this.point(this._x5, this._y5); |
| 19006 |
break; |
| 19007 |
} |
| 19008 |
} |
| 19009 |
}, |
| 19010 |
point: function(x, y) { |
| 19011 |
x = +x, y = +y; |
| 19012 |
|
| 19013 |
if (this._point) { |
| 19014 |
var x23 = this._x2 - x, |
| 19015 |
y23 = this._y2 - y; |
| 19016 |
this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha)); |
| 19017 |
} |
| 19018 |
|
| 19019 |
switch (this._point) { |
| 19020 |
case 0: this._point = 1; this._x3 = x, this._y3 = y; break; |
| 19021 |
case 1: this._point = 2; this._context.moveTo(this._x4 = x, this._y4 = y); break; |
| 19022 |
case 2: this._point = 3; this._x5 = x, this._y5 = y; break; |
| 19023 |
default: point$1(this, x, y); break; |
| 19024 |
} |
| 19025 |
|
| 19026 |
this._l01_a = this._l12_a, this._l12_a = this._l23_a; |
| 19027 |
this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a; |
| 19028 |
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x; |
| 19029 |
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y; |
| 19030 |
} |
| 19031 |
}; |
| 19032 |
|
| 19033 |
var catmullRomClosed = (function custom(alpha) { |
| 19034 |
|
| 19035 |
function catmullRom(context) { |
| 19036 |
return alpha ? new CatmullRomClosed(context, alpha) : new CardinalClosed(context, 0); |
| 19037 |
} |
| 19038 |
|
| 19039 |
catmullRom.alpha = function(alpha) { |
| 19040 |
return custom(+alpha); |
| 19041 |
}; |
| 19042 |
|
| 19043 |
return catmullRom; |
| 19044 |
})(0.5); |
| 19045 |
|
| 19046 |
function CatmullRomOpen(context, alpha) { |
| 19047 |
this._context = context; |
| 19048 |
this._alpha = alpha; |
| 19049 |
} |
| 19050 |
|
| 19051 |
CatmullRomOpen.prototype = { |
| 19052 |
areaStart: function() { |
| 19053 |
this._line = 0; |
| 19054 |
}, |
| 19055 |
areaEnd: function() { |
| 19056 |
this._line = NaN; |
| 19057 |
}, |
| 19058 |
lineStart: function() { |
| 19059 |
this._x0 = this._x1 = this._x2 = |
| 19060 |
this._y0 = this._y1 = this._y2 = NaN; |
| 19061 |
this._l01_a = this._l12_a = this._l23_a = |
| 19062 |
this._l01_2a = this._l12_2a = this._l23_2a = |
| 19063 |
this._point = 0; |
| 19064 |
}, |
| 19065 |
lineEnd: function() { |
| 19066 |
if (this._line || (this._line !== 0 && this._point === 3)) this._context.closePath(); |
| 19067 |
this._line = 1 - this._line; |
| 19068 |
}, |
| 19069 |
point: function(x, y) { |
| 19070 |
x = +x, y = +y; |
| 19071 |
|
| 19072 |
if (this._point) { |
| 19073 |
var x23 = this._x2 - x, |
| 19074 |
y23 = this._y2 - y; |
| 19075 |
this._l23_a = Math.sqrt(this._l23_2a = Math.pow(x23 * x23 + y23 * y23, this._alpha)); |
| 19076 |
} |
| 19077 |
|
| 19078 |
switch (this._point) { |
| 19079 |
case 0: this._point = 1; break; |
| 19080 |
case 1: this._point = 2; break; |
| 19081 |
case 2: this._point = 3; this._line ? this._context.lineTo(this._x2, this._y2) : this._context.moveTo(this._x2, this._y2); break; |
| 19082 |
case 3: this._point = 4; // falls through |
| 19083 |
default: point$1(this, x, y); break; |
| 19084 |
} |
| 19085 |
|
| 19086 |
this._l01_a = this._l12_a, this._l12_a = this._l23_a; |
| 19087 |
this._l01_2a = this._l12_2a, this._l12_2a = this._l23_2a; |
| 19088 |
this._x0 = this._x1, this._x1 = this._x2, this._x2 = x; |
| 19089 |
this._y0 = this._y1, this._y1 = this._y2, this._y2 = y; |
| 19090 |
} |
| 19091 |
}; |
| 19092 |
|
| 19093 |
var catmullRomOpen = (function custom(alpha) { |
| 19094 |
|
| 19095 |
function catmullRom(context) { |
| 19096 |
return alpha ? new CatmullRomOpen(context, alpha) : new CardinalOpen(context, 0); |
| 19097 |
} |
| 19098 |
|
| 19099 |
catmullRom.alpha = function(alpha) { |
| 19100 |
return custom(+alpha); |
| 19101 |
}; |
| 19102 |
|
| 19103 |
return catmullRom; |
| 19104 |
})(0.5); |
| 19105 |
|
| 19106 |
function LinearClosed(context) { |
| 19107 |
this._context = context; |
| 19108 |
} |
| 19109 |
|
| 19110 |
LinearClosed.prototype = { |
| 19111 |
areaStart: noop, |
| 19112 |
areaEnd: noop, |
| 19113 |
lineStart: function() { |
| 19114 |
this._point = 0; |
| 19115 |
}, |
| 19116 |
lineEnd: function() { |
| 19117 |
if (this._point) this._context.closePath(); |
| 19118 |
}, |
| 19119 |
point: function(x, y) { |
| 19120 |
x = +x, y = +y; |
| 19121 |
if (this._point) this._context.lineTo(x, y); |
| 19122 |
else this._point = 1, this._context.moveTo(x, y); |
| 19123 |
} |
| 19124 |
}; |
| 19125 |
|
| 19126 |
function linearClosed(context) { |
| 19127 |
return new LinearClosed(context); |
| 19128 |
} |
| 19129 |
|
| 19130 |
function sign(x) { |
| 19131 |
return x < 0 ? -1 : 1; |
| 19132 |
} |
| 19133 |
|
| 19134 |
// Calculate the slopes of the tangents (Hermite-type interpolation) based on |
| 19135 |
// the following paper: Steffen, M. 1990. A Simple Method for Monotonic |
| 19136 |
// Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO. |
| 19137 |
// NOV(II), P. 443, 1990. |
| 19138 |
function slope3(that, x2, y2) { |
| 19139 |
var h0 = that._x1 - that._x0, |
| 19140 |
h1 = x2 - that._x1, |
| 19141 |
s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0), |
| 19142 |
s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0), |
| 19143 |
p = (s0 * h1 + s1 * h0) / (h0 + h1); |
| 19144 |
return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0; |
| 19145 |
} |
| 19146 |
|
| 19147 |
// Calculate a one-sided slope. |
| 19148 |
function slope2(that, t) { |
| 19149 |
var h = that._x1 - that._x0; |
| 19150 |
return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t; |
| 19151 |
} |
| 19152 |
|
| 19153 |
// According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations |
| 19154 |
// "you can express cubic Hermite interpolation in terms of cubic Bézier curves |
| 19155 |
// with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1". |
| 19156 |
function point(that, t0, t1) { |
| 19157 |
var x0 = that._x0, |
| 19158 |
y0 = that._y0, |
| 19159 |
x1 = that._x1, |
| 19160 |
y1 = that._y1, |
| 19161 |
dx = (x1 - x0) / 3; |
| 19162 |
that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1); |
| 19163 |
} |
| 19164 |
|
| 19165 |
function MonotoneX(context) { |
| 19166 |
this._context = context; |
| 19167 |
} |
| 19168 |
|
| 19169 |
MonotoneX.prototype = { |
| 19170 |
areaStart: function() { |
| 19171 |
this._line = 0; |
| 19172 |
}, |
| 19173 |
areaEnd: function() { |
| 19174 |
this._line = NaN; |
| 19175 |
}, |
| 19176 |
lineStart: function() { |
| 19177 |
this._x0 = this._x1 = |
| 19178 |
this._y0 = this._y1 = |
| 19179 |
this._t0 = NaN; |
| 19180 |
this._point = 0; |
| 19181 |
}, |
| 19182 |
lineEnd: function() { |
| 19183 |
switch (this._point) { |
| 19184 |
case 2: this._context.lineTo(this._x1, this._y1); break; |
| 19185 |
case 3: point(this, this._t0, slope2(this, this._t0)); break; |
| 19186 |
} |
| 19187 |
if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath(); |
| 19188 |
this._line = 1 - this._line; |
| 19189 |
}, |
| 19190 |
point: function(x, y) { |
| 19191 |
var t1 = NaN; |
| 19192 |
|
| 19193 |
x = +x, y = +y; |
| 19194 |
if (x === this._x1 && y === this._y1) return; // Ignore coincident points. |
| 19195 |
switch (this._point) { |
| 19196 |
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break; |
| 19197 |
case 1: this._point = 2; break; |
| 19198 |
case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break; |
| 19199 |
default: point(this, this._t0, t1 = slope3(this, x, y)); break; |
| 19200 |
} |
| 19201 |
|
| 19202 |
this._x0 = this._x1, this._x1 = x; |
| 19203 |
this._y0 = this._y1, this._y1 = y; |
| 19204 |
this._t0 = t1; |
| 19205 |
} |
| 19206 |
}; |
| 19207 |
|
| 19208 |
function MonotoneY(context) { |
| 19209 |
this._context = new ReflectContext(context); |
| 19210 |
} |
| 19211 |
|
| 19212 |
(MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) { |
| 19213 |
MonotoneX.prototype.point.call(this, y, x); |
| 19214 |
}; |
| 19215 |
|
| 19216 |
function ReflectContext(context) { |
| 19217 |
this._context = context; |
| 19218 |
} |
| 19219 |
|
| 19220 |
ReflectContext.prototype = { |
| 19221 |
moveTo: function(x, y) { this._context.moveTo(y, x); }, |
| 19222 |
closePath: function() { this._context.closePath(); }, |
| 19223 |
lineTo: function(x, y) { this._context.lineTo(y, x); }, |
| 19224 |
bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); } |
| 19225 |
}; |
| 19226 |
|
| 19227 |
function monotoneX(context) { |
| 19228 |
return new MonotoneX(context); |
| 19229 |
} |
| 19230 |
|
| 19231 |
function monotoneY(context) { |
| 19232 |
return new MonotoneY(context); |
| 19233 |
} |
| 19234 |
|
| 19235 |
function Natural(context) { |
| 19236 |
this._context = context; |
| 19237 |
} |
| 19238 |
|
| 19239 |
Natural.prototype = { |
| 19240 |
areaStart: function() { |
| 19241 |
this._line = 0; |
| 19242 |
}, |
| 19243 |
areaEnd: function() { |
| 19244 |
this._line = NaN; |
| 19245 |
}, |
| 19246 |
lineStart: function() { |
| 19247 |
this._x = []; |
| 19248 |
this._y = []; |
| 19249 |
}, |
| 19250 |
lineEnd: function() { |
| 19251 |
var x = this._x, |
| 19252 |
y = this._y, |
| 19253 |
n = x.length; |
| 19254 |
|
| 19255 |
if (n) { |
| 19256 |
this._line ? this._context.lineTo(x[0], y[0]) : this._context.moveTo(x[0], y[0]); |
| 19257 |
if (n === 2) { |
| 19258 |
this._context.lineTo(x[1], y[1]); |
| 19259 |
} else { |
| 19260 |
var px = controlPoints(x), |
| 19261 |
py = controlPoints(y); |
| 19262 |
for (var i0 = 0, i1 = 1; i1 < n; ++i0, ++i1) { |
| 19263 |
this._context.bezierCurveTo(px[0][i0], py[0][i0], px[1][i0], py[1][i0], x[i1], y[i1]); |
| 19264 |
} |
| 19265 |
} |
| 19266 |
} |
| 19267 |
|
| 19268 |
if (this._line || (this._line !== 0 && n === 1)) this._context.closePath(); |
| 19269 |
this._line = 1 - this._line; |
| 19270 |
this._x = this._y = null; |
| 19271 |
}, |
| 19272 |
point: function(x, y) { |
| 19273 |
this._x.push(+x); |
| 19274 |
this._y.push(+y); |
| 19275 |
} |
| 19276 |
}; |
| 19277 |
|
| 19278 |
// See https://www.particleincell.com/2012/bezier-splines/ for derivation. |
| 19279 |
function controlPoints(x) { |
| 19280 |
var i, |
| 19281 |
n = x.length - 1, |
| 19282 |
m, |
| 19283 |
a = new Array(n), |
| 19284 |
b = new Array(n), |
| 19285 |
r = new Array(n); |
| 19286 |
a[0] = 0, b[0] = 2, r[0] = x[0] + 2 * x[1]; |
| 19287 |
for (i = 1; i < n - 1; ++i) a[i] = 1, b[i] = 4, r[i] = 4 * x[i] + 2 * x[i + 1]; |
| 19288 |
a[n - 1] = 2, b[n - 1] = 7, r[n - 1] = 8 * x[n - 1] + x[n]; |
| 19289 |
for (i = 1; i < n; ++i) m = a[i] / b[i - 1], b[i] -= m, r[i] -= m * r[i - 1]; |
| 19290 |
a[n - 1] = r[n - 1] / b[n - 1]; |
| 19291 |
for (i = n - 2; i >= 0; --i) a[i] = (r[i] - a[i + 1]) / b[i]; |
| 19292 |
b[n - 1] = (x[n] + a[n - 1]) / 2; |
| 19293 |
for (i = 0; i < n - 1; ++i) b[i] = 2 * x[i + 1] - a[i + 1]; |
| 19294 |
return [a, b]; |
| 19295 |
} |
| 19296 |
|
| 19297 |
function natural(context) { |
| 19298 |
return new Natural(context); |
| 19299 |
} |
| 19300 |
|
| 19301 |
function Step(context, t) { |
| 19302 |
this._context = context; |
| 19303 |
this._t = t; |
| 19304 |
} |
| 19305 |
|
| 19306 |
Step.prototype = { |
| 19307 |
areaStart: function() { |
| 19308 |
this._line = 0; |
| 19309 |
}, |
| 19310 |
areaEnd: function() { |
| 19311 |
this._line = NaN; |
| 19312 |
}, |
| 19313 |
lineStart: function() { |
| 19314 |
this._x = this._y = NaN; |
| 19315 |
this._point = 0; |
| 19316 |
}, |
| 19317 |
lineEnd: function() { |
| 19318 |
if (0 < this._t && this._t < 1 && this._point === 2) this._context.lineTo(this._x, this._y); |
| 19319 |
if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath(); |
| 19320 |
if (this._line >= 0) this._t = 1 - this._t, this._line = 1 - this._line; |
| 19321 |
}, |
| 19322 |
point: function(x, y) { |
| 19323 |
x = +x, y = +y; |
| 19324 |
switch (this._point) { |
| 19325 |
case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break; |
| 19326 |
case 1: this._point = 2; // falls through |
| 19327 |
default: { |
| 19328 |
if (this._t <= 0) { |
| 19329 |
this._context.lineTo(this._x, y); |
| 19330 |
this._context.lineTo(x, y); |
| 19331 |
} else { |
| 19332 |
var x1 = this._x * (1 - this._t) + x * this._t; |
| 19333 |
this._context.lineTo(x1, this._y); |
| 19334 |
this._context.lineTo(x1, y); |
| 19335 |
} |
| 19336 |
break; |
| 19337 |
} |
| 19338 |
} |
| 19339 |
this._x = x, this._y = y; |
| 19340 |
} |
| 19341 |
}; |
| 19342 |
|
| 19343 |
function step(context) { |
| 19344 |
return new Step(context, 0.5); |
| 19345 |
} |
| 19346 |
|
| 19347 |
function stepBefore(context) { |
| 19348 |
return new Step(context, 0); |
| 19349 |
} |
| 19350 |
|
| 19351 |
function stepAfter(context) { |
| 19352 |
return new Step(context, 1); |
| 19353 |
} |
| 19354 |
|
| 19355 |
function none$1(series, order) { |
| 19356 |
if (!((n = series.length) > 1)) return; |
| 19357 |
for (var i = 1, j, s0, s1 = series[order[0]], n, m = s1.length; i < n; ++i) { |
| 19358 |
s0 = s1, s1 = series[order[i]]; |
| 19359 |
for (j = 0; j < m; ++j) { |
| 19360 |
s1[j][1] += s1[j][0] = isNaN(s0[j][1]) ? s0[j][0] : s0[j][1]; |
| 19361 |
} |
| 19362 |
} |
| 19363 |
} |
| 19364 |
|
| 19365 |
function none(series) { |
| 19366 |
var n = series.length, o = new Array(n); |
| 19367 |
while (--n >= 0) o[n] = n; |
| 19368 |
return o; |
| 19369 |
} |
| 19370 |
|
| 19371 |
function stackValue(d, key) { |
| 19372 |
return d[key]; |
| 19373 |
} |
| 19374 |
|
| 19375 |
function stackSeries(key) { |
| 19376 |
const series = []; |
| 19377 |
series.key = key; |
| 19378 |
return series; |
| 19379 |
} |
| 19380 |
|
| 19381 |
function stack() { |
| 19382 |
var keys = constant$1([]), |
| 19383 |
order = none, |
| 19384 |
offset = none$1, |
| 19385 |
value = stackValue; |
| 19386 |
|
| 19387 |
function stack(data) { |
| 19388 |
var sz = Array.from(keys.apply(this, arguments), stackSeries), |
| 19389 |
i, n = sz.length, j = -1, |
| 19390 |
oz; |
| 19391 |
|
| 19392 |
for (const d of data) { |
| 19393 |
for (i = 0, ++j; i < n; ++i) { |
| 19394 |
(sz[i][j] = [0, +value(d, sz[i].key, j, data)]).data = d; |
| 19395 |
} |
| 19396 |
} |
| 19397 |
|
| 19398 |
for (i = 0, oz = array(order(sz)); i < n; ++i) { |
| 19399 |
sz[oz[i]].index = i; |
| 19400 |
} |
| 19401 |
|
| 19402 |
offset(sz, oz); |
| 19403 |
return sz; |
| 19404 |
} |
| 19405 |
|
| 19406 |
stack.keys = function(_) { |
| 19407 |
return arguments.length ? (keys = typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : keys; |
| 19408 |
}; |
| 19409 |
|
| 19410 |
stack.value = function(_) { |
| 19411 |
return arguments.length ? (value = typeof _ === "function" ? _ : constant$1(+_), stack) : value; |
| 19412 |
}; |
| 19413 |
|
| 19414 |
stack.order = function(_) { |
| 19415 |
return arguments.length ? (order = _ == null ? none : typeof _ === "function" ? _ : constant$1(Array.from(_)), stack) : order; |
| 19416 |
}; |
| 19417 |
|
| 19418 |
stack.offset = function(_) { |
| 19419 |
return arguments.length ? (offset = _ == null ? none$1 : _, stack) : offset; |
| 19420 |
}; |
| 19421 |
|
| 19422 |
return stack; |
| 19423 |
} |
| 19424 |
|
| 19425 |
function expand(series, order) { |
| 19426 |
if (!((n = series.length) > 0)) return; |
| 19427 |
for (var i, n, j = 0, m = series[0].length, y; j < m; ++j) { |
| 19428 |
for (y = i = 0; i < n; ++i) y += series[i][j][1] || 0; |
| 19429 |
if (y) for (i = 0; i < n; ++i) series[i][j][1] /= y; |
| 19430 |
} |
| 19431 |
none$1(series, order); |
| 19432 |
} |
| 19433 |
|
| 19434 |
function diverging(series, order) { |
| 19435 |
if (!((n = series.length) > 0)) return; |
| 19436 |
for (var i, j = 0, d, dy, yp, yn, n, m = series[order[0]].length; j < m; ++j) { |
| 19437 |
for (yp = yn = 0, i = 0; i < n; ++i) { |
| 19438 |
if ((dy = (d = series[order[i]][j])[1] - d[0]) > 0) { |
| 19439 |
d[0] = yp, d[1] = yp += dy; |
| 19440 |
} else if (dy < 0) { |
| 19441 |
d[1] = yn, d[0] = yn += dy; |
| 19442 |
} else { |
| 19443 |
d[0] = 0, d[1] = dy; |
| 19444 |
} |
| 19445 |
} |
| 19446 |
} |
| 19447 |
} |
| 19448 |
|
| 19449 |
function silhouette(series, order) { |
| 19450 |
if (!((n = series.length) > 0)) return; |
| 19451 |
for (var j = 0, s0 = series[order[0]], n, m = s0.length; j < m; ++j) { |
| 19452 |
for (var i = 0, y = 0; i < n; ++i) y += series[i][j][1] || 0; |
| 19453 |
s0[j][1] += s0[j][0] = -y / 2; |
| 19454 |
} |
| 19455 |
none$1(series, order); |
| 19456 |
} |
| 19457 |
|
| 19458 |
function wiggle(series, order) { |
| 19459 |
if (!((n = series.length) > 0) || !((m = (s0 = series[order[0]]).length) > 0)) return; |
| 19460 |
for (var y = 0, j = 1, s0, m, n; j < m; ++j) { |
| 19461 |
for (var i = 0, s1 = 0, s2 = 0; i < n; ++i) { |
| 19462 |
var si = series[order[i]], |
| 19463 |
sij0 = si[j][1] || 0, |
| 19464 |
sij1 = si[j - 1][1] || 0, |
| 19465 |
s3 = (sij0 - sij1) / 2; |
| 19466 |
for (var k = 0; k < i; ++k) { |
| 19467 |
var sk = series[order[k]], |
| 19468 |
skj0 = sk[j][1] || 0, |
| 19469 |
skj1 = sk[j - 1][1] || 0; |
| 19470 |
s3 += skj0 - skj1; |
| 19471 |
} |
| 19472 |
s1 += sij0, s2 += s3 * sij0; |
| 19473 |
} |
| 19474 |
s0[j - 1][1] += s0[j - 1][0] = y; |
| 19475 |
if (s1) y -= s2 / s1; |
| 19476 |
} |
| 19477 |
s0[j - 1][1] += s0[j - 1][0] = y; |
| 19478 |
none$1(series, order); |
| 19479 |
} |
| 19480 |
|
| 19481 |
function appearance(series) { |
| 19482 |
var peaks = series.map(peak); |
| 19483 |
return none(series).sort(function(a, b) { return peaks[a] - peaks[b]; }); |
| 19484 |
} |
| 19485 |
|
| 19486 |
function peak(series) { |
| 19487 |
var i = -1, j = 0, n = series.length, vi, vj = -Infinity; |
| 19488 |
while (++i < n) if ((vi = +series[i][1]) > vj) vj = vi, j = i; |
| 19489 |
return j; |
| 19490 |
} |
| 19491 |
|
| 19492 |
function ascending(series) { |
| 19493 |
var sums = series.map(sum); |
| 19494 |
return none(series).sort(function(a, b) { return sums[a] - sums[b]; }); |
| 19495 |
} |
| 19496 |
|
| 19497 |
function sum(series) { |
| 19498 |
var s = 0, i = -1, n = series.length, v; |
| 19499 |
while (++i < n) if (v = +series[i][1]) s += v; |
| 19500 |
return s; |
| 19501 |
} |
| 19502 |
|
| 19503 |
function descending(series) { |
| 19504 |
return ascending(series).reverse(); |
| 19505 |
} |
| 19506 |
|
| 19507 |
function insideOut(series) { |
| 19508 |
var n = series.length, |
| 19509 |
i, |
| 19510 |
j, |
| 19511 |
sums = series.map(sum), |
| 19512 |
order = appearance(series), |
| 19513 |
top = 0, |
| 19514 |
bottom = 0, |
| 19515 |
tops = [], |
| 19516 |
bottoms = []; |
| 19517 |
|
| 19518 |
for (i = 0; i < n; ++i) { |
| 19519 |
j = order[i]; |
| 19520 |
if (top < bottom) { |
| 19521 |
top += sums[j]; |
| 19522 |
tops.push(j); |
| 19523 |
} else { |
| 19524 |
bottom += sums[j]; |
| 19525 |
bottoms.push(j); |
| 19526 |
} |
| 19527 |
} |
| 19528 |
|
| 19529 |
return bottoms.reverse().concat(tops); |
| 19530 |
} |
| 19531 |
|
| 19532 |
function reverse(series) { |
| 19533 |
return none(series).reverse(); |
| 19534 |
} |
| 19535 |
|
| 19536 |
var constant = x => () => x; |
| 19537 |
|
| 19538 |
function ZoomEvent(type, { |
| 19539 |
sourceEvent, |
| 19540 |
target, |
| 19541 |
transform, |
| 19542 |
dispatch |
| 19543 |
}) { |
| 19544 |
Object.defineProperties(this, { |
| 19545 |
type: {value: type, enumerable: true, configurable: true}, |
| 19546 |
sourceEvent: {value: sourceEvent, enumerable: true, configurable: true}, |
| 19547 |
target: {value: target, enumerable: true, configurable: true}, |
| 19548 |
transform: {value: transform, enumerable: true, configurable: true}, |
| 19549 |
_: {value: dispatch} |
| 19550 |
}); |
| 19551 |
} |
| 19552 |
|
| 19553 |
function Transform(k, x, y) { |
| 19554 |
this.k = k; |
| 19555 |
this.x = x; |
| 19556 |
this.y = y; |
| 19557 |
} |
| 19558 |
|
| 19559 |
Transform.prototype = { |
| 19560 |
constructor: Transform, |
| 19561 |
scale: function(k) { |
| 19562 |
return k === 1 ? this : new Transform(this.k * k, this.x, this.y); |
| 19563 |
}, |
| 19564 |
translate: function(x, y) { |
| 19565 |
return x === 0 & y === 0 ? this : new Transform(this.k, this.x + this.k * x, this.y + this.k * y); |
| 19566 |
}, |
| 19567 |
apply: function(point) { |
| 19568 |
return [point[0] * this.k + this.x, point[1] * this.k + this.y]; |
| 19569 |
}, |
| 19570 |
applyX: function(x) { |
| 19571 |
return x * this.k + this.x; |
| 19572 |
}, |
| 19573 |
applyY: function(y) { |
| 19574 |
return y * this.k + this.y; |
| 19575 |
}, |
| 19576 |
invert: function(location) { |
| 19577 |
return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k]; |
| 19578 |
}, |
| 19579 |
invertX: function(x) { |
| 19580 |
return (x - this.x) / this.k; |
| 19581 |
}, |
| 19582 |
invertY: function(y) { |
| 19583 |
return (y - this.y) / this.k; |
| 19584 |
}, |
| 19585 |
rescaleX: function(x) { |
| 19586 |
return x.copy().domain(x.range().map(this.invertX, this).map(x.invert, x)); |
| 19587 |
}, |
| 19588 |
rescaleY: function(y) { |
| 19589 |
return y.copy().domain(y.range().map(this.invertY, this).map(y.invert, y)); |
| 19590 |
}, |
| 19591 |
toString: function() { |
| 19592 |
return "translate(" + this.x + "," + this.y + ") scale(" + this.k + ")"; |
| 19593 |
} |
| 19594 |
}; |
| 19595 |
|
| 19596 |
var identity = new Transform(1, 0, 0); |
| 19597 |
|
| 19598 |
transform.prototype = Transform.prototype; |
| 19599 |
|
| 19600 |
function transform(node) { |
| 19601 |
while (!node.__zoom) if (!(node = node.parentNode)) return identity; |
| 19602 |
return node.__zoom; |
| 19603 |
} |
| 19604 |
|
| 19605 |
function nopropagation(event) { |
| 19606 |
event.stopImmediatePropagation(); |
| 19607 |
} |
| 19608 |
|
| 19609 |
function noevent(event) { |
| 19610 |
event.preventDefault(); |
| 19611 |
event.stopImmediatePropagation(); |
| 19612 |
} |
| 19613 |
|
| 19614 |
// Ignore right-click, since that should open the context menu. |
| 19615 |
// except for pinch-to-zoom, which is sent as a wheel+ctrlKey event |
| 19616 |
function defaultFilter(event) { |
| 19617 |
return (!event.ctrlKey || event.type === 'wheel') && !event.button; |
| 19618 |
} |
| 19619 |
|
| 19620 |
function defaultExtent() { |
| 19621 |
var e = this; |
| 19622 |
if (e instanceof SVGElement) { |
| 19623 |
e = e.ownerSVGElement || e; |
| 19624 |
if (e.hasAttribute("viewBox")) { |
| 19625 |
e = e.viewBox.baseVal; |
| 19626 |
return [[e.x, e.y], [e.x + e.width, e.y + e.height]]; |
| 19627 |
} |
| 19628 |
return [[0, 0], [e.width.baseVal.value, e.height.baseVal.value]]; |
| 19629 |
} |
| 19630 |
return [[0, 0], [e.clientWidth, e.clientHeight]]; |
| 19631 |
} |
| 19632 |
|
| 19633 |
function defaultTransform() { |
| 19634 |
return this.__zoom || identity; |
| 19635 |
} |
| 19636 |
|
| 19637 |
function defaultWheelDelta(event) { |
| 19638 |
return -event.deltaY * (event.deltaMode === 1 ? 0.05 : event.deltaMode ? 1 : 0.002) * (event.ctrlKey ? 10 : 1); |
| 19639 |
} |
| 19640 |
|
| 19641 |
function defaultTouchable() { |
| 19642 |
return navigator.maxTouchPoints || ("ontouchstart" in this); |
| 19643 |
} |
| 19644 |
|
| 19645 |
function defaultConstrain(transform, extent, translateExtent) { |
| 19646 |
var dx0 = transform.invertX(extent[0][0]) - translateExtent[0][0], |
| 19647 |
dx1 = transform.invertX(extent[1][0]) - translateExtent[1][0], |
| 19648 |
dy0 = transform.invertY(extent[0][1]) - translateExtent[0][1], |
| 19649 |
dy1 = transform.invertY(extent[1][1]) - translateExtent[1][1]; |
| 19650 |
return transform.translate( |
| 19651 |
dx1 > dx0 ? (dx0 + dx1) / 2 : Math.min(0, dx0) || Math.max(0, dx1), |
| 19652 |
dy1 > dy0 ? (dy0 + dy1) / 2 : Math.min(0, dy0) || Math.max(0, dy1) |
| 19653 |
); |
| 19654 |
} |
| 19655 |
|
| 19656 |
function zoom() { |
| 19657 |
var filter = defaultFilter, |
| 19658 |
extent = defaultExtent, |
| 19659 |
constrain = defaultConstrain, |
| 19660 |
wheelDelta = defaultWheelDelta, |
| 19661 |
touchable = defaultTouchable, |
| 19662 |
scaleExtent = [0, Infinity], |
| 19663 |
translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]], |
| 19664 |
duration = 250, |
| 19665 |
interpolate = interpolateZoom, |
| 19666 |
listeners = dispatch("start", "zoom", "end"), |
| 19667 |
touchstarting, |
| 19668 |
touchfirst, |
| 19669 |
touchending, |
| 19670 |
touchDelay = 500, |
| 19671 |
wheelDelay = 150, |
| 19672 |
clickDistance2 = 0, |
| 19673 |
tapDistance = 10; |
| 19674 |
|
| 19675 |
function zoom(selection) { |
| 19676 |
selection |
| 19677 |
.property("__zoom", defaultTransform) |
| 19678 |
.on("wheel.zoom", wheeled, {passive: false}) |
| 19679 |
.on("mousedown.zoom", mousedowned) |
| 19680 |
.on("dblclick.zoom", dblclicked) |
| 19681 |
.filter(touchable) |
| 19682 |
.on("touchstart.zoom", touchstarted) |
| 19683 |
.on("touchmove.zoom", touchmoved) |
| 19684 |
.on("touchend.zoom touchcancel.zoom", touchended) |
| 19685 |
.style("-webkit-tap-highlight-color", "rgba(0,0,0,0)"); |
| 19686 |
} |
| 19687 |
|
| 19688 |
zoom.transform = function(collection, transform, point, event) { |
| 19689 |
var selection = collection.selection ? collection.selection() : collection; |
| 19690 |
selection.property("__zoom", defaultTransform); |
| 19691 |
if (collection !== selection) { |
| 19692 |
schedule(collection, transform, point, event); |
| 19693 |
} else { |
| 19694 |
selection.interrupt().each(function() { |
| 19695 |
gesture(this, arguments) |
| 19696 |
.event(event) |
| 19697 |
.start() |
| 19698 |
.zoom(null, typeof transform === "function" ? transform.apply(this, arguments) : transform) |
| 19699 |
.end(); |
| 19700 |
}); |
| 19701 |
} |
| 19702 |
}; |
| 19703 |
|
| 19704 |
zoom.scaleBy = function(selection, k, p, event) { |
| 19705 |
zoom.scaleTo(selection, function() { |
| 19706 |
var k0 = this.__zoom.k, |
| 19707 |
k1 = typeof k === "function" ? k.apply(this, arguments) : k; |
| 19708 |
return k0 * k1; |
| 19709 |
}, p, event); |
| 19710 |
}; |
| 19711 |
|
| 19712 |
zoom.scaleTo = function(selection, k, p, event) { |
| 19713 |
zoom.transform(selection, function() { |
| 19714 |
var e = extent.apply(this, arguments), |
| 19715 |
t0 = this.__zoom, |
| 19716 |
p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p, |
| 19717 |
p1 = t0.invert(p0), |
| 19718 |
k1 = typeof k === "function" ? k.apply(this, arguments) : k; |
| 19719 |
return constrain(translate(scale(t0, k1), p0, p1), e, translateExtent); |
| 19720 |
}, p, event); |
| 19721 |
}; |
| 19722 |
|
| 19723 |
zoom.translateBy = function(selection, x, y, event) { |
| 19724 |
zoom.transform(selection, function() { |
| 19725 |
return constrain(this.__zoom.translate( |
| 19726 |
typeof x === "function" ? x.apply(this, arguments) : x, |
| 19727 |
typeof y === "function" ? y.apply(this, arguments) : y |
| 19728 |
), extent.apply(this, arguments), translateExtent); |
| 19729 |
}, null, event); |
| 19730 |
}; |
| 19731 |
|
| 19732 |
zoom.translateTo = function(selection, x, y, p, event) { |
| 19733 |
zoom.transform(selection, function() { |
| 19734 |
var e = extent.apply(this, arguments), |
| 19735 |
t = this.__zoom, |
| 19736 |
p0 = p == null ? centroid(e) : typeof p === "function" ? p.apply(this, arguments) : p; |
| 19737 |
return constrain(identity.translate(p0[0], p0[1]).scale(t.k).translate( |
| 19738 |
typeof x === "function" ? -x.apply(this, arguments) : -x, |
| 19739 |
typeof y === "function" ? -y.apply(this, arguments) : -y |
| 19740 |
), e, translateExtent); |
| 19741 |
}, p, event); |
| 19742 |
}; |
| 19743 |
|
| 19744 |
function scale(transform, k) { |
| 19745 |
k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], k)); |
| 19746 |
return k === transform.k ? transform : new Transform(k, transform.x, transform.y); |
| 19747 |
} |
| 19748 |
|
| 19749 |
function translate(transform, p0, p1) { |
| 19750 |
var x = p0[0] - p1[0] * transform.k, y = p0[1] - p1[1] * transform.k; |
| 19751 |
return x === transform.x && y === transform.y ? transform : new Transform(transform.k, x, y); |
| 19752 |
} |
| 19753 |
|
| 19754 |
function centroid(extent) { |
| 19755 |
return [(+extent[0][0] + +extent[1][0]) / 2, (+extent[0][1] + +extent[1][1]) / 2]; |
| 19756 |
} |
| 19757 |
|
| 19758 |
function schedule(transition, transform, point, event) { |
| 19759 |
transition |
| 19760 |
.on("start.zoom", function() { gesture(this, arguments).event(event).start(); }) |
| 19761 |
.on("interrupt.zoom end.zoom", function() { gesture(this, arguments).event(event).end(); }) |
| 19762 |
.tween("zoom", function() { |
| 19763 |
var that = this, |
| 19764 |
args = arguments, |
| 19765 |
g = gesture(that, args).event(event), |
| 19766 |
e = extent.apply(that, args), |
| 19767 |
p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point, |
| 19768 |
w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]), |
| 19769 |
a = that.__zoom, |
| 19770 |
b = typeof transform === "function" ? transform.apply(that, args) : transform, |
| 19771 |
i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k)); |
| 19772 |
return function(t) { |
| 19773 |
if (t === 1) t = b; // Avoid rounding error on end. |
| 19774 |
else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); } |
| 19775 |
g.zoom(null, t); |
| 19776 |
}; |
| 19777 |
}); |
| 19778 |
} |
| 19779 |
|
| 19780 |
function gesture(that, args, clean) { |
| 19781 |
return (!clean && that.__zooming) || new Gesture(that, args); |
| 19782 |
} |
| 19783 |
|
| 19784 |
function Gesture(that, args) { |
| 19785 |
this.that = that; |
| 19786 |
this.args = args; |
| 19787 |
this.active = 0; |
| 19788 |
this.sourceEvent = null; |
| 19789 |
this.extent = extent.apply(that, args); |
| 19790 |
this.taps = 0; |
| 19791 |
} |
| 19792 |
|
| 19793 |
Gesture.prototype = { |
| 19794 |
event: function(event) { |
| 19795 |
if (event) this.sourceEvent = event; |
| 19796 |
return this; |
| 19797 |
}, |
| 19798 |
start: function() { |
| 19799 |
if (++this.active === 1) { |
| 19800 |
this.that.__zooming = this; |
| 19801 |
this.emit("start"); |
| 19802 |
} |
| 19803 |
return this; |
| 19804 |
}, |
| 19805 |
zoom: function(key, transform) { |
| 19806 |
if (this.mouse && key !== "mouse") this.mouse[1] = transform.invert(this.mouse[0]); |
| 19807 |
if (this.touch0 && key !== "touch") this.touch0[1] = transform.invert(this.touch0[0]); |
| 19808 |
if (this.touch1 && key !== "touch") this.touch1[1] = transform.invert(this.touch1[0]); |
| 19809 |
this.that.__zoom = transform; |
| 19810 |
this.emit("zoom"); |
| 19811 |
return this; |
| 19812 |
}, |
| 19813 |
end: function() { |
| 19814 |
if (--this.active === 0) { |
| 19815 |
delete this.that.__zooming; |
| 19816 |
this.emit("end"); |
| 19817 |
} |
| 19818 |
return this; |
| 19819 |
}, |
| 19820 |
emit: function(type) { |
| 19821 |
var d = select(this.that).datum(); |
| 19822 |
listeners.call( |
| 19823 |
type, |
| 19824 |
this.that, |
| 19825 |
new ZoomEvent(type, { |
| 19826 |
sourceEvent: this.sourceEvent, |
| 19827 |
target: zoom, |
| 19828 |
type, |
| 19829 |
transform: this.that.__zoom, |
| 19830 |
dispatch: listeners |
| 19831 |
}), |
| 19832 |
d |
| 19833 |
); |
| 19834 |
} |
| 19835 |
}; |
| 19836 |
|
| 19837 |
function wheeled(event, ...args) { |
| 19838 |
if (!filter.apply(this, arguments)) return; |
| 19839 |
var g = gesture(this, args).event(event), |
| 19840 |
t = this.__zoom, |
| 19841 |
k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], t.k * Math.pow(2, wheelDelta.apply(this, arguments)))), |
| 19842 |
p = pointer(event); |
| 19843 |
|
| 19844 |
// If the mouse is in the same location as before, reuse it. |
| 19845 |
// If there were recent wheel events, reset the wheel idle timeout. |
| 19846 |
if (g.wheel) { |
| 19847 |
if (g.mouse[0][0] !== p[0] || g.mouse[0][1] !== p[1]) { |
| 19848 |
g.mouse[1] = t.invert(g.mouse[0] = p); |
| 19849 |
} |
| 19850 |
clearTimeout(g.wheel); |
| 19851 |
} |
| 19852 |
|
| 19853 |
// If this wheel event won’t trigger a transform change, ignore it. |
| 19854 |
else if (t.k === k) return; |
| 19855 |
|
| 19856 |
// Otherwise, capture the mouse point and location at the start. |
| 19857 |
else { |
| 19858 |
g.mouse = [p, t.invert(p)]; |
| 19859 |
interrupt(this); |
| 19860 |
g.start(); |
| 19861 |
} |
| 19862 |
|
| 19863 |
noevent(event); |
| 19864 |
g.wheel = setTimeout(wheelidled, wheelDelay); |
| 19865 |
g.zoom("mouse", constrain(translate(scale(t, k), g.mouse[0], g.mouse[1]), g.extent, translateExtent)); |
| 19866 |
|
| 19867 |
function wheelidled() { |
| 19868 |
g.wheel = null; |
| 19869 |
g.end(); |
| 19870 |
} |
| 19871 |
} |
| 19872 |
|
| 19873 |
function mousedowned(event, ...args) { |
| 19874 |
if (touchending || !filter.apply(this, arguments)) return; |
| 19875 |
var currentTarget = event.currentTarget, |
| 19876 |
g = gesture(this, args, true).event(event), |
| 19877 |
v = select(event.view).on("mousemove.zoom", mousemoved, true).on("mouseup.zoom", mouseupped, true), |
| 19878 |
p = pointer(event, currentTarget), |
| 19879 |
x0 = event.clientX, |
| 19880 |
y0 = event.clientY; |
| 19881 |
|
| 19882 |
dragDisable(event.view); |
| 19883 |
nopropagation(event); |
| 19884 |
g.mouse = [p, this.__zoom.invert(p)]; |
| 19885 |
interrupt(this); |
| 19886 |
g.start(); |
| 19887 |
|
| 19888 |
function mousemoved(event) { |
| 19889 |
noevent(event); |
| 19890 |
if (!g.moved) { |
| 19891 |
var dx = event.clientX - x0, dy = event.clientY - y0; |
| 19892 |
g.moved = dx * dx + dy * dy > clickDistance2; |
| 19893 |
} |
| 19894 |
g.event(event) |
| 19895 |
.zoom("mouse", constrain(translate(g.that.__zoom, g.mouse[0] = pointer(event, currentTarget), g.mouse[1]), g.extent, translateExtent)); |
| 19896 |
} |
| 19897 |
|
| 19898 |
function mouseupped(event) { |
| 19899 |
v.on("mousemove.zoom mouseup.zoom", null); |
| 19900 |
yesdrag(event.view, g.moved); |
| 19901 |
noevent(event); |
| 19902 |
g.event(event).end(); |
| 19903 |
} |
| 19904 |
} |
| 19905 |
|
| 19906 |
function dblclicked(event, ...args) { |
| 19907 |
if (!filter.apply(this, arguments)) return; |
| 19908 |
var t0 = this.__zoom, |
| 19909 |
p0 = pointer(event.changedTouches ? event.changedTouches[0] : event, this), |
| 19910 |
p1 = t0.invert(p0), |
| 19911 |
k1 = t0.k * (event.shiftKey ? 0.5 : 2), |
| 19912 |
t1 = constrain(translate(scale(t0, k1), p0, p1), extent.apply(this, args), translateExtent); |
| 19913 |
|
| 19914 |
noevent(event); |
| 19915 |
if (duration > 0) select(this).transition().duration(duration).call(schedule, t1, p0, event); |
| 19916 |
else select(this).call(zoom.transform, t1, p0, event); |
| 19917 |
} |
| 19918 |
|
| 19919 |
function touchstarted(event, ...args) { |
| 19920 |
if (!filter.apply(this, arguments)) return; |
| 19921 |
var touches = event.touches, |
| 19922 |
n = touches.length, |
| 19923 |
g = gesture(this, args, event.changedTouches.length === n).event(event), |
| 19924 |
started, i, t, p; |
| 19925 |
|
| 19926 |
nopropagation(event); |
| 19927 |
for (i = 0; i < n; ++i) { |
| 19928 |
t = touches[i], p = pointer(t, this); |
| 19929 |
p = [p, this.__zoom.invert(p), t.identifier]; |
| 19930 |
if (!g.touch0) g.touch0 = p, started = true, g.taps = 1 + !!touchstarting; |
| 19931 |
else if (!g.touch1 && g.touch0[2] !== p[2]) g.touch1 = p, g.taps = 0; |
| 19932 |
} |
| 19933 |
|
| 19934 |
if (touchstarting) touchstarting = clearTimeout(touchstarting); |
| 19935 |
|
| 19936 |
if (started) { |
| 19937 |
if (g.taps < 2) touchfirst = p[0], touchstarting = setTimeout(function() { touchstarting = null; }, touchDelay); |
| 19938 |
interrupt(this); |
| 19939 |
g.start(); |
| 19940 |
} |
| 19941 |
} |
| 19942 |
|
| 19943 |
function touchmoved(event, ...args) { |
| 19944 |
if (!this.__zooming) return; |
| 19945 |
var g = gesture(this, args).event(event), |
| 19946 |
touches = event.changedTouches, |
| 19947 |
n = touches.length, i, t, p, l; |
| 19948 |
|
| 19949 |
noevent(event); |
| 19950 |
for (i = 0; i < n; ++i) { |
| 19951 |
t = touches[i], p = pointer(t, this); |
| 19952 |
if (g.touch0 && g.touch0[2] === t.identifier) g.touch0[0] = p; |
| 19953 |
else if (g.touch1 && g.touch1[2] === t.identifier) g.touch1[0] = p; |
| 19954 |
} |
| 19955 |
t = g.that.__zoom; |
| 19956 |
if (g.touch1) { |
| 19957 |
var p0 = g.touch0[0], l0 = g.touch0[1], |
| 19958 |
p1 = g.touch1[0], l1 = g.touch1[1], |
| 19959 |
dp = (dp = p1[0] - p0[0]) * dp + (dp = p1[1] - p0[1]) * dp, |
| 19960 |
dl = (dl = l1[0] - l0[0]) * dl + (dl = l1[1] - l0[1]) * dl; |
| 19961 |
t = scale(t, Math.sqrt(dp / dl)); |
| 19962 |
p = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2]; |
| 19963 |
l = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2]; |
| 19964 |
} |
| 19965 |
else if (g.touch0) p = g.touch0[0], l = g.touch0[1]; |
| 19966 |
else return; |
| 19967 |
|
| 19968 |
g.zoom("touch", constrain(translate(t, p, l), g.extent, translateExtent)); |
| 19969 |
} |
| 19970 |
|
| 19971 |
function touchended(event, ...args) { |
| 19972 |
if (!this.__zooming) return; |
| 19973 |
var g = gesture(this, args).event(event), |
| 19974 |
touches = event.changedTouches, |
| 19975 |
n = touches.length, i, t; |
| 19976 |
|
| 19977 |
nopropagation(event); |
| 19978 |
if (touchending) clearTimeout(touchending); |
| 19979 |
touchending = setTimeout(function() { touchending = null; }, touchDelay); |
| 19980 |
for (i = 0; i < n; ++i) { |
| 19981 |
t = touches[i]; |
| 19982 |
if (g.touch0 && g.touch0[2] === t.identifier) delete g.touch0; |
| 19983 |
else if (g.touch1 && g.touch1[2] === t.identifier) delete g.touch1; |
| 19984 |
} |
| 19985 |
if (g.touch1 && !g.touch0) g.touch0 = g.touch1, delete g.touch1; |
| 19986 |
if (g.touch0) g.touch0[1] = this.__zoom.invert(g.touch0[0]); |
| 19987 |
else { |
| 19988 |
g.end(); |
| 19989 |
// If this was a dbltap, reroute to the (optional) dblclick.zoom handler. |
| 19990 |
if (g.taps === 2) { |
| 19991 |
t = pointer(t, this); |
| 19992 |
if (Math.hypot(touchfirst[0] - t[0], touchfirst[1] - t[1]) < tapDistance) { |
| 19993 |
var p = select(this).on("dblclick.zoom"); |
| 19994 |
if (p) p.apply(this, arguments); |
| 19995 |
} |
| 19996 |
} |
| 19997 |
} |
| 19998 |
} |
| 19999 |
|
| 20000 |
zoom.wheelDelta = function(_) { |
| 20001 |
return arguments.length ? (wheelDelta = typeof _ === "function" ? _ : constant(+_), zoom) : wheelDelta; |
| 20002 |
}; |
| 20003 |
|
| 20004 |
zoom.filter = function(_) { |
| 20005 |
return arguments.length ? (filter = typeof _ === "function" ? _ : constant(!!_), zoom) : filter; |
| 20006 |
}; |
| 20007 |
|
| 20008 |
zoom.touchable = function(_) { |
| 20009 |
return arguments.length ? (touchable = typeof _ === "function" ? _ : constant(!!_), zoom) : touchable; |
| 20010 |
}; |
| 20011 |
|
| 20012 |
zoom.extent = function(_) { |
| 20013 |
return arguments.length ? (extent = typeof _ === "function" ? _ : constant([[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]]), zoom) : extent; |
| 20014 |
}; |
| 20015 |
|
| 20016 |
zoom.scaleExtent = function(_) { |
| 20017 |
return arguments.length ? (scaleExtent[0] = +_[0], scaleExtent[1] = +_[1], zoom) : [scaleExtent[0], scaleExtent[1]]; |
| 20018 |
}; |
| 20019 |
|
| 20020 |
zoom.translateExtent = function(_) { |
| 20021 |
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]]]; |
| 20022 |
}; |
| 20023 |
|
| 20024 |
zoom.constrain = function(_) { |
| 20025 |
return arguments.length ? (constrain = _, zoom) : constrain; |
| 20026 |
}; |
| 20027 |
|
| 20028 |
zoom.duration = function(_) { |
| 20029 |
return arguments.length ? (duration = +_, zoom) : duration; |
| 20030 |
}; |
| 20031 |
|
| 20032 |
zoom.interpolate = function(_) { |
| 20033 |
return arguments.length ? (interpolate = _, zoom) : interpolate; |
| 20034 |
}; |
| 20035 |
|
| 20036 |
zoom.on = function() { |
| 20037 |
var value = listeners.on.apply(listeners, arguments); |
| 20038 |
return value === listeners ? zoom : value; |
| 20039 |
}; |
| 20040 |
|
| 20041 |
zoom.clickDistance = function(_) { |
| 20042 |
return arguments.length ? (clickDistance2 = (_ = +_) * _, zoom) : Math.sqrt(clickDistance2); |
| 20043 |
}; |
| 20044 |
|
| 20045 |
zoom.tapDistance = function(_) { |
| 20046 |
return arguments.length ? (tapDistance = +_, zoom) : tapDistance; |
| 20047 |
}; |
| 20048 |
|
| 20049 |
return zoom; |
| 20050 |
} |
| 20051 |
|
| 20052 |
exports.Adder = Adder; |
| 20053 |
exports.Delaunay = Delaunay; |
| 20054 |
exports.FormatSpecifier = FormatSpecifier; |
| 20055 |
exports.InternMap = InternMap; |
| 20056 |
exports.InternSet = InternSet; |
| 20057 |
exports.Node = Node$1; |
| 20058 |
exports.Path = Path$1; |
| 20059 |
exports.Voronoi = Voronoi; |
| 20060 |
exports.ZoomTransform = Transform; |
| 20061 |
exports.active = active; |
| 20062 |
exports.arc = arc; |
| 20063 |
exports.area = area; |
| 20064 |
exports.areaRadial = areaRadial; |
| 20065 |
exports.ascending = ascending$3; |
| 20066 |
exports.autoType = autoType; |
| 20067 |
exports.axisBottom = axisBottom; |
| 20068 |
exports.axisLeft = axisLeft; |
| 20069 |
exports.axisRight = axisRight; |
| 20070 |
exports.axisTop = axisTop; |
| 20071 |
exports.bin = bin; |
| 20072 |
exports.bisect = bisect; |
| 20073 |
exports.bisectCenter = bisectCenter; |
| 20074 |
exports.bisectLeft = bisectLeft; |
| 20075 |
exports.bisectRight = bisectRight; |
| 20076 |
exports.bisector = bisector; |
| 20077 |
exports.blob = blob; |
| 20078 |
exports.blur = blur; |
| 20079 |
exports.blur2 = blur2; |
| 20080 |
exports.blurImage = blurImage; |
| 20081 |
exports.brush = brush; |
| 20082 |
exports.brushSelection = brushSelection; |
| 20083 |
exports.brushX = brushX; |
| 20084 |
exports.brushY = brushY; |
| 20085 |
exports.buffer = buffer; |
| 20086 |
exports.chord = chord; |
| 20087 |
exports.chordDirected = chordDirected; |
| 20088 |
exports.chordTranspose = chordTranspose; |
| 20089 |
exports.cluster = cluster; |
| 20090 |
exports.color = color; |
| 20091 |
exports.contourDensity = density; |
| 20092 |
exports.contours = Contours; |
| 20093 |
exports.count = count$1; |
| 20094 |
exports.create = create$1; |
| 20095 |
exports.creator = creator; |
| 20096 |
exports.cross = cross$2; |
| 20097 |
exports.csv = csv; |
| 20098 |
exports.csvFormat = csvFormat; |
| 20099 |
exports.csvFormatBody = csvFormatBody; |
| 20100 |
exports.csvFormatRow = csvFormatRow; |
| 20101 |
exports.csvFormatRows = csvFormatRows; |
| 20102 |
exports.csvFormatValue = csvFormatValue; |
| 20103 |
exports.csvParse = csvParse; |
| 20104 |
exports.csvParseRows = csvParseRows; |
| 20105 |
exports.cubehelix = cubehelix$3; |
| 20106 |
exports.cumsum = cumsum; |
| 20107 |
exports.curveBasis = basis; |
| 20108 |
exports.curveBasisClosed = basisClosed; |
| 20109 |
exports.curveBasisOpen = basisOpen; |
| 20110 |
exports.curveBumpX = bumpX; |
| 20111 |
exports.curveBumpY = bumpY; |
| 20112 |
exports.curveBundle = bundle; |
| 20113 |
exports.curveCardinal = cardinal; |
| 20114 |
exports.curveCardinalClosed = cardinalClosed; |
| 20115 |
exports.curveCardinalOpen = cardinalOpen; |
| 20116 |
exports.curveCatmullRom = catmullRom; |
| 20117 |
exports.curveCatmullRomClosed = catmullRomClosed; |
| 20118 |
exports.curveCatmullRomOpen = catmullRomOpen; |
| 20119 |
exports.curveLinear = curveLinear; |
| 20120 |
exports.curveLinearClosed = linearClosed; |
| 20121 |
exports.curveMonotoneX = monotoneX; |
| 20122 |
exports.curveMonotoneY = monotoneY; |
| 20123 |
exports.curveNatural = natural; |
| 20124 |
exports.curveStep = step; |
| 20125 |
exports.curveStepAfter = stepAfter; |
| 20126 |
exports.curveStepBefore = stepBefore; |
| 20127 |
exports.descending = descending$2; |
| 20128 |
exports.deviation = deviation; |
| 20129 |
exports.difference = difference; |
| 20130 |
exports.disjoint = disjoint; |
| 20131 |
exports.dispatch = dispatch; |
| 20132 |
exports.drag = drag; |
| 20133 |
exports.dragDisable = dragDisable; |
| 20134 |
exports.dragEnable = yesdrag; |
| 20135 |
exports.dsv = dsv; |
| 20136 |
exports.dsvFormat = dsvFormat; |
| 20137 |
exports.easeBack = backInOut; |
| 20138 |
exports.easeBackIn = backIn; |
| 20139 |
exports.easeBackInOut = backInOut; |
| 20140 |
exports.easeBackOut = backOut; |
| 20141 |
exports.easeBounce = bounceOut; |
| 20142 |
exports.easeBounceIn = bounceIn; |
| 20143 |
exports.easeBounceInOut = bounceInOut; |
| 20144 |
exports.easeBounceOut = bounceOut; |
| 20145 |
exports.easeCircle = circleInOut; |
| 20146 |
exports.easeCircleIn = circleIn; |
| 20147 |
exports.easeCircleInOut = circleInOut; |
| 20148 |
exports.easeCircleOut = circleOut; |
| 20149 |
exports.easeCubic = cubicInOut; |
| 20150 |
exports.easeCubicIn = cubicIn; |
| 20151 |
exports.easeCubicInOut = cubicInOut; |
| 20152 |
exports.easeCubicOut = cubicOut; |
| 20153 |
exports.easeElastic = elasticOut; |
| 20154 |
exports.easeElasticIn = elasticIn; |
| 20155 |
exports.easeElasticInOut = elasticInOut; |
| 20156 |
exports.easeElasticOut = elasticOut; |
| 20157 |
exports.easeExp = expInOut; |
| 20158 |
exports.easeExpIn = expIn; |
| 20159 |
exports.easeExpInOut = expInOut; |
| 20160 |
exports.easeExpOut = expOut; |
| 20161 |
exports.easeLinear = linear$1; |
| 20162 |
exports.easePoly = polyInOut; |
| 20163 |
exports.easePolyIn = polyIn; |
| 20164 |
exports.easePolyInOut = polyInOut; |
| 20165 |
exports.easePolyOut = polyOut; |
| 20166 |
exports.easeQuad = quadInOut; |
| 20167 |
exports.easeQuadIn = quadIn; |
| 20168 |
exports.easeQuadInOut = quadInOut; |
| 20169 |
exports.easeQuadOut = quadOut; |
| 20170 |
exports.easeSin = sinInOut; |
| 20171 |
exports.easeSinIn = sinIn; |
| 20172 |
exports.easeSinInOut = sinInOut; |
| 20173 |
exports.easeSinOut = sinOut; |
| 20174 |
exports.every = every; |
| 20175 |
exports.extent = extent$1; |
| 20176 |
exports.fcumsum = fcumsum; |
| 20177 |
exports.filter = filter$1; |
| 20178 |
exports.flatGroup = flatGroup; |
| 20179 |
exports.flatRollup = flatRollup; |
| 20180 |
exports.forceCenter = center; |
| 20181 |
exports.forceCollide = collide; |
| 20182 |
exports.forceLink = link$2; |
| 20183 |
exports.forceManyBody = manyBody; |
| 20184 |
exports.forceRadial = radial$1; |
| 20185 |
exports.forceSimulation = simulation; |
| 20186 |
exports.forceX = x$1; |
| 20187 |
exports.forceY = y$1; |
| 20188 |
exports.formatDefaultLocale = defaultLocale$1; |
| 20189 |
exports.formatLocale = formatLocale$1; |
| 20190 |
exports.formatSpecifier = formatSpecifier; |
| 20191 |
exports.fsum = fsum; |
| 20192 |
exports.geoAlbers = albers; |
| 20193 |
exports.geoAlbersUsa = albersUsa; |
| 20194 |
exports.geoArea = area$2; |
| 20195 |
exports.geoAzimuthalEqualArea = azimuthalEqualArea; |
| 20196 |
exports.geoAzimuthalEqualAreaRaw = azimuthalEqualAreaRaw; |
| 20197 |
exports.geoAzimuthalEquidistant = azimuthalEquidistant; |
| 20198 |
exports.geoAzimuthalEquidistantRaw = azimuthalEquidistantRaw; |
| 20199 |
exports.geoBounds = bounds; |
| 20200 |
exports.geoCentroid = centroid$1; |
| 20201 |
exports.geoCircle = circle$1; |
| 20202 |
exports.geoClipAntimeridian = clipAntimeridian; |
| 20203 |
exports.geoClipCircle = clipCircle; |
| 20204 |
exports.geoClipExtent = extent; |
| 20205 |
exports.geoClipRectangle = clipRectangle; |
| 20206 |
exports.geoConicConformal = conicConformal; |
| 20207 |
exports.geoConicConformalRaw = conicConformalRaw; |
| 20208 |
exports.geoConicEqualArea = conicEqualArea; |
| 20209 |
exports.geoConicEqualAreaRaw = conicEqualAreaRaw; |
| 20210 |
exports.geoConicEquidistant = conicEquidistant; |
| 20211 |
exports.geoConicEquidistantRaw = conicEquidistantRaw; |
| 20212 |
exports.geoContains = contains$1; |
| 20213 |
exports.geoDistance = distance; |
| 20214 |
exports.geoEqualEarth = equalEarth; |
| 20215 |
exports.geoEqualEarthRaw = equalEarthRaw; |
| 20216 |
exports.geoEquirectangular = equirectangular; |
| 20217 |
exports.geoEquirectangularRaw = equirectangularRaw; |
| 20218 |
exports.geoGnomonic = gnomonic; |
| 20219 |
exports.geoGnomonicRaw = gnomonicRaw; |
| 20220 |
exports.geoGraticule = graticule; |
| 20221 |
exports.geoGraticule10 = graticule10; |
| 20222 |
exports.geoIdentity = identity$4; |
| 20223 |
exports.geoInterpolate = interpolate; |
| 20224 |
exports.geoLength = length$1; |
| 20225 |
exports.geoMercator = mercator; |
| 20226 |
exports.geoMercatorRaw = mercatorRaw; |
| 20227 |
exports.geoNaturalEarth1 = naturalEarth1; |
| 20228 |
exports.geoNaturalEarth1Raw = naturalEarth1Raw; |
| 20229 |
exports.geoOrthographic = orthographic; |
| 20230 |
exports.geoOrthographicRaw = orthographicRaw; |
| 20231 |
exports.geoPath = index$2; |
| 20232 |
exports.geoProjection = projection; |
| 20233 |
exports.geoProjectionMutator = projectionMutator; |
| 20234 |
exports.geoRotation = rotation; |
| 20235 |
exports.geoStereographic = stereographic; |
| 20236 |
exports.geoStereographicRaw = stereographicRaw; |
| 20237 |
exports.geoStream = geoStream; |
| 20238 |
exports.geoTransform = transform$1; |
| 20239 |
exports.geoTransverseMercator = transverseMercator; |
| 20240 |
exports.geoTransverseMercatorRaw = transverseMercatorRaw; |
| 20241 |
exports.gray = gray; |
| 20242 |
exports.greatest = greatest; |
| 20243 |
exports.greatestIndex = greatestIndex; |
| 20244 |
exports.group = group; |
| 20245 |
exports.groupSort = groupSort; |
| 20246 |
exports.groups = groups; |
| 20247 |
exports.hcl = hcl$2; |
| 20248 |
exports.hierarchy = hierarchy; |
| 20249 |
exports.histogram = bin; |
| 20250 |
exports.hsl = hsl$2; |
| 20251 |
exports.html = html; |
| 20252 |
exports.image = image; |
| 20253 |
exports.index = index$4; |
| 20254 |
exports.indexes = indexes; |
| 20255 |
exports.interpolate = interpolate$2; |
| 20256 |
exports.interpolateArray = array$3; |
| 20257 |
exports.interpolateBasis = basis$2; |
| 20258 |
exports.interpolateBasisClosed = basisClosed$1; |
| 20259 |
exports.interpolateBlues = Blues; |
| 20260 |
exports.interpolateBrBG = BrBG; |
| 20261 |
exports.interpolateBuGn = BuGn; |
| 20262 |
exports.interpolateBuPu = BuPu; |
| 20263 |
exports.interpolateCividis = cividis; |
| 20264 |
exports.interpolateCool = cool; |
| 20265 |
exports.interpolateCubehelix = cubehelix$2; |
| 20266 |
exports.interpolateCubehelixDefault = cubehelix; |
| 20267 |
exports.interpolateCubehelixLong = cubehelixLong; |
| 20268 |
exports.interpolateDate = date$1; |
| 20269 |
exports.interpolateDiscrete = discrete; |
| 20270 |
exports.interpolateGnBu = GnBu; |
| 20271 |
exports.interpolateGreens = Greens; |
| 20272 |
exports.interpolateGreys = Greys; |
| 20273 |
exports.interpolateHcl = hcl$1; |
| 20274 |
exports.interpolateHclLong = hclLong; |
| 20275 |
exports.interpolateHsl = hsl$1; |
| 20276 |
exports.interpolateHslLong = hslLong; |
| 20277 |
exports.interpolateHue = hue; |
| 20278 |
exports.interpolateInferno = inferno; |
| 20279 |
exports.interpolateLab = lab; |
| 20280 |
exports.interpolateMagma = magma; |
| 20281 |
exports.interpolateNumber = interpolateNumber; |
| 20282 |
exports.interpolateNumberArray = numberArray; |
| 20283 |
exports.interpolateObject = object$1; |
| 20284 |
exports.interpolateOrRd = OrRd; |
| 20285 |
exports.interpolateOranges = Oranges; |
| 20286 |
exports.interpolatePRGn = PRGn; |
| 20287 |
exports.interpolatePiYG = PiYG; |
| 20288 |
exports.interpolatePlasma = plasma; |
| 20289 |
exports.interpolatePuBu = PuBu; |
| 20290 |
exports.interpolatePuBuGn = PuBuGn; |
| 20291 |
exports.interpolatePuOr = PuOr; |
| 20292 |
exports.interpolatePuRd = PuRd; |
| 20293 |
exports.interpolatePurples = Purples; |
| 20294 |
exports.interpolateRainbow = rainbow; |
| 20295 |
exports.interpolateRdBu = RdBu; |
| 20296 |
exports.interpolateRdGy = RdGy; |
| 20297 |
exports.interpolateRdPu = RdPu; |
| 20298 |
exports.interpolateRdYlBu = RdYlBu; |
| 20299 |
exports.interpolateRdYlGn = RdYlGn; |
| 20300 |
exports.interpolateReds = Reds; |
| 20301 |
exports.interpolateRgb = interpolateRgb; |
| 20302 |
exports.interpolateRgbBasis = rgbBasis; |
| 20303 |
exports.interpolateRgbBasisClosed = rgbBasisClosed; |
| 20304 |
exports.interpolateRound = interpolateRound; |
| 20305 |
exports.interpolateSinebow = sinebow; |
| 20306 |
exports.interpolateSpectral = Spectral; |
| 20307 |
exports.interpolateString = interpolateString; |
| 20308 |
exports.interpolateTransformCss = interpolateTransformCss; |
| 20309 |
exports.interpolateTransformSvg = interpolateTransformSvg; |
| 20310 |
exports.interpolateTurbo = turbo; |
| 20311 |
exports.interpolateViridis = viridis; |
| 20312 |
exports.interpolateWarm = warm; |
| 20313 |
exports.interpolateYlGn = YlGn; |
| 20314 |
exports.interpolateYlGnBu = YlGnBu; |
| 20315 |
exports.interpolateYlOrBr = YlOrBr; |
| 20316 |
exports.interpolateYlOrRd = YlOrRd; |
| 20317 |
exports.interpolateZoom = interpolateZoom; |
| 20318 |
exports.interrupt = interrupt; |
| 20319 |
exports.intersection = intersection; |
| 20320 |
exports.interval = interval; |
| 20321 |
exports.isoFormat = formatIso$1; |
| 20322 |
exports.isoParse = parseIso$1; |
| 20323 |
exports.json = json; |
| 20324 |
exports.lab = lab$1; |
| 20325 |
exports.lch = lch; |
| 20326 |
exports.least = least; |
| 20327 |
exports.leastIndex = leastIndex; |
| 20328 |
exports.line = line; |
| 20329 |
exports.lineRadial = lineRadial$1; |
| 20330 |
exports.link = link; |
| 20331 |
exports.linkHorizontal = linkHorizontal; |
| 20332 |
exports.linkRadial = linkRadial; |
| 20333 |
exports.linkVertical = linkVertical; |
| 20334 |
exports.local = local$1; |
| 20335 |
exports.map = map$1; |
| 20336 |
exports.matcher = matcher; |
| 20337 |
exports.max = max$3; |
| 20338 |
exports.maxIndex = maxIndex; |
| 20339 |
exports.mean = mean; |
| 20340 |
exports.median = median; |
| 20341 |
exports.medianIndex = medianIndex; |
| 20342 |
exports.merge = merge; |
| 20343 |
exports.min = min$2; |
| 20344 |
exports.minIndex = minIndex; |
| 20345 |
exports.mode = mode; |
| 20346 |
exports.namespace = namespace; |
| 20347 |
exports.namespaces = namespaces; |
| 20348 |
exports.nice = nice$1; |
| 20349 |
exports.now = now; |
| 20350 |
exports.pack = index$1; |
| 20351 |
exports.packEnclose = enclose; |
| 20352 |
exports.packSiblings = siblings; |
| 20353 |
exports.pairs = pairs; |
| 20354 |
exports.partition = partition; |
| 20355 |
exports.path = path; |
| 20356 |
exports.pathRound = pathRound; |
| 20357 |
exports.permute = permute; |
| 20358 |
exports.pie = pie; |
| 20359 |
exports.piecewise = piecewise; |
| 20360 |
exports.pointRadial = pointRadial; |
| 20361 |
exports.pointer = pointer; |
| 20362 |
exports.pointers = pointers; |
| 20363 |
exports.polygonArea = area$1; |
| 20364 |
exports.polygonCentroid = centroid; |
| 20365 |
exports.polygonContains = contains; |
| 20366 |
exports.polygonHull = hull; |
| 20367 |
exports.polygonLength = length; |
| 20368 |
exports.precisionFixed = precisionFixed; |
| 20369 |
exports.precisionPrefix = precisionPrefix; |
| 20370 |
exports.precisionRound = precisionRound; |
| 20371 |
exports.quadtree = quadtree; |
| 20372 |
exports.quantile = quantile$1; |
| 20373 |
exports.quantileIndex = quantileIndex; |
| 20374 |
exports.quantileSorted = quantileSorted; |
| 20375 |
exports.quantize = quantize$1; |
| 20376 |
exports.quickselect = quickselect; |
| 20377 |
exports.radialArea = areaRadial; |
| 20378 |
exports.radialLine = lineRadial$1; |
| 20379 |
exports.randomBates = bates; |
| 20380 |
exports.randomBernoulli = bernoulli; |
| 20381 |
exports.randomBeta = beta; |
| 20382 |
exports.randomBinomial = binomial; |
| 20383 |
exports.randomCauchy = cauchy; |
| 20384 |
exports.randomExponential = exponential; |
| 20385 |
exports.randomGamma = gamma; |
| 20386 |
exports.randomGeometric = geometric; |
| 20387 |
exports.randomInt = int; |
| 20388 |
exports.randomIrwinHall = irwinHall; |
| 20389 |
exports.randomLcg = lcg; |
| 20390 |
exports.randomLogNormal = logNormal; |
| 20391 |
exports.randomLogistic = logistic; |
| 20392 |
exports.randomNormal = normal; |
| 20393 |
exports.randomPareto = pareto; |
| 20394 |
exports.randomPoisson = poisson; |
| 20395 |
exports.randomUniform = uniform; |
| 20396 |
exports.randomWeibull = weibull; |
| 20397 |
exports.range = range$2; |
| 20398 |
exports.rank = rank; |
| 20399 |
exports.reduce = reduce; |
| 20400 |
exports.reverse = reverse$1; |
| 20401 |
exports.rgb = rgb; |
| 20402 |
exports.ribbon = ribbon$1; |
| 20403 |
exports.ribbonArrow = ribbonArrow; |
| 20404 |
exports.rollup = rollup; |
| 20405 |
exports.rollups = rollups; |
| 20406 |
exports.scaleBand = band; |
| 20407 |
exports.scaleDiverging = diverging$1; |
| 20408 |
exports.scaleDivergingLog = divergingLog; |
| 20409 |
exports.scaleDivergingPow = divergingPow; |
| 20410 |
exports.scaleDivergingSqrt = divergingSqrt; |
| 20411 |
exports.scaleDivergingSymlog = divergingSymlog; |
| 20412 |
exports.scaleIdentity = identity$2; |
| 20413 |
exports.scaleImplicit = implicit; |
| 20414 |
exports.scaleLinear = linear; |
| 20415 |
exports.scaleLog = log; |
| 20416 |
exports.scaleOrdinal = ordinal; |
| 20417 |
exports.scalePoint = point$4; |
| 20418 |
exports.scalePow = pow; |
| 20419 |
exports.scaleQuantile = quantile; |
| 20420 |
exports.scaleQuantize = quantize; |
| 20421 |
exports.scaleRadial = radial; |
| 20422 |
exports.scaleSequential = sequential; |
| 20423 |
exports.scaleSequentialLog = sequentialLog; |
| 20424 |
exports.scaleSequentialPow = sequentialPow; |
| 20425 |
exports.scaleSequentialQuantile = sequentialQuantile; |
| 20426 |
exports.scaleSequentialSqrt = sequentialSqrt; |
| 20427 |
exports.scaleSequentialSymlog = sequentialSymlog; |
| 20428 |
exports.scaleSqrt = sqrt$1; |
| 20429 |
exports.scaleSymlog = symlog; |
| 20430 |
exports.scaleThreshold = threshold; |
| 20431 |
exports.scaleTime = time; |
| 20432 |
exports.scaleUtc = utcTime; |
| 20433 |
exports.scan = scan; |
| 20434 |
exports.schemeAccent = Accent; |
| 20435 |
exports.schemeBlues = scheme$5; |
| 20436 |
exports.schemeBrBG = scheme$q; |
| 20437 |
exports.schemeBuGn = scheme$h; |
| 20438 |
exports.schemeBuPu = scheme$g; |
| 20439 |
exports.schemeCategory10 = category10; |
| 20440 |
exports.schemeDark2 = Dark2; |
| 20441 |
exports.schemeGnBu = scheme$f; |
| 20442 |
exports.schemeGreens = scheme$4; |
| 20443 |
exports.schemeGreys = scheme$3; |
| 20444 |
exports.schemeObservable10 = observable10; |
| 20445 |
exports.schemeOrRd = scheme$e; |
| 20446 |
exports.schemeOranges = scheme; |
| 20447 |
exports.schemePRGn = scheme$p; |
| 20448 |
exports.schemePaired = Paired; |
| 20449 |
exports.schemePastel1 = Pastel1; |
| 20450 |
exports.schemePastel2 = Pastel2; |
| 20451 |
exports.schemePiYG = scheme$o; |
| 20452 |
exports.schemePuBu = scheme$c; |
| 20453 |
exports.schemePuBuGn = scheme$d; |
| 20454 |
exports.schemePuOr = scheme$n; |
| 20455 |
exports.schemePuRd = scheme$b; |
| 20456 |
exports.schemePurples = scheme$2; |
| 20457 |
exports.schemeRdBu = scheme$m; |
| 20458 |
exports.schemeRdGy = scheme$l; |
| 20459 |
exports.schemeRdPu = scheme$a; |
| 20460 |
exports.schemeRdYlBu = scheme$k; |
| 20461 |
exports.schemeRdYlGn = scheme$j; |
| 20462 |
exports.schemeReds = scheme$1; |
| 20463 |
exports.schemeSet1 = Set1; |
| 20464 |
exports.schemeSet2 = Set2; |
| 20465 |
exports.schemeSet3 = Set3; |
| 20466 |
exports.schemeSpectral = scheme$i; |
| 20467 |
exports.schemeTableau10 = Tableau10; |
| 20468 |
exports.schemeYlGn = scheme$8; |
| 20469 |
exports.schemeYlGnBu = scheme$9; |
| 20470 |
exports.schemeYlOrBr = scheme$7; |
| 20471 |
exports.schemeYlOrRd = scheme$6; |
| 20472 |
exports.select = select; |
| 20473 |
exports.selectAll = selectAll; |
| 20474 |
exports.selection = selection; |
| 20475 |
exports.selector = selector; |
| 20476 |
exports.selectorAll = selectorAll; |
| 20477 |
exports.shuffle = shuffle$1; |
| 20478 |
exports.shuffler = shuffler; |
| 20479 |
exports.some = some; |
| 20480 |
exports.sort = sort; |
| 20481 |
exports.stack = stack; |
| 20482 |
exports.stackOffsetDiverging = diverging; |
| 20483 |
exports.stackOffsetExpand = expand; |
| 20484 |
exports.stackOffsetNone = none$1; |
| 20485 |
exports.stackOffsetSilhouette = silhouette; |
| 20486 |
exports.stackOffsetWiggle = wiggle; |
| 20487 |
exports.stackOrderAppearance = appearance; |
| 20488 |
exports.stackOrderAscending = ascending; |
| 20489 |
exports.stackOrderDescending = descending; |
| 20490 |
exports.stackOrderInsideOut = insideOut; |
| 20491 |
exports.stackOrderNone = none; |
| 20492 |
exports.stackOrderReverse = reverse; |
| 20493 |
exports.stratify = stratify; |
| 20494 |
exports.style = styleValue; |
| 20495 |
exports.subset = subset; |
| 20496 |
exports.sum = sum$2; |
| 20497 |
exports.superset = superset; |
| 20498 |
exports.svg = svg; |
| 20499 |
exports.symbol = Symbol$1; |
| 20500 |
exports.symbolAsterisk = asterisk; |
| 20501 |
exports.symbolCircle = circle; |
| 20502 |
exports.symbolCross = cross; |
| 20503 |
exports.symbolDiamond = diamond; |
| 20504 |
exports.symbolDiamond2 = diamond2; |
| 20505 |
exports.symbolPlus = plus; |
| 20506 |
exports.symbolSquare = square; |
| 20507 |
exports.symbolSquare2 = square2; |
| 20508 |
exports.symbolStar = star; |
| 20509 |
exports.symbolTimes = times; |
| 20510 |
exports.symbolTriangle = triangle; |
| 20511 |
exports.symbolTriangle2 = triangle2; |
| 20512 |
exports.symbolWye = wye; |
| 20513 |
exports.symbolX = times; |
| 20514 |
exports.symbols = symbolsFill; |
| 20515 |
exports.symbolsFill = symbolsFill; |
| 20516 |
exports.symbolsStroke = symbolsStroke; |
| 20517 |
exports.text = text; |
| 20518 |
exports.thresholdFreedmanDiaconis = thresholdFreedmanDiaconis; |
| 20519 |
exports.thresholdScott = thresholdScott; |
| 20520 |
exports.thresholdSturges = thresholdSturges; |
| 20521 |
exports.tickFormat = tickFormat; |
| 20522 |
exports.tickIncrement = tickIncrement; |
| 20523 |
exports.tickStep = tickStep; |
| 20524 |
exports.ticks = ticks; |
| 20525 |
exports.timeDay = timeDay; |
| 20526 |
exports.timeDays = timeDays; |
| 20527 |
exports.timeFormatDefaultLocale = defaultLocale; |
| 20528 |
exports.timeFormatLocale = formatLocale; |
| 20529 |
exports.timeFriday = timeFriday; |
| 20530 |
exports.timeFridays = timeFridays; |
| 20531 |
exports.timeHour = timeHour; |
| 20532 |
exports.timeHours = timeHours; |
| 20533 |
exports.timeInterval = timeInterval; |
| 20534 |
exports.timeMillisecond = millisecond; |
| 20535 |
exports.timeMilliseconds = milliseconds; |
| 20536 |
exports.timeMinute = timeMinute; |
| 20537 |
exports.timeMinutes = timeMinutes; |
| 20538 |
exports.timeMonday = timeMonday; |
| 20539 |
exports.timeMondays = timeMondays; |
| 20540 |
exports.timeMonth = timeMonth; |
| 20541 |
exports.timeMonths = timeMonths; |
| 20542 |
exports.timeSaturday = timeSaturday; |
| 20543 |
exports.timeSaturdays = timeSaturdays; |
| 20544 |
exports.timeSecond = second; |
| 20545 |
exports.timeSeconds = seconds; |
| 20546 |
exports.timeSunday = timeSunday; |
| 20547 |
exports.timeSundays = timeSundays; |
| 20548 |
exports.timeThursday = timeThursday; |
| 20549 |
exports.timeThursdays = timeThursdays; |
| 20550 |
exports.timeTickInterval = timeTickInterval; |
| 20551 |
exports.timeTicks = timeTicks; |
| 20552 |
exports.timeTuesday = timeTuesday; |
| 20553 |
exports.timeTuesdays = timeTuesdays; |
| 20554 |
exports.timeWednesday = timeWednesday; |
| 20555 |
exports.timeWednesdays = timeWednesdays; |
| 20556 |
exports.timeWeek = timeSunday; |
| 20557 |
exports.timeWeeks = timeSundays; |
| 20558 |
exports.timeYear = timeYear; |
| 20559 |
exports.timeYears = timeYears; |
| 20560 |
exports.timeout = timeout; |
| 20561 |
exports.timer = timer; |
| 20562 |
exports.timerFlush = timerFlush; |
| 20563 |
exports.transition = transition; |
| 20564 |
exports.transpose = transpose; |
| 20565 |
exports.tree = tree; |
| 20566 |
exports.treemap = index; |
| 20567 |
exports.treemapBinary = binary; |
| 20568 |
exports.treemapDice = treemapDice; |
| 20569 |
exports.treemapResquarify = resquarify; |
| 20570 |
exports.treemapSlice = treemapSlice; |
| 20571 |
exports.treemapSliceDice = sliceDice; |
| 20572 |
exports.treemapSquarify = squarify; |
| 20573 |
exports.tsv = tsv; |
| 20574 |
exports.tsvFormat = tsvFormat; |
| 20575 |
exports.tsvFormatBody = tsvFormatBody; |
| 20576 |
exports.tsvFormatRow = tsvFormatRow; |
| 20577 |
exports.tsvFormatRows = tsvFormatRows; |
| 20578 |
exports.tsvFormatValue = tsvFormatValue; |
| 20579 |
exports.tsvParse = tsvParse; |
| 20580 |
exports.tsvParseRows = tsvParseRows; |
| 20581 |
exports.union = union; |
| 20582 |
exports.unixDay = unixDay; |
| 20583 |
exports.unixDays = unixDays; |
| 20584 |
exports.utcDay = utcDay; |
| 20585 |
exports.utcDays = utcDays; |
| 20586 |
exports.utcFriday = utcFriday; |
| 20587 |
exports.utcFridays = utcFridays; |
| 20588 |
exports.utcHour = utcHour; |
| 20589 |
exports.utcHours = utcHours; |
| 20590 |
exports.utcMillisecond = millisecond; |
| 20591 |
exports.utcMilliseconds = milliseconds; |
| 20592 |
exports.utcMinute = utcMinute; |
| 20593 |
exports.utcMinutes = utcMinutes; |
| 20594 |
exports.utcMonday = utcMonday; |
| 20595 |
exports.utcMondays = utcMondays; |
| 20596 |
exports.utcMonth = utcMonth; |
| 20597 |
exports.utcMonths = utcMonths; |
| 20598 |
exports.utcSaturday = utcSaturday; |
| 20599 |
exports.utcSaturdays = utcSaturdays; |
| 20600 |
exports.utcSecond = second; |
| 20601 |
exports.utcSeconds = seconds; |
| 20602 |
exports.utcSunday = utcSunday; |
| 20603 |
exports.utcSundays = utcSundays; |
| 20604 |
exports.utcThursday = utcThursday; |
| 20605 |
exports.utcThursdays = utcThursdays; |
| 20606 |
exports.utcTickInterval = utcTickInterval; |
| 20607 |
exports.utcTicks = utcTicks; |
| 20608 |
exports.utcTuesday = utcTuesday; |
| 20609 |
exports.utcTuesdays = utcTuesdays; |
| 20610 |
exports.utcWednesday = utcWednesday; |
| 20611 |
exports.utcWednesdays = utcWednesdays; |
| 20612 |
exports.utcWeek = utcSunday; |
| 20613 |
exports.utcWeeks = utcSundays; |
| 20614 |
exports.utcYear = utcYear; |
| 20615 |
exports.utcYears = utcYears; |
| 20616 |
exports.variance = variance; |
| 20617 |
exports.version = version; |
| 20618 |
exports.window = defaultView; |
| 20619 |
exports.xml = xml; |
| 20620 |
exports.zip = zip; |
| 20621 |
exports.zoom = zoom; |
| 20622 |
exports.zoomIdentity = identity; |
| 20623 |
exports.zoomTransform = transform; |
| 20624 |
|
| 20625 |
})); |