@tangle-network/charts 0.12.1 → 0.13.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/dist/react/index.d.ts +7 -2
- package/dist/react/index.js +41 -13
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -220,11 +220,16 @@ export declare function Meter({ used, total, format, tone, text, segments, untra
|
|
|
220
220
|
segments?: MeterSegment[];
|
|
221
221
|
untraced?: string;
|
|
222
222
|
}): import("react").JSX.Element;
|
|
223
|
-
/** A small line of one series for a row in a list (one hue; the row's label carries identity).
|
|
224
|
-
|
|
223
|
+
/** A small line of one series for a row in a list (one hue; the row's label carries identity). `max` sets the top of
|
|
224
|
+
* the scale (any positive value; the default 1 suits shares). With `label`, the line is an image with that name and
|
|
225
|
+
* hovering it reads the nearest point through `format` and `time`. */
|
|
226
|
+
export declare function Spark({ points, max, color, label, format, time }: {
|
|
225
227
|
points: [number, number][];
|
|
226
228
|
max?: number;
|
|
227
229
|
color?: string;
|
|
230
|
+
label?: string;
|
|
231
|
+
format?: (v: number) => string;
|
|
232
|
+
time?: (t: number) => string;
|
|
228
233
|
}): import("react").JSX.Element;
|
|
229
234
|
/** One bar per row on a shared time axis (who worked when): each row's bar spans its start to its end, coloured by its
|
|
230
235
|
* state; hovering a span names it, its state and its span. Times are epoch ms; `axis` labels the time axis.
|
package/dist/react/index.js
CHANGED
|
@@ -1237,7 +1237,7 @@ function Lines({ series, format = formatCompact, rows = 13, axis, marks = [], ba
|
|
|
1237
1237
|
hover !== null && /* @__PURE__ */ jsx(Tooltip, { tip: {
|
|
1238
1238
|
x: Math.min(x(hover) + 10, width - em * 14),
|
|
1239
1239
|
y: 8,
|
|
1240
|
-
title: day(hover),
|
|
1240
|
+
title: axis ? axis(hover) : day(hover),
|
|
1241
1241
|
lines: series.filter((s) => s.points.length).map((s) => {
|
|
1242
1242
|
const p = nearest(s.points, hover);
|
|
1243
1243
|
return {
|
|
@@ -1449,8 +1449,11 @@ function SegmentMeter({ segments, total, format, text, untraced }) {
|
|
|
1449
1449
|
]
|
|
1450
1450
|
});
|
|
1451
1451
|
}
|
|
1452
|
-
/** A small line of one series for a row in a list (one hue; the row's label carries identity).
|
|
1453
|
-
|
|
1452
|
+
/** A small line of one series for a row in a list (one hue; the row's label carries identity). `max` sets the top of
|
|
1453
|
+
* the scale (any positive value; the default 1 suits shares). With `label`, the line is an image with that name and
|
|
1454
|
+
* hovering it reads the nearest point through `format` and `time`. */
|
|
1455
|
+
function Spark({ points, max = 1, color = LIVE_SERIES[0], label, format = formatCompact, time }) {
|
|
1456
|
+
const [hover, setHover] = useState(null);
|
|
1454
1457
|
if (points.length < 2) return /* @__PURE__ */ jsx("span", {
|
|
1455
1458
|
className: "ov-spark-empty",
|
|
1456
1459
|
children: "collecting"
|
|
@@ -1459,18 +1462,43 @@ function Spark({ points, max = 1, color = LIVE_SERIES[0] }) {
|
|
|
1459
1462
|
const t1 = points.at(-1)[0];
|
|
1460
1463
|
const w = 160;
|
|
1461
1464
|
const h = 32;
|
|
1462
|
-
const domain =
|
|
1463
|
-
const
|
|
1464
|
-
|
|
1465
|
+
const domain = max > 0 && Number.isFinite(max) ? max : 1;
|
|
1466
|
+
const px = (t) => (t - t0) / Math.max(1, t1 - t0) * w;
|
|
1467
|
+
const py = (v) => 30 - Math.min(domain, v) / domain * 28;
|
|
1468
|
+
const d = points.map((p) => `${px(p[0])},${py(p[1])}`).join(" ");
|
|
1469
|
+
const hovered = hover === null ? null : points[hover];
|
|
1470
|
+
const reading = hovered ? `${time ? `${time(hovered[0])} · ` : ""}${format(hovered[1])}` : null;
|
|
1471
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
1465
1472
|
viewBox: `0 0 ${w} ${h}`,
|
|
1466
1473
|
className: "ov-spark",
|
|
1467
|
-
"
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
+
role: label ? "img" : void 0,
|
|
1475
|
+
"aria-label": label,
|
|
1476
|
+
"aria-hidden": label ? void 0 : true,
|
|
1477
|
+
onMouseLeave: label ? () => setHover(null) : void 0,
|
|
1478
|
+
onMouseMove: label ? (event) => {
|
|
1479
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
1480
|
+
const t = t0 + (event.clientX - box.left) / Math.max(1, box.width) * (t1 - t0);
|
|
1481
|
+
let best = 0;
|
|
1482
|
+
for (let i = 1; i < points.length; i++) if (Math.abs(points[i][0] - t) < Math.abs(points[best][0] - t)) best = i;
|
|
1483
|
+
setHover(best);
|
|
1484
|
+
} : void 0,
|
|
1485
|
+
children: [
|
|
1486
|
+
label && /* @__PURE__ */ jsx("title", { children: reading ?? label }),
|
|
1487
|
+
/* @__PURE__ */ jsx("polyline", {
|
|
1488
|
+
fill: "none",
|
|
1489
|
+
stroke: color,
|
|
1490
|
+
strokeWidth: 1.6,
|
|
1491
|
+
points: d
|
|
1492
|
+
}),
|
|
1493
|
+
hovered && /* @__PURE__ */ jsx("circle", {
|
|
1494
|
+
cx: px(hovered[0]),
|
|
1495
|
+
cy: py(hovered[1]),
|
|
1496
|
+
r: 3,
|
|
1497
|
+
fill: color,
|
|
1498
|
+
stroke: "var(--chart-live-surface, #fff)",
|
|
1499
|
+
strokeWidth: 1.5
|
|
1500
|
+
})
|
|
1501
|
+
]
|
|
1474
1502
|
});
|
|
1475
1503
|
}
|
|
1476
1504
|
/** One bar per row on a shared time axis (who worked when): each row's bar spans its start to its end, coloured by its
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/charts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Static SVG and HTML figures for benchmarks and operational timing. Draws from producer data and refuses what it cannot draw honestly.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|