expressive-charts 0.1.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 +47 -0
- package/README.md +14 -13
- package/dist/{chunk-N5IF2RO2.js → chunk-7A7LXXT4.js} +6 -2
- package/dist/chunk-7A7LXXT4.js.map +1 -0
- package/dist/{chunk-ZIGBM4NY.js → chunk-CJUQHEX6.js} +92 -28
- 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-Du6DAgrW.d.cts → drawing-CdTgixMY.d.cts} +20 -2
- package/dist/{drawing-Du6DAgrW.d.ts → drawing-CdTgixMY.d.ts} +20 -2
- package/dist/{effect-dPmXiWlL.d.cts → effect-Bu3MHHeg.d.ts} +4 -2
- package/dist/{effect-OcyvtfZi.d.ts → effect-D4vmdYP4.d.cts} +4 -2
- package/dist/expressive-charts.css +11 -6
- package/dist/expressive-charts.css.d.cts +2 -0
- package/dist/expressive-charts.css.d.ts +2 -0
- package/dist/expressive-charts.global.js +29 -24
- 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 +1610 -669
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +143 -18
- package/dist/index.d.ts +143 -18
- package/dist/index.js +1448 -591
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +93 -42
- 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-ZIGBM4NY.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineIcon
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7A7LXXT4.js";
|
|
4
4
|
import {
|
|
5
5
|
EFFECT_SLOTS,
|
|
6
6
|
animated,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
scaleDuration,
|
|
31
31
|
tween,
|
|
32
32
|
unease
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-N2BLUETM.js";
|
|
34
34
|
import {
|
|
35
35
|
describe,
|
|
36
36
|
formatNumber,
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
offset,
|
|
41
41
|
parseTransform,
|
|
42
42
|
samplesAlong
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-CJUQHEX6.js";
|
|
44
44
|
|
|
45
45
|
// src/charts/announce.ts
|
|
46
46
|
var SORTED = {
|
|
@@ -51,16 +51,16 @@ var SORTED = {
|
|
|
51
51
|
};
|
|
52
52
|
var NAMED = 3;
|
|
53
53
|
function changeText(facts) {
|
|
54
|
-
const
|
|
54
|
+
const parts2 = [];
|
|
55
55
|
const { series } = facts;
|
|
56
|
-
if (facts.label !== void 0)
|
|
57
|
-
else if (series && !(series.length === 1 && series[0] === "value"))
|
|
58
|
-
if (facts.sort)
|
|
56
|
+
if (facts.label !== void 0) parts2.push(facts.label);
|
|
57
|
+
else if (series && !(series.length === 1 && series[0] === "value")) parts2.push(`Showing ${list(series)}`);
|
|
58
|
+
if (facts.sort) parts2.push(SORTED[facts.sort]);
|
|
59
59
|
const { changed, added, removed } = facts;
|
|
60
|
-
if (!series && changed.length > 0)
|
|
61
|
-
if (added.length > 0)
|
|
62
|
-
if (removed.length > 0)
|
|
63
|
-
return
|
|
60
|
+
if (!series && changed.length > 0) parts2.push(changed.length <= NAMED ? `${list(changed)} changed` : `${changed.length} of ${facts.count} changed`);
|
|
61
|
+
if (added.length > 0) parts2.push(`Added ${added.length <= NAMED ? list(added) : added.length}`);
|
|
62
|
+
if (removed.length > 0) parts2.push(`Removed ${removed.length <= NAMED ? list(removed) : removed.length}`);
|
|
63
|
+
return parts2.join(". ");
|
|
64
64
|
}
|
|
65
65
|
function list(names) {
|
|
66
66
|
if (names.length <= 1) return names.join("");
|
|
@@ -86,6 +86,76 @@ function chartAnnouncer(svg) {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
// src/charts/render/svg.ts
|
|
90
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
91
|
+
function svgElement(tag, attributes = {}, parent) {
|
|
92
|
+
const doc = parent?.ownerDocument ?? document;
|
|
93
|
+
const element = doc.createElementNS(SVG_NS, tag);
|
|
94
|
+
setAttributes(element, attributes);
|
|
95
|
+
parent?.appendChild(element);
|
|
96
|
+
return element;
|
|
97
|
+
}
|
|
98
|
+
function setAttributes(element, attributes) {
|
|
99
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
100
|
+
if (value === void 0) element.removeAttribute(name);
|
|
101
|
+
else element.setAttribute(name, typeof value === "number" ? formatNumber(value) : value);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function setStyles(element, styles) {
|
|
105
|
+
for (const [name, value] of Object.entries(styles)) {
|
|
106
|
+
if (value === void 0) element.style.removeProperty(name);
|
|
107
|
+
else element.style.setProperty(name, value);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function sizeAttributes({ width, height }) {
|
|
111
|
+
return { width, height, viewBox: `0 0 ${formatNumber(width)} ${formatNumber(height)}` };
|
|
112
|
+
}
|
|
113
|
+
function transformAttribute(m) {
|
|
114
|
+
const [a, b, c, d, e, f] = m;
|
|
115
|
+
return `matrix(${[a, b, c, d].map(linear2).join(" ")} ${formatNumber(e)} ${formatNumber(f)})`;
|
|
116
|
+
}
|
|
117
|
+
function linear2(value) {
|
|
118
|
+
const rounded = Math.round(value * 1e6) / 1e6;
|
|
119
|
+
return rounded === 0 ? "0" : String(rounded);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/charts/render/text.ts
|
|
123
|
+
var ASCENT = 1.05;
|
|
124
|
+
var DESCENT = 0.25;
|
|
125
|
+
var SIDE = 0.16;
|
|
126
|
+
function textBox(placement, measure, className, size) {
|
|
127
|
+
const width = measure(placement.text.replace(/\d/g, "0"), className, size);
|
|
128
|
+
const start = placement.anchor === "start" ? placement.x : placement.anchor === "end" ? placement.x - width : placement.x - width / 2;
|
|
129
|
+
return { x: start - SIDE * size, y: placement.y - ASCENT * size, width: width + 2 * SIDE * size, height: (ASCENT + DESCENT) * size };
|
|
130
|
+
}
|
|
131
|
+
function placeText(element, placement) {
|
|
132
|
+
setAttributes(element, { x: placement.x, y: placement.y, "text-anchor": placement.anchor });
|
|
133
|
+
if (element.textContent !== placement.text) element.textContent = placement.text;
|
|
134
|
+
}
|
|
135
|
+
var AVERAGE_WIDTH = 0.6;
|
|
136
|
+
function textMeasure(svg) {
|
|
137
|
+
const cache = /* @__PURE__ */ new Map();
|
|
138
|
+
const measure = (text2, className, size) => {
|
|
139
|
+
if (text2 === "") return 0;
|
|
140
|
+
const id = `${className}
|
|
141
|
+
${size}
|
|
142
|
+
${text2}`;
|
|
143
|
+
const cached = cache.get(id);
|
|
144
|
+
if (cached !== void 0) return cached;
|
|
145
|
+
let width = 0;
|
|
146
|
+
const probe = svgElement("text", { class: className, visibility: "hidden", "aria-hidden": "true" }, svg);
|
|
147
|
+
if (typeof probe.getComputedTextLength === "function" && svg.isConnected) {
|
|
148
|
+
probe.textContent = text2;
|
|
149
|
+
width = probe.getComputedTextLength();
|
|
150
|
+
}
|
|
151
|
+
probe.remove();
|
|
152
|
+
if (!(width > 0)) return text2.length * size * AVERAGE_WIDTH;
|
|
153
|
+
cache.set(id, width);
|
|
154
|
+
return width;
|
|
155
|
+
};
|
|
156
|
+
return Object.assign(measure, { clear: () => cache.clear() });
|
|
157
|
+
}
|
|
158
|
+
|
|
89
159
|
// src/charts/bar-layout.ts
|
|
90
160
|
var ROW = 34;
|
|
91
161
|
var BAR = 20;
|
|
@@ -99,6 +169,7 @@ var TICK_SIZE = 11;
|
|
|
99
169
|
var AXIS = 26;
|
|
100
170
|
var TOP = 4;
|
|
101
171
|
var PAD = 6;
|
|
172
|
+
var BOTH = { label: true, value: true };
|
|
102
173
|
var CENTRE = 0.36;
|
|
103
174
|
function barEncoding(options) {
|
|
104
175
|
const { x, y, stack, data } = options;
|
|
@@ -148,16 +219,65 @@ function layoutBars(input) {
|
|
|
148
219
|
const texts = rows2.map((row) => input.format(row.total));
|
|
149
220
|
const ticks = domain.ticks.map(input.format);
|
|
150
221
|
const frame = (input.encoding.orientation === "horizontal" ? horizontalFrame : verticalFrame)(input, rows2, domain, texts, ticks);
|
|
222
|
+
const labels = thinLabels(frame, rows2, texts, input.measure);
|
|
151
223
|
return {
|
|
152
224
|
width: frame.bands.width,
|
|
153
225
|
height: frame.bands.height,
|
|
154
226
|
orientation: frame.orientation,
|
|
155
227
|
frame,
|
|
156
|
-
rows: rows2.map((row, slot) => placeRow(frame, { ...row, slot, text: texts[slot] })),
|
|
157
|
-
ticks: domain.ticks.map((value, i) => placeTick(frame, value, ticks[i]))
|
|
228
|
+
rows: rows2.map((row, slot) => placeRow(frame, { ...row, slot, text: texts[slot], drawn: { label: slot % labels.every === 0, value: labels.values } }, input.measure)),
|
|
229
|
+
ticks: domain.ticks.map((value, i) => placeTick(frame, value, ticks[i])),
|
|
230
|
+
labels
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function thinLabels(frame, rows2, texts, measure) {
|
|
234
|
+
const placed2 = rows2.map((row, slot) => placeLabels(frame, slot, row.total, row.category, texts[slot]));
|
|
235
|
+
const horizontal = frame.orientation === "horizontal";
|
|
236
|
+
const values = !overlaps(boxesOf(placed2.map(({ value }) => value), measure, "ec-value", VALUE_SIZE), horizontal);
|
|
237
|
+
const categories = (every) => boxesOf(
|
|
238
|
+
placed2.filter((_, slot) => slot % every === 0).map(({ label: label2 }) => label2),
|
|
239
|
+
measure,
|
|
240
|
+
"ec-label",
|
|
241
|
+
LABEL_SIZE
|
|
242
|
+
);
|
|
243
|
+
let k = 0;
|
|
244
|
+
while (thinStep(k) < rows2.length && overlaps(categories(thinStep(k)), horizontal)) k++;
|
|
245
|
+
return { every: thinStep(k), values };
|
|
246
|
+
}
|
|
247
|
+
var thinStep = (k) => [1, 2, 5][k % 3] * 10 ** Math.floor(k / 3);
|
|
248
|
+
function boxesOf(labels, measure, className, size) {
|
|
249
|
+
return labels.filter((label2) => label2.text !== "").map((label2) => textBox(label2, measure, className, size));
|
|
250
|
+
}
|
|
251
|
+
function overlaps(boxes, horizontal) {
|
|
252
|
+
const along = horizontal ? boxes.map(({ x, y, width, height }) => ({ x: y, y: x, width: height, height: width })) : [...boxes];
|
|
253
|
+
along.sort((a, b) => a.x - b.x);
|
|
254
|
+
const open = [];
|
|
255
|
+
for (const box of along) {
|
|
256
|
+
for (let i = open.length - 1; i >= 0; i--) if (open[i].x + open[i].width <= box.x) open.splice(i, 1);
|
|
257
|
+
if (open.some((other) => other.y < box.y + box.height && box.y < other.y + other.height)) return true;
|
|
258
|
+
open.push(box);
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
function placeLabels(frame, slot, total2, category, text2) {
|
|
263
|
+
const { scale, bands } = frame;
|
|
264
|
+
const negative = total2 < 0;
|
|
265
|
+
const tip = position(scale)(total2);
|
|
266
|
+
const band = bands.start + slot * bands.band;
|
|
267
|
+
if (frame.orientation === "horizontal") {
|
|
268
|
+
const line = band + bands.band / 2 + LABEL_SIZE * CENTRE;
|
|
269
|
+
return {
|
|
270
|
+
label: { x: scale.label, y: line, anchor: "end", text: category },
|
|
271
|
+
value: { x: negative ? tip - PAD : tip + PAD, y: line, anchor: negative ? "end" : "start", text: text2 }
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const centre = band + bands.band / 2;
|
|
275
|
+
return {
|
|
276
|
+
label: { x: centre, y: scale.label, anchor: "middle", text: category },
|
|
277
|
+
value: { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: text2 }
|
|
158
278
|
};
|
|
159
279
|
}
|
|
160
|
-
function placeRow(frame, row) {
|
|
280
|
+
function placeRow(frame, row, measure) {
|
|
161
281
|
const { scale, bands } = frame;
|
|
162
282
|
const at = position(scale);
|
|
163
283
|
const unit = Math.abs(scale.extent / (scale.hi - scale.lo));
|
|
@@ -173,7 +293,10 @@ function placeRow(frame, row) {
|
|
|
173
293
|
gap: GAP,
|
|
174
294
|
segments: row.values.map((v) => ({ series: v.series, size: Math.max(0, negative ? -v.value : v.value) * unit }))
|
|
175
295
|
};
|
|
176
|
-
const
|
|
296
|
+
const drawn2 = row.drawn ?? BOTH;
|
|
297
|
+
const fields = { key: row.key, datum: row.datum, index: row.index, slot: row.slot, values: row.values, total: total2, category: row.category, drawn: drawn2 };
|
|
298
|
+
const { label: label2, value } = placeLabels(frame, row.slot, total2, drawn2.label ? row.category : "", drawn2.value ? row.text : "");
|
|
299
|
+
const boxes = () => [...boxesOf([label2], measure, "ec-label", LABEL_SIZE), ...boxesOf([value], measure, "ec-value", VALUE_SIZE)];
|
|
177
300
|
if (frame.orientation === "horizontal") {
|
|
178
301
|
const geometry2 = describe.bar({
|
|
179
302
|
...bar,
|
|
@@ -181,15 +304,15 @@ function placeRow(frame, row) {
|
|
|
181
304
|
y: band + (bands.band - bands.thickness) / 2,
|
|
182
305
|
width: Math.abs(tip - zero),
|
|
183
306
|
height: bands.thickness,
|
|
184
|
-
baseline: negative ? "right" : "left"
|
|
307
|
+
baseline: negative ? "right" : "left",
|
|
308
|
+
labelBounds: boxes()
|
|
185
309
|
});
|
|
186
|
-
const line = band + bands.band / 2 + LABEL_SIZE * CENTRE;
|
|
187
310
|
return {
|
|
188
311
|
...fields,
|
|
189
312
|
geometry: geometry2,
|
|
190
313
|
data: barData(row.datum, total2, geometry2),
|
|
191
|
-
label:
|
|
192
|
-
value
|
|
314
|
+
label: label2,
|
|
315
|
+
value,
|
|
193
316
|
hit: { x: 0, y: band, width: bands.width, height: bands.band }
|
|
194
317
|
};
|
|
195
318
|
}
|
|
@@ -200,14 +323,15 @@ function placeRow(frame, row) {
|
|
|
200
323
|
y: Math.min(zero, tip),
|
|
201
324
|
width: bands.thickness,
|
|
202
325
|
height: Math.abs(tip - zero),
|
|
203
|
-
baseline: negative ? "top" : "bottom"
|
|
326
|
+
baseline: negative ? "top" : "bottom",
|
|
327
|
+
labelBounds: boxes()
|
|
204
328
|
});
|
|
205
329
|
return {
|
|
206
330
|
...fields,
|
|
207
331
|
geometry,
|
|
208
332
|
data: barData(row.datum, total2, geometry),
|
|
209
|
-
label:
|
|
210
|
-
value
|
|
333
|
+
label: label2,
|
|
334
|
+
value,
|
|
211
335
|
hit: { x: band, y: 0, width: bands.band, height: bands.height }
|
|
212
336
|
};
|
|
213
337
|
}
|
|
@@ -260,9 +384,9 @@ function niceDomain(values) {
|
|
|
260
384
|
const ticks = Array.from({ length: count + 1 }, (_, i) => clean(lo + i * step2));
|
|
261
385
|
return { lo, hi, ticks };
|
|
262
386
|
}
|
|
263
|
-
function niceStep(
|
|
264
|
-
const power = 10 ** Math.floor(Math.log10(
|
|
265
|
-
const f =
|
|
387
|
+
function niceStep(span2) {
|
|
388
|
+
const power = 10 ** Math.floor(Math.log10(span2));
|
|
389
|
+
const f = span2 / power;
|
|
266
390
|
return (f <= 1 ? 1 : f <= 2 ? 2 : f <= 5 ? 5 : 10) * power;
|
|
267
391
|
}
|
|
268
392
|
function horizontalFrame(input, rows2, domain, values, ticks) {
|
|
@@ -271,9 +395,10 @@ function horizontalFrame(input, rows2, domain, values, ticks) {
|
|
|
271
395
|
const labelWidth = widest(rows2.map((row) => row.category), "ec-label", LABEL_SIZE, measure);
|
|
272
396
|
const valueWidth = widest(values, "ec-value", VALUE_SIZE, measure);
|
|
273
397
|
const tickWidth = widest(ticks, "ec-tick", TICK_SIZE, measure);
|
|
398
|
+
const { positive, negative } = reach(input, rows2);
|
|
274
399
|
const negativeRoom = domain.lo < 0 ? valueWidth + PAD : 0;
|
|
275
|
-
const left = Math.max(labelWidth + 10 + negativeRoom, tickWidth / 2 + 2);
|
|
276
|
-
const right = Math.max(valueWidth + PAD + 4, tickWidth / 2 + 2);
|
|
400
|
+
const left = Math.max(labelWidth + 10 + negativeRoom + negative, tickWidth / 2 + 2);
|
|
401
|
+
const right = Math.max(valueWidth + PAD + 4 + positive, tickWidth / 2 + 2);
|
|
277
402
|
const rowSize = input.height === void 0 || n === 0 ? ROW : Math.max(0, input.height - TOP - AXIS) / n;
|
|
278
403
|
return {
|
|
279
404
|
orientation: "horizontal",
|
|
@@ -286,8 +411,9 @@ function verticalFrame(input, rows2, domain, _values, ticks) {
|
|
|
286
411
|
const n = rows2.length;
|
|
287
412
|
const height = input.height ?? VERTICAL_HEIGHT;
|
|
288
413
|
const tickWidth = widest(ticks, "ec-tick", TICK_SIZE, measure);
|
|
289
|
-
const
|
|
290
|
-
const
|
|
414
|
+
const { positive, negative } = reach(input, rows2);
|
|
415
|
+
const top = (domain.hi > 0 ? VALUE_SIZE + PAD + 2 : TOP) + positive;
|
|
416
|
+
const bottom = AXIS + (domain.lo < 0 ? VALUE_SIZE + PAD : 0) + negative;
|
|
291
417
|
const left = tickWidth + 8 + 2;
|
|
292
418
|
const plot = { x: left, y: top, width: Math.max(0, width - left - 8), height: Math.max(0, height - top - bottom) };
|
|
293
419
|
const band = n > 0 ? plot.width / n : 0;
|
|
@@ -298,6 +424,13 @@ function verticalFrame(input, rows2, domain, _values, ticks) {
|
|
|
298
424
|
bands: { start: plot.x, band, thickness: Math.min(band * BAR / ROW, MAX_COLUMN), span: plot.width, width, height }
|
|
299
425
|
};
|
|
300
426
|
}
|
|
427
|
+
function reach(input, rows2) {
|
|
428
|
+
const room = input.room ?? 0;
|
|
429
|
+
return {
|
|
430
|
+
positive: rows2.some((row) => row.total > 0) ? room : 0,
|
|
431
|
+
negative: rows2.some((row) => row.total < 0) ? room : 0
|
|
432
|
+
};
|
|
433
|
+
}
|
|
301
434
|
function barData(datum, total2, geometry) {
|
|
302
435
|
const valueAt = (distance3) => geometry.length > 0 ? total2 * distance3 / geometry.length : 0;
|
|
303
436
|
const data = {
|
|
@@ -444,27 +577,29 @@ ${TOKEN_RULES}
|
|
|
444
577
|
:where(.ec-chart .ec-tick) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 11px; }
|
|
445
578
|
:where(.ec-chart .ec-label) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; }
|
|
446
579
|
:where(.ec-chart .ec-value, .ec-chart .ec-text) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; font-weight: 600; }
|
|
580
|
+
:where(.ec-overlay .ec-text) { fill: var(--ec-text, ${TOKENS.text}); font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
447
581
|
:where(.ec-chart .ec-hit) { fill: transparent; }
|
|
448
582
|
:where(.ec-chart .ec-mark:focus) { outline: none; }
|
|
449
583
|
:where(.ec-chart .ec-focus) { pointer-events: none; }
|
|
450
584
|
:where(.ec-chart .ec-focus-ring) { fill: none; stroke: var(--ec-focus, ${TOKENS.focus}); }
|
|
451
585
|
:where(.ec-chart .ec-focus-gap) { fill: var(--ec-surface, ${TOKENS.surface}); stroke: var(--ec-surface, ${TOKENS.surface}); }
|
|
452
|
-
:where(.ec-chart .ec-
|
|
453
|
-
:where(.ec-chart .ec-segment) { fill: var(--ec-mark); transition: fill var(--ec-hover-duration, 100ms) ease-out; }
|
|
586
|
+
:where(.ec-chart .ec-body > *) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
587
|
+
:where(.ec-chart .ec-segment) { fill: var(--ec-mark); transition: fill var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
454
588
|
:where(.ec-chart .ec-hot .ec-segment) { fill: var(--ec-mark-strong); }
|
|
455
|
-
:where(.ec-chart .ec-stroke) { fill: none; stroke: var(--ec-mark); stroke-linejoin: round; transition: stroke var(--ec-hover-duration, 100ms) ease-out; }
|
|
589
|
+
:where(.ec-chart .ec-stroke) { fill: none; stroke: var(--ec-mark); stroke-linejoin: round; transition: stroke var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
456
590
|
:where(.ec-chart .ec-hot .ec-stroke) { stroke: var(--ec-mark-strong); }
|
|
457
591
|
:where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
|
|
458
592
|
: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; }
|
|
459
593
|
:where(.ec-chart .ec-hot .ec-dot) { fill: var(--ec-mark-strong); opacity: 1; }
|
|
594
|
+
:where(.ec-chart .ec-alone .ec-dot) { opacity: 1; }
|
|
460
595
|
:where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
|
|
461
596
|
:where(.ec-chart .ec-column:focus) { outline: none; }
|
|
462
597
|
:where(.ec-chart .ec-lines, .ec-chart .ec-points) { pointer-events: none; }
|
|
463
|
-
:where(.ec-chart .ec-slice) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; stroke-linejoin: round; transition: fill var(--ec-hover-duration, 100ms) ease-out; }
|
|
598
|
+
:where(.ec-chart .ec-slice) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; stroke-linejoin: round; transition: fill var(--ec-hover-duration, 100ms) ease-out, opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
464
599
|
:where(.ec-chart .ec-hot .ec-slice) { fill: var(--ec-mark-strong); }
|
|
465
600
|
:where(.ec-chart .ec-center-value) { fill: var(--ec-text, ${TOKENS.text}); font-size: 26px; font-weight: 600; }
|
|
466
601
|
:where(.ec-chart .ec-center-label) { fill: var(--ec-text-muted, ${TOKENS["text-muted"]}); font-size: 12.5px; }
|
|
467
|
-
:where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot)) { opacity: var(--ec-dim-opacity, 0.3); }
|
|
602
|
+
:where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
|
|
468
603
|
:where(.ec-chart.ec-morphing .ec-marks) { visibility: hidden; }
|
|
469
604
|
:where(.ec-switch) { display: grid; grid-template-columns: minmax(0, 1fr); position: relative; }
|
|
470
605
|
:where(.ec-switch-view) { grid-area: 1 / 1; min-width: 0; }
|
|
@@ -491,7 +626,10 @@ ${TOKEN_RULES}
|
|
|
491
626
|
: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; }
|
|
492
627
|
:where(.ec-tooltip-layer) { position: relative; height: 0; }
|
|
493
628
|
: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); }
|
|
494
|
-
:where(.ec-tooltip.ec-tooltip-shown) { opacity: 1; visibility: visible; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
629
|
+
:where(.ec-tooltip.ec-tooltip-shown) { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
630
|
+
:where(.ec-tooltip-bridge) { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; }
|
|
631
|
+
:where(.ec-tooltip-shown + .ec-tooltip-bridge) { pointer-events: auto; }
|
|
632
|
+
:where(.ec-tooltip-through > .ec-tooltip, .ec-tooltip-through > .ec-tooltip-bridge) { pointer-events: none; }
|
|
495
633
|
:where(.ec-tooltip-title) { font-weight: 600; }
|
|
496
634
|
: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}); }
|
|
497
635
|
:where(.ec-legend-item) { display: inline-flex; align-items: center; gap: 6px; }
|
|
@@ -556,8 +694,8 @@ function checkLegendOption(option, chart) {
|
|
|
556
694
|
if (entries === void 0) return;
|
|
557
695
|
if (!Array.isArray(entries)) fail("legend.entries must be an array of { label, color }.");
|
|
558
696
|
entries.forEach((entry, i) => {
|
|
559
|
-
const { label, color } = typeof entry === "object" && entry !== null ? entry : fail(`legend.entries[${i}] must be an object with a label and a color.`);
|
|
560
|
-
if (typeof
|
|
697
|
+
const { label: label2, color } = typeof entry === "object" && entry !== null ? entry : fail(`legend.entries[${i}] must be an object with a label and a color.`);
|
|
698
|
+
if (typeof label2 !== "string" || label2.trim() === "") fail(`legend.entries[${i}].label must be a non-empty string: the entry's name.`);
|
|
561
699
|
if (typeof color !== "string" || color.trim() === "") fail(`legend.entries[${i}].color must be a theme token or a CSS colour.`);
|
|
562
700
|
if (color === "mark" || color === "mark-strong") fail(`legend.entries[${i}].color can't be "${color}": an entry has no mark. Use a theme token or a CSS colour.`);
|
|
563
701
|
});
|
|
@@ -565,23 +703,23 @@ function checkLegendOption(option, chart) {
|
|
|
565
703
|
var extras = (option) => typeof option === "object" ? option.entries ?? [] : [];
|
|
566
704
|
function chartLegend(svg) {
|
|
567
705
|
let legend;
|
|
568
|
-
let
|
|
706
|
+
let drawn2 = "";
|
|
569
707
|
const remove = () => {
|
|
570
708
|
legend?.remove();
|
|
571
709
|
legend = void 0;
|
|
572
|
-
|
|
710
|
+
drawn2 = "";
|
|
573
711
|
};
|
|
574
712
|
const draw = (entries, colors, attribute, more) => {
|
|
575
713
|
const items = [
|
|
576
|
-
...entries.map(({ key, label }) => ({ key, label, styles: markColorStyles(seriesColors(colors.slot(key))) })),
|
|
577
|
-
...more.map(({ label, color }) => ({ key: void 0, label, styles: { "--ec-mark": cssColor(color) } }))
|
|
714
|
+
...entries.map(({ key, label: label2 }) => ({ key, label: label2, styles: markColorStyles(seriesColors(colors.slot(key))) })),
|
|
715
|
+
...more.map(({ label: label2, color }) => ({ key: void 0, label: label2, styles: { "--ec-mark": cssColor(color) } }))
|
|
578
716
|
];
|
|
579
717
|
const doc = svg.ownerDocument;
|
|
580
718
|
legend ?? (legend = Object.assign(doc.createElement("div"), { className: "ec-legend" }));
|
|
581
719
|
if (legend.nextSibling !== svg) svg.before(legend);
|
|
582
720
|
const id = JSON.stringify([attribute, items]);
|
|
583
|
-
if (id ===
|
|
584
|
-
|
|
721
|
+
if (id === drawn2) return;
|
|
722
|
+
drawn2 = id;
|
|
585
723
|
legend.replaceChildren(
|
|
586
724
|
...items.map(({ key, label: text2, styles }) => {
|
|
587
725
|
const item = doc.createElement("span");
|
|
@@ -590,10 +728,10 @@ function chartLegend(svg) {
|
|
|
590
728
|
for (const [property, value] of Object.entries(styles)) if (value !== void 0) item.style.setProperty(property, value);
|
|
591
729
|
const swatch = doc.createElement("span");
|
|
592
730
|
swatch.className = "ec-legend-swatch";
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
item.append(swatch,
|
|
731
|
+
const label2 = doc.createElement("span");
|
|
732
|
+
label2.className = "ec-legend-label";
|
|
733
|
+
label2.textContent = text2;
|
|
734
|
+
item.append(swatch, label2);
|
|
597
735
|
return item;
|
|
598
736
|
})
|
|
599
737
|
);
|
|
@@ -602,7 +740,7 @@ function chartLegend(svg) {
|
|
|
602
740
|
update(series, colors, option) {
|
|
603
741
|
const more = extras(option);
|
|
604
742
|
if (option === false || series.length + more.length < 2) remove();
|
|
605
|
-
else draw(series.map(({ series: key, label }) => ({ key, label })), colors, "data-series", more);
|
|
743
|
+
else draw(series.map(({ series: key, label: label2 }) => ({ key, label: label2 })), colors, "data-series", more);
|
|
606
744
|
},
|
|
607
745
|
categories(categories, colors, option) {
|
|
608
746
|
if (option === false || categories.length === 0) remove();
|
|
@@ -612,6 +750,100 @@ function chartLegend(svg) {
|
|
|
612
750
|
};
|
|
613
751
|
}
|
|
614
752
|
|
|
753
|
+
// src/charts/link.ts
|
|
754
|
+
var own = (hovered) => hovered !== void 0 && hovered.source !== "linked";
|
|
755
|
+
var ports = /* @__PURE__ */ new WeakMap();
|
|
756
|
+
var linked = /* @__PURE__ */ new WeakSet();
|
|
757
|
+
function linkable(port, handle) {
|
|
758
|
+
ports.set(handle, port);
|
|
759
|
+
return handle;
|
|
760
|
+
}
|
|
761
|
+
var portOf = (handle) => ports.get(handle);
|
|
762
|
+
function link(sources, options = {}) {
|
|
763
|
+
if (!Array.isArray(sources)) throw new TypeError("link needs an array of charts and attachments: link([columns, line]).");
|
|
764
|
+
if (typeof options !== "object" || options === null) throw new TypeError("link: options must be an object, such as { by: (event) => event.data.datum.week }.");
|
|
765
|
+
const { by, effects = true } = options;
|
|
766
|
+
if (by !== void 0 && typeof by !== "function") throw new TypeError("link: by must be a function, such as (event) => event.data.datum.week.");
|
|
767
|
+
if (typeof effects !== "boolean") throw new TypeError(`link: effects must be true or false, got ${String(effects)}.`);
|
|
768
|
+
const members = [];
|
|
769
|
+
for (const source of sources) {
|
|
770
|
+
const port = typeof source === "object" && source !== null ? ports.get(source) : void 0;
|
|
771
|
+
if (!port) {
|
|
772
|
+
throw new TypeError("link: each source must be a chart (barChart, donutChart or lineChart) or an attachment (expressive or fromVegaView). A chartSwitch can't be linked yet.");
|
|
773
|
+
}
|
|
774
|
+
if (linked.has(port) || members.includes(port)) throw new TypeError("link: a chart or attachment can be in one link at a time. Destroy the link it's in first.");
|
|
775
|
+
members.push(port);
|
|
776
|
+
}
|
|
777
|
+
const live = /* @__PURE__ */ new Set();
|
|
778
|
+
let origin;
|
|
779
|
+
function valueOf(input) {
|
|
780
|
+
let value;
|
|
781
|
+
if (by) {
|
|
782
|
+
try {
|
|
783
|
+
value = by(input);
|
|
784
|
+
} catch (error) {
|
|
785
|
+
report(error);
|
|
786
|
+
return void 0;
|
|
787
|
+
}
|
|
788
|
+
} else {
|
|
789
|
+
const { samples } = input.data;
|
|
790
|
+
value = samples[samples.length - 1]?.at ?? input.mark.key;
|
|
791
|
+
}
|
|
792
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? void 0 : value.toISOString();
|
|
793
|
+
return value === void 0 || value === null ? void 0 : String(value);
|
|
794
|
+
}
|
|
795
|
+
function hovered(from, marks) {
|
|
796
|
+
origin = from;
|
|
797
|
+
const values = new Set(marks.map(valueOf));
|
|
798
|
+
values.delete(void 0);
|
|
799
|
+
const matches = (target) => target.some((mark) => {
|
|
800
|
+
const value = valueOf(mark);
|
|
801
|
+
return value !== void 0 && values.has(value);
|
|
802
|
+
});
|
|
803
|
+
for (const port of live) {
|
|
804
|
+
if (port === from) continue;
|
|
805
|
+
const keys = values.size === 0 ? [] : port.targets().flatMap((target) => matches(target.marks) ? [target.key] : []);
|
|
806
|
+
port.hover(keys, effects);
|
|
807
|
+
if (origin !== from) return;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function left(from) {
|
|
811
|
+
if (origin !== from) return;
|
|
812
|
+
origin = void 0;
|
|
813
|
+
for (const port of live) port.unlink();
|
|
814
|
+
}
|
|
815
|
+
for (const port of members) {
|
|
816
|
+
const listening = port.listen({
|
|
817
|
+
hover: (marks) => hovered(port, marks),
|
|
818
|
+
leave: () => left(port),
|
|
819
|
+
dismiss() {
|
|
820
|
+
const from = origin;
|
|
821
|
+
from?.leave();
|
|
822
|
+
if (from) left(from);
|
|
823
|
+
},
|
|
824
|
+
gone() {
|
|
825
|
+
live.delete(port);
|
|
826
|
+
linked.delete(port);
|
|
827
|
+
left(port);
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
if (!listening) continue;
|
|
831
|
+
live.add(port);
|
|
832
|
+
linked.add(port);
|
|
833
|
+
}
|
|
834
|
+
return {
|
|
835
|
+
destroy() {
|
|
836
|
+
for (const port of live) {
|
|
837
|
+
port.listen(void 0);
|
|
838
|
+
port.unlink();
|
|
839
|
+
linked.delete(port);
|
|
840
|
+
}
|
|
841
|
+
live.clear();
|
|
842
|
+
origin = void 0;
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
|
|
615
847
|
// src/charts/motion.ts
|
|
616
848
|
var MODES = ["presentation", "analysis", "off"];
|
|
617
849
|
function chartMotion(option, page) {
|
|
@@ -634,39 +866,6 @@ function chartMotion(option, page) {
|
|
|
634
866
|
};
|
|
635
867
|
}
|
|
636
868
|
|
|
637
|
-
// src/charts/render/svg.ts
|
|
638
|
-
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
639
|
-
function svgElement(tag, attributes = {}, parent) {
|
|
640
|
-
const doc = parent?.ownerDocument ?? document;
|
|
641
|
-
const element = doc.createElementNS(SVG_NS, tag);
|
|
642
|
-
setAttributes(element, attributes);
|
|
643
|
-
parent?.appendChild(element);
|
|
644
|
-
return element;
|
|
645
|
-
}
|
|
646
|
-
function setAttributes(element, attributes) {
|
|
647
|
-
for (const [name, value] of Object.entries(attributes)) {
|
|
648
|
-
if (value === void 0) element.removeAttribute(name);
|
|
649
|
-
else element.setAttribute(name, typeof value === "number" ? formatNumber(value) : value);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
function setStyles(element, styles) {
|
|
653
|
-
for (const [name, value] of Object.entries(styles)) {
|
|
654
|
-
if (value === void 0) element.style.removeProperty(name);
|
|
655
|
-
else element.style.setProperty(name, value);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
function sizeAttributes({ width, height }) {
|
|
659
|
-
return { width, height, viewBox: `0 0 ${formatNumber(width)} ${formatNumber(height)}` };
|
|
660
|
-
}
|
|
661
|
-
function transformAttribute(m) {
|
|
662
|
-
const [a, b, c, d, e, f] = m;
|
|
663
|
-
return `matrix(${[a, b, c, d].map(linear2).join(" ")} ${formatNumber(e)} ${formatNumber(f)})`;
|
|
664
|
-
}
|
|
665
|
-
function linear2(value) {
|
|
666
|
-
const rounded = Math.round(value * 1e6) / 1e6;
|
|
667
|
-
return rounded === 0 ? "0" : String(rounded);
|
|
668
|
-
}
|
|
669
|
-
|
|
670
869
|
// src/charts/render/outside.ts
|
|
671
870
|
var RING_GAP = 2;
|
|
672
871
|
var RING = 2;
|
|
@@ -706,8 +905,8 @@ function maskedHalo() {
|
|
|
706
905
|
group = void 0;
|
|
707
906
|
};
|
|
708
907
|
return {
|
|
709
|
-
paint(container,
|
|
710
|
-
if (!halo || !container ||
|
|
908
|
+
paint(container, parts2, halo, transform) {
|
|
909
|
+
if (!halo || !container || parts2.length === 0) {
|
|
711
910
|
remove();
|
|
712
911
|
return;
|
|
713
912
|
}
|
|
@@ -719,12 +918,12 @@ function maskedHalo() {
|
|
|
719
918
|
const id = `ec-halo-mask-${++haloMasks}`;
|
|
720
919
|
const mask = svgElement("mask", { id, maskUnits: "userSpaceOnUse", x: -1e5, y: -1e5, width: 2e5, height: 2e5 }, group);
|
|
721
920
|
svgElement("rect", { x: -1e5, y: -1e5, width: 2e5, height: 2e5, fill: "white" }, mask);
|
|
722
|
-
for (const part of
|
|
921
|
+
for (const part of parts2) {
|
|
723
922
|
const cut = part.stroke === void 0 ? { fill: "black" } : { fill: "none", stroke: "black", "stroke-width": part.stroke, "stroke-linejoin": "round" };
|
|
724
923
|
svgElement("path", { d: part.d, ...cut }, mask);
|
|
725
924
|
}
|
|
726
925
|
setAttributes(group, { transform: transform && transformAttribute(transform) });
|
|
727
|
-
for (const part of
|
|
926
|
+
for (const part of parts2) {
|
|
728
927
|
const open = part.stroke !== void 0;
|
|
729
928
|
const path = svgElement(
|
|
730
929
|
"path",
|
|
@@ -746,24 +945,24 @@ function svgMarkHandle(target, options = {}) {
|
|
|
746
945
|
const repaint = () => {
|
|
747
946
|
const current = target();
|
|
748
947
|
if (!current) return;
|
|
749
|
-
const { body, parts } = current;
|
|
948
|
+
const { body, parts: parts2 } = current;
|
|
750
949
|
setAttributes(body, {
|
|
751
950
|
transform: style.transform && transformAttribute(style.transform),
|
|
752
951
|
opacity: style.opacity
|
|
753
952
|
});
|
|
754
953
|
const emphasis = style.emphasis;
|
|
755
|
-
for (const part of
|
|
954
|
+
for (const part of parts2) {
|
|
756
955
|
setStyles(part.element, {
|
|
757
956
|
[part.open ? "stroke" : "fill"]: emphasis === void 0 ? void 0 : mix(part.colors, emphasis),
|
|
758
957
|
transition: emphasis === void 0 ? void 0 : "none"
|
|
759
958
|
});
|
|
760
959
|
}
|
|
761
|
-
paintHalo(body,
|
|
960
|
+
paintHalo(body, parts2);
|
|
762
961
|
};
|
|
763
|
-
const paintHalo = (body,
|
|
962
|
+
const paintHalo = (body, parts2) => {
|
|
764
963
|
const spec = style.halo;
|
|
765
964
|
if (above) {
|
|
766
|
-
const visible2 =
|
|
965
|
+
const visible2 = parts2.flatMap((part) => part.visible ? [{ d: part.d, color: part.colors.color, ...part.open ? { stroke: part.open.width } : {} }] : []);
|
|
767
966
|
above.paint(options.halos?.(), visible2, spec, style.transform);
|
|
768
967
|
return;
|
|
769
968
|
}
|
|
@@ -777,7 +976,7 @@ function svgMarkHandle(target, options = {}) {
|
|
|
777
976
|
halo = svgElement("g", { class: "ec-halo" }, body);
|
|
778
977
|
body.insertBefore(halo, body.firstChild);
|
|
779
978
|
}
|
|
780
|
-
const visible =
|
|
979
|
+
const visible = parts2.filter((part) => part.visible);
|
|
781
980
|
while (halo.childElementCount > visible.length) halo.lastElementChild?.remove();
|
|
782
981
|
visible.forEach((part, index) => {
|
|
783
982
|
const path = halo.children[index] ?? svgElement("path", { "stroke-linejoin": "round" }, halo);
|
|
@@ -819,15 +1018,15 @@ function svgLayer(group) {
|
|
|
819
1018
|
icon(icon, options) {
|
|
820
1019
|
const size = options?.size;
|
|
821
1020
|
if (size !== void 0 && !(size >= 0)) throw new RangeError(`layer.icon: size must be a non-negative number, got ${String(size)}.`);
|
|
822
|
-
const
|
|
1021
|
+
const placed2 = svgElement("g", { class: "ec-icon", "data-icon": icon.name, visibility: "hidden" }, group);
|
|
823
1022
|
const k = size === void 0 || !(icon.size > 0) ? 1 : size / icon.size;
|
|
824
|
-
const body = k === 1 ?
|
|
1023
|
+
const body = k === 1 ? placed2 : svgElement("g", { transform: transformAttribute(matrix.scale(k, k, icon.anchor)) }, placed2);
|
|
825
1024
|
for (const shape of icon.shapes) drawShape(shape, body);
|
|
826
1025
|
const handle = {
|
|
827
1026
|
place(transform) {
|
|
828
|
-
setAttributes(
|
|
1027
|
+
setAttributes(placed2, { transform: transformAttribute(transform), visibility: void 0 });
|
|
829
1028
|
},
|
|
830
|
-
remove: () =>
|
|
1029
|
+
remove: () => placed2.remove()
|
|
831
1030
|
};
|
|
832
1031
|
return handle;
|
|
833
1032
|
},
|
|
@@ -878,7 +1077,9 @@ function drawShape(shape, parent) {
|
|
|
878
1077
|
"clip-path": clip && `url(#${clip})`,
|
|
879
1078
|
"stroke-width": shape.stroke === void 0 ? void 0 : shape.width ?? 1,
|
|
880
1079
|
"stroke-linecap": shape.linecap,
|
|
881
|
-
"stroke-linejoin": shape.linejoin
|
|
1080
|
+
"stroke-linejoin": shape.linejoin,
|
|
1081
|
+
"fill-rule": shape.fillRule,
|
|
1082
|
+
opacity: shape.opacity
|
|
882
1083
|
},
|
|
883
1084
|
parent
|
|
884
1085
|
);
|
|
@@ -946,35 +1147,6 @@ function svgSurface(options) {
|
|
|
946
1147
|
};
|
|
947
1148
|
}
|
|
948
1149
|
|
|
949
|
-
// src/charts/render/text.ts
|
|
950
|
-
function placeText(element, placement) {
|
|
951
|
-
setAttributes(element, { x: placement.x, y: placement.y, "text-anchor": placement.anchor });
|
|
952
|
-
if (element.textContent !== placement.text) element.textContent = placement.text;
|
|
953
|
-
}
|
|
954
|
-
var AVERAGE_WIDTH = 0.6;
|
|
955
|
-
function textMeasure(svg) {
|
|
956
|
-
const cache = /* @__PURE__ */ new Map();
|
|
957
|
-
const measure = (text2, className, size) => {
|
|
958
|
-
if (text2 === "") return 0;
|
|
959
|
-
const id = `${className}
|
|
960
|
-
${size}
|
|
961
|
-
${text2}`;
|
|
962
|
-
const cached = cache.get(id);
|
|
963
|
-
if (cached !== void 0) return cached;
|
|
964
|
-
let width = 0;
|
|
965
|
-
const probe = svgElement("text", { class: className, visibility: "hidden", "aria-hidden": "true" }, svg);
|
|
966
|
-
if (typeof probe.getComputedTextLength === "function" && svg.isConnected) {
|
|
967
|
-
probe.textContent = text2;
|
|
968
|
-
width = probe.getComputedTextLength();
|
|
969
|
-
}
|
|
970
|
-
probe.remove();
|
|
971
|
-
if (!(width > 0)) return text2.length * size * AVERAGE_WIDTH;
|
|
972
|
-
cache.set(id, width);
|
|
973
|
-
return width;
|
|
974
|
-
};
|
|
975
|
-
return Object.assign(measure, { clear: () => cache.clear() });
|
|
976
|
-
}
|
|
977
|
-
|
|
978
1150
|
// src/charts/series.ts
|
|
979
1151
|
function seriesLabel(labels, series) {
|
|
980
1152
|
return labels !== void 0 && Object.prototype.hasOwnProperty.call(labels, series) ? labels[series] ?? series : series;
|
|
@@ -982,8 +1154,8 @@ function seriesLabel(labels, series) {
|
|
|
982
1154
|
function checkSeriesLabels(option, chart) {
|
|
983
1155
|
if (option === void 0) return;
|
|
984
1156
|
if (typeof option !== "object" || option === null || Array.isArray(option)) throw new TypeError(`${chart}: seriesLabels must be an object of names by series, as { goals: "Goals" }.`);
|
|
985
|
-
for (const [series,
|
|
986
|
-
if (typeof
|
|
1157
|
+
for (const [series, label2] of Object.entries(option)) {
|
|
1158
|
+
if (typeof label2 !== "string" || label2.trim() === "") throw new TypeError(`${chart}: seriesLabels.${series} must be a name, not ${typeof label2 === "string" ? "blank" : String(label2)}.`);
|
|
987
1159
|
}
|
|
988
1160
|
}
|
|
989
1161
|
|
|
@@ -1047,6 +1219,9 @@ function pointerHover(svg, options) {
|
|
|
1047
1219
|
const doc = svg.ownerDocument;
|
|
1048
1220
|
let current;
|
|
1049
1221
|
let lastPointer = "mouse";
|
|
1222
|
+
let held;
|
|
1223
|
+
let watcher;
|
|
1224
|
+
let still;
|
|
1050
1225
|
const enter = (target, source) => {
|
|
1051
1226
|
if (target?.key === current) return;
|
|
1052
1227
|
leave2();
|
|
@@ -1055,15 +1230,91 @@ function pointerHover(svg, options) {
|
|
|
1055
1230
|
options.hover(target, source);
|
|
1056
1231
|
};
|
|
1057
1232
|
const leave2 = () => {
|
|
1233
|
+
letGo();
|
|
1058
1234
|
if (current === void 0) return;
|
|
1059
1235
|
current = void 0;
|
|
1060
1236
|
options.leave();
|
|
1061
1237
|
};
|
|
1238
|
+
const tooltipHolding = (node) => {
|
|
1239
|
+
const tip = options.tooltip?.();
|
|
1240
|
+
return tip?.element && node && tip.element.contains(node) ? tip : void 0;
|
|
1241
|
+
};
|
|
1242
|
+
const elementAt = (x, y) => {
|
|
1243
|
+
const root = svg.getRootNode();
|
|
1244
|
+
return typeof root.elementFromPoint === "function" ? root.elementFromPoint(x, y) : void 0;
|
|
1245
|
+
};
|
|
1246
|
+
const landing = (event) => event.relatedTarget ?? elementAt(event.clientX, event.clientY) ?? null;
|
|
1247
|
+
const arrive = (element, x, y) => {
|
|
1248
|
+
const tip = tooltipHolding(element);
|
|
1249
|
+
if (tip) hold(tip, x, y);
|
|
1250
|
+
else enter(element && svg.contains(element) ? options.find(element) : void 0, "pointer");
|
|
1251
|
+
};
|
|
1252
|
+
const hold = (tip, x, y) => {
|
|
1253
|
+
enter({ key: tip.key }, "pointer");
|
|
1254
|
+
const element = tip.element;
|
|
1255
|
+
if (held?.element === element) {
|
|
1256
|
+
held.x = x;
|
|
1257
|
+
held.y = y;
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
letGo();
|
|
1261
|
+
held = { element, x, y };
|
|
1262
|
+
element.addEventListener("pointermove", track);
|
|
1263
|
+
element.addEventListener("pointerleave", off);
|
|
1264
|
+
watcher = new MutationObserver(recheck);
|
|
1265
|
+
watcher.observe(element, { attributes: true, childList: true, characterData: true, subtree: true });
|
|
1266
|
+
};
|
|
1267
|
+
const letGo = () => {
|
|
1268
|
+
if (!held) return;
|
|
1269
|
+
held.element.removeEventListener("pointermove", track);
|
|
1270
|
+
held.element.removeEventListener("pointerleave", off);
|
|
1271
|
+
watcher?.disconnect();
|
|
1272
|
+
watcher = void 0;
|
|
1273
|
+
held = void 0;
|
|
1274
|
+
};
|
|
1275
|
+
const track = (event) => {
|
|
1276
|
+
if (!held || event.pointerType === "touch") return;
|
|
1277
|
+
held.x = event.clientX;
|
|
1278
|
+
held.y = event.clientY;
|
|
1279
|
+
};
|
|
1280
|
+
const off = (event) => {
|
|
1281
|
+
if (event.pointerType === "touch") return;
|
|
1282
|
+
letGo();
|
|
1283
|
+
arrive(landing(event), event.clientX, event.clientY);
|
|
1284
|
+
};
|
|
1285
|
+
const recheck = () => {
|
|
1286
|
+
if (!held) return;
|
|
1287
|
+
const { x, y } = held;
|
|
1288
|
+
const under = elementAt(x, y);
|
|
1289
|
+
if (under === void 0) return;
|
|
1290
|
+
const tip = options.tooltip?.();
|
|
1291
|
+
const onTip = tip?.element !== void 0 && under !== null && tip.element.contains(under);
|
|
1292
|
+
if (onTip && tip.key === current) return;
|
|
1293
|
+
letGo();
|
|
1294
|
+
if (!onTip && tip?.key !== current) {
|
|
1295
|
+
still = { x, y };
|
|
1296
|
+
leave2();
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
arrive(under, x, y);
|
|
1300
|
+
};
|
|
1301
|
+
const resting = (event) => {
|
|
1302
|
+
if (still && Math.abs(event.clientX - still.x) < 1 && Math.abs(event.clientY - still.y) < 1) return true;
|
|
1303
|
+
still = void 0;
|
|
1304
|
+
return false;
|
|
1305
|
+
};
|
|
1062
1306
|
const over = (event) => {
|
|
1063
|
-
if (event.pointerType
|
|
1307
|
+
if (event.pointerType === "touch" || resting(event)) return;
|
|
1308
|
+
letGo();
|
|
1309
|
+
enter(options.find(event.target), "pointer");
|
|
1064
1310
|
};
|
|
1065
1311
|
const out = (event) => {
|
|
1066
|
-
if (event.pointerType
|
|
1312
|
+
if (event.pointerType === "touch") return;
|
|
1313
|
+
still = void 0;
|
|
1314
|
+
arrive(landing(event), event.clientX, event.clientY);
|
|
1315
|
+
};
|
|
1316
|
+
const move = (event) => {
|
|
1317
|
+
if (event.pointerType !== "touch") resting(event);
|
|
1067
1318
|
};
|
|
1068
1319
|
const down = (event) => {
|
|
1069
1320
|
lastPointer = event.pointerType;
|
|
@@ -1072,10 +1323,13 @@ function pointerHover(svg, options) {
|
|
|
1072
1323
|
if (lastPointer === "touch") enter(options.find(event.target), "touch");
|
|
1073
1324
|
};
|
|
1074
1325
|
const elsewhere = (event) => {
|
|
1075
|
-
if (current
|
|
1326
|
+
if (current === void 0 || event.pointerType !== "touch") return;
|
|
1327
|
+
const target = event.composedPath()[0] ?? event.target;
|
|
1328
|
+
if (!svg.contains(target) && !tooltipHolding(target)) leave2();
|
|
1076
1329
|
};
|
|
1077
1330
|
svg.addEventListener("pointerover", over);
|
|
1078
1331
|
svg.addEventListener("pointerleave", out);
|
|
1332
|
+
svg.addEventListener("pointermove", move);
|
|
1079
1333
|
svg.addEventListener("pointerdown", down);
|
|
1080
1334
|
svg.addEventListener("click", click);
|
|
1081
1335
|
doc.addEventListener("pointerdown", elsewhere, true);
|
|
@@ -1083,11 +1337,16 @@ function pointerHover(svg, options) {
|
|
|
1083
1337
|
get current() {
|
|
1084
1338
|
return current;
|
|
1085
1339
|
},
|
|
1086
|
-
clear
|
|
1340
|
+
clear() {
|
|
1341
|
+
if (held) still = { x: held.x, y: held.y };
|
|
1342
|
+
leave2();
|
|
1343
|
+
},
|
|
1087
1344
|
destroy() {
|
|
1345
|
+
letGo();
|
|
1088
1346
|
current = void 0;
|
|
1089
1347
|
svg.removeEventListener("pointerover", over);
|
|
1090
1348
|
svg.removeEventListener("pointerleave", out);
|
|
1349
|
+
svg.removeEventListener("pointermove", move);
|
|
1091
1350
|
svg.removeEventListener("pointerdown", down);
|
|
1092
1351
|
svg.removeEventListener("click", click);
|
|
1093
1352
|
doc.removeEventListener("pointerdown", elsewhere, true);
|
|
@@ -1136,10 +1395,10 @@ function keyboardFocus(svg, options) {
|
|
|
1136
1395
|
leave2();
|
|
1137
1396
|
return;
|
|
1138
1397
|
}
|
|
1139
|
-
const
|
|
1140
|
-
if (
|
|
1141
|
-
|
|
1142
|
-
if (on?.scope.activeElement ===
|
|
1398
|
+
const own2 = options.element(key);
|
|
1399
|
+
if (own2 && own2 !== event.target && event.target.getAttribute("aria-hidden") === "true") {
|
|
1400
|
+
own2.focus();
|
|
1401
|
+
if (on?.scope.activeElement === own2) return;
|
|
1143
1402
|
}
|
|
1144
1403
|
focused = { key, element: event.target };
|
|
1145
1404
|
if (key === current) return;
|
|
@@ -1175,6 +1434,13 @@ function keyboardFocus(svg, options) {
|
|
|
1175
1434
|
case "ArrowLeft":
|
|
1176
1435
|
next = keys[Math.max(0, index - 1)];
|
|
1177
1436
|
break;
|
|
1437
|
+
case "PageDown":
|
|
1438
|
+
case "PageUp": {
|
|
1439
|
+
const by = event.key === "PageDown" ? 1 : -1;
|
|
1440
|
+
const paged = options.page?.(key, by);
|
|
1441
|
+
next = paged !== void 0 && keys.includes(paged) ? paged : keys[Math.min(keys.length - 1, Math.max(0, index + by * Math.ceil(keys.length / 10)))];
|
|
1442
|
+
break;
|
|
1443
|
+
}
|
|
1178
1444
|
case "Home":
|
|
1179
1445
|
next = keys[0];
|
|
1180
1446
|
break;
|
|
@@ -1269,13 +1535,16 @@ function chartHover(options) {
|
|
|
1269
1535
|
const markElement = (key) => (options.markElement ?? options.element)(key);
|
|
1270
1536
|
let hovered;
|
|
1271
1537
|
let ringKey;
|
|
1538
|
+
let linked2;
|
|
1539
|
+
let destroyed = false;
|
|
1272
1540
|
const onScreen = (keys) => keys.flatMap((key) => {
|
|
1273
1541
|
const input = options.onScreen(key);
|
|
1274
1542
|
return input ? [{ key, input }] : [];
|
|
1275
1543
|
});
|
|
1276
|
-
|
|
1544
|
+
const marksFor = (keys) => keys.length === 1 ? marksOf(keys[0]) : [...new Set(keys.flatMap(marksOf))];
|
|
1545
|
+
function hoverMarks(marks, source, effects, segment) {
|
|
1277
1546
|
if (marks.length === 0) return;
|
|
1278
|
-
runner.hover(marks.map(({ input }) => input));
|
|
1547
|
+
if (effects) runner.hover(marks.map(({ input }) => input));
|
|
1279
1548
|
const count = marks.length;
|
|
1280
1549
|
marks.forEach(({ input }, index) => events.emit("hover", { ...input, batch: { index, count }, source, ...segment === void 0 ? {} : { segment } }));
|
|
1281
1550
|
}
|
|
@@ -1287,22 +1556,27 @@ function chartHover(options) {
|
|
|
1287
1556
|
const count = marks.length;
|
|
1288
1557
|
marks.forEach(({ input }, index) => events.emit("leave", { ...input, batch: { index, count } }));
|
|
1289
1558
|
}
|
|
1290
|
-
function startHover(
|
|
1291
|
-
const marks = onScreen(
|
|
1292
|
-
|
|
1559
|
+
function startHover(keys, source, segment, effects = true) {
|
|
1560
|
+
const marks = onScreen(marksFor(keys));
|
|
1561
|
+
const started = { keys, source, marks: marks.map((mark) => mark.key), effects };
|
|
1562
|
+
hovered = started;
|
|
1293
1563
|
for (const { key: mark } of marks) markElement(mark)?.classList.add("ec-hot");
|
|
1294
1564
|
if (options.dim()) svg.classList.add("ec-hovering");
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1565
|
+
if (source !== "linked") {
|
|
1566
|
+
options.tooltip.show(keys[0]);
|
|
1567
|
+
listenForEscape(true);
|
|
1568
|
+
}
|
|
1569
|
+
hoverMarks(marks, source, effects, segment);
|
|
1570
|
+
if (source !== "linked" && hovered === started) linked2?.hover(marks.map(({ input }) => input));
|
|
1298
1571
|
}
|
|
1299
1572
|
function endHover() {
|
|
1300
|
-
const
|
|
1573
|
+
const ended = hovered;
|
|
1301
1574
|
hovered = void 0;
|
|
1302
1575
|
listenForEscape(false);
|
|
1303
1576
|
svg.classList.remove("ec-hovering");
|
|
1304
1577
|
options.tooltip.hide();
|
|
1305
|
-
leaveMarks(marks);
|
|
1578
|
+
leaveMarks(ended?.marks ?? []);
|
|
1579
|
+
if (own(ended)) linked2?.leave();
|
|
1306
1580
|
}
|
|
1307
1581
|
let escapeDoc;
|
|
1308
1582
|
const dismiss = (event) => {
|
|
@@ -1321,57 +1595,80 @@ function chartHover(options) {
|
|
|
1321
1595
|
const interaction = pointerHover(svg, {
|
|
1322
1596
|
find: options.find,
|
|
1323
1597
|
hover(target, source) {
|
|
1324
|
-
if (!options.live(target.key) || hovered
|
|
1598
|
+
if (!options.live(target.key) || own(hovered) && hovered.keys[0] === target.key) return;
|
|
1325
1599
|
endHover();
|
|
1326
|
-
startHover(target.key, source, target.segment);
|
|
1600
|
+
startHover([target.key], source, target.segment);
|
|
1327
1601
|
},
|
|
1328
1602
|
leave() {
|
|
1329
|
-
if (hovered?.source
|
|
1330
|
-
}
|
|
1603
|
+
if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
|
|
1604
|
+
},
|
|
1605
|
+
// The pointer can move onto the tooltip of the chart's own hover. A link's has none.
|
|
1606
|
+
tooltip: () => own(hovered) ? { key: hovered.keys[0], element: options.tooltip.element?.() } : void 0
|
|
1331
1607
|
});
|
|
1332
1608
|
const keyboard = keyboardFocus(() => svg, {
|
|
1333
1609
|
find: (eventTarget) => options.find(eventTarget)?.key,
|
|
1334
1610
|
order: options.order,
|
|
1611
|
+
page: (key, by) => options.page?.(key, by),
|
|
1335
1612
|
element: options.element,
|
|
1336
1613
|
focus(key, visible) {
|
|
1337
1614
|
ringKey = visible ? key : void 0;
|
|
1338
1615
|
options.ring(ringKey);
|
|
1339
1616
|
if (!options.live(key)) return;
|
|
1340
1617
|
if (!visible) {
|
|
1341
|
-
if (hovered?.source === "keyboard" && hovered.
|
|
1618
|
+
if (hovered?.source === "keyboard" && hovered.keys[0] !== key) endHover();
|
|
1342
1619
|
return;
|
|
1343
1620
|
}
|
|
1344
|
-
if (hovered
|
|
1621
|
+
if (own(hovered) && hovered.keys[0] === key) {
|
|
1345
1622
|
hovered = { ...hovered, source: "keyboard" };
|
|
1346
1623
|
return;
|
|
1347
1624
|
}
|
|
1348
1625
|
endHover();
|
|
1349
|
-
startHover(key, "keyboard");
|
|
1626
|
+
startHover([key], "keyboard");
|
|
1350
1627
|
},
|
|
1351
1628
|
blur() {
|
|
1352
1629
|
ringKey = void 0;
|
|
1353
1630
|
options.ring(ringKey);
|
|
1354
1631
|
if (hovered?.source !== "keyboard") return;
|
|
1355
|
-
if (interaction.current === hovered.
|
|
1632
|
+
if (interaction.current === hovered.keys[0]) hovered = { ...hovered, source: "pointer" };
|
|
1356
1633
|
else endHover();
|
|
1357
1634
|
},
|
|
1358
1635
|
escape() {
|
|
1359
1636
|
if (!hovered) return false;
|
|
1360
|
-
|
|
1637
|
+
if (hovered.source === "linked" && linked2) linked2.dismiss();
|
|
1638
|
+
else endHover();
|
|
1361
1639
|
return true;
|
|
1362
1640
|
}
|
|
1363
1641
|
});
|
|
1642
|
+
const link2 = {
|
|
1643
|
+
targets: () => options.order().map((key) => ({ key, marks: onScreen(marksOf(key)).map(({ input }) => input) })),
|
|
1644
|
+
hover(keys, effects) {
|
|
1645
|
+
if (hovered !== void 0) endHover();
|
|
1646
|
+
const live = keys.filter(options.live);
|
|
1647
|
+
if (live.length > 0) startHover(live, "linked", void 0, effects);
|
|
1648
|
+
},
|
|
1649
|
+
unlink() {
|
|
1650
|
+
if (hovered?.source === "linked") endHover();
|
|
1651
|
+
},
|
|
1652
|
+
leave: leave2,
|
|
1653
|
+
listen(listener) {
|
|
1654
|
+
if (destroyed) return false;
|
|
1655
|
+
linked2 = listener;
|
|
1656
|
+
return true;
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1364
1659
|
return {
|
|
1365
1660
|
get key() {
|
|
1366
|
-
return hovered
|
|
1661
|
+
return own(hovered) ? hovered.keys[0] : void 0;
|
|
1367
1662
|
},
|
|
1368
1663
|
get ringKey() {
|
|
1369
1664
|
return ringKey;
|
|
1370
1665
|
},
|
|
1666
|
+
link: link2,
|
|
1371
1667
|
active: () => keyboard.active(),
|
|
1372
1668
|
restyled(key) {
|
|
1373
1669
|
if (ringKey !== void 0 && within(ringKey, key)) options.ring(ringKey);
|
|
1374
|
-
|
|
1670
|
+
const target = own(hovered) ? hovered.keys[0] : void 0;
|
|
1671
|
+
if (target !== void 0 && (hovered?.marks.includes(key) || key === target) && options.live(target)) options.tooltip.show(target);
|
|
1375
1672
|
},
|
|
1376
1673
|
syncDim() {
|
|
1377
1674
|
if (!options.dim()) svg.classList.remove("ec-hovering");
|
|
@@ -1379,22 +1676,24 @@ function chartHover(options) {
|
|
|
1379
1676
|
},
|
|
1380
1677
|
dropGone() {
|
|
1381
1678
|
if (hovered === void 0) return;
|
|
1382
|
-
|
|
1679
|
+
const keys = hovered.keys.filter(options.live);
|
|
1680
|
+
if (keys.length === 0) {
|
|
1383
1681
|
interaction.clear();
|
|
1384
1682
|
endHover();
|
|
1385
1683
|
return;
|
|
1386
1684
|
}
|
|
1387
|
-
const { source, marks: before } = hovered;
|
|
1388
|
-
const now = onScreen(
|
|
1685
|
+
const { source, marks: before, effects } = hovered;
|
|
1686
|
+
const now = onScreen(marksFor(keys));
|
|
1687
|
+
hovered = { ...hovered, keys };
|
|
1389
1688
|
if (now.length === before.length && now.every((mark, i) => mark.key === before[i])) return;
|
|
1390
1689
|
const had = new Set(before);
|
|
1391
|
-
const
|
|
1392
|
-
const gone = onScreen(before.filter((key) => !
|
|
1690
|
+
const kept = new Set(now.map((mark) => mark.key));
|
|
1691
|
+
const gone = onScreen(before.filter((key) => !kept.has(key)));
|
|
1393
1692
|
hovered = { ...hovered, marks: now.map((mark) => mark.key) };
|
|
1394
1693
|
for (const { key } of gone) markElement(key)?.classList.remove("ec-hot");
|
|
1395
1694
|
for (const { key } of now) if (!had.has(key)) markElement(key)?.classList.add("ec-hot");
|
|
1396
1695
|
runner.leave(before);
|
|
1397
|
-
runner.hover(now.map(({ input }) => input));
|
|
1696
|
+
if (effects) runner.hover(now.map(({ input }) => input));
|
|
1398
1697
|
gone.forEach(({ input }, index) => events.emit("leave", { ...input, batch: { index, count: gone.length } }));
|
|
1399
1698
|
const count = now.length;
|
|
1400
1699
|
now.forEach(({ key, input }, index) => {
|
|
@@ -1407,6 +1706,9 @@ function chartHover(options) {
|
|
|
1407
1706
|
},
|
|
1408
1707
|
leave: leave2,
|
|
1409
1708
|
destroy() {
|
|
1709
|
+
destroyed = true;
|
|
1710
|
+
linked2?.gone();
|
|
1711
|
+
linked2 = void 0;
|
|
1410
1712
|
listenForEscape(false);
|
|
1411
1713
|
interaction.destroy();
|
|
1412
1714
|
keyboard.destroy();
|
|
@@ -1482,9 +1784,9 @@ function checkTableOption(option, chart) {
|
|
|
1482
1784
|
throw new TypeError(`${chart}: ${what}`);
|
|
1483
1785
|
};
|
|
1484
1786
|
if (typeof option !== "object" || option === null) fail('table must be true, false, "hidden" or an object of table options.');
|
|
1485
|
-
const { hidden: hidden2, columns, category, total: total2, share, summary, series } = option;
|
|
1787
|
+
const { hidden: hidden2, columns, category, total: total2, share, summary: summary2, series } = option;
|
|
1486
1788
|
if (hidden2 !== void 0 && typeof hidden2 !== "boolean") fail("table.hidden must be true or false.");
|
|
1487
|
-
for (const [name, text2] of Object.entries({ category, total: total2, share, summary })) {
|
|
1789
|
+
for (const [name, text2] of Object.entries({ category, total: total2, share, summary: summary2 })) {
|
|
1488
1790
|
if (text2 !== void 0 && typeof text2 !== "string") fail(`table.${name} must be a string.`);
|
|
1489
1791
|
}
|
|
1490
1792
|
if (series !== void 0) {
|
|
@@ -1503,6 +1805,7 @@ function checkTableOption(option, chart) {
|
|
|
1503
1805
|
if (column.after !== void 0 && column.after !== "category" && column.after !== "values") fail(`table.columns[${i}].after must be "category" or "values".`);
|
|
1504
1806
|
});
|
|
1505
1807
|
}
|
|
1808
|
+
var MISSING = "missing";
|
|
1506
1809
|
function tableModel(input) {
|
|
1507
1810
|
const { option, format: format2 } = input;
|
|
1508
1811
|
if (option === false) return void 0;
|
|
@@ -1515,12 +1818,12 @@ function tableModel(input) {
|
|
|
1515
1818
|
const grand = input.rows.reduce((sum2, row) => sum2 + row.total, 0);
|
|
1516
1819
|
const share = (value) => input.shares ? [{ text: percent(grand > 0 ? value / grand : 0), numeric: true }] : [];
|
|
1517
1820
|
const header = (column) => ({ text: column.label, numeric: false });
|
|
1518
|
-
const
|
|
1821
|
+
const own2 = (series) => options.series && Object.prototype.hasOwnProperty.call(options.series, series) ? options.series[series] : void 0;
|
|
1519
1822
|
const blank = () => ({ text: "", numeric: false });
|
|
1520
1823
|
const headers = [
|
|
1521
1824
|
{ text: options.category ?? input.category ?? "Category", numeric: false },
|
|
1522
1825
|
...first.map(header),
|
|
1523
|
-
...input.series.map((series) => ({ text:
|
|
1826
|
+
...input.series.map((series) => ({ text: own2(series) ?? input.label?.(series) ?? series, numeric: true })),
|
|
1524
1827
|
...totals ? [{ text: options.total ?? "Total", numeric: true }] : [],
|
|
1525
1828
|
...input.shares ? [{ text: options.share ?? "Share", numeric: true }] : [],
|
|
1526
1829
|
...last.map(header)
|
|
@@ -1532,7 +1835,7 @@ function tableModel(input) {
|
|
|
1532
1835
|
cells: [
|
|
1533
1836
|
{ text: row.category, numeric: false },
|
|
1534
1837
|
...first.map((column) => columnCell(column, row, format2)),
|
|
1535
|
-
...input.series.map((series) => number2(values.get(series) ?? 0)),
|
|
1838
|
+
...input.series.map((series) => row.missing?.has(series) ? { text: MISSING, numeric: true } : number2(values.get(series) ?? 0)),
|
|
1536
1839
|
...totals ? [number2(row.total)] : [],
|
|
1537
1840
|
...share(row.total),
|
|
1538
1841
|
...last.map((column) => columnCell(column, row, format2))
|
|
@@ -1573,14 +1876,14 @@ function columnCell(column, row, format2) {
|
|
|
1573
1876
|
function chartTable(svg) {
|
|
1574
1877
|
const doc = svg.ownerDocument;
|
|
1575
1878
|
let wrapper;
|
|
1576
|
-
let
|
|
1879
|
+
let summary2;
|
|
1577
1880
|
let table;
|
|
1578
|
-
let
|
|
1881
|
+
let caption2;
|
|
1579
1882
|
let head;
|
|
1580
1883
|
let body;
|
|
1581
1884
|
let foot;
|
|
1582
1885
|
const rows2 = /* @__PURE__ */ new Map();
|
|
1583
|
-
let
|
|
1886
|
+
let drawn2 = "";
|
|
1584
1887
|
const element = (tag, className) => {
|
|
1585
1888
|
const made = doc.createElement(tag);
|
|
1586
1889
|
if (className) made.className = className;
|
|
@@ -1588,12 +1891,12 @@ function chartTable(svg) {
|
|
|
1588
1891
|
};
|
|
1589
1892
|
function build() {
|
|
1590
1893
|
table = element("table");
|
|
1591
|
-
|
|
1894
|
+
caption2 = element("caption", "ec-table-caption");
|
|
1592
1895
|
const thead = element("thead");
|
|
1593
1896
|
head = element("tr");
|
|
1594
1897
|
thead.appendChild(head);
|
|
1595
1898
|
body = element("tbody");
|
|
1596
|
-
table.append(
|
|
1899
|
+
table.append(caption2, thead, body);
|
|
1597
1900
|
return table;
|
|
1598
1901
|
}
|
|
1599
1902
|
function place(hidden2, text2) {
|
|
@@ -1602,19 +1905,19 @@ function chartTable(svg) {
|
|
|
1602
1905
|
const next = hidden2 ? element("div", "ec-table ec-visually-hidden") : element("details", "ec-table");
|
|
1603
1906
|
const content = table ?? build();
|
|
1604
1907
|
if (hidden2) {
|
|
1605
|
-
|
|
1908
|
+
summary2 = void 0;
|
|
1606
1909
|
next.appendChild(content);
|
|
1607
1910
|
} else {
|
|
1608
|
-
|
|
1911
|
+
summary2 = element("summary");
|
|
1609
1912
|
const scroll = element("div", "ec-table-scroll");
|
|
1610
1913
|
scroll.appendChild(content);
|
|
1611
|
-
next.append(
|
|
1914
|
+
next.append(summary2, scroll);
|
|
1612
1915
|
}
|
|
1613
1916
|
if (wrapper?.isConnected) wrapper.replaceWith(next);
|
|
1614
1917
|
wrapper = next;
|
|
1615
1918
|
}
|
|
1616
1919
|
if (!wrapper.isConnected) svg.after(wrapper);
|
|
1617
|
-
if (
|
|
1920
|
+
if (summary2 && summary2.textContent !== text2) summary2.textContent = text2;
|
|
1618
1921
|
}
|
|
1619
1922
|
function fill(cell, { text: text2, numeric: numeric3 }) {
|
|
1620
1923
|
if (cell.textContent !== text2) cell.textContent = text2;
|
|
@@ -1622,9 +1925,9 @@ function chartTable(svg) {
|
|
|
1622
1925
|
}
|
|
1623
1926
|
function remove() {
|
|
1624
1927
|
wrapper?.remove();
|
|
1625
|
-
wrapper =
|
|
1928
|
+
wrapper = summary2 = table = caption2 = head = body = foot = void 0;
|
|
1626
1929
|
rows2.clear();
|
|
1627
|
-
|
|
1930
|
+
drawn2 = "";
|
|
1628
1931
|
}
|
|
1629
1932
|
return {
|
|
1630
1933
|
render(model) {
|
|
@@ -1633,10 +1936,10 @@ function chartTable(svg) {
|
|
|
1633
1936
|
return;
|
|
1634
1937
|
}
|
|
1635
1938
|
place(model.hidden, model.summary);
|
|
1636
|
-
if (
|
|
1939
|
+
if (caption2.textContent !== model.caption) caption2.textContent = model.caption;
|
|
1637
1940
|
const headers = JSON.stringify(model.headers);
|
|
1638
|
-
if (headers !==
|
|
1639
|
-
|
|
1941
|
+
if (headers !== drawn2) {
|
|
1942
|
+
drawn2 = headers;
|
|
1640
1943
|
head.replaceChildren(
|
|
1641
1944
|
...model.headers.map((header) => {
|
|
1642
1945
|
const th = element("th");
|
|
@@ -1797,10 +2100,10 @@ function chartTransitions(options) {
|
|
|
1797
2100
|
});
|
|
1798
2101
|
},
|
|
1799
2102
|
supersede: () => supersede?.(),
|
|
1800
|
-
wait(settled,
|
|
2103
|
+
wait(settled, leaves2) {
|
|
1801
2104
|
return new Promise((resolve) => {
|
|
1802
2105
|
supersede = resolve;
|
|
1803
|
-
void settled.then(() => Promise.all(
|
|
2106
|
+
void settled.then(() => Promise.all(leaves2.map((leave2) => leave2.gone))).then(() => resolve());
|
|
1804
2107
|
});
|
|
1805
2108
|
},
|
|
1806
2109
|
destroy() {
|
|
@@ -1817,20 +2120,22 @@ function playUpdate(options, arrange, announce) {
|
|
|
1817
2120
|
const diff = arrange();
|
|
1818
2121
|
options.swap?.(diff);
|
|
1819
2122
|
options.hover.dropGone();
|
|
1820
|
-
const
|
|
2123
|
+
const leaves2 = diff.exiting.map((record) => record.leave);
|
|
1821
2124
|
const exited = runner.exit(diff.exiting.map(onScreen));
|
|
1822
2125
|
void exited.then(() => {
|
|
1823
|
-
for (const leave2 of
|
|
2126
|
+
for (const leave2 of leaves2) leave2.exited = true;
|
|
1824
2127
|
options.leaving.sweep();
|
|
1825
2128
|
});
|
|
1826
2129
|
events.emitEach("exit", diff.exiting, onScreen);
|
|
1827
|
-
|
|
2130
|
+
if (options.data || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) {
|
|
2131
|
+
runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
|
|
2132
|
+
}
|
|
1828
2133
|
events.emitEach("update", diff.changed, ({ record, from }) => ({ ...input(record), from }));
|
|
1829
2134
|
runner.enter(diff.entering.map(input));
|
|
1830
2135
|
events.emitEach("enter", diff.entering, input);
|
|
1831
2136
|
announce(diff);
|
|
1832
2137
|
options.hover.sync();
|
|
1833
|
-
return
|
|
2138
|
+
return leaves2;
|
|
1834
2139
|
}
|
|
1835
2140
|
function busy(value, to, equal) {
|
|
1836
2141
|
return value.animating || !equal(value.value, to);
|
|
@@ -1841,11 +2146,18 @@ function sameFields(a, b) {
|
|
|
1841
2146
|
return keys.length === Object.keys(b).length && keys.every((key) => a[key] === b[key]);
|
|
1842
2147
|
}
|
|
1843
2148
|
function geometryChanged(from, to) {
|
|
1844
|
-
if (from.outline.d !== to.outline.d) return true;
|
|
2149
|
+
if (from.outline.d !== to.outline.d || labelsMoved(from, to)) return true;
|
|
1845
2150
|
const a = from.segments ?? [];
|
|
1846
2151
|
const b = to.segments ?? [];
|
|
1847
2152
|
return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
|
|
1848
2153
|
}
|
|
2154
|
+
function labelsMoved(from, to) {
|
|
2155
|
+
const a = from.labelBounds;
|
|
2156
|
+
const b = to.labelBounds;
|
|
2157
|
+
if (a === b) return false;
|
|
2158
|
+
if (!a || !b || a.length !== b.length) return true;
|
|
2159
|
+
return a.some((box, i) => box.x !== b[i].x || box.y !== b[i].y || box.width !== b[i].width || box.height !== b[i].height);
|
|
2160
|
+
}
|
|
1849
2161
|
|
|
1850
2162
|
// src/charts/shell/watch.ts
|
|
1851
2163
|
function watchWidth(container, clock, width, resize) {
|
|
@@ -1885,6 +2197,7 @@ function watchHoverDuration(svg, motion2) {
|
|
|
1885
2197
|
|
|
1886
2198
|
// src/charts/tooltip.ts
|
|
1887
2199
|
var GAP2 = 12;
|
|
2200
|
+
var OVERLAP = 1;
|
|
1888
2201
|
var FADE = 100;
|
|
1889
2202
|
var described = 0;
|
|
1890
2203
|
function placeTooltip(anchor, size, box, side) {
|
|
@@ -1906,27 +2219,54 @@ function summaryContent(category, values, format2, options = {}) {
|
|
|
1906
2219
|
function chartTooltip(svg, options) {
|
|
1907
2220
|
let layer;
|
|
1908
2221
|
let box;
|
|
2222
|
+
let bridge;
|
|
1909
2223
|
let texts = /* @__PURE__ */ new WeakMap();
|
|
1910
2224
|
let rendered;
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
2225
|
+
let pointer;
|
|
2226
|
+
let through = false;
|
|
2227
|
+
let shape;
|
|
2228
|
+
const timing = (element) => element.style.setProperty("--ec-hover-duration", `${options.motion.duration(FADE, "feedback")}ms`);
|
|
2229
|
+
const shown = () => box?.classList.contains("ec-tooltip-shown") ?? false;
|
|
2230
|
+
const under = () => {
|
|
2231
|
+
if (!pointer || !box || !layer) return false;
|
|
2232
|
+
const { x, y } = pointer;
|
|
2233
|
+
const { left, right, top, bottom } = box.getBoundingClientRect();
|
|
2234
|
+
if (x > left && x < right && y > top && y < bottom) return true;
|
|
2235
|
+
if (!shape) return false;
|
|
2236
|
+
const origin = layer.getBoundingClientRect();
|
|
2237
|
+
return inside(shape, x - origin.left, y - origin.top);
|
|
2238
|
+
};
|
|
2239
|
+
const letThrough = (on) => {
|
|
2240
|
+
through = on;
|
|
2241
|
+
layer?.classList.toggle("ec-tooltip-through", on);
|
|
2242
|
+
};
|
|
2243
|
+
const track = (event) => {
|
|
2244
|
+
pointer = event.pointerType === "touch" ? void 0 : { x: event.clientX, y: event.clientY };
|
|
2245
|
+
if (through && !under()) letThrough(false);
|
|
2246
|
+
};
|
|
2247
|
+
svg.ownerDocument.addEventListener("pointerover", track, true);
|
|
2248
|
+
svg.ownerDocument.addEventListener("pointermove", track, true);
|
|
2249
|
+
function made() {
|
|
2250
|
+
if (!layer || !box || !bridge) {
|
|
1914
2251
|
const doc = svg.ownerDocument;
|
|
1915
2252
|
layer = doc.createElement("div");
|
|
1916
2253
|
layer.className = "ec-tooltip-layer";
|
|
1917
2254
|
box = doc.createElement("div");
|
|
1918
2255
|
box.className = "ec-tooltip";
|
|
1919
2256
|
box.setAttribute("aria-hidden", "true");
|
|
1920
|
-
|
|
2257
|
+
bridge = doc.createElement("div");
|
|
2258
|
+
bridge.className = "ec-tooltip-bridge";
|
|
2259
|
+
bridge.setAttribute("aria-hidden", "true");
|
|
2260
|
+
layer.append(box, bridge);
|
|
1921
2261
|
}
|
|
1922
2262
|
if (layer.previousSibling !== svg) svg.after(layer);
|
|
1923
2263
|
return box;
|
|
1924
2264
|
}
|
|
1925
|
-
function contentFor(row,
|
|
2265
|
+
function contentFor(row, summary2) {
|
|
1926
2266
|
const option = options.option();
|
|
1927
2267
|
const known = texts.get(row);
|
|
1928
2268
|
if (known && known.option === option) return known.content;
|
|
1929
|
-
const content = text(option, row.datum,
|
|
2269
|
+
const content = text(option, row.datum, summary2);
|
|
1930
2270
|
texts.set(row, { option, content });
|
|
1931
2271
|
return content;
|
|
1932
2272
|
}
|
|
@@ -1934,14 +2274,16 @@ function chartTooltip(svg, options) {
|
|
|
1934
2274
|
if (!box) return;
|
|
1935
2275
|
timing(box);
|
|
1936
2276
|
box.classList.remove("ec-tooltip-shown");
|
|
2277
|
+
letThrough(false);
|
|
1937
2278
|
}
|
|
1938
|
-
function place(row,
|
|
1939
|
-
const content = contentFor(row,
|
|
2279
|
+
function place(row, summary2, anchor, moved) {
|
|
2280
|
+
const content = contentFor(row, summary2);
|
|
1940
2281
|
if (content === void 0) {
|
|
1941
2282
|
hide();
|
|
1942
2283
|
return;
|
|
1943
2284
|
}
|
|
1944
|
-
const tip =
|
|
2285
|
+
const tip = made();
|
|
2286
|
+
const held = shown() && !through && under();
|
|
1945
2287
|
const key = typeof content === "string" ? `text:${content}` : JSON.stringify(content);
|
|
1946
2288
|
if (key !== rendered) {
|
|
1947
2289
|
render(tip, content);
|
|
@@ -1953,65 +2295,103 @@ function chartTooltip(svg, options) {
|
|
|
1953
2295
|
const toPx = { x: (x) => (x - view.x) * k, y: (y) => (y - view.y) * k };
|
|
1954
2296
|
const area = chart.width > 0 ? { width: chart.width, height: chart.height } : { width: view.width, height: view.height };
|
|
1955
2297
|
const size = { width: tip.offsetWidth, height: tip.offsetHeight };
|
|
1956
|
-
const
|
|
2298
|
+
const near = anchor(toPx, moved);
|
|
2299
|
+
const placed2 = placeTooltip(near, size, area, moved ? placeTooltip(anchor(toPx, false), size, area).side : void 0);
|
|
1957
2300
|
const origin = layer.getBoundingClientRect();
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2301
|
+
const dx = chart.left - origin.left;
|
|
2302
|
+
const dy = chart.top - origin.top;
|
|
2303
|
+
const left = Math.round(dx + placed2.x);
|
|
2304
|
+
const top = Math.round(dy + placed2.y);
|
|
2305
|
+
tip.style.left = `${left}px`;
|
|
2306
|
+
tip.style.top = `${top}px`;
|
|
2307
|
+
tip.setAttribute("data-side", placed2.side);
|
|
2308
|
+
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 };
|
|
2309
|
+
shape = span(bridge, { left, top, ...size }, mark, placed2.side);
|
|
1961
2310
|
timing(tip);
|
|
1962
2311
|
tip.classList.add("ec-tooltip-shown");
|
|
2312
|
+
letThrough(!held && under());
|
|
1963
2313
|
}
|
|
1964
2314
|
return {
|
|
1965
|
-
show(mark, row,
|
|
2315
|
+
show(mark, row, summary2, transform) {
|
|
1966
2316
|
const anchor = (toPx, moved) => {
|
|
1967
2317
|
const m = moved ? transform : void 0;
|
|
1968
2318
|
const { x, y, width, height } = mark.bounds;
|
|
1969
|
-
const
|
|
2319
|
+
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);
|
|
2320
|
+
const xs = corners.map((corner) => corner.x);
|
|
2321
|
+
const ys = corners.map((corner) => corner.y);
|
|
1970
2322
|
const center = m ? matrix.apply(m, mark.center) : mark.center;
|
|
1971
|
-
return { x: toPx.x(center.x), top: toPx.y(Math.min(...ys)), bottom: toPx.y(Math.max(...ys)) };
|
|
2323
|
+
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)) };
|
|
1972
2324
|
};
|
|
1973
|
-
place(row,
|
|
2325
|
+
place(row, summary2, anchor, transform !== void 0);
|
|
1974
2326
|
},
|
|
1975
|
-
showAt(point, row,
|
|
1976
|
-
place(row,
|
|
2327
|
+
showAt(point, row, summary2) {
|
|
2328
|
+
place(row, summary2, (toPx) => ({ x: toPx.x(point.x), top: toPx.y(point.top), bottom: toPx.y(point.bottom) }), false);
|
|
1977
2329
|
},
|
|
1978
|
-
describe(
|
|
1979
|
-
const
|
|
2330
|
+
describe(element, row) {
|
|
2331
|
+
const own2 = options.description?.();
|
|
1980
2332
|
let content;
|
|
1981
|
-
if (
|
|
1982
|
-
else if (typeof
|
|
2333
|
+
if (own2 === false) content = void 0;
|
|
2334
|
+
else if (typeof own2 === "function") {
|
|
1983
2335
|
try {
|
|
1984
|
-
const text2 =
|
|
2336
|
+
const text2 = own2(row.datum);
|
|
1985
2337
|
content = typeof text2 === "string" && text2 !== "" ? text2 : void 0;
|
|
1986
2338
|
} catch (error) {
|
|
1987
2339
|
report(error);
|
|
1988
2340
|
content = void 0;
|
|
1989
2341
|
}
|
|
1990
2342
|
} else content = typeof options.option() === "function" ? contentFor(row, () => "") : void 0;
|
|
1991
|
-
let desc =
|
|
2343
|
+
let desc = element.querySelector(":scope > desc.ec-description");
|
|
1992
2344
|
if (typeof content !== "string") {
|
|
1993
2345
|
if (!desc) return;
|
|
1994
|
-
if (
|
|
2346
|
+
if (element.getAttribute("aria-describedby") === desc.id) element.removeAttribute("aria-describedby");
|
|
1995
2347
|
desc.remove();
|
|
1996
2348
|
return;
|
|
1997
2349
|
}
|
|
1998
|
-
desc ?? (desc = svgElement("desc", { class: "ec-description", id: `ec-description-${++described}` },
|
|
2350
|
+
desc ?? (desc = svgElement("desc", { class: "ec-description", id: `ec-description-${++described}` }, element));
|
|
1999
2351
|
if (desc.textContent !== content) desc.textContent = content;
|
|
2000
|
-
|
|
2352
|
+
element.setAttribute("aria-describedby", desc.id);
|
|
2001
2353
|
},
|
|
2354
|
+
element: () => shown() ? layer : void 0,
|
|
2002
2355
|
hide,
|
|
2003
2356
|
destroy() {
|
|
2357
|
+
svg.ownerDocument.removeEventListener("pointerover", track, true);
|
|
2358
|
+
svg.ownerDocument.removeEventListener("pointermove", track, true);
|
|
2004
2359
|
layer?.remove();
|
|
2005
2360
|
layer = void 0;
|
|
2006
2361
|
box = void 0;
|
|
2362
|
+
bridge = void 0;
|
|
2363
|
+
shape = void 0;
|
|
2364
|
+
through = false;
|
|
2007
2365
|
texts = /* @__PURE__ */ new WeakMap();
|
|
2008
2366
|
rendered = void 0;
|
|
2009
2367
|
}
|
|
2010
2368
|
};
|
|
2011
2369
|
}
|
|
2012
|
-
function
|
|
2370
|
+
function inside({ top, bottom, upper, lower }, x, y) {
|
|
2371
|
+
if (y <= top || y >= bottom) return false;
|
|
2372
|
+
const t = (y - top) / (bottom - top);
|
|
2373
|
+
return x > upper.left + (lower.left - upper.left) * t && x < upper.right + (lower.right - upper.right) * t;
|
|
2374
|
+
}
|
|
2375
|
+
function span(bridge, box, mark, side) {
|
|
2376
|
+
bridge.hidden = mark === void 0;
|
|
2377
|
+
if (!mark) return void 0;
|
|
2378
|
+
const edge = { left: box.left, right: box.left + box.width };
|
|
2379
|
+
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];
|
|
2380
|
+
const left = Math.round(Math.min(upper.left, lower.left));
|
|
2381
|
+
const width = Math.round(Math.max(upper.right, lower.right)) - left;
|
|
2382
|
+
const height = Math.max(0, bottom - top);
|
|
2383
|
+
const x = (value) => `${Math.round(value) - left}px`;
|
|
2384
|
+
bridge.style.left = `${left}px`;
|
|
2385
|
+
bridge.style.top = `${top}px`;
|
|
2386
|
+
bridge.style.width = `${width}px`;
|
|
2387
|
+
bridge.style.height = `${height}px`;
|
|
2388
|
+
bridge.style.setProperty("clip-path", `polygon(${x(upper.left)} 0px, ${x(upper.right)} 0px, ${x(lower.right)} ${height}px, ${x(lower.left)} ${height}px)`);
|
|
2389
|
+
const round5 = (edge2) => ({ left: Math.round(edge2.left), right: Math.round(edge2.right) });
|
|
2390
|
+
return { top, bottom: top + height, upper: round5(upper), lower: round5(lower) };
|
|
2391
|
+
}
|
|
2392
|
+
function text(option, datum, summary2) {
|
|
2013
2393
|
if (option === false) return void 0;
|
|
2014
|
-
if (typeof option !== "function") return
|
|
2394
|
+
if (typeof option !== "function") return summary2();
|
|
2015
2395
|
try {
|
|
2016
2396
|
const result = option(datum);
|
|
2017
2397
|
return result === void 0 || result === null || result === "" ? void 0 : String(result);
|
|
@@ -2035,8 +2415,8 @@ function render(box, content) {
|
|
|
2035
2415
|
box.replaceChildren(line(content.title, "ec-tooltip-title"), ...content.lines.map((value) => line(value)));
|
|
2036
2416
|
}
|
|
2037
2417
|
function viewBox(svg) {
|
|
2038
|
-
const
|
|
2039
|
-
if (
|
|
2418
|
+
const parts2 = (svg.getAttribute("viewBox") ?? "").split(/[\s,]+/).map(Number);
|
|
2419
|
+
if (parts2.length === 4 && parts2.every(Number.isFinite)) return { x: parts2[0], y: parts2[1], width: parts2[2], height: parts2[3] };
|
|
2040
2420
|
return { x: 0, y: 0, width: Number(svg.getAttribute("width")) || 0, height: Number(svg.getAttribute("height")) || 0 };
|
|
2041
2421
|
}
|
|
2042
2422
|
|
|
@@ -2120,7 +2500,8 @@ function barChart(target, options, env2) {
|
|
|
2120
2500
|
width: opts.width ?? measuredWidth,
|
|
2121
2501
|
height: opts.height,
|
|
2122
2502
|
format: format(opts),
|
|
2123
|
-
measure
|
|
2503
|
+
measure,
|
|
2504
|
+
room: opts.room ?? 0
|
|
2124
2505
|
});
|
|
2125
2506
|
}
|
|
2126
2507
|
function createRecord(row, entering) {
|
|
@@ -2181,8 +2562,8 @@ function barChart(target, options, env2) {
|
|
|
2181
2562
|
element.remove();
|
|
2182
2563
|
record.paths.delete(series);
|
|
2183
2564
|
}
|
|
2184
|
-
const
|
|
2185
|
-
if (record.parts.some((part, i) =>
|
|
2565
|
+
const drawn2 = Array.from(record.body.children).filter((child) => child.classList.contains("ec-segment"));
|
|
2566
|
+
if (record.parts.some((part, i) => drawn2[i] !== part.element)) for (const part of record.parts) record.body.appendChild(part.element);
|
|
2186
2567
|
record.handle.repaint();
|
|
2187
2568
|
if (record.parts[0]?.colors.color !== before) surface.recolor(record.key);
|
|
2188
2569
|
if (record.key === hover.ringKey) drawRing(record.key);
|
|
@@ -2198,19 +2579,19 @@ function barChart(target, options, env2) {
|
|
|
2198
2579
|
setAttributes(ring, { transform: transform && transformAttribute(transform), visibility: void 0 });
|
|
2199
2580
|
}
|
|
2200
2581
|
function show3(record, row) {
|
|
2201
|
-
const moved = geometryChanged(record.shown.geometry, row.geometry);
|
|
2582
|
+
const moved = geometryChanged(record.shown.geometry, row.geometry) || record.shown.datum !== row.datum;
|
|
2202
2583
|
drawMark(record, row);
|
|
2203
2584
|
if (moved) runner.change(row.geometry, row.data);
|
|
2204
2585
|
if (record.key === hover.key) showTooltip(record);
|
|
2205
2586
|
}
|
|
2206
2587
|
function showTooltip(record) {
|
|
2207
2588
|
const { row } = record;
|
|
2208
|
-
tooltip.show(record.shown.geometry, row, () => summaryContent(row.
|
|
2589
|
+
tooltip.show(record.shown.geometry, row, () => summaryContent(row.category, labelled(row.values, current), format(current)), record.handle.style.transform);
|
|
2209
2590
|
}
|
|
2210
2591
|
function syncLegend(next) {
|
|
2211
2592
|
if (byCategory(current)) {
|
|
2212
2593
|
legend.categories(
|
|
2213
|
-
next.rows.map((row) => ({ key: row.key, label: row.
|
|
2594
|
+
next.rows.map((row) => ({ key: row.key, label: row.category })),
|
|
2214
2595
|
colors,
|
|
2215
2596
|
current.legend
|
|
2216
2597
|
);
|
|
@@ -2231,7 +2612,7 @@ function barChart(target, options, env2) {
|
|
|
2231
2612
|
category: typeof field === "string" ? field : void 0,
|
|
2232
2613
|
series: encoding.series.map((s) => s.series),
|
|
2233
2614
|
label: (series) => seriesLabel(opts.seriesLabels, series),
|
|
2234
|
-
rows: next.rows.map((row) => ({ key: row.key, category: row.
|
|
2615
|
+
rows: next.rows.map((row) => ({ key: row.key, category: row.category, datum: row.datum, index: row.index, values: row.values, total: row.total })),
|
|
2235
2616
|
format: format(opts)
|
|
2236
2617
|
});
|
|
2237
2618
|
}
|
|
@@ -2241,7 +2622,7 @@ function barChart(target, options, env2) {
|
|
|
2241
2622
|
const series = barEncoding(current).series.map((s) => s.series);
|
|
2242
2623
|
const before = barEncoding(previous).series.map((s) => s.series);
|
|
2243
2624
|
const sort = sortName(current.sort);
|
|
2244
|
-
const name = (record) => record.row.
|
|
2625
|
+
const name = (record) => record.row.category;
|
|
2245
2626
|
const changed = diff.changed.map(({ record }) => record);
|
|
2246
2627
|
const text2 = changeText({
|
|
2247
2628
|
...current.label !== previous.label ? { label: current.label } : {},
|
|
@@ -2259,8 +2640,8 @@ function barChart(target, options, env2) {
|
|
|
2259
2640
|
}
|
|
2260
2641
|
const key = (record) => record.key;
|
|
2261
2642
|
try {
|
|
2262
|
-
const
|
|
2263
|
-
if (
|
|
2643
|
+
const said2 = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
|
|
2644
|
+
if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
|
|
2264
2645
|
} catch (error) {
|
|
2265
2646
|
report(error);
|
|
2266
2647
|
}
|
|
@@ -2272,7 +2653,7 @@ function barChart(target, options, env2) {
|
|
|
2272
2653
|
const values = record.series.map((series) => ({ series, value: now[series] ?? 0 }));
|
|
2273
2654
|
const total2 = values.reduce((sum, v) => sum + v.value, 0);
|
|
2274
2655
|
const text2 = record.count === void 0 ? row.value.text : format(current)(round(total2, record.count));
|
|
2275
|
-
return placeRow(frame, { key: row.key, datum: row.datum, index: row.index, category: row.
|
|
2656
|
+
return placeRow(frame, { key: row.key, datum: row.datum, index: row.index, category: row.category, values, slot: record.slot.value, text: text2, drawn: row.drawn }, measure);
|
|
2276
2657
|
}
|
|
2277
2658
|
function addTick(value, opacity) {
|
|
2278
2659
|
const tick = {
|
|
@@ -2289,10 +2670,10 @@ function barChart(target, options, env2) {
|
|
|
2289
2670
|
}
|
|
2290
2671
|
}
|
|
2291
2672
|
function drawTick(tick, frame) {
|
|
2292
|
-
const
|
|
2673
|
+
const placed2 = placeTick(frame, tick.value, format(current)(tick.value));
|
|
2293
2674
|
const opacity = tick.opacity.value < 1 ? tick.opacity.value : void 0;
|
|
2294
|
-
setAttributes(tick.line, { ...
|
|
2295
|
-
placeText(tick.label,
|
|
2675
|
+
setAttributes(tick.line, { ...placed2.line, opacity });
|
|
2676
|
+
placeText(tick.label, placed2.label);
|
|
2296
2677
|
setAttributes(tick.label, { opacity });
|
|
2297
2678
|
}
|
|
2298
2679
|
function draw() {
|
|
@@ -2314,11 +2695,11 @@ function barChart(target, options, env2) {
|
|
|
2314
2695
|
tick.label.remove();
|
|
2315
2696
|
ticks.delete(tick.value);
|
|
2316
2697
|
}
|
|
2317
|
-
for (const
|
|
2318
|
-
const tick = ticks.get(
|
|
2698
|
+
for (const placed2 of laidOut.ticks) {
|
|
2699
|
+
const tick = ticks.get(placed2.value);
|
|
2319
2700
|
if (!tick) continue;
|
|
2320
|
-
setAttributes(tick.line, { ...
|
|
2321
|
-
placeText(tick.label,
|
|
2701
|
+
setAttributes(tick.line, { ...placed2.line, opacity: void 0 });
|
|
2702
|
+
placeText(tick.label, placed2.label);
|
|
2322
2703
|
tick.label.removeAttribute("opacity");
|
|
2323
2704
|
}
|
|
2324
2705
|
for (const record of order) {
|
|
@@ -2452,7 +2833,8 @@ function barChart(target, options, env2) {
|
|
|
2452
2833
|
const record = records.get(key);
|
|
2453
2834
|
if (record) showTooltip(record);
|
|
2454
2835
|
},
|
|
2455
|
-
hide: () => tooltip.hide()
|
|
2836
|
+
hide: () => tooltip.hide(),
|
|
2837
|
+
element: () => tooltip.element()
|
|
2456
2838
|
}
|
|
2457
2839
|
});
|
|
2458
2840
|
const unwatchHoverDuration = watchHoverDuration(svg, motion2);
|
|
@@ -2485,7 +2867,7 @@ function barChart(target, options, env2) {
|
|
|
2485
2867
|
});
|
|
2486
2868
|
hover.sync();
|
|
2487
2869
|
runner.enter(order.map(input));
|
|
2488
|
-
return {
|
|
2870
|
+
return linkable(hover.link, {
|
|
2489
2871
|
element: svg,
|
|
2490
2872
|
async update(next) {
|
|
2491
2873
|
if (destroyed) return;
|
|
@@ -2511,7 +2893,7 @@ function barChart(target, options, env2) {
|
|
|
2511
2893
|
transitions.supersede();
|
|
2512
2894
|
const swapping = swapped !== effects;
|
|
2513
2895
|
effects = swapped;
|
|
2514
|
-
const
|
|
2896
|
+
const leaves2 = playUpdate(
|
|
2515
2897
|
{
|
|
2516
2898
|
runner,
|
|
2517
2899
|
events,
|
|
@@ -2519,6 +2901,7 @@ function barChart(target, options, env2) {
|
|
|
2519
2901
|
leaving,
|
|
2520
2902
|
input,
|
|
2521
2903
|
onScreen,
|
|
2904
|
+
data: "data" in next,
|
|
2522
2905
|
...swapping ? {
|
|
2523
2906
|
swap: (diff) => {
|
|
2524
2907
|
const entering = new Set(diff.entering);
|
|
@@ -2533,7 +2916,7 @@ function barChart(target, options, env2) {
|
|
|
2533
2916
|
);
|
|
2534
2917
|
if (byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
|
|
2535
2918
|
const settled = transitionTo(nextLayout, motion2.mode === "off" || nextLayout.orientation !== orientation);
|
|
2536
|
-
await transitions.wait(settled,
|
|
2919
|
+
await transitions.wait(settled, leaves2);
|
|
2537
2920
|
},
|
|
2538
2921
|
on: events.on,
|
|
2539
2922
|
marks: () => order.map((record) => record.shown.geometry),
|
|
@@ -2573,11 +2956,12 @@ function barChart(target, options, env2) {
|
|
|
2573
2956
|
order = [];
|
|
2574
2957
|
svg.remove();
|
|
2575
2958
|
}
|
|
2576
|
-
};
|
|
2959
|
+
});
|
|
2577
2960
|
}
|
|
2578
2961
|
function checkOptions(options) {
|
|
2579
2962
|
checkChartOptions(options, "barChart");
|
|
2580
|
-
const { colorBy } = options;
|
|
2963
|
+
const { colorBy, room } = options;
|
|
2964
|
+
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)}.`);
|
|
2581
2965
|
if (colorBy !== void 0 && colorBy !== "series" && colorBy !== "category") throw new TypeError(`barChart: colorBy must be "series" or "category", got ${String(colorBy)}.`);
|
|
2582
2966
|
if (colorBy === "category" && options.stack !== void 0) {
|
|
2583
2967
|
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.');
|
|
@@ -2590,10 +2974,10 @@ function markLabel(row, options) {
|
|
|
2590
2974
|
const formatted = format(options);
|
|
2591
2975
|
const values = labelled(row.values, options);
|
|
2592
2976
|
const lone = values.length === 1 && values[0].series === "value" && values[0].label === "value";
|
|
2593
|
-
const text2 = `${row.
|
|
2977
|
+
const text2 = `${row.category}: ${values.map((v) => lone ? formatted(v.value) : `${formatted(v.value)} ${v.label}`).join(", ")}`;
|
|
2594
2978
|
if (!options.markLabel) return text2;
|
|
2595
2979
|
try {
|
|
2596
|
-
const named = options.markLabel(row.datum, { key: row.key, category: row.
|
|
2980
|
+
const named = options.markLabel(row.datum, { key: row.key, category: row.category, values, total: row.total, format: formatted, text: text2 });
|
|
2597
2981
|
if (named !== void 0 && named !== null && String(named).trim() !== "") return String(named);
|
|
2598
2982
|
} catch (error) {
|
|
2599
2983
|
report(error);
|
|
@@ -2641,9 +3025,9 @@ var GAP3 = 10;
|
|
|
2641
3025
|
var LABEL_ANGLE = Math.PI / 12;
|
|
2642
3026
|
var LABEL_SIZE2 = 12.5;
|
|
2643
3027
|
var VALUE_SIZE2 = 12.5;
|
|
2644
|
-
var
|
|
3028
|
+
var ASCENT2 = 10;
|
|
2645
3029
|
var LINE = 15;
|
|
2646
|
-
var BLOCK =
|
|
3030
|
+
var BLOCK = ASCENT2 + LINE + 3;
|
|
2647
3031
|
var LABEL_SPACE = 2;
|
|
2648
3032
|
var CENTER_SIZE = 26;
|
|
2649
3033
|
var CENTER_MIN = 14;
|
|
@@ -2672,17 +3056,18 @@ function layoutDonut(input) {
|
|
|
2672
3056
|
const frame = donutFrame(input, rows2);
|
|
2673
3057
|
const total2 = rows2.reduce((sum, row) => sum + row.value, 0);
|
|
2674
3058
|
const starts = joinedStarts(rows2.map((row) => row.value));
|
|
2675
|
-
const
|
|
3059
|
+
const states = rows2.map((row, i) => {
|
|
2676
3060
|
const share = total2 > 0 ? row.value / total2 : 0;
|
|
2677
3061
|
const end = i + 1 < rows2.length && total2 > 0 ? starts[i + 1] : total2 > 0 ? 1 : 0;
|
|
2678
|
-
return
|
|
3062
|
+
return { ...row, series: input.encoding.series, share, start: starts[i] * TAU, end: end * TAU };
|
|
2679
3063
|
});
|
|
3064
|
+
const labels = placeLabels2(frame, states, input.measure);
|
|
2680
3065
|
const centerText2 = input.center(total2);
|
|
2681
3066
|
return {
|
|
2682
3067
|
frame,
|
|
2683
3068
|
total: total2,
|
|
2684
|
-
slices,
|
|
2685
|
-
labels
|
|
3069
|
+
slices: states.map((state, i) => placeSlice(frame, state, labels[i], input.measure)),
|
|
3070
|
+
labels,
|
|
2686
3071
|
centerText: centerText2,
|
|
2687
3072
|
center: placeCenter(frame, centerText2, input.measure)
|
|
2688
3073
|
};
|
|
@@ -2696,7 +3081,7 @@ function joinedStarts(values) {
|
|
|
2696
3081
|
return start;
|
|
2697
3082
|
});
|
|
2698
3083
|
}
|
|
2699
|
-
function placeSlice(frame, state) {
|
|
3084
|
+
function placeSlice(frame, state, label2, measure) {
|
|
2700
3085
|
const geometry = describe.arc({
|
|
2701
3086
|
key: state.key,
|
|
2702
3087
|
series: state.series,
|
|
@@ -2705,27 +3090,28 @@ function placeSlice(frame, state) {
|
|
|
2705
3090
|
inner: frame.inner,
|
|
2706
3091
|
outer: frame.outer,
|
|
2707
3092
|
start: state.start,
|
|
2708
|
-
end: state.end
|
|
3093
|
+
end: state.end,
|
|
3094
|
+
labelBounds: label2 && measure ? labelBoxes(label2, measure) : []
|
|
2709
3095
|
});
|
|
2710
3096
|
return { ...state, geometry, data: sliceData(state.datum, state.share, state.series) };
|
|
2711
3097
|
}
|
|
2712
|
-
function
|
|
3098
|
+
function placeLabels2(frame, slices, measure) {
|
|
2713
3099
|
let previous;
|
|
2714
3100
|
let first;
|
|
2715
3101
|
const labels = slices.map((slice, i) => {
|
|
2716
3102
|
if (slice.end - slice.start < LABEL_ANGLE - 1e-9) return void 0;
|
|
2717
|
-
const
|
|
2718
|
-
const { box } =
|
|
3103
|
+
const label2 = labelAt(frame, slice, measure);
|
|
3104
|
+
const { box } = label2;
|
|
2719
3105
|
if (box.x < 0 || box.y < 0 || box.x + box.width > frame.width || box.y + box.height > frame.height) return void 0;
|
|
2720
|
-
if (previous &&
|
|
3106
|
+
if (previous && overlaps2(previous, box)) return void 0;
|
|
2721
3107
|
previous = box;
|
|
2722
3108
|
first ?? (first = i);
|
|
2723
|
-
return
|
|
3109
|
+
return label2;
|
|
2724
3110
|
});
|
|
2725
3111
|
for (let i = labels.length - 1; first !== void 0 && i > first; i--) {
|
|
2726
|
-
const
|
|
2727
|
-
if (!
|
|
2728
|
-
if (!
|
|
3112
|
+
const label2 = labels[i];
|
|
3113
|
+
if (!label2) continue;
|
|
3114
|
+
if (!overlaps2(labels[first].box, label2.box)) break;
|
|
2729
3115
|
labels[i] = void 0;
|
|
2730
3116
|
}
|
|
2731
3117
|
return labels;
|
|
@@ -2781,12 +3167,18 @@ function labelAt(frame, slice, measure) {
|
|
|
2781
3167
|
const top = y - BLOCK * (cos + 1) / 2;
|
|
2782
3168
|
const along = (w) => x + sin * w / 2;
|
|
2783
3169
|
return {
|
|
2784
|
-
category: { x: along(widths[0]), y: top +
|
|
2785
|
-
share: { x: along(widths[1]), y: top +
|
|
3170
|
+
category: { x: along(widths[0]), y: top + ASCENT2, anchor: "middle", text: slice.category },
|
|
3171
|
+
share: { x: along(widths[1]), y: top + ASCENT2 + LINE, anchor: "middle", text: share },
|
|
2786
3172
|
box: { x: along(width) - width / 2, y: top, width, height: BLOCK }
|
|
2787
3173
|
};
|
|
2788
3174
|
}
|
|
2789
|
-
function
|
|
3175
|
+
function labelBoxes(label2, measure) {
|
|
3176
|
+
const out = [];
|
|
3177
|
+
if (label2.category.text !== "") out.push(textBox(label2.category, measure, "ec-label", LABEL_SIZE2));
|
|
3178
|
+
if (label2.share.text !== "") out.push(textBox(label2.share, measure, "ec-value", VALUE_SIZE2));
|
|
3179
|
+
return out;
|
|
3180
|
+
}
|
|
3181
|
+
function overlaps2(a, b) {
|
|
2790
3182
|
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;
|
|
2791
3183
|
}
|
|
2792
3184
|
function sliceData(datum, share, series) {
|
|
@@ -2921,7 +3313,7 @@ function donutChart(target, options, env2) {
|
|
|
2921
3313
|
byGroup.set(group, record);
|
|
2922
3314
|
return record;
|
|
2923
3315
|
}
|
|
2924
|
-
function drawMark(record, slice,
|
|
3316
|
+
function drawMark(record, slice, label2) {
|
|
2925
3317
|
const before = record.parts[0]?.colors.color;
|
|
2926
3318
|
record.shown = slice;
|
|
2927
3319
|
const { outline: outline2 } = slice.geometry;
|
|
@@ -2934,10 +3326,10 @@ function donutChart(target, options, env2) {
|
|
|
2934
3326
|
record.parts = [{ element: record.path, d: outline2.d, colors: sliceColors, visible }];
|
|
2935
3327
|
const presence = record.presence.value;
|
|
2936
3328
|
const opacity = presence < 1 ? presence : void 0;
|
|
2937
|
-
record.drawnLabel =
|
|
3329
|
+
record.drawnLabel = label2;
|
|
2938
3330
|
for (const [text2, placement] of [
|
|
2939
|
-
[record.label,
|
|
2940
|
-
[record.share,
|
|
3331
|
+
[record.label, label2?.category],
|
|
3332
|
+
[record.share, label2?.share]
|
|
2941
3333
|
]) {
|
|
2942
3334
|
if (placement) placeText(text2, placement);
|
|
2943
3335
|
setAttributes(text2, { visibility: placement ? void 0 : "hidden", opacity });
|
|
@@ -2950,9 +3342,9 @@ function donutChart(target, options, env2) {
|
|
|
2950
3342
|
const record = key === void 0 ? void 0 : records.get(key);
|
|
2951
3343
|
focusRing.draw(record && { outline: record.shown.geometry.outline, thickness: record.shown.geometry.thickness, transform: record.handle.style.transform });
|
|
2952
3344
|
}
|
|
2953
|
-
function show3(record, slice,
|
|
2954
|
-
const moved = geometryChanged(record.shown.geometry, slice.geometry);
|
|
2955
|
-
drawMark(record, slice,
|
|
3345
|
+
function show3(record, slice, label2) {
|
|
3346
|
+
const moved = geometryChanged(record.shown.geometry, slice.geometry) || record.shown.datum !== slice.datum;
|
|
3347
|
+
drawMark(record, slice, label2);
|
|
2956
3348
|
if (moved) runner.change(slice.geometry, slice.data);
|
|
2957
3349
|
if (record.key === hover.key) showTooltip(record);
|
|
2958
3350
|
}
|
|
@@ -3014,13 +3406,13 @@ function donutChart(target, options, env2) {
|
|
|
3014
3406
|
}
|
|
3015
3407
|
const key = (record) => record.key;
|
|
3016
3408
|
try {
|
|
3017
|
-
const
|
|
3018
|
-
if (
|
|
3409
|
+
const said2 = option({ text: text2, changed: changed.map(key), added: diff.entering.map(key), removed: diff.exiting.map(key) });
|
|
3410
|
+
if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
|
|
3019
3411
|
} catch (error) {
|
|
3020
3412
|
report(error);
|
|
3021
3413
|
}
|
|
3022
3414
|
}
|
|
3023
|
-
const
|
|
3415
|
+
const drawn2 = (record) => records.get(record.key) === record || leaving.get(record.key) === record;
|
|
3024
3416
|
const valueOf = (record) => Math.max(0, record.value.value);
|
|
3025
3417
|
function startsIn(slices, total2, value = valueOf) {
|
|
3026
3418
|
const starts = /* @__PURE__ */ new Map();
|
|
@@ -3032,8 +3424,8 @@ function donutChart(target, options, env2) {
|
|
|
3032
3424
|
return starts;
|
|
3033
3425
|
}
|
|
3034
3426
|
function angles() {
|
|
3035
|
-
ring = ring.filter(
|
|
3036
|
-
from = from.filter(
|
|
3427
|
+
ring = ring.filter(drawn2);
|
|
3428
|
+
from = from.filter(drawn2);
|
|
3037
3429
|
const total2 = ring.reduce((sum, record) => sum + valueOf(record), 0);
|
|
3038
3430
|
const to = startsIn(ring, total2);
|
|
3039
3431
|
const was = startsIn(from, total2);
|
|
@@ -3052,21 +3444,27 @@ function donutChart(target, options, env2) {
|
|
|
3052
3444
|
return out;
|
|
3053
3445
|
}
|
|
3054
3446
|
function currentSlices(f) {
|
|
3055
|
-
|
|
3447
|
+
const now = [...angles()].map(([record, { start, span: span2 }]) => {
|
|
3056
3448
|
const { row } = record;
|
|
3057
|
-
const
|
|
3449
|
+
const state = {
|
|
3058
3450
|
key: row.key,
|
|
3059
3451
|
datum: row.datum,
|
|
3060
3452
|
index: row.index,
|
|
3061
3453
|
category: row.category,
|
|
3062
3454
|
series: row.series,
|
|
3063
3455
|
value: valueOf(record),
|
|
3064
|
-
share:
|
|
3456
|
+
share: span2,
|
|
3065
3457
|
start: start * TAU2,
|
|
3066
|
-
end: (start +
|
|
3067
|
-
}
|
|
3068
|
-
return { record,
|
|
3458
|
+
end: (start + span2) * TAU2
|
|
3459
|
+
};
|
|
3460
|
+
return { record, state };
|
|
3069
3461
|
});
|
|
3462
|
+
const labels = placeLabels2(
|
|
3463
|
+
f,
|
|
3464
|
+
now.map(({ state }) => state),
|
|
3465
|
+
measure
|
|
3466
|
+
);
|
|
3467
|
+
return now.map(({ record, state }, i) => ({ record, slice: placeSlice(f, state, labels[i], measure), label: labels[i] }));
|
|
3070
3468
|
}
|
|
3071
3469
|
function draw() {
|
|
3072
3470
|
if (!dirty) return;
|
|
@@ -3074,12 +3472,7 @@ function donutChart(target, options, env2) {
|
|
|
3074
3472
|
const f = frame.value;
|
|
3075
3473
|
setAttributes(svg, sizeAttributes(f));
|
|
3076
3474
|
const slices = currentSlices(f);
|
|
3077
|
-
const
|
|
3078
|
-
f,
|
|
3079
|
-
slices.map(({ slice }) => slice),
|
|
3080
|
-
measure
|
|
3081
|
-
);
|
|
3082
|
-
slices.forEach(({ record, slice }, i) => show3(record, slice, labels[i]));
|
|
3475
|
+
for (const { record, slice, label: label2 } of slices) show3(record, slice, label2);
|
|
3083
3476
|
const total2 = slices.reduce((sum, { slice }) => sum + slice.value, 0);
|
|
3084
3477
|
drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round(total2, count)), measure));
|
|
3085
3478
|
}
|
|
@@ -3088,7 +3481,7 @@ function donutChart(target, options, env2) {
|
|
|
3088
3481
|
return counted.text;
|
|
3089
3482
|
}
|
|
3090
3483
|
function land() {
|
|
3091
|
-
ring = ring.filter(
|
|
3484
|
+
ring = ring.filter(drawn2);
|
|
3092
3485
|
from = ring;
|
|
3093
3486
|
for (const record of ring) {
|
|
3094
3487
|
record.turn.set(1);
|
|
@@ -3244,7 +3637,8 @@ function donutChart(target, options, env2) {
|
|
|
3244
3637
|
const record = records.get(key);
|
|
3245
3638
|
if (record) showTooltip(record);
|
|
3246
3639
|
},
|
|
3247
|
-
hide: () => tooltip.hide()
|
|
3640
|
+
hide: () => tooltip.hide(),
|
|
3641
|
+
element: () => tooltip.element()
|
|
3248
3642
|
}
|
|
3249
3643
|
});
|
|
3250
3644
|
const unwatchHoverDuration = watchHoverDuration(svg, motion2);
|
|
@@ -3278,7 +3672,7 @@ function donutChart(target, options, env2) {
|
|
|
3278
3672
|
drawCenter(laidOut.center);
|
|
3279
3673
|
hover.sync();
|
|
3280
3674
|
runner.enter(order.map(input));
|
|
3281
|
-
return {
|
|
3675
|
+
return linkable(hover.link, {
|
|
3282
3676
|
element: svg,
|
|
3283
3677
|
async update(next) {
|
|
3284
3678
|
if (destroyed) return;
|
|
@@ -3308,7 +3702,7 @@ function donutChart(target, options, env2) {
|
|
|
3308
3702
|
transitions.supersede();
|
|
3309
3703
|
const swapping = swapped !== effects;
|
|
3310
3704
|
effects = swapped;
|
|
3311
|
-
const
|
|
3705
|
+
const leaves2 = playUpdate(
|
|
3312
3706
|
{
|
|
3313
3707
|
runner,
|
|
3314
3708
|
events,
|
|
@@ -3316,6 +3710,7 @@ function donutChart(target, options, env2) {
|
|
|
3316
3710
|
leaving,
|
|
3317
3711
|
input,
|
|
3318
3712
|
onScreen,
|
|
3713
|
+
data: "data" in next,
|
|
3319
3714
|
...swapping ? {
|
|
3320
3715
|
swap: (diff) => {
|
|
3321
3716
|
const entering = new Set(diff.entering);
|
|
@@ -3330,7 +3725,7 @@ function donutChart(target, options, env2) {
|
|
|
3330
3725
|
);
|
|
3331
3726
|
count = nextLayout.total === totalBefore ? void 0 : Math.max(decimals(totalBefore), decimals(nextLayout.total));
|
|
3332
3727
|
const settled = transitionTo(nextLayout, motion2.mode === "off");
|
|
3333
|
-
await transitions.wait(settled,
|
|
3728
|
+
await transitions.wait(settled, leaves2);
|
|
3334
3729
|
},
|
|
3335
3730
|
on: events.on,
|
|
3336
3731
|
marks: () => order.map((record) => record.shown.geometry),
|
|
@@ -3369,7 +3764,7 @@ function donutChart(target, options, env2) {
|
|
|
3369
3764
|
order = ring = from = [];
|
|
3370
3765
|
svg.remove();
|
|
3371
3766
|
}
|
|
3372
|
-
};
|
|
3767
|
+
});
|
|
3373
3768
|
}
|
|
3374
3769
|
function checkOptions2(options) {
|
|
3375
3770
|
checkChartOptions(options, "donutChart");
|
|
@@ -3379,8 +3774,8 @@ function checkOptions2(options) {
|
|
|
3379
3774
|
}
|
|
3380
3775
|
function valueText(slice, options) {
|
|
3381
3776
|
const formatted = format(options)(slice.value);
|
|
3382
|
-
const
|
|
3383
|
-
return slice.series === "value" &&
|
|
3777
|
+
const label2 = seriesLabel(options.seriesLabels, slice.series);
|
|
3778
|
+
return slice.series === "value" && label2 === "value" ? formatted : `${formatted} ${label2}`;
|
|
3384
3779
|
}
|
|
3385
3780
|
function namesFor(options, layout) {
|
|
3386
3781
|
return new Map(layout.slices.map((slice) => [slice.key, markLabel2(slice, options)]));
|
|
@@ -3410,9 +3805,9 @@ function centerText(options, series, total2) {
|
|
|
3410
3805
|
const formatted = format(options);
|
|
3411
3806
|
if (center === false) return "";
|
|
3412
3807
|
if (center === void 0) {
|
|
3413
|
-
const
|
|
3414
|
-
return series === "value" &&
|
|
3415
|
-
${
|
|
3808
|
+
const label2 = seriesLabel(options.seriesLabels, series);
|
|
3809
|
+
return series === "value" && label2 === "value" ? formatted(total2) : `${formatted(total2)}
|
|
3810
|
+
${label2}`;
|
|
3416
3811
|
}
|
|
3417
3812
|
try {
|
|
3418
3813
|
const text2 = center(total2, formatted);
|
|
@@ -3422,10 +3817,10 @@ ${label}`;
|
|
|
3422
3817
|
return "";
|
|
3423
3818
|
}
|
|
3424
3819
|
}
|
|
3425
|
-
function description(
|
|
3820
|
+
function description(own2, center) {
|
|
3426
3821
|
const text2 = center.split("\n").join(" ").trim();
|
|
3427
|
-
const mine =
|
|
3428
|
-
if (text2 === "") return
|
|
3822
|
+
const mine = own2?.trim();
|
|
3823
|
+
if (text2 === "") return own2;
|
|
3429
3824
|
if (!mine) return text2;
|
|
3430
3825
|
return /[.!?:;]$/.test(mine) ? `${mine} ${text2}` : `${mine}. ${text2}`;
|
|
3431
3826
|
}
|
|
@@ -3475,9 +3870,9 @@ var FIELDS = {
|
|
|
3475
3870
|
second: { hour: "numeric", minute: "2-digit", second: "2-digit" },
|
|
3476
3871
|
millisecond: { hour: "numeric", minute: "2-digit", second: "2-digit", ...FRACTION }
|
|
3477
3872
|
};
|
|
3478
|
-
function timeStep(
|
|
3479
|
-
for (const step2 of STEPS) if (LONGEST[step2.unit] * step2.count >=
|
|
3480
|
-
return { unit: "year", count: Math.max(1, niceStep(
|
|
3873
|
+
function timeStep(span2) {
|
|
3874
|
+
for (const step2 of STEPS) if (LONGEST[step2.unit] * step2.count >= span2) return step2;
|
|
3875
|
+
return { unit: "year", count: Math.max(1, niceStep(span2 / LONGEST.year)) };
|
|
3481
3876
|
}
|
|
3482
3877
|
function timeTicks(lo, hi, zone) {
|
|
3483
3878
|
const word = tickWording(zone);
|
|
@@ -3503,9 +3898,9 @@ function boundaries(lo, hi, step2, zone) {
|
|
|
3503
3898
|
const grain = unit === "hour" ? 15 * MINUTE : LONGEST[unit];
|
|
3504
3899
|
let t = lo - start.ms - (unit === "second" ? 0 : start.seconds * SECOND) - (unit === "hour" ? start.minutes % 15 * MINUTE : 0);
|
|
3505
3900
|
for (; t < hi; t += grain) {
|
|
3506
|
-
const
|
|
3507
|
-
const whole = unit !== "hour" ||
|
|
3508
|
-
const field = unit === "second" ?
|
|
3901
|
+
const parts2 = partsOf(t, zone);
|
|
3902
|
+
const whole = unit !== "hour" || parts2.minutes === 0;
|
|
3903
|
+
const field = unit === "second" ? parts2.seconds : unit === "minute" ? parts2.minutes : parts2.hours;
|
|
3509
3904
|
if (t > lo && whole && field % count === 0) out.push(t);
|
|
3510
3905
|
}
|
|
3511
3906
|
return out;
|
|
@@ -3523,6 +3918,21 @@ function boundaries(lo, hi, step2, zone) {
|
|
|
3523
3918
|
}
|
|
3524
3919
|
return out;
|
|
3525
3920
|
}
|
|
3921
|
+
function monthsOn(t, months, zone) {
|
|
3922
|
+
const { year, month, date, hours, minutes, seconds, ms } = partsOf(t, zone);
|
|
3923
|
+
const last = /* @__PURE__ */ new Date(0);
|
|
3924
|
+
last.setUTCFullYear(year, month + months + 1, 0);
|
|
3925
|
+
const day = Math.min(date, last.getUTCDate());
|
|
3926
|
+
const d = /* @__PURE__ */ new Date(0);
|
|
3927
|
+
if (zone === "UTC") {
|
|
3928
|
+
d.setUTCFullYear(year, month + months, day);
|
|
3929
|
+
d.setUTCHours(hours, minutes, seconds, ms);
|
|
3930
|
+
} else {
|
|
3931
|
+
d.setFullYear(year, month + months, day);
|
|
3932
|
+
d.setHours(hours, minutes, seconds, ms);
|
|
3933
|
+
}
|
|
3934
|
+
return d.getTime();
|
|
3935
|
+
}
|
|
3526
3936
|
function timeLevel(t, zone) {
|
|
3527
3937
|
const { ms, seconds, minutes, hours, date, month } = partsOf(t, zone);
|
|
3528
3938
|
if (ms !== 0) return "millisecond";
|
|
@@ -3543,9 +3953,9 @@ function timeName(times, zone) {
|
|
|
3543
3953
|
function tickWording(zone) {
|
|
3544
3954
|
const formats = /* @__PURE__ */ new Map();
|
|
3545
3955
|
return (t, upTo) => {
|
|
3546
|
-
const
|
|
3956
|
+
const own2 = LEVELS.indexOf(timeLevel(t, zone));
|
|
3547
3957
|
const fields = {};
|
|
3548
|
-
for (let i = Math.min(
|
|
3958
|
+
for (let i = Math.min(own2, LEVELS.indexOf(upTo)); i <= own2; i++) Object.assign(fields, FIELDS[LEVELS[i]]);
|
|
3549
3959
|
const id = JSON.stringify(fields);
|
|
3550
3960
|
let format2 = formats.get(id);
|
|
3551
3961
|
if (!format2) formats.set(id, format2 = new Intl.DateTimeFormat(void 0, { ...fields, timeZone: zoneOption(zone) }));
|
|
@@ -3612,7 +4022,7 @@ function layoutLines(input) {
|
|
|
3612
4022
|
const height = input.height ?? HEIGHT2;
|
|
3613
4023
|
const { rows: rows2, time } = prepareRows2(input);
|
|
3614
4024
|
const series = input.encoding.series.map((s) => s.series);
|
|
3615
|
-
const domain = niceDomain(rows2.flatMap((row) => row.values.
|
|
4025
|
+
const domain = niceDomain(rows2.flatMap((row) => row.values.flatMap((v) => v.value === void 0 ? [] : [v.value])));
|
|
3616
4026
|
const yTexts = domain.ticks.map(input.format);
|
|
3617
4027
|
const xLo = rows2[0]?.x ?? 0;
|
|
3618
4028
|
const xHi = rows2[rows2.length - 1]?.x ?? 0;
|
|
@@ -3629,7 +4039,7 @@ function layoutLines(input) {
|
|
|
3629
4039
|
};
|
|
3630
4040
|
const decimalsBy = {};
|
|
3631
4041
|
for (const name of series) decimalsBy[name] = 0;
|
|
3632
|
-
for (const row of rows2) for (const v of row.values) decimalsBy[v.series] = Math.max(decimalsBy[v.series], decimals(v.value));
|
|
4042
|
+
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));
|
|
3633
4043
|
const xTicks = xValues.map((value, i) => placeXTick(frame, value, xTexts[i]));
|
|
3634
4044
|
return {
|
|
3635
4045
|
width,
|
|
@@ -3652,7 +4062,7 @@ function positions(frame) {
|
|
|
3652
4062
|
y: (value) => ySpan > 0 ? box.bottom - (value - scale.lo) / ySpan * (box.bottom - box.top) : box.bottom
|
|
3653
4063
|
};
|
|
3654
4064
|
}
|
|
3655
|
-
function placeLines(frame, rows2, series, through, time = false) {
|
|
4065
|
+
function placeLines(frame, rows2, series, through, time = false, labels) {
|
|
3656
4066
|
const first = rows2[0];
|
|
3657
4067
|
if (!first) return [];
|
|
3658
4068
|
const at = positions(frame);
|
|
@@ -3663,28 +4073,62 @@ function placeLines(frame, rows2, series, through, time = false) {
|
|
|
3663
4073
|
const share = next && next.x > end.x && through > end.x ? (through - end.x) / (next.x - end.x) : void 0;
|
|
3664
4074
|
const shown = rows2.slice(0, last + 1);
|
|
3665
4075
|
const datas = /* @__PURE__ */ new Map();
|
|
3666
|
-
const related = (
|
|
3667
|
-
const
|
|
3668
|
-
const
|
|
3669
|
-
|
|
4076
|
+
const related = (own2) => (name) => name === own2 ? void 0 : datas.get(name);
|
|
4077
|
+
const traced = series.map((name) => {
|
|
4078
|
+
const has = (row) => !row.missing?.has(name);
|
|
4079
|
+
const vertices = [];
|
|
4080
|
+
let gap = false;
|
|
4081
|
+
for (const row of shown) {
|
|
4082
|
+
if (!has(row)) gap = vertices.length > 0;
|
|
4083
|
+
else {
|
|
4084
|
+
vertices.push({ at: row.x, value: row.values[name] ?? 0, datum: row.datum, gapBefore: gap });
|
|
4085
|
+
gap = false;
|
|
4086
|
+
}
|
|
4087
|
+
}
|
|
4088
|
+
if (share !== void 0 && has(end) && has(next)) {
|
|
3670
4089
|
const from = end.values[name] ?? 0;
|
|
3671
|
-
vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from) });
|
|
4090
|
+
vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from), datum: end.datum, gapBefore: false });
|
|
3672
4091
|
}
|
|
3673
|
-
const points = vertices.map((v) => ({ x: at.x(v.at), y: at.y(v.value) }));
|
|
3674
|
-
|
|
4092
|
+
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) }];
|
|
4093
|
+
return { name, vertices, points };
|
|
4094
|
+
});
|
|
4095
|
+
const named = traced.filter(({ vertices }) => vertices.length > 0);
|
|
4096
|
+
const placed2 = labels ? placeEndLabels(
|
|
4097
|
+
frame,
|
|
4098
|
+
named.map(({ name, vertices, points }) => ({ ...points[points.length - 1], text: labels.text(name, vertices[vertices.length - 1].value) }))
|
|
4099
|
+
) : [];
|
|
4100
|
+
const lines = traced.map(({ name, vertices, points }) => {
|
|
4101
|
+
const tip = points[points.length - 1];
|
|
4102
|
+
const label2 = labels ? placed2[named.findIndex((line) => line.name === name)] ?? { x: tip.x + LABEL_GAP, y: tip.y + VALUE_SIZE3 * CENTRE3, anchor: "start", text: "" } : void 0;
|
|
4103
|
+
const labelBounds = labels ? label2 && label2.text !== "" ? [textBox(label2, labels.measure, "ec-value", VALUE_SIZE3)] : [] : void 0;
|
|
4104
|
+
const breaks = vertices.flatMap((v, j) => v.gapBefore ? [j] : []);
|
|
4105
|
+
const geometry = describe.line({ key: name, series: name, points, width: LINE_WIDTH, ...breaks.length > 0 ? { breaks } : {}, ...labelBounds ? { labelBounds } : {} });
|
|
3675
4106
|
let distance3 = 0;
|
|
3676
4107
|
const samples = vertices.map((v, j) => {
|
|
3677
4108
|
if (j > 0) distance3 += Math.hypot(points[j].x - points[j - 1].x, points[j].y - points[j - 1].y);
|
|
3678
4109
|
const t = geometry.length > 0 ? j === vertices.length - 1 ? 1 : Math.min(1, distance3 / geometry.length) : 0;
|
|
3679
|
-
return { t, value: v.value, at: sampleAt(v.at, time) };
|
|
4110
|
+
return { t, value: v.value, at: sampleAt(v.at, time), ...v.gapBefore ? { gapBefore: true } : {} };
|
|
3680
4111
|
});
|
|
3681
|
-
const
|
|
4112
|
+
const last2 = vertices[vertices.length - 1];
|
|
4113
|
+
const data = { datum: last2 ? last2.datum : end.datum, samples, related: related(name) };
|
|
3682
4114
|
datas.set(name, data);
|
|
3683
|
-
|
|
3684
|
-
return { series: name, geometry, data, end: { ...points[points.length - 1], value: tip.value } };
|
|
4115
|
+
return { series: name, geometry, data, end: { ...tip, value: last2 ? last2.value : first.values[name] ?? 0 }, label: label2 };
|
|
3685
4116
|
});
|
|
3686
4117
|
return lines;
|
|
3687
4118
|
}
|
|
4119
|
+
function loneValues(rows2, series) {
|
|
4120
|
+
const lone = /* @__PURE__ */ new Set();
|
|
4121
|
+
if (!rows2.some((row) => row.missing !== void 0 && row.missing.size > 0)) return lone;
|
|
4122
|
+
const has = (row, name) => row !== void 0 && !row.missing?.has(name);
|
|
4123
|
+
rows2.forEach((row, i) => {
|
|
4124
|
+
for (const name of series) {
|
|
4125
|
+
const before = rows2[i - 1];
|
|
4126
|
+
const after = rows2[i + 1];
|
|
4127
|
+
if (has(row, name) && !has(before, name) && !has(after, name) && (before !== void 0 || after !== void 0)) lone.add(pointKey(name, row.key));
|
|
4128
|
+
}
|
|
4129
|
+
});
|
|
4130
|
+
return lone;
|
|
4131
|
+
}
|
|
3688
4132
|
function pointKey(series, row) {
|
|
3689
4133
|
return `${series}@${row}`;
|
|
3690
4134
|
}
|
|
@@ -3692,7 +4136,7 @@ function placePoints(frame, row, series, time = false) {
|
|
|
3692
4136
|
const at = positions(frame);
|
|
3693
4137
|
const x = at.x(row.x);
|
|
3694
4138
|
const datas = /* @__PURE__ */ new Map();
|
|
3695
|
-
return series.map((name) => {
|
|
4139
|
+
return series.filter((name) => !row.missing?.has(name)).map((name) => {
|
|
3696
4140
|
const value = row.values[name] ?? 0;
|
|
3697
4141
|
const key = pointKey(name, row.key);
|
|
3698
4142
|
const data = { datum: row.datum, samples: [{ t: 0, value, at: sampleAt(row.x, time) }], related: (other) => other === name ? void 0 : datas.get(other) };
|
|
@@ -3726,8 +4170,8 @@ function spread(values, gap, min, max) {
|
|
|
3726
4170
|
const clusters = [];
|
|
3727
4171
|
const place = (members) => {
|
|
3728
4172
|
const mean = members.reduce((sum, m) => sum + m.value, 0) / members.length;
|
|
3729
|
-
const
|
|
3730
|
-
return Math.max(min, Math.min(max -
|
|
4173
|
+
const span2 = (members.length - 1) * gap;
|
|
4174
|
+
return Math.max(min, Math.min(max - span2, mean - span2 / 2));
|
|
3731
4175
|
};
|
|
3732
4176
|
for (const item of order) {
|
|
3733
4177
|
clusters.push({ members: [item], start: place([item]) });
|
|
@@ -3799,7 +4243,34 @@ function prepareRows2({ data, encoding }) {
|
|
|
3799
4243
|
}
|
|
3800
4244
|
}
|
|
3801
4245
|
const word = xWording(encoding, time, read.map((row) => row.x));
|
|
3802
|
-
|
|
4246
|
+
const levels = levelsOf(read, encoding.series.length);
|
|
4247
|
+
return {
|
|
4248
|
+
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] })),
|
|
4249
|
+
time
|
|
4250
|
+
};
|
|
4251
|
+
}
|
|
4252
|
+
function levelsOf(rows2, count) {
|
|
4253
|
+
const levels = rows2.map(() => ({}));
|
|
4254
|
+
for (let s = 0; s < count; s++) {
|
|
4255
|
+
let before = -1;
|
|
4256
|
+
let after = -1;
|
|
4257
|
+
rows2.forEach((row, i) => {
|
|
4258
|
+
const { series, value } = row.values[s];
|
|
4259
|
+
if (value !== void 0) {
|
|
4260
|
+
levels[i][series] = value;
|
|
4261
|
+
before = i;
|
|
4262
|
+
return;
|
|
4263
|
+
}
|
|
4264
|
+
if (after <= i) {
|
|
4265
|
+
after = i + 1;
|
|
4266
|
+
while (after < rows2.length && rows2[after].values[s].value === void 0) after++;
|
|
4267
|
+
}
|
|
4268
|
+
const a = rows2[before]?.values[s].value;
|
|
4269
|
+
const b = rows2[after]?.values[s].value;
|
|
4270
|
+
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;
|
|
4271
|
+
});
|
|
4272
|
+
}
|
|
4273
|
+
return levels;
|
|
3803
4274
|
}
|
|
3804
4275
|
function xOf(x, index, time) {
|
|
3805
4276
|
if (x instanceof Date) {
|
|
@@ -3825,13 +4296,15 @@ function sampleAt(x, time) {
|
|
|
3825
4296
|
}
|
|
3826
4297
|
function numberOf3(value, series, key) {
|
|
3827
4298
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
3828
|
-
|
|
4299
|
+
if (value === null || value === void 0) return void 0;
|
|
4300
|
+
throw new RangeError(`lineChart: "${series}" for "${key}" must be a finite number, or null or undefined where it has no value, got ${show(value)}.`);
|
|
3829
4301
|
}
|
|
3830
|
-
function distinctLabels(rows2,
|
|
4302
|
+
function distinctLabels(rows2, label2) {
|
|
3831
4303
|
const shapes = /* @__PURE__ */ new Map();
|
|
3832
4304
|
for (const row of rows2) {
|
|
3833
4305
|
for (const { series, value } of row.values) {
|
|
3834
|
-
|
|
4306
|
+
if (value === void 0) continue;
|
|
4307
|
+
const text2 = label2(series, value);
|
|
3835
4308
|
const shape = text2.replace(/\d/g, "0");
|
|
3836
4309
|
if (!shapes.has(shape)) shapes.set(shape, text2);
|
|
3837
4310
|
}
|
|
@@ -3958,8 +4431,8 @@ function lineChart(target, options, env2) {
|
|
|
3958
4431
|
const text2 = `${formatted(value)} ${seriesLabel(opts.seriesLabels, series)}`;
|
|
3959
4432
|
if (typeof labels !== "function") return text2;
|
|
3960
4433
|
try {
|
|
3961
|
-
const
|
|
3962
|
-
return
|
|
4434
|
+
const own2 = labels(value, series, formatted);
|
|
4435
|
+
return own2 === void 0 || own2 === null ? "" : String(own2);
|
|
3963
4436
|
} catch (error) {
|
|
3964
4437
|
if (!quiet && !labelFailures.has(labels)) {
|
|
3965
4438
|
labelFailures.add(labels);
|
|
@@ -3969,10 +4442,15 @@ function lineChart(target, options, env2) {
|
|
|
3969
4442
|
}
|
|
3970
4443
|
};
|
|
3971
4444
|
}
|
|
4445
|
+
function endLabels(given) {
|
|
4446
|
+
const label2 = labeler(current);
|
|
4447
|
+
if (!label2) return void 0;
|
|
4448
|
+
return { text: (series, value) => label2(series, round(value, given[series] ?? decimals(value))), measure };
|
|
4449
|
+
}
|
|
3972
4450
|
function placedFor(next) {
|
|
3973
4451
|
const states = next.rows.map(restState);
|
|
3974
4452
|
return {
|
|
3975
|
-
lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time).map((line) => [line.series, line])),
|
|
4453
|
+
lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals)).map((line) => [line.series, line])),
|
|
3976
4454
|
points: new Map(states.flatMap((state) => placePoints(next.frame, state, next.series, next.time)).map((point) => [point.key, point]))
|
|
3977
4455
|
};
|
|
3978
4456
|
}
|
|
@@ -3995,17 +4473,18 @@ function lineChart(target, options, env2) {
|
|
|
3995
4473
|
column,
|
|
3996
4474
|
hit: svgElement("rect", { class: "ec-hit" }, column),
|
|
3997
4475
|
x: animated(row.x, interpolateNumber, env3),
|
|
3998
|
-
values: animated(
|
|
4476
|
+
values: animated(row.levels, interpolateRecord, env3),
|
|
3999
4477
|
presence: animated(entering ? 0 : 1, interpolateNumber, env3),
|
|
4000
4478
|
anchor: void 0,
|
|
4001
4479
|
points: [],
|
|
4002
4480
|
leaving: false,
|
|
4003
|
-
shown: true
|
|
4481
|
+
shown: true,
|
|
4482
|
+
px: 0
|
|
4004
4483
|
};
|
|
4005
4484
|
byColumn.set(column, record);
|
|
4006
4485
|
return record;
|
|
4007
4486
|
}
|
|
4008
|
-
function createLine(series,
|
|
4487
|
+
function createLine(series, placed2, entering) {
|
|
4009
4488
|
const group = svgElement("g", { class: "ec-line", "data-key": series, "data-series": series }, linesLayer);
|
|
4010
4489
|
const body = svgElement("g", { class: "ec-body" }, group);
|
|
4011
4490
|
const record = {
|
|
@@ -4020,46 +4499,46 @@ function lineChart(target, options, env2) {
|
|
|
4020
4499
|
drawnLabel: void 0,
|
|
4021
4500
|
parts: [],
|
|
4022
4501
|
handle: svgMarkHandle(() => record),
|
|
4023
|
-
target:
|
|
4024
|
-
shown:
|
|
4502
|
+
target: placed2,
|
|
4503
|
+
shown: placed2,
|
|
4025
4504
|
presence: animated(entering ? 0 : 1, interpolateNumber, { clock, motion: motion2, onChange: changed }),
|
|
4026
4505
|
leave: void 0
|
|
4027
4506
|
};
|
|
4028
4507
|
return record;
|
|
4029
4508
|
}
|
|
4030
|
-
function createPoint(row,
|
|
4031
|
-
const group = svgElement("g", { class: "ec-point", "data-key":
|
|
4509
|
+
function createPoint(row, placed2) {
|
|
4510
|
+
const group = svgElement("g", { class: "ec-point", "data-key": placed2.key, "data-series": placed2.series }, pointsLayer);
|
|
4032
4511
|
const body = svgElement("g", { class: "ec-body" }, group);
|
|
4033
4512
|
const record = {
|
|
4034
4513
|
kind: "point",
|
|
4035
|
-
key:
|
|
4036
|
-
series:
|
|
4514
|
+
key: placed2.key,
|
|
4515
|
+
series: placed2.series,
|
|
4037
4516
|
row,
|
|
4038
4517
|
group,
|
|
4039
4518
|
body,
|
|
4040
4519
|
path: svgElement("path", { class: "ec-dot" }, body),
|
|
4041
4520
|
parts: [],
|
|
4042
4521
|
handle: svgMarkHandle(() => record),
|
|
4043
|
-
target:
|
|
4044
|
-
shown:
|
|
4522
|
+
target: placed2,
|
|
4523
|
+
shown: placed2,
|
|
4045
4524
|
hidden: void 0,
|
|
4046
4525
|
leave: void 0
|
|
4047
4526
|
};
|
|
4048
4527
|
return record;
|
|
4049
4528
|
}
|
|
4050
|
-
const
|
|
4529
|
+
const drawn2 = (record) => findMark(record.key) === record;
|
|
4051
4530
|
const livePoints = (record) => record.points.filter((point) => points.get(point.key) === point);
|
|
4052
4531
|
const leavingLines = () => [...leaving.values()].filter((record) => record.kind === "line");
|
|
4053
4532
|
const currentFrame = () => ({ scale: scale.value, box: box.value });
|
|
4054
4533
|
function currentRows() {
|
|
4055
|
-
const
|
|
4534
|
+
const own2 = (record) => ({ x: record.x.value, values: record.values.value });
|
|
4056
4535
|
const states = /* @__PURE__ */ new Map();
|
|
4057
4536
|
const visiting = /* @__PURE__ */ new Set();
|
|
4058
4537
|
const stateOf = (record) => {
|
|
4059
4538
|
const known = states.get(record);
|
|
4060
4539
|
if (known) return known;
|
|
4061
4540
|
const p = record.presence.value;
|
|
4062
|
-
let state =
|
|
4541
|
+
let state = own2(record);
|
|
4063
4542
|
if (record.anchor && p < 1 && !visiting.has(record)) {
|
|
4064
4543
|
visiting.add(record);
|
|
4065
4544
|
const from = stateOf(record.anchor);
|
|
@@ -4072,7 +4551,7 @@ function lineChart(target, options, env2) {
|
|
|
4072
4551
|
const drawnRows = [...rowOrder, ...[...leavingRows.values()].filter((record) => record.presence.value > 0 && record.anchor)];
|
|
4073
4552
|
return drawnRows.map((record) => {
|
|
4074
4553
|
const { x, values } = stateOf(record);
|
|
4075
|
-
return { record, state: { key: record.key, datum: record.row.datum, x, values } };
|
|
4554
|
+
return { record, state: { key: record.key, datum: record.row.datum, x, values, missing: record.row.missing } };
|
|
4076
4555
|
}).sort((a, b) => a.state.x - b.state.x);
|
|
4077
4556
|
}
|
|
4078
4557
|
function draw() {
|
|
@@ -4083,9 +4562,10 @@ function lineChart(target, options, env2) {
|
|
|
4083
4562
|
paintFrame(frame);
|
|
4084
4563
|
paintLines(frame, states.map((s) => s.state));
|
|
4085
4564
|
for (const { record, state } of states) {
|
|
4086
|
-
const
|
|
4087
|
-
showAll(record.points.filter(
|
|
4565
|
+
const placed2 = new Map(placePoints(frame, state, record.points.map((point) => point.series), laidOut.time).map((point) => [point.key, point]));
|
|
4566
|
+
showAll(record.points.filter(drawn2).flatMap((point) => placed2.has(point.key) ? [{ record: point, placed: placed2.get(point.key) }] : []));
|
|
4088
4567
|
}
|
|
4568
|
+
paintAlone(states.map((s) => s.state));
|
|
4089
4569
|
paintColumns(frame, states);
|
|
4090
4570
|
followHover();
|
|
4091
4571
|
}
|
|
@@ -4104,7 +4584,7 @@ function lineChart(target, options, env2) {
|
|
|
4104
4584
|
leavingRows.clear();
|
|
4105
4585
|
for (const record of rowOrder) {
|
|
4106
4586
|
record.anchor = void 0;
|
|
4107
|
-
record.points = record.points.filter(
|
|
4587
|
+
record.points = record.points.filter(drawn2);
|
|
4108
4588
|
}
|
|
4109
4589
|
for (const [ticks, placedTicks] of [
|
|
4110
4590
|
[yTicks, laidOut.yTicks],
|
|
@@ -4116,11 +4596,11 @@ function lineChart(target, options, env2) {
|
|
|
4116
4596
|
tick.label.remove();
|
|
4117
4597
|
ticks.delete(tick.value);
|
|
4118
4598
|
}
|
|
4119
|
-
for (const
|
|
4120
|
-
const tick = ticks.get(
|
|
4599
|
+
for (const placed3 of placedTicks) {
|
|
4600
|
+
const tick = ticks.get(placed3.value);
|
|
4121
4601
|
if (!tick) continue;
|
|
4122
|
-
if (tick.line && "line" in
|
|
4123
|
-
placeText(tick.label,
|
|
4602
|
+
if (tick.line && "line" in placed3) setAttributes(tick.line, { ...placed3.line, opacity: void 0 });
|
|
4603
|
+
placeText(tick.label, placed3.label);
|
|
4124
4604
|
tick.label.removeAttribute("opacity");
|
|
4125
4605
|
}
|
|
4126
4606
|
}
|
|
@@ -4128,7 +4608,7 @@ function lineChart(target, options, env2) {
|
|
|
4128
4608
|
const { frame } = laidOut;
|
|
4129
4609
|
setAttributes(svg, sizeAttributes(frame.box));
|
|
4130
4610
|
drawnFrame = frame;
|
|
4131
|
-
const
|
|
4611
|
+
const placed2 = placedFor(laidOut);
|
|
4132
4612
|
const settle = (records, next) => {
|
|
4133
4613
|
const pairs = records.flatMap((record) => {
|
|
4134
4614
|
const to = next(record);
|
|
@@ -4138,10 +4618,11 @@ function lineChart(target, options, env2) {
|
|
|
4138
4618
|
if (!kept) for (const { record, to } of pairs) record.target = to;
|
|
4139
4619
|
showAll(pairs.map(({ record }) => ({ record, placed: record.target })));
|
|
4140
4620
|
};
|
|
4141
|
-
settle(lineOrder, (line) =>
|
|
4142
|
-
paintLabels(
|
|
4621
|
+
settle(lineOrder, (line) => placed2.lines.get(line.series));
|
|
4622
|
+
paintLabels(new Map(lineOrder.flatMap((line) => placed2.lines.has(line.series) ? [[line, placed2.lines.get(line.series)]] : [])));
|
|
4143
4623
|
const states = rowOrder.map((record) => ({ record, state: restState(record.row) }));
|
|
4144
|
-
for (const { record } of states) settle(livePoints(record), (point) =>
|
|
4624
|
+
for (const { record } of states) settle(livePoints(record), (point) => placed2.points.get(point.key));
|
|
4625
|
+
paintAlone(states.map((s) => s.state));
|
|
4145
4626
|
paintColumns(frame, states);
|
|
4146
4627
|
followHover();
|
|
4147
4628
|
dirty = false;
|
|
@@ -4151,10 +4632,10 @@ function lineChart(target, options, env2) {
|
|
|
4151
4632
|
setAttributes(svg, sizeAttributes(frame.box));
|
|
4152
4633
|
const formatted = format(current);
|
|
4153
4634
|
for (const tick of yTicks.values()) {
|
|
4154
|
-
const
|
|
4635
|
+
const placed2 = placeYTick(frame, tick.value, formatted(tick.value));
|
|
4155
4636
|
const opacity = tick.opacity.value < 1 ? tick.opacity.value : void 0;
|
|
4156
|
-
setAttributes(tick.line, { ...
|
|
4157
|
-
placeText(tick.label,
|
|
4637
|
+
setAttributes(tick.line, { ...placed2.line, opacity });
|
|
4638
|
+
placeText(tick.label, placed2.label);
|
|
4158
4639
|
setAttributes(tick.label, { opacity });
|
|
4159
4640
|
}
|
|
4160
4641
|
for (const tick of xTicks.values()) {
|
|
@@ -4165,46 +4646,39 @@ function lineChart(target, options, env2) {
|
|
|
4165
4646
|
function paintLines(frame, states) {
|
|
4166
4647
|
const drawnLines = [...lineOrder, ...leavingLines()];
|
|
4167
4648
|
if (states.length === 0 || drawnLines.length === 0) return;
|
|
4168
|
-
const
|
|
4169
|
-
showAll(drawnLines.map((line, i) => ({ record: line, placed:
|
|
4170
|
-
paintLabels(
|
|
4171
|
-
}
|
|
4172
|
-
function paintLabels(
|
|
4173
|
-
const label
|
|
4174
|
-
const entries = [...ends];
|
|
4175
|
-
const placed = label ? placeEndLabels(
|
|
4176
|
-
frame,
|
|
4177
|
-
entries.map(([line, { end }]) => ({ x: end.x, y: end.y, text: label(line.series, round(end.value, counting[line.series] ?? decimals(end.value))) }))
|
|
4178
|
-
) : [];
|
|
4179
|
-
entries.forEach(([line], i) => {
|
|
4180
|
-
const text2 = placed[i];
|
|
4649
|
+
const placed2 = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting));
|
|
4650
|
+
showAll(drawnLines.map((line, i) => ({ record: line, placed: placed2[i] })));
|
|
4651
|
+
paintLabels(new Map(drawnLines.map((line, i) => [line, placed2[i]])));
|
|
4652
|
+
}
|
|
4653
|
+
function paintLabels(ends) {
|
|
4654
|
+
for (const [line, { label: text2 }] of ends) {
|
|
4181
4655
|
if (text2) placeText(line.label, text2);
|
|
4182
4656
|
line.drawnLabel = text2 && text2.text !== "" ? text2 : void 0;
|
|
4183
4657
|
setAttributes(line.label, { visibility: line.drawnLabel ? void 0 : "hidden" });
|
|
4184
|
-
}
|
|
4658
|
+
}
|
|
4185
4659
|
}
|
|
4186
4660
|
function showAll(marks) {
|
|
4187
|
-
const related = marks.some(({ record, placed }) => !sameData(record.shown.data,
|
|
4188
|
-
for (const { record, placed } of marks) {
|
|
4189
|
-
if (record.kind === "line") showLine(record,
|
|
4190
|
-
else showPoint(record,
|
|
4661
|
+
const related = marks.some(({ record, placed: placed2 }) => !sameData(record.shown.data, placed2.data));
|
|
4662
|
+
for (const { record, placed: placed2 } of marks) {
|
|
4663
|
+
if (record.kind === "line") showLine(record, placed2, related);
|
|
4664
|
+
else showPoint(record, placed2, related);
|
|
4191
4665
|
}
|
|
4192
4666
|
}
|
|
4193
|
-
function showLine(record,
|
|
4194
|
-
const moved = related || geometryChanged(record.shown.geometry,
|
|
4195
|
-
record.shown =
|
|
4196
|
-
const { geometry } =
|
|
4667
|
+
function showLine(record, placed2, related) {
|
|
4668
|
+
const moved = related || geometryChanged(record.shown.geometry, placed2.geometry);
|
|
4669
|
+
record.shown = placed2;
|
|
4670
|
+
const { geometry } = placed2;
|
|
4197
4671
|
paint(record, seriesColors(colors.slot(record.series)), { visible: geometry.length >= VISIBLE2, open: { width: geometry.thickness } });
|
|
4198
|
-
setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y });
|
|
4672
|
+
setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y, visibility: placed2.data.samples.length === 0 ? "hidden" : void 0 });
|
|
4199
4673
|
const presence = record.presence.value;
|
|
4200
4674
|
setAttributes(record.group, { opacity: presence < 1 ? presence : void 0 });
|
|
4201
|
-
if (moved) runner.change(geometry,
|
|
4675
|
+
if (moved) runner.change(geometry, placed2.data);
|
|
4202
4676
|
}
|
|
4203
|
-
function showPoint(record,
|
|
4204
|
-
const moved = related || geometryChanged(record.shown.geometry,
|
|
4205
|
-
record.shown =
|
|
4677
|
+
function showPoint(record, placed2, related) {
|
|
4678
|
+
const moved = related || geometryChanged(record.shown.geometry, placed2.geometry);
|
|
4679
|
+
record.shown = placed2;
|
|
4206
4680
|
paint(record, seriesColors(colors.slot(record.series)), { visible: true });
|
|
4207
|
-
if (moved) runner.change(
|
|
4681
|
+
if (moved) runner.change(placed2.geometry, placed2.data);
|
|
4208
4682
|
}
|
|
4209
4683
|
function paint(record, markColors, part) {
|
|
4210
4684
|
const before = record.parts[0];
|
|
@@ -4217,11 +4691,21 @@ function lineChart(target, options, env2) {
|
|
|
4217
4691
|
record.handle.repaint();
|
|
4218
4692
|
if (before && recolored) surface.recolor(record.key);
|
|
4219
4693
|
}
|
|
4694
|
+
let anyAlone = false;
|
|
4695
|
+
function paintAlone(states) {
|
|
4696
|
+
const lone = loneValues(states, laidOut.series);
|
|
4697
|
+
if (lone.size === 0 && !anyAlone) return;
|
|
4698
|
+
for (const point of points.values()) point.group.classList.toggle("ec-alone", lone.has(point.key));
|
|
4699
|
+
anyAlone = lone.size > 0;
|
|
4700
|
+
}
|
|
4220
4701
|
function paintColumns(frame, states) {
|
|
4221
4702
|
const { x } = positions(frame);
|
|
4222
4703
|
const shown = states.filter(({ record }) => revealed(record));
|
|
4223
4704
|
const columns = placeColumns(frame, shown.map(({ state }) => x(state.x)));
|
|
4224
|
-
shown.forEach(({ record }, i) =>
|
|
4705
|
+
shown.forEach(({ record, state }, i) => {
|
|
4706
|
+
setAttributes(record.hit, { ...columns[i] });
|
|
4707
|
+
record.px = x(state.x);
|
|
4708
|
+
});
|
|
4225
4709
|
const visible = new Set(shown.map(({ record }) => record));
|
|
4226
4710
|
for (const record of [...rowOrder, ...leavingRows.values()]) {
|
|
4227
4711
|
const show3 = visible.has(record);
|
|
@@ -4240,10 +4724,9 @@ function lineChart(target, options, env2) {
|
|
|
4240
4724
|
}
|
|
4241
4725
|
function showHover(key) {
|
|
4242
4726
|
const record = rows2.get(key);
|
|
4243
|
-
|
|
4244
|
-
const
|
|
4245
|
-
|
|
4246
|
-
const x = first.shown.geometry.center.x;
|
|
4727
|
+
if (!record || !revealed(record)) return;
|
|
4728
|
+
const marks = livePoints(record);
|
|
4729
|
+
const x = marks[0]?.shown.geometry.center.x ?? record.px;
|
|
4247
4730
|
setAttributes(crosshair, { ...placeCrosshair(drawnFrame, x), visibility: void 0 });
|
|
4248
4731
|
const ys = marks.map((point) => {
|
|
4249
4732
|
const { transform } = point.handle.style;
|
|
@@ -4251,19 +4734,26 @@ function lineChart(target, options, env2) {
|
|
|
4251
4734
|
return (transform ? matrix.apply(transform, center) : center).y;
|
|
4252
4735
|
});
|
|
4253
4736
|
const { row } = record;
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
row,
|
|
4257
|
-
() => summaryContent(row.label, labelled2(row.values, current), format(current), { total: false })
|
|
4258
|
-
);
|
|
4737
|
+
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 };
|
|
4738
|
+
tooltip.showAt({ x, ...at }, row, () => summary(row, current));
|
|
4259
4739
|
}
|
|
4260
4740
|
function hideHover() {
|
|
4261
4741
|
crosshair.setAttribute("visibility", "hidden");
|
|
4262
4742
|
tooltip.hide();
|
|
4263
4743
|
}
|
|
4744
|
+
let ringLine;
|
|
4264
4745
|
function drawRing(key) {
|
|
4265
4746
|
const record = key === void 0 ? void 0 : rows2.get(key);
|
|
4266
|
-
const
|
|
4747
|
+
const live = record !== void 0 && revealed(record);
|
|
4748
|
+
const marks = live ? livePoints(record) : [];
|
|
4749
|
+
if (live && marks.length === 0) {
|
|
4750
|
+
ringLine ?? (ringLine = svgElement("line", { class: "ec-focus-ring", "stroke-width": RING3 }, ring));
|
|
4751
|
+
if (ring.childElementCount > 1 || ring.firstElementChild !== ringLine) ring.replaceChildren(ringLine);
|
|
4752
|
+
setAttributes(ringLine, placeCrosshair(drawnFrame, record.px));
|
|
4753
|
+
ring.removeAttribute("visibility");
|
|
4754
|
+
return;
|
|
4755
|
+
}
|
|
4756
|
+
ringLine?.remove();
|
|
4267
4757
|
while (ring.childElementCount > marks.length) ring.lastElementChild.remove();
|
|
4268
4758
|
marks.forEach((point, i) => {
|
|
4269
4759
|
let group = ring.children[i];
|
|
@@ -4304,6 +4794,17 @@ function lineChart(target, options, env2) {
|
|
|
4304
4794
|
return record !== void 0 && revealed(record);
|
|
4305
4795
|
},
|
|
4306
4796
|
order: () => rowOrder.filter(revealed).map((record) => record.key),
|
|
4797
|
+
// On a time axis a page is a calendar month in its zone: the first x a month or more on, or back,
|
|
4798
|
+
// or the last one that way. On numbers it's the keyboard's own.
|
|
4799
|
+
page(key, by) {
|
|
4800
|
+
const from = rows2.get(key);
|
|
4801
|
+
if (!laidOut.time || !from) return void 0;
|
|
4802
|
+
const stops = rowOrder.filter(revealed);
|
|
4803
|
+
const to = monthsOn(from.row.x, by, lineEncoding(current).timeZone);
|
|
4804
|
+
if (by > 0) return (stops.find((record) => record.row.x >= to) ?? stops[stops.length - 1])?.key;
|
|
4805
|
+
for (let i = stops.length - 1; i >= 0; i--) if (stops[i].row.x <= to) return stops[i].key;
|
|
4806
|
+
return stops[0]?.key;
|
|
4807
|
+
},
|
|
4307
4808
|
marks: (key) => {
|
|
4308
4809
|
const record = rows2.get(key);
|
|
4309
4810
|
return record ? livePoints(record).map((point) => point.key) : [];
|
|
@@ -4315,7 +4816,7 @@ function lineChart(target, options, env2) {
|
|
|
4315
4816
|
return record && onScreen(record);
|
|
4316
4817
|
},
|
|
4317
4818
|
ring: drawRing,
|
|
4318
|
-
tooltip: { show: showHover, hide: hideHover }
|
|
4819
|
+
tooltip: { show: showHover, hide: hideHover, element: () => tooltip.element() }
|
|
4319
4820
|
});
|
|
4320
4821
|
const syncLegend = () => legend.update(
|
|
4321
4822
|
laidOut.series.map((series) => ({ series, label: seriesLabel(current.seriesLabels, series) })),
|
|
@@ -4329,7 +4830,7 @@ function lineChart(target, options, env2) {
|
|
|
4329
4830
|
category: typeof opts.x === "string" ? opts.x : void 0,
|
|
4330
4831
|
series: next.series,
|
|
4331
4832
|
label: (series) => seriesLabel(opts.seriesLabels, series),
|
|
4332
|
-
rows: next.rows.map((row) => ({ key: row.key, category: row.label, datum: row.datum, index: row.index, values: row.values, total: total(row.values) })),
|
|
4833
|
+
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) })),
|
|
4333
4834
|
format: format(opts),
|
|
4334
4835
|
total: false
|
|
4335
4836
|
});
|
|
@@ -4359,32 +4860,34 @@ function lineChart(target, options, env2) {
|
|
|
4359
4860
|
}
|
|
4360
4861
|
const key = (record) => record.key;
|
|
4361
4862
|
try {
|
|
4362
|
-
const
|
|
4363
|
-
if (
|
|
4863
|
+
const said2 = option({ text: text2, changed: values.map(key), added: added.map(key), removed: removed.map(key) });
|
|
4864
|
+
if (said2 !== void 0 && said2 !== null) announcer.say(String(said2));
|
|
4364
4865
|
} catch (error) {
|
|
4365
4866
|
report(error);
|
|
4366
4867
|
}
|
|
4367
4868
|
}
|
|
4368
4869
|
function arrange(next) {
|
|
4369
4870
|
laidOut = next;
|
|
4370
|
-
const
|
|
4871
|
+
const placed2 = placedFor(next);
|
|
4371
4872
|
const diff = { entering: [], exiting: [], changed: [] };
|
|
4372
4873
|
const keys = new Set(next.rows.map((row) => row.key));
|
|
4373
4874
|
const series = next.rows.length > 0 ? next.series : [];
|
|
4374
4875
|
const changes = { changed: [], added: [], removed: [] };
|
|
4375
4876
|
const before = rowOrder;
|
|
4376
4877
|
const was = new Map(before.map((record) => [record, record.row]));
|
|
4878
|
+
const nextRows = new Map(next.rows.map((row) => [row.key, row]));
|
|
4377
4879
|
const exitingLines = lineOrder.filter((line) => !series.includes(line.series));
|
|
4378
4880
|
const exitingPoints = [];
|
|
4379
4881
|
for (const record of before) {
|
|
4380
4882
|
const goes = !keys.has(record.key);
|
|
4883
|
+
const missing = nextRows.get(record.key)?.missing;
|
|
4381
4884
|
if (goes) {
|
|
4382
4885
|
rows2.delete(record.key);
|
|
4383
4886
|
record.leaving = true;
|
|
4384
4887
|
leavingRows.set(record.key, record);
|
|
4385
4888
|
changes.removed.push(record);
|
|
4386
4889
|
}
|
|
4387
|
-
for (const point of livePoints(record)) if (goes || !series.includes(point.series)) exitingPoints.push(point);
|
|
4890
|
+
for (const point of livePoints(record)) if (goes || !series.includes(point.series) || missing?.has(point.series)) exitingPoints.push(point);
|
|
4388
4891
|
}
|
|
4389
4892
|
for (const line of exitingLines) lines.delete(line.series);
|
|
4390
4893
|
for (const point of exitingPoints) points.delete(point.key);
|
|
@@ -4403,7 +4906,7 @@ function lineChart(target, options, env2) {
|
|
|
4403
4906
|
leavingRows.delete(row.key);
|
|
4404
4907
|
record.leaving = false;
|
|
4405
4908
|
record.x.set(row.x);
|
|
4406
|
-
record.values.set(
|
|
4909
|
+
record.values.set(row.levels);
|
|
4407
4910
|
rows2.set(row.key, record);
|
|
4408
4911
|
changes.added.push(record);
|
|
4409
4912
|
rowsMoved = true;
|
|
@@ -4419,7 +4922,7 @@ function lineChart(target, options, env2) {
|
|
|
4419
4922
|
const previousLines = lineOrder;
|
|
4420
4923
|
lineOrder = series.map((name) => {
|
|
4421
4924
|
let line = lines.get(name);
|
|
4422
|
-
const target2 =
|
|
4925
|
+
const target2 = placed2.lines.get(name);
|
|
4423
4926
|
if (line) {
|
|
4424
4927
|
const values = [...stayed].some((record) => valueIn(was.get(record), name) !== valueIn(record.row, name));
|
|
4425
4928
|
if (rowsMoved || values) diff.changed.push({ record: line, from: line.shown.geometry });
|
|
@@ -4433,9 +4936,9 @@ function lineChart(target, options, env2) {
|
|
|
4433
4936
|
});
|
|
4434
4937
|
for (const record of rowOrder) {
|
|
4435
4938
|
const old = stayed.has(record) ? was.get(record) : void 0;
|
|
4436
|
-
const live = series.map((name) => {
|
|
4939
|
+
const live = series.filter((name) => !record.row.missing.has(name)).map((name) => {
|
|
4437
4940
|
const key = pointKey(name, record.key);
|
|
4438
|
-
const target2 =
|
|
4941
|
+
const target2 = placed2.points.get(key);
|
|
4439
4942
|
let point = points.get(key);
|
|
4440
4943
|
if (point) {
|
|
4441
4944
|
if (old && valueIn(old, name) !== valueIn(record.row, name)) diff.changed.push({ record: point, from: point.shown.geometry });
|
|
@@ -4449,7 +4952,7 @@ function lineChart(target, options, env2) {
|
|
|
4449
4952
|
return point;
|
|
4450
4953
|
});
|
|
4451
4954
|
const kept = new Set(live);
|
|
4452
|
-
record.points = [...live, ...record.points.filter((point) => !kept.has(point) &&
|
|
4955
|
+
record.points = [...live, ...record.points.filter((point) => !kept.has(point) && drawn2(point))];
|
|
4453
4956
|
}
|
|
4454
4957
|
for (const record of rowOrder) labelColumn(record);
|
|
4455
4958
|
orderElements(
|
|
@@ -4470,18 +4973,18 @@ function lineChart(target, options, env2) {
|
|
|
4470
4973
|
function retarget(next, jump) {
|
|
4471
4974
|
dirty = true;
|
|
4472
4975
|
const { frame } = next;
|
|
4473
|
-
for (const [ticks,
|
|
4976
|
+
for (const [ticks, placed2, lined] of [
|
|
4474
4977
|
[yTicks, next.yTicks, true],
|
|
4475
4978
|
[xTicks, next.xTicks, false]
|
|
4476
4979
|
]) {
|
|
4477
|
-
const wanted = new Set(
|
|
4980
|
+
const wanted = new Set(placed2.map((tick) => tick.value));
|
|
4478
4981
|
for (const value of wanted) if (!ticks.has(value)) addTick(ticks, value, 0, lined);
|
|
4479
4982
|
for (const tick of ticks.values()) tick.wanted = wanted.has(tick.value);
|
|
4480
4983
|
}
|
|
4481
4984
|
for (const tick of next.xTicks) xTicks.get(tick.value).text = tick.label.text;
|
|
4482
4985
|
const goingLines = leavingLines();
|
|
4483
4986
|
const folding = [...leavingRows.values()];
|
|
4484
|
-
const values = busy(scale, frame.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values,
|
|
4987
|
+
const values = busy(scale, frame.scale, sameFields) || [...yTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.values, record.row.levels, sameFields)) || lineOrder.some((line) => busy(line.presence, 1, same)) || goingLines.some((line) => busy(line.presence, 0, same));
|
|
4485
4988
|
const positions2 = busy(box, frame.box, sameFields) || [...xTicks.values()].some((tick) => busy(tick.opacity, tick.wanted ? 1 : 0, same)) || rowOrder.some((record) => busy(record.x, record.row.x, same) || record.anchor !== void 0 && busy(record.presence, 1, same)) || folding.some((record) => record.anchor !== void 0 && busy(record.presence, 0, same));
|
|
4486
4989
|
let first;
|
|
4487
4990
|
let second;
|
|
@@ -4502,7 +5005,7 @@ function lineChart(target, options, env2) {
|
|
|
4502
5005
|
for (const tick of yTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, first);
|
|
4503
5006
|
for (const tick of xTicks.values()) move(tick.opacity, tick.wanted ? 1 : 0, same, second);
|
|
4504
5007
|
for (const record of rowOrder) {
|
|
4505
|
-
move(record.values,
|
|
5008
|
+
move(record.values, record.row.levels, sameFields, first);
|
|
4506
5009
|
move(record.x, record.row.x, same, second);
|
|
4507
5010
|
move(record.presence, 1, same, record.anchor ? second : void 0);
|
|
4508
5011
|
}
|
|
@@ -4537,9 +5040,9 @@ function lineChart(target, options, env2) {
|
|
|
4537
5040
|
const next = layout(current);
|
|
4538
5041
|
const byKey = new Map(next.rows.map((row) => [row.key, row]));
|
|
4539
5042
|
for (const record of rowOrder) record.row = byKey.get(record.key) ?? record.row;
|
|
4540
|
-
const
|
|
4541
|
-
for (const line of lineOrder) line.target =
|
|
4542
|
-
for (const point of points.values()) point.target =
|
|
5043
|
+
const placed2 = placedFor(next);
|
|
5044
|
+
for (const line of lineOrder) line.target = placed2.lines.get(line.series) ?? line.target;
|
|
5045
|
+
for (const point of points.values()) point.target = placed2.points.get(point.key) ?? point.target;
|
|
4543
5046
|
void transitionTo(next, true);
|
|
4544
5047
|
}
|
|
4545
5048
|
const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
|
|
@@ -4554,28 +5057,28 @@ function lineChart(target, options, env2) {
|
|
|
4554
5057
|
syncLegend();
|
|
4555
5058
|
table.render(firstTable);
|
|
4556
5059
|
{
|
|
4557
|
-
const
|
|
5060
|
+
const placed2 = placedFor(laidOut);
|
|
4558
5061
|
for (const tick of laidOut.yTicks) addTick(yTicks, tick.value, 1, true);
|
|
4559
5062
|
for (const tick of laidOut.xTicks) addTick(xTicks, tick.value, 1, false, tick.label.text);
|
|
4560
5063
|
rowOrder = laidOut.rows.map((row) => {
|
|
4561
5064
|
const record = createRow(row, false);
|
|
4562
5065
|
rows2.set(row.key, record);
|
|
4563
|
-
record.points = laidOut.series.map((name) => {
|
|
4564
|
-
const point = createPoint(record,
|
|
5066
|
+
record.points = laidOut.series.filter((name) => !row.missing.has(name)).map((name) => {
|
|
5067
|
+
const point = createPoint(record, placed2.points.get(pointKey(name, row.key)));
|
|
4565
5068
|
points.set(point.key, point);
|
|
4566
5069
|
return point;
|
|
4567
5070
|
});
|
|
4568
5071
|
labelColumn(record);
|
|
4569
5072
|
return record;
|
|
4570
5073
|
});
|
|
4571
|
-
lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name,
|
|
5074
|
+
lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed2.lines.get(name), false)) : [];
|
|
4572
5075
|
for (const line of lineOrder) lines.set(line.series, line);
|
|
4573
5076
|
land();
|
|
4574
5077
|
}
|
|
4575
5078
|
const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
|
|
4576
5079
|
hover.sync();
|
|
4577
5080
|
runner.enter(liveMarks().map(input));
|
|
4578
|
-
return {
|
|
5081
|
+
return linkable(hover.link, {
|
|
4579
5082
|
element: svg,
|
|
4580
5083
|
async update(next) {
|
|
4581
5084
|
if (destroyed) return;
|
|
@@ -4602,7 +5105,7 @@ function lineChart(target, options, env2) {
|
|
|
4602
5105
|
transitions.supersede();
|
|
4603
5106
|
const swapping = swapped !== effects;
|
|
4604
5107
|
effects = swapped;
|
|
4605
|
-
const
|
|
5108
|
+
const leaves2 = playUpdate(
|
|
4606
5109
|
{
|
|
4607
5110
|
runner,
|
|
4608
5111
|
events,
|
|
@@ -4610,6 +5113,7 @@ function lineChart(target, options, env2) {
|
|
|
4610
5113
|
leaving,
|
|
4611
5114
|
input,
|
|
4612
5115
|
onScreen,
|
|
5116
|
+
data: "data" in next,
|
|
4613
5117
|
...swapping ? {
|
|
4614
5118
|
swap: (diff) => {
|
|
4615
5119
|
const entering = new Set(diff.entering);
|
|
@@ -4624,7 +5128,7 @@ function lineChart(target, options, env2) {
|
|
|
4624
5128
|
);
|
|
4625
5129
|
syncLegend();
|
|
4626
5130
|
const settled = transitionTo(nextLayout, motion2.mode === "off");
|
|
4627
|
-
await transitions.wait(settled,
|
|
5131
|
+
await transitions.wait(settled, leaves2);
|
|
4628
5132
|
},
|
|
4629
5133
|
reveal(x) {
|
|
4630
5134
|
if (destroyed) return;
|
|
@@ -4679,19 +5183,19 @@ function lineChart(target, options, env2) {
|
|
|
4679
5183
|
lineOrder = [];
|
|
4680
5184
|
svg.remove();
|
|
4681
5185
|
}
|
|
4682
|
-
};
|
|
5186
|
+
});
|
|
4683
5187
|
}
|
|
4684
5188
|
function restState(row) {
|
|
4685
|
-
return { key: row.key, datum: row.datum, x: row.x, values:
|
|
5189
|
+
return { key: row.key, datum: row.datum, x: row.x, values: row.levels, missing: row.missing };
|
|
4686
5190
|
}
|
|
4687
|
-
function
|
|
4688
|
-
return
|
|
5191
|
+
function present(values) {
|
|
5192
|
+
return values.flatMap((v) => v.value === void 0 ? [] : [{ series: v.series, value: v.value }]);
|
|
4689
5193
|
}
|
|
4690
5194
|
function valueIn(row, series) {
|
|
4691
5195
|
return row.values.find((v) => v.series === series)?.value;
|
|
4692
5196
|
}
|
|
4693
5197
|
function total(values) {
|
|
4694
|
-
return values.reduce((sum, v) => sum + v.value, 0);
|
|
5198
|
+
return values.reduce((sum, v) => sum + (v.value ?? 0), 0);
|
|
4695
5199
|
}
|
|
4696
5200
|
function nearest(order, i, among) {
|
|
4697
5201
|
for (let j = i - 1; j >= 0; j--) if (among.has(order[j])) return order[j];
|
|
@@ -4705,21 +5209,32 @@ function sameData(a, b) {
|
|
|
4705
5209
|
if (a.datum !== b.datum || a.samples.length !== b.samples.length) return false;
|
|
4706
5210
|
return a.samples.every((s, i) => {
|
|
4707
5211
|
const o = b.samples[i];
|
|
4708
|
-
return s.t === o.t && s.value === o.value && sameAt(s.at, o.at);
|
|
5212
|
+
return s.t === o.t && s.value === o.value && sameAt(s.at, o.at) && s.gapBefore === o.gapBefore;
|
|
4709
5213
|
});
|
|
4710
5214
|
}
|
|
4711
5215
|
function sameAt(a, b) {
|
|
4712
5216
|
return a === b || a instanceof Date && b instanceof Date && a.getTime() === b.getTime();
|
|
4713
5217
|
}
|
|
4714
5218
|
function labelled2(values, options) {
|
|
4715
|
-
return values.map((v) => ({ series: v.series, label: seriesLabel(options.seriesLabels, v.series), value: v.value }));
|
|
5219
|
+
return present(values).map((v) => ({ series: v.series, label: seriesLabel(options.seriesLabels, v.series), value: v.value }));
|
|
5220
|
+
}
|
|
5221
|
+
function said(values, options) {
|
|
5222
|
+
const formatted = format(options);
|
|
5223
|
+
return values.map((v) => {
|
|
5224
|
+
const label2 = seriesLabel(options.seriesLabels, v.series);
|
|
5225
|
+
return v.value === void 0 ? `${label2} missing` : `${formatted(v.value)} ${label2}`;
|
|
5226
|
+
});
|
|
5227
|
+
}
|
|
5228
|
+
function summary(row, options) {
|
|
5229
|
+
if (row.missing.size === 0) return summaryContent(row.label, labelled2(row.values, options), format(options), { total: false });
|
|
5230
|
+
return { title: row.label, lines: [said(row.values, options).join(" \xB7 ")] };
|
|
4716
5231
|
}
|
|
4717
5232
|
function namesFor2(options, layout) {
|
|
4718
5233
|
const formatted = format(options);
|
|
4719
5234
|
return new Map(
|
|
4720
5235
|
layout.rows.map((row) => {
|
|
4721
5236
|
const values = labelled2(row.values, options);
|
|
4722
|
-
const text2 = `${row.label}: ${
|
|
5237
|
+
const text2 = `${row.label}: ${said(row.values, options).join(", ")}`;
|
|
4723
5238
|
if (!options.markLabel) return [row.key, text2];
|
|
4724
5239
|
try {
|
|
4725
5240
|
const named = options.markLabel(row.datum, { key: row.key, category: row.label, values, total: total(row.values), format: formatted, text: text2 });
|
|
@@ -4758,20 +5273,20 @@ function baselines(boxes, option) {
|
|
|
4758
5273
|
}
|
|
4759
5274
|
return found;
|
|
4760
5275
|
}
|
|
4761
|
-
function describeRects(key,
|
|
4762
|
-
const box = union(
|
|
4763
|
-
const
|
|
4764
|
-
const order =
|
|
5276
|
+
function describeRects(key, parts2, baseline) {
|
|
5277
|
+
const box = union(parts2.map((part) => part.box));
|
|
5278
|
+
const span2 = spanFrom(box, baseline);
|
|
5279
|
+
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);
|
|
4765
5280
|
let reached = 0;
|
|
4766
5281
|
let gap = Infinity;
|
|
4767
5282
|
const segments = order.map(({ index, near, far }) => {
|
|
4768
5283
|
if (reached > 0 && far > near) gap = Math.min(gap, near - reached);
|
|
4769
5284
|
const size = Math.max(0, far - reached);
|
|
4770
5285
|
reached = Math.max(reached, far);
|
|
4771
|
-
return { series:
|
|
5286
|
+
return { series: parts2[index].series, size };
|
|
4772
5287
|
});
|
|
4773
|
-
const tip =
|
|
4774
|
-
const single =
|
|
5288
|
+
const tip = parts2[order[order.length - 1].index];
|
|
5289
|
+
const single = parts2.length === 1 ? parts2[0].series : void 0;
|
|
4775
5290
|
const geometry = describe.bar({
|
|
4776
5291
|
key,
|
|
4777
5292
|
...single === void 0 ? {} : { series: single },
|
|
@@ -4996,13 +5511,13 @@ function round3(value) {
|
|
|
4996
5511
|
}
|
|
4997
5512
|
|
|
4998
5513
|
// src/charts/adapter/host-style.ts
|
|
4999
|
-
function hostMarkHandle(
|
|
5514
|
+
function hostMarkHandle(parts2, edits, halos) {
|
|
5000
5515
|
let style = {};
|
|
5001
5516
|
let hot = false;
|
|
5002
5517
|
const halo = maskedHalo();
|
|
5003
5518
|
const repaint = () => {
|
|
5004
5519
|
const { transform, opacity, emphasis } = style;
|
|
5005
|
-
for (const part of
|
|
5520
|
+
for (const part of parts2()) {
|
|
5006
5521
|
const { element, colors } = part;
|
|
5007
5522
|
const moved = transform && part.parentInverse ? matrix.multiply(part.parentInverse, transform, part.parent, ownTransform(element)) : void 0;
|
|
5008
5523
|
edits.style(element, "transform", moved && cssMatrix(moved));
|
|
@@ -5017,7 +5532,7 @@ function hostMarkHandle(parts, edits, halos) {
|
|
|
5017
5532
|
paintHalo();
|
|
5018
5533
|
};
|
|
5019
5534
|
const paintHalo = () => {
|
|
5020
|
-
const visible =
|
|
5535
|
+
const visible = parts2().flatMap((part) => part.outline === void 0 ? [] : [{ ...part.outline, color: part.colors?.color }]);
|
|
5021
5536
|
halo.paint(halos(), visible, style.halo, style.transform);
|
|
5022
5537
|
};
|
|
5023
5538
|
return {
|
|
@@ -5195,7 +5710,6 @@ function watchHost(doc, clock, onChanges) {
|
|
|
5195
5710
|
|
|
5196
5711
|
// src/charts/adapter/expressive.ts
|
|
5197
5712
|
var SVG_NS2 = "http://www.w3.org/2000/svg";
|
|
5198
|
-
var ONE = { index: 0, count: 1 };
|
|
5199
5713
|
var WRAPPING_ROLES = /* @__PURE__ */ new Set(["img", "image", "graphics-symbol", "graphics-object"]);
|
|
5200
5714
|
function expressive(target, options, env2) {
|
|
5201
5715
|
checkOptions3(options);
|
|
@@ -5247,8 +5761,8 @@ function expressive(target, options, env2) {
|
|
|
5247
5761
|
if (typeof geometry !== "object" || geometry === null || geometry.key !== key) {
|
|
5248
5762
|
throw new TypeError(`expressive: geometry for "${key}" must be a MarkGeometry with the key "${key}". Build it with describe and the key passed in.`);
|
|
5249
5763
|
}
|
|
5250
|
-
const
|
|
5251
|
-
return { key, geometry, parts, index };
|
|
5764
|
+
const parts2 = pieces.map((p) => part(p, outlineOf(geometry, p.series, pieces.length), at));
|
|
5765
|
+
return { key, geometry, parts: parts2, index };
|
|
5252
5766
|
}
|
|
5253
5767
|
function rectPiece(key, piece, at) {
|
|
5254
5768
|
if (piece.element.localName !== "rect") {
|
|
@@ -5263,11 +5777,11 @@ function expressive(target, options, env2) {
|
|
|
5263
5777
|
function rectMark(key, pieces, edge, index, at) {
|
|
5264
5778
|
const { geometry, order: order2 } = describeRects(key, pieces.map((p) => p.rect), edge);
|
|
5265
5779
|
const segments = geometry.segments ?? [];
|
|
5266
|
-
const
|
|
5780
|
+
const parts2 = order2.map((j, n) => {
|
|
5267
5781
|
const segment = segments[n];
|
|
5268
5782
|
return part(pieces[j], segment && segment.length >= 0.5 ? { d: segment.outline.d } : void 0, at);
|
|
5269
5783
|
});
|
|
5270
|
-
return { key, geometry, parts, index, rect: { edge, box: union(pieces.map((p) => p.rect.box)) } };
|
|
5784
|
+
return { key, geometry, parts: parts2, index, rect: { edge, box: union(pieces.map((p) => p.rect.box)) } };
|
|
5271
5785
|
}
|
|
5272
5786
|
function part(piece, outline2, at) {
|
|
5273
5787
|
const parent = between(at.common, piece.element.parentElement ?? at.svg, at.svg, at.screen);
|
|
@@ -5275,19 +5789,19 @@ function expressive(target, options, env2) {
|
|
|
5275
5789
|
}
|
|
5276
5790
|
function withData(marks) {
|
|
5277
5791
|
return marks.map((mark) => {
|
|
5278
|
-
const { key, geometry, parts } = mark;
|
|
5279
|
-
const total2 = mark.rect ? totalOf(
|
|
5792
|
+
const { key, geometry, parts: parts2 } = mark;
|
|
5793
|
+
const total2 = mark.rect ? totalOf(parts2) : void 0;
|
|
5280
5794
|
const samplesOf = (datum, of, series) => {
|
|
5281
5795
|
if (options.samples) return checkSamples(options.samples(datum, of), series === void 0 ? `"${key}"` : `"${key}" (${series})`);
|
|
5282
5796
|
return total2 === void 0 ? [] : barSamples(geometry, of, total2);
|
|
5283
5797
|
};
|
|
5284
|
-
const
|
|
5285
|
-
const related = (series) =>
|
|
5798
|
+
const own2 = /* @__PURE__ */ new Map();
|
|
5799
|
+
const related = (series) => own2.get(series) ?? relatedOf(series, key);
|
|
5286
5800
|
for (const series of ownSeries(mark)) {
|
|
5287
|
-
const datum = (
|
|
5288
|
-
|
|
5801
|
+
const datum = (parts2.find((p) => p.series === series) ?? parts2[0]).datum;
|
|
5802
|
+
own2.set(series, { datum, samples: samplesOf(datum, geometry.segments?.find((s) => s.series === series) ?? geometry, series), related });
|
|
5289
5803
|
}
|
|
5290
|
-
return { ...mark, data: { datum:
|
|
5804
|
+
return { ...mark, data: { datum: parts2[0].datum, samples: samplesOf(parts2[0].datum, geometry), related } };
|
|
5291
5805
|
});
|
|
5292
5806
|
}
|
|
5293
5807
|
function checkNeeds3(marks) {
|
|
@@ -5322,10 +5836,10 @@ function expressive(target, options, env2) {
|
|
|
5322
5836
|
if (series === void 0 || series === null || series === "") throw new TypeError(`expressive: segment returned ${String(series)} for a part of "${key}".`);
|
|
5323
5837
|
return String(series);
|
|
5324
5838
|
}
|
|
5325
|
-
function labelOf(key,
|
|
5839
|
+
function labelOf(key, parts2) {
|
|
5326
5840
|
if (!options.markLabel) return void 0;
|
|
5327
5841
|
try {
|
|
5328
|
-
const text2 = String(options.markLabel(
|
|
5842
|
+
const text2 = String(options.markLabel(parts2[0].datum, { key, parts: parts2.map(({ series, datum }) => ({ series, datum })) }) ?? "");
|
|
5329
5843
|
return text2.trim() === "" ? void 0 : text2;
|
|
5330
5844
|
} catch (error) {
|
|
5331
5845
|
report(error);
|
|
@@ -5353,6 +5867,7 @@ function expressive(target, options, env2) {
|
|
|
5353
5867
|
let hovered;
|
|
5354
5868
|
let ringKey;
|
|
5355
5869
|
let interaction;
|
|
5870
|
+
let linked2;
|
|
5356
5871
|
let destroyed = false;
|
|
5357
5872
|
const make = (tag, attributes, parent) => {
|
|
5358
5873
|
const created = doc.createElementNS(SVG_NS2, tag);
|
|
@@ -5390,7 +5905,7 @@ function expressive(target, options, env2) {
|
|
|
5390
5905
|
if (reading.root && reading.root !== root) moveTo(reading.root);
|
|
5391
5906
|
ancestor = reading.ancestor ?? ancestor;
|
|
5392
5907
|
const keys = new Set(reading.marks.map((mark) => mark.key));
|
|
5393
|
-
const diff = { entering: [], exiting: [], changed: [], moved: [] };
|
|
5908
|
+
const diff = { entering: [], exiting: [], changed: [], moved: [], newRow: false };
|
|
5394
5909
|
const recolor = [];
|
|
5395
5910
|
for (const record of order) {
|
|
5396
5911
|
if (keys.has(record.key)) continue;
|
|
@@ -5405,8 +5920,10 @@ function expressive(target, options, env2) {
|
|
|
5405
5920
|
if (record) {
|
|
5406
5921
|
const from = record.mark;
|
|
5407
5922
|
const changed = options.value ? valuesChanged2(from.parts, mark.parts) : lengthsChanged(from.geometry, mark.geometry);
|
|
5923
|
+
const newRow = from.data.datum !== mark.data.datum;
|
|
5924
|
+
if (newRow) diff.newRow = true;
|
|
5408
5925
|
if (changed) diff.changed.push({ record, from: from.geometry });
|
|
5409
|
-
else if (geometryChanged2(from.geometry, mark.geometry) ||
|
|
5926
|
+
else if (newRow || geometryChanged2(from.geometry, mark.geometry) || samplesChanged(from.data.samples, mark.data.samples)) {
|
|
5410
5927
|
diff.moved.push(record);
|
|
5411
5928
|
}
|
|
5412
5929
|
if (from.parts[0]?.colors?.color !== mark.parts[0]?.colors?.color) recolor.push(mark.key);
|
|
@@ -5437,13 +5954,13 @@ function expressive(target, options, env2) {
|
|
|
5437
5954
|
}
|
|
5438
5955
|
function nameMark(record) {
|
|
5439
5956
|
if (!options.markLabel) return;
|
|
5440
|
-
const { label, parts } = record.mark;
|
|
5441
|
-
|
|
5442
|
-
const named =
|
|
5957
|
+
const { label: label2, parts: parts2 } = record.mark;
|
|
5958
|
+
parts2.forEach((part2, index) => {
|
|
5959
|
+
const named = label2 !== void 0 && index === 0;
|
|
5443
5960
|
edits.attribute(part2.element, "role", named ? "img" : null);
|
|
5444
|
-
edits.attribute(part2.element, "aria-label", named ?
|
|
5961
|
+
edits.attribute(part2.element, "aria-label", named ? label2 : null);
|
|
5445
5962
|
if (named) edits.remove(part2.element, "aria-hidden");
|
|
5446
|
-
else edits.attribute(part2.element, "aria-hidden",
|
|
5963
|
+
else edits.attribute(part2.element, "aria-hidden", label2 === void 0 ? null : "true");
|
|
5447
5964
|
});
|
|
5448
5965
|
}
|
|
5449
5966
|
function unwrapNames() {
|
|
@@ -5494,12 +6011,12 @@ function expressive(target, options, env2) {
|
|
|
5494
6011
|
},
|
|
5495
6012
|
hover(hoverTarget, from) {
|
|
5496
6013
|
const record = records.get(hoverTarget.key);
|
|
5497
|
-
if (!record || hovered
|
|
6014
|
+
if (!record || own(hovered) && hovered.keys[0] === hoverTarget.key) return;
|
|
5498
6015
|
endHover();
|
|
5499
|
-
startHover(record, from, hoverTarget.segment);
|
|
6016
|
+
startHover([record], from, hoverTarget.segment);
|
|
5500
6017
|
},
|
|
5501
6018
|
leave() {
|
|
5502
|
-
if (hovered?.source
|
|
6019
|
+
if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
|
|
5503
6020
|
}
|
|
5504
6021
|
});
|
|
5505
6022
|
}
|
|
@@ -5516,26 +6033,45 @@ function expressive(target, options, env2) {
|
|
|
5516
6033
|
}
|
|
5517
6034
|
return void 0;
|
|
5518
6035
|
}
|
|
5519
|
-
function startHover(
|
|
5520
|
-
|
|
6036
|
+
function startHover(marks, from, segment, effects2 = true) {
|
|
6037
|
+
const started = { keys: marks.map((record) => record.key), source: from, effects: effects2 };
|
|
6038
|
+
hovered = started;
|
|
5521
6039
|
applyDim();
|
|
5522
|
-
runner.hover(
|
|
5523
|
-
emit("hover", { ...input(record), batch:
|
|
6040
|
+
if (effects2) runner.hover(marks.map(input));
|
|
6041
|
+
marks.forEach((record, index) => emit("hover", { ...input(record), batch: { index, count: marks.length }, source: from, ...segment === void 0 ? {} : { segment } }));
|
|
6042
|
+
if (from !== "linked" && hovered === started) linked2?.hover(marks.map(input));
|
|
5524
6043
|
}
|
|
5525
6044
|
function endHover() {
|
|
5526
6045
|
const current = hovered;
|
|
5527
6046
|
if (!current) return;
|
|
5528
6047
|
hovered = void 0;
|
|
5529
|
-
const record = find(current.key);
|
|
5530
6048
|
applyDim();
|
|
5531
|
-
|
|
5532
|
-
if (
|
|
6049
|
+
leaveMarks(current.keys);
|
|
6050
|
+
if (own(current)) linked2?.leave();
|
|
6051
|
+
}
|
|
6052
|
+
function leaveMarks(keys) {
|
|
6053
|
+
const marks = keys.flatMap((key) => find(key) ?? []);
|
|
6054
|
+
runner.leave(keys);
|
|
6055
|
+
marks.forEach((record, index) => emit("leave", { ...input(record), batch: { index, count: marks.length } }));
|
|
6056
|
+
}
|
|
6057
|
+
function dropGone() {
|
|
6058
|
+
if (hovered === void 0) return;
|
|
6059
|
+
const keys = hovered.keys.filter((key) => records.has(key));
|
|
6060
|
+
if (keys.length === hovered.keys.length) return;
|
|
6061
|
+
if (keys.length === 0) {
|
|
6062
|
+
interaction?.clear();
|
|
6063
|
+
endHover();
|
|
6064
|
+
return;
|
|
6065
|
+
}
|
|
6066
|
+
const gone = hovered.keys.filter((key) => !records.has(key));
|
|
6067
|
+
hovered = { ...hovered, keys };
|
|
6068
|
+
leaveMarks(gone);
|
|
5533
6069
|
}
|
|
5534
6070
|
function applyDim() {
|
|
5535
6071
|
if (!dim) return;
|
|
5536
6072
|
const duration = `${motion2.duration(100, "feedback")}ms`;
|
|
5537
6073
|
for (const record of order) {
|
|
5538
|
-
const hot = hovered?.key ===
|
|
6074
|
+
const hot = hovered?.keys.includes(record.key) === true;
|
|
5539
6075
|
for (const part2 of record.mark.parts) {
|
|
5540
6076
|
edits.toggleClass(part2.element, "ec-attached", true);
|
|
5541
6077
|
edits.toggleClass(part2.element, "ec-dimmed", hovered !== void 0 && !hot);
|
|
@@ -5574,26 +6110,27 @@ function expressive(target, options, env2) {
|
|
|
5574
6110
|
const record = records.get(key);
|
|
5575
6111
|
if (!record) return;
|
|
5576
6112
|
if (!visible) {
|
|
5577
|
-
if (hovered?.source === "keyboard" && hovered.
|
|
6113
|
+
if (hovered?.source === "keyboard" && hovered.keys[0] !== key) endHover();
|
|
5578
6114
|
return;
|
|
5579
6115
|
}
|
|
5580
|
-
if (hovered
|
|
5581
|
-
hovered = {
|
|
6116
|
+
if (own(hovered) && hovered.keys[0] === key) {
|
|
6117
|
+
hovered = { ...hovered, source: "keyboard" };
|
|
5582
6118
|
return;
|
|
5583
6119
|
}
|
|
5584
6120
|
endHover();
|
|
5585
|
-
startHover(record, "keyboard");
|
|
6121
|
+
startHover([record], "keyboard");
|
|
5586
6122
|
},
|
|
5587
6123
|
blur() {
|
|
5588
6124
|
ringKey = void 0;
|
|
5589
6125
|
drawRing();
|
|
5590
6126
|
if (hovered?.source !== "keyboard") return;
|
|
5591
|
-
if (interaction?.current === hovered.
|
|
6127
|
+
if (interaction?.current === hovered.keys[0]) hovered = { ...hovered, source: "pointer" };
|
|
5592
6128
|
else endHover();
|
|
5593
6129
|
},
|
|
5594
6130
|
escape() {
|
|
5595
6131
|
if (!hovered) return false;
|
|
5596
|
-
|
|
6132
|
+
if (hovered.source === "linked" && linked2) linked2.dismiss();
|
|
6133
|
+
else endHover();
|
|
5597
6134
|
return true;
|
|
5598
6135
|
}
|
|
5599
6136
|
}) : void 0;
|
|
@@ -5634,7 +6171,7 @@ function expressive(target, options, env2) {
|
|
|
5634
6171
|
function reread(changed) {
|
|
5635
6172
|
const at = { svg: root, common: ancestor, screen: screenMatrices(), colors: (element) => owners.get(element)?.part.colors };
|
|
5636
6173
|
const rowOf = rowsNow();
|
|
5637
|
-
const piecesOf = ({ parts }) =>
|
|
6174
|
+
const piecesOf = ({ parts: parts2 }) => parts2.map((part2) => ({ element: part2.element, datum: rowOf(part2.element), series: part2.series, value: part2.value }));
|
|
5638
6175
|
if (options.geometry) {
|
|
5639
6176
|
const marks2 = changed.map(({ mark }) => ({ ...shapeMark(mark.key, piecesOf(mark), mark.index, at), label: mark.label }));
|
|
5640
6177
|
return { records: [...changed], marks: withData(marks2) };
|
|
@@ -5692,7 +6229,27 @@ function expressive(target, options, env2) {
|
|
|
5692
6229
|
runner.enter(apply(first).entering.map(input));
|
|
5693
6230
|
keyboard?.sync();
|
|
5694
6231
|
watchMarks();
|
|
5695
|
-
|
|
6232
|
+
const link2 = {
|
|
6233
|
+
targets: () => order.map((record) => ({ key: record.key, marks: [input(record)] })),
|
|
6234
|
+
hover(keys, effects2) {
|
|
6235
|
+
endHover();
|
|
6236
|
+
const marks = keys.flatMap((key) => records.get(key) ?? []);
|
|
6237
|
+
if (marks.length > 0) startHover(marks, "linked", void 0, effects2);
|
|
6238
|
+
},
|
|
6239
|
+
unlink() {
|
|
6240
|
+
if (hovered?.source === "linked") endHover();
|
|
6241
|
+
},
|
|
6242
|
+
leave() {
|
|
6243
|
+
interaction?.clear();
|
|
6244
|
+
endHover();
|
|
6245
|
+
},
|
|
6246
|
+
listen(listener) {
|
|
6247
|
+
if (destroyed) return false;
|
|
6248
|
+
linked2 = listener;
|
|
6249
|
+
return true;
|
|
6250
|
+
}
|
|
6251
|
+
};
|
|
6252
|
+
return linkable(link2, {
|
|
5696
6253
|
refresh(next) {
|
|
5697
6254
|
if (destroyed) return;
|
|
5698
6255
|
const reading = read(next ?? source);
|
|
@@ -5700,13 +6257,12 @@ function expressive(target, options, env2) {
|
|
|
5700
6257
|
runner.interrupt();
|
|
5701
6258
|
const diff = apply(reading);
|
|
5702
6259
|
watchMarks();
|
|
5703
|
-
|
|
5704
|
-
interaction?.clear();
|
|
5705
|
-
endHover();
|
|
5706
|
-
}
|
|
6260
|
+
dropGone();
|
|
5707
6261
|
const exited = runner.exit(diff.exiting.map(input));
|
|
5708
6262
|
emitEach("exit", diff.exiting);
|
|
5709
|
-
|
|
6263
|
+
if (diff.newRow || diff.changed.length > 0 || diff.entering.length > 0 || diff.exiting.length > 0) {
|
|
6264
|
+
runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
|
|
6265
|
+
}
|
|
5710
6266
|
diff.changed.forEach(({ record, from }, index) => emit("update", { ...input(record), from, batch: { index, count: diff.changed.length } }));
|
|
5711
6267
|
runner.enter(diff.entering.map(input));
|
|
5712
6268
|
emitEach("enter", diff.entering);
|
|
@@ -5738,6 +6294,8 @@ function expressive(target, options, env2) {
|
|
|
5738
6294
|
if (destroyed) return;
|
|
5739
6295
|
destroyed = true;
|
|
5740
6296
|
hovered = void 0;
|
|
6297
|
+
linked2?.gone();
|
|
6298
|
+
linked2 = void 0;
|
|
5741
6299
|
watching?.destroy();
|
|
5742
6300
|
runner.destroy();
|
|
5743
6301
|
unsubscribeMotion?.();
|
|
@@ -5751,7 +6309,7 @@ function expressive(target, options, env2) {
|
|
|
5751
6309
|
order = [];
|
|
5752
6310
|
owners = /* @__PURE__ */ new Map();
|
|
5753
6311
|
}
|
|
5754
|
-
};
|
|
6312
|
+
});
|
|
5755
6313
|
}
|
|
5756
6314
|
function checkOptions3(options) {
|
|
5757
6315
|
if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
|
|
@@ -5767,9 +6325,9 @@ function ownSeries(mark) {
|
|
|
5767
6325
|
const names = [...(mark.geometry.segments ?? []).map((s) => s.series), ...mark.parts.map((p) => p.series)];
|
|
5768
6326
|
return [...new Set(names.filter((name) => name !== void 0))];
|
|
5769
6327
|
}
|
|
5770
|
-
function totalOf(
|
|
6328
|
+
function totalOf(parts2) {
|
|
5771
6329
|
let total2 = 0;
|
|
5772
|
-
for (const { value } of
|
|
6330
|
+
for (const { value } of parts2) {
|
|
5773
6331
|
if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
|
|
5774
6332
|
total2 += value;
|
|
5775
6333
|
}
|
|
@@ -5793,14 +6351,17 @@ function checkSamples(samples, mark) {
|
|
|
5793
6351
|
if (!Array.isArray(samples)) throw new TypeError(`expressive: samples for ${mark} must return an array of { t, value }, got ${describeValue2(samples)}.`);
|
|
5794
6352
|
let last = 0;
|
|
5795
6353
|
return samples.map((sample, i) => {
|
|
5796
|
-
const { t, value, at } = typeof sample === "object" && sample !== null ? sample : {};
|
|
6354
|
+
const { t, value, at, gapBefore } = typeof sample === "object" && sample !== null ? sample : {};
|
|
5797
6355
|
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)}.`);
|
|
5798
6356
|
if (t < last) throw new RangeError(`expressive: samples for ${mark} must be in t order: samples[${i}].t is ${t}, after ${last}.`);
|
|
5799
6357
|
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
5800
6358
|
throw new RangeError(`expressive: samples for ${mark}: samples[${i}].value must be a finite number, got ${describeValue2(value)}.`);
|
|
5801
6359
|
}
|
|
6360
|
+
if (gapBefore !== void 0 && typeof gapBefore !== "boolean") {
|
|
6361
|
+
throw new RangeError(`expressive: samples for ${mark}: samples[${i}].gapBefore must be true or false, got ${describeValue2(gapBefore)}.`);
|
|
6362
|
+
}
|
|
5802
6363
|
last = t;
|
|
5803
|
-
return at === void 0 ? {
|
|
6364
|
+
return { t, value, ...at === void 0 ? {} : { at }, ...gapBefore ? { gapBefore } : {} };
|
|
5804
6365
|
});
|
|
5805
6366
|
}
|
|
5806
6367
|
function describeValue2(value) {
|
|
@@ -5821,9 +6382,9 @@ function ringOrder(marks, geometryOf) {
|
|
|
5821
6382
|
function distance2(a, b) {
|
|
5822
6383
|
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
5823
6384
|
}
|
|
5824
|
-
function outlineOf(geometry, series,
|
|
6385
|
+
function outlineOf(geometry, series, parts2) {
|
|
5825
6386
|
const segment = series === void 0 ? void 0 : geometry.segments?.find((s) => s.series === series);
|
|
5826
|
-
const shape = segment ?? (
|
|
6387
|
+
const shape = segment ?? (parts2 === 1 ? geometry : void 0);
|
|
5827
6388
|
if (!shape || segment && segment.length < 0.5) return void 0;
|
|
5828
6389
|
return shape.outline.closed ? { d: shape.outline.d } : { d: shape.outline.d, stroke: shape.thickness };
|
|
5829
6390
|
}
|
|
@@ -5862,7 +6423,7 @@ function samplesChanged(from, to) {
|
|
|
5862
6423
|
return from.length !== to.length || from.some((a, i) => a.t !== to[i].t || a.value !== to[i].value || !sameAt2(a.at, to[i].at));
|
|
5863
6424
|
}
|
|
5864
6425
|
function geometryChanged2(from, to) {
|
|
5865
|
-
if (from.outline.d !== to.outline.d || from.thickness !== to.thickness) return true;
|
|
6426
|
+
if (from.outline.d !== to.outline.d || from.thickness !== to.thickness || labelsMoved(from, to)) return true;
|
|
5866
6427
|
const a = from.segments ?? [];
|
|
5867
6428
|
const b = to.segments ?? [];
|
|
5868
6429
|
return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
|
|
@@ -5900,7 +6461,7 @@ function fromVegaView(view, options, env2) {
|
|
|
5900
6461
|
let observed;
|
|
5901
6462
|
let stopFrame;
|
|
5902
6463
|
let destroyed = false;
|
|
5903
|
-
const observer = typeof MutationObserver === "function" ? new MutationObserver((records) => records.some(
|
|
6464
|
+
const observer = typeof MutationObserver === "function" ? new MutationObserver((records) => records.some(drawn2) && schedule()) : void 0;
|
|
5904
6465
|
observe(current.root);
|
|
5905
6466
|
function itemOf(element) {
|
|
5906
6467
|
const item = current.items.get(element);
|
|
@@ -5963,12 +6524,12 @@ function fromVegaView(view, options, env2) {
|
|
|
5963
6524
|
const elements = [];
|
|
5964
6525
|
for (const i of visualOrder(boxes, edges)) {
|
|
5965
6526
|
const key = keys[i];
|
|
5966
|
-
const
|
|
5967
|
-
const { geometry, order } = describeRects(key,
|
|
6527
|
+
const parts2 = groups.get(key);
|
|
6528
|
+
const { geometry, order } = describeRects(key, parts2.map((p) => p.part), edges[i]);
|
|
5968
6529
|
read.geometry.set(key, geometry);
|
|
5969
|
-
elements.push(...order.map((j) =>
|
|
6530
|
+
elements.push(...order.map((j) => parts2[j].element));
|
|
5970
6531
|
if (options.sample) {
|
|
5971
|
-
const values = order.map((j) => valueOf(read.items.get(
|
|
6532
|
+
const values = order.map((j) => valueOf(read.items.get(parts2[j].element)).value);
|
|
5972
6533
|
const total2 = values.reduce((sum, v) => sum + v, 0);
|
|
5973
6534
|
read.samples.set(geometry, [{ t: 0, value: 0 }, { t: 1, value: total2 }]);
|
|
5974
6535
|
let reached = 0;
|
|
@@ -6000,7 +6561,7 @@ function fromVegaView(view, options, env2) {
|
|
|
6000
6561
|
const end = at === void 0 ? { t: 1, value } : { t: 1, value, at };
|
|
6001
6562
|
return type === "symbol" ? [{ ...end, t: 0 }] : geometry.length > 0 ? [{ t: 0, value: 0 }, end] : [{ ...end, t: 0 }];
|
|
6002
6563
|
}
|
|
6003
|
-
function
|
|
6564
|
+
function drawn2(record) {
|
|
6004
6565
|
const overlay = observed?.querySelector(":scope > .ec-overlay");
|
|
6005
6566
|
const ours = (node) => node === overlay || (overlay?.contains(node) ?? false);
|
|
6006
6567
|
if (ours(record.target)) return false;
|
|
@@ -6039,7 +6600,7 @@ function fromVegaView(view, options, env2) {
|
|
|
6039
6600
|
}
|
|
6040
6601
|
observe(next.root);
|
|
6041
6602
|
}
|
|
6042
|
-
return {
|
|
6603
|
+
return linkable(portOf(attachment), {
|
|
6043
6604
|
refresh,
|
|
6044
6605
|
on: attachment.on,
|
|
6045
6606
|
marks: attachment.marks,
|
|
@@ -6052,7 +6613,7 @@ function fromVegaView(view, options, env2) {
|
|
|
6052
6613
|
stopFrame = void 0;
|
|
6053
6614
|
attachment.destroy();
|
|
6054
6615
|
}
|
|
6055
|
-
};
|
|
6616
|
+
});
|
|
6056
6617
|
}
|
|
6057
6618
|
function checkView(view) {
|
|
6058
6619
|
if (typeof view !== "object" || view === null || typeof view.renderer !== "function" || typeof view.scenegraph !== "function" || typeof view.container !== "function") {
|
|
@@ -6371,12 +6932,12 @@ function chartSwitch(target, options, env2) {
|
|
|
6371
6932
|
if (!memory) return;
|
|
6372
6933
|
const now = focused();
|
|
6373
6934
|
if (now && now !== doc.body && now !== doc.documentElement && !wrapper.contains(now)) return;
|
|
6374
|
-
const
|
|
6935
|
+
const inside3 = () => to.chart.element.contains(focused());
|
|
6375
6936
|
if (memory.key !== void 0) to.chart.focus(memory.key);
|
|
6376
|
-
if (
|
|
6937
|
+
if (inside3()) return;
|
|
6377
6938
|
for (const mark of to.chart.marks()) {
|
|
6378
6939
|
to.chart.focus(mark.key);
|
|
6379
|
-
if (
|
|
6940
|
+
if (inside3()) return;
|
|
6380
6941
|
}
|
|
6381
6942
|
}
|
|
6382
6943
|
function say(to) {
|
|
@@ -6481,20 +7042,20 @@ function chartSwitch(target, options, env2) {
|
|
|
6481
7042
|
const drawings = [];
|
|
6482
7043
|
for (const mark of from) if (!toKeys.has(mark.key)) drawings.push(fadeMark(mark, fadeOut));
|
|
6483
7044
|
for (const mark of to) if (!fromByKey.has(mark.key)) drawings.push(fadeMark(mark, fadeIn));
|
|
6484
|
-
const id = (
|
|
6485
|
-
${
|
|
7045
|
+
const id = (label2) => `${label2.role}
|
|
7046
|
+
${label2.key}`;
|
|
6486
7047
|
const labelsA = a.chart.labels();
|
|
6487
7048
|
const labelsB = b.chart.labels();
|
|
6488
|
-
const byId = new Map(labelsA.map((
|
|
7049
|
+
const byId = new Map(labelsA.map((label2) => [id(label2), label2]));
|
|
6489
7050
|
const matched = /* @__PURE__ */ new Set();
|
|
6490
|
-
for (const
|
|
6491
|
-
const partner = byId.get(id(
|
|
7051
|
+
for (const label2 of labelsB) {
|
|
7052
|
+
const partner = byId.get(id(label2));
|
|
6492
7053
|
if (!partner) continue;
|
|
6493
|
-
matched.add(id(
|
|
6494
|
-
drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(
|
|
7054
|
+
matched.add(id(label2));
|
|
7055
|
+
drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(label2, toB)));
|
|
6495
7056
|
}
|
|
6496
|
-
for (const
|
|
6497
|
-
for (const
|
|
7057
|
+
for (const label2 of labelsA) if (!matched.has(id(label2))) drawings.push(fadeLabel(copyLabel(label2, toA), fadeOut));
|
|
7058
|
+
for (const label2 of labelsB) if (!byId.has(id(label2))) drawings.push(fadeLabel(copyLabel(label2, toB), fadeIn));
|
|
6498
7059
|
drawings.push((s) => {
|
|
6499
7060
|
setOpacity(a.container, 1 - clamp(s / OUT_BY));
|
|
6500
7061
|
setOpacity(b.container, clamp((s - HALF) / (1 - HALF)));
|
|
@@ -6519,12 +7080,12 @@ ${label.key}`;
|
|
|
6519
7080
|
svgLayer(group).path(mark.outline.d, mark.outline.closed ? { fill: "mark" } : { stroke: "mark", width: mark.thickness });
|
|
6520
7081
|
return (s) => setAttributes(group, { opacity: opacity(s) });
|
|
6521
7082
|
}
|
|
6522
|
-
function copyLabel(
|
|
6523
|
-
const text2 =
|
|
7083
|
+
function copyLabel(label2, m) {
|
|
7084
|
+
const text2 = label2.element.cloneNode(true);
|
|
6524
7085
|
for (const name of ["id", "opacity", "visibility", "aria-hidden"]) text2.removeAttribute(name);
|
|
6525
|
-
text2.textContent =
|
|
6526
|
-
const at = matrix.apply(m,
|
|
6527
|
-
setAttributes(text2, { x: at.x, y: at.y, "text-anchor":
|
|
7086
|
+
text2.textContent = label2.text;
|
|
7087
|
+
const at = matrix.apply(m, label2);
|
|
7088
|
+
setAttributes(text2, { x: at.x, y: at.y, "text-anchor": label2.anchor });
|
|
6528
7089
|
labelsLayer.appendChild(text2);
|
|
6529
7090
|
return { text: text2, at };
|
|
6530
7091
|
}
|
|
@@ -6615,8 +7176,8 @@ function moveLabel(a, b) {
|
|
|
6615
7176
|
setAttributes(b.text, { x, y, visibility: second ? void 0 : "hidden" });
|
|
6616
7177
|
};
|
|
6617
7178
|
}
|
|
6618
|
-
function fadeLabel(
|
|
6619
|
-
return (s) => setAttributes(
|
|
7179
|
+
function fadeLabel(label2, opacity) {
|
|
7180
|
+
return (s) => setAttributes(label2.text, { opacity: opacity(s) });
|
|
6620
7181
|
}
|
|
6621
7182
|
var fadeOut = (s) => 1 - clamp(s / HALF);
|
|
6622
7183
|
var fadeIn = (s) => clamp((s - HALF) / (1 - HALF));
|
|
@@ -6710,10 +7271,10 @@ function motionSwitch(target, motion2, options = {}) {
|
|
|
6710
7271
|
root.setAttribute("role", "group");
|
|
6711
7272
|
root.setAttribute("aria-labelledby", `${id}-label`);
|
|
6712
7273
|
root.setAttribute("aria-describedby", `${id}-hint`);
|
|
6713
|
-
const
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
7274
|
+
const label2 = root.appendChild(doc.createElement("span"));
|
|
7275
|
+
label2.className = "ec-motion-label";
|
|
7276
|
+
label2.id = `${id}-label`;
|
|
7277
|
+
label2.textContent = options.label ?? "Motion";
|
|
6717
7278
|
const modes = root.appendChild(doc.createElement("span"));
|
|
6718
7279
|
modes.className = "ec-motion-modes";
|
|
6719
7280
|
const buttons = MODES2.map((mode) => {
|
|
@@ -6781,8 +7342,8 @@ function checkMotion(motion2) {
|
|
|
6781
7342
|
}
|
|
6782
7343
|
}
|
|
6783
7344
|
function checkOptions5(options) {
|
|
6784
|
-
const { label, labels, hints, persist } = options;
|
|
6785
|
-
if (
|
|
7345
|
+
const { label: label2, labels, hints, persist } = options;
|
|
7346
|
+
if (label2 !== void 0 && typeof label2 !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label2}.`);
|
|
6786
7347
|
for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
|
|
6787
7348
|
if (texts === void 0) continue;
|
|
6788
7349
|
for (const [key, text2] of Object.entries(texts)) {
|
|
@@ -6879,6 +7440,7 @@ var gaits = { roll, step, slide };
|
|
|
6879
7440
|
// src/effects/travel.ts
|
|
6880
7441
|
var SPEED = 360;
|
|
6881
7442
|
var SHORTEST = 260;
|
|
7443
|
+
var LONGEST2 = 4e3;
|
|
6882
7444
|
var MIN_WALK = 0.5;
|
|
6883
7445
|
var FIT = 0.85;
|
|
6884
7446
|
var MIN_SMOOTHING = 2;
|
|
@@ -6891,7 +7453,7 @@ function travel(icon, options = {}) {
|
|
|
6891
7453
|
const resolved = typeof icon === "string" ? ctx.icons.get(icon) : icon;
|
|
6892
7454
|
if (!resolved) throw new RangeError(`travel: unknown icon "${String(icon)}". Register it with registerIcon(icon), or pass the icon itself.`);
|
|
6893
7455
|
const walk = pick(mark, options.along);
|
|
6894
|
-
if (!walk || !(walk
|
|
7456
|
+
if (!walk || !(drawn(walk) >= MIN_WALK)) return void 0;
|
|
6895
7457
|
const scale = options.size === void 0 ? 1 : options.size === "fit" ? FIT * walk.thickness / resolved.box.height : options.size / resolved.size;
|
|
6896
7458
|
if (!(scale > 0)) return void 0;
|
|
6897
7459
|
return trip(walk, resolved, scale, options);
|
|
@@ -6899,18 +7461,18 @@ function travel(icon, options = {}) {
|
|
|
6899
7461
|
function rider(mark, ctx) {
|
|
6900
7462
|
let current = plan(mark, ctx);
|
|
6901
7463
|
let handle;
|
|
6902
|
-
let
|
|
7464
|
+
let drawn2;
|
|
6903
7465
|
let progress = 0;
|
|
6904
7466
|
const draw = () => {
|
|
6905
7467
|
if (!current) {
|
|
6906
7468
|
handle?.remove();
|
|
6907
|
-
handle =
|
|
7469
|
+
handle = drawn2 = void 0;
|
|
6908
7470
|
return;
|
|
6909
7471
|
}
|
|
6910
|
-
if (!handle ||
|
|
7472
|
+
if (!handle || drawn2?.icon !== current.icon || drawn2.size !== current.size) {
|
|
6911
7473
|
handle?.remove();
|
|
6912
7474
|
handle = ctx.layer.icon(current.icon, { size: current.size });
|
|
6913
|
-
|
|
7475
|
+
drawn2 = { icon: current.icon, size: current.size };
|
|
6914
7476
|
}
|
|
6915
7477
|
handle.place(current.transform(progress));
|
|
6916
7478
|
};
|
|
@@ -6957,7 +7519,12 @@ function trip(walk, icon, scale, options) {
|
|
|
6957
7519
|
const length = walk.length;
|
|
6958
7520
|
const behind = icon.footprint[0] * scale;
|
|
6959
7521
|
const ahead = icon.footprint[1] * scale;
|
|
6960
|
-
|
|
7522
|
+
let span2 = 0;
|
|
7523
|
+
const legs = parts(walk).map(([from, to]) => {
|
|
7524
|
+
const leg = { from, to, span: Math.max(0, to - from - behind - ahead), before: span2 };
|
|
7525
|
+
span2 += leg.span;
|
|
7526
|
+
return leg;
|
|
7527
|
+
});
|
|
6961
7528
|
const smoothing = Math.max(MIN_SMOOTHING, (behind + ahead) / 2);
|
|
6962
7529
|
const radius = icon.radius ?? icon.box.height / 2;
|
|
6963
7530
|
const { anchor } = icon;
|
|
@@ -6967,14 +7534,18 @@ function trip(walk, icon, scale, options) {
|
|
|
6967
7534
|
return {
|
|
6968
7535
|
icon,
|
|
6969
7536
|
size: icon.size * scale,
|
|
6970
|
-
span,
|
|
6971
|
-
duration: Math.max(SHORTEST,
|
|
7537
|
+
span: span2,
|
|
7538
|
+
duration: Math.min(LONGEST2, Math.max(SHORTEST, span2 / SPEED * 1e3) * (gait.pace ?? 1)),
|
|
6972
7539
|
gait,
|
|
6973
7540
|
transform(progress) {
|
|
6974
|
-
const
|
|
6975
|
-
|
|
7541
|
+
const travelled = progress * span2;
|
|
7542
|
+
let index = legs.length - 1;
|
|
7543
|
+
while (index > 0 && legs[index].before > travelled) index--;
|
|
7544
|
+
const leg = legs[index];
|
|
7545
|
+
const distance3 = leg.from + behind + Math.min(leg.span, travelled - leg.before);
|
|
7546
|
+
const pose = gait({ distance: travelled / scale, length: span2 / scale, progress, radius });
|
|
6976
7547
|
const at = pointAt(walk, distance3);
|
|
6977
|
-
const direction = heading(walk, Math.min(distance3, length), smoothing);
|
|
7548
|
+
const direction = heading(walk, Math.min(distance3, length), smoothing, leg);
|
|
6978
7549
|
const mirror = orient === "auto" && icon.upright === true && Math.cos(direction) < -1e-9;
|
|
6979
7550
|
const turn2 = orient === "level" ? 0 : mirror ? normalizeAngle(direction - Math.PI) : direction;
|
|
6980
7551
|
return matrix.multiply(
|
|
@@ -6992,16 +7563,31 @@ function pick(mark, along) {
|
|
|
6992
7563
|
if (mark.segments) return mark.segments.find((segment) => segment.series === along);
|
|
6993
7564
|
return mark.series === along ? mark : void 0;
|
|
6994
7565
|
}
|
|
7566
|
+
function parts(walk) {
|
|
7567
|
+
const { length } = walk;
|
|
7568
|
+
const found = [];
|
|
7569
|
+
let at = 0;
|
|
7570
|
+
for (const [from, to] of walk.gaps ?? []) {
|
|
7571
|
+
if (!(to > from) || !(to > at)) continue;
|
|
7572
|
+
if (from > at) found.push([at * length, Math.min(1, from) * length]);
|
|
7573
|
+
at = Math.min(1, to);
|
|
7574
|
+
}
|
|
7575
|
+
found.push([at * length, length]);
|
|
7576
|
+
return found;
|
|
7577
|
+
}
|
|
7578
|
+
function drawn(walk) {
|
|
7579
|
+
return parts(walk).reduce((sum, [from, to]) => sum + (to - from), 0);
|
|
7580
|
+
}
|
|
6995
7581
|
function pointAt(walk, distance3) {
|
|
6996
7582
|
const { length } = walk;
|
|
6997
7583
|
return distance3 <= length ? walk.path(distance3 / length) : offset(walk.end, walk.angle(1), distance3 - length);
|
|
6998
7584
|
}
|
|
6999
|
-
function heading(walk, distance3, window) {
|
|
7585
|
+
function heading(walk, distance3, window, leg) {
|
|
7000
7586
|
const { length } = walk;
|
|
7001
|
-
const
|
|
7002
|
-
if (
|
|
7003
|
-
const a = walk.path((distance3 -
|
|
7004
|
-
const b = walk.path((distance3 +
|
|
7587
|
+
const reach2 = Math.min(window, distance3 - leg.from, leg.to - distance3);
|
|
7588
|
+
if (reach2 > 1e-6) {
|
|
7589
|
+
const a = walk.path((distance3 - reach2) / length);
|
|
7590
|
+
const b = walk.path((distance3 + reach2) / length);
|
|
7005
7591
|
if (Math.hypot(b.x - a.x, b.y - a.y) > 1e-9) return Math.atan2(b.y - a.y, b.x - a.x);
|
|
7006
7592
|
}
|
|
7007
7593
|
return walk.angle(distance3 / length);
|
|
@@ -7123,10 +7709,10 @@ function wiggle(options = {}) {
|
|
|
7123
7709
|
}
|
|
7124
7710
|
function limit(mark, swing) {
|
|
7125
7711
|
const { pivot } = mark;
|
|
7126
|
-
let
|
|
7127
|
-
for (const point of mark.outline.sample(SAMPLES))
|
|
7128
|
-
if (!(
|
|
7129
|
-
return Math.min(MAX_ANGLE, 2 * Math.asin(Math.min(1, swing / (2 *
|
|
7712
|
+
let reach2 = 0;
|
|
7713
|
+
for (const point of mark.outline.sample(SAMPLES)) reach2 = Math.max(reach2, Math.hypot(point.x - pivot.x, point.y - pivot.y));
|
|
7714
|
+
if (!(reach2 >= MIN_REACH)) return 0;
|
|
7715
|
+
return Math.min(MAX_ANGLE, 2 * Math.asin(Math.min(1, swing / (2 * reach2))));
|
|
7130
7716
|
}
|
|
7131
7717
|
function rock(t) {
|
|
7132
7718
|
if (!(t > 0) || t >= 1) return 0;
|
|
@@ -7190,12 +7776,238 @@ function checkOptions10(options) {
|
|
|
7190
7776
|
}
|
|
7191
7777
|
}
|
|
7192
7778
|
|
|
7193
|
-
// src/effects/
|
|
7779
|
+
// src/effects/trace.ts
|
|
7780
|
+
var DURATION5 = 500;
|
|
7781
|
+
var WIDTH3 = 3;
|
|
7782
|
+
var OPACITY3 = 0.5;
|
|
7194
7783
|
var MIN_WALK2 = 0.5;
|
|
7784
|
+
function trace(options = {}) {
|
|
7785
|
+
checkOptions11(options);
|
|
7786
|
+
const duration = options.duration ?? DURATION5;
|
|
7787
|
+
const paint = { stroke: options.color ?? "mark", width: options.width ?? WIDTH3, opacity: options.opacity ?? OPACITY3, linecap: "round" };
|
|
7788
|
+
const stroke2 = (mark, ctx) => {
|
|
7789
|
+
let current = mark;
|
|
7790
|
+
let progress = 0;
|
|
7791
|
+
let path;
|
|
7792
|
+
const draw = () => {
|
|
7793
|
+
if (!(current.length >= MIN_WALK2)) {
|
|
7794
|
+
path?.remove();
|
|
7795
|
+
path = void 0;
|
|
7796
|
+
return;
|
|
7797
|
+
}
|
|
7798
|
+
const d = current.slice(0, progress);
|
|
7799
|
+
if (path) path.update(d);
|
|
7800
|
+
else path = ctx.layer.path(d, paint);
|
|
7801
|
+
};
|
|
7802
|
+
ctx.onChange((next) => {
|
|
7803
|
+
current = next;
|
|
7804
|
+
draw();
|
|
7805
|
+
});
|
|
7806
|
+
draw();
|
|
7807
|
+
return (p) => {
|
|
7808
|
+
progress = p;
|
|
7809
|
+
draw();
|
|
7810
|
+
};
|
|
7811
|
+
};
|
|
7812
|
+
return {
|
|
7813
|
+
kind: "geometry",
|
|
7814
|
+
async run(mark, ctx) {
|
|
7815
|
+
if (ctx.signal.aborted) return;
|
|
7816
|
+
const show3 = stroke2(mark, ctx);
|
|
7817
|
+
if (!(mark.length >= MIN_WALK2)) {
|
|
7818
|
+
show3(1);
|
|
7819
|
+
return;
|
|
7820
|
+
}
|
|
7821
|
+
await ctx.tween({ duration, timing: "effect", ease: easeInOutCubic, update: show3 }).finished;
|
|
7822
|
+
},
|
|
7823
|
+
end(mark, ctx) {
|
|
7824
|
+
stroke2(mark, ctx)(1);
|
|
7825
|
+
},
|
|
7826
|
+
clear() {
|
|
7827
|
+
}
|
|
7828
|
+
};
|
|
7829
|
+
}
|
|
7830
|
+
function checkOptions11(options) {
|
|
7831
|
+
const { color, width, opacity, duration } = options;
|
|
7832
|
+
if (color !== void 0 && (typeof color !== "string" || color === "")) {
|
|
7833
|
+
throw new RangeError(`trace: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
7834
|
+
}
|
|
7835
|
+
if (width !== void 0 && !(typeof width === "number" && width >= 0 && Number.isFinite(width))) {
|
|
7836
|
+
throw new RangeError(`trace: width must be 0 px or more, got ${String(width)}.`);
|
|
7837
|
+
}
|
|
7838
|
+
if (opacity !== void 0 && !(typeof opacity === "number" && opacity >= 0 && opacity <= 1)) {
|
|
7839
|
+
throw new RangeError(`trace: opacity must be from 0 to 1, got ${String(opacity)}.`);
|
|
7840
|
+
}
|
|
7841
|
+
if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) {
|
|
7842
|
+
throw new RangeError(`trace: duration must be 0 ms or more, got ${String(duration)}.`);
|
|
7843
|
+
}
|
|
7844
|
+
}
|
|
7845
|
+
|
|
7846
|
+
// src/effects/caption.ts
|
|
7847
|
+
var PAST_END = 10;
|
|
7848
|
+
var PAST_LABEL = 6;
|
|
7849
|
+
var RISE = 8;
|
|
7850
|
+
var TEXT = 12.5;
|
|
7851
|
+
var CENTRE4 = 0.36;
|
|
7852
|
+
var HANG = 0.8;
|
|
7853
|
+
function captionPlace(mark) {
|
|
7854
|
+
const boxes = mark.labelBounds ?? [];
|
|
7855
|
+
const heading2 = mark.angle(1);
|
|
7856
|
+
const along = farthest(mark.end, heading2, boxes);
|
|
7857
|
+
if (along === void 0 && boxes.length > 0) {
|
|
7858
|
+
const up = mark.angle(0.5) - Math.PI / 2;
|
|
7859
|
+
const out = farthest(mark.center, up, boxes);
|
|
7860
|
+
if (out !== void 0) return placed(mark.center, up, out);
|
|
7861
|
+
}
|
|
7862
|
+
return placed(mark.end, heading2, Math.max(PAST_END, along ?? -Infinity));
|
|
7863
|
+
}
|
|
7864
|
+
function placed(from, toward, distance3) {
|
|
7865
|
+
const cos = Math.cos(toward);
|
|
7866
|
+
const sin = Math.sin(toward);
|
|
7867
|
+
const point = offset(from, toward, distance3);
|
|
7868
|
+
const drop = TEXT * (sin < 0 ? CENTRE4 * (1 + sin) : CENTRE4 + (HANG - CENTRE4) * sin);
|
|
7869
|
+
const anchor = Math.abs(cos) <= Math.SQRT1_2 + 1e-9 ? "middle" : cos > 0 ? "start" : "end";
|
|
7870
|
+
return { at: { x: point.x, y: point.y + drop }, anchor, toward };
|
|
7871
|
+
}
|
|
7872
|
+
function farthest(from, toward, boxes) {
|
|
7873
|
+
const cos = Math.cos(toward);
|
|
7874
|
+
const sin = Math.sin(toward);
|
|
7875
|
+
let exit;
|
|
7876
|
+
for (const { x, y, width, height } of boxes) {
|
|
7877
|
+
const grown = { x: x - PAST_LABEL, y: y - PAST_LABEL, width: width + 2 * PAST_LABEL, height: height + 2 * PAST_LABEL };
|
|
7878
|
+
const leaving = leaves(from, cos, sin, grown);
|
|
7879
|
+
if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
|
|
7880
|
+
}
|
|
7881
|
+
return exit;
|
|
7882
|
+
}
|
|
7883
|
+
function leaves(from, cos, sin, box) {
|
|
7884
|
+
let near = 0;
|
|
7885
|
+
let far = Infinity;
|
|
7886
|
+
for (const [origin, step2, lo, hi] of [
|
|
7887
|
+
[from.x, cos, box.x, box.x + box.width],
|
|
7888
|
+
[from.y, sin, box.y, box.y + box.height]
|
|
7889
|
+
]) {
|
|
7890
|
+
if (Math.abs(step2) < 1e-12) {
|
|
7891
|
+
if (origin < lo || origin > hi) return void 0;
|
|
7892
|
+
continue;
|
|
7893
|
+
}
|
|
7894
|
+
const a = (lo - origin) / step2;
|
|
7895
|
+
const b = (hi - origin) / step2;
|
|
7896
|
+
near = Math.max(near, Math.min(a, b));
|
|
7897
|
+
far = Math.min(far, Math.max(a, b));
|
|
7898
|
+
}
|
|
7899
|
+
return far >= near ? far : void 0;
|
|
7900
|
+
}
|
|
7901
|
+
function caption(mark, data, ctx, color, words) {
|
|
7902
|
+
let current = mark;
|
|
7903
|
+
let content = words(mark, data) ?? "";
|
|
7904
|
+
let latest = data;
|
|
7905
|
+
let progress = 0;
|
|
7906
|
+
let handle;
|
|
7907
|
+
const draw = () => {
|
|
7908
|
+
if (content === "") {
|
|
7909
|
+
handle?.remove();
|
|
7910
|
+
handle = void 0;
|
|
7911
|
+
return;
|
|
7912
|
+
}
|
|
7913
|
+
const { at, anchor, toward } = captionPlace(current);
|
|
7914
|
+
const style = { at: offset(at, toward - Math.PI / 2, -RISE * (1 - progress)), anchor, color, opacity: progress };
|
|
7915
|
+
if (handle) handle.update(style, content);
|
|
7916
|
+
else handle = ctx.layer.text(content, style);
|
|
7917
|
+
};
|
|
7918
|
+
ctx.onChange((next, nextData) => {
|
|
7919
|
+
current = next;
|
|
7920
|
+
latest = nextData ?? latest;
|
|
7921
|
+
content = words(current, latest) ?? "";
|
|
7922
|
+
draw();
|
|
7923
|
+
});
|
|
7924
|
+
draw();
|
|
7925
|
+
return (p) => {
|
|
7926
|
+
progress = p;
|
|
7927
|
+
draw();
|
|
7928
|
+
};
|
|
7929
|
+
}
|
|
7930
|
+
|
|
7931
|
+
// src/effects/delta.ts
|
|
7932
|
+
var DURATION6 = 400;
|
|
7195
7933
|
var TIE = 1e-9;
|
|
7934
|
+
var lastSample = (data) => {
|
|
7935
|
+
const { samples } = data;
|
|
7936
|
+
return samples[samples.length - 1]?.value ?? Number.NaN;
|
|
7937
|
+
};
|
|
7938
|
+
var wording;
|
|
7939
|
+
var signed = (change) => {
|
|
7940
|
+
wording ?? (wording = new Intl.NumberFormat(void 0, { signDisplay: "always", maximumFractionDigits: 2 }));
|
|
7941
|
+
return wording.format(change);
|
|
7942
|
+
};
|
|
7943
|
+
function delta(options = {}) {
|
|
7944
|
+
checkOptions12(options);
|
|
7945
|
+
const value = options.value ?? lastSample;
|
|
7946
|
+
const format2 = options.format ?? signed;
|
|
7947
|
+
const color = options.color ?? "text";
|
|
7948
|
+
const words = (data) => {
|
|
7949
|
+
if (!data.previous) return void 0;
|
|
7950
|
+
const now = value(data);
|
|
7951
|
+
const before = value(data.previous);
|
|
7952
|
+
const change = now - before;
|
|
7953
|
+
if (!Number.isFinite(change) || Math.abs(change) <= TIE * Math.max(Math.abs(now), Math.abs(before))) return void 0;
|
|
7954
|
+
return format2(change);
|
|
7955
|
+
};
|
|
7956
|
+
return {
|
|
7957
|
+
kind: "data",
|
|
7958
|
+
run: async (mark, data, ctx) => {
|
|
7959
|
+
if (ctx.signal.aborted) return;
|
|
7960
|
+
const text2 = words(data);
|
|
7961
|
+
if (text2 === void 0 || text2 === "") return;
|
|
7962
|
+
const show3 = caption(mark, data, ctx, color, () => text2);
|
|
7963
|
+
await ctx.tween({ duration: DURATION6, timing: "effect", update: show3 }).finished;
|
|
7964
|
+
},
|
|
7965
|
+
end: (mark, data, ctx) => {
|
|
7966
|
+
const text2 = words(data);
|
|
7967
|
+
if (text2 !== void 0 && text2 !== "") caption(mark, data, ctx, color, () => text2)(1);
|
|
7968
|
+
},
|
|
7969
|
+
clear() {
|
|
7970
|
+
}
|
|
7971
|
+
};
|
|
7972
|
+
}
|
|
7973
|
+
function checkOptions12(options) {
|
|
7974
|
+
const { value, format: format2, color } = options;
|
|
7975
|
+
if (value !== void 0 && typeof value !== "function") throw new TypeError(`delta: value must be a function that reads the mark's value from its data, got ${typeof value}.`);
|
|
7976
|
+
if (format2 !== void 0 && typeof format2 !== "function") throw new TypeError(`delta: format must be a function that words the change, got ${typeof format2}.`);
|
|
7977
|
+
if (color !== void 0 && (typeof color !== "string" || color === "")) {
|
|
7978
|
+
throw new RangeError(`delta: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
7979
|
+
}
|
|
7980
|
+
}
|
|
7981
|
+
|
|
7982
|
+
// src/effects/label.ts
|
|
7983
|
+
var DURATION7 = 400;
|
|
7984
|
+
function label(text2, options = {}) {
|
|
7985
|
+
if (typeof text2 !== "function") throw new TypeError(`label needs a function that returns the text from the mark's data, got ${typeof text2}.`);
|
|
7986
|
+
const { color = "text" } = options;
|
|
7987
|
+
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)}.`);
|
|
7988
|
+
const words = (mark, data) => {
|
|
7989
|
+
const said2 = text2(data, mark);
|
|
7990
|
+
return said2 === void 0 || said2 === null ? void 0 : String(said2);
|
|
7991
|
+
};
|
|
7992
|
+
return {
|
|
7993
|
+
kind: "data",
|
|
7994
|
+
run: async (mark, data, ctx) => {
|
|
7995
|
+
if (ctx.signal.aborted) return;
|
|
7996
|
+
const show3 = caption(mark, data, ctx, color, words);
|
|
7997
|
+
await ctx.tween({ duration: DURATION7, timing: "effect", update: show3 }).finished;
|
|
7998
|
+
},
|
|
7999
|
+
end: (mark, data, ctx) => caption(mark, data, ctx, color, words)(1),
|
|
8000
|
+
clear() {
|
|
8001
|
+
}
|
|
8002
|
+
};
|
|
8003
|
+
}
|
|
8004
|
+
|
|
8005
|
+
// src/effects/threshold.ts
|
|
8006
|
+
var MIN_WALK3 = 0.5;
|
|
8007
|
+
var TIE2 = 1e-9;
|
|
7196
8008
|
var WHENS = ["below", "above"];
|
|
7197
8009
|
function threshold(options) {
|
|
7198
|
-
|
|
8010
|
+
checkOptions13(options);
|
|
7199
8011
|
const { compareTo } = options;
|
|
7200
8012
|
const when = options.when ?? "below";
|
|
7201
8013
|
const color = options.color ?? "negative";
|
|
@@ -7203,15 +8015,15 @@ function threshold(options) {
|
|
|
7203
8015
|
const paths = [];
|
|
7204
8016
|
let latest = data;
|
|
7205
8017
|
const draw = (current) => {
|
|
7206
|
-
const
|
|
8018
|
+
const parts2 = current.length >= MIN_WALK3 ? runs(latest.samples, reference(compareTo, latest), when) : [];
|
|
7207
8019
|
const paint = { stroke: color, width: current.thickness, linecap: "butt" };
|
|
7208
|
-
|
|
8020
|
+
parts2.forEach(([t0, t1], i) => {
|
|
7209
8021
|
const d = current.slice(t0, t1);
|
|
7210
8022
|
const path = paths[i];
|
|
7211
8023
|
if (path) path.update(d, paint);
|
|
7212
8024
|
else paths.push(ctx.layer.path(d, paint));
|
|
7213
8025
|
});
|
|
7214
|
-
for (const path of paths.splice(
|
|
8026
|
+
for (const path of paths.splice(parts2.length)) path.remove();
|
|
7215
8027
|
};
|
|
7216
8028
|
ctx.onChange((next, nextData) => {
|
|
7217
8029
|
latest = nextData ?? latest;
|
|
@@ -7237,7 +8049,37 @@ function reference(compareTo, data) {
|
|
|
7237
8049
|
const byAt = data.samples.every((sample) => numeric2(sample.at) !== void 0) && related.samples.every((sample) => numeric2(sample.at) !== void 0);
|
|
7238
8050
|
const place = byAt ? (sample) => numeric2(sample.at) : (sample) => sample.t;
|
|
7239
8051
|
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);
|
|
7240
|
-
|
|
8052
|
+
const gaps = gapsOf(related.samples, place);
|
|
8053
|
+
return { place, valueAt: (u) => inside2(gaps, u) ? void 0 : interpolate(points, u), bends: points.map((point) => point.u) };
|
|
8054
|
+
}
|
|
8055
|
+
function gapsOf(samples, place) {
|
|
8056
|
+
const gaps = [];
|
|
8057
|
+
samples.forEach((sample, i) => {
|
|
8058
|
+
const before = samples[i - 1];
|
|
8059
|
+
if (sample.gapBefore !== true || !before) return;
|
|
8060
|
+
const u = place(before);
|
|
8061
|
+
const v = place(sample);
|
|
8062
|
+
if (Number.isFinite(u) && Number.isFinite(v) && u !== v) gaps.push([Math.min(u, v), Math.max(u, v)]);
|
|
8063
|
+
});
|
|
8064
|
+
gaps.sort((a, b) => a[0] - b[0]);
|
|
8065
|
+
const merged = [];
|
|
8066
|
+
for (const gap of gaps) {
|
|
8067
|
+
const last = merged[merged.length - 1];
|
|
8068
|
+
if (last && gap[0] < last[1]) last[1] = Math.max(last[1], gap[1]);
|
|
8069
|
+
else merged.push(gap);
|
|
8070
|
+
}
|
|
8071
|
+
return merged;
|
|
8072
|
+
}
|
|
8073
|
+
function inside2(gaps, u) {
|
|
8074
|
+
let lo = 0;
|
|
8075
|
+
let hi = gaps.length;
|
|
8076
|
+
while (lo < hi) {
|
|
8077
|
+
const mid = lo + hi >> 1;
|
|
8078
|
+
if (gaps[mid][0] < u) lo = mid + 1;
|
|
8079
|
+
else hi = mid;
|
|
8080
|
+
}
|
|
8081
|
+
const gap = gaps[lo - 1];
|
|
8082
|
+
return gap !== void 0 && u < gap[1];
|
|
7241
8083
|
}
|
|
7242
8084
|
function numeric2(at) {
|
|
7243
8085
|
const value = typeof at === "number" ? at : at instanceof Date ? at.getTime() : void 0;
|
|
@@ -7262,18 +8104,18 @@ function interpolate(points, u) {
|
|
|
7262
8104
|
function runs(samples, ref, when) {
|
|
7263
8105
|
if (!ref) return [];
|
|
7264
8106
|
const sign = when === "below" ? 1 : -1;
|
|
7265
|
-
const station = (t, u, value) => {
|
|
8107
|
+
const station = (t, u, value, joined = true) => {
|
|
7266
8108
|
const level = ref.valueAt(u);
|
|
7267
|
-
if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, past: void 0 };
|
|
8109
|
+
if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, u, past: void 0, joined };
|
|
7268
8110
|
const past = sign * (level - value);
|
|
7269
|
-
return { t, past: Math.abs(past) <=
|
|
8111
|
+
return { t, u, past: Math.abs(past) <= TIE2 * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past, joined };
|
|
7270
8112
|
};
|
|
7271
8113
|
const stations = [];
|
|
7272
8114
|
samples.forEach((sample, i) => {
|
|
7273
8115
|
const u = ref.place(sample);
|
|
7274
|
-
stations.push(station(sample.t, u, sample.value));
|
|
8116
|
+
stations.push(station(sample.t, u, sample.value, sample.gapBefore !== true));
|
|
7275
8117
|
const next = samples[i + 1];
|
|
7276
|
-
if (!next) return;
|
|
8118
|
+
if (!next || next.gapBefore === true) return;
|
|
7277
8119
|
const v = ref.place(next);
|
|
7278
8120
|
if (u === v || !Number.isFinite(u) || !Number.isFinite(v)) return;
|
|
7279
8121
|
const shares = [];
|
|
@@ -7284,24 +8126,25 @@ function runs(samples, ref, when) {
|
|
|
7284
8126
|
stations.push(station(sample.t + share * (next.t - sample.t), u + share * (v - u), sample.value + share * (next.value - sample.value)));
|
|
7285
8127
|
}
|
|
7286
8128
|
});
|
|
7287
|
-
const
|
|
8129
|
+
const parts2 = [];
|
|
7288
8130
|
const add = (t0, t1) => {
|
|
7289
8131
|
const from = clamp2(t0);
|
|
7290
8132
|
const to = clamp2(t1);
|
|
7291
8133
|
if (!(to > from)) return;
|
|
7292
|
-
const last =
|
|
8134
|
+
const last = parts2[parts2.length - 1];
|
|
7293
8135
|
if (last && last[1] >= from) last[1] = Math.max(last[1], to);
|
|
7294
|
-
else
|
|
8136
|
+
else parts2.push([from, to]);
|
|
7295
8137
|
};
|
|
7296
8138
|
for (let i = 1; i < stations.length; i++) {
|
|
7297
8139
|
const a = stations[i - 1];
|
|
7298
8140
|
const b = stations[i];
|
|
7299
|
-
if (a.past === void 0 || b.past === void 0 || !(b.t > a.t)) continue;
|
|
8141
|
+
if (a.past === void 0 || b.past === void 0 || !b.joined || !(b.t > a.t)) continue;
|
|
8142
|
+
if (a.u !== b.u && ref.valueAt((a.u + b.u) / 2) === void 0) continue;
|
|
7300
8143
|
if (a.past > 0 && b.past > 0) add(a.t, b.t);
|
|
7301
8144
|
else if (a.past > 0) add(a.t, a.t + (b.t - a.t) * (a.past / (a.past - b.past)));
|
|
7302
8145
|
else if (b.past > 0) add(a.t + (b.t - a.t) * (a.past / (a.past - b.past)), b.t);
|
|
7303
8146
|
}
|
|
7304
|
-
return
|
|
8147
|
+
return parts2;
|
|
7305
8148
|
}
|
|
7306
8149
|
var clamp2 = (t) => Math.min(1, Math.max(0, t));
|
|
7307
8150
|
function firstAbove(values, x) {
|
|
@@ -7314,7 +8157,7 @@ function firstAbove(values, x) {
|
|
|
7314
8157
|
}
|
|
7315
8158
|
return lo;
|
|
7316
8159
|
}
|
|
7317
|
-
function
|
|
8160
|
+
function checkOptions13(options) {
|
|
7318
8161
|
const { compareTo, when, color } = options ?? {};
|
|
7319
8162
|
if (!(typeof compareTo === "string" ? compareTo !== "" : typeof compareTo === "number" && Number.isFinite(compareTo))) {
|
|
7320
8163
|
throw new RangeError(`threshold: compareTo must be a finite number or a series name, got ${show2(compareTo)}.`);
|
|
@@ -7327,11 +8170,11 @@ function checkOptions11(options) {
|
|
|
7327
8170
|
var show2 = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
7328
8171
|
|
|
7329
8172
|
// src/effects/morph.ts
|
|
7330
|
-
var
|
|
8173
|
+
var DURATION8 = 950;
|
|
7331
8174
|
var POINTS = 160;
|
|
7332
8175
|
var ALIGNS = ["unroll", "drop"];
|
|
7333
8176
|
function morph(options = {}) {
|
|
7334
|
-
|
|
8177
|
+
checkOptions14(options);
|
|
7335
8178
|
const points = options?.points ?? POINTS;
|
|
7336
8179
|
const align = options?.align ?? "unroll";
|
|
7337
8180
|
return {
|
|
@@ -7347,7 +8190,7 @@ function morph(options = {}) {
|
|
|
7347
8190
|
const begun = unease(start);
|
|
7348
8191
|
let running;
|
|
7349
8192
|
running = ctx.tween({
|
|
7350
|
-
duration:
|
|
8193
|
+
duration: DURATION8,
|
|
7351
8194
|
timing: "transition",
|
|
7352
8195
|
ease: linear,
|
|
7353
8196
|
update: (k) => {
|
|
@@ -7435,7 +8278,7 @@ function turn(from, to, points) {
|
|
|
7435
8278
|
function startOf(start) {
|
|
7436
8279
|
return typeof start === "number" && start > 0 ? Math.min(1, start) : 0;
|
|
7437
8280
|
}
|
|
7438
|
-
function
|
|
8281
|
+
function checkOptions14(options) {
|
|
7439
8282
|
const { points, align } = options ?? {};
|
|
7440
8283
|
if (points !== void 0 && !(Number.isInteger(points) && points >= 4 && points % 4 === 0)) {
|
|
7441
8284
|
throw new RangeError(`morph: points must be a whole multiple of 4, got ${String(points)}.`);
|
|
@@ -7445,18 +8288,18 @@ function checkOptions12(options) {
|
|
|
7445
8288
|
|
|
7446
8289
|
// src/effects/combinators.ts
|
|
7447
8290
|
function sequence(...effects) {
|
|
7448
|
-
const
|
|
7449
|
-
return combine(
|
|
7450
|
-
for (const part of
|
|
8291
|
+
const parts2 = check("sequence", effects);
|
|
8292
|
+
return combine(parts2, async (start, ctx) => {
|
|
8293
|
+
for (const part of parts2) {
|
|
7451
8294
|
if (ctx.signal.aborted) return;
|
|
7452
8295
|
await start(part);
|
|
7453
8296
|
}
|
|
7454
8297
|
});
|
|
7455
8298
|
}
|
|
7456
8299
|
function parallel(...effects) {
|
|
7457
|
-
const
|
|
7458
|
-
return combine(
|
|
7459
|
-
await Promise.all(
|
|
8300
|
+
const parts2 = check("parallel", effects);
|
|
8301
|
+
return combine(parts2, async (start) => {
|
|
8302
|
+
await Promise.all(parts2.map(start));
|
|
7460
8303
|
});
|
|
7461
8304
|
}
|
|
7462
8305
|
function only(filter, effect) {
|
|
@@ -7539,7 +8382,7 @@ function follow(mark, data, ctx) {
|
|
|
7539
8382
|
});
|
|
7540
8383
|
return () => latest;
|
|
7541
8384
|
}
|
|
7542
|
-
function combine(
|
|
8385
|
+
function combine(parts2, play) {
|
|
7543
8386
|
const starter = (mark, data, ctx) => {
|
|
7544
8387
|
const now = follow(mark, data, ctx);
|
|
7545
8388
|
return (part) => {
|
|
@@ -7548,14 +8391,14 @@ function combine(parts, play) {
|
|
|
7548
8391
|
};
|
|
7549
8392
|
};
|
|
7550
8393
|
const end = (mark, data, ctx) => {
|
|
7551
|
-
for (const part of
|
|
8394
|
+
for (const part of parts2) {
|
|
7552
8395
|
if (part.kind === "data") part.end(mark, data, ctx);
|
|
7553
8396
|
else part.end(mark, ctx);
|
|
7554
8397
|
}
|
|
7555
8398
|
};
|
|
7556
8399
|
const clear = (ctx) => {
|
|
7557
8400
|
let failure;
|
|
7558
|
-
for (const part of
|
|
8401
|
+
for (const part of parts2) {
|
|
7559
8402
|
try {
|
|
7560
8403
|
part.clear(ctx);
|
|
7561
8404
|
} catch (error) {
|
|
@@ -7564,8 +8407,8 @@ function combine(parts, play) {
|
|
|
7564
8407
|
}
|
|
7565
8408
|
if (failure) throw failure.error;
|
|
7566
8409
|
};
|
|
7567
|
-
if (
|
|
7568
|
-
const related = [...new Set(
|
|
8410
|
+
if (parts2.some((part) => part.kind === "data")) {
|
|
8411
|
+
const related = [...new Set(parts2.flatMap((part) => part.kind === "data" ? part.needs?.related ?? [] : []))];
|
|
7569
8412
|
const effect2 = {
|
|
7570
8413
|
kind: "data",
|
|
7571
8414
|
...related.length > 0 ? { needs: { related } } : {},
|
|
@@ -7629,9 +8472,9 @@ var ATTRIBUTE = /([^\s=/<>]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'<>]+)))?/g;
|
|
|
7629
8472
|
var COLOR = /^(?:#[0-9a-fA-F]{3,8}|[a-zA-Z][a-zA-Z0-9-]*|(?:rgba?|hsla?)\([\d\s.,%+\-/]*\))$/;
|
|
7630
8473
|
function iconFromSvg(markup, spec) {
|
|
7631
8474
|
if (typeof markup !== "string") throw new TypeError("iconFromSvg needs SVG markup as a string.");
|
|
7632
|
-
const
|
|
8475
|
+
const label2 = typeof spec?.name === "string" ? `"${spec.name}"` : "an icon";
|
|
7633
8476
|
const fail = (problem) => {
|
|
7634
|
-
throw new RangeError(`iconFromSvg: ${
|
|
8477
|
+
throw new RangeError(`iconFromSvg: ${label2} ${problem}.`);
|
|
7635
8478
|
};
|
|
7636
8479
|
let box;
|
|
7637
8480
|
let scale = 1;
|
|
@@ -7655,7 +8498,7 @@ function iconFromSvg(markup, spec) {
|
|
|
7655
8498
|
if (typeof spec.size !== "number" || !(spec.size > 0) || !Number.isFinite(spec.size)) fail(`size must be more than 0, got ${String(spec.size)}`);
|
|
7656
8499
|
scale = spec.size / box.width;
|
|
7657
8500
|
}
|
|
7658
|
-
root = { fill: "#000000", stroke: "none", width: 1, linecap: void 0, linejoin: void 0, transform: matrix.scale(scale) };
|
|
8501
|
+
root = { fill: "#000000", stroke: "none", width: 1, linecap: void 0, linejoin: void 0, fillRule: "nonzero", opacity: 1, transform: matrix.scale(scale) };
|
|
7659
8502
|
}
|
|
7660
8503
|
const parent = stack.length > 0 ? stack[stack.length - 1].state : first ? root : void 0;
|
|
7661
8504
|
const state = parent && !hidden(attributes) ? inherit(parent, attributes) : void 0;
|
|
@@ -7726,6 +8569,10 @@ function pixels(value) {
|
|
|
7726
8569
|
const number2 = match ? Number(match[1]) : NaN;
|
|
7727
8570
|
return number2 > 0 && Number.isFinite(number2) ? number2 : void 0;
|
|
7728
8571
|
}
|
|
8572
|
+
function alpha(value) {
|
|
8573
|
+
const match = /^\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)(%?)\s*$/i.exec(value ?? "");
|
|
8574
|
+
return match ? Math.min(1, Math.max(0, Number(match[1]) / (match[2] ? 100 : 1))) : 1;
|
|
8575
|
+
}
|
|
7729
8576
|
function hidden(attributes) {
|
|
7730
8577
|
return attributes.get("display")?.trim() === "none" || attributes.get("visibility")?.trim() === "hidden";
|
|
7731
8578
|
}
|
|
@@ -7739,6 +8586,7 @@ function inherit(parent, attributes) {
|
|
|
7739
8586
|
const width = Number.parseFloat(attributes.get("stroke-width") ?? "");
|
|
7740
8587
|
const linecap = attributes.get("stroke-linecap")?.trim();
|
|
7741
8588
|
const linejoin = attributes.get("stroke-linejoin")?.trim();
|
|
8589
|
+
const fillRule = attributes.get("fill-rule")?.trim().toLowerCase();
|
|
7742
8590
|
const transform = attributes.get("transform");
|
|
7743
8591
|
return {
|
|
7744
8592
|
fill: paint("fill", parent.fill),
|
|
@@ -7746,26 +8594,31 @@ function inherit(parent, attributes) {
|
|
|
7746
8594
|
width: width >= 0 ? width : parent.width,
|
|
7747
8595
|
linecap: linecap === "butt" || linecap === "round" ? linecap : parent.linecap,
|
|
7748
8596
|
linejoin: linejoin === "miter" || linejoin === "round" ? linejoin : parent.linejoin,
|
|
8597
|
+
fillRule: fillRule === "nonzero" || fillRule === "evenodd" ? fillRule : parent.fillRule,
|
|
8598
|
+
// Opacity isn't inherited in SVG: a group is drawn and then faded. Multiplying is the same unless its shapes overlap.
|
|
8599
|
+
opacity: parent.opacity * alpha(attributes.get("opacity")),
|
|
7749
8600
|
transform: transform ? matrix.multiply(parent.transform, parseTransform(transform)) : parent.transform
|
|
7750
8601
|
};
|
|
7751
8602
|
}
|
|
7752
8603
|
function toShape(tag, attributes, state) {
|
|
7753
8604
|
const fill = state.fill === "none" ? void 0 : state.fill;
|
|
7754
8605
|
const stroke2 = state.stroke === "none" || !(state.width > 0) ? void 0 : state.stroke;
|
|
7755
|
-
|
|
8606
|
+
const opacity = round4(state.opacity);
|
|
8607
|
+
if (fill === void 0 && stroke2 === void 0 || !(opacity > 0)) return void 0;
|
|
7756
8608
|
const commands = outline(tag, attributes);
|
|
7757
8609
|
if (!commands.some((command) => command.op !== "M")) return void 0;
|
|
7758
8610
|
const m = state.transform;
|
|
7759
8611
|
return {
|
|
7760
8612
|
d: formatPath(transformPath(commands, m)),
|
|
7761
|
-
...fill !== void 0 ? { fill } : {},
|
|
8613
|
+
...fill !== void 0 ? { fill, ...state.fillRule === "evenodd" ? { fillRule: state.fillRule } : {} } : {},
|
|
7762
8614
|
...stroke2 !== void 0 ? {
|
|
7763
8615
|
stroke: stroke2,
|
|
7764
8616
|
// A stroke scales with the transform; for an uneven scale this is the average.
|
|
7765
8617
|
width: round4(state.width * Math.sqrt(Math.abs(m[0] * m[3] - m[1] * m[2]))),
|
|
7766
8618
|
...state.linecap ? { linecap: state.linecap } : {},
|
|
7767
8619
|
...state.linejoin ? { linejoin: state.linejoin } : {}
|
|
7768
|
-
} : {}
|
|
8620
|
+
} : {},
|
|
8621
|
+
...opacity < 1 ? { opacity } : {}
|
|
7769
8622
|
};
|
|
7770
8623
|
}
|
|
7771
8624
|
function outline(tag, attributes) {
|
|
@@ -7904,7 +8757,7 @@ function configure(options) {
|
|
|
7904
8757
|
}
|
|
7905
8758
|
|
|
7906
8759
|
// src/index.ts
|
|
7907
|
-
var VERSION = "0.
|
|
8760
|
+
var VERSION = "0.3.0";
|
|
7908
8761
|
var env = { presets: presetRegistry, icons: iconRegistry, motion };
|
|
7909
8762
|
function barChart2(target, options) {
|
|
7910
8763
|
return barChart(target, options, env);
|
|
@@ -7942,6 +8795,7 @@ export {
|
|
|
7942
8795
|
defineDataEffect,
|
|
7943
8796
|
defineEffect,
|
|
7944
8797
|
defineIcon,
|
|
8798
|
+
delta,
|
|
7945
8799
|
describe,
|
|
7946
8800
|
donutChart2 as donutChart,
|
|
7947
8801
|
easeInOutCubic,
|
|
@@ -7955,8 +8809,10 @@ export {
|
|
|
7955
8809
|
interpolateNumber,
|
|
7956
8810
|
interpolatePoint,
|
|
7957
8811
|
interpolateRecord,
|
|
8812
|
+
label,
|
|
7958
8813
|
lineChart2 as lineChart,
|
|
7959
8814
|
linear,
|
|
8815
|
+
link,
|
|
7960
8816
|
manualClock,
|
|
7961
8817
|
matrix,
|
|
7962
8818
|
mediaReducedMotion,
|
|
@@ -7977,6 +8833,7 @@ export {
|
|
|
7977
8833
|
sequence,
|
|
7978
8834
|
stagger,
|
|
7979
8835
|
threshold,
|
|
8836
|
+
trace,
|
|
7980
8837
|
travel,
|
|
7981
8838
|
tween,
|
|
7982
8839
|
wiggle
|