@ai-matrx/records-ui 0.116.11 → 0.116.12

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
@@ -5353,6 +5353,21 @@ interface ChartBlockProps {
5353
5353
  className?: string | undefined;
5354
5354
  /** A donut draws its total in the middle (the first measure added up over its groups). */
5355
5355
  centerValue?: boolean | undefined;
5356
+ /**
5357
+ * The number a `centerValue` donut draws in its middle when the host knows the whole answer: the
5358
+ * total over EVERY record (a cut of 200 groups still counts all of them), or an average / min / max
5359
+ * over every record, which adding the groups up would get wrong. `null` = the store had no total
5360
+ * ("–"). Absent: the drawn groups added up.
5361
+ */
5362
+ centerTotal?: number | null | undefined;
5363
+ /** `false` draws no legend beside a donut and no value list under bars or a line. Default `true`. */
5364
+ legend?: boolean | undefined;
5365
+ /**
5366
+ * The colour each group is drawn in, keyed by its stored value as text ("" for no value) — a
5367
+ * choice column's own option colours. A group not named here takes the palette's next colour.
5368
+ * Single-group blocks only; a compared block keeps its two series tones.
5369
+ */
5370
+ groupColors?: Readonly<Record<string, string>> | undefined;
5356
5371
  /**
5357
5372
  * `bare` — the drawing alone, for a block a page already titles: no figure border, no padding,
5358
5373
  * no caption row. Default `card`.
@@ -5368,7 +5383,7 @@ interface ChartBlockProps {
5368
5383
  token: string;
5369
5384
  } | undefined;
5370
5385
  }
5371
- declare function ChartBlock({ block, subject, tableName, className, centerValue, variant, source }: ChartBlockProps): react.JSX.Element;
5386
+ declare function ChartBlock({ block, subject, tableName, className, centerValue, centerTotal, legend, groupColors, variant, source }: ChartBlockProps): react.JSX.Element;
5372
5387
 
5373
5388
  type ChartLayoutKind = "bar" | "line" | "donut";
5374
5389
  /**
package/dist/index.d.ts CHANGED
@@ -5353,6 +5353,21 @@ interface ChartBlockProps {
5353
5353
  className?: string | undefined;
5354
5354
  /** A donut draws its total in the middle (the first measure added up over its groups). */
5355
5355
  centerValue?: boolean | undefined;
5356
+ /**
5357
+ * The number a `centerValue` donut draws in its middle when the host knows the whole answer: the
5358
+ * total over EVERY record (a cut of 200 groups still counts all of them), or an average / min / max
5359
+ * over every record, which adding the groups up would get wrong. `null` = the store had no total
5360
+ * ("–"). Absent: the drawn groups added up.
5361
+ */
5362
+ centerTotal?: number | null | undefined;
5363
+ /** `false` draws no legend beside a donut and no value list under bars or a line. Default `true`. */
5364
+ legend?: boolean | undefined;
5365
+ /**
5366
+ * The colour each group is drawn in, keyed by its stored value as text ("" for no value) — a
5367
+ * choice column's own option colours. A group not named here takes the palette's next colour.
5368
+ * Single-group blocks only; a compared block keeps its two series tones.
5369
+ */
5370
+ groupColors?: Readonly<Record<string, string>> | undefined;
5356
5371
  /**
5357
5372
  * `bare` — the drawing alone, for a block a page already titles: no figure border, no padding,
5358
5373
  * no caption row. Default `card`.
@@ -5368,7 +5383,7 @@ interface ChartBlockProps {
5368
5383
  token: string;
5369
5384
  } | undefined;
5370
5385
  }
5371
- declare function ChartBlock({ block, subject, tableName, className, centerValue, variant, source }: ChartBlockProps): react.JSX.Element;
5386
+ declare function ChartBlock({ block, subject, tableName, className, centerValue, centerTotal, legend, groupColors, variant, source }: ChartBlockProps): react.JSX.Element;
5372
5387
 
5373
5388
  type ChartLayoutKind = "bar" | "line" | "donut";
5374
5389
  /**
package/dist/index.js CHANGED
@@ -23471,8 +23471,15 @@ function asRefusal2(block) {
23471
23471
  "dashboard_run"
23472
23472
  );
23473
23473
  }
23474
+ function colorOfGroup(groups, colors) {
23475
+ if (!colors) return null;
23476
+ const values = Object.values(groups);
23477
+ if (values.length > 1) return null;
23478
+ const raw = values[0];
23479
+ return colors[raw === null || raw === void 0 ? "" : String(raw)] ?? null;
23480
+ }
23474
23481
  var NO_GROUPS = { title: "", kind: "bar", group_by: [], rows: [] };
23475
- function ChartBlock({ block, subject, tableName: tableName2, className, centerValue, variant = "card", source }) {
23482
+ function ChartBlock({ block, subject, tableName: tableName2, className, centerValue, centerTotal, legend = true, groupColors, variant = "card", source }) {
23476
23483
  const bare = variant === "bare";
23477
23484
  const host = useRecordsUi();
23478
23485
  const kind2 = block.kind;
@@ -23523,10 +23530,10 @@ function ChartBlock({ block, subject, tableName: tableName2, className, centerVa
23523
23530
  };
23524
23531
  }
23525
23532
  points.forEach((point, index) => {
23526
- out[point.label] ??= { label: point.label, color: SERIES_COLORS[index % SERIES_COLORS.length] };
23533
+ out[point.label] ??= { label: point.label, color: (!windows ? colorOfGroup(point.groups, groupColors) : null) ?? SERIES_COLORS[index % SERIES_COLORS.length] };
23527
23534
  });
23528
23535
  return out;
23529
- }, [primary, measureName, windows, points]);
23536
+ }, [primary, measureName, windows, points, groupColors]);
23530
23537
  const goal = target && typeof target.value === "number" ? {
23531
23538
  value: typeof target.pace === "number" ? target.pace : block.bucket ? null : target.value,
23532
23539
  label: typeof target.pace === "number" && target.per !== "bucket" ? `${target.label} pace` : target.label
@@ -23585,10 +23592,11 @@ function ChartBlock({ block, subject, tableName: tableName2, className, centerVa
23585
23592
  config,
23586
23593
  onDrill: drill,
23587
23594
  goal,
23588
- ...centerValue ? { center: points.reduce((sum, p) => sum + (p.values[primary] ?? 0), 0) } : {}
23595
+ ...centerValue ? { center: centerTotal !== void 0 ? centerTotal : points.reduce((sum, p) => sum + (p.values[primary] ?? 0), 0) } : {},
23596
+ showLegend: legend
23589
23597
  }
23590
23598
  ),
23591
- kind2 === "donut" ? null : /* @__PURE__ */ jsx79(Values, { points, measure: primary, config, onDrill: drill, compared, aimingUp: !!target })
23599
+ kind2 === "donut" || !legend ? null : /* @__PURE__ */ jsx79(Values, { points, measure: primary, config, onDrill: drill, compared, aimingUp: !!target })
23592
23600
  ] }) })
