@quantumwake/terminal-ux-dashboard-components 0.1.23 → 0.1.25

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 CHANGED
@@ -283,7 +283,9 @@ var DEFAULT_CHART_STYLE = {
283
283
  maxXTicks: 0,
284
284
  maxYTicks: 0,
285
285
  areaOpacity: 0.15,
286
+ yFromZero: false,
286
287
  barLabels: true,
288
+ animate: false,
287
289
  seriesColors: []
288
290
  };
289
291
  var DEFAULT_SERIES_COLORS = [
@@ -610,6 +612,7 @@ function BarView({ records, groupColumn, valueColumn, aggFn = "count", data: pre
610
612
  labelSkipWidth: 12,
611
613
  labelSkipHeight: 12,
612
614
  labelTextColor: { from: "color", modifiers: [["darker", 3]] },
615
+ animate: s.animate,
613
616
  theme: buildNivoTheme(style)
614
617
  }
615
618
  ) });
@@ -648,6 +651,7 @@ function PieView({ records, groupColumn, data: presetData, style }) {
648
651
  arcLabelsSkipAngle: 10,
649
652
  arcLabelsTextColor: { from: "color", modifiers: [["darker", 3]] },
650
653
  legends: legend ? [legend] : [],
654
+ animate: s.animate,
651
655
  theme: buildNivoTheme(style)
652
656
  }
653
657
  ) });
@@ -674,12 +678,17 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
674
678
  ]));
675
679
  const longest = data.reduce((a, b) => b.data.length > a.data.length ? b : a, { id: "", data: [] });
676
680
  const tickValues = thinTicks(longest.data.map((d) => d.x), s.maxXTicks);
681
+ let yScale = { type: "linear", min: "auto", max: "auto" };
682
+ if (s.yFromZero) {
683
+ const dataMax = Math.max(0, ...data.flatMap((serie) => serie.data.map((d) => Math.max(d.y, d.hi ?? d.y))));
684
+ yScale = { type: "linear", min: 0, max: niceCeil(dataMax) };
685
+ }
677
686
  const bandedIds = new Set(data.filter((serie) => serie.data.some((d) => d.lo != null)).map((serie) => serie.id));
678
- const bandsLayer = ({ series, yScale, lineGenerator }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: series.map((serie) => {
687
+ const bandsLayer = ({ series, yScale: yScale2, lineGenerator }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: series.map((serie) => {
679
688
  const pts = serie.data.filter((d) => d.data.lo != null && d.data.hi != null && d.position.x != null);
680
689
  if (pts.length < 2) return null;
681
- const upper = lineGenerator(pts.map((d) => ({ x: d.position.x, y: yScale(d.data.hi) })));
682
- const lower = lineGenerator([...pts].reverse().map((d) => ({ x: d.position.x, y: yScale(d.data.lo) })));
690
+ const upper = lineGenerator(pts.map((d) => ({ x: d.position.x, y: yScale2(d.data.hi) })));
691
+ const lower = lineGenerator([...pts].reverse().map((d) => ({ x: d.position.x, y: yScale2(d.data.lo) })));
683
692
  if (!upper || !lower) return null;
684
693
  return /* @__PURE__ */ jsxRuntime.jsx("path", { d: `${upper} L ${lower.slice(1)} Z`, fill: serie.color, opacity: 0.12 }, `band-${serie.id}`);
685
694
  }) });
@@ -700,7 +709,7 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
700
709
  data,
701
710
  margin,
702
711
  xScale: { type: "point" },
703
- yScale: { type: "linear", min: "auto", max: "auto" },
712
+ yScale,
704
713
  curve: "monotoneX",
705
714
  enableArea: s.areaOpacity > 0,
706
715
  areaOpacity: s.areaOpacity,
@@ -714,10 +723,20 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
714
723
  axisLeft: makeAxis(style, "y", yColumn, { numeric: true }),
715
724
  useMesh: true,
716
725
  layers: ["grid", "markers", "axes", "areas", bandsLayer, linesLayer, "crosshair", "slices", "mesh", "legends"],
726
+ animate: s.animate,
717
727
  theme: buildNivoTheme(style)
718
728
  }
719
729
  ) });
720
730
  }
731
+ function niceCeil(v) {
732
+ if (v <= 0) return 1;
733
+ const padded = v * 1.05;
734
+ const mag = Math.pow(10, Math.floor(Math.log10(padded)));
735
+ for (const step of [1, 2, 5, 10]) {
736
+ if (padded <= step * mag) return step * mag;
737
+ }
738
+ return 10 * mag;
739
+ }
721
740
  function SparklineView({ data, height = 56, color = "#3987e5", showValue = false, format }) {
722
741
  const gradientId = react.useId();
723
742
  const width = 260;
@@ -766,6 +785,7 @@ function ScatterView({ records, xColumn, yColumn, data: presetData, style }) {
766
785
  axisBottom: makeAxis(style, "x", xColumn, { numeric: true }),
767
786
  axisLeft: makeAxis(style, "y", yColumn, { numeric: true }),
768
787
  useMesh: true,
788
+ animate: s.animate,
769
789
  theme: buildNivoTheme(style)
770
790
  }
771
791
  ) });
@@ -873,6 +893,7 @@ function HeatmapView({
873
893
  borderColor: "#334155",
874
894
  labelTextColor: { from: "color", modifiers: [["darker", 3]] },
875
895
  hoverTarget: "cell",
896
+ animate: s.animate,
876
897
  theme: buildNivoTheme(style)
877
898
  }
878
899
  ) });
@@ -1027,6 +1048,7 @@ function HeatmapPlusView({
1027
1048
  borderColor: "#334155",
1028
1049
  labelTextColor: ((cell) => heatLabelColor(tAt(cell.serieId, cell.data.x))),
1029
1050
  hoverTarget: "cell",
1051
+ animate: s.animate,
1030
1052
  theme: buildNivoTheme(style)
1031
1053
  }
1032
1054
  ) });