expressive-charts 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +8 -8
- package/dist/{drawing-Ypmq-2h6.d.ts → drawing-OmQV-0BB.d.cts} +8 -2
- package/dist/{drawing-Ypmq-2h6.d.cts → drawing-OmQV-0BB.d.ts} +8 -2
- package/dist/{effect-D8W4ZmmG.d.cts → effect-DYCLY_6e.d.cts} +2 -2
- package/dist/{effect-DyzluQD1.d.ts → effect-HCWnmB72.d.ts} +2 -2
- package/dist/expressive-charts.global.js +10 -10
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.d.cts +1 -1
- package/dist/icons/sport.d.ts +1 -1
- package/dist/index.cjs +768 -193
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -22
- package/dist/index.d.ts +80 -22
- package/dist/index.js +768 -194
- package/dist/index.js.map +1 -1
- package/dist/testing.d.cts +2 -2
- package/dist/testing.d.ts +2 -2
- package/package.json +3 -3
package/dist/index.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)}.`);
|
|
@@ -2752,8 +2752,10 @@ function layoutBars(input) {
|
|
|
2752
2752
|
const domain = niceDomain(rows.map((row) => row.total));
|
|
2753
2753
|
const texts = rows.map((row) => input.format(row.total));
|
|
2754
2754
|
const ticks = domain.ticks.map(input.format);
|
|
2755
|
-
const
|
|
2756
|
-
|
|
2755
|
+
const make = (values) => (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows, domain, values, ticks);
|
|
2756
|
+
let frame = make(texts);
|
|
2757
|
+
let labels = thinLabels(frame, rows, texts, input.measure);
|
|
2758
|
+
if (!labels.values) labels = thinLabels(frame = make(), rows, texts, input.measure, false);
|
|
2757
2759
|
return {
|
|
2758
2760
|
width: frame.bands.width,
|
|
2759
2761
|
height: frame.bands.height,
|
|
@@ -2772,10 +2774,10 @@ function layoutBars(input) {
|
|
|
2772
2774
|
labels
|
|
2773
2775
|
};
|
|
2774
2776
|
}
|
|
2775
|
-
function thinLabels(frame, rows, texts, measure) {
|
|
2777
|
+
function thinLabels(frame, rows, texts, measure, values = true) {
|
|
2776
2778
|
const placed = rows.map((row, slot) => placeLabels$1(frame, slot, row.total, row.category, texts[slot]));
|
|
2777
2779
|
const horizontal = frame.orientation === "horizontal";
|
|
2778
|
-
|
|
2780
|
+
values && (values = !overlaps$1(boxesOf(placed.map(({ value }) => value), measure, "ec-value", VALUE_SIZE$2), horizontal));
|
|
2779
2781
|
const categories = (every) => boxesOf(placed.filter((_, slot) => slot % every === 0).map(({ label }) => label), measure, "ec-label", LABEL_SIZE$1);
|
|
2780
2782
|
let k = 0;
|
|
2781
2783
|
while (thinStep(k) < rows.length && overlaps$1(categories(thinStep(k)), horizontal)) k++;
|
|
@@ -3020,12 +3022,12 @@ function horizontalFrame(input, rows, domain, values, ticks) {
|
|
|
3020
3022
|
const { width, measure } = input;
|
|
3021
3023
|
const n = rows.length;
|
|
3022
3024
|
const labelWidth = widest$1(rows.map((row) => row.category), "ec-label", LABEL_SIZE$1, measure);
|
|
3023
|
-
const
|
|
3025
|
+
const valueRoom = values ? widest$1(values, "ec-value", VALUE_SIZE$2, measure) + PAD$1 : 0;
|
|
3024
3026
|
const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
|
|
3025
3027
|
const { positive, negative } = reach(input, rows);
|
|
3026
|
-
const negativeRoom = domain.lo < 0 ?
|
|
3028
|
+
const negativeRoom = domain.lo < 0 ? valueRoom : 0;
|
|
3027
3029
|
const left = Math.max(labelWidth + 10 + negativeRoom + negative, tickWidth / 2 + 2);
|
|
3028
|
-
const right = Math.max(
|
|
3030
|
+
const right = Math.max(valueRoom + 4 + positive, tickWidth / 2 + 2);
|
|
3029
3031
|
const rowSize = input.height === void 0 || n === 0 ? ROW : Math.max(0, input.height - TOP$1 - AXIS$1) / n;
|
|
3030
3032
|
return {
|
|
3031
3033
|
orientation: "horizontal",
|
|
@@ -3046,15 +3048,15 @@ function horizontalFrame(input, rows, domain, values, ticks) {
|
|
|
3046
3048
|
}
|
|
3047
3049
|
};
|
|
3048
3050
|
}
|
|
3049
|
-
function verticalFrame(input, rows, domain,
|
|
3051
|
+
function verticalFrame(input, rows, domain, values, ticks) {
|
|
3050
3052
|
const { width, measure } = input;
|
|
3051
3053
|
const n = rows.length;
|
|
3052
3054
|
const height = input.height ?? VERTICAL_HEIGHT;
|
|
3053
3055
|
const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
|
|
3054
3056
|
const { positive, negative } = reach(input, rows);
|
|
3055
|
-
const top = (domain.hi > 0 ? 20.5 : TOP$1) + positive;
|
|
3056
|
-
const
|
|
3057
|
-
const bottom = AXIS$1 +
|
|
3057
|
+
const top = (values && domain.hi > 0 ? 20.5 : TOP$1) + positive;
|
|
3058
|
+
const under = values && domain.lo < 0 ? 18.5 : 0;
|
|
3059
|
+
const bottom = AXIS$1 + under + negative;
|
|
3058
3060
|
const left = tickWidth + 8 + 2;
|
|
3059
3061
|
const plot = {
|
|
3060
3062
|
x: left,
|
|
@@ -3071,7 +3073,7 @@ function verticalFrame(input, rows, domain, _values, ticks) {
|
|
|
3071
3073
|
hi: domain.hi,
|
|
3072
3074
|
from: base,
|
|
3073
3075
|
extent: -plot.height,
|
|
3074
|
-
label: base +
|
|
3076
|
+
label: base + under + 18
|
|
3075
3077
|
},
|
|
3076
3078
|
bands: {
|
|
3077
3079
|
start: plot.x,
|
|
@@ -3757,7 +3759,7 @@ function mix$3(colors, emphasis) {
|
|
|
3757
3759
|
// src/charts/render/layer.ts
|
|
3758
3760
|
const FOLLOW = "ec-follow";
|
|
3759
3761
|
let clipIds = 0;
|
|
3760
|
-
function svgLayer(group, follow) {
|
|
3762
|
+
function svgLayer(group, follow, parts) {
|
|
3761
3763
|
const into = () => {
|
|
3762
3764
|
if (!follow) return group;
|
|
3763
3765
|
const last = group.lastElementChild;
|
|
@@ -3796,13 +3798,13 @@ function svgLayer(group, follow) {
|
|
|
3796
3798
|
d
|
|
3797
3799
|
}, into());
|
|
3798
3800
|
let current = { ...paint };
|
|
3799
|
-
paintPath(element, current);
|
|
3801
|
+
paintPath(element, current, parts);
|
|
3800
3802
|
return {
|
|
3801
3803
|
update(next, nextPaint) {
|
|
3802
3804
|
element.setAttribute("d", next);
|
|
3803
3805
|
if (nextPaint) {
|
|
3804
3806
|
current = mergeFields(current, nextPaint);
|
|
3805
|
-
paintPath(element, current);
|
|
3807
|
+
paintPath(element, current, parts);
|
|
3806
3808
|
}
|
|
3807
3809
|
},
|
|
3808
3810
|
remove: () => element.remove()
|
|
@@ -3846,14 +3848,17 @@ function drawShape(shape, parent) {
|
|
|
3846
3848
|
stroke: shape.stroke === void 0 ? void 0 : cssColor(shape.stroke)
|
|
3847
3849
|
});
|
|
3848
3850
|
}
|
|
3849
|
-
function paintPath(element, paint) {
|
|
3851
|
+
function paintPath(element, paint, parts) {
|
|
3852
|
+
const { part } = paint;
|
|
3850
3853
|
setAttributes(element, {
|
|
3851
3854
|
"stroke-width": paint.stroke === void 0 ? void 0 : paint.width ?? 1,
|
|
3852
3855
|
opacity: paint.opacity,
|
|
3853
3856
|
"stroke-linecap": paint.linecap,
|
|
3854
|
-
"stroke-linejoin": "round"
|
|
3857
|
+
"stroke-linejoin": "round",
|
|
3858
|
+
"data-part": part
|
|
3855
3859
|
});
|
|
3856
3860
|
setStyles(element, {
|
|
3861
|
+
...markColorStyles(part === void 0 ? void 0 : parts?.(part)),
|
|
3857
3862
|
fill: paint.fill === void 0 ? "none" : cssColor(paint.fill),
|
|
3858
3863
|
stroke: paint.stroke === void 0 ? void 0 : cssColor(paint.stroke)
|
|
3859
3864
|
});
|
|
@@ -3898,7 +3903,7 @@ function svgSurface(options) {
|
|
|
3898
3903
|
live.add(group);
|
|
3899
3904
|
const owner = live;
|
|
3900
3905
|
return {
|
|
3901
|
-
...svgLayer(group, () => transforms.get(key)),
|
|
3906
|
+
...svgLayer(group, () => transforms.get(key), (part) => options.colors(key, part)),
|
|
3902
3907
|
clear() {
|
|
3903
3908
|
group.remove();
|
|
3904
3909
|
owner.delete(group);
|
|
@@ -3929,7 +3934,10 @@ function svgSurface(options) {
|
|
|
3929
3934
|
const live = groups.get(key);
|
|
3930
3935
|
if (!live) return;
|
|
3931
3936
|
const styles = markColorStyles(options.colors(key));
|
|
3932
|
-
for (const group of live)
|
|
3937
|
+
for (const group of live) {
|
|
3938
|
+
setStyles(group, styles);
|
|
3939
|
+
for (const path of group.querySelectorAll("[data-part]")) setStyles(path, markColorStyles(options.colors(key, path.getAttribute("data-part"))));
|
|
3940
|
+
}
|
|
3933
3941
|
},
|
|
3934
3942
|
hide(key, hide) {
|
|
3935
3943
|
if (hide) hidden.add(key);
|
|
@@ -4366,6 +4374,14 @@ function keyboardFocus(svg, options) {
|
|
|
4366
4374
|
last = keys;
|
|
4367
4375
|
return had === void 0 ? void 0 : current;
|
|
4368
4376
|
},
|
|
4377
|
+
moveTabStop(key) {
|
|
4378
|
+
listen();
|
|
4379
|
+
const keys = options.order();
|
|
4380
|
+
if (!keys.includes(key) || options.find(on?.scope.activeElement ?? null) !== void 0) return false;
|
|
4381
|
+
tabStop = key;
|
|
4382
|
+
applyTabIndex(keys);
|
|
4383
|
+
return true;
|
|
4384
|
+
},
|
|
4369
4385
|
destroy() {
|
|
4370
4386
|
current = void 0;
|
|
4371
4387
|
focused = void 0;
|
|
@@ -4403,6 +4419,11 @@ function chartHover(options) {
|
|
|
4403
4419
|
}] : [];
|
|
4404
4420
|
});
|
|
4405
4421
|
const marksFor = (keys) => keys.length === 1 ? marksOf(keys[0]) : [...new Set(keys.flatMap(marksOf))];
|
|
4422
|
+
const standIns = (keys) => keys.flatMap((key) => {
|
|
4423
|
+
const input = options.standIn?.(key);
|
|
4424
|
+
return input ? [input] : [];
|
|
4425
|
+
});
|
|
4426
|
+
const standingFor = (keys, source, marks) => source === "linked" && marks.length === 0 ? keys.find((key) => options.standIn?.(key) !== void 0) : void 0;
|
|
4406
4427
|
function hoverMarks(marks, source, effects, segment) {
|
|
4407
4428
|
if (marks.length === 0) return;
|
|
4408
4429
|
if (effects) runner.hover(marks.map(({ input }) => input));
|
|
@@ -4433,11 +4454,13 @@ function chartHover(options) {
|
|
|
4433
4454
|
}
|
|
4434
4455
|
function startHover(keys, source, segment, effects = true) {
|
|
4435
4456
|
const marks = onScreen(marksFor(keys));
|
|
4457
|
+
const standing = standingFor(keys, source, marks);
|
|
4436
4458
|
const started = {
|
|
4437
4459
|
keys,
|
|
4438
4460
|
source,
|
|
4439
4461
|
marks: marks.map((mark) => mark.key),
|
|
4440
|
-
effects
|
|
4462
|
+
effects,
|
|
4463
|
+
standing
|
|
4441
4464
|
};
|
|
4442
4465
|
hovered = started;
|
|
4443
4466
|
for (const { key: mark } of marks) heat(mark, true);
|
|
@@ -4446,8 +4469,9 @@ function chartHover(options) {
|
|
|
4446
4469
|
options.tooltip.show(keys[0]);
|
|
4447
4470
|
listenForEscape(true);
|
|
4448
4471
|
}
|
|
4472
|
+
if (standing !== void 0) options.stand?.(standing);
|
|
4449
4473
|
hoverMarks(marks, source, effects, segment);
|
|
4450
|
-
if (source !== "linked" && hovered === started) linked?.hover(marks.map(({ input }) => input));
|
|
4474
|
+
if (source !== "linked" && hovered === started) linked?.hover(marks.length > 0 ? marks.map(({ input }) => input) : standIns(keys));
|
|
4451
4475
|
}
|
|
4452
4476
|
function endHover() {
|
|
4453
4477
|
const ended = hovered;
|
|
@@ -4455,6 +4479,7 @@ function chartHover(options) {
|
|
|
4455
4479
|
listenForEscape(false);
|
|
4456
4480
|
svg.classList.remove("ec-hovering");
|
|
4457
4481
|
options.tooltip.hide();
|
|
4482
|
+
if (ended?.standing !== void 0) options.stand?.(void 0);
|
|
4458
4483
|
leaveMarks(ended?.marks ?? []);
|
|
4459
4484
|
if (own(ended)) linked?.leave();
|
|
4460
4485
|
}
|
|
@@ -4533,14 +4558,20 @@ function chartHover(options) {
|
|
|
4533
4558
|
get key() {
|
|
4534
4559
|
return own(hovered) ? hovered.keys[0] : void 0;
|
|
4535
4560
|
},
|
|
4561
|
+
get standing() {
|
|
4562
|
+
return hovered?.standing;
|
|
4563
|
+
},
|
|
4536
4564
|
get ringKey() {
|
|
4537
4565
|
return ringKey;
|
|
4538
4566
|
},
|
|
4539
4567
|
link: {
|
|
4540
|
-
targets: () => options.order().map((key) =>
|
|
4541
|
-
key
|
|
4542
|
-
|
|
4543
|
-
|
|
4568
|
+
targets: () => options.order().map((key) => {
|
|
4569
|
+
const marks = onScreen(marksOf(key)).map(({ input }) => input);
|
|
4570
|
+
return {
|
|
4571
|
+
key,
|
|
4572
|
+
marks: marks.length > 0 ? marks : standIns([key])
|
|
4573
|
+
};
|
|
4574
|
+
}),
|
|
4544
4575
|
hover(keys, effects) {
|
|
4545
4576
|
if (hovered !== void 0) endHover();
|
|
4546
4577
|
const live = keys.filter(options.live);
|
|
@@ -4576,9 +4607,12 @@ function chartHover(options) {
|
|
|
4576
4607
|
}
|
|
4577
4608
|
const { source, marks: before, effects } = hovered;
|
|
4578
4609
|
const now = onScreen(marksFor(keys));
|
|
4610
|
+
const standing = standingFor(keys, source, now);
|
|
4611
|
+
if (standing !== hovered.standing) options.stand?.(standing);
|
|
4579
4612
|
hovered = {
|
|
4580
4613
|
...hovered,
|
|
4581
|
-
keys
|
|
4614
|
+
keys,
|
|
4615
|
+
standing
|
|
4582
4616
|
};
|
|
4583
4617
|
if (now.length === before.length && now.every((mark, i) => mark.key === before[i])) return;
|
|
4584
4618
|
const had = new Set(before);
|
|
@@ -4623,6 +4657,7 @@ function chartHover(options) {
|
|
|
4623
4657
|
focus(key) {
|
|
4624
4658
|
if (options.live(key)) keyboard.focus(key);
|
|
4625
4659
|
},
|
|
4660
|
+
moveTabStop: (key) => options.live(key) && keyboard.moveTabStop(key),
|
|
4626
4661
|
leave,
|
|
4627
4662
|
destroy() {
|
|
4628
4663
|
destroyed = true;
|
|
@@ -4759,6 +4794,10 @@ function tableModel(input) {
|
|
|
4759
4794
|
text: "",
|
|
4760
4795
|
numeric: false
|
|
4761
4796
|
});
|
|
4797
|
+
const missing = {
|
|
4798
|
+
text: input.missing ?? "missing",
|
|
4799
|
+
numeric: true
|
|
4800
|
+
};
|
|
4762
4801
|
const headers = [
|
|
4763
4802
|
{
|
|
4764
4803
|
text: options.category ?? input.category ?? "Category",
|
|
@@ -4789,10 +4828,7 @@ function tableModel(input) {
|
|
|
4789
4828
|
numeric: false
|
|
4790
4829
|
},
|
|
4791
4830
|
...first.map((column) => columnCell(column, row, format)),
|
|
4792
|
-
...input.series.map((series) => row.missing?.has(series) ?
|
|
4793
|
-
text: MISSING,
|
|
4794
|
-
numeric: true
|
|
4795
|
-
} : number(values.get(series) ?? 0)),
|
|
4831
|
+
...input.series.map((series) => row.missing?.has(series) ? missing : number(values.get(series) ?? 0)),
|
|
4796
4832
|
...totals ? [number(row.total)] : [],
|
|
4797
4833
|
...share(row.total),
|
|
4798
4834
|
...last.map((column) => columnCell(column, row, format))
|
|
@@ -5161,6 +5197,41 @@ function watchFonts(doc, loaded) {
|
|
|
5161
5197
|
fonts?.addEventListener?.("loadingdone", loaded);
|
|
5162
5198
|
return () => fonts?.removeEventListener?.("loadingdone", loaded);
|
|
5163
5199
|
}
|
|
5200
|
+
const PROBE_TEXT = "Hamburgefonstiv 0123456789";
|
|
5201
|
+
function watchText(svg, clock, changed) {
|
|
5202
|
+
if (typeof ResizeObserver !== "function") return () => {};
|
|
5203
|
+
const probe = svgElement("text", {
|
|
5204
|
+
"font-size": 11,
|
|
5205
|
+
visibility: "hidden",
|
|
5206
|
+
"pointer-events": "none",
|
|
5207
|
+
"aria-hidden": "true"
|
|
5208
|
+
}, svg);
|
|
5209
|
+
probe.textContent = PROBE_TEXT;
|
|
5210
|
+
let measured = 0;
|
|
5211
|
+
let pending = 0;
|
|
5212
|
+
let stopFrame;
|
|
5213
|
+
const observer = new ResizeObserver((entries) => {
|
|
5214
|
+
const next = entries.find((entry) => entry.target === probe)?.contentRect.width ?? 0;
|
|
5215
|
+
if (!(next > 0) || Math.abs(next - pending) < .5) return;
|
|
5216
|
+
pending = next;
|
|
5217
|
+
if (!measured) {
|
|
5218
|
+
measured = next;
|
|
5219
|
+
return;
|
|
5220
|
+
}
|
|
5221
|
+
stopFrame ?? (stopFrame = clock.onFrame(() => {
|
|
5222
|
+
stopFrame?.();
|
|
5223
|
+
stopFrame = void 0;
|
|
5224
|
+
if (Math.abs(pending - measured) < .5) return;
|
|
5225
|
+
measured = pending;
|
|
5226
|
+
changed();
|
|
5227
|
+
}));
|
|
5228
|
+
});
|
|
5229
|
+
observer.observe(probe);
|
|
5230
|
+
return () => {
|
|
5231
|
+
observer.disconnect();
|
|
5232
|
+
stopFrame?.();
|
|
5233
|
+
};
|
|
5234
|
+
}
|
|
5164
5235
|
function watchHoverDuration(svg, motion) {
|
|
5165
5236
|
const sync = () => svg.style.setProperty("--ec-hover-duration", `${motion.duration(100, "feedback")}ms`);
|
|
5166
5237
|
sync();
|
|
@@ -5208,7 +5279,7 @@ function chartTooltip(svg, options) {
|
|
|
5208
5279
|
if (x > left && x < right && y > top && y < bottom) return true;
|
|
5209
5280
|
if (!shape) return false;
|
|
5210
5281
|
const origin = layer.getBoundingClientRect();
|
|
5211
|
-
return inside$
|
|
5282
|
+
return inside$2(shape, x - origin.left, y - origin.top);
|
|
5212
5283
|
};
|
|
5213
5284
|
const letThrough = (on) => {
|
|
5214
5285
|
through = on;
|
|
@@ -5397,7 +5468,7 @@ function chartTooltip(svg, options) {
|
|
|
5397
5468
|
}
|
|
5398
5469
|
};
|
|
5399
5470
|
}
|
|
5400
|
-
function inside$
|
|
5471
|
+
function inside$2({ top, bottom, upper, lower }, x, y) {
|
|
5401
5472
|
if (y <= top || y >= bottom) return false;
|
|
5402
5473
|
const t = (y - top) / (bottom - top);
|
|
5403
5474
|
return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
|
|
@@ -5484,7 +5555,7 @@ function viewBox$1(svg) {
|
|
|
5484
5555
|
const STAGE$2 = 500;
|
|
5485
5556
|
function barChart$1(target, options, env) {
|
|
5486
5557
|
const container = resolveTarget$2(target, "barChart");
|
|
5487
|
-
checkOptions$
|
|
5558
|
+
checkOptions$14(options);
|
|
5488
5559
|
let current = options;
|
|
5489
5560
|
const motion = chartMotion(options.motion, env.motion);
|
|
5490
5561
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -5554,7 +5625,7 @@ function barChart$1(target, options, env) {
|
|
|
5554
5625
|
hover.restyled(key);
|
|
5555
5626
|
}
|
|
5556
5627
|
}),
|
|
5557
|
-
colors: (key) => find(key)?.parts[0]?.colors
|
|
5628
|
+
colors: (key, part) => find(key)?.parts[part === void 0 ? 0 : (find(key)?.shown.geometry.segments ?? []).findIndex((segment) => segment.key === part)]?.colors
|
|
5558
5629
|
});
|
|
5559
5630
|
const runner = createRunner({
|
|
5560
5631
|
effects,
|
|
@@ -5641,6 +5712,10 @@ function barChart$1(target, options, env) {
|
|
|
5641
5712
|
series: row.values.map((v) => v.series),
|
|
5642
5713
|
slot: animated(row.slot, interpolateNumber, env),
|
|
5643
5714
|
presence: animated(entering ? 0 : 1, interpolateNumber, env),
|
|
5715
|
+
drawn: {
|
|
5716
|
+
label: animated(Number(row.drawn.label), interpolateNumber, env),
|
|
5717
|
+
value: animated(Number(row.drawn.value), interpolateNumber, env)
|
|
5718
|
+
},
|
|
5644
5719
|
count: void 0,
|
|
5645
5720
|
leave: void 0
|
|
5646
5721
|
};
|
|
@@ -5649,15 +5724,17 @@ function barChart$1(target, options, env) {
|
|
|
5649
5724
|
return record;
|
|
5650
5725
|
}
|
|
5651
5726
|
function drawMark(record, row) {
|
|
5652
|
-
const before = record.parts
|
|
5727
|
+
const before = record.parts;
|
|
5653
5728
|
record.shown = row;
|
|
5654
5729
|
setAttributes(record.hit, { ...row.hit });
|
|
5655
5730
|
placeText(record.label, row.label);
|
|
5656
5731
|
placeText(record.value, row.value);
|
|
5657
|
-
const
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5732
|
+
const opacity = (drawn, fade) => {
|
|
5733
|
+
const shown = record.presence.value * (drawn ? fade.value : 1);
|
|
5734
|
+
return shown < 1 ? shown : void 0;
|
|
5735
|
+
};
|
|
5736
|
+
setAttributes(record.label, { opacity: opacity(row.drawn.label, record.drawn.label) });
|
|
5737
|
+
setAttributes(record.value, { opacity: opacity(row.drawn.value, record.drawn.value) });
|
|
5661
5738
|
const segments = row.geometry.segments ?? [];
|
|
5662
5739
|
const keep = /* @__PURE__ */ new Set();
|
|
5663
5740
|
const ownColors = byCategory(current) ? seriesColors(colors.slot(record.key)) : void 0;
|
|
@@ -5690,7 +5767,7 @@ function barChart$1(target, options, env) {
|
|
|
5690
5767
|
const drawn = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
|
|
5691
5768
|
if (record.parts.some((part, i) => drawn[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
|
|
5692
5769
|
record.handle.repaint();
|
|
5693
|
-
if (record.parts
|
|
5770
|
+
if (record.parts.length !== before.length || record.parts.some((part, i) => part.colors.color !== before[i].colors.color)) surface.recolor(record.key);
|
|
5694
5771
|
if (record.key === hover.ringKey) drawRing(record.key);
|
|
5695
5772
|
}
|
|
5696
5773
|
function drawRing(key) {
|
|
@@ -5797,6 +5874,10 @@ function barChart$1(target, options, env) {
|
|
|
5797
5874
|
}));
|
|
5798
5875
|
const total = values.reduce((sum, v) => sum + v.value, 0);
|
|
5799
5876
|
const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
|
|
5877
|
+
const drawn = {
|
|
5878
|
+
label: record.drawn.label.value > 0,
|
|
5879
|
+
value: record.drawn.value.value > 0
|
|
5880
|
+
};
|
|
5800
5881
|
return placeRow(frame, {
|
|
5801
5882
|
key: row.key,
|
|
5802
5883
|
datum: row.datum,
|
|
@@ -5805,7 +5886,7 @@ function barChart$1(target, options, env) {
|
|
|
5805
5886
|
values,
|
|
5806
5887
|
slot: record.slot.value,
|
|
5807
5888
|
text,
|
|
5808
|
-
drawn
|
|
5889
|
+
drawn
|
|
5809
5890
|
}, measure);
|
|
5810
5891
|
}
|
|
5811
5892
|
function addTick(value, opacity) {
|
|
@@ -5927,8 +6008,11 @@ function barChart$1(target, options, env) {
|
|
|
5927
6008
|
let first;
|
|
5928
6009
|
let second;
|
|
5929
6010
|
let grow;
|
|
6011
|
+
let out;
|
|
6012
|
+
let into;
|
|
5930
6013
|
if (!jump && motion.staged) {
|
|
5931
6014
|
const wait = values ? STAGE$2 : 0;
|
|
6015
|
+
const half = values && positions ? STAGE$2 : STAGE$2 / 2;
|
|
5932
6016
|
first = { duration: STAGE$2 };
|
|
5933
6017
|
second = {
|
|
5934
6018
|
duration: STAGE$2,
|
|
@@ -5938,6 +6022,11 @@ function barChart$1(target, options, env) {
|
|
|
5938
6022
|
duration: STAGE$2 / 2,
|
|
5939
6023
|
delay: wait + STAGE$2 / 2
|
|
5940
6024
|
};
|
|
6025
|
+
out = { duration: half };
|
|
6026
|
+
into = {
|
|
6027
|
+
duration: half,
|
|
6028
|
+
delay: half
|
|
6029
|
+
};
|
|
5941
6030
|
} else if (!jump) first = second = grow = { duration: (values && positions ? 2 : 1) * STAGE$2 };
|
|
5942
6031
|
const running = [];
|
|
5943
6032
|
const move = (value, to, equal, timing) => {
|
|
@@ -5948,6 +6037,13 @@ function barChart$1(target, options, env) {
|
|
|
5948
6037
|
move(scale, frame.scale, sameFields, first);
|
|
5949
6038
|
move(bands, frame.bands, sameFields, second);
|
|
5950
6039
|
for (const tick of ticks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
|
|
6040
|
+
for (const record of order) {
|
|
6041
|
+
const fades = !arriving.has(record);
|
|
6042
|
+
for (const part of ["label", "value"]) {
|
|
6043
|
+
const to = Number(record.row.drawn[part]);
|
|
6044
|
+
move(record.drawn[part], to, same, fades ? to ? into : out : void 0);
|
|
6045
|
+
}
|
|
6046
|
+
}
|
|
5951
6047
|
for (const record of staying) {
|
|
5952
6048
|
move(record.values, valuesOf(record.row), sameFields, first);
|
|
5953
6049
|
move(record.presence, 1, same, first);
|
|
@@ -6022,14 +6118,16 @@ function barChart$1(target, options, env) {
|
|
|
6022
6118
|
for (const record of order) record.row = rows.get(record.key) ?? record.row;
|
|
6023
6119
|
transitionTo(next, true);
|
|
6024
6120
|
}
|
|
6121
|
+
const remeasure = () => {
|
|
6122
|
+
measure.clear();
|
|
6123
|
+
relayout();
|
|
6124
|
+
};
|
|
6125
|
+
const unwatchText = watchText(svg, clock, remeasure);
|
|
6025
6126
|
const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
|
|
6026
6127
|
measuredWidth = width;
|
|
6027
6128
|
if (current.width === void 0) relayout();
|
|
6028
6129
|
});
|
|
6029
|
-
const unwatchFonts = watchFonts(doc,
|
|
6030
|
-
measure.clear();
|
|
6031
|
-
relayout();
|
|
6032
|
-
});
|
|
6130
|
+
const unwatchFonts = watchFonts(doc, remeasure);
|
|
6033
6131
|
describeChart(svg, current);
|
|
6034
6132
|
syncLegend(laidOut);
|
|
6035
6133
|
table.render(firstTable);
|
|
@@ -6053,7 +6151,7 @@ function barChart$1(target, options, env) {
|
|
|
6053
6151
|
...current,
|
|
6054
6152
|
...next
|
|
6055
6153
|
};
|
|
6056
|
-
checkOptions$
|
|
6154
|
+
checkOptions$14(merged);
|
|
6057
6155
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
6058
6156
|
const nextLayout = layout(merged, swapped);
|
|
6059
6157
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -6088,7 +6186,7 @@ function barChart$1(target, options, env) {
|
|
|
6088
6186
|
}, () => arrange(nextLayout), (diff) => {
|
|
6089
6187
|
if (announcing) announceChange(previous, diff);
|
|
6090
6188
|
});
|
|
6091
|
-
if (byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
|
|
6189
|
+
if ("colors" in next || byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
|
|
6092
6190
|
const settled = transitionTo(nextLayout, motion.mode === "off" || nextLayout.orientation !== orientation);
|
|
6093
6191
|
await transitions.wait(settled, leaves);
|
|
6094
6192
|
},
|
|
@@ -6109,6 +6207,7 @@ function barChart$1(target, options, env) {
|
|
|
6109
6207
|
drawn: true
|
|
6110
6208
|
};
|
|
6111
6209
|
},
|
|
6210
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
6112
6211
|
destroy() {
|
|
6113
6212
|
if (destroyed) return;
|
|
6114
6213
|
destroyed = true;
|
|
@@ -6120,13 +6219,16 @@ function barChart$1(target, options, env) {
|
|
|
6120
6219
|
table.destroy();
|
|
6121
6220
|
announcer?.destroy();
|
|
6122
6221
|
unwatchHoverDuration();
|
|
6222
|
+
unwatchText();
|
|
6123
6223
|
unwatchWidth();
|
|
6124
6224
|
unwatchFonts();
|
|
6125
6225
|
for (const record of [...order, ...leaving.values()]) {
|
|
6126
6226
|
for (const value of [
|
|
6127
6227
|
record.values,
|
|
6128
6228
|
record.slot,
|
|
6129
|
-
record.presence
|
|
6229
|
+
record.presence,
|
|
6230
|
+
record.drawn.label,
|
|
6231
|
+
record.drawn.value
|
|
6130
6232
|
]) value.stop();
|
|
6131
6233
|
record.leave?.resolve();
|
|
6132
6234
|
}
|
|
@@ -6141,7 +6243,7 @@ function barChart$1(target, options, env) {
|
|
|
6141
6243
|
}
|
|
6142
6244
|
});
|
|
6143
6245
|
}
|
|
6144
|
-
function checkOptions$
|
|
6246
|
+
function checkOptions$14(options) {
|
|
6145
6247
|
checkChartOptions(options, "barChart");
|
|
6146
6248
|
const { colorBy, room } = options;
|
|
6147
6249
|
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)}.`);
|
|
@@ -6445,7 +6547,7 @@ const TAU = 2 * Math.PI;
|
|
|
6445
6547
|
const VISIBLE$1 = .5;
|
|
6446
6548
|
function donutChart$1(target, options, env) {
|
|
6447
6549
|
const container = resolveTarget$2(target, "donutChart");
|
|
6448
|
-
checkOptions$
|
|
6550
|
+
checkOptions$13(options);
|
|
6449
6551
|
let current = options;
|
|
6450
6552
|
const motion = chartMotion(options.motion, env.motion);
|
|
6451
6553
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -6985,14 +7087,16 @@ function donutChart$1(target, options, env) {
|
|
|
6985
7087
|
for (const record of order) record.row = slices.get(record.key) ?? record.row;
|
|
6986
7088
|
transitionTo(next, true);
|
|
6987
7089
|
}
|
|
7090
|
+
const remeasure = () => {
|
|
7091
|
+
measure.clear();
|
|
7092
|
+
relayout();
|
|
7093
|
+
};
|
|
7094
|
+
const unwatchText = watchText(svg, clock, remeasure);
|
|
6988
7095
|
const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
|
|
6989
7096
|
measuredWidth = width;
|
|
6990
7097
|
if (current.width === void 0) relayout();
|
|
6991
7098
|
});
|
|
6992
|
-
const unwatchFonts = watchFonts(doc,
|
|
6993
|
-
measure.clear();
|
|
6994
|
-
relayout();
|
|
6995
|
-
});
|
|
7099
|
+
const unwatchFonts = watchFonts(doc, remeasure);
|
|
6996
7100
|
describeDonut();
|
|
6997
7101
|
syncLegend();
|
|
6998
7102
|
table.render(firstTable);
|
|
@@ -7017,7 +7121,7 @@ function donutChart$1(target, options, env) {
|
|
|
7017
7121
|
...current,
|
|
7018
7122
|
...next
|
|
7019
7123
|
};
|
|
7020
|
-
checkOptions$
|
|
7124
|
+
checkOptions$13(merged);
|
|
7021
7125
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
7022
7126
|
const nextLayout = layout(merged, swapped);
|
|
7023
7127
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -7073,6 +7177,7 @@ function donutChart$1(target, options, env) {
|
|
|
7073
7177
|
color: key,
|
|
7074
7178
|
drawn: true
|
|
7075
7179
|
} : void 0,
|
|
7180
|
+
moveTabStop: (key) => !destroyed && hover.moveTabStop(key),
|
|
7076
7181
|
destroy() {
|
|
7077
7182
|
if (destroyed) return;
|
|
7078
7183
|
destroyed = true;
|
|
@@ -7084,6 +7189,7 @@ function donutChart$1(target, options, env) {
|
|
|
7084
7189
|
table.destroy();
|
|
7085
7190
|
announcer?.destroy();
|
|
7086
7191
|
unwatchHoverDuration();
|
|
7192
|
+
unwatchText();
|
|
7087
7193
|
unwatchWidth();
|
|
7088
7194
|
unwatchFonts();
|
|
7089
7195
|
for (const record of [...order, ...leaving.values()]) {
|
|
@@ -7103,7 +7209,7 @@ function donutChart$1(target, options, env) {
|
|
|
7103
7209
|
}
|
|
7104
7210
|
});
|
|
7105
7211
|
}
|
|
7106
|
-
function checkOptions$
|
|
7212
|
+
function checkOptions$13(options) {
|
|
7107
7213
|
checkChartOptions(options, "donutChart");
|
|
7108
7214
|
const { center, sort } = options;
|
|
7109
7215
|
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.");
|
|
@@ -7340,7 +7446,6 @@ function cubic(v0, c1, c2, v1, u) {
|
|
|
7340
7446
|
return s * s * s * v0 + 3 * s * s * u * c1 + 3 * s * u * u * c2 + u * u * u * v1;
|
|
7341
7447
|
}
|
|
7342
7448
|
// src/charts/time.ts
|
|
7343
|
-
const TIME_ZONES = ["UTC", "local"];
|
|
7344
7449
|
const SECOND = 1e3;
|
|
7345
7450
|
const MINUTE = 60 * SECOND;
|
|
7346
7451
|
const HOUR = 60 * MINUTE;
|
|
@@ -7448,6 +7553,16 @@ const FIELDS = {
|
|
|
7448
7553
|
fractionalSecondDigits: 3
|
|
7449
7554
|
}
|
|
7450
7555
|
};
|
|
7556
|
+
function isTimeZone(zone) {
|
|
7557
|
+
if (zone === "UTC" || zone === "local") return true;
|
|
7558
|
+
if (typeof zone !== "string") return false;
|
|
7559
|
+
try {
|
|
7560
|
+
clockOf(zone);
|
|
7561
|
+
return true;
|
|
7562
|
+
} catch {
|
|
7563
|
+
return false;
|
|
7564
|
+
}
|
|
7565
|
+
}
|
|
7451
7566
|
function timeStep(span) {
|
|
7452
7567
|
for (const step of STEPS) if (LONGEST$1[step.unit] * step.count >= span) return step;
|
|
7453
7568
|
return {
|
|
@@ -7517,15 +7632,7 @@ function monthsOn(t, months, zone) {
|
|
|
7517
7632
|
const last = /* @__PURE__ */ new Date(0);
|
|
7518
7633
|
last.setUTCFullYear(year, month + months + 1, 0);
|
|
7519
7634
|
const day = Math.min(date, last.getUTCDate());
|
|
7520
|
-
|
|
7521
|
-
if (zone === "UTC") {
|
|
7522
|
-
d.setUTCFullYear(year, month + months, day);
|
|
7523
|
-
d.setUTCHours(hours, minutes, seconds, ms);
|
|
7524
|
-
} else {
|
|
7525
|
-
d.setFullYear(year, month + months, day);
|
|
7526
|
-
d.setHours(hours, minutes, seconds, ms);
|
|
7527
|
-
}
|
|
7528
|
-
return d.getTime();
|
|
7635
|
+
return timeAt(zone, year, month + months, day, hours, minutes, seconds, ms);
|
|
7529
7636
|
}
|
|
7530
7637
|
function timeLevel(t, zone) {
|
|
7531
7638
|
const { ms, seconds, minutes, hours, date, month } = partsOf(t, zone);
|
|
@@ -7537,7 +7644,8 @@ function timeLevel(t, zone) {
|
|
|
7537
7644
|
return month !== 0 ? "month" : "year";
|
|
7538
7645
|
}
|
|
7539
7646
|
function timeName(times, zone) {
|
|
7540
|
-
const
|
|
7647
|
+
const shown = clockReader(zone);
|
|
7648
|
+
const finest = times.reduce((max, t) => Math.max(max, LEVELS.indexOf(timeLevel(shown(t), "UTC"))), 0);
|
|
7541
7649
|
const timeZone = zoneOption(zone);
|
|
7542
7650
|
const timeStyle = finest >= LEVELS.indexOf("second") ? "medium" : finest >= LEVELS.indexOf("hour") ? "short" : void 0;
|
|
7543
7651
|
const options = finest === LEVELS.indexOf("millisecond") ? {
|
|
@@ -7551,7 +7659,17 @@ function timeName(times, zone) {
|
|
|
7551
7659
|
timeZone
|
|
7552
7660
|
};
|
|
7553
7661
|
const format = new Intl.DateTimeFormat(void 0, options);
|
|
7554
|
-
return (t) => format.format(t);
|
|
7662
|
+
if (zone === "UTC" || !timeStyle) return (t) => format.format(t);
|
|
7663
|
+
const named = new Intl.DateTimeFormat(void 0, {
|
|
7664
|
+
timeZone,
|
|
7665
|
+
timeZoneName: "short"
|
|
7666
|
+
});
|
|
7667
|
+
return (t) => {
|
|
7668
|
+
const text = format.format(t);
|
|
7669
|
+
if (twinOf(t, shown) === void 0) return text;
|
|
7670
|
+
const name = named.formatToParts(t).find((part) => part.type === "timeZoneName")?.value;
|
|
7671
|
+
return name ? `${text} ${name}` : text;
|
|
7672
|
+
};
|
|
7555
7673
|
}
|
|
7556
7674
|
function tickWording(zone) {
|
|
7557
7675
|
const formats = /* @__PURE__ */ new Map();
|
|
@@ -7568,19 +7686,10 @@ function tickWording(zone) {
|
|
|
7568
7686
|
return format.format(t);
|
|
7569
7687
|
};
|
|
7570
7688
|
}
|
|
7571
|
-
const zoneOption = (zone) => zone === "
|
|
7689
|
+
const zoneOption = (zone) => zone === "local" ? void 0 : zone;
|
|
7572
7690
|
function partsOf(t, zone) {
|
|
7573
|
-
const d = new Date(t);
|
|
7574
|
-
return zone === "
|
|
7575
|
-
year: d.getUTCFullYear(),
|
|
7576
|
-
month: d.getUTCMonth(),
|
|
7577
|
-
date: d.getUTCDate(),
|
|
7578
|
-
weekday: d.getUTCDay(),
|
|
7579
|
-
hours: d.getUTCHours(),
|
|
7580
|
-
minutes: d.getUTCMinutes(),
|
|
7581
|
-
seconds: d.getUTCSeconds(),
|
|
7582
|
-
ms: d.getUTCMilliseconds()
|
|
7583
|
-
} : {
|
|
7691
|
+
const d = new Date(zone === "UTC" || zone === "local" ? t : shownAt(t, zone));
|
|
7692
|
+
return zone === "local" ? {
|
|
7584
7693
|
year: d.getFullYear(),
|
|
7585
7694
|
month: d.getMonth(),
|
|
7586
7695
|
date: d.getDate(),
|
|
@@ -7589,19 +7698,88 @@ function partsOf(t, zone) {
|
|
|
7589
7698
|
minutes: d.getMinutes(),
|
|
7590
7699
|
seconds: d.getSeconds(),
|
|
7591
7700
|
ms: d.getMilliseconds()
|
|
7701
|
+
} : {
|
|
7702
|
+
year: d.getUTCFullYear(),
|
|
7703
|
+
month: d.getUTCMonth(),
|
|
7704
|
+
date: d.getUTCDate(),
|
|
7705
|
+
weekday: d.getUTCDay(),
|
|
7706
|
+
hours: d.getUTCHours(),
|
|
7707
|
+
minutes: d.getUTCMinutes(),
|
|
7708
|
+
seconds: d.getUTCSeconds(),
|
|
7709
|
+
ms: d.getUTCMilliseconds()
|
|
7592
7710
|
};
|
|
7593
7711
|
}
|
|
7594
7712
|
function midnight(zone, year, month, date) {
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7713
|
+
return timeAt(zone, year, month, date);
|
|
7714
|
+
}
|
|
7715
|
+
function timeAt(zone, year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
|
|
7716
|
+
if (zone === "local") {
|
|
7717
|
+
const d = /* @__PURE__ */ new Date(0);
|
|
7600
7718
|
d.setFullYear(year, month, date);
|
|
7601
|
-
d.setHours(
|
|
7719
|
+
d.setHours(hours, minutes, seconds, ms);
|
|
7720
|
+
return d.getTime();
|
|
7602
7721
|
}
|
|
7722
|
+
const shown = utc(year, month, date, hours, minutes, seconds, ms);
|
|
7723
|
+
if (zone === "UTC") return shown;
|
|
7724
|
+
const before = shown - (shownAt(shown - DAY, zone) - (shown - DAY));
|
|
7725
|
+
const after = shown - (shownAt(shown + DAY, zone) - (shown + DAY));
|
|
7726
|
+
if (before === after) return before;
|
|
7727
|
+
const fits = [before, after].filter((t) => shownAt(t, zone) === shown);
|
|
7728
|
+
return fits.length > 0 ? Math.min(...fits) : before;
|
|
7729
|
+
}
|
|
7730
|
+
function utc(year, month, date, hours = 0, minutes = 0, seconds = 0, ms = 0) {
|
|
7731
|
+
const d = /* @__PURE__ */ new Date(0);
|
|
7732
|
+
d.setUTCFullYear(year, month, date);
|
|
7733
|
+
d.setUTCHours(hours, minutes, seconds, ms);
|
|
7603
7734
|
return d.getTime();
|
|
7604
7735
|
}
|
|
7736
|
+
function shownAt(t, zone) {
|
|
7737
|
+
if (zone === "UTC") return t;
|
|
7738
|
+
if (zone === "local") {
|
|
7739
|
+
const d = new Date(t);
|
|
7740
|
+
return utc(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
|
|
7741
|
+
}
|
|
7742
|
+
const ms = (t % SECOND + SECOND) % SECOND;
|
|
7743
|
+
const fields = {};
|
|
7744
|
+
for (const part of clockOf(zone).formatToParts(t - ms)) fields[part.type] = part.value;
|
|
7745
|
+
const year = Number(fields["year"]);
|
|
7746
|
+
return utc(fields["era"] === "BC" ? 1 - year : year, Number(fields["month"]) - 1, Number(fields["day"]), Number(fields["hour"]) % 24, Number(fields["minute"]), Number(fields["second"]), ms);
|
|
7747
|
+
}
|
|
7748
|
+
function clockReader(zone) {
|
|
7749
|
+
if (zone === "UTC" || zone === "local") return (t) => shownAt(t, zone);
|
|
7750
|
+
const kept = /* @__PURE__ */ new Map();
|
|
7751
|
+
return (t) => {
|
|
7752
|
+
let shown = kept.get(t);
|
|
7753
|
+
if (shown === void 0) kept.set(t, shown = shownAt(t, zone));
|
|
7754
|
+
return shown;
|
|
7755
|
+
};
|
|
7756
|
+
}
|
|
7757
|
+
function twinOf(t, shown) {
|
|
7758
|
+
const at = shown(t);
|
|
7759
|
+
for (const near of [t - DAY, t + DAY]) {
|
|
7760
|
+
const other = at - (shown(near) - near);
|
|
7761
|
+
if (other !== t && shown(other) === at) return other;
|
|
7762
|
+
}
|
|
7763
|
+
}
|
|
7764
|
+
const clocks = /* @__PURE__ */ new Map();
|
|
7765
|
+
function clockOf(zone) {
|
|
7766
|
+
let clock = clocks.get(zone);
|
|
7767
|
+
if (!clock) {
|
|
7768
|
+
clock = new Intl.DateTimeFormat("en-US", {
|
|
7769
|
+
timeZone: zone,
|
|
7770
|
+
hourCycle: "h23",
|
|
7771
|
+
era: "short",
|
|
7772
|
+
year: "numeric",
|
|
7773
|
+
month: "numeric",
|
|
7774
|
+
day: "numeric",
|
|
7775
|
+
hour: "numeric",
|
|
7776
|
+
minute: "numeric",
|
|
7777
|
+
second: "numeric"
|
|
7778
|
+
});
|
|
7779
|
+
clocks.set(zone, clock);
|
|
7780
|
+
}
|
|
7781
|
+
return clock;
|
|
7782
|
+
}
|
|
7605
7783
|
// src/charts/line-layout.ts
|
|
7606
7784
|
const LINE_WIDTH = 2.25;
|
|
7607
7785
|
const DOT_RADIUS = 4.5;
|
|
@@ -7629,7 +7807,7 @@ function lineEncoding(options) {
|
|
|
7629
7807
|
const labels = options.labels;
|
|
7630
7808
|
if (labels !== void 0 && labels !== false && typeof labels !== "function") throw new TypeError("lineChart: labels must be false or a function that returns a line's end label.");
|
|
7631
7809
|
const timeZone = options.timeZone ?? "UTC";
|
|
7632
|
-
if (!
|
|
7810
|
+
if (!isTimeZone(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC", "local" or the name of a zone Intl knows, such as "Europe/London", got ${show$1(timeZone)}.`);
|
|
7633
7811
|
const xFormat = options.xFormat;
|
|
7634
7812
|
if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
|
|
7635
7813
|
const curve = options.curve ?? "linear";
|
|
@@ -7646,6 +7824,17 @@ function lineEncoding(options) {
|
|
|
7646
7824
|
curve
|
|
7647
7825
|
};
|
|
7648
7826
|
}
|
|
7827
|
+
function checkRoom(room) {
|
|
7828
|
+
const px = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
7829
|
+
if (typeof room !== "object" || room === null || Array.isArray(room)) {
|
|
7830
|
+
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)}.`);
|
|
7831
|
+
return;
|
|
7832
|
+
}
|
|
7833
|
+
for (const side of ["right", "top"]) {
|
|
7834
|
+
const value = room[side];
|
|
7835
|
+
if (value !== void 0 && !px(value)) throw new RangeError(`lineChart: room.${side} must be a number of px, 0 or more, got ${String(value)}.`);
|
|
7836
|
+
}
|
|
7837
|
+
}
|
|
7649
7838
|
function layoutLines(input) {
|
|
7650
7839
|
const { width, measure } = input;
|
|
7651
7840
|
const height = input.height ?? HEIGHT;
|
|
@@ -7662,9 +7851,11 @@ function layoutLines(input) {
|
|
|
7662
7851
|
const xValues = ticked.map((tick) => tick.value);
|
|
7663
7852
|
const xTexts = ticked.map((tick) => tick.text);
|
|
7664
7853
|
const xWidths = xTexts.map((text) => measure(text, "ec-tick", TICK_SIZE));
|
|
7854
|
+
const room = typeof input.room === "number" ? { right: input.room } : input.room;
|
|
7665
7855
|
const labelWidth = input.label ? widest(distinctLabels(rows, input.label), "ec-value", VALUE_SIZE, measure) : 0;
|
|
7666
7856
|
const left = Math.max(widest(yTexts, "ec-tick", TICK_SIZE, measure) + 10, (xWidths[0] ?? 0) / 2 + 2);
|
|
7667
|
-
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (
|
|
7857
|
+
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (room?.right ?? 0));
|
|
7858
|
+
const top = TOP + (room?.top ?? 0);
|
|
7668
7859
|
const frame = {
|
|
7669
7860
|
scale: {
|
|
7670
7861
|
lo: domain.lo,
|
|
@@ -7675,8 +7866,8 @@ function layoutLines(input) {
|
|
|
7675
7866
|
xHi,
|
|
7676
7867
|
left,
|
|
7677
7868
|
right: Math.max(left, width - right),
|
|
7678
|
-
top
|
|
7679
|
-
bottom: Math.max(
|
|
7869
|
+
top,
|
|
7870
|
+
bottom: Math.max(top, height - AXIS),
|
|
7680
7871
|
width,
|
|
7681
7872
|
height
|
|
7682
7873
|
}
|
|
@@ -8107,11 +8298,13 @@ const show$1 = (value) => typeof value === "string" ? JSON.stringify(value) : St
|
|
|
8107
8298
|
// src/charts/line.ts
|
|
8108
8299
|
const STAGE = 500;
|
|
8109
8300
|
const RING = 2;
|
|
8301
|
+
const DOT_RING = 2;
|
|
8110
8302
|
const VISIBLE = .5;
|
|
8111
8303
|
function lineChart$1(target, options, env) {
|
|
8112
8304
|
const container = resolveTarget$2(target, "lineChart");
|
|
8113
8305
|
checkChartOptions(options, "lineChart");
|
|
8114
8306
|
let hoverKind = hoverOf(options);
|
|
8307
|
+
missingOf(options);
|
|
8115
8308
|
let current = options;
|
|
8116
8309
|
const motion = chartMotion(options.motion, env.motion);
|
|
8117
8310
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -8141,17 +8334,19 @@ function lineChart$1(target, options, env) {
|
|
|
8141
8334
|
"aria-hidden": "true",
|
|
8142
8335
|
visibility: "hidden"
|
|
8143
8336
|
}, svg);
|
|
8144
|
-
const
|
|
8337
|
+
const linesLayer = svgElement("g", { class: "ec-lines" }, svgElement("g", {
|
|
8145
8338
|
class: "ec-marks",
|
|
8146
8339
|
"aria-hidden": "true"
|
|
8147
|
-
}, svg);
|
|
8148
|
-
const linesLayer = svgElement("g", { class: "ec-lines" }, marksLayer);
|
|
8149
|
-
const pointsLayer = svgElement("g", { class: "ec-points" }, marksLayer);
|
|
8150
|
-
const columnsLayer = svgElement("g", { class: "ec-columns" }, svg);
|
|
8340
|
+
}, svg));
|
|
8151
8341
|
const overlay = svgElement("g", {
|
|
8152
8342
|
class: "ec-overlay",
|
|
8153
8343
|
"aria-hidden": "true"
|
|
8154
8344
|
}, svg);
|
|
8345
|
+
const pointsLayer = svgElement("g", { class: "ec-points" }, svgElement("g", {
|
|
8346
|
+
class: "ec-marks",
|
|
8347
|
+
"aria-hidden": "true"
|
|
8348
|
+
}, svg));
|
|
8349
|
+
const columnsLayer = svgElement("g", { class: "ec-columns" }, svg);
|
|
8155
8350
|
const measure = textMeasure(svg);
|
|
8156
8351
|
let rowOrder = [];
|
|
8157
8352
|
const rows = /* @__PURE__ */ new Map();
|
|
@@ -8248,8 +8443,8 @@ function lineChart$1(target, options, env) {
|
|
|
8248
8443
|
function layout(opts, using = effects) {
|
|
8249
8444
|
const encoding = lineEncoding(opts);
|
|
8250
8445
|
checkNeeds$1(using, encoding.series.map((s) => s.series), "lineChart");
|
|
8251
|
-
const { room
|
|
8252
|
-
|
|
8446
|
+
const { room } = opts;
|
|
8447
|
+
checkRoom(room);
|
|
8253
8448
|
const next = layoutLines({
|
|
8254
8449
|
data: opts.data,
|
|
8255
8450
|
encoding,
|
|
@@ -8689,6 +8884,14 @@ function lineChart$1(target, options, env) {
|
|
|
8689
8884
|
crosshair.setAttribute("visibility", "hidden");
|
|
8690
8885
|
tooltip.hide();
|
|
8691
8886
|
}
|
|
8887
|
+
function stand(key) {
|
|
8888
|
+
const record = key === void 0 ? void 0 : rows.get(key);
|
|
8889
|
+
if (!record || !revealed(record)) crosshair.setAttribute("visibility", "hidden");
|
|
8890
|
+
else setAttributes(crosshair, {
|
|
8891
|
+
...placeCrosshair(drawnFrame, record.px),
|
|
8892
|
+
visibility: void 0
|
|
8893
|
+
});
|
|
8894
|
+
}
|
|
8692
8895
|
let ringLine;
|
|
8693
8896
|
function drawRing(key) {
|
|
8694
8897
|
const point = key === void 0 ? void 0 : points.get(key);
|
|
@@ -8728,6 +8931,7 @@ function lineChart$1(target, options, env) {
|
|
|
8728
8931
|
}
|
|
8729
8932
|
function followHover() {
|
|
8730
8933
|
if (hover.key !== void 0) showHover(hover.key);
|
|
8934
|
+
if (hover.standing !== void 0) stand(hover.standing);
|
|
8731
8935
|
if (hover.ringKey !== void 0) drawRing(hover.ringKey);
|
|
8732
8936
|
}
|
|
8733
8937
|
const input = (record) => ({
|
|
@@ -8738,6 +8942,28 @@ function lineChart$1(target, options, env) {
|
|
|
8738
8942
|
mark: record.shown.geometry,
|
|
8739
8943
|
data: record.shown.data
|
|
8740
8944
|
});
|
|
8945
|
+
function standIn(key) {
|
|
8946
|
+
const record = rows.get(key);
|
|
8947
|
+
if (!record || !revealed(record)) return void 0;
|
|
8948
|
+
const { row } = record;
|
|
8949
|
+
return {
|
|
8950
|
+
mark: describePoint({
|
|
8951
|
+
key,
|
|
8952
|
+
x: record.px,
|
|
8953
|
+
y: drawnFrame.box.top,
|
|
8954
|
+
r: DOT_RADIUS
|
|
8955
|
+
}),
|
|
8956
|
+
data: {
|
|
8957
|
+
datum: row.datum,
|
|
8958
|
+
samples: [{
|
|
8959
|
+
t: 0,
|
|
8960
|
+
value: NaN,
|
|
8961
|
+
at: laidOut.time ? new Date(row.x) : row.x
|
|
8962
|
+
}],
|
|
8963
|
+
related: () => void 0
|
|
8964
|
+
}
|
|
8965
|
+
};
|
|
8966
|
+
}
|
|
8741
8967
|
function liveRowOf(eventTarget) {
|
|
8742
8968
|
const element = eventTarget;
|
|
8743
8969
|
const column = typeof element?.closest === "function" ? element.closest(".ec-column") : null;
|
|
@@ -8833,7 +9059,7 @@ function lineChart$1(target, options, env) {
|
|
|
8833
9059
|
if (hoverKind !== "point") return;
|
|
8834
9060
|
if (!stopsLayer) {
|
|
8835
9061
|
stopsLayer = svgElement("g", { class: "ec-stops" }, svg);
|
|
8836
|
-
svg.insertBefore(stopsLayer,
|
|
9062
|
+
svg.insertBefore(stopsLayer, columnsLayer.nextSibling);
|
|
8837
9063
|
plotHit = svgElement("rect", { class: "ec-hit" }, stopsLayer);
|
|
8838
9064
|
stopsLayer.addEventListener("click", (event) => {
|
|
8839
9065
|
const point = pointAt(event.clientX, event.clientY);
|
|
@@ -9005,6 +9231,8 @@ function lineChart$1(target, options, env) {
|
|
|
9005
9231
|
const record = findMark(key);
|
|
9006
9232
|
return record && onScreen(record);
|
|
9007
9233
|
},
|
|
9234
|
+
standIn,
|
|
9235
|
+
stand,
|
|
9008
9236
|
ring: drawRing,
|
|
9009
9237
|
tooltip: {
|
|
9010
9238
|
show: showHover,
|
|
@@ -9033,7 +9261,8 @@ function lineChart$1(target, options, env) {
|
|
|
9033
9261
|
total: total(row.values)
|
|
9034
9262
|
})),
|
|
9035
9263
|
format: format(opts),
|
|
9036
|
-
total: false
|
|
9264
|
+
total: false,
|
|
9265
|
+
missing: missingOf(opts)
|
|
9037
9266
|
});
|
|
9038
9267
|
}
|
|
9039
9268
|
function labelColumn(record) {
|
|
@@ -9272,14 +9501,16 @@ function lineChart$1(target, options, env) {
|
|
|
9272
9501
|
for (const point of points.values()) point.target = placed.points.get(point.key) ?? point.target;
|
|
9273
9502
|
transitionTo(next, true);
|
|
9274
9503
|
}
|
|
9504
|
+
const remeasure = () => {
|
|
9505
|
+
measure.clear();
|
|
9506
|
+
relayout();
|
|
9507
|
+
};
|
|
9508
|
+
const unwatchText = watchText(svg, clock, remeasure);
|
|
9275
9509
|
const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
|
|
9276
9510
|
measuredWidth = width;
|
|
9277
9511
|
if (current.width === void 0) relayout();
|
|
9278
9512
|
});
|
|
9279
|
-
const unwatchFonts = watchFonts(doc,
|
|
9280
|
-
measure.clear();
|
|
9281
|
-
relayout();
|
|
9282
|
-
});
|
|
9513
|
+
const unwatchFonts = watchFonts(doc, remeasure);
|
|
9283
9514
|
describeChart(svg, current);
|
|
9284
9515
|
syncLegend();
|
|
9285
9516
|
table.render(firstTable);
|
|
@@ -9307,6 +9538,11 @@ function lineChart$1(target, options, env) {
|
|
|
9307
9538
|
const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
|
|
9308
9539
|
hover.sync();
|
|
9309
9540
|
runner.enter(liveMarks().map(input));
|
|
9541
|
+
function stopFor(key) {
|
|
9542
|
+
const row = rows.get(key);
|
|
9543
|
+
if (hoverKind === "x") return (row ?? points.get(key)?.row)?.key;
|
|
9544
|
+
return (points.get(key) ?? (row && livePoints(row)[0]))?.key;
|
|
9545
|
+
}
|
|
9310
9546
|
return linkable(hover.link, {
|
|
9311
9547
|
element: svg,
|
|
9312
9548
|
async update(next) {
|
|
@@ -9318,6 +9554,7 @@ function lineChart$1(target, options, env) {
|
|
|
9318
9554
|
};
|
|
9319
9555
|
checkChartOptions(merged, "lineChart");
|
|
9320
9556
|
const kind = hoverOf(merged);
|
|
9557
|
+
missingOf(merged);
|
|
9321
9558
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
9322
9559
|
const nextLayout = layout(merged, swapped);
|
|
9323
9560
|
const nextTable = tableFor(merged, nextLayout);
|
|
@@ -9376,30 +9613,40 @@ function lineChart$1(target, options, env) {
|
|
|
9376
9613
|
on: events.on,
|
|
9377
9614
|
marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
|
|
9378
9615
|
focus(key) {
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
if (hoverKind === "x") {
|
|
9382
|
-
const record = row ?? points.get(key)?.row;
|
|
9383
|
-
if (record) hover.focus(record.key);
|
|
9384
|
-
return;
|
|
9385
|
-
}
|
|
9386
|
-
const point = points.get(key) ?? (row && livePoints(row)[0]);
|
|
9387
|
-
if (point) hover.focus(point.key);
|
|
9616
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
9617
|
+
if (stop !== void 0) hover.focus(stop);
|
|
9388
9618
|
},
|
|
9389
9619
|
leave() {
|
|
9390
9620
|
if (!destroyed) hover.leave();
|
|
9391
9621
|
},
|
|
9392
9622
|
labels: () => lineOrder.flatMap((line) => chartLabel(line.key, "value", line.drawnLabel, line.label)),
|
|
9393
9623
|
paintOf(key) {
|
|
9394
|
-
const
|
|
9395
|
-
|
|
9396
|
-
color:
|
|
9397
|
-
drawn:
|
|
9624
|
+
const line = lines.get(key);
|
|
9625
|
+
if (line) return {
|
|
9626
|
+
color: line.series,
|
|
9627
|
+
drawn: true,
|
|
9628
|
+
...line.end.getAttribute("visibility") === "hidden" ? {} : {
|
|
9629
|
+
end: DOT_RADIUS,
|
|
9630
|
+
ring: DOT_RING
|
|
9631
|
+
}
|
|
9398
9632
|
};
|
|
9633
|
+
const point = points.get(key);
|
|
9634
|
+
return point && (point.group.classList.contains("ec-alone") ? {
|
|
9635
|
+
color: point.series,
|
|
9636
|
+
drawn: true,
|
|
9637
|
+
ring: DOT_RING
|
|
9638
|
+
} : {
|
|
9639
|
+
color: point.series,
|
|
9640
|
+
drawn: false
|
|
9641
|
+
});
|
|
9399
9642
|
},
|
|
9400
9643
|
standsFor(key) {
|
|
9401
9644
|
return rows.has(key) ? [...laidOut.series.map((series) => pointKey(series, key)), key] : [key];
|
|
9402
9645
|
},
|
|
9646
|
+
moveTabStop(key) {
|
|
9647
|
+
const stop = destroyed ? void 0 : stopFor(key);
|
|
9648
|
+
return stop !== void 0 && hover.moveTabStop(stop);
|
|
9649
|
+
},
|
|
9403
9650
|
destroy() {
|
|
9404
9651
|
if (destroyed) return;
|
|
9405
9652
|
destroyed = true;
|
|
@@ -9411,6 +9658,7 @@ function lineChart$1(target, options, env) {
|
|
|
9411
9658
|
table.destroy();
|
|
9412
9659
|
announcer?.destroy();
|
|
9413
9660
|
unwatchHoverDuration();
|
|
9661
|
+
unwatchText();
|
|
9414
9662
|
unwatchWidth();
|
|
9415
9663
|
unwatchFonts();
|
|
9416
9664
|
for (const record of [...rowOrder, ...leavingRows.values()]) for (const value of [
|
|
@@ -9513,9 +9761,10 @@ function labelled(values, options) {
|
|
|
9513
9761
|
}
|
|
9514
9762
|
function said(values, options) {
|
|
9515
9763
|
const formatted = format(options);
|
|
9764
|
+
const missing = missingOf(options);
|
|
9516
9765
|
return values.map((v) => {
|
|
9517
9766
|
const label = seriesLabel(options.seriesLabels, v.series);
|
|
9518
|
-
return v.value === void 0 ? `${label} missing` : `${formatted(v.value)} ${label}`;
|
|
9767
|
+
return v.value === void 0 ? `${label} ${missing}` : `${formatted(v.value)} ${label}`;
|
|
9519
9768
|
});
|
|
9520
9769
|
}
|
|
9521
9770
|
function summary(row, options) {
|
|
@@ -9572,6 +9821,11 @@ function hoverOf(options) {
|
|
|
9572
9821
|
if (hover !== "x" && hover !== "point") throw new TypeError(`lineChart: hover must be "x" or "point", got ${typeof hover === "string" ? JSON.stringify(hover) : String(hover)}.`);
|
|
9573
9822
|
return hover;
|
|
9574
9823
|
}
|
|
9824
|
+
function missingOf(options) {
|
|
9825
|
+
const { missing = MISSING } = options;
|
|
9826
|
+
if (typeof missing !== "string" || missing.trim() === "") throw new TypeError(`lineChart: missing must be a word for a missing value, such as "no data", got ${typeof missing === "string" ? JSON.stringify(missing) : String(missing)}.`);
|
|
9827
|
+
return missing;
|
|
9828
|
+
}
|
|
9575
9829
|
// src/core/geometry/ring.ts
|
|
9576
9830
|
const ROUND = .5;
|
|
9577
9831
|
function goesRound(mark) {
|
|
@@ -9842,7 +10096,7 @@ function keepsCircles(m) {
|
|
|
9842
10096
|
const tiny = 1e-4 * Math.max(u, v);
|
|
9843
10097
|
return Math.abs(u - v) <= tiny && Math.abs(a * c + b * d) <= tiny;
|
|
9844
10098
|
}
|
|
9845
|
-
function scaleOf$
|
|
10099
|
+
function scaleOf$2(m) {
|
|
9846
10100
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
9847
10101
|
}
|
|
9848
10102
|
function boxIn(m, rect) {
|
|
@@ -10057,7 +10311,7 @@ function cssMatrix(m) {
|
|
|
10057
10311
|
const NEAR = .5;
|
|
10058
10312
|
const MOST = 32;
|
|
10059
10313
|
function sliceOf$1(commands, m) {
|
|
10060
|
-
const scale = scaleOf$
|
|
10314
|
+
const scale = scaleOf$2(m);
|
|
10061
10315
|
if (!keepsCircles(m) || !(scale > 0) || commands.length > MOST || commands.some((command) => command.op === "C" || command.op === "Q")) return void 0;
|
|
10062
10316
|
const near = NEAR / scale;
|
|
10063
10317
|
const subpaths = flattenPath(commands);
|
|
@@ -10170,7 +10424,7 @@ const onCircle = (run, center, radius, near) => Math.abs(run.radius - radius) <=
|
|
|
10170
10424
|
1
|
|
10171
10425
|
].every((u) => Math.abs(distance$1(pointOn(arc, u), center) - radius) <= near));
|
|
10172
10426
|
function moved(own, m) {
|
|
10173
|
-
const scale = scaleOf$
|
|
10427
|
+
const scale = scaleOf$2(m);
|
|
10174
10428
|
const center = matrix.apply(m, own.center);
|
|
10175
10429
|
const corner = matrix.apply(m, {
|
|
10176
10430
|
x: own.center.x + own.outer * Math.cos(own.start),
|
|
@@ -10391,7 +10645,7 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
|
|
|
10391
10645
|
"graphics-object"
|
|
10392
10646
|
]);
|
|
10393
10647
|
function expressive$1(target, options, env) {
|
|
10394
|
-
checkOptions$
|
|
10648
|
+
checkOptions$12(options);
|
|
10395
10649
|
const motion = chartMotion(options.motion, env.motion);
|
|
10396
10650
|
let effects = resolveEffects(options.on, env.presets);
|
|
10397
10651
|
let given = options.on;
|
|
@@ -10536,7 +10790,7 @@ function expressive$1(target, options, env) {
|
|
|
10536
10790
|
series,
|
|
10537
10791
|
x: round$1(center.x),
|
|
10538
10792
|
y: round$1(center.y),
|
|
10539
|
-
r: round$1(Math.max(0, r) * scaleOf$
|
|
10793
|
+
r: round$1(Math.max(0, r) * scaleOf$2(m))
|
|
10540
10794
|
});
|
|
10541
10795
|
} else {
|
|
10542
10796
|
const commands = shapeOutline(tag, attribute);
|
|
@@ -10573,9 +10827,9 @@ function expressive$1(target, options, env) {
|
|
|
10573
10827
|
}
|
|
10574
10828
|
function widthOf(stroke, m, at) {
|
|
10575
10829
|
const width = stroke?.width ?? 1;
|
|
10576
|
-
if (!stroke?.screen) return width * scaleOf$
|
|
10830
|
+
if (!stroke?.screen) return width * scaleOf$2(m);
|
|
10577
10831
|
const screen = at.screen(at.common);
|
|
10578
|
-
const scale = screen ? scaleOf$
|
|
10832
|
+
const scale = screen ? scaleOf$2(screen) : 0;
|
|
10579
10833
|
return scale > 0 ? width / scale : width;
|
|
10580
10834
|
}
|
|
10581
10835
|
function transformOf(element, at) {
|
|
@@ -10724,7 +10978,7 @@ function expressive$1(target, options, env) {
|
|
|
10724
10978
|
set: (style) => find(key)?.handle.set(style),
|
|
10725
10979
|
reset: () => find(key)?.handle.reset()
|
|
10726
10980
|
}),
|
|
10727
|
-
colors: (key) => find(key)?.mark
|
|
10981
|
+
colors: (key, part) => partOf(find(key)?.mark, part)?.colors
|
|
10728
10982
|
});
|
|
10729
10983
|
const runner = createRunner({
|
|
10730
10984
|
effects,
|
|
@@ -10777,7 +11031,7 @@ function expressive$1(target, options, env) {
|
|
|
10777
11031
|
from: from.geometry
|
|
10778
11032
|
});
|
|
10779
11033
|
else if (newRow || geometryChanged(from.geometry, mark.geometry) || samplesChanged(from.data.samples, mark.data.samples)) diff.moved.push(record);
|
|
10780
|
-
if (from.parts
|
|
11034
|
+
if (from.parts.length !== mark.parts.length || mark.parts.some((part, i) => part.colors?.color !== from.parts[i].colors?.color)) recolor.push(mark.key);
|
|
10781
11035
|
record.mark = mark;
|
|
10782
11036
|
} else {
|
|
10783
11037
|
record = leaving.get(mark.key);
|
|
@@ -11267,7 +11521,7 @@ function expressive$1(target, options, env) {
|
|
|
11267
11521
|
}
|
|
11268
11522
|
});
|
|
11269
11523
|
}
|
|
11270
|
-
function checkOptions$
|
|
11524
|
+
function checkOptions$12(options) {
|
|
11271
11525
|
if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
|
|
11272
11526
|
if (typeof options.key !== "function") throw new TypeError("expressive needs a key function, for example key: (d) => d.name. Marks are matched by key.");
|
|
11273
11527
|
for (const name of [
|
|
@@ -11279,6 +11533,11 @@ function checkOptions$11(options) {
|
|
|
11279
11533
|
]) if (options[name] !== void 0 && typeof options[name] !== "function") throw new TypeError(`expressive: ${name} must be a function.`);
|
|
11280
11534
|
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)}.`);
|
|
11281
11535
|
}
|
|
11536
|
+
function partOf(mark, key) {
|
|
11537
|
+
if (key === void 0) return mark?.parts[0];
|
|
11538
|
+
const segment = mark?.geometry.segments?.find((s) => s.key === key);
|
|
11539
|
+
return segment && mark.parts.find((p) => p.series === segment.series);
|
|
11540
|
+
}
|
|
11282
11541
|
function ownSeries(mark) {
|
|
11283
11542
|
const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
|
|
11284
11543
|
return [...new Set(names.filter((name) => name !== void 0))];
|
|
@@ -11722,7 +11981,7 @@ function pointsOf(first) {
|
|
|
11722
11981
|
function lineOf(key, element, first, m) {
|
|
11723
11982
|
const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
|
|
11724
11983
|
if (!straight(first)) {
|
|
11725
|
-
const scaled = width * scaleOf(m);
|
|
11984
|
+
const scaled = width * scaleOf$1(m);
|
|
11726
11985
|
return describeShape({
|
|
11727
11986
|
key,
|
|
11728
11987
|
series: key,
|
|
@@ -11738,7 +11997,7 @@ function lineOf(key, element, first, m) {
|
|
|
11738
11997
|
series: key,
|
|
11739
11998
|
points: points.map(({ point }) => matrix.apply(m, point)),
|
|
11740
11999
|
...breaks.length > 0 ? { breaks } : {},
|
|
11741
|
-
width: (Number.isFinite(width) ? width : 1) * scaleOf(m)
|
|
12000
|
+
width: (Number.isFinite(width) ? width : 1) * scaleOf$1(m)
|
|
11742
12001
|
});
|
|
11743
12002
|
}
|
|
11744
12003
|
function sliceOf(key, item, m) {
|
|
@@ -11746,7 +12005,7 @@ function sliceOf(key, item, m) {
|
|
|
11746
12005
|
x: number(item.x),
|
|
11747
12006
|
y: number(item.y)
|
|
11748
12007
|
});
|
|
11749
|
-
const s = scaleOf(m);
|
|
12008
|
+
const s = scaleOf$1(m);
|
|
11750
12009
|
const [start, end] = [number(item.startAngle), number(item.endAngle)].sort((a, b) => a - b);
|
|
11751
12010
|
return describeArc({
|
|
11752
12011
|
key,
|
|
@@ -11767,7 +12026,7 @@ function pointOf(key, item, m) {
|
|
|
11767
12026
|
key,
|
|
11768
12027
|
x: center.x,
|
|
11769
12028
|
y: center.y,
|
|
11770
|
-
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf(m)
|
|
12029
|
+
r: Math.sqrt(Math.max(0, item.size ?? 64) / Math.PI) * scaleOf$1(m)
|
|
11771
12030
|
});
|
|
11772
12031
|
}
|
|
11773
12032
|
function boxOf(item) {
|
|
@@ -11782,7 +12041,7 @@ function boxOf(item) {
|
|
|
11782
12041
|
height: Math.abs(height)
|
|
11783
12042
|
};
|
|
11784
12043
|
}
|
|
11785
|
-
function scaleOf(m) {
|
|
12044
|
+
function scaleOf$1(m) {
|
|
11786
12045
|
return Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
11787
12046
|
}
|
|
11788
12047
|
function number(value) {
|
|
@@ -11933,12 +12192,12 @@ function describeEffect(value) {
|
|
|
11933
12192
|
return kind === void 0 ? "an object with no kind" : `an effect of kind ${JSON.stringify(kind)}`;
|
|
11934
12193
|
}
|
|
11935
12194
|
// src/charts/switch.ts
|
|
11936
|
-
const DURATION$
|
|
12195
|
+
const DURATION$8 = 950;
|
|
11937
12196
|
const OUT_BY = .4;
|
|
11938
12197
|
const HALF = .5;
|
|
11939
12198
|
function chartSwitch$1(target, options, env) {
|
|
11940
12199
|
const host = resolveTarget$2(target, "chartSwitch");
|
|
11941
|
-
const names = checkOptions$
|
|
12200
|
+
const names = checkOptions$11(options);
|
|
11942
12201
|
const effect = options.transition;
|
|
11943
12202
|
const colors = toColorAssignment(options.colors);
|
|
11944
12203
|
const motion = env.motion;
|
|
@@ -11982,7 +12241,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
11982
12241
|
const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
|
|
11983
12242
|
const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
|
|
11984
12243
|
const orders = /* @__PURE__ */ new WeakMap();
|
|
11985
|
-
const surfaceFor = (paints) => ({ group(key, order) {
|
|
12244
|
+
const surfaceFor = (paints, extras) => ({ group(key, order) {
|
|
11986
12245
|
const group = svgElement("g", {
|
|
11987
12246
|
class: "ec-run",
|
|
11988
12247
|
"data-key": key
|
|
@@ -11991,11 +12250,91 @@ function chartSwitch$1(target, options, env) {
|
|
|
11991
12250
|
orders.set(group, order);
|
|
11992
12251
|
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
|
|
11993
12252
|
runsLayer.insertBefore(group, above ?? null);
|
|
12253
|
+
const layer = svgLayer(group);
|
|
11994
12254
|
return {
|
|
11995
|
-
...
|
|
12255
|
+
...extras[order]?.wrap(layer, group) ?? layer,
|
|
11996
12256
|
clear: () => group.remove()
|
|
11997
12257
|
};
|
|
11998
12258
|
} });
|
|
12259
|
+
function extrasFor(rings, ends, dotColors) {
|
|
12260
|
+
const [ringA, ringB] = rings;
|
|
12261
|
+
const [endA, endB] = ends;
|
|
12262
|
+
if (ringA === 0 && ringB === 0 && !endA && !endB) return void 0;
|
|
12263
|
+
const dots = [];
|
|
12264
|
+
if (endA && endB) {
|
|
12265
|
+
const element = endDot();
|
|
12266
|
+
const draw = (s) => placeDot(element, {
|
|
12267
|
+
at: {
|
|
12268
|
+
x: mix$1(endA.at.x, endB.at.x, s),
|
|
12269
|
+
y: mix$1(endA.at.y, endB.at.y, s)
|
|
12270
|
+
},
|
|
12271
|
+
r: mix$1(endA.r, endB.r, s),
|
|
12272
|
+
ring: mix$1(endA.ring, endB.ring, s)
|
|
12273
|
+
});
|
|
12274
|
+
dots.push({
|
|
12275
|
+
element,
|
|
12276
|
+
draw
|
|
12277
|
+
});
|
|
12278
|
+
} else [[
|
|
12279
|
+
endA,
|
|
12280
|
+
fadeOut,
|
|
12281
|
+
dotColors[0]
|
|
12282
|
+
], [
|
|
12283
|
+
endB,
|
|
12284
|
+
fadeIn,
|
|
12285
|
+
dotColors[1]
|
|
12286
|
+
]].forEach(([end, opacity, color]) => {
|
|
12287
|
+
if (!end) return;
|
|
12288
|
+
const element = endDot();
|
|
12289
|
+
setStyles(element, markColorStyles(seriesColors(colors.slot(color))));
|
|
12290
|
+
placeDot(element, end);
|
|
12291
|
+
dots.push({
|
|
12292
|
+
element,
|
|
12293
|
+
draw: (s) => setAttributes(element, { opacity: opacity(s) })
|
|
12294
|
+
});
|
|
12295
|
+
});
|
|
12296
|
+
const ringed = ringA > 0 || ringB > 0;
|
|
12297
|
+
let width = ringA;
|
|
12298
|
+
const shapes = /* @__PURE__ */ new Map();
|
|
12299
|
+
return {
|
|
12300
|
+
wrap(layer, group) {
|
|
12301
|
+
shapes.clear();
|
|
12302
|
+
const raise = () => {
|
|
12303
|
+
for (const dot of dots) group.appendChild(dot.element);
|
|
12304
|
+
};
|
|
12305
|
+
raise();
|
|
12306
|
+
return {
|
|
12307
|
+
...layer,
|
|
12308
|
+
path(d, paint) {
|
|
12309
|
+
const ring = ringed && paint.fill !== void 0 && paint.stroke === void 0;
|
|
12310
|
+
const handle = layer.path(d, ring ? {
|
|
12311
|
+
...paint,
|
|
12312
|
+
stroke: "surface",
|
|
12313
|
+
width
|
|
12314
|
+
} : paint);
|
|
12315
|
+
raise();
|
|
12316
|
+
if (!ring) return handle;
|
|
12317
|
+
shapes.set(handle, d);
|
|
12318
|
+
return {
|
|
12319
|
+
update(next, nextPaint) {
|
|
12320
|
+
shapes.set(handle, next);
|
|
12321
|
+
handle.update(next, nextPaint);
|
|
12322
|
+
},
|
|
12323
|
+
remove() {
|
|
12324
|
+
shapes.delete(handle);
|
|
12325
|
+
handle.remove();
|
|
12326
|
+
}
|
|
12327
|
+
};
|
|
12328
|
+
}
|
|
12329
|
+
};
|
|
12330
|
+
},
|
|
12331
|
+
draw(s) {
|
|
12332
|
+
width = mix$1(ringA, ringB, s);
|
|
12333
|
+
for (const [handle, d] of shapes) handle.update(d, { width });
|
|
12334
|
+
for (const dot of dots) dot.draw(s);
|
|
12335
|
+
}
|
|
12336
|
+
};
|
|
12337
|
+
}
|
|
11999
12338
|
let current = options.initial;
|
|
12000
12339
|
let active;
|
|
12001
12340
|
let destroyed = false;
|
|
@@ -12021,15 +12360,23 @@ function chartSwitch$1(target, options, env) {
|
|
|
12021
12360
|
}
|
|
12022
12361
|
function readFocus(from) {
|
|
12023
12362
|
const element = focused();
|
|
12024
|
-
|
|
12025
|
-
const keyed = element.closest("[data-key]");
|
|
12363
|
+
const inside = element !== null && from.container.contains(element);
|
|
12364
|
+
const keyed = (inside ? element : from.chart.element.querySelector("[tabindex=\"0\"]"))?.closest("[data-key]");
|
|
12026
12365
|
const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
|
|
12027
|
-
|
|
12366
|
+
if (!inside && key === null) return void 0;
|
|
12367
|
+
return {
|
|
12368
|
+
keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key],
|
|
12369
|
+
focused: inside
|
|
12370
|
+
};
|
|
12028
12371
|
}
|
|
12029
12372
|
function restoreFocus(to, memory) {
|
|
12030
12373
|
if (!memory) return;
|
|
12031
12374
|
const now = focused();
|
|
12032
|
-
|
|
12375
|
+
const away = now !== null && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now);
|
|
12376
|
+
if (!memory.focused || away) {
|
|
12377
|
+
for (const key of memory.keys) if (to.chart.moveTabStop?.(key)) return;
|
|
12378
|
+
return;
|
|
12379
|
+
}
|
|
12033
12380
|
const inside = () => to.chart.element.contains(focused());
|
|
12034
12381
|
for (const key of [...memory.keys, ...to.chart.marks().map((mark) => mark.key)]) {
|
|
12035
12382
|
to.chart.focus(key);
|
|
@@ -12157,12 +12504,15 @@ function chartSwitch$1(target, options, env) {
|
|
|
12157
12504
|
function prepare(a, b) {
|
|
12158
12505
|
const toA = between$1(overlay, a.chart.element, wrapper);
|
|
12159
12506
|
const toB = between$1(overlay, b.chart.element, wrapper);
|
|
12507
|
+
const scaleA = scaleOf(toA);
|
|
12508
|
+
const scaleB = scaleOf(toB);
|
|
12160
12509
|
const from = a.chart.marks().map((mark) => mapMark(mark, toA));
|
|
12161
12510
|
const to = b.chart.marks().map((mark) => mapMark(mark, toB));
|
|
12162
12511
|
const fromByKey = new Map(from.map((mark) => [mark.key, mark]));
|
|
12163
12512
|
const toKeys = new Set(to.map((mark) => mark.key));
|
|
12164
12513
|
const pairs = [];
|
|
12165
12514
|
const paints = [];
|
|
12515
|
+
const extras = [];
|
|
12166
12516
|
for (const mark of to) {
|
|
12167
12517
|
const partner = fromByKey.get(mark.key);
|
|
12168
12518
|
if (!partner) continue;
|
|
@@ -12174,14 +12524,18 @@ function chartSwitch$1(target, options, env) {
|
|
|
12174
12524
|
to: will.drawn ? mark : dot$1(mark)
|
|
12175
12525
|
});
|
|
12176
12526
|
paints.push(will.color);
|
|
12527
|
+
extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was.color, will.color]));
|
|
12177
12528
|
}
|
|
12178
12529
|
const drawings = [];
|
|
12179
|
-
|
|
12530
|
+
if (extras.some((each) => each !== void 0)) drawings.push((s) => {
|
|
12531
|
+
for (const each of extras) each?.draw(s);
|
|
12532
|
+
});
|
|
12533
|
+
const fade = (view, mark, scale, opacity) => {
|
|
12180
12534
|
const paint = paintOf(view, mark);
|
|
12181
|
-
if (paint.drawn) drawings.push(fadeMark(mark, paint
|
|
12535
|
+
if (paint.drawn) drawings.push(fadeMark(mark, paint, scale, opacity));
|
|
12182
12536
|
};
|
|
12183
|
-
for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, fadeOut);
|
|
12184
|
-
for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, fadeIn);
|
|
12537
|
+
for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, scaleA, fadeOut);
|
|
12538
|
+
for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, scaleB, fadeIn);
|
|
12185
12539
|
const id = (label) => `${label.role}\n${label.key}`;
|
|
12186
12540
|
const labelsA = a.chart.labels();
|
|
12187
12541
|
const labelsB = b.chart.labels();
|
|
@@ -12201,7 +12555,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12201
12555
|
});
|
|
12202
12556
|
return {
|
|
12203
12557
|
pairs,
|
|
12204
|
-
surface: surfaceFor(paints),
|
|
12558
|
+
surface: surfaceFor(paints, extras),
|
|
12205
12559
|
scene: {
|
|
12206
12560
|
draw: (s) => {
|
|
12207
12561
|
for (const draw of drawings) draw(s);
|
|
@@ -12214,18 +12568,36 @@ function chartSwitch$1(target, options, env) {
|
|
|
12214
12568
|
}
|
|
12215
12569
|
};
|
|
12216
12570
|
}
|
|
12217
|
-
function fadeMark(mark,
|
|
12571
|
+
function fadeMark(mark, paint, scale, opacity) {
|
|
12218
12572
|
const group = svgElement("g", {
|
|
12219
12573
|
class: "ec-switch-fade",
|
|
12220
12574
|
"data-key": mark.key
|
|
12221
12575
|
}, fadesLayer);
|
|
12222
|
-
setStyles(group, markColorStyles(seriesColors(colors.slot(color))));
|
|
12223
|
-
|
|
12576
|
+
setStyles(group, markColorStyles(seriesColors(colors.slot(paint.color))));
|
|
12577
|
+
const ring = ringOf(paint, scale);
|
|
12578
|
+
svgLayer(group).path(mark.outline.d, mark.outline.closed ? {
|
|
12579
|
+
fill: "mark",
|
|
12580
|
+
...ring > 0 ? {
|
|
12581
|
+
stroke: "surface",
|
|
12582
|
+
width: ring
|
|
12583
|
+
} : {}
|
|
12584
|
+
} : {
|
|
12224
12585
|
stroke: "mark",
|
|
12225
12586
|
width: mark.thickness
|
|
12226
12587
|
});
|
|
12588
|
+
const end = endOf(paint, mark, scale);
|
|
12589
|
+
if (end) placeDot(group.appendChild(endDot()), end);
|
|
12227
12590
|
return (s) => setAttributes(group, { opacity: opacity(s) });
|
|
12228
12591
|
}
|
|
12592
|
+
function endDot() {
|
|
12593
|
+
const element = doc.createElementNS(SVG_NS$2, "circle");
|
|
12594
|
+
element.setAttribute("class", "ec-switch-end");
|
|
12595
|
+
setStyles(element, {
|
|
12596
|
+
fill: cssColor("mark"),
|
|
12597
|
+
stroke: cssColor("surface")
|
|
12598
|
+
});
|
|
12599
|
+
return element;
|
|
12600
|
+
}
|
|
12229
12601
|
function copyLabel(label, m) {
|
|
12230
12602
|
const text = label.element.cloneNode(true);
|
|
12231
12603
|
for (const name of [
|
|
@@ -12356,7 +12728,7 @@ function drive(begin, at, env) {
|
|
|
12356
12728
|
const begun = unease(begin);
|
|
12357
12729
|
let running;
|
|
12358
12730
|
running = tween({
|
|
12359
|
-
duration: DURATION$
|
|
12731
|
+
duration: DURATION$8,
|
|
12360
12732
|
timing: "transition",
|
|
12361
12733
|
ease: linear,
|
|
12362
12734
|
update: (k) => {
|
|
@@ -12427,12 +12799,29 @@ function dot$1(mark) {
|
|
|
12427
12799
|
r: 0
|
|
12428
12800
|
});
|
|
12429
12801
|
}
|
|
12802
|
+
const ringOf = (paint, scale) => paint.drawn && paint.end === void 0 ? (paint.ring ?? 0) * scale : 0;
|
|
12803
|
+
function endOf(paint, mark, scale) {
|
|
12804
|
+
return paint.drawn && paint.end !== void 0 ? {
|
|
12805
|
+
at: mark.end,
|
|
12806
|
+
r: paint.end * scale,
|
|
12807
|
+
ring: (paint.ring ?? 0) * scale
|
|
12808
|
+
} : void 0;
|
|
12809
|
+
}
|
|
12810
|
+
function placeDot(element, end) {
|
|
12811
|
+
setAttributes(element, {
|
|
12812
|
+
cx: end.at.x,
|
|
12813
|
+
cy: end.at.y,
|
|
12814
|
+
r: end.r,
|
|
12815
|
+
"stroke-width": end.ring
|
|
12816
|
+
});
|
|
12817
|
+
}
|
|
12430
12818
|
const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
12819
|
+
const scaleOf = (m) => Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
12431
12820
|
function mapMark(mark, m) {
|
|
12432
12821
|
if (isIdentity(m)) return mark;
|
|
12433
12822
|
const point = (p) => matrix.apply(m, p);
|
|
12434
12823
|
const path = (d) => formatPath(transformPath(parsePath(d), m));
|
|
12435
|
-
const scale =
|
|
12824
|
+
const scale = scaleOf(m);
|
|
12436
12825
|
const { outline } = mark;
|
|
12437
12826
|
return {
|
|
12438
12827
|
key: mark.key,
|
|
@@ -12482,7 +12871,7 @@ function isView(value, container) {
|
|
|
12482
12871
|
"destroy"
|
|
12483
12872
|
].every((method) => typeof view[method] === "function") && element?.nodeType === 1 && container.contains(element);
|
|
12484
12873
|
}
|
|
12485
|
-
function checkOptions$
|
|
12874
|
+
function checkOptions$11(options) {
|
|
12486
12875
|
if (typeof options !== "object" || options === null) throw new TypeError("chartSwitch needs options.");
|
|
12487
12876
|
const { views, initial, transition, announce } = options;
|
|
12488
12877
|
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.");
|
|
@@ -12515,7 +12904,7 @@ let switches = 0;
|
|
|
12515
12904
|
function motionSwitch$1(target, motion, options = {}) {
|
|
12516
12905
|
const parent = resolveTarget$1(target);
|
|
12517
12906
|
checkMotion(motion);
|
|
12518
|
-
checkOptions$
|
|
12907
|
+
checkOptions$10(options);
|
|
12519
12908
|
const labels = {
|
|
12520
12909
|
...LABELS$1,
|
|
12521
12910
|
...options.labels
|
|
@@ -12599,7 +12988,7 @@ function resolveTarget$1(target) {
|
|
|
12599
12988
|
function checkMotion(motion) {
|
|
12600
12989
|
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().");
|
|
12601
12990
|
}
|
|
12602
|
-
function checkOptions$
|
|
12991
|
+
function checkOptions$10(options) {
|
|
12603
12992
|
const { label, labels, hints, persist } = options;
|
|
12604
12993
|
if (label !== void 0 && typeof label !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label}.`);
|
|
12605
12994
|
for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
|
|
@@ -12616,7 +13005,7 @@ const LABELS = {
|
|
|
12616
13005
|
function playButton(target, playback, options = {}) {
|
|
12617
13006
|
const parent = resolveTarget(target);
|
|
12618
13007
|
checkPlayback(playback);
|
|
12619
|
-
checkOptions$
|
|
13008
|
+
checkOptions$9(options);
|
|
12620
13009
|
const labels = {
|
|
12621
13010
|
...LABELS,
|
|
12622
13011
|
...options.labels
|
|
@@ -12657,7 +13046,7 @@ function resolveTarget(target) {
|
|
|
12657
13046
|
function checkPlayback(playback) {
|
|
12658
13047
|
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().");
|
|
12659
13048
|
}
|
|
12660
|
-
function checkOptions$
|
|
13049
|
+
function checkOptions$9(options) {
|
|
12661
13050
|
const { labels } = options;
|
|
12662
13051
|
if (labels === void 0) return;
|
|
12663
13052
|
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)}.`);
|
|
@@ -12709,7 +13098,7 @@ const gaits = {
|
|
|
12709
13098
|
const SPEED = 360;
|
|
12710
13099
|
const SHORTEST = 260;
|
|
12711
13100
|
const LONGEST = 4e3;
|
|
12712
|
-
const MIN_WALK$
|
|
13101
|
+
const MIN_WALK$3 = .5;
|
|
12713
13102
|
const FIT = .85;
|
|
12714
13103
|
const MIN_SMOOTHING = 2;
|
|
12715
13104
|
const IDENTITY = [
|
|
@@ -12727,12 +13116,12 @@ const ORIENTS = [
|
|
|
12727
13116
|
];
|
|
12728
13117
|
const RIDES = ["center", "on"];
|
|
12729
13118
|
function travel(icon, options = {}) {
|
|
12730
|
-
checkOptions$
|
|
13119
|
+
checkOptions$8(icon, options);
|
|
12731
13120
|
function plan(mark, ctx) {
|
|
12732
13121
|
const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
|
|
12733
13122
|
if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
|
|
12734
13123
|
const walk = pick(mark, options.along);
|
|
12735
|
-
if (!walk || !(drawn(walk) >= MIN_WALK$
|
|
13124
|
+
if (!walk || !(drawn(walk) >= MIN_WALK$3)) return void 0;
|
|
12736
13125
|
const scale = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
|
|
12737
13126
|
if (!(scale > 0)) return void 0;
|
|
12738
13127
|
return trip(walk, resolved, scale, options);
|
|
@@ -12880,7 +13269,7 @@ function heading(walk, distance, window, leg) {
|
|
|
12880
13269
|
}
|
|
12881
13270
|
return walk.angle(distance / length);
|
|
12882
13271
|
}
|
|
12883
|
-
function checkOptions$
|
|
13272
|
+
function checkOptions$8(icon, options) {
|
|
12884
13273
|
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}.`);
|
|
12885
13274
|
const { along, gait, size, orient, ride } = options;
|
|
12886
13275
|
if (along !== void 0 && typeof along !== "string") throw new RangeError(`travel: along must be a series name, got ${String(along)}.`);
|
|
@@ -12890,12 +13279,12 @@ function checkOptions$7(icon, options) {
|
|
|
12890
13279
|
if (ride !== void 0 && !RIDES.includes(ride)) throw new RangeError(`travel: ride must be center or on, got ${String(ride)}.`);
|
|
12891
13280
|
}
|
|
12892
13281
|
// src/effects/flash.ts
|
|
12893
|
-
const DURATION$
|
|
13282
|
+
const DURATION$7 = 900;
|
|
12894
13283
|
const PEAK = .25;
|
|
12895
13284
|
const WIDTH$2 = 8;
|
|
12896
13285
|
const OPACITY$2 = .35;
|
|
12897
13286
|
function flash(options = {}) {
|
|
12898
|
-
checkOptions$
|
|
13287
|
+
checkOptions$7(options);
|
|
12899
13288
|
const width = options.width ?? WIDTH$2;
|
|
12900
13289
|
const opacity = options.opacity ?? OPACITY$2;
|
|
12901
13290
|
const { color } = options;
|
|
@@ -12912,7 +13301,7 @@ function flash(options = {}) {
|
|
|
12912
13301
|
async run(_mark, ctx) {
|
|
12913
13302
|
if (ctx.signal.aborted) return;
|
|
12914
13303
|
await ctx.tween({
|
|
12915
|
-
duration: DURATION$
|
|
13304
|
+
duration: DURATION$7,
|
|
12916
13305
|
timing: "effect",
|
|
12917
13306
|
ease: linear,
|
|
12918
13307
|
update: (p) => show(ctx, p)
|
|
@@ -12939,14 +13328,14 @@ function easeOut(x) {
|
|
|
12939
13328
|
const s = (lo + hi) / 2;
|
|
12940
13329
|
return 3 * s * s - 2 * s * s * s;
|
|
12941
13330
|
}
|
|
12942
|
-
function checkOptions$
|
|
13331
|
+
function checkOptions$7(options) {
|
|
12943
13332
|
const { width, opacity, color } = options;
|
|
12944
13333
|
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)}.`);
|
|
12945
13334
|
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)}.`);
|
|
12946
13335
|
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)}.`);
|
|
12947
13336
|
}
|
|
12948
13337
|
// src/effects/wiggle.ts
|
|
12949
|
-
const DURATION$
|
|
13338
|
+
const DURATION$6 = 450;
|
|
12950
13339
|
const SWINGS = [
|
|
12951
13340
|
1,
|
|
12952
13341
|
-.5,
|
|
@@ -12957,7 +13346,7 @@ const MIN_REACH = .5;
|
|
|
12957
13346
|
const SAMPLES = 64;
|
|
12958
13347
|
const MAX_ANGLE = Math.PI / 12;
|
|
12959
13348
|
function wiggle(options = {}) {
|
|
12960
|
-
checkOptions$
|
|
13349
|
+
checkOptions$6(options);
|
|
12961
13350
|
const swing = options.swing ?? SWING;
|
|
12962
13351
|
return {
|
|
12963
13352
|
kind: "geometry",
|
|
@@ -12976,7 +13365,7 @@ function wiggle(options = {}) {
|
|
|
12976
13365
|
show();
|
|
12977
13366
|
});
|
|
12978
13367
|
await ctx.tween({
|
|
12979
|
-
duration: DURATION$
|
|
13368
|
+
duration: DURATION$6,
|
|
12980
13369
|
timing: "effect",
|
|
12981
13370
|
ease: linear,
|
|
12982
13371
|
update: (p) => {
|
|
@@ -13002,19 +13391,19 @@ function rock(t) {
|
|
|
13002
13391
|
const index = Math.floor(position);
|
|
13003
13392
|
return SWINGS[index] * Math.sin(Math.PI * (position - index));
|
|
13004
13393
|
}
|
|
13005
|
-
function checkOptions$
|
|
13394
|
+
function checkOptions$6(options) {
|
|
13006
13395
|
const { swing } = options;
|
|
13007
13396
|
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)}.`);
|
|
13008
13397
|
}
|
|
13009
13398
|
// src/effects/pulse.ts
|
|
13010
|
-
const DURATION$
|
|
13399
|
+
const DURATION$5 = 600;
|
|
13011
13400
|
const TIMES = 2;
|
|
13012
13401
|
const MAX_TIMES = 6;
|
|
13013
13402
|
const WIDTH$1 = 12;
|
|
13014
13403
|
const OPACITY$1 = .4;
|
|
13015
13404
|
const LIMIT = 5e3;
|
|
13016
13405
|
function pulse(options = {}) {
|
|
13017
|
-
checkOptions$
|
|
13406
|
+
checkOptions$5(options);
|
|
13018
13407
|
const times = options.times ?? TIMES;
|
|
13019
13408
|
const width = options.width ?? WIDTH$1;
|
|
13020
13409
|
const { color } = options;
|
|
@@ -13032,11 +13421,11 @@ function pulse(options = {}) {
|
|
|
13032
13421
|
let total = 0;
|
|
13033
13422
|
for (let i = 0; i < times; i++) {
|
|
13034
13423
|
if (ctx.signal.aborted) return;
|
|
13035
|
-
const length = ctx.motion.duration(DURATION$
|
|
13424
|
+
const length = ctx.motion.duration(DURATION$5, "effect");
|
|
13036
13425
|
if (total + length >= LIMIT) return;
|
|
13037
13426
|
total += length;
|
|
13038
13427
|
await ctx.tween({
|
|
13039
|
-
duration: DURATION$
|
|
13428
|
+
duration: DURATION$5,
|
|
13040
13429
|
timing: "effect",
|
|
13041
13430
|
ease: linear,
|
|
13042
13431
|
update: (t) => show(ctx, t)
|
|
@@ -13047,20 +13436,20 @@ function pulse(options = {}) {
|
|
|
13047
13436
|
clear() {}
|
|
13048
13437
|
};
|
|
13049
13438
|
}
|
|
13050
|
-
function checkOptions$
|
|
13439
|
+
function checkOptions$5(options) {
|
|
13051
13440
|
const { times, width, color } = options;
|
|
13052
13441
|
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)}.`);
|
|
13053
13442
|
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)}.`);
|
|
13054
13443
|
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)}.`);
|
|
13055
13444
|
}
|
|
13056
13445
|
// src/effects/trace.ts
|
|
13057
|
-
const DURATION$
|
|
13446
|
+
const DURATION$4 = 500;
|
|
13058
13447
|
const WIDTH = 3;
|
|
13059
13448
|
const OPACITY = .5;
|
|
13060
|
-
const MIN_WALK$
|
|
13449
|
+
const MIN_WALK$2 = .5;
|
|
13061
13450
|
function trace(options = {}) {
|
|
13062
|
-
checkOptions$
|
|
13063
|
-
const duration = options.duration ?? DURATION$
|
|
13451
|
+
checkOptions$4(options);
|
|
13452
|
+
const duration = options.duration ?? DURATION$4;
|
|
13064
13453
|
const paint = {
|
|
13065
13454
|
stroke: options.color ?? "mark",
|
|
13066
13455
|
width: options.width ?? WIDTH,
|
|
@@ -13072,7 +13461,7 @@ function trace(options = {}) {
|
|
|
13072
13461
|
let progress = 0;
|
|
13073
13462
|
let path;
|
|
13074
13463
|
const draw = () => {
|
|
13075
|
-
if (!(current.length >= MIN_WALK$
|
|
13464
|
+
if (!(current.length >= MIN_WALK$2)) {
|
|
13076
13465
|
path?.remove();
|
|
13077
13466
|
path = void 0;
|
|
13078
13467
|
return;
|
|
@@ -13096,7 +13485,7 @@ function trace(options = {}) {
|
|
|
13096
13485
|
async run(mark, ctx) {
|
|
13097
13486
|
if (ctx.signal.aborted) return;
|
|
13098
13487
|
const show = stroke(mark, ctx);
|
|
13099
|
-
if (!(mark.length >= MIN_WALK$
|
|
13488
|
+
if (!(mark.length >= MIN_WALK$2)) {
|
|
13100
13489
|
show(1);
|
|
13101
13490
|
return;
|
|
13102
13491
|
}
|
|
@@ -13113,13 +13502,82 @@ function trace(options = {}) {
|
|
|
13113
13502
|
clear() {}
|
|
13114
13503
|
};
|
|
13115
13504
|
}
|
|
13116
|
-
function checkOptions$
|
|
13505
|
+
function checkOptions$4(options) {
|
|
13117
13506
|
const { color, width, opacity, duration } = options;
|
|
13118
13507
|
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)}.`);
|
|
13119
13508
|
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)}.`);
|
|
13120
13509
|
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)}.`);
|
|
13121
13510
|
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)}.`);
|
|
13122
13511
|
}
|
|
13512
|
+
// src/effects/draw-in.ts
|
|
13513
|
+
const DURATION$3 = 750;
|
|
13514
|
+
const FAINT = .3;
|
|
13515
|
+
const MIN_WALK$1 = .5;
|
|
13516
|
+
function drawIn(options = {}) {
|
|
13517
|
+
checkOptions$3(options);
|
|
13518
|
+
const duration = options.duration ?? DURATION$3;
|
|
13519
|
+
const faint = options.faint ?? FAINT;
|
|
13520
|
+
return {
|
|
13521
|
+
kind: "geometry",
|
|
13522
|
+
async run(mark, ctx) {
|
|
13523
|
+
if (ctx.signal.aborted || !(walk(mark) >= MIN_WALK$1)) return;
|
|
13524
|
+
let current = mark;
|
|
13525
|
+
let progress = 0;
|
|
13526
|
+
let done = false;
|
|
13527
|
+
const paths = [];
|
|
13528
|
+
const draw = (repaint) => {
|
|
13529
|
+
const { segments } = current;
|
|
13530
|
+
const parts = segments ?? [current];
|
|
13531
|
+
const reached = progress * walk(current);
|
|
13532
|
+
let from = 0;
|
|
13533
|
+
parts.forEach((piece, i) => {
|
|
13534
|
+
const share = piece.length > 0 ? Math.min(1, Math.max(0, (reached - from) / piece.length)) : 0;
|
|
13535
|
+
from += piece.length;
|
|
13536
|
+
const d = piece.slice(0, easeInOutCubic(share));
|
|
13537
|
+
const paint = {
|
|
13538
|
+
stroke: "mark",
|
|
13539
|
+
width: piece.thickness,
|
|
13540
|
+
linecap: "butt",
|
|
13541
|
+
...segments && { part: piece.key }
|
|
13542
|
+
};
|
|
13543
|
+
const path = paths[i];
|
|
13544
|
+
if (!path) paths[i] = ctx.layer.path(d, paint);
|
|
13545
|
+
else path.update(d, repaint ? {
|
|
13546
|
+
part: void 0,
|
|
13547
|
+
...paint
|
|
13548
|
+
} : void 0);
|
|
13549
|
+
});
|
|
13550
|
+
for (const path of paths.splice(parts.length)) path.remove();
|
|
13551
|
+
};
|
|
13552
|
+
ctx.onChange((next) => {
|
|
13553
|
+
current = next;
|
|
13554
|
+
if (!done) draw(true);
|
|
13555
|
+
});
|
|
13556
|
+
ctx.mark.set({ opacity: faint });
|
|
13557
|
+
draw(false);
|
|
13558
|
+
await ctx.tween({
|
|
13559
|
+
duration,
|
|
13560
|
+
timing: "effect",
|
|
13561
|
+
ease: linear,
|
|
13562
|
+
update: (p) => {
|
|
13563
|
+
progress = p;
|
|
13564
|
+
draw(false);
|
|
13565
|
+
}
|
|
13566
|
+
}).finished;
|
|
13567
|
+
done = true;
|
|
13568
|
+
for (const path of paths) path.remove();
|
|
13569
|
+
ctx.mark.set({ opacity: void 0 });
|
|
13570
|
+
},
|
|
13571
|
+
end() {},
|
|
13572
|
+
clear() {}
|
|
13573
|
+
};
|
|
13574
|
+
}
|
|
13575
|
+
const walk = (mark) => (mark.segments ?? [mark]).reduce((sum, part) => sum + part.length, 0);
|
|
13576
|
+
function checkOptions$3(options) {
|
|
13577
|
+
const { duration, faint } = options;
|
|
13578
|
+
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)}.`);
|
|
13579
|
+
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)}.`);
|
|
13580
|
+
}
|
|
13123
13581
|
// src/effects/caption.ts
|
|
13124
13582
|
const PAST_END = 10;
|
|
13125
13583
|
const PAST_LABEL = 6;
|
|
@@ -13140,9 +13598,9 @@ function captionPlace(mark, text) {
|
|
|
13140
13598
|
return past(mark.end, heading, PAST_END, own, boxes, text);
|
|
13141
13599
|
}
|
|
13142
13600
|
function past(from, toward, least, own, boxes, text) {
|
|
13143
|
-
if (!text) return placed(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
|
|
13144
|
-
const { x, y, width, height } = text.box(placed(from, toward, 0));
|
|
13145
|
-
return placed(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
|
|
13601
|
+
if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
|
|
13602
|
+
const { x, y, width, height } = text.box(placed$1(from, toward, 0));
|
|
13603
|
+
return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
|
|
13146
13604
|
x: x - from.x,
|
|
13147
13605
|
y: y - from.y,
|
|
13148
13606
|
width,
|
|
@@ -13184,7 +13642,7 @@ const grow = ({ x, y, width, height }, by) => ({
|
|
|
13184
13642
|
width: width + 2 * by,
|
|
13185
13643
|
height: height + 2 * by
|
|
13186
13644
|
});
|
|
13187
|
-
function placed(from, toward, distance) {
|
|
13645
|
+
function placed$1(from, toward, distance) {
|
|
13188
13646
|
const cos = Math.cos(toward);
|
|
13189
13647
|
const sin = Math.sin(toward);
|
|
13190
13648
|
const point = offset(from, toward, distance);
|
|
@@ -13424,7 +13882,7 @@ function reference(compareTo, data) {
|
|
|
13424
13882
|
const gaps = gapsOf(related.samples, place);
|
|
13425
13883
|
return {
|
|
13426
13884
|
place,
|
|
13427
|
-
valueAt: (u) => inside(gaps, u) ? void 0 : interpolate(points, u),
|
|
13885
|
+
valueAt: (u) => inside$1(gaps, u) ? void 0 : interpolate(points, u),
|
|
13428
13886
|
bends: points.map((point) => point.u)
|
|
13429
13887
|
};
|
|
13430
13888
|
}
|
|
@@ -13446,7 +13904,7 @@ function gapsOf(samples, place) {
|
|
|
13446
13904
|
}
|
|
13447
13905
|
return merged;
|
|
13448
13906
|
}
|
|
13449
|
-
function inside(gaps, u) {
|
|
13907
|
+
function inside$1(gaps, u) {
|
|
13450
13908
|
let lo = 0;
|
|
13451
13909
|
let hi = gaps.length;
|
|
13452
13910
|
while (lo < hi) {
|
|
@@ -13553,6 +14011,8 @@ const DURATION = 950;
|
|
|
13553
14011
|
const POINTS = 160;
|
|
13554
14012
|
const ALIGNS = ["unroll", "drop"];
|
|
13555
14013
|
const SAME_T = 1e-9;
|
|
14014
|
+
const SAME_X = .01;
|
|
14015
|
+
const VERTICES = 1e3;
|
|
13556
14016
|
const GRID = 9;
|
|
13557
14017
|
const CHECKS = 8;
|
|
13558
14018
|
function morph(options = {}) {
|
|
@@ -13592,6 +14052,8 @@ function morph(options = {}) {
|
|
|
13592
14052
|
function drawing(from, to, layer, points, align) {
|
|
13593
14053
|
const closed = from.outline.closed;
|
|
13594
14054
|
if (closed !== to.outline.closed) return crossfade(from, to, layer);
|
|
14055
|
+
const across = closed ? void 0 : acrossX(from, to, points);
|
|
14056
|
+
if (across) return piecewise(from, to, layer, across.stops, across.kinds);
|
|
13595
14057
|
const a = from.outline.sample(points);
|
|
13596
14058
|
const b = to.outline.sample(points);
|
|
13597
14059
|
if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
|
|
@@ -13629,20 +14091,25 @@ function gapped(from, to, layer, a, b) {
|
|
|
13629
14091
|
to: to.path(t)
|
|
13630
14092
|
});
|
|
13631
14093
|
stops.sort((x, y) => x.t - y.t);
|
|
14094
|
+
return piecewise(from, to, layer, stops, stops.slice(1).map((stop, k) => {
|
|
14095
|
+
const t = (stops[k].t + stop.t) / 2;
|
|
14096
|
+
return (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
14097
|
+
}));
|
|
14098
|
+
}
|
|
14099
|
+
function piecewise(from, to, layer, stops, kinds) {
|
|
13632
14100
|
const runs = [
|
|
13633
14101
|
[],
|
|
13634
14102
|
[],
|
|
13635
14103
|
[]
|
|
13636
14104
|
];
|
|
13637
|
-
for (let k = 0; k
|
|
13638
|
-
const
|
|
13639
|
-
const kind = (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
14105
|
+
for (let k = 0; k < kinds.length; k++) {
|
|
14106
|
+
const kind = kinds[k];
|
|
13640
14107
|
if (kind === 3) continue;
|
|
13641
14108
|
const last = runs[kind][runs[kind].length - 1];
|
|
13642
14109
|
if (last && last[1] === k) last[1] = k + 1;
|
|
13643
14110
|
else runs[kind].push([k, k + 1]);
|
|
13644
14111
|
}
|
|
13645
|
-
const
|
|
14112
|
+
const order = [
|
|
13646
14113
|
0,
|
|
13647
14114
|
1,
|
|
13648
14115
|
2
|
|
@@ -13655,7 +14122,7 @@ function gapped(from, to, layer, a, b) {
|
|
|
13655
14122
|
p,
|
|
13656
14123
|
1 - p
|
|
13657
14124
|
];
|
|
13658
|
-
const pieces = p <= 0 || p >= 1 ? [[p <= 0 ? from.outline.d : to.outline.d, void 0]] :
|
|
14125
|
+
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]]);
|
|
13659
14126
|
pieces.forEach(([d, opacity], i) => {
|
|
13660
14127
|
if (paths[i]) paths[i].update(d, {
|
|
13661
14128
|
width,
|
|
@@ -13676,6 +14143,113 @@ function along(stops, [first, last], p) {
|
|
|
13676
14143
|
for (let k = first; k <= last; k++) d += `${k === first ? "M" : "L"}${at(stops[k].from, stops[k].to, p)}`;
|
|
13677
14144
|
return d;
|
|
13678
14145
|
}
|
|
14146
|
+
function acrossX(from, to, points) {
|
|
14147
|
+
const a = courseOf(from);
|
|
14148
|
+
const b = a && courseOf(to);
|
|
14149
|
+
if (!a || !b || a.way !== b.way) return void 0;
|
|
14150
|
+
const all = [
|
|
14151
|
+
...Array.from({ length: points }, (_, i) => [i / (points - 1), 0]),
|
|
14152
|
+
...corners(a).map((s) => [s, 1]),
|
|
14153
|
+
...corners(b).map((s) => [s, 2])
|
|
14154
|
+
].sort((x, y) => x[0] - y[0]);
|
|
14155
|
+
const same = SAME_X / Math.max(Math.abs(a.span), Math.abs(b.span));
|
|
14156
|
+
const merged = [];
|
|
14157
|
+
for (const [s, whose] of all) {
|
|
14158
|
+
var _stop, _stop2;
|
|
14159
|
+
let stop = merged[merged.length - 1];
|
|
14160
|
+
if (!stop || s - stop[0] > same || whose > 0 && stop[whose] !== void 0) merged.push(stop = [s]);
|
|
14161
|
+
if (whose === 1) (_stop = stop)[1] ?? (_stop[1] = s);
|
|
14162
|
+
if (whose === 2) (_stop2 = stop)[2] ?? (_stop2[2] = s);
|
|
14163
|
+
}
|
|
14164
|
+
const last = merged.length - 1;
|
|
14165
|
+
if (last < 1) return void 0;
|
|
14166
|
+
const shareOn = (whose) => merged.map((stop, k) => k === 0 ? 0 : k === last ? 1 : stop[whose] ?? stop[0]);
|
|
14167
|
+
const [onA, onB] = [shareOn(1), shareOn(2)];
|
|
14168
|
+
const [pointsA, pointsB] = [placed(a, onA), placed(b, onB)];
|
|
14169
|
+
const stops = merged.map(([t], k) => ({
|
|
14170
|
+
t,
|
|
14171
|
+
from: pointsA[k],
|
|
14172
|
+
to: pointsB[k]
|
|
14173
|
+
}));
|
|
14174
|
+
const [inA, inB] = [inside(a.gaps), inside(b.gaps)];
|
|
14175
|
+
return {
|
|
14176
|
+
stops,
|
|
14177
|
+
kinds: stops.slice(1).map((_, k) => (inA((onA[k] + onA[k + 1]) / 2) ? 1 : 0) + (inB((onB[k] + onB[k + 1]) / 2) ? 2 : 0))
|
|
14178
|
+
};
|
|
14179
|
+
}
|
|
14180
|
+
function courseOf(mark) {
|
|
14181
|
+
const subpaths = flattenPath(parsePath(mark.outline.d));
|
|
14182
|
+
const points = [];
|
|
14183
|
+
const before = [];
|
|
14184
|
+
let next = 0;
|
|
14185
|
+
let from = 0;
|
|
14186
|
+
const stretch = (to) => {
|
|
14187
|
+
if (!(to > from)) {
|
|
14188
|
+
points.push(mark.path(from));
|
|
14189
|
+
return true;
|
|
14190
|
+
}
|
|
14191
|
+
const subpath = subpaths[next++];
|
|
14192
|
+
if (!subpath) return false;
|
|
14193
|
+
points.push(subpath.start);
|
|
14194
|
+
for (const segment of subpath.segments) {
|
|
14195
|
+
if (segment.kind !== "line") return false;
|
|
14196
|
+
points.push(segment.to);
|
|
14197
|
+
}
|
|
14198
|
+
return true;
|
|
14199
|
+
};
|
|
14200
|
+
for (const [start, end] of mark.gaps ?? []) {
|
|
14201
|
+
if (!stretch(start)) return void 0;
|
|
14202
|
+
before.push(points.length - 1);
|
|
14203
|
+
from = end;
|
|
14204
|
+
}
|
|
14205
|
+
if (!stretch(1) || next < subpaths.length || points.length < 2) return void 0;
|
|
14206
|
+
const x0 = points[0].x;
|
|
14207
|
+
const span = points[points.length - 1].x - x0;
|
|
14208
|
+
const way = Math.sign(span);
|
|
14209
|
+
for (let i = 1; i < points.length; i++) if (!((points[i].x - points[i - 1].x) * way > 0)) return void 0;
|
|
14210
|
+
const shares = points.map((point) => (point.x - x0) / span);
|
|
14211
|
+
return {
|
|
14212
|
+
points,
|
|
14213
|
+
shares,
|
|
14214
|
+
gaps: before.map((i) => [shares[i], shares[i + 1]]),
|
|
14215
|
+
span,
|
|
14216
|
+
way
|
|
14217
|
+
};
|
|
14218
|
+
}
|
|
14219
|
+
function corners(course) {
|
|
14220
|
+
const { points, shares, gaps } = course;
|
|
14221
|
+
if (points.length <= VERTICES) return shares;
|
|
14222
|
+
const columns = VERTICES / 4;
|
|
14223
|
+
const column = (k) => Math.min(249, Math.floor(shares[k] * columns));
|
|
14224
|
+
const kept = gaps.flat();
|
|
14225
|
+
for (let first = 0, i = 1; i <= points.length; i++) {
|
|
14226
|
+
if (i < points.length && column(i) === column(first)) continue;
|
|
14227
|
+
let [low, high] = [first, first];
|
|
14228
|
+
for (let k = first; k < i; k++) {
|
|
14229
|
+
if (points[k].y < points[low].y) low = k;
|
|
14230
|
+
if (points[k].y > points[high].y) high = k;
|
|
14231
|
+
}
|
|
14232
|
+
kept.push(shares[first], shares[low], shares[high], shares[i - 1]);
|
|
14233
|
+
first = i;
|
|
14234
|
+
}
|
|
14235
|
+
return Array.from(new Set(kept));
|
|
14236
|
+
}
|
|
14237
|
+
function placed(course, shares) {
|
|
14238
|
+
const { points, shares: at } = course;
|
|
14239
|
+
let i = 0;
|
|
14240
|
+
return shares.map((s) => {
|
|
14241
|
+
while (i + 2 < points.length && at[i + 1] <= s) i++;
|
|
14242
|
+
const width = at[i + 1] - at[i];
|
|
14243
|
+
return mixed(points[i], points[i + 1], width > 0 ? Math.min(1, Math.max(0, (s - at[i]) / width)) : 0);
|
|
14244
|
+
});
|
|
14245
|
+
}
|
|
14246
|
+
function inside(gaps) {
|
|
14247
|
+
let k = 0;
|
|
14248
|
+
return (s) => {
|
|
14249
|
+
while (k < gaps.length && gaps[k][1] <= s) k++;
|
|
14250
|
+
return k < gaps.length && gaps[k][0] < s;
|
|
14251
|
+
};
|
|
14252
|
+
}
|
|
13679
14253
|
function holePairs(from, to, a, b, [shiftA, shiftB], count) {
|
|
13680
14254
|
const holesA = holesOf(from.outline, count);
|
|
13681
14255
|
const holesB = holesOf(to.outline, count);
|
|
@@ -14470,7 +15044,7 @@ function configure(options) {
|
|
|
14470
15044
|
}
|
|
14471
15045
|
}
|
|
14472
15046
|
// src/index.ts
|
|
14473
|
-
const VERSION = "0.
|
|
15047
|
+
const VERSION = "0.8.0";
|
|
14474
15048
|
const env = {
|
|
14475
15049
|
presets: presetRegistry,
|
|
14476
15050
|
icons: iconRegistry,
|
|
@@ -14516,6 +15090,7 @@ exports.defineIcon = defineIcon;
|
|
|
14516
15090
|
exports.delta = delta;
|
|
14517
15091
|
exports.describe = describe;
|
|
14518
15092
|
exports.donutChart = donutChart;
|
|
15093
|
+
exports.drawIn = drawIn;
|
|
14519
15094
|
exports.easeInOutCubic = easeInOutCubic;
|
|
14520
15095
|
exports.easeOutCubic = easeOutCubic;
|
|
14521
15096
|
exports.expressive = expressive;
|