23593
23601
  ]
23594
23602
  }
@@ -23795,7 +23803,8 @@ function Drawing({
23795
23803
  config,
23796
23804
  onDrill,
23797
23805
  goal,
23798
- center
23806
+ center,
23807
+ showLegend = true
23799
23808
  }) {
23800
23809
  const compared = series.length > 1;
23801
23810
  const drawOrder = compared ? [series[1], series[0]] : series;
@@ -23852,15 +23861,15 @@ function Drawing({
23852
23861
  {
23853
23862
  className: "pointer-events-none absolute inset-0 flex items-center justify-center px-6 font-semibold tabular-nums",
23854
23863
  "data-records-chart-center": "",
23855
- title: pretty(center),
23856
- style: { fontSize: pretty(center).length > 6 ? 13 : 16 },
23857
- children: pretty(center).length > 7 ? compactTick(center) : pretty(center)
23864
+ title: center === null ? void 0 : pretty(center),
23865
+ style: { fontSize: center !== null && pretty(center).length > 6 ? 13 : 16 },
23866
+ children: center === null ? "\u2013" : pretty(center).length > 7 ? compactTick(center) : pretty(center)
23858
23867
  }
23859
23868
  )
23860
23869
  ] });
23861
23870
  return /* @__PURE__ */ jsxs72("div", { className: "flex min-w-0 flex-wrap items-center gap-x-4 gap-y-2", "data-records-donut": "", children: [
23862
23871
  ringWithCenter,
23863
- /* @__PURE__ */ jsx79("ul", { className: "flex min-w-[8rem] max-w-md flex-1 basis-40 flex-col gap-0.5 overflow-y-auto overscroll-contain", style: { maxHeight: DONUT_LEGEND_MAX_PX }, "data-records-donut-legend": "", children: points.map((point, at) => {
23872
+ showLegend ? /* @__PURE__ */ jsx79("ul", { className: "flex min-w-[8rem] max-w-md flex-1 basis-40 flex-col gap-0.5 overflow-y-auto overscroll-contain", style: { maxHeight: DONUT_LEGEND_MAX_PX }, "data-records-donut-legend": "", children: points.map((point, at) => {
23864
23873
  const value = point.values[series[0]] ?? 0;
23865
23874
  const share = total > 0 ? Math.round(value / total * 1e3) / 10 : 0;
23866
23875
  const row = /* @__PURE__ */ jsxs72(Fragment34, { children: [
@@ -23870,7 +23879,7 @@ function Drawing({
23870
23879
  /* @__PURE__ */ jsx79("span", { className: "w-10 shrink-0 text-right tabular-nums text-muted-foreground", "data-records-donut-share": "", children: `${share}%` })
23871
23880
  ] });
23872
23881
  return /* @__PURE__ */ jsx79("li", { className: "min-w-0 text-xs", children: onDrill ? /* @__PURE__ */ jsx79("button", { type: "button", className: "flex w-full min-w-0 items-center gap-2 rounded px-1 py-0.5 text-left hover:bg-muted focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", onClick: () => onDrill(point), children: row }) : /* @__PURE__ */ jsx79("span", { className: "flex w-full min-w-0 items-center gap-2 px-1 py-0.5", children: row }) }, `${at}:${point.label}`);
23873
- }) })
23882
+ }) }) : null
23874
23883
  ] });
23875
23884
  }
23876
23885
  if (kind2 === "line") {