@quantumwake/terminal-ux-dashboard-components 0.1.22 → 0.1.24
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 +29 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +29 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -283,6 +283,7 @@ var DEFAULT_CHART_STYLE = {
|
|
|
283
283
|
maxXTicks: 0,
|
|
284
284
|
maxYTicks: 0,
|
|
285
285
|
areaOpacity: 0.15,
|
|
286
|
+
yFromZero: false,
|
|
286
287
|
barLabels: true,
|
|
287
288
|
seriesColors: []
|
|
288
289
|
};
|
|
@@ -652,7 +653,7 @@ function PieView({ records, groupColumn, data: presetData, style }) {
|
|
|
652
653
|
}
|
|
653
654
|
) });
|
|
654
655
|
}
|
|
655
|
-
function LineView({ records, xColumn, yColumn, data: presetData,
|
|
656
|
+
function LineView({ records, xColumn, yColumn, data: presetData, style }) {
|
|
656
657
|
const computed = react.useMemo(() => {
|
|
657
658
|
if (presetData || !records) return [];
|
|
658
659
|
const sorted = [...records].filter((r) => r[xColumn] != null && r[yColumn] != null).sort((a, b) => {
|
|
@@ -674,16 +675,28 @@ function LineView({ records, xColumn, yColumn, data: presetData, dashedIds, styl
|
|
|
674
675
|
]));
|
|
675
676
|
const longest = data.reduce((a, b) => b.data.length > a.data.length ? b : a, { id: "", data: [] });
|
|
676
677
|
const tickValues = thinTicks(longest.data.map((d) => d.x), s.maxXTicks);
|
|
677
|
-
|
|
678
|
+
let yScale = { type: "linear", min: "auto", max: "auto" };
|
|
679
|
+
if (s.yFromZero) {
|
|
680
|
+
const dataMax = Math.max(0, ...data.flatMap((serie) => serie.data.map((d) => Math.max(d.y, d.hi ?? d.y))));
|
|
681
|
+
yScale = { type: "linear", min: 0, max: niceCeil(dataMax) };
|
|
682
|
+
}
|
|
683
|
+
const bandedIds = new Set(data.filter((serie) => serie.data.some((d) => d.lo != null)).map((serie) => serie.id));
|
|
684
|
+
const bandsLayer = ({ series, yScale: yScale2, lineGenerator }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: series.map((serie) => {
|
|
685
|
+
const pts = serie.data.filter((d) => d.data.lo != null && d.data.hi != null && d.position.x != null);
|
|
686
|
+
if (pts.length < 2) return null;
|
|
687
|
+
const upper = lineGenerator(pts.map((d) => ({ x: d.position.x, y: yScale2(d.data.hi) })));
|
|
688
|
+
const lower = lineGenerator([...pts].reverse().map((d) => ({ x: d.position.x, y: yScale2(d.data.lo) })));
|
|
689
|
+
if (!upper || !lower) return null;
|
|
690
|
+
return /* @__PURE__ */ jsxRuntime.jsx("path", { d: `${upper} L ${lower.slice(1)} Z`, fill: serie.color, opacity: 0.12 }, `band-${serie.id}`);
|
|
691
|
+
}) });
|
|
678
692
|
const linesLayer = ({ series, lineGenerator }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: series.map((serie) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
679
693
|
"path",
|
|
680
694
|
{
|
|
681
695
|
d: lineGenerator(serie.data.map((d) => d.position)),
|
|
682
696
|
fill: "none",
|
|
683
697
|
stroke: serie.color,
|
|
684
|
-
strokeWidth: 2,
|
|
685
|
-
strokeLinecap: "round"
|
|
686
|
-
strokeDasharray: dashed.has(String(serie.id)) ? "1 5" : void 0
|
|
698
|
+
strokeWidth: bandedIds.has(String(serie.id)) ? 2.5 : 1.5,
|
|
699
|
+
strokeLinecap: "round"
|
|
687
700
|
},
|
|
688
701
|
serie.id
|
|
689
702
|
)) });
|
|
@@ -693,7 +706,7 @@ function LineView({ records, xColumn, yColumn, data: presetData, dashedIds, styl
|
|
|
693
706
|
data,
|
|
694
707
|
margin,
|
|
695
708
|
xScale: { type: "point" },
|
|
696
|
-
yScale
|
|
709
|
+
yScale,
|
|
697
710
|
curve: "monotoneX",
|
|
698
711
|
enableArea: s.areaOpacity > 0,
|
|
699
712
|
areaOpacity: s.areaOpacity,
|
|
@@ -706,11 +719,20 @@ function LineView({ records, xColumn, yColumn, data: presetData, dashedIds, styl
|
|
|
706
719
|
axisBottom: { ...makeAxis(style, "x", xColumn), ...tickValues ? { tickValues } : {} },
|
|
707
720
|
axisLeft: makeAxis(style, "y", yColumn, { numeric: true }),
|
|
708
721
|
useMesh: true,
|
|
709
|
-
layers: ["grid", "markers", "axes", "areas", linesLayer, "crosshair", "slices", "mesh", "legends"],
|
|
722
|
+
layers: ["grid", "markers", "axes", "areas", bandsLayer, linesLayer, "crosshair", "slices", "mesh", "legends"],
|
|
710
723
|
theme: buildNivoTheme(style)
|
|
711
724
|
}
|
|
712
725
|
) });
|
|
713
726
|
}
|
|
727
|
+
function niceCeil(v) {
|
|
728
|
+
if (v <= 0) return 1;
|
|
729
|
+
const padded = v * 1.05;
|
|
730
|
+
const mag = Math.pow(10, Math.floor(Math.log10(padded)));
|
|
731
|
+
for (const step of [1, 2, 5, 10]) {
|
|
732
|
+
if (padded <= step * mag) return step * mag;
|
|
733
|
+
}
|
|
734
|
+
return 10 * mag;
|
|
735
|
+
}
|
|
714
736
|
function SparklineView({ data, height = 56, color = "#3987e5", showValue = false, format }) {
|
|
715
737
|
const gradientId = react.useId();
|
|
716
738
|
const width = 260;
|