@ai-matrx/records-ui 0.116.13 → 0.116.14

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/CHANGELOG.md CHANGED
@@ -14,11 +14,21 @@
14
14
  - Tests: `vitest.setup.ts` gives jsdom a no-op `performance.mark` / `measure`.
15
15
  - **New subpath `@ai-matrx/records-ui/data-source`:** `recordsDataSource`, `personActor` and the who-changed words (`whenWords`, `actorWords`, `actorBadge`, `lastChangeSentence`, `SOMEBODY`, `THE_SYSTEM`) alone. `/helpers` also carries the field-type words, the colour resolver and the table builders, which read `@ai-matrx/records/core`; this entry reaches `@ai-matrx/kit` only, and shares the one data-source cache with `/helpers` and the root. Additive. Consumer action: a shell-reachable service that only binds its supabase client or says when imports from `/data-source`.
16
16
 
17
- ## 0.116.13
17
+ ## 0.116.14
18
18
 
19
19
  UNVERIFIED: this release has no Unreleased entry and the source comparison could not be made (the caller supplied no source comparison). Whether source changed is unknown; consumer action is unknown.
20
20
  Check the package's gitHead on npm against this version's gitHead: `git diff <previous gitHead> <this gitHead> -- apps/shared/records-ui/src`.
21
21
 
22
+ ## 0.116.13
23
+
24
+ SOURCE CHANGED WITH NO RELEASE NOTE. This release shipped source changes that nobody described in an Unreleased entry,
25
+ so they may include breaking API changes. Consumer action is UNKNOWN: read the diff before upgrading.
26
+ Diff: `git diff ac7b396045 803a1d7fd1 -- apps/shared/records-ui/src`
27
+
28
+ Changed shipped source files (2):
29
+ - `apps/shared/records-ui/src/AddRowSettings.tsx`
30
+ - `apps/shared/records-ui/src/ChartBlock.tsx`
31
+
22
32
  ## 0.116.12
23
33
 
24
34
  SOURCE CHANGED WITH NO RELEASE NOTE. This release shipped source changes that nobody described in an Unreleased entry,
package/dist/index.cjs CHANGED
@@ -43052,7 +43052,7 @@ function colorOfGroup(groups, colors) {
43052
43052
  return colors[raw === null || raw === void 0 ? "" : String(raw)] ?? null;
43053
43053
  }
43054
43054
  var NO_GROUPS = { title: "", kind: "bar", group_by: [], rows: [] };
