expressive-charts 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +8 -8
- package/dist/{drawing-Ypmq-2h6.d.ts → drawing-OmQV-0BB.d.cts} +8 -2
- package/dist/{drawing-Ypmq-2h6.d.cts → drawing-OmQV-0BB.d.ts} +8 -2
- package/dist/{effect-D8W4ZmmG.d.cts → effect-DYCLY_6e.d.cts} +2 -2
- package/dist/{effect-DyzluQD1.d.ts → effect-HCWnmB72.d.ts} +2 -2
- package/dist/expressive-charts.global.js +10 -10
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.d.cts +1 -1
- package/dist/icons/sport.d.ts +1 -1
- package/dist/index.cjs +768 -193
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -22
- package/dist/index.d.ts +80 -22
- package/dist/index.js +768 -194
- package/dist/index.js.map +1 -1
- package/dist/testing.d.cts +2 -2
- package/dist/testing.d.ts +2 -2
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -77,7 +77,7 @@ function animated(initial, interpolate, options = {}) {
|
|
|
77
77
|
// src/core/playback.ts
|
|
78
78
|
const SEEK_MS = 350;
|
|
79
79
|
function playback(options) {
|
|
80
|
-
checkOptions$
|
|
80
|
+
checkOptions$15(options);
|
|
81
81
|
const { from, to, duration, onFrame } = options;
|
|
82
82
|
const ease = options.ease ?? linear;
|
|
83
83
|
const timing = options.timing ?? "playback";
|
|
@@ -220,7 +220,7 @@ function playback(options) {
|
|
|
220
220
|
}
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
|
-
function checkOptions$
|
|
223
|
+
function checkOptions$15(options) {
|
|
224
224
|
if (typeof options !== "object" || options === null) throw new TypeError("playback needs options: { from, to, duration, onFrame }.");
|
|
225
225
|
const { from, to, duration, ease, timing, onFrame, clock, motion } = options;
|
|
226
226
|
for (const [name, value] of [["from", from], ["to", to]]) if (!isFiniteNumber(value)) throw new RangeError(`playback: ${name} must be a finite number, got ${String(value)}.`);
|
|
@@ -656,8 +656,10 @@ function layoutBars(input) {
|
|
|
656
656
|
const domain = niceDomain(rows.map((row) => row.total));
|
|
657
657
|
const texts = rows.map((row) => input.format(row.total));
|
|
658
658
|
const ticks = domain.ticks.map(input.format);
|
|
659
|
-
const
|
|
660
|
-
|
|
659
|
+
const make = (values) => (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows, domain, values, ticks);
|
|
660
|
+
let frame = make(texts);
|
|
661
|
+
let labels = thinLabels(frame, rows, texts, input.measure);
|
|
662
|
+
if (!labels.values) labels = thinLabels(frame = make(), rows, texts, input.measure, false);
|
|
661
663
|
return {
|
|
662
664
|
width: frame.bands.width,
|
|
663
665
|
height: frame.bands.height,
|
|
@@ -676,10 +678,10 @@ function layoutBars(input) {
|
|
|
676
678
|
labels
|
|
677
679
|
};
|
|
678
680
|
}
|
|
679
|
-
function thinLabels(frame, rows, texts, measure) {
|
|
681
|
+
function thinLabels(frame, rows, texts, measure, values = true) {
|
|
680
682
|
const placed = rows.map((row, slot) => placeLabels$1(frame, slot, row.total, row.category, texts[slot]));
|
|
681
683
|
const horizontal = frame.orientation === "horizontal";
|
|
682
|
-
|
|
684
|
+
values && (values = !overlaps$1(boxesOf(placed.map(({ value }) => value), measure, "ec-value", VALUE_SIZE$2), horizontal));
|
|
683
685
|
const categories = (every) => boxesOf(placed.filter((_, slot) => slot % every === 0).map(({ label }) => label), measure, "ec-label", LABEL_SIZE$1);
|
|
684
686
|
let k = 0;
|
|
685
687
|
while (thinStep(k) < rows.length && overlaps$1(categories(thinStep(k)), horizontal)) k++;
|
|
@@ -924,12 +926,12 @@ function horizontalFrame(input, rows, domain, values, ticks) {
|
|
|
924
926
|
const { width, measure } = input;
|
|
925
927
|
const n = rows.length;
|
|
926
928
|
const labelWidth = widest$1(rows.map((row) => row.category), "ec-label", LABEL_SIZE$1, measure);
|
|
927
|
-
const
|
|
929
|
+
const valueRoom = values ? widest$1(values, "ec-value", VALUE_SIZE$2, measure) + PAD$1 : 0;
|
|
928
930
|
const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
|
|
929
931
|
const { positive, negative } = reach(input, rows);
|
|
930
|
-
const negativeRoom = domain.lo < 0 ?
|
|
932
|
+
const negativeRoom = domain.lo < 0 ? valueRoom : 0;
|
|
931
933
|
const left = Math.max(labelWidth + 10 + negativeRoom + negative, tickWidth / 2 + 2);
|
|
932
|
-
const right = Math.max(
|
|
934
|
+
const right = Math.max(valueRoom + 4 + positive, tickWidth / 2 + 2);
|
|
933
935
|
const rowSize = input.height === void 0 || n === 0 ? ROW : Math.max(0, input.height - TOP$1 - AXIS$1) / n;
|
|
934
936
|
return {
|
|
935
937
|
orientation: "horizontal",
|
|
@@ -950,15 +952,15 @@ function horizontalFrame(input, rows, domain, values, ticks) {
|
|
|
950
952
|
}
|
|
951
953
|
};
|
|
952
954
|
}
|
|
953
|
-
function verticalFrame(input, rows, domain,
|
|
955
|
+
function verticalFrame(input, rows, domain, values, ticks) {
|
|
954
956
|
const { width, measure } = input;
|
|
955
957
|
const n = rows.length;
|
|
956
958
|
const height = input.height ?? VERTICAL_HEIGHT;
|
|
957
959
|
const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
|
|
958
960
|
const { positive, negative } = reach(input, rows);
|
|
959
|
-
const top = (domain.hi > 0 ? 20.5 : TOP$1) + positive;
|
|
960
|
-
const
|
|
961
|
-
const bottom = AXIS$1 +
|
|
961
|
+
const top = (values && domain.hi > 0 ? 20.5 : TOP$1) + positive;
|
|
962
|
+
const under = values && domain.lo < 0 ? 18.5 : 0;
|
|
963
|
+
const bottom = AXIS$1 + under + negative;
|
|
962
964
|
const left = tickWidth + 8 + 2;
|
|
963
965
|
const plot = {
|
|
964
966
|
x: left,
|
|
@@ -975,7 +977,7 @@ function verticalFrame(input, rows, domain, _values, ticks) {
|
|
|
975
977
|
hi: domain.hi,
|
|
976
978
|
from: base,
|
|
977
979
|
extent: -plot.height,
|
|
978
|
-
label: base +
|
|
980
|
+
label: base + under + 18
|
|
979
981
|
},
|
|
980
982
|
bands: {
|
|
981
983
|
start: plot.x,
|
|
@@ -1661,7 +1663,7 @@ function mix$3(colors, emphasis) {
|
|
|
1661
1663
|
// src/charts/render/layer.ts
|
|
1662
1664
|
const FOLLOW = "ec-follow";
|
|
1663
1665
|
let clipIds = 0;
|
|
1664
|
-
function svgLayer(group, follow) {
|
|
1666
|
+
function svgLayer(group, follow, parts) {
|
|
1665
1667
|
const into = () => {
|
|
1666
1668
|
if (!follow) return group;
|
|
1667
1669
|
const last = group.lastElementChild;
|
|
@@ -1700,13 +1702,13 @@ function svgLayer(group, follow) {
|
|
|
1700
1702
|
d
|
|
1701
1703
|
}, into());
|
|
1702
1704
|
let current = { ...paint };
|
|
1703
|
-
paintPath(element, current);
|
|
1705
|
+
paintPath(element, current, parts);
|
|
1704
1706
|
return {
|
|
1705
1707
|
update(next, nextPaint) {
|
|
1706
1708
|
element.setAttribute("d", next);
|
|
1707
1709
|
if (nextPaint) {
|
|
1708
1710
|
current = mergeFields(current, nextPaint);
|
|
1709
|
-
paintPath(element, current);
|
|
1711
|
+
paintPath(element, current, parts);
|
|
1710
1712
|
}
|
|
1711
1713
|
},
|
|
1712
1714
|
remove: () => element.remove()
|
|
@@ -1750,14 +1752,17 @@ function drawShape(shape, parent) {
|
|
|
1750
1752
|
stroke: shape.stroke === void 0 ? void 0 : cssColor(shape.stroke)
|
|
1751
1753
|
});
|
|
1752
1754
|
}
|
|
1753
|
-
function paintPath(element, paint) {
|
|
1755
|
+
function paintPath(element, paint, parts) {
|
|
1756
|
+
const { part } = paint;
|
|
1754
1757
|
setAttributes(element, {
|
|
1755
1758
|
"stroke-width": paint.stroke === void 0 ? void 0 : paint.width ?? 1,
|
|
1756
1759
|
opacity: paint.opacity,
|
|
1757
1760
|
"stroke-linecap": paint.linecap,
|
|
1758
|
-
"stroke-linejoin": "round"
|
|
1761
|
+
"stroke-linejoin": "round",
|
|
1762
|
+
"data-part": part
|
|
1759
1763
|
});
|
|
1760
1764
|
setStyles(element, {
|
|
1765
|
+
...markColorStyles(part === void 0 ? void 0 : parts?.(part)),
|
|
1761
1766
|
fill: paint.fill === void 0 ? "none" : cssColor(paint.fill),
|
|
1762
1767
|
stroke: paint.stroke === void 0 ? void 0 : cssColor(paint.stroke)
|
|
1763
1768
|
});
|
|
@@ -1802,7 +1807,7 @@ function svgSurface(options) {
|
|
|
1802
1807
|
live.add(group);
|
|
1803
1808
|
const owner = live;
|
|
1804
1809
|
return {
|
|
1805
|
-
...svgLayer(group, () => transforms.get(key)),
|
|
1810
|
+
...svgLayer(group, () => transforms.get(key), (part) => options.colors(key, part)),
|
|
1806
1811
|
clear() {
|
|
1807
1812
|
group.remove();
|
|
1808
1813
|
owner.delete(group);
|
|
@@ -1833,7 +1838,10 @@ function svgSurface(options) {
|
|
|
1833
1838
|
const live = groups.get(key);
|
|
1834
1839
|
if (!live) return;
|
|
1835
1840
|
const styles = markColorStyles(options.colors(key));
|
|
1836
|
-
for (const group of live)
|
|
1841
|
+
for (const group of live) {
|
|
1842
|
+
setStyles(group, styles);
|
|
1843
|
+
for (const path of group.querySelectorAll("[data-part]")) setStyles(path, markColorStyles(options.colors(key, path.getAttribute("data-part"))));
|
|
1844
|
+
}
|
|
1837
1845
|
},
|
|
1838
1846
|
hide(key, hide) {
|
|
1839
1847
|
if (hide) hidden.add(key);
|
|
@@ -2270,6 +2278,14 @@ function keyboardFocus(svg, options) {
|
|
|
2270
2278
|
last = keys;
|
|
2271
2279
|
return had === void 0 ? void 0 : current;
|
|
2272
2280
|
},
|
|
2281
|
+
moveTabStop(key) {
|
|
2282
|
+
listen();
|
|
2283
|
+
const keys = options.order();
|
|
2284
|
+
if (!keys.includes(key) || options.find(on?.scope.activeElement ?? null) !== void 0) return false;
|
|
2285
|
+
tabStop = key;
|
|
2286
|
+
applyTabIndex(keys);
|
|
2287
|
+
return true;
|
|
2288
|
+
},
|
|
2273
2289
|
destroy() {
|
|
2274
2290
|
current = void 0;
|
|
2275
2291
|
focused = void 0;
|
|
@@ -2307,6 +2323,11 @@ function chartHover(options) {
|
|
|
2307
2323
|
}] : [];
|
|
2308
2324
|
});
|
|
2309
2325
|
const marksFor = (keys) => keys.length === 1 ? marksOf(keys[0]) : [...new Set(keys.flatMap(marksOf))];
|
|
2326
|
+
const standIns = (keys) => keys.flatMap((key) => {
|
|
2327
|
+
const input = options.standIn?.(key);
|
|
2328
|
+
return input ? [input] : [];
|
|
2329
|
+
});
|
|
2330
|
+
const standingFor = (keys, source, marks) => source === "linked" && marks.length === 0 ? keys.find((key) => options.standIn?.(key) !== void 0) : void 0;
|
|
2310
2331
|
function hoverMarks(marks, source, effects, segment) {
|
|
2311
2332
|
if (marks.length === 0) return;
|
|
2312
2333
|
if (effects) runner.hover(marks.map(({ input }) => input));
|
|
@@ -2337,11 +2358,13 @@ function chartHover(options) {
|
|
|
2337
2358
|
}
|
|
2338
2359
|
function startHover(keys, source, segment, effects = true) {
|
|
2339
2360
|
const marks = onScreen(marksFor(keys));
|
|
2361
|
+
const standing = standingFor(keys, source, marks);
|
|
2340
2362
|
const started = {
|
|
2341
2363
|
keys,
|
|
2342
2364
|
source,
|
|
2343
2365
|
marks: marks.map((mark) => mark.key),
|
|
2344
|
-
effects
|
|
2366
|
+
effects,
|
|
2367
|
+
standing
|
|
2345
2368
|
};
|
|
2346
2369
|
hovered = started;
|
|
2347
2370
|
for (const { key: mark } of marks) heat(mark, true);
|
|
@@ -2350,8 +2373,9 @@ function chartHover(options) {
|
|
|
2350
2373
|
options.tooltip.show(keys[0]);
|
|
2351
2374
|
listenForEscape(true);
|
|
2352
2375
|
}
|
|
2376
|
+
if (standing !== void 0) options.stand?.(standing);
|
|
2353
2377
|
hoverMarks(marks, source, effects, segment);
|
|
2354
|
-
if (source !== "linked" && hovered === started) linked?.hover(marks.map(({ input }) => input));
|
|
2378
|
+
if (source !== "linked" && hovered === started) linked?.hover(marks.length > 0 ? marks.map(({ input }) => input) : standIns(keys));
|
|
2355
2379
|
}
|
|
2356
2380
|
function endHover() {
|
|
2357
2381
|
const ended = hovered;
|
|
@@ -2359,6 +2383,7 @@ function chartHover(options) {
|
|
|
2359
2383
|
listenForEscape(false);
|
|
2360
2384
|
svg.classList.remove("ec-hovering");
|
|
2361
2385
|
options.tooltip.hide();
|
|
2386
|
+
if (ended?.standing !== void 0) options.stand?.(void 0);
|
|
2362
2387
|
leaveMarks(ended?.marks ?? []);
|
|
2363
2388
|
if (own(ended)) linked?.leave();
|
|
2364
2389
|
}
|
|
@@ -2437,14 +2462,20 @@ function chartHover(options) {
|
|
|
2437
2462
|
get key() {
|
|
2438
2463
|
return own(hovered) ? hovered.keys[0] : void 0;
|
|
2439
2464
|
},
|
|
2465
|
+
get standing() {
|
|
2466
|
+
return hovered?.standing;
|
|
2467
|
+
},
|
|
2440
2468
|
get ringKey() {
|
|
2441
2469
|
return ringKey;
|
|
2442
2470
|
},
|
|
2443
2471
|
link: {
|
|
2444
|
-
targets: () => options.order().map((key) =>
|
|
2445
|
-
key
|
|
2446
|
-
|
|
2447
|
-
|
|
2472
|
+
targets: () => options.order().map((key) => {
|
|
2473
|
+
const marks = onScreen(marksOf(key)).map(({ input }) => input);
|
|
2474
|
+
return {
|
|
2475
|
+
key,
|
|
2476
|
+
marks: marks.length > 0 ? marks : standIns([key])
|
|
2477
|
+
};
|
|
2478
|
+
}),
|
|
2448
2479
|
hover(keys, effects) {
|
|
2449
2480
|
if (hovered !== void 0) endHover();
|
|
2450
2481
|
const live = keys.filter(options.live);
|
|
@@ -2480,9 +2511,12 @@ function chartHover(options) {
|
|
|
2480
2511
|
}
|
|
2481
2512
|
const { source, marks: before, effects } = hovered;
|
|
2482
2513
|
const now = onScreen(marksFor(keys));
|
|
2514
|
+
const standing = standingFor(keys, source, now);
|
|
2515
|
+
if (standing !== hovered.standing) options.stand?.(standing);
|
|
2483
2516
|
hovered = {
|
|
2484
2517
|
...hovered,
|
|
2485
|
-
keys
|
|
2518
|
+
keys,
|
|
2519
|
+
standing
|
|
2486
2520
|
};
|
|
2487
2521
|
if (now.length === before.length && now.every((mark, i) => mark.key === before[i])) return;
|
|
2488
2522
|
const had = new Set(before);
|
|
@@ -2527,6 +2561,7 @@ function chartHover(options) {
|
|
|
2527
2561
|
focus(key) {
|
|
2528
2562
|
if (options.live(key)) keyboard.focus(key);
|
|
2529
2563
|
},
|
|
2564
|
+
moveTabStop: (key) => options.live(key) && keyboard.moveTabStop(key),
|
|
2530
2565
|
leave,
|
|
2531
2566
|
destroy() {
|
|
2532
2567
|
destroyed = true;
|
|
@@ -2663,6 +2698,10 @@ function tableModel(input) {
|
|
|
2663
2698
|
text: "",
|
|
2664
2699
|
numeric: false
|
|
2665
2700
|
});
|
|
2701
|
+
const missing = {
|
|
2702
|
+
text: input.missing ?? "missing",
|
|
2703
|
+
numeric: true
|
|
2704
|
+
};
|
|
2666
2705
|
const headers = [
|
|
2667
2706
|
{
|
|
2668
2707
|
text: options.category ?? input.category ?? "Category",
|
|
@@ -2693,10 +2732,7 @@ function tableModel(input) {
|
|
|
2693
2732
|
numeric: false
|
|
2694
2733
|
},
|
|
2695
2734
|
...first.map((column) => columnCell(column, row, format)),
|
|
2696
|
-
...input.series.map((series) => row.missing?.has(series) ?
|
|
2697
|
-
text: MISSING,
|
|
2698
|
-
numeric: true
|
|
2699
|
-
} : number(values.get(series) ?? 0)),
|
|
2735
|
+
...input.series.map((series) => row.missing?.has(series) ? missing : number(values.get(series) ?? 0)),
|
|
2700
2736
|
...totals ? [number(row.total)] : [],
|
|
2701
2737
|
...share(row.total),
|
|
2702
2738
|
...last.map((column) => columnCell(column, row, format))
|
|
@@ -3065,6 +3101,41 @@ function watchFonts(doc, loaded) {
|
|
|
3065
3101
|
fonts?.addEventListener?.("loadingdone", loaded);
|
|
3066
3102
|
return () => fonts?.removeEventListener?.("loadingdone", loaded);
|
|
3067
3103
|
}
|
|
3104
|
+
const PROBE_TEXT = "Hamburgefonstiv 0123456789";
|
|
3105
|
+
function watchText(svg, clock, changed) {
|
|
3106
|
+
if (typeof ResizeObserver !== "function") return () => {};
|
|
3107
|
+
const probe = svgElement("text", {
|
|
3108
|
+
"font-size": 11,
|
|
3109
|
+
visibility: "hidden",
|
|
3110
|
+
"pointer-events": "none",
|
|
3111
|
+
"aria-hidden": "true"
|
|
3112
|
+
}, svg);
|
|
3113
|
+
probe.textContent = PROBE_TEXT;
|
|
3114
|
+
let measured = 0;
|
|
3115
|
+
let pending = 0;
|
|
3116
|
+
let stopFrame;
|
|
3117
|
+
const observer = new ResizeObserver((entries) => {
|
|
3118
|
+
const next = entries.find((entry) => entry.target === probe)?.contentRect.width ?? 0;
|
|
3119
|
+
if (!(next > 0) || Math.abs(next - pending) < .5) return;
|
|
3120
|
+
pending = next;
|
|
3121
|
+
if (!measured) {
|
|
3122
|
+
measured = next;
|
|
3123
|
+
return;
|
|
3124
|
+
}
|
|
3125
|
+
stopFrame ?? (stopFrame = clock.onFrame(() => {
|
|
3126
|
+
stopFrame?.();
|
|
3127
|
+
stopFrame = void 0;
|
|
3128
|
+
if (Math.abs(pending - measured) < .5) return;
|
|
3129
|
+
measured = pending;
|
|
3130
|
+
changed();
|
|
3131
|
+
}));
|
|
3132
|
+
});
|
|
3133
|
+
observer.observe(probe);
|
|
3134
|
+
return () => {
|
|
3135
|
+
observer.disconnect();
|
|
3136
|
+
stopFrame?.();
|
|
3137
|
+
};
|
|
3138
|
+
}
|
|
3068
3139
|
function watchHoverDuration(svg, motion) {
|
|
3069
3140
|
const sync = () => svg.style.setProperty("--ec-hover-duration", `${motion.duration(100, "feedback")}ms`);
|
|
3070
3141
|
sync();
|
|
@@ -3112,7 +3183,7 @@ function chartTooltip(svg, options) {
|
|
|
3112
3183
|
if (x > left && x < right && y > top && y < bottom) return true;
|
|
3113
3184
|
if (!shape) return false;
|
|
3114
3185
|
const origin = layer.getBoundingClientRect();
|
|
3115
|
-
return inside$
|
|
3186
|
+
return inside$2(shape, x - origin.left, y - origin.top);
|
|
3116
3187
|
};
|
|
3117
3188
|
const letThrough = (on) => {
|
|
3118
3189
|
through = on;
|
|
@@ -3301,7 +3372,7 @@ function chartTooltip(svg, options) {
|
|
|
3301
3372
|
}
|
|
3302
3373
|
};
|
|
3303
3374
|
}
|
|
3304
|
-
function inside$
|
|
3375
|
+
function inside$2({ top, bottom, upper, lower }, x, y) {
|
|
3305
3376
|
if (y <= top || y >= bottom) return false;
|
|
3306
3377
|
const t = (y - top) / (bottom - top);
|
|
3307
3378
|
return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
|
|
@@ -3388,7 +3459,7 @@ function viewBox$1(svg) {
|
|
|
3388
3459
|
const STAGE$2 = 500;
|
|
3389
3460
|
function barChart$1(target, options, env) {
|
|
3390
3461
|
const container = resolveTarget$2(target, "barChart");
|
|
3391
|
-
checkOptions$
|
|
3462
|
+
checkOptions$14(options);
|
|
3392
3463
|
let current = options;
|
|
3393
3464
|
const motion = chartMotion(options.motion, env.motion);
|
|
3394
3465
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -3458,7 +3529,7 @@ function barChart$1(target, options, env) {
|
|
|
3458
3529
|
hover.restyled(key);
|
|
3459
3530
|
}
|
|
3460
3531
|
}),
|
|
3461
|
-
colors: (key) => find(key)?.parts[0]?.colors
|
|
3532
|
+
colors: (key, part) => find(key)?.parts[part === void 0 ? 0 : (find(key)?.shown.geometry.segments ?? []).findIndex((segment) => segment.key === part)]?.colors
|
|
3462
3533
|
});
|
|
3463
3534
|
const runner = createRunner({
|
|
3464
3535
|
effects,
|
|
@@ -3545,6 +3616,10 @@ function barChart$1(target, options, env) {
|
|
|
3545
3616
|
series: row.values.map((v) => v.series),
|
|
3546
3617
|
slot: animated(row.slot, interpolateNumber, env),
|
|
3547
3618
|
presence: animated(entering ? 0 : 1, interpolateNumber, env),
|
|
3619
|
+
drawn: {
|
|
3620
|
+
label: animated(Number(row.drawn.label), interpolateNumber, env),
|
|
3621
|
+
value: animated(Number(row.drawn.value), interpolateNumber, env)
|
|
3622
|
+
},
|
|
3548
3623
|
count: void 0,
|
|
3549
3624
|
leave: void 0
|
|
3550
3625
|
};
|
|
@@ -3553,15 +3628,17 @@ function barChart$1(target, options, env) {
|
|
|
3553
3628
|
return record;
|
|
3554
3629
|
}
|
|
3555
3630
|
function drawMark(record, row) {
|
|
3556
|
-
const before = record.parts
|
|
3631
|
+
const before = record.parts;
|
|
3557
3632
|
record.shown = row;
|
|
3558
3633
|
setAttributes(record.hit, { ...row.hit });
|
|
3559
3634
|
placeText(record.label, row.label);
|
|
3560
3635
|
placeText(record.value, row.value);
|
|
3561
|
-
const
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3636
|
+
const opacity = (drawn, fade) => {
|
|
3637
|
+
const shown = record.presence.value * (drawn ? fade.value : 1);
|
|
3638
|
+
return shown < 1 ? shown : void 0;
|
|
3639
|
+
};
|
|
3640
|
+
setAttributes(record.label, { opacity: opacity(row.drawn.label, record.drawn.label) });
|
|
3641
|
+
setAttributes(record.value, { opacity: opacity(row.drawn.value, record.drawn.value) });
|
|
3565
3642
|
const segments = row.geometry.segments ?? [];
|
|
3566
3643
|
const keep = /* @__PURE__ */ new Set();
|
|
3567
3644
|
const ownColors = byCategory(current) ? seriesColors(colors.slot(record.key)) : void 0;
|
|
@@ -3594,7 +3671,7 @@ function barChart$1(target, options, env) {
|
|
|
3594
3671
|
const drawn = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
|
|
3595
3672
|
if (record.parts.some((part, i) => drawn[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
|
|
3596
3673
|
record.handle.repaint();
|
|
3597
|
-
if (record.parts
|
|
3674
|
+
if (record.parts.length !== before.length || record.parts.some((part, i) => part.colors.color !== before[i].colors.color)) surface.recolor(record.key);
|
|
3598
3675
|
if (record.key === hover.ringKey) drawRing(record.key);
|
|
3599
3676
|
}
|
|
3600
3677
|
function drawRing(key) {
|
|
@@ -3701,6 +3778,10 @@ function barChart$1(target, options, env) {
|
|
|
3701
3778
|
}));
|
|
3702
3779
|
const total = values.reduce((sum, v) => sum + v.value, 0);
|
|
3703
3780
|
const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
|
|
3781
|
+
const drawn = {
|
|
3782
|
+
label: record.drawn.label.value > 0,
|
|
3783
|
+
value: record.drawn.value.value > 0
|
|
3784
|
+
};
|
|
3704
3785
|
return placeRow(frame, {
|
|
3705
3786
|
key: row.key,
|
|
3706
3787
|
datum: row.datum,
|
|
@@ -3709,7 +3790,7 @@ function barChart$1(target, options, env) {
|
|
|
3709
3790
|
values,
|
|
3710
3791
|
slot: record.slot.value,
|
|
3711
3792
|
text,
|
|
3712
|
-
drawn
|
|
3793
|
+
drawn
|
|
3713
3794
|
}, measure);
|
|
3714
3795
|
}
|
|
3715
3796
|
function addTick(value, opacity) {
|
|
@@ -3831,8 +3912,11 @@ function barChart$1(target, options, env) {
|
|
|
3831
3912
|
let first;
|
|
3832
3913
|
let second;
|
|
3833
3914
|
let grow;
|
|
3915
|
+
let out;
|
|
3916
|
+
let into;
|
|
3834
3917
|
if (!jump && motion.staged) {
|
|
3835
3918
|
const wait = values ? STAGE$2 : 0;
|
|
3919
|
+
const half = values && positions ? STAGE$2 : STAGE$2 / 2;
|
|
3836
3920
|
first = { duration: STAGE$2 };
|
|
3837
3921
|
second = {
|
|
3838
3922
|
duration: STAGE$2,
|
|
@@ -3842,6 +3926,11 @@ function barChart$1(target, options, env) {
|
|
|
3842
3926
|
duration: STAGE$2 / 2,
|
|
3843
3927
|
delay: wait + STAGE$2 / 2
|
|
3844
3928
|
};
|
|
3929
|
+
out = { duration: half };
|
|
3930
|
+
into = {
|
|
3931
|
+
duration: half,
|
|
3932
|
+
delay: half
|
|
3933
|
+
};
|
|
3845
3934
|
} else if (!jump) first = second = grow = { duration: (values && positions ? 2 : 1) * STAGE$2 };
|
|
3846
3935
|
const running = [];
|
|
3847
3936
|
const move = (value, to, equal, timing) => {
|
|
@@ -3852,6 +3941,13 @@ function barChart$1(target, options, env) {
|
|
|
3852
3941
|
move(scale, frame.scale, sameFields, first);
|
|
3853
3942
|
move(bands, frame.bands, sameFields, second);
|
|
3854
3943
|
for (const tick of ticks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
|
|
3944
|
+
for (const record of order) {
|
|
3945
|
+
const fades = !arriving.has(record);
|
|
3946
|
+
for (const part of ["label", "value"]) {
|
|
3947
|
+
const to = Number(record.row.drawn[part]);
|
|
3948
|
+
move(record.drawn[part], to, same, fades ? to ? into : out : void 0);
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3855
3951
|
for (const record of staying) {
|
|
3856
3952
|
move(record.values, valuesOf(record.row), sameFields, first);
|
|
3857
3953
|
move(record.presence, 1, same, first);
|
|
@@ -3926,14 +4022,16 @@ function barChart$1(target, options, env) {
|
|
|
3926
4022
|
for (const record of order) record.row = rows.get(record.key) ?? record.row;
|
|
3927
4023
|
transitionTo(next, true);
|
|
3928
4024
|
}
|
|
4025
|
+
const remeasure = () => {
|
|
4026
|
+
measure.clear();
|
|
4027
|
+
relayout();
|
|
4028
|
+
};
|
|
4029
|
+
const unwatchText = watchText(svg, clock, remeasure);
|
|
3929
4030
|
const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
|
|
3930
4031
|
measuredWidth = width;
|
|
3931
4032
|
if (current.width === void 0) relayout();
|
|
3932
4033
|
});
|
|
3933
|
-
const unwatchFonts = watchFonts(doc,
|
|
3934
|
-
measure.clear();
|
|
3935
|
-
relayout();
|
|
3936
|
-
});
|
|
4034
|
+
const unwatchFonts = watchFonts(doc, remeasure);
|
|
3937
4035
|
describeChart(svg, current);
|
|
3938
4036
|
syncLegend(laidOut);
|
|
3939
4037
|
table.render(firstTable);
|
|
@@ -3957,7 +4055,7 @@ function barChart$1(target, options, env) {
|
|
|
3957
4055
|
...current,
|
|
3958
4056
|
...next
|
|
3959
4057
|
};
|
|
3960
|
-
checkOptions$
|
|
4058
|
+
checkOptions$14(merged);
|
|
3961
4059
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
3962
4060
|
const nextLayout = layout(merged, swapped);
|
|
3963
4061
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -3992,7 +4090,7 @@ function barChart$1(target, options, env) {
|
|
|
3992
4090
|
}, () => arrange(nextLayout), (diff) => {
|
|
3993
4091
|
if (announcing) announceChange(previous, diff);
|
|
3994
4092
|
});
|
|
3995
|
-
if (byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
|
|
4093
|
+
if ("colors" in next || byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
|
|
3996
4094
|
const settled = transitionTo(nextLayout, motion.mode === "off" || nextLayout.orientation !== orientation);
|
|
3997
4095
|
await transitions.wait(settled, leaves);
|
|
3998
4096
|
},
|
|
@@ -4013,6 +4111,7 @@ function barChart$1(target, options, env) {
|
|
|
4013
4111
|
drawn: true
|
|
4014
4112
|
};
|
|
4015
4113
|
},
|
|
4114
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
4016
4115
|
destroy() {
|
|
4017
4116
|
if (destroyed) return;
|
|
4018
4117
|
destroyed = true;
|
|
@@ -4024,13 +4123,16 @@ function barChart$1(target, options, env) {
|
|
|
4024
4123
|
table.destroy();
|
|
4025
4124
|
announcer?.destroy();
|
|
4026
4125
|
unwatchHoverDuration();
|
|
4126
|
+
unwatchText();
|
|
4027
4127
|
unwatchWidth();
|
|
4028
4128
|
unwatchFonts();
|
|
4029
4129
|
for (const record of [...order, ...leaving.values()]) {
|
|
4030
4130
|
for (const value of [
|
|
4031
4131
|
record.values,
|
|
4032
4132
|
record.slot,
|
|
4033
|
-
record.presence
|
|
4133
|
+
record.presence,
|
|
4134
|
+
record.drawn.label,
|
|
4135
|
+
record.drawn.value
|
|
4034
4136
|
]) value.stop();
|
|
4035
4137
|
record.leave?.resolve();
|
|
4036
4138
|
}
|
|
@@ -4045,7 +4147,7 @@ function barChart$1(target, options, env) {
|
|
|
4045
4147
|
}
|
|
4046
4148
|
});
|
|
4047
4149
|
}
|
|
4048
|
-
function checkOptions$
|
|
4150
|
+
function checkOptions$14(options) {
|
|
4049
4151
|
checkChartOptions(options, "barChart");
|
|
4050
4152
|
const { colorBy, room } = options;
|
|
4051
4153
|
if (room !== void 0 && !(typeof room === "number" && Number.isFinite(room) && room >= 0)) throw new RangeError(`barChart: room must be a number of px, 0 or more, got ${String(room)}.`);
|
|
@@ -4349,7 +4451,7 @@ const TAU = 2 * Math.PI;
|
|
|
4349
4451
|
const VISIBLE$1 = .5;
|
|
4350
4452
|
function donutChart$1(target, options, env) {
|
|
4351
4453
|
const container = resolveTarget$2(target, "donutChart");
|
|
4352
|
-
checkOptions$
|
|
4454
|
+
checkOptions$13(options);
|
|
4353
4455
|
let current = options;
|
|
4354
4456
|
const motion = chartMotion(options.motion, env.motion);
|
|
4355
4457
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -4889,14 +4991,16 @@ function donutChart$1(target, options, env) {
|
|
|
4889
4991
|
for (const record of order) record.row = slices.get(record.key) ?? record.row;
|
|
4890
4992
|
transitionTo(next, true);
|
|
4891
4993
|
}
|
|
4994
|
+
const remeasure = () => {
|
|
4995
|
+
measure.clear();
|
|
4996
|
+
relayout();
|
|
4997
|
+
};
|
|
4998
|
+
const unwatchText = watchText(svg, clock, remeasure);
|
|
4892
4999
|
const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
|
|
4893
5000
|
measuredWidth = width;
|
|
4894
5001
|
if (current.width === void 0) relayout();
|
|
4895
5002
|
});
|
|
4896
|
-
const unwatchFonts = watchFonts(doc,
|
|
4897
|
-
measure.clear();
|
|
4898
|
-
relayout();
|
|
4899
|
-
});
|
|
5003
|
+
const unwatchFonts = watchFonts(doc, remeasure);
|
|
4900
5004
|
describeDonut();
|
|
4901
5005
|
syncLegend();
|
|
4902
5006
|
table.render(firstTable);
|
|
@@ -4921,7 +5025,7 @@ function donutChart$1(target, options, env) {
|
|
|
4921
5025
|
...current,
|
|
4922
5026
|
...next
|
|
4923
5027
|
};
|
|
4924
|
-
checkOptions$
|
|
5028
|
+
checkOptions$13(merged);
|
|
4925
5029
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
4926
5030
|
const nextLayout = layout(merged, swapped);
|
|
4927
5031
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -4977,6 +5081,7 @@ function donutChart$1(target, options, env) {
|
|
|
4977
5081
|
color: key,
|
|
4978
5082
|
drawn: true
|
|
4979
5083
|
} : void 0,
|
|
5084
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
4980
5085
|
destroy() {
|
|
4981
5086
|
if (destroyed) return;
|
|
4982
5087
|
destroyed = true;
|
|
@@ -4988,6 +5093,7 @@ function donutChart$1(target, options, env) {
|
|
|
4988
5093
|
table.destroy();
|
|
4989
5094
|
announcer?.destroy();
|
|
4990
5095
|
unwatchHoverDuration();
|
|
5096
|
+
unwatchText();
|
|
4991
5097
|
unwatchWidth();
|
|
4992
5098
|
unwatchFonts();
|
|
4993
5099
|
for (const record of [...order, ...leaving.values()]) {
|
|
@@ -5007,7 +5113,7 @@ function donutChart$1(target, options, env) {
|
|
|
5007
5113
|
}
|
|
5008
5114
|
});
|
|
5009
5115
|
}
|
|
5010
|
-
function checkOptions$
|
|
5116
|
+
function checkOptions$13(options) {
|
|
5011
5117
|
checkChartOptions(options, "donutChart");
|
|
5012
5118
|
const { center, sort } = options;
|
|
5013
5119
|
if (center !== void 0 && center !== false && typeof center !== "function") throw new TypeError("donutChart: center must be false or a function that returns the text for the total.");
|
|
@@ -5244,7 +5350,6 @@ function cubic(v0, c1, c2, v1, u) {
|
|
|
5244
5350
|
return s * s * s * v0 + 3 * s * s * u * c1 + 3 * s * u * u * c2 + u * u * u * v1;
|
|
5245
5351
|
}
|
|
5246
5352
|
// src/charts/time.ts
|
|
5247
|
-
const TIME_ZONES = ["UTC", "local"];
|
|
5248
5353
|
const SECOND = 1e3;
|
|
5249
5354
|
const MINUTE = 60 * SECOND;
|
|
5250
5355
|
const HOUR = 60 * MINUTE;
|
|
@@ -5352,6 +5457,16 @@ const FIELDS = {
|
|
|
5352
5457
|
fractionalSecondDigits: 3
|
|
5353
5458
|
}
|
|
5354
5459
|
};
|
|
5460
|
+
function isTimeZone(zone) {
|
|
5461
|
+
if (zone === "UTC" || zone === "local") return true;
|
|
5462
|
+
if (typeof zone !== "string") return false;
|
|
5463
|
+
try {
|
|
5464
|
+
clockOf(zone);
|
|
5465
|
+
return true;
|
|
5466
|
+
} catch {
|
|
5467
|
+
return false;
|
|
5468
|
+
}
|
|
5469
|
+
}
|
|
5355
5470
|
function timeStep(span) {
|
|
5356
5471
|
for (const step of STEPS) if (LONGEST$1[step.unit] * step.count >= span) return step;
|
|
5357
5472
|
return {
|
|
@@ -5421,15 +5536,7 @@ function monthsOn(t, months, zone) {
|
|
|
5421
5536
|
const last = /* @__PURE__ */ new Date(0);
|
|
5422
5537
|
last.setUTCFullYear(year, month + months + 1, 0);
|
|
5423
5538
|
const day = Math.min(date, last.getUTCDate());
|
|
5424
|
-
|
|
5425
|
-
if (zone === "UTC") {
|
|
5426
|
-
d.setUTCFullYear(year, month + months, day);
|
|
5427
|
-
d.setUTCHours(hours, minutes, seconds, ms);
|
|
5428
|
-
} else {
|
|
5429
|
-
d.setFullYear(year, month + months, day);
|
|
5430
|
-
d.setHours(hours, minutes, seconds, ms);
|
|
5431
|
-
}
|
|
5432
|
-
return d.getTime();
|
|
5539
|
+
return timeAt(zone, year, month + months, day, hours, minutes, seconds, ms);
|
|
5433
5540
|
}
|
|
5434
5541
|
function timeLevel(t, zone) {
|
|
5435
5542
|
const { ms, seconds, minutes, hours, date, month } = partsOf(t, zone);
|
|
@@ -5441,7 +5548,8 @@ function timeLevel(t, zone) {
|
|
|
5441
5548
|
return month !== 0 ? "month" : "year";
|
|
5442
5549
|
}
|
|
5443
5550
|
function timeName(times, zone) {
|
|
5444
|
-
const
|
|
5551
|
+
const shown = clockReader(zone);
|
|
5552
|
+
const finest = times.reduce((max, t) => Math.max(max, LEVELS.indexOf(timeLevel(shown(t), "UTC"))), 0);
|
|
5445
5553
|
const timeZone = zoneOption(zone);
|
|
5446
5554
|
const timeStyle = finest >= LEVELS.indexOf("second") ? "medium" : finest >= LEVELS.indexOf("hour") ? "short" : void 0;
|
|
5447
5555
|
const options = finest === LEVELS.indexOf("millisecond") ? {
|
|
@@ -5455,7 +5563,17 @@ function timeName(times, zone) {
|
|
|
5455
5563
|
timeZone
|
|
5456
5564
|
};
|
|
5457
5565
|
const format = new Intl.DateTimeFormat(void 0, options);
|
|
5458
|
-
return (t) => format.format(t);
|
|
5566
|
+
if (zone === "UTC" || !timeStyle) return (t) => format.format(t);
|
|
5567
|
+
const named = new Intl.DateTimeFormat(void 0, {
|
|
5568
|
+
timeZone,
|
|
5569
|
+
timeZoneName: "short"
|
|
5570
|
+
});
|
|
5571
|
+
return (t) => {
|
|
5572
|
+
const text = format.format(t);
|
|
5573
|
+
if (twinOf(t, shown) === void 0) return text;
|
|
5574
|
+
const name = named.formatToParts(t).find((part) => part.type === "timeZoneName")?.value;
|
|
5575
|
+
return name ? `${text} ${name}` : text;
|
|
5576
|
+
};
|
|
5459
5577
|
}
|
|
5460
5578
|
function tickWording(zone) {
|
|
5461
5579
|
const formats = /* @__PURE__ */ new Map();
|
|
@@ -5472,19 +5590,10 @@ function tickWording(zone) {
|
|
|
5472
5590
|
return format.format(t);
|
|
5473
5591
|
};
|
|
5474
5592
|
}
|
|
5475
|
-
const zoneOption = (zone) => zone === "
|
|
5593
|
+
const zoneOption = (zone) => zone === "local" ? void 0 : zone;
|
|
5476
5594
|
function partsOf(t, zone) {
|
|
5477
|
-
const d = new Date(t);
|
|
5478
|
-
return zone === "
|
|
5479
|
-
year: d.getUTCFullYear(),
|
|
5480
|
-
month: d.getUTCMonth(),
|
|
5481
|
-
date: d.getUTCDate(),
|
|
5482
|
-
weekday: d.getUTCDay(),
|
|
5483
|
-
hours: d.getUTCHours(),
|
|
5484
|
-
minutes: d.getUTCMinutes(),
|
|
5485
|
-
seconds: d.getUTCSeconds(),
|
|
5486
|
-
ms: d.getUTCMilliseconds()
|
|
5487
|
-
} : {
|
|
5595
|
+
const d = new Date(zone === "UTC" || zone === "local" ? t : shownAt(t, zone));
|
|
5596
|
+
return zone === "local" ? {
|
|
5488
5597
|
year: d.getFullYear(),
|
|
5489
5598
|
month: d.getMonth(),
|
|
5490
5599
|
date: d.getDate(),
|
|
@@ -5493,19 +5602,88 @@ function partsOf(t, zone) {
|
|
|
5493
5602
|
minutes: d.getMinutes(),
|
|
5494
5603
|
seconds: d.getSeconds(),
|
|
5495
5604
|
ms: d.getMilliseconds()
|
|
5605
|
+
} : {
|
|
5606
|
+
year: d.getUTCFullYear(),
|
|
5607
|
+
month: d.getUTCMonth(),
|
|
5608
|
+
date: d.getUTCDate(),
|
|
5609
|
+
weekday: d.getUTCDay(),
|
|
5610
|
+
hours: d.getUTCHours(),
|
|
5611
|
+
minutes: d.getUTCMinutes(),
|
|
5612
|
+
seconds: d.getUTCSeconds(),
|
|
5613
|
+
ms: d.getUTCMilliseconds()
|
|
5496
5614
|
};
|
|
5497
5615
|
}
|
|
5498
5616
|
function midnight(zone, year, month, date) {
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5617
|
+
return timeAt(zone, year, month, date);
|
|
5618
|
+
}
|
|
5619
|
+
function timeAt(zone, year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
|
|
5620
|
+
if (zone === "local") {
|
|
5621
|
+
const d = /* @__PURE__ */ new Date(0);
|
|
5504
5622
|
d.setFullYear(year, month, date);
|
|
5505
|
-
d.setHours(
|
|
5623
|
+
d.setHours(hours, minutes, seconds, ms);
|
|
5624
|
+
return d.getTime();
|
|
5506
5625
|
}
|
|
5626
|
+
const shown = utc(year, month, date, hours, minutes, seconds, ms);
|
|
5627
|
+
if (zone === "UTC") return shown;
|
|
5628
|
+
const before = shown - (shownAt(shown - DAY, zone) - (shown - DAY));
|
|
5629
|
+
const after = shown - (shownAt(shown + DAY, zone) - (shown + DAY));
|
|
5630
|
+
if (before === after) return before;
|
|
5631
|
+
const fits = [before, after].filter((t) => shownAt(t, zone) === shown);
|
|
5632
|
+
return fits.length > 0 ? Math.min(...fits) : before;
|
|
5633
|
+
}
|
|
5634
|
+
function utc(year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
|
|
5635
|
+
const d = /* @__PURE__ */ new Date(0);
|
|
5636
|
+
d.setUTCFullYear(year, month, date);
|
|
5637
|
+
d.setUTCHours(hours, minutes, seconds, ms);
|
|
5507
5638
|
return d.getTime();
|
|
5508
5639
|
}
|
|
5640
|
+
function shownAt(t, zone) {
|
|
5641
|
+
if (zone === "UTC") return t;
|
|
5642
|
+
if (zone === "local") {
|
|
5643
|
+
const d = new Date(t);
|
|
5644
|
+
return utc(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
|
|
5645
|
+
}
|
|
5646
|
+
const ms = (t % SECOND + SECOND) % SECOND;
|
|
5647
|
+
const fields = {};
|
|
5648
|
+
for (const part of clockOf(zone).formatToParts(t - ms)) fields[part.type] = part.value;
|
|
5649
|
+
const year = Number(fields["year"]);
|
|
5650
|
+
return utc(fields["era"] === "BC" ? 1 - year : year, Number(fields["month"]) - 1, Number(fields["day"]), Number(fields["hour"]) % 24, Number(fields["minute"]), Number(fields["second"]), ms);
|
|
5651
|
+
}
|
|
5652
|
+
function clockReader(zone) {
|
|
5653
|
+
if (zone === "UTC" || zone === "local") return (t) => shownAt(t, zone);
|
|
5654
|
+
const kept = /* @__PURE__ */ new Map();
|
|
5655
|
+
return (t) => {
|
|
5656
|
+
let shown = kept.get(t);
|
|
5657
|
+
if (shown === void 0) kept.set(t, shown = shownAt(t, zone));
|
|
5658
|
+
return shown;
|
|
5659
|
+
};
|
|
5660
|
+
}
|
|
5661
|
+
function twinOf(t, shown) {
|
|
5662
|
+
const at = shown(t);
|
|
5663
|
+
for (const near of [t - DAY, t + DAY]) {
|
|
5664
|
+
const other = at - (shown(near) - near);
|
|
5665
|
+
if (other !== t && shown(other) === at) return other;
|
|
5666
|
+
}
|
|
5667
|
+
}
|
|
5668
|
+
const clocks = /* @__PURE__ */ new Map();
|
|
5669
|
+
function clockOf(zone) {
|
|
5670
|
+
let clock = clocks.get(zone);
|
|
5671
|
+
if (!clock) {
|
|
5672
|
+
clock = new Intl.DateTimeFormat("en-US", {
|
|
5673
|
+
timeZone: zone,
|
|
5674
|
+
hourCycle: "h23",
|
|
5675
|
+
era: "short",
|
|
5676
|
+
year: "numeric",
|
|
5677
|
+
month: "numeric",
|
|
5678
|
+
day: "numeric",
|
|
5679
|
+
hour: "numeric",
|
|
5680
|
+
minute: "numeric",
|
|
5681
|
+
second: "numeric"
|
|
5682
|
+
});
|
|
5683
|
+
clocks.set(zone, clock);
|
|
5684
|
+
}
|
|
5685
|
+
return clock;
|
|
5686
|
+
}
|
|
5509
5687
|
// src/charts/line-layout.ts
|
|
5510
5688
|
const LINE_WIDTH = 2.25;
|
|
5511
5689
|
const DOT_RADIUS = 4.5;
|
|
@@ -5533,7 +5711,7 @@ function lineEncoding(options) {
|
|
|
5533
5711
|
const labels = options.labels;
|
|
5534
5712
|
if (labels !== void 0 && labels !== false && typeof labels !== "function") throw new TypeError("lineChart: labels must be false or a function that returns a line's end label.");
|
|
5535
5713
|
const timeZone = options.timeZone ?? "UTC";
|
|
5536
|
-
if (!
|
|
5714
|
+
if (!isTimeZone(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC", "local" or the name of a zone Intl knows, such as "Europe/London", got ${show$1(timeZone)}.`);
|
|
5537
5715
|
const xFormat = options.xFormat;
|
|
5538
5716
|
if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
|
|
5539
5717
|
const curve = options.curve ?? "linear";
|
|
@@ -5550,6 +5728,17 @@ function lineEncoding(options) {
|
|
|
5550
5728
|
curve
|
|
5551
5729
|
};
|
|
5552
5730
|
}
|
|
5731
|
+
function checkRoom(room) {
|
|
5732
|
+
const px = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
5733
|
+
if (typeof room !== "object" || room === null || Array.isArray(room)) {
|
|
5734
|
+
if (room !== void 0 && !px(room)) throw new RangeError(`lineChart: room must be a number of px, 0 or more, got ${typeof room === "object" ? JSON.stringify(room) : String(room)}.`);
|
|
5735
|
+
return;
|
|
5736
|
+
}
|
|
5737
|
+
for (const side of ["right", "top"]) {
|
|
5738
|
+
const value = room[side];
|
|
5739
|
+
if (value !== void 0 && !px(value)) throw new RangeError(`lineChart: room.${side} must be a number of px, 0 or more, got ${String(value)}.`);
|
|
5740
|
+
}
|
|
5741
|
+
}
|
|
5553
5742
|
function layoutLines(input) {
|
|
5554
5743
|
const { width, measure } = input;
|
|
5555
5744
|
const height = input.height ?? HEIGHT;
|
|
@@ -5566,9 +5755,11 @@ function layoutLines(input) {
|
|
|
5566
5755
|
const xValues = ticked.map((tick) => tick.value);
|
|
5567
5756
|
const xTexts = ticked.map((tick) => tick.text);
|
|
5568
5757
|
const xWidths = xTexts.map((text) => measure(text, "ec-tick", TICK_SIZE));
|
|
5758
|
+
const room = typeof input.room === "number" ? { right: input.room } : input.room;
|
|
5569
5759
|
const labelWidth = input.label ? widest(distinctLabels(rows, input.label), "ec-value", VALUE_SIZE, measure) : 0;
|
|
5570
5760
|
const left = Math.max(widest(yTexts, "ec-tick", TICK_SIZE, measure) + 10, (xWidths[0] ?? 0) / 2 + 2);
|
|
5571
|
-
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (
|
|
5761
|
+
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (room?.right ?? 0));
|
|
5762
|
+
const top = TOP + (room?.top ?? 0);
|
|
5572
5763
|
const frame = {
|
|
5573
5764
|
scale: {
|
|
5574
5765
|
lo: domain.lo,
|
|
@@ -5579,8 +5770,8 @@ function layoutLines(input) {
|
|
|
5579
5770
|
xHi,
|
|
5580
5771
|
left,
|
|
5581
5772
|
right: Math.max(left, width - right),
|
|
5582
|
-
top
|
|
5583
|
-
bottom: Math.max(
|
|
5773
|
+
top,
|
|
5774
|
+
bottom: Math.max(top, height - AXIS),
|
|
5584
5775
|
width,
|
|
5585
5776
|
height
|
|
5586
5777
|
}
|
|
@@ -6011,11 +6202,13 @@ const show$1 = (value) => typeof value === "string" ? JSON.stringify(value) : St
|
|
|
6011
6202
|
// src/charts/line.ts
|
|
6012
6203
|
const STAGE = 500;
|
|
6013
6204
|
const RING = 2;
|
|
6205
|
+
const DOT_RING = 2;
|
|
6014
6206
|
const VISIBLE = .5;
|
|
6015
6207
|
function lineChart$1(target, options, env) {
|
|
6016
6208
|
const container = resolveTarget$2(target, "lineChart");
|
|
6017
6209
|
checkChartOptions(options, "lineChart");
|
|
6018
6210
|
let hoverKind = hoverOf(options);
|
|
6211
|
+
missingOf(options);
|
|
6019
6212
|
let current = options;
|
|
6020
6213
|
const motion = chartMotion(options.motion, env.motion);
|
|
6021
6214
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -6045,17 +6238,19 @@ function lineChart$1(target, options, env) {
|
|
|
6045
6238
|
"aria-hidden": "true",
|
|
6046
6239
|
visibility: "hidden"
|
|
6047
6240
|
}, svg);
|
|
6048
|
-
const
|
|
6241
|
+
const linesLayer = svgElement("g", { class: "ec-lines" }, svgElement("g", {
|
|
6049
6242
|
class: "ec-marks",
|
|
6050
6243
|
"aria-hidden": "true"
|
|
6051
|
-
}, svg);
|
|
6052
|
-
const linesLayer = svgElement("g", { class: "ec-lines" }, marksLayer);
|
|
6053
|
-
const pointsLayer = svgElement("g", { class: "ec-points" }, marksLayer);
|
|
6054
|
-
const columnsLayer = svgElement("g", { class: "ec-columns" }, svg);
|
|
6244
|
+
}, svg));
|
|
6055
6245
|
const overlay = svgElement("g", {
|
|
6056
6246
|
class: "ec-overlay",
|
|
6057
6247
|
"aria-hidden": "true"
|
|
6058
6248
|
}, svg);
|
|
6249
|
+
const pointsLayer = svgElement("g", { class: "ec-points" }, svgElement("g", {
|
|
6250
|
+
class: "ec-marks",
|
|
6251
|
+
"aria-hidden": "true"
|
|
6252
|
+
}, svg));
|
|
6253
|
+
const columnsLayer = svgElement("g", { class: "ec-columns" }, svg);
|
|
6059
6254
|
const measure = textMeasure(svg);
|
|
6060
6255
|
let rowOrder = [];
|
|
6061
6256
|
const rows = /* @__PURE__ */ new Map();
|
|
@@ -6152,8 +6347,8 @@ function lineChart$1(target, options, env) {
|
|
|
6152
6347
|
function layout(opts, using = effects) {
|
|
6153
6348
|
const encoding = lineEncoding(opts);
|
|
6154
6349
|
checkNeeds$1(using, encoding.series.map((s) => s.series), "lineChart");
|
|
6155
|
-
const { room
|
|
6156
|
-
|
|
6350
|
+
const { room } = opts;
|
|
6351
|
+
checkRoom(room);
|
|
6157
6352
|
const next = layoutLines({
|
|
6158
6353
|
data: opts.data,
|
|
6159
6354
|
encoding,
|
|
@@ -6593,6 +6788,14 @@ function lineChart$1(target, options, env) {
|
|
|
6593
6788
|
crosshair.setAttribute("visibility", "hidden");
|
|
6594
6789
|
tooltip.hide();
|
|
6595
6790
|
}
|
|
6791
|
+
function stand(key) {
|
|
6792
|
+
const record = key === void 0 ? void 0 : rows.get(key);
|
|
6793
|
+
if (!record || !revealed(record)) crosshair.setAttribute("visibility", "hidden");
|
|
6794
|
+
else setAttributes(crosshair, {
|
|
6795
|
+
...placeCrosshair(drawnFrame, record.px),
|
|
6796
|
+
visibility: void 0
|
|
6797
|
+
});
|
|
6798
|
+
}
|
|
6596
6799
|
let ringLine;
|
|
6597
6800
|
function drawRing(key) {
|
|
6598
6801
|
const point = key === void 0 ? void 0 : points.get(key);
|
|
@@ -6632,6 +6835,7 @@ function lineChart$1(target, options, env) {
|
|
|
6632
6835
|
}
|
|
6633
6836
|
function followHover() {
|
|
6634
6837
|
if (hover.key !== void 0) showHover(hover.key);
|
|
6838
|
+
if (hover.standing !== void 0) stand(hover.standing);
|
|
6635
6839
|
if (hover.ringKey !== void 0) drawRing(hover.ringKey);
|
|
6636
6840
|
}
|
|
6637
6841
|
const input = (record) => ({
|
|
@@ -6642,6 +6846,28 @@ function lineChart$1(target, options, env) {
|
|
|
6642
6846
|
mark: record.shown.geometry,
|
|
6643
6847
|
data: record.shown.data
|
|
6644
6848
|
});
|
|
6849
|
+
function standIn(key) {
|
|
6850
|
+
const record = rows.get(key);
|
|
6851
|
+
if (!record || !revealed(record)) return void 0;
|
|
6852
|
+
const { row } = record;
|
|
6853
|
+
return {
|
|
6854
|
+
mark: describePoint({
|
|
6855
|
+
key,
|
|
6856
|
+
x: record.px,
|
|
6857
|
+
y: drawnFrame.box.top,
|
|
6858
|
+
r: DOT_RADIUS
|
|
6859
|
+
}),
|
|
6860
|
+
data: {
|
|
6861
|
+
datum: row.datum,
|
|
6862
|
+
samples: [{
|
|
6863
|
+
t: 0,
|
|
6864
|
+
value: NaN,
|
|
6865
|
+
at: laidOut.time ? new Date(row.x) : row.x
|
|
6866
|
+
}],
|
|
6867
|
+
related: () => void 0
|
|
6868
|
+
}
|
|
6869
|
+
};
|
|
6870
|
+
}
|
|
6645
6871
|
function liveRowOf(eventTarget) {
|
|
6646
6872
|
const element = eventTarget;
|
|
6647
6873
|
const column = typeof element?.closest === "function" ? element.closest(".ec-column") : null;
|
|
@@ -6737,7 +6963,7 @@ function lineChart$1(target, options, env) {
|
|
|
6737
6963
|
if (hoverKind !== "point") return;
|
|
6738
6964
|
if (!stopsLayer) {
|
|
6739
6965
|
stopsLayer = svgElement("g", { class: "ec-stops" }, svg);
|
|
6740
|
-
svg.insertBefore(stopsLayer,
|
|
6966
|
+
svg.insertBefore(stopsLayer, columnsLayer.nextSibling);
|
|
6741
6967
|
plotHit = svgElement("rect", { class: "ec-hit" }, stopsLayer);
|
|
6742
6968
|
stopsLayer.addEventListener("click", (event) => {
|
|
6743
6969
|
const point = pointAt(event.clientX, event.clientY);
|
|
@@ -6909,6 +7135,8 @@ function lineChart$1(target, options, env) {
|
|
|
6909
7135
|
const record = findMark(key);
|
|
6910
7136
|
return record && onScreen(record);
|
|
6911
7137
|
},
|
|
7138
|
+
standIn,
|
|
7139
|
+
stand,
|
|
6912
7140
|
ring: drawRing,
|
|
6913
7141
|
tooltip: {
|
|
6914
7142
|
show: showHover,
|
|
@@ -6937,7 +7165,8 @@ function lineChart$1(target, options, env) {
|
|
|
6937
7165
|
total: total(row.values)
|
|
6938
7166
|
})),
|
|
6939
7167
|
format: format(opts),
|
|
6940
|
-
total: false
|
|
7168
|
+
total: false,
|
|
7169
|
+
missing: missingOf(opts)
|
|
6941
7170
|
});
|
|
6942
7171
|
}
|
|
6943
7172
|
function labelColumn(record) {
|
|
@@ -7176,14 +7405,16 @@ function lineChart$1(target, options, env) {
|
|
|
7176
7405
|
for (const point of points.values()) point.target = placed.points.get(point.key) ?? point.target;
|
|
7177
7406
|
transitionTo(next, true);
|
|
7178
7407
|
}
|
|
7408
|
+
const remeasure = () => {
|
|
7409
|
+
measure.clear();
|
|
7410
|
+
relayout();
|
|
7411
|
+
};
|
|
7412
|
+
const unwatchText = watchText(svg, clock, remeasure);
|
|
7179
7413
|
const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
|
|
7180
7414
|
measuredWidth = width;
|
|
7181
7415
|
if (current.width === void 0) relayout();
|
|
7182
7416
|
});
|
|
7183
|
-
const unwatchFonts = watchFonts(doc,
|
|
7184
|
-
measure.clear();
|
|
7185
|
-
relayout();
|
|
7186
|
-
});
|
|
7417
|
+
const unwatchFonts = watchFonts(doc, remeasure);
|
|
7187
7418
|
describeChart(svg, current);
|
|
7188
7419
|
syncLegend();
|
|
7189
7420
|
table.render(firstTable);
|
|
@@ -7211,6 +7442,11 @@ function lineChart$1(target, options, env) {
|
|
|
7211
7442
|
const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
|
|
7212
7443
|
hover.sync();
|
|
7213
7444
|
runner.enter(liveMarks().map(input));
|
|
7445
|
+
function stopFor(key) {
|
|
7446
|
+
const row = rows.get(key);
|
|
7447
|
+
if (hoverKind === "x") return (row ?? points.get(key)?.row)?.key;
|
|
7448
|
+
return (points.get(key) ?? (row && livePoints(row)[0]))?.key;
|
|
7449
|
+
}
|
|
7214
7450
|
return linkable(hover.link, {
|
|
7215
7451
|
element: svg,
|
|
7216
7452
|
async update(next) {
|
|
@@ -7222,6 +7458,7 @@ function lineChart$1(target, options, env) {
|
|
|
7222
7458
|
};
|
|
7223
7459
|
checkChartOptions(merged, "lineChart");
|
|
7224
7460
|
const kind = hoverOf(merged);
|
|
7461
|
+
missingOf(merged);
|
|
7225
7462
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
7226
7463
|
const nextLayout = layout(merged, swapped);
|
|
7227
7464
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -7280,30 +7517,40 @@ function lineChart$1(target, options, env) {
|
|
|
7280
7517
|
on: events.on,
|
|
7281
7518
|
marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
|
|
7282
7519
|
focus(key) {
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
if (hoverKind === "x") {
|
|
7286
|
-
const record = row ?? points.get(key)?.row;
|
|
7287
|
-
if (record) hover.focus(record.key);
|
|
7288
|
-
return;
|
|
7289
|
-
}
|
|
7290
|
-
const point = points.get(key) ?? (row && livePoints(row)[0]);
|
|
7291
|
-
if (point) hover.focus(point.key);
|
|
7520
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
7521
|
+
if (stop !== void 0) hover.focus(stop);
|
|
7292
7522
|
},
|
|
7293
7523
|
leave() {
|
|
7294
7524
|
if (!destroyed) hover.leave();
|
|
7295
7525
|
},
|
|
7296
7526
|
labels: () => lineOrder.flatMap((line) => chartLabel(line.key, "value", line.drawnLabel, line.label)),
|
|
7297
7527
|
paintOf(key) {
|
|
7298
|
-
const
|
|
7299
|
-
|
|
7300
|
-
color:
|
|
7301
|
-
drawn:
|
|
7528
|
+
const line = lines.get(key);
|
|
7529
|
+
if (line) return {
|
|
7530
|
+
color: line.series,
|
|
7531
|
+
drawn: true,
|
|
7532
|
+
...line.end.getAttribute("visibility") === "hidden" ? {} : {
|
|
7533
|
+
end: DOT_RADIUS,
|
|
7534
|
+
ring: DOT_RING
|
|
7535
|
+
}
|
|
7302
7536
|
};
|
|
7537
|
+
const point = points.get(key);
|
|
7538
|
+
return point && (point.group.classList.contains("ec-alone") ? {
|
|
7539
|
+
color: point.series,
|
|
7540
|
+
drawn: true,
|
|
7541
|
+
ring: DOT_RING
|
|
7542
|
+
} : {
|
|
7543
|
+
color: point.series,
|
|
7544
|
+
drawn: false
|
|
7545
|
+
});
|
|
7303
7546
|
},
|
|
7304
7547
|
standsFor(key) {
|
|
7305
7548
|
return rows.has(key) ? [...laidOut.series.map((series) => pointKey(series, key)), key] : [key];
|
|
7306
7549
|
},
|
|
7550
|
+
moveTabStop(key) {
|
|
7551
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
7552
|
+
return stop !== void 0 && hover.moveTabStop(stop);
|
|
7553
|
+
},
|
|
7307
7554
|
destroy() {
|
|
7308
7555
|
if (destroyed) return;
|
|
7309
7556
|
destroyed = true;
|
|
@@ -7315,6 +7562,7 @@ function lineChart$1(target, options, env) {
|
|
|
7315
7562
|
table.destroy();
|
|
7316
7563
|
announcer?.destroy();
|
|
7317
7564
|
unwatchHoverDuration();
|
|
7565
|
+
unwatchText();
|
|
7318
7566
|
unwatchWidth();
|
|
7319
7567
|
unwatchFonts();
|
|
7320
7568
|
for (const record of [...rowOrder, ...leavingRows.values()]) for (const value of [
|
|
@@ -7417,9 +7665,10 @@ function labelled(values, options) {
|
|
|
7417
7665
|
}
|
|
7418
7666
|
function said(values, options) {
|
|
7419
7667
|
const formatted = format(options);
|
|
7668
|
+
const missing = missingOf(options);
|
|
7420
7669
|
return values.map((v) => {
|
|
7421
7670
|
const label = seriesLabel(options.seriesLabels, v.series);
|
|
7422
|
-
return v.value === void 0 ? `${label} missing` : `${formatted(v.value)} ${label}`;
|
|
7671
|
+
return v.value === void 0 ? `${label} ${missing}` : `${formatted(v.value)} ${label}`;
|
|
7423
7672
|
});
|
|
7424
7673
|
}
|
|
7425
7674
|
function summary(row, options) {
|
|
@@ -7476,6 +7725,11 @@ function hoverOf(options) {
|
|
|
7476
7725
|
if (hover !== "x" && hover !== "point") throw new TypeError(`lineChart: hover must be "x" or "point", got ${typeof hover === "string" ? JSON.stringify(hover) : String(hover)}.`);
|
|
7477
7726
|
return hover;
|
|
7478
7727
|
}
|
|
7728
|
+
function missingOf(options) {
|
|
7729
|
+
const { missing = MISSING } = options;
|
|
7730
|
+
if (typeof missing !== "string" || missing.trim() === "") throw new TypeError(`lineChart: missing must be a word for a missing value, such as "no data", got ${typeof missing === "string" ? JSON.stringify(missing) : String(missing)}.`);
|
|
7731
|
+
return missing;
|
|
7732
|
+
}
|
|
7479
7733
|
// src/core/geometry/ring.ts
|
|
7480
7734
|
const ROUND = .5;
|
|
7481
7735
|
function goesRound(mark) {
|
|
@@ -7746,7 +8000,7 @@ function keepsCircles(m) {
|
|
|
7746
8000
|
const tiny = 1e-4 * Math.max(u, v);
|
|
7747
8001
|
return Math.abs(u - v) <= tiny && Math.abs(a * c + b * d) <= tiny;
|
|
7748
8002
|
}
|
|
7749
|
-
function scaleOf$
|
|
8003
|
+
function scaleOf$2(m) {
|
|
7750
8004
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
7751
8005
|
}
|
|
7752
8006
|
function boxIn(m, rect) {
|
|
@@ -7961,7 +8215,7 @@ function cssMatrix(m) {
|
|
|
7961
8215
|
const NEAR = .5;
|
|
7962
8216
|
const MOST = 32;
|
|
7963
8217
|
function sliceOf$1(commands, m) {
|
|
7964
|
-
const scale = scaleOf$
|
|
8218
|
+
const scale = scaleOf$2(m);
|
|
7965
8219
|
if (!keepsCircles(m) || !(scale > 0) || commands.length > MOST || commands.some((command) => command.op === "C" || command.op === "Q")) return void 0;
|
|
7966
8220
|
const near = NEAR / scale;
|
|
7967
8221
|
const subpaths = flattenPath(commands);
|
|
@@ -8074,7 +8328,7 @@ const onCircle = (run, center, radius, near) => Math.abs(run.radius - radius) <=
|
|
|
8074
8328
|
1
|
|
8075
8329
|
].every((u) => Math.abs(distance$1(pointOn(arc, u), center) - radius) <= near));
|
|
8076
8330
|
function moved(own, m) {
|
|
8077
|
-
const scale = scaleOf$
|
|
8331
|
+
const scale = scaleOf$2(m);
|
|
8078
8332
|
const center = matrix.apply(m, own.center);
|
|
8079
8333
|
const corner = matrix.apply(m, {
|
|
8080
8334
|
x: own.center.x + own.outer * Math.cos(own.start),
|
|
@@ -8295,7 +8549,7 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
|
|
|
8295
8549
|
"graphics-object"
|
|
8296
8550
|
]);
|
|
8297
8551
|
function expressive$1(target, options, env) {
|
|
8298
|
-
checkOptions$
|
|
8552
|
+
checkOptions$12(options);
|
|
8299
8553
|
const motion = chartMotion(options.motion, env.motion);
|
|
8300
8554
|
let effects = resolveEffects(options.on, env.presets);
|
|
8301
8555
|
let given = options.on;
|
|
@@ -8440,7 +8694,7 @@ function expressive$1(target, options, env) {
|
|
|
8440
8694
|
series,
|
|
8441
8695
|
x: round$1(center.x),
|
|
8442
8696
|
y: round$1(center.y),
|
|
8443
|
-
r: round$1(Math.max(0, r) * scaleOf$
|
|
8697
|
+
r: round$1(Math.max(0, r) * scaleOf$2(m))
|
|
8444
8698
|
});
|
|
8445
8699
|
} else {
|
|
8446
8700
|
const commands = shapeOutline(tag, attribute);
|
|
@@ -8478,9 +8732,9 @@ function expressive$1(target, options, env) {
|
|
|
8478
8732
|
}
|
|
8479
8733
|
function widthOf(stroke, m, at) {
|
|
8480
8734
|
const width = stroke?.width ?? 1;
|
|
8481
|
-
if (!stroke?.screen) return width * scaleOf$
|
|
8735
|
+
if (!stroke?.screen) return width * scaleOf$2(m);
|
|
8482
8736
|
const screen = at.screen(at.common);
|
|
8483
|
-
const scale = screen ? scaleOf$
|
|
8737
|
+
const scale = screen ? scaleOf$2(screen) : 0;
|
|
8484
8738
|
return scale > 0 ? width / scale : width;
|
|
8485
8739
|
}
|
|
8486
8740
|
function transformOf(element, at) {
|
|
@@ -8629,7 +8883,7 @@ function expressive$1(target, options, env) {
|
|
|
8629
8883
|
set: (style) => find(key)?.handle.set(style),
|
|
8630
8884
|
reset: () => find(key)?.handle.reset()
|
|
8631
8885
|
}),
|
|
8632
|
-
colors: (key) => find(key)?.mark
|
|
8886
|
+
colors: (key, part) => partOf(find(key)?.mark, part)?.colors
|
|
8633
8887
|
});
|
|
8634
8888
|
const runner = createRunner({
|
|
8635
8889
|
effects,
|
|
@@ -8682,7 +8936,7 @@ function expressive$1(target, options, env) {
|
|
|
8682
8936
|
from: from.geometry
|
|
8683
8937
|
});
|
|
8684
8938
|
else if (newRow || geometryChanged(from.geometry, mark.geometry) || samplesChanged(from.data.samples, mark.data.samples)) diff.moved.push(record);
|
|
8685
|
-
if (from.parts
|
|
8939
|
+
if (from.parts.length !== mark.parts.length || mark.parts.some((part, i) => part.colors?.color !== from.parts[i].colors?.color)) recolor.push(mark.key);
|
|
8686
8940
|
record.mark = mark;
|
|
8687
8941
|
} else {
|
|
8688
8942
|
record = leaving.get(mark.key);
|
|
@@ -9172,7 +9426,7 @@ function expressive$1(target, options, env) {
|
|
|
9172
9426
|
}
|
|
9173
9427
|
});
|
|
9174
9428
|
}
|
|
9175
|
-
function checkOptions$
|
|
9429
|
+
function checkOptions$12(options) {
|
|
9176
9430
|
if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
|
|
9177
9431
|
if (typeof options.key !== "function") throw new TypeError("expressive needs a key function, for example key: (d) => d.name. Marks are matched by key.");
|
|
9178
9432
|
for (const name of [
|
|
@@ -9184,6 +9438,11 @@ function checkOptions$11(options) {
|
|
|
9184
9438
|
]) if (options[name] !== void 0 && typeof options[name] !== "function") throw new TypeError(`expressive: ${name} must be a function.`);
|
|
9185
9439
|
if (options.baseline !== void 0 && options.baseline !== "auto" && !isBaseline(options.baseline)) throw new RangeError(`expressive: baseline must be "left", "right", "top", "bottom" or "auto", got ${String(options.baseline)}.`);
|
|
9186
9440
|
}
|
|
9441
|
+
function partOf(mark, key) {
|
|
9442
|
+
if (key === void 0) return mark?.parts[0];
|
|
9443
|
+
const segment = mark?.geometry.segments?.find((s) => s.key === key);
|
|
9444
|
+
return segment && mark.parts.find((p) => p.series === segment.series);
|
|
9445
|
+
}
|
|
9187
9446
|
function ownSeries(mark) {
|
|
9188
9447
|
const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
|
|
9189
9448
|
return [...new Set(names.filter((name) => name !== void 0))];
|
|
@@ -9627,7 +9886,7 @@ function pointsOf(first) {
|
|
|
9627
9886
|
function lineOf(key, element, first, m) {
|
|
9628
9887
|
const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
|
|
9629
9888
|
if (!straight(first)) {
|
|
9630
|
-
const scaled = width * scaleOf(m);
|
|
9889
|
+
const scaled = width * scaleOf$1(m);
|
|
9631
9890
|
return describeShape({
|
|
9632
9891
|
key,
|
|
9633
9892
|
series: key,
|
|
@@ -9643,7 +9902,7 @@ function lineOf(key, element, first, m) {
|
|
|
9643
9902
|
series: key,
|
|
9644
9903
|
points: points.map(({ point }) => matrix.apply(m, point)),
|
|
9645
9904
|
...breaks.length > 0 ? { breaks } : {},
|
|
9646
|
-
width: (Number.isFinite(width) ? width : 1) * scaleOf(m)
|
|
9905
|
+
width: (Number.isFinite(width) ? width : 1) * scaleOf$1(m)
|
|
9647
9906
|
});
|
|
9648
9907
|
}
|
|
9649
9908
|
function sliceOf(key, item, m) {
|
|
@@ -9651,7 +9910,7 @@ function sliceOf(key, item, m) {
|
|
|
9651
9910
|
x: number(item.x),
|
|
9652
9911
|
y: number(item.y)
|
|
9653
9912
|
});
|
|
9654
|
-
const s = scaleOf(m);
|
|
9913
|
+
const s = scaleOf$1(m);
|
|
9655
9914
|
const [start, end] = [number(item.startAngle), number(item.endAngle)].sort((a, b) => a - b);
|
|
9656
9915
|
return describeArc({
|
|
9657
9916
|
key,
|
|
@@ -9672,7 +9931,7 @@ function pointOf(key, item, m) {
|
|
|
9672
9931
|
key,
|
|
9673
9932
|
x: center.x,
|
|
9674
9933
|
y: center.y,
|
|
9675
|
-
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf(m)
|
|
9934
|
+
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf$1(m)
|
|
9676
9935
|
});
|
|
9677
9936
|
}
|
|
9678
9937
|
function boxOf(item) {
|
|
@@ -9687,19 +9946,19 @@ function boxOf(item) {
|
|
|
9687
9946
|
height: Math.abs(height)
|
|
9688
9947
|
};
|
|
9689
9948
|
}
|
|
9690
|
-
function scaleOf(m) {
|
|
9949
|
+
function scaleOf$1(m) {
|
|
9691
9950
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
9692
9951
|
}
|
|
9693
9952
|
function number(value) {
|
|
9694
9953
|
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
9695
9954
|
}
|
|
9696
9955
|
// src/charts/switch.ts
|
|
9697
|
-
const DURATION$
|
|
9956
|
+
const DURATION$8 = 950;
|
|
9698
9957
|
const OUT_BY = .4;
|
|
9699
9958
|
const HALF = .5;
|
|
9700
9959
|
function chartSwitch$1(target, options, env) {
|
|
9701
9960
|
const host = resolveTarget$2(target, "chartSwitch");
|
|
9702
|
-
const names = checkOptions$
|
|
9961
|
+
const names = checkOptions$11(options);
|
|
9703
9962
|
const effect = options.transition;
|
|
9704
9963
|
const colors = toColorAssignment(options.colors);
|
|
9705
9964
|
const motion = env.motion;
|
|
@@ -9743,7 +10002,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
9743
10002
|
const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
|
|
9744
10003
|
const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
|
|
9745
10004
|
const orders = /* @__PURE__ */ new WeakMap();
|
|
9746
|
-
const surfaceFor = (paints) => ({ group(key, order) {
|
|
10005
|
+
const surfaceFor = (paints, extras) => ({ group(key, order) {
|
|
9747
10006
|
const group = svgElement("g", {
|
|
9748
10007
|
class: "ec-run",
|
|
9749
10008
|
"data-key": key
|
|
@@ -9752,11 +10011,91 @@ function chartSwitch$1(target, options, env) {
|
|
|
9752
10011
|
orders.set(group, order);
|
|
9753
10012
|
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
|
|
9754
10013
|
runsLayer.insertBefore(group, above ?? null);
|
|
10014
|
+
const layer = svgLayer(group);
|
|
9755
10015
|
return {
|
|
9756
|
-
...
|
|
10016
|
+
...extras[order]?.wrap(layer, group) ?? layer,
|
|
9757
10017
|
clear: () => group.remove()
|
|
9758
10018
|
};
|
|
9759
10019
|
} });
|
|
10020
|
+
function extrasFor(rings, ends, dotColors) {
|
|
10021
|
+
const [ringA, ringB] = rings;
|
|
10022
|
+
const [endA, endB] = ends;
|
|
10023
|
+
if (ringA === 0 && ringB === 0 && !endA && !endB) return void 0;
|
|
10024
|
+
const dots = [];
|
|
10025
|
+
if (endA && endB) {
|
|
10026
|
+
const element = endDot();
|
|
10027
|
+
const draw = (s) => placeDot(element, {
|
|
10028
|
+
at: {
|
|
10029
|
+
x: mix$1(endA.at.x, endB.at.x, s),
|
|
10030
|
+
y: mix$1(endA.at.y, endB.at.y, s)
|
|
10031
|
+
},
|
|
10032
|
+
r: mix$1(endA.r, endB.r, s),
|
|
10033
|
+
ring: mix$1(endA.ring, endB.ring, s)
|
|
10034
|
+
});
|
|
10035
|
+
dots.push({
|
|
10036
|
+
element,
|
|
10037
|
+
draw
|
|
10038
|
+
});
|
|
10039
|
+
} else [[
|
|
10040
|
+
endA,
|
|
10041
|
+
fadeOut,
|
|
10042
|
+
dotColors[0]
|
|
10043
|
+
], [
|
|
10044
|
+
endB,
|
|
10045
|
+
fadeIn,
|
|
10046
|
+
dotColors[1]
|
|
10047
|
+
]].forEach(([end, opacity, color]) => {
|
|
10048
|
+
if (!end) return;
|
|
10049
|
+
const element = endDot();
|
|
10050
|
+
setStyles(element, markColorStyles(seriesColors(colors.slot(color))));
|
|
10051
|
+
placeDot(element, end);
|
|
10052
|
+
dots.push({
|
|
10053
|
+
element,
|
|
10054
|
+
draw: (s) => setAttributes(element, { opacity: opacity(s) })
|
|
10055
|
+
});
|
|
10056
|
+
});
|
|
10057
|
+
const ringed = ringA > 0 || ringB > 0;
|
|
10058
|
+
let width = ringA;
|
|
10059
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
10060
|
+
return {
|
|
10061
|
+
wrap(layer, group) {
|
|
10062
|
+
shapes.clear();
|
|
10063
|
+
const raise = () => {
|
|
10064
|
+
for (const dot of dots) group.appendChild(dot.element);
|
|
10065
|
+
};
|
|
10066
|
+
raise();
|
|
10067
|
+
return {
|
|
10068
|
+
...layer,
|
|
10069
|
+
path(d, paint) {
|
|
10070
|
+
const ring = ringed && paint.fill !== void 0 && paint.stroke === void 0;
|
|
10071
|
+
const handle = layer.path(d, ring ? {
|
|
10072
|
+
...paint,
|
|
10073
|
+
stroke: "surface",
|
|
10074
|
+
width
|
|
10075
|
+
} : paint);
|
|
10076
|
+
raise();
|
|
10077
|
+
if (!ring) return handle;
|
|
10078
|
+
shapes.set(handle, d);
|
|
10079
|
+
return {
|
|
10080
|
+
update(next, nextPaint) {
|
|
10081
|
+
shapes.set(handle, next);
|
|
10082
|
+
handle.update(next, nextPaint);
|
|
10083
|
+
},
|
|
10084
|
+
remove() {
|
|
10085
|
+
shapes.delete(handle);
|
|
10086
|
+
handle.remove();
|
|
10087
|
+
}
|
|
10088
|
+
};
|
|
10089
|
+
}
|
|
10090
|
+
};
|
|
10091
|
+
},
|
|
10092
|
+
draw(s) {
|
|
10093
|
+
width = mix$1(ringA, ringB, s);
|
|
10094
|
+
for (const [handle, d] of shapes) handle.update(d, { width });
|
|
10095
|
+
for (const dot of dots) dot.draw(s);
|
|
10096
|
+
}
|
|
10097
|
+
};
|
|
10098
|
+
}
|
|
9760
10099
|
let current = options.initial;
|
|
9761
10100
|
let active;
|
|
9762
10101
|
let destroyed = false;
|
|
@@ -9782,15 +10121,23 @@ function chartSwitch$1(target, options, env) {
|
|
|
9782
10121
|
}
|
|
9783
10122
|
function readFocus(from) {
|
|
9784
10123
|
const element = focused();
|
|
9785
|
-
|
|
9786
|
-
const keyed = element.closest("[data-key]");
|
|
10124
|
+
const inside = element !== null && from.container.contains(element);
|
|
10125
|
+
const keyed = (inside ? element : from.chart.element.querySelector("[tabindex=\"0\"]"))?.closest("[data-key]");
|
|
9787
10126
|
const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
|
|
9788
|
-
|
|
10127
|
+
if (!inside && key === null) return void 0;
|
|
10128
|
+
return {
|
|
10129
|
+
keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key],
|
|
10130
|
+
focused: inside
|
|
10131
|
+
};
|
|
9789
10132
|
}
|
|
9790
10133
|
function restoreFocus(to, memory) {
|
|
9791
10134
|
if (!memory) return;
|
|
9792
10135
|
const now = focused();
|
|
9793
|
-
|
|
10136
|
+
const away = now !== null && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now);
|
|
10137
|
+
if (!memory.focused || away) {
|
|
10138
|
+
for (const key of memory.keys) if (to.chart.moveTabStop?.(key)) return;
|
|
10139
|
+
return;
|
|
10140
|
+
}
|
|
9794
10141
|
const inside = () => to.chart.element.contains(focused());
|
|
9795
10142
|
for (const key of [...memory.keys, ...to.chart.marks().map((mark) => mark.key)]) {
|
|
9796
10143
|
to.chart.focus(key);
|
|
@@ -9918,12 +10265,15 @@ function chartSwitch$1(target, options, env) {
|
|
|
9918
10265
|
function prepare(a, b) {
|
|
9919
10266
|
const toA = between$1(overlay, a.chart.element, wrapper);
|
|
9920
10267
|
const toB = between$1(overlay, b.chart.element, wrapper);
|
|
10268
|
+
const scaleA = scaleOf(toA);
|
|
10269
|
+
const scaleB = scaleOf(toB);
|
|
9921
10270
|
const from = a.chart.marks().map((mark) => mapMark(mark, toA));
|
|
9922
10271
|
const to = b.chart.marks().map((mark) => mapMark(mark, toB));
|
|
9923
10272
|
const fromByKey = new Map(from.map((mark) => [mark.key, mark]));
|
|
9924
10273
|
const toKeys = new Set(to.map((mark) => mark.key));
|
|
9925
10274
|
const pairs = [];
|
|
9926
10275
|
const paints = [];
|
|
10276
|
+
const extras = [];
|
|
9927
10277
|
for (const mark of to) {
|
|
9928
10278
|
const partner = fromByKey.get(mark.key);
|
|
9929
10279
|
if (!partner) continue;
|
|
@@ -9935,14 +10285,18 @@ function chartSwitch$1(target, options, env) {
|
|
|
9935
10285
|
to: will.drawn ? mark : dot$1(mark)
|
|
9936
10286
|
});
|
|
9937
10287
|
paints.push(will.color);
|
|
10288
|
+
extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was.color, will.color]));
|
|
9938
10289
|
}
|
|
9939
10290
|
const drawings = [];
|
|
9940
|
-
|
|
10291
|
+
if (extras.some((each) => each !== void 0)) drawings.push((s) => {
|
|
10292
|
+
for (const each of extras) each?.draw(s);
|
|
10293
|
+
});
|
|
10294
|
+
const fade = (view, mark, scale, opacity) => {
|
|
9941
10295
|
const paint = paintOf(view, mark);
|
|
9942
|
-
if (paint.drawn) drawings.push(fadeMark(mark, paint
|
|
10296
|
+
if (paint.drawn) drawings.push(fadeMark(mark, paint, scale, opacity));
|
|
9943
10297
|
};
|
|
9944
|
-
for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, fadeOut);
|
|
9945
|
-
for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, fadeIn);
|
|
10298
|
+
for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, scaleA, fadeOut);
|
|
10299
|
+
for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, scaleB, fadeIn);
|
|
9946
10300
|
const id = (label) => `${label.role}\n${label.key}`;
|
|
9947
10301
|
const labelsA = a.chart.labels();
|
|
9948
10302
|
const labelsB = b.chart.labels();
|
|
@@ -9962,7 +10316,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
9962
10316
|
});
|
|
9963
10317
|
return {
|
|
9964
10318
|
pairs,
|
|
9965
|
-
surface: surfaceFor(paints),
|
|
10319
|
+
surface: surfaceFor(paints, extras),
|
|
9966
10320
|
scene: {
|
|
9967
10321
|
draw: (s) => {
|
|
9968
10322
|
for (const draw of drawings) draw(s);
|
|
@@ -9975,18 +10329,36 @@ function chartSwitch$1(target, options, env) {
|
|
|
9975
10329
|
}
|
|
9976
10330
|
};
|
|
9977
10331
|
}
|
|
9978
|
-
function fadeMark(mark,
|
|
10332
|
+
function fadeMark(mark, paint, scale, opacity) {
|
|
9979
10333
|
const group = svgElement("g", {
|
|
9980
10334
|
class: "ec-switch-fade",
|
|
9981
10335
|
"data-key": mark.key
|
|
9982
10336
|
}, fadesLayer);
|
|
9983
|
-
setStyles(group, markColorStyles(seriesColors(colors.slot(color))));
|
|
9984
|
-
|
|
10337
|
+
setStyles(group, markColorStyles(seriesColors(colors.slot(paint.color))));
|
|
10338
|
+
const ring = ringOf(paint, scale);
|
|
10339
|
+
svgLayer(group).path(mark.outline.d, mark.outline.closed ? {
|
|
10340
|
+
fill: "mark",
|
|
10341
|
+
...ring > 0 ? {
|
|
10342
|
+
stroke: "surface",
|
|
10343
|
+
width: ring
|
|
10344
|
+
} : {}
|
|
10345
|
+
} : {
|
|
9985
10346
|
stroke: "mark",
|
|
9986
10347
|
width: mark.thickness
|
|
9987
10348
|
});
|
|
10349
|
+
const end = endOf(paint, mark, scale);
|
|
10350
|
+
if (end) placeDot(group.appendChild(endDot()), end);
|
|
9988
10351
|
return (s) => setAttributes(group, { opacity: opacity(s) });
|
|
9989
10352
|
}
|
|
10353
|
+
function endDot() {
|
|
10354
|
+
const element = doc.createElementNS(SVG_NS$2, "circle");
|
|
10355
|
+
element.setAttribute("class", "ec-switch-end");
|
|
10356
|
+
setStyles(element, {
|
|
10357
|
+
fill: cssColor("mark"),
|
|
10358
|
+
stroke: cssColor("surface")
|
|
10359
|
+
});
|
|
10360
|
+
return element;
|
|
10361
|
+
}
|
|
9990
10362
|
function copyLabel(label, m) {
|
|
9991
10363
|
const text = label.element.cloneNode(true);
|
|
9992
10364
|
for (const name of [
|
|
@@ -10117,7 +10489,7 @@ function drive(begin, at, env) {
|
|
|
10117
10489
|
const begun = unease(begin);
|
|
10118
10490
|
let running;
|
|
10119
10491
|
running = tween({
|
|
10120
|
-
duration: DURATION$
|
|
10492
|
+
duration: DURATION$8,
|
|
10121
10493
|
timing: "transition",
|
|
10122
10494
|
ease: linear,
|
|
10123
10495
|
update: (k) => {
|
|
@@ -10188,12 +10560,29 @@ function dot$1(mark) {
|
|
|
10188
10560
|
r: 0
|
|
10189
10561
|
});
|
|
10190
10562
|
}
|
|
10563
|
+
const ringOf = (paint, scale) => paint.drawn && paint.end === void 0 ? (paint.ring ?? 0) * scale : 0;
|
|
10564
|
+
function endOf(paint, mark, scale) {
|
|
10565
|
+
return paint.drawn && paint.end !== void 0 ? {
|
|
10566
|
+
at: mark.end,
|
|
10567
|
+
r: paint.end * scale,
|
|
10568
|
+
ring: (paint.ring ?? 0) * scale
|
|
10569
|
+
} : void 0;
|
|
10570
|
+
}
|
|
10571
|
+
function placeDot(element, end) {
|
|
10572
|
+
setAttributes(element, {
|
|
10573
|
+
cx: end.at.x,
|
|
10574
|
+
cy: end.at.y,
|
|
10575
|
+
r: end.r,
|
|
10576
|
+
"stroke-width": end.ring
|
|
10577
|
+
});
|
|
10578
|
+
}
|
|
10191
10579
|
const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
10580
|
+
const scaleOf = (m) => Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
10192
10581
|
function mapMark(mark, m) {
|
|
10193
10582
|
if (isIdentity(m)) return mark;
|
|
10194
10583
|
const point = (p) => matrix.apply(m, p);
|
|
10195
10584
|
const path = (d) => formatPath(transformPath(parsePath(d), m));
|
|
10196
|
-
const scale =
|
|
10585
|
+
const scale = scaleOf(m);
|
|
10197
10586
|
const { outline } = mark;
|
|
10198
10587
|
return {
|
|
10199
10588
|
key: mark.key,
|
|
@@ -10243,7 +10632,7 @@ function isView(value, container) {
|
|
|
10243
10632
|
"destroy"
|
|
10244
10633
|
].every((method) => typeof view[method] === "function") && element?.nodeType === 1 && container.contains(element);
|
|
10245
10634
|
}
|
|
10246
|
-
function checkOptions$
|
|
10635
|
+
function checkOptions$11(options) {
|
|
10247
10636
|
if (typeof options !== "object" || options === null) throw new TypeError("chartSwitch needs options.");
|
|
10248
10637
|
const { views, initial, transition, announce } = options;
|
|
10249
10638
|
if (typeof views !== "object" || views === null) throw new TypeError("chartSwitch needs views: by name, a function that draws each view's chart in the container it's given.");
|
|
@@ -10276,7 +10665,7 @@ let switches = 0;
|
|
|
10276
10665
|
function motionSwitch$1(target, motion, options = {}) {
|
|
10277
10666
|
const parent = resolveTarget$1(target);
|
|
10278
10667
|
checkMotion(motion);
|
|
10279
|
-
checkOptions$
|
|
10668
|
+
checkOptions$10(options);
|
|
10280
10669
|
const labels = {
|
|
10281
10670
|
...LABELS$1,
|
|
10282
10671
|
...options.labels
|
|
@@ -10360,7 +10749,7 @@ function resolveTarget$1(target) {
|
|
|
10360
10749
|
function checkMotion(motion) {
|
|
10361
10750
|
if (typeof motion !== "object" || motion === null || typeof motion.chooseMode !== "function" || typeof motion.subscribe !== "function") throw new TypeError("motionSwitch needs a Motion, such as the page-wide `motion` or one from createMotion().");
|
|
10362
10751
|
}
|
|
10363
|
-
function checkOptions$
|
|
10752
|
+
function checkOptions$10(options) {
|
|
10364
10753
|
const { label, labels, hints, persist } = options;
|
|
10365
10754
|
if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
|
|
10366
10755
|
for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
|
|
@@ -10377,7 +10766,7 @@ const LABELS = {
|
|
|
10377
10766
|
function playButton(target, playback, options = {}) {
|
|
10378
10767
|
const parent = resolveTarget(target);
|
|
10379
10768
|
checkPlayback(playback);
|
|
10380
|
-
checkOptions$
|
|
10769
|
+
checkOptions$9(options);
|
|
10381
10770
|
const labels = {
|
|
10382
10771
|
...LABELS,
|
|
10383
10772
|
...options.labels
|
|
@@ -10418,7 +10807,7 @@ function resolveTarget(target) {
|
|
|
10418
10807
|
function checkPlayback(playback) {
|
|
10419
10808
|
if (typeof playback !== "object" || playback === null || typeof playback.play !== "function" || typeof playback.pause !== "function" || typeof playback.subscribe !== "function") throw new TypeError("playButton needs a Playback, from playback().");
|
|
10420
10809
|
}
|
|
10421
|
-
function checkOptions$
|
|
10810
|
+
function checkOptions$9(options) {
|
|
10422
10811
|
const { labels } = options;
|
|
10423
10812
|
if (labels === void 0) return;
|
|
10424
10813
|
for (const [key, text] of Object.entries(labels)) if (typeof text !== "string" || text.trim() === "") throw new TypeError(`playButton: labels.${key} must be a string with some text, got ${JSON.stringify(text) ?? String(text)}.`);
|
|
@@ -10470,7 +10859,7 @@ const gaits = {
|
|
|
10470
10859
|
const SPEED = 360;
|
|
10471
10860
|
const SHORTEST = 260;
|
|
10472
10861
|
const LONGEST = 4e3;
|
|
10473
|
-
const MIN_WALK$
|
|
10862
|
+
const MIN_WALK$3 = .5;
|
|
10474
10863
|
const FIT = .85;
|
|
10475
10864
|
const MIN_SMOOTHING = 2;
|
|
10476
10865
|
const IDENTITY = [
|
|
@@ -10488,12 +10877,12 @@ const ORIENTS = [
|
|
|
10488
10877
|
];
|
|
10489
10878
|
const RIDES = ["center", "on"];
|
|
10490
10879
|
function travel(icon, options = {}) {
|
|
10491
|
-
checkOptions$
|
|
10880
|
+
checkOptions$8(icon, options);
|
|
10492
10881
|
function plan(mark, ctx) {
|
|
10493
10882
|
const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
|
|
10494
10883
|
if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
|
|
10495
10884
|
const walk = pick(mark, options.along);
|
|
10496
|
-
if (!walk || !(drawn(walk) >= MIN_WALK$
|
|
10885
|
+
if (!walk || !(drawn(walk) >= MIN_WALK$3)) return void 0;
|
|
10497
10886
|
const scale = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
|
|
10498
10887
|
if (!(scale > 0)) return void 0;
|
|
10499
10888
|
return trip(walk, resolved, scale, options);
|
|
@@ -10641,7 +11030,7 @@ function heading(walk, distance, window, leg) {
|
|
|
10641
11030
|
}
|
|
10642
11031
|
return walk.angle(distance / length);
|
|
10643
11032
|
}
|
|
10644
|
-
function checkOptions$
|
|
11033
|
+
function checkOptions$8(icon, options) {
|
|
10645
11034
|
if (!(typeof icon === "string" && icon !== "") && (typeof icon !== "object" || icon === null || typeof icon.name !== "string")) throw new TypeError(`travel needs an icon or an icon's name, got ${icon === null ? "null" : typeof icon}.`);
|
|
10646
11035
|
const { along, gait, size, orient, ride } = options;
|
|
10647
11036
|
if (along !== void 0 && typeof along !== "string") throw new RangeError(`travel: along must be a series name, got ${String(along)}.`);
|
|
@@ -10651,12 +11040,12 @@ function checkOptions$7(icon, options) {
|
|
|
10651
11040
|
if (ride !== void 0 && !RIDES.includes(ride)) throw new RangeError(`travel: ride must be center or on, got ${String(ride)}.`);
|
|
10652
11041
|
}
|
|
10653
11042
|
// src/effects/flash.ts
|
|
10654
|
-
const DURATION$
|
|
11043
|
+
const DURATION$7 = 900;
|
|
10655
11044
|
const PEAK = .25;
|
|
10656
11045
|
const WIDTH$2 = 8;
|
|
10657
11046
|
const OPACITY$2 = .35;
|
|
10658
11047
|
function flash(options = {}) {
|
|
10659
|
-
checkOptions$
|
|
11048
|
+
checkOptions$7(options);
|
|
10660
11049
|
const width = options.width ?? WIDTH$2;
|
|
10661
11050
|
const opacity = options.opacity ?? OPACITY$2;
|
|
10662
11051
|
const { color } = options;
|
|
@@ -10673,7 +11062,7 @@ function flash(options = {}) {
|
|
|
10673
11062
|
async run(_mark, ctx) {
|
|
10674
11063
|
if (ctx.signal.aborted) return;
|
|
10675
11064
|
await ctx.tween({
|
|
10676
|
-
duration: DURATION$
|
|
11065
|
+
duration: DURATION$7,
|
|
10677
11066
|
timing: "effect",
|
|
10678
11067
|
ease: linear,
|
|
10679
11068
|
update: (p) => show(ctx, p)
|
|
@@ -10700,14 +11089,14 @@ function easeOut(x) {
|
|
|
10700
11089
|
const s = (lo + hi) / 2;
|
|
10701
11090
|
return 3 * s * s - 2 * s * s * s;
|
|
10702
11091
|
}
|
|
10703
|
-
function checkOptions$
|
|
11092
|
+
function checkOptions$7(options) {
|
|
10704
11093
|
const { width, opacity, color } = options;
|
|
10705
11094
|
if (width !== void 0 && !(typeof width === "number" && width > 0 && Number.isFinite(width))) throw new RangeError(`flash: width must be more than 0 px, got ${String(width)}.`);
|
|
10706
11095
|
if (opacity !== void 0 && !(typeof opacity === "number" && opacity > 0 && opacity <= 1)) throw new RangeError(`flash: opacity must be more than 0 and at most 1, got ${String(opacity)}.`);
|
|
10707
11096
|
if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`flash: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
10708
11097
|
}
|
|
10709
11098
|
// src/effects/wiggle.ts
|
|
10710
|
-
const DURATION$
|
|
11099
|
+
const DURATION$6 = 450;
|
|
10711
11100
|
const SWINGS = [
|
|
10712
11101
|
1,
|
|
10713
11102
|
-.5,
|
|
@@ -10718,7 +11107,7 @@ const MIN_REACH = .5;
|
|
|
10718
11107
|
const SAMPLES = 64;
|
|
10719
11108
|
const MAX_ANGLE = Math.PI / 12;
|
|
10720
11109
|
function wiggle(options = {}) {
|
|
10721
|
-
checkOptions$
|
|
11110
|
+
checkOptions$6(options);
|
|
10722
11111
|
const swing = options.swing ?? SWING;
|
|
10723
11112
|
return {
|
|
10724
11113
|
kind: "geometry",
|
|
@@ -10737,7 +11126,7 @@ function wiggle(options = {}) {
|
|
|
10737
11126
|
show();
|
|
10738
11127
|
});
|
|
10739
11128
|
await ctx.tween({
|
|
10740
|
-
duration: DURATION$
|
|
11129
|
+
duration: DURATION$6,
|
|
10741
11130
|
timing: "effect",
|
|
10742
11131
|
ease: linear,
|
|
10743
11132
|
update: (p) => {
|
|
@@ -10763,19 +11152,19 @@ function rock(t) {
|
|
|
10763
11152
|
const index = Math.floor(position);
|
|
10764
11153
|
return SWINGS[index] * Math.sin(Math.PI * (position - index));
|
|
10765
11154
|
}
|
|
10766
|
-
function checkOptions$
|
|
11155
|
+
function checkOptions$6(options) {
|
|
10767
11156
|
const { swing } = options;
|
|
10768
11157
|
if (swing !== void 0 && !(typeof swing === "number" && swing > 0 && swing <= SWING)) throw new RangeError(`wiggle: swing must be more than 0 and at most ${SWING} px, got ${String(swing)}.`);
|
|
10769
11158
|
}
|
|
10770
11159
|
// src/effects/pulse.ts
|
|
10771
|
-
const DURATION$
|
|
11160
|
+
const DURATION$5 = 600;
|
|
10772
11161
|
const TIMES = 2;
|
|
10773
11162
|
const MAX_TIMES = 6;
|
|
10774
11163
|
const WIDTH$1 = 12;
|
|
10775
11164
|
const OPACITY$1 = .4;
|
|
10776
11165
|
const LIMIT = 5e3;
|
|
10777
11166
|
function pulse(options = {}) {
|
|
10778
|
-
checkOptions$
|
|
11167
|
+
checkOptions$5(options);
|
|
10779
11168
|
const times = options.times ?? TIMES;
|
|
10780
11169
|
const width = options.width ?? WIDTH$1;
|
|
10781
11170
|
const { color } = options;
|
|
@@ -10793,11 +11182,11 @@ function pulse(options = {}) {
|
|
|
10793
11182
|
let total = 0;
|
|
10794
11183
|
for (let i = 0; i < times; i++) {
|
|
10795
11184
|
if (ctx.signal.aborted) return;
|
|
10796
|
-
const length = ctx.motion.duration(DURATION$
|
|
11185
|
+
const length = ctx.motion.duration(DURATION$5, "effect");
|
|
10797
11186
|
if (total + length >= LIMIT) return;
|
|
10798
11187
|
total += length;
|
|
10799
11188
|
await ctx.tween({
|
|
10800
|
-
duration: DURATION$
|
|
11189
|
+
duration: DURATION$5,
|
|
10801
11190
|
timing: "effect",
|
|
10802
11191
|
ease: linear,
|
|
10803
11192
|
update: (t) => show(ctx, t)
|
|
@@ -10808,20 +11197,20 @@ function pulse(options = {}) {
|
|
|
10808
11197
|
clear() {}
|
|
10809
11198
|
};
|
|
10810
11199
|
}
|
|
10811
|
-
function checkOptions$
|
|
11200
|
+
function checkOptions$5(options) {
|
|
10812
11201
|
const { times, width, color } = options;
|
|
10813
11202
|
if (times !== void 0 && !(Number.isInteger(times) && times >= 1 && times <= MAX_TIMES)) throw new RangeError(`pulse: times must be a whole number from 1 to ${MAX_TIMES}, got ${String(times)}.`);
|
|
10814
11203
|
if (width !== void 0 && !(typeof width === "number" && width > 0 && Number.isFinite(width))) throw new RangeError(`pulse: width must be more than 0 px, got ${String(width)}.`);
|
|
10815
11204
|
if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`pulse: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
10816
11205
|
}
|
|
10817
11206
|
// src/effects/trace.ts
|
|
10818
|
-
const DURATION$
|
|
11207
|
+
const DURATION$4 = 500;
|
|
10819
11208
|
const WIDTH = 3;
|
|
10820
11209
|
const OPACITY = .5;
|
|
10821
|
-
const MIN_WALK$
|
|
11210
|
+
const MIN_WALK$2 = .5;
|
|
10822
11211
|
function trace(options = {}) {
|
|
10823
|
-
checkOptions$
|
|
10824
|
-
const duration = options.duration ?? DURATION$
|
|
11212
|
+
checkOptions$4(options);
|
|
11213
|
+
const duration = options.duration ?? DURATION$4;
|
|
10825
11214
|
const paint = {
|
|
10826
11215
|
stroke: options.color ?? "mark",
|
|
10827
11216
|
width: options.width ?? WIDTH,
|
|
@@ -10833,7 +11222,7 @@ function trace(options = {}) {
|
|
|
10833
11222
|
let progress = 0;
|
|
10834
11223
|
let path;
|
|
10835
11224
|
const draw = () => {
|
|
10836
|
-
if (!(current.length >= MIN_WALK$
|
|
11225
|
+
if (!(current.length >= MIN_WALK$2)) {
|
|
10837
11226
|
path?.remove();
|
|
10838
11227
|
path = void 0;
|
|
10839
11228
|
return;
|
|
@@ -10857,7 +11246,7 @@ function trace(options = {}) {
|
|
|
10857
11246
|
async run(mark, ctx) {
|
|
10858
11247
|
if (ctx.signal.aborted) return;
|
|
10859
11248
|
const show = stroke(mark, ctx);
|
|
10860
|
-
if (!(mark.length >= MIN_WALK$
|
|
11249
|
+
if (!(mark.length >= MIN_WALK$2)) {
|
|
10861
11250
|
show(1);
|
|
10862
11251
|
return;
|
|
10863
11252
|
}
|
|
@@ -10874,13 +11263,82 @@ function trace(options = {}) {
|
|
|
10874
11263
|
clear() {}
|
|
10875
11264
|
};
|
|
10876
11265
|
}
|
|
10877
|
-
function checkOptions$
|
|
11266
|
+
function checkOptions$4(options) {
|
|
10878
11267
|
const { color, width, opacity, duration } = options;
|
|
10879
11268
|
if (color !== void 0 && (typeof color !== "string" || color === "")) throw new RangeError(`trace: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
10880
11269
|
if (width !== void 0 && !(typeof width === "number" && width >= 0 && Number.isFinite(width))) throw new RangeError(`trace: width must be 0 px or more, got ${String(width)}.`);
|
|
10881
11270
|
if (opacity !== void 0 && !(typeof opacity === "number" && opacity >= 0 && opacity <= 1)) throw new RangeError(`trace: opacity must be from 0 to 1, got ${String(opacity)}.`);
|
|
10882
11271
|
if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) throw new RangeError(`trace: duration must be 0 ms or more, got ${String(duration)}.`);
|
|
10883
11272
|
}
|
|
11273
|
+
// src/effects/draw-in.ts
|
|
11274
|
+
const DURATION$3 = 750;
|
|
11275
|
+
const FAINT = .3;
|
|
11276
|
+
const MIN_WALK$1 = .5;
|
|
11277
|
+
function drawIn(options = {}) {
|
|
11278
|
+
checkOptions$3(options);
|
|
11279
|
+
const duration = options.duration ?? DURATION$3;
|
|
11280
|
+
const faint = options.faint ?? FAINT;
|
|
11281
|
+
return {
|
|
11282
|
+
kind: "geometry",
|
|
11283
|
+
async run(mark, ctx) {
|
|
11284
|
+
if (ctx.signal.aborted || !(walk(mark) >= MIN_WALK$1)) return;
|
|
11285
|
+
let current = mark;
|
|
11286
|
+
let progress = 0;
|
|
11287
|
+
let done = false;
|
|
11288
|
+
const paths = [];
|
|
11289
|
+
const draw = (repaint) => {
|
|
11290
|
+
const { segments } = current;
|
|
11291
|
+
const parts = segments ?? [current];
|
|
11292
|
+
const reached = progress * walk(current);
|
|
11293
|
+
let from = 0;
|
|
11294
|
+
parts.forEach((piece, i) => {
|
|
11295
|
+
const share = piece.length > 0 ? Math.min(1, Math.max(0, (reached - from) / piece.length)) : 0;
|
|
11296
|
+
from += piece.length;
|
|
11297
|
+
const d = piece.slice(0, easeInOutCubic(share));
|
|
11298
|
+
const paint = {
|
|
11299
|
+
stroke: "mark",
|
|
11300
|
+
width: piece.thickness,
|
|
11301
|
+
linecap: "butt",
|
|
11302
|
+
...segments && { part: piece.key }
|
|
11303
|
+
};
|
|
11304
|
+
const path = paths[i];
|
|
11305
|
+
if (!path) paths[i] = ctx.layer.path(d, paint);
|
|
11306
|
+
else path.update(d, repaint ? {
|
|
11307
|
+
part: void 0,
|
|
11308
|
+
...paint
|
|
11309
|
+
} : void 0);
|
|
11310
|
+
});
|
|
11311
|
+
for (const path of paths.splice(parts.length)) path.remove();
|
|
11312
|
+
};
|
|
11313
|
+
ctx.onChange((next) => {
|
|
11314
|
+
current = next;
|
|
11315
|
+
if (!done) draw(true);
|
|
11316
|
+
});
|
|
11317
|
+
ctx.mark.set({ opacity: faint });
|
|
11318
|
+
draw(false);
|
|
11319
|
+
await ctx.tween({
|
|
11320
|
+
duration,
|
|
11321
|
+
timing: "effect",
|
|
11322
|
+
ease: linear,
|
|
11323
|
+
update: (p) => {
|
|
11324
|
+
progress = p;
|
|
11325
|
+
draw(false);
|
|
11326
|
+
}
|
|
11327
|
+
}).finished;
|
|
11328
|
+
done = true;
|
|
11329
|
+
for (const path of paths) path.remove();
|
|
11330
|
+
ctx.mark.set({ opacity: void 0 });
|
|
11331
|
+
},
|
|
11332
|
+
end() {},
|
|
11333
|
+
clear() {}
|
|
11334
|
+
};
|
|
11335
|
+
}
|
|
11336
|
+
const walk = (mark) => (mark.segments ?? [mark]).reduce((sum, part) => sum + part.length, 0);
|
|
11337
|
+
function checkOptions$3(options) {
|
|
11338
|
+
const { duration, faint } = options;
|
|
11339
|
+
if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) throw new RangeError(`drawIn: duration must be 0 ms or more, got ${String(duration)}.`);
|
|
11340
|
+
if (faint !== void 0 && !(typeof faint === "number" && faint >= 0 && faint <= 1)) throw new RangeError(`drawIn: faint must be from 0 to 1, got ${String(faint)}.`);
|
|
11341
|
+
}
|
|
10884
11342
|
// src/effects/caption.ts
|
|
10885
11343
|
const PAST_END = 10;
|
|
10886
11344
|
const PAST_LABEL = 6;
|
|
@@ -10901,9 +11359,9 @@ function captionPlace(mark, text) {
|
|
|
10901
11359
|
return past(mark.end, heading, PAST_END, own, boxes, text);
|
|
10902
11360
|
}
|
|
10903
11361
|
function past(from, toward, least, own, boxes, text) {
|
|
10904
|
-
if (!text) return placed(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
|
|
10905
|
-
const { x, y, width, height } = text.box(placed(from, toward, 0));
|
|
10906
|
-
return placed(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
|
|
11362
|
+
if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
|
|
11363
|
+
const { x, y, width, height } = text.box(placed$1(from, toward, 0));
|
|
11364
|
+
return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
|
|
10907
11365
|
x: x - from.x,
|
|
10908
11366
|
y: y - from.y,
|
|
10909
11367
|
width,
|
|
@@ -10945,7 +11403,7 @@ const grow = ({ x, y, width, height }, by) => ({
|
|
|
10945
11403
|
width: width + 2 * by,
|
|
10946
11404
|
height: height + 2 * by
|
|
10947
11405
|
});
|
|
10948
|
-
function placed(from, toward, distance) {
|
|
11406
|
+
function placed$1(from, toward, distance) {
|
|
10949
11407
|
const cos = Math.cos(toward);
|
|
10950
11408
|
const sin = Math.sin(toward);
|
|
10951
11409
|
const point = offset(from, toward, distance);
|
|
@@ -11185,7 +11643,7 @@ function reference(compareTo, data) {
|
|
|
11185
11643
|
const gaps = gapsOf(related.samples, place);
|
|
11186
11644
|
return {
|
|
11187
11645
|
place,
|
|
11188
|
-
valueAt: (u) => inside(gaps, u) ? void 0 : interpolate(points, u),
|
|
11646
|
+
valueAt: (u) => inside$1(gaps, u) ? void 0 : interpolate(points, u),
|
|
11189
11647
|
bends: points.map((point) => point.u)
|
|
11190
11648
|
};
|
|
11191
11649
|
}
|
|
@@ -11207,7 +11665,7 @@ function gapsOf(samples, place) {
|
|
|
11207
11665
|
}
|
|
11208
11666
|
return merged;
|
|
11209
11667
|
}
|
|
11210
|
-
function inside(gaps, u) {
|
|
11668
|
+
function inside$1(gaps, u) {
|
|
11211
11669
|
let lo = 0;
|
|
11212
11670
|
let hi = gaps.length;
|
|
11213
11671
|
while (lo < hi) {
|
|
@@ -11314,6 +11772,8 @@ const DURATION = 950;
|
|
|
11314
11772
|
const POINTS = 160;
|
|
11315
11773
|
const ALIGNS = ["unroll", "drop"];
|
|
11316
11774
|
const SAME_T = 1e-9;
|
|
11775
|
+
const SAME_X = .01;
|
|
11776
|
+
const VERTICES = 1e3;
|
|
11317
11777
|
const GRID = 9;
|
|
11318
11778
|
const CHECKS = 8;
|
|
11319
11779
|
function morph(options = {}) {
|
|
@@ -11353,6 +11813,8 @@ function morph(options = {}) {
|
|
|
11353
11813
|
function drawing(from, to, layer, points, align) {
|
|
11354
11814
|
const closed = from.outline.closed;
|
|
11355
11815
|
if (closed !== to.outline.closed) return crossfade(from, to, layer);
|
|
11816
|
+
const across = closed ? void 0 : acrossX(from, to, points);
|
|
11817
|
+
if (across) return piecewise(from, to, layer, across.stops, across.kinds);
|
|
11356
11818
|
const a = from.outline.sample(points);
|
|
11357
11819
|
const b = to.outline.sample(points);
|
|
11358
11820
|
if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
|
|
@@ -11390,20 +11852,25 @@ function gapped(from, to, layer, a, b) {
|
|
|
11390
11852
|
to: to.path(t)
|
|
11391
11853
|
});
|
|
11392
11854
|
stops.sort((x, y) => x.t - y.t);
|
|
11855
|
+
return piecewise(from, to, layer, stops, stops.slice(1).map((stop, k) => {
|
|
11856
|
+
const t = (stops[k].t + stop.t) / 2;
|
|
11857
|
+
return (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
11858
|
+
}));
|
|
11859
|
+
}
|
|
11860
|
+
function piecewise(from, to, layer, stops, kinds) {
|
|
11393
11861
|
const runs = [
|
|
11394
11862
|
[],
|
|
11395
11863
|
[],
|
|
11396
11864
|
[]
|
|
11397
11865
|
];
|
|
11398
|
-
for (let k = 0; k
|
|
11399
|
-
const
|
|
11400
|
-
const kind = (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
11866
|
+
for (let k = 0; k < kinds.length; k++) {
|
|
11867
|
+
const kind = kinds[k];
|
|
11401
11868
|
if (kind === 3) continue;
|
|
11402
11869
|
const last = runs[kind][runs[kind].length - 1];
|
|
11403
11870
|
if (last && last[1] === k) last[1] = k + 1;
|
|
11404
11871
|
else runs[kind].push([k, k + 1]);
|
|
11405
11872
|
}
|
|
11406
|
-
const
|
|
11873
|
+
const order = [
|
|
11407
11874
|
0,
|
|
11408
11875
|
1,
|
|
11409
11876
|
2
|
|
@@ -11416,7 +11883,7 @@ function gapped(from, to, layer, a, b) {
|
|
|
11416
11883
|
p,
|
|
11417
11884
|
1 - p
|
|
11418
11885
|
];
|
|
11419
|
-
const pieces = p <= 0 || p >= 1 ? [[p <= 0 ? from.outline.d : to.outline.d, void 0]] :
|
|
11886
|
+
const pieces = p <= 0 || p >= 1 ? [[p <= 0 ? from.outline.d : to.outline.d, void 0]] : order.map((kind) => [runs[kind].map((run) => along(stops, run, p)).join(""), opacities[kind]]);
|
|
11420
11887
|
pieces.forEach(([d, opacity], i) => {
|
|
11421
11888
|
if (paths[i]) paths[i].update(d, {
|
|
11422
11889
|
width,
|
|
@@ -11437,6 +11904,113 @@ function along(stops, [first, last], p) {
|
|
|
11437
11904
|
for (let k = first; k <= last; k++) d += `${k === first ? "M" : "L"}${at(stops[k].from, stops[k].to, p)}`;
|
|
11438
11905
|
return d;
|
|
11439
11906
|
}
|
|
11907
|
+
function acrossX(from, to, points) {
|
|
11908
|
+
const a = courseOf(from);
|
|
11909
|
+
const b = a && courseOf(to);
|
|
11910
|
+
if (!a || !b || a.way !== b.way) return void 0;
|
|
11911
|
+
const all = [
|
|
11912
|
+
...Array.from({ length: points }, (_, i) => [i / (points - 1), 0]),
|
|
11913
|
+
...corners(a).map((s) => [s, 1]),
|
|
11914
|
+
...corners(b).map((s) => [s, 2])
|
|
11915
|
+
].sort((x, y) => x[0] - y[0]);
|
|
11916
|
+
const same = SAME_X / Math.max(Math.abs(a.span), Math.abs(b.span));
|
|
11917
|
+
const merged = [];
|
|
11918
|
+
for (const [s, whose] of all) {
|
|
11919
|
+
var _stop, _stop2;
|
|
11920
|
+
let stop = merged[merged.length - 1];
|
|
11921
|
+
if (!stop || s - stop[0] > same || whose > 0 && stop[whose] !== void 0) merged.push(stop = [s]);
|
|
11922
|
+
if (whose === 1) (_stop = stop)[1] ?? (_stop[1] = s);
|
|
11923
|
+
if (whose === 2) (_stop2 = stop)[2] ?? (_stop2[2] = s);
|
|
11924
|
+
}
|
|
11925
|
+
const last = merged.length - 1;
|
|
11926
|
+
if (last < 1) return void 0;
|
|
11927
|
+
const shareOn = (whose) => merged.map((stop, k) => k === 0 ? 0 : k === last ? 1 : stop[whose] ?? stop[0]);
|
|
11928
|
+
const [onA, onB] = [shareOn(1), shareOn(2)];
|
|
11929
|
+
const [pointsA, pointsB] = [placed(a, onA), placed(b, onB)];
|
|
11930
|
+
const stops = merged.map(([t], k) => ({
|
|
11931
|
+
t,
|
|
11932
|
+
from: pointsA[k],
|
|
11933
|
+
to: pointsB[k]
|
|
11934
|
+
}));
|
|
11935
|
+
const [inA, inB] = [inside(a.gaps), inside(b.gaps)];
|
|
11936
|
+
return {
|
|
11937
|
+
stops,
|
|
11938
|
+
kinds: stops.slice(1).map((_, k) => (inA((onA[k] + onA[k + 1]) / 2) ? 1 : 0) + (inB((onB[k] + onB[k + 1]) / 2) ? 2 : 0))
|
|
11939
|
+
};
|
|
11940
|
+
}
|
|
11941
|
+
function courseOf(mark) {
|
|
11942
|
+
const subpaths = flattenPath(parsePath(mark.outline.d));
|
|
11943
|
+
const points = [];
|
|
11944
|
+
const before = [];
|
|
11945
|
+
let next = 0;
|
|
11946
|
+
let from = 0;
|
|
11947
|
+
const stretch = (to) => {
|
|
11948
|
+
if (!(to > from)) {
|
|
11949
|
+
points.push(mark.path(from));
|
|
11950
|
+
return true;
|
|
11951
|
+
}
|
|
11952
|
+
const subpath = subpaths[next++];
|
|
11953
|
+
if (!subpath) return false;
|
|
11954
|
+
points.push(subpath.start);
|
|
11955
|
+
for (const segment of subpath.segments) {
|
|
11956
|
+
if (segment.kind !== "line") return false;
|
|
11957
|
+
points.push(segment.to);
|
|
11958
|
+
}
|
|
11959
|
+
return true;
|
|
11960
|
+
};
|
|
11961
|
+
for (const [start, end] of mark.gaps ?? []) {
|
|
11962
|
+
if (!stretch(start)) return void 0;
|
|
11963
|
+
before.push(points.length - 1);
|
|
11964
|
+
from = end;
|
|
11965
|
+
}
|
|
11966
|
+
if (!stretch(1) || next < subpaths.length || points.length < 2) return void 0;
|
|
11967
|
+
const x0 = points[0].x;
|
|
11968
|
+
const span = points[points.length - 1].x - x0;
|
|
11969
|
+
const way = Math.sign(span);
|
|
11970
|
+
for (let i = 1; i < points.length; i++) if (!((points[i].x - points[i - 1].x) * way > 0)) return void 0;
|
|
11971
|
+
const shares = points.map((point) => (point.x - x0) / span);
|
|
11972
|
+
return {
|
|
11973
|
+
points,
|
|
11974
|
+
shares,
|
|
11975
|
+
gaps: before.map((i) => [shares[i], shares[i + 1]]),
|
|
11976
|
+
span,
|
|
11977
|
+
way
|
|
11978
|
+
};
|
|
11979
|
+
}
|
|
11980
|
+
function corners(course) {
|
|
11981
|
+
const { points, shares, gaps } = course;
|
|
11982
|
+
if (points.length <= VERTICES) return shares;
|
|
11983
|
+
const columns = VERTICES / 4;
|
|
11984
|
+
const column = (k) => Math.min(249, Math.floor(shares[k] * columns));
|
|
11985
|
+
const kept = gaps.flat();
|
|
11986
|
+
for (let first = 0, i = 1; i <= points.length; i++) {
|
|
11987
|
+
if (i < points.length && column(i) === column(first)) continue;
|
|
11988
|
+
let [low, high] = [first, first];
|
|
11989
|
+
for (let k = first; k < i; k++) {
|
|
11990
|
+
if (points[k].y < points[low].y) low = k;
|
|
11991
|
+
if (points[k].y > points[high].y) high = k;
|
|
11992
|
+
}
|
|
11993
|
+
kept.push(shares[first], shares[low], shares[high], shares[i - 1]);
|
|
11994
|
+
first = i;
|
|
11995
|
+
}
|
|
11996
|
+
return Array.from(new Set(kept));
|
|
11997
|
+
}
|
|
11998
|
+
function placed(course, shares) {
|
|
11999
|
+
const { points, shares: at } = course;
|
|
12000
|
+
let i = 0;
|
|
12001
|
+
return shares.map((s) => {
|
|
12002
|
+
while (i + 2 < points.length && at[i + 1] <= s) i++;
|
|
12003
|
+
const width = at[i + 1] - at[i];
|
|
12004
|
+
return mixed(points[i], points[i + 1], width > 0 ? Math.min(1, Math.max(0, (s - at[i]) / width)) : 0);
|
|
12005
|
+
});
|
|
12006
|
+
}
|
|
12007
|
+
function inside(gaps) {
|
|
12008
|
+
let k = 0;
|
|
12009
|
+
return (s) => {
|
|
12010
|
+
while (k < gaps.length && gaps[k][1] <= s) k++;
|
|
12011
|
+
return k < gaps.length && gaps[k][0] < s;
|
|
12012
|
+
};
|
|
12013
|
+
}
|
|
11440
12014
|
function holePairs(from, to, a, b, [shiftA, shiftB], count) {
|
|
11441
12015
|
const holesA = holesOf(from.outline, count);
|
|
11442
12016
|
const holesB = holesOf(to.outline, count);
|
|
@@ -12139,7 +12713,7 @@ function configure(options) {
|
|
|
12139
12713
|
}
|
|
12140
12714
|
}
|
|
12141
12715
|
// src/index.ts
|
|
12142
|
-
const VERSION = "0.
|
|
12716
|
+
const VERSION = "0.8.0";
|
|
12143
12717
|
const env = {
|
|
12144
12718
|
presets: presetRegistry,
|
|
12145
12719
|
icons: iconRegistry,
|
|
@@ -12169,6 +12743,6 @@ function fromVegaView(view, options) {
|
|
|
12169
12743
|
function motionSwitch(target, motion$1 = motion, options) {
|
|
12170
12744
|
return motionSwitch$1(target, motion$1, options);
|
|
12171
12745
|
}
|
|
12172
|
-
export { VERSION, animated, barChart, chartSwitch, colorAssignment, configure, createClock, createMotion, defaultClock, defaultScaling, defineDataEffect, defineEffect, defineIcon, delta, describe, donutChart, easeInOutCubic, easeOutCubic, expressive, flash, fromVegaView, gaits, iconFromSvg, icons, interpolateNumber, interpolatePoint, interpolateRecord, label, lineChart, linear, link, manualClock, matrix, mediaReducedMotion, morph, motion, motionSwitch, offset, only, parallel, playButton, playback, pulse, registerIcon, registerIcons, registerPreset, samplesAlong, scaleDuration, sequence, stagger, threshold, trace, travel, tween, wiggle };
|
|
12746
|
+
export { VERSION, animated, barChart, chartSwitch, colorAssignment, configure, createClock, createMotion, defaultClock, defaultScaling, defineDataEffect, defineEffect, defineIcon, delta, describe, donutChart, drawIn, easeInOutCubic, easeOutCubic, expressive, flash, fromVegaView, gaits, iconFromSvg, icons, interpolateNumber, interpolatePoint, interpolateRecord, label, lineChart, linear, link, manualClock, matrix, mediaReducedMotion, morph, motion, motionSwitch, offset, only, parallel, playButton, playback, pulse, registerIcon, registerIcons, registerPreset, samplesAlong, scaleDuration, sequence, stagger, threshold, trace, travel, tween, wiggle };
|
|
12173
12747
|
|
|
12174
12748
|
//# sourceMappingURL=index.js.map
|