Spaces:
Build error
Build error
File size: 39,479 Bytes
c211499 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 |
// https://d3js.org/d3-array/ v3.2.3 Copyright 2010-2023 Mike Bostock
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}));
})(this, (function (exports) { 'use strict';
function ascending(a, b) {
return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
function descending(a, b) {
return a == null || b == null ? NaN
: b < a ? -1
: b > a ? 1
: b >= a ? 0
: NaN;
}
function bisector(f) {
let compare1, compare2, delta;
// If an accessor is specified, promote it to a comparator. In this case we
// can test whether the search value is (self-) comparable. We can’t do this
// for a comparator (except for specific, known comparators) because we can’t
// tell if the comparator is symmetric, and an asymmetric comparator can’t be
// used to test whether a single value is comparable.
if (f.length !== 2) {
compare1 = ascending;
compare2 = (d, x) => ascending(f(d), x);
delta = (d, x) => f(d) - x;
} else {
compare1 = f === ascending || f === descending ? f : zero;
compare2 = f;
delta = f;
}
function left(a, x, lo = 0, hi = a.length) {
if (lo < hi) {
if (compare1(x, x) !== 0) return hi;
do {
const mid = (lo + hi) >>> 1;
if (compare2(a[mid], x) < 0) lo = mid + 1;
else hi = mid;
} while (lo < hi);
}
return lo;
}
function right(a, x, lo = 0, hi = a.length) {
if (lo < hi) {
if (compare1(x, x) !== 0) return hi;
do {
const mid = (lo + hi) >>> 1;
if (compare2(a[mid], x) <= 0) lo = mid + 1;
else hi = mid;
} while (lo < hi);
}
return lo;
}
function center(a, x, lo = 0, hi = a.length) {
const i = left(a, x, lo, hi - 1);
return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
}
return {left, center, right};
}
function zero() {
return 0;
}
function number(x) {
return x === null ? NaN : +x;
}
function* numbers(values, valueof) {
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
yield value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
yield value;
}
}
}
}
const ascendingBisect = bisector(ascending);
const bisectRight = ascendingBisect.right;
const bisectLeft = ascendingBisect.left;
const bisectCenter = bisector(number).center;
var bisect = bisectRight;
function blur(values, r) {
if (!((r = +r) >= 0)) throw new RangeError("invalid r");
let length = values.length;
if (!((length = Math.floor(length)) >= 0)) throw new RangeError("invalid length");
if (!length || !r) return values;
const blur = blurf(r);
const temp = values.slice();
blur(values, temp, 0, length, 1);
blur(temp, values, 0, length, 1);
blur(values, temp, 0, length, 1);
return values;
}
const blur2 = Blur2(blurf);
const blurImage = Blur2(blurfImage);
function Blur2(blur) {
return function(data, rx, ry = rx) {
if (!((rx = +rx) >= 0)) throw new RangeError("invalid rx");
if (!((ry = +ry) >= 0)) throw new RangeError("invalid ry");
let {data: values, width, height} = data;
if (!((width = Math.floor(width)) >= 0)) throw new RangeError("invalid width");
if (!((height = Math.floor(height !== undefined ? height : values.length / width)) >= 0)) throw new RangeError("invalid height");
if (!width || !height || (!rx && !ry)) return data;
const blurx = rx && blur(rx);
const blury = ry && blur(ry);
const temp = values.slice();
if (blurx && blury) {
blurh(blurx, temp, values, width, height);
blurh(blurx, values, temp, width, height);
blurh(blurx, temp, values, width, height);
blurv(blury, values, temp, width, height);
blurv(blury, temp, values, width, height);
blurv(blury, values, temp, width, height);
} else if (blurx) {
blurh(blurx, values, temp, width, height);
blurh(blurx, temp, values, width, height);
blurh(blurx, values, temp, width, height);
} else if (blury) {
blurv(blury, values, temp, width, height);
blurv(blury, temp, values, width, height);
blurv(blury, values, temp, width, height);
}
return data;
};
}
function blurh(blur, T, S, w, h) {
for (let y = 0, n = w * h; y < n;) {
blur(T, S, y, y += w, 1);
}
}
function blurv(blur, T, S, w, h) {
for (let x = 0, n = w * h; x < w; ++x) {
blur(T, S, x, x + n, w);
}
}
function blurfImage(radius) {
const blur = blurf(radius);
return (T, S, start, stop, step) => {
start <<= 2, stop <<= 2, step <<= 2;
blur(T, S, start + 0, stop + 0, step);
blur(T, S, start + 1, stop + 1, step);
blur(T, S, start + 2, stop + 2, step);
blur(T, S, start + 3, stop + 3, step);
};
}
// Given a target array T, a source array S, sets each value T[i] to the average
// of {S[i - r], …, S[i], …, S[i + r]}, where r = ⌊radius⌋, start <= i < stop,
// for each i, i + step, i + 2 * step, etc., and where S[j] is clamped between
// S[start] (inclusive) and S[stop] (exclusive). If the given radius is not an
// integer, S[i - r - 1] and S[i + r + 1] are added to the sum, each weighted
// according to r - ⌊radius⌋.
function blurf(radius) {
const radius0 = Math.floor(radius);
if (radius0 === radius) return bluri(radius);
const t = radius - radius0;
const w = 2 * radius + 1;
return (T, S, start, stop, step) => { // stop must be aligned!
if (!((stop -= step) >= start)) return; // inclusive stop
let sum = radius0 * S[start];
const s0 = step * radius0;
const s1 = s0 + step;
for (let i = start, j = start + s0; i < j; i += step) {
sum += S[Math.min(stop, i)];
}
for (let i = start, j = stop; i <= j; i += step) {
sum += S[Math.min(stop, i + s0)];
T[i] = (sum + t * (S[Math.max(start, i - s1)] + S[Math.min(stop, i + s1)])) / w;
sum -= S[Math.max(start, i - s0)];
}
};
}
// Like blurf, but optimized for integer radius.
function bluri(radius) {
const w = 2 * radius + 1;
return (T, S, start, stop, step) => { // stop must be aligned!
if (!((stop -= step) >= start)) return; // inclusive stop
let sum = radius * S[start];
const s = step * radius;
for (let i = start, j = start + s; i < j; i += step) {
sum += S[Math.min(stop, i)];
}
for (let i = start, j = stop; i <= j; i += step) {
sum += S[Math.min(stop, i + s)];
T[i] = sum / w;
sum -= S[Math.max(start, i - s)];
}
};
}
function count(values, valueof) {
let count = 0;
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
++count;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
++count;
}
}
}
return count;
}
function length$1(array) {
return array.length | 0;
}
function empty(length) {
return !(length > 0);
}
function arrayify(values) {
return typeof values !== "object" || "length" in values ? values : Array.from(values);
}
function reducer(reduce) {
return values => reduce(...values);
}
function cross(...values) {
const reduce = typeof values[values.length - 1] === "function" && reducer(values.pop());
values = values.map(arrayify);
const lengths = values.map(length$1);
const j = values.length - 1;
const index = new Array(j + 1).fill(0);
const product = [];
if (j < 0 || lengths.some(empty)) return product;
while (true) {
product.push(index.map((j, i) => values[i][j]));
let i = j;
while (++index[i] === lengths[i]) {
if (i === 0) return reduce ? product.map(reduce) : product;
index[i--] = 0;
}
}
}
function cumsum(values, valueof) {
var sum = 0, index = 0;
return Float64Array.from(values, valueof === undefined
? v => (sum += +v || 0)
: v => (sum += +valueof(v, index++, values) || 0));
}
function variance(values, valueof) {
let count = 0;
let delta;
let mean = 0;
let sum = 0;
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
delta = value - mean;
mean += delta / ++count;
sum += delta * (value - mean);
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
delta = value - mean;
mean += delta / ++count;
sum += delta * (value - mean);
}
}
}
if (count > 1) return sum / (count - 1);
}
function deviation(values, valueof) {
const v = variance(values, valueof);
return v ? Math.sqrt(v) : v;
}
function extent(values, valueof) {
let min;
let max;
if (valueof === undefined) {
for (const value of values) {
if (value != null) {
if (min === undefined) {
if (value >= value) min = max = value;
} else {
if (min > value) min = value;
if (max < value) max = value;
}
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null) {
if (min === undefined) {
if (value >= value) min = max = value;
} else {
if (min > value) min = value;
if (max < value) max = value;
}
}
}
}
return [min, max];
}
// https://github.com/python/cpython/blob/a74eea238f5baba15797e2e8b570d153bc8690a7/Modules/mathmodule.c#L1423
class Adder {
constructor() {
this._partials = new Float64Array(32);
this._n = 0;
}
add(x) {
const p = this._partials;
let i = 0;
for (let j = 0; j < this._n && j < 32; j++) {
const y = p[j],
hi = x + y,
lo = Math.abs(x) < Math.abs(y) ? x - (hi - y) : y - (hi - x);
if (lo) p[i++] = lo;
x = hi;
}
p[i] = x;
this._n = i + 1;
return this;
}
valueOf() {
const p = this._partials;
let n = this._n, x, y, lo, hi = 0;
if (n > 0) {
hi = p[--n];
while (n > 0) {
x = hi;
y = p[--n];
hi = x + y;
lo = y - (hi - x);
if (lo) break;
}
if (n > 0 && ((lo < 0 && p[n - 1] < 0) || (lo > 0 && p[n - 1] > 0))) {
y = lo * 2;
x = hi + y;
if (y == x - hi) hi = x;
}
}
return hi;
}
}
function fsum(values, valueof) {
const adder = new Adder();
if (valueof === undefined) {
for (let value of values) {
if (value = +value) {
adder.add(value);
}
}
} else {
let index = -1;
for (let value of values) {
if (value = +valueof(value, ++index, values)) {
adder.add(value);
}
}
}
return +adder;
}
function fcumsum(values, valueof) {
const adder = new Adder();
let index = -1;
return Float64Array.from(values, valueof === undefined
? v => adder.add(+v || 0)
: v => adder.add(+valueof(v, ++index, values) || 0)
);
}
class InternMap extends Map {
constructor(entries, key = keyof) {
super();
Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
if (entries != null) for (const [key, value] of entries) this.set(key, value);
}
get(key) {
return super.get(intern_get(this, key));
}
has(key) {
return super.has(intern_get(this, key));
}
set(key, value) {
return super.set(intern_set(this, key), value);
}
delete(key) {
return super.delete(intern_delete(this, key));
}
}
class InternSet extends Set {
constructor(values, key = keyof) {
super();
Object.defineProperties(this, {_intern: {value: new Map()}, _key: {value: key}});
if (values != null) for (const value of values) this.add(value);
}
has(value) {
return super.has(intern_get(this, value));
}
add(value) {
return super.add(intern_set(this, value));
}
delete(value) {
return super.delete(intern_delete(this, value));
}
}
function intern_get({_intern, _key}, value) {
const key = _key(value);
return _intern.has(key) ? _intern.get(key) : value;
}
function intern_set({_intern, _key}, value) {
const key = _key(value);
if (_intern.has(key)) return _intern.get(key);
_intern.set(key, value);
return value;
}
function intern_delete({_intern, _key}, value) {
const key = _key(value);
if (_intern.has(key)) {
value = _intern.get(key);
_intern.delete(key);
}
return value;
}
function keyof(value) {
return value !== null && typeof value === "object" ? value.valueOf() : value;
}
function identity(x) {
return x;
}
function group(values, ...keys) {
return nest(values, identity, identity, keys);
}
function groups(values, ...keys) {
return nest(values, Array.from, identity, keys);
}
function flatten$1(groups, keys) {
for (let i = 1, n = keys.length; i < n; ++i) {
groups = groups.flatMap(g => g.pop().map(([key, value]) => [...g, key, value]));
}
return groups;
}
function flatGroup(values, ...keys) {
return flatten$1(groups(values, ...keys), keys);
}
function flatRollup(values, reduce, ...keys) {
return flatten$1(rollups(values, reduce, ...keys), keys);
}
function rollup(values, reduce, ...keys) {
return nest(values, identity, reduce, keys);
}
function rollups(values, reduce, ...keys) {
return nest(values, Array.from, reduce, keys);
}
function index(values, ...keys) {
return nest(values, identity, unique, keys);
}
function indexes(values, ...keys) {
return nest(values, Array.from, unique, keys);
}
function unique(values) {
if (values.length !== 1) throw new Error("duplicate key");
return values[0];
}
function nest(values, map, reduce, keys) {
return (function regroup(values, i) {
if (i >= keys.length) return reduce(values);
const groups = new InternMap();
const keyof = keys[i++];
let index = -1;
for (const value of values) {
const key = keyof(value, ++index, values);
const group = groups.get(key);
if (group) group.push(value);
else groups.set(key, [value]);
}
for (const [key, values] of groups) {
groups.set(key, regroup(values, i));
}
return map(groups);
})(values, 0);
}
function permute(source, keys) {
return Array.from(keys, key => source[key]);
}
function sort(values, ...F) {
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
values = Array.from(values);
let [f] = F;
if ((f && f.length !== 2) || F.length > 1) {
const index = Uint32Array.from(values, (d, i) => i);
if (F.length > 1) {
F = F.map(f => values.map(f));
index.sort((i, j) => {
for (const f of F) {
const c = ascendingDefined(f[i], f[j]);
if (c) return c;
}
});
} else {
f = values.map(f);
index.sort((i, j) => ascendingDefined(f[i], f[j]));
}
return permute(values, index);
}
return values.sort(compareDefined(f));
}
function compareDefined(compare = ascending) {
if (compare === ascending) return ascendingDefined;
if (typeof compare !== "function") throw new TypeError("compare is not a function");
return (a, b) => {
const x = compare(a, b);
if (x || x === 0) return x;
return (compare(b, b) === 0) - (compare(a, a) === 0);
};
}
function ascendingDefined(a, b) {
return (a == null || !(a >= a)) - (b == null || !(b >= b)) || (a < b ? -1 : a > b ? 1 : 0);
}
function groupSort(values, reduce, key) {
return (reduce.length !== 2
? sort(rollup(values, reduce, key), (([ak, av], [bk, bv]) => ascending(av, bv) || ascending(ak, bk)))
: sort(group(values, key), (([ak, av], [bk, bv]) => reduce(av, bv) || ascending(ak, bk))))
.map(([key]) => key);
}
var array = Array.prototype;
var slice = array.slice;
function constant(x) {
return () => x;
}
const e10 = Math.sqrt(50),
e5 = Math.sqrt(10),
e2 = Math.sqrt(2);
function tickSpec(start, stop, count) {
const step = (stop - start) / Math.max(0, count),
power = Math.floor(Math.log10(step)),
error = step / Math.pow(10, power),
factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1;
let i1, i2, inc;
if (power < 0) {
inc = Math.pow(10, -power) / factor;
i1 = Math.round(start * inc);
i2 = Math.round(stop * inc);
if (i1 / inc < start) ++i1;
if (i2 / inc > stop) --i2;
inc = -inc;
} else {
inc = Math.pow(10, power) * factor;
i1 = Math.round(start / inc);
i2 = Math.round(stop / inc);
if (i1 * inc < start) ++i1;
if (i2 * inc > stop) --i2;
}
if (i2 < i1 && 0.5 <= count && count < 2) return tickSpec(start, stop, count * 2);
return [i1, i2, inc];
}
function ticks(start, stop, count) {
stop = +stop, start = +start, count = +count;
if (!(count > 0)) return [];
if (start === stop) return [start];
const reverse = stop < start, [i1, i2, inc] = reverse ? tickSpec(stop, start, count) : tickSpec(start, stop, count);
if (!(i2 >= i1)) return [];
const n = i2 - i1 + 1, ticks = new Array(n);
if (reverse) {
if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) / -inc;
else for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) * inc;
} else {
if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) / -inc;
else for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) * inc;
}
return ticks;
}
function tickIncrement(start, stop, count) {
stop = +stop, start = +start, count = +count;
return tickSpec(start, stop, count)[2];
}
function tickStep(start, stop, count) {
stop = +stop, start = +start, count = +count;
const reverse = stop < start, inc = reverse ? tickIncrement(stop, start, count) : tickIncrement(start, stop, count);
return (reverse ? -1 : 1) * (inc < 0 ? 1 / -inc : inc);
}
function nice(start, stop, count) {
let prestep;
while (true) {
const step = tickIncrement(start, stop, count);
if (step === prestep || step === 0 || !isFinite(step)) {
return [start, stop];
} else if (step > 0) {
start = Math.floor(start / step) * step;
stop = Math.ceil(stop / step) * step;
} else if (step < 0) {
start = Math.ceil(start * step) / step;
stop = Math.floor(stop * step) / step;
}
prestep = step;
}
}
function thresholdSturges(values) {
return Math.max(1, Math.ceil(Math.log(count(values)) / Math.LN2) + 1);
}
function bin() {
var value = identity,
domain = extent,
threshold = thresholdSturges;
function histogram(data) {
if (!Array.isArray(data)) data = Array.from(data);
var i,
n = data.length,
x,
step,
values = new Array(n);
for (i = 0; i < n; ++i) {
values[i] = value(data[i], i, data);
}
var xz = domain(values),
x0 = xz[0],
x1 = xz[1],
tz = threshold(values, x0, x1);
// Convert number of thresholds into uniform thresholds, and nice the
// default domain accordingly.
if (!Array.isArray(tz)) {
const max = x1, tn = +tz;
if (domain === extent) [x0, x1] = nice(x0, x1, tn);
tz = ticks(x0, x1, tn);
// If the domain is aligned with the first tick (which it will by
// default), then we can use quantization rather than bisection to bin
// values, which is substantially faster.
if (tz[0] <= x0) step = tickIncrement(x0, x1, tn);
// If the last threshold is coincident with the domain’s upper bound, the
// last bin will be zero-width. If the default domain is used, and this
// last threshold is coincident with the maximum input value, we can
// extend the niced upper bound by one tick to ensure uniform bin widths;
// otherwise, we simply remove the last threshold. Note that we don’t
// coerce values or the domain to numbers, and thus must be careful to
// compare order (>=) rather than strict equality (===)!
if (tz[tz.length - 1] >= x1) {
if (max >= x1 && domain === extent) {
const step = tickIncrement(x0, x1, tn);
if (isFinite(step)) {
if (step > 0) {
x1 = (Math.floor(x1 / step) + 1) * step;
} else if (step < 0) {
x1 = (Math.ceil(x1 * -step) + 1) / -step;
}
}
} else {
tz.pop();
}
}
}
// Remove any thresholds outside the domain.
// Be careful not to mutate an array owned by the user!
var m = tz.length, a = 0, b = m;
while (tz[a] <= x0) ++a;
while (tz[b - 1] > x1) --b;
if (a || b < m) tz = tz.slice(a, b), m = b - a;
var bins = new Array(m + 1),
bin;
// Initialize bins.
for (i = 0; i <= m; ++i) {
bin = bins[i] = [];
bin.x0 = i > 0 ? tz[i - 1] : x0;
bin.x1 = i < m ? tz[i] : x1;
}
// Assign data to bins by value, ignoring any outside the domain.
if (isFinite(step)) {
if (step > 0) {
for (i = 0; i < n; ++i) {
if ((x = values[i]) != null && x0 <= x && x <= x1) {
bins[Math.min(m, Math.floor((x - x0) / step))].push(data[i]);
}
}
} else if (step < 0) {
for (i = 0; i < n; ++i) {
if ((x = values[i]) != null && x0 <= x && x <= x1) {
const j = Math.floor((x0 - x) * step);
bins[Math.min(m, j + (tz[j] <= x))].push(data[i]); // handle off-by-one due to rounding
}
}
}
} else {
for (i = 0; i < n; ++i) {
if ((x = values[i]) != null && x0 <= x && x <= x1) {
bins[bisect(tz, x, 0, m)].push(data[i]);
}
}
}
return bins;
}
histogram.value = function(_) {
return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
};
histogram.domain = function(_) {
return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
};
histogram.thresholds = function(_) {
return arguments.length ? (threshold = typeof _ === "function" ? _ : constant(Array.isArray(_) ? slice.call(_) : _), histogram) : threshold;
};
return histogram;
}
function max(values, valueof) {
let max;
if (valueof === undefined) {
for (const value of values) {
if (value != null
&& (max < value || (max === undefined && value >= value))) {
max = value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null
&& (max < value || (max === undefined && value >= value))) {
max = value;
}
}
}
return max;
}
function maxIndex(values, valueof) {
let max;
let maxIndex = -1;
let index = -1;
if (valueof === undefined) {
for (const value of values) {
++index;
if (value != null
&& (max < value || (max === undefined && value >= value))) {
max = value, maxIndex = index;
}
}
} else {
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null
&& (max < value || (max === undefined && value >= value))) {
max = value, maxIndex = index;
}
}
}
return maxIndex;
}
function min(values, valueof) {
let min;
if (valueof === undefined) {
for (const value of values) {
if (value != null
&& (min > value || (min === undefined && value >= value))) {
min = value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null
&& (min > value || (min === undefined && value >= value))) {
min = value;
}
}
}
return min;
}
function minIndex(values, valueof) {
let min;
let minIndex = -1;
let index = -1;
if (valueof === undefined) {
for (const value of values) {
++index;
if (value != null
&& (min > value || (min === undefined && value >= value))) {
min = value, minIndex = index;
}
}
} else {
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null
&& (min > value || (min === undefined && value >= value))) {
min = value, minIndex = index;
}
}
}
return minIndex;
}
// Based on https://github.com/mourner/quickselect
// ISC license, Copyright 2018 Vladimir Agafonkin.
function quickselect(array, k, left = 0, right = Infinity, compare) {
k = Math.floor(k);
left = Math.floor(Math.max(0, left));
right = Math.floor(Math.min(array.length - 1, right));
if (!(left <= k && k <= right)) return array;
compare = compare === undefined ? ascendingDefined : compareDefined(compare);
while (right > left) {
if (right - left > 600) {
const n = right - left + 1;
const m = k - left + 1;
const z = Math.log(n);
const s = 0.5 * Math.exp(2 * z / 3);
const sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
const newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
const newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
quickselect(array, k, newLeft, newRight, compare);
}
const t = array[k];
let i = left;
let j = right;
swap(array, left, k);
if (compare(array[right], t) > 0) swap(array, left, right);
while (i < j) {
swap(array, i, j), ++i, --j;
while (compare(array[i], t) < 0) ++i;
while (compare(array[j], t) > 0) --j;
}
if (compare(array[left], t) === 0) swap(array, left, j);
else ++j, swap(array, j, right);
if (j <= k) left = j + 1;
if (k <= j) right = j - 1;
}
return array;
}
function swap(array, i, j) {
const t = array[i];
array[i] = array[j];
array[j] = t;
}
function greatest(values, compare = ascending) {
let max;
let defined = false;
if (compare.length === 1) {
let maxValue;
for (const element of values) {
const value = compare(element);
if (defined
? ascending(value, maxValue) > 0
: ascending(value, value) === 0) {
max = element;
maxValue = value;
defined = true;
}
}
} else {
for (const value of values) {
if (defined
? compare(value, max) > 0
: compare(value, value) === 0) {
max = value;
defined = true;
}
}
}
return max;
}
function quantile(values, p, valueof) {
values = Float64Array.from(numbers(values, valueof));
if (!(n = values.length) || isNaN(p = +p)) return;
if (p <= 0 || n < 2) return min(values);
if (p >= 1) return max(values);
var n,
i = (n - 1) * p,
i0 = Math.floor(i),
value0 = max(quickselect(values, i0).subarray(0, i0 + 1)),
value1 = min(values.subarray(i0 + 1));
return value0 + (value1 - value0) * (i - i0);
}
function quantileSorted(values, p, valueof = number) {
if (!(n = values.length) || isNaN(p = +p)) return;
if (p <= 0 || n < 2) return +valueof(values[0], 0, values);
if (p >= 1) return +valueof(values[n - 1], n - 1, values);
var n,
i = (n - 1) * p,
i0 = Math.floor(i),
value0 = +valueof(values[i0], i0, values),
value1 = +valueof(values[i0 + 1], i0 + 1, values);
return value0 + (value1 - value0) * (i - i0);
}
function quantileIndex(values, p, valueof) {
values = Float64Array.from(numbers(values, valueof));
if (!(n = values.length) || isNaN(p = +p)) return;
if (p <= 0 || n < 2) return minIndex(values);
if (p >= 1) return maxIndex(values);
var n,
i = Math.floor((n - 1) * p),
order = (i, j) => ascendingDefined(values[i], values[j]),
index = quickselect(Uint32Array.from(values, (_, i) => i), i, 0, n - 1, order);
return greatest(index.subarray(0, i + 1), i => values[i]);
}
function thresholdFreedmanDiaconis(values, min, max) {
const c = count(values), d = quantile(values, 0.75) - quantile(values, 0.25);
return c && d ? Math.ceil((max - min) / (2 * d * Math.pow(c, -1 / 3))) : 1;
}
function thresholdScott(values, min, max) {
const c = count(values), d = deviation(values);
return c && d ? Math.ceil((max - min) * Math.cbrt(c) / (3.49 * d)) : 1;
}
function mean(values, valueof) {
let count = 0;
let sum = 0;
if (valueof === undefined) {
for (let value of values) {
if (value != null && (value = +value) >= value) {
++count, sum += value;
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && (value = +value) >= value) {
++count, sum += value;
}
}
}
if (count) return sum / count;
}
function median(values, valueof) {
return quantile(values, 0.5, valueof);
}
function medianIndex(values, valueof) {
return quantileIndex(values, 0.5, valueof);
}
function* flatten(arrays) {
for (const array of arrays) {
yield* array;
}
}
function merge(arrays) {
return Array.from(flatten(arrays));
}
function mode(values, valueof) {
const counts = new InternMap();
if (valueof === undefined) {
for (let value of values) {
if (value != null && value >= value) {
counts.set(value, (counts.get(value) || 0) + 1);
}
}
} else {
let index = -1;
for (let value of values) {
if ((value = valueof(value, ++index, values)) != null && value >= value) {
counts.set(value, (counts.get(value) || 0) + 1);
}
}
}
let modeValue;
let modeCount = 0;
for (const [value, count] of counts) {
if (count > modeCount) {
modeCount = count;
modeValue = value;
}
}
return modeValue;
}
function pairs(values, pairof = pair) {
const pairs = [];
let previous;
let first = false;
for (const value of values) {
if (first) pairs.push(pairof(previous, value));
previous = value;
first = true;
}
return pairs;
}
function pair(a, b) {
return [a, b];
}
function range(start, stop, step) {
start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
var i = -1,
n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
range = new Array(n);
while (++i < n) {
range[i] = start + i * step;
}
return range;
}
function rank(values, valueof = ascending) {
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
let V = Array.from(values);
const R = new Float64Array(V.length);
if (valueof.length !== 2) V = V.map(valueof), valueof = ascending;
const compareIndex = (i, j) => valueof(V[i], V[j]);
let k, r;
values = Uint32Array.from(V, (_, i) => i);
// Risky chaining due to Safari 14 https://github.com/d3/d3-array/issues/123
values.sort(valueof === ascending ? (i, j) => ascendingDefined(V[i], V[j]) : compareDefined(compareIndex));
values.forEach((j, i) => {
const c = compareIndex(j, k === undefined ? j : k);
if (c >= 0) {
if (k === undefined || c > 0) k = j, r = i;
R[j] = r;
} else {
R[j] = NaN;
}
});
return R;
}
function least(values, compare = ascending) {
let min;
let defined = false;
if (compare.length === 1) {
let minValue;
for (const element of values) {
const value = compare(element);
if (defined
? ascending(value, minValue) < 0
: ascending(value, value) === 0) {
min = element;
minValue = value;
defined = true;
}
}
} else {
for (const value of values) {
if (defined
? compare(value, min) < 0
: compare(value, value) === 0) {
min = value;
defined = true;
}
}
}
return min;
}
function leastIndex(values, compare = ascending) {
if (compare.length === 1) return minIndex(values, compare);
let minValue;
let min = -1;
let index = -1;
for (const value of values) {
++index;
if (min < 0
? compare(value, value) === 0
: compare(value, minValue) < 0) {
minValue = value;
min = index;
}
}
return min;
}
function greatestIndex(values, compare = ascending) {
if (compare.length === 1) return maxIndex(values, compare);
let maxValue;
let max = -1;
let index = -1;
for (const value of values) {
++index;
if (max < 0
? compare(value, value) === 0
: compare(value, maxValue) > 0) {
maxValue = value;
max = index;
}
}
return max;
}
function scan(values, compare) {
const index = leastIndex(values, compare);
return index < 0 ? undefined : index;
}
var shuffle = shuffler(Math.random);
function shuffler(random) {
return function shuffle(array, i0 = 0, i1 = array.length) {
let m = i1 - (i0 = +i0);
while (m) {
const i = random() * m-- | 0, t = array[m + i0];
array[m + i0] = array[i + i0];
array[i + i0] = t;
}
return array;
};
}
function sum(values, valueof) {
let sum = 0;
if (valueof === undefined) {
for (let value of values) {
if (value = +value) {
sum += value;
}
}
} else {
let index = -1;
for (let value of values) {
if (value = +valueof(value, ++index, values)) {
sum += value;
}
}
}
return sum;
}
function transpose(matrix) {
if (!(n = matrix.length)) return [];
for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
row[j] = matrix[j][i];
}
}
return transpose;
}
function length(d) {
return d.length;
}
function zip() {
return transpose(arguments);
}
function every(values, test) {
if (typeof test !== "function") throw new TypeError("test is not a function");
let index = -1;
for (const value of values) {
if (!test(value, ++index, values)) {
return false;
}
}
return true;
}
function some(values, test) {
if (typeof test !== "function") throw new TypeError("test is not a function");
let index = -1;
for (const value of values) {
if (test(value, ++index, values)) {
return true;
}
}
return false;
}
function filter(values, test) {
if (typeof test !== "function") throw new TypeError("test is not a function");
const array = [];
let index = -1;
for (const value of values) {
if (test(value, ++index, values)) {
array.push(value);
}
}
return array;
}
function map(values, mapper) {
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
if (typeof mapper !== "function") throw new TypeError("mapper is not a function");
return Array.from(values, (value, index) => mapper(value, index, values));
}
function reduce(values, reducer, value) {
if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
const iterator = values[Symbol.iterator]();
let done, next, index = -1;
if (arguments.length < 3) {
({done, value} = iterator.next());
if (done) return;
++index;
}
while (({done, value: next} = iterator.next()), !done) {
value = reducer(value, next, ++index, values);
}
return value;
}
function reverse(values) {
if (typeof values[Symbol.iterator] !== "function") throw new TypeError("values is not iterable");
return Array.from(values).reverse();
}
function difference(values, ...others) {
values = new InternSet(values);
for (const other of others) {
for (const value of other) {
values.delete(value);
}
}
return values;
}
function disjoint(values, other) {
const iterator = other[Symbol.iterator](), set = new InternSet();
for (const v of values) {
if (set.has(v)) return false;
let value, done;
while (({value, done} = iterator.next())) {
if (done) break;
if (Object.is(v, value)) return false;
set.add(value);
}
}
return true;
}
function intersection(values, ...others) {
values = new InternSet(values);
others = others.map(set);
out: for (const value of values) {
for (const other of others) {
if (!other.has(value)) {
values.delete(value);
continue out;
}
}
}
return values;
}
function set(values) {
return values instanceof InternSet ? values : new InternSet(values);
}
function superset(values, other) {
const iterator = values[Symbol.iterator](), set = new Set();
for (const o of other) {
const io = intern(o);
if (set.has(io)) continue;
let value, done;
while (({value, done} = iterator.next())) {
if (done) return false;
const ivalue = intern(value);
set.add(ivalue);
if (Object.is(io, ivalue)) break;
}
}
return true;
}
function intern(value) {
return value !== null && typeof value === "object" ? value.valueOf() : value;
}
function subset(values, other) {
return superset(other, values);
}
function union(...others) {
const set = new InternSet();
for (const other of others) {
for (const o of other) {
set.add(o);
}
}
return set;
}
exports.Adder = Adder;
exports.InternMap = InternMap;
exports.InternSet = InternSet;
exports.ascending = ascending;
exports.bin = bin;
exports.bisect = bisect;
exports.bisectCenter = bisectCenter;
exports.bisectLeft = bisectLeft;
exports.bisectRight = bisectRight;
exports.bisector = bisector;
exports.blur = blur;
exports.blur2 = blur2;
exports.blurImage = blurImage;
exports.count = count;
exports.cross = cross;
exports.cumsum = cumsum;
exports.descending = descending;
exports.deviation = deviation;
exports.difference = difference;
exports.disjoint = disjoint;
exports.every = every;
exports.extent = extent;
exports.fcumsum = fcumsum;
exports.filter = filter;
exports.flatGroup = flatGroup;
exports.flatRollup = flatRollup;
exports.fsum = fsum;
exports.greatest = greatest;
exports.greatestIndex = greatestIndex;
exports.group = group;
exports.groupSort = groupSort;
exports.groups = groups;
exports.histogram = bin;
exports.index = index;
exports.indexes = indexes;
exports.intersection = intersection;
exports.least = least;
exports.leastIndex = leastIndex;
exports.map = map;
exports.max = max;
exports.maxIndex = maxIndex;
exports.mean = mean;
exports.median = median;
exports.medianIndex = medianIndex;
exports.merge = merge;
exports.min = min;
exports.minIndex = minIndex;
exports.mode = mode;
exports.nice = nice;
exports.pairs = pairs;
exports.permute = permute;
exports.quantile = quantile;
exports.quantileIndex = quantileIndex;
exports.quantileSorted = quantileSorted;
exports.quickselect = quickselect;
exports.range = range;
exports.rank = rank;
exports.reduce = reduce;
exports.reverse = reverse;
exports.rollup = rollup;
exports.rollups = rollups;
exports.scan = scan;
exports.shuffle = shuffle;
exports.shuffler = shuffler;
exports.some = some;
exports.sort = sort;
exports.subset = subset;
exports.sum = sum;
exports.superset = superset;
exports.thresholdFreedmanDiaconis = thresholdFreedmanDiaconis;
exports.thresholdScott = thresholdScott;
exports.thresholdSturges = thresholdSturges;
exports.tickIncrement = tickIncrement;
exports.tickStep = tickStep;
exports.ticks = ticks;
exports.transpose = transpose;
exports.union = union;
exports.variance = variance;
exports.zip = zip;
}));
|