expressive-charts 0.4.0 → 0.6.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 +65 -1
- package/README.md +7 -7
- package/dist/{drawing-Dz_IvJPB.d.ts → drawing-Ypmq-2h6.d.cts} +7 -1
- package/dist/{drawing-Dz_IvJPB.d.cts → drawing-Ypmq-2h6.d.ts} +7 -1
- package/dist/{effect-uYC8Vs6_.d.cts → effect-D8W4ZmmG.d.cts} +28 -4
- package/dist/{effect-CdH5449m.d.ts → effect-DyzluQD1.d.ts} +28 -4
- package/dist/expressive-charts.css +3 -2
- package/dist/expressive-charts.global.js +13 -12
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.d.cts +1 -1
- package/dist/icons/sport.d.ts +1 -1
- package/dist/index.cjs +1421 -228
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -15
- package/dist/index.d.ts +93 -15
- package/dist/index.js +1326 -205
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +64 -16
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +12 -3
- package/dist/testing.d.ts +12 -3
- package/dist/testing.js +20 -3
- package/dist/testing.js.map +1 -1
- package/dist/{transition-DSRt2DH3.js → transition-romki_A6.js} +98 -26
- package/dist/transition-romki_A6.js.map +1 -0
- package/package.json +2 -2
- package/dist/transition-DSRt2DH3.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { d as normalizeAngle, n as formatNumber } from "./path-data-DnEckjY8.js";
|
|
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-romki_A6.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-DnEckjY8.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;
|
|
@@ -397,7 +397,7 @@ function offset(point, angle, distance) {
|
|
|
397
397
|
// src/core/geometry/samples.ts
|
|
398
398
|
const MAX_GRID = 4096;
|
|
399
399
|
const REFINE = 48;
|
|
400
|
-
const GOLDEN = (Math.sqrt(5) - 1) / 2;
|
|
400
|
+
const GOLDEN = /* @__PURE__ */ (() => (Math.sqrt(5) - 1) / 2)();
|
|
401
401
|
function samplesAlong(mark, points) {
|
|
402
402
|
if (typeof mark !== "object" || mark === null || typeof mark.path !== "function" || !Number.isFinite(mark.length)) throw new TypeError("samplesAlong needs a MarkGeometry, as describe builds it.");
|
|
403
403
|
if (!Array.isArray(points)) throw new TypeError("samplesAlong needs an array of points { x, y, value, at? }.");
|
|
@@ -421,9 +421,9 @@ function samplesAlong(mark, points) {
|
|
|
421
421
|
...p.at === void 0 ? {} : { at: p.at }
|
|
422
422
|
}
|
|
423
423
|
})).sort((a, b) => a.sample.t - b.sample.t || a.index - b.index).map(({ sample }) => sample);
|
|
424
|
-
return mark.gaps && mark.gaps.length > 0 ? gapped(samples, mark.gaps) : samples;
|
|
424
|
+
return mark.gaps && mark.gaps.length > 0 ? gapped$1(samples, mark.gaps) : samples;
|
|
425
425
|
}
|
|
426
|
-
function gapped(samples, gaps) {
|
|
426
|
+
function gapped$1(samples, gaps) {
|
|
427
427
|
const middles = gaps.map(([from, to]) => (from + to) / 2).sort((a, b) => a - b);
|
|
428
428
|
let next = 0;
|
|
429
429
|
return samples.map((sample, k) => {
|
|
@@ -555,16 +555,8 @@ function linear$1(value) {
|
|
|
555
555
|
return rounded === 0 ? "0" : String(rounded);
|
|
556
556
|
}
|
|
557
557
|
// src/charts/render/text.ts
|
|
558
|
-
const ASCENT$1 = 1.05;
|
|
559
|
-
const SIDE = .16;
|
|
560
558
|
function textBox(placement, measure, className, size) {
|
|
561
|
-
|
|
562
|
-
return {
|
|
563
|
-
x: (placement.anchor === "start" ? placement.x : placement.anchor === "end" ? placement.x - width : placement.x - width / 2) - SIDE * size,
|
|
564
|
-
y: placement.y - ASCENT$1 * size,
|
|
565
|
-
width: width + 2 * SIDE * size,
|
|
566
|
-
height: 1.3 * size
|
|
567
|
-
};
|
|
559
|
+
return boxAround(placement, placement.anchor, measure(placement.text.replace(/\d/g, "0"), className, size), size);
|
|
568
560
|
}
|
|
569
561
|
function placeText(element, placement) {
|
|
570
562
|
setAttributes(element, {
|
|
@@ -574,7 +566,6 @@ function placeText(element, placement) {
|
|
|
574
566
|
});
|
|
575
567
|
if (element.textContent !== placement.text) element.textContent = placement.text;
|
|
576
568
|
}
|
|
577
|
-
const AVERAGE_WIDTH = .6;
|
|
578
569
|
function textMeasure(svg) {
|
|
579
570
|
const cache = /* @__PURE__ */ new Map();
|
|
580
571
|
const measure = (text, className, size) => {
|
|
@@ -966,7 +957,8 @@ function verticalFrame(input, rows, domain, _values, ticks) {
|
|
|
966
957
|
const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
|
|
967
958
|
const { positive, negative } = reach(input, rows);
|
|
968
959
|
const top = (domain.hi > 0 ? 20.5 : TOP$1) + positive;
|
|
969
|
-
const
|
|
960
|
+
const values = domain.lo < 0 ? 18.5 : 0;
|
|
961
|
+
const bottom = AXIS$1 + values + negative;
|
|
970
962
|
const left = tickWidth + 8 + 2;
|
|
971
963
|
const plot = {
|
|
972
964
|
x: left,
|
|
@@ -983,7 +975,7 @@ function verticalFrame(input, rows, domain, _values, ticks) {
|
|
|
983
975
|
hi: domain.hi,
|
|
984
976
|
from: base,
|
|
985
977
|
extent: -plot.height,
|
|
986
|
-
label: base + 18
|
|
978
|
+
label: base + values + 18
|
|
987
979
|
},
|
|
988
980
|
bands: {
|
|
989
981
|
start: plot.x,
|
|
@@ -1111,7 +1103,7 @@ const COLOR_TOKENS = [
|
|
|
1111
1103
|
"focus",
|
|
1112
1104
|
"negative"
|
|
1113
1105
|
];
|
|
1114
|
-
const TOKENS = Object.fromEntries(COLOR_TOKENS.map((name) => [name, themes.light[name]]));
|
|
1106
|
+
const TOKENS = /* @__PURE__ */ Object.fromEntries(/* @__PURE__ */ COLOR_TOKENS.map((name) => [name, themes.light[name]]));
|
|
1115
1107
|
function seriesColors(slot) {
|
|
1116
1108
|
const n = (Math.max(1, Math.floor(slot)) - 1) % 8 + 1;
|
|
1117
1109
|
const [color, strong] = themes.light.series[n - 1];
|
|
@@ -1147,8 +1139,7 @@ function declarations(theme, indent) {
|
|
|
1147
1139
|
theme.series.forEach(([color, strong], i) => lines.push(`--ec-series-${i + 1}: ${color};`, `--ec-series-${i + 1}-strong: ${strong};`));
|
|
1148
1140
|
return lines.map((line) => indent + line).join("\n");
|
|
1149
1141
|
}
|
|
1150
|
-
const
|
|
1151
|
-
${`:where(:root, [data-theme="light"]) {
|
|
1142
|
+
const TOKEN_RULES = /* @__PURE__ */ (() => `:where(:root, [data-theme="light"]) {
|
|
1152
1143
|
${declarations(themes.light, " ")}
|
|
1153
1144
|
}
|
|
1154
1145
|
@media (prefers-color-scheme: dark) {
|
|
@@ -1158,7 +1149,9 @@ ${declarations(themes.dark, " ")}
|
|
|
1158
1149
|
}
|
|
1159
1150
|
:where([data-theme="dark"]) {
|
|
1160
1151
|
${declarations(themes.dark, " ")}
|
|
1161
|
-
}`
|
|
1152
|
+
}`)();
|
|
1153
|
+
const STYLES = /* @__PURE__ */ (() => `/* expressive-charts: theme tokens and default styles. Every rule has zero specificity, so your CSS wins. */
|
|
1154
|
+
${TOKEN_RULES}
|
|
1162
1155
|
:where(.ec-chart) { display: block; max-width: 100%; height: auto; overflow: visible; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
|
|
1163
1156
|
:where(.ec-chart text) { font-variant-numeric: tabular-nums; }
|
|
1164
1157
|
:where(.ec-chart .ec-gridline) { stroke: var(--ec-grid, ${TOKENS.grid}); stroke-width: 1; }
|
|
@@ -1177,18 +1170,19 @@ ${declarations(themes.dark, " ")}
|
|
|
1177
1170
|
:where(.ec-chart .ec-hot .ec-segment) { fill: var(--ec-mark-strong); }
|
|
1178
1171
|
:where(.ec-chart .ec-stroke) { fill: none; stroke: var(--ec-mark); stroke-linejoin: round; transition: stroke var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
1179
1172
|
:where(.ec-chart .ec-hot .ec-stroke) { stroke: var(--ec-mark-strong); }
|
|
1180
|
-
:where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
|
|
1173
|
+
:where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
1181
1174
|
:where(.ec-chart .ec-dot) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; opacity: 0; transition: opacity var(--ec-hover-duration, 100ms) ease-out, fill var(--ec-hover-duration, 100ms) ease-out; }
|
|
1182
1175
|
:where(.ec-chart .ec-hot .ec-dot) { fill: var(--ec-mark-strong); opacity: 1; }
|
|
1183
1176
|
:where(.ec-chart .ec-alone .ec-dot) { opacity: 1; }
|
|
1184
1177
|
:where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
|
|
1185
|
-
:where(.ec-chart .ec-column:focus) { outline: none; }
|
|
1178
|
+
:where(.ec-chart .ec-column:focus, .ec-chart .ec-stop:focus) { outline: none; }
|
|
1186
1179
|
:where(.ec-chart .ec-lines, .ec-chart .ec-points) { pointer-events: none; }
|
|
1187
1180
|
:where(.ec-chart .ec-slice) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; stroke-linejoin: round; transition: fill var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
1188
1181
|
:where(.ec-chart .ec-hot .ec-slice) { fill: var(--ec-mark-strong); }
|
|
1189
1182
|
:where(.ec-chart .ec-center-value) { fill: var(--ec-text, ${TOKENS.text}); font-size: 26px; font-weight: 600; }
|
|
1190
1183
|
:where(.ec-chart .ec-center-label) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12.5px; }
|
|
1191
1184
|
:where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
|
|
1185
|
+
:where(.ec-chart.ec-hovering .ec-line:not(.ec-hot-line) > .ec-body > *, .ec-chart.ec-hovering .ec-alone:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
|
|
1192
1186
|
:where(.ec-hovering .ec-run:not(.ec-hot) > .ec-follow) { opacity: var(--ec-dim-opacity, 0.3); }
|
|
1193
1187
|
:where(.ec-follow) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
1194
1188
|
:where(.ec-chart.ec-morphing .ec-marks) { visibility: hidden; }
|
|
@@ -1234,7 +1228,7 @@ ${declarations(themes.dark, " ")}
|
|
|
1234
1228
|
:where(.ec-table thead th) { color: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12px; font-weight: 600; }
|
|
1235
1229
|
:where(.ec-table .ec-num) { text-align: right; }
|
|
1236
1230
|
:where(.ec-table-caption, .ec-visually-hidden) { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
|
|
1237
|
-
|
|
1231
|
+
`)();
|
|
1238
1232
|
const MARKER = "data-expressive-charts";
|
|
1239
1233
|
const styleOptions = {};
|
|
1240
1234
|
function injectStyles(doc) {
|
|
@@ -1780,6 +1774,7 @@ function styleText(element, style) {
|
|
|
1780
1774
|
// src/charts/render/surface.ts
|
|
1781
1775
|
function svgSurface(options) {
|
|
1782
1776
|
const { overlay } = options;
|
|
1777
|
+
const measure = options.measure ?? textMeasure(overlay);
|
|
1783
1778
|
const orders = /* @__PURE__ */ new WeakMap();
|
|
1784
1779
|
const groups = /* @__PURE__ */ new Map();
|
|
1785
1780
|
const hidden = /* @__PURE__ */ new Set();
|
|
@@ -1815,6 +1810,12 @@ function svgSurface(options) {
|
|
|
1815
1810
|
}
|
|
1816
1811
|
};
|
|
1817
1812
|
},
|
|
1813
|
+
box: (text, { at, anchor = "start" }) => textBox({
|
|
1814
|
+
x: at.x,
|
|
1815
|
+
y: at.y,
|
|
1816
|
+
anchor,
|
|
1817
|
+
text
|
|
1818
|
+
}, measure, "ec-text", TEXT_SIZE),
|
|
1818
1819
|
mark(key) {
|
|
1819
1820
|
const handle = options.mark(key);
|
|
1820
1821
|
return {
|
|
@@ -1910,13 +1911,13 @@ function decimals(value) {
|
|
|
1910
1911
|
const point = text.indexOf(".");
|
|
1911
1912
|
return point < 0 ? 0 : Math.min(6, text.length - point - 1);
|
|
1912
1913
|
}
|
|
1913
|
-
function round$
|
|
1914
|
+
function round$5(value, digits) {
|
|
1914
1915
|
const factor = 10 ** digits;
|
|
1915
1916
|
const rounded = Math.round(value * factor) / factor;
|
|
1916
1917
|
return rounded === 0 ? 0 : rounded;
|
|
1917
1918
|
}
|
|
1918
1919
|
function percent(share) {
|
|
1919
|
-
return `${round$
|
|
1920
|
+
return `${round$5(share * 100, 0)}%`;
|
|
1920
1921
|
}
|
|
1921
1922
|
// src/charts/interaction.ts
|
|
1922
1923
|
function pointerHover(svg, options) {
|
|
@@ -1926,7 +1927,9 @@ function pointerHover(svg, options) {
|
|
|
1926
1927
|
let held;
|
|
1927
1928
|
let watcher;
|
|
1928
1929
|
let still;
|
|
1930
|
+
let under;
|
|
1929
1931
|
const enter = (target, source) => {
|
|
1932
|
+
under = target?.key;
|
|
1930
1933
|
if (target?.key === current) return;
|
|
1931
1934
|
leave();
|
|
1932
1935
|
if (!target) return;
|
|
@@ -1951,8 +1954,15 @@ function pointerHover(svg, options) {
|
|
|
1951
1954
|
const arrive = (element, x, y) => {
|
|
1952
1955
|
const tip = tooltipHolding(element);
|
|
1953
1956
|
if (tip) hold(tip, x, y);
|
|
1954
|
-
else enter(element && svg.contains(element) ? options.find(element
|
|
1957
|
+
else enter(element && svg.contains(element) ? options.find(element, {
|
|
1958
|
+
x,
|
|
1959
|
+
y
|
|
1960
|
+
}) : void 0, "pointer");
|
|
1955
1961
|
};
|
|
1962
|
+
const at = (event) => options.find(event.target, {
|
|
1963
|
+
x: event.clientX,
|
|
1964
|
+
y: event.clientY
|
|
1965
|
+
});
|
|
1956
1966
|
const hold = (tip, x, y) => {
|
|
1957
1967
|
enter({ key: tip.key }, "pointer");
|
|
1958
1968
|
const element = tip.element;
|
|
@@ -2022,7 +2032,8 @@ function pointerHover(svg, options) {
|
|
|
2022
2032
|
const over = (event) => {
|
|
2023
2033
|
if (event.pointerType === "touch" || resting(event)) return;
|
|
2024
2034
|
letGo();
|
|
2025
|
-
|
|
2035
|
+
const target = at(event);
|
|
2036
|
+
if (!options.moves?.() || target?.key !== under) enter(target, "pointer");
|
|
2026
2037
|
};
|
|
2027
2038
|
const out = (event) => {
|
|
2028
2039
|
if (event.pointerType === "touch") return;
|
|
@@ -2030,13 +2041,17 @@ function pointerHover(svg, options) {
|
|
|
2030
2041
|
arrive(landing(event), event.clientX, event.clientY);
|
|
2031
2042
|
};
|
|
2032
2043
|
const move = (event) => {
|
|
2033
|
-
if (event.pointerType
|
|
2044
|
+
if (event.pointerType === "touch" || resting(event) || !options.moves?.()) return;
|
|
2045
|
+
const target = at(event);
|
|
2046
|
+
if (target?.key === under) return;
|
|
2047
|
+
letGo();
|
|
2048
|
+
enter(target, "pointer");
|
|
2034
2049
|
};
|
|
2035
2050
|
const down = (event) => {
|
|
2036
2051
|
lastPointer = event.pointerType;
|
|
2037
2052
|
};
|
|
2038
2053
|
const click = (event) => {
|
|
2039
|
-
if (lastPointer === "touch") enter(
|
|
2054
|
+
if (lastPointer === "touch") enter(at(event), "touch");
|
|
2040
2055
|
};
|
|
2041
2056
|
const elsewhere = (event) => {
|
|
2042
2057
|
if (current === void 0 || event.pointerType !== "touch") return;
|
|
@@ -2144,15 +2159,19 @@ function keyboardFocus(svg, options) {
|
|
|
2144
2159
|
if (key === void 0 || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
2145
2160
|
const keys = options.order();
|
|
2146
2161
|
const index = keys.indexOf(key);
|
|
2162
|
+
const moved = (press, fallback) => {
|
|
2163
|
+
const to = options.move?.(key, press);
|
|
2164
|
+
return to !== void 0 && keys.includes(to) ? to : fallback;
|
|
2165
|
+
};
|
|
2147
2166
|
let next;
|
|
2148
2167
|
switch (event.key) {
|
|
2149
2168
|
case "ArrowDown":
|
|
2150
2169
|
case "ArrowRight":
|
|
2151
|
-
next = keys[Math.min(keys.length - 1, index + 1)];
|
|
2170
|
+
next = moved(event.key, keys[Math.min(keys.length - 1, index + 1)]);
|
|
2152
2171
|
break;
|
|
2153
2172
|
case "ArrowUp":
|
|
2154
2173
|
case "ArrowLeft":
|
|
2155
|
-
next = keys[Math.max(0, index - 1)];
|
|
2174
|
+
next = moved(event.key, keys[Math.max(0, index - 1)]);
|
|
2156
2175
|
break;
|
|
2157
2176
|
case "PageDown":
|
|
2158
2177
|
case "PageUp": {
|
|
@@ -2162,10 +2181,10 @@ function keyboardFocus(svg, options) {
|
|
|
2162
2181
|
break;
|
|
2163
2182
|
}
|
|
2164
2183
|
case "Home":
|
|
2165
|
-
next = keys[0];
|
|
2184
|
+
next = moved(event.key, keys[0]);
|
|
2166
2185
|
break;
|
|
2167
2186
|
case "End":
|
|
2168
|
-
next = keys[keys.length - 1];
|
|
2187
|
+
next = moved(event.key, keys[keys.length - 1]);
|
|
2169
2188
|
break;
|
|
2170
2189
|
case "Escape":
|
|
2171
2190
|
if (options.escape(key)) event.preventDefault();
|
|
@@ -2229,6 +2248,28 @@ function keyboardFocus(svg, options) {
|
|
|
2229
2248
|
for (const key of gone) setTabIndex(key, void 0);
|
|
2230
2249
|
last = keys;
|
|
2231
2250
|
},
|
|
2251
|
+
retarget(to) {
|
|
2252
|
+
listen();
|
|
2253
|
+
const keys = options.order();
|
|
2254
|
+
const live = new Set(keys);
|
|
2255
|
+
const active = on?.scope.activeElement ?? null;
|
|
2256
|
+
const had = focused?.element === active ? focused.key : last.find((key) => options.element(key) === active);
|
|
2257
|
+
const from = had ?? tabStop;
|
|
2258
|
+
const moved = from === void 0 ? void 0 : to(from);
|
|
2259
|
+
tabStop = moved !== void 0 && live.has(moved) ? moved : keys[0];
|
|
2260
|
+
applyTabIndex(keys);
|
|
2261
|
+
if (had !== void 0) {
|
|
2262
|
+
current = tabStop;
|
|
2263
|
+
if (tabStop !== void 0) options.element(tabStop)?.focus();
|
|
2264
|
+
else {
|
|
2265
|
+
active.blur();
|
|
2266
|
+
focused = void 0;
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
for (const key of last) if (!live.has(key)) setTabIndex(key, void 0);
|
|
2270
|
+
last = keys;
|
|
2271
|
+
return had === void 0 ? void 0 : current;
|
|
2272
|
+
},
|
|
2232
2273
|
destroy() {
|
|
2233
2274
|
current = void 0;
|
|
2234
2275
|
focused = void 0;
|
|
@@ -2337,6 +2378,7 @@ function chartHover(options) {
|
|
|
2337
2378
|
const within = (target, key) => key === target || options.live(target) && marksOf(target).includes(key);
|
|
2338
2379
|
const interaction = pointerHover(svg, {
|
|
2339
2380
|
find: options.find,
|
|
2381
|
+
moves: () => options.moves?.() ?? false,
|
|
2340
2382
|
hover(target, source) {
|
|
2341
2383
|
if (!options.live(target.key) || own(hovered) && hovered.keys[0] === target.key) return;
|
|
2342
2384
|
endHover();
|
|
@@ -2354,6 +2396,7 @@ function chartHover(options) {
|
|
|
2354
2396
|
find: (eventTarget) => options.find(eventTarget)?.key,
|
|
2355
2397
|
order: options.order,
|
|
2356
2398
|
page: (key, by) => options.page?.(key, by),
|
|
2399
|
+
move: (key, press) => options.move?.(key, press),
|
|
2357
2400
|
element: options.element,
|
|
2358
2401
|
focus(key, visible) {
|
|
2359
2402
|
ringKey = visible ? key : void 0;
|
|
@@ -2473,6 +2516,14 @@ function chartHover(options) {
|
|
|
2473
2516
|
});
|
|
2474
2517
|
},
|
|
2475
2518
|
sync: () => keyboard.sync(),
|
|
2519
|
+
retarget(to) {
|
|
2520
|
+
const key = keyboard.retarget(to);
|
|
2521
|
+
if (ringKey !== void 0) {
|
|
2522
|
+
ringKey = key;
|
|
2523
|
+
options.ring(ringKey);
|
|
2524
|
+
}
|
|
2525
|
+
linked?.shown();
|
|
2526
|
+
},
|
|
2476
2527
|
focus(key) {
|
|
2477
2528
|
if (options.live(key)) keyboard.focus(key);
|
|
2478
2529
|
},
|
|
@@ -2978,8 +3029,9 @@ function geometryChanged$1(from, to) {
|
|
|
2978
3029
|
return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
|
|
2979
3030
|
}
|
|
2980
3031
|
function labelsMoved(from, to) {
|
|
2981
|
-
|
|
2982
|
-
|
|
3032
|
+
return boxesMoved(from.labelBounds, to.labelBounds) || boxesMoved(from.nearbyLabels, to.nearbyLabels);
|
|
3033
|
+
}
|
|
3034
|
+
function boxesMoved(a, b) {
|
|
2983
3035
|
if (a === b) return false;
|
|
2984
3036
|
if (!a || !b || a.length !== b.length) return true;
|
|
2985
3037
|
return a.some((box, i) => box.x !== b[i].x || box.y !== b[i].y || box.width !== b[i].width || box.height !== b[i].height);
|
|
@@ -3095,7 +3147,7 @@ function chartTooltip(svg, options) {
|
|
|
3095
3147
|
const option = options.option();
|
|
3096
3148
|
const known = texts.get(row);
|
|
3097
3149
|
if (known && known.option === option) return known.content;
|
|
3098
|
-
const content = text(option, row.datum, summary);
|
|
3150
|
+
const content = text(option, row.datum, summary, row.series);
|
|
3099
3151
|
texts.set(row, {
|
|
3100
3152
|
option,
|
|
3101
3153
|
content
|
|
@@ -3155,7 +3207,7 @@ function chartTooltip(svg, options) {
|
|
|
3155
3207
|
top: dy + near.top,
|
|
3156
3208
|
bottom: dy + near.bottom
|
|
3157
3209
|
};
|
|
3158
|
-
shape = span(bridge, {
|
|
3210
|
+
shape = span$1(bridge, {
|
|
3159
3211
|
left,
|
|
3160
3212
|
top,
|
|
3161
3213
|
...size
|
|
@@ -3254,7 +3306,7 @@ function inside$1({ top, bottom, upper, lower }, x, y) {
|
|
|
3254
3306
|
const t = (y - top) / (bottom - top);
|
|
3255
3307
|
return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
|
|
3256
3308
|
}
|
|
3257
|
-
function span(bridge, box, mark, side) {
|
|
3309
|
+
function span$1(bridge, box, mark, side) {
|
|
3258
3310
|
bridge.hidden = mark === void 0;
|
|
3259
3311
|
if (!mark) return void 0;
|
|
3260
3312
|
const edge = {
|
|
@@ -3264,13 +3316,13 @@ function span(bridge, box, mark, side) {
|
|
|
3264
3316
|
const [upper, lower, top, bottom] = side === "above" ? [
|
|
3265
3317
|
edge,
|
|
3266
3318
|
mark,
|
|
3267
|
-
box.top + box.height,
|
|
3319
|
+
box.top + box.height - OVERLAP,
|
|
3268
3320
|
Math.round(mark.top + OVERLAP)
|
|
3269
3321
|
] : [
|
|
3270
3322
|
mark,
|
|
3271
3323
|
edge,
|
|
3272
3324
|
Math.round(mark.bottom - OVERLAP),
|
|
3273
|
-
box.top
|
|
3325
|
+
box.top + OVERLAP
|
|
3274
3326
|
];
|
|
3275
3327
|
const left = Math.round(Math.min(upper.left, lower.left));
|
|
3276
3328
|
const width = Math.round(Math.max(upper.right, lower.right)) - left;
|
|
@@ -3292,11 +3344,11 @@ function span(bridge, box, mark, side) {
|
|
|
3292
3344
|
lower: round(lower)
|
|
3293
3345
|
};
|
|
3294
3346
|
}
|
|
3295
|
-
function text(option, datum, summary) {
|
|
3347
|
+
function text(option, datum, summary, series) {
|
|
3296
3348
|
if (option === false) return void 0;
|
|
3297
3349
|
if (typeof option !== "function") return summary();
|
|
3298
3350
|
try {
|
|
3299
|
-
const result = option(datum);
|
|
3351
|
+
const result = series === void 0 ? option(datum) : option(datum, { series });
|
|
3300
3352
|
return result === void 0 || result === null || result === "" ? void 0 : String(result);
|
|
3301
3353
|
} catch (error) {
|
|
3302
3354
|
report(error);
|
|
@@ -3395,6 +3447,7 @@ function barChart$1(target, options, env) {
|
|
|
3395
3447
|
const find = (key) => records.get(key) ?? leaving.get(key);
|
|
3396
3448
|
const surface = svgSurface({
|
|
3397
3449
|
overlay,
|
|
3450
|
+
measure,
|
|
3398
3451
|
mark: (key) => ({
|
|
3399
3452
|
set: (style) => {
|
|
3400
3453
|
find(key)?.handle.set(style);
|
|
@@ -3647,7 +3700,7 @@ function barChart$1(target, options, env) {
|
|
|
3647
3700
|
value: now[series] ?? 0
|
|
3648
3701
|
}));
|
|
3649
3702
|
const total = values.reduce((sum, v) => sum + v.value, 0);
|
|
3650
|
-
const text = record.count === void 0 ? row.value.text : format(current)(round$
|
|
3703
|
+
const text = record.count === void 0 ? row.value.text : format(current)(round$5(total, record.count));
|
|
3651
3704
|
return placeRow(frame, {
|
|
3652
3705
|
key: row.key,
|
|
3653
3706
|
datum: row.datum,
|
|
@@ -3952,6 +4005,14 @@ function barChart$1(target, options, env) {
|
|
|
3952
4005
|
if (!destroyed) hover.leave();
|
|
3953
4006
|
},
|
|
3954
4007
|
labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.shown.label, record.label), ...chartLabel(record.key, "value", record.shown.value, record.value)]),
|
|
4008
|
+
paintOf(key) {
|
|
4009
|
+
const record = records.get(key);
|
|
4010
|
+
const first = record?.shown.geometry.segments?.[0];
|
|
4011
|
+
return record && {
|
|
4012
|
+
color: byCategory(current) ? key : first?.series ?? first?.key ?? key,
|
|
4013
|
+
drawn: true
|
|
4014
|
+
};
|
|
4015
|
+
},
|
|
3955
4016
|
destroy() {
|
|
3956
4017
|
if (destroyed) return;
|
|
3957
4018
|
destroyed = true;
|
|
@@ -4101,7 +4162,7 @@ function layoutDonut(input) {
|
|
|
4101
4162
|
return {
|
|
4102
4163
|
frame,
|
|
4103
4164
|
total,
|
|
4104
|
-
slices:
|
|
4165
|
+
slices: placeSlices(frame, states, labels, input.measure),
|
|
4105
4166
|
labels,
|
|
4106
4167
|
centerText,
|
|
4107
4168
|
center: placeCenter(frame, centerText, input.measure)
|
|
@@ -4116,7 +4177,11 @@ function joinedStarts(values) {
|
|
|
4116
4177
|
return start;
|
|
4117
4178
|
});
|
|
4118
4179
|
}
|
|
4119
|
-
function
|
|
4180
|
+
function placeSlices(frame, states, labels, measure) {
|
|
4181
|
+
const boxes = labels.map((label) => label ? labelBoxes(label, measure) : []);
|
|
4182
|
+
return states.map((state, i) => placeSlice(frame, state, labels[i], measure, boxes.flatMap((box, j) => j === i ? [] : box)));
|
|
4183
|
+
}
|
|
4184
|
+
function placeSlice(frame, state, label, measure, nearby) {
|
|
4120
4185
|
const geometry = describeArc({
|
|
4121
4186
|
key: state.key,
|
|
4122
4187
|
series: state.series,
|
|
@@ -4126,7 +4191,8 @@ function placeSlice(frame, state, label, measure) {
|
|
|
4126
4191
|
outer: frame.outer,
|
|
4127
4192
|
start: state.start,
|
|
4128
4193
|
end: state.end,
|
|
4129
|
-
labelBounds: label && measure ? labelBoxes(label, measure) : []
|
|
4194
|
+
labelBounds: label && measure ? labelBoxes(label, measure) : [],
|
|
4195
|
+
...nearby ? { nearbyLabels: nearby } : {}
|
|
4130
4196
|
});
|
|
4131
4197
|
return {
|
|
4132
4198
|
...state,
|
|
@@ -4329,6 +4395,7 @@ function donutChart$1(target, options, env) {
|
|
|
4329
4395
|
const find = (key) => records.get(key) ?? leaving.get(key);
|
|
4330
4396
|
const surface = svgSurface({
|
|
4331
4397
|
overlay: runs,
|
|
4398
|
+
measure,
|
|
4332
4399
|
mark: (key) => ({
|
|
4333
4400
|
set: (style) => {
|
|
4334
4401
|
find(key)?.handle.set(style);
|
|
@@ -4617,9 +4684,10 @@ function donutChart$1(target, options, env) {
|
|
|
4617
4684
|
};
|
|
4618
4685
|
});
|
|
4619
4686
|
const labels = placeLabels(f, now.map(({ state }) => state), measure);
|
|
4620
|
-
|
|
4687
|
+
const slices = placeSlices(f, now.map(({ state }) => state), labels, measure);
|
|
4688
|
+
return now.map(({ record }, i) => ({
|
|
4621
4689
|
record,
|
|
4622
|
-
slice:
|
|
4690
|
+
slice: slices[i],
|
|
4623
4691
|
label: labels[i]
|
|
4624
4692
|
}));
|
|
4625
4693
|
}
|
|
@@ -4631,7 +4699,7 @@ function donutChart$1(target, options, env) {
|
|
|
4631
4699
|
const slices = currentSlices(f);
|
|
4632
4700
|
for (const { record, slice, label } of slices) show(record, slice, label);
|
|
4633
4701
|
const total = slices.reduce((sum, { slice }) => sum + slice.value, 0);
|
|
4634
|
-
drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$
|
|
4702
|
+
drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round$5(total, count)), measure));
|
|
4635
4703
|
}
|
|
4636
4704
|
function counting(total) {
|
|
4637
4705
|
if (counted?.total !== total) counted = {
|
|
@@ -4905,6 +4973,10 @@ function donutChart$1(target, options, env) {
|
|
|
4905
4973
|
if (!destroyed) hover.leave();
|
|
4906
4974
|
},
|
|
4907
4975
|
labels: () => order.flatMap((record) => [...chartLabel(record.key, "category", record.drawnLabel?.category, record.label), ...chartLabel(record.key, "value", record.drawnLabel?.share, record.share)]),
|
|
4976
|
+
paintOf: (key) => records.has(key) ? {
|
|
4977
|
+
color: key,
|
|
4978
|
+
drawn: true
|
|
4979
|
+
} : void 0,
|
|
4908
4980
|
destroy() {
|
|
4909
4981
|
if (destroyed) return;
|
|
4910
4982
|
destroyed = true;
|
|
@@ -5012,6 +5084,165 @@ function mergeRing(shown, next) {
|
|
|
5012
5084
|
});
|
|
5013
5085
|
return out;
|
|
5014
5086
|
}
|
|
5087
|
+
// src/charts/curve.ts
|
|
5088
|
+
const CURVES = ["linear", "monotone"];
|
|
5089
|
+
function bendOf(curve) {
|
|
5090
|
+
return curve === "monotone" ? 1 : 0;
|
|
5091
|
+
}
|
|
5092
|
+
function lineCurve(xs, values, amount, scales, presence) {
|
|
5093
|
+
const knotOf = new Int32Array(xs.length).fill(-1);
|
|
5094
|
+
const kx = [];
|
|
5095
|
+
const kv = [];
|
|
5096
|
+
const run = [];
|
|
5097
|
+
const kp = [];
|
|
5098
|
+
let runs = 0;
|
|
5099
|
+
let joined = false;
|
|
5100
|
+
for (let i = 0; i < xs.length; i++) {
|
|
5101
|
+
const value = values[i];
|
|
5102
|
+
if (value === void 0) {
|
|
5103
|
+
joined = false;
|
|
5104
|
+
continue;
|
|
5105
|
+
}
|
|
5106
|
+
const k = kx.length - 1;
|
|
5107
|
+
if (joined && xs[i] === kx[k] && value === kv[k]) {
|
|
5108
|
+
knotOf[i] = k;
|
|
5109
|
+
kp[k] = Math.max(kp[k], presence?.[i] ?? 1);
|
|
5110
|
+
continue;
|
|
5111
|
+
}
|
|
5112
|
+
if (!joined || xs[i] === kx[k]) runs++;
|
|
5113
|
+
kx.push(xs[i]);
|
|
5114
|
+
kv.push(value);
|
|
5115
|
+
run.push(runs);
|
|
5116
|
+
kp.push(presence?.[i] ?? 1);
|
|
5117
|
+
knotOf[i] = k + 1;
|
|
5118
|
+
joined = true;
|
|
5119
|
+
}
|
|
5120
|
+
const tangents = amount > 0 ? new Float64Array(kx.length) : void 0;
|
|
5121
|
+
if (tangents) for (let start = 0; start < kx.length;) {
|
|
5122
|
+
let end = start + 1;
|
|
5123
|
+
while (end < kx.length && run[end] === run[start]) end++;
|
|
5124
|
+
monotoneTangents(kx, kv, start, end, tangents);
|
|
5125
|
+
if (presence) fade(kx, kv, kp, start, end, tangents);
|
|
5126
|
+
start = end;
|
|
5127
|
+
}
|
|
5128
|
+
const piece = (from, to) => {
|
|
5129
|
+
const k = knotOf[from];
|
|
5130
|
+
if (k < 0 || knotOf[to] !== k + 1 || run[k + 1] !== run[k]) return void 0;
|
|
5131
|
+
const h = kx[k + 1] - kx[k];
|
|
5132
|
+
const v0 = kv[k];
|
|
5133
|
+
const v1 = kv[k + 1];
|
|
5134
|
+
const slope = (v1 - v0) / h;
|
|
5135
|
+
const [lo, hi] = slope < 0 ? [3 * slope, 0] : [0, 3 * slope];
|
|
5136
|
+
const ease = (tangent) => Math.min(hi, Math.max(lo, amount === 1 ? tangent : slope + amount * (tangent - slope)));
|
|
5137
|
+
const a = tangents ? ease(tangents[k]) : slope;
|
|
5138
|
+
const b = tangents ? ease(tangents[k + 1]) : slope;
|
|
5139
|
+
return [
|
|
5140
|
+
v0,
|
|
5141
|
+
v0 + h * a / 3,
|
|
5142
|
+
v1 - h * b / 3,
|
|
5143
|
+
v1,
|
|
5144
|
+
k
|
|
5145
|
+
];
|
|
5146
|
+
};
|
|
5147
|
+
return {
|
|
5148
|
+
between(from, to, through = Infinity) {
|
|
5149
|
+
const p = piece(from, to);
|
|
5150
|
+
if (!p || !tangents) return [];
|
|
5151
|
+
const [v0, c1, c2, v1, k] = p;
|
|
5152
|
+
const x0 = kx[k];
|
|
5153
|
+
const h = kx[k + 1] - x0;
|
|
5154
|
+
const left = scales.x(x0);
|
|
5155
|
+
const right = scales.x(kx[k + 1]);
|
|
5156
|
+
const n = Math.min(cubicPieces({
|
|
5157
|
+
x: left,
|
|
5158
|
+
y: scales.y(v0)
|
|
5159
|
+
}, {
|
|
5160
|
+
x: left + (right - left) / 3,
|
|
5161
|
+
y: scales.y(c1)
|
|
5162
|
+
}, {
|
|
5163
|
+
x: right - (right - left) / 3,
|
|
5164
|
+
y: scales.y(c2)
|
|
5165
|
+
}, {
|
|
5166
|
+
x: right,
|
|
5167
|
+
y: scales.y(v1)
|
|
5168
|
+
}), Math.max(1, Math.ceil(Math.abs(right - left) / FLAT)));
|
|
5169
|
+
const bends = [];
|
|
5170
|
+
for (let j = 1; j < n; j++) {
|
|
5171
|
+
const x = x0 + j / n * h;
|
|
5172
|
+
if (!(x < through)) break;
|
|
5173
|
+
bends.push({
|
|
5174
|
+
x,
|
|
5175
|
+
value: cubic(v0, c1, c2, v1, j / n)
|
|
5176
|
+
});
|
|
5177
|
+
}
|
|
5178
|
+
return bends;
|
|
5179
|
+
},
|
|
5180
|
+
valueAt(from, to, x) {
|
|
5181
|
+
const p = piece(from, to);
|
|
5182
|
+
if (!p) return values[from] ?? 0;
|
|
5183
|
+
const [v0, c1, c2, v1, k] = p;
|
|
5184
|
+
return cubic(v0, c1, c2, v1, (x - kx[k]) / (kx[k + 1] - kx[k]));
|
|
5185
|
+
}
|
|
5186
|
+
};
|
|
5187
|
+
}
|
|
5188
|
+
function monotoneTangents(xs, values, start, end, out) {
|
|
5189
|
+
const count = end - start;
|
|
5190
|
+
if (count < 2) {
|
|
5191
|
+
if (count === 1) out[start] = 0;
|
|
5192
|
+
return;
|
|
5193
|
+
}
|
|
5194
|
+
const slope = (k) => (values[k + 1] - values[k]) / (xs[k + 1] - xs[k]);
|
|
5195
|
+
if (count === 2) {
|
|
5196
|
+
out[start] = out[start + 1] = slope(start);
|
|
5197
|
+
return;
|
|
5198
|
+
}
|
|
5199
|
+
for (let k = start + 1; k < end - 1; k++) {
|
|
5200
|
+
const h0 = xs[k] - xs[k - 1];
|
|
5201
|
+
const h1 = xs[k + 1] - xs[k];
|
|
5202
|
+
const s0 = slope(k - 1);
|
|
5203
|
+
const s1 = slope(k);
|
|
5204
|
+
const p = (s0 * h1 + s1 * h0) / (h0 + h1);
|
|
5205
|
+
out[k] = (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), .5 * Math.abs(p)) || 0;
|
|
5206
|
+
}
|
|
5207
|
+
out[start] = (3 * slope(start) - out[start + 1]) / 2;
|
|
5208
|
+
out[end - 1] = (3 * slope(end - 2) - out[end - 2]) / 2;
|
|
5209
|
+
}
|
|
5210
|
+
function fade(xs, values, presence, start, end, tangents) {
|
|
5211
|
+
const kept = [];
|
|
5212
|
+
for (let k = start; k < end; k++) if (presence[k] >= 1) kept.push(k);
|
|
5213
|
+
if (kept.length === end - start || kept.length < 2) return;
|
|
5214
|
+
const kx = kept.map((k) => xs[k]);
|
|
5215
|
+
const kv = kept.map((k) => values[k]);
|
|
5216
|
+
const without = new Float64Array(kept.length);
|
|
5217
|
+
monotoneTangents(kx, kv, 0, kept.length, without);
|
|
5218
|
+
const eased = new Float64Array(end - start);
|
|
5219
|
+
let j = 0;
|
|
5220
|
+
let i = 0;
|
|
5221
|
+
for (let k = start; k < end; k++) {
|
|
5222
|
+
while (j < kx.length - 2 && kx[j + 1] <= xs[k]) j++;
|
|
5223
|
+
const own = kept[i] === k ? i++ : -1;
|
|
5224
|
+
let least = 1;
|
|
5225
|
+
for (let n = Math.max(start, k - 2); n < Math.min(end, k + 3); n++) least = Math.min(least, presence[n]);
|
|
5226
|
+
if (least >= 1) {
|
|
5227
|
+
eased[k - start] = tangents[k];
|
|
5228
|
+
continue;
|
|
5229
|
+
}
|
|
5230
|
+
let slope;
|
|
5231
|
+
if (own >= 0) slope = without[own];
|
|
5232
|
+
else {
|
|
5233
|
+
const h = kx[j + 1] - kx[j];
|
|
5234
|
+
const u = Math.min(1, Math.max(0, (xs[k] - kx[j]) / h));
|
|
5235
|
+
slope = (6 * u * u - 6 * u) * (kv[j] - kv[j + 1]) / h + (3 * u * u - 4 * u + 1) * without[j] + (3 * u * u - 2 * u) * without[j + 1];
|
|
5236
|
+
}
|
|
5237
|
+
eased[k - start] = least * tangents[k] + (1 - least) * slope;
|
|
5238
|
+
}
|
|
5239
|
+
tangents.set(eased, start);
|
|
5240
|
+
}
|
|
5241
|
+
const sign = (x) => x < 0 ? -1 : 1;
|
|
5242
|
+
function cubic(v0, c1, c2, v1, u) {
|
|
5243
|
+
const s = 1 - u;
|
|
5244
|
+
return s * s * s * v0 + 3 * s * s * u * c1 + 3 * s * u * u * c2 + u * u * u * v1;
|
|
5245
|
+
}
|
|
5015
5246
|
// src/charts/time.ts
|
|
5016
5247
|
const TIME_ZONES = ["UTC", "local"];
|
|
5017
5248
|
const SECOND = 1e3;
|
|
@@ -5027,7 +5258,7 @@ const LONGEST$1 = {
|
|
|
5027
5258
|
month: 31 * DAY,
|
|
5028
5259
|
year: 366 * DAY
|
|
5029
5260
|
};
|
|
5030
|
-
const STEPS = [
|
|
5261
|
+
const STEPS = /* @__PURE__ */ (() => [
|
|
5031
5262
|
...[
|
|
5032
5263
|
1,
|
|
5033
5264
|
5,
|
|
@@ -5075,7 +5306,7 @@ const STEPS = [
|
|
|
5075
5306
|
unit: "month",
|
|
5076
5307
|
count: 3
|
|
5077
5308
|
}
|
|
5078
|
-
];
|
|
5309
|
+
])();
|
|
5079
5310
|
const LEVELS = [
|
|
5080
5311
|
"year",
|
|
5081
5312
|
"month",
|
|
@@ -5305,6 +5536,8 @@ function lineEncoding(options) {
|
|
|
5305
5536
|
if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${show$1(timeZone)}.`);
|
|
5306
5537
|
const xFormat = options.xFormat;
|
|
5307
5538
|
if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
|
|
5539
|
+
const curve = options.curve ?? "linear";
|
|
5540
|
+
if (!CURVES.includes(curve)) throw new TypeError(`lineChart: curve must be "linear" or "monotone", got ${show$1(curve)}.`);
|
|
5308
5541
|
return {
|
|
5309
5542
|
x: accessor(x),
|
|
5310
5543
|
key: key === void 0 ? void 0 : accessor(key),
|
|
@@ -5313,7 +5546,8 @@ function lineEncoding(options) {
|
|
|
5313
5546
|
value: accessor(field)
|
|
5314
5547
|
})),
|
|
5315
5548
|
timeZone,
|
|
5316
|
-
xFormat: options.xFormat
|
|
5549
|
+
xFormat: options.xFormat,
|
|
5550
|
+
curve
|
|
5317
5551
|
};
|
|
5318
5552
|
}
|
|
5319
5553
|
function layoutLines(input) {
|
|
@@ -5334,7 +5568,7 @@ function layoutLines(input) {
|
|
|
5334
5568
|
const xWidths = xTexts.map((text) => measure(text, "ec-tick", TICK_SIZE));
|
|
5335
5569
|
const labelWidth = input.label ? widest(distinctLabels(rows, input.label), "ec-value", VALUE_SIZE, measure) : 0;
|
|
5336
5570
|
const left = Math.max(widest(yTexts, "ec-tick", TICK_SIZE, measure) + 10, (xWidths[0] ?? 0) / 2 + 2);
|
|
5337
|
-
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0);
|
|
5571
|
+
const right = Math.max(10, (xWidths[xWidths.length - 1] ?? 0) / 2 + 2, (labelWidth > 0 ? LABEL_GAP + labelWidth + 4 : 0) + (input.room ?? 0));
|
|
5338
5572
|
const frame = {
|
|
5339
5573
|
scale: {
|
|
5340
5574
|
lo: domain.lo,
|
|
@@ -5364,7 +5598,8 @@ function layoutLines(input) {
|
|
|
5364
5598
|
series,
|
|
5365
5599
|
yTicks: domain.ticks.map((value, i) => placeYTick(frame, value, yTexts[i])),
|
|
5366
5600
|
xTicks: spaced(xTicks, xWidths),
|
|
5367
|
-
decimals: decimalsBy
|
|
5601
|
+
decimals: decimalsBy,
|
|
5602
|
+
curve: input.encoding.curve
|
|
5368
5603
|
};
|
|
5369
5604
|
}
|
|
5370
5605
|
function positions(frame) {
|
|
@@ -5376,7 +5611,7 @@ function positions(frame) {
|
|
|
5376
5611
|
y: (value) => ySpan > 0 ? box.bottom - (value - scale.lo) / ySpan * (box.bottom - box.top) : box.bottom
|
|
5377
5612
|
};
|
|
5378
5613
|
}
|
|
5379
|
-
function placeLines(frame, rows, series, through, time = false, labels) {
|
|
5614
|
+
function placeLines(frame, rows, series, through, time = false, labels, bend = 0) {
|
|
5380
5615
|
const first = rows[0];
|
|
5381
5616
|
if (!first) return [];
|
|
5382
5617
|
const at = positions(frame);
|
|
@@ -5386,27 +5621,47 @@ function placeLines(frame, rows, series, through, time = false, labels) {
|
|
|
5386
5621
|
const next = rows[last + 1];
|
|
5387
5622
|
const share = next && next.x > end.x && through > end.x ? (through - end.x) / (next.x - end.x) : void 0;
|
|
5388
5623
|
const shown = rows.slice(0, last + 1);
|
|
5624
|
+
const xs = bend > 0 ? rows.map((row) => row.x) : [];
|
|
5625
|
+
const presence = bend > 0 && rows.some((row) => row.presence !== void 0 && row.presence < 1) ? rows.map((row) => row.presence ?? 1) : void 0;
|
|
5389
5626
|
const datas = /* @__PURE__ */ new Map();
|
|
5390
5627
|
const related = (own) => (name) => name === own ? void 0 : datas.get(name);
|
|
5391
5628
|
const traced = series.map((name) => {
|
|
5392
5629
|
const has = (row) => !row.missing?.has(name);
|
|
5630
|
+
const curve = bend > 0 ? lineCurve(xs, rows.map((row) => has(row) ? row.values[name] ?? 0 : void 0), bend, at, presence) : void 0;
|
|
5393
5631
|
const vertices = [];
|
|
5394
5632
|
let gap = false;
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
vertices.
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5633
|
+
let before = -1;
|
|
5634
|
+
shown.forEach((row, i) => {
|
|
5635
|
+
if (!has(row)) gap = vertices.length > 0;
|
|
5636
|
+
else {
|
|
5637
|
+
if (curve && before >= 0) for (const b of curve.between(before, i)) vertices.push({
|
|
5638
|
+
at: b.x,
|
|
5639
|
+
value: b.value,
|
|
5640
|
+
datum: rows[before].datum,
|
|
5641
|
+
gapBefore: false
|
|
5642
|
+
});
|
|
5643
|
+
vertices.push({
|
|
5644
|
+
at: row.x,
|
|
5645
|
+
value: row.values[name] ?? 0,
|
|
5646
|
+
datum: row.datum,
|
|
5647
|
+
gapBefore: gap
|
|
5648
|
+
});
|
|
5649
|
+
gap = false;
|
|
5650
|
+
before = i;
|
|
5651
|
+
}
|
|
5652
|
+
});
|
|
5405
5653
|
if (share !== void 0 && has(end) && has(next)) {
|
|
5654
|
+
if (curve) for (const b of curve.between(last, last + 1, through)) vertices.push({
|
|
5655
|
+
at: b.x,
|
|
5656
|
+
value: b.value,
|
|
5657
|
+
datum: end.datum,
|
|
5658
|
+
gapBefore: false
|
|
5659
|
+
});
|
|
5406
5660
|
const from = end.values[name] ?? 0;
|
|
5661
|
+
const value = curve ? curve.valueAt(last, last + 1, through) : from + share * ((next.values[name] ?? 0) - from);
|
|
5407
5662
|
vertices.push({
|
|
5408
5663
|
at: through,
|
|
5409
|
-
value
|
|
5664
|
+
value,
|
|
5410
5665
|
datum: end.datum,
|
|
5411
5666
|
gapBefore: false
|
|
5412
5667
|
});
|
|
@@ -5428,15 +5683,19 @@ function placeLines(frame, rows, series, through, time = false, labels) {
|
|
|
5428
5683
|
...points[points.length - 1],
|
|
5429
5684
|
text: labels.text(name, vertices[vertices.length - 1].value)
|
|
5430
5685
|
}))) : [];
|
|
5686
|
+
const boxes = labels ? placed.map((label) => label.text !== "" ? textBox(label, labels.measure, "ec-value", VALUE_SIZE) : void 0) : [];
|
|
5431
5687
|
return traced.map(({ name, vertices, points }) => {
|
|
5432
5688
|
const tip = points[points.length - 1];
|
|
5433
|
-
const
|
|
5689
|
+
const index = named.findIndex((line) => line.name === name);
|
|
5690
|
+
const label = labels ? placed[index] ?? {
|
|
5434
5691
|
x: tip.x + LABEL_GAP,
|
|
5435
5692
|
y: tip.y + VALUE_SIZE * CENTRE$1,
|
|
5436
5693
|
anchor: "start",
|
|
5437
5694
|
text: ""
|
|
5438
5695
|
} : void 0;
|
|
5439
|
-
const
|
|
5696
|
+
const own = boxes[index];
|
|
5697
|
+
const labelBounds = labels ? own ? [own] : [] : void 0;
|
|
5698
|
+
const nearbyLabels = labels ? boxes.filter((box, i) => box !== void 0 && i !== index) : void 0;
|
|
5440
5699
|
const breaks = vertices.flatMap((v, j) => v.gapBefore ? [j] : []);
|
|
5441
5700
|
const geometry = describeLine({
|
|
5442
5701
|
key: name,
|
|
@@ -5444,7 +5703,8 @@ function placeLines(frame, rows, series, through, time = false, labels) {
|
|
|
5444
5703
|
points,
|
|
5445
5704
|
width: LINE_WIDTH,
|
|
5446
5705
|
...breaks.length > 0 ? { breaks } : {},
|
|
5447
|
-
...labelBounds ? { labelBounds } : {}
|
|
5706
|
+
...labelBounds ? { labelBounds } : {},
|
|
5707
|
+
...nearbyLabels ? { nearbyLabels } : {}
|
|
5448
5708
|
});
|
|
5449
5709
|
let distance = 0;
|
|
5450
5710
|
const samples = vertices.map((v, j) => {
|
|
@@ -5755,6 +6015,7 @@ const VISIBLE = .5;
|
|
|
5755
6015
|
function lineChart$1(target, options, env) {
|
|
5756
6016
|
const container = resolveTarget$2(target, "lineChart");
|
|
5757
6017
|
checkChartOptions(options, "lineChart");
|
|
6018
|
+
let hoverKind = hoverOf(options);
|
|
5758
6019
|
let current = options;
|
|
5759
6020
|
const motion = chartMotion(options.motion, env.motion);
|
|
5760
6021
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -5812,10 +6073,12 @@ function lineChart$1(target, options, env) {
|
|
|
5812
6073
|
let laidOut;
|
|
5813
6074
|
let firstTable;
|
|
5814
6075
|
let names;
|
|
6076
|
+
let pointNames;
|
|
5815
6077
|
try {
|
|
5816
6078
|
laidOut = layout(current);
|
|
5817
6079
|
firstTable = tableFor(current, laidOut);
|
|
5818
|
-
names = namesFor(current, laidOut);
|
|
6080
|
+
names = hoverKind === "x" ? namesFor(current, laidOut) : void 0;
|
|
6081
|
+
pointNames = hoverKind === "point" ? pointNamesFor(current, laidOut) : void 0;
|
|
5819
6082
|
} catch (error) {
|
|
5820
6083
|
svg.remove();
|
|
5821
6084
|
throw error;
|
|
@@ -5823,6 +6086,7 @@ function lineChart$1(target, options, env) {
|
|
|
5823
6086
|
const findMark = (key) => points.get(key) ?? lines.get(key) ?? leaving.get(key);
|
|
5824
6087
|
const surface = svgSurface({
|
|
5825
6088
|
overlay,
|
|
6089
|
+
measure,
|
|
5826
6090
|
mark: (key) => ({
|
|
5827
6091
|
set: (style) => {
|
|
5828
6092
|
findMark(key)?.handle.set(style);
|
|
@@ -5864,6 +6128,11 @@ function lineChart$1(target, options, env) {
|
|
|
5864
6128
|
motion,
|
|
5865
6129
|
onChange: changed
|
|
5866
6130
|
});
|
|
6131
|
+
const curved = animated(bendOf(laidOut.curve), interpolateNumber, {
|
|
6132
|
+
clock,
|
|
6133
|
+
motion,
|
|
6134
|
+
onChange: changed
|
|
6135
|
+
});
|
|
5867
6136
|
const yTicks = /* @__PURE__ */ new Map();
|
|
5868
6137
|
const xTicks = /* @__PURE__ */ new Map();
|
|
5869
6138
|
let counting = laidOut.decimals;
|
|
@@ -5883,6 +6152,8 @@ function lineChart$1(target, options, env) {
|
|
|
5883
6152
|
function layout(opts, using = effects) {
|
|
5884
6153
|
const encoding = lineEncoding(opts);
|
|
5885
6154
|
checkNeeds$1(using, encoding.series.map((s) => s.series), "lineChart");
|
|
6155
|
+
const { room = 0 } = opts;
|
|
6156
|
+
if (!(typeof room === "number" && Number.isFinite(room) && room >= 0)) throw new RangeError(`lineChart: room must be a number of px, 0 or more, got ${String(room)}.`);
|
|
5886
6157
|
const next = layoutLines({
|
|
5887
6158
|
data: opts.data,
|
|
5888
6159
|
encoding,
|
|
@@ -5890,7 +6161,8 @@ function lineChart$1(target, options, env) {
|
|
|
5890
6161
|
height: opts.height,
|
|
5891
6162
|
format: format(opts),
|
|
5892
6163
|
measure,
|
|
5893
|
-
label: labeler(opts, true)
|
|
6164
|
+
label: labeler(opts, true),
|
|
6165
|
+
room
|
|
5894
6166
|
});
|
|
5895
6167
|
const keys = new Set(next.series);
|
|
5896
6168
|
for (const row of next.rows) for (const name of next.series) {
|
|
@@ -5924,14 +6196,14 @@ function lineChart$1(target, options, env) {
|
|
|
5924
6196
|
const label = labeler(current);
|
|
5925
6197
|
if (!label) return void 0;
|
|
5926
6198
|
return {
|
|
5927
|
-
text: (series, value) => label(series, round$
|
|
6199
|
+
text: (series, value) => label(series, round$5(value, given[series] ?? decimals(value))),
|
|
5928
6200
|
measure
|
|
5929
6201
|
};
|
|
5930
6202
|
}
|
|
5931
6203
|
function placedFor(next) {
|
|
5932
6204
|
const states = next.rows.map(restState);
|
|
5933
6205
|
return {
|
|
5934
|
-
lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals)).map((line) => [line.series, line])),
|
|
6206
|
+
lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals), bendOf(next.curve)).map((line) => [line.series, line])),
|
|
5935
6207
|
points: new Map(states.flatMap((state) => placePoints(next.frame, state, next.series, next.time)).map((point) => [point.key, point]))
|
|
5936
6208
|
};
|
|
5937
6209
|
}
|
|
@@ -6066,6 +6338,7 @@ function lineChart$1(target, options, env) {
|
|
|
6066
6338
|
};
|
|
6067
6339
|
return [...rowOrder, ...[...leavingRows.values()].filter((record) => record.presence.value > 0 && record.anchor)].map((record) => {
|
|
6068
6340
|
const { x, values } = stateOf(record);
|
|
6341
|
+
const presence = record.anchor && record.presence.value < 1 ? { presence: record.presence.value } : {};
|
|
6069
6342
|
return {
|
|
6070
6343
|
record,
|
|
6071
6344
|
state: {
|
|
@@ -6073,7 +6346,8 @@ function lineChart$1(target, options, env) {
|
|
|
6073
6346
|
datum: record.row.datum,
|
|
6074
6347
|
x,
|
|
6075
6348
|
values,
|
|
6076
|
-
missing: record.row.missing
|
|
6349
|
+
missing: record.row.missing,
|
|
6350
|
+
...presence
|
|
6077
6351
|
}
|
|
6078
6352
|
};
|
|
6079
6353
|
}).sort((a, b) => a.state.x - b.state.x);
|
|
@@ -6188,7 +6462,7 @@ function lineChart$1(target, options, env) {
|
|
|
6188
6462
|
function paintLines(frame, states) {
|
|
6189
6463
|
const drawnLines = [...lineOrder, ...leavingLines()];
|
|
6190
6464
|
if (states.length === 0 || drawnLines.length === 0) return;
|
|
6191
|
-
const placed = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting));
|
|
6465
|
+
const placed = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting), curved.value);
|
|
6192
6466
|
showAll(drawnLines.map((line, i) => ({
|
|
6193
6467
|
record: line,
|
|
6194
6468
|
placed: placed[i]
|
|
@@ -6279,8 +6553,16 @@ function lineChart$1(target, options, env) {
|
|
|
6279
6553
|
surface.hide(point.key, hidden);
|
|
6280
6554
|
}
|
|
6281
6555
|
}
|
|
6556
|
+
if (stopsLayer) paintStops(frame);
|
|
6282
6557
|
}
|
|
6283
6558
|
function showHover(key) {
|
|
6559
|
+
const point = points.get(key);
|
|
6560
|
+
if (point) {
|
|
6561
|
+
if (!revealed(point.row)) return;
|
|
6562
|
+
const { row } = point.row;
|
|
6563
|
+
tooltip.show(point.shown.geometry, about(row, point.series), () => pointSummary(row, point.series, current), point.handle.style.transform);
|
|
6564
|
+
return;
|
|
6565
|
+
}
|
|
6284
6566
|
const record = rows.get(key);
|
|
6285
6567
|
if (!record || !revealed(record)) return;
|
|
6286
6568
|
const marks = livePoints(record);
|
|
@@ -6313,9 +6595,10 @@ function lineChart$1(target, options, env) {
|
|
|
6313
6595
|
}
|
|
6314
6596
|
let ringLine;
|
|
6315
6597
|
function drawRing(key) {
|
|
6316
|
-
const
|
|
6598
|
+
const point = key === void 0 ? void 0 : points.get(key);
|
|
6599
|
+
const record = key === void 0 ? void 0 : point?.row ?? rows.get(key);
|
|
6317
6600
|
const live = record !== void 0 && revealed(record);
|
|
6318
|
-
const marks = live ? livePoints(record) : [];
|
|
6601
|
+
const marks = live ? point ? [point] : livePoints(record) : [];
|
|
6319
6602
|
if (live && marks.length === 0) {
|
|
6320
6603
|
ringLine ?? (ringLine = svgElement("line", {
|
|
6321
6604
|
class: "ec-focus-ring",
|
|
@@ -6365,34 +6648,262 @@ function lineChart$1(target, options, env) {
|
|
|
6365
6648
|
const record = column ? byColumn.get(column) : void 0;
|
|
6366
6649
|
return record && rows.get(record.key) === record && revealed(record) ? record : void 0;
|
|
6367
6650
|
}
|
|
6651
|
+
let stopsLayer;
|
|
6652
|
+
let plotHit;
|
|
6653
|
+
const stops = /* @__PURE__ */ new Map();
|
|
6654
|
+
let stopOrder = [];
|
|
6655
|
+
const byStop = /* @__PURE__ */ new WeakMap();
|
|
6656
|
+
function pointOrder() {
|
|
6657
|
+
const bySeries = new Map(laidOut.series.map((series) => [series, []]));
|
|
6658
|
+
for (const record of rowOrder) for (const point of livePoints(record)) bySeries.get(point.series)?.push(point);
|
|
6659
|
+
return [...bySeries.values()].flat();
|
|
6660
|
+
}
|
|
6661
|
+
const along = (series) => rowOrder.filter(revealed).flatMap((record) => livePoints(record).filter((point) => point.series === series));
|
|
6662
|
+
function nearestPoint(at) {
|
|
6663
|
+
const shown = rowOrder.filter(revealed).flatMap(livePoints);
|
|
6664
|
+
let best;
|
|
6665
|
+
let far = Infinity;
|
|
6666
|
+
let rank = Infinity;
|
|
6667
|
+
for (const point of shown) {
|
|
6668
|
+
const d = apart(point.shown.geometry.center, at);
|
|
6669
|
+
const r = laidOut.series.indexOf(point.series);
|
|
6670
|
+
if (d < far || d === far && r < rank) [best, far, rank] = [
|
|
6671
|
+
point,
|
|
6672
|
+
d,
|
|
6673
|
+
r
|
|
6674
|
+
];
|
|
6675
|
+
}
|
|
6676
|
+
if (!best) return void 0;
|
|
6677
|
+
const center = best.shown.geometry.center;
|
|
6678
|
+
const on = /* @__PURE__ */ new Map();
|
|
6679
|
+
for (const point of shown) {
|
|
6680
|
+
const { center: c } = point.shown.geometry;
|
|
6681
|
+
const known = on.get(point.series);
|
|
6682
|
+
if (apart(c, center) <= 1 && (!known || apart(c, at) < apart(known.shown.geometry.center, at))) on.set(point.series, point);
|
|
6683
|
+
}
|
|
6684
|
+
if (on.size < 2) return best;
|
|
6685
|
+
let pick = best;
|
|
6686
|
+
let near = Infinity;
|
|
6687
|
+
for (const series of laidOut.series) {
|
|
6688
|
+
const point = on.get(series);
|
|
6689
|
+
if (!point) continue;
|
|
6690
|
+
const d = passing(point, at);
|
|
6691
|
+
if (d < near) [pick, near] = [point, d];
|
|
6692
|
+
}
|
|
6693
|
+
return pick;
|
|
6694
|
+
}
|
|
6695
|
+
function passing(point, at) {
|
|
6696
|
+
const { geometry, data } = point.shown;
|
|
6697
|
+
const line = lines.get(point.series);
|
|
6698
|
+
return (line && strokeNear(line.shown, data.samples[0].at, geometry.center, at, 9)) ?? Math.max(0, Math.hypot(at.x - geometry.center.x, at.y - geometry.center.y) - 4.5);
|
|
6699
|
+
}
|
|
6700
|
+
function heldPoint(at) {
|
|
6701
|
+
const point = hover.key === void 0 || !tooltip.element() ? void 0 : points.get(hover.key);
|
|
6702
|
+
if (!point || !revealed(point.row)) return void 0;
|
|
6703
|
+
const { transform } = point.handle.style;
|
|
6704
|
+
let on = at;
|
|
6705
|
+
if (transform) try {
|
|
6706
|
+
on = matrix.apply(invert(transform), at);
|
|
6707
|
+
} catch {
|
|
6708
|
+
return;
|
|
6709
|
+
}
|
|
6710
|
+
const { center } = point.shown.geometry;
|
|
6711
|
+
return (on.x - center.x) ** 2 + (on.y - center.y) ** 2 <= 4.5 ** 2 ? point : void 0;
|
|
6712
|
+
}
|
|
6713
|
+
function pointAt(clientX, clientY) {
|
|
6714
|
+
const at = fromClient(clientX, clientY);
|
|
6715
|
+
return heldPoint(at) ?? nearestPoint(at);
|
|
6716
|
+
}
|
|
6717
|
+
function fromClient(x, y) {
|
|
6718
|
+
const box = svg.getBoundingClientRect();
|
|
6719
|
+
const k = box.width > 0 && drawnFrame.box.width > 0 ? box.width / drawnFrame.box.width : 1;
|
|
6720
|
+
return {
|
|
6721
|
+
x: (x - box.left) / k,
|
|
6722
|
+
y: (y - box.top) / k
|
|
6723
|
+
};
|
|
6724
|
+
}
|
|
6725
|
+
const abouts = /* @__PURE__ */ new WeakMap();
|
|
6726
|
+
function about(row, series) {
|
|
6727
|
+
let bySeries = abouts.get(row);
|
|
6728
|
+
if (!bySeries) abouts.set(row, bySeries = /* @__PURE__ */ new Map());
|
|
6729
|
+
let known = bySeries.get(series);
|
|
6730
|
+
if (!known) bySeries.set(series, known = {
|
|
6731
|
+
datum: row.datum,
|
|
6732
|
+
series
|
|
6733
|
+
});
|
|
6734
|
+
return known;
|
|
6735
|
+
}
|
|
6736
|
+
function syncStops() {
|
|
6737
|
+
if (hoverKind !== "point") return;
|
|
6738
|
+
if (!stopsLayer) {
|
|
6739
|
+
stopsLayer = svgElement("g", { class: "ec-stops" }, svg);
|
|
6740
|
+
svg.insertBefore(stopsLayer, overlay);
|
|
6741
|
+
plotHit = svgElement("rect", { class: "ec-hit" }, stopsLayer);
|
|
6742
|
+
stopsLayer.addEventListener("click", (event) => {
|
|
6743
|
+
const point = pointAt(event.clientX, event.clientY);
|
|
6744
|
+
if (point) stops.get(point.key)?.element.focus();
|
|
6745
|
+
});
|
|
6746
|
+
}
|
|
6747
|
+
const live = pointOrder();
|
|
6748
|
+
const keep = new Set(live.map((point) => point.key));
|
|
6749
|
+
for (const [key, stop] of stops) {
|
|
6750
|
+
if (keep.has(key)) continue;
|
|
6751
|
+
stop.element.remove();
|
|
6752
|
+
stops.delete(key);
|
|
6753
|
+
}
|
|
6754
|
+
const order = live.map((point) => {
|
|
6755
|
+
let stop = stops.get(point.key);
|
|
6756
|
+
if (!stop) {
|
|
6757
|
+
const element = svgElement("g", {
|
|
6758
|
+
class: "ec-stop",
|
|
6759
|
+
"data-key": point.key,
|
|
6760
|
+
role: "img"
|
|
6761
|
+
}, stopsLayer);
|
|
6762
|
+
stop = {
|
|
6763
|
+
element,
|
|
6764
|
+
bounds: svgElement("circle", {
|
|
6765
|
+
r: 8.5,
|
|
6766
|
+
fill: "none"
|
|
6767
|
+
}, element),
|
|
6768
|
+
x: NaN,
|
|
6769
|
+
y: NaN,
|
|
6770
|
+
hidden: void 0
|
|
6771
|
+
};
|
|
6772
|
+
stops.set(point.key, stop);
|
|
6773
|
+
byStop.set(element, point.key);
|
|
6774
|
+
}
|
|
6775
|
+
const name = pointNames?.get(point.key) ?? point.key;
|
|
6776
|
+
if (stop.element.getAttribute("aria-label") !== name) stop.element.setAttribute("aria-label", name);
|
|
6777
|
+
tooltip.describe(stop.element, about(point.row.row, point.series));
|
|
6778
|
+
return stop.element;
|
|
6779
|
+
});
|
|
6780
|
+
orderElements(stopsLayer, stopOrder, order, hover.active);
|
|
6781
|
+
stopOrder = order;
|
|
6782
|
+
}
|
|
6783
|
+
function paintStops(frame) {
|
|
6784
|
+
const { left, right, top, bottom } = frame.box;
|
|
6785
|
+
setAttributes(plotHit, {
|
|
6786
|
+
x: left - DOT_RADIUS,
|
|
6787
|
+
y: top - DOT_RADIUS,
|
|
6788
|
+
width: right - left + 2 * DOT_RADIUS,
|
|
6789
|
+
height: bottom - top + 2 * DOT_RADIUS
|
|
6790
|
+
});
|
|
6791
|
+
for (const [key, stop] of stops) {
|
|
6792
|
+
const point = points.get(key);
|
|
6793
|
+
if (!point) continue;
|
|
6794
|
+
const hidden = !revealed(point.row);
|
|
6795
|
+
if (stop.hidden !== hidden) {
|
|
6796
|
+
stop.hidden = hidden;
|
|
6797
|
+
setAttributes(stop.element, { visibility: hidden ? "hidden" : void 0 });
|
|
6798
|
+
}
|
|
6799
|
+
const { x, y } = point.shown.geometry.center;
|
|
6800
|
+
if (stop.x === x && stop.y === y) continue;
|
|
6801
|
+
stop.x = x;
|
|
6802
|
+
stop.y = y;
|
|
6803
|
+
setAttributes(stop.bounds, {
|
|
6804
|
+
cx: x,
|
|
6805
|
+
cy: y
|
|
6806
|
+
});
|
|
6807
|
+
}
|
|
6808
|
+
}
|
|
6809
|
+
function counterpart(key) {
|
|
6810
|
+
const point = points.get(key);
|
|
6811
|
+
if (point) return point.row.key;
|
|
6812
|
+
const shown = rowOrder.filter(revealed);
|
|
6813
|
+
const i = shown.findIndex((record) => record.key === key);
|
|
6814
|
+
for (let step = 0; i >= 0 && step < shown.length; step++) for (const at of [i + step, i - step]) {
|
|
6815
|
+
const first = shown[at] && livePoints(shown[at])[0];
|
|
6816
|
+
if (first) return first.key;
|
|
6817
|
+
}
|
|
6818
|
+
}
|
|
6819
|
+
function rehover(kind) {
|
|
6820
|
+
if (kind === hoverKind) return;
|
|
6821
|
+
hover.leave();
|
|
6822
|
+
hoverKind = kind;
|
|
6823
|
+
if (kind === "point") {
|
|
6824
|
+
syncStops();
|
|
6825
|
+
paintStops(drawnFrame);
|
|
6826
|
+
} else columnsLayer.removeAttribute("display");
|
|
6827
|
+
hover.retarget(counterpart);
|
|
6828
|
+
if (kind === "point") columnsLayer.setAttribute("display", "none");
|
|
6829
|
+
else {
|
|
6830
|
+
stopsLayer?.remove();
|
|
6831
|
+
stopsLayer = plotHit = void 0;
|
|
6832
|
+
stops.clear();
|
|
6833
|
+
stopOrder = [];
|
|
6834
|
+
}
|
|
6835
|
+
}
|
|
6836
|
+
const hotLines = /* @__PURE__ */ new Map();
|
|
6837
|
+
function heat(key, on) {
|
|
6838
|
+
const series = on ? hoverKind === "point" ? findMark(key)?.series : void 0 : hotLines.get(key);
|
|
6839
|
+
if (series === void 0) return;
|
|
6840
|
+
if (on) hotLines.set(key, series);
|
|
6841
|
+
else hotLines.delete(key);
|
|
6842
|
+
surface.hot(key, on);
|
|
6843
|
+
if (!on && [...hotLines.values()].includes(series)) return;
|
|
6844
|
+
findMark(series)?.group.classList.toggle("ec-hot-line", on);
|
|
6845
|
+
surface.hot(series, on);
|
|
6846
|
+
}
|
|
6847
|
+
function live(key) {
|
|
6848
|
+
const point = hoverKind === "point" ? points.get(key) : void 0;
|
|
6849
|
+
const record = hoverKind === "point" ? point?.row : rows.get(key);
|
|
6850
|
+
return record !== void 0 && revealed(record);
|
|
6851
|
+
}
|
|
6368
6852
|
const hover = chartHover({
|
|
6369
6853
|
svg,
|
|
6370
6854
|
runner,
|
|
6371
6855
|
events,
|
|
6372
|
-
dim: () => false,
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6856
|
+
dim: () => hoverKind === "point" && current.dim !== false && hover.key !== void 0,
|
|
6857
|
+
hot: heat,
|
|
6858
|
+
find(eventTarget, pointer) {
|
|
6859
|
+
if (hoverKind === "x") {
|
|
6860
|
+
const record = liveRowOf(eventTarget);
|
|
6861
|
+
return record && { key: record.key };
|
|
6862
|
+
}
|
|
6863
|
+
const element = eventTarget;
|
|
6864
|
+
if (!stopsLayer || typeof element?.closest !== "function" || !stopsLayer.contains(element)) return void 0;
|
|
6865
|
+
if (pointer) {
|
|
6866
|
+
const point = pointAt(pointer.x, pointer.y);
|
|
6867
|
+
return point && { key: point.key };
|
|
6868
|
+
}
|
|
6869
|
+
const stop = element.closest(".ec-stop");
|
|
6870
|
+
const key = stop ? byStop.get(stop) : void 0;
|
|
6871
|
+
return key !== void 0 && live(key) ? { key } : void 0;
|
|
6380
6872
|
},
|
|
6381
|
-
|
|
6873
|
+
moves: () => hoverKind === "point",
|
|
6874
|
+
live,
|
|
6875
|
+
order: () => (hoverKind === "point" ? pointOrder().filter((point) => revealed(point.row)) : rowOrder.filter(revealed)).map((record) => record.key),
|
|
6382
6876
|
page(key, by) {
|
|
6383
|
-
const
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6877
|
+
const point = hoverKind === "point" ? points.get(key) : void 0;
|
|
6878
|
+
const stops = point ? along(point.series).map((p) => ({
|
|
6879
|
+
key: p.key,
|
|
6880
|
+
x: p.row.row.x
|
|
6881
|
+
})) : rowOrder.filter(revealed).map((record) => ({
|
|
6882
|
+
key: record.key,
|
|
6883
|
+
x: record.row.x
|
|
6884
|
+
}));
|
|
6885
|
+
const i = stops.findIndex((stop) => stop.key === key);
|
|
6886
|
+
if (i < 0) return void 0;
|
|
6887
|
+
if (!laidOut.time) return point ? stops[Math.min(stops.length - 1, Math.max(0, i + by * Math.ceil(stops.length / 10)))].key : void 0;
|
|
6888
|
+
const to = monthsOn(stops[i].x, by, lineEncoding(current).timeZone);
|
|
6889
|
+
if (by > 0) return (stops.find((stop) => stop.x >= to) ?? stops[stops.length - 1])?.key;
|
|
6890
|
+
for (let j = stops.length - 1; j >= 0; j--) if (stops[j].x <= to) return stops[j].key;
|
|
6389
6891
|
return stops[0]?.key;
|
|
6390
6892
|
},
|
|
6893
|
+
move(key, press) {
|
|
6894
|
+
const point = hoverKind === "point" ? points.get(key) : void 0;
|
|
6895
|
+
if (!point) return void 0;
|
|
6896
|
+
const stops = press === "ArrowUp" || press === "ArrowDown" ? livePoints(point.row).sort((a, b) => a.shown.geometry.center.y - b.shown.geometry.center.y) : along(point.series);
|
|
6897
|
+
const i = stops.indexOf(point);
|
|
6898
|
+
const to = press === "Home" ? 0 : press === "End" ? stops.length - 1 : i + (press === "ArrowDown" || press === "ArrowRight" ? 1 : -1);
|
|
6899
|
+
return stops[Math.max(0, Math.min(stops.length - 1, to))]?.key;
|
|
6900
|
+
},
|
|
6391
6901
|
marks: (key) => {
|
|
6392
6902
|
const record = rows.get(key);
|
|
6393
|
-
|
|
6903
|
+
if (record) return livePoints(record).map((point) => point.key);
|
|
6904
|
+
return points.has(key) ? [key] : [];
|
|
6394
6905
|
},
|
|
6395
|
-
element: (key) => (rows.get(key) ?? leavingRows.get(key))?.column,
|
|
6906
|
+
element: (key) => (rows.get(key) ?? leavingRows.get(key))?.column ?? stops.get(key)?.element,
|
|
6396
6907
|
markElement: (key) => findMark(key)?.group,
|
|
6397
6908
|
onScreen(key) {
|
|
6398
6909
|
const record = findMark(key);
|
|
@@ -6430,6 +6941,7 @@ function lineChart$1(target, options, env) {
|
|
|
6430
6941
|
});
|
|
6431
6942
|
}
|
|
6432
6943
|
function labelColumn(record) {
|
|
6944
|
+
if (hoverKind !== "x") return;
|
|
6433
6945
|
record.column.setAttribute("aria-label", names.get(record.key));
|
|
6434
6946
|
tooltip.describe(record.column, record.row);
|
|
6435
6947
|
}
|
|
@@ -6567,6 +7079,7 @@ function lineChart$1(target, options, env) {
|
|
|
6567
7079
|
record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn(point))];
|
|
6568
7080
|
}
|
|
6569
7081
|
for (const record of rowOrder) labelColumn(record);
|
|
7082
|
+
syncStops();
|
|
6570
7083
|
orderElements(columnsLayer, before.filter((record) => !record.leaving).map((record) => record.column), rowOrder.map((record) => record.column), hover.active);
|
|
6571
7084
|
orderElements(linesLayer, previousLines.map((line) => line.group), lineOrder.map((line) => line.group), () => null);
|
|
6572
7085
|
rowChanges = changes;
|
|
@@ -6596,7 +7109,7 @@ function lineChart$1(target, options, env) {
|
|
|
6596
7109
|
for (const tick of next.xTicks) xTicks.get(tick.value).text = tick.label.text;
|
|
6597
7110
|
const goingLines = leavingLines();
|
|
6598
7111
|
const folding = [...leavingRows.values()];
|
|
6599
|
-
const values = busy(scale, frame.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values, record.row.levels, sameFields)) || lineOrder.some((line) => busy(line.presence, 1, same)) || goingLines.some((line) => busy(line.presence, 0, same));
|
|
7112
|
+
const values = busy(scale, frame.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values, record.row.levels, sameFields)) || lineOrder.some((line) => busy(line.presence, 1, same)) || goingLines.some((line) => busy(line.presence, 0, same)) || busy(curved, bendOf(next.curve), same);
|
|
6600
7113
|
const positions = busy(box, frame.box, sameFields) || [...xTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.x, record.row.x, same) || record.anchor !== void 0 && busy(record.presence, 1, same)) || folding.some((record) => record.anchor !== void 0 && busy(record.presence, 0, same));
|
|
6601
7114
|
let first;
|
|
6602
7115
|
let second;
|
|
@@ -6614,6 +7127,7 @@ function lineChart$1(target, options, env) {
|
|
|
6614
7127
|
else value.set(to);
|
|
6615
7128
|
};
|
|
6616
7129
|
move(scale, frame.scale, sameFields, first);
|
|
7130
|
+
move(curved, bendOf(next.curve), same, first);
|
|
6617
7131
|
move(box, frame.box, sameFields, second);
|
|
6618
7132
|
for (const tick of yTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
|
|
6619
7133
|
for (const tick of xTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, second);
|
|
@@ -6690,6 +7204,8 @@ function lineChart$1(target, options, env) {
|
|
|
6690
7204
|
});
|
|
6691
7205
|
lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed.lines.get(name), false)) : [];
|
|
6692
7206
|
for (const line of lineOrder) lines.set(line.series, line);
|
|
7207
|
+
syncStops();
|
|
7208
|
+
if (hoverKind === "point") columnsLayer.setAttribute("display", "none");
|
|
6693
7209
|
land();
|
|
6694
7210
|
}
|
|
6695
7211
|
const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
|
|
@@ -6705,15 +7221,18 @@ function lineChart$1(target, options, env) {
|
|
|
6705
7221
|
...next
|
|
6706
7222
|
};
|
|
6707
7223
|
checkChartOptions(merged, "lineChart");
|
|
7224
|
+
const kind = hoverOf(merged);
|
|
6708
7225
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
6709
7226
|
const nextLayout = layout(merged, swapped);
|
|
6710
7227
|
const nextTable = tableFor(merged, nextLayout);
|
|
6711
|
-
const nextNames = namesFor(merged, nextLayout);
|
|
7228
|
+
const nextNames = kind === "x" ? namesFor(merged, nextLayout) : void 0;
|
|
7229
|
+
const nextPointNames = kind === "point" ? pointNamesFor(merged, nextLayout) : void 0;
|
|
6712
7230
|
if ("colors" in next) colors = toColorAssignment(merged.colors);
|
|
6713
7231
|
const previous = current;
|
|
6714
7232
|
const seriesBefore = laidOut.series;
|
|
6715
7233
|
current = merged;
|
|
6716
7234
|
names = nextNames;
|
|
7235
|
+
pointNames = nextPointNames;
|
|
6717
7236
|
describeChart(svg, current);
|
|
6718
7237
|
table.render(nextTable);
|
|
6719
7238
|
const announcing = announcer !== void 0;
|
|
@@ -6722,6 +7241,8 @@ function lineChart$1(target, options, env) {
|
|
|
6722
7241
|
announcer.destroy();
|
|
6723
7242
|
announcer = void 0;
|
|
6724
7243
|
}
|
|
7244
|
+
rehover(kind);
|
|
7245
|
+
hover.syncDim();
|
|
6725
7246
|
transitions.supersede();
|
|
6726
7247
|
const swapping = swapped !== effects;
|
|
6727
7248
|
effects = swapped;
|
|
@@ -6760,13 +7281,29 @@ function lineChart$1(target, options, env) {
|
|
|
6760
7281
|
marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
|
|
6761
7282
|
focus(key) {
|
|
6762
7283
|
if (destroyed) return;
|
|
6763
|
-
const
|
|
6764
|
-
if (
|
|
7284
|
+
const row = rows.get(key);
|
|
7285
|
+
if (hoverKind === "x") {
|
|
7286
|
+
const record = row ?? points.get(key)?.row;
|
|
7287
|
+
if (record) hover.focus(record.key);
|
|
7288
|
+
return;
|
|
7289
|
+
}
|
|
7290
|
+
const point = points.get(key) ?? (row && livePoints(row)[0]);
|
|
7291
|
+
if (point) hover.focus(point.key);
|
|
6765
7292
|
},
|
|
6766
7293
|
leave() {
|
|
6767
7294
|
if (!destroyed) hover.leave();
|
|
6768
7295
|
},
|
|
6769
7296
|
labels: () => lineOrder.flatMap((line) => chartLabel(line.key, "value", line.drawnLabel, line.label)),
|
|
7297
|
+
paintOf(key) {
|
|
7298
|
+
const record = lines.get(key) ?? points.get(key);
|
|
7299
|
+
return record && {
|
|
7300
|
+
color: record.series,
|
|
7301
|
+
drawn: record.kind === "line" || record.group.classList.contains("ec-alone")
|
|
7302
|
+
};
|
|
7303
|
+
},
|
|
7304
|
+
standsFor(key) {
|
|
7305
|
+
return rows.has(key) ? [...laidOut.series.map((series) => pointKey(series, key)), key] : [key];
|
|
7306
|
+
},
|
|
6770
7307
|
destroy() {
|
|
6771
7308
|
if (destroyed) return;
|
|
6772
7309
|
destroyed = true;
|
|
@@ -6789,6 +7326,7 @@ function lineChart$1(target, options, env) {
|
|
|
6789
7326
|
for (const record of leaving.values()) record.leave?.resolve();
|
|
6790
7327
|
scale.stop();
|
|
6791
7328
|
box.stop();
|
|
7329
|
+
curved.stop();
|
|
6792
7330
|
for (const tick of [...yTicks.values(), ...xTicks.values()]) tick.opacity.stop();
|
|
6793
7331
|
events.clear();
|
|
6794
7332
|
rows.clear();
|
|
@@ -6840,6 +7378,36 @@ function sameData(a, b) {
|
|
|
6840
7378
|
function sameAt(a, b) {
|
|
6841
7379
|
return a === b || a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
|
|
6842
7380
|
}
|
|
7381
|
+
function apart(a, b) {
|
|
7382
|
+
return (a.x - b.x) ** 2 + (a.y - b.y) ** 2;
|
|
7383
|
+
}
|
|
7384
|
+
function strokeNear({ geometry, data: { samples } }, x, from, at, reach) {
|
|
7385
|
+
const i = samples.findIndex((sample) => sameAt(sample.at, x));
|
|
7386
|
+
if (i < 0 || !(geometry.length > 0)) return void 0;
|
|
7387
|
+
const t = samples[i].t;
|
|
7388
|
+
const span = reach / geometry.length;
|
|
7389
|
+
let near;
|
|
7390
|
+
for (const way of [-1, 1]) {
|
|
7391
|
+
let a = from;
|
|
7392
|
+
for (let j = i;; j += way) {
|
|
7393
|
+
const next = samples[j + way];
|
|
7394
|
+
if (!next || (way > 0 ? next : samples[j]).gapBefore) break;
|
|
7395
|
+
const to = way > 0 ? Math.min(next.t, t + span) : Math.max(next.t, t - span);
|
|
7396
|
+
const b = geometry.path(to);
|
|
7397
|
+
near = Math.min(near ?? Infinity, toSegment(at, a, b));
|
|
7398
|
+
if (to !== next.t) break;
|
|
7399
|
+
a = b;
|
|
7400
|
+
}
|
|
7401
|
+
}
|
|
7402
|
+
return near;
|
|
7403
|
+
}
|
|
7404
|
+
function toSegment(p, a, b) {
|
|
7405
|
+
const dx = b.x - a.x;
|
|
7406
|
+
const dy = b.y - a.y;
|
|
7407
|
+
const length = dx * dx + dy * dy;
|
|
7408
|
+
const u = length > 0 ? Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / length)) : 0;
|
|
7409
|
+
return Math.hypot(p.x - a.x - u * dx, p.y - a.y - u * dy);
|
|
7410
|
+
}
|
|
6843
7411
|
function labelled(values, options) {
|
|
6844
7412
|
return present(values).map((v) => ({
|
|
6845
7413
|
series: v.series,
|
|
@@ -6861,35 +7429,60 @@ function summary(row, options) {
|
|
|
6861
7429
|
lines: [said(row.values, options).join(" · ")]
|
|
6862
7430
|
};
|
|
6863
7431
|
}
|
|
7432
|
+
function pointSummary(row, series, options) {
|
|
7433
|
+
return summaryContent(row.label, labelled(row.values, options).filter((v) => v.series === series), format(options), { total: false });
|
|
7434
|
+
}
|
|
7435
|
+
function worded(options, datum, mark) {
|
|
7436
|
+
if (!options.markLabel) return mark.text;
|
|
7437
|
+
try {
|
|
7438
|
+
const named = options.markLabel(datum, mark);
|
|
7439
|
+
if (named !== void 0 && named !== null && String(named).trim() !== "") return String(named);
|
|
7440
|
+
} catch (error) {
|
|
7441
|
+
report(error);
|
|
7442
|
+
}
|
|
7443
|
+
return mark.text;
|
|
7444
|
+
}
|
|
6864
7445
|
function namesFor(options, layout) {
|
|
6865
7446
|
const formatted = format(options);
|
|
6866
7447
|
return new Map(layout.rows.map((row) => {
|
|
6867
|
-
const values = labelled(row.values, options);
|
|
6868
7448
|
const text = `${row.label}: ${said(row.values, options).join(", ")}`;
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
text
|
|
6878
|
-
});
|
|
6879
|
-
if (named !== void 0 && named !== null && String(named).trim() !== "") return [row.key, String(named)];
|
|
6880
|
-
} catch (error) {
|
|
6881
|
-
report(error);
|
|
6882
|
-
}
|
|
6883
|
-
return [row.key, text];
|
|
7449
|
+
return [row.key, worded(options, row.datum, {
|
|
7450
|
+
key: row.key,
|
|
7451
|
+
category: row.label,
|
|
7452
|
+
values: labelled(row.values, options),
|
|
7453
|
+
total: total(row.values),
|
|
7454
|
+
format: formatted,
|
|
7455
|
+
text
|
|
7456
|
+
})];
|
|
6884
7457
|
}));
|
|
6885
7458
|
}
|
|
7459
|
+
function pointNamesFor(options, layout) {
|
|
7460
|
+
const formatted = format(options);
|
|
7461
|
+
return new Map(layout.rows.flatMap((row) => labelled(row.values, options).map((value) => {
|
|
7462
|
+
const key = pointKey(value.series, row.key);
|
|
7463
|
+
const text = `${row.label}: ${formatted(value.value)} ${value.label}`;
|
|
7464
|
+
return [key, worded(options, row.datum, {
|
|
7465
|
+
key,
|
|
7466
|
+
category: row.label,
|
|
7467
|
+
values: [value],
|
|
7468
|
+
total: value.value,
|
|
7469
|
+
format: formatted,
|
|
7470
|
+
text
|
|
7471
|
+
})];
|
|
7472
|
+
})));
|
|
7473
|
+
}
|
|
7474
|
+
function hoverOf(options) {
|
|
7475
|
+
const { hover = "x" } = options;
|
|
7476
|
+
if (hover !== "x" && hover !== "point") throw new TypeError(`lineChart: hover must be "x" or "point", got ${typeof hover === "string" ? JSON.stringify(hover) : String(hover)}.`);
|
|
7477
|
+
return hover;
|
|
7478
|
+
}
|
|
6886
7479
|
// src/core/geometry/ring.ts
|
|
6887
7480
|
const ROUND = .5;
|
|
6888
7481
|
function goesRound(mark) {
|
|
6889
|
-
const radius = distance$
|
|
6890
|
-
return radius > ROUND && Math.abs(distance$
|
|
7482
|
+
const radius = distance$2(mark.start, mark.pivot);
|
|
7483
|
+
return radius > ROUND && Math.abs(distance$2(mark.center, mark.pivot) - radius) <= ROUND && Math.abs(distance$2(mark.end, mark.pivot) - radius) <= ROUND;
|
|
6891
7484
|
}
|
|
6892
|
-
const distance$
|
|
7485
|
+
const distance$2 = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
|
|
6893
7486
|
// src/charts/adapter/bars.ts
|
|
6894
7487
|
const SAME = .5;
|
|
6895
7488
|
const BASELINES = [
|
|
@@ -6938,10 +7531,10 @@ function describeRects(key, parts, baseline) {
|
|
|
6938
7531
|
...box,
|
|
6939
7532
|
baseline,
|
|
6940
7533
|
radius: tip.radius,
|
|
6941
|
-
gap: Number.isFinite(gap) ? Math.max(0, round$
|
|
7534
|
+
gap: Number.isFinite(gap) ? Math.max(0, round$4(gap)) : 0,
|
|
6942
7535
|
...segments.every((s) => s.series !== void 0) ? { segments: segments.map((s) => ({
|
|
6943
7536
|
series: s.series,
|
|
6944
|
-
size: round$
|
|
7537
|
+
size: round$4(s.size)
|
|
6945
7538
|
})) } : {}
|
|
6946
7539
|
}),
|
|
6947
7540
|
order: order.map((o) => o.index)
|
|
@@ -6959,8 +7552,8 @@ function union(boxes) {
|
|
|
6959
7552
|
return {
|
|
6960
7553
|
x,
|
|
6961
7554
|
y,
|
|
6962
|
-
width: round$
|
|
6963
|
-
height: round$
|
|
7555
|
+
width: round$4(Math.max(...boxes.map((b) => b.x + b.width)) - x),
|
|
7556
|
+
height: round$4(Math.max(...boxes.map((b) => b.y + b.height)) - y)
|
|
6964
7557
|
};
|
|
6965
7558
|
}
|
|
6966
7559
|
function commonLine(boxes, nearEdge, farEdge, near, far) {
|
|
@@ -7001,7 +7594,7 @@ function spanFrom(mark, baseline) {
|
|
|
7001
7594
|
});
|
|
7002
7595
|
}
|
|
7003
7596
|
}
|
|
7004
|
-
function round$
|
|
7597
|
+
function round$4(value) {
|
|
7005
7598
|
return Math.round(value * 1e3) / 1e3;
|
|
7006
7599
|
}
|
|
7007
7600
|
// src/charts/adapter/edits.ts
|
|
@@ -7177,13 +7770,13 @@ function boxIn(m, rect) {
|
|
|
7177
7770
|
].map((corner) => matrix.apply(m, corner));
|
|
7178
7771
|
const xs = corners.map((p) => p.x);
|
|
7179
7772
|
const ys = corners.map((p) => p.y);
|
|
7180
|
-
const x = round$
|
|
7181
|
-
const y = round$
|
|
7773
|
+
const x = round$3(Math.min(...xs));
|
|
7774
|
+
const y = round$3(Math.min(...ys));
|
|
7182
7775
|
return {
|
|
7183
7776
|
x,
|
|
7184
7777
|
y,
|
|
7185
|
-
width: round$
|
|
7186
|
-
height: round$
|
|
7778
|
+
width: round$3(round$3(Math.max(...xs)) - x),
|
|
7779
|
+
height: round$3(round$3(Math.max(...ys)) - y)
|
|
7187
7780
|
};
|
|
7188
7781
|
}
|
|
7189
7782
|
function rectOf(element) {
|
|
@@ -7201,6 +7794,7 @@ function rectOf(element) {
|
|
|
7201
7794
|
}
|
|
7202
7795
|
function attributesOf(element) {
|
|
7203
7796
|
return (name) => {
|
|
7797
|
+
if (!element.hasAttribute(name)) return null;
|
|
7204
7798
|
const animated = element[name];
|
|
7205
7799
|
return typeof animated?.baseVal?.value === "number" ? String(animated.baseVal.value) : element.getAttribute(name);
|
|
7206
7800
|
};
|
|
@@ -7228,7 +7822,7 @@ function fromRoot(element, root) {
|
|
|
7228
7822
|
for (let node = element; node && node !== root; node = node.parentElement) m = matrix.multiply(ownTransform(node), m);
|
|
7229
7823
|
return m;
|
|
7230
7824
|
}
|
|
7231
|
-
function round$
|
|
7825
|
+
function round$3(value) {
|
|
7232
7826
|
return Math.round(value * 1e3) / 1e3;
|
|
7233
7827
|
}
|
|
7234
7828
|
// src/charts/adapter/host-style.ts
|
|
@@ -7280,9 +7874,9 @@ function hostMarkHandle(parts, edits, halos) {
|
|
|
7280
7874
|
};
|
|
7281
7875
|
}
|
|
7282
7876
|
function hostColors(element, root) {
|
|
7283
|
-
const fill = paintOf(element, root, "fill");
|
|
7877
|
+
const fill = paintOf$1(element, root, "fill");
|
|
7284
7878
|
const paint = fill === NONE ? "stroke" : "fill";
|
|
7285
|
-
const color = paint === "fill" ? fill : paintOf(element, root, "stroke");
|
|
7879
|
+
const color = paint === "fill" ? fill : paintOf$1(element, root, "stroke");
|
|
7286
7880
|
if (color === void 0 || color === NONE) return void 0;
|
|
7287
7881
|
return {
|
|
7288
7882
|
color,
|
|
@@ -7307,7 +7901,7 @@ function attributesComputed(root) {
|
|
|
7307
7901
|
probed.set(root, computed);
|
|
7308
7902
|
return computed;
|
|
7309
7903
|
}
|
|
7310
|
-
function paintOf(element, root, property) {
|
|
7904
|
+
function paintOf$1(element, root, property) {
|
|
7311
7905
|
const raw = element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue(property);
|
|
7312
7906
|
const computed = kind(raw);
|
|
7313
7907
|
if (raw && attributesComputed(root)) return computed;
|
|
@@ -7320,15 +7914,28 @@ function paintOf(element, root, property) {
|
|
|
7320
7914
|
return computed !== void 0 && !(initial && declared !== void 0) ? computed : kind(declared);
|
|
7321
7915
|
}
|
|
7322
7916
|
function strokeWidthOf(element, root) {
|
|
7323
|
-
const
|
|
7917
|
+
const style = element.ownerDocument.defaultView?.getComputedStyle?.(element);
|
|
7918
|
+
const raw = style?.getPropertyValue("stroke-width");
|
|
7324
7919
|
const computed = pixels$1(raw);
|
|
7325
|
-
|
|
7920
|
+
const effect = style?.getPropertyValue("vector-effect").trim().toLowerCase();
|
|
7921
|
+
const declared = element.style?.getPropertyValue("vector-effect") ? effect : element.getAttribute("vector-effect")?.trim().toLowerCase();
|
|
7922
|
+
const screen = (effect && (effect !== "none" || attributesComputed(root)) ? effect : declared) === "non-scaling-stroke";
|
|
7923
|
+
if (raw && attributesComputed(root) || computed !== void 0 && computed !== 1) return {
|
|
7924
|
+
width: computed,
|
|
7925
|
+
screen
|
|
7926
|
+
};
|
|
7326
7927
|
for (let node = element; node; node = node === root ? null : node.parentElement) {
|
|
7327
7928
|
if (node.style?.getPropertyValue("stroke-width")) break;
|
|
7328
7929
|
const width = pixels$1(node.getAttribute("stroke-width"));
|
|
7329
|
-
if (width !== void 0) return
|
|
7930
|
+
if (width !== void 0) return {
|
|
7931
|
+
width,
|
|
7932
|
+
screen
|
|
7933
|
+
};
|
|
7330
7934
|
}
|
|
7331
|
-
return
|
|
7935
|
+
return {
|
|
7936
|
+
width: computed,
|
|
7937
|
+
screen
|
|
7938
|
+
};
|
|
7332
7939
|
}
|
|
7333
7940
|
function pixels$1(value) {
|
|
7334
7941
|
const match = /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)\s*(?:px\s*)?$/i.exec(value ?? "");
|
|
@@ -7350,6 +7957,183 @@ function mix$2(colors, emphasis) {
|
|
|
7350
7957
|
function cssMatrix(m) {
|
|
7351
7958
|
return `matrix(${m.map((v, i) => i < 4 ? Math.round(v * 1e6) / 1e6 : Math.round(v * 1e3) / 1e3).join(", ")})`;
|
|
7352
7959
|
}
|
|
7960
|
+
// src/charts/adapter/slice.ts
|
|
7961
|
+
const NEAR = .5;
|
|
7962
|
+
const MOST = 32;
|
|
7963
|
+
function sliceOf$1(commands, m) {
|
|
7964
|
+
const scale = scaleOf$1(m);
|
|
7965
|
+
if (!keepsCircles(m) || !(scale > 0) || commands.length > MOST || commands.some((command) => command.op === "C" || command.op === "Q")) return void 0;
|
|
7966
|
+
const near = NEAR / scale;
|
|
7967
|
+
const subpaths = flattenPath(commands);
|
|
7968
|
+
if (subpaths.length === 0 || subpaths.length > 2 || !subpaths.every(closes)) return void 0;
|
|
7969
|
+
const runs = subpaths.map((subpath) => runsOf(subpath.segments, near));
|
|
7970
|
+
const own = subpaths.length === 2 ? ring(runs[0], runs[1], near) : slice(runs[0], near);
|
|
7971
|
+
return own && moved(own, m);
|
|
7972
|
+
}
|
|
7973
|
+
function ring(a, b, near) {
|
|
7974
|
+
const [first, second] = [a[0], b[0]];
|
|
7975
|
+
if (a.length !== 1 || b.length !== 1 || first?.kind !== "arc" || second?.kind !== "arc") return void 0;
|
|
7976
|
+
const [outer, inner] = first.radius >= second.radius ? [first, second] : [second, first];
|
|
7977
|
+
const whole = (turn, radius) => Math.abs(Math.abs(turn) - TAU$2) * radius <= near;
|
|
7978
|
+
for (const center of [centerOf(outer), outer.arcs[0].center]) {
|
|
7979
|
+
if (!center) continue;
|
|
7980
|
+
const [r1, r0] = [distance$1(outer.from, center), distance$1(inner.from, center)];
|
|
7981
|
+
const [t1, t0] = [turnOf(outer, center), turnOf(inner, center)];
|
|
7982
|
+
if (r1 > near && r1 - r0 > near && Math.sign(t1) !== Math.sign(t0) && whole(t1, r1) && whole(t0, r0) && onCircle(outer, center, r1, near) && onCircle(inner, center, r0, near)) return {
|
|
7983
|
+
center,
|
|
7984
|
+
inner: r0,
|
|
7985
|
+
outer: r1,
|
|
7986
|
+
start: angleOf(outer.from, center),
|
|
7987
|
+
sweep: Math.sign(t1) * TAU$2
|
|
7988
|
+
};
|
|
7989
|
+
}
|
|
7990
|
+
}
|
|
7991
|
+
function slice(runs, near) {
|
|
7992
|
+
let first = -1;
|
|
7993
|
+
runs.forEach((run, i) => {
|
|
7994
|
+
if (run.kind === "arc" && (first < 0 || run.radius > runs[first].radius)) first = i;
|
|
7995
|
+
});
|
|
7996
|
+
if (first < 0) return void 0;
|
|
7997
|
+
const cycle = [...runs.slice(first), ...runs.slice(0, first)];
|
|
7998
|
+
const outer = cycle[0];
|
|
7999
|
+
const [, side, third, fourth] = cycle;
|
|
8000
|
+
const pie = cycle.length === 3 && side?.kind === "line" && third?.kind === "line";
|
|
8001
|
+
const back = cycle.length === 4 && side?.kind === "line" && third?.kind === "arc" && fourth?.kind === "line" ? third : void 0;
|
|
8002
|
+
if (!pie && !back) return void 0;
|
|
8003
|
+
const [inEnd, inStart] = back ? [back.from, back.to] : [side.to, side.to];
|
|
8004
|
+
const toward = (from, to) => {
|
|
8005
|
+
const length = distance$1(from, to);
|
|
8006
|
+
return length > near ? {
|
|
8007
|
+
x: from.x + (to.x - from.x) * outer.radius / length,
|
|
8008
|
+
y: from.y + (to.y - from.y) * outer.radius / length
|
|
8009
|
+
} : void 0;
|
|
8010
|
+
};
|
|
8011
|
+
const a = toward(outer.from, inStart);
|
|
8012
|
+
const b = toward(outer.to, inEnd);
|
|
8013
|
+
if (!a || !b) return void 0;
|
|
8014
|
+
let center = {
|
|
8015
|
+
x: (a.x + b.x) / 2,
|
|
8016
|
+
y: (a.y + b.y) / 2
|
|
8017
|
+
};
|
|
8018
|
+
if (pie && distance$1(inEnd, center) <= near) center = inEnd;
|
|
8019
|
+
const inner = center === inEnd ? 0 : (distance$1(inEnd, center) + distance$1(inStart, center)) / 2;
|
|
8020
|
+
const sweep = turnOf(outer, center);
|
|
8021
|
+
if (sweep === 0) return void 0;
|
|
8022
|
+
const own = {
|
|
8023
|
+
center,
|
|
8024
|
+
inner,
|
|
8025
|
+
outer: (distance$1(outer.from, center) + distance$1(outer.to, center)) / 2,
|
|
8026
|
+
start: angleOf(outer.from, center),
|
|
8027
|
+
sweep
|
|
8028
|
+
};
|
|
8029
|
+
return checked(own, outer, back, [inEnd, inStart], near) ? own : void 0;
|
|
8030
|
+
}
|
|
8031
|
+
function checked(own, outer, back, [inEnd, inStart], near) {
|
|
8032
|
+
const { center, start, sweep } = own;
|
|
8033
|
+
const at = (radius, angle) => ({
|
|
8034
|
+
x: center.x + radius * Math.cos(angle),
|
|
8035
|
+
y: center.y + radius * Math.sin(angle)
|
|
8036
|
+
});
|
|
8037
|
+
return own.outer > near && own.outer - own.inner > near && distance$1(outer.from, at(own.outer, start)) <= near && distance$1(outer.to, at(own.outer, start + sweep)) <= near && onCircle(outer, center, own.outer, near) && distance$1(inEnd, at(own.inner, start + sweep)) <= near && distance$1(inStart, at(own.inner, start)) <= near && (!back || Math.abs(turnOf(back, center) + sweep) * own.inner <= near && onCircle(back, center, own.inner, near));
|
|
8038
|
+
}
|
|
8039
|
+
function turnOf(run, center) {
|
|
8040
|
+
let turn = 0;
|
|
8041
|
+
for (const arc of run.arcs) {
|
|
8042
|
+
const step = normalizeAngle(angleOf(pointOn(arc, 1), center) - angleOf(pointOn(arc, 0), center));
|
|
8043
|
+
turn += step + TAU$2 * Math.round((arc.sweep - step) / TAU$2);
|
|
8044
|
+
}
|
|
8045
|
+
return turn;
|
|
8046
|
+
}
|
|
8047
|
+
function centerOf(run) {
|
|
8048
|
+
const points = [run.from, ...run.arcs.slice(0, -1).map((arc) => pointOn(arc, 1))];
|
|
8049
|
+
if (points.length < 2) return void 0;
|
|
8050
|
+
if (points.length === 2) return {
|
|
8051
|
+
x: (points[0].x + points[1].x) / 2,
|
|
8052
|
+
y: (points[0].y + points[1].y) / 2
|
|
8053
|
+
};
|
|
8054
|
+
const [p, q, r] = [
|
|
8055
|
+
points[0],
|
|
8056
|
+
points[Math.floor(points.length / 3)],
|
|
8057
|
+
points[Math.floor(2 * points.length / 3)]
|
|
8058
|
+
];
|
|
8059
|
+
const d = 2 * (p.x * (q.y - r.y) + q.x * (r.y - p.y) + r.x * (p.y - q.y));
|
|
8060
|
+
if (!(Math.abs(d) > 0)) return void 0;
|
|
8061
|
+
const [pp, qq, rr] = [
|
|
8062
|
+
p,
|
|
8063
|
+
q,
|
|
8064
|
+
r
|
|
8065
|
+
].map(({ x, y }) => x * x + y * y);
|
|
8066
|
+
return {
|
|
8067
|
+
x: (pp * (q.y - r.y) + qq * (r.y - p.y) + rr * (p.y - q.y)) / d,
|
|
8068
|
+
y: (pp * (r.x - q.x) + qq * (p.x - r.x) + rr * (q.x - p.x)) / d
|
|
8069
|
+
};
|
|
8070
|
+
}
|
|
8071
|
+
const onCircle = (run, center, radius, near) => Math.abs(run.radius - radius) <= near && run.arcs.every((arc) => [
|
|
8072
|
+
0,
|
|
8073
|
+
.5,
|
|
8074
|
+
1
|
|
8075
|
+
].every((u) => Math.abs(distance$1(pointOn(arc, u), center) - radius) <= near));
|
|
8076
|
+
function moved(own, m) {
|
|
8077
|
+
const scale = scaleOf$1(m);
|
|
8078
|
+
const center = matrix.apply(m, own.center);
|
|
8079
|
+
const corner = matrix.apply(m, {
|
|
8080
|
+
x: own.center.x + own.outer * Math.cos(own.start),
|
|
8081
|
+
y: own.center.y + own.outer * Math.sin(own.start)
|
|
8082
|
+
});
|
|
8083
|
+
const sweep = m[0] * m[3] - m[1] * m[2] < 0 ? -own.sweep : own.sweep;
|
|
8084
|
+
let start = ((angleOf(corner, center) + Math.PI / 2) % TAU$2 + TAU$2) % TAU$2;
|
|
8085
|
+
if (start > TAU$2 - 1e-9) start = 0;
|
|
8086
|
+
return {
|
|
8087
|
+
cx: round$2(center.x),
|
|
8088
|
+
cy: round$2(center.y),
|
|
8089
|
+
inner: round$2(own.inner * scale),
|
|
8090
|
+
outer: round$2(own.outer * scale),
|
|
8091
|
+
start,
|
|
8092
|
+
end: start + sweep
|
|
8093
|
+
};
|
|
8094
|
+
}
|
|
8095
|
+
function runsOf(segments, near) {
|
|
8096
|
+
const runs = [];
|
|
8097
|
+
const join = (run, arc) => run !== void 0 && Math.sign(run.sweep) === Math.sign(arc.sweep) && Math.abs(run.radius - arc.radius) <= near;
|
|
8098
|
+
for (const segment of segments) {
|
|
8099
|
+
const last = runs[runs.length - 1];
|
|
8100
|
+
if (segment.kind === "line") runs.push({
|
|
8101
|
+
kind: "line",
|
|
8102
|
+
from: segment.from,
|
|
8103
|
+
to: segment.to
|
|
8104
|
+
});
|
|
8105
|
+
else if (last?.kind === "arc" && join(last, segment)) runs[runs.length - 1] = {
|
|
8106
|
+
...last,
|
|
8107
|
+
arcs: [...last.arcs, segment],
|
|
8108
|
+
to: pointOn(segment, 1),
|
|
8109
|
+
sweep: last.sweep + segment.sweep
|
|
8110
|
+
};
|
|
8111
|
+
else runs.push({
|
|
8112
|
+
kind: "arc",
|
|
8113
|
+
arcs: [segment],
|
|
8114
|
+
from: pointOn(segment, 0),
|
|
8115
|
+
to: pointOn(segment, 1),
|
|
8116
|
+
radius: segment.radius,
|
|
8117
|
+
sweep: segment.sweep
|
|
8118
|
+
});
|
|
8119
|
+
}
|
|
8120
|
+
const [head] = runs;
|
|
8121
|
+
const tail = runs[runs.length - 1];
|
|
8122
|
+
if (runs.length > 1 && head?.kind === "arc" && tail?.kind === "arc" && tail.arcs.every((arc) => join(head, arc))) {
|
|
8123
|
+
runs[0] = {
|
|
8124
|
+
...head,
|
|
8125
|
+
arcs: [...tail.arcs, ...head.arcs],
|
|
8126
|
+
from: tail.from,
|
|
8127
|
+
sweep: tail.sweep + head.sweep
|
|
8128
|
+
};
|
|
8129
|
+
runs.pop();
|
|
8130
|
+
}
|
|
8131
|
+
return runs;
|
|
8132
|
+
}
|
|
8133
|
+
const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
|
|
8134
|
+
const angleOf = (point, center) => Math.atan2(point.y - center.y, point.x - center.x);
|
|
8135
|
+
const distance$1 = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
|
|
8136
|
+
const round$2 = (value) => Math.round(value * 1e3) / 1e3 + 0;
|
|
7353
8137
|
// src/charts/adapter/source.ts
|
|
7354
8138
|
function readSource(source) {
|
|
7355
8139
|
if (typeof source === "string") {
|
|
@@ -7559,7 +8343,7 @@ function expressive$1(target, options, env) {
|
|
|
7559
8343
|
common,
|
|
7560
8344
|
screen: screenMatrices(),
|
|
7561
8345
|
colors: (element) => colorsOf(element, svg),
|
|
7562
|
-
|
|
8346
|
+
stroke: (element) => strokeWidthOf(element, svg)
|
|
7563
8347
|
};
|
|
7564
8348
|
const named = (mark) => ({
|
|
7565
8349
|
...mark,
|
|
@@ -7575,7 +8359,7 @@ function expressive$1(target, options, env) {
|
|
|
7575
8359
|
const shapes = [];
|
|
7576
8360
|
keys.forEach((key, index) => {
|
|
7577
8361
|
const pieces = groups.get(key);
|
|
7578
|
-
if (pieces[0].element.localName === "rect") bars.push(index);
|
|
8362
|
+
if (pieces[0].element.localName === "rect" && !turned(pieces, at)) bars.push(index);
|
|
7579
8363
|
else {
|
|
7580
8364
|
const mark = shapeMark(key, pieces[0], index, at);
|
|
7581
8365
|
if (mark) shapes.push(mark);
|
|
@@ -7602,9 +8386,12 @@ function expressive$1(target, options, env) {
|
|
|
7602
8386
|
index
|
|
7603
8387
|
};
|
|
7604
8388
|
}
|
|
8389
|
+
function turned(pieces, at) {
|
|
8390
|
+
return pieces.length === 1 && !axisAligned(transformOf(pieces[0].element, at));
|
|
8391
|
+
}
|
|
7605
8392
|
function rectPiece(key, piece, at) {
|
|
7606
8393
|
const m = transformOf(piece.element, at);
|
|
7607
|
-
if (!axisAligned(m)) throw new TypeError(`expressive: the <rect> of "${key}" is rotated or skewed, so it isn't an upright bar.
|
|
8394
|
+
if (!axisAligned(m)) throw new TypeError(`expressive: the <rect> of "${key}" is rotated or skewed, so it isn't an upright bar's segment. A rect turned on its own is a shape, a mark of its own: give each its own key, or describe the bar with the geometry option.`);
|
|
7608
8395
|
return {
|
|
7609
8396
|
...piece,
|
|
7610
8397
|
rect: {
|
|
@@ -7642,7 +8429,7 @@ function expressive$1(target, options, env) {
|
|
|
7642
8429
|
};
|
|
7643
8430
|
const r = tag === "circle" ? length("r") : 0;
|
|
7644
8431
|
let geometry;
|
|
7645
|
-
let
|
|
8432
|
+
let stroke;
|
|
7646
8433
|
if (tag === "circle" && (keepsCircles(m) || !(r > 0))) {
|
|
7647
8434
|
const center = matrix.apply(m, {
|
|
7648
8435
|
x: length("cx"),
|
|
@@ -7658,20 +8445,28 @@ function expressive$1(target, options, env) {
|
|
|
7658
8445
|
} else {
|
|
7659
8446
|
const commands = shapeOutline(tag, attribute);
|
|
7660
8447
|
if (commands[0]?.op !== "M" || commands.every((command) => command.op === "M")) return void 0;
|
|
7661
|
-
|
|
7662
|
-
const
|
|
7663
|
-
|
|
7664
|
-
geometry = describeShape({
|
|
8448
|
+
stroke = tag === "circle" ? void 0 : at.stroke(element);
|
|
8449
|
+
const slice = tag === "path" ? sliceOf$1(commands, m) : void 0;
|
|
8450
|
+
if (slice) geometry = describeArc({
|
|
7665
8451
|
key,
|
|
7666
8452
|
series,
|
|
7667
|
-
|
|
7668
|
-
matrix: m,
|
|
7669
|
-
width: width > 0 ? width : 1
|
|
8453
|
+
...slice
|
|
7670
8454
|
});
|
|
8455
|
+
else {
|
|
8456
|
+
const width = round$1(widthOf(stroke, m, at));
|
|
8457
|
+
const d = tag === "path" ? attribute("d") ?? "" : formatPath(commands);
|
|
8458
|
+
geometry = describeShape({
|
|
8459
|
+
key,
|
|
8460
|
+
series,
|
|
8461
|
+
d,
|
|
8462
|
+
matrix: m,
|
|
8463
|
+
width: width > 0 ? width : 1
|
|
8464
|
+
});
|
|
8465
|
+
}
|
|
7671
8466
|
}
|
|
7672
8467
|
const parts = [{
|
|
7673
8468
|
...part(piece, outlineOf(geometry, series, 1), at),
|
|
7674
|
-
|
|
8469
|
+
stroke
|
|
7675
8470
|
}];
|
|
7676
8471
|
return {
|
|
7677
8472
|
key,
|
|
@@ -7681,6 +8476,13 @@ function expressive$1(target, options, env) {
|
|
|
7681
8476
|
...tag === "circle" ? { circle: true } : {}
|
|
7682
8477
|
};
|
|
7683
8478
|
}
|
|
8479
|
+
function widthOf(stroke, m, at) {
|
|
8480
|
+
const width = stroke?.width ?? 1;
|
|
8481
|
+
if (!stroke?.screen) return width * scaleOf$1(m);
|
|
8482
|
+
const screen = at.screen(at.common);
|
|
8483
|
+
const scale = screen ? scaleOf$1(screen) : 0;
|
|
8484
|
+
return scale > 0 ? width / scale : width;
|
|
8485
|
+
}
|
|
7684
8486
|
function transformOf(element, at) {
|
|
7685
8487
|
return matrix.multiply(between$1(at.common, element.parentElement ?? at.svg, at.svg, at.screen), ownTransform(element));
|
|
7686
8488
|
}
|
|
@@ -8135,9 +8937,17 @@ function expressive$1(target, options, env) {
|
|
|
8135
8937
|
let overlayMoved = false;
|
|
8136
8938
|
for (const element of changes.ancestors) if (element.contains(ancestor)) overlayMoved = true;
|
|
8137
8939
|
else for (const record of order) if (record.mark.parts.some((part) => element.contains(part.element))) changed.add(record);
|
|
8138
|
-
|
|
8139
|
-
if (
|
|
8140
|
-
|
|
8940
|
+
const rescaled = /* @__PURE__ */ new Set();
|
|
8941
|
+
if (overlayMoved) {
|
|
8942
|
+
placeOverlay();
|
|
8943
|
+
for (const record of order) if (!changed.has(record) && record.mark.parts.some((part) => part.stroke?.screen)) rescaled.add(record);
|
|
8944
|
+
}
|
|
8945
|
+
if (changed.size === 0 && rescaled.size === 0) return;
|
|
8946
|
+
const read = reread([...changed, ...rescaled]);
|
|
8947
|
+
const kept = read.records.flatMap((record, i) => rescaled.has(record) && !geometryChanged(record.mark.geometry, read.marks[i].geometry) ? [] : [i]);
|
|
8948
|
+
if (kept.length === 0) return;
|
|
8949
|
+
const records = kept.map((i) => read.records[i]);
|
|
8950
|
+
const marks = kept.map((i) => read.marks[i]);
|
|
8141
8951
|
records.forEach((record, i) => {
|
|
8142
8952
|
const mark = marks[i];
|
|
8143
8953
|
record.mark = mark;
|
|
@@ -8159,7 +8969,7 @@ function expressive$1(target, options, env) {
|
|
|
8159
8969
|
common: ancestor,
|
|
8160
8970
|
screen: screenMatrices(),
|
|
8161
8971
|
colors: (element) => owners.get(element)?.part.colors,
|
|
8162
|
-
|
|
8972
|
+
stroke: (element) => owners.get(element)?.part.stroke
|
|
8163
8973
|
};
|
|
8164
8974
|
const rowOf = rowsNow();
|
|
8165
8975
|
const piecesOf = ({ parts }) => parts.map((part) => ({
|
|
@@ -8178,16 +8988,17 @@ function expressive$1(target, options, env) {
|
|
|
8178
8988
|
marks: withData(marks)
|
|
8179
8989
|
};
|
|
8180
8990
|
}
|
|
8181
|
-
const
|
|
8182
|
-
const
|
|
8183
|
-
|
|
8991
|
+
const shapes = new Set(changed.filter((record) => !record.mark.rect || turned(record.mark.parts, at)));
|
|
8992
|
+
const rects = new Map(changed.flatMap((record) => shapes.has(record) ? [] : [[record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at))]]));
|
|
8993
|
+
const edges = edgesNow(rects, shapes);
|
|
8994
|
+
for (const record of order) if (record.mark.rect && !rects.has(record) && !shapes.has(record) && edges.get(record) !== record.mark.rect.edge) rects.set(record, piecesOf(record.mark).map((piece) => rectPiece(record.key, piece, at)));
|
|
8184
8995
|
const records = [...rects.keys()];
|
|
8185
8996
|
const marks = records.map((record) => ({
|
|
8186
8997
|
...rectMark(record.key, rects.get(record), edges.get(record), record.mark.index, at),
|
|
8187
8998
|
label: record.mark.label
|
|
8188
8999
|
}));
|
|
8189
9000
|
for (const record of changed) {
|
|
8190
|
-
if (record
|
|
9001
|
+
if (!shapes.has(record)) continue;
|
|
8191
9002
|
const mark = shapeMark(record.key, piecesOf(record.mark)[0], record.mark.index, at);
|
|
8192
9003
|
if (!mark) continue;
|
|
8193
9004
|
records.push(record);
|
|
@@ -8201,8 +9012,8 @@ function expressive$1(target, options, env) {
|
|
|
8201
9012
|
marks: withData(marks)
|
|
8202
9013
|
};
|
|
8203
9014
|
}
|
|
8204
|
-
function edgesNow(rects) {
|
|
8205
|
-
const bars = order.filter((record) => record.mark.rect);
|
|
9015
|
+
function edgesNow(rects, shapes) {
|
|
9016
|
+
const bars = order.filter((record) => record.mark.rect && !shapes.has(record));
|
|
8206
9017
|
const kept = new Map(bars.map((record) => [record, record.mark.rect.edge]));
|
|
8207
9018
|
if (options.baseline !== void 0 && options.baseline !== "auto") return kept;
|
|
8208
9019
|
const boxes = bars.map((record) => {
|
|
@@ -8788,10 +9599,12 @@ function namesIn(root) {
|
|
|
8788
9599
|
}
|
|
8789
9600
|
const lineItems = (first) => first.mark?.items ?? [first];
|
|
8790
9601
|
const drawsLine = (first) => lineItems(first).some((item) => item.defined !== false);
|
|
9602
|
+
const straight = (first) => {
|
|
9603
|
+
const interpolate = lineItems(first)[0]?.interpolate;
|
|
9604
|
+
return interpolate === void 0 || interpolate === "linear";
|
|
9605
|
+
};
|
|
8791
9606
|
function pointsOf(first) {
|
|
8792
9607
|
const items = lineItems(first);
|
|
8793
|
-
const interpolate = items[0]?.interpolate;
|
|
8794
|
-
if (interpolate !== void 0 && interpolate !== "linear") throw new TypeError(`fromVegaView: a line is drawn with interpolate "${interpolate}", but only straight lines can be read. Use interpolate "linear" (the default), or describe the curve with expressive()'s geometry option.`);
|
|
8795
9608
|
const points = [];
|
|
8796
9609
|
let gap = false;
|
|
8797
9610
|
for (const item of items) {
|
|
@@ -8813,6 +9626,16 @@ function pointsOf(first) {
|
|
|
8813
9626
|
}
|
|
8814
9627
|
function lineOf(key, element, first, m) {
|
|
8815
9628
|
const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
|
|
9629
|
+
if (!straight(first)) {
|
|
9630
|
+
const scaled = width * scaleOf(m);
|
|
9631
|
+
return describeShape({
|
|
9632
|
+
key,
|
|
9633
|
+
series: key,
|
|
9634
|
+
d: element.getAttribute("d") ?? "",
|
|
9635
|
+
matrix: m,
|
|
9636
|
+
width: scaled > 0 && Number.isFinite(scaled) ? scaled : 1
|
|
9637
|
+
});
|
|
9638
|
+
}
|
|
8816
9639
|
const points = pointsOf(first);
|
|
8817
9640
|
const breaks = points.flatMap((p, i) => p.gapBefore ? [i] : []);
|
|
8818
9641
|
return describeLine({
|
|
@@ -8920,12 +9743,12 @@ function chartSwitch$1(target, options, env) {
|
|
|
8920
9743
|
const labelsLayer = svgElement("g", { class: "ec-switch-labels" }, overlay);
|
|
8921
9744
|
const announcer = options.announce ? chartAnnouncer(overlay) : void 0;
|
|
8922
9745
|
const orders = /* @__PURE__ */ new WeakMap();
|
|
8923
|
-
const
|
|
9746
|
+
const surfaceFor = (paints) => ({ group(key, order) {
|
|
8924
9747
|
const group = svgElement("g", {
|
|
8925
9748
|
class: "ec-run",
|
|
8926
9749
|
"data-key": key
|
|
8927
9750
|
}, runsLayer);
|
|
8928
|
-
setStyles(group, markColorStyles(seriesColors(colors.slot(key))));
|
|
9751
|
+
setStyles(group, markColorStyles(seriesColors(colors.slot(paints[order] ?? key))));
|
|
8929
9752
|
orders.set(group, order);
|
|
8930
9753
|
const above = Array.from(runsLayer.children).find((child) => (orders.get(child) ?? -Infinity) > order);
|
|
8931
9754
|
runsLayer.insertBefore(group, above ?? null);
|
|
@@ -8933,7 +9756,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
8933
9756
|
...svgLayer(group),
|
|
8934
9757
|
clear: () => group.remove()
|
|
8935
9758
|
};
|
|
8936
|
-
} };
|
|
9759
|
+
} });
|
|
8937
9760
|
let current = options.initial;
|
|
8938
9761
|
let active;
|
|
8939
9762
|
let destroyed = false;
|
|
@@ -8961,17 +9784,16 @@ function chartSwitch$1(target, options, env) {
|
|
|
8961
9784
|
const element = focused();
|
|
8962
9785
|
if (!element || !from.container.contains(element)) return void 0;
|
|
8963
9786
|
const keyed = element.closest("[data-key]");
|
|
8964
|
-
|
|
9787
|
+
const key = keyed && from.chart.element.contains(keyed) ? keyed.getAttribute("data-key") : null;
|
|
9788
|
+
return { keys: key === null ? [] : from.chart.standsFor?.(key) ?? [key] };
|
|
8965
9789
|
}
|
|
8966
9790
|
function restoreFocus(to, memory) {
|
|
8967
9791
|
if (!memory) return;
|
|
8968
9792
|
const now = focused();
|
|
8969
9793
|
if (now && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now)) return;
|
|
8970
9794
|
const inside = () => to.chart.element.contains(focused());
|
|
8971
|
-
|
|
8972
|
-
|
|
8973
|
-
for (const mark of to.chart.marks()) {
|
|
8974
|
-
to.chart.focus(mark.key);
|
|
9795
|
+
for (const key of [...memory.keys, ...to.chart.marks().map((mark) => mark.key)]) {
|
|
9796
|
+
to.chart.focus(key);
|
|
8975
9797
|
if (inside()) return;
|
|
8976
9798
|
}
|
|
8977
9799
|
}
|
|
@@ -9009,7 +9831,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
9009
9831
|
each.container.setAttribute("inert", "");
|
|
9010
9832
|
each.chart.element.classList.add("ec-morphing");
|
|
9011
9833
|
}
|
|
9012
|
-
const { pairs, scene } = prepare(from, to);
|
|
9834
|
+
const { pairs, surface, scene } = prepare(from, to);
|
|
9013
9835
|
const { done, settle } = deferred();
|
|
9014
9836
|
const session = {
|
|
9015
9837
|
a: from,
|
|
@@ -9020,6 +9842,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
9020
9842
|
from: b,
|
|
9021
9843
|
to: a
|
|
9022
9844
|
})),
|
|
9845
|
+
surface,
|
|
9023
9846
|
scene,
|
|
9024
9847
|
focus: memory,
|
|
9025
9848
|
progress: 0,
|
|
@@ -9046,7 +9869,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
9046
9869
|
const started = startClock(clock);
|
|
9047
9870
|
session.transition = playTransition(session.forward ? session.pairs : session.reversed, {
|
|
9048
9871
|
effect,
|
|
9049
|
-
surface,
|
|
9872
|
+
surface: session.surface,
|
|
9050
9873
|
start: begin,
|
|
9051
9874
|
motion,
|
|
9052
9875
|
clock: started.clock,
|
|
@@ -9099,16 +9922,27 @@ function chartSwitch$1(target, options, env) {
|
|
|
9099
9922
|
const to = b.chart.marks().map((mark) => mapMark(mark, toB));
|
|
9100
9923
|
const fromByKey = new Map(from.map((mark) => [mark.key, mark]));
|
|
9101
9924
|
const toKeys = new Set(to.map((mark) => mark.key));
|
|
9102
|
-
const pairs =
|
|
9925
|
+
const pairs = [];
|
|
9926
|
+
const paints = [];
|
|
9927
|
+
for (const mark of to) {
|
|
9103
9928
|
const partner = fromByKey.get(mark.key);
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9929
|
+
if (!partner) continue;
|
|
9930
|
+
const was = paintOf(a, partner);
|
|
9931
|
+
const will = paintOf(b, mark);
|
|
9932
|
+
if (!was.drawn && !will.drawn) continue;
|
|
9933
|
+
pairs.push({
|
|
9934
|
+
from: was.drawn ? partner : dot$1(partner),
|
|
9935
|
+
to: will.drawn ? mark : dot$1(mark)
|
|
9936
|
+
});
|
|
9937
|
+
paints.push(will.color);
|
|
9938
|
+
}
|
|
9109
9939
|
const drawings = [];
|
|
9110
|
-
|
|
9111
|
-
|
|
9940
|
+
const fade = (view, mark, opacity) => {
|
|
9941
|
+
const paint = paintOf(view, mark);
|
|
9942
|
+
if (paint.drawn) drawings.push(fadeMark(mark, paint.color, opacity));
|
|
9943
|
+
};
|
|
9944
|
+
for (const mark of from) if (!toKeys.has(mark.key)) fade(a, mark, fadeOut);
|
|
9945
|
+
for (const mark of to) if (!fromByKey.has(mark.key)) fade(b, mark, fadeIn);
|
|
9112
9946
|
const id = (label) => `${label.role}\n${label.key}`;
|
|
9113
9947
|
const labelsA = a.chart.labels();
|
|
9114
9948
|
const labelsB = b.chart.labels();
|
|
@@ -9128,6 +9962,7 @@ function chartSwitch$1(target, options, env) {
|
|
|
9128
9962
|
});
|
|
9129
9963
|
return {
|
|
9130
9964
|
pairs,
|
|
9965
|
+
surface: surfaceFor(paints),
|
|
9131
9966
|
scene: {
|
|
9132
9967
|
draw: (s) => {
|
|
9133
9968
|
for (const draw of drawings) draw(s);
|
|
@@ -9140,12 +9975,12 @@ function chartSwitch$1(target, options, env) {
|
|
|
9140
9975
|
}
|
|
9141
9976
|
};
|
|
9142
9977
|
}
|
|
9143
|
-
function fadeMark(mark, opacity) {
|
|
9978
|
+
function fadeMark(mark, color, opacity) {
|
|
9144
9979
|
const group = svgElement("g", {
|
|
9145
9980
|
class: "ec-switch-fade",
|
|
9146
9981
|
"data-key": mark.key
|
|
9147
9982
|
}, fadesLayer);
|
|
9148
|
-
setStyles(group, markColorStyles(seriesColors(colors.slot(
|
|
9983
|
+
setStyles(group, markColorStyles(seriesColors(colors.slot(color))));
|
|
9149
9984
|
svgLayer(group).path(mark.outline.d, mark.outline.closed ? { fill: "mark" } : {
|
|
9150
9985
|
stroke: "mark",
|
|
9151
9986
|
width: mark.thickness
|
|
@@ -9338,6 +10173,21 @@ const fadeOut = (s) => 1 - clamp$1(s / HALF);
|
|
|
9338
10173
|
const fadeIn = (s) => clamp$1((s - HALF) / .5);
|
|
9339
10174
|
const clamp$1 = (value) => Math.min(1, Math.max(0, value));
|
|
9340
10175
|
const mix$1 = (x, y, s) => x * (1 - s) + y * s;
|
|
10176
|
+
function paintOf(view, mark) {
|
|
10177
|
+
return view.chart.paintOf?.(mark.key) ?? {
|
|
10178
|
+
color: mark.key,
|
|
10179
|
+
drawn: true
|
|
10180
|
+
};
|
|
10181
|
+
}
|
|
10182
|
+
function dot$1(mark) {
|
|
10183
|
+
return describePoint({
|
|
10184
|
+
key: mark.key,
|
|
10185
|
+
...mark.series === void 0 ? {} : { series: mark.series },
|
|
10186
|
+
x: mark.center.x,
|
|
10187
|
+
y: mark.center.y,
|
|
10188
|
+
r: 0
|
|
10189
|
+
});
|
|
10190
|
+
}
|
|
9341
10191
|
const isIdentity = (m) => m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && m[4] === 0 && m[5] === 0;
|
|
9342
10192
|
function mapMark(mark, m) {
|
|
9343
10193
|
if (isIdentity(m)) return mark;
|
|
@@ -9359,6 +10209,7 @@ function mapMark(mark, m) {
|
|
|
9359
10209
|
return Math.atan2(m[1] * cos + m[3] * sin, m[0] * cos + m[2] * sin);
|
|
9360
10210
|
},
|
|
9361
10211
|
slice: (t0, t1) => path(mark.slice(t0, t1)),
|
|
10212
|
+
...mark.gaps === void 0 ? {} : { gaps: mark.gaps },
|
|
9362
10213
|
thickness: mark.thickness * scale,
|
|
9363
10214
|
outline: {
|
|
9364
10215
|
d: path(outline.d),
|
|
@@ -9573,7 +10424,7 @@ function checkOptions$8(options) {
|
|
|
9573
10424
|
for (const [key, text] of Object.entries(labels)) if (typeof text !== "string" || text.trim() === "") throw new TypeError(`playButton: labels.${key} must be a string with some text, got ${JSON.stringify(text) ?? String(text)}.`);
|
|
9574
10425
|
}
|
|
9575
10426
|
// src/effects/gaits.ts
|
|
9576
|
-
const STILL = Object.freeze({
|
|
10427
|
+
const STILL = /* @__PURE__ */ Object.freeze({
|
|
9577
10428
|
lift: 0,
|
|
9578
10429
|
spin: 0,
|
|
9579
10430
|
tilt: 0
|
|
@@ -10035,23 +10886,71 @@ const PAST_END = 10;
|
|
|
10035
10886
|
const PAST_LABEL = 6;
|
|
10036
10887
|
const TEXT = 12.5;
|
|
10037
10888
|
const CENTRE = .36;
|
|
10038
|
-
function captionPlace(mark) {
|
|
10039
|
-
const
|
|
10889
|
+
function captionPlace(mark, text) {
|
|
10890
|
+
const own = mark.labelBounds ?? [];
|
|
10891
|
+
const boxes = [
|
|
10892
|
+
...own,
|
|
10893
|
+
...mark.nearbyLabels ?? [],
|
|
10894
|
+
...text?.held ?? []
|
|
10895
|
+
];
|
|
10040
10896
|
const heading = mark.angle(1);
|
|
10041
|
-
|
|
10042
|
-
if (along === void 0 && boxes.length > 0) {
|
|
10897
|
+
if (farthest(mark.end, heading, own) === void 0) {
|
|
10043
10898
|
const up = mark.angle(.5) - Math.PI / 2;
|
|
10044
|
-
|
|
10045
|
-
if (out !== void 0) return placed(mark.center, up, out);
|
|
10899
|
+
if (farthest(mark.center, up, own) !== void 0) return past(mark.center, up, 0, own, boxes, text);
|
|
10046
10900
|
}
|
|
10047
|
-
return
|
|
10901
|
+
return past(mark.end, heading, PAST_END, own, boxes, text);
|
|
10902
|
+
}
|
|
10903
|
+
function past(from, toward, least, own, boxes, text) {
|
|
10904
|
+
if (!text) return placed(from, toward, Math.max(least, farthest(from, toward, boxes) ?? -Infinity));
|
|
10905
|
+
const { x, y, width, height } = text.box(placed(from, toward, 0));
|
|
10906
|
+
return placed(from, toward, clearOf(from, toward, Math.max(least, farthest(from, toward, own) ?? -Infinity), boxes, {
|
|
10907
|
+
x: x - from.x,
|
|
10908
|
+
y: y - from.y,
|
|
10909
|
+
width,
|
|
10910
|
+
height
|
|
10911
|
+
}, new Set(text.held)));
|
|
10048
10912
|
}
|
|
10913
|
+
function clearOf(from, toward, distance, boxes, reach, held) {
|
|
10914
|
+
const cos = Math.cos(toward);
|
|
10915
|
+
const sin = Math.sin(toward);
|
|
10916
|
+
const across = centred(cos);
|
|
10917
|
+
const meets = (box) => span(from, cos, sin, {
|
|
10918
|
+
x: box.x - reach.x - reach.width,
|
|
10919
|
+
y: box.y - reach.y - reach.height,
|
|
10920
|
+
width: box.width + reach.width,
|
|
10921
|
+
height: box.height + reach.height
|
|
10922
|
+
});
|
|
10923
|
+
const spans = boxes.map((box) => {
|
|
10924
|
+
const near = grow(box, PAST_LABEL);
|
|
10925
|
+
const band = span(from, cos, sin, near);
|
|
10926
|
+
if (!band && held.has(box)) return meets(box);
|
|
10927
|
+
const within = meets(near);
|
|
10928
|
+
if (!band || !within) return within;
|
|
10929
|
+
const leaving = across ? Math.max(band[1], ((sin > 0 ? near.y + near.height : near.y) - from.y) / sin) : band[1];
|
|
10930
|
+
return [within[0], Math.max(leaving, meets(box)?.[1] ?? -Infinity)];
|
|
10931
|
+
});
|
|
10932
|
+
let at = distance;
|
|
10933
|
+
for (let moved = true; moved;) {
|
|
10934
|
+
moved = false;
|
|
10935
|
+
for (const meets of spans) if (meets && at > meets[0] + 1e-6 && at < meets[1] - 1e-6) {
|
|
10936
|
+
at = meets[1];
|
|
10937
|
+
moved = true;
|
|
10938
|
+
}
|
|
10939
|
+
}
|
|
10940
|
+
return at;
|
|
10941
|
+
}
|
|
10942
|
+
const grow = ({ x, y, width, height }, by) => ({
|
|
10943
|
+
x: x - by,
|
|
10944
|
+
y: y - by,
|
|
10945
|
+
width: width + 2 * by,
|
|
10946
|
+
height: height + 2 * by
|
|
10947
|
+
});
|
|
10049
10948
|
function placed(from, toward, distance) {
|
|
10050
10949
|
const cos = Math.cos(toward);
|
|
10051
10950
|
const sin = Math.sin(toward);
|
|
10052
10951
|
const point = offset(from, toward, distance);
|
|
10053
10952
|
const drop = TEXT * (sin < 0 ? CENTRE * (1 + sin) : CENTRE + .44000000000000006 * sin);
|
|
10054
|
-
const anchor =
|
|
10953
|
+
const anchor = centred(cos) ? "middle" : cos > 0 ? "start" : "end";
|
|
10055
10954
|
return {
|
|
10056
10955
|
at: {
|
|
10057
10956
|
x: point.x,
|
|
@@ -10061,22 +10960,26 @@ function placed(from, toward, distance) {
|
|
|
10061
10960
|
toward
|
|
10062
10961
|
};
|
|
10063
10962
|
}
|
|
10963
|
+
function centred(cos) {
|
|
10964
|
+
return Math.abs(cos) <= Math.SQRT1_2 + 1e-9;
|
|
10965
|
+
}
|
|
10064
10966
|
function farthest(from, toward, boxes) {
|
|
10065
10967
|
const cos = Math.cos(toward);
|
|
10066
10968
|
const sin = Math.sin(toward);
|
|
10969
|
+
const across = centred(cos);
|
|
10067
10970
|
let exit;
|
|
10068
|
-
for (const
|
|
10069
|
-
const
|
|
10070
|
-
|
|
10071
|
-
|
|
10072
|
-
width: width + 12,
|
|
10073
|
-
height: height + 12
|
|
10074
|
-
});
|
|
10971
|
+
for (const box of boxes) {
|
|
10972
|
+
const grown = grow(box, PAST_LABEL);
|
|
10973
|
+
let leaving = leaves(from, cos, sin, grown);
|
|
10974
|
+
if (leaving !== void 0 && across) leaving = Math.max(leaving, ((sin > 0 ? grown.y + grown.height : grown.y) - from.y) / sin);
|
|
10075
10975
|
if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
|
|
10076
10976
|
}
|
|
10077
10977
|
return exit;
|
|
10078
10978
|
}
|
|
10079
10979
|
function leaves(from, cos, sin, box) {
|
|
10980
|
+
return span(from, cos, sin, box)?.[1];
|
|
10981
|
+
}
|
|
10982
|
+
function span(from, cos, sin, box) {
|
|
10080
10983
|
let near = 0;
|
|
10081
10984
|
let far = Infinity;
|
|
10082
10985
|
for (const [origin, step, lo, hi] of [[
|
|
@@ -10099,7 +11002,7 @@ function leaves(from, cos, sin, box) {
|
|
|
10099
11002
|
near = Math.max(near, Math.min(a, b));
|
|
10100
11003
|
far = Math.min(far, Math.max(a, b));
|
|
10101
11004
|
}
|
|
10102
|
-
return far >= near ? far : void 0;
|
|
11005
|
+
return far >= near ? [near, far] : void 0;
|
|
10103
11006
|
}
|
|
10104
11007
|
function caption(mark, data, ctx, color, words) {
|
|
10105
11008
|
let current = mark;
|
|
@@ -10107,13 +11010,22 @@ function caption(mark, data, ctx, color, words) {
|
|
|
10107
11010
|
let latest = data;
|
|
10108
11011
|
let progress = 0;
|
|
10109
11012
|
let handle;
|
|
11013
|
+
const { texts } = ctx;
|
|
10110
11014
|
const draw = () => {
|
|
10111
11015
|
if (content === "") {
|
|
10112
11016
|
handle?.remove();
|
|
10113
11017
|
handle = void 0;
|
|
11018
|
+
texts?.hold(void 0);
|
|
10114
11019
|
return;
|
|
10115
11020
|
}
|
|
10116
|
-
const { at, anchor, toward } = captionPlace(current
|
|
11021
|
+
const { at, anchor, toward } = captionPlace(current, texts && {
|
|
11022
|
+
held: texts.held(),
|
|
11023
|
+
box: (style) => texts.box(content, style)
|
|
11024
|
+
});
|
|
11025
|
+
texts?.hold(texts.box(content, {
|
|
11026
|
+
at,
|
|
11027
|
+
anchor
|
|
11028
|
+
}));
|
|
10117
11029
|
const style = {
|
|
10118
11030
|
at: offset(at, toward - Math.PI / 2, -8 * (1 - progress)),
|
|
10119
11031
|
anchor,
|
|
@@ -10401,6 +11313,9 @@ const show = (value) => typeof value === "string" ? JSON.stringify(value) : Stri
|
|
|
10401
11313
|
const DURATION = 950;
|
|
10402
11314
|
const POINTS = 160;
|
|
10403
11315
|
const ALIGNS = ["unroll", "drop"];
|
|
11316
|
+
const SAME_T = 1e-9;
|
|
11317
|
+
const GRID = 9;
|
|
11318
|
+
const CHECKS = 8;
|
|
10404
11319
|
function morph(options = {}) {
|
|
10405
11320
|
checkOptions(options);
|
|
10406
11321
|
const points = options?.points ?? POINTS;
|
|
@@ -10440,11 +11355,12 @@ function drawing(from, to, layer, points, align) {
|
|
|
10440
11355
|
if (closed !== to.outline.closed) return crossfade(from, to, layer);
|
|
10441
11356
|
const a = from.outline.sample(points);
|
|
10442
11357
|
const b = to.outline.sample(points);
|
|
10443
|
-
if (!closed) return stroke(from, to, layer, a, b);
|
|
11358
|
+
if (!closed) return from.gaps?.length || to.gaps?.length ? gapped(from, to, layer, a, b) : stroke(from, to, layer, a, b);
|
|
10444
11359
|
const [shiftA, shiftB] = align === "drop" ? turn(from, to, points) : [0, 0];
|
|
11360
|
+
const holes = holePairs(from, to, a, b, [shiftA, shiftB], points / 4);
|
|
10445
11361
|
let path;
|
|
10446
11362
|
return (p) => {
|
|
10447
|
-
const d = p <= 0 ? from.outline.d : p >= 1 ? to.outline.d : between(a, b, shiftA, shiftB, p, true);
|
|
11363
|
+
const d = p <= 0 ? from.outline.d : p >= 1 ? to.outline.d : between(a, b, shiftA, shiftB, p, true) + holes.map((hole) => holeAt(hole, p)).join("");
|
|
10448
11364
|
if (path) path.update(d);
|
|
10449
11365
|
else path = layer.path(d, { fill: "mark" });
|
|
10450
11366
|
};
|
|
@@ -10461,6 +11377,214 @@ function stroke(from, to, layer, a, b) {
|
|
|
10461
11377
|
});
|
|
10462
11378
|
};
|
|
10463
11379
|
}
|
|
11380
|
+
function gapped(from, to, layer, a, b) {
|
|
11381
|
+
const n = a.length;
|
|
11382
|
+
const stops = a.map((point, i) => ({
|
|
11383
|
+
t: i / (n - 1),
|
|
11384
|
+
from: point,
|
|
11385
|
+
to: b[i]
|
|
11386
|
+
}));
|
|
11387
|
+
for (const gap of [...from.gaps ?? [], ...to.gaps ?? []]) for (const t of gap) if (t > 0 && t < 1 && stops.every((stop) => Math.abs(stop.t - t) > SAME_T)) stops.push({
|
|
11388
|
+
t,
|
|
11389
|
+
from: from.path(t),
|
|
11390
|
+
to: to.path(t)
|
|
11391
|
+
});
|
|
11392
|
+
stops.sort((x, y) => x.t - y.t);
|
|
11393
|
+
const runs = [
|
|
11394
|
+
[],
|
|
11395
|
+
[],
|
|
11396
|
+
[]
|
|
11397
|
+
];
|
|
11398
|
+
for (let k = 0; k + 1 < stops.length; k++) {
|
|
11399
|
+
const t = (stops[k].t + stops[k + 1].t) / 2;
|
|
11400
|
+
const kind = (inGap(from, t) ? 1 : 0) + (inGap(to, t) ? 2 : 0);
|
|
11401
|
+
if (kind === 3) continue;
|
|
11402
|
+
const last = runs[kind][runs[kind].length - 1];
|
|
11403
|
+
if (last && last[1] === k) last[1] = k + 1;
|
|
11404
|
+
else runs[kind].push([k, k + 1]);
|
|
11405
|
+
}
|
|
11406
|
+
const kinds = [
|
|
11407
|
+
0,
|
|
11408
|
+
1,
|
|
11409
|
+
2
|
|
11410
|
+
].filter((kind) => runs[kind].length > 0).sort((x, y) => runs[x][0][0] - runs[y][0][0]);
|
|
11411
|
+
const paths = [];
|
|
11412
|
+
return (p) => {
|
|
11413
|
+
const width = p <= 0 ? from.thickness : p >= 1 ? to.thickness : mix(from.thickness, to.thickness, p);
|
|
11414
|
+
const opacities = [
|
|
11415
|
+
void 0,
|
|
11416
|
+
p,
|
|
11417
|
+
1 - p
|
|
11418
|
+
];
|
|
11419
|
+
const pieces = p <= 0 || p >= 1 ? [[p <= 0 ? from.outline.d : to.outline.d, void 0]] : kinds.map((kind) => [runs[kind].map((run) => along(stops, run, p)).join(""), opacities[kind]]);
|
|
11420
|
+
pieces.forEach(([d, opacity], i) => {
|
|
11421
|
+
if (paths[i]) paths[i].update(d, {
|
|
11422
|
+
width,
|
|
11423
|
+
opacity
|
|
11424
|
+
});
|
|
11425
|
+
else paths[i] = layer.path(d, {
|
|
11426
|
+
stroke: "mark",
|
|
11427
|
+
width,
|
|
11428
|
+
...opacity === void 0 ? {} : { opacity }
|
|
11429
|
+
});
|
|
11430
|
+
});
|
|
11431
|
+
for (const path of paths.splice(pieces.length)) path.remove();
|
|
11432
|
+
};
|
|
11433
|
+
}
|
|
11434
|
+
const inGap = (mark, t) => (mark.gaps ?? []).some(([x, y]) => x < t && t < y);
|
|
11435
|
+
function along(stops, [first, last], p) {
|
|
11436
|
+
let d = "";
|
|
11437
|
+
for (let k = first; k <= last; k++) d += `${k === first ? "M" : "L"}${at(stops[k].from, stops[k].to, p)}`;
|
|
11438
|
+
return d;
|
|
11439
|
+
}
|
|
11440
|
+
function holePairs(from, to, a, b, [shiftA, shiftB], count) {
|
|
11441
|
+
const holesA = holesOf(from.outline, count);
|
|
11442
|
+
const holesB = holesOf(to.outline, count);
|
|
11443
|
+
const both = Math.min(holesA.length, holesB.length);
|
|
11444
|
+
const pairs = holesA.slice(0, both).map((hole, k) => ({
|
|
11445
|
+
from: hole.points,
|
|
11446
|
+
to: holesB[k].points
|
|
11447
|
+
}));
|
|
11448
|
+
const closes = holesA.length > holesB.length;
|
|
11449
|
+
const [ownHoles, otherHoles, other, own, theirs, ownShift, otherShift] = closes ? [
|
|
11450
|
+
holesA,
|
|
11451
|
+
holesB,
|
|
11452
|
+
to,
|
|
11453
|
+
a,
|
|
11454
|
+
b,
|
|
11455
|
+
shiftA,
|
|
11456
|
+
shiftB
|
|
11457
|
+
] : [
|
|
11458
|
+
holesB,
|
|
11459
|
+
holesA,
|
|
11460
|
+
from,
|
|
11461
|
+
b,
|
|
11462
|
+
a,
|
|
11463
|
+
shiftB,
|
|
11464
|
+
shiftA
|
|
11465
|
+
];
|
|
11466
|
+
const n = own.length;
|
|
11467
|
+
const outside = own.map((_, i) => [own[(i + ownShift) % n], theirs[(i + otherShift) % n]]);
|
|
11468
|
+
const inner = ownHoles.slice(0, both).map((hole, k) => hole.points.map((p, i) => [p, otherHoles[k].points[i]]));
|
|
11469
|
+
const area = [theirs, ...otherHoles.map((hole) => hole.points)];
|
|
11470
|
+
for (const hole of ownHoles.slice(both)) {
|
|
11471
|
+
const { end, point } = closing(hole, landing(hole, (closes ? from : to).bounds, other, area), outside, inner);
|
|
11472
|
+
const dot = new Array(count).fill(point);
|
|
11473
|
+
pairs.push(closes ? {
|
|
11474
|
+
from: hole.points,
|
|
11475
|
+
to: dot,
|
|
11476
|
+
end
|
|
11477
|
+
} : {
|
|
11478
|
+
from: dot,
|
|
11479
|
+
to: hole.points,
|
|
11480
|
+
end,
|
|
11481
|
+
opens: true
|
|
11482
|
+
});
|
|
11483
|
+
}
|
|
11484
|
+
return pairs;
|
|
11485
|
+
}
|
|
11486
|
+
function closing(hole, there, outside, inner) {
|
|
11487
|
+
let end = .5;
|
|
11488
|
+
while (end > 1 / 16 && !stays(hole, mixed(hole.center, there, end), end, outside, inner)) end /= 2;
|
|
11489
|
+
return {
|
|
11490
|
+
end,
|
|
11491
|
+
point: mixed(hole.center, there, end)
|
|
11492
|
+
};
|
|
11493
|
+
}
|
|
11494
|
+
function stays(hole, point, end, outside, inner) {
|
|
11495
|
+
for (let j = 1; j < CHECKS; j++) {
|
|
11496
|
+
const t = end * j / CHECKS;
|
|
11497
|
+
const at = (path) => mixed(path[0], path[1], t);
|
|
11498
|
+
const area = [outside.map(at), ...inner.map((ring) => ring.map(at))];
|
|
11499
|
+
if (hole.points.some((p) => windingAt(mixed(p, point, j / CHECKS), area) === 0)) return false;
|
|
11500
|
+
}
|
|
11501
|
+
return true;
|
|
11502
|
+
}
|
|
11503
|
+
function holeAt({ from, to, end, opens }, p) {
|
|
11504
|
+
if (end === void 0) return between(from, to, 0, 0, p, true);
|
|
11505
|
+
const q = opens ? (p - (1 - end)) / end : p / end;
|
|
11506
|
+
return (opens ? q <= 0 : q >= 1) ? "" : between(from, to, 0, 0, q, true);
|
|
11507
|
+
}
|
|
11508
|
+
const mixed = (a, b, t) => ({
|
|
11509
|
+
x: mix(a.x, b.x, t),
|
|
11510
|
+
y: mix(a.y, b.y, t)
|
|
11511
|
+
});
|
|
11512
|
+
function landing(hole, own, other, area) {
|
|
11513
|
+
const place = placeIn(hole.center, own, other.bounds);
|
|
11514
|
+
if (depth(place, area) >= hole.size / 4) return place;
|
|
11515
|
+
const { x, y, width, height } = other.bounds;
|
|
11516
|
+
let best = other.center;
|
|
11517
|
+
let deepest = depth(best, area);
|
|
11518
|
+
for (let i = 0; i < GRID; i++) for (let j = 0; j < GRID; j++) {
|
|
11519
|
+
const point = {
|
|
11520
|
+
x: x + width * (i + .5) / GRID,
|
|
11521
|
+
y: y + height * (j + .5) / GRID
|
|
11522
|
+
};
|
|
11523
|
+
const d = depth(point, area);
|
|
11524
|
+
if (d > deepest) [best, deepest] = [point, d];
|
|
11525
|
+
}
|
|
11526
|
+
return best;
|
|
11527
|
+
}
|
|
11528
|
+
function depth(point, area) {
|
|
11529
|
+
if (windingAt(point, area) === 0) return 0;
|
|
11530
|
+
let nearest = Infinity;
|
|
11531
|
+
for (const ring of area) ring.forEach((p, i) => {
|
|
11532
|
+
const q = ring[(i + 1) % ring.length];
|
|
11533
|
+
const dx = q.x - p.x;
|
|
11534
|
+
const dy = q.y - p.y;
|
|
11535
|
+
const u = dx === 0 && dy === 0 ? 0 : Math.max(0, Math.min(1, ((point.x - p.x) * dx + (point.y - p.y) * dy) / (dx * dx + dy * dy)));
|
|
11536
|
+
nearest = Math.min(nearest, Math.hypot(point.x - p.x - u * dx, point.y - p.y - u * dy));
|
|
11537
|
+
});
|
|
11538
|
+
return nearest;
|
|
11539
|
+
}
|
|
11540
|
+
function windingAt(point, area) {
|
|
11541
|
+
let winding = 0;
|
|
11542
|
+
for (const ring of area) ring.forEach((p, i) => {
|
|
11543
|
+
const q = ring[(i + 1) % ring.length];
|
|
11544
|
+
const side = (q.x - p.x) * (point.y - p.y) - (point.x - p.x) * (q.y - p.y);
|
|
11545
|
+
if (p.y <= point.y && q.y > point.y && side > 0) winding++;
|
|
11546
|
+
else if (p.y > point.y && q.y <= point.y && side < 0) winding--;
|
|
11547
|
+
});
|
|
11548
|
+
return winding;
|
|
11549
|
+
}
|
|
11550
|
+
function placeIn(point, own, other) {
|
|
11551
|
+
const fraction = (value, start, size) => size > 0 ? (value - start) / size : .5;
|
|
11552
|
+
return {
|
|
11553
|
+
x: other.x + fraction(point.x, own.x, own.width) * other.width,
|
|
11554
|
+
y: other.y + fraction(point.y, own.y, own.height) * other.height
|
|
11555
|
+
};
|
|
11556
|
+
}
|
|
11557
|
+
function holesOf(outline, count) {
|
|
11558
|
+
const loops = flattenPath(parsePath(outline.d)).map((subpath) => subpath.segments).filter((segments) => segments.length > 0);
|
|
11559
|
+
if (loops.length < 2) return [];
|
|
11560
|
+
const lengths = loops.map((loop) => loop.reduce((sum, segment) => sum + segment.length, 0));
|
|
11561
|
+
let longest = 0;
|
|
11562
|
+
lengths.forEach((length, i) => {
|
|
11563
|
+
if (length > lengths[longest] + Math.max(.01, lengths[longest] / 1e3)) longest = i;
|
|
11564
|
+
});
|
|
11565
|
+
return loops.filter((_, i) => i !== longest).map((loop) => {
|
|
11566
|
+
const round = loopOutline([loop]).sample(4 * count);
|
|
11567
|
+
const points = round.filter((_, i) => i % 4 === 0);
|
|
11568
|
+
const box = boundsOf(loop.flatMap(extremes));
|
|
11569
|
+
return {
|
|
11570
|
+
points: [points[0], ...points.slice(1).reverse()],
|
|
11571
|
+
area: Math.abs(areaOf(round)),
|
|
11572
|
+
center: {
|
|
11573
|
+
x: box.x + box.width / 2,
|
|
11574
|
+
y: box.y + box.height / 2
|
|
11575
|
+
},
|
|
11576
|
+
size: Math.max(box.width, box.height) / 2
|
|
11577
|
+
};
|
|
11578
|
+
}).sort((x, y) => y.area - x.area);
|
|
11579
|
+
}
|
|
11580
|
+
function areaOf(points) {
|
|
11581
|
+
let sum = 0;
|
|
11582
|
+
points.forEach((p, i) => {
|
|
11583
|
+
const q = points[(i + 1) % points.length];
|
|
11584
|
+
sum += p.x * q.y - q.x * p.y;
|
|
11585
|
+
});
|
|
11586
|
+
return sum / 2;
|
|
11587
|
+
}
|
|
10464
11588
|
function crossfade(from, to, layer) {
|
|
10465
11589
|
const paint = (mark, opacity) => ({
|
|
10466
11590
|
...mark.outline.closed ? { fill: "mark" } : {
|
|
@@ -10494,13 +11618,10 @@ function crossfade(from, to, layer) {
|
|
|
10494
11618
|
function between(a, b, shiftA, shiftB, p, closed) {
|
|
10495
11619
|
const n = a.length;
|
|
10496
11620
|
let d = "";
|
|
10497
|
-
for (let i = 0; i < n; i++) {
|
|
10498
|
-
const from = a[(i + shiftA) % n];
|
|
10499
|
-
const to = b[(i + shiftB) % n];
|
|
10500
|
-
d += `${i === 0 ? "M" : "L"}${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
|
|
10501
|
-
}
|
|
11621
|
+
for (let i = 0; i < n; i++) d += `${i === 0 ? "M" : "L"}${at(a[(i + shiftA) % n], b[(i + shiftB) % n], p)}`;
|
|
10502
11622
|
return closed ? `${d}Z` : d;
|
|
10503
11623
|
}
|
|
11624
|
+
const at = (from, to, p) => `${formatNumber(mix(from.x, to.x, p))},${formatNumber(mix(from.y, to.y, p))}`;
|
|
10504
11625
|
const mix = (x, y, p) => x * (1 - p) + y * p;
|
|
10505
11626
|
function turn(from, to, points) {
|
|
10506
11627
|
const quarter = points / 4;
|
|
@@ -11018,7 +12139,7 @@ function configure(options) {
|
|
|
11018
12139
|
}
|
|
11019
12140
|
}
|
|
11020
12141
|
// src/index.ts
|
|
11021
|
-
const VERSION = "0.
|
|
12142
|
+
const VERSION = "0.6.0";
|
|
11022
12143
|
const env = {
|
|
11023
12144
|
presets: presetRegistry,
|
|
11024
12145
|
icons: iconRegistry,
|