expressive-charts 0.10.0 → 0.12.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 +19 -0
- package/README.md +8 -8
- package/dist/define-DeZLs1h7.js.map +1 -1
- package/dist/expressive-charts.global.js +6 -6
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.cjs.map +1 -1
- package/dist/icons/sport.js +1 -1
- package/dist/index.cjs +346 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +56 -9
- package/dist/index.d.ts +56 -9
- package/dist/index.js +341 -99
- package/dist/index.js.map +1 -1
- package/dist/{path-data-DnEckjY8.js → path-data-Cfjk04X8.js} +5 -5
- package/dist/{path-data-DnEckjY8.js.map → path-data-Cfjk04X8.js.map} +1 -1
- package/dist/testing.cjs +7 -7
- package/dist/testing.js +1 -1
- package/dist/{transition-romki_A6.js → transition-BFd3ktZY.js} +5 -5
- package/dist/{transition-romki_A6.js.map → transition-BFd3ktZY.js.map} +1 -1
- package/package.json +10 -5
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as TIMINGS, B as createClock, C as flattenPath, D as describeArc, E as describeBar, F as scaleDuration, H as manualClock, I as easeInOutCubic, L as easeOutCubic, M as defaultScaling, N as mediaReducedMotion, O as loopOutline, P as motion, R as linear, S as cubicPieces, T as describeLine, U as report, V as defaultClock, _ as formatPath, a as AVERAGE_WIDTH, b as transformPath, d as createRegistry, f as describeValue$1, g as describeShape, h as describe, j as createMotion, k as tween, l as mergeFields, m as resolveEffects, n as playTransition, o as TEXT_SIZE, p as isMarkEffect, r as createRunner, s as boxAround, t as isTransitionEffect, u as EFFECT_SLOTS, v as parsePath, w as describePoint, x as FLAT, y as shapeOutline, z as unease } from "./transition-
|
|
2
|
-
import { a as TAU$2, c as boundsOf, d as normalizeAngle, f as pointOn, l as extremes, n as formatNumber } from "./path-data-
|
|
1
|
+
import { A as TIMINGS, B as createClock, C as flattenPath, D as describeArc, E as describeBar, F as scaleDuration, H as manualClock, I as easeInOutCubic, L as easeOutCubic, M as defaultScaling, N as mediaReducedMotion, O as loopOutline, P as motion, R as linear, S as cubicPieces, T as describeLine, U as report, V as defaultClock, _ as formatPath, a as AVERAGE_WIDTH, b as transformPath, d as createRegistry, f as describeValue$1, g as describeShape, h as describe, j as createMotion, k as tween, l as mergeFields, m as resolveEffects, n as playTransition, o as TEXT_SIZE, p as isMarkEffect, r as createRunner, s as boxAround, t as isTransitionEffect, u as EFFECT_SLOTS, v as parsePath, w as describePoint, x as FLAT, y as shapeOutline, z as unease } from "./transition-BFd3ktZY.js";
|
|
2
|
+
import { a as TAU$2, c as boundsOf, d as normalizeAngle, f as pointOn, l as extremes, n as formatNumber } from "./path-data-Cfjk04X8.js";
|
|
3
3
|
import { t as defineIcon } from "./define-DeZLs1h7.js";
|
|
4
4
|
// src/core/animated.ts
|
|
5
5
|
const interpolateNumber = (a, b) => (t) => a * (1 - t) + b * t;
|
|
@@ -440,7 +440,7 @@ function nearest$1(mark, grid, p) {
|
|
|
440
440
|
const n = grid.length;
|
|
441
441
|
if (n === 1) return 0;
|
|
442
442
|
let best = 0;
|
|
443
|
-
let bestDistance =
|
|
443
|
+
let bestDistance = 1e400;
|
|
444
444
|
grid.forEach((q, i) => {
|
|
445
445
|
const d = squared(q, p);
|
|
446
446
|
if (d < bestDistance) {
|
|
@@ -1800,7 +1800,7 @@ function svgSurface(options) {
|
|
|
1800
1800
|
}, overlay);
|
|
1801
1801
|
setStyles(group, markColorStyles(options.colors(key)));
|
|
1802
1802
|
orders.set(group, order);
|
|
1803
|
-
const above = Array.from(overlay.children).find((child) => (orders.get(child) ?? -
|
|
1803
|
+
const above = Array.from(overlay.children).find((child) => (orders.get(child) ?? -1e400) > order);
|
|
1804
1804
|
overlay.insertBefore(group, above ?? null);
|
|
1805
1805
|
let live = groups.get(key);
|
|
1806
1806
|
if (!live) groups.set(key, live = /* @__PURE__ */ new Set());
|
|
@@ -5252,7 +5252,7 @@ function lineCurve(xs, values, amount, scales, presence) {
|
|
|
5252
5252
|
];
|
|
5253
5253
|
};
|
|
5254
5254
|
return {
|
|
5255
|
-
between(from, to, through =
|
|
5255
|
+
between(from, to, through = 1e400) {
|
|
5256
5256
|
const p = piece(from, to);
|
|
5257
5257
|
if (!p || !tangents) return [];
|
|
5258
5258
|
const [v0, c1, c2, v1, k] = p;
|
|
@@ -5523,7 +5523,7 @@ function boundaries(lo, hi, step, zone) {
|
|
|
5523
5523
|
return out;
|
|
5524
5524
|
}
|
|
5525
5525
|
const nth = unit === "day" ? (i) => midnight(zone, start.year, start.month, start.date + i) : unit === "week" ? (i) => midnight(zone, start.year, start.month, start.date - (start.weekday + 6) % 7 + 7 * i) : unit === "month" ? (i) => midnight(zone, start.year, Math.floor(start.month / count) * count + count * i, 1) : (i) => midnight(zone, Math.floor(start.year / count) * count + count * i, 0, 1);
|
|
5526
|
-
let previous = -
|
|
5526
|
+
let previous = -1e400;
|
|
5527
5527
|
for (let i = 0;; i++) {
|
|
5528
5528
|
const t = nth(i);
|
|
5529
5529
|
if (t >= hi || t <= previous) break;
|
|
@@ -6264,7 +6264,7 @@ function lineChart$1(target, options, env) {
|
|
|
6264
6264
|
const events = chartEvents("lineChart");
|
|
6265
6265
|
let measuredWidth = containerWidth(container);
|
|
6266
6266
|
let destroyed = false;
|
|
6267
|
-
let through =
|
|
6267
|
+
let through = 1e400;
|
|
6268
6268
|
const labelFailures = /* @__PURE__ */ new WeakSet();
|
|
6269
6269
|
let laidOut;
|
|
6270
6270
|
let firstTable;
|
|
@@ -6410,7 +6410,7 @@ function lineChart$1(target, options, env) {
|
|
|
6410
6410
|
}
|
|
6411
6411
|
function drawnThrough(next) {
|
|
6412
6412
|
const last = next.rows[next.rows.length - 1];
|
|
6413
|
-
return last && through < last.x ? revealedIn(next) :
|
|
6413
|
+
return last && through < last.x ? revealedIn(next) : 1e400;
|
|
6414
6414
|
}
|
|
6415
6415
|
const revealed = (record) => !record.leaving && record.row.x <= revealedIn(laidOut);
|
|
6416
6416
|
function createRow(row, entering) {
|
|
@@ -6889,8 +6889,8 @@ function lineChart$1(target, options, env) {
|
|
|
6889
6889
|
function nearestPoint(at) {
|
|
6890
6890
|
const shown = rowOrder.filter(revealed).flatMap(livePoints);
|
|
6891
6891
|
let best;
|
|
6892
|
-
let far =
|
|
6893
|
-
let rank =
|
|
6892
|
+
let far = 1e400;
|
|
6893
|
+
let rank = 1e400;
|
|
6894
6894
|
for (const point of shown) {
|
|
6895
6895
|
const d = apart(point.shown.geometry.center, at);
|
|
6896
6896
|
const r = laidOut.series.indexOf(point.series);
|
|
@@ -6910,7 +6910,7 @@ function lineChart$1(target, options, env) {
|
|
|
6910
6910
|
}
|
|
6911
6911
|
if (on.size < 2) return best;
|
|
6912
6912
|
let pick = best;
|
|
6913
|
-
let near =
|
|
6913
|
+
let near = 1e400;
|
|
6914
6914
|
for (const series of laidOut.series) {
|
|
6915
6915
|
const point = on.get(series);
|
|
6916
6916
|
if (!point) continue;
|
|
@@ -7643,7 +7643,7 @@ function strokeNear({ geometry, data: { samples } }, x, from, at, reach) {
|
|
|
7643
7643
|
if (!next || (way > 0 ? next : samples[j]).gapBefore) break;
|
|
7644
7644
|
const to = way > 0 ? Math.min(next.t, t + span) : Math.max(next.t, t - span);
|
|
7645
7645
|
const b = geometry.path(to);
|
|
7646
|
-
near = Math.min(near ??
|
|
7646
|
+
near = Math.min(near ?? 1e400, toSegment(at, a, b));
|
|
7647
7647
|
if (to !== next.t) break;
|
|
7648
7648
|
a = b;
|
|
7649
7649
|
}
|
|
@@ -7767,7 +7767,7 @@ function describeRects(key, parts, baseline) {
|
|
|
7767
7767
|
...span(part.box)
|
|
7768
7768
|
})).sort((a, b) => a.near - b.near || a.far - b.far || a.index - b.index);
|
|
7769
7769
|
let reached = 0;
|
|
7770
|
-
let gap =
|
|
7770
|
+
let gap = 1e400;
|
|
7771
7771
|
const segments = order.map(({ index, near, far }) => {
|
|
7772
7772
|
if (reached > 0 && far > near) gap = Math.min(gap, near - reached);
|
|
7773
7773
|
const size = Math.max(0, far - reached);
|
|
@@ -7986,6 +7986,40 @@ function between$1(outer, inner, root, screen = screenMatrix) {
|
|
|
7986
7986
|
if (a && b) return matrix.multiply(invert(a), b);
|
|
7987
7987
|
return matrix.multiply(invert(fromRoot(outer, root)), fromRoot(inner, root));
|
|
7988
7988
|
}
|
|
7989
|
+
function mapMark(mark, m) {
|
|
7990
|
+
if (isIdentity$1(m)) return mark;
|
|
7991
|
+
const point = (p) => matrix.apply(m, p);
|
|
7992
|
+
const path = (d) => formatPath(transformPath(parsePath(d), m));
|
|
7993
|
+
const scale = scaleOf$2(m);
|
|
7994
|
+
const { outline } = mark;
|
|
7995
|
+
return {
|
|
7996
|
+
key: mark.key,
|
|
7997
|
+
...mark.series === void 0 ? {} : { series: mark.series },
|
|
7998
|
+
start: point(mark.start),
|
|
7999
|
+
end: point(mark.end),
|
|
8000
|
+
length: mark.length * scale,
|
|
8001
|
+
path: (t) => point(mark.path(t)),
|
|
8002
|
+
angle: (t) => {
|
|
8003
|
+
const angle = mark.angle(t);
|
|
8004
|
+
const cos = Math.cos(angle);
|
|
8005
|
+
const sin = Math.sin(angle);
|
|
8006
|
+
return Math.atan2(m[1] * cos + m[3] * sin, m[0] * cos + m[2] * sin);
|
|
8007
|
+
},
|
|
8008
|
+
slice: (t0, t1) => path(mark.slice(t0, t1)),
|
|
8009
|
+
...mark.gaps === void 0 ? {} : { gaps: mark.gaps },
|
|
8010
|
+
thickness: mark.thickness * scale,
|
|
8011
|
+
outline: {
|
|
8012
|
+
d: path(outline.d),
|
|
8013
|
+
closed: outline.closed,
|
|
8014
|
+
sample: (n) => outline.sample(n).map(point)
|
|
8015
|
+
},
|
|
8016
|
+
bounds: boxIn(m, mark.bounds),
|
|
8017
|
+
center: point(mark.center),
|
|
8018
|
+
pivot: point(mark.pivot),
|
|
8019
|
+
...mark.segments === void 0 ? {} : { segments: mark.segments.map((segment) => mapMark(segment, m)) }
|
|
8020
|
+
};
|
|
8021
|
+
}
|
|
8022
|
+
const isIdentity$1 = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
7989
8023
|
function ownTransform(element) {
|
|
7990
8024
|
return parseTransform(element.getAttribute("transform") ?? "");
|
|
7991
8025
|
}
|
|
@@ -8129,7 +8163,7 @@ function hostMarkHandle(parts, edits, halos) {
|
|
|
8129
8163
|
};
|
|
8130
8164
|
}
|
|
8131
8165
|
function hostColors(element, root) {
|
|
8132
|
-
const fill = paintOf$1(element, root, "fill");
|
|
8166
|
+
const fill = element.localName === "line" ? NONE : paintOf$1(element, root, "fill");
|
|
8133
8167
|
const paint = fill === NONE ? "stroke" : "fill";
|
|
8134
8168
|
const color = paint === "fill" ? fill : paintOf$1(element, root, "stroke");
|
|
8135
8169
|
if (color === void 0 || color === NONE) return void 0;
|
|
@@ -9026,7 +9060,7 @@ function expressive$1(target, options, env) {
|
|
|
9026
9060
|
if (root.lastElementChild !== overlay) root.appendChild(overlay);
|
|
9027
9061
|
overlay.removeAttribute("transform");
|
|
9028
9062
|
const m = between$1(overlay, ancestor, root);
|
|
9029
|
-
if (!isIdentity
|
|
9063
|
+
if (!isIdentity(m)) overlay.setAttribute("transform", transformAttribute(m));
|
|
9030
9064
|
}
|
|
9031
9065
|
function moveTo(next) {
|
|
9032
9066
|
detach();
|
|
@@ -9577,7 +9611,7 @@ function tryInvert(m) {
|
|
|
9577
9611
|
return;
|
|
9578
9612
|
}
|
|
9579
9613
|
}
|
|
9580
|
-
function isIdentity
|
|
9614
|
+
function isIdentity(m) {
|
|
9581
9615
|
return Math.abs(m[0] - 1) < 1e-9 && Math.abs(m[1]) < 1e-9 && Math.abs(m[2]) < 1e-9 && Math.abs(m[3] - 1) < 1e-9 && Math.abs(m[4]) < 1e-6 && Math.abs(m[5]) < 1e-6;
|
|
9582
9616
|
}
|
|
9583
9617
|
function valuesChanged(from, to) {
|
|
@@ -9630,19 +9664,37 @@ function scaled(value, scale) {
|
|
|
9630
9664
|
if (scale === 1) return value;
|
|
9631
9665
|
return value.replace(/(-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(px)?(?![\w.%])/gi, (_, n, px) => `${Math.round(Number(n) * scale * 1e3) / 1e3}${px ?? ""}`);
|
|
9632
9666
|
}
|
|
9633
|
-
function hostView(
|
|
9634
|
-
const
|
|
9635
|
-
|
|
9636
|
-
|
|
9667
|
+
function hostView(attachments, options = {}) {
|
|
9668
|
+
const list = Array.isArray(attachments) ? attachments : [attachments];
|
|
9669
|
+
if (list.length === 0) throw new TypeError("hostView needs an attachment, or an array of attachments on one <svg>: hostView([dots, connectors]).");
|
|
9670
|
+
const parts = list.map((attachment, i) => {
|
|
9671
|
+
const port = typeof attachment === "object" && attachment !== null ? portOf(attachment) : void 0;
|
|
9672
|
+
const inside = insidesOf(port);
|
|
9673
|
+
if (!port || !inside?.root()) throw new TypeError(list === attachments ? `hostView needs attachments that expressive() or fromVegaView() returned, each with marks in an <svg>: attachments[${i}] isn't one.` : "hostView needs an attachment that expressive() or fromVegaView() returned, with marks in an <svg>.");
|
|
9674
|
+
if (list.indexOf(attachment) !== i) throw new TypeError(`hostView: attachments[${i}] is attachments[${list.indexOf(attachment)}] again. Each attachment is in a view once.`);
|
|
9675
|
+
return {
|
|
9676
|
+
attachment,
|
|
9677
|
+
port,
|
|
9678
|
+
inside,
|
|
9679
|
+
hidden: []
|
|
9680
|
+
};
|
|
9681
|
+
});
|
|
9637
9682
|
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\" })).");
|
|
9638
|
-
|
|
9639
|
-
const
|
|
9683
|
+
if (options.guides !== void 0 && typeof options.guides !== "function") throw new TypeError("hostView: guides must be a function that returns the host's guides, such as () => [{ element: svg.querySelector(\"g.axis\"), key: \"y\" }].");
|
|
9684
|
+
const lead = parts[0];
|
|
9685
|
+
const several = parts.length > 1;
|
|
9686
|
+
const { edits } = lead.inside;
|
|
9687
|
+
const svg = () => lead.inside.root();
|
|
9640
9688
|
let given;
|
|
9641
|
-
let
|
|
9689
|
+
let guided;
|
|
9642
9690
|
let classed;
|
|
9691
|
+
const clash = several ? clashOf(parts, svg()) : void 0;
|
|
9692
|
+
if (clash) throw new TypeError(`hostView: ${clash.problem}.`);
|
|
9693
|
+
const drawn = () => parts.filter((part) => part.inside.root() === svg());
|
|
9694
|
+
const ownerOf = (key) => drawn().find((part) => part.attachment.marks().some((mark) => mark.key === key));
|
|
9643
9695
|
function read() {
|
|
9644
9696
|
if (!options.labels) return [];
|
|
9645
|
-
const keys = new Set(attachment.marks().map((mark) => mark.key));
|
|
9697
|
+
const keys = new Set(drawn().flatMap((part) => part.attachment.marks().map((mark) => mark.key)));
|
|
9646
9698
|
try {
|
|
9647
9699
|
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"));
|
|
9648
9700
|
} catch (error) {
|
|
@@ -9650,6 +9702,16 @@ function hostView(attachment, options = {}) {
|
|
|
9650
9702
|
return [];
|
|
9651
9703
|
}
|
|
9652
9704
|
}
|
|
9705
|
+
function guides() {
|
|
9706
|
+
if (!options.guides) return [];
|
|
9707
|
+
const root = svg();
|
|
9708
|
+
try {
|
|
9709
|
+
return Array.from(options.guides()).filter((guide) => (guide?.element)?.nodeType === 1 && guide.element !== root && root.contains(guide.element) && typeof guide.key === "string");
|
|
9710
|
+
} catch (error) {
|
|
9711
|
+
report(error);
|
|
9712
|
+
return [];
|
|
9713
|
+
}
|
|
9714
|
+
}
|
|
9653
9715
|
function chartLabel({ element, key, role }) {
|
|
9654
9716
|
const root = svg();
|
|
9655
9717
|
const m = between$1(view.space, element, root);
|
|
@@ -9680,16 +9742,27 @@ function hostView(attachment, options = {}) {
|
|
|
9680
9742
|
};
|
|
9681
9743
|
}
|
|
9682
9744
|
const hide = (on) => {
|
|
9745
|
+
if (on && given === void 0 && several) {
|
|
9746
|
+
const found = clashOf(parts, svg());
|
|
9747
|
+
if (found) report(/* @__PURE__ */ new TypeError(`hostView: ${found.problem}. The switch plays on, and ${found.left}.`));
|
|
9748
|
+
}
|
|
9683
9749
|
const root = on ? svg() : void 0;
|
|
9684
9750
|
given = on ? read() : void 0;
|
|
9685
|
-
|
|
9751
|
+
guided = on ? guides() : void 0;
|
|
9752
|
+
const named = [...(given ?? []).map((label) => label.element), ...(guided ?? []).map((guide) => guide.element)];
|
|
9753
|
+
const now = parts.map(({ inside, hidden }, i) => new Set(given ? [
|
|
9686
9754
|
...inside.elements(),
|
|
9687
|
-
...
|
|
9755
|
+
...i === 0 ? named : [],
|
|
9688
9756
|
...hidden.filter((element) => root?.contains(element))
|
|
9689
|
-
] : []);
|
|
9690
|
-
for (const element of
|
|
9691
|
-
|
|
9692
|
-
|
|
9757
|
+
] : []));
|
|
9758
|
+
for (let i = 1; i < now.length; i++) for (const element of now[i]) if (now.some((earlier, j) => j < i && earlier.has(element))) now[i].delete(element);
|
|
9759
|
+
parts.forEach((part, i) => {
|
|
9760
|
+
for (const element of part.hidden) if (!now[i].has(element)) part.inside.edits.style(element, "visibility", void 0);
|
|
9761
|
+
});
|
|
9762
|
+
parts.forEach((part, i) => {
|
|
9763
|
+
part.hidden = [...now[i]];
|
|
9764
|
+
for (const element of part.hidden) part.inside.edits.style(element, "visibility", "hidden");
|
|
9765
|
+
});
|
|
9693
9766
|
if (classed !== root) {
|
|
9694
9767
|
if (classed) edits.toggleClass(classed, "ec-morphing", false);
|
|
9695
9768
|
if (root) edits.toggleClass(root, "ec-morphing", true);
|
|
@@ -9701,36 +9774,82 @@ function hostView(attachment, options = {}) {
|
|
|
9701
9774
|
return svg();
|
|
9702
9775
|
},
|
|
9703
9776
|
get space() {
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9777
|
+
const root = svg();
|
|
9778
|
+
const [space, ...others] = drawn().map((part) => part.inside.ancestor() ?? root);
|
|
9779
|
+
let common = space;
|
|
9780
|
+
for (const other of others) while (common !== root && !common.contains(other)) common = common.parentElement ?? root;
|
|
9781
|
+
return common;
|
|
9782
|
+
},
|
|
9783
|
+
refresh(source) {
|
|
9784
|
+
if (several && source !== void 0) throw new TypeError("hostView: a view of several attachments refreshes each from what it last read, with refresh(). To read new sources, refresh each attachment with its own.");
|
|
9785
|
+
for (const { attachment } of parts) attachment.refresh(source);
|
|
9786
|
+
},
|
|
9787
|
+
update: (next) => several ? Promise.all(parts.map(({ attachment }) => attachment.update(next))).then(() => {}) : lead.attachment.update(next),
|
|
9788
|
+
on(type, listener) {
|
|
9789
|
+
const stops = parts.map(({ attachment }) => attachment.on(type, listener));
|
|
9790
|
+
return several ? () => stops.forEach((stop) => stop()) : stops[0];
|
|
9791
|
+
},
|
|
9792
|
+
marks() {
|
|
9793
|
+
const root = svg();
|
|
9794
|
+
const space = view.space;
|
|
9795
|
+
const keys = /* @__PURE__ */ new Set();
|
|
9796
|
+
return drawn().flatMap(({ attachment, inside }) => {
|
|
9797
|
+
const ancestor = inside.ancestor() ?? root;
|
|
9798
|
+
const m = ancestor === space ? void 0 : between$1(space, ancestor, root);
|
|
9799
|
+
return attachment.marks().flatMap((mark) => keys.has(mark.key) ? [] : (keys.add(mark.key), [m ? mapMark(mark, m) : mark]));
|
|
9800
|
+
});
|
|
9801
|
+
},
|
|
9802
|
+
focus: (key) => ownerOf(key)?.attachment.focus(key),
|
|
9803
|
+
leave() {
|
|
9804
|
+
for (const { attachment } of parts) attachment.leave();
|
|
9805
|
+
},
|
|
9712
9806
|
destroy() {
|
|
9713
|
-
given = classed = void 0;
|
|
9714
|
-
hidden = [];
|
|
9715
|
-
attachment.destroy();
|
|
9807
|
+
given = guided = classed = void 0;
|
|
9808
|
+
for (const part of parts) part.hidden = [];
|
|
9809
|
+
for (const { attachment } of [...parts].reverse()) attachment.destroy();
|
|
9716
9810
|
},
|
|
9717
9811
|
labels: () => (given ?? read()).map(chartLabel),
|
|
9812
|
+
guides: () => guided ?? guides(),
|
|
9718
9813
|
paintOf(key) {
|
|
9719
|
-
const
|
|
9720
|
-
|
|
9721
|
-
color
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9814
|
+
for (const { inside } of drawn()) {
|
|
9815
|
+
const color = inside.colorOf(key);
|
|
9816
|
+
if (color !== void 0) return {
|
|
9817
|
+
color: key,
|
|
9818
|
+
drawn: true,
|
|
9819
|
+
cssColor: color
|
|
9820
|
+
};
|
|
9821
|
+
}
|
|
9822
|
+
},
|
|
9823
|
+
keyOf(element) {
|
|
9824
|
+
for (const { inside } of parts) {
|
|
9825
|
+
const key = inside.keyOf(element);
|
|
9826
|
+
if (key !== void 0) return key;
|
|
9827
|
+
}
|
|
9725
9828
|
},
|
|
9726
|
-
|
|
9727
|
-
moveTabStop: (key) => inside.moveTabStop(key),
|
|
9829
|
+
moveTabStop: (key) => drawn().some(({ inside }) => inside.moveTabStop(key)),
|
|
9728
9830
|
morphing: hide
|
|
9729
9831
|
};
|
|
9730
|
-
inside.refreshed.add(() => {
|
|
9832
|
+
for (const { inside } of parts) inside.refreshed.add(() => {
|
|
9731
9833
|
if (given) hide(true);
|
|
9732
9834
|
});
|
|
9733
|
-
return linkable(port, view);
|
|
9835
|
+
return several ? view : linkable(lead.port, view);
|
|
9836
|
+
}
|
|
9837
|
+
function clashOf(parts, root) {
|
|
9838
|
+
const owners = /* @__PURE__ */ new Map();
|
|
9839
|
+
for (const [i, { attachment, inside }] of parts.entries()) {
|
|
9840
|
+
if (inside.root() !== root) return {
|
|
9841
|
+
problem: `attachments[${i}]'s marks are in another <svg> than attachments[0]'s, and a view's attachments share one`,
|
|
9842
|
+
left: `attachments[${i}]'s marks are left out`
|
|
9843
|
+
};
|
|
9844
|
+
for (const { key } of attachment.marks()) {
|
|
9845
|
+
const owner = owners.get(key);
|
|
9846
|
+
if (owner !== void 0 && owner !== i) return {
|
|
9847
|
+
problem: `attachments[${owner}] and attachments[${i}] both have a mark with the key ${JSON.stringify(key)}, and each key must be one mark's. Key each one's marks apart, such as (d) => \`first@\${d.name}\``,
|
|
9848
|
+
left: `the key stays attachments[${owner}]'s: attachments[${i}]'s mark is left out`
|
|
9849
|
+
};
|
|
9850
|
+
owners.set(key, i);
|
|
9851
|
+
}
|
|
9852
|
+
}
|
|
9734
9853
|
}
|
|
9735
9854
|
// src/charts/adapter/vega.ts
|
|
9736
9855
|
const MARK_TYPES = [
|
|
@@ -10178,7 +10297,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
10178
10297
|
}, runsLayer);
|
|
10179
10298
|
setStyles(group, tokensOf(paints[order] ?? { color: key }));
|
|
10180
10299
|
orders.set(group, order);
|
|
10181
|
-
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -
|
|
10300
|
+
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -1e400) > order);
|
|
10182
10301
|
runsLayer.insertBefore(group, above ?? null);
|
|
10183
10302
|
const layer = svgLayer(group);
|
|
10184
10303
|
return {
|
|
@@ -10347,14 +10466,16 @@ function chartSwitch$1(target, options, env) {
|
|
|
10347
10466
|
reached();
|
|
10348
10467
|
return Promise.resolve();
|
|
10349
10468
|
}
|
|
10469
|
+
const guides = [];
|
|
10350
10470
|
for (const each of [from, to]) {
|
|
10351
10471
|
each.container.classList.remove("ec-switch-inactive");
|
|
10472
|
+
guides.push(guidesOf(each));
|
|
10352
10473
|
each.container.classList.add("ec-switching");
|
|
10353
10474
|
each.container.setAttribute("inert", "");
|
|
10354
10475
|
each.chart.morphing?.(true);
|
|
10355
10476
|
each.chart.element.classList.add("ec-morphing");
|
|
10356
10477
|
}
|
|
10357
|
-
const { pairs, surface, scene } = prepare(from, to);
|
|
10478
|
+
const { pairs, surface, scene } = prepare(from, to, guides);
|
|
10358
10479
|
const { done, settle } = carried ?? deferred();
|
|
10359
10480
|
const session = {
|
|
10360
10481
|
a: from,
|
|
@@ -10452,7 +10573,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
10452
10573
|
}
|
|
10453
10574
|
session.settle();
|
|
10454
10575
|
}
|
|
10455
|
-
function prepare(a, b) {
|
|
10576
|
+
function prepare(a, b, guides) {
|
|
10456
10577
|
const toA = between$1(overlay, a.chart.space ?? a.chart.element, wrapper);
|
|
10457
10578
|
const toB = between$1(overlay, b.chart.space ?? b.chart.element, wrapper);
|
|
10458
10579
|
const scaleA = scaleOf(toA);
|
|
@@ -10502,9 +10623,39 @@ function chartSwitch$1(target, options, env) {
|
|
|
10502
10623
|
}
|
|
10503
10624
|
for (const label of labelsA) if (!matched.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toA, sizeA), fadeOut));
|
|
10504
10625
|
for (const label of labelsB) if (!byId.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toB, sizeB), fadeIn));
|
|
10626
|
+
const [guidesA = [], guidesB = []] = guides;
|
|
10627
|
+
const partners = /* @__PURE__ */ new Map();
|
|
10628
|
+
for (const guide of guidesA) if (!partners.has(guide.key)) partners.set(guide.key, guide);
|
|
10629
|
+
const kept = /* @__PURE__ */ new Set();
|
|
10630
|
+
for (const guide of guidesB) {
|
|
10631
|
+
const partner = partners.get(guide.key);
|
|
10632
|
+
partners.delete(guide.key);
|
|
10633
|
+
if (partner && sameGuide(partner, guide)) kept.add(partner).add(guide);
|
|
10634
|
+
}
|
|
10635
|
+
let guidesLayer;
|
|
10636
|
+
if (guidesA.length + guidesB.length > 0) {
|
|
10637
|
+
const layer = guidesLayer = doc.createElementNS(SVG_NS$2, "g");
|
|
10638
|
+
layer.setAttribute("class", "ec-switch-guides");
|
|
10639
|
+
overlay.insertBefore(layer, fadesLayer);
|
|
10640
|
+
[[
|
|
10641
|
+
guidesA,
|
|
10642
|
+
(s) => s < HALF ? 1 : 0,
|
|
10643
|
+
othersOut
|
|
10644
|
+
], [
|
|
10645
|
+
guidesB,
|
|
10646
|
+
(s) => s < HALF ? 0 : 1,
|
|
10647
|
+
othersIn
|
|
10648
|
+
]].forEach(([list, steady, fading]) => {
|
|
10649
|
+
for (const guide of list) {
|
|
10650
|
+
layer.appendChild(guide.group);
|
|
10651
|
+
const opacity = kept.has(guide) ? steady : fading;
|
|
10652
|
+
drawings.push((s) => guide.group.setAttribute("opacity", opacityText(opacity(s))));
|
|
10653
|
+
}
|
|
10654
|
+
});
|
|
10655
|
+
}
|
|
10505
10656
|
drawings.push((s) => {
|
|
10506
|
-
setOpacity(a.container,
|
|
10507
|
-
setOpacity(b.container,
|
|
10657
|
+
setOpacity(a.container, othersOut(s));
|
|
10658
|
+
setOpacity(b.container, othersIn(s));
|
|
10508
10659
|
});
|
|
10509
10660
|
return {
|
|
10510
10661
|
pairs,
|
|
@@ -10514,6 +10665,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
10514
10665
|
for (const draw of drawings) draw(s);
|
|
10515
10666
|
},
|
|
10516
10667
|
clear: () => {
|
|
10668
|
+
guidesLayer?.remove();
|
|
10517
10669
|
fadesLayer.replaceChildren();
|
|
10518
10670
|
runsLayer.replaceChildren();
|
|
10519
10671
|
labelsLayer.replaceChildren();
|
|
@@ -10521,6 +10673,31 @@ function chartSwitch$1(target, options, env) {
|
|
|
10521
10673
|
}
|
|
10522
10674
|
};
|
|
10523
10675
|
}
|
|
10676
|
+
function guidesOf(view) {
|
|
10677
|
+
const root = view.chart.element;
|
|
10678
|
+
return (view.chart.guides?.() ?? []).flatMap((guide) => {
|
|
10679
|
+
const element = guide?.element;
|
|
10680
|
+
const parent = element?.parentElement;
|
|
10681
|
+
if (typeof guide?.key !== "string" || !parent || !root.contains(parent)) return [];
|
|
10682
|
+
const m = between$1(overlay, parent, wrapper);
|
|
10683
|
+
const copy = paintedCopy(element, root);
|
|
10684
|
+
const group = doc.createElementNS(SVG_NS$2, "g");
|
|
10685
|
+
setAttributes(group, {
|
|
10686
|
+
class: "ec-switch-guide",
|
|
10687
|
+
"data-key": guide.key,
|
|
10688
|
+
transform: isIdentity$1(m) ? void 0 : transformAttribute(m)
|
|
10689
|
+
});
|
|
10690
|
+
group.appendChild(copy);
|
|
10691
|
+
const own = ownTransform(element);
|
|
10692
|
+
return [{
|
|
10693
|
+
key: guide.key,
|
|
10694
|
+
group,
|
|
10695
|
+
markup: copy.outerHTML,
|
|
10696
|
+
corners: cornersOf(element).map((p) => matrix.apply(m, matrix.apply(own, p))),
|
|
10697
|
+
place: m
|
|
10698
|
+
}];
|
|
10699
|
+
});
|
|
10700
|
+
}
|
|
10524
10701
|
function fadeMark(mark, paint, scale, opacity) {
|
|
10525
10702
|
const group = svgElement("g", {
|
|
10526
10703
|
class: "ec-switch-fade",
|
|
@@ -10726,8 +10903,105 @@ function setActive(container, active) {
|
|
|
10726
10903
|
else container.setAttribute("aria-hidden", "true");
|
|
10727
10904
|
}
|
|
10728
10905
|
function setOpacity(container, opacity) {
|
|
10729
|
-
container.style.setProperty("opacity",
|
|
10906
|
+
container.style.setProperty("opacity", opacityText(opacity));
|
|
10907
|
+
}
|
|
10908
|
+
const opacityText = (opacity) => String(Math.round(opacity * 1e3) / 1e3);
|
|
10909
|
+
const INHERITED = [
|
|
10910
|
+
"fill",
|
|
10911
|
+
"fill-opacity",
|
|
10912
|
+
"fill-rule",
|
|
10913
|
+
"stroke",
|
|
10914
|
+
"stroke-opacity",
|
|
10915
|
+
"stroke-width",
|
|
10916
|
+
"stroke-dasharray",
|
|
10917
|
+
"stroke-dashoffset",
|
|
10918
|
+
"stroke-linecap",
|
|
10919
|
+
"stroke-linejoin",
|
|
10920
|
+
"stroke-miterlimit",
|
|
10921
|
+
"paint-order",
|
|
10922
|
+
"marker-start",
|
|
10923
|
+
"marker-mid",
|
|
10924
|
+
"marker-end",
|
|
10925
|
+
"color",
|
|
10926
|
+
"visibility",
|
|
10927
|
+
"font-family",
|
|
10928
|
+
"font-size",
|
|
10929
|
+
"font-style",
|
|
10930
|
+
"font-weight",
|
|
10931
|
+
"font-stretch",
|
|
10932
|
+
"font-variant-caps",
|
|
10933
|
+
"font-variant-ligatures",
|
|
10934
|
+
"font-variant-numeric",
|
|
10935
|
+
"font-feature-settings",
|
|
10936
|
+
"font-kerning",
|
|
10937
|
+
"letter-spacing",
|
|
10938
|
+
"word-spacing",
|
|
10939
|
+
"text-anchor",
|
|
10940
|
+
"dominant-baseline",
|
|
10941
|
+
"text-rendering",
|
|
10942
|
+
"shape-rendering",
|
|
10943
|
+
"writing-mode",
|
|
10944
|
+
"direction"
|
|
10945
|
+
];
|
|
10946
|
+
const OWN = {
|
|
10947
|
+
opacity: "1",
|
|
10948
|
+
display: "inline",
|
|
10949
|
+
"clip-path": "none",
|
|
10950
|
+
mask: "none",
|
|
10951
|
+
filter: "none",
|
|
10952
|
+
"vector-effect": "none"
|
|
10953
|
+
};
|
|
10954
|
+
function paintedCopy(source, root) {
|
|
10955
|
+
const copy = source.cloneNode(true);
|
|
10956
|
+
const sources = [source, ...source.querySelectorAll("*")];
|
|
10957
|
+
const copies = [copy, ...copy.querySelectorAll("*")];
|
|
10958
|
+
sources.forEach((element, i) => {
|
|
10959
|
+
const target = copies[i];
|
|
10960
|
+
target.removeAttribute("id");
|
|
10961
|
+
const computed = element.ownerDocument.defaultView?.getComputedStyle?.(element);
|
|
10962
|
+
const styles = {};
|
|
10963
|
+
for (const property of INHERITED) styles[property] = drawnStyle(element, root, property) || void 0;
|
|
10964
|
+
for (const [property, initial] of Object.entries(OWN)) {
|
|
10965
|
+
const value = computed?.getPropertyValue(property).trim();
|
|
10966
|
+
if (value && value !== initial) styles[property] = value;
|
|
10967
|
+
}
|
|
10968
|
+
setStyles(target, styles);
|
|
10969
|
+
});
|
|
10970
|
+
return copy;
|
|
10730
10971
|
}
|
|
10972
|
+
function cornersOf(element) {
|
|
10973
|
+
try {
|
|
10974
|
+
const box = element.getBBox?.();
|
|
10975
|
+
if (box) return [
|
|
10976
|
+
{
|
|
10977
|
+
x: box.x,
|
|
10978
|
+
y: box.y
|
|
10979
|
+
},
|
|
10980
|
+
{
|
|
10981
|
+
x: box.x + box.width,
|
|
10982
|
+
y: box.y
|
|
10983
|
+
},
|
|
10984
|
+
{
|
|
10985
|
+
x: box.x,
|
|
10986
|
+
y: box.y + box.height
|
|
10987
|
+
},
|
|
10988
|
+
{
|
|
10989
|
+
x: box.x + box.width,
|
|
10990
|
+
y: box.y + box.height
|
|
10991
|
+
}
|
|
10992
|
+
];
|
|
10993
|
+
} catch {}
|
|
10994
|
+
return [{
|
|
10995
|
+
x: 0,
|
|
10996
|
+
y: 0
|
|
10997
|
+
}];
|
|
10998
|
+
}
|
|
10999
|
+
const sameGuide = (a, b) => a.markup === b.markup && a.corners.length === b.corners.length && a.corners.every((p, i) => Math.hypot(p.x - b.corners[i].x, p.y - b.corners[i].y) <= .5) && [
|
|
11000
|
+
0,
|
|
11001
|
+
1,
|
|
11002
|
+
2,
|
|
11003
|
+
3
|
|
11004
|
+
].every((i) => Math.abs(a.place[i] - b.place[i]) <= 1e-4);
|
|
10731
11005
|
function moveLabel(a, b) {
|
|
10732
11006
|
return (s) => {
|
|
10733
11007
|
const x = mix$1(a.at.x, b.at.x, s);
|
|
@@ -10760,6 +11034,8 @@ function fadeLabel(label, opacity) {
|
|
|
10760
11034
|
}
|
|
10761
11035
|
const fadeOut = (s) => 1 - clamp$1(s / HALF);
|
|
10762
11036
|
const fadeIn = (s) => clamp$1((s - HALF) / .5);
|
|
11037
|
+
const othersOut = (s) => 1 - clamp$1(s / OUT_BY);
|
|
11038
|
+
const othersIn = fadeIn;
|
|
10763
11039
|
const clamp$1 = (value) => Math.min(1, Math.max(0, value));
|
|
10764
11040
|
const mix$1 = (x, y, s) => x * (1 - s) + y * s;
|
|
10765
11041
|
function paintOf(view, mark) {
|
|
@@ -10793,41 +11069,7 @@ function placeDot(element, end) {
|
|
|
10793
11069
|
"stroke-width": end.ring
|
|
10794
11070
|
});
|
|
10795
11071
|
}
|
|
10796
|
-
const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
10797
11072
|
const scaleOf = (m) => Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
10798
|
-
function mapMark(mark, m) {
|
|
10799
|
-
if (isIdentity(m)) return mark;
|
|
10800
|
-
const point = (p) => matrix.apply(m, p);
|
|
10801
|
-
const path = (d) => formatPath(transformPath(parsePath(d), m));
|
|
10802
|
-
const scale = scaleOf(m);
|
|
10803
|
-
const { outline } = mark;
|
|
10804
|
-
return {
|
|
10805
|
-
key: mark.key,
|
|
10806
|
-
...mark.series === void 0 ? {} : { series: mark.series },
|
|
10807
|
-
start: point(mark.start),
|
|
10808
|
-
end: point(mark.end),
|
|
10809
|
-
length: mark.length * scale,
|
|
10810
|
-
path: (t) => point(mark.path(t)),
|
|
10811
|
-
angle: (t) => {
|
|
10812
|
-
const angle = mark.angle(t);
|
|
10813
|
-
const cos = Math.cos(angle);
|
|
10814
|
-
const sin = Math.sin(angle);
|
|
10815
|
-
return Math.atan2(m[1] * cos + m[3] * sin, m[0] * cos + m[2] * sin);
|
|
10816
|
-
},
|
|
10817
|
-
slice: (t0, t1) => path(mark.slice(t0, t1)),
|
|
10818
|
-
...mark.gaps === void 0 ? {} : { gaps: mark.gaps },
|
|
10819
|
-
thickness: mark.thickness * scale,
|
|
10820
|
-
outline: {
|
|
10821
|
-
d: path(outline.d),
|
|
10822
|
-
closed: outline.closed,
|
|
10823
|
-
sample: (n) => outline.sample(n).map(point)
|
|
10824
|
-
},
|
|
10825
|
-
bounds: boxIn(m, mark.bounds),
|
|
10826
|
-
center: point(mark.center),
|
|
10827
|
-
pivot: point(mark.pivot),
|
|
10828
|
-
...mark.segments === void 0 ? {} : { segments: mark.segments.map((segment) => mapMark(segment, m)) }
|
|
10829
|
-
};
|
|
10830
|
-
}
|
|
10831
11073
|
function deferred() {
|
|
10832
11074
|
let settle;
|
|
10833
11075
|
return {
|
|
@@ -11576,9 +11818,9 @@ function captionPlace(mark, text) {
|
|
|
11576
11818
|
return past(mark.end, heading, PAST_END, own, boxes, text);
|
|
11577
11819
|
}
|
|
11578
11820
|
function past(from, toward, least, own, boxes, text) {
|
|
11579
|
-
if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -
|
|
11821
|
+
if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -1e400));
|
|
11580
11822
|
const { x, y, width, height } = text.box(placed$1(from, toward, 0));
|
|
11581
|
-
return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -
|
|
11823
|
+
return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -1e400), boxes, {
|
|
11582
11824
|
x: x - from.x,
|
|
11583
11825
|
y: y - from.y,
|
|
11584
11826
|
width,
|
|
@@ -11602,7 +11844,7 @@ function clearOf(from, toward, distance, boxes, reach, held) {
|
|
|
11602
11844
|
const within = meets(near);
|
|
11603
11845
|
if (!band || !within) return within;
|
|
11604
11846
|
const leaving = across ? Math.max(band[1], ((sin > 0 ? near.y + near.height : near.y) - from.y) / sin) : band[1];
|
|
11605
|
-
return [within[0], Math.max(leaving, meets(box)?.[1] ?? -
|
|
11847
|
+
return [within[0], Math.max(leaving, meets(box)?.[1] ?? -1e400)];
|
|
11606
11848
|
});
|
|
11607
11849
|
let at = distance;
|
|
11608
11850
|
for (let moved = true; moved;) {
|
|
@@ -11656,7 +11898,7 @@ function leaves(from, cos, sin, box) {
|
|
|
11656
11898
|
}
|
|
11657
11899
|
function span(from, cos, sin, box) {
|
|
11658
11900
|
let near = 0;
|
|
11659
|
-
let far =
|
|
11901
|
+
let far = 1e400;
|
|
11660
11902
|
for (const [origin, step, lo, hi] of [[
|
|
11661
11903
|
from.x,
|
|
11662
11904
|
cos,
|
|
@@ -12248,8 +12490,8 @@ function bandOf(outline) {
|
|
|
12248
12490
|
ring.push(segment.to);
|
|
12249
12491
|
}
|
|
12250
12492
|
if (areaOf(ring) < 0) ring.reverse();
|
|
12251
|
-
const left = ring.reduce((x, point) => Math.min(x, point.x),
|
|
12252
|
-
const right = ring.reduce((x, point) => Math.max(x, point.x), -
|
|
12493
|
+
const left = ring.reduce((x, point) => Math.min(x, point.x), 1e400);
|
|
12494
|
+
const right = ring.reduce((x, point) => Math.max(x, point.x), -1e400);
|
|
12253
12495
|
if (!(right - left > 2 * SAME_X)) return void 0;
|
|
12254
12496
|
const atLeft = (point) => point.x - left <= SAME_X;
|
|
12255
12497
|
const atRight = (point) => right - point.x <= SAME_X;
|
|
@@ -12366,7 +12608,7 @@ function landing(hole, own, other, area) {
|
|
|
12366
12608
|
}
|
|
12367
12609
|
function depth(point, area) {
|
|
12368
12610
|
if (windingAt(point, area) === 0) return 0;
|
|
12369
|
-
let nearest =
|
|
12611
|
+
let nearest = 1e400;
|
|
12370
12612
|
for (const ring of area) ring.forEach((p, i) => {
|
|
12371
12613
|
const q = ring[(i + 1) % ring.length];
|
|
12372
12614
|
const dx = q.x - p.x;
|
|
@@ -12983,7 +13225,7 @@ function configure(options) {
|
|
|
12983
13225
|
}
|
|
12984
13226
|
}
|
|
12985
13227
|
// src/index.ts
|
|
12986
|
-
const VERSION = "0.
|
|
13228
|
+
const VERSION = "0.12.0";
|
|
12987
13229
|
const env = {
|
|
12988
13230
|
presets: presetRegistry,
|
|
12989
13231
|
icons: iconRegistry,
|