@sincpro/web-ui 1.10.0 → 1.11.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.
Files changed (47) hide show
  1. package/dist/components/board/Board.d.ts +51 -0
  2. package/dist/components/board/Board.js +15 -0
  3. package/dist/components/board/index.d.ts +1 -0
  4. package/dist/components/board/index.js +2 -0
  5. package/dist/components/frame/Chart.d.ts +12 -7
  6. package/dist/components/frame/Chart.js +17 -17
  7. package/dist/components/frame/FrameView.d.ts +3 -3
  8. package/dist/components/frame/FrameView.js +79 -26
  9. package/dist/components/frame/model.d.ts +12 -3
  10. package/dist/components/frame/model.js +53 -19
  11. package/dist/components/index.d.ts +1 -0
  12. package/dist/components/index.js +1 -0
  13. package/dist/components/listing/AxisLevels.d.ts +24 -0
  14. package/dist/components/listing/AxisLevels.js +58 -0
  15. package/dist/components/listing/ChartExplorer.d.ts +79 -0
  16. package/dist/components/listing/ChartExplorer.js +114 -0
  17. package/dist/components/listing/PivotExplorer.js +5 -36
  18. package/dist/components/listing/index.d.ts +2 -0
  19. package/dist/components/listing/index.js +2 -0
  20. package/dist/components/listing/set.d.ts +3 -1
  21. package/dist/foundations/calendar.d.ts +15 -0
  22. package/dist/foundations/calendar.js +59 -1
  23. package/dist/foundations/chart.d.ts +126 -0
  24. package/dist/foundations/chart.js +297 -0
  25. package/dist/foundations/copy.d.ts +39 -0
  26. package/dist/foundations/copy.es.js +27 -0
  27. package/dist/foundations/copy.js +27 -0
  28. package/dist/foundations/index.d.ts +2 -1
  29. package/dist/foundations/index.js +4 -1
  30. package/dist/foundations/pivot.d.ts +9 -0
  31. package/dist/foundations/pivot.js +1 -0
  32. package/dist/primitives/chart/Chart.d.ts +39 -0
  33. package/dist/primitives/chart/Chart.js +235 -0
  34. package/dist/primitives/chart/index.d.ts +1 -0
  35. package/dist/primitives/chart/index.js +1 -0
  36. package/dist/primitives/index.d.ts +1 -0
  37. package/dist/primitives/index.js +1 -0
  38. package/dist/primitives/value/Metric.d.ts +13 -2
  39. package/dist/primitives/value/Metric.js +25 -3
  40. package/dist/tokens.css +45 -0
  41. package/dist/views/list/List.d.ts +2 -1
  42. package/dist/views/list/List.js +8 -1
  43. package/dist/views/list/ListView.d.ts +1 -1
  44. package/dist/views/list/ListView.js +37 -5
  45. package/dist/views/list/index.d.ts +1 -1
  46. package/dist/views/list/types.d.ts +34 -0
  47. package/package.json +2 -1
