@quantumwake/terminal-ux-dashboard-components 0.1.28 → 0.1.29
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/index.cjs +21 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -656,7 +656,11 @@ function PieView({ records, groupColumn, data: presetData, style }) {
|
|
|
656
656
|
}
|
|
657
657
|
) });
|
|
658
658
|
}
|
|
659
|
-
|
|
659
|
+
var fmtClock = (d) => d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" });
|
|
660
|
+
var toDate = (x) => x instanceof Date ? x : new Date(x);
|
|
661
|
+
function LineView({ records, xColumn, yColumn, data: presetData, style, xScale = "point", xFormat, xDomain }) {
|
|
662
|
+
const timed = xScale === "time";
|
|
663
|
+
const clock = xFormat ?? fmtClock;
|
|
660
664
|
const computed = react.useMemo(() => {
|
|
661
665
|
if (presetData || !records) return [];
|
|
662
666
|
const sorted = [...records].filter((r) => r[xColumn] != null && r[yColumn] != null).sort((a, b) => {
|
|
@@ -669,7 +673,11 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
|
|
|
669
673
|
data: sorted.map((r) => ({ x: String(r[xColumn]), y: Number(r[yColumn]) || 0 }))
|
|
670
674
|
}];
|
|
671
675
|
}, [records, xColumn, yColumn, presetData]);
|
|
672
|
-
const
|
|
676
|
+
const shaped = presetData || computed;
|
|
677
|
+
const data = react.useMemo(
|
|
678
|
+
() => timed ? shaped.map((serie) => ({ ...serie, data: serie.data.map((d) => ({ ...d, x: toDate(d.x) })) })) : shaped,
|
|
679
|
+
[shaped, timed]
|
|
680
|
+
);
|
|
673
681
|
const s = withStyleDefaults(style);
|
|
674
682
|
const { frameClass, frameStyle, margin } = chartSizing(style, { top: 20, right: 20, bottom: 60, left: 60 });
|
|
675
683
|
const colorById = new Map(data.map((serie, i) => [
|
|
@@ -677,7 +685,14 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
|
|
|
677
685
|
serie.color ?? (s.seriesColors.length || data.length > 1 ? seriesColor(i, s) : "rgba(96, 165, 250, 0.9)")
|
|
678
686
|
]));
|
|
679
687
|
const longest = data.reduce((a, b) => b.data.length > a.data.length ? b : a, { id: "", data: [] });
|
|
680
|
-
const tickValues = thinTicks(longest.data.map((d) => d.x), s.maxXTicks);
|
|
688
|
+
const tickValues = timed ? void 0 : thinTicks(longest.data.map((d) => d.x), s.maxXTicks);
|
|
689
|
+
const axisBottom = (() => {
|
|
690
|
+
const base = makeAxis(style, "x", xColumn);
|
|
691
|
+
if (!timed) return { ...base, ...tickValues ? { tickValues } : {} };
|
|
692
|
+
delete base.renderTick;
|
|
693
|
+
return { ...base, tickRotation: s.xTickRotation, format: clock, ...s.maxXTicks > 0 ? { tickValues: s.maxXTicks } : {} };
|
|
694
|
+
})();
|
|
695
|
+
const nivoXScale = timed ? { type: "time", format: "native", precision: "millisecond", useUTC: false, min: xDomain?.[0] ?? "auto", max: xDomain?.[1] ?? "auto" } : { type: "point" };
|
|
681
696
|
let yScale = { type: "linear", min: "auto", max: "auto" };
|
|
682
697
|
if (s.yFromZero) {
|
|
683
698
|
const dataMax = Math.max(0, ...data.flatMap((serie) => serie.data.map((d) => Math.max(d.y ?? 0, d.hi ?? d.y ?? 0))));
|
|
@@ -708,7 +723,8 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
|
|
|
708
723
|
{
|
|
709
724
|
data,
|
|
710
725
|
margin,
|
|
711
|
-
xScale:
|
|
726
|
+
xScale: nivoXScale,
|
|
727
|
+
xFormat: timed ? (v) => clock(v) : void 0,
|
|
712
728
|
yScale,
|
|
713
729
|
curve: "monotoneX",
|
|
714
730
|
enableArea: s.areaOpacity > 0,
|
|
@@ -719,7 +735,7 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
|
|
|
719
735
|
pointBorderWidth: 2,
|
|
720
736
|
pointBorderColor: { from: "serieColor" },
|
|
721
737
|
enableGridX: false,
|
|
722
|
-
axisBottom
|
|
738
|
+
axisBottom,
|
|
723
739
|
axisLeft: makeAxis(style, "y", yColumn, { numeric: true }),
|
|
724
740
|
useMesh: true,
|
|
725
741
|
layers: ["grid", "markers", "axes", "areas", bandsLayer, linesLayer, "crosshair", "slices", "mesh", "legends"],
|