@arbidocs/react 0.5.157 → 0.5.158

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.
@@ -1,7 +1,7 @@
1
1
  import { useMemo } from "react";
2
2
  import { fillTimeGaps } from "./aggregate.js";
3
3
  function queryOfChart(chart) {
4
- if (chart.type === "table" && !chart.x) {
4
+ if (chart.type === "table" && !chart.x || chart.type === "scatter") {
5
5
  return {
6
6
  records: true,
7
7
  ...chart.filters?.length ? { filters: chart.filters } : {},
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/datasets/panel.ts"],
4
- "sourcesContent": ["/**\n * From a panel's spec to its dataset: the query a `ChartSpec` asks of its source, and the hook a\n * panel reads (grouped and measured by the source, date gaps filled for a trend).\n */\nimport { useMemo } from 'react'\nimport { fillTimeGaps } from './aggregate'\nimport type {\n ChartSpec,\n DataSource,\n DataSourceParams,\n DatasetField,\n DatasetQuery,\n DatasetState,\n} from './types'\n\n/**\n * The query a chart asks: its x field grouped (a metric: one group), its series split, its y\n * measured by the aggregate; a table without `x` lists the records (filtered, ordered, limited).\n */\nexport function queryOfChart(chart: ChartSpec): DatasetQuery {\n if (chart.type === 'table' && !chart.x) {\n return {\n records: true,\n ...(chart.filters?.length ? { filters: chart.filters } : {}),\n ...(chart.orderBy ? { orderBy: chart.orderBy } : {}),\n ...(chart.limit ? { limit: chart.limit } : {}),\n }\n }\n const grouped = chart.type !== 'metric'\n const split = grouped && chart.type !== 'pie' && chart.type !== 'donut' && chart.series\n const op = chart.aggregate ?? 'count'\n return {\n ...(chart.filters?.length ? { filters: chart.filters } : {}),\n ...(grouped && chart.x ? { groupBy: chart.x, bucket: chart.bucket ?? 'month' } : {}),\n ...(split ? { splitBy: chart.series } : {}),\n measure: { op, ...(chart.y ? { field: chart.y } : {}) },\n ...(chart.sort ? { sort: chart.sort } : {}),\n ...(chart.limit ? { limit: chart.limit } : {}),\n }\n}\n\n/** Charts drawn along time, whose missing buckets read as gaps. */\nconst TRENDS = new Set<ChartSpec['type']>(['bar', 'line', 'area'])\n\nexport interface PanelDatasetState extends DatasetState {\n /** The source's fields (for labels and units). */\n fields: readonly DatasetField[]\n}\n\n/**\n * The dataset a panel shows. Render it from a component keyed by `source.id`: the source's hooks\n * run here, and differ from one source to another.\n */\nexport function usePanelDataset(\n source: DataSource,\n params: DataSourceParams | undefined,\n chart: ChartSpec,\n options?: { enabled?: boolean }\n): PanelDatasetState {\n // Specs arrive as fresh objects (edited, parsed); key the memo on their content.\n const paramsKey = JSON.stringify(params ?? {})\n const chartKey = JSON.stringify(chart)\n const stableParams = useMemo(() => JSON.parse(paramsKey) as DataSourceParams, [paramsKey])\n const query = useMemo(() => queryOfChart(JSON.parse(chartKey) as ChartSpec), [chartKey])\n const fields = source.useFields(stableParams)\n const state = source.useDataset(stableParams, query, options)\n const xField = fields.fields.find((f) => f.id === chart.x)\n const fillGaps =\n !!state.dataset &&\n xField?.type === 'date' &&\n TRENDS.has(chart.type) &&\n (chart.sort ?? 'label') === 'label'\n const dataset = useMemo(\n () =>\n state.dataset && fillGaps\n ? fillTimeGaps(state.dataset, chart.bucket ?? 'month')\n : state.dataset,\n [state.dataset, fillGaps, chart.bucket]\n )\n return { ...state, dataset, fields: fields.fields }\n}\n"],
5
- "mappings": "AAIA,SAAS,eAAe;AACxB,SAAS,oBAAoB;AActB,SAAS,aAAa,OAAgC;AAC3D,MAAI,MAAM,SAAS,WAAW,CAAC,MAAM,GAAG;AACtC,WAAO;AAAA,MACL,SAAS;AAAA,MACT,GAAI,MAAM,SAAS,SAAS,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,MAC1D,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,MAClD,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;AAAA,IAC9C;AAAA,EACF;AACA,QAAM,UAAU,MAAM,SAAS;AAC/B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d,MACE,MAAM,WAAW,WACb,aAAa,MAAM,SAAS,MAAM,UAAU,OAAO,IACnD,MAAM;AAAA,IACZ,CAAC,MAAM,SAAS,UAAU,MAAM,MAAM;AAAA,EACxC;AACA,SAAO,EAAE,GAAG,OAAO,SAAS,QAAQ,OAAO,OAAO;AACpD;",
4
+ "sourcesContent": ["/**\n * From a panel's spec to its dataset: the query a `ChartSpec` asks of its source, and the hook a\n * panel reads (grouped and measured by the source, date gaps filled for a trend).\n */\nimport { useMemo } from 'react'\nimport { fillTimeGaps } from './aggregate'\nimport type {\n ChartSpec,\n DataSource,\n DataSourceParams,\n DatasetField,\n DatasetQuery,\n DatasetState,\n} from './types'\n\n/**\n * The query a chart asks: its x field grouped (a metric: one group), its series split, its y\n * measured by the aggregate; a table without `x`, and a scatter (a point per record), list the\n * records (filtered, ordered, limited).\n */\nexport function queryOfChart(chart: ChartSpec): DatasetQuery {\n if ((chart.type === 'table' && !chart.x) || chart.type === 'scatter') {\n return {\n records: true,\n ...(chart.filters?.length ? { filters: chart.filters } : {}),\n ...(chart.orderBy ? { orderBy: chart.orderBy } : {}),\n ...(chart.limit ? { limit: chart.limit } : {}),\n }\n }\n const grouped = chart.type !== 'metric'\n const split = grouped && chart.type !== 'pie' && chart.type !== 'donut' && chart.series\n const op = chart.aggregate ?? 'count'\n return {\n ...(chart.filters?.length ? { filters: chart.filters } : {}),\n ...(grouped && chart.x ? { groupBy: chart.x, bucket: chart.bucket ?? 'month' } : {}),\n ...(split ? { splitBy: chart.series } : {}),\n measure: { op, ...(chart.y ? { field: chart.y } : {}) },\n ...(chart.sort ? { sort: chart.sort } : {}),\n ...(chart.limit ? { limit: chart.limit } : {}),\n }\n}\n\n/** Charts drawn along time, whose missing buckets read as gaps. */\nconst TRENDS = new Set<ChartSpec['type']>(['bar', 'line', 'area'])\n\nexport interface PanelDatasetState extends DatasetState {\n /** The source's fields (for labels and units). */\n fields: readonly DatasetField[]\n}\n\n/**\n * The dataset a panel shows. Render it from a component keyed by `source.id`: the source's hooks\n * run here, and differ from one source to another.\n */\nexport function usePanelDataset(\n source: DataSource,\n params: DataSourceParams | undefined,\n chart: ChartSpec,\n options?: { enabled?: boolean }\n): PanelDatasetState {\n // Specs arrive as fresh objects (edited, parsed); key the memo on their content.\n const paramsKey = JSON.stringify(params ?? {})\n const chartKey = JSON.stringify(chart)\n const stableParams = useMemo(() => JSON.parse(paramsKey) as DataSourceParams, [paramsKey])\n const query = useMemo(() => queryOfChart(JSON.parse(chartKey) as ChartSpec), [chartKey])\n const fields = source.useFields(stableParams)\n const state = source.useDataset(stableParams, query, options)\n const xField = fields.fields.find((f) => f.id === chart.x)\n const fillGaps =\n !!state.dataset &&\n xField?.type === 'date' &&\n TRENDS.has(chart.type) &&\n (chart.sort ?? 'label') === 'label'\n const dataset = useMemo(\n () =>\n state.dataset && fillGaps\n ? fillTimeGaps(state.dataset, chart.bucket ?? 'month')\n : state.dataset,\n [state.dataset, fillGaps, chart.bucket]\n )\n return { ...state, dataset, fields: fields.fields }\n}\n"],
5
+ "mappings": "AAIA,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAetB,SAAS,aAAa,OAAgC;AAC3D,MAAK,MAAM,SAAS,WAAW,CAAC,MAAM,KAAM,MAAM,SAAS,WAAW;AACpE,WAAO;AAAA,MACL,SAAS;AAAA,MACT,GAAI,MAAM,SAAS,SAAS,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,MAC1D,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,MAClD,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;AAAA,IAC9C;AAAA,EACF;AACA,QAAM,UAAU,MAAM,SAAS;AAC/B,QAAM,QAAQ,WAAW,MAAM,SAAS,SAAS,MAAM,SAAS,WAAW,MAAM;AACjF,QAAM,KAAK,MAAM,aAAa;AAC9B,SAAO;AAAA,IACL,GAAI,MAAM,SAAS,SAAS,EAAE,SAAS,MA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OAAO,SAAS,QAAQ,OAAO,OAAO;AACpD;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/datasets/types.ts"],
4
- "sourcesContent": ["/**\n * Datasets: the one shape every chart and dashboard reads, whatever the data comes from.\n *\n * Three layers, each knowing only the one below it:\n * 1. A `DataSource` adapter (AI usage, documents, threads, projects, a database, later an external\n * feed) exposes its data as a normalized `Dataset`: typed fields and plain rows. Filtering,\n * grouping and aggregation happen here (`aggregateDataset`, or on the server where the backend\n * can, as a database does), never in a chart.\n * 2. A `ChartSpec` (inside a `PanelSpec`, inside a `DashboardSpec`) says what to show in terms of\n * field ids only: the chart type, x / series / y fields, the aggregate, sort and limit. It is\n * plain JSON, saved in dashboards and studio pages.\n * 3. A renderer (`@arbidocs/blocks/dashboards`) maps a spec plus the aggregated dataset onto the\n * drawing component. No renderer type appears here, so the renderer stays swappable.\n */\n\n/** A field's value type. Dates are ISO strings (`2026-06-12` or a full timestamp). */\nexport type DatasetFieldType = 'string' | 'number' | 'date' | 'boolean'\n\n/** One column of a dataset. */\nexport interface DatasetField {\n /** Stable id: what specs and rows use. */\n id: string\n /** What people read (a column name, \"Status\"). */\n label: string\n type: DatasetFieldType\n /**\n * The unit of a number field, which picks its formatting: `gbp` (\u00A3), `bytes`, `tokens`, or any\n * suffix (`\"MB\"`, `\"%\"`).\n */\n unit?: string\n /** The values a string field takes, when known (a select column's options), for a filter picker. */\n options?: readonly string[]\n /** A string field whose cell holds several values (tags, linked rows): a row counts in each. */\n multiple?: boolean\n}\n\n/** A cell: a scalar, `null` when empty, or a list for a `multiple` field. */\nexport type DatasetValue = string | number | boolean | null | readonly string[]\n\n/** One row, keyed by field id. */\nexport type DatasetRow = Readonly<Record<string, DatasetValue | undefined>>\n\n/** A normalized dataset: typed fields and the rows. */\nexport interface Dataset {\n fields: readonly DatasetField[]\n rows: readonly DatasetRow[]\n /** Rows matched before grouping (after filters). */\n totalRows?: number\n /** More groups existed than the query's `limit`. */\n truncated?: boolean\n}\n\n/** How a date field is grouped. Keys: `2026-06-12`, `2026-W24`, `2026-06`, `2026-Q2`, `2026`. */\nexport type TimeBucket = 'day' | 'week' | 'month' | 'quarter' | 'year'\n\nexport type AggregateOp = 'count' | 'sum' | 'avg' | 'min' | 'max'\n\nexport type FilterOp =\n 'eq' | 'neq' | 'contains' | 'gt' | 'gte' | 'lt' | 'lte' | 'empty' | 'not_empty'\n\n/** Keep rows whose `field` satisfies `op value` (compared in the field's type). */\nexport interface DatasetFilter {\n field: string\n op: FilterOp\n value?: string | number | boolean | null\n}\n\n/** How the groups are ordered: by label (dates: chronological), or by value. */\nexport type DatasetSort = 'label' | 'value-desc' | 'value-asc'\n\n/** How records are ordered: by a field (empty cells last). */\nexport interface DatasetOrder {\n field: string\n /** Default `asc`. */\n direction?: 'asc' | 'desc'\n}\n\n/**\n * What to read of a source. Grouped (the default): the (filtered) rows grouped and each group\n * measured, a dataset in long form with the fields {@link AGGREGATE_FIELDS}, one row per group (and\n * series). With `records`: the matching rows themselves, ordered by `orderBy` and cut at `limit`.\n */\nexport interface DatasetQuery {\n /** List the matching records instead of grouping them (`groupBy`, `splitBy`, `measure` unused). */\n records?: boolean\n /** The order of the records. */\n orderBy?: DatasetOrder\n filters?: readonly DatasetFilter[]\n /** The field whose values (or date buckets) are the groups. Absent: one group, \"All\". */\n groupBy?: string\n /** The bucket of a date `groupBy` / `splitBy`. Default `month`. */\n bucket?: TimeBucket\n /** A second field: one series per value (a stacked or multi-line chart). */\n splitBy?: string\n /** Default: count rows. `count` with a `field` counts the rows where it is not empty. */\n measure?: { op: AggregateOp; field?: string }\n /** Default: dates chronological, others by value, largest first. */\n sort?: DatasetSort\n /** Most groups kept (by value), or records listed. Default 50 groups; every record. */\n limit?: number\n}\n\n/** The field ids of an aggregated dataset. */\nexport const AGGREGATE_FIELDS = {\n /** The group's label (\"Open\", \"2026-06\"). */\n group: 'group',\n /** The group's key as grouped (a date bucket, an id), for ordering and links. */\n key: 'key',\n /** The series' label (only with `splitBy`). */\n series: 'series',\n /** The measured value; `null` when the group has no value to measure. */\n value: 'value',\n} as const\n\n/** A dataset (or a source's fields) as a hook reads it. */\nexport interface DatasetState {\n dataset: Dataset | undefined\n /**\n * No dataset yet, and one is coming: a read in flight or still waiting to start (the workspace\n * opening, a saved view being read first). A panel says \"Loading\u2026\" then, never \"nothing to show\".\n */\n isLoading: boolean\n error: unknown\n}\n\nexport interface DataSourceFieldsState {\n fields: readonly DatasetField[]\n isLoading: boolean\n error: unknown\n}\n\n/** A source's parameters as saved in a panel (a database id, a period). */\nexport type DataSourceParams = Readonly<\n Record<string, string | number | boolean | null | undefined>\n>\n\n/** A choice for a parameter (an option of a select). */\nexport interface DataSourceOption {\n value: string\n label: string\n /** Other parameters set with this choice (a database's workspace, so a panel reads it anywhere). */\n params?: DataSourceParams\n}\n\n/** A parameter the panel editor asks for, before the source's fields are known. */\nexport interface DataSourceParam {\n id: string\n label: string\n /** Absent: the parameter may be left empty. */\n required?: boolean\n /** Shown when nothing is chosen (\"All columns\"). */\n placeholder?: string\n /** The choices, read live (databases of the open workspace; a database's saved views). */\n useOptions: (params: DataSourceParams) => {\n options: readonly DataSourceOption[]\n isLoading: boolean\n }\n}\n\n/**\n * A data source adapter: where a dataset comes from.\n *\n * `useFields` and `useDataset` are hooks. A caller renders them from a component keyed by the\n * source id, so switching source mounts afresh (the hooks differ between sources).\n *\n * Extension point: an external source (an HTTP/JSON API, a CSV feed, a warehouse) is one more\n * adapter. It reads its rows however it likes (its own `useQuery`) and returns them as a `Dataset`;\n * `defineRowsSource` aggregates them for it. A host lists it in `<ArbiHost config={{ dashboards:\n * { sources } }}>` and every editor, panel and studio block offers it. Fetching third-party URLs\n * from the browser is the host's decision (CORS, credentials, what a shared dashboard may reach),\n * so none is built in; data to chart today is imported into a database (CSV / spreadsheet import).\n */\nexport interface DataSource {\n id: string\n label: string\n description?: string\n /** `workspace`: it reads the open workspace's data (documents, threads\u2026), so it shows nothing until\n * one is open; a function decides from the panel's parameters (a database panel that does not name\n * its workspace). Absent: it is the person's own or names what it reads (AI usage). */\n scope?: 'workspace' | ((params: DataSourceParams) => 'workspace' | undefined)\n params?: readonly DataSourceParam[]\n /** The fields a panel can use, given the parameters. */\n useFields: (params: DataSourceParams) => DataSourceFieldsState\n /**\n * The dataset: grouped and measured (long form with {@link AGGREGATE_FIELDS}), or the records\n * (`query.records`), filtered either way.\n */\n useDataset: (\n params: DataSourceParams,\n query: DatasetQuery,\n options?: { enabled?: boolean }\n ) => DatasetState\n}\n\n// \u2500\u2500 Specs: what a panel shows (plain JSON) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** How a panel draws its data. `metric` is one number; `table` a table of rows or groups. */\nexport type ChartType = 'metric' | 'bar' | 'line' | 'area' | 'pie' | 'donut' | 'table'\n\n/** What to show, in terms of the dataset's field ids. Serialisable. */\nexport interface ChartSpec {\n type: ChartType\n /** The category or date field along the x axis (pie slices; table groups). */\n x?: string\n /** The bucket of a date `x`. Default `month`. */\n bucket?: TimeBucket\n /** A field whose values become the series (stacked bars or areas, several lines). */\n series?: string\n /** The number field the aggregate reads (absent: rows are counted). */\n y?: string\n /** Default `count`. */\n aggregate?: AggregateOp\n sort?: DatasetSort\n limit?: number\n /** Stack the series (bar, area). */\n stacked?: boolean\n filters?: readonly DatasetFilter[]\n /** A table of records (no aggregate): the fields shown, in order. Absent: every field. */\n columns?: readonly string[]\n /** A table of records: their order. */\n orderBy?: DatasetOrder\n}\n\n/** The source a panel reads, by registry id, with its parameters. */\nexport interface DataSourceRef {\n id: string\n params?: DataSourceParams\n}\n\n/** One panel of a dashboard. */\nexport interface PanelSpec {\n id: string\n title: string\n description?: string\n source: DataSourceRef\n chart: ChartSpec\n /** Columns of the 12-column grid it spans on a wide screen (it is full width on a phone). */\n width?: number\n}\n\n/** A dashboard: a titled grid of panels. Plain JSON (`version` for later migrations). */\nexport interface DashboardSpec {\n version: 1\n title: string\n description?: string\n panels: readonly PanelSpec[]\n}\n"],
4
+ "sourcesContent": ["/**\n * Datasets: the one shape every chart and dashboard reads, whatever the data comes from.\n *\n * Three layers, each knowing only the one below it:\n * 1. A `DataSource` adapter (AI usage, documents, threads, projects, a database, later an external\n * feed) exposes its data as a normalized `Dataset`: typed fields and plain rows. Filtering,\n * grouping and aggregation happen here (`aggregateDataset`, or on the server where the backend\n * can, as a database does), never in a chart.\n * 2. A `ChartSpec` (inside a `PanelSpec`, inside a `DashboardSpec`) says what to show in terms of\n * field ids only: the chart type, x / series / y fields, the aggregate, sort and limit. It is\n * plain JSON, saved in dashboards and studio pages.\n * 3. A renderer (`@arbidocs/blocks/dashboards`) maps a spec plus the aggregated dataset onto the\n * drawing component. No renderer type appears here, so the renderer stays swappable.\n */\n\n/** A field's value type. Dates are ISO strings (`2026-06-12` or a full timestamp). */\nexport type DatasetFieldType = 'string' | 'number' | 'date' | 'boolean'\n\n/** One column of a dataset. */\nexport interface DatasetField {\n /** Stable id: what specs and rows use. */\n id: string\n /** What people read (a column name, \"Status\"). */\n label: string\n type: DatasetFieldType\n /**\n * The unit of a number field, which picks its formatting: `gbp` (\u00A3), `bytes`, `tokens`, or any\n * suffix (`\"MB\"`, `\"%\"`).\n */\n unit?: string\n /** The values a string field takes, when known (a select column's options), for a filter picker. */\n options?: readonly string[]\n /** A string field whose cell holds several values (tags, linked rows): a row counts in each. */\n multiple?: boolean\n}\n\n/** A cell: a scalar, `null` when empty, or a list for a `multiple` field. */\nexport type DatasetValue = string | number | boolean | null | readonly string[]\n\n/** One row, keyed by field id. */\nexport type DatasetRow = Readonly<Record<string, DatasetValue | undefined>>\n\n/** A normalized dataset: typed fields and the rows. */\nexport interface Dataset {\n fields: readonly DatasetField[]\n rows: readonly DatasetRow[]\n /** Rows matched before grouping (after filters). */\n totalRows?: number\n /** More groups existed than the query's `limit`. */\n truncated?: boolean\n}\n\n/** How a date field is grouped. Keys: `2026-06-12`, `2026-W24`, `2026-06`, `2026-Q2`, `2026`. */\nexport type TimeBucket = 'day' | 'week' | 'month' | 'quarter' | 'year'\n\nexport type AggregateOp = 'count' | 'sum' | 'avg' | 'min' | 'max'\n\nexport type FilterOp =\n 'eq' | 'neq' | 'contains' | 'gt' | 'gte' | 'lt' | 'lte' | 'empty' | 'not_empty'\n\n/** Keep rows whose `field` satisfies `op value` (compared in the field's type). */\nexport interface DatasetFilter {\n field: string\n op: FilterOp\n value?: string | number | boolean | null\n}\n\n/** How the groups are ordered: by label (dates: chronological), or by value. */\nexport type DatasetSort = 'label' | 'value-desc' | 'value-asc'\n\n/** How records are ordered: by a field (empty cells last). */\nexport interface DatasetOrder {\n field: string\n /** Default `asc`. */\n direction?: 'asc' | 'desc'\n}\n\n/**\n * What to read of a source. Grouped (the default): the (filtered) rows grouped and each group\n * measured, a dataset in long form with the fields {@link AGGREGATE_FIELDS}, one row per group (and\n * series). With `records`: the matching rows themselves, ordered by `orderBy` and cut at `limit`.\n */\nexport interface DatasetQuery {\n /** List the matching records instead of grouping them (`groupBy`, `splitBy`, `measure` unused). */\n records?: boolean\n /** The order of the records. */\n orderBy?: DatasetOrder\n filters?: readonly DatasetFilter[]\n /** The field whose values (or date buckets) are the groups. Absent: one group, \"All\". */\n groupBy?: string\n /** The bucket of a date `groupBy` / `splitBy`. Default `month`. */\n bucket?: TimeBucket\n /** A second field: one series per value (a stacked or multi-line chart). */\n splitBy?: string\n /** Default: count rows. `count` with a `field` counts the rows where it is not empty. */\n measure?: { op: AggregateOp; field?: string }\n /** Default: dates chronological, others by value, largest first. */\n sort?: DatasetSort\n /** Most groups kept (by value), or records listed. Default 50 groups; every record. */\n limit?: number\n}\n\n/** The field ids of an aggregated dataset. */\nexport const AGGREGATE_FIELDS = {\n /** The group's label (\"Open\", \"2026-06\"). */\n group: 'group',\n /** The group's key as grouped (a date bucket, an id), for ordering and links. */\n key: 'key',\n /** The series' label (only with `splitBy`). */\n series: 'series',\n /** The measured value; `null` when the group has no value to measure. */\n value: 'value',\n} as const\n\n/** A dataset (or a source's fields) as a hook reads it. */\nexport interface DatasetState {\n dataset: Dataset | undefined\n /**\n * No dataset yet, and one is coming: a read in flight or still waiting to start (the workspace\n * opening, a saved view being read first). A panel says \"Loading\u2026\" then, never \"nothing to show\".\n */\n isLoading: boolean\n error: unknown\n}\n\nexport interface DataSourceFieldsState {\n fields: readonly DatasetField[]\n isLoading: boolean\n error: unknown\n}\n\n/** A source's parameters as saved in a panel (a database id, a period). */\nexport type DataSourceParams = Readonly<\n Record<string, string | number | boolean | null | undefined>\n>\n\n/** A choice for a parameter (an option of a select). */\nexport interface DataSourceOption {\n value: string\n label: string\n /** Other parameters set with this choice (a database's workspace, so a panel reads it anywhere). */\n params?: DataSourceParams\n}\n\n/** A parameter the panel editor asks for, before the source's fields are known. */\nexport interface DataSourceParam {\n id: string\n label: string\n /** Absent: the parameter may be left empty. */\n required?: boolean\n /** Shown when nothing is chosen (\"All columns\"). */\n placeholder?: string\n /** The choices, read live (databases of the open workspace; a database's saved views). */\n useOptions: (params: DataSourceParams) => {\n options: readonly DataSourceOption[]\n isLoading: boolean\n }\n}\n\n/**\n * A data source adapter: where a dataset comes from.\n *\n * `useFields` and `useDataset` are hooks. A caller renders them from a component keyed by the\n * source id, so switching source mounts afresh (the hooks differ between sources).\n *\n * Extension point: an external source (an HTTP/JSON API, a CSV feed, a warehouse) is one more\n * adapter. It reads its rows however it likes (its own `useQuery`) and returns them as a `Dataset`;\n * `defineRowsSource` aggregates them for it. A host lists it in `<ArbiHost config={{ dashboards:\n * { sources } }}>` and every editor, panel and studio block offers it. Fetching third-party URLs\n * from the browser is the host's decision (CORS, credentials, what a shared dashboard may reach),\n * so none is built in; data to chart today is imported into a database (CSV / spreadsheet import).\n */\nexport interface DataSource {\n id: string\n label: string\n description?: string\n /** `workspace`: it reads the open workspace's data (documents, threads\u2026), so it shows nothing until\n * one is open; a function decides from the panel's parameters (a database panel that does not name\n * its workspace). Absent: it is the person's own or names what it reads (AI usage). */\n scope?: 'workspace' | ((params: DataSourceParams) => 'workspace' | undefined)\n params?: readonly DataSourceParam[]\n /** The fields a panel can use, given the parameters. */\n useFields: (params: DataSourceParams) => DataSourceFieldsState\n /**\n * The dataset: grouped and measured (long form with {@link AGGREGATE_FIELDS}), or the records\n * (`query.records`), filtered either way.\n */\n useDataset: (\n params: DataSourceParams,\n query: DatasetQuery,\n options?: { enabled?: boolean }\n ) => DatasetState\n}\n\n// \u2500\u2500 Specs: what a panel shows (plain JSON) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * How a panel draws its data. `metric` is one number; `table` a table of rows or groups; `scatter`\n * one point per record (x and y both numbers).\n */\nexport type ChartType = 'metric' | 'bar' | 'line' | 'area' | 'pie' | 'donut' | 'scatter' | 'table'\n\n/** Which way is better on a scatter axis, for its Pareto frontier. */\nexport type FrontierGoal = 'min' | 'max'\n\n/** What to show, in terms of the dataset's field ids. Serialisable. */\nexport interface ChartSpec {\n type: ChartType\n /** The category or date field along the x axis (pie slices; table groups); a scatter's number field. */\n x?: string\n /** The bucket of a date `x`. Default `month`. */\n bucket?: TimeBucket\n /** A field whose values become the series (stacked bars or areas, several lines). */\n series?: string\n /** The number field the aggregate reads (absent: rows are counted); a scatter's vertical number. */\n y?: string\n /** Default `count`. */\n aggregate?: AggregateOp\n sort?: DatasetSort\n limit?: number\n /** Stack the series (bar, area). */\n stacked?: boolean\n filters?: readonly DatasetFilter[]\n /** A table of records (no aggregate): the fields shown, in order. Absent: every field. */\n columns?: readonly string[]\n /** A table of records: their order. */\n orderBy?: DatasetOrder\n /** A scatter: the field that names each point. */\n label?: string\n /** Categories (bar, line, area) or point labels (scatter) drawn in the accent colour. */\n highlight?: readonly string[]\n /**\n * A scatter: draw its Pareto frontier, the points no other point beats on both axes. `x` / `y`\n * say which way is better (price: `min`, score: `max`).\n */\n frontier?: { x: FrontierGoal; y: FrontierGoal }\n /** A scatter: dashed guides at the median x and median y, splitting it into quadrants. */\n quadrants?: boolean\n /** A scatter: the x axis's scale (`log` for values across orders of magnitude). Default `linear`. */\n xScale?: 'linear' | 'log'\n}\n\n/** The source a panel reads, by registry id, with its parameters. */\nexport interface DataSourceRef {\n id: string\n params?: DataSourceParams\n}\n\n/** One panel of a dashboard. */\nexport interface PanelSpec {\n id: string\n title: string\n description?: string\n source: DataSourceRef\n chart: ChartSpec\n /** Columns of the 12-column grid it spans on a wide screen (it is full width on a phone). */\n width?: number\n}\n\n/** A dashboard: a titled grid of panels. Plain JSON (`version` for later migrations). */\nexport interface DashboardSpec {\n version: 1\n title: string\n description?: string\n panels: readonly PanelSpec[]\n}\n"],
5
5
  "mappings": "AAuGO,MAAM,mBAAmB;AAAA;AAAA,EAE9B,OAAO;AAAA;AAAA,EAEP,KAAK;AAAA;AAAA,EAEL,QAAQ;AAAA;AAAA,EAER,OAAO;AACT;",
6
6
  "names": []
7
7
  }
package/dist/index.cjs CHANGED
@@ -10891,7 +10891,7 @@ function defineAggregateSource(definition) {
10891
10891
  };
10892
10892
  }
10893
10893
  function queryOfChart(chart) {
10894
- if (chart.type === "table" && !chart.x) {
10894
+ if (chart.type === "table" && !chart.x || chart.type === "scatter") {
10895
10895
  return {
10896
10896
  records: true,
10897
10897
  ...chart.filters?.length ? { filters: chart.filters } : {},