UNPKG

20.3 kBJavaScriptView Raw
1import { X as constant, Z as interpolateNumber, $ as color, a0 as interpolateRgb, a1 as interpolateString } from "./mermaid-4b4b971d.js";
2import { i as initRange } from "./init-cc95ec8e.js";
3function ascending(a, b) {
4 return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
5}
6function descending(a, b) {
7 return a == null || b == null ? NaN : b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
8}
9function bisector(f) {
10 let compare1, compare2, delta;
11 if (f.length !== 2) {
12 compare1 = ascending;
13 compare2 = (d, x) => ascending(f(d), x);
14 delta = (d, x) => f(d) - x;
15 } else {
16 compare1 = f === ascending || f === descending ? f : zero;
17 compare2 = f;
18 delta = f;
19 }
20 function left(a, x, lo = 0, hi = a.length) {
21 if (lo < hi) {
22 if (compare1(x, x) !== 0)
23 return hi;
24 do {
25 const mid = lo + hi >>> 1;
26 if (compare2(a[mid], x) < 0)
27 lo = mid + 1;
28 else
29 hi = mid;
30 } while (lo < hi);
31 }
32 return lo;
33 }
34 function right(a, x, lo = 0, hi = a.length) {
35 if (lo < hi) {
36 if (compare1(x, x) !== 0)
37 return hi;
38 do {
39 const mid = lo + hi >>> 1;
40 if (compare2(a[mid], x) <= 0)
41 lo = mid + 1;
42 else
43 hi = mid;
44 } while (lo < hi);
45 }
46 return lo;
47 }
48 function center(a, x, lo = 0, hi = a.length) {
49 const i = left(a, x, lo, hi - 1);
50 return i > lo && delta(a[i - 1], x) > -delta(a[i], x) ? i - 1 : i;
51 }
52 return { left, center, right };
53}
54function zero() {
55 return 0;
56}
57function number$1(x) {
58 return x === null ? NaN : +x;
59}
60const ascendingBisect = bisector(ascending);
61const bisectRight = ascendingBisect.right;
62bisector(number$1).center;
63const bisect = bisectRight;
64var e10 = Math.sqrt(50), e5 = Math.sqrt(10), e2 = Math.sqrt(2);
65function ticks(start, stop, count) {
66 var reverse, i = -1, n, ticks2, step;
67 stop = +stop, start = +start, count = +count;
68 if (start === stop && count > 0)
69 return [start];
70 if (reverse = stop < start)
71 n = start, start = stop, stop = n;
72 if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step))
73 return [];
74 if (step > 0) {
75 let r0 = Math.round(start / step), r1 = Math.round(stop / step);
76 if (r0 * step < start)
77 ++r0;
78 if (r1 * step > stop)
79 --r1;
80 ticks2 = new Array(n = r1 - r0 + 1);
81 while (++i < n)
82 ticks2[i] = (r0 + i) * step;
83 } else {
84 step = -step;
85 let r0 = Math.round(start * step), r1 = Math.round(stop * step);
86 if (r0 / step < start)
87 ++r0;
88 if (r1 / step > stop)
89 --r1;
90 ticks2 = new Array(n = r1 - r0 + 1);
91 while (++i < n)
92 ticks2[i] = (r0 + i) / step;
93 }
94 if (reverse)
95 ticks2.reverse();
96 return ticks2;
97}
98function tickIncrement(start, stop, count) {
99 var step = (stop - start) / Math.max(0, count), power = Math.floor(Math.log(step) / Math.LN10), error = step / Math.pow(10, power);
100 return power >= 0 ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power) : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
101}
102function tickStep(start, stop, count) {
103 var step0 = Math.abs(stop - start) / Math.max(0, count), step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)), error = step0 / step1;
104 if (error >= e10)
105 step1 *= 10;
106 else if (error >= e5)
107 step1 *= 5;
108 else if (error >= e2)
109 step1 *= 2;
110 return stop < start ? -step1 : step1;
111}
112function numberArray(a, b) {
113 if (!b)
114 b = [];
115 var n = a ? Math.min(b.length, a.length) : 0, c = b.slice(), i;
116 return function(t) {
117 for (i = 0; i < n; ++i)
118 c[i] = a[i] * (1 - t) + b[i] * t;
119 return c;
120 };
121}
122function isNumberArray(x) {
123 return ArrayBuffer.isView(x) && !(x instanceof DataView);
124}
125function genericArray(a, b) {
126 var nb = b ? b.length : 0, na = a ? Math.min(nb, a.length) : 0, x = new Array(na), c = new Array(nb), i;
127 for (i = 0; i < na; ++i)
128 x[i] = interpolate(a[i], b[i]);
129 for (; i < nb; ++i)
130 c[i] = b[i];
131 return function(t) {
132 for (i = 0; i < na; ++i)
133 c[i] = x[i](t);
134 return c;
135 };
136}
137function date(a, b) {
138 var d = /* @__PURE__ */ new Date();
139 return a = +a, b = +b, function(t) {
140 return d.setTime(a * (1 - t) + b * t), d;
141 };
142}
143function object(a, b) {
144 var i = {}, c = {}, k;
145 if (a === null || typeof a !== "object")
146 a = {};
147 if (b === null || typeof b !== "object")
148 b = {};
149 for (k in b) {
150 if (k in a) {
151 i[k] = interpolate(a[k], b[k]);
152 } else {
153 c[k] = b[k];
154 }
155 }
156 return function(t) {
157 for (k in i)
158 c[k] = i[k](t);
159 return c;
160 };
161}
162function interpolate(a, b) {
163 var t = typeof b, c;
164 return b == null || t === "boolean" ? constant(b) : (t === "number" ? interpolateNumber : t === "string" ? (c = color(b)) ? (b = c, interpolateRgb) : interpolateString : b instanceof color ? interpolateRgb : b instanceof Date ? date : isNumberArray(b) ? numberArray : Array.isArray(b) ? genericArray : typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object : interpolateNumber)(a, b);
165}
166function interpolateRound(a, b) {
167 return a = +a, b = +b, function(t) {
168 return Math.round(a * (1 - t) + b * t);
169 };
170}
171function formatDecimal(x) {
172 return Math.abs(x = Math.round(x)) >= 1e21 ? x.toLocaleString("en").replace(/,/g, "") : x.toString(10);
173}
174function formatDecimalParts(x, p) {
175 if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0)
176 return null;
177 var i, coefficient = x.slice(0, i);
178 return [
179 coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
180 +x.slice(i + 1)
181 ];
182}
183function exponent(x) {
184 return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
185}
186function formatGroup(grouping, thousands) {
187 return function(value, width) {
188 var i = value.length, t = [], j = 0, g = grouping[0], length = 0;
189 while (i > 0 && g > 0) {
190 if (length + g + 1 > width)
191 g = Math.max(1, width - length);
192 t.push(value.substring(i -= g, i + g));
193 if ((length += g + 1) > width)
194 break;
195 g = grouping[j = (j + 1) % grouping.length];
196 }
197 return t.reverse().join(thousands);
198 };
199}
200function formatNumerals(numerals) {
201 return function(value) {
202 return value.replace(/[0-9]/g, function(i) {
203 return numerals[+i];
204 });
205 };
206}
207var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
208function formatSpecifier(specifier) {
209 if (!(match = re.exec(specifier)))
210 throw new Error("invalid format: " + specifier);
211 var match;
212 return new FormatSpecifier({
213 fill: match[1],
214 align: match[2],
215 sign: match[3],
216 symbol: match[4],
217 zero: match[5],
218 width: match[6],
219 comma: match[7],
220 precision: match[8] && match[8].slice(1),
221 trim: match[9],
222 type: match[10]
223 });
224}
225formatSpecifier.prototype = FormatSpecifier.prototype;
226function FormatSpecifier(specifier) {
227 this.fill = specifier.fill === void 0 ? " " : specifier.fill + "";
228 this.align = specifier.align === void 0 ? ">" : specifier.align + "";
229 this.sign = specifier.sign === void 0 ? "-" : specifier.sign + "";
230 this.symbol = specifier.symbol === void 0 ? "" : specifier.symbol + "";
231 this.zero = !!specifier.zero;
232 this.width = specifier.width === void 0 ? void 0 : +specifier.width;
233 this.comma = !!specifier.comma;
234 this.precision = specifier.precision === void 0 ? void 0 : +specifier.precision;
235 this.trim = !!specifier.trim;
236 this.type = specifier.type === void 0 ? "" : specifier.type + "";
237}
238FormatSpecifier.prototype.toString = function() {
239 return this.fill + this.align + this.sign + this.symbol + (this.zero ? "0" : "") + (this.width === void 0 ? "" : Math.max(1, this.width | 0)) + (this.comma ? "," : "") + (this.precision === void 0 ? "" : "." + Math.max(0, this.precision | 0)) + (this.trim ? "~" : "") + this.type;
240};
241function formatTrim(s) {
242 out:
243 for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
244 switch (s[i]) {
245 case ".":
246 i0 = i1 = i;
247 break;
248 case "0":
249 if (i0 === 0)
250 i0 = i;
251 i1 = i;
252 break;
253 default:
254 if (!+s[i])
255 break out;
256 if (i0 > 0)
257 i0 = 0;
258 break;
259 }
260 }
261 return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
262}
263var prefixExponent;
264function formatPrefixAuto(x, p) {
265 var d = formatDecimalParts(x, p);
266 if (!d)
267 return x + "";
268 var coefficient = d[0], exponent2 = d[1], i = exponent2 - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent2 / 3))) * 3) + 1, n = coefficient.length;
269 return i === n ? coefficient : i > n ? coefficient + new Array(i - n + 1).join("0") : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i) : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0];
270}
271function formatRounded(x, p) {
272 var d = formatDecimalParts(x, p);
273 if (!d)
274 return x + "";
275 var coefficient = d[0], exponent2 = d[1];
276 return exponent2 < 0 ? "0." + new Array(-exponent2).join("0") + coefficient : coefficient.length > exponent2 + 1 ? coefficient.slice(0, exponent2 + 1) + "." + coefficient.slice(exponent2 + 1) : coefficient + new Array(exponent2 - coefficient.length + 2).join("0");
277}
278const formatTypes = {
279 "%": (x, p) => (x * 100).toFixed(p),
280 "b": (x) => Math.round(x).toString(2),
281 "c": (x) => x + "",
282 "d": formatDecimal,
283 "e": (x, p) => x.toExponential(p),
284 "f": (x, p) => x.toFixed(p),
285 "g": (x, p) => x.toPrecision(p),
286 "o": (x) => Math.round(x).toString(8),
287 "p": (x, p) => formatRounded(x * 100, p),
288 "r": formatRounded,
289 "s": formatPrefixAuto,
290 "X": (x) => Math.round(x).toString(16).toUpperCase(),
291 "x": (x) => Math.round(x).toString(16)
292};
293function identity$1(x) {
294 return x;
295}
296var map = Array.prototype.map, prefixes = ["y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y"];
297function formatLocale(locale2) {
298 var group = locale2.grouping === void 0 || locale2.thousands === void 0 ? identity$1 : formatGroup(map.call(locale2.grouping, Number), locale2.thousands + ""), currencyPrefix = locale2.currency === void 0 ? "" : locale2.currency[0] + "", currencySuffix = locale2.currency === void 0 ? "" : locale2.currency[1] + "", decimal = locale2.decimal === void 0 ? "." : locale2.decimal + "", numerals = locale2.numerals === void 0 ? identity$1 : formatNumerals(map.call(locale2.numerals, String)), percent = locale2.percent === void 0 ? "%" : locale2.percent + "", minus = locale2.minus === void 0 ? "−" : locale2.minus + "", nan = locale2.nan === void 0 ? "NaN" : locale2.nan + "";
299 function newFormat(specifier) {
300 specifier = formatSpecifier(specifier);
301 var fill = specifier.fill, align = specifier.align, sign = specifier.sign, symbol = specifier.symbol, zero2 = specifier.zero, width = specifier.width, comma = specifier.comma, precision = specifier.precision, trim = specifier.trim, type = specifier.type;
302 if (type === "n")
303 comma = true, type = "g";
304 else if (!formatTypes[type])
305 precision === void 0 && (precision = 12), trim = true, type = "g";
306 if (zero2 || fill === "0" && align === "=")
307 zero2 = true, fill = "0", align = "=";
308 var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "", suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
309 var formatType = formatTypes[type], maybeSuffix = /[defgprs%]/.test(type);
310 precision = precision === void 0 ? 6 : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision)) : Math.max(0, Math.min(20, precision));
311 function format2(value) {
312 var valuePrefix = prefix, valueSuffix = suffix, i, n, c;
313 if (type === "c") {
314 valueSuffix = formatType(value) + valueSuffix;
315 value = "";
316 } else {
317 value = +value;
318 var valueNegative = value < 0 || 1 / value < 0;
319 value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
320 if (trim)
321 value = formatTrim(value);
322 if (valueNegative && +value === 0 && sign !== "+")
323 valueNegative = false;
324 valuePrefix = (valueNegative ? sign === "(" ? sign : minus : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
325 valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
326 if (maybeSuffix) {
327 i = -1, n = value.length;
328 while (++i < n) {
329 if (c = value.charCodeAt(i), 48 > c || c > 57) {
330 valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
331 value = value.slice(0, i);
332 break;
333 }
334 }
335 }
336 }
337 if (comma && !zero2)
338 value = group(value, Infinity);
339 var length = valuePrefix.length + value.length + valueSuffix.length, padding = length < width ? new Array(width - length + 1).join(fill) : "";
340 if (comma && zero2)
341 value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
342 switch (align) {
343 case "<":
344 value = valuePrefix + value + valueSuffix + padding;
345 break;
346 case "=":
347 value = valuePrefix + padding + value + valueSuffix;
348 break;
349 case "^":
350 value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length);
351 break;
352 default:
353 value = padding + valuePrefix + value + valueSuffix;
354 break;
355 }
356 return numerals(value);
357 }
358 format2.toString = function() {
359 return specifier + "";
360 };
361 return format2;
362 }
363 function formatPrefix2(specifier, value) {
364 var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)), e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3, k = Math.pow(10, -e), prefix = prefixes[8 + e / 3];
365 return function(value2) {
366 return f(k * value2) + prefix;
367 };
368 }
369 return {
370 format: newFormat,
371 formatPrefix: formatPrefix2
372 };
373}
374var locale;
375var format;
376var formatPrefix;
377defaultLocale({
378 thousands: ",",
379 grouping: [3],
380 currency: ["$", ""]
381});
382function defaultLocale(definition) {
383 locale = formatLocale(definition);
384 format = locale.format;
385 formatPrefix = locale.formatPrefix;
386 return locale;
387}
388function precisionFixed(step) {
389 return Math.max(0, -exponent(Math.abs(step)));
390}
391function precisionPrefix(step, value) {
392 return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
393}
394function precisionRound(step, max) {
395 step = Math.abs(step), max = Math.abs(max) - step;
396 return Math.max(0, exponent(max) - exponent(step)) + 1;
397}
398function constants(x) {
399 return function() {
400 return x;
401 };
402}
403function number(x) {
404 return +x;
405}
406var unit = [0, 1];
407function identity(x) {
408 return x;
409}
410function normalize(a, b) {
411 return (b -= a = +a) ? function(x) {
412 return (x - a) / b;
413 } : constants(isNaN(b) ? NaN : 0.5);
414}
415function clamper(a, b) {
416 var t;
417 if (a > b)
418 t = a, a = b, b = t;
419 return function(x) {
420 return Math.max(a, Math.min(b, x));
421 };
422}
423function bimap(domain, range, interpolate2) {
424 var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
425 if (d1 < d0)
426 d0 = normalize(d1, d0), r0 = interpolate2(r1, r0);
427 else
428 d0 = normalize(d0, d1), r0 = interpolate2(r0, r1);
429 return function(x) {
430 return r0(d0(x));
431 };
432}
433function polymap(domain, range, interpolate2) {
434 var j = Math.min(domain.length, range.length) - 1, d = new Array(j), r = new Array(j), i = -1;
435 if (domain[j] < domain[0]) {
436 domain = domain.slice().reverse();
437 range = range.slice().reverse();
438 }
439 while (++i < j) {
440 d[i] = normalize(domain[i], domain[i + 1]);
441 r[i] = interpolate2(range[i], range[i + 1]);
442 }
443 return function(x) {
444 var i2 = bisect(domain, x, 1, j) - 1;
445 return r[i2](d[i2](x));
446 };
447}
448function copy(source, target) {
449 return target.domain(source.domain()).range(source.range()).interpolate(source.interpolate()).clamp(source.clamp()).unknown(source.unknown());
450}
451function transformer() {
452 var domain = unit, range = unit, interpolate$1 = interpolate, transform, untransform, unknown, clamp = identity, piecewise, output, input;
453 function rescale() {
454 var n = Math.min(domain.length, range.length);
455 if (clamp !== identity)
456 clamp = clamper(domain[0], domain[n - 1]);
457 piecewise = n > 2 ? polymap : bimap;
458 output = input = null;
459 return scale;
460 }
461 function scale(x) {
462 return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate$1)))(transform(clamp(x)));
463 }
464 scale.invert = function(y) {
465 return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
466 };
467 scale.domain = function(_) {
468 return arguments.length ? (domain = Array.from(_, number), rescale()) : domain.slice();
469 };
470 scale.range = function(_) {
471 return arguments.length ? (range = Array.from(_), rescale()) : range.slice();
472 };
473 scale.rangeRound = function(_) {
474 return range = Array.from(_), interpolate$1 = interpolateRound, rescale();
475 };
476 scale.clamp = function(_) {
477 return arguments.length ? (clamp = _ ? true : identity, rescale()) : clamp !== identity;
478 };
479 scale.interpolate = function(_) {
480 return arguments.length ? (interpolate$1 = _, rescale()) : interpolate$1;
481 };
482 scale.unknown = function(_) {
483 return arguments.length ? (unknown = _, scale) : unknown;
484 };
485 return function(t, u) {
486 transform = t, untransform = u;
487 return rescale();
488 };
489}
490function continuous() {
491 return transformer()(identity, identity);
492}
493function tickFormat(start, stop, count, specifier) {
494 var step = tickStep(start, stop, count), precision;
495 specifier = formatSpecifier(specifier == null ? ",f" : specifier);
496 switch (specifier.type) {
497 case "s": {
498 var value = Math.max(Math.abs(start), Math.abs(stop));
499 if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value)))
500 specifier.precision = precision;
501 return formatPrefix(specifier, value);
502 }
503 case "":
504 case "e":
505 case "g":
506 case "p":
507 case "r": {
508 if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop)))))
509 specifier.precision = precision - (specifier.type === "e");
510 break;
511 }
512 case "f":
513 case "%": {
514 if (specifier.precision == null && !isNaN(precision = precisionFixed(step)))
515 specifier.precision = precision - (specifier.type === "%") * 2;
516 break;
517 }
518 }
519 return format(specifier);
520}
521function linearish(scale) {
522 var domain = scale.domain;
523 scale.ticks = function(count) {
524 var d = domain();
525 return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
526 };
527 scale.tickFormat = function(count, specifier) {
528 var d = domain();
529 return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
530 };
531 scale.nice = function(count) {
532 if (count == null)
533 count = 10;
534 var d = domain();
535 var i0 = 0;
536 var i1 = d.length - 1;
537 var start = d[i0];
538 var stop = d[i1];
539 var prestep;
540 var step;
541 var maxIter = 10;
542 if (stop < start) {
543 step = start, start = stop, stop = step;
544 step = i0, i0 = i1, i1 = step;
545 }
546 while (maxIter-- > 0) {
547 step = tickIncrement(start, stop, count);
548 if (step === prestep) {
549 d[i0] = start;
550 d[i1] = stop;
551 return domain(d);
552 } else if (step > 0) {
553 start = Math.floor(start / step) * step;
554 stop = Math.ceil(stop / step) * step;
555 } else if (step < 0) {
556 start = Math.ceil(start * step) / step;
557 stop = Math.floor(stop * step) / step;
558 } else {
559 break;
560 }
561 prestep = step;
562 }
563 return scale;
564 };
565 return scale;
566}
567function linear() {
568 var scale = continuous();
569 scale.copy = function() {
570 return copy(scale, linear());
571 };
572 initRange.apply(scale, arguments);
573 return linearish(scale);
574}
575export {
576 copy as a,
577 bisector as b,
578 continuous as c,
579 linear as l,
580 tickStep as t
581};