@quantumwake/terminal-ux-dashboard-components 0.1.20 → 0.1.21

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.d.cts CHANGED
@@ -144,6 +144,9 @@ interface ChartStyle {
144
144
  height: number;
145
145
  margin: Partial<ChartMargin> | null;
146
146
  maxXTicks: number;
147
+ maxYTicks: number;
148
+ areaOpacity: number;
149
+ barLabels: boolean;
147
150
  seriesColors: string[];
148
151
  }
149
152
  declare const DEFAULT_CHART_STYLE: ChartStyle;
@@ -297,9 +300,12 @@ interface BarViewProps {
297
300
  aggFn?: string;
298
301
  /** Pre-aggregated [{group, value}] bypasses client-side aggregation. */
299
302
  data?: BarDatum[];
303
+ /** 'horizontal' lays categories on the y axis — the readable form for
304
+ * many bars with long names (labels never collide). Default vertical. */
305
+ layout?: 'vertical' | 'horizontal';
300
306
  style?: Partial<ChartStyle>;
301
307
  }
302
- declare function BarView({ records, groupColumn, valueColumn, aggFn, data: presetData, style }: BarViewProps): react.JSX.Element;
308
+ declare function BarView({ records, groupColumn, valueColumn, aggFn, data: presetData, layout, style }: BarViewProps): react.JSX.Element;
303
309
 
