@flytedan/flytebot-design-system 0.62.0 → 0.64.0

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
@@ -1095,6 +1095,7 @@ __export(index_exports, {
1095
1095
  formatDuration: () => formatDuration,
1096
1096
  formatEta: () => formatEta,
1097
1097
  formatRelative: () => formatRelative,
1098
+ formatShare: () => formatShare,
1098
1099
  groupMessages: () => groupMessages,
1099
1100
  hasModifier: () => hasModifier,
1100
1101
  historyUrlAdapter: () => historyUrlAdapter,
@@ -3923,11 +3924,13 @@ function DonutChart({
3923
3924
  // src/components/data/BarList.tsx
3924
3925
  var React25 = __toESM(require("react"), 1);
3925
3926
  var import_jsx_runtime40 = require("react/jsx-runtime");
3927
+ var wholePercent = (share) => formatPercent(Math.round(share * 100));
3926
3928
  function BarList({
3927
3929
  rows,
3928
3930
  label,
3929
3931
  valueFormat = formatCompact,
3930
3932
  total,
3933
+ shareFormat = wholePercent,
3931
3934
  sort = true,
3932
3935
  maxRows,
3933
3936
  barHeight = 10,
@@ -3956,9 +3959,9 @@ function BarList({
3956
3959
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("ol", { className: "fd-barlist-list", "aria-label": label, children: ordered.map((r, i) => {
3957
3960
  const value = Number(r.value) || 0;
3958
3961
  const barPct = Math.max(0, Math.min(100, value / maxValue * 100));
3959
- const pct = effectiveTotal ? Math.round(value / effectiveTotal * 100) : 0;
3962
+ const share = effectiveTotal ? value / effectiveTotal : 0;
3960
3963
  const color = chartColor(i, r.color);
3961
- const detail = `${r.label} \u2014 ${valueFormat(value)} (${formatPercent(pct)})`;
3964
+ const detail = `${r.label} \u2014 ${valueFormat(value)} (${shareFormat(share)})`;
3962
3965
  return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("li", { className: "fd-barlist-row", children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Tooltip, { label: detail, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("button", { type: "button", className: "fd-barlist-btn", children: [
3963
3966
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "fd-barlist-label", title: truncationTitle(r.label), children: r.label }),
3964
3967
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "fd-barlist-track", style: { height: barHeight }, children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("svg", { viewBox: "0 0 100 10", preserveAspectRatio: "none", role: "img", "aria-label": detail, children: [
@@ -3966,7 +3969,7 @@ function BarList({
3966
3969
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("rect", { x: 0, y: 0, width: barPct, height: 10, rx: 3, fill: color })
3967
3970
  ] }) }),
3968
3971
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "fd-barlist-value fd-tabular", children: valueFormat(value) }),
3969
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "fd-barlist-pct fd-tabular", children: formatPercent(pct) })
3972
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: "fd-barlist-pct fd-tabular", children: shareFormat(share) })
3970
3973
  ] }) }) }, r.id);
3971
3974
  }) }),
3972
3975
  /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
@@ -3976,8 +3979,8 @@ function BarList({
3976
3979
  columns: ["", "Value", "Percent"],
3977
3980
  rows: ordered.map((r) => {
3978
3981
  const value = Number(r.value) || 0;
3979
- const pct = effectiveTotal ? Math.round(value / effectiveTotal * 100) : 0;
3980
- return [r.label, valueFormat(value), formatPercent(pct)];
3982
+ const share = effectiveTotal ? value / effectiveTotal : 0;
3983
+ return [r.label, valueFormat(value), shareFormat(share)];
3981
3984
  })
3982
3985
  }
3983
3986
  )
@@ -7569,9 +7572,9 @@ function formatShare(share) {
7569
7572
  return tenths >= 10 ? `${Math.round(percent)}%` : `${tenths.toFixed(1)}%`;
7570
7573
  }
7571
7574
  var byValue = (a, b) => b.value - a.value;
7572
- function buildChoroplethModel(values, topN) {
7575
+ function buildChoroplethModel(values, topN, givenTotal) {
7573
7576
  const byCode = /* @__PURE__ */ new Map();
7574
- let total = 0;
7577
+ let sum = 0;
7575
7578
  for (const { state, value } of values) {
7576
7579
  if (!isUsStateCode(state)) throw new Error(`USChoropleth: "${state}" is not a US state code`);
7577
7580
  if (byCode.has(state)) throw new Error(`USChoropleth: ${state} is given more than once`);
@@ -7579,8 +7582,12 @@ function buildChoroplethModel(values, topN) {
7579
7582
  throw new Error(`USChoropleth: the value for ${state} must be a whole count of 0 or more, got ${value}`);
7580
7583
  }
7581
7584
  byCode.set(state, value);
7582
- total += value;
7585
+ sum += value;
7586
+ }
7587
+ if (givenTotal !== void 0 && !(Number.isInteger(givenTotal) && givenTotal >= sum)) {
7588
+ throw new Error(`USChoropleth: total must be a whole count of at least the sum of values (${sum}), got ${givenTotal}`);
7583
7589
  }
7590
+ const total = givenTotal ?? sum;
7584
7591
  const share = (value) => total === 0 ? 0 : value / total;
7585
7592
  const rows = US_STATES.map((state) => {
7586
7593
  const value = byCode.get(state.code) ?? 0;
@@ -7690,8 +7697,8 @@ function StateTable({ model, valueLabel, formatValue }) {
7690
7697
  ];
7691
7698
  return /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(Collapsible, { title: TABLE_TITLE, children: /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(DataTable, { columns, rows: model.rows, rowKey: "code", compact: true }) });
7692
7699
  }
7693
- function USChoropleth({ values, label, valueLabel, formatValue, formatReadout, topN, className = "" }) {
7694
- const model = React44.useMemo(() => buildChoroplethModel(values, topN ?? 0), [values, topN]);
7700
+ function USChoropleth({ values, label, valueLabel, formatValue, formatReadout, topN, total, className = "" }) {
7701
+ const model = React44.useMemo(() => buildChoroplethModel(values, topN ?? 0, total), [values, topN, total]);
7695
7702
  const figures = React44.useMemo(() => new Map(model.rows.map((row) => [row.code, row])), [model]);
7696
7703
  const { state, retry } = useUsStateShapes();
7697
7704
  return /* @__PURE__ */ (0, import_jsx_runtime67.jsxs)("div", { className: ["fd-uschoro", className].filter(Boolean).join(" "), children: [
@@ -7717,6 +7724,7 @@ function USChoropleth({ values, label, valueLabel, formatValue, formatReadout, t
7717
7724
  rows: model.top.map((row) => ({ id: row.code, label: row.name, value: row.value, color: "var(--seq-4)" })),
7718
7725
  valueFormat: formatValue,
7719
7726
  total: model.total,
7727
+ shareFormat: formatShare,
7720
7728
  sort: false
7721
7729
  }
7722
7730
  ) }) : null
@@ -16335,6 +16343,7 @@ function useDocumentTitle(routeTitle, appName) {
16335
16343
  formatDuration,
16336
16344
  formatEta,
16337
16345
  formatRelative,
16346
+ formatShare,
16338
16347
  groupMessages,
16339
16348
  hasModifier,
16340
16349
  historyUrlAdapter,