expressive-charts 0.2.0 → 0.3.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 +29 -0
- package/README.md +8 -8
- package/dist/{chunk-N5IF2RO2.js → chunk-7A7LXXT4.js} +6 -2
- package/dist/chunk-7A7LXXT4.js.map +1 -0
- package/dist/{chunk-V5IUTXRW.js → chunk-CJUQHEX6.js} +70 -23
- package/dist/chunk-CJUQHEX6.js.map +1 -0
- package/dist/{chunk-CVXP2L2J.js → chunk-N2BLUETM.js} +17 -5
- package/dist/chunk-N2BLUETM.js.map +1 -0
- package/dist/{drawing-DWZIXIeR.d.cts → drawing-CdTgixMY.d.cts} +14 -2
- package/dist/{drawing-DWZIXIeR.d.ts → drawing-CdTgixMY.d.ts} +14 -2
- package/dist/{effect-CcGdU41j.d.cts → effect-Bu3MHHeg.d.ts} +4 -2
- package/dist/{effect-CZUckY0l.d.ts → effect-D4vmdYP4.d.cts} +4 -2
- package/dist/expressive-charts.css +6 -1
- package/dist/expressive-charts.css.d.cts +2 -0
- package/dist/expressive-charts.css.d.ts +2 -0
- package/dist/expressive-charts.global.js +51 -46
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.cjs +5 -1
- package/dist/icons/sport.cjs.map +1 -1
- package/dist/icons/sport.js +2 -2
- package/dist/index.cjs +839 -358
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -15
- package/dist/index.d.ts +43 -15
- package/dist/index.js +700 -282
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +71 -37
- 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 +6 -8
- package/dist/testing.js.map +1 -1
- package/package.json +16 -4
- package/dist/chunk-CVXP2L2J.js.map +0 -1
- package/dist/chunk-N5IF2RO2.js.map +0 -1
- package/dist/chunk-V5IUTXRW.js.map +0 -1
package/dist/testing.cjs
CHANGED
|
@@ -680,7 +680,8 @@ function pathData(segments, closed = false) {
|
|
|
680
680
|
|
|
681
681
|
// src/core/geometry/walk.ts
|
|
682
682
|
var clamp01 = (t) => t > 0 ? t < 1 ? t : 1 : 0;
|
|
683
|
-
|
|
683
|
+
var NONE = Object.freeze([]);
|
|
684
|
+
function createWalk(segments, gaps = NONE) {
|
|
684
685
|
const first = segments[0];
|
|
685
686
|
const last = segments[segments.length - 1];
|
|
686
687
|
if (!first || !last) throw new RangeError("A walk needs at least one segment.");
|
|
@@ -712,40 +713,54 @@ function createWalk(segments) {
|
|
|
712
713
|
const { index, u } = locate(at * length);
|
|
713
714
|
return pointOn(segments[index], u);
|
|
714
715
|
};
|
|
716
|
+
const draw = (from, to) => {
|
|
717
|
+
let d = moveTo(point(from));
|
|
718
|
+
const a = from * length;
|
|
719
|
+
const b = to * length;
|
|
720
|
+
if (!(b > a)) return d;
|
|
721
|
+
const first2 = locate(a);
|
|
722
|
+
for (let i = first2.index; i < segments.length && cumulative[i] < b; i++) {
|
|
723
|
+
const segment = segments[i];
|
|
724
|
+
if (!(segment.length > 0)) continue;
|
|
725
|
+
const u0 = i === first2.index ? first2.u : 0;
|
|
726
|
+
const u1 = cumulative[i + 1] > b ? Math.min(1, (b - cumulative[i]) / segment.length) : 1;
|
|
727
|
+
if (u1 > u0) d += drawTo(segment, u0, u1);
|
|
728
|
+
}
|
|
729
|
+
return d;
|
|
730
|
+
};
|
|
731
|
+
const slice = (t0, t1) => {
|
|
732
|
+
const from = clamp01(Math.min(t0, t1));
|
|
733
|
+
const to = clamp01(Math.max(t0, t1));
|
|
734
|
+
if (gaps.length === 0) return draw(from, to);
|
|
735
|
+
let d = "";
|
|
736
|
+
let at = from;
|
|
737
|
+
for (const [a, b] of gaps) {
|
|
738
|
+
if (a >= to) break;
|
|
739
|
+
if (a > at) d += draw(at, a);
|
|
740
|
+
if (b > at) at = b;
|
|
741
|
+
}
|
|
742
|
+
if (to > at) d += draw(at, to);
|
|
743
|
+
return d === "" ? moveTo(point(from)) : d;
|
|
744
|
+
};
|
|
715
745
|
return {
|
|
716
746
|
segments,
|
|
717
747
|
length,
|
|
718
748
|
start,
|
|
719
749
|
end,
|
|
750
|
+
gaps,
|
|
720
751
|
point,
|
|
721
752
|
angle(t) {
|
|
722
753
|
const { index, u } = locate(clamp01(t) * length);
|
|
723
754
|
return angleOn(segments[index], u);
|
|
724
755
|
},
|
|
725
|
-
slice
|
|
726
|
-
|
|
727
|
-
const to = clamp01(Math.max(t0, t1));
|
|
728
|
-
let d = moveTo(point(from));
|
|
729
|
-
const a = from * length;
|
|
730
|
-
const b = to * length;
|
|
731
|
-
if (!(b > a)) return d;
|
|
732
|
-
const first2 = locate(a);
|
|
733
|
-
for (let i = first2.index; i < segments.length && cumulative[i] < b; i++) {
|
|
734
|
-
const segment = segments[i];
|
|
735
|
-
if (!(segment.length > 0)) continue;
|
|
736
|
-
const u0 = i === first2.index ? first2.u : 0;
|
|
737
|
-
const u1 = cumulative[i + 1] > b ? Math.min(1, (b - cumulative[i]) / segment.length) : 1;
|
|
738
|
-
if (u1 > u0) d += drawTo(segment, u0, u1);
|
|
739
|
-
}
|
|
740
|
-
return d;
|
|
741
|
-
},
|
|
742
|
-
d: pathData(segments)
|
|
756
|
+
slice,
|
|
757
|
+
d: gaps.length === 0 ? pathData(segments) : slice(0, 1)
|
|
743
758
|
};
|
|
744
759
|
}
|
|
745
760
|
|
|
746
761
|
// src/core/geometry/outline.ts
|
|
747
762
|
function closedOutline(sides) {
|
|
748
|
-
const walks = sides.map(createWalk);
|
|
763
|
+
const walks = sides.map((side) => createWalk(side));
|
|
749
764
|
return {
|
|
750
765
|
d: pathData(sides.flat(), true),
|
|
751
766
|
closed: true,
|
|
@@ -791,6 +806,7 @@ function assemble({ key, series, walk, thickness, outline, bounds, center, pivot
|
|
|
791
806
|
path: (t) => walk.point(t),
|
|
792
807
|
angle: (t) => walk.angle(t),
|
|
793
808
|
slice: (t0, t1) => walk.slice(t0, t1),
|
|
809
|
+
...walk.gaps.length === 0 ? {} : { gaps: walk.gaps },
|
|
794
810
|
thickness,
|
|
795
811
|
outline,
|
|
796
812
|
bounds,
|
|
@@ -946,12 +962,13 @@ function describeLine(spec) {
|
|
|
946
962
|
finite("line", `points[${i}].x`, p.x);
|
|
947
963
|
finite("line", `points[${i}].y`, p.y);
|
|
948
964
|
});
|
|
965
|
+
const breaks = checkBreaks(spec.breaks, points.length);
|
|
949
966
|
const segments = [];
|
|
950
967
|
for (let i = 1; i < points.length; i++) {
|
|
951
968
|
segments.push(line(points[i - 1], points[i], segments[segments.length - 1]?.angle ?? 0));
|
|
952
969
|
}
|
|
953
970
|
if (segments.length === 0) segments.push(line(first, first));
|
|
954
|
-
const walk = createWalk(segments);
|
|
971
|
+
const walk = createWalk(segments, gapsAt(breaks, segments));
|
|
955
972
|
const box = boundsOf(points);
|
|
956
973
|
const pad = width / 2;
|
|
957
974
|
return assemble({
|
|
@@ -966,6 +983,25 @@ function describeLine(spec) {
|
|
|
966
983
|
labelBounds: labelBoxes("line", spec.labelBounds)
|
|
967
984
|
});
|
|
968
985
|
}
|
|
986
|
+
function gapsAt(breaks, segments) {
|
|
987
|
+
const along = [0];
|
|
988
|
+
for (const segment of segments) along.push(along[along.length - 1] + segment.length);
|
|
989
|
+
const length = along[along.length - 1];
|
|
990
|
+
return breaks.filter((i) => along[i] > along[i - 1]).map((i) => [along[i - 1] / length, along[i] / length]);
|
|
991
|
+
}
|
|
992
|
+
function checkBreaks(breaks, count) {
|
|
993
|
+
if (breaks === void 0) return [];
|
|
994
|
+
if (!Array.isArray(breaks)) throw new RangeError(`describe.line: breaks must be an array of point indices, got ${show(breaks)}.`);
|
|
995
|
+
let after = 0;
|
|
996
|
+
breaks.forEach((index, i) => {
|
|
997
|
+
if (!(Number.isInteger(index) && index > after && index < count)) {
|
|
998
|
+
throw new RangeError(`describe.line: breaks[${i}] must be a whole number more than ${after} and less than ${count}, the number of points, got ${show(index)}.`);
|
|
999
|
+
}
|
|
1000
|
+
after = index;
|
|
1001
|
+
});
|
|
1002
|
+
return breaks;
|
|
1003
|
+
}
|
|
1004
|
+
var show = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
969
1005
|
|
|
970
1006
|
// src/core/geometry/describe/point.ts
|
|
971
1007
|
function describePoint(spec) {
|
|
@@ -1013,6 +1049,7 @@ function makeFixtures(moved) {
|
|
|
1013
1049
|
const y = moved ? 30 : 0;
|
|
1014
1050
|
const bar = (width, more = {}) => describe.bar({ key: "Okafor", series: "goals", x: 0, y, width, height: 20, baseline: "left", ...more });
|
|
1015
1051
|
const [goals, assists] = moved ? [120, 82] : [160, 62];
|
|
1052
|
+
const points = moved ? [{ x: 0, y: 90 }, { x: 64, y: 58 }, { x: 128, y: 82 }, { x: 192, y: 26 }, { x: 256, y: 40 }] : [{ x: 0, y: 100 }, { x: 80, y: 60 }, { x: 160, y: 90 }, { x: 240, y: 20 }];
|
|
1016
1053
|
return Object.freeze({
|
|
1017
1054
|
bar: bar(moved ? 160 : 200, { radius: 4 }),
|
|
1018
1055
|
"negative bar": describe.bar({ key: "n", series: "goals", x: moved ? 30 : 0, y, width: moved ? 90 : 120, height: 20, baseline: "right" }),
|
|
@@ -1020,12 +1057,9 @@ function makeFixtures(moved) {
|
|
|
1020
1057
|
stacked: bar(goals + assists, { series: void 0, gap: 2, segments: [{ series: "goals", size: goals }, { series: "assists", size: assists }] }),
|
|
1021
1058
|
"short bar": bar(moved ? 4 : 6),
|
|
1022
1059
|
slice: moved ? describe.arc({ key: "Saved", cx: 140, cy: 130, inner: 60, outer: 100, start: 0.5, end: 2 }) : describe.arc({ key: "Saved", cx: 150, cy: 150, inner: 70, outer: 116, start: 0.3, end: 2.4 }),
|
|
1023
|
-
line: describe.line({
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
points: moved ? [{ x: 0, y: 90 }, { x: 64, y: 58 }, { x: 128, y: 82 }, { x: 192, y: 26 }, { x: 256, y: 40 }] : [{ x: 0, y: 100 }, { x: 80, y: 60 }, { x: 160, y: 90 }, { x: 240, y: 20 }],
|
|
1027
|
-
width: 2
|
|
1028
|
-
}),
|
|
1060
|
+
line: describe.line({ key: "goals", series: "goals", points, width: 2 }),
|
|
1061
|
+
// The line broken after its second point: a run, a gap, and a run.
|
|
1062
|
+
"gapped line": describe.line({ key: "goals", series: "goals", points, breaks: [2], width: 2 }),
|
|
1029
1063
|
point: describe.point({ key: "p", x: moved ? 40 : 10, y: moved ? 25 : 10, r: 3 })
|
|
1030
1064
|
});
|
|
1031
1065
|
}
|
|
@@ -1136,27 +1170,27 @@ async function retraces(effect, a, b, icons) {
|
|
|
1136
1170
|
const back = await opening(effect, b, a, 1 - p, icons);
|
|
1137
1171
|
if (same(back, forward)) continue;
|
|
1138
1172
|
const index = back.findIndex((item, i) => !same(item, forward[i]));
|
|
1139
|
-
const what = back.length !== forward.length ? `${back.length} ${back.length === 1 ? "item" : "items"} (${
|
|
1173
|
+
const what = back.length !== forward.length ? `${back.length} ${back.length === 1 ? "item" : "items"} (${show2(back)}) where the run from a to b from start: ${p} begins with ${forward.length} (${show2(forward)})` : `item ${index + 1} unlike the run from a to b from start: ${p}: ${difference(back[index], forward[index])}`;
|
|
1140
1174
|
return `the run from b to a from start: ${1 - p} begins with ${what}`;
|
|
1141
1175
|
}
|
|
1142
1176
|
return void 0;
|
|
1143
1177
|
}
|
|
1144
1178
|
function difference(actual, expected) {
|
|
1145
|
-
if (typeof actual !== "object" || typeof expected !== "object" || actual === null || expected === null) return `${
|
|
1179
|
+
if (typeof actual !== "object" || typeof expected !== "object" || actual === null || expected === null) return `${show2(actual)}, not ${show2(expected)}`;
|
|
1146
1180
|
const a = actual;
|
|
1147
1181
|
const b = expected;
|
|
1148
1182
|
for (const field of /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
1149
1183
|
const x = a[field];
|
|
1150
1184
|
const y = b[field];
|
|
1151
1185
|
if (same(x, y)) continue;
|
|
1152
|
-
if (typeof x !== "string" || typeof y !== "string") return `its ${field} is ${
|
|
1186
|
+
if (typeof x !== "string" || typeof y !== "string") return `its ${field} is ${show2(x)}, not ${show2(y)}`;
|
|
1153
1187
|
let at = 0;
|
|
1154
1188
|
while (at < x.length && x[at] === y[at]) at++;
|
|
1155
1189
|
const from = Math.max(0, at - 24);
|
|
1156
1190
|
const part = (text) => `${from > 0 ? "\u2026" : ""}${text.slice(from, at + 24)}${at + 24 < text.length ? "\u2026" : ""}`;
|
|
1157
1191
|
return `its ${field} parts at character ${at + 1}: ${JSON.stringify(part(x))}, not ${JSON.stringify(part(y))}`;
|
|
1158
1192
|
}
|
|
1159
|
-
return `${
|
|
1193
|
+
return `${show2(actual)}, not ${show2(expected)}`;
|
|
1160
1194
|
}
|
|
1161
1195
|
function namedPairs(pairs) {
|
|
1162
1196
|
if (!Array.isArray(pairs)) return Object.entries(pairs).map(([name, pair]) => [`the ${name}`, pair]);
|
|
@@ -1335,18 +1369,18 @@ function compare(actual, expected, when) {
|
|
|
1335
1369
|
if (!same(drawn, wanted)) {
|
|
1336
1370
|
const index = drawn.findIndex((item, i) => !same(item, wanted[i]));
|
|
1337
1371
|
problems2.push(
|
|
1338
|
-
drawn.length !== wanted.length ? `${drawn.length} ${drawn.length === 1 ? "item is" : "items are"} drawn ${when} but end() draws ${wanted.length} (${
|
|
1372
|
+
drawn.length !== wanted.length ? `${drawn.length} ${drawn.length === 1 ? "item is" : "items are"} drawn ${when} but end() draws ${wanted.length} (${show2(drawn)} vs ${show2(wanted)})` : `item ${index + 1} drawn ${when} is ${show2(drawn[index])} but end() draws ${show2(wanted[index])}`
|
|
1339
1373
|
);
|
|
1340
1374
|
}
|
|
1341
1375
|
const style = rounded(actual.mark.style);
|
|
1342
1376
|
const wantedStyle = rounded(expected.mark.style);
|
|
1343
|
-
if (!same(style, wantedStyle)) problems2.push(`the mark's style ${when} is ${
|
|
1377
|
+
if (!same(style, wantedStyle)) problems2.push(`the mark's style ${when} is ${show2(style)} but end() leaves ${show2(wantedStyle)}`);
|
|
1344
1378
|
return problems2.length > 0 ? problems2.join("; ") : void 0;
|
|
1345
1379
|
}
|
|
1346
1380
|
function leftovers(ctx) {
|
|
1347
1381
|
const problems2 = [];
|
|
1348
|
-
if (ctx.layer.drawn.length > 0) problems2.push(`${
|
|
1349
|
-
if (Object.keys(ctx.mark.style).length > 0) problems2.push(`the mark's style is still ${
|
|
1382
|
+
if (ctx.layer.drawn.length > 0) problems2.push(`${show2(ctx.layer.picture())} is still drawn`);
|
|
1383
|
+
if (Object.keys(ctx.mark.style).length > 0) problems2.push(`the mark's style is still ${show2(ctx.mark.style)}`);
|
|
1350
1384
|
if (!ctx.clock.idle) problems2.push("animation frames are still running");
|
|
1351
1385
|
return problems2.length > 0 ? problems2.join("; ") : void 0;
|
|
1352
1386
|
}
|
|
@@ -1368,12 +1402,12 @@ function rounded(value) {
|
|
|
1368
1402
|
return value;
|
|
1369
1403
|
}
|
|
1370
1404
|
var LONGEST = 240;
|
|
1371
|
-
function
|
|
1405
|
+
function show2(value) {
|
|
1372
1406
|
const text = JSON.stringify(value) ?? String(value);
|
|
1373
1407
|
return text.length > LONGEST ? `${text.slice(0, LONGEST - 1)}\u2026` : text;
|
|
1374
1408
|
}
|
|
1375
1409
|
function describeError(error) {
|
|
1376
|
-
return error instanceof Error ? `${error.name}: ${error.message}` :
|
|
1410
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : show2(error);
|
|
1377
1411
|
}
|
|
1378
1412
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1379
1413
|
0 && (module.exports = {
|