expressive-charts 0.8.0 → 0.10.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 +30 -0
- package/README.md +7 -7
- package/dist/drawing-OmQV-0BB.d.ts +1 -2
- package/dist/effect-HCWnmB72.d.ts +1 -2
- package/dist/expressive-charts.global.js +6 -6
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.d.cts +2 -3
- package/dist/icons/sport.d.ts +1 -2
- package/dist/index-CmnxlWkB.d.cts +752 -0
- package/dist/index.cjs +325 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +189 -382
- package/dist/index.d.ts +187 -100
- package/dist/index.js +325 -55
- package/dist/index.js.map +1 -1
- package/dist/runner-C87v9F_y.d.cts +1 -0
- package/dist/testing.d.cts +3 -4
- package/dist/testing.d.ts +1 -2
- package/package.json +9 -7
- package/dist/drawing-OmQV-0BB.d.cts +0 -220
- package/dist/effect-DYCLY_6e.d.cts +0 -256
package/dist/index.cjs
CHANGED
|
@@ -5230,6 +5230,7 @@ function watchText(svg, clock, changed) {
|
|
|
5230
5230
|
return () => {
|
|
5231
5231
|
observer.disconnect();
|
|
5232
5232
|
stopFrame?.();
|
|
5233
|
+
probe.remove();
|
|
5233
5234
|
};
|
|
5234
5235
|
}
|
|
5235
5236
|
function watchHoverDuration(svg, motion) {
|
|
@@ -10229,11 +10230,25 @@ function hostColors(element, root) {
|
|
|
10229
10230
|
const color = paint === "fill" ? fill : paintOf$1(element, root, "stroke");
|
|
10230
10231
|
if (color === void 0 || color === NONE) return void 0;
|
|
10231
10232
|
return {
|
|
10232
|
-
color,
|
|
10233
|
-
strong: `color-mix(in oklab, ${color}, ${cssColor("text")} ${STRONG})`,
|
|
10233
|
+
...strongColors(color),
|
|
10234
10234
|
paint
|
|
10235
10235
|
};
|
|
10236
10236
|
}
|
|
10237
|
+
function strongColors(color) {
|
|
10238
|
+
return {
|
|
10239
|
+
color,
|
|
10240
|
+
strong: `color-mix(in oklab, ${color}, ${cssColor("text")} ${STRONG})`
|
|
10241
|
+
};
|
|
10242
|
+
}
|
|
10243
|
+
function drawnStyle(element, root, property) {
|
|
10244
|
+
const computed = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue(property).trim() ?? "";
|
|
10245
|
+
if (attributesComputed(root)) return computed;
|
|
10246
|
+
for (let node = element; node; node = node === root ? null : node.parentElement) {
|
|
10247
|
+
const value = node.style?.getPropertyValue(property) || node.getAttribute(property);
|
|
10248
|
+
if (value) return value.trim();
|
|
10249
|
+
}
|
|
10250
|
+
return computed;
|
|
10251
|
+
}
|
|
10237
10252
|
const STRONG = "25%";
|
|
10238
10253
|
const NONE = "none";
|
|
10239
10254
|
const SVG_NS$1 = "http://www.w3.org/2000/svg";
|
|
@@ -10644,6 +10659,8 @@ const WRAPPING_ROLES = /* @__PURE__ */ new Set([
|
|
|
10644
10659
|
"graphics-symbol",
|
|
10645
10660
|
"graphics-object"
|
|
10646
10661
|
]);
|
|
10662
|
+
const insides = /* @__PURE__ */ new WeakMap();
|
|
10663
|
+
const insidesOf = (port) => port ? insides.get(port) : void 0;
|
|
10647
10664
|
function expressive$1(target, options, env) {
|
|
10648
10665
|
checkOptions$12(options);
|
|
10649
10666
|
const motion = chartMotion(options.motion, env.motion);
|
|
@@ -10972,8 +10989,10 @@ function expressive$1(target, options, env) {
|
|
|
10972
10989
|
const runs = make("g", { class: "ec-runs" }, overlay);
|
|
10973
10990
|
const ring = maskedRing(overlay);
|
|
10974
10991
|
const find = (key) => records.get(key) ?? leaving.get(key);
|
|
10992
|
+
const measure = textMeasure(runs);
|
|
10975
10993
|
const surface = svgSurface({
|
|
10976
10994
|
overlay: runs,
|
|
10995
|
+
measure,
|
|
10977
10996
|
mark: (key) => ({
|
|
10978
10997
|
set: (style) => find(key)?.handle.set(style),
|
|
10979
10998
|
reset: () => find(key)?.handle.reset()
|
|
@@ -10991,6 +11010,12 @@ function expressive$1(target, options, env) {
|
|
|
10991
11010
|
mark: record.mark.geometry,
|
|
10992
11011
|
data: record.mark.data
|
|
10993
11012
|
});
|
|
11013
|
+
function remeasure() {
|
|
11014
|
+
measure.clear();
|
|
11015
|
+
for (const record of order) runner.change(record.mark.geometry, record.mark.data);
|
|
11016
|
+
}
|
|
11017
|
+
let unwatchText = () => {};
|
|
11018
|
+
const unwatchFonts = watchFonts(doc, remeasure);
|
|
10994
11019
|
function createRecord(mark) {
|
|
10995
11020
|
const record = {
|
|
10996
11021
|
key: mark.key,
|
|
@@ -11101,6 +11126,7 @@ function expressive$1(target, options, env) {
|
|
|
11101
11126
|
function moveTo(next) {
|
|
11102
11127
|
detach();
|
|
11103
11128
|
root = next;
|
|
11129
|
+
unwatchText = watchText(root, clock, remeasure);
|
|
11104
11130
|
root.appendChild(overlay);
|
|
11105
11131
|
if ((options.keyboard === true || options.markLabel) && root.getAttribute("role") === "img" && !warnedImage) {
|
|
11106
11132
|
warnedImage = true;
|
|
@@ -11132,6 +11158,7 @@ function expressive$1(target, options, env) {
|
|
|
11132
11158
|
endHover();
|
|
11133
11159
|
interaction?.destroy();
|
|
11134
11160
|
interaction = void 0;
|
|
11161
|
+
unwatchText();
|
|
11135
11162
|
}
|
|
11136
11163
|
function ownerOf(eventTarget) {
|
|
11137
11164
|
for (let node = eventTarget; node && node !== root; node = node.parentElement) {
|
|
@@ -11431,6 +11458,17 @@ function expressive$1(target, options, env) {
|
|
|
11431
11458
|
return true;
|
|
11432
11459
|
}
|
|
11433
11460
|
};
|
|
11461
|
+
const refreshed = /* @__PURE__ */ new Set();
|
|
11462
|
+
insides.set(link, {
|
|
11463
|
+
root: () => root,
|
|
11464
|
+
ancestor: () => ancestor,
|
|
11465
|
+
elements: () => order.flatMap((record) => record.mark.parts.map((part) => part.element)),
|
|
11466
|
+
keyOf: (element) => ownerOf(element)?.record.key,
|
|
11467
|
+
colorOf: (key) => records.get(key)?.mark.parts[0]?.colors?.color,
|
|
11468
|
+
moveTabStop: (key) => keyboard?.moveTabStop(key) ?? false,
|
|
11469
|
+
edits,
|
|
11470
|
+
refreshed
|
|
11471
|
+
});
|
|
11434
11472
|
return linkable(link, {
|
|
11435
11473
|
refresh(next) {
|
|
11436
11474
|
if (destroyed) return;
|
|
@@ -11468,6 +11506,7 @@ function expressive$1(target, options, env) {
|
|
|
11468
11506
|
for (const record of following) runner.change(record.mark.geometry, record.mark.data);
|
|
11469
11507
|
runner.settle();
|
|
11470
11508
|
keyboard?.sync();
|
|
11509
|
+
for (const listener of refreshed) listener();
|
|
11471
11510
|
exited.then(() => {
|
|
11472
11511
|
for (const record of diff.exiting) if (leaving.get(record.key) === record) leaving.delete(record.key);
|
|
11473
11512
|
});
|
|
@@ -11509,6 +11548,7 @@ function expressive$1(target, options, env) {
|
|
|
11509
11548
|
watching?.destroy();
|
|
11510
11549
|
runner.destroy();
|
|
11511
11550
|
unsubscribeMotion?.();
|
|
11551
|
+
unwatchFonts();
|
|
11512
11552
|
keyboard?.destroy();
|
|
11513
11553
|
detach();
|
|
11514
11554
|
overlay.remove();
|
|
@@ -11659,6 +11699,134 @@ function geometryChanged(from, to) {
|
|
|
11659
11699
|
const b = to.segments ?? [];
|
|
11660
11700
|
return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
|
|
11661
11701
|
}
|
|
11702
|
+
// src/charts/adapter/host-view.ts
|
|
11703
|
+
const FONT = [
|
|
11704
|
+
"font-family",
|
|
11705
|
+
"font-size",
|
|
11706
|
+
"font-style",
|
|
11707
|
+
"font-weight",
|
|
11708
|
+
"font-variant-numeric",
|
|
11709
|
+
"letter-spacing",
|
|
11710
|
+
"word-spacing",
|
|
11711
|
+
"dominant-baseline",
|
|
11712
|
+
"fill"
|
|
11713
|
+
];
|
|
11714
|
+
const LENGTHS = /* @__PURE__ */ new Set([
|
|
11715
|
+
"font-size",
|
|
11716
|
+
"letter-spacing",
|
|
11717
|
+
"word-spacing"
|
|
11718
|
+
]);
|
|
11719
|
+
function first(element, name) {
|
|
11720
|
+
const list = element[name]?.baseVal;
|
|
11721
|
+
if (list && list.numberOfItems > 0) return list.getItem(0).value;
|
|
11722
|
+
return Number.parseFloat(element.getAttribute(name) ?? "") || 0;
|
|
11723
|
+
}
|
|
11724
|
+
function scaled(value, scale) {
|
|
11725
|
+
if (scale === 1) return value;
|
|
11726
|
+
return value.replace(/(-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(px)?(?![\w.%])/gi, (_, n, px) => `${Math.round(Number(n) * scale * 1e3) / 1e3}${px ?? ""}`);
|
|
11727
|
+
}
|
|
11728
|
+
function hostView(attachment, options = {}) {
|
|
11729
|
+
const port = typeof attachment === "object" && attachment !== null ? portOf(attachment) : void 0;
|
|
11730
|
+
const inside = insidesOf(port);
|
|
11731
|
+
if (!port || !inside?.root()) throw new TypeError("hostView needs an attachment that expressive() or fromVegaView() returned, with marks in an <svg>.");
|
|
11732
|
+
if (typeof options !== "object" || options === null || options.labels !== void 0 && typeof options.labels !== "function") throw new TypeError("hostView: labels must be a function that returns the host's labels, such as () => names.map((element) => ({ element, key: element.textContent, role: \"category\" })).");
|
|
11733
|
+
const { edits } = inside;
|
|
11734
|
+
const svg = () => inside.root();
|
|
11735
|
+
let given;
|
|
11736
|
+
let hidden = [];
|
|
11737
|
+
let classed;
|
|
11738
|
+
function read() {
|
|
11739
|
+
if (!options.labels) return [];
|
|
11740
|
+
const keys = new Set(attachment.marks().map((mark) => mark.key));
|
|
11741
|
+
try {
|
|
11742
|
+
return Array.from(options.labels()).filter((label) => label?.element?.localName === "text" && svg().contains(label.element) && keys.has(label.key) && (label.role === "category" || label.role === "value"));
|
|
11743
|
+
} catch (error) {
|
|
11744
|
+
report(error);
|
|
11745
|
+
return [];
|
|
11746
|
+
}
|
|
11747
|
+
}
|
|
11748
|
+
function chartLabel({ element, key, role }) {
|
|
11749
|
+
const root = svg();
|
|
11750
|
+
const m = between$1(view.space, element, root);
|
|
11751
|
+
const at = matrix.apply(m, {
|
|
11752
|
+
x: first(element, "x"),
|
|
11753
|
+
y: first(element, "y")
|
|
11754
|
+
});
|
|
11755
|
+
const scale = scaleOf$2(m);
|
|
11756
|
+
const text = element.ownerDocument.createElementNS(SVG_NS$2, "text");
|
|
11757
|
+
text.textContent = element.textContent;
|
|
11758
|
+
for (const name of ["dx", "dy"]) {
|
|
11759
|
+
const value = element.getAttribute(name);
|
|
11760
|
+
if (value !== null) text.setAttribute(name, scaled(value, scale));
|
|
11761
|
+
}
|
|
11762
|
+
setStyles(text, Object.fromEntries(FONT.map((property) => {
|
|
11763
|
+
const value = drawnStyle(element, root, property);
|
|
11764
|
+
return [property, (LENGTHS.has(property) ? scaled(value, scale) : value) || void 0];
|
|
11765
|
+
})));
|
|
11766
|
+
const anchor = drawnStyle(element, root, "text-anchor");
|
|
11767
|
+
return {
|
|
11768
|
+
key,
|
|
11769
|
+
role,
|
|
11770
|
+
text: element.textContent ?? "",
|
|
11771
|
+
x: at.x,
|
|
11772
|
+
y: at.y,
|
|
11773
|
+
anchor: anchor === "middle" || anchor === "end" ? anchor : "start",
|
|
11774
|
+
element: text
|
|
11775
|
+
};
|
|
11776
|
+
}
|
|
11777
|
+
const hide = (on) => {
|
|
11778
|
+
const root = on ? svg() : void 0;
|
|
11779
|
+
given = on ? read() : void 0;
|
|
11780
|
+
const now = new Set(given ? [
|
|
11781
|
+
...inside.elements(),
|
|
11782
|
+
...given.map((label) => label.element),
|
|
11783
|
+
...hidden.filter((element) => root?.contains(element))
|
|
11784
|
+
] : []);
|
|
11785
|
+
for (const element of hidden) if (!now.has(element)) edits.style(element, "visibility", void 0);
|
|
11786
|
+
hidden = [...now];
|
|
11787
|
+
for (const element of hidden) edits.style(element, "visibility", "hidden");
|
|
11788
|
+
if (classed !== root) {
|
|
11789
|
+
if (classed) edits.toggleClass(classed, "ec-morphing", false);
|
|
11790
|
+
if (root) edits.toggleClass(root, "ec-morphing", true);
|
|
11791
|
+
classed = root;
|
|
11792
|
+
}
|
|
11793
|
+
};
|
|
11794
|
+
const view = {
|
|
11795
|
+
get element() {
|
|
11796
|
+
return svg();
|
|
11797
|
+
},
|
|
11798
|
+
get space() {
|
|
11799
|
+
return inside.ancestor() ?? svg();
|
|
11800
|
+
},
|
|
11801
|
+
refresh: (source) => attachment.refresh(source),
|
|
11802
|
+
update: (next) => attachment.update(next),
|
|
11803
|
+
on: (type, listener) => attachment.on(type, listener),
|
|
11804
|
+
marks: () => attachment.marks(),
|
|
11805
|
+
focus: (key) => attachment.focus(key),
|
|
11806
|
+
leave: () => attachment.leave(),
|
|
11807
|
+
destroy() {
|
|
11808
|
+
given = classed = void 0;
|
|
11809
|
+
hidden = [];
|
|
11810
|
+
attachment.destroy();
|
|
11811
|
+
},
|
|
11812
|
+
labels: () => (given ?? read()).map(chartLabel),
|
|
11813
|
+
paintOf(key) {
|
|
11814
|
+
const color = inside.colorOf(key);
|
|
11815
|
+
return color === void 0 ? void 0 : {
|
|
11816
|
+
color: key,
|
|
11817
|
+
drawn: true,
|
|
11818
|
+
cssColor: color
|
|
11819
|
+
};
|
|
11820
|
+
},
|
|
11821
|
+
keyOf: (element) => inside.keyOf(element),
|
|
11822
|
+
moveTabStop: (key) => inside.moveTabStop(key),
|
|
11823
|
+
morphing: hide
|
|
11824
|
+
};
|
|
11825
|
+
inside.refreshed.add(() => {
|
|
11826
|
+
if (given) hide(true);
|
|
11827
|
+
});
|
|
11828
|
+
return linkable(port, view);
|
|
11829
|
+
}
|
|
11662
11830
|
// src/charts/adapter/vega.ts
|
|
11663
11831
|
const MARK_TYPES = [
|
|
11664
11832
|
"line",
|
|
@@ -12240,13 +12408,14 @@ function chartSwitch$1(target, options, env) {
|
|
|
12240
12408
|
const runsLayer = svgElement("g", { class: "ec-switch-runs" }, overlay);
|
|
12241
12409
|
const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
|
|
12242
12410
|
const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
|
|
12411
|
+
const tokensOf = (paint) => markColorStyles(paint.cssColor === void 0 ? seriesColors(colors.slot(paint.color)) : strongColors(paint.cssColor));
|
|
12243
12412
|
const orders = /* @__PURE__ */ new WeakMap();
|
|
12244
12413
|
const surfaceFor = (paints, extras) => ({ group(key, order) {
|
|
12245
12414
|
const group = svgElement("g", {
|
|
12246
12415
|
class: "ec-run",
|
|
12247
12416
|
"data-key": key
|
|
12248
12417
|
}, runsLayer);
|
|
12249
|
-
setStyles(group,
|
|
12418
|
+
setStyles(group, tokensOf(paints[order] ?? { color: key }));
|
|
12250
12419
|
orders.set(group, order);
|
|
12251
12420
|
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
|
|
12252
12421
|
runsLayer.insertBefore(group, above ?? null);
|
|
@@ -12286,7 +12455,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12286
12455
|
]].forEach(([end, opacity, color]) => {
|
|
12287
12456
|
if (!end) return;
|
|
12288
12457
|
const element = endDot();
|
|
12289
|
-
setStyles(element,
|
|
12458
|
+
setStyles(element, tokensOf(color));
|
|
12290
12459
|
placeDot(element, end);
|
|
12291
12460
|
dots.push({
|
|
12292
12461
|
element,
|
|
@@ -12355,14 +12524,16 @@ function chartSwitch$1(target, options, env) {
|
|
|
12355
12524
|
}) : void 0;
|
|
12356
12525
|
observer?.observe(wrapper);
|
|
12357
12526
|
const view = (name) => views.get(name);
|
|
12527
|
+
const missing = (name, what = "") => /* @__PURE__ */ new TypeError(`chartSwitch: there's no view ${JSON.stringify(name)}${what}. The views are ${names.map((n) => JSON.stringify(n)).join(", ")}.`);
|
|
12358
12528
|
function focused() {
|
|
12359
12529
|
return wrapper.getRootNode().activeElement ?? null;
|
|
12360
12530
|
}
|
|
12361
12531
|
function readFocus(from) {
|
|
12362
12532
|
const element = focused();
|
|
12363
12533
|
const inside = element !== null && from.container.contains(element);
|
|
12364
|
-
const
|
|
12365
|
-
const
|
|
12534
|
+
const stop = inside ? element : from.chart.element.querySelector("[tabindex=\"0\"]");
|
|
12535
|
+
const keyed = stop?.closest("[data-key]");
|
|
12536
|
+
const key = (stop && from.chart.keyOf?.(stop)) ?? (keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null);
|
|
12366
12537
|
if (!inside && key === null) return void 0;
|
|
12367
12538
|
return {
|
|
12368
12539
|
keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key],
|
|
@@ -12389,7 +12560,10 @@ function chartSwitch$1(target, options, env) {
|
|
|
12389
12560
|
function reached() {
|
|
12390
12561
|
if (held) linked?.shown();
|
|
12391
12562
|
}
|
|
12392
|
-
function
|
|
12563
|
+
function jump(from, to, via, carried) {
|
|
12564
|
+
return via === void 0 || !motion.staged || via === from.name || via === to.name ? start(from, to, carried) : start(from, view(via), carried, to);
|
|
12565
|
+
}
|
|
12566
|
+
function start(from, to, carried, next) {
|
|
12393
12567
|
const memory = carried ? carried.focus : readFocus(from);
|
|
12394
12568
|
const waiting = [];
|
|
12395
12569
|
opening = waiting;
|
|
@@ -12398,16 +12572,17 @@ function chartSwitch$1(target, options, env) {
|
|
|
12398
12572
|
} finally {
|
|
12399
12573
|
opening = void 0;
|
|
12400
12574
|
}
|
|
12401
|
-
const done = destroyed ? Promise.resolve() : begin(from, to, memory);
|
|
12575
|
+
const done = destroyed ? Promise.resolve() : begin(from, to, memory, next);
|
|
12402
12576
|
for (const run of waiting) run();
|
|
12403
12577
|
return done;
|
|
12404
12578
|
}
|
|
12405
|
-
function begin(from, to, memory) {
|
|
12406
|
-
current = to.name;
|
|
12579
|
+
function begin(from, to, memory, next, carried) {
|
|
12580
|
+
current = (next ?? to).name;
|
|
12407
12581
|
if (motion.mode === "off") {
|
|
12408
|
-
|
|
12409
|
-
|
|
12410
|
-
|
|
12582
|
+
const end = view(current);
|
|
12583
|
+
for (const each of views.values()) setActive(each.container, each === end);
|
|
12584
|
+
restoreFocus(end, memory);
|
|
12585
|
+
say(end);
|
|
12411
12586
|
reached();
|
|
12412
12587
|
return Promise.resolve();
|
|
12413
12588
|
}
|
|
@@ -12415,10 +12590,11 @@ function chartSwitch$1(target, options, env) {
|
|
|
12415
12590
|
each.container.classList.remove("ec-switch-inactive");
|
|
12416
12591
|
each.container.classList.add("ec-switching");
|
|
12417
12592
|
each.container.setAttribute("inert", "");
|
|
12593
|
+
each.chart.morphing?.(true);
|
|
12418
12594
|
each.chart.element.classList.add("ec-morphing");
|
|
12419
12595
|
}
|
|
12420
12596
|
const { pairs, surface, scene } = prepare(from, to);
|
|
12421
|
-
const { done, settle } = deferred();
|
|
12597
|
+
const { done, settle } = carried ?? deferred();
|
|
12422
12598
|
const session = {
|
|
12423
12599
|
a: from,
|
|
12424
12600
|
b: to,
|
|
@@ -12431,6 +12607,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12431
12607
|
surface,
|
|
12432
12608
|
scene,
|
|
12433
12609
|
focus: memory,
|
|
12610
|
+
next,
|
|
12434
12611
|
progress: 0,
|
|
12435
12612
|
transition: void 0,
|
|
12436
12613
|
driver: void 0,
|
|
@@ -12445,7 +12622,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12445
12622
|
function play(session, begin) {
|
|
12446
12623
|
const run = ++session.run;
|
|
12447
12624
|
if (begin >= 1) {
|
|
12448
|
-
|
|
12625
|
+
arrive(session);
|
|
12449
12626
|
return;
|
|
12450
12627
|
}
|
|
12451
12628
|
const at = (progress) => {
|
|
@@ -12467,7 +12644,19 @@ function chartSwitch$1(target, options, env) {
|
|
|
12467
12644
|
});
|
|
12468
12645
|
started.release();
|
|
12469
12646
|
Promise.all([session.driver.finished, session.transition.finished]).then(([result]) => {
|
|
12470
|
-
if (active === session && session.run === run && result === "done")
|
|
12647
|
+
if (active === session && session.run === run && result === "done") arrive(session);
|
|
12648
|
+
});
|
|
12649
|
+
}
|
|
12650
|
+
function arrive(session) {
|
|
12651
|
+
const next = session.forward ? session.next : void 0;
|
|
12652
|
+
if (!next || motion.mode === "off") return land(session, true);
|
|
12653
|
+
const { done, settle } = session;
|
|
12654
|
+
session.next = void 0;
|
|
12655
|
+
session.settle = () => {};
|
|
12656
|
+
land(session, false);
|
|
12657
|
+
begin(session.b, next, session.focus, void 0, {
|
|
12658
|
+
done,
|
|
12659
|
+
settle
|
|
12471
12660
|
});
|
|
12472
12661
|
}
|
|
12473
12662
|
function reverse(session) {
|
|
@@ -12487,9 +12676,10 @@ function chartSwitch$1(target, options, env) {
|
|
|
12487
12676
|
session.driver?.cancel();
|
|
12488
12677
|
session.transition?.clear();
|
|
12489
12678
|
session.scene.clear();
|
|
12490
|
-
const to = session.forward ? session.b : session.a;
|
|
12679
|
+
const to = session.forward ? session.next ?? session.b : session.a;
|
|
12491
12680
|
for (const each of [session.a, session.b]) {
|
|
12492
12681
|
each.chart.element.classList.remove("ec-morphing");
|
|
12682
|
+
each.chart.morphing?.(false);
|
|
12493
12683
|
each.container.classList.remove("ec-switching");
|
|
12494
12684
|
each.container.style.removeProperty("opacity");
|
|
12495
12685
|
}
|
|
@@ -12502,8 +12692,8 @@ function chartSwitch$1(target, options, env) {
|
|
|
12502
12692
|
session.settle();
|
|
12503
12693
|
}
|
|
12504
12694
|
function prepare(a, b) {
|
|
12505
|
-
const toA = between$1(overlay, a.chart.element, wrapper);
|
|
12506
|
-
const toB = between$1(overlay, b.chart.element, wrapper);
|
|
12695
|
+
const toA = between$1(overlay, a.chart.space ?? a.chart.element, wrapper);
|
|
12696
|
+
const toB = between$1(overlay, b.chart.space ?? b.chart.element, wrapper);
|
|
12507
12697
|
const scaleA = scaleOf(toA);
|
|
12508
12698
|
const scaleB = scaleOf(toB);
|
|
12509
12699
|
const from = a.chart.marks().map((mark) => mapMark(mark, toA));
|
|
@@ -12523,8 +12713,8 @@ function chartSwitch$1(target, options, env) {
|
|
|
12523
12713
|
from: was.drawn ? partner : dot$1(partner),
|
|
12524
12714
|
to: will.drawn ? mark : dot$1(mark)
|
|
12525
12715
|
});
|
|
12526
|
-
paints.push(will
|
|
12527
|
-
extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was
|
|
12716
|
+
paints.push(will);
|
|
12717
|
+
extras.push(extrasFor([ringOf(was, scaleA), ringOf(will, scaleB)], [endOf(was, partner, scaleA), endOf(will, mark, scaleB)], [was, will]));
|
|
12528
12718
|
}
|
|
12529
12719
|
const drawings = [];
|
|
12530
12720
|
if (extras.some((each) => each !== void 0)) drawings.push((s) => {
|
|
@@ -12539,16 +12729,18 @@ function chartSwitch$1(target, options, env) {
|
|
|
12539
12729
|
const id = (label) => `${label.role}\n${label.key}`;
|
|
12540
12730
|
const labelsA = a.chart.labels();
|
|
12541
12731
|
const labelsB = b.chart.labels();
|
|
12732
|
+
const sizeA = a.chart.space ? scaleA : 1;
|
|
12733
|
+
const sizeB = b.chart.space ? scaleB : 1;
|
|
12542
12734
|
const byId = new Map(labelsA.map((label) => [id(label), label]));
|
|
12543
12735
|
const matched = /* @__PURE__ */ new Set();
|
|
12544
12736
|
for (const label of labelsB) {
|
|
12545
12737
|
const partner = byId.get(id(label));
|
|
12546
12738
|
if (!partner) continue;
|
|
12547
12739
|
matched.add(id(label));
|
|
12548
|
-
drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(label, toB)));
|
|
12740
|
+
drawings.push(moveLabel(copyLabel(partner, toA, sizeA), copyLabel(label, toB, sizeB)));
|
|
12549
12741
|
}
|
|
12550
|
-
for (const label of labelsA) if (!matched.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toA), fadeOut));
|
|
12551
|
-
for (const label of labelsB) if (!byId.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toB), fadeIn));
|
|
12742
|
+
for (const label of labelsA) if (!matched.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toA, sizeA), fadeOut));
|
|
12743
|
+
for (const label of labelsB) if (!byId.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toB, sizeB), fadeIn));
|
|
12552
12744
|
drawings.push((s) => {
|
|
12553
12745
|
setOpacity(a.container, 1 - clamp$1(s / OUT_BY));
|
|
12554
12746
|
setOpacity(b.container, clamp$1((s - HALF) / .5));
|
|
@@ -12573,7 +12765,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12573
12765
|
class: "ec-switch-fade",
|
|
12574
12766
|
"data-key": mark.key
|
|
12575
12767
|
}, fadesLayer);
|
|
12576
|
-
setStyles(group,
|
|
12768
|
+
setStyles(group, tokensOf(paint));
|
|
12577
12769
|
const ring = ringOf(paint, scale);
|
|
12578
12770
|
svgLayer(group).path(mark.outline.d, mark.outline.closed ? {
|
|
12579
12771
|
fill: "mark",
|
|
@@ -12598,7 +12790,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12598
12790
|
});
|
|
12599
12791
|
return element;
|
|
12600
12792
|
}
|
|
12601
|
-
function copyLabel(label, m) {
|
|
12793
|
+
function copyLabel(label, m, scale) {
|
|
12602
12794
|
const text = label.element.cloneNode(true);
|
|
12603
12795
|
for (const name of [
|
|
12604
12796
|
"id",
|
|
@@ -12607,39 +12799,53 @@ function chartSwitch$1(target, options, env) {
|
|
|
12607
12799
|
"aria-hidden"
|
|
12608
12800
|
]) text.removeAttribute(name);
|
|
12609
12801
|
text.textContent = label.text;
|
|
12610
|
-
const
|
|
12802
|
+
const copy = {
|
|
12803
|
+
text,
|
|
12804
|
+
at: matrix.apply(m, label),
|
|
12805
|
+
scale
|
|
12806
|
+
};
|
|
12611
12807
|
setAttributes(text, {
|
|
12612
|
-
x: at.x,
|
|
12613
|
-
y: at.y,
|
|
12614
|
-
"text-anchor": label.anchor
|
|
12808
|
+
x: copy.at.x,
|
|
12809
|
+
y: copy.at.y,
|
|
12810
|
+
"text-anchor": label.anchor,
|
|
12811
|
+
...scaledAt(copy, copy.at.x, copy.at.y)
|
|
12615
12812
|
});
|
|
12616
12813
|
labelsLayer.appendChild(text);
|
|
12617
|
-
return
|
|
12618
|
-
text,
|
|
12619
|
-
at
|
|
12620
|
-
};
|
|
12814
|
+
return copy;
|
|
12621
12815
|
}
|
|
12622
12816
|
const api = {
|
|
12623
12817
|
get current() {
|
|
12624
12818
|
return current;
|
|
12625
12819
|
},
|
|
12626
|
-
show(name) {
|
|
12627
|
-
if (!views.has(name)) return Promise.reject(
|
|
12820
|
+
show(name, options) {
|
|
12821
|
+
if (!views.has(name)) return Promise.reject(missing(name));
|
|
12822
|
+
const via = options?.via;
|
|
12823
|
+
if (via !== void 0 && !views.has(via)) return Promise.reject(missing(via, " to go via"));
|
|
12628
12824
|
if (destroyed) return Promise.resolve();
|
|
12629
12825
|
const waiting = opening;
|
|
12630
|
-
if (waiting) return new Promise((resolve) => waiting.push(() => resolve(api.show(name))));
|
|
12826
|
+
if (waiting) return new Promise((resolve) => waiting.push(() => resolve(api.show(name, options))));
|
|
12631
12827
|
const session = active;
|
|
12632
|
-
if (!session) return name === current ? Promise.resolve() :
|
|
12828
|
+
if (!session) return name === current ? Promise.resolve() : jump(view(current), view(name), via);
|
|
12633
12829
|
const heading = session.forward ? session.b : session.a;
|
|
12634
12830
|
const leaving = session.forward ? session.a : session.b;
|
|
12635
|
-
|
|
12831
|
+
const next = session.next;
|
|
12832
|
+
if (name === (next ?? heading).name) return session.done;
|
|
12833
|
+
if (next) {
|
|
12834
|
+
session.next = void 0;
|
|
12835
|
+
if (name === heading.name) {
|
|
12836
|
+
current = name;
|
|
12837
|
+
session.settle();
|
|
12838
|
+
({done: session.done, settle: session.settle} = deferred());
|
|
12839
|
+
return session.done;
|
|
12840
|
+
}
|
|
12841
|
+
}
|
|
12636
12842
|
if (name === leaving.name) return reverse(session);
|
|
12637
12843
|
land(session, false);
|
|
12638
|
-
return
|
|
12844
|
+
return jump(heading, view(name), via, { focus: session.focus });
|
|
12639
12845
|
},
|
|
12640
12846
|
chart(name) {
|
|
12641
12847
|
const found = views.get(name);
|
|
12642
|
-
if (!found) throw
|
|
12848
|
+
if (!found) throw missing(name);
|
|
12643
12849
|
return found.chart;
|
|
12644
12850
|
},
|
|
12645
12851
|
on(type, listener) {
|
|
@@ -12669,6 +12875,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12669
12875
|
session.driver?.cancel();
|
|
12670
12876
|
session.transition?.clear();
|
|
12671
12877
|
session.scene.clear();
|
|
12878
|
+
for (const each of [session.a, session.b]) each.chart.morphing?.(false);
|
|
12672
12879
|
session.settle();
|
|
12673
12880
|
}
|
|
12674
12881
|
stopMotion();
|
|
@@ -12768,15 +12975,25 @@ function moveLabel(a, b) {
|
|
|
12768
12975
|
setAttributes(a.text, {
|
|
12769
12976
|
x,
|
|
12770
12977
|
y,
|
|
12771
|
-
visibility: second ? "hidden" : void 0
|
|
12978
|
+
visibility: second ? "hidden" : void 0,
|
|
12979
|
+
...scaledAt(a, x, y)
|
|
12772
12980
|
});
|
|
12773
12981
|
setAttributes(b.text, {
|
|
12774
12982
|
x,
|
|
12775
12983
|
y,
|
|
12776
|
-
visibility: second ? void 0 : "hidden"
|
|
12984
|
+
visibility: second ? void 0 : "hidden",
|
|
12985
|
+
...scaledAt(b, x, y)
|
|
12777
12986
|
});
|
|
12778
12987
|
};
|
|
12779
12988
|
}
|
|
12989
|
+
const scaledAt = (copy, x, y) => copy.scale === 1 ? {} : { transform: transformAttribute([
|
|
12990
|
+
copy.scale,
|
|
12991
|
+
0,
|
|
12992
|
+
0,
|
|
12993
|
+
copy.scale,
|
|
12994
|
+
x * (1 - copy.scale),
|
|
12995
|
+
y * (1 - copy.scale)
|
|
12996
|
+
]) };
|
|
12780
12997
|
function fadeLabel(label, opacity) {
|
|
12781
12998
|
return (s) => setAttributes(label.text, { opacity: opacity(s) });
|
|
12782
12999
|
}
|
|
@@ -14054,10 +14271,11 @@ function drawing(from, to, layer, points, align) {
|
|
|
14054
14271
|
if (closed !== to.outline.closed) return crossfade(from, to, layer);
|
|
14055
14272
|
const across = closed ? void 0 : acrossX(from, to, points);
|
|
14056
14273
|
if (across) return piecewise(from, to, layer, across.stops, across.kinds);
|
|
14057
|
-
const
|
|
14058
|
-
const
|
|
14274
|
+
const bands = closed ? bandsAcross(from, to, points) : void 0;
|
|
14275
|
+
const a = bands?.from ?? from.outline.sample(points);
|
|
14276
|
+
const b = bands?.to ?? to.outline.sample(points);
|
|
14059
14277
|
if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
|
|
14060
|
-
const [shiftA, shiftB] = align === "drop" ? turn(from, to, points) : [0, 0];
|
|
14278
|
+
const [shiftA, shiftB] = !bands && align === "drop" ? turn(from, to, points) : [0, 0];
|
|
14061
14279
|
const holes = holePairs(from, to, a, b, [shiftA, shiftB], points / 4);
|
|
14062
14280
|
let path;
|
|
14063
14281
|
return (p) => {
|
|
@@ -14147,6 +14365,9 @@ function acrossX(from, to, points) {
|
|
|
14147
14365
|
const a = courseOf(from);
|
|
14148
14366
|
const b = a && courseOf(to);
|
|
14149
14367
|
if (!a || !b || a.way !== b.way) return void 0;
|
|
14368
|
+
return byX(a, b, points);
|
|
14369
|
+
}
|
|
14370
|
+
function byX(a, b, points) {
|
|
14150
14371
|
const all = [
|
|
14151
14372
|
...Array.from({ length: points }, (_, i) => [i / (points - 1), 0]),
|
|
14152
14373
|
...corners(a).map((s) => [s, 1]),
|
|
@@ -14202,7 +14423,9 @@ function courseOf(mark) {
|
|
|
14202
14423
|
before.push(points.length - 1);
|
|
14203
14424
|
from = end;
|
|
14204
14425
|
}
|
|
14205
|
-
|
|
14426
|
+
return !stretch(1) || next < subpaths.length || points.length < 2 ? void 0 : courseThrough(points, before);
|
|
14427
|
+
}
|
|
14428
|
+
function courseThrough(points, before = []) {
|
|
14206
14429
|
const x0 = points[0].x;
|
|
14207
14430
|
const span = points[points.length - 1].x - x0;
|
|
14208
14431
|
const way = Math.sign(span);
|
|
@@ -14243,6 +14466,48 @@ function placed(course, shares) {
|
|
|
14243
14466
|
return mixed(points[i], points[i + 1], width > 0 ? Math.min(1, Math.max(0, (s - at[i]) / width)) : 0);
|
|
14244
14467
|
});
|
|
14245
14468
|
}
|
|
14469
|
+
function bandsAcross(from, to, points) {
|
|
14470
|
+
const a = bandOf(from.outline);
|
|
14471
|
+
const b = a && bandOf(to.outline);
|
|
14472
|
+
if (!a || !b || Math.abs(a.left - b.left) > SAME_X || Math.abs(a.right - b.right) > SAME_X) return void 0;
|
|
14473
|
+
const upper = byX(a.upper, b.upper, points);
|
|
14474
|
+
const lower = byX(a.lower, b.lower, points);
|
|
14475
|
+
if (!upper || !lower) return void 0;
|
|
14476
|
+
const stops = [...upper.stops, ...lower.stops];
|
|
14477
|
+
return {
|
|
14478
|
+
from: stops.map((stop) => stop.from),
|
|
14479
|
+
to: stops.map((stop) => stop.to)
|
|
14480
|
+
};
|
|
14481
|
+
}
|
|
14482
|
+
function bandOf(outline) {
|
|
14483
|
+
const loops = loopsOf(outline);
|
|
14484
|
+
const ring = [];
|
|
14485
|
+
for (const segment of loops[outsideOf(loops)] ?? []) {
|
|
14486
|
+
if (segment.kind !== "line") return void 0;
|
|
14487
|
+
ring.push(segment.to);
|
|
14488
|
+
}
|
|
14489
|
+
if (areaOf(ring) < 0) ring.reverse();
|
|
14490
|
+
const left = ring.reduce((x, point) => Math.min(x, point.x), Infinity);
|
|
14491
|
+
const right = ring.reduce((x, point) => Math.max(x, point.x), -Infinity);
|
|
14492
|
+
if (!(right - left > 2 * SAME_X)) return void 0;
|
|
14493
|
+
const atLeft = (point) => point.x - left <= SAME_X;
|
|
14494
|
+
const atRight = (point) => right - point.x <= SAME_X;
|
|
14495
|
+
const s = ring.findIndex((point, i) => atLeft(point) && !atLeft(ring[(i + 1) % ring.length]));
|
|
14496
|
+
const walk = [...ring.slice(s), ...ring.slice(0, s + 1)];
|
|
14497
|
+
const topRight = walk.findIndex(atRight);
|
|
14498
|
+
let baseRight = topRight;
|
|
14499
|
+
while (atRight(walk[baseRight + 1])) baseRight++;
|
|
14500
|
+
const baseLeft = walk.findIndex((point, i) => i > baseRight && atLeft(point));
|
|
14501
|
+
if (walk.slice(baseLeft).some((point) => !atLeft(point))) return void 0;
|
|
14502
|
+
const upper = courseThrough(walk.slice(0, topRight + 1));
|
|
14503
|
+
const lower = courseThrough(walk.slice(baseRight, baseLeft + 1));
|
|
14504
|
+
return upper && lower && upper.points.length > 2 && lower.points.length > 2 ? {
|
|
14505
|
+
upper,
|
|
14506
|
+
lower,
|
|
14507
|
+
left,
|
|
14508
|
+
right
|
|
14509
|
+
} : void 0;
|
|
14510
|
+
}
|
|
14246
14511
|
function inside(gaps) {
|
|
14247
14512
|
let k = 0;
|
|
14248
14513
|
return (s) => {
|
|
@@ -14368,13 +14633,9 @@ function placeIn(point, own, other) {
|
|
|
14368
14633
|
};
|
|
14369
14634
|
}
|
|
14370
14635
|
function holesOf(outline, count) {
|
|
14371
|
-
const loops =
|
|
14636
|
+
const loops = loopsOf(outline);
|
|
14372
14637
|
if (loops.length < 2) return [];
|
|
14373
|
-
const
|
|
14374
|
-
let longest = 0;
|
|
14375
|
-
lengths.forEach((length, i) => {
|
|
14376
|
-
if (length > lengths[longest] + Math.max(.01, lengths[longest] / 1e3)) longest = i;
|
|
14377
|
-
});
|
|
14638
|
+
const longest = outsideOf(loops);
|
|
14378
14639
|
return loops.filter((_, i) => i !== longest).map((loop) => {
|
|
14379
14640
|
const round = loopOutline([loop]).sample(4 * count);
|
|
14380
14641
|
const points = round.filter((_, i) => i % 4 === 0);
|
|
@@ -14390,6 +14651,15 @@ function holesOf(outline, count) {
|
|
|
14390
14651
|
};
|
|
14391
14652
|
}).sort((x, y) => y.area - x.area);
|
|
14392
14653
|
}
|
|
14654
|
+
const loopsOf = (outline) => flattenPath(parsePath(outline.d)).map((subpath) => subpath.segments).filter((segments) => segments.length > 0);
|
|
14655
|
+
function outsideOf(loops) {
|
|
14656
|
+
const lengths = loops.map((loop) => loop.reduce((sum, segment) => sum + segment.length, 0));
|
|
14657
|
+
let longest = 0;
|
|
14658
|
+
lengths.forEach((length, i) => {
|
|
14659
|
+
if (length > lengths[longest] + Math.max(.01, lengths[longest] / 1e3)) longest = i;
|
|
14660
|
+
});
|
|
14661
|
+
return longest;
|
|
14662
|
+
}
|
|
14393
14663
|
function areaOf(points) {
|
|
14394
14664
|
let sum = 0;
|
|
14395
14665
|
points.forEach((p, i) => {
|
|
@@ -15044,7 +15314,7 @@ function configure(options) {
|
|
|
15044
15314
|
}
|
|
15045
15315
|
}
|
|
15046
15316
|
// src/index.ts
|
|
15047
|
-
const VERSION = "0.
|
|
15317
|
+
const VERSION = "0.10.0";
|
|
15048
15318
|
const env = {
|
|
15049
15319
|
presets: presetRegistry,
|
|
15050
15320
|
icons: iconRegistry,
|
|
@@ -15097,6 +15367,7 @@ exports.expressive = expressive;
|
|
|
15097
15367
|
exports.flash = flash;
|
|
15098
15368
|
exports.fromVegaView = fromVegaView;
|
|
15099
15369
|
exports.gaits = gaits;
|
|
15370
|
+
exports.hostView = hostView;
|
|
15100
15371
|
exports.iconFromSvg = iconFromSvg;
|
|
15101
15372
|
exports.icons = icons;
|
|
15102
15373
|
exports.interpolateNumber = interpolateNumber;
|