43055
- function ChartBlock({ block, subject, tableName: tableName2, className, centerValue, centerTotal, legend = true, groupColors, variant = "card", source }) {
43055
+ function ChartBlock({ block, subject, tableName: tableName2, className, centerValue, centerTotal, dataLabels, legend = true, groupColors, variant = "card", source }) {
43056
43056
  const bare = variant === "bare";
43057
43057
  const host = useRecordsUi();
43058
43058
  const kind2 = block.kind;
@@ -43165,7 +43165,8 @@ function ChartBlock({ block, subject, tableName: tableName2, className, centerVa
43165
43165
  config,
43166
43166
  onDrill: drill,
43167
43167
  goal,
43168
- ...centerValue ? { center: centerTotal !== void 0 ? centerTotal : points.reduce((sum, p) => sum + (p.values[primary] ?? 0), 0) } : {},
43168
+ ...centerValue ? { center: centerTotal !== void 0 ? centerTotal : centerOfGroups(points, primary, measures[0].op) } : {},
43169
+ ...dataLabels ? { dataLabels } : {},
43169
43170
  showLegend: legend
43170
43171
  }
43171
43172
  ),
@@ -43181,7 +43182,7 @@ function BigNumber({
43181
43182
  onDrill,
43182
43183
  block
43183
43184
  }) {
43184
- const summed = points.reduce((sum, p) => sum + (p.values[measure] ?? 0), 0);
43185
+ const summed = centerOfGroups(points, measure, String(block.measures?.[0]?.op ?? "count"));
43185
43186
  const total = block.totals && typeof block.totals.current === "number" ? block.totals.current : summed;
43186
43187
  const records = points.reduce((sum, p) => sum + p.n, 0);
43187
43188
  const windows = block.compare ?? null;
@@ -43189,7 +43190,7 @@ function BigNumber({
43189
43190
  const priorTotal = block.totals?.prior;
43190
43191
  const body = /* @__PURE__ */ (0, import_jsx_runtime143.jsxs)(import_jsx_runtime143.Fragment, { children: [
43191
43192
  /* @__PURE__ */ (0, import_jsx_runtime143.jsxs)("span", { className: "flex items-baseline gap-2", children: [
43192
- /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("span", { className: "text-2xl font-semibold tabular-nums", children: pretty(total) }),
43193
+ /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("span", { className: "text-2xl font-semibold tabular-nums", children: total === null ? "\u2013" : pretty(total) }),
43193
43194
  windows ? /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(Trend, { pct: block.totals?.change_pct, aimingUp: !!target, className: "text-sm" }) : null
43194
43195
  ] }),
43195
43196
  /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("span", { className: "text-xs text-muted-foreground", children: windows && typeof priorTotal === "number" ? `${windowName(windows.window, windows.period)} \xB7 ${pretty(priorTotal)} in ${windowName(windows.prior_window, windows.period)}` : `from ${(0, import_format10.formatCount)(records)} ${records === 1 ? "record" : "records"}` })
@@ -43382,8 +43383,10 @@ function Drawing({
43382
43383
  onDrill,
43383
43384
  goal,
43384
43385
  center,
43386
+ dataLabels,
43385
43387
  showLegend = true
43386
43388
  }) {
43389
+ const labelText = (v) => typeof v === "number" ? pretty(v).length > 7 ? compactTick(v) : pretty(v) : "";
43387
43390
  const compared = series.length > 1;
43388
43391
  const drawOrder = compared ? [series[1], series[0]] : series;
43389
43392
  const goalLine = (horizontal2) => goal && typeof goal.value === "number" ? /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(
@@ -43423,8 +43426,9 @@ function Drawing({
43423
43426
  data,
43424
43427
  dataKey: series[0],
43425
43428
  nameKey: "label",
43426
- innerRadius: 44,
43427
- outerRadius: 66,
43429
+ innerRadius: dataLabels ? DONUT_LABELLED.inner : 44,
43430
+ outerRadius: dataLabels ? DONUT_LABELLED.outer : 66,
43431
+ ...dataLabels ? donutLabelProps(points.map((p) => p.values[series[0]] ?? 0), dataLabels === "value" ? (v) => labelText(v) : null) : {},
43428
43432
  paddingAngle: donutGap(points.length),
43429
43433
  isAnimationActive: false,
43430
43434
  ...click ? { onClick: click, className: "cursor-pointer" } : {},
@@ -43461,7 +43465,7 @@ function Drawing({
43461
43465
  ] });
43462
43466
  }
43463
43467
  if (kind2 === "line") {
43464
- return /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(ChartFrame, { config, height: HEIGHT, children: (width) => /* @__PURE__ */ (0, import_jsx_runtime143.jsxs)(import_recharts.LineChart, { width, height: HEIGHT, data, margin: { top: 6, right: 6, bottom: 0, left: 0 }, children: [
43468
+ return /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(ChartFrame, { config, height: HEIGHT, children: (width) => /* @__PURE__ */ (0, import_jsx_runtime143.jsxs)(import_recharts.LineChart, { width, height: HEIGHT, data, margin: { top: dataLabels ? 16 : 6, right: dataLabels ? 14 : 6, bottom: 0, left: 0 }, children: [
43465
43469
  /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(import_recharts.CartesianGrid, { vertical: false }),
43466
43470
  /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(import_recharts.XAxis, { dataKey: "label", ...axis }),
43467
43471
  /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(import_recharts.YAxis, { width: 44, ...axis }),
@@ -43478,7 +43482,8 @@ function Drawing({
43478
43482
  ...key !== series[0] ? { strokeDasharray: "4 3" } : {},
43479
43483
  dot: false,
43480
43484
  isAnimationActive: false,
43481
- ...click ? { className: "cursor-pointer" } : {}
43485
+ ...click ? { className: "cursor-pointer" } : {},
43486
+ children: dataLabels && key === series[0] ? /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(import_recharts.LabelList, { dataKey: key, content: /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(SpacedLabel, { show: labelsThatFit(points.map((p) => labelText(p.values[key])), width - 50), text: labelText, placement: "above" }) }) : null
43482
43487
  },
43483
43488
  key
43484
43489
  ))
@@ -43492,7 +43497,7 @@ function Drawing({
43492
43497
  height: HEIGHT,
43493
43498
  data,
43494
43499
  layout: horizontal ? "vertical" : "horizontal",
43495
- margin: { top: 6, right: 6, bottom: 0, left: 0 },
43500
+ margin: { top: dataLabels && !horizontal ? 16 : 6, right: dataLabels && horizontal ? 40 : 6, bottom: 0, left: 0 },
43496
43501
  children: [
43497
43502
  /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(import_recharts.CartesianGrid, { vertical: horizontal, horizontal: !horizontal }),
43498
43503
  horizontal ? /* @__PURE__ */ (0, import_jsx_runtime143.jsxs)(import_jsx_runtime143.Fragment, { children: [
@@ -43505,7 +43510,7 @@ function Drawing({
43505
43510
  tooltip,
43506
43511
  legend,
43507
43512
  goalLine(horizontal),
43508
- drawOrder.map((key, index) => /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(
43513
+ drawOrder.map((key, index) => /* @__PURE__ */ (0, import_jsx_runtime143.jsxs)(
43509
43514
  import_recharts.Bar,
43510
43515
  {
43511
43516
  dataKey: key,
@@ -43513,7 +43518,23 @@ function Drawing({
43513
43518
  isAnimationActive: false,
43514
43519
  fill: `var(--color-${key})`,
43515
43520
  ...click ? { onClick: click, className: "cursor-pointer" } : {},
43516
- children: series.length === 1 ? points.map((point, at) => /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(import_recharts.Cell, { fill: String(config[point.label]?.color ?? SERIES_COLORS[index]) }, `${at}:${point.label}`)) : null
43521
+ children: [
43522
+ series.length === 1 ? points.map((point, at) => /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(import_recharts.Cell, { fill: String(config[point.label]?.color ?? SERIES_COLORS[index]) }, `${at}:${point.label}`)) : null,
43523
+ dataLabels && key === series[0] ? /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(
43524
+ import_recharts.LabelList,
43525
+ {
43526
+ dataKey: key,
43527
+ content: /* @__PURE__ */ (0, import_jsx_runtime143.jsx)(
43528
+ SpacedLabel,
43529
+ {
43530
+ show: horizontal ? labelsThatFit(points.map(() => "0"), HEIGHT - 20, 11, true) : labelsThatFit(points.map((p) => labelText(p.values[key])), width - 50),
43531
+ text: labelText,
43532
+ placement: horizontal ? "end" : "above"
43533
+ }
43534
+ )
43535
+ }
43536
+ ) : null
43537
+ ]
43517
43538
  },
43518
43539
  key
43519
43540
  ))
@@ -43521,6 +43542,79 @@ function Drawing({
43521
43542
  }
43522
43543
  ) });
43523
43544
  }
43545
+ function centerOfGroups(points, key, op2) {
43546
+ const vals = points.map((p) => p.values[key]).filter((v) => typeof v === "number" && Number.isFinite(v));
43547
+ if (op2 === "count" || op2 === "sum" || op2 === "filled" || op2 === "empty") return vals.reduce((a, b) => a + b, 0);
43548
+ if (!vals.length) return null;
43549
+ if (op2 === "min") return Math.min(...vals);
43550
+ if (op2 === "max") return Math.max(...vals);
43551
+ return null;
43552
+ }
43553
+ var LABEL_CHAR_PX = 6;
43554
+ function labelsThatFit(texts, span, fixedPx, fixed = false, gap = 4) {
43555
+ const n = texts.length;
43556
+ if (!n) return [];
43557
+ const band = Math.max(1, span / n);
43558
+ const widest = fixed ? fixedPx ?? 11 : Math.max(...texts.map((t) => t.length * LABEL_CHAR_PX)) + gap;
43559
+ const step2 = Math.max(1, Math.ceil(widest / band));
43560
+ return texts.map((_t, i) => i % step2 === 0);
43561
+ }
43562
+ function SpacedLabel(props) {
43563
+ const { show, text, placement, value, index = 0 } = props;
43564
+ const x = Number(props.x ?? 0);
43565
+ const y = Number(props.y ?? 0);
43566
+ const w = Number(props.width ?? 0);
43567
+ const h = Number(props.height ?? 0);
43568
+ if (!show[index]) return null;
43569
+ const words2 = text(value);
43570
+ if (!words2) return null;
43571
+ return placement === "end" ? /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("text", { x: x + w + 4, y: y + h / 2, dominantBaseline: "central", fontSize: 10, className: "fill-muted-foreground tabular-nums", "data-records-chart-label": "", children: words2 }) : /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("text", { x: x + w / 2, y: y - 5, textAnchor: "middle", fontSize: 10, className: "fill-muted-foreground tabular-nums", "data-records-chart-label": "", children: words2 });
43572
+ }
43573
+ var DONUT_LABELLED = { inner: 30, outer: 46 };
43574
+ function donutLabelPlan(values, outer2 = DONUT_LABELLED.outer) {
43575
+ const total = values.reduce((a, b) => a + (b > 0 ? b : 0), 0);
43576
+ if (total <= 0) return values.map(() => "none");
43577
+ let acc = 0;
43578
+ const lastY = { left: null, right: null };
43579
+ return values.map((v) => {
43580
+ const share = v > 0 ? v / total : 0;
43581
+ const mid = (acc + share / 2) * 2 * Math.PI;
43582
+ acc += share;
43583
+ if (share >= 0.09) return "inside";
43584
+ if (share < 0.03) return "none";
43585
+ const y = -Math.sin(mid) * (outer2 + 10);
43586
+ const side = Math.cos(mid) >= 0 ? "right" : "left";
43587
+ const prev = lastY[side];
43588
+ if (prev !== null && Math.abs(prev - y) < 11) return "none";
43589
+ lastY[side] = y;
43590
+ return "outside";
43591
+ });
43592
+ }
43593
+ function donutLabelProps(values, asValue) {
43594
+ const plan = donutLabelPlan(values);
43595
+ const total = values.reduce((a, b) => a + (b > 0 ? b : 0), 0);
43596
+ const words2 = (i) => asValue ? asValue(values[i] ?? 0) : `${Math.round((values[i] ?? 0) / (total || 1) * 100)}%`;
43597
+ return {
43598
+ labelLine: (p) => {
43599
+ const at = p.index ?? 0;
43600
+ const pts = p.points ?? [];
43601
+ if (plan[at] !== "outside" || pts.length < 2) return /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("g", {});
43602
+ return /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("polyline", { points: pts.map((q) => `${q.x},${q.y}`).join(" "), fill: "none", stroke: "currentColor", strokeOpacity: 0.4, strokeWidth: 1, "data-records-chart-leader": "" });
43603
+ },
43604
+ label: (p) => {
43605
+ const at = p.index ?? 0;
43606
+ const where = plan[at];
43607
+ if (!where || where === "none") return /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("g", {});
43608
+ const rad = Math.PI / 180;
43609
+ const mid = p.midAngle ?? 0;
43610
+ if (where === "inside") {
43611
+ const r = ((p.innerRadius ?? 0) + (p.outerRadius ?? 0)) / 2;
43612
+ return /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("text", { x: (p.cx ?? 0) + r * Math.cos(-mid * rad), y: (p.cy ?? 0) + r * Math.sin(-mid * rad), textAnchor: "middle", dominantBaseline: "central", fontSize: 9, className: "fill-background font-medium tabular-nums", "data-records-chart-label": "", children: words2(at) });
43613
+ }
43614
+ return /* @__PURE__ */ (0, import_jsx_runtime143.jsx)("text", { x: p.x ?? 0, y: p.y ?? 0, textAnchor: Math.cos(-mid * rad) >= 0 ? "start" : "end", dominantBaseline: "central", fontSize: 9, className: "fill-muted-foreground tabular-nums", "data-records-chart-label": "", children: words2(at) });
43615
+ }
43616
+ };
43617
+ }
43524
43618
  function onlyWholeNumbers(rows) {
43525
43619
  return rows.every(
43526
43620
  (row) => Object.entries(row).every(([key, value]) => key === "label" || typeof value !== "number" || Number.isInteger(value))
@@ -43566,21 +43660,25 @@ function ChartLayout({ view, fields, filter, onChange, remembered }) {
43566
43660
  let cancelled = false;
43567
43661
  const asked4 = JSON.parse(filterKey);
43568
43662
  const question = JSON.parse(qKey);
43569
- void client.recordAggregate({
43663
+ const whole = question.kind === "donut" ? client.recordAggregate({ table_id: view.subject, groupBy: [], measures: [question.measure], ...Object.keys(asked4).length > 0 ? { filter: asked4 } : {} }) : Promise.resolve(null);
43664
+ void Promise.all([client.recordAggregate({
43570
43665
  table_id: view.subject,
43571
43666
  groupBy: question.groupBy,
43572
43667
  ...question.bucket ? { bucket: question.bucket } : {},
43573
43668
  measures: [question.measure],
43574
43669
  limit: 200,
43575
43670
  ...Object.keys(asked4).length > 0 ? { filter: asked4 } : {}
43576
- }).then((answered) => {
43671
+ }), whole]).then(([answered, overall]) => {
43577
43672
  if (cancelled) return;
43578
43673
  if (!answered.ok) {
43579
43674
  setState({ block: null, error: answered.error });
43580
43675
  return;
43581
43676
  }
43677
+ const wholeRow = overall && overall.ok ? (overall.data ?? [])[0] : void 0;
43678
+ const wholeValue = wholeRow ? wholeRow.measures[(0, import_records57.measureKey)(question.measure)] : void 0;
43582
43679
  setState({
43583
43680
  error: null,
43681
+ ...question.kind === "donut" ? { total: typeof wholeValue === "number" ? wholeValue : null } : {},
43584
43682
  block: {
43585
43683
  title: view.name,
43586
43684
  kind: question.kind,
@@ -43627,7 +43725,7 @@ function ChartLayout({ view, fields, filter, onChange, remembered }) {
43627
43725
  MEASURE_LABEL2[isChartMeasure(view.chartMeasure) ? view.chartMeasure : "count"],
43628
43726
  " needs a number field \u2014 pick one above. Counting until then."
43629
43727
  ] }) : null,
43630
- state2.error ? /* @__PURE__ */ (0, import_jsx_runtime144.jsx)(RefusalNotice, { error: state2.error }) : state2.block ? /* @__PURE__ */ (0, import_jsx_runtime144.jsx)(ChartBlock, { block: state2.block, subject: view.subject, variant: "bare", centerValue: true }) : null
43728
+ state2.error ? /* @__PURE__ */ (0, import_jsx_runtime144.jsx)(RefusalNotice, { error: state2.error }) : state2.block ? /* @__PURE__ */ (0, import_jsx_runtime144.jsx)(ChartBlock, { block: state2.block, subject: view.subject, variant: "bare", centerValue: true, ...state2.total !== void 0 ? { centerTotal: state2.total } : {} }) : null
43631
43729
  ] });
43632
43730
  }
43633
43731
 
@@ -60387,7 +60485,8 @@ function blockOfAnswer(answer, base2, by) {
60387
60485
  for (const [k, v] of Object.entries(r.measures ?? {})) measuresOut[k] = typeof v === "number" ? v : v === null ? null : Number(v);
60388
60486
  return { groups, measures: measuresOut, row_count: Number(r.row_count) };
60389
60487
  });
60390
- return { ...base2, rows };
60488
+ const totalValue = answer.data.total?.measures ? Object.values(answer.data.total.measures)[0] : void 0;
60489
+ return { ...base2, rows, center_total: typeof totalValue === "number" ? totalValue : totalValue === null || totalValue === void 0 ? null : Number(totalValue) };
60391
60490
  }
60392
60491
  function EntityChartBlock({ source, kind: kind2, by, measure, title, where, organization, centerValue, variant, className }) {
60393
60492
  const client = (0, import_react339.useRecordsClient)();
@@ -60421,7 +60520,7 @@ function EntityChartBlock({ source, kind: kind2, by, measure, title, where, orga
60421
60520
  block,
60422
60521
  subject: source.token,
60423
60522
  source,
60424
- ...centerValue ? { centerValue } : {},
60523
+ ...centerValue ? { centerValue, ...block.center_total !== void 0 ? { centerTotal: block.center_total } : {} } : {},
60425
60524
  ...variant ? { variant } : {},
60426
60525
  ...className ? { className } : {}
60427
60526
  }