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.cjs
CHANGED
|
@@ -196,7 +196,7 @@ function createMotion(options = {}) {
|
|
|
196
196
|
function scaleDuration(base, rule) {
|
|
197
197
|
if (!(base > 0)) return 0;
|
|
198
198
|
const floor = Math.min(base, rule.min ?? 0);
|
|
199
|
-
const ceiling = rule.max ??
|
|
199
|
+
const ceiling = rule.max ?? 1e400;
|
|
200
200
|
return Math.min(Math.max(base * rule.factor, floor), ceiling);
|
|
201
201
|
}
|
|
202
202
|
function mediaReducedMotion(query = "(prefers-reduced-motion: reduce)") {
|
|
@@ -613,10 +613,10 @@ function extremes(segment) {
|
|
|
613
613
|
return points;
|
|
614
614
|
}
|
|
615
615
|
function boundsOf(points) {
|
|
616
|
-
let minX =
|
|
617
|
-
let minY =
|
|
618
|
-
let maxX = -
|
|
619
|
-
let maxY = -
|
|
616
|
+
let minX = 1e400;
|
|
617
|
+
let minY = 1e400;
|
|
618
|
+
let maxX = -1e400;
|
|
619
|
+
let maxY = -1e400;
|
|
620
620
|
for (const { x, y } of points) {
|
|
621
621
|
if (x < minX) minX = x;
|
|
622
622
|
if (x > maxX) maxX = x;
|
|
@@ -819,8 +819,8 @@ function reversed(loop) {
|
|
|
819
819
|
function fromUpperLeft(loop) {
|
|
820
820
|
let index = 0;
|
|
821
821
|
let u = 0;
|
|
822
|
-
let key =
|
|
823
|
-
let top =
|
|
822
|
+
let key = 1e400;
|
|
823
|
+
let top = 1e400;
|
|
824
824
|
const consider = (point, i, at) => {
|
|
825
825
|
const k = point.x + point.y;
|
|
826
826
|
if (k < key - 1e-9 || k <= key + 1e-9 && point.y < top) [index, u, key, top] = [
|
|
@@ -1973,7 +1973,7 @@ function nearest$1(mark, grid, p) {
|
|
|
1973
1973
|
const n = grid.length;
|
|
1974
1974
|
if (n === 1) return 0;
|
|
1975
1975
|
let best = 0;
|
|
1976
|
-
let bestDistance =
|
|
1976
|
+
let bestDistance = 1e400;
|
|
1977
1977
|
grid.forEach((q, i) => {
|
|
1978
1978
|
const d = squared(q, p);
|
|
1979
1979
|
if (d < bestDistance) {
|
|
@@ -3896,7 +3896,7 @@ function svgSurface(options) {
|
|
|
3896
3896
|
}, overlay);
|
|
3897
3897
|
setStyles(group, markColorStyles(options.colors(key)));
|
|
3898
3898
|
orders.set(group, order);
|
|
3899
|
-
const above = Array.from(overlay.children).find((child) => (orders.get(child) ?? -
|
|
3899
|
+
const above = Array.from(overlay.children).find((child) => (orders.get(child) ?? -1e400) > order);
|
|
3900
3900
|
overlay.insertBefore(group, above ?? null);
|
|
3901
3901
|
let live = groups.get(key);
|
|
3902
3902
|
if (!live) groups.set(key, live = /* @__PURE__ */ new Set());
|
|
@@ -7348,7 +7348,7 @@ function lineCurve(xs, values, amount, scales, presence) {
|
|
|
7348
7348
|
];
|
|
7349
7349
|
};
|
|
7350
7350
|
return {
|
|
7351
|
-
between(from, to, through =
|
|
7351
|
+
between(from, to, through = 1e400) {
|
|
7352
7352
|
const p = piece(from, to);
|
|
7353
7353
|
if (!p || !tangents) return [];
|
|
7354
7354
|
const [v0, c1, c2, v1, k] = p;
|
|
@@ -7619,7 +7619,7 @@ function boundaries(lo, hi, step, zone) {
|
|
|
7619
7619
|
return out;
|
|
7620
7620
|
}
|
|
7621
7621
|
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);
|
|
7622
|
-
let previous = -
|
|
7622
|
+
let previous = -1e400;
|
|
7623
7623
|
for (let i = 0;; i++) {
|
|
7624
7624
|
const t = nth(i);
|
|
7625
7625
|
if (t >= hi || t <= previous) break;
|
|
@@ -8360,7 +8360,7 @@ function lineChart$1(target, options, env) {
|
|
|
8360
8360
|
const events = chartEvents("lineChart");
|
|
8361
8361
|
let measuredWidth = containerWidth(container);
|
|
8362
8362
|
let destroyed = false;
|
|
8363
|
-
let through =
|
|
8363
|
+
let through = 1e400;
|
|
8364
8364
|
const labelFailures = /* @__PURE__ */ new WeakSet();
|
|
8365
8365
|
let laidOut;
|
|
8366
8366
|
let firstTable;
|
|
@@ -8506,7 +8506,7 @@ function lineChart$1(target, options, env) {
|
|
|
8506
8506
|
}
|
|
8507
8507
|
function drawnThrough(next) {
|
|
8508
8508
|
const last = next.rows[next.rows.length - 1];
|
|
8509
|
-
return last && through < last.x ? revealedIn(next) :
|
|
8509
|
+
return last && through < last.x ? revealedIn(next) : 1e400;
|
|
8510
8510
|
}
|
|
8511
8511
|
const revealed = (record) => !record.leaving && record.row.x <= revealedIn(laidOut);
|
|
8512
8512
|
function createRow(row, entering) {
|
|
@@ -8985,8 +8985,8 @@ function lineChart$1(target, options, env) {
|
|
|
8985
8985
|
function nearestPoint(at) {
|
|
8986
8986
|
const shown = rowOrder.filter(revealed).flatMap(livePoints);
|
|
8987
8987
|
let best;
|
|
8988
|
-
let far =
|
|
8989
|
-
let rank =
|
|
8988
|
+
let far = 1e400;
|
|
8989
|
+
let rank = 1e400;
|
|
8990
8990
|
for (const point of shown) {
|
|
8991
8991
|
const d = apart(point.shown.geometry.center, at);
|
|
8992
8992
|
const r = laidOut.series.indexOf(point.series);
|
|
@@ -9006,7 +9006,7 @@ function lineChart$1(target, options, env) {
|
|
|
9006
9006
|
}
|
|
9007
9007
|
if (on.size < 2) return best;
|
|
9008
9008
|
let pick = best;
|
|
9009
|
-
let near =
|
|
9009
|
+
let near = 1e400;
|
|
9010
9010
|
for (const series of laidOut.series) {
|
|
9011
9011
|
const point = on.get(series);
|
|
9012
9012
|
if (!point) continue;
|
|
@@ -9739,7 +9739,7 @@ function strokeNear({ geometry, data: { samples } }, x, from, at, reach) {
|
|
|
9739
9739
|
if (!next || (way > 0 ? next : samples[j]).gapBefore) break;
|
|
9740
9740
|
const to = way > 0 ? Math.min(next.t, t + span) : Math.max(next.t, t - span);
|
|
9741
9741
|
const b = geometry.path(to);
|
|
9742
|
-
near = Math.min(near ??
|
|
9742
|
+
near = Math.min(near ?? 1e400, toSegment(at, a, b));
|
|
9743
9743
|
if (to !== next.t) break;
|
|
9744
9744
|
a = b;
|
|
9745
9745
|
}
|
|
@@ -9863,7 +9863,7 @@ function describeRects(key, parts, baseline) {
|
|
|
9863
9863
|
...span(part.box)
|
|
9864
9864
|
})).sort((a, b) => a.near - b.near || a.far - b.far || a.index - b.index);
|
|
9865
9865
|
let reached = 0;
|
|
9866
|
-
let gap =
|
|
9866
|
+
let gap = 1e400;
|
|
9867
9867
|
const segments = order.map(({ index, near, far }) => {
|
|
9868
9868
|
if (reached > 0 && far > near) gap = Math.min(gap, near - reached);
|
|
9869
9869
|
const size = Math.max(0, far - reached);
|
|
@@ -10082,6 +10082,40 @@ function between$1(outer, inner, root, screen = screenMatrix) {
|
|
|
10082
10082
|
if (a && b) return matrix.multiply(invert(a), b);
|
|
10083
10083
|
return matrix.multiply(invert(fromRoot(outer, root)), fromRoot(inner, root));
|
|
10084
10084
|
}
|
|
10085
|
+
function mapMark(mark, m) {
|
|
10086
|
+
if (isIdentity$1(m)) return mark;
|
|
10087
|
+
const point = (p) => matrix.apply(m, p);
|
|
10088
|
+
const path = (d) => formatPath(transformPath(parsePath(d), m));
|
|
10089
|
+
const scale = scaleOf$2(m);
|
|
10090
|
+
const { outline } = mark;
|
|
10091
|
+
return {
|
|
10092
|
+
key: mark.key,
|
|
10093
|
+
...mark.series === void 0 ? {} : { series: mark.series },
|
|
10094
|
+
start: point(mark.start),
|
|
10095
|
+
end: point(mark.end),
|
|
10096
|
+
length: mark.length * scale,
|
|
10097
|
+
path: (t) => point(mark.path(t)),
|
|
10098
|
+
angle: (t) => {
|
|
10099
|
+
const angle = mark.angle(t);
|
|
10100
|
+
const cos = Math.cos(angle);
|
|
10101
|
+
const sin = Math.sin(angle);
|
|
10102
|
+
return Math.atan2(m[1] * cos + m[3] * sin, m[0] * cos + m[2] * sin);
|
|
10103
|
+
},
|
|
10104
|
+
slice: (t0, t1) => path(mark.slice(t0, t1)),
|
|
10105
|
+
...mark.gaps === void 0 ? {} : { gaps: mark.gaps },
|
|
10106
|
+
thickness: mark.thickness * scale,
|
|
10107
|
+
outline: {
|
|
10108
|
+
d: path(outline.d),
|
|
10109
|
+
closed: outline.closed,
|
|
10110
|
+
sample: (n) => outline.sample(n).map(point)
|
|
10111
|
+
},
|
|
10112
|
+
bounds: boxIn(m, mark.bounds),
|
|
10113
|
+
center: point(mark.center),
|
|
10114
|
+
pivot: point(mark.pivot),
|
|
10115
|
+
...mark.segments === void 0 ? {} : { segments: mark.segments.map((segment) => mapMark(segment, m)) }
|
|
10116
|
+
};
|
|
10117
|
+
}
|
|
10118
|
+
const isIdentity$1 = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
10085
10119
|
function ownTransform(element) {
|
|
10086
10120
|
return parseTransform(element.getAttribute("transform") ?? "");
|
|
10087
10121
|
}
|
|
@@ -10225,7 +10259,7 @@ function hostMarkHandle(parts, edits, halos) {
|
|
|
10225
10259
|
};
|
|
10226
10260
|
}
|
|
10227
10261
|
function hostColors(element, root) {
|
|
10228
|
-
const fill = paintOf$1(element, root, "fill");
|
|
10262
|
+
const fill = element.localName === "line" ? NONE : paintOf$1(element, root, "fill");
|
|
10229
10263
|
const paint = fill === NONE ? "stroke" : "fill";
|
|
10230
10264
|
const color = paint === "fill" ? fill : paintOf$1(element, root, "stroke");
|
|
10231
10265
|
if (color === void 0 || color === NONE) return void 0;
|
|
@@ -11121,7 +11155,7 @@ function expressive$1(target, options, env) {
|
|
|
11121
11155
|
if (root.lastElementChild !== overlay) root.appendChild(overlay);
|
|
11122
11156
|
overlay.removeAttribute("transform");
|
|
11123
11157
|
const m = between$1(overlay, ancestor, root);
|
|
11124
|
-
if (!isIdentity
|
|
11158
|
+
if (!isIdentity(m)) overlay.setAttribute("transform", transformAttribute(m));
|
|
11125
11159
|
}
|
|
11126
11160
|
function moveTo(next) {
|
|
11127
11161
|
detach();
|
|
@@ -11672,7 +11706,7 @@ function tryInvert(m) {
|
|
|
11672
11706
|
return;
|
|
11673
11707
|
}
|
|
11674
11708
|
}
|
|
11675
|
-
function isIdentity
|
|
11709
|
+
function isIdentity(m) {
|
|
11676
11710
|
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;
|
|
11677
11711
|
}
|
|
11678
11712
|
function valuesChanged(from, to) {
|
|
@@ -11725,19 +11759,37 @@ function scaled(value, scale) {
|
|
|
11725
11759
|
if (scale === 1) return value;
|
|
11726
11760
|
return value.replace(/(-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(px)?(?![\w.%])/gi, (_, n, px) => `${Math.round(Number(n) * scale * 1e3) / 1e3}${px ?? ""}`);
|
|
11727
11761
|
}
|
|
11728
|
-
function hostView(
|
|
11729
|
-
const
|
|
11730
|
-
|
|
11731
|
-
|
|
11762
|
+
function hostView(attachments, options = {}) {
|
|
11763
|
+
const list = Array.isArray(attachments) ? attachments : [attachments];
|
|
11764
|
+
if (list.length === 0) throw new TypeError("hostView needs an attachment, or an array of attachments on one <svg>: hostView([dots, connectors]).");
|
|
11765
|
+
const parts = list.map((attachment, i) => {
|
|
11766
|
+
const port = typeof attachment === "object" && attachment !== null ? portOf(attachment) : void 0;
|
|
11767
|
+
const inside = insidesOf(port);
|
|
11768
|
+
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>.");
|
|
11769
|
+
if (list.indexOf(attachment) !== i) throw new TypeError(`hostView: attachments[${i}] is attachments[${list.indexOf(attachment)}] again. Each attachment is in a view once.`);
|
|
11770
|
+
return {
|
|
11771
|
+
attachment,
|
|
11772
|
+
port,
|
|
11773
|
+
inside,
|
|
11774
|
+
hidden: []
|
|
11775
|
+
};
|
|
11776
|
+
});
|
|
11732
11777
|
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
|
-
|
|
11734
|
-
const
|
|
11778
|
+
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\" }].");
|
|
11779
|
+
const lead = parts[0];
|
|
11780
|
+
const several = parts.length > 1;
|
|
11781
|
+
const { edits } = lead.inside;
|
|
11782
|
+
const svg = () => lead.inside.root();
|
|
11735
11783
|
let given;
|
|
11736
|
-
let
|
|
11784
|
+
let guided;
|
|
11737
11785
|
let classed;
|
|
11786
|
+
const clash = several ? clashOf(parts, svg()) : void 0;
|
|
11787
|
+
if (clash) throw new TypeError(`hostView: ${clash.problem}.`);
|
|
11788
|
+
const drawn = () => parts.filter((part) => part.inside.root() === svg());
|
|
11789
|
+
const ownerOf = (key) => drawn().find((part) => part.attachment.marks().some((mark) => mark.key === key));
|
|
11738
11790
|
function read() {
|
|
11739
11791
|
if (!options.labels) return [];
|
|
11740
|
-
const keys = new Set(attachment.marks().map((mark) => mark.key));
|
|
11792
|
+
const keys = new Set(drawn().flatMap((part) => part.attachment.marks().map((mark) => mark.key)));
|
|
11741
11793
|
try {
|
|
11742
11794
|
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
11795
|
} catch (error) {
|
|
@@ -11745,6 +11797,16 @@ function hostView(attachment, options = {}) {
|
|
|
11745
11797
|
return [];
|
|
11746
11798
|
}
|
|
11747
11799
|
}
|
|
11800
|
+
function guides() {
|
|
11801
|
+
if (!options.guides) return [];
|
|
11802
|
+
const root = svg();
|
|
11803
|
+
try {
|
|
11804
|
+
return Array.from(options.guides()).filter((guide) => (guide?.element)?.nodeType === 1 && guide.element !== root && root.contains(guide.element) && typeof guide.key === "string");
|
|
11805
|
+
} catch (error) {
|
|
11806
|
+
report(error);
|
|
11807
|
+
return [];
|
|
11808
|
+
}
|
|
11809
|
+
}
|
|
11748
11810
|
function chartLabel({ element, key, role }) {
|
|
11749
11811
|
const root = svg();
|
|
11750
11812
|
const m = between$1(view.space, element, root);
|
|
@@ -11775,16 +11837,27 @@ function hostView(attachment, options = {}) {
|
|
|
11775
11837
|
};
|
|
11776
11838
|
}
|
|
11777
11839
|
const hide = (on) => {
|
|
11840
|
+
if (on && given === void 0 && several) {
|
|
11841
|
+
const found = clashOf(parts, svg());
|
|
11842
|
+
if (found) report(/* @__PURE__ */ new TypeError(`hostView: ${found.problem}. The switch plays on, and ${found.left}.`));
|
|
11843
|
+
}
|
|
11778
11844
|
const root = on ? svg() : void 0;
|
|
11779
11845
|
given = on ? read() : void 0;
|
|
11780
|
-
|
|
11846
|
+
guided = on ? guides() : void 0;
|
|
11847
|
+
const named = [...(given ?? []).map((label) => label.element), ...(guided ?? []).map((guide) => guide.element)];
|
|
11848
|
+
const now = parts.map(({ inside, hidden }, i) => new Set(given ? [
|
|
11781
11849
|
...inside.elements(),
|
|
11782
|
-
...
|
|
11850
|
+
...i === 0 ? named : [],
|
|
11783
11851
|
...hidden.filter((element) => root?.contains(element))
|
|
11784
|
-
] : []);
|
|
11785
|
-
for (const element of
|
|
11786
|
-
|
|
11787
|
-
|
|
11852
|
+
] : []));
|
|
11853
|
+
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);
|
|
11854
|
+
parts.forEach((part, i) => {
|
|
11855
|
+
for (const element of part.hidden) if (!now[i].has(element)) part.inside.edits.style(element, "visibility", void 0);
|
|
11856
|
+
});
|
|
11857
|
+
parts.forEach((part, i) => {
|
|
11858
|
+
part.hidden = [...now[i]];
|
|
11859
|
+
for (const element of part.hidden) part.inside.edits.style(element, "visibility", "hidden");
|
|
11860
|
+
});
|
|
11788
11861
|
if (classed !== root) {
|
|
11789
11862
|
if (classed) edits.toggleClass(classed, "ec-morphing", false);
|
|
11790
11863
|
if (root) edits.toggleClass(root, "ec-morphing", true);
|
|
@@ -11796,36 +11869,82 @@ function hostView(attachment, options = {}) {
|
|
|
11796
11869
|
return svg();
|
|
11797
11870
|
},
|
|
11798
11871
|
get space() {
|
|
11799
|
-
|
|
11800
|
-
|
|
11801
|
-
|
|
11802
|
-
|
|
11803
|
-
|
|
11804
|
-
|
|
11805
|
-
|
|
11806
|
-
|
|
11872
|
+
const root = svg();
|
|
11873
|
+
const [space, ...others] = drawn().map((part) => part.inside.ancestor() ?? root);
|
|
11874
|
+
let common = space;
|
|
11875
|
+
for (const other of others) while (common !== root && !common.contains(other)) common = common.parentElement ?? root;
|
|
11876
|
+
return common;
|
|
11877
|
+
},
|
|
11878
|
+
refresh(source) {
|
|
11879
|
+
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.");
|
|
11880
|
+
for (const { attachment } of parts) attachment.refresh(source);
|
|
11881
|
+
},
|
|
11882
|
+
update: (next) => several ? Promise.all(parts.map(({ attachment }) => attachment.update(next))).then(() => {}) : lead.attachment.update(next),
|
|
11883
|
+
on(type, listener) {
|
|
11884
|
+
const stops = parts.map(({ attachment }) => attachment.on(type, listener));
|
|
11885
|
+
return several ? () => stops.forEach((stop) => stop()) : stops[0];
|
|
11886
|
+
},
|
|
11887
|
+
marks() {
|
|
11888
|
+
const root = svg();
|
|
11889
|
+
const space = view.space;
|
|
11890
|
+
const keys = /* @__PURE__ */ new Set();
|
|
11891
|
+
return drawn().flatMap(({ attachment, inside }) => {
|
|
11892
|
+
const ancestor = inside.ancestor() ?? root;
|
|
11893
|
+
const m = ancestor === space ? void 0 : between$1(space, ancestor, root);
|
|
11894
|
+
return attachment.marks().flatMap((mark) => keys.has(mark.key) ? [] : (keys.add(mark.key), [m ? mapMark(mark, m) : mark]));
|
|
11895
|
+
});
|
|
11896
|
+
},
|
|
11897
|
+
focus: (key) => ownerOf(key)?.attachment.focus(key),
|
|
11898
|
+
leave() {
|
|
11899
|
+
for (const { attachment } of parts) attachment.leave();
|
|
11900
|
+
},
|
|
11807
11901
|
destroy() {
|
|
11808
|
-
given = classed = void 0;
|
|
11809
|
-
hidden = [];
|
|
11810
|
-
attachment.destroy();
|
|
11902
|
+
given = guided = classed = void 0;
|
|
11903
|
+
for (const part of parts) part.hidden = [];
|
|
11904
|
+
for (const { attachment } of [...parts].reverse()) attachment.destroy();
|
|
11811
11905
|
},
|
|
11812
11906
|
labels: () => (given ?? read()).map(chartLabel),
|
|
11907
|
+
guides: () => guided ?? guides(),
|
|
11813
11908
|
paintOf(key) {
|
|
11814
|
-
const
|
|
11815
|
-
|
|
11816
|
-
color
|
|
11817
|
-
|
|
11818
|
-
|
|
11819
|
-
|
|
11909
|
+
for (const { inside } of drawn()) {
|
|
11910
|
+
const color = inside.colorOf(key);
|
|
11911
|
+
if (color !== void 0) return {
|
|
11912
|
+
color: key,
|
|
11913
|
+
drawn: true,
|
|
11914
|
+
cssColor: color
|
|
11915
|
+
};
|
|
11916
|
+
}
|
|
11917
|
+
},
|
|
11918
|
+
keyOf(element) {
|
|
11919
|
+
for (const { inside } of parts) {
|
|
11920
|
+
const key = inside.keyOf(element);
|
|
11921
|
+
if (key !== void 0) return key;
|
|
11922
|
+
}
|
|
11820
11923
|
},
|
|
11821
|
-
|
|
11822
|
-
moveTabStop: (key) => inside.moveTabStop(key),
|
|
11924
|
+
moveTabStop: (key) => drawn().some(({ inside }) => inside.moveTabStop(key)),
|
|
11823
11925
|
morphing: hide
|
|
11824
11926
|
};
|
|
11825
|
-
inside.refreshed.add(() => {
|
|
11927
|
+
for (const { inside } of parts) inside.refreshed.add(() => {
|
|
11826
11928
|
if (given) hide(true);
|
|
11827
11929
|
});
|
|
11828
|
-
return linkable(port, view);
|
|
11930
|
+
return several ? view : linkable(lead.port, view);
|
|
11931
|
+
}
|
|
11932
|
+
function clashOf(parts, root) {
|
|
11933
|
+
const owners = /* @__PURE__ */ new Map();
|
|
11934
|
+
for (const [i, { attachment, inside }] of parts.entries()) {
|
|
11935
|
+
if (inside.root() !== root) return {
|
|
11936
|
+
problem: `attachments[${i}]'s marks are in another <svg> than attachments[0]'s, and a view's attachments share one`,
|
|
11937
|
+
left: `attachments[${i}]'s marks are left out`
|
|
11938
|
+
};
|
|
11939
|
+
for (const { key } of attachment.marks()) {
|
|
11940
|
+
const owner = owners.get(key);
|
|
11941
|
+
if (owner !== void 0 && owner !== i) return {
|
|
11942
|
+
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}\``,
|
|
11943
|
+
left: `the key stays attachments[${owner}]'s: attachments[${i}]'s mark is left out`
|
|
11944
|
+
};
|
|
11945
|
+
owners.set(key, i);
|
|
11946
|
+
}
|
|
11947
|
+
}
|
|
11829
11948
|
}
|
|
11830
11949
|
// src/charts/adapter/vega.ts
|
|
11831
11950
|
const MARK_TYPES = [
|
|
@@ -12417,7 +12536,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12417
12536
|
}, runsLayer);
|
|
12418
12537
|
setStyles(group, tokensOf(paints[order] ?? { color: key }));
|
|
12419
12538
|
orders.set(group, order);
|
|
12420
|
-
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -
|
|
12539
|
+
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -1e400) > order);
|
|
12421
12540
|
runsLayer.insertBefore(group, above ?? null);
|
|
12422
12541
|
const layer = svgLayer(group);
|
|
12423
12542
|
return {
|
|
@@ -12586,14 +12705,16 @@ function chartSwitch$1(target, options, env) {
|
|
|
12586
12705
|
reached();
|
|
12587
12706
|
return Promise.resolve();
|
|
12588
12707
|
}
|
|
12708
|
+
const guides = [];
|
|
12589
12709
|
for (const each of [from, to]) {
|
|
12590
12710
|
each.container.classList.remove("ec-switch-inactive");
|
|
12711
|
+
guides.push(guidesOf(each));
|
|
12591
12712
|
each.container.classList.add("ec-switching");
|
|
12592
12713
|
each.container.setAttribute("inert", "");
|
|
12593
12714
|
each.chart.morphing?.(true);
|
|
12594
12715
|
each.chart.element.classList.add("ec-morphing");
|
|
12595
12716
|
}
|
|
12596
|
-
const { pairs, surface, scene } = prepare(from, to);
|
|
12717
|
+
const { pairs, surface, scene } = prepare(from, to, guides);
|
|
12597
12718
|
const { done, settle } = carried ?? deferred();
|
|
12598
12719
|
const session = {
|
|
12599
12720
|
a: from,
|
|
@@ -12691,7 +12812,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12691
12812
|
}
|
|
12692
12813
|
session.settle();
|
|
12693
12814
|
}
|
|
12694
|
-
function prepare(a, b) {
|
|
12815
|
+
function prepare(a, b, guides) {
|
|
12695
12816
|
const toA = between$1(overlay, a.chart.space ?? a.chart.element, wrapper);
|
|
12696
12817
|
const toB = between$1(overlay, b.chart.space ?? b.chart.element, wrapper);
|
|
12697
12818
|
const scaleA = scaleOf(toA);
|
|
@@ -12741,9 +12862,39 @@ function chartSwitch$1(target, options, env) {
|
|
|
12741
12862
|
}
|
|
12742
12863
|
for (const label of labelsA) if (!matched.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toA, sizeA), fadeOut));
|
|
12743
12864
|
for (const label of labelsB) if (!byId.has(id(label))) drawings.push(fadeLabel(copyLabel(label, toB, sizeB), fadeIn));
|
|
12865
|
+
const [guidesA = [], guidesB = []] = guides;
|
|
12866
|
+
const partners = /* @__PURE__ */ new Map();
|
|
12867
|
+
for (const guide of guidesA) if (!partners.has(guide.key)) partners.set(guide.key, guide);
|
|
12868
|
+
const kept = /* @__PURE__ */ new Set();
|
|
12869
|
+
for (const guide of guidesB) {
|
|
12870
|
+
const partner = partners.get(guide.key);
|
|
12871
|
+
partners.delete(guide.key);
|
|
12872
|
+
if (partner && sameGuide(partner, guide)) kept.add(partner).add(guide);
|
|
12873
|
+
}
|
|
12874
|
+
let guidesLayer;
|
|
12875
|
+
if (guidesA.length + guidesB.length > 0) {
|
|
12876
|
+
const layer = guidesLayer = doc.createElementNS(SVG_NS$2, "g");
|
|
12877
|
+
layer.setAttribute("class", "ec-switch-guides");
|
|
12878
|
+
overlay.insertBefore(layer, fadesLayer);
|
|
12879
|
+
[[
|
|
12880
|
+
guidesA,
|
|
12881
|
+
(s) => s < HALF ? 1 : 0,
|
|
12882
|
+
othersOut
|
|
12883
|
+
], [
|
|
12884
|
+
guidesB,
|
|
12885
|
+
(s) => s < HALF ? 0 : 1,
|
|
12886
|
+
othersIn
|
|
12887
|
+
]].forEach(([list, steady, fading]) => {
|
|
12888
|
+
for (const guide of list) {
|
|
12889
|
+
layer.appendChild(guide.group);
|
|
12890
|
+
const opacity = kept.has(guide) ? steady : fading;
|
|
12891
|
+
drawings.push((s) => guide.group.setAttribute("opacity", opacityText(opacity(s))));
|
|
12892
|
+
}
|
|
12893
|
+
});
|
|
12894
|
+
}
|
|
12744
12895
|
drawings.push((s) => {
|
|
12745
|
-
setOpacity(a.container,
|
|
12746
|
-
setOpacity(b.container,
|
|
12896
|
+
setOpacity(a.container, othersOut(s));
|
|
12897
|
+
setOpacity(b.container, othersIn(s));
|
|
12747
12898
|
});
|
|
12748
12899
|
return {
|
|
12749
12900
|
pairs,
|
|
@@ -12753,6 +12904,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
12753
12904
|
for (const draw of drawings) draw(s);
|
|
12754
12905
|
},
|
|
12755
12906
|
clear: () => {
|
|
12907
|
+
guidesLayer?.remove();
|
|
12756
12908
|
fadesLayer.replaceChildren();
|
|
12757
12909
|
runsLayer.replaceChildren();
|
|
12758
12910
|
labelsLayer.replaceChildren();
|
|
@@ -12760,6 +12912,31 @@ function chartSwitch$1(target, options, env) {
|
|
|
12760
12912
|
}
|
|
12761
12913
|
};
|
|
12762
12914
|
}
|
|
12915
|
+
function guidesOf(view) {
|
|
12916
|
+
const root = view.chart.element;
|
|
12917
|
+
return (view.chart.guides?.() ?? []).flatMap((guide) => {
|
|
12918
|
+
const element = guide?.element;
|
|
12919
|
+
const parent = element?.parentElement;
|
|
12920
|
+
if (typeof guide?.key !== "string" || !parent || !root.contains(parent)) return [];
|
|
12921
|
+
const m = between$1(overlay, parent, wrapper);
|
|
12922
|
+
const copy = paintedCopy(element, root);
|
|
12923
|
+
const group = doc.createElementNS(SVG_NS$2, "g");
|
|
12924
|
+
setAttributes(group, {
|
|
12925
|
+
class: "ec-switch-guide",
|
|
12926
|
+
"data-key": guide.key,
|
|
12927
|
+
transform: isIdentity$1(m) ? void 0 : transformAttribute(m)
|
|
12928
|
+
});
|
|
12929
|
+
group.appendChild(copy);
|
|
12930
|
+
const own = ownTransform(element);
|
|
12931
|
+
return [{
|
|
12932
|
+
key: guide.key,
|
|
12933
|
+
group,
|
|
12934
|
+
markup: copy.outerHTML,
|
|
12935
|
+
corners: cornersOf(element).map((p) => matrix.apply(m, matrix.apply(own, p))),
|
|
12936
|
+
place: m
|
|
12937
|
+
}];
|
|
12938
|
+
});
|
|
12939
|
+
}
|
|
12763
12940
|
function fadeMark(mark, paint, scale, opacity) {
|
|
12764
12941
|
const group = svgElement("g", {
|
|
12765
12942
|
class: "ec-switch-fade",
|
|
@@ -12965,8 +13142,105 @@ function setActive(container, active) {
|
|
|
12965
13142
|
else container.setAttribute("aria-hidden", "true");
|
|
12966
13143
|
}
|
|
12967
13144
|
function setOpacity(container, opacity) {
|
|
12968
|
-
container.style.setProperty("opacity",
|
|
13145
|
+
container.style.setProperty("opacity", opacityText(opacity));
|
|
13146
|
+
}
|
|
13147
|
+
const opacityText = (opacity) => String(Math.round(opacity * 1e3) / 1e3);
|
|
13148
|
+
const INHERITED = [
|
|
13149
|
+
"fill",
|
|
13150
|
+
"fill-opacity",
|
|
13151
|
+
"fill-rule",
|
|
13152
|
+
"stroke",
|
|
13153
|
+
"stroke-opacity",
|
|
13154
|
+
"stroke-width",
|
|
13155
|
+
"stroke-dasharray",
|
|
13156
|
+
"stroke-dashoffset",
|
|
13157
|
+
"stroke-linecap",
|
|
13158
|
+
"stroke-linejoin",
|
|
13159
|
+
"stroke-miterlimit",
|
|
13160
|
+
"paint-order",
|
|
13161
|
+
"marker-start",
|
|
13162
|
+
"marker-mid",
|
|
13163
|
+
"marker-end",
|
|
13164
|
+
"color",
|
|
13165
|
+
"visibility",
|
|
13166
|
+
"font-family",
|
|
13167
|
+
"font-size",
|
|
13168
|
+
"font-style",
|
|
13169
|
+
"font-weight",
|
|
13170
|
+
"font-stretch",
|
|
13171
|
+
"font-variant-caps",
|
|
13172
|
+
"font-variant-ligatures",
|
|
13173
|
+
"font-variant-numeric",
|
|
13174
|
+
"font-feature-settings",
|
|
13175
|
+
"font-kerning",
|
|
13176
|
+
"letter-spacing",
|
|
13177
|
+
"word-spacing",
|
|
13178
|
+
"text-anchor",
|
|
13179
|
+
"dominant-baseline",
|
|
13180
|
+
"text-rendering",
|
|
13181
|
+
"shape-rendering",
|
|
13182
|
+
"writing-mode",
|
|
13183
|
+
"direction"
|
|
13184
|
+
];
|
|
13185
|
+
const OWN = {
|
|
13186
|
+
opacity: "1",
|
|
13187
|
+
display: "inline",
|
|
13188
|
+
"clip-path": "none",
|
|
13189
|
+
mask: "none",
|
|
13190
|
+
filter: "none",
|
|
13191
|
+
"vector-effect": "none"
|
|
13192
|
+
};
|
|
13193
|
+
function paintedCopy(source, root) {
|
|
13194
|
+
const copy = source.cloneNode(true);
|
|
13195
|
+
const sources = [source, ...source.querySelectorAll("*")];
|
|
13196
|
+
const copies = [copy, ...copy.querySelectorAll("*")];
|
|
13197
|
+
sources.forEach((element, i) => {
|
|
13198
|
+
const target = copies[i];
|
|
13199
|
+
target.removeAttribute("id");
|
|
13200
|
+
const computed = element.ownerDocument.defaultView?.getComputedStyle?.(element);
|
|
13201
|
+
const styles = {};
|
|
13202
|
+
for (const property of INHERITED) styles[property] = drawnStyle(element, root, property) || void 0;
|
|
13203
|
+
for (const [property, initial] of Object.entries(OWN)) {
|
|
13204
|
+
const value = computed?.getPropertyValue(property).trim();
|
|
13205
|
+
if (value && value !== initial) styles[property] = value;
|
|
13206
|
+
}
|
|
13207
|
+
setStyles(target, styles);
|
|
13208
|
+
});
|
|
13209
|
+
return copy;
|
|
13210
|
+
}
|
|
13211
|
+
function cornersOf(element) {
|
|
13212
|
+
try {
|
|
13213
|
+
const box = element.getBBox?.();
|
|
13214
|
+
if (box) return [
|
|
13215
|
+
{
|
|
13216
|
+
x: box.x,
|
|
13217
|
+
y: box.y
|
|
13218
|
+
},
|
|
13219
|
+
{
|
|
13220
|
+
x: box.x + box.width,
|
|
13221
|
+
y: box.y
|
|
13222
|
+
},
|
|
13223
|
+
{
|
|
13224
|
+
x: box.x,
|
|
13225
|
+
y: box.y + box.height
|
|
13226
|
+
},
|
|
13227
|
+
{
|
|
13228
|
+
x: box.x + box.width,
|
|
13229
|
+
y: box.y + box.height
|
|
13230
|
+
}
|
|
13231
|
+
];
|
|
13232
|
+
} catch {}
|
|
13233
|
+
return [{
|
|
13234
|
+
x: 0,
|
|
13235
|
+
y: 0
|
|
13236
|
+
}];
|
|
12969
13237
|
}
|
|
13238
|
+
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) && [
|
|
13239
|
+
0,
|
|
13240
|
+
1,
|
|
13241
|
+
2,
|
|
13242
|
+
3
|
|
13243
|
+
].every((i) => Math.abs(a.place[i] - b.place[i]) <= 1e-4);
|
|
12970
13244
|
function moveLabel(a, b) {
|
|
12971
13245
|
return (s) => {
|
|
12972
13246
|
const x = mix$1(a.at.x, b.at.x, s);
|
|
@@ -12999,6 +13273,8 @@ function fadeLabel(label, opacity) {
|
|
|
12999
13273
|
}
|
|
13000
13274
|
const fadeOut = (s) => 1 - clamp$1(s / HALF);
|
|
13001
13275
|
const fadeIn = (s) => clamp$1((s - HALF) / .5);
|
|
13276
|
+
const othersOut = (s) => 1 - clamp$1(s / OUT_BY);
|
|
13277
|
+
const othersIn = fadeIn;
|
|
13002
13278
|
const clamp$1 = (value) => Math.min(1, Math.max(0, value));
|
|
13003
13279
|
const mix$1 = (x, y, s) => x * (1 - s) + y * s;
|
|
13004
13280
|
function paintOf(view, mark) {
|
|
@@ -13032,41 +13308,7 @@ function placeDot(element, end) {
|
|
|
13032
13308
|
"stroke-width": end.ring
|
|
13033
13309
|
});
|
|
13034
13310
|
}
|
|
13035
|
-
const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
13036
13311
|
const scaleOf = (m) => Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]));
|
|
13037
|
-
function mapMark(mark, m) {
|
|
13038
|
-
if (isIdentity(m)) return mark;
|
|
13039
|
-
const point = (p) => matrix.apply(m, p);
|
|
13040
|
-
const path = (d) => formatPath(transformPath(parsePath(d), m));
|
|
13041
|
-
const scale = scaleOf(m);
|
|
13042
|
-
const { outline } = mark;
|
|
13043
|
-
return {
|
|
13044
|
-
key: mark.key,
|
|
13045
|
-
...mark.series === void 0 ? {} : { series: mark.series },
|
|
13046
|
-
start: point(mark.start),
|
|
13047
|
-
end: point(mark.end),
|
|
13048
|
-
length: mark.length * scale,
|
|
13049
|
-
path: (t) => point(mark.path(t)),
|
|
13050
|
-
angle: (t) => {
|
|
13051
|
-
const angle = mark.angle(t);
|
|
13052
|
-
const cos = Math.cos(angle);
|
|
13053
|
-
const sin = Math.sin(angle);
|
|
13054
|
-
return Math.atan2(m[1] * cos + m[3] * sin, m[0] * cos + m[2] * sin);
|
|
13055
|
-
},
|
|
13056
|
-
slice: (t0, t1) => path(mark.slice(t0, t1)),
|
|
13057
|
-
...mark.gaps === void 0 ? {} : { gaps: mark.gaps },
|
|
13058
|
-
thickness: mark.thickness * scale,
|
|
13059
|
-
outline: {
|
|
13060
|
-
d: path(outline.d),
|
|
13061
|
-
closed: outline.closed,
|
|
13062
|
-
sample: (n) => outline.sample(n).map(point)
|
|
13063
|
-
},
|
|
13064
|
-
bounds: boxIn(m, mark.bounds),
|
|
13065
|
-
center: point(mark.center),
|
|
13066
|
-
pivot: point(mark.pivot),
|
|
13067
|
-
...mark.segments === void 0 ? {} : { segments: mark.segments.map((segment) => mapMark(segment, m)) }
|
|
13068
|
-
};
|
|
13069
|
-
}
|
|
13070
13312
|
function deferred() {
|
|
13071
13313
|
let settle;
|
|
13072
13314
|
return {
|
|
@@ -13815,9 +14057,9 @@ function captionPlace(mark, text) {
|
|
|
13815
14057
|
return past(mark.end, heading, PAST_END, own, boxes, text);
|
|
13816
14058
|
}
|
|
13817
14059
|
function past(from, toward, least, own, boxes, text) {
|
|
13818
|
-
if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -
|
|
14060
|
+
if (!text) return placed$1(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -1e400));
|
|
13819
14061
|
const { x, y, width, height } = text.box(placed$1(from, toward, 0));
|
|
13820
|
-
return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -
|
|
14062
|
+
return placed$1(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -1e400), boxes, {
|
|
13821
14063
|
x: x - from.x,
|
|
13822
14064
|
y: y - from.y,
|
|
13823
14065
|
width,
|
|
@@ -13841,7 +14083,7 @@ function clearOf(from, toward, distance, boxes, reach, held) {
|
|
|
13841
14083
|
const within = meets(near);
|
|
13842
14084
|
if (!band || !within) return within;
|
|
13843
14085
|
const leaving = across ? Math.max(band[1], ((sin > 0 ? near.y + near.height : near.y) - from.y) / sin) : band[1];
|
|
13844
|
-
return [within[0], Math.max(leaving, meets(box)?.[1] ?? -
|
|
14086
|
+
return [within[0], Math.max(leaving, meets(box)?.[1] ?? -1e400)];
|
|
13845
14087
|
});
|
|
13846
14088
|
let at = distance;
|
|
13847
14089
|
for (let moved = true; moved;) {
|
|
@@ -13895,7 +14137,7 @@ function leaves(from, cos, sin, box) {
|
|
|
13895
14137
|
}
|
|
13896
14138
|
function span(from, cos, sin, box) {
|
|
13897
14139
|
let near = 0;
|
|
13898
|
-
let far =
|
|
14140
|
+
let far = 1e400;
|
|
13899
14141
|
for (const [origin, step, lo, hi] of [[
|
|
13900
14142
|
from.x,
|
|
13901
14143
|
cos,
|
|
@@ -14487,8 +14729,8 @@ function bandOf(outline) {
|
|
|
14487
14729
|
ring.push(segment.to);
|
|
14488
14730
|
}
|
|
14489
14731
|
if (areaOf(ring) < 0) ring.reverse();
|
|
14490
|
-
const left = ring.reduce((x, point) => Math.min(x, point.x),
|
|
14491
|
-
const right = ring.reduce((x, point) => Math.max(x, point.x), -
|
|
14732
|
+
const left = ring.reduce((x, point) => Math.min(x, point.x), 1e400);
|
|
14733
|
+
const right = ring.reduce((x, point) => Math.max(x, point.x), -1e400);
|
|
14492
14734
|
if (!(right - left > 2 * SAME_X)) return void 0;
|
|
14493
14735
|
const atLeft = (point) => point.x - left <= SAME_X;
|
|
14494
14736
|
const atRight = (point) => right - point.x <= SAME_X;
|
|
@@ -14605,7 +14847,7 @@ function landing(hole, own, other, area) {
|
|
|
14605
14847
|
}
|
|
14606
14848
|
function depth(point, area) {
|
|
14607
14849
|
if (windingAt(point, area) === 0) return 0;
|
|
14608
|
-
let nearest =
|
|
14850
|
+
let nearest = 1e400;
|
|
14609
14851
|
for (const ring of area) ring.forEach((p, i) => {
|
|
14610
14852
|
const q = ring[(i + 1) % ring.length];
|
|
14611
14853
|
const dx = q.x - p.x;
|
|
@@ -15314,7 +15556,7 @@ function configure(options) {
|
|
|
15314
15556
|
}
|
|
15315
15557
|
}
|
|
15316
15558
|
// src/index.ts
|
|
15317
|
-
const VERSION = "0.
|
|
15559
|
+
const VERSION = "0.12.0";
|
|
15318
15560
|
const env = {
|
|
15319
15561
|
presets: presetRegistry,
|
|
15320
15562
|
icons: iconRegistry,
|