@@ -0,0 +1,51 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * A BOARD: the tiles of a dashboard — Odoo's «Tableros», a BI page — over one slice of data.
4
+ *
5
+ * Context: a board is not a third view. Each tile is a piece that already exists (a `Chart`,
6
+ * a `List`, a `PivotTable`, `Metrics`); what the board adds is the ORDER of the page, and two
7
+ * rules that a page of loose cards breaks:
8
+ *
9
+ * 1. **One filter row, above everything it scopes.** The period and the branch are chosen
10
+ * once and every tile re-reads the same slice. A filter inside one tile would make two
11
+ * tiles of the same page answer about two different sets, and nothing on screen would
12
+ * say so.
13
+ * 2. **The headline numbers first**, then the tiles. What is read in two seconds goes where
14
+ * the eye lands.
15
+ *
16
+ * The grid asks the CONTAINER and not the window (`@container`): a board inside a panel of
17
+ * the workspace is as narrow as the panel, whatever the screen measures.
18
+ *
19
+ * It knows no domain and folds nothing: the application reads its data with the filters and
20
+ * hands each tile what to draw — the same `Pivot` the list's chart and pivot read.
21
+ */
22
+ export type BoardProps = {
23
+ /** What the board is about: «Ventas». */
24
+ title: string;
25
+ description?: ReactNode;
26
+ /** The filters that scope EVERY tile, in one row. */
27
+ filters?: ReactNode;
28
+ /** The headline numbers — `Metrics` — read before the tiles. */
29
+ metrics?: ReactNode;
30
+ /** The tiles: `BoardTile`s. */
31
+ children: ReactNode;
32
+ };
33
+ export declare function Board({ title, description, filters, metrics, children }: BoardProps): import("react").JSX.Element;
34
+ declare const SPAN: {
35
+ readonly 1: "";
36
+ readonly 2: "@3xl:col-span-2";
37
+ readonly full: "col-span-full";
38
+ };
39
+ export type BoardTileProps = {
40
+ title: string;
41
+ /** One line under the title: what it counts, or what a press on it does. */
42
+ description?: ReactNode;
43
+ /** The tile's own buttons, at its top right: open the list behind it, download. */
44
+ actions?: ReactNode;
45
+ /** How many columns it takes: a time series reads better wide. */
46
+ span?: keyof typeof SPAN;
47
+ children: ReactNode;
48
+ };
49
+ /** One tile of a `Board`: a titled surface around a chart, a list or a number. */
50
+ export declare function BoardTile({ title, description, actions, span, children, }: BoardTileProps): import("react").JSX.Element;
51
+ export {};
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ export function Board({ title, description, filters, metrics, children }) {
3
+ return (
4
+ /* Its own gutter: a board is a page (or a whole panel), not a piece inside one. */
5
+ _jsxs("div", { className: "@container flex min-w-0 flex-col gap-5 p-4 sm:p-6", children: [_jsxs("header", { className: "flex min-w-0 flex-wrap items-end justify-between gap-x-6 gap-y-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h1", { className: "text-display font-semibold text-ink", children: title }), description === undefined ? null : (_jsx("p", { className: "mt-1 text-body text-muted", children: description }))] }), filters === undefined ? null : (_jsx("div", { className: "flex min-w-0 flex-wrap items-end gap-3", children: filters }))] }), metrics, _jsx("div", { className: "grid min-w-0 grid-cols-1 gap-4 @3xl:grid-cols-2 @7xl:grid-cols-3", children: children })] }));
6
+ }
7
+ const SPAN = {
8
+ 1: "",
9
+ 2: "@3xl:col-span-2",
10
+ full: "col-span-full",
11
+ };
12
+ /** One tile of a `Board`: a titled surface around a chart, a list or a number. */
13
+ export function BoardTile({ title, description, actions, span = 1, children, }) {
14
+ return (_jsxs("section", { "aria-label": title, className: `flex min-w-0 flex-col gap-4 rounded-box border border-line-strong bg-surface p-4 ${SPAN[span]}`, children: [_jsxs("header", { className: "flex min-w-0 items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h2", { className: "text-lead font-semibold text-ink", children: title }), description === undefined ? null : (_jsx("p", { className: "mt-0.5 text-meta text-muted", children: description }))] }), actions === undefined ? null : (_jsx("div", { className: "flex shrink-0 items-center gap-1", children: actions }))] }), children] }));
15
+ }
@@ -0,0 +1 @@
1
+ export { Board, type BoardProps, BoardTile, type BoardTileProps, } from "./Board.js";
@@ -0,0 +1,2 @@
1
+ /* A dashboard: one filter row, the headline numbers, and tiles over the same slice. */
2
+ export { Board, BoardTile, } from "./Board.js";
@@ -1,13 +1,18 @@
1
1
  import type { SeriesBar } from "./model.js";
2
2
  /**
3
- * One series, drawn as a bar list: the name, the count, and a track.
3
+ * How ONE column is spread: its values counted, drawn with the system's `Chart`.
4
4
  *
5
- * A column of vertical bars with the names in a legend underneath asks the
6
- * eye to match a bar to a word. Here the word sits on its own bar, which is
7
- * the question this piece answers — how the values of one column are spread.
8
- * CSS, not a charting library: the width is a percentage of the largest
9
- * count, and the color is the data color, one series, not a palette.
5
+ * Context: this used to be its own drawing — 6 px progress bars stretched across the page,
6
+ * the count 1,200 px from its bar, an empty stretch drawn with a stub as if it had rows.
7
+ * Now it is the same chart every other set uses, read from the bars `columnSeries` decides:
8
+ * a text column ranked (bars lying down, the count at the tip), a numeric one as a
9
+ * histogram (columns along the number line, round edges, an empty stretch at zero).
10
+ *
11
+ * Grouping by a field and measuring is `ChartExplorer`'s question; this one is narrower and
12
+ * stays for it: «how are the values of this column spread».
10
13
  */
