expressive-charts 0.1.0 → 0.2.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 +18 -0
- package/README.md +10 -9
- package/dist/{chunk-ZIGBM4NY.js → chunk-V5IUTXRW.js} +23 -6
- package/dist/chunk-V5IUTXRW.js.map +1 -0
- package/dist/{drawing-Du6DAgrW.d.cts → drawing-DWZIXIeR.d.cts} +6 -0
- package/dist/{drawing-Du6DAgrW.d.ts → drawing-DWZIXIeR.d.ts} +6 -0
- package/dist/{effect-OcyvtfZi.d.ts → effect-CZUckY0l.d.ts} +1 -1
- package/dist/{effect-dPmXiWlL.d.cts → effect-CcGdU41j.d.cts} +1 -1
- package/dist/expressive-charts.css +5 -5
- package/dist/expressive-charts.global.js +50 -50
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.js +1 -1
- package/dist/index.cjs +819 -359
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +105 -8
- package/dist/index.d.ts +105 -8
- package/dist/index.js +788 -349
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +22 -5
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-ZIGBM4NY.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
offset,
|
|
41
41
|
parseTransform,
|
|
42
42
|
samplesAlong
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-V5IUTXRW.js";
|
|
44
44
|
|
|
45
45
|
// src/charts/announce.ts
|
|
46
46
|
var SORTED = {
|
|
@@ -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;
|
|
@@ -153,11 +223,11 @@ function layoutBars(input) {
|
|
|
153
223
|
height: frame.bands.height,
|
|
154
224
|
orientation: frame.orientation,
|
|
155
225
|
frame,
|
|
156
|
-
rows: rows2.map((row, slot) => placeRow(frame, { ...row, slot, text: texts[slot] })),
|
|
226
|
+
rows: rows2.map((row, slot) => placeRow(frame, { ...row, slot, text: texts[slot] }, input.measure)),
|
|
157
227
|
ticks: domain.ticks.map((value, i) => placeTick(frame, value, ticks[i]))
|
|
158
228
|
};
|
|
159
229
|
}
|
|
160
|
-
function placeRow(frame, row) {
|
|
230
|
+
function placeRow(frame, row, measure) {
|
|
161
231
|
const { scale, bands } = frame;
|
|
162
232
|
const at = position(scale);
|
|
163
233
|
const unit = Math.abs(scale.extent / (scale.hi - scale.lo));
|
|
@@ -174,40 +244,52 @@ function placeRow(frame, row) {
|
|
|
174
244
|
segments: row.values.map((v) => ({ series: v.series, size: Math.max(0, negative ? -v.value : v.value) * unit }))
|
|
175
245
|
};
|
|
176
246
|
const fields = { key: row.key, datum: row.datum, index: row.index, slot: row.slot, values: row.values, total: total2 };
|
|
247
|
+
const boxes = (label3, value2) => {
|
|
248
|
+
const out = [];
|
|
249
|
+
if (label3.text !== "") out.push(textBox(label3, measure, "ec-label", LABEL_SIZE));
|
|
250
|
+
if (value2.text !== "") out.push(textBox(value2, measure, "ec-value", VALUE_SIZE));
|
|
251
|
+
return out;
|
|
252
|
+
};
|
|
177
253
|
if (frame.orientation === "horizontal") {
|
|
254
|
+
const line = band + bands.band / 2 + LABEL_SIZE * CENTRE;
|
|
255
|
+
const label3 = { x: scale.label, y: line, anchor: "end", text: row.category };
|
|
256
|
+
const value2 = { x: negative ? tip - PAD : tip + PAD, y: line, anchor: negative ? "end" : "start", text: row.text };
|
|
178
257
|
const geometry2 = describe.bar({
|
|
179
258
|
...bar,
|
|
180
259
|
x: Math.min(zero, tip),
|
|
181
260
|
y: band + (bands.band - bands.thickness) / 2,
|
|
182
261
|
width: Math.abs(tip - zero),
|
|
183
262
|
height: bands.thickness,
|
|
184
|
-
baseline: negative ? "right" : "left"
|
|
263
|
+
baseline: negative ? "right" : "left",
|
|
264
|
+
labelBounds: boxes(label3, value2)
|
|
185
265
|
});
|
|
186
|
-
const line = band + bands.band / 2 + LABEL_SIZE * CENTRE;
|
|
187
266
|
return {
|
|
188
267
|
...fields,
|
|
189
268
|
geometry: geometry2,
|
|
190
269
|
data: barData(row.datum, total2, geometry2),
|
|
191
|
-
label:
|
|
192
|
-
value:
|
|
270
|
+
label: label3,
|
|
271
|
+
value: value2,
|
|
193
272
|
hit: { x: 0, y: band, width: bands.width, height: bands.band }
|
|
194
273
|
};
|
|
195
274
|
}
|
|
196
275
|
const centre = band + bands.band / 2;
|
|
276
|
+
const label2 = { x: centre, y: scale.label, anchor: "middle", text: row.category };
|
|
277
|
+
const value = { x: centre, y: negative ? tip + PAD + VALUE_SIZE * 0.8 : tip - PAD, anchor: "middle", text: row.text };
|
|
197
278
|
const geometry = describe.bar({
|
|
198
279
|
...bar,
|
|
199
280
|
x: centre - bands.thickness / 2,
|
|
200
281
|
y: Math.min(zero, tip),
|
|
201
282
|
width: bands.thickness,
|
|
202
283
|
height: Math.abs(tip - zero),
|
|
203
|
-
baseline: negative ? "top" : "bottom"
|
|
284
|
+
baseline: negative ? "top" : "bottom",
|
|
285
|
+
labelBounds: boxes(label2, value)
|
|
204
286
|
});
|
|
205
287
|
return {
|
|
206
288
|
...fields,
|
|
207
289
|
geometry,
|
|
208
290
|
data: barData(row.datum, total2, geometry),
|
|
209
|
-
label:
|
|
210
|
-
value
|
|
291
|
+
label: label2,
|
|
292
|
+
value,
|
|
211
293
|
hit: { x: band, y: 0, width: bands.band, height: bands.height }
|
|
212
294
|
};
|
|
213
295
|
}
|
|
@@ -449,10 +531,10 @@ ${TOKEN_RULES}
|
|
|
449
531
|
:where(.ec-chart .ec-focus) { pointer-events: none; }
|
|
450
532
|
:where(.ec-chart .ec-focus-ring) { fill: none; stroke: var(--ec-focus, ${TOKENS.focus}); }
|
|
451
533
|
: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; }
|
|
534
|
+
:where(.ec-chart .ec-body > *) { transition: opacity var(--ec-hover-duration, 100ms) ease-out; }
|
|
535
|
+
: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
536
|
: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; }
|
|
537
|
+
: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
538
|
:where(.ec-chart .ec-hot .ec-stroke) { stroke: var(--ec-mark-strong); }
|
|
457
539
|
:where(.ec-chart .ec-end) { fill: var(--ec-mark); stroke: var(--ec-surface, ${TOKENS.surface}); stroke-width: 2; }
|
|
458
540
|
: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; }
|
|
@@ -460,11 +542,11 @@ ${TOKEN_RULES}
|
|
|
460
542
|
:where(.ec-chart .ec-crosshair) { stroke: var(--ec-axis, ${TOKENS.axis}); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
|
|
461
543
|
:where(.ec-chart .ec-column:focus) { outline: none; }
|
|
462
544
|
: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; }
|
|
545
|
+
: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
546
|
:where(.ec-chart .ec-hot .ec-slice) { fill: var(--ec-mark-strong); }
|
|
465
547
|
:where(.ec-chart .ec-center-value) { fill: var(--ec-text, ${TOKENS.text}); font-size: 26px; font-weight: 600; }
|
|
466
548
|
: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); }
|
|
549
|
+
:where(.ec-chart.ec-hovering .ec-mark:not(.ec-hot) > .ec-body > *) { opacity: var(--ec-dim-opacity, 0.3); }
|
|
468
550
|
:where(.ec-chart.ec-morphing .ec-marks) { visibility: hidden; }
|
|
469
551
|
:where(.ec-switch) { display: grid; grid-template-columns: minmax(0, 1fr); position: relative; }
|
|
470
552
|
:where(.ec-switch-view) { grid-area: 1 / 1; min-width: 0; }
|
|
@@ -556,8 +638,8 @@ function checkLegendOption(option, chart) {
|
|
|
556
638
|
if (entries === void 0) return;
|
|
557
639
|
if (!Array.isArray(entries)) fail("legend.entries must be an array of { label, color }.");
|
|
558
640
|
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
|
|
641
|
+
const { label: label2, color } = typeof entry === "object" && entry !== null ? entry : fail(`legend.entries[${i}] must be an object with a label and a color.`);
|
|
642
|
+
if (typeof label2 !== "string" || label2.trim() === "") fail(`legend.entries[${i}].label must be a non-empty string: the entry's name.`);
|
|
561
643
|
if (typeof color !== "string" || color.trim() === "") fail(`legend.entries[${i}].color must be a theme token or a CSS colour.`);
|
|
562
644
|
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
645
|
});
|
|
@@ -573,8 +655,8 @@ function chartLegend(svg) {
|
|
|
573
655
|
};
|
|
574
656
|
const draw = (entries, colors, attribute, more) => {
|
|
575
657
|
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) } }))
|
|
658
|
+
...entries.map(({ key, label: label2 }) => ({ key, label: label2, styles: markColorStyles(seriesColors(colors.slot(key))) })),
|
|
659
|
+
...more.map(({ label: label2, color }) => ({ key: void 0, label: label2, styles: { "--ec-mark": cssColor(color) } }))
|
|
578
660
|
];
|
|
579
661
|
const doc = svg.ownerDocument;
|
|
580
662
|
legend ?? (legend = Object.assign(doc.createElement("div"), { className: "ec-legend" }));
|
|
@@ -590,10 +672,10 @@ function chartLegend(svg) {
|
|
|
590
672
|
for (const [property, value] of Object.entries(styles)) if (value !== void 0) item.style.setProperty(property, value);
|
|
591
673
|
const swatch = doc.createElement("span");
|
|
592
674
|
swatch.className = "ec-legend-swatch";
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
item.append(swatch,
|
|
675
|
+
const label2 = doc.createElement("span");
|
|
676
|
+
label2.className = "ec-legend-label";
|
|
677
|
+
label2.textContent = text2;
|
|
678
|
+
item.append(swatch, label2);
|
|
597
679
|
return item;
|
|
598
680
|
})
|
|
599
681
|
);
|
|
@@ -602,7 +684,7 @@ function chartLegend(svg) {
|
|
|
602
684
|
update(series, colors, option) {
|
|
603
685
|
const more = extras(option);
|
|
604
686
|
if (option === false || series.length + more.length < 2) remove();
|
|
605
|
-
else draw(series.map(({ series: key, label }) => ({ key, label })), colors, "data-series", more);
|
|
687
|
+
else draw(series.map(({ series: key, label: label2 }) => ({ key, label: label2 })), colors, "data-series", more);
|
|
606
688
|
},
|
|
607
689
|
categories(categories, colors, option) {
|
|
608
690
|
if (option === false || categories.length === 0) remove();
|
|
@@ -612,6 +694,100 @@ function chartLegend(svg) {
|
|
|
612
694
|
};
|
|
613
695
|
}
|
|
614
696
|
|
|
697
|
+
// src/charts/link.ts
|
|
698
|
+
var own = (hovered) => hovered !== void 0 && hovered.source !== "linked";
|
|
699
|
+
var ports = /* @__PURE__ */ new WeakMap();
|
|
700
|
+
var linked = /* @__PURE__ */ new WeakSet();
|
|
701
|
+
function linkable(port, handle) {
|
|
702
|
+
ports.set(handle, port);
|
|
703
|
+
return handle;
|
|
704
|
+
}
|
|
705
|
+
var portOf = (handle) => ports.get(handle);
|
|
706
|
+
function link(sources, options = {}) {
|
|
707
|
+
if (!Array.isArray(sources)) throw new TypeError("link needs an array of charts and attachments: link([columns, line]).");
|
|
708
|
+
if (typeof options !== "object" || options === null) throw new TypeError("link: options must be an object, such as { by: (event) => event.data.datum.week }.");
|
|
709
|
+
const { by, effects = true } = options;
|
|
710
|
+
if (by !== void 0 && typeof by !== "function") throw new TypeError("link: by must be a function, such as (event) => event.data.datum.week.");
|
|
711
|
+
if (typeof effects !== "boolean") throw new TypeError(`link: effects must be true or false, got ${String(effects)}.`);
|
|
712
|
+
const members = [];
|
|
713
|
+
for (const source of sources) {
|
|
714
|
+
const port = typeof source === "object" && source !== null ? ports.get(source) : void 0;
|
|
715
|
+
if (!port) {
|
|
716
|
+
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.");
|
|
717
|
+
}
|
|
718
|
+
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.");
|
|
719
|
+
members.push(port);
|
|
720
|
+
}
|
|
721
|
+
const live = /* @__PURE__ */ new Set();
|
|
722
|
+
let origin;
|
|
723
|
+
function valueOf(input) {
|
|
724
|
+
let value;
|
|
725
|
+
if (by) {
|
|
726
|
+
try {
|
|
727
|
+
value = by(input);
|
|
728
|
+
} catch (error) {
|
|
729
|
+
report(error);
|
|
730
|
+
return void 0;
|
|
731
|
+
}
|
|
732
|
+
} else {
|
|
733
|
+
const { samples } = input.data;
|
|
734
|
+
value = samples[samples.length - 1]?.at ?? input.mark.key;
|
|
735
|
+
}
|
|
736
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? void 0 : value.toISOString();
|
|
737
|
+
return value === void 0 || value === null ? void 0 : String(value);
|
|
738
|
+
}
|
|
739
|
+
function hovered(from, marks) {
|
|
740
|
+
origin = from;
|
|
741
|
+
const values = new Set(marks.map(valueOf));
|
|
742
|
+
values.delete(void 0);
|
|
743
|
+
const matches = (target) => target.some((mark) => {
|
|
744
|
+
const value = valueOf(mark);
|
|
745
|
+
return value !== void 0 && values.has(value);
|
|
746
|
+
});
|
|
747
|
+
for (const port of live) {
|
|
748
|
+
if (port === from) continue;
|
|
749
|
+
const keys = values.size === 0 ? [] : port.targets().flatMap((target) => matches(target.marks) ? [target.key] : []);
|
|
750
|
+
port.hover(keys, effects);
|
|
751
|
+
if (origin !== from) return;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
function left(from) {
|
|
755
|
+
if (origin !== from) return;
|
|
756
|
+
origin = void 0;
|
|
757
|
+
for (const port of live) port.unlink();
|
|
758
|
+
}
|
|
759
|
+
for (const port of members) {
|
|
760
|
+
const listening = port.listen({
|
|
761
|
+
hover: (marks) => hovered(port, marks),
|
|
762
|
+
leave: () => left(port),
|
|
763
|
+
dismiss() {
|
|
764
|
+
const from = origin;
|
|
765
|
+
from?.leave();
|
|
766
|
+
if (from) left(from);
|
|
767
|
+
},
|
|
768
|
+
gone() {
|
|
769
|
+
live.delete(port);
|
|
770
|
+
linked.delete(port);
|
|
771
|
+
left(port);
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
if (!listening) continue;
|
|
775
|
+
live.add(port);
|
|
776
|
+
linked.add(port);
|
|
777
|
+
}
|
|
778
|
+
return {
|
|
779
|
+
destroy() {
|
|
780
|
+
for (const port of live) {
|
|
781
|
+
port.listen(void 0);
|
|
782
|
+
port.unlink();
|
|
783
|
+
linked.delete(port);
|
|
784
|
+
}
|
|
785
|
+
live.clear();
|
|
786
|
+
origin = void 0;
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
|
|
615
791
|
// src/charts/motion.ts
|
|
616
792
|
var MODES = ["presentation", "analysis", "off"];
|
|
617
793
|
function chartMotion(option, page) {
|
|
@@ -634,39 +810,6 @@ function chartMotion(option, page) {
|
|
|
634
810
|
};
|
|
635
811
|
}
|
|
636
812
|
|
|
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
813
|
// src/charts/render/outside.ts
|
|
671
814
|
var RING_GAP = 2;
|
|
672
815
|
var RING = 2;
|
|
@@ -819,15 +962,15 @@ function svgLayer(group) {
|
|
|
819
962
|
icon(icon, options) {
|
|
820
963
|
const size = options?.size;
|
|
821
964
|
if (size !== void 0 && !(size >= 0)) throw new RangeError(`layer.icon: size must be a non-negative number, got ${String(size)}.`);
|
|
822
|
-
const
|
|
965
|
+
const placed2 = svgElement("g", { class: "ec-icon", "data-icon": icon.name, visibility: "hidden" }, group);
|
|
823
966
|
const k = size === void 0 || !(icon.size > 0) ? 1 : size / icon.size;
|
|
824
|
-
const body = k === 1 ?
|
|
967
|
+
const body = k === 1 ? placed2 : svgElement("g", { transform: transformAttribute(matrix.scale(k, k, icon.anchor)) }, placed2);
|
|
825
968
|
for (const shape of icon.shapes) drawShape(shape, body);
|
|
826
969
|
const handle = {
|
|
827
970
|
place(transform) {
|
|
828
|
-
setAttributes(
|
|
971
|
+
setAttributes(placed2, { transform: transformAttribute(transform), visibility: void 0 });
|
|
829
972
|
},
|
|
830
|
-
remove: () =>
|
|
973
|
+
remove: () => placed2.remove()
|
|
831
974
|
};
|
|
832
975
|
return handle;
|
|
833
976
|
},
|
|
@@ -946,35 +1089,6 @@ function svgSurface(options) {
|
|
|
946
1089
|
};
|
|
947
1090
|
}
|
|
948
1091
|
|
|
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
1092
|
// src/charts/series.ts
|
|
979
1093
|
function seriesLabel(labels, series) {
|
|
980
1094
|
return labels !== void 0 && Object.prototype.hasOwnProperty.call(labels, series) ? labels[series] ?? series : series;
|
|
@@ -982,8 +1096,8 @@ function seriesLabel(labels, series) {
|
|
|
982
1096
|
function checkSeriesLabels(option, chart) {
|
|
983
1097
|
if (option === void 0) return;
|
|
984
1098
|
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
|
|
1099
|
+
for (const [series, label2] of Object.entries(option)) {
|
|
1100
|
+
if (typeof label2 !== "string" || label2.trim() === "") throw new TypeError(`${chart}: seriesLabels.${series} must be a name, not ${typeof label2 === "string" ? "blank" : String(label2)}.`);
|
|
987
1101
|
}
|
|
988
1102
|
}
|
|
989
1103
|
|
|
@@ -1136,10 +1250,10 @@ function keyboardFocus(svg, options) {
|
|
|
1136
1250
|
leave2();
|
|
1137
1251
|
return;
|
|
1138
1252
|
}
|
|
1139
|
-
const
|
|
1140
|
-
if (
|
|
1141
|
-
|
|
1142
|
-
if (on?.scope.activeElement ===
|
|
1253
|
+
const own2 = options.element(key);
|
|
1254
|
+
if (own2 && own2 !== event.target && event.target.getAttribute("aria-hidden") === "true") {
|
|
1255
|
+
own2.focus();
|
|
1256
|
+
if (on?.scope.activeElement === own2) return;
|
|
1143
1257
|
}
|
|
1144
1258
|
focused = { key, element: event.target };
|
|
1145
1259
|
if (key === current) return;
|
|
@@ -1269,13 +1383,16 @@ function chartHover(options) {
|
|
|
1269
1383
|
const markElement = (key) => (options.markElement ?? options.element)(key);
|
|
1270
1384
|
let hovered;
|
|
1271
1385
|
let ringKey;
|
|
1386
|
+
let linked2;
|
|
1387
|
+
let destroyed = false;
|
|
1272
1388
|
const onScreen = (keys) => keys.flatMap((key) => {
|
|
1273
1389
|
const input = options.onScreen(key);
|
|
1274
1390
|
return input ? [{ key, input }] : [];
|
|
1275
1391
|
});
|
|
1276
|
-
|
|
1392
|
+
const marksFor = (keys) => keys.length === 1 ? marksOf(keys[0]) : [...new Set(keys.flatMap(marksOf))];
|
|
1393
|
+
function hoverMarks(marks, source, effects, segment) {
|
|
1277
1394
|
if (marks.length === 0) return;
|
|
1278
|
-
runner.hover(marks.map(({ input }) => input));
|
|
1395
|
+
if (effects) runner.hover(marks.map(({ input }) => input));
|
|
1279
1396
|
const count = marks.length;
|
|
1280
1397
|
marks.forEach(({ input }, index) => events.emit("hover", { ...input, batch: { index, count }, source, ...segment === void 0 ? {} : { segment } }));
|
|
1281
1398
|
}
|
|
@@ -1287,22 +1404,27 @@ function chartHover(options) {
|
|
|
1287
1404
|
const count = marks.length;
|
|
1288
1405
|
marks.forEach(({ input }, index) => events.emit("leave", { ...input, batch: { index, count } }));
|
|
1289
1406
|
}
|
|
1290
|
-
function startHover(
|
|
1291
|
-
const marks = onScreen(
|
|
1292
|
-
|
|
1407
|
+
function startHover(keys, source, segment, effects = true) {
|
|
1408
|
+
const marks = onScreen(marksFor(keys));
|
|
1409
|
+
const started = { keys, source, marks: marks.map((mark) => mark.key), effects };
|
|
1410
|
+
hovered = started;
|
|
1293
1411
|
for (const { key: mark } of marks) markElement(mark)?.classList.add("ec-hot");
|
|
1294
1412
|
if (options.dim()) svg.classList.add("ec-hovering");
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1413
|
+
if (source !== "linked") {
|
|
1414
|
+
options.tooltip.show(keys[0]);
|
|
1415
|
+
listenForEscape(true);
|
|
1416
|
+
}
|
|
1417
|
+
hoverMarks(marks, source, effects, segment);
|
|
1418
|
+
if (source !== "linked" && hovered === started) linked2?.hover(marks.map(({ input }) => input));
|
|
1298
1419
|
}
|
|
1299
1420
|
function endHover() {
|
|
1300
|
-
const
|
|
1421
|
+
const ended = hovered;
|
|
1301
1422
|
hovered = void 0;
|
|
1302
1423
|
listenForEscape(false);
|
|
1303
1424
|
svg.classList.remove("ec-hovering");
|
|
1304
1425
|
options.tooltip.hide();
|
|
1305
|
-
leaveMarks(marks);
|
|
1426
|
+
leaveMarks(ended?.marks ?? []);
|
|
1427
|
+
if (own(ended)) linked2?.leave();
|
|
1306
1428
|
}
|
|
1307
1429
|
let escapeDoc;
|
|
1308
1430
|
const dismiss = (event) => {
|
|
@@ -1321,12 +1443,12 @@ function chartHover(options) {
|
|
|
1321
1443
|
const interaction = pointerHover(svg, {
|
|
1322
1444
|
find: options.find,
|
|
1323
1445
|
hover(target, source) {
|
|
1324
|
-
if (!options.live(target.key) || hovered
|
|
1446
|
+
if (!options.live(target.key) || own(hovered) && hovered.keys[0] === target.key) return;
|
|
1325
1447
|
endHover();
|
|
1326
|
-
startHover(target.key, source, target.segment);
|
|
1448
|
+
startHover([target.key], source, target.segment);
|
|
1327
1449
|
},
|
|
1328
1450
|
leave() {
|
|
1329
|
-
if (hovered?.source
|
|
1451
|
+
if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
|
|
1330
1452
|
}
|
|
1331
1453
|
});
|
|
1332
1454
|
const keyboard = keyboardFocus(() => svg, {
|
|
@@ -1338,40 +1460,60 @@ function chartHover(options) {
|
|
|
1338
1460
|
options.ring(ringKey);
|
|
1339
1461
|
if (!options.live(key)) return;
|
|
1340
1462
|
if (!visible) {
|
|
1341
|
-
if (hovered?.source === "keyboard" && hovered.
|
|
1463
|
+
if (hovered?.source === "keyboard" && hovered.keys[0] !== key) endHover();
|
|
1342
1464
|
return;
|
|
1343
1465
|
}
|
|
1344
|
-
if (hovered
|
|
1466
|
+
if (own(hovered) && hovered.keys[0] === key) {
|
|
1345
1467
|
hovered = { ...hovered, source: "keyboard" };
|
|
1346
1468
|
return;
|
|
1347
1469
|
}
|
|
1348
1470
|
endHover();
|
|
1349
|
-
startHover(key, "keyboard");
|
|
1471
|
+
startHover([key], "keyboard");
|
|
1350
1472
|
},
|
|
1351
1473
|
blur() {
|
|
1352
1474
|
ringKey = void 0;
|
|
1353
1475
|
options.ring(ringKey);
|
|
1354
1476
|
if (hovered?.source !== "keyboard") return;
|
|
1355
|
-
if (interaction.current === hovered.
|
|
1477
|
+
if (interaction.current === hovered.keys[0]) hovered = { ...hovered, source: "pointer" };
|
|
1356
1478
|
else endHover();
|
|
1357
1479
|
},
|
|
1358
1480
|
escape() {
|
|
1359
1481
|
if (!hovered) return false;
|
|
1360
|
-
|
|
1482
|
+
if (hovered.source === "linked" && linked2) linked2.dismiss();
|
|
1483
|
+
else endHover();
|
|
1361
1484
|
return true;
|
|
1362
1485
|
}
|
|
1363
1486
|
});
|
|
1487
|
+
const link2 = {
|
|
1488
|
+
targets: () => options.order().map((key) => ({ key, marks: onScreen(marksOf(key)).map(({ input }) => input) })),
|
|
1489
|
+
hover(keys, effects) {
|
|
1490
|
+
if (hovered !== void 0) endHover();
|
|
1491
|
+
const live = keys.filter(options.live);
|
|
1492
|
+
if (live.length > 0) startHover(live, "linked", void 0, effects);
|
|
1493
|
+
},
|
|
1494
|
+
unlink() {
|
|
1495
|
+
if (hovered?.source === "linked") endHover();
|
|
1496
|
+
},
|
|
1497
|
+
leave: leave2,
|
|
1498
|
+
listen(listener) {
|
|
1499
|
+
if (destroyed) return false;
|
|
1500
|
+
linked2 = listener;
|
|
1501
|
+
return true;
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1364
1504
|
return {
|
|
1365
1505
|
get key() {
|
|
1366
|
-
return hovered
|
|
1506
|
+
return own(hovered) ? hovered.keys[0] : void 0;
|
|
1367
1507
|
},
|
|
1368
1508
|
get ringKey() {
|
|
1369
1509
|
return ringKey;
|
|
1370
1510
|
},
|
|
1511
|
+
link: link2,
|
|
1371
1512
|
active: () => keyboard.active(),
|
|
1372
1513
|
restyled(key) {
|
|
1373
1514
|
if (ringKey !== void 0 && within(ringKey, key)) options.ring(ringKey);
|
|
1374
|
-
|
|
1515
|
+
const target = own(hovered) ? hovered.keys[0] : void 0;
|
|
1516
|
+
if (target !== void 0 && (hovered?.marks.includes(key) || key === target) && options.live(target)) options.tooltip.show(target);
|
|
1375
1517
|
},
|
|
1376
1518
|
syncDim() {
|
|
1377
1519
|
if (!options.dim()) svg.classList.remove("ec-hovering");
|
|
@@ -1379,22 +1521,24 @@ function chartHover(options) {
|
|
|
1379
1521
|
},
|
|
1380
1522
|
dropGone() {
|
|
1381
1523
|
if (hovered === void 0) return;
|
|
1382
|
-
|
|
1524
|
+
const keys = hovered.keys.filter(options.live);
|
|
1525
|
+
if (keys.length === 0) {
|
|
1383
1526
|
interaction.clear();
|
|
1384
1527
|
endHover();
|
|
1385
1528
|
return;
|
|
1386
1529
|
}
|
|
1387
|
-
const { source, marks: before } = hovered;
|
|
1388
|
-
const now = onScreen(
|
|
1530
|
+
const { source, marks: before, effects } = hovered;
|
|
1531
|
+
const now = onScreen(marksFor(keys));
|
|
1532
|
+
hovered = { ...hovered, keys };
|
|
1389
1533
|
if (now.length === before.length && now.every((mark, i) => mark.key === before[i])) return;
|
|
1390
1534
|
const had = new Set(before);
|
|
1391
|
-
const
|
|
1392
|
-
const gone = onScreen(before.filter((key) => !
|
|
1535
|
+
const kept = new Set(now.map((mark) => mark.key));
|
|
1536
|
+
const gone = onScreen(before.filter((key) => !kept.has(key)));
|
|
1393
1537
|
hovered = { ...hovered, marks: now.map((mark) => mark.key) };
|
|
1394
1538
|
for (const { key } of gone) markElement(key)?.classList.remove("ec-hot");
|
|
1395
1539
|
for (const { key } of now) if (!had.has(key)) markElement(key)?.classList.add("ec-hot");
|
|
1396
1540
|
runner.leave(before);
|
|
1397
|
-
runner.hover(now.map(({ input }) => input));
|
|
1541
|
+
if (effects) runner.hover(now.map(({ input }) => input));
|
|
1398
1542
|
gone.forEach(({ input }, index) => events.emit("leave", { ...input, batch: { index, count: gone.length } }));
|
|
1399
1543
|
const count = now.length;
|
|
1400
1544
|
now.forEach(({ key, input }, index) => {
|
|
@@ -1407,6 +1551,9 @@ function chartHover(options) {
|
|
|
1407
1551
|
},
|
|
1408
1552
|
leave: leave2,
|
|
1409
1553
|
destroy() {
|
|
1554
|
+
destroyed = true;
|
|
1555
|
+
linked2?.gone();
|
|
1556
|
+
linked2 = void 0;
|
|
1410
1557
|
listenForEscape(false);
|
|
1411
1558
|
interaction.destroy();
|
|
1412
1559
|
keyboard.destroy();
|
|
@@ -1515,12 +1662,12 @@ function tableModel(input) {
|
|
|
1515
1662
|
const grand = input.rows.reduce((sum2, row) => sum2 + row.total, 0);
|
|
1516
1663
|
const share = (value) => input.shares ? [{ text: percent(grand > 0 ? value / grand : 0), numeric: true }] : [];
|
|
1517
1664
|
const header = (column) => ({ text: column.label, numeric: false });
|
|
1518
|
-
const
|
|
1665
|
+
const own2 = (series) => options.series && Object.prototype.hasOwnProperty.call(options.series, series) ? options.series[series] : void 0;
|
|
1519
1666
|
const blank = () => ({ text: "", numeric: false });
|
|
1520
1667
|
const headers = [
|
|
1521
1668
|
{ text: options.category ?? input.category ?? "Category", numeric: false },
|
|
1522
1669
|
...first.map(header),
|
|
1523
|
-
...input.series.map((series) => ({ text:
|
|
1670
|
+
...input.series.map((series) => ({ text: own2(series) ?? input.label?.(series) ?? series, numeric: true })),
|
|
1524
1671
|
...totals ? [{ text: options.total ?? "Total", numeric: true }] : [],
|
|
1525
1672
|
...input.shares ? [{ text: options.share ?? "Share", numeric: true }] : [],
|
|
1526
1673
|
...last.map(header)
|
|
@@ -1575,7 +1722,7 @@ function chartTable(svg) {
|
|
|
1575
1722
|
let wrapper;
|
|
1576
1723
|
let summary;
|
|
1577
1724
|
let table;
|
|
1578
|
-
let
|
|
1725
|
+
let caption2;
|
|
1579
1726
|
let head;
|
|
1580
1727
|
let body;
|
|
1581
1728
|
let foot;
|
|
@@ -1588,12 +1735,12 @@ function chartTable(svg) {
|
|
|
1588
1735
|
};
|
|
1589
1736
|
function build() {
|
|
1590
1737
|
table = element("table");
|
|
1591
|
-
|
|
1738
|
+
caption2 = element("caption", "ec-table-caption");
|
|
1592
1739
|
const thead = element("thead");
|
|
1593
1740
|
head = element("tr");
|
|
1594
1741
|
thead.appendChild(head);
|
|
1595
1742
|
body = element("tbody");
|
|
1596
|
-
table.append(
|
|
1743
|
+
table.append(caption2, thead, body);
|
|
1597
1744
|
return table;
|
|
1598
1745
|
}
|
|
1599
1746
|
function place(hidden2, text2) {
|
|
@@ -1622,7 +1769,7 @@ function chartTable(svg) {
|
|
|
1622
1769
|
}
|
|
1623
1770
|
function remove() {
|
|
1624
1771
|
wrapper?.remove();
|
|
1625
|
-
wrapper = summary = table =
|
|
1772
|
+
wrapper = summary = table = caption2 = head = body = foot = void 0;
|
|
1626
1773
|
rows2.clear();
|
|
1627
1774
|
drawn = "";
|
|
1628
1775
|
}
|
|
@@ -1633,7 +1780,7 @@ function chartTable(svg) {
|
|
|
1633
1780
|
return;
|
|
1634
1781
|
}
|
|
1635
1782
|
place(model.hidden, model.summary);
|
|
1636
|
-
if (
|
|
1783
|
+
if (caption2.textContent !== model.caption) caption2.textContent = model.caption;
|
|
1637
1784
|
const headers = JSON.stringify(model.headers);
|
|
1638
1785
|
if (headers !== drawn) {
|
|
1639
1786
|
drawn = headers;
|
|
@@ -1797,10 +1944,10 @@ function chartTransitions(options) {
|
|
|
1797
1944
|
});
|
|
1798
1945
|
},
|
|
1799
1946
|
supersede: () => supersede?.(),
|
|
1800
|
-
wait(settled,
|
|
1947
|
+
wait(settled, leaves2) {
|
|
1801
1948
|
return new Promise((resolve) => {
|
|
1802
1949
|
supersede = resolve;
|
|
1803
|
-
void settled.then(() => Promise.all(
|
|
1950
|
+
void settled.then(() => Promise.all(leaves2.map((leave2) => leave2.gone))).then(() => resolve());
|
|
1804
1951
|
});
|
|
1805
1952
|
},
|
|
1806
1953
|
destroy() {
|
|
@@ -1817,10 +1964,10 @@ function playUpdate(options, arrange, announce) {
|
|
|
1817
1964
|
const diff = arrange();
|
|
1818
1965
|
options.swap?.(diff);
|
|
1819
1966
|
options.hover.dropGone();
|
|
1820
|
-
const
|
|
1967
|
+
const leaves2 = diff.exiting.map((record) => record.leave);
|
|
1821
1968
|
const exited = runner.exit(diff.exiting.map(onScreen));
|
|
1822
1969
|
void exited.then(() => {
|
|
1823
|
-
for (const leave2 of
|
|
1970
|
+
for (const leave2 of leaves2) leave2.exited = true;
|
|
1824
1971
|
options.leaving.sweep();
|
|
1825
1972
|
});
|
|
1826
1973
|
events.emitEach("exit", diff.exiting, onScreen);
|
|
@@ -1830,7 +1977,7 @@ function playUpdate(options, arrange, announce) {
|
|
|
1830
1977
|
events.emitEach("enter", diff.entering, input);
|
|
1831
1978
|
announce(diff);
|
|
1832
1979
|
options.hover.sync();
|
|
1833
|
-
return
|
|
1980
|
+
return leaves2;
|
|
1834
1981
|
}
|
|
1835
1982
|
function busy(value, to, equal) {
|
|
1836
1983
|
return value.animating || !equal(value.value, to);
|
|
@@ -1841,11 +1988,18 @@ function sameFields(a, b) {
|
|
|
1841
1988
|
return keys.length === Object.keys(b).length && keys.every((key) => a[key] === b[key]);
|
|
1842
1989
|
}
|
|
1843
1990
|
function geometryChanged(from, to) {
|
|
1844
|
-
if (from.outline.d !== to.outline.d) return true;
|
|
1991
|
+
if (from.outline.d !== to.outline.d || labelsMoved(from, to)) return true;
|
|
1845
1992
|
const a = from.segments ?? [];
|
|
1846
1993
|
const b = to.segments ?? [];
|
|
1847
1994
|
return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
|
|
1848
1995
|
}
|
|
1996
|
+
function labelsMoved(from, to) {
|
|
1997
|
+
const a = from.labelBounds;
|
|
1998
|
+
const b = to.labelBounds;
|
|
1999
|
+
if (a === b) return false;
|
|
2000
|
+
if (!a || !b || a.length !== b.length) return true;
|
|
2001
|
+
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);
|
|
2002
|
+
}
|
|
1849
2003
|
|
|
1850
2004
|
// src/charts/shell/watch.ts
|
|
1851
2005
|
function watchWidth(container, clock, width, resize) {
|
|
@@ -1953,11 +2107,11 @@ function chartTooltip(svg, options) {
|
|
|
1953
2107
|
const toPx = { x: (x) => (x - view.x) * k, y: (y) => (y - view.y) * k };
|
|
1954
2108
|
const area = chart.width > 0 ? { width: chart.width, height: chart.height } : { width: view.width, height: view.height };
|
|
1955
2109
|
const size = { width: tip.offsetWidth, height: tip.offsetHeight };
|
|
1956
|
-
const
|
|
2110
|
+
const placed2 = placeTooltip(anchor(toPx, moved), size, area, moved ? placeTooltip(anchor(toPx, false), size, area).side : void 0);
|
|
1957
2111
|
const origin = layer.getBoundingClientRect();
|
|
1958
|
-
tip.style.left = `${Math.round(chart.left - origin.left +
|
|
1959
|
-
tip.style.top = `${Math.round(chart.top - origin.top +
|
|
1960
|
-
tip.setAttribute("data-side",
|
|
2112
|
+
tip.style.left = `${Math.round(chart.left - origin.left + placed2.x)}px`;
|
|
2113
|
+
tip.style.top = `${Math.round(chart.top - origin.top + placed2.y)}px`;
|
|
2114
|
+
tip.setAttribute("data-side", placed2.side);
|
|
1961
2115
|
timing(tip);
|
|
1962
2116
|
tip.classList.add("ec-tooltip-shown");
|
|
1963
2117
|
}
|
|
@@ -1976,12 +2130,12 @@ function chartTooltip(svg, options) {
|
|
|
1976
2130
|
place(row, summary, (toPx) => ({ x: toPx.x(point.x), top: toPx.y(point.top), bottom: toPx.y(point.bottom) }), false);
|
|
1977
2131
|
},
|
|
1978
2132
|
describe(element2, row) {
|
|
1979
|
-
const
|
|
2133
|
+
const own2 = options.description?.();
|
|
1980
2134
|
let content;
|
|
1981
|
-
if (
|
|
1982
|
-
else if (typeof
|
|
2135
|
+
if (own2 === false) content = void 0;
|
|
2136
|
+
else if (typeof own2 === "function") {
|
|
1983
2137
|
try {
|
|
1984
|
-
const text2 =
|
|
2138
|
+
const text2 = own2(row.datum);
|
|
1985
2139
|
content = typeof text2 === "string" && text2 !== "" ? text2 : void 0;
|
|
1986
2140
|
} catch (error) {
|
|
1987
2141
|
report(error);
|
|
@@ -2198,7 +2352,7 @@ function barChart(target, options, env2) {
|
|
|
2198
2352
|
setAttributes(ring, { transform: transform && transformAttribute(transform), visibility: void 0 });
|
|
2199
2353
|
}
|
|
2200
2354
|
function show3(record, row) {
|
|
2201
|
-
const moved = geometryChanged(record.shown.geometry, row.geometry);
|
|
2355
|
+
const moved = geometryChanged(record.shown.geometry, row.geometry) || record.shown.datum !== row.datum;
|
|
2202
2356
|
drawMark(record, row);
|
|
2203
2357
|
if (moved) runner.change(row.geometry, row.data);
|
|
2204
2358
|
if (record.key === hover.key) showTooltip(record);
|
|
@@ -2272,7 +2426,7 @@ function barChart(target, options, env2) {
|
|
|
2272
2426
|
const values = record.series.map((series) => ({ series, value: now[series] ?? 0 }));
|
|
2273
2427
|
const total2 = values.reduce((sum, v) => sum + v.value, 0);
|
|
2274
2428
|
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.label.text, values, slot: record.slot.value, text: text2 });
|
|
2429
|
+
return placeRow(frame, { key: row.key, datum: row.datum, index: row.index, category: row.label.text, values, slot: record.slot.value, text: text2 }, measure);
|
|
2276
2430
|
}
|
|
2277
2431
|
function addTick(value, opacity) {
|
|
2278
2432
|
const tick = {
|
|
@@ -2289,10 +2443,10 @@ function barChart(target, options, env2) {
|
|
|
2289
2443
|
}
|
|
2290
2444
|
}
|
|
2291
2445
|
function drawTick(tick, frame) {
|
|
2292
|
-
const
|
|
2446
|
+
const placed2 = placeTick(frame, tick.value, format(current)(tick.value));
|
|
2293
2447
|
const opacity = tick.opacity.value < 1 ? tick.opacity.value : void 0;
|
|
2294
|
-
setAttributes(tick.line, { ...
|
|
2295
|
-
placeText(tick.label,
|
|
2448
|
+
setAttributes(tick.line, { ...placed2.line, opacity });
|
|
2449
|
+
placeText(tick.label, placed2.label);
|
|
2296
2450
|
setAttributes(tick.label, { opacity });
|
|
2297
2451
|
}
|
|
2298
2452
|
function draw() {
|
|
@@ -2314,11 +2468,11 @@ function barChart(target, options, env2) {
|
|
|
2314
2468
|
tick.label.remove();
|
|
2315
2469
|
ticks.delete(tick.value);
|
|
2316
2470
|
}
|
|
2317
|
-
for (const
|
|
2318
|
-
const tick = ticks.get(
|
|
2471
|
+
for (const placed2 of laidOut.ticks) {
|
|
2472
|
+
const tick = ticks.get(placed2.value);
|
|
2319
2473
|
if (!tick) continue;
|
|
2320
|
-
setAttributes(tick.line, { ...
|
|
2321
|
-
placeText(tick.label,
|
|
2474
|
+
setAttributes(tick.line, { ...placed2.line, opacity: void 0 });
|
|
2475
|
+
placeText(tick.label, placed2.label);
|
|
2322
2476
|
tick.label.removeAttribute("opacity");
|
|
2323
2477
|
}
|
|
2324
2478
|
for (const record of order) {
|
|
@@ -2485,7 +2639,7 @@ function barChart(target, options, env2) {
|
|
|
2485
2639
|
});
|
|
2486
2640
|
hover.sync();
|
|
2487
2641
|
runner.enter(order.map(input));
|
|
2488
|
-
return {
|
|
2642
|
+
return linkable(hover.link, {
|
|
2489
2643
|
element: svg,
|
|
2490
2644
|
async update(next) {
|
|
2491
2645
|
if (destroyed) return;
|
|
@@ -2511,7 +2665,7 @@ function barChart(target, options, env2) {
|
|
|
2511
2665
|
transitions.supersede();
|
|
2512
2666
|
const swapping = swapped !== effects;
|
|
2513
2667
|
effects = swapped;
|
|
2514
|
-
const
|
|
2668
|
+
const leaves2 = playUpdate(
|
|
2515
2669
|
{
|
|
2516
2670
|
runner,
|
|
2517
2671
|
events,
|
|
@@ -2533,7 +2687,7 @@ function barChart(target, options, env2) {
|
|
|
2533
2687
|
);
|
|
2534
2688
|
if (byCategory(current) !== byCategory(previous)) for (const record of [...order, ...leaving.values()]) dirty.add(record);
|
|
2535
2689
|
const settled = transitionTo(nextLayout, motion2.mode === "off" || nextLayout.orientation !== orientation);
|
|
2536
|
-
await transitions.wait(settled,
|
|
2690
|
+
await transitions.wait(settled, leaves2);
|
|
2537
2691
|
},
|
|
2538
2692
|
on: events.on,
|
|
2539
2693
|
marks: () => order.map((record) => record.shown.geometry),
|
|
@@ -2573,7 +2727,7 @@ function barChart(target, options, env2) {
|
|
|
2573
2727
|
order = [];
|
|
2574
2728
|
svg.remove();
|
|
2575
2729
|
}
|
|
2576
|
-
};
|
|
2730
|
+
});
|
|
2577
2731
|
}
|
|
2578
2732
|
function checkOptions(options) {
|
|
2579
2733
|
checkChartOptions(options, "barChart");
|
|
@@ -2641,9 +2795,9 @@ var GAP3 = 10;
|
|
|
2641
2795
|
var LABEL_ANGLE = Math.PI / 12;
|
|
2642
2796
|
var LABEL_SIZE2 = 12.5;
|
|
2643
2797
|
var VALUE_SIZE2 = 12.5;
|
|
2644
|
-
var
|
|
2798
|
+
var ASCENT2 = 10;
|
|
2645
2799
|
var LINE = 15;
|
|
2646
|
-
var BLOCK =
|
|
2800
|
+
var BLOCK = ASCENT2 + LINE + 3;
|
|
2647
2801
|
var LABEL_SPACE = 2;
|
|
2648
2802
|
var CENTER_SIZE = 26;
|
|
2649
2803
|
var CENTER_MIN = 14;
|
|
@@ -2672,17 +2826,18 @@ function layoutDonut(input) {
|
|
|
2672
2826
|
const frame = donutFrame(input, rows2);
|
|
2673
2827
|
const total2 = rows2.reduce((sum, row) => sum + row.value, 0);
|
|
2674
2828
|
const starts = joinedStarts(rows2.map((row) => row.value));
|
|
2675
|
-
const
|
|
2829
|
+
const states = rows2.map((row, i) => {
|
|
2676
2830
|
const share = total2 > 0 ? row.value / total2 : 0;
|
|
2677
2831
|
const end = i + 1 < rows2.length && total2 > 0 ? starts[i + 1] : total2 > 0 ? 1 : 0;
|
|
2678
|
-
return
|
|
2832
|
+
return { ...row, series: input.encoding.series, share, start: starts[i] * TAU, end: end * TAU };
|
|
2679
2833
|
});
|
|
2834
|
+
const labels = placeLabels(frame, states, input.measure);
|
|
2680
2835
|
const centerText2 = input.center(total2);
|
|
2681
2836
|
return {
|
|
2682
2837
|
frame,
|
|
2683
2838
|
total: total2,
|
|
2684
|
-
slices,
|
|
2685
|
-
labels
|
|
2839
|
+
slices: states.map((state, i) => placeSlice(frame, state, labels[i], input.measure)),
|
|
2840
|
+
labels,
|
|
2686
2841
|
centerText: centerText2,
|
|
2687
2842
|
center: placeCenter(frame, centerText2, input.measure)
|
|
2688
2843
|
};
|
|
@@ -2696,7 +2851,7 @@ function joinedStarts(values) {
|
|
|
2696
2851
|
return start;
|
|
2697
2852
|
});
|
|
2698
2853
|
}
|
|
2699
|
-
function placeSlice(frame, state) {
|
|
2854
|
+
function placeSlice(frame, state, label2, measure) {
|
|
2700
2855
|
const geometry = describe.arc({
|
|
2701
2856
|
key: state.key,
|
|
2702
2857
|
series: state.series,
|
|
@@ -2705,7 +2860,8 @@ function placeSlice(frame, state) {
|
|
|
2705
2860
|
inner: frame.inner,
|
|
2706
2861
|
outer: frame.outer,
|
|
2707
2862
|
start: state.start,
|
|
2708
|
-
end: state.end
|
|
2863
|
+
end: state.end,
|
|
2864
|
+
labelBounds: label2 && measure ? labelBoxes(label2, measure) : []
|
|
2709
2865
|
});
|
|
2710
2866
|
return { ...state, geometry, data: sliceData(state.datum, state.share, state.series) };
|
|
2711
2867
|
}
|
|
@@ -2714,18 +2870,18 @@ function placeLabels(frame, slices, measure) {
|
|
|
2714
2870
|
let first;
|
|
2715
2871
|
const labels = slices.map((slice, i) => {
|
|
2716
2872
|
if (slice.end - slice.start < LABEL_ANGLE - 1e-9) return void 0;
|
|
2717
|
-
const
|
|
2718
|
-
const { box } =
|
|
2873
|
+
const label2 = labelAt(frame, slice, measure);
|
|
2874
|
+
const { box } = label2;
|
|
2719
2875
|
if (box.x < 0 || box.y < 0 || box.x + box.width > frame.width || box.y + box.height > frame.height) return void 0;
|
|
2720
2876
|
if (previous && overlaps(previous, box)) return void 0;
|
|
2721
2877
|
previous = box;
|
|
2722
2878
|
first ?? (first = i);
|
|
2723
|
-
return
|
|
2879
|
+
return label2;
|
|
2724
2880
|
});
|
|
2725
2881
|
for (let i = labels.length - 1; first !== void 0 && i > first; i--) {
|
|
2726
|
-
const
|
|
2727
|
-
if (!
|
|
2728
|
-
if (!overlaps(labels[first].box,
|
|
2882
|
+
const label2 = labels[i];
|
|
2883
|
+
if (!label2) continue;
|
|
2884
|
+
if (!overlaps(labels[first].box, label2.box)) break;
|
|
2729
2885
|
labels[i] = void 0;
|
|
2730
2886
|
}
|
|
2731
2887
|
return labels;
|
|
@@ -2781,11 +2937,17 @@ function labelAt(frame, slice, measure) {
|
|
|
2781
2937
|
const top = y - BLOCK * (cos + 1) / 2;
|
|
2782
2938
|
const along = (w) => x + sin * w / 2;
|
|
2783
2939
|
return {
|
|
2784
|
-
category: { x: along(widths[0]), y: top +
|
|
2785
|
-
share: { x: along(widths[1]), y: top +
|
|
2940
|
+
category: { x: along(widths[0]), y: top + ASCENT2, anchor: "middle", text: slice.category },
|
|
2941
|
+
share: { x: along(widths[1]), y: top + ASCENT2 + LINE, anchor: "middle", text: share },
|
|
2786
2942
|
box: { x: along(width) - width / 2, y: top, width, height: BLOCK }
|
|
2787
2943
|
};
|
|
2788
2944
|
}
|
|
2945
|
+
function labelBoxes(label2, measure) {
|
|
2946
|
+
const out = [];
|
|
2947
|
+
if (label2.category.text !== "") out.push(textBox(label2.category, measure, "ec-label", LABEL_SIZE2));
|
|
2948
|
+
if (label2.share.text !== "") out.push(textBox(label2.share, measure, "ec-value", VALUE_SIZE2));
|
|
2949
|
+
return out;
|
|
2950
|
+
}
|
|
2789
2951
|
function overlaps(a, b) {
|
|
2790
2952
|
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
2953
|
}
|
|
@@ -2921,7 +3083,7 @@ function donutChart(target, options, env2) {
|
|
|
2921
3083
|
byGroup.set(group, record);
|
|
2922
3084
|
return record;
|
|
2923
3085
|
}
|
|
2924
|
-
function drawMark(record, slice,
|
|
3086
|
+
function drawMark(record, slice, label2) {
|
|
2925
3087
|
const before = record.parts[0]?.colors.color;
|
|
2926
3088
|
record.shown = slice;
|
|
2927
3089
|
const { outline: outline2 } = slice.geometry;
|
|
@@ -2934,10 +3096,10 @@ function donutChart(target, options, env2) {
|
|
|
2934
3096
|
record.parts = [{ element: record.path, d: outline2.d, colors: sliceColors, visible }];
|
|
2935
3097
|
const presence = record.presence.value;
|
|
2936
3098
|
const opacity = presence < 1 ? presence : void 0;
|
|
2937
|
-
record.drawnLabel =
|
|
3099
|
+
record.drawnLabel = label2;
|
|
2938
3100
|
for (const [text2, placement] of [
|
|
2939
|
-
[record.label,
|
|
2940
|
-
[record.share,
|
|
3101
|
+
[record.label, label2?.category],
|
|
3102
|
+
[record.share, label2?.share]
|
|
2941
3103
|
]) {
|
|
2942
3104
|
if (placement) placeText(text2, placement);
|
|
2943
3105
|
setAttributes(text2, { visibility: placement ? void 0 : "hidden", opacity });
|
|
@@ -2950,9 +3112,9 @@ function donutChart(target, options, env2) {
|
|
|
2950
3112
|
const record = key === void 0 ? void 0 : records.get(key);
|
|
2951
3113
|
focusRing.draw(record && { outline: record.shown.geometry.outline, thickness: record.shown.geometry.thickness, transform: record.handle.style.transform });
|
|
2952
3114
|
}
|
|
2953
|
-
function show3(record, slice,
|
|
2954
|
-
const moved = geometryChanged(record.shown.geometry, slice.geometry);
|
|
2955
|
-
drawMark(record, slice,
|
|
3115
|
+
function show3(record, slice, label2) {
|
|
3116
|
+
const moved = geometryChanged(record.shown.geometry, slice.geometry) || record.shown.datum !== slice.datum;
|
|
3117
|
+
drawMark(record, slice, label2);
|
|
2956
3118
|
if (moved) runner.change(slice.geometry, slice.data);
|
|
2957
3119
|
if (record.key === hover.key) showTooltip(record);
|
|
2958
3120
|
}
|
|
@@ -3052,9 +3214,9 @@ function donutChart(target, options, env2) {
|
|
|
3052
3214
|
return out;
|
|
3053
3215
|
}
|
|
3054
3216
|
function currentSlices(f) {
|
|
3055
|
-
|
|
3217
|
+
const now = [...angles()].map(([record, { start, span }]) => {
|
|
3056
3218
|
const { row } = record;
|
|
3057
|
-
const
|
|
3219
|
+
const state = {
|
|
3058
3220
|
key: row.key,
|
|
3059
3221
|
datum: row.datum,
|
|
3060
3222
|
index: row.index,
|
|
@@ -3064,9 +3226,15 @@ function donutChart(target, options, env2) {
|
|
|
3064
3226
|
share: span,
|
|
3065
3227
|
start: start * TAU2,
|
|
3066
3228
|
end: (start + span) * TAU2
|
|
3067
|
-
}
|
|
3068
|
-
return { record,
|
|
3229
|
+
};
|
|
3230
|
+
return { record, state };
|
|
3069
3231
|
});
|
|
3232
|
+
const labels = placeLabels(
|
|
3233
|
+
f,
|
|
3234
|
+
now.map(({ state }) => state),
|
|
3235
|
+
measure
|
|
3236
|
+
);
|
|
3237
|
+
return now.map(({ record, state }, i) => ({ record, slice: placeSlice(f, state, labels[i], measure), label: labels[i] }));
|
|
3070
3238
|
}
|
|
3071
3239
|
function draw() {
|
|
3072
3240
|
if (!dirty) return;
|
|
@@ -3074,12 +3242,7 @@ function donutChart(target, options, env2) {
|
|
|
3074
3242
|
const f = frame.value;
|
|
3075
3243
|
setAttributes(svg, sizeAttributes(f));
|
|
3076
3244
|
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]));
|
|
3245
|
+
for (const { record, slice, label: label2 } of slices) show3(record, slice, label2);
|
|
3083
3246
|
const total2 = slices.reduce((sum, { slice }) => sum + slice.value, 0);
|
|
3084
3247
|
drawCenter(placeCenter(f, count === void 0 ? laidOut.centerText : counting(round(total2, count)), measure));
|
|
3085
3248
|
}
|
|
@@ -3278,7 +3441,7 @@ function donutChart(target, options, env2) {
|
|
|
3278
3441
|
drawCenter(laidOut.center);
|
|
3279
3442
|
hover.sync();
|
|
3280
3443
|
runner.enter(order.map(input));
|
|
3281
|
-
return {
|
|
3444
|
+
return linkable(hover.link, {
|
|
3282
3445
|
element: svg,
|
|
3283
3446
|
async update(next) {
|
|
3284
3447
|
if (destroyed) return;
|
|
@@ -3308,7 +3471,7 @@ function donutChart(target, options, env2) {
|
|
|
3308
3471
|
transitions.supersede();
|
|
3309
3472
|
const swapping = swapped !== effects;
|
|
3310
3473
|
effects = swapped;
|
|
3311
|
-
const
|
|
3474
|
+
const leaves2 = playUpdate(
|
|
3312
3475
|
{
|
|
3313
3476
|
runner,
|
|
3314
3477
|
events,
|
|
@@ -3330,7 +3493,7 @@ function donutChart(target, options, env2) {
|
|
|
3330
3493
|
);
|
|
3331
3494
|
count = nextLayout.total === totalBefore ? void 0 : Math.max(decimals(totalBefore), decimals(nextLayout.total));
|
|
3332
3495
|
const settled = transitionTo(nextLayout, motion2.mode === "off");
|
|
3333
|
-
await transitions.wait(settled,
|
|
3496
|
+
await transitions.wait(settled, leaves2);
|
|
3334
3497
|
},
|
|
3335
3498
|
on: events.on,
|
|
3336
3499
|
marks: () => order.map((record) => record.shown.geometry),
|
|
@@ -3369,7 +3532,7 @@ function donutChart(target, options, env2) {
|
|
|
3369
3532
|
order = ring = from = [];
|
|
3370
3533
|
svg.remove();
|
|
3371
3534
|
}
|
|
3372
|
-
};
|
|
3535
|
+
});
|
|
3373
3536
|
}
|
|
3374
3537
|
function checkOptions2(options) {
|
|
3375
3538
|
checkChartOptions(options, "donutChart");
|
|
@@ -3379,8 +3542,8 @@ function checkOptions2(options) {
|
|
|
3379
3542
|
}
|
|
3380
3543
|
function valueText(slice, options) {
|
|
3381
3544
|
const formatted = format(options)(slice.value);
|
|
3382
|
-
const
|
|
3383
|
-
return slice.series === "value" &&
|
|
3545
|
+
const label2 = seriesLabel(options.seriesLabels, slice.series);
|
|
3546
|
+
return slice.series === "value" && label2 === "value" ? formatted : `${formatted} ${label2}`;
|
|
3384
3547
|
}
|
|
3385
3548
|
function namesFor(options, layout) {
|
|
3386
3549
|
return new Map(layout.slices.map((slice) => [slice.key, markLabel2(slice, options)]));
|
|
@@ -3410,9 +3573,9 @@ function centerText(options, series, total2) {
|
|
|
3410
3573
|
const formatted = format(options);
|
|
3411
3574
|
if (center === false) return "";
|
|
3412
3575
|
if (center === void 0) {
|
|
3413
|
-
const
|
|
3414
|
-
return series === "value" &&
|
|
3415
|
-
${
|
|
3576
|
+
const label2 = seriesLabel(options.seriesLabels, series);
|
|
3577
|
+
return series === "value" && label2 === "value" ? formatted(total2) : `${formatted(total2)}
|
|
3578
|
+
${label2}`;
|
|
3416
3579
|
}
|
|
3417
3580
|
try {
|
|
3418
3581
|
const text2 = center(total2, formatted);
|
|
@@ -3422,10 +3585,10 @@ ${label}`;
|
|
|
3422
3585
|
return "";
|
|
3423
3586
|
}
|
|
3424
3587
|
}
|
|
3425
|
-
function description(
|
|
3588
|
+
function description(own2, center) {
|
|
3426
3589
|
const text2 = center.split("\n").join(" ").trim();
|
|
3427
|
-
const mine =
|
|
3428
|
-
if (text2 === "") return
|
|
3590
|
+
const mine = own2?.trim();
|
|
3591
|
+
if (text2 === "") return own2;
|
|
3429
3592
|
if (!mine) return text2;
|
|
3430
3593
|
return /[.!?:;]$/.test(mine) ? `${mine} ${text2}` : `${mine}. ${text2}`;
|
|
3431
3594
|
}
|
|
@@ -3543,9 +3706,9 @@ function timeName(times, zone) {
|
|
|
3543
3706
|
function tickWording(zone) {
|
|
3544
3707
|
const formats = /* @__PURE__ */ new Map();
|
|
3545
3708
|
return (t, upTo) => {
|
|
3546
|
-
const
|
|
3709
|
+
const own2 = LEVELS.indexOf(timeLevel(t, zone));
|
|
3547
3710
|
const fields = {};
|
|
3548
|
-
for (let i = Math.min(
|
|
3711
|
+
for (let i = Math.min(own2, LEVELS.indexOf(upTo)); i <= own2; i++) Object.assign(fields, FIELDS[LEVELS[i]]);
|
|
3549
3712
|
const id = JSON.stringify(fields);
|
|
3550
3713
|
let format2 = formats.get(id);
|
|
3551
3714
|
if (!format2) formats.set(id, format2 = new Intl.DateTimeFormat(void 0, { ...fields, timeZone: zoneOption(zone) }));
|
|
@@ -3652,7 +3815,7 @@ function positions(frame) {
|
|
|
3652
3815
|
y: (value) => ySpan > 0 ? box.bottom - (value - scale.lo) / ySpan * (box.bottom - box.top) : box.bottom
|
|
3653
3816
|
};
|
|
3654
3817
|
}
|
|
3655
|
-
function placeLines(frame, rows2, series, through, time = false) {
|
|
3818
|
+
function placeLines(frame, rows2, series, through, time = false, labels) {
|
|
3656
3819
|
const first = rows2[0];
|
|
3657
3820
|
if (!first) return [];
|
|
3658
3821
|
const at = positions(frame);
|
|
@@ -3663,15 +3826,23 @@ function placeLines(frame, rows2, series, through, time = false) {
|
|
|
3663
3826
|
const share = next && next.x > end.x && through > end.x ? (through - end.x) / (next.x - end.x) : void 0;
|
|
3664
3827
|
const shown = rows2.slice(0, last + 1);
|
|
3665
3828
|
const datas = /* @__PURE__ */ new Map();
|
|
3666
|
-
const related = (
|
|
3667
|
-
const
|
|
3829
|
+
const related = (own2) => (name) => name === own2 ? void 0 : datas.get(name);
|
|
3830
|
+
const traced = series.map((name) => {
|
|
3668
3831
|
const vertices = shown.map((row) => ({ at: row.x, value: row.values[name] ?? 0 }));
|
|
3669
3832
|
if (share !== void 0) {
|
|
3670
3833
|
const from = end.values[name] ?? 0;
|
|
3671
3834
|
vertices.push({ at: through, value: from + share * ((next.values[name] ?? 0) - from) });
|
|
3672
3835
|
}
|
|
3673
|
-
|
|
3674
|
-
|
|
3836
|
+
return { name, vertices, points: vertices.map((v) => ({ x: at.x(v.at), y: at.y(v.value) })) };
|
|
3837
|
+
});
|
|
3838
|
+
const placed2 = labels ? placeEndLabels(
|
|
3839
|
+
frame,
|
|
3840
|
+
traced.map(({ name, vertices, points }) => ({ ...points[points.length - 1], text: labels.text(name, vertices[vertices.length - 1].value) }))
|
|
3841
|
+
) : [];
|
|
3842
|
+
const lines = traced.map(({ name, vertices, points }, i) => {
|
|
3843
|
+
const label2 = placed2[i];
|
|
3844
|
+
const labelBounds = labels ? label2 && label2.text !== "" ? [textBox(label2, labels.measure, "ec-value", VALUE_SIZE3)] : [] : void 0;
|
|
3845
|
+
const geometry = describe.line({ key: name, series: name, points, width: LINE_WIDTH, ...labelBounds ? { labelBounds } : {} });
|
|
3675
3846
|
let distance3 = 0;
|
|
3676
3847
|
const samples = vertices.map((v, j) => {
|
|
3677
3848
|
if (j > 0) distance3 += Math.hypot(points[j].x - points[j - 1].x, points[j].y - points[j - 1].y);
|
|
@@ -3681,7 +3852,7 @@ function placeLines(frame, rows2, series, through, time = false) {
|
|
|
3681
3852
|
const data = { datum: end.datum, samples, related: related(name) };
|
|
3682
3853
|
datas.set(name, data);
|
|
3683
3854
|
const tip = vertices[vertices.length - 1];
|
|
3684
|
-
return { series: name, geometry, data, end: { ...points[points.length - 1], value: tip.value } };
|
|
3855
|
+
return { series: name, geometry, data, end: { ...points[points.length - 1], value: tip.value }, label: label2 };
|
|
3685
3856
|
});
|
|
3686
3857
|
return lines;
|
|
3687
3858
|
}
|
|
@@ -3827,11 +3998,11 @@ function numberOf3(value, series, key) {
|
|
|
3827
3998
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
3828
3999
|
throw new RangeError(`lineChart: "${series}" for "${key}" must be a finite number, got ${show(value)}. Lines can't skip a value yet.`);
|
|
3829
4000
|
}
|
|
3830
|
-
function distinctLabels(rows2,
|
|
4001
|
+
function distinctLabels(rows2, label2) {
|
|
3831
4002
|
const shapes = /* @__PURE__ */ new Map();
|
|
3832
4003
|
for (const row of rows2) {
|
|
3833
4004
|
for (const { series, value } of row.values) {
|
|
3834
|
-
const text2 =
|
|
4005
|
+
const text2 = label2(series, value);
|
|
3835
4006
|
const shape = text2.replace(/\d/g, "0");
|
|
3836
4007
|
if (!shapes.has(shape)) shapes.set(shape, text2);
|
|
3837
4008
|
}
|
|
@@ -3958,8 +4129,8 @@ function lineChart(target, options, env2) {
|
|
|
3958
4129
|
const text2 = `${formatted(value)} ${seriesLabel(opts.seriesLabels, series)}`;
|
|
3959
4130
|
if (typeof labels !== "function") return text2;
|
|
3960
4131
|
try {
|
|
3961
|
-
const
|
|
3962
|
-
return
|
|
4132
|
+
const own2 = labels(value, series, formatted);
|
|
4133
|
+
return own2 === void 0 || own2 === null ? "" : String(own2);
|
|
3963
4134
|
} catch (error) {
|
|
3964
4135
|
if (!quiet && !labelFailures.has(labels)) {
|
|
3965
4136
|
labelFailures.add(labels);
|
|
@@ -3969,10 +4140,15 @@ function lineChart(target, options, env2) {
|
|
|
3969
4140
|
}
|
|
3970
4141
|
};
|
|
3971
4142
|
}
|
|
4143
|
+
function endLabels(given) {
|
|
4144
|
+
const label2 = labeler(current);
|
|
4145
|
+
if (!label2) return void 0;
|
|
4146
|
+
return { text: (series, value) => label2(series, round(value, given[series] ?? decimals(value))), measure };
|
|
4147
|
+
}
|
|
3972
4148
|
function placedFor(next) {
|
|
3973
4149
|
const states = next.rows.map(restState);
|
|
3974
4150
|
return {
|
|
3975
|
-
lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time).map((line) => [line.series, line])),
|
|
4151
|
+
lines: new Map(placeLines(next.frame, states, next.series, drawnThrough(next), next.time, endLabels(next.decimals)).map((line) => [line.series, line])),
|
|
3976
4152
|
points: new Map(states.flatMap((state) => placePoints(next.frame, state, next.series, next.time)).map((point) => [point.key, point]))
|
|
3977
4153
|
};
|
|
3978
4154
|
}
|
|
@@ -4005,7 +4181,7 @@ function lineChart(target, options, env2) {
|
|
|
4005
4181
|
byColumn.set(column, record);
|
|
4006
4182
|
return record;
|
|
4007
4183
|
}
|
|
4008
|
-
function createLine(series,
|
|
4184
|
+
function createLine(series, placed2, entering) {
|
|
4009
4185
|
const group = svgElement("g", { class: "ec-line", "data-key": series, "data-series": series }, linesLayer);
|
|
4010
4186
|
const body = svgElement("g", { class: "ec-body" }, group);
|
|
4011
4187
|
const record = {
|
|
@@ -4020,28 +4196,28 @@ function lineChart(target, options, env2) {
|
|
|
4020
4196
|
drawnLabel: void 0,
|
|
4021
4197
|
parts: [],
|
|
4022
4198
|
handle: svgMarkHandle(() => record),
|
|
4023
|
-
target:
|
|
4024
|
-
shown:
|
|
4199
|
+
target: placed2,
|
|
4200
|
+
shown: placed2,
|
|
4025
4201
|
presence: animated(entering ? 0 : 1, interpolateNumber, { clock, motion: motion2, onChange: changed }),
|
|
4026
4202
|
leave: void 0
|
|
4027
4203
|
};
|
|
4028
4204
|
return record;
|
|
4029
4205
|
}
|
|
4030
|
-
function createPoint(row,
|
|
4031
|
-
const group = svgElement("g", { class: "ec-point", "data-key":
|
|
4206
|
+
function createPoint(row, placed2) {
|
|
4207
|
+
const group = svgElement("g", { class: "ec-point", "data-key": placed2.key, "data-series": placed2.series }, pointsLayer);
|
|
4032
4208
|
const body = svgElement("g", { class: "ec-body" }, group);
|
|
4033
4209
|
const record = {
|
|
4034
4210
|
kind: "point",
|
|
4035
|
-
key:
|
|
4036
|
-
series:
|
|
4211
|
+
key: placed2.key,
|
|
4212
|
+
series: placed2.series,
|
|
4037
4213
|
row,
|
|
4038
4214
|
group,
|
|
4039
4215
|
body,
|
|
4040
4216
|
path: svgElement("path", { class: "ec-dot" }, body),
|
|
4041
4217
|
parts: [],
|
|
4042
4218
|
handle: svgMarkHandle(() => record),
|
|
4043
|
-
target:
|
|
4044
|
-
shown:
|
|
4219
|
+
target: placed2,
|
|
4220
|
+
shown: placed2,
|
|
4045
4221
|
hidden: void 0,
|
|
4046
4222
|
leave: void 0
|
|
4047
4223
|
};
|
|
@@ -4052,14 +4228,14 @@ function lineChart(target, options, env2) {
|
|
|
4052
4228
|
const leavingLines = () => [...leaving.values()].filter((record) => record.kind === "line");
|
|
4053
4229
|
const currentFrame = () => ({ scale: scale.value, box: box.value });
|
|
4054
4230
|
function currentRows() {
|
|
4055
|
-
const
|
|
4231
|
+
const own2 = (record) => ({ x: record.x.value, values: record.values.value });
|
|
4056
4232
|
const states = /* @__PURE__ */ new Map();
|
|
4057
4233
|
const visiting = /* @__PURE__ */ new Set();
|
|
4058
4234
|
const stateOf = (record) => {
|
|
4059
4235
|
const known = states.get(record);
|
|
4060
4236
|
if (known) return known;
|
|
4061
4237
|
const p = record.presence.value;
|
|
4062
|
-
let state =
|
|
4238
|
+
let state = own2(record);
|
|
4063
4239
|
if (record.anchor && p < 1 && !visiting.has(record)) {
|
|
4064
4240
|
visiting.add(record);
|
|
4065
4241
|
const from = stateOf(record.anchor);
|
|
@@ -4083,8 +4259,8 @@ function lineChart(target, options, env2) {
|
|
|
4083
4259
|
paintFrame(frame);
|
|
4084
4260
|
paintLines(frame, states.map((s) => s.state));
|
|
4085
4261
|
for (const { record, state } of states) {
|
|
4086
|
-
const
|
|
4087
|
-
showAll(record.points.filter(drawn).map((point) => ({ record: point, placed:
|
|
4262
|
+
const placed2 = new Map(placePoints(frame, state, record.points.map((point) => point.series), laidOut.time).map((point) => [point.key, point]));
|
|
4263
|
+
showAll(record.points.filter(drawn).map((point) => ({ record: point, placed: placed2.get(point.key) })));
|
|
4088
4264
|
}
|
|
4089
4265
|
paintColumns(frame, states);
|
|
4090
4266
|
followHover();
|
|
@@ -4116,11 +4292,11 @@ function lineChart(target, options, env2) {
|
|
|
4116
4292
|
tick.label.remove();
|
|
4117
4293
|
ticks.delete(tick.value);
|
|
4118
4294
|
}
|
|
4119
|
-
for (const
|
|
4120
|
-
const tick = ticks.get(
|
|
4295
|
+
for (const placed3 of placedTicks) {
|
|
4296
|
+
const tick = ticks.get(placed3.value);
|
|
4121
4297
|
if (!tick) continue;
|
|
4122
|
-
if (tick.line && "line" in
|
|
4123
|
-
placeText(tick.label,
|
|
4298
|
+
if (tick.line && "line" in placed3) setAttributes(tick.line, { ...placed3.line, opacity: void 0 });
|
|
4299
|
+
placeText(tick.label, placed3.label);
|
|
4124
4300
|
tick.label.removeAttribute("opacity");
|
|
4125
4301
|
}
|
|
4126
4302
|
}
|
|
@@ -4128,7 +4304,7 @@ function lineChart(target, options, env2) {
|
|
|
4128
4304
|
const { frame } = laidOut;
|
|
4129
4305
|
setAttributes(svg, sizeAttributes(frame.box));
|
|
4130
4306
|
drawnFrame = frame;
|
|
4131
|
-
const
|
|
4307
|
+
const placed2 = placedFor(laidOut);
|
|
4132
4308
|
const settle = (records, next) => {
|
|
4133
4309
|
const pairs = records.flatMap((record) => {
|
|
4134
4310
|
const to = next(record);
|
|
@@ -4138,10 +4314,10 @@ function lineChart(target, options, env2) {
|
|
|
4138
4314
|
if (!kept) for (const { record, to } of pairs) record.target = to;
|
|
4139
4315
|
showAll(pairs.map(({ record }) => ({ record, placed: record.target })));
|
|
4140
4316
|
};
|
|
4141
|
-
settle(lineOrder, (line) =>
|
|
4142
|
-
paintLabels(
|
|
4317
|
+
settle(lineOrder, (line) => placed2.lines.get(line.series));
|
|
4318
|
+
paintLabels(new Map(lineOrder.flatMap((line) => placed2.lines.has(line.series) ? [[line, placed2.lines.get(line.series)]] : [])));
|
|
4143
4319
|
const states = rowOrder.map((record) => ({ record, state: restState(record.row) }));
|
|
4144
|
-
for (const { record } of states) settle(livePoints(record), (point) =>
|
|
4320
|
+
for (const { record } of states) settle(livePoints(record), (point) => placed2.points.get(point.key));
|
|
4145
4321
|
paintColumns(frame, states);
|
|
4146
4322
|
followHover();
|
|
4147
4323
|
dirty = false;
|
|
@@ -4151,10 +4327,10 @@ function lineChart(target, options, env2) {
|
|
|
4151
4327
|
setAttributes(svg, sizeAttributes(frame.box));
|
|
4152
4328
|
const formatted = format(current);
|
|
4153
4329
|
for (const tick of yTicks.values()) {
|
|
4154
|
-
const
|
|
4330
|
+
const placed2 = placeYTick(frame, tick.value, formatted(tick.value));
|
|
4155
4331
|
const opacity = tick.opacity.value < 1 ? tick.opacity.value : void 0;
|
|
4156
|
-
setAttributes(tick.line, { ...
|
|
4157
|
-
placeText(tick.label,
|
|
4332
|
+
setAttributes(tick.line, { ...placed2.line, opacity });
|
|
4333
|
+
placeText(tick.label, placed2.label);
|
|
4158
4334
|
setAttributes(tick.label, { opacity });
|
|
4159
4335
|
}
|
|
4160
4336
|
for (const tick of xTicks.values()) {
|
|
@@ -4165,46 +4341,39 @@ function lineChart(target, options, env2) {
|
|
|
4165
4341
|
function paintLines(frame, states) {
|
|
4166
4342
|
const drawnLines = [...lineOrder, ...leavingLines()];
|
|
4167
4343
|
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];
|
|
4344
|
+
const placed2 = placeLines(frame, states, drawnLines.map((line) => line.series), drawnThrough(laidOut), laidOut.time, endLabels(counting));
|
|
4345
|
+
showAll(drawnLines.map((line, i) => ({ record: line, placed: placed2[i] })));
|
|
4346
|
+
paintLabels(new Map(drawnLines.map((line, i) => [line, placed2[i]])));
|
|
4347
|
+
}
|
|
4348
|
+
function paintLabels(ends) {
|
|
4349
|
+
for (const [line, { label: text2 }] of ends) {
|
|
4181
4350
|
if (text2) placeText(line.label, text2);
|
|
4182
4351
|
line.drawnLabel = text2 && text2.text !== "" ? text2 : void 0;
|
|
4183
4352
|
setAttributes(line.label, { visibility: line.drawnLabel ? void 0 : "hidden" });
|
|
4184
|
-
}
|
|
4353
|
+
}
|
|
4185
4354
|
}
|
|
4186
4355
|
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,
|
|
4356
|
+
const related = marks.some(({ record, placed: placed2 }) => !sameData(record.shown.data, placed2.data));
|
|
4357
|
+
for (const { record, placed: placed2 } of marks) {
|
|
4358
|
+
if (record.kind === "line") showLine(record, placed2, related);
|
|
4359
|
+
else showPoint(record, placed2, related);
|
|
4191
4360
|
}
|
|
4192
4361
|
}
|
|
4193
|
-
function showLine(record,
|
|
4194
|
-
const moved = related || geometryChanged(record.shown.geometry,
|
|
4195
|
-
record.shown =
|
|
4196
|
-
const { geometry } =
|
|
4362
|
+
function showLine(record, placed2, related) {
|
|
4363
|
+
const moved = related || geometryChanged(record.shown.geometry, placed2.geometry);
|
|
4364
|
+
record.shown = placed2;
|
|
4365
|
+
const { geometry } = placed2;
|
|
4197
4366
|
paint(record, seriesColors(colors.slot(record.series)), { visible: geometry.length >= VISIBLE2, open: { width: geometry.thickness } });
|
|
4198
4367
|
setAttributes(record.end, { cx: geometry.end.x, cy: geometry.end.y });
|
|
4199
4368
|
const presence = record.presence.value;
|
|
4200
4369
|
setAttributes(record.group, { opacity: presence < 1 ? presence : void 0 });
|
|
4201
|
-
if (moved) runner.change(geometry,
|
|
4370
|
+
if (moved) runner.change(geometry, placed2.data);
|
|
4202
4371
|
}
|
|
4203
|
-
function showPoint(record,
|
|
4204
|
-
const moved = related || geometryChanged(record.shown.geometry,
|
|
4205
|
-
record.shown =
|
|
4372
|
+
function showPoint(record, placed2, related) {
|
|
4373
|
+
const moved = related || geometryChanged(record.shown.geometry, placed2.geometry);
|
|
4374
|
+
record.shown = placed2;
|
|
4206
4375
|
paint(record, seriesColors(colors.slot(record.series)), { visible: true });
|
|
4207
|
-
if (moved) runner.change(
|
|
4376
|
+
if (moved) runner.change(placed2.geometry, placed2.data);
|
|
4208
4377
|
}
|
|
4209
4378
|
function paint(record, markColors, part) {
|
|
4210
4379
|
const before = record.parts[0];
|
|
@@ -4367,7 +4536,7 @@ function lineChart(target, options, env2) {
|
|
|
4367
4536
|
}
|
|
4368
4537
|
function arrange(next) {
|
|
4369
4538
|
laidOut = next;
|
|
4370
|
-
const
|
|
4539
|
+
const placed2 = placedFor(next);
|
|
4371
4540
|
const diff = { entering: [], exiting: [], changed: [] };
|
|
4372
4541
|
const keys = new Set(next.rows.map((row) => row.key));
|
|
4373
4542
|
const series = next.rows.length > 0 ? next.series : [];
|
|
@@ -4419,7 +4588,7 @@ function lineChart(target, options, env2) {
|
|
|
4419
4588
|
const previousLines = lineOrder;
|
|
4420
4589
|
lineOrder = series.map((name) => {
|
|
4421
4590
|
let line = lines.get(name);
|
|
4422
|
-
const target2 =
|
|
4591
|
+
const target2 = placed2.lines.get(name);
|
|
4423
4592
|
if (line) {
|
|
4424
4593
|
const values = [...stayed].some((record) => valueIn(was.get(record), name) !== valueIn(record.row, name));
|
|
4425
4594
|
if (rowsMoved || values) diff.changed.push({ record: line, from: line.shown.geometry });
|
|
@@ -4435,7 +4604,7 @@ function lineChart(target, options, env2) {
|
|
|
4435
4604
|
const old = stayed.has(record) ? was.get(record) : void 0;
|
|
4436
4605
|
const live = series.map((name) => {
|
|
4437
4606
|
const key = pointKey(name, record.key);
|
|
4438
|
-
const target2 =
|
|
4607
|
+
const target2 = placed2.points.get(key);
|
|
4439
4608
|
let point = points.get(key);
|
|
4440
4609
|
if (point) {
|
|
4441
4610
|
if (old && valueIn(old, name) !== valueIn(record.row, name)) diff.changed.push({ record: point, from: point.shown.geometry });
|
|
@@ -4470,11 +4639,11 @@ function lineChart(target, options, env2) {
|
|
|
4470
4639
|
function retarget(next, jump) {
|
|
4471
4640
|
dirty = true;
|
|
4472
4641
|
const { frame } = next;
|
|
4473
|
-
for (const [ticks,
|
|
4642
|
+
for (const [ticks, placed2, lined] of [
|
|
4474
4643
|
[yTicks, next.yTicks, true],
|
|
4475
4644
|
[xTicks, next.xTicks, false]
|
|
4476
4645
|
]) {
|
|
4477
|
-
const wanted = new Set(
|
|
4646
|
+
const wanted = new Set(placed2.map((tick) => tick.value));
|
|
4478
4647
|
for (const value of wanted) if (!ticks.has(value)) addTick(ticks, value, 0, lined);
|
|
4479
4648
|
for (const tick of ticks.values()) tick.wanted = wanted.has(tick.value);
|
|
4480
4649
|
}
|
|
@@ -4537,9 +4706,9 @@ function lineChart(target, options, env2) {
|
|
|
4537
4706
|
const next = layout(current);
|
|
4538
4707
|
const byKey = new Map(next.rows.map((row) => [row.key, row]));
|
|
4539
4708
|
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 =
|
|
4709
|
+
const placed2 = placedFor(next);
|
|
4710
|
+
for (const line of lineOrder) line.target = placed2.lines.get(line.series) ?? line.target;
|
|
4711
|
+
for (const point of points.values()) point.target = placed2.points.get(point.key) ?? point.target;
|
|
4543
4712
|
void transitionTo(next, true);
|
|
4544
4713
|
}
|
|
4545
4714
|
const unwatchWidth = watchWidth(container, clock, measuredWidth, (width) => {
|
|
@@ -4554,28 +4723,28 @@ function lineChart(target, options, env2) {
|
|
|
4554
4723
|
syncLegend();
|
|
4555
4724
|
table.render(firstTable);
|
|
4556
4725
|
{
|
|
4557
|
-
const
|
|
4726
|
+
const placed2 = placedFor(laidOut);
|
|
4558
4727
|
for (const tick of laidOut.yTicks) addTick(yTicks, tick.value, 1, true);
|
|
4559
4728
|
for (const tick of laidOut.xTicks) addTick(xTicks, tick.value, 1, false, tick.label.text);
|
|
4560
4729
|
rowOrder = laidOut.rows.map((row) => {
|
|
4561
4730
|
const record = createRow(row, false);
|
|
4562
4731
|
rows2.set(row.key, record);
|
|
4563
4732
|
record.points = laidOut.series.map((name) => {
|
|
4564
|
-
const point = createPoint(record,
|
|
4733
|
+
const point = createPoint(record, placed2.points.get(pointKey(name, row.key)));
|
|
4565
4734
|
points.set(point.key, point);
|
|
4566
4735
|
return point;
|
|
4567
4736
|
});
|
|
4568
4737
|
labelColumn(record);
|
|
4569
4738
|
return record;
|
|
4570
4739
|
});
|
|
4571
|
-
lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name,
|
|
4740
|
+
lineOrder = laidOut.rows.length > 0 ? laidOut.series.map((name) => createLine(name, placed2.lines.get(name), false)) : [];
|
|
4572
4741
|
for (const line of lineOrder) lines.set(line.series, line);
|
|
4573
4742
|
land();
|
|
4574
4743
|
}
|
|
4575
4744
|
const liveMarks = () => [...lineOrder, ...rowOrder.flatMap(livePoints)];
|
|
4576
4745
|
hover.sync();
|
|
4577
4746
|
runner.enter(liveMarks().map(input));
|
|
4578
|
-
return {
|
|
4747
|
+
return linkable(hover.link, {
|
|
4579
4748
|
element: svg,
|
|
4580
4749
|
async update(next) {
|
|
4581
4750
|
if (destroyed) return;
|
|
@@ -4602,7 +4771,7 @@ function lineChart(target, options, env2) {
|
|
|
4602
4771
|
transitions.supersede();
|
|
4603
4772
|
const swapping = swapped !== effects;
|
|
4604
4773
|
effects = swapped;
|
|
4605
|
-
const
|
|
4774
|
+
const leaves2 = playUpdate(
|
|
4606
4775
|
{
|
|
4607
4776
|
runner,
|
|
4608
4777
|
events,
|
|
@@ -4624,7 +4793,7 @@ function lineChart(target, options, env2) {
|
|
|
4624
4793
|
);
|
|
4625
4794
|
syncLegend();
|
|
4626
4795
|
const settled = transitionTo(nextLayout, motion2.mode === "off");
|
|
4627
|
-
await transitions.wait(settled,
|
|
4796
|
+
await transitions.wait(settled, leaves2);
|
|
4628
4797
|
},
|
|
4629
4798
|
reveal(x) {
|
|
4630
4799
|
if (destroyed) return;
|
|
@@ -4679,7 +4848,7 @@ function lineChart(target, options, env2) {
|
|
|
4679
4848
|
lineOrder = [];
|
|
4680
4849
|
svg.remove();
|
|
4681
4850
|
}
|
|
4682
|
-
};
|
|
4851
|
+
});
|
|
4683
4852
|
}
|
|
4684
4853
|
function restState(row) {
|
|
4685
4854
|
return { key: row.key, datum: row.datum, x: row.x, values: valuesOf2(row.values) };
|
|
@@ -5195,7 +5364,6 @@ function watchHost(doc, clock, onChanges) {
|
|
|
5195
5364
|
|
|
5196
5365
|
// src/charts/adapter/expressive.ts
|
|
5197
5366
|
var SVG_NS2 = "http://www.w3.org/2000/svg";
|
|
5198
|
-
var ONE = { index: 0, count: 1 };
|
|
5199
5367
|
var WRAPPING_ROLES = /* @__PURE__ */ new Set(["img", "image", "graphics-symbol", "graphics-object"]);
|
|
5200
5368
|
function expressive(target, options, env2) {
|
|
5201
5369
|
checkOptions3(options);
|
|
@@ -5281,11 +5449,11 @@ function expressive(target, options, env2) {
|
|
|
5281
5449
|
if (options.samples) return checkSamples(options.samples(datum, of), series === void 0 ? `"${key}"` : `"${key}" (${series})`);
|
|
5282
5450
|
return total2 === void 0 ? [] : barSamples(geometry, of, total2);
|
|
5283
5451
|
};
|
|
5284
|
-
const
|
|
5285
|
-
const related = (series) =>
|
|
5452
|
+
const own2 = /* @__PURE__ */ new Map();
|
|
5453
|
+
const related = (series) => own2.get(series) ?? relatedOf(series, key);
|
|
5286
5454
|
for (const series of ownSeries(mark)) {
|
|
5287
5455
|
const datum = (parts.find((p) => p.series === series) ?? parts[0]).datum;
|
|
5288
|
-
|
|
5456
|
+
own2.set(series, { datum, samples: samplesOf(datum, geometry.segments?.find((s) => s.series === series) ?? geometry, series), related });
|
|
5289
5457
|
}
|
|
5290
5458
|
return { ...mark, data: { datum: parts[0].datum, samples: samplesOf(parts[0].datum, geometry), related } };
|
|
5291
5459
|
});
|
|
@@ -5353,6 +5521,7 @@ function expressive(target, options, env2) {
|
|
|
5353
5521
|
let hovered;
|
|
5354
5522
|
let ringKey;
|
|
5355
5523
|
let interaction;
|
|
5524
|
+
let linked2;
|
|
5356
5525
|
let destroyed = false;
|
|
5357
5526
|
const make = (tag, attributes, parent) => {
|
|
5358
5527
|
const created = doc.createElementNS(SVG_NS2, tag);
|
|
@@ -5437,13 +5606,13 @@ function expressive(target, options, env2) {
|
|
|
5437
5606
|
}
|
|
5438
5607
|
function nameMark(record) {
|
|
5439
5608
|
if (!options.markLabel) return;
|
|
5440
|
-
const { label, parts } = record.mark;
|
|
5609
|
+
const { label: label2, parts } = record.mark;
|
|
5441
5610
|
parts.forEach((part2, index) => {
|
|
5442
|
-
const named =
|
|
5611
|
+
const named = label2 !== void 0 && index === 0;
|
|
5443
5612
|
edits.attribute(part2.element, "role", named ? "img" : null);
|
|
5444
|
-
edits.attribute(part2.element, "aria-label", named ?
|
|
5613
|
+
edits.attribute(part2.element, "aria-label", named ? label2 : null);
|
|
5445
5614
|
if (named) edits.remove(part2.element, "aria-hidden");
|
|
5446
|
-
else edits.attribute(part2.element, "aria-hidden",
|
|
5615
|
+
else edits.attribute(part2.element, "aria-hidden", label2 === void 0 ? null : "true");
|
|
5447
5616
|
});
|
|
5448
5617
|
}
|
|
5449
5618
|
function unwrapNames() {
|
|
@@ -5494,12 +5663,12 @@ function expressive(target, options, env2) {
|
|
|
5494
5663
|
},
|
|
5495
5664
|
hover(hoverTarget, from) {
|
|
5496
5665
|
const record = records.get(hoverTarget.key);
|
|
5497
|
-
if (!record || hovered
|
|
5666
|
+
if (!record || own(hovered) && hovered.keys[0] === hoverTarget.key) return;
|
|
5498
5667
|
endHover();
|
|
5499
|
-
startHover(record, from, hoverTarget.segment);
|
|
5668
|
+
startHover([record], from, hoverTarget.segment);
|
|
5500
5669
|
},
|
|
5501
5670
|
leave() {
|
|
5502
|
-
if (hovered?.source
|
|
5671
|
+
if (hovered?.source === "pointer" || hovered?.source === "touch") endHover();
|
|
5503
5672
|
}
|
|
5504
5673
|
});
|
|
5505
5674
|
}
|
|
@@ -5516,26 +5685,45 @@ function expressive(target, options, env2) {
|
|
|
5516
5685
|
}
|
|
5517
5686
|
return void 0;
|
|
5518
5687
|
}
|
|
5519
|
-
function startHover(
|
|
5520
|
-
|
|
5688
|
+
function startHover(marks, from, segment, effects2 = true) {
|
|
5689
|
+
const started = { keys: marks.map((record) => record.key), source: from, effects: effects2 };
|
|
5690
|
+
hovered = started;
|
|
5521
5691
|
applyDim();
|
|
5522
|
-
runner.hover(
|
|
5523
|
-
emit("hover", { ...input(record), batch:
|
|
5692
|
+
if (effects2) runner.hover(marks.map(input));
|
|
5693
|
+
marks.forEach((record, index) => emit("hover", { ...input(record), batch: { index, count: marks.length }, source: from, ...segment === void 0 ? {} : { segment } }));
|
|
5694
|
+
if (from !== "linked" && hovered === started) linked2?.hover(marks.map(input));
|
|
5524
5695
|
}
|
|
5525
5696
|
function endHover() {
|
|
5526
5697
|
const current = hovered;
|
|
5527
5698
|
if (!current) return;
|
|
5528
5699
|
hovered = void 0;
|
|
5529
|
-
const record = find(current.key);
|
|
5530
5700
|
applyDim();
|
|
5531
|
-
|
|
5532
|
-
if (
|
|
5701
|
+
leaveMarks(current.keys);
|
|
5702
|
+
if (own(current)) linked2?.leave();
|
|
5703
|
+
}
|
|
5704
|
+
function leaveMarks(keys) {
|
|
5705
|
+
const marks = keys.flatMap((key) => find(key) ?? []);
|
|
5706
|
+
runner.leave(keys);
|
|
5707
|
+
marks.forEach((record, index) => emit("leave", { ...input(record), batch: { index, count: marks.length } }));
|
|
5708
|
+
}
|
|
5709
|
+
function dropGone() {
|
|
5710
|
+
if (hovered === void 0) return;
|
|
5711
|
+
const keys = hovered.keys.filter((key) => records.has(key));
|
|
5712
|
+
if (keys.length === hovered.keys.length) return;
|
|
5713
|
+
if (keys.length === 0) {
|
|
5714
|
+
interaction?.clear();
|
|
5715
|
+
endHover();
|
|
5716
|
+
return;
|
|
5717
|
+
}
|
|
5718
|
+
const gone = hovered.keys.filter((key) => !records.has(key));
|
|
5719
|
+
hovered = { ...hovered, keys };
|
|
5720
|
+
leaveMarks(gone);
|
|
5533
5721
|
}
|
|
5534
5722
|
function applyDim() {
|
|
5535
5723
|
if (!dim) return;
|
|
5536
5724
|
const duration = `${motion2.duration(100, "feedback")}ms`;
|
|
5537
5725
|
for (const record of order) {
|
|
5538
|
-
const hot = hovered?.key ===
|
|
5726
|
+
const hot = hovered?.keys.includes(record.key) === true;
|
|
5539
5727
|
for (const part2 of record.mark.parts) {
|
|
5540
5728
|
edits.toggleClass(part2.element, "ec-attached", true);
|
|
5541
5729
|
edits.toggleClass(part2.element, "ec-dimmed", hovered !== void 0 && !hot);
|
|
@@ -5574,26 +5762,27 @@ function expressive(target, options, env2) {
|
|
|
5574
5762
|
const record = records.get(key);
|
|
5575
5763
|
if (!record) return;
|
|
5576
5764
|
if (!visible) {
|
|
5577
|
-
if (hovered?.source === "keyboard" && hovered.
|
|
5765
|
+
if (hovered?.source === "keyboard" && hovered.keys[0] !== key) endHover();
|
|
5578
5766
|
return;
|
|
5579
5767
|
}
|
|
5580
|
-
if (hovered
|
|
5581
|
-
hovered = {
|
|
5768
|
+
if (own(hovered) && hovered.keys[0] === key) {
|
|
5769
|
+
hovered = { ...hovered, source: "keyboard" };
|
|
5582
5770
|
return;
|
|
5583
5771
|
}
|
|
5584
5772
|
endHover();
|
|
5585
|
-
startHover(record, "keyboard");
|
|
5773
|
+
startHover([record], "keyboard");
|
|
5586
5774
|
},
|
|
5587
5775
|
blur() {
|
|
5588
5776
|
ringKey = void 0;
|
|
5589
5777
|
drawRing();
|
|
5590
5778
|
if (hovered?.source !== "keyboard") return;
|
|
5591
|
-
if (interaction?.current === hovered.
|
|
5779
|
+
if (interaction?.current === hovered.keys[0]) hovered = { ...hovered, source: "pointer" };
|
|
5592
5780
|
else endHover();
|
|
5593
5781
|
},
|
|
5594
5782
|
escape() {
|
|
5595
5783
|
if (!hovered) return false;
|
|
5596
|
-
|
|
5784
|
+
if (hovered.source === "linked" && linked2) linked2.dismiss();
|
|
5785
|
+
else endHover();
|
|
5597
5786
|
return true;
|
|
5598
5787
|
}
|
|
5599
5788
|
}) : void 0;
|
|
@@ -5692,7 +5881,27 @@ function expressive(target, options, env2) {
|
|
|
5692
5881
|
runner.enter(apply(first).entering.map(input));
|
|
5693
5882
|
keyboard?.sync();
|
|
5694
5883
|
watchMarks();
|
|
5695
|
-
|
|
5884
|
+
const link2 = {
|
|
5885
|
+
targets: () => order.map((record) => ({ key: record.key, marks: [input(record)] })),
|
|
5886
|
+
hover(keys, effects2) {
|
|
5887
|
+
endHover();
|
|
5888
|
+
const marks = keys.flatMap((key) => records.get(key) ?? []);
|
|
5889
|
+
if (marks.length > 0) startHover(marks, "linked", void 0, effects2);
|
|
5890
|
+
},
|
|
5891
|
+
unlink() {
|
|
5892
|
+
if (hovered?.source === "linked") endHover();
|
|
5893
|
+
},
|
|
5894
|
+
leave() {
|
|
5895
|
+
interaction?.clear();
|
|
5896
|
+
endHover();
|
|
5897
|
+
},
|
|
5898
|
+
listen(listener) {
|
|
5899
|
+
if (destroyed) return false;
|
|
5900
|
+
linked2 = listener;
|
|
5901
|
+
return true;
|
|
5902
|
+
}
|
|
5903
|
+
};
|
|
5904
|
+
return linkable(link2, {
|
|
5696
5905
|
refresh(next) {
|
|
5697
5906
|
if (destroyed) return;
|
|
5698
5907
|
const reading = read(next ?? source);
|
|
@@ -5700,10 +5909,7 @@ function expressive(target, options, env2) {
|
|
|
5700
5909
|
runner.interrupt();
|
|
5701
5910
|
const diff = apply(reading);
|
|
5702
5911
|
watchMarks();
|
|
5703
|
-
|
|
5704
|
-
interaction?.clear();
|
|
5705
|
-
endHover();
|
|
5706
|
-
}
|
|
5912
|
+
dropGone();
|
|
5707
5913
|
const exited = runner.exit(diff.exiting.map(input));
|
|
5708
5914
|
emitEach("exit", diff.exiting);
|
|
5709
5915
|
runner.update(diff.changed.map(({ record, from }) => ({ ...input(record), from })));
|
|
@@ -5738,6 +5944,8 @@ function expressive(target, options, env2) {
|
|
|
5738
5944
|
if (destroyed) return;
|
|
5739
5945
|
destroyed = true;
|
|
5740
5946
|
hovered = void 0;
|
|
5947
|
+
linked2?.gone();
|
|
5948
|
+
linked2 = void 0;
|
|
5741
5949
|
watching?.destroy();
|
|
5742
5950
|
runner.destroy();
|
|
5743
5951
|
unsubscribeMotion?.();
|
|
@@ -5751,7 +5959,7 @@ function expressive(target, options, env2) {
|
|
|
5751
5959
|
order = [];
|
|
5752
5960
|
owners = /* @__PURE__ */ new Map();
|
|
5753
5961
|
}
|
|
5754
|
-
};
|
|
5962
|
+
});
|
|
5755
5963
|
}
|
|
5756
5964
|
function checkOptions3(options) {
|
|
5757
5965
|
if (typeof options !== "object" || options === null) throw new TypeError("expressive needs options, with at least a key: { key: (d) => d.name }.");
|
|
@@ -5862,7 +6070,7 @@ function samplesChanged(from, to) {
|
|
|
5862
6070
|
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
6071
|
}
|
|
5864
6072
|
function geometryChanged2(from, to) {
|
|
5865
|
-
if (from.outline.d !== to.outline.d || from.thickness !== to.thickness) return true;
|
|
6073
|
+
if (from.outline.d !== to.outline.d || from.thickness !== to.thickness || labelsMoved(from, to)) return true;
|
|
5866
6074
|
const a = from.segments ?? [];
|
|
5867
6075
|
const b = to.segments ?? [];
|
|
5868
6076
|
return a.length !== b.length || a.some((segment, i) => segment.key !== b[i].key || segment.outline.d !== b[i].outline.d);
|
|
@@ -6039,7 +6247,7 @@ function fromVegaView(view, options, env2) {
|
|
|
6039
6247
|
}
|
|
6040
6248
|
observe(next.root);
|
|
6041
6249
|
}
|
|
6042
|
-
return {
|
|
6250
|
+
return linkable(portOf(attachment), {
|
|
6043
6251
|
refresh,
|
|
6044
6252
|
on: attachment.on,
|
|
6045
6253
|
marks: attachment.marks,
|
|
@@ -6052,7 +6260,7 @@ function fromVegaView(view, options, env2) {
|
|
|
6052
6260
|
stopFrame = void 0;
|
|
6053
6261
|
attachment.destroy();
|
|
6054
6262
|
}
|
|
6055
|
-
};
|
|
6263
|
+
});
|
|
6056
6264
|
}
|
|
6057
6265
|
function checkView(view) {
|
|
6058
6266
|
if (typeof view !== "object" || view === null || typeof view.renderer !== "function" || typeof view.scenegraph !== "function" || typeof view.container !== "function") {
|
|
@@ -6481,20 +6689,20 @@ function chartSwitch(target, options, env2) {
|
|
|
6481
6689
|
const drawings = [];
|
|
6482
6690
|
for (const mark of from) if (!toKeys.has(mark.key)) drawings.push(fadeMark(mark, fadeOut));
|
|
6483
6691
|
for (const mark of to) if (!fromByKey.has(mark.key)) drawings.push(fadeMark(mark, fadeIn));
|
|
6484
|
-
const id = (
|
|
6485
|
-
${
|
|
6692
|
+
const id = (label2) => `${label2.role}
|
|
6693
|
+
${label2.key}`;
|
|
6486
6694
|
const labelsA = a.chart.labels();
|
|
6487
6695
|
const labelsB = b.chart.labels();
|
|
6488
|
-
const byId = new Map(labelsA.map((
|
|
6696
|
+
const byId = new Map(labelsA.map((label2) => [id(label2), label2]));
|
|
6489
6697
|
const matched = /* @__PURE__ */ new Set();
|
|
6490
|
-
for (const
|
|
6491
|
-
const partner = byId.get(id(
|
|
6698
|
+
for (const label2 of labelsB) {
|
|
6699
|
+
const partner = byId.get(id(label2));
|
|
6492
6700
|
if (!partner) continue;
|
|
6493
|
-
matched.add(id(
|
|
6494
|
-
drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(
|
|
6701
|
+
matched.add(id(label2));
|
|
6702
|
+
drawings.push(moveLabel(copyLabel(partner, toA), copyLabel(label2, toB)));
|
|
6495
6703
|
}
|
|
6496
|
-
for (const
|
|
6497
|
-
for (const
|
|
6704
|
+
for (const label2 of labelsA) if (!matched.has(id(label2))) drawings.push(fadeLabel(copyLabel(label2, toA), fadeOut));
|
|
6705
|
+
for (const label2 of labelsB) if (!byId.has(id(label2))) drawings.push(fadeLabel(copyLabel(label2, toB), fadeIn));
|
|
6498
6706
|
drawings.push((s) => {
|
|
6499
6707
|
setOpacity(a.container, 1 - clamp(s / OUT_BY));
|
|
6500
6708
|
setOpacity(b.container, clamp((s - HALF) / (1 - HALF)));
|
|
@@ -6519,12 +6727,12 @@ ${label.key}`;
|
|
|
6519
6727
|
svgLayer(group).path(mark.outline.d, mark.outline.closed ? { fill: "mark" } : { stroke: "mark", width: mark.thickness });
|
|
6520
6728
|
return (s) => setAttributes(group, { opacity: opacity(s) });
|
|
6521
6729
|
}
|
|
6522
|
-
function copyLabel(
|
|
6523
|
-
const text2 =
|
|
6730
|
+
function copyLabel(label2, m) {
|
|
6731
|
+
const text2 = label2.element.cloneNode(true);
|
|
6524
6732
|
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":
|
|
6733
|
+
text2.textContent = label2.text;
|
|
6734
|
+
const at = matrix.apply(m, label2);
|
|
6735
|
+
setAttributes(text2, { x: at.x, y: at.y, "text-anchor": label2.anchor });
|
|
6528
6736
|
labelsLayer.appendChild(text2);
|
|
6529
6737
|
return { text: text2, at };
|
|
6530
6738
|
}
|
|
@@ -6615,8 +6823,8 @@ function moveLabel(a, b) {
|
|
|
6615
6823
|
setAttributes(b.text, { x, y, visibility: second ? void 0 : "hidden" });
|
|
6616
6824
|
};
|
|
6617
6825
|
}
|
|
6618
|
-
function fadeLabel(
|
|
6619
|
-
return (s) => setAttributes(
|
|
6826
|
+
function fadeLabel(label2, opacity) {
|
|
6827
|
+
return (s) => setAttributes(label2.text, { opacity: opacity(s) });
|
|
6620
6828
|
}
|
|
6621
6829
|
var fadeOut = (s) => 1 - clamp(s / HALF);
|
|
6622
6830
|
var fadeIn = (s) => clamp((s - HALF) / (1 - HALF));
|
|
@@ -6710,10 +6918,10 @@ function motionSwitch(target, motion2, options = {}) {
|
|
|
6710
6918
|
root.setAttribute("role", "group");
|
|
6711
6919
|
root.setAttribute("aria-labelledby", `${id}-label`);
|
|
6712
6920
|
root.setAttribute("aria-describedby", `${id}-hint`);
|
|
6713
|
-
const
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6921
|
+
const label2 = root.appendChild(doc.createElement("span"));
|
|
6922
|
+
label2.className = "ec-motion-label";
|
|
6923
|
+
label2.id = `${id}-label`;
|
|
6924
|
+
label2.textContent = options.label ?? "Motion";
|
|
6717
6925
|
const modes = root.appendChild(doc.createElement("span"));
|
|
6718
6926
|
modes.className = "ec-motion-modes";
|
|
6719
6927
|
const buttons = MODES2.map((mode) => {
|
|
@@ -6781,8 +6989,8 @@ function checkMotion(motion2) {
|
|
|
6781
6989
|
}
|
|
6782
6990
|
}
|
|
6783
6991
|
function checkOptions5(options) {
|
|
6784
|
-
const { label, labels, hints, persist } = options;
|
|
6785
|
-
if (
|
|
6992
|
+
const { label: label2, labels, hints, persist } = options;
|
|
6993
|
+
if (label2 !== void 0 && typeof label2 !== "string") throw new TypeError(`motionSwitch: label must be a string, got ${typeof label2}.`);
|
|
6786
6994
|
for (const [name, texts] of [["labels", labels], ["hints", hints]]) {
|
|
6787
6995
|
if (texts === void 0) continue;
|
|
6788
6996
|
for (const [key, text2] of Object.entries(texts)) {
|
|
@@ -6879,6 +7087,7 @@ var gaits = { roll, step, slide };
|
|
|
6879
7087
|
// src/effects/travel.ts
|
|
6880
7088
|
var SPEED = 360;
|
|
6881
7089
|
var SHORTEST = 260;
|
|
7090
|
+
var LONGEST2 = 4e3;
|
|
6882
7091
|
var MIN_WALK = 0.5;
|
|
6883
7092
|
var FIT = 0.85;
|
|
6884
7093
|
var MIN_SMOOTHING = 2;
|
|
@@ -6968,7 +7177,7 @@ function trip(walk, icon, scale, options) {
|
|
|
6968
7177
|
icon,
|
|
6969
7178
|
size: icon.size * scale,
|
|
6970
7179
|
span,
|
|
6971
|
-
duration: Math.max(SHORTEST, span / SPEED * 1e3) * (gait.pace ?? 1),
|
|
7180
|
+
duration: Math.min(LONGEST2, Math.max(SHORTEST, span / SPEED * 1e3) * (gait.pace ?? 1)),
|
|
6972
7181
|
gait,
|
|
6973
7182
|
transform(progress) {
|
|
6974
7183
|
const distance3 = behind + progress * span;
|
|
@@ -7190,12 +7399,238 @@ function checkOptions10(options) {
|
|
|
7190
7399
|
}
|
|
7191
7400
|
}
|
|
7192
7401
|
|
|
7193
|
-
// src/effects/
|
|
7402
|
+
// src/effects/trace.ts
|
|
7403
|
+
var DURATION5 = 500;
|
|
7404
|
+
var WIDTH3 = 3;
|
|
7405
|
+
var OPACITY3 = 0.5;
|
|
7194
7406
|
var MIN_WALK2 = 0.5;
|
|
7407
|
+
function trace(options = {}) {
|
|
7408
|
+
checkOptions11(options);
|
|
7409
|
+
const duration = options.duration ?? DURATION5;
|
|
7410
|
+
const paint = { stroke: options.color ?? "mark", width: options.width ?? WIDTH3, opacity: options.opacity ?? OPACITY3, linecap: "round" };
|
|
7411
|
+
const stroke2 = (mark, ctx) => {
|
|
7412
|
+
let current = mark;
|
|
7413
|
+
let progress = 0;
|
|
7414
|
+
let path;
|
|
7415
|
+
const draw = () => {
|
|
7416
|
+
if (!(current.length >= MIN_WALK2)) {
|
|
7417
|
+
path?.remove();
|
|
7418
|
+
path = void 0;
|
|
7419
|
+
return;
|
|
7420
|
+
}
|
|
7421
|
+
const d = current.slice(0, progress);
|
|
7422
|
+
if (path) path.update(d);
|
|
7423
|
+
else path = ctx.layer.path(d, paint);
|
|
7424
|
+
};
|
|
7425
|
+
ctx.onChange((next) => {
|
|
7426
|
+
current = next;
|
|
7427
|
+
draw();
|
|
7428
|
+
});
|
|
7429
|
+
draw();
|
|
7430
|
+
return (p) => {
|
|
7431
|
+
progress = p;
|
|
7432
|
+
draw();
|
|
7433
|
+
};
|
|
7434
|
+
};
|
|
7435
|
+
return {
|
|
7436
|
+
kind: "geometry",
|
|
7437
|
+
async run(mark, ctx) {
|
|
7438
|
+
if (ctx.signal.aborted) return;
|
|
7439
|
+
const show3 = stroke2(mark, ctx);
|
|
7440
|
+
if (!(mark.length >= MIN_WALK2)) {
|
|
7441
|
+
show3(1);
|
|
7442
|
+
return;
|
|
7443
|
+
}
|
|
7444
|
+
await ctx.tween({ duration, timing: "effect", ease: easeInOutCubic, update: show3 }).finished;
|
|
7445
|
+
},
|
|
7446
|
+
end(mark, ctx) {
|
|
7447
|
+
stroke2(mark, ctx)(1);
|
|
7448
|
+
},
|
|
7449
|
+
clear() {
|
|
7450
|
+
}
|
|
7451
|
+
};
|
|
7452
|
+
}
|
|
7453
|
+
function checkOptions11(options) {
|
|
7454
|
+
const { color, width, opacity, duration } = options;
|
|
7455
|
+
if (color !== void 0 && (typeof color !== "string" || color === "")) {
|
|
7456
|
+
throw new RangeError(`trace: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
7457
|
+
}
|
|
7458
|
+
if (width !== void 0 && !(typeof width === "number" && width >= 0 && Number.isFinite(width))) {
|
|
7459
|
+
throw new RangeError(`trace: width must be 0 px or more, got ${String(width)}.`);
|
|
7460
|
+
}
|
|
7461
|
+
if (opacity !== void 0 && !(typeof opacity === "number" && opacity >= 0 && opacity <= 1)) {
|
|
7462
|
+
throw new RangeError(`trace: opacity must be from 0 to 1, got ${String(opacity)}.`);
|
|
7463
|
+
}
|
|
7464
|
+
if (duration !== void 0 && !(typeof duration === "number" && duration >= 0 && Number.isFinite(duration))) {
|
|
7465
|
+
throw new RangeError(`trace: duration must be 0 ms or more, got ${String(duration)}.`);
|
|
7466
|
+
}
|
|
7467
|
+
}
|
|
7468
|
+
|
|
7469
|
+
// src/effects/caption.ts
|
|
7470
|
+
var PAST_END = 10;
|
|
7471
|
+
var PAST_LABEL = 6;
|
|
7472
|
+
var RISE = 8;
|
|
7473
|
+
var TEXT = 12.5;
|
|
7474
|
+
var CENTRE4 = 0.36;
|
|
7475
|
+
var HANG = 0.8;
|
|
7476
|
+
function captionPlace(mark) {
|
|
7477
|
+
const boxes = mark.labelBounds ?? [];
|
|
7478
|
+
const heading2 = mark.angle(1);
|
|
7479
|
+
const along = farthest(mark.end, heading2, boxes);
|
|
7480
|
+
if (along === void 0 && boxes.length > 0) {
|
|
7481
|
+
const up = mark.angle(0.5) - Math.PI / 2;
|
|
7482
|
+
const out = farthest(mark.center, up, boxes);
|
|
7483
|
+
if (out !== void 0) return placed(mark.center, up, out);
|
|
7484
|
+
}
|
|
7485
|
+
return placed(mark.end, heading2, Math.max(PAST_END, along ?? -Infinity));
|
|
7486
|
+
}
|
|
7487
|
+
function placed(from, toward, distance3) {
|
|
7488
|
+
const cos = Math.cos(toward);
|
|
7489
|
+
const sin = Math.sin(toward);
|
|
7490
|
+
const point = offset(from, toward, distance3);
|
|
7491
|
+
const drop = TEXT * (sin < 0 ? CENTRE4 * (1 + sin) : CENTRE4 + (HANG - CENTRE4) * sin);
|
|
7492
|
+
const anchor = Math.abs(cos) <= Math.SQRT1_2 + 1e-9 ? "middle" : cos > 0 ? "start" : "end";
|
|
7493
|
+
return { at: { x: point.x, y: point.y + drop }, anchor, toward };
|
|
7494
|
+
}
|
|
7495
|
+
function farthest(from, toward, boxes) {
|
|
7496
|
+
const cos = Math.cos(toward);
|
|
7497
|
+
const sin = Math.sin(toward);
|
|
7498
|
+
let exit;
|
|
7499
|
+
for (const { x, y, width, height } of boxes) {
|
|
7500
|
+
const grown = { x: x - PAST_LABEL, y: y - PAST_LABEL, width: width + 2 * PAST_LABEL, height: height + 2 * PAST_LABEL };
|
|
7501
|
+
const leaving = leaves(from, cos, sin, grown);
|
|
7502
|
+
if (leaving !== void 0) exit = Math.max(exit ?? leaving, leaving);
|
|
7503
|
+
}
|
|
7504
|
+
return exit;
|
|
7505
|
+
}
|
|
7506
|
+
function leaves(from, cos, sin, box) {
|
|
7507
|
+
let near = 0;
|
|
7508
|
+
let far = Infinity;
|
|
7509
|
+
for (const [origin, step2, lo, hi] of [
|
|
7510
|
+
[from.x, cos, box.x, box.x + box.width],
|
|
7511
|
+
[from.y, sin, box.y, box.y + box.height]
|
|
7512
|
+
]) {
|
|
7513
|
+
if (Math.abs(step2) < 1e-12) {
|
|
7514
|
+
if (origin < lo || origin > hi) return void 0;
|
|
7515
|
+
continue;
|
|
7516
|
+
}
|
|
7517
|
+
const a = (lo - origin) / step2;
|
|
7518
|
+
const b = (hi - origin) / step2;
|
|
7519
|
+
near = Math.max(near, Math.min(a, b));
|
|
7520
|
+
far = Math.min(far, Math.max(a, b));
|
|
7521
|
+
}
|
|
7522
|
+
return far >= near ? far : void 0;
|
|
7523
|
+
}
|
|
7524
|
+
function caption(mark, data, ctx, color, words) {
|
|
7525
|
+
let current = mark;
|
|
7526
|
+
let content = words(mark, data) ?? "";
|
|
7527
|
+
let latest = data;
|
|
7528
|
+
let progress = 0;
|
|
7529
|
+
let handle;
|
|
7530
|
+
const draw = () => {
|
|
7531
|
+
if (content === "") {
|
|
7532
|
+
handle?.remove();
|
|
7533
|
+
handle = void 0;
|
|
7534
|
+
return;
|
|
7535
|
+
}
|
|
7536
|
+
const { at, anchor, toward } = captionPlace(current);
|
|
7537
|
+
const style = { at: offset(at, toward - Math.PI / 2, -RISE * (1 - progress)), anchor, color, opacity: progress };
|
|
7538
|
+
if (handle) handle.update(style, content);
|
|
7539
|
+
else handle = ctx.layer.text(content, style);
|
|
7540
|
+
};
|
|
7541
|
+
ctx.onChange((next, nextData) => {
|
|
7542
|
+
current = next;
|
|
7543
|
+
latest = nextData ?? latest;
|
|
7544
|
+
content = words(current, latest) ?? "";
|
|
7545
|
+
draw();
|
|
7546
|
+
});
|
|
7547
|
+
draw();
|
|
7548
|
+
return (p) => {
|
|
7549
|
+
progress = p;
|
|
7550
|
+
draw();
|
|
7551
|
+
};
|
|
7552
|
+
}
|
|
7553
|
+
|
|
7554
|
+
// src/effects/delta.ts
|
|
7555
|
+
var DURATION6 = 400;
|
|
7195
7556
|
var TIE = 1e-9;
|
|
7557
|
+
var lastSample = (data) => {
|
|
7558
|
+
const { samples } = data;
|
|
7559
|
+
return samples[samples.length - 1]?.value ?? Number.NaN;
|
|
7560
|
+
};
|
|
7561
|
+
var wording;
|
|
7562
|
+
var signed = (change) => {
|
|
7563
|
+
wording ?? (wording = new Intl.NumberFormat(void 0, { signDisplay: "always", maximumFractionDigits: 2 }));
|
|
7564
|
+
return wording.format(change);
|
|
7565
|
+
};
|
|
7566
|
+
function delta(options = {}) {
|
|
7567
|
+
checkOptions12(options);
|
|
7568
|
+
const value = options.value ?? lastSample;
|
|
7569
|
+
const format2 = options.format ?? signed;
|
|
7570
|
+
const color = options.color ?? "text";
|
|
7571
|
+
const words = (data) => {
|
|
7572
|
+
if (!data.previous) return void 0;
|
|
7573
|
+
const now = value(data);
|
|
7574
|
+
const before = value(data.previous);
|
|
7575
|
+
const change = now - before;
|
|
7576
|
+
if (!Number.isFinite(change) || Math.abs(change) <= TIE * Math.max(Math.abs(now), Math.abs(before))) return void 0;
|
|
7577
|
+
return format2(change);
|
|
7578
|
+
};
|
|
7579
|
+
return {
|
|
7580
|
+
kind: "data",
|
|
7581
|
+
run: async (mark, data, ctx) => {
|
|
7582
|
+
if (ctx.signal.aborted) return;
|
|
7583
|
+
const text2 = words(data);
|
|
7584
|
+
if (text2 === void 0 || text2 === "") return;
|
|
7585
|
+
const show3 = caption(mark, data, ctx, color, () => text2);
|
|
7586
|
+
await ctx.tween({ duration: DURATION6, timing: "effect", update: show3 }).finished;
|
|
7587
|
+
},
|
|
7588
|
+
end: (mark, data, ctx) => {
|
|
7589
|
+
const text2 = words(data);
|
|
7590
|
+
if (text2 !== void 0 && text2 !== "") caption(mark, data, ctx, color, () => text2)(1);
|
|
7591
|
+
},
|
|
7592
|
+
clear() {
|
|
7593
|
+
}
|
|
7594
|
+
};
|
|
7595
|
+
}
|
|
7596
|
+
function checkOptions12(options) {
|
|
7597
|
+
const { value, format: format2, color } = options;
|
|
7598
|
+
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}.`);
|
|
7599
|
+
if (format2 !== void 0 && typeof format2 !== "function") throw new TypeError(`delta: format must be a function that words the change, got ${typeof format2}.`);
|
|
7600
|
+
if (color !== void 0 && (typeof color !== "string" || color === "")) {
|
|
7601
|
+
throw new RangeError(`delta: color must be a theme token or a CSS colour, got ${JSON.stringify(color) ?? String(color)}.`);
|
|
7602
|
+
}
|
|
7603
|
+
}
|
|
7604
|
+
|
|
7605
|
+
// src/effects/label.ts
|
|
7606
|
+
var DURATION7 = 400;
|
|
7607
|
+
function label(text2, options = {}) {
|
|
7608
|
+
if (typeof text2 !== "function") throw new TypeError(`label needs a function that returns the text from the mark's data, got ${typeof text2}.`);
|
|
7609
|
+
const { color = "text" } = options;
|
|
7610
|
+
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)}.`);
|
|
7611
|
+
const words = (mark, data) => {
|
|
7612
|
+
const said = text2(data, mark);
|
|
7613
|
+
return said === void 0 || said === null ? void 0 : String(said);
|
|
7614
|
+
};
|
|
7615
|
+
return {
|
|
7616
|
+
kind: "data",
|
|
7617
|
+
run: async (mark, data, ctx) => {
|
|
7618
|
+
if (ctx.signal.aborted) return;
|
|
7619
|
+
const show3 = caption(mark, data, ctx, color, words);
|
|
7620
|
+
await ctx.tween({ duration: DURATION7, timing: "effect", update: show3 }).finished;
|
|
7621
|
+
},
|
|
7622
|
+
end: (mark, data, ctx) => caption(mark, data, ctx, color, words)(1),
|
|
7623
|
+
clear() {
|
|
7624
|
+
}
|
|
7625
|
+
};
|
|
7626
|
+
}
|
|
7627
|
+
|
|
7628
|
+
// src/effects/threshold.ts
|
|
7629
|
+
var MIN_WALK3 = 0.5;
|
|
7630
|
+
var TIE2 = 1e-9;
|
|
7196
7631
|
var WHENS = ["below", "above"];
|
|
7197
7632
|
function threshold(options) {
|
|
7198
|
-
|
|
7633
|
+
checkOptions13(options);
|
|
7199
7634
|
const { compareTo } = options;
|
|
7200
7635
|
const when = options.when ?? "below";
|
|
7201
7636
|
const color = options.color ?? "negative";
|
|
@@ -7203,7 +7638,7 @@ function threshold(options) {
|
|
|
7203
7638
|
const paths = [];
|
|
7204
7639
|
let latest = data;
|
|
7205
7640
|
const draw = (current) => {
|
|
7206
|
-
const parts = current.length >=
|
|
7641
|
+
const parts = current.length >= MIN_WALK3 ? runs(latest.samples, reference(compareTo, latest), when) : [];
|
|
7207
7642
|
const paint = { stroke: color, width: current.thickness, linecap: "butt" };
|
|
7208
7643
|
parts.forEach(([t0, t1], i) => {
|
|
7209
7644
|
const d = current.slice(t0, t1);
|
|
@@ -7266,7 +7701,7 @@ function runs(samples, ref, when) {
|
|
|
7266
7701
|
const level = ref.valueAt(u);
|
|
7267
7702
|
if (level === void 0 || !Number.isFinite(level) || !Number.isFinite(value) || !Number.isFinite(t)) return { t, past: void 0 };
|
|
7268
7703
|
const past = sign * (level - value);
|
|
7269
|
-
return { t, past: Math.abs(past) <=
|
|
7704
|
+
return { t, past: Math.abs(past) <= TIE2 * Math.max(Math.abs(level), Math.abs(value)) ? 0 : past };
|
|
7270
7705
|
};
|
|
7271
7706
|
const stations = [];
|
|
7272
7707
|
samples.forEach((sample, i) => {
|
|
@@ -7314,7 +7749,7 @@ function firstAbove(values, x) {
|
|
|
7314
7749
|
}
|
|
7315
7750
|
return lo;
|
|
7316
7751
|
}
|
|
7317
|
-
function
|
|
7752
|
+
function checkOptions13(options) {
|
|
7318
7753
|
const { compareTo, when, color } = options ?? {};
|
|
7319
7754
|
if (!(typeof compareTo === "string" ? compareTo !== "" : typeof compareTo === "number" && Number.isFinite(compareTo))) {
|
|
7320
7755
|
throw new RangeError(`threshold: compareTo must be a finite number or a series name, got ${show2(compareTo)}.`);
|
|
@@ -7327,11 +7762,11 @@ function checkOptions11(options) {
|
|
|
7327
7762
|
var show2 = (value) => typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
7328
7763
|
|
|
7329
7764
|
// src/effects/morph.ts
|
|
7330
|
-
var
|
|
7765
|
+
var DURATION8 = 950;
|
|
7331
7766
|
var POINTS = 160;
|
|
7332
7767
|
var ALIGNS = ["unroll", "drop"];
|
|
7333
7768
|
function morph(options = {}) {
|
|
7334
|
-
|
|
7769
|
+
checkOptions14(options);
|
|
7335
7770
|
const points = options?.points ?? POINTS;
|
|
7336
7771
|
const align = options?.align ?? "unroll";
|
|
7337
7772
|
return {
|
|
@@ -7347,7 +7782,7 @@ function morph(options = {}) {
|
|
|
7347
7782
|
const begun = unease(start);
|
|
7348
7783
|
let running;
|
|
7349
7784
|
running = ctx.tween({
|
|
7350
|
-
duration:
|
|
7785
|
+
duration: DURATION8,
|
|
7351
7786
|
timing: "transition",
|
|
7352
7787
|
ease: linear,
|
|
7353
7788
|
update: (k) => {
|
|
@@ -7435,7 +7870,7 @@ function turn(from, to, points) {
|
|
|
7435
7870
|
function startOf(start) {
|
|
7436
7871
|
return typeof start === "number" && start > 0 ? Math.min(1, start) : 0;
|
|
7437
7872
|
}
|
|
7438
|
-
function
|
|
7873
|
+
function checkOptions14(options) {
|
|
7439
7874
|
const { points, align } = options ?? {};
|
|
7440
7875
|
if (points !== void 0 && !(Number.isInteger(points) && points >= 4 && points % 4 === 0)) {
|
|
7441
7876
|
throw new RangeError(`morph: points must be a whole multiple of 4, got ${String(points)}.`);
|
|
@@ -7629,9 +8064,9 @@ var ATTRIBUTE = /([^\s=/<>]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'<>]+)))?/g;
|
|
|
7629
8064
|
var COLOR = /^(?:#[0-9a-fA-F]{3,8}|[a-zA-Z][a-zA-Z0-9-]*|(?:rgba?|hsla?)\([\d\s.,%+\-/]*\))$/;
|
|
7630
8065
|
function iconFromSvg(markup, spec) {
|
|
7631
8066
|
if (typeof markup !== "string") throw new TypeError("iconFromSvg needs SVG markup as a string.");
|
|
7632
|
-
const
|
|
8067
|
+
const label2 = typeof spec?.name === "string" ? `"${spec.name}"` : "an icon";
|
|
7633
8068
|
const fail = (problem) => {
|
|
7634
|
-
throw new RangeError(`iconFromSvg: ${
|
|
8069
|
+
throw new RangeError(`iconFromSvg: ${label2} ${problem}.`);
|
|
7635
8070
|
};
|
|
7636
8071
|
let box;
|
|
7637
8072
|
let scale = 1;
|
|
@@ -7904,7 +8339,7 @@ function configure(options) {
|
|
|
7904
8339
|
}
|
|
7905
8340
|
|
|
7906
8341
|
// src/index.ts
|
|
7907
|
-
var VERSION = "0.
|
|
8342
|
+
var VERSION = "0.2.0";
|
|
7908
8343
|
var env = { presets: presetRegistry, icons: iconRegistry, motion };
|
|
7909
8344
|
function barChart2(target, options) {
|
|
7910
8345
|
return barChart(target, options, env);
|
|
@@ -7942,6 +8377,7 @@ export {
|
|
|
7942
8377
|
defineDataEffect,
|
|
7943
8378
|
defineEffect,
|
|
7944
8379
|
defineIcon,
|
|
8380
|
+
delta,
|
|
7945
8381
|
describe,
|
|
7946
8382
|
donutChart2 as donutChart,
|
|
7947
8383
|
easeInOutCubic,
|
|
@@ -7955,8 +8391,10 @@ export {
|
|
|
7955
8391
|
interpolateNumber,
|
|
7956
8392
|
interpolatePoint,
|
|
7957
8393
|
interpolateRecord,
|
|
8394
|
+
label,
|
|
7958
8395
|
lineChart2 as lineChart,
|
|
7959
8396
|
linear,
|
|
8397
|
+
link,
|
|
7960
8398
|
manualClock,
|
|
7961
8399
|
matrix,
|
|
7962
8400
|
mediaReducedMotion,
|
|
@@ -7977,6 +8415,7 @@ export {
|
|
|
7977
8415
|
sequence,
|
|
7978
8416
|
stagger,
|
|
7979
8417
|
threshold,
|
|
8418
|
+
trace,
|
|
7980
8419
|
travel,
|
|
7981
8420
|
tween,
|
|
7982
8421
|
wiggle
|