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/index.cjs
CHANGED
|
@@ -746,7 +746,8 @@ function pathData(segments, closed = false) {
|
|
|
746
746
|
|
|
747
747
|
// src/core/geometry/walk.ts
|
|
748
748
|
var clamp01 = (t) => t > 0 ? t < 1 ? t : 1 : 0;
|
|
749
|
-
|
|
749
|
+
var NONE = Object.freeze([]);
|
|
750
|
+
function createWalk(segments, gaps = NONE) {
|
|
750
751
|
const first = segments[0];
|
|
751
752
|
const last = segments[segments.length - 1];
|
|
752
753
|
if (!first || !last) throw new RangeError("A walk needs at least one segment.");
|
|
@@ -778,40 +779,54 @@ function createWalk(segments) {
|
|
|
778
779
|
const { index, u } = locate(at * length);
|
|
779
780
|
return pointOn(segments[index], u);
|
|
780
781
|
};
|
|
782
|
+
const draw = (from, to) => {
|
|
783
|
+
let d = moveTo(point(from));
|
|
784
|
+
const a = from * length;
|
|
785
|
+
const b = to * length;
|
|
786
|
+
if (!(b > a)) return d;
|
|
787
|
+
const first2 = locate(a);
|
|
788
|
+
for (let i = first2.index; i < segments.length && cumulative[i] < b; i++) {
|
|
789
|
+
const segment = segments[i];
|
|
790
|
+
if (!(segment.length > 0)) continue;
|
|
791
|
+
const u0 = i === first2.index ? first2.u : 0;
|
|
792
|
+
const u1 = cumulative[i + 1] > b ? Math.min(1, (b - cumulative[i]) / segment.length) : 1;
|
|
793
|
+
if (u1 > u0) d += drawTo(segment, u0, u1);
|
|
794
|
+
}
|
|
795
|
+
return d;
|
|
796
|
+
};
|
|
797
|
+
const slice = (t0, t1) => {
|
|
798
|
+
const from = clamp01(Math.min(t0, t1));
|
|
799
|
+
const to = clamp01(Math.max(t0, t1));
|
|
800
|
+
if (gaps.length === 0) return draw(from, to);
|
|
801
|
+
let d = "";
|
|
802
|
+
let at = from;
|
|
803
|
+
for (const [a, b] of gaps) {
|
|
804
|
+
if (a >= to) break;
|
|
805
|
+
if (a > at) d += draw(at, a);
|
|
806
|
+
if (b > at) at = b;
|
|
807
|
+
}
|
|
808
|
+
if (to > at) d += draw(at, to);
|
|
809
|
+
return d === "" ? moveTo(point(from)) : d;
|
|
810
|
+
};
|
|
781
811
|
return {
|
|
782
812
|
segments,
|
|
783
813
|
length,
|
|
784
814
|
start,
|
|
785
815
|
end,
|
|
816
|
+
gaps,
|
|
786
817
|
point,
|
|
787
818
|
angle(t) {
|
|
788
819
|
const { index, u } = locate(clamp01(t) * length);
|
|
789
820
|
return angleOn(segments[index], u);
|
|
790
821
|
},
|
|
791
|
-
slice
|
|
792
|
-
|
|
793
|
-
const to = clamp01(Math.max(t0, t1));
|
|
794
|
-
let d = moveTo(point(from));
|
|
795
|
-
const a = from * length;
|
|
796
|
-
const b = to * length;
|
|
797
|
-
if (!(b > a)) return d;
|
|
798
|
-
const first2 = locate(a);
|
|
799
|
-
for (let i = first2.index; i < segments.length && cumulative[i] < b; i++) {
|
|
800
|
-
const segment = segments[i];
|
|
801
|
-
if (!(segment.length > 0)) continue;
|
|
802
|
-
const u0 = i === first2.index ? first2.u : 0;
|
|
803
|
-
const u1 = cumulative[i + 1] > b ? Math.min(1, (b - cumulative[i]) / segment.length) : 1;
|
|
804
|
-
if (u1 > u0) d += drawTo(segment, u0, u1);
|
|
805
|
-
}
|
|
806
|
-
return d;
|
|
807
|
-
},
|
|
808
|
-
d: pathData(segments)
|
|
822
|
+
slice,
|
|
823
|
+
d: gaps.length === 0 ? pathData(segments) : slice(0, 1)
|
|
809
824
|
};
|
|
810
825
|
}
|
|
811
826
|
|
|
812
827
|
// src/core/geometry/outline.ts
|
|
813
828
|
function closedOutline(sides) {
|
|
814
|
-
const walks = sides.map(createWalk);
|
|
829
|
+
const walks = sides.map((side) => createWalk(side));
|
|
815
830
|
return {
|
|
816
831
|
d: pathData(sides.flat(), true),
|
|
817
832
|
closed: true,
|
|
@@ -857,6 +872,7 @@ function assemble({ key, series, walk, thickness, outline: outline2, bounds, cen
|
|
|
857
872
|
path: (t) => walk.point(t),
|
|
858
873
|
angle: (t) => walk.angle(t),
|
|
859
874
|
slice: (t0, t1) => walk.slice(t0, t1),
|
|
875
|
+
...walk.gaps.length === 0 ? {} : { gaps: walk.gaps },
|
|
860
876
|
thickness,
|
|
861
877
|
outline: outline2,
|
|
862
878
|
bounds,
|
|
@@ -1012,12 +1028,13 @@ function describeLine(spec) {
|
|
|
1012
1028
|
finite("line", `points[${i}].x`, p.x);
|
|
1013
1029
|
finite("line", `points[${i}].y`, p.y);
|
|
1014
1030
|
});
|
|
1031
|
+
const breaks = checkBreaks(spec.breaks, points.length);
|
|
1015
1032
|
const segments = [];
|
|
1016
1033
|
for (let i = 1; i < points.length; i++) {
|
|
1017
1034
|
segments.push(line(points[i - 1], points[i], segments[segments.length - 1]?.angle ?? 0));
|
|
1018
1035
|
}
|
|
1019
1036
|
if (segments.length === 0) segments.push(line(first, first));
|
|
1020
|
-
const walk = createWalk(segments);
|
|
1037
|
+
const walk = createWalk(segments, gapsAt(breaks, segments));
|
|
1021
1038
|
const box = boundsOf(points);
|
|
1022
1039
|
const pad = width / 2;
|
|
1023
1040
|
return assemble({
|
|
@@ -1032,6 +1049,25 @@ function describeLine(spec) {
|
|
|
1032
1049
|
labelBounds: labelBoxes("line", spec.labelBounds)
|
|
1033
1050
|
});
|
|
1034
1051
|
}
|
|
1052
|
+
function gapsAt(breaks, segments) {
|
|
1053
|
+
const along = [0];
|
|
1054
|
+
for (const segment of segments) along.push(along[along.length - 1] + segment.length);
|
|
1055
|
+
const length = along[along.length - 1];
|
|
1056
|
+
return breaks.filter((i) => along[i] > along[i - 1]).map((i) => [along[i - 1] / length, along[i] / length]);
|
|
1057
|
+
}
|
|
1058
|
+
function checkBreaks(breaks, count) {
|
|
1059
|
+
if (breaks === void 0) return [];
|
|
1060
|
+
if (!Array.isArray(breaks)) throw new RangeError(`describe.line: breaks must be an array of point indices, got ${show(breaks)}.`);
|
|
1061
|
+
let after = 0;
|
|
1062
|
+
breaks.forEach((index, i) => {
|
|
1063
|
+
if (!(Number.isInteger(index) && index > after && index < count)) {
|
|
1064
|
+
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)}.`);
|
|
1065
|
+
}
|
|
1066
|
+
after = index;
|
|
1067
|
+
});
|
|
1068
|
+
return breaks;
|
|
1069
|
+
}
|
|
1070
|
+
var show = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
1035
1071
|
|
|
1036
1072
|
// src/core/geometry/describe/point.ts
|
|
1037
1073
|
function describePoint(spec) {
|
|
@@ -1111,7 +1147,7 @@ function invert(m) {
|
|
|
1111
1147
|
return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];
|
|
1112
1148
|
}
|
|
1113
1149
|
function parseTransform(source) {
|
|
1114
|
-
const
|
|
1150
|
+
const parts2 = [];
|
|
1115
1151
|
for (const [, name, rawArgs = ""] of source.matchAll(/(matrix|translate|scale|rotate|skewX|skewY)\s*\(([^)]*)\)/g)) {
|
|
1116
1152
|
const args = rawArgs.trim().split(/[\s,]+/).filter(Boolean).map(Number);
|
|
1117
1153
|
if (!args.every(Number.isFinite)) continue;
|
|
@@ -1119,26 +1155,26 @@ function parseTransform(source) {
|
|
|
1119
1155
|
const radians = (degrees) => degrees * Math.PI / 180;
|
|
1120
1156
|
switch (name) {
|
|
1121
1157
|
case "matrix":
|
|
1122
|
-
if (args.length === 6)
|
|
1158
|
+
if (args.length === 6) parts2.push([a, b, c, d, e, f]);
|
|
1123
1159
|
break;
|
|
1124
1160
|
case "translate":
|
|
1125
|
-
|
|
1161
|
+
parts2.push(translate(a, b ?? 0));
|
|
1126
1162
|
break;
|
|
1127
1163
|
case "scale":
|
|
1128
|
-
|
|
1164
|
+
parts2.push(scale(a, b ?? a));
|
|
1129
1165
|
break;
|
|
1130
1166
|
case "rotate":
|
|
1131
|
-
|
|
1167
|
+
parts2.push(rotate(radians(a), b !== void 0 && c !== void 0 ? { x: b, y: c } : void 0));
|
|
1132
1168
|
break;
|
|
1133
1169
|
case "skewX":
|
|
1134
|
-
|
|
1170
|
+
parts2.push([1, 0, Math.tan(radians(a)), 1, 0, 0]);
|
|
1135
1171
|
break;
|
|
1136
1172
|
case "skewY":
|
|
1137
|
-
|
|
1173
|
+
parts2.push([1, Math.tan(radians(a)), 0, 1, 0, 0]);
|
|
1138
1174
|
break;
|
|
1139
1175
|
}
|
|
1140
1176
|
}
|
|
1141
|
-
return multiply(...
|
|
1177
|
+
return multiply(...parts2);
|
|
1142
1178
|
}
|
|
1143
1179
|
function offset(point, angle, distance3) {
|
|
1144
1180
|
return { x: point.x + distance3 * Math.cos(angle), y: point.y + distance3 * Math.sin(angle) };
|
|
@@ -1161,7 +1197,18 @@ function samplesAlong(mark, points) {
|
|
|
1161
1197
|
});
|
|
1162
1198
|
const n = mark.length > 0 ? Math.min(MAX_GRID, Math.ceil(mark.length) + 1) : 1;
|
|
1163
1199
|
const grid = Array.from({ length: n }, (_, i) => mark.path(n === 1 ? 0 : i / (n - 1)));
|
|
1164
|
-
|
|
1200
|
+
const samples = points.map((p, index) => ({ index, sample: { t: nearest(mark, grid, p), value: p.value, ...p.at === void 0 ? {} : { at: p.at } } })).sort((a, b) => a.sample.t - b.sample.t || a.index - b.index).map(({ sample }) => sample);
|
|
1201
|
+
return mark.gaps && mark.gaps.length > 0 ? gapped(samples, mark.gaps) : samples;
|
|
1202
|
+
}
|
|
1203
|
+
function gapped(samples, gaps) {
|
|
1204
|
+
const middles = gaps.map(([from, to]) => (from + to) / 2).sort((a, b) => a - b);
|
|
1205
|
+
let next = 0;
|
|
1206
|
+
return samples.map((sample, k) => {
|
|
1207
|
+
if (k === 0) return sample;
|
|
1208
|
+
const before = samples[k - 1].t;
|
|
1209
|
+
while (next < middles.length && middles[next] <= before) next++;
|
|
1210
|
+
return next < middles.length && middles[next] <= sample.t ? { ...sample, gapBefore: true } : sample;
|
|
1211
|
+
});
|
|
1165
1212
|
}
|
|
1166
1213
|
function nearest(mark, grid, p) {
|
|
1167
1214
|
const n = grid.length;
|
|
@@ -1342,7 +1389,7 @@ function createRunner(options) {
|
|
|
1342
1389
|
entry.data = input.data;
|
|
1343
1390
|
return entry;
|
|
1344
1391
|
}
|
|
1345
|
-
const created = { key, mark: input.mark, data: input.data, runs: /* @__PURE__ */ new Map(), applied: {}, handle: void 0, exiting: void 0 };
|
|
1392
|
+
const created = { key, mark: input.mark, data: input.data, resting: input.data, runs: /* @__PURE__ */ new Map(), applied: {}, handle: void 0, exiting: void 0 };
|
|
1346
1393
|
entries.set(key, created);
|
|
1347
1394
|
return created;
|
|
1348
1395
|
}
|
|
@@ -1433,9 +1480,9 @@ function createRunner(options) {
|
|
|
1433
1480
|
path: (d, paint) => target()?.path(d, paint) ?? INERT,
|
|
1434
1481
|
text: (content, style) => target()?.text(content, style) ?? INERT,
|
|
1435
1482
|
clear() {
|
|
1436
|
-
const
|
|
1483
|
+
const drawn2 = group;
|
|
1437
1484
|
group = void 0;
|
|
1438
|
-
|
|
1485
|
+
drawn2?.clear();
|
|
1439
1486
|
}
|
|
1440
1487
|
};
|
|
1441
1488
|
}
|
|
@@ -1522,6 +1569,7 @@ function createRunner(options) {
|
|
|
1522
1569
|
if (destroyed) return;
|
|
1523
1570
|
marks.forEach((input, index) => {
|
|
1524
1571
|
const entry = track(input);
|
|
1572
|
+
entry.resting = input.data;
|
|
1525
1573
|
cancelExit(entry);
|
|
1526
1574
|
const batch = { index, count: marks.length };
|
|
1527
1575
|
start(entry, "decorate", input.data, batch);
|
|
@@ -1530,11 +1578,18 @@ function createRunner(options) {
|
|
|
1530
1578
|
},
|
|
1531
1579
|
update(marks) {
|
|
1532
1580
|
if (destroyed) return;
|
|
1581
|
+
const changing = new Set(marks.map((input) => input.mark.key));
|
|
1582
|
+
for (const entry of [...entries.values()]) {
|
|
1583
|
+
const run = entry.runs.get("update");
|
|
1584
|
+
if (run && !changing.has(entry.key)) clearRun(run);
|
|
1585
|
+
}
|
|
1533
1586
|
marks.forEach((input, index) => {
|
|
1534
1587
|
const known = entries.get(input.mark.key);
|
|
1535
1588
|
const previous = input.from ?? known?.mark;
|
|
1536
|
-
const data = known && !input.data.previous ? withPrevious(input.data, known.
|
|
1537
|
-
|
|
1589
|
+
const data = known && !input.data.previous ? withPrevious(input.data, known.resting) : input.data;
|
|
1590
|
+
const entry = track(input);
|
|
1591
|
+
entry.resting = input.data;
|
|
1592
|
+
start(entry, "update", data, { index, count: marks.length }, { previous });
|
|
1538
1593
|
});
|
|
1539
1594
|
},
|
|
1540
1595
|
exit(marks) {
|
|
@@ -1579,7 +1634,10 @@ function createRunner(options) {
|
|
|
1579
1634
|
const entry = entries.get(mark.key);
|
|
1580
1635
|
if (!entry) return;
|
|
1581
1636
|
entry.mark = mark;
|
|
1582
|
-
if (data)
|
|
1637
|
+
if (data) {
|
|
1638
|
+
entry.data = data;
|
|
1639
|
+
if (!transitioning) entry.resting = data;
|
|
1640
|
+
}
|
|
1583
1641
|
for (const run of [...entry.runs.values()]) {
|
|
1584
1642
|
if (run.state === "cleared") continue;
|
|
1585
1643
|
try {
|
|
@@ -1601,6 +1659,7 @@ function createRunner(options) {
|
|
|
1601
1659
|
settle() {
|
|
1602
1660
|
if (!transitioning) return;
|
|
1603
1661
|
transitioning = false;
|
|
1662
|
+
for (const entry of entries.values()) if (!entry.exiting) entry.resting = entry.data;
|
|
1604
1663
|
const keys = [...hovered];
|
|
1605
1664
|
keys.forEach((key, index) => {
|
|
1606
1665
|
const entry = entries.get(key);
|
|
@@ -1662,16 +1721,16 @@ var SORTED = {
|
|
|
1662
1721
|
};
|
|
1663
1722
|
var NAMED = 3;
|
|
1664
1723
|
function changeText(facts) {
|
|
1665
|
-
const
|
|
1724
|
+
const parts2 = [];
|
|
1666
1725
|
const { series } = facts;
|
|
1667
|
-
if (facts.label !== void 0)
|
|
1668
|
-
else if (series && !(series.length === 1 && series[0] === "value"))
|
|
1669
|
-
if (facts.sort)
|
|
1726
|
+
if (facts.label !== void 0) parts2.push(facts.label);
|
|
1727
|
+
else if (series && !(series.length === 1 && series[0] === "value")) parts2.push(`Showing ${list(series)}`);
|
|
1728
|
+
if (facts.sort) parts2.push(SORTED[facts.sort]);
|
|
1670
1729
|
const { changed, added, removed } = facts;
|
|
1671
|
-
if (!series && changed.length > 0)
|
|
1672
|
-
if (added.length > 0)
|
|
1673
|
-
if (removed.length > 0)
|
|
1674
|
-
return
|
|
1730
|
+
if (!series && changed.length > 0) parts2.push(changed.length <= NAMED ? `${list(changed)} changed` : `${changed.length} of ${facts.count} changed`);
|
|
1731
|
+
if (added.length > 0) parts2.push(`Added ${added.length <= NAMED ? list(added) : added.length}`);
|
|
1732
|
+
if (removed.length > 0) parts2.push(`Removed ${removed.length <= NAMED ? list(removed) : removed.length}`);
|
|
1733
|
+
return parts2.join(". ");
|
|
1675
1734
|
}
|
|
1676
1735
|
function list(names) {
|
|
1677
1736
|
if (names.length <= 1) return names.join("");
|
|
@@ -1780,6 +1839,7 @@ var TICK_SIZE = 11;
|
|
|
1780
1839
|
var AXIS = 26;
|
|
1781
1840
|
var TOP = 4;
|
|
1782
1841
|
var PAD = 6;
|
|
1842
|
+
var BOTH = { label: true, value: true };
|
|
1783
1843
|
var CENTRE = 0.36;
|
|
1784
1844
|
function barEncoding(options) {
|
|
1785
1845
|
const { x, y, stack, data } = options;
|
|
@@ -1829,13 +1889,62 @@ function layoutBars(input) {
|
|
|
1829
1889
|
const texts = rows2.map((row) => input.format(row.total));
|
|
1830
1890
|
const ticks = domain.ticks.map(input.format);
|
|
1831
1891
|
const frame2 = (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows2, domain, texts, ticks);
|
|
1892
|
+
const labels = thinLabels(frame2, rows2, texts, input.measure);
|
|
1832
1893
|
return {
|
|
1833
1894
|
width: frame2.bands.width,
|
|
1834
1895
|
height: frame2.bands.height,
|
|
1835
1896
|
orientation: frame2.orientation,
|
|
1836
1897
|
frame: frame2,
|
|
1837
|
-
rows: rows2.map((row, slot) => placeRow(frame2, { ...row, slot, text: texts[slot] }, input.measure)),
|
|
1838
|
-
ticks: domain.ticks.map((value, i) => placeTick(frame2, value, ticks[i]))
|
|
1898
|
+
rows: rows2.map((row, slot) => placeRow(frame2, { ...row, slot, text: texts[slot], drawn: { label: slot % labels.every === 0, value: labels.values } }, input.measure)),
|
|
1899
|
+
ticks: domain.ticks.map((value, i) => placeTick(frame2, value, ticks[i])),
|
|
1900
|
+
labels
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
function thinLabels(frame2, rows2, texts, measure) {
|
|
1904
|
+
const placed2 = rows2.map((row, slot) => placeLabels(frame2, slot, row.total, row.category, texts[slot]));
|
|
1905
|
+
const horizontal = frame2.orientation === "horizontal";
|
|
1906
|
+
const values = !overlaps(boxesOf(placed2.map(({ value }) => value), measure, "ec-value", VALUE_SIZE), horizontal);
|
|
1907
|
+
const categories = (every) => boxesOf(
|
|
1908
|
+
placed2.filter((_, slot) => slot % every === 0).map(({ label: label2 }) => label2),
|
|
1909
|
+
measure,
|
|
1910
|
+
"ec-label",
|
|
1911
|
+
LABEL_SIZE
|
|
1912
|
+
);
|
|
1913
|
+
let k = 0;
|
|
1914
|
+
while (thinStep(k) < rows2.length && overlaps(categories(thinStep(k)), horizontal)) k++;
|
|
1915
|
+
return { every: thinStep(k), values };
|
|
1916
|
+
}
|
|
1917
|
+
var thinStep = (k) => [1, 2, 5][k % 3] * 10 ** Math.floor(k / 3);
|
|
1918
|
+
function boxesOf(labels, measure, className, size2) {
|
|
1919
|
+
return labels.filter((label2) => label2.text !== "").map((label2) => textBox(label2, measure, className, size2));
|
|
1920
|
+
}
|
|
1921
|
+
function overlaps(boxes, horizontal) {
|
|
1922
|
+
const along = horizontal ? boxes.map(({ x, y, width, height }) => ({ x: y, y: x, width: height, height: width })) : [...boxes];
|
|
1923
|
+
along.sort((a, b) => a.x - b.x);
|
|
1924
|
+
const open = [];
|
|
1925
|
+
for (const box of along) {
|
|
1926
|
+
for (let i = open.length - 1; i >= 0; i--) if (open[i].x + open[i].width <= box.x) open.splice(i, 1);
|
|
1927
|
+
if (open.some((other) => other.y < box.y + box.height && box.y < other.y + other.height)) return true;
|
|
1928
|
+
open.push(box);
|
|
1929
|
+
}
|
|
1930
|
+
return false;
|
|
1931
|
+
}
|
|
1932
|
+
function placeLabels(frame2, slot, total2, category, text2) {
|
|
1933
|
+
const { scale: scale2, bands } = frame2;
|
|
1934
|
+
const negative = total2 < 0;
|
|
1935
|
+
const tip = position(scale2)(total2);
|
|
1936
|
+
const band = bands.start + slot * bands.band;
|
|
1937
|
+
if (frame2.orientation === "horizontal") {
|
|
1938
|
+
const line2 = band + bands.band / 2 + LABEL_SIZE * CENTRE;
|
|
1939
|
+
return {
|
|
1940
|
+
label: { x: scale2.label, y: line2, anchor: "end", text: category },
|
|
1941
|
+
value: { x: negative ? tip - PAD : tip + PAD, y: line2, anchor: negative ? "end" : "start", text: text2 }
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
const centre = band + bands.band / 2;
|
|
1945
|
+
return {
|
|
1946
|
+
label: { x: centre, y: scale2.label, anchor: "middle", text: category },
|
|
1947
|
+
value: { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: text2 }
|
|
1839
1948
|
};
|
|
1840
1949
|
}
|
|
1841
1950
|
function placeRow(frame2, row, measure) {
|
|
@@ -1854,17 +1963,11 @@ function placeRow(frame2, row, measure) {
|
|
|
1854
1963
|
gap: GAP,
|
|
1855
1964
|
segments: row.values.map((v) => ({ series: v.series, size: Math.max(0, negative ? -v.value : v.value) * unit }))
|
|
1856
1965
|
};
|
|
1857
|
-
const
|
|
1858
|
-
const
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
if (value2.text !== "") out.push(textBox(value2, measure, "ec-value", VALUE_SIZE));
|
|
1862
|
-
return out;
|
|
1863
|
-
};
|
|
1966
|
+
const drawn2 = row.drawn ?? BOTH;
|
|
1967
|
+
const fields = { key: row.key, datum: row.datum, index: row.index, slot: row.slot, values: row.values, total: total2, category: row.category, drawn: drawn2 };
|
|
1968
|
+
const { label: label2, value } = placeLabels(frame2, row.slot, total2, drawn2.label ? row.category : "", drawn2.value ? row.text : "");
|
|
1969
|
+
const boxes = () => [...boxesOf([label2], measure, "ec-label", LABEL_SIZE), ...boxesOf([value], measure, "ec-value", VALUE_SIZE)];
|
|
1864
1970
|
if (frame2.orientation === "horizontal") {
|
|
1865
|
-
const line2 = band + bands.band / 2 + LABEL_SIZE * CENTRE;
|
|
1866
|
-
const label3 = { x: scale2.label, y: line2, anchor: "end", text: row.category };
|
|
1867
|
-
const value2 = { x: negative ? tip - PAD : tip + PAD, y: line2, anchor: negative ? "end" : "start", text: row.text };
|
|
1868
1971
|
const geometry2 = describe.bar({
|
|
1869
1972
|
...bar,
|
|
1870
1973
|
x: Math.min(zero, tip),
|
|
@@ -1872,20 +1975,18 @@ function placeRow(frame2, row, measure) {
|
|
|
1872
1975
|
width: Math.abs(tip - zero),
|
|
1873
1976
|
height: bands.thickness,
|
|
1874
1977
|
baseline: negative ? "right" : "left",
|
|
1875
|
-
labelBounds: boxes(
|
|
1978
|
+
labelBounds: boxes()
|
|
1876
1979
|
});
|
|
1877
1980
|
return {
|
|
1878
1981
|
...fields,
|
|
1879
1982
|
geometry: geometry2,
|
|
1880
1983
|
data: barData(row.datum, total2, geometry2),
|
|
1881
|
-
label:
|
|
1882
|
-
value
|
|
1984
|
+
label: label2,
|
|
1985
|
+
value,
|
|
1883
1986
|
hit: { x: 0, y: band, width: bands.width, height: bands.band }
|
|
1884
1987
|
};
|
|
1885
1988
|
}
|
|
1886
1989
|
const centre = band + bands.band / 2;
|
|
1887
|
-
const label2 = { x: centre, y: scale2.label, anchor: "middle", text: row.category };
|
|
1888
|
-
const value = { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: row.text };
|
|
1889
1990
|
const geometry = describe.bar({
|
|
1890
1991
|
...bar,
|
|
1891
1992
|
x: centre - bands.thickness / 2,
|
|
@@ -1893,7 +1994,7 @@ function placeRow(frame2, row, measure) {
|
|
|
1893
1994
|
width: bands.thickness,
|
|
1894
1995
|
height: Math.abs(tip - zero),
|
|
1895
1996
|
baseline: negative ? "top" : "bottom",
|
|
1896
|
-
labelBounds: boxes(
|
|
1997
|
+
labelBounds: boxes()
|
|
1897
1998
|
});
|
|
1898
1999
|
return {
|
|
1899
2000
|
...fields,
|
|
@@ -1953,9 +2054,9 @@ function niceDomain(values) {
|
|
|
1953
2054
|
const ticks = Array.from({ length: count + 1 }, (_, i) => clean(lo + i * step2));
|
|
1954
2055
|
return { lo, hi, ticks };
|
|
1955
2056
|
}
|
|
1956
|
-
function niceStep(
|
|
1957
|
-
const power = 10 ** Math.floor(Math.log10(
|
|
1958
|
-
const f =
|
|
2057
|
+
function niceStep(span2) {
|
|
2058
|
+
const power = 10 ** Math.floor(Math.log10(span2));
|
|
2059
|
+
const f = span2 / power;
|
|
1959
2060
|
return (f <= 1 ? 1 : f <= 2 ? 2 : f <= 5 ? 5 : 10) * power;
|
|
1960
2061
|
}
|
|
1961
2062
|
function horizontalFrame(input, rows2, domain, values, ticks) {
|
|
@@ -1964,9 +2065,10 @@ function horizontalFrame(input, rows2, domain, values, ticks) {
|
|
|
1964
2065
|
const labelWidth = widest(rows2.map((row) => row.category), "ec-label", LABEL_SIZE, measure);
|
|
1965
2066
|
const valueWidth = widest(values, "ec-value", VALUE_SIZE, measure);
|
|
1966
2067
|
const tickWidth = widest(ticks, "ec-tick", TICK_SIZE, measure);
|
|
2068
|
+
const { positive, negative } = reach(input, rows2);
|
|
1967
2069
|
const negativeRoom = domain.lo < 0 ? valueWidth + PAD : 0;
|
|
1968
|
-
const left = Math.max(labelWidth + 10 + negativeRoom, tickWidth / 2 + 2);
|
|
1969
|
-
const right = Math.max(valueWidth + PAD + 4, tickWidth / 2 + 2);
|
|
2070
|
+
const left = Math.max(labelWidth + 10 + negativeRoom + negative, tickWidth / 2 + 2);
|
|
2071
|
+
const right = Math.max(valueWidth + PAD + 4 + positive, tickWidth / 2 + 2);
|
|
1970
2072
|
const rowSize = input.height === void 0 || n === 0 ? ROW : Math.max(0, input.height - TOP - AXIS) / n;
|
|
1971
2073
|
return {
|
|
1972
2074
|
orientation: "horizontal",
|
|
@@ -1979,8 +2081,9 @@ function verticalFrame(input, rows2, domain, _values, ticks) {
|
|
|
1979
2081
|
const n = rows2.length;
|
|
1980
2082
|
const height = input.height ?? VERTICAL_HEIGHT;
|
|
1981
2083
|
const tickWidth = widest(ticks, "ec-tick", TICK_SIZE, measure);
|
|
1982
|
-
const
|
|
1983
|
-
const
|
|
2084
|
+
const { positive, negative } = reach(input, rows2);
|
|
2085
|
+
const top = (domain.hi > 0 ? VALUE_SIZE + PAD + 2 : TOP) + positive;
|
|
2086
|
+
const bottom = AXIS + (domain.lo < 0 ? VALUE_SIZE + PAD : 0) + negative;
|
|
1984
2087
|
const left = tickWidth + 8 + 2;
|
|
1985
2088
|
const plot = { x: left, y: top, width: Math.max(0, width - left - 8), height: Math.max(0, height - top - bottom) };
|
|
1986
2089
|
const band = n > 0 ? plot.width / n : 0;
|
|
@@ -1991,6 +2094,13 @@ function verticalFrame(input, rows2, domain, _values, ticks) {
|
|
|
1991
2094
|
bands: { start: plot.x, band, thickness: Math.min(band * BAR / ROW, MAX_COLUMN), span: plot.width, width, height }
|
|
1992
2095
|
};
|
|
1993
2096
|
}
|
|
2097
|
+
function reach(input, rows2) {
|
|
2098
|
+
const room = input.room ?? 0;
|
|
2099
|
+
return {
|
|
2100
|
+
positive: rows2.some((row) => row.total > 0) ? room : 0,
|
|
2101
|
+
negative: rows2.some((row) => row.total < 0) ? room : 0
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
1994
2104
|
function barData(datum, total2, geometry) {
|
|
1995
2105
|
const valueAt = (distance3) => geometry.length > 0 ? total2 * distance3 / geometry.length : 0;
|
|
1996
2106
|
const data = {
|
|
@@ -2137,6 +2247,7 @@ ${TOKEN_RULES}
|
|
|
2137
2247
|
:where(.ec-chart .ec-tick) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 11px; }
|
|
2138
2248
|
:where(.ec-chart .ec-label) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; }
|
|
2139
2249
|
:where(.ec-chart .ec-value, .ec-chart .ec-text) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; font-weight: 600; }
|
|
2250
|
+
:where(.ec-overlay .ec-text) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
2140
2251
|
:where(.ec-chart .ec-hit) { fill: transparent; }
|
|
2141
2252
|
:where(.ec-chart .ec-mark:focus) { outline: none; }
|
|
2142
2253
|
:where(.ec-chart .ec-focus) { pointer-events: none; }
|
|
@@ -2150,6 +2261,7 @@ ${TOKEN_RULES}
|
|
|
2150
2261
|
:where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
|
|
2151
2262
|
: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; }
|
|
2152
2263
|
:where(.ec-chart .ec-hot .ec-dot) { fill: var(--ec-mark-strong); opacity: 1; }
|
|
2264
|
+
:where(.ec-chart .ec-alone .ec-dot) { opacity: 1; }
|
|
2153
2265
|
:where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
|
|
2154
2266
|
:where(.ec-chart .ec-column:focus) { outline: none; }
|
|
2155
2267
|
:where(.ec-chart .ec-lines, .ec-chart .ec-points) { pointer-events: none; }
|
|
@@ -2184,7 +2296,10 @@ ${TOKEN_RULES}
|
|
|
2184
2296
|
:where(.ec-attached) { transition: opacity var(--ec-hover-duration, 100ms) ease-out, fill var(--ec-hover-duration, 100ms) ease-out, stroke var(--ec-hover-duration, 100ms) ease-out; }
|
|
2185
2297
|
:where(.ec-tooltip-layer) { position: relative; height: 0; }
|
|
2186
2298
|
:where(.ec-tooltip) { position: absolute; left: 0; top: 0; z-index: 3; box-sizing: border-box; width: max-content; max-width: 24em; padding: 8px 10px; border: 1px solid var(--ec-ring, color-mix(in srgb, currentColor 12%, transparent)); border-radius: 8px; background: var(--ec-surface, ${TOKENS.surface}); color: var(--ec-text, ${TOKENS.text}); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); font-size: 13px; line-height: 1.35; white-space: pre-line; font-variant-numeric: tabular-nums; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity var(--ec-hover-duration, 100ms) ease-out, visibility 0s linear var(--ec-hover-duration, 100ms); }
|
|
2187
|
-
:where(.ec-tooltip.ec-tooltip-shown) { opacity: 1; visibility: visible; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
2299
|
+
:where(.ec-tooltip.ec-tooltip-shown) { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
2300
|
+
:where(.ec-tooltip-bridge) { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; }
|
|
2301
|
+
:where(.ec-tooltip-shown + .ec-tooltip-bridge) { pointer-events: auto; }
|
|
2302
|
+
:where(.ec-tooltip-through > .ec-tooltip, .ec-tooltip-through > .ec-tooltip-bridge) { pointer-events: none; }
|
|
2188
2303
|
:where(.ec-tooltip-title) { font-weight: 600; }
|
|
2189
2304
|
:where(.ec-legend) { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 8px; font-size: 13px; line-height: 1.4; color: var(--ec-text, ${TOKENS.text}); }
|
|
2190
2305
|
:where(.ec-legend-item) { display: inline-flex; align-items: center; gap: 6px; }
|
|
@@ -2258,11 +2373,11 @@ function checkLegendOption(option, chart) {
|
|
|
2258
2373
|
var extras = (option) => typeof option === "object" ? option.entries ?? [] : [];
|
|
2259
2374
|
function chartLegend(svg) {
|
|
2260
2375
|
let legend;
|
|
2261
|
-
let
|
|
2376
|
+
let drawn2 = "";
|
|
2262
2377
|
const remove = () => {
|
|
2263
2378
|
legend?.remove();
|
|
2264
2379
|
legend = void 0;
|
|
2265
|
-
|
|
2380
|
+
drawn2 = "";
|
|
2266
2381
|
};
|
|
2267
2382
|
const draw = (entries, colors, attribute, more) => {
|
|
2268
2383
|
const items = [
|
|
@@ -2273,8 +2388,8 @@ function chartLegend(svg) {
|
|
|
2273
2388
|
legend ?? (legend = Object.assign(doc.createElement("div"), { className: "ec-legend" }));
|
|
2274
2389
|
if (legend.nextSibling !== svg) svg.before(legend);
|
|
2275
2390
|
const id = JSON.stringify([attribute, items]);
|
|
2276
|
-
if (id ===
|
|
2277
|
-
|
|
2391
|
+
if (id === drawn2) return;
|
|
2392
|
+
drawn2 = id;
|
|
2278
2393
|
legend.replaceChildren(
|
|
2279
2394
|
...items.map(({ key, label: text2, styles }) => {
|
|
2280
2395
|
const item = doc.createElement("span");
|
|
@@ -2460,8 +2575,8 @@ function maskedHalo() {
|
|
|
2460
2575
|
group = void 0;
|
|
2461
2576
|
};
|
|
2462
2577
|
return {
|
|
2463
|
-
paint(container,
|
|
2464
|
-
if (!halo || !container ||
|
|
2578
|
+
paint(container, parts2, halo, transform) {
|
|
2579
|
+
if (!halo || !container || parts2.length === 0) {
|
|
2465
2580
|
remove();
|
|
2466
2581
|
return;
|
|
2467
2582
|
}
|
|
@@ -2473,12 +2588,12 @@ function maskedHalo() {
|
|
|
2473
2588
|
const id = `ec-halo-mask-${++haloMasks}`;
|
|
2474
2589
|
const mask = svgElement("mask", { id, maskUnits: "userSpaceOnUse", x: -1e5, y: -1e5, width: 2e5, height: 2e5 }, group);
|
|
2475
2590
|
svgElement("rect", { x: -1e5, y: -1e5, width: 2e5, height: 2e5, fill: "white" }, mask);
|
|
2476
|
-
for (const part of
|
|
2591
|
+
for (const part of parts2) {
|
|
2477
2592
|
const cut = part.stroke === void 0 ? { fill: "black" } : { fill: "none", stroke: "black", "stroke-width": part.stroke, "stroke-linejoin": "round" };
|
|
2478
2593
|
svgElement("path", { d: part.d, ...cut }, mask);
|
|
2479
2594
|
}
|
|
2480
2595
|
setAttributes(group, { transform: transform && transformAttribute(transform) });
|
|
2481
|
-
for (const part of
|
|
2596
|
+
for (const part of parts2) {
|
|
2482
2597
|
const open = part.stroke !== void 0;
|
|
2483
2598
|
const path = svgElement(
|
|
2484
2599
|
"path",
|
|
@@ -2500,24 +2615,24 @@ function svgMarkHandle(target, options = {}) {
|
|
|
2500
2615
|
const repaint = () => {
|
|
2501
2616
|
const current = target();
|
|
2502
2617
|
if (!current) return;
|
|
2503
|
-
const { body, parts } = current;
|
|
2618
|
+
const { body, parts: parts2 } = current;
|
|
2504
2619
|
setAttributes(body, {
|
|
2505
2620
|
transform: style.transform && transformAttribute(style.transform),
|
|
2506
2621
|
opacity: style.opacity
|
|
2507
2622
|
});
|
|
2508
2623
|
const emphasis = style.emphasis;
|
|
2509
|
-
for (const part of
|
|
2624
|
+
for (const part of parts2) {
|
|
2510
2625
|
setStyles(part.element, {
|
|
2511
2626
|
[part.open ? "stroke" : "fill"]: emphasis === void 0 ? void 0 : mix(part.colors, emphasis),
|
|
2512
2627
|
transition: emphasis === void 0 ? void 0 : "none"
|
|
2513
2628
|
});
|
|
2514
2629
|
}
|
|
2515
|
-
paintHalo(body,
|
|
2630
|
+
paintHalo(body, parts2);
|
|
2516
2631
|
};
|
|
2517
|
-
const paintHalo = (body,
|
|
2632
|
+
const paintHalo = (body, parts2) => {
|
|
2518
2633
|
const spec = style.halo;
|
|
2519
2634
|
if (above) {
|
|
2520
|
-
const visible2 =
|
|
2635
|
+
const visible2 = parts2.flatMap((part) => part.visible ? [{ d: part.d, color: part.colors.color, ...part.open ? { stroke: part.open.width } : {} }] : []);
|
|
2521
2636
|
above.paint(options.halos?.(), visible2, spec, style.transform);
|
|
2522
2637
|
return;
|
|
2523
2638
|
}
|
|
@@ -2531,7 +2646,7 @@ function svgMarkHandle(target, options = {}) {
|
|
|
2531
2646
|
halo = svgElement("g", { class: "ec-halo" }, body);
|
|
2532
2647
|
body.insertBefore(halo, body.firstChild);
|
|
2533
2648
|
}
|
|
2534
|
-
const visible =
|
|
2649
|
+
const visible = parts2.filter((part) => part.visible);
|
|
2535
2650
|
while (halo.childElementCount > visible.length) halo.lastElementChild?.remove();
|
|
2536
2651
|
visible.forEach((part, index) => {
|
|
2537
2652
|
const path = halo.children[index] ?? svgElement("path", { "stroke-linejoin": "round" }, halo);
|
|
@@ -2632,7 +2747,9 @@ function drawShape(shape, parent) {
|
|
|
2632
2747
|
"clip-path": clip && `url(#${clip})`,
|
|
2633
2748
|
"stroke-width": shape.stroke === void 0 ? void 0 : shape.width ?? 1,
|
|
2634
2749
|
"stroke-linecap": shape.linecap,
|
|
2635
|
-
"stroke-linejoin": shape.linejoin
|
|
2750
|
+
"stroke-linejoin": shape.linejoin,
|
|
2751
|
+
"fill-rule": shape.fillRule,
|
|
2752
|
+
opacity: shape.opacity
|
|
2636
2753
|
},
|
|
2637
2754
|
parent
|
|
2638
2755
|
);
|
|
@@ -2772,6 +2889,9 @@ function pointerHover(svg, options) {
|
|
|
2772
2889
|
const doc = svg.ownerDocument;
|
|
2773
2890
|
let current;
|
|
2774
2891
|
let lastPointer = "mouse";
|
|
2892
|
+
let held;
|
|
2893
|
+
let watcher;
|
|
2894
|
+
let still;
|
|
2775
2895
|
const enter = (target, source) => {
|
|
2776
2896
|
if (target?.key === current) return;
|
|
2777
2897
|
leave2();
|
|
@@ -2780,15 +2900,91 @@ function pointerHover(svg, options) {
|
|
|
2780
2900
|
options.hover(target, source);
|
|
2781
2901
|
};
|
|
2782
2902
|
const leave2 = () => {
|
|
2903
|
+
letGo();
|
|
2783
2904
|
if (current === void 0) return;
|
|
2784
2905
|
current = void 0;
|
|
2785
2906
|
options.leave();
|
|
2786
2907
|
};
|
|
2908
|
+
const tooltipHolding = (node) => {
|
|
2909
|
+
const tip = options.tooltip?.();
|
|
2910
|
+
return tip?.element && node && tip.element.contains(node) ? tip : void 0;
|
|
2911
|
+
};
|
|
2912
|
+
const elementAt = (x, y) => {
|
|
2913
|
+
const root = svg.getRootNode();
|
|
2914
|
+
return typeof root.elementFromPoint === "function" ? root.elementFromPoint(x, y) : void 0;
|
|
2915
|
+
};
|
|
2916
|
+
const landing = (event) => event.relatedTarget ?? elementAt(event.clientX, event.clientY) ?? null;
|
|
2917
|
+
const arrive = (element, x, y) => {
|
|
2918
|
+
const tip = tooltipHolding(element);
|
|
2919
|
+
if (tip) hold(tip, x, y);
|
|
2920
|
+
else enter(element && svg.contains(element) ? options.find(element) : void 0, "pointer");
|
|
2921
|
+
};
|
|
2922
|
+
const hold = (tip, x, y) => {
|
|
2923
|
+
enter({ key: tip.key }, "pointer");
|
|
2924
|
+
const element = tip.element;
|
|
2925
|
+
if (held?.element === element) {
|
|
2926
|
+
held.x = x;
|
|
2927
|
+
held.y = y;
|
|
2928
|
+
return;
|
|
2929
|
+
}
|
|
2930
|
+
letGo();
|
|
2931
|
+
held = { element, x, y };
|
|
2932
|
+
element.addEventListener("pointermove", track);
|
|
2933
|
+
element.addEventListener("pointerleave", off);
|
|
2934
|
+
watcher = new MutationObserver(recheck);
|
|
2935
|
+
watcher.observe(element, { attributes: true, childList: true, characterData: true, subtree: true });
|
|
2936
|
+
};
|
|
2937
|
+
const letGo = () => {
|
|
2938
|
+
if (!held) return;
|
|
2939
|
+
held.element.removeEventListener("pointermove", track);
|
|
2940
|
+
held.element.removeEventListener("pointerleave", off);
|
|
2941
|
+
watcher?.disconnect();
|
|
2942
|
+
watcher = void 0;
|
|
2943
|
+
held = void 0;
|
|
2944
|
+
};
|
|
2945
|
+
const track = (event) => {
|
|
2946
|
+
if (!held || event.pointerType === "touch") return;
|
|
2947
|
+
held.x = event.clientX;
|
|
2948
|
+
held.y = event.clientY;
|
|
2949
|
+
};
|
|
2950
|
+
const off = (event) => {
|
|
2951
|
+
if (event.pointerType === "touch") return;
|
|
2952
|
+
letGo();
|
|
2953
|
+
arrive(landing(event), event.clientX, event.clientY);
|
|
2954
|
+
};
|
|
2955
|
+
const recheck = () => {
|
|
2956
|
+
if (!held) return;
|
|
2957
|
+
const { x, y } = held;
|
|
2958
|
+
const under = elementAt(x, y);
|
|
2959
|
+
if (under === void 0) return;
|
|
2960
|
+
const tip = options.tooltip?.();
|
|
2961
|
+
const onTip = tip?.element !== void 0 && under !== null && tip.element.contains(under);
|
|
2962
|
+
if (onTip && tip.key === current) return;
|
|
2963
|
+
letGo();
|
|
2964
|
+
if (!onTip && tip?.key !== current) {
|
|
2965
|
+
still = { x, y };
|
|
2966
|
+
leave2();
|
|
2967
|
+
return;
|
|
2968
|
+
}
|
|
2969
|
+
arrive(under, x, y);
|
|
2970
|
+
};
|
|
2971
|
+
const resting = (event) => {
|
|
2972
|
+
if (still && Math.abs(event.clientX - still.x) < 1 && Math.abs(event.clientY - still.y) < 1) return true;
|
|
2973
|
+
still = void 0;
|
|
2974
|
+
return false;
|
|
2975
|
+
};
|
|
2787
2976
|
const over = (event) => {
|
|
2788
|
-
if (event.pointerType
|
|
2977
|
+
if (event.pointerType === "touch" || resting(event)) return;
|
|
2978
|
+
letGo();
|
|
2979
|
+
enter(options.find(event.target), "pointer");
|
|
2789
2980
|
};
|
|
2790
2981
|
const out = (event) => {
|
|
2791
|
-
if (event.pointerType
|
|
2982
|
+
if (event.pointerType === "touch") return;
|
|
2983
|
+
still = void 0;
|
|
2984
|
+
arrive(landing(event), event.clientX, event.clientY);
|
|
2985
|
+
};
|
|
2986
|
+
const move = (event) => {
|
|
2987
|
+
if (event.pointerType !== "touch") resting(event);
|
|
2792
2988
|
};
|
|
2793
2989
|
const down = (event) => {
|
|
2794
2990
|
lastPointer = event.pointerType;
|
|
@@ -2797,10 +2993,13 @@ function pointerHover(svg, options) {
|
|
|
2797
2993
|
if (lastPointer === "touch") enter(options.find(event.target), "touch");
|
|
2798
2994
|
};
|
|
2799
2995
|
const elsewhere = (event) => {
|
|
2800
|
-
if (current
|
|
2996
|
+
if (current === void 0 || event.pointerType !== "touch") return;
|
|
2997
|
+
const target = event.composedPath()[0] ?? event.target;
|
|
2998
|
+
if (!svg.contains(target) && !tooltipHolding(target)) leave2();
|
|
2801
2999
|
};
|
|
2802
3000
|
svg.addEventListener("pointerover", over);
|
|
2803
3001
|
svg.addEventListener("pointerleave", out);
|
|
3002
|
+
svg.addEventListener("pointermove", move);
|
|
2804
3003
|
svg.addEventListener("pointerdown", down);
|
|
2805
3004
|
svg.addEventListener("click", click);
|
|
2806
3005
|
doc.addEventListener("pointerdown", elsewhere, true);
|
|
@@ -2808,11 +3007,16 @@ function pointerHover(svg, options) {
|
|
|
2808
3007
|
get current() {
|
|
2809
3008
|
return current;
|
|
2810
3009
|
},
|
|
2811
|
-
clear
|
|
3010
|
+
clear() {
|
|
3011
|
+
if (held) still = { x: held.x, y: held.y };
|
|
3012
|
+
leave2();
|
|
3013
|
+
},
|
|
2812
3014
|
destroy() {
|
|
3015
|
+
letGo();
|
|
2813
3016
|
current = void 0;
|
|
2814
3017
|
svg.removeEventListener("pointerover", over);
|
|
2815
3018
|
svg.removeEventListener("pointerleave", out);
|
|
3019
|
+
svg.removeEventListener("pointermove", move);
|
|
2816
3020
|
svg.removeEventListener("pointerdown", down);
|
|
2817
3021
|
svg.removeEventListener("click", click);
|
|
2818
3022
|
doc.removeEventListener("pointerdown", elsewhere, true);
|
|
@@ -2900,6 +3104,13 @@ function keyboardFocus(svg, options) {
|
|
|
2900
3104
|
case "ArrowLeft":
|
|
2901
3105
|
next = keys[Math.max(0, index - 1)];
|
|
2902
3106
|
break;
|
|
3107
|
+
case "PageDown":
|
|
3108
|
+
case "PageUp": {
|
|
3109
|
+
const by = event.key === "PageDown" ? 1 : -1;
|
|
3110
|
+
const paged = options.page?.(key, by);
|
|
3111
|
+
next = paged !== void 0 && keys.includes(paged) ? paged : keys[Math.min(keys.length - 1, Math.max(0, index + by * Math.ceil(keys.length / 10)))];
|
|
3112
|
+
break;
|
|
3113
|
+
}
|
|
2903
3114
|
case "Home":
|
|
2904
3115
|
next = keys[0];
|
|
2905
3116
|
break;
|
|
@@ -3060,11 +3271,14 @@ function chartHover(options) {
|
|
|
3060
3271
|
},
|
|
3061
3272
|
leave() {
|
|
3062
3273
|
if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
|
|
3063
|
-
}
|
|
3274
|
+
},
|
|
3275
|
+
// The pointer can move onto the tooltip of the chart's own hover. A link's has none.
|
|
3276
|
+
tooltip: () => own(hovered) ? { key: hovered.keys[0], element: options.tooltip.element?.() } : void 0
|
|
3064
3277
|
});
|
|
3065
3278
|
const keyboard = keyboardFocus(() => svg, {
|
|
3066
3279
|
find: (eventTarget) => options.find(eventTarget)?.key,
|
|
3067
3280
|
order: options.order,
|
|
3281
|
+
page: (key, by) => options.page?.(key, by),
|
|
3068
3282
|
element: options.element,
|
|
3069
3283
|
focus(key, visible) {
|
|
3070
3284
|
ringKey = visible ? key : void 0;
|
|
@@ -3240,9 +3454,9 @@ function checkTableOption(option, chart) {
|
|
|
3240
3454
|
throw new TypeError(`${chart}: ${what}`);
|
|
3241
3455
|
};
|
|
3242
3456
|
if (typeof option !== "object" || option === null) fail('table must be true, false, "hidden" or an object of table options.');
|
|
3243
|
-
const { hidden: hidden2, columns, category, total: total2, share, summary, series } = option;
|
|
3457
|
+
const { hidden: hidden2, columns, category, total: total2, share, summary: summary2, series } = option;
|
|
3244
3458
|
if (hidden2 !== void 0 && typeof hidden2 !== "boolean") fail("table.hidden must be true or false.");
|
|
3245
|
-
for (const [name, text2] of Object.entries({ category, total: total2, share, summary })) {
|
|
3459
|
+
for (const [name, text2] of Object.entries({ category, total: total2, share, summary: summary2 })) {
|
|
3246
3460
|
if (text2 !== void 0 && typeof text2 !== "string") fail(`table.${name} must be a string.`);
|
|
3247
3461
|
}
|
|
3248
3462
|
if (series !== void 0) {
|
|
@@ -3261,6 +3475,7 @@ function checkTableOption(option, chart) {
|
|
|
3261
3475
|
if (column.after !== void 0 && column.after !== "category" && column.after !== "values") fail(`table.columns[${i}].after must be "category" or "values".`);
|
|
3262
3476
|
});
|
|
3263
3477
|
}
|
|
3478
|
+
var MISSING = "missing";
|
|
3264
3479
|
function tableModel(input) {
|
|
3265
3480
|
const { option, format: format2 } = input;
|
|
3266
3481
|
if (option === false) return void 0;
|
|
@@ -3290,7 +3505,7 @@ function tableModel(input) {
|
|
|
3290
3505
|
cells: [
|
|
3291
3506
|
{ text: row.category, numeric: false },
|
|
3292
3507
|
...first.map((column) => columnCell(column, row, format2)),
|
|
3293
|
-
...input.series.map((series) => number2(values.get(series) ?? 0)),
|
|
3508
|
+
...input.series.map((series) => row.missing?.has(series) ? { text: MISSING, numeric: true } : number2(values.get(series) ?? 0)),
|
|
3294
3509
|
...totals ? [number2(row.total)] : [],
|
|
3295
3510
|
...share(row.total),
|
|
3296
3511
|
...last.map((column) => columnCell(column, row, format2))
|
|
@@ -3331,14 +3546,14 @@ function columnCell(column, row, format2) {
|
|
|
3331
3546
|
function chartTable(svg) {
|
|
3332
3547
|
const doc = svg.ownerDocument;
|
|
3333
3548
|
let wrapper;
|
|
3334
|
-
let
|
|
3549
|
+
let summary2;
|
|
3335
3550
|
let table;
|
|
3336
3551
|
let caption2;
|
|
3337
3552
|
let head;
|
|
3338
3553
|
let body;
|
|
3339
3554
|
let foot;
|
|
3340
3555
|
const rows2 = /* @__PURE__ */ new Map();
|
|
3341
|
-
let
|
|
3556
|
+
let drawn2 = "";
|
|
3342
3557
|
const element = (tag, className) => {
|
|
3343
3558
|
const made = doc.createElement(tag);
|
|
3344
3559
|
if (className) made.className = className;
|
|
@@ -3360,19 +3575,19 @@ function chartTable(svg) {
|
|
|
3360
3575
|
const next = hidden2 ? element("div", "ec-table ec-visually-hidden") : element("details", "ec-table");
|
|
3361
3576
|
const content = table ?? build();
|
|
3362
3577
|
if (hidden2) {
|
|
3363
|
-
|
|
3578
|
+
summary2 = void 0;
|
|
3364
3579
|
next.appendChild(content);
|
|
3365
3580
|
} else {
|
|
3366
|
-
|
|
3581
|
+
summary2 = element("summary");
|
|
3367
3582
|
const scroll = element("div", "ec-table-scroll");
|
|
3368
3583
|
scroll.appendChild(content);
|
|
3369
|
-
next.append(
|
|
3584
|
+
next.append(summary2, scroll);
|
|
3370
3585
|
}
|
|
3371
3586
|
if (wrapper?.isConnected) wrapper.replaceWith(next);
|
|
3372
3587
|
wrapper = next;
|
|
3373
3588
|
}
|
|
3374
3589
|
if (!wrapper.isConnected) svg.after(wrapper);
|
|
3375
|
-
if (
|
|
3590
|
+
if (summary2 && summary2.textContent !== text2) summary2.textContent = text2;
|
|
3376
3591
|
}
|
|
3377
3592
|
function fill(cell, { text: text2, numeric: numeric3 }) {
|
|
3378
3593
|
if (cell.textContent !== text2) cell.textContent = text2;
|
|
@@ -3380,9 +3595,9 @@ function chartTable(svg) {
|
|
|
3380
3595
|
}
|
|
3381
3596
|
function remove() {
|
|
3382
3597
|
wrapper?.remove();
|
|
3383
|
-
wrapper =
|
|
3598
|
+
wrapper = summary2 = table = caption2 = head = body = foot = void 0;
|
|
3384
3599
|
rows2.clear();
|
|
3385
|
-
|
|
3600
|
+
drawn2 = "";
|
|
3386
3601
|
}
|
|
3387
3602
|
return {
|
|
3388
3603
|
render(model) {
|
|
@@ -3393,8 +3608,8 @@ function chartTable(svg) {
|
|
|
3393
3608
|
place(model.hidden, model.summary);
|
|
3394
3609
|
if (caption2.textContent !== model.caption) caption2.textContent = model.caption;
|
|
3395
3610
|
const headers = JSON.stringify(model.headers);
|
|
3396
|
-
if (headers !==
|
|
3397
|
-
|
|
3611
|
+
if (headers !== drawn2) {
|
|
3612
|
+
drawn2 = headers;
|
|
3398
3613
|
head.replaceChildren(
|
|
3399
3614
|
...model.headers.map((header) => {
|
|
3400
3615
|
const th = element("th");
|
|
@@ -3582,7 +3797,9 @@ function playUpdate(options, arrange, announce) {
|
|
|
3582
3797
|
options.leaving.sweep();
|
|
3583
3798
|
});
|
|
3584
3799
|
events.emitEach("exit", diff.exiting, onScreen);
|
|
3585
|
-
|
|
3800
|
+
if (options.data || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) {
|
|
3801
|
+
runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
|
|
3802
|
+
}
|
|
3586
3803
|
events.emitEach("update", diff.changed, ({ record, from }) => ({ ...input(record), from }));
|
|
3587
3804
|
runner.enter(diff.entering.map(input));
|
|
3588
3805
|
events.emitEach("enter", diff.entering, input);
|
|
@@ -3650,6 +3867,7 @@ function watchHoverDuration(svg, motion2) {
|
|
|
3650
3867
|
|
|
3651
3868
|
// src/charts/tooltip.ts
|
|
3652
3869
|
var GAP2 = 12;
|
|
3870
|
+
var OVERLAP = 1;
|
|
3653
3871
|
var FADE = 100;
|
|
3654
3872
|
var described = 0;
|
|
3655
3873
|
function placeTooltip(anchor, size2, box, side) {
|
|
@@ -3671,27 +3889,54 @@ function summaryContent(category, values, format2, options = {}) {
|
|
|
3671
3889
|
function chartTooltip(svg, options) {
|
|
3672
3890
|
let layer;
|
|
3673
3891
|
let box;
|
|
3892
|
+
let bridge;
|
|
3674
3893
|
let texts = /* @__PURE__ */ new WeakMap();
|
|
3675
3894
|
let rendered;
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3895
|
+
let pointer;
|
|
3896
|
+
let through = false;
|
|
3897
|
+
let shape;
|
|
3898
|
+
const timing = (element) => element.style.setProperty("--ec-hover-duration", `${options.motion.duration(FADE, "feedback")}ms`);
|
|
3899
|
+
const shown = () => box?.classList.contains("ec-tooltip-shown") ?? false;
|
|
3900
|
+
const under = () => {
|
|
3901
|
+
if (!pointer || !box || !layer) return false;
|
|
3902
|
+
const { x, y } = pointer;
|
|
3903
|
+
const { left, right, top, bottom } = box.getBoundingClientRect();
|
|
3904
|
+
if (x > left && x < right && y > top && y < bottom) return true;
|
|
3905
|
+
if (!shape) return false;
|
|
3906
|
+
const origin = layer.getBoundingClientRect();
|
|
3907
|
+
return inside(shape, x - origin.left, y - origin.top);
|
|
3908
|
+
};
|
|
3909
|
+
const letThrough = (on) => {
|
|
3910
|
+
through = on;
|
|
3911
|
+
layer?.classList.toggle("ec-tooltip-through", on);
|
|
3912
|
+
};
|
|
3913
|
+
const track = (event) => {
|
|
3914
|
+
pointer = event.pointerType === "touch" ? void 0 : { x: event.clientX, y: event.clientY };
|
|
3915
|
+
if (through && !under()) letThrough(false);
|
|
3916
|
+
};
|
|
3917
|
+
svg.ownerDocument.addEventListener("pointerover", track, true);
|
|
3918
|
+
svg.ownerDocument.addEventListener("pointermove", track, true);
|
|
3919
|
+
function made() {
|
|
3920
|
+
if (!layer || !box || !bridge) {
|
|
3679
3921
|
const doc = svg.ownerDocument;
|
|
3680
3922
|
layer = doc.createElement("div");
|
|
3681
3923
|
layer.className = "ec-tooltip-layer";
|
|
3682
3924
|
box = doc.createElement("div");
|
|
3683
3925
|
box.className = "ec-tooltip";
|
|
3684
3926
|
box.setAttribute("aria-hidden", "true");
|
|
3685
|
-
|
|
3927
|
+
bridge = doc.createElement("div");
|
|
3928
|
+
bridge.className = "ec-tooltip-bridge";
|
|
3929
|
+
bridge.setAttribute("aria-hidden", "true");
|
|
3930
|
+
layer.append(box, bridge);
|
|
3686
3931
|
}
|
|
3687
3932
|
if (layer.previousSibling !== svg) svg.after(layer);
|
|
3688
3933
|
return box;
|
|
3689
3934
|
}
|
|
3690
|
-
function contentFor(row,
|
|
3935
|
+
function contentFor(row, summary2) {
|
|
3691
3936
|
const option = options.option();
|
|
3692
3937
|
const known = texts.get(row);
|
|
3693
3938
|
if (known && known.option === option) return known.content;
|
|
3694
|
-
const content = text(option, row.datum,
|
|
3939
|
+
const content = text(option, row.datum, summary2);
|
|
3695
3940
|
texts.set(row, { option, content });
|
|
3696
3941
|
return content;
|
|
3697
3942
|
}
|
|
@@ -3699,14 +3944,16 @@ function chartTooltip(svg, options) {
|
|
|
3699
3944
|
if (!box) return;
|
|
3700
3945
|
timing(box);
|
|
3701
3946
|
box.classList.remove("ec-tooltip-shown");
|
|
3947
|
+
letThrough(false);
|
|
3702
3948
|
}
|
|
3703
|
-
function place(row,
|
|
3704
|
-
const content = contentFor(row,
|
|
3949
|
+
function place(row, summary2, anchor, moved) {
|
|
3950
|
+
const content = contentFor(row, summary2);
|
|
3705
3951
|
if (content === void 0) {
|
|
3706
3952
|
hide();
|
|
3707
3953
|
return;
|
|
3708
3954
|
}
|
|
3709
|
-
const tip =
|
|
3955
|
+
const tip = made();
|
|
3956
|
+
const held = shown() && !through && under();
|
|
3710
3957
|
const key = typeof content === "string" ? `text:${content}` : JSON.stringify(content);
|
|
3711
3958
|
if (key !== rendered) {
|
|
3712
3959
|
render(tip, content);
|
|
@@ -3718,29 +3965,39 @@ function chartTooltip(svg, options) {
|
|
|
3718
3965
|
const toPx = { x: (x) => (x - view.x) * k, y: (y) => (y - view.y) * k };
|
|
3719
3966
|
const area = chart.width > 0 ? { width: chart.width, height: chart.height } : { width: view.width, height: view.height };
|
|
3720
3967
|
const size2 = { width: tip.offsetWidth, height: tip.offsetHeight };
|
|
3721
|
-
const
|
|
3968
|
+
const near = anchor(toPx, moved);
|
|
3969
|
+
const placed2 = placeTooltip(near, size2, area, moved ? placeTooltip(anchor(toPx, false), size2, area).side : void 0);
|
|
3722
3970
|
const origin = layer.getBoundingClientRect();
|
|
3723
|
-
|
|
3724
|
-
|
|
3971
|
+
const dx = chart.left - origin.left;
|
|
3972
|
+
const dy = chart.top - origin.top;
|
|
3973
|
+
const left = Math.round(dx + placed2.x);
|
|
3974
|
+
const top = Math.round(dy + placed2.y);
|
|
3975
|
+
tip.style.left = `${left}px`;
|
|
3976
|
+
tip.style.top = `${top}px`;
|
|
3725
3977
|
tip.setAttribute("data-side", placed2.side);
|
|
3978
|
+
const mark = near.left === void 0 || near.right === void 0 ? void 0 : { left: dx + near.left, right: dx + near.right, top: dy + near.top, bottom: dy + near.bottom };
|
|
3979
|
+
shape = span(bridge, { left, top, ...size2 }, mark, placed2.side);
|
|
3726
3980
|
timing(tip);
|
|
3727
3981
|
tip.classList.add("ec-tooltip-shown");
|
|
3982
|
+
letThrough(!held && under());
|
|
3728
3983
|
}
|
|
3729
3984
|
return {
|
|
3730
|
-
show(mark, row,
|
|
3985
|
+
show(mark, row, summary2, transform) {
|
|
3731
3986
|
const anchor = (toPx, moved) => {
|
|
3732
3987
|
const m = moved ? transform : void 0;
|
|
3733
3988
|
const { x, y, width, height } = mark.bounds;
|
|
3734
|
-
const
|
|
3989
|
+
const corners = [{ x, y }, { x: x + width, y }, { x, y: y + height }, { x: x + width, y: y + height }].map((corner) => m ? matrix.apply(m, corner) : corner);
|
|
3990
|
+
const xs = corners.map((corner) => corner.x);
|
|
3991
|
+
const ys = corners.map((corner) => corner.y);
|
|
3735
3992
|
const center = m ? matrix.apply(m, mark.center) : mark.center;
|
|
3736
|
-
return { x: toPx.x(center.x), top: toPx.y(Math.min(...ys)), bottom: toPx.y(Math.max(...ys)) };
|
|
3993
|
+
return { x: toPx.x(center.x), top: toPx.y(Math.min(...ys)), bottom: toPx.y(Math.max(...ys)), left: toPx.x(Math.min(...xs)), right: toPx.x(Math.max(...xs)) };
|
|
3737
3994
|
};
|
|
3738
|
-
place(row,
|
|
3995
|
+
place(row, summary2, anchor, transform !== void 0);
|
|
3739
3996
|
},
|
|
3740
|
-
showAt(point, row,
|
|
3741
|
-
place(row,
|
|
3997
|
+
showAt(point, row, summary2) {
|
|
3998
|
+
place(row, summary2, (toPx) => ({ x: toPx.x(point.x), top: toPx.y(point.top), bottom: toPx.y(point.bottom) }), false);
|
|
3742
3999
|
},
|
|
3743
|
-
describe(
|
|
4000
|
+
describe(element, row) {
|
|
3744
4001
|
const own2 = options.description?.();
|
|
3745
4002
|
let content;
|
|
3746
4003
|
if (own2 === false) content = void 0;
|
|
@@ -3753,30 +4010,58 @@ function chartTooltip(svg, options) {
|
|
|
3753
4010
|
content = void 0;
|
|
3754
4011
|
}
|
|
3755
4012
|
} else content = typeof options.option() === "function" ? contentFor(row, () => "") : void 0;
|
|
3756
|
-
let desc =
|
|
4013
|
+
let desc = element.querySelector(":scope > desc.ec-description");
|
|
3757
4014
|
if (typeof content !== "string") {
|
|
3758
4015
|
if (!desc) return;
|
|
3759
|
-
if (
|
|
4016
|
+
if (element.getAttribute("aria-describedby") === desc.id) element.removeAttribute("aria-describedby");
|
|
3760
4017
|
desc.remove();
|
|
3761
4018
|
return;
|
|
3762
4019
|
}
|
|
3763
|
-
desc ?? (desc = svgElement("desc", { class: "ec-description", id: `ec-description-${++described}` },
|
|
4020
|
+
desc ?? (desc = svgElement("desc", { class: "ec-description", id: `ec-description-${++described}` }, element));
|
|
3764
4021
|
if (desc.textContent !== content) desc.textContent = content;
|
|
3765
|
-
|
|
4022
|
+
element.setAttribute("aria-describedby", desc.id);
|
|
3766
4023
|
},
|
|
4024
|
+
element: () => shown() ? layer : void 0,
|
|
3767
4025
|
hide,
|
|
3768
4026
|
destroy() {
|
|
4027
|
+
svg.ownerDocument.removeEventListener("pointerover", track, true);
|
|
4028
|
+
svg.ownerDocument.removeEventListener("pointermove", track, true);
|
|
3769
4029
|
layer?.remove();
|
|
3770
4030
|
layer = void 0;
|
|
3771
4031
|
box = void 0;
|
|
4032
|
+
bridge = void 0;
|
|
4033
|
+
shape = void 0;
|
|
4034
|
+
through = false;
|
|
3772
4035
|
texts = /* @__PURE__ */ new WeakMap();
|
|
3773
4036
|
rendered = void 0;
|
|
3774
4037
|
}
|
|
3775
4038
|
};
|
|
3776
4039
|
}
|
|
3777
|
-
function
|
|
4040
|
+
function inside({ top, bottom, upper, lower }, x, y) {
|
|
4041
|
+
if (y <= top || y >= bottom) return false;
|
|
4042
|
+
const t = (y - top) / (bottom - top);
|
|
4043
|
+
return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
|
|
4044
|
+
}
|
|
4045
|
+
function span(bridge, box, mark, side) {
|
|
4046
|
+
bridge.hidden = mark === void 0;
|
|
4047
|
+
if (!mark) return void 0;
|
|
4048
|
+
const edge = { left: box.left, right: box.left + box.width };
|
|
4049
|
+
const [upper, lower, top, bottom] = side === "above" ? [edge, mark, box.top + box.height, Math.round(mark.top + OVERLAP)] : [mark, edge, Math.round(mark.bottom - OVERLAP), box.top];
|
|
4050
|
+
const left = Math.round(Math.min(upper.left, lower.left));
|
|
4051
|
+
const width = Math.round(Math.max(upper.right, lower.right)) - left;
|
|
4052
|
+
const height = Math.max(0, bottom - top);
|
|
4053
|
+
const x = (value) => `${Math.round(value) - left}px`;
|
|
4054
|
+
bridge.style.left = `${left}px`;
|
|
4055
|
+
bridge.style.top = `${top}px`;
|
|
4056
|
+
bridge.style.width = `${width}px`;
|
|
4057
|
+
bridge.style.height = `${height}px`;
|
|
4058
|
+
bridge.style.setProperty("clip-path", `polygon(${x(upper.left)} 0px, ${x(upper.right)} 0px, ${x(lower.right)} ${height}px, ${x(lower.left)} ${height}px)`);
|
|
4059
|
+
const round5 = (edge2) => ({ left: Math.round(edge2.left), right: Math.round(edge2.right) });
|
|
4060
|
+
return { top, bottom: top + height, upper: round5(upper), lower: round5(lower) };
|
|
4061
|
+
}
|
|
4062
|
+
function text(option, datum, summary2) {
|
|
3778
4063
|
if (option === false) return void 0;
|
|
3779
|
-
if (typeof option !== "function") return
|
|
4064
|
+
if (typeof option !== "function") return summary2();
|
|
3780
4065
|
try {
|
|
3781
4066
|
const result = option(datum);
|
|
3782
4067
|
return result === void 0 || result === null || result === "" ? void 0 : String(result);
|
|
@@ -3800,8 +4085,8 @@ function render(box, content) {
|
|
|
3800
4085
|
box.replaceChildren(line2(content.title, "ec-tooltip-title"), ...content.lines.map((value) => line2(value)));
|
|
3801
4086
|
}
|
|
3802
4087
|
function viewBox(svg) {
|
|
3803
|
-
const
|
|
3804
|
-
if (
|
|
4088
|
+
const parts2 = (svg.getAttribute("viewBox") ?? "").split(/[\s,]+/).map(Number);
|
|
4089
|
+
if (parts2.length === 4 && parts2.every(Number.isFinite)) return { x: parts2[0], y: parts2[1], width: parts2[2], height: parts2[3] };
|
|
3805
4090
|
return { x: 0, y: 0, width: Number(svg.getAttribute("width")) || 0, height: Number(svg.getAttribute("height")) || 0 };
|
|
3806
4091
|
}
|
|
3807
4092
|
|
|
@@ -3885,7 +4170,8 @@ function barChart(target, options, env2) {
|
|
|
3885
4170
|
width: opts.width ?? measuredWidth,
|
|
3886
4171
|
height: opts.height,
|
|
3887
4172
|
format: format(opts),
|
|
3888
|
-
measure
|
|
4173
|
+
measure,
|
|
4174
|
+
room: opts.room ?? 0
|
|
3889
4175
|
});
|
|
3890
4176
|
}
|
|
3891
4177
|
function createRecord(row, entering) {
|
|
@@ -3946,8 +4232,8 @@ function barChart(target, options, env2) {
|
|
|
3946
4232
|
element.remove();
|
|
3947
4233
|
record.paths.delete(series);
|
|
3948
4234
|
}
|
|
3949
|
-
const
|
|
3950
|
-
if (record.parts.some((part, i) =>
|
|
4235
|
+
const drawn2 = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
|
|
4236
|
+
if (record.parts.some((part, i) => drawn2[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
|
|
3951
4237
|
record.handle.repaint();
|
|
3952
4238
|
if (record.parts[0]?.colors.color !== before) surface.recolor(record.key);
|
|
3953
4239
|
if (record.key === hover.ringKey) drawRing(record.key);
|
|
@@ -3962,7 +4248,7 @@ function barChart(target, options, env2) {
|
|
|
3962
4248
|
const { transform } = record.handle.style;
|
|
3963
4249
|
setAttributes(ring, { transform: transform && transformAttribute(transform), visibility: void 0 });
|
|
3964
4250
|
}
|
|
3965
|
-
function
|
|
4251
|
+
function show4(record, row) {
|
|
3966
4252
|
const moved = geometryChanged(record.shown.geometry, row.geometry) || record.shown.datum !== row.datum;
|
|
3967
4253
|
drawMark(record, row);
|
|
3968
4254
|
if (moved) runner.change(row.geometry, row.data);
|
|
@@ -3970,12 +4256,12 @@ function barChart(target, options, env2) {
|
|
|
3970
4256
|
}
|
|
3971
4257
|
function showTooltip(record) {
|
|
3972
4258
|
const { row } = record;
|
|
3973
|
-
tooltip.show(record.shown.geometry, row, () => summaryContent(row.
|
|
4259
|
+
tooltip.show(record.shown.geometry, row, () => summaryContent(row.category, labelled(row.values, current), format(current)), record.handle.style.transform);
|
|
3974
4260
|
}
|
|
3975
4261
|
function syncLegend(next) {
|
|
3976
4262
|
if (byCategory(current)) {
|
|
3977
4263
|
legend.categories(
|
|
3978
|
-
next.rows.map((row) => ({ key: row.key, label: row.
|
|
4264
|
+
next.rows.map((row) => ({ key: row.key, label: row.category })),
|
|
3979
4265
|
colors,
|
|
3980
4266
|
current.legend
|
|
3981
4267
|
);
|
|
@@ -3996,7 +4282,7 @@ function barChart(target, options, env2) {
|
|
|
3996
4282
|
category: typeof field === "string" ? field : void 0,
|
|
3997
4283
|
series: encoding.series.map((s) => s.series),
|
|
3998
4284
|
label: (series) => seriesLabel(opts.seriesLabels, series),
|
|
3999
|
-
rows: next.rows.map((row) => ({ key: row.key, category: row.
|
|
4285
|
+
rows: next.rows.map((row) => ({ key: row.key, category: row.category, datum: row.datum, index: row.index, values: row.values, total: row.total })),
|
|
4000
4286
|
format: format(opts)
|
|
4001
4287
|
});
|
|
4002
4288
|
}
|
|
@@ -4006,7 +4292,7 @@ function barChart(target, options, env2) {
|
|
|
4006
4292
|
const series = barEncoding(current).series.map((s) => s.series);
|
|
4007
4293
|
const before = barEncoding(previous).series.map((s) => s.series);
|
|
4008
4294
|
const sort = sortName(current.sort);
|
|
4009
|
-
const name = (record) => record.row.
|
|
4295
|
+
const name = (record) => record.row.category;
|
|
4010
4296
|
const changed = diff.changed.map(({ record }) => record);
|
|
4011
4297
|
const text2 = changeText({
|
|
4012
4298
|
...current.label !== previous.label ? { label: current.label } : {},
|
|
@@ -4024,8 +4310,8 @@ function barChart(target, options, env2) {
|
|
|
4024
4310
|
}
|
|
4025
4311
|
const key = (record) => record.key;
|
|
4026
4312
|
try {
|
|
4027
|
-
const
|
|
4028
|
-
if (
|
|
4313
|
+
const said2 = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
|
|
4314
|
+
if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
|
|
4029
4315
|
} catch (error) {
|
|
4030
4316
|
report(error);
|
|
4031
4317
|
}
|
|
@@ -4037,7 +4323,7 @@ function barChart(target, options, env2) {
|
|
|
4037
4323
|
const values = record.series.map((series) => ({ series, value: now[series] ?? 0 }));
|
|
4038
4324
|
const total2 = values.reduce((sum, v) => sum + v.value, 0);
|
|
4039
4325
|
const text2 = record.count === void 0 ? row.value.text : format(current)(round(total2, record.count));
|
|
4040
|
-
return placeRow(frame2, { key: row.key, datum: row.datum, index: row.index, category: row.
|
|
4326
|
+
return placeRow(frame2, { key: row.key, datum: row.datum, index: row.index, category: row.category, values, slot: record.slot.value, text: text2, drawn: row.drawn }, measure);
|
|
4041
4327
|
}
|
|
4042
4328
|
function addTick(value, opacity) {
|
|
4043
4329
|
const tick = {
|
|
@@ -4065,7 +4351,7 @@ function barChart(target, options, env2) {
|
|
|
4065
4351
|
if (frameMoved) setAttributes(svg, sizeAttributes(frame2.bands));
|
|
4066
4352
|
if (frameMoved || ticksFaded) for (const tick of ticks.values()) drawTick(tick, frame2);
|
|
4067
4353
|
for (const record of [...order, ...leaving.values()]) {
|
|
4068
|
-
if (frameMoved || dirty.has(record))
|
|
4354
|
+
if (frameMoved || dirty.has(record)) show4(record, currentRow(record, frame2));
|
|
4069
4355
|
}
|
|
4070
4356
|
frameMoved = false;
|
|
4071
4357
|
ticksFaded = false;
|
|
@@ -4089,7 +4375,7 @@ function barChart(target, options, env2) {
|
|
|
4089
4375
|
for (const record of order) {
|
|
4090
4376
|
record.series = record.row.values.map((v) => v.series);
|
|
4091
4377
|
record.count = void 0;
|
|
4092
|
-
|
|
4378
|
+
show4(record, record.row);
|
|
4093
4379
|
}
|
|
4094
4380
|
frameMoved = false;
|
|
4095
4381
|
ticksFaded = false;
|
|
@@ -4217,7 +4503,8 @@ function barChart(target, options, env2) {
|
|
|
4217
4503
|
const record = records.get(key);
|
|
4218
4504
|
if (record) showTooltip(record);
|
|
4219
4505
|
},
|
|
4220
|
-
hide: () => tooltip.hide()
|
|
4506
|
+
hide: () => tooltip.hide(),
|
|
4507
|
+
element: () => tooltip.element()
|
|
4221
4508
|
}
|
|
4222
4509
|
});
|
|
4223
4510
|
const unwatchHoverDuration = watchHoverDuration(svg, motion2);
|
|
@@ -4284,6 +4571,7 @@ function barChart(target, options, env2) {
|
|
|
4284
4571
|
leaving,
|
|
4285
4572
|
input,
|
|
4286
4573
|
onScreen,
|
|
4574
|
+
data: "data" in next,
|
|
4287
4575
|
...swapping ? {
|
|
4288
4576
|
swap: (diff) => {
|
|
4289
4577
|
const entering = new Set(diff.entering);
|
|
@@ -4342,7 +4630,8 @@ function barChart(target, options, env2) {
|
|
|
4342
4630
|
}
|
|
4343
4631
|
function checkOptions2(options) {
|
|
4344
4632
|
checkChartOptions(options, "barChart");
|
|
4345
|
-
const { colorBy } = options;
|
|
4633
|
+
const { colorBy, room } = options;
|
|
4634
|
+
if (room !== void 0 && !(typeof room === "number" && Number.isFinite(room) && room >= 0)) throw new RangeError(`barChart: room must be a number of px, 0 or more, got ${String(room)}.`);
|
|
4346
4635
|
if (colorBy !== void 0 && colorBy !== "series" && colorBy !== "category") throw new TypeError(`barChart: colorBy must be "series" or "category", got ${String(colorBy)}.`);
|
|
4347
4636
|
if (colorBy === "category" && options.stack !== void 0) {
|
|
4348
4637
|
throw new TypeError('barChart: colorBy: "category" gives each bar one colour, so it needs one series, not a stack. A stack colours its segments by series.');
|
|
@@ -4355,10 +4644,10 @@ function markLabel(row, options) {
|
|
|
4355
4644
|
const formatted = format(options);
|
|
4356
4645
|
const values = labelled(row.values, options);
|
|
4357
4646
|
const lone = values.length === 1 && values[0].series === "value" && values[0].label === "value";
|
|
4358
|
-
const text2 = `${row.
|
|
4647
|
+
const text2 = `${row.category}: ${values.map((v) => lone ? formatted(v.value) : `${formatted(v.value)} ${v.label}`).join(", ")}`;
|
|
4359
4648
|
if (!options.markLabel) return text2;
|
|
4360
4649
|
try {
|
|
4361
|
-
const named = options.markLabel(row.datum, { key: row.key, category: row.
|
|
4650
|
+
const named = options.markLabel(row.datum, { key: row.key, category: row.category, values, total: row.total, format: formatted, text: text2 });
|
|
4362
4651
|
if (named !== void 0 && named !== null && String(named).trim() !== "") return String(named);
|
|
4363
4652
|
} catch (error) {
|
|
4364
4653
|
report(error);
|
|
@@ -4442,7 +4731,7 @@ function layoutDonut(input) {
|
|
|
4442
4731
|
const end = i + 1 < rows2.length && total2 > 0 ? starts[i + 1] : total2 > 0 ? 1 : 0;
|
|
4443
4732
|
return { ...row, series: input.encoding.series, share, start: starts[i] * TAU2, end: end * TAU2 };
|
|
4444
4733
|
});
|
|
4445
|
-
const labels =
|
|
4734
|
+
const labels = placeLabels2(frame2, states, input.measure);
|
|
4446
4735
|
const centerText2 = input.center(total2);
|
|
4447
4736
|
return {
|
|
4448
4737
|
frame: frame2,
|
|
@@ -4476,7 +4765,7 @@ function placeSlice(frame2, state, label2, measure) {
|
|
|
4476
4765
|
});
|
|
4477
4766
|
return { ...state, geometry, data: sliceData(state.datum, state.share, state.series) };
|
|
4478
4767
|
}
|
|
4479
|
-
function
|
|
4768
|
+
function placeLabels2(frame2, slices, measure) {
|
|
4480
4769
|
let previous;
|
|
4481
4770
|
let first;
|
|
4482
4771
|
const labels = slices.map((slice, i) => {
|
|
@@ -4484,7 +4773,7 @@ function placeLabels(frame2, slices, measure) {
|
|
|
4484
4773
|
const label2 = labelAt(frame2, slice, measure);
|
|
4485
4774
|
const { box } = label2;
|
|
4486
4775
|
if (box.x < 0 || box.y < 0 || box.x + box.width > frame2.width || box.y + box.height > frame2.height) return void 0;
|
|
4487
|
-
if (previous &&
|
|
4776
|
+
if (previous && overlaps2(previous, box)) return void 0;
|
|
4488
4777
|
previous = box;
|
|
4489
4778
|
first ?? (first = i);
|
|
4490
4779
|
return label2;
|
|
@@ -4492,7 +4781,7 @@ function placeLabels(frame2, slices, measure) {
|
|
|
4492
4781
|
for (let i = labels.length - 1; first !== void 0 && i > first; i--) {
|
|
4493
4782
|
const label2 = labels[i];
|
|
4494
4783
|
if (!label2) continue;
|
|
4495
|
-
if (!
|
|
4784
|
+
if (!overlaps2(labels[first].box, label2.box)) break;
|
|
4496
4785
|
labels[i] = void 0;
|
|
4497
4786
|
}
|
|
4498
4787
|
return labels;
|
|
@@ -4559,7 +4848,7 @@ function labelBoxes2(label2, measure) {
|
|
|
4559
4848
|
if (label2.share.text !== "") out.push(textBox(label2.share, measure, "ec-value", VALUE_SIZE2));
|
|
4560
4849
|
return out;
|
|
4561
4850
|
}
|
|
4562
|
-
function
|
|
4851
|
+
function overlaps2(a, b) {
|
|
4563
4852
|
return a.x < b.x + b.width + LABEL_SPACE && b.x < a.x + a.width + LABEL_SPACE && a.y < b.y + b.height + LABEL_SPACE && b.y < a.y + a.height + LABEL_SPACE;
|
|
4564
4853
|
}
|
|
4565
4854
|
function sliceData(datum, share, series) {
|
|
@@ -4723,7 +5012,7 @@ function donutChart(target, options, env2) {
|
|
|
4723
5012
|
const record = key === void 0 ? void 0 : records.get(key);
|
|
4724
5013
|
focusRing.draw(record && { outline: record.shown.geometry.outline, thickness: record.shown.geometry.thickness, transform: record.handle.style.transform });
|
|
4725
5014
|
}
|
|
4726
|
-
function
|
|
5015
|
+
function show4(record, slice, label2) {
|
|
4727
5016
|
const moved = geometryChanged(record.shown.geometry, slice.geometry) || record.shown.datum !== slice.datum;
|
|
4728
5017
|
drawMark(record, slice, label2);
|
|
4729
5018
|
if (moved) runner.change(slice.geometry, slice.data);
|
|
@@ -4787,13 +5076,13 @@ function donutChart(target, options, env2) {
|
|
|
4787
5076
|
}
|
|
4788
5077
|
const key = (record) => record.key;
|
|
4789
5078
|
try {
|
|
4790
|
-
const
|
|
4791
|
-
if (
|
|
5079
|
+
const said2 = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
|
|
5080
|
+
if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
|
|
4792
5081
|
} catch (error) {
|
|
4793
5082
|
report(error);
|
|
4794
5083
|
}
|
|
4795
5084
|
}
|
|
4796
|
-
const
|
|
5085
|
+
const drawn2 = (record) => records.get(record.key) === record || leaving.get(record.key) === record;
|
|
4797
5086
|
const valueOf = (record) => Math.max(0, record.value.value);
|
|
4798
5087
|
function startsIn(slices, total2, value = valueOf) {
|
|
4799
5088
|
const starts = /* @__PURE__ */ new Map();
|
|
@@ -4805,8 +5094,8 @@ function donutChart(target, options, env2) {
|
|
|
4805
5094
|
return starts;
|
|
4806
5095
|
}
|
|
4807
5096
|
function angles() {
|
|
4808
|
-
ring = ring.filter(
|
|
4809
|
-
from = from.filter(
|
|
5097
|
+
ring = ring.filter(drawn2);
|
|
5098
|
+
from = from.filter(drawn2);
|
|
4810
5099
|
const total2 = ring.reduce((sum, record) => sum + valueOf(record), 0);
|
|
4811
5100
|
const to = startsIn(ring, total2);
|
|
4812
5101
|
const was = startsIn(from, total2);
|
|
@@ -4825,7 +5114,7 @@ function donutChart(target, options, env2) {
|
|
|
4825
5114
|
return out;
|
|
4826
5115
|
}
|
|
4827
5116
|
function currentSlices(f) {
|
|
4828
|
-
const now = [...angles()].map(([record, { start, span }]) => {
|
|
5117
|
+
const now = [...angles()].map(([record, { start, span: span2 }]) => {
|
|
4829
5118
|
const { row } = record;
|
|
4830
5119
|
const state = {
|
|
4831
5120
|
key: row.key,
|
|
@@ -4834,13 +5123,13 @@ function donutChart(target, options, env2) {
|
|
|
4834
5123
|
category: row.category,
|
|
4835
5124
|
series: row.series,
|
|
4836
5125
|
value: valueOf(record),
|
|
4837
|
-
share:
|
|
5126
|
+
share: span2,
|
|
4838
5127
|
start: start * TAU3,
|
|
4839
|
-
end: (start +
|
|
5128
|
+
end: (start + span2) * TAU3
|
|
4840
5129
|
};
|
|
4841
5130
|
return { record, state };
|
|
4842
5131
|
});
|
|
4843
|
-
const labels =
|
|
5132
|
+
const labels = placeLabels2(
|
|
4844
5133
|
f,
|
|
4845
5134
|
now.map(({ state }) => state),
|
|
4846
5135
|
measure
|
|
@@ -4853,7 +5142,7 @@ function donutChart(target, options, env2) {
|
|
|
4853
5142
|
const f = frame2.value;
|
|
4854
5143
|
setAttributes(svg, sizeAttributes(f));
|
|
4855
5144
|
const slices = currentSlices(f);
|
|
4856
|
-
for (const { record, slice, label: label2 } of slices)
|
|
5145
|
+
for (const { record, slice, label: label2 } of slices) show4(record, slice, label2);
|
|
4857
5146
|
const total2 = slices.reduce((sum, { slice }) => sum + slice.value, 0);
|
|
4858
5147
|
drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round(total2, count)), measure));
|
|
4859
5148
|
}
|
|
@@ -4862,7 +5151,7 @@ function donutChart(target, options, env2) {
|
|
|
4862
5151
|
return counted.text;
|
|
4863
5152
|
}
|
|
4864
5153
|
function land() {
|
|
4865
|
-
ring = ring.filter(
|
|
5154
|
+
ring = ring.filter(drawn2);
|
|
4866
5155
|
from = ring;
|
|
4867
5156
|
for (const record of ring) {
|
|
4868
5157
|
record.turn.set(1);
|
|
@@ -4872,7 +5161,7 @@ function donutChart(target, options, env2) {
|
|
|
4872
5161
|
count = void 0;
|
|
4873
5162
|
counted = void 0;
|
|
4874
5163
|
setAttributes(svg, sizeAttributes(laidOut.frame));
|
|
4875
|
-
laidOut.slices.forEach((slice, i) =>
|
|
5164
|
+
laidOut.slices.forEach((slice, i) => show4(records.get(slice.key), slice, laidOut.labels[i]));
|
|
4876
5165
|
drawCenter(laidOut.center);
|
|
4877
5166
|
dirty = false;
|
|
4878
5167
|
}
|
|
@@ -5018,7 +5307,8 @@ function donutChart(target, options, env2) {
|
|
|
5018
5307
|
const record = records.get(key);
|
|
5019
5308
|
if (record) showTooltip(record);
|
|
5020
5309
|
},
|
|
5021
|
-
hide: () => tooltip.hide()
|
|
5310
|
+
hide: () => tooltip.hide(),
|
|
5311
|
+
element: () => tooltip.element()
|
|
5022
5312
|
}
|
|
5023
5313
|
});
|
|
5024
5314
|
const unwatchHoverDuration = watchHoverDuration(svg, motion2);
|
|
@@ -5090,6 +5380,7 @@ function donutChart(target, options, env2) {
|
|
|
5090
5380
|
leaving,
|
|
5091
5381
|
input,
|
|
5092
5382
|
onScreen,
|
|
5383
|
+
data: "data" in next,
|
|
5093
5384
|
...swapping ? {
|
|
5094
5385
|
swap: (diff) => {
|
|
5095
5386
|
const entering = new Set(diff.entering);
|
|
@@ -5249,9 +5540,9 @@ var FIELDS = {
|
|
|
5249
5540
|
second: { hour: "numeric", minute: "2-digit", second: "2-digit" },
|
|
5250
5541
|
millisecond: { hour: "numeric", minute: "2-digit", second: "2-digit", ...FRACTION }
|
|
5251
5542
|
};
|
|
5252
|
-
function timeStep(
|
|
5253
|
-
for (const step2 of STEPS) if (LONGEST[step2.unit] * step2.count >=
|
|
5254
|
-
return { unit: "year", count: Math.max(1, niceStep(
|
|
5543
|
+
function timeStep(span2) {
|
|
5544
|
+
for (const step2 of STEPS) if (LONGEST[step2.unit] * step2.count >= span2) return step2;
|
|
5545
|
+
return { unit: "year", count: Math.max(1, niceStep(span2 / LONGEST.year)) };
|
|
5255
5546
|
}
|
|
5256
5547
|
function timeTicks(lo, hi, zone) {
|
|
5257
5548
|
const word = tickWording(zone);
|
|
@@ -5277,9 +5568,9 @@ function boundaries(lo, hi, step2, zone) {
|
|
|
5277
5568
|
const grain = unit === "hour" ? 15 * MINUTE : LONGEST[unit];
|
|
5278
5569
|
let t = lo - start.ms - (unit === "second" ? 0 : start.seconds * SECOND) - (unit === "hour" ? start.minutes % 15 * MINUTE : 0);
|
|
5279
5570
|
for (; t < hi; t += grain) {
|
|
5280
|
-
const
|
|
5281
|
-
const whole = unit !== "hour" ||
|
|
5282
|
-
const field = unit === "second" ?
|
|
5571
|
+
const parts2 = partsOf(t, zone);
|
|
5572
|
+
const whole = unit !== "hour" || parts2.minutes === 0;
|
|
5573
|
+
const field = unit === "second" ? parts2.seconds : unit === "minute" ? parts2.minutes : parts2.hours;
|
|
5283
5574
|
if (t > lo && whole && field % count === 0) out.push(t);
|
|
5284
5575
|
}
|
|
5285
5576
|
return out;
|
|
@@ -5297,6 +5588,21 @@ function boundaries(lo, hi, step2, zone) {
|
|
|
5297
5588
|
}
|
|
5298
5589
|
return out;
|
|
5299
5590
|
}
|
|
5591
|
+
function monthsOn(t, months, zone) {
|
|
5592
|
+
const { year, month, date, hours, minutes, seconds, ms } = partsOf(t, zone);
|
|
5593
|
+
const last = /* @__PURE__ */ new Date(0);
|
|
5594
|
+
last.setUTCFullYear(year, month + months + 1, 0);
|
|
5595
|
+
const day = Math.min(date, last.getUTCDate());
|
|
5596
|
+
const d = /* @__PURE__ */ new Date(0);
|
|
5597
|
+
if (zone === "UTC") {
|
|
5598
|
+
d.setUTCFullYear(year, month + months, day);
|
|
5599
|
+
d.setUTCHours(hours, minutes, seconds, ms);
|
|
5600
|
+
} else {
|
|
5601
|
+
d.setFullYear(year, month + months, day);
|
|
5602
|
+
d.setHours(hours, minutes, seconds, ms);
|
|
5603
|
+
}
|
|
5604
|
+
return d.getTime();
|
|
5605
|
+
}
|
|
5300
5606
|
function timeLevel(t, zone) {
|
|
5301
5607
|
const { ms, seconds, minutes, hours, date, month } = partsOf(t, zone);
|
|
5302
5608
|
if (ms !== 0) return "millisecond";
|
|
@@ -5362,7 +5668,7 @@ function lineEncoding(options) {
|
|
|
5362
5668
|
if (!Array.isArray(series) || series.length === 0) throw new TypeError("lineChart needs series: the numeric fields to draw as lines.");
|
|
5363
5669
|
const seen = /* @__PURE__ */ new Set();
|
|
5364
5670
|
for (const field of series) {
|
|
5365
|
-
if (typeof field !== "string" || field === "") throw new TypeError(`lineChart: each series must be a field name, got ${
|
|
5671
|
+
if (typeof field !== "string" || field === "") throw new TypeError(`lineChart: each series must be a field name, got ${show2(field)}.`);
|
|
5366
5672
|
if (seen.has(field)) throw new TypeError(`lineChart: "${field}" appears twice in series.`);
|
|
5367
5673
|
seen.add(field);
|
|
5368
5674
|
}
|
|
@@ -5370,7 +5676,7 @@ function lineEncoding(options) {
|
|
|
5370
5676
|
const labels = options.labels;
|
|
5371
5677
|
if (labels !== void 0 && labels !== false && typeof labels !== "function") throw new TypeError("lineChart: labels must be false or a function that returns a line's end label.");
|
|
5372
5678
|
const timeZone = options.timeZone ?? "UTC";
|
|
5373
|
-
if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${
|
|
5679
|
+
if (!TIME_ZONES.includes(timeZone)) throw new TypeError(`lineChart: timeZone must be "UTC" or "local", got ${show2(timeZone)}.`);
|
|
5374
5680
|
const xFormat = options.xFormat;
|
|
5375
5681
|
if (xFormat !== void 0 && typeof xFormat !== "function") throw new TypeError("lineChart: xFormat must be a function that turns an x into text.");
|
|
5376
5682
|
return {
|
|
@@ -5386,7 +5692,7 @@ function layoutLines(input) {
|
|
|
5386
5692
|
const height = input.height ?? HEIGHT2;
|
|
5387
5693
|
const { rows: rows2, time } = prepareRows2(input);
|
|
5388
5694
|
const series = input.encoding.series.map((s) => s.series);
|
|
5389
|
-
const domain = niceDomain(rows2.flatMap((row) => row.values.
|
|
5695
|
+
const domain = niceDomain(rows2.flatMap((row) => row.values.flatMap((v) => v.value === void 0 ? [] : [v.value])));
|
|
5390
5696
|
const yTexts = domain.ticks.map(input.format);
|
|
5391
5697
|
const xLo = rows2[0]?.x ?? 0;
|
|
5392
5698
|
const xHi = rows2[rows2.length - 1]?.x ?? 0;
|
|
@@ -5403,7 +5709,7 @@ function layoutLines(input) {
|
|
|
5403
5709
|
};
|
|
5404
5710
|
const decimalsBy = {};
|
|
5405
5711
|
for (const name of series) decimalsBy[name] = 0;
|
|
5406
|
-
for (const row of rows2) for (const v of row.values) decimalsBy[v.series] = Math.max(decimalsBy[v.series], decimals(v.value));
|
|
5712
|
+
for (const row of rows2) for (const v of row.values) if (v.value !== void 0) decimalsBy[v.series] = Math.max(decimalsBy[v.series], decimals(v.value));
|
|
5407
5713
|
const xTicks = xValues.map((value, i) => placeXTick(frame2, value, xTexts[i]));
|
|
5408
5714
|
return {
|
|
5409
5715
|
width,
|
|
@@ -5439,34 +5745,60 @@ function placeLines(frame2, rows2, series, through, time = false, labels) {
|
|
|
5439
5745
|
const datas = /* @__PURE__ */ new Map();
|
|
5440
5746
|
const related = (own2) => (name) => name === own2 ? void 0 : datas.get(name);
|
|
5441
5747
|
const traced = series.map((name) => {
|
|
5442
|
-
const
|
|
5443
|
-
|
|
5748
|
+
const has = (row) => !row.missing?.has(name);
|
|
5749
|
+
const vertices = [];
|
|
5750
|
+
let gap = false;
|
|
5751
|
+
for (const row of shown) {
|
|
5752
|
+
if (!has(row)) gap = vertices.length > 0;
|
|
5753
|
+
else {
|
|
5754
|
+
vertices.push({ at: row.x, value: row.values[name] ?? 0, datum: row.datum, gapBefore: gap });
|
|
5755
|
+
gap = false;
|
|
5756
|
+
}
|
|
5757
|
+
}
|
|
5758
|
+
if (share !== void 0 && has(end) && has(next)) {
|
|
5444
5759
|
const from = end.values[name] ?? 0;
|
|
5445
|
-
vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from) });
|
|
5760
|
+
vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from), datum: end.datum, gapBefore: false });
|
|
5446
5761
|
}
|
|
5447
|
-
|
|
5762
|
+
const points = vertices.length > 0 ? vertices.map((v) => ({ x: at.x(v.at), y: at.y(v.value) })) : [{ x: at.x(first.x), y: at.y(first.values[name] ?? 0) }];
|
|
5763
|
+
return { name, vertices, points };
|
|
5448
5764
|
});
|
|
5765
|
+
const named = traced.filter(({ vertices }) => vertices.length > 0);
|
|
5449
5766
|
const placed2 = labels ? placeEndLabels(
|
|
5450
5767
|
frame2,
|
|
5451
|
-
|
|
5768
|
+
named.map(({ name, vertices, points }) => ({ ...points[points.length - 1], text: labels.text(name, vertices[vertices.length - 1].value) }))
|
|
5452
5769
|
) : [];
|
|
5453
|
-
const lines = traced.map(({ name, vertices, points }
|
|
5454
|
-
const
|
|
5770
|
+
const lines = traced.map(({ name, vertices, points }) => {
|
|
5771
|
+
const tip = points[points.length - 1];
|
|
5772
|
+
const label2 = labels ? placed2[named.findIndex((line2) => line2.name === name)] ?? { x: tip.x + LABEL_GAP, y: tip.y + VALUE_SIZE3 * CENTRE3, anchor: "start", text: "" } : void 0;
|
|
5455
5773
|
const labelBounds = labels ? label2 && label2.text !== "" ? [textBox(label2, labels.measure, "ec-value", VALUE_SIZE3)] : [] : void 0;
|
|
5456
|
-
const
|
|
5774
|
+
const breaks = vertices.flatMap((v, j) => v.gapBefore ? [j] : []);
|
|
5775
|
+
const geometry = describe.line({ key: name, series: name, points, width: LINE_WIDTH, ...breaks.length > 0 ? { breaks } : {}, ...labelBounds ? { labelBounds } : {} });
|
|
5457
5776
|
let distance3 = 0;
|
|
5458
5777
|
const samples = vertices.map((v, j) => {
|
|
5459
5778
|
if (j > 0) distance3 += Math.hypot(points[j].x - points[j - 1].x, points[j].y - points[j - 1].y);
|
|
5460
5779
|
const t = geometry.length > 0 ? j === vertices.length - 1 ? 1 : Math.min(1, distance3 / geometry.length) : 0;
|
|
5461
|
-
return { t, value: v.value, at: sampleAt(v.at, time) };
|
|
5780
|
+
return { t, value: v.value, at: sampleAt(v.at, time), ...v.gapBefore ? { gapBefore: true } : {} };
|
|
5462
5781
|
});
|
|
5463
|
-
const
|
|
5782
|
+
const last2 = vertices[vertices.length - 1];
|
|
5783
|
+
const data = { datum: last2 ? last2.datum : end.datum, samples, related: related(name) };
|
|
5464
5784
|
datas.set(name, data);
|
|
5465
|
-
|
|
5466
|
-
return { series: name, geometry, data, end: { ...points[points.length - 1], value: tip.value }, label: label2 };
|
|
5785
|
+
return { series: name, geometry, data, end: { ...tip, value: last2 ? last2.value : first.values[name] ?? 0 }, label: label2 };
|
|
5467
5786
|
});
|
|
5468
5787
|
return lines;
|
|
5469
5788
|
}
|
|
5789
|
+
function loneValues(rows2, series) {
|
|
5790
|
+
const lone = /* @__PURE__ */ new Set();
|
|
5791
|
+
if (!rows2.some((row) => row.missing !== void 0 && row.missing.size > 0)) return lone;
|
|
5792
|
+
const has = (row, name) => row !== void 0 && !row.missing?.has(name);
|
|
5793
|
+
rows2.forEach((row, i) => {
|
|
5794
|
+
for (const name of series) {
|
|
5795
|
+
const before = rows2[i - 1];
|
|
5796
|
+
const after = rows2[i + 1];
|
|
5797
|
+
if (has(row, name) && !has(before, name) && !has(after, name) && (before !== void 0 || after !== void 0)) lone.add(pointKey(name, row.key));
|
|
5798
|
+
}
|
|
5799
|
+
});
|
|
5800
|
+
return lone;
|
|
5801
|
+
}
|
|
5470
5802
|
function pointKey(series, row) {
|
|
5471
5803
|
return `${series}@${row}`;
|
|
5472
5804
|
}
|
|
@@ -5474,7 +5806,7 @@ function placePoints(frame2, row, series, time = false) {
|
|
|
5474
5806
|
const at = positions(frame2);
|
|
5475
5807
|
const x = at.x(row.x);
|
|
5476
5808
|
const datas = /* @__PURE__ */ new Map();
|
|
5477
|
-
return series.map((name) => {
|
|
5809
|
+
return series.filter((name) => !row.missing?.has(name)).map((name) => {
|
|
5478
5810
|
const value = row.values[name] ?? 0;
|
|
5479
5811
|
const key = pointKey(name, row.key);
|
|
5480
5812
|
const data = { datum: row.datum, samples: [{ t: 0, value, at: sampleAt(row.x, time) }], related: (other) => other === name ? void 0 : datas.get(other) };
|
|
@@ -5508,8 +5840,8 @@ function spread(values, gap, min, max) {
|
|
|
5508
5840
|
const clusters = [];
|
|
5509
5841
|
const place = (members) => {
|
|
5510
5842
|
const mean = members.reduce((sum, m) => sum + m.value, 0) / members.length;
|
|
5511
|
-
const
|
|
5512
|
-
return Math.max(min, Math.min(max -
|
|
5843
|
+
const span2 = (members.length - 1) * gap;
|
|
5844
|
+
return Math.max(min, Math.min(max - span2, mean - span2 / 2));
|
|
5513
5845
|
};
|
|
5514
5846
|
for (const item of order) {
|
|
5515
5847
|
clusters.push({ members: [item], start: place([item]) });
|
|
@@ -5581,7 +5913,34 @@ function prepareRows2({ data, encoding }) {
|
|
|
5581
5913
|
}
|
|
5582
5914
|
}
|
|
5583
5915
|
const word = xWording(encoding, time, read.map((row) => row.x));
|
|
5584
|
-
|
|
5916
|
+
const levels = levelsOf(read, encoding.series.length);
|
|
5917
|
+
return {
|
|
5918
|
+
rows: read.map((row, i) => ({ ...row, label: word(row.x), missing: new Set(row.values.flatMap((v) => v.value === void 0 ? [v.series] : [])), levels: levels[i] })),
|
|
5919
|
+
time
|
|
5920
|
+
};
|
|
5921
|
+
}
|
|
5922
|
+
function levelsOf(rows2, count) {
|
|
5923
|
+
const levels = rows2.map(() => ({}));
|
|
5924
|
+
for (let s = 0; s < count; s++) {
|
|
5925
|
+
let before = -1;
|
|
5926
|
+
let after = -1;
|
|
5927
|
+
rows2.forEach((row, i) => {
|
|
5928
|
+
const { series, value } = row.values[s];
|
|
5929
|
+
if (value !== void 0) {
|
|
5930
|
+
levels[i][series] = value;
|
|
5931
|
+
before = i;
|
|
5932
|
+
return;
|
|
5933
|
+
}
|
|
5934
|
+
if (after <= i) {
|
|
5935
|
+
after = i + 1;
|
|
5936
|
+
while (after < rows2.length && rows2[after].values[s].value === void 0) after++;
|
|
5937
|
+
}
|
|
5938
|
+
const a = rows2[before]?.values[s].value;
|
|
5939
|
+
const b = rows2[after]?.values[s].value;
|
|
5940
|
+
levels[i][series] = a !== void 0 && b !== void 0 ? a + (row.x - rows2[before].x) / (rows2[after].x - rows2[before].x) * (b - a) : a ?? b ?? 0;
|
|
5941
|
+
});
|
|
5942
|
+
}
|
|
5943
|
+
return levels;
|
|
5585
5944
|
}
|
|
5586
5945
|
function xOf(x, index, time) {
|
|
5587
5946
|
if (x instanceof Date) {
|
|
@@ -5592,9 +5951,9 @@ function xOf(x, index, time) {
|
|
|
5592
5951
|
}
|
|
5593
5952
|
if (time) {
|
|
5594
5953
|
if (typeof x === "number") throw new TypeError(`lineChart: x must be all numbers or all Dates, but row 0's is a Date and row ${index}'s a number.`);
|
|
5595
|
-
throw new TypeError(`lineChart: x must be a valid Date, got ${
|
|
5954
|
+
throw new TypeError(`lineChart: x must be a valid Date, got ${show2(x)} in row ${index}.`);
|
|
5596
5955
|
}
|
|
5597
|
-
if (typeof x !== "number" || !Number.isFinite(x)) throw new RangeError(`lineChart: x must be a finite number, got ${
|
|
5956
|
+
if (typeof x !== "number" || !Number.isFinite(x)) throw new RangeError(`lineChart: x must be a finite number, got ${show2(x)} in row ${index}.`);
|
|
5598
5957
|
return x;
|
|
5599
5958
|
}
|
|
5600
5959
|
function xWording(encoding, time, xs) {
|
|
@@ -5607,12 +5966,14 @@ function sampleAt(x, time) {
|
|
|
5607
5966
|
}
|
|
5608
5967
|
function numberOf3(value, series, key) {
|
|
5609
5968
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
5610
|
-
|
|
5969
|
+
if (value === null || value === void 0) return void 0;
|
|
5970
|
+
throw new RangeError(`lineChart: "${series}" for "${key}" must be a finite number, or null or undefined where it has no value, got ${show2(value)}.`);
|
|
5611
5971
|
}
|
|
5612
5972
|
function distinctLabels(rows2, label2) {
|
|
5613
5973
|
const shapes = /* @__PURE__ */ new Map();
|
|
5614
5974
|
for (const row of rows2) {
|
|
5615
5975
|
for (const { series, value } of row.values) {
|
|
5976
|
+
if (value === void 0) continue;
|
|
5616
5977
|
const text2 = label2(series, value);
|
|
5617
5978
|
const shape = text2.replace(/\d/g, "0");
|
|
5618
5979
|
if (!shapes.has(shape)) shapes.set(shape, text2);
|
|
@@ -5627,7 +5988,7 @@ function accessor3(option) {
|
|
|
5627
5988
|
if (typeof option === "function") return option;
|
|
5628
5989
|
return (d) => d[option];
|
|
5629
5990
|
}
|
|
5630
|
-
var
|
|
5991
|
+
var show2 = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
5631
5992
|
|
|
5632
5993
|
// src/charts/line.ts
|
|
5633
5994
|
var STAGE3 = 500;
|
|
@@ -5782,12 +6143,13 @@ function lineChart(target, options, env2) {
|
|
|
5782
6143
|
column,
|
|
5783
6144
|
hit: svgElement("rect", { class: "ec-hit" }, column),
|
|
5784
6145
|
x: animated(row.x, interpolateNumber, env3),
|
|
5785
|
-
values: animated(
|
|
6146
|
+
values: animated(row.levels, interpolateRecord, env3),
|
|
5786
6147
|
presence: animated(entering ? 0 : 1, interpolateNumber, env3),
|
|
5787
6148
|
anchor: void 0,
|
|
5788
6149
|
points: [],
|
|
5789
6150
|
leaving: false,
|
|
5790
|
-
shown: true
|
|
6151
|
+
shown: true,
|
|
6152
|
+
px: 0
|
|
5791
6153
|
};
|
|
5792
6154
|
byColumn.set(column, record);
|
|
5793
6155
|
return record;
|
|
@@ -5834,7 +6196,7 @@ function lineChart(target, options, env2) {
|
|
|
5834
6196
|
};
|
|
5835
6197
|
return record;
|
|
5836
6198
|
}
|
|
5837
|
-
const
|
|
6199
|
+
const drawn2 = (record) => findMark(record.key) === record;
|
|
5838
6200
|
const livePoints = (record) => record.points.filter((point) => points.get(point.key) === point);
|
|
5839
6201
|
const leavingLines = () => [...leaving.values()].filter((record) => record.kind === "line");
|
|
5840
6202
|
const currentFrame = () => ({ scale: scale2.value, box: box.value });
|
|
@@ -5859,7 +6221,7 @@ function lineChart(target, options, env2) {
|
|
|
5859
6221
|
const drawnRows = [...rowOrder, ...[...leavingRows.values()].filter((record) => record.presence.value > 0 && record.anchor)];
|
|
5860
6222
|
return drawnRows.map((record) => {
|
|
5861
6223
|
const { x, values } = stateOf(record);
|
|
5862
|
-
return { record, state: { key: record.key, datum: record.row.datum, x, values } };
|
|
6224
|
+
return { record, state: { key: record.key, datum: record.row.datum, x, values, missing: record.row.missing } };
|
|
5863
6225
|
}).sort((a, b) => a.state.x - b.state.x);
|
|
5864
6226
|
}
|
|
5865
6227
|
function draw() {
|
|
@@ -5871,8 +6233,9 @@ function lineChart(target, options, env2) {
|
|
|
5871
6233
|
paintLines(frame2, states.map((s) => s.state));
|
|
5872
6234
|
for (const { record, state } of states) {
|
|
5873
6235
|
const placed2 = new Map(placePoints(frame2, state, record.points.map((point) => point.series), laidOut.time).map((point) => [point.key, point]));
|
|
5874
|
-
showAll(record.points.filter(
|
|
6236
|
+
showAll(record.points.filter(drawn2).flatMap((point) => placed2.has(point.key) ? [{ record: point, placed: placed2.get(point.key) }] : []));
|
|
5875
6237
|
}
|
|
6238
|
+
paintAlone(states.map((s) => s.state));
|
|
5876
6239
|
paintColumns(frame2, states);
|
|
5877
6240
|
followHover();
|
|
5878
6241
|
}
|
|
@@ -5891,7 +6254,7 @@ function lineChart(target, options, env2) {
|
|
|
5891
6254
|
leavingRows.clear();
|
|
5892
6255
|
for (const record of rowOrder) {
|
|
5893
6256
|
record.anchor = void 0;
|
|
5894
|
-
record.points = record.points.filter(
|
|
6257
|
+
record.points = record.points.filter(drawn2);
|
|
5895
6258
|
}
|
|
5896
6259
|
for (const [ticks, placedTicks] of [
|
|
5897
6260
|
[yTicks, laidOut.yTicks],
|
|
@@ -5929,6 +6292,7 @@ function lineChart(target, options, env2) {
|
|
|
5929
6292
|
paintLabels(new Map(lineOrder.flatMap((line2) => placed2.lines.has(line2.series) ? [[line2, placed2.lines.get(line2.series)]] : [])));
|
|
5930
6293
|
const states = rowOrder.map((record) => ({ record, state: restState(record.row) }));
|
|
5931
6294
|
for (const { record } of states) settle(livePoints(record), (point) => placed2.points.get(point.key));
|
|
6295
|
+
paintAlone(states.map((s) => s.state));
|
|
5932
6296
|
paintColumns(frame2, states);
|
|
5933
6297
|
followHover();
|
|
5934
6298
|
dirty = false;
|
|
@@ -5975,7 +6339,7 @@ function lineChart(target, options, env2) {
|
|
|
5975
6339
|
record.shown = placed2;
|
|
5976
6340
|
const { geometry } = placed2;
|
|
5977
6341
|
paint(record, seriesColors(colors.slot(record.series)), { visible: geometry.length >= VISIBLE2, open: { width: geometry.thickness } });
|
|
5978
|
-
setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y });
|
|
6342
|
+
setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y, visibility: placed2.data.samples.length === 0 ? "hidden" : void 0 });
|
|
5979
6343
|
const presence = record.presence.value;
|
|
5980
6344
|
setAttributes(record.group, { opacity: presence < 1 ? presence : void 0 });
|
|
5981
6345
|
if (moved) runner.change(geometry, placed2.data);
|
|
@@ -5997,17 +6361,27 @@ function lineChart(target, options, env2) {
|
|
|
5997
6361
|
record.handle.repaint();
|
|
5998
6362
|
if (before && recolored) surface.recolor(record.key);
|
|
5999
6363
|
}
|
|
6364
|
+
let anyAlone = false;
|
|
6365
|
+
function paintAlone(states) {
|
|
6366
|
+
const lone = loneValues(states, laidOut.series);
|
|
6367
|
+
if (lone.size === 0 && !anyAlone) return;
|
|
6368
|
+
for (const point of points.values()) point.group.classList.toggle("ec-alone", lone.has(point.key));
|
|
6369
|
+
anyAlone = lone.size > 0;
|
|
6370
|
+
}
|
|
6000
6371
|
function paintColumns(frame2, states) {
|
|
6001
6372
|
const { x } = positions(frame2);
|
|
6002
6373
|
const shown = states.filter(({ record }) => revealed(record));
|
|
6003
6374
|
const columns = placeColumns(frame2, shown.map(({ state }) => x(state.x)));
|
|
6004
|
-
shown.forEach(({ record }, i) =>
|
|
6375
|
+
shown.forEach(({ record, state }, i) => {
|
|
6376
|
+
setAttributes(record.hit, { ...columns[i] });
|
|
6377
|
+
record.px = x(state.x);
|
|
6378
|
+
});
|
|
6005
6379
|
const visible = new Set(shown.map(({ record }) => record));
|
|
6006
6380
|
for (const record of [...rowOrder, ...leavingRows.values()]) {
|
|
6007
|
-
const
|
|
6008
|
-
if (record.shown !==
|
|
6009
|
-
record.shown =
|
|
6010
|
-
setAttributes(record.column, { visibility:
|
|
6381
|
+
const show4 = visible.has(record);
|
|
6382
|
+
if (record.shown !== show4) {
|
|
6383
|
+
record.shown = show4;
|
|
6384
|
+
setAttributes(record.column, { visibility: show4 ? void 0 : "hidden", "aria-hidden": record.leaving ? "true" : void 0 });
|
|
6011
6385
|
}
|
|
6012
6386
|
const hidden2 = !revealed(record);
|
|
6013
6387
|
for (const point of record.points) {
|
|
@@ -6020,10 +6394,9 @@ function lineChart(target, options, env2) {
|
|
|
6020
6394
|
}
|
|
6021
6395
|
function showHover(key) {
|
|
6022
6396
|
const record = rows2.get(key);
|
|
6023
|
-
|
|
6024
|
-
const
|
|
6025
|
-
|
|
6026
|
-
const x = first.shown.geometry.center.x;
|
|
6397
|
+
if (!record || !revealed(record)) return;
|
|
6398
|
+
const marks = livePoints(record);
|
|
6399
|
+
const x = marks[0]?.shown.geometry.center.x ?? record.px;
|
|
6027
6400
|
setAttributes(crosshair, { ...placeCrosshair(drawnFrame, x), visibility: void 0 });
|
|
6028
6401
|
const ys = marks.map((point) => {
|
|
6029
6402
|
const { transform } = point.handle.style;
|
|
@@ -6031,19 +6404,26 @@ function lineChart(target, options, env2) {
|
|
|
6031
6404
|
return (transform ? matrix.apply(transform, center) : center).y;
|
|
6032
6405
|
});
|
|
6033
6406
|
const { row } = record;
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
row,
|
|
6037
|
-
() => summaryContent(row.label, labelled2(row.values, current), format(current), { total: false })
|
|
6038
|
-
);
|
|
6407
|
+
const at = ys.length > 0 ? { top: Math.min(...ys) - DOT_RADIUS, bottom: Math.max(...ys) + DOT_RADIUS } : { top: drawnFrame.box.top, bottom: drawnFrame.box.top };
|
|
6408
|
+
tooltip.showAt({ x, ...at }, row, () => summary(row, current));
|
|
6039
6409
|
}
|
|
6040
6410
|
function hideHover() {
|
|
6041
6411
|
crosshair.setAttribute("visibility", "hidden");
|
|
6042
6412
|
tooltip.hide();
|
|
6043
6413
|
}
|
|
6414
|
+
let ringLine;
|
|
6044
6415
|
function drawRing(key) {
|
|
6045
6416
|
const record = key === void 0 ? void 0 : rows2.get(key);
|
|
6046
|
-
const
|
|
6417
|
+
const live = record !== void 0 && revealed(record);
|
|
6418
|
+
const marks = live ? livePoints(record) : [];
|
|
6419
|
+
if (live && marks.length === 0) {
|
|
6420
|
+
ringLine ?? (ringLine = svgElement("line", { class: "ec-focus-ring", "stroke-width": RING3 }, ring));
|
|
6421
|
+
if (ring.childElementCount > 1 || ring.firstElementChild !== ringLine) ring.replaceChildren(ringLine);
|
|
6422
|
+
setAttributes(ringLine, placeCrosshair(drawnFrame, record.px));
|
|
6423
|
+
ring.removeAttribute("visibility");
|
|
6424
|
+
return;
|
|
6425
|
+
}
|
|
6426
|
+
ringLine?.remove();
|
|
6047
6427
|
while (ring.childElementCount > marks.length) ring.lastElementChild.remove();
|
|
6048
6428
|
marks.forEach((point, i) => {
|
|
6049
6429
|
let group = ring.children[i];
|
|
@@ -6084,6 +6464,17 @@ function lineChart(target, options, env2) {
|
|
|
6084
6464
|
return record !== void 0 && revealed(record);
|
|
6085
6465
|
},
|
|
6086
6466
|
order: () => rowOrder.filter(revealed).map((record) => record.key),
|
|
6467
|
+
// On a time axis a page is a calendar month in its zone: the first x a month or more on, or back,
|
|
6468
|
+
// or the last one that way. On numbers it's the keyboard's own.
|
|
6469
|
+
page(key, by) {
|
|
6470
|
+
const from = rows2.get(key);
|
|
6471
|
+
if (!laidOut.time || !from) return void 0;
|
|
6472
|
+
const stops = rowOrder.filter(revealed);
|
|
6473
|
+
const to = monthsOn(from.row.x, by, lineEncoding(current).timeZone);
|
|
6474
|
+
if (by > 0) return (stops.find((record) => record.row.x >= to) ?? stops[stops.length - 1])?.key;
|
|
6475
|
+
for (let i = stops.length - 1; i >= 0; i--) if (stops[i].row.x <= to) return stops[i].key;
|
|
6476
|
+
return stops[0]?.key;
|
|
6477
|
+
},
|
|
6087
6478
|
marks: (key) => {
|
|
6088
6479
|
const record = rows2.get(key);
|
|
6089
6480
|
return record ? livePoints(record).map((point) => point.key) : [];
|
|
@@ -6095,7 +6486,7 @@ function lineChart(target, options, env2) {
|
|
|
6095
6486
|
return record && onScreen(record);
|
|
6096
6487
|
},
|
|
6097
6488
|
ring: drawRing,
|
|
6098
|
-
tooltip: { show: showHover, hide: hideHover }
|
|
6489
|
+
tooltip: { show: showHover, hide: hideHover, element: () => tooltip.element() }
|
|
6099
6490
|
});
|
|
6100
6491
|
const syncLegend = () => legend.update(
|
|
6101
6492
|
laidOut.series.map((series) => ({ series, label: seriesLabel(current.seriesLabels, series) })),
|
|
@@ -6109,7 +6500,7 @@ function lineChart(target, options, env2) {
|
|
|
6109
6500
|
category: typeof opts.x === "string" ? opts.x : void 0,
|
|
6110
6501
|
series: next.series,
|
|
6111
6502
|
label: (series) => seriesLabel(opts.seriesLabels, series),
|
|
6112
|
-
rows: next.rows.map((row) => ({ key: row.key, category: row.label, datum: row.datum, index: row.index, values: row.values, total: total(row.values) })),
|
|
6503
|
+
rows: next.rows.map((row) => ({ key: row.key, category: row.label, datum: row.datum, index: row.index, values: present(row.values), missing: row.missing, total: total(row.values) })),
|
|
6113
6504
|
format: format(opts),
|
|
6114
6505
|
total: false
|
|
6115
6506
|
});
|
|
@@ -6139,8 +6530,8 @@ function lineChart(target, options, env2) {
|
|
|
6139
6530
|
}
|
|
6140
6531
|
const key = (record) => record.key;
|
|
6141
6532
|
try {
|
|
6142
|
-
const
|
|
6143
|
-
if (
|
|
6533
|
+
const said2 = option({ text: text2, changed: values.map(key), added: added.map(key), removed: removed.map(key) });
|
|
6534
|
+
if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
|
|
6144
6535
|
} catch (error) {
|
|
6145
6536
|
report(error);
|
|
6146
6537
|
}
|
|
@@ -6154,17 +6545,19 @@ function lineChart(target, options, env2) {
|
|
|
6154
6545
|
const changes = { changed: [], added: [], removed: [] };
|
|
6155
6546
|
const before = rowOrder;
|
|
6156
6547
|
const was = new Map(before.map((record) => [record, record.row]));
|
|
6548
|
+
const nextRows = new Map(next.rows.map((row) => [row.key, row]));
|
|
6157
6549
|
const exitingLines = lineOrder.filter((line2) => !series.includes(line2.series));
|
|
6158
6550
|
const exitingPoints = [];
|
|
6159
6551
|
for (const record of before) {
|
|
6160
6552
|
const goes = !keys.has(record.key);
|
|
6553
|
+
const missing = nextRows.get(record.key)?.missing;
|
|
6161
6554
|
if (goes) {
|
|
6162
6555
|
rows2.delete(record.key);
|
|
6163
6556
|
record.leaving = true;
|
|
6164
6557
|
leavingRows.set(record.key, record);
|
|
6165
6558
|
changes.removed.push(record);
|
|
6166
6559
|
}
|
|
6167
|
-
for (const point of livePoints(record)) if (goes || !series.includes(point.series)) exitingPoints.push(point);
|
|
6560
|
+
for (const point of livePoints(record)) if (goes || !series.includes(point.series) || missing?.has(point.series)) exitingPoints.push(point);
|
|
6168
6561
|
}
|
|
6169
6562
|
for (const line2 of exitingLines) lines.delete(line2.series);
|
|
6170
6563
|
for (const point of exitingPoints) points.delete(point.key);
|
|
@@ -6183,7 +6576,7 @@ function lineChart(target, options, env2) {
|
|
|
6183
6576
|
leavingRows.delete(row.key);
|
|
6184
6577
|
record.leaving = false;
|
|
6185
6578
|
record.x.set(row.x);
|
|
6186
|
-
record.values.set(
|
|
6579
|
+
record.values.set(row.levels);
|
|
6187
6580
|
rows2.set(row.key, record);
|
|
6188
6581
|
changes.added.push(record);
|
|
6189
6582
|
rowsMoved = true;
|
|
@@ -6213,7 +6606,7 @@ function lineChart(target, options, env2) {
|
|
|
6213
6606
|
});
|
|
6214
6607
|
for (const record of rowOrder) {
|
|
6215
6608
|
const old = stayed.has(record) ? was.get(record) : void 0;
|
|
6216
|
-
const live = series.map((name) => {
|
|
6609
|
+
const live = series.filter((name) => !record.row.missing.has(name)).map((name) => {
|
|
6217
6610
|
const key = pointKey(name, record.key);
|
|
6218
6611
|
const target2 = placed2.points.get(key);
|
|
6219
6612
|
let point = points.get(key);
|
|
@@ -6229,7 +6622,7 @@ function lineChart(target, options, env2) {
|
|
|
6229
6622
|
return point;
|
|
6230
6623
|
});
|
|
6231
6624
|
const kept = new Set(live);
|
|
6232
|
-
record.points = [...live, ...record.points.filter((point) => !kept.has(point) &&
|
|
6625
|
+
record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn2(point))];
|
|
6233
6626
|
}
|
|
6234
6627
|
for (const record of rowOrder) labelColumn(record);
|
|
6235
6628
|
orderElements(
|
|
@@ -6261,7 +6654,7 @@ function lineChart(target, options, env2) {
|
|
|
6261
6654
|
for (const tick of next.xTicks) xTicks.get(tick.value).text = tick.label.text;
|
|
6262
6655
|
const goingLines = leavingLines();
|
|
6263
6656
|
const folding = [...leavingRows.values()];
|
|
6264
|
-
const values = busy(scale2, frame2.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values,
|
|
6657
|
+
const values = busy(scale2, frame2.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((line2) => busy(line2.presence, 1, same)) || goingLines.some((line2) => busy(line2.presence, 0, same));
|
|
6265
6658
|
const positions2 = busy(box, frame2.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));
|
|
6266
6659
|
let first;
|
|
6267
6660
|
let second;
|
|
@@ -6282,7 +6675,7 @@ function lineChart(target, options, env2) {
|
|
|
6282
6675
|
for (const tick of yTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
|
|
6283
6676
|
for (const tick of xTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, second);
|
|
6284
6677
|
for (const record of rowOrder) {
|
|
6285
|
-
move(record.values,
|
|
6678
|
+
move(record.values, record.row.levels, sameFields, first);
|
|
6286
6679
|
move(record.x, record.row.x, same, second);
|
|
6287
6680
|
move(record.presence, 1, same, record.anchor ? second : void 0);
|
|
6288
6681
|
}
|
|
@@ -6340,7 +6733,7 @@ function lineChart(target, options, env2) {
|
|
|
6340
6733
|
rowOrder = laidOut.rows.map((row) => {
|
|
6341
6734
|
const record = createRow(row, false);
|
|
6342
6735
|
rows2.set(row.key, record);
|
|
6343
|
-
record.points = laidOut.series.map((name) => {
|
|
6736
|
+
record.points = laidOut.series.filter((name) => !row.missing.has(name)).map((name) => {
|
|
6344
6737
|
const point = createPoint(record, placed2.points.get(pointKey(name, row.key)));
|
|
6345
6738
|
points.set(point.key, point);
|
|
6346
6739
|
return point;
|
|
@@ -6390,6 +6783,7 @@ function lineChart(target, options, env2) {
|
|
|
6390
6783
|
leaving,
|
|
6391
6784
|
input,
|
|
6392
6785
|
onScreen,
|
|
6786
|
+
data: "data" in next,
|
|
6393
6787
|
...swapping ? {
|
|
6394
6788
|
swap: (diff) => {
|
|
6395
6789
|
const entering = new Set(diff.entering);
|
|
@@ -6462,16 +6856,16 @@ function lineChart(target, options, env2) {
|
|
|
6462
6856
|
});
|
|
6463
6857
|
}
|
|
6464
6858
|
function restState(row) {
|
|
6465
|
-
return { key: row.key, datum: row.datum, x: row.x, values:
|
|
6859
|
+
return { key: row.key, datum: row.datum, x: row.x, values: row.levels, missing: row.missing };
|
|
6466
6860
|
}
|
|
6467
|
-
function
|
|
6468
|
-
return
|
|
6861
|
+
function present(values) {
|
|
6862
|
+
return values.flatMap((v) => v.value === void 0 ? [] : [{ series: v.series, value: v.value }]);
|
|
6469
6863
|
}
|
|
6470
6864
|
function valueIn(row, series) {
|
|
6471
6865
|
return row.values.find((v) => v.series === series)?.value;
|
|
6472
6866
|
}
|
|
6473
6867
|
function total(values) {
|
|
6474
|
-
return values.reduce((sum, v) => sum + v.value, 0);
|
|
6868
|
+
return values.reduce((sum, v) => sum + (v.value ?? 0), 0);
|
|
6475
6869
|
}
|
|
6476
6870
|
function nearest2(order, i, among) {
|
|
6477
6871
|
for (let j = i - 1; j >= 0; j--) if (among.has(order[j])) return order[j];
|
|
@@ -6485,21 +6879,32 @@ function sameData(a, b) {
|
|
|
6485
6879
|
if (a.datum !== b.datum || a.samples.length !== b.samples.length) return false;
|
|
6486
6880
|
return a.samples.every((s, i) => {
|
|
6487
6881
|
const o = b.samples[i];
|
|
6488
|
-
return s.t === o.t && s.value === o.value && sameAt(s.at, o.at);
|
|
6882
|
+
return s.t === o.t && s.value === o.value && sameAt(s.at, o.at) && s.gapBefore === o.gapBefore;
|
|
6489
6883
|
});
|
|
6490
6884
|
}
|
|
6491
6885
|
function sameAt(a, b) {
|
|
6492
6886
|
return a === b || a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
|
|
6493
6887
|
}
|
|
6494
6888
|
function labelled2(values, options) {
|
|
6495
|
-
return values.map((v) => ({ series: v.series, label: seriesLabel(options.seriesLabels, v.series), value: v.value }));
|
|
6889
|
+
return present(values).map((v) => ({ series: v.series, label: seriesLabel(options.seriesLabels, v.series), value: v.value }));
|
|
6890
|
+
}
|
|
6891
|
+
function said(values, options) {
|
|
6892
|
+
const formatted = format(options);
|
|
6893
|
+
return values.map((v) => {
|
|
6894
|
+
const label2 = seriesLabel(options.seriesLabels, v.series);
|
|
6895
|
+
return v.value === void 0 ? `${label2} missing` : `${formatted(v.value)} ${label2}`;
|
|
6896
|
+
});
|
|
6897
|
+
}
|
|
6898
|
+
function summary(row, options) {
|
|
6899
|
+
if (row.missing.size === 0) return summaryContent(row.label, labelled2(row.values, options), format(options), { total: false });
|
|
6900
|
+
return { title: row.label, lines: [said(row.values, options).join(" \xB7 ")] };
|
|
6496
6901
|
}
|
|
6497
6902
|
function namesFor2(options, layout) {
|
|
6498
6903
|
const formatted = format(options);
|
|
6499
6904
|
return new Map(
|
|
6500
6905
|
layout.rows.map((row) => {
|
|
6501
6906
|
const values = labelled2(row.values, options);
|
|
6502
|
-
const text2 = `${row.label}: ${
|
|
6907
|
+
const text2 = `${row.label}: ${said(row.values, options).join(", ")}`;
|
|
6503
6908
|
if (!options.markLabel) return [row.key, text2];
|
|
6504
6909
|
try {
|
|
6505
6910
|
const named = options.markLabel(row.datum, { key: row.key, category: row.label, values, total: total(row.values), format: formatted, text: text2 });
|
|
@@ -6538,20 +6943,20 @@ function baselines(boxes, option) {
|
|
|
6538
6943
|
}
|
|
6539
6944
|
return found;
|
|
6540
6945
|
}
|
|
6541
|
-
function describeRects(key,
|
|
6542
|
-
const box = union(
|
|
6543
|
-
const
|
|
6544
|
-
const order =
|
|
6946
|
+
function describeRects(key, parts2, baseline) {
|
|
6947
|
+
const box = union(parts2.map((part) => part.box));
|
|
6948
|
+
const span2 = spanFrom(box, baseline);
|
|
6949
|
+
const order = parts2.map((part, index) => ({ index, ...span2(part.box) })).sort((a, b) => a.near - b.near || a.far - b.far || a.index - b.index);
|
|
6545
6950
|
let reached = 0;
|
|
6546
6951
|
let gap = Infinity;
|
|
6547
6952
|
const segments = order.map(({ index, near, far }) => {
|
|
6548
6953
|
if (reached > 0 && far > near) gap = Math.min(gap, near - reached);
|
|
6549
6954
|
const size2 = Math.max(0, far - reached);
|
|
6550
6955
|
reached = Math.max(reached, far);
|
|
6551
|
-
return { series:
|
|
6956
|
+
return { series: parts2[index].series, size: size2 };
|
|
6552
6957
|
});
|
|
6553
|
-
const tip =
|
|
6554
|
-
const single =
|
|
6958
|
+
const tip = parts2[order[order.length - 1].index];
|
|
6959
|
+
const single = parts2.length === 1 ? parts2[0].series : void 0;
|
|
6555
6960
|
const geometry = describe.bar({
|
|
6556
6961
|
key,
|
|
6557
6962
|
...single === void 0 ? {} : { series: single },
|
|
@@ -6776,13 +7181,13 @@ function round3(value) {
|
|
|
6776
7181
|
}
|
|
6777
7182
|
|
|
6778
7183
|
// src/charts/adapter/host-style.ts
|
|
6779
|
-
function hostMarkHandle(
|
|
7184
|
+
function hostMarkHandle(parts2, edits, halos) {
|
|
6780
7185
|
let style = {};
|
|
6781
7186
|
let hot = false;
|
|
6782
7187
|
const halo = maskedHalo();
|
|
6783
7188
|
const repaint = () => {
|
|
6784
7189
|
const { transform, opacity, emphasis } = style;
|
|
6785
|
-
for (const part of
|
|
7190
|
+
for (const part of parts2()) {
|
|
6786
7191
|
const { element, colors } = part;
|
|
6787
7192
|
const moved = transform && part.parentInverse ? matrix.multiply(part.parentInverse, transform, part.parent, ownTransform(element)) : void 0;
|
|
6788
7193
|
edits.style(element, "transform", moved && cssMatrix(moved));
|
|
@@ -6797,7 +7202,7 @@ function hostMarkHandle(parts, edits, halos) {
|
|
|
6797
7202
|
paintHalo();
|
|
6798
7203
|
};
|
|
6799
7204
|
const paintHalo = () => {
|
|
6800
|
-
const visible =
|
|
7205
|
+
const visible = parts2().flatMap((part) => part.outline === void 0 ? [] : [{ ...part.outline, color: part.colors?.color }]);
|
|
6801
7206
|
halo.paint(halos(), visible, style.halo, style.transform);
|
|
6802
7207
|
};
|
|
6803
7208
|
return {
|
|
@@ -6822,13 +7227,13 @@ function hostMarkHandle(parts, edits, halos) {
|
|
|
6822
7227
|
}
|
|
6823
7228
|
function hostColors(element, root) {
|
|
6824
7229
|
const fill = paintOf(element, root, "fill");
|
|
6825
|
-
const paint = fill ===
|
|
7230
|
+
const paint = fill === NONE2 ? "stroke" : "fill";
|
|
6826
7231
|
const color = paint === "fill" ? fill : paintOf(element, root, "stroke");
|
|
6827
|
-
if (color === void 0 || color ===
|
|
7232
|
+
if (color === void 0 || color === NONE2) return void 0;
|
|
6828
7233
|
return { color, strong: `color-mix(in oklab, ${color}, ${cssColor("text")} ${STRONG})`, paint };
|
|
6829
7234
|
}
|
|
6830
7235
|
var STRONG = "25%";
|
|
6831
|
-
var
|
|
7236
|
+
var NONE2 = "none";
|
|
6832
7237
|
function paintOf(element, root, property) {
|
|
6833
7238
|
let declared;
|
|
6834
7239
|
for (let node = element; node && declared === void 0; node = node === root ? null : node.parentElement) {
|
|
@@ -6836,13 +7241,13 @@ function paintOf(element, root, property) {
|
|
|
6836
7241
|
if (value) declared = value;
|
|
6837
7242
|
}
|
|
6838
7243
|
const computed = kind(element.ownerDocument.defaultView?.getComputedStyle?.(element).getPropertyValue(property));
|
|
6839
|
-
const initial = property === "fill" ? computed?.replace(/\s/g, "") === "rgb(0,0,0)" : computed ===
|
|
7244
|
+
const initial = property === "fill" ? computed?.replace(/\s/g, "") === "rgb(0,0,0)" : computed === NONE2;
|
|
6840
7245
|
return computed !== void 0 && !(initial && declared !== void 0) ? computed : kind(declared);
|
|
6841
7246
|
}
|
|
6842
7247
|
function kind(value) {
|
|
6843
7248
|
const v = value?.trim().toLowerCase();
|
|
6844
7249
|
if (!v || v === "inherit" || v.startsWith("url(")) return void 0;
|
|
6845
|
-
if (v ===
|
|
7250
|
+
if (v === NONE2 || v === "transparent" || /^rgba\((?:[^,]+,){3}\s*0(?:\.0*)?\s*\)$/.test(v)) return NONE2;
|
|
6846
7251
|
return value.trim();
|
|
6847
7252
|
}
|
|
6848
7253
|
function mix2(colors, emphasis) {
|
|
@@ -7026,8 +7431,8 @@ function expressive(target, options, env2) {
|
|
|
7026
7431
|
if (typeof geometry !== "object" || geometry === null || geometry.key !== key) {
|
|
7027
7432
|
throw new TypeError(`expressive: geometry for "${key}" must be a MarkGeometry with the key "${key}". Build it with describe and the key passed in.`);
|
|
7028
7433
|
}
|
|
7029
|
-
const
|
|
7030
|
-
return { key, geometry, parts, index };
|
|
7434
|
+
const parts2 = pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at));
|
|
7435
|
+
return { key, geometry, parts: parts2, index };
|
|
7031
7436
|
}
|
|
7032
7437
|
function rectPiece(key, piece, at) {
|
|
7033
7438
|
if (piece.element.localName !== "rect") {
|
|
@@ -7042,11 +7447,11 @@ function expressive(target, options, env2) {
|
|
|
7042
7447
|
function rectMark(key, pieces, edge, index, at) {
|
|
7043
7448
|
const { geometry, order: order2 } = describeRects(key, pieces.map((p) => p.rect), edge);
|
|
7044
7449
|
const segments = geometry.segments ?? [];
|
|
7045
|
-
const
|
|
7450
|
+
const parts2 = order2.map((j, n) => {
|
|
7046
7451
|
const segment = segments[n];
|
|
7047
7452
|
return part(pieces[j], segment && segment.length >= 0.5 ? { d: segment.outline.d } : void 0, at);
|
|
7048
7453
|
});
|
|
7049
|
-
return { key, geometry, parts, index, rect: { edge, box: union(pieces.map((p) => p.rect.box)) } };
|
|
7454
|
+
return { key, geometry, parts: parts2, index, rect: { edge, box: union(pieces.map((p) => p.rect.box)) } };
|
|
7050
7455
|
}
|
|
7051
7456
|
function part(piece, outline2, at) {
|
|
7052
7457
|
const parent = between(at.common, piece.element.parentElement ?? at.svg, at.svg, at.screen);
|
|
@@ -7054,8 +7459,8 @@ function expressive(target, options, env2) {
|
|
|
7054
7459
|
}
|
|
7055
7460
|
function withData(marks) {
|
|
7056
7461
|
return marks.map((mark) => {
|
|
7057
|
-
const { key, geometry, parts } = mark;
|
|
7058
|
-
const total2 = mark.rect ? totalOf(
|
|
7462
|
+
const { key, geometry, parts: parts2 } = mark;
|
|
7463
|
+
const total2 = mark.rect ? totalOf(parts2) : void 0;
|
|
7059
7464
|
const samplesOf = (datum, of, series) => {
|
|
7060
7465
|
if (options.samples) return checkSamples(options.samples(datum, of), series === void 0 ? `"${key}"` : `"${key}" (${series})`);
|
|
7061
7466
|
return total2 === void 0 ? [] : barSamples(geometry, of, total2);
|
|
@@ -7063,10 +7468,10 @@ function expressive(target, options, env2) {
|
|
|
7063
7468
|
const own2 = /* @__PURE__ */ new Map();
|
|
7064
7469
|
const related = (series) => own2.get(series) ?? relatedOf(series, key);
|
|
7065
7470
|
for (const series of ownSeries(mark)) {
|
|
7066
|
-
const datum = (
|
|
7471
|
+
const datum = (parts2.find((p) => p.series === series) ?? parts2[0]).datum;
|
|
7067
7472
|
own2.set(series, { datum, samples: samplesOf(datum, geometry.segments?.find((s) => s.series === series) ?? geometry, series), related });
|
|
7068
7473
|
}
|
|
7069
|
-
return { ...mark, data: { datum:
|
|
7474
|
+
return { ...mark, data: { datum: parts2[0].datum, samples: samplesOf(parts2[0].datum, geometry), related } };
|
|
7070
7475
|
});
|
|
7071
7476
|
}
|
|
7072
7477
|
function checkNeeds3(marks) {
|
|
@@ -7101,10 +7506,10 @@ function expressive(target, options, env2) {
|
|
|
7101
7506
|
if (series === void 0 || series === null || series === "") throw new TypeError(`expressive: segment returned ${String(series)} for a part of "${key}".`);
|
|
7102
7507
|
return String(series);
|
|
7103
7508
|
}
|
|
7104
|
-
function labelOf(key,
|
|
7509
|
+
function labelOf(key, parts2) {
|
|
7105
7510
|
if (!options.markLabel) return void 0;
|
|
7106
7511
|
try {
|
|
7107
|
-
const text2 = String(options.markLabel(
|
|
7512
|
+
const text2 = String(options.markLabel(parts2[0].datum, { key, parts: parts2.map(({ series, datum }) => ({ series, datum })) }) ?? "");
|
|
7108
7513
|
return text2.trim() === "" ? void 0 : text2;
|
|
7109
7514
|
} catch (error) {
|
|
7110
7515
|
report(error);
|
|
@@ -7170,7 +7575,7 @@ function expressive(target, options, env2) {
|
|
|
7170
7575
|
if (reading.root && reading.root !== root) moveTo2(reading.root);
|
|
7171
7576
|
ancestor = reading.ancestor ?? ancestor;
|
|
7172
7577
|
const keys = new Set(reading.marks.map((mark) => mark.key));
|
|
7173
|
-
const diff = { entering: [], exiting: [], changed: [], moved: [] };
|
|
7578
|
+
const diff = { entering: [], exiting: [], changed: [], moved: [], newRow: false };
|
|
7174
7579
|
const recolor = [];
|
|
7175
7580
|
for (const record of order) {
|
|
7176
7581
|
if (keys.has(record.key)) continue;
|
|
@@ -7185,8 +7590,10 @@ function expressive(target, options, env2) {
|
|
|
7185
7590
|
if (record) {
|
|
7186
7591
|
const from = record.mark;
|
|
7187
7592
|
const changed = options.value ? valuesChanged2(from.parts, mark.parts) : lengthsChanged(from.geometry, mark.geometry);
|
|
7593
|
+
const newRow = from.data.datum !== mark.data.datum;
|
|
7594
|
+
if (newRow) diff.newRow = true;
|
|
7188
7595
|
if (changed) diff.changed.push({ record, from: from.geometry });
|
|
7189
|
-
else if (geometryChanged2(from.geometry, mark.geometry) ||
|
|
7596
|
+
else if (newRow || geometryChanged2(from.geometry, mark.geometry) || samplesChanged(from.data.samples, mark.data.samples)) {
|
|
7190
7597
|
diff.moved.push(record);
|
|
7191
7598
|
}
|
|
7192
7599
|
if (from.parts[0]?.colors?.color !== mark.parts[0]?.colors?.color) recolor.push(mark.key);
|
|
@@ -7217,8 +7624,8 @@ function expressive(target, options, env2) {
|
|
|
7217
7624
|
}
|
|
7218
7625
|
function nameMark(record) {
|
|
7219
7626
|
if (!options.markLabel) return;
|
|
7220
|
-
const { label: label2, parts } = record.mark;
|
|
7221
|
-
|
|
7627
|
+
const { label: label2, parts: parts2 } = record.mark;
|
|
7628
|
+
parts2.forEach((part2, index) => {
|
|
7222
7629
|
const named = label2 !== void 0 && index === 0;
|
|
7223
7630
|
edits.attribute(part2.element, "role", named ? "img" : null);
|
|
7224
7631
|
edits.attribute(part2.element, "aria-label", named ? label2 : null);
|
|
@@ -7434,7 +7841,7 @@ function expressive(target, options, env2) {
|
|
|
7434
7841
|
function reread(changed) {
|
|
7435
7842
|
const at = { svg: root, common: ancestor, screen: screenMatrices(), colors: (element) => owners.get(element)?.part.colors };
|
|
7436
7843
|
const rowOf = rowsNow();
|
|
7437
|
-
const piecesOf = ({ parts }) =>
|
|
7844
|
+
const piecesOf = ({ parts: parts2 }) => parts2.map((part2) => ({ element: part2.element, datum: rowOf(part2.element), series: part2.series, value: part2.value }));
|
|
7438
7845
|
if (options.geometry) {
|
|
7439
7846
|
const marks2 = changed.map(({ mark }) => ({ ...shapeMark(mark.key, piecesOf(mark), mark.index, at), label: mark.label }));
|
|
7440
7847
|
return { records: [...changed], marks: withData(marks2) };
|
|
@@ -7523,7 +7930,9 @@ function expressive(target, options, env2) {
|
|
|
7523
7930
|
dropGone();
|
|
7524
7931
|
const exited = runner.exit(diff.exiting.map(input));
|
|
7525
7932
|
emitEach("exit", diff.exiting);
|
|
7526
|
-
|
|
7933
|
+
if (diff.newRow || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) {
|
|
7934
|
+
runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
|
|
7935
|
+
}
|
|
7527
7936
|
diff.changed.forEach(({ record, from }, index) => emit("update", { ...input(record), from, batch: { index, count: diff.changed.length } }));
|
|
7528
7937
|
runner.enter(diff.entering.map(input));
|
|
7529
7938
|
emitEach("enter", diff.entering);
|
|
@@ -7586,9 +7995,9 @@ function ownSeries(mark) {
|
|
|
7586
7995
|
const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
|
|
7587
7996
|
return [...new Set(names.filter((name) => name !== void 0))];
|
|
7588
7997
|
}
|
|
7589
|
-
function totalOf(
|
|
7998
|
+
function totalOf(parts2) {
|
|
7590
7999
|
let total2 = 0;
|
|
7591
|
-
for (const { value } of
|
|
8000
|
+
for (const { value } of parts2) {
|
|
7592
8001
|
if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
|
|
7593
8002
|
total2 += value;
|
|
7594
8003
|
}
|
|
@@ -7612,14 +8021,17 @@ function checkSamples(samples, mark) {
|
|
|
7612
8021
|
if (!Array.isArray(samples)) throw new TypeError(`expressive: samples for ${mark} must return an array of { t, value }, got ${describeValue2(samples)}.`);
|
|
7613
8022
|
let last = 0;
|
|
7614
8023
|
return samples.map((sample, i) => {
|
|
7615
|
-
const { t, value, at } = typeof sample === "object" && sample !== null ? sample : {};
|
|
8024
|
+
const { t, value, at, gapBefore } = typeof sample === "object" && sample !== null ? sample : {};
|
|
7616
8025
|
if (typeof t !== "number" || !(t >= 0 && t <= 1)) throw new RangeError(`expressive: samples for ${mark}: samples[${i}].t must be in [0, 1], got ${describeValue2(t)}.`);
|
|
7617
8026
|
if (t < last) throw new RangeError(`expressive: samples for ${mark} must be in t order: samples[${i}].t is ${t}, after ${last}.`);
|
|
7618
8027
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
7619
8028
|
throw new RangeError(`expressive: samples for ${mark}: samples[${i}].value must be a finite number, got ${describeValue2(value)}.`);
|
|
7620
8029
|
}
|
|
8030
|
+
if (gapBefore !== void 0 && typeof gapBefore !== "boolean") {
|
|
8031
|
+
throw new RangeError(`expressive: samples for ${mark}: samples[${i}].gapBefore must be true or false, got ${describeValue2(gapBefore)}.`);
|
|
8032
|
+
}
|
|
7621
8033
|
last = t;
|
|
7622
|
-
return at === void 0 ? {
|
|
8034
|
+
return { t, value, ...at === void 0 ? {} : { at }, ...gapBefore ? { gapBefore } : {} };
|
|
7623
8035
|
});
|
|
7624
8036
|
}
|
|
7625
8037
|
function describeValue2(value) {
|
|
@@ -7640,9 +8052,9 @@ function ringOrder(marks, geometryOf) {
|
|
|
7640
8052
|
function distance2(a, b) {
|
|
7641
8053
|
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
7642
8054
|
}
|
|
7643
|
-
function outlineOf(geometry, series,
|
|
8055
|
+
function outlineOf(geometry, series, parts2) {
|
|
7644
8056
|
const segment = series === void 0 ? void 0 : geometry.segments?.find((s) => s.series === series);
|
|
7645
|
-
const shape = segment ?? (
|
|
8057
|
+
const shape = segment ?? (parts2 === 1 ? geometry : void 0);
|
|
7646
8058
|
if (!shape || segment && segment.length < 0.5) return void 0;
|
|
7647
8059
|
return shape.outline.closed ? { d: shape.outline.d } : { d: shape.outline.d, stroke: shape.thickness };
|
|
7648
8060
|
}
|
|
@@ -7719,7 +8131,7 @@ function fromVegaView(view, options, env2) {
|
|
|
7719
8131
|
let observed;
|
|
7720
8132
|
let stopFrame;
|
|
7721
8133
|
let destroyed = false;
|
|
7722
|
-
const observer = typeof MutationObserver === "function" ? new MutationObserver((records) => records.some(
|
|
8134
|
+
const observer = typeof MutationObserver === "function" ? new MutationObserver((records) => records.some(drawn2) && schedule()) : void 0;
|
|
7723
8135
|
observe(current.root);
|
|
7724
8136
|
function itemOf(element) {
|
|
7725
8137
|
const item = current.items.get(element);
|
|
@@ -7782,12 +8194,12 @@ function fromVegaView(view, options, env2) {
|
|
|
7782
8194
|
const elements = [];
|
|
7783
8195
|
for (const i of visualOrder(boxes, edges)) {
|
|
7784
8196
|
const key = keys[i];
|
|
7785
|
-
const
|
|
7786
|
-
const { geometry, order } = describeRects(key,
|
|
8197
|
+
const parts2 = groups.get(key);
|
|
8198
|
+
const { geometry, order } = describeRects(key, parts2.map((p) => p.part), edges[i]);
|
|
7787
8199
|
read.geometry.set(key, geometry);
|
|
7788
|
-
elements.push(...order.map((j) =>
|
|
8200
|
+
elements.push(...order.map((j) => parts2[j].element));
|
|
7789
8201
|
if (options.sample) {
|
|
7790
|
-
const values = order.map((j) => valueOf(read.items.get(
|
|
8202
|
+
const values = order.map((j) => valueOf(read.items.get(parts2[j].element)).value);
|
|
7791
8203
|
const total2 = values.reduce((sum, v) => sum + v, 0);
|
|
7792
8204
|
read.samples.set(geometry, [{ t: 0, value: 0 }, { t: 1, value: total2 }]);
|
|
7793
8205
|
let reached = 0;
|
|
@@ -7819,7 +8231,7 @@ function fromVegaView(view, options, env2) {
|
|
|
7819
8231
|
const end = at === void 0 ? { t: 1, value } : { t: 1, value, at };
|
|
7820
8232
|
return type === "symbol" ? [{ ...end, t: 0 }] : geometry.length > 0 ? [{ t: 0, value: 0 }, end] : [{ ...end, t: 0 }];
|
|
7821
8233
|
}
|
|
7822
|
-
function
|
|
8234
|
+
function drawn2(record) {
|
|
7823
8235
|
const overlay = observed?.querySelector(":scope > .ec-overlay");
|
|
7824
8236
|
const ours = (node) => node === overlay || (overlay?.contains(node) ?? false);
|
|
7825
8237
|
if (ours(record.target)) return false;
|
|
@@ -8214,9 +8626,9 @@ function playTransition(pairs, options) {
|
|
|
8214
8626
|
path: (d, paint) => target()?.path(d, paint) ?? INERT2,
|
|
8215
8627
|
text: (content, style) => target()?.text(content, style) ?? INERT2,
|
|
8216
8628
|
clear() {
|
|
8217
|
-
const
|
|
8629
|
+
const drawn2 = group;
|
|
8218
8630
|
group = void 0;
|
|
8219
|
-
|
|
8631
|
+
drawn2?.clear();
|
|
8220
8632
|
}
|
|
8221
8633
|
};
|
|
8222
8634
|
}
|
|
@@ -8325,12 +8737,12 @@ function chartSwitch(target, options, env2) {
|
|
|
8325
8737
|
if (!memory) return;
|
|
8326
8738
|
const now = focused();
|
|
8327
8739
|
if (now && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now)) return;
|
|
8328
|
-
const
|
|
8740
|
+
const inside3 = () => to.chart.element.contains(focused());
|
|
8329
8741
|
if (memory.key !== void 0) to.chart.focus(memory.key);
|
|
8330
|
-
if (
|
|
8742
|
+
if (inside3()) return;
|
|
8331
8743
|
for (const mark of to.chart.marks()) {
|
|
8332
8744
|
to.chart.focus(mark.key);
|
|
8333
|
-
if (
|
|
8745
|
+
if (inside3()) return;
|
|
8334
8746
|
}
|
|
8335
8747
|
}
|
|
8336
8748
|
function say(to) {
|
|
@@ -8846,7 +9258,7 @@ function travel(icon, options = {}) {
|
|
|
8846
9258
|
const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
|
|
8847
9259
|
if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
|
|
8848
9260
|
const walk = pick(mark, options.along);
|
|
8849
|
-
if (!walk || !(walk
|
|
9261
|
+
if (!walk || !(drawn(walk) >= MIN_WALK)) return void 0;
|
|
8850
9262
|
const scale2 = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
|
|
8851
9263
|
if (!(scale2 > 0)) return void 0;
|
|
8852
9264
|
return trip(walk, resolved, scale2, options);
|
|
@@ -8854,18 +9266,18 @@ function travel(icon, options = {}) {
|
|
|
8854
9266
|
function rider(mark, ctx) {
|
|
8855
9267
|
let current = plan(mark, ctx);
|
|
8856
9268
|
let handle;
|
|
8857
|
-
let
|
|
9269
|
+
let drawn2;
|
|
8858
9270
|
let progress = 0;
|
|
8859
9271
|
const draw = () => {
|
|
8860
9272
|
if (!current) {
|
|
8861
9273
|
handle?.remove();
|
|
8862
|
-
handle =
|
|
9274
|
+
handle = drawn2 = void 0;
|
|
8863
9275
|
return;
|
|
8864
9276
|
}
|
|
8865
|
-
if (!handle ||
|
|
9277
|
+
if (!handle || drawn2?.icon !== current.icon || drawn2.size !== current.size) {
|
|
8866
9278
|
handle?.remove();
|
|
8867
9279
|
handle = ctx.layer.icon(current.icon, { size: current.size });
|
|
8868
|
-
|
|
9280
|
+
drawn2 = { icon: current.icon, size: current.size };
|
|
8869
9281
|
}
|
|
8870
9282
|
handle.place(current.transform(progress));
|
|
8871
9283
|
};
|
|
@@ -8912,7 +9324,12 @@ function trip(walk, icon, scale2, options) {
|
|
|
8912
9324
|
const length = walk.length;
|
|
8913
9325
|
const behind = icon.footprint[0] * scale2;
|
|
8914
9326
|
const ahead = icon.footprint[1] * scale2;
|
|
8915
|
-
|
|
9327
|
+
let span2 = 0;
|
|
9328
|
+
const legs = parts(walk).map(([from, to]) => {
|
|
9329
|
+
const leg = { from, to, span: Math.max(0, to - from - behind - ahead), before: span2 };
|
|
9330
|
+
span2 += leg.span;
|
|
9331
|
+
return leg;
|
|
9332
|
+
});
|
|
8916
9333
|
const smoothing = Math.max(MIN_SMOOTHING, (behind + ahead) / 2);
|
|
8917
9334
|
const radius = icon.radius ?? icon.box.height / 2;
|
|
8918
9335
|
const { anchor } = icon;
|
|
@@ -8922,14 +9339,18 @@ function trip(walk, icon, scale2, options) {
|
|
|
8922
9339
|
return {
|
|
8923
9340
|
icon,
|
|
8924
9341
|
size: icon.size * scale2,
|
|
8925
|
-
span,
|
|
8926
|
-
duration: Math.min(LONGEST2, Math.max(SHORTEST,
|
|
9342
|
+
span: span2,
|
|
9343
|
+
duration: Math.min(LONGEST2, Math.max(SHORTEST, span2 / SPEED * 1e3) * (gait.pace ?? 1)),
|
|
8927
9344
|
gait,
|
|
8928
9345
|
transform(progress) {
|
|
8929
|
-
const
|
|
8930
|
-
|
|
9346
|
+
const travelled = progress * span2;
|
|
9347
|
+
let index = legs.length - 1;
|
|
9348
|
+
while (index > 0 && legs[index].before > travelled) index--;
|
|
9349
|
+
const leg = legs[index];
|
|
9350
|
+
const distance3 = leg.from + behind + Math.min(leg.span, travelled - leg.before);
|
|
9351
|
+
const pose = gait({ distance: travelled / scale2, length: span2 / scale2, progress, radius });
|
|
8931
9352
|
const at = pointAt(walk, distance3);
|
|
8932
|
-
const direction = heading(walk, Math.min(distance3, length), smoothing);
|
|
9353
|
+
const direction = heading(walk, Math.min(distance3, length), smoothing, leg);
|
|
8933
9354
|
const mirror = orient === "auto" && icon.upright === true && Math.cos(direction) < -1e-9;
|
|
8934
9355
|
const turn2 = orient === "level" ? 0 : mirror ? normalizeAngle(direction - Math.PI) : direction;
|
|
8935
9356
|
return matrix.multiply(
|
|
@@ -8947,16 +9368,31 @@ function pick(mark, along) {
|
|
|
8947
9368
|
if (mark.segments) return mark.segments.find((segment) => segment.series === along);
|
|
8948
9369
|
return mark.series === along ? mark : void 0;
|
|
8949
9370
|
}
|
|
9371
|
+
function parts(walk) {
|
|
9372
|
+
const { length } = walk;
|
|
9373
|
+
const found = [];
|
|
9374
|
+
let at = 0;
|
|
9375
|
+
for (const [from, to] of walk.gaps ?? []) {
|
|
9376
|
+
if (!(to > from) || !(to > at)) continue;
|
|
9377
|
+
if (from > at) found.push([at * length, Math.min(1, from) * length]);
|
|
9378
|
+
at = Math.min(1, to);
|
|
9379
|
+
}
|
|
9380
|
+
found.push([at * length, length]);
|
|
9381
|
+
return found;
|
|
9382
|
+
}
|
|
9383
|
+
function drawn(walk) {
|
|
9384
|
+
return parts(walk).reduce((sum, [from, to]) => sum + (to - from), 0);
|
|
9385
|
+
}
|
|
8950
9386
|
function pointAt(walk, distance3) {
|
|
8951
9387
|
const { length } = walk;
|
|
8952
9388
|
return distance3 <= length ? walk.path(distance3 / length) : offset(walk.end, walk.angle(1), distance3 - length);
|
|
8953
9389
|
}
|
|
8954
|
-
function heading(walk, distance3, window) {
|
|
9390
|
+
function heading(walk, distance3, window, leg) {
|
|
8955
9391
|
const { length } = walk;
|
|
8956
|
-
const
|
|
8957
|
-
if (
|
|
8958
|
-
const a = walk.path((distance3 -
|
|
8959
|
-
const b = walk.path((distance3 +
|
|
9392
|
+
const reach2 = Math.min(window, distance3 - leg.from, leg.to - distance3);
|
|
9393
|
+
if (reach2 > 1e-6) {
|
|
9394
|
+
const a = walk.path((distance3 - reach2) / length);
|
|
9395
|
+
const b = walk.path((distance3 + reach2) / length);
|
|
8960
9396
|
if (Math.hypot(b.x - a.x, b.y - a.y) > 1e-9) return Math.atan2(b.y - a.y, b.x - a.x);
|
|
8961
9397
|
}
|
|
8962
9398
|
return walk.angle(distance3 / length);
|
|
@@ -8988,7 +9424,7 @@ function flash(options = {}) {
|
|
|
8988
9424
|
const width = options.width ?? WIDTH;
|
|
8989
9425
|
const opacity = options.opacity ?? OPACITY;
|
|
8990
9426
|
const { color } = options;
|
|
8991
|
-
const
|
|
9427
|
+
const show4 = (ctx, progress) => {
|
|
8992
9428
|
const stroke2 = width * blink(progress);
|
|
8993
9429
|
ctx.mark.set({ halo: stroke2 > 0 ? { width: stroke2, opacity, ...color === void 0 ? {} : { color } } : void 0 });
|
|
8994
9430
|
};
|
|
@@ -8996,7 +9432,7 @@ function flash(options = {}) {
|
|
|
8996
9432
|
kind: "geometry",
|
|
8997
9433
|
async run(_mark, ctx) {
|
|
8998
9434
|
if (ctx.signal.aborted) return;
|
|
8999
|
-
await ctx.tween({ duration: DURATION2, timing: "effect", ease: linear, update: (p) =>
|
|
9435
|
+
await ctx.tween({ duration: DURATION2, timing: "effect", ease: linear, update: (p) => show4(ctx, p) }).finished;
|
|
9000
9436
|
},
|
|
9001
9437
|
end() {
|
|
9002
9438
|
},
|
|
@@ -9051,14 +9487,14 @@ function wiggle(options = {}) {
|
|
|
9051
9487
|
let current = mark;
|
|
9052
9488
|
let cap = limit(mark, swing);
|
|
9053
9489
|
let progress = 0;
|
|
9054
|
-
const
|
|
9490
|
+
const show4 = () => {
|
|
9055
9491
|
const angle = cap * rock(progress);
|
|
9056
9492
|
ctx.mark.set({ transform: angle === 0 ? void 0 : matrix.rotate(angle, current.pivot) });
|
|
9057
9493
|
};
|
|
9058
9494
|
ctx.onChange((next) => {
|
|
9059
9495
|
current = next;
|
|
9060
9496
|
cap = limit(next, swing);
|
|
9061
|
-
|
|
9497
|
+
show4();
|
|
9062
9498
|
});
|
|
9063
9499
|
await ctx.tween({
|
|
9064
9500
|
duration: DURATION3,
|
|
@@ -9066,7 +9502,7 @@ function wiggle(options = {}) {
|
|
|
9066
9502
|
ease: linear,
|
|
9067
9503
|
update: (p) => {
|
|
9068
9504
|
progress = p;
|
|
9069
|
-
|
|
9505
|
+
show4();
|
|
9070
9506
|
}
|
|
9071
9507
|
}).finished;
|
|
9072
9508
|
},
|
|
@@ -9078,10 +9514,10 @@ function wiggle(options = {}) {
|
|
|
9078
9514
|
}
|
|
9079
9515
|
function limit(mark, swing) {
|
|
9080
9516
|
const { pivot } = mark;
|
|
9081
|
-
let
|
|
9082
|
-
for (const point of mark.outline.sample(SAMPLES))
|
|
9083
|
-
if (!(
|
|
9084
|
-
return Math.min(MAX_ANGLE, 2 * Math.asin(Math.min(1, swing / (2 *
|
|
9517
|
+
let reach2 = 0;
|
|
9518
|
+
for (const point of mark.outline.sample(SAMPLES)) reach2 = Math.max(reach2, Math.hypot(point.x - pivot.x, point.y - pivot.y));
|
|
9519
|
+
if (!(reach2 >= MIN_REACH)) return 0;
|
|
9520
|
+
return Math.min(MAX_ANGLE, 2 * Math.asin(Math.min(1, swing / (2 * reach2))));
|
|
9085
9521
|
}
|
|
9086
9522
|
function rock(t) {
|
|
9087
9523
|
if (!(t > 0) || t >= 1) return 0;
|
|
@@ -9108,7 +9544,7 @@ function pulse(options = {}) {
|
|
|
9108
9544
|
const times = options.times ?? TIMES;
|
|
9109
9545
|
const width = options.width ?? WIDTH2;
|
|
9110
9546
|
const { color } = options;
|
|
9111
|
-
const
|
|
9547
|
+
const show4 = (ctx, t) => {
|
|
9112
9548
|
const visible = t > 0 && t < 1;
|
|
9113
9549
|
ctx.mark.set({
|
|
9114
9550
|
halo: visible ? { width: width * easeOutCubic(t), opacity: OPACITY2 * (1 - t), ...color === void 0 ? {} : { color } } : void 0
|
|
@@ -9123,7 +9559,7 @@ function pulse(options = {}) {
|
|
|
9123
9559
|
const length = ctx.motion.duration(DURATION4, "effect");
|
|
9124
9560
|
if (total2 + length >= LIMIT) return;
|
|
9125
9561
|
total2 += length;
|
|
9126
|
-
await ctx.tween({ duration: DURATION4, timing: "effect", ease: linear, update: (t) =>
|
|
9562
|
+
await ctx.tween({ duration: DURATION4, timing: "effect", ease: linear, update: (t) => show4(ctx, t) }).finished;
|
|
9127
9563
|
}
|
|
9128
9564
|
},
|
|
9129
9565
|
end() {
|
|
@@ -9182,12 +9618,12 @@ function trace(options = {}) {
|
|
|
9182
9618
|
kind: "geometry",
|
|
9183
9619
|
async run(mark, ctx) {
|
|
9184
9620
|
if (ctx.signal.aborted) return;
|
|
9185
|
-
const
|
|
9621
|
+
const show4 = stroke2(mark, ctx);
|
|
9186
9622
|
if (!(mark.length >= MIN_WALK2)) {
|
|
9187
|
-
|
|
9623
|
+
show4(1);
|
|
9188
9624
|
return;
|
|
9189
9625
|
}
|
|
9190
|
-
await ctx.tween({ duration, timing: "effect", ease: easeInOutCubic, update:
|
|
9626
|
+
await ctx.tween({ duration, timing: "effect", ease: easeInOutCubic, update: show4 }).finished;
|
|
9191
9627
|
},
|
|
9192
9628
|
end(mark, ctx) {
|
|
9193
9629
|
stroke2(mark, ctx)(1);
|
|
@@ -9328,8 +9764,8 @@ function delta(options = {}) {
|
|
|
9328
9764
|
if (ctx.signal.aborted) return;
|
|
9329
9765
|
const text2 = words(data);
|
|
9330
9766
|
if (text2 === void 0 || text2 === "") return;
|
|
9331
|
-
const
|
|
9332
|
-
await ctx.tween({ duration: DURATION6, timing: "effect", update:
|
|
9767
|
+
const show4 = caption(mark, data, ctx, color, () => text2);
|
|
9768
|
+
await ctx.tween({ duration: DURATION6, timing: "effect", update: show4 }).finished;
|
|
9333
9769
|
},
|
|
9334
9770
|
end: (mark, data, ctx) => {
|
|
9335
9771
|
const text2 = words(data);
|
|
@@ -9355,15 +9791,15 @@ function label(text2, options = {}) {
|
|
|
9355
9791
|
const { color = "text" } = options;
|
|
9356
9792
|
if (typeof color !== "string" || color === "") throw new RangeError(`label: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
9357
9793
|
const words = (mark, data) => {
|
|
9358
|
-
const
|
|
9359
|
-
return
|
|
9794
|
+
const said2 = text2(data, mark);
|
|
9795
|
+
return said2 === void 0 || said2 === null ? void 0 : String(said2);
|
|
9360
9796
|
};
|
|
9361
9797
|
return {
|
|
9362
9798
|
kind: "data",
|
|
9363
9799
|
run: async (mark, data, ctx) => {
|
|
9364
9800
|
if (ctx.signal.aborted) return;
|
|
9365
|
-
const
|
|
9366
|
-
await ctx.tween({ duration: DURATION7, timing: "effect", update:
|
|
9801
|
+
const show4 = caption(mark, data, ctx, color, words);
|
|
9802
|
+
await ctx.tween({ duration: DURATION7, timing: "effect", update: show4 }).finished;
|
|
9367
9803
|
},
|
|
9368
9804
|
end: (mark, data, ctx) => caption(mark, data, ctx, color, words)(1),
|
|
9369
9805
|
clear() {
|
|
@@ -9384,15 +9820,15 @@ function threshold(options) {
|
|
|
9384
9820
|
const paths = [];
|
|
9385
9821
|
let latest = data;
|
|
9386
9822
|
const draw = (current) => {
|
|
9387
|
-
const
|
|
9823
|
+
const parts2 = current.length >= MIN_WALK3 ? runs(latest.samples, reference(compareTo, latest), when) : [];
|
|
9388
9824
|
const paint = { stroke: color, width: current.thickness, linecap: "butt" };
|
|
9389
|
-
|
|
9825
|
+
parts2.forEach(([t0, t1], i) => {
|
|
9390
9826
|
const d = current.slice(t0, t1);
|
|
9391
9827
|
const path = paths[i];
|
|
9392
9828
|
if (path) path.update(d, paint);
|
|
9393
9829
|
else paths.push(ctx.layer.path(d, paint));
|
|
9394
9830
|
});
|
|
9395
|
-
for (const path of paths.splice(
|
|
9831
|
+
for (const path of paths.splice(parts2.length)) path.remove();
|
|
9396
9832
|
};
|
|
9397
9833
|
ctx.onChange((next, nextData) => {
|
|
9398
9834
|
latest = nextData ?? latest;
|
|
@@ -9418,7 +9854,37 @@ function reference(compareTo, data) {
|
|
|
9418
9854
|
const byAt = data.samples.every((sample) => numeric2(sample.at) !== void 0) && related.samples.every((sample) => numeric2(sample.at) !== void 0);
|
|
9419
9855
|
const place = byAt ? (sample) => numeric2(sample.at) : (sample) => sample.t;
|
|
9420
9856
|
const points = related.samples.map((sample) => ({ u: place(sample), value: sample.value })).filter((point) => Number.isFinite(point.u)).sort((a, b) => a.u - b.u);
|
|
9421
|
-
|
|
9857
|
+
const gaps = gapsOf(related.samples, place);
|
|
9858
|
+
return { place, valueAt: (u) => inside2(gaps, u) ? void 0 : interpolate(points, u), bends: points.map((point) => point.u) };
|
|
9859
|
+
}
|
|
9860
|
+
function gapsOf(samples, place) {
|
|
9861
|
+
const gaps = [];
|
|
9862
|
+
samples.forEach((sample, i) => {
|
|
9863
|
+
const before = samples[i - 1];
|
|
9864
|
+
if (sample.gapBefore !== true || !before) return;
|
|
9865
|
+
const u = place(before);
|
|
9866
|
+
const v = place(sample);
|
|
9867
|
+
if (Number.isFinite(u) && Number.isFinite(v) && u !== v) gaps.push([Math.min(u, v), Math.max(u, v)]);
|
|
9868
|
+
});
|
|
9869
|
+
gaps.sort((a, b) => a[0] - b[0]);
|
|
9870
|
+
const merged = [];
|
|
9871
|
+
for (const gap of gaps) {
|
|
9872
|
+
const last = merged[merged.length - 1];
|
|
9873
|
+
if (last && gap[0] < last[1]) last[1] = Math.max(last[1], gap[1]);
|
|
9874
|
+
else merged.push(gap);
|
|
9875
|
+
}
|
|
9876
|
+
return merged;
|
|
9877
|
+
}
|
|
9878
|
+
function inside2(gaps, u) {
|
|
9879
|
+
let lo = 0;
|
|
9880
|
+
let hi = gaps.length;
|
|
9881
|
+
while (lo < hi) {
|
|
9882
|
+
const mid = lo + hi >> 1;
|
|
9883
|
+
if (gaps[mid][0] < u) lo = mid + 1;
|
|
9884
|
+
else hi = mid;
|
|
9885
|
+
}
|
|
9886
|
+
const gap = gaps[lo - 1];
|
|
9887
|
+
return gap !== void 0 && u < gap[1];
|
|
9422
9888
|
}
|
|
9423
9889
|
function numeric2(at) {
|
|
9424
9890
|
const value = typeof at === "number" ? at : at instanceof Date ? at.getTime() : void 0;
|
|
@@ -9443,18 +9909,18 @@ function interpolate(points, u) {
|
|
|
9443
9909
|
function runs(samples, ref, when) {
|
|
9444
9910
|
if (!ref) return [];
|
|
9445
9911
|
const sign = when === "below" ? 1 : -1;
|
|
9446
|
-
const station = (t, u, value) => {
|
|
9912
|
+
const station = (t, u, value, joined = true) => {
|
|
9447
9913
|
const level = ref.valueAt(u);
|
|
9448
|
-
if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, past: void 0 };
|
|
9914
|
+
if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, u, past: void 0, joined };
|
|
9449
9915
|
const past = sign * (level - value);
|
|
9450
|
-
return { t, past: Math.abs(past) <= TIE2 * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past };
|
|
9916
|
+
return { t, u, past: Math.abs(past) <= TIE2 * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past, joined };
|
|
9451
9917
|
};
|
|
9452
9918
|
const stations = [];
|
|
9453
9919
|
samples.forEach((sample, i) => {
|
|
9454
9920
|
const u = ref.place(sample);
|
|
9455
|
-
stations.push(station(sample.t, u, sample.value));
|
|
9921
|
+
stations.push(station(sample.t, u, sample.value, sample.gapBefore !== true));
|
|
9456
9922
|
const next = samples[i + 1];
|
|
9457
|
-
if (!next) return;
|
|
9923
|
+
if (!next || next.gapBefore === true) return;
|
|
9458
9924
|
const v = ref.place(next);
|
|
9459
9925
|
if (u === v || !Number.isFinite(u) || !Number.isFinite(v)) return;
|
|
9460
9926
|
const shares = [];
|
|
@@ -9465,24 +9931,25 @@ function runs(samples, ref, when) {
|
|
|
9465
9931
|
stations.push(station(sample.t + share * (next.t - sample.t), u + share * (v - u), sample.value + share * (next.value - sample.value)));
|
|
9466
9932
|
}
|
|
9467
9933
|
});
|
|
9468
|
-
const
|
|
9934
|
+
const parts2 = [];
|
|
9469
9935
|
const add = (t0, t1) => {
|
|
9470
9936
|
const from = clamp2(t0);
|
|
9471
9937
|
const to = clamp2(t1);
|
|
9472
9938
|
if (!(to > from)) return;
|
|
9473
|
-
const last =
|
|
9939
|
+
const last = parts2[parts2.length - 1];
|
|
9474
9940
|
if (last && last[1] >= from) last[1] = Math.max(last[1], to);
|
|
9475
|
-
else
|
|
9941
|
+
else parts2.push([from, to]);
|
|
9476
9942
|
};
|
|
9477
9943
|
for (let i = 1; i < stations.length; i++) {
|
|
9478
9944
|
const a = stations[i - 1];
|
|
9479
9945
|
const b = stations[i];
|
|
9480
|
-
if (a.past === void 0 || b.past === void 0 || !(b.t > a.t)) continue;
|
|
9946
|
+
if (a.past === void 0 || b.past === void 0 || !b.joined || !(b.t > a.t)) continue;
|
|
9947
|
+
if (a.u !== b.u && ref.valueAt((a.u + b.u) / 2) === void 0) continue;
|
|
9481
9948
|
if (a.past > 0 && b.past > 0) add(a.t, b.t);
|
|
9482
9949
|
else if (a.past > 0) add(a.t, a.t + (b.t - a.t) * (a.past / (a.past - b.past)));
|
|
9483
9950
|
else if (b.past > 0) add(a.t + (b.t - a.t) * (a.past / (a.past - b.past)), b.t);
|
|
9484
9951
|
}
|
|
9485
|
-
return
|
|
9952
|
+
return parts2;
|
|
9486
9953
|
}
|
|
9487
9954
|
var clamp2 = (t) => Math.min(1, Math.max(0, t));
|
|
9488
9955
|
function firstAbove(values, x) {
|
|
@@ -9498,14 +9965,14 @@ function firstAbove(values, x) {
|
|
|
9498
9965
|
function checkOptions14(options) {
|
|
9499
9966
|
const { compareTo, when, color } = options ?? {};
|
|
9500
9967
|
if (!(typeof compareTo === "string" ? compareTo !== "" : typeof compareTo === "number" && Number.isFinite(compareTo))) {
|
|
9501
|
-
throw new RangeError(`threshold: compareTo must be a finite number or a series name, got ${
|
|
9968
|
+
throw new RangeError(`threshold: compareTo must be a finite number or a series name, got ${show3(compareTo)}.`);
|
|
9502
9969
|
}
|
|
9503
|
-
if (when !== void 0 && !WHENS.includes(when)) throw new RangeError(`threshold: when must be "below" or "above", got ${
|
|
9970
|
+
if (when !== void 0 && !WHENS.includes(when)) throw new RangeError(`threshold: when must be "below" or "above", got ${show3(when)}.`);
|
|
9504
9971
|
if (color !== void 0 && (typeof color !== "string" || color === "")) {
|
|
9505
|
-
throw new RangeError(`threshold: color must be a theme token or a CSS colour, got ${
|
|
9972
|
+
throw new RangeError(`threshold: color must be a theme token or a CSS colour, got ${show3(color)}.`);
|
|
9506
9973
|
}
|
|
9507
9974
|
}
|
|
9508
|
-
var
|
|
9975
|
+
var show3 = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
9509
9976
|
|
|
9510
9977
|
// src/effects/morph.ts
|
|
9511
9978
|
var DURATION8 = 950;
|
|
@@ -9626,18 +10093,18 @@ function checkOptions15(options) {
|
|
|
9626
10093
|
|
|
9627
10094
|
// src/effects/combinators.ts
|
|
9628
10095
|
function sequence(...effects) {
|
|
9629
|
-
const
|
|
9630
|
-
return combine(
|
|
9631
|
-
for (const part of
|
|
10096
|
+
const parts2 = check("sequence", effects);
|
|
10097
|
+
return combine(parts2, async (start, ctx) => {
|
|
10098
|
+
for (const part of parts2) {
|
|
9632
10099
|
if (ctx.signal.aborted) return;
|
|
9633
10100
|
await start(part);
|
|
9634
10101
|
}
|
|
9635
10102
|
});
|
|
9636
10103
|
}
|
|
9637
10104
|
function parallel(...effects) {
|
|
9638
|
-
const
|
|
9639
|
-
return combine(
|
|
9640
|
-
await Promise.all(
|
|
10105
|
+
const parts2 = check("parallel", effects);
|
|
10106
|
+
return combine(parts2, async (start) => {
|
|
10107
|
+
await Promise.all(parts2.map(start));
|
|
9641
10108
|
});
|
|
9642
10109
|
}
|
|
9643
10110
|
function only(filter, effect) {
|
|
@@ -9720,7 +10187,7 @@ function follow(mark, data, ctx) {
|
|
|
9720
10187
|
});
|
|
9721
10188
|
return () => latest;
|
|
9722
10189
|
}
|
|
9723
|
-
function combine(
|
|
10190
|
+
function combine(parts2, play) {
|
|
9724
10191
|
const starter = (mark, data, ctx) => {
|
|
9725
10192
|
const now = follow(mark, data, ctx);
|
|
9726
10193
|
return (part) => {
|
|
@@ -9729,14 +10196,14 @@ function combine(parts, play) {
|
|
|
9729
10196
|
};
|
|
9730
10197
|
};
|
|
9731
10198
|
const end = (mark, data, ctx) => {
|
|
9732
|
-
for (const part of
|
|
10199
|
+
for (const part of parts2) {
|
|
9733
10200
|
if (part.kind === "data") part.end(mark, data, ctx);
|
|
9734
10201
|
else part.end(mark, ctx);
|
|
9735
10202
|
}
|
|
9736
10203
|
};
|
|
9737
10204
|
const clear = (ctx) => {
|
|
9738
10205
|
let failure;
|
|
9739
|
-
for (const part of
|
|
10206
|
+
for (const part of parts2) {
|
|
9740
10207
|
try {
|
|
9741
10208
|
part.clear(ctx);
|
|
9742
10209
|
} catch (error) {
|
|
@@ -9745,8 +10212,8 @@ function combine(parts, play) {
|
|
|
9745
10212
|
}
|
|
9746
10213
|
if (failure) throw failure.error;
|
|
9747
10214
|
};
|
|
9748
|
-
if (
|
|
9749
|
-
const related = [...new Set(
|
|
10215
|
+
if (parts2.some((part) => part.kind === "data")) {
|
|
10216
|
+
const related = [...new Set(parts2.flatMap((part) => part.kind === "data" ? part.needs?.related ?? [] : []))];
|
|
9750
10217
|
const effect2 = {
|
|
9751
10218
|
kind: "data",
|
|
9752
10219
|
...related.length > 0 ? { needs: { related } } : {},
|
|
@@ -9806,6 +10273,7 @@ function checkNeeds2(needs) {
|
|
|
9806
10273
|
var GAITS = ["roll", "step", "slide"];
|
|
9807
10274
|
var LINECAPS = ["butt", "round"];
|
|
9808
10275
|
var LINEJOINS = ["miter", "round"];
|
|
10276
|
+
var FILL_RULES = ["nonzero", "evenodd"];
|
|
9809
10277
|
var PATH_DATA = /^\s*[Mm][MmLlHhVvCcSsQqTtAaZz0-9eE.,+\-\s]*$/;
|
|
9810
10278
|
function defineIcon(spec) {
|
|
9811
10279
|
const name = spec?.name;
|
|
@@ -9825,8 +10293,8 @@ function defineIcon(spec) {
|
|
|
9825
10293
|
const pivot = spec.pivot === void 0 ? anchor : point("pivot", spec.pivot);
|
|
9826
10294
|
const footprint = spec.footprint ?? [Math.max(0, anchor.x - box.x), Math.max(0, box.x + box.width - anchor.x)];
|
|
9827
10295
|
if (!Array.isArray(footprint) || footprint.length !== 2) fail("footprint", "must be [behind, ahead]");
|
|
9828
|
-
footprint.forEach((
|
|
9829
|
-
if (finite2(`footprint[${i}]`,
|
|
10296
|
+
footprint.forEach((reach2, i) => {
|
|
10297
|
+
if (finite2(`footprint[${i}]`, reach2) < 0) fail(`footprint[${i}]`, `can't be negative, got ${reach2}`);
|
|
9830
10298
|
});
|
|
9831
10299
|
const size2 = spec.size === void 0 ? box.width : positive("size", spec.size);
|
|
9832
10300
|
const radius = spec.radius === void 0 ? box.height / 2 : positive("radius", spec.radius);
|
|
@@ -9856,8 +10324,11 @@ function checkShape(shape, field, fail, finite2) {
|
|
|
9856
10324
|
if (shape.width !== void 0 && finite2(`${field}.width`, shape.width) < 0) fail(`${field}.width`, `can't be negative, got ${shape.width}`);
|
|
9857
10325
|
if (shape.linecap !== void 0 && !LINECAPS.includes(shape.linecap)) fail(`${field}.linecap`, `must be butt or round, got ${String(shape.linecap)}`);
|
|
9858
10326
|
if (shape.linejoin !== void 0 && !LINEJOINS.includes(shape.linejoin)) fail(`${field}.linejoin`, `must be miter or round, got ${String(shape.linejoin)}`);
|
|
10327
|
+
if (shape.fillRule !== void 0 && !FILL_RULES.includes(shape.fillRule)) fail(`${field}.fillRule`, `must be nonzero or evenodd, got ${String(shape.fillRule)}`);
|
|
10328
|
+
const opacity = shape.opacity === void 0 ? 1 : finite2(`${field}.opacity`, shape.opacity);
|
|
10329
|
+
if (opacity < 0 || opacity > 1) fail(`${field}.opacity`, `must be from 0 to 1, got ${opacity}`);
|
|
9859
10330
|
const copy = { d: shape.d };
|
|
9860
|
-
for (const key of ["fill", "stroke", "width", "linecap", "linejoin", "clip"]) {
|
|
10331
|
+
for (const key of ["fill", "stroke", "width", "linecap", "linejoin", "clip", "fillRule", "opacity"]) {
|
|
9861
10332
|
if (shape[key] !== void 0) copy[key] = shape[key];
|
|
9862
10333
|
}
|
|
9863
10334
|
return freeze(copy);
|
|
@@ -9898,7 +10369,7 @@ function iconFromSvg(markup, spec) {
|
|
|
9898
10369
|
if (typeof spec.size !== "number" || !(spec.size > 0) || !Number.isFinite(spec.size)) fail(`size must be more than 0, got ${String(spec.size)}`);
|
|
9899
10370
|
scale2 = spec.size / box.width;
|
|
9900
10371
|
}
|
|
9901
|
-
root = { fill: "#000000", stroke: "none", width: 1, linecap: void 0, linejoin: void 0, transform: matrix.scale(scale2) };
|
|
10372
|
+
root = { fill: "#000000", stroke: "none", width: 1, linecap: void 0, linejoin: void 0, fillRule: "nonzero", opacity: 1, transform: matrix.scale(scale2) };
|
|
9902
10373
|
}
|
|
9903
10374
|
const parent = stack.length > 0 ? stack[stack.length - 1].state : first ? root : void 0;
|
|
9904
10375
|
const state = parent && !hidden(attributes) ? inherit(parent, attributes) : void 0;
|
|
@@ -9969,6 +10440,10 @@ function pixels(value) {
|
|
|
9969
10440
|
const number2 = match ? Number(match[1]) : NaN;
|
|
9970
10441
|
return number2 > 0 && Number.isFinite(number2) ? number2 : void 0;
|
|
9971
10442
|
}
|
|
10443
|
+
function alpha(value) {
|
|
10444
|
+
const match = /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)(%?)\s*$/i.exec(value ?? "");
|
|
10445
|
+
return match ? Math.min(1, Math.max(0, Number(match[1]) / (match[2] ? 100 : 1))) : 1;
|
|
10446
|
+
}
|
|
9972
10447
|
function hidden(attributes) {
|
|
9973
10448
|
return attributes.get("display")?.trim() === "none" || attributes.get("visibility")?.trim() === "hidden";
|
|
9974
10449
|
}
|
|
@@ -9982,6 +10457,7 @@ function inherit(parent, attributes) {
|
|
|
9982
10457
|
const width = Number.parseFloat(attributes.get("stroke-width") ?? "");
|
|
9983
10458
|
const linecap = attributes.get("stroke-linecap")?.trim();
|
|
9984
10459
|
const linejoin = attributes.get("stroke-linejoin")?.trim();
|
|
10460
|
+
const fillRule = attributes.get("fill-rule")?.trim().toLowerCase();
|
|
9985
10461
|
const transform = attributes.get("transform");
|
|
9986
10462
|
return {
|
|
9987
10463
|
fill: paint("fill", parent.fill),
|
|
@@ -9989,26 +10465,31 @@ function inherit(parent, attributes) {
|
|
|
9989
10465
|
width: width >= 0 ? width : parent.width,
|
|
9990
10466
|
linecap: linecap === "butt" || linecap === "round" ? linecap : parent.linecap,
|
|
9991
10467
|
linejoin: linejoin === "miter" || linejoin === "round" ? linejoin : parent.linejoin,
|
|
10468
|
+
fillRule: fillRule === "nonzero" || fillRule === "evenodd" ? fillRule : parent.fillRule,
|
|
10469
|
+
// Opacity isn't inherited in SVG: a group is drawn and then faded. Multiplying is the same unless its shapes overlap.
|
|
10470
|
+
opacity: parent.opacity * alpha(attributes.get("opacity")),
|
|
9992
10471
|
transform: transform ? matrix.multiply(parent.transform, parseTransform(transform)) : parent.transform
|
|
9993
10472
|
};
|
|
9994
10473
|
}
|
|
9995
10474
|
function toShape(tag, attributes, state) {
|
|
9996
10475
|
const fill = state.fill === "none" ? void 0 : state.fill;
|
|
9997
10476
|
const stroke2 = state.stroke === "none" || !(state.width > 0) ? void 0 : state.stroke;
|
|
9998
|
-
|
|
10477
|
+
const opacity = round4(state.opacity);
|
|
10478
|
+
if (fill === void 0 && stroke2 === void 0 || !(opacity > 0)) return void 0;
|
|
9999
10479
|
const commands = outline(tag, attributes);
|
|
10000
10480
|
if (!commands.some((command) => command.op !== "M")) return void 0;
|
|
10001
10481
|
const m = state.transform;
|
|
10002
10482
|
return {
|
|
10003
10483
|
d: formatPath(transformPath(commands, m)),
|
|
10004
|
-
...fill !== void 0 ? { fill } : {},
|
|
10484
|
+
...fill !== void 0 ? { fill, ...state.fillRule === "evenodd" ? { fillRule: state.fillRule } : {} } : {},
|
|
10005
10485
|
...stroke2 !== void 0 ? {
|
|
10006
10486
|
stroke: stroke2,
|
|
10007
10487
|
// A stroke scales with the transform; for an uneven scale this is the average.
|
|
10008
10488
|
width: round4(state.width * Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]))),
|
|
10009
10489
|
...state.linecap ? { linecap: state.linecap } : {},
|
|
10010
10490
|
...state.linejoin ? { linejoin: state.linejoin } : {}
|
|
10011
|
-
} : {}
|
|
10491
|
+
} : {},
|
|
10492
|
+
...opacity < 1 ? { opacity } : {}
|
|
10012
10493
|
};
|
|
10013
10494
|
}
|
|
10014
10495
|
function outline(tag, attributes) {
|
|
@@ -10147,7 +10628,7 @@ function configure(options) {
|
|
|
10147
10628
|
}
|
|
10148
10629
|
|
|
10149
10630
|
// src/index.ts
|
|
10150
|
-
var VERSION = "0.
|
|
10631
|
+
var VERSION = "0.3.0";
|
|
10151
10632
|
var env = { presets: presetRegistry, icons: iconRegistry, motion };
|
|
10152
10633
|
function barChart2(target, options) {
|
|
10153
10634
|
return barChart(target, options, env);
|