expressive-charts 0.4.0 → 0.5.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 +33 -0
- package/README.md +5 -5
- 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-C786hGyJ.d.cts} +2 -2
- package/dist/{effect-CdH5449m.d.ts → effect-CMo-2gPf.d.ts} +2 -2
- 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 +686 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -5
- package/dist/index.d.ts +45 -5
- package/dist/index.js +659 -105
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +28 -14
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +1 -1
- package/dist/{transition-DSRt2DH3.js → transition-Bu1NsQor.js} +30 -16
- package/dist/transition-Bu1NsQor.js.map +1 -0
- package/package.json +2 -2
- package/dist/transition-DSRt2DH3.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -677,7 +677,7 @@ function pathData(segments, closed = false) {
|
|
|
677
677
|
}
|
|
678
678
|
// src/core/geometry/walk.ts
|
|
679
679
|
const clamp01 = (t) => t > 0 ? t < 1 ? t : 1 : 0;
|
|
680
|
-
const NONE$1 = Object.freeze([]);
|
|
680
|
+
const NONE$1 = /* @__PURE__ */ Object.freeze([]);
|
|
681
681
|
function createWalk(segments, gaps = NONE$1) {
|
|
682
682
|
const first = segments[0];
|
|
683
683
|
const last = segments[segments.length - 1];
|
|
@@ -874,7 +874,7 @@ function checkCount(n, multiple) {
|
|
|
874
874
|
}
|
|
875
875
|
}
|
|
876
876
|
// src/core/geometry/describe/mark.ts
|
|
877
|
-
function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, labelBounds, segments }) {
|
|
877
|
+
function assemble({ key, series, walk, thickness, outline, bounds, center, pivot, labelBounds, nearbyLabels, segments }) {
|
|
878
878
|
return {
|
|
879
879
|
key,
|
|
880
880
|
...series === void 0 ? {} : { series },
|
|
@@ -891,6 +891,7 @@ function assemble({ key, series, walk, thickness, outline, bounds, center, pivot
|
|
|
891
891
|
center,
|
|
892
892
|
pivot,
|
|
893
893
|
...labelBounds === void 0 ? {} : { labelBounds },
|
|
894
|
+
...nearbyLabels === void 0 ? {} : { nearbyLabels },
|
|
894
895
|
...segments === void 0 ? {} : { segments }
|
|
895
896
|
};
|
|
896
897
|
}
|
|
@@ -898,15 +899,15 @@ function finite(builder, field, value) {
|
|
|
898
899
|
if (!Number.isFinite(value)) throw new RangeError(`describe.${builder}: ${field} must be a finite number, got ${value}.`);
|
|
899
900
|
return value;
|
|
900
901
|
}
|
|
901
|
-
function labelBoxes$1(builder, boxes) {
|
|
902
|
+
function labelBoxes$1(builder, boxes, field = "labelBounds") {
|
|
902
903
|
if (!boxes) return boxes;
|
|
903
904
|
for (let i = 0; i < boxes.length; i++) {
|
|
904
905
|
const { x, y, width, height } = boxes[i];
|
|
905
906
|
if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && width >= 0 && Number.isFinite(height) && height >= 0) continue;
|
|
906
|
-
finite(builder,
|
|
907
|
-
finite(builder,
|
|
908
|
-
size(builder,
|
|
909
|
-
size(builder,
|
|
907
|
+
finite(builder, `${field}[${i}].x`, x);
|
|
908
|
+
finite(builder, `${field}[${i}].y`, y);
|
|
909
|
+
size(builder, `${field}[${i}].width`, width);
|
|
910
|
+
size(builder, `${field}[${i}].height`, height);
|
|
910
911
|
}
|
|
911
912
|
return boxes;
|
|
912
913
|
}
|
|
@@ -945,7 +946,8 @@ function describeArc(spec) {
|
|
|
945
946
|
bounds: boundsOf(sides.flat().flatMap(extremes)),
|
|
946
947
|
center: walk.point(.5),
|
|
947
948
|
pivot: center,
|
|
948
|
-
labelBounds: labelBoxes$1("arc", spec.labelBounds)
|
|
949
|
+
labelBounds: labelBoxes$1("arc", spec.labelBounds),
|
|
950
|
+
nearbyLabels: labelBoxes$1("arc", spec.nearbyLabels, "nearbyLabels")
|
|
949
951
|
});
|
|
950
952
|
}
|
|
951
953
|
// src/core/geometry/describe/bar.ts
|
|
@@ -965,6 +967,7 @@ function describeBar(spec) {
|
|
|
965
967
|
const radius = size("bar", "radius", spec.radius ?? 0);
|
|
966
968
|
const gap = size("bar", "gap", spec.gap ?? 0);
|
|
967
969
|
const labelBounds = labelBoxes$1("bar", spec.labelBounds);
|
|
970
|
+
const nearbyLabels = labelBoxes$1("bar", spec.nearbyLabels, "nearbyLabels");
|
|
968
971
|
const horizontal = baseline === "left" || baseline === "right";
|
|
969
972
|
const length = horizontal ? width : height;
|
|
970
973
|
const thickness = horizontal ? height : width;
|
|
@@ -1029,6 +1032,7 @@ function describeBar(spec) {
|
|
|
1029
1032
|
height
|
|
1030
1033
|
},
|
|
1031
1034
|
labelBounds,
|
|
1035
|
+
nearbyLabels,
|
|
1032
1036
|
segments
|
|
1033
1037
|
});
|
|
1034
1038
|
}
|
|
@@ -1083,7 +1087,8 @@ function describeLine(spec) {
|
|
|
1083
1087
|
},
|
|
1084
1088
|
center: walk.point(.5),
|
|
1085
1089
|
pivot: first,
|
|
1086
|
-
labelBounds: labelBoxes$1("line", spec.labelBounds)
|
|
1090
|
+
labelBounds: labelBoxes$1("line", spec.labelBounds),
|
|
1091
|
+
nearbyLabels: labelBoxes$1("line", spec.nearbyLabels, "nearbyLabels")
|
|
1087
1092
|
});
|
|
1088
1093
|
}
|
|
1089
1094
|
function gapsAt(breaks, segments) {
|
|
@@ -1131,7 +1136,8 @@ function describePoint(spec) {
|
|
|
1131
1136
|
},
|
|
1132
1137
|
center,
|
|
1133
1138
|
pivot: center,
|
|
1134
|
-
labelBounds: labelBoxes$1("point", spec.labelBounds)
|
|
1139
|
+
labelBounds: labelBoxes$1("point", spec.labelBounds),
|
|
1140
|
+
nearbyLabels: labelBoxes$1("point", spec.nearbyLabels, "nearbyLabels")
|
|
1135
1141
|
});
|
|
1136
1142
|
}
|
|
1137
1143
|
// src/core/geometry/flatten.ts
|
|
@@ -1208,9 +1214,8 @@ function flattenPath(commands) {
|
|
|
1208
1214
|
return subpaths;
|
|
1209
1215
|
}
|
|
1210
1216
|
function bezier(...p) {
|
|
1211
|
-
const bend = (a, b, c) => Math.hypot(a.x - 2 * b.x + c.x, a.y - 2 * b.y + c.y);
|
|
1212
1217
|
const cubic = p.length === 4;
|
|
1213
|
-
const n =
|
|
1218
|
+
const n = cubic ? cubicPieces(p[0], p[1], p[2], p[3]) : pieces(1, 2 * bend(p[0], p[1], p[2]));
|
|
1214
1219
|
const points = [p[0]];
|
|
1215
1220
|
for (let k = 1; k < n; k++) {
|
|
1216
1221
|
const t = k / n;
|
|
@@ -1234,6 +1239,12 @@ function bezier(...p) {
|
|
|
1234
1239
|
points.push(p[p.length - 1]);
|
|
1235
1240
|
return points;
|
|
1236
1241
|
}
|
|
1242
|
+
function cubicPieces(p0, p1, p2, p3) {
|
|
1243
|
+
return pieces(1, 6 * Math.max(bend(p0, p1, p2), bend(p1, p2, p3)));
|
|
1244
|
+
}
|
|
1245
|
+
function bend(a, b, c) {
|
|
1246
|
+
return Math.hypot(a.x - 2 * b.x + c.x, a.y - 2 * b.y + c.y);
|
|
1247
|
+
}
|
|
1237
1248
|
function pieces(span, second) {
|
|
1238
1249
|
const n = Math.ceil(span * Math.sqrt(second / (8 * FLAT)));
|
|
1239
1250
|
return Number.isFinite(n) ? Math.min(MAX_PIECES, Math.max(1, n)) : MAX_PIECES;
|
|
@@ -1682,6 +1693,7 @@ function describeShape(spec) {
|
|
|
1682
1693
|
length
|
|
1683
1694
|
].every(Number.isFinite)) throw new RangeError(`describe.shape: d must stay finite${m ? " once moved by matrix" : ""}, got ${show$2(d)}.`);
|
|
1684
1695
|
const labelBounds = labelBoxes$1("shape", spec.labelBounds);
|
|
1696
|
+
const nearbyLabels = labelBoxes$1("shape", spec.nearbyLabels, "nearbyLabels");
|
|
1685
1697
|
if (subpaths.every(closes) && length > 0) {
|
|
1686
1698
|
const center = {
|
|
1687
1699
|
x: box.x + box.width / 2,
|
|
@@ -1696,7 +1708,8 @@ function describeShape(spec) {
|
|
|
1696
1708
|
bounds: box,
|
|
1697
1709
|
center,
|
|
1698
1710
|
pivot: center,
|
|
1699
|
-
labelBounds
|
|
1711
|
+
labelBounds,
|
|
1712
|
+
nearbyLabels
|
|
1700
1713
|
});
|
|
1701
1714
|
}
|
|
1702
1715
|
const { segments, gaps } = joined(subpaths);
|
|
@@ -1716,7 +1729,8 @@ function describeShape(spec) {
|
|
|
1716
1729
|
},
|
|
1717
1730
|
center: walk.point(.5),
|
|
1718
1731
|
pivot: walk.start,
|
|
1719
|
-
labelBounds
|
|
1732
|
+
labelBounds,
|
|
1733
|
+
nearbyLabels
|
|
1720
1734
|
});
|
|
1721
1735
|
}
|
|
1722
1736
|
const closes = ({ closed, start, end }) => closed || start.x === end.x && start.y === end.y;
|
|
@@ -1916,7 +1930,7 @@ function offset(point, angle, distance) {
|
|
|
1916
1930
|
// src/core/geometry/samples.ts
|
|
1917
1931
|
const MAX_GRID = 4096;
|
|
1918
1932
|
const REFINE = 48;
|
|
1919
|
-
const GOLDEN = (Math.sqrt(5) - 1) / 2;
|
|
1933
|
+
const GOLDEN = /* @__PURE__ */ (() => (Math.sqrt(5) - 1) / 2)();
|
|
1920
1934
|
function samplesAlong(mark, points) {
|
|
1921
1935
|
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.");
|
|
1922
1936
|
if (!Array.isArray(points)) throw new TypeError("samplesAlong needs an array of points { x, y, value, at? }.");
|
|
@@ -2990,7 +3004,8 @@ function verticalFrame(input, rows, domain, _values, ticks) {
|
|
|
2990
3004
|
const tickWidth = widest$1(ticks, "ec-tick", TICK_SIZE$1, measure);
|
|
2991
3005
|
const { positive, negative } = reach(input, rows);
|
|
2992
3006
|
const top = (domain.hi > 0 ? 20.5 : TOP$1) + positive;
|
|
2993
|
-
const
|
|
3007
|
+
const values = domain.lo < 0 ? 18.5 : 0;
|
|
3008
|
+
const bottom = AXIS$1 + values + negative;
|
|
2994
3009
|
const left = tickWidth + 8 + 2;
|
|
2995
3010
|
const plot = {
|
|
2996
3011
|
x: left,
|
|
@@ -3007,7 +3022,7 @@ function verticalFrame(input, rows, domain, _values, ticks) {
|
|
|
3007
3022
|
hi: domain.hi,
|
|
3008
3023
|
from: base,
|
|
3009
3024
|
extent: -plot.height,
|
|
3010
|
-
label: base + 18
|
|
3025
|
+
label: base + values + 18
|
|
3011
3026
|
},
|
|
3012
3027
|
bands: {
|
|
3013
3028
|
start: plot.x,
|
|
@@ -3135,7 +3150,7 @@ const COLOR_TOKENS = [
|
|
|
3135
3150
|
"focus",
|
|
3136
3151
|
"negative"
|
|
3137
3152
|
];
|
|
3138
|
-
const TOKENS = Object.fromEntries(COLOR_TOKENS.map((name) => [name, themes.light[name]]));
|
|
3153
|
+
const TOKENS = /* @__PURE__ */ Object.fromEntries(/* @__PURE__ */ COLOR_TOKENS.map((name) => [name, themes.light[name]]));
|
|
3139
3154
|
function seriesColors(slot) {
|
|
3140
3155
|
const n = (Math.max(1, Math.floor(slot)) - 1) % 8 + 1;
|
|
3141
3156
|
const [color, strong] = themes.light.series[n - 1];
|
|
@@ -3171,8 +3186,7 @@ function declarations(theme, indent) {
|
|
|
3171
3186
|
theme.series.forEach(([color, strong], i) => lines.push(`--ec-series-${i + 1}: ${color};`, `--ec-series-${i + 1}-strong: ${strong};`));
|
|
3172
3187
|
return lines.map((line) => indent + line).join("\n");
|
|
3173
3188
|
}
|
|
3174
|
-
const
|
|
3175
|
-
${`:where(:root, [data-theme="light"]) {
|
|
3189
|
+
const TOKEN_RULES = /* @__PURE__ */ (() => `:where(:root, [data-theme="light"]) {
|
|
3176
3190
|
${declarations(themes.light, " ")}
|
|
3177
3191
|
}
|
|
3178
3192
|
@media (prefers-color-scheme: dark) {
|
|
@@ -3182,7 +3196,9 @@ ${declarations(themes.dark, " ")}
|
|
|
3182
3196
|
}
|
|
3183
3197
|
:where([data-theme="dark"]) {
|
|
3184
3198
|
${declarations(themes.dark, " ")}
|
|
3185
|
-
}`
|
|
3199
|
+
}`)();
|
|
3200
|
+
const STYLES = /* @__PURE__ */ (() => `/* expressive-charts: theme tokens and default styles. Every rule has zero specificity, so your CSS wins. */
|
|
3201
|
+
${TOKEN_RULES}
|
|
3186
3202
|
:where(.ec-chart) { display: block; max-width: 100%; height: auto; overflow: visible; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
|
|
3187
3203
|
:where(.ec-chart text) { font-variant-numeric: tabular-nums; }
|
|
3188
3204
|
:where(.ec-chart .ec-gridline) { stroke: var(--ec-grid, ${TOKENS.grid}); stroke-width: 1; }
|
|
@@ -3201,18 +3217,19 @@ ${declarations(themes.dark, " ")}
|
|
|
3201
3217
|
:where(.ec-chart .ec-hot .ec-segment) { fill: var(--ec-mark-strong); }
|
|
3202
3218
|
: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; }
|
|
3203
3219
|
:where(.ec-chart .ec-hot .ec-stroke) { stroke: var(--ec-mark-strong); }
|
|
3204
|
-
:where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
|
|
3220
|
+
: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; }
|
|
3205
3221
|
: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; }
|
|
3206
3222
|
:where(.ec-chart .ec-hot .ec-dot) { fill: var(--ec-mark-strong); opacity: 1; }
|
|
3207
3223
|
:where(.ec-chart .ec-alone .ec-dot) { opacity: 1; }
|
|
3208
3224
|
:where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
|
|
3209
|
-
:where(.ec-chart .ec-column:focus) { outline: none; }
|
|
3225
|
+
:where(.ec-chart .ec-column:focus, .ec-chart .ec-stop:focus) { outline: none; }
|
|
3210
3226
|
:where(.ec-chart .ec-lines, .ec-chart .ec-points) { pointer-events: none; }
|
|
3211
3227
|
: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; }
|
|
3212
3228
|
:where(.ec-chart .ec-hot .ec-slice) { fill: var(--ec-mark-strong); }
|
|
3213
3229
|
:where(.ec-chart .ec-center-value) { fill: var(--ec-text, ${TOKENS.text}); font-size: 26px; font-weight: 600; }
|
|
3214
3230
|
:where(.ec-chart .ec-center-label) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12.5px; }
|
|
3215
3231
|
:where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
|
|
3232
|
+
: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); }
|
|
3216
3233
|
:where(.ec-hovering .ec-run:not(.ec-hot) > .ec-follow) { opacity: var(--ec-dim-opacity, 0.3); }
|
|
3217
3234
|
:where(.ec-follow) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
3218
3235
|
:where(.ec-chart.ec-morphing .ec-marks) { visibility: hidden; }
|
|
@@ -3258,7 +3275,7 @@ ${declarations(themes.dark, " ")}
|
|
|
3258
3275
|
:where(.ec-table thead th) { color: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12px; font-weight: 600; }
|
|
3259
3276
|
:where(.ec-table .ec-num) { text-align: right; }
|
|
3260
3277
|
: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; }
|
|
3261
|
-
|
|
3278
|
+
`)();
|
|
3262
3279
|
const MARKER = "data-expressive-charts";
|
|
3263
3280
|
const styleOptions = {};
|
|
3264
3281
|
function injectStyles(doc) {
|
|
@@ -3950,7 +3967,9 @@ function pointerHover(svg, options) {
|
|
|
3950
3967
|
let held;
|
|
3951
3968
|
let watcher;
|
|
3952
3969
|
let still;
|
|
3970
|
+
let under;
|
|
3953
3971
|
const enter = (target, source) => {
|
|
3972
|
+
under = target?.key;
|
|
3954
3973
|
if (target?.key === current) return;
|
|
3955
3974
|
leave();
|
|
3956
3975
|
if (!target) return;
|
|
@@ -3975,8 +3994,15 @@ function pointerHover(svg, options) {
|
|
|
3975
3994
|
const arrive = (element, x, y) => {
|
|
3976
3995
|
const tip = tooltipHolding(element);
|
|
3977
3996
|
if (tip) hold(tip, x, y);
|
|
3978
|
-
else enter(element && svg.contains(element) ? options.find(element
|
|
3997
|
+
else enter(element && svg.contains(element) ? options.find(element, {
|
|
3998
|
+
x,
|
|
3999
|
+
y
|
|
4000
|
+
}) : void 0, "pointer");
|
|
3979
4001
|
};
|
|
4002
|
+
const at = (event) => options.find(event.target, {
|
|
4003
|
+
x: event.clientX,
|
|
4004
|
+
y: event.clientY
|
|
4005
|
+
});
|
|
3980
4006
|
const hold = (tip, x, y) => {
|
|
3981
4007
|
enter({ key: tip.key }, "pointer");
|
|
3982
4008
|
const element = tip.element;
|
|
@@ -4046,7 +4072,8 @@ function pointerHover(svg, options) {
|
|
|
4046
4072
|
const over = (event) => {
|
|
4047
4073
|
if (event.pointerType === "touch" || resting(event)) return;
|
|
4048
4074
|
letGo();
|
|
4049
|
-
|
|
4075
|
+
const target = at(event);
|
|
4076
|
+
if (!options.moves?.() || target?.key !== under) enter(target, "pointer");
|
|
4050
4077
|
};
|
|
4051
4078
|
const out = (event) => {
|
|
4052
4079
|
if (event.pointerType === "touch") return;
|
|
@@ -4054,13 +4081,17 @@ function pointerHover(svg, options) {
|
|
|
4054
4081
|
arrive(landing(event), event.clientX, event.clientY);
|
|
4055
4082
|
};
|
|
4056
4083
|
const move = (event) => {
|
|
4057
|
-
if (event.pointerType
|
|
4084
|
+
if (event.pointerType === "touch" || resting(event) || !options.moves?.()) return;
|
|
4085
|
+
const target = at(event);
|
|
4086
|
+
if (target?.key === under) return;
|
|
4087
|
+
letGo();
|
|
4088
|
+
enter(target, "pointer");
|
|
4058
4089
|
};
|
|
4059
4090
|
const down = (event) => {
|
|
4060
4091
|
lastPointer = event.pointerType;
|
|
4061
4092
|
};
|
|
4062
4093
|
const click = (event) => {
|
|
4063
|
-
if (lastPointer === "touch") enter(
|
|
4094
|
+
if (lastPointer === "touch") enter(at(event), "touch");
|
|
4064
4095
|
};
|
|
4065
4096
|
const elsewhere = (event) => {
|
|
4066
4097
|
if (current === void 0 || event.pointerType !== "touch") return;
|
|
@@ -4168,15 +4199,19 @@ function keyboardFocus(svg, options) {
|
|
|
4168
4199
|
if (key === void 0 || event.altKey || event.ctrlKey || event.metaKey) return;
|
|
4169
4200
|
const keys = options.order();
|
|
4170
4201
|
const index = keys.indexOf(key);
|
|
4202
|
+
const moved = (press, fallback) => {
|
|
4203
|
+
const to = options.move?.(key, press);
|
|
4204
|
+
return to !== void 0 && keys.includes(to) ? to : fallback;
|
|
4205
|
+
};
|
|
4171
4206
|
let next;
|
|
4172
4207
|
switch (event.key) {
|
|
4173
4208
|
case "ArrowDown":
|
|
4174
4209
|
case "ArrowRight":
|
|
4175
|
-
next = keys[Math.min(keys.length - 1, index + 1)];
|
|
4210
|
+
next = moved(event.key, keys[Math.min(keys.length - 1, index + 1)]);
|
|
4176
4211
|
break;
|
|
4177
4212
|
case "ArrowUp":
|
|
4178
4213
|
case "ArrowLeft":
|
|
4179
|
-
next = keys[Math.max(0, index - 1)];
|
|
4214
|
+
next = moved(event.key, keys[Math.max(0, index - 1)]);
|
|
4180
4215
|
break;
|
|
4181
4216
|
case "PageDown":
|
|
4182
4217
|
case "PageUp": {
|
|
@@ -4186,10 +4221,10 @@ function keyboardFocus(svg, options) {
|
|
|
4186
4221
|
break;
|
|
4187
4222
|
}
|
|
4188
4223
|
case "Home":
|
|
4189
|
-
next = keys[0];
|
|
4224
|
+
next = moved(event.key, keys[0]);
|
|
4190
4225
|
break;
|
|
4191
4226
|
case "End":
|
|
4192
|
-
next = keys[keys.length - 1];
|
|
4227
|
+
next = moved(event.key, keys[keys.length - 1]);
|
|
4193
4228
|
break;
|
|
4194
4229
|
case "Escape":
|
|
4195
4230
|
if (options.escape(key)) event.preventDefault();
|
|
@@ -4253,6 +4288,28 @@ function keyboardFocus(svg, options) {
|
|
|
4253
4288
|
for (const key of gone) setTabIndex(key, void 0);
|
|
4254
4289
|
last = keys;
|
|
4255
4290
|
},
|
|
4291
|
+
retarget(to) {
|
|
4292
|
+
listen();
|
|
4293
|
+
const keys = options.order();
|
|
4294
|
+
const live = new Set(keys);
|
|
4295
|
+
const active = on?.scope.activeElement ?? null;
|
|
4296
|
+
const had = focused?.element === active ? focused.key : last.find((key) => options.element(key) === active);
|
|
4297
|
+
const from = had ?? tabStop;
|
|
4298
|
+
const moved = from === void 0 ? void 0 : to(from);
|
|
4299
|
+
tabStop = moved !== void 0 && live.has(moved) ? moved : keys[0];
|
|
4300
|
+
applyTabIndex(keys);
|
|
4301
|
+
if (had !== void 0) {
|
|
4302
|
+
current = tabStop;
|
|
4303
|
+
if (tabStop !== void 0) options.element(tabStop)?.focus();
|
|
4304
|
+
else {
|
|
4305
|
+
active.blur();
|
|
4306
|
+
focused = void 0;
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
for (const key of last) if (!live.has(key)) setTabIndex(key, void 0);
|
|
4310
|
+
last = keys;
|
|
4311
|
+
return had === void 0 ? void 0 : current;
|
|
4312
|
+
},
|
|
4256
4313
|
destroy() {
|
|
4257
4314
|
current = void 0;
|
|
4258
4315
|
focused = void 0;
|
|
@@ -4361,6 +4418,7 @@ function chartHover(options) {
|
|
|
4361
4418
|
const within = (target, key) => key === target || options.live(target) && marksOf(target).includes(key);
|
|
4362
4419
|
const interaction = pointerHover(svg, {
|
|
4363
4420
|
find: options.find,
|
|
4421
|
+
moves: () => options.moves?.() ?? false,
|
|
4364
4422
|
hover(target, source) {
|
|
4365
4423
|
if (!options.live(target.key) || own(hovered) && hovered.keys[0] === target.key) return;
|
|
4366
4424
|
endHover();
|
|
@@ -4378,6 +4436,7 @@ function chartHover(options) {
|
|
|
4378
4436
|
find: (eventTarget) => options.find(eventTarget)?.key,
|
|
4379
4437
|
order: options.order,
|
|
4380
4438
|
page: (key, by) => options.page?.(key, by),
|
|
4439
|
+
move: (key, press) => options.move?.(key, press),
|
|
4381
4440
|
element: options.element,
|
|
4382
4441
|
focus(key, visible) {
|
|
4383
4442
|
ringKey = visible ? key : void 0;
|
|
@@ -4497,6 +4556,14 @@ function chartHover(options) {
|
|
|
4497
4556
|
});
|
|
4498
4557
|
},
|
|
4499
4558
|
sync: () => keyboard.sync(),
|
|
4559
|
+
retarget(to) {
|
|
4560
|
+
const key = keyboard.retarget(to);
|
|
4561
|
+
if (ringKey !== void 0) {
|
|
4562
|
+
ringKey = key;
|
|
4563
|
+
options.ring(ringKey);
|
|
4564
|
+
}
|
|
4565
|
+
linked?.shown();
|
|
4566
|
+
},
|
|
4500
4567
|
focus(key) {
|
|
4501
4568
|
if (options.live(key)) keyboard.focus(key);
|
|
4502
4569
|
},
|
|
@@ -5002,8 +5069,9 @@ function geometryChanged$1(from, to) {
|
|
|
5002
5069
|
return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
|
|
5003
5070
|
}
|
|
5004
5071
|
function labelsMoved(from, to) {
|
|
5005
|
-
|
|
5006
|
-
|
|
5072
|
+
return boxesMoved(from.labelBounds, to.labelBounds) || boxesMoved(from.nearbyLabels, to.nearbyLabels);
|
|
5073
|
+
}
|
|
5074
|
+
function boxesMoved(a, b) {
|
|
5007
5075
|
if (a === b) return false;
|
|
5008
5076
|
if (!a || !b || a.length !== b.length) return true;
|
|
5009
5077
|
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);
|
|
@@ -5119,7 +5187,7 @@ function chartTooltip(svg, options) {
|
|
|
5119
5187
|
const option = options.option();
|
|
5120
5188
|
const known = texts.get(row);
|
|
5121
5189
|
if (known && known.option === option) return known.content;
|
|
5122
|
-
const content = text(option, row.datum, summary);
|
|
5190
|
+
const content = text(option, row.datum, summary, row.series);
|
|
5123
5191
|
texts.set(row, {
|
|
5124
5192
|
option,
|
|
5125
5193
|
content
|
|
@@ -5288,13 +5356,13 @@ function span(bridge, box, mark, side) {
|
|
|
5288
5356
|
const [upper, lower, top, bottom] = side === "above" ? [
|
|
5289
5357
|
edge,
|
|
5290
5358
|
mark,
|
|
5291
|
-
box.top + box.height,
|
|
5359
|
+
box.top + box.height - OVERLAP,
|
|
5292
5360
|
Math.round(mark.top + OVERLAP)
|
|
5293
5361
|
] : [
|
|
5294
5362
|
mark,
|
|
5295
5363
|
edge,
|
|
5296
5364
|
Math.round(mark.bottom - OVERLAP),
|
|
5297
|
-
box.top
|
|
5365
|
+
box.top + OVERLAP
|
|
5298
5366
|
];
|
|
5299
5367
|
const left = Math.round(Math.min(upper.left, lower.left));
|
|
5300
5368
|
const width = Math.round(Math.max(upper.right, lower.right)) - left;
|
|
@@ -5316,11 +5384,11 @@ function span(bridge, box, mark, side) {
|
|
|
5316
5384
|
lower: round(lower)
|
|
5317
5385
|
};
|
|
5318
5386
|
}
|
|
5319
|
-
function text(option, datum, summary) {
|
|
5387
|
+
function text(option, datum, summary, series) {
|
|
5320
5388
|
if (option === false) return void 0;
|
|
5321
5389
|
if (typeof option !== "function") return summary();
|
|
5322
5390
|
try {
|
|
5323
|
-
const result = option(datum);
|
|
5391
|
+
const result = series === void 0 ? option(datum) : option(datum, { series });
|
|
5324
5392
|
return result === void 0 || result === null || result === "" ? void 0 : String(result);
|
|
5325
5393
|
} catch (error) {
|
|
5326
5394
|
report(error);
|
|
@@ -6125,7 +6193,7 @@ function layoutDonut(input) {
|
|
|
6125
6193
|
return {
|
|
6126
6194
|
frame,
|
|
6127
6195
|
total,
|
|
6128
|
-
slices:
|
|
6196
|
+
slices: placeSlices(frame, states, labels, input.measure),
|
|
6129
6197
|
labels,
|
|
6130
6198
|
centerText,
|
|
6131
6199
|
center: placeCenter(frame, centerText, input.measure)
|
|
@@ -6140,7 +6208,29 @@ function joinedStarts(values) {
|
|
|
6140
6208
|
return start;
|
|
6141
6209
|
});
|
|
6142
6210
|
}
|
|
6143
|
-
function
|
|
6211
|
+
function placeSlices(frame, states, labels, measure) {
|
|
6212
|
+
const boxes = labels.map((label) => label ? labelBoxes(label, measure) : void 0);
|
|
6213
|
+
const labelled = boxes.flatMap((box, i) => box ? [i] : []);
|
|
6214
|
+
const first = labelled[0];
|
|
6215
|
+
const last = labelled[labelled.length - 1];
|
|
6216
|
+
const before = [];
|
|
6217
|
+
const after = [];
|
|
6218
|
+
let seen;
|
|
6219
|
+
for (let i = 0; i < states.length; i++) {
|
|
6220
|
+
before[i] = seen ?? (last === i ? void 0 : last);
|
|
6221
|
+
if (boxes[i]) seen = i;
|
|
6222
|
+
}
|
|
6223
|
+
seen = void 0;
|
|
6224
|
+
for (let i = states.length - 1; i >= 0; i--) {
|
|
6225
|
+
after[i] = seen ?? (first === i ? void 0 : first);
|
|
6226
|
+
if (boxes[i]) seen = i;
|
|
6227
|
+
}
|
|
6228
|
+
return states.map((state, i) => {
|
|
6229
|
+
const sides = before[i] === after[i] ? [before[i]] : [before[i], after[i]];
|
|
6230
|
+
return placeSlice(frame, state, labels[i], measure, sides.flatMap((j) => j === void 0 ? [] : boxes[j]));
|
|
6231
|
+
});
|
|
6232
|
+
}
|
|
6233
|
+
function placeSlice(frame, state, label, measure, nearby) {
|
|
6144
6234
|
const geometry = describeArc({
|
|
6145
6235
|
key: state.key,
|
|
6146
6236
|
series: state.series,
|
|
@@ -6150,7 +6240,8 @@ function placeSlice(frame, state, label, measure) {
|
|
|
6150
6240
|
outer: frame.outer,
|
|
6151
6241
|
start: state.start,
|
|
6152
6242
|
end: state.end,
|
|
6153
|
-
labelBounds: label && measure ? labelBoxes(label, measure) : []
|
|
6243
|
+
labelBounds: label && measure ? labelBoxes(label, measure) : [],
|
|
6244
|
+
...nearby ? { nearbyLabels: nearby } : {}
|
|
6154
6245
|
});
|
|
6155
6246
|
return {
|
|
6156
6247
|
...state,
|
|
@@ -6641,9 +6732,10 @@ function donutChart$1(target, options, env) {
|
|
|
6641
6732
|
};
|
|
6642
6733
|
});
|
|
6643
6734
|
const labels = placeLabels(f, now.map(({ state }) => state), measure);
|
|
6644
|
-
|
|
6735
|
+
const slices = placeSlices(f, now.map(({ state }) => state), labels, measure);
|
|
6736
|
+
return now.map(({ record }, i) => ({
|
|
6645
6737
|
record,
|
|
6646
|
-
slice:
|
|
6738
|
+
slice: slices[i],
|
|
6647
6739
|
label: labels[i]
|
|
6648
6740
|
}));
|
|
6649
6741
|
}
|
|
@@ -7036,6 +7128,165 @@ function mergeRing(shown, next) {
|
|
|
7036
7128
|
});
|
|
7037
7129
|
return out;
|
|
7038
7130
|
}
|
|
7131
|
+
// src/charts/curve.ts
|
|
7132
|
+
const CURVES = ["linear", "monotone"];
|
|
7133
|
+
function bendOf(curve) {
|
|
7134
|
+
return curve === "monotone" ? 1 : 0;
|
|
7135
|
+
}
|
|
7136
|
+
function lineCurve(xs, values, amount, scales, presence) {
|
|
7137
|
+
const knotOf = new Int32Array(xs.length).fill(-1);
|
|
7138
|
+
const kx = [];
|
|
7139
|
+
const kv = [];
|
|
7140
|
+
const run = [];
|
|
7141
|
+
const kp = [];
|
|
7142
|
+
let runs = 0;
|
|
7143
|
+
let joined = false;
|
|
7144
|
+
for (let i = 0; i < xs.length; i++) {
|
|
7145
|
+
const value = values[i];
|
|
7146
|
+
if (value === void 0) {
|
|
7147
|
+
joined = false;
|
|
7148
|
+
continue;
|
|
7149
|
+
}
|
|
7150
|
+
const k = kx.length - 1;
|
|
7151
|
+
if (joined && xs[i] === kx[k] && value === kv[k]) {
|
|
7152
|
+
knotOf[i] = k;
|
|
7153
|
+
kp[k] = Math.max(kp[k], presence?.[i] ?? 1);
|
|
7154
|
+
continue;
|
|
7155
|
+
}
|
|
7156
|
+
if (!joined || xs[i] === kx[k]) runs++;
|
|
7157
|
+
kx.push(xs[i]);
|
|
7158
|
+
kv.push(value);
|
|
7159
|
+
run.push(runs);
|
|
7160
|
+
kp.push(presence?.[i] ?? 1);
|
|
7161
|
+
knotOf[i] = k + 1;
|
|
7162
|
+
joined = true;
|
|
7163
|
+
}
|
|
7164
|
+
const tangents = amount > 0 ? new Float64Array(kx.length) : void 0;
|
|
7165
|
+
if (tangents) for (let start = 0; start < kx.length;) {
|
|
7166
|
+
let end = start + 1;
|
|
7167
|
+
while (end < kx.length && run[end] === run[start]) end++;
|
|
7168
|
+
monotoneTangents(kx, kv, start, end, tangents);
|
|
7169
|
+
if (presence) fade(kx, kv, kp, start, end, tangents);
|
|
7170
|
+
start = end;
|
|
7171
|
+
}
|
|
7172
|
+
const piece = (from, to) => {
|
|
7173
|
+
const k = knotOf[from];
|
|
7174
|
+
if (k < 0 || knotOf[to] !== k + 1 || run[k + 1] !== run[k]) return void 0;
|
|
7175
|
+
const h = kx[k + 1] - kx[k];
|
|
7176
|
+
const v0 = kv[k];
|
|
7177
|
+
const v1 = kv[k + 1];
|
|
7178
|
+
const slope = (v1 - v0) / h;
|
|
7179
|
+
const [lo, hi] = slope < 0 ? [3 * slope, 0] : [0, 3 * slope];
|
|
7180
|
+
const ease = (tangent) => Math.min(hi, Math.max(lo, amount === 1 ? tangent : slope + amount * (tangent - slope)));
|
|
7181
|
+
const a = tangents ? ease(tangents[k]) : slope;
|
|
7182
|
+
const b = tangents ? ease(tangents[k + 1]) : slope;
|
|
7183
|
+
return [
|
|
7184
|
+
v0,
|
|
7185
|
+
v0 + h * a / 3,
|
|
7186
|
+
v1 - h * b / 3,
|
|
7187
|
+
v1,
|
|
7188
|
+
k
|
|
7189
|
+
];
|
|
7190
|
+
};
|
|
7191
|
+
return {
|
|
7192
|
+
between(from, to, through = Infinity) {
|
|
7193
|
+
const p = piece(from, to);
|
|
7194
|
+
if (!p || !tangents) return [];
|
|
7195
|
+
const [v0, c1, c2, v1, k] = p;
|
|
7196
|
+
const x0 = kx[k];
|
|
7197
|
+
const h = kx[k + 1] - x0;
|
|
7198
|
+
const left = scales.x(x0);
|
|
7199
|
+
const right = scales.x(kx[k + 1]);
|
|
7200
|
+
const n = Math.min(cubicPieces({
|
|
7201
|
+
x: left,
|
|
7202
|
+
y: scales.y(v0)
|
|
7203
|
+
}, {
|
|
7204
|
+
x: left + (right - left) / 3,
|
|
7205
|
+
y: scales.y(c1)
|
|
7206
|
+
}, {
|
|
7207
|
+
x: right - (right - left) / 3,
|
|
7208
|
+
y: scales.y(c2)
|
|
7209
|
+
}, {
|
|
7210
|
+
x: right,
|
|
7211
|
+
y: scales.y(v1)
|
|
7212
|
+
}), Math.max(1, Math.ceil(Math.abs(right - left) / FLAT)));
|
|
7213
|
+
const bends = [];
|
|
7214
|
+
for (let j = 1; j < n; j++) {
|
|
7215
|
+
const x = x0 + j / n * h;
|
|
7216
|
+
if (!(x < through)) break;
|
|
7217
|
+
bends.push({
|
|
7218
|
+
x,
|
|
7219
|
+
value: cubic(v0, c1, c2, v1, j / n)
|
|
7220
|
+
});
|
|
7221
|
+
}
|
|
7222
|
+
return bends;
|
|
7223
|
+
},
|
|
7224
|
+
valueAt(from, to, x) {
|
|
7225
|
+
const p = piece(from, to);
|
|
7226
|
+
if (!p) return values[from] ?? 0;
|
|
7227
|
+
const [v0, c1, c2, v1, k] = p;
|
|
7228
|
+
return cubic(v0, c1, c2, v1, (x - kx[k]) / (kx[k + 1] - kx[k]));
|
|
7229
|
+
}
|
|
7230
|
+
};
|
|
7231
|
+
}
|
|
7232
|
+
function monotoneTangents(xs, values, start, end, out) {
|
|
7233
|
+
const count = end - start;
|
|
7234
|
+
if (count < 2) {
|
|
7235
|
+
if (count === 1) out[start] = 0;
|
|
7236
|
+
return;
|
|
7237
|
+
}
|
|
7238
|
+
const slope = (k) => (values[k + 1] - values[k]) / (xs[k + 1] - xs[k]);
|
|
7239
|
+
if (count === 2) {
|
|
7240
|
+
out[start] = out[start + 1] = slope(start);
|
|
7241
|
+
return;
|
|
7242
|
+
}
|
|
7243
|
+
for (let k = start + 1; k < end - 1; k++) {
|
|
7244
|
+
const h0 = xs[k] - xs[k - 1];
|
|
7245
|
+
const h1 = xs[k + 1] - xs[k];
|
|
7246
|
+
const s0 = slope(k - 1);
|
|
7247
|
+
const s1 = slope(k);
|
|
7248
|
+
const p = (s0 * h1 + s1 * h0) / (h0 + h1);
|
|
7249
|
+
out[k] = (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), .5 * Math.abs(p)) || 0;
|
|
7250
|
+
}
|
|
7251
|
+
out[start] = (3 * slope(start) - out[start + 1]) / 2;
|
|
7252
|
+
out[end - 1] = (3 * slope(end - 2) - out[end - 2]) / 2;
|
|
7253
|
+
}
|
|
7254
|
+
function fade(xs, values, presence, start, end, tangents) {
|
|
7255
|
+
const kept = [];
|
|
7256
|
+
for (let k = start; k < end; k++) if (presence[k] >= 1) kept.push(k);
|
|
7257
|
+
if (kept.length === end - start || kept.length < 2) return;
|
|
7258
|
+
const kx = kept.map((k) => xs[k]);
|
|
7259
|
+
const kv = kept.map((k) => values[k]);
|
|
7260
|
+
const without = new Float64Array(kept.length);
|
|
7261
|
+
monotoneTangents(kx, kv, 0, kept.length, without);
|
|
7262
|
+
const eased = new Float64Array(end - start);
|
|
7263
|
+
let j = 0;
|
|
7264
|
+
let i = 0;
|
|
7265
|
+
for (let k = start; k < end; k++) {
|
|
7266
|
+
while (j < kx.length - 2 && kx[j + 1] <= xs[k]) j++;
|
|
7267
|
+
const own = kept[i] === k ? i++ : -1;
|
|
7268
|
+
let least = 1;
|
|
7269
|
+
for (let n = Math.max(start, k - 2); n < Math.min(end, k + 3); n++) least = Math.min(least, presence[n]);
|
|
7270
|
+
if (least >= 1) {
|
|
7271
|
+
eased[k - start] = tangents[k];
|
|
7272
|
+
continue;
|
|
7273
|
+
}
|
|
7274
|
+
let slope;
|
|
7275
|
+
if (own >= 0) slope = without[own];
|
|
7276
|
+
else {
|
|
7277
|
+
const h = kx[j + 1] - kx[j];
|
|
7278
|
+
const u = Math.min(1, Math.max(0, (xs[k] - kx[j]) / h));
|
|
7279
|
+
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];
|
|
7280
|
+
}
|
|
7281
|
+
eased[k - start] = least * tangents[k] + (1 - least) * slope;
|
|
7282
|
+
}
|
|
7283
|
+
tangents.set(eased, start);
|
|
7284
|
+
}
|
|
7285
|
+
const sign = (x) => x < 0 ? -1 : 1;
|
|
7286
|
+
function cubic(v0, c1, c2, v1, u) {
|
|
7287
|
+
const s = 1 - u;
|
|
7288
|
+
return s * s * s * v0 + 3 * s * s * u * c1 + 3 * s * u * u * c2 + u * u * u * v1;
|
|
7289
|
+
}
|
|
7039
7290
|
// src/charts/time.ts
|
|
7040
7291
|
const TIME_ZONES = ["UTC", "local"];
|
|
7041
7292
|
const SECOND = 1e3;
|
|
@@ -7051,7 +7302,7 @@ const LONGEST$1 = {
|
|
|
7051
7302
|
month: 31 * DAY,
|
|
7052
7303
|
year: 366 * DAY
|
|
7053
7304
|
};
|
|
7054
|
-
const STEPS = [
|
|
7305
|
+
const STEPS = /* @__PURE__ */ (() => [
|
|
7055
7306
|
...[
|
|
7056
7307
|
1,
|
|
7057
7308
|
5,
|
|
@@ -7099,7 +7350,7 @@ const STEPS = [
|
|
|
7099
7350
|
unit: "month",
|
|
7100
7351
|
count: 3
|
|
7101
7352
|
}
|
|
7102
|
-
];
|
|
7353
|
+
])();
|
|
7103
7354
|
const LEVELS = [
|
|
7104
7355
|
"year",
|
|
7105
7356
|
"month",
|
|
@@ -7329,6 +7580,8 @@ function lineEncoding(options) {
|
|
|
7329
7580
|
if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${show$1(timeZone)}.`);
|
|
7330
7581
|
const xFormat = options.xFormat;
|
|
7331
7582
|
if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
|
|
7583
|
+
const curve = options.curve ?? "linear";
|
|
7584
|
+
if (!CURVES.includes(curve)) throw new TypeError(`lineChart: curve must be "linear" or "monotone", got ${show$1(curve)}.`);
|
|
7332
7585
|
return {
|
|
7333
7586
|
x: accessor(x),
|
|
7334
7587
|
key: key === void 0 ? void 0 : accessor(key),
|
|
@@ -7337,7 +7590,8 @@ function lineEncoding(options) {
|
|
|
7337
7590
|
value: accessor(field)
|
|
7338
7591
|
})),
|
|
7339
7592
|
timeZone,
|
|
7340
|
-
xFormat: options.xFormat
|
|
7593
|
+
xFormat: options.xFormat,
|
|
7594
|
+
curve
|
|
7341
7595
|
};
|
|
7342
7596
|
}
|
|
7343
7597
|
function layoutLines(input) {
|
|
@@ -7388,7 +7642,8 @@ function layoutLines(input) {
|
|
|
7388
7642
|
series,
|
|
7389
7643
|
yTicks: domain.ticks.map((value, i) => placeYTick(frame, value, yTexts[i])),
|
|
7390
7644
|
xTicks: spaced(xTicks, xWidths),
|
|
7391
|
-
decimals: decimalsBy
|
|
7645
|
+
decimals: decimalsBy,
|
|
7646
|
+
curve: input.encoding.curve
|
|
7392
7647
|
};
|
|
7393
7648
|
}
|
|
7394
7649
|
function positions(frame) {
|
|
@@ -7400,7 +7655,7 @@ function positions(frame) {
|
|
|
7400
7655
|
y: (value) => ySpan > 0 ? box.bottom - (value - scale.lo) / ySpan * (box.bottom - box.top) : box.bottom
|
|
7401
7656
|
};
|
|
7402
7657
|
}
|
|
7403
|
-
function placeLines(frame, rows, series, through, time = false, labels) {
|
|
7658
|
+
function placeLines(frame, rows, series, through, time = false, labels, bend = 0) {
|
|
7404
7659
|
const first = rows[0];
|
|
7405
7660
|
if (!first) return [];
|
|
7406
7661
|
const at = positions(frame);
|
|
@@ -7410,27 +7665,47 @@ function placeLines(frame, rows, series, through, time = false, labels) {
|
|
|
7410
7665
|
const next = rows[last + 1];
|
|
7411
7666
|
const share = next && next.x > end.x && through > end.x ? (through - end.x) / (next.x - end.x) : void 0;
|
|
7412
7667
|
const shown = rows.slice(0, last + 1);
|
|
7668
|
+
const xs = bend > 0 ? rows.map((row) => row.x) : [];
|
|
7669
|
+
const presence = bend > 0 && rows.some((row) => row.presence !== void 0 && row.presence < 1) ? rows.map((row) => row.presence ?? 1) : void 0;
|
|
7413
7670
|
const datas = /* @__PURE__ */ new Map();
|
|
7414
7671
|
const related = (own) => (name) => name === own ? void 0 : datas.get(name);
|
|
7415
7672
|
const traced = series.map((name) => {
|
|
7416
7673
|
const has = (row) => !row.missing?.has(name);
|
|
7674
|
+
const curve = bend > 0 ? lineCurve(xs, rows.map((row) => has(row) ? row.values[name] ?? 0 : void 0), bend, at, presence) : void 0;
|
|
7417
7675
|
const vertices = [];
|
|
7418
7676
|
let gap = false;
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
vertices.
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7677
|
+
let before = -1;
|
|
7678
|
+
shown.forEach((row, i) => {
|
|
7679
|
+
if (!has(row)) gap = vertices.length > 0;
|
|
7680
|
+
else {
|
|
7681
|
+
if (curve && before >= 0) for (const b of curve.between(before, i)) vertices.push({
|
|
7682
|
+
at: b.x,
|
|
7683
|
+
value: b.value,
|
|
7684
|
+
datum: rows[before].datum,
|
|
7685
|
+
gapBefore: false
|
|
7686
|
+
});
|
|
7687
|
+
vertices.push({
|
|
7688
|
+
at: row.x,
|
|
7689
|
+
value: row.values[name] ?? 0,
|
|
7690
|
+
datum: row.datum,
|
|
7691
|
+
gapBefore: gap
|
|
7692
|
+
});
|
|
7693
|
+
gap = false;
|
|
7694
|
+
before = i;
|
|
7695
|
+
}
|
|
7696
|
+
});
|
|
7429
7697
|
if (share !== void 0 && has(end) && has(next)) {
|
|
7698
|
+
if (curve) for (const b of curve.between(last, last + 1, through)) vertices.push({
|
|
7699
|
+
at: b.x,
|
|
7700
|
+
value: b.value,
|
|
7701
|
+
datum: end.datum,
|
|
7702
|
+
gapBefore: false
|
|
7703
|
+
});
|
|
7430
7704
|
const from = end.values[name] ?? 0;
|
|
7705
|
+
const value = curve ? curve.valueAt(last, last + 1, through) : from + share * ((next.values[name] ?? 0) - from);
|
|
7431
7706
|
vertices.push({
|
|
7432
7707
|
at: through,
|
|
7433
|
-
value
|
|
7708
|
+
value,
|
|
7434
7709
|
datum: end.datum,
|
|
7435
7710
|
gapBefore: false
|
|
7436
7711
|
});
|
|
@@ -7452,15 +7727,19 @@ function placeLines(frame, rows, series, through, time = false, labels) {
|
|
|
7452
7727
|
...points[points.length - 1],
|
|
7453
7728
|
text: labels.text(name, vertices[vertices.length - 1].value)
|
|
7454
7729
|
}))) : [];
|
|
7730
|
+
const boxes = labels ? placed.map((label) => label.text !== "" ? textBox(label, labels.measure, "ec-value", VALUE_SIZE) : void 0) : [];
|
|
7455
7731
|
return traced.map(({ name, vertices, points }) => {
|
|
7456
7732
|
const tip = points[points.length - 1];
|
|
7457
|
-
const
|
|
7733
|
+
const index = named.findIndex((line) => line.name === name);
|
|
7734
|
+
const label = labels ? placed[index] ?? {
|
|
7458
7735
|
x: tip.x + LABEL_GAP,
|
|
7459
7736
|
y: tip.y + VALUE_SIZE * CENTRE$1,
|
|
7460
7737
|
anchor: "start",
|
|
7461
7738
|
text: ""
|
|
7462
7739
|
} : void 0;
|
|
7463
|
-
const
|
|
7740
|
+
const own = boxes[index];
|
|
7741
|
+
const labelBounds = labels ? own ? [own] : [] : void 0;
|
|
7742
|
+
const nearbyLabels = labels ? boxes.filter((box, i) => box !== void 0 && i !== index) : void 0;
|
|
7464
7743
|
const breaks = vertices.flatMap((v, j) => v.gapBefore ? [j] : []);
|
|
7465
7744
|
const geometry = describeLine({
|
|
7466
7745
|
key: name,
|
|
@@ -7468,7 +7747,8 @@ function placeLines(frame, rows, series, through, time = false, labels) {
|
|
|
7468
7747
|
points,
|
|
7469
7748
|
width: LINE_WIDTH,
|
|
7470
7749
|
...breaks.length > 0 ? { breaks } : {},
|
|
7471
|
-
...labelBounds ? { labelBounds } : {}
|
|
7750
|
+
...labelBounds ? { labelBounds } : {},
|
|
7751
|
+
...nearbyLabels ? { nearbyLabels } : {}
|
|
7472
7752
|
});
|
|
7473
7753
|
let distance = 0;
|
|
7474
7754
|
const samples = vertices.map((v, j) => {
|
|
@@ -7779,6 +8059,7 @@ const VISIBLE = .5;
|
|
|
7779
8059
|
function lineChart$1(target, options, env) {
|
|
7780
8060
|
const container = resolveTarget$2(target, "lineChart");
|
|
7781
8061
|
checkChartOptions(options, "lineChart");
|
|
8062
|
+
let hoverKind = hoverOf(options);
|
|
7782
8063
|
let current = options;
|
|
7783
8064
|
const motion = chartMotion(options.motion, env.motion);
|
|
7784
8065
|
let effects = resolveEffects(options.on, env.presets);
|
|
@@ -7836,10 +8117,12 @@ function lineChart$1(target, options, env) {
|
|
|
7836
8117
|
let laidOut;
|
|
7837
8118
|
let firstTable;
|
|
7838
8119
|
let names;
|
|
8120
|
+
let pointNames;
|
|
7839
8121
|
try {
|
|
7840
8122
|
laidOut = layout(current);
|
|
7841
8123
|
firstTable = tableFor(current, laidOut);
|
|
7842
8124
|
names = namesFor(current, laidOut);
|
|
8125
|
+
pointNames = hoverKind === "point" ? pointNamesFor(current, laidOut) : void 0;
|
|
7843
8126
|
} catch (error) {
|
|
7844
8127
|
svg.remove();
|
|
7845
8128
|
throw error;
|
|
@@ -7888,6 +8171,11 @@ function lineChart$1(target, options, env) {
|
|
|
7888
8171
|
motion,
|
|
7889
8172
|
onChange: changed
|
|
7890
8173
|
});
|
|
8174
|
+
const curved = animated(bendOf(laidOut.curve), interpolateNumber, {
|
|
8175
|
+
clock,
|
|
8176
|
+
motion,
|
|
8177
|
+
onChange: changed
|
|
8178
|
+
});
|
|
7891
8179
|
const yTicks = /* @__PURE__ */ new Map();
|
|
7892
8180
|
const xTicks = /* @__PURE__ */ new Map();
|
|
7893
8181
|
let counting = laidOut.decimals;
|
|
@@ -7955,7 +8243,7 @@ function lineChart$1(target, options, env) {
|
|
|
7955
8243
|
function placedFor(next) {
|
|
7956
8244
|
const states = next.rows.map(restState);
|
|
7957
8245
|
return {
|
|
7958
|
-
lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals)).map((line) => [line.series, line])),
|
|
8246
|
+
lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals), bendOf(next.curve)).map((line) => [line.series, line])),
|
|
7959
8247
|
points: new Map(states.flatMap((state) => placePoints(next.frame, state, next.series, next.time)).map((point) => [point.key, point]))
|
|
7960
8248
|
};
|
|
7961
8249
|
}
|
|
@@ -8090,6 +8378,7 @@ function lineChart$1(target, options, env) {
|
|
|
8090
8378
|
};
|
|
8091
8379
|
return [...rowOrder, ...[...leavingRows.values()].filter((record) => record.presence.value > 0 && record.anchor)].map((record) => {
|
|
8092
8380
|
const { x, values } = stateOf(record);
|
|
8381
|
+
const presence = record.anchor && record.presence.value < 1 ? { presence: record.presence.value } : {};
|
|
8093
8382
|
return {
|
|
8094
8383
|
record,
|
|
8095
8384
|
state: {
|
|
@@ -8097,7 +8386,8 @@ function lineChart$1(target, options, env) {
|
|
|
8097
8386
|
datum: record.row.datum,
|
|
8098
8387
|
x,
|
|
8099
8388
|
values,
|
|
8100
|
-
missing: record.row.missing
|
|
8389
|
+
missing: record.row.missing,
|
|
8390
|
+
...presence
|
|
8101
8391
|
}
|
|
8102
8392
|
};
|
|
8103
8393
|
}).sort((a, b) => a.state.x - b.state.x);
|
|
@@ -8212,7 +8502,7 @@ function lineChart$1(target, options, env) {
|
|
|
8212
8502
|
function paintLines(frame, states) {
|
|
8213
8503
|
const drawnLines = [...lineOrder, ...leavingLines()];
|
|
8214
8504
|
if (states.length === 0 || drawnLines.length === 0) return;
|
|
8215
|
-
const placed = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting));
|
|
8505
|
+
const placed = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting), curved.value);
|
|
8216
8506
|
showAll(drawnLines.map((line, i) => ({
|
|
8217
8507
|
record: line,
|
|
8218
8508
|
placed: placed[i]
|
|
@@ -8303,8 +8593,16 @@ function lineChart$1(target, options, env) {
|
|
|
8303
8593
|
surface.hide(point.key, hidden);
|
|
8304
8594
|
}
|
|
8305
8595
|
}
|
|
8596
|
+
if (stopsLayer) paintStops(frame);
|
|
8306
8597
|
}
|
|
8307
8598
|
function showHover(key) {
|
|
8599
|
+
const point = points.get(key);
|
|
8600
|
+
if (point) {
|
|
8601
|
+
if (!revealed(point.row)) return;
|
|
8602
|
+
const { row } = point.row;
|
|
8603
|
+
tooltip.show(point.shown.geometry, about(row, point.series), () => pointSummary(row, point.series, current), point.handle.style.transform);
|
|
8604
|
+
return;
|
|
8605
|
+
}
|
|
8308
8606
|
const record = rows.get(key);
|
|
8309
8607
|
if (!record || !revealed(record)) return;
|
|
8310
8608
|
const marks = livePoints(record);
|
|
@@ -8337,9 +8635,10 @@ function lineChart$1(target, options, env) {
|
|
|
8337
8635
|
}
|
|
8338
8636
|
let ringLine;
|
|
8339
8637
|
function drawRing(key) {
|
|
8340
|
-
const
|
|
8638
|
+
const point = key === void 0 ? void 0 : points.get(key);
|
|
8639
|
+
const record = key === void 0 ? void 0 : point?.row ?? rows.get(key);
|
|
8341
8640
|
const live = record !== void 0 && revealed(record);
|
|
8342
|
-
const marks = live ? livePoints(record) : [];
|
|
8641
|
+
const marks = live ? point ? [point] : livePoints(record) : [];
|
|
8343
8642
|
if (live && marks.length === 0) {
|
|
8344
8643
|
ringLine ?? (ringLine = svgElement("line", {
|
|
8345
8644
|
class: "ec-focus-ring",
|
|
@@ -8389,34 +8688,243 @@ function lineChart$1(target, options, env) {
|
|
|
8389
8688
|
const record = column ? byColumn.get(column) : void 0;
|
|
8390
8689
|
return record && rows.get(record.key) === record && revealed(record) ? record : void 0;
|
|
8391
8690
|
}
|
|
8691
|
+
let stopsLayer;
|
|
8692
|
+
let plotHit;
|
|
8693
|
+
const stops = /* @__PURE__ */ new Map();
|
|
8694
|
+
let stopOrder = [];
|
|
8695
|
+
const byStop = /* @__PURE__ */ new WeakMap();
|
|
8696
|
+
function pointOrder() {
|
|
8697
|
+
const bySeries = new Map(laidOut.series.map((series) => [series, []]));
|
|
8698
|
+
for (const record of rowOrder) for (const point of livePoints(record)) bySeries.get(point.series)?.push(point);
|
|
8699
|
+
return [...bySeries.values()].flat();
|
|
8700
|
+
}
|
|
8701
|
+
const along = (series) => rowOrder.filter(revealed).flatMap((record) => livePoints(record).filter((point) => point.series === series));
|
|
8702
|
+
function nearestPoint(at) {
|
|
8703
|
+
let best;
|
|
8704
|
+
let far = Infinity;
|
|
8705
|
+
let rank = Infinity;
|
|
8706
|
+
for (const record of rowOrder) {
|
|
8707
|
+
if (!revealed(record)) continue;
|
|
8708
|
+
for (const point of livePoints(record)) {
|
|
8709
|
+
const { x, y } = point.shown.geometry.center;
|
|
8710
|
+
const d = (x - at.x) ** 2 + (y - at.y) ** 2;
|
|
8711
|
+
const r = laidOut.series.indexOf(point.series);
|
|
8712
|
+
if (d < far || d === far && r < rank) [best, far, rank] = [
|
|
8713
|
+
point,
|
|
8714
|
+
d,
|
|
8715
|
+
r
|
|
8716
|
+
];
|
|
8717
|
+
}
|
|
8718
|
+
}
|
|
8719
|
+
return best;
|
|
8720
|
+
}
|
|
8721
|
+
function heldPoint(at) {
|
|
8722
|
+
const point = hover.key === void 0 || !tooltip.element() ? void 0 : points.get(hover.key);
|
|
8723
|
+
if (!point || !revealed(point.row)) return void 0;
|
|
8724
|
+
const { transform } = point.handle.style;
|
|
8725
|
+
let on = at;
|
|
8726
|
+
if (transform) try {
|
|
8727
|
+
on = matrix.apply(invert(transform), at);
|
|
8728
|
+
} catch {
|
|
8729
|
+
return;
|
|
8730
|
+
}
|
|
8731
|
+
const { center } = point.shown.geometry;
|
|
8732
|
+
return (on.x - center.x) ** 2 + (on.y - center.y) ** 2 <= 4.5 ** 2 ? point : void 0;
|
|
8733
|
+
}
|
|
8734
|
+
function pointAt(clientX, clientY) {
|
|
8735
|
+
const at = fromClient(clientX, clientY);
|
|
8736
|
+
return heldPoint(at) ?? nearestPoint(at);
|
|
8737
|
+
}
|
|
8738
|
+
function fromClient(x, y) {
|
|
8739
|
+
const box = svg.getBoundingClientRect();
|
|
8740
|
+
const k = box.width > 0 && drawnFrame.box.width > 0 ? box.width / drawnFrame.box.width : 1;
|
|
8741
|
+
return {
|
|
8742
|
+
x: (x - box.left) / k,
|
|
8743
|
+
y: (y - box.top) / k
|
|
8744
|
+
};
|
|
8745
|
+
}
|
|
8746
|
+
const abouts = /* @__PURE__ */ new WeakMap();
|
|
8747
|
+
function about(row, series) {
|
|
8748
|
+
let bySeries = abouts.get(row);
|
|
8749
|
+
if (!bySeries) abouts.set(row, bySeries = /* @__PURE__ */ new Map());
|
|
8750
|
+
let known = bySeries.get(series);
|
|
8751
|
+
if (!known) bySeries.set(series, known = {
|
|
8752
|
+
datum: row.datum,
|
|
8753
|
+
series
|
|
8754
|
+
});
|
|
8755
|
+
return known;
|
|
8756
|
+
}
|
|
8757
|
+
function syncStops() {
|
|
8758
|
+
if (hoverKind !== "point") return;
|
|
8759
|
+
if (!stopsLayer) {
|
|
8760
|
+
stopsLayer = svgElement("g", { class: "ec-stops" }, svg);
|
|
8761
|
+
svg.insertBefore(stopsLayer, overlay);
|
|
8762
|
+
plotHit = svgElement("rect", { class: "ec-hit" }, stopsLayer);
|
|
8763
|
+
stopsLayer.addEventListener("click", (event) => {
|
|
8764
|
+
const point = pointAt(event.clientX, event.clientY);
|
|
8765
|
+
if (point) stops.get(point.key)?.element.focus();
|
|
8766
|
+
});
|
|
8767
|
+
}
|
|
8768
|
+
const live = pointOrder();
|
|
8769
|
+
const keep = new Set(live.map((point) => point.key));
|
|
8770
|
+
for (const [key, stop] of stops) {
|
|
8771
|
+
if (keep.has(key)) continue;
|
|
8772
|
+
stop.element.remove();
|
|
8773
|
+
stops.delete(key);
|
|
8774
|
+
}
|
|
8775
|
+
const order = live.map((point) => {
|
|
8776
|
+
let stop = stops.get(point.key);
|
|
8777
|
+
if (!stop) {
|
|
8778
|
+
const element = svgElement("g", {
|
|
8779
|
+
class: "ec-stop",
|
|
8780
|
+
"data-key": point.key,
|
|
8781
|
+
role: "img"
|
|
8782
|
+
}, stopsLayer);
|
|
8783
|
+
stop = {
|
|
8784
|
+
element,
|
|
8785
|
+
bounds: svgElement("circle", {
|
|
8786
|
+
r: 8.5,
|
|
8787
|
+
fill: "none"
|
|
8788
|
+
}, element),
|
|
8789
|
+
x: NaN,
|
|
8790
|
+
y: NaN,
|
|
8791
|
+
hidden: void 0
|
|
8792
|
+
};
|
|
8793
|
+
stops.set(point.key, stop);
|
|
8794
|
+
byStop.set(element, point.key);
|
|
8795
|
+
}
|
|
8796
|
+
const name = pointNames?.get(point.key) ?? point.key;
|
|
8797
|
+
if (stop.element.getAttribute("aria-label") !== name) stop.element.setAttribute("aria-label", name);
|
|
8798
|
+
tooltip.describe(stop.element, about(point.row.row, point.series));
|
|
8799
|
+
return stop.element;
|
|
8800
|
+
});
|
|
8801
|
+
orderElements(stopsLayer, stopOrder, order, hover.active);
|
|
8802
|
+
stopOrder = order;
|
|
8803
|
+
}
|
|
8804
|
+
function paintStops(frame) {
|
|
8805
|
+
const { left, right, top, bottom } = frame.box;
|
|
8806
|
+
setAttributes(plotHit, {
|
|
8807
|
+
x: left - DOT_RADIUS,
|
|
8808
|
+
y: top - DOT_RADIUS,
|
|
8809
|
+
width: right - left + 2 * DOT_RADIUS,
|
|
8810
|
+
height: bottom - top + 2 * DOT_RADIUS
|
|
8811
|
+
});
|
|
8812
|
+
for (const [key, stop] of stops) {
|
|
8813
|
+
const point = points.get(key);
|
|
8814
|
+
if (!point) continue;
|
|
8815
|
+
const hidden = !revealed(point.row);
|
|
8816
|
+
if (stop.hidden !== hidden) {
|
|
8817
|
+
stop.hidden = hidden;
|
|
8818
|
+
setAttributes(stop.element, { visibility: hidden ? "hidden" : void 0 });
|
|
8819
|
+
}
|
|
8820
|
+
const { x, y } = point.shown.geometry.center;
|
|
8821
|
+
if (stop.x === x && stop.y === y) continue;
|
|
8822
|
+
stop.x = x;
|
|
8823
|
+
stop.y = y;
|
|
8824
|
+
setAttributes(stop.bounds, {
|
|
8825
|
+
cx: x,
|
|
8826
|
+
cy: y
|
|
8827
|
+
});
|
|
8828
|
+
}
|
|
8829
|
+
}
|
|
8830
|
+
function counterpart(key) {
|
|
8831
|
+
const point = points.get(key);
|
|
8832
|
+
if (point) return point.row.key;
|
|
8833
|
+
const shown = rowOrder.filter(revealed);
|
|
8834
|
+
const i = shown.findIndex((record) => record.key === key);
|
|
8835
|
+
for (let step = 0; i >= 0 && step < shown.length; step++) for (const at of [i + step, i - step]) {
|
|
8836
|
+
const first = shown[at] && livePoints(shown[at])[0];
|
|
8837
|
+
if (first) return first.key;
|
|
8838
|
+
}
|
|
8839
|
+
}
|
|
8840
|
+
function rehover(kind) {
|
|
8841
|
+
if (kind === hoverKind) return;
|
|
8842
|
+
hover.leave();
|
|
8843
|
+
hoverKind = kind;
|
|
8844
|
+
if (kind === "point") {
|
|
8845
|
+
syncStops();
|
|
8846
|
+
paintStops(drawnFrame);
|
|
8847
|
+
} else columnsLayer.removeAttribute("display");
|
|
8848
|
+
hover.retarget(counterpart);
|
|
8849
|
+
if (kind === "point") columnsLayer.setAttribute("display", "none");
|
|
8850
|
+
else {
|
|
8851
|
+
stopsLayer?.remove();
|
|
8852
|
+
stopsLayer = plotHit = void 0;
|
|
8853
|
+
stops.clear();
|
|
8854
|
+
stopOrder = [];
|
|
8855
|
+
}
|
|
8856
|
+
}
|
|
8857
|
+
const hotLines = /* @__PURE__ */ new Map();
|
|
8858
|
+
function heat(key, on) {
|
|
8859
|
+
const series = on ? hoverKind === "point" ? findMark(key)?.series : void 0 : hotLines.get(key);
|
|
8860
|
+
if (series === void 0) return;
|
|
8861
|
+
if (on) hotLines.set(key, series);
|
|
8862
|
+
else hotLines.delete(key);
|
|
8863
|
+
surface.hot(key, on);
|
|
8864
|
+
if (!on && [...hotLines.values()].includes(series)) return;
|
|
8865
|
+
findMark(series)?.group.classList.toggle("ec-hot-line", on);
|
|
8866
|
+
surface.hot(series, on);
|
|
8867
|
+
}
|
|
8868
|
+
function live(key) {
|
|
8869
|
+
const point = hoverKind === "point" ? points.get(key) : void 0;
|
|
8870
|
+
const record = hoverKind === "point" ? point?.row : rows.get(key);
|
|
8871
|
+
return record !== void 0 && revealed(record);
|
|
8872
|
+
}
|
|
8392
8873
|
const hover = chartHover({
|
|
8393
8874
|
svg,
|
|
8394
8875
|
runner,
|
|
8395
8876
|
events,
|
|
8396
|
-
dim: () => false,
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
|
|
8400
|
-
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
|
|
8877
|
+
dim: () => hoverKind === "point" && current.dim !== false && hover.key !== void 0,
|
|
8878
|
+
hot: heat,
|
|
8879
|
+
find(eventTarget, pointer) {
|
|
8880
|
+
if (hoverKind === "x") {
|
|
8881
|
+
const record = liveRowOf(eventTarget);
|
|
8882
|
+
return record && { key: record.key };
|
|
8883
|
+
}
|
|
8884
|
+
const element = eventTarget;
|
|
8885
|
+
if (!stopsLayer || typeof element?.closest !== "function" || !stopsLayer.contains(element)) return void 0;
|
|
8886
|
+
if (pointer) {
|
|
8887
|
+
const point = pointAt(pointer.x, pointer.y);
|
|
8888
|
+
return point && { key: point.key };
|
|
8889
|
+
}
|
|
8890
|
+
const stop = element.closest(".ec-stop");
|
|
8891
|
+
const key = stop ? byStop.get(stop) : void 0;
|
|
8892
|
+
return key !== void 0 && live(key) ? { key } : void 0;
|
|
8404
8893
|
},
|
|
8405
|
-
|
|
8894
|
+
moves: () => hoverKind === "point",
|
|
8895
|
+
live,
|
|
8896
|
+
order: () => (hoverKind === "point" ? pointOrder().filter((point) => revealed(point.row)) : rowOrder.filter(revealed)).map((record) => record.key),
|
|
8406
8897
|
page(key, by) {
|
|
8407
|
-
const
|
|
8408
|
-
|
|
8409
|
-
|
|
8410
|
-
|
|
8411
|
-
|
|
8412
|
-
|
|
8898
|
+
const point = hoverKind === "point" ? points.get(key) : void 0;
|
|
8899
|
+
const stops = point ? along(point.series).map((p) => ({
|
|
8900
|
+
key: p.key,
|
|
8901
|
+
x: p.row.row.x
|
|
8902
|
+
})) : rowOrder.filter(revealed).map((record) => ({
|
|
8903
|
+
key: record.key,
|
|
8904
|
+
x: record.row.x
|
|
8905
|
+
}));
|
|
8906
|
+
const i = stops.findIndex((stop) => stop.key === key);
|
|
8907
|
+
if (i < 0) return void 0;
|
|
8908
|
+
if (!laidOut.time) return point ? stops[Math.min(stops.length - 1, Math.max(0, i + by * Math.ceil(stops.length / 10)))].key : void 0;
|
|
8909
|
+
const to = monthsOn(stops[i].x, by, lineEncoding(current).timeZone);
|
|
8910
|
+
if (by > 0) return (stops.find((stop) => stop.x >= to) ?? stops[stops.length - 1])?.key;
|
|
8911
|
+
for (let j = stops.length - 1; j >= 0; j--) if (stops[j].x <= to) return stops[j].key;
|
|
8413
8912
|
return stops[0]?.key;
|
|
8414
8913
|
},
|
|
8914
|
+
move(key, press) {
|
|
8915
|
+
const point = hoverKind === "point" ? points.get(key) : void 0;
|
|
8916
|
+
if (!point) return void 0;
|
|
8917
|
+
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);
|
|
8918
|
+
const i = stops.indexOf(point);
|
|
8919
|
+
const to = press === "Home" ? 0 : press === "End" ? stops.length - 1 : i + (press === "ArrowDown" || press === "ArrowRight" ? 1 : -1);
|
|
8920
|
+
return stops[Math.max(0, Math.min(stops.length - 1, to))]?.key;
|
|
8921
|
+
},
|
|
8415
8922
|
marks: (key) => {
|
|
8416
8923
|
const record = rows.get(key);
|
|
8417
|
-
|
|
8924
|
+
if (record) return livePoints(record).map((point) => point.key);
|
|
8925
|
+
return points.has(key) ? [key] : [];
|
|
8418
8926
|
},
|
|
8419
|
-
element: (key) => (rows.get(key) ?? leavingRows.get(key))?.column,
|
|
8927
|
+
element: (key) => (rows.get(key) ?? leavingRows.get(key))?.column ?? stops.get(key)?.element,
|
|
8420
8928
|
markElement: (key) => findMark(key)?.group,
|
|
8421
8929
|
onScreen(key) {
|
|
8422
8930
|
const record = findMark(key);
|
|
@@ -8455,7 +8963,7 @@ function lineChart$1(target, options, env) {
|
|
|
8455
8963
|
}
|
|
8456
8964
|
function labelColumn(record) {
|
|
8457
8965
|
record.column.setAttribute("aria-label", names.get(record.key));
|
|
8458
|
-
tooltip.describe(record.column, record.row);
|
|
8966
|
+
if (hoverKind === "x") tooltip.describe(record.column, record.row);
|
|
8459
8967
|
}
|
|
8460
8968
|
function announceChange(previous, before) {
|
|
8461
8969
|
const option = current.announce;
|
|
@@ -8591,6 +9099,7 @@ function lineChart$1(target, options, env) {
|
|
|
8591
9099
|
record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn(point))];
|
|
8592
9100
|
}
|
|
8593
9101
|
for (const record of rowOrder) labelColumn(record);
|
|
9102
|
+
syncStops();
|
|
8594
9103
|
orderElements(columnsLayer, before.filter((record) => !record.leaving).map((record) => record.column), rowOrder.map((record) => record.column), hover.active);
|
|
8595
9104
|
orderElements(linesLayer, previousLines.map((line) => line.group), lineOrder.map((line) => line.group), () => null);
|
|
8596
9105
|
rowChanges = changes;
|
|
@@ -8620,7 +9129,7 @@ function lineChart$1(target, options, env) {
|
|
|
8620
9129
|
for (const tick of next.xTicks) xTicks.get(tick.value).text = tick.label.text;
|
|
8621
9130
|
const goingLines = leavingLines();
|
|
8622
9131
|
const folding = [...leavingRows.values()];
|
|
8623
|
-
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));
|
|
9132
|
+
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);
|
|
8624
9133
|
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));
|
|
8625
9134
|
let first;
|
|
8626
9135
|
let second;
|
|
@@ -8638,6 +9147,7 @@ function lineChart$1(target, options, env) {
|
|
|
8638
9147
|
else value.set(to);
|
|
8639
9148
|
};
|
|
8640
9149
|
move(scale, frame.scale, sameFields, first);
|
|
9150
|
+
move(curved, bendOf(next.curve), same, first);
|
|
8641
9151
|
move(box, frame.box, sameFields, second);
|
|
8642
9152
|
for (const tick of yTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
|
|
8643
9153
|
for (const tick of xTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, second);
|
|
@@ -8714,6 +9224,8 @@ function lineChart$1(target, options, env) {
|
|
|
8714
9224
|
});
|
|
8715
9225
|
lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed.lines.get(name), false)) : [];
|
|
8716
9226
|
for (const line of lineOrder) lines.set(line.series, line);
|
|
9227
|
+
syncStops();
|
|
9228
|
+
if (hoverKind === "point") columnsLayer.setAttribute("display", "none");
|
|
8717
9229
|
land();
|
|
8718
9230
|
}
|
|
8719
9231
|
const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
|
|
@@ -8729,15 +9241,18 @@ function lineChart$1(target, options, env) {
|
|
|
8729
9241
|
...next
|
|
8730
9242
|
};
|
|
8731
9243
|
checkChartOptions(merged, "lineChart");
|
|
9244
|
+
const kind = hoverOf(merged);
|
|
8732
9245
|
const swapped = "on" in next ? nextEffects(effects, current.on, merged.on, env.presets) : effects;
|
|
8733
9246
|
const nextLayout = layout(merged, swapped);
|
|
8734
9247
|
const nextTable = tableFor(merged, nextLayout);
|
|
8735
9248
|
const nextNames = namesFor(merged, nextLayout);
|
|
9249
|
+
const nextPointNames = kind === "point" ? pointNamesFor(merged, nextLayout) : void 0;
|
|
8736
9250
|
if ("colors" in next) colors = toColorAssignment(merged.colors);
|
|
8737
9251
|
const previous = current;
|
|
8738
9252
|
const seriesBefore = laidOut.series;
|
|
8739
9253
|
current = merged;
|
|
8740
9254
|
names = nextNames;
|
|
9255
|
+
pointNames = nextPointNames;
|
|
8741
9256
|
describeChart(svg, current);
|
|
8742
9257
|
table.render(nextTable);
|
|
8743
9258
|
const announcing = announcer !== void 0;
|
|
@@ -8746,6 +9261,8 @@ function lineChart$1(target, options, env) {
|
|
|
8746
9261
|
announcer.destroy();
|
|
8747
9262
|
announcer = void 0;
|
|
8748
9263
|
}
|
|
9264
|
+
rehover(kind);
|
|
9265
|
+
hover.syncDim();
|
|
8749
9266
|
transitions.supersede();
|
|
8750
9267
|
const swapping = swapped !== effects;
|
|
8751
9268
|
effects = swapped;
|
|
@@ -8784,8 +9301,14 @@ function lineChart$1(target, options, env) {
|
|
|
8784
9301
|
marks: () => [...lineOrder.map((line) => line.shown.geometry), ...rowOrder.filter(revealed).flatMap((record) => livePoints(record).map((point) => point.shown.geometry))],
|
|
8785
9302
|
focus(key) {
|
|
8786
9303
|
if (destroyed) return;
|
|
8787
|
-
const
|
|
8788
|
-
if (
|
|
9304
|
+
const row = rows.get(key);
|
|
9305
|
+
if (hoverKind === "x") {
|
|
9306
|
+
const record = row ?? points.get(key)?.row;
|
|
9307
|
+
if (record) hover.focus(record.key);
|
|
9308
|
+
return;
|
|
9309
|
+
}
|
|
9310
|
+
const point = points.get(key) ?? (row && livePoints(row)[0]);
|
|
9311
|
+
if (point) hover.focus(point.key);
|
|
8789
9312
|
},
|
|
8790
9313
|
leave() {
|
|
8791
9314
|
if (!destroyed) hover.leave();
|
|
@@ -8813,6 +9336,7 @@ function lineChart$1(target, options, env) {
|
|
|
8813
9336
|
for (const record of leaving.values()) record.leave?.resolve();
|
|
8814
9337
|
scale.stop();
|
|
8815
9338
|
box.stop();
|
|
9339
|
+
curved.stop();
|
|
8816
9340
|
for (const tick of [...yTicks.values(), ...xTicks.values()]) tick.opacity.stop();
|
|
8817
9341
|
events.clear();
|
|
8818
9342
|
rows.clear();
|
|
@@ -8885,28 +9409,53 @@ function summary(row, options) {
|
|
|
8885
9409
|
lines: [said(row.values, options).join(" · ")]
|
|
8886
9410
|
};
|
|
8887
9411
|
}
|
|
9412
|
+
function pointSummary(row, series, options) {
|
|
9413
|
+
return summaryContent(row.label, labelled(row.values, options).filter((v) => v.series === series), format(options), { total: false });
|
|
9414
|
+
}
|
|
9415
|
+
function worded(options, datum, mark) {
|
|
9416
|
+
if (!options.markLabel) return mark.text;
|
|
9417
|
+
try {
|
|
9418
|
+
const named = options.markLabel(datum, mark);
|
|
9419
|
+
if (named !== void 0 && named !== null && String(named).trim() !== "") return String(named);
|
|
9420
|
+
} catch (error) {
|
|
9421
|
+
report(error);
|
|
9422
|
+
}
|
|
9423
|
+
return mark.text;
|
|
9424
|
+
}
|
|
8888
9425
|
function namesFor(options, layout) {
|
|
8889
9426
|
const formatted = format(options);
|
|
8890
9427
|
return new Map(layout.rows.map((row) => {
|
|
8891
|
-
const values = labelled(row.values, options);
|
|
8892
9428
|
const text = `${row.label}: ${said(row.values, options).join(", ")}`;
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
text
|
|
8902
|
-
});
|
|
8903
|
-
if (named !== void 0 && named !== null && String(named).trim() !== "") return [row.key, String(named)];
|
|
8904
|
-
} catch (error) {
|
|
8905
|
-
report(error);
|
|
8906
|
-
}
|
|
8907
|
-
return [row.key, text];
|
|
9429
|
+
return [row.key, worded(options, row.datum, {
|
|
9430
|
+
key: row.key,
|
|
9431
|
+
category: row.label,
|
|
9432
|
+
values: labelled(row.values, options),
|
|
9433
|
+
total: total(row.values),
|
|
9434
|
+
format: formatted,
|
|
9435
|
+
text
|
|
9436
|
+
})];
|
|
8908
9437
|
}));
|
|
8909
9438
|
}
|
|
9439
|
+
function pointNamesFor(options, layout) {
|
|
9440
|
+
const formatted = format(options);
|
|
9441
|
+
return new Map(layout.rows.flatMap((row) => labelled(row.values, options).map((value) => {
|
|
9442
|
+
const key = pointKey(value.series, row.key);
|
|
9443
|
+
const text = `${row.label}: ${formatted(value.value)} ${value.label}`;
|
|
9444
|
+
return [key, worded(options, row.datum, {
|
|
9445
|
+
key,
|
|
9446
|
+
category: row.label,
|
|
9447
|
+
values: [value],
|
|
9448
|
+
total: value.value,
|
|
9449
|
+
format: formatted,
|
|
9450
|
+
text
|
|
9451
|
+
})];
|
|
9452
|
+
})));
|
|
9453
|
+
}
|
|
9454
|
+
function hoverOf(options) {
|
|
9455
|
+
const { hover = "x" } = options;
|
|
9456
|
+
if (hover !== "x" && hover !== "point") throw new TypeError(`lineChart: hover must be "x" or "point", got ${typeof hover === "string" ? JSON.stringify(hover) : String(hover)}.`);
|
|
9457
|
+
return hover;
|
|
9458
|
+
}
|
|
8910
9459
|
// src/core/geometry/ring.ts
|
|
8911
9460
|
const ROUND = .5;
|
|
8912
9461
|
function goesRound(mark) {
|
|
@@ -10811,10 +11360,12 @@ function namesIn(root) {
|
|
|
10811
11360
|
}
|
|
10812
11361
|
const lineItems = (first) => first.mark?.items ?? [first];
|
|
10813
11362
|
const drawsLine = (first) => lineItems(first).some((item) => item.defined !== false);
|
|
11363
|
+
const straight = (first) => {
|
|
11364
|
+
const interpolate = lineItems(first)[0]?.interpolate;
|
|
11365
|
+
return interpolate === void 0 || interpolate === "linear";
|
|
11366
|
+
};
|
|
10814
11367
|
function pointsOf(first) {
|
|
10815
11368
|
const items = lineItems(first);
|
|
10816
|
-
const interpolate = items[0]?.interpolate;
|
|
10817
|
-
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.`);
|
|
10818
11369
|
const points = [];
|
|
10819
11370
|
let gap = false;
|
|
10820
11371
|
for (const item of items) {
|
|
@@ -10836,6 +11387,16 @@ function pointsOf(first) {
|
|
|
10836
11387
|
}
|
|
10837
11388
|
function lineOf(key, element, first, m) {
|
|
10838
11389
|
const width = first.strokeWidth ?? Number.parseFloat(element.getAttribute("stroke-width") ?? "1");
|
|
11390
|
+
if (!straight(first)) {
|
|
11391
|
+
const scaled = width * scaleOf(m);
|
|
11392
|
+
return describeShape({
|
|
11393
|
+
key,
|
|
11394
|
+
series: key,
|
|
11395
|
+
d: element.getAttribute("d") ?? "",
|
|
11396
|
+
matrix: m,
|
|
11397
|
+
width: scaled > 0 && Number.isFinite(scaled) ? scaled : 1
|
|
11398
|
+
});
|
|
11399
|
+
}
|
|
10839
11400
|
const points = pointsOf(first);
|
|
10840
11401
|
const breaks = points.flatMap((p, i) => p.gapBefore ? [i] : []);
|
|
10841
11402
|
return describeLine({
|
|
@@ -11740,7 +12301,7 @@ function checkOptions$8(options) {
|
|
|
11740
12301
|
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)}.`);
|
|
11741
12302
|
}
|
|
11742
12303
|
// src/effects/gaits.ts
|
|
11743
|
-
const STILL = Object.freeze({
|
|
12304
|
+
const STILL = /* @__PURE__ */ Object.freeze({
|
|
11744
12305
|
lift: 0,
|
|
11745
12306
|
spin: 0,
|
|
11746
12307
|
tilt: 0
|
|
@@ -12203,22 +12764,23 @@ const PAST_LABEL = 6;
|
|
|
12203
12764
|
const TEXT = 12.5;
|
|
12204
12765
|
const CENTRE = .36;
|
|
12205
12766
|
function captionPlace(mark) {
|
|
12206
|
-
const
|
|
12767
|
+
const own = mark.labelBounds ?? [];
|
|
12768
|
+
const nearby = mark.nearbyLabels ?? [];
|
|
12207
12769
|
const heading = mark.angle(1);
|
|
12208
|
-
const along = farthest(mark.end, heading,
|
|
12209
|
-
if (along === void 0 &&
|
|
12770
|
+
const along = farthest(mark.end, heading, own);
|
|
12771
|
+
if (along === void 0 && own.length > 0) {
|
|
12210
12772
|
const up = mark.angle(.5) - Math.PI / 2;
|
|
12211
|
-
const out = farthest(mark.center, up,
|
|
12212
|
-
if (out !== void 0) return placed(mark.center, up, out);
|
|
12773
|
+
const out = farthest(mark.center, up, own);
|
|
12774
|
+
if (out !== void 0) return placed(mark.center, up, Math.max(out, farthest(mark.center, up, nearby) ?? -Infinity));
|
|
12213
12775
|
}
|
|
12214
|
-
return placed(mark.end, heading, Math.max(PAST_END, along ?? -Infinity));
|
|
12776
|
+
return placed(mark.end, heading, Math.max(PAST_END, along ?? -Infinity, farthest(mark.end, heading, nearby) ?? -Infinity));
|
|
12215
12777
|
}
|
|
12216
12778
|
function placed(from, toward, distance) {
|
|
12217
12779
|
const cos = Math.cos(toward);
|
|
12218
12780
|
const sin = Math.sin(toward);
|
|
12219
12781
|
const point = offset(from, toward, distance);
|
|
12220
12782
|
const drop = TEXT * (sin < 0 ? CENTRE * (1 + sin) : CENTRE + .44000000000000006 * sin);
|
|
12221
|
-
const anchor =
|
|
12783
|
+
const anchor = centred(cos) ? "middle" : cos > 0 ? "start" : "end";
|
|
12222
12784
|
return {
|
|
12223
12785
|
at: {
|
|
12224
12786
|
x: point.x,
|
|
@@ -12228,17 +12790,23 @@ function placed(from, toward, distance) {
|
|
|
12228
12790
|
toward
|
|
12229
12791
|
};
|
|
12230
12792
|
}
|
|
12793
|
+
function centred(cos) {
|
|
12794
|
+
return Math.abs(cos) <= Math.SQRT1_2 + 1e-9;
|
|
12795
|
+
}
|
|
12231
12796
|
function farthest(from, toward, boxes) {
|
|
12232
12797
|
const cos = Math.cos(toward);
|
|
12233
12798
|
const sin = Math.sin(toward);
|
|
12799
|
+
const across = centred(cos);
|
|
12234
12800
|
let exit;
|
|
12235
12801
|
for (const { x, y, width, height } of boxes) {
|
|
12236
|
-
const
|
|
12802
|
+
const grown = {
|
|
12237
12803
|
x: x - PAST_LABEL,
|
|
12238
12804
|
y: y - PAST_LABEL,
|
|
12239
12805
|
width: width + 12,
|
|
12240
12806
|
height: height + 12
|
|
12241
|
-
}
|
|
12807
|
+
};
|
|
12808
|
+
let leaving = leaves(from, cos, sin, grown);
|
|
12809
|
+
if (leaving !== void 0 && across) leaving = Math.max(leaving, ((sin > 0 ? grown.y + grown.height : grown.y) - from.y) / sin);
|
|
12242
12810
|
if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
|
|
12243
12811
|
}
|
|
12244
12812
|
return exit;
|
|
@@ -13277,7 +13845,7 @@ function configure(options) {
|
|
|
13277
13845
|
}
|
|
13278
13846
|
}
|
|
13279
13847
|
// src/index.ts
|
|
13280
|
-
const VERSION = "0.
|
|
13848
|
+
const VERSION = "0.5.0";
|
|
13281
13849
|
const env = {
|
|
13282
13850
|
presets: presetRegistry,
|
|
13283
13851
|
icons: iconRegistry,
|