304
310
  interface PieDatum {
305
311
  id: string;
@@ -328,9 +334,12 @@ interface LineViewProps {
328
334
  yColumn: string;
329
335
  /** Pre-shaped Nivo line series bypasses client-side processing. */
330
336
  data?: LineSerie[];
337
+ /** Serie ids to draw dotted — the aggregate-vs-individual distinction
338
+ * (an average line reads as derived, a member line as observed). */
339
+ dashedIds?: string[];
331
340
  style?: Partial<ChartStyle>;
332
341
  }
333
- declare function LineView({ records, xColumn, yColumn, data: presetData, style }: LineViewProps): react.JSX.Element;
342
+ declare function LineView({ records, xColumn, yColumn, data: presetData, dashedIds, style }: LineViewProps): react.JSX.Element;
334
343
 
335
344
  interface SparklineViewProps {
336
345
  /** The series, oldest first. */
package/dist/index.d.ts CHANGED
@@ -144,6 +144,9 @@ interface ChartStyle {
144
144
  height: number;
145
145
  margin: Partial<ChartMargin> | null;
146
146
  maxXTicks: number;
147
+ maxYTicks: number;
148
+ areaOpacity: number;
149
+ barLabels: boolean;
147
150
  seriesColors: string[];
148
151
  }
149
152
  declare const DEFAULT_CHART_STYLE: ChartStyle;
@@ -297,9 +300,12 @@ interface BarViewProps {
297
300
  aggFn?: string;
298
301
  /** Pre-aggregated [{group, value}] bypasses client-side aggregation. */
299
302
  data?: BarDatum[];
303
+ /** 'horizontal' lays categories on the y axis — the readable form for
304
+ * many bars with long names (labels never collide). Default vertical. */
305
+ layout?: 'vertical' | 'horizontal';
300
306
  style?: Partial<ChartStyle>;
301
307
  }
302
- declare function BarView({ records, groupColumn, valueColumn, aggFn, data: presetData, style }: BarViewProps): react.JSX.Element;
308
+ declare function BarView({ records, groupColumn, valueColumn, aggFn, data: presetData, layout, style }: BarViewProps): react.JSX.Element;
303
309
 
304
310
  interface PieDatum {
305
311
  id: string;
@@ -328,9 +334,12 @@ interface LineViewProps {
328
334
  yColumn: string;
329
335
  /** Pre-shaped Nivo line series bypasses client-side processing. */
330
336
  data?: LineSerie[];
337
+ /** Serie ids to draw dotted — the aggregate-vs-individual distinction
338
+ * (an average line reads as derived, a member line as observed). */
339
+ dashedIds?: string[];
331
340
  style?: Partial<ChartStyle>;
332
341
  }
333
- declare function LineView({ records, xColumn, yColumn, data: presetData, style }: LineViewProps): react.JSX.Element;
342
+ declare function LineView({ records, xColumn, yColumn, data: presetData, dashedIds, style }: LineViewProps): react.JSX.Element;
334
343
 
335
344
  interface SparklineViewProps {
336
345
  /** The series, oldest first. */
package/dist/index.js CHANGED
@@ -273,6 +273,9 @@ var DEFAULT_CHART_STYLE = {
273
273
  height: 0,
274
274
  margin: null,
275
275
  maxXTicks: 0,
276
+ maxYTicks: 0,
277
+ areaOpacity: 0.15,
278
+ barLabels: true,
276
279
  seriesColors: []
277
280
  };
278
281
  var DEFAULT_SERIES_COLORS = [
@@ -565,9 +568,11 @@ function makeAxis(style, axis, columnName, opts2 = {}) {
565
568
  out.tickRotation = rotate;
566
569
  out.format = (v) => formatVal(v, s, numeric);
567
570
  }
571
+ const maxTicks = isX ? s.maxXTicks : s.maxYTicks;
572
+ if (numeric && maxTicks > 0) out.tickValues = maxTicks;
568
573
  return out;
569
574
  }
570
- function BarView({ records, groupColumn, valueColumn, aggFn = "count", data: presetData, style }) {
575
+ function BarView({ records, groupColumn, valueColumn, aggFn = "count", data: presetData, layout = "vertical", style }) {
571
576
  const computed = useMemo(() => {
572
577
  if (presetData || !records) return [];
573
578
  const groups = groupBy(records, groupColumn);
@@ -576,18 +581,24 @@ function BarView({ records, groupColumn, valueColumn, aggFn = "count", data: pre
576
581
  const data = presetData || computed;
577
582
  const s = withStyleDefaults(style);
578
583
  const { frameClass, frameStyle, margin } = chartSizing(style, { top: 20, right: 20, bottom: 60, left: 60 });
584
+ const horizontal = layout === "horizontal";
585
+ const plotted = horizontal ? [...data].reverse() : data;
586
+ const axisBottom = horizontal ? makeAxis(style, "x", valueColumn, { numeric: true }) : makeAxis(style, "x", groupColumn);
587
+ const axisLeft = horizontal ? makeAxis(style, "y", groupColumn) : makeAxis(style, "y", valueColumn, { numeric: true });
579
588
  return /* @__PURE__ */ jsx("div", { className: frameClass, style: frameStyle, children: /* @__PURE__ */ jsx(
580
589
  ResponsiveBar,
581
590
  {
582
- data,
591
+ data: plotted,
583
592
  keys: ["value"],
584
593
  indexBy: "group",
594
+ layout,
585
595
  margin,
586
596
  padding: 0.3,
587
597
  colors: [s.seriesColors[0] || "rgba(74, 222, 128, 0.8)"],
588
598
  borderColor: { from: "color", modifiers: [["darker", 1.6]] },
589
- axisBottom: makeAxis(style, "x", groupColumn),
590
- axisLeft: makeAxis(style, "y", valueColumn, { numeric: true }),
599
+ axisBottom,
600
+ axisLeft,
601
+ enableLabel: s.barLabels,
591
602
  labelSkipWidth: 12,
592
603
  labelSkipHeight: 12,
593
604
  labelTextColor: { from: "color", modifiers: [["darker", 3]] },
@@ -633,7 +644,7 @@ function PieView({ records, groupColumn, data: presetData, style }) {
633
644
  }
634
645
  ) });
635
646
  }
636
- function LineView({ records, xColumn, yColumn, data: presetData, style }) {
647
+ function LineView({ records, xColumn, yColumn, data: presetData, dashedIds, style }) {
637
648
  const computed = useMemo(() => {
638
649
  if (presetData || !records) return [];
639
650
  const sorted = [...records].filter((r) => r[xColumn] != null && r[yColumn] != null).sort((a, b) => {
@@ -653,7 +664,21 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
653
664
  serie.id,
654
665
  s.seriesColors.length || data.length > 1 ? seriesColor(i, s) : "rgba(96, 165, 250, 0.9)"
655
666
  ]));
656
- const tickValues = thinTicks(data[0]?.data.map((d) => d.x) ?? [], s.maxXTicks);
667
+ const longest = data.reduce((a, b) => b.data.length > a.data.length ? b : a, { id: "", data: [] });
668
+ const tickValues = thinTicks(longest.data.map((d) => d.x), s.maxXTicks);
669
+ const dashed = new Set(dashedIds || []);
670
+ const linesLayer = ({ series, lineGenerator }) => /* @__PURE__ */ jsx(Fragment, { children: series.map((serie) => /* @__PURE__ */ jsx(
671
+ "path",
672
+ {
673
+ d: lineGenerator(serie.data.map((d) => d.position)),
674
+ fill: "none",
675
+ stroke: serie.color,
676
+ strokeWidth: 2,
677
+ strokeLinecap: "round",
678
+ strokeDasharray: dashed.has(String(serie.id)) ? "1 5" : void 0
679
+ },
680
+ serie.id
681
+ )) });
657
682
  return /* @__PURE__ */ jsx("div", { className: frameClass, style: frameStyle, children: /* @__PURE__ */ jsx(
658
683
  ResponsiveLine,
659
684
  {
@@ -662,10 +687,10 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
662
687
  xScale: { type: "point" },
663
688
  yScale: { type: "linear", min: "auto", max: "auto" },
664
689
  curve: "monotoneX",
665
- enableArea: true,
666
- areaOpacity: 0.15,
690
+ enableArea: s.areaOpacity > 0,
691
+ areaOpacity: s.areaOpacity,
667
692
  colors: ((serie) => colorById.get(serie.id)),
668
- pointSize: (data[0]?.data.length ?? 0) > 50 ? 0 : 6,
693
+ pointSize: 0,
669
694
  pointColor: { theme: "background" },
670
695
  pointBorderWidth: 2,
671
696
  pointBorderColor: { from: "serieColor" },
@@ -673,6 +698,7 @@ function LineView({ records, xColumn, yColumn, data: presetData, style }) {
673
698
  axisBottom: { ...makeAxis(style, "x", xColumn), ...tickValues ? { tickValues } : {} },
674
699
  axisLeft: makeAxis(style, "y", yColumn, { numeric: true }),
675
700
  useMesh: true,
701
+ layers: ["grid", "markers", "axes", "areas", linesLayer, "crosshair", "slices", "mesh", "legends"],
676
702
  theme: buildNivoTheme(style)
677
703
  }
678
704
  ) });