expressive-charts 0.6.0 → 0.7.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 +23 -0
- package/README.md +6 -6
- 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 +476 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -17
- package/dist/index.d.ts +64 -17
- package/dist/index.js +476 -110
- package/dist/index.js.map +1 -1
- package/dist/testing.d.cts +2 -2
- package/dist/testing.d.ts +2 -2
- package/package.json +2 -2
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)}.`);
|
|
@@ -1661,7 +1661,7 @@ function mix$3(colors, emphasis) {
|
|
|
1661
1661
|
// src/charts/render/layer.ts
|
|
1662
1662
|
const FOLLOW = "ec-follow";
|
|
1663
1663
|
let clipIds = 0;
|
|
1664
|
-
function svgLayer(group, follow) {
|
|
1664
|
+
function svgLayer(group, follow, parts) {
|
|
1665
1665
|
const into = () => {
|
|
1666
1666
|
if (!follow) return group;
|
|
1667
1667
|
const last = group.lastElementChild;
|
|
@@ -1700,13 +1700,13 @@ function svgLayer(group, follow) {
|
|
|
1700
1700
|
d
|
|
1701
1701
|
}, into());
|
|
1702
1702
|
let current = { ...paint };
|
|
1703
|
-
paintPath(element, current);
|
|
1703
|
+
paintPath(element, current, parts);
|
|
1704
1704
|
return {
|
|
1705
1705
|
update(next, nextPaint) {
|
|
1706
1706
|
element.setAttribute("d", next);
|
|
1707
1707
|
if (nextPaint) {
|
|
1708
1708
|
current = mergeFields(current, nextPaint);
|
|
1709
|
-
paintPath(element, current);
|
|
1709
|
+
paintPath(element, current, parts);
|
|
1710
1710
|
}
|
|
1711
1711
|
},
|
|
1712
1712
|
remove: () => element.remove()
|
|
@@ -1750,14 +1750,17 @@ function drawShape(shape, parent) {
|
|
|
1750
1750
|
stroke: shape.stroke === void 0 ? void 0 : cssColor(shape.stroke)
|
|
1751
1751
|
});
|
|
1752
1752
|
}
|
|
1753
|
-
function paintPath(element, paint) {
|
|
1753
|
+
function paintPath(element, paint, parts) {
|
|
1754
|
+
const { part } = paint;
|
|
1754
1755
|
setAttributes(element, {
|
|
1755
1756
|
"stroke-width": paint.stroke === void 0 ? void 0 : paint.width ?? 1,
|
|
1756
1757
|
opacity: paint.opacity,
|
|
1757
1758
|
"stroke-linecap": paint.linecap,
|
|
1758
|
-
"stroke-linejoin": "round"
|
|
1759
|
+
"stroke-linejoin": "round",
|
|
1760
|
+
"data-part": part
|
|
1759
1761
|
});
|
|
1760
1762
|
setStyles(element, {
|
|
1763
|
+
...markColorStyles(part === void 0 ? void 0 : parts?.(part)),
|
|
1761
1764
|
fill: paint.fill === void 0 ? "none" : cssColor(paint.fill),
|
|
1762
1765
|
stroke: paint.stroke === void 0 ? void 0 : cssColor(paint.stroke)
|
|
1763
1766
|
});
|
|
@@ -1802,7 +1805,7 @@ function svgSurface(options) {
|
|
|
1802
1805
|
live.add(group);
|
|
1803
1806
|
const owner = live;
|
|
1804
1807
|
return {
|
|
1805
|
-
...svgLayer(group, () => transforms.get(key)),
|
|
1808
|
+
...svgLayer(group, () => transforms.get(key), (part) => options.colors(key, part)),
|
|
1806
1809
|
clear() {
|
|
1807
1810
|
group.remove();
|
|
1808
1811
|
owner.delete(group);
|
|
@@ -1833,7 +1836,10 @@ function svgSurface(options) {
|
|
|
1833
1836
|
const live = groups.get(key);
|
|
1834
1837
|
if (!live) return;
|
|
1835
1838
|
const styles = markColorStyles(options.colors(key));
|
|
1836
|
-
for (const group of live)
|
|
1839
|
+
for (const group of live) {
|
|
1840
|
+
setStyles(group, styles);
|
|
1841
|
+
for (const path of group.querySelectorAll("[data-part]")) setStyles(path, markColorStyles(options.colors(key, path.getAttribute("data-part"))));
|
|
1842
|
+
}
|
|
1837
1843
|
},
|
|
1838
1844
|
hide(key, hide) {
|
|
1839
1845
|
if (hide) hidden.add(key);
|
|
@@ -2270,6 +2276,14 @@ function keyboardFocus(svg, options) {
|
|
|
2270
2276
|
last = keys;
|
|
2271
2277
|
return had === void 0 ? void 0 : current;
|
|
2272
2278
|
},
|
|
2279
|
+
moveTabStop(key) {
|
|
2280
|
+
listen();
|
|
2281
|
+
const keys = options.order();
|
|
2282
|
+
if (!keys.includes(key) || options.find(on?.scope.activeElement ?? null) !== void 0) return false;
|
|
2283
|
+
tabStop = key;
|
|
2284
|
+
applyTabIndex(keys);
|
|
2285
|
+
return true;
|
|
2286
|
+
},
|
|
2273
2287
|
destroy() {
|
|
2274
2288
|
current = void 0;
|
|
2275
2289
|
focused = void 0;
|
|
@@ -2527,6 +2541,7 @@ function chartHover(options) {
|
|
|
2527
2541
|
focus(key) {
|
|
2528
2542
|
if (options.live(key)) keyboard.focus(key);
|
|
2529
2543
|
},
|
|
2544
|
+
moveTabStop: (key) => options.live(key) && keyboard.moveTabStop(key),
|
|
2530
2545
|
leave,
|
|
2531
2546
|
destroy() {
|
|
2532
2547
|
destroyed = true;
|
|
@@ -3112,7 +3127,7 @@ function chartTooltip(svg, options) {
|
|
|
3112
3127
|
if (x > left && x < right && y > top && y < bottom) return true;
|
|
3113
3128
|
if (!shape) return false;
|
|
3114
3129
|
const origin = layer.getBoundingClientRect();
|
|
3115
|
-
return inside$
|
|
3130
|
+
return inside$2(shape, x - origin.left, y - origin.top);
|
|
3116
3131
|
};
|
|
3117
3132
|
const letThrough = (on) => {
|
|
3118
3133
|
through = on;
|
|
@@ -3301,7 +3316,7 @@ function chartTooltip(svg, options) {
|
|
|
3301
3316
|
}
|
|
3302
3317
|
};
|
|
3303
3318
|
}
|
|
3304
|
-
function inside$
|
|
3319
|
+
function inside$2({ top, bottom, upper, lower }, x, y) {
|
|
3305
3320
|
if (y <= top || y >= bottom) return false;
|
|
3306
3321
|
const t = (y - top) / (bottom - top);
|
|
3307
3322
|
return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
|
|
@@ -3388,7 +3403,7 @@ function viewBox$1(svg) {
|
|
|
3388
3403
|
const STAGE$2 = 500;
|
|
3389
3404
|
function barChart$1(target, options, env) {
|
|
3390
3405
|
const container = resolveTarget$2(target, "barChart");
|
|
3391
|
-
checkOptions$
|
|
3406
|
+
checkOptions$14(options);
|
|
3392
3407
|
let current = options;
|
|
3393
3408
|
const motion = chartMotion(options.motion, env.motion);
|
|
3394
3409
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -3458,7 +3473,7 @@ function barChart$1(target, options, env) {
|
|
|
3458
3473
|
hover.restyled(key);
|
|
3459
3474
|
}
|
|
3460
3475
|
}),
|
|
3461
|
-
colors: (key) => find(key)?.parts[0]?.colors
|
|
3476
|
+
colors: (key, part) => find(key)?.parts[part === void 0 ? 0 : (find(key)?.shown.geometry.segments ?? []).findIndex((segment) => segment.key === part)]?.colors
|
|
3462
3477
|
});
|
|
3463
3478
|
const runner = createRunner({
|
|
3464
3479
|
effects,
|
|
@@ -3957,7 +3972,7 @@ function barChart$1(target, options, env) {
|
|
|
3957
3972
|
...current,
|
|
3958
3973
|
...next
|
|
3959
3974
|
};
|
|
3960
|
-
checkOptions$
|
|
3975
|
+
checkOptions$14(merged);
|
|
3961
3976
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
3962
3977
|
const nextLayout = layout(merged, swapped);
|
|
3963
3978
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -4013,6 +4028,7 @@ function barChart$1(target, options, env) {
|
|
|
4013
4028
|
drawn: true
|
|
4014
4029
|
};
|
|
4015
4030
|
},
|
|
4031
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
4016
4032
|
destroy() {
|
|
4017
4033
|
if (destroyed) return;
|
|
4018
4034
|
destroyed = true;
|
|
@@ -4045,7 +4061,7 @@ function barChart$1(target, options, env) {
|
|
|
4045
4061
|
}
|
|
4046
4062
|
});
|
|
4047
4063
|
}
|
|
4048
|
-
function checkOptions$
|
|
4064
|
+
function checkOptions$14(options) {
|
|
4049
4065
|
checkChartOptions(options, "barChart");
|
|
4050
4066
|
const { colorBy, room } = options;
|
|
4051
4067
|
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 +4365,7 @@ const TAU = 2 * Math.PI;
|
|
|
4349
4365
|
const VISIBLE$1 = .5;
|
|
4350
4366
|
function donutChart$1(target, options, env) {
|
|
4351
4367
|
const container = resolveTarget$2(target, "donutChart");
|
|
4352
|
-
checkOptions$
|
|
4368
|
+
checkOptions$13(options);
|
|
4353
4369
|
let current = options;
|
|
4354
4370
|
const motion = chartMotion(options.motion, env.motion);
|
|
4355
4371
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -4921,7 +4937,7 @@ function donutChart$1(target, options, env) {
|
|
|
4921
4937
|
...current,
|
|
4922
4938
|
...next
|
|
4923
4939
|
};
|
|
4924
|
-
checkOptions$
|
|
4940
|
+
checkOptions$13(merged);
|
|
4925
4941
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
4926
4942
|
const nextLayout = layout(merged, swapped);
|
|
4927
4943
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -4977,6 +4993,7 @@ function donutChart$1(target, options, env) {
|
|
|
4977
4993
|
color: key,
|
|
4978
4994
|
drawn: true
|
|
4979
4995
|
} : void 0,
|
|
4996
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
4980
4997
|
destroy() {
|
|
4981
4998
|
if (destroyed) return;
|
|
4982
4999
|
destroyed = true;
|
|
@@ -5007,7 +5024,7 @@ function donutChart$1(target, options, env) {
|
|
|
5007
5024
|
}
|
|
5008
5025
|
});
|
|
5009
5026
|
}
|
|
5010
|
-
function checkOptions$
|
|
5027
|
+
function checkOptions$13(options) {
|
|
5011
5028
|
checkChartOptions(options, "donutChart");
|
|
5012
5029
|
const { center, sort } = options;
|
|
5013
5030
|
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.");
|
|
@@ -5550,6 +5567,17 @@ function lineEncoding(options) {
|
|
|
5550
5567
|
curve
|
|
5551
5568
|
};
|
|
5552
5569
|
}
|
|
5570
|
+
function checkRoom(room) {
|
|
5571
|
+
const px = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
5572
|
+
if (typeof room !== "object" || room === null || Array.isArray(room)) {
|
|
5573
|
+
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)}.`);
|
|
5574
|
+
return;
|
|
5575
|
+
}
|
|
5576
|
+
for (const side of ["right", "top"]) {
|
|
5577
|
+
const value = room[side];
|
|
5578
|
+
if (value !== void 0 && !px(value)) throw new RangeError(`lineChart: room.${side} must be a number of px, 0 or more, got ${String(value)}.`);
|
|
5579
|
+
}
|
|
5580
|
+
}
|
|
5553
5581
|
function layoutLines(input) {
|
|
5554
5582
|
const { width, measure } = input;
|
|
5555
5583
|
const height = input.height ?? HEIGHT;
|
|
@@ -5566,9 +5594,11 @@ function layoutLines(input) {
|
|
|
5566
5594
|
const xValues = ticked.map((tick) => tick.value);
|
|
5567
5595
|
const xTexts = ticked.map((tick) => tick.text);
|
|
5568
5596
|
const xWidths = xTexts.map((text) => measure(text, "ec-tick", TICK_SIZE));
|
|
5597
|
+
const room = typeof input.room === "number" ? { right: input.room } : input.room;
|
|
5569
5598
|
const labelWidth = input.label ? widest(distinctLabels(rows, input.label), "ec-value", VALUE_SIZE, measure) : 0;
|
|
5570
5599
|
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) + (
|
|
5600
|
+
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (room?.right ?? 0));
|
|
5601
|
+
const top = TOP + (room?.top ?? 0);
|
|
5572
5602
|
const frame = {
|
|
5573
5603
|
scale: {
|
|
5574
5604
|
lo: domain.lo,
|
|
@@ -5579,8 +5609,8 @@ function layoutLines(input) {
|
|
|
5579
5609
|
xHi,
|
|
5580
5610
|
left,
|
|
5581
5611
|
right: Math.max(left, width - right),
|
|
5582
|
-
top
|
|
5583
|
-
bottom: Math.max(
|
|
5612
|
+
top,
|
|
5613
|
+
bottom: Math.max(top, height - AXIS),
|
|
5584
5614
|
width,
|
|
5585
5615
|
height
|
|
5586
5616
|
}
|
|
@@ -6011,6 +6041,7 @@ const show$1 = (value) => typeof value === "string" ? JSON.stringify(value) : St
|
|
|
6011
6041
|
// src/charts/line.ts
|
|
6012
6042
|
const STAGE = 500;
|
|
6013
6043
|
const RING = 2;
|
|
6044
|
+
const DOT_RING = 2;
|
|
6014
6045
|
const VISIBLE = .5;
|
|
6015
6046
|
function lineChart$1(target, options, env) {
|
|
6016
6047
|
const container = resolveTarget$2(target, "lineChart");
|
|
@@ -6152,8 +6183,8 @@ function lineChart$1(target, options, env) {
|
|
|
6152
6183
|
function layout(opts, using = effects) {
|
|
6153
6184
|
const encoding = lineEncoding(opts);
|
|
6154
6185
|
checkNeeds$1(using, encoding.series.map((s) => s.series), "lineChart");
|
|
6155
|
-
const { room
|
|
6156
|
-
|
|
6186
|
+
const { room } = opts;
|
|
6187
|
+
checkRoom(room);
|
|
6157
6188
|
const next = layoutLines({
|
|
6158
6189
|
data: opts.data,
|
|
6159
6190
|
encoding,
|
|
@@ -7211,6 +7242,11 @@ function lineChart$1(target, options, env) {
|
|
|
7211
7242
|
const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
|
|
7212
7243
|
hover.sync();
|
|
7213
7244
|
runner.enter(liveMarks().map(input));
|
|
7245
|
+
function stopFor(key) {
|
|
7246
|
+
const row = rows.get(key);
|
|
7247
|
+
if (hoverKind === "x") return (row ?? points.get(key)?.row)?.key;
|
|
7248
|
+
return (points.get(key) ?? (row && livePoints(row)[0]))?.key;
|
|
7249
|
+
}
|
|
7214
7250
|
return linkable(hover.link, {
|
|
7215
7251
|
element: svg,
|
|
7216
7252
|
async update(next) {
|
|
@@ -7280,30 +7316,40 @@ function lineChart$1(target, options, env) {
|
|
|
7280
7316
|
on: events.on,
|
|
7281
7317
|
marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
|
|
7282
7318
|
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);
|
|
7319
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
7320
|
+
if (stop !== void 0) hover.focus(stop);
|
|
7292
7321
|
},
|
|
7293
7322
|
leave() {
|
|
7294
7323
|
if (!destroyed) hover.leave();
|
|
7295
7324
|
},
|
|
7296
7325
|
labels: () => lineOrder.flatMap((line) => chartLabel(line.key, "value", line.drawnLabel, line.label)),
|
|
7297
7326
|
paintOf(key) {
|
|
7298
|
-
const
|
|
7299
|
-
|
|
7300
|
-
color:
|
|
7301
|
-
drawn:
|
|
7327
|
+
const line = lines.get(key);
|
|
7328
|
+
if (line) return {
|
|
7329
|
+
color: line.series,
|
|
7330
|
+
drawn: true,
|
|
7331
|
+
...line.end.getAttribute("visibility") === "hidden" ? {} : {
|
|
7332
|
+
end: DOT_RADIUS,
|
|
7333
|
+
ring: DOT_RING
|
|
7334
|
+
}
|
|
7302
7335
|
};
|
|
7336
|
+
const point = points.get(key);
|
|
7337
|
+
return point && (point.group.classList.contains("ec-alone") ? {
|
|
7338
|
+
color: point.series,
|
|
7339
|
+
drawn: true,
|
|
7340
|
+
ring: DOT_RING
|
|
7341
|
+
} : {
|
|
7342
|
+
color: point.series,
|
|
7343
|
+
drawn: false
|
|
7344
|
+
});
|
|
7303
7345
|
},
|
|
7304
7346
|
standsFor(key) {
|
|
7305
7347
|
return rows.has(key) ? [...laidOut.series.map((series) => pointKey(series, key)), key] : [key];
|
|
7306
7348
|
},
|
|
7349
|
+
moveTabStop(key) {
|
|
7350
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
7351
|
+
return stop !== void 0 && hover.moveTabStop(stop);
|
|
7352
|
+
},
|
|
7307
7353
|
destroy() {
|
|
7308
7354
|
if (destroyed) return;
|
|
7309
7355
|
destroyed = true;
|
|
@@ -7746,7 +7792,7 @@ function keepsCircles(m) {
|
|
|
7746
7792
|
const tiny = 1e-4 * Math.max(u, v);
|
|
7747
7793
|
return Math.abs(u - v) <= tiny && Math.abs(a * c + b * d) <= tiny;
|
|
7748
7794
|
}
|
|
7749
|
-
function scaleOf$
|
|
7795
|
+
function scaleOf$2(m) {
|
|
7750
7796
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
7751
7797
|
}
|
|
7752
7798
|
function boxIn(m, rect) {
|
|
@@ -7961,7 +8007,7 @@ function cssMatrix(m) {
|
|
|
7961
8007
|
const NEAR = .5;
|
|
7962
8008
|
const MOST = 32;
|
|
7963
8009
|
function sliceOf$1(commands, m) {
|
|
7964
|
-
const scale = scaleOf$
|
|
8010
|
+
const scale = scaleOf$2(m);
|
|
7965
8011
|
if (!keepsCircles(m) || !(scale > 0) || commands.length > MOST || commands.some((command) => command.op === "C" || command.op === "Q")) return void 0;
|
|
7966
8012
|
const near = NEAR / scale;
|
|
7967
8013
|
const subpaths = flattenPath(commands);
|
|
@@ -8074,7 +8120,7 @@ const onCircle = (run, center, radius, near) => Math.abs(run.radius - radius) <=
|
|
|
8074
8120
|
1
|
|
8075
8121
|
].every((u) => Math.abs(distance$1(pointOn(arc, u), center) - radius) <= near));
|
|
8076
8122
|
function moved(own, m) {
|
|
8077
|
-
const scale = scaleOf$
|
|
8123
|
+
const scale = scaleOf$2(m);
|
|
8078
8124
|
const center = matrix.apply(m, own.center);
|
|
8079
8125
|
const corner = matrix.apply(m, {
|
|
8080
8126
|
x: own.center.x + own.outer * Math.cos(own.start),
|
|
@@ -8295,7 +8341,7 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
|
|
|
8295
8341
|
"graphics-object"
|
|
8296
8342
|
]);
|
|
8297
8343
|
function expressive$1(target, options, env) {
|
|
8298
|
-
checkOptions$
|
|
8344
|
+
checkOptions$12(options);
|
|
8299
8345
|
const motion = chartMotion(options.motion, env.motion);
|
|
8300
8346
|
let effects = resolveEffects(options.on, env.presets);
|
|
8301
8347
|
let given = options.on;
|
|
@@ -8440,7 +8486,7 @@ function expressive$1(target, options, env) {
|
|
|
8440
8486
|
series,
|
|
8441
8487
|
x: round$1(center.x),
|
|
8442
8488
|
y: round$1(center.y),
|
|
8443
|
-
r: round$1(Math.max(0, r) * scaleOf$
|
|
8489
|
+
r: round$1(Math.max(0, r) * scaleOf$2(m))
|
|
8444
8490
|
});
|
|
8445
8491
|
} else {
|
|
8446
8492
|
const commands = shapeOutline(tag, attribute);
|
|
@@ -8478,9 +8524,9 @@ function expressive$1(target, options, env) {
|
|
|
8478
8524
|
}
|
|
8479
8525
|
function widthOf(stroke, m, at) {
|
|
8480
8526
|
const width = stroke?.width ?? 1;
|
|
8481
|
-
if (!stroke?.screen) return width * scaleOf$
|
|
8527
|
+
if (!stroke?.screen) return width * scaleOf$2(m);
|
|
8482
8528
|
const screen = at.screen(at.common);
|
|
8483
|
-
const scale = screen ? scaleOf$
|
|
8529
|
+
const scale = screen ? scaleOf$2(screen) : 0;
|
|
8484
8530
|
return scale > 0 ? width / scale : width;
|
|
8485
8531
|
}
|
|
8486
8532
|
function transformOf(element, at) {
|
|
@@ -8629,7 +8675,7 @@ function expressive$1(target, options, env) {
|
|
|
8629
8675
|
set: (style) => find(key)?.handle.set(style),
|
|
8630
8676
|
reset: () => find(key)?.handle.reset()
|
|
8631
8677
|
}),
|
|
8632
|
-
colors: (key) => find(key)?.mark
|
|
8678
|
+
colors: (key, part) => partOf(find(key)?.mark, part)?.colors
|
|
8633
8679
|
});
|
|
8634
8680
|
const runner = createRunner({
|
|
8635
8681
|
effects,
|
|
@@ -9172,7 +9218,7 @@ function expressive$1(target, options, env) {
|
|
|
9172
9218
|
}
|
|
9173
9219
|
});
|
|
9174
9220
|
}
|
|
9175
|
-
function checkOptions$
|
|
9221
|
+
function checkOptions$12(options) {
|
|
9176
9222
|
if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
|
|
9177
9223
|
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
9224
|
for (const name of [
|
|
@@ -9184,6 +9230,11 @@ function checkOptions$11(options) {
|
|
|
9184
9230
|
]) if (options[name] !== void 0 && typeof options[name] !== "function") throw new TypeError(`expressive: ${name} must be a function.`);
|
|
9185
9231
|
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
9232
|
}
|
|
9233
|
+
function partOf(mark, key) {
|
|
9234
|
+
if (key === void 0) return mark?.parts[0];
|
|
9235
|
+
const segment = mark?.geometry.segments?.find((s) => s.key === key);
|
|
9236
|
+
return segment && mark.parts.find((p) => p.series === segment.series);
|
|
9237
|
+
}
|
|
9187
9238
|
function ownSeries(mark) {
|
|
9188
9239
|
const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
|
|
9189
9240
|
return [...new Set(names.filter((name) => name !== void 0))];
|
|
@@ -9627,7 +9678,7 @@ function pointsOf(first) {
|
|
|
9627
9678
|
function lineOf(key, element, first, m) {
|
|
9628
9679
|
const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
|
|
9629
9680
|
if (!straight(first)) {
|
|
9630
|
-
const scaled = width * scaleOf(m);
|
|
9681
|
+
const scaled = width * scaleOf$1(m);
|
|
9631
9682
|
return describeShape({
|
|
9632
9683
|
key,
|
|
9633
9684
|
series: key,
|
|
@@ -9643,7 +9694,7 @@ function lineOf(key, element, first, m) {
|
|
|
9643
9694
|
series: key,
|
|
9644
9695
|
points: points.map(({ point }) => matrix.apply(m, point)),
|
|
9645
9696
|
...breaks.length > 0 ? { breaks } : {},
|
|
9646
|
-
width: (Number.isFinite(width) ? width : 1) * scaleOf(m)
|
|
9697
|
+
width: (Number.isFinite(width) ? width : 1) * scaleOf$1(m)
|
|
9647
9698
|
});
|
|
9648
9699
|
}
|
|
9649
9700
|
function sliceOf(key, item, m) {
|
|
@@ -9651,7 +9702,7 @@ function sliceOf(key, item, m) {
|
|
|
9651
9702
|
x: number(item.x),
|
|
9652
9703
|
y: number(item.y)
|
|
9653
9704
|
});
|
|
9654
|
-
const s = scaleOf(m);
|
|
9705
|
+
const s = scaleOf$1(m);
|
|
9655
9706
|
const [start, end] = [number(item.startAngle), number(item.endAngle)].sort((a, b) => a - b);
|
|
9656
9707
|
return describeArc({
|
|
9657
9708
|
key,
|
|
@@ -9672,7 +9723,7 @@ function pointOf(key, item, m) {
|
|
|
9672
9723
|
key,
|
|
9673
9724
|
x: center.x,
|
|
9674
9725
|
y: center.y,
|
|
9675
|
-
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf(m)
|
|
9726
|
+
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf$1(m)
|
|
9676
9727
|
});
|
|
9677
9728
|
}
|
|
9678
9729
|
function boxOf(item) {
|
|
@@ -9687,19 +9738,19 @@ function boxOf(item) {
|
|
|
9687
9738
|
height: Math.abs(height)
|
|
9688
9739
|
};
|
|
9689
9740
|
}
|
|
9690
|
-
function scaleOf(m) {
|
|
9741
|
+
function scaleOf$1(m) {
|
|
9691
9742
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
9692
9743
|
}
|
|
9693
9744
|
function number(value) {
|
|
9694
9745
|
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
9695
9746
|
}
|
|
9696
9747
|
// src/charts/switch.ts
|
|
9697
|
-
const DURATION$
|
|
9748
|
+
const DURATION$8 = 950;
|
|
9698
9749
|
const OUT_BY = .4;
|
|
9699
9750
|
const HALF = .5;
|
|
9700
9751
|
function chartSwitch$1(target, options, env) {
|
|
9701
9752
|
const host = resolveTarget$2(target, "chartSwitch");
|
|
9702
|
-
const names = checkOptions$
|
|
9753
|
+
const names = checkOptions$11(options);
|
|
9703
9754
|
const effect = options.transition;
|
|
9704
9755
|
const colors = toColorAssignment(options.colors);
|
|
9705
9756
|
const motion = env.motion;
|
|
@@ -9743,7 +9794,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
9743
9794
|
const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
|
|
9744
9795
|
const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
|
|
9745
9796
|
const orders = /* @__PURE__ */ new WeakMap();
|
|
9746
|
-
const surfaceFor = (paints) => ({ group(key, order) {
|
|
9797
|
+
const surfaceFor = (paints, extras) => ({ group(key, order) {
|
|
9747
9798
|
const group = svgElement("g", {
|
|
9748
9799
|
class: "ec-run",
|
|
9749
9800
|
"data-key": key
|
|
@@ -9752,11 +9803,91 @@ function chartSwitch$1(target, options, env) {
|
|
|
9752
9803
|
orders.set(group, order);
|
|
9753
9804
|
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
|
|
9754
9805
|
runsLayer.insertBefore(group, above ?? null);
|
|
9806
|
+
const layer = svgLayer(group);
|
|
9755
9807
|
return {
|
|
9756
|
-
...
|
|
9808
|
+
...extras[order]?.wrap(layer, group) ?? layer,
|
|
9757
9809
|
clear: () => group.remove()
|
|
9758
9810
|
};
|
|
9759
9811
|
} });
|
|
9812
|
+
function extrasFor(rings, ends, dotColors) {
|
|
9813
|
+
const [ringA, ringB] = rings;
|
|
9814
|
+
const [endA, endB] = ends;
|
|
9815
|
+
if (ringA === 0 && ringB === 0 && !endA && !endB) return void 0;
|
|
9816
|
+
const dots = [];
|
|
9817
|
+
if (endA && endB) {
|
|
9818
|
+
const element = endDot();
|
|
9819
|
+
const draw = (s) => placeDot(element, {
|
|
9820
|
+
at: {
|
|
9821
|
+
x: mix$1(endA.at.x, endB.at.x, s),
|
|
9822
|
+
y: mix$1(endA.at.y, endB.at.y, s)
|
|
9823
|
+
},
|
|
9824
|
+
r: mix$1(endA.r, endB.r, s),
|
|
9825
|
+
ring: mix$1(endA.ring, endB.ring, s)
|
|
9826
|
+
});
|
|
9827
|
+
dots.push({
|
|
9828
|
+
element,
|
|
9829
|
+
draw
|
|
9830
|
+
});
|
|
9831
|
+
} else [[
|
|
9832
|
+
endA,
|
|
9833
|
+
fadeOut,
|
|
9834
|
+
dotColors[0]
|
|
9835
|
+
], [
|
|
9836
|
+
endB,
|
|
9837
|
+
fadeIn,
|
|
9838
|
+
dotColors[1]
|
|
9839
|
+
]].forEach(([end, opacity, color]) => {
|
|
9840
|
+
if (!end) return;
|
|
9841
|
+
const element = endDot();
|
|
9842
|
+
setStyles(element, markColorStyles(seriesColors(colors.slot(color))));
|
|
9843
|
+
placeDot(element, end);
|
|
9844
|
+
dots.push({
|
|
9845
|
+
element,
|
|
9846
|
+
draw: (s) => setAttributes(element, { opacity: opacity(s) })
|
|
9847
|
+
});
|
|
9848
|
+
});
|
|
9849
|
+
const ringed = ringA > 0 || ringB > 0;
|
|
9850
|
+
let width = ringA;
|
|
9851
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
9852
|
+
return {
|
|
9853
|
+
wrap(layer, group) {
|
|
9854
|
+
shapes.clear();
|
|
9855
|
+
const raise = () => {
|
|
9856
|
+
for (const dot of dots) group.appendChild(dot.element);
|
|
9857
|
+
};
|
|
9858
|
+
raise();
|
|
9859
|
+
return {
|
|
9860
|
+
...layer,
|
|
9861
|
+
path(d, paint) {
|
|
9862
|
+
const ring = ringed && paint.fill !== void 0 && paint.stroke === void 0;
|
|
9863
|
+
const handle = layer.path(d, ring ? {
|
|
9864
|
+
...paint,
|
|
9865
|
+
stroke: "surface",
|
|
9866
|
+
width
|
|
9867
|
+
} : paint);
|
|
9868
|
+
raise();
|
|
9869
|
+
if (!ring) return handle;
|
|
9870
|
+
shapes.set(handle, d);
|
|
9871
|
+
return {
|
|
9872
|
+
update(next, nextPaint) {
|
|
9873
|
+
shapes.set(handle, next);
|
|
9874
|
+
handle.update(next, nextPaint);
|
|
9875
|
+
},
|
|
9876
|
+
remove() {
|
|
9877
|
+
shapes.delete(handle);
|
|
9878
|
+
handle.remove();
|
|
9879
|
+
}
|
|
9880
|
+
};
|
|
9881
|
+
}
|
|
9882
|
+
};
|
|
9883
|
+
},
|
|
9884
|
+
draw(s) {
|
|
9885
|
+
width = mix$1(ringA, ringB, s);
|
|
9886
|
+
for (const [handle, d] of shapes) handle.update(d, { width });
|
|
9887
|
+
for (const dot of dots) dot.draw(s);
|
|
9888
|
+
}
|
|
9889
|
+
};
|
|
9890
|
+
}
|
|
9760
9891
|
let current = options.initial;
|
|
9761
9892
|
let active;
|
|
9762
9893
|
let destroyed = false;
|
|
@@ -9782,15 +9913,23 @@ function chartSwitch$1(target, options, env) {
|
|
|
9782
9913
|
}
|
|
9783
9914
|
function readFocus(from) {
|
|
9784
9915
|
const element = focused();
|
|
9785
|
-
|
|
9786
|
-
const keyed = element.closest("[data-key]");
|
|
9916
|
+
const inside = element !== null && from.container.contains(element);
|
|
9917
|
+
const keyed = (inside ? element : from.chart.element.querySelector("[tabindex=\"0\"]"))?.closest("[data-key]");
|
|
9787
9918
|
const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
|
|
9788
|
-
|
|
9919
|
+
if (!inside && key === null) return void 0;
|
|
9920
|
+
return {
|
|
9921
|
+
keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key],
|
|
9922
|
+
focused: inside
|
|
9923
|
+
};
|
|
9789
9924
|
}
|
|
9790
9925
|
function restoreFocus(to, memory) {
|
|
9791
9926
|
if (!memory) return;
|
|
9792
9927
|
const now = focused();
|
|
9793
|
-
|
|
9928
|
+
const away = now !== null && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now);
|
|
9929
|
+
if (!memory.focused || away) {
|
|
9930
|
+
for (const key of memory.keys) if (to.chart.moveTabStop?.(key)) return;
|
|
9931
|
+
return;
|
|
9932
|
+
}
|
|
9794
9933
|
const inside = () => to.chart.element.contains(focused());
|
|
9795
9934
|
for (const key of [...memory.keys, ...to.chart.marks().map((mark) => mark.key)]) {
|
|
9796
9935
|
to.chart.focus(key);
|
|
@@ -9918,12 +10057,15 @@ function chartSwitch$1(target, options, env) {
|
|
|
9918
10057
|
function prepare(a, b) {
|
|
9919
10058
|
const toA = between$1(overlay, a.chart.element, wrapper);
|
|
9920
10059
|
const toB = between$1(overlay, b.chart.element, wrapper);
|
|
10060
|
+
const scaleA = scaleOf(toA);
|
|
10061
|
+
const scaleB = scaleOf(toB);
|
|
9921
10062
|
const from = a.chart.marks().map((mark) => mapMark(mark, toA));
|
|
9922
10063
|
const to = b.chart.marks().map((mark) => mapMark(mark, toB));
|
|
9923
10064
|
const fromByKey = new Map(from.map((mark) => [mark.key, mark]));
|
|
9924
10065
|
const toKeys = new Set(to.map((mark) => mark.key));
|
|
9925
10066
|
const pairs = [];
|
|
9926
10067
|
const paints = [];
|
|
10068
|
+
const extras = [];
|
|
9927
10069
|
for (const mark of to) {
|
|
9928
10070
|
const partner = fromByKey.get(mark.key);
|
|
9929
10071
|
if (!partner) continue;
|
|
@@ -9935,14 +10077,18 @@ function chartSwitch$1(target, options, env) {
|
|
|
9935
10077
|
to: will.drawn ? mark : dot$1(mark)
|
|
9936
10078
|
});
|
|
9937
10079
|
paints.push(will.color);
|
|
10080
|
+
extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was.color, will.color]));
|
|
9938
10081
|
}
|
|
9939
10082
|
const drawings = [];
|
|
9940
|
-
|
|
10083
|
+
if (extras.some((each) => each !== void 0)) drawings.push((s) => {
|
|
10084
|
+
for (const each of extras) each?.draw(s);
|
|
10085
|
+
});
|
|
10086
|
+
const fade = (view, mark, scale, opacity) => {
|
|
9941
10087
|
const paint = paintOf(view, mark);
|
|
9942
|
-
if (paint.drawn) drawings.push(fadeMark(mark, paint
|
|
10088
|
+
if (paint.drawn) drawings.push(fadeMark(mark, paint, scale, opacity));
|
|
9943
10089
|
};
|
|
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);
|
|
10090
|
+
for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, scaleA, fadeOut);
|
|
10091
|
+
for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, scaleB, fadeIn);
|
|
9946
10092
|
const id = (label) => `${label.role}\n${label.key}`;
|
|
9947
10093
|
const labelsA = a.chart.labels();
|
|
9948
10094
|
const labelsB = b.chart.labels();
|
|
@@ -9962,7 +10108,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
9962
10108
|
});
|
|
9963
10109
|
return {
|
|
9964
10110
|
pairs,
|
|
9965
|
-
surface: surfaceFor(paints),
|
|
10111
|
+
surface: surfaceFor(paints, extras),
|
|
9966
10112
|
scene: {
|
|
9967
10113
|
draw: (s) => {
|
|
9968
10114
|
for (const draw of drawings) draw(s);
|
|
@@ -9975,18 +10121,36 @@ function chartSwitch$1(target, options, env) {
|
|
|
9975
10121
|
}
|
|
9976
10122
|
};
|
|
9977
10123
|
}
|
|
9978
|
-
function fadeMark(mark,
|
|
10124
|
+
function fadeMark(mark, paint, scale, opacity) {
|
|
9979
10125
|
const group = svgElement("g", {
|
|
9980
10126
|
class: "ec-switch-fade",
|
|
9981
10127
|
"data-key": mark.key
|
|
9982
10128
|
}, fadesLayer);
|
|
9983
|
-
setStyles(group, markColorStyles(seriesColors(colors.slot(color))));
|
|
9984
|
-
|
|
10129
|
+
setStyles(group, markColorStyles(seriesColors(colors.slot(paint.color))));
|
|
10130
|
+
const ring = ringOf(paint, scale);
|
|
10131
|
+
svgLayer(group).path(mark.outline.d, mark.outline.closed ? {
|
|
10132
|
+
fill: "mark",
|
|
10133
|
+
...ring > 0 ? {
|
|
10134
|
+
stroke: "surface",
|
|
10135
|
+
width: ring
|
|
10136
|
+
} : {}
|
|
10137
|
+
} : {
|
|
9985
10138
|
stroke: "mark",
|
|
9986
10139
|
width: mark.thickness
|
|
9987
10140
|
});
|
|
10141
|
+
const end = endOf(paint, mark, scale);
|
|
10142
|
+
if (end) placeDot(group.appendChild(endDot()), end);
|
|
9988
10143
|
return (s) => setAttributes(group, { opacity: opacity(s) });
|
|
9989
10144
|
}
|
|
10145
|
+
function endDot() {
|
|
10146
|
+
const element = doc.createElementNS(SVG_NS$2, "circle");
|
|
10147
|
+
element.setAttribute("class", "ec-switch-end");
|
|
10148
|
+
setStyles(element, {
|
|
10149
|
+
fill: cssColor("mark"),
|
|
10150
|
+
stroke: cssColor("surface")
|
|
10151
|
+
});
|
|
10152
|
+
return element;
|
|
10153
|
+
}
|
|
9990
10154
|
function copyLabel(label, m) {
|
|
9991
10155
|
const text = label.element.cloneNode(true);
|
|
9992
10156
|
for (const name of [
|
|
@@ -10117,7 +10281,7 @@ function drive(begin, at, env) {
|
|
|
10117
10281
|
const begun = unease(begin);
|
|
10118
10282
|
let running;
|
|
10119
10283
|
running = tween({
|
|
10120
|
-
duration: DURATION$
|
|
10284
|
+
duration: DURATION$8,
|
|
10121
10285
|
timing: "transition",
|
|
10122
10286
|
ease: linear,
|
|
10123
10287
|
update: (k) => {
|
|
@@ -10188,12 +10352,29 @@ function dot$1(mark) {
|
|
|
10188
10352
|
r: 0
|
|
10189
10353
|
});
|
|
10190
10354
|
}
|
|
10355
|
+
const ringOf = (paint, scale) => paint.drawn && paint.end === void 0 ? (paint.ring ?? 0) * scale : 0;
|
|
10356
|
+
function endOf(paint, mark, scale) {
|
|
10357
|
+
return paint.drawn && paint.end !== void 0 ? {
|
|
10358
|
+
at: mark.end,
|
|
10359
|
+
r: paint.end * scale,
|
|
10360
|
+
ring: (paint.ring ?? 0) * scale
|
|
10361
|
+
} : void 0;
|
|
10362
|
+
}
|
|
10363
|
+
function placeDot(element, end) {
|
|
10364
|
+
setAttributes(element, {
|
|
10365
|
+
cx: end.at.x,
|
|
10366
|
+
cy: end.at.y,
|
|
10367
|
+
r: end.r,
|
|
10368
|
+
"stroke-width": end.ring
|
|
10369
|
+
});
|
|
10370
|
+
}
|
|
10191
10371
|
const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
10372
|
+
const scaleOf = (m) => Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
10192
10373
|
function mapMark(mark, m) {
|
|
10193
10374
|
if (isIdentity(m)) return mark;
|
|
10194
10375
|
const point = (p) => matrix.apply(m, p);
|
|
10195
10376
|
const path = (d) => formatPath(transformPath(parsePath(d), m));
|
|
10196
|
-
const scale =
|
|
10377
|
+
const scale = scaleOf(m);
|
|
10197
10378
|
const { outline } = mark;
|
|
10198
10379
|
return {
|
|
10199
10380
|
key: mark.key,
|
|
@@ -10243,7 +10424,7 @@ function isView(value, container) {
|
|
|
10243
10424
|
"destroy"
|
|
10244
10425
|
].every((method) => typeof view[method] === "function") && element?.nodeType === 1 && container.contains(element);
|
|
10245
10426
|
}
|
|
10246
|
-
function checkOptions$
|
|
10427
|
+
function checkOptions$11(options) {
|
|
10247
10428
|
if (typeof options !== "object" || options === null) throw new TypeError("chartSwitch needs options.");
|
|
10248
10429
|
const { views, initial, transition, announce } = options;
|
|
10249
10430
|
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 +10457,7 @@ let switches = 0;
|
|
|
10276
10457
|
function motionSwitch$1(target, motion, options = {}) {
|
|
10277
10458
|
const parent = resolveTarget$1(target);
|
|
10278
10459
|
checkMotion(motion);
|
|
10279
|
-
checkOptions$
|
|
10460
|
+
checkOptions$10(options);
|
|
10280
10461
|
const labels = {
|
|
10281
10462
|
...LABELS$1,
|
|
10282
10463
|
...options.labels
|
|
@@ -10360,7 +10541,7 @@ function resolveTarget$1(target) {
|
|
|
10360
10541
|
function checkMotion(motion) {
|
|
10361
10542
|
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
10543
|
}
|
|
10363
|
-
function checkOptions$
|
|
10544
|
+
function checkOptions$10(options) {
|
|
10364
10545
|
const { label, labels, hints, persist } = options;
|
|
10365
10546
|
if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
|
|
10366
10547
|
for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
|
|
@@ -10377,7 +10558,7 @@ const LABELS = {
|
|
|
10377
10558
|
function playButton(target, playback, options = {}) {
|
|
10378
10559
|
const parent = resolveTarget(target);
|
|
10379
10560
|
checkPlayback(playback);
|
|
10380
|
-
checkOptions$
|
|
10561
|
+
checkOptions$9(options);
|
|
10381
10562
|
const labels = {
|
|
10382
10563
|
...LABELS,
|
|
10383
10564
|
...options.labels
|
|
@@ -10418,7 +10599,7 @@ function resolveTarget(target) {
|
|
|
10418
10599
|
function checkPlayback(playback) {
|
|
10419
10600
|
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
10601
|
}
|
|
10421
|
-
function checkOptions$
|
|
10602
|
+
function checkOptions$9(options) {
|
|
10422
10603
|
const { labels } = options;
|
|
10423
10604
|
if (labels === void 0) return;
|
|
10424
10605
|
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 +10651,7 @@ const gaits = {
|
|
|
10470
10651
|
const SPEED = 360;
|
|
10471
10652
|
const SHORTEST = 260;
|
|
10472
10653
|
const LONGEST = 4e3;
|
|
10473
|
-
const MIN_WALK$
|
|
10654
|
+
const MIN_WALK$3 = .5;
|
|
10474
10655
|
const FIT = .85;
|
|
10475
10656
|
const MIN_SMOOTHING = 2;
|
|
10476
10657
|
const IDENTITY = [
|
|
@@ -10488,12 +10669,12 @@ const ORIENTS = [
|
|
|
10488
10669
|
];
|
|
10489
10670
|
const RIDES = ["center", "on"];
|
|
10490
10671
|
function travel(icon, options = {}) {
|
|
10491
|
-
checkOptions$
|
|
10672
|
+
checkOptions$8(icon, options);
|
|
10492
10673
|
function plan(mark, ctx) {
|
|
10493
10674
|
const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
|
|
10494
10675
|
if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
|
|
10495
10676
|
const walk = pick(mark, options.along);
|
|
10496
|
-
if (!walk || !(drawn(walk) >= MIN_WALK$
|
|
10677
|
+
if (!walk || !(drawn(walk) >= MIN_WALK$3)) return void 0;
|
|
10497
10678
|
const scale = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
|
|
10498
10679
|
if (!(scale > 0)) return void 0;
|
|
10499
10680
|
return trip(walk, resolved, scale, options);
|
|
@@ -10641,7 +10822,7 @@ function heading(walk, distance, window, leg) {
|
|
|
10641
10822
|
}
|
|
10642
10823
|
return walk.angle(distance / length);
|
|
10643
10824
|
}
|
|
10644
|
-
function checkOptions$
|
|
10825
|
+
function checkOptions$8(icon, options) {
|
|
10645
10826
|
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
10827
|
const { along, gait, size, orient, ride } = options;
|
|
10647
10828
|
if (along !== void 0 && typeof along !== "string") throw new RangeError(`travel: along must be a series name, got ${String(along)}.`);
|
|
@@ -10651,12 +10832,12 @@ function checkOptions$7(icon, options) {
|
|
|
10651
10832
|
if (ride !== void 0 && !RIDES.includes(ride)) throw new RangeError(`travel: ride must be center or on, got ${String(ride)}.`);
|
|
10652
10833
|
}
|
|
10653
10834
|
// src/effects/flash.ts
|
|
10654
|
-
const DURATION$
|
|
10835
|
+
const DURATION$7 = 900;
|
|
10655
10836
|
const PEAK = .25;
|
|
10656
10837
|
const WIDTH$2 = 8;
|
|
10657
10838
|
const OPACITY$2 = .35;
|
|
10658
10839
|
function flash(options = {}) {
|
|
10659
|
-
checkOptions$
|
|
10840
|
+
checkOptions$7(options);
|
|
10660
10841
|
const width = options.width ?? WIDTH$2;
|
|
10661
10842
|
const opacity = options.opacity ?? OPACITY$2;
|
|
10662
10843
|
const { color } = options;
|
|
@@ -10673,7 +10854,7 @@ function flash(options = {}) {
|
|
|
10673
10854
|
async run(_mark, ctx) {
|
|
10674
10855
|
if (ctx.signal.aborted) return;
|
|
10675
10856
|
await ctx.tween({
|
|
10676
|
-
duration: DURATION$
|
|
10857
|
+
duration: DURATION$7,
|
|
10677
10858
|
timing: "effect",
|
|
10678
10859
|
ease: linear,
|
|
10679
10860
|
update: (p) => show(ctx, p)
|
|
@@ -10700,14 +10881,14 @@ function easeOut(x) {
|
|
|
10700
10881
|
const s = (lo + hi) / 2;
|
|
10701
10882
|
return 3 * s * s - 2 * s * s * s;
|
|
10702
10883
|
}
|
|
10703
|
-
function checkOptions$
|
|
10884
|
+
function checkOptions$7(options) {
|
|
10704
10885
|
const { width, opacity, color } = options;
|
|
10705
10886
|
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
10887
|
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
10888
|
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
10889
|
}
|
|
10709
10890
|
// src/effects/wiggle.ts
|
|
10710
|
-
const DURATION$
|
|
10891
|
+
const DURATION$6 = 450;
|
|
10711
10892
|
const SWINGS = [
|
|
10712
10893
|
1,
|
|
10713
10894
|
-.5,
|
|
@@ -10718,7 +10899,7 @@ const MIN_REACH = .5;
|
|
|
10718
10899
|
const SAMPLES = 64;
|
|
10719
10900
|
const MAX_ANGLE = Math.PI / 12;
|
|
10720
10901
|
function wiggle(options = {}) {
|
|
10721
|
-
checkOptions$
|
|
10902
|
+
checkOptions$6(options);
|
|
10722
10903
|
const swing = options.swing ?? SWING;
|
|
10723
10904
|
return {
|
|
10724
10905
|
kind: "geometry",
|
|
@@ -10737,7 +10918,7 @@ function wiggle(options = {}) {
|
|
|
10737
10918
|
show();
|
|
10738
10919
|
});
|
|
10739
10920
|
await ctx.tween({
|
|
10740
|
-
duration: DURATION$
|
|
10921
|
+
duration: DURATION$6,
|
|
10741
10922
|
timing: "effect",
|
|
10742
10923
|
ease: linear,
|
|
10743
10924
|
update: (p) => {
|
|
@@ -10763,19 +10944,19 @@ function rock(t) {
|
|
|
10763
10944
|
const index = Math.floor(position);
|
|
10764
10945
|
return SWINGS[index] * Math.sin(Math.PI * (position - index));
|
|
10765
10946
|
}
|
|
10766
|
-
function checkOptions$
|
|
10947
|
+
function checkOptions$6(options) {
|
|
10767
10948
|
const { swing } = options;
|
|
10768
10949
|
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
10950
|
}
|
|
10770
10951
|
// src/effects/pulse.ts
|
|
10771
|
-
const DURATION$
|
|
10952
|
+
const DURATION$5 = 600;
|
|
10772
10953
|
const TIMES = 2;
|
|
10773
10954
|
const MAX_TIMES = 6;
|
|
10774
10955
|
const WIDTH$1 = 12;
|
|
10775
10956
|
const OPACITY$1 = .4;
|
|
10776
10957
|
const LIMIT = 5e3;
|
|
10777
10958
|
function pulse(options = {}) {
|
|
10778
|
-
checkOptions$
|
|
10959
|
+
checkOptions$5(options);
|
|
10779
10960
|
const times = options.times ?? TIMES;
|
|
10780
10961
|
const width = options.width ?? WIDTH$1;
|
|
10781
10962
|
const { color } = options;
|
|
@@ -10793,11 +10974,11 @@ function pulse(options = {}) {
|
|
|
10793
10974
|
let total = 0;
|
|
10794
10975
|
for (let i = 0; i < times; i++) {
|
|
10795
10976
|
if (ctx.signal.aborted) return;
|
|
10796
|
-
const length = ctx.motion.duration(DURATION$
|
|
10977
|
+
const length = ctx.motion.duration(DURATION$5, "effect");
|
|
10797
10978
|
if (total + length >= LIMIT) return;
|
|
10798
10979
|
total += length;
|
|
10799
10980
|
await ctx.tween({
|
|
10800
|
-
duration: DURATION$
|
|
10981
|
+
duration: DURATION$5,
|
|
10801
10982
|
timing: "effect",
|
|
10802
10983
|
ease: linear,
|
|
10803
10984
|
update: (t) => show(ctx, t)
|
|
@@ -10808,20 +10989,20 @@ function pulse(options = {}) {
|
|
|
10808
10989
|
clear() {}
|
|
10809
10990
|
};
|
|
10810
10991
|
}
|
|
10811
|
-
function checkOptions$
|
|
10992
|
+
function checkOptions$5(options) {
|
|
10812
10993
|
const { times, width, color } = options;
|
|
10813
10994
|
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
10995
|
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
10996
|
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
10997
|
}
|
|
10817
10998
|
// src/effects/trace.ts
|
|
10818
|
-
const DURATION$
|
|
10999
|
+
const DURATION$4 = 500;
|
|
10819
11000
|
const WIDTH = 3;
|
|
10820
11001
|
const OPACITY = .5;
|
|
10821
|
-
const MIN_WALK$
|
|
11002
|
+
const MIN_WALK$2 = .5;
|
|
10822
11003
|
function trace(options = {}) {
|
|
10823
|
-
checkOptions$
|
|
10824
|
-
const duration = options.duration ?? DURATION$
|
|
11004
|
+
checkOptions$4(options);
|
|
11005
|
+
const duration = options.duration ?? DURATION$4;
|
|
10825
11006
|
const paint = {
|
|
10826
11007
|
stroke: options.color ?? "mark",
|
|
10827
11008
|
width: options.width ?? WIDTH,
|
|
@@ -10833,7 +11014,7 @@ function trace(options = {}) {
|
|
|
10833
11014
|
let progress = 0;
|
|
10834
11015
|
let path;
|
|
10835
11016
|
const draw = () => {
|
|
10836
|
-
if (!(current.length >= MIN_WALK$
|
|
11017
|
+
if (!(current.length >= MIN_WALK$2)) {
|
|
10837
11018
|
path?.remove();
|
|
10838
11019
|
path = void 0;
|
|
10839
11020
|
return;
|
|
@@ -10857,7 +11038,7 @@ function trace(options = {}) {
|
|
|
10857
11038
|
async run(mark, ctx) {
|
|
10858
11039
|
if (ctx.signal.aborted) return;
|
|
10859
11040
|
const show = stroke(mark, ctx);
|
|
10860
|
-
if (!(mark.length >= MIN_WALK$
|
|
11041
|
+
if (!(mark.length >= MIN_WALK$2)) {
|
|
10861
11042
|
show(1);
|
|
10862
11043
|
return;
|
|
10863
11044
|
}
|
|
@@ -10874,13 +11055,82 @@ function trace(options = {}) {
|
|
|
10874
11055
|
clear() {}
|
|
10875
11056
|
};
|
|
10876
11057
|
}
|
|
10877
|
-
function checkOptions$
|
|
11058
|
+
function checkOptions$4(options) {
|
|
10878
11059
|
const { color, width, opacity, duration } = options;
|
|
10879
11060
|
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
11061
|
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
11062
|
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
11063
|
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
11064
|
}
|
|
11065
|
+
// src/effects/draw-in.ts
|
|
11066
|
+
const DURATION$3 = 750;
|
|
11067
|
+
const FAINT = .3;
|
|
11068
|
+
const MIN_WALK$1 = .5;
|
|
11069
|
+
function drawIn(options = {}) {
|
|
11070
|
+
checkOptions$3(options);
|
|
11071
|
+
const duration = options.duration ?? DURATION$3;
|
|
11072
|
+
const faint = options.faint ?? FAINT;
|
|
11073
|
+
return {
|
|
11074
|
+
kind: "geometry",
|
|
11075
|
+
async run(mark, ctx) {
|
|
11076
|
+
if (ctx.signal.aborted || !(walk(mark) >= MIN_WALK$1)) return;
|
|
11077
|
+
let current = mark;
|
|
11078
|
+
let progress = 0;
|
|
11079
|
+
let done = false;
|
|
11080
|
+
const paths = [];
|
|
11081
|
+
const draw = (repaint) => {
|
|
11082
|
+
const { segments } = current;
|
|
11083
|
+
const parts = segments ?? [current];
|
|
11084
|
+
const reached = progress * walk(current);
|
|
11085
|
+
let from = 0;
|
|
11086
|
+
parts.forEach((piece, i) => {
|
|
11087
|
+
const share = piece.length > 0 ? Math.min(1, Math.max(0, (reached - from) / piece.length)) : 0;
|
|
11088
|
+
from += piece.length;
|
|
11089
|
+
const d = piece.slice(0, easeInOutCubic(share));
|
|
11090
|
+
const paint = {
|
|
11091
|
+
stroke: "mark",
|
|
11092
|
+
width: piece.thickness,
|
|
11093
|
+
linecap: "butt",
|
|
11094
|
+
...segments && { part: piece.key }
|
|
11095
|
+
};
|
|
11096
|
+
const path = paths[i];
|
|
11097
|
+
if (!path) paths[i] = ctx.layer.path(d, paint);
|
|
11098
|
+
else path.update(d, repaint ? {
|
|
11099
|
+
part: void 0,
|
|
11100
|
+
...paint
|
|
11101
|
+
} : void 0);
|
|
11102
|
+
});
|
|
11103
|
+
for (const path of paths.splice(parts.length)) path.remove();
|
|
11104
|
+
};
|
|
11105
|
+
ctx.onChange((next) => {
|
|
11106
|
+
current = next;
|
|
11107
|
+
if (!done) draw(true);
|
|
11108
|
+
});
|
|
11109
|
+
ctx.mark.set({ opacity: faint });
|
|
11110
|
+
draw(false);
|
|
11111
|
+
await ctx.tween({
|
|
11112
|
+
duration,
|
|
11113
|
+
timing: "effect",
|
|
11114
|
+
ease: linear,
|
|
11115
|
+
update: (p) => {
|
|
11116
|
+
progress = p;
|
|
11117
|
+
draw(false);
|
|
11118
|
+
}
|
|
11119
|
+
}).finished;
|
|
11120
|
+
done = true;
|
|
11121
|
+
for (const path of paths) path.remove();
|
|
11122
|
+
ctx.mark.set({ opacity: void 0 });
|
|
11123
|
+
},
|
|
11124
|
+
end() {},
|
|
11125
|
+
clear() {}
|
|
11126
|
+
};
|
|
11127
|
+
}
|
|
11128
|
+
const walk = (mark) => (mark.segments ?? [mark]).reduce((sum, part) => sum + part.length, 0);
|
|
11129
|
+
function checkOptions$3(options) {
|
|
11130
|
+
const { duration, faint } = options;
|
|
11131
|
+
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)}.`);
|
|
11132
|
+
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)}.`);
|
|
11133
|
+
}
|
|
10884
11134
|
// src/effects/caption.ts
|
|
10885
11135
|
const PAST_END = 10;
|
|
10886
11136
|
const PAST_LABEL = 6;
|
|
@@ -10901,9 +11151,9 @@ function captionPlace(mark, text) {
|
|
|
10901
11151
|
return past(mark.end, heading, PAST_END, own, boxes, text);
|
|
10902
11152
|
}
|
|
10903
11153
|
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, {
|
|
11154
|
+
if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
|
|
11155
|
+
const { x, y, width, height } = text.box(placed$1(from, toward, 0));
|
|
11156
|
+
return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
|
|
10907
11157
|
x: x - from.x,
|
|
10908
11158
|
y: y - from.y,
|
|
10909
11159
|
width,
|
|
@@ -10945,7 +11195,7 @@ const grow = ({ x, y, width, height }, by) => ({
|
|
|
10945
11195
|
width: width + 2 * by,
|
|
10946
11196
|
height: height + 2 * by
|
|
10947
11197
|
});
|
|
10948
|
-
function placed(from, toward, distance) {
|
|
11198
|
+
function placed$1(from, toward, distance) {
|
|
10949
11199
|
const cos = Math.cos(toward);
|
|
10950
11200
|
const sin = Math.sin(toward);
|
|
10951
11201
|
const point = offset(from, toward, distance);
|
|
@@ -11185,7 +11435,7 @@ function reference(compareTo, data) {
|
|
|
11185
11435
|
const gaps = gapsOf(related.samples, place);
|
|
11186
11436
|
return {
|
|
11187
11437
|
place,
|
|
11188
|
-
valueAt: (u) => inside(gaps, u) ? void 0 : interpolate(points, u),
|
|
11438
|
+
valueAt: (u) => inside$1(gaps, u) ? void 0 : interpolate(points, u),
|
|
11189
11439
|
bends: points.map((point) => point.u)
|
|
11190
11440
|
};
|
|
11191
11441
|
}
|
|
@@ -11207,7 +11457,7 @@ function gapsOf(samples, place) {
|
|
|
11207
11457
|
}
|
|
11208
11458
|
return merged;
|
|
11209
11459
|
}
|
|
11210
|
-
function inside(gaps, u) {
|
|
11460
|
+
function inside$1(gaps, u) {
|
|
11211
11461
|
let lo = 0;
|
|
11212
11462
|
let hi = gaps.length;
|
|
11213
11463
|
while (lo < hi) {
|
|
@@ -11314,6 +11564,8 @@ const DURATION = 950;
|
|
|
11314
11564
|
const POINTS = 160;
|
|
11315
11565
|
const ALIGNS = ["unroll", "drop"];
|
|
11316
11566
|
const SAME_T = 1e-9;
|
|
11567
|
+
const SAME_X = .01;
|
|
11568
|
+
const VERTICES = 1e3;
|
|
11317
11569
|
const GRID = 9;
|
|
11318
11570
|
const CHECKS = 8;
|
|
11319
11571
|
function morph(options = {}) {
|
|
@@ -11353,6 +11605,8 @@ function morph(options = {}) {
|
|
|
11353
11605
|
function drawing(from, to, layer, points, align) {
|
|
11354
11606
|
const closed = from.outline.closed;
|
|
11355
11607
|
if (closed !== to.outline.closed) return crossfade(from, to, layer);
|
|
11608
|
+
const across = closed ? void 0 : acrossX(from, to, points);
|
|
11609
|
+
if (across) return piecewise(from, to, layer, across.stops, across.kinds);
|
|
11356
11610
|
const a = from.outline.sample(points);
|
|
11357
11611
|
const b = to.outline.sample(points);
|
|
11358
11612
|
if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
|
|
@@ -11390,20 +11644,25 @@ function gapped(from, to, layer, a, b) {
|
|
|
11390
11644
|
to: to.path(t)
|
|
11391
11645
|
});
|
|
11392
11646
|
stops.sort((x, y) => x.t - y.t);
|
|
11647
|
+
return piecewise(from, to, layer, stops, stops.slice(1).map((stop, k) => {
|
|
11648
|
+
const t = (stops[k].t + stop.t) / 2;
|
|
11649
|
+
return (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
11650
|
+
}));
|
|
11651
|
+
}
|
|
11652
|
+
function piecewise(from, to, layer, stops, kinds) {
|
|
11393
11653
|
const runs = [
|
|
11394
11654
|
[],
|
|
11395
11655
|
[],
|
|
11396
11656
|
[]
|
|
11397
11657
|
];
|
|
11398
|
-
for (let k = 0; k
|
|
11399
|
-
const
|
|
11400
|
-
const kind = (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
11658
|
+
for (let k = 0; k < kinds.length; k++) {
|
|
11659
|
+
const kind = kinds[k];
|
|
11401
11660
|
if (kind === 3) continue;
|
|
11402
11661
|
const last = runs[kind][runs[kind].length - 1];
|
|
11403
11662
|
if (last && last[1] === k) last[1] = k + 1;
|
|
11404
11663
|
else runs[kind].push([k, k + 1]);
|
|
11405
11664
|
}
|
|
11406
|
-
const
|
|
11665
|
+
const order = [
|
|
11407
11666
|
0,
|
|
11408
11667
|
1,
|
|
11409
11668
|
2
|
|
@@ -11416,7 +11675,7 @@ function gapped(from, to, layer, a, b) {
|
|
|
11416
11675
|
p,
|
|
11417
11676
|
1 - p
|
|
11418
11677
|
];
|
|
11419
|
-
const pieces = p <= 0 || p >= 1 ? [[p <= 0 ? from.outline.d : to.outline.d, void 0]] :
|
|
11678
|
+
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
11679
|
pieces.forEach(([d, opacity], i) => {
|
|
11421
11680
|
if (paths[i]) paths[i].update(d, {
|
|
11422
11681
|
width,
|
|
@@ -11437,6 +11696,113 @@ function along(stops, [first, last], p) {
|
|
|
11437
11696
|
for (let k = first; k <= last; k++) d += `${k === first ? "M" : "L"}${at(stops[k].from, stops[k].to, p)}`;
|
|
11438
11697
|
return d;
|
|
11439
11698
|
}
|
|
11699
|
+
function acrossX(from, to, points) {
|
|
11700
|
+
const a = courseOf(from);
|
|
11701
|
+
const b = a && courseOf(to);
|
|
11702
|
+
if (!a || !b || a.way !== b.way) return void 0;
|
|
11703
|
+
const all = [
|
|
11704
|
+
...Array.from({ length: points }, (_, i) => [i / (points - 1), 0]),
|
|
11705
|
+
...corners(a).map((s) => [s, 1]),
|
|
11706
|
+
...corners(b).map((s) => [s, 2])
|
|
11707
|
+
].sort((x, y) => x[0] - y[0]);
|
|
11708
|
+
const same = SAME_X / Math.max(Math.abs(a.span), Math.abs(b.span));
|
|
11709
|
+
const merged = [];
|
|
11710
|
+
for (const [s, whose] of all) {
|
|
11711
|
+
var _stop, _stop2;
|
|
11712
|
+
let stop = merged[merged.length - 1];
|
|
11713
|
+
if (!stop || s - stop[0] > same || whose > 0 && stop[whose] !== void 0) merged.push(stop = [s]);
|
|
11714
|
+
if (whose === 1) (_stop = stop)[1] ?? (_stop[1] = s);
|
|
11715
|
+
if (whose === 2) (_stop2 = stop)[2] ?? (_stop2[2] = s);
|
|
11716
|
+
}
|
|
11717
|
+
const last = merged.length - 1;
|
|
11718
|
+
if (last < 1) return void 0;
|
|
11719
|
+
const shareOn = (whose) => merged.map((stop, k) => k === 0 ? 0 : k === last ? 1 : stop[whose] ?? stop[0]);
|
|
11720
|
+
const [onA, onB] = [shareOn(1), shareOn(2)];
|
|
11721
|
+
const [pointsA, pointsB] = [placed(a, onA), placed(b, onB)];
|
|
11722
|
+
const stops = merged.map(([t], k) => ({
|
|
11723
|
+
t,
|
|
11724
|
+
from: pointsA[k],
|
|
11725
|
+
to: pointsB[k]
|
|
11726
|
+
}));
|
|
11727
|
+
const [inA, inB] = [inside(a.gaps), inside(b.gaps)];
|
|
11728
|
+
return {
|
|
11729
|
+
stops,
|
|
11730
|
+
kinds: stops.slice(1).map((_, k) => (inA((onA[k] + onA[k + 1]) / 2) ? 1 : 0) + (inB((onB[k] + onB[k + 1]) / 2) ? 2 : 0))
|
|
11731
|
+
};
|
|
11732
|
+
}
|
|
11733
|
+
function courseOf(mark) {
|
|
11734
|
+
const subpaths = flattenPath(parsePath(mark.outline.d));
|
|
11735
|
+
const points = [];
|
|
11736
|
+
const before = [];
|
|
11737
|
+
let next = 0;
|
|
11738
|
+
let from = 0;
|
|
11739
|
+
const stretch = (to) => {
|
|
11740
|
+
if (!(to > from)) {
|
|
11741
|
+
points.push(mark.path(from));
|
|
11742
|
+
return true;
|
|
11743
|
+
}
|
|
11744
|
+
const subpath = subpaths[next++];
|
|
11745
|
+
if (!subpath) return false;
|
|
11746
|
+
points.push(subpath.start);
|
|
11747
|
+
for (const segment of subpath.segments) {
|
|
11748
|
+
if (segment.kind !== "line") return false;
|
|
11749
|
+
points.push(segment.to);
|
|
11750
|
+
}
|
|
11751
|
+
return true;
|
|
11752
|
+
};
|
|
11753
|
+
for (const [start, end] of mark.gaps ?? []) {
|
|
11754
|
+
if (!stretch(start)) return void 0;
|
|
11755
|
+
before.push(points.length - 1);
|
|
11756
|
+
from = end;
|
|
11757
|
+
}
|
|
11758
|
+
if (!stretch(1) || next < subpaths.length || points.length < 2) return void 0;
|
|
11759
|
+
const x0 = points[0].x;
|
|
11760
|
+
const span = points[points.length - 1].x - x0;
|
|
11761
|
+
const way = Math.sign(span);
|
|
11762
|
+
for (let i = 1; i < points.length; i++) if (!((points[i].x - points[i - 1].x) * way > 0)) return void 0;
|
|
11763
|
+
const shares = points.map((point) => (point.x - x0) / span);
|
|
11764
|
+
return {
|
|
11765
|
+
points,
|
|
11766
|
+
shares,
|
|
11767
|
+
gaps: before.map((i) => [shares[i], shares[i + 1]]),
|
|
11768
|
+
span,
|
|
11769
|
+
way
|
|
11770
|
+
};
|
|
11771
|
+
}
|
|
11772
|
+
function corners(course) {
|
|
11773
|
+
const { points, shares, gaps } = course;
|
|
11774
|
+
if (points.length <= VERTICES) return shares;
|
|
11775
|
+
const columns = VERTICES / 4;
|
|
11776
|
+
const column = (k) => Math.min(249, Math.floor(shares[k] * columns));
|
|
11777
|
+
const kept = gaps.flat();
|
|
11778
|
+
for (let first = 0, i = 1; i <= points.length; i++) {
|
|
11779
|
+
if (i < points.length && column(i) === column(first)) continue;
|
|
11780
|
+
let [low, high] = [first, first];
|
|
11781
|
+
for (let k = first; k < i; k++) {
|
|
11782
|
+
if (points[k].y < points[low].y) low = k;
|
|
11783
|
+
if (points[k].y > points[high].y) high = k;
|
|
11784
|
+
}
|
|
11785
|
+
kept.push(shares[first], shares[low], shares[high], shares[i - 1]);
|
|
11786
|
+
first = i;
|
|
11787
|
+
}
|
|
11788
|
+
return Array.from(new Set(kept));
|
|
11789
|
+
}
|
|
11790
|
+
function placed(course, shares) {
|
|
11791
|
+
const { points, shares: at } = course;
|
|
11792
|
+
let i = 0;
|
|
11793
|
+
return shares.map((s) => {
|
|
11794
|
+
while (i + 2 < points.length && at[i + 1] <= s) i++;
|
|
11795
|
+
const width = at[i + 1] - at[i];
|
|
11796
|
+
return mixed(points[i], points[i + 1], width > 0 ? Math.min(1, Math.max(0, (s - at[i]) / width)) : 0);
|
|
11797
|
+
});
|
|
11798
|
+
}
|
|
11799
|
+
function inside(gaps) {
|
|
11800
|
+
let k = 0;
|
|
11801
|
+
return (s) => {
|
|
11802
|
+
while (k < gaps.length && gaps[k][1] <= s) k++;
|
|
11803
|
+
return k < gaps.length && gaps[k][0] < s;
|
|
11804
|
+
};
|
|
11805
|
+
}
|
|
11440
11806
|
function holePairs(from, to, a, b, [shiftA, shiftB], count) {
|
|
11441
11807
|
const holesA = holesOf(from.outline, count);
|
|
11442
11808
|
const holesB = holesOf(to.outline, count);
|
|
@@ -12139,7 +12505,7 @@ function configure(options) {
|
|
|
12139
12505
|
}
|
|
12140
12506
|
}
|
|
12141
12507
|
// src/index.ts
|
|
12142
|
-
const VERSION = "0.
|
|
12508
|
+
const VERSION = "0.7.0";
|
|
12143
12509
|
const env = {
|
|
12144
12510
|
presets: presetRegistry,
|
|
12145
12511
|
icons: iconRegistry,
|
|
@@ -12169,6 +12535,6 @@ function fromVegaView(view, options) {
|
|
|
12169
12535
|
function motionSwitch(target, motion$1 = motion, options) {
|
|
12170
12536
|
return motionSwitch$1(target, motion$1, options);
|
|
12171
12537
|
}
|
|
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 };
|
|
12538
|
+
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
12539
|
|
|
12174
12540
|
//# sourceMappingURL=index.js.map
|