11
- export declare function SeriesChart({ series }: {
14
+ export declare function SeriesChart({ series, label, }: {
12
15
  series: readonly SeriesBar[];
16
+ /** What is being counted: «ciudad», «importe en tramos». */
17
+ label?: string;
13
18
  }): import("react").JSX.Element;
@@ -1,24 +1,24 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { chartFromRecord } from "../../foundations/chart.js";
3
4
  import { useUiCopy } from "../../foundations/copy.js";
5
+ import { Chart } from "../../primitives/chart/Chart.js";
6
+ import { useMemo } from "react";
4
7
  /**
5
- * One series, drawn as a bar list: the name, the count, and a track.
8
+ * How ONE column is spread: its values counted, drawn with the system's `Chart`.
6
9
  *
7
- * A column of vertical bars with the names in a legend underneath asks the
8
- * eye to match a bar to a word. Here the word sits on its own bar, which is
9
- * the question this piece answers — how the values of one column are spread.
10
- * CSS, not a charting library: the width is a percentage of the largest
11
- * count, and the color is the data color, one series, not a palette.
10
+ * Context: this used to be its own drawing — 6 px progress bars stretched across the page,
11
+ * the count 1,200 px from its bar, an empty stretch drawn with a stub as if it had rows.
12
+ * Now it is the same chart every other set uses, read from the bars `columnSeries` decides:
13
+ * a text column ranked (bars lying down, the count at the tip), a numeric one as a
14
+ * histogram (columns along the number line, round edges, an empty stretch at zero).
15
+ *
16
+ * Grouping by a field and measuring is `ChartExplorer`'s question; this one is narrower and
17
+ * stays for it: «how are the values of this column spread».
12
18
  */
13
- export function SeriesChart({ series }) {
19
+ export function SeriesChart({ series, label, }) {
14
20
  const copy = useUiCopy();
15
- const peak = Math.max(1, ...series.map((bar) => bar.count));
16
- if (series.length === 0) {
17
- return _jsx("p", { className: "px-3 py-4 text-body text-muted", children: copy.frame.noSeries });
18
- }
19
- return (_jsx("ul", { className: "flex flex-col gap-2.5 px-3 py-3", children: series.map((bar) => {
20
- const width = Math.max((bar.count / peak) * 100, 2);
21
- const count = bar.count.toLocaleString(copy.locale);
22
- return (_jsxs("li", { className: "flex min-w-0 flex-col gap-1", title: `${bar.label}: ${count}`, children: [_jsxs("div", { className: "flex min-w-0 items-baseline justify-between gap-3", children: [_jsx("span", { className: "min-w-0 truncate text-meta text-ink", children: bar.label }), _jsx("span", { className: "shrink-0 text-micro tabular-nums text-muted", children: count })] }), _jsx("div", { className: "h-1.5 overflow-hidden rounded-pill bg-ink/8", children: _jsx("div", { className: "h-full rounded-pill bg-data", style: { width: `${width}%` } }) })] }, bar.label));
23
- }) }));
21
+ const histogram = series.some((bar) => bar.bin !== undefined);
22
+ const data = useMemo(() => chartFromRecord(series.map((bar) => [bar.label, bar.count]), { header: copy.chart.count }), [series, copy.chart.count]);
23
+ return (_jsx(Chart, { data: data, kind: "bar", horizontal: !histogram, label: label ?? copy.frame.series }));
24
24
  }
@@ -9,9 +9,9 @@ export type FrameViewProps = {
9
9
  present?: FramePresent;
10
10
  presents?: readonly FramePresent[];
11
11
  onPresentChange?: (next: FramePresent) => void;
12
- /** Which column the chart reads. Defaults to the first numeric, else the first. */
12
+ /** Where the chart starts: a text column goes along its axis, a numeric one is the measure
13
+ * (its sum). By default, the first text column by the sum of the first numeric one. */
13
14
  chartColumn?: string;
14
- onChartColumnChange?: (id: string) => void;
15
15
  visibleColumnIds?: readonly string[];
16
16
  onVisibleColumnIdsChange?: (ids: readonly string[]) => void;
17
17
  /** Search, filters, pagination: the same slots as a list. A frame inside a
@@ -30,4 +30,4 @@ export type FrameViewProps = {
30
30
  */
31
31
  grouping?: Grouping<number>;
32
32
  };
33
- export declare function FrameView({ frame, identity, caption, present: presentProp, presents, onPresentChange, chartColumn: chartColumnProp, onChartColumnChange, visibleColumnIds, onVisibleColumnIdsChange, search, pagination, grouping, }: FrameViewProps): import("react").JSX.Element;
33
+ export declare function FrameView({ frame, identity, caption, present: presentProp, presents, onPresentChange, chartColumn, visibleColumnIds, onVisibleColumnIdsChange, search, pagination, grouping, }: FrameViewProps): import("react").JSX.Element;
@@ -1,19 +1,21 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { SeriesChart } from "./Chart.js";
4
- import { columnSeries, withColumns, } from "./model.js";
3
+ import { cellNumber, withColumns, } from "./model.js";
5
4
  import { useColumnControl } from "../listing/columns.js";
6
5
  import { ColumnsMenu, specsFromColumns, } from "../listing/ColumnsMenu.js";
7
6
  import { Listing } from "../listing/Listing.js";
8
7
  import { ListingBar } from "../listing/ListingBar.js";
9
8
  import { ViewSwitcher } from "../listing/ViewSwitcher.js";
10
- import { useUiCopy } from "../../foundations/copy.js";
9
+ import { fillCopy, useUiCopy } from "../../foundations/copy.js";
11
10
  import { pathKey, pileIsOpen, pilesOf, } from "../../foundations/grouping.js";
12
- import { Menu } from "../../primitives/menu/Menu.js";
13
- import { Empty } from "../../primitives/notice/Notice.js";
11
+ import { Empty, Skeleton } from "../../primitives/notice/Notice.js";
14
12
  import { SheetTable } from "../../primitives/table/SheetTable.js";
15
13
  import { BarChart3, Table2 } from "lucide-react";
16
- import { useMemo, useState } from "react";
14
+ import { lazy, Suspense, useMemo, useState } from "react";
15
+ /* The chart (Recharts) is fetched the first time a frame is drawn as one. */
16
+ const ChartExplorer = lazy(() => import("../listing/ChartExplorer.js").then((module) => ({
17
+ default: module.ChartExplorer,
18
+ })));
17
19
  /**
18
20
  * ARCHETYPE 3 — a FRAME: the cells of a payload, as a table or as a chart.
19
21
  *
@@ -32,15 +34,11 @@ const PRESENT_ICONS = [
32
34
  { id: "table", icon: Table2 },
33
35
  { id: "chart", icon: BarChart3 },
34
36
  ];
35
- export function FrameView({ frame, identity, caption, present: presentProp, presents = ["table", "chart"], onPresentChange, chartColumn: chartColumnProp, onChartColumnChange, visibleColumnIds, onVisibleColumnIdsChange, search, pagination, grouping, }) {
37
+ export function FrameView({ frame, identity, caption, present: presentProp, presents = ["table", "chart"], onPresentChange, chartColumn, visibleColumnIds, onVisibleColumnIdsChange, search, pagination, grouping, }) {
36
38
  const copy = useUiCopy();
37
39
  const [ownedPresent, setOwnedPresent] = useState(presentProp ?? "table");
38
40
  const present = onPresentChange !== undefined ? (presentProp ?? "table") : ownedPresent;
39
41
  const setPresent = onPresentChange ?? setOwnedPresent;
40
- const defaultChart = frame.columns.find((column) => column.numeric)?.id ?? frame.columns[0]?.id ?? "";
41
- const [ownedChart, setOwnedChart] = useState(chartColumnProp ?? defaultChart);
42
- const chartColumn = onChartColumnChange !== undefined ? (chartColumnProp ?? defaultChart) : ownedChart;
43
- const setChartColumn = onChartColumnChange ?? setOwnedChart;
44
42
  const columnSpecs = useMemo(() => specsFromColumns(frame.columns, true), [frame.columns]);
45
43
  const columns = useColumnControl(columnSpecs, {
46
44
  ...(visibleColumnIds === undefined ? {} : { visibleIds: visibleColumnIds }),
@@ -83,29 +81,84 @@ export function FrameView({ frame, identity, caption, present: presentProp, pres
83
81
  walk(piles);
84
82
  return out;
85
83
  }, [shown.rows, grouping]);
86
- const series = useMemo(() => (present === "chart" ? columnSeries(shown, chartColumn) : []), [present, shown, chartColumn]);
84
+ /* The chart folds ROW INDICES, the same way the grouping does: a text column splits them
85
+ (along the axis or into series) and a numeric one is summed or averaged. All the
86
+ columns, hidden ones too — hiding is about the table, not about what can be asked. */
87
+ const chart = useMemo(() => {
88
+ const indexOf = new Map(frame.columns.map((column, index) => [column.id, index]));
89
+ const cell = (row, id) => {
90
+ const at = indexOf.get(id);
91
+ const column = at === undefined ? undefined : frame.columns[at];
92
+ return column === undefined || at === undefined ? null : frame.value(row, column, at);
93
+ };
94
+ const texts = frame.columns.filter((column) => column.numeric !== true);
95
+ const numbers = frame.columns.filter((column) => column.numeric === true);
96
+ const fields = (texts.length > 0 ? texts : frame.columns).map((column) => ({
97
+ field: column.id,
98
+ label: column.header,
99
+ }));
100
+ const values = (rows, id) => rows.map((row) => cellNumber(cell(row, id))).filter((n) => n !== null);
101
+ const measures = numbers.flatMap((column) => [
102
+ {
103
+ id: `sum:${column.id}`,
104
+ header: fillCopy(copy.chart.sumOf, { name: column.header }),
105
+ additive: true,
106
+ fold: (rows) => {
107
+ const found = values(rows, column.id);
108
+ return found.length === 0 ? null : found.reduce((a, b) => a + b, 0);
109
+ },
110
+ },
111
+ {
112
+ id: `avg:${column.id}`,
113
+ header: fillCopy(copy.chart.averageOf, { name: column.header }),
114
+ fold: (rows) => {
115
+ const found = values(rows, column.id);
116
+ return found.length === 0 ? null : found.reduce((a, b) => a + b, 0) / found.length;
117
+ },
118
+ },
119
+ ]);
120
+ /* Where the axis starts: the text column that GROUPS — the fewest distinct values, two
121
+ at least. An identifier (one value per row) charts a bar per row, which is the table
122
+ again; a column with one value charts a single bar. */
123
+ const distinct = (id) => {
124
+ const seen = new Set();
125
+ for (let row = 0; row < frame.rows; row += 1)
126
+ seen.add(String(cell(row, id)));
127
+ return seen.size;
128
+ };
129
+ const splits = fields
130
+ .map((field) => ({ field: field.field, count: distinct(field.field) }))
131
+ .filter((one) => one.count >= 2 && one.count < frame.rows)
132
+ .sort((a, b) => a.count - b.count)[0]?.field;
133
+ const start = frame.columns.find((column) => column.id === chartColumn);
134
+ const axis = start !== undefined && start.numeric !== true ? start.id : (splits ?? fields[0]?.field);
135
+ const measure = start?.numeric === true ? `sum:${start.id}` : (measures[0]?.id ?? undefined);
136
+ return {
137
+ items: Array.from({ length: frame.rows }, (_, index) => index),
138
+ of: (row, level) => {
139
+ const value = cell(row, level.field);
140
+ return value === null || value === "" ? copy.cell.emptyBin : String(value);
141
+ },
142
+ fields,
143
+ measures,
144
+ axis,
145
+ measure,
146
+ };
147
+ }, [frame, chartColumn, copy]);
87
148
  const switcher = presents.length > 1 ? (_jsx(ViewSwitcher, { options: PRESENT_ICONS.filter((option) => presents.includes(option.id)).map((option) => ({
88
149
  id: option.id,
89
150
  label: option.id === "table" ? copy.present.table : copy.present.chart,
90
151
  icon: option.icon,
91
152
  })), current: present, onSelect: (id) => setPresent(id) })) : undefined;
92
- const chartMenu = present === "chart" ? (_jsx(Menu, { label: copy.frame.series, groups: [
93
- {
94
- label: copy.frame.column,
95
- options: shown.columns.map((column) => ({
96
- id: column.id,
97
- label: column.type === undefined
98
- ? column.header
99
- : `${column.header} · ${column.type}`,
100
- checked: column.id === chartColumn,
101
- })),
102
- },
103
- ], onSelect: setChartColumn })) : null;
104
- const bar = (_jsx(ListingBar, { ...(identity?.title === undefined ? {} : { title: identity.title }), ...(identity?.description === undefined ? {} : { description: identity.description }), ...(identity?.counters === undefined ? {} : { counters: identity.counters }), ...(search === undefined ? {} : { search }), ...(pagination === undefined ? {} : { pagination }), views: _jsxs(_Fragment, { children: [_jsx(ColumnsMenu, { control: columns }), chartMenu, switcher] }) }));
153
+ const bar = (_jsx(ListingBar, { ...(identity?.title === undefined ? {} : { title: identity.title }), ...(identity?.description === undefined ? {} : { description: identity.description }), ...(identity?.counters === undefined ? {} : { counters: identity.counters }), ...(search === undefined ? {} : { search }), ...(pagination === undefined ? {} : { pagination }), views: _jsxs(_Fragment, { children: [present === "chart" ? null : _jsx(ColumnsMenu, { control: columns }), switcher] }) }));
105
154
  if (frame.rows === 0 || frame.columns.length === 0) {
106
155
  return (_jsx(Listing, { bar: bar, children: _jsx(Empty, { sentence: copy.frame.empty }) }));
107
156
  }
108
- return (_jsx(Listing, { bar: bar, children: present === "chart" ? (_jsx(SeriesChart, { series: series })) : (_jsx(SheetTable, { columns: shown.columns, rows: bands === null ? shown.rows : bands.length, value: (index, column, columnIndex) => {
157
+ return (_jsx(Listing, { bar: bar, children: present === "chart" ? (_jsx("div", { className: "p-3", children: _jsx(Suspense, { fallback: _jsx(Skeleton, { label: copy.failed.loading }), children: _jsx(ChartExplorer, { items: chart.items,
158
+ /* Following the frame's grouping, its levels are read the way it reads them. */
159
+ of: grouping !== undefined && grouping.levels.length > 0 ? grouping.of : chart.of, fields: chart.fields, measures: chart.measures, ...(chart.axis === undefined
160
+ ? {}
161
+ : { defaultCategories: [{ field: chart.axis }] }), ...(chart.measure === undefined ? {} : { defaultMeasure: chart.measure }), ...((grouping?.levels.length ?? 0) > 0 ? { levels: grouping.levels } : {}), ...(identity?.title === undefined ? {} : { label: identity.title }) }) }) })) : (_jsx(SheetTable, { columns: shown.columns, rows: bands === null ? shown.rows : bands.length, value: (index, column, columnIndex) => {
109
162
  const row = bands === null ? index : bands[index]?.row;
110
163
  return row === undefined ? null : shown.value(row, column, columnIndex);
111
164
  }, height: "auto", ...(bands === null
@@ -31,13 +31,22 @@ export type FramePresent = "table" | "chart";
31
31
  export type SeriesBar = {
32
32
  label: string;
33
33
  count: number;
34
+ /** A stretch of a numeric column, `[from, to)` — the last one closed. Present = the
35
+ * bars are a histogram: they go side by side along a number line, not ranked. */
36
+ bin?: {
37
+ from: number;
38
+ to: number;
39
+ };
34
40
  };
35
41
  export declare function frameFromRows(columns: readonly FrameColumn[], rows: readonly (readonly FrameCell[])[]): Frame;
36
42
  /** Keep only some columns. The cells still come from the original frame. */
37
43
  export declare function withColumns(frame: Frame, ids: readonly string[]): Frame;
44
+ /** A cell read as a number: a number, or a text that writes one («12,5»). Anything else is
45
+ * `null` — not a zero. */
46
+ export declare function cellNumber(cell: FrameCell): number | null;
38
47
  /**
39
- * Turn one column into bars: a histogram if the values are numbers, the
40
- * most frequent labels otherwise. Twelve bars is the ceiling — more than
41
- * that is a table again.
48
+ * Turn one column into bars: a histogram with round edges if the values are numbers, the
49
+ * most frequent labels otherwise — the tail gathered into «others». Twelve bars is the
50
+ * ceiling: more than that is a table again.
42
51
  */
43
52
  export declare function columnSeries(frame: Frame, columnId: string): SeriesBar[];
@@ -1,4 +1,4 @@
1
- import { currentCopy, currentCopyLocale } from "../../foundations/copy.js";
1
+ import { currentCopy, currentCopyLocale, fillCopy } from "../../foundations/copy.js";
2
2
  const BINS = 12;
3
3
  const TOP = 12;
4
4
  export function frameFromRows(columns, rows) {
@@ -22,7 +22,9 @@ export function withColumns(frame, ids) {
22
22
  },
23
23
  };
24
24
  }
25
- function asNumber(cell) {
25
+ /** A cell read as a number: a number, or a text that writes one («12,5»). Anything else is
26
+ * `null` — not a zero. */
27
+ export function cellNumber(cell) {
26
28
  if (typeof cell === "number" && Number.isFinite(cell))
27
29
  return cell;
28
30
  if (typeof cell === "string" && cell.trim() !== "") {
@@ -35,9 +37,9 @@ function present(cell) {
35
37
  return cell !== null && cell !== "";
36
38
  }
37
39
  /**
38
- * Turn one column into bars: a histogram if the values are numbers, the
39
- * most frequent labels otherwise. Twelve bars is the ceiling — more than
40
- * that is a table again.
40
+ * Turn one column into bars: a histogram with round edges if the values are numbers, the
41
+ * most frequent labels otherwise — the tail gathered into «others». Twelve bars is the
42
+ * ceiling: more than that is a table again.
41
43
  */
42
44
  export function columnSeries(frame, columnId) {
43
45
  const columnIndex = frame.columns.findIndex((column) => column.id === columnId);
@@ -48,7 +50,7 @@ export function columnSeries(frame, columnId) {
48
50
  for (let row = 0; row < frame.rows; row += 1) {
49
51
  cells.push(frame.value(row, column, columnIndex));
50
52
  }
51
- const numbers = cells.map(asNumber);
53
+ const numbers = cells.map(cellNumber);
52
54
  const numeric = numbers.filter((n) => n !== null);
53
55
  const filled = cells.filter(present).length;
54
56
  if (filled === 0)
@@ -58,23 +60,46 @@ export function columnSeries(frame, columnId) {
58
60
  }
59
61
  return categories(cells);
60
62
  }
63
+ /** A step a person reads without effort: 1, 2, 2.5 or 5 times a power of ten. */
64
+ function niceStep(raw) {
65
+ const power = 10 ** Math.floor(Math.log10(raw));
66
+ const unit = raw / power;
67
+ const nice = unit <= 1 ? 1 : unit <= 2 ? 2 : unit <= 2.5 ? 2.5 : unit <= 5 ? 5 : 10;
68
+ return nice * power;
69
+ }
70
+ /**
71
+ * Stretches with ROUND edges: 0–100, 100–200, not 1,4–35,6. How many follows the number of
72
+ * values (Sturges: ten values make five stretches, six hundred make eleven) and never more
73
+ * than twelve. A stretch with nothing in it stays — it is part of the shape — and counts 0.
74
+ */
61
75
  function histogram(values) {
62
76
  if (values.length === 0)
63
77
  return [];
64
78
  const min = Math.min(...values);
65
79
  const max = Math.max(...values);
66
80
  if (min === max)
67
- return [{ label: String(min), count: values.length }];
68
- const width = (max - min) / BINS;
69
- const counts = Array.from({ length: BINS }, () => 0);
81
+ return [{ label: formatTick(min), count: values.length }];
82
+ const target = Math.min(BINS, Math.max(2, Math.ceil(Math.log2(values.length)) + 1));
83
+ let step = niceStep((max - min) / target);
84
+ let start = Math.floor(min / step) * step;
85
+ let bins = Math.max(1, Math.ceil((max - start) / step));
86
+ while (bins > BINS) {
87
+ step = niceStep(step * 1.01);
88
+ start = Math.floor(min / step) * step;
89
+ bins = Math.max(1, Math.ceil((max - start) / step));
90
+ }
91
+ /* Edges are rounded to the step's own precision: 0.1 × 3 is 0.30000000000000004. */
92
+ const digits = Math.max(0, -Math.floor(Math.log10(step)) + 1);
93
+ const edge = (index) => Number((start + index * step).toFixed(digits));
94
+ const counts = Array.from({ length: bins }, () => 0);
70
95
  for (const value of values) {
71
- const slot = Math.min(BINS - 1, Math.floor((value - min) / width));
96
+ const slot = Math.min(bins - 1, Math.floor((value - start) / step));
72
97
  counts[slot] = (counts[slot] ?? 0) + 1;
73
98
  }
74
99
  return counts.map((count, index) => {
75
- const from = min + index * width;
76
- const to = index === BINS - 1 ? max : from + width;
77
- return { label: `${formatTick(from)}–${formatTick(to)}`, count };
100
+ const from = edge(index);
101
+ const to = edge(index + 1);
102
+ return { label: `${formatTick(from)}–${formatTick(to)}`, count, bin: { from, to } };
78
103
  });
79
104
  }
80
105
  function categories(cells) {
@@ -85,17 +110,26 @@ function categories(cells) {
85
110
  const label = String(cell);
86
111
  tally.set(label, (tally.get(label) ?? 0) + 1);
87
112
  }
88
- return [...tally.entries()]
113
+ const ranked = [...tally.entries()]
89
114
  .sort((a, b) => b[1] - a[1])
90
- .slice(0, TOP)
91
115
  .map(([label, count]) => ({
92
116
  label: label === "" ? currentCopy().cell.emptyBin : label,
93
117
  count,
94
118
  }));
119
+ if (ranked.length <= TOP)
120
+ return ranked;
121
+ /* The tail is gathered, not dropped: the bars still add up to the rows that were counted,
122
+ and «others (388)» says how long the tail is — often the finding itself. */
123
+ const kept = ranked.slice(0, TOP - 1);
124
+ const tail = ranked.slice(TOP - 1);
125
+ return [
126
+ ...kept,
127
+ {
128
+ label: fillCopy(currentCopy().chart.rest, { count: tail.length }),
129
+ count: tail.reduce((total, bar) => total + bar.count, 0),
130
+ },
131
+ ];
95
132
  }
96
133
  function formatTick(n) {
97
- const abs = Math.abs(n);
98
- if (abs >= 100 || Number.isInteger(n))
99
- return String(Math.round(n));
100
- return n.toLocaleString(currentCopyLocale(), { maximumFractionDigits: 1 });
134
+ return n.toLocaleString(currentCopyLocale(), { maximumFractionDigits: 2 });
101
135
  }
@@ -1,6 +1,7 @@
1
1
  export * from "./activity/index.js";
2
2
  export * from "./assist/index.js";
3
3
  export * from "./attachments/index.js";
4
+ export * from "./board/index.js";
4
5
  export * from "./calendar/index.js";
5
6
  export * from "./canvas/index.js";
6
7
  export * from "./chat/index.js";
@@ -2,6 +2,7 @@
2
2
  export * from "./activity/index.js";
3
3
  export * from "./assist/index.js";
4
4
  export * from "./attachments/index.js";
5
+ export * from "./board/index.js";
5
6
  export * from "./calendar/index.js";
6
7
  export * from "./canvas/index.js";
7
8
  export * from "./chat/index.js";
@@ -0,0 +1,24 @@
1
+ import type { GroupableField, GroupLevel } from "../../foundations/grouping.js";
2
+ /**
3
+ * The levels of ONE axis, chosen on the screen: a tag per level with its ×, and «+» to add
4
+ * a field (a date with each of its grains).
5
+ *
6
+ * Context: the pivot had it written inline, and the chart asks the same question twice
7
+ * (its axis and its series). Two copies would drift; this is the one both draw.
8
+ */
9
+ export declare const levelId: (level: GroupLevel) => string;
10
+ /** How a level is named: the field's label, and its grain when it is a date. */
11
+ export declare function levelLabeler(fields: readonly GroupableField[]): (level: GroupLevel) => string;
12
+ /** `fields` name what they list; anything else is named by `fallback`, then by its id. */
13
+ export declare function namer(fields: readonly GroupableField[], fallback?: (level: GroupLevel) => string): (level: GroupLevel) => string;
14
+ export declare function AxisLevels({ name, levels, onChange, fields, used, labelOf: outerLabel, }: {
15
+ name: string;
16
+ levels: readonly GroupLevel[];
17
+ /** `null`: the levels come from somewhere else (the search bar) and are only shown. */
18
+ onChange: ((next: readonly GroupLevel[]) => void) | null;
19
+ fields: readonly GroupableField[];
20
+ /** Levels already on another axis: offered, but not choosable twice. */
21
+ used: readonly GroupLevel[];
22
+ /** How a level not among `fields` is named — the spec's own `labelOf`. */
23
+ labelOf?: (level: GroupLevel) => string;
24
+ }): import("react").JSX.Element;
@@ -0,0 +1,58 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { grainName } from "../../foundations/calendar.js";
4
+ import { fillCopy, useUiCopy } from "../../foundations/copy.js";
5
+ import { Menu } from "../../primitives/menu/Menu.js";
6
+ import { Tags } from "../../primitives/tag/Tags.js";
7
+ import { Plus } from "lucide-react";
8
+ /**
9
+ * The levels of ONE axis, chosen on the screen: a tag per level with its ×, and «+» to add
10
+ * a field (a date with each of its grains).
11
+ *
12
+ * Context: the pivot had it written inline, and the chart asks the same question twice
13
+ * (its axis and its series). Two copies would drift; this is the one both draw.
14
+ */
15
+ export const levelId = (level) => `${level.field}:${level.grain ?? ""}`;
16
+ const fromId = (id) => {
17
+ const [field = "", grain = ""] = id.split(":");
18
+ return grain === "" ? { field } : { field, grain: grain };
19
+ };
20
+ /** How a level is named: the field's label, and its grain when it is a date. */
21
+ export function levelLabeler(fields) {
22
+ return (level) => {
23
+ const field = fields.find((one) => one.field === level.field)?.label ?? level.field;
24
+ return level.grain === undefined
25
+ ? field
26
+ : `${field} · ${grainName(level.grain).toLowerCase()}`;
27
+ };
28
+ }
29
+ /** `fields` name what they list; anything else is named by `fallback`, then by its id. */
30
+ export function namer(fields, fallback) {
31
+ const named = levelLabeler(fields);
32
+ return (level) => fallback !== undefined && !fields.some((one) => one.field === level.field)
33
+ ? fallback(level)
34
+ : named(level);
35
+ }
36
+ export function AxisLevels({ name, levels, onChange, fields, used, labelOf: outerLabel, }) {
37
+ const words = useUiCopy().pivot;
38
+ const labelOf = namer(fields, outerLabel);
39
+ const taken = new Set([...levels, ...used].map(levelId));
40
+ const options = fields.flatMap((field) => (field.grains ?? [undefined]).map((grain) => {
41
+ const level = grain === undefined ? { field: field.field } : { field: field.field, grain };
42
+ return {
43
+ id: levelId(level),
44
+ label: labelOf(level),
45
+ disabled: taken.has(levelId(level)),
46
+ };
47
+ }));
48
+ return (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-1.5", children: [_jsx("span", { className: "text-micro font-medium text-muted", children: name }), _jsx(Tags, { label: name, items: levels.map((level) => ({
49
+ id: levelId(level),
50
+ label: labelOf(level),
51
+ ...(onChange === null
52
+ ? {}
53
+ : {
54
+ onRemove: () => onChange(levels.filter((one) => levelId(one) !== levelId(level))),
55
+ removeLabel: fillCopy(words.removeLevel, { level: labelOf(level) }),
56
+ }),
57
+ })) }), onChange === null ? (_jsx("span", { className: "text-micro text-muted italic", children: words.fromSearch })) : options.length === 0 ? null : (_jsx(Menu, { label: fillCopy(words.addLevel, { axis: name }), icon: Plus, iconOnly: true, chevron: false, variant: "text", groups: [{ options }], onSelect: (id) => onChange([...levels, fromId(id)]) }))] }));
58
+ }