expressive-charts 0.5.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 +55 -1
- package/README.md +7 -7
- 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-CMo-2gPf.d.ts → effect-DYCLY_6e.d.cts} +28 -4
- package/dist/{effect-C786hGyJ.d.cts → effect-HCWnmB72.d.ts} +28 -4
- 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 +1226 -234
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -17
- package/dist/index.d.ts +102 -17
- package/dist/index.js +1159 -226
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +36 -2
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +12 -3
- package/dist/testing.d.ts +12 -3
- package/dist/testing.js +20 -3
- package/dist/testing.js.map +1 -1
- package/dist/{transition-Bu1NsQor.js → transition-romki_A6.js} +70 -12
- package/dist/transition-romki_A6.js.map +1 -0
- package/package.json +3 -3
- package/dist/transition-Bu1NsQor.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -392,7 +392,7 @@ function animated(initial, interpolate, options = {}) {
|
|
|
392
392
|
// src/core/playback.ts
|
|
393
393
|
const SEEK_MS = 350;
|
|
394
394
|
function playback(options) {
|
|
395
|
-
checkOptions$
|
|
395
|
+
checkOptions$15(options);
|
|
396
396
|
const { from, to, duration, onFrame } = options;
|
|
397
397
|
const ease = options.ease ?? linear;
|
|
398
398
|
const timing = options.timing ?? "playback";
|
|
@@ -535,7 +535,7 @@ function playback(options) {
|
|
|
535
535
|
}
|
|
536
536
|
};
|
|
537
537
|
}
|
|
538
|
-
function checkOptions$
|
|
538
|
+
function checkOptions$15(options) {
|
|
539
539
|
if (typeof options !== "object" || options === null) throw new TypeError("playback needs options: { from, to, duration, onFrame }.");
|
|
540
540
|
const { from, to, duration, ease, timing, onFrame, clock, motion } = options;
|
|
541
541
|
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)}.`);
|
|
@@ -1694,7 +1694,7 @@ function describeShape(spec) {
|
|
|
1694
1694
|
].every(Number.isFinite)) throw new RangeError(`describe.shape: d must stay finite${m ? " once moved by matrix" : ""}, got ${show$2(d)}.`);
|
|
1695
1695
|
const labelBounds = labelBoxes$1("shape", spec.labelBounds);
|
|
1696
1696
|
const nearbyLabels = labelBoxes$1("shape", spec.nearbyLabels, "nearbyLabels");
|
|
1697
|
-
if (subpaths.every(closes) && length > 0) {
|
|
1697
|
+
if (subpaths.every(closes$1) && length > 0) {
|
|
1698
1698
|
const center = {
|
|
1699
1699
|
x: box.x + box.width / 2,
|
|
1700
1700
|
y: box.y + box.height / 2
|
|
@@ -1733,7 +1733,7 @@ function describeShape(spec) {
|
|
|
1733
1733
|
nearbyLabels
|
|
1734
1734
|
});
|
|
1735
1735
|
}
|
|
1736
|
-
const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
|
|
1736
|
+
const closes$1 = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
|
|
1737
1737
|
function joined(subpaths) {
|
|
1738
1738
|
const segments = [];
|
|
1739
1739
|
const across = [];
|
|
@@ -1954,9 +1954,9 @@ function samplesAlong(mark, points) {
|
|
|
1954
1954
|
...p.at === void 0 ? {} : { at: p.at }
|
|
1955
1955
|
}
|
|
1956
1956
|
})).sort((a, b) => a.sample.t - b.sample.t || a.index - b.index).map(({ sample }) => sample);
|
|
1957
|
-
return mark.gaps && mark.gaps.length > 0 ? gapped(samples, mark.gaps) : samples;
|
|
1957
|
+
return mark.gaps && mark.gaps.length > 0 ? gapped$1(samples, mark.gaps) : samples;
|
|
1958
1958
|
}
|
|
1959
|
-
function gapped(samples, gaps) {
|
|
1959
|
+
function gapped$1(samples, gaps) {
|
|
1960
1960
|
const middles = gaps.map(([from, to]) => (from + to) / 2).sort((a, b) => a - b);
|
|
1961
1961
|
let next = 0;
|
|
1962
1962
|
return samples.map((sample, k) => {
|
|
@@ -2073,6 +2073,22 @@ function mergeFields(current, next) {
|
|
|
2073
2073
|
else result[field] = value;
|
|
2074
2074
|
return result;
|
|
2075
2075
|
}
|
|
2076
|
+
// src/core/text-box.ts
|
|
2077
|
+
const TEXT_SIZE = 12.5;
|
|
2078
|
+
const AVERAGE_WIDTH = .6;
|
|
2079
|
+
const ASCENT$1 = 1.05;
|
|
2080
|
+
const SIDE = .16;
|
|
2081
|
+
function boxAround(at, anchor, width, size) {
|
|
2082
|
+
return {
|
|
2083
|
+
x: (anchor === "end" ? at.x - width : anchor === "middle" ? at.x - width / 2 : at.x) - SIDE * size,
|
|
2084
|
+
y: at.y - ASCENT$1 * size,
|
|
2085
|
+
width: width + 2 * SIDE * size,
|
|
2086
|
+
height: 1.3 * size
|
|
2087
|
+
};
|
|
2088
|
+
}
|
|
2089
|
+
function estimatedBox(content, style) {
|
|
2090
|
+
return boxAround(style.at, style.anchor, content.length * TEXT_SIZE * AVERAGE_WIDTH, TEXT_SIZE);
|
|
2091
|
+
}
|
|
2076
2092
|
// src/core/runner.ts
|
|
2077
2093
|
function runScope(options) {
|
|
2078
2094
|
const { clock, motion, layer, mark } = options;
|
|
@@ -2087,6 +2103,7 @@ function runScope(options) {
|
|
|
2087
2103
|
icons: options.icons,
|
|
2088
2104
|
batch: options.batch,
|
|
2089
2105
|
...options.previous ? { previous: options.previous } : {},
|
|
2106
|
+
...options.texts ? { texts: options.texts } : {},
|
|
2090
2107
|
tween(tweenOptions) {
|
|
2091
2108
|
const own = tweenOptions.signal;
|
|
2092
2109
|
const running = tween({
|
|
@@ -2127,6 +2144,8 @@ const SLOTS = [
|
|
|
2127
2144
|
"exit",
|
|
2128
2145
|
"hover"
|
|
2129
2146
|
];
|
|
2147
|
+
const byOrder = (a, b) => a.order - b.order;
|
|
2148
|
+
const sameBox = (a, b) => a === b || a !== void 0 && b !== void 0 && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
2130
2149
|
const NO_ICONS$1 = { get: () => void 0 };
|
|
2131
2150
|
const INERT$1 = {
|
|
2132
2151
|
place() {},
|
|
@@ -2144,6 +2163,10 @@ function createRunner(options) {
|
|
|
2144
2163
|
let transitioning = false;
|
|
2145
2164
|
let destroyed = false;
|
|
2146
2165
|
let order = 0;
|
|
2166
|
+
const box = (content, style) => surface.box ? surface.box(content, style) : estimatedBox(content, style);
|
|
2167
|
+
const texts = /* @__PURE__ */ new Map();
|
|
2168
|
+
let holds = 0;
|
|
2169
|
+
let flushing = false;
|
|
2147
2170
|
const unsubscribe = motion$3.subscribe(() => {
|
|
2148
2171
|
if (motion$3.mode === "off") endRunning();
|
|
2149
2172
|
});
|
|
@@ -2195,7 +2218,14 @@ function createRunner(options) {
|
|
|
2195
2218
|
batch,
|
|
2196
2219
|
previous,
|
|
2197
2220
|
layer: runLayer(entry.key, slot, () => run.order, () => run.state !== "cleared"),
|
|
2198
|
-
mark: runMark(() => run)
|
|
2221
|
+
mark: runMark(() => run),
|
|
2222
|
+
texts: {
|
|
2223
|
+
box,
|
|
2224
|
+
held: () => [...texts].flatMap(([other, held]) => held.box && other.order < run.order ? [held.box] : []),
|
|
2225
|
+
hold(next) {
|
|
2226
|
+
if (run.state !== "cleared") hold(run, next);
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2199
2229
|
})
|
|
2200
2230
|
};
|
|
2201
2231
|
entry.runs.set(slot, run);
|
|
@@ -2242,8 +2272,44 @@ function createRunner(options) {
|
|
|
2242
2272
|
report(error);
|
|
2243
2273
|
}
|
|
2244
2274
|
run.scope.clear();
|
|
2275
|
+
hold(run, void 0);
|
|
2245
2276
|
release(run);
|
|
2246
2277
|
}
|
|
2278
|
+
function tell(run, mark) {
|
|
2279
|
+
try {
|
|
2280
|
+
run.scope.change(mark, latestData(run.entry, run));
|
|
2281
|
+
} catch (error) {
|
|
2282
|
+
report(error);
|
|
2283
|
+
clearRun(run);
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
function hold(run, next) {
|
|
2287
|
+
let held = texts.get(run);
|
|
2288
|
+
if (!held) {
|
|
2289
|
+
if (!next) return;
|
|
2290
|
+
texts.set(run, held = {
|
|
2291
|
+
box: void 0,
|
|
2292
|
+
placed: 0,
|
|
2293
|
+
moved: 0
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
held.placed = ++holds;
|
|
2297
|
+
if (sameBox(held.box, next)) return;
|
|
2298
|
+
held.box = next;
|
|
2299
|
+
held.moved = holds;
|
|
2300
|
+
if (flushing) return;
|
|
2301
|
+
flushing = true;
|
|
2302
|
+
queueMicrotask(flush);
|
|
2303
|
+
}
|
|
2304
|
+
function flush() {
|
|
2305
|
+
let moved = 0;
|
|
2306
|
+
for (const [run, held] of [...texts].sort(([a], [b]) => byOrder(a, b))) {
|
|
2307
|
+
if (held.box && held.placed < moved) tell(run, run.entry.mark);
|
|
2308
|
+
if (!held.box) texts.delete(run);
|
|
2309
|
+
moved = Math.max(moved, held.moved);
|
|
2310
|
+
}
|
|
2311
|
+
flushing = false;
|
|
2312
|
+
}
|
|
2247
2313
|
function runLayer(key, slot, order, live) {
|
|
2248
2314
|
let group;
|
|
2249
2315
|
const target = () => live() ? group ?? (group = surface.group(key, slot, order())) : void 0;
|
|
@@ -2422,15 +2488,7 @@ function createRunner(options) {
|
|
|
2422
2488
|
entry.data = data;
|
|
2423
2489
|
if (!transitioning) entry.resting = data;
|
|
2424
2490
|
}
|
|
2425
|
-
for (const run of [...entry.runs.values()])
|
|
2426
|
-
if (run.state === "cleared") continue;
|
|
2427
|
-
try {
|
|
2428
|
-
run.scope.change(mark, latestData(entry, run));
|
|
2429
|
-
} catch (error) {
|
|
2430
|
-
report(error);
|
|
2431
|
-
clearRun(run);
|
|
2432
|
-
}
|
|
2433
|
-
}
|
|
2491
|
+
for (const run of [...entry.runs.values()].sort(byOrder)) if (run.state !== "cleared") tell(run, mark);
|
|
2434
2492
|
},
|
|
2435
2493
|
interrupt() {
|
|
2436
2494
|
if (destroyed) return;
|
|
@@ -2593,16 +2651,8 @@ function linear$1(value) {
|
|
|
2593
2651
|
return rounded === 0 ? "0" : String(rounded);
|
|
2594
2652
|
}
|
|
2595
2653
|
// src/charts/render/text.ts
|
|
2596
|
-
const ASCENT$1 = 1.05;
|
|
2597
|
-
const SIDE = .16;
|
|
2598
2654
|
function textBox(placement, measure, className, size) {
|
|
2599
|
-
|
|
2600
|
-
return {
|
|
2601
|
-
x: (placement.anchor === "start" ? placement.x : placement.anchor === "end" ? placement.x - width : placement.x - width / 2) - SIDE * size,
|
|
2602
|
-
y: placement.y - ASCENT$1 * size,
|
|
2603
|
-
width: width + 2 * SIDE * size,
|
|
2604
|
-
height: 1.3 * size
|
|
2605
|
-
};
|
|
2655
|
+
return boxAround(placement, placement.anchor, measure(placement.text.replace(/\d/g, "0"), className, size), size);
|
|
2606
2656
|
}
|
|
2607
2657
|
function placeText(element, placement) {
|
|
2608
2658
|
setAttributes(element, {
|
|
@@ -2612,7 +2662,6 @@ function placeText(element, placement) {
|
|
|
2612
2662
|
});
|
|
2613
2663
|
if (element.textContent !== placement.text) element.textContent = placement.text;
|
|
2614
2664
|
}
|
|
2615
|
-
const AVERAGE_WIDTH = .6;
|
|
2616
2665
|
function textMeasure(svg) {
|
|
2617
2666
|
const cache = /* @__PURE__ */ new Map();
|
|
2618
2667
|
const measure = (text, className, size) => {
|
|
@@ -3708,7 +3757,7 @@ function mix$3(colors, emphasis) {
|
|
|
3708
3757
|
// src/charts/render/layer.ts
|
|
3709
3758
|
const FOLLOW = "ec-follow";
|
|
3710
3759
|
let clipIds = 0;
|
|
3711
|
-
function svgLayer(group, follow) {
|
|
3760
|
+
function svgLayer(group, follow, parts) {
|
|
3712
3761
|
const into = () => {
|
|
3713
3762
|
if (!follow) return group;
|
|
3714
3763
|
const last = group.lastElementChild;
|
|
@@ -3747,13 +3796,13 @@ function svgLayer(group, follow) {
|
|
|
3747
3796
|
d
|
|
3748
3797
|
}, into());
|
|
3749
3798
|
let current = { ...paint };
|
|
3750
|
-
paintPath(element, current);
|
|
3799
|
+
paintPath(element, current, parts);
|
|
3751
3800
|
return {
|
|
3752
3801
|
update(next, nextPaint) {
|
|
3753
3802
|
element.setAttribute("d", next);
|
|
3754
3803
|
if (nextPaint) {
|
|
3755
3804
|
current = mergeFields(current, nextPaint);
|
|
3756
|
-
paintPath(element, current);
|
|
3805
|
+
paintPath(element, current, parts);
|
|
3757
3806
|
}
|
|
3758
3807
|
},
|
|
3759
3808
|
remove: () => element.remove()
|
|
@@ -3797,14 +3846,17 @@ function drawShape(shape, parent) {
|
|
|
3797
3846
|
stroke: shape.stroke === void 0 ? void 0 : cssColor(shape.stroke)
|
|
3798
3847
|
});
|
|
3799
3848
|
}
|
|
3800
|
-
function paintPath(element, paint) {
|
|
3849
|
+
function paintPath(element, paint, parts) {
|
|
3850
|
+
const { part } = paint;
|
|
3801
3851
|
setAttributes(element, {
|
|
3802
3852
|
"stroke-width": paint.stroke === void 0 ? void 0 : paint.width ?? 1,
|
|
3803
3853
|
opacity: paint.opacity,
|
|
3804
3854
|
"stroke-linecap": paint.linecap,
|
|
3805
|
-
"stroke-linejoin": "round"
|
|
3855
|
+
"stroke-linejoin": "round",
|
|
3856
|
+
"data-part": part
|
|
3806
3857
|
});
|
|
3807
3858
|
setStyles(element, {
|
|
3859
|
+
...markColorStyles(part === void 0 ? void 0 : parts?.(part)),
|
|
3808
3860
|
fill: paint.fill === void 0 ? "none" : cssColor(paint.fill),
|
|
3809
3861
|
stroke: paint.stroke === void 0 ? void 0 : cssColor(paint.stroke)
|
|
3810
3862
|
});
|
|
@@ -3821,6 +3873,7 @@ function styleText(element, style) {
|
|
|
3821
3873
|
// src/charts/render/surface.ts
|
|
3822
3874
|
function svgSurface(options) {
|
|
3823
3875
|
const { overlay } = options;
|
|
3876
|
+
const measure = options.measure ?? textMeasure(overlay);
|
|
3824
3877
|
const orders = /* @__PURE__ */ new WeakMap();
|
|
3825
3878
|
const groups = /* @__PURE__ */ new Map();
|
|
3826
3879
|
const hidden = /* @__PURE__ */ new Set();
|
|
@@ -3848,7 +3901,7 @@ function svgSurface(options) {
|
|
|
3848
3901
|
live.add(group);
|
|
3849
3902
|
const owner = live;
|
|
3850
3903
|
return {
|
|
3851
|
-
...svgLayer(group, () => transforms.get(key)),
|
|
3904
|
+
...svgLayer(group, () => transforms.get(key), (part) => options.colors(key, part)),
|
|
3852
3905
|
clear() {
|
|
3853
3906
|
group.remove();
|
|
3854
3907
|
owner.delete(group);
|
|
@@ -3856,6 +3909,12 @@ function svgSurface(options) {
|
|
|
3856
3909
|
}
|
|
3857
3910
|
};
|
|
3858
3911
|
},
|
|
3912
|
+
box: (text, { at, anchor = "start" }) => textBox({
|
|
3913
|
+
x: at.x,
|
|
3914
|
+
y: at.y,
|
|
3915
|
+
anchor,
|
|
3916
|
+
text
|
|
3917
|
+
}, measure, "ec-text", TEXT_SIZE),
|
|
3859
3918
|
mark(key) {
|
|
3860
3919
|
const handle = options.mark(key);
|
|
3861
3920
|
return {
|
|
@@ -3873,7 +3932,10 @@ function svgSurface(options) {
|
|
|
3873
3932
|
const live = groups.get(key);
|
|
3874
3933
|
if (!live) return;
|
|
3875
3934
|
const styles = markColorStyles(options.colors(key));
|
|
3876
|
-
for (const group of live)
|
|
3935
|
+
for (const group of live) {
|
|
3936
|
+
setStyles(group, styles);
|
|
3937
|
+
for (const path of group.querySelectorAll("[data-part]")) setStyles(path, markColorStyles(options.colors(key, path.getAttribute("data-part"))));
|
|
3938
|
+
}
|
|
3877
3939
|
},
|
|
3878
3940
|
hide(key, hide) {
|
|
3879
3941
|
if (hide) hidden.add(key);
|
|
@@ -3951,13 +4013,13 @@ function decimals(value) {
|
|
|
3951
4013
|
const point = text.indexOf(".");
|
|
3952
4014
|
return point < 0 ? 0 : Math.min(6, text.length - point - 1);
|
|
3953
4015
|
}
|
|
3954
|
-
function round$
|
|
4016
|
+
function round$5(value, digits) {
|
|
3955
4017
|
const factor = 10 ** digits;
|
|
3956
4018
|
const rounded = Math.round(value * factor) / factor;
|
|
3957
4019
|
return rounded === 0 ? 0 : rounded;
|
|
3958
4020
|
}
|
|
3959
4021
|
function percent(share) {
|
|
3960
|
-
return `${round$
|
|
4022
|
+
return `${round$5(share * 100, 0)}%`;
|
|
3961
4023
|
}
|
|
3962
4024
|
// src/charts/interaction.ts
|
|
3963
4025
|
function pointerHover(svg, options) {
|
|
@@ -4310,6 +4372,14 @@ function keyboardFocus(svg, options) {
|
|
|
4310
4372
|
last = keys;
|
|
4311
4373
|
return had === void 0 ? void 0 : current;
|
|
4312
4374
|
},
|
|
4375
|
+
moveTabStop(key) {
|
|
4376
|
+
listen();
|
|
4377
|
+
const keys = options.order();
|
|
4378
|
+
if (!keys.includes(key) || options.find(on?.scope.activeElement ?? null) !== void 0) return false;
|
|
4379
|
+
tabStop = key;
|
|
4380
|
+
applyTabIndex(keys);
|
|
4381
|
+
return true;
|
|
4382
|
+
},
|
|
4313
4383
|
destroy() {
|
|
4314
4384
|
current = void 0;
|
|
4315
4385
|
focused = void 0;
|
|
@@ -4567,6 +4637,7 @@ function chartHover(options) {
|
|
|
4567
4637
|
focus(key) {
|
|
4568
4638
|
if (options.live(key)) keyboard.focus(key);
|
|
4569
4639
|
},
|
|
4640
|
+
moveTabStop: (key) => options.live(key) && keyboard.moveTabStop(key),
|
|
4570
4641
|
leave,
|
|
4571
4642
|
destroy() {
|
|
4572
4643
|
destroyed = true;
|
|
@@ -5152,7 +5223,7 @@ function chartTooltip(svg, options) {
|
|
|
5152
5223
|
if (x > left && x < right && y > top && y < bottom) return true;
|
|
5153
5224
|
if (!shape) return false;
|
|
5154
5225
|
const origin = layer.getBoundingClientRect();
|
|
5155
|
-
return inside$
|
|
5226
|
+
return inside$2(shape, x - origin.left, y - origin.top);
|
|
5156
5227
|
};
|
|
5157
5228
|
const letThrough = (on) => {
|
|
5158
5229
|
through = on;
|
|
@@ -5247,7 +5318,7 @@ function chartTooltip(svg, options) {
|
|
|
5247
5318
|
top: dy + near.top,
|
|
5248
5319
|
bottom: dy + near.bottom
|
|
5249
5320
|
};
|
|
5250
|
-
shape = span(bridge, {
|
|
5321
|
+
shape = span$1(bridge, {
|
|
5251
5322
|
left,
|
|
5252
5323
|
top,
|
|
5253
5324
|
...size
|
|
@@ -5341,12 +5412,12 @@ function chartTooltip(svg, options) {
|
|
|
5341
5412
|
}
|
|
5342
5413
|
};
|
|
5343
5414
|
}
|
|
5344
|
-
function inside$
|
|
5415
|
+
function inside$2({ top, bottom, upper, lower }, x, y) {
|
|
5345
5416
|
if (y <= top || y >= bottom) return false;
|
|
5346
5417
|
const t = (y - top) / (bottom - top);
|
|
5347
5418
|
return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
|
|
5348
5419
|
}
|
|
5349
|
-
function span(bridge, box, mark, side) {
|
|
5420
|
+
function span$1(bridge, box, mark, side) {
|
|
5350
5421
|
bridge.hidden = mark === void 0;
|
|
5351
5422
|
if (!mark) return void 0;
|
|
5352
5423
|
const edge = {
|
|
@@ -5428,7 +5499,7 @@ function viewBox$1(svg) {
|
|
|
5428
5499
|
const STAGE$2 = 500;
|
|
5429
5500
|
function barChart$1(target, options, env) {
|
|
5430
5501
|
const container = resolveTarget$2(target, "barChart");
|
|
5431
|
-
checkOptions$
|
|
5502
|
+
checkOptions$14(options);
|
|
5432
5503
|
let current = options;
|
|
5433
5504
|
const motion = chartMotion(options.motion, env.motion);
|
|
5434
5505
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -5487,6 +5558,7 @@ function barChart$1(target, options, env) {
|
|
|
5487
5558
|
const find = (key) => records.get(key) ?? leaving.get(key);
|
|
5488
5559
|
const surface = svgSurface({
|
|
5489
5560
|
overlay,
|
|
5561
|
+
measure,
|
|
5490
5562
|
mark: (key) => ({
|
|
5491
5563
|
set: (style) => {
|
|
5492
5564
|
find(key)?.handle.set(style);
|
|
@@ -5497,7 +5569,7 @@ function barChart$1(target, options, env) {
|
|
|
5497
5569
|
hover.restyled(key);
|
|
5498
5570
|
}
|
|
5499
5571
|
}),
|
|
5500
|
-
colors: (key) => find(key)?.parts[0]?.colors
|
|
5572
|
+
colors: (key, part) => find(key)?.parts[part === void 0 ? 0 : (find(key)?.shown.geometry.segments ?? []).findIndex((segment) => segment.key === part)]?.colors
|
|
5501
5573
|
});
|
|
5502
5574
|
const runner = createRunner({
|
|
5503
5575
|
effects,
|
|
@@ -5739,7 +5811,7 @@ function barChart$1(target, options, env) {
|
|
|
5739
5811
|
value: now[series] ?? 0
|
|
5740
5812
|
}));
|
|
5741
5813
|
const total = values.reduce((sum, v) => sum + v.value, 0);
|
|
5742
|
-
const text = record.count === void 0 ? row.value.text : format(current)(round$
|
|
5814
|
+
const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
|
|
5743
5815
|
return placeRow(frame, {
|
|
5744
5816
|
key: row.key,
|
|
5745
5817
|
datum: row.datum,
|
|
@@ -5996,7 +6068,7 @@ function barChart$1(target, options, env) {
|
|
|
5996
6068
|
...current,
|
|
5997
6069
|
...next
|
|
5998
6070
|
};
|
|
5999
|
-
checkOptions$
|
|
6071
|
+
checkOptions$14(merged);
|
|
6000
6072
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
6001
6073
|
const nextLayout = layout(merged, swapped);
|
|
6002
6074
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -6044,6 +6116,15 @@ function barChart$1(target, options, env) {
|
|
|
6044
6116
|
if (!destroyed) hover.leave();
|
|
6045
6117
|
},
|
|
6046
6118
|
labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.shown.label, record.label), ...chartLabel(record.key, "value", record.shown.value, record.value)]),
|
|
6119
|
+
paintOf(key) {
|
|
6120
|
+
const record = records.get(key);
|
|
6121
|
+
const first = record?.shown.geometry.segments?.[0];
|
|
6122
|
+
return record && {
|
|
6123
|
+
color: byCategory(current) ? key : first?.series ?? first?.key ?? key,
|
|
6124
|
+
drawn: true
|
|
6125
|
+
};
|
|
6126
|
+
},
|
|
6127
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
6047
6128
|
destroy() {
|
|
6048
6129
|
if (destroyed) return;
|
|
6049
6130
|
destroyed = true;
|
|
@@ -6076,7 +6157,7 @@ function barChart$1(target, options, env) {
|
|
|
6076
6157
|
}
|
|
6077
6158
|
});
|
|
6078
6159
|
}
|
|
6079
|
-
function checkOptions$
|
|
6160
|
+
function checkOptions$14(options) {
|
|
6080
6161
|
checkChartOptions(options, "barChart");
|
|
6081
6162
|
const { colorBy, room } = options;
|
|
6082
6163
|
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)}.`);
|
|
@@ -6209,26 +6290,8 @@ function joinedStarts(values) {
|
|
|
6209
6290
|
});
|
|
6210
6291
|
}
|
|
6211
6292
|
function placeSlices(frame, states, labels, measure) {
|
|
6212
|
-
const boxes = labels.map((label) => label ? labelBoxes(label, measure) :
|
|
6213
|
-
|
|
6214
|
-
const first = labelled[0];
|
|
6215
|
-
const last = labelled[labelled.length - 1];
|
|
6216
|
-
const before = [];
|
|
6217
|
-
const after = [];
|
|
6218
|
-
let seen;
|
|
6219
|
-
for (let i = 0; i < states.length; i++) {
|
|
6220
|
-
before[i] = seen ?? (last === i ? void 0 : last);
|
|
6221
|
-
if (boxes[i]) seen = i;
|
|
6222
|
-
}
|
|
6223
|
-
seen = void 0;
|
|
6224
|
-
for (let i = states.length - 1; i >= 0; i--) {
|
|
6225
|
-
after[i] = seen ?? (first === i ? void 0 : first);
|
|
6226
|
-
if (boxes[i]) seen = i;
|
|
6227
|
-
}
|
|
6228
|
-
return states.map((state, i) => {
|
|
6229
|
-
const sides = before[i] === after[i] ? [before[i]] : [before[i], after[i]];
|
|
6230
|
-
return placeSlice(frame, state, labels[i], measure, sides.flatMap((j) => j === void 0 ? [] : boxes[j]));
|
|
6231
|
-
});
|
|
6293
|
+
const boxes = labels.map((label) => label ? labelBoxes(label, measure) : []);
|
|
6294
|
+
return states.map((state, i) => placeSlice(frame, state, labels[i], measure, boxes.flatMap((box, j) => j === i ? [] : box)));
|
|
6232
6295
|
}
|
|
6233
6296
|
function placeSlice(frame, state, label, measure, nearby) {
|
|
6234
6297
|
const geometry = describeArc({
|
|
@@ -6398,7 +6461,7 @@ const TAU = 2 * Math.PI;
|
|
|
6398
6461
|
const VISIBLE$1 = .5;
|
|
6399
6462
|
function donutChart$1(target, options, env) {
|
|
6400
6463
|
const container = resolveTarget$2(target, "donutChart");
|
|
6401
|
-
checkOptions$
|
|
6464
|
+
checkOptions$13(options);
|
|
6402
6465
|
let current = options;
|
|
6403
6466
|
const motion = chartMotion(options.motion, env.motion);
|
|
6404
6467
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -6444,6 +6507,7 @@ function donutChart$1(target, options, env) {
|
|
|
6444
6507
|
const find = (key) => records.get(key) ?? leaving.get(key);
|
|
6445
6508
|
const surface = svgSurface({
|
|
6446
6509
|
overlay: runs,
|
|
6510
|
+
measure,
|
|
6447
6511
|
mark: (key) => ({
|
|
6448
6512
|
set: (style) => {
|
|
6449
6513
|
find(key)?.handle.set(style);
|
|
@@ -6747,7 +6811,7 @@ function donutChart$1(target, options, env) {
|
|
|
6747
6811
|
const slices = currentSlices(f);
|
|
6748
6812
|
for (const { record, slice, label } of slices) show(record, slice, label);
|
|
6749
6813
|
const total = slices.reduce((sum, { slice }) => sum + slice.value, 0);
|
|
6750
|
-
drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$
|
|
6814
|
+
drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$5(total, count)), measure));
|
|
6751
6815
|
}
|
|
6752
6816
|
function counting(total) {
|
|
6753
6817
|
if (counted?.total !== total) counted = {
|
|
@@ -6969,7 +7033,7 @@ function donutChart$1(target, options, env) {
|
|
|
6969
7033
|
...current,
|
|
6970
7034
|
...next
|
|
6971
7035
|
};
|
|
6972
|
-
checkOptions$
|
|
7036
|
+
checkOptions$13(merged);
|
|
6973
7037
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
6974
7038
|
const nextLayout = layout(merged, swapped);
|
|
6975
7039
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -7021,6 +7085,11 @@ function donutChart$1(target, options, env) {
|
|
|
7021
7085
|
if (!destroyed) hover.leave();
|
|
7022
7086
|
},
|
|
7023
7087
|
labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.drawnLabel?.category, record.label), ...chartLabel(record.key, "value", record.drawnLabel?.share, record.share)]),
|
|
7088
|
+
paintOf: (key) => records.has(key) ? {
|
|
7089
|
+
color: key,
|
|
7090
|
+
drawn: true
|
|
7091
|
+
} : void 0,
|
|
7092
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
7024
7093
|
destroy() {
|
|
7025
7094
|
if (destroyed) return;
|
|
7026
7095
|
destroyed = true;
|
|
@@ -7051,7 +7120,7 @@ function donutChart$1(target, options, env) {
|
|
|
7051
7120
|
}
|
|
7052
7121
|
});
|
|
7053
7122
|
}
|
|
7054
|
-
function checkOptions$
|
|
7123
|
+
function checkOptions$13(options) {
|
|
7055
7124
|
checkChartOptions(options, "donutChart");
|
|
7056
7125
|
const { center, sort } = options;
|
|
7057
7126
|
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.");
|
|
@@ -7594,6 +7663,17 @@ function lineEncoding(options) {
|
|
|
7594
7663
|
curve
|
|
7595
7664
|
};
|
|
7596
7665
|
}
|
|
7666
|
+
function checkRoom(room) {
|
|
7667
|
+
const px = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
7668
|
+
if (typeof room !== "object" || room === null || Array.isArray(room)) {
|
|
7669
|
+
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)}.`);
|
|
7670
|
+
return;
|
|
7671
|
+
}
|
|
7672
|
+
for (const side of ["right", "top"]) {
|
|
7673
|
+
const value = room[side];
|
|
7674
|
+
if (value !== void 0 && !px(value)) throw new RangeError(`lineChart: room.${side} must be a number of px, 0 or more, got ${String(value)}.`);
|
|
7675
|
+
}
|
|
7676
|
+
}
|
|
7597
7677
|
function layoutLines(input) {
|
|
7598
7678
|
const { width, measure } = input;
|
|
7599
7679
|
const height = input.height ?? HEIGHT;
|
|
@@ -7610,9 +7690,11 @@ function layoutLines(input) {
|
|
|
7610
7690
|
const xValues = ticked.map((tick) => tick.value);
|
|
7611
7691
|
const xTexts = ticked.map((tick) => tick.text);
|
|
7612
7692
|
const xWidths = xTexts.map((text) => measure(text, "ec-tick", TICK_SIZE));
|
|
7693
|
+
const room = typeof input.room === "number" ? { right: input.room } : input.room;
|
|
7613
7694
|
const labelWidth = input.label ? widest(distinctLabels(rows, input.label), "ec-value", VALUE_SIZE, measure) : 0;
|
|
7614
7695
|
const left = Math.max(widest(yTexts, "ec-tick", TICK_SIZE, measure) + 10, (xWidths[0] ?? 0) / 2 + 2);
|
|
7615
|
-
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0);
|
|
7696
|
+
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (room?.right ?? 0));
|
|
7697
|
+
const top = TOP + (room?.top ?? 0);
|
|
7616
7698
|
const frame = {
|
|
7617
7699
|
scale: {
|
|
7618
7700
|
lo: domain.lo,
|
|
@@ -7623,8 +7705,8 @@ function layoutLines(input) {
|
|
|
7623
7705
|
xHi,
|
|
7624
7706
|
left,
|
|
7625
7707
|
right: Math.max(left, width - right),
|
|
7626
|
-
top
|
|
7627
|
-
bottom: Math.max(
|
|
7708
|
+
top,
|
|
7709
|
+
bottom: Math.max(top, height - AXIS),
|
|
7628
7710
|
width,
|
|
7629
7711
|
height
|
|
7630
7712
|
}
|
|
@@ -8055,6 +8137,7 @@ const show$1 = (value) => typeof value === "string" ? JSON.stringify(value) : St
|
|
|
8055
8137
|
// src/charts/line.ts
|
|
8056
8138
|
const STAGE = 500;
|
|
8057
8139
|
const RING = 2;
|
|
8140
|
+
const DOT_RING = 2;
|
|
8058
8141
|
const VISIBLE = .5;
|
|
8059
8142
|
function lineChart$1(target, options, env) {
|
|
8060
8143
|
const container = resolveTarget$2(target, "lineChart");
|
|
@@ -8121,7 +8204,7 @@ function lineChart$1(target, options, env) {
|
|
|
8121
8204
|
try {
|
|
8122
8205
|
laidOut = layout(current);
|
|
8123
8206
|
firstTable = tableFor(current, laidOut);
|
|
8124
|
-
names = namesFor(current, laidOut);
|
|
8207
|
+
names = hoverKind === "x" ? namesFor(current, laidOut) : void 0;
|
|
8125
8208
|
pointNames = hoverKind === "point" ? pointNamesFor(current, laidOut) : void 0;
|
|
8126
8209
|
} catch (error) {
|
|
8127
8210
|
svg.remove();
|
|
@@ -8130,6 +8213,7 @@ function lineChart$1(target, options, env) {
|
|
|
8130
8213
|
const findMark = (key) => points.get(key) ?? lines.get(key) ?? leaving.get(key);
|
|
8131
8214
|
const surface = svgSurface({
|
|
8132
8215
|
overlay,
|
|
8216
|
+
measure,
|
|
8133
8217
|
mark: (key) => ({
|
|
8134
8218
|
set: (style) => {
|
|
8135
8219
|
findMark(key)?.handle.set(style);
|
|
@@ -8195,6 +8279,8 @@ function lineChart$1(target, options, env) {
|
|
|
8195
8279
|
function layout(opts, using = effects) {
|
|
8196
8280
|
const encoding = lineEncoding(opts);
|
|
8197
8281
|
checkNeeds$1(using, encoding.series.map((s) => s.series), "lineChart");
|
|
8282
|
+
const { room } = opts;
|
|
8283
|
+
checkRoom(room);
|
|
8198
8284
|
const next = layoutLines({
|
|
8199
8285
|
data: opts.data,
|
|
8200
8286
|
encoding,
|
|
@@ -8202,7 +8288,8 @@ function lineChart$1(target, options, env) {
|
|
|
8202
8288
|
height: opts.height,
|
|
8203
8289
|
format: format(opts),
|
|
8204
8290
|
measure,
|
|
8205
|
-
label: labeler(opts, true)
|
|
8291
|
+
label: labeler(opts, true),
|
|
8292
|
+
room
|
|
8206
8293
|
});
|
|
8207
8294
|
const keys = new Set(next.series);
|
|
8208
8295
|
for (const row of next.rows) for (const name of next.series) {
|
|
@@ -8236,7 +8323,7 @@ function lineChart$1(target, options, env) {
|
|
|
8236
8323
|
const label = labeler(current);
|
|
8237
8324
|
if (!label) return void 0;
|
|
8238
8325
|
return {
|
|
8239
|
-
text: (series, value) => label(series, round$
|
|
8326
|
+
text: (series, value) => label(series, round$5(value, given[series] ?? decimals(value))),
|
|
8240
8327
|
measure
|
|
8241
8328
|
};
|
|
8242
8329
|
}
|
|
@@ -8700,23 +8787,42 @@ function lineChart$1(target, options, env) {
|
|
|
8700
8787
|
}
|
|
8701
8788
|
const along = (series) => rowOrder.filter(revealed).flatMap((record) => livePoints(record).filter((point) => point.series === series));
|
|
8702
8789
|
function nearestPoint(at) {
|
|
8790
|
+
const shown = rowOrder.filter(revealed).flatMap(livePoints);
|
|
8703
8791
|
let best;
|
|
8704
8792
|
let far = Infinity;
|
|
8705
8793
|
let rank = Infinity;
|
|
8706
|
-
for (const
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8794
|
+
for (const point of shown) {
|
|
8795
|
+
const d = apart(point.shown.geometry.center, at);
|
|
8796
|
+
const r = laidOut.series.indexOf(point.series);
|
|
8797
|
+
if (d < far || d === far && r < rank) [best, far, rank] = [
|
|
8798
|
+
point,
|
|
8799
|
+
d,
|
|
8800
|
+
r
|
|
8801
|
+
];
|
|
8802
|
+
}
|
|
8803
|
+
if (!best) return void 0;
|
|
8804
|
+
const center = best.shown.geometry.center;
|
|
8805
|
+
const on = /* @__PURE__ */ new Map();
|
|
8806
|
+
for (const point of shown) {
|
|
8807
|
+
const { center: c } = point.shown.geometry;
|
|
8808
|
+
const known = on.get(point.series);
|
|
8809
|
+
if (apart(c, center) <= 1 && (!known || apart(c, at) < apart(known.shown.geometry.center, at))) on.set(point.series, point);
|
|
8810
|
+
}
|
|
8811
|
+
if (on.size < 2) return best;
|
|
8812
|
+
let pick = best;
|
|
8813
|
+
let near = Infinity;
|
|
8814
|
+
for (const series of laidOut.series) {
|
|
8815
|
+
const point = on.get(series);
|
|
8816
|
+
if (!point) continue;
|
|
8817
|
+
const d = passing(point, at);
|
|
8818
|
+
if (d < near) [pick, near] = [point, d];
|
|
8718
8819
|
}
|
|
8719
|
-
return
|
|
8820
|
+
return pick;
|
|
8821
|
+
}
|
|
8822
|
+
function passing(point, at) {
|
|
8823
|
+
const { geometry, data } = point.shown;
|
|
8824
|
+
const line = lines.get(point.series);
|
|
8825
|
+
return (line && strokeNear(line.shown, data.samples[0].at, geometry.center, at, 9)) ?? Math.max(0, Math.hypot(at.x - geometry.center.x, at.y - geometry.center.y) - 4.5);
|
|
8720
8826
|
}
|
|
8721
8827
|
function heldPoint(at) {
|
|
8722
8828
|
const point = hover.key === void 0 || !tooltip.element() ? void 0 : points.get(hover.key);
|
|
@@ -8962,8 +9068,9 @@ function lineChart$1(target, options, env) {
|
|
|
8962
9068
|
});
|
|
8963
9069
|
}
|
|
8964
9070
|
function labelColumn(record) {
|
|
9071
|
+
if (hoverKind !== "x") return;
|
|
8965
9072
|
record.column.setAttribute("aria-label", names.get(record.key));
|
|
8966
|
-
|
|
9073
|
+
tooltip.describe(record.column, record.row);
|
|
8967
9074
|
}
|
|
8968
9075
|
function announceChange(previous, before) {
|
|
8969
9076
|
const option = current.announce;
|
|
@@ -9231,6 +9338,11 @@ function lineChart$1(target, options, env) {
|
|
|
9231
9338
|
const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
|
|
9232
9339
|
hover.sync();
|
|
9233
9340
|
runner.enter(liveMarks().map(input));
|
|
9341
|
+
function stopFor(key) {
|
|
9342
|
+
const row = rows.get(key);
|
|
9343
|
+
if (hoverKind === "x") return (row ?? points.get(key)?.row)?.key;
|
|
9344
|
+
return (points.get(key) ?? (row && livePoints(row)[0]))?.key;
|
|
9345
|
+
}
|
|
9234
9346
|
return linkable(hover.link, {
|
|
9235
9347
|
element: svg,
|
|
9236
9348
|
async update(next) {
|
|
@@ -9245,7 +9357,7 @@ function lineChart$1(target, options, env) {
|
|
|
9245
9357
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
9246
9358
|
const nextLayout = layout(merged, swapped);
|
|
9247
9359
|
const nextTable = tableFor(merged, nextLayout);
|
|
9248
|
-
const nextNames = namesFor(merged, nextLayout);
|
|
9360
|
+
const nextNames = kind === "x" ? namesFor(merged, nextLayout) : void 0;
|
|
9249
9361
|
const nextPointNames = kind === "point" ? pointNamesFor(merged, nextLayout) : void 0;
|
|
9250
9362
|
if ("colors" in next) colors = toColorAssignment(merged.colors);
|
|
9251
9363
|
const previous = current;
|
|
@@ -9300,20 +9412,40 @@ function lineChart$1(target, options, env) {
|
|
|
9300
9412
|
on: events.on,
|
|
9301
9413
|
marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
|
|
9302
9414
|
focus(key) {
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
if (hoverKind === "x") {
|
|
9306
|
-
const record = row ?? points.get(key)?.row;
|
|
9307
|
-
if (record) hover.focus(record.key);
|
|
9308
|
-
return;
|
|
9309
|
-
}
|
|
9310
|
-
const point = points.get(key) ?? (row && livePoints(row)[0]);
|
|
9311
|
-
if (point) hover.focus(point.key);
|
|
9415
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
9416
|
+
if (stop !== void 0) hover.focus(stop);
|
|
9312
9417
|
},
|
|
9313
9418
|
leave() {
|
|
9314
9419
|
if (!destroyed) hover.leave();
|
|
9315
9420
|
},
|
|
9316
9421
|
labels: () => lineOrder.flatMap((line) => chartLabel(line.key, "value", line.drawnLabel, line.label)),
|
|
9422
|
+
paintOf(key) {
|
|
9423
|
+
const line = lines.get(key);
|
|
9424
|
+
if (line) return {
|
|
9425
|
+
color: line.series,
|
|
9426
|
+
drawn: true,
|
|
9427
|
+
...line.end.getAttribute("visibility") === "hidden" ? {} : {
|
|
9428
|
+
end: DOT_RADIUS,
|
|
9429
|
+
ring: DOT_RING
|
|
9430
|
+
}
|
|
9431
|
+
};
|
|
9432
|
+
const point = points.get(key);
|
|
9433
|
+
return point && (point.group.classList.contains("ec-alone") ? {
|
|
9434
|
+
color: point.series,
|
|
9435
|
+
drawn: true,
|
|
9436
|
+
ring: DOT_RING
|
|
9437
|
+
} : {
|
|
9438
|
+
color: point.series,
|
|
9439
|
+
drawn: false
|
|
9440
|
+
});
|
|
9441
|
+
},
|
|
9442
|
+
standsFor(key) {
|
|
9443
|
+
return rows.has(key) ? [...laidOut.series.map((series) => pointKey(series, key)), key] : [key];
|
|
9444
|
+
},
|
|
9445
|
+
moveTabStop(key) {
|
|
9446
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
9447
|
+
return stop !== void 0 && hover.moveTabStop(stop);
|
|
9448
|
+
},
|
|
9317
9449
|
destroy() {
|
|
9318
9450
|
if (destroyed) return;
|
|
9319
9451
|
destroyed = true;
|
|
@@ -9388,6 +9520,36 @@ function sameData(a, b) {
|
|
|
9388
9520
|
function sameAt(a, b) {
|
|
9389
9521
|
return a === b || a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
|
|
9390
9522
|
}
|
|
9523
|
+
function apart(a, b) {
|
|
9524
|
+
return (a.x - b.x) ** 2 + (a.y - b.y) ** 2;
|
|
9525
|
+
}
|
|
9526
|
+
function strokeNear({ geometry, data: { samples } }, x, from, at, reach) {
|
|
9527
|
+
const i = samples.findIndex((sample) => sameAt(sample.at, x));
|
|
9528
|
+
if (i < 0 || !(geometry.length > 0)) return void 0;
|
|
9529
|
+
const t = samples[i].t;
|
|
9530
|
+
const span = reach / geometry.length;
|
|
9531
|
+
let near;
|
|
9532
|
+
for (const way of [-1, 1]) {
|
|
9533
|
+
let a = from;
|
|
9534
|
+
for (let j = i;; j += way) {
|
|
9535
|
+
const next = samples[j + way];
|
|
9536
|
+
if (!next || (way > 0 ? next : samples[j]).gapBefore) break;
|
|
9537
|
+
const to = way > 0 ? Math.min(next.t, t + span) : Math.max(next.t, t - span);
|
|
9538
|
+
const b = geometry.path(to);
|
|
9539
|
+
near = Math.min(near ?? Infinity, toSegment(at, a, b));
|
|
9540
|
+
if (to !== next.t) break;
|
|
9541
|
+
a = b;
|
|
9542
|
+
}
|
|
9543
|
+
}
|
|
9544
|
+
return near;
|
|
9545
|
+
}
|
|
9546
|
+
function toSegment(p, a, b) {
|
|
9547
|
+
const dx = b.x - a.x;
|
|
9548
|
+
const dy = b.y - a.y;
|
|
9549
|
+
const length = dx * dx + dy * dy;
|
|
9550
|
+
const u = length > 0 ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / length)) : 0;
|
|
9551
|
+
return Math.hypot(p.x - a.x - u * dx, p.y - a.y - u * dy);
|
|
9552
|
+
}
|
|
9391
9553
|
function labelled(values, options) {
|
|
9392
9554
|
return present(values).map((v) => ({
|
|
9393
9555
|
series: v.series,
|
|
@@ -9459,10 +9621,10 @@ function hoverOf(options) {
|
|
|
9459
9621
|
// src/core/geometry/ring.ts
|
|
9460
9622
|
const ROUND = .5;
|
|
9461
9623
|
function goesRound(mark) {
|
|
9462
|
-
const radius = distance$
|
|
9463
|
-
return radius > ROUND && Math.abs(distance$
|
|
9624
|
+
const radius = distance$2(mark.start, mark.pivot);
|
|
9625
|
+
return radius > ROUND && Math.abs(distance$2(mark.center, mark.pivot) - radius) <= ROUND && Math.abs(distance$2(mark.end, mark.pivot) - radius) <= ROUND;
|
|
9464
9626
|
}
|
|
9465
|
-
const distance$
|
|
9627
|
+
const distance$2 = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
|
|
9466
9628
|
// src/charts/adapter/bars.ts
|
|
9467
9629
|
const SAME = .5;
|
|
9468
9630
|
const BASELINES = [
|
|
@@ -9511,10 +9673,10 @@ function describeRects(key, parts, baseline) {
|
|
|
9511
9673
|
...box,
|
|
9512
9674
|
baseline,
|
|
9513
9675
|
radius: tip.radius,
|
|
9514
|
-
gap: Number.isFinite(gap) ? Math.max(0, round$
|
|
9676
|
+
gap: Number.isFinite(gap) ? Math.max(0, round$4(gap)) : 0,
|
|
9515
9677
|
...segments.every((s) => s.series !== void 0) ? { segments: segments.map((s) => ({
|
|
9516
9678
|
series: s.series,
|
|
9517
|
-
size: round$
|
|
9679
|
+
size: round$4(s.size)
|
|
9518
9680
|
})) } : {}
|
|
9519
9681
|
}),
|
|
9520
9682
|
order: order.map((o) => o.index)
|
|
@@ -9532,8 +9694,8 @@ function union(boxes) {
|
|
|
9532
9694
|
return {
|
|
9533
9695
|
x,
|
|
9534
9696
|
y,
|
|
9535
|
-
width: round$
|
|
9536
|
-
height: round$
|
|
9697
|
+
width: round$4(Math.max(...boxes.map((b) => b.x + b.width)) - x),
|
|
9698
|
+
height: round$4(Math.max(...boxes.map((b) => b.y + b.height)) - y)
|
|
9537
9699
|
};
|
|
9538
9700
|
}
|
|
9539
9701
|
function commonLine(boxes, nearEdge, farEdge, near, far) {
|
|
@@ -9574,7 +9736,7 @@ function spanFrom(mark, baseline) {
|
|
|
9574
9736
|
});
|
|
9575
9737
|
}
|
|
9576
9738
|
}
|
|
9577
|
-
function round$
|
|
9739
|
+
function round$4(value) {
|
|
9578
9740
|
return Math.round(value * 1e3) / 1e3;
|
|
9579
9741
|
}
|
|
9580
9742
|
// src/charts/adapter/edits.ts
|
|
@@ -9726,7 +9888,7 @@ function keepsCircles(m) {
|
|
|
9726
9888
|
const tiny = 1e-4 * Math.max(u, v);
|
|
9727
9889
|
return Math.abs(u - v) <= tiny && Math.abs(a * c + b * d) <= tiny;
|
|
9728
9890
|
}
|
|
9729
|
-
function scaleOf$
|
|
9891
|
+
function scaleOf$2(m) {
|
|
9730
9892
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
9731
9893
|
}
|
|
9732
9894
|
function boxIn(m, rect) {
|
|
@@ -9750,13 +9912,13 @@ function boxIn(m, rect) {
|
|
|
9750
9912
|
].map((corner) => matrix.apply(m, corner));
|
|
9751
9913
|
const xs = corners.map((p) => p.x);
|
|
9752
9914
|
const ys = corners.map((p) => p.y);
|
|
9753
|
-
const x = round$
|
|
9754
|
-
const y = round$
|
|
9915
|
+
const x = round$3(Math.min(...xs));
|
|
9916
|
+
const y = round$3(Math.min(...ys));
|
|
9755
9917
|
return {
|
|
9756
9918
|
x,
|
|
9757
9919
|
y,
|
|
9758
|
-
width: round$
|
|
9759
|
-
height: round$
|
|
9920
|
+
width: round$3(round$3(Math.max(...xs)) - x),
|
|
9921
|
+
height: round$3(round$3(Math.max(...ys)) - y)
|
|
9760
9922
|
};
|
|
9761
9923
|
}
|
|
9762
9924
|
function rectOf(element) {
|
|
@@ -9774,6 +9936,7 @@ function rectOf(element) {
|
|
|
9774
9936
|
}
|
|
9775
9937
|
function attributesOf(element) {
|
|
9776
9938
|
return (name) => {
|
|
9939
|
+
if (!element.hasAttribute(name)) return null;
|
|
9777
9940
|
const animated = element[name];
|
|
9778
9941
|
return typeof animated?.baseVal?.value === "number" ? String(animated.baseVal.value) : element.getAttribute(name);
|
|
9779
9942
|
};
|
|
@@ -9801,7 +9964,7 @@ function fromRoot(element, root) {
|
|
|
9801
9964
|
for (let node = element; node && node !== root; node = node.parentElement) m = matrix.multiply(ownTransform(node), m);
|
|
9802
9965
|
return m;
|
|
9803
9966
|
}
|
|
9804
|
-
function round$
|
|
9967
|
+
function round$3(value) {
|
|
9805
9968
|
return Math.round(value * 1e3) / 1e3;
|
|
9806
9969
|
}
|
|
9807
9970
|
// src/charts/adapter/host-style.ts
|
|
@@ -9853,9 +10016,9 @@ function hostMarkHandle(parts, edits, halos) {
|
|
|
9853
10016
|
};
|
|
9854
10017
|
}
|
|
9855
10018
|
function hostColors(element, root) {
|
|
9856
|
-
const fill = paintOf(element, root, "fill");
|
|
10019
|
+
const fill = paintOf$1(element, root, "fill");
|
|
9857
10020
|
const paint = fill === NONE ? "stroke" : "fill";
|
|
9858
|
-
const color = paint === "fill" ? fill : paintOf(element, root, "stroke");
|
|
10021
|
+
const color = paint === "fill" ? fill : paintOf$1(element, root, "stroke");
|
|
9859
10022
|
if (color === void 0 || color === NONE) return void 0;
|
|
9860
10023
|
return {
|
|
9861
10024
|
color,
|
|
@@ -9880,7 +10043,7 @@ function attributesComputed(root) {
|
|
|
9880
10043
|
probed.set(root, computed);
|
|
9881
10044
|
return computed;
|
|
9882
10045
|
}
|
|
9883
|
-
function paintOf(element, root, property) {
|
|
10046
|
+
function paintOf$1(element, root, property) {
|
|
9884
10047
|
const raw = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue(property);
|
|
9885
10048
|
const computed = kind(raw);
|
|
9886
10049
|
if (raw && attributesComputed(root)) return computed;
|
|
@@ -9893,15 +10056,28 @@ function paintOf(element, root, property) {
|
|
|
9893
10056
|
return computed !== void 0 && !(initial && declared !== void 0) ? computed : kind(declared);
|
|
9894
10057
|
}
|
|
9895
10058
|
function strokeWidthOf(element, root) {
|
|
9896
|
-
const
|
|
10059
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle?.(element);
|
|
10060
|
+
const raw = style?.getPropertyValue("stroke-width");
|
|
9897
10061
|
const computed = pixels$1(raw);
|
|
9898
|
-
|
|
10062
|
+
const effect = style?.getPropertyValue("vector-effect").trim().toLowerCase();
|
|
10063
|
+
const declared = element.style?.getPropertyValue("vector-effect") ? effect : element.getAttribute("vector-effect")?.trim().toLowerCase();
|
|
10064
|
+
const screen = (effect && (effect !== "none" || attributesComputed(root)) ? effect : declared) === "non-scaling-stroke";
|
|
10065
|
+
if (raw && attributesComputed(root) || computed !== void 0 && computed !== 1) return {
|
|
10066
|
+
width: computed,
|
|
10067
|
+
screen
|
|
10068
|
+
};
|
|
9899
10069
|
for (let node = element; node; node = node === root ? null : node.parentElement) {
|
|
9900
10070
|
if (node.style?.getPropertyValue("stroke-width")) break;
|
|
9901
10071
|
const width = pixels$1(node.getAttribute("stroke-width"));
|
|
9902
|
-
if (width !== void 0) return
|
|
10072
|
+
if (width !== void 0) return {
|
|
10073
|
+
width,
|
|
10074
|
+
screen
|
|
10075
|
+
};
|
|
9903
10076
|
}
|
|
9904
|
-
return
|
|
10077
|
+
return {
|
|
10078
|
+
width: computed,
|
|
10079
|
+
screen
|
|
10080
|
+
};
|
|
9905
10081
|
}
|
|
9906
10082
|
function pixels$1(value) {
|
|
9907
10083
|
const match = /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)\s*(?:px\s*)?$/i.exec(value ?? "");
|
|
@@ -9923,6 +10099,183 @@ function mix$2(colors, emphasis) {
|
|
|
9923
10099
|
function cssMatrix(m) {
|
|
9924
10100
|
return `matrix(${m.map((v, i) => i < 4 ? Math.round(v * 1e6) / 1e6 : Math.round(v * 1e3) / 1e3).join(", ")})`;
|
|
9925
10101
|
}
|
|
10102
|
+
// src/charts/adapter/slice.ts
|
|
10103
|
+
const NEAR = .5;
|
|
10104
|
+
const MOST = 32;
|
|
10105
|
+
function sliceOf$1(commands, m) {
|
|
10106
|
+
const scale = scaleOf$2(m);
|
|
10107
|
+
if (!keepsCircles(m) || !(scale > 0) || commands.length > MOST || commands.some((command) => command.op === "C" || command.op === "Q")) return void 0;
|
|
10108
|
+
const near = NEAR / scale;
|
|
10109
|
+
const subpaths = flattenPath(commands);
|
|
10110
|
+
if (subpaths.length === 0 || subpaths.length > 2 || !subpaths.every(closes)) return void 0;
|
|
10111
|
+
const runs = subpaths.map((subpath) => runsOf(subpath.segments, near));
|
|
10112
|
+
const own = subpaths.length === 2 ? ring(runs[0], runs[1], near) : slice(runs[0], near);
|
|
10113
|
+
return own && moved(own, m);
|
|
10114
|
+
}
|
|
10115
|
+
function ring(a, b, near) {
|
|
10116
|
+
const [first, second] = [a[0], b[0]];
|
|
10117
|
+
if (a.length !== 1 || b.length !== 1 || first?.kind !== "arc" || second?.kind !== "arc") return void 0;
|
|
10118
|
+
const [outer, inner] = first.radius >= second.radius ? [first, second] : [second, first];
|
|
10119
|
+
const whole = (turn, radius) => Math.abs(Math.abs(turn) - TAU$2) * radius <= near;
|
|
10120
|
+
for (const center of [centerOf(outer), outer.arcs[0].center]) {
|
|
10121
|
+
if (!center) continue;
|
|
10122
|
+
const [r1, r0] = [distance$1(outer.from, center), distance$1(inner.from, center)];
|
|
10123
|
+
const [t1, t0] = [turnOf(outer, center), turnOf(inner, center)];
|
|
10124
|
+
if (r1 > near && r1 - r0 > near && Math.sign(t1) !== Math.sign(t0) && whole(t1, r1) && whole(t0, r0) && onCircle(outer, center, r1, near) && onCircle(inner, center, r0, near)) return {
|
|
10125
|
+
center,
|
|
10126
|
+
inner: r0,
|
|
10127
|
+
outer: r1,
|
|
10128
|
+
start: angleOf(outer.from, center),
|
|
10129
|
+
sweep: Math.sign(t1) * TAU$2
|
|
10130
|
+
};
|
|
10131
|
+
}
|
|
10132
|
+
}
|
|
10133
|
+
function slice(runs, near) {
|
|
10134
|
+
let first = -1;
|
|
10135
|
+
runs.forEach((run, i) => {
|
|
10136
|
+
if (run.kind === "arc" && (first < 0 || run.radius > runs[first].radius)) first = i;
|
|
10137
|
+
});
|
|
10138
|
+
if (first < 0) return void 0;
|
|
10139
|
+
const cycle = [...runs.slice(first), ...runs.slice(0, first)];
|
|
10140
|
+
const outer = cycle[0];
|
|
10141
|
+
const [, side, third, fourth] = cycle;
|
|
10142
|
+
const pie = cycle.length === 3 && side?.kind === "line" && third?.kind === "line";
|
|
10143
|
+
const back = cycle.length === 4 && side?.kind === "line" && third?.kind === "arc" && fourth?.kind === "line" ? third : void 0;
|
|
10144
|
+
if (!pie && !back) return void 0;
|
|
10145
|
+
const [inEnd, inStart] = back ? [back.from, back.to] : [side.to, side.to];
|
|
10146
|
+
const toward = (from, to) => {
|
|
10147
|
+
const length = distance$1(from, to);
|
|
10148
|
+
return length > near ? {
|
|
10149
|
+
x: from.x + (to.x - from.x) * outer.radius / length,
|
|
10150
|
+
y: from.y + (to.y - from.y) * outer.radius / length
|
|
10151
|
+
} : void 0;
|
|
10152
|
+
};
|
|
10153
|
+
const a = toward(outer.from, inStart);
|
|
10154
|
+
const b = toward(outer.to, inEnd);
|
|
10155
|
+
if (!a || !b) return void 0;
|
|
10156
|
+
let center = {
|
|
10157
|
+
x: (a.x + b.x) / 2,
|
|
10158
|
+
y: (a.y + b.y) / 2
|
|
10159
|
+
};
|
|
10160
|
+
if (pie && distance$1(inEnd, center) <= near) center = inEnd;
|
|
10161
|
+
const inner = center === inEnd ? 0 : (distance$1(inEnd, center) + distance$1(inStart, center)) / 2;
|
|
10162
|
+
const sweep = turnOf(outer, center);
|
|
10163
|
+
if (sweep === 0) return void 0;
|
|
10164
|
+
const own = {
|
|
10165
|
+
center,
|
|
10166
|
+
inner,
|
|
10167
|
+
outer: (distance$1(outer.from, center) + distance$1(outer.to, center)) / 2,
|
|
10168
|
+
start: angleOf(outer.from, center),
|
|
10169
|
+
sweep
|
|
10170
|
+
};
|
|
10171
|
+
return checked(own, outer, back, [inEnd, inStart], near) ? own : void 0;
|
|
10172
|
+
}
|
|
10173
|
+
function checked(own, outer, back, [inEnd, inStart], near) {
|
|
10174
|
+
const { center, start, sweep } = own;
|
|
10175
|
+
const at = (radius, angle) => ({
|
|
10176
|
+
x: center.x + radius * Math.cos(angle),
|
|
10177
|
+
y: center.y + radius * Math.sin(angle)
|
|
10178
|
+
});
|
|
10179
|
+
return own.outer > near && own.outer - own.inner > near && distance$1(outer.from, at(own.outer, start)) <= near && distance$1(outer.to, at(own.outer, start + sweep)) <= near && onCircle(outer, center, own.outer, near) && distance$1(inEnd, at(own.inner, start + sweep)) <= near && distance$1(inStart, at(own.inner, start)) <= near && (!back || Math.abs(turnOf(back, center) + sweep) * own.inner <= near && onCircle(back, center, own.inner, near));
|
|
10180
|
+
}
|
|
10181
|
+
function turnOf(run, center) {
|
|
10182
|
+
let turn = 0;
|
|
10183
|
+
for (const arc of run.arcs) {
|
|
10184
|
+
const step = normalizeAngle(angleOf(pointOn(arc, 1), center) - angleOf(pointOn(arc, 0), center));
|
|
10185
|
+
turn += step + TAU$2 * Math.round((arc.sweep - step) / TAU$2);
|
|
10186
|
+
}
|
|
10187
|
+
return turn;
|
|
10188
|
+
}
|
|
10189
|
+
function centerOf(run) {
|
|
10190
|
+
const points = [run.from, ...run.arcs.slice(0, -1).map((arc) => pointOn(arc, 1))];
|
|
10191
|
+
if (points.length < 2) return void 0;
|
|
10192
|
+
if (points.length === 2) return {
|
|
10193
|
+
x: (points[0].x + points[1].x) / 2,
|
|
10194
|
+
y: (points[0].y + points[1].y) / 2
|
|
10195
|
+
};
|
|
10196
|
+
const [p, q, r] = [
|
|
10197
|
+
points[0],
|
|
10198
|
+
points[Math.floor(points.length / 3)],
|
|
10199
|
+
points[Math.floor(2 * points.length / 3)]
|
|
10200
|
+
];
|
|
10201
|
+
const d = 2 * (p.x * (q.y - r.y) + q.x * (r.y - p.y) + r.x * (p.y - q.y));
|
|
10202
|
+
if (!(Math.abs(d) > 0)) return void 0;
|
|
10203
|
+
const [pp, qq, rr] = [
|
|
10204
|
+
p,
|
|
10205
|
+
q,
|
|
10206
|
+
r
|
|
10207
|
+
].map(({ x, y }) => x * x + y * y);
|
|
10208
|
+
return {
|
|
10209
|
+
x: (pp * (q.y - r.y) + qq * (r.y - p.y) + rr * (p.y - q.y)) / d,
|
|
10210
|
+
y: (pp * (r.x - q.x) + qq * (p.x - r.x) + rr * (q.x - p.x)) / d
|
|
10211
|
+
};
|
|
10212
|
+
}
|
|
10213
|
+
const onCircle = (run, center, radius, near) => Math.abs(run.radius - radius) <= near && run.arcs.every((arc) => [
|
|
10214
|
+
0,
|
|
10215
|
+
.5,
|
|
10216
|
+
1
|
|
10217
|
+
].every((u) => Math.abs(distance$1(pointOn(arc, u), center) - radius) <= near));
|
|
10218
|
+
function moved(own, m) {
|
|
10219
|
+
const scale = scaleOf$2(m);
|
|
10220
|
+
const center = matrix.apply(m, own.center);
|
|
10221
|
+
const corner = matrix.apply(m, {
|
|
10222
|
+
x: own.center.x + own.outer * Math.cos(own.start),
|
|
10223
|
+
y: own.center.y + own.outer * Math.sin(own.start)
|
|
10224
|
+
});
|
|
10225
|
+
const sweep = m[0] * m[3] - m[1] * m[2] < 0 ? -own.sweep : own.sweep;
|
|
10226
|
+
let start = ((angleOf(corner, center) + Math.PI / 2) % TAU$2 + TAU$2) % TAU$2;
|
|
10227
|
+
if (start > TAU$2 - 1e-9) start = 0;
|
|
10228
|
+
return {
|
|
10229
|
+
cx: round$2(center.x),
|
|
10230
|
+
cy: round$2(center.y),
|
|
10231
|
+
inner: round$2(own.inner * scale),
|
|
10232
|
+
outer: round$2(own.outer * scale),
|
|
10233
|
+
start,
|
|
10234
|
+
end: start + sweep
|
|
10235
|
+
};
|
|
10236
|
+
}
|
|
10237
|
+
function runsOf(segments, near) {
|
|
10238
|
+
const runs = [];
|
|
10239
|
+
const join = (run, arc) => run !== void 0 && Math.sign(run.sweep) === Math.sign(arc.sweep) && Math.abs(run.radius - arc.radius) <= near;
|
|
10240
|
+
for (const segment of segments) {
|
|
10241
|
+
const last = runs[runs.length - 1];
|
|
10242
|
+
if (segment.kind === "line") runs.push({
|
|
10243
|
+
kind: "line",
|
|
10244
|
+
from: segment.from,
|
|
10245
|
+
to: segment.to
|
|
10246
|
+
});
|
|
10247
|
+
else if (last?.kind === "arc" && join(last, segment)) runs[runs.length - 1] = {
|
|
10248
|
+
...last,
|
|
10249
|
+
arcs: [...last.arcs, segment],
|
|
10250
|
+
to: pointOn(segment, 1),
|
|
10251
|
+
sweep: last.sweep + segment.sweep
|
|
10252
|
+
};
|
|
10253
|
+
else runs.push({
|
|
10254
|
+
kind: "arc",
|
|
10255
|
+
arcs: [segment],
|
|
10256
|
+
from: pointOn(segment, 0),
|
|
10257
|
+
to: pointOn(segment, 1),
|
|
10258
|
+
radius: segment.radius,
|
|
10259
|
+
sweep: segment.sweep
|
|
10260
|
+
});
|
|
10261
|
+
}
|
|
10262
|
+
const [head] = runs;
|
|
10263
|
+
const tail = runs[runs.length - 1];
|
|
10264
|
+
if (runs.length > 1 && head?.kind === "arc" && tail?.kind === "arc" && tail.arcs.every((arc) => join(head, arc))) {
|
|
10265
|
+
runs[0] = {
|
|
10266
|
+
...head,
|
|
10267
|
+
arcs: [...tail.arcs, ...head.arcs],
|
|
10268
|
+
from: tail.from,
|
|
10269
|
+
sweep: tail.sweep + head.sweep
|
|
10270
|
+
};
|
|
10271
|
+
runs.pop();
|
|
10272
|
+
}
|
|
10273
|
+
return runs;
|
|
10274
|
+
}
|
|
10275
|
+
const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
|
|
10276
|
+
const angleOf = (point, center) => Math.atan2(point.y - center.y, point.x - center.x);
|
|
10277
|
+
const distance$1 = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
|
|
10278
|
+
const round$2 = (value) => Math.round(value * 1e3) / 1e3 + 0;
|
|
9926
10279
|
// src/charts/adapter/source.ts
|
|
9927
10280
|
function readSource(source) {
|
|
9928
10281
|
if (typeof source === "string") {
|
|
@@ -10084,7 +10437,7 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
|
|
|
10084
10437
|
"graphics-object"
|
|
10085
10438
|
]);
|
|
10086
10439
|
function expressive$1(target, options, env) {
|
|
10087
|
-
checkOptions$
|
|
10440
|
+
checkOptions$12(options);
|
|
10088
10441
|
const motion = chartMotion(options.motion, env.motion);
|
|
10089
10442
|
let effects = resolveEffects(options.on, env.presets);
|
|
10090
10443
|
let given = options.on;
|
|
@@ -10132,7 +10485,7 @@ function expressive$1(target, options, env) {
|
|
|
10132
10485
|
common,
|
|
10133
10486
|
screen: screenMatrices(),
|
|
10134
10487
|
colors: (element) => colorsOf(element, svg),
|
|
10135
|
-
|
|
10488
|
+
stroke: (element) => strokeWidthOf(element, svg)
|
|
10136
10489
|
};
|
|
10137
10490
|
const named = (mark) => ({
|
|
10138
10491
|
...mark,
|
|
@@ -10148,7 +10501,7 @@ function expressive$1(target, options, env) {
|
|
|
10148
10501
|
const shapes = [];
|
|
10149
10502
|
keys.forEach((key, index) => {
|
|
10150
10503
|
const pieces = groups.get(key);
|
|
10151
|
-
if (pieces[0].element.localName === "rect") bars.push(index);
|
|
10504
|
+
if (pieces[0].element.localName === "rect" && !turned(pieces, at)) bars.push(index);
|
|
10152
10505
|
else {
|
|
10153
10506
|
const mark = shapeMark(key, pieces[0], index, at);
|
|
10154
10507
|
if (mark) shapes.push(mark);
|
|
@@ -10175,9 +10528,12 @@ function expressive$1(target, options, env) {
|
|
|
10175
10528
|
index
|
|
10176
10529
|
};
|
|
10177
10530
|
}
|
|
10531
|
+
function turned(pieces, at) {
|
|
10532
|
+
return pieces.length === 1 && !axisAligned(transformOf(pieces[0].element, at));
|
|
10533
|
+
}
|
|
10178
10534
|
function rectPiece(key, piece, at) {
|
|
10179
10535
|
const m = transformOf(piece.element, at);
|
|
10180
|
-
if (!axisAligned(m)) throw new TypeError(`expressive: the <rect> of "${key}" is rotated or skewed, so it isn't an upright bar.
|
|
10536
|
+
if (!axisAligned(m)) throw new TypeError(`expressive: the <rect> of "${key}" is rotated or skewed, so it isn't an upright bar's segment. A rect turned on its own is a shape, a mark of its own: give each its own key, or describe the bar with the geometry option.`);
|
|
10181
10537
|
return {
|
|
10182
10538
|
...piece,
|
|
10183
10539
|
rect: {
|
|
@@ -10215,7 +10571,7 @@ function expressive$1(target, options, env) {
|
|
|
10215
10571
|
};
|
|
10216
10572
|
const r = tag === "circle" ? length("r") : 0;
|
|
10217
10573
|
let geometry;
|
|
10218
|
-
let
|
|
10574
|
+
let stroke;
|
|
10219
10575
|
if (tag === "circle" && (keepsCircles(m) || !(r > 0))) {
|
|
10220
10576
|
const center = matrix.apply(m, {
|
|
10221
10577
|
x: length("cx"),
|
|
@@ -10226,24 +10582,32 @@ function expressive$1(target, options, env) {
|
|
|
10226
10582
|
series,
|
|
10227
10583
|
x: round$1(center.x),
|
|
10228
10584
|
y: round$1(center.y),
|
|
10229
|
-
r: round$1(Math.max(0, r) * scaleOf$
|
|
10585
|
+
r: round$1(Math.max(0, r) * scaleOf$2(m))
|
|
10230
10586
|
});
|
|
10231
10587
|
} else {
|
|
10232
10588
|
const commands = shapeOutline(tag, attribute);
|
|
10233
10589
|
if (commands[0]?.op !== "M" || commands.every((command) => command.op === "M")) return void 0;
|
|
10234
|
-
|
|
10235
|
-
const
|
|
10236
|
-
geometry =
|
|
10590
|
+
stroke = tag === "circle" ? void 0 : at.stroke(element);
|
|
10591
|
+
const slice = tag === "path" ? sliceOf$1(commands, m) : void 0;
|
|
10592
|
+
if (slice) geometry = describeArc({
|
|
10237
10593
|
key,
|
|
10238
10594
|
series,
|
|
10239
|
-
|
|
10240
|
-
matrix: m,
|
|
10241
|
-
width: width > 0 ? width : 1
|
|
10595
|
+
...slice
|
|
10242
10596
|
});
|
|
10597
|
+
else {
|
|
10598
|
+
const width = round$1(widthOf(stroke, m, at));
|
|
10599
|
+
geometry = describeShape({
|
|
10600
|
+
key,
|
|
10601
|
+
series,
|
|
10602
|
+
d: tag === "path" ? attribute("d") ?? "" : formatPath(commands),
|
|
10603
|
+
matrix: m,
|
|
10604
|
+
width: width > 0 ? width : 1
|
|
10605
|
+
});
|
|
10606
|
+
}
|
|
10243
10607
|
}
|
|
10244
10608
|
const parts = [{
|
|
10245
10609
|
...part(piece, outlineOf(geometry, series, 1), at),
|
|
10246
|
-
|
|
10610
|
+
stroke
|
|
10247
10611
|
}];
|
|
10248
10612
|
return {
|
|
10249
10613
|
key,
|
|
@@ -10253,6 +10617,13 @@ function expressive$1(target, options, env) {
|
|
|
10253
10617
|
...tag === "circle" ? { circle: true } : {}
|
|
10254
10618
|
};
|
|
10255
10619
|
}
|
|
10620
|
+
function widthOf(stroke, m, at) {
|
|
10621
|
+
const width = stroke?.width ?? 1;
|
|
10622
|
+
if (!stroke?.screen) return width * scaleOf$2(m);
|
|
10623
|
+
const screen = at.screen(at.common);
|
|
10624
|
+
const scale = screen ? scaleOf$2(screen) : 0;
|
|
10625
|
+
return scale > 0 ? width / scale : width;
|
|
10626
|
+
}
|
|
10256
10627
|
function transformOf(element, at) {
|
|
10257
10628
|
return matrix.multiply(between$1(at.common, element.parentElement ?? at.svg, at.svg, at.screen), ownTransform(element));
|
|
10258
10629
|
}
|
|
@@ -10399,7 +10770,7 @@ function expressive$1(target, options, env) {
|
|
|
10399
10770
|
set: (style) => find(key)?.handle.set(style),
|
|
10400
10771
|
reset: () => find(key)?.handle.reset()
|
|
10401
10772
|
}),
|
|
10402
|
-
colors: (key) => find(key)?.mark
|
|
10773
|
+
colors: (key, part) => partOf(find(key)?.mark, part)?.colors
|
|
10403
10774
|
});
|
|
10404
10775
|
const runner = createRunner({
|
|
10405
10776
|
effects,
|
|
@@ -10707,9 +11078,17 @@ function expressive$1(target, options, env) {
|
|
|
10707
11078
|
let overlayMoved = false;
|
|
10708
11079
|
for (const element of changes.ancestors) if (element.contains(ancestor)) overlayMoved = true;
|
|
10709
11080
|
else for (const record of order) if (record.mark.parts.some((part) => element.contains(part.element))) changed.add(record);
|
|
10710
|
-
|
|
10711
|
-
if (
|
|
10712
|
-
|
|
11081
|
+
const rescaled = /* @__PURE__ */ new Set();
|
|
11082
|
+
if (overlayMoved) {
|
|
11083
|
+
placeOverlay();
|
|
11084
|
+
for (const record of order) if (!changed.has(record) && record.mark.parts.some((part) => part.stroke?.screen)) rescaled.add(record);
|
|
11085
|
+
}
|
|
11086
|
+
if (changed.size === 0 && rescaled.size === 0) return;
|
|
11087
|
+
const read = reread([...changed, ...rescaled]);
|
|
11088
|
+
const kept = read.records.flatMap((record, i) => rescaled.has(record) && !geometryChanged(record.mark.geometry, read.marks[i].geometry) ? [] : [i]);
|
|
11089
|
+
if (kept.length === 0) return;
|
|
11090
|
+
const records = kept.map((i) => read.records[i]);
|
|
11091
|
+
const marks = kept.map((i) => read.marks[i]);
|
|
10713
11092
|
records.forEach((record, i) => {
|
|
10714
11093
|
const mark = marks[i];
|
|
10715
11094
|
record.mark = mark;
|
|
@@ -10731,7 +11110,7 @@ function expressive$1(target, options, env) {
|
|
|
10731
11110
|
common: ancestor,
|
|
10732
11111
|
screen: screenMatrices(),
|
|
10733
11112
|
colors: (element) => owners.get(element)?.part.colors,
|
|
10734
|
-
|
|
11113
|
+
stroke: (element) => owners.get(element)?.part.stroke
|
|
10735
11114
|
};
|
|
10736
11115
|
const rowOf = rowsNow();
|
|
10737
11116
|
const piecesOf = ({ parts }) => parts.map((part) => ({
|
|
@@ -10750,16 +11129,17 @@ function expressive$1(target, options, env) {
|
|
|
10750
11129
|
marks: withData(marks)
|
|
10751
11130
|
};
|
|
10752
11131
|
}
|
|
10753
|
-
const
|
|
10754
|
-
const
|
|
10755
|
-
|
|
11132
|
+
const shapes = new Set(changed.filter((record) => !record.mark.rect || turned(record.mark.parts, at)));
|
|
11133
|
+
const rects = new Map(changed.flatMap((record) => shapes.has(record) ? [] : [[record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at))]]));
|
|
11134
|
+
const edges = edgesNow(rects, shapes);
|
|
11135
|
+
for (const record of order) if (record.mark.rect && !rects.has(record) && !shapes.has(record) && edges.get(record) !== record.mark.rect.edge) rects.set(record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at)));
|
|
10756
11136
|
const records = [...rects.keys()];
|
|
10757
11137
|
const marks = records.map((record) => ({
|
|
10758
11138
|
...rectMark(record.key, rects.get(record), edges.get(record), record.mark.index, at),
|
|
10759
11139
|
label: record.mark.label
|
|
10760
11140
|
}));
|
|
10761
11141
|
for (const record of changed) {
|
|
10762
|
-
if (record
|
|
11142
|
+
if (!shapes.has(record)) continue;
|
|
10763
11143
|
const mark = shapeMark(record.key, piecesOf(record.mark)[0], record.mark.index, at);
|
|
10764
11144
|
if (!mark) continue;
|
|
10765
11145
|
records.push(record);
|
|
@@ -10773,8 +11153,8 @@ function expressive$1(target, options, env) {
|
|
|
10773
11153
|
marks: withData(marks)
|
|
10774
11154
|
};
|
|
10775
11155
|
}
|
|
10776
|
-
function edgesNow(rects) {
|
|
10777
|
-
const bars = order.filter((record) => record.mark.rect);
|
|
11156
|
+
function edgesNow(rects, shapes) {
|
|
11157
|
+
const bars = order.filter((record) => record.mark.rect && !shapes.has(record));
|
|
10778
11158
|
const kept = new Map(bars.map((record) => [record, record.mark.rect.edge]));
|
|
10779
11159
|
if (options.baseline !== void 0 && options.baseline !== "auto") return kept;
|
|
10780
11160
|
const boxes = bars.map((record) => {
|
|
@@ -10933,7 +11313,7 @@ function expressive$1(target, options, env) {
|
|
|
10933
11313
|
}
|
|
10934
11314
|
});
|
|
10935
11315
|
}
|
|
10936
|
-
function checkOptions$
|
|
11316
|
+
function checkOptions$12(options) {
|
|
10937
11317
|
if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
|
|
10938
11318
|
if (typeof options.key !== "function") throw new TypeError("expressive needs a key function, for example key: (d) => d.name. Marks are matched by key.");
|
|
10939
11319
|
for (const name of [
|
|
@@ -10945,6 +11325,11 @@ function checkOptions$11(options) {
|
|
|
10945
11325
|
]) if (options[name] !== void 0 && typeof options[name] !== "function") throw new TypeError(`expressive: ${name} must be a function.`);
|
|
10946
11326
|
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)}.`);
|
|
10947
11327
|
}
|
|
11328
|
+
function partOf(mark, key) {
|
|
11329
|
+
if (key === void 0) return mark?.parts[0];
|
|
11330
|
+
const segment = mark?.geometry.segments?.find((s) => s.key === key);
|
|
11331
|
+
return segment && mark.parts.find((p) => p.series === segment.series);
|
|
11332
|
+
}
|
|
10948
11333
|
function ownSeries(mark) {
|
|
10949
11334
|
const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
|
|
10950
11335
|
return [...new Set(names.filter((name) => name !== void 0))];
|
|
@@ -11388,7 +11773,7 @@ function pointsOf(first) {
|
|
|
11388
11773
|
function lineOf(key, element, first, m) {
|
|
11389
11774
|
const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
|
|
11390
11775
|
if (!straight(first)) {
|
|
11391
|
-
const scaled = width * scaleOf(m);
|
|
11776
|
+
const scaled = width * scaleOf$1(m);
|
|
11392
11777
|
return describeShape({
|
|
11393
11778
|
key,
|
|
11394
11779
|
series: key,
|
|
@@ -11404,7 +11789,7 @@ function lineOf(key, element, first, m) {
|
|
|
11404
11789
|
series: key,
|
|
11405
11790
|
points: points.map(({ point }) => matrix.apply(m, point)),
|
|
11406
11791
|
...breaks.length > 0 ? { breaks } : {},
|
|
11407
|
-
width: (Number.isFinite(width) ? width : 1) * scaleOf(m)
|
|
11792
|
+
width: (Number.isFinite(width) ? width : 1) * scaleOf$1(m)
|
|
11408
11793
|
});
|
|
11409
11794
|
}
|
|
11410
11795
|
function sliceOf(key, item, m) {
|
|
@@ -11412,7 +11797,7 @@ function sliceOf(key, item, m) {
|
|
|
11412
11797
|
x: number(item.x),
|
|
11413
11798
|
y: number(item.y)
|
|
11414
11799
|
});
|
|
11415
|
-
const s = scaleOf(m);
|
|
11800
|
+
const s = scaleOf$1(m);
|
|
11416
11801
|
const [start, end] = [number(item.startAngle), number(item.endAngle)].sort((a, b) => a - b);
|
|
11417
11802
|
return describeArc({
|
|
11418
11803
|
key,
|
|
@@ -11433,7 +11818,7 @@ function pointOf(key, item, m) {
|
|
|
11433
11818
|
key,
|
|
11434
11819
|
x: center.x,
|
|
11435
11820
|
y: center.y,
|
|
11436
|
-
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf(m)
|
|
11821
|
+
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf$1(m)
|
|
11437
11822
|
});
|
|
11438
11823
|
}
|
|
11439
11824
|
function boxOf(item) {
|
|
@@ -11448,7 +11833,7 @@ function boxOf(item) {
|
|
|
11448
11833
|
height: Math.abs(height)
|
|
11449
11834
|
};
|
|
11450
11835
|
}
|
|
11451
|
-
function scaleOf(m) {
|
|
11836
|
+
function scaleOf$1(m) {
|
|
11452
11837
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
11453
11838
|
}
|
|
11454
11839
|
function number(value) {
|
|
@@ -11599,12 +11984,12 @@ function describeEffect(value) {
|
|
|
11599
11984
|
return kind === void 0 ? "an object with no kind" : `an effect of kind ${JSON.stringify(kind)}`;
|
|
11600
11985
|
}
|
|
11601
11986
|
// src/charts/switch.ts
|
|
11602
|
-
const DURATION$
|
|
11987
|
+
const DURATION$8 = 950;
|
|
11603
11988
|
const OUT_BY = .4;
|
|
11604
11989
|
const HALF = .5;
|
|
11605
11990
|
function chartSwitch$1(target, options, env) {
|
|
11606
11991
|
const host = resolveTarget$2(target, "chartSwitch");
|
|
11607
|
-
const names = checkOptions$
|
|
11992
|
+
const names = checkOptions$11(options);
|
|
11608
11993
|
const effect = options.transition;
|
|
11609
11994
|
const colors = toColorAssignment(options.colors);
|
|
11610
11995
|
const motion = env.motion;
|
|
@@ -11648,20 +12033,100 @@ function chartSwitch$1(target, options, env) {
|
|
|
11648
12033
|
const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
|
|
11649
12034
|
const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
|
|
11650
12035
|
const orders = /* @__PURE__ */ new WeakMap();
|
|
11651
|
-
const
|
|
12036
|
+
const surfaceFor = (paints, extras) => ({ group(key, order) {
|
|
11652
12037
|
const group = svgElement("g", {
|
|
11653
12038
|
class: "ec-run",
|
|
11654
12039
|
"data-key": key
|
|
11655
12040
|
}, runsLayer);
|
|
11656
|
-
setStyles(group, markColorStyles(seriesColors(colors.slot(key))));
|
|
12041
|
+
setStyles(group, markColorStyles(seriesColors(colors.slot(paints[order] ?? key))));
|
|
11657
12042
|
orders.set(group, order);
|
|
11658
12043
|
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
|
|
11659
12044
|
runsLayer.insertBefore(group, above ?? null);
|
|
12045
|
+
const layer = svgLayer(group);
|
|
11660
12046
|
return {
|
|
11661
|
-
...
|
|
12047
|
+
...extras[order]?.wrap(layer, group) ?? layer,
|
|
11662
12048
|
clear: () => group.remove()
|
|
11663
12049
|
};
|
|
11664
|
-
} };
|
|
12050
|
+
} });
|
|
12051
|
+
function extrasFor(rings, ends, dotColors) {
|
|
12052
|
+
const [ringA, ringB] = rings;
|
|
12053
|
+
const [endA, endB] = ends;
|
|
12054
|
+
if (ringA === 0 && ringB === 0 && !endA && !endB) return void 0;
|
|
12055
|
+
const dots = [];
|
|
12056
|
+
if (endA && endB) {
|
|
12057
|
+
const element = endDot();
|
|
12058
|
+
const draw = (s) => placeDot(element, {
|
|
12059
|
+
at: {
|
|
12060
|
+
x: mix$1(endA.at.x, endB.at.x, s),
|
|
12061
|
+
y: mix$1(endA.at.y, endB.at.y, s)
|
|
12062
|
+
},
|
|
12063
|
+
r: mix$1(endA.r, endB.r, s),
|
|
12064
|
+
ring: mix$1(endA.ring, endB.ring, s)
|
|
12065
|
+
});
|
|
12066
|
+
dots.push({
|
|
12067
|
+
element,
|
|
12068
|
+
draw
|
|
12069
|
+
});
|
|
12070
|
+
} else [[
|
|
12071
|
+
endA,
|
|
12072
|
+
fadeOut,
|
|
12073
|
+
dotColors[0]
|
|
12074
|
+
], [
|
|
12075
|
+
endB,
|
|
12076
|
+
fadeIn,
|
|
12077
|
+
dotColors[1]
|
|
12078
|
+
]].forEach(([end, opacity, color]) => {
|
|
12079
|
+
if (!end) return;
|
|
12080
|
+
const element = endDot();
|
|
12081
|
+
setStyles(element, markColorStyles(seriesColors(colors.slot(color))));
|
|
12082
|
+
placeDot(element, end);
|
|
12083
|
+
dots.push({
|
|
12084
|
+
element,
|
|
12085
|
+
draw: (s) => setAttributes(element, { opacity: opacity(s) })
|
|
12086
|
+
});
|
|
12087
|
+
});
|
|
12088
|
+
const ringed = ringA > 0 || ringB > 0;
|
|
12089
|
+
let width = ringA;
|
|
12090
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
12091
|
+
return {
|
|
12092
|
+
wrap(layer, group) {
|
|
12093
|
+
shapes.clear();
|
|
12094
|
+
const raise = () => {
|
|
12095
|
+
for (const dot of dots) group.appendChild(dot.element);
|
|
12096
|
+
};
|
|
12097
|
+
raise();
|
|
12098
|
+
return {
|
|
12099
|
+
...layer,
|
|
12100
|
+
path(d, paint) {
|
|
12101
|
+
const ring = ringed && paint.fill !== void 0 && paint.stroke === void 0;
|
|
12102
|
+
const handle = layer.path(d, ring ? {
|
|
12103
|
+
...paint,
|
|
12104
|
+
stroke: "surface",
|
|
12105
|
+
width
|
|
12106
|
+
} : paint);
|
|
12107
|
+
raise();
|
|
12108
|
+
if (!ring) return handle;
|
|
12109
|
+
shapes.set(handle, d);
|
|
12110
|
+
return {
|
|
12111
|
+
update(next, nextPaint) {
|
|
12112
|
+
shapes.set(handle, next);
|
|
12113
|
+
handle.update(next, nextPaint);
|
|
12114
|
+
},
|
|
12115
|
+
remove() {
|
|
12116
|
+
shapes.delete(handle);
|
|
12117
|
+
handle.remove();
|
|
12118
|
+
}
|
|
12119
|
+
};
|
|
12120
|
+
}
|
|
12121
|
+
};
|
|
12122
|
+
},
|
|
12123
|
+
draw(s) {
|
|
12124
|
+
width = mix$1(ringA, ringB, s);
|
|
12125
|
+
for (const [handle, d] of shapes) handle.update(d, { width });
|
|
12126
|
+
for (const dot of dots) dot.draw(s);
|
|
12127
|
+
}
|
|
12128
|
+
};
|
|
12129
|
+
}
|
|
11665
12130
|
let current = options.initial;
|
|
11666
12131
|
let active;
|
|
11667
12132
|
let destroyed = false;
|
|
@@ -11687,19 +12152,26 @@ function chartSwitch$1(target, options, env) {
|
|
|
11687
12152
|
}
|
|
11688
12153
|
function readFocus(from) {
|
|
11689
12154
|
const element = focused();
|
|
11690
|
-
|
|
11691
|
-
const keyed = element.closest("[data-key]");
|
|
11692
|
-
|
|
12155
|
+
const inside = element !== null && from.container.contains(element);
|
|
12156
|
+
const keyed = (inside ? element : from.chart.element.querySelector("[tabindex=\"0\"]"))?.closest("[data-key]");
|
|
12157
|
+
const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
|
|
12158
|
+
if (!inside && key === null) return void 0;
|
|
12159
|
+
return {
|
|
12160
|
+
keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key],
|
|
12161
|
+
focused: inside
|
|
12162
|
+
};
|
|
11693
12163
|
}
|
|
11694
12164
|
function restoreFocus(to, memory) {
|
|
11695
12165
|
if (!memory) return;
|
|
11696
12166
|
const now = focused();
|
|
11697
|
-
|
|
12167
|
+
const away = now !== null && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now);
|
|
12168
|
+
if (!memory.focused || away) {
|
|
12169
|
+
for (const key of memory.keys) if (to.chart.moveTabStop?.(key)) return;
|
|
12170
|
+
return;
|
|
12171
|
+
}
|
|
11698
12172
|
const inside = () => to.chart.element.contains(focused());
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
for (const mark of to.chart.marks()) {
|
|
11702
|
-
to.chart.focus(mark.key);
|
|
12173
|
+
for (const key of [...memory.keys, ...to.chart.marks().map((mark) => mark.key)]) {
|
|
12174
|
+
to.chart.focus(key);
|
|
11703
12175
|
if (inside()) return;
|
|
11704
12176
|
}
|
|
11705
12177
|
}
|
|
@@ -11737,7 +12209,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
11737
12209
|
each.container.setAttribute("inert", "");
|
|
11738
12210
|
each.chart.element.classList.add("ec-morphing");
|
|
11739
12211
|
}
|
|
11740
|
-
const { pairs, scene } = prepare(from, to);
|
|
12212
|
+
const { pairs, surface, scene } = prepare(from, to);
|
|
11741
12213
|
const { done, settle } = deferred();
|
|
11742
12214
|
const session = {
|
|
11743
12215
|
a: from,
|
|
@@ -11748,6 +12220,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
11748
12220
|
from: b,
|
|
11749
12221
|
to: a
|
|
11750
12222
|
})),
|
|
12223
|
+
surface,
|
|
11751
12224
|
scene,
|
|
11752
12225
|
focus: memory,
|
|
11753
12226
|
progress: 0,
|
|
@@ -11774,7 +12247,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
11774
12247
|
const started = startClock(clock);
|
|
11775
12248
|
session.transition = playTransition(session.forward ? session.pairs : session.reversed, {
|
|
11776
12249
|
effect,
|
|
11777
|
-
surface,
|
|
12250
|
+
surface: session.surface,
|
|
11778
12251
|
start: begin,
|
|
11779
12252
|
motion,
|
|
11780
12253
|
clock: started.clock,
|
|
@@ -11823,20 +12296,38 @@ function chartSwitch$1(target, options, env) {
|
|
|
11823
12296
|
function prepare(a, b) {
|
|
11824
12297
|
const toA = between$1(overlay, a.chart.element, wrapper);
|
|
11825
12298
|
const toB = between$1(overlay, b.chart.element, wrapper);
|
|
12299
|
+
const scaleA = scaleOf(toA);
|
|
12300
|
+
const scaleB = scaleOf(toB);
|
|
11826
12301
|
const from = a.chart.marks().map((mark) => mapMark(mark, toA));
|
|
11827
12302
|
const to = b.chart.marks().map((mark) => mapMark(mark, toB));
|
|
11828
12303
|
const fromByKey = new Map(from.map((mark) => [mark.key, mark]));
|
|
11829
12304
|
const toKeys = new Set(to.map((mark) => mark.key));
|
|
11830
|
-
const pairs =
|
|
12305
|
+
const pairs = [];
|
|
12306
|
+
const paints = [];
|
|
12307
|
+
const extras = [];
|
|
12308
|
+
for (const mark of to) {
|
|
11831
12309
|
const partner = fromByKey.get(mark.key);
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
|
|
11835
|
-
|
|
11836
|
-
|
|
12310
|
+
if (!partner) continue;
|
|
12311
|
+
const was = paintOf(a, partner);
|
|
12312
|
+
const will = paintOf(b, mark);
|
|
12313
|
+
if (!was.drawn && !will.drawn) continue;
|
|
12314
|
+
pairs.push({
|
|
12315
|
+
from: was.drawn ? partner : dot$1(partner),
|
|
12316
|
+
to: will.drawn ? mark : dot$1(mark)
|
|
12317
|
+
});
|
|
12318
|
+
paints.push(will.color);
|
|
12319
|
+
extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was.color, will.color]));
|
|
12320
|
+
}
|
|
11837
12321
|
const drawings = [];
|
|
11838
|
-
|
|
11839
|
-
|
|
12322
|
+
if (extras.some((each) => each !== void 0)) drawings.push((s) => {
|
|
12323
|
+
for (const each of extras) each?.draw(s);
|
|
12324
|
+
});
|
|
12325
|
+
const fade = (view, mark, scale, opacity) => {
|
|
12326
|
+
const paint = paintOf(view, mark);
|
|
12327
|
+
if (paint.drawn) drawings.push(fadeMark(mark, paint, scale, opacity));
|
|
12328
|
+
};
|
|
12329
|
+
for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, scaleA, fadeOut);
|
|
12330
|
+
for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, scaleB, fadeIn);
|
|
11840
12331
|
const id = (label) => `${label.role}\n${label.key}`;
|
|
11841
12332
|
const labelsA = a.chart.labels();
|
|
11842
12333
|
const labelsB = b.chart.labels();
|
|
@@ -11856,6 +12347,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
11856
12347
|
});
|
|
11857
12348
|
return {
|
|
11858
12349
|
pairs,
|
|
12350
|
+
surface: surfaceFor(paints, extras),
|
|
11859
12351
|
scene: {
|
|
11860
12352
|
draw: (s) => {
|
|
11861
12353
|
for (const draw of drawings) draw(s);
|
|
@@ -11868,18 +12360,36 @@ function chartSwitch$1(target, options, env) {
|
|
|
11868
12360
|
}
|
|
11869
12361
|
};
|
|
11870
12362
|
}
|
|
11871
|
-
function fadeMark(mark, opacity) {
|
|
12363
|
+
function fadeMark(mark, paint, scale, opacity) {
|
|
11872
12364
|
const group = svgElement("g", {
|
|
11873
12365
|
class: "ec-switch-fade",
|
|
11874
12366
|
"data-key": mark.key
|
|
11875
12367
|
}, fadesLayer);
|
|
11876
|
-
setStyles(group, markColorStyles(seriesColors(colors.slot(
|
|
11877
|
-
|
|
12368
|
+
setStyles(group, markColorStyles(seriesColors(colors.slot(paint.color))));
|
|
12369
|
+
const ring = ringOf(paint, scale);
|
|
12370
|
+
svgLayer(group).path(mark.outline.d, mark.outline.closed ? {
|
|
12371
|
+
fill: "mark",
|
|
12372
|
+
...ring > 0 ? {
|
|
12373
|
+
stroke: "surface",
|
|
12374
|
+
width: ring
|
|
12375
|
+
} : {}
|
|
12376
|
+
} : {
|
|
11878
12377
|
stroke: "mark",
|
|
11879
12378
|
width: mark.thickness
|
|
11880
12379
|
});
|
|
12380
|
+
const end = endOf(paint, mark, scale);
|
|
12381
|
+
if (end) placeDot(group.appendChild(endDot()), end);
|
|
11881
12382
|
return (s) => setAttributes(group, { opacity: opacity(s) });
|
|
11882
12383
|
}
|
|
12384
|
+
function endDot() {
|
|
12385
|
+
const element = doc.createElementNS(SVG_NS$2, "circle");
|
|
12386
|
+
element.setAttribute("class", "ec-switch-end");
|
|
12387
|
+
setStyles(element, {
|
|
12388
|
+
fill: cssColor("mark"),
|
|
12389
|
+
stroke: cssColor("surface")
|
|
12390
|
+
});
|
|
12391
|
+
return element;
|
|
12392
|
+
}
|
|
11883
12393
|
function copyLabel(label, m) {
|
|
11884
12394
|
const text = label.element.cloneNode(true);
|
|
11885
12395
|
for (const name of [
|
|
@@ -12010,7 +12520,7 @@ function drive(begin, at, env) {
|
|
|
12010
12520
|
const begun = unease(begin);
|
|
12011
12521
|
let running;
|
|
12012
12522
|
running = tween({
|
|
12013
|
-
duration: DURATION$
|
|
12523
|
+
duration: DURATION$8,
|
|
12014
12524
|
timing: "transition",
|
|
12015
12525
|
ease: linear,
|
|
12016
12526
|
update: (k) => {
|
|
@@ -12066,12 +12576,44 @@ const fadeOut = (s) => 1 - clamp$1(s / HALF);
|
|
|
12066
12576
|
const fadeIn = (s) => clamp$1((s - HALF) / .5);
|
|
12067
12577
|
const clamp$1 = (value) => Math.min(1, Math.max(0, value));
|
|
12068
12578
|
const mix$1 = (x, y, s) => x * (1 - s) + y * s;
|
|
12579
|
+
function paintOf(view, mark) {
|
|
12580
|
+
return view.chart.paintOf?.(mark.key) ?? {
|
|
12581
|
+
color: mark.key,
|
|
12582
|
+
drawn: true
|
|
12583
|
+
};
|
|
12584
|
+
}
|
|
12585
|
+
function dot$1(mark) {
|
|
12586
|
+
return describePoint({
|
|
12587
|
+
key: mark.key,
|
|
12588
|
+
...mark.series === void 0 ? {} : { series: mark.series },
|
|
12589
|
+
x: mark.center.x,
|
|
12590
|
+
y: mark.center.y,
|
|
12591
|
+
r: 0
|
|
12592
|
+
});
|
|
12593
|
+
}
|
|
12594
|
+
const ringOf = (paint, scale) => paint.drawn && paint.end === void 0 ? (paint.ring ?? 0) * scale : 0;
|
|
12595
|
+
function endOf(paint, mark, scale) {
|
|
12596
|
+
return paint.drawn && paint.end !== void 0 ? {
|
|
12597
|
+
at: mark.end,
|
|
12598
|
+
r: paint.end * scale,
|
|
12599
|
+
ring: (paint.ring ?? 0) * scale
|
|
12600
|
+
} : void 0;
|
|
12601
|
+
}
|
|
12602
|
+
function placeDot(element, end) {
|
|
12603
|
+
setAttributes(element, {
|
|
12604
|
+
cx: end.at.x,
|
|
12605
|
+
cy: end.at.y,
|
|
12606
|
+
r: end.r,
|
|
12607
|
+
"stroke-width": end.ring
|
|
12608
|
+
});
|
|
12609
|
+
}
|
|
12069
12610
|
const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
12611
|
+
const scaleOf = (m) => Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
12070
12612
|
function mapMark(mark, m) {
|
|
12071
12613
|
if (isIdentity(m)) return mark;
|
|
12072
12614
|
const point = (p) => matrix.apply(m, p);
|
|
12073
12615
|
const path = (d) => formatPath(transformPath(parsePath(d), m));
|
|
12074
|
-
const scale =
|
|
12616
|
+
const scale = scaleOf(m);
|
|
12075
12617
|
const { outline } = mark;
|
|
12076
12618
|
return {
|
|
12077
12619
|
key: mark.key,
|
|
@@ -12087,6 +12629,7 @@ function mapMark(mark, m) {
|
|
|
12087
12629
|
return Math.atan2(m[1] * cos + m[3] * sin, m[0] * cos + m[2] * sin);
|
|
12088
12630
|
},
|
|
12089
12631
|
slice: (t0, t1) => path(mark.slice(t0, t1)),
|
|
12632
|
+
...mark.gaps === void 0 ? {} : { gaps: mark.gaps },
|
|
12090
12633
|
thickness: mark.thickness * scale,
|
|
12091
12634
|
outline: {
|
|
12092
12635
|
d: path(outline.d),
|
|
@@ -12120,7 +12663,7 @@ function isView(value, container) {
|
|
|
12120
12663
|
"destroy"
|
|
12121
12664
|
].every((method) => typeof view[method] === "function") && element?.nodeType === 1 && container.contains(element);
|
|
12122
12665
|
}
|
|
12123
|
-
function checkOptions$
|
|
12666
|
+
function checkOptions$11(options) {
|
|
12124
12667
|
if (typeof options !== "object" || options === null) throw new TypeError("chartSwitch needs options.");
|
|
12125
12668
|
const { views, initial, transition, announce } = options;
|
|
12126
12669
|
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.");
|
|
@@ -12153,7 +12696,7 @@ let switches = 0;
|
|
|
12153
12696
|
function motionSwitch$1(target, motion, options = {}) {
|
|
12154
12697
|
const parent = resolveTarget$1(target);
|
|
12155
12698
|
checkMotion(motion);
|
|
12156
|
-
checkOptions$
|
|
12699
|
+
checkOptions$10(options);
|
|
12157
12700
|
const labels = {
|
|
12158
12701
|
...LABELS$1,
|
|
12159
12702
|
...options.labels
|
|
@@ -12237,7 +12780,7 @@ function resolveTarget$1(target) {
|
|
|
12237
12780
|
function checkMotion(motion) {
|
|
12238
12781
|
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().");
|
|
12239
12782
|
}
|
|
12240
|
-
function checkOptions$
|
|
12783
|
+
function checkOptions$10(options) {
|
|
12241
12784
|
const { label, labels, hints, persist } = options;
|
|
12242
12785
|
if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
|
|
12243
12786
|
for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
|
|
@@ -12254,7 +12797,7 @@ const LABELS = {
|
|
|
12254
12797
|
function playButton(target, playback, options = {}) {
|
|
12255
12798
|
const parent = resolveTarget(target);
|
|
12256
12799
|
checkPlayback(playback);
|
|
12257
|
-
checkOptions$
|
|
12800
|
+
checkOptions$9(options);
|
|
12258
12801
|
const labels = {
|
|
12259
12802
|
...LABELS,
|
|
12260
12803
|
...options.labels
|
|
@@ -12295,7 +12838,7 @@ function resolveTarget(target) {
|
|
|
12295
12838
|
function checkPlayback(playback) {
|
|
12296
12839
|
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().");
|
|
12297
12840
|
}
|
|
12298
|
-
function checkOptions$
|
|
12841
|
+
function checkOptions$9(options) {
|
|
12299
12842
|
const { labels } = options;
|
|
12300
12843
|
if (labels === void 0) return;
|
|
12301
12844
|
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)}.`);
|
|
@@ -12347,7 +12890,7 @@ const gaits = {
|
|
|
12347
12890
|
const SPEED = 360;
|
|
12348
12891
|
const SHORTEST = 260;
|
|
12349
12892
|
const LONGEST = 4e3;
|
|
12350
|
-
const MIN_WALK$
|
|
12893
|
+
const MIN_WALK$3 = .5;
|
|
12351
12894
|
const FIT = .85;
|
|
12352
12895
|
const MIN_SMOOTHING = 2;
|
|
12353
12896
|
const IDENTITY = [
|
|
@@ -12365,12 +12908,12 @@ const ORIENTS = [
|
|
|
12365
12908
|
];
|
|
12366
12909
|
const RIDES = ["center", "on"];
|
|
12367
12910
|
function travel(icon, options = {}) {
|
|
12368
|
-
checkOptions$
|
|
12911
|
+
checkOptions$8(icon, options);
|
|
12369
12912
|
function plan(mark, ctx) {
|
|
12370
12913
|
const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
|
|
12371
12914
|
if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
|
|
12372
12915
|
const walk = pick(mark, options.along);
|
|
12373
|
-
if (!walk || !(drawn(walk) >= MIN_WALK$
|
|
12916
|
+
if (!walk || !(drawn(walk) >= MIN_WALK$3)) return void 0;
|
|
12374
12917
|
const scale = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
|
|
12375
12918
|
if (!(scale > 0)) return void 0;
|
|
12376
12919
|
return trip(walk, resolved, scale, options);
|
|
@@ -12518,7 +13061,7 @@ function heading(walk, distance, window, leg) {
|
|
|
12518
13061
|
}
|
|
12519
13062
|
return walk.angle(distance / length);
|
|
12520
13063
|
}
|
|
12521
|
-
function checkOptions$
|
|
13064
|
+
function checkOptions$8(icon, options) {
|
|
12522
13065
|
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}.`);
|
|
12523
13066
|
const { along, gait, size, orient, ride } = options;
|
|
12524
13067
|
if (along !== void 0 && typeof along !== "string") throw new RangeError(`travel: along must be a series name, got ${String(along)}.`);
|
|
@@ -12528,12 +13071,12 @@ function checkOptions$7(icon, options) {
|
|
|
12528
13071
|
if (ride !== void 0 && !RIDES.includes(ride)) throw new RangeError(`travel: ride must be center or on, got ${String(ride)}.`);
|
|
12529
13072
|
}
|
|
12530
13073
|
// src/effects/flash.ts
|
|
12531
|
-
const DURATION$
|
|
13074
|
+
const DURATION$7 = 900;
|
|
12532
13075
|
const PEAK = .25;
|
|
12533
13076
|
const WIDTH$2 = 8;
|
|
12534
13077
|
const OPACITY$2 = .35;
|
|
12535
13078
|
function flash(options = {}) {
|
|
12536
|
-
checkOptions$
|
|
13079
|
+
checkOptions$7(options);
|
|
12537
13080
|
const width = options.width ?? WIDTH$2;
|
|
12538
13081
|
const opacity = options.opacity ?? OPACITY$2;
|
|
12539
13082
|
const { color } = options;
|
|
@@ -12550,7 +13093,7 @@ function flash(options = {}) {
|
|
|
12550
13093
|
async run(_mark, ctx) {
|
|
12551
13094
|
if (ctx.signal.aborted) return;
|
|
12552
13095
|
await ctx.tween({
|
|
12553
|
-
duration: DURATION$
|
|
13096
|
+
duration: DURATION$7,
|
|
12554
13097
|
timing: "effect",
|
|
12555
13098
|
ease: linear,
|
|
12556
13099
|
update: (p) => show(ctx, p)
|
|
@@ -12577,14 +13120,14 @@ function easeOut(x) {
|
|
|
12577
13120
|
const s = (lo + hi) / 2;
|
|
12578
13121
|
return 3 * s * s - 2 * s * s * s;
|
|
12579
13122
|
}
|
|
12580
|
-
function checkOptions$
|
|
13123
|
+
function checkOptions$7(options) {
|
|
12581
13124
|
const { width, opacity, color } = options;
|
|
12582
13125
|
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)}.`);
|
|
12583
13126
|
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)}.`);
|
|
12584
13127
|
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)}.`);
|
|
12585
13128
|
}
|
|
12586
13129
|
// src/effects/wiggle.ts
|
|
12587
|
-
const DURATION$
|
|
13130
|
+
const DURATION$6 = 450;
|
|
12588
13131
|
const SWINGS = [
|
|
12589
13132
|
1,
|
|
12590
13133
|
-.5,
|
|
@@ -12595,7 +13138,7 @@ const MIN_REACH = .5;
|
|
|
12595
13138
|
const SAMPLES = 64;
|
|
12596
13139
|
const MAX_ANGLE = Math.PI / 12;
|
|
12597
13140
|
function wiggle(options = {}) {
|
|
12598
|
-
checkOptions$
|
|
13141
|
+
checkOptions$6(options);
|
|
12599
13142
|
const swing = options.swing ?? SWING;
|
|
12600
13143
|
return {
|
|
12601
13144
|
kind: "geometry",
|
|
@@ -12614,7 +13157,7 @@ function wiggle(options = {}) {
|
|
|
12614
13157
|
show();
|
|
12615
13158
|
});
|
|
12616
13159
|
await ctx.tween({
|
|
12617
|
-
duration: DURATION$
|
|
13160
|
+
duration: DURATION$6,
|
|
12618
13161
|
timing: "effect",
|
|
12619
13162
|
ease: linear,
|
|
12620
13163
|
update: (p) => {
|
|
@@ -12640,19 +13183,19 @@ function rock(t) {
|
|
|
12640
13183
|
const index = Math.floor(position);
|
|
12641
13184
|
return SWINGS[index] * Math.sin(Math.PI * (position - index));
|
|
12642
13185
|
}
|
|
12643
|
-
function checkOptions$
|
|
13186
|
+
function checkOptions$6(options) {
|
|
12644
13187
|
const { swing } = options;
|
|
12645
13188
|
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)}.`);
|
|
12646
13189
|
}
|
|
12647
13190
|
// src/effects/pulse.ts
|
|
12648
|
-
const DURATION$
|
|
13191
|
+
const DURATION$5 = 600;
|
|
12649
13192
|
const TIMES = 2;
|
|
12650
13193
|
const MAX_TIMES = 6;
|
|
12651
13194
|
const WIDTH$1 = 12;
|
|
12652
13195
|
const OPACITY$1 = .4;
|
|
12653
13196
|
const LIMIT = 5e3;
|
|
12654
13197
|
function pulse(options = {}) {
|
|
12655
|
-
checkOptions$
|
|
13198
|
+
checkOptions$5(options);
|
|
12656
13199
|
const times = options.times ?? TIMES;
|
|
12657
13200
|
const width = options.width ?? WIDTH$1;
|
|
12658
13201
|
const { color } = options;
|
|
@@ -12670,11 +13213,11 @@ function pulse(options = {}) {
|
|
|
12670
13213
|
let total = 0;
|
|
12671
13214
|
for (let i = 0; i < times; i++) {
|
|
12672
13215
|
if (ctx.signal.aborted) return;
|
|
12673
|
-
const length = ctx.motion.duration(DURATION$
|
|
13216
|
+
const length = ctx.motion.duration(DURATION$5, "effect");
|
|
12674
13217
|
if (total + length >= LIMIT) return;
|
|
12675
13218
|
total += length;
|
|
12676
13219
|
await ctx.tween({
|
|
12677
|
-
duration: DURATION$
|
|
13220
|
+
duration: DURATION$5,
|
|
12678
13221
|
timing: "effect",
|
|
12679
13222
|
ease: linear,
|
|
12680
13223
|
update: (t) => show(ctx, t)
|
|
@@ -12685,20 +13228,20 @@ function pulse(options = {}) {
|
|
|
12685
13228
|
clear() {}
|
|
12686
13229
|
};
|
|
12687
13230
|
}
|
|
12688
|
-
function checkOptions$
|
|
13231
|
+
function checkOptions$5(options) {
|
|
12689
13232
|
const { times, width, color } = options;
|
|
12690
13233
|
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)}.`);
|
|
12691
13234
|
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)}.`);
|
|
12692
13235
|
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)}.`);
|
|
12693
13236
|
}
|
|
12694
13237
|
// src/effects/trace.ts
|
|
12695
|
-
const DURATION$
|
|
13238
|
+
const DURATION$4 = 500;
|
|
12696
13239
|
const WIDTH = 3;
|
|
12697
13240
|
const OPACITY = .5;
|
|
12698
|
-
const MIN_WALK$
|
|
13241
|
+
const MIN_WALK$2 = .5;
|
|
12699
13242
|
function trace(options = {}) {
|
|
12700
|
-
checkOptions$
|
|
12701
|
-
const duration = options.duration ?? DURATION$
|
|
13243
|
+
checkOptions$4(options);
|
|
13244
|
+
const duration = options.duration ?? DURATION$4;
|
|
12702
13245
|
const paint = {
|
|
12703
13246
|
stroke: options.color ?? "mark",
|
|
12704
13247
|
width: options.width ?? WIDTH,
|
|
@@ -12710,7 +13253,7 @@ function trace(options = {}) {
|
|
|
12710
13253
|
let progress = 0;
|
|
12711
13254
|
let path;
|
|
12712
13255
|
const draw = () => {
|
|
12713
|
-
if (!(current.length >= MIN_WALK$
|
|
13256
|
+
if (!(current.length >= MIN_WALK$2)) {
|
|
12714
13257
|
path?.remove();
|
|
12715
13258
|
path = void 0;
|
|
12716
13259
|
return;
|
|
@@ -12734,7 +13277,7 @@ function trace(options = {}) {
|
|
|
12734
13277
|
async run(mark, ctx) {
|
|
12735
13278
|
if (ctx.signal.aborted) return;
|
|
12736
13279
|
const show = stroke(mark, ctx);
|
|
12737
|
-
if (!(mark.length >= MIN_WALK$
|
|
13280
|
+
if (!(mark.length >= MIN_WALK$2)) {
|
|
12738
13281
|
show(1);
|
|
12739
13282
|
return;
|
|
12740
13283
|
}
|
|
@@ -12751,31 +13294,147 @@ function trace(options = {}) {
|
|
|
12751
13294
|
clear() {}
|
|
12752
13295
|
};
|
|
12753
13296
|
}
|
|
12754
|
-
function checkOptions$
|
|
13297
|
+
function checkOptions$4(options) {
|
|
12755
13298
|
const { color, width, opacity, duration } = options;
|
|
12756
13299
|
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)}.`);
|
|
12757
13300
|
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)}.`);
|
|
12758
13301
|
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)}.`);
|
|
12759
13302
|
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)}.`);
|
|
12760
13303
|
}
|
|
13304
|
+
// src/effects/draw-in.ts
|
|
13305
|
+
const DURATION$3 = 750;
|
|
13306
|
+
const FAINT = .3;
|
|
13307
|
+
const MIN_WALK$1 = .5;
|
|
13308
|
+
function drawIn(options = {}) {
|
|
13309
|
+
checkOptions$3(options);
|
|
13310
|
+
const duration = options.duration ?? DURATION$3;
|
|
13311
|
+
const faint = options.faint ?? FAINT;
|
|
13312
|
+
return {
|
|
13313
|
+
kind: "geometry",
|
|
13314
|
+
async run(mark, ctx) {
|
|
13315
|
+
if (ctx.signal.aborted || !(walk(mark) >= MIN_WALK$1)) return;
|
|
13316
|
+
let current = mark;
|
|
13317
|
+
let progress = 0;
|
|
13318
|
+
let done = false;
|
|
13319
|
+
const paths = [];
|
|
13320
|
+
const draw = (repaint) => {
|
|
13321
|
+
const { segments } = current;
|
|
13322
|
+
const parts = segments ?? [current];
|
|
13323
|
+
const reached = progress * walk(current);
|
|
13324
|
+
let from = 0;
|
|
13325
|
+
parts.forEach((piece, i) => {
|
|
13326
|
+
const share = piece.length > 0 ? Math.min(1, Math.max(0, (reached - from) / piece.length)) : 0;
|
|
13327
|
+
from += piece.length;
|
|
13328
|
+
const d = piece.slice(0, easeInOutCubic(share));
|
|
13329
|
+
const paint = {
|
|
13330
|
+
stroke: "mark",
|
|
13331
|
+
width: piece.thickness,
|
|
13332
|
+
linecap: "butt",
|
|
13333
|
+
...segments && { part: piece.key }
|
|
13334
|
+
};
|
|
13335
|
+
const path = paths[i];
|
|
13336
|
+
if (!path) paths[i] = ctx.layer.path(d, paint);
|
|
13337
|
+
else path.update(d, repaint ? {
|
|
13338
|
+
part: void 0,
|
|
13339
|
+
...paint
|
|
13340
|
+
} : void 0);
|
|
13341
|
+
});
|
|
13342
|
+
for (const path of paths.splice(parts.length)) path.remove();
|
|
13343
|
+
};
|
|
13344
|
+
ctx.onChange((next) => {
|
|
13345
|
+
current = next;
|
|
13346
|
+
if (!done) draw(true);
|
|
13347
|
+
});
|
|
13348
|
+
ctx.mark.set({ opacity: faint });
|
|
13349
|
+
draw(false);
|
|
13350
|
+
await ctx.tween({
|
|
13351
|
+
duration,
|
|
13352
|
+
timing: "effect",
|
|
13353
|
+
ease: linear,
|
|
13354
|
+
update: (p) => {
|
|
13355
|
+
progress = p;
|
|
13356
|
+
draw(false);
|
|
13357
|
+
}
|
|
13358
|
+
}).finished;
|
|
13359
|
+
done = true;
|
|
13360
|
+
for (const path of paths) path.remove();
|
|
13361
|
+
ctx.mark.set({ opacity: void 0 });
|
|
13362
|
+
},
|
|
13363
|
+
end() {},
|
|
13364
|
+
clear() {}
|
|
13365
|
+
};
|
|
13366
|
+
}
|
|
13367
|
+
const walk = (mark) => (mark.segments ?? [mark]).reduce((sum, part) => sum + part.length, 0);
|
|
13368
|
+
function checkOptions$3(options) {
|
|
13369
|
+
const { duration, faint } = options;
|
|
13370
|
+
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)}.`);
|
|
13371
|
+
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)}.`);
|
|
13372
|
+
}
|
|
12761
13373
|
// src/effects/caption.ts
|
|
12762
13374
|
const PAST_END = 10;
|
|
12763
13375
|
const PAST_LABEL = 6;
|
|
12764
13376
|
const TEXT = 12.5;
|
|
12765
13377
|
const CENTRE = .36;
|
|
12766
|
-
function captionPlace(mark) {
|
|
13378
|
+
function captionPlace(mark, text) {
|
|
12767
13379
|
const own = mark.labelBounds ?? [];
|
|
12768
|
-
const
|
|
13380
|
+
const boxes = [
|
|
13381
|
+
...own,
|
|
13382
|
+
...mark.nearbyLabels ?? [],
|
|
13383
|
+
...text?.held ?? []
|
|
13384
|
+
];
|
|
12769
13385
|
const heading = mark.angle(1);
|
|
12770
|
-
|
|
12771
|
-
if (along === void 0 && own.length > 0) {
|
|
13386
|
+
if (farthest(mark.end, heading, own) === void 0) {
|
|
12772
13387
|
const up = mark.angle(.5) - Math.PI / 2;
|
|
12773
|
-
|
|
12774
|
-
if (out !== void 0) return placed(mark.center, up, Math.max(out, farthest(mark.center, up, nearby) ?? -Infinity));
|
|
13388
|
+
if (farthest(mark.center, up, own) !== void 0) return past(mark.center, up, 0, own, boxes, text);
|
|
12775
13389
|
}
|
|
12776
|
-
return
|
|
13390
|
+
return past(mark.end, heading, PAST_END, own, boxes, text);
|
|
13391
|
+
}
|
|
13392
|
+
function past(from, toward, least, own, boxes, text) {
|
|
13393
|
+
if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
|
|
13394
|
+
const { x, y, width, height } = text.box(placed$1(from, toward, 0));
|
|
13395
|
+
return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
|
|
13396
|
+
x: x - from.x,
|
|
13397
|
+
y: y - from.y,
|
|
13398
|
+
width,
|
|
13399
|
+
height
|
|
13400
|
+
}, new Set(text.held)));
|
|
12777
13401
|
}
|
|
12778
|
-
function
|
|
13402
|
+
function clearOf(from, toward, distance, boxes, reach, held) {
|
|
13403
|
+
const cos = Math.cos(toward);
|
|
13404
|
+
const sin = Math.sin(toward);
|
|
13405
|
+
const across = centred(cos);
|
|
13406
|
+
const meets = (box) => span(from, cos, sin, {
|
|
13407
|
+
x: box.x - reach.x - reach.width,
|
|
13408
|
+
y: box.y - reach.y - reach.height,
|
|
13409
|
+
width: box.width + reach.width,
|
|
13410
|
+
height: box.height + reach.height
|
|
13411
|
+
});
|
|
13412
|
+
const spans = boxes.map((box) => {
|
|
13413
|
+
const near = grow(box, PAST_LABEL);
|
|
13414
|
+
const band = span(from, cos, sin, near);
|
|
13415
|
+
if (!band && held.has(box)) return meets(box);
|
|
13416
|
+
const within = meets(near);
|
|
13417
|
+
if (!band || !within) return within;
|
|
13418
|
+
const leaving = across ? Math.max(band[1], ((sin > 0 ? near.y + near.height : near.y) - from.y) / sin) : band[1];
|
|
13419
|
+
return [within[0], Math.max(leaving, meets(box)?.[1] ?? -Infinity)];
|
|
13420
|
+
});
|
|
13421
|
+
let at = distance;
|
|
13422
|
+
for (let moved = true; moved;) {
|
|
13423
|
+
moved = false;
|
|
13424
|
+
for (const meets of spans) if (meets && at > meets[0] + 1e-6 && at < meets[1] - 1e-6) {
|
|
13425
|
+
at = meets[1];
|
|
13426
|
+
moved = true;
|
|
13427
|
+
}
|
|
13428
|
+
}
|
|
13429
|
+
return at;
|
|
13430
|
+
}
|
|
13431
|
+
const grow = ({ x, y, width, height }, by) => ({
|
|
13432
|
+
x: x - by,
|
|
13433
|
+
y: y - by,
|
|
13434
|
+
width: width + 2 * by,
|
|
13435
|
+
height: height + 2 * by
|
|
13436
|
+
});
|
|
13437
|
+
function placed$1(from, toward, distance) {
|
|
12779
13438
|
const cos = Math.cos(toward);
|
|
12780
13439
|
const sin = Math.sin(toward);
|
|
12781
13440
|
const point = offset(from, toward, distance);
|
|
@@ -12798,13 +13457,8 @@ function farthest(from, toward, boxes) {
|
|
|
12798
13457
|
const sin = Math.sin(toward);
|
|
12799
13458
|
const across = centred(cos);
|
|
12800
13459
|
let exit;
|
|
12801
|
-
for (const
|
|
12802
|
-
const grown =
|
|
12803
|
-
x: x - PAST_LABEL,
|
|
12804
|
-
y: y - PAST_LABEL,
|
|
12805
|
-
width: width + 12,
|
|
12806
|
-
height: height + 12
|
|
12807
|
-
};
|
|
13460
|
+
for (const box of boxes) {
|
|
13461
|
+
const grown = grow(box, PAST_LABEL);
|
|
12808
13462
|
let leaving = leaves(from, cos, sin, grown);
|
|
12809
13463
|
if (leaving !== void 0 && across) leaving = Math.max(leaving, ((sin > 0 ? grown.y + grown.height : grown.y) - from.y) / sin);
|
|
12810
13464
|
if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
|
|
@@ -12812,6 +13466,9 @@ function farthest(from, toward, boxes) {
|
|
|
12812
13466
|
return exit;
|
|
12813
13467
|
}
|
|
12814
13468
|
function leaves(from, cos, sin, box) {
|
|
13469
|
+
return span(from, cos, sin, box)?.[1];
|
|
13470
|
+
}
|
|
13471
|
+
function span(from, cos, sin, box) {
|
|
12815
13472
|
let near = 0;
|
|
12816
13473
|
let far = Infinity;
|
|
12817
13474
|
for (const [origin, step, lo, hi] of [[
|
|
@@ -12834,7 +13491,7 @@ function leaves(from, cos, sin, box) {
|
|
|
12834
13491
|
near = Math.max(near, Math.min(a, b));
|
|
12835
13492
|
far = Math.min(far, Math.max(a, b));
|
|
12836
13493
|
}
|
|
12837
|
-
return far >= near ? far : void 0;
|
|
13494
|
+
return far >= near ? [near, far] : void 0;
|
|
12838
13495
|
}
|
|
12839
13496
|
function caption(mark, data, ctx, color, words) {
|
|
12840
13497
|
let current = mark;
|
|
@@ -12842,13 +13499,22 @@ function caption(mark, data, ctx, color, words) {
|
|
|
12842
13499
|
let latest = data;
|
|
12843
13500
|
let progress = 0;
|
|
12844
13501
|
let handle;
|
|
13502
|
+
const { texts } = ctx;
|
|
12845
13503
|
const draw = () => {
|
|
12846
13504
|
if (content === "") {
|
|
12847
13505
|
handle?.remove();
|
|
12848
13506
|
handle = void 0;
|
|
13507
|
+
texts?.hold(void 0);
|
|
12849
13508
|
return;
|
|
12850
13509
|
}
|
|
12851
|
-
const { at, anchor, toward } = captionPlace(current
|
|
13510
|
+
const { at, anchor, toward } = captionPlace(current, texts && {
|
|
13511
|
+
held: texts.held(),
|
|
13512
|
+
box: (style) => texts.box(content, style)
|
|
13513
|
+
});
|
|
13514
|
+
texts?.hold(texts.box(content, {
|
|
13515
|
+
at,
|
|
13516
|
+
anchor
|
|
13517
|
+
}));
|
|
12852
13518
|
const style = {
|
|
12853
13519
|
at: offset(at, toward - Math.PI / 2, -8 * (1 - progress)),
|
|
12854
13520
|
anchor,
|
|
@@ -13008,7 +13674,7 @@ function reference(compareTo, data) {
|
|
|
13008
13674
|
const gaps = gapsOf(related.samples, place);
|
|
13009
13675
|
return {
|
|
13010
13676
|
place,
|
|
13011
|
-
valueAt: (u) => inside(gaps, u) ? void 0 : interpolate(points, u),
|
|
13677
|
+
valueAt: (u) => inside$1(gaps, u) ? void 0 : interpolate(points, u),
|
|
13012
13678
|
bends: points.map((point) => point.u)
|
|
13013
13679
|
};
|
|
13014
13680
|
}
|
|
@@ -13030,7 +13696,7 @@ function gapsOf(samples, place) {
|
|
|
13030
13696
|
}
|
|
13031
13697
|
return merged;
|
|
13032
13698
|
}
|
|
13033
|
-
function inside(gaps, u) {
|
|
13699
|
+
function inside$1(gaps, u) {
|
|
13034
13700
|
let lo = 0;
|
|
13035
13701
|
let hi = gaps.length;
|
|
13036
13702
|
while (lo < hi) {
|
|
@@ -13136,6 +13802,11 @@ const show = (value) => typeof value === "string" ? JSON.stringify(value) : Stri
|
|
|
13136
13802
|
const DURATION = 950;
|
|
13137
13803
|
const POINTS = 160;
|
|
13138
13804
|
const ALIGNS = ["unroll", "drop"];
|
|
13805
|
+
const SAME_T = 1e-9;
|
|
13806
|
+
const SAME_X = .01;
|
|
13807
|
+
const VERTICES = 1e3;
|
|
13808
|
+
const GRID = 9;
|
|
13809
|
+
const CHECKS = 8;
|
|
13139
13810
|
function morph(options = {}) {
|
|
13140
13811
|
checkOptions(options);
|
|
13141
13812
|
const points = options?.points ?? POINTS;
|
|
@@ -13173,13 +13844,16 @@ function morph(options = {}) {
|
|
|
13173
13844
|
function drawing(from, to, layer, points, align) {
|
|
13174
13845
|
const closed = from.outline.closed;
|
|
13175
13846
|
if (closed !== to.outline.closed) return crossfade(from, to, layer);
|
|
13847
|
+
const across = closed ? void 0 : acrossX(from, to, points);
|
|
13848
|
+
if (across) return piecewise(from, to, layer, across.stops, across.kinds);
|
|
13176
13849
|
const a = from.outline.sample(points);
|
|
13177
13850
|
const b = to.outline.sample(points);
|
|
13178
|
-
if (!closed) return stroke(from, to, layer, a, b);
|
|
13851
|
+
if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
|
|
13179
13852
|
const [shiftA, shiftB] = align === "drop" ? turn(from, to, points) : [0, 0];
|
|
13853
|
+
const holes = holePairs(from, to, a, b, [shiftA, shiftB], points / 4);
|
|
13180
13854
|
let path;
|
|
13181
13855
|
return (p) => {
|
|
13182
|
-
const d = p <= 0 ? from.outline.d : p >= 1 ? to.outline.d : between(a, b, shiftA, shiftB, p, true);
|
|
13856
|
+
const d = p <= 0 ? from.outline.d : p >= 1 ? to.outline.d : between(a, b, shiftA, shiftB, p, true) + holes.map((hole) => holeAt(hole, p)).join("");
|
|
13183
13857
|
if (path) path.update(d);
|
|
13184
13858
|
else path = layer.path(d, { fill: "mark" });
|
|
13185
13859
|
};
|
|
@@ -13196,6 +13870,326 @@ function stroke(from, to, layer, a, b) {
|
|
|
13196
13870
|
});
|
|
13197
13871
|
};
|
|
13198
13872
|
}
|
|
13873
|
+
function gapped(from, to, layer, a, b) {
|
|
13874
|
+
const n = a.length;
|
|
13875
|
+
const stops = a.map((point, i) => ({
|
|
13876
|
+
t: i / (n - 1),
|
|
13877
|
+
from: point,
|
|
13878
|
+
to: b[i]
|
|
13879
|
+
}));
|
|
13880
|
+
for (const gap of [...from.gaps ?? [], ...to.gaps ?? []]) for (const t of gap) if (t > 0 && t < 1 && stops.every((stop) => Math.abs(stop.t - t) > SAME_T)) stops.push({
|
|
13881
|
+
t,
|
|
13882
|
+
from: from.path(t),
|
|
13883
|
+
to: to.path(t)
|
|
13884
|
+
});
|
|
13885
|
+
stops.sort((x, y) => x.t - y.t);
|
|
13886
|
+
return piecewise(from, to, layer, stops, stops.slice(1).map((stop, k) => {
|
|
13887
|
+
const t = (stops[k].t + stop.t) / 2;
|
|
13888
|
+
return (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
13889
|
+
}));
|
|
13890
|
+
}
|
|
13891
|
+
function piecewise(from, to, layer, stops, kinds) {
|
|
13892
|
+
const runs = [
|
|
13893
|
+
[],
|
|
13894
|
+
[],
|
|
13895
|
+
[]
|
|
13896
|
+
];
|
|
13897
|
+
for (let k = 0; k < kinds.length; k++) {
|
|
13898
|
+
const kind = kinds[k];
|
|
13899
|
+
if (kind === 3) continue;
|
|
13900
|
+
const last = runs[kind][runs[kind].length - 1];
|
|
13901
|
+
if (last && last[1] === k) last[1] = k + 1;
|
|
13902
|
+
else runs[kind].push([k, k + 1]);
|
|
13903
|
+
}
|
|
13904
|
+
const order = [
|
|
13905
|
+
0,
|
|
13906
|
+
1,
|
|
13907
|
+
2
|
|
13908
|
+
].filter((kind) => runs[kind].length > 0).sort((x, y) => runs[x][0][0] - runs[y][0][0]);
|
|
13909
|
+
const paths = [];
|
|
13910
|
+
return (p) => {
|
|
13911
|
+
const width = p <= 0 ? from.thickness : p >= 1 ? to.thickness : mix(from.thickness, to.thickness, p);
|
|
13912
|
+
const opacities = [
|
|
13913
|
+
void 0,
|
|
13914
|
+
p,
|
|
13915
|
+
1 - p
|
|
13916
|
+
];
|
|
13917
|
+
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]]);
|
|
13918
|
+
pieces.forEach(([d, opacity], i) => {
|
|
13919
|
+
if (paths[i]) paths[i].update(d, {
|
|
13920
|
+
width,
|
|
13921
|
+
opacity
|
|
13922
|
+
});
|
|
13923
|
+
else paths[i] = layer.path(d, {
|
|
13924
|
+
stroke: "mark",
|
|
13925
|
+
width,
|
|
13926
|
+
...opacity === void 0 ? {} : { opacity }
|
|
13927
|
+
});
|
|
13928
|
+
});
|
|
13929
|
+
for (const path of paths.splice(pieces.length)) path.remove();
|
|
13930
|
+
};
|
|
13931
|
+
}
|
|
13932
|
+
const inGap = (mark, t) => (mark.gaps ?? []).some(([x, y]) => x < t && t < y);
|
|
13933
|
+
function along(stops, [first, last], p) {
|
|
13934
|
+
let d = "";
|
|
13935
|
+
for (let k = first; k <= last; k++) d += `${k === first ? "M" : "L"}${at(stops[k].from, stops[k].to, p)}`;
|
|
13936
|
+
return d;
|
|
13937
|
+
}
|
|
13938
|
+
function acrossX(from, to, points) {
|
|
13939
|
+
const a = courseOf(from);
|
|
13940
|
+
const b = a && courseOf(to);
|
|
13941
|
+
if (!a || !b || a.way !== b.way) return void 0;
|
|
13942
|
+
const all = [
|
|
13943
|
+
...Array.from({ length: points }, (_, i) => [i / (points - 1), 0]),
|
|
13944
|
+
...corners(a).map((s) => [s, 1]),
|
|
13945
|
+
...corners(b).map((s) => [s, 2])
|
|
13946
|
+
].sort((x, y) => x[0] - y[0]);
|
|
13947
|
+
const same = SAME_X / Math.max(Math.abs(a.span), Math.abs(b.span));
|
|
13948
|
+
const merged = [];
|
|
13949
|
+
for (const [s, whose] of all) {
|
|
13950
|
+
var _stop, _stop2;
|
|
13951
|
+
let stop = merged[merged.length - 1];
|
|
13952
|
+
if (!stop || s - stop[0] > same || whose > 0 && stop[whose] !== void 0) merged.push(stop = [s]);
|
|
13953
|
+
if (whose === 1) (_stop = stop)[1] ?? (_stop[1] = s);
|
|
13954
|
+
if (whose === 2) (_stop2 = stop)[2] ?? (_stop2[2] = s);
|
|
13955
|
+
}
|
|
13956
|
+
const last = merged.length - 1;
|
|
13957
|
+
if (last < 1) return void 0;
|
|
13958
|
+
const shareOn = (whose) => merged.map((stop, k) => k === 0 ? 0 : k === last ? 1 : stop[whose] ?? stop[0]);
|
|
13959
|
+
const [onA, onB] = [shareOn(1), shareOn(2)];
|
|
13960
|
+
const [pointsA, pointsB] = [placed(a, onA), placed(b, onB)];
|
|
13961
|
+
const stops = merged.map(([t], k) => ({
|
|
13962
|
+
t,
|
|
13963
|
+
from: pointsA[k],
|
|
13964
|
+
to: pointsB[k]
|
|
13965
|
+
}));
|
|
13966
|
+
const [inA, inB] = [inside(a.gaps), inside(b.gaps)];
|
|
13967
|
+
return {
|
|
13968
|
+
stops,
|
|
13969
|
+
kinds: stops.slice(1).map((_, k) => (inA((onA[k] + onA[k + 1]) / 2) ? 1 : 0) + (inB((onB[k] + onB[k + 1]) / 2) ? 2 : 0))
|
|
13970
|
+
};
|
|
13971
|
+
}
|
|
13972
|
+
function courseOf(mark) {
|
|
13973
|
+
const subpaths = flattenPath(parsePath(mark.outline.d));
|
|
13974
|
+
const points = [];
|
|
13975
|
+
const before = [];
|
|
13976
|
+
let next = 0;
|
|
13977
|
+
let from = 0;
|
|
13978
|
+
const stretch = (to) => {
|
|
13979
|
+
if (!(to > from)) {
|
|
13980
|
+
points.push(mark.path(from));
|
|
13981
|
+
return true;
|
|
13982
|
+
}
|
|
13983
|
+
const subpath = subpaths[next++];
|
|
13984
|
+
if (!subpath) return false;
|
|
13985
|
+
points.push(subpath.start);
|
|
13986
|
+
for (const segment of subpath.segments) {
|
|
13987
|
+
if (segment.kind !== "line") return false;
|
|
13988
|
+
points.push(segment.to);
|
|
13989
|
+
}
|
|
13990
|
+
return true;
|
|
13991
|
+
};
|
|
13992
|
+
for (const [start, end] of mark.gaps ?? []) {
|
|
13993
|
+
if (!stretch(start)) return void 0;
|
|
13994
|
+
before.push(points.length - 1);
|
|
13995
|
+
from = end;
|
|
13996
|
+
}
|
|
13997
|
+
if (!stretch(1) || next < subpaths.length || points.length < 2) return void 0;
|
|
13998
|
+
const x0 = points[0].x;
|
|
13999
|
+
const span = points[points.length - 1].x - x0;
|
|
14000
|
+
const way = Math.sign(span);
|
|
14001
|
+
for (let i = 1; i < points.length; i++) if (!((points[i].x - points[i - 1].x) * way > 0)) return void 0;
|
|
14002
|
+
const shares = points.map((point) => (point.x - x0) / span);
|
|
14003
|
+
return {
|
|
14004
|
+
points,
|
|
14005
|
+
shares,
|
|
14006
|
+
gaps: before.map((i) => [shares[i], shares[i + 1]]),
|
|
14007
|
+
span,
|
|
14008
|
+
way
|
|
14009
|
+
};
|
|
14010
|
+
}
|
|
14011
|
+
function corners(course) {
|
|
14012
|
+
const { points, shares, gaps } = course;
|
|
14013
|
+
if (points.length <= VERTICES) return shares;
|
|
14014
|
+
const columns = VERTICES / 4;
|
|
14015
|
+
const column = (k) => Math.min(249, Math.floor(shares[k] * columns));
|
|
14016
|
+
const kept = gaps.flat();
|
|
14017
|
+
for (let first = 0, i = 1; i <= points.length; i++) {
|
|
14018
|
+
if (i < points.length && column(i) === column(first)) continue;
|
|
14019
|
+
let [low, high] = [first, first];
|
|
14020
|
+
for (let k = first; k < i; k++) {
|
|
14021
|
+
if (points[k].y < points[low].y) low = k;
|
|
14022
|
+
if (points[k].y > points[high].y) high = k;
|
|
14023
|
+
}
|
|
14024
|
+
kept.push(shares[first], shares[low], shares[high], shares[i - 1]);
|
|
14025
|
+
first = i;
|
|
14026
|
+
}
|
|
14027
|
+
return Array.from(new Set(kept));
|
|
14028
|
+
}
|
|
14029
|
+
function placed(course, shares) {
|
|
14030
|
+
const { points, shares: at } = course;
|
|
14031
|
+
let i = 0;
|
|
14032
|
+
return shares.map((s) => {
|
|
14033
|
+
while (i + 2 < points.length && at[i + 1] <= s) i++;
|
|
14034
|
+
const width = at[i + 1] - at[i];
|
|
14035
|
+
return mixed(points[i], points[i + 1], width > 0 ? Math.min(1, Math.max(0, (s - at[i]) / width)) : 0);
|
|
14036
|
+
});
|
|
14037
|
+
}
|
|
14038
|
+
function inside(gaps) {
|
|
14039
|
+
let k = 0;
|
|
14040
|
+
return (s) => {
|
|
14041
|
+
while (k < gaps.length && gaps[k][1] <= s) k++;
|
|
14042
|
+
return k < gaps.length && gaps[k][0] < s;
|
|
14043
|
+
};
|
|
14044
|
+
}
|
|
14045
|
+
function holePairs(from, to, a, b, [shiftA, shiftB], count) {
|
|
14046
|
+
const holesA = holesOf(from.outline, count);
|
|
14047
|
+
const holesB = holesOf(to.outline, count);
|
|
14048
|
+
const both = Math.min(holesA.length, holesB.length);
|
|
14049
|
+
const pairs = holesA.slice(0, both).map((hole, k) => ({
|
|
14050
|
+
from: hole.points,
|
|
14051
|
+
to: holesB[k].points
|
|
14052
|
+
}));
|
|
14053
|
+
const closes = holesA.length > holesB.length;
|
|
14054
|
+
const [ownHoles, otherHoles, other, own, theirs, ownShift, otherShift] = closes ? [
|
|
14055
|
+
holesA,
|
|
14056
|
+
holesB,
|
|
14057
|
+
to,
|
|
14058
|
+
a,
|
|
14059
|
+
b,
|
|
14060
|
+
shiftA,
|
|
14061
|
+
shiftB
|
|
14062
|
+
] : [
|
|
14063
|
+
holesB,
|
|
14064
|
+
holesA,
|
|
14065
|
+
from,
|
|
14066
|
+
b,
|
|
14067
|
+
a,
|
|
14068
|
+
shiftB,
|
|
14069
|
+
shiftA
|
|
14070
|
+
];
|
|
14071
|
+
const n = own.length;
|
|
14072
|
+
const outside = own.map((_, i) => [own[(i + ownShift) % n], theirs[(i + otherShift) % n]]);
|
|
14073
|
+
const inner = ownHoles.slice(0, both).map((hole, k) => hole.points.map((p, i) => [p, otherHoles[k].points[i]]));
|
|
14074
|
+
const area = [theirs, ...otherHoles.map((hole) => hole.points)];
|
|
14075
|
+
for (const hole of ownHoles.slice(both)) {
|
|
14076
|
+
const { end, point } = closing(hole, landing(hole, (closes ? from : to).bounds, other, area), outside, inner);
|
|
14077
|
+
const dot = new Array(count).fill(point);
|
|
14078
|
+
pairs.push(closes ? {
|
|
14079
|
+
from: hole.points,
|
|
14080
|
+
to: dot,
|
|
14081
|
+
end
|
|
14082
|
+
} : {
|
|
14083
|
+
from: dot,
|
|
14084
|
+
to: hole.points,
|
|
14085
|
+
end,
|
|
14086
|
+
opens: true
|
|
14087
|
+
});
|
|
14088
|
+
}
|
|
14089
|
+
return pairs;
|
|
14090
|
+
}
|
|
14091
|
+
function closing(hole, there, outside, inner) {
|
|
14092
|
+
let end = .5;
|
|
14093
|
+
while (end > 1 / 16 && !stays(hole, mixed(hole.center, there, end), end, outside, inner)) end /= 2;
|
|
14094
|
+
return {
|
|
14095
|
+
end,
|
|
14096
|
+
point: mixed(hole.center, there, end)
|
|
14097
|
+
};
|
|
14098
|
+
}
|
|
14099
|
+
function stays(hole, point, end, outside, inner) {
|
|
14100
|
+
for (let j = 1; j < CHECKS; j++) {
|
|
14101
|
+
const t = end * j / CHECKS;
|
|
14102
|
+
const at = (path) => mixed(path[0], path[1], t);
|
|
14103
|
+
const area = [outside.map(at), ...inner.map((ring) => ring.map(at))];
|
|
14104
|
+
if (hole.points.some((p) => windingAt(mixed(p, point, j / CHECKS), area) === 0)) return false;
|
|
14105
|
+
}
|
|
14106
|
+
return true;
|
|
14107
|
+
}
|
|
14108
|
+
function holeAt({ from, to, end, opens }, p) {
|
|
14109
|
+
if (end === void 0) return between(from, to, 0, 0, p, true);
|
|
14110
|
+
const q = opens ? (p - (1 - end)) / end : p / end;
|
|
14111
|
+
return (opens ? q <= 0 : q >= 1) ? "" : between(from, to, 0, 0, q, true);
|
|
14112
|
+
}
|
|
14113
|
+
const mixed = (a, b, t) => ({
|
|
14114
|
+
x: mix(a.x, b.x, t),
|
|
14115
|
+
y: mix(a.y, b.y, t)
|
|
14116
|
+
});
|
|
14117
|
+
function landing(hole, own, other, area) {
|
|
14118
|
+
const place = placeIn(hole.center, own, other.bounds);
|
|
14119
|
+
if (depth(place, area) >= hole.size / 4) return place;
|
|
14120
|
+
const { x, y, width, height } = other.bounds;
|
|
14121
|
+
let best = other.center;
|
|
14122
|
+
let deepest = depth(best, area);
|
|
14123
|
+
for (let i = 0; i < GRID; i++) for (let j = 0; j < GRID; j++) {
|
|
14124
|
+
const point = {
|
|
14125
|
+
x: x + width * (i + .5) / GRID,
|
|
14126
|
+
y: y + height * (j + .5) / GRID
|
|
14127
|
+
};
|
|
14128
|
+
const d = depth(point, area);
|
|
14129
|
+
if (d > deepest) [best, deepest] = [point, d];
|
|
14130
|
+
}
|
|
14131
|
+
return best;
|
|
14132
|
+
}
|
|
14133
|
+
function depth(point, area) {
|
|
14134
|
+
if (windingAt(point, area) === 0) return 0;
|
|
14135
|
+
let nearest = Infinity;
|
|
14136
|
+
for (const ring of area) ring.forEach((p, i) => {
|
|
14137
|
+
const q = ring[(i + 1) % ring.length];
|
|
14138
|
+
const dx = q.x - p.x;
|
|
14139
|
+
const dy = q.y - p.y;
|
|
14140
|
+
const u = dx === 0 && dy === 0 ? 0 : Math.max(0, Math.min(1, ((point.x - p.x) * dx + (point.y - p.y) * dy) / (dx * dx + dy * dy)));
|
|
14141
|
+
nearest = Math.min(nearest, Math.hypot(point.x - p.x - u * dx, point.y - p.y - u * dy));
|
|
14142
|
+
});
|
|
14143
|
+
return nearest;
|
|
14144
|
+
}
|
|
14145
|
+
function windingAt(point, area) {
|
|
14146
|
+
let winding = 0;
|
|
14147
|
+
for (const ring of area) ring.forEach((p, i) => {
|
|
14148
|
+
const q = ring[(i + 1) % ring.length];
|
|
14149
|
+
const side = (q.x - p.x) * (point.y - p.y) - (point.x - p.x) * (q.y - p.y);
|
|
14150
|
+
if (p.y <= point.y && q.y > point.y && side > 0) winding++;
|
|
14151
|
+
else if (p.y > point.y && q.y <= point.y && side < 0) winding--;
|
|
14152
|
+
});
|
|
14153
|
+
return winding;
|
|
14154
|
+
}
|
|
14155
|
+
function placeIn(point, own, other) {
|
|
14156
|
+
const fraction = (value, start, size) => size > 0 ? (value - start) / size : .5;
|
|
14157
|
+
return {
|
|
14158
|
+
x: other.x + fraction(point.x, own.x, own.width) * other.width,
|
|
14159
|
+
y: other.y + fraction(point.y, own.y, own.height) * other.height
|
|
14160
|
+
};
|
|
14161
|
+
}
|
|
14162
|
+
function holesOf(outline, count) {
|
|
14163
|
+
const loops = flattenPath(parsePath(outline.d)).map((subpath) => subpath.segments).filter((segments) => segments.length > 0);
|
|
14164
|
+
if (loops.length < 2) return [];
|
|
14165
|
+
const lengths = loops.map((loop) => loop.reduce((sum, segment) => sum + segment.length, 0));
|
|
14166
|
+
let longest = 0;
|
|
14167
|
+
lengths.forEach((length, i) => {
|
|
14168
|
+
if (length > lengths[longest] + Math.max(.01, lengths[longest] / 1e3)) longest = i;
|
|
14169
|
+
});
|
|
14170
|
+
return loops.filter((_, i) => i !== longest).map((loop) => {
|
|
14171
|
+
const round = loopOutline([loop]).sample(4 * count);
|
|
14172
|
+
const points = round.filter((_, i) => i % 4 === 0);
|
|
14173
|
+
const box = boundsOf(loop.flatMap(extremes));
|
|
14174
|
+
return {
|
|
14175
|
+
points: [points[0], ...points.slice(1).reverse()],
|
|
14176
|
+
area: Math.abs(areaOf(round)),
|
|
14177
|
+
center: {
|
|
14178
|
+
x: box.x + box.width / 2,
|
|
14179
|
+
y: box.y + box.height / 2
|
|
14180
|
+
},
|
|
14181
|
+
size: Math.max(box.width, box.height) / 2
|
|
14182
|
+
};
|
|
14183
|
+
}).sort((x, y) => y.area - x.area);
|
|
14184
|
+
}
|
|
14185
|
+
function areaOf(points) {
|
|
14186
|
+
let sum = 0;
|
|
14187
|
+
points.forEach((p, i) => {
|
|
14188
|
+
const q = points[(i + 1) % points.length];
|
|
14189
|
+
sum += p.x * q.y - q.x * p.y;
|
|
14190
|
+
});
|
|
14191
|
+
return sum / 2;
|
|
14192
|
+
}
|
|
13199
14193
|
function crossfade(from, to, layer) {
|
|
13200
14194
|
const paint = (mark, opacity) => ({
|
|
13201
14195
|
...mark.outline.closed ? { fill: "mark" } : {
|
|
@@ -13229,13 +14223,10 @@ function crossfade(from, to, layer) {
|
|
|
13229
14223
|
function between(a, b, shiftA, shiftB, p, closed) {
|
|
13230
14224
|
const n = a.length;
|
|
13231
14225
|
let d = "";
|
|
13232
|
-
for (let i = 0; i < n; i++) {
|
|
13233
|
-
const from = a[(i + shiftA) % n];
|
|
13234
|
-
const to = b[(i + shiftB) % n];
|
|
13235
|
-
d += `${i === 0 ? "M" : "L"}${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
|
|
13236
|
-
}
|
|
14226
|
+
for (let i = 0; i < n; i++) d += `${i === 0 ? "M" : "L"}${at(a[(i + shiftA) % n], b[(i + shiftB) % n], p)}`;
|
|
13237
14227
|
return closed ? `${d}Z` : d;
|
|
13238
14228
|
}
|
|
14229
|
+
const at = (from, to, p) => `${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
|
|
13239
14230
|
const mix = (x, y, p) => x * (1 - p) + y * p;
|
|
13240
14231
|
function turn(from, to, points) {
|
|
13241
14232
|
const quarter = points / 4;
|
|
@@ -13845,7 +14836,7 @@ function configure(options) {
|
|
|
13845
14836
|
}
|
|
13846
14837
|
}
|
|
13847
14838
|
// src/index.ts
|
|
13848
|
-
const VERSION = "0.
|
|
14839
|
+
const VERSION = "0.7.0";
|
|
13849
14840
|
const env = {
|
|
13850
14841
|
presets: presetRegistry,
|
|
13851
14842
|
icons: iconRegistry,
|
|
@@ -13891,6 +14882,7 @@ exports.defineIcon = defineIcon;
|
|
|
13891
14882
|
exports.delta = delta;
|
|
13892
14883
|
exports.describe = describe;
|
|
13893
14884
|
exports.donutChart = donutChart;
|
|
14885
|
+
exports.drawIn = drawIn;
|
|
13894
14886
|
exports.easeInOutCubic = easeInOutCubic;
|
|
13895
14887
|
exports.easeOutCubic = easeOutCubic;
|
|
13896
14888
|
exports.expressive = expressive;
|